Skip to main content

Functions that operate directly on Events. @public

Properties#

currentOffsets#

currentOffsets: () => Promise<{}>

Get the current latest offsets known locally.

Type declaration:#

▸ (): Promise<{}>

Returns: Promise<{}>


emit#

emit: (events: readonly Readonly<{ event: unknown ; tags: string[] }>[]) => PendingEmission

Emit a number of events with tags attached.

param Events to emit.

returns A PendingEmission object that can be used to register callbacks with the emission’s completion.

Type declaration:#

▸ (events: readonly Readonly<{ event: unknown ; tags: string[] }>[]): PendingEmission

Parameters:#

NameType
eventsreadonly Readonly<{ event: unknown ; tags: string[] }>[]

Returns: PendingEmission


observeBestMatch#

observeBestMatch: <E>(query: Where<E>, shouldReplace: (candidate: ActyxEvent<E>, cur: ActyxEvent<E>) => boolean, onReplaced: (event: E, metadata: Readonly<{ eventId: string ; isLocalEvent: boolean ; lamport: number ; tags: readonly string[] ; timestampAsDate: () => Date ; timestampMicros: number }>) => void) => CancelSubscription

Among all events matching the query, find one that best matches some property. This is useful for finding the event that has min or max of something. E.g. shouldReplace = (candidate, cur) => candidate.meta.timestampMicros > cur.meta.timestampMicros keeps finding the event with the highest timestamp.

param Query to select the set of candidate events.

param Should candidate replace cur?

param Callback that is evoked whenever replacement happens, i.e. we found a new best match.

returns A function that can be called in order to cancel the subscription.

Type declaration:#

▸ <E>(query: Where<E>, shouldReplace: (candidate: ActyxEvent<E>, cur: ActyxEvent<E>) => boolean, onReplaced: (event: E, metadata: Readonly<{ eventId: string ; isLocalEvent: boolean ; lamport: number ; tags: readonly string[] ; timestampAsDate: () => Date ; timestampMicros: number }>) => void): CancelSubscription

Type parameters:#

Name
E

Parameters:#

NameType
queryWhere<E>
shouldReplace(candidate: ActyxEvent<E>, cur: ActyxEvent<E>) => boolean
onReplaced(event: E, metadata: Readonly<{ eventId: string ; isLocalEvent: boolean ; lamport: number ; tags: readonly string[] ; timestampAsDate: () => Date ; timestampMicros: number }>) => void

Returns: CancelSubscription


observeEarliest#

observeEarliest: <E>(query: EarliestQuery<E>, onNewEarliest: (event: E, metadata: Readonly<{ eventId: string ; isLocalEvent: boolean ; lamport: number ; tags: readonly string[] ; timestampAsDate: () => Date ; timestampMicros: number }>) => void) => CancelSubscription

Observe always the earliest event matching the given query. If there is an existing event fitting the query, onNewEarliest will be called with that event. Afterwards, onNewEarliest will be called whenever a new event becomes known that is older than the previously passed one. Note that the 'earliest' event may keep updating as new events become known.

param Query to select the set of events.

param Callback that will be invoked whenever there is a 'new' earliest event.

returns A function that can be called in order to cancel the subscription.

beta

Type declaration:#

▸ <E>(query: EarliestQuery<E>, onNewEarliest: (event: E, metadata: Readonly<{ eventId: string ; isLocalEvent: boolean ; lamport: number ; tags: readonly string[] ; timestampAsDate: () => Date ; timestampMicros: number }>) => void): CancelSubscription

Type parameters:#

Name
E

Parameters:#

NameType
queryEarliestQuery<E>
onNewEarliest(event: E, metadata: Readonly<{ eventId: string ; isLocalEvent: boolean ; lamport: number ; tags: readonly string[] ; timestampAsDate: () => Date ; timestampMicros: number }>) => void

Returns: CancelSubscription


observeLatest#

observeLatest: <E>(query: EarliestQuery<E>, onNewLatest: (event: E, metadata: Readonly<{ eventId: string ; isLocalEvent: boolean ; lamport: number ; tags: readonly string[] ; timestampAsDate: () => Date ; timestampMicros: number }>) => void) => CancelSubscription

Observe always the latest event matching the given query. If there is an existing event fitting the query, onNewLatest will be called with that event. Afterwards, onNewLatest will be called whenever a new event becomes known that is younger than the previously passed one.

param Query to select the set of events.

param Callback that will be invoked for each new latest event.

returns A function that can be called in order to cancel the subscription.

beta

Type declaration:#

▸ <E>(query: EarliestQuery<E>, onNewLatest: (event: E, metadata: Readonly<{ eventId: string ; isLocalEvent: boolean ; lamport: number ; tags: readonly string[] ; timestampAsDate: () => Date ; timestampMicros: number }>) => void): CancelSubscription

Type parameters:#

Name
E

Parameters:#

NameType
queryEarliestQuery<E>
onNewLatest(event: E, metadata: Readonly<{ eventId: string ; isLocalEvent: boolean ; lamport: number ; tags: readonly string[] ; timestampAsDate: () => Date ; timestampMicros: number }>) => void

Returns: CancelSubscription


observeUnorderedReduce#

observeUnorderedReduce: <R, E>(query: Where<E>, reduce: (acc: R, event: E, metadata: Readonly<{ eventId: string ; isLocalEvent: boolean ; lamport: number ; tags: readonly string[] ; timestampAsDate: () => Date ; timestampMicros: number }>) => R, initial: R, onUpdate: (result: R) => void) => CancelSubscription

Apply a reduce operation to all events matching query, in no specific order. This is useful for operations that are commutative, e.g. sum or product.

param Query to select the set of events to pass to the reducer.

param Compute a new state R by integrating the next event.

param Initial, neutral state, e.g. 0 for a sum operation.

param Callback that is evoked with updated results. If a batch of events was applied, onUpdate will only be called once, with the final new state.

returns A function that can be called in order to cancel the subscription.

Type declaration:#

▸ <R, E>(query: Where<E>, reduce: (acc: R, event: E, metadata: Readonly<{ eventId: string ; isLocalEvent: boolean ; lamport: number ; tags: readonly string[] ; timestampAsDate: () => Date ; timestampMicros: number }>) => R, initial: R, onUpdate: (result: R) => void): CancelSubscription

Type parameters:#

Name
R
E

Parameters:#

NameType
queryWhere<E>
reduce(acc: R, event: E, metadata: Readonly<{ eventId: string ; isLocalEvent: boolean ; lamport: number ; tags: readonly string[] ; timestampAsDate: () => Date ; timestampMicros: number }>) => R
initialR
onUpdate(result: R) => void

Returns: CancelSubscription


queryAllKnown#

queryAllKnown: (query: AutoCappedQuery) => Promise<EventChunk>

Query all known events that occured after the given lowerBound.

param OpenEndedQuery object specifying the desired set of events.

returns An EventChunk with the result and its bounds. The contained upperBound can be passed as lowerBound to a subsequent call of this function to achieve exactly-once delivery of all events.

Type declaration:#

▸ (query: AutoCappedQuery): Promise<EventChunk>

Parameters:#

NameType
queryAutoCappedQuery

Returns: Promise<EventChunk>


queryAllKnownChunked#

queryAllKnownChunked: (query: AutoCappedQuery, chunkSize: number, onChunk: (chunk: EventChunk) => void | Promise<void>) => Promise<{}>

Query all known events that occured after the given lowerBound, in chunks. This is useful if the complete result set is potentially too large to fit into memory at once.

param OpenEndedQuery object specifying the desired set of events.

param Maximum size of chunks. Chunks may be smaller than this.

param Callback that will be invoked for each chunk, in sequence. Second argument is an offset map covering all events passed as first arg.

returns A Promise that resolves to updated offset-map after all chunks have been delivered.

Type declaration:#

▸ (query: AutoCappedQuery, chunkSize: number, onChunk: (chunk: EventChunk) => void | Promise<void>): Promise<{}>

Parameters:#

NameType
queryAutoCappedQuery
chunkSizenumber
onChunk(chunk: EventChunk) => void | Promise<void>

Returns: Promise<{}>


queryKnownRange#

queryKnownRange: (query: RangeQuery) => Promise<ActyxEvent<unknown>[]>

Get all known events between the given offsets, in one array.

param RangeQuery object specifying the desired set of events.

returns A Promise that resolves to the complete set of queries events.

Type declaration:#

▸ (query: RangeQuery): Promise<ActyxEvent<unknown>[]>

Parameters:#

NameType
queryRangeQuery

Returns: Promise<ActyxEvent<unknown>[]>


queryKnownRangeChunked#

queryKnownRangeChunked: (query: RangeQuery, chunkSize: number, onChunk: (chunk: EventChunk) => void | Promise<void>) => Promise<void>

Get all known events between the given offsets, in chunks. This is helpful if the result set is too large to fit into memory all at once. The returned Promise resolves after all chunks have been delivered.

param RangeQuery object specifying the desired set of events.

param Maximum size of chunks. Chunks may be smaller than this.

param Callback that will be invoked with every chunk, in sequence.

returns A Promise that resolves when all chunks have been delivered to the callback.

Type declaration:#

▸ (query: RangeQuery, chunkSize: number, onChunk: (chunk: EventChunk) => void | Promise<void>): Promise<void>

Parameters:#

NameType
queryRangeQuery
chunkSizenumber
onChunk(chunk: EventChunk) => void | Promise<void>

Returns: Promise<void>


subscribe#

subscribe: (query: EventSubscription, onChunk: (chunk: EventChunk) => void | Promise<void>) => CancelSubscription

Subscribe to all events fitting the query after lowerBound. They will be delivered in chunks of at most 5000. New events are delivered as they become known. The subscription goes on forever, until manually cancelled.

param EventSubscription object specifying the desired set of events.

param Callback that will be invoked for each chunk, in sequence. Second argument is the updated offset map.

returns A function that can be called in order to cancel the subscription.

Type declaration:#

▸ (query: EventSubscription, onChunk: (chunk: EventChunk) => void | Promise<void>): CancelSubscription

Parameters:#

NameType
queryEventSubscription
onChunk(chunk: EventChunk) => void | Promise<void>

Returns: CancelSubscription