@nlozgachev/pipelined 0.36.0 → 0.37.1
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/README.md +18 -7
- package/dist/{Task-DXsuurnc.d.mts → Task-DcXhCZYg.d.mts} +472 -380
- package/dist/{Task-zAY4kSVB.d.ts → Task-uupX7xd9.d.ts} +472 -380
- package/dist/{chunk-VWVPHDZO.mjs → chunk-5AFEEFE4.mjs} +5 -1
- package/dist/{chunk-IJFFWBKW.mjs → chunk-E7YI5PVW.mjs} +2 -2
- package/dist/{chunk-4QMYKCWE.mjs → chunk-M2X7TFKN.mjs} +500 -100
- package/dist/core.d.mts +743 -605
- package/dist/core.d.ts +743 -605
- package/dist/core.js +336 -246
- package/dist/core.mjs +6 -8
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +353 -263
- package/dist/index.mjs +16 -21
- package/dist/types.d.mts +29 -29
- package/dist/types.d.ts +29 -29
- package/dist/types.mjs +3 -6
- package/dist/utils.d.mts +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +89 -51
- package/dist/utils.mjs +3 -4
- package/package.json +17 -5
- package/dist/chunk-DBIC62UV.mjs +0 -6
- package/dist/chunk-DLBHVYII.mjs +0 -322
- package/dist/chunk-IPP4XFYH.mjs +0 -0
package/dist/index.js
CHANGED
|
@@ -46,7 +46,7 @@ __export(src_exports, {
|
|
|
46
46
|
Str: () => Str,
|
|
47
47
|
Task: () => Task,
|
|
48
48
|
TaskMaybe: () => TaskMaybe,
|
|
49
|
-
TaskResult: () =>
|
|
49
|
+
TaskResult: () => TaskResult3,
|
|
50
50
|
TaskValidation: () => TaskValidation,
|
|
51
51
|
These: () => These,
|
|
52
52
|
Tuple: () => Tuple,
|
|
@@ -417,84 +417,6 @@ function uncurry(f) {
|
|
|
417
417
|
var uncurry3 = (f) => (a, b, c) => f(a)(b)(c);
|
|
418
418
|
var uncurry4 = (f) => (a, b, c, d) => f(a)(b)(c)(d);
|
|
419
419
|
|
|
420
|
-
// src/Core/Result.ts
|
|
421
|
-
var Result;
|
|
422
|
-
((Result2) => {
|
|
423
|
-
Result2.ok = (value) => ({ kind: "Ok", value });
|
|
424
|
-
Result2.err = (e) => ({ kind: "Err", error: e });
|
|
425
|
-
Result2.isOk = (data) => data.kind === "Ok";
|
|
426
|
-
Result2.isErr = (data) => data.kind === "Err";
|
|
427
|
-
Result2.tryCatch = (f, onError) => {
|
|
428
|
-
try {
|
|
429
|
-
return (0, Result2.ok)(f());
|
|
430
|
-
} catch (error) {
|
|
431
|
-
return (0, Result2.err)(onError(error));
|
|
432
|
-
}
|
|
433
|
-
};
|
|
434
|
-
Result2.map = (f) => (data) => (0, Result2.isOk)(data) ? (0, Result2.ok)(f(data.value)) : data;
|
|
435
|
-
Result2.mapError = (f) => (data) => (0, Result2.isErr)(data) ? (0, Result2.err)(f(data.error)) : data;
|
|
436
|
-
Result2.chain = (f) => (data) => (0, Result2.isOk)(data) ? f(data.value) : data;
|
|
437
|
-
Result2.fold = (onErr, onOk) => (data) => (0, Result2.isOk)(data) ? onOk(data.value) : onErr(data.error);
|
|
438
|
-
Result2.match = (cases) => (data) => (0, Result2.isOk)(data) ? cases.ok(data.value) : cases.err(data.error);
|
|
439
|
-
Result2.getOrElse = (defaultValue) => (data) => (0, Result2.isOk)(data) ? data.value : defaultValue();
|
|
440
|
-
Result2.tap = (f) => (data) => {
|
|
441
|
-
if ((0, Result2.isOk)(data)) {
|
|
442
|
-
f(data.value);
|
|
443
|
-
}
|
|
444
|
-
return data;
|
|
445
|
-
};
|
|
446
|
-
Result2.tapError = (f) => (data) => {
|
|
447
|
-
if ((0, Result2.isErr)(data)) {
|
|
448
|
-
f(data.error);
|
|
449
|
-
}
|
|
450
|
-
return data;
|
|
451
|
-
};
|
|
452
|
-
Result2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Result2.ok)(a) : (0, Result2.err)(onFalse(a));
|
|
453
|
-
Result2.fromNullable = (onNull) => (value) => value === null || value === void 0 ? (0, Result2.err)(onNull()) : (0, Result2.ok)(value);
|
|
454
|
-
Result2.fromMaybe = (onNone) => (maybe) => Maybe.isNone(maybe) ? (0, Result2.err)(onNone()) : (0, Result2.ok)(maybe.value);
|
|
455
|
-
Result2.fromThrowable = (f, onError) => (...args) => {
|
|
456
|
-
try {
|
|
457
|
-
return (0, Result2.ok)(f(...args));
|
|
458
|
-
} catch (error) {
|
|
459
|
-
return (0, Result2.err)(onError(error));
|
|
460
|
-
}
|
|
461
|
-
};
|
|
462
|
-
Result2.recover = (fallback) => (data) => (0, Result2.isOk)(data) ? data : fallback(data.error);
|
|
463
|
-
Result2.recoverUnless = (isBlocked, fallback) => (data) => (0, Result2.isErr)(data) && !isBlocked(data.error) ? fallback() : data;
|
|
464
|
-
Result2.toMaybe = (data) => (0, Result2.isOk)(data) ? Maybe.some(data.value) : Maybe.none();
|
|
465
|
-
Result2.ap = (arg) => (data) => (0, Result2.isOk)(data) && (0, Result2.isOk)(arg) ? (0, Result2.ok)(data.value(arg.value)) : (0, Result2.isErr)(data) ? data : arg;
|
|
466
|
-
})(Result || (Result = {}));
|
|
467
|
-
|
|
468
|
-
// src/Core/Maybe.ts
|
|
469
|
-
var _none = { kind: "None" };
|
|
470
|
-
var Maybe;
|
|
471
|
-
((Maybe2) => {
|
|
472
|
-
Maybe2.some = (value) => ({ kind: "Some", value });
|
|
473
|
-
Maybe2.isSome = (data) => data.kind === "Some";
|
|
474
|
-
Maybe2.none = () => _none;
|
|
475
|
-
Maybe2.isNone = (data) => data.kind === "None";
|
|
476
|
-
Maybe2.fromNullable = (value) => value === null || value === void 0 ? (0, Maybe2.none)() : (0, Maybe2.some)(value);
|
|
477
|
-
Maybe2.toNullable = (data) => (0, Maybe2.isSome)(data) ? data.value : null;
|
|
478
|
-
Maybe2.toUndefined = (data) => (0, Maybe2.isSome)(data) ? data.value : void 0;
|
|
479
|
-
Maybe2.fromPredicate = (pred) => (a) => pred(a) ? (0, Maybe2.some)(a) : (0, Maybe2.none)();
|
|
480
|
-
Maybe2.toResult = (onNone) => (data) => (0, Maybe2.isSome)(data) ? Result.ok(data.value) : Result.err(onNone());
|
|
481
|
-
Maybe2.fromResult = (data) => Result.isOk(data) ? (0, Maybe2.some)(data.value) : (0, Maybe2.none)();
|
|
482
|
-
Maybe2.map = (f) => (data) => (0, Maybe2.isSome)(data) ? (0, Maybe2.some)(f(data.value)) : data;
|
|
483
|
-
Maybe2.chain = (f) => (data) => (0, Maybe2.isSome)(data) ? f(data.value) : data;
|
|
484
|
-
Maybe2.fold = (onNone, onSome) => (data) => (0, Maybe2.isSome)(data) ? onSome(data.value) : onNone();
|
|
485
|
-
Maybe2.match = (cases) => (data) => (0, Maybe2.isSome)(data) ? cases.some(data.value) : cases.none();
|
|
486
|
-
Maybe2.getOrElse = (defaultValue) => (data) => (0, Maybe2.isSome)(data) ? data.value : defaultValue();
|
|
487
|
-
Maybe2.tap = (f) => (data) => {
|
|
488
|
-
if ((0, Maybe2.isSome)(data)) {
|
|
489
|
-
f(data.value);
|
|
490
|
-
}
|
|
491
|
-
return data;
|
|
492
|
-
};
|
|
493
|
-
Maybe2.filter = (predicate) => (data) => (0, Maybe2.isSome)(data) ? predicate(data.value) ? data : (0, Maybe2.none)() : data;
|
|
494
|
-
Maybe2.recover = (fallback) => (data) => (0, Maybe2.isSome)(data) ? data : fallback();
|
|
495
|
-
Maybe2.ap = (arg) => (data) => (0, Maybe2.isSome)(data) && (0, Maybe2.isSome)(arg) ? (0, Maybe2.some)(data.value(arg.value)) : (0, Maybe2.none)();
|
|
496
|
-
})(Maybe || (Maybe = {}));
|
|
497
|
-
|
|
498
420
|
// src/Core/Combinable.ts
|
|
499
421
|
var Combinable;
|
|
500
422
|
((Combinable2) => {
|
|
@@ -523,14 +445,14 @@ var Deferred;
|
|
|
523
445
|
|
|
524
446
|
// src/Core/Equality.ts
|
|
525
447
|
var Equality;
|
|
526
|
-
((
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
448
|
+
((Equality3) => {
|
|
449
|
+
Equality3.string = (a, b) => a === b;
|
|
450
|
+
Equality3.number = (a, b) => a === b;
|
|
451
|
+
Equality3.boolean = (a, b) => a === b;
|
|
452
|
+
Equality3.date = (a, b) => a.getTime() === b.getTime();
|
|
453
|
+
Equality3.array = (eq) => (a, b) => a.length === b.length && a.every((x, i) => eq(x, b[i]));
|
|
454
|
+
Equality3.by = (f) => (eq) => (a, b) => eq(f(a), f(b));
|
|
455
|
+
Equality3.and = (eq2) => (eq1) => (a, b) => eq1(a, b) && eq2(a, b);
|
|
534
456
|
})(Equality || (Equality = {}));
|
|
535
457
|
|
|
536
458
|
// src/Core/Lazy.ts
|
|
@@ -561,18 +483,18 @@ var Lazy;
|
|
|
561
483
|
|
|
562
484
|
// src/Core/Lens.ts
|
|
563
485
|
var Lens;
|
|
564
|
-
((
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
486
|
+
((Lens3) => {
|
|
487
|
+
Lens3.make = (get2, set2) => ({ get: get2, set: set2 });
|
|
488
|
+
Lens3.prop = () => (key) => (0, Lens3.make)((s) => s[key], (a) => (s) => ({ ...s, [key]: a }));
|
|
489
|
+
Lens3.get = (lens) => (s) => lens.get(s);
|
|
490
|
+
Lens3.set = (lens) => (a) => (s) => lens.set(a)(s);
|
|
491
|
+
Lens3.modify = (lens) => (f) => (s) => lens.set(f(lens.get(s)))(s);
|
|
492
|
+
Lens3.andThen = (inner) => (outer) => (0, Lens3.make)((s) => inner.get(outer.get(s)), (b) => (s) => outer.set(inner.set(b)(outer.get(s)))(s));
|
|
493
|
+
Lens3.andThenOptional = (inner) => (outer) => ({
|
|
572
494
|
get: (s) => inner.get(outer.get(s)),
|
|
573
495
|
set: (b) => (s) => outer.set(inner.set(b)(outer.get(s)))(s)
|
|
574
496
|
});
|
|
575
|
-
|
|
497
|
+
Lens3.toOptional = (lens) => ({
|
|
576
498
|
get: (s) => ({ kind: "Some", value: lens.get(s) }),
|
|
577
499
|
set: lens.set
|
|
578
500
|
});
|
|
@@ -600,8 +522,59 @@ var Logged;
|
|
|
600
522
|
return data;
|
|
601
523
|
};
|
|
602
524
|
Logged2.run = (data) => [data.value, data.log];
|
|
525
|
+
Logged2.bindTo = (key) => (data) => (0, Logged2.map)((a) => ({ [key]: a }))(data);
|
|
526
|
+
Logged2.bind = (key, f) => (data) => (0, Logged2.chain)(
|
|
527
|
+
(a) => (0, Logged2.map)((b) => ({ ...a, [key]: b }))(f(a))
|
|
528
|
+
)(data);
|
|
603
529
|
})(Logged || (Logged = {}));
|
|
604
530
|
|
|
531
|
+
// src/Core/Maybe.ts
|
|
532
|
+
var _none = { kind: "None" };
|
|
533
|
+
var Maybe;
|
|
534
|
+
((Maybe2) => {
|
|
535
|
+
Maybe2.some = (value) => ({ kind: "Some", value });
|
|
536
|
+
Maybe2.isSome = (data) => data.kind === "Some";
|
|
537
|
+
Maybe2.none = () => _none;
|
|
538
|
+
Maybe2.isNone = (data) => data.kind === "None";
|
|
539
|
+
Maybe2.fromNullable = (value) => value === null || value === void 0 ? (0, Maybe2.none)() : (0, Maybe2.some)(value);
|
|
540
|
+
Maybe2.toNullable = (data) => (0, Maybe2.isSome)(data) ? data.value : null;
|
|
541
|
+
Maybe2.toUndefined = (data) => (0, Maybe2.isSome)(data) ? data.value : void 0;
|
|
542
|
+
Maybe2.fromPredicate = (pred) => (a) => pred(a) ? (0, Maybe2.some)(a) : (0, Maybe2.none)();
|
|
543
|
+
Maybe2.toResult = (onNone) => (data) => (0, Maybe2.isSome)(data) ? Result.ok(data.value) : Result.err(onNone());
|
|
544
|
+
Maybe2.fromResult = (data) => Result.isOk(data) ? (0, Maybe2.some)(data.value) : (0, Maybe2.none)();
|
|
545
|
+
Maybe2.map = (f) => (data) => (0, Maybe2.isSome)(data) ? (0, Maybe2.some)(f(data.value)) : data;
|
|
546
|
+
Maybe2.chain = (f) => (data) => (0, Maybe2.isSome)(data) ? f(data.value) : data;
|
|
547
|
+
Maybe2.fold = (onNone, onSome) => (data) => (0, Maybe2.isSome)(data) ? onSome(data.value) : onNone();
|
|
548
|
+
Maybe2.match = (cases) => (data) => (0, Maybe2.isSome)(data) ? cases.some(data.value) : cases.none();
|
|
549
|
+
Maybe2.getOrElse = (defaultValue) => (data) => (0, Maybe2.isSome)(data) ? data.value : defaultValue();
|
|
550
|
+
Maybe2.tap = (f) => (data) => {
|
|
551
|
+
if ((0, Maybe2.isSome)(data)) {
|
|
552
|
+
f(data.value);
|
|
553
|
+
}
|
|
554
|
+
return data;
|
|
555
|
+
};
|
|
556
|
+
Maybe2.filter = (predicate) => (data) => (0, Maybe2.isSome)(data) ? predicate(data.value) ? data : (0, Maybe2.none)() : data;
|
|
557
|
+
Maybe2.recover = (fallback) => (data) => (0, Maybe2.isSome)(data) ? data : fallback();
|
|
558
|
+
Maybe2.ap = (arg) => (data) => (0, Maybe2.isSome)(data) && (0, Maybe2.isSome)(arg) ? (0, Maybe2.some)(data.value(arg.value)) : (0, Maybe2.none)();
|
|
559
|
+
Maybe2.bindTo = (key) => (data) => (0, Maybe2.map)((a) => ({ [key]: a }))(data);
|
|
560
|
+
Maybe2.bind = (key, f) => (data) => (0, Maybe2.chain)(
|
|
561
|
+
(a) => (0, Maybe2.map)((b) => ({ ...a, [key]: b }))(f(a))
|
|
562
|
+
)(data);
|
|
563
|
+
Maybe2.struct = (fields) => {
|
|
564
|
+
const result = {};
|
|
565
|
+
for (const key in fields) {
|
|
566
|
+
if (Object.hasOwn(fields, key)) {
|
|
567
|
+
const res = fields[key];
|
|
568
|
+
if ((0, Maybe2.isNone)(res)) {
|
|
569
|
+
return res;
|
|
570
|
+
}
|
|
571
|
+
result[key] = res.value;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
return (0, Maybe2.some)(result);
|
|
575
|
+
};
|
|
576
|
+
})(Maybe || (Maybe = {}));
|
|
577
|
+
|
|
605
578
|
// src/Types/Brand.ts
|
|
606
579
|
var Brand;
|
|
607
580
|
((Brand2) => {
|
|
@@ -627,6 +600,9 @@ var Duration;
|
|
|
627
600
|
Duration2.subtract = (other) => (self) => wrap(Brand.unwrap(self) - Brand.unwrap(other));
|
|
628
601
|
})(Duration || (Duration = {}));
|
|
629
602
|
|
|
603
|
+
// src/Types/NonEmptyList.ts
|
|
604
|
+
var isNonEmptyList = (list) => list.length > 0;
|
|
605
|
+
|
|
630
606
|
// src/internal/Op.util.ts
|
|
631
607
|
var _abortedNil = { kind: "OpNil", reason: "aborted" };
|
|
632
608
|
var _droppedNil = { kind: "OpNil", reason: "dropped" };
|
|
@@ -1759,16 +1735,16 @@ var Optional;
|
|
|
1759
1735
|
|
|
1760
1736
|
// src/Core/Ordering.ts
|
|
1761
1737
|
var Ordering;
|
|
1762
|
-
((
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1738
|
+
((Ordering3) => {
|
|
1739
|
+
Ordering3.string = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
1740
|
+
Ordering3.number = (a, b) => a - b;
|
|
1741
|
+
Ordering3.date = (a, b) => a.getTime() - b.getTime();
|
|
1742
|
+
Ordering3.reverse = (ord) => (a, b) => ord(b, a);
|
|
1743
|
+
Ordering3.thenBy = (ord2) => (ord1) => (a, b) => {
|
|
1768
1744
|
const r = ord1(a, b);
|
|
1769
1745
|
return r !== 0 ? r : ord2(a, b);
|
|
1770
1746
|
};
|
|
1771
|
-
|
|
1747
|
+
Ordering3.by = (f) => (ord) => (a, b) => ord(f(a), f(b));
|
|
1772
1748
|
})(Ordering || (Ordering = {}));
|
|
1773
1749
|
|
|
1774
1750
|
// src/Core/Predicate.ts
|
|
@@ -1799,6 +1775,10 @@ var Reader;
|
|
|
1799
1775
|
};
|
|
1800
1776
|
Reader2.local = (f) => (data) => (env) => data(f(env));
|
|
1801
1777
|
Reader2.run = (env) => (data) => data(env);
|
|
1778
|
+
Reader2.bindTo = (key) => (data) => (0, Reader2.map)((a) => ({ [key]: a }))(data);
|
|
1779
|
+
Reader2.bind = (key, f) => (data) => (0, Reader2.chain)(
|
|
1780
|
+
(a) => (0, Reader2.map)((b) => ({ ...a, [key]: b }))(f(a))
|
|
1781
|
+
)(data);
|
|
1802
1782
|
})(Reader || (Reader = {}));
|
|
1803
1783
|
|
|
1804
1784
|
// src/Core/Refinement.ts
|
|
@@ -1896,6 +1876,152 @@ var RemoteData;
|
|
|
1896
1876
|
RemoteData2.filter = (pred, onFalse) => (data) => (0, RemoteData2.isSuccess)(data) ? pred(data.value) ? data : (0, RemoteData2.failure)(onFalse(data.value)) : data;
|
|
1897
1877
|
})(RemoteData || (RemoteData = {}));
|
|
1898
1878
|
|
|
1879
|
+
// src/Core/Resource.ts
|
|
1880
|
+
var Resource;
|
|
1881
|
+
((Resource2) => {
|
|
1882
|
+
Resource2.make = (acquire, release) => ({
|
|
1883
|
+
acquire,
|
|
1884
|
+
release
|
|
1885
|
+
});
|
|
1886
|
+
Resource2.fromTask = (acquire, release) => ({
|
|
1887
|
+
acquire: Task.map((a) => Result.ok(a))(acquire),
|
|
1888
|
+
release
|
|
1889
|
+
});
|
|
1890
|
+
Resource2.use = (f) => (resource) => Task.from(
|
|
1891
|
+
(signal) => Deferred.toPromise(resource.acquire(signal)).then(async (acquired) => {
|
|
1892
|
+
if (Result.isErr(acquired)) {
|
|
1893
|
+
return acquired;
|
|
1894
|
+
}
|
|
1895
|
+
const a = acquired.value;
|
|
1896
|
+
try {
|
|
1897
|
+
const usageResult = await Deferred.toPromise(f(a)(signal));
|
|
1898
|
+
return usageResult;
|
|
1899
|
+
} finally {
|
|
1900
|
+
await Deferred.toPromise(resource.release(a)(signal));
|
|
1901
|
+
}
|
|
1902
|
+
})
|
|
1903
|
+
);
|
|
1904
|
+
Resource2.combine = (resourceA, resourceB) => ({
|
|
1905
|
+
acquire: Task.from(
|
|
1906
|
+
(signal) => Deferred.toPromise(resourceA.acquire(signal)).then(async (acquiredA) => {
|
|
1907
|
+
if (Result.isErr(acquiredA)) {
|
|
1908
|
+
return acquiredA;
|
|
1909
|
+
}
|
|
1910
|
+
const a = acquiredA.value;
|
|
1911
|
+
const acquiredB = await Deferred.toPromise(resourceB.acquire(signal));
|
|
1912
|
+
if (Result.isErr(acquiredB)) {
|
|
1913
|
+
await Deferred.toPromise(resourceA.release(a)(signal));
|
|
1914
|
+
return acquiredB;
|
|
1915
|
+
}
|
|
1916
|
+
return Result.ok([a, acquiredB.value]);
|
|
1917
|
+
})
|
|
1918
|
+
),
|
|
1919
|
+
release: ([a, b]) => Task.from(
|
|
1920
|
+
(signal) => Deferred.toPromise(resourceB.release(b)(signal)).then(() => Deferred.toPromise(resourceA.release(a)(signal)))
|
|
1921
|
+
)
|
|
1922
|
+
});
|
|
1923
|
+
})(Resource || (Resource = {}));
|
|
1924
|
+
|
|
1925
|
+
// src/Core/Result.ts
|
|
1926
|
+
var Result;
|
|
1927
|
+
((Result4) => {
|
|
1928
|
+
Result4.ok = (value) => ({ kind: "Ok", value });
|
|
1929
|
+
Result4.err = (e) => ({ kind: "Err", error: e });
|
|
1930
|
+
Result4.isOk = (data) => data.kind === "Ok";
|
|
1931
|
+
Result4.isErr = (data) => data.kind === "Err";
|
|
1932
|
+
Result4.tryCatch = (f, onError) => {
|
|
1933
|
+
try {
|
|
1934
|
+
return (0, Result4.ok)(f());
|
|
1935
|
+
} catch (error) {
|
|
1936
|
+
return (0, Result4.err)(onError(error));
|
|
1937
|
+
}
|
|
1938
|
+
};
|
|
1939
|
+
Result4.map = (f) => (data) => (0, Result4.isOk)(data) ? (0, Result4.ok)(f(data.value)) : data;
|
|
1940
|
+
Result4.mapError = (f) => (data) => (0, Result4.isErr)(data) ? (0, Result4.err)(f(data.error)) : data;
|
|
1941
|
+
Result4.chain = (f) => (data) => (0, Result4.isOk)(data) ? f(data.value) : data;
|
|
1942
|
+
Result4.fold = (onErr, onOk) => (data) => (0, Result4.isOk)(data) ? onOk(data.value) : onErr(data.error);
|
|
1943
|
+
Result4.match = (cases) => (data) => (0, Result4.isOk)(data) ? cases.ok(data.value) : cases.err(data.error);
|
|
1944
|
+
Result4.getOrElse = (defaultValue) => (data) => (0, Result4.isOk)(data) ? data.value : defaultValue();
|
|
1945
|
+
Result4.tap = (f) => (data) => {
|
|
1946
|
+
if ((0, Result4.isOk)(data)) {
|
|
1947
|
+
f(data.value);
|
|
1948
|
+
}
|
|
1949
|
+
return data;
|
|
1950
|
+
};
|
|
1951
|
+
Result4.tapError = (f) => (data) => {
|
|
1952
|
+
if ((0, Result4.isErr)(data)) {
|
|
1953
|
+
f(data.error);
|
|
1954
|
+
}
|
|
1955
|
+
return data;
|
|
1956
|
+
};
|
|
1957
|
+
Result4.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Result4.ok)(a) : (0, Result4.err)(onFalse(a));
|
|
1958
|
+
Result4.fromNullable = (onNull) => (value) => value === null || value === void 0 ? (0, Result4.err)(onNull()) : (0, Result4.ok)(value);
|
|
1959
|
+
Result4.fromMaybe = (onNone) => (maybe) => Maybe.isNone(maybe) ? (0, Result4.err)(onNone()) : (0, Result4.ok)(maybe.value);
|
|
1960
|
+
Result4.fromThrowable = (f, onError) => (...args) => {
|
|
1961
|
+
try {
|
|
1962
|
+
return (0, Result4.ok)(f(...args));
|
|
1963
|
+
} catch (error) {
|
|
1964
|
+
return (0, Result4.err)(onError(error));
|
|
1965
|
+
}
|
|
1966
|
+
};
|
|
1967
|
+
Result4.recover = (fallback) => (data) => (0, Result4.isOk)(data) ? data : fallback(data.error);
|
|
1968
|
+
Result4.recoverUnless = (isBlocked, fallback) => (data) => (0, Result4.isErr)(data) && !isBlocked(data.error) ? fallback() : data;
|
|
1969
|
+
Result4.toMaybe = (data) => (0, Result4.isOk)(data) ? Maybe.some(data.value) : Maybe.none();
|
|
1970
|
+
Result4.ap = (arg) => (data) => (0, Result4.isOk)(data) && (0, Result4.isOk)(arg) ? (0, Result4.ok)(data.value(arg.value)) : (0, Result4.isErr)(data) ? data : arg;
|
|
1971
|
+
Result4.bindTo = (key) => (data) => (0, Result4.map)((a) => ({ [key]: a }))(data);
|
|
1972
|
+
Result4.bind = (key, f) => (data) => (0, Result4.chain)(
|
|
1973
|
+
(a) => (0, Result4.map)((b) => ({ ...a, [key]: b }))(f(a))
|
|
1974
|
+
)(data);
|
|
1975
|
+
Result4.struct = (fields) => {
|
|
1976
|
+
const result = {};
|
|
1977
|
+
for (const key in fields) {
|
|
1978
|
+
if (Object.hasOwn(fields, key)) {
|
|
1979
|
+
const res = fields[key];
|
|
1980
|
+
if ((0, Result4.isErr)(res)) {
|
|
1981
|
+
return res;
|
|
1982
|
+
}
|
|
1983
|
+
result[key] = res.value;
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
return (0, Result4.ok)(result);
|
|
1987
|
+
};
|
|
1988
|
+
})(Result || (Result = {}));
|
|
1989
|
+
|
|
1990
|
+
// src/Core/State.ts
|
|
1991
|
+
var State;
|
|
1992
|
+
((State2) => {
|
|
1993
|
+
State2.resolve = (value) => (s) => [value, s];
|
|
1994
|
+
State2.get = () => (s) => [s, s];
|
|
1995
|
+
State2.gets = (f) => (s) => [f(s), s];
|
|
1996
|
+
State2.put = (newState) => (_s) => [void 0, newState];
|
|
1997
|
+
State2.modify = (f) => (s) => [void 0, f(s)];
|
|
1998
|
+
State2.map = (f) => (st) => (s) => {
|
|
1999
|
+
const [a, s1] = st(s);
|
|
2000
|
+
return [f(a), s1];
|
|
2001
|
+
};
|
|
2002
|
+
State2.chain = (f) => (st) => (s) => {
|
|
2003
|
+
const [a, s1] = st(s);
|
|
2004
|
+
return f(a)(s1);
|
|
2005
|
+
};
|
|
2006
|
+
State2.ap = (arg) => (fn) => (s) => {
|
|
2007
|
+
const [f, s1] = fn(s);
|
|
2008
|
+
const [a, s2] = arg(s1);
|
|
2009
|
+
return [f(a), s2];
|
|
2010
|
+
};
|
|
2011
|
+
State2.tap = (f) => (st) => (s) => {
|
|
2012
|
+
const [a, s1] = st(s);
|
|
2013
|
+
f(a);
|
|
2014
|
+
return [a, s1];
|
|
2015
|
+
};
|
|
2016
|
+
State2.run = (initialState) => (st) => st(initialState);
|
|
2017
|
+
State2.evaluate = (initialState) => (st) => st(initialState)[0];
|
|
2018
|
+
State2.execute = (initialState) => (st) => st(initialState)[1];
|
|
2019
|
+
State2.bindTo = (key) => (data) => (0, State2.map)((a) => ({ [key]: a }))(data);
|
|
2020
|
+
State2.bind = (key, f) => (data) => (0, State2.chain)(
|
|
2021
|
+
(a) => (0, State2.map)((b) => ({ ...a, [key]: b }))(f(a))
|
|
2022
|
+
)(data);
|
|
2023
|
+
})(State || (State = {}));
|
|
2024
|
+
|
|
1899
2025
|
// src/Core/Task.ts
|
|
1900
2026
|
var toPromise = (task, signal) => Deferred.toPromise(task(signal));
|
|
1901
2027
|
var getMs2 = (duration) => Duration.toMilliseconds(duration);
|
|
@@ -2118,85 +2244,12 @@ var Task;
|
|
|
2118
2244
|
return { task, abort };
|
|
2119
2245
|
};
|
|
2120
2246
|
Task2.run = (signal) => (task) => Deferred.toPromise(task(signal));
|
|
2247
|
+
Task2.bindTo = (key) => (data) => (0, Task2.map)((a) => ({ [key]: a }))(data);
|
|
2248
|
+
Task2.bind = (key, f) => (data) => (0, Task2.chain)(
|
|
2249
|
+
(a) => (0, Task2.map)((b) => ({ ...a, [key]: b }))(f(a))
|
|
2250
|
+
)(data);
|
|
2121
2251
|
})(Task || (Task = {}));
|
|
2122
2252
|
|
|
2123
|
-
// src/Core/Resource.ts
|
|
2124
|
-
var Resource;
|
|
2125
|
-
((Resource2) => {
|
|
2126
|
-
Resource2.make = (acquire, release) => ({
|
|
2127
|
-
acquire,
|
|
2128
|
-
release
|
|
2129
|
-
});
|
|
2130
|
-
Resource2.fromTask = (acquire, release) => ({
|
|
2131
|
-
acquire: Task.map((a) => Result.ok(a))(acquire),
|
|
2132
|
-
release
|
|
2133
|
-
});
|
|
2134
|
-
Resource2.use = (f) => (resource) => Task.from(
|
|
2135
|
-
(signal) => Deferred.toPromise(resource.acquire(signal)).then(async (acquired) => {
|
|
2136
|
-
if (Result.isErr(acquired)) {
|
|
2137
|
-
return acquired;
|
|
2138
|
-
}
|
|
2139
|
-
const a = acquired.value;
|
|
2140
|
-
try {
|
|
2141
|
-
const usageResult = await Deferred.toPromise(f(a)(signal));
|
|
2142
|
-
return usageResult;
|
|
2143
|
-
} finally {
|
|
2144
|
-
await Deferred.toPromise(resource.release(a)(signal));
|
|
2145
|
-
}
|
|
2146
|
-
})
|
|
2147
|
-
);
|
|
2148
|
-
Resource2.combine = (resourceA, resourceB) => ({
|
|
2149
|
-
acquire: Task.from(
|
|
2150
|
-
(signal) => Deferred.toPromise(resourceA.acquire(signal)).then(async (acquiredA) => {
|
|
2151
|
-
if (Result.isErr(acquiredA)) {
|
|
2152
|
-
return acquiredA;
|
|
2153
|
-
}
|
|
2154
|
-
const a = acquiredA.value;
|
|
2155
|
-
const acquiredB = await Deferred.toPromise(resourceB.acquire(signal));
|
|
2156
|
-
if (Result.isErr(acquiredB)) {
|
|
2157
|
-
await Deferred.toPromise(resourceA.release(a)(signal));
|
|
2158
|
-
return acquiredB;
|
|
2159
|
-
}
|
|
2160
|
-
return Result.ok([a, acquiredB.value]);
|
|
2161
|
-
})
|
|
2162
|
-
),
|
|
2163
|
-
release: ([a, b]) => Task.from(
|
|
2164
|
-
(signal) => Deferred.toPromise(resourceB.release(b)(signal)).then(() => Deferred.toPromise(resourceA.release(a)(signal)))
|
|
2165
|
-
)
|
|
2166
|
-
});
|
|
2167
|
-
})(Resource || (Resource = {}));
|
|
2168
|
-
|
|
2169
|
-
// src/Core/State.ts
|
|
2170
|
-
var State;
|
|
2171
|
-
((State2) => {
|
|
2172
|
-
State2.resolve = (value) => (s) => [value, s];
|
|
2173
|
-
State2.get = () => (s) => [s, s];
|
|
2174
|
-
State2.gets = (f) => (s) => [f(s), s];
|
|
2175
|
-
State2.put = (newState) => (_s) => [void 0, newState];
|
|
2176
|
-
State2.modify = (f) => (s) => [void 0, f(s)];
|
|
2177
|
-
State2.map = (f) => (st) => (s) => {
|
|
2178
|
-
const [a, s1] = st(s);
|
|
2179
|
-
return [f(a), s1];
|
|
2180
|
-
};
|
|
2181
|
-
State2.chain = (f) => (st) => (s) => {
|
|
2182
|
-
const [a, s1] = st(s);
|
|
2183
|
-
return f(a)(s1);
|
|
2184
|
-
};
|
|
2185
|
-
State2.ap = (arg) => (fn) => (s) => {
|
|
2186
|
-
const [f, s1] = fn(s);
|
|
2187
|
-
const [a, s2] = arg(s1);
|
|
2188
|
-
return [f(a), s2];
|
|
2189
|
-
};
|
|
2190
|
-
State2.tap = (f) => (st) => (s) => {
|
|
2191
|
-
const [a, s1] = st(s);
|
|
2192
|
-
f(a);
|
|
2193
|
-
return [a, s1];
|
|
2194
|
-
};
|
|
2195
|
-
State2.run = (initialState) => (st) => st(initialState);
|
|
2196
|
-
State2.evaluate = (initialState) => (st) => st(initialState)[0];
|
|
2197
|
-
State2.execute = (initialState) => (st) => st(initialState)[1];
|
|
2198
|
-
})(State || (State = {}));
|
|
2199
|
-
|
|
2200
2253
|
// src/Core/TaskMaybe.ts
|
|
2201
2254
|
var TaskMaybe;
|
|
2202
2255
|
((TaskMaybe2) => {
|
|
@@ -2220,99 +2273,63 @@ var TaskMaybe;
|
|
|
2220
2273
|
TaskMaybe2.tap = (f) => (data) => Task.map(Maybe.tap(f))(data);
|
|
2221
2274
|
TaskMaybe2.filter = (predicate) => (data) => Task.map(Maybe.filter(predicate))(data);
|
|
2222
2275
|
TaskMaybe2.toTaskResult = (onNone) => (data) => Task.map(Maybe.toResult(onNone))(data);
|
|
2276
|
+
TaskMaybe2.bindTo = (key) => (data) => (0, TaskMaybe2.map)((a) => ({ [key]: a }))(data);
|
|
2277
|
+
TaskMaybe2.bind = (key, f) => (data) => (0, TaskMaybe2.chain)(
|
|
2278
|
+
(a) => (0, TaskMaybe2.map)((b) => ({ ...a, [key]: b }))(f(a))
|
|
2279
|
+
)(data);
|
|
2223
2280
|
})(TaskMaybe || (TaskMaybe = {}));
|
|
2224
2281
|
|
|
2225
2282
|
// src/Core/TaskResult.ts
|
|
2226
|
-
var
|
|
2227
|
-
((
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2283
|
+
var TaskResult3;
|
|
2284
|
+
((TaskResult4) => {
|
|
2285
|
+
TaskResult4.ok = (value) => Task.resolve(Result.ok(value));
|
|
2286
|
+
TaskResult4.err = (error) => Task.resolve(Result.err(error));
|
|
2287
|
+
TaskResult4.fromNullable = (onNull) => (value) => Task.resolve(value === null || value === void 0 ? Result.err(onNull()) : Result.ok(value));
|
|
2288
|
+
TaskResult4.fromMaybe = (onNone) => (maybe) => Task.resolve(Maybe.isNone(maybe) ? Result.err(onNone()) : Result.ok(maybe.value));
|
|
2289
|
+
TaskResult4.fromResult = (result) => Task.resolve(result);
|
|
2290
|
+
TaskResult4.fromThrowable = (f, onError) => (...args) => Task.from(() => f(...args).then(Result.ok).catch((error) => Result.err(onError(error))));
|
|
2291
|
+
TaskResult4.tryCatch = (f, onError) => Task.from((signal) => f(signal).then(Result.ok).catch((error) => Result.err(onError(error))));
|
|
2292
|
+
TaskResult4.map = (f) => (data) => Task.map(Result.map(f))(data);
|
|
2293
|
+
TaskResult4.mapError = (f) => (data) => Task.map(Result.mapError(f))(data);
|
|
2294
|
+
TaskResult4.chain = (f) => (data) => Task.chain((result) => Result.isOk(result) ? f(result.value) : Task.resolve(Result.err(result.error)))(
|
|
2238
2295
|
data
|
|
2239
2296
|
);
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2297
|
+
TaskResult4.fold = (onErr, onOk) => (data) => Task.map(Result.fold(onErr, onOk))(data);
|
|
2298
|
+
TaskResult4.match = (cases) => (data) => Task.map(Result.match(cases))(data);
|
|
2299
|
+
TaskResult4.recover = (fallback) => (data) => Task.chain(
|
|
2243
2300
|
(result) => Result.isErr(result) ? fallback(result.error) : Task.resolve(result)
|
|
2244
2301
|
)(data);
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2302
|
+
TaskResult4.getOrElse = (defaultValue) => (data) => Task.map(Result.getOrElse(defaultValue))(data);
|
|
2303
|
+
TaskResult4.tap = (f) => (data) => Task.map(Result.tap(f))(data);
|
|
2304
|
+
TaskResult4.tapError = (f) => (data) => Task.map(Result.tapError(f))(data);
|
|
2305
|
+
TaskResult4.ap = (arg) => (data) => Task.from(
|
|
2249
2306
|
(signal) => Promise.all([Deferred.toPromise(data(signal)), Deferred.toPromise(arg(signal))]).then(
|
|
2250
2307
|
([of_, oa]) => Result.ap(oa)(of_)
|
|
2251
2308
|
)
|
|
2252
2309
|
);
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
((
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
return (0, Validation2.passed)(data.value(arg.value));
|
|
2272
|
-
}
|
|
2273
|
-
const errors = [...(0, Validation2.isFailed)(data) ? data.errors : [], ...(0, Validation2.isFailed)(arg) ? arg.errors : []];
|
|
2274
|
-
return (0, Validation2.failedAll)(errors);
|
|
2275
|
-
};
|
|
2276
|
-
Validation2.fold = (onFailed, onPassed) => (data) => (0, Validation2.isPassed)(data) ? onPassed(data.value) : onFailed(data.errors);
|
|
2277
|
-
Validation2.match = (cases) => (data) => (0, Validation2.isPassed)(data) ? cases.passed(data.value) : cases.failed(data.errors);
|
|
2278
|
-
Validation2.getOrElse = (defaultValue) => (data) => (0, Validation2.isPassed)(data) ? data.value : defaultValue();
|
|
2279
|
-
Validation2.tap = (f) => (data) => {
|
|
2280
|
-
if ((0, Validation2.isPassed)(data)) {
|
|
2281
|
-
f(data.value);
|
|
2282
|
-
}
|
|
2283
|
-
return data;
|
|
2284
|
-
};
|
|
2285
|
-
Validation2.tapError = (f) => (data) => {
|
|
2286
|
-
if ((0, Validation2.isFailed)(data)) {
|
|
2287
|
-
f(data.errors);
|
|
2288
|
-
}
|
|
2289
|
-
return data;
|
|
2290
|
-
};
|
|
2291
|
-
Validation2.recover = (fallback) => (data) => (0, Validation2.isPassed)(data) ? data : fallback(data.errors);
|
|
2292
|
-
Validation2.recoverUnless = (isBlocked, fallback) => (data) => (0, Validation2.isFailed)(data) && !data.errors.some(isBlocked) ? fallback() : data;
|
|
2293
|
-
Validation2.toResult = (data) => (0, Validation2.isPassed)(data) ? Result.ok(data.value) : Result.err(data.errors);
|
|
2294
|
-
Validation2.toMaybe = (data) => (0, Validation2.isPassed)(data) ? Maybe.some(data.value) : Maybe.none();
|
|
2295
|
-
Validation2.fromResult = (data) => data.kind === "Ok" ? (0, Validation2.passed)(data.value) : (0, Validation2.failed)(data.error);
|
|
2296
|
-
Validation2.product = (first, second) => {
|
|
2297
|
-
if ((0, Validation2.isPassed)(first) && (0, Validation2.isPassed)(second)) {
|
|
2298
|
-
return (0, Validation2.passed)([first.value, second.value]);
|
|
2299
|
-
}
|
|
2300
|
-
const errors = [...(0, Validation2.isFailed)(first) ? first.errors : [], ...(0, Validation2.isFailed)(second) ? second.errors : []];
|
|
2301
|
-
return (0, Validation2.failedAll)(errors);
|
|
2302
|
-
};
|
|
2303
|
-
Validation2.productAll = (data) => {
|
|
2304
|
-
const values = [];
|
|
2305
|
-
const errors = [];
|
|
2306
|
-
for (const v of data) {
|
|
2307
|
-
if ((0, Validation2.isPassed)(v)) {
|
|
2308
|
-
values.push(v.value);
|
|
2309
|
-
} else {
|
|
2310
|
-
errors.push(...v.errors);
|
|
2310
|
+
TaskResult4.run = (signal) => (task) => Deferred.toPromise(task(signal));
|
|
2311
|
+
TaskResult4.bindTo = (key) => (data) => (0, TaskResult4.map)((a) => ({ [key]: a }))(data);
|
|
2312
|
+
TaskResult4.bind = (key, f) => (data) => (0, TaskResult4.chain)(
|
|
2313
|
+
(a) => (0, TaskResult4.map)((b) => ({ ...a, [key]: b }))(f(a))
|
|
2314
|
+
)(data);
|
|
2315
|
+
TaskResult4.struct = (fields) => Task.from((signal) => {
|
|
2316
|
+
const keys = Object.keys(fields);
|
|
2317
|
+
const promises = keys.map((key) => Deferred.toPromise(fields[key](signal)).then((res) => ({ key, res })));
|
|
2318
|
+
return Promise.all(promises).then((results) => {
|
|
2319
|
+
const record = {};
|
|
2320
|
+
for (const key of keys) {
|
|
2321
|
+
const found = results.find((r) => r.key === key);
|
|
2322
|
+
if (found) {
|
|
2323
|
+
if (Result.isErr(found.res)) {
|
|
2324
|
+
return found.res;
|
|
2325
|
+
}
|
|
2326
|
+
record[key] = found.res.value;
|
|
2327
|
+
}
|
|
2311
2328
|
}
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
};
|
|
2315
|
-
})(
|
|
2329
|
+
return Result.ok(record);
|
|
2330
|
+
});
|
|
2331
|
+
});
|
|
2332
|
+
})(TaskResult3 || (TaskResult3 = {}));
|
|
2316
2333
|
|
|
2317
2334
|
// src/Core/TaskValidation.ts
|
|
2318
2335
|
var TaskValidation;
|
|
@@ -2458,8 +2475,81 @@ var Tuple;
|
|
|
2458
2475
|
};
|
|
2459
2476
|
})(Tuple || (Tuple = {}));
|
|
2460
2477
|
|
|
2461
|
-
// src/
|
|
2462
|
-
var
|
|
2478
|
+
// src/Core/Validation.ts
|
|
2479
|
+
var Validation;
|
|
2480
|
+
((Validation2) => {
|
|
2481
|
+
Validation2.passed = (value) => ({ kind: "Passed", value });
|
|
2482
|
+
Validation2.failed = (error) => ({ kind: "Failed", errors: [error] });
|
|
2483
|
+
Validation2.failedAll = (errors) => ({ kind: "Failed", errors });
|
|
2484
|
+
Validation2.isPassed = (data) => data.kind === "Passed";
|
|
2485
|
+
Validation2.isFailed = (data) => data.kind === "Failed";
|
|
2486
|
+
Validation2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Validation2.passed)(a) : (0, Validation2.failed)(onFalse(a));
|
|
2487
|
+
Validation2.fromNullable = (onNull) => (value) => value === null || value === void 0 ? (0, Validation2.failed)(onNull()) : (0, Validation2.passed)(value);
|
|
2488
|
+
Validation2.fromMaybe = (onNone) => (maybe) => Maybe.isNone(maybe) ? (0, Validation2.failed)(onNone()) : (0, Validation2.passed)(maybe.value);
|
|
2489
|
+
Validation2.map = (f) => (data) => (0, Validation2.isPassed)(data) ? (0, Validation2.passed)(f(data.value)) : data;
|
|
2490
|
+
Validation2.mapError = (f) => (data) => (0, Validation2.isFailed)(data) ? (0, Validation2.failedAll)(data.errors.map(f)) : data;
|
|
2491
|
+
Validation2.ap = (arg) => (data) => {
|
|
2492
|
+
if ((0, Validation2.isPassed)(data) && (0, Validation2.isPassed)(arg)) {
|
|
2493
|
+
return (0, Validation2.passed)(data.value(arg.value));
|
|
2494
|
+
}
|
|
2495
|
+
const errors = [...(0, Validation2.isFailed)(data) ? data.errors : [], ...(0, Validation2.isFailed)(arg) ? arg.errors : []];
|
|
2496
|
+
return (0, Validation2.failedAll)(errors);
|
|
2497
|
+
};
|
|
2498
|
+
Validation2.fold = (onFailed, onPassed) => (data) => (0, Validation2.isPassed)(data) ? onPassed(data.value) : onFailed(data.errors);
|
|
2499
|
+
Validation2.match = (cases) => (data) => (0, Validation2.isPassed)(data) ? cases.passed(data.value) : cases.failed(data.errors);
|
|
2500
|
+
Validation2.getOrElse = (defaultValue) => (data) => (0, Validation2.isPassed)(data) ? data.value : defaultValue();
|
|
2501
|
+
Validation2.tap = (f) => (data) => {
|
|
2502
|
+
if ((0, Validation2.isPassed)(data)) {
|
|
2503
|
+
f(data.value);
|
|
2504
|
+
}
|
|
2505
|
+
return data;
|
|
2506
|
+
};
|
|
2507
|
+
Validation2.tapError = (f) => (data) => {
|
|
2508
|
+
if ((0, Validation2.isFailed)(data)) {
|
|
2509
|
+
f(data.errors);
|
|
2510
|
+
}
|
|
2511
|
+
return data;
|
|
2512
|
+
};
|
|
2513
|
+
Validation2.recover = (fallback) => (data) => (0, Validation2.isPassed)(data) ? data : fallback(data.errors);
|
|
2514
|
+
Validation2.recoverUnless = (isBlocked, fallback) => (data) => (0, Validation2.isFailed)(data) && !data.errors.some(isBlocked) ? fallback() : data;
|
|
2515
|
+
Validation2.toResult = (data) => (0, Validation2.isPassed)(data) ? Result.ok(data.value) : Result.err(data.errors);
|
|
2516
|
+
Validation2.toMaybe = (data) => (0, Validation2.isPassed)(data) ? Maybe.some(data.value) : Maybe.none();
|
|
2517
|
+
Validation2.fromResult = (data) => data.kind === "Ok" ? (0, Validation2.passed)(data.value) : (0, Validation2.failed)(data.error);
|
|
2518
|
+
Validation2.product = (first, second) => {
|
|
2519
|
+
if ((0, Validation2.isPassed)(first) && (0, Validation2.isPassed)(second)) {
|
|
2520
|
+
return (0, Validation2.passed)([first.value, second.value]);
|
|
2521
|
+
}
|
|
2522
|
+
const errors = [...(0, Validation2.isFailed)(first) ? first.errors : [], ...(0, Validation2.isFailed)(second) ? second.errors : []];
|
|
2523
|
+
return (0, Validation2.failedAll)(errors);
|
|
2524
|
+
};
|
|
2525
|
+
Validation2.productAll = (data) => {
|
|
2526
|
+
const values = [];
|
|
2527
|
+
const errors = [];
|
|
2528
|
+
for (const v of data) {
|
|
2529
|
+
if ((0, Validation2.isPassed)(v)) {
|
|
2530
|
+
values.push(v.value);
|
|
2531
|
+
} else {
|
|
2532
|
+
errors.push(...v.errors);
|
|
2533
|
+
}
|
|
2534
|
+
}
|
|
2535
|
+
return errors.length > 0 ? (0, Validation2.failedAll)(errors) : (0, Validation2.passed)(values);
|
|
2536
|
+
};
|
|
2537
|
+
Validation2.struct = (fields) => {
|
|
2538
|
+
const record = {};
|
|
2539
|
+
const errors = [];
|
|
2540
|
+
for (const key in fields) {
|
|
2541
|
+
if (Object.hasOwn(fields, key)) {
|
|
2542
|
+
const val = fields[key];
|
|
2543
|
+
if ((0, Validation2.isPassed)(val)) {
|
|
2544
|
+
record[key] = val.value;
|
|
2545
|
+
} else {
|
|
2546
|
+
errors.push(...val.errors);
|
|
2547
|
+
}
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
return errors.length > 0 ? (0, Validation2.failedAll)(errors) : (0, Validation2.passed)(record);
|
|
2551
|
+
};
|
|
2552
|
+
})(Validation || (Validation = {}));
|
|
2463
2553
|
|
|
2464
2554
|
// src/Utils/Arr.ts
|
|
2465
2555
|
var Arr;
|