resultar 3.7.0 → 3.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,88 @@
1
+ # Typed services and HTTP scopes
2
+
3
+ Read the installed `resultar-di/README.md`, `resultar-hono/README.md` and `resultar-fastify/README.md` for the exact companion
4
+ versions. The application DI helpers are `createModule`, `service`, `Service`, and `resource`.
5
+ Named factory overloads and low-level adapter access use the same `resultar-di` entry point.
6
+ The former `/advanced` subpath has been removed; migrate existing imports to `resultar-di`.
7
+
8
+ - Use `ResultTask.service<Contract>()('name')` in core or `Service.require<Contract>()('name')`
9
+ in DI to infer the literal identifier. The direct core overload remains supported; do not invent
10
+ `Result.service`. Service requirements are represented by `R` in `ResultTask<T, E, R>`.
11
+ - Declare class services with `Service('name', { requires: { alias: Token }, make: ({ alias }) =>
12
+ ResultTask.sync(...) })`. The readonly dependency object is inferred; `make` must return a
13
+ ResultTask, never a plain object or Promise. Use `ResultTask.gen` for initialization with more
14
+ steps. Without `requires`, pass a task directly as `make` and yield requirements inline or by token.
15
+ Both forms support `Service<Contract>()('name', definition)`.
16
+ - Keep provider registration explicit. `requires` does not acquire or register dependencies.
17
+ Inline tokens resolve by name in DI or `provideServices`; core `provideService` supplies an exact
18
+ token binding plus a named fallback. Reuse the same token for exact identity when identifiers
19
+ collide; separately created tags can resolve the named fallback.
20
+ - Register a service token with `.singleton(Token)`, `.scoped(Token)`, or `.transient(Token)`.
21
+ Dependency objects are inferred from tokens. Use `service(name, task)` for asynchronous
22
+ initialization; an async function passed as an ordinary factory is a defect in the contract.
23
+ - Keep a server's serving-and-waiting task inside its owning `use` / ResultTask scope. Returning a
24
+ live resource from a completed scope returns a resource whose finalizer has already run.
25
+ - Use `createHonoApp` for Hono routes. Ordinary `await` and `result.match` inside a route are valid;
26
+ generator-specific restrictions do not apply to a route body.
27
+ Export `type AppHono = Hono<{ Bindings: InferRequestServices<typeof createApplication> }>`
28
+ from `main.ts`, using `InferRequestServices` from `resultar-hono`. Separate route files import
29
+ `AppHono` with `import type` and receive `(app: AppHono)`. Bindings follow the application
30
+ selection without repeating service tokens.
31
+ - `bindings` is optional in `createHonoApp`, `createFastifyApp` and `createFastifyPlugin`.
32
+ Omission selects all registrations; an explicit list restricts the view and `[]` selects none.
33
+ Selected services resolve before the handler, preserving each lifetime and resource ownership.
34
+ Unused default-selected services can still fail acquisition and prevent the handler.
35
+ Fastify `appBindings` continues to default to `[]`; locals satisfy requirements without being
36
+ automatically exposed as registrations. The Hono middleware API still takes explicit keys.
37
+ - Use `createHonoServices(module).middleware(keys, { locals })` to add services to an existing Hono
38
+ router. Inline route middleware infers `c.var.services` while preserving `c.env` and native RPC
39
+ responses. Install one services middleware per request; consume/cancel responses before `close()`.
40
+ - Use `createFastifyApp({ services, bindings? }, configure)` for a new native Fastify application,
41
+ or `createFastifyPlugin({ services, bindings?, appBindings?, locals? })` for an existing server.
42
+ Derive `FastifyRequest.services` once with
43
+ `InferRequestServices<typeof createApplication>` directly in `main.ts` or in a declaration
44
+ file included by TypeScript. `InferAppServices` also accepts the application return type. Both follow the
45
+ selected bindings or custom exposed views; no global types or runtime metadata are installed
46
+ by the adapter. Native routes and autoload do not need wrappers.
47
+ `app.services` contains the selected startup singletons; `request.services` is available from
48
+ `preHandler` through response completion. Register authentication providing locals earlier.
49
+ Infer decorators with `InferAppServices` / `InferRequestServices`; augment Fastify in the application
50
+ or use its typed `getDecorator`. Annotate module/locals callback parameters with native Fastify
51
+ types when their inferred return values participate in selection checking.
52
+ - Keep business logic in plain factories with async methods when sufficient. Register them using
53
+ `service(name, dependencies, factory)`. Map results explicitly through `matchTags` and native
54
+ response APIs; the framework adapters install no status table or `reply.result` helper.
55
+ - `scope.useSingletons(keys, callback)` restricts selected services and callback tokens to the root
56
+ lifetime. Keep its callback active while serving; it is not a free-standing resolver. Factory
57
+ initialization stays lazy until selection; resource release remains explicit.
58
+ - `scope.fetch`, `services.http`, and `createHonoApp` keep the request scope open until the Response
59
+ body ends, fails, or is canceled. Tests must consume or cancel response bodies before shutdown.
60
+ - Stop and drain the server, finish/cancel persistent streams, then await application close.
61
+ Handle typed release errors; defects and composite causes may reject `close()`.
62
+ - Supply authenticated request locals through the appropriate per-request integration. A singleton
63
+ cannot capture scoped services or request-local data. Extracting authentication remains the
64
+ framework adapter's responsibility.
65
+
66
+ For a complete runnable pattern, see the workspace `examples/hono/` and `examples/resultar/`
67
+ application lifecycle examples. The distributed guide includes the checked core recipe at
68
+ `examples/workflow.mjs`; use the published declarations to adapt companion integrations.
69
+
70
+ ## Framework DI exports
71
+
72
+ `resultar-fastify` and `resultar-hono` reexport the application DI helpers: `createModule`, `Service`,
73
+ `service`, `resource`, plus `HttpApplication`, `ServiceClass`, `ServiceLifetime`, `ServiceModule`
74
+ and `ServiceScope` types. In framework-specific code, import these from the adapter together
75
+ with its integration helpers. Core APIs such as `ResultTask` still come from `resultar`.
76
+ Keep direct `resultar-di` imports and dependencies in framework-independent shared code and
77
+ for framework adapter helpers such as `withProvider` and `useServiceAccess`. Check the installed adapter exports before using this convenience
78
+ with older versions.
79
+
80
+ ## Runnable HTTP examples
81
+
82
+ The maintained Fastify and Hono examples each contain their own `services.ts`, `routes.ts`
83
+ and `main.ts`. `services.ts` declares `Cache`, `UsersRepository` and `Users` classes,
84
+ function-based `Health`, and the `createServices` module factory. `main.ts` omits
85
+ `bindings` and owns framework typing and startup. The default request view includes all
86
+ registered services, including the cache and repository. Do not introduce
87
+ a shared package, separate `users.ts` or an extra `app.ts` for these small examples.
88
+ Start either example with `pnpm dev` from its directory; `PORT` defaults to 3000.
@@ -0,0 +1,10 @@
1
+ {
2
+ "resultar-check": "3.2.0",
3
+ "resultar-di": "0.3.0",
4
+ "resultar-fastify": "0.3.0",
5
+ "resultar-hono": "0.3.0",
6
+ "resultar-request": "0.1.2",
7
+ "resultar-request-typebox": "0.1.2",
8
+ "resultar-request-zod": "0.1.2",
9
+ "resultar": "3.9.0"
10
+ }
package/dist/index.d.ts CHANGED
@@ -365,7 +365,7 @@ interface ErrResult<T, E> extends ResultOperations<T, E> {
365
365
  readonly error: E;
366
366
  }
367
367
  /** Success-or-failure value with explicit Ok and Err channels. */
368
- type Result<T, E> = OkResult<T, E> | ErrResult<T, E>;
368
+ export type Result<T, E> = OkResult<T, E> | ErrResult<T, E>;
369
369
  /** `Result` convention that restricts the error channel to real `Error` instances. */
370
370
  type StrictResult<T, E extends Error = Error> = Result<T, E>;
371
371
  /**
@@ -541,12 +541,12 @@ interface ResultStatic {
541
541
  };
542
542
  }
543
543
  /** Static helpers for creating, combining, and iterating over Result values. */
544
- declare const Result: ResultStatic;
544
+ export declare const Result: ResultStatic;
545
545
  /**
546
546
  * A `Disposable` is an object that has a `dispose` method that can be used to
547
547
  * clean up resources.
548
548
  */
549
- declare class DisposableResult<T, E> implements Resultable<T, E>, Disposable {
549
+ export declare class DisposableResult<T, E> implements Resultable<T, E>, Disposable {
550
550
  private disposed;
551
551
  private readonly finalizer;
552
552
  /**
@@ -598,14 +598,14 @@ declare class DisposableResult<T, E> implements Resultable<T, E>, Disposable {
598
598
  * Inside the generator, use `yield* result` to unwrap Ok values and short-circuit on Err. The object
599
599
  * form can map thrown setup errors into the Result error channel.
600
600
  */
601
- declare function safeTry<T, E, CatchErr = E>(input: SafeTryOptions<Result<never, E>, Result<T, E>, CatchErr> & {
601
+ export declare function safeTry<T, E, CatchErr = E>(input: SafeTryOptions<Result<never, E>, Result<T, E>, CatchErr> & {
602
602
  readonly catch: (e: unknown) => CatchErr;
603
603
  }): Result<T, E | CatchErr>;
604
- declare function safeTry<T, E>(input: (() => Generator<Result<never, E>, Result<T, E>>) | SafeTryOptions<Result<never, E>, Result<T, E>>): Result<T, E>;
605
- declare function safeTry<YieldErr extends Result<never, unknown>, GeneratorReturnResult extends Result<unknown, unknown>, CatchErr>(input: SafeTryOptions<YieldErr, GeneratorReturnResult, CatchErr> & {
604
+ export declare function safeTry<T, E>(input: (() => Generator<Result<never, E>, Result<T, E>>) | SafeTryOptions<Result<never, E>, Result<T, E>>): Result<T, E>;
605
+ export declare function safeTry<YieldErr extends Result<never, unknown>, GeneratorReturnResult extends Result<unknown, unknown>, CatchErr>(input: SafeTryOptions<YieldErr, GeneratorReturnResult, CatchErr> & {
606
606
  readonly catch: (e: unknown) => CatchErr;
607
607
  }): Result<InferOkTypes<GeneratorReturnResult>, InferErrTypes<YieldErr> | InferErrTypes<GeneratorReturnResult> | CatchErr>;
608
- declare function safeTry<YieldErr extends Result<never, unknown>, GeneratorReturnResult extends Result<unknown, unknown>>(input: (() => Generator<YieldErr, GeneratorReturnResult>) | SafeTryOptions<YieldErr, GeneratorReturnResult>): Result<InferOkTypes<GeneratorReturnResult>, InferErrTypes<YieldErr> | InferErrTypes<GeneratorReturnResult>>;
608
+ export declare function safeTry<YieldErr extends Result<never, unknown>, GeneratorReturnResult extends Result<unknown, unknown>>(input: (() => Generator<YieldErr, GeneratorReturnResult>) | SafeTryOptions<YieldErr, GeneratorReturnResult>): Result<InferOkTypes<GeneratorReturnResult>, InferErrTypes<YieldErr> | InferErrTypes<GeneratorReturnResult>>;
609
609
  /**
610
610
  * Evaluates an async generator and returns a ResultAsync for the first yielded Err or returned
611
611
  * Result.
@@ -614,31 +614,31 @@ declare function safeTry<YieldErr extends Result<never, unknown>, GeneratorRetur
614
614
  * short-circuit on Err. The object form can map thrown or rejected setup errors into the ResultAsync
615
615
  * error channel.
616
616
  */
617
- declare function safeTry<T, E, CatchErr = E>(input: SafeTryAsyncOptions<Result<never, E>, Result<T, E>, CatchErr> & {
617
+ export declare function safeTry<T, E, CatchErr = E>(input: SafeTryAsyncOptions<Result<never, E>, Result<T, E>, CatchErr> & {
618
618
  readonly catch: (e: unknown) => CatchErr;
619
619
  }): ResultAsync<T, E | CatchErr>;
620
- declare function safeTry<T, E>(input: (() => AsyncGenerator<Result<never, E>, Result<T, E>>) | SafeTryAsyncOptions<Result<never, E>, Result<T, E>>): ResultAsync<T, E>;
621
- declare function safeTry<YieldErr extends Result<never, unknown>, GeneratorReturnResult extends Result<unknown, unknown>, CatchErr>(input: SafeTryAsyncOptions<YieldErr, GeneratorReturnResult, CatchErr> & {
620
+ export declare function safeTry<T, E>(input: (() => AsyncGenerator<Result<never, E>, Result<T, E>>) | SafeTryAsyncOptions<Result<never, E>, Result<T, E>>): ResultAsync<T, E>;
621
+ export declare function safeTry<YieldErr extends Result<never, unknown>, GeneratorReturnResult extends Result<unknown, unknown>, CatchErr>(input: SafeTryAsyncOptions<YieldErr, GeneratorReturnResult, CatchErr> & {
622
622
  readonly catch: (e: unknown) => CatchErr;
623
623
  }): ResultAsync<InferOkTypes<GeneratorReturnResult>, InferErrTypes<YieldErr> | InferErrTypes<GeneratorReturnResult> | CatchErr>;
624
- declare function safeTry<YieldErr extends Result<never, unknown>, GeneratorReturnResult extends Result<unknown, unknown>>(input: (() => AsyncGenerator<YieldErr, GeneratorReturnResult>) | SafeTryAsyncOptions<YieldErr, GeneratorReturnResult>): ResultAsync<InferOkTypes<GeneratorReturnResult>, InferErrTypes<YieldErr> | InferErrTypes<GeneratorReturnResult>>;
624
+ export declare function safeTry<YieldErr extends Result<never, unknown>, GeneratorReturnResult extends Result<unknown, unknown>>(input: (() => AsyncGenerator<YieldErr, GeneratorReturnResult>) | SafeTryAsyncOptions<YieldErr, GeneratorReturnResult>): ResultAsync<InferOkTypes<GeneratorReturnResult>, InferErrTypes<YieldErr> | InferErrTypes<GeneratorReturnResult>>;
625
625
  /**
626
626
  * Creates an Ok result.
627
627
  */
628
- declare function ok<T, E = never>(value: T): OkResult<T, E>;
629
- declare function ok<E = never>(value: void): OkResult<void, E>;
628
+ export declare function ok<T, E = never>(value: T): OkResult<T, E>;
629
+ export declare function ok<E = never>(value: void): OkResult<void, E>;
630
630
  /**
631
631
  * Creates an Err result.
632
632
  */
633
- declare function err<T = never, E extends string = string>(err: E): ErrResult<T, E>;
634
- declare function err<T = never, E = unknown>(err: E): ErrResult<T, E>;
635
- declare function err<T = never>(err: void): ErrResult<T, void>;
633
+ export declare function err<T = never, E extends string = string>(err: E): ErrResult<T, E>;
634
+ export declare function err<T = never, E = unknown>(err: E): ErrResult<T, E>;
635
+ export declare function err<T = never>(err: void): ErrResult<T, void>;
636
636
  /**
637
637
  * Wraps a throwing synchronous function so every later call returns a Result.
638
638
  *
639
639
  * Prefer `tryResult` when you want to run the operation immediately.
640
640
  */
641
- declare const fromThrowable: typeof Result.fromThrowable;
641
+ export declare const fromThrowable: typeof Result.fromThrowable;
642
642
  /**
643
643
  * Runs synchronous work and captures thrown values into `Result<T, E>`.
644
644
  *
@@ -654,14 +654,14 @@ declare const fromThrowable: typeof Result.fromThrowable;
654
654
  * )
655
655
  * ```
656
656
  */
657
- declare function tryResult<T, E>(fn: () => Exclude<T, Promise<unknown>>, errorFn: (e: unknown) => E): Result<T, E>;
657
+ export declare function tryResult<T, E>(fn: () => Exclude<T, Promise<unknown>>, errorFn: (e: unknown) => E): Result<T, E>;
658
658
  /**
659
659
  * Captures a synchronous boundary with named `try` and `catch` fields.
660
660
  *
661
661
  * This is equivalent to `tryResult(() => ..., toError)`, but it reads better when the boundary has
662
662
  * a clear domain name or label.
663
663
  */
664
- declare function tryResult<T, E>(options: TryResultOptions<T, E> & {
664
+ export declare function tryResult<T, E>(options: TryResultOptions<T, E> & {
665
665
  readonly catch: (e: unknown) => E;
666
666
  }): Result<T, E>;
667
667
  /**
@@ -670,20 +670,20 @@ declare function tryResult<T, E>(options: TryResultOptions<T, E> & {
670
670
  * Prefer the overload with a catch mapper in application code so the error channel stays documented.
671
671
  * This overload is useful while adapting unknown external failures or during migration.
672
672
  */
673
- declare function tryResult<T>(input: (() => Exclude<T, Promise<unknown>>) | TryResultOptions<T>): Result<T, unknown>;
673
+ export declare function tryResult<T>(input: (() => Exclude<T, Promise<unknown>>) | TryResultOptions<T>): Result<T, unknown>;
674
674
  /**
675
675
  * Creates an Ok result with `undefined`.
676
676
  */
677
- declare function unit<E = never>(): OkResult<undefined, E>;
677
+ export declare function unit<E = never>(): OkResult<undefined, E>;
678
678
  /**
679
679
  * Runs a `Result` at an application boundary and returns the success value.
680
680
  *
681
681
  * If the result is `Err`, this throws the error. Use it at final framework, CLI, test, or bootstrap
682
682
  * boundaries after the error channel has already been modeled with Resultar.
683
683
  */
684
- declare const runSync: <T, E>(result: Result<T, E>) => T;
684
+ export declare const runSync: <T, E>(result: Result<T, E>) => T;
685
685
  /** Compatibility alias. Prefer `tryResult` in new code. */
686
- declare const tryCatch: typeof tryResult;
686
+ export declare const tryCatch: typeof tryResult;
687
687
  type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, ...0[]];
688
688
  type CollectResults<T, Collected extends unknown[] = [], Depth extends number = 50> = [Depth] extends [never] ? [] : T extends [infer H, ...infer Rest] ? H extends Result<infer L, infer R> ? CollectResults<Rest, [...Collected, [L, R]], Prev[Depth]> : never : Collected;
689
689
  type Transpose<A, Transposed extends unknown[][] = [], Depth extends number = 10> = A extends [infer T, ...infer Rest] ? T extends [infer L, infer R] ? Transposed extends [infer PL, infer PR] ? PL extends unknown[] ? PR extends unknown[] ? Transpose<Rest, [[...PL, L], [...PR, R]], Prev[Depth]> : never : never : Transpose<Rest, [[L], [R]], Prev[Depth]> : Transposed : Transposed;
@@ -705,7 +705,7 @@ type CombineResultsWithAllErrorsArray<T extends readonly Result<unknown, unknown
705
705
  /**
706
706
  * Standard cancellation error used by ResultAsync retry, race, timeout, and resource helpers.
707
707
  */
708
- declare class AbortError extends Error {
708
+ export declare class AbortError extends Error {
709
709
  /**
710
710
  * Creates an AbortError.
711
711
  */
@@ -714,7 +714,7 @@ declare class AbortError extends Error {
714
714
  /**
715
715
  * Checks whether a value is an AbortError or abort-shaped platform error.
716
716
  */
717
- declare const isAbortError: (value: unknown) => value is AbortError;
717
+ export declare const isAbortError: (value: unknown) => value is AbortError;
718
718
  //#endregion
719
719
  //#region src/result-task.d.ts
720
720
  /** A failure cause produced by a `ResultTask` execution. */
@@ -733,18 +733,18 @@ type Cause<E> = {
733
733
  readonly right: Cause<E>;
734
734
  };
735
735
  /** Rejection used when a simplified boundary cannot represent multiple failures. */
736
- declare class ResultTaskCauseError extends Error {
736
+ export declare class ResultTaskCauseError extends Error {
737
737
  override readonly cause: Cause<unknown>;
738
738
  constructor(cause: Cause<unknown>);
739
739
  }
740
740
  /** Type identifier symbol for nominal `ResultTask` branding and variance checks. */
741
- declare const ResultTaskTypeId: unique symbol;
741
+ export declare const ResultTaskTypeId: unique symbol;
742
742
  /** Type identifier symbol for nominal `ServiceTag` branding. */
743
- declare const ServiceTagTypeId: unique symbol;
743
+ export declare const ServiceTagTypeId: unique symbol;
744
744
  /** Type identifier symbol for nominal `ResultTask` yieldable objects. */
745
- declare const ResultTaskYieldTypeId: unique symbol;
745
+ export declare const ResultTaskYieldTypeId: unique symbol;
746
746
  /** Error thrown as a Die cause when a requested service is not provided in the environment. */
747
- declare class MissingServiceError extends Error {
747
+ export declare class MissingServiceError extends Error {
748
748
  readonly serviceIdentifier: string;
749
749
  constructor(serviceIdentifier: string);
750
750
  }
@@ -796,6 +796,8 @@ type IncompatibleResolvedServices<R, Resolvers> = R extends AnyServiceTag ? R["i
796
796
  /** Owns resources across executions. Close it after its consumers have finished. */
797
797
  interface ResultTaskScopeOwner {
798
798
  readonly use: <A, E, R>(task: ResultTask<A, E, R>) => ResultTask<A, E, R>;
799
+ /** Registers an already-acquired resource's release synchronously, in registration order. */
800
+ readonly addFinalizer: (release: (exit: Exit<unknown, unknown>) => ResultTask<void, unknown>) => void;
799
801
  readonly close: (exit?: Exit<unknown, unknown>) => ResultTask<void, unknown>;
800
802
  }
801
803
  /** Options for running a `ResultTask` with an optional signal and its required services. */
@@ -847,35 +849,30 @@ type GeneratorRequirements<Yield> = Yield extends {
847
849
  } ? Tag : never;
848
850
  type ResultTaskRunArguments<R> = [WithoutScope<R>] extends [never] ? [options?: ResultTaskRunOptions<R>] : [options: ResultTaskRunOptions<R>];
849
851
  /** Returns true if a value is a nominal `ServiceTag`. */
850
- declare const isServiceTag: (value: unknown) => value is ServiceTag<string, unknown>;
852
+ export declare const isServiceTag: (value: unknown) => value is ServiceTag<string, unknown>;
851
853
  /** Returns true if a value is a `ResultTask` instance. */
852
- declare const isResultTask: (value: unknown) => value is ResultTask<unknown, unknown, unknown>;
854
+ export declare const isResultTask: (value: unknown) => value is ResultTask<unknown, unknown, unknown>;
853
855
  /** Creates a service tag that can be requested with `yield*` inside `ResultTask.gen`. */
854
- declare const serviceTag: <Service, const Identifier extends string = string>(identifier: Identifier) => ServiceTag<Identifier, Service>;
855
- interface ContinuationStep {
856
- readonly current: ResultTask<unknown, unknown, unknown> | undefined;
857
- readonly currentExit: Exit<unknown, unknown> | undefined;
858
- }
856
+ export declare const serviceTag: <Service, const Identifier extends string = string>(identifier: Identifier) => ServiceTag<Identifier, Service>;
859
857
  /**
860
858
  * A lazy, composable workflow that can succeed with `A` or fail with `E`.
861
859
  *
862
860
  * Constructing a `ResultTask` never runs its work. Use `runResult`, `runExit`, or `runPromise` at an
863
861
  * explicit application boundary to execute it.
864
862
  */
865
- interface ResultTask<out A, out E = never, out R = never> {
863
+ export interface ResultTask<out A, out E = never, out R = never> {
866
864
  readonly [ResultTaskTypeId]: {
867
865
  readonly success: (_: never) => A;
868
866
  readonly error: (_: never) => E;
869
867
  readonly requirements: (_: never) => R;
870
868
  };
871
869
  }
872
- declare class ResultTask<out A, out E = never, out R = never> extends Pipeable {
870
+ export declare class ResultTask<out A, out E = never, out R = never> extends Pipeable {
871
+ #private;
873
872
  private readonly typeWitness;
874
873
  private readonly instruction;
875
874
  private readonly execute;
876
875
  private constructor();
877
- /** @internal */
878
- static toTapContinuationStep(res: unknown, onSuccess: () => ResultTask<unknown, unknown, unknown>, passThroughExit: Exit<unknown, unknown>): ContinuationStep;
879
876
  private static runTaskLoop;
880
877
  /** Creates a task that succeeds with `value` when it is executed. */
881
878
  static succeed<A>(value: A): ResultTask<A, never>;
@@ -901,6 +898,8 @@ declare class ResultTask<out A, out E = never, out R = never> extends Pipeable {
901
898
  static scoped<A, E, R>(task: ResultTask<A, E, R>): ResultTask<A, E | ScopeError<R>, WithoutScope<R>>;
902
899
  /** Creates a service tag that can be requested with `yield*` inside `ResultTask.gen`. */
903
900
  static service<Service, const Identifier extends string>(identifier: Identifier): ServiceTag<Identifier, Service>;
901
+ /** Infers the literal identifier after specifying the service contract. */
902
+ static service<Service>(): <const Identifier extends string>(identifier: Identifier) => ServiceTag<Identifier, Service>;
904
903
  /** Builds a task from a generator and short-circuits on the first failed task. */
905
904
  static gen<Yield, Return, Next>(body: () => Generator<Yield, Return, Next>): ResultTask<Return, GeneratorError<Yield>, GeneratorRequirements<Yield>>;
906
905
  /** Maps the success value without executing the task. */
@@ -1315,7 +1314,7 @@ interface ResultAsyncIfOptions<OnTrue extends ResultAsyncConditional, OnFalse ex
1315
1314
  readonly onTrue: () => OnTrue;
1316
1315
  }
1317
1316
  /** Async-disposable wrapper that finalizes a `ResultAsync` exactly once. */
1318
- declare class DisposableResultAsync<T, E> implements PromiseLike<Result<T, E>>, AsyncDisposable {
1317
+ export declare class DisposableResultAsync<T, E> implements PromiseLike<Result<T, E>>, AsyncDisposable {
1319
1318
  private readonly innerPromise;
1320
1319
  private readonly finalizer;
1321
1320
  private disposed;
@@ -1372,7 +1371,7 @@ declare class DisposableResultAsync<T, E> implements PromiseLike<Result<T, E>>,
1372
1371
  * - Conditional branching (if)
1373
1372
  * - Combining multiple ResultAsync instances (combine, combineWithAllErrors)
1374
1373
  */
1375
- declare class ResultAsync<T, E> extends Pipeable implements PromiseLike<Result<T, E>> {
1374
+ export declare class ResultAsync<T, E> extends Pipeable implements PromiseLike<Result<T, E>> {
1376
1375
  /**
1377
1376
  * Returns a ResultAsync instance that is immediately resolved with a Result.ok(value).
1378
1377
  *
@@ -1706,33 +1705,33 @@ type StrictResultAsync<T, E extends Error = Error> = ResultAsync<T, E>;
1706
1705
  /**
1707
1706
  * Creates an Ok ResultAsync.
1708
1707
  */
1709
- declare const okAsync: typeof ResultAsync.okAsync;
1708
+ export declare const okAsync: typeof ResultAsync.okAsync;
1710
1709
  /**
1711
1710
  * Creates an Err ResultAsync.
1712
1711
  */
1713
- declare const errAsync: typeof ResultAsync.errAsync;
1712
+ export declare const errAsync: typeof ResultAsync.errAsync;
1714
1713
  /**
1715
1714
  * Adapts a callback or subscription API into a cancellable ResultAsync.
1716
1715
  */
1717
- declare const fromCallback: typeof ResultAsync.fromCallback;
1716
+ export declare const fromCallback: typeof ResultAsync.fromCallback;
1718
1717
  /**
1719
1718
  * Converts an existing promise into a ResultAsync and maps rejection into a typed Err.
1720
1719
  */
1721
- declare const fromPromise: typeof ResultAsync.fromPromise;
1720
+ export declare const fromPromise: typeof ResultAsync.fromPromise;
1722
1721
  /**
1723
1722
  * Converts an existing promise that is expected not to reject into a ResultAsync.
1724
1723
  *
1725
1724
  * Use `fromPromise` or `tryResultAsync` when rejection should become a typed Err.
1726
1725
  */
1727
- declare const fromSafePromise: typeof ResultAsync.fromSafePromise;
1726
+ export declare const fromSafePromise: typeof ResultAsync.fromSafePromise;
1728
1727
  /**
1729
1728
  * Creates an Ok ResultAsync with `undefined`.
1730
1729
  */
1731
- declare const unitAsync: typeof ResultAsync.unitAsync;
1730
+ export declare const unitAsync: typeof ResultAsync.unitAsync;
1732
1731
  /**
1733
1732
  * Wraps an async function so every later call returns a ResultAsync.
1734
1733
  */
1735
- declare const fromThrowableAsync: typeof ResultAsync.fromThrowable;
1734
+ export declare const fromThrowableAsync: typeof ResultAsync.fromThrowable;
1736
1735
  /**
1737
1736
  * Captures a promise or async factory into `ResultAsync<T, E>`.
1738
1737
  *
@@ -1750,7 +1749,7 @@ declare const fromThrowableAsync: typeof ResultAsync.fromThrowable;
1750
1749
  * )
1751
1750
  * ```
1752
1751
  */
1753
- declare function tryResultAsync<T, E>(fn: Promise<T> | (() => Promise<T>), errorFn: (e: unknown) => E): ResultAsync<T, E>;
1752
+ export declare function tryResultAsync<T, E>(fn: Promise<T> | (() => Promise<T>), errorFn: (e: unknown) => E): ResultAsync<T, E>;
1754
1753
  /**
1755
1754
  * Captures an async boundary with named `try` and `catch` fields.
1756
1755
  *
@@ -1765,7 +1764,7 @@ declare function tryResultAsync<T, E>(fn: Promise<T> | (() => Promise<T>), error
1765
1764
  * })
1766
1765
  * ```
1767
1766
  */
1768
- declare function tryResultAsync<T, E>(options: TryResultAsyncOptions<T, E> & {
1767
+ export declare function tryResultAsync<T, E>(options: TryResultAsyncOptions<T, E> & {
1769
1768
  readonly catch: (e: unknown) => E;
1770
1769
  }): ResultAsync<T, E>;
1771
1770
  /**
@@ -1774,16 +1773,16 @@ declare function tryResultAsync<T, E>(options: TryResultAsyncOptions<T, E> & {
1774
1773
  * Prefer the overload with a catch mapper in application code so the error channel stays documented.
1775
1774
  * This overload is useful while adapting unknown external failures or during migration.
1776
1775
  */
1777
- declare function tryResultAsync<T>(input: Promise<T> | (() => Promise<T>) | TryResultAsyncOptions<T>): ResultAsync<T, unknown>;
1776
+ export declare function tryResultAsync<T>(input: Promise<T> | (() => Promise<T>) | TryResultAsyncOptions<T>): ResultAsync<T, unknown>;
1778
1777
  /**
1779
1778
  * Runs a `ResultAsync` at an application boundary and returns the success value.
1780
1779
  *
1781
1780
  * If the result is `Err`, this rejects with the error. Use it at final framework, CLI, test, or
1782
1781
  * bootstrap boundaries after the error channel has already been modeled with Resultar.
1783
1782
  */
1784
- declare const runPromise: <T, E>(result: ResultAsync<T, E>) => Promise<T>;
1783
+ export declare const runPromise: <T, E>(result: ResultAsync<T, E>) => Promise<T>;
1785
1784
  /** Compatibility alias. Prefer `tryResultAsync` in new code. */
1786
- declare const tryCatchAsync: typeof tryResultAsync;
1785
+ export declare const tryCatchAsync: typeof tryResultAsync;
1787
1786
  type CombineResultAsyncs<T extends readonly ResultAsync<unknown, unknown>[]> = IsLiteralArray<T> extends 1 ? TraverseAsync<UnwrapAsync<T>> : ResultAsync<ExtractOkAsyncTypes<T>, ExtractErrAsyncTypes<T>[number]>;
1788
1787
  type CombineResultsWithAllErrorsArrayAsync<T extends readonly ResultAsync<unknown, unknown>[]> = IsLiteralArray<T> extends 1 ? TraverseWithAllErrorsAsync<UnwrapAsync<T>> : ResultAsync<ExtractOkAsyncTypes<T>, ExtractErrAsyncTypes<T>[number][]>;
1789
1788
  type UnwrapAsync<T> = IsLiteralArray<T> extends 1 ? Writable<T> extends [infer H, ...infer Rest] ? H extends PromiseLike<infer HI> ? HI extends Result<unknown, unknown> ? [Dedup<HI>, ...UnwrapAsync<Rest>] : never : never : [] : T extends (infer A)[] ? A extends PromiseLike<infer HI> ? HI extends Result<infer L, infer R> ? Result<L, R>[] : never : never : never;
@@ -1817,15 +1816,15 @@ type Redacted<T> = string & {
1817
1816
  /**
1818
1817
  * Wraps a sensitive value so tagged-error messages and JSON output show only a placeholder.
1819
1818
  */
1820
- declare const redact: <T>(value: T, label?: string) => Redacted<T>;
1819
+ export declare const redact: <T>(value: T, label?: string) => Redacted<T>;
1821
1820
  /**
1822
1821
  * Checks whether a value was created by `redact`.
1823
1822
  */
1824
- declare const isRedacted: (value: unknown) => value is Redacted<unknown>;
1823
+ export declare const isRedacted: (value: unknown) => value is Redacted<unknown>;
1825
1824
  /**
1826
1825
  * Returns the original sensitive value from a Redacted wrapper.
1827
1826
  */
1828
- declare const revealRedacted: <T>(value: Redacted<T>) => T;
1827
+ export declare const revealRedacted: <T>(value: Redacted<T>) => T;
1829
1828
  //#endregion
1830
1829
  //#region src/tagged-error.d.ts
1831
1830
  type Alpha = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z" | "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z" | "_";
@@ -1954,12 +1953,12 @@ declare const defaultMessageTemplate = "$message";
1954
1953
  /**
1955
1954
  * Narrows a value to native or platform-recognized Error.
1956
1955
  */
1957
- declare function isError(value: unknown): value is Error;
1958
- declare function isError<Value>(value: Value): value is Extract<Value, Error>;
1956
+ export declare function isError(value: unknown): value is Error;
1957
+ export declare function isError<Value>(value: Value): value is Extract<Value, Error>;
1959
1958
  /**
1960
1959
  * Finds the first cause in an Error cause chain that is an instance of `ErrorClass`.
1961
1960
  */
1962
- declare const findCause: <T extends Error>(error: Error, ErrorClass: ErrorClass<T>) => T | undefined;
1961
+ export declare const findCause: <T extends Error>(error: Error, ErrorClass: ErrorClass<T>) => T | undefined;
1963
1962
  /**
1964
1963
  * Creates an Error class with a stable `_tag`, typed template props, cause support, and JSON output.
1965
1964
  *
@@ -1973,22 +1972,22 @@ declare const findCause: <T extends Error>(error: Error, ErrorClass: ErrorClass<
1973
1972
  * }) {}
1974
1973
  * ```
1975
1974
  */
1976
- declare function createTaggedError<const Tag extends string, const MessageTemplate extends string = typeof defaultMessageTemplate, Base extends Error = Error>(options: Omit<TaggedErrorOptions<Tag, MessageTemplate, Base>, "message"> & {
1975
+ export declare function createTaggedError<const Tag extends string, const MessageTemplate extends string = typeof defaultMessageTemplate, Base extends Error = Error>(options: Omit<TaggedErrorOptions<Tag, MessageTemplate, Base>, "message"> & {
1977
1976
  readonly message?: RejectReservedTemplateVariables<MessageTemplate>;
1978
1977
  }): TaggedErrorClass<Tag, MessageTemplate, Base>;
1979
1978
  /**
1980
1979
  * Creates a small tagged-union factory with member constructors, `$is`, and `$match`.
1981
1980
  */
1982
- declare const taggedEnum: <Members extends Record<string, object>>() => TaggedEnumFactory<Members>;
1981
+ export declare const taggedEnum: <Members extends Record<string, object>>() => TaggedEnumFactory<Members>;
1983
1982
  /**
1984
1983
  * Matches an Error by tagged `_tag`, with optional native `Error` fallback.
1985
1984
  *
1986
1985
  * Throws the original error when no handler matches.
1987
1986
  */
1988
- declare const matchError: <ErrorType extends Error, ReturnType>(error: ErrorType, handlers: MatchHandlers<ErrorType, ReturnType>) => ReturnType;
1987
+ export declare const matchError: <ErrorType extends Error, ReturnType>(error: ErrorType, handlers: MatchHandlers<ErrorType, ReturnType>) => ReturnType;
1989
1988
  /**
1990
1989
  * Matches an Error by tagged `_tag`, then native `Error`, then the provided fallback.
1991
1990
  */
1992
- declare const matchErrorPartial: <ErrorType extends Error, ReturnType>(error: ErrorType, handlers: PartialMatchHandlers<ErrorType, ReturnType>, fallback: (error: ErrorType) => ReturnType) => ReturnType;
1991
+ export declare const matchErrorPartial: <ErrorType extends Error, ReturnType>(error: ErrorType, handlers: PartialMatchHandlers<ErrorType, ReturnType>, fallback: (error: ErrorType) => ReturnType) => ReturnType;
1993
1992
  //#endregion
1994
- export { AbortError, type Cause, DisposableResult, DisposableResultAsync, type ErrResult, type Exit, MissingServiceError, type OkResult, type Redacted, Result, ResultAsync, type ResultAsyncAbortSignal, type ResultAsyncCallbackCleanup, type ResultAsyncCallbackContext, type ResultAsyncConcurrency, type ResultAsyncFromCallbackOptions, type ResultAsyncRaceHandle, type ResultAsyncRaceTask, type ResultAsyncResourceAcquire, type ResultAsyncResourceEffect, type ResultAsyncResourceRelease, type ResultAsyncResourceReleaseContext, type ResultAsyncResourceUse, type ResultAsyncRetryContext, type ResultAsyncRetryOptions, type ResultAsyncRetryOrElseOptions, type ResultAsyncRetryTask, type ResultAsyncTimeoutOptions, type ResultAsyncWithResourceOptions, type ResultOperations, ResultTask, type ResultTaskAcquireReleaseOptions, ResultTaskCauseError, type ResultTaskMatchOptions, type ResultTaskRunOptions, type ResultTaskScope, type ResultTaskScopeOwner, type ResultTaskServiceResolver, type ResultTaskServices, type ResultTaskTryOptions, type ResultTaskTryPromiseOptions, ResultTaskTypeId, ResultTaskYieldTypeId, type SafeTryAsyncOptions, type SafeTryOptions, type ServiceTag, ServiceTagTypeId, type StrictResult, type StrictResultAsync, type TaggedEnum, type TaggedEnumFactory, type TaggedErrorClass, type TaggedErrorInstance, type TaggedErrorOptions, type TryResultAsyncOptions, type TryResultOptions, createTaggedError, tryResult as default, tryResult as try, tryResult, err, errAsync, findCause, fromCallback, fromPromise, fromSafePromise, fromThrowable, fromThrowableAsync, isAbortError, isError, isRedacted, isResultTask, isServiceTag, matchError, matchErrorPartial, ok, okAsync, redact, revealRedacted, runPromise, runSync, safeTry, serviceTag, taggedEnum, tryResultAsync as tryAsync, tryResultAsync, tryCatch, tryCatchAsync, unit, unitAsync };
1993
+ export { type Cause, type ErrResult, type Exit, type OkResult, type Redacted, type ResultAsyncAbortSignal, type ResultAsyncCallbackCleanup, type ResultAsyncCallbackContext, type ResultAsyncConcurrency, type ResultAsyncFromCallbackOptions, type ResultAsyncRaceHandle, type ResultAsyncRaceTask, type ResultAsyncResourceAcquire, type ResultAsyncResourceEffect, type ResultAsyncResourceRelease, type ResultAsyncResourceReleaseContext, type ResultAsyncResourceUse, type ResultAsyncRetryContext, type ResultAsyncRetryOptions, type ResultAsyncRetryOrElseOptions, type ResultAsyncRetryTask, type ResultAsyncTimeoutOptions, type ResultAsyncWithResourceOptions, type ResultOperations, type ResultTaskAcquireReleaseOptions, type ResultTaskMatchOptions, type ResultTaskRunOptions, type ResultTaskScope, type ResultTaskScopeOwner, type ResultTaskServiceResolver, type ResultTaskServices, type ResultTaskTryOptions, type ResultTaskTryPromiseOptions, type SafeTryAsyncOptions, type SafeTryOptions, type ServiceTag, type StrictResult, type StrictResultAsync, type TaggedEnum, type TaggedEnumFactory, type TaggedErrorClass, type TaggedErrorInstance, type TaggedErrorOptions, type TryResultAsyncOptions, type TryResultOptions, tryResult as default, tryResult as try, tryResultAsync as tryAsync };