@nlozgachev/pipelined 0.53.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.
@@ -1,4 +1,4 @@
1
- import { D as Duration } from './Duration-B8joKzro.mjs';
1
+ import { D as Duration } from './Duration-B8joKzro.cjs';
2
2
 
3
3
  declare const _deferred: unique symbol;
4
4
  /**
@@ -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-CDiDBAY4.mjs';
2
- import { D as Duration } from './Duration-B8joKzro.mjs';
3
- import { RetryPolicy } from './types.mjs';
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.
@@ -325,7 +325,7 @@ declare namespace Maybe {
325
325
  * pipe(Maybe.make.none<string>(), Maybe.getOrElse(() => null)); // null — typed as string | null
326
326
  * ```
327
327
  */
328
- const getOrElse: <A, B>(defaultValue: () => B) => (data: Maybe<A>) => A | B;
328
+ const getOrElse: <B>(defaultValue: () => B) => <A>(data: Maybe<A>) => A | B;
329
329
  /**
330
330
  * Executes a side effect on the value without changing the Maybe.
331
331
  * Useful for logging or debugging.
@@ -361,7 +361,7 @@ declare namespace Maybe {
361
361
  * pipe(Maybe.make.some(10), Maybe.recover(() => Maybe.make.some(42))); // Some(10)
362
362
  * ```
363
363
  */
364
- const recover: <A, B>(fallback: () => Maybe<B>) => (data: Maybe<A>) => Maybe<A | B>;
364
+ const recover: <B>(fallback: () => Maybe<B>) => <A>(data: Maybe<A>) => Maybe<A | B>;
365
365
  /**
366
366
  * Applies a function wrapped in a Maybe to a value wrapped in a Maybe.
367
367
  *
@@ -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 parseJson = (s: string): Result<string, unknown> =>
601
- * Result.tryCatch(
602
- * () => JSON.parse(s),
603
- * { onError: (e) => `Parse error: ${e}` }
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: {
@@ -685,7 +688,7 @@ declare namespace Result {
685
688
  * pipe(Result.make.err("error"), Result.getOrElse(() => null)); // null — typed as number | null
686
689
  * ```
687
690
  */
688
- const getOrElse: <E, A, B>(defaultValue: () => B) => (data: Result<E, A>) => A | B;
691
+ const getOrElse: <B>(defaultValue: () => B) => <E, A>(data: Result<E, A>) => A | B;
689
692
  /**
690
693
  * Executes a side effect on the success value without changing the Result.
691
694
  * Useful for logging or debugging.
@@ -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))`.
@@ -782,7 +767,7 @@ declare namespace Result {
782
767
  * Recovers from an error by providing a fallback Result.
783
768
  * The fallback can produce a different success type, widening the result to `Result<E, A | B>`.
784
769
  */
785
- const recover: <E, A, B>(fallback: (e: E) => Result<E, B>) => (data: Result<E, A>) => Result<E, A | B>;
770
+ const recover: <E, B>(fallback: (e: E) => Result<E, B>) => <A>(data: Result<E, A>) => Result<E, A | B>;
786
771
  /**
787
772
  * Recovers from an error unless the predicate `isBlocked` returns true for that error.
788
773
  * The fallback can produce a different success type, widening the result to `Result<E, A | B>`.
@@ -795,7 +780,7 @@ declare namespace Result {
795
780
  * ); // Ok(0)
796
781
  * ```
797
782
  */
798
- const recoverUnless: <E, A, B>(isBlocked: (e: E) => boolean, fallback: () => Result<E, B>) => (data: Result<E, A>) => Result<E, A | B>;
783
+ const recoverUnless: <E, B>(isBlocked: (e: E) => boolean, fallback: () => Result<E, B>) => <A>(data: Result<E, A>) => Result<E, A | B>;
799
784
  namespace to {
800
785
  /**
801
786
  * Converts a Result to a Maybe.
@@ -1062,7 +1047,7 @@ declare namespace TaskMaybe {
1062
1047
  * Returns the value or a default if the Task.Maybe resolves to None.
1063
1048
  * The default can be a different type, widening the result to `Task<A | B>`.
1064
1049
  */
1065
- const getOrElse: <A, B>(defaultValue: () => B) => (data: TaskMaybe<A>) => Task<A | B>;
1050
+ const getOrElse: <B>(defaultValue: () => B) => <A>(data: TaskMaybe<A>) => Task<A | B>;
1066
1051
  /**
1067
1052
  * Executes a side effect on the value without changing the Task.Maybe.
1068
1053
  * Useful for logging or debugging.
@@ -1118,7 +1103,7 @@ declare namespace TaskMaybe {
1118
1103
  * ); // Task.Maybe(42)
1119
1104
  * ```
1120
1105
  */
1121
- const recover: <A, B>(fallback: () => TaskMaybe<B>) => (data: TaskMaybe<A>) => TaskMaybe<A | B>;
1106
+ const recover: <B>(fallback: () => TaskMaybe<B>) => <A>(data: TaskMaybe<A>) => TaskMaybe<A | B>;
1122
1107
  /**
1123
1108
  * Combines a record of Task.Maybes into a single Task.Maybe of a record.
1124
1109
  * Evaluates fields in parallel and returns None if any task resolves to None.
@@ -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
- * Wraps a Promise-returning function of any arguments, returning a new function
1210
- * that catches rejections and returns a Task.Result.
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 throwable: <Args extends readonly unknown[], A, E>(f: (...args: Args) => Promise<A>, options: {
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 function that may throw.
1230
- * Catches any errors and transforms them using the onError function.
1231
- * The factory optionally receives an `AbortSignal` forwarded from the call site.
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 fetchUser = (id: string): Task.Result<string, User> =>
1236
- * Task.Result.tryCatch(
1237
- * (signal) => fetch(`/users/${id}`, { signal }).then(r => r.json()),
1238
- * { onError: String }
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: (e: unknown) => E;
1228
+ onError: (error: unknown) => E;
1244
1229
  }) => TaskResult<E, A>;
1245
1230
  /**
1246
1231
  * Transforms the success value inside a Task.Result.
@@ -1270,12 +1255,12 @@ declare namespace TaskResult {
1270
1255
  * Recovers from an error by providing a fallback Task.Result.
1271
1256
  * The fallback can produce a different success type, widening the result to `Task.Result<E, A | B>`.
1272
1257
  */
1273
- const recover: <E, A, B>(fallback: (e: E) => TaskResult<E, B>) => (data: TaskResult<E, A>) => TaskResult<E, A | B>;
1258
+ const recover: <E, B>(fallback: (e: E) => TaskResult<E, B>) => <A>(data: TaskResult<E, A>) => TaskResult<E, A | B>;
1274
1259
  /**
1275
1260
  * Returns the success value or a default value if the Task.Result is an error.
1276
1261
  * The default can be a different type, widening the result to `Task<A | B>`.
1277
1262
  */
1278
- const getOrElse: <E, A, B>(defaultValue: () => B) => (data: TaskResult<E, A>) => Task<A | B>;
1263
+ const getOrElse: <B>(defaultValue: () => B) => <E, A>(data: TaskResult<E, A>) => Task<A | B>;
1279
1264
  /**
1280
1265
  * Executes a side effect on the success value without changing the Task.Result.
1281
1266
  * Useful for logging or debugging.
@@ -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 fetchUser = (id: string): Task.Validation<string, User> =>
1517
- * Task.Validation.tryCatch(
1518
- * (signal) => fetch(`/users/${id}`, { signal }).then(r => r.json()),
1519
- * e => `Failed to fetch user: ${e}`
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>, onError: (e: unknown) => E) => TaskValidation<E, 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
  */
@@ -1566,7 +1556,7 @@ declare namespace TaskValidation {
1566
1556
  * Returns the success value or a default value if the Task.Validation is failed.
1567
1557
  * The default can be a different type, widening the result to `Task<A | B>`.
1568
1558
  */
1569
- const getOrElse: <E, A, B>(defaultValue: () => B) => (data: TaskValidation<E, A>) => Task<A | B>;
1559
+ const getOrElse: <B>(defaultValue: () => B) => <E, A>(data: TaskValidation<E, A>) => Task<A | B>;
1570
1560
  /**
1571
1561
  * Executes a side effect on the success value without changing the Task.Validation.
1572
1562
  * Useful for logging or debugging.
@@ -1577,7 +1567,7 @@ declare namespace TaskValidation {
1577
1567
  * The fallback receives the accumulated error list so callers can inspect which errors occurred.
1578
1568
  * The fallback can produce a different success type, widening the result to `Task.Validation<E, A | B>`.
1579
1569
  */
1580
- const recover: <E, A, B>(fallback: (errors: NonEmptyArr<E>) => TaskValidation<E, B>) => (data: TaskValidation<E, A>) => TaskValidation<E, A | B>;
1570
+ const recover: <E, B>(fallback: (errors: NonEmptyArr<E>) => TaskValidation<E, B>) => <A>(data: TaskValidation<E, A>) => TaskValidation<E, A | B>;
1581
1571
  /**
1582
1572
  * Runs two Task.Validations concurrently and combines their results into a tuple.
1583
1573
  * If both are Passed, returns Passed with both values. If either fails, accumulates
@@ -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.from.Promise(() => new Promise<string>(r => setTimeout(() => r("fast"), 10)));
1849
- * const slow = Task.from.Promise(() => new Promise<string>(r => setTimeout(() => r("slow"), 200)));
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.from.Promise(() => {
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 function that may throw.
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 parseJson = (s: string): Validation<string, unknown> =>
2098
- * Validation.tryCatch(
2099
- * () => JSON.parse(s),
2100
- * { onError: (e) => `Parse error: ${e}` }
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: {
@@ -2255,7 +2246,7 @@ declare namespace Validation {
2255
2246
  * pipe(Validation.make.failed("oops"), Validation.getOrElse(() => null)); // null — typed as number | null
2256
2247
  * ```
2257
2248
  */
2258
- const getOrElse: <E, A, B>(defaultValue: () => B) => (data: Validation<E, A>) => A | B;
2249
+ const getOrElse: <B>(defaultValue: () => B) => <E, A>(data: Validation<E, A>) => A | B;
2259
2250
  /**
2260
2251
  * Executes a side effect on the success value without changing the Validation.
2261
2252
  *
@@ -2288,7 +2279,7 @@ declare namespace Validation {
2288
2279
  * The fallback receives the accumulated error list so callers can inspect which errors occurred.
2289
2280
  * The fallback can produce a different success type, widening the result to `Validation<E, A | B>`.
2290
2281
  */
2291
- const recover: <E, A, B>(fallback: (errors: NonEmptyArr<E>) => Validation<E, B>) => (data: Validation<E, A>) => Validation<E, A | B>;
2282
+ const recover: <E, B>(fallback: (errors: NonEmptyArr<E>) => Validation<E, B>) => <A>(data: Validation<E, A>) => Validation<E, A | B>;
2292
2283
  /**
2293
2284
  * Recovers from a Failed state unless `isBlocked` returns true for any of the accumulated errors.
2294
2285
  * The fallback can produce a different success type, widening the result to `Validation<E, A | B>`.
@@ -2301,7 +2292,7 @@ declare namespace Validation {
2301
2292
  * ); // Passed(0)
2302
2293
  * ```
2303
2294
  */
2304
- const recoverUnless: <E, A, B>(isBlocked: (e: E) => boolean, fallback: () => Validation<E, B>) => (data: Validation<E, A>) => Validation<E, A | B>;
2295
+ const recoverUnless: <E, B>(isBlocked: (e: E) => boolean, fallback: () => Validation<E, B>) => <A>(data: Validation<E, A>) => Validation<E, A | B>;
2305
2296
  namespace to {
2306
2297
  /**
2307
2298
  * Converts a Validation to a Result.