better-effect 0.9.2 → 0.9.31

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"effect-CZdZCZLW.mjs","names":["SCOPE_SUCCESS","next"],"sources":["../src/scope/errors.ts","../src/scope/disposable.ts","../src/scope/runtime.ts","../src/scope/internal.ts","../src/scope/scope.ts","../src/effect/combinators.ts","../src/effect/effect.ts"],"sourcesContent":["/** Thrown when Scope context is accessed outside an active Scope execution. */\nexport class ScopeRuntimeNotConfiguredError extends Error {\n constructor() {\n super('No Scope is available in the current execution context')\n\n this.name = 'ScopeRuntimeNotConfiguredError'\n }\n}\n\n/** Thrown when a resource or finalizer is added after Scope closure begins. */\nexport class ScopeClosedError extends Error {\n constructor() {\n super('Cannot add resources or finalizers to a closed Scope')\n\n this.name = 'ScopeClosedError'\n }\n}\n\n/** Aggregates finalizer failures encountered while closing a Scope. */\nexport class ScopeCloseError extends Error {\n constructor(readonly causes: readonly unknown[]) {\n super(\n `Failed to close Scope (${causes.length} finalizer${causes.length === 1 ? '' : 's'} failed)`\n )\n\n this.name = 'ScopeCloseError'\n }\n}\n\n/** Thrown when a value has neither Symbol.dispose nor Symbol.asyncDispose. */\nexport class ResourceNotDisposableError extends Error {\n constructor() {\n super('Resource does not implement Symbol.dispose or Symbol.asyncDispose')\n\n this.name = 'ResourceNotDisposableError'\n }\n}\n","import type { ScopeFinalizer } from './types'\n\nconst SCOPE_SUCCESS = { status: 'success' } as const\n\ntype Disposer = (...args: never[]) => void | PromiseLike<void>\n\ntype DisposableCandidate = {\n [Symbol.dispose]?: Disposer\n\n [Symbol.asyncDispose]?: Disposer\n}\n\n/** Return a Scope finalizer for a value's async or sync disposal protocol. */\nexport const getDisposeFinalizer = <Resource>(resource: Resource): ScopeFinalizer | undefined => {\n // SAFETY: Object() provides a property-bearing view for protocol lookup; each method is checked for callability before invocation.\n const candidate = Object(resource) as DisposableCandidate\n const asyncDispose = candidate[Symbol.asyncDispose]\n\n if (asyncDispose instanceof Function) {\n return () => asyncDispose.call(resource)\n }\n\n const dispose = candidate[Symbol.dispose]\n\n if (dispose instanceof Function) {\n return () => dispose.call(resource)\n }\n\n return undefined\n}\n\n/** Dispose a value immediately when it implements a disposal protocol. */\nexport const disposeResource = <Resource>(resource: Resource): void | PromiseLike<void> => {\n const finalizer = getDisposeFinalizer(resource)\n\n return finalizer?.(SCOPE_SUCCESS)\n}\n","import { ScopeRuntimeNotConfiguredError } from './errors'\n\nimport type { Scope } from './scope'\n\nimport {\n activeRuntimeContextStorage,\n currentRuntimeContext,\n getRuntimeContext,\n makeRuntimeContext,\n runRuntimeContext\n} from '../runtime/context'\n\nimport type { RuntimeContextStorage } from '../runtime/context'\n\nconst scopeStorages = new WeakMap<object, RuntimeContextStorage>()\n\n/** Bridges the current Scope through async execution context. */\nexport class ScopeRuntime {\n /** Supply a Scope while invoking a callback. */\n static run<A>(\n scope: Scope,\n program: () => A,\n storage: RuntimeContextStorage = scopeStorages.get(scope) ?? activeRuntimeContextStorage()\n ): A {\n scopeStorages.set(scope, storage)\n\n const current = getRuntimeContext(storage)\n const context = makeRuntimeContext(\n current?.resolver,\n scope,\n current?.resolutionPath ?? [],\n current?.signal\n )\n\n return runRuntimeContext(storage, context, program)\n }\n\n /** Return the Scope active in the current execution context. */\n static current(): Scope {\n let context\n\n try {\n context = currentRuntimeContext()\n } catch {\n throw new ScopeRuntimeNotConfiguredError()\n }\n\n if (!context.scope) {\n throw new ScopeRuntimeNotConfiguredError()\n }\n\n return context.scope\n }\n\n /** Associate a Runtime-owned Scope with its context storage. */\n static bind(scope: Scope, storage: RuntimeContextStorage): void {\n scopeStorages.set(scope, storage)\n }\n}\n","import { ScopeCloseError } from './errors'\n\nimport { ScopeRuntime } from './runtime'\n\nimport type { CloseableScope } from './scope'\n\nimport {\n runRuntimeContext,\n type RuntimeContext,\n type RuntimeContextStorage\n} from '../runtime/context'\n\nimport type { CleanupFailureDiagnostic, MaybePromise, ScopeOutcome } from './types'\n\nexport type OutcomeClassifier<A> = (value: A) => ScopeOutcome\n\nexport type RunScopedOptions<A> = {\n readonly classify: OutcomeClassifier<A>\n readonly onCleanupFailure?: (diagnostic: CleanupFailureDiagnostic) => MaybePromise<void>\n readonly contextStorage?: RuntimeContextStorage\n readonly context?: RuntimeContext\n}\n\nconst notifyCleanupFailure = async (\n observer: ((diagnostic: CleanupFailureDiagnostic) => MaybePromise<void>) | undefined,\n diagnostic: CleanupFailureDiagnostic\n): Promise<void> => {\n if (!observer) {\n return\n }\n\n try {\n await observer(diagnostic)\n } catch {\n // Cleanup diagnostics are best effort and never affect the primary result.\n }\n}\n\nexport const runScoped = async <A>(\n scope: CloseableScope,\n program: () => A | PromiseLike<A>,\n options: RunScopedOptions<Awaited<A>>\n): Promise<Awaited<A>> => {\n let value!: Awaited<A>\n\n let programFailed = false\n let programFailure: unknown\n\n try {\n const run = () => ScopeRuntime.run(scope, program, options.contextStorage)\n\n value = await (options.context && options.contextStorage\n ? runRuntimeContext(options.contextStorage, options.context, run)\n : run())\n } catch (cause) {\n programFailed = true\n programFailure = cause\n }\n\n const outcome: ScopeOutcome = programFailed\n ? {\n status: 'failure',\n cause: programFailure\n }\n : options.classify(value)\n\n let cleanupFailed = false\n let cleanupFailure: unknown\n\n try {\n await scope.close(outcome)\n } catch (cause) {\n cleanupFailed = true\n cleanupFailure = cause\n }\n\n if (cleanupFailed) {\n const error =\n cleanupFailure instanceof ScopeCloseError\n ? cleanupFailure\n : new ScopeCloseError([cleanupFailure])\n\n await notifyCleanupFailure(options.onCleanupFailure, {\n outcome,\n error\n })\n\n cleanupFailure = error\n }\n\n if (programFailed) {\n throw programFailure\n }\n\n if (outcome.status === 'failure') {\n return value\n }\n\n if (cleanupFailed) {\n throw cleanupFailure\n }\n\n return value\n}\n","import { ResourceNotDisposableError, ScopeCloseError, ScopeClosedError } from './errors'\n\nimport { getDisposeFinalizer } from './disposable'\n\nimport { runScoped } from './internal'\n\nimport { ScopeRuntime } from './runtime'\n\nimport type { DisposableResource, MaybePromise, ScopeFinalizer, ScopeOutcome } from './types'\n\n/**\n * Non-owning lifecycle context for finalizers and child Scopes.\n *\n * A Scope can register cleanup and create children, but it cannot close\n * itself. Use `Scope.make()` or `Scope.run()` when your code owns the Scope.\n */\nexport interface Scope {\n /** Register a finalizer that runs when the owning Scope closes. */\n addFinalizer(finalizer: ScopeFinalizer): void\n\n /** Acquire a resource and register its outcome-aware release callback. */\n acquire<R>(\n acquire: () => MaybePromise<R>,\n release: (resource: R, outcome: ScopeOutcome) => MaybePromise<void>\n ): Promise<R>\n\n /** Register an already-acquired disposable resource. */\n add<R extends DisposableResource>(resource: R): Promise<R>\n\n /** Create a child Scope owned by this Scope. */\n fork(): CloseableScope\n}\n\n/** A Scope whose owner is responsible for calling `close()`. */\nexport interface CloseableScope extends Scope {\n /** Close the Scope and run children and finalizers in child-first LIFO order. */\n close(outcome?: ScopeOutcome): Promise<void>\n}\n\nconst SCOPE_SUCCESS: ScopeOutcome = Object.freeze({ status: 'success' })\n\nclass ScopeImpl implements CloseableScope {\n private readonly children = new Set<ScopeImpl>()\n\n private readonly finalizers: ScopeFinalizer[] = []\n\n private closePromise: Promise<void> | undefined\n\n private closeOutcome: ScopeOutcome | undefined\n\n constructor(private parent?: ScopeImpl) {}\n\n fork(): CloseableScope {\n this.assertOpen()\n\n const child = new ScopeImpl(this)\n\n this.children.add(child)\n\n return child\n }\n\n addFinalizer(finalizer: ScopeFinalizer): void {\n this.assertOpen()\n\n this.finalizers.push(finalizer)\n }\n\n async acquire<R>(\n acquire: () => MaybePromise<R>,\n release: (resource: R, outcome: ScopeOutcome) => MaybePromise<void>\n ): Promise<R> {\n this.assertOpen()\n\n const resource = await acquire()\n\n try {\n this.addFinalizer((outcome) => release(resource, outcome))\n\n return resource\n } catch (scopeFailure) {\n try {\n await release(resource, this.closeOutcome ?? SCOPE_SUCCESS)\n } catch (releaseFailure) {\n throw new AggregateError(\n [scopeFailure, releaseFailure],\n 'Scope closed while acquiring a resource and immediate cleanup also failed'\n )\n }\n\n throw scopeFailure\n }\n }\n\n async add<R extends DisposableResource>(resource: R): Promise<R> {\n const finalizer = getDisposeFinalizer(resource)\n\n if (!finalizer) {\n throw new ResourceNotDisposableError()\n }\n\n try {\n this.addFinalizer(finalizer)\n\n return resource\n } catch (scopeFailure) {\n try {\n await finalizer(this.closeOutcome ?? SCOPE_SUCCESS)\n } catch (releaseFailure) {\n throw new AggregateError(\n [scopeFailure, releaseFailure],\n 'Scope closed while adding a disposable resource and cleanup also failed'\n )\n }\n\n throw scopeFailure\n }\n }\n\n close(outcome: ScopeOutcome = SCOPE_SUCCESS): Promise<void> {\n if (this.closePromise) {\n return this.closePromise\n }\n\n this.closeOutcome = outcome\n this.closePromise = ScopeRuntime.run(this, () => this.closeInternal(outcome))\n\n return this.closePromise\n }\n\n private async closeInternal(outcome: ScopeOutcome): Promise<void> {\n const failures: unknown[] = []\n\n const children = [...this.children]\n\n this.children.clear()\n\n for (let index = children.length - 1; index >= 0; index--) {\n const child = children[index]\n\n if (!child) {\n continue\n }\n\n try {\n await child.close(outcome)\n } catch (cause) {\n if (cause instanceof ScopeCloseError) {\n failures.push(...cause.causes)\n } else {\n failures.push(cause)\n }\n }\n }\n\n for (let index = this.finalizers.length - 1; index >= 0; index--) {\n const finalizer = this.finalizers[index]\n\n if (!finalizer) {\n continue\n }\n\n try {\n await finalizer(outcome)\n } catch (cause) {\n failures.push(cause)\n }\n }\n\n this.finalizers.length = 0\n\n this.detach()\n\n if (failures.length > 0) {\n throw new ScopeCloseError(failures)\n }\n }\n\n private detach(): void {\n const parent = this.parent\n\n if (!parent) {\n return\n }\n\n parent.children.delete(this)\n this.parent = undefined\n }\n\n private assertOpen(): void {\n if (this.closePromise) {\n throw new ScopeClosedError()\n }\n }\n}\n\nexport const Scope = {\n /** Create an owned, initially open Scope. */\n make(): CloseableScope {\n return new ScopeImpl()\n },\n\n /** Return the non-owning Scope available in the current execution context. */\n current(): Scope {\n return ScopeRuntime.current()\n },\n\n /** Run a callback with an existing Scope supplied as the current context. */\n provide<A>(scope: Scope, program: () => A): A {\n return ScopeRuntime.run(scope, program)\n },\n\n /** Resolve the current Scope through `yield* Scope` inside an Effect. */\n // oxlint-disable-next-line require-yield\n *[Symbol.iterator](): Generator<never, Scope, unknown> {\n return ScopeRuntime.current()\n },\n\n /**\n * Run a program in a newly owned Scope.\n *\n * Scope is independent from `better-result`, so returned values—including\n * `Result.err`—close this Scope with a successful outcome. Result-aware\n * outcome classification belongs to `Runtime.run`.\n *\n * @example\n * ```ts\n * await Scope.run(async (scope) => {\n * const connection = await scope.acquire(connect, (connection) => connection.close())\n * return connection.query()\n * })\n * ```\n */\n run<A>(program: (scope: Scope) => A | PromiseLike<A>): Promise<Awaited<A>> {\n const scope = new ScopeImpl()\n\n return runScoped(scope, () => program(scope), {\n classify: () => SCOPE_SUCCESS\n })\n }\n} as const\n\n/** Type-level aliases for Scope ownership, outcomes, and cleanup contracts. */\nexport declare namespace Scope {\n /** A Scope whose owner is responsible for calling `close()`. */\n export type Closeable = CloseableScope\n\n /** The outcome supplied to Scope finalizers and resource releases. */\n export type Outcome = ScopeOutcome\n\n /** A cleanup callback registered with a Scope. */\n export type Finalizer = ScopeFinalizer\n\n /** A value implementing a JavaScript disposal protocol. */\n export type Disposable = DisposableResource\n}\n","import { Result } 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 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 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/** 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 { Err, Result as ResultType, UnhandledException } from 'better-result'\n\nimport { Scope } from '../scope'\n\nimport type { DisposableResource, MaybePromise, ScopeOutcome } from '../scope'\nimport type { AnyService } from '../service'\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 recover,\n recoverAsync,\n tap,\n tapBoth,\n tapError,\n zip\n} from './combinators'\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\nexport type ProgramAllOptions = {\n readonly concurrency?: number\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\nconst 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\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 validateProgramConcurrency(options.concurrency)\n\n const concurrency = options.concurrency\n const program = async (): Promise<AnyResult> => {\n const results: Array<AnyResult | undefined> = Array.from({ length: programs.length })\n const failures: boolean[] = Array.from({ length: programs.length }, () => false)\n const causes: unknown[] = Array.from({ length: programs.length })\n let nextIndex = 0\n\n const worker = async (): Promise<void> => {\n while (true) {\n const index = nextIndex++\n\n if (index >= programs.length) {\n return\n }\n\n try {\n results[index] = await programs[index]!()\n } catch (cause) {\n failures[index] = true\n causes[index] = cause\n }\n }\n }\n\n const workers = Math.min(concurrency ?? programs.length, programs.length)\n await Promise.all(Array.from({ length: workers }, () => worker()))\n\n const failureIndex = failures.findIndex(Boolean)\n\n if (failureIndex >= 0) {\n throw causes[failureIndex]\n }\n\n // SAFETY: Program's callable contract produces Result values; the array is erased only at this collection boundary.\n return Result.all(results as AnyResult[])\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/** Value-level namespace for lazy Program combinators. */\nexport const Program = {\n all: programAll\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\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 add: typeof add\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 tapError: typeof tapError\n readonly tapBoth: typeof tapBoth\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 /** Register an already-acquired disposable in the current Scope. */\n add,\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 error values without changing the Result. */\n tapError,\n /** Observe the active Result branch without changing the Result. */\n tapBoth,\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"],"mappings":";;;;;AACA,IAAa,iCAAb,cAAoD,MAAM;CACxD,cAAc;EACZ,MAAM,wDAAwD;EAE9D,KAAK,OAAO;CACd;AACF;;AAGA,IAAa,mBAAb,cAAsC,MAAM;CAC1C,cAAc;EACZ,MAAM,sDAAsD;EAE5D,KAAK,OAAO;CACd;AACF;;AAGA,IAAa,kBAAb,cAAqC,MAAM;CACpB;CAArB,YAAY,QAAqC;EAC/C,MACE,0BAA0B,OAAO,OAAO,YAAY,OAAO,WAAW,IAAI,KAAK,IAAI,SACrF;EAHmB,KAAA,SAAA;EAKnB,KAAK,OAAO;CACd;AACF;;AAGA,IAAa,6BAAb,cAAgD,MAAM;CACpD,cAAc;EACZ,MAAM,mEAAmE;EAEzE,KAAK,OAAO;CACd;AACF;;;AClCA,MAAMA,kBAAgB,EAAE,QAAQ,UAAU;;AAW1C,MAAa,uBAAiC,aAAmD;CAE/F,MAAM,YAAY,OAAO,QAAQ;CACjC,MAAM,eAAe,UAAU,OAAO;CAEtC,IAAI,wBAAwB,UAC1B,aAAa,aAAa,KAAK,QAAQ;CAGzC,MAAM,UAAU,UAAU,OAAO;CAEjC,IAAI,mBAAmB,UACrB,aAAa,QAAQ,KAAK,QAAQ;AAItC;;AAGA,MAAa,mBAA6B,aAAiD;CAGzF,OAFkB,oBAAoB,QAEvB,CAAC,GAAGA,eAAa;AAClC;;;ACtBA,MAAM,gCAAgB,IAAI,QAAuC;;AAGjE,IAAa,eA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,MAAM,OAAO,iBAAiB,MAAM,QAAQ,SAAS,OAAO,CAAC,CAAC;AAC9E;;;;;;;;;;;;;AAcA,SAAgB,IACd,UAC4D;CAC5D,MAAM,QAAQ,MAAM,QAAQ;CAE5B,OAAO,OAAO,MAAM,OAAO,iBAAiB,MAAM,IAAI,QAAQ,CAAC,CAAC;AAClE;AA8BA,MAAa,SAA0B;;CAErC;;CAEA;;CAEA;;CAEA;;CAEA;;CAEA;;CAEA;;CAEA;;CAEA;;CAEA;;CAEA;;CAEA;;CAEA;;CAEA;;CAEA;;CAEA;;CAEA;;CAEA;;CAEA;AACF"}
@@ -0,0 +1,88 @@
1
+ import { A as ProgramFromGenerator, D as EffectYield, E as EffectSuccess, M as AnyService, k as Program } from "./index-1NLNdkJy.mjs";
2
+ import { E as MissingDependencies, S as LayerInput, w as ProvidedEnvironment, x as ExecutionMissing } from "./index-EJlskfAW.mjs";
3
+ import { f as Runtime } from "./index-BsPr7qHf.mjs";
4
+ import { a as CurrentRequest } from "./index-CITM15SE.mjs";
5
+ import { Result } from "better-result";
6
+ import { Context, Env, Handler, HonoRequest, Input, MiddlewareHandler } from "hono";
7
+ //#region src/hono/types.d.ts
8
+ type AnyResult = Result<any, any>;
9
+ type AnyProgram = Program<any, any, AnyService>;
10
+ type HonoContext = Context<any, any, any>;
11
+ type ResponseLike = Response | Promise<Response>;
12
+ type AnyHonoMiddleware = MiddlewareHandler<any, any, any, any>;
13
+ type MiddlewareInput<Middleware extends AnyHonoMiddleware> = Middleware extends MiddlewareHandler<any, any, infer InputType, any> ? InputType : Input;
14
+ type MiddlewareInputs<Middlewares extends readonly AnyHonoMiddleware[]> = Middlewares extends readonly [infer Head extends AnyHonoMiddleware, ...infer Tail extends AnyHonoMiddleware[]] ? MiddlewareInput<Head> & MiddlewareInputs<Tail> : Input;
15
+ type ValidatedTarget<InputType extends Input, Target extends 'param' | 'header'> = NonNullable<InputType['out']> extends Record<Target, infer Value> ? Value extends object ? Value : never : never;
16
+ type ValidatedRequest<P extends string, InputType extends Input> = Omit<HonoRequest<P, NonNullable<InputType['out']>>, 'param' | 'header'> & {
17
+ param: [ValidatedTarget<InputType, 'param'>] extends [never] ? HonoRequest<P, NonNullable<InputType['out']>>['param'] : {
18
+ <Key extends keyof ValidatedTarget<InputType, 'param'> & string>(key: Key): ValidatedTarget<InputType, 'param'>[Key];
19
+ (key: string): string | undefined;
20
+ (): ValidatedTarget<InputType, 'param'>;
21
+ };
22
+ header: [ValidatedTarget<InputType, 'header'>] extends [never] ? HonoRequest<P, NonNullable<InputType['out']>>['header'] : {
23
+ <Key extends keyof ValidatedTarget<InputType, 'header'> & string>(name: Key): ValidatedTarget<InputType, 'header'>[Key];
24
+ (name: string): string | undefined;
25
+ (): ValidatedTarget<InputType, 'header'>;
26
+ };
27
+ };
28
+ type HonoEffectContext<E extends Env, P extends string, InputType extends Input> = Omit<Context<E, P, InputType>, 'req'> & {
29
+ readonly req: ValidatedRequest<P, InputType>;
30
+ };
31
+ type MiddlewareEnvironment<Middleware extends AnyHonoMiddleware> = Middleware extends MiddlewareHandler<infer Environment, any, any, any> ? Environment : Env;
32
+ type MiddlewarePath<Middleware extends AnyHonoMiddleware> = Middleware extends MiddlewareHandler<any, infer Path, any, any> ? Path : string;
33
+ type HonoJsonValue = null | boolean | number | string | readonly HonoJsonValue[] | {
34
+ readonly [key: string]: HonoJsonValue;
35
+ };
36
+ type DefaultRequestLayer = ReturnType<typeof CurrentRequest.layer>;
37
+ type RequestProvided<RequestLayer extends LayerInput> = ProvidedEnvironment<RequestLayer>;
38
+ type AvailableServices<Provided extends AnyService, RequestLayer extends LayerInput> = Provided | InstanceType<typeof CurrentRequest> | RequestProvided<RequestLayer>;
39
+ type ProgramMissing<Provided extends AnyService, Program extends AnyProgram> = ExecutionMissing<Provided, Program>;
40
+ type CompleteProgram<Provided extends AnyService, Program extends AnyProgram> = [ProgramMissing<Provided, Program>] extends [never] ? Program : Program & MissingDependencies<ProgramMissing<Provided, Program>>;
41
+ type GeneratorBody<ContextType extends object, Yield extends EffectYield, Returned extends AnyResult> = (context: ContextType) => Generator<Yield, Returned, unknown> | AsyncGenerator<Yield, Returned, unknown>;
42
+ type GeneratorChecks<Provided extends AnyService, Yield extends EffectYield, Returned extends AnyResult> = [ProgramMissing<Provided, ProgramFromGenerator<Yield, Returned>>] extends [never] ? unknown : MissingDependencies<ProgramMissing<Provided, ProgramFromGenerator<Yield, Returned>>>;
43
+ type HonoEffectSuccess<A = unknown> = {
44
+ readonly value: A;
45
+ readonly status?: number;
46
+ readonly serialize?: (value: A) => HonoJsonValue;
47
+ };
48
+ type HonoEffectOptions<Failure = unknown, RequestLayer extends LayerInput = DefaultRequestLayer> = {
49
+ readonly onSuccess?: (result: HonoEffectSuccess<any>, context: HonoContext) => ResponseLike;
50
+ readonly onFailure?: (error: Failure, context: HonoContext) => ResponseLike;
51
+ readonly requestLayer?: (context: HonoContext) => RequestLayer;
52
+ };
53
+ type HonoEffectRouteOptions<A, ContextType extends HonoContext = HonoContext> = {
54
+ readonly status?: number;
55
+ readonly serialize?: (value: A) => HonoJsonValue;
56
+ readonly respond?: (value: A, context: ContextType) => ResponseLike;
57
+ };
58
+ //#endregion
59
+ //#region src/hono/hono-effect.d.ts
60
+ /** Run Effect Programs inside one Runtime execution per Hono request. */
61
+ declare class HonoEffect<Provided extends AnyService = any, Failure = unknown, RequestLayer extends LayerInput = DefaultRequestLayer> {
62
+ readonly runtime: Runtime<Provided>;
63
+ private readonly states;
64
+ private readonly onSuccess;
65
+ private readonly onFailure;
66
+ private readonly requestLayer;
67
+ private constructor();
68
+ static make<Provided extends AnyService, Failure = unknown, RequestLayer extends LayerInput = DefaultRequestLayer>(runtime: Runtime<Provided>, options?: HonoEffectOptions<Failure, RequestLayer>): HonoEffect<Provided, Failure, RequestLayer>;
69
+ middleware<E extends Env = Env, Path extends string = string>(): MiddlewareHandler<E, Path>;
70
+ handler<E extends Env = Env, Path extends string = string, InputType extends Input = Input, Program extends AnyProgram = AnyProgram>(makeProgram: (context: Context<E, Path, InputType>) => CompleteProgram<AvailableServices<Provided, RequestLayer>, Program>, options?: HonoEffectRouteOptions<EffectSuccess<Program>, Context<E, Path, InputType>>): Handler<E, Path, InputType, Promise<Response>>;
71
+ handler<const FirstMiddleware extends AnyHonoMiddleware, const SecondMiddleware extends AnyHonoMiddleware, E extends Env = MiddlewareEnvironment<FirstMiddleware>, Path extends string = MiddlewarePath<FirstMiddleware>, Program extends AnyProgram = AnyProgram>(firstMiddleware: FirstMiddleware, secondMiddleware: SecondMiddleware, makeProgram: (context: HonoEffectContext<E, Path, MiddlewareInputs<[FirstMiddleware, SecondMiddleware]>>) => CompleteProgram<AvailableServices<Provided, RequestLayer>, Program>, options?: HonoEffectRouteOptions<EffectSuccess<Program>, Context<E, Path, MiddlewareInputs<[FirstMiddleware, SecondMiddleware]>>>): Handler<E, Path, MiddlewareInputs<[FirstMiddleware, SecondMiddleware]>, Promise<Response>>;
72
+ handler<const FirstMiddleware extends AnyHonoMiddleware, const SecondMiddleware extends AnyHonoMiddleware, const ThirdMiddleware extends AnyHonoMiddleware, E extends Env = MiddlewareEnvironment<FirstMiddleware>, Path extends string = MiddlewarePath<FirstMiddleware>, Program extends AnyProgram = AnyProgram>(firstMiddleware: FirstMiddleware, secondMiddleware: SecondMiddleware, thirdMiddleware: ThirdMiddleware, makeProgram: (context: HonoEffectContext<E, Path, MiddlewareInputs<[FirstMiddleware, SecondMiddleware, ThirdMiddleware]>>) => CompleteProgram<AvailableServices<Provided, RequestLayer>, Program>, options?: HonoEffectRouteOptions<EffectSuccess<Program>, Context<E, Path, MiddlewareInputs<[FirstMiddleware, SecondMiddleware, ThirdMiddleware]>>>): Handler<E, Path, MiddlewareInputs<[FirstMiddleware, SecondMiddleware, ThirdMiddleware]>, Promise<Response>>;
73
+ handler<const InputMiddleware extends AnyHonoMiddleware, E extends Env = MiddlewareEnvironment<InputMiddleware>, Path extends string = MiddlewarePath<InputMiddleware>, Program extends AnyProgram = AnyProgram>(inputMiddleware: InputMiddleware, makeProgram: (context: HonoEffectContext<E, Path, MiddlewareInput<InputMiddleware>>) => CompleteProgram<AvailableServices<Provided, RequestLayer>, Program>, options?: HonoEffectRouteOptions<EffectSuccess<Program>, Context<E, Path, MiddlewareInput<InputMiddleware>>>): Handler<E, Path, MiddlewareInput<InputMiddleware>, Promise<Response>>;
74
+ 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<AvailableServices<Provided, RequestLayer>, Yield, Returned>, options?: HonoEffectRouteOptions<EffectSuccess<ProgramFromGenerator<Yield, Returned>>, Context<E, Path, InputType>>): Handler<E, Path, InputType, Promise<Response>>;
75
+ gen<const FirstMiddleware extends AnyHonoMiddleware, const SecondMiddleware extends AnyHonoMiddleware, E extends Env = MiddlewareEnvironment<FirstMiddleware>, Path extends string = MiddlewarePath<FirstMiddleware>, const Yield extends EffectYield = EffectYield, const Returned extends AnyResult = AnyResult>(firstMiddleware: FirstMiddleware, secondMiddleware: SecondMiddleware, body: GeneratorBody<HonoEffectContext<E, Path, MiddlewareInputs<[FirstMiddleware, SecondMiddleware]>>, Yield, Returned> & GeneratorChecks<AvailableServices<Provided, RequestLayer>, Yield, Returned>, options?: HonoEffectRouteOptions<EffectSuccess<ProgramFromGenerator<Yield, Returned>>, Context<E, Path, MiddlewareInputs<[FirstMiddleware, SecondMiddleware]>>>): Handler<E, Path, MiddlewareInputs<[FirstMiddleware, SecondMiddleware]>, Promise<Response>>;
76
+ gen<const FirstMiddleware extends AnyHonoMiddleware, const SecondMiddleware extends AnyHonoMiddleware, const ThirdMiddleware extends AnyHonoMiddleware, E extends Env = MiddlewareEnvironment<FirstMiddleware>, Path extends string = MiddlewarePath<FirstMiddleware>, const Yield extends EffectYield = EffectYield, const Returned extends AnyResult = AnyResult>(firstMiddleware: FirstMiddleware, secondMiddleware: SecondMiddleware, thirdMiddleware: ThirdMiddleware, body: GeneratorBody<HonoEffectContext<E, Path, MiddlewareInputs<[FirstMiddleware, SecondMiddleware, ThirdMiddleware]>>, Yield, Returned> & GeneratorChecks<AvailableServices<Provided, RequestLayer>, Yield, Returned>, options?: HonoEffectRouteOptions<EffectSuccess<ProgramFromGenerator<Yield, Returned>>, Context<E, Path, MiddlewareInputs<[FirstMiddleware, SecondMiddleware, ThirdMiddleware]>>>): Handler<E, Path, MiddlewareInputs<[FirstMiddleware, SecondMiddleware, ThirdMiddleware]>, Promise<Response>>;
77
+ gen<const InputMiddleware extends AnyHonoMiddleware, E extends Env = MiddlewareEnvironment<InputMiddleware>, Path extends string = MiddlewarePath<InputMiddleware>, const Yield extends EffectYield = EffectYield, const Returned extends AnyResult = AnyResult>(inputMiddleware: InputMiddleware, body: GeneratorBody<HonoEffectContext<E, Path, MiddlewareInput<InputMiddleware>>, Yield, Returned> & GeneratorChecks<AvailableServices<Provided, RequestLayer>, Yield, Returned>, options?: HonoEffectRouteOptions<EffectSuccess<ProgramFromGenerator<Yield, Returned>>, Context<E, Path, MiddlewareInput<InputMiddleware>>>): Handler<E, Path, MiddlewareInput<InputMiddleware>, Promise<Response>>;
78
+ 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<AvailableServices<Provided, RequestLayer>, Yield, Returned>): MiddlewareHandler<E, Path>;
79
+ private makeHandler;
80
+ private composeInputMiddleware;
81
+ private getState;
82
+ }
83
+ declare class HonoEffectBoundaryMissingError extends Error {
84
+ constructor();
85
+ }
86
+ //#endregion
87
+ export { type HonoContext, HonoEffect, HonoEffectBoundaryMissingError, type HonoEffectOptions, type HonoEffectRouteOptions, type HonoEffectSuccess, type HonoJsonValue };
88
+ //# sourceMappingURL=hono.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hono.d.mts","names":[],"sources":["../src/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,QAAQ,GAAG,MAAM,YAAY,OAAO,YACtD,gBAAgB,kBAAkB,UAAU,eAAe,OAAO,YACnE,kBAAkB,GAAG;UAiBhB;UAmCA;UAuBA;;cAWG,uCAAuC;EAAA"}
package/dist/hono.mjs ADDED
@@ -0,0 +1,149 @@
1
+ import { r as Layer } from "./signal-Cl9tqGyX.mjs";
2
+ import { t as Effect } from "./effect-CZdZCZLW.mjs";
3
+ import { a as CurrentRequest } from "./standard-services-QseopL9g.mjs";
4
+ import { Result } from "better-result";
5
+ import { createMiddleware } from "hono/factory";
6
+ //#region src/hono/request-boundary.ts
7
+ const makeRequestBoundary = (options) => {
8
+ return createMiddleware(async (context, next) => {
9
+ const key = context;
10
+ if (options.states.get(key) !== void 0) {
11
+ await next();
12
+ return;
13
+ }
14
+ const state = {};
15
+ options.states.set(key, state);
16
+ try {
17
+ const requestLayer = CurrentRequest.layer(context.req.raw);
18
+ const customLayer = options.requestLayer?.(context);
19
+ const layer = customLayer === void 0 ? requestLayer : Layer.override(requestLayer, customLayer);
20
+ await options.runtime.runWith(layer, async () => {
21
+ try {
22
+ await next();
23
+ } catch (cause) {
24
+ state.failure ??= { cause };
25
+ }
26
+ if (state.failure !== void 0) return Result.err(state.failure.cause);
27
+ if (context.error !== void 0) return Result.err(context.error);
28
+ return Result.ok(context.res);
29
+ }, { signal: context.req.raw.signal });
30
+ } finally {
31
+ options.states.delete(key);
32
+ }
33
+ });
34
+ };
35
+ //#endregion
36
+ //#region src/hono/responses.ts
37
+ const defaultSuccess = ({ value, status, serialize }, context) => {
38
+ if (value instanceof Response) return value;
39
+ const body = serialize === void 0 ? value : serialize(value);
40
+ if (body === void 0) return context.body(null, status ?? 204);
41
+ if (status === void 0) return context.json({ data: body });
42
+ return context.json({ data: body }, status);
43
+ };
44
+ const defaultFailure = (error, context) => {
45
+ if (error instanceof Response) return error;
46
+ const message = error instanceof Error ? error.message : String(error);
47
+ return context.json({ error: message }, 500);
48
+ };
49
+ //#endregion
50
+ //#region src/hono/hono-effect.ts
51
+ /** Run Effect Programs inside one Runtime execution per Hono request. */
52
+ var HonoEffect = class HonoEffect {
53
+ runtime;
54
+ states = /* @__PURE__ */ new WeakMap();
55
+ onSuccess;
56
+ onFailure;
57
+ requestLayer;
58
+ constructor(runtime, options) {
59
+ this.runtime = runtime;
60
+ this.onSuccess = options.onSuccess ?? defaultSuccess;
61
+ this.onFailure = options.onFailure ?? defaultFailure;
62
+ this.requestLayer = options.requestLayer;
63
+ }
64
+ static make(runtime, options = {}) {
65
+ return new HonoEffect(runtime, options);
66
+ }
67
+ middleware() {
68
+ return makeRequestBoundary({
69
+ runtime: this.runtime,
70
+ states: this.states,
71
+ requestLayer: this.requestLayer
72
+ });
73
+ }
74
+ handler(...args) {
75
+ const last = args.at(-1);
76
+ const hasOptions = args.length > 1 && (last === void 0 || typeof last !== "function");
77
+ const options = hasOptions ? last : {};
78
+ const bodyIndex = hasOptions ? args.length - 2 : args.length - 1;
79
+ const makeProgram = args[bodyIndex];
80
+ let handler = this.makeHandler(makeProgram, options);
81
+ for (let index = bodyIndex - 1; index >= 0; index -= 1) handler = this.composeInputMiddleware(args[index], handler);
82
+ return handler;
83
+ }
84
+ gen(...args) {
85
+ const last = args.at(-1);
86
+ const hasOptions = args.length > 1 && (last === void 0 || typeof last !== "function");
87
+ const options = hasOptions ? last : {};
88
+ const bodyIndex = hasOptions ? args.length - 2 : args.length - 1;
89
+ const body = args[bodyIndex];
90
+ let handler = this.makeHandler((context) => {
91
+ return Effect.fn(() => body(context));
92
+ }, options);
93
+ for (let index = bodyIndex - 1; index >= 0; index -= 1) handler = this.composeInputMiddleware(args[index], handler);
94
+ return handler;
95
+ }
96
+ guard(body) {
97
+ return async (context, next) => {
98
+ const state = this.getState(context);
99
+ const result = await Effect.fn(() => body(context))();
100
+ if (Result.isError(result)) {
101
+ state.failure ??= { cause: result.error };
102
+ return await this.onFailure(result.error, context);
103
+ }
104
+ await next();
105
+ };
106
+ }
107
+ makeHandler(makeProgram, options) {
108
+ return async (context) => {
109
+ const state = this.getState(context);
110
+ const result = await makeProgram(context)();
111
+ if (Result.isError(result)) {
112
+ state.failure ??= { cause: result.error };
113
+ return await this.onFailure(result.error, context);
114
+ }
115
+ const value = result.value;
116
+ if (options.respond !== void 0) return await options.respond(value, context);
117
+ const success = { value };
118
+ if (options.status !== void 0) Object.assign(success, { status: options.status });
119
+ if (options.serialize !== void 0) Object.assign(success, { serialize: options.serialize });
120
+ return await this.onSuccess(success, context);
121
+ };
122
+ }
123
+ composeInputMiddleware(inputMiddleware, handler) {
124
+ return async (context, next) => {
125
+ let downstreamResponse;
126
+ const middlewareResponse = await inputMiddleware(context, async () => {
127
+ downstreamResponse = await handler(context, next);
128
+ });
129
+ if (middlewareResponse instanceof Response) return middlewareResponse;
130
+ if (downstreamResponse !== void 0) return downstreamResponse;
131
+ return context.res;
132
+ };
133
+ }
134
+ getState(context) {
135
+ const state = this.states.get(context);
136
+ if (state === void 0) throw new HonoEffectBoundaryMissingError();
137
+ return state;
138
+ }
139
+ };
140
+ var HonoEffectBoundaryMissingError = class extends Error {
141
+ constructor() {
142
+ super("Register HonoEffect.middleware() before better-effect handlers");
143
+ this.name = "HonoEffectBoundaryMissingError";
144
+ }
145
+ };
146
+ //#endregion
147
+ export { HonoEffect, HonoEffectBoundaryMissingError };
148
+
149
+ //# sourceMappingURL=hono.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hono.mjs","names":[],"sources":["../src/hono/request-boundary.ts","../src/hono/responses.ts","../src/hono/hono-effect.ts"],"sourcesContent":["import { Result } from 'better-result'\nimport { createMiddleware } from 'hono/factory'\nimport type { Env, MiddlewareHandler } from 'hono'\n\nimport { CurrentRequest } from '../standard-services'\nimport { Layer } from '../layer'\nimport type { LayerInput } from '../layer/inference'\nimport { Runtime } from '../runtime'\nimport type { AnyService } from '../service'\nimport type { HonoContext } from './types'\n\nexport type RequestState = {\n failure?: {\n readonly cause: unknown\n }\n}\n\nexport type RequestBoundaryOptions<Provided extends AnyService, RequestLayer extends LayerInput> = {\n readonly runtime: Runtime<Provided>\n readonly states: WeakMap<object, RequestState>\n readonly requestLayer?: ((context: HonoContext) => RequestLayer) | undefined\n}\n\nexport const makeRequestBoundary = <\n Provided extends AnyService,\n RequestLayer extends LayerInput,\n E extends Env = Env,\n Path extends string = string\n>(\n options: RequestBoundaryOptions<Provided, RequestLayer>\n): MiddlewareHandler<E, Path> => {\n // SAFETY: createMiddleware preserves the Hono handler contract; only the generic Context is restored here.\n return createMiddleware(async (context, next) => {\n const key = context\n const existing = options.states.get(key)\n\n if (existing !== undefined) {\n await next()\n return\n }\n\n const state: RequestState = {}\n options.states.set(key, state)\n\n try {\n const requestLayer = CurrentRequest.layer(context.req.raw)\n const customLayer = options.requestLayer?.(context)\n // SAFETY: a custom request Layer extends or intentionally overrides the built-in CurrentRequest provider.\n const layer =\n customLayer === undefined\n ? requestLayer\n : Layer.override(requestLayer, customLayer as never)\n\n // SAFETY: request Layers are supplied by this adapter and execute inside the Runtime's typed boundary.\n await options.runtime.runWith(\n layer as never,\n async () => {\n try {\n await next()\n } catch (cause) {\n state.failure ??= { cause }\n }\n\n if (state.failure !== undefined) {\n return Result.err(state.failure.cause)\n }\n\n if (context.error !== undefined) {\n return Result.err(context.error)\n }\n\n return Result.ok(context.res)\n },\n { signal: context.req.raw.signal }\n )\n } finally {\n options.states.delete(key)\n }\n }) as MiddlewareHandler<E, Path>\n}\n","import type { HonoContext, HonoEffectSuccess } from './types'\n\nexport const defaultSuccess = (\n { value, status, serialize }: HonoEffectSuccess,\n context: HonoContext\n): Response => {\n if (value instanceof Response) {\n return value\n }\n\n const body = serialize === undefined ? value : serialize(value)\n\n if (body === undefined) {\n // SAFETY: route status is intentionally configurable and Hono validates it at response construction.\n return context.body(null, (status ?? 204) as never)\n }\n\n if (status === undefined) {\n return context.json({ data: body })\n }\n\n // SAFETY: route status is intentionally configurable and Hono validates it at response construction.\n return context.json({ data: body }, status as never)\n}\n\n// oxlint-disable-next-line anti-slop/no-unknown-parameters -- Result errors are intentionally opaque at this HTTP boundary.\nexport const defaultFailure = (error: unknown, context: HonoContext): Response => {\n if (error instanceof Response) {\n return error\n }\n\n const message = error instanceof Error ? error.message : String(error)\n\n return context.json({ error: message }, 500)\n}\n","import { Result } from 'better-result'\nimport type { Context, Env, Handler, Input, MiddlewareHandler } from 'hono'\n\nimport { Effect } from '../effect'\nimport type { EffectSuccess, EffectYield, ProgramFromGenerator } from '../effect/types'\nimport { Runtime } from '../runtime'\nimport type { LayerInput } from '../layer/inference'\nimport type { AnyService } from '../service'\nimport { makeRequestBoundary, type RequestState } from './request-boundary'\nimport { defaultFailure, defaultSuccess } from './responses'\nimport type {\n AnyGeneratorBody,\n AnyHonoMiddleware,\n AnyProgram,\n AnyProgramFactory,\n AnyResult,\n AnyRouteOptions,\n AvailableServices,\n CompleteProgram,\n DefaultRequestLayer,\n GeneratorBody,\n GeneratorChecks,\n HonoContext,\n HonoEffectContext,\n HonoEffectOptions,\n HonoEffectRouteOptions,\n HonoEffectSuccess,\n MiddlewareEnvironment,\n MiddlewareInput,\n MiddlewareInputs,\n MiddlewarePath\n} from './types'\n\n/** Run Effect Programs inside one Runtime execution per Hono request. */\nexport class HonoEffect<\n Provided extends AnyService = any,\n Failure = unknown,\n RequestLayer extends LayerInput = DefaultRequestLayer\n> {\n readonly runtime: Runtime<Provided>\n\n private readonly states = new WeakMap<object, RequestState>()\n\n private readonly onSuccess: NonNullable<HonoEffectOptions<Failure, RequestLayer>['onSuccess']>\n\n private readonly onFailure: NonNullable<HonoEffectOptions<Failure, RequestLayer>['onFailure']>\n\n private readonly requestLayer: HonoEffectOptions<Failure, RequestLayer>['requestLayer']\n\n private constructor(\n runtime: Runtime<Provided>,\n options: HonoEffectOptions<Failure, RequestLayer>\n ) {\n this.runtime = runtime\n this.onSuccess = options.onSuccess ?? defaultSuccess\n this.onFailure = options.onFailure ?? defaultFailure\n this.requestLayer = options.requestLayer\n }\n\n static make<\n Provided extends AnyService,\n Failure = unknown,\n RequestLayer extends LayerInput = DefaultRequestLayer\n >(\n runtime: Runtime<Provided>,\n options: HonoEffectOptions<Failure, RequestLayer> = {}\n ): HonoEffect<Provided, Failure, RequestLayer> {\n return new HonoEffect(runtime, options)\n }\n\n middleware<E extends Env = Env, Path extends string = string>(): MiddlewareHandler<E, Path> {\n return makeRequestBoundary<Provided, RequestLayer, E, Path>({\n runtime: this.runtime,\n states: this.states,\n requestLayer: this.requestLayer\n })\n }\n\n handler<\n E extends Env = Env,\n Path extends string = string,\n InputType extends Input = Input,\n Program extends AnyProgram = AnyProgram\n >(\n makeProgram: (\n context: Context<E, Path, InputType>\n ) => CompleteProgram<AvailableServices<Provided, RequestLayer>, Program>,\n options?: HonoEffectRouteOptions<EffectSuccess<Program>, Context<E, Path, InputType>>\n ): Handler<E, Path, InputType, Promise<Response>>\n handler<\n const FirstMiddleware extends AnyHonoMiddleware,\n const SecondMiddleware extends AnyHonoMiddleware,\n E extends Env = MiddlewareEnvironment<FirstMiddleware>,\n Path extends string = MiddlewarePath<FirstMiddleware>,\n Program extends AnyProgram = AnyProgram\n >(\n firstMiddleware: FirstMiddleware,\n secondMiddleware: SecondMiddleware,\n makeProgram: (\n context: HonoEffectContext<E, Path, MiddlewareInputs<[FirstMiddleware, SecondMiddleware]>>\n ) => CompleteProgram<AvailableServices<Provided, RequestLayer>, Program>,\n options?: HonoEffectRouteOptions<\n EffectSuccess<Program>,\n Context<E, Path, MiddlewareInputs<[FirstMiddleware, SecondMiddleware]>>\n >\n ): Handler<E, Path, MiddlewareInputs<[FirstMiddleware, SecondMiddleware]>, Promise<Response>>\n handler<\n const FirstMiddleware extends AnyHonoMiddleware,\n const SecondMiddleware extends AnyHonoMiddleware,\n const ThirdMiddleware extends AnyHonoMiddleware,\n E extends Env = MiddlewareEnvironment<FirstMiddleware>,\n Path extends string = MiddlewarePath<FirstMiddleware>,\n Program extends AnyProgram = AnyProgram\n >(\n firstMiddleware: FirstMiddleware,\n secondMiddleware: SecondMiddleware,\n thirdMiddleware: ThirdMiddleware,\n makeProgram: (\n context: HonoEffectContext<\n E,\n Path,\n MiddlewareInputs<[FirstMiddleware, SecondMiddleware, ThirdMiddleware]>\n >\n ) => CompleteProgram<AvailableServices<Provided, RequestLayer>, Program>,\n options?: HonoEffectRouteOptions<\n EffectSuccess<Program>,\n Context<E, Path, MiddlewareInputs<[FirstMiddleware, SecondMiddleware, ThirdMiddleware]>>\n >\n ): Handler<\n E,\n Path,\n MiddlewareInputs<[FirstMiddleware, SecondMiddleware, ThirdMiddleware]>,\n Promise<Response>\n >\n handler<\n const InputMiddleware extends AnyHonoMiddleware,\n E extends Env = MiddlewareEnvironment<InputMiddleware>,\n Path extends string = MiddlewarePath<InputMiddleware>,\n Program extends AnyProgram = AnyProgram\n >(\n inputMiddleware: InputMiddleware,\n makeProgram: (\n context: HonoEffectContext<E, Path, MiddlewareInput<InputMiddleware>>\n ) => CompleteProgram<AvailableServices<Provided, RequestLayer>, Program>,\n options?: HonoEffectRouteOptions<\n EffectSuccess<Program>,\n Context<E, Path, MiddlewareInput<InputMiddleware>>\n >\n ): Handler<E, Path, MiddlewareInput<InputMiddleware>, Promise<Response>>\n handler(...args: unknown[]): Handler<any, any, any, Promise<Response>> {\n const last = args.at(-1)\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- overload dispatch separates route options from function callbacks.\n const hasOptions = args.length > 1 && (last === undefined || typeof last !== 'function')\n // SAFETY: the overloads restrict the optional trailing argument to route options.\n const options = (hasOptions ? last : {}) as AnyRouteOptions\n const bodyIndex = hasOptions ? args.length - 2 : args.length - 1\n // SAFETY: the overloads place the program factory immediately before route options.\n const makeProgram = args[bodyIndex] as AnyProgramFactory\n let handler = this.makeHandler(makeProgram, options)\n\n for (let index = bodyIndex - 1; index >= 0; index -= 1) {\n // SAFETY: every argument before the program factory is an input middleware by the overloads.\n handler = this.composeInputMiddleware(args[index] as AnyHonoMiddleware, handler)\n }\n\n return handler\n }\n\n gen<\n E extends Env = Env,\n Path extends string = string,\n InputType extends Input = Input,\n const Yield extends EffectYield = EffectYield,\n const Returned extends AnyResult = AnyResult\n >(\n body: GeneratorBody<Context<E, Path, InputType>, Yield, Returned> &\n GeneratorChecks<AvailableServices<Provided, RequestLayer>, Yield, Returned>,\n options?: HonoEffectRouteOptions<\n EffectSuccess<ProgramFromGenerator<Yield, Returned>>,\n Context<E, Path, InputType>\n >\n ): Handler<E, Path, InputType, Promise<Response>>\n gen<\n const FirstMiddleware extends AnyHonoMiddleware,\n const SecondMiddleware extends AnyHonoMiddleware,\n E extends Env = MiddlewareEnvironment<FirstMiddleware>,\n Path extends string = MiddlewarePath<FirstMiddleware>,\n const Yield extends EffectYield = EffectYield,\n const Returned extends AnyResult = AnyResult\n >(\n firstMiddleware: FirstMiddleware,\n secondMiddleware: SecondMiddleware,\n body: GeneratorBody<\n HonoEffectContext<E, Path, MiddlewareInputs<[FirstMiddleware, SecondMiddleware]>>,\n Yield,\n Returned\n > &\n GeneratorChecks<AvailableServices<Provided, RequestLayer>, Yield, Returned>,\n options?: HonoEffectRouteOptions<\n EffectSuccess<ProgramFromGenerator<Yield, Returned>>,\n Context<E, Path, MiddlewareInputs<[FirstMiddleware, SecondMiddleware]>>\n >\n ): Handler<E, Path, MiddlewareInputs<[FirstMiddleware, SecondMiddleware]>, Promise<Response>>\n gen<\n const FirstMiddleware extends AnyHonoMiddleware,\n const SecondMiddleware extends AnyHonoMiddleware,\n const ThirdMiddleware extends AnyHonoMiddleware,\n E extends Env = MiddlewareEnvironment<FirstMiddleware>,\n Path extends string = MiddlewarePath<FirstMiddleware>,\n const Yield extends EffectYield = EffectYield,\n const Returned extends AnyResult = AnyResult\n >(\n firstMiddleware: FirstMiddleware,\n secondMiddleware: SecondMiddleware,\n thirdMiddleware: ThirdMiddleware,\n body: GeneratorBody<\n HonoEffectContext<\n E,\n Path,\n MiddlewareInputs<[FirstMiddleware, SecondMiddleware, ThirdMiddleware]>\n >,\n Yield,\n Returned\n > &\n GeneratorChecks<AvailableServices<Provided, RequestLayer>, Yield, Returned>,\n options?: HonoEffectRouteOptions<\n EffectSuccess<ProgramFromGenerator<Yield, Returned>>,\n Context<E, Path, MiddlewareInputs<[FirstMiddleware, SecondMiddleware, ThirdMiddleware]>>\n >\n ): Handler<\n E,\n Path,\n MiddlewareInputs<[FirstMiddleware, SecondMiddleware, ThirdMiddleware]>,\n Promise<Response>\n >\n gen<\n const InputMiddleware extends AnyHonoMiddleware,\n E extends Env = MiddlewareEnvironment<InputMiddleware>,\n Path extends string = MiddlewarePath<InputMiddleware>,\n const Yield extends EffectYield = EffectYield,\n const Returned extends AnyResult = AnyResult\n >(\n inputMiddleware: InputMiddleware,\n body: GeneratorBody<\n HonoEffectContext<E, Path, MiddlewareInput<InputMiddleware>>,\n Yield,\n Returned\n > &\n GeneratorChecks<AvailableServices<Provided, RequestLayer>, Yield, Returned>,\n options?: HonoEffectRouteOptions<\n EffectSuccess<ProgramFromGenerator<Yield, Returned>>,\n Context<E, Path, MiddlewareInput<InputMiddleware>>\n >\n ): Handler<E, Path, MiddlewareInput<InputMiddleware>, Promise<Response>>\n gen(...args: unknown[]): Handler<any, any, any, Promise<Response>> {\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- overload dispatch distinguishes middleware from the generator body.\n const last = args.at(-1)\n // oxlint-disable-next-line anti-slop/no-runtime-typeof -- overload dispatch separates route options from function callbacks.\n const hasOptions = args.length > 1 && (last === undefined || typeof last !== 'function')\n // SAFETY: the overloads restrict the optional trailing argument to route options.\n const options = (hasOptions ? last : {}) as AnyRouteOptions\n const bodyIndex = hasOptions ? args.length - 2 : args.length - 1\n // SAFETY: the overloads place the generator body immediately before route options.\n const body = args[bodyIndex] as AnyGeneratorBody\n\n let handler = this.makeHandler((context) => {\n // SAFETY: Effect.fn's runtime generator accepts both sync and async generators; the cast only joins its overloads.\n const program = Effect.fn(\n () => body(context) as AsyncGenerator<EffectYield, AnyResult, unknown>\n )\n\n // SAFETY: the public GeneratorChecks overload validates requirements before this erased boundary.\n return program as AnyProgram\n }, options)\n\n for (let index = bodyIndex - 1; index >= 0; index -= 1) {\n // SAFETY: every argument before the generator body is an input middleware by the overloads.\n handler = this.composeInputMiddleware(args[index] as AnyHonoMiddleware, handler)\n }\n\n return handler\n }\n\n guard<\n E extends Env = Env,\n Path extends string = string,\n InputType extends Input = Input,\n const Yield extends EffectYield = EffectYield,\n const Returned extends AnyResult = AnyResult\n >(\n body: GeneratorBody<Context<E, Path, InputType>, Yield, Returned> &\n GeneratorChecks<AvailableServices<Provided, RequestLayer>, Yield, Returned>\n ): MiddlewareHandler<E, Path> {\n return async (context, next) => {\n const state = this.getState(context)\n // SAFETY: Effect.fn accepts the sync or async generator supplied by the caller; this joins its overloads.\n const program = Effect.fn(() => body(context) as AsyncGenerator<Yield, Returned, unknown>)\n const result = await program()\n\n if (Result.isError(result)) {\n state.failure ??= { cause: result.error }\n // SAFETY: the configured failure policy is the boundary for this guard's Result error channel.\n return await this.onFailure(result.error as Failure, context)\n }\n\n await next()\n }\n }\n\n private makeHandler(\n makeProgram: (context: HonoContext) => AnyProgram,\n options: HonoEffectRouteOptions<any, any>\n ): Handler<any, any, any, Promise<Response>> {\n return async (context) => {\n const state = this.getState(context)\n const program = makeProgram(context)\n const result = await program()\n\n if (Result.isError(result)) {\n state.failure ??= { cause: result.error }\n // SAFETY: the configured failure policy is the boundary for this Program's Result error channel.\n return await this.onFailure(result.error as Failure, context)\n }\n\n const value = result.value\n\n if (options.respond !== undefined) {\n return await options.respond(value, context)\n }\n\n const success: HonoEffectSuccess<any> = { value }\n\n if (options.status !== undefined) {\n Object.assign(success, { status: options.status })\n }\n\n if (options.serialize !== undefined) {\n Object.assign(success, { serialize: options.serialize })\n }\n\n return await this.onSuccess(success, context)\n }\n }\n\n private composeInputMiddleware(\n inputMiddleware: AnyHonoMiddleware,\n handler: Handler<any, any, any, Promise<Response>>\n ): Handler<any, any, any, Promise<Response>> {\n return async (context, next) => {\n let downstreamResponse: Response | undefined\n\n const middlewareResponse = await inputMiddleware(context, async () => {\n downstreamResponse = await handler(context, next)\n })\n\n if (middlewareResponse instanceof Response) {\n return middlewareResponse\n }\n\n if (downstreamResponse !== undefined) {\n return downstreamResponse\n }\n\n return context.res\n }\n }\n\n private getState(context: HonoContext): RequestState {\n const state = this.states.get(context)\n\n if (state === undefined) {\n throw new HonoEffectBoundaryMissingError()\n }\n\n return state\n }\n}\n\nexport class HonoEffectBoundaryMissingError extends Error {\n constructor() {\n super('Register HonoEffect.middleware() before better-effect handlers')\n this.name = 'HonoEffectBoundaryMissingError'\n }\n}\n"],"mappings":";;;;;;AAuBA,MAAa,uBAMX,YAC+B;CAE/B,OAAO,iBAAiB,OAAO,SAAS,SAAS;EAC/C,MAAM,MAAM;EAGZ,IAFiB,QAAQ,OAAO,IAAI,GAEzB,MAAM,KAAA,GAAW;GAC1B,MAAM,KAAK;GACX;EACF;EAEA,MAAM,QAAsB,CAAC;EAC7B,QAAQ,OAAO,IAAI,KAAK,KAAK;EAE7B,IAAI;GACF,MAAM,eAAe,eAAe,MAAM,QAAQ,IAAI,GAAG;GACzD,MAAM,cAAc,QAAQ,eAAe,OAAO;GAElD,MAAM,QACJ,gBAAgB,KAAA,IACZ,eACA,MAAM,SAAS,cAAc,WAAoB;GAGvD,MAAM,QAAQ,QAAQ,QACpB,OACA,YAAY;IACV,IAAI;KACF,MAAM,KAAK;IACb,SAAS,OAAO;KACd,MAAM,YAAY,EAAE,MAAM;IAC5B;IAEA,IAAI,MAAM,YAAY,KAAA,GACpB,OAAO,OAAO,IAAI,MAAM,QAAQ,KAAK;IAGvC,IAAI,QAAQ,UAAU,KAAA,GACpB,OAAO,OAAO,IAAI,QAAQ,KAAK;IAGjC,OAAO,OAAO,GAAG,QAAQ,GAAG;GAC9B,GACA,EAAE,QAAQ,QAAQ,IAAI,IAAI,OAAO,CACnC;EACF,UAAU;GACR,QAAQ,OAAO,OAAO,GAAG;EAC3B;CACF,CAAC;AACH;;;AC7EA,MAAa,kBACX,EAAE,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