@nlozgachev/pipelined 0.43.0 → 0.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -10
- package/dist/{InternalTypes-DuzMFAfJ.d.ts → InternalTypes-7o9-yrHq.d.ts} +1 -1
- package/dist/{InternalTypes-DsCqxWZm.d.mts → InternalTypes-BL23H8Qr.d.mts} +1 -1
- package/dist/{Validation-BOPLiDqa.d.ts → Validation-DM2eh6wj.d.ts} +126 -126
- package/dist/{Validation-Do6uWLLZ.d.mts → Validation-Dz70wtcG.d.mts} +126 -126
- package/dist/{chunk-W6RWKBDX.mjs → chunk-LKTOK5IT.mjs} +1 -1
- package/dist/{chunk-CHRXZIJU.mjs → chunk-ND476266.mjs} +3 -0
- package/dist/composition.d.mts +1 -1
- package/dist/composition.d.ts +1 -1
- package/dist/core.d.mts +4 -4
- package/dist/core.d.ts +4 -4
- package/dist/core.js +6 -0
- package/dist/core.mjs +7 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -0
- package/dist/index.mjs +8 -2
- package/dist/utils.d.mts +4 -4
- package/dist/utils.d.ts +4 -4
- package/dist/utils.mjs +2 -2
- package/package.json +5 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { g as WithKind, n as WithValue, d as WithError, T as Thenable, D as Deferred, N as NonEmptyArr, e as WithErrors } from './InternalTypes-
|
|
1
|
+
import { g as WithKind, n as WithValue, d as WithError, T as Thenable, D as Deferred, N as NonEmptyArr, e as WithErrors } from './InternalTypes-BL23H8Qr.mjs';
|
|
2
2
|
import { Duration } from './types.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -709,13 +709,13 @@ declare namespace Result {
|
|
|
709
709
|
*
|
|
710
710
|
* @example
|
|
711
711
|
* ```ts
|
|
712
|
-
* const findUser = (id: string):
|
|
713
|
-
*
|
|
712
|
+
* const findUser = (id: string): Task.Maybe<User> =>
|
|
713
|
+
* Task.Maybe.tryCatch(() => db.users.findById(id));
|
|
714
714
|
*
|
|
715
715
|
* pipe(
|
|
716
716
|
* findUser("123"),
|
|
717
|
-
*
|
|
718
|
-
*
|
|
717
|
+
* Task.Maybe.map(user => user.name),
|
|
718
|
+
* Task.Maybe.getOrElse(() => "Unknown")
|
|
719
719
|
* )();
|
|
720
720
|
* ```
|
|
721
721
|
*/
|
|
@@ -726,74 +726,74 @@ declare namespace TaskMaybe {
|
|
|
726
726
|
*/
|
|
727
727
|
const some: <A>(value: A) => TaskMaybe<A>;
|
|
728
728
|
/**
|
|
729
|
-
* Creates a
|
|
729
|
+
* Creates a Task.Maybe that resolves to None.
|
|
730
730
|
*/
|
|
731
731
|
const none: <A = never>() => TaskMaybe<A>;
|
|
732
732
|
/**
|
|
733
|
-
* Lifts an Option into a
|
|
733
|
+
* Lifts an Option into a Task.Maybe.
|
|
734
734
|
*/
|
|
735
735
|
const fromMaybe: <A>(option: Maybe<A>) => TaskMaybe<A>;
|
|
736
736
|
/**
|
|
737
|
-
* Creates a
|
|
737
|
+
* Creates a Task.Maybe from a nullable value.
|
|
738
738
|
* Returns Some if the value is not null or undefined, None otherwise.
|
|
739
739
|
*/
|
|
740
740
|
const fromNullable: <A>(value: A | null | undefined) => TaskMaybe<A>;
|
|
741
741
|
/**
|
|
742
|
-
* Creates a
|
|
742
|
+
* Creates a Task.Maybe from a Result.
|
|
743
743
|
* Ok becomes Some, Error becomes None (the error value is discarded).
|
|
744
744
|
*/
|
|
745
745
|
const fromResult: <E, A>(result: Result<E, A>) => TaskMaybe<A>;
|
|
746
746
|
/**
|
|
747
|
-
* Lifts a Task into a
|
|
747
|
+
* Lifts a Task into a Task.Maybe by wrapping its result in Some.
|
|
748
748
|
*/
|
|
749
749
|
const fromTask: <A>(task: Task<A>) => TaskMaybe<A>;
|
|
750
750
|
/**
|
|
751
|
-
* Creates a
|
|
751
|
+
* Creates a Task.Maybe from a Promise-returning function.
|
|
752
752
|
* Returns Some if the promise resolves, None if it rejects.
|
|
753
753
|
* The factory optionally receives an `AbortSignal` forwarded from the call site.
|
|
754
754
|
*
|
|
755
755
|
* @example
|
|
756
756
|
* ```ts
|
|
757
|
-
* const fetchUser =
|
|
757
|
+
* const fetchUser = Task.Maybe.tryCatch((signal) =>
|
|
758
758
|
* fetch("/user/1", { signal }).then(r => r.json())
|
|
759
759
|
* );
|
|
760
760
|
* ```
|
|
761
761
|
*/
|
|
762
762
|
const tryCatch: <A>(f: (signal?: AbortSignal) => Thenable<A>) => TaskMaybe<A>;
|
|
763
763
|
/**
|
|
764
|
-
* Transforms the value inside a
|
|
764
|
+
* Transforms the value inside a Task.Maybe.
|
|
765
765
|
*/
|
|
766
766
|
const map: <A, B>(f: (a: A) => B) => (data: TaskMaybe<A>) => TaskMaybe<B>;
|
|
767
767
|
/**
|
|
768
|
-
* Chains
|
|
768
|
+
* Chains Task.Maybe computations. If the first resolves to Some, passes the
|
|
769
769
|
* value to f. If the first resolves to None, propagates None.
|
|
770
770
|
*
|
|
771
771
|
* @example
|
|
772
772
|
* ```ts
|
|
773
773
|
* pipe(
|
|
774
774
|
* findUser("123"),
|
|
775
|
-
*
|
|
775
|
+
* Task.Maybe.chain(user => findOrg(user.orgId))
|
|
776
776
|
* )();
|
|
777
777
|
* ```
|
|
778
778
|
*/
|
|
779
779
|
const chain: <A, B>(f: (a: A) => TaskMaybe<B>) => (data: TaskMaybe<A>) => TaskMaybe<B>;
|
|
780
780
|
/**
|
|
781
|
-
* Applies a function wrapped in a
|
|
781
|
+
* Applies a function wrapped in a Task.Maybe to a value wrapped in a Task.Maybe.
|
|
782
782
|
* Both Tasks run in parallel.
|
|
783
783
|
*/
|
|
784
784
|
const ap: <A>(arg: TaskMaybe<A>) => <B>(data: TaskMaybe<(a: A) => B>) => TaskMaybe<B>;
|
|
785
785
|
/**
|
|
786
|
-
* Extracts a value from a
|
|
786
|
+
* Extracts a value from a Task.Maybe by providing handlers for both cases.
|
|
787
787
|
*/
|
|
788
788
|
const fold: <A, B>(onNone: () => B, onSome: (a: A) => B) => (data: TaskMaybe<A>) => Task<B>;
|
|
789
789
|
/**
|
|
790
|
-
* Pattern matches on a
|
|
790
|
+
* Pattern matches on a Task.Maybe, returning a Task of the result.
|
|
791
791
|
*
|
|
792
792
|
* @example
|
|
793
793
|
* ```ts
|
|
794
794
|
* pipe(
|
|
795
795
|
* findUser("123"),
|
|
796
|
-
*
|
|
796
|
+
* Task.Maybe.match({
|
|
797
797
|
* some: user => `Hello, ${user.name}`,
|
|
798
798
|
* none: () => "User not found"
|
|
799
799
|
* })
|
|
@@ -805,74 +805,74 @@ declare namespace TaskMaybe {
|
|
|
805
805
|
some: (a: A) => B;
|
|
806
806
|
}) => (data: TaskMaybe<A>) => Task<B>;
|
|
807
807
|
/**
|
|
808
|
-
* Returns the value or a default if the
|
|
808
|
+
* Returns the value or a default if the Task.Maybe resolves to None.
|
|
809
809
|
* The default can be a different type, widening the result to `Task<A | B>`.
|
|
810
810
|
*/
|
|
811
811
|
const getOrElse: <A, B>(defaultValue: () => B) => (data: TaskMaybe<A>) => Task<A | B>;
|
|
812
812
|
/**
|
|
813
|
-
* Executes a side effect on the value without changing the
|
|
813
|
+
* Executes a side effect on the value without changing the Task.Maybe.
|
|
814
814
|
* Useful for logging or debugging.
|
|
815
815
|
*/
|
|
816
816
|
const tap: <A>(f: (a: A) => void) => (data: TaskMaybe<A>) => TaskMaybe<A>;
|
|
817
817
|
/**
|
|
818
|
-
* Filters the value inside a
|
|
818
|
+
* Filters the value inside a Task.Maybe. Returns None if the predicate fails.
|
|
819
819
|
*/
|
|
820
820
|
const filter: <A>(predicate: (a: A) => boolean) => (data: TaskMaybe<A>) => TaskMaybe<A>;
|
|
821
821
|
/**
|
|
822
|
-
* Converts a
|
|
822
|
+
* Converts a Task.Maybe to a Task.Result, using onNone to produce the error value.
|
|
823
823
|
*
|
|
824
824
|
* @example
|
|
825
825
|
* ```ts
|
|
826
826
|
* pipe(
|
|
827
827
|
* findUser("123"),
|
|
828
|
-
*
|
|
828
|
+
* Task.Maybe.toResult(() => "User not found")
|
|
829
829
|
* );
|
|
830
830
|
* ```
|
|
831
831
|
*/
|
|
832
832
|
const toResult: <E>(onNone: () => E) => <A>(data: TaskMaybe<A>) => Task.Result<E, A>;
|
|
833
833
|
/**
|
|
834
|
-
* Lifts a
|
|
834
|
+
* Lifts a Task.Maybe value into an accumulator object.
|
|
835
835
|
*
|
|
836
836
|
* @example
|
|
837
837
|
* ```ts
|
|
838
|
-
* pipe(
|
|
838
|
+
* pipe(Task.Maybe.some(42), Task.Maybe.bindTo("value")); // Task.Maybe({ value: 42 })
|
|
839
839
|
* ```
|
|
840
840
|
*/
|
|
841
841
|
const bindTo: <K extends string>(key: K) => <A>(data: TaskMaybe<A>) => TaskMaybe<{ [P in K]: A; }>;
|
|
842
842
|
/**
|
|
843
|
-
* Evaluates a new
|
|
843
|
+
* Evaluates a new Task.Maybe using the current accumulator and attaches the output to a new key.
|
|
844
844
|
*
|
|
845
845
|
* @example
|
|
846
846
|
* ```ts
|
|
847
847
|
* pipe(
|
|
848
|
-
*
|
|
849
|
-
*
|
|
850
|
-
* ); //
|
|
848
|
+
* Task.Maybe.some({ a: 1 }),
|
|
849
|
+
* Task.Maybe.bind("b", ({ a }) => Task.Maybe.some(a + 1))
|
|
850
|
+
* ); // Task.Maybe({ a: 1, b: 2 })
|
|
851
851
|
* ```
|
|
852
852
|
*/
|
|
853
853
|
const bind: <K extends string, A, B>(key: K, f: (a: A) => TaskMaybe<B>) => (data: TaskMaybe<A>) => TaskMaybe<A & { [P in K]: B; }>;
|
|
854
854
|
/**
|
|
855
|
-
* Recovers from a None state by providing a fallback
|
|
855
|
+
* Recovers from a None state by providing a fallback Task.Maybe.
|
|
856
856
|
*
|
|
857
857
|
* @example
|
|
858
858
|
* ```ts
|
|
859
859
|
* pipe(
|
|
860
|
-
*
|
|
861
|
-
*
|
|
862
|
-
* ); //
|
|
860
|
+
* Task.Maybe.none(),
|
|
861
|
+
* Task.Maybe.recover(() => Task.Maybe.some(42))
|
|
862
|
+
* ); // Task.Maybe(42)
|
|
863
863
|
* ```
|
|
864
864
|
*/
|
|
865
865
|
const recover: <A, B>(fallback: () => TaskMaybe<B>) => (data: TaskMaybe<A>) => TaskMaybe<A | B>;
|
|
866
866
|
/**
|
|
867
|
-
* Combines a record of
|
|
867
|
+
* Combines a record of Task.Maybes into a single Task.Maybe of a record.
|
|
868
868
|
* Evaluates fields in parallel and returns None if any task resolves to None.
|
|
869
869
|
*
|
|
870
870
|
* @example
|
|
871
871
|
* ```ts
|
|
872
|
-
*
|
|
873
|
-
* name:
|
|
874
|
-
* age:
|
|
875
|
-
* }); //
|
|
872
|
+
* Task.Maybe.struct({
|
|
873
|
+
* name: Task.Maybe.some("Alice"),
|
|
874
|
+
* age: Task.Maybe.some(30)
|
|
875
|
+
* }); // Task.Maybe({ name: "Alice", age: 30 })
|
|
876
876
|
* ```
|
|
877
877
|
*/
|
|
878
878
|
const struct: <R extends Record<string, any>>(fields: { [K in keyof R]: TaskMaybe<R[K]>; }) => TaskMaybe<R>;
|
|
@@ -884,8 +884,8 @@ declare namespace TaskMaybe {
|
|
|
884
884
|
*
|
|
885
885
|
* @example
|
|
886
886
|
* ```ts
|
|
887
|
-
* const fetchUser = (id: string):
|
|
888
|
-
*
|
|
887
|
+
* const fetchUser = (id: string): Task.Result<Error, User> =>
|
|
888
|
+
* Task.Result.tryCatch(
|
|
889
889
|
* (signal) => fetch(`/users/${id}`, { signal }).then(r => r.json()),
|
|
890
890
|
* (e) => new Error(`Failed to fetch user: ${e}`)
|
|
891
891
|
* );
|
|
@@ -894,41 +894,41 @@ declare namespace TaskMaybe {
|
|
|
894
894
|
type TaskResult<E, A> = Task<Result<E, A>>;
|
|
895
895
|
declare namespace TaskResult {
|
|
896
896
|
/**
|
|
897
|
-
* Wraps a value in a successful
|
|
897
|
+
* Wraps a value in a successful Task.Result.
|
|
898
898
|
*/
|
|
899
899
|
const ok: <E, A>(value: A) => TaskResult<E, A>;
|
|
900
900
|
/**
|
|
901
|
-
* Creates a failed
|
|
901
|
+
* Creates a failed Task.Result with the given error.
|
|
902
902
|
*/
|
|
903
903
|
const err: <E, A>(error: E) => TaskResult<E, A>;
|
|
904
904
|
/**
|
|
905
|
-
* Creates a
|
|
905
|
+
* Creates a Task.Result from a nullable value.
|
|
906
906
|
* Returns Ok if the value is not null or undefined, err from onNull otherwise.
|
|
907
907
|
*/
|
|
908
908
|
const fromNullable: <E>(onNull: () => E) => <A>(value: A | null | undefined) => TaskResult<E, A>;
|
|
909
909
|
/**
|
|
910
|
-
* Creates a
|
|
910
|
+
* Creates a Task.Result from a Maybe.
|
|
911
911
|
* Some becomes Ok, None becomes err from onNone.
|
|
912
912
|
*/
|
|
913
913
|
const fromMaybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => TaskResult<E, A>;
|
|
914
914
|
/**
|
|
915
|
-
* Lifts a Result into a
|
|
915
|
+
* Lifts a Result into a Task.Result.
|
|
916
916
|
*/
|
|
917
917
|
const fromResult: <E, A>(result: Result<E, A>) => TaskResult<E, A>;
|
|
918
918
|
/**
|
|
919
919
|
* Wraps a Promise-returning function of any arguments, returning a new function
|
|
920
|
-
* that catches rejections and returns a
|
|
920
|
+
* that catches rejections and returns a Task.Result.
|
|
921
921
|
*/
|
|
922
922
|
const fromThrowable: <Args extends readonly unknown[], A, E>(f: (...args: Args) => Promise<A>, onError: (e: unknown) => E) => (...args: Args) => TaskResult<E, A>;
|
|
923
923
|
/**
|
|
924
|
-
* Creates a
|
|
924
|
+
* Creates a Task.Result from a function that may throw.
|
|
925
925
|
* Catches any errors and transforms them using the onError function.
|
|
926
926
|
* The factory optionally receives an `AbortSignal` forwarded from the call site.
|
|
927
927
|
*
|
|
928
928
|
* @example
|
|
929
929
|
* ```ts
|
|
930
|
-
* const fetchUser = (id: string):
|
|
931
|
-
*
|
|
930
|
+
* const fetchUser = (id: string): Task.Result<string, User> =>
|
|
931
|
+
* Task.Result.tryCatch(
|
|
932
932
|
* (signal) => fetch(`/users/${id}`, { signal }).then(r => r.json()),
|
|
933
933
|
* String
|
|
934
934
|
* );
|
|
@@ -936,65 +936,65 @@ declare namespace TaskResult {
|
|
|
936
936
|
*/
|
|
937
937
|
const tryCatch: <E, A>(f: (signal?: AbortSignal) => Thenable<A>, onError: (e: unknown) => E) => TaskResult<E, A>;
|
|
938
938
|
/**
|
|
939
|
-
* Transforms the success value inside a
|
|
939
|
+
* Transforms the success value inside a Task.Result.
|
|
940
940
|
*/
|
|
941
941
|
const map: <E, A, B>(f: (a: A) => B) => (data: TaskResult<E, A>) => TaskResult<E, B>;
|
|
942
942
|
/**
|
|
943
|
-
* Transforms the error value inside a
|
|
943
|
+
* Transforms the error value inside a Task.Result.
|
|
944
944
|
*/
|
|
945
945
|
const mapError: <E, F, A>(f: (e: E) => F) => (data: TaskResult<E, A>) => TaskResult<F, A>;
|
|
946
946
|
/**
|
|
947
|
-
* Chains
|
|
947
|
+
* Chains Task.Result computations. If the first succeeds, passes the value to f.
|
|
948
948
|
* If the first fails, propagates the error.
|
|
949
949
|
*/
|
|
950
950
|
const chain: <E, A, B>(f: (a: A) => TaskResult<E, B>) => (data: TaskResult<E, A>) => TaskResult<E, B>;
|
|
951
951
|
/**
|
|
952
|
-
* Extracts the value from a
|
|
952
|
+
* Extracts the value from a Task.Result by providing handlers for both cases.
|
|
953
953
|
*/
|
|
954
954
|
const fold: <E, A, B>(onErr: (e: E) => B, onOk: (a: A) => B) => (data: TaskResult<E, A>) => Task<B>;
|
|
955
955
|
/**
|
|
956
|
-
* Pattern matches on a
|
|
956
|
+
* Pattern matches on a Task.Result, returning a Task of the result.
|
|
957
957
|
*/
|
|
958
958
|
const match: <E, A, B>(cases: {
|
|
959
959
|
err: (e: E) => B;
|
|
960
960
|
ok: (a: A) => B;
|
|
961
961
|
}) => (data: TaskResult<E, A>) => Task<B>;
|
|
962
962
|
/**
|
|
963
|
-
* Recovers from an error by providing a fallback
|
|
964
|
-
* The fallback can produce a different success type, widening the result to `
|
|
963
|
+
* Recovers from an error by providing a fallback Task.Result.
|
|
964
|
+
* The fallback can produce a different success type, widening the result to `Task.Result<E, A | B>`.
|
|
965
965
|
*/
|
|
966
966
|
const recover: <E, A, B>(fallback: (e: E) => TaskResult<E, B>) => (data: TaskResult<E, A>) => TaskResult<E, A | B>;
|
|
967
967
|
/**
|
|
968
|
-
* Returns the success value or a default value if the
|
|
968
|
+
* Returns the success value or a default value if the Task.Result is an error.
|
|
969
969
|
* The default can be a different type, widening the result to `Task<A | B>`.
|
|
970
970
|
*/
|
|
971
971
|
const getOrElse: <E, A, B>(defaultValue: () => B) => (data: TaskResult<E, A>) => Task<A | B>;
|
|
972
972
|
/**
|
|
973
|
-
* Executes a side effect on the success value without changing the
|
|
973
|
+
* Executes a side effect on the success value without changing the Task.Result.
|
|
974
974
|
* Useful for logging or debugging.
|
|
975
975
|
*/
|
|
976
976
|
const tap: <E, A>(f: (a: A) => void) => (data: TaskResult<E, A>) => TaskResult<E, A>;
|
|
977
977
|
/**
|
|
978
|
-
* Executes a side effect on the error value without changing the
|
|
978
|
+
* Executes a side effect on the error value without changing the Task.Result.
|
|
979
979
|
* Useful for logging or reporting async errors.
|
|
980
980
|
*
|
|
981
981
|
* @example
|
|
982
982
|
* ```ts
|
|
983
983
|
* pipe(
|
|
984
984
|
* fetchUser(id),
|
|
985
|
-
*
|
|
986
|
-
*
|
|
985
|
+
* Task.Result.tapError(e => console.error("fetch failed:", e)),
|
|
986
|
+
* Task.Result.chain(saveToCache),
|
|
987
987
|
* )
|
|
988
988
|
* ```
|
|
989
989
|
*/
|
|
990
990
|
const tapError: <E, A>(f: (e: E) => void) => (data: TaskResult<E, A>) => TaskResult<E, A>;
|
|
991
991
|
/**
|
|
992
|
-
* Applies a function wrapped in a
|
|
992
|
+
* Applies a function wrapped in a Task.Result to a value wrapped in a Task.Result.
|
|
993
993
|
* Both Tasks run in parallel.
|
|
994
994
|
*/
|
|
995
995
|
const ap: <E, A>(arg: TaskResult<E, A>) => <B>(data: TaskResult<E, (a: A) => B>) => TaskResult<E, B>;
|
|
996
996
|
/**
|
|
997
|
-
* Executes a `
|
|
997
|
+
* Executes a `Task.Result` with an optional signal, returning `Promise<Result<E, A>>`.
|
|
998
998
|
* Use as a terminal step in a `pipe` chain.
|
|
999
999
|
*
|
|
1000
1000
|
* @example
|
|
@@ -1002,46 +1002,46 @@ declare namespace TaskResult {
|
|
|
1002
1002
|
* const controller = new AbortController();
|
|
1003
1003
|
* const result = await pipe(
|
|
1004
1004
|
* fetchUser("42"),
|
|
1005
|
-
*
|
|
1006
|
-
*
|
|
1005
|
+
* Task.Result.chain(user => fetchPosts(user.id)),
|
|
1006
|
+
* Task.Result.run(controller.signal),
|
|
1007
1007
|
* );
|
|
1008
1008
|
* if (Result.isOk(result)) render(result.value);
|
|
1009
1009
|
* ```
|
|
1010
1010
|
*/
|
|
1011
1011
|
const run: (signal?: AbortSignal) => <E, A>(task: TaskResult<E, A>) => Deferred<Result<E, A>>;
|
|
1012
1012
|
/**
|
|
1013
|
-
* Converts a
|
|
1013
|
+
* Converts a Task.Result value into an object containing a single property.
|
|
1014
1014
|
* Initiates the pipeline accumulator record.
|
|
1015
1015
|
*
|
|
1016
1016
|
* @example
|
|
1017
1017
|
* ```ts
|
|
1018
|
-
* pipe(
|
|
1018
|
+
* pipe(Task.Result.ok(42), Task.Result.bindTo("value")); // Task.Result({ value: 42 })
|
|
1019
1019
|
* ```
|
|
1020
1020
|
*/
|
|
1021
1021
|
const bindTo: <K extends string>(key: K) => <E, A>(data: TaskResult<E, A>) => TaskResult<E, { [P in K]: A; }>;
|
|
1022
1022
|
/**
|
|
1023
|
-
* Evaluates a new
|
|
1023
|
+
* Evaluates a new Task.Result using the current accumulator and attaches the output to a new key.
|
|
1024
1024
|
*
|
|
1025
1025
|
* @example
|
|
1026
1026
|
* ```ts
|
|
1027
1027
|
* pipe(
|
|
1028
|
-
*
|
|
1029
|
-
*
|
|
1030
|
-
* ); //
|
|
1028
|
+
* Task.Result.ok({ a: 1 }),
|
|
1029
|
+
* Task.Result.bind("b", ({ a }) => Task.Result.ok(a + 1))
|
|
1030
|
+
* ); // Task.Result({ a: 1, b: 2 })
|
|
1031
1031
|
* ```
|
|
1032
1032
|
*/
|
|
1033
1033
|
const bind: <K extends string, E, A, B>(key: K, f: (a: A) => TaskResult<E, B>) => (data: TaskResult<E, A>) => TaskResult<E, A & { [P in K]: B; }>;
|
|
1034
1034
|
/**
|
|
1035
|
-
* Combines a record of
|
|
1035
|
+
* Combines a record of Task.Results into a single Task.Result of a record.
|
|
1036
1036
|
* Evaluates all tasks in parallel, forwarding the AbortSignal down to each sub-task.
|
|
1037
1037
|
* Returns the first Err encountered in key order.
|
|
1038
1038
|
*
|
|
1039
1039
|
* @example
|
|
1040
1040
|
* ```ts
|
|
1041
|
-
*
|
|
1042
|
-
* name:
|
|
1043
|
-
* age:
|
|
1044
|
-
* }); //
|
|
1041
|
+
* Task.Result.struct({
|
|
1042
|
+
* name: Task.Result.ok("Alice"),
|
|
1043
|
+
* age: Task.Result.ok(30)
|
|
1044
|
+
* }); // Task.Result({ name: "Alice", age: 30 })
|
|
1045
1045
|
* ```
|
|
1046
1046
|
*/
|
|
1047
1047
|
const struct: <E, R extends Record<string, any>>(fields: { [K in keyof R]: TaskResult<E, R[K]>; }) => TaskResult<E, R>;
|
|
@@ -1049,21 +1049,21 @@ declare namespace TaskResult {
|
|
|
1049
1049
|
|
|
1050
1050
|
/**
|
|
1051
1051
|
* A Task that resolves to a Validation — combining async operations with
|
|
1052
|
-
* error accumulation. Unlike
|
|
1052
|
+
* error accumulation. Unlike Task.Result, multiple failures are collected
|
|
1053
1053
|
* rather than short-circuiting on the first error.
|
|
1054
1054
|
*
|
|
1055
1055
|
* @example
|
|
1056
1056
|
* ```ts
|
|
1057
|
-
* const validateName = (name: string):
|
|
1057
|
+
* const validateName = (name: string): Task.Validation<string, string> =>
|
|
1058
1058
|
* name.length > 0
|
|
1059
|
-
* ?
|
|
1060
|
-
* :
|
|
1059
|
+
* ? Task.Validation.passed(name)
|
|
1060
|
+
* : Task.Validation.failed("Name is required");
|
|
1061
1061
|
*
|
|
1062
1062
|
* // Accumulate errors from multiple async validations using ap
|
|
1063
1063
|
* pipe(
|
|
1064
|
-
*
|
|
1065
|
-
*
|
|
1066
|
-
*
|
|
1064
|
+
* Task.Validation.passed((name: string) => (age: number) => ({ name, age })),
|
|
1065
|
+
* Task.Validation.ap(validateName("")),
|
|
1066
|
+
* Task.Validation.ap(validateAge(-1))
|
|
1067
1067
|
* )();
|
|
1068
1068
|
* // Failed(["Name is required", "Age must be positive"])
|
|
1069
1069
|
* ```
|
|
@@ -1071,46 +1071,46 @@ declare namespace TaskResult {
|
|
|
1071
1071
|
type TaskValidation<E, A> = Task<Validation<E, A>>;
|
|
1072
1072
|
declare namespace TaskValidation {
|
|
1073
1073
|
/**
|
|
1074
|
-
* Wraps a value in a passed
|
|
1074
|
+
* Wraps a value in a passed Task.Validation.
|
|
1075
1075
|
*/
|
|
1076
1076
|
const passed: <E, A>(value: A) => TaskValidation<E, A>;
|
|
1077
1077
|
/**
|
|
1078
|
-
* Creates a failed
|
|
1078
|
+
* Creates a failed Task.Validation with a single error.
|
|
1079
1079
|
*/
|
|
1080
1080
|
const failed: <E, A>(error: E) => TaskValidation<E, A>;
|
|
1081
1081
|
/**
|
|
1082
|
-
* Creates a failed
|
|
1082
|
+
* Creates a failed Task.Validation from multiple errors.
|
|
1083
1083
|
*/
|
|
1084
1084
|
const failedAll: <E, A>(errors: NonEmptyArr<E>) => TaskValidation<E, A>;
|
|
1085
1085
|
/**
|
|
1086
|
-
* Lifts a Validation into a
|
|
1086
|
+
* Lifts a Validation into a Task.Validation.
|
|
1087
1087
|
*/
|
|
1088
1088
|
const fromValidation: <E, A>(validation: Validation<E, A>) => TaskValidation<E, A>;
|
|
1089
1089
|
/**
|
|
1090
|
-
* Creates a
|
|
1090
|
+
* Creates a Task.Validation from a nullable value.
|
|
1091
1091
|
* If the value is null or undefined, returns Failed with the error from onNull.
|
|
1092
1092
|
* Otherwise, returns Passed.
|
|
1093
1093
|
*/
|
|
1094
1094
|
const fromNullable: <E>(onNull: () => E) => <A>(value: A | null | undefined) => TaskValidation<E, A>;
|
|
1095
1095
|
/**
|
|
1096
|
-
* Creates a
|
|
1096
|
+
* Creates a Task.Validation from a Maybe.
|
|
1097
1097
|
* Some becomes Passed, None becomes Failed with the error from onNone.
|
|
1098
1098
|
*/
|
|
1099
1099
|
const fromMaybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => TaskValidation<E, A>;
|
|
1100
1100
|
/**
|
|
1101
|
-
* Creates a
|
|
1101
|
+
* Creates a Task.Validation from a Result.
|
|
1102
1102
|
* Ok becomes Passed, Err(e) becomes Failed([e]).
|
|
1103
1103
|
*/
|
|
1104
1104
|
const fromResult: <E, A>(result: Result<E, A>) => TaskValidation<E, A>;
|
|
1105
1105
|
/**
|
|
1106
|
-
* Creates a
|
|
1106
|
+
* Creates a Task.Validation from a Promise-returning function.
|
|
1107
1107
|
* Catches any errors and transforms them using the onError function.
|
|
1108
1108
|
* The factory optionally receives an `AbortSignal` forwarded from the call site.
|
|
1109
1109
|
*
|
|
1110
1110
|
* @example
|
|
1111
1111
|
* ```ts
|
|
1112
|
-
* const fetchUser = (id: string):
|
|
1113
|
-
*
|
|
1112
|
+
* const fetchUser = (id: string): Task.Validation<string, User> =>
|
|
1113
|
+
* Task.Validation.tryCatch(
|
|
1114
1114
|
* (signal) => fetch(`/users/${id}`, { signal }).then(r => r.json()),
|
|
1115
1115
|
* e => `Failed to fetch user: ${e}`
|
|
1116
1116
|
* );
|
|
@@ -1118,36 +1118,36 @@ declare namespace TaskValidation {
|
|
|
1118
1118
|
*/
|
|
1119
1119
|
const tryCatch: <E, A>(f: (signal?: AbortSignal) => Thenable<A>, onError: (e: unknown) => E) => TaskValidation<E, A>;
|
|
1120
1120
|
/**
|
|
1121
|
-
* Transforms the success value inside a
|
|
1121
|
+
* Transforms the success value inside a Task.Validation.
|
|
1122
1122
|
*/
|
|
1123
1123
|
const map: <E, A, B>(f: (a: A) => B) => (data: TaskValidation<E, A>) => TaskValidation<E, B>;
|
|
1124
1124
|
/**
|
|
1125
|
-
* Applies a function wrapped in a
|
|
1126
|
-
*
|
|
1125
|
+
* Applies a function wrapped in a Task.Validation to a value wrapped in a
|
|
1126
|
+
* Task.Validation. Both Tasks run in parallel and errors from both sides
|
|
1127
1127
|
* are accumulated.
|
|
1128
1128
|
*
|
|
1129
1129
|
* @example
|
|
1130
1130
|
* ```ts
|
|
1131
1131
|
* pipe(
|
|
1132
|
-
*
|
|
1133
|
-
*
|
|
1134
|
-
*
|
|
1132
|
+
* Task.Validation.passed((name: string) => (age: number) => ({ name, age })),
|
|
1133
|
+
* Task.Validation.ap(validateName(name)),
|
|
1134
|
+
* Task.Validation.ap(validateAge(age))
|
|
1135
1135
|
* )();
|
|
1136
1136
|
* ```
|
|
1137
1137
|
*/
|
|
1138
1138
|
const ap: <E, A>(arg: TaskValidation<E, A>) => <B>(data: TaskValidation<E, (a: A) => B>) => TaskValidation<E, B>;
|
|
1139
1139
|
/**
|
|
1140
|
-
* Extracts a value from a
|
|
1140
|
+
* Extracts a value from a Task.Validation by providing handlers for both cases.
|
|
1141
1141
|
*/
|
|
1142
1142
|
const fold: <E, A, B>(onFailed: (errors: NonEmptyArr<E>) => B, onPassed: (a: A) => B) => (data: TaskValidation<E, A>) => Task<B>;
|
|
1143
1143
|
/**
|
|
1144
|
-
* Pattern matches on a
|
|
1144
|
+
* Pattern matches on a Task.Validation, returning a Task of the result.
|
|
1145
1145
|
*
|
|
1146
1146
|
* @example
|
|
1147
1147
|
* ```ts
|
|
1148
1148
|
* pipe(
|
|
1149
1149
|
* validateForm(input),
|
|
1150
|
-
*
|
|
1150
|
+
* Task.Validation.match({
|
|
1151
1151
|
* passed: data => save(data),
|
|
1152
1152
|
* failed: errors => showErrors(errors)
|
|
1153
1153
|
* })
|
|
@@ -1159,29 +1159,29 @@ declare namespace TaskValidation {
|
|
|
1159
1159
|
failed: (errors: NonEmptyArr<E>) => B;
|
|
1160
1160
|
}) => (data: TaskValidation<E, A>) => Task<B>;
|
|
1161
1161
|
/**
|
|
1162
|
-
* Returns the success value or a default value if the
|
|
1162
|
+
* Returns the success value or a default value if the Task.Validation is failed.
|
|
1163
1163
|
* The default can be a different type, widening the result to `Task<A | B>`.
|
|
1164
1164
|
*/
|
|
1165
1165
|
const getOrElse: <E, A, B>(defaultValue: () => B) => (data: TaskValidation<E, A>) => Task<A | B>;
|
|
1166
1166
|
/**
|
|
1167
|
-
* Executes a side effect on the success value without changing the
|
|
1167
|
+
* Executes a side effect on the success value without changing the Task.Validation.
|
|
1168
1168
|
* Useful for logging or debugging.
|
|
1169
1169
|
*/
|
|
1170
1170
|
const tap: <E, A>(f: (a: A) => void) => (data: TaskValidation<E, A>) => TaskValidation<E, A>;
|
|
1171
1171
|
/**
|
|
1172
|
-
* Recovers from a Failed state by providing a fallback
|
|
1172
|
+
* Recovers from a Failed state by providing a fallback Task.Validation.
|
|
1173
1173
|
* The fallback receives the accumulated error list so callers can inspect which errors occurred.
|
|
1174
|
-
* The fallback can produce a different success type, widening the result to `
|
|
1174
|
+
* The fallback can produce a different success type, widening the result to `Task.Validation<E, A | B>`.
|
|
1175
1175
|
*/
|
|
1176
1176
|
const recover: <E, A, B>(fallback: (errors: NonEmptyArr<E>) => TaskValidation<E, B>) => (data: TaskValidation<E, A>) => TaskValidation<E, A | B>;
|
|
1177
1177
|
/**
|
|
1178
|
-
* Runs two
|
|
1178
|
+
* Runs two Task.Validations concurrently and combines their results into a tuple.
|
|
1179
1179
|
* If both are Passed, returns Passed with both values. If either fails, accumulates
|
|
1180
1180
|
* errors from both sides.
|
|
1181
1181
|
*
|
|
1182
1182
|
* @example
|
|
1183
1183
|
* ```ts
|
|
1184
|
-
* await
|
|
1184
|
+
* await Task.Validation.product(
|
|
1185
1185
|
* validateName(form.name),
|
|
1186
1186
|
* validateAge(form.age),
|
|
1187
1187
|
* )(); // Passed(["Alice", 30]) or Failed([...errors])
|
|
@@ -1189,13 +1189,13 @@ declare namespace TaskValidation {
|
|
|
1189
1189
|
*/
|
|
1190
1190
|
const product: <E, A, B>(first: TaskValidation<E, A>, second: TaskValidation<E, B>) => TaskValidation<E, readonly [A, B]>;
|
|
1191
1191
|
/**
|
|
1192
|
-
* Runs all
|
|
1192
|
+
* Runs all Task.Validations concurrently and collects results.
|
|
1193
1193
|
* If all are Passed, returns Passed with all values as an array.
|
|
1194
1194
|
* If any fail, returns Failed with all accumulated errors.
|
|
1195
1195
|
*
|
|
1196
1196
|
* @example
|
|
1197
1197
|
* ```ts
|
|
1198
|
-
* await
|
|
1198
|
+
* await Task.Validation.productAll([
|
|
1199
1199
|
* validateName(form.name),
|
|
1200
1200
|
* validateEmail(form.email),
|
|
1201
1201
|
* validateAge(form.age),
|
|
@@ -1204,39 +1204,39 @@ declare namespace TaskValidation {
|
|
|
1204
1204
|
*/
|
|
1205
1205
|
const productAll: <E, A>(data: NonEmptyArr<TaskValidation<E, A>>) => TaskValidation<E, readonly A[]>;
|
|
1206
1206
|
/**
|
|
1207
|
-
* Transforms all accumulated errors inside a
|
|
1207
|
+
* Transforms all accumulated errors inside a Task.Validation.
|
|
1208
1208
|
*
|
|
1209
1209
|
* @example
|
|
1210
1210
|
* ```ts
|
|
1211
1211
|
* pipe(
|
|
1212
|
-
*
|
|
1213
|
-
*
|
|
1214
|
-
* ); //
|
|
1212
|
+
* Task.Validation.failed("oops"),
|
|
1213
|
+
* Task.Validation.mapError(e => e.toUpperCase())
|
|
1214
|
+
* ); // Task.Validation(Failed(["OOPS"]))
|
|
1215
1215
|
* ```
|
|
1216
1216
|
*/
|
|
1217
1217
|
const mapError: <E, F, A>(f: (e: E) => F) => (data: TaskValidation<E, A>) => TaskValidation<F, A>;
|
|
1218
1218
|
/**
|
|
1219
|
-
* Executes a side effect on the accumulated errors without changing the
|
|
1219
|
+
* Executes a side effect on the accumulated errors without changing the Task.Validation.
|
|
1220
1220
|
*
|
|
1221
1221
|
* @example
|
|
1222
1222
|
* ```ts
|
|
1223
1223
|
* pipe(
|
|
1224
|
-
*
|
|
1225
|
-
*
|
|
1224
|
+
* Task.Validation.failed("invalid name"),
|
|
1225
|
+
* Task.Validation.tapError(errs => logger.error(errs))
|
|
1226
1226
|
* );
|
|
1227
1227
|
* ```
|
|
1228
1228
|
*/
|
|
1229
1229
|
const tapError: <E, A>(f: (errors: NonEmptyArr<E>) => void) => (data: TaskValidation<E, A>) => TaskValidation<E, A>;
|
|
1230
1230
|
/**
|
|
1231
|
-
* Combines a record of
|
|
1231
|
+
* Combines a record of Task.Validations into a single Task.Validation of a record.
|
|
1232
1232
|
* Evaluates fields in parallel and accumulates all validation errors.
|
|
1233
1233
|
*
|
|
1234
1234
|
* @example
|
|
1235
1235
|
* ```ts
|
|
1236
|
-
*
|
|
1237
|
-
* name:
|
|
1238
|
-
* age:
|
|
1239
|
-
* }); //
|
|
1236
|
+
* Task.Validation.struct({
|
|
1237
|
+
* name: Task.Validation.passed("Alice"),
|
|
1238
|
+
* age: Task.Validation.passed(30)
|
|
1239
|
+
* }); // Task.Validation({ name: "Alice", age: 30 })
|
|
1240
1240
|
* ```
|
|
1241
1241
|
*/
|
|
1242
1242
|
const struct: <E, R extends Record<string, any>>(fields: { [K in keyof R]: TaskValidation<E, R[K]>; }) => TaskValidation<E, R>;
|
|
@@ -1248,7 +1248,7 @@ declare namespace TaskValidation {
|
|
|
1248
1248
|
* Two guarantees:
|
|
1249
1249
|
* - **Lazy** — nothing starts until you call it.
|
|
1250
1250
|
* - **Infallible** — it never rejects. If failure is possible, encode it in the
|
|
1251
|
-
* return type using `
|
|
1251
|
+
* return type using `Task.Result<E, A>` instead.
|
|
1252
1252
|
*
|
|
1253
1253
|
* An optional `AbortSignal` can be passed at the call site. Combinators like
|
|
1254
1254
|
* `retry`, `pollUntil`, and `timeout` thread it automatically to every inner
|
|
@@ -1485,7 +1485,7 @@ declare namespace Task {
|
|
|
1485
1485
|
* pipe(
|
|
1486
1486
|
* heavyComputation,
|
|
1487
1487
|
* Task.timeout(Duration.seconds(5), () => "timed out"),
|
|
1488
|
-
*
|
|
1488
|
+
* Task.Result.chain(processResult)
|
|
1489
1489
|
* );
|
|
1490
1490
|
* ```
|
|
1491
1491
|
*/
|
|
@@ -1883,4 +1883,4 @@ declare namespace Validation {
|
|
|
1883
1883
|
const struct: <E, R extends Record<string, any>>(fields: { [K in keyof R]: Validation<E, R[K]>; }) => Validation<E, R>;
|
|
1884
1884
|
}
|
|
1885
1885
|
|
|
1886
|
-
export { Equality as E, type Failed as F, Maybe as M, type None as N, type Ok as O, type Passed as P, Result as R, type Some as S, Task as T, Validation as V, type Err as a, Ordering as b };
|
|
1886
|
+
export { Equality as E, type Failed as F, Maybe as M, type None as N, type Ok as O, type Passed as P, Result as R, type Some as S, Task as T, Validation as V, type Err as a, Ordering as b, TaskMaybe as c, TaskResult as d, TaskValidation as e };
|