/** * vapor-chamber — Utility layer * * createChamber, createWorkflow, createReaction * * These use only the public BaseBus interface. They are optional and tree-shaken. */ import type { BaseBus, Command, CommandResult, Handler, RegisterOptions } from './command-bus'; export type ChamberHandlers = Record; export type ChamberOptions = { /** Per-action registration options (undo, throttle). */ options?: Record; }; export interface Chamber { /** Namespace prefix (e.g. 'cart'). */ readonly namespace: string; /** Install all handlers on a bus. Returns uninstall function. */ install(bus: BaseBus): () => void; /** Get the prefixed action name (e.g. 'add' → 'cartAdd'). */ actionName(shortName: string): string; } /** * createChamber — groups related handlers under a namespace. * The declarative counterpart to `useCommandGroup`. * * @example * const cart = createChamber('cart', { * add: handleCartAdd, * remove: handleCartRemove, * clear: handleCartClear, * }); * const uninstall = cart.install(bus); * // Registers: cartAdd, cartRemove, cartClear */ export declare function createChamber(namespace: string, handlers: ChamberHandlers, opts?: ChamberOptions): Chamber; export type WorkflowStep = { /** Action name to dispatch. */ action: string; /** If this step fails, dispatch this action to compensate previous steps. */ compensate?: string; /** Map the workflow target/payload into step-specific target. */ mapTarget?: (target: any, payload?: any) => any; /** Map the workflow target/payload into step-specific payload. */ mapPayload?: (target: any, payload?: any) => any; }; export type WorkflowResult = { ok: boolean; /** Results of each step that executed (in order). */ results: CommandResult[]; /** If failed, the step index that caused the failure. */ failedAt?: number; /** Error from the failed step. */ error?: Error; /** Results of compensation steps (in reverse order). */ compensations?: CommandResult[]; }; export interface Workflow { /** Execute the workflow. Async because compensation may involve async buses. */ run(bus: BaseBus, target: any, payload?: any): Promise; /** The step definitions. */ readonly steps: readonly WorkflowStep[]; } /** * createWorkflow — sequential commands with automatic compensation on failure. * * @example * const checkout = createWorkflow([ * { action: 'cartValidate' }, * { action: 'paymentReserve', compensate: 'paymentRelease' }, * { action: 'orderCreate', compensate: 'orderCancel' }, * { action: 'cartClear' }, * ]); * const result = await checkout.run(bus, { cartId, paymentInfo }); * // If orderCreate fails → paymentRelease runs automatically */ export declare function createWorkflow(steps: WorkflowStep[]): Workflow; export type ReactionOptions = { /** Only react when this predicate returns true. */ when?: (cmd: Command, result: CommandResult) => boolean; /** Transform the source command into the target command's target. */ map?: (cmd: Command, result: CommandResult) => any; /** Transform the source command into the target command's payload. */ mapPayload?: (cmd: Command, result: CommandResult) => any; }; export interface Reaction { /** Install the reaction on a bus. Returns unsubscribe function. */ install(bus: BaseBus): () => void; } /** * createReaction — declarative cross-chamber dispatch rules. * Explicit edges between domain modules. * * @example * createReaction('cartAdd', 'inventoryCheck', { * when: (cmd, result) => result.ok, * map: (cmd) => ({ itemId: cmd.payload.itemId }), * }).install(bus); */ export declare function createReaction(sourcePattern: string, targetAction: string, options?: ReactionOptions): Reaction; //# sourceMappingURL=utilities.d.ts.map