@castore/event-storage-adapter-in-memory
TypeScript icon, indicating that this package has built-in type declarations

2.3.1 • Public • Published

In Memory Event Storage Adapter

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 🙂

📥 Installation

# npm
npm install @castore/event-storage-adapter-in-memory

# yarn
yarn add @castore/event-storage-adapter-in-memory

This package has @castore/core as peer dependency, so you will have to install it as well:

# npm
npm install @castore/core

# yarn
yarn add @castore/core

👩‍💻 Usage

import { InMemoryEventStorageAdapter } from '@castore/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[] }

Package Sidebar

Install

npm i @castore/event-storage-adapter-in-memory

Weekly Downloads

602

Version

2.3.1

License

MIT

Unpacked Size

173 kB

Total Files

29

Last publish

Collaborators

  • thomasaribart
  • valentinbeggi
  • charlesgery
  • julietteff