@nlozgachev/pipelined 0.54.0 → 0.56.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/{InternalTypes-CDiDBAY4.d.mts → InternalTypes-DuK_XpTi.d.cts} +1 -1
- package/dist/{Validation-C5Qz1R0S.d.mts → Validation-DCqWoCC2.d.cts} +91 -80
- package/dist/{Validation-yOcgYn9K.d.ts → Validation-t0k4ic-S.d.ts} +88 -77
- package/dist/{chunk-L6GLADRU.mjs → chunk-EJX32LRO.js} +4 -5
- package/dist/{chunk-5OFVS5UZ.mjs → chunk-JSG7SFXS.js} +1 -1
- package/dist/{chunk-XFE3SQEE.mjs → chunk-K7HHEACE.js} +55 -62
- package/dist/composition.cjs +533 -0
- package/dist/{composition.d.mts → composition.d.cts} +2 -2
- package/dist/composition.js +35 -503
- package/dist/core.cjs +2680 -0
- package/dist/{core.d.mts → core.d.cts} +10 -10
- package/dist/core.d.ts +7 -7
- package/dist/core.js +27 -2665
- package/dist/data.cjs +1612 -0
- package/dist/{data.d.mts → data.d.cts} +4 -4
- package/dist/data.d.ts +1 -1
- package/dist/data.js +14 -2137
- package/dist/index.cjs +4510 -0
- package/dist/{index.d.mts → index.d.cts} +7 -7
- package/dist/index.d.ts +1 -1
- package/dist/index.js +73 -4454
- package/dist/types.cjs +84 -0
- package/dist/{types.d.mts → types.d.cts} +2 -2
- package/dist/types.js +7 -81
- package/package.json +2 -1
- package/dist/composition.mjs +0 -65
- package/dist/core.mjs +0 -49
- package/dist/data.mjs +0 -22
- package/dist/index.mjs +0 -136
- package/dist/types.mjs +0 -10
- /package/dist/{Duration-B8joKzro.d.mts → Duration-B8joKzro.d.cts} +0 -0
- /package/dist/{chunk-DENXUTKL.mjs → chunk-OIIOGDHK.js} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { h as WithKind, o as WithValue, e as WithError, a as NonEmptyArr, T as Thenable, D as Deferred, f as WithErrors } from './InternalTypes-
|
|
2
|
-
import { D as Duration } from './Duration-B8joKzro.
|
|
3
|
-
import { RetryPolicy } from './types.
|
|
1
|
+
import { h as WithKind, o as WithValue, e as WithError, a as NonEmptyArr, T as Thenable, D as Deferred, f as WithErrors } from './InternalTypes-DuK_XpTi.cjs';
|
|
2
|
+
import { D as Duration } from './Duration-B8joKzro.cjs';
|
|
3
|
+
import { RetryPolicy } from './types.cjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* A function that checks whether two values of type `A` are equal.
|
|
@@ -595,13 +595,16 @@ declare namespace Result {
|
|
|
595
595
|
* Creates a Result from a function that may throw.
|
|
596
596
|
* Catches any errors and transforms them using the onError function.
|
|
597
597
|
*
|
|
598
|
+
/**
|
|
599
|
+
* Creates a Result from a synchronous thunk that may throw.
|
|
600
|
+
* Catches any errors and transforms them using the `onError` function.
|
|
601
|
+
*
|
|
598
602
|
* @example
|
|
599
603
|
* ```ts
|
|
600
|
-
* const
|
|
601
|
-
*
|
|
602
|
-
*
|
|
603
|
-
*
|
|
604
|
-
* );
|
|
604
|
+
* const result = Result.tryCatch(
|
|
605
|
+
* () => JSON.parse(rawString),
|
|
606
|
+
* { onError: (e) => `Parse error: ${e}` }
|
|
607
|
+
* );
|
|
605
608
|
* ```
|
|
606
609
|
*/
|
|
607
610
|
const tryCatch: <E, A>(f: () => A, options: {
|
|
@@ -749,24 +752,6 @@ declare namespace Result {
|
|
|
749
752
|
* ```
|
|
750
753
|
*/
|
|
751
754
|
const Maybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => Result<E, A>;
|
|
752
|
-
/**
|
|
753
|
-
* Wraps a throwing function of any arguments, returning a new function
|
|
754
|
-
* that catches errors and returns a Result.
|
|
755
|
-
*
|
|
756
|
-
* @example
|
|
757
|
-
* ```ts
|
|
758
|
-
* const safeParse = Result.from.throwable(
|
|
759
|
-
* (s: string) => JSON.parse(s),
|
|
760
|
-
* { onError: (e) => new Error(`Parse error: ${e}`) }
|
|
761
|
-
* );
|
|
762
|
-
*
|
|
763
|
-
* safeParse('{"a":1}'); // Ok({ a: 1 })
|
|
764
|
-
* safeParse('invalid'); // Err(Error)
|
|
765
|
-
* ```
|
|
766
|
-
*/
|
|
767
|
-
const throwable: <Args extends readonly unknown[], A, E>(f: (...args: Args) => A, options: {
|
|
768
|
-
onError: (e: unknown) => E;
|
|
769
|
-
}) => (...args: Args) => Result<E, A>;
|
|
770
755
|
/**
|
|
771
756
|
* Converts a `Validation` to a `Result`, combining accumulated errors using `combineErrors`.
|
|
772
757
|
* `Passed(a)` becomes `Ok(a)`; `Failed(errors)` becomes `Err(combineErrors(errors))`.
|
|
@@ -1132,6 +1117,16 @@ declare namespace TaskMaybe {
|
|
|
1132
1117
|
* ```
|
|
1133
1118
|
*/
|
|
1134
1119
|
const struct: <R extends Record<string, any>>(fields: { [K in keyof R]: TaskMaybe<R[K]>; }) => TaskMaybe<R>;
|
|
1120
|
+
/**
|
|
1121
|
+
* Creates a memoized version of a Task.Maybe. The task is executed at most once on first call,
|
|
1122
|
+
* and its resolved Maybe is cached for all subsequent calls.
|
|
1123
|
+
*
|
|
1124
|
+
* @example
|
|
1125
|
+
* ```ts
|
|
1126
|
+
* const loadUser = Task.Maybe.memoize(fetchUserMaybeTask);
|
|
1127
|
+
* ```
|
|
1128
|
+
*/
|
|
1129
|
+
const memoize: <A>(task: TaskMaybe<A>) => TaskMaybe<A>;
|
|
1135
1130
|
}
|
|
1136
1131
|
|
|
1137
1132
|
/**
|
|
@@ -1159,7 +1154,7 @@ declare namespace TaskResult {
|
|
|
1159
1154
|
* const res = await task(); // Ok(42)
|
|
1160
1155
|
* ```
|
|
1161
1156
|
*/
|
|
1162
|
-
const ok: <E, A>(value: A) => TaskResult<E, A>;
|
|
1157
|
+
const ok: <E = never, A = unknown>(value: A) => TaskResult<E, A>;
|
|
1163
1158
|
/**
|
|
1164
1159
|
* Creates a failed Task.Result with the given error.
|
|
1165
1160
|
*
|
|
@@ -1169,10 +1164,10 @@ declare namespace TaskResult {
|
|
|
1169
1164
|
* const res = await task(); // Err("failed")
|
|
1170
1165
|
* ```
|
|
1171
1166
|
*/
|
|
1172
|
-
const err: <E, A>(error: E) => TaskResult<E, A>;
|
|
1167
|
+
const err: <E, A = never>(error: E) => TaskResult<E, A>;
|
|
1173
1168
|
}
|
|
1174
|
-
const ok: <E, A>(value: A) => TaskResult<E, A>;
|
|
1175
|
-
const err: <E, A>(error: E) => TaskResult<E, A>;
|
|
1169
|
+
const ok: <E = never, A = unknown>(value: A) => TaskResult<E, A>;
|
|
1170
|
+
const err: <E, A = never>(error: E) => TaskResult<E, A>;
|
|
1176
1171
|
namespace from {
|
|
1177
1172
|
/**
|
|
1178
1173
|
* Creates a Task.Result from a nullable value.
|
|
@@ -1204,14 +1199,15 @@ declare namespace TaskResult {
|
|
|
1204
1199
|
* Task.Result.from.Result(Result.make.ok(42)); // resolves to Ok(42)
|
|
1205
1200
|
* ```
|
|
1206
1201
|
*/
|
|
1207
|
-
const Result: <E, A>(result: Result<E, A>) => TaskResult<E, A>;
|
|
1208
1202
|
/**
|
|
1209
|
-
*
|
|
1210
|
-
*
|
|
1203
|
+
* Lifts a Result into a Task.Result.
|
|
1204
|
+
*
|
|
1205
|
+
* @example
|
|
1206
|
+
* ```ts
|
|
1207
|
+
* Task.Result.from.Result(Result.make.ok(42)); // resolves to Ok(42)
|
|
1208
|
+
* ```
|
|
1211
1209
|
*/
|
|
1212
|
-
const
|
|
1213
|
-
onError: (e: unknown) => E;
|
|
1214
|
-
}) => (...args: Args) => TaskResult<E, A>;
|
|
1210
|
+
const Result: <E, A>(result: Result<E, A>) => TaskResult<E, A>;
|
|
1215
1211
|
}
|
|
1216
1212
|
namespace to {
|
|
1217
1213
|
/**
|
|
@@ -1226,21 +1222,20 @@ declare namespace TaskResult {
|
|
|
1226
1222
|
const Maybe: <E, A>(data: TaskResult<E, A>) => TaskMaybe<A>;
|
|
1227
1223
|
}
|
|
1228
1224
|
/**
|
|
1229
|
-
* Creates a Task.Result from a
|
|
1230
|
-
* Catches any errors and transforms them using the onError function
|
|
1231
|
-
* The
|
|
1225
|
+
* Creates a Task.Result from a Promise-returning thunk that may throw or reject.
|
|
1226
|
+
* Catches any errors and transforms them using the `onError` function into an `Err`.
|
|
1227
|
+
* The thunk optionally receives an `AbortSignal` forwarded from the call site.
|
|
1232
1228
|
*
|
|
1233
1229
|
* @example
|
|
1234
1230
|
* ```ts
|
|
1235
|
-
* const
|
|
1236
|
-
*
|
|
1237
|
-
*
|
|
1238
|
-
*
|
|
1239
|
-
* );
|
|
1231
|
+
* const loadUser = Task.Result.tryCatch(
|
|
1232
|
+
* (signal) => userStore.get("u_123", { signal }),
|
|
1233
|
+
* { onError: (e) => new DbError(e) }
|
|
1234
|
+
* );
|
|
1240
1235
|
* ```
|
|
1241
1236
|
*/
|
|
1242
1237
|
const tryCatch: <E, A>(f: (signal?: AbortSignal) => Thenable<A>, options: {
|
|
1243
|
-
onError: (
|
|
1238
|
+
onError: (error: unknown) => E;
|
|
1244
1239
|
}) => TaskResult<E, A>;
|
|
1245
1240
|
/**
|
|
1246
1241
|
* Transforms the success value inside a Task.Result.
|
|
@@ -1436,7 +1431,7 @@ declare namespace TaskValidation {
|
|
|
1436
1431
|
* const res = await task(); // Passed(42)
|
|
1437
1432
|
* ```
|
|
1438
1433
|
*/
|
|
1439
|
-
const passed: <E, A>(value: A) => TaskValidation<E, A>;
|
|
1434
|
+
const passed: <E = never, A = unknown>(value: A) => TaskValidation<E, A>;
|
|
1440
1435
|
/**
|
|
1441
1436
|
* Creates a failed Task.Validation with a single error.
|
|
1442
1437
|
*
|
|
@@ -1446,7 +1441,7 @@ declare namespace TaskValidation {
|
|
|
1446
1441
|
* const res = await task(); // Failed(["invalid"])
|
|
1447
1442
|
* ```
|
|
1448
1443
|
*/
|
|
1449
|
-
const failed: <E, A>(error: E) => TaskValidation<E, A>;
|
|
1444
|
+
const failed: <E, A = never>(error: E) => TaskValidation<E, A>;
|
|
1450
1445
|
/**
|
|
1451
1446
|
* Creates a failed Task.Validation from multiple errors.
|
|
1452
1447
|
*
|
|
@@ -1456,11 +1451,11 @@ declare namespace TaskValidation {
|
|
|
1456
1451
|
* const res = await task(); // Failed(["err1", "err2"])
|
|
1457
1452
|
* ```
|
|
1458
1453
|
*/
|
|
1459
|
-
const failedAll: <E, A>(errors: NonEmptyArr<E>) => TaskValidation<E, A>;
|
|
1454
|
+
const failedAll: <E, A = never>(errors: NonEmptyArr<E>) => TaskValidation<E, A>;
|
|
1460
1455
|
}
|
|
1461
|
-
const passed: <E, A>(value: A) => TaskValidation<E, A>;
|
|
1462
|
-
const failed: <E, A>(error: E) => TaskValidation<E, A>;
|
|
1463
|
-
const failedAll: <E, A>(errors: NonEmptyArr<E>) => TaskValidation<E, A>;
|
|
1456
|
+
const passed: <E = never, A = unknown>(value: A) => TaskValidation<E, A>;
|
|
1457
|
+
const failed: <E, A = never>(error: E) => TaskValidation<E, A>;
|
|
1458
|
+
const failedAll: <E, A = never>(errors: NonEmptyArr<E>) => TaskValidation<E, A>;
|
|
1464
1459
|
namespace from {
|
|
1465
1460
|
/**
|
|
1466
1461
|
* Lifts a Validation into a Task.Validation.
|
|
@@ -1510,17 +1505,22 @@ declare namespace TaskValidation {
|
|
|
1510
1505
|
* Creates a Task.Validation from a Promise-returning function.
|
|
1511
1506
|
* Catches any errors and transforms them using the onError function.
|
|
1512
1507
|
* The factory optionally receives an `AbortSignal` forwarded from the call site.
|
|
1508
|
+
/**
|
|
1509
|
+
* Creates a Task.Validation from a Promise-returning thunk that may throw or reject.
|
|
1510
|
+
* Catches any errors and transforms them using the `onError` function into a Failed validation.
|
|
1511
|
+
* The thunk optionally receives an `AbortSignal` forwarded from the call site.
|
|
1513
1512
|
*
|
|
1514
1513
|
* @example
|
|
1515
1514
|
* ```ts
|
|
1516
|
-
* const
|
|
1517
|
-
*
|
|
1518
|
-
*
|
|
1519
|
-
*
|
|
1520
|
-
* );
|
|
1515
|
+
* const loadConfig = Task.Validation.tryCatch(
|
|
1516
|
+
* (signal) => configStore.get("default", { signal }),
|
|
1517
|
+
* { onError: (e) => `Failed to load config: ${e}` }
|
|
1518
|
+
* );
|
|
1521
1519
|
* ```
|
|
1522
1520
|
*/
|
|
1523
|
-
const tryCatch: <E, A>(f: (signal?: AbortSignal) => Thenable<A>,
|
|
1521
|
+
const tryCatch: <E, A>(f: (signal?: AbortSignal) => Thenable<A>, options: {
|
|
1522
|
+
onError: (error: unknown) => E;
|
|
1523
|
+
}) => TaskValidation<E, A>;
|
|
1524
1524
|
/**
|
|
1525
1525
|
* Transforms the success value inside a Task.Validation.
|
|
1526
1526
|
*/
|
|
@@ -1644,6 +1644,16 @@ declare namespace TaskValidation {
|
|
|
1644
1644
|
* ```
|
|
1645
1645
|
*/
|
|
1646
1646
|
const struct: <E, R extends Record<string, any>>(fields: { [K in keyof R]: TaskValidation<E, R[K]>; }) => TaskValidation<E, R>;
|
|
1647
|
+
/**
|
|
1648
|
+
* Creates a memoized version of a Task.Validation. The task is executed at most once on first call,
|
|
1649
|
+
* and its resolved Validation is cached for all subsequent calls.
|
|
1650
|
+
*
|
|
1651
|
+
* @example
|
|
1652
|
+
* ```ts
|
|
1653
|
+
* const validate = Task.Validation.memoize(validateFormTask);
|
|
1654
|
+
* ```
|
|
1655
|
+
*/
|
|
1656
|
+
const memoize: <E, A>(task: TaskValidation<E, A>) => TaskValidation<E, A>;
|
|
1647
1657
|
}
|
|
1648
1658
|
|
|
1649
1659
|
/**
|
|
@@ -1701,16 +1711,6 @@ declare namespace Task {
|
|
|
1701
1711
|
*/
|
|
1702
1712
|
const resolve: <A>(value: A) => Task<A>;
|
|
1703
1713
|
namespace from {
|
|
1704
|
-
/**
|
|
1705
|
-
* Creates a Task from a function that returns a Promise.
|
|
1706
|
-
* The factory optionally receives an `AbortSignal` forwarded from the call site.
|
|
1707
|
-
*
|
|
1708
|
-
* @example
|
|
1709
|
-
* ```ts
|
|
1710
|
-
* const getTimestamp = Task.from.Promise(() => Promise.resolve(Date.now()));
|
|
1711
|
-
* ```
|
|
1712
|
-
*/
|
|
1713
|
-
const Promise: <A>(f: (signal?: AbortSignal) => Thenable<A>) => Task<A>;
|
|
1714
1714
|
/**
|
|
1715
1715
|
* Creates a Task from a lazy synchronous thunk.
|
|
1716
1716
|
* Unlike `Task.resolve(f())`, `from.sync` does not evaluate `f` until the Task is called.
|
|
@@ -1723,6 +1723,21 @@ declare namespace Task {
|
|
|
1723
1723
|
*/
|
|
1724
1724
|
const sync: <A>(f: () => A) => Task<A>;
|
|
1725
1725
|
}
|
|
1726
|
+
/**
|
|
1727
|
+
* Wraps a Promise-returning thunk that may throw or reject,
|
|
1728
|
+
* trapping errors with a fallback function and returning a guaranteed `Task<A>`.
|
|
1729
|
+
*
|
|
1730
|
+
* @example
|
|
1731
|
+
* ```ts
|
|
1732
|
+
* const loadConfig = Task.tryCatch(
|
|
1733
|
+
* () => configStore.get("default"),
|
|
1734
|
+
* { onError: () => DEFAULT_CONFIG }
|
|
1735
|
+
* );
|
|
1736
|
+
* ```
|
|
1737
|
+
*/
|
|
1738
|
+
const tryCatch: <A>(f: (signal?: AbortSignal) => globalThis.Promise<A>, options: {
|
|
1739
|
+
onError: (error: unknown) => A;
|
|
1740
|
+
}) => Task<A>;
|
|
1726
1741
|
/**
|
|
1727
1742
|
* Transforms the value inside a Task.
|
|
1728
1743
|
*
|
|
@@ -1845,8 +1860,8 @@ declare namespace Task {
|
|
|
1845
1860
|
*
|
|
1846
1861
|
* @example
|
|
1847
1862
|
* ```ts
|
|
1848
|
-
* const fast = Task.
|
|
1849
|
-
* const slow = Task.
|
|
1863
|
+
* const fast = Task.resolve("fast");
|
|
1864
|
+
* const slow = Task.delay(Duration.milliseconds(200))(Task.resolve("slow"));
|
|
1850
1865
|
*
|
|
1851
1866
|
* await Task.race([fast, slow])(); // "fast"
|
|
1852
1867
|
* ```
|
|
@@ -1870,10 +1885,7 @@ declare namespace Task {
|
|
|
1870
1885
|
* @example
|
|
1871
1886
|
* ```ts
|
|
1872
1887
|
* let log: number[] = [];
|
|
1873
|
-
* const makeTask = (n: number) => Task.
|
|
1874
|
-
* log.push(n);
|
|
1875
|
-
* return Promise.resolve(n);
|
|
1876
|
-
* });
|
|
1888
|
+
* const makeTask = (n: number) => Task.resolve(n);
|
|
1877
1889
|
*
|
|
1878
1890
|
* await Task.sequential([makeTask(1), makeTask(2), makeTask(3)])();
|
|
1879
1891
|
* // log = [1, 2, 3] — tasks ran in order
|
|
@@ -2089,16 +2101,15 @@ declare namespace Validation {
|
|
|
2089
2101
|
const failed: <E, A>(data: Validation<E, A>) => data is Failed<E>;
|
|
2090
2102
|
}
|
|
2091
2103
|
/**
|
|
2092
|
-
* Creates a Validation from a
|
|
2093
|
-
* Catches any errors and transforms them using the onError function into a Failed validation.
|
|
2104
|
+
* Creates a Validation from a synchronous thunk that may throw.
|
|
2105
|
+
* Catches any errors and transforms them using the `onError` function into a Failed validation.
|
|
2094
2106
|
*
|
|
2095
2107
|
* @example
|
|
2096
2108
|
* ```ts
|
|
2097
|
-
* const
|
|
2098
|
-
*
|
|
2099
|
-
*
|
|
2100
|
-
*
|
|
2101
|
-
* );
|
|
2109
|
+
* const result = Validation.tryCatch(
|
|
2110
|
+
* () => JSON.parse(rawString),
|
|
2111
|
+
* { onError: (e) => `Parse error: ${e}` }
|
|
2112
|
+
* );
|
|
2102
2113
|
* ```
|
|
2103
2114
|
*/
|
|
2104
2115
|
const tryCatch: <E, A>(f: () => A, options: {
|
|
@@ -595,13 +595,16 @@ declare namespace Result {
|
|
|
595
595
|
* Creates a Result from a function that may throw.
|
|
596
596
|
* Catches any errors and transforms them using the onError function.
|
|
597
597
|
*
|
|
598
|
+
/**
|
|
599
|
+
* Creates a Result from a synchronous thunk that may throw.
|
|
600
|
+
* Catches any errors and transforms them using the `onError` function.
|
|
601
|
+
*
|
|
598
602
|
* @example
|
|
599
603
|
* ```ts
|
|
600
|
-
* const
|
|
601
|
-
*
|
|
602
|
-
*
|
|
603
|
-
*
|
|
604
|
-
* );
|
|
604
|
+
* const result = Result.tryCatch(
|
|
605
|
+
* () => JSON.parse(rawString),
|
|
606
|
+
* { onError: (e) => `Parse error: ${e}` }
|
|
607
|
+
* );
|
|
605
608
|
* ```
|
|
606
609
|
*/
|
|
607
610
|
const tryCatch: <E, A>(f: () => A, options: {
|
|
@@ -749,24 +752,6 @@ declare namespace Result {
|
|
|
749
752
|
* ```
|
|
750
753
|
*/
|
|
751
754
|
const Maybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => Result<E, A>;
|
|
752
|
-
/**
|
|
753
|
-
* Wraps a throwing function of any arguments, returning a new function
|
|
754
|
-
* that catches errors and returns a Result.
|
|
755
|
-
*
|
|
756
|
-
* @example
|
|
757
|
-
* ```ts
|
|
758
|
-
* const safeParse = Result.from.throwable(
|
|
759
|
-
* (s: string) => JSON.parse(s),
|
|
760
|
-
* { onError: (e) => new Error(`Parse error: ${e}`) }
|
|
761
|
-
* );
|
|
762
|
-
*
|
|
763
|
-
* safeParse('{"a":1}'); // Ok({ a: 1 })
|
|
764
|
-
* safeParse('invalid'); // Err(Error)
|
|
765
|
-
* ```
|
|
766
|
-
*/
|
|
767
|
-
const throwable: <Args extends readonly unknown[], A, E>(f: (...args: Args) => A, options: {
|
|
768
|
-
onError: (e: unknown) => E;
|
|
769
|
-
}) => (...args: Args) => Result<E, A>;
|
|
770
755
|
/**
|
|
771
756
|
* Converts a `Validation` to a `Result`, combining accumulated errors using `combineErrors`.
|
|
772
757
|
* `Passed(a)` becomes `Ok(a)`; `Failed(errors)` becomes `Err(combineErrors(errors))`.
|
|
@@ -1132,6 +1117,16 @@ declare namespace TaskMaybe {
|
|
|
1132
1117
|
* ```
|
|
1133
1118
|
*/
|
|
1134
1119
|
const struct: <R extends Record<string, any>>(fields: { [K in keyof R]: TaskMaybe<R[K]>; }) => TaskMaybe<R>;
|
|
1120
|
+
/**
|
|
1121
|
+
* Creates a memoized version of a Task.Maybe. The task is executed at most once on first call,
|
|
1122
|
+
* and its resolved Maybe is cached for all subsequent calls.
|
|
1123
|
+
*
|
|
1124
|
+
* @example
|
|
1125
|
+
* ```ts
|
|
1126
|
+
* const loadUser = Task.Maybe.memoize(fetchUserMaybeTask);
|
|
1127
|
+
* ```
|
|
1128
|
+
*/
|
|
1129
|
+
const memoize: <A>(task: TaskMaybe<A>) => TaskMaybe<A>;
|
|
1135
1130
|
}
|
|
1136
1131
|
|
|
1137
1132
|
/**
|
|
@@ -1159,7 +1154,7 @@ declare namespace TaskResult {
|
|
|
1159
1154
|
* const res = await task(); // Ok(42)
|
|
1160
1155
|
* ```
|
|
1161
1156
|
*/
|
|
1162
|
-
const ok: <E, A>(value: A) => TaskResult<E, A>;
|
|
1157
|
+
const ok: <E = never, A = unknown>(value: A) => TaskResult<E, A>;
|
|
1163
1158
|
/**
|
|
1164
1159
|
* Creates a failed Task.Result with the given error.
|
|
1165
1160
|
*
|
|
@@ -1169,10 +1164,10 @@ declare namespace TaskResult {
|
|
|
1169
1164
|
* const res = await task(); // Err("failed")
|
|
1170
1165
|
* ```
|
|
1171
1166
|
*/
|
|
1172
|
-
const err: <E, A>(error: E) => TaskResult<E, A>;
|
|
1167
|
+
const err: <E, A = never>(error: E) => TaskResult<E, A>;
|
|
1173
1168
|
}
|
|
1174
|
-
const ok: <E, A>(value: A) => TaskResult<E, A>;
|
|
1175
|
-
const err: <E, A>(error: E) => TaskResult<E, A>;
|
|
1169
|
+
const ok: <E = never, A = unknown>(value: A) => TaskResult<E, A>;
|
|
1170
|
+
const err: <E, A = never>(error: E) => TaskResult<E, A>;
|
|
1176
1171
|
namespace from {
|
|
1177
1172
|
/**
|
|
1178
1173
|
* Creates a Task.Result from a nullable value.
|
|
@@ -1204,14 +1199,15 @@ declare namespace TaskResult {
|
|
|
1204
1199
|
* Task.Result.from.Result(Result.make.ok(42)); // resolves to Ok(42)
|
|
1205
1200
|
* ```
|
|
1206
1201
|
*/
|
|
1207
|
-
const Result: <E, A>(result: Result<E, A>) => TaskResult<E, A>;
|
|
1208
1202
|
/**
|
|
1209
|
-
*
|
|
1210
|
-
*
|
|
1203
|
+
* Lifts a Result into a Task.Result.
|
|
1204
|
+
*
|
|
1205
|
+
* @example
|
|
1206
|
+
* ```ts
|
|
1207
|
+
* Task.Result.from.Result(Result.make.ok(42)); // resolves to Ok(42)
|
|
1208
|
+
* ```
|
|
1211
1209
|
*/
|
|
1212
|
-
const
|
|
1213
|
-
onError: (e: unknown) => E;
|
|
1214
|
-
}) => (...args: Args) => TaskResult<E, A>;
|
|
1210
|
+
const Result: <E, A>(result: Result<E, A>) => TaskResult<E, A>;
|
|
1215
1211
|
}
|
|
1216
1212
|
namespace to {
|
|
1217
1213
|
/**
|
|
@@ -1226,21 +1222,20 @@ declare namespace TaskResult {
|
|
|
1226
1222
|
const Maybe: <E, A>(data: TaskResult<E, A>) => TaskMaybe<A>;
|
|
1227
1223
|
}
|
|
1228
1224
|
/**
|
|
1229
|
-
* Creates a Task.Result from a
|
|
1230
|
-
* Catches any errors and transforms them using the onError function
|
|
1231
|
-
* The
|
|
1225
|
+
* Creates a Task.Result from a Promise-returning thunk that may throw or reject.
|
|
1226
|
+
* Catches any errors and transforms them using the `onError` function into an `Err`.
|
|
1227
|
+
* The thunk optionally receives an `AbortSignal` forwarded from the call site.
|
|
1232
1228
|
*
|
|
1233
1229
|
* @example
|
|
1234
1230
|
* ```ts
|
|
1235
|
-
* const
|
|
1236
|
-
*
|
|
1237
|
-
*
|
|
1238
|
-
*
|
|
1239
|
-
* );
|
|
1231
|
+
* const loadUser = Task.Result.tryCatch(
|
|
1232
|
+
* (signal) => userStore.get("u_123", { signal }),
|
|
1233
|
+
* { onError: (e) => new DbError(e) }
|
|
1234
|
+
* );
|
|
1240
1235
|
* ```
|
|
1241
1236
|
*/
|
|
1242
1237
|
const tryCatch: <E, A>(f: (signal?: AbortSignal) => Thenable<A>, options: {
|
|
1243
|
-
onError: (
|
|
1238
|
+
onError: (error: unknown) => E;
|
|
1244
1239
|
}) => TaskResult<E, A>;
|
|
1245
1240
|
/**
|
|
1246
1241
|
* Transforms the success value inside a Task.Result.
|
|
@@ -1436,7 +1431,7 @@ declare namespace TaskValidation {
|
|
|
1436
1431
|
* const res = await task(); // Passed(42)
|
|
1437
1432
|
* ```
|
|
1438
1433
|
*/
|
|
1439
|
-
const passed: <E, A>(value: A) => TaskValidation<E, A>;
|
|
1434
|
+
const passed: <E = never, A = unknown>(value: A) => TaskValidation<E, A>;
|
|
1440
1435
|
/**
|
|
1441
1436
|
* Creates a failed Task.Validation with a single error.
|
|
1442
1437
|
*
|
|
@@ -1446,7 +1441,7 @@ declare namespace TaskValidation {
|
|
|
1446
1441
|
* const res = await task(); // Failed(["invalid"])
|
|
1447
1442
|
* ```
|
|
1448
1443
|
*/
|
|
1449
|
-
const failed: <E, A>(error: E) => TaskValidation<E, A>;
|
|
1444
|
+
const failed: <E, A = never>(error: E) => TaskValidation<E, A>;
|
|
1450
1445
|
/**
|
|
1451
1446
|
* Creates a failed Task.Validation from multiple errors.
|
|
1452
1447
|
*
|
|
@@ -1456,11 +1451,11 @@ declare namespace TaskValidation {
|
|
|
1456
1451
|
* const res = await task(); // Failed(["err1", "err2"])
|
|
1457
1452
|
* ```
|
|
1458
1453
|
*/
|
|
1459
|
-
const failedAll: <E, A>(errors: NonEmptyArr<E>) => TaskValidation<E, A>;
|
|
1454
|
+
const failedAll: <E, A = never>(errors: NonEmptyArr<E>) => TaskValidation<E, A>;
|
|
1460
1455
|
}
|
|
1461
|
-
const passed: <E, A>(value: A) => TaskValidation<E, A>;
|
|
1462
|
-
const failed: <E, A>(error: E) => TaskValidation<E, A>;
|
|
1463
|
-
const failedAll: <E, A>(errors: NonEmptyArr<E>) => TaskValidation<E, A>;
|
|
1456
|
+
const passed: <E = never, A = unknown>(value: A) => TaskValidation<E, A>;
|
|
1457
|
+
const failed: <E, A = never>(error: E) => TaskValidation<E, A>;
|
|
1458
|
+
const failedAll: <E, A = never>(errors: NonEmptyArr<E>) => TaskValidation<E, A>;
|
|
1464
1459
|
namespace from {
|
|
1465
1460
|
/**
|
|
1466
1461
|
* Lifts a Validation into a Task.Validation.
|
|
@@ -1510,17 +1505,22 @@ declare namespace TaskValidation {
|
|
|
1510
1505
|
* Creates a Task.Validation from a Promise-returning function.
|
|
1511
1506
|
* Catches any errors and transforms them using the onError function.
|
|
1512
1507
|
* The factory optionally receives an `AbortSignal` forwarded from the call site.
|
|
1508
|
+
/**
|
|
1509
|
+
* Creates a Task.Validation from a Promise-returning thunk that may throw or reject.
|
|
1510
|
+
* Catches any errors and transforms them using the `onError` function into a Failed validation.
|
|
1511
|
+
* The thunk optionally receives an `AbortSignal` forwarded from the call site.
|
|
1513
1512
|
*
|
|
1514
1513
|
* @example
|
|
1515
1514
|
* ```ts
|
|
1516
|
-
* const
|
|
1517
|
-
*
|
|
1518
|
-
*
|
|
1519
|
-
*
|
|
1520
|
-
* );
|
|
1515
|
+
* const loadConfig = Task.Validation.tryCatch(
|
|
1516
|
+
* (signal) => configStore.get("default", { signal }),
|
|
1517
|
+
* { onError: (e) => `Failed to load config: ${e}` }
|
|
1518
|
+
* );
|
|
1521
1519
|
* ```
|
|
1522
1520
|
*/
|
|
1523
|
-
const tryCatch: <E, A>(f: (signal?: AbortSignal) => Thenable<A>,
|
|
1521
|
+
const tryCatch: <E, A>(f: (signal?: AbortSignal) => Thenable<A>, options: {
|
|
1522
|
+
onError: (error: unknown) => E;
|
|
1523
|
+
}) => TaskValidation<E, A>;
|
|
1524
1524
|
/**
|
|
1525
1525
|
* Transforms the success value inside a Task.Validation.
|
|
1526
1526
|
*/
|
|
@@ -1644,6 +1644,16 @@ declare namespace TaskValidation {
|
|
|
1644
1644
|
* ```
|
|
1645
1645
|
*/
|
|
1646
1646
|
const struct: <E, R extends Record<string, any>>(fields: { [K in keyof R]: TaskValidation<E, R[K]>; }) => TaskValidation<E, R>;
|
|
1647
|
+
/**
|
|
1648
|
+
* Creates a memoized version of a Task.Validation. The task is executed at most once on first call,
|
|
1649
|
+
* and its resolved Validation is cached for all subsequent calls.
|
|
1650
|
+
*
|
|
1651
|
+
* @example
|
|
1652
|
+
* ```ts
|
|
1653
|
+
* const validate = Task.Validation.memoize(validateFormTask);
|
|
1654
|
+
* ```
|
|
1655
|
+
*/
|
|
1656
|
+
const memoize: <E, A>(task: TaskValidation<E, A>) => TaskValidation<E, A>;
|
|
1647
1657
|
}
|
|
1648
1658
|
|
|
1649
1659
|
/**
|
|
@@ -1701,16 +1711,6 @@ declare namespace Task {
|
|
|
1701
1711
|
*/
|
|
1702
1712
|
const resolve: <A>(value: A) => Task<A>;
|
|
1703
1713
|
namespace from {
|
|
1704
|
-
/**
|
|
1705
|
-
* Creates a Task from a function that returns a Promise.
|
|
1706
|
-
* The factory optionally receives an `AbortSignal` forwarded from the call site.
|
|
1707
|
-
*
|
|
1708
|
-
* @example
|
|
1709
|
-
* ```ts
|
|
1710
|
-
* const getTimestamp = Task.from.Promise(() => Promise.resolve(Date.now()));
|
|
1711
|
-
* ```
|
|
1712
|
-
*/
|
|
1713
|
-
const Promise: <A>(f: (signal?: AbortSignal) => Thenable<A>) => Task<A>;
|
|
1714
1714
|
/**
|
|
1715
1715
|
* Creates a Task from a lazy synchronous thunk.
|
|
1716
1716
|
* Unlike `Task.resolve(f())`, `from.sync` does not evaluate `f` until the Task is called.
|
|
@@ -1723,6 +1723,21 @@ declare namespace Task {
|
|
|
1723
1723
|
*/
|
|
1724
1724
|
const sync: <A>(f: () => A) => Task<A>;
|
|
1725
1725
|
}
|
|
1726
|
+
/**
|
|
1727
|
+
* Wraps a Promise-returning thunk that may throw or reject,
|
|
1728
|
+
* trapping errors with a fallback function and returning a guaranteed `Task<A>`.
|
|
1729
|
+
*
|
|
1730
|
+
* @example
|
|
1731
|
+
* ```ts
|
|
1732
|
+
* const loadConfig = Task.tryCatch(
|
|
1733
|
+
* () => configStore.get("default"),
|
|
1734
|
+
* { onError: () => DEFAULT_CONFIG }
|
|
1735
|
+
* );
|
|
1736
|
+
* ```
|
|
1737
|
+
*/
|
|
1738
|
+
const tryCatch: <A>(f: (signal?: AbortSignal) => globalThis.Promise<A>, options: {
|
|
1739
|
+
onError: (error: unknown) => A;
|
|
1740
|
+
}) => Task<A>;
|
|
1726
1741
|
/**
|
|
1727
1742
|
* Transforms the value inside a Task.
|
|
1728
1743
|
*
|
|
@@ -1845,8 +1860,8 @@ declare namespace Task {
|
|
|
1845
1860
|
*
|
|
1846
1861
|
* @example
|
|
1847
1862
|
* ```ts
|
|
1848
|
-
* const fast = Task.
|
|
1849
|
-
* const slow = Task.
|
|
1863
|
+
* const fast = Task.resolve("fast");
|
|
1864
|
+
* const slow = Task.delay(Duration.milliseconds(200))(Task.resolve("slow"));
|
|
1850
1865
|
*
|
|
1851
1866
|
* await Task.race([fast, slow])(); // "fast"
|
|
1852
1867
|
* ```
|
|
@@ -1870,10 +1885,7 @@ declare namespace Task {
|
|
|
1870
1885
|
* @example
|
|
1871
1886
|
* ```ts
|
|
1872
1887
|
* let log: number[] = [];
|
|
1873
|
-
* const makeTask = (n: number) => Task.
|
|
1874
|
-
* log.push(n);
|
|
1875
|
-
* return Promise.resolve(n);
|
|
1876
|
-
* });
|
|
1888
|
+
* const makeTask = (n: number) => Task.resolve(n);
|
|
1877
1889
|
*
|
|
1878
1890
|
* await Task.sequential([makeTask(1), makeTask(2), makeTask(3)])();
|
|
1879
1891
|
* // log = [1, 2, 3] — tasks ran in order
|
|
@@ -2089,16 +2101,15 @@ declare namespace Validation {
|
|
|
2089
2101
|
const failed: <E, A>(data: Validation<E, A>) => data is Failed<E>;
|
|
2090
2102
|
}
|
|
2091
2103
|
/**
|
|
2092
|
-
* Creates a Validation from a
|
|
2093
|
-
* Catches any errors and transforms them using the onError function into a Failed validation.
|
|
2104
|
+
* Creates a Validation from a synchronous thunk that may throw.
|
|
2105
|
+
* Catches any errors and transforms them using the `onError` function into a Failed validation.
|
|
2094
2106
|
*
|
|
2095
2107
|
* @example
|
|
2096
2108
|
* ```ts
|
|
2097
|
-
* const
|
|
2098
|
-
*
|
|
2099
|
-
*
|
|
2100
|
-
*
|
|
2101
|
-
* );
|
|
2109
|
+
* const result = Validation.tryCatch(
|
|
2110
|
+
* () => JSON.parse(rawString),
|
|
2111
|
+
* { onError: (e) => `Parse error: ${e}` }
|
|
2112
|
+
* );
|
|
2102
2113
|
* ```
|
|
2103
2114
|
*/
|
|
2104
2115
|
const tryCatch: <E, A>(f: () => A, options: {
|
|
@@ -2,9 +2,8 @@ import {
|
|
|
2
2
|
Deferred,
|
|
3
3
|
Maybe,
|
|
4
4
|
Result,
|
|
5
|
-
Task,
|
|
6
5
|
isNonEmptyArr
|
|
7
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-K7HHEACE.js";
|
|
8
7
|
|
|
9
8
|
// src/Data/Arr.ts
|
|
10
9
|
var ArrMaybe;
|
|
@@ -41,7 +40,7 @@ var ArrResult;
|
|
|
41
40
|
})(ArrResult || (ArrResult = {}));
|
|
42
41
|
var ArrTaskResult;
|
|
43
42
|
((ArrTaskResult2) => {
|
|
44
|
-
ArrTaskResult2.traverse = (f) => (data) =>
|
|
43
|
+
ArrTaskResult2.traverse = (f) => (data) => () => Deferred.from.Promise((async () => {
|
|
45
44
|
const result = [];
|
|
46
45
|
for (const a of data) {
|
|
47
46
|
const r = await Deferred.to.Promise(f(a)());
|
|
@@ -51,12 +50,12 @@ var ArrTaskResult;
|
|
|
51
50
|
result.push(r.value);
|
|
52
51
|
}
|
|
53
52
|
return Result.make.ok(result);
|
|
54
|
-
});
|
|
53
|
+
})());
|
|
55
54
|
ArrTaskResult2.sequence = (data) => (0, ArrTaskResult2.traverse)((a) => a)(data);
|
|
56
55
|
})(ArrTaskResult || (ArrTaskResult = {}));
|
|
57
56
|
var ArrTask;
|
|
58
57
|
((ArrTask2) => {
|
|
59
|
-
ArrTask2.traverse = (f) => (data) =>
|
|
58
|
+
ArrTask2.traverse = (f) => (data) => () => Deferred.from.Promise(Promise.all(data.map((a) => Deferred.to.Promise(f(a)()))));
|
|
60
59
|
ArrTask2.sequence = (data) => (0, ArrTask2.traverse)((a) => a)(data);
|
|
61
60
|
ArrTask2.Result = ArrTaskResult;
|
|
62
61
|
})(ArrTask || (ArrTask = {}));
|