import { F as FlowConfig, S as StepDefinition, P as ParallelBranchDefinition, a as ParallelGroupOptions, E as ExecuteOptions, b as SerializedError, R as RetryPolicy, L as Logger } from './types-D8r3B8Ax.cjs'; export { A as AcquireLockOptions, C as CompensateEvent, c as FlowEndEvent, d as FlowHooks, e as FlowStartEvent, f as FlowState, g as FlowStatus, h as Lock, i as ParallelStepDefinition, j as StepContext, k as StepEndEvent, l as StepRetryEvent, m as StepStartEvent, n as StepState, o as StepStatus, p as StorageAdapter } from './types-D8r3B8Ax.cjs'; export { MemoryStorage, createMemoryStorage } from './storage/memory.cjs'; /** * Compute the result type of a parallel group from its branches map. * For a branches object `{ a: { run: () => A }, b: { run: () => B } }` * the inferred type is `{ a: A; b: B }`. Promise return types are unwrapped * to match the final `ctx.results..` value. */ type Awaited2 = T extends Promise ? U : T; type ParallelBranchResults = { [K in keyof TBranches]: TBranches[K] extends { run: (...args: never[]) => infer R; } ? Awaited2 : never; }; /** * A Flow is a typed, ordered list of steps. The result type accumulates as * steps are added, so each subsequent step's `ctx.results` is statically * typed with every prior step's return value. */ type EmptyResults = {}; declare class Flow { readonly name: string; readonly config: FlowConfig; private readonly _steps; constructor(name: string, config?: FlowConfig); /** * Append a step. The step's return value is accumulated into TResults so * every downstream step's `ctx.results.` is statically typed. * * Duplicate step names are rejected at runtime (Flow.step will throw). */ step(name: TName, definition: StepDefinition): Flow; /** * Append a parallel step group (fan-out / fan-in). Each branch runs * concurrently via `Promise.all`. Results merge into a single object keyed * by branch name and become available downstream as * `ctx.results..`, fully typed. * * Behavior: * - Branches run concurrently. By default, the first failing branch aborts * its siblings via a shared `AbortSignal` (`abortOnFailure: true`). * - Compensation runs in parallel by default. Pass * `{ compensateSerially: true }` when there is a causal dependency * between branches that requires reverse-order rollback. * - Per-branch `retry`, `timeout`, and `compensate` work exactly like a * regular step. A group-level `groupTimeout` bounds the entire group. * - Crash recovery resumes only branches that did not finish — already * `success` branches are skipped, just like sequential steps. * * @example * createFlow<{ orderId: string }>('checkout') * .parallel('externals', { * pricing: { run: (ctx) => api.pricing(ctx.input.orderId) }, * shipping: { run: (ctx) => api.shipping(ctx.input.orderId) }, * tax: { run: (ctx) => api.tax(ctx.input.orderId), retry: { maxAttempts: 3 } }, * }) * .step('charge', { * run: (ctx) => charge(ctx.results.externals.pricing.amount), * }) */ parallel>>(name: TName, branches: TBranches, options?: ParallelGroupOptions): Flow; }>; /** Expose the registered step list for inspection (read-only copy). */ get steps(): ReadonlyArray<{ name: string; kind: 'sequential' | 'parallel'; branches?: string[]; }>; /** * Run the flow. Re-running with the same `idempotencyKey` returns the * previously-cached result (if succeeded) or resumes from the last * successful step (if the prior run was interrupted). */ execute(input: TInput, options?: ExecuteOptions): Promise; } /** * Create a new flow. Generic parameter defines the input shape; step results * are inferred from `.step()` calls. * * @example * const checkout = createFlow<{ orderId: string }>('checkout') * .step('reserve', { run: async (c) => reserve(c.input.orderId), compensate: release }) * .step('charge', { run: async (c) => charge(c.input.orderId), compensate: refund }) * * await checkout.execute({ orderId: '42' }, { idempotencyKey: 'order-42' }) */ declare function createFlow(name: string, config?: FlowConfig): Flow; /** Mark an error as permanently fatal — the executor must not retry it. */ declare class PermanentError extends Error { readonly permanent: true; readonly code?: string; constructor(message: string, options?: { cause?: unknown; code?: string; }); } /** Mark an error as transient — explicitly eligible for retry. */ declare class TransientError extends Error { readonly transient: true; readonly code?: string; constructor(message: string, options?: { cause?: unknown; code?: string; }); } /** Thrown when a step exceeds its configured timeout. Retryable by default. */ declare class StepTimeoutError extends Error { readonly stepName: string; readonly timeoutMs: number; readonly timeout: true; constructor(stepName: string, timeoutMs: number); } /** Thrown when execution is cancelled via AbortSignal. */ declare class FlowAbortedError extends Error { readonly aborted: true; constructor(reason?: unknown); } /** * Thrown when the storage adapter cannot acquire a lock within the configured * wait timeout — typically because another worker is currently executing the * same idempotency key. */ declare class LockAcquisitionError extends Error { readonly flowName: string; readonly flowId: string; constructor(flowName: string, flowId: string, reason?: string); } /** Thrown by the executor when a step fails and compensation runs. */ declare class FlowError extends Error { readonly flowId: string; readonly flowName: string; readonly failedStep: string; readonly originalError: unknown; readonly compensationErrors: Array<{ step: string; error: unknown; }>; constructor(message: string, flowId: string, flowName: string, failedStep: string, originalError: unknown, compensationErrors?: Array<{ step: string; error: unknown; }>); } /** Heuristic: errors are retryable unless explicitly marked permanent. */ declare function isPermanent(err: unknown): boolean; declare function isTransient(err: unknown): boolean; declare function serializeError(err: unknown): SerializedError; /** * Compute the delay (ms) before the next attempt. Attempt numbers are 1-based; * `attempt` here is the attempt that just failed, so the next attempt is * `attempt + 1` and waits for the delay returned here. */ declare function computeDelay(policy: RetryPolicy | undefined, attempt: number): number; /** * Decide whether `error` should trigger another attempt given the current * policy and attempt count. Callers still need to enforce maxAttempts. */ declare function shouldRetryError(policy: RetryPolicy | undefined, error: unknown, attempt: number): boolean; declare function getMaxAttempts(policy: RetryPolicy | undefined): number; /** Discards all log output. Default when the user configures no logger. */ declare const silentLogger: Logger; /** Minimal console-backed logger, useful for local debugging. */ declare const consoleLogger: Logger; export { ExecuteOptions, Flow, FlowAbortedError, FlowConfig, FlowError, LockAcquisitionError, Logger, ParallelBranchDefinition, ParallelGroupOptions, PermanentError, RetryPolicy, SerializedError, StepDefinition, StepTimeoutError, TransientError, computeDelay, consoleLogger, createFlow, getMaxAttempts, isPermanent, isTransient, serializeError, shouldRetryError, silentLogger };