@authentik8/es-aggregate
TypeScript icon, indicating that this package has built-in type declarations

0.2.8 • Public • Published

ES-Aggregate

This package provides my take on an event-sourced aggregate, allowing a user to configure an aggregate based on it's name, initial state, command handling & event processing.

Installation

npm install @authentik8/es-aggregate

Usage

import { createAggregate } from '@authentik8/es-aggregate';

const name = 'Counter'

const initialState = { count: 0 };

const commands = {
  increment: (entity, command) => {
    const { by } = command;
    entity.publish('incremented', { incrementSize: by })
  }
}

const eventHandlers = {
  incremented: (state, event) => ({
    ...state,
    count: state.count + event.incrementSize
  })
}

const aggregate = createAggregate({ 
  name, 
  initialState, 
  commands, 
  eventHandlers 
})

/@authentik8/es-aggregate/

    Package Sidebar

    Install

    npm i @authentik8/es-aggregate

    Weekly Downloads

    0

    Version

    0.2.8

    License

    MIT

    Unpacked Size

    21.5 kB

    Total Files

    22

    Last publish

    Collaborators

    • authentik8