import type { BatchOperation } from '../../storage/interface.ts'; import type { ComposedWorkflowInterceptor } from '../interceptor.ts'; import type { SignalDeliveryOptions, WorkflowState } from '../types.ts'; import type { EngineInternals } from './internals.ts'; type TrackedWaiterKeys = string | Set; export type SignalCallbacks = { loadWorkflowState: (workflowId: string) => Promise; dispatchEvent: (event: Event) => boolean; broadcast: (message: { type: 'signal:received'; workflowId: string; signalName: string; }) => void; getComposedInterceptor: () => ComposedWorkflowInterceptor | null | undefined; resumeParkedInlineWorkflow: (workflowId: string) => Promise; }; export type BufferedSignalOptions = { emitPublicEvent?: boolean; signalId?: string; }; export type BufferedSignalDelivery = { signalName: string; payload: unknown; options?: BufferedSignalOptions; }; export type ConsumedSignalResult = { found: false; } | { found: true; payload: unknown; }; export declare function signal(internals: EngineInternals, workflowId: string, name: string, payload: unknown, callbacks: SignalCallbacks, options?: SignalDeliveryOptions): Promise; /** * Remove the signal waiter registered under `waiterKey`, optionally only when * it is still `expectedResolve`. * * Returns whether THIS call removed that exact waiter. Callers that go on to * invoke the resolver must gate on the return value: a waiter captured before * an await can be replaced by replay or a fresh park while that await is in * flight, and invoking the captured resolver anyway advances a superseded * generator even though the replacement was correctly left in place. */ export declare function releaseSignalWaiter(internals: EngineInternals, workflowId: string, waiterKey: string, expectedResolve?: () => void): boolean; export declare function bufferSignalPayloads(internals: EngineInternals, workflowId: string, deliveries: BufferedSignalDelivery[], callbacks: SignalCallbacks, defaultOptions?: SignalDeliveryOptions): Promise; /** * Build the durable operations for a single keyed signal so it can be folded * into a workflow's create batch by {@link startOrSignal}. Writes the same pair * the live signal path writes — the `sig:` payload (consumed on first drive by * `processWaitSignalOperation`) and the `sigres:` accepted-response marker — so a * concurrent caller that falls back to the standard signal path dedups against * the SAME `signalId`. The accepted-response marker is consumption-independent: * even after the winning run consumes the `sig:` payload, a late loser finds the * `sigres:` key and short-circuits instead of re-delivering, which is what * guarantees "one signal per signalId" across the create and signal paths. * * Returns both the put operations and the CAS condition. The condition gates on * the `sigres:` accepted-response marker (the dedup identity, keyed by signalId * alone), NOT the `sig:` payload key: the FIFO sort-class (#458) makes the * start-signal's `sig:` key (class `0`) differ from the live signal path's (class * `1`), so a `sig:`-keyed CAS would no longer collide with a pre-buffered signal * of the same signalId and would buffer a second copy. The class-independent * `sigres:` marker is what both paths share, so gating on it preserves "one * signal per signalId" across the create and signal paths. */ export declare function buildCreateBatchSignalOperations(internals: EngineInternals, workflowId: string, signalName: string, payload: unknown, signalId: string): { operations: BatchOperation[]; condition: { key: string; expectedValue: null; }; }; export declare function hasBufferedSignal(internals: EngineInternals, workflowId: string, signalName: string): Promise; export declare function consumeSignal(internals: EngineInternals, workflowId: string, signalName: string): Promise; export declare function consumeSignalWithAtomicWorkflowCommit(internals: EngineInternals, workflowId: string, signalName: string): Promise; /** * Read the first buffered signal payload WITHOUT deleting it. Use when a caller * must check for a buffered signal but might not end up consuming it — e.g. a * `ctx.race` / `ctx.all` wait-signal branch that could lose, where a destructive * {@link consumeSignal} on the losing path would silently drop the signal. The * winner calls {@link consumeSignalWithAtomicWorkflowCommit} to stage the * durable delete into the checkpoint batch. */ export declare function peekSignal(internals: EngineInternals, workflowId: string, signalName: string): Promise; /** Register a waiter key in a workflow-keyed reverse index. */ export declare function trackWaiterKey(reverseIndex: Map, workflowId: string, waiterKey: string): void; /** Remove a waiter key from a workflow-keyed reverse index. */ export declare function untrackWaiterKey(reverseIndex: Map, workflowId: string, waiterKey: string): void; export {};