@nlozgachev/pipelined 0.54.0 → 0.55.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-CbU7Z-kj.d.cts} +71 -80
- package/dist/{Validation-yOcgYn9K.d.ts → Validation-CmxZ3V4r.d.ts} +68 -77
- package/dist/{chunk-5OFVS5UZ.mjs → chunk-JSG7SFXS.js} +1 -1
- package/dist/{chunk-XFE3SQEE.mjs → chunk-MFJXL6J2.js} +53 -62
- package/dist/{chunk-L6GLADRU.mjs → chunk-NIE7VVZU.js} +4 -5
- 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 +2678 -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 +4508 -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))`.
|
|
@@ -1159,7 +1144,7 @@ declare namespace TaskResult {
|
|
|
1159
1144
|
* const res = await task(); // Ok(42)
|
|
1160
1145
|
* ```
|
|
1161
1146
|
*/
|
|
1162
|
-
const ok: <E, A>(value: A) => TaskResult<E, A>;
|
|
1147
|
+
const ok: <E = never, A = unknown>(value: A) => TaskResult<E, A>;
|
|
1163
1148
|
/**
|
|
1164
1149
|
* Creates a failed Task.Result with the given error.
|
|
1165
1150
|
*
|
|
@@ -1169,10 +1154,10 @@ declare namespace TaskResult {
|
|
|
1169
1154
|
* const res = await task(); // Err("failed")
|
|
1170
1155
|
* ```
|
|
1171
1156
|
*/
|
|
1172
|
-
const err: <E, A>(error: E) => TaskResult<E, A>;
|
|
1157
|
+
const err: <E, A = never>(error: E) => TaskResult<E, A>;
|
|
1173
1158
|
}
|
|
1174
|
-
const ok: <E, A>(value: A) => TaskResult<E, A>;
|
|
1175
|
-
const err: <E, A>(error: E) => TaskResult<E, A>;
|
|
1159
|
+
const ok: <E = never, A = unknown>(value: A) => TaskResult<E, A>;
|
|
1160
|
+
const err: <E, A = never>(error: E) => TaskResult<E, A>;
|
|
1176
1161
|
namespace from {
|
|
1177
1162
|
/**
|
|
1178
1163
|
* Creates a Task.Result from a nullable value.
|
|
@@ -1204,14 +1189,15 @@ declare namespace TaskResult {
|
|
|
1204
1189
|
* Task.Result.from.Result(Result.make.ok(42)); // resolves to Ok(42)
|
|
1205
1190
|
* ```
|
|
1206
1191
|
*/
|
|
1207
|
-
const Result: <E, A>(result: Result<E, A>) => TaskResult<E, A>;
|
|
1208
1192
|
/**
|
|
1209
|
-
*
|
|
1210
|
-
*
|
|
1193
|
+
* Lifts a Result into a Task.Result.
|
|
1194
|
+
*
|
|
1195
|
+
* @example
|
|
1196
|
+
* ```ts
|
|
1197
|
+
* Task.Result.from.Result(Result.make.ok(42)); // resolves to Ok(42)
|
|
1198
|
+
* ```
|
|
1211
1199
|
*/
|
|
1212
|
-
const
|
|
1213
|
-
onError: (e: unknown) => E;
|
|
1214
|
-
}) => (...args: Args) => TaskResult<E, A>;
|
|
1200
|
+
const Result: <E, A>(result: Result<E, A>) => TaskResult<E, A>;
|
|
1215
1201
|
}
|
|
1216
1202
|
namespace to {
|
|
1217
1203
|
/**
|
|
@@ -1226,21 +1212,20 @@ declare namespace TaskResult {
|
|
|
1226
1212
|
const Maybe: <E, A>(data: TaskResult<E, A>) => TaskMaybe<A>;
|
|
1227
1213
|
}
|
|
1228
1214
|
/**
|
|
1229
|
-
* Creates a Task.Result from a
|
|
1230
|
-
* Catches any errors and transforms them using the onError function
|
|
1231
|
-
* The
|
|
1215
|
+
* Creates a Task.Result from a Promise-returning thunk that may throw or reject.
|
|
1216
|
+
* Catches any errors and transforms them using the `onError` function into an `Err`.
|
|
1217
|
+
* The thunk optionally receives an `AbortSignal` forwarded from the call site.
|
|
1232
1218
|
*
|
|
1233
1219
|
* @example
|
|
1234
1220
|
* ```ts
|
|
1235
|
-
* const
|
|
1236
|
-
*
|
|
1237
|
-
*
|
|
1238
|
-
*
|
|
1239
|
-
* );
|
|
1221
|
+
* const loadUser = Task.Result.tryCatch(
|
|
1222
|
+
* (signal) => userStore.get("u_123", { signal }),
|
|
1223
|
+
* { onError: (e) => new DbError(e) }
|
|
1224
|
+
* );
|
|
1240
1225
|
* ```
|
|
1241
1226
|
*/
|
|
1242
1227
|
const tryCatch: <E, A>(f: (signal?: AbortSignal) => Thenable<A>, options: {
|
|
1243
|
-
onError: (
|
|
1228
|
+
onError: (error: unknown) => E;
|
|
1244
1229
|
}) => TaskResult<E, A>;
|
|
1245
1230
|
/**
|
|
1246
1231
|
* Transforms the success value inside a Task.Result.
|
|
@@ -1436,7 +1421,7 @@ declare namespace TaskValidation {
|
|
|
1436
1421
|
* const res = await task(); // Passed(42)
|
|
1437
1422
|
* ```
|
|
1438
1423
|
*/
|
|
1439
|
-
const passed: <E, A>(value: A) => TaskValidation<E, A>;
|
|
1424
|
+
const passed: <E = never, A = unknown>(value: A) => TaskValidation<E, A>;
|
|
1440
1425
|
/**
|
|
1441
1426
|
* Creates a failed Task.Validation with a single error.
|
|
1442
1427
|
*
|
|
@@ -1446,7 +1431,7 @@ declare namespace TaskValidation {
|
|
|
1446
1431
|
* const res = await task(); // Failed(["invalid"])
|
|
1447
1432
|
* ```
|
|
1448
1433
|
*/
|
|
1449
|
-
const failed: <E, A>(error: E) => TaskValidation<E, A>;
|
|
1434
|
+
const failed: <E, A = never>(error: E) => TaskValidation<E, A>;
|
|
1450
1435
|
/**
|
|
1451
1436
|
* Creates a failed Task.Validation from multiple errors.
|
|
1452
1437
|
*
|
|
@@ -1456,11 +1441,11 @@ declare namespace TaskValidation {
|
|
|
1456
1441
|
* const res = await task(); // Failed(["err1", "err2"])
|
|
1457
1442
|
* ```
|
|
1458
1443
|
*/
|
|
1459
|
-
const failedAll: <E, A>(errors: NonEmptyArr<E>) => TaskValidation<E, A>;
|
|
1444
|
+
const failedAll: <E, A = never>(errors: NonEmptyArr<E>) => TaskValidation<E, A>;
|
|
1460
1445
|
}
|
|
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>;
|
|
1446
|
+
const passed: <E = never, A = unknown>(value: A) => TaskValidation<E, A>;
|
|
1447
|
+
const failed: <E, A = never>(error: E) => TaskValidation<E, A>;
|
|
1448
|
+
const failedAll: <E, A = never>(errors: NonEmptyArr<E>) => TaskValidation<E, A>;
|
|
1464
1449
|
namespace from {
|
|
1465
1450
|
/**
|
|
1466
1451
|
* Lifts a Validation into a Task.Validation.
|
|
@@ -1510,17 +1495,22 @@ declare namespace TaskValidation {
|
|
|
1510
1495
|
* Creates a Task.Validation from a Promise-returning function.
|
|
1511
1496
|
* Catches any errors and transforms them using the onError function.
|
|
1512
1497
|
* The factory optionally receives an `AbortSignal` forwarded from the call site.
|
|
1498
|
+
/**
|
|
1499
|
+
* Creates a Task.Validation from a Promise-returning thunk that may throw or reject.
|
|
1500
|
+
* Catches any errors and transforms them using the `onError` function into a Failed validation.
|
|
1501
|
+
* The thunk optionally receives an `AbortSignal` forwarded from the call site.
|
|
1513
1502
|
*
|
|
1514
1503
|
* @example
|
|
1515
1504
|
* ```ts
|
|
1516
|
-
* const
|
|
1517
|
-
*
|
|
1518
|
-
*
|
|
1519
|
-
*
|
|
1520
|
-
* );
|
|
1505
|
+
* const loadConfig = Task.Validation.tryCatch(
|
|
1506
|
+
* (signal) => configStore.get("default", { signal }),
|
|
1507
|
+
* { onError: (e) => `Failed to load config: ${e}` }
|
|
1508
|
+
* );
|
|
1521
1509
|
* ```
|
|
1522
1510
|
*/
|
|
1523
|
-
const tryCatch: <E, A>(f: (signal?: AbortSignal) => Thenable<A>,
|
|
1511
|
+
const tryCatch: <E, A>(f: (signal?: AbortSignal) => Thenable<A>, options: {
|
|
1512
|
+
onError: (error: unknown) => E;
|
|
1513
|
+
}) => TaskValidation<E, A>;
|
|
1524
1514
|
/**
|
|
1525
1515
|
* Transforms the success value inside a Task.Validation.
|
|
1526
1516
|
*/
|
|
@@ -1701,16 +1691,6 @@ declare namespace Task {
|
|
|
1701
1691
|
*/
|
|
1702
1692
|
const resolve: <A>(value: A) => Task<A>;
|
|
1703
1693
|
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
1694
|
/**
|
|
1715
1695
|
* Creates a Task from a lazy synchronous thunk.
|
|
1716
1696
|
* Unlike `Task.resolve(f())`, `from.sync` does not evaluate `f` until the Task is called.
|
|
@@ -1723,6 +1703,21 @@ declare namespace Task {
|
|
|
1723
1703
|
*/
|
|
1724
1704
|
const sync: <A>(f: () => A) => Task<A>;
|
|
1725
1705
|
}
|
|
1706
|
+
/**
|
|
1707
|
+
* Wraps a Promise-returning thunk that may throw or reject,
|
|
1708
|
+
* trapping errors with a fallback function and returning a guaranteed `Task<A>`.
|
|
1709
|
+
*
|
|
1710
|
+
* @example
|
|
1711
|
+
* ```ts
|
|
1712
|
+
* const loadConfig = Task.tryCatch(
|
|
1713
|
+
* () => configStore.get("default"),
|
|
1714
|
+
* { onError: () => DEFAULT_CONFIG }
|
|
1715
|
+
* );
|
|
1716
|
+
* ```
|
|
1717
|
+
*/
|
|
1718
|
+
const tryCatch: <A>(f: (signal?: AbortSignal) => globalThis.Promise<A>, options: {
|
|
1719
|
+
onError: (error: unknown) => A;
|
|
1720
|
+
}) => Task<A>;
|
|
1726
1721
|
/**
|
|
1727
1722
|
* Transforms the value inside a Task.
|
|
1728
1723
|
*
|
|
@@ -1845,8 +1840,8 @@ declare namespace Task {
|
|
|
1845
1840
|
*
|
|
1846
1841
|
* @example
|
|
1847
1842
|
* ```ts
|
|
1848
|
-
* const fast = Task.
|
|
1849
|
-
* const slow = Task.
|
|
1843
|
+
* const fast = Task.resolve("fast");
|
|
1844
|
+
* const slow = Task.delay(Duration.milliseconds(200))(Task.resolve("slow"));
|
|
1850
1845
|
*
|
|
1851
1846
|
* await Task.race([fast, slow])(); // "fast"
|
|
1852
1847
|
* ```
|
|
@@ -1870,10 +1865,7 @@ declare namespace Task {
|
|
|
1870
1865
|
* @example
|
|
1871
1866
|
* ```ts
|
|
1872
1867
|
* let log: number[] = [];
|
|
1873
|
-
* const makeTask = (n: number) => Task.
|
|
1874
|
-
* log.push(n);
|
|
1875
|
-
* return Promise.resolve(n);
|
|
1876
|
-
* });
|
|
1868
|
+
* const makeTask = (n: number) => Task.resolve(n);
|
|
1877
1869
|
*
|
|
1878
1870
|
* await Task.sequential([makeTask(1), makeTask(2), makeTask(3)])();
|
|
1879
1871
|
* // log = [1, 2, 3] — tasks ran in order
|
|
@@ -2089,16 +2081,15 @@ declare namespace Validation {
|
|
|
2089
2081
|
const failed: <E, A>(data: Validation<E, A>) => data is Failed<E>;
|
|
2090
2082
|
}
|
|
2091
2083
|
/**
|
|
2092
|
-
* Creates a Validation from a
|
|
2093
|
-
* Catches any errors and transforms them using the onError function into a Failed validation.
|
|
2084
|
+
* Creates a Validation from a synchronous thunk that may throw.
|
|
2085
|
+
* Catches any errors and transforms them using the `onError` function into a Failed validation.
|
|
2094
2086
|
*
|
|
2095
2087
|
* @example
|
|
2096
2088
|
* ```ts
|
|
2097
|
-
* const
|
|
2098
|
-
*
|
|
2099
|
-
*
|
|
2100
|
-
*
|
|
2101
|
-
* );
|
|
2089
|
+
* const result = Validation.tryCatch(
|
|
2090
|
+
* () => JSON.parse(rawString),
|
|
2091
|
+
* { onError: (e) => `Parse error: ${e}` }
|
|
2092
|
+
* );
|
|
2102
2093
|
* ```
|
|
2103
2094
|
*/
|
|
2104
2095
|
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))`.
|
|
@@ -1159,7 +1144,7 @@ declare namespace TaskResult {
|
|
|
1159
1144
|
* const res = await task(); // Ok(42)
|
|
1160
1145
|
* ```
|
|
1161
1146
|
*/
|
|
1162
|
-
const ok: <E, A>(value: A) => TaskResult<E, A>;
|
|
1147
|
+
const ok: <E = never, A = unknown>(value: A) => TaskResult<E, A>;
|
|
1163
1148
|
/**
|
|
1164
1149
|
* Creates a failed Task.Result with the given error.
|
|
1165
1150
|
*
|
|
@@ -1169,10 +1154,10 @@ declare namespace TaskResult {
|
|
|
1169
1154
|
* const res = await task(); // Err("failed")
|
|
1170
1155
|
* ```
|
|
1171
1156
|
*/
|
|
1172
|
-
const err: <E, A>(error: E) => TaskResult<E, A>;
|
|
1157
|
+
const err: <E, A = never>(error: E) => TaskResult<E, A>;
|
|
1173
1158
|
}
|
|
1174
|
-
const ok: <E, A>(value: A) => TaskResult<E, A>;
|
|
1175
|
-
const err: <E, A>(error: E) => TaskResult<E, A>;
|
|
1159
|
+
const ok: <E = never, A = unknown>(value: A) => TaskResult<E, A>;
|
|
1160
|
+
const err: <E, A = never>(error: E) => TaskResult<E, A>;
|
|
1176
1161
|
namespace from {
|
|
1177
1162
|
/**
|
|
1178
1163
|
* Creates a Task.Result from a nullable value.
|
|
@@ -1204,14 +1189,15 @@ declare namespace TaskResult {
|
|
|
1204
1189
|
* Task.Result.from.Result(Result.make.ok(42)); // resolves to Ok(42)
|
|
1205
1190
|
* ```
|
|
1206
1191
|
*/
|
|
1207
|
-
const Result: <E, A>(result: Result<E, A>) => TaskResult<E, A>;
|
|
1208
1192
|
/**
|
|
1209
|
-
*
|
|
1210
|
-
*
|
|
1193
|
+
* Lifts a Result into a Task.Result.
|
|
1194
|
+
*
|
|
1195
|
+
* @example
|
|
1196
|
+
* ```ts
|
|
1197
|
+
* Task.Result.from.Result(Result.make.ok(42)); // resolves to Ok(42)
|
|
1198
|
+
* ```
|
|
1211
1199
|
*/
|
|
1212
|
-
const
|
|
1213
|
-
onError: (e: unknown) => E;
|
|
1214
|
-
}) => (...args: Args) => TaskResult<E, A>;
|
|
1200
|
+
const Result: <E, A>(result: Result<E, A>) => TaskResult<E, A>;
|
|
1215
1201
|
}
|
|
1216
1202
|
namespace to {
|
|
1217
1203
|
/**
|
|
@@ -1226,21 +1212,20 @@ declare namespace TaskResult {
|
|
|
1226
1212
|
const Maybe: <E, A>(data: TaskResult<E, A>) => TaskMaybe<A>;
|
|
1227
1213
|
}
|
|
1228
1214
|
/**
|
|
1229
|
-
* Creates a Task.Result from a
|
|
1230
|
-
* Catches any errors and transforms them using the onError function
|
|
1231
|
-
* The
|
|
1215
|
+
* Creates a Task.Result from a Promise-returning thunk that may throw or reject.
|
|
1216
|
+
* Catches any errors and transforms them using the `onError` function into an `Err`.
|
|
1217
|
+
* The thunk optionally receives an `AbortSignal` forwarded from the call site.
|
|
1232
1218
|
*
|
|
1233
1219
|
* @example
|
|
1234
1220
|
* ```ts
|
|
1235
|
-
* const
|
|
1236
|
-
*
|
|
1237
|
-
*
|
|
1238
|
-
*
|
|
1239
|
-
* );
|
|
1221
|
+
* const loadUser = Task.Result.tryCatch(
|
|
1222
|
+
* (signal) => userStore.get("u_123", { signal }),
|
|
1223
|
+
* { onError: (e) => new DbError(e) }
|
|
1224
|
+
* );
|
|
1240
1225
|
* ```
|
|
1241
1226
|
*/
|
|
1242
1227
|
const tryCatch: <E, A>(f: (signal?: AbortSignal) => Thenable<A>, options: {
|
|
1243
|
-
onError: (
|
|
1228
|
+
onError: (error: unknown) => E;
|
|
1244
1229
|
}) => TaskResult<E, A>;
|
|
1245
1230
|
/**
|
|
1246
1231
|
* Transforms the success value inside a Task.Result.
|
|
@@ -1436,7 +1421,7 @@ declare namespace TaskValidation {
|
|
|
1436
1421
|
* const res = await task(); // Passed(42)
|
|
1437
1422
|
* ```
|
|
1438
1423
|
*/
|
|
1439
|
-
const passed: <E, A>(value: A) => TaskValidation<E, A>;
|
|
1424
|
+
const passed: <E = never, A = unknown>(value: A) => TaskValidation<E, A>;
|
|
1440
1425
|
/**
|
|
1441
1426
|
* Creates a failed Task.Validation with a single error.
|
|
1442
1427
|
*
|
|
@@ -1446,7 +1431,7 @@ declare namespace TaskValidation {
|
|
|
1446
1431
|
* const res = await task(); // Failed(["invalid"])
|
|
1447
1432
|
* ```
|
|
1448
1433
|
*/
|
|
1449
|
-
const failed: <E, A>(error: E) => TaskValidation<E, A>;
|
|
1434
|
+
const failed: <E, A = never>(error: E) => TaskValidation<E, A>;
|
|
1450
1435
|
/**
|
|
1451
1436
|
* Creates a failed Task.Validation from multiple errors.
|
|
1452
1437
|
*
|
|
@@ -1456,11 +1441,11 @@ declare namespace TaskValidation {
|
|
|
1456
1441
|
* const res = await task(); // Failed(["err1", "err2"])
|
|
1457
1442
|
* ```
|
|
1458
1443
|
*/
|
|
1459
|
-
const failedAll: <E, A>(errors: NonEmptyArr<E>) => TaskValidation<E, A>;
|
|
1444
|
+
const failedAll: <E, A = never>(errors: NonEmptyArr<E>) => TaskValidation<E, A>;
|
|
1460
1445
|
}
|
|
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>;
|
|
1446
|
+
const passed: <E = never, A = unknown>(value: A) => TaskValidation<E, A>;
|
|
1447
|
+
const failed: <E, A = never>(error: E) => TaskValidation<E, A>;
|
|
1448
|
+
const failedAll: <E, A = never>(errors: NonEmptyArr<E>) => TaskValidation<E, A>;
|
|
1464
1449
|
namespace from {
|
|
1465
1450
|
/**
|
|
1466
1451
|
* Lifts a Validation into a Task.Validation.
|
|
@@ -1510,17 +1495,22 @@ declare namespace TaskValidation {
|
|
|
1510
1495
|
* Creates a Task.Validation from a Promise-returning function.
|
|
1511
1496
|
* Catches any errors and transforms them using the onError function.
|
|
1512
1497
|
* The factory optionally receives an `AbortSignal` forwarded from the call site.
|
|
1498
|
+
/**
|
|
1499
|
+
* Creates a Task.Validation from a Promise-returning thunk that may throw or reject.
|
|
1500
|
+
* Catches any errors and transforms them using the `onError` function into a Failed validation.
|
|
1501
|
+
* The thunk optionally receives an `AbortSignal` forwarded from the call site.
|
|
1513
1502
|
*
|
|
1514
1503
|
* @example
|
|
1515
1504
|
* ```ts
|
|
1516
|
-
* const
|
|
1517
|
-
*
|
|
1518
|
-
*
|
|
1519
|
-
*
|
|
1520
|
-
* );
|
|
1505
|
+
* const loadConfig = Task.Validation.tryCatch(
|
|
1506
|
+
* (signal) => configStore.get("default", { signal }),
|
|
1507
|
+
* { onError: (e) => `Failed to load config: ${e}` }
|
|
1508
|
+
* );
|
|
1521
1509
|
* ```
|
|
1522
1510
|
*/
|
|
1523
|
-
const tryCatch: <E, A>(f: (signal?: AbortSignal) => Thenable<A>,
|
|
1511
|
+
const tryCatch: <E, A>(f: (signal?: AbortSignal) => Thenable<A>, options: {
|
|
1512
|
+
onError: (error: unknown) => E;
|
|
1513
|
+
}) => TaskValidation<E, A>;
|
|
1524
1514
|
/**
|
|
1525
1515
|
* Transforms the success value inside a Task.Validation.
|
|
1526
1516
|
*/
|
|
@@ -1701,16 +1691,6 @@ declare namespace Task {
|
|
|
1701
1691
|
*/
|
|
1702
1692
|
const resolve: <A>(value: A) => Task<A>;
|
|
1703
1693
|
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
1694
|
/**
|
|
1715
1695
|
* Creates a Task from a lazy synchronous thunk.
|
|
1716
1696
|
* Unlike `Task.resolve(f())`, `from.sync` does not evaluate `f` until the Task is called.
|
|
@@ -1723,6 +1703,21 @@ declare namespace Task {
|
|
|
1723
1703
|
*/
|
|
1724
1704
|
const sync: <A>(f: () => A) => Task<A>;
|
|
1725
1705
|
}
|
|
1706
|
+
/**
|
|
1707
|
+
* Wraps a Promise-returning thunk that may throw or reject,
|
|
1708
|
+
* trapping errors with a fallback function and returning a guaranteed `Task<A>`.
|
|
1709
|
+
*
|
|
1710
|
+
* @example
|
|
1711
|
+
* ```ts
|
|
1712
|
+
* const loadConfig = Task.tryCatch(
|
|
1713
|
+
* () => configStore.get("default"),
|
|
1714
|
+
* { onError: () => DEFAULT_CONFIG }
|
|
1715
|
+
* );
|
|
1716
|
+
* ```
|
|
1717
|
+
*/
|
|
1718
|
+
const tryCatch: <A>(f: (signal?: AbortSignal) => globalThis.Promise<A>, options: {
|
|
1719
|
+
onError: (error: unknown) => A;
|
|
1720
|
+
}) => Task<A>;
|
|
1726
1721
|
/**
|
|
1727
1722
|
* Transforms the value inside a Task.
|
|
1728
1723
|
*
|
|
@@ -1845,8 +1840,8 @@ declare namespace Task {
|
|
|
1845
1840
|
*
|
|
1846
1841
|
* @example
|
|
1847
1842
|
* ```ts
|
|
1848
|
-
* const fast = Task.
|
|
1849
|
-
* const slow = Task.
|
|
1843
|
+
* const fast = Task.resolve("fast");
|
|
1844
|
+
* const slow = Task.delay(Duration.milliseconds(200))(Task.resolve("slow"));
|
|
1850
1845
|
*
|
|
1851
1846
|
* await Task.race([fast, slow])(); // "fast"
|
|
1852
1847
|
* ```
|
|
@@ -1870,10 +1865,7 @@ declare namespace Task {
|
|
|
1870
1865
|
* @example
|
|
1871
1866
|
* ```ts
|
|
1872
1867
|
* let log: number[] = [];
|
|
1873
|
-
* const makeTask = (n: number) => Task.
|
|
1874
|
-
* log.push(n);
|
|
1875
|
-
* return Promise.resolve(n);
|
|
1876
|
-
* });
|
|
1868
|
+
* const makeTask = (n: number) => Task.resolve(n);
|
|
1877
1869
|
*
|
|
1878
1870
|
* await Task.sequential([makeTask(1), makeTask(2), makeTask(3)])();
|
|
1879
1871
|
* // log = [1, 2, 3] — tasks ran in order
|
|
@@ -2089,16 +2081,15 @@ declare namespace Validation {
|
|
|
2089
2081
|
const failed: <E, A>(data: Validation<E, A>) => data is Failed<E>;
|
|
2090
2082
|
}
|
|
2091
2083
|
/**
|
|
2092
|
-
* Creates a Validation from a
|
|
2093
|
-
* Catches any errors and transforms them using the onError function into a Failed validation.
|
|
2084
|
+
* Creates a Validation from a synchronous thunk that may throw.
|
|
2085
|
+
* Catches any errors and transforms them using the `onError` function into a Failed validation.
|
|
2094
2086
|
*
|
|
2095
2087
|
* @example
|
|
2096
2088
|
* ```ts
|
|
2097
|
-
* const
|
|
2098
|
-
*
|
|
2099
|
-
*
|
|
2100
|
-
*
|
|
2101
|
-
* );
|
|
2089
|
+
* const result = Validation.tryCatch(
|
|
2090
|
+
* () => JSON.parse(rawString),
|
|
2091
|
+
* { onError: (e) => `Parse error: ${e}` }
|
|
2092
|
+
* );
|
|
2102
2093
|
* ```
|
|
2103
2094
|
*/
|
|
2104
2095
|
const tryCatch: <E, A>(f: () => A, options: {
|