@nlozgachev/pipelined 0.31.0 → 0.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{Task-CnF22Q2o.d.ts → Task-5na0QzS4.d.mts} +281 -66
- package/dist/{Task-BDcKwFAj.d.mts → Task-DeiWgoeJ.d.ts} +281 -66
- package/dist/{chunk-VIC54JR4.mjs → chunk-FZX4MTRI.mjs} +135 -21
- package/dist/{chunk-SDGDJ7CU.mjs → chunk-GSTKY7MF.mjs} +158 -35
- package/dist/chunk-IPP4XFYH.mjs +0 -0
- package/dist/chunk-VWVPHDZO.mjs +29 -0
- package/dist/{chunk-FWYOEWJ2.mjs → chunk-W53ZYTLX.mjs} +98 -4
- package/dist/core.d.mts +249 -9
- package/dist/core.d.ts +249 -9
- package/dist/core.js +366 -104
- package/dist/core.mjs +11 -2
- package/dist/index.d.mts +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.js +465 -114
- package/dist/index.mjs +17 -6
- package/dist/types.d.mts +104 -2
- package/dist/types.d.ts +104 -2
- package/dist/types.js +20 -0
- package/dist/types.mjs +6 -3
- package/dist/utils.d.mts +124 -2
- package/dist/utils.d.ts +124 -2
- package/dist/utils.js +266 -28
- package/dist/utils.mjs +3 -2
- package/package.json +1 -1
- package/dist/NonEmptyList-BlGFjor5.d.mts +0 -30
- package/dist/NonEmptyList-BlGFjor5.d.ts +0 -30
- package/dist/chunk-BYWKZLHM.mjs +0 -10
|
@@ -1,56 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
declare const _deferred: unique symbol;
|
|
4
|
-
/**
|
|
5
|
-
* A nominally typed, one-shot async value that supports `await` but enforces infallibility.
|
|
6
|
-
*
|
|
7
|
-
* Two design choices work together to make the guarantee structural rather than documentary:
|
|
8
|
-
*
|
|
9
|
-
* - The phantom `[_deferred]` symbol makes the type **nominal**: only values produced by
|
|
10
|
-
* `Deferred.fromPromise` satisfy it. A plain object `{ then: ... }` does not.
|
|
11
|
-
* - The single-parameter `.then()` **excludes rejection handlers** by construction. There is
|
|
12
|
-
* no second argument to pass, so chaining and `.catch()` are impossible.
|
|
13
|
-
*
|
|
14
|
-
* This makes `Deferred<A>` the natural return type for `Task<A>`, which is guaranteed to
|
|
15
|
-
* never reject.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```ts
|
|
19
|
-
* const value = await Deferred.fromPromise(Promise.resolve(42));
|
|
20
|
-
* // value === 42
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
type Deferred<A> = {
|
|
24
|
-
readonly [_deferred]: A;
|
|
25
|
-
readonly then: (onfulfilled: (value: A) => unknown) => void;
|
|
26
|
-
};
|
|
27
|
-
declare namespace Deferred {
|
|
28
|
-
/**
|
|
29
|
-
* Wraps a `Promise` into a `Deferred`, structurally excluding rejection handlers,
|
|
30
|
-
* `.catch()`, `.finally()`, and chainable `.then()`.
|
|
31
|
-
*
|
|
32
|
-
* **Precondition**: `p` must never reject. If `p` rejects, the returned `Deferred` will
|
|
33
|
-
* never resolve — `await`-ing it will hang indefinitely. Use `TaskResult.tryCatch` to
|
|
34
|
-
* handle operations that may fail before converting to a `Deferred`.
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```ts
|
|
38
|
-
* const d = Deferred.fromPromise(Promise.resolve("hello"));
|
|
39
|
-
* const value = await d; // "hello"
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
const fromPromise: <A>(p: Promise<A>) => Deferred<A>;
|
|
43
|
-
/**
|
|
44
|
-
* Converts a `Deferred` back into a `Promise`.
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* ```ts
|
|
48
|
-
* const p = Deferred.toPromise(Deferred.fromPromise(Promise.resolve(42)));
|
|
49
|
-
* // p is Promise<42>
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
|
-
const toPromise: <A>(d: Deferred<A>) => Promise<A>;
|
|
53
|
-
}
|
|
1
|
+
import { NonEmptyList, Duration } from './types.js';
|
|
54
2
|
|
|
55
3
|
type WithKind<K extends string> = {
|
|
56
4
|
readonly kind: K;
|
|
@@ -275,6 +223,44 @@ declare namespace Result {
|
|
|
275
223
|
* ```
|
|
276
224
|
*/
|
|
277
225
|
const fromPredicate: <E, A>(pred: (a: A) => boolean, onFalse: (a: A) => E) => (a: A) => Result<E, A>;
|
|
226
|
+
/**
|
|
227
|
+
* Creates a Result from a nullable value.
|
|
228
|
+
* Returns Ok if the value is not null or undefined, error from onNull otherwise.
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```ts
|
|
232
|
+
* pipe(null, Result.fromNullable(() => "is null")); // Error("is null")
|
|
233
|
+
* pipe(42, Result.fromNullable(() => "is null")); // Ok(42)
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
const fromNullable: <E>(onNull: () => E) => <A>(value: A | null | undefined) => Result<E, A>;
|
|
237
|
+
/**
|
|
238
|
+
* Creates a Result from a Maybe.
|
|
239
|
+
* Some becomes Ok, None becomes error from onNone.
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```ts
|
|
243
|
+
* pipe(Maybe.none(), Result.fromMaybe(() => "is none")); // Error("is none")
|
|
244
|
+
* pipe(Maybe.some(42), Result.fromMaybe(() => "is none")); // Ok(42)
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
247
|
+
const fromMaybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => Result<E, A>;
|
|
248
|
+
/**
|
|
249
|
+
* Wraps a throwing function of any arguments, returning a new function
|
|
250
|
+
* that catches errors and returns a Result.
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```ts
|
|
254
|
+
* const safeParse = Result.fromThrowable(
|
|
255
|
+
* (s: string) => JSON.parse(s),
|
|
256
|
+
* (e) => new Error(`Parse error: ${e}`)
|
|
257
|
+
* );
|
|
258
|
+
*
|
|
259
|
+
* safeParse('{"a":1}'); // Ok({ a: 1 })
|
|
260
|
+
* safeParse('invalid'); // Error(Error)
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
263
|
+
const fromThrowable: <Args extends readonly unknown[], A, E>(f: (...args: Args) => A, onError: (e: unknown) => E) => (...args: Args) => Result<E, A>;
|
|
278
264
|
/**
|
|
279
265
|
* Recovers from an error by providing a fallback Result.
|
|
280
266
|
* The fallback can produce a different success type, widening the result to `Result<E, A | B>`.
|
|
@@ -536,6 +522,223 @@ declare namespace Maybe {
|
|
|
536
522
|
const ap: <A>(arg: Maybe<A>) => <B>(data: Maybe<(a: A) => B>) => Maybe<B>;
|
|
537
523
|
}
|
|
538
524
|
|
|
525
|
+
declare const _deferred: unique symbol;
|
|
526
|
+
/**
|
|
527
|
+
* A nominally typed, one-shot async value that supports `await` but enforces infallibility.
|
|
528
|
+
*
|
|
529
|
+
* Two design choices work together to make the guarantee structural rather than documentary:
|
|
530
|
+
*
|
|
531
|
+
* - The phantom `[_deferred]` symbol makes the type **nominal**: only values produced by
|
|
532
|
+
* `Deferred.fromPromise` satisfy it. A plain object `{ then: ... }` does not.
|
|
533
|
+
* - The single-parameter `.then()` **excludes rejection handlers** by construction. There is
|
|
534
|
+
* no second argument to pass, so chaining and `.catch()` are impossible.
|
|
535
|
+
*
|
|
536
|
+
* This makes `Deferred<A>` the natural return type for `Task<A>`, which is guaranteed to
|
|
537
|
+
* never reject.
|
|
538
|
+
*
|
|
539
|
+
* @example
|
|
540
|
+
* ```ts
|
|
541
|
+
* const value = await Deferred.fromPromise(Promise.resolve(42));
|
|
542
|
+
* // value === 42
|
|
543
|
+
* ```
|
|
544
|
+
*/
|
|
545
|
+
type Deferred<A> = {
|
|
546
|
+
readonly [_deferred]: A;
|
|
547
|
+
readonly then: (onfulfilled: (value: A) => unknown) => void;
|
|
548
|
+
};
|
|
549
|
+
declare namespace Deferred {
|
|
550
|
+
/**
|
|
551
|
+
* Wraps a `Promise` into a `Deferred`, structurally excluding rejection handlers,
|
|
552
|
+
* `.catch()`, `.finally()`, and chainable `.then()`.
|
|
553
|
+
*
|
|
554
|
+
* **Precondition**: `p` must never reject. If `p` rejects, the returned `Deferred` will
|
|
555
|
+
* never resolve — `await`-ing it will hang indefinitely. Use `TaskResult.tryCatch` to
|
|
556
|
+
* handle operations that may fail before converting to a `Deferred`.
|
|
557
|
+
*
|
|
558
|
+
* @example
|
|
559
|
+
* ```ts
|
|
560
|
+
* const d = Deferred.fromPromise(Promise.resolve("hello"));
|
|
561
|
+
* const value = await d; // "hello"
|
|
562
|
+
* ```
|
|
563
|
+
*/
|
|
564
|
+
const fromPromise: <A>(p: Promise<A>) => Deferred<A>;
|
|
565
|
+
/**
|
|
566
|
+
* Converts a `Deferred` back into a `Promise`.
|
|
567
|
+
*
|
|
568
|
+
* @example
|
|
569
|
+
* ```ts
|
|
570
|
+
* const p = Deferred.toPromise(Deferred.fromPromise(Promise.resolve(42)));
|
|
571
|
+
* // p is Promise<42>
|
|
572
|
+
* ```
|
|
573
|
+
*/
|
|
574
|
+
const toPromise: <A>(d: Deferred<A>) => Promise<A>;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* A function that checks whether two values of type `A` are equal.
|
|
579
|
+
* Use built-in instances (`Equality.string`, `Equality.number`, etc.) as starting points,
|
|
580
|
+
* then adapt them with `Equality.by` and combine them with `Equality.and`.
|
|
581
|
+
*
|
|
582
|
+
* @example
|
|
583
|
+
* ```ts
|
|
584
|
+
* type User = { id: string; name: string };
|
|
585
|
+
* const byId = pipe(Equality.string, Equality.by((u: User) => u.id));
|
|
586
|
+
*
|
|
587
|
+
* pipe(users, Arr.uniqWith(byId));
|
|
588
|
+
* ```
|
|
589
|
+
*/
|
|
590
|
+
type Equality<A> = (a: A, b: A) => boolean;
|
|
591
|
+
declare namespace Equality {
|
|
592
|
+
/**
|
|
593
|
+
* Equality for strings. Case-sensitive.
|
|
594
|
+
*
|
|
595
|
+
* @example
|
|
596
|
+
* ```ts
|
|
597
|
+
* Equality.string("hello", "hello"); // true
|
|
598
|
+
* Equality.string("hello", "Hello"); // false
|
|
599
|
+
* ```
|
|
600
|
+
*/
|
|
601
|
+
const string: Equality<string>;
|
|
602
|
+
/**
|
|
603
|
+
* Equality for numbers. Uses strict equality.
|
|
604
|
+
*
|
|
605
|
+
* @example
|
|
606
|
+
* ```ts
|
|
607
|
+
* Equality.number(42, 42); // true
|
|
608
|
+
* ```
|
|
609
|
+
*/
|
|
610
|
+
const number: Equality<number>;
|
|
611
|
+
/**
|
|
612
|
+
* Equality for booleans.
|
|
613
|
+
*
|
|
614
|
+
* @example
|
|
615
|
+
* ```ts
|
|
616
|
+
* Equality.boolean(true, true); // true
|
|
617
|
+
* ```
|
|
618
|
+
*/
|
|
619
|
+
const boolean: Equality<boolean>;
|
|
620
|
+
/**
|
|
621
|
+
* Equality for `Date` values. Compares by numeric time value.
|
|
622
|
+
*
|
|
623
|
+
* @example
|
|
624
|
+
* ```ts
|
|
625
|
+
* Equality.date(new Date("2024-01-01"), new Date("2024-01-01")); // true
|
|
626
|
+
* ```
|
|
627
|
+
*/
|
|
628
|
+
const date: Equality<Date>;
|
|
629
|
+
/**
|
|
630
|
+
* Lifts an element equality into an array equality. Two arrays are equal if they have the
|
|
631
|
+
* same length and every element pair is equal under `eq`.
|
|
632
|
+
*
|
|
633
|
+
* @example
|
|
634
|
+
* ```ts
|
|
635
|
+
* Equality.array(Equality.number)([1, 2, 3], [1, 2, 3]); // true
|
|
636
|
+
* ```
|
|
637
|
+
*/
|
|
638
|
+
const array: <A>(eq: Equality<A>) => Equality<readonly A[]>;
|
|
639
|
+
/**
|
|
640
|
+
* Adapts an equality for type `A` into an equality for type `B` by extracting a field.
|
|
641
|
+
* Read as "equality by this field": `pipe(Equality.string, Equality.by(u => u.name))`.
|
|
642
|
+
*
|
|
643
|
+
* @example
|
|
644
|
+
* ```ts
|
|
645
|
+
* type Product = { id: string; price: number };
|
|
646
|
+
* const byId = pipe(Equality.string, Equality.by((p: Product) => p.id));
|
|
647
|
+
* byId({ id: "p1", price: 9 }, { id: "p1", price: 12 }); // true
|
|
648
|
+
* ```
|
|
649
|
+
*/
|
|
650
|
+
const by: <A, B>(f: (b: B) => A) => (eq: Equality<A>) => Equality<B>;
|
|
651
|
+
/**
|
|
652
|
+
* Combines two equalities with logical AND. Both must pass for two values to be considered equal.
|
|
653
|
+
* Data-last: the first equality is the data being piped.
|
|
654
|
+
*
|
|
655
|
+
* @example
|
|
656
|
+
* ```ts
|
|
657
|
+
* const exact = pipe(byName, Equality.and(byRole));
|
|
658
|
+
* exact(userA, userB); // true only if name AND role match
|
|
659
|
+
* ```
|
|
660
|
+
*/
|
|
661
|
+
const and: <A>(eq2: Equality<A>) => (eq1: Equality<A>) => Equality<A>;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
/**
|
|
665
|
+
* A function that orders two values of type `A`. Returns a negative number when `a` comes before
|
|
666
|
+
* `b`, a positive number when `a` comes after `b`, and `0` when they are equal.
|
|
667
|
+
*
|
|
668
|
+
* Compatible with `Array.prototype.sort` and `Arr.sortWith`.
|
|
669
|
+
*
|
|
670
|
+
* @example
|
|
671
|
+
* ```ts
|
|
672
|
+
* type Employee = { name: string; salary: number };
|
|
673
|
+
*
|
|
674
|
+
* const byName = pipe(Ordering.string, Ordering.by((e: Employee) => e.name));
|
|
675
|
+
* const bySalary = pipe(Ordering.number, Ordering.by((e: Employee) => e.salary));
|
|
676
|
+
*
|
|
677
|
+
* pipe(employees, Arr.sortWith(pipe(byName, Ordering.thenBy(bySalary))));
|
|
678
|
+
* ```
|
|
679
|
+
*/
|
|
680
|
+
type Ordering<A> = (a: A, b: A) => number;
|
|
681
|
+
declare namespace Ordering {
|
|
682
|
+
/**
|
|
683
|
+
* Alphabetical ordering for strings.
|
|
684
|
+
*
|
|
685
|
+
* @example
|
|
686
|
+
* ```ts
|
|
687
|
+
* Ordering.string("apple", "banana"); // negative
|
|
688
|
+
* ```
|
|
689
|
+
*/
|
|
690
|
+
const string: Ordering<string>;
|
|
691
|
+
/**
|
|
692
|
+
* Numeric ordering. Equivalent to `(a, b) => a - b`.
|
|
693
|
+
*
|
|
694
|
+
* @example
|
|
695
|
+
* ```ts
|
|
696
|
+
* pipe([3, 1, 2], Arr.sortWith(Ordering.number)); // [1, 2, 3]
|
|
697
|
+
* ```
|
|
698
|
+
*/
|
|
699
|
+
const number: Ordering<number>;
|
|
700
|
+
/**
|
|
701
|
+
* Ordering for `Date` values by numeric time value.
|
|
702
|
+
*
|
|
703
|
+
* @example
|
|
704
|
+
* ```ts
|
|
705
|
+
* pipe(dates, Arr.sortWith(Ordering.date)); // earliest first
|
|
706
|
+
* ```
|
|
707
|
+
*/
|
|
708
|
+
const date: Ordering<Date>;
|
|
709
|
+
/**
|
|
710
|
+
* Flips the direction of an ordering.
|
|
711
|
+
*
|
|
712
|
+
* @example
|
|
713
|
+
* ```ts
|
|
714
|
+
* pipe([3, 1, 2], Arr.sortWith(Ordering.reverse(Ordering.number))); // [3, 2, 1]
|
|
715
|
+
* ```
|
|
716
|
+
*/
|
|
717
|
+
const reverse: <A>(ord: Ordering<A>) => Ordering<A>;
|
|
718
|
+
/**
|
|
719
|
+
* Chains two orderings: the second is used only when the first returns `0`.
|
|
720
|
+
* Data-last: the first ordering is the data being piped.
|
|
721
|
+
*
|
|
722
|
+
* @example
|
|
723
|
+
* ```ts
|
|
724
|
+
* const byDeptThenSalary = pipe(byDept, Ordering.thenBy(bySalary));
|
|
725
|
+
* ```
|
|
726
|
+
*/
|
|
727
|
+
const thenBy: <A>(ord2: Ordering<A>) => (ord1: Ordering<A>) => Ordering<A>;
|
|
728
|
+
/**
|
|
729
|
+
* Adapts an ordering for type `A` into an ordering for type `B` by extracting a field.
|
|
730
|
+
* Read as "ordering by this field": `pipe(Ordering.number, Ordering.by(p => p.price))`.
|
|
731
|
+
*
|
|
732
|
+
* @example
|
|
733
|
+
* ```ts
|
|
734
|
+
* type Product = { name: string; price: number };
|
|
735
|
+
* const byPrice = pipe(Ordering.number, Ordering.by((p: Product) => p.price));
|
|
736
|
+
* pipe(products, Arr.sortWith(byPrice));
|
|
737
|
+
* ```
|
|
738
|
+
*/
|
|
739
|
+
const by: <A, B>(f: (b: B) => A) => (ord: Ordering<A>) => Ordering<B>;
|
|
740
|
+
}
|
|
741
|
+
|
|
539
742
|
/**
|
|
540
743
|
* A lazy async computation that always resolves.
|
|
541
744
|
*
|
|
@@ -679,37 +882,37 @@ declare namespace Task {
|
|
|
679
882
|
*/
|
|
680
883
|
const all: <T extends readonly Task<unknown>[]>(tasks: T) => Task<{ [K in keyof T]: T[K] extends Task<infer A> ? A : never; }>;
|
|
681
884
|
/**
|
|
682
|
-
* Delays the execution of a Task by the specified milliseconds.
|
|
885
|
+
* Delays the execution of a Task by the specified milliseconds or duration.
|
|
683
886
|
* Useful for debouncing or rate limiting.
|
|
684
887
|
*
|
|
685
888
|
* @example
|
|
686
889
|
* ```ts
|
|
687
890
|
* pipe(
|
|
688
891
|
* Task.resolve(42),
|
|
689
|
-
* Task.delay(
|
|
892
|
+
* Task.delay(Duration.seconds(1))
|
|
690
893
|
* )(); // Resolves after 1 second
|
|
691
894
|
* ```
|
|
692
895
|
*/
|
|
693
|
-
const delay: (ms: number) => <A>(data: Task<A>) => Task<A>;
|
|
896
|
+
const delay: (ms: number | Duration) => <A>(data: Task<A>) => Task<A>;
|
|
694
897
|
/**
|
|
695
898
|
* Runs a Task a fixed number of times sequentially, collecting all results into an array.
|
|
696
|
-
* An optional delay (ms) can be inserted between runs.
|
|
899
|
+
* An optional delay (ms or Duration) can be inserted between runs.
|
|
697
900
|
*
|
|
698
901
|
* @example
|
|
699
902
|
* ```ts
|
|
700
903
|
* pipe(
|
|
701
904
|
* pollSensor,
|
|
702
|
-
* Task.repeat({ times: 5, delay:
|
|
905
|
+
* Task.repeat({ times: 5, delay: Duration.seconds(1) })
|
|
703
906
|
* )(); // Task<Reading[]> — 5 readings, one per second
|
|
704
907
|
* ```
|
|
705
908
|
*/
|
|
706
909
|
const repeat: (options: {
|
|
707
910
|
times: number;
|
|
708
|
-
delay?: number;
|
|
911
|
+
delay?: number | Duration;
|
|
709
912
|
}) => <A>(task: Task<A>) => Task<readonly A[]>;
|
|
710
913
|
/**
|
|
711
914
|
* Runs a Task repeatedly until the result satisfies a predicate, returning that result.
|
|
712
|
-
* An optional delay (ms) can be inserted between runs.
|
|
915
|
+
* An optional delay (ms or Duration) can be inserted between runs.
|
|
713
916
|
* An optional `maxAttempts` cap stops the loop after N calls — the last value is returned
|
|
714
917
|
* regardless of whether the predicate was satisfied.
|
|
715
918
|
*
|
|
@@ -717,18 +920,19 @@ declare namespace Task {
|
|
|
717
920
|
* ```ts
|
|
718
921
|
* pipe(
|
|
719
922
|
* checkStatus,
|
|
720
|
-
* Task.repeatUntil({ when: (s) => s === "ready", delay: 500 })
|
|
923
|
+
* Task.repeatUntil({ when: (s) => s === "ready", delay: Duration.milliseconds(500) })
|
|
721
924
|
* )(); // polls every 500ms until status is "ready"
|
|
722
925
|
* ```
|
|
723
926
|
*/
|
|
724
927
|
const repeatUntil: <A>(options: {
|
|
725
928
|
when: (a: A) => boolean;
|
|
726
|
-
delay?: number;
|
|
929
|
+
delay?: number | Duration;
|
|
727
930
|
maxAttempts?: number;
|
|
728
931
|
}) => (task: Task<A>) => Task<A>;
|
|
729
932
|
/**
|
|
730
933
|
* Resolves with the value of the first Task to complete. All Tasks start
|
|
731
|
-
* immediately
|
|
934
|
+
* immediately. When one resolves, the other tasks are cancelled (aborted)
|
|
935
|
+
* downstream.
|
|
732
936
|
*
|
|
733
937
|
* @example
|
|
734
938
|
* ```ts
|
|
@@ -739,6 +943,17 @@ declare namespace Task {
|
|
|
739
943
|
* ```
|
|
740
944
|
*/
|
|
741
945
|
const race: <A>(tasks: ReadonlyArray<Task<A>>) => Task<A>;
|
|
946
|
+
/**
|
|
947
|
+
* Runs an array of Tasks concurrently and collects their results in an array.
|
|
948
|
+
* Forward-propagates the call site's AbortSignal to all subtasks concurrently.
|
|
949
|
+
*
|
|
950
|
+
* @example
|
|
951
|
+
* ```ts
|
|
952
|
+
* Task.sequence([loadConfig, detectLocale, loadTheme])();
|
|
953
|
+
* // Deferred<[Config, string, Theme]>
|
|
954
|
+
* ```
|
|
955
|
+
*/
|
|
956
|
+
const sequence: <A>(tasks: ReadonlyArray<Task<A>>) => Task<ReadonlyArray<A>>;
|
|
742
957
|
/**
|
|
743
958
|
* Runs an array of Tasks one at a time in order, collecting all results.
|
|
744
959
|
* Each Task starts only after the previous one resolves.
|
|
@@ -766,12 +981,12 @@ declare namespace Task {
|
|
|
766
981
|
* ```ts
|
|
767
982
|
* pipe(
|
|
768
983
|
* heavyComputation,
|
|
769
|
-
* Task.timeout(
|
|
984
|
+
* Task.timeout(Duration.seconds(5), () => "timed out"),
|
|
770
985
|
* TaskResult.chain(processResult)
|
|
771
986
|
* );
|
|
772
987
|
* ```
|
|
773
988
|
*/
|
|
774
|
-
const timeout: <E>(ms: number, onTimeout: () => E) => <A>(task: Task<A>) => Task<Result<E, A>>;
|
|
989
|
+
const timeout: <E>(ms: number | Duration, onTimeout: () => E) => <A>(task: Task<A>) => Task<Result<E, A>>;
|
|
775
990
|
/**
|
|
776
991
|
* Creates a Task paired with an `abort` handle. Calling `abort()` cancels the
|
|
777
992
|
* current in-flight call immediately. Unlike a one-shot abort, calling `task()`
|
|
@@ -812,4 +1027,4 @@ declare namespace Task {
|
|
|
812
1027
|
const run: (signal?: AbortSignal) => <A>(task: Task<A>) => Promise<A>;
|
|
813
1028
|
}
|
|
814
1029
|
|
|
815
|
-
export { Deferred as D,
|
|
1030
|
+
export { Deferred as D, Equality as E, Maybe as M, type None as N, type Ok as O, Result as R, type Some as S, Task as T, type WithValue as W, type Error as a, Ordering as b, type WithLog as c, type WithKind as d, type WithError as e, type RetryOptions as f, type TimeoutOptions as g, type WithTimeout as h, type WithMinInterval as i, type WithCooldown as j, type WithConcurrency as k, type WithSize as l, type WithMs as m, type WithN as n, type WithErrors as o, type WithFirst as p, type WithSecond as q };
|
|
@@ -3,7 +3,79 @@ import {
|
|
|
3
3
|
Maybe,
|
|
4
4
|
Result,
|
|
5
5
|
Task
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-GSTKY7MF.mjs";
|
|
7
|
+
|
|
8
|
+
// src/Core/Combinable.ts
|
|
9
|
+
var Combinable;
|
|
10
|
+
((Combinable2) => {
|
|
11
|
+
Combinable2.string = {
|
|
12
|
+
empty: "",
|
|
13
|
+
combine: (b) => (a) => a + b
|
|
14
|
+
};
|
|
15
|
+
Combinable2.sum = {
|
|
16
|
+
empty: 0,
|
|
17
|
+
combine: (b) => (a) => a + b
|
|
18
|
+
};
|
|
19
|
+
Combinable2.product = {
|
|
20
|
+
empty: 1,
|
|
21
|
+
combine: (b) => (a) => a * b
|
|
22
|
+
};
|
|
23
|
+
Combinable2.all = {
|
|
24
|
+
empty: true,
|
|
25
|
+
combine: (b) => (a) => a && b
|
|
26
|
+
};
|
|
27
|
+
Combinable2.any = {
|
|
28
|
+
empty: false,
|
|
29
|
+
combine: (b) => (a) => a || b
|
|
30
|
+
};
|
|
31
|
+
Combinable2.array = () => ({
|
|
32
|
+
empty: [],
|
|
33
|
+
combine: (b) => (a) => [...a, ...b]
|
|
34
|
+
});
|
|
35
|
+
Combinable2.maybe = (inner) => ({
|
|
36
|
+
empty: Maybe.none(),
|
|
37
|
+
combine: (b) => (a) => Maybe.isNone(a) ? b : Maybe.isNone(b) ? a : Maybe.some(inner.combine(b.value)(a.value))
|
|
38
|
+
});
|
|
39
|
+
Combinable2.fold = (c) => (data) => data.reduce((acc, x) => c.combine(x)(acc), c.empty);
|
|
40
|
+
})(Combinable || (Combinable = {}));
|
|
41
|
+
|
|
42
|
+
// src/Core/Equality.ts
|
|
43
|
+
var Equality;
|
|
44
|
+
((Equality2) => {
|
|
45
|
+
Equality2.string = (a, b) => a === b;
|
|
46
|
+
Equality2.number = (a, b) => a === b;
|
|
47
|
+
Equality2.boolean = (a, b) => a === b;
|
|
48
|
+
Equality2.date = (a, b) => a.getTime() === b.getTime();
|
|
49
|
+
Equality2.array = (eq) => (a, b) => a.length === b.length && a.every((x, i) => eq(x, b[i]));
|
|
50
|
+
Equality2.by = (f) => (eq) => (a, b) => eq(f(a), f(b));
|
|
51
|
+
Equality2.and = (eq2) => (eq1) => (a, b) => eq1(a, b) && eq2(a, b);
|
|
52
|
+
})(Equality || (Equality = {}));
|
|
53
|
+
|
|
54
|
+
// src/Core/Lazy.ts
|
|
55
|
+
var Lazy;
|
|
56
|
+
((Lazy2) => {
|
|
57
|
+
Lazy2.from = (f) => {
|
|
58
|
+
let done = false;
|
|
59
|
+
let cache;
|
|
60
|
+
return {
|
|
61
|
+
get: () => {
|
|
62
|
+
if (!done) {
|
|
63
|
+
cache = f();
|
|
64
|
+
done = true;
|
|
65
|
+
}
|
|
66
|
+
return cache;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
Lazy2.evaluate = (lazy) => lazy.get();
|
|
71
|
+
Lazy2.map = (f) => (lazy) => Lazy2.from(() => f(lazy.get()));
|
|
72
|
+
Lazy2.chain = (f) => (lazy) => Lazy2.from(() => f(lazy.get()).get());
|
|
73
|
+
Lazy2.tap = (f) => (lazy) => Lazy2.from(() => {
|
|
74
|
+
const v = lazy.get();
|
|
75
|
+
f(v);
|
|
76
|
+
return v;
|
|
77
|
+
});
|
|
78
|
+
})(Lazy || (Lazy = {}));
|
|
7
79
|
|
|
8
80
|
// src/Core/Lens.ts
|
|
9
81
|
var Lens;
|
|
@@ -1056,6 +1128,20 @@ var Optional;
|
|
|
1056
1128
|
);
|
|
1057
1129
|
})(Optional || (Optional = {}));
|
|
1058
1130
|
|
|
1131
|
+
// src/Core/Ordering.ts
|
|
1132
|
+
var Ordering;
|
|
1133
|
+
((Ordering2) => {
|
|
1134
|
+
Ordering2.string = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
1135
|
+
Ordering2.number = (a, b) => a - b;
|
|
1136
|
+
Ordering2.date = (a, b) => a.getTime() - b.getTime();
|
|
1137
|
+
Ordering2.reverse = (ord) => (a, b) => ord(b, a);
|
|
1138
|
+
Ordering2.thenBy = (ord2) => (ord1) => (a, b) => {
|
|
1139
|
+
const r = ord1(a, b);
|
|
1140
|
+
return r !== 0 ? r : ord2(a, b);
|
|
1141
|
+
};
|
|
1142
|
+
Ordering2.by = (f) => (ord) => (a, b) => ord(f(a), f(b));
|
|
1143
|
+
})(Ordering || (Ordering = {}));
|
|
1144
|
+
|
|
1059
1145
|
// src/Core/Predicate.ts
|
|
1060
1146
|
var Predicate;
|
|
1061
1147
|
((Predicate2) => {
|
|
@@ -1178,28 +1264,33 @@ var Resource;
|
|
|
1178
1264
|
release
|
|
1179
1265
|
});
|
|
1180
1266
|
Resource2.use = (f) => (resource) => Task.from(
|
|
1181
|
-
() => Deferred.toPromise(resource.acquire()).then(async (acquired) => {
|
|
1267
|
+
(signal) => Deferred.toPromise(resource.acquire(signal)).then(async (acquired) => {
|
|
1182
1268
|
if (Result.isError(acquired)) return acquired;
|
|
1183
1269
|
const a = acquired.value;
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1270
|
+
try {
|
|
1271
|
+
const usageResult = await Deferred.toPromise(f(a)(signal));
|
|
1272
|
+
return usageResult;
|
|
1273
|
+
} finally {
|
|
1274
|
+
await Deferred.toPromise(resource.release(a)(signal));
|
|
1275
|
+
}
|
|
1187
1276
|
})
|
|
1188
1277
|
);
|
|
1189
1278
|
Resource2.combine = (resourceA, resourceB) => ({
|
|
1190
1279
|
acquire: Task.from(
|
|
1191
|
-
() => Deferred.toPromise(resourceA.acquire()).then(async (acquiredA) => {
|
|
1280
|
+
(signal) => Deferred.toPromise(resourceA.acquire(signal)).then(async (acquiredA) => {
|
|
1192
1281
|
if (Result.isError(acquiredA)) return acquiredA;
|
|
1193
1282
|
const a = acquiredA.value;
|
|
1194
|
-
const acquiredB = await Deferred.toPromise(resourceB.acquire());
|
|
1283
|
+
const acquiredB = await Deferred.toPromise(resourceB.acquire(signal));
|
|
1195
1284
|
if (Result.isError(acquiredB)) {
|
|
1196
|
-
await Deferred.toPromise(resourceA.release(a)());
|
|
1285
|
+
await Deferred.toPromise(resourceA.release(a)(signal));
|
|
1197
1286
|
return acquiredB;
|
|
1198
1287
|
}
|
|
1199
1288
|
return Result.ok([a, acquiredB.value]);
|
|
1200
1289
|
})
|
|
1201
1290
|
),
|
|
1202
|
-
release: ([a, b]) => Task.from(
|
|
1291
|
+
release: ([a, b]) => Task.from(
|
|
1292
|
+
(signal) => Deferred.toPromise(resourceB.release(b)(signal)).then(() => Deferred.toPromise(resourceA.release(a)(signal)))
|
|
1293
|
+
)
|
|
1203
1294
|
});
|
|
1204
1295
|
})(Resource || (Resource = {}));
|
|
1205
1296
|
|
|
@@ -1240,16 +1331,18 @@ var TaskMaybe;
|
|
|
1240
1331
|
TaskMaybe2.some = (value) => Task.resolve(Maybe.some(value));
|
|
1241
1332
|
TaskMaybe2.none = () => Task.resolve(Maybe.none());
|
|
1242
1333
|
TaskMaybe2.fromMaybe = (option) => Task.resolve(option);
|
|
1334
|
+
TaskMaybe2.fromNullable = (value) => Task.resolve(Maybe.fromNullable(value));
|
|
1335
|
+
TaskMaybe2.fromResult = (result) => Task.resolve(Result.toMaybe(result));
|
|
1243
1336
|
TaskMaybe2.fromTask = (task) => Task.map(Maybe.some)(task);
|
|
1244
1337
|
TaskMaybe2.tryCatch = (f) => Task.from(
|
|
1245
|
-
() => f().then(Maybe.some).catch(() => Maybe.none())
|
|
1338
|
+
(signal) => f(signal).then(Maybe.some).catch(() => Maybe.none())
|
|
1246
1339
|
);
|
|
1247
1340
|
TaskMaybe2.map = (f) => (data) => Task.map(Maybe.map(f))(data);
|
|
1248
1341
|
TaskMaybe2.chain = (f) => (data) => Task.chain((option) => Maybe.isSome(option) ? f(option.value) : Task.resolve(Maybe.none()))(data);
|
|
1249
1342
|
TaskMaybe2.ap = (arg) => (data) => Task.from(
|
|
1250
|
-
() => Promise.all([
|
|
1251
|
-
Deferred.toPromise(data()),
|
|
1252
|
-
Deferred.toPromise(arg())
|
|
1343
|
+
(signal) => Promise.all([
|
|
1344
|
+
Deferred.toPromise(data(signal)),
|
|
1345
|
+
Deferred.toPromise(arg(signal))
|
|
1253
1346
|
]).then(([of_, oa]) => Maybe.ap(oa)(of_))
|
|
1254
1347
|
);
|
|
1255
1348
|
TaskMaybe2.fold = (onNone, onSome) => (data) => Task.map(Maybe.fold(onNone, onSome))(data);
|
|
@@ -1265,6 +1358,12 @@ var TaskResult;
|
|
|
1265
1358
|
((TaskResult2) => {
|
|
1266
1359
|
TaskResult2.ok = (value) => Task.resolve(Result.ok(value));
|
|
1267
1360
|
TaskResult2.err = (error) => Task.resolve(Result.error(error));
|
|
1361
|
+
TaskResult2.fromNullable = (onNull) => (value) => Task.resolve(value === null || value === void 0 ? Result.error(onNull()) : Result.ok(value));
|
|
1362
|
+
TaskResult2.fromMaybe = (onNone) => (maybe) => Task.resolve(Maybe.isNone(maybe) ? Result.error(onNone()) : Result.ok(maybe.value));
|
|
1363
|
+
TaskResult2.fromResult = (result) => Task.resolve(result);
|
|
1364
|
+
TaskResult2.fromThrowable = (f, onError) => (...args) => Task.from(
|
|
1365
|
+
() => f(...args).then(Result.ok).catch((e) => Result.error(onError(e)))
|
|
1366
|
+
);
|
|
1268
1367
|
TaskResult2.tryCatch = (f, onError) => Task.from(
|
|
1269
1368
|
(signal) => f(signal).then(Result.ok).catch((e) => Result.error(onError(e)))
|
|
1270
1369
|
);
|
|
@@ -1283,6 +1382,12 @@ var TaskResult;
|
|
|
1283
1382
|
TaskResult2.getOrElse = (defaultValue) => (data) => Task.map(Result.getOrElse(defaultValue))(data);
|
|
1284
1383
|
TaskResult2.tap = (f) => (data) => Task.map(Result.tap(f))(data);
|
|
1285
1384
|
TaskResult2.tapError = (f) => (data) => Task.map(Result.tapError(f))(data);
|
|
1385
|
+
TaskResult2.ap = (arg) => (data) => Task.from(
|
|
1386
|
+
(signal) => Promise.all([
|
|
1387
|
+
Deferred.toPromise(data(signal)),
|
|
1388
|
+
Deferred.toPromise(arg(signal))
|
|
1389
|
+
]).then(([of_, oa]) => Result.ap(oa)(of_))
|
|
1390
|
+
);
|
|
1286
1391
|
TaskResult2.run = (signal) => (task) => Deferred.toPromise(task(signal));
|
|
1287
1392
|
})(TaskResult || (TaskResult = {}));
|
|
1288
1393
|
|
|
@@ -1304,6 +1409,8 @@ var Validation;
|
|
|
1304
1409
|
Validation2.isValid = (data) => data.kind === "Valid";
|
|
1305
1410
|
Validation2.isInvalid = (data) => data.kind === "Invalid";
|
|
1306
1411
|
Validation2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Validation2.valid)(a) : (0, Validation2.invalid)(onFalse(a));
|
|
1412
|
+
Validation2.fromNullable = (onNull) => (value) => value === null || value === void 0 ? (0, Validation2.invalid)(onNull()) : (0, Validation2.valid)(value);
|
|
1413
|
+
Validation2.fromMaybe = (onNone) => (maybe) => Maybe.isNone(maybe) ? (0, Validation2.invalid)(onNone()) : (0, Validation2.valid)(maybe.value);
|
|
1307
1414
|
Validation2.map = (f) => (data) => (0, Validation2.isValid)(data) ? (0, Validation2.valid)(f(data.value)) : data;
|
|
1308
1415
|
Validation2.ap = (arg) => (data) => {
|
|
1309
1416
|
if ((0, Validation2.isValid)(data) && (0, Validation2.isValid)(arg)) return (0, Validation2.valid)(data.value(arg.value));
|
|
@@ -1355,14 +1462,17 @@ var TaskValidation;
|
|
|
1355
1462
|
TaskValidation2.invalid = (error) => Task.resolve(Validation.invalid(error));
|
|
1356
1463
|
TaskValidation2.invalidAll = (errors) => Task.resolve(Validation.invalidAll(errors));
|
|
1357
1464
|
TaskValidation2.fromValidation = (validation) => Task.resolve(validation);
|
|
1465
|
+
TaskValidation2.fromNullable = (onNull) => (value) => Task.resolve(value === null || value === void 0 ? Validation.invalid(onNull()) : Validation.valid(value));
|
|
1466
|
+
TaskValidation2.fromMaybe = (onNone) => (maybe) => Task.resolve(Maybe.isNone(maybe) ? Validation.invalid(onNone()) : Validation.valid(maybe.value));
|
|
1467
|
+
TaskValidation2.fromResult = (result) => Task.resolve(Validation.fromResult(result));
|
|
1358
1468
|
TaskValidation2.tryCatch = (f, onError) => Task.from(
|
|
1359
|
-
() => f().then(Validation.valid).catch((e) => Validation.invalid(onError(e)))
|
|
1469
|
+
(signal) => f(signal).then(Validation.valid).catch((e) => Validation.invalid(onError(e)))
|
|
1360
1470
|
);
|
|
1361
1471
|
TaskValidation2.map = (f) => (data) => Task.map(Validation.map(f))(data);
|
|
1362
1472
|
TaskValidation2.ap = (arg) => (data) => Task.from(
|
|
1363
|
-
() => Promise.all([
|
|
1364
|
-
Deferred.toPromise(data()),
|
|
1365
|
-
Deferred.toPromise(arg())
|
|
1473
|
+
(signal) => Promise.all([
|
|
1474
|
+
Deferred.toPromise(data(signal)),
|
|
1475
|
+
Deferred.toPromise(arg(signal))
|
|
1366
1476
|
]).then(([vf, va]) => Validation.ap(va)(vf))
|
|
1367
1477
|
);
|
|
1368
1478
|
TaskValidation2.fold = (onInvalid, onValid) => (data) => Task.map(Validation.fold(onInvalid, onValid))(data);
|
|
@@ -1373,13 +1483,13 @@ var TaskValidation;
|
|
|
1373
1483
|
(validation) => Validation.isValid(validation) ? Task.resolve(validation) : fallback(validation.errors)
|
|
1374
1484
|
)(data);
|
|
1375
1485
|
TaskValidation2.product = (first, second) => Task.from(
|
|
1376
|
-
() => Promise.all([
|
|
1377
|
-
Deferred.toPromise(first()),
|
|
1378
|
-
Deferred.toPromise(second())
|
|
1486
|
+
(signal) => Promise.all([
|
|
1487
|
+
Deferred.toPromise(first(signal)),
|
|
1488
|
+
Deferred.toPromise(second(signal))
|
|
1379
1489
|
]).then(([va, vb]) => Validation.product(va, vb))
|
|
1380
1490
|
);
|
|
1381
1491
|
TaskValidation2.productAll = (data) => Task.from(
|
|
1382
|
-
() => Promise.all(data.map((t) => Deferred.toPromise(t()))).then((results) => Validation.productAll(results))
|
|
1492
|
+
(signal) => Promise.all(data.map((t) => Deferred.toPromise(t(signal)))).then((results) => Validation.productAll(results))
|
|
1383
1493
|
);
|
|
1384
1494
|
})(TaskValidation || (TaskValidation = {}));
|
|
1385
1495
|
|
|
@@ -1466,10 +1576,14 @@ var Tuple;
|
|
|
1466
1576
|
})(Tuple || (Tuple = {}));
|
|
1467
1577
|
|
|
1468
1578
|
export {
|
|
1579
|
+
Combinable,
|
|
1580
|
+
Equality,
|
|
1581
|
+
Lazy,
|
|
1469
1582
|
Lens,
|
|
1470
1583
|
Logged,
|
|
1471
1584
|
Op,
|
|
1472
1585
|
Optional,
|
|
1586
|
+
Ordering,
|
|
1473
1587
|
Predicate,
|
|
1474
1588
|
Reader,
|
|
1475
1589
|
Refinement,
|