resultar 3.6.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
@@ -15,6 +15,11 @@ declare abstract class Pipeable {
15
15
  pipe<A>(ab: PipeFn<this, A>): A;
16
16
  pipe<A, B>(ab: PipeFn<this, A>, bc: PipeFn<A, B>): B;
17
17
  pipe<A, B, C>(ab: PipeFn<this, A>, bc: PipeFn<A, B>, cd: PipeFn<B, C>): C;
18
+ pipe<A, B, C, D>(ab: PipeFn<this, A>, bc: PipeFn<A, B>, cd: PipeFn<B, C>, de: PipeFn<C, D>): D;
19
+ pipe<A, B, C, D, E>(ab: PipeFn<this, A>, bc: PipeFn<A, B>, cd: PipeFn<B, C>, de: PipeFn<C, D>, ef: PipeFn<D, E>): E;
20
+ pipe<A, B, C, D, E, F>(ab: PipeFn<this, A>, bc: PipeFn<A, B>, cd: PipeFn<B, C>, de: PipeFn<C, D>, ef: PipeFn<D, E>, fg: PipeFn<E, F>): F;
21
+ pipe<A, B, C, D, E, F, G>(ab: PipeFn<this, A>, bc: PipeFn<A, B>, cd: PipeFn<B, C>, de: PipeFn<C, D>, ef: PipeFn<D, E>, fg: PipeFn<E, F>, gh: PipeFn<F, G>): G;
22
+ pipe<A, B, C, D, E, F, G, H>(ab: PipeFn<this, A>, bc: PipeFn<A, B>, cd: PipeFn<B, C>, de: PipeFn<C, D>, ef: PipeFn<D, E>, fg: PipeFn<E, F>, gh: PipeFn<F, G>, hi: PipeFn<G, H>): H;
18
23
  }
19
24
  //#endregion
20
25
  //#region src/utils.d.ts
@@ -360,7 +365,7 @@ interface ErrResult<T, E> extends ResultOperations<T, E> {
360
365
  readonly error: E;
361
366
  }
362
367
  /** Success-or-failure value with explicit Ok and Err channels. */
363
- type Result<T, E> = OkResult<T, E> | ErrResult<T, E>;
368
+ export type Result<T, E> = OkResult<T, E> | ErrResult<T, E>;
364
369
  /** `Result` convention that restricts the error channel to real `Error` instances. */
365
370
  type StrictResult<T, E extends Error = Error> = Result<T, E>;
366
371
  /**
@@ -536,12 +541,12 @@ interface ResultStatic {
536
541
  };
537
542
  }
538
543
  /** Static helpers for creating, combining, and iterating over Result values. */
539
- declare const Result: ResultStatic;
544
+ export declare const Result: ResultStatic;
540
545
  /**
541
546
  * A `Disposable` is an object that has a `dispose` method that can be used to
542
547
  * clean up resources.
543
548
  */
544
- declare class DisposableResult<T, E> implements Resultable<T, E>, Disposable {
549
+ export declare class DisposableResult<T, E> implements Resultable<T, E>, Disposable {
545
550
  private disposed;
546
551
  private readonly finalizer;
547
552
  /**
@@ -593,14 +598,14 @@ declare class DisposableResult<T, E> implements Resultable<T, E>, Disposable {
593
598
  * Inside the generator, use `yield* result` to unwrap Ok values and short-circuit on Err. The object
594
599
  * form can map thrown setup errors into the Result error channel.
595
600
  */
596
- 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> & {
597
602
  readonly catch: (e: unknown) => CatchErr;
598
603
  }): Result<T, E | CatchErr>;
599
- declare function safeTry<T, E>(input: (() => Generator<Result<never, E>, Result<T, E>>) | SafeTryOptions<Result<never, E>, Result<T, E>>): Result<T, E>;
600
- 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> & {
601
606
  readonly catch: (e: unknown) => CatchErr;
602
607
  }): Result<InferOkTypes<GeneratorReturnResult>, InferErrTypes<YieldErr> | InferErrTypes<GeneratorReturnResult> | CatchErr>;
603
- 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>>;
604
609
  /**
605
610
  * Evaluates an async generator and returns a ResultAsync for the first yielded Err or returned
606
611
  * Result.
@@ -609,31 +614,31 @@ declare function safeTry<YieldErr extends Result<never, unknown>, GeneratorRetur
609
614
  * short-circuit on Err. The object form can map thrown or rejected setup errors into the ResultAsync
610
615
  * error channel.
611
616
  */
612
- 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> & {
613
618
  readonly catch: (e: unknown) => CatchErr;
614
619
  }): ResultAsync<T, E | CatchErr>;
615
- declare function safeTry<T, E>(input: (() => AsyncGenerator<Result<never, E>, Result<T, E>>) | SafeTryAsyncOptions<Result<never, E>, Result<T, E>>): ResultAsync<T, E>;
616
- 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> & {
617
622
  readonly catch: (e: unknown) => CatchErr;
618
623
  }): ResultAsync<InferOkTypes<GeneratorReturnResult>, InferErrTypes<YieldErr> | InferErrTypes<GeneratorReturnResult> | CatchErr>;
619
- 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>>;
620
625
  /**
621
626
  * Creates an Ok result.
622
627
  */
623
- declare function ok<T, E = never>(value: T): OkResult<T, E>;
624
- 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>;
625
630
  /**
626
631
  * Creates an Err result.
627
632
  */
628
- declare function err<T = never, E extends string = string>(err: E): ErrResult<T, E>;
629
- declare function err<T = never, E = unknown>(err: E): ErrResult<T, E>;
630
- 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>;
631
636
  /**
632
637
  * Wraps a throwing synchronous function so every later call returns a Result.
633
638
  *
634
639
  * Prefer `tryResult` when you want to run the operation immediately.
635
640
  */
636
- declare const fromThrowable: typeof Result.fromThrowable;
641
+ export declare const fromThrowable: typeof Result.fromThrowable;
637
642
  /**
638
643
  * Runs synchronous work and captures thrown values into `Result<T, E>`.
639
644
  *
@@ -649,14 +654,14 @@ declare const fromThrowable: typeof Result.fromThrowable;
649
654
  * )
650
655
  * ```
651
656
  */
652
- 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>;
653
658
  /**
654
659
  * Captures a synchronous boundary with named `try` and `catch` fields.
655
660
  *
656
661
  * This is equivalent to `tryResult(() => ..., toError)`, but it reads better when the boundary has
657
662
  * a clear domain name or label.
658
663
  */
659
- declare function tryResult<T, E>(options: TryResultOptions<T, E> & {
664
+ export declare function tryResult<T, E>(options: TryResultOptions<T, E> & {
660
665
  readonly catch: (e: unknown) => E;
661
666
  }): Result<T, E>;
662
667
  /**
@@ -665,20 +670,20 @@ declare function tryResult<T, E>(options: TryResultOptions<T, E> & {
665
670
  * Prefer the overload with a catch mapper in application code so the error channel stays documented.
666
671
  * This overload is useful while adapting unknown external failures or during migration.
667
672
  */
668
- 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>;
669
674
  /**
670
675
  * Creates an Ok result with `undefined`.
671
676
  */
672
- declare function unit<E = never>(): OkResult<undefined, E>;
677
+ export declare function unit<E = never>(): OkResult<undefined, E>;
673
678
  /**
674
679
  * Runs a `Result` at an application boundary and returns the success value.
675
680
  *
676
681
  * If the result is `Err`, this throws the error. Use it at final framework, CLI, test, or bootstrap
677
682
  * boundaries after the error channel has already been modeled with Resultar.
678
683
  */
679
- declare const runSync: <T, E>(result: Result<T, E>) => T;
684
+ export declare const runSync: <T, E>(result: Result<T, E>) => T;
680
685
  /** Compatibility alias. Prefer `tryResult` in new code. */
681
- declare const tryCatch: typeof tryResult;
686
+ export declare const tryCatch: typeof tryResult;
682
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[]];
683
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;
684
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;
@@ -700,7 +705,7 @@ type CombineResultsWithAllErrorsArray<T extends readonly Result<unknown, unknown
700
705
  /**
701
706
  * Standard cancellation error used by ResultAsync retry, race, timeout, and resource helpers.
702
707
  */
703
- declare class AbortError extends Error {
708
+ export declare class AbortError extends Error {
704
709
  /**
705
710
  * Creates an AbortError.
706
711
  */
@@ -709,7 +714,291 @@ declare class AbortError extends Error {
709
714
  /**
710
715
  * Checks whether a value is an AbortError or abort-shaped platform error.
711
716
  */
712
- declare const isAbortError: (value: unknown) => value is AbortError;
717
+ export declare const isAbortError: (value: unknown) => value is AbortError;
718
+ //#endregion
719
+ //#region src/result-task.d.ts
720
+ /** A failure cause produced by a `ResultTask` execution. */
721
+ type Cause<E> = {
722
+ readonly _tag: "Fail";
723
+ readonly error: E;
724
+ } | {
725
+ readonly _tag: "Die";
726
+ readonly defect: unknown;
727
+ } | {
728
+ readonly _tag: "Interrupt";
729
+ readonly reason: unknown;
730
+ } | {
731
+ readonly _tag: "Sequential";
732
+ readonly left: Cause<E>;
733
+ readonly right: Cause<E>;
734
+ };
735
+ /** Rejection used when a simplified boundary cannot represent multiple failures. */
736
+ export declare class ResultTaskCauseError extends Error {
737
+ override readonly cause: Cause<unknown>;
738
+ constructor(cause: Cause<unknown>);
739
+ }
740
+ /** Type identifier symbol for nominal `ResultTask` branding and variance checks. */
741
+ export declare const ResultTaskTypeId: unique symbol;
742
+ /** Type identifier symbol for nominal `ServiceTag` branding. */
743
+ export declare const ServiceTagTypeId: unique symbol;
744
+ /** Type identifier symbol for nominal `ResultTask` yieldable objects. */
745
+ export declare const ResultTaskYieldTypeId: unique symbol;
746
+ /** Error thrown as a Die cause when a requested service is not provided in the environment. */
747
+ export declare class MissingServiceError extends Error {
748
+ readonly serviceIdentifier: string;
749
+ constructor(serviceIdentifier: string);
750
+ }
751
+ declare const scopeTypeId: unique symbol;
752
+ /** Tracks deferred release failures until the owning scope is closed. */
753
+ interface ResultTaskScope<out E> {
754
+ readonly [scopeTypeId]: E;
755
+ }
756
+ type ScopeError<R> = R extends ResultTaskScope<infer E> ? E : never;
757
+ type WithoutScope<R> = Exclude<R, ResultTaskScope<unknown>>;
758
+ /** Resource acquisition and release share one execution and service environment. */
759
+ interface ResultTaskAcquireReleaseOptions<A, E, R, ReleaseError, ReleaseR> {
760
+ readonly acquire: ResultTask<A, E, R>;
761
+ readonly release: (resource: A, exit: Exit<unknown, unknown>) => ResultTask<void, ReleaseError, ReleaseR>;
762
+ }
763
+ /** The complete outcome of a `ResultTask` execution. */
764
+ type Exit<A, E> = {
765
+ readonly _tag: "Success";
766
+ readonly value: A;
767
+ } | {
768
+ readonly _tag: "Failure";
769
+ readonly cause: Cause<E>;
770
+ };
771
+ /** Handlers for matching both success and failure cases of a ResultTask. */
772
+ type ResultTaskMatchOptions<A, E, B, C = B> = {
773
+ readonly onSuccess: (value: A) => B;
774
+ readonly onFailure: (error: E) => C;
775
+ } | {
776
+ readonly ok: (value: A) => B;
777
+ readonly err: (error: E) => C;
778
+ };
779
+ /** A service that can be requested from a `ResultTask.gen` workflow. */
780
+ interface ServiceTag<Identifier extends string, Service> {
781
+ readonly [ServiceTagTypeId]: typeof ServiceTagTypeId;
782
+ readonly _tag: "ServiceTag";
783
+ readonly identifier: Identifier;
784
+ readonly key: symbol;
785
+ readonly [Symbol.iterator]: () => Generator<ResultTaskServiceYield<ServiceTag<Identifier, Service>>, Service, Service>;
786
+ }
787
+ /** Resolves a service requested by a `ResultTask.gen` workflow. */
788
+ type ResultTaskServiceResolver<R, E = never, ResolverR = never> = { readonly [Tag in Extract<R, AnyServiceTag> as Tag["identifier"]]: () => ResultTask<ServiceForTag<Tag>, E, ResolverR>; };
789
+ type ResolverTasks<Resolvers> = Resolvers[keyof Resolvers] extends (() => infer Task) ? Task : never;
790
+ type ResolverError<Resolvers> = [ResolverTasks<Resolvers>] extends [never] ? never : ResolverTasks<Resolvers> extends ResultTask<unknown, infer E, unknown> ? E : never;
791
+ type ResolverRequirements<Resolvers> = [ResolverTasks<Resolvers>] extends [never] ? never : ResolverTasks<Resolvers> extends ResultTask<unknown, unknown, infer R> ? R : never;
792
+ type EliminateProvidedServices<R, Services> = R extends AnyServiceTag ? R["identifier"] extends keyof Services ? Services[R["identifier"]] extends ServiceForTag<R> ? never : R : R : R;
793
+ type EliminateResolvedServices<R, Resolvers> = R extends AnyServiceTag ? R["identifier"] extends keyof Resolvers ? Resolvers[R["identifier"]] extends (() => ResultTask<infer S, unknown, unknown>) ? S extends ServiceForTag<R> ? never : R : R : R : R;
794
+ type IncompatibleProvidedServices<R, Services> = R extends AnyServiceTag ? R["identifier"] extends keyof Services ? Services[R["identifier"]] extends ServiceForTag<R> ? never : R["identifier"] : never : never;
795
+ type IncompatibleResolvedServices<R, Resolvers> = R extends AnyServiceTag ? R["identifier"] extends keyof Resolvers ? Resolvers[R["identifier"]] extends (() => ResultTask<infer S, unknown, unknown>) ? S extends ServiceForTag<R> ? never : R["identifier"] : R["identifier"] : never : never;
796
+ /** Owns resources across executions. Close it after its consumers have finished. */
797
+ interface ResultTaskScopeOwner {
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;
801
+ readonly close: (exit?: Exit<unknown, unknown>) => ResultTask<void, unknown>;
802
+ }
803
+ /** Options for running a `ResultTask` with an optional signal and its required services. */
804
+ type ResultTaskRunOptions<R = never> = {
805
+ readonly signal?: AbortSignal;
806
+ } & ([WithoutScope<R>] extends [never] ? {
807
+ readonly services?: never;
808
+ } : {
809
+ readonly services: ResultTaskServices<R>;
810
+ });
811
+ /** The object-shaped service environment required by a task. */
812
+ type ResultTaskServices<R> = { readonly [Tag in Extract<R, AnyServiceTag> as Tag["identifier"]]: ServiceForTag<Tag>; };
813
+ /** Options for creating a synchronous task with an explicit error boundary. */
814
+ interface ResultTaskTryOptions<A, E> {
815
+ readonly try: () => A;
816
+ readonly catch: (cause: unknown) => E;
817
+ }
818
+ /** Options for creating a lazy promise-producing task with an explicit error boundary. */
819
+ interface ResultTaskTryPromiseOptions<A, E> {
820
+ readonly try: (signal: AbortSignal) => PromiseLike<A>;
821
+ readonly catch: (cause: unknown) => E;
822
+ }
823
+ type AnyServiceTag = Pick<ServiceTag<string, unknown>, "_tag" | "identifier" | "key">;
824
+ type ServiceForTag<Tag> = Tag extends ServiceTag<string, infer Service> ? Service : never;
825
+ type WithoutServices<R> = Exclude<R, AnyServiceTag>;
826
+ interface ResultTaskYield<A, E, R> {
827
+ readonly [ResultTaskYieldTypeId]: typeof ResultTaskYieldTypeId;
828
+ readonly _tag: "ResultTask";
829
+ readonly task: ResultTask<A, E, R>;
830
+ }
831
+ interface ResultTaskServiceYield<Tag extends AnyServiceTag> {
832
+ readonly [ResultTaskYieldTypeId]: typeof ResultTaskYieldTypeId;
833
+ readonly _tag: "Service";
834
+ readonly tag: Tag;
835
+ }
836
+ type GeneratorError<Yield> = Yield extends {
837
+ readonly _tag: "ResultTask";
838
+ readonly task: infer Task;
839
+ } ? Task extends ResultTask<infer _A, infer E, infer _R> ? E : never : Yield extends {
840
+ readonly error: infer E;
841
+ readonly isErr: unknown;
842
+ } ? E : never;
843
+ type GeneratorRequirements<Yield> = Yield extends {
844
+ readonly _tag: "ResultTask";
845
+ readonly task: infer Task;
846
+ } ? Task extends ResultTask<infer _A, infer _E, infer R> ? R : never : Yield extends {
847
+ readonly _tag: "Service";
848
+ readonly tag: infer Tag;
849
+ } ? Tag : never;
850
+ type ResultTaskRunArguments<R> = [WithoutScope<R>] extends [never] ? [options?: ResultTaskRunOptions<R>] : [options: ResultTaskRunOptions<R>];
851
+ /** Returns true if a value is a nominal `ServiceTag`. */
852
+ export declare const isServiceTag: (value: unknown) => value is ServiceTag<string, unknown>;
853
+ /** Returns true if a value is a `ResultTask` instance. */
854
+ export declare const isResultTask: (value: unknown) => value is ResultTask<unknown, unknown, unknown>;
855
+ /** Creates a service tag that can be requested with `yield*` inside `ResultTask.gen`. */
856
+ export declare const serviceTag: <Service, const Identifier extends string = string>(identifier: Identifier) => ServiceTag<Identifier, Service>;
857
+ /**
858
+ * A lazy, composable workflow that can succeed with `A` or fail with `E`.
859
+ *
860
+ * Constructing a `ResultTask` never runs its work. Use `runResult`, `runExit`, or `runPromise` at an
861
+ * explicit application boundary to execute it.
862
+ */
863
+ export interface ResultTask<out A, out E = never, out R = never> {
864
+ readonly [ResultTaskTypeId]: {
865
+ readonly success: (_: never) => A;
866
+ readonly error: (_: never) => E;
867
+ readonly requirements: (_: never) => R;
868
+ };
869
+ }
870
+ export declare class ResultTask<out A, out E = never, out R = never> extends Pipeable {
871
+ #private;
872
+ private readonly typeWitness;
873
+ private readonly instruction;
874
+ private readonly execute;
875
+ private constructor();
876
+ private static runTaskLoop;
877
+ /** Creates a task that succeeds with `value` when it is executed. */
878
+ static succeed<A>(value: A): ResultTask<A, never>;
879
+ static succeed<A, E>(value: A): ResultTask<A, E>;
880
+ /** Creates a task that fails with `error` when it is executed. */
881
+ static fail<const E>(error: E): ResultTask<never, E>;
882
+ /** Lifts an already computed Result into a lazy task. */
883
+ static fromResult<A, E>(result: Result<A, E>): ResultTask<A, E>;
884
+ /** Creates a task for synchronous work. Thrown values are defects, not typed failures. */
885
+ static sync<A>(evaluate: () => A): ResultTask<A>;
886
+ /** Creates a task that maps synchronous throws into the typed error channel. */
887
+ static try<A, E>(options: ResultTaskTryOptions<A, E>): ResultTask<A, E>;
888
+ /** Creates a lazy task that preserves synchronous throws and promise rejections as unknown. */
889
+ static tryPromise<A>(run: (signal: AbortSignal) => PromiseLike<A>): ResultTask<A, unknown>;
890
+ /** Creates a lazy task that maps synchronous throws and promise rejections into `E`. */
891
+ static tryPromise<A, E>(options: ResultTaskTryPromiseOptions<A, E>): ResultTask<A, E>;
892
+ /**
893
+ * Acquires lazily and registers release in the current scope. Release failures remain in the
894
+ * scope requirement until `scoped` or a run boundary closes it; catchAll cannot erase them early.
895
+ */
896
+ static acquireRelease<A, E, R, ReleaseError = never, ReleaseR = never>(options: ResultTaskAcquireReleaseOptions<A, E, R, ReleaseError, ReleaseR>): ResultTask<A, E, R | WithoutScope<ReleaseR> | ResultTaskScope<ReleaseError | ScopeError<ReleaseR>>>;
897
+ /** Closes a child scope before continuing, adding its deferred release errors to E. */
898
+ static scoped<A, E, R>(task: ResultTask<A, E, R>): ResultTask<A, E | ScopeError<R>, WithoutScope<R>>;
899
+ /** Creates a service tag that can be requested with `yield*` inside `ResultTask.gen`. */
900
+ static service<Service, const Identifier extends string>(identifier: Identifier): ServiceTag<Identifier, Service>;
901
+ /** Builds a task from a generator and short-circuits on the first failed task. */
902
+ static gen<Yield, Return, Next>(body: () => Generator<Yield, Return, Next>): ResultTask<Return, GeneratorError<Yield>, GeneratorRequirements<Yield>>;
903
+ /** Maps the success value without executing the task. */
904
+ map<B>(f: (value: A) => B): ResultTask<B, E, R>;
905
+ /** Chains another task from the success value without executing either task immediately. */
906
+ flatMap<B, E2, R2>(f: (value: A) => ResultTask<B, E2, R2>): ResultTask<B, E | E2, R | R2>;
907
+ /** Alias for `flatMap`, matching the existing Resultar vocabulary. */
908
+ andThen<B, E2, R2>(f: (value: A) => ResultTask<B, E2, R2>): ResultTask<B, E | E2, R | R2>;
909
+ /**
910
+ * Recovers a single typed failure. Composite causes become a Die(ResultTaskCauseError) so the
911
+ * removed E cannot escape through runExit; the original tree remains available on error.cause.
912
+ */
913
+ catchAll<B, E2, R2>(f: (error: E) => ResultTask<B, E2, R2>): ResultTask<A | B, E2, R | R2>;
914
+ /** Maps the error value without executing the task. */
915
+ mapError<E2>(f: (error: E) => E2): ResultTask<A, E2, R>;
916
+ /**
917
+ * Executes a side effect on the success value without modifying it.
918
+ * If the callback returns a `ResultTask`, its requirements and errors are merged.
919
+ */
920
+ tap<E2 = never, R2 = never>(f: (value: A) => ResultTask<unknown, E2, R2> | Promise<unknown> | void): ResultTask<A, E | E2, R | R2>;
921
+ /**
922
+ * Executes a side effect on the error value without modifying it.
923
+ * If the callback returns a `ResultTask`, its requirements and errors are merged.
924
+ */
925
+ tapError<E2 = never, R2 = never>(f: (error: E) => ResultTask<unknown, E2, R2> | Promise<unknown> | void): ResultTask<A, E | E2, R | R2>;
926
+ /** Replaces the success value with a constant. */
927
+ as<B>(value: B): ResultTask<B, E, R>;
928
+ /**
929
+ * Transforms both success and failure cases into a single value type.
930
+ */
931
+ match<B, C = B>(handlers: ResultTaskMatchOptions<A, E, B, C>): ResultTask<B | C, never, R>;
932
+ /** Converts this ResultTask into an eagerly started ResultAsync using the standard runtime. */
933
+ toResultAsync(this: ResultTask<A, E, never>): ResultAsync<A, E>;
934
+ /** Provides one required service and removes it from the task's requirements. */
935
+ provideService<Tag extends Extract<R, AnyServiceTag>>(tag: Tag, ...args: [service: ServiceForTag<Tag>]): ResultTask<A, E, Exclude<R, Tag>>;
936
+ /** Provides all requirements using an object keyed by service identifier. */
937
+ provideServices(services: ResultTaskServices<R>): ResultTask<A, E, Extract<R, ResultTaskScope<unknown>>>;
938
+ /** Provides a lazy resolver for service tags that are not already in the environment. */
939
+ provideServiceResolver<Resolvers extends ResultTaskServiceResolver<NoInfer<R>, unknown, unknown>>(resolvers: Resolvers): ResultTask<A, E | ResolverError<Resolvers>, WithoutServices<R> | ResolverRequirements<Resolvers>>;
940
+ /** Enables `yield* task` inside `ResultTask.gen` workflows. */
941
+ [Symbol.iterator](): Generator<ResultTaskYield<A, E, R>, A, Exit<A, E>>;
942
+ /** Provides one required service and removes it from the task's requirements. */
943
+ static provideService<A, E, R, Tag extends Extract<R, AnyServiceTag>>(task: ResultTask<A, E, R>, tag: Tag, service: ServiceForTag<Tag>): ResultTask<A, E, Exclude<R, Tag>>;
944
+ static provideService<Tag extends AnyServiceTag>(tag: Tag, service: ServiceForTag<Tag>): <A, E, R>(task: ResultTask<A, E, R>) => ResultTask<A, E, Exclude<R, Tag>>;
945
+ /** Provides a lazy resolver for service tags that are not already in the environment. */
946
+ static provideServiceResolver<A, E, R, Resolvers extends ResultTaskServiceResolver<NoInfer<R>, unknown, unknown>>(task: ResultTask<A, E, R>, resolvers: Resolvers): ResultTask<A, E | ResolverError<Resolvers>, WithoutServices<R> | ResolverRequirements<Resolvers>>;
947
+ static provideServiceResolver<const Resolvers extends Readonly<Record<string, () => ResultTask<unknown, unknown, unknown>>>>(resolvers: Resolvers): <A, E, R>(task: [IncompatibleResolvedServices<R, Resolvers>] extends [never] ? ResultTask<A, E, R> : never) => ResultTask<A, E | ResolverError<Resolvers>, EliminateResolvedServices<R, Resolvers> | ResolverRequirements<Resolvers>>;
948
+ /** Shares one in-flight execution and successful value. Failed executions can be retried. */
949
+ static memoize<A, E, R>(task: ResultTask<A, E, R>): ResultTask<A, E, R>;
950
+ /** Creates an explicit resource owner for adapters that manage long-lived scopes. */
951
+ static makeScope(): ResultTaskScopeOwner;
952
+ /** Provides all requirements using an object keyed by service identifier. */
953
+ static provideServices<A, E, R>(task: ResultTask<A, E, R>, services: ResultTaskServices<R>): ResultTask<A, E, Extract<R, ResultTaskScope<unknown>>>;
954
+ static provideServices<const Services extends Readonly<Record<string, unknown>>>(services: Services): <A, E, R>(task: [IncompatibleProvidedServices<R, Services>] extends [never] ? ResultTask<A, E, R> : never) => ResultTask<A, E, EliminateProvidedServices<R, Services>>;
955
+ /** Maps the success value using the canonical functional form or curried for `pipe`. */
956
+ static map<A, E, R, B>(task: ResultTask<A, E, R>, f: (value: A) => B): ResultTask<B, E, R>;
957
+ static map<A, B>(f: (value: A) => B): <E, R>(task: ResultTask<A, E, R>) => ResultTask<B, E, R>;
958
+ /** Maps the error value using the canonical functional form or curried for `pipe`. */
959
+ static mapError<A, E, R, E2>(task: ResultTask<A, E, R>, f: (error: E) => E2): ResultTask<A, E2, R>;
960
+ static mapError<E, E2>(f: (error: E) => E2): <A, R>(task: ResultTask<A, E, R>) => ResultTask<A, E2, R>;
961
+ /** Chains a task using the canonical functional form or curried for `pipe`. */
962
+ static flatMap<A, E, R, B, E2, R2>(task: ResultTask<A, E, R>, f: (value: A) => ResultTask<B, E2, R2>): ResultTask<B, E | E2, R | R2>;
963
+ static flatMap<A, B, E2, R2>(f: (value: A) => ResultTask<B, E2, R2>): <E, R>(task: ResultTask<A, E, R>) => ResultTask<B, E | E2, R | R2>;
964
+ /** Alias for `flatMap`, matching the existing Resultar vocabulary. */
965
+ static andThen<A, E, R, B, E2, R2>(task: ResultTask<A, E, R>, f: (value: A) => ResultTask<B, E2, R2>): ResultTask<B, E | E2, R | R2>;
966
+ static andThen<A, B, E2, R2>(f: (value: A) => ResultTask<B, E2, R2>): <E, R>(task: ResultTask<A, E, R>) => ResultTask<B, E | E2, R | R2>;
967
+ /** Recovers from a typed failure using the canonical functional form or curried for `pipe`. */
968
+ static catchAll<A, E, R, B, E2, R2>(task: ResultTask<A, E, R>, f: (error: E) => ResultTask<B, E2, R2>): ResultTask<A | B, E2, R | R2>;
969
+ static catchAll<E, B, E2, R2>(f: (error: E) => ResultTask<B, E2, R2>): <A, R>(task: ResultTask<A, E, R>) => ResultTask<A | B, E2, R | R2>;
970
+ /** Executes a side effect on the success value using the canonical functional form or curried for `pipe`. */
971
+ static tap<A, E, R, E2 = never, R2 = never>(task: ResultTask<A, E, R>, f: (value: A) => ResultTask<unknown, E2, R2> | Promise<unknown> | void): ResultTask<A, E | E2, R | R2>;
972
+ static tap<A, E2 = never, R2 = never>(f: (value: A) => ResultTask<unknown, E2, R2> | Promise<unknown> | void): <E, R>(task: ResultTask<A, E, R>) => ResultTask<A, E | E2, R | R2>;
973
+ /** Executes a side effect on the error value using the canonical functional form or curried for `pipe`. */
974
+ static tapError<A, E, R, E2 = never, R2 = never>(task: ResultTask<A, E, R>, f: (error: E) => ResultTask<unknown, E2, R2> | Promise<unknown> | void): ResultTask<A, E | E2, R | R2>;
975
+ static tapError<E, E2 = never, R2 = never>(f: (error: E) => ResultTask<unknown, E2, R2> | Promise<unknown> | void): <A, R>(task: ResultTask<A, E, R>) => ResultTask<A, E | E2, R | R2>;
976
+ /** Replaces the success value with a constant using the canonical functional form or curried for `pipe`. */
977
+ static as<A, E, R, B>(task: ResultTask<A, E, R>, value: B): ResultTask<B, E, R>;
978
+ static as<B>(value: B): <A, E, R>(task: ResultTask<A, E, R>) => ResultTask<B, E, R>;
979
+ /** Matches both success and error cases using the canonical functional form or curried for `pipe`. */
980
+ static match<A, E, R, B, C = B>(task: ResultTask<A, E, R>, handlers: ResultTaskMatchOptions<A, E, B, C>): ResultTask<B | C, never, R>;
981
+ static match<A, E, B, C = B>(handlers: ResultTaskMatchOptions<A, E, B, C>): <R>(task: ResultTask<A, E, R>) => ResultTask<B | C, never, R>;
982
+ /**
983
+ * Eagerly executes a ResultTask using the standard runtime and returns a ResultAsync.
984
+ */
985
+ static toResultAsync<A, E>(task: ResultTask<A, E, never>): ResultAsync<A, E>;
986
+ /**
987
+ * Captures an existing ResultAsync or creates a lazy task from a ResultAsync factory.
988
+ */
989
+ static fromResultAsync<A, E>(asyncResultOrFactory: ResultAsync<A, E> | ((signal: AbortSignal) => ResultAsync<A, E>)): ResultTask<A, E>;
990
+ private static runExitInternal;
991
+ private static runResultInternal;
992
+ /** Runs a task and preserves success, typed failure, and runtime defects in an `Exit`. */
993
+ static runExit<A, E>(task: ResultTask<A, E, never>): Promise<Exit<A, E>>;
994
+ static runExit<A, E, R>(task: ResultTask<A, E, R>, ...args: ResultTaskRunArguments<R>): Promise<Exit<A, E | ScopeError<R>>>;
995
+ /** Returns single typed failures as Err; rejects defects, interruption, and composite causes. */
996
+ static runResult<A, E>(task: ResultTask<A, E, never>): Promise<Result<A, E>>;
997
+ static runResult<A, E, R>(task: ResultTask<A, E, R>, ...args: ResultTaskRunArguments<R>): Promise<Result<A, E | ScopeError<R>>>;
998
+ /** Runs a task and returns the success value, rejecting on typed failures or defects. */
999
+ static runPromise<A, E>(task: ResultTask<A, E, never>): Promise<A>;
1000
+ static runPromise<A, E, R>(task: ResultTask<A, E, R>, ...args: ResultTaskRunArguments<R>): Promise<A>;
1001
+ }
713
1002
  //#endregion
714
1003
  //#region src/result-async.d.ts
715
1004
  type ResultAsyncFinalizer<T, E> = (value: T | undefined, error: E | undefined) => void | Promise<void>;
@@ -1023,7 +1312,7 @@ interface ResultAsyncIfOptions<OnTrue extends ResultAsyncConditional, OnFalse ex
1023
1312
  readonly onTrue: () => OnTrue;
1024
1313
  }
1025
1314
  /** Async-disposable wrapper that finalizes a `ResultAsync` exactly once. */
1026
- declare class DisposableResultAsync<T, E> implements PromiseLike<Result<T, E>>, AsyncDisposable {
1315
+ export declare class DisposableResultAsync<T, E> implements PromiseLike<Result<T, E>>, AsyncDisposable {
1027
1316
  private readonly innerPromise;
1028
1317
  private readonly finalizer;
1029
1318
  private disposed;
@@ -1080,7 +1369,7 @@ declare class DisposableResultAsync<T, E> implements PromiseLike<Result<T, E>>,
1080
1369
  * - Conditional branching (if)
1081
1370
  * - Combining multiple ResultAsync instances (combine, combineWithAllErrors)
1082
1371
  */
1083
- 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>> {
1084
1373
  /**
1085
1374
  * Returns a ResultAsync instance that is immediately resolved with a Result.ok(value).
1086
1375
  *
@@ -1126,6 +1415,10 @@ declare class ResultAsync<T, E> extends Pipeable implements PromiseLike<Result<T
1126
1415
  * @return {ResultAsync<T, E>} A ResultAsync instance with the given promise and error type E.
1127
1416
  */
1128
1417
  static fromSafePromise<T, E = never>(this: void, promise: PromiseLike<T>): ResultAsync<T, E>;
1418
+ /**
1419
+ * Eagerly executes a ResultTask using the standard runtime and wraps it in a ResultAsync.
1420
+ */
1421
+ static fromTask<T, E>(this: void, task: ResultTask<T, E, never>): ResultAsync<T, E>;
1129
1422
  /**
1130
1423
  * Returns a ResultAsync instance that is resolved with a Result.ok(value) or Result.err(error)
1131
1424
  * based on the provided promise.
@@ -1410,33 +1703,33 @@ type StrictResultAsync<T, E extends Error = Error> = ResultAsync<T, E>;
1410
1703
  /**
1411
1704
  * Creates an Ok ResultAsync.
1412
1705
  */
1413
- declare const okAsync: typeof ResultAsync.okAsync;
1706
+ export declare const okAsync: typeof ResultAsync.okAsync;
1414
1707
  /**
1415
1708
  * Creates an Err ResultAsync.
1416
1709
  */
1417
- declare const errAsync: typeof ResultAsync.errAsync;
1710
+ export declare const errAsync: typeof ResultAsync.errAsync;
1418
1711
  /**
1419
1712
  * Adapts a callback or subscription API into a cancellable ResultAsync.
1420
1713
  */
1421
- declare const fromCallback: typeof ResultAsync.fromCallback;
1714
+ export declare const fromCallback: typeof ResultAsync.fromCallback;
1422
1715
  /**
1423
1716
  * Converts an existing promise into a ResultAsync and maps rejection into a typed Err.
1424
1717
  */
1425
- declare const fromPromise: typeof ResultAsync.fromPromise;
1718
+ export declare const fromPromise: typeof ResultAsync.fromPromise;
1426
1719
  /**
1427
1720
  * Converts an existing promise that is expected not to reject into a ResultAsync.
1428
1721
  *
1429
1722
  * Use `fromPromise` or `tryResultAsync` when rejection should become a typed Err.
1430
1723
  */
1431
- declare const fromSafePromise: typeof ResultAsync.fromSafePromise;
1724
+ export declare const fromSafePromise: typeof ResultAsync.fromSafePromise;
1432
1725
  /**
1433
1726
  * Creates an Ok ResultAsync with `undefined`.
1434
1727
  */
1435
- declare const unitAsync: typeof ResultAsync.unitAsync;
1728
+ export declare const unitAsync: typeof ResultAsync.unitAsync;
1436
1729
  /**
1437
1730
  * Wraps an async function so every later call returns a ResultAsync.
1438
1731
  */
1439
- declare const fromThrowableAsync: typeof ResultAsync.fromThrowable;
1732
+ export declare const fromThrowableAsync: typeof ResultAsync.fromThrowable;
1440
1733
  /**
1441
1734
  * Captures a promise or async factory into `ResultAsync<T, E>`.
1442
1735
  *
@@ -1454,7 +1747,7 @@ declare const fromThrowableAsync: typeof ResultAsync.fromThrowable;
1454
1747
  * )
1455
1748
  * ```
1456
1749
  */
1457
- 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>;
1458
1751
  /**
1459
1752
  * Captures an async boundary with named `try` and `catch` fields.
1460
1753
  *
@@ -1469,7 +1762,7 @@ declare function tryResultAsync<T, E>(fn: Promise<T> | (() => Promise<T>), error
1469
1762
  * })
1470
1763
  * ```
1471
1764
  */
1472
- declare function tryResultAsync<T, E>(options: TryResultAsyncOptions<T, E> & {
1765
+ export declare function tryResultAsync<T, E>(options: TryResultAsyncOptions<T, E> & {
1473
1766
  readonly catch: (e: unknown) => E;
1474
1767
  }): ResultAsync<T, E>;
1475
1768
  /**
@@ -1478,16 +1771,16 @@ declare function tryResultAsync<T, E>(options: TryResultAsyncOptions<T, E> & {
1478
1771
  * Prefer the overload with a catch mapper in application code so the error channel stays documented.
1479
1772
  * This overload is useful while adapting unknown external failures or during migration.
1480
1773
  */
1481
- 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>;
1482
1775
  /**
1483
1776
  * Runs a `ResultAsync` at an application boundary and returns the success value.
1484
1777
  *
1485
1778
  * If the result is `Err`, this rejects with the error. Use it at final framework, CLI, test, or
1486
1779
  * bootstrap boundaries after the error channel has already been modeled with Resultar.
1487
1780
  */
1488
- declare const runPromise: <T, E>(result: ResultAsync<T, E>) => Promise<T>;
1781
+ export declare const runPromise: <T, E>(result: ResultAsync<T, E>) => Promise<T>;
1489
1782
  /** Compatibility alias. Prefer `tryResultAsync` in new code. */
1490
- declare const tryCatchAsync: typeof tryResultAsync;
1783
+ export declare const tryCatchAsync: typeof tryResultAsync;
1491
1784
  type CombineResultAsyncs<T extends readonly ResultAsync<unknown, unknown>[]> = IsLiteralArray<T> extends 1 ? TraverseAsync<UnwrapAsync<T>> : ResultAsync<ExtractOkAsyncTypes<T>, ExtractErrAsyncTypes<T>[number]>;
1492
1785
  type CombineResultsWithAllErrorsArrayAsync<T extends readonly ResultAsync<unknown, unknown>[]> = IsLiteralArray<T> extends 1 ? TraverseWithAllErrorsAsync<UnwrapAsync<T>> : ResultAsync<ExtractOkAsyncTypes<T>, ExtractErrAsyncTypes<T>[number][]>;
1493
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;
@@ -1521,137 +1814,15 @@ type Redacted<T> = string & {
1521
1814
  /**
1522
1815
  * Wraps a sensitive value so tagged-error messages and JSON output show only a placeholder.
1523
1816
  */
1524
- declare const redact: <T>(value: T, label?: string) => Redacted<T>;
1817
+ export declare const redact: <T>(value: T, label?: string) => Redacted<T>;
1525
1818
  /**
1526
1819
  * Checks whether a value was created by `redact`.
1527
1820
  */
1528
- declare const isRedacted: (value: unknown) => value is Redacted<unknown>;
1821
+ export declare const isRedacted: (value: unknown) => value is Redacted<unknown>;
1529
1822
  /**
1530
1823
  * Returns the original sensitive value from a Redacted wrapper.
1531
1824
  */
1532
- declare const revealRedacted: <T>(value: Redacted<T>) => T;
1533
- //#endregion
1534
- //#region src/result-task.d.ts
1535
- /** A failure cause produced by a `ResultTask` execution. */
1536
- type Cause<E> = {
1537
- readonly _tag: "Fail";
1538
- readonly error: E;
1539
- } | {
1540
- readonly _tag: "Die";
1541
- readonly defect: unknown;
1542
- };
1543
- /** The complete outcome of a `ResultTask` execution. */
1544
- type Exit<A, E> = {
1545
- readonly _tag: "Success";
1546
- readonly value: A;
1547
- } | {
1548
- readonly _tag: "Failure";
1549
- readonly cause: Cause<E>;
1550
- };
1551
- /** A service that can be requested from a `ResultTask.gen` workflow. */
1552
- interface ServiceTag<Identifier extends string, Service> {
1553
- readonly _tag: "ServiceTag";
1554
- readonly identifier: Identifier;
1555
- readonly key: symbol;
1556
- readonly [Symbol.iterator]: () => Generator<ResultTaskServiceYield<ServiceTag<Identifier, Service>>, Service, Service>;
1557
- }
1558
- /** Options for running a `ResultTask` with an optional signal and its required services. */
1559
- type ResultTaskRunOptions<R = never> = {
1560
- readonly signal?: AbortSignal;
1561
- } & ([R] extends [never] ? {
1562
- readonly services?: never;
1563
- } : {
1564
- readonly services: ResultTaskServices<R>;
1565
- });
1566
- /** The object-shaped service environment required by a task. */
1567
- type ResultTaskServices<R> = { readonly [Tag in Extract<R, AnyServiceTag> as Tag["identifier"]]: ServiceForTag<Tag>; };
1568
- /** Options for creating a synchronous task with an explicit error boundary. */
1569
- interface ResultTaskTryOptions<A, E> {
1570
- readonly try: () => A;
1571
- readonly catch: (cause: unknown) => E;
1572
- }
1573
- /** Options for creating a lazy promise-producing task with an explicit error boundary. */
1574
- interface ResultTaskTryPromiseOptions<A, E> {
1575
- readonly try: (signal: AbortSignal) => PromiseLike<A>;
1576
- readonly catch: (cause: unknown) => E;
1577
- }
1578
- type AnyServiceTag = Pick<ServiceTag<string, unknown>, "_tag" | "identifier" | "key">;
1579
- type ServiceForTag<Tag> = Tag extends ServiceTag<string, infer Service> ? Service : never;
1580
- interface ResultTaskYield<A, E, R> {
1581
- readonly _tag: "ResultTask";
1582
- readonly task: ResultTask<A, E, R>;
1583
- }
1584
- interface ResultTaskServiceYield<Tag extends AnyServiceTag> {
1585
- readonly _tag: "Service";
1586
- readonly tag: Tag;
1587
- }
1588
- type GeneratorError<Yield> = Yield extends {
1589
- readonly _tag: "ResultTask";
1590
- readonly task: infer Task;
1591
- } ? Task extends ResultTask<infer _A, infer E, infer _R> ? E : never : never;
1592
- type GeneratorRequirements<Yield> = Yield extends {
1593
- readonly _tag: "ResultTask";
1594
- readonly task: infer Task;
1595
- } ? Task extends ResultTask<infer _A, infer _E, infer R> ? R : never : Yield extends {
1596
- readonly _tag: "Service";
1597
- readonly tag: infer Tag;
1598
- } ? Tag : never;
1599
- type ResultTaskRunArguments<R> = [R] extends [never] ? [options?: ResultTaskRunOptions<R>] : [options: ResultTaskRunOptions<R>];
1600
- /**
1601
- * A lazy, composable workflow that can succeed with `A` or fail with `E`.
1602
- *
1603
- * Constructing a `ResultTask` never runs its work. Use `runResult`, `runExit`, or `runPromise` at an
1604
- * explicit application boundary to execute it.
1605
- */
1606
- declare class ResultTask<A, E = never, R = never> extends Pipeable {
1607
- private readonly execute;
1608
- private constructor();
1609
- private readonly typeWitness;
1610
- /** Creates a task that succeeds with `value` when it is executed. */
1611
- static succeed<A, E = never>(value: A): ResultTask<A, E>;
1612
- /** Creates a task that fails with `error` when it is executed. */
1613
- static fail<const E>(error: E): ResultTask<never, E>;
1614
- /** Lifts an already computed Result into a lazy task. */
1615
- static fromResult<A, E>(result: Result<A, E>): ResultTask<A, E>;
1616
- /** Creates a task for synchronous work. Thrown values are defects, not typed failures. */
1617
- static sync<A>(evaluate: () => A): ResultTask<A>;
1618
- /** Creates a task that maps synchronous throws into the typed error channel. */
1619
- static try<A, E>(options: ResultTaskTryOptions<A, E>): ResultTask<A, E>;
1620
- /** Creates a lazy task that maps synchronous throws and promise rejections into `E`. */
1621
- static tryPromise<A, E>(options: ResultTaskTryPromiseOptions<A, E>): ResultTask<A, E>;
1622
- /** Creates a service tag that can be requested with `yield*` inside `ResultTask.gen`. */
1623
- static service<Service, const Identifier extends string>(identifier: Identifier): ServiceTag<Identifier, Service>;
1624
- /** Builds a task from a generator and short-circuits on the first failed task. */
1625
- static gen<Yield, Return, Next>(body: () => Generator<Yield, Return, Next>): ResultTask<Return, GeneratorError<Yield>, GeneratorRequirements<Yield>>;
1626
- /** Maps the success value without executing the task. */
1627
- map<B>(f: (value: A) => B): ResultTask<B, E, R>;
1628
- /** Chains another task from the success value without executing either task immediately. */
1629
- flatMap<B, E2, R2>(f: (value: A) => ResultTask<B, E2, R2>): ResultTask<B, E | E2, R | R2>;
1630
- /** Alias for `flatMap`, matching the existing Resultar vocabulary. */
1631
- andThen<B, E2, R2>(f: (value: A) => ResultTask<B, E2, R2>): ResultTask<B, E | E2, R | R2>;
1632
- /** Recovers from a typed failure without recovering from a runtime defect. */
1633
- catchAll<B, E2, R2>(f: (error: E) => ResultTask<B, E2, R2>): ResultTask<A | B, E2, R | R2>;
1634
- /** Enables `yield* task` inside `ResultTask.gen` workflows. */
1635
- [Symbol.iterator](): Generator<ResultTaskYield<A, E, R>, A, Exit<A, E>>;
1636
- /** Provides one required service and removes it from the task's requirements. */
1637
- static provideService<A, E, R, Tag extends Extract<R, AnyServiceTag>>(task: ResultTask<A, E, R>, tag: Tag, service: ServiceForTag<Tag>): ResultTask<A, E, Exclude<R, Tag>>;
1638
- /** Provides all requirements using an object keyed by service identifier. */
1639
- static provideServices<A, E, R>(task: ResultTask<A, E, R>, services: ResultTaskServices<R>): ResultTask<A, E>;
1640
- /** Maps the success value using the canonical functional form. */
1641
- static map<A, E, R, B>(task: ResultTask<A, E, R>, f: (value: A) => B): ResultTask<B, E, R>;
1642
- /** Chains a task using the canonical functional form. */
1643
- static flatMap<A, E, R, B, E2, R2>(task: ResultTask<A, E, R>, f: (value: A) => ResultTask<B, E2, R2>): ResultTask<B, E | E2, R | R2>;
1644
- /** Recovers from a typed failure using the canonical functional form. */
1645
- static catchAll<A, E, R, B, E2, R2>(task: ResultTask<A, E, R>, f: (error: E) => ResultTask<B, E2, R2>): ResultTask<A | B, E2, R | R2>;
1646
- private static runExitInternal;
1647
- private static runResultInternal;
1648
- /** Runs a task and preserves success, typed failure, and runtime defects in an `Exit`. */
1649
- static runExit<A, E, R>(task: ResultTask<A, E, R>, ...args: ResultTaskRunArguments<R>): Promise<Exit<A, E>>;
1650
- /** Runs a task and returns a Result, rejecting only when a runtime defect occurs. */
1651
- static runResult<A, E, R>(task: ResultTask<A, E, R>, ...args: ResultTaskRunArguments<R>): Promise<Result<A, E>>;
1652
- /** Runs a task and returns the success value, rejecting on typed failures or defects. */
1653
- static runPromise<A, E, R>(task: ResultTask<A, E, R>, ...args: ResultTaskRunArguments<R>): Promise<A>;
1654
- }
1825
+ export declare const revealRedacted: <T>(value: Redacted<T>) => T;
1655
1826
  //#endregion
1656
1827
  //#region src/tagged-error.d.ts
1657
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" | "_";
@@ -1780,12 +1951,12 @@ declare const defaultMessageTemplate = "$message";
1780
1951
  /**
1781
1952
  * Narrows a value to native or platform-recognized Error.
1782
1953
  */
1783
- declare function isError(value: unknown): value is Error;
1784
- 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>;
1785
1956
  /**
1786
1957
  * Finds the first cause in an Error cause chain that is an instance of `ErrorClass`.
1787
1958
  */
1788
- 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;
1789
1960
  /**
1790
1961
  * Creates an Error class with a stable `_tag`, typed template props, cause support, and JSON output.
1791
1962
  *
@@ -1799,22 +1970,22 @@ declare const findCause: <T extends Error>(error: Error, ErrorClass: ErrorClass<
1799
1970
  * }) {}
1800
1971
  * ```
1801
1972
  */
1802
- 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"> & {
1803
1974
  readonly message?: RejectReservedTemplateVariables<MessageTemplate>;
1804
1975
  }): TaggedErrorClass<Tag, MessageTemplate, Base>;
1805
1976
  /**
1806
1977
  * Creates a small tagged-union factory with member constructors, `$is`, and `$match`.
1807
1978
  */
1808
- declare const taggedEnum: <Members extends Record<string, object>>() => TaggedEnumFactory<Members>;
1979
+ export declare const taggedEnum: <Members extends Record<string, object>>() => TaggedEnumFactory<Members>;
1809
1980
  /**
1810
1981
  * Matches an Error by tagged `_tag`, with optional native `Error` fallback.
1811
1982
  *
1812
1983
  * Throws the original error when no handler matches.
1813
1984
  */
1814
- 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;
1815
1986
  /**
1816
1987
  * Matches an Error by tagged `_tag`, then native `Error`, then the provided fallback.
1817
1988
  */
1818
- 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;
1819
1990
  //#endregion
1820
- export { AbortError, type Cause, DisposableResult, DisposableResultAsync, type ErrResult, type Exit, 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 ResultTaskRunOptions, 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, createTaggedError, tryResult as default, tryResult as try, tryResult, err, errAsync, findCause, fromCallback, fromPromise, fromSafePromise, fromThrowable, fromThrowableAsync, isAbortError, isError, isRedacted, matchError, matchErrorPartial, ok, okAsync, redact, revealRedacted, runPromise, runSync, safeTry, 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 };