import type { Actor, CommittedEvent, Message, Messages, Patch, State } from "./messages"; import type { ProjectionMap, ProjectionPatch } from "./projection"; /** * State reducers apply partial state patches to a state, and returns the new state * - `state` the original state * - `patch` the patches to apply, considering rules like: * - using `undefined` values to delete fields from the original state * - recursively merging vs copying objects (like arrays) */ export type StateReducer = (state: Readonly, patch: Readonly> | undefined) => Readonly; /** * Event reducers apply events to a reduced state, and returns the new patch * - `state` the current reduced state * - `event` the event to be applied */ export type EventReducer = (state: Readonly, event: CommittedEvent>) => Readonly>; /** * Projector reducers apply events as "state patches" to the resulting projection map * - `event` the committed event being projected * - `map` a reference to the resulting projection map */ export type ProjectorReducer = (event: CommittedEvent>, map: ProjectionMap) => Promise[]>; /** * Command handlers handle commands and emit events * - `data` the command's payload * - `state` the state of the artifact handling this command - Empty for systems * - `actor?` the actor invoking the command */ export type CommandHandler = (data: Readonly, state: Readonly, actor?: Actor) => Promise[]>; /** * Invariants validate aggregate preconditions before processing commands, * allowing state and authorization checks in a declarative way */ export type Invariant = { description: string; valid: (state: Readonly, actor?: Actor) => boolean; }; /** * Actor handlers extract process manager actor ids from input events * - `event` the committed event being handled */ export type ActorHandler = (event: CommittedEvent>) => string; //# sourceMappingURL=handlers.d.ts.map