rheactor-event-store
v9.7.0
Published
Implementation of an event store based on redis
Downloads
15
Readme
rheactor-event-store
Implementation of an event store based on redis.
Contains helper methods to manage secondary indices.
Versioning
Storing events per aggregate is done in a list per individual aggregate, the order of the insertion is guaranteed by using Redis lists. This gives use an version number per event for free.
Lets assume we want to create a user 17
, we store a UserCreatedEvent
for this aggregate id:
eventStore.persist(new ModelEvent('UserCreatedEvent', '17', {name: 'John'}))
If we add another event later:
eventStore.persist(new ModelEvent('UserNameUpdatedEvent', '17', {name: 'Mike'}))
this event will be appended to the list.
When aggregating the events, we can increase the version of the aggregate per event.
Mutable Aggregates have been deprecated
The initial implementation of the event store modified models in place. More recently we decied to use immutable models instead.
The ImmutableAggregateRepository
changes how Models are instantiated. It moves the responsibility of creating the model instance to the repository, where the applyEvent()
method is invoked as a reducer. The method will return an instance of ImmutableAggregateRoot
which can no longer be manipulated directly.
This also changes how meta information is stored in the Aggregates, it is now encapsuled in a separate object called AggregateMeta
.
See the tests for details.