Skip to content

jwindridge/es-aggregate

Repository files navigation

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 
})

About

Library for building event-sourced aggregates

Resources

License

Stars

Watchers

Forks

Packages

No packages published