awaitly 1.31.1 → 1.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters.cjs +2 -2
- package/dist/adapters.cjs.map +1 -1
- package/dist/adapters.d.cts +3 -1
- package/dist/adapters.d.ts +3 -1
- package/dist/adapters.js +2 -2
- package/dist/adapters.js.map +1 -1
- package/dist/batch.cjs +2 -2
- package/dist/batch.cjs.map +1 -1
- package/dist/batch.d.cts +3 -1
- package/dist/batch.d.ts +3 -1
- package/dist/batch.js +2 -2
- package/dist/batch.js.map +1 -1
- package/dist/circuit-breaker.cjs +2 -2
- package/dist/circuit-breaker.cjs.map +1 -1
- package/dist/circuit-breaker.d.cts +3 -1
- package/dist/circuit-breaker.d.ts +3 -1
- package/dist/circuit-breaker.js +2 -2
- package/dist/circuit-breaker.js.map +1 -1
- package/dist/conditional.d.cts +3 -1
- package/dist/conditional.d.ts +3 -1
- package/dist/core.cjs +2 -2
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +2 -1
- package/dist/core.d.ts +2 -1
- package/dist/core.js +2 -2
- package/dist/core.js.map +1 -1
- package/dist/diagnostics.cjs +3 -3
- package/dist/diagnostics.cjs.map +1 -1
- package/dist/diagnostics.d.cts +3 -1
- package/dist/diagnostics.d.ts +3 -1
- package/dist/diagnostics.js +3 -3
- package/dist/diagnostics.js.map +1 -1
- package/dist/durable.cjs +3 -3
- package/dist/durable.cjs.map +1 -1
- package/dist/durable.d.cts +8 -361
- package/dist/durable.d.ts +8 -361
- package/dist/durable.js +3 -3
- package/dist/durable.js.map +1 -1
- package/dist/engine.cjs +11 -0
- package/dist/engine.cjs.map +1 -0
- package/dist/engine.d.cts +114 -0
- package/dist/engine.d.ts +114 -0
- package/dist/engine.js +11 -0
- package/dist/engine.js.map +1 -0
- package/dist/errors-entry-CMH73Eym.d.cts +339 -0
- package/dist/errors-entry-DOt5UUl4.d.ts +339 -0
- package/dist/errors.cjs +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts +2 -318
- package/dist/errors.d.ts +2 -318
- package/dist/errors.js +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/fetch.cjs +2 -2
- package/dist/fetch.cjs.map +1 -1
- package/dist/fetch.d.cts +3 -1
- package/dist/fetch.d.ts +3 -1
- package/dist/fetch.js +2 -2
- package/dist/fetch.js.map +1 -1
- package/dist/functional.cjs +1 -1
- package/dist/functional.cjs.map +1 -1
- package/dist/functional.d.cts +2 -0
- package/dist/functional.d.ts +2 -0
- package/dist/functional.js +1 -1
- package/dist/functional.js.map +1 -1
- package/dist/{guards-PU64_GKv.d.cts → guards-B79mP5Q8.d.cts} +3 -3
- package/dist/{guards-B5lgMJq0.d.ts → guards-BUq6NJCM.d.ts} +3 -3
- package/dist/{hitl-Dyiy0R1v.d.cts → hitl-BCqkMAHw.d.cts} +2 -2
- package/dist/{hitl-BjeSm1sJ.d.ts → hitl-BZtPx0aU.d.ts} +2 -2
- package/dist/hitl.cjs +2 -2
- package/dist/hitl.cjs.map +1 -1
- package/dist/hitl.d.cts +9 -6
- package/dist/hitl.d.ts +9 -6
- package/dist/hitl.js +2 -2
- package/dist/hitl.js.map +1 -1
- package/dist/index-BVUAOWGG.d.ts +417 -0
- package/dist/index-CQnpmUcC.d.cts +417 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/otel.d.cts +3 -1
- package/dist/otel.d.ts +3 -1
- package/dist/{persistence-entry-B3ukwbb5.d.ts → persistence-entry-ClFhxd2Q.d.ts} +11 -5
- package/dist/{persistence-entry-CgVzswbg.d.cts → persistence-entry-jflY61az.d.cts} +11 -5
- package/dist/persistence.d.cts +6 -3
- package/dist/persistence.d.ts +6 -3
- package/dist/policies.d.cts +3 -1
- package/dist/policies.d.ts +3 -1
- package/dist/ratelimit.cjs +2 -2
- package/dist/ratelimit.cjs.map +1 -1
- package/dist/ratelimit.d.cts +3 -1
- package/dist/ratelimit.d.ts +3 -1
- package/dist/ratelimit.js +2 -2
- package/dist/ratelimit.js.map +1 -1
- package/dist/reliability.cjs +2 -2
- package/dist/reliability.cjs.map +1 -1
- package/dist/reliability.d.cts +3 -1
- package/dist/reliability.d.ts +3 -1
- package/dist/reliability.js +2 -2
- package/dist/reliability.js.map +1 -1
- package/dist/resolver.cjs +2 -2
- package/dist/resolver.cjs.map +1 -1
- package/dist/resolver.d.cts +5 -3
- package/dist/resolver.d.ts +5 -3
- package/dist/resolver.js +2 -2
- package/dist/resolver.js.map +1 -1
- package/dist/resource.cjs +2 -2
- package/dist/resource.cjs.map +1 -1
- package/dist/resource.d.cts +3 -1
- package/dist/resource.d.ts +3 -1
- package/dist/resource.js +2 -2
- package/dist/resource.js.map +1 -1
- package/dist/result/retry.cjs +1 -1
- package/dist/result/retry.cjs.map +1 -1
- package/dist/result/retry.d.cts +2 -0
- package/dist/result/retry.d.ts +2 -0
- package/dist/result/retry.js +1 -1
- package/dist/result/retry.js.map +1 -1
- package/dist/result.cjs +1 -1
- package/dist/result.cjs.map +1 -1
- package/dist/result.d.cts +8 -23
- package/dist/result.d.ts +8 -23
- package/dist/result.js +1 -1
- package/dist/result.js.map +1 -1
- package/dist/{run-entry-C1uFytM6.d.cts → run-entry-rw7zll_G.d.ts} +16 -45
- package/dist/{run-entry-C1uFytM6.d.ts → run-entry-yQu63Yj9.d.cts} +16 -45
- package/dist/run.cjs +2 -2
- package/dist/run.cjs.map +1 -1
- package/dist/run.d.cts +3 -1
- package/dist/run.d.ts +3 -1
- package/dist/run.js +2 -2
- package/dist/run.js.map +1 -1
- package/dist/saga.cjs +2 -2
- package/dist/saga.cjs.map +1 -1
- package/dist/saga.d.cts +3 -1
- package/dist/saga.d.ts +3 -1
- package/dist/saga.js +2 -2
- package/dist/saga.js.map +1 -1
- package/dist/singleflight.d.cts +3 -1
- package/dist/singleflight.d.ts +3 -1
- package/dist/streaming.cjs +4 -4
- package/dist/streaming.cjs.map +1 -1
- package/dist/streaming.d.cts +5 -3
- package/dist/streaming.d.ts +5 -3
- package/dist/streaming.js +4 -4
- package/dist/streaming.js.map +1 -1
- package/dist/testing.cjs +8 -4
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +87 -4
- package/dist/testing.d.ts +87 -4
- package/dist/testing.js +8 -4
- package/dist/testing.js.map +1 -1
- package/dist/{types-wa_wTOn3.d.ts → types-CuWK5AlK.d.ts} +1 -1
- package/dist/{types-DUWrNIJu.d.cts → types-uR3JpwvF.d.cts} +1 -1
- package/dist/webhook.cjs +2 -2
- package/dist/webhook.cjs.map +1 -1
- package/dist/webhook.d.cts +7 -4
- package/dist/webhook.d.ts +7 -4
- package/dist/webhook.js +2 -2
- package/dist/webhook.js.map +1 -1
- package/dist/workflow.cjs +3 -3
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +47 -11
- package/dist/workflow.d.ts +47 -11
- package/dist/workflow.js +3 -3
- package/dist/workflow.js.map +1 -1
- package/package.json +15 -1
package/dist/result.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/result/index.ts"],"sourcesContent":["/**\n * awaitly/result (internal)\n *\n * Core Result primitives - minimal bundle for typed error handling.\n * This file is intentionally kept small for optimal tree-shaking.\n * The full orchestration (run, step, etc.) lives in core.ts.\n */\n\n// =============================================================================\n// Core Result Types\n// =============================================================================\n\n/**\n * Represents a successful result.\n * Use `ok(value)` to create instances.\n */\nexport type Ok<T> = {\n ok: true;\n value: T;\n};\n\n/**\n * Represents a failed result.\n * Use `err(error)` to create instances.\n */\nexport type Err<E, C = unknown> = {\n ok: false;\n error: E;\n cause?: C;\n};\n\n/**\n * Represents a successful computation or a failed one.\n */\nexport type Result<T, E = unknown, C = unknown> = Ok<T> | Err<E, C>;\n\n/**\n * A Promise that resolves to a Result.\n */\nexport type AsyncResult<T, E = unknown, C = unknown> = Promise<Result<T, E, C>>;\n\nexport type UnexpectedStepFailureCause =\n | {\n type: \"STEP_FAILURE\";\n origin: \"result\";\n error: unknown;\n cause?: unknown;\n }\n | {\n type: \"STEP_FAILURE\";\n origin: \"throw\";\n error: unknown;\n thrown: unknown;\n };\n\nexport type UnexpectedCause =\n | { type: \"UNCAUGHT_EXCEPTION\"; thrown: unknown }\n | UnexpectedStepFailureCause;\n\n/** Discriminant for UnexpectedError type - use in switch statements */\nexport const UNEXPECTED_ERROR = \"UNEXPECTED_ERROR\" as const;\n\n/** Discriminant for PromiseRejectedError type - use in switch statements */\nexport const PROMISE_REJECTED = \"PROMISE_REJECTED\" as const;\n\n// =============================================================================\n// Named Error Constants (for static analysis)\n// =============================================================================\n\n/**\n * Named error constant for unexpected/unhandled errors.\n * Used by the analyzer when a step doesn't declare errors.\n */\nexport const AWAITLY_UNEXPECTED = \"AWAITLY_UNEXPECTED\" as const;\n\n/**\n * Named error constant for cancelled operations.\n */\nexport const AWAITLY_CANCELLED = \"AWAITLY_CANCELLED\" as const;\n\n/**\n * Named error constant for timed-out operations.\n */\nexport const AWAITLY_TIMEOUT = \"AWAITLY_TIMEOUT\" as const;\n\n// =============================================================================\n// Static Analysis Helpers\n// =============================================================================\n\n/**\n * Helper to create a tuple of string literal tags with preserved literal types.\n * Use this when you need to store error tags in a variable while keeping\n * TypeScript's literal type inference (avoiding widening to string[]).\n *\n * @param t - The string literal tags\n * @returns The same array with preserved literal types\n *\n * @example\n * ```typescript\n * // Without tags() - type widens to string[]\n * const errs = ['CART_NOT_FOUND', 'CART_EMPTY']; // string[]\n *\n * // With tags() - literal types preserved\n * const errs = tags('CART_NOT_FOUND', 'CART_EMPTY'); // readonly ['CART_NOT_FOUND', 'CART_EMPTY']\n *\n * await step('getCart', () => getCart(id), {\n * errors: errs, // Analyzer can extract literal types\n * out: 'cart',\n * });\n * ```\n */\nexport const tags = <const T extends readonly string[]>(...t: T): T => t;\n\nexport type UnexpectedError = {\n type: typeof UNEXPECTED_ERROR;\n cause: UnexpectedCause;\n};\nexport type PromiseRejectedError = { type: typeof PROMISE_REJECTED; cause: unknown };\n/** Cause type for promise rejections in async batch helpers */\nexport type PromiseRejectionCause = { type: \"PROMISE_REJECTION\"; reason: unknown };\nexport type EmptyInputError = { type: \"EMPTY_INPUT\"; message: string };\nexport type MaybeAsyncResult<T, E, C = unknown> = Result<T, E, C> | Promise<Result<T, E, C>>;\n\n// =============================================================================\n// Result Constructors\n// =============================================================================\n\n/**\n * Creates a successful Result.\n *\n * @remarks When to use: Wrap a successful value in a Result for consistent return types.\n */\nexport function ok(): Ok<void>;\nexport function ok<T>(value: T): Ok<T>;\nexport function ok<T>(value?: T): Ok<T | void> {\n return { ok: true as const, value: value as T | void };\n}\n\n/**\n * Creates a failed Result.\n *\n * @remarks When to use: Return a typed failure without throwing so callers can handle it explicitly.\n */\nexport function err<E, C = unknown>(error: E, options?: { cause?: C }): Err<E, C> {\n const cause = options?.cause;\n return { ok: false as const, error, ...(cause !== undefined ? { cause } : {}) } as Err<E, C>;\n}\n\n// =============================================================================\n// Type Guards\n// =============================================================================\n\n/**\n * Checks if a Result is successful.\n *\n * @remarks When to use: Prefer functional-style checks or array filtering over `result.ok`.\n */\nexport const isOk = <T, E, C>(r: Result<T, E, C>): r is Ok<T> => r.ok;\n\n/**\n * Checks if a Result is a failure.\n *\n * @remarks When to use: Prefer functional-style checks or array filtering over `result.ok`.\n */\nexport const isErr = <T, E, C>(r: Result<T, E, C>): r is Err<E, C> => !r.ok;\n\n/**\n * Checks if an error is an UnexpectedError.\n *\n * @remarks When to use: Distinguish unexpected failures from your typed error union.\n */\nexport const isUnexpectedError = (e: unknown): e is UnexpectedError =>\n typeof e === \"object\" &&\n e !== null &&\n \"type\" in e &&\n e.type === UNEXPECTED_ERROR;\n\n/**\n * Checks if an error is a PromiseRejectedError.\n */\nexport const isPromiseRejectedError = (e: unknown): e is PromiseRejectedError =>\n typeof e === \"object\" &&\n e !== null &&\n \"type\" in e &&\n e.type === PROMISE_REJECTED;\n\n// =============================================================================\n// Error Matching\n// =============================================================================\n\nexport type MatchErrorHandlers<E extends string, R> = {\n [K in E]: (error: K extends \"UNEXPECTED_ERROR\" ? UnexpectedError : K) => R;\n};\n\n/**\n * Match on string error types with exhaustive checking.\n * Takes an error value (not a Result) and handlers for each error type.\n */\nexport function matchError<E extends string, R>(\n error: E | UnexpectedError,\n handlers: MatchErrorHandlers<E, R>\n): R {\n // Handle UnexpectedError objects\n if (isUnexpectedError(error)) {\n return (handlers as MatchErrorHandlers<\"UNEXPECTED_ERROR\", R>).UNEXPECTED_ERROR(error);\n }\n // Handle the string literal \"UNEXPECTED_ERROR\" - wrap it in an UnexpectedError object\n // to maintain the typed contract that UNEXPECTED_ERROR handler receives an object\n if (error === \"UNEXPECTED_ERROR\") {\n const syntheticError: UnexpectedError = {\n type: UNEXPECTED_ERROR,\n cause: { type: \"UNCAUGHT_EXCEPTION\", thrown: error },\n };\n return (handlers as MatchErrorHandlers<\"UNEXPECTED_ERROR\", R>).UNEXPECTED_ERROR(syntheticError);\n }\n // Cast to the excluded type since we've handled UNEXPECTED_ERROR above\n type StringErrors = Exclude<E, \"UNEXPECTED_ERROR\">;\n return (handlers as unknown as Record<string, (e: string) => R>)[error as StringErrors](error as StringErrors);\n}\n\n// =============================================================================\n// Type Utilities\n// =============================================================================\n\ntype AnyFunction = (...args: never[]) => unknown;\n\n/**\n * Helper to extract the error type from Result or AsyncResult return values.\n * Works even when a function is declared to return a union of both forms.\n */\ntype ErrorOfReturn<R> = Extract<Awaited<R>, { ok: false }> extends { error: infer E }\n ? E\n : never;\n\n/**\n * Extract error type from a single function's return type\n */\nexport type ErrorOf<T extends AnyFunction> = ErrorOfReturn<ReturnType<T>>;\n\n/**\n * Extract union of error types from multiple functions\n */\nexport type Errors<T extends AnyFunction[]> = {\n [K in keyof T]: ErrorOf<T[K]>;\n}[number];\n\n/**\n * Extract value type from Result\n */\nexport type ExtractValue<T> = T extends { ok: true; value: infer U }\n ? U\n : never;\n\n/**\n * Extract error type from Result\n */\nexport type ExtractError<T> = T extends { ok: false; error: infer E }\n ? E\n : never;\n\n/**\n * Extract cause type from Result\n */\nexport type ExtractCause<T> = T extends { ok: false; cause?: infer C }\n ? C\n : never;\n\n/**\n * Helper to extract the cause type from Result or AsyncResult return values.\n * Works even when a function is declared to return a union of both forms.\n */\ntype CauseOfReturn<R> = Extract<Awaited<R>, { ok: false }> extends { cause?: infer C }\n ? C\n : never;\n\n/**\n * Extract cause type from a function's return type\n */\nexport type CauseOf<T extends AnyFunction> = CauseOfReturn<ReturnType<T>>;\n\n// =============================================================================\n// Unwrap Utilities\n// =============================================================================\n\n/**\n * Error thrown when attempting to unwrap an Err result.\n */\nexport class UnwrapError extends Error {\n public readonly error: unknown;\n public readonly cause?: unknown;\n\n constructor(result: Err<unknown, unknown>) {\n const errorStr =\n typeof result.error === \"string\"\n ? result.error\n : JSON.stringify(result.error);\n super(`Attempted to unwrap an Err: ${errorStr}`);\n this.name = \"UnwrapError\";\n this.error = result.error;\n this.cause = result.cause;\n }\n}\n\n/**\n * Extracts the value from an Ok result, or throws UnwrapError if it's an Err.\n *\n * @remarks When to use: Only at boundaries or tests where a failure should be fatal.\n */\nexport const unwrap = <T, E, C>(r: Result<T, E, C>): T => {\n if (r.ok) return r.value;\n throw new UnwrapError(r);\n};\n\n/**\n * Extracts the value from an Ok result, or returns a default value if it's an Err.\n *\n * @remarks When to use: Provide a safe fallback without branching.\n */\nexport const unwrapOr = <T, E, C>(r: Result<T, E, C>, defaultValue: T): T =>\n r.ok ? r.value : defaultValue;\n\n/**\n * Extracts the value from an Ok result, or calls a function to get a default value if it's an Err.\n *\n * @remarks When to use: Compute a fallback from the error (logging, metrics, or derived defaults).\n */\nexport const unwrapOrElse = <T, E, C>(\n r: Result<T, E, C>,\n fn: (error: E, cause?: C) => T\n): T => (r.ok ? r.value : fn(r.error, r.cause));\n\n/**\n * Alias for `unwrap`. Returns the success value or throws.\n *\n * The Result is already computed; use when you want the value or throw (e.g. at boundaries or in tests).\n *\n * @param r - The Result to unwrap\n * @returns The success value if the Result is successful\n * @throws {UnwrapError} If the Result is an error (includes the error and cause)\n */\nexport const runOrThrow = <T, E, C>(r: Result<T, E, C>): T => unwrap(r);\n\n/**\n * Awaits a Promise of a Result, then returns the success value or rejects.\n *\n * The returned promise **resolves with T** on success and **rejects with UnwrapError** on failure.\n * UnwrapError extends Error and carries the original `error` and `cause` from the Err.\n *\n * @param ar - A Promise or thenable that resolves to a Result\n * @returns A Promise that resolves with the success value or rejects with UnwrapError\n */\nexport const runOrThrowAsync = <T, E, C>(\n ar: PromiseLike<Result<T, E, C>>\n): Promise<T> => Promise.resolve(ar).then(unwrap);\n\n/**\n * Convenience alias for `unwrapOr(r, null)`. Returns the success value or null.\n *\n * @param r - The Result to unwrap\n * @returns The success value if successful, otherwise null\n */\nexport const runOrNull = <T, E, C>(r: Result<T, E, C>): T | null =>\n r.ok ? r.value : null;\n\n/**\n * Convenience alias for `unwrapOr(r, undefined)`. Returns the success value or undefined.\n *\n * @param r - The Result to unwrap\n * @returns The success value if successful, otherwise undefined\n */\nexport const runOrUndefined = <T, E, C>(r: Result<T, E, C>): T | undefined =>\n r.ok ? r.value : undefined;\n\n// =============================================================================\n// Wrapping Functions\n// =============================================================================\n\n/**\n * Wraps a synchronous function that might throw into a Result.\n *\n * @remarks When to use: Wrap sync code that might throw so exceptions become Err values.\n */\nexport function from<T>(fn: () => T): Ok<T> | Err<unknown, unknown>;\nexport function from<T, E>(fn: () => T, onError: (cause: unknown) => E): Ok<T> | Err<E, unknown>;\nexport function from<T, E>(fn: () => T, onError?: (cause: unknown) => E) {\n try {\n return ok(fn());\n } catch (cause) {\n return onError ? err(onError(cause), { cause }) : err(cause);\n }\n}\n\n/**\n * Wraps a Promise into a Result.\n *\n * @remarks When to use: Wrap a Promise and keep the raw rejection as Err; use tryAsync to map errors.\n */\nexport function fromPromise<T>(promise: Promise<T>): Promise<Ok<T> | Err<unknown, unknown>>;\nexport function fromPromise<T, E>(\n promise: Promise<T>,\n onError: (cause: unknown) => E\n): Promise<Ok<T> | Err<E, unknown>>;\nexport async function fromPromise<T, E>(\n promise: Promise<T>,\n onError?: (cause: unknown) => E\n): Promise<Ok<T> | Err<E | unknown, unknown>> {\n try {\n return ok(await promise);\n } catch (cause) {\n return onError ? err(onError(cause), { cause }) : err(cause);\n }\n}\n\n/**\n * Wraps an async function that might throw into an AsyncResult.\n *\n * @remarks When to use: Wrap async work and map thrown/rejected values into your typed error union.\n */\nexport function tryAsync<T>(fn: () => Promise<T>): AsyncResult<T, unknown>;\nexport function tryAsync<T, E>(\n fn: () => Promise<T>,\n onError: (cause: unknown) => E\n): AsyncResult<T, E>;\nexport async function tryAsync<T, E>(\n fn: () => Promise<T>,\n onError?: (cause: unknown) => E\n): AsyncResult<T, E | unknown> {\n try {\n return ok(await fn());\n } catch (cause) {\n return onError ? err(onError(cause), { cause }) : err(cause);\n }\n}\n\n/**\n * Converts a nullable value into a Result.\n *\n * @remarks When to use: Turn null/undefined into a typed error before continuing.\n */\nexport function fromNullable<T, E>(\n value: T | null | undefined,\n onNull: () => E\n): Result<T, E> {\n return value != null ? ok(value) : err(onNull());\n}\n\n// =============================================================================\n// Transformers\n// =============================================================================\n\n/**\n * Transforms the value inside an Ok result.\n *\n * @remarks When to use: Transform only the Ok value while leaving Err untouched.\n */\nexport function map<T, U>(r: Ok<T>, fn: (value: T) => U): Ok<U>;\nexport function map<T, U, E, C>(r: Err<E, C>, fn: (value: T) => U): Err<E, C>;\nexport function map<T, U, E, C>(r: Result<T, E, C>, fn: (value: T) => U): Result<U, E, C>;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function map(r: any, fn: any): any {\n return r.ok ? ok(fn(r.value)) : r;\n}\n\n/**\n * Transforms the error inside an Err result.\n *\n * @remarks When to use: Retype or normalize errors while leaving Ok values unchanged.\n */\nexport function mapError<T, E, F, C>(\n r: Result<T, E, C>,\n fn: (error: E, cause?: C) => F\n): Result<T, F, C> {\n return r.ok ? r : err(fn(r.error, r.cause), { cause: r.cause });\n}\n\n/**\n * Pattern match on a Result.\n *\n * @remarks When to use: Handle both Ok and Err in a single expression that returns a value.\n */\nexport function match<T, E, C, R>(r: Ok<T>, handlers: { ok: (value: T) => R; err: (error: E, cause?: C) => R }): R;\nexport function match<T, E, C, R>(r: Err<E, C>, handlers: { ok: (value: T) => R; err: (error: E, cause?: C) => R }): R;\nexport function match<T, E, C, R>(r: Result<T, E, C>, handlers: { ok: (value: T) => R; err: (error: E, cause?: C) => R }): R;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function match(r: any, handlers: any): any {\n return r.ok ? handlers.ok(r.value) : handlers.err(r.error, r.cause);\n}\n\n/**\n * Chain Result-returning functions.\n *\n * @remarks When to use: Chain dependent operations that return Result without nested branching.\n */\nexport function andThen<T, U>(r: Ok<T>, fn: (value: T) => Ok<U>): Ok<U>;\nexport function andThen<T, F, C2>(r: Ok<T>, fn: (value: T) => Err<F, C2>): Err<F, C2>;\nexport function andThen<T, U, F, C2>(r: Ok<T>, fn: (value: T) => Result<U, F, C2>): Result<U, F, C2>;\nexport function andThen<T, U, E, F, C1, C2>(r: Err<E, C1>, fn: (value: T) => Result<U, F, C2>): Err<E, C1>;\nexport function andThen<T, U, E, F, C1, C2>(r: Result<T, E, C1>, fn: (value: T) => Result<U, F, C2>): Result<U, E | F, C1 | C2>;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function andThen(r: any, fn: any): any {\n return r.ok ? fn(r.value) : r;\n}\n\n/**\n * Execute a side effect on Ok values.\n *\n * @remarks When to use: Add side effects (logging, metrics) on Ok without changing the Result.\n */\nexport function tap<T, E, C>(\n r: Result<T, E, C>,\n fn: (value: T) => void\n): Result<T, E, C> {\n if (r.ok) fn(r.value);\n return r;\n}\n\n/**\n * Execute a side effect on Err values.\n *\n * @remarks When to use: Add side effects (logging, metrics) on Err without changing the Result.\n */\nexport function tapError<T, E, C>(\n r: Result<T, E, C>,\n fn: (error: E, cause?: C) => void\n): Result<T, E, C> {\n if (!r.ok) fn(r.error, r.cause);\n return r;\n}\n\n/**\n * Transform value with a function that might throw.\n *\n * @remarks When to use: Transform Ok values with a function that might throw and capture the failure.\n */\nexport function mapTry<T, U, E, F, C>(\n r: Result<T, E, C>,\n fn: (value: T) => U,\n onError: (thrown: unknown) => F\n): Result<U, E | F, C | unknown> {\n if (!r.ok) return r;\n try {\n return ok(fn(r.value));\n } catch (error) {\n return err(onError(error), { cause: error });\n }\n}\n\n/**\n * Transform error with a function that might throw.\n *\n * @remarks When to use: Transform errors when the mapping might throw and you want that captured.\n */\nexport function mapErrorTry<T, E, F, G, C>(\n r: Result<T, E, C>,\n fn: (error: E) => F,\n onError: (thrown: unknown) => G\n): Result<T, F | G, C | unknown> {\n if (r.ok) return r;\n try {\n return err(fn(r.error), { cause: r.cause });\n } catch (error) {\n return err(onError(error), { cause: error });\n }\n}\n\n/**\n * Transform both value and error.\n */\nexport function bimap<T, U, E, F, C>(\n r: Result<T, E, C>,\n onOk: (value: T) => U,\n onErr: (error: E, cause?: C) => F\n): Result<U, F, C> {\n return r.ok ? ok(onOk(r.value)) : err(onErr(r.error, r.cause), { cause: r.cause });\n}\n\n/**\n * Provide an alternative Result if the first is an Err.\n *\n * @remarks When to use: Recover from Err by returning a fallback Result or retyping the error.\n */\nexport function orElse<T, E, E2, C, C2>(\n r: Result<T, E, C>,\n fn: (error: E, cause?: C) => Result<T, E2, C2>\n): Result<T, E2, C | C2> {\n return r.ok ? r : fn(r.error, r.cause);\n}\n\n/**\n * Async version of orElse.\n */\nexport async function orElseAsync<T, E, E2, C, C2>(\n r: Result<T, E, C>,\n fn: (error: E, cause?: C) => Promise<Result<T, E2, C2>>\n): Promise<Result<T, E2, C | C2>> {\n return r.ok ? r : fn(r.error, r.cause);\n}\n\n/**\n * Recover from errors - always returns Ok<T>.\n */\nexport function recover<T, E, C>(\n r: Result<T, E, C>,\n fn: (error: E, cause?: C) => T\n): Ok<T> {\n return r.ok ? ok(r.value) : ok(fn(r.error, r.cause));\n}\n\n/**\n * Async version of recover - always returns Promise<Ok<T>>.\n */\nexport async function recoverAsync<T, E, C>(\n r: Result<T, E, C> | Promise<Result<T, E, C>>,\n fn: (error: E, cause?: C) => T | Promise<T>\n): Promise<Ok<T>> {\n const resolved = await r;\n if (resolved.ok) return ok(resolved.value);\n return ok(await fn(resolved.error, resolved.cause));\n}\n\n// =============================================================================\n// Result Hydration (Serialization)\n// =============================================================================\n\n/**\n * Hydrate a serialized Result back into a proper Result object.\n */\nexport function hydrate<T, E, C = unknown>(value: unknown): Result<T, E, C> | null {\n if (typeof value !== \"object\" || value === null) return null;\n if (!(\"ok\" in value)) return null;\n\n const obj = value as Record<string, unknown>;\n if (obj.ok === true && \"value\" in obj) {\n return ok(obj.value as T);\n }\n if (obj.ok === false && \"error\" in obj) {\n return err(obj.error as E, { cause: obj.cause as C });\n }\n return null;\n}\n\n/**\n * Type guard to check if a value is a serialized Result.\n */\nexport function isSerializedResult(\n value: unknown\n): value is { ok: boolean; value?: unknown; error?: unknown; cause?: unknown } {\n if (typeof value !== \"object\" || value === null) return false;\n if (!(\"ok\" in value)) return false;\n const obj = value as Record<string, unknown>;\n return (\n (obj.ok === true && \"value\" in obj) ||\n (obj.ok === false && \"error\" in obj)\n );\n}\n\n// =============================================================================\n// Batch Operations\n// =============================================================================\n\ntype AllValues<T extends readonly Result<unknown, unknown, unknown>[]> = {\n [K in keyof T]: T[K] extends Ok<infer V>\n ? V\n : T[K] extends Err<unknown, unknown>\n ? never\n : T[K] extends Result<infer V, unknown, unknown>\n ? V\n : never;\n};\ntype AllErrors<T extends readonly Result<unknown, unknown, unknown>[]> = {\n [K in keyof T]: T[K] extends Ok<unknown>\n ? never\n : T[K] extends Err<infer E, unknown>\n ? E\n : T[K] extends Result<unknown, infer E, unknown>\n ? E\n : never;\n}[number];\ntype AllCauses<T extends readonly Result<unknown, unknown, unknown>[]> = {\n [K in keyof T]: T[K] extends Ok<unknown>\n ? never\n : T[K] extends Err<unknown, infer C>\n ? C\n : T[K] extends Result<unknown, unknown, infer C>\n ? C\n : never;\n}[number];\n\n// Conditional type: returns Ok<...> when there are no errors, Result<...> otherwise\n// Note: We only check AllErrors, not AllCauses - causes only matter when there are errors\ntype AllResult<T extends readonly Result<unknown, unknown, unknown>[]> =\n [AllErrors<T>] extends [never]\n ? Ok<AllValues<T>>\n : Result<AllValues<T>, AllErrors<T>, AllCauses<T>>;\n\n/**\n * Combines multiple Results into a single Result containing an array of values.\n * Returns the first Err encountered, or Ok with all values.\n */\nexport function all<const T extends readonly Result<unknown, unknown, unknown>[]>(\n results: T\n): AllResult<T> {\n const values: unknown[] = [];\n for (const result of results) {\n if (!result.ok) {\n return result as unknown as AllResult<T>;\n }\n values.push(result.value);\n }\n return ok(values) as AllResult<T>;\n}\n\n/**\n * Async version of all - works with Promises of Results.\n */\nexport async function allAsync<\n const T extends readonly (Result<unknown, unknown, unknown> | Promise<Result<unknown, unknown, unknown>>)[]\n>(\n results: T\n): Promise<\n Result<\n { [K in keyof T]: T[K] extends Result<infer V, unknown, unknown> | Promise<Result<infer V, unknown, unknown>> ? V : never },\n | { [K in keyof T]: T[K] extends Result<unknown, infer E, unknown> | Promise<Result<unknown, infer E, unknown>> ? E : never }[number]\n | PromiseRejectedError,\n | { [K in keyof T]: T[K] extends Result<unknown, unknown, infer C> | Promise<Result<unknown, unknown, infer C>> ? C : never }[number]\n | PromiseRejectionCause\n >\n> {\n const values: unknown[] = [];\n for (const resultOrPromise of results) {\n try {\n const r = await resultOrPromise;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if (!r.ok) return r as any;\n values.push(r.value);\n } catch (reason) {\n return err(\n { type: PROMISE_REJECTED, cause: reason } as PromiseRejectedError,\n { cause: { type: \"PROMISE_REJECTION\", reason } as PromiseRejectionCause }\n );\n }\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return ok(values) as any;\n}\n\nexport type SettledError<E, C = unknown> = { error: E; cause?: C };\n\n// Conditional type: returns Ok<...> when there are no errors, Result<...> otherwise\ntype AllSettledResult<T extends readonly Result<unknown, unknown, unknown>[]> =\n [AllErrors<T>] extends [never]\n ? Ok<AllValues<T>>\n : Result<AllValues<T>, SettledError<AllErrors<T>, AllCauses<T>>[]>;\n\n/**\n * Collects all Results, returning Ok with values if all succeed,\n * or Err with array of errors if any fail.\n */\nexport function allSettled<const T extends readonly Result<unknown, unknown, unknown>[]>(\n results: T\n): AllSettledResult<T> {\n const values: unknown[] = [];\n const errors: SettledError<unknown>[] = [];\n\n for (const result of results) {\n if (result.ok) {\n values.push(result.value);\n } else {\n errors.push({ error: result.error, cause: result.cause });\n }\n }\n\n if (errors.length > 0) {\n return err(errors) as unknown as AllSettledResult<T>;\n }\n\n return ok(values) as unknown as AllSettledResult<T>;\n}\n\n/**\n * Async version of allSettled.\n */\nexport async function allSettledAsync<\n const T extends readonly (Result<unknown, unknown, unknown> | Promise<Result<unknown, unknown, unknown>>)[]\n>(\n results: T\n): Promise<\n Result<\n { [K in keyof T]: T[K] extends Result<infer V, unknown, unknown> | Promise<Result<infer V, unknown, unknown>> ? V : never },\n SettledError<\n | { [K in keyof T]: T[K] extends Result<unknown, infer E, unknown> | Promise<Result<unknown, infer E, unknown>> ? E : never }[number]\n | PromiseRejectedError,\n | { [K in keyof T]: T[K] extends Result<unknown, unknown, infer C> | Promise<Result<unknown, unknown, infer C>> ? C : never }[number]\n | PromiseRejectionCause\n >[]\n >\n> {\n const settled = await Promise.all(\n results.map((item) =>\n Promise.resolve(item)\n .then((result) => ({ status: \"result\" as const, result }))\n .catch((reason) => ({\n status: \"rejected\" as const,\n error: { type: PROMISE_REJECTED, cause: reason } as PromiseRejectedError,\n cause: { type: \"PROMISE_REJECTION\", reason } as PromiseRejectionCause,\n }))\n )\n );\n\n const values: unknown[] = [];\n const errors: SettledError<unknown, unknown>[] = [];\n\n for (const item of settled) {\n if (item.status === \"rejected\") {\n errors.push({ error: item.error, cause: item.cause });\n } else if (item.result.ok) {\n values.push(item.result.value);\n } else {\n errors.push({ error: item.result.error, cause: item.result.cause });\n }\n }\n\n if (errors.length > 0) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return err(errors) as any;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return ok(values) as any;\n}\n\n/**\n * Partitions Results into { values, errors }.\n */\nexport function partition<T, E, C>(\n results: readonly Result<T, E, C>[]\n): { values: T[]; errors: E[] } {\n const values: T[] = [];\n const errors: E[] = [];\n for (const r of results) {\n if (r.ok) values.push(r.value);\n else errors.push(r.error);\n }\n return { values, errors };\n}\n\n/**\n * Returns the first Ok result, or an EmptyInputError/first Err if all fail.\n */\nexport function any<const T extends readonly Result<unknown, unknown, unknown>[]>(\n results: T\n): T extends readonly []\n ? Err<EmptyInputError, unknown>\n : Result<\n { [K in keyof T]: T[K] extends Result<infer V, unknown, unknown> ? V : never }[number],\n AllErrors<T> | EmptyInputError,\n AllCauses<T>\n >;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function any(results: any): any {\n if (results.length === 0) {\n return err({ type: \"EMPTY_INPUT\", message: \"any() requires at least one Result\" });\n }\n let firstErr: Err<unknown, unknown> | undefined;\n for (const r of results) {\n if (r.ok) return r;\n if (!firstErr) firstErr = r;\n }\n return firstErr;\n}\n\n/**\n * Async version of any - races promises and returns first success.\n */\nexport async function anyAsync<\n const T extends readonly (Result<unknown, unknown, unknown> | Promise<Result<unknown, unknown, unknown>>)[]\n>(\n results: T\n): Promise<\n T extends readonly []\n ? Err<EmptyInputError, unknown>\n : Result<\n { [K in keyof T]: T[K] extends Result<infer V, unknown, unknown> | Promise<Result<infer V, unknown, unknown>> ? V : never }[number],\n | { [K in keyof T]: T[K] extends Result<unknown, infer E, unknown> | Promise<Result<unknown, infer E, unknown>> ? E : never }[number]\n | EmptyInputError\n | PromiseRejectedError,\n | { [K in keyof T]: T[K] extends Result<unknown, unknown, infer C> | Promise<Result<unknown, unknown, infer C>> ? C : never }[number]\n | PromiseRejectionCause\n >\n> {\n if (results.length === 0) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return err({ type: \"EMPTY_INPUT\", message: \"anyAsync() requires at least one Result\" }) as any;\n }\n\n return new Promise((resolve) => {\n let settled = false;\n let pendingCount = results.length;\n let firstError: Err<unknown, unknown> | null = null;\n\n for (const item of results) {\n Promise.resolve(item)\n .catch((reason) =>\n err(\n { type: PROMISE_REJECTED, cause: reason } as PromiseRejectedError,\n { cause: { type: \"PROMISE_REJECTION\", reason } as PromiseRejectionCause }\n )\n )\n .then((result) => {\n if (settled) return;\n\n if (result.ok) {\n settled = true;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n resolve(result as any);\n return;\n }\n\n if (!firstError) firstError = result;\n pendingCount--;\n\n if (pendingCount === 0) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n resolve(firstError as any);\n }\n });\n }\n });\n}\n\n/**\n * Combines exactly two Results into a tuple.\n */\nexport function zip<A, EA, CA, B, EB, CB>(\n a: Result<A, EA, CA>,\n b: Result<B, EB, CB>\n): Result<[A, B], EA | EB, CA | CB> {\n if (!a.ok) return a;\n if (!b.ok) return b;\n return ok([a.value, b.value]);\n}\n\n/**\n * Async version of zip.\n */\nexport async function zipAsync<A, EA, CA, B, EB, CB>(\n a: Result<A, EA, CA> | Promise<Result<A, EA, CA>>,\n b: Result<B, EB, CB> | Promise<Result<B, EB, CB>>\n): Promise<Result<[A, B], EA | EB | PromiseRejectedError, CA | CB | PromiseRejectionCause>> {\n // Wrap rejections into PromiseRejectedError (consistent with allAsync)\n const wrapRejection = <T, E, C>(\n p: Result<T, E, C> | Promise<Result<T, E, C>>\n ): Promise<Result<T, E | PromiseRejectedError, C | PromiseRejectionCause>> =>\n Promise.resolve(p).catch((reason) =>\n err(\n { type: PROMISE_REJECTED, cause: reason } as PromiseRejectedError,\n { cause: { type: \"PROMISE_REJECTION\", reason } as PromiseRejectionCause }\n )\n );\n\n const [ra, rb] = await Promise.all([wrapRejection(a), wrapRejection(b)]);\n return zip(ra, rb);\n}\n\n// =============================================================================\n// Flatten\n// =============================================================================\n\n/**\n * Flattens a nested Result into a single Result.\n *\n * @remarks When to use: Unwrap a Result<Result<T, E1>, E2> into Result<T, E1 | E2> after an operation that returns nested Results.\n */\nexport function flatten<T, E1, C1, E2, C2>(\n result: Result<Result<T, E1, C1>, E2, C2>\n): Result<T, E1 | E2, C1 | C2> {\n if (!result.ok) return result as Err<E2, C2>;\n return result.value;\n}\n\n// =============================================================================\n// Deserialization (improved hydrate)\n// =============================================================================\n\n/** Discriminant for deserialization errors */\nexport const DESERIALIZATION_ERROR = \"DESERIALIZATION_ERROR\" as const;\n\n/** Error type returned when deserialize() receives invalid input */\nexport type DeserializationError = { type: typeof DESERIALIZATION_ERROR; value: unknown };\n\n/**\n * Deserialize a value back into a Result.\n * Returns a typed DeserializationError on invalid input instead of null.\n *\n * @remarks When to use: Rehydrate Results from JSON, RPC, or server actions with type-safe error handling.\n */\nexport function deserialize<T, E, C = unknown>(\n value: unknown\n): Result<T, E | DeserializationError, C> {\n if (typeof value !== \"object\" || value === null) {\n return err({ type: DESERIALIZATION_ERROR, value } as DeserializationError);\n }\n if (!(\"ok\" in value)) {\n return err({ type: DESERIALIZATION_ERROR, value } as DeserializationError);\n }\n\n const obj = value as Record<string, unknown>;\n if (obj.ok === true && \"value\" in obj) {\n return ok(obj.value as T);\n }\n if (obj.ok === false && \"error\" in obj) {\n return err(obj.error as E, { cause: obj.cause as C });\n }\n return err({ type: DESERIALIZATION_ERROR, value } as DeserializationError);\n}\n\n// =============================================================================\n// Serialization\n// =============================================================================\n\n/** A plain serialized form of a Result, safe to JSON.stringify. */\nexport type SerializedResult<T, E> = { ok: true; value: T } | { ok: false; error: E };\n\n/**\n * Serialize a Result to a plain object (inverse of `deserialize`).\n * Strips cause — safe for JSON.stringify, RPC, and server actions.\n *\n * @remarks When to use: Sending Results over the wire or storing them in JSON.\n */\nexport function serialize<T, E>(result: Result<T, E>): SerializedResult<T, E> {\n return result.ok\n ? { ok: true, value: result.value }\n : { ok: false, error: result.error };\n}\n\n// =============================================================================\n// Partial error matching\n// =============================================================================\n\n/**\n * Non-exhaustive error match — handle the errors you care about; let the rest fall through to fallback.\n *\n * @example\n * ```typescript\n * const message = matchErrorPartial(\n * error,\n * { NOT_FOUND: () => 'Resource not found' },\n * (e) => `Unexpected: ${e}`\n * );\n * ```\n */\nexport function matchErrorPartial<E extends string, R>(\n error: E | UnexpectedError,\n handlers: Partial<MatchErrorHandlers<E, R>>,\n fallback: (error: E | UnexpectedError) => R\n): R {\n if (isUnexpectedError(error)) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const h = (handlers as any).UNEXPECTED_ERROR as ((e: UnexpectedError) => R) | undefined;\n return h ? h(error) : fallback(error);\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const h = (handlers as any)[error as string] as ((e: E) => R) | undefined;\n return h ? h(error as E) : fallback(error);\n}\n\n// Retry helper is intentionally NOT re-exported here.\n// Import from the dedicated subpath to keep awaitly/result minimal:\n// import { tryAsyncRetry } from 'awaitly/result/retry';\n"],"mappings":"AA4DO,IAAMA,EAAmB,mBAGnBC,EAAmB,mBAUnBC,EAAqB,qBAKrBC,EAAoB,oBAKpBC,EAAkB,kBA4BlBC,EAAO,IAAuCC,IAAYA,EAuBhE,SAASC,EAAMC,EAAyB,CAC7C,MAAO,CAAE,GAAI,GAAe,MAAOA,CAAkB,CACvD,CAOO,SAASC,EAAoBC,EAAUC,EAAoC,CAChF,IAAMC,EAAQD,GAAS,MACvB,MAAO,CAAE,GAAI,GAAgB,MAAAD,EAAO,GAAIE,IAAU,OAAY,CAAE,MAAAA,CAAM,EAAI,CAAC,CAAG,CAChF,CAWO,IAAMC,EAAiBC,GAAmCA,EAAE,GAOtDC,EAAkBD,GAAuC,CAACA,EAAE,GAO5DE,EAAqB,GAChC,OAAO,GAAM,UACb,IAAM,MACN,SAAU,GACV,EAAE,OAAShB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,CAEzB,CAOO,IAAMiE,EAAwB,wBAW9B,SAASC,GACdhF,EACwC,CACxC,GAAI,OAAOA,GAAU,UAAYA,IAAU,KACzC,OAAOC,EAAI,CAAE,KAAM8E,EAAuB,MAAA/E,CAAM,CAAyB,EAE3E,GAAI,EAAE,OAAQA,GACZ,OAAOC,EAAI,CAAE,KAAM8E,EAAuB,MAAA/E,CAAM,CAAyB,EAG3E,IAAMkD,EAAMlD,EACZ,OAAIkD,EAAI,KAAO,IAAQ,UAAWA,EACzBnD,EAAGmD,EAAI,KAAU,EAEtBA,EAAI,KAAO,IAAS,UAAWA,EAC1BjD,EAAIiD,EAAI,MAAY,CAAE,MAAOA,EAAI,KAAW,CAAC,EAE/CjD,EAAI,CAAE,KAAM8E,EAAuB,MAAA/E,CAAM,CAAyB,CAC3E,CAeO,SAASiF,GAAgBnE,EAA8C,CAC5E,OAAOA,EAAO,GACV,CAAE,GAAI,GAAM,MAAOA,EAAO,KAAM,EAChC,CAAE,GAAI,GAAO,MAAOA,EAAO,KAAM,CACvC,CAkBO,SAASoE,GACdhF,EACAS,EACAwE,EACG,CACH,GAAI3E,EAAkBN,CAAK,EAAG,CAE5B,IAAMkF,EAAKzE,EAAiB,iBAC5B,OAAOyE,EAAIA,EAAElF,CAAK,EAAIiF,EAASjF,CAAK,CACtC,CAEA,IAAMkF,EAAKzE,EAAiBT,CAAe,EAC3C,OAAOkF,EAAIA,EAAElF,CAAU,EAAIiF,EAASjF,CAAK,CAC3C","names":["UNEXPECTED_ERROR","PROMISE_REJECTED","AWAITLY_UNEXPECTED","AWAITLY_CANCELLED","AWAITLY_TIMEOUT","tags","t","ok","value","err","error","options","cause","isOk","r","isErr","isUnexpectedError","isPromiseRejectedError","matchError","handlers","syntheticError","UnwrapError","result","errorStr","unwrap","unwrapOr","defaultValue","unwrapOrElse","fn","runOrThrow","runOrThrowAsync","ar","runOrNull","runOrUndefined","from","onError","fromPromise","promise","tryAsync","fromNullable","onNull","map","mapError","match","andThen","tap","tapError","mapTry","mapErrorTry","bimap","onOk","onErr","orElse","orElseAsync","recover","recoverAsync","resolved","hydrate","obj","isSerializedResult","all","results","values","allAsync","resultOrPromise","reason","allSettled","errors","allSettledAsync","settled","item","partition","any","firstErr","anyAsync","resolve","pendingCount","firstError","zip","a","b","zipAsync","wrapRejection","p","ra","rb","flatten","DESERIALIZATION_ERROR","deserialize","serialize","matchErrorPartial","fallback","h"]}
|
|
1
|
+
{"version":3,"sources":["../src/tagged-error.ts","../src/errors.ts","../src/result/index.ts"],"sourcesContent":["/**\n * awaitly/tagged-error\n *\n * Factory for creating tagged error types with exhaustive pattern matching.\n * Enables TypeScript to enforce that all error variants are handled.\n *\n * @example\n * ```typescript\n * // Define error types (Props via generic)\n * class NotFoundError extends TaggedError(\"NotFoundError\")<{\n * id: string;\n * resource: string;\n * }> {}\n *\n * // Define with type-safe message (Props inferred from callback annotation)\n * class ValidationError extends TaggedError(\"ValidationError\", {\n * message: (p: { field: string; reason: string }) => `Invalid ${p.field}: ${p.reason}`,\n * }) {}\n *\n * // Create instances\n * const error = new NotFoundError({ id: \"123\", resource: \"User\" });\n *\n * // Runtime type check: instanceof TaggedError works!\n * console.log(error instanceof TaggedError); // true\n *\n * // Exhaustive matching\n * type AppError = NotFoundError | ValidationError;\n * const message = TaggedError.match(error as AppError, {\n * NotFoundError: (e) => `Missing: ${e.resource} ${e.id}`,\n * ValidationError: (e) => `Invalid ${e.field}: ${e.reason}`,\n * });\n * ```\n */\n\n/**\n * Options for Error constructor (compatible with ES2022 ErrorOptions).\n */\nexport interface TaggedErrorOptions {\n cause?: unknown;\n}\n\n/**\n * Options for TaggedError factory with type-safe message callback.\n */\nexport interface TaggedErrorCreateOptions<Props extends Record<string, unknown>> {\n /** Custom message generator from props. Annotate parameter for type safety. */\n message: (props: Props) => string;\n}\n\n/**\n * Base interface for all tagged errors.\n */\nexport interface TaggedErrorBase extends Error {\n readonly _tag: string;\n}\n\n/**\n * Internal base class for instanceof checks.\n * All TaggedError-created classes extend this.\n * @internal\n */\nclass InternalTaggedErrorBase extends Error implements TaggedErrorBase {\n readonly _tag!: string;\n}\n\n/**\n * Instance type for factory-created TaggedErrors.\n */\ntype TaggedErrorInstance<Tag extends string, Props> = TaggedErrorBase & {\n readonly _tag: Tag;\n} & Readonly<Props>;\n\n/**\n * Constructor args type - conditionally optional based on whether Props has required fields.\n * - If Props is empty or all properties are optional: props argument is optional\n * - If Props has any required properties: props argument is required\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\ntype ConstructorArgs<Props extends Record<string, unknown>> = {} extends Props\n ? [props?: Props | void, options?: TaggedErrorOptions]\n : [props: Props, options?: TaggedErrorOptions];\n\n/**\n * Constructor type returned by TaggedError factory.\n */\nexport interface TaggedErrorConstructor<\n Tag extends string,\n Props extends Record<string, unknown>,\n> {\n new (...args: ConstructorArgs<Props>): TaggedErrorInstance<Tag, Props>;\n readonly prototype: TaggedErrorInstance<Tag, Props>;\n}\n\n/**\n * Generic class factory type that allows `<Props>` parameterization.\n * This enables the Effect.js-style syntax: `class X extends TaggedError(\"X\")<Props> {}`\n * @internal\n */\nexport interface TaggedErrorClassFactory<Tag extends string> {\n new <Props extends Record<string, unknown> = Record<string, never>>(\n ...args: ConstructorArgs<Props>\n ): TaggedErrorInstance<Tag, Props>;\n}\n\n/**\n * Helper type to extract return type from a function type.\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype FnReturnType<T> = T extends (...args: any[]) => infer R ? R : never;\n\n/**\n * Helper type to get union of return types from all handlers.\n * @internal\n */\ntype HandlersReturnType<H> = { [K in keyof H]: FnReturnType<H[K]> }[keyof H];\n\n/**\n * Helper type to extract keys whose values are definitely functions (not undefined).\n * Only excludes a tag from the fallback type if its handler is guaranteed to be\n * a function. Keys where the value type includes undefined are NOT excluded,\n * ensuring type safety with dynamic/conditional handlers.\n * @internal\n */\ntype DefinitelyHandledKeys<H> = {\n [K in keyof H]-?: undefined extends H[K] ? never : K;\n}[keyof H];\n\n/**\n * Factory function to create tagged error classes.\n *\n * Two usage patterns:\n *\n * 1. **Props via generic** (default message is tag name):\n * ```typescript\n * class NotFoundError extends TaggedError(\"NotFoundError\")<{ id: string }> {}\n * ```\n *\n * 2. **Props inferred from message callback** (type-safe message):\n * ```typescript\n * class NotFoundError extends TaggedError(\"NotFoundError\", {\n * message: (p: { id: string }) => `Not found: ${p.id}`,\n * }) {}\n * ```\n *\n * Both support `instanceof TaggedError` checks at runtime.\n *\n * @param tag - The unique tag string for this error type\n * @param options - Optional configuration with message generator (annotate param for type safety)\n * @returns A class constructor that can be extended\n */\n\n// Overload 1: No options - use <Props> generic syntax, default message is tag\nfunction TaggedError<Tag extends string>(\n tag: Tag\n): TaggedErrorClassFactory<Tag>;\n\n// Overload 2: With message option - Props inferred from callback parameter annotation\nfunction TaggedError<Tag extends string, Props extends Record<string, unknown>>(\n tag: Tag,\n options: TaggedErrorCreateOptions<Props>\n): TaggedErrorConstructor<Tag, Props>;\n\n// Implementation\nfunction TaggedError<Tag extends string, Props extends Record<string, unknown>>(\n tag: Tag,\n options?: TaggedErrorCreateOptions<Props>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): any {\n return class extends InternalTaggedErrorBase {\n override readonly _tag: Tag = tag;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(props?: any, errorOptions?: TaggedErrorOptions) {\n // Generate message: call callback if provided (even for prop-less errors), else use tag\n const message = options?.message ? options.message(props ?? {}) : tag;\n\n super(message);\n this.name = tag;\n\n // Maintains proper prototype chain for instanceof checks\n Object.setPrototypeOf(this, new.target.prototype);\n\n // Assign props to instance, stripping reserved keys:\n // - _tag: discriminant for pattern matching (cannot be forged)\n // - name, message, stack: Error internals (preserve for logging/debugging)\n // Note: 'cause' is allowed as a user prop (common for domain errors)\n if (props && typeof props === \"object\") {\n const {\n _tag: _,\n name: _n,\n message: _m,\n stack: _s,\n ...safeProps\n } = props;\n\n const hasUserCause = Object.prototype.hasOwnProperty.call(\n safeProps,\n \"cause\"\n );\n const userCause = hasUserCause\n ? (safeProps as { cause?: unknown }).cause\n : undefined;\n if (hasUserCause) {\n delete (safeProps as { cause?: unknown }).cause;\n }\n\n const hasOptionsCause = errorOptions?.cause !== undefined;\n if (hasUserCause && hasOptionsCause) {\n throw new TypeError(\n \"TaggedError: cannot provide 'cause' in props when also setting ErrorOptions.cause\"\n );\n }\n\n Object.assign(this, safeProps);\n\n if (hasUserCause) {\n (this as { cause?: unknown }).cause = userCause;\n }\n if (hasOptionsCause) {\n (this as { cause?: unknown }).cause = errorOptions?.cause;\n }\n } else if (errorOptions?.cause !== undefined) {\n (this as { cause?: unknown }).cause = errorOptions.cause;\n }\n }\n };\n}\n\n// Add Symbol.hasInstance so `instanceof TaggedError` works\nObject.defineProperty(TaggedError, Symbol.hasInstance, {\n value: (instance: unknown): boolean => instance instanceof InternalTaggedErrorBase,\n});\n\n/**\n * Namespace for static methods on TaggedError.\n */\n// eslint-disable-next-line @typescript-eslint/no-namespace\nnamespace TaggedError {\n /**\n * Type guard to check if a value is an Error instance.\n */\n export function isError(value: unknown): value is Error {\n return value instanceof Error;\n }\n\n /**\n * Type guard to check if a value is a TaggedError instance.\n * Uses the same check as `instanceof TaggedError` - only genuine\n * TaggedError instances (created via the factory) pass this guard.\n */\n export function isTaggedError(value: unknown): value is TaggedErrorBase {\n return value instanceof InternalTaggedErrorBase;\n }\n\n /**\n * Exhaustively matches on a tagged error, requiring handlers for all variants.\n *\n * TypeScript will error if any variant in the error union is not handled.\n *\n * @remarks When to use: You want compile-time enforcement that every tagged variant is handled.\n *\n * @param error - The tagged error to match\n * @param handlers - Object mapping _tag values to handler functions\n * @returns The return value of the matched handler\n *\n * @example\n * ```typescript\n * type AppError = NotFoundError | ValidationError;\n *\n * const message = TaggedError.match(error, {\n * NotFoundError: (e) => `Not found: ${e.id}`,\n * ValidationError: (e) => `Invalid: ${e.field}`,\n * });\n * ```\n */\n export function match<\n E extends TaggedErrorBase,\n H extends { [K in E[\"_tag\"]]: (e: Extract<E, { _tag: K }>) => unknown },\n >(error: E, handlers: H): HandlersReturnType<H> {\n const tag = error._tag as E[\"_tag\"];\n const handler = handlers[tag];\n return handler(\n error as Extract<E, { _tag: typeof tag }>\n ) as HandlersReturnType<H>;\n }\n\n /**\n * Partially matches on a tagged error with a fallback for unhandled variants.\n *\n * The fallback receives variants that are NOT definitely handled. A tag is\n * considered \"definitely handled\" only if its handler is a function (not\n * `undefined`). This ensures type safety even with dynamic/conditional handlers:\n *\n * ```typescript\n * const maybeHandle = featureFlag ? (e) => e.id : undefined;\n * TaggedError.matchPartial(\n * error,\n * { NotFoundError: maybeHandle }, // maybeHandle might be undefined\n * (e) => e._tag // e correctly includes NotFoundError\n * );\n * ```\n *\n * @param error - The tagged error to match\n * @param handlers - Partial object mapping _tag values to handler functions\n * @param otherwise - Fallback handler for unmatched variants\n * @returns The return value of the matched handler or fallback\n *\n * @example\n * ```typescript\n * const message = TaggedError.matchPartial(\n * error,\n * { NotFoundError: (e) => `Not found: ${e.id}` },\n * (e) => `Other error: ${e.message}`\n * );\n * ```\n */\n export function matchPartial<\n E extends TaggedErrorBase,\n H extends Partial<{\n [K in E[\"_tag\"]]: (e: Extract<E, { _tag: K }>) => unknown;\n }>,\n T,\n >(\n error: E,\n handlers: H,\n otherwise: (e: Exclude<E, { _tag: DefinitelyHandledKeys<H> }>) => T\n ): HandlersReturnType<H> | T {\n const tag = error._tag as E[\"_tag\"];\n const handler = handlers[tag];\n if (handler) {\n return handler(\n error as Extract<E, { _tag: typeof tag }>\n ) as HandlersReturnType<H>;\n }\n return otherwise(error as Exclude<E, { _tag: DefinitelyHandledKeys<H> }>);\n }\n}\n\nexport { TaggedError };\n\n/**\n * Helper type to extract the _tag literal type from a TaggedError.\n *\n * @example\n * ```typescript\n * class MyError extends TaggedError(\"MyError\")<{ id: string }> {}\n * type Tag = TagOf<MyError>; // \"MyError\"\n * ```\n */\nexport type TagOf<E extends TaggedErrorBase> = E[\"_tag\"];\n\n/**\n * Helper type to extract a specific variant from a TaggedError union by tag.\n *\n * @example\n * ```typescript\n * type AppError = NotFoundError | ValidationError;\n * type NotFound = ErrorByTag<AppError, \"NotFoundError\">; // NotFoundError\n * ```\n */\nexport type ErrorByTag<\n E extends TaggedErrorBase,\n Tag extends E[\"_tag\"],\n> = Extract<E, { _tag: Tag }>;\n\n/**\n * Reserved keys that are stripped from user props at runtime.\n * These keys cannot be used as user-defined properties:\n * - _tag: discriminant for pattern matching\n * - name, message, stack: Error internals (preserved for logging/debugging)\n *\n * Note: 'cause' is NOT reserved - it can be used as a user prop.\n */\ntype ReservedErrorKeys = \"_tag\" | \"name\" | \"message\" | \"stack\";\n\n/**\n * Helper type to extract props from a TaggedError.\n * Excludes reserved keys that are stripped at runtime.\n *\n * @example\n * ```typescript\n * class MyError extends TaggedError(\"MyError\")<{ id: string }> {}\n * type Props = PropsOf<MyError>; // { id: string }\n *\n * // 'cause' is allowed as a user prop\n * class DomainError extends TaggedError(\"DomainError\")<{ cause: { field: string } }> {}\n * type DomainProps = PropsOf<DomainError>; // { cause: { field: string } }\n * ```\n */\nexport type PropsOf<E extends TaggedErrorBase> = Omit<E, ReservedErrorKeys>;\n","/**\n * awaitly/errors\n *\n * Pre-built error types for common failure scenarios.\n * Uses TaggedError for type-safe exhaustive matching.\n *\n * @example\n * ```typescript\n * import { TimeoutError, RetryExhaustedError, RateLimitError, CircuitOpenError } from 'awaitly/errors';\n *\n * // Create errors\n * const timeout = new TimeoutError({ operation: 'fetchUser', ms: 5000 });\n * const retryFailed = new RetryExhaustedError({ operation: 'sendEmail', attempts: 3 });\n *\n * // Pattern match\n * TaggedError.match(error, {\n * TimeoutError: (e) => `${e.operation} timed out after ${e.ms}ms`,\n * RetryExhaustedError: (e) => `${e.operation} failed after ${e.attempts} attempts`,\n * RateLimitError: (e) => `Rate limit exceeded, retry after ${e.retryAfterMs}ms`,\n * CircuitOpenError: (e) => `Circuit ${e.circuitName} is open`,\n * });\n * ```\n */\n\nimport { TaggedError } from \"./tagged-error\";\n\n// =============================================================================\n// Error Factory\n// =============================================================================\n\n/**\n * Factory function to create tagged error classes with default values.\n *\n * This is a convenience wrapper around TaggedError that allows specifying\n * default property values for error types.\n *\n * @example\n * ```typescript\n * // Define custom error with defaults\n * const NetworkError = makeError('NetworkError', {\n * defaults: { retryable: true },\n * message: (p) => `Network error: ${p.reason}`,\n * });\n *\n * class MyNetworkError extends NetworkError<{ reason: string; code?: number }> {}\n *\n * const error = new MyNetworkError({ reason: 'Connection refused' });\n * // error.retryable === true (from defaults)\n * ```\n */\nexport function makeError<Tag extends string>(\n tag: Tag,\n options?: {\n message?: (props: Record<string, unknown>) => string;\n defaults?: Record<string, unknown>;\n }\n) {\n const messageGenerator = options?.message ?? (() => tag);\n const defaults = options?.defaults ?? {};\n\n // Create base class using TaggedError\n const BaseClass = TaggedError(tag, {\n message: (props: Record<string, unknown>) =>\n messageGenerator({ ...defaults, ...props }),\n });\n\n // Return a factory that applies defaults\n return class extends BaseClass {\n constructor(props?: Record<string, unknown>) {\n super({ ...defaults, ...props } as Record<string, unknown>);\n // Apply defaults to instance\n Object.assign(this, { ...defaults, ...props });\n }\n };\n}\n\n// =============================================================================\n// Pre-built Error Types\n// =============================================================================\n\n/**\n * Error thrown when an operation times out.\n *\n * @example\n * ```typescript\n * const error = new TimeoutError({\n * operation: 'fetchUser',\n * ms: 5000,\n * });\n * console.log(error.message); // \"TimeoutError: fetchUser timed out after 5000ms\"\n * ```\n */\nexport class TimeoutError extends TaggedError(\"TimeoutError\", {\n message: (p: {\n /** Name of the operation that timed out */\n operation?: string;\n /** Timeout duration in milliseconds */\n ms: number;\n }) =>\n p.operation\n ? `TimeoutError: ${p.operation} timed out after ${p.ms}ms`\n : `TimeoutError: Operation timed out after ${p.ms}ms`,\n}) {}\n\n/**\n * Error thrown when all retry attempts are exhausted.\n *\n * @example\n * ```typescript\n * const error = new RetryExhaustedError({\n * operation: 'sendEmail',\n * attempts: 3,\n * lastError: originalError,\n * });\n * console.log(error.message); // \"RetryExhaustedError: sendEmail failed after 3 attempts\"\n * ```\n */\nexport class RetryExhaustedError extends TaggedError(\"RetryExhaustedError\", {\n message: (p: {\n /** Name of the operation that failed */\n operation?: string;\n /** Total number of retry attempts made */\n attempts: number;\n /** The last error encountered before giving up */\n lastError?: unknown;\n }) =>\n p.operation\n ? `RetryExhaustedError: ${p.operation} failed after ${p.attempts} attempts`\n : `RetryExhaustedError: Operation failed after ${p.attempts} attempts`,\n}) {}\n\n/**\n * Error thrown when a rate limit is exceeded.\n *\n * @example\n * ```typescript\n * const error = new RateLimitError({\n * limiterName: 'api-calls',\n * retryAfterMs: 1000,\n * });\n * console.log(error.message); // \"RateLimitError: Rate limit exceeded for api-calls\"\n * ```\n */\nexport class RateLimitError extends TaggedError(\"RateLimitError\", {\n message: (p: {\n /** Name of the rate limiter that was exceeded */\n limiterName?: string;\n /** Time in milliseconds until the rate limit resets */\n retryAfterMs?: number;\n }) =>\n p.limiterName\n ? `RateLimitError: Rate limit exceeded for ${p.limiterName}${p.retryAfterMs ? `, retry after ${p.retryAfterMs}ms` : \"\"}`\n : `RateLimitError: Rate limit exceeded${p.retryAfterMs ? `, retry after ${p.retryAfterMs}ms` : \"\"}`,\n}) {}\n\n/**\n * Error thrown when a circuit breaker is open.\n *\n * @example\n * ```typescript\n * const error = new CircuitBreakerOpenError({\n * circuitName: 'payment-api',\n * state: 'OPEN',\n * retryAfterMs: 30000,\n * });\n * console.log(error.message); // \"CircuitBreakerOpenError: Circuit payment-api is OPEN\"\n * ```\n */\nexport class CircuitBreakerOpenError extends TaggedError(\n \"CircuitBreakerOpenError\",\n {\n message: (p: {\n /** Name of the circuit breaker */\n circuitName: string;\n /** Current state of the circuit */\n state?: \"OPEN\" | \"HALF_OPEN\";\n /** Time in milliseconds until the circuit may close */\n retryAfterMs?: number;\n }) =>\n `CircuitBreakerOpenError: Circuit ${p.circuitName} is ${p.state ?? \"OPEN\"}${p.retryAfterMs ? `, retry after ${Math.ceil(p.retryAfterMs / 1000)}s` : \"\"}`,\n }\n) {}\n\n/**\n * Error thrown when validation fails.\n *\n * @example\n * ```typescript\n * const error = new ValidationError({\n * field: 'email',\n * reason: 'Invalid email format',\n * });\n * console.log(error.message); // \"ValidationError: Invalid email - Invalid email format\"\n * ```\n */\nexport class ValidationError extends TaggedError(\"ValidationError\", {\n message: (p: {\n /** Field that failed validation */\n field: string;\n /** Reason for validation failure */\n reason: string;\n /** Raw value that failed validation */\n value?: unknown;\n }) => `ValidationError: Invalid ${p.field} - ${p.reason}`,\n}) {}\n\n/**\n * Error thrown when a resource is not found.\n *\n * @example\n * ```typescript\n * const error = new NotFoundError({\n * resource: 'User',\n * id: '123',\n * });\n * console.log(error.message); // \"NotFoundError: User with id 123 not found\"\n * ```\n */\nexport class NotFoundError extends TaggedError(\"NotFoundError\", {\n message: (p: {\n /** Type of resource that was not found */\n resource: string;\n /** Identifier of the missing resource */\n id?: string;\n }) =>\n p.id\n ? `NotFoundError: ${p.resource} with id ${p.id} not found`\n : `NotFoundError: ${p.resource} not found`,\n}) {}\n\n/**\n * Error thrown when access is denied.\n *\n * @example\n * ```typescript\n * const error = new UnauthorizedError({\n * action: 'delete',\n * resource: 'User',\n * });\n * console.log(error.message); // \"UnauthorizedError: Not authorized to delete User\"\n * ```\n */\nexport class UnauthorizedError extends TaggedError(\"UnauthorizedError\", {\n message: (p: {\n /** Action that was attempted */\n action?: string;\n /** Resource that was being accessed */\n resource?: string;\n /** Reason for denial */\n reason?: string;\n }) =>\n p.reason\n ? `UnauthorizedError: ${p.reason}`\n : p.action && p.resource\n ? `UnauthorizedError: Not authorized to ${p.action} ${p.resource}`\n : \"UnauthorizedError: Access denied\",\n}) {}\n\n/**\n * Error thrown for network-related failures.\n *\n * @example\n * ```typescript\n * const error = new NetworkError({\n * url: 'https://api.example.com/users',\n * reason: 'Connection refused',\n * retryable: true,\n * });\n * ```\n */\nexport class NetworkError extends TaggedError(\"NetworkError\", {\n message: (p: {\n /** URL that was being accessed */\n url?: string;\n /** Reason for the network failure */\n reason: string;\n /** Whether this error is retryable */\n retryable?: boolean;\n /** HTTP status code if applicable */\n statusCode?: number;\n }) =>\n p.url\n ? `NetworkError: ${p.reason} (${p.url})`\n : `NetworkError: ${p.reason}`,\n}) {}\n\n/**\n * Error thrown when a saga compensation fails.\n *\n * @example\n * ```typescript\n * const error = new CompensationError({\n * step: 'chargeCard',\n * originalError: paymentError,\n * compensationError: refundError,\n * });\n * ```\n */\nexport class CompensationError extends TaggedError(\"CompensationError\", {\n message: (p: {\n /** Step that triggered compensation */\n step: string;\n /** The original error that caused compensation */\n originalError?: unknown;\n /** Error that occurred during compensation */\n compensationError?: unknown;\n }) => `CompensationError: Failed to compensate step ${p.step}`,\n}) {}\n\n// =============================================================================\n// Unexpected Error\n// =============================================================================\n\n/**\n * Default error type for uncaught exceptions and cancellation in workflows.\n * This is the default `U` type when `catchUnexpected` is not provided.\n *\n * @example\n * ```typescript\n * // Automatically used as the default — no need to pass catchUnexpected:\n * const workflow = createWorkflow(\"checkout\", { chargeCard, sendEmail });\n *\n * // Equivalent to:\n * const workflow = createWorkflow(\"checkout\", { chargeCard, sendEmail }, {\n * catchUnexpected: (cause) => new UnexpectedError({ cause }),\n * });\n * ```\n */\nexport class UnexpectedError extends TaggedError(\"UnexpectedError\", {\n message: (p: {\n /** The original thrown value or cancellation error */\n cause?: unknown;\n }) => `UnexpectedError: ${p.cause instanceof Error ? p.cause.message : String(p.cause ?? \"unknown\")}`,\n}) {}\n\n\n// =============================================================================\n// Union Type for Common Errors\n// =============================================================================\n\n/**\n * Union of all pre-built error types.\n * Useful for exhaustive pattern matching.\n *\n * @example\n * ```typescript\n * function handleError(error: AwaitlyError): string {\n * return TaggedError.match(error, {\n * TimeoutError: (e) => `Timeout: ${e.ms}ms`,\n * RetryExhaustedError: (e) => `Retries: ${e.attempts}`,\n * RateLimitError: (e) => `Rate limited`,\n * CircuitBreakerOpenError: (e) => `Circuit open: ${e.circuitName}`,\n * ValidationError: (e) => `Invalid: ${e.field}`,\n * NotFoundError: (e) => `Not found: ${e.resource}`,\n * UnauthorizedError: (e) => `Unauthorized`,\n * NetworkError: (e) => `Network: ${e.reason}`,\n * CompensationError: (e) => `Compensation failed: ${e.step}`,\n * });\n * }\n * ```\n */\nexport type AwaitlyError =\n | TimeoutError\n | RetryExhaustedError\n | RateLimitError\n | CircuitBreakerOpenError\n | ValidationError\n | NotFoundError\n | UnauthorizedError\n | NetworkError\n | CompensationError;\n\n// =============================================================================\n// Type Guards\n// =============================================================================\n\n/**\n * Check if an error is a TimeoutError.\n */\nexport function isTimeoutError(error: unknown): error is TimeoutError {\n return TaggedError.isTaggedError(error) && error._tag === \"TimeoutError\";\n}\n\n/**\n * Check if an error is a RetryExhaustedError.\n */\nexport function isRetryExhaustedError(\n error: unknown\n): error is RetryExhaustedError {\n return (\n TaggedError.isTaggedError(error) && error._tag === \"RetryExhaustedError\"\n );\n}\n\n/**\n * Check if an error is a RateLimitError.\n */\nexport function isRateLimitError(error: unknown): error is RateLimitError {\n return TaggedError.isTaggedError(error) && error._tag === \"RateLimitError\";\n}\n\n/**\n * Check if an error is a CircuitBreakerOpenError.\n */\nexport function isCircuitBreakerOpenError(\n error: unknown\n): error is CircuitBreakerOpenError {\n return (\n TaggedError.isTaggedError(error) && error._tag === \"CircuitBreakerOpenError\"\n );\n}\n\n/**\n * Check if an error is a ValidationError.\n */\nexport function isValidationError(error: unknown): error is ValidationError {\n return TaggedError.isTaggedError(error) && error._tag === \"ValidationError\";\n}\n\n/**\n * Check if an error is a NotFoundError.\n */\nexport function isNotFoundError(error: unknown): error is NotFoundError {\n return TaggedError.isTaggedError(error) && error._tag === \"NotFoundError\";\n}\n\n/**\n * Check if an error is an UnauthorizedError.\n */\nexport function isUnauthorizedError(\n error: unknown\n): error is UnauthorizedError {\n return TaggedError.isTaggedError(error) && error._tag === \"UnauthorizedError\";\n}\n\n/**\n * Check if an error is a NetworkError.\n */\nexport function isNetworkError(error: unknown): error is NetworkError {\n return TaggedError.isTaggedError(error) && error._tag === \"NetworkError\";\n}\n\n/**\n * Check if an error is a CompensationError.\n */\nexport function isCompensationError(\n error: unknown\n): error is CompensationError {\n return TaggedError.isTaggedError(error) && error._tag === \"CompensationError\";\n}\n\n/**\n * Check if an error is any AwaitlyError.\n */\nexport function isAwaitlyError(error: unknown): error is AwaitlyError {\n if (!TaggedError.isTaggedError(error)) return false;\n const tag = error._tag;\n return [\n \"TimeoutError\",\n \"RetryExhaustedError\",\n \"RateLimitError\",\n \"CircuitBreakerOpenError\",\n \"ValidationError\",\n \"NotFoundError\",\n \"UnauthorizedError\",\n \"NetworkError\",\n \"CompensationError\",\n ].includes(tag);\n}\n","/**\n * awaitly/result (internal)\n *\n * Core Result primitives - minimal bundle for typed error handling.\n * This file is intentionally kept small for optimal tree-shaking.\n * The full orchestration (run, step, etc.) lives in core.ts.\n */\n\n// =============================================================================\n// Core Result Types\n// =============================================================================\n\n/**\n * Represents a successful result.\n * Use `ok(value)` to create instances.\n */\nexport type Ok<T> = {\n ok: true;\n value: T;\n};\n\n/**\n * Represents a failed result.\n * Use `err(error)` to create instances.\n */\nexport type Err<E, C = unknown> = {\n ok: false;\n error: E;\n cause?: C;\n};\n\n/**\n * Represents a successful computation or a failed one.\n */\nexport type Result<T, E = unknown, C = unknown> = Ok<T> | Err<E, C>;\n\n/**\n * A Promise that resolves to a Result.\n */\nexport type AsyncResult<T, E = unknown, C = unknown> = Promise<Result<T, E, C>>;\n\n/** Discriminant for PromiseRejectedError type - use in switch statements */\nexport const PROMISE_REJECTED = \"PROMISE_REJECTED\" as const;\n\n// =============================================================================\n// Named Error Constants (for static analysis)\n// =============================================================================\n\n/**\n * Named error constant for unexpected/unhandled errors.\n * Used by the analyzer when a step doesn't declare errors.\n */\nexport const AWAITLY_UNEXPECTED = \"AWAITLY_UNEXPECTED\" as const;\n\n/**\n * Named error constant for cancelled operations.\n */\nexport const AWAITLY_CANCELLED = \"AWAITLY_CANCELLED\" as const;\n\n/**\n * Named error constant for timed-out operations.\n */\nexport const AWAITLY_TIMEOUT = \"AWAITLY_TIMEOUT\" as const;\n\n// =============================================================================\n// Static Analysis Helpers\n// =============================================================================\n\n/**\n * Helper to create a tuple of string literal tags with preserved literal types.\n * Use this when you need to store error tags in a variable while keeping\n * TypeScript's literal type inference (avoiding widening to string[]).\n *\n * @param t - The string literal tags\n * @returns The same array with preserved literal types\n *\n * @example\n * ```typescript\n * // Without tags() - type widens to string[]\n * const errs = ['CART_NOT_FOUND', 'CART_EMPTY']; // string[]\n *\n * // With tags() - literal types preserved\n * const errs = tags('CART_NOT_FOUND', 'CART_EMPTY'); // readonly ['CART_NOT_FOUND', 'CART_EMPTY']\n *\n * await step('getCart', () => getCart(id), {\n * errors: errs, // Analyzer can extract literal types\n * out: 'cart',\n * });\n * ```\n */\nexport const tags = <const T extends readonly string[]>(...t: T): T => t;\n\nimport { UnexpectedError } from \"../errors\";\nexport { UnexpectedError };\nexport type PromiseRejectedError = { type: typeof PROMISE_REJECTED; cause: unknown };\n/** Cause type for promise rejections in async batch helpers */\nexport type PromiseRejectionCause = { type: \"PROMISE_REJECTION\"; reason: unknown };\nexport type EmptyInputError = { type: \"EMPTY_INPUT\"; message: string };\nexport type MaybeAsyncResult<T, E, C = unknown> = Result<T, E, C> | Promise<Result<T, E, C>>;\n\n// =============================================================================\n// Result Constructors\n// =============================================================================\n\n/**\n * Creates a successful Result.\n *\n * @remarks When to use: Wrap a successful value in a Result for consistent return types.\n */\nexport function ok(): Ok<void>;\nexport function ok<T>(value: T): Ok<T>;\nexport function ok<T>(value?: T): Ok<T | void> {\n return { ok: true as const, value: value as T | void };\n}\n\n/**\n * Creates a failed Result.\n *\n * @remarks When to use: Return a typed failure without throwing so callers can handle it explicitly.\n */\nexport function err<E, C = unknown>(error: E, options?: { cause?: C }): Err<E, C> {\n const cause = options?.cause;\n return { ok: false as const, error, ...(cause !== undefined ? { cause } : {}) } as Err<E, C>;\n}\n\n// =============================================================================\n// Type Guards\n// =============================================================================\n\n/**\n * Checks if a Result is successful.\n *\n * @remarks When to use: Prefer functional-style checks or array filtering over `result.ok`.\n */\nexport const isOk = <T, E, C>(r: Result<T, E, C>): r is Ok<T> => r.ok;\n\n/**\n * Checks if a Result is a failure.\n *\n * @remarks When to use: Prefer functional-style checks or array filtering over `result.ok`.\n */\nexport const isErr = <T, E, C>(r: Result<T, E, C>): r is Err<E, C> => !r.ok;\n\n/**\n * Checks if an error is an UnexpectedError.\n *\n * @remarks When to use: Distinguish unexpected failures from your typed error union.\n */\nexport const isUnexpectedError = (e: unknown): e is UnexpectedError =>\n e instanceof UnexpectedError ||\n (typeof e === \"object\" &&\n e !== null &&\n \"_tag\" in e &&\n (e as { _tag: string })._tag === \"UnexpectedError\");\n\n/**\n * Checks if an error is a PromiseRejectedError.\n */\nexport const isPromiseRejectedError = (e: unknown): e is PromiseRejectedError =>\n typeof e === \"object\" &&\n e !== null &&\n \"type\" in e &&\n e.type === PROMISE_REJECTED;\n\n// =============================================================================\n// Error Matching\n// =============================================================================\n\nexport type MatchErrorHandlers<E extends string, R> = {\n [K in Exclude<E, \"UnexpectedError\">]: (error: K) => R;\n} & {\n UnexpectedError: (error: UnexpectedError) => R;\n};\n\n/**\n * Match on string error types with exhaustive checking.\n * Takes an error value (not a Result) and handlers for each error type.\n */\nexport function matchError<E extends string, R>(\n error: E | UnexpectedError,\n handlers: MatchErrorHandlers<E, R>\n): R {\n // Handle UnexpectedError instances\n if (isUnexpectedError(error)) {\n return handlers.UnexpectedError(error as UnexpectedError);\n }\n // Handle string literal errors\n type StringErrors = Exclude<E, \"UnexpectedError\">;\n return (handlers as unknown as Record<string, (e: string) => R>)[error as StringErrors](error as StringErrors);\n}\n\n// =============================================================================\n// Type Utilities\n// =============================================================================\n\ntype AnyFunction = (...args: never[]) => unknown;\n\n/**\n * Helper to extract the error type from Result or AsyncResult return values.\n * Works even when a function is declared to return a union of both forms.\n */\ntype ErrorOfReturn<R> = Extract<Awaited<R>, { ok: false }> extends { error: infer E }\n ? E\n : never;\n\n/**\n * Extract error type from a single function's return type\n */\nexport type ErrorOf<T extends AnyFunction> = ErrorOfReturn<ReturnType<T>>;\n\n/**\n * Extract union of error types from multiple functions\n */\nexport type Errors<T extends AnyFunction[]> = {\n [K in keyof T]: ErrorOf<T[K]>;\n}[number];\n\n/**\n * Extract value type from Result\n */\nexport type ExtractValue<T> = T extends { ok: true; value: infer U }\n ? U\n : never;\n\n/**\n * Extract error type from Result\n */\nexport type ExtractError<T> = T extends { ok: false; error: infer E }\n ? E\n : never;\n\n/**\n * Extract cause type from Result\n */\nexport type ExtractCause<T> = T extends { ok: false; cause?: infer C }\n ? C\n : never;\n\n/**\n * Helper to extract the cause type from Result or AsyncResult return values.\n * Works even when a function is declared to return a union of both forms.\n */\ntype CauseOfReturn<R> = Extract<Awaited<R>, { ok: false }> extends { cause?: infer C }\n ? C\n : never;\n\n/**\n * Extract cause type from a function's return type\n */\nexport type CauseOf<T extends AnyFunction> = CauseOfReturn<ReturnType<T>>;\n\n// =============================================================================\n// Unwrap Utilities\n// =============================================================================\n\n/**\n * Error thrown when attempting to unwrap an Err result.\n */\nexport class UnwrapError extends Error {\n public readonly error: unknown;\n public readonly cause?: unknown;\n\n constructor(result: Err<unknown, unknown>) {\n const errorStr =\n typeof result.error === \"string\"\n ? result.error\n : JSON.stringify(result.error);\n super(`Attempted to unwrap an Err: ${errorStr}`);\n this.name = \"UnwrapError\";\n this.error = result.error;\n this.cause = result.cause;\n }\n}\n\n/**\n * Extracts the value from an Ok result, or throws UnwrapError if it's an Err.\n *\n * @remarks When to use: Only at boundaries or tests where a failure should be fatal.\n */\nexport const unwrap = <T, E, C>(r: Result<T, E, C>): T => {\n if (r.ok) return r.value;\n throw new UnwrapError(r);\n};\n\n/**\n * Extracts the value from an Ok result, or returns a default value if it's an Err.\n *\n * @remarks When to use: Provide a safe fallback without branching.\n */\nexport const unwrapOr = <T, E, C>(r: Result<T, E, C>, defaultValue: T): T =>\n r.ok ? r.value : defaultValue;\n\n/**\n * Extracts the value from an Ok result, or calls a function to get a default value if it's an Err.\n *\n * @remarks When to use: Compute a fallback from the error (logging, metrics, or derived defaults).\n */\nexport const unwrapOrElse = <T, E, C>(\n r: Result<T, E, C>,\n fn: (error: E, cause?: C) => T\n): T => (r.ok ? r.value : fn(r.error, r.cause));\n\n/**\n * Alias for `unwrap`. Returns the success value or throws.\n *\n * The Result is already computed; use when you want the value or throw (e.g. at boundaries or in tests).\n *\n * @param r - The Result to unwrap\n * @returns The success value if the Result is successful\n * @throws {UnwrapError} If the Result is an error (includes the error and cause)\n */\nexport const runOrThrow = <T, E, C>(r: Result<T, E, C>): T => unwrap(r);\n\n/**\n * Awaits a Promise of a Result, then returns the success value or rejects.\n *\n * The returned promise **resolves with T** on success and **rejects with UnwrapError** on failure.\n * UnwrapError extends Error and carries the original `error` and `cause` from the Err.\n *\n * @param ar - A Promise or thenable that resolves to a Result\n * @returns A Promise that resolves with the success value or rejects with UnwrapError\n */\nexport const runOrThrowAsync = <T, E, C>(\n ar: PromiseLike<Result<T, E, C>>\n): Promise<T> => Promise.resolve(ar).then(unwrap);\n\n/**\n * Convenience alias for `unwrapOr(r, null)`. Returns the success value or null.\n *\n * @param r - The Result to unwrap\n * @returns The success value if successful, otherwise null\n */\nexport const runOrNull = <T, E, C>(r: Result<T, E, C>): T | null =>\n r.ok ? r.value : null;\n\n/**\n * Convenience alias for `unwrapOr(r, undefined)`. Returns the success value or undefined.\n *\n * @param r - The Result to unwrap\n * @returns The success value if successful, otherwise undefined\n */\nexport const runOrUndefined = <T, E, C>(r: Result<T, E, C>): T | undefined =>\n r.ok ? r.value : undefined;\n\n// =============================================================================\n// Wrapping Functions\n// =============================================================================\n\n/**\n * Wraps a synchronous function that might throw into a Result.\n *\n * @remarks When to use: Wrap sync code that might throw so exceptions become Err values.\n */\nexport function from<T>(fn: () => T): Ok<T> | Err<unknown, unknown>;\nexport function from<T, E>(fn: () => T, onError: (cause: unknown) => E): Ok<T> | Err<E, unknown>;\nexport function from<T, E>(fn: () => T, onError?: (cause: unknown) => E) {\n try {\n return ok(fn());\n } catch (cause) {\n return onError ? err(onError(cause), { cause }) : err(cause);\n }\n}\n\n/**\n * Wraps a Promise into a Result.\n *\n * @remarks When to use: Wrap a Promise and keep the raw rejection as Err; use tryAsync to map errors.\n */\nexport function fromPromise<T>(promise: Promise<T>): Promise<Ok<T> | Err<unknown, unknown>>;\nexport function fromPromise<T, E>(\n promise: Promise<T>,\n onError: (cause: unknown) => E\n): Promise<Ok<T> | Err<E, unknown>>;\nexport async function fromPromise<T, E>(\n promise: Promise<T>,\n onError?: (cause: unknown) => E\n): Promise<Ok<T> | Err<E | unknown, unknown>> {\n try {\n return ok(await promise);\n } catch (cause) {\n return onError ? err(onError(cause), { cause }) : err(cause);\n }\n}\n\n/**\n * Wraps an async function that might throw into an AsyncResult.\n *\n * @remarks When to use: Wrap async work and map thrown/rejected values into your typed error union.\n */\nexport function tryAsync<T>(fn: () => Promise<T>): AsyncResult<T, unknown>;\nexport function tryAsync<T, E>(\n fn: () => Promise<T>,\n onError: (cause: unknown) => E\n): AsyncResult<T, E>;\nexport async function tryAsync<T, E>(\n fn: () => Promise<T>,\n onError?: (cause: unknown) => E\n): AsyncResult<T, E | unknown> {\n try {\n return ok(await fn());\n } catch (cause) {\n return onError ? err(onError(cause), { cause }) : err(cause);\n }\n}\n\n/**\n * Converts a nullable value into a Result.\n *\n * @remarks When to use: Turn null/undefined into a typed error before continuing.\n */\nexport function fromNullable<T, E>(\n value: T | null | undefined,\n onNull: () => E\n): Result<T, E> {\n return value != null ? ok(value) : err(onNull());\n}\n\n// =============================================================================\n// Transformers\n// =============================================================================\n\n/**\n * Transforms the value inside an Ok result.\n *\n * @remarks When to use: Transform only the Ok value while leaving Err untouched.\n */\nexport function map<T, U>(r: Ok<T>, fn: (value: T) => U): Ok<U>;\nexport function map<T, U, E, C>(r: Err<E, C>, fn: (value: T) => U): Err<E, C>;\nexport function map<T, U, E, C>(r: Result<T, E, C>, fn: (value: T) => U): Result<U, E, C>;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function map(r: any, fn: any): any {\n return r.ok ? ok(fn(r.value)) : r;\n}\n\n/**\n * Transforms the error inside an Err result.\n *\n * @remarks When to use: Retype or normalize errors while leaving Ok values unchanged.\n */\nexport function mapError<T, E, F, C>(\n r: Result<T, E, C>,\n fn: (error: E, cause?: C) => F\n): Result<T, F, C> {\n return r.ok ? r : err(fn(r.error, r.cause), { cause: r.cause });\n}\n\n/**\n * Pattern match on a Result.\n *\n * @remarks When to use: Handle both Ok and Err in a single expression that returns a value.\n */\nexport function match<T, E, C, R>(r: Ok<T>, handlers: { ok: (value: T) => R; err: (error: E, cause?: C) => R }): R;\nexport function match<T, E, C, R>(r: Err<E, C>, handlers: { ok: (value: T) => R; err: (error: E, cause?: C) => R }): R;\nexport function match<T, E, C, R>(r: Result<T, E, C>, handlers: { ok: (value: T) => R; err: (error: E, cause?: C) => R }): R;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function match(r: any, handlers: any): any {\n return r.ok ? handlers.ok(r.value) : handlers.err(r.error, r.cause);\n}\n\n/**\n * Chain Result-returning functions.\n *\n * @remarks When to use: Chain dependent operations that return Result without nested branching.\n */\nexport function andThen<T, U>(r: Ok<T>, fn: (value: T) => Ok<U>): Ok<U>;\nexport function andThen<T, F, C2>(r: Ok<T>, fn: (value: T) => Err<F, C2>): Err<F, C2>;\nexport function andThen<T, U, F, C2>(r: Ok<T>, fn: (value: T) => Result<U, F, C2>): Result<U, F, C2>;\nexport function andThen<T, U, E, F, C1, C2>(r: Err<E, C1>, fn: (value: T) => Result<U, F, C2>): Err<E, C1>;\nexport function andThen<T, U, E, F, C1, C2>(r: Result<T, E, C1>, fn: (value: T) => Result<U, F, C2>): Result<U, E | F, C1 | C2>;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function andThen(r: any, fn: any): any {\n return r.ok ? fn(r.value) : r;\n}\n\n/**\n * Execute a side effect on Ok values.\n *\n * @remarks When to use: Add side effects (logging, metrics) on Ok without changing the Result.\n */\nexport function tap<T, E, C>(\n r: Result<T, E, C>,\n fn: (value: T) => void\n): Result<T, E, C> {\n if (r.ok) fn(r.value);\n return r;\n}\n\n/**\n * Execute a side effect on Err values.\n *\n * @remarks When to use: Add side effects (logging, metrics) on Err without changing the Result.\n */\nexport function tapError<T, E, C>(\n r: Result<T, E, C>,\n fn: (error: E, cause?: C) => void\n): Result<T, E, C> {\n if (!r.ok) fn(r.error, r.cause);\n return r;\n}\n\n/**\n * Transform value with a function that might throw.\n *\n * @remarks When to use: Transform Ok values with a function that might throw and capture the failure.\n */\nexport function mapTry<T, U, E, F, C>(\n r: Result<T, E, C>,\n fn: (value: T) => U,\n onError: (thrown: unknown) => F\n): Result<U, E | F, C | unknown> {\n if (!r.ok) return r;\n try {\n return ok(fn(r.value));\n } catch (error) {\n return err(onError(error), { cause: error });\n }\n}\n\n/**\n * Transform error with a function that might throw.\n *\n * @remarks When to use: Transform errors when the mapping might throw and you want that captured.\n */\nexport function mapErrorTry<T, E, F, G, C>(\n r: Result<T, E, C>,\n fn: (error: E) => F,\n onError: (thrown: unknown) => G\n): Result<T, F | G, C | unknown> {\n if (r.ok) return r;\n try {\n return err(fn(r.error), { cause: r.cause });\n } catch (error) {\n return err(onError(error), { cause: error });\n }\n}\n\n/**\n * Transform both value and error.\n */\nexport function bimap<T, U, E, F, C>(\n r: Result<T, E, C>,\n onOk: (value: T) => U,\n onErr: (error: E, cause?: C) => F\n): Result<U, F, C> {\n return r.ok ? ok(onOk(r.value)) : err(onErr(r.error, r.cause), { cause: r.cause });\n}\n\n/**\n * Provide an alternative Result if the first is an Err.\n *\n * @remarks When to use: Recover from Err by returning a fallback Result or retyping the error.\n */\nexport function orElse<T, E, E2, C, C2>(\n r: Result<T, E, C>,\n fn: (error: E, cause?: C) => Result<T, E2, C2>\n): Result<T, E2, C | C2> {\n return r.ok ? r : fn(r.error, r.cause);\n}\n\n/**\n * Async version of orElse.\n */\nexport async function orElseAsync<T, E, E2, C, C2>(\n r: Result<T, E, C>,\n fn: (error: E, cause?: C) => Promise<Result<T, E2, C2>>\n): Promise<Result<T, E2, C | C2>> {\n return r.ok ? r : fn(r.error, r.cause);\n}\n\n/**\n * Recover from errors - always returns Ok<T>.\n */\nexport function recover<T, E, C>(\n r: Result<T, E, C>,\n fn: (error: E, cause?: C) => T\n): Ok<T> {\n return r.ok ? ok(r.value) : ok(fn(r.error, r.cause));\n}\n\n/**\n * Async version of recover - always returns Promise<Ok<T>>.\n */\nexport async function recoverAsync<T, E, C>(\n r: Result<T, E, C> | Promise<Result<T, E, C>>,\n fn: (error: E, cause?: C) => T | Promise<T>\n): Promise<Ok<T>> {\n const resolved = await r;\n if (resolved.ok) return ok(resolved.value);\n return ok(await fn(resolved.error, resolved.cause));\n}\n\n// =============================================================================\n// Result Hydration (Serialization)\n// =============================================================================\n\n/**\n * Hydrate a serialized Result back into a proper Result object.\n */\nexport function hydrate<T, E, C = unknown>(value: unknown): Result<T, E, C> | null {\n if (typeof value !== \"object\" || value === null) return null;\n if (!(\"ok\" in value)) return null;\n\n const obj = value as Record<string, unknown>;\n if (obj.ok === true && \"value\" in obj) {\n return ok(obj.value as T);\n }\n if (obj.ok === false && \"error\" in obj) {\n return err(obj.error as E, { cause: obj.cause as C });\n }\n return null;\n}\n\n/**\n * Type guard to check if a value is a serialized Result.\n */\nexport function isSerializedResult(\n value: unknown\n): value is { ok: boolean; value?: unknown; error?: unknown; cause?: unknown } {\n if (typeof value !== \"object\" || value === null) return false;\n if (!(\"ok\" in value)) return false;\n const obj = value as Record<string, unknown>;\n return (\n (obj.ok === true && \"value\" in obj) ||\n (obj.ok === false && \"error\" in obj)\n );\n}\n\n// =============================================================================\n// Batch Operations\n// =============================================================================\n\ntype AllValues<T extends readonly Result<unknown, unknown, unknown>[]> = {\n [K in keyof T]: T[K] extends Ok<infer V>\n ? V\n : T[K] extends Err<unknown, unknown>\n ? never\n : T[K] extends Result<infer V, unknown, unknown>\n ? V\n : never;\n};\ntype AllErrors<T extends readonly Result<unknown, unknown, unknown>[]> = {\n [K in keyof T]: T[K] extends Ok<unknown>\n ? never\n : T[K] extends Err<infer E, unknown>\n ? E\n : T[K] extends Result<unknown, infer E, unknown>\n ? E\n : never;\n}[number];\ntype AllCauses<T extends readonly Result<unknown, unknown, unknown>[]> = {\n [K in keyof T]: T[K] extends Ok<unknown>\n ? never\n : T[K] extends Err<unknown, infer C>\n ? C\n : T[K] extends Result<unknown, unknown, infer C>\n ? C\n : never;\n}[number];\n\n// Conditional type: returns Ok<...> when there are no errors, Result<...> otherwise\n// Note: We only check AllErrors, not AllCauses - causes only matter when there are errors\ntype AllResult<T extends readonly Result<unknown, unknown, unknown>[]> =\n [AllErrors<T>] extends [never]\n ? Ok<AllValues<T>>\n : Result<AllValues<T>, AllErrors<T>, AllCauses<T>>;\n\n/**\n * Combines multiple Results into a single Result containing an array of values.\n * Returns the first Err encountered, or Ok with all values.\n */\nexport function all<const T extends readonly Result<unknown, unknown, unknown>[]>(\n results: T\n): AllResult<T> {\n const values: unknown[] = [];\n for (const result of results) {\n if (!result.ok) {\n return result as unknown as AllResult<T>;\n }\n values.push(result.value);\n }\n return ok(values) as AllResult<T>;\n}\n\n/**\n * Async version of all - works with Promises of Results.\n */\nexport async function allAsync<\n const T extends readonly (Result<unknown, unknown, unknown> | Promise<Result<unknown, unknown, unknown>>)[]\n>(\n results: T\n): Promise<\n Result<\n { [K in keyof T]: T[K] extends Result<infer V, unknown, unknown> | Promise<Result<infer V, unknown, unknown>> ? V : never },\n | { [K in keyof T]: T[K] extends Result<unknown, infer E, unknown> | Promise<Result<unknown, infer E, unknown>> ? E : never }[number]\n | PromiseRejectedError,\n | { [K in keyof T]: T[K] extends Result<unknown, unknown, infer C> | Promise<Result<unknown, unknown, infer C>> ? C : never }[number]\n | PromiseRejectionCause\n >\n> {\n const values: unknown[] = [];\n for (const resultOrPromise of results) {\n try {\n const r = await resultOrPromise;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if (!r.ok) return r as any;\n values.push(r.value);\n } catch (reason) {\n return err(\n { type: PROMISE_REJECTED, cause: reason } as PromiseRejectedError,\n { cause: { type: \"PROMISE_REJECTION\", reason } as PromiseRejectionCause }\n );\n }\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return ok(values) as any;\n}\n\nexport type SettledError<E, C = unknown> = { error: E; cause?: C };\n\n// Conditional type: returns Ok<...> when there are no errors, Result<...> otherwise\ntype AllSettledResult<T extends readonly Result<unknown, unknown, unknown>[]> =\n [AllErrors<T>] extends [never]\n ? Ok<AllValues<T>>\n : Result<AllValues<T>, SettledError<AllErrors<T>, AllCauses<T>>[]>;\n\n/**\n * Collects all Results, returning Ok with values if all succeed,\n * or Err with array of errors if any fail.\n */\nexport function allSettled<const T extends readonly Result<unknown, unknown, unknown>[]>(\n results: T\n): AllSettledResult<T> {\n const values: unknown[] = [];\n const errors: SettledError<unknown>[] = [];\n\n for (const result of results) {\n if (result.ok) {\n values.push(result.value);\n } else {\n errors.push({ error: result.error, cause: result.cause });\n }\n }\n\n if (errors.length > 0) {\n return err(errors) as unknown as AllSettledResult<T>;\n }\n\n return ok(values) as unknown as AllSettledResult<T>;\n}\n\n/**\n * Async version of allSettled.\n */\nexport async function allSettledAsync<\n const T extends readonly (Result<unknown, unknown, unknown> | Promise<Result<unknown, unknown, unknown>>)[]\n>(\n results: T\n): Promise<\n Result<\n { [K in keyof T]: T[K] extends Result<infer V, unknown, unknown> | Promise<Result<infer V, unknown, unknown>> ? V : never },\n SettledError<\n | { [K in keyof T]: T[K] extends Result<unknown, infer E, unknown> | Promise<Result<unknown, infer E, unknown>> ? E : never }[number]\n | PromiseRejectedError,\n | { [K in keyof T]: T[K] extends Result<unknown, unknown, infer C> | Promise<Result<unknown, unknown, infer C>> ? C : never }[number]\n | PromiseRejectionCause\n >[]\n >\n> {\n const settled = await Promise.all(\n results.map((item) =>\n Promise.resolve(item)\n .then((result) => ({ status: \"result\" as const, result }))\n .catch((reason) => ({\n status: \"rejected\" as const,\n error: { type: PROMISE_REJECTED, cause: reason } as PromiseRejectedError,\n cause: { type: \"PROMISE_REJECTION\", reason } as PromiseRejectionCause,\n }))\n )\n );\n\n const values: unknown[] = [];\n const errors: SettledError<unknown, unknown>[] = [];\n\n for (const item of settled) {\n if (item.status === \"rejected\") {\n errors.push({ error: item.error, cause: item.cause });\n } else if (item.result.ok) {\n values.push(item.result.value);\n } else {\n errors.push({ error: item.result.error, cause: item.result.cause });\n }\n }\n\n if (errors.length > 0) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return err(errors) as any;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return ok(values) as any;\n}\n\n/**\n * Partitions Results into { values, errors }.\n */\nexport function partition<T, E, C>(\n results: readonly Result<T, E, C>[]\n): { values: T[]; errors: E[] } {\n const values: T[] = [];\n const errors: E[] = [];\n for (const r of results) {\n if (r.ok) values.push(r.value);\n else errors.push(r.error);\n }\n return { values, errors };\n}\n\n/**\n * Returns the first Ok result, or an EmptyInputError/first Err if all fail.\n */\nexport function any<const T extends readonly Result<unknown, unknown, unknown>[]>(\n results: T\n): T extends readonly []\n ? Err<EmptyInputError, unknown>\n : Result<\n { [K in keyof T]: T[K] extends Result<infer V, unknown, unknown> ? V : never }[number],\n AllErrors<T> | EmptyInputError,\n AllCauses<T>\n >;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function any(results: any): any {\n if (results.length === 0) {\n return err({ type: \"EMPTY_INPUT\", message: \"any() requires at least one Result\" });\n }\n let firstErr: Err<unknown, unknown> | undefined;\n for (const r of results) {\n if (r.ok) return r;\n if (!firstErr) firstErr = r;\n }\n return firstErr;\n}\n\n/**\n * Async version of any - races promises and returns first success.\n */\nexport async function anyAsync<\n const T extends readonly (Result<unknown, unknown, unknown> | Promise<Result<unknown, unknown, unknown>>)[]\n>(\n results: T\n): Promise<\n T extends readonly []\n ? Err<EmptyInputError, unknown>\n : Result<\n { [K in keyof T]: T[K] extends Result<infer V, unknown, unknown> | Promise<Result<infer V, unknown, unknown>> ? V : never }[number],\n | { [K in keyof T]: T[K] extends Result<unknown, infer E, unknown> | Promise<Result<unknown, infer E, unknown>> ? E : never }[number]\n | EmptyInputError\n | PromiseRejectedError,\n | { [K in keyof T]: T[K] extends Result<unknown, unknown, infer C> | Promise<Result<unknown, unknown, infer C>> ? C : never }[number]\n | PromiseRejectionCause\n >\n> {\n if (results.length === 0) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return err({ type: \"EMPTY_INPUT\", message: \"anyAsync() requires at least one Result\" }) as any;\n }\n\n return new Promise((resolve) => {\n let settled = false;\n let pendingCount = results.length;\n let firstError: Err<unknown, unknown> | null = null;\n\n for (const item of results) {\n Promise.resolve(item)\n .catch((reason) =>\n err(\n { type: PROMISE_REJECTED, cause: reason } as PromiseRejectedError,\n { cause: { type: \"PROMISE_REJECTION\", reason } as PromiseRejectionCause }\n )\n )\n .then((result) => {\n if (settled) return;\n\n if (result.ok) {\n settled = true;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n resolve(result as any);\n return;\n }\n\n if (!firstError) firstError = result;\n pendingCount--;\n\n if (pendingCount === 0) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n resolve(firstError as any);\n }\n });\n }\n });\n}\n\n/**\n * Combines exactly two Results into a tuple.\n */\nexport function zip<A, EA, CA, B, EB, CB>(\n a: Result<A, EA, CA>,\n b: Result<B, EB, CB>\n): Result<[A, B], EA | EB, CA | CB> {\n if (!a.ok) return a;\n if (!b.ok) return b;\n return ok([a.value, b.value]);\n}\n\n/**\n * Async version of zip.\n */\nexport async function zipAsync<A, EA, CA, B, EB, CB>(\n a: Result<A, EA, CA> | Promise<Result<A, EA, CA>>,\n b: Result<B, EB, CB> | Promise<Result<B, EB, CB>>\n): Promise<Result<[A, B], EA | EB | PromiseRejectedError, CA | CB | PromiseRejectionCause>> {\n // Wrap rejections into PromiseRejectedError (consistent with allAsync)\n const wrapRejection = <T, E, C>(\n p: Result<T, E, C> | Promise<Result<T, E, C>>\n ): Promise<Result<T, E | PromiseRejectedError, C | PromiseRejectionCause>> =>\n Promise.resolve(p).catch((reason) =>\n err(\n { type: PROMISE_REJECTED, cause: reason } as PromiseRejectedError,\n { cause: { type: \"PROMISE_REJECTION\", reason } as PromiseRejectionCause }\n )\n );\n\n const [ra, rb] = await Promise.all([wrapRejection(a), wrapRejection(b)]);\n return zip(ra, rb);\n}\n\n// =============================================================================\n// Flatten\n// =============================================================================\n\n/**\n * Flattens a nested Result into a single Result.\n *\n * @remarks When to use: Unwrap a Result<Result<T, E1>, E2> into Result<T, E1 | E2> after an operation that returns nested Results.\n */\nexport function flatten<T, E1, C1, E2, C2>(\n result: Result<Result<T, E1, C1>, E2, C2>\n): Result<T, E1 | E2, C1 | C2> {\n if (!result.ok) return result as Err<E2, C2>;\n return result.value;\n}\n\n// =============================================================================\n// Deserialization (improved hydrate)\n// =============================================================================\n\n/** Discriminant for deserialization errors */\nexport const DESERIALIZATION_ERROR = \"DESERIALIZATION_ERROR\" as const;\n\n/** Error type returned when deserialize() receives invalid input */\nexport type DeserializationError = { type: typeof DESERIALIZATION_ERROR; value: unknown };\n\n/**\n * Deserialize a value back into a Result.\n * Returns a typed DeserializationError on invalid input instead of null.\n *\n * @remarks When to use: Rehydrate Results from JSON, RPC, or server actions with type-safe error handling.\n */\nexport function deserialize<T, E, C = unknown>(\n value: unknown\n): Result<T, E | DeserializationError, C> {\n if (typeof value !== \"object\" || value === null) {\n return err({ type: DESERIALIZATION_ERROR, value } as DeserializationError);\n }\n if (!(\"ok\" in value)) {\n return err({ type: DESERIALIZATION_ERROR, value } as DeserializationError);\n }\n\n const obj = value as Record<string, unknown>;\n if (obj.ok === true && \"value\" in obj) {\n return ok(obj.value as T);\n }\n if (obj.ok === false && \"error\" in obj) {\n return err(obj.error as E, { cause: obj.cause as C });\n }\n return err({ type: DESERIALIZATION_ERROR, value } as DeserializationError);\n}\n\n// =============================================================================\n// Serialization\n// =============================================================================\n\n/** A plain serialized form of a Result, safe to JSON.stringify. */\nexport type SerializedResult<T, E> = { ok: true; value: T } | { ok: false; error: E };\n\n/**\n * Serialize a Result to a plain object (inverse of `deserialize`).\n * Strips cause — safe for JSON.stringify, RPC, and server actions.\n *\n * @remarks When to use: Sending Results over the wire or storing them in JSON.\n */\nexport function serialize<T, E>(result: Result<T, E>): SerializedResult<T, E> {\n return result.ok\n ? { ok: true, value: result.value }\n : { ok: false, error: result.error };\n}\n\n// =============================================================================\n// Partial error matching\n// =============================================================================\n\n/**\n * Non-exhaustive error match — handle the errors you care about; let the rest fall through to fallback.\n *\n * @example\n * ```typescript\n * const message = matchErrorPartial(\n * error,\n * { NOT_FOUND: () => 'Resource not found' },\n * (e) => `Unexpected: ${e}`\n * );\n * ```\n */\nexport function matchErrorPartial<E extends string, R>(\n error: E | UnexpectedError,\n handlers: Partial<MatchErrorHandlers<E, R>>,\n fallback: (error: E | UnexpectedError) => R\n): R {\n if (isUnexpectedError(error)) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const h = (handlers as any).UnexpectedError as ((e: UnexpectedError) => R) | undefined;\n return h ? h(error) : fallback(error);\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const h = (handlers as any)[error as string] as ((e: E) => R) | undefined;\n return h ? h(error as E) : fallback(error);\n}\n\n// Retry helper is intentionally NOT re-exported here.\n// Import from the dedicated subpath to keep awaitly/result minimal:\n// import { tryAsyncRetry } from 'awaitly/result/retry';\n"],"mappings":"AA6DA,IAAMA,EAAN,cAAsC,KAAiC,CAC5D,IACX,EAsGA,SAASC,EACPC,EACAC,EAEK,CACL,OAAO,cAAcH,CAAwB,CACzB,KAAYE,EAG9B,YAAYE,EAAaC,EAAmC,CAE1D,IAAMC,EAAUH,GAAS,QAAUA,EAAQ,QAAQC,GAAS,CAAC,CAAC,EAAIF,EAYlE,GAVA,MAAMI,CAAO,EACb,KAAK,KAAOJ,EAGZ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,GAAI,GAAM,MAAOA,EAAO,KAAM,EAChC,CAAE,GAAI,GAAO,MAAOA,EAAO,KAAM,CACvC,CAkBO,SAASoE,GACdjF,EACAW,EACAuE,EACG,CACH,GAAI5E,EAAkBN,CAAK,EAAG,CAE5B,IAAMmF,EAAKxE,EAAiB,gBAC5B,OAAOwE,EAAIA,EAAEnF,CAAK,EAAIkF,EAASlF,CAAK,CACtC,CAEA,IAAMmF,EAAKxE,EAAiBX,CAAe,EAC3C,OAAOmF,EAAIA,EAAEnF,CAAU,EAAIkF,EAASlF,CAAK,CAC3C","names":["InternalTaggedErrorBase","TaggedError","tag","options","props","errorOptions","message","_","_n","_m","_s","safeProps","hasUserCause","userCause","hasOptionsCause","instance","isError","value","isTaggedError","match","error","handlers","handler","matchPartial","otherwise","TimeoutError","TaggedError","p","RetryExhaustedError","RateLimitError","CircuitBreakerOpenError","ValidationError","NotFoundError","UnauthorizedError","NetworkError","CompensationError","UnexpectedError","PROMISE_REJECTED","AWAITLY_UNEXPECTED","AWAITLY_CANCELLED","AWAITLY_TIMEOUT","tags","t","ok","value","err","error","options","cause","isOk","r","isErr","isUnexpectedError","UnexpectedError","isPromiseRejectedError","PROMISE_REJECTED","matchError","handlers","UnwrapError","result","errorStr","unwrap","unwrapOr","defaultValue","unwrapOrElse","fn","runOrThrow","runOrThrowAsync","ar","runOrNull","runOrUndefined","from","onError","fromPromise","promise","tryAsync","fromNullable","onNull","map","mapError","match","andThen","tap","tapError","mapTry","mapErrorTry","bimap","onOk","onErr","orElse","orElseAsync","recover","recoverAsync","resolved","hydrate","obj","isSerializedResult","all","results","values","allAsync","resultOrPromise","reason","allSettled","errors","allSettledAsync","settled","item","partition","any","firstErr","anyAsync","resolve","pendingCount","firstError","zip","a","b","zipAsync","wrapRejection","p","ra","rb","flatten","DESERIALIZATION_ERROR","deserialize","serialize","matchErrorPartial","fallback","h"]}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { U as UnexpectedError } from './errors-entry-DOt5UUl4.js';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* awaitly/core
|
|
3
5
|
*
|
|
@@ -67,31 +69,6 @@ type Result<T, E = unknown, C = unknown> = Ok<T> | Err<E, C>;
|
|
|
67
69
|
* Use this for asynchronous operations that might fail.
|
|
68
70
|
*/
|
|
69
71
|
type AsyncResult<T, E = unknown, C = unknown> = Promise<Result<T, E, C>>;
|
|
70
|
-
/**
|
|
71
|
-
* Cause of a step failure: either a Result error or a thrown value.
|
|
72
|
-
* Used inside UnexpectedError when a step returns Err or throws.
|
|
73
|
-
*/
|
|
74
|
-
type UnexpectedStepFailureCause = {
|
|
75
|
-
type: "STEP_FAILURE";
|
|
76
|
-
origin: "result";
|
|
77
|
-
error: unknown;
|
|
78
|
-
cause?: unknown;
|
|
79
|
-
} | {
|
|
80
|
-
type: "STEP_FAILURE";
|
|
81
|
-
origin: "throw";
|
|
82
|
-
error: unknown;
|
|
83
|
-
thrown: unknown;
|
|
84
|
-
};
|
|
85
|
-
/**
|
|
86
|
-
* Union of causes for unexpected errors: uncaught exception or step failure.
|
|
87
|
-
* Used as the cause field of UnexpectedError.
|
|
88
|
-
*/
|
|
89
|
-
type UnexpectedCause = {
|
|
90
|
-
type: "UNCAUGHT_EXCEPTION";
|
|
91
|
-
thrown: unknown;
|
|
92
|
-
} | UnexpectedStepFailureCause;
|
|
93
|
-
/** Discriminant for UnexpectedError type - use in switch statements */
|
|
94
|
-
declare const UNEXPECTED_ERROR: "UNEXPECTED_ERROR";
|
|
95
72
|
/** Discriminant for PromiseRejectedError type - use in switch statements */
|
|
96
73
|
declare const PROMISE_REJECTED: "PROMISE_REJECTED";
|
|
97
74
|
/**
|
|
@@ -130,10 +107,7 @@ declare const AWAITLY_TIMEOUT: "AWAITLY_TIMEOUT";
|
|
|
130
107
|
* ```
|
|
131
108
|
*/
|
|
132
109
|
declare const tags: <const T extends readonly string[]>(...t: T) => T;
|
|
133
|
-
|
|
134
|
-
type: typeof UNEXPECTED_ERROR;
|
|
135
|
-
cause: UnexpectedCause;
|
|
136
|
-
};
|
|
110
|
+
|
|
137
111
|
type PromiseRejectedError = {
|
|
138
112
|
type: typeof PROMISE_REJECTED;
|
|
139
113
|
cause: unknown;
|
|
@@ -240,25 +214,22 @@ declare const isErr: <T, E, C>(r: Result<T, E, C>) => r is Err<E, C>;
|
|
|
240
214
|
*
|
|
241
215
|
* @remarks When to use: Distinguish unexpected failures from your typed error union.
|
|
242
216
|
*/
|
|
243
|
-
declare const isUnexpectedError: (e: unknown) => e is UnexpectedError
|
|
217
|
+
declare const isUnexpectedError: (e: unknown) => e is UnexpectedError;
|
|
244
218
|
/**
|
|
245
219
|
* Type for exhaustive error handlers mapping string literal errors and UnexpectedError.
|
|
246
|
-
* Each key in E gets a handler, plus
|
|
247
|
-
* Note: "UNEXPECTED_ERROR" is excluded from E to avoid intersection conflicts when users
|
|
248
|
-
* have that literal in their error union - the UNEXPECTED_ERROR handler always receives
|
|
249
|
-
* the UnexpectedError object type, not the string literal.
|
|
220
|
+
* Each key in E gets a handler, plus UnexpectedError is required.
|
|
250
221
|
*/
|
|
251
222
|
type MatchErrorHandlers<E extends string, R> = {
|
|
252
|
-
[K in Exclude<E, "
|
|
223
|
+
[K in Exclude<E, "UnexpectedError">]: (error: K) => R;
|
|
253
224
|
} & {
|
|
254
|
-
|
|
225
|
+
UnexpectedError: (error: UnexpectedError) => R;
|
|
255
226
|
};
|
|
256
227
|
/**
|
|
257
228
|
* Exhaustive pattern matching for error types.
|
|
258
229
|
* Handles both string literal errors and UnexpectedError, ensuring all cases are covered.
|
|
259
230
|
*
|
|
260
231
|
* @param error - The error to match (string literal or UnexpectedError)
|
|
261
|
-
* @param handlers - Object with a handler for each error case plus
|
|
232
|
+
* @param handlers - Object with a handler for each error case plus UnexpectedError
|
|
262
233
|
* @returns The result of the matched handler
|
|
263
234
|
*
|
|
264
235
|
* @example
|
|
@@ -270,7 +241,7 @@ type MatchErrorHandlers<E extends string, R> = {
|
|
|
270
241
|
* return matchError(result.error, {
|
|
271
242
|
* NOT_FOUND: () => 404,
|
|
272
243
|
* FETCH_ERROR: () => 500,
|
|
273
|
-
*
|
|
244
|
+
* UnexpectedError: (e) => { throw e.cause; }
|
|
274
245
|
* });
|
|
275
246
|
* }
|
|
276
247
|
* ```
|
|
@@ -2053,9 +2024,9 @@ declare function isEarlyExit<E>(e: unknown): e is EarlyExit<E>;
|
|
|
2053
2024
|
*
|
|
2054
2025
|
* `run()` returns:
|
|
2055
2026
|
* - **`catchUnexpected`**: Maps uncaught exceptions to your type E → `Result<T, E>`
|
|
2056
|
-
* - **No catchUnexpected**: Step errors pass through + `
|
|
2027
|
+
* - **No catchUnexpected**: Step errors pass through + `UnexpectedError` for exceptions → `Result<T, E | UnexpectedError>`
|
|
2057
2028
|
*
|
|
2058
|
-
* When `E` is not specified, it defaults to `never`, giving `Result<T,
|
|
2029
|
+
* When `E` is not specified, it defaults to `never`, giving `Result<T, UnexpectedError>`.
|
|
2059
2030
|
*
|
|
2060
2031
|
* @see createWorkflow - For static dependencies with auto error inference
|
|
2061
2032
|
*/
|
|
@@ -2067,21 +2038,21 @@ declare function run<T, E, C = void>(fn: (context: {
|
|
|
2067
2038
|
}) => Promise<T> | T, options: RunOptionsWithCatch<E, C>): AsyncResult<T, E, unknown>;
|
|
2068
2039
|
/**
|
|
2069
2040
|
* run() without catchUnexpected.
|
|
2070
|
-
* Always adds
|
|
2041
|
+
* Always adds UnexpectedError to the error union so callers know
|
|
2071
2042
|
* uncaught exceptions are possible. Step errors pass through as-is.
|
|
2072
2043
|
* When E is never (default), step is RunStep<unknown> so any operation is allowed.
|
|
2073
2044
|
*/
|
|
2074
2045
|
declare function run<T, E = never, C = void>(fn: (context: {
|
|
2075
2046
|
step: [E] extends [never] ? RunStep<unknown> : RunStep<E>;
|
|
2076
2047
|
}) => Promise<T> | T, options?: {
|
|
2077
|
-
onError?: (error: E |
|
|
2078
|
-
onEvent?: (event: WorkflowEvent<E |
|
|
2048
|
+
onError?: (error: E | UnexpectedError, stepName?: string, ctx?: C) => void;
|
|
2049
|
+
onEvent?: (event: WorkflowEvent<E | UnexpectedError, C>, ctx: C) => void;
|
|
2079
2050
|
workflowId?: string;
|
|
2080
2051
|
workflowName?: string;
|
|
2081
2052
|
context?: C;
|
|
2082
2053
|
/** @internal External signal for workflow-level cancellation. */
|
|
2083
2054
|
_workflowSignal?: AbortSignal;
|
|
2084
|
-
}): AsyncResult<T, E |
|
|
2055
|
+
}): AsyncResult<T, E | UnexpectedError, unknown>;
|
|
2085
2056
|
declare namespace run {
|
|
2086
2057
|
var strict: <T, E, C = void>(fn: (context: {
|
|
2087
2058
|
step: RunStep<E>;
|
|
@@ -3519,4 +3490,4 @@ type AllAsyncCauses<T extends readonly MaybeAsyncResult<unknown, unknown, unknow
|
|
|
3519
3490
|
*/
|
|
3520
3491
|
declare function allSettledAsync<const T extends readonly MaybeAsyncResult<unknown, unknown, unknown>[]>(results: T): Promise<Result<AllAsyncValues<T>, SettledError<AllAsyncErrors<T> | PromiseRejectedError, AllAsyncCauses<T> | PromiseRejectionCause>[]>>;
|
|
3521
3492
|
|
|
3522
|
-
export {
|
|
3493
|
+
export { partition as $, AWAITLY_CANCELLED as A, from as B, type CauseOf as C, fromNullable as D, type EmptyInputError as E, fromPromise as F, hydrate as G, isErr as H, isOk as I, isSerializedResult as J, isUnexpectedError as K, lookupErrorClassification as L, type MatchErrorHandlers as M, map as N, type Ok as O, PROMISE_REJECTED as P, mapError as Q, type Result as R, type SettledError as S, mapErrorTry as T, UnwrapError as U, mapTry as V, match as W, matchError as X, ok as Y, orElse as Z, orElseAsync as _, AWAITLY_TIMEOUT as a, recover as a0, recoverAsync as a1, runOrNull as a2, runOrThrow as a3, runOrThrowAsync as a4, runOrUndefined as a5, tags as a6, tap as a7, tapError as a8, tryAsync as a9, unwrap as aa, unwrapOr as ab, unwrapOrElse as ac, type WorkflowEvent as ad, type RunStep as ae, type RetryOptions as af, type StepOptions as ag, type BackoffStrategy as ah, type RunOptions as ai, type RunOptionsWithCatch as aj, type RunOptionsWithoutCatch as ak, STEP_TIMEOUT_MARKER as al, type ScopeType as am, type StepTimeoutError as an, type StepTimeoutMarkerMeta as ao, type TimeoutOptions as ap, getStepTimeoutMeta as aq, isStepTimeoutError as ar, run as as, type StepFailureMeta as at, EARLY_EXIT_SYMBOL as au, type EarlyExit as av, createEarlyExit as aw, isEarlyExit as ax, AWAITLY_UNEXPECTED as b, type AsyncResult as c, type Err as d, type ErrorClassification as e, type ErrorOf as f, type Errors as g, type ExtractCause as h, type ExtractError as i, type ExtractValue as j, type MaybeAsyncResult as k, type PromiseRejectedError as l, type PromiseRejectionCause as m, type StepErrorDiagnostics as n, type StepMetadata as o, all as p, allAsync as q, allSettled as r, allSettledAsync as s, andThen as t, any as u, anyAsync as v, bimap as w, err as x, extractErrorTag as y, extractStepMetadata as z };
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { U as UnexpectedError } from './errors-entry-CMH73Eym.cjs';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* awaitly/core
|
|
3
5
|
*
|
|
@@ -67,31 +69,6 @@ type Result<T, E = unknown, C = unknown> = Ok<T> | Err<E, C>;
|
|
|
67
69
|
* Use this for asynchronous operations that might fail.
|
|
68
70
|
*/
|
|
69
71
|
type AsyncResult<T, E = unknown, C = unknown> = Promise<Result<T, E, C>>;
|
|
70
|
-
/**
|
|
71
|
-
* Cause of a step failure: either a Result error or a thrown value.
|
|
72
|
-
* Used inside UnexpectedError when a step returns Err or throws.
|
|
73
|
-
*/
|
|
74
|
-
type UnexpectedStepFailureCause = {
|
|
75
|
-
type: "STEP_FAILURE";
|
|
76
|
-
origin: "result";
|
|
77
|
-
error: unknown;
|
|
78
|
-
cause?: unknown;
|
|
79
|
-
} | {
|
|
80
|
-
type: "STEP_FAILURE";
|
|
81
|
-
origin: "throw";
|
|
82
|
-
error: unknown;
|
|
83
|
-
thrown: unknown;
|
|
84
|
-
};
|
|
85
|
-
/**
|
|
86
|
-
* Union of causes for unexpected errors: uncaught exception or step failure.
|
|
87
|
-
* Used as the cause field of UnexpectedError.
|
|
88
|
-
*/
|
|
89
|
-
type UnexpectedCause = {
|
|
90
|
-
type: "UNCAUGHT_EXCEPTION";
|
|
91
|
-
thrown: unknown;
|
|
92
|
-
} | UnexpectedStepFailureCause;
|
|
93
|
-
/** Discriminant for UnexpectedError type - use in switch statements */
|
|
94
|
-
declare const UNEXPECTED_ERROR: "UNEXPECTED_ERROR";
|
|
95
72
|
/** Discriminant for PromiseRejectedError type - use in switch statements */
|
|
96
73
|
declare const PROMISE_REJECTED: "PROMISE_REJECTED";
|
|
97
74
|
/**
|
|
@@ -130,10 +107,7 @@ declare const AWAITLY_TIMEOUT: "AWAITLY_TIMEOUT";
|
|
|
130
107
|
* ```
|
|
131
108
|
*/
|
|
132
109
|
declare const tags: <const T extends readonly string[]>(...t: T) => T;
|
|
133
|
-
|
|
134
|
-
type: typeof UNEXPECTED_ERROR;
|
|
135
|
-
cause: UnexpectedCause;
|
|
136
|
-
};
|
|
110
|
+
|
|
137
111
|
type PromiseRejectedError = {
|
|
138
112
|
type: typeof PROMISE_REJECTED;
|
|
139
113
|
cause: unknown;
|
|
@@ -240,25 +214,22 @@ declare const isErr: <T, E, C>(r: Result<T, E, C>) => r is Err<E, C>;
|
|
|
240
214
|
*
|
|
241
215
|
* @remarks When to use: Distinguish unexpected failures from your typed error union.
|
|
242
216
|
*/
|
|
243
|
-
declare const isUnexpectedError: (e: unknown) => e is UnexpectedError
|
|
217
|
+
declare const isUnexpectedError: (e: unknown) => e is UnexpectedError;
|
|
244
218
|
/**
|
|
245
219
|
* Type for exhaustive error handlers mapping string literal errors and UnexpectedError.
|
|
246
|
-
* Each key in E gets a handler, plus
|
|
247
|
-
* Note: "UNEXPECTED_ERROR" is excluded from E to avoid intersection conflicts when users
|
|
248
|
-
* have that literal in their error union - the UNEXPECTED_ERROR handler always receives
|
|
249
|
-
* the UnexpectedError object type, not the string literal.
|
|
220
|
+
* Each key in E gets a handler, plus UnexpectedError is required.
|
|
250
221
|
*/
|
|
251
222
|
type MatchErrorHandlers<E extends string, R> = {
|
|
252
|
-
[K in Exclude<E, "
|
|
223
|
+
[K in Exclude<E, "UnexpectedError">]: (error: K) => R;
|
|
253
224
|
} & {
|
|
254
|
-
|
|
225
|
+
UnexpectedError: (error: UnexpectedError) => R;
|
|
255
226
|
};
|
|
256
227
|
/**
|
|
257
228
|
* Exhaustive pattern matching for error types.
|
|
258
229
|
* Handles both string literal errors and UnexpectedError, ensuring all cases are covered.
|
|
259
230
|
*
|
|
260
231
|
* @param error - The error to match (string literal or UnexpectedError)
|
|
261
|
-
* @param handlers - Object with a handler for each error case plus
|
|
232
|
+
* @param handlers - Object with a handler for each error case plus UnexpectedError
|
|
262
233
|
* @returns The result of the matched handler
|
|
263
234
|
*
|
|
264
235
|
* @example
|
|
@@ -270,7 +241,7 @@ type MatchErrorHandlers<E extends string, R> = {
|
|
|
270
241
|
* return matchError(result.error, {
|
|
271
242
|
* NOT_FOUND: () => 404,
|
|
272
243
|
* FETCH_ERROR: () => 500,
|
|
273
|
-
*
|
|
244
|
+
* UnexpectedError: (e) => { throw e.cause; }
|
|
274
245
|
* });
|
|
275
246
|
* }
|
|
276
247
|
* ```
|
|
@@ -2053,9 +2024,9 @@ declare function isEarlyExit<E>(e: unknown): e is EarlyExit<E>;
|
|
|
2053
2024
|
*
|
|
2054
2025
|
* `run()` returns:
|
|
2055
2026
|
* - **`catchUnexpected`**: Maps uncaught exceptions to your type E → `Result<T, E>`
|
|
2056
|
-
* - **No catchUnexpected**: Step errors pass through + `
|
|
2027
|
+
* - **No catchUnexpected**: Step errors pass through + `UnexpectedError` for exceptions → `Result<T, E | UnexpectedError>`
|
|
2057
2028
|
*
|
|
2058
|
-
* When `E` is not specified, it defaults to `never`, giving `Result<T,
|
|
2029
|
+
* When `E` is not specified, it defaults to `never`, giving `Result<T, UnexpectedError>`.
|
|
2059
2030
|
*
|
|
2060
2031
|
* @see createWorkflow - For static dependencies with auto error inference
|
|
2061
2032
|
*/
|
|
@@ -2067,21 +2038,21 @@ declare function run<T, E, C = void>(fn: (context: {
|
|
|
2067
2038
|
}) => Promise<T> | T, options: RunOptionsWithCatch<E, C>): AsyncResult<T, E, unknown>;
|
|
2068
2039
|
/**
|
|
2069
2040
|
* run() without catchUnexpected.
|
|
2070
|
-
* Always adds
|
|
2041
|
+
* Always adds UnexpectedError to the error union so callers know
|
|
2071
2042
|
* uncaught exceptions are possible. Step errors pass through as-is.
|
|
2072
2043
|
* When E is never (default), step is RunStep<unknown> so any operation is allowed.
|
|
2073
2044
|
*/
|
|
2074
2045
|
declare function run<T, E = never, C = void>(fn: (context: {
|
|
2075
2046
|
step: [E] extends [never] ? RunStep<unknown> : RunStep<E>;
|
|
2076
2047
|
}) => Promise<T> | T, options?: {
|
|
2077
|
-
onError?: (error: E |
|
|
2078
|
-
onEvent?: (event: WorkflowEvent<E |
|
|
2048
|
+
onError?: (error: E | UnexpectedError, stepName?: string, ctx?: C) => void;
|
|
2049
|
+
onEvent?: (event: WorkflowEvent<E | UnexpectedError, C>, ctx: C) => void;
|
|
2079
2050
|
workflowId?: string;
|
|
2080
2051
|
workflowName?: string;
|
|
2081
2052
|
context?: C;
|
|
2082
2053
|
/** @internal External signal for workflow-level cancellation. */
|
|
2083
2054
|
_workflowSignal?: AbortSignal;
|
|
2084
|
-
}): AsyncResult<T, E |
|
|
2055
|
+
}): AsyncResult<T, E | UnexpectedError, unknown>;
|
|
2085
2056
|
declare namespace run {
|
|
2086
2057
|
var strict: <T, E, C = void>(fn: (context: {
|
|
2087
2058
|
step: RunStep<E>;
|
|
@@ -3519,4 +3490,4 @@ type AllAsyncCauses<T extends readonly MaybeAsyncResult<unknown, unknown, unknow
|
|
|
3519
3490
|
*/
|
|
3520
3491
|
declare function allSettledAsync<const T extends readonly MaybeAsyncResult<unknown, unknown, unknown>[]>(results: T): Promise<Result<AllAsyncValues<T>, SettledError<AllAsyncErrors<T> | PromiseRejectedError, AllAsyncCauses<T> | PromiseRejectionCause>[]>>;
|
|
3521
3492
|
|
|
3522
|
-
export {
|
|
3493
|
+
export { partition as $, AWAITLY_CANCELLED as A, from as B, type CauseOf as C, fromNullable as D, type EmptyInputError as E, fromPromise as F, hydrate as G, isErr as H, isOk as I, isSerializedResult as J, isUnexpectedError as K, lookupErrorClassification as L, type MatchErrorHandlers as M, map as N, type Ok as O, PROMISE_REJECTED as P, mapError as Q, type Result as R, type SettledError as S, mapErrorTry as T, UnwrapError as U, mapTry as V, match as W, matchError as X, ok as Y, orElse as Z, orElseAsync as _, AWAITLY_TIMEOUT as a, recover as a0, recoverAsync as a1, runOrNull as a2, runOrThrow as a3, runOrThrowAsync as a4, runOrUndefined as a5, tags as a6, tap as a7, tapError as a8, tryAsync as a9, unwrap as aa, unwrapOr as ab, unwrapOrElse as ac, type WorkflowEvent as ad, type RunStep as ae, type RetryOptions as af, type StepOptions as ag, type BackoffStrategy as ah, type RunOptions as ai, type RunOptionsWithCatch as aj, type RunOptionsWithoutCatch as ak, STEP_TIMEOUT_MARKER as al, type ScopeType as am, type StepTimeoutError as an, type StepTimeoutMarkerMeta as ao, type TimeoutOptions as ap, getStepTimeoutMeta as aq, isStepTimeoutError as ar, run as as, type StepFailureMeta as at, EARLY_EXIT_SYMBOL as au, type EarlyExit as av, createEarlyExit as aw, isEarlyExit as ax, AWAITLY_UNEXPECTED as b, type AsyncResult as c, type Err as d, type ErrorClassification as e, type ErrorOf as f, type Errors as g, type ExtractCause as h, type ExtractError as i, type ExtractValue as j, type MaybeAsyncResult as k, type PromiseRejectedError as l, type PromiseRejectionCause as m, type StepErrorDiagnostics as n, type StepMetadata as o, all as p, allAsync as q, allSettled as r, allSettledAsync as s, andThen as t, any as u, anyAsync as v, bimap as w, err as x, extractErrorTag as y, extractStepMetadata as z };
|