@nlozgachev/pipelined 0.27.0 → 0.29.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/README.md +157 -35
- package/dist/{Task-vQb3-puQ.d.mts → Task-BDcKwFAj.d.mts} +52 -30
- package/dist/{Task-C8Pgm7EX.d.ts → Task-CnF22Q2o.d.ts} +52 -30
- package/dist/{chunk-SBTMTAZF.mjs → chunk-FWYOEWJ2.mjs} +12 -4
- package/dist/{chunk-YYVONF5X.mjs → chunk-PV7JOUKL.mjs} +127 -39
- package/dist/{chunk-HHCRWQYN.mjs → chunk-SDGDJ7CU.mjs} +25 -20
- package/dist/core.d.mts +305 -72
- package/dist/core.d.ts +305 -72
- package/dist/core.js +151 -58
- package/dist/core.mjs +2 -2
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +162 -61
- package/dist/index.mjs +3 -3
- package/dist/utils.d.mts +28 -10
- package/dist/utils.d.ts +28 -10
- package/dist/utils.js +36 -23
- package/dist/utils.mjs +2 -2
- package/package.json +3 -3
package/dist/core.js
CHANGED
|
@@ -106,18 +106,18 @@ var Logged;
|
|
|
106
106
|
var Result;
|
|
107
107
|
((Result2) => {
|
|
108
108
|
Result2.ok = (value) => ({ kind: "Ok", value });
|
|
109
|
-
Result2.
|
|
109
|
+
Result2.error = (e) => ({ kind: "Error", error: e });
|
|
110
110
|
Result2.isOk = (data) => data.kind === "Ok";
|
|
111
|
-
Result2.
|
|
111
|
+
Result2.isError = (data) => data.kind === "Error";
|
|
112
112
|
Result2.tryCatch = (f, onError) => {
|
|
113
113
|
try {
|
|
114
114
|
return (0, Result2.ok)(f());
|
|
115
115
|
} catch (e) {
|
|
116
|
-
return (0, Result2.
|
|
116
|
+
return (0, Result2.error)(onError(e));
|
|
117
117
|
}
|
|
118
118
|
};
|
|
119
119
|
Result2.map = (f) => (data) => (0, Result2.isOk)(data) ? (0, Result2.ok)(f(data.value)) : data;
|
|
120
|
-
Result2.mapError = (f) => (data) => (0, Result2.
|
|
120
|
+
Result2.mapError = (f) => (data) => (0, Result2.isError)(data) ? (0, Result2.error)(f(data.error)) : data;
|
|
121
121
|
Result2.chain = (f) => (data) => (0, Result2.isOk)(data) ? f(data.value) : data;
|
|
122
122
|
Result2.fold = (onErr, onOk) => (data) => (0, Result2.isOk)(data) ? onOk(data.value) : onErr(data.error);
|
|
123
123
|
Result2.match = (cases) => (data) => (0, Result2.isOk)(data) ? cases.ok(data.value) : cases.err(data.error);
|
|
@@ -127,14 +127,14 @@ var Result;
|
|
|
127
127
|
return data;
|
|
128
128
|
};
|
|
129
129
|
Result2.tapError = (f) => (data) => {
|
|
130
|
-
if ((0, Result2.
|
|
130
|
+
if ((0, Result2.isError)(data)) f(data.error);
|
|
131
131
|
return data;
|
|
132
132
|
};
|
|
133
|
-
Result2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Result2.ok)(a) : (0, Result2.
|
|
133
|
+
Result2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Result2.ok)(a) : (0, Result2.error)(onFalse(a));
|
|
134
134
|
Result2.recover = (fallback) => (data) => (0, Result2.isOk)(data) ? data : fallback(data.error);
|
|
135
|
-
Result2.recoverUnless = (
|
|
135
|
+
Result2.recoverUnless = (isBlocked, fallback) => (data) => (0, Result2.isError)(data) && !isBlocked(data.error) ? fallback() : data;
|
|
136
136
|
Result2.toMaybe = (data) => (0, Result2.isOk)(data) ? Maybe.some(data.value) : Maybe.none();
|
|
137
|
-
Result2.ap = (arg) => (data) => (0, Result2.isOk)(data) && (0, Result2.isOk)(arg) ? (0, Result2.ok)(data.value(arg.value)) : (0, Result2.
|
|
137
|
+
Result2.ap = (arg) => (data) => (0, Result2.isOk)(data) && (0, Result2.isOk)(arg) ? (0, Result2.ok)(data.value(arg.value)) : (0, Result2.isError)(data) ? data : arg;
|
|
138
138
|
})(Result || (Result = {}));
|
|
139
139
|
|
|
140
140
|
// src/Core/Maybe.ts
|
|
@@ -148,9 +148,8 @@ var Maybe;
|
|
|
148
148
|
Maybe2.fromNullable = (value) => value === null || value === void 0 ? (0, Maybe2.none)() : (0, Maybe2.some)(value);
|
|
149
149
|
Maybe2.toNullable = (data) => (0, Maybe2.isSome)(data) ? data.value : null;
|
|
150
150
|
Maybe2.toUndefined = (data) => (0, Maybe2.isSome)(data) ? data.value : void 0;
|
|
151
|
-
Maybe2.fromUndefined = (value) => value === void 0 ? (0, Maybe2.none)() : (0, Maybe2.some)(value);
|
|
152
151
|
Maybe2.fromPredicate = (pred) => (a) => pred(a) ? (0, Maybe2.some)(a) : (0, Maybe2.none)();
|
|
153
|
-
Maybe2.toResult = (onNone) => (data) => (0, Maybe2.isSome)(data) ? Result.ok(data.value) : Result.
|
|
152
|
+
Maybe2.toResult = (onNone) => (data) => (0, Maybe2.isSome)(data) ? Result.ok(data.value) : Result.error(onNone());
|
|
154
153
|
Maybe2.fromResult = (data) => Result.isOk(data) ? (0, Maybe2.some)(data.value) : (0, Maybe2.none)();
|
|
155
154
|
Maybe2.map = (f) => (data) => (0, Maybe2.isSome)(data) ? (0, Maybe2.some)(f(data.value)) : data;
|
|
156
155
|
Maybe2.chain = (f) => (data) => (0, Maybe2.isSome)(data) ? f(data.value) : data;
|
|
@@ -167,14 +166,14 @@ var Maybe;
|
|
|
167
166
|
})(Maybe || (Maybe = {}));
|
|
168
167
|
|
|
169
168
|
// src/internal/Op.util.ts
|
|
170
|
-
var _abortedNil = { kind: "
|
|
171
|
-
var _droppedNil = { kind: "
|
|
172
|
-
var _replacedNil = { kind: "
|
|
173
|
-
var _evictedNil = { kind: "
|
|
169
|
+
var _abortedNil = { kind: "OpNil", reason: "aborted" };
|
|
170
|
+
var _droppedNil = { kind: "OpNil", reason: "dropped" };
|
|
171
|
+
var _replacedNil = { kind: "OpNil", reason: "replaced" };
|
|
172
|
+
var _evictedNil = { kind: "OpNil", reason: "evicted" };
|
|
174
173
|
var _idle = { kind: "Idle" };
|
|
175
174
|
var _pending = { kind: "Pending" };
|
|
176
|
-
var ok = (value) => ({ kind: "
|
|
177
|
-
var err = (error) => ({ kind: "
|
|
175
|
+
var ok = (value) => ({ kind: "OpOk", value });
|
|
176
|
+
var err = (error) => ({ kind: "OpError", error });
|
|
178
177
|
var cancellableWait = (ms, signal) => {
|
|
179
178
|
if (ms <= 0) return Promise.resolve();
|
|
180
179
|
return new Promise((resolve) => {
|
|
@@ -297,6 +296,12 @@ var makeRestartable = (op, minInterval, retryOptions, timeoutOptions) => {
|
|
|
297
296
|
subscribers.add(cb);
|
|
298
297
|
if (currentState.kind !== "Idle") cb(currentState);
|
|
299
298
|
return () => subscribers.delete(cb);
|
|
299
|
+
},
|
|
300
|
+
reset: () => emit(_idle),
|
|
301
|
+
poll: (input, { interval }) => {
|
|
302
|
+
void run(input);
|
|
303
|
+
const id = setInterval(() => void run(input), interval);
|
|
304
|
+
return () => clearInterval(id);
|
|
300
305
|
}
|
|
301
306
|
};
|
|
302
307
|
};
|
|
@@ -361,6 +366,12 @@ var makeExclusive = (op, cooldown, retryOptions, timeoutOptions) => {
|
|
|
361
366
|
subscribers.add(cb);
|
|
362
367
|
if (currentState.kind !== "Idle") cb(currentState);
|
|
363
368
|
return () => subscribers.delete(cb);
|
|
369
|
+
},
|
|
370
|
+
reset: () => emit(_idle),
|
|
371
|
+
poll: (input, { interval }) => {
|
|
372
|
+
void run(input);
|
|
373
|
+
const id = setInterval(() => void run(input), interval);
|
|
374
|
+
return () => clearInterval(id);
|
|
364
375
|
}
|
|
365
376
|
};
|
|
366
377
|
};
|
|
@@ -460,6 +471,12 @@ var makeQueue = (op, maxSize, overflow, concurrency, dedupe, retryOptions, timeo
|
|
|
460
471
|
subscribers.add(cb);
|
|
461
472
|
if (currentState.kind !== "Idle") cb(currentState);
|
|
462
473
|
return () => subscribers.delete(cb);
|
|
474
|
+
},
|
|
475
|
+
reset: () => emit(_idle),
|
|
476
|
+
poll: (input, { interval }) => {
|
|
477
|
+
void run(input);
|
|
478
|
+
const id = setInterval(() => void run(input), interval);
|
|
479
|
+
return () => clearInterval(id);
|
|
463
480
|
}
|
|
464
481
|
};
|
|
465
482
|
};
|
|
@@ -530,6 +547,12 @@ var makeBuffered = (op, size, retryOptions, timeoutOptions) => {
|
|
|
530
547
|
subscribers.add(cb);
|
|
531
548
|
if (currentState.kind !== "Idle") cb(currentState);
|
|
532
549
|
return () => subscribers.delete(cb);
|
|
550
|
+
},
|
|
551
|
+
reset: () => emit(_idle),
|
|
552
|
+
poll: (input, { interval }) => {
|
|
553
|
+
void run(input);
|
|
554
|
+
const id = setInterval(() => void run(input), interval);
|
|
555
|
+
return () => clearInterval(id);
|
|
533
556
|
}
|
|
534
557
|
};
|
|
535
558
|
};
|
|
@@ -652,6 +675,12 @@ var makeDebounced = (op, ms, leading, maxWait, retryOptions, timeoutOptions) =>
|
|
|
652
675
|
subscribers.add(cb);
|
|
653
676
|
if (currentState.kind !== "Idle") cb(currentState);
|
|
654
677
|
return () => subscribers.delete(cb);
|
|
678
|
+
},
|
|
679
|
+
reset: () => emit(_idle),
|
|
680
|
+
poll: (input, { interval }) => {
|
|
681
|
+
void run(input);
|
|
682
|
+
const id = setInterval(() => void run(input), interval);
|
|
683
|
+
return () => clearInterval(id);
|
|
655
684
|
}
|
|
656
685
|
};
|
|
657
686
|
};
|
|
@@ -744,6 +773,12 @@ var makeThrottled = (op, ms, trailing, retryOptions, timeoutOptions) => {
|
|
|
744
773
|
subscribers.add(cb);
|
|
745
774
|
if (currentState.kind !== "Idle") cb(currentState);
|
|
746
775
|
return () => subscribers.delete(cb);
|
|
776
|
+
},
|
|
777
|
+
reset: () => emit(_idle),
|
|
778
|
+
poll: (input, { interval }) => {
|
|
779
|
+
void run(input);
|
|
780
|
+
const id = setInterval(() => void run(input), interval);
|
|
781
|
+
return () => clearInterval(id);
|
|
747
782
|
}
|
|
748
783
|
};
|
|
749
784
|
};
|
|
@@ -825,6 +860,12 @@ var makeConcurrent = (op, n, overflow, retryOptions, timeoutOptions) => {
|
|
|
825
860
|
subscribers.add(cb);
|
|
826
861
|
if (currentState.kind !== "Idle") cb(currentState);
|
|
827
862
|
return () => subscribers.delete(cb);
|
|
863
|
+
},
|
|
864
|
+
reset: () => emit(_idle),
|
|
865
|
+
poll: (input, { interval }) => {
|
|
866
|
+
void run(input);
|
|
867
|
+
const id = setInterval(() => void run(input), interval);
|
|
868
|
+
return () => clearInterval(id);
|
|
828
869
|
}
|
|
829
870
|
};
|
|
830
871
|
};
|
|
@@ -901,6 +942,15 @@ var makeKeyed = (op, keyFn, perKey, timeoutOptions) => {
|
|
|
901
942
|
subscribers.add(cb);
|
|
902
943
|
if (stateMap.size > 0) cb(new Map(stateMap));
|
|
903
944
|
return () => subscribers.delete(cb);
|
|
945
|
+
},
|
|
946
|
+
reset: () => {
|
|
947
|
+
stateMap.clear();
|
|
948
|
+
emitSnapshot();
|
|
949
|
+
},
|
|
950
|
+
poll: (input, { interval }) => {
|
|
951
|
+
void run(input);
|
|
952
|
+
const id = setInterval(() => void run(input), interval);
|
|
953
|
+
return () => clearInterval(id);
|
|
904
954
|
}
|
|
905
955
|
};
|
|
906
956
|
};
|
|
@@ -955,6 +1005,12 @@ var makeOnce = (op, retryOptions, timeoutOptions) => {
|
|
|
955
1005
|
subscribers.add(cb);
|
|
956
1006
|
if (currentState.kind !== "Idle") cb(currentState);
|
|
957
1007
|
return () => subscribers.delete(cb);
|
|
1008
|
+
},
|
|
1009
|
+
reset: () => emit(_idle),
|
|
1010
|
+
poll: (input, { interval }) => {
|
|
1011
|
+
void run(input);
|
|
1012
|
+
const id = setInterval(() => void run(input), interval);
|
|
1013
|
+
return () => clearInterval(id);
|
|
958
1014
|
}
|
|
959
1015
|
};
|
|
960
1016
|
};
|
|
@@ -962,44 +1018,59 @@ var makeOnce = (op, retryOptions, timeoutOptions) => {
|
|
|
962
1018
|
// src/Core/Op.ts
|
|
963
1019
|
var Op;
|
|
964
1020
|
((Op2) => {
|
|
965
|
-
Op2.nil = (reason) => ({ kind: "
|
|
1021
|
+
Op2.nil = (reason) => ({ kind: "OpNil", reason });
|
|
966
1022
|
Op2.create = (factory, onError) => ({
|
|
967
1023
|
_factory: (input, signal) => Deferred.fromPromise(
|
|
968
|
-
factory(signal)(input).then((value) => Result.ok(value)).catch((e) => signal.aborted ? null : Result.
|
|
1024
|
+
factory(signal)(input).then((value) => Result.ok(value)).catch((e) => signal.aborted ? null : Result.error(onError(e)))
|
|
969
1025
|
)
|
|
970
1026
|
});
|
|
971
|
-
Op2.
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
Op2.
|
|
1027
|
+
Op2.lift = (f) => (0, Op2.create)(
|
|
1028
|
+
(signal) => (input) => f(input, signal),
|
|
1029
|
+
(e) => e
|
|
1030
|
+
);
|
|
1031
|
+
Op2.ok = (value) => ({ kind: "OpOk", value });
|
|
1032
|
+
Op2.error = (error2) => ({ kind: "OpError", error: error2 });
|
|
1033
|
+
Op2.isIdle = (state) => state.kind === "Idle";
|
|
1034
|
+
Op2.isPending = (state) => state.kind === "Pending";
|
|
1035
|
+
Op2.isQueued = (state) => state.kind === "Queued";
|
|
1036
|
+
Op2.isRetrying = (state) => state.kind === "Retrying";
|
|
1037
|
+
Op2.isOk = (state) => state.kind === "OpOk";
|
|
1038
|
+
Op2.isError = (state) => state.kind === "OpError";
|
|
1039
|
+
Op2.isNil = (state) => state.kind === "OpNil";
|
|
976
1040
|
Op2.match = (cases) => (outcome) => {
|
|
977
|
-
if (outcome.kind === "
|
|
978
|
-
if (outcome.kind === "
|
|
1041
|
+
if (outcome.kind === "OpOk") return cases.ok(outcome.value);
|
|
1042
|
+
if (outcome.kind === "OpError") return cases.error(outcome.error);
|
|
979
1043
|
return cases.nil();
|
|
980
1044
|
};
|
|
981
|
-
Op2.fold = (
|
|
982
|
-
if (outcome.kind === "
|
|
983
|
-
if (outcome.kind === "
|
|
1045
|
+
Op2.fold = (onError, onOk, onNil) => (outcome) => {
|
|
1046
|
+
if (outcome.kind === "OpOk") return onOk(outcome.value);
|
|
1047
|
+
if (outcome.kind === "OpError") return onError(outcome.error);
|
|
984
1048
|
return onNil();
|
|
985
1049
|
};
|
|
986
|
-
Op2.getOrElse = (defaultValue) => (outcome) => outcome.kind === "
|
|
987
|
-
Op2.map = (f) => (outcome) => outcome.kind === "
|
|
988
|
-
Op2.mapError = (f) => (outcome) => outcome.kind === "
|
|
989
|
-
Op2.chain = (f) => (outcome) => outcome.kind === "
|
|
1050
|
+
Op2.getOrElse = (defaultValue) => (outcome) => outcome.kind === "OpOk" ? outcome.value : defaultValue();
|
|
1051
|
+
Op2.map = (f) => (outcome) => outcome.kind === "OpOk" ? (0, Op2.ok)(f(outcome.value)) : outcome;
|
|
1052
|
+
Op2.mapError = (f) => (outcome) => outcome.kind === "OpError" ? (0, Op2.error)(f(outcome.error)) : outcome;
|
|
1053
|
+
Op2.chain = (f) => (outcome) => outcome.kind === "OpOk" ? f(outcome.value) : outcome;
|
|
990
1054
|
Op2.tap = (f) => (outcome) => {
|
|
991
|
-
if (outcome.kind === "
|
|
1055
|
+
if (outcome.kind === "OpOk") f(outcome.value);
|
|
992
1056
|
return outcome;
|
|
993
1057
|
};
|
|
994
|
-
Op2.recover = (f) => (outcome) => outcome.kind === "
|
|
1058
|
+
Op2.recover = (f) => (outcome) => outcome.kind === "OpError" ? f(outcome.error) : outcome;
|
|
995
1059
|
Op2.toResult = (onNil) => (outcome) => {
|
|
996
|
-
if (outcome.kind === "
|
|
997
|
-
if (outcome.kind === "
|
|
998
|
-
return Result.
|
|
1060
|
+
if (outcome.kind === "OpOk") return Result.ok(outcome.value);
|
|
1061
|
+
if (outcome.kind === "OpError") return Result.error(outcome.error);
|
|
1062
|
+
return Result.error(onNil());
|
|
999
1063
|
};
|
|
1000
|
-
Op2.toMaybe = (outcome) => outcome.kind === "
|
|
1064
|
+
Op2.toMaybe = (outcome) => outcome.kind === "OpOk" ? Maybe.some(outcome.value) : Maybe.none();
|
|
1001
1065
|
Op2.all = (invocations) => Deferred.fromPromise(Promise.all(invocations.map(Deferred.toPromise)));
|
|
1002
1066
|
Op2.race = (invocations) => Deferred.fromPromise(Promise.race(invocations.map(Deferred.toPromise)));
|
|
1067
|
+
Op2.wire = (source, f) => source.subscribe((state) => {
|
|
1068
|
+
if ((0, Op2.isOk)(state)) f(state.value);
|
|
1069
|
+
});
|
|
1070
|
+
Op2.wireAll = (...pairs) => {
|
|
1071
|
+
const cleanups = pairs.map(([source, f]) => (0, Op2.wire)(source, f));
|
|
1072
|
+
return () => cleanups.forEach((c) => c());
|
|
1073
|
+
};
|
|
1003
1074
|
function interpret(op, options) {
|
|
1004
1075
|
const { strategy, retry: retryOptions, timeout: timeoutOptions } = options;
|
|
1005
1076
|
switch (strategy) {
|
|
@@ -1138,7 +1209,7 @@ var Refinement;
|
|
|
1138
1209
|
Refinement2.and = (second) => (first) => (a) => first(a) && second(a);
|
|
1139
1210
|
Refinement2.or = (second) => (first) => (a) => first(a) || second(a);
|
|
1140
1211
|
Refinement2.toFilter = (r) => (a) => r(a) ? Maybe.some(a) : Maybe.none();
|
|
1141
|
-
Refinement2.toResult = (r, onFail) => (a) => r(a) ? Result.ok(a) : Result.
|
|
1212
|
+
Refinement2.toResult = (r, onFail) => (a) => r(a) ? Result.ok(a) : Result.error(onFail(a));
|
|
1142
1213
|
})(Refinement || (Refinement = {}));
|
|
1143
1214
|
|
|
1144
1215
|
// src/Core/RemoteData.ts
|
|
@@ -1201,11 +1272,16 @@ var RemoteData;
|
|
|
1201
1272
|
if ((0, RemoteData2.isSuccess)(data)) f(data.value);
|
|
1202
1273
|
return data;
|
|
1203
1274
|
};
|
|
1275
|
+
RemoteData2.tapError = (f) => (data) => {
|
|
1276
|
+
if ((0, RemoteData2.isFailure)(data)) f(data.error);
|
|
1277
|
+
return data;
|
|
1278
|
+
};
|
|
1204
1279
|
RemoteData2.recover = (fallback) => (data) => (0, RemoteData2.isFailure)(data) ? fallback(data.error) : data;
|
|
1205
1280
|
RemoteData2.toMaybe = (data) => (0, RemoteData2.isSuccess)(data) ? Maybe.some(data.value) : Maybe.none();
|
|
1206
|
-
RemoteData2.toResult = (onNotReady) => (data) => (0, RemoteData2.isSuccess)(data) ? Result.ok(data.value) : Result.
|
|
1281
|
+
RemoteData2.toResult = (onNotReady) => (data) => (0, RemoteData2.isSuccess)(data) ? Result.ok(data.value) : Result.error((0, RemoteData2.isFailure)(data) ? data.error : onNotReady());
|
|
1207
1282
|
RemoteData2.fromResult = (data) => Result.isOk(data) ? (0, RemoteData2.success)(data.value) : (0, RemoteData2.failure)(data.error);
|
|
1208
1283
|
RemoteData2.fromMaybe = (onNone) => (data) => Maybe.isSome(data) ? (0, RemoteData2.success)(data.value) : (0, RemoteData2.failure)(onNone());
|
|
1284
|
+
RemoteData2.filter = (pred, onFalse) => (data) => (0, RemoteData2.isSuccess)(data) ? pred(data.value) ? data : (0, RemoteData2.failure)(onFalse(data.value)) : data;
|
|
1209
1285
|
})(RemoteData || (RemoteData = {}));
|
|
1210
1286
|
|
|
1211
1287
|
// src/Core/Task.ts
|
|
@@ -1245,21 +1321,22 @@ var Task;
|
|
|
1245
1321
|
if (times <= 0) return Promise.resolve([]);
|
|
1246
1322
|
const results = [];
|
|
1247
1323
|
const wait = () => ms !== void 0 && ms > 0 ? new Promise((r) => setTimeout(r, ms)) : Promise.resolve();
|
|
1248
|
-
const
|
|
1324
|
+
const run2 = (left) => toPromise(task, signal).then((a) => {
|
|
1249
1325
|
results.push(a);
|
|
1250
1326
|
if (left <= 1) return results;
|
|
1251
|
-
return wait().then(() =>
|
|
1327
|
+
return wait().then(() => run2(left - 1));
|
|
1252
1328
|
});
|
|
1253
|
-
return
|
|
1329
|
+
return run2(times);
|
|
1254
1330
|
});
|
|
1255
1331
|
Task2.repeatUntil = (options) => (task) => (0, Task2.from)((signal) => {
|
|
1256
|
-
const { when: predicate, delay: ms } = options;
|
|
1332
|
+
const { when: predicate, delay: ms, maxAttempts } = options;
|
|
1257
1333
|
const wait = () => ms !== void 0 && ms > 0 ? new Promise((r) => setTimeout(r, ms)) : Promise.resolve();
|
|
1258
|
-
const
|
|
1334
|
+
const run2 = (attempt) => toPromise(task, signal).then((a) => {
|
|
1259
1335
|
if (predicate(a)) return a;
|
|
1260
|
-
|
|
1336
|
+
if (maxAttempts !== void 0 && attempt >= maxAttempts) return a;
|
|
1337
|
+
return wait().then(() => run2(attempt + 1));
|
|
1261
1338
|
});
|
|
1262
|
-
return
|
|
1339
|
+
return run2(1);
|
|
1263
1340
|
});
|
|
1264
1341
|
Task2.race = (tasks) => (0, Task2.from)((signal) => Promise.race(tasks.map((t) => toPromise(t, signal))));
|
|
1265
1342
|
Task2.sequential = (tasks) => (0, Task2.from)(async (signal) => {
|
|
@@ -1284,14 +1361,18 @@ var Task;
|
|
|
1284
1361
|
timerId = setTimeout(() => {
|
|
1285
1362
|
controller.abort();
|
|
1286
1363
|
outerSignal?.removeEventListener("abort", onOuterAbort);
|
|
1287
|
-
resolve2(Result.
|
|
1364
|
+
resolve2(Result.error(onTimeout()));
|
|
1288
1365
|
}, ms);
|
|
1289
1366
|
})
|
|
1290
1367
|
]);
|
|
1291
1368
|
});
|
|
1292
1369
|
Task2.abortable = (factory) => {
|
|
1293
|
-
|
|
1370
|
+
let currentController = null;
|
|
1371
|
+
const abort = () => currentController?.abort();
|
|
1294
1372
|
const task = (outerSignal) => {
|
|
1373
|
+
currentController?.abort();
|
|
1374
|
+
currentController = new AbortController();
|
|
1375
|
+
const controller = currentController;
|
|
1295
1376
|
if (outerSignal) {
|
|
1296
1377
|
if (outerSignal.aborted) {
|
|
1297
1378
|
controller.abort(outerSignal.reason);
|
|
@@ -1301,8 +1382,9 @@ var Task;
|
|
|
1301
1382
|
}
|
|
1302
1383
|
return Deferred.fromPromise(factory(controller.signal));
|
|
1303
1384
|
};
|
|
1304
|
-
return { task, abort
|
|
1385
|
+
return { task, abort };
|
|
1305
1386
|
};
|
|
1387
|
+
Task2.run = (signal) => (task) => Deferred.toPromise(task(signal));
|
|
1306
1388
|
})(Task || (Task = {}));
|
|
1307
1389
|
|
|
1308
1390
|
// src/Core/Resource.ts
|
|
@@ -1315,7 +1397,7 @@ var Resource;
|
|
|
1315
1397
|
});
|
|
1316
1398
|
Resource2.use = (f) => (resource) => Task.from(
|
|
1317
1399
|
() => Deferred.toPromise(resource.acquire()).then(async (acquired) => {
|
|
1318
|
-
if (Result.
|
|
1400
|
+
if (Result.isError(acquired)) return acquired;
|
|
1319
1401
|
const a = acquired.value;
|
|
1320
1402
|
const usageResult = await Deferred.toPromise(f(a)());
|
|
1321
1403
|
await Deferred.toPromise(resource.release(a)());
|
|
@@ -1325,10 +1407,10 @@ var Resource;
|
|
|
1325
1407
|
Resource2.combine = (resourceA, resourceB) => ({
|
|
1326
1408
|
acquire: Task.from(
|
|
1327
1409
|
() => Deferred.toPromise(resourceA.acquire()).then(async (acquiredA) => {
|
|
1328
|
-
if (Result.
|
|
1410
|
+
if (Result.isError(acquiredA)) return acquiredA;
|
|
1329
1411
|
const a = acquiredA.value;
|
|
1330
1412
|
const acquiredB = await Deferred.toPromise(resourceB.acquire());
|
|
1331
|
-
if (Result.
|
|
1413
|
+
if (Result.isError(acquiredB)) {
|
|
1332
1414
|
await Deferred.toPromise(resourceA.release(a)());
|
|
1333
1415
|
return acquiredB;
|
|
1334
1416
|
}
|
|
@@ -1400,23 +1482,26 @@ var TaskMaybe;
|
|
|
1400
1482
|
var TaskResult;
|
|
1401
1483
|
((TaskResult2) => {
|
|
1402
1484
|
TaskResult2.ok = (value) => Task.resolve(Result.ok(value));
|
|
1403
|
-
TaskResult2.err = (error) => Task.resolve(Result.
|
|
1485
|
+
TaskResult2.err = (error) => Task.resolve(Result.error(error));
|
|
1404
1486
|
TaskResult2.tryCatch = (f, onError) => Task.from(
|
|
1405
|
-
(signal) => f(signal).then(Result.ok).catch((e) => Result.
|
|
1487
|
+
(signal) => f(signal).then(Result.ok).catch((e) => Result.error(onError(e)))
|
|
1406
1488
|
);
|
|
1407
1489
|
TaskResult2.map = (f) => (data) => Task.map(Result.map(f))(data);
|
|
1408
1490
|
TaskResult2.mapError = (f) => (data) => Task.map(Result.mapError(f))(data);
|
|
1409
|
-
TaskResult2.chain = (f) => (data) => Task.chain(
|
|
1491
|
+
TaskResult2.chain = (f) => (data) => Task.chain(
|
|
1492
|
+
(result) => Result.isOk(result) ? f(result.value) : Task.resolve(Result.error(result.error))
|
|
1493
|
+
)(
|
|
1410
1494
|
data
|
|
1411
1495
|
);
|
|
1412
1496
|
TaskResult2.fold = (onErr, onOk) => (data) => Task.map(Result.fold(onErr, onOk))(data);
|
|
1413
1497
|
TaskResult2.match = (cases) => (data) => Task.map(Result.match(cases))(data);
|
|
1414
1498
|
TaskResult2.recover = (fallback) => (data) => Task.chain(
|
|
1415
|
-
(result) => Result.
|
|
1499
|
+
(result) => Result.isError(result) ? fallback(result.error) : Task.resolve(result)
|
|
1416
1500
|
)(data);
|
|
1417
1501
|
TaskResult2.getOrElse = (defaultValue) => (data) => Task.map(Result.getOrElse(defaultValue))(data);
|
|
1418
1502
|
TaskResult2.tap = (f) => (data) => Task.map(Result.tap(f))(data);
|
|
1419
1503
|
TaskResult2.tapError = (f) => (data) => Task.map(Result.tapError(f))(data);
|
|
1504
|
+
TaskResult2.run = (signal) => (task) => Deferred.toPromise(task(signal));
|
|
1420
1505
|
})(TaskResult || (TaskResult = {}));
|
|
1421
1506
|
|
|
1422
1507
|
// src/Core/Validation.ts
|
|
@@ -1436,6 +1521,7 @@ var Validation;
|
|
|
1436
1521
|
});
|
|
1437
1522
|
Validation2.isValid = (data) => data.kind === "Valid";
|
|
1438
1523
|
Validation2.isInvalid = (data) => data.kind === "Invalid";
|
|
1524
|
+
Validation2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Validation2.valid)(a) : (0, Validation2.invalid)(onFalse(a));
|
|
1439
1525
|
Validation2.map = (f) => (data) => (0, Validation2.isValid)(data) ? (0, Validation2.valid)(f(data.value)) : data;
|
|
1440
1526
|
Validation2.ap = (arg) => (data) => {
|
|
1441
1527
|
if ((0, Validation2.isValid)(data) && (0, Validation2.isValid)(arg)) return (0, Validation2.valid)(data.value(arg.value));
|
|
@@ -1452,8 +1538,15 @@ var Validation;
|
|
|
1452
1538
|
if ((0, Validation2.isValid)(data)) f(data.value);
|
|
1453
1539
|
return data;
|
|
1454
1540
|
};
|
|
1541
|
+
Validation2.tapError = (f) => (data) => {
|
|
1542
|
+
if ((0, Validation2.isInvalid)(data)) f(data.errors);
|
|
1543
|
+
return data;
|
|
1544
|
+
};
|
|
1455
1545
|
Validation2.recover = (fallback) => (data) => (0, Validation2.isValid)(data) ? data : fallback(data.errors);
|
|
1456
|
-
Validation2.recoverUnless = (
|
|
1546
|
+
Validation2.recoverUnless = (isBlocked, fallback) => (data) => (0, Validation2.isInvalid)(data) && !data.errors.some(isBlocked) ? fallback() : data;
|
|
1547
|
+
Validation2.toResult = (data) => (0, Validation2.isValid)(data) ? Result.ok(data.value) : Result.error(data.errors);
|
|
1548
|
+
Validation2.toMaybe = (data) => (0, Validation2.isValid)(data) ? Maybe.some(data.value) : Maybe.none();
|
|
1549
|
+
Validation2.fromResult = (data) => data.kind === "Ok" ? (0, Validation2.valid)(data.value) : (0, Validation2.invalid)(data.error);
|
|
1457
1550
|
Validation2.product = (first, second) => {
|
|
1458
1551
|
if ((0, Validation2.isValid)(first) && (0, Validation2.isValid)(second)) return (0, Validation2.valid)([first.value, second.value]);
|
|
1459
1552
|
const errors = [
|
package/dist/core.mjs
CHANGED
|
@@ -15,13 +15,13 @@ import {
|
|
|
15
15
|
These,
|
|
16
16
|
Tuple,
|
|
17
17
|
Validation
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-PV7JOUKL.mjs";
|
|
19
19
|
import {
|
|
20
20
|
Deferred,
|
|
21
21
|
Maybe,
|
|
22
22
|
Result,
|
|
23
23
|
Task
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-SDGDJ7CU.mjs";
|
|
25
25
|
export {
|
|
26
26
|
Deferred,
|
|
27
27
|
Lens,
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { and, compose, constFalse, constNull, constTrue, constUndefined, constVoid, constant, converge, curry, curry3, curry4, flip, flow, identity, juxt, memoize, memoizeWeak, not, on, once, or, pipe, tap, uncurry, uncurry3, uncurry4 } from './composition.mjs';
|
|
2
|
-
export { D as Deferred, E as
|
|
2
|
+
export { D as Deferred, E as Error, M as Maybe, N as None, O as Ok, R as Result, S as Some, T as Task } from './Task-BDcKwFAj.mjs';
|
|
3
3
|
export { Failure, Invalid, Lens, Loading, Logged, NotAsked, Op, Optional, Predicate, Reader, Refinement, RemoteData, Resource, State, Success, TaskMaybe, TaskResult, TaskValidation, These, TheseBoth, TheseFirst, TheseSecond, Tuple, Valid, Validation } from './core.mjs';
|
|
4
4
|
export { Brand } from './types.mjs';
|
|
5
5
|
export { N as NonEmptyList, i as isNonEmptyList } from './NonEmptyList-BlGFjor5.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { and, compose, constFalse, constNull, constTrue, constUndefined, constVoid, constant, converge, curry, curry3, curry4, flip, flow, identity, juxt, memoize, memoizeWeak, not, on, once, or, pipe, tap, uncurry, uncurry3, uncurry4 } from './composition.js';
|
|
2
|
-
export { D as Deferred, E as
|
|
2
|
+
export { D as Deferred, E as Error, M as Maybe, N as None, O as Ok, R as Result, S as Some, T as Task } from './Task-CnF22Q2o.js';
|
|
3
3
|
export { Failure, Invalid, Lens, Loading, Logged, NotAsked, Op, Optional, Predicate, Reader, Refinement, RemoteData, Resource, State, Success, TaskMaybe, TaskResult, TaskValidation, These, TheseBoth, TheseFirst, TheseSecond, Tuple, Valid, Validation } from './core.js';
|
|
4
4
|
export { Brand } from './types.js';
|
|
5
5
|
export { N as NonEmptyList, i as isNonEmptyList } from './NonEmptyList-BlGFjor5.js';
|