@nlozgachev/pipelined 0.33.0 → 0.35.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 +75 -40
- package/dist/{Task-5na0QzS4.d.mts → Task-DXsuurnc.d.mts} +54 -55
- package/dist/{Task-DeiWgoeJ.d.ts → Task-zAY4kSVB.d.ts} +54 -55
- package/dist/{chunk-FZX4MTRI.mjs → chunk-5AWUAG7G.mjs} +445 -308
- package/dist/{chunk-NRF2FVPZ.mjs → chunk-AHEZFTMT.mjs} +64 -32
- package/dist/{chunk-GSTKY7MF.mjs → chunk-DLBHVYII.mjs} +69 -52
- package/dist/{chunk-W53ZYTLX.mjs → chunk-IJFFWBKW.mjs} +184 -64
- package/dist/composition.d.mts +8 -7
- package/dist/composition.d.ts +8 -7
- package/dist/composition.js +64 -32
- package/dist/composition.mjs +1 -1
- package/dist/core.d.mts +172 -163
- package/dist/core.d.ts +172 -163
- package/dist/core.js +535 -384
- package/dist/core.mjs +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +783 -480
- package/dist/index.mjs +4 -4
- package/dist/utils.d.mts +8 -7
- package/dist/utils.d.ts +8 -7
- package/dist/utils.js +252 -115
- package/dist/utils.mjs +2 -2
- package/package.json +9 -9
package/dist/core.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { M as Maybe, W as WithValue, c as WithLog, D as Deferred, R as Result, d as WithKind, e as WithError, f as RetryOptions, g as TimeoutOptions, h as WithTimeout, i as WithMinInterval, j as WithCooldown, k as WithConcurrency, l as WithSize, m as
|
|
2
|
-
export { E as Equality, a as
|
|
3
|
-
import { NonEmptyList } from './types.js';
|
|
1
|
+
import { M as Maybe, W as WithValue, c as WithLog, D as Deferred, R as Result, d as WithKind, e as WithError, f as RetryOptions, g as TimeoutOptions, h as WithTimeout, i as WithMinInterval, j as WithCooldown, k as WithConcurrency, l as WithSize, m as WithDuration, n as WithN, T as Task, o as WithErrors, p as WithFirst, q as WithSecond } from './Task-zAY4kSVB.js';
|
|
2
|
+
export { E as Equality, a as Err, N as None, O as Ok, b as Ordering, S as Some } from './Task-zAY4kSVB.js';
|
|
3
|
+
import { Duration, NonEmptyList } from './types.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* A type that can combine two values of type `A` into one, with a neutral starting value.
|
|
@@ -588,12 +588,12 @@ type AllInterpretOptions<I, E> = ({
|
|
|
588
588
|
strategy: "debounced";
|
|
589
589
|
retry?: RetryOptions<E>;
|
|
590
590
|
leading?: true;
|
|
591
|
-
maxWait?:
|
|
592
|
-
} &
|
|
591
|
+
maxWait?: Duration;
|
|
592
|
+
} & WithDuration & WithTimeout<E>) | ({
|
|
593
593
|
strategy: "throttled";
|
|
594
594
|
retry?: RetryOptions<E>;
|
|
595
595
|
trailing?: true;
|
|
596
|
-
} &
|
|
596
|
+
} & WithDuration & WithTimeout<E>) | ({
|
|
597
597
|
strategy: "concurrent";
|
|
598
598
|
retry?: RetryOptions<E>;
|
|
599
599
|
overflow?: "queue" | "drop";
|
|
@@ -671,7 +671,7 @@ type InterpretResult<I, E, A, O> = [O] extends [{
|
|
|
671
671
|
* manager.subscribe(state => {
|
|
672
672
|
* if (Op.isPending(state)) showSpinner();
|
|
673
673
|
* if (Op.isOk(state)) render(state.value);
|
|
674
|
-
* if (Op.
|
|
674
|
+
* if (Op.isErr(state)) showError(state.error);
|
|
675
675
|
* if (Op.isNil(state)) resetUI();
|
|
676
676
|
* });
|
|
677
677
|
* manager.run(userId);
|
|
@@ -696,11 +696,11 @@ declare namespace Op {
|
|
|
696
696
|
* over a call that was already running; `"evicted"` — a newer `run()` took over
|
|
697
697
|
* a call that was waiting and had not yet started.
|
|
698
698
|
*/
|
|
699
|
-
type Outcome<E, A> = Ok<A> |
|
|
699
|
+
type Outcome<E, A> = Ok<A> | Err<E> | Nil;
|
|
700
700
|
/** A successful outcome with a value. */
|
|
701
701
|
type Ok<A> = WithKind<"OpOk"> & WithValue<A>;
|
|
702
702
|
/** A failed outcome with a typed error. */
|
|
703
|
-
type
|
|
703
|
+
type Err<E> = WithKind<"OpErr"> & WithError<E>;
|
|
704
704
|
/**
|
|
705
705
|
* An outcome that produced nothing. `reason` identifies why:
|
|
706
706
|
* - `"aborted"` — `abort()` was called explicitly.
|
|
@@ -759,7 +759,7 @@ declare namespace Op {
|
|
|
759
759
|
* manager.subscribe(state => {
|
|
760
760
|
* if (Op.isPending(state)) lockForm();
|
|
761
761
|
* if (Op.isOk(state)) toast("Saved");
|
|
762
|
-
* if (Op.
|
|
762
|
+
* if (Op.isErr(state)) toast(`Error: ${state.error.message}`);
|
|
763
763
|
* });
|
|
764
764
|
*
|
|
765
765
|
* // Fire and subscribe (subscriber pattern)
|
|
@@ -797,7 +797,7 @@ declare namespace Op {
|
|
|
797
797
|
* Returns a stop handle — call it to cancel future runs.
|
|
798
798
|
*/
|
|
799
799
|
poll: (input: I, options: {
|
|
800
|
-
interval:
|
|
800
|
+
interval: Duration;
|
|
801
801
|
}) => () => void;
|
|
802
802
|
};
|
|
803
803
|
/**
|
|
@@ -848,65 +848,65 @@ declare namespace Op {
|
|
|
848
848
|
* Returns a stop handle — call it to cancel future runs.
|
|
849
849
|
*/
|
|
850
850
|
poll: (input: I, options: {
|
|
851
|
-
interval:
|
|
851
|
+
interval: Duration;
|
|
852
852
|
}) => () => void;
|
|
853
853
|
};
|
|
854
854
|
/** States reachable by a `once` manager (no retry). */
|
|
855
|
-
type OnceState<E, A> = Idle | Pending | Ok<A> |
|
|
855
|
+
type OnceState<E, A> = Idle | Pending | Ok<A> | Err<E> | AbortedNil | DroppedNil;
|
|
856
856
|
/** States reachable by a `once` manager with retry configured. */
|
|
857
|
-
type RetryableOnceState<E, A> = Idle | Pending | Retrying<E> | Ok<A> |
|
|
857
|
+
type RetryableOnceState<E, A> = Idle | Pending | Retrying<E> | Ok<A> | Err<E> | AbortedNil | DroppedNil;
|
|
858
858
|
/** States reachable by a `restartable` manager (no retry). */
|
|
859
|
-
type RestartableState<E, A> = Idle | Pending | Ok<A> |
|
|
859
|
+
type RestartableState<E, A> = Idle | Pending | Ok<A> | Err<E> | AbortedNil | ReplacedNil;
|
|
860
860
|
/** States reachable by a `restartable` manager with retry configured. */
|
|
861
|
-
type RetryableRestartableState<E, A> = Idle | Pending | Retrying<E> | Ok<A> |
|
|
861
|
+
type RetryableRestartableState<E, A> = Idle | Pending | Retrying<E> | Ok<A> | Err<E> | AbortedNil | ReplacedNil;
|
|
862
862
|
/** States reachable by an `exclusive` manager (no retry). */
|
|
863
|
-
type ExclusiveState<E, A> = Idle | Pending | Ok<A> |
|
|
863
|
+
type ExclusiveState<E, A> = Idle | Pending | Ok<A> | Err<E> | AbortedNil | DroppedNil;
|
|
864
864
|
/** States reachable by an `exclusive` manager with retry configured. */
|
|
865
|
-
type RetryableExclusiveState<E, A> = Idle | Pending | Retrying<E> | Ok<A> |
|
|
865
|
+
type RetryableExclusiveState<E, A> = Idle | Pending | Retrying<E> | Ok<A> | Err<E> | AbortedNil | DroppedNil;
|
|
866
866
|
/** States reachable by a `queue` manager (no retry, no overflow, no dedupe). */
|
|
867
|
-
type QueueState<E, A> = Idle | Pending | Queued | Ok<A> |
|
|
867
|
+
type QueueState<E, A> = Idle | Pending | Queued | Ok<A> | Err<E> | AbortedNil;
|
|
868
868
|
/** States reachable by a `queue` manager with retry (no overflow, no dedupe). */
|
|
869
|
-
type RetryableQueueState<E, A> = Idle | Pending | Queued | Retrying<E> | Ok<A> |
|
|
869
|
+
type RetryableQueueState<E, A> = Idle | Pending | Queued | Retrying<E> | Ok<A> | Err<E> | AbortedNil;
|
|
870
870
|
/** States reachable by a `queue` manager with `overflow:"drop"` or `dedupe` (no retry). */
|
|
871
|
-
type QueueDropState<E, A> = Idle | Pending | Queued | Ok<A> |
|
|
871
|
+
type QueueDropState<E, A> = Idle | Pending | Queued | Ok<A> | Err<E> | AbortedNil | DroppedNil;
|
|
872
872
|
/** States reachable by a `queue` manager with `overflow:"drop"` or `dedupe`, with retry. */
|
|
873
|
-
type RetryableQueueDropState<E, A> = Idle | Pending | Queued | Retrying<E> | Ok<A> |
|
|
873
|
+
type RetryableQueueDropState<E, A> = Idle | Pending | Queued | Retrying<E> | Ok<A> | Err<E> | AbortedNil | DroppedNil;
|
|
874
874
|
/** States reachable by a `queue` manager with `overflow:"replace-last"` and no `dedupe` (no retry). */
|
|
875
|
-
type QueueReplaceState<E, A> = Idle | Pending | Queued | Ok<A> |
|
|
875
|
+
type QueueReplaceState<E, A> = Idle | Pending | Queued | Ok<A> | Err<E> | AbortedNil | EvictedNil;
|
|
876
876
|
/** States reachable by a `queue` manager with `overflow:"replace-last"` and no `dedupe`, with retry. */
|
|
877
|
-
type RetryableQueueReplaceState<E, A> = Idle | Pending | Queued | Retrying<E> | Ok<A> |
|
|
877
|
+
type RetryableQueueReplaceState<E, A> = Idle | Pending | Queued | Retrying<E> | Ok<A> | Err<E> | AbortedNil | EvictedNil;
|
|
878
878
|
/** States reachable by a `queue` manager with `overflow:"replace-last"` AND `dedupe` (no retry). */
|
|
879
|
-
type QueueDropAndReplaceState<E, A> = Idle | Pending | Queued | Ok<A> |
|
|
879
|
+
type QueueDropAndReplaceState<E, A> = Idle | Pending | Queued | Ok<A> | Err<E> | AbortedNil | DroppedNil | EvictedNil;
|
|
880
880
|
/** States reachable by a `queue` manager with `overflow:"replace-last"` AND `dedupe`, with retry. */
|
|
881
|
-
type RetryableQueueDropAndReplaceState<E, A> = Idle | Pending | Queued | Retrying<E> | Ok<A> |
|
|
881
|
+
type RetryableQueueDropAndReplaceState<E, A> = Idle | Pending | Queued | Retrying<E> | Ok<A> | Err<E> | AbortedNil | DroppedNil | EvictedNil;
|
|
882
882
|
/** States reachable by a `buffered` manager (no retry). */
|
|
883
|
-
type BufferedState<E, A> = Idle | Pending | Queued | Ok<A> |
|
|
883
|
+
type BufferedState<E, A> = Idle | Pending | Queued | Ok<A> | Err<E> | AbortedNil | EvictedNil;
|
|
884
884
|
/** States reachable by a `buffered` manager with retry configured. */
|
|
885
|
-
type RetryableBufferedState<E, A> = Idle | Pending | Queued | Retrying<E> | Ok<A> |
|
|
885
|
+
type RetryableBufferedState<E, A> = Idle | Pending | Queued | Retrying<E> | Ok<A> | Err<E> | AbortedNil | EvictedNil;
|
|
886
886
|
/** States reachable by a `debounced` manager (no retry). */
|
|
887
|
-
type DebouncedState<E, A> = Idle | Pending | Ok<A> |
|
|
887
|
+
type DebouncedState<E, A> = Idle | Pending | Ok<A> | Err<E> | AbortedNil | EvictedNil;
|
|
888
888
|
/** States reachable by a `debounced` manager with retry configured. */
|
|
889
|
-
type RetryableDebouncedState<E, A> = Idle | Pending | Retrying<E> | Ok<A> |
|
|
889
|
+
type RetryableDebouncedState<E, A> = Idle | Pending | Retrying<E> | Ok<A> | Err<E> | AbortedNil | EvictedNil;
|
|
890
890
|
/** States reachable by a `throttled` manager (leading-only, no retry). */
|
|
891
|
-
type ThrottledState<E, A> = Idle | Pending | Ok<A> |
|
|
891
|
+
type ThrottledState<E, A> = Idle | Pending | Ok<A> | Err<E> | AbortedNil | DroppedNil;
|
|
892
892
|
/** States reachable by a `throttled` manager (leading-only, with retry). */
|
|
893
|
-
type RetryableThrottledState<E, A> = Idle | Pending | Retrying<E> | Ok<A> |
|
|
893
|
+
type RetryableThrottledState<E, A> = Idle | Pending | Retrying<E> | Ok<A> | Err<E> | AbortedNil | DroppedNil;
|
|
894
894
|
/** States reachable by a `throttled` manager with `trailing: true` (no retry). */
|
|
895
|
-
type ThrottledTrailingState<E, A> = Idle | Pending | Ok<A> |
|
|
895
|
+
type ThrottledTrailingState<E, A> = Idle | Pending | Ok<A> | Err<E> | AbortedNil | EvictedNil;
|
|
896
896
|
/** States reachable by a `throttled` manager with `trailing: true` and retry. */
|
|
897
|
-
type RetryableThrottledTrailingState<E, A> = Idle | Pending | Retrying<E> | Ok<A> |
|
|
897
|
+
type RetryableThrottledTrailingState<E, A> = Idle | Pending | Retrying<E> | Ok<A> | Err<E> | AbortedNil | EvictedNil;
|
|
898
898
|
/** States reachable by a `concurrent` manager with `overflow: "queue"` (no retry). */
|
|
899
|
-
type ConcurrentQueueState<E, A> = Idle | Pending | Queued | Ok<A> |
|
|
899
|
+
type ConcurrentQueueState<E, A> = Idle | Pending | Queued | Ok<A> | Err<E> | AbortedNil;
|
|
900
900
|
/** States reachable by a `concurrent` manager with `overflow: "queue"` and retry. */
|
|
901
|
-
type RetryableConcurrentQueueState<E, A> = Idle | Pending | Queued | Retrying<E> | Ok<A> |
|
|
901
|
+
type RetryableConcurrentQueueState<E, A> = Idle | Pending | Queued | Retrying<E> | Ok<A> | Err<E> | AbortedNil;
|
|
902
902
|
/** States reachable by a `concurrent` manager with `overflow: "drop"` (no retry). */
|
|
903
|
-
type ConcurrentDropState<E, A> = Idle | Pending | Ok<A> |
|
|
903
|
+
type ConcurrentDropState<E, A> = Idle | Pending | Ok<A> | Err<E> | AbortedNil | DroppedNil;
|
|
904
904
|
/** States reachable by a `concurrent` manager with `overflow: "drop"` and retry. */
|
|
905
|
-
type RetryableConcurrentDropState<E, A> = Idle | Pending | Retrying<E> | Ok<A> |
|
|
905
|
+
type RetryableConcurrentDropState<E, A> = Idle | Pending | Retrying<E> | Ok<A> | Err<E> | AbortedNil | DroppedNil;
|
|
906
906
|
/** Per-key state union for a `keyed` manager with `perKey: "exclusive"`. */
|
|
907
|
-
type KeyedExclusivePerKey<E, A> = Pending | Ok<A> |
|
|
907
|
+
type KeyedExclusivePerKey<E, A> = Pending | Ok<A> | Err<E> | AbortedNil | DroppedNil;
|
|
908
908
|
/** Per-key state union for a `keyed` manager with `perKey: "restartable"`. */
|
|
909
|
-
type KeyedRestartablePerKey<E, A> = Pending | Ok<A> |
|
|
909
|
+
type KeyedRestartablePerKey<E, A> = Pending | Ok<A> | Err<E> | AbortedNil | ReplacedNil;
|
|
910
910
|
type RetryOptions<E> = RetryOptions<E>;
|
|
911
911
|
type TimeoutOptions<E> = TimeoutOptions<E>;
|
|
912
912
|
/**
|
|
@@ -991,10 +991,10 @@ declare namespace Op {
|
|
|
991
991
|
*
|
|
992
992
|
* @example
|
|
993
993
|
* ```ts
|
|
994
|
-
* Op.
|
|
994
|
+
* Op.err(new ApiError("not found")); // { kind: "OpErr", error: ApiError }
|
|
995
995
|
* ```
|
|
996
996
|
*/
|
|
997
|
-
const
|
|
997
|
+
const err: <E>(error: E) => Err<E>;
|
|
998
998
|
/**
|
|
999
999
|
* Returns `true` if the state is `Idle`.
|
|
1000
1000
|
*
|
|
@@ -1051,16 +1051,16 @@ declare namespace Op {
|
|
|
1051
1051
|
*/
|
|
1052
1052
|
const isOk: <E, A>(state: State<E, A>) => state is Ok<A>;
|
|
1053
1053
|
/**
|
|
1054
|
-
* Returns `true` if the state is `
|
|
1054
|
+
* Returns `true` if the state is `Err` (the operation failed with a typed error).
|
|
1055
1055
|
*
|
|
1056
1056
|
* @example
|
|
1057
1057
|
* ```ts
|
|
1058
1058
|
* manager.subscribe(state => {
|
|
1059
|
-
* if (Op.
|
|
1059
|
+
* if (Op.isErr(state)) showError(state.error);
|
|
1060
1060
|
* });
|
|
1061
1061
|
* ```
|
|
1062
1062
|
*/
|
|
1063
|
-
const
|
|
1063
|
+
const isErr: <E, A>(state: State<E, A>) => state is Err<E>;
|
|
1064
1064
|
/**
|
|
1065
1065
|
* Returns `true` if the state is `Nil` (the operation completed without a value or error).
|
|
1066
1066
|
*
|
|
@@ -1079,19 +1079,19 @@ declare namespace Op {
|
|
|
1079
1079
|
* ```ts
|
|
1080
1080
|
* Op.match({
|
|
1081
1081
|
* ok: (user) => render(user),
|
|
1082
|
-
*
|
|
1082
|
+
* err: (e) => showError(e.message),
|
|
1083
1083
|
* nil: () => resetUI(),
|
|
1084
1084
|
* })(outcome);
|
|
1085
1085
|
* ```
|
|
1086
1086
|
*/
|
|
1087
1087
|
const match: <E, A, B>(cases: {
|
|
1088
1088
|
ok: (a: A) => B;
|
|
1089
|
-
|
|
1089
|
+
err: (e: E) => B;
|
|
1090
1090
|
nil: () => B;
|
|
1091
1091
|
}) => (outcome: Outcome<E, A>) => B;
|
|
1092
1092
|
/**
|
|
1093
1093
|
* Eliminates an Outcome with positional handlers.
|
|
1094
|
-
* Order: `
|
|
1094
|
+
* Order: `onErr`, `onOk`, `onNil` — mirrors `Result.fold` for the first two.
|
|
1095
1095
|
*
|
|
1096
1096
|
* @example
|
|
1097
1097
|
* ```ts
|
|
@@ -1102,7 +1102,7 @@ declare namespace Op {
|
|
|
1102
1102
|
* )(outcome);
|
|
1103
1103
|
* ```
|
|
1104
1104
|
*/
|
|
1105
|
-
const fold: <E, A, B>(
|
|
1105
|
+
const fold: <E, A, B>(onErr: (e: E) => B, onOk: (a: A) => B, onNil: () => B) => (outcome: Outcome<E, A>) => B;
|
|
1106
1106
|
/**
|
|
1107
1107
|
* Returns the success value, or the result of `defaultValue()` for `Err` or `Nil`.
|
|
1108
1108
|
*
|
|
@@ -1137,7 +1137,7 @@ declare namespace Op {
|
|
|
1137
1137
|
* ```ts
|
|
1138
1138
|
* pipe(
|
|
1139
1139
|
* outcome,
|
|
1140
|
-
* Op.chain(user => user.active ? Op.ok(user) : Op.
|
|
1140
|
+
* Op.chain(user => user.active ? Op.ok(user) : Op.err(new Error("inactive"))),
|
|
1141
1141
|
* );
|
|
1142
1142
|
* ```
|
|
1143
1143
|
*/
|
|
@@ -1158,7 +1158,7 @@ declare namespace Op {
|
|
|
1158
1158
|
* ```ts
|
|
1159
1159
|
* pipe(
|
|
1160
1160
|
* outcome,
|
|
1161
|
-
* Op.recover(e => e.isRetryable ? Op.ok(cachedValue) : Op.
|
|
1161
|
+
* Op.recover(e => e.isRetryable ? Op.ok(cachedValue) : Op.err(e)),
|
|
1162
1162
|
* );
|
|
1163
1163
|
* ```
|
|
1164
1164
|
*/
|
|
@@ -1369,7 +1369,7 @@ declare namespace Refinement {
|
|
|
1369
1369
|
* Converts a `Refinement<A, B>` into a function `(a: A) => Maybe<B>`.
|
|
1370
1370
|
*
|
|
1371
1371
|
* Returns `Some(a)` when the refinement holds, `None` otherwise. Useful for
|
|
1372
|
-
* integrating runtime validation into
|
|
1372
|
+
* integrating runtime validation into a `Maybe`-based pipeline.
|
|
1373
1373
|
*
|
|
1374
1374
|
* @example
|
|
1375
1375
|
* ```ts
|
|
@@ -1905,7 +1905,7 @@ declare namespace RemoteData {
|
|
|
1905
1905
|
*/
|
|
1906
1906
|
const recover: <E, A, B>(fallback: (e: E) => RemoteData<E, B>) => (data: RemoteData<E, A>) => RemoteData<E, A | B>;
|
|
1907
1907
|
/**
|
|
1908
|
-
* Converts a RemoteData to
|
|
1908
|
+
* Converts a RemoteData to a Maybe.
|
|
1909
1909
|
* Success becomes Some, all other states become None.
|
|
1910
1910
|
*/
|
|
1911
1911
|
const toMaybe: <E, A>(data: RemoteData<E, A>) => Maybe<A>;
|
|
@@ -1986,12 +1986,12 @@ declare namespace TaskResult {
|
|
|
1986
1986
|
const err: <E, A>(error: E) => TaskResult<E, A>;
|
|
1987
1987
|
/**
|
|
1988
1988
|
* Creates a TaskResult from a nullable value.
|
|
1989
|
-
* Returns Ok if the value is not null or undefined,
|
|
1989
|
+
* Returns Ok if the value is not null or undefined, err from onNull otherwise.
|
|
1990
1990
|
*/
|
|
1991
1991
|
const fromNullable: <E>(onNull: () => E) => <A>(value: A | null | undefined) => TaskResult<E, A>;
|
|
1992
1992
|
/**
|
|
1993
1993
|
* Creates a TaskResult from a Maybe.
|
|
1994
|
-
* Some becomes Ok, None becomes
|
|
1994
|
+
* Some becomes Ok, None becomes err from onNone.
|
|
1995
1995
|
*/
|
|
1996
1996
|
const fromMaybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => TaskResult<E, A>;
|
|
1997
1997
|
/**
|
|
@@ -2510,11 +2510,11 @@ declare namespace TaskMaybe {
|
|
|
2510
2510
|
const toTaskResult: <E>(onNone: () => E) => <A>(data: TaskMaybe<A>) => TaskResult<E, A>;
|
|
2511
2511
|
}
|
|
2512
2512
|
|
|
2513
|
-
type
|
|
2514
|
-
type
|
|
2513
|
+
type Passed<A> = WithKind<"Passed"> & WithValue<A>;
|
|
2514
|
+
type Failed<E> = WithKind<"Failed"> & WithErrors<E>;
|
|
2515
2515
|
/**
|
|
2516
|
-
* Validation represents a value that is either
|
|
2517
|
-
* or
|
|
2516
|
+
* Validation represents a value that is either passed with a success value,
|
|
2517
|
+
* or failed with accumulated errors.
|
|
2518
2518
|
* Unlike Result, Validation can accumulate multiple errors instead of short-circuiting.
|
|
2519
2519
|
*
|
|
2520
2520
|
* Use Validation when you need to collect all errors (e.g., form validation).
|
|
@@ -2523,60 +2523,60 @@ type Invalid<E> = WithKind<"Invalid"> & WithErrors<E>;
|
|
|
2523
2523
|
* @example
|
|
2524
2524
|
* ```ts
|
|
2525
2525
|
* const validateName = (name: string): Validation<string, string> =>
|
|
2526
|
-
* name.length > 0 ? Validation.
|
|
2526
|
+
* name.length > 0 ? Validation.passed(name) : Validation.failed("Name is required");
|
|
2527
2527
|
*
|
|
2528
2528
|
* const validateAge = (age: number): Validation<string, number> =>
|
|
2529
|
-
* age >= 0 ? Validation.
|
|
2529
|
+
* age >= 0 ? Validation.passed(age) : Validation.failed("Age must be positive");
|
|
2530
2530
|
*
|
|
2531
2531
|
* // Accumulates all errors using ap
|
|
2532
2532
|
* pipe(
|
|
2533
|
-
* Validation.
|
|
2533
|
+
* Validation.passed((name: string) => (age: number) => ({ name, age })),
|
|
2534
2534
|
* Validation.ap(validateName("")),
|
|
2535
2535
|
* Validation.ap(validateAge(-1))
|
|
2536
2536
|
* );
|
|
2537
|
-
* //
|
|
2537
|
+
* // Failed(["Name is required", "Age must be positive"])
|
|
2538
2538
|
* ```
|
|
2539
2539
|
*/
|
|
2540
|
-
type Validation<E, A> =
|
|
2540
|
+
type Validation<E, A> = Passed<A> | Failed<E>;
|
|
2541
2541
|
declare namespace Validation {
|
|
2542
2542
|
/**
|
|
2543
|
-
* Wraps a value in a
|
|
2543
|
+
* Wraps a value in a passed Validation.
|
|
2544
2544
|
*
|
|
2545
2545
|
* @example
|
|
2546
2546
|
* ```ts
|
|
2547
|
-
* Validation.
|
|
2547
|
+
* Validation.passed(42); // Passed(42)
|
|
2548
2548
|
* ```
|
|
2549
2549
|
*/
|
|
2550
|
-
const
|
|
2550
|
+
const passed: <E, A>(value: A) => Validation<E, A>;
|
|
2551
2551
|
/**
|
|
2552
|
-
* Creates
|
|
2552
|
+
* Creates a failed Validation from a single error.
|
|
2553
2553
|
*
|
|
2554
2554
|
* @example
|
|
2555
2555
|
* ```ts
|
|
2556
|
-
* Validation.
|
|
2556
|
+
* Validation.failed("Invalid input");
|
|
2557
2557
|
* ```
|
|
2558
2558
|
*/
|
|
2559
|
-
const
|
|
2559
|
+
const failed: <E>(error: E) => Failed<E>;
|
|
2560
2560
|
/**
|
|
2561
|
-
* Creates
|
|
2561
|
+
* Creates a failed Validation from multiple errors.
|
|
2562
2562
|
*
|
|
2563
2563
|
* @example
|
|
2564
2564
|
* ```ts
|
|
2565
|
-
* Validation.
|
|
2565
|
+
* Validation.failedAll(["Invalid input"]);
|
|
2566
2566
|
* ```
|
|
2567
2567
|
*/
|
|
2568
|
-
const
|
|
2568
|
+
const failedAll: <E>(errors: NonEmptyList<E>) => Failed<E>;
|
|
2569
2569
|
/**
|
|
2570
|
-
* Type guard that checks if a Validation is
|
|
2570
|
+
* Type guard that checks if a Validation is passed.
|
|
2571
2571
|
*/
|
|
2572
|
-
const
|
|
2572
|
+
const isPassed: <E, A>(data: Validation<E, A>) => data is Passed<A>;
|
|
2573
2573
|
/**
|
|
2574
|
-
* Type guard that checks if a Validation is
|
|
2574
|
+
* Type guard that checks if a Validation is failed.
|
|
2575
2575
|
*/
|
|
2576
|
-
const
|
|
2576
|
+
const isFailed: <E, A>(data: Validation<E, A>) => data is Failed<E>;
|
|
2577
2577
|
/**
|
|
2578
2578
|
* Creates a Validation from a predicate applied to a value.
|
|
2579
|
-
* Returns
|
|
2579
|
+
* Returns Passed if the predicate passes, Failed from `onFalse` otherwise.
|
|
2580
2580
|
*
|
|
2581
2581
|
* @example
|
|
2582
2582
|
* ```ts
|
|
@@ -2585,32 +2585,32 @@ declare namespace Validation {
|
|
|
2585
2585
|
* () => "Name is required"
|
|
2586
2586
|
* );
|
|
2587
2587
|
*
|
|
2588
|
-
* validateName("Alice"); //
|
|
2589
|
-
* validateName(""); //
|
|
2588
|
+
* validateName("Alice"); // Passed("Alice")
|
|
2589
|
+
* validateName(""); // Failed(["Name is required"])
|
|
2590
2590
|
* ```
|
|
2591
2591
|
*/
|
|
2592
2592
|
const fromPredicate: <E, A>(pred: (a: A) => boolean, onFalse: (a: A) => E) => (a: A) => Validation<E, A>;
|
|
2593
2593
|
/**
|
|
2594
2594
|
* Creates a Validation from a nullable value.
|
|
2595
|
-
* If the value is null or undefined, returns
|
|
2596
|
-
* Otherwise, returns
|
|
2595
|
+
* If the value is null or undefined, returns Failed with the error from onNull.
|
|
2596
|
+
* Otherwise, returns Passed.
|
|
2597
2597
|
*
|
|
2598
2598
|
* @example
|
|
2599
2599
|
* ```ts
|
|
2600
|
-
* pipe(null, Validation.fromNullable(() => "is null")); //
|
|
2601
|
-
* pipe(42, Validation.fromNullable(() => "is null")); //
|
|
2600
|
+
* pipe(null, Validation.fromNullable(() => "is null")); // Failed(["is null"])
|
|
2601
|
+
* pipe(42, Validation.fromNullable(() => "is null")); // Passed(42)
|
|
2602
2602
|
* ```
|
|
2603
2603
|
*/
|
|
2604
2604
|
const fromNullable: <E>(onNull: () => E) => <A>(value: A | null | undefined) => Validation<E, A>;
|
|
2605
2605
|
/**
|
|
2606
2606
|
* Creates a Validation from a Maybe.
|
|
2607
|
-
* If the Maybe is None, returns
|
|
2608
|
-
* Otherwise, returns
|
|
2607
|
+
* If the Maybe is None, returns Failed with the error from onNone.
|
|
2608
|
+
* Otherwise, returns Passed.
|
|
2609
2609
|
*
|
|
2610
2610
|
* @example
|
|
2611
2611
|
* ```ts
|
|
2612
|
-
* pipe(Maybe.none(), Validation.fromMaybe(() => "is none")); //
|
|
2613
|
-
* pipe(Maybe.some(42), Validation.fromMaybe(() => "is none")); //
|
|
2612
|
+
* pipe(Maybe.none(), Validation.fromMaybe(() => "is none")); // Failed(["is none"])
|
|
2613
|
+
* pipe(Maybe.some(42), Validation.fromMaybe(() => "is none")); // Passed(42)
|
|
2614
2614
|
* ```
|
|
2615
2615
|
*/
|
|
2616
2616
|
const fromMaybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => Validation<E, A>;
|
|
@@ -2619,11 +2619,20 @@ declare namespace Validation {
|
|
|
2619
2619
|
*
|
|
2620
2620
|
* @example
|
|
2621
2621
|
* ```ts
|
|
2622
|
-
* pipe(Validation.
|
|
2623
|
-
* pipe(Validation.
|
|
2622
|
+
* pipe(Validation.passed(5), Validation.map(n => n * 2)); // Passed(10)
|
|
2623
|
+
* pipe(Validation.failed("oops"), Validation.map(n => n * 2)); // Failed(["oops"])
|
|
2624
2624
|
* ```
|
|
2625
2625
|
*/
|
|
2626
2626
|
const map: <A, B>(f: (a: A) => B) => <E>(data: Validation<E, A>) => Validation<E, B>;
|
|
2627
|
+
/**
|
|
2628
|
+
* Transforms the error list inside a Validation.
|
|
2629
|
+
*
|
|
2630
|
+
* @example
|
|
2631
|
+
* ```ts
|
|
2632
|
+
* pipe(Validation.failed("oops"), Validation.mapError(e => e.toUpperCase())); // Failed(["OOPS"])
|
|
2633
|
+
* ```
|
|
2634
|
+
*/
|
|
2635
|
+
const mapError: <E, F, A>(f: (e: E) => F) => (data: Validation<E, A>) => Validation<F, A>;
|
|
2627
2636
|
/**
|
|
2628
2637
|
* Applies a function wrapped in a Validation to a value wrapped in a Validation.
|
|
2629
2638
|
* Accumulates errors from both sides.
|
|
@@ -2632,16 +2641,16 @@ declare namespace Validation {
|
|
|
2632
2641
|
* ```ts
|
|
2633
2642
|
* const add = (a: number) => (b: number) => a + b;
|
|
2634
2643
|
* pipe(
|
|
2635
|
-
* Validation.
|
|
2636
|
-
* Validation.ap(Validation.
|
|
2637
|
-
* Validation.ap(Validation.
|
|
2638
|
-
* ); //
|
|
2644
|
+
* Validation.passed(add),
|
|
2645
|
+
* Validation.ap(Validation.passed(5)),
|
|
2646
|
+
* Validation.ap(Validation.passed(3))
|
|
2647
|
+
* ); // Passed(8)
|
|
2639
2648
|
*
|
|
2640
2649
|
* pipe(
|
|
2641
|
-
* Validation.
|
|
2642
|
-
* Validation.ap(Validation.
|
|
2643
|
-
* Validation.ap(Validation.
|
|
2644
|
-
* ); //
|
|
2650
|
+
* Validation.passed(add),
|
|
2651
|
+
* Validation.ap(Validation.failed<string, number>("bad a")),
|
|
2652
|
+
* Validation.ap(Validation.failed<string, number>("bad b"))
|
|
2653
|
+
* ); // Failed(["bad a", "bad b"])
|
|
2645
2654
|
* ```
|
|
2646
2655
|
*/
|
|
2647
2656
|
const ap: <E, A>(arg: Validation<E, A>) => <B>(data: Validation<E, (a: A) => B>) => Validation<E, B>;
|
|
@@ -2651,7 +2660,7 @@ declare namespace Validation {
|
|
|
2651
2660
|
* @example
|
|
2652
2661
|
* ```ts
|
|
2653
2662
|
* pipe(
|
|
2654
|
-
* Validation.
|
|
2663
|
+
* Validation.passed(42),
|
|
2655
2664
|
* Validation.fold(
|
|
2656
2665
|
* errors => `Errors: ${errors.join(", ")}`,
|
|
2657
2666
|
* value => `Value: ${value}`
|
|
@@ -2659,7 +2668,7 @@ declare namespace Validation {
|
|
|
2659
2668
|
* );
|
|
2660
2669
|
* ```
|
|
2661
2670
|
*/
|
|
2662
|
-
const fold: <E, A, B>(
|
|
2671
|
+
const fold: <E, A, B>(onFailed: (errors: NonEmptyList<E>) => B, onPassed: (a: A) => B) => (data: Validation<E, A>) => B;
|
|
2663
2672
|
/**
|
|
2664
2673
|
* Pattern matches on a Validation, returning the result of the matching case.
|
|
2665
2674
|
*
|
|
@@ -2668,25 +2677,25 @@ declare namespace Validation {
|
|
|
2668
2677
|
* pipe(
|
|
2669
2678
|
* validation,
|
|
2670
2679
|
* Validation.match({
|
|
2671
|
-
*
|
|
2672
|
-
*
|
|
2680
|
+
* passed: value => `Got ${value}`,
|
|
2681
|
+
* failed: errors => `Failed: ${errors.join(", ")}`
|
|
2673
2682
|
* })
|
|
2674
2683
|
* );
|
|
2675
2684
|
* ```
|
|
2676
2685
|
*/
|
|
2677
2686
|
const match: <E, A, B>(cases: {
|
|
2678
|
-
|
|
2679
|
-
|
|
2687
|
+
passed: (a: A) => B;
|
|
2688
|
+
failed: (errors: NonEmptyList<E>) => B;
|
|
2680
2689
|
}) => (data: Validation<E, A>) => B;
|
|
2681
2690
|
/**
|
|
2682
|
-
* Returns the success value or a default value if the Validation is
|
|
2691
|
+
* Returns the success value or a default value if the Validation is failed.
|
|
2683
2692
|
* The default can be a different type, widening the result to `A | B`.
|
|
2684
2693
|
*
|
|
2685
2694
|
* @example
|
|
2686
2695
|
* ```ts
|
|
2687
|
-
* pipe(Validation.
|
|
2688
|
-
* pipe(Validation.
|
|
2689
|
-
* pipe(Validation.
|
|
2696
|
+
* pipe(Validation.passed(5), Validation.getOrElse(() => 0)); // 5
|
|
2697
|
+
* pipe(Validation.failed("oops"), Validation.getOrElse(() => 0)); // 0
|
|
2698
|
+
* pipe(Validation.failed("oops"), Validation.getOrElse(() => null)); // null — typed as number | null
|
|
2690
2699
|
* ```
|
|
2691
2700
|
*/
|
|
2692
2701
|
const getOrElse: <E, A, B>(defaultValue: () => B) => (data: Validation<E, A>) => A | B;
|
|
@@ -2696,7 +2705,7 @@ declare namespace Validation {
|
|
|
2696
2705
|
* @example
|
|
2697
2706
|
* ```ts
|
|
2698
2707
|
* pipe(
|
|
2699
|
-
* Validation.
|
|
2708
|
+
* Validation.passed(5),
|
|
2700
2709
|
* Validation.tap(n => console.log("Value:", n)),
|
|
2701
2710
|
* Validation.map(n => n * 2)
|
|
2702
2711
|
* );
|
|
@@ -2710,7 +2719,7 @@ declare namespace Validation {
|
|
|
2710
2719
|
* @example
|
|
2711
2720
|
* ```ts
|
|
2712
2721
|
* pipe(
|
|
2713
|
-
* Validation.
|
|
2722
|
+
* Validation.failed("Name required"),
|
|
2714
2723
|
* Validation.tapError(errors => console.error("validation failed:", errors)),
|
|
2715
2724
|
* Validation.map(toUser)
|
|
2716
2725
|
* );
|
|
@@ -2718,82 +2727,82 @@ declare namespace Validation {
|
|
|
2718
2727
|
*/
|
|
2719
2728
|
const tapError: <E, A>(f: (errors: NonEmptyList<E>) => void) => (data: Validation<E, A>) => Validation<E, A>;
|
|
2720
2729
|
/**
|
|
2721
|
-
* Recovers from
|
|
2730
|
+
* Recovers from a Failed state by providing a fallback Validation.
|
|
2722
2731
|
* The fallback receives the accumulated error list so callers can inspect which errors occurred.
|
|
2723
2732
|
* The fallback can produce a different success type, widening the result to `Validation<E, A | B>`.
|
|
2724
2733
|
*/
|
|
2725
2734
|
const recover: <E, A, B>(fallback: (errors: NonEmptyList<E>) => Validation<E, B>) => (data: Validation<E, A>) => Validation<E, A | B>;
|
|
2726
2735
|
/**
|
|
2727
|
-
* Recovers from
|
|
2736
|
+
* Recovers from a Failed state unless `isBlocked` returns true for any of the accumulated errors.
|
|
2728
2737
|
* The fallback can produce a different success type, widening the result to `Validation<E, A | B>`.
|
|
2729
2738
|
*
|
|
2730
2739
|
* @example
|
|
2731
2740
|
* ```ts
|
|
2732
2741
|
* pipe(
|
|
2733
|
-
* Validation.
|
|
2734
|
-
* Validation.recoverUnless(e => e === "fatal", () => Validation.
|
|
2735
|
-
* ); //
|
|
2742
|
+
* Validation.failed("field-error"),
|
|
2743
|
+
* Validation.recoverUnless(e => e === "fatal", () => Validation.passed(0))
|
|
2744
|
+
* ); // Passed(0)
|
|
2736
2745
|
* ```
|
|
2737
2746
|
*/
|
|
2738
2747
|
const recoverUnless: <E, A, B>(isBlocked: (e: E) => boolean, fallback: () => Validation<E, B>) => (data: Validation<E, A>) => Validation<E, A | B>;
|
|
2739
2748
|
/**
|
|
2740
2749
|
* Converts a Validation to a Result.
|
|
2741
|
-
*
|
|
2750
|
+
* Passed becomes Ok, Failed becomes Err with the accumulated error list.
|
|
2742
2751
|
*
|
|
2743
2752
|
* @example
|
|
2744
2753
|
* ```ts
|
|
2745
|
-
* Validation.toResult(Validation.
|
|
2746
|
-
* Validation.toResult(Validation.
|
|
2754
|
+
* Validation.toResult(Validation.passed(42)); // Ok(42)
|
|
2755
|
+
* Validation.toResult(Validation.failed("oops")); // Err(["oops"])
|
|
2747
2756
|
* ```
|
|
2748
2757
|
*/
|
|
2749
2758
|
const toResult: <E, A>(data: Validation<E, A>) => Result<NonEmptyList<E>, A>;
|
|
2750
2759
|
/**
|
|
2751
|
-
* Converts a Validation to a Maybe. `
|
|
2760
|
+
* Converts a Validation to a Maybe. `Passed` becomes `Some`; `Failed` becomes `None`
|
|
2752
2761
|
* (errors are discarded).
|
|
2753
2762
|
*
|
|
2754
2763
|
* @example
|
|
2755
2764
|
* ```ts
|
|
2756
|
-
* Validation.toMaybe(Validation.
|
|
2757
|
-
* Validation.toMaybe(Validation.
|
|
2765
|
+
* Validation.toMaybe(Validation.passed(42)); // Some(42)
|
|
2766
|
+
* Validation.toMaybe(Validation.failed("bad")); // None
|
|
2758
2767
|
* ```
|
|
2759
2768
|
*/
|
|
2760
2769
|
const toMaybe: <E, A>(data: Validation<E, A>) => Maybe<A>;
|
|
2761
2770
|
/**
|
|
2762
|
-
* Converts a `Result` to a `Validation`. `Ok` becomes `
|
|
2771
|
+
* Converts a `Result` to a `Validation`. `Ok` becomes `Passed`; `Err(e)` becomes `Failed([e])`.
|
|
2763
2772
|
*
|
|
2764
2773
|
* Useful when bridging from error-short-circuiting `Result` pipelines into
|
|
2765
2774
|
* error-accumulating `Validation` pipelines.
|
|
2766
2775
|
*
|
|
2767
2776
|
* @example
|
|
2768
2777
|
* ```ts
|
|
2769
|
-
* Validation.fromResult(Result.ok(42)); //
|
|
2770
|
-
* Validation.fromResult(Result.
|
|
2778
|
+
* Validation.fromResult(Result.ok(42)); // Passed(42)
|
|
2779
|
+
* Validation.fromResult(Result.err("bad")); // Failed(["bad"])
|
|
2771
2780
|
* ```
|
|
2772
2781
|
*/
|
|
2773
2782
|
const fromResult: <E, A>(data: Result<E, A>) => Validation<E, A>;
|
|
2774
2783
|
/**
|
|
2775
2784
|
* Combines two independent Validation instances into a tuple.
|
|
2776
|
-
* If both are
|
|
2777
|
-
* If either is
|
|
2785
|
+
* If both are Passed, returns Passed with both values as a tuple.
|
|
2786
|
+
* If either is Failed, accumulates errors from both sides.
|
|
2778
2787
|
*
|
|
2779
2788
|
* @example
|
|
2780
2789
|
* ```ts
|
|
2781
2790
|
* Validation.product(
|
|
2782
|
-
* Validation.
|
|
2783
|
-
* Validation.
|
|
2784
|
-
* ); //
|
|
2791
|
+
* Validation.passed("alice"),
|
|
2792
|
+
* Validation.passed(30)
|
|
2793
|
+
* ); // Passed(["alice", 30])
|
|
2785
2794
|
*
|
|
2786
2795
|
* Validation.product(
|
|
2787
|
-
* Validation.
|
|
2788
|
-
* Validation.
|
|
2789
|
-
* ); //
|
|
2796
|
+
* Validation.failed("Name required"),
|
|
2797
|
+
* Validation.failed("Age must be >= 0")
|
|
2798
|
+
* ); // Failed(["Name required", "Age must be >= 0"])
|
|
2790
2799
|
* ```
|
|
2791
2800
|
*/
|
|
2792
2801
|
const product: <E, A, B>(first: Validation<E, A>, second: Validation<E, B>) => Validation<E, readonly [A, B]>;
|
|
2793
2802
|
/**
|
|
2794
2803
|
* Combines a non-empty list of Validation instances, accumulating all errors.
|
|
2795
|
-
* If all are
|
|
2796
|
-
* If any are
|
|
2804
|
+
* If all are Passed, returns Passed with all values collected into an array.
|
|
2805
|
+
* If any are Failed, returns Failed with all accumulated errors.
|
|
2797
2806
|
*
|
|
2798
2807
|
* @example
|
|
2799
2808
|
* ```ts
|
|
@@ -2802,7 +2811,7 @@ declare namespace Validation {
|
|
|
2802
2811
|
* validateEmail(email),
|
|
2803
2812
|
* validateAge(age)
|
|
2804
2813
|
* ]);
|
|
2805
|
-
* //
|
|
2814
|
+
* // Passed([name, email, age]) or Failed([...all errors])
|
|
2806
2815
|
* ```
|
|
2807
2816
|
*/
|
|
2808
2817
|
const productAll: <E, A>(data: NonEmptyList<Validation<E, A>>) => Validation<E, readonly A[]>;
|
|
@@ -2817,50 +2826,50 @@ declare namespace Validation {
|
|
|
2817
2826
|
* ```ts
|
|
2818
2827
|
* const validateName = (name: string): TaskValidation<string, string> =>
|
|
2819
2828
|
* name.length > 0
|
|
2820
|
-
* ? TaskValidation.
|
|
2821
|
-
* : TaskValidation.
|
|
2829
|
+
* ? TaskValidation.passed(name)
|
|
2830
|
+
* : TaskValidation.failed("Name is required");
|
|
2822
2831
|
*
|
|
2823
2832
|
* // Accumulate errors from multiple async validations using ap
|
|
2824
2833
|
* pipe(
|
|
2825
|
-
* TaskValidation.
|
|
2834
|
+
* TaskValidation.passed((name: string) => (age: number) => ({ name, age })),
|
|
2826
2835
|
* TaskValidation.ap(validateName("")),
|
|
2827
2836
|
* TaskValidation.ap(validateAge(-1))
|
|
2828
2837
|
* )();
|
|
2829
|
-
* //
|
|
2838
|
+
* // Failed(["Name is required", "Age must be positive"])
|
|
2830
2839
|
* ```
|
|
2831
2840
|
*/
|
|
2832
2841
|
type TaskValidation<E, A> = Task<Validation<E, A>>;
|
|
2833
2842
|
declare namespace TaskValidation {
|
|
2834
2843
|
/**
|
|
2835
|
-
* Wraps a value in a
|
|
2844
|
+
* Wraps a value in a passed TaskValidation.
|
|
2836
2845
|
*/
|
|
2837
|
-
const
|
|
2846
|
+
const passed: <E, A>(value: A) => TaskValidation<E, A>;
|
|
2838
2847
|
/**
|
|
2839
2848
|
* Creates a failed TaskValidation with a single error.
|
|
2840
2849
|
*/
|
|
2841
|
-
const
|
|
2850
|
+
const failed: <E, A>(error: E) => TaskValidation<E, A>;
|
|
2842
2851
|
/**
|
|
2843
|
-
* Creates
|
|
2852
|
+
* Creates a failed TaskValidation from multiple errors.
|
|
2844
2853
|
*/
|
|
2845
|
-
const
|
|
2854
|
+
const failedAll: <E, A>(errors: NonEmptyList<E>) => TaskValidation<E, A>;
|
|
2846
2855
|
/**
|
|
2847
2856
|
* Lifts a Validation into a TaskValidation.
|
|
2848
2857
|
*/
|
|
2849
2858
|
const fromValidation: <E, A>(validation: Validation<E, A>) => TaskValidation<E, A>;
|
|
2850
2859
|
/**
|
|
2851
2860
|
* Creates a TaskValidation from a nullable value.
|
|
2852
|
-
* If the value is null or undefined, returns
|
|
2853
|
-
* Otherwise, returns
|
|
2861
|
+
* If the value is null or undefined, returns Failed with the error from onNull.
|
|
2862
|
+
* Otherwise, returns Passed.
|
|
2854
2863
|
*/
|
|
2855
2864
|
const fromNullable: <E>(onNull: () => E) => <A>(value: A | null | undefined) => TaskValidation<E, A>;
|
|
2856
2865
|
/**
|
|
2857
2866
|
* Creates a TaskValidation from a Maybe.
|
|
2858
|
-
* Some becomes
|
|
2867
|
+
* Some becomes Passed, None becomes Failed with the error from onNone.
|
|
2859
2868
|
*/
|
|
2860
2869
|
const fromMaybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => TaskValidation<E, A>;
|
|
2861
2870
|
/**
|
|
2862
2871
|
* Creates a TaskValidation from a Result.
|
|
2863
|
-
* Ok becomes
|
|
2872
|
+
* Ok becomes Passed, Err(e) becomes Failed([e]).
|
|
2864
2873
|
*/
|
|
2865
2874
|
const fromResult: <E, A>(result: Result<E, A>) => TaskValidation<E, A>;
|
|
2866
2875
|
/**
|
|
@@ -2890,7 +2899,7 @@ declare namespace TaskValidation {
|
|
|
2890
2899
|
* @example
|
|
2891
2900
|
* ```ts
|
|
2892
2901
|
* pipe(
|
|
2893
|
-
* TaskValidation.
|
|
2902
|
+
* TaskValidation.passed((name: string) => (age: number) => ({ name, age })),
|
|
2894
2903
|
* TaskValidation.ap(validateName(name)),
|
|
2895
2904
|
* TaskValidation.ap(validateAge(age))
|
|
2896
2905
|
* )();
|
|
@@ -2900,7 +2909,7 @@ declare namespace TaskValidation {
|
|
|
2900
2909
|
/**
|
|
2901
2910
|
* Extracts a value from a TaskValidation by providing handlers for both cases.
|
|
2902
2911
|
*/
|
|
2903
|
-
const fold: <E, A, B>(
|
|
2912
|
+
const fold: <E, A, B>(onFailed: (errors: NonEmptyList<E>) => B, onPassed: (a: A) => B) => (data: TaskValidation<E, A>) => Task<B>;
|
|
2904
2913
|
/**
|
|
2905
2914
|
* Pattern matches on a TaskValidation, returning a Task of the result.
|
|
2906
2915
|
*
|
|
@@ -2909,18 +2918,18 @@ declare namespace TaskValidation {
|
|
|
2909
2918
|
* pipe(
|
|
2910
2919
|
* validateForm(input),
|
|
2911
2920
|
* TaskValidation.match({
|
|
2912
|
-
*
|
|
2913
|
-
*
|
|
2921
|
+
* passed: data => save(data),
|
|
2922
|
+
* failed: errors => showErrors(errors)
|
|
2914
2923
|
* })
|
|
2915
2924
|
* )();
|
|
2916
2925
|
* ```
|
|
2917
2926
|
*/
|
|
2918
2927
|
const match: <E, A, B>(cases: {
|
|
2919
|
-
|
|
2920
|
-
|
|
2928
|
+
passed: (a: A) => B;
|
|
2929
|
+
failed: (errors: NonEmptyList<E>) => B;
|
|
2921
2930
|
}) => (data: TaskValidation<E, A>) => Task<B>;
|
|
2922
2931
|
/**
|
|
2923
|
-
* Returns the success value or a default value if the TaskValidation is
|
|
2932
|
+
* Returns the success value or a default value if the TaskValidation is failed.
|
|
2924
2933
|
* The default can be a different type, widening the result to `Task<A | B>`.
|
|
2925
2934
|
*/
|
|
2926
2935
|
const getOrElse: <E, A, B>(defaultValue: () => B) => (data: TaskValidation<E, A>) => Task<A | B>;
|
|
@@ -2930,14 +2939,14 @@ declare namespace TaskValidation {
|
|
|
2930
2939
|
*/
|
|
2931
2940
|
const tap: <E, A>(f: (a: A) => void) => (data: TaskValidation<E, A>) => TaskValidation<E, A>;
|
|
2932
2941
|
/**
|
|
2933
|
-
* Recovers from
|
|
2942
|
+
* Recovers from a Failed state by providing a fallback TaskValidation.
|
|
2934
2943
|
* The fallback receives the accumulated error list so callers can inspect which errors occurred.
|
|
2935
2944
|
* The fallback can produce a different success type, widening the result to `TaskValidation<E, A | B>`.
|
|
2936
2945
|
*/
|
|
2937
2946
|
const recover: <E, A, B>(fallback: (errors: NonEmptyList<E>) => TaskValidation<E, B>) => (data: TaskValidation<E, A>) => TaskValidation<E, A | B>;
|
|
2938
2947
|
/**
|
|
2939
2948
|
* Runs two TaskValidations concurrently and combines their results into a tuple.
|
|
2940
|
-
* If both are
|
|
2949
|
+
* If both are Passed, returns Passed with both values. If either fails, accumulates
|
|
2941
2950
|
* errors from both sides.
|
|
2942
2951
|
*
|
|
2943
2952
|
* @example
|
|
@@ -2945,14 +2954,14 @@ declare namespace TaskValidation {
|
|
|
2945
2954
|
* await TaskValidation.product(
|
|
2946
2955
|
* validateName(form.name),
|
|
2947
2956
|
* validateAge(form.age),
|
|
2948
|
-
* )(); //
|
|
2957
|
+
* )(); // Passed(["Alice", 30]) or Failed([...errors])
|
|
2949
2958
|
* ```
|
|
2950
2959
|
*/
|
|
2951
2960
|
const product: <E, A, B>(first: TaskValidation<E, A>, second: TaskValidation<E, B>) => TaskValidation<E, readonly [A, B]>;
|
|
2952
2961
|
/**
|
|
2953
2962
|
* Runs all TaskValidations concurrently and collects results.
|
|
2954
|
-
* If all are
|
|
2955
|
-
* If any fail, returns
|
|
2963
|
+
* If all are Passed, returns Passed with all values as an array.
|
|
2964
|
+
* If any fail, returns Failed with all accumulated errors.
|
|
2956
2965
|
*
|
|
2957
2966
|
* @example
|
|
2958
2967
|
* ```ts
|
|
@@ -2960,7 +2969,7 @@ declare namespace TaskValidation {
|
|
|
2960
2969
|
* validateName(form.name),
|
|
2961
2970
|
* validateEmail(form.email),
|
|
2962
2971
|
* validateAge(form.age),
|
|
2963
|
-
* ])(); //
|
|
2972
|
+
* ])(); // Passed([name, email, age]) or Failed([...all errors])
|
|
2964
2973
|
* ```
|
|
2965
2974
|
*/
|
|
2966
2975
|
const productAll: <E, A>(data: NonEmptyList<TaskValidation<E, A>>) => TaskValidation<E, readonly A[]>;
|
|
@@ -3020,7 +3029,7 @@ declare namespace These {
|
|
|
3020
3029
|
* These.both(42, "Deprecated API used"); // { kind: "Both", first: 42, second: "Deprecated API used" }
|
|
3021
3030
|
* ```
|
|
3022
3031
|
*/
|
|
3023
|
-
const both: <A, B>(
|
|
3032
|
+
const both: <A, B>(f: A, s: B) => TheseBoth<A, B>;
|
|
3024
3033
|
/**
|
|
3025
3034
|
* Type guard — checks if a These holds only a first value.
|
|
3026
3035
|
*/
|
|
@@ -3319,4 +3328,4 @@ declare namespace Tuple {
|
|
|
3319
3328
|
const tap: <A, B>(f: (a: A, b: B) => void) => (tuple: Tuple<A, B>) => Tuple<A, B>;
|
|
3320
3329
|
}
|
|
3321
3330
|
|
|
3322
|
-
export { Combinable, Deferred, type
|
|
3331
|
+
export { Combinable, Deferred, type Failed, type Failure, Lazy, Lens, type Loading, Logged, Maybe, type NotAsked, Op, Optional, type Passed, Predicate, Reader, Refinement, RemoteData, Resource, Result, State, type Success, Task, TaskMaybe, TaskResult, TaskValidation, These, type TheseBoth, type TheseFirst, type TheseSecond, Tuple, Validation };
|