A store keeps the bus’s events. The bus only needs four operations:

OperationContract
append(event)Store one event
get(id)The event, or undefined
list(filter?)Matching events, ordered (see below)
findByDedupeKey(key)The event carrying that dedupeKey, or undefined

The contract for list:

  • Order: ascending by time, with ties broken by ascending id.
  • since: an inclusive cutoff on time.
  • limit: applied after filtering and ordering, and takes the first limit events, not the most recent. Callers page forward from since.

Every operation returns copies. Changing an event you got back never changes what’s stored.

In the Effect API, a store is an EventStoreService whose operations are Effects that fail with StoreError, plus BusValidationError for a malformed filter. In the Promise facade, it’s the EventStore interface with Promises.

Memory

EventStore.memory (or new MemoryEventStore()) is for tests and short-lived runs. It deep-clones events on the way in and on the way out.

JSONL

EventStore.jsonl(directory) (or new JsonlEventStore(directory)) appends one event per line to <directory>/events.jsonl. The directory is created on the first append.

  • Unrecognised lines: a line that doesn’t parse as an event is skipped, and the file is never rewritten. A line that is an event keeps any fields this version doesn’t know.
  • Reads: each read replays the whole file.
  • Crashes: a line torn by a crash mid-append is skipped, but the next append continues on that same line.
  • Concurrency: two concurrent emits with the same dedupeKey can both land. One process per store is fine. A store shared between processes needs a unique index.

Conformance

runEventStoreConformance(name, factory) from @techsavvyash/bus/conformance registers the node:test suite that the memory and JSONL stores pass. It covers the append/get round trip, ordering, every filter, since, limit, dedupe lookup and copy isolation. Run it against your own store:

import { runEventStoreConformance } from "@techsavvyash/bus/conformance";
 
runEventStoreConformance("PostgresEventStore", async () => {
  const store = await openTestStore();
  return { store, cleanup: () => store.drop() };
});

The suite takes a Promise store. To check an Effect store, wrap it with toPromiseEventStore from @techsavvyash/bus/promise.