UNPKG

@actyx/sdk

Version:
68 lines (67 loc) 2.3 kB
import { Lamport, NodeId, OffsetMap, OffsetMapBuilder, TimeInjector, Timestamp } from '../types'; import { DoPersistEvents, DoQuery, DoSubscribe, EventStore } from './eventStore'; import { Event } from './types'; /** * A raw Actyx event to be emitted by the TestEventStore, as if it really arrived from the outside. * @public */ export declare type TestEvent = { offset: number; stream: string; timestamp: Timestamp; lamport: Lamport; tags: string[]; payload: unknown; }; export declare type TestEventStore = EventStore & { directlyPushEvents: (events: TestEvent[]) => void; storedEvents: () => Event[]; close: () => void; }; export declare type HasPsnAndSource = { offset: number; stream: string; }; export declare const includeEvent: (offsetsBuilder: OffsetMapBuilder, ev: HasPsnAndSource) => OffsetMap; /** * HERE BE DRAGONS: This function is just a draft of an optimisation we may do in a Rust-side impl * Take an offset map and a sorted array of events -> find an index that fully covers the offsetmap. * - Offset of event is smaller than in map -> Too low * - Offset of event is higher -> Too high * - Event’s source is not in offsets: Too high if offsets default is 'min' * - Psn eq: Too low, unless the next event is too high */ export declare const binSearchOffsets: (a: { offset: number; stream: string; timestamp: number; lamport: number; appId: string; tags: string[]; payload: unknown; }[], offsets: OffsetMap) => number; export declare const testEventStore: (nodeId?: NodeId, timeInjector?: TimeInjector | undefined) => { nodeId: string; offsets: () => Promise<{ present: OffsetMap; toReplicate: {}; }>; query: DoQuery; queryUnchecked: () => never; subscribe: DoSubscribe; subscribeUnchecked: () => never; subscribeMonotonic: () => never; persistEvents: DoPersistEvents; directlyPushEvents: (newEvents: TestEvent[]) => void; storedEvents: () => { offset: number; stream: string; timestamp: number; lamport: number; appId: string; tags: string[]; payload: unknown; }[]; connectivityStatus: () => import("rxjs/internal/Observable").Observable<never>; close: () => void; };