import type { ContextInternals } from './internals.ts'; /** * Options for `ctx.onUpdate`. Currently supports an optional pre-acceptance * validator that runs before the update payload is durably written. * * @example * ```ts * import { workflow, Engine, update } from '@lostgradient/weft'; * import type { UpdateHandlerOptions } from '@lostgradient/weft'; * * const setAge = update<{ age: number }, void>('setAge'); * const engine = new Engine(); * engine.register( * workflow({ name: 'demo' }).execute(async function* (ctx) { * const options: UpdateHandlerOptions = { * validator: (v): unknown => { * const age = (v as Record)['age']; * if (typeof age !== 'number' || age < 0) { * return { issues: [{ message: 'age must be non-negative' }] }; * } * return undefined; * }, * }; * ctx.onUpdate(setAge, () => undefined, options); * await new Promise(() => {}); * }), * ); * void engine; * ``` */ export type UpdateHandlerOptions = { /** * Pre-acceptance validator. Runs at the engine boundary before the payload * is durably written or the workflow observes it. * * - **Throw** to reject: the thrown error message is wrapped into an * `UpdateValidationError`. * - **Return `{ issues: [...] }`** (Standard Schema v1 failure result) to * reject with structured messages. * - **Return anything else** (including `undefined`) to accept. */ readonly validator?: (payload: unknown) => unknown; }; export declare function onUpdate(internals: ContextInternals, name: string, handler: (payload: unknown) => unknown, options?: UpdateHandlerOptions): void; export declare function onQuery(internals: ContextInternals, name: string, handler: (input: unknown) => unknown): void; export declare function expose(internals: ContextInternals, accessors: Record unknown>): void;