import { EventEmitter } from "node:events"; import type { ZodType } from "zod"; import type { Disposable, ProjectorStore } from "./interfaces"; import type { ArtifactFactory, ArtifactType, Messages, Projection, ProjectionResults, ProjectionSort, ProjectorFactory, ReducibleFactory, Schema, Scope, Snapshot, State } from "./types"; /** * Internal message details used as main drivers of public interfaces and documentation */ export type MessageMetadata = { name: keyof M; schema: ZodType; type: "command" | "event" | "message"; handlers: string[]; producer?: string; }; /** * Artifact reflected metadata */ export type ArtifactMetadata = { type: ArtifactType; factory: ArtifactFactory; schema?: Schema; inputs: Array<{ name: string; scope: Scope; }>; outputs: string[]; projector?: { schema: Schema>; store: ProjectorStore; indexes: ProjectionSort[]; }; }; /** * Returns true to commit state in stream * @param snapshot - current snapshot */ export type CommitPredicate = (snapshot: Snapshot) => boolean; /** * Registration options * - `scope?` the scope used to publish message handlers * - `store?` a projector store associated with projectors * - `commit?` flags when to store state snapshots in the aggregate stream */ export type WithOptions = { scope?: Scope; projector?: { store: ProjectorStore; indexes: ProjectionSort[]; }; commit?: CommitPredicate; }; export declare interface Builder { on(event: "commit", listener: (args: { factory: ReducibleFactory; snapshot?: Snapshot; }) => void): this; on(event: "projection", listener: (args: { factory: ProjectorFactory; results: ProjectionResults; }) => void): this; } /** * Abstract application builder * * Concrete adapters should provide disposers and the listening framework */ export declare abstract class Builder extends EventEmitter implements Disposable { abstract readonly name: string; abstract listen(): Promise; dispose(): Promise; private _hasStreams; readonly messages: Map>; readonly artifacts: Map>; readonly commits: Map>; constructor(); private _reflect; /** * Flags app with streams */ withStreams(): this; get hasStreams(): boolean; /** * Registers factory * @param factory the artifact factory * @param options the artifact options */ with(factory: ArtifactFactory, options?: WithOptions): this; /** * Builds message handlers * Concrete app adapters should provide their own building steps * @returns optional internal application object (e.g. express) */ build(): unknown | undefined; } //# sourceMappingURL=builder.d.ts.map