Skip to content

PersistenceQuery

Defined in: src/persistence/query/PersistenceQuery.ts:27

Read-side query layer for the journal. Designed for projections — processes that materialise a read-model by sweeping events out of the write-side journal and feeding them into a user handler.

Two flavours of query:

  • current* — one-shot snapshot of events currently in the journal at call time. Resolves to a Promise. Use this for a batch backfill or a self-contained report.
  • events* — continuous live stream. Polls the journal at pollIntervalMs for new events. Yields an AsyncIterable so consumers can for await (const ev of stream) .... The stream stays open until the consumer breaks out of the loop or calls return() on the iterator.

Delivery guarantees: at-least-once. A projection that fails mid-event must accept that the event will be redelivered after restart. Handlers therefore have to be idempotent.

Pull-only. The first iteration polls. Push-based subscribe (via the system’s EventStream) is intentionally deferred — see issue #36 / the roadmap plan.

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

Defined in: src/persistence/query/PersistenceQuery.ts:46

One-shot read of every event for persistenceId whose sequenceNr >= fromSeq (and <= toSeq if given). Resolves once with the events known at call time.

E

string

number

number

Promise<PersistentEvent<E>[]>


currentEventsByTag<E>(filter, fromOffset): Promise<TaggedEvent<E>[]>

Defined in: src/persistence/query/PersistenceQuery.ts:73

One-shot read of every event matching filter whose offset is >= fromOffset. See TagFilter for the operator semantics.

E

TagFilter

Offset

Promise<TaggedEvent<E>[]>


currentPersistenceIds(): Promise<string[]>

Defined in: src/persistence/query/PersistenceQuery.ts:84

Snapshot of every persistence id known to the journal. Resolves once. Useful for fan-out projections that subscribe to one stream per id; pair with eventsByPersistenceId for the continuous read.

Promise<string[]>


eventsByPersistenceId<E>(persistenceId, fromSeq, options?): AsyncIterable<PersistentEvent<E>>

Defined in: src/persistence/query/PersistenceQuery.ts:35

Live stream of every event for persistenceId whose sequenceNr >= fromSeq. Past events are emitted first (chronological by sequenceNr), then new events as they are appended. The stream never completes on its own — break out of the loop or call return() on the iterator to stop polling.

E

string

number

LiveQueryOptions

AsyncIterable<PersistentEvent<E>>


eventsByTag<E>(filter, fromOffset, options?): AsyncIterable<TaggedEvent<E>>

Defined in: src/persistence/query/PersistenceQuery.ts:63

Live stream of every event matching filter whose offset is >= fromOffset. Yields events ordered by (timestamp, persistenceId, sequenceNr). See Offset for offset semantics — the stream emits the offset alongside the event so the consumer can persist progress.

filter accepts either a single tag string (back-compat shortcut for { all: [tag] }) or a TagFilter object that combines all (intersect), any (union), and not (exclusion) operators.

E

TagFilter

Offset

LiveQueryOptions

AsyncIterable<TaggedEvent<E>>