@hamstore/event-storage-adapter-in-memory
v3.1.0
Published
DRY Hamstore EventStorageAdapter implementation using a JS object
Readme
In Memory Event Storage Adapter
DRY Hamstore EventStorageAdapter implementation using a JS object.
This class is mainly useful for manual and unit tests. It is obviously not recommended for production uses 🙂
📥 Installation
# npm
npm install @hamstore/event-storage-adapter-in-memory
# pnpm
pnpm add @hamstore/event-storage-adapter-in-memoryThis package has @hamstore/core as peer dependency, so you will have to install it as well:
# npm
npm install @hamstore/core
# pnpm
pnpm add @hamstore/core👩💻 Usage
import { InMemoryEventStorageAdapter } from '@hamstore/event-storage-adapter-in-memory';
const pokemonsEventStorageAdapter = new InMemoryEventStorageAdapter({
// 👇 You can specify an initial state for your event store
initialEvents: [
{
aggregateId: '123',
...
},
],
});
const pokemonsEventStore = new EventStore({
...
eventStorageAdapter: pokemonsEventStorageAdapter,
});🤔 How it works
This adapter simply persists events in a local dictionary. You can retrieve it at all time through the eventStore property:
const eventStore = pokemonsEventStore.eventStore;
// => { [aggregateId: string]: EventDetail[] }