Skip to content
English

InMemoryJournal

Defined in: src/persistence/journals/InMemoryJournal.ts:26

In-process journal backed by plain arrays. The default plug-in used by tests and dev-mode; data lives only as long as the process and is NOT shared across ActorSystem instances. Serves as reference semantics for all other Journal implementations — including the value model: stored events take the same PayloadCodec round-trip a real store performs, so an event that would corrupt or fail on Postgres fails the same way here, in tests, instead of on the first production recovery (#888). Like the real stores, append returns and publishes the caller’s original objects; only the stored stream holds the round-tripped copies.

Exposes an in-process JournalEventBus so the query layer can do sub-poll-interval push delivery (see #42).

new InMemoryJournal(): InMemoryJournal

InMemoryJournal

readonly events: JournalEventBus

Defined in: src/persistence/journals/InMemoryJournal.ts:36

Optional in-process notification bus. When present, the read-side query layer subscribes here for sub-poll-interval push delivery (see JournalEventBus). Journals that span processes (Cassandra, Postgres) leave it undefined — the query layer falls back to the polling loop.

Journal.events

_remapForMigration<E, F>(persistenceId, transform): Promise<void>

Defined in: src/persistence/journals/InMemoryJournal.ts:137

Migration hook (#9). Applies transform to every persisted event’s payload under persistenceId, rewriting in place — sequence numbers, timestamps, tags are preserved. Used by migrateInMemoryJournal to wrap legacy raw events into the _v/_t/_e envelope when an actor is retro-fitted with an EventAdapter.

Internal API. Callers should reach for the documented migrateInMemoryJournal helper instead of calling this directly; the underscored prefix marks it as a migration-only escape hatch.

E

F

string

(e) => F

Promise<void>


append<E>(persistenceId, events, expectedSeq, tags?): Promise<PersistentEvent<E>[]>

Defined in: src/persistence/journals/InMemoryJournal.ts:38

Append events to the stream of persistenceId, enforcing optimistic concurrency: the current highest sequence number MUST equal expectedSeq or the call throws JournalConcurrencyError. Returns the written events with their assigned sequence numbers.

E

string

readonly E[]

number

readonly string[]

Promise<PersistentEvent<E>[]>

Journal.append


close(): Promise<void>

Defined in: src/persistence/journals/InMemoryJournal.ts:124

Best-effort teardown; idempotent.

Promise<void>

Journal.close


delete(persistenceId, toSeq): Promise<void>

Defined in: src/persistence/journals/InMemoryJournal.ts:97

Delete events up to and including toSeq — used when compacting past a snapshot. Only ever a prefix, so what survives is a suffix that read still returns contiguously, and sequence numbers never rewind: highestSeq keeps reporting the high-water mark afterwards.

string

number

Promise<void>

Journal.delete


highestSeq(persistenceId): Promise<number>

Defined in: src/persistence/journals/InMemoryJournal.ts:93

Current highest sequence number for persistenceId — 0 if no events exist.

string

Promise<number>

Journal.highestSeq


persistenceIds(): Promise<string[]>

Defined in: src/persistence/journals/InMemoryJournal.ts:106

Persistence IDs currently known to the journal (useful for projections).

Promise<string[]>

Journal.persistenceIds


persistenceIdsPaginated(afterPersistenceId, limit): Promise<string[]>

Defined in: src/persistence/journals/InMemoryJournal.ts:117

Implemented even though nothing is saved on the read — a Map has every key in memory already — because it is what makes the ordering half of the contract observable in tests: this journal is the reference implementation the SQL and CQL push-downs are checked against, and an oracle that skips the method proves nothing about the ones that don’t.

string | undefined

number

Promise<string[]>

Journal.persistenceIdsPaginated


read<E>(persistenceId, fromSeq, toSeq?): Promise<PersistentEvent<E>[]>

Defined in: src/persistence/journals/InMemoryJournal.ts:84

Return the events in [fromSeq, …, toSeq], ascending by sequence number. toSeq defaults to the current highest sequence number. Both bounds are inclusive — fromSeq is the first event returned, not an “after” cursor.

Ordering and contiguity are part of the contract, and replay enforces them (#122). Consecutive entries must differ by exactly one, every sequenceNr must be a safe integer ≥ 1, and nothing may fall outside the requested window. delete compacts a prefix, never a hole in the middle, so a gap inside the returned slice can only mean a defect — a missing ORDER BY, a half-written append, a store someone else can write. replayState raises JournalIntegrityError instead of folding it, because an actor that recovers from a shuffled or holed stream reaches a state that never existed and then fails every later persist with a JournalConcurrencyError that has no visible cause.

E

string

number

number

Promise<PersistentEvent<E>[]>

Journal.read