DRY Castore EventStorageAdapter
implementation using a JS object.
This class is mainly useful for manual and unit tests. It is obviously not recommended for production uses 🙂
# npm
npm install @castore/inmemory-event-storage-adapter
# yarn
yarn add @castore/inmemory-event-storage-adapter
This package has @castore/core
as peer dependencies, so you will have to install it as well:
# npm
npm install @castore/core
# yarn
yarn add @castore/core
import { InMemoryStorageAdapter } from '@castore/inmemory-event-storage-adapter';
const userEventsStorageAdapter = new InMemoryStorageAdapter({
// 👇 You can specify an initial state for your event store
initialEvents: [
{
aggregateId: '123',
...
},
],
});
const userEventStore = new EventStore({
// ...
storageAdapter: userEventsStorageAdapter,
});
This adapter simply persists events in a local dictionary. You can retrieve it at all time through the eventStore
property:
const eventStore = userEventStore.eventStore;
// => { [aggregateId: string]: EventDetail[] }