@nicolastoulemont/std 0.8.1 → 0.9.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/README.md +63 -11
- package/dist/adt/index.d.mts +1 -1
- package/dist/adt/index.mjs +1 -1
- package/dist/adt-CY8wLJJI.mjs +2 -0
- package/dist/adt-CY8wLJJI.mjs.map +1 -0
- package/dist/data/index.d.mts +1 -1
- package/dist/data/index.mjs +1 -1
- package/dist/data-DqACNS_g.mjs +2 -0
- package/dist/data-DqACNS_g.mjs.map +1 -0
- package/dist/duration/index.d.mts +1 -1
- package/dist/duration/index.mjs +1 -1
- package/dist/{duration-CYoDHcOR.mjs → duration-Bas3mi1N.mjs} +2 -2
- package/dist/{duration-CYoDHcOR.mjs.map → duration-Bas3mi1N.mjs.map} +1 -1
- package/dist/fx/index.d.mts +1 -1
- package/dist/fx/index.mjs +1 -1
- package/dist/{fx-DUXDxwsU.mjs → fx-C_RTDEpv.mjs} +2 -2
- package/dist/{fx-DUXDxwsU.mjs.map → fx-C_RTDEpv.mjs.map} +1 -1
- package/dist/{index-MsJqfQu0.d.mts → index-BD-els5J.d.mts} +2 -2
- package/dist/{index-MsJqfQu0.d.mts.map → index-BD-els5J.d.mts.map} +1 -1
- package/dist/{index-DUki2Bcp.d.mts → index-BaRJVkLo.d.mts} +2 -2
- package/dist/{index-DUki2Bcp.d.mts.map → index-BaRJVkLo.d.mts.map} +1 -1
- package/dist/{index-B4WfexUL.d.mts → index-BipW0MC3.d.mts} +32 -25
- package/dist/index-BipW0MC3.d.mts.map +1 -0
- package/dist/index-BqJ1GWAF.d.mts.map +1 -1
- package/dist/{index-Ctqe1fD1.d.mts → index-CVmgBpDt.d.mts} +2 -2
- package/dist/{index-Ctqe1fD1.d.mts.map → index-CVmgBpDt.d.mts.map} +1 -1
- package/dist/{index-UINIHFuh.d.mts → index-D6pjHqlK.d.mts} +48 -2
- package/dist/index-D6pjHqlK.d.mts.map +1 -0
- package/dist/{index-crtzMG48.d.mts → index-D8gcYvR9.d.mts} +38 -3
- package/dist/index-D8gcYvR9.d.mts.map +1 -0
- package/dist/index-D8rDE60Y.d.mts.map +1 -1
- package/dist/{index-BsPOcZk9.d.mts → index-DfAqfnY0.d.mts} +2 -2
- package/dist/{index-BsPOcZk9.d.mts.map → index-DfAqfnY0.d.mts.map} +1 -1
- package/dist/index.d.mts +8 -8
- package/dist/index.mjs +1 -1
- package/dist/{equality-BX6BUidG.mjs → is-plain-object-BoFjRafL.mjs} +2 -2
- package/dist/is-plain-object-BoFjRafL.mjs.map +1 -0
- package/dist/layer/index.mjs +1 -1
- package/dist/{layer-CKtH7TRL.mjs → layer-C5A-EM0h.mjs} +2 -2
- package/dist/{layer-CKtH7TRL.mjs.map → layer-C5A-EM0h.mjs.map} +1 -1
- package/dist/provide/index.d.mts +1 -1
- package/dist/provide/index.mjs +1 -1
- package/dist/provide-CuccogWx.mjs +2 -0
- package/dist/provide-CuccogWx.mjs.map +1 -0
- package/dist/queue/index.d.mts +1 -1
- package/dist/queue/index.mjs +1 -1
- package/dist/{queue-apiEOlRD.mjs → queue-GYVrD39q.mjs} +2 -2
- package/dist/{queue-apiEOlRD.mjs.map → queue-GYVrD39q.mjs.map} +1 -1
- package/dist/schedule/index.d.mts +1 -1
- package/dist/schedule/index.mjs +1 -1
- package/dist/{schedule-C6iN3oMt.mjs → schedule-B7qV60tO.mjs} +2 -2
- package/dist/{schedule-C6iN3oMt.mjs.map → schedule-B7qV60tO.mjs.map} +1 -1
- package/dist/{schedule-B9K_2Z21.d.mts → schedule-BzPjvMXc.d.mts} +3 -3
- package/dist/{schedule-B9K_2Z21.d.mts.map → schedule-BzPjvMXc.d.mts.map} +1 -1
- package/dist/schema/index.d.mts +1 -1
- package/dist/schema/index.mjs +1 -1
- package/dist/schema-DstB1_VK.mjs +2 -0
- package/dist/schema-DstB1_VK.mjs.map +1 -0
- package/dist/{schema.types-CBEXCwfs.d.mts → schema.types-w1WK4kGS.d.mts} +7 -5
- package/dist/schema.types-w1WK4kGS.d.mts.map +1 -0
- package/package.json +1 -1
- package/dist/adt-CPG_sa8q.mjs +0 -2
- package/dist/adt-CPG_sa8q.mjs.map +0 -1
- package/dist/data-BHYPdqWZ.mjs +0 -2
- package/dist/data-BHYPdqWZ.mjs.map +0 -1
- package/dist/equality-BX6BUidG.mjs.map +0 -1
- package/dist/index-B4WfexUL.d.mts.map +0 -1
- package/dist/index-UINIHFuh.d.mts.map +0 -1
- package/dist/index-crtzMG48.d.mts.map +0 -1
- package/dist/provide--yZE8x-n.mjs +0 -2
- package/dist/provide--yZE8x-n.mjs.map +0 -1
- package/dist/schema-CJ-aaQe8.mjs +0 -2
- package/dist/schema-CJ-aaQe8.mjs.map +0 -1
- package/dist/schema.types-CBEXCwfs.d.mts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fx-DUXDxwsU.mjs","names":["gen","result","makeQueue","gen","result","resultOk","resultErr","resultTry","optionFromNullable"],"sources":["../src/fx/foreach.ts","../src/fx/fx.ts"],"sourcesContent":["import { NoSuchElementError } from \"../option/option.types\"\nimport { make as makeQueue, QueueAbortedError, QueueClosedError, QueueTaskAbortedError } from \"../queue/queue\"\nimport type { Concurrency } from \"../queue/queue.types\"\nimport { asServiceRequest } from \"../service/service-resolution\"\nimport { dual } from \"../shared/dual\"\nimport { FxTypeId } from \"./fx.types\"\nimport type { AsyncFx, FxError, FxRequirements, FxValue, FxYield, RunnableFx } from \"./fx.types\"\n\n/* oxlint-disable no-await-in-loop -- Fx.forEach coordinates child iterators and queue scheduling sequentially at specific yield points. */\n\ntype ForEachValue<Discard extends boolean, B> = Discard extends true ? void : Array<B>\n\ntype FxForEachOptions<Discard extends boolean = false> = {\n readonly concurrency?: Concurrency\n readonly discard?: Discard\n}\n\ntype ForEachFx<\n F extends (a: never, i: number) => RunnableFx<unknown, unknown, unknown>,\n Discard extends boolean,\n> = AsyncFx<ForEachValue<Discard, FxValue<ReturnType<F>>>, FxError<ReturnType<F>>, FxRequirements<ReturnType<F>>>\n\ntype FxForEach = {\n <A, F extends (a: A, i: number) => RunnableFx<unknown, unknown, unknown>, const Discard extends boolean = false>(\n self: Iterable<A>,\n f: F,\n options?: FxForEachOptions<Discard>,\n ): ForEachFx<F, Discard>\n <A, F extends (a: A, i: number) => RunnableFx<unknown, unknown, unknown>, const Discard extends boolean = false>(\n f: F,\n options?: FxForEachOptions<Discard>,\n ): (self: Iterable<A>) => ForEachFx<F, Discard>\n}\n\ntype ServiceRequestEntry<E, R> = {\n readonly yielded: FxYield<E, R>\n readonly signal: AbortSignal\n readonly resolve: (value: unknown) => void\n readonly reject: (reason: Error) => void\n}\n\ntype ResultErrShape = {\n readonly _tag: \"Err\"\n readonly error: unknown\n}\n\nclass TypedFailure<E> extends Error {\n readonly _tag = \"TypedFailure\"\n\n constructor(readonly error: E) {\n super(\"TypedFailure\")\n this.name = \"TypedFailure\"\n }\n}\n\nconst isTypedFailure = <E>(value: unknown): value is TypedFailure<E> => value instanceof TypedFailure\n\nconst isResultErr = (value: unknown): value is ResultErrShape =>\n typeof value === \"object\" && value !== null && \"_tag\" in value && value._tag === \"Err\" && \"error\" in value\n\nconst toFailureValue = (yielded: unknown): unknown => {\n if (yielded instanceof NoSuchElementError) {\n return yielded\n }\n\n if (isResultErr(yielded)) {\n return yielded.error\n }\n\n return yielded\n}\n\nconst isIterable = (value: unknown): value is Iterable<unknown> =>\n value !== null &&\n value !== undefined &&\n typeof (value as { [Symbol.iterator]?: unknown })[Symbol.iterator] === \"function\"\n\nconst queueTaskAbortedError = (signal: AbortSignal): QueueTaskAbortedError =>\n new QueueTaskAbortedError({ reason: signal.reason })\n\nconst toError = (reason: unknown): Error =>\n reason instanceof Error ? reason : new Error(\"Fx.forEach defect was not an Error\", { cause: reason })\n\nconst unreachableType = (): never => {\n throw new Error(\"Unreachable: Fx type marker should never execute at runtime\")\n}\n\nconst typeMarker = <A>(): (() => A) => unreachableType\n\nconst runMappedFx = async <B, E, R>(\n fx: RunnableFx<B, E, R>,\n signal: AbortSignal,\n requestService: (yielded: FxYield<E, R>, signal: AbortSignal) => Promise<unknown>,\n): Promise<B> => {\n if (fx._tag === \"AsyncFx\") {\n const gen = fx[Symbol.asyncIterator]()\n let result = await gen.next()\n\n while (result.done !== true) {\n if (signal.aborted) {\n throw queueTaskAbortedError(signal)\n }\n\n const yielded = result.value\n const serviceRequest = asServiceRequest(yielded)\n if (serviceRequest !== undefined) {\n const injected = await requestService(yielded, signal)\n result = await gen.next(injected)\n continue\n }\n\n // oxlint-disable-next-line typescript-eslint/no-unsafe-type-assertion -- failure channel values come from generic E at runtime.\n throw new TypedFailure<E>(toFailureValue(yielded) as E)\n }\n\n return result.value\n }\n\n const gen = fx[Symbol.iterator]()\n let result = gen.next()\n\n while (result.done !== true) {\n if (signal.aborted) {\n throw queueTaskAbortedError(signal)\n }\n\n const yielded = result.value\n const serviceRequest = asServiceRequest(yielded)\n if (serviceRequest !== undefined) {\n const injected = await requestService(yielded, signal)\n result = gen.next(injected)\n continue\n }\n\n // oxlint-disable-next-line typescript-eslint/no-unsafe-type-assertion -- failure channel values come from generic E at runtime.\n throw new TypedFailure<E>(toFailureValue(yielded) as E)\n }\n\n return result.value\n}\n\nconst fxForEach = dual(\n (args) => isIterable(args[0]) && typeof args[1] === \"function\",\n <A, B, E, R>(\n self: Iterable<A>,\n f: (a: A, i: number) => RunnableFx<B, E, R>,\n options?: FxForEachOptions<boolean>,\n ): AsyncFx<Array<B> | void, E, R> => {\n const items = [...self]\n const discard = options?.discard === true\n\n const program: AsyncFx<Array<B> | void, E, R> = {\n _tag: \"AsyncFx\",\n [FxTypeId]: {\n _A: typeMarker<Array<B> | void>(),\n _E: typeMarker<E>(),\n _R: typeMarker<R>(),\n },\n async *[Symbol.asyncIterator](): AsyncGenerator<FxYield<E, R>, Array<B> | void, unknown> {\n if (items.length === 0) {\n return discard ? undefined : []\n }\n\n const queue = makeQueue({ concurrency: options?.concurrency ?? \"unbounded\" })\n const results: Array<B> | undefined = discard ? undefined : []\n\n let remaining = items.length\n let firstFailure: E | undefined\n let firstDefect: Error | undefined\n let queueAborted = false\n\n const serviceRequests: ServiceRequestEntry<E, R>[] = []\n const eventWaiters = new Set<() => void>()\n\n const notifyEvent = () => {\n for (const resolve of eventWaiters) {\n resolve()\n }\n eventWaiters.clear()\n }\n\n const waitForEvent = () =>\n new Promise<void>((resolve) => {\n eventWaiters.add(resolve)\n })\n\n const requestService = (yielded: FxYield<E, R>, signal: AbortSignal): Promise<unknown> => {\n if (signal.aborted) {\n return Promise.reject(queueTaskAbortedError(signal))\n }\n\n return new Promise<unknown>((resolve, reject) => {\n const entry: ServiceRequestEntry<E, R> = {\n yielded,\n signal,\n resolve: (value) => {\n signal.removeEventListener(\"abort\", onAbort)\n resolve(value)\n },\n reject: (reason) => {\n signal.removeEventListener(\"abort\", onAbort)\n reject(reason)\n },\n }\n\n const onAbort = () => {\n const index = serviceRequests.indexOf(entry)\n if (index !== -1) {\n serviceRequests.splice(index, 1)\n }\n reject(queueTaskAbortedError(signal))\n }\n\n signal.addEventListener(\"abort\", onAbort, { once: true })\n serviceRequests.push(entry)\n notifyEvent()\n })\n }\n\n const rejectPendingServiceRequests = (reason: Error) => {\n const pending = serviceRequests.splice(0)\n for (const request of pending) {\n request.reject(reason)\n }\n }\n\n const abortQueue = (reason: unknown) => {\n if (queueAborted) {\n return\n }\n\n queueAborted = true\n void queue.shutdown({ mode: \"abort\", reason }).catch(() => {\n // no-op: fail-fast cleanup should never interrupt parent error handling\n })\n }\n\n const onTaskFailure = (error: unknown) => {\n if (isTypedFailure<E>(error)) {\n if (firstFailure === undefined && firstDefect === undefined) {\n firstFailure = error.error\n abortQueue(error.error)\n }\n return\n }\n\n if (\n (error instanceof QueueAbortedError ||\n error instanceof QueueTaskAbortedError ||\n error instanceof QueueClosedError) &&\n (firstFailure !== undefined || firstDefect !== undefined)\n ) {\n return\n }\n\n if (firstDefect === undefined && firstFailure === undefined) {\n const defect = toError(error)\n firstDefect = defect\n abortQueue(defect)\n }\n }\n\n const onTaskSettled = () => {\n remaining -= 1\n notifyEvent()\n }\n\n for (const [index, item] of items.entries()) {\n void queue\n .enqueue(async ({ signal }) => {\n const value = await runMappedFx(f(item, index), signal, requestService)\n if (results !== undefined) {\n results[index] = value\n }\n })\n .catch(onTaskFailure)\n .finally(onTaskSettled)\n }\n\n while (true) {\n if (firstDefect !== undefined) {\n rejectPendingServiceRequests(firstDefect)\n throw new Error(\"Fx.forEach defect\", { cause: firstDefect })\n }\n\n if (firstFailure !== undefined) {\n rejectPendingServiceRequests(new QueueAbortedError({ reason: firstFailure }))\n yield firstFailure\n throw new Error(\"Unreachable: Fx runtime short-circuits on first failure\")\n }\n\n const request = serviceRequests.shift()\n if (request !== undefined) {\n if (request.signal.aborted) {\n request.reject(queueTaskAbortedError(request.signal))\n continue\n }\n\n try {\n const injected = yield request.yielded\n request.resolve(injected)\n } catch (error) {\n request.reject(toError(error))\n }\n continue\n }\n\n if (remaining === 0) {\n break\n }\n\n await waitForEvent()\n }\n\n return discard ? undefined : results\n },\n }\n\n return program\n },\n) as FxForEach\n\nexport { fxForEach as forEach }\n\n/* oxlint-enable no-await-in-loop */\n","/**\n * Lightweight effect runtime with typed success, error, and requirement channels.\n *\n * **Mental model**\n * - `Fx<A, E, R>` models computations that may fail and require services.\n * - Build with `Fx.gen`, run with `Fx.run`, and compose with `Layer`/`Provide`.\n *\n * **Common tasks**\n * - Create workflows with `Fx.gen`.\n * - Execute with `Fx.run` or `Fx.fn`.\n * - Retry with `Fx.retry` and match outcomes with `Fx.match`.\n *\n * **Gotchas**\n * - Dependencies (`R`) must be provided before execution.\n * - `Fx.run` returns `Exit`, not raw values.\n *\n * **Quickstart**\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const program = Fx.gen(function* () {\n * const value = yield* Fx.ok(2)\n * return value + 1\n * })\n * const exit = Fx.run(program)\n * // => { _tag: \"Ok\", value: 3 }\n * ```\n *\n * @module\n */\nimport { fromNullable as optionFromNullable } from \"../option/option\"\nimport { ok as resultOk, err as resultErr, fromTry as resultTry } from \"../result/result\"\nimport type { RetrySchedule, SyncRetrySchedule } from \"../schedule/schedule\"\nimport { asServiceRequest } from \"../service/service-resolution\"\nimport { dual } from \"../shared/dual\"\nimport type { Exit as ExitType } from \"./exit\"\nimport { forEach as fxForEach } from \"./foreach\"\nimport { runSync, runAsync } from \"./fx.runtime\"\nimport { FxTypeId } from \"./fx.types\"\nimport type { RunnableFx, SyncFx, AsyncFx, FxYield, Fx as FxProtocol, FxGenerator, AsyncFxGenerator } from \"./fx.types\"\nexport {\n /**\n * `Exit` utilities namespace for `Fx.run` outcomes.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const exit = Fx.Exit.ok(1)\n * // => { _tag: \"Ok\", value: 1 }\n * ```\n *\n */\n Exit,\n} from \"./exit\"\nexport {\n /**\n * Type guard for Fx service requests.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const request = { _tag: \"ServiceRequest\", serviceKey: \"Logger\" } as Fx.ServiceRequest<unknown>\n * const isRequest = Fx.isServiceRequest(request)\n * // => true\n * ```\n *\n */\n isServiceRequest,\n} from \"./fx.types\"\nexport {\n /**\n * Runtime unique symbol identifying Fx values.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const marker = { [Fx.FxTypeId]: true }\n * // => Object.getOwnPropertySymbols(marker).includes(Fx.FxTypeId)\n * ```\n *\n */\n FxTypeId,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported core Fx protocol type.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.Fx<unknown, unknown, unknown>\n * ```\n *\n */\n type Fx,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported synchronous Fx type.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.SyncFx<unknown, unknown, unknown>\n * ```\n *\n */\n type SyncFx,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported asynchronous Fx type.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.AsyncFx<unknown, unknown, unknown>\n * ```\n *\n */\n type AsyncFx,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported runnable Fx union type.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.RunnableFx<unknown, unknown, unknown>\n * ```\n *\n */\n type RunnableFx,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported service-request protocol type.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.ServiceRequest<unknown>\n * ```\n *\n */\n type ServiceRequest,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported helper extracting Fx success type.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.FxValue<Fx.SyncFx<number>>\n * ```\n *\n */\n type FxValue,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported helper extracting Fx error type.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.FxError<Fx.SyncFx<number, string>>\n * ```\n *\n */\n type FxError,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported helper extracting Fx requirements type.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.FxRequirements<Fx.SyncFx<number, never, { readonly svc: unknown }>>\n * ```\n *\n */\n type FxRequirements,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported generator yield union for Fx internals.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.FxYield<unknown, unknown>\n * ```\n *\n */\n type FxYield,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported sync generator signature used by `Fx.gen`.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.FxGenerator<unknown, unknown, unknown>\n * ```\n *\n */\n type FxGenerator,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported async generator signature used by `Fx.gen`.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.AsyncFxGenerator<unknown, unknown, unknown>\n * ```\n *\n */\n type AsyncFxGenerator,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported sync Fx yieldable protocol type.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.FxYieldable<unknown, unknown, unknown>\n * ```\n *\n */\n type FxYieldable,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported async Fx yieldable protocol type.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.AsyncFxYieldable<unknown, unknown, unknown>\n * ```\n *\n */\n type AsyncFxYieldable,\n} from \"./fx.types\"\n\n/* oxlint-disable no-unsafe-type-assertion, no-unsafe-assignment, no-unsafe-call, no-unsafe-member-access, no-unsafe-return, no-unsafe-argument, no-unnecessary-type-assertion -- Fx runtime adapters intentionally traverse erased generator channels and rehydrate typed effects through controlled dynamic boundaries. */\n\n// ============================================================================\n// Fx.run - Execute computations\n// ============================================================================\n\n/**\n * Execute a sync Fx computation and return the Exit.\n * Catches unexpected thrown exceptions and wraps them as Defect.\n * Only available when R = never (all dependencies provided).\n *\n * @param fx - The sync computation to execute\n * @returns Exit<A, E>\n */\nfunction fxRun<A, E>(fx: SyncFx<A, E>): ExitType<A, E>\n\n/**\n * Execute an async Fx computation and return a Promise of the Exit.\n * Catches unexpected thrown exceptions and wraps them as Defect.\n * Only available when R = never (all dependencies provided).\n *\n * @param fx - The async computation to execute\n * @returns Promise<Exit<A, E>>\n */\nfunction fxRun<A, E>(fx: AsyncFx<A, E>): Promise<ExitType<A, E>>\n\n/**\n * Execute an Fx computation (union type).\n * Returns Exit for sync, Promise<Exit> for async.\n * Catches unexpected thrown exceptions and wraps them as Defect.\n */\nfunction fxRun<A, E>(fx: RunnableFx<A, E>): ExitType<A, E> | Promise<ExitType<A, E>>\n\n/**\n * Implementation of Fx.run.\n * Detects sync vs async and executes appropriately.\n */\nfunction fxRun<A, E>(fx: RunnableFx<A, E>): ExitType<A, E> | Promise<ExitType<A, E>> {\n if (fx._tag === \"AsyncFx\") {\n return runAsync(fx)\n }\n return runSync(fx)\n}\n\n// ============================================================================\n// Fx.retry - Retry failed computations\n// ============================================================================\n\nconst sleep = (ms: number): Promise<void> =>\n new Promise((resolve) => {\n setTimeout(resolve, ms)\n })\n\nconst sleepIfNeeded = async (ms: number): Promise<void> => {\n if (ms <= 0) {\n return\n }\n await sleep(ms)\n}\n\nconst closeSyncAttempt = (gen: Generator<unknown, unknown, unknown>) => {\n if (typeof gen.return === \"function\") {\n gen.return(undefined)\n }\n}\n\nconst closeAsyncAttempt = async (\n gen: Generator<unknown, unknown, unknown> | AsyncGenerator<unknown, unknown, unknown>,\n) => {\n if (typeof gen.return === \"function\") {\n await gen.return(undefined)\n }\n}\n\nconst makeSyncRetryFx = <A, E, R>(fx: SyncFx<A, E, R>, schedule: SyncRetrySchedule): SyncFx<A, E, R> => ({\n _tag: \"SyncFx\",\n [FxTypeId]: {\n _A: () => undefined as unknown as A,\n _E: () => undefined as unknown as E,\n _R: () => undefined as unknown as R,\n },\n *[Symbol.iterator](): Generator<FxYield<E, R>, A, unknown> {\n let retryAttempt = 0\n attemptLoop: while (true) {\n const gen = fx[Symbol.iterator]()\n let result = gen.next()\n\n while (result.done !== true) {\n const yielded = result.value\n const serviceRequest = asServiceRequest(yielded)\n if (serviceRequest !== undefined) {\n const injected = yield yielded as FxYield<E, R>\n result = gen.next(injected)\n continue\n }\n\n retryAttempt += 1\n if (retryAttempt <= schedule.maxRetries) {\n closeSyncAttempt(gen)\n continue attemptLoop\n }\n\n // Forward the terminal typed failure to the outer runtime.\n yield yielded as FxYield<E, R>\n return undefined as never\n }\n\n return result.value\n }\n },\n})\n\n/* oxlint-disable no-await-in-loop -- retry execution is intentionally sequential across attempts and iterator steps. */\nconst makeAsyncRetryFx = <A, E, R>(fx: RunnableFx<A, E, R>, schedule: RetrySchedule): AsyncFx<A, E, R> => ({\n _tag: \"AsyncFx\",\n [FxTypeId]: {\n _A: () => undefined as unknown as A,\n _E: () => undefined as unknown as E,\n _R: () => undefined as unknown as R,\n },\n async *[Symbol.asyncIterator](): AsyncGenerator<FxYield<E, R>, A, unknown> {\n let retryAttempt = 0\n\n attemptLoop: while (true) {\n if (fx._tag === \"AsyncFx\") {\n const gen = fx[Symbol.asyncIterator]()\n // Sequential async iterator protocol: each step depends on the previous one.\n let result = await gen.next()\n\n while (result.done !== true) {\n const yielded = result.value\n const serviceRequest = asServiceRequest(yielded)\n if (serviceRequest !== undefined) {\n const injected = yield yielded as FxYield<E, R>\n // oxlint-disable-next-line no-await-in-loop\n result = await gen.next(injected)\n continue\n }\n\n retryAttempt += 1\n if (retryAttempt <= schedule.maxRetries) {\n const delayMs = schedule.delayForAttempt(retryAttempt)\n await sleepIfNeeded(delayMs)\n await closeAsyncAttempt(gen)\n continue attemptLoop\n }\n\n // Forward the terminal typed failure to the outer runtime.\n yield yielded as FxYield<E, R>\n return undefined as never\n }\n\n return result.value\n }\n\n const gen = fx[Symbol.iterator]()\n let result = gen.next()\n\n while (result.done !== true) {\n const yielded = result.value\n const serviceRequest = asServiceRequest(yielded)\n if (serviceRequest !== undefined) {\n const injected = yield yielded as FxYield<E, R>\n result = gen.next(injected)\n continue\n }\n\n retryAttempt += 1\n if (retryAttempt <= schedule.maxRetries) {\n const delayMs = schedule.delayForAttempt(retryAttempt)\n await sleepIfNeeded(delayMs)\n await closeAsyncAttempt(gen)\n continue attemptLoop\n }\n\n // Forward the terminal typed failure to the outer runtime.\n yield yielded as FxYield<E, R>\n return undefined as never\n }\n\n return result.value\n }\n },\n})\n/* oxlint-enable no-await-in-loop */\n\n/**\n * Retry a computation according to the given schedule.\n *\n * Retries only typed failures (Err channel). Defects are not retried.\n */\ntype RetryResult<Fx extends RunnableFx<unknown, unknown, unknown>, S extends RetrySchedule> =\n Fx extends AsyncFx<infer A, infer E, infer R>\n ? AsyncFx<A, E, R>\n : S extends SyncRetrySchedule\n ? Fx extends SyncFx<infer A, infer E, infer R>\n ? SyncFx<A, E, R>\n : never\n : Fx extends SyncFx<infer A, infer E, infer R>\n ? AsyncFx<A, E, R>\n : never\n\nconst fxRetry: {\n <Fx extends RunnableFx<unknown, unknown, unknown>, S extends RetrySchedule>(fx: Fx, schedule: S): RetryResult<Fx, S>\n <S extends RetrySchedule>(\n schedule: S,\n ): <Fx extends RunnableFx<unknown, unknown, unknown>>(fx: Fx) => RetryResult<Fx, S>\n} = dual(\n 2,\n <Fx extends RunnableFx<unknown, unknown, unknown>, S extends RetrySchedule>(\n fx: Fx,\n schedule: S,\n ): RetryResult<Fx, S> => {\n if (fx._tag === \"AsyncFx\" || !schedule._sync) {\n return makeAsyncRetryFx(fx, schedule) as RetryResult<Fx, S>\n }\n return makeSyncRetryFx(fx as SyncFx<unknown, unknown, unknown>, schedule as SyncRetrySchedule) as RetryResult<Fx, S>\n },\n)\n\n// ============================================================================\n// Fx.gen - Create composable computations\n// ============================================================================\n\ntype FxGenError<Yielded> = Yielded extends FxProtocol<unknown, infer E, unknown> ? E : Yielded\ntype FxGenRequirements<Yielded> = Yielded extends FxProtocol<unknown, unknown, infer R> ? R : never\n\n/**\n * Create a composable computation from a sync generator function.\n * Returns a SyncFx that can be stored, passed around, and executed later.\n *\n * @template Yielded - The type of values yielded by the generator\n * @template A - The success value type\n * @param generatorFn - A function that returns a sync generator\n * @returns SyncFx<A, FxGenError<Yielded>, FxGenRequirements<Yielded>>\n *\n * @example\n * ```ts\n * import { Fx, Provide, Service } from \"@nicolastoulemont/std\"\n *\n * const Port = Service.tag<number>(\"Port\")\n * const readPort = Fx.gen(function* () {\n * return yield* Port\n * })\n * const exit = Fx.run(Provide.service(Port, 3000)(readPort))\n * // => { _tag: \"Ok\", value: 3000 }\n * ```\n */\nfunction fxGen<Yielded, A>(\n generatorFn: () => Generator<Yielded, A, unknown>,\n): SyncFx<A, FxGenError<Yielded>, FxGenRequirements<Yielded>>\n\n/**\n * Create a composable computation from an async generator function.\n * Returns an AsyncFx that can be stored, passed around, and executed later.\n *\n * @template Yielded - The type of values yielded by the generator\n * @template A - The success value type\n * @param generatorFn - A function that returns an async generator\n * @returns AsyncFx<A, FxGenError<Yielded>, FxGenRequirements<Yielded>>\n *\n * @example\n * ```ts\n * import { Fx, Provide, Service } from \"@nicolastoulemont/std\"\n *\n * const Token = Service.tag<string>(\"Token\")\n * const readToken = Fx.gen(async function* () {\n * const token = yield* Token\n * const suffix = await Promise.resolve(\"-ok\")\n * return `${token}${suffix}`\n * })\n * const exit = await Fx.run(Provide.service(Token, \"abc\")(readToken))\n * // => { _tag: \"Ok\", value: \"abc-ok\" }\n * ```\n */\nfunction fxGen<Yielded, A>(\n generatorFn: () => AsyncGenerator<Yielded, A, unknown>,\n): AsyncFx<A, FxGenError<Yielded>, FxGenRequirements<Yielded>>\n\n/**\n * Create a composable computation from a sync generator function that takes parameters.\n * Returns a factory function that, when called with parameters, produces a SyncFx.\n *\n * @template P - The parameter types (must be non-empty)\n * @template Yielded - The type of values yielded by the generator\n * @template A - The success value type\n * @param generatorFn - A function that takes parameters and returns a sync generator\n * @returns A factory function that produces SyncFx<A, FxGenError<Yielded>, FxGenRequirements<Yielded>>\n *\n * @example\n * ```ts\n * import { Fx, Provide, Service } from \"@nicolastoulemont/std\"\n *\n * const Port = Service.tag<number>(\"Port\")\n * const describePort = Fx.gen(function* (label: string) {\n * const port = yield* Port\n * return `${label}:${port}`\n * })\n * const exit = Fx.run(Provide.service(Port, 3000)(describePort(\"port\")))\n * // => { _tag: \"Ok\", value: \"port:3000\" }\n * ```\n */\nfunction fxGen<P extends [unknown, ...unknown[]], Yielded, A>(\n generatorFn: (...params: P) => Generator<Yielded, A, unknown>,\n): (...params: P) => SyncFx<A, FxGenError<Yielded>, FxGenRequirements<Yielded>>\n\n/**\n * Create a composable computation from an async generator function that takes parameters.\n * Returns a factory function that, when called with parameters, produces an AsyncFx.\n *\n * @template P - The parameter types (must be non-empty)\n * @template Yielded - The type of values yielded by the generator\n * @template A - The success value type\n * @param generatorFn - A function that takes parameters and returns an async generator\n * @returns A factory function that produces AsyncFx<A, FxGenError<Yielded>, FxGenRequirements<Yielded>>\n *\n * @example\n * ```ts\n * import { Fx, Provide, Service } from \"@nicolastoulemont/std\"\n *\n * const Token = Service.tag<string>(\"Token\")\n * const describeToken = Fx.gen(async function* (prefix: string) {\n * const token = yield* Token\n * const suffix = await Promise.resolve(\"!\")\n * return `${prefix}:${token}${suffix}`\n * })\n * const exit = await Fx.run(Provide.service(Token, \"abc\")(describeToken(\"token\")))\n * // => { _tag: \"Ok\", value: \"token:abc!\" }\n * ```\n */\nfunction fxGen<P extends [unknown, ...unknown[]], Yielded, A>(\n generatorFn: (...params: P) => AsyncGenerator<Yielded, A, unknown>,\n): (...params: P) => AsyncFx<A, FxGenError<Yielded>, FxGenRequirements<Yielded>>\n\n/**\n * Implementation of unified Fx.gen function.\n * Detects sync vs async generator and returns appropriate computation type.\n * For parameterized generators (length > 0), returns a factory function.\n */\n// oxlint-disable-next-line no-explicit-any\nfunction fxGen(generatorFn: (...args: any[]) => any): any {\n if (generatorFn.length > 0) {\n return (...params: unknown[]) => fxGen(() => generatorFn(...params))\n }\n\n // Check if we're dealing with async generator\n const testGen = generatorFn()\n const isAsync = Symbol.asyncIterator in testGen\n\n if (isAsync) {\n return {\n _tag: \"AsyncFx\",\n [FxTypeId]: {\n _A: () => undefined,\n _E: () => undefined,\n _R: () => undefined,\n },\n // oxlint-disable-next-line no-explicit-any\n async *[Symbol.asyncIterator](): AsyncGenerator<any, any, unknown> {\n const gen = generatorFn()\n let result = await gen.next()\n\n while (result.done !== true) {\n // Pass through yields (errors or services as Fx values)\n const injected = yield result.value\n // oxlint-disable-next-line no-await-in-loop\n result = await gen.next(injected)\n }\n\n return result.value\n },\n }\n }\n\n // Sync generator\n return {\n _tag: \"SyncFx\",\n [FxTypeId]: {\n _A: () => undefined,\n _E: () => undefined,\n _R: () => undefined,\n },\n // oxlint-disable-next-line no-explicit-any\n *[Symbol.iterator](): Generator<any, any, unknown> {\n const gen = generatorFn()\n let result = gen.next()\n\n while (result.done !== true) {\n const injected = yield result.value\n result = gen.next(injected)\n }\n\n return result.value\n },\n }\n}\n\n// ============================================================================\n// Fx.fn - Execute computations immediately\n// ============================================================================\n\ntype FxRunResult<F extends RunnableFx<unknown, unknown, unknown>> =\n F extends AsyncFx<infer A, infer E, unknown>\n ? Promise<ExitType<A, E>>\n : F extends SyncFx<infer A, infer E, unknown>\n ? ExitType<A, E>\n : never\n\n/**\n * Execute a sync computation immediately and return the Exit.\n * Catches unexpected thrown exceptions and wraps them as Defect.\n * For computations without service dependencies.\n *\n * @template A - The success value type\n * @template E - The error type\n * @param generatorFn - A function that returns a sync generator\n * @returns Exit<A, E>\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const exit = Fx.fn(function* () {\n * const a = yield* Fx.ok(10)\n * const b = yield* Fx.ok(20)\n * return a + b\n * })\n * // => { _tag: \"Ok\", value: 30 }\n * ```\n */\nfunction fxFn<A, E>(generatorFn: () => FxGenerator<A, E, never>): ExitType<A, E>\n\n/**\n * Execute an async computation immediately and return a Promise of the Exit.\n * Catches unexpected thrown exceptions and wraps them as Defect.\n * For computations without service dependencies.\n *\n * @template A - The success value type\n * @template E - The error type\n * @param generatorFn - A function that returns an async generator\n * @returns Promise<Exit<A, E>>\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const exit = await Fx.fn(async function* () {\n * const value = await Promise.resolve(2)\n * return value + 1\n * })\n * // => { _tag: \"Ok\", value: 3 }\n * ```\n */\nfunction fxFn<A, E>(generatorFn: () => AsyncFxGenerator<A, E, never>): Promise<ExitType<A, E>>\n\n/**\n * Execute a sync computation with service dependencies immediately.\n * Catches unexpected thrown exceptions and wraps them as Defect.\n * The second argument is required when the computation has service requirements (R ≠ never).\n *\n * @template A - The success value type\n * @template E - The error type from the computation\n * @template R - The required services type\n * @param generatorFn - A function that returns a sync generator with service requirements\n * @param provider - A function that provides the services (e.g., Provide.layer(AppLayer))\n * @returns Exit result from running the provided Fx (sync or async depending on provider output)\n *\n * @example\n * ```ts\n * import { Fx, Provide, Service } from \"@nicolastoulemont/std\"\n *\n * const Port = Service.tag<number>(\"Port\")\n *\n * const exit = Fx.fn(function* () {\n * const port = yield* Port\n * return port + 1\n * }, Provide.service(Port, 3000))\n * // => { _tag: \"Ok\", value: 3001 }\n * ```\n */\nfunction fxFn<A, E, R, ProvidedFx extends RunnableFx<unknown, unknown, unknown>>(\n generatorFn: () => FxGenerator<A, E, R>,\n provider: (fx: SyncFx<A, E, R>) => ProvidedFx,\n): FxRunResult<ProvidedFx>\n\n/**\n * Execute an async computation with service dependencies immediately.\n * Catches unexpected thrown exceptions and wraps them as Defect.\n * The second argument is required when the computation has service requirements (R ≠ never).\n *\n * @template A - The success value type\n * @template E - The error type from the computation\n * @template R - The required services type\n * @param generatorFn - A function that returns an async generator with service requirements\n * @param provider - A function that provides the services (e.g., Provide.layer(AppLayer))\n * @returns Exit result from running the provided Fx (sync or async depending on provider output)\n *\n * @example\n * ```ts\n * import { Fx, Provide, Service } from \"@nicolastoulemont/std\"\n *\n * const Token = Service.tag<string>(\"Token\")\n *\n * const exit = await Fx.fn(async function* () {\n * const token = yield* Token\n * const suffix = await Promise.resolve(\"!\")\n * return `${token}${suffix}`\n * }, Provide.service(Token, \"abc\"))\n * // => { _tag: \"Ok\", value: \"abc!\" }\n * ```\n */\nfunction fxFn<A, E, R, ProvidedFx extends RunnableFx<unknown, unknown, unknown>>(\n generatorFn: () => AsyncFxGenerator<A, E, R>,\n provider: (fx: AsyncFx<A, E, R>) => ProvidedFx,\n): FxRunResult<ProvidedFx>\n\n/**\n * Implementation of Fx.fn.\n * Reuses fxGen() for Fx creation and fxRun() for execution to ensure consistent behavior.\n */\nfunction fxFn<A, E, E2, R>(\n generatorFn: () => FxGenerator<A, E, R> | AsyncFxGenerator<A, E, R>,\n provider?: ((fx: SyncFx<A, E, R>) => RunnableFx<A, E | E2>) | ((fx: AsyncFx<A, E, R>) => RunnableFx<A, E | E2>),\n): ExitType<A, E | E2> | Promise<ExitType<A, E | E2>> {\n // Create the Fx using fxGen (single source of truth for Fx creation)\n // Type cast needed because fxGen infers E/R from yielded Fx values,\n // while fxFn receives E/R as explicit type parameters\n // oxlint-disable-next-line no-explicit-any\n const fx = fxGen(generatorFn as any) as RunnableFx<A, E, R>\n\n if (provider) {\n // Apply provider and run\n const provided =\n fx._tag === \"AsyncFx\"\n ? (provider as (fx: AsyncFx<A, E, R>) => RunnableFx<A, E | E2>)(fx)\n : (provider as (fx: SyncFx<A, E, R>) => RunnableFx<A, E | E2>)(fx)\n return fxRun(provided as RunnableFx<A, E | E2>) as ExitType<A, E | E2> | Promise<ExitType<A, E | E2>>\n }\n\n // No provider - run directly (R must be never at the type level)\n return fxRun(fx as RunnableFx<A, E | E2>) as ExitType<A, E | E2> | Promise<ExitType<A, E | E2>>\n}\n\n// ============================================================================\n// Fx.ok / Fx.err / Fx.option - Convenience aliases\n// ============================================================================\n\n/**\n * Convenience alias for Result.ok.\n * Creates a successful Result that can be yielded in an Fx computation.\n *\n * @param value - The success value\n * @returns Result<T, never>\n *\n * @example\n * ```ts\n * const workflow = Fx.gen(function* () {\n * const value = yield* Fx.ok(42)\n * return value * 2\n * })\n * ```\n */\nconst fxOk = resultOk\n\n/**\n * Convenience alias for Result.err.\n * Creates an error Result that can be yielded in an Fx computation.\n *\n * @param error - The error value\n * @returns Result<never, E>\n *\n * @example\n * ```ts\n * const workflow = Fx.gen(function* () {\n * const config = yield* Config\n *\n * if (!config.dbUrl) {\n * return yield* Fx.err(new ValidationError({ field: \"dbUrl\" }))\n * }\n *\n * return config.dbUrl\n * })\n * ```\n */\nconst fxErr = resultErr\n\n/**\n * Convenience alias for Result.try.\n * Creates a Result that can be yielded in an Fx computation.\n *\n * @param fn - A function that returns a value or throws an error\n * @returns Result<T, E>\n *\n * @example\n * ```ts\n * const result = Fx.try(() => {\n * return 42\n * })\n *\n * const workflow = Fx.gen(function* () {\n * const result = yield* Fx.try(() => {\n * return 42\n * })\n * return result\n * })\n * ```\n */\nconst fxTry = resultTry\n\n/**\n * Convenience alias for Option.fromNullable.\n * Converts nullable values into an Option that can be yielded in an Fx computation.\n *\n * @param value - A possibly nullish value\n * @returns Option<NonNullable<T>>\n *\n * @example\n * ```ts\n * const workflow = Fx.gen(function* () {\n * const apiKey = yield* Fx.option(request.headers[\"x-api-key\"])\n * return apiKey\n * })\n * ```\n */\nconst fxOption = optionFromNullable\n\n// ============================================================================\n// Fx.match - Universal pattern matching\n// ============================================================================\n\n/**\n * Handler functions for matching on a tagged union by `_tag` discriminator.\n * Each handler receives the narrowed variant corresponding to its tag key.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = typeof Fx\n * ```\n */\nexport type TaggedMatch<T extends { readonly _tag: string }, R> = {\n readonly [K in T[\"_tag\"]]: (variant: Extract<T, { readonly _tag: K }>) => R\n}\n\n/**\n * Generic pattern matcher for any `_tag`-based discriminated union.\n *\n * Works with Exit, tagged errors, or any type with a `readonly _tag` discriminator.\n * Each handler receives the full narrowed variant object for its tag.\n *\n * Supports both data-first and data-last (pipe) calling styles.\n *\n * @example\n * ```ts\n * // Match on Exit\n * Fx.match(exit, {\n * Ok: (ok) => ok.value,\n * Err: (err) =>\n * Fx.match(err.error, {\n * DatabaseError: (e) => e.message,\n * NotFoundError: (e) => e.resourceId,\n * }),\n * Defect: (d) => String(d.defect),\n * })\n *\n * // Data-last with pipe\n * pipe(exit, Fx.match({\n * Ok: (ok) => ok.value,\n * Err: (err) => \"error\",\n * Defect: (d) => \"defect\",\n * }))\n * ```\n */\nconst fxMatch: {\n <T extends { readonly _tag: string }, R>(value: T, handlers: TaggedMatch<T, R>): R\n <T extends { readonly _tag: string }, R>(handlers: TaggedMatch<T, R>): (value: T) => R\n} = dual(\n 2,\n // oxlint-disable-next-line no-explicit-any\n (value: any, handlers: any): any => handlers[value._tag](value),\n)\n\n// ============================================================================\n// Exports\n// ============================================================================\n\n/**\n * Build typed computations from generator functions.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const program = Fx.gen(function* () {\n * const value = yield* Fx.ok(2)\n * return value + 1\n * })\n * const exit = Fx.run(program)\n * // => { _tag: \"Ok\", value: 3 }\n * ```\n */\nexport const gen = fxGen\n\n/**\n * Run a generator function immediately and return its `Exit`.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const exit = Fx.fn(function* () {\n * return yield* Fx.ok(2)\n * })\n * // => { _tag: \"Ok\", value: 2 }\n * ```\n */\nexport const fn = fxFn\n\n/**\n * Execute an existing `Fx` value and produce an `Exit`.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const exit = Fx.run(Fx.gen(function* () {\n * return 1\n * }))\n * // => { _tag: \"Ok\", value: 1 }\n * ```\n */\nexport const run = fxRun\n\n/**\n * Retry failed computations according to a schedule.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * import { Schedule } from \"@nicolastoulemont/std\"\n *\n * const retried = Fx.retry(\n * Fx.gen(function* () {\n * return yield* Fx.err(\"boom\")\n * }),\n * Schedule.recurs(2),\n * )\n * const exit = Fx.run(retried)\n * // => { _tag: \"Err\", error: \"boom\" }\n * ```\n */\nexport const retry = fxRetry\n\n/**\n * Run an effectful function for each item in a collection.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const fx = Fx.forEach([1, 2, 3], (n) => Fx.gen(function* () {\n * return n * 2\n * }))\n * // => AsyncFx<readonly number[], ...>\n * ```\n */\nexport const forEach = fxForEach\n\n/**\n * Alias for `Result.ok` in `Fx` namespace.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const value = Fx.ok(42)\n * // => { _tag: \"Ok\", value: 42 }\n * ```\n */\nexport const ok = fxOk\n\n/**\n * Alias for `Result.err` in `Fx` namespace.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const value = Fx.err(\"boom\")\n * // => { _tag: \"Err\", error: \"boom\" }\n * ```\n */\nexport const err = fxErr\n\n/**\n * Alias for `Option.fromNullable` in `Fx` namespace.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const value = Fx.option(\"token\")\n * // => { _tag: \"Some\", value: \"token\" }\n * ```\n */\nexport const option = fxOption\n\nconst try_ = fxTry\n\nexport {\n /**\n * Alias for `Result.fromTry` in `Fx` namespace.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const parsed = Fx.try(() => Number.parseInt(\"42\", 10))\n * // => { _tag: \"Ok\", value: 42 }\n * ```\n *\n */\n try_ as try,\n}\n\n/**\n * Pattern matching helper for tagged unions.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const value = Fx.match({ _tag: \"Ok\", value: 2 } as const, {\n * Ok: (ok) => ok.value + 1,\n * })\n * // => 3\n * ```\n */\nexport const match = fxMatch\n\n/* oxlint-enable no-unsafe-type-assertion, no-unsafe-assignment, no-unsafe-call, no-unsafe-member-access, no-unsafe-return, no-unsafe-argument, no-unnecessary-type-assertion */\n"],"mappings":"icA8CA,IAAM,EAAN,cAA8B,KAAM,CAClC,KAAgB,eAEhB,YAAY,EAAmB,CAC7B,MAAM,eAAe,CADF,KAAA,MAAA,EAEnB,KAAK,KAAO,iBAIhB,MAAM,EAAqB,GAA6C,aAAiB,EAEnF,EAAe,GACnB,OA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M,EAAW,MAAM,EAAO,MAE9B,EAAS,MAAMA,EAAI,KAAK,EAAS,CAGnC,OAAO,EAAO,OAEjB,CAII,CACL,KAAM,UACL,GAAW,CACV,OAAU,IAAA,GACV,OAAU,IAAA,GACV,OAAU,IAAA,GACX,CAED,EAAE,OAAO,WAA0C,CACjD,IAAMA,EAAM,GAAa,CACrB,EAASA,EAAI,MAAM,CAEvB,KAAO,EAAO,OAAS,IAAM,CAC3B,IAAM,EAAW,MAAM,EAAO,MAC9B,EAASA,EAAI,KAAK,EAAS,CAG7B,OAAO,EAAO,OAEjB,CA8HH,SAAS,EACP,EACA,EACoD,CAKpD,IAAM,EAAK,EAAM,EAAmB,CAYpC,OAJS,EANL,GAGA,EAAG,KACE,EAA6D,EAAG,EAM5D,EAJoC,CA0BnD,MAAM,EAAOE,EAsBP,EAAQC,EAuBR,EAAQC,EAiBR,EAAWC,EAkDX,EAGF,EACF,GAEC,EAAY,IAAuB,EAAS,EAAM,MAAM,EAAM,CAChE,CAqBY,EAAM,EAeN,EAAK,EAeL,EAAM,EAqBN,EAAQ,EAeR,EAAU,EAaV,EAAK,EAaL,EAAM,EAaN,EAAS,EAEhB,EAAO,EA+BA,EAAQ"}
|
|
1
|
+
{"version":3,"file":"fx-C_RTDEpv.mjs","names":["gen","result","makeQueue","gen","result","resultOk","resultErr","resultTry","optionFromNullable"],"sources":["../src/fx/foreach.ts","../src/fx/fx.ts"],"sourcesContent":["import { NoSuchElementError } from \"../option/option.types\"\nimport { make as makeQueue, QueueAbortedError, QueueClosedError, QueueTaskAbortedError } from \"../queue/queue\"\nimport type { Concurrency } from \"../queue/queue.types\"\nimport { asServiceRequest } from \"../service/service-resolution\"\nimport { dual } from \"../shared/dual\"\nimport { FxTypeId } from \"./fx.types\"\nimport type { AsyncFx, FxError, FxRequirements, FxValue, FxYield, RunnableFx } from \"./fx.types\"\n\n/* oxlint-disable no-await-in-loop -- Fx.forEach coordinates child iterators and queue scheduling sequentially at specific yield points. */\n\ntype ForEachValue<Discard extends boolean, B> = Discard extends true ? void : Array<B>\n\ntype FxForEachOptions<Discard extends boolean = false> = {\n readonly concurrency?: Concurrency\n readonly discard?: Discard\n}\n\ntype ForEachFx<\n F extends (a: never, i: number) => RunnableFx<unknown, unknown, unknown>,\n Discard extends boolean,\n> = AsyncFx<ForEachValue<Discard, FxValue<ReturnType<F>>>, FxError<ReturnType<F>>, FxRequirements<ReturnType<F>>>\n\ntype FxForEach = {\n <A, F extends (a: A, i: number) => RunnableFx<unknown, unknown, unknown>, const Discard extends boolean = false>(\n self: Iterable<A>,\n f: F,\n options?: FxForEachOptions<Discard>,\n ): ForEachFx<F, Discard>\n <A, F extends (a: A, i: number) => RunnableFx<unknown, unknown, unknown>, const Discard extends boolean = false>(\n f: F,\n options?: FxForEachOptions<Discard>,\n ): (self: Iterable<A>) => ForEachFx<F, Discard>\n}\n\ntype ServiceRequestEntry<E, R> = {\n readonly yielded: FxYield<E, R>\n readonly signal: AbortSignal\n readonly resolve: (value: unknown) => void\n readonly reject: (reason: Error) => void\n}\n\ntype ResultErrShape = {\n readonly _tag: \"Err\"\n readonly error: unknown\n}\n\nclass TypedFailure<E> extends Error {\n readonly _tag = \"TypedFailure\"\n\n constructor(readonly error: E) {\n super(\"TypedFailure\")\n this.name = \"TypedFailure\"\n }\n}\n\nconst isTypedFailure = <E>(value: unknown): value is TypedFailure<E> => value instanceof TypedFailure\n\nconst isResultErr = (value: unknown): value is ResultErrShape =>\n typeof value === \"object\" && value !== null && \"_tag\" in value && value._tag === \"Err\" && \"error\" in value\n\nconst toFailureValue = (yielded: unknown): unknown => {\n if (yielded instanceof NoSuchElementError) {\n return yielded\n }\n\n if (isResultErr(yielded)) {\n return yielded.error\n }\n\n return yielded\n}\n\nconst isIterable = (value: unknown): value is Iterable<unknown> =>\n value !== null &&\n value !== undefined &&\n typeof (value as { [Symbol.iterator]?: unknown })[Symbol.iterator] === \"function\"\n\nconst queueTaskAbortedError = (signal: AbortSignal): QueueTaskAbortedError =>\n new QueueTaskAbortedError({ reason: signal.reason })\n\nconst toError = (reason: unknown): Error =>\n reason instanceof Error ? reason : new Error(\"Fx.forEach defect was not an Error\", { cause: reason })\n\nconst unreachableType = (): never => {\n throw new Error(\"Unreachable: Fx type marker should never execute at runtime\")\n}\n\nconst typeMarker = <A>(): (() => A) => unreachableType\n\nconst runMappedFx = async <B, E, R>(\n fx: RunnableFx<B, E, R>,\n signal: AbortSignal,\n requestService: (yielded: FxYield<E, R>, signal: AbortSignal) => Promise<unknown>,\n): Promise<B> => {\n if (fx._tag === \"AsyncFx\") {\n const gen = fx[Symbol.asyncIterator]()\n let result = await gen.next()\n\n while (result.done !== true) {\n if (signal.aborted) {\n throw queueTaskAbortedError(signal)\n }\n\n const yielded = result.value\n const serviceRequest = asServiceRequest(yielded)\n if (serviceRequest !== undefined) {\n const injected = await requestService(yielded, signal)\n result = await gen.next(injected)\n continue\n }\n\n // oxlint-disable-next-line typescript-eslint/no-unsafe-type-assertion -- failure channel values come from generic E at runtime.\n throw new TypedFailure<E>(toFailureValue(yielded) as E)\n }\n\n return result.value\n }\n\n const gen = fx[Symbol.iterator]()\n let result = gen.next()\n\n while (result.done !== true) {\n if (signal.aborted) {\n throw queueTaskAbortedError(signal)\n }\n\n const yielded = result.value\n const serviceRequest = asServiceRequest(yielded)\n if (serviceRequest !== undefined) {\n const injected = await requestService(yielded, signal)\n result = gen.next(injected)\n continue\n }\n\n // oxlint-disable-next-line typescript-eslint/no-unsafe-type-assertion -- failure channel values come from generic E at runtime.\n throw new TypedFailure<E>(toFailureValue(yielded) as E)\n }\n\n return result.value\n}\n\nconst fxForEach = dual(\n (args) => isIterable(args[0]) && typeof args[1] === \"function\",\n <A, B, E, R>(\n self: Iterable<A>,\n f: (a: A, i: number) => RunnableFx<B, E, R>,\n options?: FxForEachOptions<boolean>,\n ): AsyncFx<Array<B> | void, E, R> => {\n const items = [...self]\n const discard = options?.discard === true\n\n const program: AsyncFx<Array<B> | void, E, R> = {\n _tag: \"AsyncFx\",\n [FxTypeId]: {\n _A: typeMarker<Array<B> | void>(),\n _E: typeMarker<E>(),\n _R: typeMarker<R>(),\n },\n async *[Symbol.asyncIterator](): AsyncGenerator<FxYield<E, R>, Array<B> | void, unknown> {\n if (items.length === 0) {\n return discard ? undefined : []\n }\n\n const queue = makeQueue({ concurrency: options?.concurrency ?? \"unbounded\" })\n const results: Array<B> | undefined = discard ? undefined : []\n\n let remaining = items.length\n let firstFailure: E | undefined\n let firstDefect: Error | undefined\n let queueAborted = false\n\n const serviceRequests: ServiceRequestEntry<E, R>[] = []\n const eventWaiters = new Set<() => void>()\n\n const notifyEvent = () => {\n for (const resolve of eventWaiters) {\n resolve()\n }\n eventWaiters.clear()\n }\n\n const waitForEvent = () =>\n new Promise<void>((resolve) => {\n eventWaiters.add(resolve)\n })\n\n const requestService = (yielded: FxYield<E, R>, signal: AbortSignal): Promise<unknown> => {\n if (signal.aborted) {\n return Promise.reject(queueTaskAbortedError(signal))\n }\n\n return new Promise<unknown>((resolve, reject) => {\n const entry: ServiceRequestEntry<E, R> = {\n yielded,\n signal,\n resolve: (value) => {\n signal.removeEventListener(\"abort\", onAbort)\n resolve(value)\n },\n reject: (reason) => {\n signal.removeEventListener(\"abort\", onAbort)\n reject(reason)\n },\n }\n\n const onAbort = () => {\n const index = serviceRequests.indexOf(entry)\n if (index !== -1) {\n serviceRequests.splice(index, 1)\n }\n reject(queueTaskAbortedError(signal))\n }\n\n signal.addEventListener(\"abort\", onAbort, { once: true })\n serviceRequests.push(entry)\n notifyEvent()\n })\n }\n\n const rejectPendingServiceRequests = (reason: Error) => {\n const pending = serviceRequests.splice(0)\n for (const request of pending) {\n request.reject(reason)\n }\n }\n\n const abortQueue = (reason: unknown) => {\n if (queueAborted) {\n return\n }\n\n queueAborted = true\n void queue.shutdown({ mode: \"abort\", reason }).catch(() => {\n // no-op: fail-fast cleanup should never interrupt parent error handling\n })\n }\n\n const onTaskFailure = (error: unknown) => {\n if (isTypedFailure<E>(error)) {\n if (firstFailure === undefined && firstDefect === undefined) {\n firstFailure = error.error\n abortQueue(error.error)\n }\n return\n }\n\n if (\n (error instanceof QueueAbortedError ||\n error instanceof QueueTaskAbortedError ||\n error instanceof QueueClosedError) &&\n (firstFailure !== undefined || firstDefect !== undefined)\n ) {\n return\n }\n\n if (firstDefect === undefined && firstFailure === undefined) {\n const defect = toError(error)\n firstDefect = defect\n abortQueue(defect)\n }\n }\n\n const onTaskSettled = () => {\n remaining -= 1\n notifyEvent()\n }\n\n for (const [index, item] of items.entries()) {\n void queue\n .enqueue(async ({ signal }) => {\n const value = await runMappedFx(f(item, index), signal, requestService)\n if (results !== undefined) {\n results[index] = value\n }\n })\n .catch(onTaskFailure)\n .finally(onTaskSettled)\n }\n\n while (true) {\n if (firstDefect !== undefined) {\n rejectPendingServiceRequests(firstDefect)\n throw new Error(\"Fx.forEach defect\", { cause: firstDefect })\n }\n\n if (firstFailure !== undefined) {\n rejectPendingServiceRequests(new QueueAbortedError({ reason: firstFailure }))\n yield firstFailure\n throw new Error(\"Unreachable: Fx runtime short-circuits on first failure\")\n }\n\n const request = serviceRequests.shift()\n if (request !== undefined) {\n if (request.signal.aborted) {\n request.reject(queueTaskAbortedError(request.signal))\n continue\n }\n\n try {\n const injected = yield request.yielded\n request.resolve(injected)\n } catch (error) {\n request.reject(toError(error))\n }\n continue\n }\n\n if (remaining === 0) {\n break\n }\n\n await waitForEvent()\n }\n\n return discard ? undefined : results\n },\n }\n\n return program\n },\n) as FxForEach\n\nexport { fxForEach as forEach }\n\n/* oxlint-enable no-await-in-loop */\n","/**\n * Lightweight effect runtime with typed success, error, and requirement channels.\n *\n * **Mental model**\n * - `Fx<A, E, R>` models computations that may fail and require services.\n * - Build with `Fx.gen`, run with `Fx.run`, and compose with `Layer`/`Provide`.\n *\n * **Common tasks**\n * - Create workflows with `Fx.gen`.\n * - Execute with `Fx.run` or `Fx.fn`.\n * - Retry with `Fx.retry` and match outcomes with `Fx.match`.\n *\n * **Gotchas**\n * - Dependencies (`R`) must be provided before execution.\n * - `Fx.run` returns `Exit`, not raw values.\n *\n * **Quickstart**\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const program = Fx.gen(function* () {\n * const value = yield* Fx.ok(2)\n * return value + 1\n * })\n * const exit = Fx.run(program)\n * // => { _tag: \"Ok\", value: 3 }\n * ```\n *\n * @module\n */\nimport { fromNullable as optionFromNullable } from \"../option/option\"\nimport { ok as resultOk, err as resultErr, fromTry as resultTry } from \"../result/result\"\nimport type { RetrySchedule, SyncRetrySchedule } from \"../schedule/schedule\"\nimport { asServiceRequest } from \"../service/service-resolution\"\nimport { dual } from \"../shared/dual\"\nimport type { Exit as ExitType } from \"./exit\"\nimport { forEach as fxForEach } from \"./foreach\"\nimport { runSync, runAsync } from \"./fx.runtime\"\nimport { FxTypeId } from \"./fx.types\"\nimport type { RunnableFx, SyncFx, AsyncFx, FxYield, Fx as FxProtocol, FxGenerator, AsyncFxGenerator } from \"./fx.types\"\nexport {\n /**\n * `Exit` utilities namespace for `Fx.run` outcomes.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const exit = Fx.Exit.ok(1)\n * // => { _tag: \"Ok\", value: 1 }\n * ```\n *\n */\n Exit,\n} from \"./exit\"\nexport {\n /**\n * Type guard for Fx service requests.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const request = { _tag: \"ServiceRequest\", serviceKey: \"Logger\" } as Fx.ServiceRequest<unknown>\n * const isRequest = Fx.isServiceRequest(request)\n * // => true\n * ```\n *\n */\n isServiceRequest,\n} from \"./fx.types\"\nexport {\n /**\n * Runtime unique symbol identifying Fx values.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const marker = { [Fx.FxTypeId]: true }\n * // => Object.getOwnPropertySymbols(marker).includes(Fx.FxTypeId)\n * ```\n *\n */\n FxTypeId,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported core Fx protocol type.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.Fx<unknown, unknown, unknown>\n * ```\n *\n */\n type Fx,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported synchronous Fx type.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.SyncFx<unknown, unknown, unknown>\n * ```\n *\n */\n type SyncFx,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported asynchronous Fx type.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.AsyncFx<unknown, unknown, unknown>\n * ```\n *\n */\n type AsyncFx,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported runnable Fx union type.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.RunnableFx<unknown, unknown, unknown>\n * ```\n *\n */\n type RunnableFx,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported service-request protocol type.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.ServiceRequest<unknown>\n * ```\n *\n */\n type ServiceRequest,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported helper extracting Fx success type.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.FxValue<Fx.SyncFx<number>>\n * ```\n *\n */\n type FxValue,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported helper extracting Fx error type.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.FxError<Fx.SyncFx<number, string>>\n * ```\n *\n */\n type FxError,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported helper extracting Fx requirements type.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.FxRequirements<Fx.SyncFx<number, never, { readonly svc: unknown }>>\n * ```\n *\n */\n type FxRequirements,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported generator yield union for Fx internals.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.FxYield<unknown, unknown>\n * ```\n *\n */\n type FxYield,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported sync generator signature used by `Fx.gen`.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.FxGenerator<unknown, unknown, unknown>\n * ```\n *\n */\n type FxGenerator,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported async generator signature used by `Fx.gen`.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.AsyncFxGenerator<unknown, unknown, unknown>\n * ```\n *\n */\n type AsyncFxGenerator,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported sync Fx yieldable protocol type.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.FxYieldable<unknown, unknown, unknown>\n * ```\n *\n */\n type FxYieldable,\n} from \"./fx.types\"\nexport {\n /**\n * Re-exported async Fx yieldable protocol type.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = Fx.AsyncFxYieldable<unknown, unknown, unknown>\n * ```\n *\n */\n type AsyncFxYieldable,\n} from \"./fx.types\"\n\n/* oxlint-disable no-unsafe-type-assertion, no-unsafe-assignment, no-unsafe-call, no-unsafe-member-access, no-unsafe-return, no-unsafe-argument, no-unnecessary-type-assertion -- Fx runtime adapters intentionally traverse erased generator channels and rehydrate typed effects through controlled dynamic boundaries. */\n\n// ============================================================================\n// Fx.run - Execute computations\n// ============================================================================\n\n/**\n * Execute a sync Fx computation and return the Exit.\n * Catches unexpected thrown exceptions and wraps them as Defect.\n * Only available when R = never (all dependencies provided).\n *\n * @param fx - The sync computation to execute\n * @returns Exit<A, E>\n */\nfunction fxRun<A, E>(fx: SyncFx<A, E>): ExitType<A, E>\n\n/**\n * Execute an async Fx computation and return a Promise of the Exit.\n * Catches unexpected thrown exceptions and wraps them as Defect.\n * Only available when R = never (all dependencies provided).\n *\n * @param fx - The async computation to execute\n * @returns Promise<Exit<A, E>>\n */\nfunction fxRun<A, E>(fx: AsyncFx<A, E>): Promise<ExitType<A, E>>\n\n/**\n * Execute an Fx computation (union type).\n * Returns Exit for sync, Promise<Exit> for async.\n * Catches unexpected thrown exceptions and wraps them as Defect.\n */\nfunction fxRun<A, E>(fx: RunnableFx<A, E>): ExitType<A, E> | Promise<ExitType<A, E>>\n\n/**\n * Implementation of Fx.run.\n * Detects sync vs async and executes appropriately.\n */\nfunction fxRun<A, E>(fx: RunnableFx<A, E>): ExitType<A, E> | Promise<ExitType<A, E>> {\n if (fx._tag === \"AsyncFx\") {\n return runAsync(fx)\n }\n return runSync(fx)\n}\n\n// ============================================================================\n// Fx.retry - Retry failed computations\n// ============================================================================\n\nconst sleep = (ms: number): Promise<void> =>\n new Promise((resolve) => {\n setTimeout(resolve, ms)\n })\n\nconst sleepIfNeeded = async (ms: number): Promise<void> => {\n if (ms <= 0) {\n return\n }\n await sleep(ms)\n}\n\nconst closeSyncAttempt = (gen: Generator<unknown, unknown, unknown>) => {\n if (typeof gen.return === \"function\") {\n gen.return(undefined)\n }\n}\n\nconst closeAsyncAttempt = async (\n gen: Generator<unknown, unknown, unknown> | AsyncGenerator<unknown, unknown, unknown>,\n) => {\n if (typeof gen.return === \"function\") {\n await gen.return(undefined)\n }\n}\n\nconst makeSyncRetryFx = <A, E, R>(fx: SyncFx<A, E, R>, schedule: SyncRetrySchedule): SyncFx<A, E, R> => ({\n _tag: \"SyncFx\",\n [FxTypeId]: {\n _A: () => undefined as unknown as A,\n _E: () => undefined as unknown as E,\n _R: () => undefined as unknown as R,\n },\n *[Symbol.iterator](): Generator<FxYield<E, R>, A, unknown> {\n let retryAttempt = 0\n attemptLoop: while (true) {\n const gen = fx[Symbol.iterator]()\n let result = gen.next()\n\n while (result.done !== true) {\n const yielded = result.value\n const serviceRequest = asServiceRequest(yielded)\n if (serviceRequest !== undefined) {\n const injected = yield yielded as FxYield<E, R>\n result = gen.next(injected)\n continue\n }\n\n retryAttempt += 1\n if (retryAttempt <= schedule.maxRetries) {\n closeSyncAttempt(gen)\n continue attemptLoop\n }\n\n // Forward the terminal typed failure to the outer runtime.\n yield yielded as FxYield<E, R>\n return undefined as never\n }\n\n return result.value\n }\n },\n})\n\n/* oxlint-disable no-await-in-loop -- retry execution is intentionally sequential across attempts and iterator steps. */\nconst makeAsyncRetryFx = <A, E, R>(fx: RunnableFx<A, E, R>, schedule: RetrySchedule): AsyncFx<A, E, R> => ({\n _tag: \"AsyncFx\",\n [FxTypeId]: {\n _A: () => undefined as unknown as A,\n _E: () => undefined as unknown as E,\n _R: () => undefined as unknown as R,\n },\n async *[Symbol.asyncIterator](): AsyncGenerator<FxYield<E, R>, A, unknown> {\n let retryAttempt = 0\n\n attemptLoop: while (true) {\n if (fx._tag === \"AsyncFx\") {\n const gen = fx[Symbol.asyncIterator]()\n // Sequential async iterator protocol: each step depends on the previous one.\n let result = await gen.next()\n\n while (result.done !== true) {\n const yielded = result.value\n const serviceRequest = asServiceRequest(yielded)\n if (serviceRequest !== undefined) {\n const injected = yield yielded as FxYield<E, R>\n // oxlint-disable-next-line no-await-in-loop\n result = await gen.next(injected)\n continue\n }\n\n retryAttempt += 1\n if (retryAttempt <= schedule.maxRetries) {\n const delayMs = schedule.delayForAttempt(retryAttempt)\n await sleepIfNeeded(delayMs)\n await closeAsyncAttempt(gen)\n continue attemptLoop\n }\n\n // Forward the terminal typed failure to the outer runtime.\n yield yielded as FxYield<E, R>\n return undefined as never\n }\n\n return result.value\n }\n\n const gen = fx[Symbol.iterator]()\n let result = gen.next()\n\n while (result.done !== true) {\n const yielded = result.value\n const serviceRequest = asServiceRequest(yielded)\n if (serviceRequest !== undefined) {\n const injected = yield yielded as FxYield<E, R>\n result = gen.next(injected)\n continue\n }\n\n retryAttempt += 1\n if (retryAttempt <= schedule.maxRetries) {\n const delayMs = schedule.delayForAttempt(retryAttempt)\n await sleepIfNeeded(delayMs)\n await closeAsyncAttempt(gen)\n continue attemptLoop\n }\n\n // Forward the terminal typed failure to the outer runtime.\n yield yielded as FxYield<E, R>\n return undefined as never\n }\n\n return result.value\n }\n },\n})\n/* oxlint-enable no-await-in-loop */\n\n/**\n * Retry a computation according to the given schedule.\n *\n * Retries only typed failures (Err channel). Defects are not retried.\n */\ntype RetryResult<Fx extends RunnableFx<unknown, unknown, unknown>, S extends RetrySchedule> =\n Fx extends AsyncFx<infer A, infer E, infer R>\n ? AsyncFx<A, E, R>\n : S extends SyncRetrySchedule\n ? Fx extends SyncFx<infer A, infer E, infer R>\n ? SyncFx<A, E, R>\n : never\n : Fx extends SyncFx<infer A, infer E, infer R>\n ? AsyncFx<A, E, R>\n : never\n\nconst fxRetry: {\n <Fx extends RunnableFx<unknown, unknown, unknown>, S extends RetrySchedule>(fx: Fx, schedule: S): RetryResult<Fx, S>\n <S extends RetrySchedule>(\n schedule: S,\n ): <Fx extends RunnableFx<unknown, unknown, unknown>>(fx: Fx) => RetryResult<Fx, S>\n} = dual(\n 2,\n <Fx extends RunnableFx<unknown, unknown, unknown>, S extends RetrySchedule>(\n fx: Fx,\n schedule: S,\n ): RetryResult<Fx, S> => {\n if (fx._tag === \"AsyncFx\" || !schedule._sync) {\n return makeAsyncRetryFx(fx, schedule) as RetryResult<Fx, S>\n }\n return makeSyncRetryFx(fx as SyncFx<unknown, unknown, unknown>, schedule as SyncRetrySchedule) as RetryResult<Fx, S>\n },\n)\n\n// ============================================================================\n// Fx.gen - Create composable computations\n// ============================================================================\n\ntype FxGenError<Yielded> = Yielded extends FxProtocol<unknown, infer E, unknown> ? E : Yielded\ntype FxGenRequirements<Yielded> = Yielded extends FxProtocol<unknown, unknown, infer R> ? R : never\n\n/**\n * Create a composable computation from a sync generator function.\n * Returns a SyncFx that can be stored, passed around, and executed later.\n *\n * @template Yielded - The type of values yielded by the generator\n * @template A - The success value type\n * @param generatorFn - A function that returns a sync generator\n * @returns SyncFx<A, FxGenError<Yielded>, FxGenRequirements<Yielded>>\n *\n * @example\n * ```ts\n * import { Fx, Provide, Service } from \"@nicolastoulemont/std\"\n *\n * const Port = Service.tag<number>(\"Port\")\n * const readPort = Fx.gen(function* () {\n * return yield* Port\n * })\n * const exit = Fx.run(Provide.service(Port, 3000)(readPort))\n * // => { _tag: \"Ok\", value: 3000 }\n * ```\n */\nfunction fxGen<Yielded, A>(\n generatorFn: () => Generator<Yielded, A, unknown>,\n): SyncFx<A, FxGenError<Yielded>, FxGenRequirements<Yielded>>\n\n/**\n * Create a composable computation from an async generator function.\n * Returns an AsyncFx that can be stored, passed around, and executed later.\n *\n * @template Yielded - The type of values yielded by the generator\n * @template A - The success value type\n * @param generatorFn - A function that returns an async generator\n * @returns AsyncFx<A, FxGenError<Yielded>, FxGenRequirements<Yielded>>\n *\n * @example\n * ```ts\n * import { Fx, Provide, Service } from \"@nicolastoulemont/std\"\n *\n * const Token = Service.tag<string>(\"Token\")\n * const readToken = Fx.gen(async function* () {\n * const token = yield* Token\n * const suffix = await Promise.resolve(\"-ok\")\n * return `${token}${suffix}`\n * })\n * const exit = await Fx.run(Provide.service(Token, \"abc\")(readToken))\n * // => { _tag: \"Ok\", value: \"abc-ok\" }\n * ```\n */\nfunction fxGen<Yielded, A>(\n generatorFn: () => AsyncGenerator<Yielded, A, unknown>,\n): AsyncFx<A, FxGenError<Yielded>, FxGenRequirements<Yielded>>\n\n/**\n * Create a composable computation from a sync generator function that takes parameters.\n * Returns a factory function that, when called with parameters, produces a SyncFx.\n *\n * @template P - The parameter types (must be non-empty)\n * @template Yielded - The type of values yielded by the generator\n * @template A - The success value type\n * @param generatorFn - A function that takes parameters and returns a sync generator\n * @returns A factory function that produces SyncFx<A, FxGenError<Yielded>, FxGenRequirements<Yielded>>\n *\n * @example\n * ```ts\n * import { Fx, Provide, Service } from \"@nicolastoulemont/std\"\n *\n * const Port = Service.tag<number>(\"Port\")\n * const describePort = Fx.gen(function* (label: string) {\n * const port = yield* Port\n * return `${label}:${port}`\n * })\n * const exit = Fx.run(Provide.service(Port, 3000)(describePort(\"port\")))\n * // => { _tag: \"Ok\", value: \"port:3000\" }\n * ```\n */\nfunction fxGen<P extends [unknown, ...unknown[]], Yielded, A>(\n generatorFn: (...params: P) => Generator<Yielded, A, unknown>,\n): (...params: P) => SyncFx<A, FxGenError<Yielded>, FxGenRequirements<Yielded>>\n\n/**\n * Create a composable computation from an async generator function that takes parameters.\n * Returns a factory function that, when called with parameters, produces an AsyncFx.\n *\n * @template P - The parameter types (must be non-empty)\n * @template Yielded - The type of values yielded by the generator\n * @template A - The success value type\n * @param generatorFn - A function that takes parameters and returns an async generator\n * @returns A factory function that produces AsyncFx<A, FxGenError<Yielded>, FxGenRequirements<Yielded>>\n *\n * @example\n * ```ts\n * import { Fx, Provide, Service } from \"@nicolastoulemont/std\"\n *\n * const Token = Service.tag<string>(\"Token\")\n * const describeToken = Fx.gen(async function* (prefix: string) {\n * const token = yield* Token\n * const suffix = await Promise.resolve(\"!\")\n * return `${prefix}:${token}${suffix}`\n * })\n * const exit = await Fx.run(Provide.service(Token, \"abc\")(describeToken(\"token\")))\n * // => { _tag: \"Ok\", value: \"token:abc!\" }\n * ```\n */\nfunction fxGen<P extends [unknown, ...unknown[]], Yielded, A>(\n generatorFn: (...params: P) => AsyncGenerator<Yielded, A, unknown>,\n): (...params: P) => AsyncFx<A, FxGenError<Yielded>, FxGenRequirements<Yielded>>\n\n/**\n * Implementation of unified Fx.gen function.\n * Detects sync vs async generator and returns appropriate computation type.\n * For parameterized generators (length > 0), returns a factory function.\n */\n// oxlint-disable-next-line no-explicit-any\nfunction fxGen(generatorFn: (...args: any[]) => any): any {\n if (generatorFn.length > 0) {\n return (...params: unknown[]) => fxGen(() => generatorFn(...params))\n }\n\n // Check if we're dealing with async generator\n const testGen = generatorFn()\n const isAsync = Symbol.asyncIterator in testGen\n\n if (isAsync) {\n return {\n _tag: \"AsyncFx\",\n [FxTypeId]: {\n _A: () => undefined,\n _E: () => undefined,\n _R: () => undefined,\n },\n // oxlint-disable-next-line no-explicit-any\n async *[Symbol.asyncIterator](): AsyncGenerator<any, any, unknown> {\n const gen = generatorFn()\n let result = await gen.next()\n\n while (result.done !== true) {\n // Pass through yields (errors or services as Fx values)\n const injected = yield result.value\n // oxlint-disable-next-line no-await-in-loop\n result = await gen.next(injected)\n }\n\n return result.value\n },\n }\n }\n\n // Sync generator\n return {\n _tag: \"SyncFx\",\n [FxTypeId]: {\n _A: () => undefined,\n _E: () => undefined,\n _R: () => undefined,\n },\n // oxlint-disable-next-line no-explicit-any\n *[Symbol.iterator](): Generator<any, any, unknown> {\n const gen = generatorFn()\n let result = gen.next()\n\n while (result.done !== true) {\n const injected = yield result.value\n result = gen.next(injected)\n }\n\n return result.value\n },\n }\n}\n\n// ============================================================================\n// Fx.fn - Execute computations immediately\n// ============================================================================\n\ntype FxRunResult<F extends RunnableFx<unknown, unknown, unknown>> =\n F extends AsyncFx<infer A, infer E, unknown>\n ? Promise<ExitType<A, E>>\n : F extends SyncFx<infer A, infer E, unknown>\n ? ExitType<A, E>\n : never\n\n/**\n * Execute a sync computation immediately and return the Exit.\n * Catches unexpected thrown exceptions and wraps them as Defect.\n * For computations without service dependencies.\n *\n * @template A - The success value type\n * @template E - The error type\n * @param generatorFn - A function that returns a sync generator\n * @returns Exit<A, E>\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const exit = Fx.fn(function* () {\n * const a = yield* Fx.ok(10)\n * const b = yield* Fx.ok(20)\n * return a + b\n * })\n * // => { _tag: \"Ok\", value: 30 }\n * ```\n */\nfunction fxFn<A, E>(generatorFn: () => FxGenerator<A, E, never>): ExitType<A, E>\n\n/**\n * Execute an async computation immediately and return a Promise of the Exit.\n * Catches unexpected thrown exceptions and wraps them as Defect.\n * For computations without service dependencies.\n *\n * @template A - The success value type\n * @template E - The error type\n * @param generatorFn - A function that returns an async generator\n * @returns Promise<Exit<A, E>>\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const exit = await Fx.fn(async function* () {\n * const value = await Promise.resolve(2)\n * return value + 1\n * })\n * // => { _tag: \"Ok\", value: 3 }\n * ```\n */\nfunction fxFn<A, E>(generatorFn: () => AsyncFxGenerator<A, E, never>): Promise<ExitType<A, E>>\n\n/**\n * Execute a sync computation with service dependencies immediately.\n * Catches unexpected thrown exceptions and wraps them as Defect.\n * The second argument is required when the computation has service requirements (R ≠ never).\n *\n * @template A - The success value type\n * @template E - The error type from the computation\n * @template R - The required services type\n * @param generatorFn - A function that returns a sync generator with service requirements\n * @param provider - A function that provides the services (e.g., Provide.layer(AppLayer))\n * @returns Exit result from running the provided Fx (sync or async depending on provider output)\n *\n * @example\n * ```ts\n * import { Fx, Provide, Service } from \"@nicolastoulemont/std\"\n *\n * const Port = Service.tag<number>(\"Port\")\n *\n * const exit = Fx.fn(function* () {\n * const port = yield* Port\n * return port + 1\n * }, Provide.service(Port, 3000))\n * // => { _tag: \"Ok\", value: 3001 }\n * ```\n */\nfunction fxFn<A, E, R, ProvidedFx extends RunnableFx<unknown, unknown, unknown>>(\n generatorFn: () => FxGenerator<A, E, R>,\n provider: (fx: SyncFx<A, E, R>) => ProvidedFx,\n): FxRunResult<ProvidedFx>\n\n/**\n * Execute an async computation with service dependencies immediately.\n * Catches unexpected thrown exceptions and wraps them as Defect.\n * The second argument is required when the computation has service requirements (R ≠ never).\n *\n * @template A - The success value type\n * @template E - The error type from the computation\n * @template R - The required services type\n * @param generatorFn - A function that returns an async generator with service requirements\n * @param provider - A function that provides the services (e.g., Provide.layer(AppLayer))\n * @returns Exit result from running the provided Fx (sync or async depending on provider output)\n *\n * @example\n * ```ts\n * import { Fx, Provide, Service } from \"@nicolastoulemont/std\"\n *\n * const Token = Service.tag<string>(\"Token\")\n *\n * const exit = await Fx.fn(async function* () {\n * const token = yield* Token\n * const suffix = await Promise.resolve(\"!\")\n * return `${token}${suffix}`\n * }, Provide.service(Token, \"abc\"))\n * // => { _tag: \"Ok\", value: \"abc!\" }\n * ```\n */\nfunction fxFn<A, E, R, ProvidedFx extends RunnableFx<unknown, unknown, unknown>>(\n generatorFn: () => AsyncFxGenerator<A, E, R>,\n provider: (fx: AsyncFx<A, E, R>) => ProvidedFx,\n): FxRunResult<ProvidedFx>\n\n/**\n * Implementation of Fx.fn.\n * Reuses fxGen() for Fx creation and fxRun() for execution to ensure consistent behavior.\n */\nfunction fxFn<A, E, E2, R>(\n generatorFn: () => FxGenerator<A, E, R> | AsyncFxGenerator<A, E, R>,\n provider?: ((fx: SyncFx<A, E, R>) => RunnableFx<A, E | E2>) | ((fx: AsyncFx<A, E, R>) => RunnableFx<A, E | E2>),\n): ExitType<A, E | E2> | Promise<ExitType<A, E | E2>> {\n // Create the Fx using fxGen (single source of truth for Fx creation)\n // Type cast needed because fxGen infers E/R from yielded Fx values,\n // while fxFn receives E/R as explicit type parameters\n // oxlint-disable-next-line no-explicit-any\n const fx = fxGen(generatorFn as any) as RunnableFx<A, E, R>\n\n if (provider) {\n // Apply provider and run\n const provided =\n fx._tag === \"AsyncFx\"\n ? (provider as (fx: AsyncFx<A, E, R>) => RunnableFx<A, E | E2>)(fx)\n : (provider as (fx: SyncFx<A, E, R>) => RunnableFx<A, E | E2>)(fx)\n return fxRun(provided as RunnableFx<A, E | E2>) as ExitType<A, E | E2> | Promise<ExitType<A, E | E2>>\n }\n\n // No provider - run directly (R must be never at the type level)\n return fxRun(fx as RunnableFx<A, E | E2>) as ExitType<A, E | E2> | Promise<ExitType<A, E | E2>>\n}\n\n// ============================================================================\n// Fx.ok / Fx.err / Fx.option - Convenience aliases\n// ============================================================================\n\n/**\n * Convenience alias for Result.ok.\n * Creates a successful Result that can be yielded in an Fx computation.\n *\n * @param value - The success value\n * @returns Result<T, never>\n *\n * @example\n * ```ts\n * const workflow = Fx.gen(function* () {\n * const value = yield* Fx.ok(42)\n * return value * 2\n * })\n * ```\n */\nconst fxOk = resultOk\n\n/**\n * Convenience alias for Result.err.\n * Creates an error Result that can be yielded in an Fx computation.\n *\n * @param error - The error value\n * @returns Result<never, E>\n *\n * @example\n * ```ts\n * const workflow = Fx.gen(function* () {\n * const config = yield* Config\n *\n * if (!config.dbUrl) {\n * return yield* Fx.err(new ValidationError({ field: \"dbUrl\" }))\n * }\n *\n * return config.dbUrl\n * })\n * ```\n */\nconst fxErr = resultErr\n\n/**\n * Convenience alias for Result.try.\n * Creates a Result that can be yielded in an Fx computation.\n *\n * @param fn - A function that returns a value or throws an error\n * @returns Result<T, E>\n *\n * @example\n * ```ts\n * const result = Fx.try(() => {\n * return 42\n * })\n *\n * const workflow = Fx.gen(function* () {\n * const result = yield* Fx.try(() => {\n * return 42\n * })\n * return result\n * })\n * ```\n */\nconst fxTry = resultTry\n\n/**\n * Convenience alias for Option.fromNullable.\n * Converts nullable values into an Option that can be yielded in an Fx computation.\n *\n * @param value - A possibly nullish value\n * @returns Option<NonNullable<T>>\n *\n * @example\n * ```ts\n * const workflow = Fx.gen(function* () {\n * const apiKey = yield* Fx.option(request.headers[\"x-api-key\"])\n * return apiKey\n * })\n * ```\n */\nconst fxOption = optionFromNullable\n\n// ============================================================================\n// Fx.match - Universal pattern matching\n// ============================================================================\n\n/**\n * Handler functions for matching on a tagged union by `_tag` discriminator.\n * Each handler receives the narrowed variant corresponding to its tag key.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * type Example = typeof Fx\n * ```\n */\nexport type TaggedMatch<T extends { readonly _tag: string }, R> = {\n readonly [K in T[\"_tag\"]]: (variant: Extract<T, { readonly _tag: K }>) => R\n}\n\n/**\n * Generic pattern matcher for any `_tag`-based discriminated union.\n *\n * Works with Exit, tagged errors, or any type with a `readonly _tag` discriminator.\n * Each handler receives the full narrowed variant object for its tag.\n *\n * Supports both data-first and data-last (pipe) calling styles.\n *\n * @example\n * ```ts\n * // Match on Exit\n * Fx.match(exit, {\n * Ok: (ok) => ok.value,\n * Err: (err) =>\n * Fx.match(err.error, {\n * DatabaseError: (e) => e.message,\n * NotFoundError: (e) => e.resourceId,\n * }),\n * Defect: (d) => String(d.defect),\n * })\n *\n * // Data-last with pipe\n * pipe(exit, Fx.match({\n * Ok: (ok) => ok.value,\n * Err: (err) => \"error\",\n * Defect: (d) => \"defect\",\n * }))\n * ```\n */\nconst fxMatch: {\n <T extends { readonly _tag: string }, R>(value: T, handlers: TaggedMatch<T, R>): R\n <T extends { readonly _tag: string }, R>(handlers: TaggedMatch<T, R>): (value: T) => R\n} = dual(\n 2,\n // oxlint-disable-next-line no-explicit-any\n (value: any, handlers: any): any => handlers[value._tag](value),\n)\n\n// ============================================================================\n// Exports\n// ============================================================================\n\n/**\n * Build typed computations from generator functions.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const program = Fx.gen(function* () {\n * const value = yield* Fx.ok(2)\n * return value + 1\n * })\n * const exit = Fx.run(program)\n * // => { _tag: \"Ok\", value: 3 }\n * ```\n */\nexport const gen = fxGen\n\n/**\n * Run a generator function immediately and return its `Exit`.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const exit = Fx.fn(function* () {\n * return yield* Fx.ok(2)\n * })\n * // => { _tag: \"Ok\", value: 2 }\n * ```\n */\nexport const fn = fxFn\n\n/**\n * Execute an existing `Fx` value and produce an `Exit`.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const exit = Fx.run(Fx.gen(function* () {\n * return 1\n * }))\n * // => { _tag: \"Ok\", value: 1 }\n * ```\n */\nexport const run = fxRun\n\n/**\n * Retry failed computations according to a schedule.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * import { Schedule } from \"@nicolastoulemont/std\"\n *\n * const retried = Fx.retry(\n * Fx.gen(function* () {\n * return yield* Fx.err(\"boom\")\n * }),\n * Schedule.recurs(2),\n * )\n * const exit = Fx.run(retried)\n * // => { _tag: \"Err\", error: \"boom\" }\n * ```\n */\nexport const retry = fxRetry\n\n/**\n * Run an effectful function for each item in a collection.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const fx = Fx.forEach([1, 2, 3], (n) => Fx.gen(function* () {\n * return n * 2\n * }))\n * // => AsyncFx<readonly number[], ...>\n * ```\n */\nexport const forEach = fxForEach\n\n/**\n * Alias for `Result.ok` in `Fx` namespace.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const value = Fx.ok(42)\n * // => { _tag: \"Ok\", value: 42 }\n * ```\n */\nexport const ok = fxOk\n\n/**\n * Alias for `Result.err` in `Fx` namespace.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const value = Fx.err(\"boom\")\n * // => { _tag: \"Err\", error: \"boom\" }\n * ```\n */\nexport const err = fxErr\n\n/**\n * Alias for `Option.fromNullable` in `Fx` namespace.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const value = Fx.option(\"token\")\n * // => { _tag: \"Some\", value: \"token\" }\n * ```\n */\nexport const option = fxOption\n\nconst try_ = fxTry\n\nexport {\n /**\n * Alias for `Result.fromTry` in `Fx` namespace.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const parsed = Fx.try(() => Number.parseInt(\"42\", 10))\n * // => { _tag: \"Ok\", value: 42 }\n * ```\n *\n */\n try_ as try,\n}\n\n/**\n * Pattern matching helper for tagged unions.\n *\n * @example\n * ```ts\n * import { Fx } from \"@nicolastoulemont/std\"\n *\n * const value = Fx.match({ _tag: \"Ok\", value: 2 } as const, {\n * Ok: (ok) => ok.value + 1,\n * })\n * // => 3\n * ```\n */\nexport const match = fxMatch\n\n/* oxlint-enable no-unsafe-type-assertion, no-unsafe-assignment, no-unsafe-call, no-unsafe-member-access, no-un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gB,OAAO,iBAAiB,EAG/B,CACL,KAAM,WACL,GAAW,CACV,OAAU,IAAA,GACV,OAAU,IAAA,GACV,OAAU,IAAA,GACX,CAED,OAAQ,OAAO,gBAAoD,CACjE,IAAMA,EAAM,GAAa,CACrB,EAAS,MAAMA,EAAI,MAAM,CAE7B,KAAO,EAAO,OAAS,IAAM,CAE3B,IAAM,EAAW,MAAM,EAAO,MAE9B,EAAS,MAAMA,EAAI,KAAK,EAAS,CAGnC,OAAO,EAAO,OAEjB,CAII,CACL,KAAM,UACL,GAAW,CACV,OAAU,IAAA,GACV,OAAU,IAAA,GACV,OAAU,IAAA,GACX,CAED,EAAE,OAAO,WAA0C,CACjD,IAAMA,EAAM,GAAa,CACrB,EAASA,EAAI,MAAM,CAEvB,KAAO,EAAO,OAAS,IAAM,CAC3B,IAAM,EAAW,MAAM,EAAO,MAC9B,EAASA,EAAI,KAAK,EAAS,CAG7B,OAAO,EAAO,OAEjB,CA8HH,SAAS,EACP,EACA,EACoD,CAKpD,IAAM,EAAK,EAAM,EAAmB,CAYpC,OAJS,EANL,GAGA,EAAG,KACE,EAA6D,EAAG,EAM5D,EAJoC,CA0BnD,MAAM,EAAOE,EAsBP,EAAQC,EAuBR,EAAQC,EAiBR,EAAWC,EAkDX,EAGF,EACF,GAEC,EAAY,IAAuB,EAAS,EAAM,MAAM,EAAM,CAChE,CAqBY,EAAM,EAeN,EAAK,EAeL,EAAM,EAqBN,EAAQ,EAeR,EAAU,EAaV,EAAK,EAaL,EAAM,EAaN,EAAS,EAEhB,EAAO,EA+BA,EAAQ"}
|
|
@@ -2,7 +2,7 @@ import { a as FxError, c as FxTypeId, d as FxYieldable, f as RunnableFx, h as is
|
|
|
2
2
|
import { a as ResultFromTry, m as Ok, p as Err, t as Result } from "./result.types-BKzChyWY.mjs";
|
|
3
3
|
import { r as Option } from "./option.types-D9hrKcfa.mjs";
|
|
4
4
|
import { t as Concurrency } from "./queue.types-B-l5XYbU.mjs";
|
|
5
|
-
import { n as SyncRetrySchedule, t as RetrySchedule } from "./schedule-
|
|
5
|
+
import { n as SyncRetrySchedule, t as RetrySchedule } from "./schedule-BzPjvMXc.mjs";
|
|
6
6
|
|
|
7
7
|
//#region src/fx/exit.d.ts
|
|
8
8
|
/**
|
|
@@ -455,4 +455,4 @@ declare const match: {
|
|
|
455
455
|
};
|
|
456
456
|
//#endregion
|
|
457
457
|
export { fx_d_exports as t };
|
|
458
|
-
//# sourceMappingURL=index-
|
|
458
|
+
//# sourceMappingURL=index-BD-els5J.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-
|
|
1
|
+
{"version":3,"file":"index-BD-els5J.d.mts","names":[],"sources":["../src/fx/exit.ts","../src/fx/fx.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;KAUK,MAAA;;;;AAToD;AA+BzD;;;;;;;AAmBuF;;;;;;;AAiGvF;;AA3GoC,KATxB,IASwB,CAAA,GAAA,EAAA,GAAA,CAAA,GATX,EASW,CATR,GASQ,CAAA,GATH,GASG,CATC,GASD,CAAA,GATM,MASN;;;;KAsC/B,SAT8B,CAAA,GAAA,EAAA,GAAA,EAAA,GAAA,CAAA,GAAA;EAAG,SAAA,EAAA,EAAA,CAAA,KAAA,EAUf,GAVe,EAAA,GAUT,GAVS;EAAR,SAAA,GAAA,EAAA,CAAA,KAAA,EAWN,GAXM,EAAA,GAWA,GAXA;EAAqB,SAAA,MAAA,EAAA,CAAA,MAAA,EAAA,OAAA,EAAA,GAYX,GAZW;CAoC5B;;;;AAA8B,cA0CxC,IA1CwC,EAAA;EAAG,SAAA,EAAA,EAAA,CAAA,GAAA,CAAA,CAAA,KAAA,EAjE3B,GAiE2B,EAAA,GAjEvB,EAiEuB,CAjEpB,GAiEoB,CAAA;EAAhB,SAAA,GAAA,EAAA,CAAA,GAAA,CAAA,CAAA,KAAA,EA5DV,GA4DU,EAAA,GA5DN,GA4DM,CA5DF,GA4DE,CAAA;EAAqB,SAAA,MAAA,EAAA,CAAA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;;;;;;iBAnYS,kCAA8B,iBAAiB,KAAG,cAAY,QAAQ,KAAS,KAAG;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2BlF,uCAAiC,0DACrB,YAAY,KAAG,KAAG,qBACtB,OAAO,KAAG,KAAG,SAAO,aAClC,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA4BN,uCAAiC,0DACrB,iBAAiB,KAAG,KAAG,qBAC3B,QAAQ,KAAG,KAAG,SAAO,aACnC,YAAY;;;;;;;;;;;;KA+HH;;2BACK,sBAAsB,QAAQ;iBAAoB;OAAS;;;;;;;;;;;;;;;;cA4D/D,YAAG;;;;;;;;;;;;;;cAeH,WAAE;;;;;;;;;;;;;;cAeF,YAAG;;;;;;;;;;;;;;;;;;;;cAqBH;gBAtiBC,iDAAiD,mBAAmB,gBAAc,IAAI,YAAY,MAAI;aACvG,yBACC,kBACG,2CAA2C,SAAO,YAAY,MAAI;;;;;;;;;;;;;;;cAkjBtE;;;;;;;;;;;;;;;;;;;;;;;;;;;cAaA,eAAE,MAAA,OAAA;;;;;;;;;;;;cAaF,kBAAG,QAAA,cAAA;;;;;;;;;;;;cAaH,mBAAM,MAAA,OAAA,YAAA;cAEb,MAAY;;;;;;;;;;;;;;cA+BL;;;iBArKqC,aAAa,YAAY,GAAG,OAAK;;;oBAC9B,YAAY,GAAG,eAAa,MAAM"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { h as Prettify, t as Result } from "./result.types-BKzChyWY.mjs";
|
|
2
|
-
import { c as ValidationError } from "./schema.types-
|
|
2
|
+
import { c as ValidationError } from "./schema.types-w1WK4kGS.mjs";
|
|
3
3
|
import { t as Discriminator } from "./discriminator.types-C-ygT2S1.mjs";
|
|
4
4
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
5
5
|
|
|
@@ -455,4 +455,4 @@ declare const variant: typeof variant$1;
|
|
|
455
455
|
declare const match: typeof match$1;
|
|
456
456
|
//#endregion
|
|
457
457
|
export { adt_d_exports as t };
|
|
458
|
-
//# sourceMappingURL=index-
|
|
458
|
+
//# sourceMappingURL=index-BaRJVkLo.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-
|
|
1
|
+
{"version":3,"file":"index-BaRJVkLo.d.mts","names":[],"sources":["../src/adt/adt.match.ts","../src/adt/adt.types.ts","../src/adt/adt.union.ts","../src/adt/adt.variant.ts","../src/adt/adt.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;KAOK,gBAAA,CAAA,UAAgB;EACb,SAAA,IAAA,EAAA,MAAA;CAA4B,EAAA,OAAA,CAAA,GAAA,QAA5B,CAAgD,CAAA,MAAA,CAAA,GAAA,CAAA,KAAA,EAA5B,OAA4B,CAApB,CAAoB,EAAA;EAA5B,SAAA,IAAA,EAA4B,CAA5B;AAAqC,CAAA,CAAA,EAAA,GAAA,OAAA,EAAO;AAsCxE;;;;;;;;;;;;;;ACTA;;;;;;;;AAcA;AAeA;;;;;AAMA;;;;;AAAuG;AAW5E;AAef,iBDpDI,OCoDK,CAAA,UAAA;EAAW,SAAA,IAAA,EAAA,MAAA;CACF,EAAA,OAAA,EAAA,iBDlDX,gBCkDW,CDlDM,CCkDN,EDlDS,OCkDT,CAAA,GDlDoB,gBCkDpB,CDlDqC,CCkDrC,EDlDwC,OCkDxC,CAAA,CAAA,CAAA,KAAA,EDjDrB,CCiDqB,EAAA,QAAA,EDjDR,QCiDQ,CAAA,EDjDG,OCiDH;;;;;;AA9D9B;;AAI+B,KAJnB,kBAImB,CAAA,cAAA,MAAA,EAAA,YAJ8B,gBAI9B,CAAA,GAJkD,MAIlD,CAAA,MAAA,EAAA;EAAf,EAAA,EAAA,CAAA,KAAA,EAAA,cAAA,CAAe,GAAf,CAAA,GAAoB,aAApB,CAAkC,KAAlC,CAAA,EAAA,GAAA,GAAA;EAAkC,IAAA,EAAA,CAAA,KAAA,EAAA,GAAA,EAAA,GAAA,GAAA;CAAd,CAAA;;;AAUpC;AAeA;AAAo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,gBF+BF,CAAA,CAAA,IAAA,EE/B0B,KF+B1B,EAAA,MAAA,EE/BuC,GF+BvC,CAAA,EE/B2C,UF+B3C,CE/BsD,KF+BtD,EE/B2D,GF+B3D,CAAA;AAAA;;;AAjCpD;;;;;AAMA;;;;;AAAuG;AAW5E;AAe3B;;;AACgB,KG1CJ,KH0CI,CAAA,CAAA,CAAA,GG1CO,QH0CP,CG1CoB,CH0CpB,CAAA;;;;;;;;;;;;;;AAchB;;AACiD,KGxCrC,YHwCqC,CAAA,CAAA,CAAA,GGxCnB,eHwCmB,CGxCC,CHwCD,CAAA;;;;;;;;;;;;;;;;AAMS,KG7B9C,SH6B8C,CAAA,CAAA,EAAA,YAAA,MAAA,CAAA,GG7Bb,YH6Ba,CG7BI,CH6BJ,EG7BO,GH6BP,CAAA;;;AAa1D;;;;;;;;;;;;;;AAkBwD,cG1C3C,KH0C2C,EAAA,OG1CtC,OH0CsC;;;;;;;;;;;;;;;;;AAqBxB,cG7CnB,OH6CmB,EAAA,OG7CZ,SH6CY;;;;;;;;;;AAmBhC;AAA2E;;;AAY/D,cG7DC,KH6DD,EAAA,OG7DM,OH6DN"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as Result } from "./result.types-BKzChyWY.mjs";
|
|
2
|
-
import { a as RefinementSchema, c as ValidationError, i as Refine, l as ValidationIssue, n as Input, o as SyncRefinementSchema, r as Output, s as SyncSchema, t as Infer } from "./schema.types-
|
|
2
|
+
import { a as RefinementSchema, c as ValidationError, i as Refine, l as ValidationIssue, n as Input, o as SyncRefinementSchema, r as Output, s as SyncSchema, t as Infer } from "./schema.types-w1WK4kGS.mjs";
|
|
3
3
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
4
4
|
|
|
5
5
|
//#region src/schema/schema.d.ts
|
|
@@ -14,44 +14,51 @@ declare namespace schema_d_exports {
|
|
|
14
14
|
*/
|
|
15
15
|
declare function parse<S extends SyncSchema>(schema: S): (value: Input<S>) => Result<Output<S>, ValidationError>;
|
|
16
16
|
declare function parse<S extends StandardSchemaV1>(schema: S): (value: Input<S>) => Promise<Result<Output<S>, ValidationError>>;
|
|
17
|
+
type RefineFn = {
|
|
18
|
+
<S extends SyncSchema, Base extends Input<S>>(value: Base, schema: S): value is Refine<Base, S>;
|
|
19
|
+
<S extends SyncSchema>(schema: S): <Base extends Input<S>>(value: Base) => value is Refine<Base, S>;
|
|
20
|
+
};
|
|
21
|
+
type Is = {
|
|
22
|
+
<Base, Sub extends Base>(value: Base, schema: SyncRefinementSchema<Base, Sub>): value is Sub;
|
|
23
|
+
<S extends SyncSchema>(value: unknown, schema: S): value is Output<S>;
|
|
24
|
+
<Base, Sub extends Base>(schema: SyncRefinementSchema<Base, Sub>): (value: Base) => value is Sub;
|
|
25
|
+
<S extends SyncSchema>(schema: S): (value: unknown) => value is Output<S>;
|
|
26
|
+
};
|
|
17
27
|
/**
|
|
18
|
-
* Create a sync-only schema-backed type guard that preserves the original value shape.
|
|
28
|
+
* Create a sync-only schema-backed reusable type guard that preserves the original value shape.
|
|
19
29
|
*
|
|
20
|
-
* Use this when a schema validates only a subset of a broader in-memory value
|
|
21
|
-
*
|
|
30
|
+
* Use this when a schema validates only a subset of a broader in-memory value
|
|
31
|
+
* and you need the preserved shape to survive higher-order APIs like
|
|
32
|
+
* `Array.filter`. The narrowed type is `Base & Output<typeof schema>`, not the
|
|
33
|
+
* exact schema output.
|
|
22
34
|
*
|
|
23
35
|
* Supports both data-first and data-last styles:
|
|
24
36
|
* - Data-first: `Schema.refine(value, schema)`
|
|
25
37
|
* - Data-last: `Schema.refine(schema)(value)`
|
|
26
38
|
*
|
|
27
|
-
* Only use this with sync schemas that
|
|
28
|
-
* original value. Transforms, defaults, and coercions are not
|
|
29
|
-
* they can change the schema output without changing the
|
|
39
|
+
* Only use this with sync proof schemas that validate properties already
|
|
40
|
+
* present on the original value. Transforms, defaults, and coercions are not
|
|
41
|
+
* safe here because they can change the schema output without changing the
|
|
42
|
+
* original input value.
|
|
30
43
|
*/
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
<S extends SyncSchema>(schema: S): <Base extends Input<S>>(value: Base) => value is Refine<Base, S>;
|
|
34
|
-
};
|
|
44
|
+
declare function refine<S extends SyncSchema, Base extends Input<S>>(value: Base, schema: S): value is Refine<Base, S>;
|
|
45
|
+
declare function refine<S extends SyncSchema>(schema: S): <Base extends Input<S>>(value: Base) => value is Refine<Base, S>;
|
|
35
46
|
/**
|
|
36
|
-
* Create a sync-only schema-backed
|
|
47
|
+
* Create a sync-only schema-backed proof guard.
|
|
37
48
|
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
49
|
+
* On `unknown` values this narrows to the exact schema output. On already-typed
|
|
50
|
+
* values, TypeScript preserves the current shape during direct control-flow
|
|
51
|
+
* checks. Use `Schema.refine` when that preserved shape must survive
|
|
52
|
+
* higher-order APIs like `Array.filter`.
|
|
42
53
|
*
|
|
43
54
|
* Supports both data-first and data-last styles:
|
|
44
55
|
* - Data-first: `Schema.is(value, schema)`
|
|
45
56
|
* - Data-last: `Schema.is(schema)(value)`
|
|
46
57
|
*/
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
<S extends SyncSchema>(schema: S): (value: unknown) => value is Output<S>;
|
|
52
|
-
};
|
|
53
|
-
declare const refine: RefineFn;
|
|
54
|
-
declare const is: Is;
|
|
58
|
+
declare function is<Base, Sub extends Base>(value: Base, schema: SyncRefinementSchema<Base, Sub>): value is Sub;
|
|
59
|
+
declare function is<S extends SyncSchema>(value: unknown, schema: S): value is Output<S>;
|
|
60
|
+
declare function is<Base, Sub extends Base>(schema: SyncRefinementSchema<Base, Sub>): (value: Base) => value is Sub;
|
|
61
|
+
declare function is<S extends SyncSchema>(schema: S): (value: unknown) => value is Output<S>;
|
|
55
62
|
//#endregion
|
|
56
63
|
export { schema_d_exports as t };
|
|
57
|
-
//# sourceMappingURL=index-
|
|
64
|
+
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D0D,GA1D1D,CAAA,CAAA,EAAA,KAAA,IA0D0E,GA1D1E;AAAwB,iBA2DzC,EA3DyC,CAAA,UA2D5B,UA3D4B,CAAA,CAAA,KAAA,EAAA,OAAA,EAAA,MAAA,EA2DQ,CA3DR,CAAA,EAAA,KAAA,IA2DqB,MA3DrB,CA2D4B,CA3D5B,CAAA;AAAN,iBA4DnC,EA5DmC,CAAA,IAAA,EAAA,YA4Dd,IA5Dc,CAAA,CAAA,MAAA,EA4DA,oBA5DA,CA4DqB,IA5DrB,EA4D2B,GA5D3B,CAAA,CAAA,EAAA,CAAA,KAAA,EA4D0C,IA5D1C,EAAA,GAAA,KAAA,IA4D4D,GA5D5D;AAAiB,iBA6DpD,EA7DoD,CAAA,UA6DvC,UA7DuC,CAAA,CAAA,MAAA,EA6DnB,CA7DmB,CAAA,EAAA,CAAA,KAAA,EAAA,OAAA,EAAA,GAAA,KAAA,IA6Dc,MA7Dd,CA6DqB,CA7DrB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-BqJ1GWAF.d.mts","names":[],"sources":["../src/option/option.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;cA0Da,2BAAkB;;;;;;;;;;AAA/B;AAYY,KAAA,kBAAA,GAAqB,YAAoB,CAAA,OAAA,oBAAR,CAAA;AAY7C;AAsBA;;;;;AA4BA;AAgCA;;;AAA+E,KAlFnE,MAkFmE,CAAA,CAAA,CAAA,GAlFvD,QAkFuD,CAlF5C,CAkF4C,CAAA;;;;AAc/E;;;;;;;AAmCA;AAsCA;AAsCA;AAsCA;AA4Ba,cA3PA,
|
|
1
|
+
{"version":3,"file":"index-BqJ1GWAF.d.mts","names":[],"sources":["../src/option/option.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;cA0Da,2BAAkB;;;;;;;;;;AAA/B;AAYY,KAAA,kBAAA,GAAqB,YAAoB,CAAA,OAAA,oBAAR,CAAA;AAY7C;AAsBA;;;;;AA4BA;AAgCA;;;AAA+E,KAlFnE,MAkFmE,CAAA,CAAA,CAAA,GAlFvD,QAkFuD,CAlF5C,CAkF4C,CAAA;;;;AAc/E;;;;;;;AAmCA;AAsCA;AAsCA;AAsCA;AA4Ba,cA3PA,IA8PX,EAHmB,CAAA,CAAA,CAAA,CAAA,KAAA,EA3PU,CA8P7B,EAAA,GA9PiC,QA8PjC,CA9P4C,CA8P5C,CAAA;AAyBF;AAgDA;AA2BA;AAiCA;AAyCA;;;;;;AA2BA;;;AAAyC,cA3a5B,IA2a4B,EAAA,CAAA,IAAA,KAAA,CAAA,GAAA,GA3aN,QA2aM,CA3aK,CA2aL,CAAA;;;;;;;;;;;;;;;cA3Y5B,oBAAqB,SAAW,iBAAe,QAAQ,SAAW;;;;;;;;;;;;;;cAclE,oBAAqB,SAAW,iBAAe,QAAQ,SAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAmClE,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAsCL,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAsCT,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAsCL,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;cA4BR,QAAQ;;;;;;;;;;;;;;;;;;;cA4BR,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;cAgDL,UAAU;;;;;;;;;;;;;;;;;;;;;;;cA2BV,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAiCd,OAAO;;;;;;;;;;;;cAyCP,yBAA0B,MAAI,SAAW,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;cA2BrD,uBAAwB,MAAI,cAAc"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as TaggedErrorFactory } from "./index-
|
|
1
|
+
import { n as TaggedErrorFactory } from "./index-D6pjHqlK.mjs";
|
|
2
2
|
import { i as QueueOptions, n as Queue, r as QueueBoundedOptions } from "./queue.types-B-l5XYbU.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/queue/queue.d.ts
|
|
@@ -104,4 +104,4 @@ declare const bounded: (maxSize: number, options?: QueueBoundedOptions) => Queue
|
|
|
104
104
|
declare const unbounded: (options?: QueueOptions) => Queue;
|
|
105
105
|
//#endregion
|
|
106
106
|
export { queue_d_exports as t };
|
|
107
|
-
//# sourceMappingURL=index-
|
|
107
|
+
//# sourceMappingURL=index-CVmgBpDt.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-
|
|
1
|
+
{"version":3,"file":"index-CVmgBpDt.d.mts","names":[],"sources":["../src/queue/queue.ts"],"sourcesContent":[],"mappings":";;;;;;;cAsCsB,uBAAA;;;;;;;;;;;;cAcT,gBAAA,SAAyB;;;cAA0E,wBAAA;;;;;;;;;;;;cAYnG,iBAAA,SAA0B;;;cAA8D,4BAAA;;;;;;;;;;;;cAYxF,qBAAA,SAA8B;;;;;;;;;;;;;;;cAoG9B,iCAAgC;;;;;;;;;;;;;cAoWhC,iBAAkB,iBAAe;;;;;;;;;;;;;cAcjC,qCAAsC,wBAAsB;;;;;;;;;;;;;cAc5D,sBAAuB,iBAAe"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { i as Fx } from "./fx.types-BdN1EWxr.mjs";
|
|
2
|
+
import { t as Result } from "./result.types-BKzChyWY.mjs";
|
|
3
|
+
import { c as ValidationError, n as Input, r as Output, s as SyncSchema } from "./schema.types-w1WK4kGS.mjs";
|
|
2
4
|
import { t as Discriminator } from "./discriminator.types-C-ygT2S1.mjs";
|
|
3
5
|
|
|
4
6
|
//#region src/data/data.types.d.ts
|
|
@@ -116,6 +118,36 @@ type ArrayValue<out T> = {
|
|
|
116
118
|
*/
|
|
117
119
|
declare function array$1<T>(items: readonly T[]): ArrayValue<T>;
|
|
118
120
|
//#endregion
|
|
121
|
+
//#region src/data/data.entity.d.ts
|
|
122
|
+
type EntitySchema<TInput = unknown, TOutput extends Record<string, unknown> = Record<string, unknown>> = SyncSchema<TInput, TOutput>;
|
|
123
|
+
type EntityConstructor<S extends EntitySchema> = (input: Input<S>) => Result<StructValue<Output<S>>, ValidationError>;
|
|
124
|
+
/**
|
|
125
|
+
* Create a sync schema-backed constructor for untagged entity objects.
|
|
126
|
+
*
|
|
127
|
+
* The constructor validates through the provided schema, then wraps the
|
|
128
|
+
* validated object with `Data.struct()` so the result is frozen and gains
|
|
129
|
+
* structural `equals()` and `hash()` behavior.
|
|
130
|
+
*
|
|
131
|
+
* Defaults and output shaping should be defined at the schema level.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* import { Data } from "@nicolastoulemont/std"
|
|
136
|
+
* import { z } from "zod"
|
|
137
|
+
*
|
|
138
|
+
* const User = Data.entity(
|
|
139
|
+
* z.object({
|
|
140
|
+
* id: z.string(),
|
|
141
|
+
* role: z.string().default("member"),
|
|
142
|
+
* }),
|
|
143
|
+
* )
|
|
144
|
+
*
|
|
145
|
+
* const user = User({ id: "u1" })
|
|
146
|
+
* // => { _tag: "Ok", value: { id: "u1", role: "member" } }
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
declare function entity$1<S extends EntitySchema>(schema: S): EntityConstructor<S>;
|
|
150
|
+
//#endregion
|
|
119
151
|
//#region src/data/data.struct.d.ts
|
|
120
152
|
/**
|
|
121
153
|
* Create a frozen value object with structural equality.
|
|
@@ -289,7 +321,7 @@ declare function TaggedError$1<Tag extends string>(tag: Tag): TaggedErrorFactory
|
|
|
289
321
|
*/
|
|
290
322
|
declare function tuple$1<T extends readonly unknown[]>(...args: T): TupleValue<T>;
|
|
291
323
|
declare namespace data_d_exports {
|
|
292
|
-
export { TaggedError, TaggedErrorClass, TaggedErrorFactory, TaggedErrorInstance, array, struct, tagged, tuple };
|
|
324
|
+
export { ArrayValue, StructValue, TaggedConstructor, TaggedError, TaggedErrorClass, TaggedErrorCore, TaggedErrorFactory, TaggedErrorInstance, TaggedValue, TupleValue, array, entity, struct, tagged, tuple };
|
|
293
325
|
}
|
|
294
326
|
/**
|
|
295
327
|
* Construct tagged data objects.
|
|
@@ -317,6 +349,20 @@ declare const tagged: typeof tagged$1;
|
|
|
317
349
|
* ```
|
|
318
350
|
*/
|
|
319
351
|
declare const TaggedError: typeof TaggedError$1;
|
|
352
|
+
/**
|
|
353
|
+
* Construct sync schema-backed entities with structural value semantics.
|
|
354
|
+
*
|
|
355
|
+
* @example
|
|
356
|
+
* ```ts
|
|
357
|
+
* import { Data } from "@nicolastoulemont/std"
|
|
358
|
+
* import { z } from "zod"
|
|
359
|
+
*
|
|
360
|
+
* const User = Data.entity(z.object({ id: z.string() }))
|
|
361
|
+
* const result = User({ id: "u1" })
|
|
362
|
+
* // => { _tag: "Ok", value: { id: "u1" } }
|
|
363
|
+
* ```
|
|
364
|
+
*/
|
|
365
|
+
declare const entity: typeof entity$1;
|
|
320
366
|
/**
|
|
321
367
|
* Construct immutable-like structs with stable structural behavior.
|
|
322
368
|
*
|
|
@@ -358,4 +404,4 @@ declare const tuple: typeof tuple$1;
|
|
|
358
404
|
declare const array: typeof array$1;
|
|
359
405
|
//#endregion
|
|
360
406
|
export { TaggedErrorFactory as n, data_d_exports as t };
|
|
361
|
-
//# sourceMappingURL=index-
|
|
407
|
+
//# sourceMappingURL=index-D6pjHqlK.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-D6pjHqlK.d.mts","names":[],"sources":["../src/data/data.types.ts","../src/data/data.array.ts","../src/data/data.entity.ts","../src/data/data.struct.ts","../src/data/data.tagged.ts","../src/data/data.tagged-error.types.ts","../src/data/data.tagged-error.ts","../src/data/data.tuple.ts","../src/data/data.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;KAUY,qCAAqC,SAAS,KAAK,cAAc;;AAA7E;;;;AAA+D,KAOnD,iBAPmD,CAAA,YAAA,MAAA,EAAA,CAAA,CAAA,GAAA;EAAa;EAOhE,SAAA,IAAA,EAEK,GAFL;EAEK;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