import { type BatchOperation, type ConditionalBatchCondition } from '../../../storage/interface.ts'; import type { Checkpoint, StartOptions, TimerEntry, WorkflowState } from '../../types.ts'; import type { EngineInternals } from '../internals.ts'; import type { WorkflowConcurrencyStartOperations } from '../workflow-concurrency.ts'; import { type LifecycleCallbacks, type RegistrationEntry } from './shared.ts'; /** * Builds the id-dependent operations and compare-and-swap preconditions for an * idempotent start or `startOrSignal`. Invoked by `startWorkflow` with the real * `workflowId` once it has been generated, so the idempotency mapping put (and * any create-batch signal) can carry that id. The whole start batch then commits * through a single `storageConditionalBatch` gated on the returned conditions; a * lost CAS rolls back the start and throws {@link StartIdempotencyRaceLostError} * so the caller resolves to the winner. */ export type BuildIdempotentStartOperations = (workflowId: string) => { operations: BatchOperation[]; conditions: ConditionalBatchCondition[]; }; /** * The `conditionalBatch` precondition half of {@link buildCatalogEntryStartPrecondition} * — a bare `type`/`revision` pair rather than a full `WorkflowState`, so it * is also reusable by a checkpoint-backed failed-run retry's reactivation * commit (`bulk-operations-retry.ts`, WFT-17/18 Codex review on PR #958), * which has no `WorkflowState & { revision: string }` narrowing of its own * and — unlike a fresh start — carries no `inFlightStartsByRevision` * reservation to close the SAME-process half of this race, so it needs this * fence unconditionally rather than only under `ownershipMode !== 'none'`. * Exported (rather than kept local to this module) specifically for that * reuse; returns the bare {@link ConditionalBatchCondition} so callers never * need this module's own non-exported {@link TaggedStartCondition} shape. */ export declare function buildCatalogEntryRevisionCondition(internals: EngineInternals, type: string, revision: string): Promise; /** Everything {@link buildAndCommitStartBatch} needs to assemble the start batch. */ export type StartBatchContext = { internals: EngineInternals; workflowId: string; state: WorkflowState; checkpoint: Checkpoint; registration: RegistrationEntry; options: StartOptions | undefined; delayedStartTimer: TimerEntry | undefined; persistedWorkflowStartHeaders: Map | undefined; additionalStartOperations: BatchOperation[] | undefined; buildWorkflowConcurrencyStartOperations: (() => Promise) | undefined; callbacks: LifecycleCallbacks; /** * Storage deletes for a prior terminal run being displaced by an * `onTerminalConflict: 'start-new'` restart. Prepended ahead of the create puts * so purge-and-recreate commit as one atomic batch (see * {@link buildStartBatchOperations}). Undefined for an ordinary start. */ purgeDeleteOperations: BatchOperation[] | undefined; /** * Compare-and-swap precondition making the caller-supplied-id duplicate check * atomic with this commit (WFT-152). Built by `resolveTerminalConflictForRestart` * from the exact bytes its duplicate-id read observed, and carried here as the * `duplicateIdCondition` of the `StartDuplicateIdDecision` it returns. Undefined * for a generated id, which cannot collide and so keeps the unconditioned hot * path. */ duplicateIdCondition: ConditionalBatchCondition | undefined; /** ADDITIONAL WFT-153 precondition on observed `wf-gen:` bytes; see `StartDuplicateIdDecision.duplicateIdGenerationCondition` in `start-terminal-conflict-purge.ts`. Undefined exactly when `duplicateIdCondition` is. */ duplicateIdGenerationCondition: ConditionalBatchCondition | undefined; }; /** * Assemble the start batch — folding in the id-dependent idempotency mapping and * create-batch signal once the real workflow id exists — and commit it, gated on * any idempotency preconditions. Throws {@link StartIdempotencyRaceLostError} * when a concurrent same-key caller won the compare-and-swap, so the calling * `startWorkflow` rolls back its transient state and the wrapper resolves to the * winning run. */ export declare function buildAndCommitStartBatch(context: StartBatchContext, buildIdempotentStartOperations: BuildIdempotentStartOperations | undefined): Promise;