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 atpollIntervalMsfor new events. Yields anAsyncIterableso consumers canfor await (const ev of stream) .... The stream stays open until the consumer breaks out of the loop or callsreturn()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.
Methods
Section titled “Methods”currentEventsByPersistenceId()
Section titled “currentEventsByPersistenceId()”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.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”persistenceId
Section titled “persistenceId”string
fromSeq
Section titled “fromSeq”number
toSeq?
Section titled “toSeq?”number
Returns
Section titled “Returns”Promise<PersistentEvent<E>[]>
currentEventsByTag()
Section titled “currentEventsByTag()”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.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”filter
Section titled “filter”fromOffset
Section titled “fromOffset”Returns
Section titled “Returns”Promise<TaggedEvent<E>[]>
currentPersistenceIds()
Section titled “currentPersistenceIds()”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.
Returns
Section titled “Returns”Promise<string[]>
eventsByPersistenceId()
Section titled “eventsByPersistenceId()”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.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”persistenceId
Section titled “persistenceId”string
fromSeq
Section titled “fromSeq”number
options?
Section titled “options?”Returns
Section titled “Returns”AsyncIterable<PersistentEvent<E>>
eventsByTag()
Section titled “eventsByTag()”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.
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”filter
Section titled “filter”fromOffset
Section titled “fromOffset”options?
Section titled “options?”Returns
Section titled “Returns”AsyncIterable<TaggedEvent<E>>