In-Memory Driver
The in-memory driver stores events, checkpoints, and snapshots in plain JavaScript arrays and maps. It requires no external dependencies and works out of the box.
import { createEventStore, createAggregateRoot } from '@requence/event-sourcing/memory'
const eventStore = createEventStore({ aggregateRoots: [userAggregateRoot],})When to use
Section titled “When to use”- Unit and integration tests — no database setup needed, tests run instantly.
- Prototyping — focus on your domain logic before committing to a database.
- Single-process applications — lightweight apps that don’t need durable persistence.
Configuration
Section titled “Configuration”import { createEventStore, createAggregateRoot } from '@requence/event-sourcing/memory'
const eventStore = createEventStore({ // Required — one or more aggregate roots aggregateRoots: [user, project],
// Optional — disable automatic initialization (default: true) autoInit: false,
// Optional — callback invoked after events are appended onEventsAppended(events) { console.log(`${events.length} event(s) appended`) },
// Optional — progress callbacks for projection replays onProjectionReplay: { begin(name) { console.log(`Replaying ${name}…`) }, end(name) { console.log(`${name} replay complete`) }, },
// Optional — progress callbacks for process manager refreshes onProcessManagerRefresh: { begin(name) { console.log(`Refreshing ${name}…`) }, end(name) { console.log(`${name} refresh complete`) }, },
// Optional — post-process events before they are appended postProcessEvent(event, aggregateRoot) { return event },})Encryption keys
Section titled “Encryption keys”memoryKeyStore keeps the data keys for encrypted fields in a Map. Use it in tests to check that no plaintext is stored and that destroyed keys read as null:
import { randomBytes } from 'node:crypto'import { createEventStore, memoryKeyStore } from '@requence/event-sourcing/memory'
const eventStore = createEventStore({ aggregateRoots: [user], encryption: { masterKeys: randomBytes(32), keyStore: memoryKeyStore(), },})Like everything else in this driver, the keys are lost when the process exits, which makes every encrypted field unreadable. For durable data, use drizzleKeyStore or surrealKeyStore.
Features
Section titled “Features”The in-memory driver provides full support for all event store features:
- Event storage with position tracking and concurrency checks
- Checkpoints for projection and process manager catch-up
- Aggregate root snapshots for fast stream rehydration
- Projection snapshots with applied-count tracking
ConcurrencyErrorthrown when the expected stream version doesn’t match