@nlozgachev/pipelined 0.65.0 → 0.67.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 +70 -57
- package/dist/{Core-BHN87zoB.mjs → Core-BCN6WRzp.mjs} +1038 -616
- package/dist/{Core-BDXRLmMa.cjs → Core-CfAL_21H.cjs} +1043 -621
- package/dist/{InternalTypes-DzDey5Do.d.ts → InternalTypes-C0F5jyVQ.d.ts} +1 -1
- package/dist/{InternalTypes-B1Lh9uw_.d.cts → InternalTypes-DxSlzrpu.d.cts} +1 -1
- package/dist/composition.d.cts +2 -2
- package/dist/composition.d.ts +2 -2
- package/dist/core.cjs +2 -2
- package/dist/core.d.cts +3 -3
- package/dist/core.d.ts +3 -3
- package/dist/core.mjs +2 -2
- package/dist/data.cjs +1040 -535
- package/dist/data.d.cts +497 -310
- package/dist/data.d.ts +497 -310
- package/dist/data.mjs +1040 -535
- package/dist/{index-Bs8En5LJ.d.cts → index-CTe9CCHY.d.cts} +3 -0
- package/dist/{index-Bs8En5LJ.d.ts → index-CTe9CCHY.d.ts} +3 -0
- package/dist/{index-B07Wr815.d.ts → index-CdzHrj62.d.ts} +792 -444
- package/dist/{index-DCK_VPog.d.cts → index-NYjtX7XS.d.cts} +792 -444
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.mjs +2 -2
- package/dist/types.cjs +5 -1
- package/dist/types.d.cts +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.mjs +5 -1
- package/package.json +20 -19
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as Duration, t as RetryPolicy } from "./index-
|
|
2
|
-
import { _ as WithSecond, a as Thenable, b as WithValue, c as WithCooldown, d as WithErrors, f as WithFirst, g as WithN, h as WithMinInterval, i as RetryOptions, l as WithDuration, m as WithLog, o as TimeoutOptions, p as WithKind, r as NonEmptyArr, s as WithConcurrency, u as WithError, v as WithSize, x as Deferred, y as WithTimeout } from "./InternalTypes-
|
|
1
|
+
import { n as Duration, t as RetryPolicy } from "./index-CTe9CCHY.cjs";
|
|
2
|
+
import { _ as WithSecond, a as Thenable, b as WithValue, c as WithCooldown, d as WithErrors, f as WithFirst, g as WithN, h as WithMinInterval, i as RetryOptions, l as WithDuration, m as WithLog, o as TimeoutOptions, p as WithKind, r as NonEmptyArr, s as WithConcurrency, u as WithError, v as WithSize, x as Deferred, y as WithTimeout } from "./InternalTypes-DxSlzrpu.cjs";
|
|
3
3
|
//#region src/Core/Combinable.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* A type that can combine two values of type `A` into one, with a neutral starting value.
|
|
@@ -218,6 +218,145 @@ declare const Equality: {
|
|
|
218
218
|
tuple: <T extends readonly unknown[]>(...equalities: { [K in keyof T]: Equality<T[K]>; }) => Equality<T>;
|
|
219
219
|
};
|
|
220
220
|
//#endregion
|
|
221
|
+
//#region src/Core/EventBus.d.ts
|
|
222
|
+
/**
|
|
223
|
+
* An event bus pipeline for a typed message schema `S`.
|
|
224
|
+
*
|
|
225
|
+
* `EventBus` provides typed event emission, sequence matching, state reduction,
|
|
226
|
+
* and structural event bus forwarding.
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```ts
|
|
230
|
+
* type AppMessages = {
|
|
231
|
+
* userLoggedIn: { userId: string };
|
|
232
|
+
* checkoutStarted: { amount: number };
|
|
233
|
+
* };
|
|
234
|
+
*
|
|
235
|
+
* const appBus = EventBus.make<AppMessages>();
|
|
236
|
+
*
|
|
237
|
+
* const subscription = EventBus.listen(
|
|
238
|
+
* appBus,
|
|
239
|
+
* ["userLoggedIn", "checkoutStarted"],
|
|
240
|
+
* { ordered: true }
|
|
241
|
+
* ).reduce(
|
|
242
|
+
* (msg, state) => {
|
|
243
|
+
* if (msg.kind === "checkoutStarted") {
|
|
244
|
+
* return { count: state.count + 1 };
|
|
245
|
+
* }
|
|
246
|
+
* return state;
|
|
247
|
+
* },
|
|
248
|
+
* { count: 0 }
|
|
249
|
+
* );
|
|
250
|
+
*
|
|
251
|
+
* EventBus.emit(appBus, {
|
|
252
|
+
* kind: "userLoggedIn",
|
|
253
|
+
* value: { userId: "user-1" },
|
|
254
|
+
* });
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
type EventBus<S extends Record<string, unknown>> = {
|
|
258
|
+
readonly options?: EventBus.Options;
|
|
259
|
+
/** @internal */
|
|
260
|
+
readonly _listeners: Set<(msg: EventBus.Message<S>) => void>;
|
|
261
|
+
/**
|
|
262
|
+
* @internal
|
|
263
|
+
* Lazy array snapshot of `_listeners`. Avoids allocating new array objects on every `emit` call
|
|
264
|
+
* (2.98x emission speedup, 0 heap allocations). Rebuilt whenever `_listeners` is mutated,
|
|
265
|
+
* guaranteeing reentrancy safety and preventing listeners subscribed mid-emission from executing early.
|
|
266
|
+
*/
|
|
267
|
+
_listenerArray: Array<(msg: EventBus.Message<S>) => void> | null;
|
|
268
|
+
/** @internal */
|
|
269
|
+
readonly _queue: Array<EventBus.Message<S>>;
|
|
270
|
+
/** @internal */
|
|
271
|
+
_isEmitting: boolean;
|
|
272
|
+
};
|
|
273
|
+
declare const EventBus: {
|
|
274
|
+
/**
|
|
275
|
+
* Constructs a new `EventBus` instance.
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```ts
|
|
279
|
+
* const bus = EventBus.make<AppMessages>({ name: "app" });
|
|
280
|
+
* ```
|
|
281
|
+
*/
|
|
282
|
+
make: <S extends Record<string, unknown>>(options?: EventBus.Options) => EventBus<S>;
|
|
283
|
+
/**
|
|
284
|
+
* Emits a message payload to one or more target event buses.
|
|
285
|
+
*
|
|
286
|
+
* Uses a synchronous breadth-first trampoline queue to handle re-entrant emissions deterministically.
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* ```ts
|
|
290
|
+
* EventBus.emit(busA, {
|
|
291
|
+
* kind: "userLoggedIn",
|
|
292
|
+
* value: { userId: "user-1" },
|
|
293
|
+
* });
|
|
294
|
+
*
|
|
295
|
+
* EventBus.emit([busA, busB], {
|
|
296
|
+
* kind: "userLoggedIn",
|
|
297
|
+
* value: { userId: "user-1" },
|
|
298
|
+
* });
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
emit: <S extends Record<string, unknown>, K extends keyof S & string>(target: EventBus<S> | ReadonlyArray<EventBus<S>>, message: WithKind<K> & WithValue<S[K]>) => void;
|
|
302
|
+
/**
|
|
303
|
+
* Forwards messages from one event bus to another (or multiple).
|
|
304
|
+
*
|
|
305
|
+
* @example
|
|
306
|
+
* ```ts
|
|
307
|
+
* const stop = EventBus.forward({
|
|
308
|
+
* from: authBus,
|
|
309
|
+
* to: analyticsBus,
|
|
310
|
+
* only: ["userLoggedIn"],
|
|
311
|
+
* });
|
|
312
|
+
* ```
|
|
313
|
+
*/
|
|
314
|
+
forward: <S extends Record<string, unknown>>(options: EventBus.ForwardOptions<S>) => () => void;
|
|
315
|
+
/**
|
|
316
|
+
* Initiates listener registration on an event bus for specific event kind(s) or sequence.
|
|
317
|
+
*
|
|
318
|
+
* @example
|
|
319
|
+
* ```ts
|
|
320
|
+
* const sub = EventBus.listen(
|
|
321
|
+
* appBus,
|
|
322
|
+
* ["userLoggedIn", "checkoutStarted"],
|
|
323
|
+
* { ordered: true }
|
|
324
|
+
* ).reduce(
|
|
325
|
+
* (msg, state) => ({ count: state.count + 1 }),
|
|
326
|
+
* { count: 0 }
|
|
327
|
+
* );
|
|
328
|
+
* ```
|
|
329
|
+
*/
|
|
330
|
+
listen: <S extends Record<string, unknown>, K extends keyof S & string>(bus: EventBus<S>, events: K | ReadonlyArray<K>, options?: EventBus.SequenceOptions<S>) => EventBus.ListenerBuilder<S>;
|
|
331
|
+
};
|
|
332
|
+
declare namespace EventBus {
|
|
333
|
+
type Message<S extends Record<string, unknown>> = { [K in keyof S & string]: WithKind<K> & WithValue<S[K]>; }[keyof S & string];
|
|
334
|
+
type Options = {
|
|
335
|
+
readonly name?: string;
|
|
336
|
+
readonly onError?: (error: unknown) => void;
|
|
337
|
+
};
|
|
338
|
+
type SequenceOptions<S extends Record<string, unknown>> = {
|
|
339
|
+
readonly ordered?: boolean;
|
|
340
|
+
readonly strict?: boolean;
|
|
341
|
+
readonly once?: boolean;
|
|
342
|
+
readonly reset?: (keyof S & string) | ReadonlyArray<keyof S & string>;
|
|
343
|
+
readonly optional?: (keyof S & string) | ReadonlyArray<keyof S & string>;
|
|
344
|
+
};
|
|
345
|
+
type Subscription<State> = {
|
|
346
|
+
readonly unsubscribe: () => void;
|
|
347
|
+
readonly getState: () => State;
|
|
348
|
+
};
|
|
349
|
+
type ForwardOptions<S extends Record<string, unknown>> = {
|
|
350
|
+
readonly from: EventBus<S>;
|
|
351
|
+
readonly to: EventBus<S> | ReadonlyArray<EventBus<S>>;
|
|
352
|
+
readonly only?: ReadonlyArray<keyof S & string>;
|
|
353
|
+
};
|
|
354
|
+
type ListenerBuilder<S extends Record<string, unknown>> = {
|
|
355
|
+
readonly reduce: <State>(reducer: (msg: Message<S>, state: State) => State, initialState: State) => Subscription<State>;
|
|
356
|
+
readonly tap: (effect: (msg: Message<S>) => void) => () => void;
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
//#endregion
|
|
221
360
|
//#region src/Core/Lazy.d.ts
|
|
222
361
|
/**
|
|
223
362
|
* A synchronous memoized computation. The factory function runs exactly once —
|
|
@@ -436,6 +575,16 @@ declare const Lens: {
|
|
|
436
575
|
*/
|
|
437
576
|
type Logged<L, A> = WithValue<A> & WithLog<L>;
|
|
438
577
|
declare const Logged: {
|
|
578
|
+
/**
|
|
579
|
+
* Creates a `Logged` with a value and an optional initial log array.
|
|
580
|
+
*
|
|
581
|
+
* @example
|
|
582
|
+
* ```ts
|
|
583
|
+
* Logged.make(42); // { value: 42, log: [] }
|
|
584
|
+
* Logged.make(42, ["initialized"]); // { value: 42, log: ["initialized"] }
|
|
585
|
+
* ```
|
|
586
|
+
*/
|
|
587
|
+
make: <W = never, A = unknown>(value: A, log?: readonly W[]) => Logged<W, A>;
|
|
439
588
|
from: {
|
|
440
589
|
/**
|
|
441
590
|
* Wraps a pure value into a `Logged` with an empty log.
|
|
@@ -500,11 +649,11 @@ declare const Logged: {
|
|
|
500
649
|
* };
|
|
501
650
|
* const arg: Logged<string, number> = { value: 5, log: ["arg-loaded"] };
|
|
502
651
|
*
|
|
503
|
-
* const result = pipe(fn, Logged.
|
|
652
|
+
* const result = pipe(fn, Logged.apply(arg));
|
|
504
653
|
* Logged.run(result); // [10, ["fn-loaded", "arg-loaded"]]
|
|
505
654
|
* ```
|
|
506
655
|
*/
|
|
507
|
-
|
|
656
|
+
apply: <W, A>(arg: Logged<W, A>) => <B>(data: Logged<W, (a: A) => B>) => Logged<W, B>;
|
|
508
657
|
/**
|
|
509
658
|
* Runs a side effect on the value without changing the `Logged`.
|
|
510
659
|
* Useful for debugging or inspecting intermediate values.
|
|
@@ -612,6 +761,8 @@ declare const Maybe: {
|
|
|
612
761
|
/**
|
|
613
762
|
* Type guard that checks if a Maybe is Some.
|
|
614
763
|
*
|
|
764
|
+
* @see {@link Maybe.is.none}
|
|
765
|
+
*
|
|
615
766
|
* @example
|
|
616
767
|
* ```ts
|
|
617
768
|
* const value = Maybe.make.some(42);
|
|
@@ -624,6 +775,8 @@ declare const Maybe: {
|
|
|
624
775
|
/**
|
|
625
776
|
* Type guard that checks if a Maybe is None.
|
|
626
777
|
*
|
|
778
|
+
* @see {@link Maybe.is.some}
|
|
779
|
+
*
|
|
627
780
|
* @example
|
|
628
781
|
* ```ts
|
|
629
782
|
* const value = Maybe.make.none();
|
|
@@ -673,6 +826,17 @@ declare const Maybe: {
|
|
|
673
826
|
* ```
|
|
674
827
|
*/
|
|
675
828
|
Result: <E>(onNone: () => E) => <A>(data: Maybe<A>) => Result<E, A>;
|
|
829
|
+
/**
|
|
830
|
+
* Converts a Maybe to a Validation.
|
|
831
|
+
* Some becomes Passed, None becomes Failed with error produced by `onNone`.
|
|
832
|
+
*
|
|
833
|
+
* @example
|
|
834
|
+
* ```ts
|
|
835
|
+
* pipe(Maybe.make.some(42), Maybe.to.Validation(() => "missing")); // Passed(42)
|
|
836
|
+
* pipe(Maybe.make.none(), Maybe.to.Validation(() => "missing")); // Failed(["missing"])
|
|
837
|
+
* ```
|
|
838
|
+
*/
|
|
839
|
+
Validation: <E>(onNone: () => E) => <A>(data: Maybe<A>) => Validation<E, A>;
|
|
676
840
|
};
|
|
677
841
|
from: {
|
|
678
842
|
/**
|
|
@@ -712,20 +876,36 @@ declare const Maybe: {
|
|
|
712
876
|
*/
|
|
713
877
|
Result: <E, A>(data: Result<E, A>) => Maybe<A>;
|
|
714
878
|
};
|
|
879
|
+
/**
|
|
880
|
+
* Wraps a synchronous operation that may throw, returning a `Maybe<A>`.
|
|
881
|
+
* Returns `Some(value)` if successful, or `None` if an exception is thrown.
|
|
882
|
+
*
|
|
883
|
+
* @example
|
|
884
|
+
* ```ts
|
|
885
|
+
* const safeParse = (s: string) => Maybe.tryCatch(() => JSON.parse(s));
|
|
886
|
+
* safeParse('{"a": 1}'); // Some({ a: 1 })
|
|
887
|
+
* safeParse('invalid'); // None
|
|
888
|
+
* ```
|
|
889
|
+
*/
|
|
890
|
+
tryCatch: <A>(f: () => A) => Maybe<A>;
|
|
715
891
|
/**
|
|
716
892
|
* Transforms the value inside a Maybe if it exists.
|
|
717
893
|
*
|
|
894
|
+
* @see {@link Maybe.chain} for functions that return a Maybe.
|
|
895
|
+
*
|
|
718
896
|
* @example
|
|
719
897
|
* ```ts
|
|
720
898
|
* pipe(Maybe.make.some(5), Maybe.map(n => n * 2)); // Some(10)
|
|
721
899
|
* pipe(Maybe.make.none(), Maybe.map(n => n * 2)); // None
|
|
722
900
|
* ```
|
|
723
901
|
*/
|
|
724
|
-
map: <A, B>(
|
|
902
|
+
map: <A, B>(transform: (value: A) => B) => (maybe: Maybe<A>) => Maybe<B>;
|
|
725
903
|
/**
|
|
726
|
-
* Chains Maybe computations. If the first is Some, passes the value to
|
|
904
|
+
* Chains Maybe computations. If the first is Some, passes the value to `transform`.
|
|
727
905
|
* If the first is None, propagates None.
|
|
728
906
|
*
|
|
907
|
+
* @see {@link Maybe.map} for transforming with plain non-optional functions.
|
|
908
|
+
*
|
|
729
909
|
* @example
|
|
730
910
|
* ```ts
|
|
731
911
|
* const parseNumber = (s: string): Maybe<number> => {
|
|
@@ -737,10 +917,12 @@ declare const Maybe: {
|
|
|
737
917
|
* pipe(Maybe.make.some("abc"), Maybe.chain(parseNumber)); // None
|
|
738
918
|
* ```
|
|
739
919
|
*/
|
|
740
|
-
chain: <A, B>(
|
|
920
|
+
chain: <A, B>(transform: (value: A) => Maybe<B>) => (maybe: Maybe<A>) => Maybe<B>;
|
|
741
921
|
/**
|
|
742
922
|
* Extracts the value from a Maybe by providing handlers for both cases.
|
|
743
923
|
*
|
|
924
|
+
* @see {@link Maybe.match} for named-case handling using an object.
|
|
925
|
+
*
|
|
744
926
|
* @example
|
|
745
927
|
* ```ts
|
|
746
928
|
* pipe(
|
|
@@ -752,10 +934,12 @@ declare const Maybe: {
|
|
|
752
934
|
* ); // "Value: 5"
|
|
753
935
|
* ```
|
|
754
936
|
*/
|
|
755
|
-
fold: <A, B>(onNone: () => B, onSome: (
|
|
937
|
+
fold: <A, B>(onNone: () => B, onSome: (value: A) => B) => (maybe: Maybe<A>) => B;
|
|
756
938
|
/**
|
|
757
939
|
* Pattern matches on a Maybe, returning the result of the matching case.
|
|
758
940
|
*
|
|
941
|
+
* @see {@link Maybe.fold} for positional arguments (onNone, onSome).
|
|
942
|
+
*
|
|
759
943
|
* @example
|
|
760
944
|
* ```ts
|
|
761
945
|
* pipe(
|
|
@@ -769,13 +953,16 @@ declare const Maybe: {
|
|
|
769
953
|
*/
|
|
770
954
|
match: <A, B>(cases: {
|
|
771
955
|
none: () => B;
|
|
772
|
-
some: (
|
|
773
|
-
}) => (
|
|
956
|
+
some: (value: A) => B;
|
|
957
|
+
}) => (maybe: Maybe<A>) => B;
|
|
774
958
|
/**
|
|
775
959
|
* Returns the value inside a Maybe, or a default value if None.
|
|
776
960
|
* The default is a thunk `() => B` — evaluated only when the Maybe is None.
|
|
777
961
|
* The default can be a different type, widening the result to `A | B`.
|
|
778
962
|
*
|
|
963
|
+
* @see {@link Maybe.match}
|
|
964
|
+
* @see {@link Maybe.to.nullable}
|
|
965
|
+
*
|
|
779
966
|
* @example
|
|
780
967
|
* ```ts
|
|
781
968
|
* pipe(Maybe.make.some(5), Maybe.getOrElse(() => 0)); // 5
|
|
@@ -783,11 +970,13 @@ declare const Maybe: {
|
|
|
783
970
|
* pipe(Maybe.make.none<string>(), Maybe.getOrElse(() => null)); // null — typed as string | null
|
|
784
971
|
* ```
|
|
785
972
|
*/
|
|
786
|
-
getOrElse: <B>(defaultValue: () => B) => <A>(
|
|
973
|
+
getOrElse: <B>(defaultValue: () => B) => <A>(maybe: Maybe<A>) => A | B;
|
|
787
974
|
/**
|
|
788
975
|
* Executes a side effect on the value without changing the Maybe.
|
|
789
976
|
* Useful for logging or debugging.
|
|
790
977
|
*
|
|
978
|
+
* @see {@link Maybe.tapNone} for running side effects on None.
|
|
979
|
+
*
|
|
791
980
|
* @example
|
|
792
981
|
* ```ts
|
|
793
982
|
* pipe(
|
|
@@ -797,29 +986,51 @@ declare const Maybe: {
|
|
|
797
986
|
* );
|
|
798
987
|
* ```
|
|
799
988
|
*/
|
|
800
|
-
tap: <A>(
|
|
989
|
+
tap: <A>(sideEffect: (value: A) => void) => (maybe: Maybe<A>) => Maybe<A>;
|
|
990
|
+
/**
|
|
991
|
+
* Executes a side effect when the Maybe is None, without changing the Maybe.
|
|
992
|
+
*
|
|
993
|
+
* @see {@link Maybe.tap} for running side effects on Some.
|
|
994
|
+
*
|
|
995
|
+
* @example
|
|
996
|
+
* ```ts
|
|
997
|
+
* pipe(
|
|
998
|
+
* Maybe.make.none(),
|
|
999
|
+
* Maybe.tapNone(() => console.log("Value missing")),
|
|
1000
|
+
* );
|
|
1001
|
+
* ```
|
|
1002
|
+
*/
|
|
1003
|
+
tapNone: (sideEffect: () => void) => <A>(maybe: Maybe<A>) => Maybe<A>;
|
|
801
1004
|
/**
|
|
802
|
-
* Filters a Maybe based on a predicate.
|
|
1005
|
+
* Filters a Maybe based on a predicate or type guard.
|
|
803
1006
|
* Returns None if the predicate returns false or if the Maybe is already None.
|
|
804
1007
|
*
|
|
1008
|
+
* @see {@link Maybe.map}
|
|
1009
|
+
*
|
|
805
1010
|
* @example
|
|
806
1011
|
* ```ts
|
|
807
1012
|
* pipe(Maybe.make.some(5), Maybe.filter(n => n > 3)); // Some(5)
|
|
808
1013
|
* pipe(Maybe.make.some(2), Maybe.filter(n => n > 3)); // None
|
|
1014
|
+
* pipe(Maybe.make.some("hi"), Maybe.filter((x): x is string => typeof x === "string")); // Some("hi")
|
|
809
1015
|
* ```
|
|
810
1016
|
*/
|
|
811
|
-
filter:
|
|
1017
|
+
filter: {
|
|
1018
|
+
<A, B extends A>(refinement: (value: A) => value is B): (maybe: Maybe<A>) => Maybe<B>;
|
|
1019
|
+
<A>(predicate: (value: A) => boolean): (maybe: Maybe<A>) => Maybe<A>;
|
|
1020
|
+
};
|
|
812
1021
|
/**
|
|
813
1022
|
* Recovers from a None by providing a fallback Maybe.
|
|
814
1023
|
* The fallback can produce a different type, widening the result to `Maybe<A | B>`.
|
|
815
1024
|
*
|
|
1025
|
+
* @see {@link Maybe.getOrElse}
|
|
1026
|
+
*
|
|
816
1027
|
* @example
|
|
817
1028
|
* ```ts
|
|
818
1029
|
* pipe(Maybe.make.none(), Maybe.recover(() => Maybe.make.some(42))); // Some(42)
|
|
819
1030
|
* pipe(Maybe.make.some(10), Maybe.recover(() => Maybe.make.some(42))); // Some(10)
|
|
820
1031
|
* ```
|
|
821
1032
|
*/
|
|
822
|
-
recover: <B>(fallback: () => Maybe<B>) => <A>(
|
|
1033
|
+
recover: <B>(fallback: () => Maybe<B>) => <A>(maybe: Maybe<A>) => Maybe<A | B>;
|
|
823
1034
|
/**
|
|
824
1035
|
* Applies a function wrapped in a Maybe to a value wrapped in a Maybe.
|
|
825
1036
|
*
|
|
@@ -828,12 +1039,12 @@ declare const Maybe: {
|
|
|
828
1039
|
* const add = (a: number) => (b: number) => a + b;
|
|
829
1040
|
* pipe(
|
|
830
1041
|
* Maybe.make.some(add),
|
|
831
|
-
* Maybe.
|
|
832
|
-
* Maybe.
|
|
1042
|
+
* Maybe.apply(Maybe.make.some(5)),
|
|
1043
|
+
* Maybe.apply(Maybe.make.some(3))
|
|
833
1044
|
* ); // Some(8)
|
|
834
1045
|
* ```
|
|
835
1046
|
*/
|
|
836
|
-
|
|
1047
|
+
apply: <A>(arg: Maybe<A>) => <B>(data: Maybe<(a: A) => B>) => Maybe<B>;
|
|
837
1048
|
/**
|
|
838
1049
|
* Converts a Maybe value into an object containing a single property.
|
|
839
1050
|
* Initiates the pipeline accumulator record.
|
|
@@ -884,6 +1095,7 @@ declare const Maybe: {
|
|
|
884
1095
|
};
|
|
885
1096
|
//#endregion
|
|
886
1097
|
//#region src/Core/Op.d.ts
|
|
1098
|
+
declare const _opBrand: unique symbol;
|
|
887
1099
|
/**
|
|
888
1100
|
* A reusable description of async work — decoupled from execution strategy and lifetime.
|
|
889
1101
|
*
|
|
@@ -902,7 +1114,7 @@ declare const Maybe: {
|
|
|
902
1114
|
* if (!r.ok) throw new Error(`${r.status} ${r.statusText}`);
|
|
903
1115
|
* return r.json() as Promise<User>;
|
|
904
1116
|
* }),
|
|
905
|
-
* (e) => new ApiError(e),
|
|
1117
|
+
* { onError: (e) => new ApiError(e) },
|
|
906
1118
|
* );
|
|
907
1119
|
*
|
|
908
1120
|
* const manager = Op.interpret(fetchUser, { strategy: "restartable" });
|
|
@@ -915,17 +1127,17 @@ declare const Maybe: {
|
|
|
915
1127
|
* manager.run(userId);
|
|
916
1128
|
* ```
|
|
917
1129
|
*/
|
|
918
|
-
type Op<
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
1130
|
+
type Op<Args extends readonly any[] = any[], E = unknown, A = unknown> = {
|
|
1131
|
+
readonly [_opBrand]: {
|
|
1132
|
+
readonly _args: (...args: Args) => void;
|
|
1133
|
+
readonly _error: () => E;
|
|
1134
|
+
readonly _value: () => A;
|
|
1135
|
+
};
|
|
924
1136
|
};
|
|
925
1137
|
type MaybeRetry<E, O> = O extends {
|
|
926
1138
|
retry: RetryOptions<E>;
|
|
927
1139
|
} ? Op.Retrying<E> : never;
|
|
928
|
-
type AllInterpretOptions<
|
|
1140
|
+
type AllInterpretOptions<Args extends readonly any[], E> = ({
|
|
929
1141
|
strategy: "once";
|
|
930
1142
|
retry?: RetryOptions<E>;
|
|
931
1143
|
} & WithTimeout<E>) | ({
|
|
@@ -939,7 +1151,7 @@ type AllInterpretOptions<I, E> = ({
|
|
|
939
1151
|
retry?: RetryOptions<E>;
|
|
940
1152
|
maxSize?: number;
|
|
941
1153
|
overflow?: "drop" | "replace-last";
|
|
942
|
-
dedupe?: (a:
|
|
1154
|
+
dedupe?: (a: Args, b: Args) => boolean;
|
|
943
1155
|
} & WithConcurrency & WithTimeout<E>) | ({
|
|
944
1156
|
strategy: "buffered";
|
|
945
1157
|
retry?: RetryOptions<E>;
|
|
@@ -959,53 +1171,53 @@ type AllInterpretOptions<I, E> = ({
|
|
|
959
1171
|
} & WithN & WithTimeout<E>) | ({
|
|
960
1172
|
strategy: "keyed";
|
|
961
1173
|
perKey?: "exclusive" | "restartable";
|
|
962
|
-
key: (
|
|
1174
|
+
key: (...args: Args) => unknown;
|
|
963
1175
|
} & WithTimeout<E>);
|
|
964
|
-
type KeyType<
|
|
965
|
-
key: (
|
|
1176
|
+
type KeyType<Args extends readonly any[], O> = O extends {
|
|
1177
|
+
key: (...args: Args) => infer K;
|
|
966
1178
|
} ? K : unknown;
|
|
967
|
-
type InterpretResult<
|
|
1179
|
+
type InterpretResult<Args extends readonly any[], E, A, O> = [O] extends [{
|
|
968
1180
|
strategy: "throttled";
|
|
969
1181
|
trailing: true;
|
|
970
|
-
}] ? Op.Manager<
|
|
1182
|
+
}] ? Op.Manager<Args, E, A, Op.ThrottledTrailingState<E, A> | MaybeRetry<E, O>> : [O] extends [{
|
|
971
1183
|
strategy: "throttled";
|
|
972
|
-
}] ? Op.Manager<
|
|
1184
|
+
}] ? Op.Manager<Args, E, A, Op.ThrottledState<E, A> | MaybeRetry<E, O>> : [O] extends [{
|
|
973
1185
|
strategy: "debounced";
|
|
974
|
-
}] ? Op.Manager<
|
|
1186
|
+
}] ? Op.Manager<Args, E, A, Op.DebouncedState<E, A> | MaybeRetry<E, O>> : [O] extends [{
|
|
975
1187
|
strategy: "concurrent";
|
|
976
1188
|
overflow: "queue";
|
|
977
|
-
}] ? Op.Manager<
|
|
1189
|
+
}] ? Op.Manager<Args, E, A, Op.ConcurrentQueueState<E, A> | MaybeRetry<E, O>> : [O] extends [{
|
|
978
1190
|
strategy: "concurrent";
|
|
979
|
-
}] ? Op.Manager<
|
|
1191
|
+
}] ? Op.Manager<Args, E, A, Op.ConcurrentDropState<E, A> | MaybeRetry<E, O>> : [O] extends [{
|
|
980
1192
|
strategy: "keyed";
|
|
981
1193
|
perKey: "restartable";
|
|
982
|
-
}] ? Op.KeyedManager<
|
|
1194
|
+
}] ? Op.KeyedManager<Args, KeyType<Args, O>, E, Op.KeyedRestartablePerKey<E, A>> : [O] extends [{
|
|
983
1195
|
strategy: "keyed";
|
|
984
|
-
}] ? Op.KeyedManager<
|
|
1196
|
+
}] ? Op.KeyedManager<Args, KeyType<Args, O>, E, Op.KeyedExclusivePerKey<E, A>> : [O] extends [{
|
|
985
1197
|
strategy: "once";
|
|
986
|
-
}] ? Op.Manager<
|
|
1198
|
+
}] ? Op.Manager<Args, E, A, Op.OnceState<E, A> | MaybeRetry<E, O>> : [O] extends [{
|
|
987
1199
|
strategy: "restartable";
|
|
988
|
-
}] ? Op.Manager<
|
|
1200
|
+
}] ? Op.Manager<Args, E, A, Op.RestartableState<E, A> | MaybeRetry<E, O>> : [O] extends [{
|
|
989
1201
|
strategy: "exclusive";
|
|
990
|
-
}] ? Op.Manager<
|
|
1202
|
+
}] ? Op.Manager<Args, E, A, Op.ExclusiveState<E, A> | MaybeRetry<E, O>> : [O] extends [{
|
|
991
1203
|
strategy: "queue";
|
|
992
1204
|
overflow: "replace-last";
|
|
993
|
-
dedupe: (a:
|
|
994
|
-
}] ? Op.Manager<
|
|
1205
|
+
dedupe: (a: Args, b: Args) => boolean;
|
|
1206
|
+
}] ? Op.Manager<Args, E, A, Op.QueueDropAndReplaceState<E, A> | MaybeRetry<E, O>> : [O] extends [{
|
|
995
1207
|
strategy: "queue";
|
|
996
1208
|
overflow: "replace-last";
|
|
997
|
-
}] ? Op.Manager<
|
|
1209
|
+
}] ? Op.Manager<Args, E, A, Op.QueueReplaceState<E, A> | MaybeRetry<E, O>> : [O] extends [{
|
|
998
1210
|
strategy: "queue";
|
|
999
1211
|
maxSize: number;
|
|
1000
|
-
}] ? Op.Manager<
|
|
1212
|
+
}] ? Op.Manager<Args, E, A, Op.QueueDropState<E, A> | MaybeRetry<E, O>> : [O] extends [{
|
|
1001
1213
|
strategy: "queue";
|
|
1002
|
-
dedupe: (a:
|
|
1003
|
-
}] ? Op.Manager<
|
|
1214
|
+
dedupe: (a: Args, b: Args) => boolean;
|
|
1215
|
+
}] ? Op.Manager<Args, E, A, Op.QueueDropState<E, A> | MaybeRetry<E, O>> : [O] extends [{
|
|
1004
1216
|
strategy: "queue";
|
|
1005
|
-
}] ? Op.Manager<
|
|
1217
|
+
}] ? Op.Manager<Args, E, A, Op.QueueState<E, A> | MaybeRetry<E, O>> : [O] extends [{
|
|
1006
1218
|
strategy: "buffered";
|
|
1007
|
-
}] ? Op.Manager<
|
|
1008
|
-
declare function interpretFn<
|
|
1219
|
+
}] ? Op.Manager<Args, E, A, Op.BufferedState<E, A> | MaybeRetry<E, O>> : never;
|
|
1220
|
+
declare function interpretFn<Args extends readonly any[], E, A, O extends AllInterpretOptions<Args, E>>(op: Op<Args, E, A>, options: O): InterpretResult<Args, E, A, O>;
|
|
1009
1221
|
declare const Op: {
|
|
1010
1222
|
make: {
|
|
1011
1223
|
/**
|
|
@@ -1115,8 +1327,24 @@ declare const Op: {
|
|
|
1115
1327
|
*/
|
|
1116
1328
|
nil: <E, A>(state: Op.State<E, A>) => state is Op.Nil;
|
|
1117
1329
|
};
|
|
1118
|
-
|
|
1119
|
-
|
|
1330
|
+
/**
|
|
1331
|
+
* Creates an Op from a signal-accepting factory function that returns the async action,
|
|
1332
|
+
* along with an error mapping handler.
|
|
1333
|
+
*
|
|
1334
|
+
* Arguments to the returned function are automatically inferred as tuple parameters via `Parameters<Fn>`.
|
|
1335
|
+
*
|
|
1336
|
+
* @example
|
|
1337
|
+
* ```ts
|
|
1338
|
+
* const fetchUser = Op.create(
|
|
1339
|
+
* (signal) => (id: string) => fetch(`/users/${id}`, { signal }).then(r => r.json() as Promise<User>),
|
|
1340
|
+
* { onError: (e) => new ApiError(e) },
|
|
1341
|
+
* );
|
|
1342
|
+
* ```
|
|
1343
|
+
*/
|
|
1344
|
+
create: <Fn extends (...args: any[]) => Promise<any>, E = unknown>(factory: (signal: AbortSignal) => Fn, options: {
|
|
1345
|
+
onError: (error: unknown) => E;
|
|
1346
|
+
}) => Op<Parameters<Fn>, E, Awaited<ReturnType<Fn>>>;
|
|
1347
|
+
lift: <Fn extends (...args: any[]) => Promise<any>>(f: (signal: AbortSignal) => Fn) => Op<Parameters<Fn>, unknown, Awaited<ReturnType<Fn>>>;
|
|
1120
1348
|
match: <E, A, B>(cases: {
|
|
1121
1349
|
ok: (a: A) => B;
|
|
1122
1350
|
err: (e: E) => B;
|
|
@@ -1135,7 +1363,7 @@ declare const Op: {
|
|
|
1135
1363
|
};
|
|
1136
1364
|
all: <E, A>(invocations: ReadonlyArray<Deferred<Op.Outcome<E, A>>>) => Deferred<ReadonlyArray<Op.Outcome<E, A>>>;
|
|
1137
1365
|
race: <E, A>(invocations: ReadonlyArray<Deferred<Op.Outcome<E, A>>>) => Deferred<Op.Outcome<E, A>>;
|
|
1138
|
-
wire: <
|
|
1366
|
+
wire: <Args extends readonly any[], E, A, S extends Op.State<E, A>>(source: Op.Manager<Args, E, A, S>, f: (a: A) => void) => () => void;
|
|
1139
1367
|
interpret: typeof interpretFn;
|
|
1140
1368
|
};
|
|
1141
1369
|
declare namespace Op {
|
|
@@ -1169,25 +1397,25 @@ declare namespace Op {
|
|
|
1169
1397
|
readonly lastError: E;
|
|
1170
1398
|
readonly nextRetryIn?: number;
|
|
1171
1399
|
};
|
|
1172
|
-
type Manager<
|
|
1400
|
+
type Manager<Args extends readonly any[], E, A, S extends State<E, A>> = {
|
|
1173
1401
|
readonly state: S;
|
|
1174
|
-
run: (
|
|
1402
|
+
run: (...args: Args) => Deferred<Exclude<S, Idle | Pending | Queued | Retrying<E>>>;
|
|
1175
1403
|
abort: () => void;
|
|
1176
1404
|
subscribe: (cb: (state: S) => void) => () => void;
|
|
1177
1405
|
reset: () => void;
|
|
1178
|
-
poll: (
|
|
1406
|
+
poll: (options: {
|
|
1179
1407
|
interval: Duration;
|
|
1180
|
-
}) => () => void;
|
|
1408
|
+
}) => (...args: Args) => () => void;
|
|
1181
1409
|
};
|
|
1182
|
-
type KeyedManager<
|
|
1410
|
+
type KeyedManager<Args extends readonly any[], K, E, PerKeyS> = {
|
|
1183
1411
|
readonly state: ReadonlyMap<K, PerKeyS>;
|
|
1184
|
-
run: (
|
|
1412
|
+
run: (...args: Args) => Deferred<Exclude<PerKeyS, Pending | Retrying<E>>>;
|
|
1185
1413
|
abort: (key?: K) => void;
|
|
1186
1414
|
subscribe: (cb: (state: ReadonlyMap<K, PerKeyS>) => void) => () => void;
|
|
1187
1415
|
reset: () => void;
|
|
1188
|
-
poll: (
|
|
1416
|
+
poll: (options: {
|
|
1189
1417
|
interval: Duration;
|
|
1190
|
-
}) => () => void;
|
|
1418
|
+
}) => (...args: Args) => () => void;
|
|
1191
1419
|
};
|
|
1192
1420
|
type OnceState<E, A> = Idle | Pending | Ok<A> | Err<E> | AbortedNil | DroppedNil;
|
|
1193
1421
|
type RetryableOnceState<E, A> = Idle | Pending | Retrying<E> | Ok<A> | Err<E> | AbortedNil | DroppedNil;
|
|
@@ -1491,7 +1719,7 @@ declare const Ordering: {
|
|
|
1491
1719
|
* import { Pair } from "@nlozgachev/pipelined/core";
|
|
1492
1720
|
* import { pipe } from "@nlozgachev/pipelined/composition";
|
|
1493
1721
|
*
|
|
1494
|
-
* const entry = Pair.
|
|
1722
|
+
* const entry = Pair.make("alice", 42);
|
|
1495
1723
|
*
|
|
1496
1724
|
* pipe(
|
|
1497
1725
|
* entry,
|
|
@@ -1503,16 +1731,16 @@ declare const Ordering: {
|
|
|
1503
1731
|
*/
|
|
1504
1732
|
type Pair<A, B> = readonly [A, B];
|
|
1505
1733
|
declare const Pair: {
|
|
1734
|
+
/**
|
|
1735
|
+
* Creates a Pair from two values.
|
|
1736
|
+
*
|
|
1737
|
+
* @example
|
|
1738
|
+
* ```ts
|
|
1739
|
+
* Pair.make("Paris", 2_161_000); // ["Paris", 2161000]
|
|
1740
|
+
* ```
|
|
1741
|
+
*/
|
|
1742
|
+
make: <A, B>(first: A, second: B) => Pair<A, B>;
|
|
1506
1743
|
from: {
|
|
1507
|
-
/**
|
|
1508
|
-
* Creates a Pair from two values.
|
|
1509
|
-
*
|
|
1510
|
-
* @example
|
|
1511
|
-
* ```ts
|
|
1512
|
-
* Pair.from.pair("Paris", 2_161_000); // ["Paris", 2161000]
|
|
1513
|
-
* ```
|
|
1514
|
-
*/
|
|
1515
|
-
pair: <A, B>(first: A, second: B) => Pair<A, B>;
|
|
1516
1744
|
/**
|
|
1517
1745
|
* Creates a Pair from a two-element array.
|
|
1518
1746
|
*
|
|
@@ -1521,51 +1749,60 @@ declare const Pair: {
|
|
|
1521
1749
|
* Pair.from.array(["Paris", 2_161_000] as const); // ["Paris", 2161000]
|
|
1522
1750
|
* ```
|
|
1523
1751
|
*/
|
|
1524
|
-
array: <A, B>(
|
|
1752
|
+
array: <A, B>(items: readonly [A, B]) => Pair<A, B>;
|
|
1525
1753
|
};
|
|
1526
1754
|
/**
|
|
1527
1755
|
* Returns the first value from the pair.
|
|
1528
1756
|
*
|
|
1529
1757
|
* @example
|
|
1530
1758
|
* ```ts
|
|
1531
|
-
* Pair.first(Pair.
|
|
1759
|
+
* Pair.first(Pair.make("Paris", 2_161_000)); // "Paris"
|
|
1532
1760
|
* ```
|
|
1533
1761
|
*/
|
|
1534
|
-
first: <A, B>(
|
|
1762
|
+
first: <A, B>(pair: Pair<A, B>) => A;
|
|
1535
1763
|
/**
|
|
1536
1764
|
* Returns the second value from the pair.
|
|
1537
1765
|
*
|
|
1538
1766
|
* @example
|
|
1539
1767
|
* ```ts
|
|
1540
|
-
* Pair.second(Pair.
|
|
1768
|
+
* Pair.second(Pair.make("Paris", 2_161_000)); // 2161000
|
|
1541
1769
|
* ```
|
|
1542
1770
|
*/
|
|
1543
|
-
second: <A, B>(
|
|
1771
|
+
second: <A, B>(pair: Pair<A, B>) => B;
|
|
1544
1772
|
/**
|
|
1545
1773
|
* Transforms the first value, leaving the second unchanged.
|
|
1546
1774
|
*
|
|
1775
|
+
* @see {@link Pair.mapSecond} to transform the second element instead.
|
|
1776
|
+
* @see {@link Pair.mapBoth} to transform both elements at once.
|
|
1777
|
+
*
|
|
1547
1778
|
* @example
|
|
1548
1779
|
* ```ts
|
|
1549
|
-
* pipe(Pair.
|
|
1780
|
+
* pipe(Pair.make("alice", 42), Pair.mapFirst((s) => s.toUpperCase())); // ["ALICE", 42]
|
|
1550
1781
|
* ```
|
|
1551
1782
|
*/
|
|
1552
|
-
mapFirst: <A, C>(
|
|
1783
|
+
mapFirst: <A, C>(transform: (first: A) => C) => <B>(pair: Pair<A, B>) => Pair<C, B>;
|
|
1553
1784
|
/**
|
|
1554
1785
|
* Transforms the second value, leaving the first unchanged.
|
|
1555
1786
|
*
|
|
1787
|
+
* @see {@link Pair.mapFirst} to transform the first element instead.
|
|
1788
|
+
* @see {@link Pair.mapBoth} to transform both elements at once.
|
|
1789
|
+
*
|
|
1556
1790
|
* @example
|
|
1557
1791
|
* ```ts
|
|
1558
|
-
* pipe(Pair.
|
|
1792
|
+
* pipe(Pair.make("alice", 42), Pair.mapSecond((n) => n * 2)); // ["alice", 84]
|
|
1559
1793
|
* ```
|
|
1560
1794
|
*/
|
|
1561
|
-
mapSecond: <B, D>(
|
|
1795
|
+
mapSecond: <B, D>(transform: (second: B) => D) => <A>(pair: Pair<A, B>) => Pair<A, D>;
|
|
1562
1796
|
/**
|
|
1563
1797
|
* Transforms both values independently in a single step.
|
|
1564
1798
|
*
|
|
1799
|
+
* @see {@link Pair.mapFirst} to transform only the first element.
|
|
1800
|
+
* @see {@link Pair.mapSecond} to transform only the second element.
|
|
1801
|
+
*
|
|
1565
1802
|
* @example
|
|
1566
1803
|
* ```ts
|
|
1567
1804
|
* pipe(
|
|
1568
|
-
* Pair.
|
|
1805
|
+
* Pair.make("alice", 42),
|
|
1569
1806
|
* Pair.mapBoth(
|
|
1570
1807
|
* (name) => name.toUpperCase(),
|
|
1571
1808
|
* (score) => score * 2,
|
|
@@ -1573,37 +1810,37 @@ declare const Pair: {
|
|
|
1573
1810
|
* ); // ["ALICE", 84]
|
|
1574
1811
|
* ```
|
|
1575
1812
|
*/
|
|
1576
|
-
mapBoth: <A, C, B, D>(onFirst: (
|
|
1813
|
+
mapBoth: <A, C, B, D>(onFirst: (first: A) => C, onSecond: (second: B) => D) => (pair: Pair<A, B>) => Pair<C, D>;
|
|
1577
1814
|
/**
|
|
1578
1815
|
* Applies a binary function to both values, collapsing the pair into a single value.
|
|
1579
1816
|
* Useful as the final step when consuming a pair in a pipeline.
|
|
1580
1817
|
*
|
|
1581
1818
|
* @example
|
|
1582
1819
|
* ```ts
|
|
1583
|
-
* pipe(Pair.
|
|
1820
|
+
* pipe(Pair.make("Alice", 100), Pair.fold((name, score) => `${name}: ${score}`));
|
|
1584
1821
|
* // "Alice: 100"
|
|
1585
1822
|
* ```
|
|
1586
1823
|
*/
|
|
1587
|
-
fold: <A, B, C>(
|
|
1824
|
+
fold: <A, B, C>(reducer: (first: A, second: B) => C) => (pair: Pair<A, B>) => C;
|
|
1588
1825
|
/**
|
|
1589
1826
|
* Swaps the two values: `[A, B]` becomes `[B, A]`.
|
|
1590
1827
|
*
|
|
1591
1828
|
* @example
|
|
1592
1829
|
* ```ts
|
|
1593
|
-
* Pair.swap(Pair.
|
|
1830
|
+
* Pair.swap(Pair.make("key", 1)); // [1, "key"]
|
|
1594
1831
|
* ```
|
|
1595
1832
|
*/
|
|
1596
|
-
swap: <A, B>(
|
|
1833
|
+
swap: <A, B>(pair: Pair<A, B>) => Pair<B, A>;
|
|
1597
1834
|
to: {
|
|
1598
1835
|
/**
|
|
1599
1836
|
* Converts the pair to a heterogeneous readonly array `readonly (A | B)[]`.
|
|
1600
1837
|
*
|
|
1601
1838
|
* @example
|
|
1602
1839
|
* ```ts
|
|
1603
|
-
* Pair.to.
|
|
1840
|
+
* Pair.to.array(Pair.make("hello", 42)); // ["hello", 42]
|
|
1604
1841
|
* ```
|
|
1605
1842
|
*/
|
|
1606
|
-
|
|
1843
|
+
array: <A, B>(pair: Pair<A, B>) => readonly (A | B)[];
|
|
1607
1844
|
};
|
|
1608
1845
|
/**
|
|
1609
1846
|
* Runs a side effect with both values without changing the pair.
|
|
@@ -1612,13 +1849,13 @@ declare const Pair: {
|
|
|
1612
1849
|
* @example
|
|
1613
1850
|
* ```ts
|
|
1614
1851
|
* pipe(
|
|
1615
|
-
* Pair.
|
|
1852
|
+
* Pair.make("Paris", 2_161_000),
|
|
1616
1853
|
* Pair.tap((city, pop) => console.log(`${city}: ${pop}`)),
|
|
1617
1854
|
* Pair.mapSecond((n) => n / 1_000_000),
|
|
1618
1855
|
* ); // logs "Paris: 2161000", returns ["Paris", 2.161]
|
|
1619
1856
|
* ```
|
|
1620
1857
|
*/
|
|
1621
|
-
tap: <A, B>(
|
|
1858
|
+
tap: <A, B>(sideEffect: (first: A, second: B) => void) => (pair: Pair<A, B>) => Pair<A, B>;
|
|
1622
1859
|
};
|
|
1623
1860
|
//#endregion
|
|
1624
1861
|
//#region src/Core/Predicate.d.ts
|
|
@@ -1905,12 +2142,12 @@ declare const Reader: {
|
|
|
1905
2142
|
* const add = (a: number) => (b: number) => a + b;
|
|
1906
2143
|
* pipe(
|
|
1907
2144
|
* Reader.resolve<Config, typeof add>(add),
|
|
1908
|
-
* Reader.
|
|
1909
|
-
* Reader.
|
|
2145
|
+
* Reader.apply(Reader.asks(c => c.timeout)),
|
|
2146
|
+
* Reader.apply(Reader.resolve(5))
|
|
1910
2147
|
* )(appConfig);
|
|
1911
2148
|
* ```
|
|
1912
2149
|
*/
|
|
1913
|
-
|
|
2150
|
+
apply: <R, A>(arg: Reader<R, A>) => <B>(data: Reader<R, (a: A) => B>) => Reader<R, B>;
|
|
1914
2151
|
/**
|
|
1915
2152
|
* Executes a side effect on the produced value without changing the Reader.
|
|
1916
2153
|
* Useful for logging or debugging inside a pipeline.
|
|
@@ -2199,7 +2436,7 @@ declare const RemoteData: {
|
|
|
2199
2436
|
* }
|
|
2200
2437
|
* ```
|
|
2201
2438
|
*/
|
|
2202
|
-
notAsked: <E, A>(
|
|
2439
|
+
notAsked: <E, A>(remoteData: RemoteData<E, A>) => remoteData is NotAsked;
|
|
2203
2440
|
/**
|
|
2204
2441
|
* Type guard that checks if a RemoteData is Loading.
|
|
2205
2442
|
*
|
|
@@ -2211,10 +2448,12 @@ declare const RemoteData: {
|
|
|
2211
2448
|
* }
|
|
2212
2449
|
* ```
|
|
2213
2450
|
*/
|
|
2214
|
-
loading: <E, A>(
|
|
2451
|
+
loading: <E, A>(remoteData: RemoteData<E, A>) => remoteData is Loading;
|
|
2215
2452
|
/**
|
|
2216
2453
|
* Type guard that checks if a RemoteData is Failure.
|
|
2217
2454
|
*
|
|
2455
|
+
* @see {@link RemoteData.is.success} to check if data loaded successfully.
|
|
2456
|
+
*
|
|
2218
2457
|
* @example
|
|
2219
2458
|
* ```ts
|
|
2220
2459
|
* const data = RemoteData.make.failure("Failed");
|
|
@@ -2223,10 +2462,12 @@ declare const RemoteData: {
|
|
|
2223
2462
|
* }
|
|
2224
2463
|
* ```
|
|
2225
2464
|
*/
|
|
2226
|
-
failure: <E, A>(
|
|
2465
|
+
failure: <E, A>(remoteData: RemoteData<E, A>) => remoteData is Failure<E>;
|
|
2227
2466
|
/**
|
|
2228
2467
|
* Type guard that checks if a RemoteData is Success.
|
|
2229
2468
|
*
|
|
2469
|
+
* @see {@link RemoteData.is.failure} to check if data loading failed.
|
|
2470
|
+
*
|
|
2230
2471
|
* @example
|
|
2231
2472
|
* ```ts
|
|
2232
2473
|
* const data = RemoteData.make.success(42);
|
|
@@ -2235,31 +2476,38 @@ declare const RemoteData: {
|
|
|
2235
2476
|
* }
|
|
2236
2477
|
* ```
|
|
2237
2478
|
*/
|
|
2238
|
-
success: <E, A>(
|
|
2479
|
+
success: <E, A>(remoteData: RemoteData<E, A>) => remoteData is Success<A>;
|
|
2239
2480
|
};
|
|
2240
2481
|
/**
|
|
2241
2482
|
* Transforms the success value inside a RemoteData.
|
|
2242
2483
|
*
|
|
2484
|
+
* @see {@link RemoteData.chain} to sequence operations that themselves return a RemoteData.
|
|
2485
|
+
* @see {@link RemoteData.mapError} to transform the error value instead of the success value.
|
|
2486
|
+
*
|
|
2243
2487
|
* @example
|
|
2244
2488
|
* ```ts
|
|
2245
2489
|
* pipe(RemoteData.make.success(5), RemoteData.map(n => n * 2)); // Success(10)
|
|
2246
2490
|
* pipe(RemoteData.make.loading(), RemoteData.map(n => n * 2)); // Loading
|
|
2247
2491
|
* ```
|
|
2248
2492
|
*/
|
|
2249
|
-
map: <A, B>(
|
|
2493
|
+
map: <A, B>(transform: (value: A) => B) => <E>(remoteData: RemoteData<E, A>) => RemoteData<E, B>;
|
|
2250
2494
|
/**
|
|
2251
2495
|
* Transforms the error value inside a RemoteData.
|
|
2252
2496
|
*
|
|
2497
|
+
* @see {@link RemoteData.map} to transform the success value instead of the error value.
|
|
2498
|
+
*
|
|
2253
2499
|
* @example
|
|
2254
2500
|
* ```ts
|
|
2255
2501
|
* pipe(RemoteData.make.failure("oops"), RemoteData.mapError(e => e.toUpperCase())); // Failure("OOPS")
|
|
2256
2502
|
* ```
|
|
2257
2503
|
*/
|
|
2258
|
-
mapError: <E, F>(
|
|
2504
|
+
mapError: <E, F>(transform: (error: E) => F) => <A>(remoteData: RemoteData<E, A>) => RemoteData<F, A>;
|
|
2259
2505
|
/**
|
|
2260
|
-
* Chains RemoteData computations. If the input is Success, passes the value to
|
|
2506
|
+
* Chains RemoteData computations. If the input is Success, passes the value to transform.
|
|
2261
2507
|
* Otherwise, propagates the current state.
|
|
2262
2508
|
*
|
|
2509
|
+
* @see {@link RemoteData.map} to transform the success value without returning a new RemoteData.
|
|
2510
|
+
*
|
|
2263
2511
|
* @example
|
|
2264
2512
|
* ```ts
|
|
2265
2513
|
* pipe(
|
|
@@ -2268,7 +2516,7 @@ declare const RemoteData: {
|
|
|
2268
2516
|
* );
|
|
2269
2517
|
* ```
|
|
2270
2518
|
*/
|
|
2271
|
-
chain: <E2, A, B>(
|
|
2519
|
+
chain: <E2, A, B>(transform: (value: A) => RemoteData<E2, B>) => <E1 = never>(remoteData: RemoteData<E1, A>) => RemoteData<E1 | E2, B>;
|
|
2272
2520
|
/**
|
|
2273
2521
|
* Applies a function wrapped in a RemoteData to a value wrapped in a RemoteData.
|
|
2274
2522
|
*
|
|
@@ -2277,21 +2525,23 @@ declare const RemoteData: {
|
|
|
2277
2525
|
* const add = (a: number) => (b: number) => a + b;
|
|
2278
2526
|
* pipe(
|
|
2279
2527
|
* RemoteData.make.success(add),
|
|
2280
|
-
* RemoteData.
|
|
2281
|
-
* RemoteData.
|
|
2528
|
+
* RemoteData.apply(RemoteData.make.success(5)),
|
|
2529
|
+
* RemoteData.apply(RemoteData.make.success(3))
|
|
2282
2530
|
* ); // Success(8)
|
|
2283
2531
|
* ```
|
|
2284
2532
|
*/
|
|
2285
|
-
|
|
2533
|
+
apply: <E2, A>(arg: RemoteData<E2, A>) => <E1, B>(remoteData: RemoteData<E1, (value: A) => B>) => RemoteData<E1 | E2, B>;
|
|
2286
2534
|
/**
|
|
2287
2535
|
* Extracts the value from a RemoteData by providing handlers for all four cases.
|
|
2288
2536
|
*
|
|
2537
|
+
* @see {@link RemoteData.match} for named-case pattern matching with an object literal.
|
|
2538
|
+
*
|
|
2289
2539
|
* @example
|
|
2290
2540
|
* ```ts
|
|
2291
2541
|
* pipe(
|
|
2292
2542
|
* userData,
|
|
2293
2543
|
* RemoteData.fold(
|
|
2294
|
-
*
|
|
2544
|
+
* error => `Error: ${error}`,
|
|
2295
2545
|
* () => "Not asked",
|
|
2296
2546
|
* () => "Loading...",
|
|
2297
2547
|
* value => `Got: ${value}`
|
|
@@ -2299,10 +2549,12 @@ declare const RemoteData: {
|
|
|
2299
2549
|
* );
|
|
2300
2550
|
* ```
|
|
2301
2551
|
*/
|
|
2302
|
-
fold: <E, A, B>(onFailure: (
|
|
2552
|
+
fold: <E, A, B>(onFailure: (error: E) => B, onNotAsked: () => B, onLoading: () => B, onSuccess: (value: A) => B) => (remoteData: RemoteData<E, A>) => B;
|
|
2303
2553
|
/**
|
|
2304
2554
|
* Pattern matches on a RemoteData, returning the result of the matching case.
|
|
2305
2555
|
*
|
|
2556
|
+
* @see {@link RemoteData.fold} for positional argument pattern matching.
|
|
2557
|
+
*
|
|
2306
2558
|
* @example
|
|
2307
2559
|
* ```ts
|
|
2308
2560
|
* pipe(
|
|
@@ -2310,7 +2562,7 @@ declare const RemoteData: {
|
|
|
2310
2562
|
* RemoteData.match({
|
|
2311
2563
|
* notAsked: () => "Click to load",
|
|
2312
2564
|
* loading: () => "Loading...",
|
|
2313
|
-
* failure:
|
|
2565
|
+
* failure: error => `Error: ${error}`,
|
|
2314
2566
|
* success: user => `Hello, ${user.name}!`
|
|
2315
2567
|
* })
|
|
2316
2568
|
* );
|
|
@@ -2319,13 +2571,15 @@ declare const RemoteData: {
|
|
|
2319
2571
|
match: <E, A, B>(cases: {
|
|
2320
2572
|
notAsked: () => B;
|
|
2321
2573
|
loading: () => B;
|
|
2322
|
-
failure: (
|
|
2323
|
-
success: (
|
|
2324
|
-
}) => (
|
|
2574
|
+
failure: (error: E) => B;
|
|
2575
|
+
success: (value: A) => B;
|
|
2576
|
+
}) => (remoteData: RemoteData<E, A>) => B;
|
|
2325
2577
|
/**
|
|
2326
2578
|
* Returns the success value or a default value if the RemoteData is not Success.
|
|
2327
2579
|
* The default can be a different type, widening the result to `A | B`.
|
|
2328
2580
|
*
|
|
2581
|
+
* @see {@link RemoteData.fold} to handle all four lifecycle states.
|
|
2582
|
+
*
|
|
2329
2583
|
* @example
|
|
2330
2584
|
* ```ts
|
|
2331
2585
|
* pipe(RemoteData.make.success(5), RemoteData.getOrElse(() => 0)); // 5
|
|
@@ -2333,10 +2587,12 @@ declare const RemoteData: {
|
|
|
2333
2587
|
* pipe(RemoteData.make.loading<string, number>(), RemoteData.getOrElse(() => null)); // null — typed as number | null
|
|
2334
2588
|
* ```
|
|
2335
2589
|
*/
|
|
2336
|
-
getOrElse: <B>(
|
|
2590
|
+
getOrElse: <B>(fallback: () => B) => <E, A>(remoteData: RemoteData<E, A>) => A | B;
|
|
2337
2591
|
/**
|
|
2338
2592
|
* Executes a side effect on the success value without changing the RemoteData.
|
|
2339
2593
|
*
|
|
2594
|
+
* @see {@link RemoteData.tapError} to perform a side effect on the failure error.
|
|
2595
|
+
*
|
|
2340
2596
|
* @example
|
|
2341
2597
|
* ```ts
|
|
2342
2598
|
* pipe(
|
|
@@ -2346,11 +2602,13 @@ declare const RemoteData: {
|
|
|
2346
2602
|
* );
|
|
2347
2603
|
* ```
|
|
2348
2604
|
*/
|
|
2349
|
-
tap: <E, A>(
|
|
2605
|
+
tap: <E, A>(sideEffect: (value: A) => void) => (remoteData: RemoteData<E, A>) => RemoteData<E, A>;
|
|
2350
2606
|
/**
|
|
2351
2607
|
* Executes a side effect on the failure error without changing the RemoteData.
|
|
2352
2608
|
* Useful for logging errors.
|
|
2353
2609
|
*
|
|
2610
|
+
* @see {@link RemoteData.tap} to perform a side effect on the success value.
|
|
2611
|
+
*
|
|
2354
2612
|
* @example
|
|
2355
2613
|
* ```ts
|
|
2356
2614
|
* pipe(
|
|
@@ -2360,18 +2618,18 @@ declare const RemoteData: {
|
|
|
2360
2618
|
* );
|
|
2361
2619
|
* ```
|
|
2362
2620
|
*/
|
|
2363
|
-
tapError: <E, A>(
|
|
2621
|
+
tapError: <E, A>(sideEffect: (error: E) => void) => (remoteData: RemoteData<E, A>) => RemoteData<E, A>;
|
|
2364
2622
|
/**
|
|
2365
2623
|
* Recovers from a Failure state by providing a fallback RemoteData.
|
|
2366
|
-
* The fallback can produce a different success type
|
|
2624
|
+
* The fallback can produce a different success type or resolve with a different error type.
|
|
2367
2625
|
*/
|
|
2368
|
-
recover: <
|
|
2626
|
+
recover: <E1, E2, B>(fallback: (error: E1) => RemoteData<E2, B>) => <A>(remoteData: RemoteData<E1, A>) => RemoteData<E2, A | B>;
|
|
2369
2627
|
to: {
|
|
2370
2628
|
/**
|
|
2371
2629
|
* Converts a RemoteData to a Maybe.
|
|
2372
2630
|
* Success becomes Some, all other states become None.
|
|
2373
2631
|
*/
|
|
2374
|
-
Maybe: <E, A>(
|
|
2632
|
+
Maybe: <E, A>(remoteData: RemoteData<E, A>) => Maybe<A>;
|
|
2375
2633
|
/**
|
|
2376
2634
|
* Converts a RemoteData to a Result.
|
|
2377
2635
|
* Success becomes Ok, Failure becomes Err.
|
|
@@ -2385,7 +2643,7 @@ declare const RemoteData: {
|
|
|
2385
2643
|
* ); // Ok(42)
|
|
2386
2644
|
* ```
|
|
2387
2645
|
*/
|
|
2388
|
-
Result: <E>(onNotReady: () => E) => <A>(
|
|
2646
|
+
Result: <E>(onNotReady: () => E) => <A>(remoteData: RemoteData<E, A>) => Result<E, A>;
|
|
2389
2647
|
};
|
|
2390
2648
|
from: {
|
|
2391
2649
|
/**
|
|
@@ -2398,7 +2656,7 @@ declare const RemoteData: {
|
|
|
2398
2656
|
* setState(RemoteData.from.Result(result)); // Success(user) or Failure(msg)
|
|
2399
2657
|
* ```
|
|
2400
2658
|
*/
|
|
2401
|
-
Result: <E, A>(
|
|
2659
|
+
Result: <E, A>(result: Result<E, A>) => RemoteData<E, A>;
|
|
2402
2660
|
/**
|
|
2403
2661
|
* Converts a Maybe to a RemoteData.
|
|
2404
2662
|
* Some becomes Success, None becomes Failure using the onNone error producer.
|
|
@@ -2409,7 +2667,7 @@ declare const RemoteData: {
|
|
|
2409
2667
|
* pipe(Maybe.make.none(), RemoteData.from.Maybe(() => "not found")); // Failure("not found")
|
|
2410
2668
|
* ```
|
|
2411
2669
|
*/
|
|
2412
|
-
Maybe: <E>(onNone: () => E) => <A>(
|
|
2670
|
+
Maybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => RemoteData<E, A>;
|
|
2413
2671
|
};
|
|
2414
2672
|
/**
|
|
2415
2673
|
* Filters a `Success` value. When the predicate passes, the value is kept. When it fails,
|
|
@@ -2424,7 +2682,7 @@ declare const RemoteData: {
|
|
|
2424
2682
|
* RemoteData.filter(n => n > 0, () => "error")(RemoteData.make.loading()); // Loading
|
|
2425
2683
|
* ```
|
|
2426
2684
|
*/
|
|
2427
|
-
filter: <E, A>(
|
|
2685
|
+
filter: <E, A>(predicate: (value: A) => boolean, onFalse: (value: A) => E) => (remoteData: RemoteData<E, A>) => RemoteData<E, A>;
|
|
2428
2686
|
};
|
|
2429
2687
|
//#endregion
|
|
2430
2688
|
//#region src/Core/Resource.d.ts
|
|
@@ -2564,12 +2822,14 @@ declare const Result: {
|
|
|
2564
2822
|
* Result.make.err("Error message"); // Err("Error message")
|
|
2565
2823
|
* ```
|
|
2566
2824
|
*/
|
|
2567
|
-
err: <E>(
|
|
2825
|
+
err: <E>(error: E) => Err$1<E>;
|
|
2568
2826
|
};
|
|
2569
2827
|
is: {
|
|
2570
2828
|
/**
|
|
2571
2829
|
* Type guard that checks if a Result is Ok.
|
|
2572
2830
|
*
|
|
2831
|
+
* @see {@link Result.is.err} to check if a Result is an Err failure.
|
|
2832
|
+
*
|
|
2573
2833
|
* @example
|
|
2574
2834
|
* ```ts
|
|
2575
2835
|
* const res = Result.make.ok(42);
|
|
@@ -2578,10 +2838,12 @@ declare const Result: {
|
|
|
2578
2838
|
* }
|
|
2579
2839
|
* ```
|
|
2580
2840
|
*/
|
|
2581
|
-
ok: <E, A>(
|
|
2841
|
+
ok: <E, A>(result: Result<E, A>) => result is Ok$1<A>;
|
|
2582
2842
|
/**
|
|
2583
2843
|
* Type guard that checks if a Result is Err.
|
|
2584
2844
|
*
|
|
2845
|
+
* @see {@link Result.is.ok} to check if a Result is an Ok success.
|
|
2846
|
+
*
|
|
2585
2847
|
* @example
|
|
2586
2848
|
* ```ts
|
|
2587
2849
|
* const res = Result.make.err("failed");
|
|
@@ -2590,7 +2852,7 @@ declare const Result: {
|
|
|
2590
2852
|
* }
|
|
2591
2853
|
* ```
|
|
2592
2854
|
*/
|
|
2593
|
-
err: <E, A>(
|
|
2855
|
+
err: <E, A>(result: Result<E, A>) => result is Err$1<E>;
|
|
2594
2856
|
};
|
|
2595
2857
|
/**
|
|
2596
2858
|
* Creates a Result from a synchronous thunk that may throw.
|
|
@@ -2600,36 +2862,43 @@ declare const Result: {
|
|
|
2600
2862
|
* ```ts
|
|
2601
2863
|
* const result = Result.tryCatch(
|
|
2602
2864
|
* () => JSON.parse(rawString),
|
|
2603
|
-
* { onError: (
|
|
2865
|
+
* { onError: (error) => `Parse error: ${error}` }
|
|
2604
2866
|
* );
|
|
2605
2867
|
* ```
|
|
2606
2868
|
*/
|
|
2607
|
-
tryCatch: <E, A>(
|
|
2608
|
-
onError: (
|
|
2869
|
+
tryCatch: <E, A>(fn: () => A, options: {
|
|
2870
|
+
onError: (error: unknown) => E;
|
|
2609
2871
|
}) => Result<E, A>;
|
|
2610
2872
|
/**
|
|
2611
2873
|
* Transforms the success value inside a Result.
|
|
2612
2874
|
*
|
|
2875
|
+
* @see {@link Result.chain} to sequence operations that themselves return a Result.
|
|
2876
|
+
* @see {@link Result.mapError} to transform the error value instead of the success value.
|
|
2877
|
+
*
|
|
2613
2878
|
* @example
|
|
2614
2879
|
* ```ts
|
|
2615
2880
|
* pipe(Result.make.ok(5), Result.map(n => n * 2)); // Ok(10)
|
|
2616
2881
|
* pipe(Result.make.err("error"), Result.map(n => n * 2)); // Err("error")
|
|
2617
2882
|
* ```
|
|
2618
2883
|
*/
|
|
2619
|
-
map: <E, A, B>(
|
|
2884
|
+
map: <E, A, B>(transform: (value: A) => B) => (result: Result<E, A>) => Result<E, B>;
|
|
2620
2885
|
/**
|
|
2621
2886
|
* Transforms the error value inside a Result.
|
|
2622
2887
|
*
|
|
2888
|
+
* @see {@link Result.map} to transform the success value instead of the error value.
|
|
2889
|
+
*
|
|
2623
2890
|
* @example
|
|
2624
2891
|
* ```ts
|
|
2625
2892
|
* pipe(Result.make.err("oops"), Result.mapError(e => e.toUpperCase())); // Err("OOPS")
|
|
2626
2893
|
* ```
|
|
2627
2894
|
*/
|
|
2628
|
-
mapError: <E, F, A>(
|
|
2895
|
+
mapError: <E, F, A>(transform: (error: E) => F) => (result: Result<E, A>) => Result<F, A>;
|
|
2629
2896
|
/**
|
|
2630
|
-
* Chains Result computations. If the first is Ok, passes the value to
|
|
2897
|
+
* Chains Result computations. If the first is Ok, passes the value to transform.
|
|
2631
2898
|
* If the first is Err, propagates the error.
|
|
2632
2899
|
*
|
|
2900
|
+
* @see {@link Result.map} to transform the inner value without returning a new Result.
|
|
2901
|
+
*
|
|
2633
2902
|
* @example
|
|
2634
2903
|
* ```ts
|
|
2635
2904
|
* const validatePositive = (n: number): Result<string, number> =>
|
|
@@ -2639,25 +2908,29 @@ declare const Result: {
|
|
|
2639
2908
|
* pipe(Result.make.ok(-1), Result.chain(validatePositive)); // Err("Must be positive")
|
|
2640
2909
|
* ```
|
|
2641
2910
|
*/
|
|
2642
|
-
chain: <E2, A, B>(
|
|
2911
|
+
chain: <E2, A, B>(transform: (value: A) => Result<E2, B>) => <E1 = never>(result: Result<E1, A>) => Result<E1 | E2, B>;
|
|
2643
2912
|
/**
|
|
2644
2913
|
* Extracts the value from a Result by providing handlers for both cases.
|
|
2645
2914
|
*
|
|
2915
|
+
* @see {@link Result.match} for named-case pattern matching with an object literal.
|
|
2916
|
+
*
|
|
2646
2917
|
* @example
|
|
2647
2918
|
* ```ts
|
|
2648
2919
|
* pipe(
|
|
2649
2920
|
* Result.make.ok(5),
|
|
2650
2921
|
* Result.fold(
|
|
2651
|
-
*
|
|
2652
|
-
*
|
|
2922
|
+
* error => `Error: ${error}`,
|
|
2923
|
+
* value => `Value: ${value}`
|
|
2653
2924
|
* )
|
|
2654
2925
|
* ); // "Value: 5"
|
|
2655
2926
|
* ```
|
|
2656
2927
|
*/
|
|
2657
|
-
fold: <E, A, B>(onErr: (
|
|
2928
|
+
fold: <E, A, B>(onErr: (error: E) => B, onOk: (value: A) => B) => (result: Result<E, A>) => B;
|
|
2658
2929
|
/**
|
|
2659
2930
|
* Pattern matches on a Result, returning the result of the matching case.
|
|
2660
2931
|
*
|
|
2932
|
+
* @see {@link Result.fold} for positional argument pattern matching.
|
|
2933
|
+
*
|
|
2661
2934
|
* @example
|
|
2662
2935
|
* ```ts
|
|
2663
2936
|
* pipe(
|
|
@@ -2670,14 +2943,16 @@ declare const Result: {
|
|
|
2670
2943
|
* ```
|
|
2671
2944
|
*/
|
|
2672
2945
|
match: <E, A, B>(cases: {
|
|
2673
|
-
ok: (
|
|
2674
|
-
err: (
|
|
2675
|
-
}) => (
|
|
2946
|
+
ok: (value: A) => B;
|
|
2947
|
+
err: (error: E) => B;
|
|
2948
|
+
}) => (result: Result<E, A>) => B;
|
|
2676
2949
|
/**
|
|
2677
2950
|
* Returns the success value or a default value if the Result is an error.
|
|
2678
2951
|
* The default is a thunk `() => B` — evaluated only when the Result is Err.
|
|
2679
2952
|
* The default can be a different type, widening the result to `A | B`.
|
|
2680
2953
|
*
|
|
2954
|
+
* @see {@link Result.fold} to handle both the Ok and Err cases.
|
|
2955
|
+
*
|
|
2681
2956
|
* @example
|
|
2682
2957
|
* ```ts
|
|
2683
2958
|
* pipe(Result.make.ok(5), Result.getOrElse(() => 0)); // 5
|
|
@@ -2685,11 +2960,13 @@ declare const Result: {
|
|
|
2685
2960
|
* pipe(Result.make.err("error"), Result.getOrElse(() => null)); // null — typed as number | null
|
|
2686
2961
|
* ```
|
|
2687
2962
|
*/
|
|
2688
|
-
getOrElse: <B>(
|
|
2963
|
+
getOrElse: <B>(fallback: () => B) => <E, A>(result: Result<E, A>) => A | B;
|
|
2689
2964
|
/**
|
|
2690
2965
|
* Executes a side effect on the success value without changing the Result.
|
|
2691
2966
|
* Useful for logging or debugging.
|
|
2692
2967
|
*
|
|
2968
|
+
* @see {@link Result.tapError} to perform a side effect on the error value.
|
|
2969
|
+
*
|
|
2693
2970
|
* @example
|
|
2694
2971
|
* ```ts
|
|
2695
2972
|
* pipe(
|
|
@@ -2699,11 +2976,13 @@ declare const Result: {
|
|
|
2699
2976
|
* );
|
|
2700
2977
|
* ```
|
|
2701
2978
|
*/
|
|
2702
|
-
tap: <E, A>(
|
|
2979
|
+
tap: <E, A>(sideEffect: (value: A) => void) => (result: Result<E, A>) => Result<E, A>;
|
|
2703
2980
|
/**
|
|
2704
2981
|
* Executes a side effect on the error value without changing the Result.
|
|
2705
2982
|
* Useful for logging or reporting errors.
|
|
2706
2983
|
*
|
|
2984
|
+
* @see {@link Result.tap} to perform a side effect on the success value.
|
|
2985
|
+
*
|
|
2707
2986
|
* @example
|
|
2708
2987
|
* ```ts
|
|
2709
2988
|
* pipe(
|
|
@@ -2713,7 +2992,7 @@ declare const Result: {
|
|
|
2713
2992
|
* )
|
|
2714
2993
|
* ```
|
|
2715
2994
|
*/
|
|
2716
|
-
tapError: <E, A>(
|
|
2995
|
+
tapError: <E, A>(sideEffect: (error: E) => void) => (result: Result<E, A>) => Result<E, A>;
|
|
2717
2996
|
from: {
|
|
2718
2997
|
/**
|
|
2719
2998
|
* Creates a Result from a predicate applied to a value.
|
|
@@ -2726,7 +3005,7 @@ declare const Result: {
|
|
|
2726
3005
|
* pipe("", Result.from.Predicate(s => s.length > 0, () => "empty string")); // Err("empty string")
|
|
2727
3006
|
* ```
|
|
2728
3007
|
*/
|
|
2729
|
-
Predicate: <E, A>(
|
|
3008
|
+
Predicate: <E, A>(predicate: (value: A) => boolean, onFalse: (value: A) => E) => (value: A) => Result<E, A>;
|
|
2730
3009
|
/**
|
|
2731
3010
|
* Creates a Result from a nullable value.
|
|
2732
3011
|
* Returns Ok if the value is not null or undefined, error from onNull otherwise.
|
|
@@ -2758,16 +3037,20 @@ declare const Result: {
|
|
|
2758
3037
|
* Result.from.Validation((errors) => errors.join(", "))(Validation.make.failed("error1")); // Err("error1")
|
|
2759
3038
|
* ```
|
|
2760
3039
|
*/
|
|
2761
|
-
Validation: <E1, E2, A>(combineErrors: (errors: NonEmptyArr<E1>) => E2) => (
|
|
3040
|
+
Validation: <E1, E2, A>(combineErrors: (errors: NonEmptyArr<E1>) => E2) => (validation: Validation<E1, A>) => Result<E2, A>;
|
|
2762
3041
|
};
|
|
2763
3042
|
/**
|
|
2764
3043
|
* Recovers from an error by providing a fallback Result.
|
|
2765
|
-
* The fallback can produce a different success type
|
|
3044
|
+
* The fallback can produce a different success type or resolve with a different error type.
|
|
3045
|
+
*
|
|
3046
|
+
* @see {@link Result.recoverUnless} to conditionally recover based on the error value.
|
|
2766
3047
|
*/
|
|
2767
|
-
recover: <
|
|
3048
|
+
recover: <E1, E2, B>(fallback: (error: E1) => Result<E2, B>) => <A>(result: Result<E1, A>) => Result<E2, A | B>;
|
|
2768
3049
|
/**
|
|
2769
3050
|
* Recovers from an error unless the predicate `isBlocked` returns true for that error.
|
|
2770
|
-
* The fallback can produce a different success type, widening the result to `Result<
|
|
3051
|
+
* The fallback can produce a different success type, widening the result to `Result<E1 | E2, A | B>`.
|
|
3052
|
+
*
|
|
3053
|
+
* @see {@link Result.recover} for unconditional error recovery.
|
|
2771
3054
|
*
|
|
2772
3055
|
* @example
|
|
2773
3056
|
* ```ts
|
|
@@ -2777,7 +3060,7 @@ declare const Result: {
|
|
|
2777
3060
|
* ); // Ok(0)
|
|
2778
3061
|
* ```
|
|
2779
3062
|
*/
|
|
2780
|
-
recoverUnless: <
|
|
3063
|
+
recoverUnless: <E1, E2, B>(isBlocked: (error: E1) => boolean, fallback: (error: E1) => Result<E2, B>) => <A>(result: Result<E1, A>) => Result<E1 | E2, A | B>;
|
|
2781
3064
|
to: {
|
|
2782
3065
|
/**
|
|
2783
3066
|
* Converts a Result to a Maybe.
|
|
@@ -2789,7 +3072,7 @@ declare const Result: {
|
|
|
2789
3072
|
* Result.to.Maybe(Result.make.err("oops")); // None
|
|
2790
3073
|
* ```
|
|
2791
3074
|
*/
|
|
2792
|
-
Maybe: <E, A>(
|
|
3075
|
+
Maybe: <E, A>(result: Result<E, A>) => Maybe<A>;
|
|
2793
3076
|
/**
|
|
2794
3077
|
* Converts a `Result` to a `Validation`. `Ok(a)` becomes `Passed(a)`; `Err(e)` becomes `Failed([e])`.
|
|
2795
3078
|
*
|
|
@@ -2799,7 +3082,7 @@ declare const Result: {
|
|
|
2799
3082
|
* Result.to.Validation(Result.make.err("bad")); // Failed(["bad"])
|
|
2800
3083
|
* ```
|
|
2801
3084
|
*/
|
|
2802
|
-
Validation: <E, A>(
|
|
3085
|
+
Validation: <E, A>(result: Result<E, A>) => Validation<E, A>;
|
|
2803
3086
|
};
|
|
2804
3087
|
/**
|
|
2805
3088
|
* Swaps the outer `Result` and inner `Maybe` context.
|
|
@@ -2812,7 +3095,7 @@ declare const Result: {
|
|
|
2812
3095
|
* Result.transposeMaybe(Result.make.err("error")); // Some(Err("error"))
|
|
2813
3096
|
* ```
|
|
2814
3097
|
*/
|
|
2815
|
-
transposeMaybe: <E, A>(
|
|
3098
|
+
transposeMaybe: <E, A>(result: Result<E, Maybe<A>>) => Maybe<Result<E, A>>;
|
|
2816
3099
|
/**
|
|
2817
3100
|
* Applies a function wrapped in a Result to a value wrapped in a Result.
|
|
2818
3101
|
*
|
|
@@ -2821,12 +3104,12 @@ declare const Result: {
|
|
|
2821
3104
|
* const add = (a: number) => (b: number) => a + b;
|
|
2822
3105
|
* pipe(
|
|
2823
3106
|
* Result.make.ok(add),
|
|
2824
|
-
* Result.
|
|
2825
|
-
* Result.
|
|
3107
|
+
* Result.apply(Result.make.ok(5)),
|
|
3108
|
+
* Result.apply(Result.make.ok(3))
|
|
2826
3109
|
* ); // Ok(8)
|
|
2827
3110
|
* ```
|
|
2828
3111
|
*/
|
|
2829
|
-
|
|
3112
|
+
apply: <E2, A>(arg: Result<E2, A>) => <E1, B>(result: Result<E1, (value: A) => B>) => Result<E1 | E2, B>;
|
|
2830
3113
|
/**
|
|
2831
3114
|
* Converts a Result value into an object containing a single property.
|
|
2832
3115
|
* Initiates the pipeline accumulator record.
|
|
@@ -2836,7 +3119,7 @@ declare const Result: {
|
|
|
2836
3119
|
* pipe(Result.make.ok(42), Result.bindTo("value")); // Ok({ value: 42 })
|
|
2837
3120
|
* ```
|
|
2838
3121
|
*/
|
|
2839
|
-
bindTo: <K extends string>(key: K) => <E, A>(
|
|
3122
|
+
bindTo: <K extends string>(key: K) => <E, A>(result: Result<E, A>) => Result<E, { [P in K]: A; }>;
|
|
2840
3123
|
/**
|
|
2841
3124
|
* Evaluates a new Result using the current accumulator and attaches the output to a new key.
|
|
2842
3125
|
*
|
|
@@ -2848,7 +3131,7 @@ declare const Result: {
|
|
|
2848
3131
|
* ); // Ok({ a: 1, b: 2 })
|
|
2849
3132
|
* ```
|
|
2850
3133
|
*/
|
|
2851
|
-
bind: <K extends string,
|
|
3134
|
+
bind: <K extends string, E2, A, B>(key: K, transform: (value: A) => Result<E2, B>) => <E1 = never>(result: Result<E1, A>) => Result<E1 | E2, A & { [P in K]: B; }>;
|
|
2852
3135
|
/**
|
|
2853
3136
|
* Combines a record of Results into a single Result of a record.
|
|
2854
3137
|
* Evaluates fields in key order and short-circuits on the first failure.
|
|
@@ -2863,7 +3146,7 @@ declare const Result: {
|
|
|
2863
3146
|
*/
|
|
2864
3147
|
struct: <E, R extends Record<string, any>>(fields: { [K in keyof R]: Result<E, R[K]>; }) => Result<E, R>;
|
|
2865
3148
|
/**
|
|
2866
|
-
* Narrows an `Ok` value with a predicate, converting to `Err(onFail(
|
|
3149
|
+
* Narrows an `Ok` value with a predicate, converting to `Err(onFail(value))` if the predicate returns false.
|
|
2867
3150
|
*
|
|
2868
3151
|
* @example
|
|
2869
3152
|
* ```ts
|
|
@@ -2873,7 +3156,7 @@ declare const Result: {
|
|
|
2873
3156
|
* ); // Err("Age 15 is below 18")
|
|
2874
3157
|
* ```
|
|
2875
3158
|
*/
|
|
2876
|
-
ensure: <A, E2>(predicate: (
|
|
3159
|
+
ensure: <A, E2>(predicate: (value: A) => boolean, onFail: (value: A) => E2) => <E1 = never>(result: Result<E1, A>) => Result<E1 | E2, A>;
|
|
2877
3160
|
/**
|
|
2878
3161
|
* Transforms both branches of a Result simultaneously.
|
|
2879
3162
|
* Applies `onErr` to `Err` values and `onOk` to `Ok` values.
|
|
@@ -2889,7 +3172,7 @@ declare const Result: {
|
|
|
2889
3172
|
* ); // Ok(10)
|
|
2890
3173
|
* ```
|
|
2891
3174
|
*/
|
|
2892
|
-
bimap: <E1, E2, A, B>(onErr: (
|
|
3175
|
+
bimap: <E1, E2, A, B>(onErr: (error: E1) => E2, onOk: (value: A) => B) => (result: Result<E1, A>) => Result<E2, B>;
|
|
2893
3176
|
};
|
|
2894
3177
|
//#endregion
|
|
2895
3178
|
//#region src/Core/State.d.ts
|
|
@@ -3019,14 +3302,14 @@ declare const State$1: {
|
|
|
3019
3302
|
* const addCounted = (n: number) => (m: number) => n + m;
|
|
3020
3303
|
* const program = pipe(
|
|
3021
3304
|
* State.resolve<number, typeof addCounted>(addCounted),
|
|
3022
|
-
* State.
|
|
3023
|
-
* State.
|
|
3305
|
+
* State.apply(State.gets((s: number) => s * 2)),
|
|
3306
|
+
* State.apply(State.gets((s: number) => s)),
|
|
3024
3307
|
* );
|
|
3025
3308
|
*
|
|
3026
3309
|
* State.evaluate(3)(program); // 6 + 3 = 9
|
|
3027
3310
|
* ```
|
|
3028
3311
|
*/
|
|
3029
|
-
|
|
3312
|
+
apply: <S, A>(arg: State$1<S, A>) => <B>(fn: State$1<S, (a: A) => B>) => State$1<S, B>;
|
|
3030
3313
|
/**
|
|
3031
3314
|
* Runs a side effect on the produced value without changing the State computation.
|
|
3032
3315
|
*
|
|
@@ -3118,145 +3401,6 @@ declare const State$1: {
|
|
|
3118
3401
|
focus: <S, A>(lens: Lens<S, A>) => <B>(stateOp: State$1<A, B>) => State$1<S, B>;
|
|
3119
3402
|
};
|
|
3120
3403
|
//#endregion
|
|
3121
|
-
//#region src/Core/Stream.d.ts
|
|
3122
|
-
/**
|
|
3123
|
-
* An event stream pipeline for a typed message schema `S`.
|
|
3124
|
-
*
|
|
3125
|
-
* `Stream` provides typed event emission, sequence matching, state reduction,
|
|
3126
|
-
* and structural stream forwarding.
|
|
3127
|
-
*
|
|
3128
|
-
* @example
|
|
3129
|
-
* ```ts
|
|
3130
|
-
* type AppMessages = {
|
|
3131
|
-
* userLoggedIn: { userId: string };
|
|
3132
|
-
* checkoutStarted: { amount: number };
|
|
3133
|
-
* };
|
|
3134
|
-
*
|
|
3135
|
-
* const appStream = Stream.make<AppMessages>();
|
|
3136
|
-
*
|
|
3137
|
-
* const subscription = Stream.listen(
|
|
3138
|
-
* appStream,
|
|
3139
|
-
* ["userLoggedIn", "checkoutStarted"],
|
|
3140
|
-
* { ordered: true }
|
|
3141
|
-
* ).reduce(
|
|
3142
|
-
* (msg, state) => {
|
|
3143
|
-
* if (msg.kind === "checkoutStarted") {
|
|
3144
|
-
* return { count: state.count + 1 };
|
|
3145
|
-
* }
|
|
3146
|
-
* return state;
|
|
3147
|
-
* },
|
|
3148
|
-
* { count: 0 }
|
|
3149
|
-
* );
|
|
3150
|
-
*
|
|
3151
|
-
* Stream.emit(appStream, {
|
|
3152
|
-
* kind: "userLoggedIn",
|
|
3153
|
-
* value: { userId: "user-1" },
|
|
3154
|
-
* });
|
|
3155
|
-
* ```
|
|
3156
|
-
*/
|
|
3157
|
-
type Stream<S extends Record<string, unknown>> = {
|
|
3158
|
-
readonly options?: Stream.Options;
|
|
3159
|
-
/** @internal */
|
|
3160
|
-
readonly _listeners: Set<(msg: Stream.Message<S>) => void>;
|
|
3161
|
-
/**
|
|
3162
|
-
* @internal
|
|
3163
|
-
* Lazy array snapshot of `_listeners`. Avoids allocating new array objects on every `emit` call
|
|
3164
|
-
* (2.98x emission speedup, 0 heap allocations). Rebuilt whenever `_listeners` is mutated,
|
|
3165
|
-
* guaranteeing reentrancy safety and preventing listeners subscribed mid-emission from executing early.
|
|
3166
|
-
*/
|
|
3167
|
-
_listenerArray: Array<(msg: Stream.Message<S>) => void> | null;
|
|
3168
|
-
/** @internal */
|
|
3169
|
-
readonly _queue: Array<Stream.Message<S>>;
|
|
3170
|
-
/** @internal */
|
|
3171
|
-
_isEmitting: boolean;
|
|
3172
|
-
};
|
|
3173
|
-
declare const Stream: {
|
|
3174
|
-
/**
|
|
3175
|
-
* Constructs a new `Stream` instance.
|
|
3176
|
-
*
|
|
3177
|
-
* @example
|
|
3178
|
-
* ```ts
|
|
3179
|
-
* const stream = Stream.make<AppMessages>({ name: "app" });
|
|
3180
|
-
* ```
|
|
3181
|
-
*/
|
|
3182
|
-
make: <S extends Record<string, unknown>>(options?: Stream.Options) => Stream<S>;
|
|
3183
|
-
/**
|
|
3184
|
-
* Emits a message payload to one or more target streams.
|
|
3185
|
-
*
|
|
3186
|
-
* Uses a synchronous breadth-first trampoline queue to handle re-entrant emissions deterministically.
|
|
3187
|
-
*
|
|
3188
|
-
* @example
|
|
3189
|
-
* ```ts
|
|
3190
|
-
* Stream.emit(streamA, {
|
|
3191
|
-
* kind: "userLoggedIn",
|
|
3192
|
-
* value: { userId: "user-1" },
|
|
3193
|
-
* });
|
|
3194
|
-
*
|
|
3195
|
-
* Stream.emit([streamA, streamB], {
|
|
3196
|
-
* kind: "userLoggedIn",
|
|
3197
|
-
* value: { userId: "user-1" },
|
|
3198
|
-
* });
|
|
3199
|
-
* ```
|
|
3200
|
-
*/
|
|
3201
|
-
emit: <S extends Record<string, unknown>, K extends keyof S & string>(target: Stream<S> | ReadonlyArray<Stream<S>>, message: WithKind<K> & WithValue<S[K]>) => void;
|
|
3202
|
-
/**
|
|
3203
|
-
* Forwards messages from one stream to another (or multiple).
|
|
3204
|
-
*
|
|
3205
|
-
* @example
|
|
3206
|
-
* ```ts
|
|
3207
|
-
* const stop = Stream.forward({
|
|
3208
|
-
* from: authStream,
|
|
3209
|
-
* to: analyticsStream,
|
|
3210
|
-
* only: ["userLoggedIn"],
|
|
3211
|
-
* });
|
|
3212
|
-
* ```
|
|
3213
|
-
*/
|
|
3214
|
-
forward: <S extends Record<string, unknown>>(options: Stream.ForwardOptions<S>) => () => void;
|
|
3215
|
-
/**
|
|
3216
|
-
* Initiates listener registration on a stream for specific event kind(s) or sequence.
|
|
3217
|
-
*
|
|
3218
|
-
* @example
|
|
3219
|
-
* ```ts
|
|
3220
|
-
* const sub = Stream.listen(
|
|
3221
|
-
* appStream,
|
|
3222
|
-
* ["userLoggedIn", "checkoutStarted"],
|
|
3223
|
-
* { ordered: true }
|
|
3224
|
-
* ).reduce(
|
|
3225
|
-
* (msg, state) => ({ count: state.count + 1 }),
|
|
3226
|
-
* { count: 0 }
|
|
3227
|
-
* );
|
|
3228
|
-
* ```
|
|
3229
|
-
*/
|
|
3230
|
-
listen: <S extends Record<string, unknown>, K extends keyof S & string>(stream: Stream<S>, events: K | ReadonlyArray<K>, options?: Stream.SequenceOptions<S>) => Stream.ListenerBuilder<S>;
|
|
3231
|
-
};
|
|
3232
|
-
declare namespace Stream {
|
|
3233
|
-
type Message<S extends Record<string, unknown>> = { [K in keyof S & string]: WithKind<K> & WithValue<S[K]>; }[keyof S & string];
|
|
3234
|
-
type Options = {
|
|
3235
|
-
readonly name?: string;
|
|
3236
|
-
readonly onError?: (error: unknown) => void;
|
|
3237
|
-
};
|
|
3238
|
-
type SequenceOptions<S extends Record<string, unknown>> = {
|
|
3239
|
-
readonly ordered?: boolean;
|
|
3240
|
-
readonly strict?: boolean;
|
|
3241
|
-
readonly once?: boolean;
|
|
3242
|
-
readonly reset?: (keyof S & string) | ReadonlyArray<keyof S & string>;
|
|
3243
|
-
readonly optional?: (keyof S & string) | ReadonlyArray<keyof S & string>;
|
|
3244
|
-
};
|
|
3245
|
-
type Subscription<State> = {
|
|
3246
|
-
readonly unsubscribe: () => void;
|
|
3247
|
-
readonly getState: () => State;
|
|
3248
|
-
};
|
|
3249
|
-
type ForwardOptions<S extends Record<string, unknown>> = {
|
|
3250
|
-
readonly from: Stream<S>;
|
|
3251
|
-
readonly to: Stream<S> | ReadonlyArray<Stream<S>>;
|
|
3252
|
-
readonly only?: ReadonlyArray<keyof S & string>;
|
|
3253
|
-
};
|
|
3254
|
-
type ListenerBuilder<S extends Record<string, unknown>> = {
|
|
3255
|
-
readonly reduce: <State>(reducer: (msg: Message<S>, state: State) => State, initialState: State) => Subscription<State>;
|
|
3256
|
-
readonly tap: (effect: (msg: Message<S>) => void) => () => void;
|
|
3257
|
-
};
|
|
3258
|
-
}
|
|
3259
|
-
//#endregion
|
|
3260
3404
|
//#region src/Core/Validation.d.ts
|
|
3261
3405
|
/**
|
|
3262
3406
|
* Validation represents a value that is either passed with a success value,
|
|
@@ -3286,8 +3430,8 @@ declare namespace Stream {
|
|
|
3286
3430
|
type Validation<E, A> = Passed<A> | Failed<E>;
|
|
3287
3431
|
type Passed<A> = WithKind<"Passed"> & WithValue<A>;
|
|
3288
3432
|
type Failed<E> = WithKind<"Failed"> & WithErrors<E>;
|
|
3289
|
-
declare function toResult<E1, E2, A>(combineErrors: (errors: NonEmptyArr<E1>) => E2): (
|
|
3290
|
-
declare function toResult<E, A>(
|
|
3433
|
+
declare function toResult<E1, E2, A>(combineErrors: (errors: NonEmptyArr<E1>) => E2): (validation: Validation<E1, A>) => Result<E2, A>;
|
|
3434
|
+
declare function toResult<E, A>(validation: Validation<E, A>): Result<NonEmptyArr<E>, A>;
|
|
3291
3435
|
declare const Validation: {
|
|
3292
3436
|
make: {
|
|
3293
3437
|
/**
|
|
@@ -3322,6 +3466,8 @@ declare const Validation: {
|
|
|
3322
3466
|
/**
|
|
3323
3467
|
* Type guard that checks if a Validation is passed.
|
|
3324
3468
|
*
|
|
3469
|
+
* @see {@link Validation.is.failed} to check if a Validation is failed.
|
|
3470
|
+
*
|
|
3325
3471
|
* @example
|
|
3326
3472
|
* ```ts
|
|
3327
3473
|
* const v = Validation.make.passed(42);
|
|
@@ -3330,10 +3476,12 @@ declare const Validation: {
|
|
|
3330
3476
|
* }
|
|
3331
3477
|
* ```
|
|
3332
3478
|
*/
|
|
3333
|
-
passed: <E, A>(
|
|
3479
|
+
passed: <E, A>(validation: Validation<E, A>) => validation is Passed<A>;
|
|
3334
3480
|
/**
|
|
3335
3481
|
* Type guard that checks if a Validation is failed.
|
|
3336
3482
|
*
|
|
3483
|
+
* @see {@link Validation.is.passed} to check if a Validation is passed.
|
|
3484
|
+
*
|
|
3337
3485
|
* @example
|
|
3338
3486
|
* ```ts
|
|
3339
3487
|
* const v = Validation.make.failed("invalid");
|
|
@@ -3342,7 +3490,7 @@ declare const Validation: {
|
|
|
3342
3490
|
* }
|
|
3343
3491
|
* ```
|
|
3344
3492
|
*/
|
|
3345
|
-
failed: <E, A>(
|
|
3493
|
+
failed: <E, A>(validation: Validation<E, A>) => validation is Failed<E>;
|
|
3346
3494
|
};
|
|
3347
3495
|
/**
|
|
3348
3496
|
* Creates a Validation from a synchronous thunk that may throw.
|
|
@@ -3352,12 +3500,12 @@ declare const Validation: {
|
|
|
3352
3500
|
* ```ts
|
|
3353
3501
|
* const result = Validation.tryCatch(
|
|
3354
3502
|
* () => JSON.parse(rawString),
|
|
3355
|
-
* { onError: (
|
|
3503
|
+
* { onError: (error) => `Parse error: ${error}` }
|
|
3356
3504
|
* );
|
|
3357
3505
|
* ```
|
|
3358
3506
|
*/
|
|
3359
|
-
tryCatch: <E, A>(
|
|
3360
|
-
onError: (
|
|
3507
|
+
tryCatch: <E, A>(fn: () => A, options: {
|
|
3508
|
+
onError: (error: unknown) => E;
|
|
3361
3509
|
}) => Validation<E, A>;
|
|
3362
3510
|
from: {
|
|
3363
3511
|
/**
|
|
@@ -3375,7 +3523,7 @@ declare const Validation: {
|
|
|
3375
3523
|
* validateName(""); // Failed(["Name is required"])
|
|
3376
3524
|
* ```
|
|
3377
3525
|
*/
|
|
3378
|
-
Predicate: <E, A>(
|
|
3526
|
+
Predicate: <E, A>(predicate: (value: A) => boolean, onFalse: (value: A) => E) => (value: A) => Validation<E, A>;
|
|
3379
3527
|
/**
|
|
3380
3528
|
* Creates a Validation from a nullable value.
|
|
3381
3529
|
* If the value is null or undefined, returns Failed with the error from onNull.
|
|
@@ -3412,63 +3560,71 @@ declare const Validation: {
|
|
|
3412
3560
|
* Validation.from.Result(Result.make.err("bad")); // Failed(["bad"])
|
|
3413
3561
|
* ```
|
|
3414
3562
|
*/
|
|
3415
|
-
Result: <E, A>(
|
|
3563
|
+
Result: <E, A>(result: Result<E, A>) => Validation<E, A>;
|
|
3416
3564
|
};
|
|
3417
3565
|
/**
|
|
3418
3566
|
* Transforms the success value inside a Validation.
|
|
3419
3567
|
*
|
|
3568
|
+
* @see {@link Validation.mapError} to transform accumulated errors.
|
|
3569
|
+
* @see {@link Validation.apply} to combine multiple validations.
|
|
3570
|
+
*
|
|
3420
3571
|
* @example
|
|
3421
3572
|
* ```ts
|
|
3422
3573
|
* pipe(Validation.make.passed(5), Validation.map(n => n * 2)); // Passed(10)
|
|
3423
3574
|
* pipe(Validation.make.failed("oops"), Validation.map(n => n * 2)); // Failed(["oops"])
|
|
3424
3575
|
* ```
|
|
3425
3576
|
*/
|
|
3426
|
-
map: <A, B>(
|
|
3577
|
+
map: <A, B>(transform: (value: A) => B) => <E>(validation: Validation<E, A>) => Validation<E, B>;
|
|
3427
3578
|
/**
|
|
3428
3579
|
* Transforms the error list inside a Validation.
|
|
3429
3580
|
*
|
|
3581
|
+
* @see {@link Validation.map} to transform the success value.
|
|
3582
|
+
*
|
|
3430
3583
|
* @example
|
|
3431
3584
|
* ```ts
|
|
3432
3585
|
* pipe(Validation.make.failed("oops"), Validation.mapError(e => e.toUpperCase())); // Failed(["OOPS"])
|
|
3433
3586
|
* ```
|
|
3434
3587
|
*/
|
|
3435
|
-
mapError: <E, F, A>(
|
|
3588
|
+
mapError: <E, F, A>(transform: (error: E) => F) => (validation: Validation<E, A>) => Validation<F, A>;
|
|
3436
3589
|
/**
|
|
3437
3590
|
* Applies a function wrapped in a Validation to a value wrapped in a Validation.
|
|
3438
|
-
* Accumulates errors from both sides
|
|
3591
|
+
* Accumulates errors from both sides if both fail, using optional `combineErrors`
|
|
3592
|
+
* or default concatenation.
|
|
3593
|
+
*
|
|
3594
|
+
* @see {@link Validation.product} to combine two validations into a tuple.
|
|
3439
3595
|
*
|
|
3440
3596
|
* @example
|
|
3441
3597
|
* ```ts
|
|
3442
3598
|
* const add = (a: number) => (b: number) => a + b;
|
|
3443
3599
|
* pipe(
|
|
3444
3600
|
* Validation.make.passed(add),
|
|
3445
|
-
* Validation.
|
|
3446
|
-
* Validation.
|
|
3601
|
+
* Validation.apply(Validation.make.passed(5)),
|
|
3602
|
+
* Validation.apply(Validation.make.passed(3))
|
|
3447
3603
|
* ); // Passed(8)
|
|
3448
3604
|
*
|
|
3449
3605
|
* pipe(
|
|
3450
3606
|
* Validation.make.passed(add),
|
|
3451
|
-
* Validation.
|
|
3452
|
-
* Validation.
|
|
3607
|
+
* Validation.apply(Validation.make.failed<string>("bad a")),
|
|
3608
|
+
* Validation.apply(Validation.make.failed<string>("bad b"))
|
|
3453
3609
|
* ); // Failed(["bad a", "bad b"])
|
|
3454
|
-
* ```
|
|
3455
|
-
*/
|
|
3456
|
-
ap: <E, A>(arg: Validation<E, A>) => <B>(data: Validation<E, (a: A) => B>) => Validation<E, B>;
|
|
3457
|
-
/**
|
|
3458
|
-
* Applies a function wrapped in a Validation to a value wrapped in a Validation,
|
|
3459
|
-
* using a custom error concatenator function when both sides fail.
|
|
3460
3610
|
*
|
|
3461
|
-
*
|
|
3462
|
-
*
|
|
3463
|
-
*
|
|
3464
|
-
*
|
|
3465
|
-
*
|
|
3611
|
+
* // Custom error combination:
|
|
3612
|
+
* pipe(
|
|
3613
|
+
* Validation.make.passed(add),
|
|
3614
|
+
* Validation.apply(Validation.make.failed("err"), {
|
|
3615
|
+
* combineErrors: (e1, e2) => [...e1, ...e2],
|
|
3616
|
+
* })
|
|
3617
|
+
* );
|
|
3466
3618
|
* ```
|
|
3467
3619
|
*/
|
|
3468
|
-
|
|
3620
|
+
apply: <E2, A, E3 = never>(arg: Validation<E2, A>, options?: {
|
|
3621
|
+
combineErrors?: (e1: NonEmptyArr<any>, e2: NonEmptyArr<E2>) => NonEmptyArr<E3>;
|
|
3622
|
+
}) => <B, E1 = never>(validation: Validation<E1, (value: A) => B>) => Validation<[E3] extends [never] ? E1 | E2 : E3, B>;
|
|
3469
3623
|
/**
|
|
3470
3624
|
* Extracts the value from a Validation by providing handlers for both cases.
|
|
3471
3625
|
*
|
|
3626
|
+
* @see {@link Validation.match} for named-case pattern matching with an object literal.
|
|
3627
|
+
*
|
|
3472
3628
|
* @example
|
|
3473
3629
|
* ```ts
|
|
3474
3630
|
* pipe(
|
|
@@ -3480,10 +3636,12 @@ declare const Validation: {
|
|
|
3480
3636
|
* );
|
|
3481
3637
|
* ```
|
|
3482
3638
|
*/
|
|
3483
|
-
fold: <E, A, B>(onFailed: (errors: NonEmptyArr<E>) => B, onPassed: (
|
|
3639
|
+
fold: <E, A, B>(onFailed: (errors: NonEmptyArr<E>) => B, onPassed: (value: A) => B) => (validation: Validation<E, A>) => B;
|
|
3484
3640
|
/**
|
|
3485
3641
|
* Pattern matches on a Validation, returning the result of the matching case.
|
|
3486
3642
|
*
|
|
3643
|
+
* @see {@link Validation.fold} for positional argument pattern matching.
|
|
3644
|
+
*
|
|
3487
3645
|
* @example
|
|
3488
3646
|
* ```ts
|
|
3489
3647
|
* pipe(
|
|
@@ -3496,13 +3654,15 @@ declare const Validation: {
|
|
|
3496
3654
|
* ```
|
|
3497
3655
|
*/
|
|
3498
3656
|
match: <E, A, B>(cases: {
|
|
3499
|
-
passed: (
|
|
3657
|
+
passed: (value: A) => B;
|
|
3500
3658
|
failed: (errors: NonEmptyArr<E>) => B;
|
|
3501
|
-
}) => (
|
|
3659
|
+
}) => (validation: Validation<E, A>) => B;
|
|
3502
3660
|
/**
|
|
3503
3661
|
* Returns the success value or a default value if the Validation is failed.
|
|
3504
3662
|
* The default can be a different type, widening the result to `A | B`.
|
|
3505
3663
|
*
|
|
3664
|
+
* @see {@link Validation.fold} to handle both the passed and failed cases.
|
|
3665
|
+
*
|
|
3506
3666
|
* @example
|
|
3507
3667
|
* ```ts
|
|
3508
3668
|
* pipe(Validation.make.passed(5), Validation.getOrElse(() => 0)); // 5
|
|
@@ -3510,10 +3670,12 @@ declare const Validation: {
|
|
|
3510
3670
|
* pipe(Validation.make.failed("oops"), Validation.getOrElse(() => null)); // null — typed as number | null
|
|
3511
3671
|
* ```
|
|
3512
3672
|
*/
|
|
3513
|
-
getOrElse: <B>(
|
|
3673
|
+
getOrElse: <B>(fallback: () => B) => <E, A>(validation: Validation<E, A>) => A | B;
|
|
3514
3674
|
/**
|
|
3515
3675
|
* Executes a side effect on the success value without changing the Validation.
|
|
3516
3676
|
*
|
|
3677
|
+
* @see {@link Validation.tapError} to perform a side effect on accumulated errors.
|
|
3678
|
+
*
|
|
3517
3679
|
* @example
|
|
3518
3680
|
* ```ts
|
|
3519
3681
|
* pipe(
|
|
@@ -3523,11 +3685,13 @@ declare const Validation: {
|
|
|
3523
3685
|
* );
|
|
3524
3686
|
* ```
|
|
3525
3687
|
*/
|
|
3526
|
-
tap: <E, A>(
|
|
3688
|
+
tap: <E, A>(sideEffect: (value: A) => void) => (validation: Validation<E, A>) => Validation<E, A>;
|
|
3527
3689
|
/**
|
|
3528
3690
|
* Executes a side effect on the accumulated errors without changing the Validation.
|
|
3529
3691
|
* Useful for logging or reporting validation failures.
|
|
3530
3692
|
*
|
|
3693
|
+
* @see {@link Validation.tap} to perform a side effect on the success value.
|
|
3694
|
+
*
|
|
3531
3695
|
* @example
|
|
3532
3696
|
* ```ts
|
|
3533
3697
|
* pipe(
|
|
@@ -3537,16 +3701,20 @@ declare const Validation: {
|
|
|
3537
3701
|
* );
|
|
3538
3702
|
* ```
|
|
3539
3703
|
*/
|
|
3540
|
-
tapError: <E, A>(
|
|
3704
|
+
tapError: <E, A>(sideEffect: (errors: NonEmptyArr<E>) => void) => (validation: Validation<E, A>) => Validation<E, A>;
|
|
3541
3705
|
/**
|
|
3542
3706
|
* Recovers from a Failed state by providing a fallback Validation.
|
|
3543
3707
|
* The fallback receives the accumulated error list so callers can inspect which errors occurred.
|
|
3544
|
-
* The fallback can produce a different success type
|
|
3708
|
+
* The fallback can produce a different success type or resolve with a different error type.
|
|
3709
|
+
*
|
|
3710
|
+
* @see {@link Validation.recoverUnless} to conditionally recover based on accumulated errors.
|
|
3545
3711
|
*/
|
|
3546
|
-
recover: <
|
|
3712
|
+
recover: <E1, E2, B>(fallback: (errors: NonEmptyArr<E1>) => Validation<E2, B>) => <A>(validation: Validation<E1, A>) => Validation<E2, A | B>;
|
|
3547
3713
|
/**
|
|
3548
3714
|
* Recovers from a Failed state unless `isBlocked` returns true for any of the accumulated errors.
|
|
3549
|
-
* The fallback can produce a different success type, widening the result to `Validation<
|
|
3715
|
+
* The fallback can produce a different success type, widening the result to `Validation<E1 | E2, A | B>`.
|
|
3716
|
+
*
|
|
3717
|
+
* @see {@link Validation.recover} for unconditional error recovery.
|
|
3550
3718
|
*
|
|
3551
3719
|
* @example
|
|
3552
3720
|
* ```ts
|
|
@@ -3556,7 +3724,7 @@ declare const Validation: {
|
|
|
3556
3724
|
* ); // Passed(0)
|
|
3557
3725
|
* ```
|
|
3558
3726
|
*/
|
|
3559
|
-
recoverUnless: <
|
|
3727
|
+
recoverUnless: <E1, E2, B>(isBlocked: (error: E1) => boolean, fallback: (errors: NonEmptyArr<E1>) => Validation<E2, B>) => <A>(validation: Validation<E1, A>) => Validation<E1 | E2, A | B>;
|
|
3560
3728
|
to: {
|
|
3561
3729
|
/**
|
|
3562
3730
|
* Converts a Validation to a Result.
|
|
@@ -3582,13 +3750,16 @@ declare const Validation: {
|
|
|
3582
3750
|
* Validation.to.Maybe(Validation.make.failed("bad")); // None
|
|
3583
3751
|
* ```
|
|
3584
3752
|
*/
|
|
3585
|
-
Maybe: <E, A>(
|
|
3753
|
+
Maybe: <E, A>(validation: Validation<E, A>) => Maybe<A>;
|
|
3586
3754
|
};
|
|
3587
3755
|
/**
|
|
3588
3756
|
* Combines two independent Validation instances into a tuple.
|
|
3589
3757
|
* If both are Passed, returns Passed with both values as a tuple.
|
|
3590
3758
|
* If either is Failed, accumulates errors from both sides.
|
|
3591
3759
|
*
|
|
3760
|
+
* @see {@link Validation.productAll} to combine a non-empty list of validations.
|
|
3761
|
+
* @see {@link Validation.apply} to apply a curried function across validations.
|
|
3762
|
+
*
|
|
3592
3763
|
* @example
|
|
3593
3764
|
* ```ts
|
|
3594
3765
|
* Validation.product(
|
|
@@ -3608,6 +3779,8 @@ declare const Validation: {
|
|
|
3608
3779
|
* If all are Passed, returns Passed with all values collected into an array.
|
|
3609
3780
|
* If any are Failed, returns Failed with all accumulated errors.
|
|
3610
3781
|
*
|
|
3782
|
+
* @see {@link Validation.product} to combine exactly two validations into a pair.
|
|
3783
|
+
*
|
|
3611
3784
|
* @example
|
|
3612
3785
|
* ```ts
|
|
3613
3786
|
* Validation.productAll([
|
|
@@ -3618,7 +3791,7 @@ declare const Validation: {
|
|
|
3618
3791
|
* // Passed([name, email, age]) or Failed([...all errors])
|
|
3619
3792
|
* ```
|
|
3620
3793
|
*/
|
|
3621
|
-
productAll: <E, A>(
|
|
3794
|
+
productAll: <E, A>(validations: NonEmptyArr<Validation<E, A>>) => Validation<E, readonly A[]>;
|
|
3622
3795
|
/**
|
|
3623
3796
|
* Combines a record of Validations into a single Validation of a record.
|
|
3624
3797
|
* Accumulates all failed branches' errors.
|
|
@@ -3637,7 +3810,87 @@ declare const Validation: {
|
|
|
3637
3810
|
* ```
|
|
3638
3811
|
*/
|
|
3639
3812
|
struct: <E, R extends Record<string, any>>(fields: { [K in keyof R]: Validation<E, R[K]>; }) => Validation<E, R>;
|
|
3813
|
+
keyed: {
|
|
3814
|
+
/**
|
|
3815
|
+
* Creates a keyed validator function from a schema of field validators.
|
|
3816
|
+
* Evaluates each validator against its corresponding field in the input object,
|
|
3817
|
+
* returning a record where every key holds its own Validation outcome.
|
|
3818
|
+
*
|
|
3819
|
+
* @example
|
|
3820
|
+
* ```ts
|
|
3821
|
+
* const validateUser = Validation.keyed.make({
|
|
3822
|
+
* name: (s: string) => s.length > 0 ? Validation.make.passed(s) : Validation.make.failed("Name required"),
|
|
3823
|
+
* age: (n: number) => n >= 18 ? Validation.make.passed(n) : Validation.make.failed("Must be 18+"),
|
|
3824
|
+
* });
|
|
3825
|
+
*
|
|
3826
|
+
* const result = validateUser({ name: "", age: 16 });
|
|
3827
|
+
* // { name: Failed(["Name required"]), age: Failed(["Must be 18+"]) }
|
|
3828
|
+
* ```
|
|
3829
|
+
*/
|
|
3830
|
+
make: <T extends Record<string, any>, E = unknown>(validators: { readonly [K in keyof T]: (val: T[K]) => Validation<E, T[K]>; }) => (input: T) => { readonly [K in keyof T]: Validation<E, T[K]>; };
|
|
3831
|
+
is: {
|
|
3832
|
+
/**
|
|
3833
|
+
* Type guard checking if every keyed field is Passed.
|
|
3834
|
+
*
|
|
3835
|
+
* @see {@link Validation.keyed.is.failed} to check if any keyed field failed.
|
|
3836
|
+
*
|
|
3837
|
+
* @example
|
|
3838
|
+
* ```ts
|
|
3839
|
+
* if (Validation.keyed.is.passed(results)) {
|
|
3840
|
+
* // results.name is Passed<string>, results.age is Passed<number>
|
|
3841
|
+
* }
|
|
3842
|
+
* ```
|
|
3843
|
+
*/
|
|
3844
|
+
passed: <T extends Record<string, any>, E>(keyed: { readonly [K in keyof T]: Validation<E, T[K]>; }) => keyed is { readonly [K in keyof T]: Passed<T[K]>; };
|
|
3845
|
+
/**
|
|
3846
|
+
* Checks if at least one keyed field is Failed.
|
|
3847
|
+
*
|
|
3848
|
+
* @see {@link Validation.keyed.is.passed} to check if all keyed fields passed.
|
|
3849
|
+
*
|
|
3850
|
+
* @example
|
|
3851
|
+
* ```ts
|
|
3852
|
+
* if (Validation.keyed.is.failed(results)) {
|
|
3853
|
+
* console.log("Validation errors occurred");
|
|
3854
|
+
* }
|
|
3855
|
+
* ```
|
|
3856
|
+
*/
|
|
3857
|
+
failed: <T extends Record<string, any>, E>(keyed: { readonly [K in keyof T]: Validation<E, T[K]>; }) => boolean;
|
|
3858
|
+
};
|
|
3859
|
+
/**
|
|
3860
|
+
* Extracts all validated field values if every field passed.
|
|
3861
|
+
* Returns `Some(data)` if all passed, `None` if any field failed.
|
|
3862
|
+
*
|
|
3863
|
+
* @see {@link Validation.keyed.getErrors} to extract keyed field errors when failures occur.
|
|
3864
|
+
*
|
|
3865
|
+
* @example
|
|
3866
|
+
* ```ts
|
|
3867
|
+
* const passed = Validation.keyed.getPassed(results);
|
|
3868
|
+
* // Some({ name: "Alice", age: 30 }) or None
|
|
3869
|
+
* ```
|
|
3870
|
+
*/
|
|
3871
|
+
getPassed: <T extends Record<string, any>, E>(keyed: { readonly [K in keyof T]: Validation<E, T[K]>; }) => Maybe<T>;
|
|
3872
|
+
/**
|
|
3873
|
+
* Extracts keyed field errors if any field failed.
|
|
3874
|
+
* Symmetrical to `getPassed`: returns `Some(errors)` when there are failures,
|
|
3875
|
+
* or `None` if every field passed.
|
|
3876
|
+
*
|
|
3877
|
+
* @see {@link Validation.keyed.getPassed} to extract keyed values when all fields pass.
|
|
3878
|
+
*
|
|
3879
|
+
* @example
|
|
3880
|
+
* ```ts
|
|
3881
|
+
* const errors = Validation.keyed.getErrors(results);
|
|
3882
|
+
* // Some({ name: ["Name required"] }) or None
|
|
3883
|
+
* ```
|
|
3884
|
+
*/
|
|
3885
|
+
getErrors: <T extends Record<string, any>, E>(keyed: { readonly [K in keyof T]: Validation<E, T[K]>; }) => Maybe<Validation.KeyedErrors<T, E>>;
|
|
3886
|
+
};
|
|
3640
3887
|
};
|
|
3888
|
+
declare namespace Validation {
|
|
3889
|
+
type Passed<A> = WithKind<"Passed"> & WithValue<A>;
|
|
3890
|
+
type Failed<E> = WithKind<"Failed"> & WithErrors<E>;
|
|
3891
|
+
type KeyedErrors<T, E = unknown> = { readonly [K in keyof T]?: NonEmptyArr<E>; };
|
|
3892
|
+
type KeyedResult<T, E> = { readonly [K in keyof T]: Validation<E, T[K]>; };
|
|
3893
|
+
}
|
|
3641
3894
|
//#endregion
|
|
3642
3895
|
//#region src/Core/Task.d.ts
|
|
3643
3896
|
/**
|
|
@@ -3649,7 +3902,7 @@ declare const Validation: {
|
|
|
3649
3902
|
* return type using `Task.Result<E, A>` instead.
|
|
3650
3903
|
*
|
|
3651
3904
|
* An optional `AbortSignal` can be passed at the call site. Combinators like
|
|
3652
|
-
* `retry`, `
|
|
3905
|
+
* `retry`, `poll`, and `timeout` thread it automatically to every inner
|
|
3653
3906
|
* operation. Existing tasks that ignore the signal continue to work unchanged.
|
|
3654
3907
|
*
|
|
3655
3908
|
* Calling a Task returns a `Deferred<A>` — a one-shot async value that supports
|
|
@@ -3670,7 +3923,7 @@ declare const Validation: {
|
|
|
3670
3923
|
*
|
|
3671
3924
|
* @example
|
|
3672
3925
|
* ```ts
|
|
3673
|
-
* const getTimestamp: Task<number> = Task.
|
|
3926
|
+
* const getTimestamp: Task<number> = Task.make(Date.now());
|
|
3674
3927
|
*
|
|
3675
3928
|
* // Nothing runs yet — getTimestamp is just a description
|
|
3676
3929
|
* const formatted = pipe(
|
|
@@ -3689,15 +3942,15 @@ declare const Task: {
|
|
|
3689
3942
|
*
|
|
3690
3943
|
* @example
|
|
3691
3944
|
* ```ts
|
|
3692
|
-
* const task = Task.
|
|
3945
|
+
* const task = Task.make(42);
|
|
3693
3946
|
* const value = await task(); // 42
|
|
3694
3947
|
* ```
|
|
3695
3948
|
*/
|
|
3696
|
-
|
|
3949
|
+
make: <A>(value: A) => Task<A>;
|
|
3697
3950
|
from: {
|
|
3698
3951
|
/**
|
|
3699
3952
|
* Creates a Task from a lazy synchronous thunk.
|
|
3700
|
-
* Unlike `Task.
|
|
3953
|
+
* Unlike `Task.make(f())`, `from.sync` does not evaluate `f` until the Task is called.
|
|
3701
3954
|
*
|
|
3702
3955
|
* @example
|
|
3703
3956
|
* ```ts
|
|
@@ -3705,7 +3958,7 @@ declare const Task: {
|
|
|
3705
3958
|
* const ts = await t(); // called here, every time
|
|
3706
3959
|
* ```
|
|
3707
3960
|
*/
|
|
3708
|
-
sync: <A>(
|
|
3961
|
+
sync: <A>(fn: () => A) => Task<A>;
|
|
3709
3962
|
};
|
|
3710
3963
|
/**
|
|
3711
3964
|
* Wraps a Promise-returning thunk that may throw or reject,
|
|
@@ -3719,12 +3972,14 @@ declare const Task: {
|
|
|
3719
3972
|
* );
|
|
3720
3973
|
* ```
|
|
3721
3974
|
*/
|
|
3722
|
-
tryCatch: <A>(
|
|
3975
|
+
tryCatch: <A>(fn: (signal?: AbortSignal) => globalThis.Promise<A>, options: {
|
|
3723
3976
|
onError: (error: unknown) => A;
|
|
3724
3977
|
}) => Task<A>;
|
|
3725
3978
|
/**
|
|
3726
3979
|
* Transforms the value inside a Task.
|
|
3727
3980
|
*
|
|
3981
|
+
* @see {@link Task.chain} to sequence operations that return a Task.
|
|
3982
|
+
*
|
|
3728
3983
|
* @example
|
|
3729
3984
|
* ```ts
|
|
3730
3985
|
* pipe(
|
|
@@ -3733,9 +3988,11 @@ declare const Task: {
|
|
|
3733
3988
|
* )(); // Deferred<10>
|
|
3734
3989
|
* ```
|
|
3735
3990
|
*/
|
|
3736
|
-
map: <A, B>(
|
|
3991
|
+
map: <A, B>(transform: (value: A) => B) => (task: Task<A>) => Task<B>;
|
|
3737
3992
|
/**
|
|
3738
|
-
* Chains Task computations. Passes the resolved value of the first Task to
|
|
3993
|
+
* Chains Task computations. Passes the resolved value of the first Task to transform.
|
|
3994
|
+
*
|
|
3995
|
+
* @see {@link Task.map} to transform the resolved value without creating a new Task.
|
|
3739
3996
|
*
|
|
3740
3997
|
* @example
|
|
3741
3998
|
* ```ts
|
|
@@ -3749,22 +4006,24 @@ declare const Task: {
|
|
|
3749
4006
|
* )(); // Deferred<Preferences>
|
|
3750
4007
|
* ```
|
|
3751
4008
|
*/
|
|
3752
|
-
chain: <A, B>(
|
|
4009
|
+
chain: <A, B>(transform: (value: A) => Task<B>) => (task: Task<A>) => Task<B>;
|
|
3753
4010
|
/**
|
|
3754
4011
|
* Applies a function wrapped in a Task to a value wrapped in a Task.
|
|
3755
4012
|
* Both Tasks run in parallel.
|
|
3756
4013
|
*
|
|
4014
|
+
* @see {@link Task.all} to run multiple independent Tasks in parallel.
|
|
4015
|
+
*
|
|
3757
4016
|
* @example
|
|
3758
4017
|
* ```ts
|
|
3759
4018
|
* const add = (a: number) => (b: number) => a + b;
|
|
3760
4019
|
* pipe(
|
|
3761
|
-
* Task.
|
|
3762
|
-
* Task.
|
|
3763
|
-
* Task.
|
|
4020
|
+
* Task.make(add),
|
|
4021
|
+
* Task.apply(Task.make(5)),
|
|
4022
|
+
* Task.apply(Task.make(3))
|
|
3764
4023
|
* )(); // Deferred<8>
|
|
3765
4024
|
* ```
|
|
3766
4025
|
*/
|
|
3767
|
-
|
|
4026
|
+
apply: <A>(arg: Task<A>) => <B>(task: Task<(value: A) => B>) => Task<B>;
|
|
3768
4027
|
/**
|
|
3769
4028
|
* Executes a side effect on the value without changing the Task.
|
|
3770
4029
|
* Useful for logging or debugging.
|
|
@@ -3778,17 +4037,25 @@ declare const Task: {
|
|
|
3778
4037
|
* );
|
|
3779
4038
|
* ```
|
|
3780
4039
|
*/
|
|
3781
|
-
tap: <A>(
|
|
4040
|
+
tap: <A>(sideEffect: (value: A) => void) => (task: Task<A>) => Task<A>;
|
|
3782
4041
|
/**
|
|
3783
4042
|
* Runs multiple Tasks in parallel and collects their results.
|
|
4043
|
+
* An optional `concurrency` option limits the number of tasks executing at any given time.
|
|
4044
|
+
*
|
|
4045
|
+
* @see {@link Task.sequence} to run an array of Tasks concurrently.
|
|
4046
|
+
* @see {@link Task.sequential} to run an array of Tasks one after another in order.
|
|
3784
4047
|
*
|
|
3785
4048
|
* @example
|
|
3786
4049
|
* ```ts
|
|
3787
4050
|
* Task.all([loadConfig, detectLocale, loadTheme])();
|
|
3788
4051
|
* // Deferred<[Config, string, Theme]>
|
|
4052
|
+
*
|
|
4053
|
+
* Task.all([loadConfig, detectLocale, loadTheme], { concurrency: 2 })();
|
|
3789
4054
|
* ```
|
|
3790
4055
|
*/
|
|
3791
|
-
all: <T extends readonly Task<unknown>[]>(tasks: T
|
|
4056
|
+
all: <T extends readonly Task<unknown>[]>(tasks: T, options?: {
|
|
4057
|
+
concurrency?: number;
|
|
4058
|
+
}) => Task<{ [K in keyof T]: T[K] extends Task<infer A> ? A : never; }>;
|
|
3792
4059
|
/**
|
|
3793
4060
|
* Delays the execution of a Task by the specified duration.
|
|
3794
4061
|
* Useful for debouncing or rate limiting.
|
|
@@ -3796,16 +4063,18 @@ declare const Task: {
|
|
|
3796
4063
|
* @example
|
|
3797
4064
|
* ```ts
|
|
3798
4065
|
* pipe(
|
|
3799
|
-
* Task.
|
|
4066
|
+
* Task.make(42),
|
|
3800
4067
|
* Task.delay(Duration.seconds(1))
|
|
3801
4068
|
* )(); // Resolves after 1 second
|
|
3802
4069
|
* ```
|
|
3803
4070
|
*/
|
|
3804
|
-
delay: (duration: Duration) => <A>(
|
|
4071
|
+
delay: (duration: Duration) => <A>(task: Task<A>) => Task<A>;
|
|
3805
4072
|
/**
|
|
3806
4073
|
* Runs a Task a fixed number of times sequentially, collecting all results into an array.
|
|
3807
4074
|
* An optional delay duration can be inserted between runs.
|
|
3808
4075
|
*
|
|
4076
|
+
* @see {@link Task.poll} to repeatedly run a Task until a predicate is satisfied.
|
|
4077
|
+
*
|
|
3809
4078
|
* @example
|
|
3810
4079
|
* ```ts
|
|
3811
4080
|
* pipe(
|
|
@@ -3819,23 +4088,25 @@ declare const Task: {
|
|
|
3819
4088
|
delay?: Duration;
|
|
3820
4089
|
}) => <A>(task: Task<A>) => Task<readonly A[]>;
|
|
3821
4090
|
/**
|
|
3822
|
-
*
|
|
3823
|
-
* An optional delay duration can be inserted between runs.
|
|
3824
|
-
* An optional `
|
|
4091
|
+
* Polls a Task repeatedly until the result satisfies a predicate, returning that result.
|
|
4092
|
+
* An optional delay duration can be inserted between polling runs.
|
|
4093
|
+
* An optional `attempts` cap stops the loop after N calls — the last value is returned
|
|
3825
4094
|
* regardless of whether the predicate was satisfied.
|
|
3826
4095
|
*
|
|
4096
|
+
* @see {@link Task.repeat} to run a Task a fixed number of times.
|
|
4097
|
+
*
|
|
3827
4098
|
* @example
|
|
3828
4099
|
* ```ts
|
|
3829
4100
|
* pipe(
|
|
3830
4101
|
* checkStatus,
|
|
3831
|
-
* Task.
|
|
4102
|
+
* Task.poll({ until: (s) => s === "ready", delay: Duration.milliseconds(500) })
|
|
3832
4103
|
* )(); // polls every 500ms until status is "ready"
|
|
3833
4104
|
* ```
|
|
3834
4105
|
*/
|
|
3835
|
-
|
|
3836
|
-
|
|
4106
|
+
poll: <A>(options: {
|
|
4107
|
+
until: (value: A) => boolean;
|
|
3837
4108
|
delay?: Duration;
|
|
3838
|
-
|
|
4109
|
+
attempts?: number;
|
|
3839
4110
|
}) => (task: Task<A>) => Task<A>;
|
|
3840
4111
|
/**
|
|
3841
4112
|
* Resolves with the value of the first Task to complete. All Tasks start
|
|
@@ -3844,8 +4115,8 @@ declare const Task: {
|
|
|
3844
4115
|
*
|
|
3845
4116
|
* @example
|
|
3846
4117
|
* ```ts
|
|
3847
|
-
* const fast = Task.
|
|
3848
|
-
* const slow = Task.delay(Duration.milliseconds(200))(Task.
|
|
4118
|
+
* const fast = Task.make("fast");
|
|
4119
|
+
* const slow = Task.delay(Duration.milliseconds(200))(Task.make("slow"));
|
|
3849
4120
|
*
|
|
3850
4121
|
* await Task.race([fast, slow])(); // "fast"
|
|
3851
4122
|
* ```
|
|
@@ -3855,6 +4126,9 @@ declare const Task: {
|
|
|
3855
4126
|
* Runs an array of Tasks concurrently and collects their results in an array.
|
|
3856
4127
|
* Forward-propagates the call site's AbortSignal to all subtasks concurrently.
|
|
3857
4128
|
*
|
|
4129
|
+
* @see {@link Task.sequential} to run an array of tasks one after another in order.
|
|
4130
|
+
* @see {@link Task.all} to run an array or tuple of tasks in parallel with optional concurrency limit.
|
|
4131
|
+
*
|
|
3858
4132
|
* @example
|
|
3859
4133
|
* ```ts
|
|
3860
4134
|
* Task.sequence([loadConfig, detectLocale, loadTheme])();
|
|
@@ -3866,10 +4140,12 @@ declare const Task: {
|
|
|
3866
4140
|
* Runs an array of Tasks one at a time in order, collecting all results.
|
|
3867
4141
|
* Each Task starts only after the previous one resolves.
|
|
3868
4142
|
*
|
|
4143
|
+
* @see {@link Task.sequence} to run an array of tasks concurrently.
|
|
4144
|
+
*
|
|
3869
4145
|
* @example
|
|
3870
4146
|
* ```ts
|
|
3871
4147
|
* let log: number[] = [];
|
|
3872
|
-
* const makeTask = (n: number) => Task.
|
|
4148
|
+
* const makeTask = (n: number) => Task.make(n);
|
|
3873
4149
|
*
|
|
3874
4150
|
* await Task.sequential([makeTask(1), makeTask(2), makeTask(3)])();
|
|
3875
4151
|
* // log = [1, 2, 3] — tasks ran in order
|
|
@@ -3939,22 +4215,22 @@ declare const Task: {
|
|
|
3939
4215
|
*
|
|
3940
4216
|
* @example
|
|
3941
4217
|
* ```ts
|
|
3942
|
-
* pipe(Task.
|
|
4218
|
+
* pipe(Task.make(42), Task.bindTo("value")); // Task({ value: 42 })
|
|
3943
4219
|
* ```
|
|
3944
4220
|
*/
|
|
3945
|
-
bindTo: <K extends string>(key: K) => <A>(
|
|
4221
|
+
bindTo: <K extends string>(key: K) => <A>(task: Task<A>) => Task<{ [P in K]: A; }>;
|
|
3946
4222
|
/**
|
|
3947
4223
|
* Evaluates a new Task using the current accumulator and attaches the output to a new key.
|
|
3948
4224
|
*
|
|
3949
4225
|
* @example
|
|
3950
4226
|
* ```ts
|
|
3951
4227
|
* pipe(
|
|
3952
|
-
* Task.
|
|
3953
|
-
* Task.bind("b", ({ a }) => Task.
|
|
4228
|
+
* Task.make({ a: 1 }),
|
|
4229
|
+
* Task.bind("b", ({ a }) => Task.make(a + 1))
|
|
3954
4230
|
* ); // Task({ a: 1, b: 2 })
|
|
3955
4231
|
* ```
|
|
3956
4232
|
*/
|
|
3957
|
-
bind: <K extends string, A, B>(key: K,
|
|
4233
|
+
bind: <K extends string, A, B>(key: K, transform: (value: A) => Task<B>) => (task: Task<A>) => Task<A & { [P in K]: B; }>;
|
|
3958
4234
|
/**
|
|
3959
4235
|
* Creates a memoized version of a Task. The task is executed at most once on first call,
|
|
3960
4236
|
* and its resolved value is cached for all subsequent calls.
|
|
@@ -3995,29 +4271,29 @@ declare const Task: {
|
|
|
3995
4271
|
none: <A = never>() => Task.Maybe<A>;
|
|
3996
4272
|
};
|
|
3997
4273
|
from: {
|
|
3998
|
-
Maybe: <A>(
|
|
4274
|
+
Maybe: <A>(maybe: Maybe<A>) => Task.Maybe<A>;
|
|
3999
4275
|
nullable: <A>(value: A | null | undefined) => Task.Maybe<A>;
|
|
4000
4276
|
Result: <E, A>(result: Result<E, A>) => Task.Maybe<A>;
|
|
4001
4277
|
Task: <A>(task: Task<A>) => Task.Maybe<A>;
|
|
4002
4278
|
};
|
|
4003
|
-
tryCatch: <A>(
|
|
4004
|
-
map: <A, B>(
|
|
4005
|
-
chain: <A, B>(
|
|
4006
|
-
|
|
4007
|
-
fold: <A, B>(onNone: () => B, onSome: (
|
|
4279
|
+
tryCatch: <A>(fn: (signal?: AbortSignal) => Thenable<A>) => Task.Maybe<A>;
|
|
4280
|
+
map: <A, B>(transform: (value: A) => B) => (task: Task.Maybe<A>) => Task.Maybe<B>;
|
|
4281
|
+
chain: <A, B>(transform: (value: A) => Task.Maybe<B>) => (task: Task.Maybe<A>) => Task.Maybe<B>;
|
|
4282
|
+
apply: <A>(arg: Task.Maybe<A>) => <B>(task: Task.Maybe<(value: A) => B>) => Task.Maybe<B>;
|
|
4283
|
+
fold: <A, B>(onNone: () => B, onSome: (value: A) => B) => (task: Task.Maybe<A>) => Task<B>;
|
|
4008
4284
|
match: <A, B>(cases: {
|
|
4009
4285
|
none: () => B;
|
|
4010
|
-
some: (
|
|
4011
|
-
}) => (
|
|
4012
|
-
getOrElse: <B>(
|
|
4013
|
-
tap: <A>(
|
|
4014
|
-
filter: <A>(predicate: (
|
|
4286
|
+
some: (value: A) => B;
|
|
4287
|
+
}) => (task: Task.Maybe<A>) => Task<B>;
|
|
4288
|
+
getOrElse: <B>(fallback: () => B) => <A>(task: Task.Maybe<A>) => Task<A | B>;
|
|
4289
|
+
tap: <A>(sideEffect: (value: A) => void) => (task: Task.Maybe<A>) => Task.Maybe<A>;
|
|
4290
|
+
filter: <A>(predicate: (value: A) => boolean) => (task: Task.Maybe<A>) => Task.Maybe<A>;
|
|
4015
4291
|
to: {
|
|
4016
|
-
Result: <E>(onNone: () => E) => <A>(
|
|
4292
|
+
Result: <E>(onNone: () => E) => <A>(task: Task.Maybe<A>) => Task.Result<E, A>;
|
|
4017
4293
|
};
|
|
4018
|
-
bindTo: <K extends string>(key: K) => <A>(
|
|
4019
|
-
bind: <K extends string, A, B>(key: K,
|
|
4020
|
-
recover: <B>(fallback: () => Task.Maybe<B>) => <A>(
|
|
4294
|
+
bindTo: <K extends string>(key: K) => <A>(task: Task.Maybe<A>) => Task.Maybe<{ [P in K]: A; }>;
|
|
4295
|
+
bind: <K extends string, A, B>(key: K, transform: (value: A) => Task.Maybe<B>) => (task: Task.Maybe<A>) => Task.Maybe<A & { [P in K]: B; }>;
|
|
4296
|
+
recover: <B>(fallback: () => Task.Maybe<B>) => <A>(task: Task.Maybe<A>) => Task.Maybe<A | B>;
|
|
4021
4297
|
struct: <R extends Record<string, any>>(fields: { [K in keyof R]: Task.Maybe<R[K]>; }) => Task.Maybe<R>;
|
|
4022
4298
|
memoize: <A>(task: Task.Maybe<A>) => Task.Maybe<A>;
|
|
4023
4299
|
};
|
|
@@ -4032,36 +4308,83 @@ declare const Task: {
|
|
|
4032
4308
|
Result: <E, A>(result: Result<E, A>) => Task.Result<E, A>;
|
|
4033
4309
|
};
|
|
4034
4310
|
to: {
|
|
4035
|
-
Maybe: <E, A>(
|
|
4311
|
+
Maybe: <E, A>(task: Task.Result<E, A>) => Task.Maybe<A>;
|
|
4036
4312
|
};
|
|
4037
|
-
tryCatch: <E, A>(
|
|
4313
|
+
tryCatch: <E, A>(fn: (signal?: AbortSignal) => Thenable<A>, options: {
|
|
4038
4314
|
onError: (error: unknown) => E;
|
|
4039
4315
|
}) => Task.Result<E, A>;
|
|
4040
|
-
map: <E, A, B>(
|
|
4041
|
-
mapError: <E, F, A>(
|
|
4042
|
-
chain: <E2, A, B>(
|
|
4043
|
-
|
|
4316
|
+
map: <E, A, B>(transform: (value: A) => B) => (task: Task.Result<E, A>) => Task.Result<E, B>;
|
|
4317
|
+
mapError: <E, F, A>(transform: (error: E) => F) => (task: Task.Result<E, A>) => Task.Result<F, A>;
|
|
4318
|
+
chain: <E2, A, B>(transform: (value: A) => Task.Result<E2, B>) => <E1 = never
|
|
4319
|
+
/**
|
|
4320
|
+
* A lazy async computation that always resolves.
|
|
4321
|
+
*
|
|
4322
|
+
* Two guarantees:
|
|
4323
|
+
* - **Lazy** — nothing starts until you call it.
|
|
4324
|
+
* - **Infallible** — it never rejects. If failure is possible, encode it in the
|
|
4325
|
+
* return type using `Task.Result<E, A>` instead.
|
|
4326
|
+
*
|
|
4327
|
+
* An optional `AbortSignal` can be passed at the call site. Combinators like
|
|
4328
|
+
* `retry`, `poll`, and `timeout` thread it automatically to every inner
|
|
4329
|
+
* operation. Existing tasks that ignore the signal continue to work unchanged.
|
|
4330
|
+
*
|
|
4331
|
+
* Calling a Task returns a `Deferred<A>` — a one-shot async value that supports
|
|
4332
|
+
* `await` but has no `.catch()`, `.finally()`, or chainable `.then()`.
|
|
4333
|
+
*
|
|
4334
|
+
* **Consuming a Task:**
|
|
4335
|
+
*
|
|
4336
|
+
* Use `await task()` to run it and get the value directly:
|
|
4337
|
+
* ```ts
|
|
4338
|
+
* const value: number = await task();
|
|
4339
|
+
* ```
|
|
4340
|
+
*
|
|
4341
|
+
* When you need an explicit `Promise<A>` (e.g. for a third-party API), convert
|
|
4342
|
+
* the `Deferred` with `Deferred.to.Promise`:
|
|
4343
|
+
* ```ts
|
|
4344
|
+
* const p: Promise<number> = Deferred.to.Promise(task());
|
|
4345
|
+
* ```
|
|
4346
|
+
*
|
|
4347
|
+
* @example
|
|
4348
|
+
* ```ts
|
|
4349
|
+
* const getTimestamp: Task<number> = Task.make(Date.now());
|
|
4350
|
+
*
|
|
4351
|
+
* // Nothing runs yet — getTimestamp is just a description
|
|
4352
|
+
* const formatted = pipe(
|
|
4353
|
+
* getTimestamp,
|
|
4354
|
+
* Task.map(ts => new Date(ts).toISOString())
|
|
4355
|
+
* );
|
|
4356
|
+
*
|
|
4357
|
+
* // Execute when ready
|
|
4358
|
+
* const result = await formatted();
|
|
4359
|
+
* ```
|
|
4360
|
+
*/
|
|
4361
|
+
>(task: Task.Result<E1, A>) => Task.Result<E1 | E2, B>;
|
|
4362
|
+
fold: <E, A, B>(onErr: (error: E) => B, onOk: (value: A) => B) => (task: Task.Result<E, A>) => Task<B>;
|
|
4044
4363
|
match: <E, A, B>(cases: {
|
|
4045
|
-
err: (
|
|
4046
|
-
ok: (
|
|
4047
|
-
}) => (
|
|
4048
|
-
recover: <
|
|
4049
|
-
recoverUnless: <
|
|
4050
|
-
getOrElse: <B>(
|
|
4051
|
-
tap: <E, A>(
|
|
4052
|
-
tapError: <E, A>(
|
|
4053
|
-
|
|
4364
|
+
err: (error: E) => B;
|
|
4365
|
+
ok: (value: A) => B;
|
|
4366
|
+
}) => (task: Task.Result<E, A>) => Task<B>;
|
|
4367
|
+
recover: <E1, E2, B>(fallback: (error: E1) => Task.Result<E2, B>) => <A>(task: Task.Result<E1, A>) => Task.Result<E2, A | B>;
|
|
4368
|
+
recoverUnless: <E1, E2, B>(isBlocked: (error: E1) => boolean, fallback: (error: E1) => Task.Result<E2, B>) => <A>(task: Task.Result<E1, A>) => Task.Result<E1 | E2, A | B>;
|
|
4369
|
+
getOrElse: <B>(fallback: () => B) => <E, A>(task: Task.Result<E, A>) => Task<A | B>;
|
|
4370
|
+
tap: <E, A>(sideEffect: (value: A) => void) => (task: Task.Result<E, A>) => Task.Result<E, A>;
|
|
4371
|
+
tapError: <E, A>(sideEffect: (error: E) => void) => (task: Task.Result<E, A>) => Task.Result<E, A>;
|
|
4372
|
+
apply: <E2, A>(arg: Task.Result<E2, A>) => <B, E1 = never>(task: Task.Result<E1, (value: A) => B>) => Task.Result<E1 | E2, B>;
|
|
4054
4373
|
run: (signal?: AbortSignal) => <E, A>(task: Task.Result<E, A>) => Deferred<Result<E, A>>;
|
|
4055
|
-
bindTo: <K extends string>(key: K) => <E, A>(
|
|
4056
|
-
bind: <K extends string,
|
|
4374
|
+
bindTo: <K extends string>(key: K) => <E, A>(task: Task.Result<E, A>) => Task.Result<E, { [P in K]: A; }>;
|
|
4375
|
+
bind: <K extends string, E2, A, B>(key: K, transform: (value: A) => Task.Result<E2, B>) => <E1 = never>(task: Task.Result<E1, A>) => Task.Result<E1 | E2, A & { [P in K]: B; }>;
|
|
4057
4376
|
struct: <E, R extends Record<string, any>>(fields: { [K in keyof R]: Task.Result<E, R[K]>; }) => Task.Result<E, R>;
|
|
4058
|
-
retry: (policy: RetryPolicy
|
|
4377
|
+
retry: (policy: RetryPolicy, options?: {
|
|
4378
|
+
when?: (error: unknown) => boolean;
|
|
4379
|
+
}) => <E, A>(task: Task.Result<E, A>) => Task.Result<E, A>;
|
|
4059
4380
|
memoize: <E, A>(task: Task.Result<E, A>) => Task.Result<E, A>;
|
|
4060
4381
|
timeout: <E2>(options: {
|
|
4061
4382
|
duration: Duration;
|
|
4062
4383
|
onTimeout: () => E2;
|
|
4063
4384
|
}) => <E1 = never, A = unknown>(task: Task.Result<E1, A>) => Task.Result<E1 | E2, A>;
|
|
4064
4385
|
allSettled: <E, A>(tasks: ReadonlyArray<Task.Result<E, A>>) => Task<ReadonlyArray<Result<E, A>>>;
|
|
4386
|
+
ensure: <A, E2>(predicate: (value: A) => boolean, onFail: (value: A) => E2) => <E1 = never>(task: Task.Result<E1, A>) => Task.Result<E1 | E2, A>;
|
|
4387
|
+
bimap: <E1, E2, A, B>(onErr: (error: E1) => E2, onOk: (value: A) => B) => (task: Task.Result<E1, A>) => Task.Result<E2, B>;
|
|
4065
4388
|
};
|
|
4066
4389
|
Validation: {
|
|
4067
4390
|
make: {
|
|
@@ -4076,27 +4399,27 @@ declare const Task: {
|
|
|
4076
4399
|
Result: <E, A>(result: Result<E, A>) => Task.Validation<E, A>;
|
|
4077
4400
|
};
|
|
4078
4401
|
to: {
|
|
4079
|
-
Result: <E1, E2, A>(combineErrors: (errors: NonEmptyArr<E1>) => E2) => (
|
|
4080
|
-
Maybe: <E, A>(
|
|
4402
|
+
Result: <E1, E2, A>(combineErrors: (errors: NonEmptyArr<E1>) => E2) => (task: Task.Validation<E1, A>) => Task.Result<E2, A>;
|
|
4403
|
+
Maybe: <E, A>(task: Task.Validation<E, A>) => Task.Maybe<A>;
|
|
4081
4404
|
};
|
|
4082
|
-
tryCatch: <E, A>(
|
|
4405
|
+
tryCatch: <E, A>(fn: (signal?: AbortSignal) => Thenable<A>, options: {
|
|
4083
4406
|
onError: (error: unknown) => E;
|
|
4084
4407
|
}) => Task.Validation<E, A>;
|
|
4085
|
-
map: <E, A, B>(
|
|
4086
|
-
|
|
4087
|
-
fold: <E, A, B>(onFailed: (errors: NonEmptyArr<E>) => B, onPassed: (
|
|
4408
|
+
map: <E, A, B>(transform: (value: A) => B) => (task: Task.Validation<E, A>) => Task.Validation<E, B>;
|
|
4409
|
+
apply: <E2, A>(arg: Task.Validation<E2, A>) => <B, E1 = never>(task: Task.Validation<E1, (value: A) => B>) => Task.Validation<E1 | E2, B>;
|
|
4410
|
+
fold: <E, A, B>(onFailed: (errors: NonEmptyArr<E>) => B, onPassed: (value: A) => B) => (task: Task.Validation<E, A>) => Task<B>;
|
|
4088
4411
|
match: <E, A, B>(cases: {
|
|
4089
|
-
passed: (
|
|
4412
|
+
passed: (value: A) => B;
|
|
4090
4413
|
failed: (errors: NonEmptyArr<E>) => B;
|
|
4091
|
-
}) => (
|
|
4092
|
-
getOrElse: <B>(
|
|
4093
|
-
tap: <E, A>(
|
|
4094
|
-
recover: <
|
|
4095
|
-
recoverUnless: <
|
|
4414
|
+
}) => (task: Task.Validation<E, A>) => Task<B>;
|
|
4415
|
+
getOrElse: <B>(fallback: () => B) => <E, A>(task: Task.Validation<E, A>) => Task<A | B>;
|
|
4416
|
+
tap: <E, A>(sideEffect: (value: A) => void) => (task: Task.Validation<E, A>) => Task.Validation<E, A>;
|
|
4417
|
+
recover: <E1, E2, B>(fallback: (errors: NonEmptyArr<E1>) => Task.Validation<E2, B>) => <A>(task: Task.Validation<E1, A>) => Task.Validation<E2, A | B>;
|
|
4418
|
+
recoverUnless: <E1, E2, B>(isBlocked: (errors: NonEmptyArr<E1>) => boolean, fallback: (errors: NonEmptyArr<E1>) => Task.Validation<E2, B>) => <A>(task: Task.Validation<E1, A>) => Task.Validation<E1 | E2, A | B>;
|
|
4096
4419
|
product: <E, A, B>(first: Task.Validation<E, A>, second: Task.Validation<E, B>) => Task.Validation<E, readonly [A, B]>;
|
|
4097
|
-
productAll: <E, A>(
|
|
4098
|
-
mapError: <E, F, A>(
|
|
4099
|
-
tapError: <E, A>(
|
|
4420
|
+
productAll: <E, A>(validations: NonEmptyArr<Task.Validation<E, A>>) => Task.Validation<E, readonly A[]>;
|
|
4421
|
+
mapError: <E, F, A>(transform: (error: E) => F) => (task: Task.Validation<E, A>) => Task.Validation<F, A>;
|
|
4422
|
+
tapError: <E, A>(sideEffect: (errors: NonEmptyArr<E>) => void) => (task: Task.Validation<E, A>) => Task.Validation<E, A>;
|
|
4100
4423
|
struct: <E, R extends Record<string, any>>(fields: { [K in keyof R]: Task.Validation<E, R[K]>; }) => Task.Validation<E, R>;
|
|
4101
4424
|
memoize: <E, A>(task: Task.Validation<E, A>) => Task.Validation<E, A>;
|
|
4102
4425
|
};
|
|
@@ -4169,7 +4492,7 @@ declare const These: {
|
|
|
4169
4492
|
* These.make.both(42, "Deprecated API used"); // { kind: "Both", first: 42, second: "Deprecated API used" }
|
|
4170
4493
|
* ```
|
|
4171
4494
|
*/
|
|
4172
|
-
both: <A, B>(
|
|
4495
|
+
both: <A, B>(first: A, second: B) => TheseBoth<A, B>;
|
|
4173
4496
|
};
|
|
4174
4497
|
is: {
|
|
4175
4498
|
/**
|
|
@@ -4183,7 +4506,7 @@ declare const These: {
|
|
|
4183
4506
|
* }
|
|
4184
4507
|
* ```
|
|
4185
4508
|
*/
|
|
4186
|
-
first: <A, B>(
|
|
4509
|
+
first: <A, B>(these: These<A, B>) => these is TheseFirst<A>;
|
|
4187
4510
|
/**
|
|
4188
4511
|
* Type guard — checks if a These holds only a second value.
|
|
4189
4512
|
*
|
|
@@ -4195,7 +4518,7 @@ declare const These: {
|
|
|
4195
4518
|
* }
|
|
4196
4519
|
* ```
|
|
4197
4520
|
*/
|
|
4198
|
-
second: <A, B>(
|
|
4521
|
+
second: <A, B>(these: These<A, B>) => these is TheseSecond<B>;
|
|
4199
4522
|
/**
|
|
4200
4523
|
* Type guard — checks if a These holds both values simultaneously.
|
|
4201
4524
|
*
|
|
@@ -4207,11 +4530,13 @@ declare const These: {
|
|
|
4207
4530
|
* }
|
|
4208
4531
|
* ```
|
|
4209
4532
|
*/
|
|
4210
|
-
both: <A, B>(
|
|
4533
|
+
both: <A, B>(these: These<A, B>) => these is TheseBoth<A, B>;
|
|
4211
4534
|
};
|
|
4212
4535
|
/**
|
|
4213
4536
|
* Returns true if the These contains a first value (First or Both).
|
|
4214
4537
|
*
|
|
4538
|
+
* @see {@link These.hasSecond} to check if These contains a second value.
|
|
4539
|
+
*
|
|
4215
4540
|
* @example
|
|
4216
4541
|
* ```ts
|
|
4217
4542
|
* These.hasFirst(These.make.first(42)); // true
|
|
@@ -4219,10 +4544,12 @@ declare const These: {
|
|
|
4219
4544
|
* These.hasFirst(These.make.second("warn")); // false
|
|
4220
4545
|
* ```
|
|
4221
4546
|
*/
|
|
4222
|
-
hasFirst: <A, B>(
|
|
4547
|
+
hasFirst: <A, B>(these: These<A, B>) => these is TheseFirst<A> | TheseBoth<A, B>;
|
|
4223
4548
|
/**
|
|
4224
4549
|
* Returns true if the These contains a second value (Second or Both).
|
|
4225
4550
|
*
|
|
4551
|
+
* @see {@link These.hasFirst} to check if These contains a first value.
|
|
4552
|
+
*
|
|
4226
4553
|
* @example
|
|
4227
4554
|
* ```ts
|
|
4228
4555
|
* These.hasSecond(These.make.second("warn")); // true
|
|
@@ -4230,10 +4557,13 @@ declare const These: {
|
|
|
4230
4557
|
* These.hasSecond(These.make.first(42)); // false
|
|
4231
4558
|
* ```
|
|
4232
4559
|
*/
|
|
4233
|
-
hasSecond: <A, B>(
|
|
4560
|
+
hasSecond: <A, B>(these: These<A, B>) => these is TheseSecond<B> | TheseBoth<A, B>;
|
|
4234
4561
|
/**
|
|
4235
4562
|
* Transforms the first value, leaving the second unchanged.
|
|
4236
4563
|
*
|
|
4564
|
+
* @see {@link These.mapSecond} to transform the second element.
|
|
4565
|
+
* @see {@link These.mapBoth} to transform both elements.
|
|
4566
|
+
*
|
|
4237
4567
|
* @example
|
|
4238
4568
|
* ```ts
|
|
4239
4569
|
* pipe(These.make.first(5), These.mapFirst(n => n * 2)); // First(10)
|
|
@@ -4241,20 +4571,26 @@ declare const These: {
|
|
|
4241
4571
|
* pipe(These.make.second("warn"), These.mapFirst(n => n * 2)); // Second("warn")
|
|
4242
4572
|
* ```
|
|
4243
4573
|
*/
|
|
4244
|
-
mapFirst: <A, C>(
|
|
4574
|
+
mapFirst: <A, C>(transform: (first: A) => C) => <B>(these: These<A, B>) => These<C, B>;
|
|
4245
4575
|
/**
|
|
4246
4576
|
* Transforms the second value, leaving the first unchanged.
|
|
4247
4577
|
*
|
|
4578
|
+
* @see {@link These.mapFirst} to transform the first element.
|
|
4579
|
+
* @see {@link These.mapBoth} to transform both elements.
|
|
4580
|
+
*
|
|
4248
4581
|
* @example
|
|
4249
4582
|
* ```ts
|
|
4250
4583
|
* pipe(These.make.second("warn"), These.mapSecond(e => e.toUpperCase())); // Second("WARN")
|
|
4251
4584
|
* pipe(These.make.both(5, "warn"), These.mapSecond(e => e.toUpperCase())); // Both(5, "WARN")
|
|
4252
4585
|
* ```
|
|
4253
4586
|
*/
|
|
4254
|
-
mapSecond: <B, D>(
|
|
4587
|
+
mapSecond: <B, D>(transform: (second: B) => D) => <A>(these: These<A, B>) => These<A, D>;
|
|
4255
4588
|
/**
|
|
4256
4589
|
* Transforms both the first and second values independently.
|
|
4257
4590
|
*
|
|
4591
|
+
* @see {@link These.mapFirst} to transform only the first element.
|
|
4592
|
+
* @see {@link These.mapSecond} to transform only the second element.
|
|
4593
|
+
*
|
|
4258
4594
|
* @example
|
|
4259
4595
|
* ```ts
|
|
4260
4596
|
* pipe(
|
|
@@ -4263,10 +4599,12 @@ declare const These: {
|
|
|
4263
4599
|
* ); // Both(10, "WARN")
|
|
4264
4600
|
* ```
|
|
4265
4601
|
*/
|
|
4266
|
-
mapBoth: <A, C, B, D>(onFirst: (
|
|
4602
|
+
mapBoth: <A, C, B, D>(onFirst: (first: A) => C, onSecond: (second: B) => D) => (these: These<A, B>) => These<C, D>;
|
|
4267
4603
|
/**
|
|
4268
|
-
* Chains These computations by passing the first value to
|
|
4269
|
-
* Second propagates unchanged; First and Both apply
|
|
4604
|
+
* Chains These computations by passing the first value to transform.
|
|
4605
|
+
* Second propagates unchanged; First and Both apply transform to the first value.
|
|
4606
|
+
*
|
|
4607
|
+
* @see {@link These.chainSecond} to chain based on the second value.
|
|
4270
4608
|
*
|
|
4271
4609
|
* @example
|
|
4272
4610
|
* ```ts
|
|
@@ -4277,10 +4615,12 @@ declare const These: {
|
|
|
4277
4615
|
* pipe(These.make.second("warn"), These.chainFirst(double)); // Second("warn")
|
|
4278
4616
|
* ```
|
|
4279
4617
|
*/
|
|
4280
|
-
chainFirst: <A, B, C>(
|
|
4618
|
+
chainFirst: <A, B, C>(transform: (first: A) => These<C, B>) => (these: These<A, B>) => These<C, B>;
|
|
4281
4619
|
/**
|
|
4282
|
-
* Chains These computations by passing the second value to
|
|
4283
|
-
* First propagates unchanged; Second and Both apply
|
|
4620
|
+
* Chains These computations by passing the second value to transform.
|
|
4621
|
+
* First propagates unchanged; Second and Both apply transform to the second value.
|
|
4622
|
+
*
|
|
4623
|
+
* @see {@link These.chainFirst} to chain based on the first value.
|
|
4284
4624
|
*
|
|
4285
4625
|
* @example
|
|
4286
4626
|
* ```ts
|
|
@@ -4291,10 +4631,12 @@ declare const These: {
|
|
|
4291
4631
|
* pipe(These.make.first(5), These.chainSecond(shout)); // First(5)
|
|
4292
4632
|
* ```
|
|
4293
4633
|
*/
|
|
4294
|
-
chainSecond: <A, B, D>(
|
|
4634
|
+
chainSecond: <A, B, D>(transform: (second: B) => These<A, D>) => (these: These<A, B>) => These<A, D>;
|
|
4295
4635
|
/**
|
|
4296
4636
|
* Extracts a value from a These by providing handlers for all three cases.
|
|
4297
4637
|
*
|
|
4638
|
+
* @see {@link These.match} for named-case pattern matching with an object literal.
|
|
4639
|
+
*
|
|
4298
4640
|
* @example
|
|
4299
4641
|
* ```ts
|
|
4300
4642
|
* pipe(
|
|
@@ -4307,10 +4649,12 @@ declare const These: {
|
|
|
4307
4649
|
* );
|
|
4308
4650
|
* ```
|
|
4309
4651
|
*/
|
|
4310
|
-
fold: <A, B, C>(onFirst: (
|
|
4652
|
+
fold: <A, B, C>(onFirst: (first: A) => C, onSecond: (second: B) => C, onBoth: (first: A, second: B) => C) => (these: These<A, B>) => C;
|
|
4311
4653
|
/**
|
|
4312
4654
|
* Pattern matches on a These, returning the result of the matching case.
|
|
4313
4655
|
*
|
|
4656
|
+
* @see {@link These.fold} for positional argument pattern matching.
|
|
4657
|
+
*
|
|
4314
4658
|
* @example
|
|
4315
4659
|
* ```ts
|
|
4316
4660
|
* pipe(
|
|
@@ -4324,14 +4668,16 @@ declare const These: {
|
|
|
4324
4668
|
* ```
|
|
4325
4669
|
*/
|
|
4326
4670
|
match: <A, B, C>(cases: {
|
|
4327
|
-
first: (
|
|
4328
|
-
second: (
|
|
4329
|
-
both: (
|
|
4330
|
-
}) => (
|
|
4671
|
+
first: (first: A) => C;
|
|
4672
|
+
second: (second: B) => C;
|
|
4673
|
+
both: (first: A, second: B) => C;
|
|
4674
|
+
}) => (these: These<A, B>) => C;
|
|
4331
4675
|
/**
|
|
4332
4676
|
* Returns the first value, or a default if the These has no first value.
|
|
4333
4677
|
* The default can be a different type, widening the result to `A | C`.
|
|
4334
4678
|
*
|
|
4679
|
+
* @see {@link These.getSecondOrElse} to retrieve the second value with fallback.
|
|
4680
|
+
*
|
|
4335
4681
|
* @example
|
|
4336
4682
|
* ```ts
|
|
4337
4683
|
* pipe(These.make.first(5), These.getFirstOrElse(() => 0)); // 5
|
|
@@ -4340,11 +4686,13 @@ declare const These: {
|
|
|
4340
4686
|
* pipe(These.make.second("warn"), These.getFirstOrElse(() => null)); // null — typed as number | null
|
|
4341
4687
|
* ```
|
|
4342
4688
|
*/
|
|
4343
|
-
getFirstOrElse: <A, C>(
|
|
4689
|
+
getFirstOrElse: <A, C>(fallback: () => C) => <B>(these: These<A, B>) => A | C;
|
|
4344
4690
|
/**
|
|
4345
4691
|
* Returns the second value, or a default if the These has no second value.
|
|
4346
4692
|
* The default can be a different type, widening the result to `B | D`.
|
|
4347
4693
|
*
|
|
4694
|
+
* @see {@link These.getFirstOrElse} to retrieve the first value with fallback.
|
|
4695
|
+
*
|
|
4348
4696
|
* @example
|
|
4349
4697
|
* ```ts
|
|
4350
4698
|
* pipe(These.make.second("warn"), These.getSecondOrElse(() => "none")); // "warn"
|
|
@@ -4353,7 +4701,7 @@ declare const These: {
|
|
|
4353
4701
|
* pipe(These.make.first(5), These.getSecondOrElse(() => null)); // null — typed as string | null
|
|
4354
4702
|
* ```
|
|
4355
4703
|
*/
|
|
4356
|
-
getSecondOrElse: <B, D>(
|
|
4704
|
+
getSecondOrElse: <B, D>(fallback: () => D) => <A>(these: These<A, B>) => B | D;
|
|
4357
4705
|
/**
|
|
4358
4706
|
* Runs a side effect on the first value without changing the These.
|
|
4359
4707
|
* Useful for logging or debugging.
|
|
@@ -4363,7 +4711,7 @@ declare const These: {
|
|
|
4363
4711
|
* pipe(These.make.first(5), These.tap(console.log)); // logs 5, returns First(5)
|
|
4364
4712
|
* ```
|
|
4365
4713
|
*/
|
|
4366
|
-
tap: <A>(
|
|
4714
|
+
tap: <A>(sideEffect: (first: A) => void) => <B>(these: These<A, B>) => These<A, B>;
|
|
4367
4715
|
/**
|
|
4368
4716
|
* Swaps the roles of first and second values.
|
|
4369
4717
|
* - First(a) → Second(a)
|
|
@@ -4377,7 +4725,7 @@ declare const These: {
|
|
|
4377
4725
|
* These.swap(These.make.both(5, "warn")); // Both("warn", 5)
|
|
4378
4726
|
* ```
|
|
4379
4727
|
*/
|
|
4380
|
-
swap: <A, B>(
|
|
4728
|
+
swap: <A, B>(these: These<A, B>) => These<B, A>;
|
|
4381
4729
|
};
|
|
4382
4730
|
//#endregion
|
|
4383
|
-
export {
|
|
4731
|
+
export { Lens as A, Ordering as C, None as D, Maybe as E, EventBus as M, Equality as N, Some as O, Combinable as P, Pair as S, Op as T, RemoteData as _, Task as a, Reader as b, Validation as c, Ok$1 as d, Result as f, NotAsked as g, Loading as h, TheseSecond as i, Lazy as j, Logged as k, State$1 as l, Failure as m, TheseBoth as n, Failed as o, Resource as p, TheseFirst as r, Passed as s, These as t, Err$1 as u, Success as v, Optional as w, Predicate as x, Refinement as y };
|