import type { AggQuery, AggResult, AllQuery, CommittedEvent, CommittedEventMetadata, Lease, Message, Messages, PollOptions, Projection, ProjectionMap, ProjectionQuery, ProjectionRecord, ProjectionResults, ProjectionSort, Schema, State, StoreStat, Subscription } from "../types"; import { Disposable } from "./generic"; /** * Stores events in streams and consumer subscriptions/leases */ export interface Store extends Disposable { /** * Queries the event store * @param callback callback predicate * @param query optional query values * @returns number of records */ query: (callback: (event: CommittedEvent) => void, query?: AllQuery) => Promise; /** * Commits message into stream of aggregate id * @param stream stream name * @param events array of uncommitted events * @param metadata metadata * @param expectedVersion optional aggregate expected version to provide optimistic concurrency, raises concurrency exception when not matched * @returns array of committed events */ commit: (stream: string, events: Message[], metadata: CommittedEventMetadata, expectedVersion?: number) => Promise[]>; /** * Gets store stats * TODO: refactor stats using async projections */ stats: () => Promise; /** * Seeds the store */ seed: () => Promise; /** * Drops the store */ drop: () => Promise; } /** * Stores projections */ export interface ProjectorStore extends Disposable { /** * Loads projection records by id * @param ids the record ids * @returns the stored records by id */ load: (ids: string[]) => Promise[]>; /** * Commits projection map with basic idempotence check * @param map the projection map * @param watermark the new watermark - ignored when new watermark <= stored watermark * @returns the projection results */ commit: (map: ProjectionMap, watermark: number) => Promise; /** * Queries projection * @param query projection query * @returns array of records found */ query: (query: ProjectionQuery) => Promise[]>; /** * Aggregates projection * @param query aggregate query * @returns aggregate results */ agg: (query: AggQuery) => Promise>; /** * Seeds the store */ seed: (schema: Schema>, indexes: ProjectionSort[]) => Promise; /** * Drops the store */ drop: () => Promise; } /** * Stores subscriptions * - Poll: When no active lease found, creates new consumer lease if events are found after watermark * - Ack: Updates watermark if received before lease expiration */ export interface SubscriptionStore extends Disposable { /** * Polls the store for events created after a watermark * @param consumer consumer name * @param options poll options * @returns a new lease when events are found */ poll: (consumer: string, options: PollOptions) => Promise | undefined>; /** * Acknowledges consumer handling events on active lease * @param lease active lease * @param watermark new watermark poiting to the last consumed event * @returns false when lease expired */ ack: (lease: Lease, watermark: number) => Promise; /** * Gets stored subscriptions */ subscriptions: () => Promise; /** * Seeds the store */ seed: () => Promise; /** * Drops the store */ drop: () => Promise; } /** * High throughput FIFO message queue supporting multiple concurrent producers and * a controlled dequeuing process guaranteeing at-least-once ordered delivery to consumers of the same stream. * * Adapters should implement mechanisms to ensure message ordering and delivery guarantees. */ export interface MessageQueue extends Disposable { /** * Enqueues messages * @param messages the messages */ enqueue: (messages: Message[]) => Promise; /** * Dequeues message on top of the queue after being processed by consumer callback * @param callback consumer callback that receives the message with storage attributes {id, created} and returns a promise or error * @param opts optional options for dequeuing * @param opts.stream optional stream name to support independent concurrent consumers * @param opts.leaseMillis optional lease duration in milliseconds before lock expires (default dictated by adapter) * @returns promise that resolves true when message is successfully processed, false when stream is empty or lock cannot be acquired, * rejects when message has failed to be processed */ dequeue: (callback: (message: Message & { id: number | string; created: Date; }) => Promise, opts?: { stream?: string; leaseMillis?: number; }) => Promise; /** * Seeds the store */ seed: () => Promise; /** * Drops the store */ drop: () => Promise; } //# sourceMappingURL=stores.d.ts.map