@nlozgachev/pipelined 0.47.0 → 0.48.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/Duration-B8joKzro.d.mts +181 -0
- package/dist/Duration-B8joKzro.d.ts +181 -0
- package/dist/{InternalTypes-Mssktd7z.d.ts → InternalTypes-CDiDBAY4.d.mts} +20 -1
- package/dist/{InternalTypes-CLE7qlOc.d.mts → InternalTypes-LdhLQx3N.d.ts} +20 -1
- package/dist/{Validation-BMsvixWH.d.ts → Validation-1OgJJdeA.d.ts} +507 -37
- package/dist/{Validation-v38R0qH-.d.mts → Validation-D-aARYlP.d.mts} +507 -37
- package/dist/{chunk-KOYYDQH4.mjs → chunk-5OFVS5UZ.mjs} +7 -2
- package/dist/{chunk-XTVF5R6R.mjs → chunk-DENXUTKL.mjs} +24 -0
- package/dist/{chunk-VSU36S2K.mjs → chunk-LR63GW6J.mjs} +223 -18
- package/dist/{chunk-W2L244AS.mjs → chunk-UGVU2RTM.mjs} +279 -1
- package/dist/composition.d.mts +226 -18
- package/dist/composition.d.ts +226 -18
- package/dist/composition.js +10 -3
- package/dist/composition.mjs +8 -4
- package/dist/core.d.mts +151 -8
- package/dist/core.d.ts +151 -8
- package/dist/core.js +222 -17
- package/dist/core.mjs +2 -2
- package/dist/data.d.mts +619 -41
- package/dist/data.d.ts +619 -41
- package/dist/data.js +424 -17
- package/dist/data.mjs +7 -3
- package/dist/index.d.mts +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.js +550 -33
- package/dist/index.mjs +17 -7
- package/dist/types.d.mts +37 -108
- package/dist/types.d.ts +37 -108
- package/dist/types.js +27 -2
- package/dist/types.mjs +5 -3
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Duration
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-DENXUTKL.mjs";
|
|
4
4
|
|
|
5
5
|
// src/Composition/compose.ts
|
|
6
6
|
function compose(f0, f1, f2, f3, f4, f5, f6, f7, f8, f9) {
|
|
@@ -200,6 +200,8 @@ var once = (f) => {
|
|
|
200
200
|
};
|
|
201
201
|
};
|
|
202
202
|
var defaultTo = (fallback) => (a) => a === null || a === void 0 ? fallback : a;
|
|
203
|
+
var tuple = (f) => (args) => f(...args);
|
|
204
|
+
var untuple = (f) => (...args) => f(args);
|
|
203
205
|
|
|
204
206
|
// src/Composition/juxt.ts
|
|
205
207
|
function juxt(fns) {
|
|
@@ -207,8 +209,9 @@ function juxt(fns) {
|
|
|
207
209
|
}
|
|
208
210
|
|
|
209
211
|
// src/Composition/memoize.ts
|
|
210
|
-
var memoize = (f,
|
|
212
|
+
var memoize = (f, options) => {
|
|
211
213
|
const cache = /* @__PURE__ */ new Map();
|
|
214
|
+
const keyFn = options?.key ?? ((a) => a);
|
|
212
215
|
return (a) => {
|
|
213
216
|
const key = keyFn(a);
|
|
214
217
|
if (cache.has(key)) {
|
|
@@ -434,6 +437,8 @@ export {
|
|
|
434
437
|
or,
|
|
435
438
|
once,
|
|
436
439
|
defaultTo,
|
|
440
|
+
tuple,
|
|
441
|
+
untuple,
|
|
437
442
|
juxt,
|
|
438
443
|
memoize,
|
|
439
444
|
memoizeWeak,
|
|
@@ -26,7 +26,31 @@ var Duration;
|
|
|
26
26
|
Duration2.subtract = (other) => (self) => wrap(Brand.unwrap(self) - Brand.unwrap(other));
|
|
27
27
|
})(Duration || (Duration = {}));
|
|
28
28
|
|
|
29
|
+
// src/Types/RetryPolicy.ts
|
|
30
|
+
var RetryPolicy;
|
|
31
|
+
((RetryPolicy2) => {
|
|
32
|
+
RetryPolicy2.constant = (options) => ({
|
|
33
|
+
attempts: Math.max(1, options.attempts),
|
|
34
|
+
getDelay: () => options.delay
|
|
35
|
+
});
|
|
36
|
+
RetryPolicy2.exponential = (options) => {
|
|
37
|
+
const attempts = Math.max(1, options.attempts);
|
|
38
|
+
const initialMs = Duration.to.milliseconds(options.initial);
|
|
39
|
+
const factor = options.factor ?? 2;
|
|
40
|
+
const jitter = options.jitter ?? false;
|
|
41
|
+
return {
|
|
42
|
+
attempts,
|
|
43
|
+
getDelay: (attempt) => {
|
|
44
|
+
const rawMs = initialMs * factor ** Math.max(0, attempt - 1);
|
|
45
|
+
const finalMs = jitter ? Math.random() * rawMs : rawMs;
|
|
46
|
+
return Duration.milliseconds(finalMs);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
})(RetryPolicy || (RetryPolicy = {}));
|
|
51
|
+
|
|
29
52
|
export {
|
|
30
53
|
Brand,
|
|
54
|
+
RetryPolicy,
|
|
31
55
|
Duration
|
|
32
56
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Duration
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-DENXUTKL.mjs";
|
|
4
4
|
|
|
5
5
|
// src/Core/Combinable.ts
|
|
6
6
|
var Combinable;
|
|
@@ -16,6 +16,26 @@ var Combinable;
|
|
|
16
16
|
combine: (b) => (a) => Maybe.is.none(a) ? b : Maybe.is.none(b) ? a : Maybe.make.some(inner.combine(b.value)(a.value))
|
|
17
17
|
});
|
|
18
18
|
Combinable2.fold = (c) => (data) => data.reduce((acc, x) => c.combine(x)(acc), c.empty);
|
|
19
|
+
Combinable2.struct = (fields) => {
|
|
20
|
+
const empty = {};
|
|
21
|
+
for (const key in fields) {
|
|
22
|
+
if (Object.hasOwn(fields, key)) {
|
|
23
|
+
empty[key] = fields[key].empty;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
empty,
|
|
28
|
+
combine: (b) => (a) => {
|
|
29
|
+
const result = {};
|
|
30
|
+
for (const key in fields) {
|
|
31
|
+
if (Object.hasOwn(fields, key)) {
|
|
32
|
+
result[key] = fields[key].combine(b[key])(a[key]);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
};
|
|
19
39
|
})(Combinable || (Combinable = {}));
|
|
20
40
|
|
|
21
41
|
// src/Core/Deferred.ts
|
|
@@ -32,6 +52,8 @@ var Deferred;
|
|
|
32
52
|
((to2) => {
|
|
33
53
|
to2.Promise = (d) => new globalThis.Promise((resolve) => d.then(resolve));
|
|
34
54
|
})(to = Deferred2.to || (Deferred2.to = {}));
|
|
55
|
+
Deferred2.all = (deferreds) => from.Promise(globalThis.Promise.all(deferreds.map((d) => to.Promise(d))));
|
|
56
|
+
Deferred2.race = (deferreds) => from.Promise(globalThis.Promise.race(deferreds.map((d) => to.Promise(d))));
|
|
35
57
|
})(Deferred || (Deferred = {}));
|
|
36
58
|
|
|
37
59
|
// src/Core/Equality.ts
|
|
@@ -44,6 +66,27 @@ var Equality;
|
|
|
44
66
|
Equality2.array = (eq) => (a, b) => a.length === b.length && a.every((x, i) => eq(x, b[i]));
|
|
45
67
|
Equality2.by = (f) => (eq) => (a, b) => eq(f(a), f(b));
|
|
46
68
|
Equality2.and = (eq2) => (eq1) => (a, b) => eq1(a, b) && eq2(a, b);
|
|
69
|
+
Equality2.struct = (fields) => (a, b) => {
|
|
70
|
+
for (const key in fields) {
|
|
71
|
+
if (Object.hasOwn(fields, key)) {
|
|
72
|
+
if (!fields[key](a[key], b[key])) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return true;
|
|
78
|
+
};
|
|
79
|
+
Equality2.tuple = (...equalities) => (a, b) => {
|
|
80
|
+
if (a.length !== b.length) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
for (let i = 0; i < equalities.length; i++) {
|
|
84
|
+
if (!equalities[i](a[i], b[i])) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return true;
|
|
89
|
+
};
|
|
47
90
|
})(Equality || (Equality = {}));
|
|
48
91
|
|
|
49
92
|
// src/Core/Lazy.ts
|
|
@@ -123,6 +166,10 @@ var Logged;
|
|
|
123
166
|
Logged2.bind = (key, f) => (data) => (0, Logged2.chain)(
|
|
124
167
|
(a) => (0, Logged2.map)((b) => ({ ...a, [key]: b }))(f(a))
|
|
125
168
|
)(data);
|
|
169
|
+
Logged2.focus = (lens) => (f) => (data) => ({
|
|
170
|
+
value: lens.set(f(lens.get(data.value)))(data.value),
|
|
171
|
+
log: data.log
|
|
172
|
+
});
|
|
126
173
|
})(Logged || (Logged = {}));
|
|
127
174
|
|
|
128
175
|
// src/Core/Maybe.ts
|
|
@@ -182,6 +229,7 @@ var Maybe;
|
|
|
182
229
|
}
|
|
183
230
|
return make.some(result);
|
|
184
231
|
};
|
|
232
|
+
Maybe3.transposeResult = (data) => is.none(data) ? Result.make.ok(make.none()) : Result.is.ok(data.value) ? Result.make.ok(make.some(data.value.value)) : Result.make.err(data.value.error);
|
|
185
233
|
})(Maybe || (Maybe = {}));
|
|
186
234
|
|
|
187
235
|
// src/internal/Op.util.ts
|
|
@@ -1333,6 +1381,25 @@ var Ordering;
|
|
|
1333
1381
|
return r !== 0 ? r : ord2(a, b);
|
|
1334
1382
|
};
|
|
1335
1383
|
Ordering2.by = (f) => (ord) => (a, b) => ord(f(a), f(b));
|
|
1384
|
+
Ordering2.byFields = (orderings) => (a, b) => {
|
|
1385
|
+
for (let i = 0; i < orderings.length; i++) {
|
|
1386
|
+
const res = orderings[i](a, b);
|
|
1387
|
+
if (res !== 0) {
|
|
1388
|
+
return res;
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
return 0;
|
|
1392
|
+
};
|
|
1393
|
+
Ordering2.tuple = (...orderings) => (a, b) => {
|
|
1394
|
+
const len = Math.min(a.length, b.length);
|
|
1395
|
+
for (let i = 0; i < len; i++) {
|
|
1396
|
+
const res = orderings[i](a[i], b[i]);
|
|
1397
|
+
if (res !== 0) {
|
|
1398
|
+
return res;
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
return a.length - b.length;
|
|
1402
|
+
};
|
|
1336
1403
|
})(Ordering || (Ordering = {}));
|
|
1337
1404
|
|
|
1338
1405
|
// src/Core/Predicate.ts
|
|
@@ -1348,6 +1415,15 @@ var Predicate;
|
|
|
1348
1415
|
((from2) => {
|
|
1349
1416
|
from2.Refinement = (r) => r;
|
|
1350
1417
|
})(from = Predicate2.from || (Predicate2.from = {}));
|
|
1418
|
+
Predicate2.match = (branches, fallback) => (a) => {
|
|
1419
|
+
for (let i = 0; i < branches.length; i++) {
|
|
1420
|
+
const [p, h] = branches[i];
|
|
1421
|
+
if (p(a)) {
|
|
1422
|
+
return h(a);
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
return fallback(a);
|
|
1426
|
+
};
|
|
1351
1427
|
})(Predicate || (Predicate = {}));
|
|
1352
1428
|
|
|
1353
1429
|
// src/Core/Reader.ts
|
|
@@ -1547,11 +1623,11 @@ var Result;
|
|
|
1547
1623
|
is2.ok = (data) => data.kind === "Ok";
|
|
1548
1624
|
is2.err = (data) => data.kind === "Err";
|
|
1549
1625
|
})(is = Result4.is || (Result4.is = {}));
|
|
1550
|
-
Result4.tryCatch = (f,
|
|
1626
|
+
Result4.tryCatch = (f, options) => {
|
|
1551
1627
|
try {
|
|
1552
1628
|
return make.ok(f());
|
|
1553
1629
|
} catch (error) {
|
|
1554
|
-
return make.err(onError(error));
|
|
1630
|
+
return make.err(options.onError(error));
|
|
1555
1631
|
}
|
|
1556
1632
|
};
|
|
1557
1633
|
Result4.map = (f) => (data) => is.ok(data) ? make.ok(f(data.value)) : data;
|
|
@@ -1577,20 +1653,23 @@ var Result;
|
|
|
1577
1653
|
from2.Predicate = (pred, onFalse) => (a) => pred(a) ? make.ok(a) : make.err(onFalse(a));
|
|
1578
1654
|
from2.nullable = (onNull) => (value) => value === null || value === void 0 ? make.err(onNull()) : make.ok(value);
|
|
1579
1655
|
from2.Maybe = (onNone) => (maybe) => Maybe.is.none(maybe) ? make.err(onNone()) : make.ok(maybe.value);
|
|
1580
|
-
from2.throwable = (f,
|
|
1656
|
+
from2.throwable = (f, options) => (...args) => {
|
|
1581
1657
|
try {
|
|
1582
1658
|
return make.ok(f(...args));
|
|
1583
1659
|
} catch (error) {
|
|
1584
|
-
return make.err(onError(error));
|
|
1660
|
+
return make.err(options.onError(error));
|
|
1585
1661
|
}
|
|
1586
1662
|
};
|
|
1663
|
+
from2.Validation = (combineErrors) => (val) => Validation.is.passed(val) ? make.ok(val.value) : make.err(combineErrors(val.errors));
|
|
1587
1664
|
})(from = Result4.from || (Result4.from = {}));
|
|
1588
1665
|
Result4.recover = (fallback) => (data) => is.ok(data) ? data : fallback(data.error);
|
|
1589
1666
|
Result4.recoverUnless = (isBlocked, fallback) => (data) => is.err(data) && !isBlocked(data.error) ? fallback() : data;
|
|
1590
1667
|
let to;
|
|
1591
1668
|
((to2) => {
|
|
1592
1669
|
to2.Maybe = (data) => is.ok(data) ? Maybe.make.some(data.value) : Maybe.make.none();
|
|
1670
|
+
to2.Validation = (data) => Validation.from.Result(data);
|
|
1593
1671
|
})(to = Result4.to || (Result4.to = {}));
|
|
1672
|
+
Result4.transposeMaybe = (data) => is.err(data) ? Maybe.make.some(data) : Maybe.is.some(data.value) ? Maybe.make.some(make.ok(data.value.value)) : Maybe.make.none();
|
|
1594
1673
|
Result4.ap = (arg) => (data) => is.ok(data) && is.ok(arg) ? make.ok(data.value(arg.value)) : is.err(data) ? data : arg;
|
|
1595
1674
|
Result4.bindTo = (key) => (data) => (0, Result4.map)((a) => ({ [key]: a }))(data);
|
|
1596
1675
|
Result4.bind = (key, f) => (data) => (0, Result4.chain)(
|
|
@@ -1609,6 +1688,8 @@ var Result;
|
|
|
1609
1688
|
}
|
|
1610
1689
|
return make.ok(result);
|
|
1611
1690
|
};
|
|
1691
|
+
Result4.ensure = (predicate, onFail) => (data) => is.err(data) ? data : predicate(data.value) ? data : make.err(onFail(data.value));
|
|
1692
|
+
Result4.bimap = (onErr, onOk) => (data) => is.ok(data) ? make.ok(onOk(data.value)) : make.err(onErr(data.error));
|
|
1612
1693
|
})(Result || (Result = {}));
|
|
1613
1694
|
|
|
1614
1695
|
// src/Core/State.ts
|
|
@@ -1644,13 +1725,23 @@ var State;
|
|
|
1644
1725
|
State2.bind = (key, f) => (data) => (0, State2.chain)(
|
|
1645
1726
|
(a) => (0, State2.map)((b) => ({ ...a, [key]: b }))(f(a))
|
|
1646
1727
|
)(data);
|
|
1728
|
+
State2.focus = (lens) => (stateOp) => (s) => {
|
|
1729
|
+
const subState = lens.get(s);
|
|
1730
|
+
const [b, newSubState] = stateOp(subState);
|
|
1731
|
+
return [b, lens.set(newSubState)(s)];
|
|
1732
|
+
};
|
|
1647
1733
|
})(State || (State = {}));
|
|
1648
1734
|
|
|
1649
1735
|
// src/Core/TaskMaybe.ts
|
|
1650
1736
|
var TaskMaybe;
|
|
1651
1737
|
((TaskMaybe2) => {
|
|
1652
|
-
|
|
1653
|
-
|
|
1738
|
+
let make;
|
|
1739
|
+
((make2) => {
|
|
1740
|
+
make2.some = (value) => Task.resolve(Maybe.make.some(value));
|
|
1741
|
+
make2.none = () => Task.resolve(Maybe.make.none());
|
|
1742
|
+
})(make = TaskMaybe2.make || (TaskMaybe2.make = {}));
|
|
1743
|
+
({ some: TaskMaybe2.some } = make);
|
|
1744
|
+
({ none: TaskMaybe2.none } = make);
|
|
1654
1745
|
let from;
|
|
1655
1746
|
((from2) => {
|
|
1656
1747
|
from2.Maybe = (option) => Task.resolve(option);
|
|
@@ -1706,19 +1797,28 @@ var TaskMaybe;
|
|
|
1706
1797
|
// src/Core/TaskResult.ts
|
|
1707
1798
|
var TaskResult;
|
|
1708
1799
|
((TaskResult2) => {
|
|
1709
|
-
|
|
1710
|
-
|
|
1800
|
+
let make;
|
|
1801
|
+
((make2) => {
|
|
1802
|
+
make2.ok = (value) => Task.resolve(Result.make.ok(value));
|
|
1803
|
+
make2.err = (error) => Task.resolve(Result.make.err(error));
|
|
1804
|
+
})(make = TaskResult2.make || (TaskResult2.make = {}));
|
|
1805
|
+
({ ok: TaskResult2.ok } = make);
|
|
1806
|
+
({ err: TaskResult2.err } = make);
|
|
1711
1807
|
let from;
|
|
1712
1808
|
((from2) => {
|
|
1713
1809
|
from2.nullable = (onNull) => (value) => Task.resolve(value === null || value === void 0 ? Result.make.err(onNull()) : Result.make.ok(value));
|
|
1714
1810
|
from2.Maybe = (onNone) => (maybe) => Task.resolve(Maybe.is.none(maybe) ? Result.make.err(onNone()) : Result.make.ok(maybe.value));
|
|
1715
1811
|
from2.Result = (result) => Task.resolve(result);
|
|
1716
|
-
from2.throwable = (f,
|
|
1717
|
-
() => f(...args).then(Result.make.ok).catch((error) => Result.make.err(onError(error)))
|
|
1812
|
+
from2.throwable = (f, options) => (...args) => Task.from.Promise(
|
|
1813
|
+
() => f(...args).then(Result.make.ok).catch((error) => Result.make.err(options.onError(error)))
|
|
1718
1814
|
);
|
|
1719
1815
|
})(from = TaskResult2.from || (TaskResult2.from = {}));
|
|
1720
|
-
|
|
1721
|
-
|
|
1816
|
+
let to;
|
|
1817
|
+
((to2) => {
|
|
1818
|
+
to2.Maybe = (data) => Task.map(Result.to.Maybe)(data);
|
|
1819
|
+
})(to = TaskResult2.to || (TaskResult2.to = {}));
|
|
1820
|
+
TaskResult2.tryCatch = (f, options) => Task.from.Promise(
|
|
1821
|
+
(signal) => Promise.resolve(f(signal)).then(Result.make.ok).catch((error) => Result.make.err(options.onError(error)))
|
|
1722
1822
|
);
|
|
1723
1823
|
TaskResult2.map = (f) => (data) => Task.map(Result.map(f))(data);
|
|
1724
1824
|
TaskResult2.mapError = (f) => (data) => Task.map(Result.mapError(f))(data);
|
|
@@ -1758,6 +1858,60 @@ var TaskResult;
|
|
|
1758
1858
|
return Result.make.ok(record);
|
|
1759
1859
|
});
|
|
1760
1860
|
});
|
|
1861
|
+
TaskResult2.retry = (policy) => (task) => Task.from.Promise((signal) => {
|
|
1862
|
+
const { attempts } = policy;
|
|
1863
|
+
const wait = (duration) => new Promise((res) => {
|
|
1864
|
+
let timerId;
|
|
1865
|
+
const onAbort = () => {
|
|
1866
|
+
clearTimeout(timerId);
|
|
1867
|
+
res();
|
|
1868
|
+
};
|
|
1869
|
+
if (signal) {
|
|
1870
|
+
if (signal.aborted) {
|
|
1871
|
+
return res();
|
|
1872
|
+
}
|
|
1873
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
1874
|
+
}
|
|
1875
|
+
timerId = setTimeout(() => {
|
|
1876
|
+
signal?.removeEventListener("abort", onAbort);
|
|
1877
|
+
res();
|
|
1878
|
+
}, Duration.to.milliseconds(duration));
|
|
1879
|
+
});
|
|
1880
|
+
const executeAttempt = (attempt) => Deferred.to.Promise(task(signal)).then((res) => {
|
|
1881
|
+
if (Result.is.ok(res) || attempt >= attempts || signal?.aborted) {
|
|
1882
|
+
return res;
|
|
1883
|
+
}
|
|
1884
|
+
const delay = policy.getDelay(attempt);
|
|
1885
|
+
return wait(delay).then(() => executeAttempt(attempt + 1));
|
|
1886
|
+
});
|
|
1887
|
+
return executeAttempt(1);
|
|
1888
|
+
});
|
|
1889
|
+
TaskResult2.memoize = (task) => Task.memoize(task);
|
|
1890
|
+
TaskResult2.timeout = (options) => (task) => Task.from.Promise((signal) => {
|
|
1891
|
+
const ms = Duration.to.milliseconds(options.duration);
|
|
1892
|
+
return new Promise((resolve) => {
|
|
1893
|
+
let timerId;
|
|
1894
|
+
const onAbort = () => {
|
|
1895
|
+
clearTimeout(timerId);
|
|
1896
|
+
};
|
|
1897
|
+
if (signal) {
|
|
1898
|
+
if (signal.aborted) {
|
|
1899
|
+
return Deferred.to.Promise(task(signal)).then(resolve);
|
|
1900
|
+
}
|
|
1901
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
1902
|
+
}
|
|
1903
|
+
timerId = setTimeout(() => {
|
|
1904
|
+
signal?.removeEventListener("abort", onAbort);
|
|
1905
|
+
resolve(Result.make.err(options.onTimeout()));
|
|
1906
|
+
}, ms);
|
|
1907
|
+
Deferred.to.Promise(task(signal)).then((res) => {
|
|
1908
|
+
clearTimeout(timerId);
|
|
1909
|
+
signal?.removeEventListener("abort", onAbort);
|
|
1910
|
+
resolve(res);
|
|
1911
|
+
});
|
|
1912
|
+
});
|
|
1913
|
+
});
|
|
1914
|
+
TaskResult2.allSettled = (tasks) => Task.from.Promise((signal) => Promise.all(tasks.map((task) => Deferred.to.Promise(task(signal)))));
|
|
1761
1915
|
})(TaskResult || (TaskResult = {}));
|
|
1762
1916
|
|
|
1763
1917
|
// src/internal/InternalTypes.ts
|
|
@@ -1766,9 +1920,15 @@ var isNonEmptyArr = (list) => list.length > 0;
|
|
|
1766
1920
|
// src/Core/TaskValidation.ts
|
|
1767
1921
|
var TaskValidation;
|
|
1768
1922
|
((TaskValidation2) => {
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1923
|
+
let make;
|
|
1924
|
+
((make2) => {
|
|
1925
|
+
make2.passed = (value) => Task.resolve(Validation.make.passed(value));
|
|
1926
|
+
make2.failed = (error) => Task.resolve(Validation.make.failed(error));
|
|
1927
|
+
make2.failedAll = (errors) => Task.resolve(Validation.make.failedAll(errors));
|
|
1928
|
+
})(make = TaskValidation2.make || (TaskValidation2.make = {}));
|
|
1929
|
+
({ passed: TaskValidation2.passed } = make);
|
|
1930
|
+
({ failed: TaskValidation2.failed } = make);
|
|
1931
|
+
({ failedAll: TaskValidation2.failedAll } = make);
|
|
1772
1932
|
let from;
|
|
1773
1933
|
((from2) => {
|
|
1774
1934
|
from2.Validation = (validation) => Task.resolve(validation);
|
|
@@ -1986,7 +2146,8 @@ var Task;
|
|
|
1986
2146
|
}
|
|
1987
2147
|
return results;
|
|
1988
2148
|
});
|
|
1989
|
-
Task2.timeout = (
|
|
2149
|
+
Task2.timeout = (options) => (task) => from.Promise((outerSignal) => {
|
|
2150
|
+
const { duration, onTimeout } = options;
|
|
1990
2151
|
const controller = new AbortController();
|
|
1991
2152
|
let timerId;
|
|
1992
2153
|
let cleanUp = () => {
|
|
@@ -2043,6 +2204,30 @@ var Task;
|
|
|
2043
2204
|
Task2.bind = (key, f) => (data) => (0, Task2.chain)(
|
|
2044
2205
|
(a) => (0, Task2.map)((b) => ({ ...a, [key]: b }))(f(a))
|
|
2045
2206
|
)(data);
|
|
2207
|
+
Task2.memoize = (task) => {
|
|
2208
|
+
let cached = null;
|
|
2209
|
+
return (signal) => {
|
|
2210
|
+
if (cached === null) {
|
|
2211
|
+
cached = task(signal);
|
|
2212
|
+
}
|
|
2213
|
+
return cached;
|
|
2214
|
+
};
|
|
2215
|
+
};
|
|
2216
|
+
Task2.withProgress = (onProgress) => (task) => (signal) => {
|
|
2217
|
+
onProgress(0);
|
|
2218
|
+
const d = task(signal);
|
|
2219
|
+
return Deferred.from.Promise(
|
|
2220
|
+
Deferred.to.Promise(d).then((res) => {
|
|
2221
|
+
onProgress(1);
|
|
2222
|
+
return res;
|
|
2223
|
+
})
|
|
2224
|
+
);
|
|
2225
|
+
};
|
|
2226
|
+
Task2.withLabel = (label) => (task) => {
|
|
2227
|
+
const fn = ((signal) => task(signal));
|
|
2228
|
+
Object.defineProperty(fn, "label", { value: label, writable: false, enumerable: true, configurable: true });
|
|
2229
|
+
return fn;
|
|
2230
|
+
};
|
|
2046
2231
|
Task2.Maybe = TaskMaybe;
|
|
2047
2232
|
Task2.Result = TaskResult;
|
|
2048
2233
|
Task2.Validation = TaskValidation;
|
|
@@ -2183,6 +2368,13 @@ var Validation;
|
|
|
2183
2368
|
is2.passed = (data) => data.kind === "Passed";
|
|
2184
2369
|
is2.failed = (data) => data.kind === "Failed";
|
|
2185
2370
|
})(is = Validation2.is || (Validation2.is = {}));
|
|
2371
|
+
Validation2.tryCatch = (f, options) => {
|
|
2372
|
+
try {
|
|
2373
|
+
return make.passed(f());
|
|
2374
|
+
} catch (error) {
|
|
2375
|
+
return make.failed(options.onError(error));
|
|
2376
|
+
}
|
|
2377
|
+
};
|
|
2186
2378
|
let from;
|
|
2187
2379
|
((from2) => {
|
|
2188
2380
|
from2.Predicate = (pred, onFalse) => (a) => pred(a) ? make.passed(a) : make.failed(onFalse(a));
|
|
@@ -2198,6 +2390,12 @@ var Validation;
|
|
|
2198
2390
|
}
|
|
2199
2391
|
return is.passed(arg) ? make.failedAll(data.errors) : make.failedAll([...data.errors, ...arg.errors]);
|
|
2200
2392
|
};
|
|
2393
|
+
Validation2.apCustom = (concat) => (arg) => (data) => {
|
|
2394
|
+
if (is.passed(data)) {
|
|
2395
|
+
return is.passed(arg) ? make.passed(data.value(arg.value)) : make.failedAll(arg.errors);
|
|
2396
|
+
}
|
|
2397
|
+
return is.passed(arg) ? make.failedAll(data.errors) : make.failedAll(concat(data.errors, arg.errors));
|
|
2398
|
+
};
|
|
2201
2399
|
Validation2.fold = (onFailed, onPassed) => (data) => is.passed(data) ? onPassed(data.value) : onFailed(data.errors);
|
|
2202
2400
|
Validation2.match = (cases) => (data) => is.passed(data) ? cases.passed(data.value) : cases.failed(data.errors);
|
|
2203
2401
|
Validation2.getOrElse = (defaultValue) => (data) => is.passed(data) ? data.value : defaultValue();
|
|
@@ -2217,7 +2415,14 @@ var Validation;
|
|
|
2217
2415
|
Validation2.recoverUnless = (isBlocked, fallback) => (data) => is.failed(data) && !data.errors.some(isBlocked) ? fallback() : data;
|
|
2218
2416
|
let to;
|
|
2219
2417
|
((to2) => {
|
|
2220
|
-
|
|
2418
|
+
function Result4(arg) {
|
|
2419
|
+
if (typeof arg === "function") {
|
|
2420
|
+
const combine = arg;
|
|
2421
|
+
return (val) => is.passed(val) ? Result.make.ok(val.value) : Result.make.err(combine(val.errors));
|
|
2422
|
+
}
|
|
2423
|
+
return is.passed(arg) ? Result.make.ok(arg.value) : Result.make.err(arg.errors);
|
|
2424
|
+
}
|
|
2425
|
+
to2.Result = Result4;
|
|
2221
2426
|
to2.Maybe = (data) => is.passed(data) ? Maybe.make.some(data.value) : Maybe.make.none();
|
|
2222
2427
|
})(to = Validation2.to || (Validation2.to = {}));
|
|
2223
2428
|
Validation2.product = (first, second) => {
|