import type { AggregateFactory, CommandAdapterFactory, CommandHandlerFactory, EventHandlerFactory, ProjectorFactory } from "./factories"; import type { AllQuery, CommandTarget, CommittedEvent, Message, Messages, Snapshot, State } from "./messages"; import type { AggQuery, AggResult, ProjectionQuery, ProjectionRecord, ProjectionResults } from "./projection"; /** * Response from event handlers * * - `id`: the event id * - `error?`: error message when failed * - `command?` the command triggered by the event handler when handled by policies * - `state?` the reducible state when handled by process managers */ export type EventResponse = { readonly id: number; readonly error?: string; readonly command?: Message; readonly state?: S; }; export type Client = { /** * Invokes command through adapter * @param factory adapter factory * @param payload message payload * @returns last snapshot produced by command */ invoke:

(factory: CommandAdapterFactory, payload: P) => Promise | undefined>; /** * Handles command * @param factory the command handler factory (aggregate or system) * @param name the command name * @param data the command payload * @param target the command target * @returns last snapshot produced by command */ command: (factory: CommandHandlerFactory, name: N, data: Readonly, target: CommandTarget, skipValidation?: boolean) => Promise | undefined>; /** * Validates and handles event message * @param factory the event handler factory (policy, process manager, or projector) * @param event the committed event to be handled * @returns response, including command or projection side effects */ event: (factory: EventHandlerFactory, event: CommittedEvent) => Promise>; /** * Loads current aggregate snapshot * @param factory the aggregate factory * @param stream the aggregate stream id * @param callback optional reduction predicate to act on each snapshot * @returns current model state */ load: (reducible: AggregateFactory, stream: string, callback?: (snapshot: Snapshot) => void) => Promise>; /** * Queries the store - all streams * @param query query parameters * @param callback optional event predicate * @returns query summary */ query: (query: AllQuery, callback?: (event: CommittedEvent) => void) => Promise<{ first?: CommittedEvent; last?: CommittedEvent; count: number; }>; /** * Projects events into a projection * @param factory the projector factory * @param events the committed events to project * @returns the projection */ project: (factory: ProjectorFactory, events: CommittedEvent[]) => Promise; /** * Reads projection records by id or query * @param factory the projector factory * @param query the record id(s) or a query * @returns the matched records */ read: (factory: ProjectorFactory, query: string | string[] | ProjectionQuery) => Promise[]>; /** * Aggregates projection records * @param factory the projector factory * @param query the aggregate query * @returns the aggregate results */ agg: (factory: ProjectorFactory, query: AggQuery) => Promise>; }; //# sourceMappingURL=client.d.ts.map