resultar 3.7.0 → 3.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/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>;
@@ -1315,7 +1312,7 @@ interface ResultAsyncIfOptions<OnTrue extends ResultAsyncConditional, OnFalse ex
1315
1312
  readonly onTrue: () => OnTrue;
1316
1313
  }
1317
1314
  /** Async-disposable wrapper that finalizes a `ResultAsync` exactly once. */
1318
- declare class DisposableResultAsync<T, E> implements PromiseLike<Result<T, E>>, AsyncDisposable {
1315
+ export declare class DisposableResultAsync<T, E> implements PromiseLike<Result<T, E>>, AsyncDisposable {
1319
1316
  private readonly innerPromise;
1320
1317
  private readonly finalizer;
1321
1318
  private disposed;
@@ -1372,7 +1369,7 @@ declare class DisposableResultAsync<T, E> implements PromiseLike<Result<T, E>>,
1372
1369
  * - Conditional branching (if)
1373
1370
  * - Combining multiple ResultAsync instances (combine, combineWithAllErrors)
1374
1371
  */
1375
- declare class ResultAsync<T, E> extends Pipeable implements PromiseLike<Result<T, E>> {
1372
+ export declare class ResultAsync<T, E> extends Pipeable implements PromiseLike<Result<T, E>> {
1376
1373
  /**
1377
1374
  * Returns a ResultAsync instance that is immediately resolved with a Result.ok(value).
1378
1375
  *
@@ -1706,33 +1703,33 @@ type StrictResultAsync<T, E extends Error = Error> = ResultAsync<T, E>;
1706
1703
  /**
1707
1704
  * Creates an Ok ResultAsync.
1708
1705
  */
1709
- declare const okAsync: typeof ResultAsync.okAsync;
1706
+ export declare const okAsync: typeof ResultAsync.okAsync;
1710
1707
  /**
1711
1708
  * Creates an Err ResultAsync.
1712
1709
  */
1713
- declare const errAsync: typeof ResultAsync.errAsync;
1710
+ export declare const errAsync: typeof ResultAsync.errAsync;
1714
1711
  /**
1715
1712
  * Adapts a callback or subscription API into a cancellable ResultAsync.
1716
1713
  */
1717
- declare const fromCallback: typeof ResultAsync.fromCallback;
1714
+ export declare const fromCallback: typeof ResultAsync.fromCallback;
1718
1715
  /**
1719
1716
  * Converts an existing promise into a ResultAsync and maps rejection into a typed Err.
1720
1717
  */
1721
- declare const fromPromise: typeof ResultAsync.fromPromise;
1718
+ export declare const fromPromise: typeof ResultAsync.fromPromise;
1722
1719
  /**
1723
1720
  * Converts an existing promise that is expected not to reject into a ResultAsync.
1724
1721
  *
1725
1722
  * Use `fromPromise` or `tryResultAsync` when rejection should become a typed Err.
1726
1723
  */
1727
- declare const fromSafePromise: typeof ResultAsync.fromSafePromise;
1724
+ export declare const fromSafePromise: typeof ResultAsync.fromSafePromise;
1728
1725
  /**
1729
1726
  * Creates an Ok ResultAsync with `undefined`.
1730
1727
  */
1731
- declare const unitAsync: typeof ResultAsync.unitAsync;
1728
+ export declare const unitAsync: typeof ResultAsync.unitAsync;
1732
1729
  /**
1733
1730
  * Wraps an async function so every later call returns a ResultAsync.
1734
1731
  */
1735
- declare const fromThrowableAsync: typeof ResultAsync.fromThrowable;
1732
+ export declare const fromThrowableAsync: typeof ResultAsync.fromThrowable;
1736
1733
  /**
1737
1734
  * Captures a promise or async factory into `ResultAsync<T, E>`.
1738
1735
  *
@@ -1750,7 +1747,7 @@ declare const fromThrowableAsync: typeof ResultAsync.fromThrowable;
1750
1747
  * )
1751
1748
  * ```
1752
1749
  */
1753
- declare function tryResultAsync<T, E>(fn: Promise<T> | (() => Promise<T>), errorFn: (e: unknown) => E): ResultAsync<T, E>;
1750
+ export declare function tryResultAsync<T, E>(fn: Promise<T> | (() => Promise<T>), errorFn: (e: unknown) => E): ResultAsync<T, E>;
1754
1751
  /**
1755
1752
  * Captures an async boundary with named `try` and `catch` fields.
1756
1753
  *
@@ -1765,7 +1762,7 @@ declare function tryResultAsync<T, E>(fn: Promise<T> | (() => Promise<T>), error
1765
1762
  * })
1766
1763
  * ```
1767
1764
  */
1768
- declare function tryResultAsync<T, E>(options: TryResultAsyncOptions<T, E> & {
1765
+ export declare function tryResultAsync<T, E>(options: TryResultAsyncOptions<T, E> & {
1769
1766
  readonly catch: (e: unknown) => E;
1770
1767
  }): ResultAsync<T, E>;
1771
1768
  /**
@@ -1774,16 +1771,16 @@ declare function tryResultAsync<T, E>(options: TryResultAsyncOptions<T, E> & {
1774
1771
  * Prefer the overload with a catch mapper in application code so the error channel stays documented.
1775
1772
  * This overload is useful while adapting unknown external failures or during migration.
1776
1773
  */
1777
- declare function tryResultAsync<T>(input: Promise<T> | (() => Promise<T>) | TryResultAsyncOptions<T>): ResultAsync<T, unknown>;
1774
+ export declare function tryResultAsync<T>(input: Promise<T> | (() => Promise<T>) | TryResultAsyncOptions<T>): ResultAsync<T, unknown>;
1778
1775
  /**
1779
1776
  * Runs a `ResultAsync` at an application boundary and returns the success value.
1780
1777
  *
1781
1778
  * If the result is `Err`, this rejects with the error. Use it at final framework, CLI, test, or
1782
1779
  * bootstrap boundaries after the error channel has already been modeled with Resultar.
1783
1780
  */
1784
- declare const runPromise: <T, E>(result: ResultAsync<T, E>) => Promise<T>;
1781
+ export declare const runPromise: <T, E>(result: ResultAsync<T, E>) => Promise<T>;
1785
1782
  /** Compatibility alias. Prefer `tryResultAsync` in new code. */
1786
- declare const tryCatchAsync: typeof tryResultAsync;
1783
+ export declare const tryCatchAsync: typeof tryResultAsync;
1787
1784
  type CombineResultAsyncs<T extends readonly ResultAsync<unknown, unknown>[]> = IsLiteralArray<T> extends 1 ? TraverseAsync<UnwrapAsync<T>> : ResultAsync<ExtractOkAsyncTypes<T>, ExtractErrAsyncTypes<T>[number]>;
1788
1785
  type CombineResultsWithAllErrorsArrayAsync<T extends readonly ResultAsync<unknown, unknown>[]> = IsLiteralArray<T> extends 1 ? TraverseWithAllErrorsAsync<UnwrapAsync<T>> : ResultAsync<ExtractOkAsyncTypes<T>, ExtractErrAsyncTypes<T>[number][]>;
1789
1786
  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 +1814,15 @@ type Redacted<T> = string & {
1817
1814
  /**
1818
1815
  * Wraps a sensitive value so tagged-error messages and JSON output show only a placeholder.
1819
1816
  */
1820
- declare const redact: <T>(value: T, label?: string) => Redacted<T>;
1817
+ export declare const redact: <T>(value: T, label?: string) => Redacted<T>;
1821
1818
  /**
1822
1819
  * Checks whether a value was created by `redact`.
1823
1820
  */
1824
- declare const isRedacted: (value: unknown) => value is Redacted<unknown>;
1821
+ export declare const isRedacted: (value: unknown) => value is Redacted<unknown>;
1825
1822
  /**
1826
1823
  * Returns the original sensitive value from a Redacted wrapper.
1827
1824
  */
1828
- declare const revealRedacted: <T>(value: Redacted<T>) => T;
1825
+ export declare const revealRedacted: <T>(value: Redacted<T>) => T;
1829
1826
  //#endregion
1830
1827
  //#region src/tagged-error.d.ts
1831
1828
  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 +1951,12 @@ declare const defaultMessageTemplate = "$message";
1954
1951
  /**
1955
1952
  * Narrows a value to native or platform-recognized Error.
1956
1953
  */
1957
- declare function isError(value: unknown): value is Error;
1958
- declare function isError<Value>(value: Value): value is Extract<Value, Error>;
1954
+ export declare function isError(value: unknown): value is Error;
1955
+ export declare function isError<Value>(value: Value): value is Extract<Value, Error>;
1959
1956
  /**
1960
1957
  * Finds the first cause in an Error cause chain that is an instance of `ErrorClass`.
1961
1958
  */
1962
- declare const findCause: <T extends Error>(error: Error, ErrorClass: ErrorClass<T>) => T | undefined;
1959
+ export declare const findCause: <T extends Error>(error: Error, ErrorClass: ErrorClass<T>) => T | undefined;
1963
1960
  /**
1964
1961
  * Creates an Error class with a stable `_tag`, typed template props, cause support, and JSON output.
1965
1962
  *
@@ -1973,22 +1970,22 @@ declare const findCause: <T extends Error>(error: Error, ErrorClass: ErrorClass<
1973
1970
  * }) {}
1974
1971
  * ```
1975
1972
  */
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"> & {
1973
+ 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
1974
  readonly message?: RejectReservedTemplateVariables<MessageTemplate>;
1978
1975
  }): TaggedErrorClass<Tag, MessageTemplate, Base>;
1979
1976
  /**
1980
1977
  * Creates a small tagged-union factory with member constructors, `$is`, and `$match`.
1981
1978
  */
1982
- declare const taggedEnum: <Members extends Record<string, object>>() => TaggedEnumFactory<Members>;
1979
+ export declare const taggedEnum: <Members extends Record<string, object>>() => TaggedEnumFactory<Members>;
1983
1980
  /**
1984
1981
  * Matches an Error by tagged `_tag`, with optional native `Error` fallback.
1985
1982
  *
1986
1983
  * Throws the original error when no handler matches.
1987
1984
  */
1988
- declare const matchError: <ErrorType extends Error, ReturnType>(error: ErrorType, handlers: MatchHandlers<ErrorType, ReturnType>) => ReturnType;
1985
+ export declare const matchError: <ErrorType extends Error, ReturnType>(error: ErrorType, handlers: MatchHandlers<ErrorType, ReturnType>) => ReturnType;
1989
1986
  /**
1990
1987
  * Matches an Error by tagged `_tag`, then native `Error`, then the provided fallback.
1991
1988
  */
1992
- declare const matchErrorPartial: <ErrorType extends Error, ReturnType>(error: ErrorType, handlers: PartialMatchHandlers<ErrorType, ReturnType>, fallback: (error: ErrorType) => ReturnType) => ReturnType;
1989
+ export declare const matchErrorPartial: <ErrorType extends Error, ReturnType>(error: ErrorType, handlers: PartialMatchHandlers<ErrorType, ReturnType>, fallback: (error: ErrorType) => ReturnType) => ReturnType;
1993
1990
  //#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 };
1991
+ 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 };
package/dist/index.js CHANGED
@@ -918,129 +918,6 @@ var ServiceTagValue = class {
918
918
  };
919
919
  /** Creates a service tag that can be requested with `yield*` inside `ResultTask.gen`. */
920
920
  const serviceTag = (identifier) => new ServiceTagValue(identifier);
921
- const applySuccessContinuation = (continuation, exit) => {
922
- switch (continuation._tag) {
923
- case "Map": try {
924
- return {
925
- current: void 0,
926
- currentExit: success(continuation.f(exit.value))
927
- };
928
- } catch (error) {
929
- return {
930
- current: void 0,
931
- currentExit: died(error)
932
- };
933
- }
934
- case "FlatMap": try {
935
- return {
936
- current: continuation.f(exit.value),
937
- currentExit: void 0
938
- };
939
- } catch (error) {
940
- return {
941
- current: void 0,
942
- currentExit: died(error)
943
- };
944
- }
945
- case "Tap": try {
946
- const res = continuation.f(exit.value);
947
- return ResultTask.toTapContinuationStep(res, () => ResultTask.succeed(exit.value), exit);
948
- } catch (error) {
949
- return {
950
- current: void 0,
951
- currentExit: died(error)
952
- };
953
- }
954
- case "MapError": return {
955
- current: void 0,
956
- currentExit: exit
957
- };
958
- case "TapError": return {
959
- current: void 0,
960
- currentExit: exit
961
- };
962
- case "CatchAll": return {
963
- current: void 0,
964
- currentExit: exit
965
- };
966
- default: return {
967
- current: void 0,
968
- currentExit: exit
969
- };
970
- }
971
- };
972
- const applyFailureContinuation = (continuation, exit) => {
973
- switch (continuation._tag) {
974
- case "MapError":
975
- if (exit.cause._tag === "Fail") try {
976
- return {
977
- current: void 0,
978
- currentExit: failed(continuation.f(exit.cause.error))
979
- };
980
- } catch (error) {
981
- return {
982
- current: void 0,
983
- currentExit: died(error)
984
- };
985
- }
986
- return {
987
- current: void 0,
988
- currentExit: exit
989
- };
990
- case "TapError":
991
- if (exit.cause._tag === "Fail") try {
992
- const failError = exit.cause.error;
993
- const res = continuation.f(failError);
994
- return ResultTask.toTapContinuationStep(res, () => ResultTask.fail(failError), exit);
995
- } catch (error) {
996
- return {
997
- current: void 0,
998
- currentExit: died(error)
999
- };
1000
- }
1001
- return {
1002
- current: void 0,
1003
- currentExit: exit
1004
- };
1005
- case "CatchAll":
1006
- if (exit.cause._tag === "Sequential") return {
1007
- current: void 0,
1008
- currentExit: died(new ResultTaskCauseError(exit.cause))
1009
- };
1010
- if (exit.cause._tag === "Fail") try {
1011
- return {
1012
- current: continuation.f(exit.cause.error),
1013
- currentExit: void 0
1014
- };
1015
- } catch (error) {
1016
- return {
1017
- current: void 0,
1018
- currentExit: died(error)
1019
- };
1020
- }
1021
- return {
1022
- current: void 0,
1023
- currentExit: exit
1024
- };
1025
- case "Map": return {
1026
- current: void 0,
1027
- currentExit: exit
1028
- };
1029
- case "FlatMap": return {
1030
- current: void 0,
1031
- currentExit: exit
1032
- };
1033
- case "Tap": return {
1034
- current: void 0,
1035
- currentExit: exit
1036
- };
1037
- default: return {
1038
- current: void 0,
1039
- currentExit: exit
1040
- };
1041
- }
1042
- };
1043
- const applyContinuation = (continuation, exit) => exit._tag === "Success" ? applySuccessContinuation(continuation, exit) : applyFailureContinuation(continuation, exit);
1044
921
  const executeInstruction = async (instruction, continuations, context) => {
1045
922
  switch (instruction._tag) {
1046
923
  case "FlatMap":
@@ -1101,8 +978,129 @@ var ResultTask = class ResultTask extends Pipeable {
1101
978
  } : instructionOrExecute;
1102
979
  this.execute = (context) => ResultTask.runTaskLoop(this, context);
1103
980
  }
1104
- /** @internal */
1105
- static toTapContinuationStep(res, onSuccess, passThroughExit) {
981
+ static #applySuccessContinuation(continuation, exit) {
982
+ switch (continuation._tag) {
983
+ case "Map": try {
984
+ return {
985
+ current: void 0,
986
+ currentExit: success(continuation.f(exit.value))
987
+ };
988
+ } catch (error) {
989
+ return {
990
+ current: void 0,
991
+ currentExit: died(error)
992
+ };
993
+ }
994
+ case "FlatMap": try {
995
+ return {
996
+ current: continuation.f(exit.value),
997
+ currentExit: void 0
998
+ };
999
+ } catch (error) {
1000
+ return {
1001
+ current: void 0,
1002
+ currentExit: died(error)
1003
+ };
1004
+ }
1005
+ case "Tap": try {
1006
+ const res = continuation.f(exit.value);
1007
+ return ResultTask.#toTapContinuationStep(res, () => ResultTask.succeed(exit.value), exit);
1008
+ } catch (error) {
1009
+ return {
1010
+ current: void 0,
1011
+ currentExit: died(error)
1012
+ };
1013
+ }
1014
+ case "MapError": return {
1015
+ current: void 0,
1016
+ currentExit: exit
1017
+ };
1018
+ case "TapError": return {
1019
+ current: void 0,
1020
+ currentExit: exit
1021
+ };
1022
+ case "CatchAll": return {
1023
+ current: void 0,
1024
+ currentExit: exit
1025
+ };
1026
+ default: return {
1027
+ current: void 0,
1028
+ currentExit: exit
1029
+ };
1030
+ }
1031
+ }
1032
+ static #applyFailureContinuation(continuation, exit) {
1033
+ switch (continuation._tag) {
1034
+ case "MapError":
1035
+ if (exit.cause._tag === "Fail") try {
1036
+ return {
1037
+ current: void 0,
1038
+ currentExit: failed(continuation.f(exit.cause.error))
1039
+ };
1040
+ } catch (error) {
1041
+ return {
1042
+ current: void 0,
1043
+ currentExit: died(error)
1044
+ };
1045
+ }
1046
+ return {
1047
+ current: void 0,
1048
+ currentExit: exit
1049
+ };
1050
+ case "TapError":
1051
+ if (exit.cause._tag === "Fail") try {
1052
+ const failError = exit.cause.error;
1053
+ const res = continuation.f(failError);
1054
+ return ResultTask.#toTapContinuationStep(res, () => ResultTask.fail(failError), exit);
1055
+ } catch (error) {
1056
+ return {
1057
+ current: void 0,
1058
+ currentExit: died(error)
1059
+ };
1060
+ }
1061
+ return {
1062
+ current: void 0,
1063
+ currentExit: exit
1064
+ };
1065
+ case "CatchAll":
1066
+ if (exit.cause._tag === "Sequential") return {
1067
+ current: void 0,
1068
+ currentExit: died(new ResultTaskCauseError(exit.cause))
1069
+ };
1070
+ if (exit.cause._tag === "Fail") try {
1071
+ return {
1072
+ current: continuation.f(exit.cause.error),
1073
+ currentExit: void 0
1074
+ };
1075
+ } catch (error) {
1076
+ return {
1077
+ current: void 0,
1078
+ currentExit: died(error)
1079
+ };
1080
+ }
1081
+ return {
1082
+ current: void 0,
1083
+ currentExit: exit
1084
+ };
1085
+ case "Map": return {
1086
+ current: void 0,
1087
+ currentExit: exit
1088
+ };
1089
+ case "FlatMap": return {
1090
+ current: void 0,
1091
+ currentExit: exit
1092
+ };
1093
+ case "Tap": return {
1094
+ current: void 0,
1095
+ currentExit: exit
1096
+ };
1097
+ default: return {
1098
+ current: void 0,
1099
+ currentExit: exit
1100
+ };
1101
+ }
1102
+ }
1103
+ static #toTapContinuationStep(res, onSuccess, passThroughExit) {
1106
1104
  if (res instanceof ResultTask) return {
1107
1105
  current: res.flatMap(onSuccess),
1108
1106
  currentExit: void 0
@@ -1132,7 +1130,7 @@ var ResultTask = class ResultTask extends Pipeable {
1132
1130
  const nextContinuation = continuations.pop();
1133
1131
  if (nextContinuation === void 0) return currentExit;
1134
1132
  const resolvedExit = context.signal.aborted && currentExit._tag === "Success" ? interrupted(context.signal) : currentExit;
1135
- const step = applyContinuation(nextContinuation, resolvedExit);
1133
+ const step = resolvedExit._tag === "Success" ? ResultTask.#applySuccessContinuation(nextContinuation, resolvedExit) : ResultTask.#applyFailureContinuation(nextContinuation, resolvedExit);
1136
1134
  current = step.current;
1137
1135
  currentExit = step.currentExit;
1138
1136
  }
@@ -1410,6 +1408,12 @@ var ResultTask = class ResultTask extends Pipeable {
1410
1408
  const pending = /* @__PURE__ */ new Set();
1411
1409
  let closing = void 0;
1412
1410
  return {
1411
+ addFinalizer: (release) => {
1412
+ if (closing !== void 0) throw new Error("Cannot acquire into a closing ResultTask scope");
1413
+ scope.add((exit) => ResultTask.runExit(ResultTask.gen(function* () {
1414
+ yield* release(exit);
1415
+ })));
1416
+ },
1413
1417
  use: (task) => new ResultTask(async (context) => {
1414
1418
  if (closing !== void 0) return died(/* @__PURE__ */ new Error("Cannot execute in a closed ResultTask scope"));
1415
1419
  const attempt = new TaskScope();