better-effect 0.13.0 → 0.14.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 +337 -88
- package/dist/adapters/iti.d.mts +2 -3
- package/dist/adapters/iti.d.mts.map +1 -1
- package/dist/adapters/iti.mjs +2 -2
- package/dist/bun.d.mts +75 -23
- package/dist/bun.d.mts.map +1 -1
- package/dist/bun.mjs +170 -33
- package/dist/bun.mjs.map +1 -1
- package/dist/{context-BphfFUMO.mjs → context-DSGSqcJj.mjs} +12 -3
- package/dist/context-DSGSqcJj.mjs.map +1 -0
- package/dist/{current-request-DDKNyymv.mjs → current-request-Bc1YHL0w.mjs} +3 -2
- package/dist/{current-request-DDKNyymv.mjs.map → current-request-Bc1YHL0w.mjs.map} +1 -1
- package/dist/{current-request-CIU7AHhF.d.mts → current-request-Dm-QQ3Xr.d.mts} +4 -4
- package/dist/current-request-Dm-QQ3Xr.d.mts.map +1 -0
- package/dist/{effect-CPdV7Yv8.mjs → effect-W0IQXY8P.mjs} +21 -2
- package/dist/effect-W0IQXY8P.mjs.map +1 -0
- package/dist/{errors-BKcsQ0ip.d.mts → errors-CpHMzPiP.d.mts} +6 -2
- package/dist/errors-CpHMzPiP.d.mts.map +1 -0
- package/dist/hono.d.mts +63 -27
- package/dist/hono.d.mts.map +1 -1
- package/dist/hono.mjs +111 -45
- package/dist/hono.mjs.map +1 -1
- package/dist/{index-CCi07kUw.d.mts → index-3Bkl-sxS.d.mts} +7 -2
- package/dist/{index-CCi07kUw.d.mts.map → index-3Bkl-sxS.d.mts.map} +1 -1
- package/dist/{index-cXgyMa0v.d.mts → index-C2ed9Ilq.d.mts} +32 -7
- package/dist/index-C2ed9Ilq.d.mts.map +1 -0
- package/dist/{index-BodMy6rO.d.mts → index-ClNndn2-.d.mts} +93 -63
- package/dist/index-ClNndn2-.d.mts.map +1 -0
- package/dist/{index-DAKn0qHk.d.mts → index-Cy1VsU-u.d.mts} +2 -4
- package/dist/index-Cy1VsU-u.d.mts.map +1 -0
- package/dist/index.d.mts +6 -8
- package/dist/index.mjs +8 -9
- package/dist/index.mjs.map +1 -1
- package/dist/{internal-identity-CbXoZIfw.mjs → internal-identity-BuHBtP0k.mjs} +2 -2
- package/dist/{internal-identity-CbXoZIfw.mjs.map → internal-identity-BuHBtP0k.mjs.map} +1 -1
- package/dist/layer-2kjHVv4N.mjs +343 -0
- package/dist/layer-2kjHVv4N.mjs.map +1 -0
- package/dist/layer-C2OaqTmB.d.mts +987 -0
- package/dist/layer-C2OaqTmB.d.mts.map +1 -0
- package/dist/next.d.mts +102 -26
- package/dist/next.d.mts.map +1 -1
- package/dist/next.mjs +157 -40
- package/dist/next.mjs.map +1 -1
- package/dist/{node-context-DczjAcrX.d.mts → node-context-1YEjrU9g.d.mts} +2 -2
- package/dist/{node-context-DczjAcrX.d.mts.map → node-context-1YEjrU9g.d.mts.map} +1 -1
- package/dist/{node-context-Ca18oNSg.mjs → node-context-g3bCcY9t.mjs} +2 -2
- package/dist/{node-context-Ca18oNSg.mjs.map → node-context-g3bCcY9t.mjs.map} +1 -1
- package/dist/node.d.mts +11 -6
- package/dist/node.d.mts.map +1 -1
- package/dist/node.mjs +156 -10
- package/dist/node.mjs.map +1 -1
- package/dist/opentelemetry.d.mts +20 -2
- package/dist/opentelemetry.d.mts.map +1 -1
- package/dist/opentelemetry.mjs +423 -5
- package/dist/opentelemetry.mjs.map +1 -1
- package/dist/{registration-drnZk0SY.mjs → registration-Bwe2GbVu.mjs} +8 -2
- package/dist/registration-Bwe2GbVu.mjs.map +1 -0
- package/dist/runtime/explicit.d.mts +2 -2
- package/dist/runtime/explicit.mjs +1 -1
- package/dist/runtime/node.d.mts +3 -3
- package/dist/runtime/node.mjs +2 -2
- package/dist/runtime-qpcVwaz_.mjs +1680 -0
- package/dist/runtime-qpcVwaz_.mjs.map +1 -0
- package/dist/service-CO9VJQYa.mjs +74 -0
- package/dist/service-CO9VJQYa.mjs.map +1 -0
- package/dist/{signal-nfgFyNCk.mjs → signal-5Rg9bUUe.mjs} +2 -2
- package/dist/{signal-nfgFyNCk.mjs.map → signal-5Rg9bUUe.mjs.map} +1 -1
- package/dist/{standard-services-vnGIafkS.mjs → standard-services-B-iMM_W7.mjs} +38 -4
- package/dist/standard-services-B-iMM_W7.mjs.map +1 -0
- package/dist/standard-services.d.mts +4 -4
- package/dist/standard-services.mjs +3 -3
- package/dist/testing.d.mts +25 -7
- package/dist/testing.d.mts.map +1 -1
- package/dist/testing.mjs +51 -7
- package/dist/testing.mjs.map +1 -1
- package/dist/{types-oihI-ESv.d.mts → types-BFTqCCcw.d.mts} +32 -5
- package/dist/types-BFTqCCcw.d.mts.map +1 -0
- package/dist/web-effect-B9hp9jIe.mjs +380 -0
- package/dist/web-effect-B9hp9jIe.mjs.map +1 -0
- package/dist/web.d.mts +22 -13
- package/dist/web.d.mts.map +1 -1
- package/dist/web.mjs +1 -1
- package/package.json +10 -16
- package/dist/context-BphfFUMO.mjs.map +0 -1
- package/dist/current-request-CIU7AHhF.d.mts.map +0 -1
- package/dist/disposable-CP-Q2H3l.mjs +0 -57
- package/dist/disposable-CP-Q2H3l.mjs.map +0 -1
- package/dist/effect-CPdV7Yv8.mjs.map +0 -1
- package/dist/errors-BKcsQ0ip.d.mts.map +0 -1
- package/dist/index-AiKM71-u.d.mts +0 -376
- package/dist/index-AiKM71-u.d.mts.map +0 -1
- package/dist/index-BodMy6rO.d.mts.map +0 -1
- package/dist/index-DAKn0qHk.d.mts.map +0 -1
- package/dist/index-cXgyMa0v.d.mts.map +0 -1
- package/dist/layer-D16GKxuX.mjs +0 -269
- package/dist/layer-D16GKxuX.mjs.map +0 -1
- package/dist/observer-9nhbL7Pr.d.mts +0 -68
- package/dist/observer-9nhbL7Pr.d.mts.map +0 -1
- package/dist/outcome-DI8LPIQ4.d.mts +0 -387
- package/dist/outcome-DI8LPIQ4.d.mts.map +0 -1
- package/dist/program-metadata-BxjGkT17.mjs +0 -260
- package/dist/program-metadata-BxjGkT17.mjs.map +0 -1
- package/dist/registration-drnZk0SY.mjs.map +0 -1
- package/dist/runtime-C_55ofnL.mjs +0 -791
- package/dist/runtime-C_55ofnL.mjs.map +0 -1
- package/dist/standard-services-vnGIafkS.mjs.map +0 -1
- package/dist/types-oihI-ESv.d.mts.map +0 -1
- package/dist/web-Bq3MfMrj.mjs +0 -147
- package/dist/web-Bq3MfMrj.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effect-W0IQXY8P.mjs","names":["map","mapError","andThen","next","resultMatchError","resultMatchErrorPartial","tap","tapError","matchError","matchErrorPartial","recover","programMap","programMapError","programAndThen","programTap","programTapError","programRecover"],"sources":["../src/effect/task.ts","../src/effect/combinators.ts","../src/effect/program-combinators.ts","../src/effect/program-scheduler.ts","../src/effect/effect.ts"],"sourcesContent":["import { Result } from 'better-result'\n\nimport type { Result as ResultType } from 'better-result'\n\nimport { RuntimeContextNotConfiguredError } from '../runtime/errors'\nimport { currentRuntimeContext } from '../runtime/context'\nimport { getRuntimeTaskSupervisor } from '../runtime/task'\nimport type { AnyService } from '../service'\nimport type { ScopeCloseError } from '../scope'\n\nimport type {\n Effect as EffectType,\n EffectError,\n EffectRequirements,\n EffectSuccess,\n Program\n} from './types'\n\ntype AnyProgram = Program<any, any, AnyService>\n\n/** The live state of a Scope-owned task. */\nexport type ScopedTaskState = 'running' | 'succeeded' | 'failed' | 'defected' | 'interrupted'\n\n/** The terminal observation of a Scope-owned task. */\nexport type ScopedTaskExit<A, E> =\n | {\n readonly status: 'succeeded'\n readonly value: A\n readonly cleanupFailure?: ScopeCloseError\n }\n | {\n readonly status: 'failed'\n readonly error: E\n readonly cleanupFailure?: ScopeCloseError\n }\n | {\n readonly status: 'defected'\n readonly cause: unknown\n readonly cleanupFailure?: ScopeCloseError\n }\n | {\n readonly status: 'interrupted'\n readonly reason: unknown\n readonly cleanupFailure?: ScopeCloseError\n }\n\n/** A small, immutable handle for a task owned by the current Scope. */\nexport type ScopedTask<out A, out E> = {\n readonly state: ScopedTaskState\n await(): Promise<ResultType<A, E>>\n awaitExit(): Promise<ScopedTaskExit<A, E>>\n // oxlint-disable-next-line anti-slop/no-unknown-parameters -- Task interruption preserves arbitrary caller-defined reasons.\n interrupt(reason?: unknown): Promise<void>\n}\n\n/** Start a nominal Program as a child task supervised by the current Scope. */\nexport function forkScoped<Input extends AnyProgram>(\n program: Input\n): EffectType<\n ScopedTask<EffectSuccess<Input>, EffectError<Input>>,\n never,\n EffectRequirements<Input>\n> {\n const context = currentRuntimeContext()\n const resolver = context.resolver\n const scope = context.scope\n\n if (!resolver || !scope) {\n throw new RuntimeContextNotConfiguredError()\n }\n\n const supervisor = getRuntimeTaskSupervisor(scope)\n\n if (!supervisor) {\n throw new RuntimeContextNotConfiguredError()\n }\n\n // SAFETY: Result.ok supplies the runtime Result value; the Effect requirement channel is declaration-only and restored by this cast.\n return Result.ok(supervisor.forkScoped(program, { ...context, resolver, scope })) as EffectType<\n ScopedTask<EffectSuccess<Input>, EffectError<Input>>,\n never,\n EffectRequirements<Input>\n >\n}\n","import {\n matchError as resultMatchError,\n matchErrorPartial as resultMatchErrorPartial,\n Result\n} from 'better-result'\n\nimport type { Result as ResultType } from 'better-result'\n\nimport type { AnyService } from '../service'\nimport { isPromiseLike } from '../utils/runtime'\nimport type { Effect, EffectError, EffectRequirements, EffectSuccess } from './types'\n\ntype EffectInput<A, E> = ResultType<A, E> | PromiseLike<ResultType<A, E>>\n\ntype AnyEffectInput = EffectInput<any, any>\ntype AnyEffectValue = ResultType<any, any>\ntype AnyAsyncEffectInput = PromiseLike<ResultType<any, any>>\ntype CombinatorCallback = (value: any) => any\ntype CombinatorInput = AnyEffectInput | CombinatorCallback\n\ntype PreserveAsync<Input, Output> = Input extends PromiseLike<unknown> ? Promise<Output> : Output\n\ntype MappedResult<Input, B> = Effect<B, EffectError<Input>, EffectRequirements<Input>>\n\ntype ErrorMappedResult<Input, E2> = Effect<EffectSuccess<Input>, E2, EffectRequirements<Input>>\n\ntype ChainedResult<First, Next> = Effect<\n EffectSuccess<Next>,\n EffectError<First> | EffectError<Next>,\n EffectRequirements<First> | EffectRequirements<Next>\n>\n\ntype ChainedOutput<First, Next> = ChainedResult<First, Next>\n\ntype AsyncChainedOutput<First, Next> = Promise<ChainedResult<First, Next>>\n\ntype MapOperation<A, B> = {\n <Input>(effect: Input & EffectInput<A, any>): PreserveAsync<Input, MappedResult<Input, B>>\n}\n\ntype MapErrorOperation<E1, E2> = {\n <Input>(effect: Input & EffectInput<any, E1>): PreserveAsync<Input, ErrorMappedResult<Input, E2>>\n}\n\ntype AndThenOperation<Next> = {\n <Input>(effect: Input & AnyEffectValue): ChainedOutput<Input, Next>\n}\n\ntype AndThenAsyncOperation<A, Next> = {\n <Input>(effect: Input & EffectInput<A, any>): AsyncChainedOutput<Input, Next>\n}\n\ntype TappedResult<Input> = Effect<\n EffectSuccess<Input>,\n EffectError<Input>,\n EffectRequirements<Input>\n>\n\ntype RecoveredResult<Input, Next> = Effect<\n EffectSuccess<Input> | EffectSuccess<Next>,\n EffectError<Next>,\n EffectRequirements<Input> | EffectRequirements<Next>\n>\n\ntype FlattenedResult<Input> = Effect<\n EffectSuccess<EffectSuccess<Input>>,\n EffectError<Input> | EffectError<EffectSuccess<Input>>,\n EffectRequirements<Input> | EffectRequirements<EffectSuccess<Input>>\n>\n\ntype AsResult<Input, Value> = Effect<Value, EffectError<Input>, EffectRequirements<Input>>\n\ntype MatchedResult<Input, OkResult, ErrResult> = Effect<\n EffectSuccess<OkResult> | EffectSuccess<ErrResult>,\n EffectError<OkResult> | EffectError<ErrResult>,\n EffectRequirements<Input> | EffectRequirements<OkResult> | EffectRequirements<ErrResult>\n>\n\ntype AllResult<Results extends readonly AnyEffectValue[]> = Effect<\n { -readonly [Index in keyof Results]: EffectSuccess<Results[Index]> },\n EffectError<Results[number]>,\n EffectRequirements<Results[number]>\n>\n\ntype ZipResult<Left, Right> = Effect<\n [EffectSuccess<Left>, EffectSuccess<Right>],\n EffectError<Left> | EffectError<Right>,\n EffectRequirements<Left> | EffectRequirements<Right>\n>\n\ntype TapOperation = {\n <Input>(\n effect: Input & AnyEffectInput,\n fn: (value: EffectSuccess<Input>) => void\n ): PreserveAsync<Input, TappedResult<Input>>\n}\n\ntype TapErrorOperation = {\n <Input>(\n effect: Input & AnyEffectInput,\n fn: (error: EffectError<Input>) => void\n ): PreserveAsync<Input, TappedResult<Input>>\n}\n\ntype TapBothOperation = {\n <Input>(\n effect: Input & AnyEffectInput,\n handlers: {\n ok: (value: EffectSuccess<Input>) => void\n err: (error: EffectError<Input>) => void\n }\n ): PreserveAsync<Input, TappedResult<Input>>\n}\n\ntype TapAsyncOperation = {\n <Input>(effect: Input & AnyEffectInput): Promise<TappedResult<Input>>\n}\n\ntype TapErrorAsyncOperation = {\n <Input>(effect: Input & AnyEffectInput): Promise<TappedResult<Input>>\n}\n\ntype TapBothAsyncOperation = {\n <Input>(effect: Input & AnyEffectInput): Promise<TappedResult<Input>>\n}\n\ntype TaggedErrorLike = Error & { readonly _tag: string }\n\ntype TaggedErrorHandlers<ErrorValue extends TaggedErrorLike> = {\n // oxlint-disable-next-line anti-slop/no-unknown-returns -- better-result matchers allow arbitrary handler results.\n [Tag in ErrorValue['_tag']]: (error: Extract<ErrorValue, { readonly _tag: Tag }>) => unknown\n}\n\ntype TaggedErrorOf<Input> = Extract<EffectError<Input>, TaggedErrorLike>\n\ntype TaggedErrorHandlersFor<Input> = [EffectError<Input>] extends [TaggedErrorLike]\n ? TaggedErrorHandlers<TaggedErrorOf<Input>>\n : never\n\ntype HandlerReturn<Handlers> = {\n [Key in keyof Handlers]-?: NonNullable<Handlers[Key]> extends (error: never) => infer Return\n ? Return\n : never\n}[keyof Handlers]\n\ntype RequiredHandlerKeys<Handlers> = {\n [Key in keyof Handlers]-?: {} extends Pick<Handlers, Key>\n ? never\n : undefined extends Handlers[Key]\n ? never\n : Key\n}[keyof Handlers]\n\ntype UnhandledTaggedErrors<ErrorValue extends TaggedErrorLike, Handlers> = Exclude<\n ErrorValue,\n { readonly _tag: Extract<RequiredHandlerKeys<Handlers>, ErrorValue['_tag']> }\n>\n\ntype MatchErrorResult<Input, Handlers> = Effect<\n EffectSuccess<Input>,\n HandlerReturn<Handlers>,\n EffectRequirements<Input>\n>\n\ntype MatchErrorPartialResult<Input, Handlers> = Effect<\n EffectSuccess<Input>,\n HandlerReturn<Handlers> | UnhandledTaggedErrors<TaggedErrorOf<Input>, Handlers>,\n EffectRequirements<Input>\n>\n\ntype RecoverOperation<Next> = {\n <Input>(\n effect: Input & AnyEffectInput,\n fn: (error: EffectError<Input>) => Next\n ): PreserveAsync<Input, RecoveredResult<Input, Next>>\n}\n\ntype RecoverAsyncOperation<Next> = {\n <Input>(\n effect: Input & AnyEffectInput,\n fn: (error: EffectError<Input>) => Next\n ): Promise<RecoveredResult<Input, Next>>\n}\n\nconst asResult = <Value>(value: Value): ResultType<any, any> => {\n // SAFETY: Effect is the declaration-only Result facade, so every runtime value is a Result.\n return value as ResultType<any, any>\n}\n\nconst mapResult = <A, B, E, Requirements extends AnyService>(\n result: ResultType<A, E>,\n fn: (value: A) => B\n): Effect<B, E, Requirements> => {\n // SAFETY: Result.map changes only the success channel; the declaration-only Effect marker is restored by this adapter.\n return Result.map(result, fn) as Effect<B, E, Requirements>\n}\n\nconst mapErrorResult = <A, E1, E2, Requirements extends AnyService>(\n result: ResultType<A, E1>,\n fn: (error: E1) => E2\n): Effect<A, E2, Requirements> => {\n // SAFETY: Result.mapError changes only the error channel; the declaration-only Effect marker is restored by this adapter.\n return Result.mapError(result, fn) as Effect<A, E2, Requirements>\n}\n\nconst andThenResult = <\n A,\n B,\n E1,\n E2,\n Requirements1 extends AnyService,\n Requirements2 extends AnyService\n>(\n result: ResultType<A, E1>,\n next: (value: A) => ResultType<B, E2>\n): Effect<B, E1 | E2, Requirements1 | Requirements2> => {\n // SAFETY: The public callback returns an Effect, whose only runtime contract is the underlying Result.\n const resultNext = next as (value: A) => ResultType<B, E2>\n\n // SAFETY: Result.andThen unions Result errors; the declaration-only Effect marker is restored by this adapter.\n return Result.andThen(result, resultNext) as Effect<B, E1 | E2, Requirements1 | Requirements2>\n}\n\nconst andThenAsyncResult = <\n A,\n B,\n E1,\n E2,\n Requirements1 extends AnyService,\n Requirements2 extends AnyService\n>(\n result: ResultType<A, E1>,\n next: (value: A) => PromiseLike<ResultType<B, E2>>\n): Promise<Effect<B, E1 | E2, Requirements1 | Requirements2>> => {\n // SAFETY: The public callback returns an Effect, whose only runtime contract is the underlying Result.\n const resultNext = (value: A) => {\n // SAFETY: Promise resolution preserves the callback's Result value; only declaration-only Effect metadata is erased.\n return Promise.resolve(next(value)) as Promise<ResultType<B, E2>>\n }\n\n // SAFETY: Result.andThenAsync unions Result errors; the declaration-only Effect marker is restored by this adapter.\n return Result.andThenAsync(result, resultNext) as Promise<\n Effect<B, E1 | E2, Requirements1 | Requirements2>\n >\n}\n\n/**\n * Map the successful value of a Result or Effect result.\n *\n * Supports both data-first and data-last forms and preserves asynchronous\n * results and declaration-only Service requirements.\n *\n * @example\n * ```ts\n * const doubled = Effect.map(Result.ok(2), (value) => value * 2)\n * const toLabel = Effect.map((value: number) => `#${value}`)\n * ```\n */\nexport function map<A, B>(fn: (value: A) => B): MapOperation<A, B>\nexport function map<Input, B>(\n effect: Input & AnyEffectInput,\n fn: (value: EffectSuccess<Input>) => B\n): PreserveAsync<Input, MappedResult<Input, B>>\nexport function map(first: CombinatorInput, second?: CombinatorCallback): any {\n if (first instanceof Function && second === undefined) {\n // SAFETY: The curried overload accepts a unary mapping callback in this branch.\n const callback = first as CombinatorCallback\n\n return (effect: AnyEffectInput) => {\n // SAFETY: The overload implementation has already established the callback and Effect input positions.\n return map(effect as never, callback as never)\n }\n }\n\n // SAFETY: The data-first overload requires the second argument to be a unary mapping callback.\n const fn = second as CombinatorCallback\n\n if (isPromiseLike(first)) {\n return Promise.resolve(first).then((result) => {\n // SAFETY: Result is the runtime representation shared by Effect and better-result.\n return mapResult(result as ResultType<any, any>, fn)\n })\n }\n\n // SAFETY: The data-first overload supplies a Result-compatible Effect value.\n return mapResult(first as ResultType<any, any>, fn)\n}\n\n/**\n * Map the error value of a Result or Effect result while preserving its\n * successful value, asynchronous shape, and declaration-only Service requirements.\n *\n * @example\n * ```ts\n * const labelled = Effect.mapError(Result.err('missing'), (error) => ({ error }))\n * ```\n */\nexport function mapError<E1, E2>(fn: (error: E1) => E2): MapErrorOperation<E1, E2>\nexport function mapError<Input, E2>(\n effect: Input & AnyEffectInput,\n fn: (error: EffectError<Input>) => E2\n): PreserveAsync<Input, ErrorMappedResult<Input, E2>>\nexport function mapError(first: CombinatorInput, second?: CombinatorCallback): any {\n if (first instanceof Function && second === undefined) {\n // SAFETY: The curried overload accepts a unary error-mapping callback in this branch.\n const callback = first as CombinatorCallback\n\n return (effect: AnyEffectInput) => {\n // SAFETY: The overload implementation has already established the callback and Effect input positions.\n return mapError(effect as never, callback as never)\n }\n }\n\n // SAFETY: The data-first overload requires the second argument to be a unary error-mapping callback.\n const fn = second as CombinatorCallback\n\n if (isPromiseLike(first)) {\n return Promise.resolve(first).then((result) => {\n // SAFETY: Result is the runtime representation shared by Effect and better-result.\n return mapErrorResult(result as ResultType<any, any>, fn)\n })\n }\n\n // SAFETY: The data-first overload supplies a Result-compatible Effect value.\n return mapErrorResult(first as ResultType<any, any>, fn)\n}\n\n/**\n * Chain a synchronous Result-producing operation after a successful result.\n *\n * The next operation is skipped when the input is an error. Both error types\n * and both sets of Service requirements are preserved in the output.\n *\n * @example\n * ```ts\n * const user = Effect.andThen(Result.ok('u1'), (id) => repository.find(id))\n * ```\n */\nexport function andThen<A, Next extends AnyEffectValue>(\n next: (value: A) => Next\n): AndThenOperation<Next>\nexport function andThen<Input, Next extends AnyEffectValue>(\n effect: Input & AnyEffectValue,\n next: (value: EffectSuccess<Input>) => Next\n): ChainedOutput<Input, Next>\nexport function andThen(first: CombinatorInput, second?: CombinatorCallback): any {\n if (first instanceof Function && second === undefined) {\n // SAFETY: The curried overload accepts a unary continuation in this branch.\n const callback = first as CombinatorCallback\n\n return (effect: AnyEffectInput) => {\n // SAFETY: The overload implementation has already established the callback and Effect input positions.\n return andThen(effect as never, callback as never)\n }\n }\n\n // SAFETY: The data-first overload requires the second argument to return a Result.\n const next = second as CombinatorCallback\n\n // SAFETY: The data-first overload supplies a Result-compatible Effect value.\n return andThenResult(first as ResultType<any, any>, next)\n}\n\n/**\n * Chain an asynchronous Result-producing operation after a successful result.\n *\n * The returned value is always a Promise and retains both operations' error\n * and Service-requirement metadata.\n *\n * @example\n * ```ts\n * const user = Effect.andThenAsync(loadUser(), (user) => fetchProfile(user.id))\n * ```\n */\nexport function andThenAsync<A, Next extends AnyAsyncEffectInput>(\n next: (value: A) => Next\n): AndThenAsyncOperation<A, Next>\nexport function andThenAsync<Input, Next extends AnyAsyncEffectInput>(\n effect: Input & AnyEffectInput,\n next: (value: EffectSuccess<Input>) => Next\n): AsyncChainedOutput<Input, Next>\nexport function andThenAsync(first: CombinatorInput, second?: CombinatorCallback): any {\n if (first instanceof Function && second === undefined) {\n // SAFETY: The curried overload accepts a unary asynchronous continuation in this branch.\n const callback = first as CombinatorCallback\n\n return (effect: AnyEffectInput) => {\n // SAFETY: The overload implementation has already established the callback and Effect input positions.\n return andThenAsync(effect as never, callback as never)\n }\n }\n\n // SAFETY: The data-first overload requires the second argument to return a PromiseLike Effect.\n const next = second as CombinatorCallback\n\n if (isPromiseLike(first)) {\n return Promise.resolve(first).then((result) => {\n // SAFETY: Result is the runtime representation shared by Effect and better-result.\n return andThenAsyncResult(result as ResultType<any, any>, next)\n })\n }\n\n // SAFETY: The data-first overload supplies a Result-compatible Effect value.\n return andThenAsyncResult(first as ResultType<any, any>, next)\n}\n\nconst tapResult = <A, E, Requirements extends AnyService>(\n result: ResultType<A, E>,\n fn: (value: A) => void\n): Effect<A, E, Requirements> =>\n // SAFETY: Result.tap preserves the Result value; the declaration-only Effect marker is restored here.\n Result.tap(result, fn) as Effect<A, E, Requirements>\n\nconst tapErrorResult = <A, E, Requirements extends AnyService>(\n result: ResultType<A, E>,\n fn: (error: E) => void\n): Effect<A, E, Requirements> =>\n // SAFETY: Result.tapError preserves the Result value; the declaration-only Effect marker is restored here.\n Result.tapError(result, fn) as Effect<A, E, Requirements>\n\nconst tapBothResult = <A, E, Requirements extends AnyService>(\n result: ResultType<A, E>,\n handlers: { ok: (value: A) => void; err: (error: E) => void }\n): Effect<A, E, Requirements> =>\n // SAFETY: Result.tapBoth preserves the Result value; the declaration-only Effect marker is restored here.\n Result.tapBoth(result, handlers) as Effect<A, E, Requirements>\n\nconst tapAsyncResult = <A, E, Requirements extends AnyService>(\n result: ResultType<A, E>,\n fn: (value: A) => PromiseLike<void>\n): Promise<Effect<A, E, Requirements>> =>\n // SAFETY: Result.tapAsync preserves the Result value and owns observer defect behavior; only the Effect marker is restored here.\n Result.tapAsync(result, (value) => Promise.resolve(fn(value))) as Promise<\n Effect<A, E, Requirements>\n >\n\nconst tapErrorAsyncResult = <A, E, Requirements extends AnyService>(\n result: ResultType<A, E>,\n fn: (error: E) => PromiseLike<void>\n): Promise<Effect<A, E, Requirements>> =>\n // SAFETY: Result.tapErrorAsync preserves the Result value and owns observer defect behavior; only the Effect marker is restored here.\n Result.tapErrorAsync(result, (error) => Promise.resolve(fn(error))) as Promise<\n Effect<A, E, Requirements>\n >\n\nconst tapBothAsyncResult = <A, E, Requirements extends AnyService>(\n result: ResultType<A, E>,\n handlers: { ok: (value: A) => PromiseLike<void>; err: (error: E) => PromiseLike<void> }\n): Promise<Effect<A, E, Requirements>> =>\n // SAFETY: Result.tapBothAsync selects one branch and preserves the Result; only the Effect marker is restored here.\n Result.tapBothAsync(result, {\n ok: (value) => Promise.resolve(handlers.ok(value)),\n err: (error) => Promise.resolve(handlers.err(error))\n }) as Promise<Effect<A, E, Requirements>>\n\nconst asTaggedResult = (\n result: ResultType<unknown, unknown>\n): ResultType<unknown, TaggedErrorLike> => {\n // SAFETY: The public matcher overload restricts error values to TaggedErrorLike before reaching this runtime boundary.\n return result as ResultType<unknown, TaggedErrorLike>\n}\n\nconst matchErrorResult = <\n A,\n E extends TaggedErrorLike,\n Requirements extends AnyService,\n Handlers extends TaggedErrorHandlers<E>\n>(\n result: ResultType<A, E>,\n handlers: Handlers\n): Effect<A, HandlerReturn<Handlers>, Requirements> => {\n // SAFETY: Result.mapError selects Err and preserves Ok; the declaration-only Effect marker is restored here.\n return Result.mapError(result, (error) => resultMatchError(error, handlers)) as Effect<\n A,\n HandlerReturn<Handlers>,\n Requirements\n >\n}\n\nconst matchErrorPartialResult = <\n A,\n E extends TaggedErrorLike,\n Requirements extends AnyService,\n Handlers extends Partial<TaggedErrorHandlers<E>>\n>(\n result: ResultType<A, E>,\n handlers: Handlers\n): Effect<A, HandlerReturn<Handlers> | UnhandledTaggedErrors<E, Handlers>, Requirements> => {\n // SAFETY: Result.mapError selects Err and preserves Ok; the declaration-only Effect marker is restored here.\n return Result.mapError(result, (error) => resultMatchErrorPartial(error, handlers)) as Effect<\n A,\n HandlerReturn<Handlers> | UnhandledTaggedErrors<E, Handlers>,\n Requirements\n >\n}\n\nconst recoverResult = <\n A,\n E,\n B,\n E2,\n Requirements1 extends AnyService,\n Requirements2 extends AnyService\n>(\n result: ResultType<A, E>,\n fn: (error: E) => ResultType<B, E2>\n): Effect<A | B, E2, Requirements1 | Requirements2> =>\n // SAFETY: Result.tryRecover owns recovery and short-circuiting; only Effect metadata is restored here.\n Result.tryRecover(result, fn) as Effect<A | B, E2, Requirements1 | Requirements2>\n\nconst recoverAsyncResult = <\n A,\n E,\n B,\n E2,\n Requirements1 extends AnyService,\n Requirements2 extends AnyService\n>(\n result: ResultType<A, E>,\n fn: (error: E) => PromiseLike<ResultType<B, E2>>\n): Promise<Effect<A | B, E2, Requirements1 | Requirements2>> =>\n // SAFETY: Result.tryRecoverAsync owns asynchronous recovery; only Effect metadata is restored here.\n Result.tryRecoverAsync(result, (error) => Promise.resolve(fn(error))) as Promise<\n Effect<A | B, E2, Requirements1 | Requirements2>\n >\n\nconst flattenResult = <\n A,\n E1,\n E2,\n Requirements1 extends AnyService,\n Requirements2 extends AnyService\n>(\n result: ResultType<ResultType<A, E2>, E1>\n): Effect<A, E1 | E2, Requirements1 | Requirements2> =>\n // SAFETY: Result.flatten removes one Result layer; the outer and inner Effect markers are restored here.\n Result.flatten(result) as Effect<A, E1 | E2, Requirements1 | Requirements2>\n\nconst matchResult = <A, E, OkResult, ErrResult>(\n result: ResultType<A, E>,\n handlers: { ok: (value: A) => OkResult; err: (error: E) => ErrResult }\n): OkResult | ErrResult =>\n // SAFETY: Result.match invokes only the selected branch; handler Results remain ordinary runtime values.\n Result.match(result, handlers as never) as OkResult | ErrResult\n\nconst allResult = <const Results extends readonly AnyEffectValue[]>(\n results: Results\n): AllResult<Results> =>\n // SAFETY: Result.all preserves tuple order and short-circuiting; the declaration-only channels are restored here.\n Result.all(results as readonly ResultType<any, any>[]) as AllResult<Results>\n\n/** Observe a successful value without changing the Result. */\nexport function tap(fn: (value: any) => void): TapOperation\nexport function tap<Input>(\n effect: Input & AnyEffectInput,\n fn: (value: EffectSuccess<Input>) => void\n): PreserveAsync<Input, TappedResult<Input>>\nexport function tap(first: CombinatorInput, second?: CombinatorCallback): any {\n if (first instanceof Function && second === undefined) {\n const callback = first\n return (effect: AnyEffectInput) => tap(effect, callback)\n }\n\n if (second === undefined) {\n throw new TypeError('Effect.tap requires a callback')\n }\n\n const fn = second\n if (isPromiseLike(first)) {\n return Promise.resolve(first).then((result) => tapResult(asResult(result), fn))\n }\n\n return tapResult(asResult(first), fn)\n}\n\n/** Observe an error value without changing the Result. */\nexport function tapError(fn: (error: any) => void): TapErrorOperation\nexport function tapError<Input>(\n effect: Input & AnyEffectInput,\n fn: (error: EffectError<Input>) => void\n): PreserveAsync<Input, TappedResult<Input>>\nexport function tapError(first: CombinatorInput, second?: CombinatorCallback): any {\n if (first instanceof Function && second === undefined) {\n const callback = first\n return (effect: AnyEffectInput) => tapError(effect, callback)\n }\n\n if (second === undefined) {\n throw new TypeError('Effect.tapError requires a callback')\n }\n\n const fn = second\n if (isPromiseLike(first)) {\n return Promise.resolve(first).then((result) => tapErrorResult(asResult(result), fn))\n }\n\n return tapErrorResult(asResult(first), fn)\n}\n\n/** Observe whichever Result branch is active without changing the Result. */\nexport function tapBoth(handlers: {\n ok: (value: any) => void\n err: (error: any) => void\n}): TapBothOperation\nexport function tapBoth<Input>(\n effect: Input & AnyEffectInput,\n handlers: {\n ok: (value: EffectSuccess<Input>) => void\n err: (error: EffectError<Input>) => void\n }\n): PreserveAsync<Input, TappedResult<Input>>\nexport function tapBoth(first: any, second?: any): any {\n if (second === undefined) {\n return (effect: AnyEffectInput) => tapBoth(effect, first)\n }\n\n if (isPromiseLike(first)) {\n return Promise.resolve(first).then((result) => tapBothResult(result, second))\n }\n\n return tapBothResult(asResult(first), second)\n}\n\n/** Observe a successful value asynchronously without changing the Result. */\nexport function tapAsync(fn: (value: any) => PromiseLike<void>): TapAsyncOperation\nexport function tapAsync<Input>(\n effect: Input & AnyEffectInput,\n fn: (value: EffectSuccess<Input>) => PromiseLike<void>\n): Promise<TappedResult<Input>>\nexport function tapAsync(first: CombinatorInput, second?: CombinatorCallback): any {\n if (first instanceof Function && second === undefined) {\n const callback = first\n return (effect: AnyEffectInput) => tapAsync(effect, callback)\n }\n\n if (second === undefined) {\n throw new TypeError('Effect.tapAsync requires a callback')\n }\n\n if (isPromiseLike(first)) {\n return Promise.resolve(first).then((result) => tapAsyncResult(asResult(result), second))\n }\n\n return tapAsyncResult(asResult(first), second)\n}\n\n/** Observe an error value asynchronously without changing the Result. */\nexport function tapErrorAsync(fn: (error: any) => PromiseLike<void>): TapErrorAsyncOperation\nexport function tapErrorAsync<Input>(\n effect: Input & AnyEffectInput,\n fn: (error: EffectError<Input>) => PromiseLike<void>\n): Promise<TappedResult<Input>>\nexport function tapErrorAsync(first: CombinatorInput, second?: CombinatorCallback): any {\n if (first instanceof Function && second === undefined) {\n const callback = first\n return (effect: AnyEffectInput) => tapErrorAsync(effect, callback)\n }\n\n if (second === undefined) {\n throw new TypeError('Effect.tapErrorAsync requires a callback')\n }\n\n if (isPromiseLike(first)) {\n return Promise.resolve(first).then((result) => tapErrorAsyncResult(asResult(result), second))\n }\n\n return tapErrorAsyncResult(asResult(first), second)\n}\n\n/** Observe the active Result branch asynchronously without changing the Result. */\nexport function tapBothAsync(handlers: {\n ok: (value: any) => PromiseLike<void>\n err: (error: any) => PromiseLike<void>\n}): TapBothAsyncOperation\nexport function tapBothAsync<Input>(\n effect: Input & AnyEffectInput,\n handlers: {\n ok: (value: EffectSuccess<Input>) => PromiseLike<void>\n err: (error: EffectError<Input>) => PromiseLike<void>\n }\n): Promise<TappedResult<Input>>\nexport function tapBothAsync(first: any, second?: any): any {\n if (second === undefined) {\n return (effect: AnyEffectInput) => tapBothAsync(effect, first)\n }\n\n if (isPromiseLike(first)) {\n return Promise.resolve(first).then((result) => tapBothAsyncResult(result, second))\n }\n\n return tapBothAsyncResult(asResult(first), second)\n}\n\n/** Match every tagged error variant and map it to a new error value. */\nexport function matchError<Input, Handlers extends TaggedErrorHandlersFor<Input>>(\n effect: Input & AnyEffectInput,\n handlers: Handlers\n): PreserveAsync<Input, MatchErrorResult<Input, Handlers>>\n// oxlint-disable-next-line anti-slop/no-unknown-parameters -- overload implementation is narrowed by the typed public signature.\nexport function matchError(first: AnyEffectInput, second?: unknown): any {\n if (second === undefined) {\n throw new TypeError('Effect.matchError requires handlers')\n }\n\n // SAFETY: The public matcher overload checks the handler map against the source tagged-error union.\n const handlers = second as TaggedErrorHandlers<TaggedErrorLike>\n\n if (isPromiseLike(first)) {\n return Promise.resolve(first).then((result) =>\n matchErrorResult(asTaggedResult(asResult(result)), handlers)\n )\n }\n\n return matchErrorResult(asTaggedResult(asResult(first)), handlers)\n}\n\n/** Match selected tagged errors and retain unhandled variants unchanged. */\nexport function matchErrorPartial<Input, Handlers extends Partial<TaggedErrorHandlersFor<Input>>>(\n effect: Input & AnyEffectInput,\n handlers: Handlers\n): PreserveAsync<Input, MatchErrorPartialResult<Input, Handlers>>\n// oxlint-disable-next-line anti-slop/no-unknown-parameters -- overload implementation is narrowed by the typed public signature.\nexport function matchErrorPartial(first: AnyEffectInput, second?: unknown): any {\n if (second === undefined) {\n throw new TypeError('Effect.matchErrorPartial requires handlers')\n }\n\n // SAFETY: The public matcher overload checks the handler map against the source tagged-error union.\n const handlers = second as Partial<TaggedErrorHandlers<TaggedErrorLike>>\n\n if (isPromiseLike(first)) {\n return Promise.resolve(first).then((result) =>\n matchErrorPartialResult(asTaggedResult(asResult(result)), handlers)\n )\n }\n\n return matchErrorPartialResult(asTaggedResult(asResult(first)), handlers)\n}\n\n/** Recover an Err with a synchronous Result-producing callback. */\nexport function recover<Next extends AnyEffectValue>(\n fn: (error: any) => Next\n): RecoverOperation<Next>\nexport function recover<Input, Next extends AnyEffectValue>(\n effect: Input & AnyEffectInput,\n fn: (error: EffectError<Input>) => Next\n): PreserveAsync<Input, RecoveredResult<Input, Next>>\nexport function recover(first: CombinatorInput, second?: CombinatorCallback): any {\n if (first instanceof Function && second === undefined) {\n const callback = first\n return (effect: AnyEffectInput) => recover(effect, callback)\n }\n\n if (second === undefined) {\n throw new TypeError('Effect.recover requires a callback')\n }\n\n const fn = second\n if (isPromiseLike(first)) {\n return Promise.resolve(first).then((result) => recoverResult(asResult(result), fn))\n }\n\n return recoverResult(asResult(first), fn)\n}\n\n/** Recover an Err with an asynchronous Result-producing callback. */\nexport function recoverAsync<Next extends AnyAsyncEffectInput>(\n fn: (error: any) => Next\n): RecoverAsyncOperation<Next>\nexport function recoverAsync<Input, Next extends AnyAsyncEffectInput>(\n effect: Input & AnyEffectInput,\n fn: (error: EffectError<Input>) => Next\n): Promise<RecoveredResult<Input, Next>>\nexport function recoverAsync(first: CombinatorInput, second?: CombinatorCallback): any {\n if (first instanceof Function && second === undefined) {\n const callback = first\n return (effect: AnyEffectInput) => recoverAsync(effect, callback)\n }\n\n if (second === undefined) {\n throw new TypeError('Effect.recoverAsync requires a callback')\n }\n\n const fn = second\n if (isPromiseLike(first)) {\n return Promise.resolve(first).then((result) => recoverAsyncResult(asResult(result), fn))\n }\n\n return recoverAsyncResult(asResult(first), fn)\n}\n\n/** Remove one nested Result/Effect layer. */\nexport function flatten<Input>(effect: Input & AnyEffectValue): FlattenedResult<Input> {\n // SAFETY: flattenResult restores the nested Effect channels after Result.flatten removes one runtime layer.\n return flattenResult(asResult(effect)) as FlattenedResult<Input>\n}\n\n/** Replace a successful value while preserving errors and requirements. */\nexport function as<Value>(\n value: Value\n): <Input>(effect: Input & AnyEffectValue) => AsResult<Input, Value>\nexport function as<Input, Value>(\n effect: Input & AnyEffectValue,\n value: Value\n): AsResult<Input, Value>\nexport function as(first: any, second?: any): any {\n if (arguments.length < 2) {\n return (effect: AnyEffectValue) => as(effect, first)\n }\n\n return mapResult(asResult(first), () => second)\n}\n\n/** Replace a successful value with void. */\nexport function asVoid<Input>(effect: Input & AnyEffectValue): AsResult<Input, void> {\n return mapResult(asResult(effect), () => undefined)\n}\n\n/** Match an Effect and return branch Effects with their channels unioned. */\nexport function match<Input, OkResult extends AnyEffectValue, ErrResult extends AnyEffectValue>(\n effect: Input & AnyEffectValue,\n handlers: {\n ok: (value: EffectSuccess<Input>) => OkResult\n err: (error: EffectError<Input>) => ErrResult\n }\n): PreserveAsync<Input, MatchedResult<Input, OkResult, ErrResult>>\nexport function match<Input, OkValue, ErrValue>(\n effect: Input & AnyEffectValue,\n handlers: {\n ok: (value: EffectSuccess<Input>) => OkValue\n err: (error: EffectError<Input>) => ErrValue\n }\n): PreserveAsync<Input, OkValue | ErrValue>\nexport function match(first: AnyEffectInput, second?: any): any {\n if (isPromiseLike(first)) {\n return Promise.resolve(first).then((result) => match(asResult(result), second))\n }\n\n return matchResult(asResult(first), second)\n}\n\n/** Collect already-created Effects in input order. */\nexport function all<const Results extends readonly AnyEffectValue[]>(\n results: Results\n): AllResult<Results> {\n return allResult(results)\n}\n\n/** Combine two already-created Effects in input order. */\nexport function zip<Left, Right>(\n left: Left & AnyEffectValue,\n right: Right & AnyEffectValue\n): ZipResult<Left, Right> {\n // SAFETY: Result.all returns the ordered pair; ZipResult restores only the declaration-only Effect channels.\n return Result.all([left, right]) as ZipResult<Left, Right>\n}\n","import { Result } from 'better-result'\n\nimport type { Result as ResultType } from 'better-result'\n\nimport type { AnyService } from '../service'\nimport { inheritProgramName } from './program-metadata'\nimport { isPromiseLike } from '../utils/runtime'\n\nimport type { EffectError, EffectRequirements, EffectSuccess, Program } from './types'\n\ntype AnyResult = ResultType<any, any>\ntype RuntimeEffect = AnyResult | PromiseLike<AnyResult>\ntype RuntimeProgram = () => RuntimeEffect\ntype RuntimeProgramOutput = RuntimeEffect | RuntimeProgram\ntype RuntimeCallback = (value: any) => any\ntype RuntimeContinuation = (value: any) => RuntimeProgramOutput\ntype AnyProgram = Program<any, any, AnyService>\n\ntype ProgramInput<Input extends RuntimeProgram> = Input &\n Program<EffectSuccess<Input>, EffectError<Input>, EffectRequirements<Input>>\n\ntype CompatibleSuccess<Input, A> = EffectSuccess<Input> extends A ? unknown : never\ntype CompatibleError<Input, E> = EffectError<Input> extends E ? unknown : never\n\ntype ProgramOutput<Output> =\n Output extends Program<infer _Success, infer _Error, infer _Requirements extends AnyService>\n ? Output\n : Output extends PromiseLike<infer AsyncOutput>\n ? AsyncOutput extends ResultType<infer _Success, infer _Error>\n ? Output\n : never\n : Output extends ResultType<infer _Success, infer _Error>\n ? Output\n : never\n\ntype MappedProgram<Input, B> = Program<B, EffectError<Input>, EffectRequirements<Input>>\n\ntype ErrorMappedProgram<Input, E2> = Program<EffectSuccess<Input>, E2, EffectRequirements<Input>>\n\ntype ChainedProgram<Input, Next> = Program<\n EffectSuccess<Next>,\n EffectError<Input> | EffectError<Next>,\n EffectRequirements<Input> | EffectRequirements<Next>\n>\n\ntype TappedProgram<Input> = Program<\n EffectSuccess<Input>,\n EffectError<Input>,\n EffectRequirements<Input>\n>\n\ntype RecoveredProgram<Input, Next> = Program<\n EffectSuccess<Input> | EffectSuccess<Next>,\n EffectError<Next>,\n EffectRequirements<Input> | EffectRequirements<Next>\n>\n\ntype MapOperation<A, B> = {\n <Input extends RuntimeProgram>(\n program: ProgramInput<Input> & CompatibleSuccess<Input, A>\n ): MappedProgram<Input, B>\n}\n\ntype MapErrorOperation<E1, E2> = {\n <Input extends RuntimeProgram>(\n program: ProgramInput<Input> & CompatibleError<Input, E1>\n ): ErrorMappedProgram<Input, E2>\n}\n\ntype AndThenOperation<A, Next> = {\n <Input extends RuntimeProgram>(\n program: ProgramInput<Input> & CompatibleSuccess<Input, A>\n ): ChainedProgram<Input, Next>\n}\n\ntype TapOperation<A> = {\n <Input extends RuntimeProgram>(\n program: ProgramInput<Input> & CompatibleSuccess<Input, A>\n ): TappedProgram<Input>\n}\n\ntype TapErrorOperation<E> = {\n <Input extends RuntimeProgram>(\n program: ProgramInput<Input> & CompatibleError<Input, E>\n ): TappedProgram<Input>\n}\n\ntype RecoverOperation<E, Next> = {\n <Input extends RuntimeProgram>(\n program: ProgramInput<Input> & CompatibleError<Input, E>\n ): RecoveredProgram<Input, Next>\n}\n\nconst asProgram = <Output extends AnyProgram>(program: RuntimeProgram): Output =>\n // SAFETY: Program's channels and nominal marker are declaration-only; callers derive them from typed inputs.\n program as Output\n\nconst isAsyncEffect = (effect: RuntimeEffect): effect is PromiseLike<AnyResult> =>\n isPromiseLike(effect)\n\nconst mapRuntime = (effect: RuntimeEffect, fn: RuntimeCallback): RuntimeEffect => {\n if (isAsyncEffect(effect)) {\n return Promise.resolve(effect).then((result) => Result.map(result, fn))\n }\n\n return Result.map(effect, fn)\n}\n\nconst mapErrorRuntime = (effect: RuntimeEffect, fn: RuntimeCallback): RuntimeEffect => {\n if (isAsyncEffect(effect)) {\n return Promise.resolve(effect).then((result) => Result.mapError(result, fn))\n }\n\n return Result.mapError(effect, fn)\n}\n\nconst tapRuntime = (effect: RuntimeEffect, fn: RuntimeCallback): RuntimeEffect => {\n if (isAsyncEffect(effect)) {\n return Promise.resolve(effect).then((result) => Result.tap(result, fn))\n }\n\n return Result.tap(effect, fn)\n}\n\nconst tapErrorRuntime = (effect: RuntimeEffect, fn: RuntimeCallback): RuntimeEffect => {\n if (isAsyncEffect(effect)) {\n return Promise.resolve(effect).then((result) => Result.tapError(result, fn))\n }\n\n return Result.tapError(effect, fn)\n}\n\nconst invoke = (output: RuntimeProgramOutput): RuntimeEffect =>\n output instanceof Function ? output() : output\n\nconst andThenRuntime = (effect: RuntimeEffect, next: RuntimeContinuation): Promise<AnyResult> => {\n const continueWith = (value: any) => Promise.resolve(invoke(next(value)))\n\n if (isAsyncEffect(effect)) {\n return Promise.resolve(effect).then((result) => Result.andThenAsync(result, continueWith))\n }\n\n return Result.andThenAsync(effect, continueWith)\n}\n\nconst recoverRuntime = (\n effect: RuntimeEffect,\n recover: RuntimeContinuation\n): Promise<AnyResult> => {\n const continueWith = (error: any) => Promise.resolve(invoke(recover(error)))\n\n if (isAsyncEffect(effect)) {\n return Promise.resolve(effect).then((result) => Result.tryRecoverAsync(result, continueWith))\n }\n\n return Result.tryRecoverAsync(effect, continueWith)\n}\n\nconst mapProgram = <Input extends RuntimeProgram, B>(\n program: ProgramInput<Input>,\n fn: (value: EffectSuccess<Input>) => B\n): MappedProgram<Input, B> => {\n const mapped = asProgram<MappedProgram<Input, B>>(() => mapRuntime(program(), fn))\n\n return inheritProgramName(program, mapped)\n}\n\nconst mapErrorProgram = <Input extends RuntimeProgram, E2>(\n program: ProgramInput<Input>,\n fn: (error: EffectError<Input>) => E2\n): ErrorMappedProgram<Input, E2> => {\n const mapped = asProgram<ErrorMappedProgram<Input, E2>>(() => mapErrorRuntime(program(), fn))\n\n return inheritProgramName(program, mapped)\n}\n\nconst tapProgram = <Input extends RuntimeProgram>(\n program: ProgramInput<Input>,\n fn: (value: EffectSuccess<Input>) => any\n): TappedProgram<Input> => {\n const tapped = asProgram<TappedProgram<Input>>(() => tapRuntime(program(), fn))\n\n return inheritProgramName(program, tapped)\n}\n\nconst tapErrorProgram = <Input extends RuntimeProgram>(\n program: ProgramInput<Input>,\n fn: (error: EffectError<Input>) => any\n): TappedProgram<Input> => {\n const tapped = asProgram<TappedProgram<Input>>(() => tapErrorRuntime(program(), fn))\n\n return inheritProgramName(program, tapped)\n}\n\n/** Lazily map the successful Result value of a Program. */\nexport function map<A, B>(fn: (value: A) => B): MapOperation<A, B>\nexport function map<Input extends RuntimeProgram, B>(\n program: ProgramInput<Input>,\n fn: (value: EffectSuccess<Input>) => B\n): MappedProgram<Input, B>\nexport function map(first: RuntimeProgram | RuntimeCallback, second?: RuntimeCallback): any {\n if (second === undefined) {\n return (program: RuntimeProgram) => {\n // SAFETY: The curried overload supplies a Program and a callback that accepts its success channel.\n return mapProgram(program as ProgramInput<typeof program>, first)\n }\n }\n\n // SAFETY: The data-first overload supplies a Program as its first argument.\n return mapProgram(first as ProgramInput<RuntimeProgram>, second)\n}\n\n/** Lazily map the error Result value of a Program. */\nexport function mapError<E1, E2>(fn: (error: E1) => E2): MapErrorOperation<E1, E2>\nexport function mapError<Input extends RuntimeProgram, E2>(\n program: ProgramInput<Input>,\n fn: (error: EffectError<Input>) => E2\n): ErrorMappedProgram<Input, E2>\nexport function mapError(first: RuntimeProgram | RuntimeCallback, second?: RuntimeCallback): any {\n if (second === undefined) {\n return (program: RuntimeProgram) => {\n // SAFETY: The curried overload supplies a Program and a callback that accepts its error channel.\n return mapErrorProgram(program as ProgramInput<typeof program>, first)\n }\n }\n\n // SAFETY: The data-first overload supplies a Program as its first argument.\n return mapErrorProgram(first as ProgramInput<RuntimeProgram>, second)\n}\n\n/** Lazily continue a successful Program with an Effect or Program. */\nexport function andThen<A, Next>(\n next: (value: A) => Next & ProgramOutput<Next>\n): AndThenOperation<A, Next>\nexport function andThen<Input extends RuntimeProgram, Next>(\n program: ProgramInput<Input>,\n next: (value: EffectSuccess<Input>) => Next & ProgramOutput<Next>\n): ChainedProgram<Input, Next>\nexport function andThen(\n first: RuntimeProgram | RuntimeContinuation,\n second?: RuntimeContinuation\n): any {\n if (second === undefined) {\n return (program: RuntimeProgram) => {\n // SAFETY: The curried overload supplies a Program and a continuation for its success channel.\n const chained = () => andThenRuntime(program(), first as RuntimeContinuation)\n\n return inheritProgramName(program, chained)\n }\n }\n\n // SAFETY: The data-first overload supplies a Program as its first argument.\n const source = first as RuntimeProgram\n const chained = () => andThenRuntime(source(), second)\n\n return inheritProgramName(source, chained)\n}\n\n/** Lazily observe a successful Program value without changing its Result. */\nexport function tap<A>(fn: (value: A) => void): TapOperation<A>\nexport function tap<Input extends RuntimeProgram>(\n program: ProgramInput<Input>,\n fn: (value: EffectSuccess<Input>) => void\n): TappedProgram<Input>\nexport function tap(first: RuntimeProgram | RuntimeCallback, second?: RuntimeCallback): any {\n if (second === undefined) {\n return (program: RuntimeProgram) => {\n // SAFETY: The curried overload supplies a Program and a callback that accepts its success channel.\n return tapProgram(program as ProgramInput<typeof program>, first)\n }\n }\n\n // SAFETY: The data-first overload supplies a Program as its first argument.\n return tapProgram(first as ProgramInput<RuntimeProgram>, second)\n}\n\n/** Lazily observe a failed Program value without changing its Result. */\nexport function tapError<E>(fn: (error: E) => void): TapErrorOperation<E>\nexport function tapError<Input extends RuntimeProgram>(\n program: ProgramInput<Input>,\n fn: (error: EffectError<Input>) => void\n): TappedProgram<Input>\nexport function tapError(first: RuntimeProgram | RuntimeCallback, second?: RuntimeCallback): any {\n if (second === undefined) {\n return (program: RuntimeProgram) => {\n // SAFETY: The curried overload supplies a Program and a callback that accepts its error channel.\n return tapErrorProgram(program as ProgramInput<typeof program>, first)\n }\n }\n\n // SAFETY: The data-first overload supplies a Program as its first argument.\n return tapErrorProgram(first as ProgramInput<RuntimeProgram>, second)\n}\n\n/** Lazily recover a failed Program with an Effect or Program. */\nexport function recover<E, Next>(\n fn: (error: E) => Next & ProgramOutput<Next>\n): RecoverOperation<E, Next>\nexport function recover<Input extends RuntimeProgram, Next>(\n program: ProgramInput<Input>,\n recover: (error: EffectError<Input>) => Next & ProgramOutput<Next>\n): RecoveredProgram<Input, Next>\nexport function recover(\n first: RuntimeProgram | RuntimeContinuation,\n second?: RuntimeContinuation\n): any {\n if (second === undefined) {\n return (program: RuntimeProgram) => {\n // SAFETY: The curried overload supplies a Program and a recovery callback for its error channel.\n const recovered = () => recoverRuntime(program(), first as RuntimeContinuation)\n\n return inheritProgramName(program, recovered)\n }\n }\n\n // SAFETY: The data-first overload supplies a Program as its first argument.\n const source = first as RuntimeProgram\n const recovered = () => recoverRuntime(source(), second)\n\n return inheritProgramName(source, recovered)\n}\n","import { Err } from 'better-result'\n\nimport type { Result as ResultType } from 'better-result'\n\ntype AnyResult = ResultType<any, any>\n\ntype ProgramCollectionFailure =\n | { readonly kind: 'result'; readonly result: AnyResult }\n | { readonly kind: 'defect'; readonly cause: unknown }\n\ntype ProgramCollectionDefect = { readonly cause: unknown }\n\ntype ProgramCollectionOutcome = {\n readonly results: Array<AnyResult | undefined>\n readonly defects: Array<ProgramCollectionDefect | undefined>\n}\n\nexport type ProgramCollectionOptions = {\n readonly concurrency: number | undefined\n readonly stopOnResultError: boolean\n}\n\ntype ProgramTask = (index: number) => AnyResult | PromiseLike<AnyResult>\n\ntype SchedulerState = {\n nextIndex: number\n stopScheduling: boolean\n readonly results: Array<AnyResult | undefined>\n readonly defects: Array<ProgramCollectionDefect | undefined>\n}\n\n/** Validate the shared bounded-concurrency option before a Program is run. */\nexport const validateProgramConcurrency = (concurrency: number | undefined): void => {\n if (\n concurrency !== undefined &&\n (!Number.isFinite(concurrency) || !Number.isInteger(concurrency) || concurrency <= 0)\n ) {\n throw new RangeError('Program.all concurrency must be a positive integer')\n }\n}\n\nconst runWorker = async (\n length: number,\n task: ProgramTask,\n stopOnResultError: boolean,\n state: SchedulerState\n): Promise<void> => {\n while (!state.stopScheduling) {\n const index = state.nextIndex++\n\n if (index >= length) {\n return\n }\n\n try {\n const result = await task(index)\n state.results[index] = result\n\n if (result instanceof Err) {\n state.stopScheduling ||= stopOnResultError\n }\n } catch (cause) {\n state.defects[index] = { cause }\n state.stopScheduling = true\n }\n }\n}\n\n/** Run claimed Programs with a shared FIFO worker pool and no cancellation. */\nexport const runProgramCollection = async (\n length: number,\n task: ProgramTask,\n options: ProgramCollectionOptions\n): Promise<ProgramCollectionOutcome> => {\n const state: SchedulerState = {\n nextIndex: 0,\n stopScheduling: false,\n results: Array.from({ length }),\n defects: Array.from({ length })\n }\n const workerCount = Math.min(options.concurrency ?? length, length)\n const workers = Array.from({ length: workerCount }, () =>\n runWorker(length, task, options.stopOnResultError, state)\n )\n\n await Promise.all(workers)\n\n return state\n}\n\n/** Select the first defect by input index, independent of settlement order. */\nexport const firstProgramDefect = (\n defects: readonly (ProgramCollectionDefect | undefined)[]\n): ProgramCollectionDefect | undefined => {\n for (const defect of defects) {\n if (defect !== undefined) {\n return defect\n }\n }\n\n return undefined\n}\n\n/** Select the first short-circuiting failure by input index. */\nexport const firstProgramFailure = (\n results: readonly (AnyResult | undefined)[],\n defects: readonly (ProgramCollectionDefect | undefined)[]\n): ProgramCollectionFailure | undefined => {\n const length = Math.max(results.length, defects.length)\n\n for (let index = 0; index < length; index++) {\n const defect = defects[index]\n if (defect !== undefined) {\n return { kind: 'defect', cause: defect.cause }\n }\n\n const result = results[index]\n if (result instanceof Err) {\n return { kind: 'result', result }\n }\n }\n\n return undefined\n}\n","import { Result } from 'better-result'\n\nimport type { Err, Result as ResultType, UnhandledException } from 'better-result'\n\nimport { Scope } from '../scope'\n\nimport type { DisposableResource, MaybePromise, ScopeOutcome } from '../scope'\n\nimport { setProgramName } from './program-metadata'\nimport type { AnyService } from '../service'\nimport { forkScoped } from './task'\nimport type { ScopedTask, ScopedTaskExit } from './task'\n\nimport type {\n AnyEffect,\n Effect as EffectType,\n EffectError,\n EffectFromGenerator,\n EffectRequirements,\n EffectSuccess,\n EffectYield,\n Program as ProgramType,\n ProgramFromGenerator\n} from './types'\n\nimport {\n all,\n andThen,\n andThenAsync,\n as,\n asVoid,\n flatten,\n map,\n mapError,\n match,\n matchError,\n matchErrorPartial,\n recover,\n recoverAsync,\n tap,\n tapAsync,\n tapBoth,\n tapBothAsync,\n tapError,\n tapErrorAsync,\n zip\n} from './combinators'\nimport {\n andThen as programAndThen,\n map as programMap,\n mapError as programMapError,\n recover as programRecover,\n tap as programTap,\n tapError as programTapError\n} from './program-combinators'\nimport {\n firstProgramDefect,\n firstProgramFailure,\n runProgramCollection,\n validateProgramConcurrency\n} from './program-scheduler'\n\nexport type Effect<A, E, R extends AnyService = never> = EffectType<A, E, R>\n\ntype LazyProgram<A, E, R extends AnyService = never> = ProgramType<A, E, R>\n\n/** A nominal lazy computation that produces an Effect when invoked. */\nexport type Program<A, E, R extends AnyService = never> = LazyProgram<A, E, R>\n\ntype AnyResult = ResultType<any, any>\n\ntype AnyProgram = ProgramType<any, any, AnyService>\n\ntype ProgramAllSuccess<Programs extends readonly AnyProgram[]> = {\n -readonly [Index in keyof Programs]: EffectSuccess<Programs[Index]>\n}\n\ntype ProgramAllError<Programs extends readonly AnyProgram[]> = EffectError<Programs[number]>\n\ntype ProgramAllRequirements<Programs extends readonly AnyProgram[]> = EffectRequirements<\n Programs[number]\n>\n\ntype ProgramAllResult<Programs extends readonly AnyProgram[]> = ProgramType<\n ProgramAllSuccess<Programs>,\n ProgramAllError<Programs>,\n ProgramAllRequirements<Programs>\n>\n\ntype ProgramResultFor<Child> = Child extends AnyProgram\n ? ResultType<EffectSuccess<Child>, EffectError<Child>>\n : never\n\ntype ProgramAllResultsSuccess<Programs extends readonly AnyProgram[]> =\n number extends Programs['length']\n ? ReadonlyArray<ResultType<EffectSuccess<Programs[number]>, EffectError<Programs[number]>>>\n : { readonly [Index in keyof Programs]: ProgramResultFor<Programs[Index]> }\n\ntype ProgramAllResultsResult<Programs extends readonly AnyProgram[]> = ProgramType<\n ProgramAllResultsSuccess<Programs>,\n never,\n ProgramAllRequirements<Programs>\n>\n\ntype ProgramForEachResult<Child extends AnyProgram> = ProgramType<\n ReadonlyArray<EffectSuccess<Child>>,\n EffectError<Child>,\n EffectRequirements<Child>\n>\n\nexport type ProgramAllOptions = {\n readonly concurrency?: number\n /** Optional diagnostic name for the collection execution. */\n readonly name?: string\n}\n\ntype EffectGenerator =\n | (() => Generator<EffectYield, AnyResult, unknown>)\n | (() => AsyncGenerator<EffectYield, AnyResult, unknown>)\n\ntype RuntimeResultGenerator = (body: EffectGenerator) => AnyResult | Promise<AnyResult>\n\n// SAFETY: Service iterators yield no runtime markers, so Result.gen receives only the Err values that exist at runtime.\nconst runResultGenerator = Result.gen as RuntimeResultGenerator\n\n/**\n * Compose `better-result` operations while preserving Service requirements in\n * a declaration-only type channel.\n *\n * A generator may yield Service tokens and Result operations. It must return a\n * `Result` as its final value; Service yields are resolved by the active\n * Runtime and do not add runtime values to the Result stream.\n * Use `fn` when generator execution should wait for a Runtime boundary.\n *\n * @example\n * ```ts\n * const loadUser = Effect.gen(async function* () {\n * const database = yield* Database\n * const user = yield* Result.await(database.findUser('u1'))\n *\n * return Result.ok(user)\n * })\n * ```\n */\nexport function gen<Yield extends EffectYield, Returned extends AnyResult>(\n body: () => Generator<Yield, Returned, unknown>\n): EffectFromGenerator<Yield, Returned>\n\nexport function gen<Yield extends EffectYield, Returned extends AnyResult>(\n body: () => AsyncGenerator<Yield, Returned, unknown>\n): Promise<EffectFromGenerator<Yield, Returned>>\n\nexport function gen(body: EffectGenerator): AnyResult | Promise<AnyResult> {\n return runResultGenerator(body)\n}\n\n/** Build a lazy Program without running its generator. */\nexport function fn<Yield extends EffectYield, Returned extends AnyResult>(\n body: () => Generator<Yield, Returned, unknown>\n): ProgramFromGenerator<Yield, Returned>\n\nexport function fn<Yield extends EffectYield, Returned extends AnyResult>(\n body: () => AsyncGenerator<Yield, Returned, unknown>\n): ProgramFromGenerator<Yield, Returned>\n\nexport function fn(body: EffectGenerator): Program<any, any, AnyService> {\n const program = () => runResultGenerator(body)\n\n // SAFETY: The generator overloads derive the Program channels; this cast only adds the declaration-only nominal marker.\n return program as Program<any, any, AnyService>\n}\n\ntype ProgramNamedOperation = {\n <Input extends AnyProgram>(program: Input): Input\n}\n\nconst validateProgramName = (name: string): void => {\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- validate JavaScript callers at the public boundary.\n if (typeof name !== 'string') {\n throw new TypeError('Program name must be a string')\n }\n}\n\n/** Attach a lazy diagnostic name to a Program without invoking it. */\nfunction programNamed(name: string): ProgramNamedOperation\nfunction programNamed<Input extends AnyProgram>(name: string, program: Input): Input\nfunction programNamed(name: string, program?: AnyProgram): AnyProgram | ProgramNamedOperation {\n validateProgramName(name)\n\n if (program === undefined) {\n return (source) => setProgramName(source, name)\n }\n\n return setProgramName(program, name)\n}\n\nconst runShortCircuitingCollection = async (\n length: number,\n task: (index: number) => AnyResult | PromiseLike<AnyResult>,\n concurrency: number | undefined\n): Promise<AnyResult> => {\n const outcome = await runProgramCollection(length, task, {\n concurrency,\n stopOnResultError: true\n })\n const failure = firstProgramFailure(outcome.results, outcome.defects)\n\n if (failure?.kind === 'defect') {\n throw failure.cause\n }\n\n if (failure?.kind === 'result') {\n return failure.result\n }\n\n // SAFETY: The scheduler records one Result per claimed index before completing successfully.\n return Result.all(outcome.results as AnyResult[])\n}\n\nconst runAllResultsCollection = async (\n length: number,\n task: (index: number) => AnyResult | PromiseLike<AnyResult>,\n concurrency: number | undefined\n): Promise<AnyResult> => {\n const outcome = await runProgramCollection(length, task, {\n concurrency,\n stopOnResultError: false\n })\n const defect = firstProgramDefect(outcome.defects)\n\n if (defect !== undefined) {\n throw defect.cause\n }\n\n // SAFETY: The scheduler records each Result object at its input index.\n return Result.ok(outcome.results as AnyResult[])\n}\n\n/** Build a lazy Program collection with optional bounded concurrency. */\nexport function programAll<const Programs extends readonly AnyProgram[]>(\n programs: Programs,\n options: ProgramAllOptions = {}\n): ProgramAllResult<Programs> {\n const concurrency = options.concurrency\n const name = options?.name\n validateProgramConcurrency(concurrency)\n const program = () =>\n runShortCircuitingCollection(programs.length, (index) => programs[index]!(), concurrency)\n\n if (name !== undefined) {\n validateProgramName(name)\n setProgramName(program, name)\n }\n\n // SAFETY: Program channels are declaration-only and are restored from the input tuple here.\n return program as ProgramAllResult<Programs>\n}\n\n/** Build a lazy Program collection from an input array and Program factory. */\nexport function programForEach<const Items extends readonly unknown[], Child extends AnyProgram>(\n items: Items,\n makeProgram: (item: Items[number], index: number) => Child,\n options: ProgramAllOptions = {}\n): ProgramForEachResult<Child> {\n const concurrency = options.concurrency\n const name = options?.name\n validateProgramConcurrency(concurrency)\n const program = () =>\n runShortCircuitingCollection(\n items.length,\n (index) => makeProgram(items[index]!, index)(),\n concurrency\n )\n\n if (name !== undefined) {\n validateProgramName(name)\n setProgramName(program, name)\n }\n\n // SAFETY: Program channels are declaration-only and are restored from the factory's result type.\n return program as ProgramForEachResult<Child>\n}\n\n/** Build a lazy Program collection that retains every child Result. */\nexport function programAllResults<const Programs extends readonly AnyProgram[]>(\n programs: Programs,\n options: ProgramAllOptions = {}\n): ProgramAllResultsResult<Programs> {\n const concurrency = options.concurrency\n const name = options?.name\n validateProgramConcurrency(concurrency)\n const program = () =>\n runAllResultsCollection(programs.length, (index) => programs[index]!(), concurrency)\n\n if (name !== undefined) {\n validateProgramName(name)\n setProgramName(program, name)\n }\n\n // SAFETY: Program channels are declaration-only and are restored from the input tuple here.\n return program as ProgramAllResultsResult<Programs>\n}\n\n/** Value-level namespace for lazy Program combinators. */\nexport const Program = {\n named: programNamed,\n all: programAll,\n forEach: programForEach,\n allResults: programAllResults,\n map: programMap,\n mapError: programMapError,\n andThen: programAndThen,\n tap: programTap,\n tapError: programTapError,\n recover: programRecover\n} as const\n\n/**\n * Acquire a resource in the current Scope and register its release callback.\n *\n * Acquisition failures are represented in the Effect Result error channel;\n * release failures remain owned by Scope cleanup. The release callback\n * receives the final outcome chosen by the enclosing execution boundary.\n *\n * @example\n * ```ts\n * const connection = yield* Effect.acquireRelease(\n * () => pool.connect(),\n * (connection, outcome) => connection.close(outcome)\n * )\n * ```\n */\nexport function acquireRelease<R>(\n acquire: () => MaybePromise<R>,\n release: (resource: R, outcome: ScopeOutcome) => MaybePromise<void>\n): AsyncGenerator<Err<never, UnhandledException>, R, unknown> {\n const scope = Scope.current()\n\n return Result.await(Result.tryPromise(() => scope.acquire(acquire, release)))\n}\n\nclass AcquireReleaseResultFailure<R, E> {\n constructor(readonly result: Err<R, E>) {}\n}\n\n/**\n * Acquire a Result-valued resource and register only successful acquisitions.\n *\n * Typed acquisition failures remain unchanged in the Effect error channel;\n * unexpected acquisition and registration failures are normalized by\n * `better-result`. Release failures remain Scope cleanup failures.\n */\nexport function acquireReleaseResult<R, E>(\n acquire: () => MaybePromise<ResultType<R, E>>,\n release: (resource: R, outcome: ScopeOutcome) => MaybePromise<void>\n): AsyncGenerator<Err<never, E | UnhandledException>, R, unknown> {\n const scope = Scope.current()\n const registered = Result.tryPromise(async (): Promise<ResultType<R, E>> => {\n try {\n const resource = await scope.acquire(async () => {\n const result = await acquire()\n\n if (Result.isError(result)) {\n throw new AcquireReleaseResultFailure(result)\n }\n\n return result.value\n }, release)\n\n return Result.ok(resource)\n } catch (cause) {\n if (cause instanceof AcquireReleaseResultFailure) {\n return cause.result\n }\n\n throw cause\n }\n })\n\n return Result.await(registered.then((result) => result.andThen((acquired) => acquired)))\n}\n\n/**\n * Lazily acquire and register a disposable resource in the current Scope.\n *\n * Disposal is delegated to `Scope.add`, including protocol preference,\n * validation, race-safe registration, and cleanup error handling.\n */\nexport function acquireDisposable<R extends DisposableResource>(\n acquire: () => MaybePromise<R>\n): AsyncGenerator<Err<never, UnhandledException>, R, unknown> {\n const scope = Scope.current()\n\n return Result.await(Result.tryPromise(async () => scope.add(await acquire())))\n}\n\n/**\n * Register an already-acquired disposable resource in the current Scope.\n *\n * The resource is not acquired by this helper. Registration failures are\n * represented in the Effect Result error channel; disposal failures remain\n * owned by Scope cleanup.\n *\n * @example\n * ```ts\n * const file = yield* Effect.add(await openFile('notes.txt'))\n * ```\n */\nexport function add<R extends DisposableResource>(\n resource: R\n): AsyncGenerator<Err<never, UnhandledException>, R, unknown> {\n const scope = Scope.current()\n\n return Result.await(Result.tryPromise(() => scope.add(resource)))\n}\n\n/**\n * Effect namespace containing generator, resource, and Result combinators.\n *\n * Prefer these helpers when a program needs typed Service requirements or\n * Scope-aware acquisition and cleanup.\n */\ntype EffectNamespace = {\n readonly gen: typeof gen\n readonly fn: typeof fn\n readonly acquireRelease: typeof acquireRelease\n readonly acquireReleaseResult: typeof acquireReleaseResult\n readonly acquireDisposable: typeof acquireDisposable\n readonly add: typeof add\n readonly forkScoped: typeof forkScoped\n readonly map: typeof map\n readonly mapError: typeof mapError\n readonly andThen: typeof andThen\n readonly andThenAsync: typeof andThenAsync\n readonly tap: typeof tap\n readonly tapAsync: typeof tapAsync\n readonly tapError: typeof tapError\n readonly tapErrorAsync: typeof tapErrorAsync\n readonly tapBoth: typeof tapBoth\n readonly tapBothAsync: typeof tapBothAsync\n readonly matchError: typeof matchError\n readonly matchErrorPartial: typeof matchErrorPartial\n readonly recover: typeof recover\n readonly recoverAsync: typeof recoverAsync\n readonly flatten: typeof flatten\n readonly as: typeof as\n readonly asVoid: typeof asVoid\n readonly match: typeof match\n readonly all: typeof all\n readonly zip: typeof zip\n}\n\nexport const Effect: EffectNamespace = {\n /** Compose a generator-based Effect program. */\n gen,\n /** Build a lazy Program from a generator. */\n fn,\n /** Acquire and register a resource in the current Scope. */\n acquireRelease,\n /** Acquire a Result-valued resource and register successful acquisitions. */\n acquireReleaseResult,\n /** Acquire and register a disposable resource in the current Scope. */\n acquireDisposable,\n /** Register an already-acquired disposable in the current Scope. */\n add,\n /** Start a child Program owned by the current Scope. */\n forkScoped,\n /** Map a successful Effect result. */\n map,\n /** Map an Effect error. */\n mapError,\n /** Chain a synchronous Effect result. */\n andThen,\n /** Chain an asynchronous Effect result. */\n andThenAsync,\n /** Observe successful values without changing the Result. */\n tap,\n /** Observe successful values asynchronously without changing the Result. */\n tapAsync,\n /** Observe error values without changing the Result. */\n tapError,\n /** Observe error values asynchronously without changing the Result. */\n tapErrorAsync,\n /** Observe the active Result branch without changing the Result. */\n tapBoth,\n /** Observe the active Result branch asynchronously without changing the Result. */\n tapBothAsync,\n /** Match every tagged error variant and map it to a new error value. */\n matchError,\n /** Match selected tagged errors and retain unhandled variants. */\n matchErrorPartial,\n /** Recover an error with another Effect. */\n recover,\n /** Recover an error asynchronously with another Effect. */\n recoverAsync,\n /** Remove one nested Effect layer. */\n flatten,\n /** Replace a successful value. */\n as,\n /** Replace a successful value with void. */\n asVoid,\n /** Match either Result branch. */\n match,\n /** Collect Effects in input order. */\n all,\n /** Zip two Effects in input order. */\n zip\n} as const\n\n/** Type-level aliases for inspecting Effect result channels and requirements. */\nexport declare namespace Effect {\n /** A nominal lazy computation that produces an Effect when invoked. */\n export type Program<A, E, R extends AnyService = never> = LazyProgram<A, E, R>\n\n /** Extract the success channel from an Effect result or Promise. */\n export type Success<T> = EffectSuccess<T>\n\n /** Extract the error channel from an Effect result or Promise. */\n export type Error<T> = EffectError<T>\n\n /** Extract the Service requirements from an Effect result or Promise. */\n export type Requirements<T> = EffectRequirements<T>\n\n /** An Effect with erased success, error, and requirements. */\n export type Any = AnyEffect\n\n /** A small handle for a Scope-owned child task. */\n export type Task<A, E> = ScopedTask<A, E>\n\n /** The terminal observation returned by a Scope-owned child task. */\n export type TaskExit<A, E> = ScopedTaskExit<A, E>\n}\n"],"mappings":";;;;;;AAwDA,SAAgB,WACd,SAKA;CACA,MAAM,UAAU,sBAAsB;CACtC,MAAM,WAAW,QAAQ;CACzB,MAAM,QAAQ,QAAQ;CAEtB,IAAI,CAAC,YAAY,CAAC,OAChB,MAAM,IAAI,iCAAiC;CAG7C,MAAM,aAAa,yBAAyB,KAAK;CAEjD,IAAI,CAAC,YACH,MAAM,IAAI,iCAAiC;CAI7C,OAAO,OAAO,GAAG,WAAW,WAAW,SAAS;EAAE,GAAG;EAAS;EAAU;CAAM,CAAC,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AAM,aAAa,OAAO,WAAW,YAAuC;EAC1E,IAAI;GACF,MAAM,WAAW,MAAM,MAAM,QAAQ,YAAY;IAC/C,MAAM,SAAS,MAAM,QAAQ;IAE7B,IAAI,OAAO,QAAQ,MAAM,GACvB,MAAM,IAAI,4BAA4B,MAAM;IAG9C,OAAO,OAAO;GAChB,GAAG,OAAO;GAEV,OAAO,OAAO,GAAG,QAAQ;EAC3B,SAAS,OAAO;GACd,IAAI,iBAAiB,6BACnB,OAAO,MAAM;GAGf,MAAM;EACR;CACF,CAAC;CAED,OAAO,OAAO,MAAM,WAAW,MAAM,WAAW,OAAO,SAAS,aAAa,QAAQ,CAAC,CAAC;AACzF;;;;;;;AAQA,SAAgB,kBACd,SAC4D;CAC5D,MAAM,QAAQ,MAAM,QAAQ;CAE5B,OAAO,OAAO,MAAM,OAAO,WAAW,YAAY,MAAM,IAAI,MAAM,QAAQ,CAAC,CAAC,CAAC;AAC/E;;;;;;;;;;;;;AAcA,SAAgB,IACd,UAC4D;CAC5D,MAAM,QAAQ,MAAM,QAAQ;CAE5B,OAAO,OAAO,MAAM,OAAO,iBAAiB,MAAM,IAAI,QAAQ,CAAC,CAAC;AAClE;AAsCA,MAAa,SAA0B;;CAErC;;CAEA;;CAEA;;CAEA;;CAEA;;CAEA;;CAEA;;CAEA,KAAA;;CAEA,UAAA;;CAEA,SAAA;;CAEA;;CAEA,KAAA;;CAEA;;CAEA,UAAA;;CAEA;;CAEA;;CAEA;;CAEA,YAAA;;CAEA,mBAAA;;CAEA,SAAA;;CAEA;;CAEA;;CAEA;;CAEA;;CAEA;;CAEA;;CAEA;AACF"}
|
|
@@ -7,6 +7,10 @@ declare class RuntimeContextNotConfiguredError extends Error {
|
|
|
7
7
|
declare class RuntimeContextOverlapError extends Error {
|
|
8
8
|
constructor();
|
|
9
9
|
}
|
|
10
|
+
/** Thrown when a Runtime executor is requested without an active Runtime. */
|
|
11
|
+
declare class RuntimeExecutorNotConfiguredError extends Error {
|
|
12
|
+
constructor();
|
|
13
|
+
}
|
|
10
14
|
//#endregion
|
|
11
|
-
export { RuntimeContextOverlapError as n, RuntimeContextNotConfiguredError as t };
|
|
12
|
-
//# sourceMappingURL=errors-
|
|
15
|
+
export { RuntimeContextOverlapError as n, RuntimeExecutorNotConfiguredError as r, RuntimeContextNotConfiguredError as t };
|
|
16
|
+
//# sourceMappingURL=errors-CpHMzPiP.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors-CpHMzPiP.d.mts","names":[],"sources":["../src/runtime/errors.ts"],"mappings":";;cACa,yCAAyC;EACpD;;;cAQW,mCAAmC;EAC9C;;;cAUW,0CAA0C;EACrD"}
|
package/dist/hono.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { t as CurrentRequest } from "./current-request-CIU7AHhF.mjs";
|
|
1
|
+
import { At as EffectRequirements, Bt as ServiceContract, Ft as ProgramFromGenerator, It as ServiceRequirement, Kt as ServiceToken, Lt as AnyService, Mt as EffectYield, Nt as InferYieldRequirements, Ot as EffectError, Pt as Program, Ut as ServiceRequirements, Vt as ServiceIdentity, ct as ValidateLayerInput, ft as ProviderEntry, it as MissingServices, jt as EffectSuccess, lt as ValidateOneOverride, ot as ProvidedEnvironment, rt as LayerResult, st as RequiredEnvironment, tt as LayerInput } from "./layer-C2OaqTmB.mjs";
|
|
2
|
+
import { t as CurrentRequest } from "./current-request-Dm-QQ3Xr.mjs";
|
|
3
|
+
import { c as WebEffectStream } from "./types-BFTqCCcw.mjs";
|
|
5
4
|
import { Result } from "better-result";
|
|
6
5
|
import { Context, Env, Handler, HonoRequest, Input, MiddlewareHandler } from "hono";
|
|
7
6
|
//#region src/hono/types.d.ts
|
|
@@ -10,6 +9,11 @@ type AnyProgram = Program<any, any, AnyService>;
|
|
|
10
9
|
type HonoContext = Context<any, any, any>;
|
|
11
10
|
type ResponseLike = Response | Promise<Response>;
|
|
12
11
|
type AnyHonoMiddleware = MiddlewareHandler<any, any, any>;
|
|
12
|
+
/** A builder operation resolved while the application Layer is acquired. */
|
|
13
|
+
interface HonoEffectOperation<A, Requirements extends AnyService = never> {
|
|
14
|
+
readonly [Symbol.iterator]: () => Generator<ServiceRequirement<Requirements>, A, unknown>;
|
|
15
|
+
readonly [Symbol.asyncIterator]: () => AsyncGenerator<ServiceRequirement<Requirements>, A, unknown>;
|
|
16
|
+
}
|
|
13
17
|
type MiddlewareInput<Middleware extends AnyHonoMiddleware> = Middleware extends MiddlewareHandler<any, any, infer InputType> ? InputType : Input;
|
|
14
18
|
type UnionToIntersection<Union> = (Union extends unknown ? (value: Union) => void : never) extends ((value: infer Intersection) => void) ? Intersection : never;
|
|
15
19
|
type MiddlewareInputs<Middlewares extends readonly AnyHonoMiddleware[]> = Middlewares extends readonly [] ? Input : Input & UnionToIntersection<MiddlewareInput<Middlewares[number]>>;
|
|
@@ -42,7 +46,6 @@ type HonoJsonValue = null | boolean | number | string | readonly HonoJsonValue[]
|
|
|
42
46
|
};
|
|
43
47
|
type DefaultRequestLayer = ReturnType<typeof CurrentRequest.layer>;
|
|
44
48
|
type RequestProvided<RequestLayer extends LayerInput> = ProvidedEnvironment<RequestLayer>;
|
|
45
|
-
type AvailableServices<Provided extends AnyService, RequestLayer extends LayerInput> = Provided | InstanceType<typeof CurrentRequest> | RequestProvided<RequestLayer>;
|
|
46
49
|
type InvalidFailure<Actual, Expected> = {
|
|
47
50
|
readonly __betterEffectInvalidHonoFailure: {
|
|
48
51
|
readonly actual: Actual;
|
|
@@ -51,14 +54,14 @@ type InvalidFailure<Actual, Expected> = {
|
|
|
51
54
|
};
|
|
52
55
|
type FailureCheck<Failure, Actual> = [Actual] extends [Failure] ? unknown : InvalidFailure<Actual, Failure>;
|
|
53
56
|
type ProgramFailure<Failure, Program extends AnyProgram> = FailureCheck<Failure, EffectError<Program>>;
|
|
54
|
-
|
|
55
|
-
type
|
|
56
|
-
/**
|
|
57
|
-
type
|
|
58
|
-
|
|
59
|
-
type CompleteProgram<
|
|
57
|
+
/** Validate a request Layer against the built-in CurrentRequest provider. */
|
|
58
|
+
type HonoRequestLayerChecks<RequestLayer extends LayerInput> = ValidateLayerInput<RequestLayer> & ValidateOneOverride<DefaultRequestLayer, RequestLayer>;
|
|
59
|
+
/** Requirements of a route Program that must be provided by the application Layer. */
|
|
60
|
+
type HonoProgramRequirements<RequestLayer extends LayerInput, Program extends AnyProgram> = Extract<RequiredEnvironment<RequestLayer> | MissingServices<Extract<EffectRequirements<Program>, AnyService>, Extract<InstanceType<typeof CurrentRequest> | RequestProvided<RequestLayer>, AnyService>>, AnyService>;
|
|
61
|
+
/** Validate only a route Program's typed failure channel at the builder boundary. */
|
|
62
|
+
type CompleteProgram<Program extends AnyProgram, Failure = unknown> = Program & ProgramFailure<Failure, Program>;
|
|
60
63
|
type GeneratorBody<ContextType extends object, Yield extends EffectYield, Returned extends AnyResult> = (context: ContextType) => Generator<Yield, Returned, unknown> | AsyncGenerator<Yield, Returned, unknown>;
|
|
61
|
-
type GeneratorChecks<
|
|
64
|
+
type GeneratorChecks<Yield extends EffectYield, Returned extends AnyResult, Failure = unknown> = FailureCheck<Failure, EffectError<ProgramFromGenerator<Yield, Returned>>>;
|
|
62
65
|
type HonoEffectSuccess<A = unknown> = {
|
|
63
66
|
readonly value: A;
|
|
64
67
|
readonly status?: number;
|
|
@@ -74,27 +77,40 @@ type HonoEffectRouteOptions<A, ContextType extends HonoContext = HonoContext> =
|
|
|
74
77
|
readonly serialize?: (value: A) => HonoJsonValue;
|
|
75
78
|
readonly respond?: (value: A, context: ContextType) => ResponseLike;
|
|
76
79
|
};
|
|
80
|
+
/** Options for a managed Hono stream route. */
|
|
81
|
+
type HonoEffectStreamOptions = {
|
|
82
|
+
/** Cancel an unconsumed or abandoned body after this idle period. */
|
|
83
|
+
readonly unconsumedTimeoutMs?: number;
|
|
84
|
+
};
|
|
85
|
+
type StreamValueCheck<Program extends AnyProgram> = [EffectSuccess<Program>] extends [WebEffectStream] ? unknown : {
|
|
86
|
+
readonly __betterEffectInvalidHonoStream: {
|
|
87
|
+
readonly actual: EffectSuccess<Program>;
|
|
88
|
+
readonly expected: WebEffectStream;
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
/** Validate a managed stream Program at the Hono builder boundary. */
|
|
92
|
+
type CompleteHonoStreamProgram<Program extends AnyProgram, Failure = unknown> = Program & ProgramFailure<Failure, Program> & StreamValueCheck<Program>;
|
|
77
93
|
//#endregion
|
|
78
|
-
//#region src/hono/
|
|
94
|
+
//#region src/hono/builder.d.ts
|
|
79
95
|
type HonoRouteArguments<Middlewares extends readonly AnyHonoMiddleware[], Body, Options> = [...middlewares: Middlewares, body: Body] | [...middlewares: Middlewares, body: Body, options: Options | undefined];
|
|
80
|
-
type HonoHandlerFactory<ContextType extends object,
|
|
81
|
-
/**
|
|
82
|
-
declare class
|
|
83
|
-
readonly runtime: Runtime<Provided>;
|
|
96
|
+
type HonoHandlerFactory<ContextType extends object, Failure, ProgramFactory extends (context: ContextType) => AnyProgram> = ProgramFactory & ([ReturnType<ProgramFactory>] extends [CompleteProgram<ReturnType<ProgramFactory>, Failure>] ? unknown : (context: ContextType) => CompleteProgram<ReturnType<ProgramFactory>, Failure>);
|
|
97
|
+
/** Build Hono-native handlers whose Runtime capability is captured by the app Layer. */
|
|
98
|
+
declare class HonoEffectBuilder<Failure, RequestLayer extends LayerInput> {
|
|
84
99
|
private readonly states;
|
|
85
100
|
private readonly onSuccess;
|
|
86
101
|
private readonly onFailure;
|
|
87
102
|
private readonly requestLayer;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
handler<E extends Env =
|
|
92
|
-
|
|
93
|
-
gen<
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
103
|
+
constructor(options: HonoEffectOptions<Failure, RequestLayer>);
|
|
104
|
+
middleware<E extends Env = Env, Path extends string = string>(): HonoEffectOperation<MiddlewareHandler<E, Path>, Extract<RequiredEnvironment<RequestLayer>, AnyService>>;
|
|
105
|
+
handler<E extends Env = Env, Path extends string = string, InputType extends Input = Input, Program extends AnyProgram = AnyProgram>(makeProgram: (context: Context<E, Path, InputType>) => CompleteProgram<Program, Failure>, options?: HonoEffectRouteOptions<EffectSuccess<Program>, Context<E, Path, InputType>>): HonoEffectOperation<Handler<E, Path, InputType, Promise<Response>>, HonoProgramRequirements<RequestLayer, Program>>;
|
|
106
|
+
handler<const Middlewares extends readonly AnyHonoMiddleware[], E extends Env = MiddlewareEnvironment<Middlewares>, Path extends string = MiddlewarePath<Middlewares>, const ProgramFactory extends (context: HonoEffectContext<E, Path, MiddlewareInputs<Middlewares>>) => AnyProgram = (context: HonoEffectContext<E, Path, MiddlewareInputs<Middlewares>>) => AnyProgram>(...args: HonoRouteArguments<Middlewares, HonoHandlerFactory<HonoEffectContext<E, Path, MiddlewareInputs<Middlewares>>, Failure, ProgramFactory>, HonoEffectRouteOptions<EffectSuccess<ReturnType<ProgramFactory>>, Context<E, Path, MiddlewareInputs<Middlewares>>>>): HonoEffectOperation<Handler<E, Path, MiddlewareInputs<Middlewares>, Promise<Response>>, HonoProgramRequirements<RequestLayer, ReturnType<ProgramFactory>>>;
|
|
107
|
+
gen<E extends Env = Env, Path extends string = string, InputType extends Input = Input, const Yield extends EffectYield = EffectYield, const Returned extends AnyResult = AnyResult>(body: GeneratorBody<Context<E, Path, InputType>, Yield, Returned> & GeneratorChecks<Yield, Returned, Failure>, options?: HonoEffectRouteOptions<EffectSuccess<ProgramFromGenerator<Yield, Returned>>, Context<E, Path, InputType>>): HonoEffectOperation<Handler<E, Path, InputType, Promise<Response>>, HonoProgramRequirements<RequestLayer, ProgramFromGenerator<Yield, Returned>>>;
|
|
108
|
+
gen<const Middlewares extends readonly AnyHonoMiddleware[], E extends Env = MiddlewareEnvironment<Middlewares>, Path extends string = MiddlewarePath<Middlewares>, const Yield extends EffectYield = EffectYield, const Returned extends AnyResult = AnyResult>(...args: HonoRouteArguments<Middlewares, GeneratorBody<HonoEffectContext<E, Path, MiddlewareInputs<Middlewares>>, Yield, Returned> & GeneratorChecks<Yield, Returned, Failure>, HonoEffectRouteOptions<EffectSuccess<ProgramFromGenerator<Yield, Returned>>, Context<E, Path, MiddlewareInputs<Middlewares>>>>): HonoEffectOperation<Handler<E, Path, MiddlewareInputs<Middlewares>, Promise<Response>>, HonoProgramRequirements<RequestLayer, ProgramFromGenerator<Yield, Returned>>>;
|
|
109
|
+
stream<E extends Env = Env, Path extends string = string, InputType extends Input = Input, Program extends AnyProgram = AnyProgram>(program: CompleteHonoStreamProgram<Program, Failure>, options?: HonoEffectStreamOptions): HonoEffectOperation<Handler<E, Path, InputType, Promise<Response>>, HonoProgramRequirements<RequestLayer, Program>>;
|
|
110
|
+
stream<const Middlewares extends readonly AnyHonoMiddleware[], E extends Env = MiddlewareEnvironment<Middlewares>, Path extends string = MiddlewarePath<Middlewares>, Program extends AnyProgram = AnyProgram>(...args: HonoRouteArguments<Middlewares, CompleteHonoStreamProgram<Program, Failure>, HonoEffectStreamOptions>): HonoEffectOperation<Handler<E, Path, MiddlewareInputs<Middlewares>, Promise<Response>>, HonoProgramRequirements<RequestLayer, Program>>;
|
|
111
|
+
guard<E extends Env = Env, Path extends string = string, InputType extends Input = Input, const Yield extends EffectYield = EffectYield, const Returned extends AnyResult = AnyResult>(body: GeneratorBody<Context<E, Path, InputType>, Yield, Returned> & GeneratorChecks<Yield, Returned, Failure>): HonoEffectOperation<MiddlewareHandler<E, Path>, HonoProgramRequirements<RequestLayer, ProgramFromGenerator<Yield, Returned>>>;
|
|
97
112
|
private makeHandler;
|
|
113
|
+
private makeStreamHandler;
|
|
98
114
|
private handleSuccess;
|
|
99
115
|
private handleFailure;
|
|
100
116
|
private composeInputMiddleware;
|
|
@@ -104,5 +120,25 @@ declare class HonoEffectBoundaryMissingError extends Error {
|
|
|
104
120
|
constructor();
|
|
105
121
|
}
|
|
106
122
|
//#endregion
|
|
107
|
-
|
|
123
|
+
//#region src/hono/hono-effect.d.ts
|
|
124
|
+
type HonoFactoryFor<Builder, Returned extends object> = (http: Builder) => Generator<ServiceRequirement<unknown>, Returned, unknown> | AsyncGenerator<ServiceRequirement<unknown>, Returned, unknown>;
|
|
125
|
+
type HonoFactory<Builder> = HonoFactoryFor<Builder, object>;
|
|
126
|
+
type HonoFactoryReturn<Factory> = Factory extends ((...arguments_: any[]) => infer Iterator) ? Iterator extends Generator<any, infer Returned, any> ? Returned extends object ? Returned : never : Iterator extends AsyncGenerator<any, infer Returned, any> ? Returned extends object ? Returned : never : never : never;
|
|
127
|
+
type HonoFactoryYield<Factory> = Factory extends ((...arguments_: any[]) => infer Iterator) ? Iterator extends Generator<infer Yield, object, any> ? Yield : Iterator extends AsyncGenerator<infer Yield, object, any> ? Yield : never : never;
|
|
128
|
+
/** A Hono application Layer with inferred Service requirements. */
|
|
129
|
+
type HonoEffectLayer<Service extends ServiceToken<any, any>, Yield extends ServiceRequirement<unknown>> = LayerResult<ProviderEntry<InstanceType<Service>, Extract<ServiceRequirements<InstanceType<Service>> | InferYieldRequirements<Yield>, AnyService>>>;
|
|
130
|
+
type HonoApplicationToken<Tag extends string, App extends object, Service extends ServiceToken<any, any>, Yield extends ServiceRequirement<unknown>> = ServiceToken<Tag, App & ServiceIdentity<Tag>> & {
|
|
131
|
+
readonly layer: HonoEffectLayer<Service, Yield>;
|
|
132
|
+
};
|
|
133
|
+
type HonoLiteralTag<Tag extends string> = string extends Tag ? never : Tag extends '' ? never : Tag;
|
|
134
|
+
/** Layer-first Hono integration. The application owns the Runtime composition. */
|
|
135
|
+
declare class HonoEffect {
|
|
136
|
+
private constructor();
|
|
137
|
+
/** Create a yieldable Hono application token and its Layer. */
|
|
138
|
+
static app<const Tag extends string, RequestLayer extends LayerInput = DefaultRequestLayer, Failure = unknown, const Factory extends HonoFactory<HonoEffectBuilder<Failure, RequestLayer>> = HonoFactory<HonoEffectBuilder<Failure, RequestLayer>>>(tag: Tag & HonoLiteralTag<Tag>, options: HonoEffectOptions<Failure, RequestLayer> & HonoRequestLayerChecks<RequestLayer>, factory: Factory): HonoApplicationToken<Tag, HonoFactoryReturn<Factory>, ServiceToken<Tag, HonoFactoryReturn<Factory> & ServiceIdentity<Tag>>, Extract<HonoFactoryYield<Factory>, ServiceRequirement<unknown>>>;
|
|
139
|
+
/** Provide an application-chosen Service token with a Hono Layer. */
|
|
140
|
+
static layer<Service extends ServiceToken<any, any>, RequestLayer extends LayerInput = DefaultRequestLayer, Failure = unknown, const Returned extends ServiceContract<InstanceType<Service>> = ServiceContract<InstanceType<Service>>, const Factory extends HonoFactoryFor<HonoEffectBuilder<Failure, RequestLayer>, Returned> = HonoFactoryFor<HonoEffectBuilder<Failure, RequestLayer>, Returned>>(service: Service, options: HonoEffectOptions<Failure, RequestLayer> & HonoRequestLayerChecks<RequestLayer>, factory: Factory): HonoEffectLayer<Service, Extract<HonoFactoryYield<Factory>, ServiceRequirement<unknown>>>;
|
|
141
|
+
}
|
|
142
|
+
//#endregion
|
|
143
|
+
export { type HonoApplicationToken, type HonoContext, HonoEffect, HonoEffectBoundaryMissingError, type HonoEffectLayer, type HonoEffectOperation, type HonoEffectOptions, type HonoEffectRouteOptions, type HonoEffectStreamOptions, type HonoEffectSuccess, type HonoJsonValue };
|
|
108
144
|
//# sourceMappingURL=hono.d.mts.map
|
package/dist/hono.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hono.d.mts","names":[],"sources":["../src/hono/types.ts","../src/hono/hono-effect.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"hono.d.mts","names":[],"sources":["../src/hono/types.ts","../src/hono/builder.ts","../src/hono/hono-effect.ts"],"mappings":";;;;;;KAwBY,YAAY;KACZ,aAAa,kBAAsB;KACnC,cAAc;KACd,eAAe,WAAW,QAAQ;KAClC,oBAAoB;;UAKf,oBAAoB,GAAG,qBAAqB;YACjD,OAAO,iBAAiB,UAAU,mBAAmB,eAAe;YACpE,OAAO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