npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

serverless-cqrs.write-model

v0.2.10-alpha.0

Published

The serverelss-cqrs write model. A collection of builder functions for generating a write model.

Downloads

10

Readme

write-model

The write-model exports two functions repositoryBuilder and commandServiceBuilder.

To initialize the model, you pass an adapter and reducer to the repositoryBuilder to generate a repository. Then you pass the repository and actions to the commandServiceBuilder to generate a list of commands

Example

const {
  repositoryBuilder,
  commandServiceBuilder,
} = require('serverless-cqrs.write-mode')

const adapter = require('./adapter')
const reducer = require('./reducer')
const actions = require('./actions')

const repository = repositoryBuilder.build({
  adapter,
  reducer,
})

module.exports = commandServiceBuilder.build({
  repository,
  actions,
})

repositoryBuilder

Takes a reducer and an adapter and returns a repository. A repository is the layer of our Onion Architecture (see Introduction) which handles data persistence.

The write-model repository has a single method called getById. When invoked, it uses the adapter to load all events for given ID and runs them through the reducer to calculate the current state. It returns an object that contains state and also a save method, which is used to append new events.

Methods

build

build({ adapter, reducer })

builds a repository

Parameters

| attribute | type | description | | :--- | :--- | :--- | | adapter | object | Any object which implements the write-model Adapter Interface. | | reducer | function | a function which, given a list of events, knows how to calculate the current state of an object. |

Returns

{ getById } - an object with the getById function.

getById

getById(id)

Loads and returns the current state of an entity. Also returns a save function for appending new events to the data store.

Parameters

| attribute | type | description | | :--- | :--- | :--- | | id | string | the id of the entity |

Returns

{ state, save } - an object containing an arbitrary state object, and a save function.

save

save(events)

Appends new events to the datastore

Parameters

| attribute | type | description | | :--- | :--- | :--- | | events | array | an array of arbitrary event objects |

Returns

null

commandServiceBuilder

Takes a list of actions and a repository and returns an object where action names map to executable commands.

Each command accepts an id and a payload. When invoked, a command loads the current state of the entity from the repo and passes it, and the payload, to the action. The action will perform its validation and if successful, generate one or more events. The command forwards those events to the repository to be appended to the entity.

Methods

build

build({ actions, repository })

Turns actions into commands that can be executed on real objects.

Parameters

| attribute | type | description | | :--- | :--- | :--- | | actions | object | Domain actions | | repository | object | generated by the repositoryBuilder |

Returns

commands - where keys are actions names and values are functions which accept an id and payload