import { a as TimeoutError, i as RetryExhaustedError, o as UnhandledException, t as CancellationError } from "./errors-CmmADuBm.js"; import { a as AllSettledResult, d as TaskResult, f as TaskValidation, i as AllOptions, n as FlowResult, o as InferredTaskContext, p as AsyncDisposer, r as InferredFlowTaskContext, u as TaskRecord } from "./flow-BxKpmKTg.js"; //#region src/lib/execution/context.d.ts interface RetryInfo { attempt: number; limit: number; } interface BaseTryCtx { signal?: AbortSignal; } type TryCtxFor = HasRetry extends true ? BaseTryCtx & { retry: RetryInfo; } : BaseTryCtx; type TryCtx = TryCtxFor; //#endregion //#region src/lib/policies/retry.d.ts interface BaseRetryPolicy { /** * Maximum number of attempts, including the first run. */ limit: number; /** * Delay in milliseconds between attempts. Defaults to 0. */ delayMs?: number; /** * Adds random jitter to delays when enabled. */ jitter?: boolean; /** * Return true to retry after an error, false to stop. */ shouldRetry?: (error: unknown, ctx: TryCtx) => boolean; } interface LinearBackoffRetryPolicy extends BaseRetryPolicy { /** * Use linearly increasing delay between attempts. */ backoff: "linear"; /** * Not supported for linear backoff. */ maxDelayMs?: never; } interface ExponentialBackoffRetryPolicy extends BaseRetryPolicy { /** * Use exponential delay growth between attempts. */ backoff: "exponential"; /** * Optional cap for exponential delay in milliseconds. */ maxDelayMs?: number; } /** * Retry policy using a constant delay strategy. */ interface ConstantBackoffRetryPolicy extends BaseRetryPolicy { /** * Required discriminant: use a fixed delay between attempts. */ backoff: "constant"; /** * Not supported for constant backoff. */ maxDelayMs?: never; } /** * Retry configuration object. */ type RetryPolicy = LinearBackoffRetryPolicy | ExponentialBackoffRetryPolicy | ConstantBackoffRetryPolicy; /** * Retry shorthand or full retry configuration. * * - `number`: attempt limit * - `RetryPolicy`: detailed retry settings */ type RetryOptions = number | RetryPolicy; declare const INVALID_RETRY_LIMIT: unique symbol; type InvalidRetryLimit = { readonly [INVALID_RETRY_LIMIT]: "retry() requires a positive integer limit"; }; /** * Compile-time validation for literal retry limits. Rejects `0`, negative, and fractional literals; * non-literal `number` values pass and are validated at runtime by {@link retryOptions} instead. * (`Infinity`/`NaN` have no literal types, so they are runtime-only.) */ type ValidateRetryLimit = number extends N ? number : `${N}` extends `-${string}` | `${string}.${string}` ? InvalidRetryLimit : N extends 0 ? InvalidRetryLimit : number; /** * Compile-time validation for full {@link RetryOptions} values, including unions of number and * policy forms. Distributes over union members so that mixed inputs like `flag ? 3 : { backoff: * "constant", limit: 5 }` are accepted while any member carrying an invalid literal limit still * fails to compile. */ type ValidateRetryOptions

= P extends number ? ValidateRetryLimit

: P extends { limit: infer N extends number; } ? { limit: ValidateRetryLimit; } : never; declare function retryOptions(policy: RetryOptions): RetryPolicy; //#endregion //#region src/lib/utils.d.ts type NonPromise = T extends PromiseLike ? never : T; //#endregion //#region src/lib/execution/run.d.ts type RunTryFn = (ctx: Ctx) => NonPromise | Promise; type RunCatchFn = (error: unknown) => NonPromise | Promise; interface RunAsyncOptions { try: RunTryFn; /** * Maps errors that originated inside `try` — thrown directly, or carried out of the retry loop as * the last attempt's error once the retry policy gives up. Policy outcomes (timeout, * cancellation) and defects (`Panic`) never pass through `catch`: they are reported directly, * even when they fire while the handler is running. */ catch: RunCatchFn; } type AsyncRunInput = RunTryFn | RunAsyncOptions; //#endregion //#region src/lib/execution/run-sync.d.ts type SyncRunTryFn = (ctx: Ctx) => NonPromise; type SyncRunCatchFn = (error: unknown) => NonPromise; interface SyncRunOptions { try: SyncRunTryFn; /** * Maps errors that originated inside `try` — thrown directly, or carried out of the retry loop as * the last attempt's error once the retry policy gives up. Policy outcomes (timeout, * cancellation) and defects (`Panic`) never pass through `catch`: they are reported directly, * even when they fire while the handler is running. */ catch: SyncRunCatchFn; } type SyncRunInput = SyncRunTryFn | SyncRunOptions; //#endregion //#region src/lib/builder.d.ts /** * Wraps are observational hooks: they can inspect execution context and surround execution, but * they must not mutate context or replace it. */ type WrapCtx = Readonly> & { readonly retry: Readonly; }; type WrapFn = (ctx: WrapCtx, next: () => unknown) => unknown; interface BuilderConfig { /** * Retry configuration applied to the run. */ retry?: RetryPolicy; /** * Timeout configuration applied to the run. */ timeout?: number; /** * Abort signals used to cancel execution. */ signals?: AbortSignal[]; /** * Wrapper middleware chain around execution. */ wraps?: WrapFn[]; } type ConfigRunErrors = TimeoutError | CancellationError; /** * The failure type for try functions without a catch handler. With retry configured, any give-up * (limit exhausted or `shouldRetry` declining) is reported as {@link RetryExhaustedError} carrying * the last attempt's error as `cause`; otherwise failures are wrapped in {@link UnhandledException}. */ type UnmappedError = HasRetry extends true ? RetryExhaustedError : UnhandledException; type OrchestrationMethods = "all" | "allSettled" | "flow"; type AsyncPolicyHiddenMethods = "runSync" | "wrap" | (SupportsOrchestration extends true ? never : OrchestrationMethods); type ExecutionBuilderSurface = Omit, OrchestrationMethods | "wrap">; /** * Surface after an async policy (`timeout`/`signal`): sync execution and further wraps are gone, * orchestration stays available unless retry already removed it. */ type AsyncPolicyBuilderSurface = Omit, AsyncPolicyHiddenMethods>; type AsyncExecutionBuilderSurface = AsyncPolicyBuilderSurface; declare class RunBuilder { protected readonly config: BuilderConfig; constructor(config?: BuilderConfig); protected buildTimeoutConfig(ms: number): BuilderConfig; protected buildSignalConfig(signal: AbortSignal): BuilderConfig; retry(policy: N & ValidateRetryLimit): ExecutionBuilderSurface; retry(policy: RetryPolicy & { limit: N & ValidateRetryLimit; }): AsyncExecutionBuilderSurface; retry(policy: P & ValidateRetryOptions

): AsyncExecutionBuilderSurface; /** * Applies one total deadline to the next terminal call. For `run`, the deadline spans attempts, * delays, and catch handling, and surfaces typed as {@link TimeoutError}. For orchestration * (`all`/`allSettled`/`flow`), it is a whole-graph deadline: the task signal aborts when it fires * and the orchestration rejects with {@link TimeoutError} (cancellation still wins when both * fire). The deadline is cooperative — orchestration waits for in-flight tasks to settle before * rejecting, so tasks must observe `$signal` for it to bound wall-clock time. */ timeout(ms: number): AsyncPolicyBuilderSurface; signal(signal: AbortSignal): AsyncPolicyBuilderSurface; wrap(fn: WrapFn): RunBuilder; /** * Executes an async unit of work. * * `catch` maps errors that originated inside `try` — thrown directly, or carried out of the retry * loop as the last attempt's error once the retry policy gives up. Policy outcomes ({@link * TimeoutError}, {@link CancellationError}) and defects (`Panic`) never pass through `catch`; they * surface typed in the return union (or are thrown, for `Panic`). * * Without `catch`, unmapped failures are wrapped: {@link RetryExhaustedError} when a retry policy * gave up, {@link UnhandledException} otherwise. The original error is available as `cause`. */ run(tryFn: RunTryFn>): Promise | E>; run(options: AsyncRunInput>): Promise; /** * Executes a sync unit of work. * * Follows the same `catch` contract as {@link RunBuilder.run}: `catch` maps try-originated errors * (including retry give-up); policy outcomes and defects never pass through it. */ runSync(tryFn: SyncRunTryFn>): T | UnmappedError | E; runSync(input: SyncRunInput>): T | C | E; all(tasks: T & TaskValidation> & ThisType>, options?: AllOptions): Promise<{ [K in keyof T]: TaskResult; } | C>; allSettled(tasks: T & TaskValidation> & ThisType>): Promise>; flow(tasks: T & ThisType>): Promise>; } //#endregion //#region src/lib/dispose.d.ts /** * Creates an {@link AsyncDisposer}: register cleanup with `defer(fn)` or `use(resource)`, then run * teardown with `await d.dispose()` or by declaring the disposer with `await using`. */ declare function disposer(): AsyncDisposer; //#endregion //#region src/lib/gen.d.ts type GenUnwrap = Exclude, Error>; type GenUse = (value: T) => Generator, GenUnwrap>; type GenErrors = Extract, Error>; type CheckIsAsync = Extract> extends never ? false : true; type GenResult = CheckIsAsync extends true ? Promise | GenErrors> : Awaited | GenErrors; declare function driveGen(factory: (useFn: GenUse) => Generator): GenResult; //#endregion //#region src/index.d.ts declare const all: RunBuilder["all"]; declare const allSettled: RunBuilder["allSettled"]; declare const flow: RunBuilder["flow"]; declare const retry: RunBuilder["retry"]; declare const run: RunBuilder["run"]; declare const runSync: RunBuilder["runSync"]; declare const signal: RunBuilder["signal"]; declare const timeout: RunBuilder["timeout"]; declare const wrap: RunBuilder["wrap"]; //#endregion export { all, allSettled, disposer, flow, driveGen as gen, retry, retryOptions, run, runSync, signal, timeout, wrap }; //# sourceMappingURL=index.d.ts.map