@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/index.js
CHANGED
|
@@ -351,18 +351,18 @@ var Logged;
|
|
|
351
351
|
var Result;
|
|
352
352
|
((Result2) => {
|
|
353
353
|
Result2.ok = (value) => ({ kind: "Ok", value });
|
|
354
|
-
Result2.
|
|
354
|
+
Result2.error = (e) => ({ kind: "Error", error: e });
|
|
355
355
|
Result2.isOk = (data) => data.kind === "Ok";
|
|
356
|
-
Result2.
|
|
356
|
+
Result2.isError = (data) => data.kind === "Error";
|
|
357
357
|
Result2.tryCatch = (f, onError) => {
|
|
358
358
|
try {
|
|
359
359
|
return (0, Result2.ok)(f());
|
|
360
360
|
} catch (e) {
|
|
361
|
-
return (0, Result2.
|
|
361
|
+
return (0, Result2.error)(onError(e));
|
|
362
362
|
}
|
|
363
363
|
};
|
|
364
364
|
Result2.map = (f) => (data) => (0, Result2.isOk)(data) ? (0, Result2.ok)(f(data.value)) : data;
|
|
365
|
-
Result2.mapError = (f) => (data) => (0, Result2.
|
|
365
|
+
Result2.mapError = (f) => (data) => (0, Result2.isError)(data) ? (0, Result2.error)(f(data.error)) : data;
|
|
366
366
|
Result2.chain = (f) => (data) => (0, Result2.isOk)(data) ? f(data.value) : data;
|
|
367
367
|
Result2.fold = (onErr, onOk) => (data) => (0, Result2.isOk)(data) ? onOk(data.value) : onErr(data.error);
|
|
368
368
|
Result2.match = (cases) => (data) => (0, Result2.isOk)(data) ? cases.ok(data.value) : cases.err(data.error);
|
|
@@ -372,14 +372,14 @@ var Result;
|
|
|
372
372
|
return data;
|
|
373
373
|
};
|
|
374
374
|
Result2.tapError = (f) => (data) => {
|
|
375
|
-
if ((0, Result2.
|
|
375
|
+
if ((0, Result2.isError)(data)) f(data.error);
|
|
376
376
|
return data;
|
|
377
377
|
};
|
|
378
|
-
Result2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Result2.ok)(a) : (0, Result2.
|
|
378
|
+
Result2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Result2.ok)(a) : (0, Result2.error)(onFalse(a));
|
|
379
379
|
Result2.recover = (fallback) => (data) => (0, Result2.isOk)(data) ? data : fallback(data.error);
|
|
380
|
-
Result2.recoverUnless = (
|
|
380
|
+
Result2.recoverUnless = (isBlocked, fallback) => (data) => (0, Result2.isError)(data) && !isBlocked(data.error) ? fallback() : data;
|
|
381
381
|
Result2.toMaybe = (data) => (0, Result2.isOk)(data) ? Maybe.some(data.value) : Maybe.none();
|
|
382
|
-
Result2.ap = (arg) => (data) => (0, Result2.isOk)(data) && (0, Result2.isOk)(arg) ? (0, Result2.ok)(data.value(arg.value)) : (0, Result2.
|
|
382
|
+
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;
|
|
383
383
|
})(Result || (Result = {}));
|
|
384
384
|
|
|
385
385
|
// src/Core/Maybe.ts
|
|
@@ -393,9 +393,8 @@ var Maybe;
|
|
|
393
393
|
Maybe2.fromNullable = (value) => value === null || value === void 0 ? (0, Maybe2.none)() : (0, Maybe2.some)(value);
|
|
394
394
|
Maybe2.toNullable = (data) => (0, Maybe2.isSome)(data) ? data.value : null;
|
|
395
395
|
Maybe2.toUndefined = (data) => (0, Maybe2.isSome)(data) ? data.value : void 0;
|
|
396
|
-
Maybe2.fromUndefined = (value) => value === void 0 ? (0, Maybe2.none)() : (0, Maybe2.some)(value);
|
|
397
396
|
Maybe2.fromPredicate = (pred) => (a) => pred(a) ? (0, Maybe2.some)(a) : (0, Maybe2.none)();
|
|
398
|
-
Maybe2.toResult = (onNone) => (data) => (0, Maybe2.isSome)(data) ? Result.ok(data.value) : Result.
|
|
397
|
+
Maybe2.toResult = (onNone) => (data) => (0, Maybe2.isSome)(data) ? Result.ok(data.value) : Result.error(onNone());
|
|
399
398
|
Maybe2.fromResult = (data) => Result.isOk(data) ? (0, Maybe2.some)(data.value) : (0, Maybe2.none)();
|
|
400
399
|
Maybe2.map = (f) => (data) => (0, Maybe2.isSome)(data) ? (0, Maybe2.some)(f(data.value)) : data;
|
|
401
400
|
Maybe2.chain = (f) => (data) => (0, Maybe2.isSome)(data) ? f(data.value) : data;
|
|
@@ -412,14 +411,14 @@ var Maybe;
|
|
|
412
411
|
})(Maybe || (Maybe = {}));
|
|
413
412
|
|
|
414
413
|
// src/internal/Op.util.ts
|
|
415
|
-
var _abortedNil = { kind: "
|
|
416
|
-
var _droppedNil = { kind: "
|
|
417
|
-
var _replacedNil = { kind: "
|
|
418
|
-
var _evictedNil = { kind: "
|
|
414
|
+
var _abortedNil = { kind: "OpNil", reason: "aborted" };
|
|
415
|
+
var _droppedNil = { kind: "OpNil", reason: "dropped" };
|
|
416
|
+
var _replacedNil = { kind: "OpNil", reason: "replaced" };
|
|
417
|
+
var _evictedNil = { kind: "OpNil", reason: "evicted" };
|
|
419
418
|
var _idle = { kind: "Idle" };
|
|
420
419
|
var _pending = { kind: "Pending" };
|
|
421
|
-
var ok = (value) => ({ kind: "
|
|
422
|
-
var err = (error) => ({ kind: "
|
|
420
|
+
var ok = (value) => ({ kind: "OpOk", value });
|
|
421
|
+
var err = (error) => ({ kind: "OpError", error });
|
|
423
422
|
var cancellableWait = (ms, signal) => {
|
|
424
423
|
if (ms <= 0) return Promise.resolve();
|
|
425
424
|
return new Promise((resolve) => {
|
|
@@ -542,6 +541,12 @@ var makeRestartable = (op, minInterval, retryOptions, timeoutOptions) => {
|
|
|
542
541
|
subscribers.add(cb);
|
|
543
542
|
if (currentState.kind !== "Idle") cb(currentState);
|
|
544
543
|
return () => subscribers.delete(cb);
|
|
544
|
+
},
|
|
545
|
+
reset: () => emit(_idle),
|
|
546
|
+
poll: (input, { interval }) => {
|
|
547
|
+
void run(input);
|
|
548
|
+
const id = setInterval(() => void run(input), interval);
|
|
549
|
+
return () => clearInterval(id);
|
|
545
550
|
}
|
|
546
551
|
};
|
|
547
552
|
};
|
|
@@ -606,6 +611,12 @@ var makeExclusive = (op, cooldown, retryOptions, timeoutOptions) => {
|
|
|
606
611
|
subscribers.add(cb);
|
|
607
612
|
if (currentState.kind !== "Idle") cb(currentState);
|
|
608
613
|
return () => subscribers.delete(cb);
|
|
614
|
+
},
|
|
615
|
+
reset: () => emit(_idle),
|
|
616
|
+
poll: (input, { interval }) => {
|
|
617
|
+
void run(input);
|
|
618
|
+
const id = setInterval(() => void run(input), interval);
|
|
619
|
+
return () => clearInterval(id);
|
|
609
620
|
}
|
|
610
621
|
};
|
|
611
622
|
};
|
|
@@ -705,6 +716,12 @@ var makeQueue = (op, maxSize, overflow, concurrency, dedupe, retryOptions, timeo
|
|
|
705
716
|
subscribers.add(cb);
|
|
706
717
|
if (currentState.kind !== "Idle") cb(currentState);
|
|
707
718
|
return () => subscribers.delete(cb);
|
|
719
|
+
},
|
|
720
|
+
reset: () => emit(_idle),
|
|
721
|
+
poll: (input, { interval }) => {
|
|
722
|
+
void run(input);
|
|
723
|
+
const id = setInterval(() => void run(input), interval);
|
|
724
|
+
return () => clearInterval(id);
|
|
708
725
|
}
|
|
709
726
|
};
|
|
710
727
|
};
|
|
@@ -775,6 +792,12 @@ var makeBuffered = (op, size, retryOptions, timeoutOptions) => {
|
|
|
775
792
|
subscribers.add(cb);
|
|
776
793
|
if (currentState.kind !== "Idle") cb(currentState);
|
|
777
794
|
return () => subscribers.delete(cb);
|
|
795
|
+
},
|
|
796
|
+
reset: () => emit(_idle),
|
|
797
|
+
poll: (input, { interval }) => {
|
|
798
|
+
void run(input);
|
|
799
|
+
const id = setInterval(() => void run(input), interval);
|
|
800
|
+
return () => clearInterval(id);
|
|
778
801
|
}
|
|
779
802
|
};
|
|
780
803
|
};
|
|
@@ -897,6 +920,12 @@ var makeDebounced = (op, ms, leading, maxWait, retryOptions, timeoutOptions) =>
|
|
|
897
920
|
subscribers.add(cb);
|
|
898
921
|
if (currentState.kind !== "Idle") cb(currentState);
|
|
899
922
|
return () => subscribers.delete(cb);
|
|
923
|
+
},
|
|
924
|
+
reset: () => emit(_idle),
|
|
925
|
+
poll: (input, { interval }) => {
|
|
926
|
+
void run(input);
|
|
927
|
+
const id = setInterval(() => void run(input), interval);
|
|
928
|
+
return () => clearInterval(id);
|
|
900
929
|
}
|
|
901
930
|
};
|
|
902
931
|
};
|
|
@@ -989,6 +1018,12 @@ var makeThrottled = (op, ms, trailing, retryOptions, timeoutOptions) => {
|
|
|
989
1018
|
subscribers.add(cb);
|
|
990
1019
|
if (currentState.kind !== "Idle") cb(currentState);
|
|
991
1020
|
return () => subscribers.delete(cb);
|
|
1021
|
+
},
|
|
1022
|
+
reset: () => emit(_idle),
|
|
1023
|
+
poll: (input, { interval }) => {
|
|
1024
|
+
void run(input);
|
|
1025
|
+
const id = setInterval(() => void run(input), interval);
|
|
1026
|
+
return () => clearInterval(id);
|
|
992
1027
|
}
|
|
993
1028
|
};
|
|
994
1029
|
};
|
|
@@ -1070,6 +1105,12 @@ var makeConcurrent = (op, n, overflow, retryOptions, timeoutOptions) => {
|
|
|
1070
1105
|
subscribers.add(cb);
|
|
1071
1106
|
if (currentState.kind !== "Idle") cb(currentState);
|
|
1072
1107
|
return () => subscribers.delete(cb);
|
|
1108
|
+
},
|
|
1109
|
+
reset: () => emit(_idle),
|
|
1110
|
+
poll: (input, { interval }) => {
|
|
1111
|
+
void run(input);
|
|
1112
|
+
const id = setInterval(() => void run(input), interval);
|
|
1113
|
+
return () => clearInterval(id);
|
|
1073
1114
|
}
|
|
1074
1115
|
};
|
|
1075
1116
|
};
|
|
@@ -1146,6 +1187,15 @@ var makeKeyed = (op, keyFn, perKey, timeoutOptions) => {
|
|
|
1146
1187
|
subscribers.add(cb);
|
|
1147
1188
|
if (stateMap.size > 0) cb(new Map(stateMap));
|
|
1148
1189
|
return () => subscribers.delete(cb);
|
|
1190
|
+
},
|
|
1191
|
+
reset: () => {
|
|
1192
|
+
stateMap.clear();
|
|
1193
|
+
emitSnapshot();
|
|
1194
|
+
},
|
|
1195
|
+
poll: (input, { interval }) => {
|
|
1196
|
+
void run(input);
|
|
1197
|
+
const id = setInterval(() => void run(input), interval);
|
|
1198
|
+
return () => clearInterval(id);
|
|
1149
1199
|
}
|
|
1150
1200
|
};
|
|
1151
1201
|
};
|
|
@@ -1200,6 +1250,12 @@ var makeOnce = (op, retryOptions, timeoutOptions) => {
|
|
|
1200
1250
|
subscribers.add(cb);
|
|
1201
1251
|
if (currentState.kind !== "Idle") cb(currentState);
|
|
1202
1252
|
return () => subscribers.delete(cb);
|
|
1253
|
+
},
|
|
1254
|
+
reset: () => emit(_idle),
|
|
1255
|
+
poll: (input, { interval }) => {
|
|
1256
|
+
void run(input);
|
|
1257
|
+
const id = setInterval(() => void run(input), interval);
|
|
1258
|
+
return () => clearInterval(id);
|
|
1203
1259
|
}
|
|
1204
1260
|
};
|
|
1205
1261
|
};
|
|
@@ -1207,44 +1263,59 @@ var makeOnce = (op, retryOptions, timeoutOptions) => {
|
|
|
1207
1263
|
// src/Core/Op.ts
|
|
1208
1264
|
var Op;
|
|
1209
1265
|
((Op2) => {
|
|
1210
|
-
Op2.nil = (reason) => ({ kind: "
|
|
1266
|
+
Op2.nil = (reason) => ({ kind: "OpNil", reason });
|
|
1211
1267
|
Op2.create = (factory, onError) => ({
|
|
1212
1268
|
_factory: (input, signal) => Deferred.fromPromise(
|
|
1213
|
-
factory(signal)(input).then((value) => Result.ok(value)).catch((e) => signal.aborted ? null : Result.
|
|
1269
|
+
factory(signal)(input).then((value) => Result.ok(value)).catch((e) => signal.aborted ? null : Result.error(onError(e)))
|
|
1214
1270
|
)
|
|
1215
1271
|
});
|
|
1216
|
-
Op2.
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
Op2.
|
|
1272
|
+
Op2.lift = (f) => (0, Op2.create)(
|
|
1273
|
+
(signal) => (input) => f(input, signal),
|
|
1274
|
+
(e) => e
|
|
1275
|
+
);
|
|
1276
|
+
Op2.ok = (value) => ({ kind: "OpOk", value });
|
|
1277
|
+
Op2.error = (error2) => ({ kind: "OpError", error: error2 });
|
|
1278
|
+
Op2.isIdle = (state) => state.kind === "Idle";
|
|
1279
|
+
Op2.isPending = (state) => state.kind === "Pending";
|
|
1280
|
+
Op2.isQueued = (state) => state.kind === "Queued";
|
|
1281
|
+
Op2.isRetrying = (state) => state.kind === "Retrying";
|
|
1282
|
+
Op2.isOk = (state) => state.kind === "OpOk";
|
|
1283
|
+
Op2.isError = (state) => state.kind === "OpError";
|
|
1284
|
+
Op2.isNil = (state) => state.kind === "OpNil";
|
|
1221
1285
|
Op2.match = (cases) => (outcome) => {
|
|
1222
|
-
if (outcome.kind === "
|
|
1223
|
-
if (outcome.kind === "
|
|
1286
|
+
if (outcome.kind === "OpOk") return cases.ok(outcome.value);
|
|
1287
|
+
if (outcome.kind === "OpError") return cases.error(outcome.error);
|
|
1224
1288
|
return cases.nil();
|
|
1225
1289
|
};
|
|
1226
|
-
Op2.fold = (
|
|
1227
|
-
if (outcome.kind === "
|
|
1228
|
-
if (outcome.kind === "
|
|
1290
|
+
Op2.fold = (onError, onOk, onNil) => (outcome) => {
|
|
1291
|
+
if (outcome.kind === "OpOk") return onOk(outcome.value);
|
|
1292
|
+
if (outcome.kind === "OpError") return onError(outcome.error);
|
|
1229
1293
|
return onNil();
|
|
1230
1294
|
};
|
|
1231
|
-
Op2.getOrElse = (defaultValue) => (outcome) => outcome.kind === "
|
|
1232
|
-
Op2.map = (f) => (outcome) => outcome.kind === "
|
|
1233
|
-
Op2.mapError = (f) => (outcome) => outcome.kind === "
|
|
1234
|
-
Op2.chain = (f) => (outcome) => outcome.kind === "
|
|
1295
|
+
Op2.getOrElse = (defaultValue) => (outcome) => outcome.kind === "OpOk" ? outcome.value : defaultValue();
|
|
1296
|
+
Op2.map = (f) => (outcome) => outcome.kind === "OpOk" ? (0, Op2.ok)(f(outcome.value)) : outcome;
|
|
1297
|
+
Op2.mapError = (f) => (outcome) => outcome.kind === "OpError" ? (0, Op2.error)(f(outcome.error)) : outcome;
|
|
1298
|
+
Op2.chain = (f) => (outcome) => outcome.kind === "OpOk" ? f(outcome.value) : outcome;
|
|
1235
1299
|
Op2.tap = (f) => (outcome) => {
|
|
1236
|
-
if (outcome.kind === "
|
|
1300
|
+
if (outcome.kind === "OpOk") f(outcome.value);
|
|
1237
1301
|
return outcome;
|
|
1238
1302
|
};
|
|
1239
|
-
Op2.recover = (f) => (outcome) => outcome.kind === "
|
|
1303
|
+
Op2.recover = (f) => (outcome) => outcome.kind === "OpError" ? f(outcome.error) : outcome;
|
|
1240
1304
|
Op2.toResult = (onNil) => (outcome) => {
|
|
1241
|
-
if (outcome.kind === "
|
|
1242
|
-
if (outcome.kind === "
|
|
1243
|
-
return Result.
|
|
1305
|
+
if (outcome.kind === "OpOk") return Result.ok(outcome.value);
|
|
1306
|
+
if (outcome.kind === "OpError") return Result.error(outcome.error);
|
|
1307
|
+
return Result.error(onNil());
|
|
1244
1308
|
};
|
|
1245
|
-
Op2.toMaybe = (outcome) => outcome.kind === "
|
|
1309
|
+
Op2.toMaybe = (outcome) => outcome.kind === "OpOk" ? Maybe.some(outcome.value) : Maybe.none();
|
|
1246
1310
|
Op2.all = (invocations) => Deferred.fromPromise(Promise.all(invocations.map(Deferred.toPromise)));
|
|
1247
1311
|
Op2.race = (invocations) => Deferred.fromPromise(Promise.race(invocations.map(Deferred.toPromise)));
|
|
1312
|
+
Op2.wire = (source, f) => source.subscribe((state) => {
|
|
1313
|
+
if ((0, Op2.isOk)(state)) f(state.value);
|
|
1314
|
+
});
|
|
1315
|
+
Op2.wireAll = (...pairs) => {
|
|
1316
|
+
const cleanups = pairs.map(([source, f]) => (0, Op2.wire)(source, f));
|
|
1317
|
+
return () => cleanups.forEach((c) => c());
|
|
1318
|
+
};
|
|
1248
1319
|
function interpret(op, options) {
|
|
1249
1320
|
const { strategy, retry: retryOptions, timeout: timeoutOptions } = options;
|
|
1250
1321
|
switch (strategy) {
|
|
@@ -1383,7 +1454,7 @@ var Refinement;
|
|
|
1383
1454
|
Refinement2.and = (second) => (first) => (a) => first(a) && second(a);
|
|
1384
1455
|
Refinement2.or = (second) => (first) => (a) => first(a) || second(a);
|
|
1385
1456
|
Refinement2.toFilter = (r) => (a) => r(a) ? Maybe.some(a) : Maybe.none();
|
|
1386
|
-
Refinement2.toResult = (r, onFail) => (a) => r(a) ? Result.ok(a) : Result.
|
|
1457
|
+
Refinement2.toResult = (r, onFail) => (a) => r(a) ? Result.ok(a) : Result.error(onFail(a));
|
|
1387
1458
|
})(Refinement || (Refinement = {}));
|
|
1388
1459
|
|
|
1389
1460
|
// src/Core/RemoteData.ts
|
|
@@ -1446,11 +1517,16 @@ var RemoteData;
|
|
|
1446
1517
|
if ((0, RemoteData2.isSuccess)(data)) f(data.value);
|
|
1447
1518
|
return data;
|
|
1448
1519
|
};
|
|
1520
|
+
RemoteData2.tapError = (f) => (data) => {
|
|
1521
|
+
if ((0, RemoteData2.isFailure)(data)) f(data.error);
|
|
1522
|
+
return data;
|
|
1523
|
+
};
|
|
1449
1524
|
RemoteData2.recover = (fallback) => (data) => (0, RemoteData2.isFailure)(data) ? fallback(data.error) : data;
|
|
1450
1525
|
RemoteData2.toMaybe = (data) => (0, RemoteData2.isSuccess)(data) ? Maybe.some(data.value) : Maybe.none();
|
|
1451
|
-
RemoteData2.toResult = (onNotReady) => (data) => (0, RemoteData2.isSuccess)(data) ? Result.ok(data.value) : Result.
|
|
1526
|
+
RemoteData2.toResult = (onNotReady) => (data) => (0, RemoteData2.isSuccess)(data) ? Result.ok(data.value) : Result.error((0, RemoteData2.isFailure)(data) ? data.error : onNotReady());
|
|
1452
1527
|
RemoteData2.fromResult = (data) => Result.isOk(data) ? (0, RemoteData2.success)(data.value) : (0, RemoteData2.failure)(data.error);
|
|
1453
1528
|
RemoteData2.fromMaybe = (onNone) => (data) => Maybe.isSome(data) ? (0, RemoteData2.success)(data.value) : (0, RemoteData2.failure)(onNone());
|
|
1529
|
+
RemoteData2.filter = (pred, onFalse) => (data) => (0, RemoteData2.isSuccess)(data) ? pred(data.value) ? data : (0, RemoteData2.failure)(onFalse(data.value)) : data;
|
|
1454
1530
|
})(RemoteData || (RemoteData = {}));
|
|
1455
1531
|
|
|
1456
1532
|
// src/Core/Task.ts
|
|
@@ -1490,21 +1566,22 @@ var Task;
|
|
|
1490
1566
|
if (times <= 0) return Promise.resolve([]);
|
|
1491
1567
|
const results = [];
|
|
1492
1568
|
const wait = () => ms !== void 0 && ms > 0 ? new Promise((r) => setTimeout(r, ms)) : Promise.resolve();
|
|
1493
|
-
const
|
|
1569
|
+
const run2 = (left) => toPromise(task, signal).then((a) => {
|
|
1494
1570
|
results.push(a);
|
|
1495
1571
|
if (left <= 1) return results;
|
|
1496
|
-
return wait().then(() =>
|
|
1572
|
+
return wait().then(() => run2(left - 1));
|
|
1497
1573
|
});
|
|
1498
|
-
return
|
|
1574
|
+
return run2(times);
|
|
1499
1575
|
});
|
|
1500
1576
|
Task2.repeatUntil = (options) => (task) => (0, Task2.from)((signal) => {
|
|
1501
|
-
const { when: predicate, delay: ms } = options;
|
|
1577
|
+
const { when: predicate, delay: ms, maxAttempts } = options;
|
|
1502
1578
|
const wait = () => ms !== void 0 && ms > 0 ? new Promise((r) => setTimeout(r, ms)) : Promise.resolve();
|
|
1503
|
-
const
|
|
1579
|
+
const run2 = (attempt) => toPromise(task, signal).then((a) => {
|
|
1504
1580
|
if (predicate(a)) return a;
|
|
1505
|
-
|
|
1581
|
+
if (maxAttempts !== void 0 && attempt >= maxAttempts) return a;
|
|
1582
|
+
return wait().then(() => run2(attempt + 1));
|
|
1506
1583
|
});
|
|
1507
|
-
return
|
|
1584
|
+
return run2(1);
|
|
1508
1585
|
});
|
|
1509
1586
|
Task2.race = (tasks) => (0, Task2.from)((signal) => Promise.race(tasks.map((t) => toPromise(t, signal))));
|
|
1510
1587
|
Task2.sequential = (tasks) => (0, Task2.from)(async (signal) => {
|
|
@@ -1529,14 +1606,18 @@ var Task;
|
|
|
1529
1606
|
timerId = setTimeout(() => {
|
|
1530
1607
|
controller.abort();
|
|
1531
1608
|
outerSignal?.removeEventListener("abort", onOuterAbort);
|
|
1532
|
-
resolve2(Result.
|
|
1609
|
+
resolve2(Result.error(onTimeout()));
|
|
1533
1610
|
}, ms);
|
|
1534
1611
|
})
|
|
1535
1612
|
]);
|
|
1536
1613
|
});
|
|
1537
1614
|
Task2.abortable = (factory) => {
|
|
1538
|
-
|
|
1615
|
+
let currentController = null;
|
|
1616
|
+
const abort = () => currentController?.abort();
|
|
1539
1617
|
const task = (outerSignal) => {
|
|
1618
|
+
currentController?.abort();
|
|
1619
|
+
currentController = new AbortController();
|
|
1620
|
+
const controller = currentController;
|
|
1540
1621
|
if (outerSignal) {
|
|
1541
1622
|
if (outerSignal.aborted) {
|
|
1542
1623
|
controller.abort(outerSignal.reason);
|
|
@@ -1546,8 +1627,9 @@ var Task;
|
|
|
1546
1627
|
}
|
|
1547
1628
|
return Deferred.fromPromise(factory(controller.signal));
|
|
1548
1629
|
};
|
|
1549
|
-
return { task, abort
|
|
1630
|
+
return { task, abort };
|
|
1550
1631
|
};
|
|
1632
|
+
Task2.run = (signal) => (task) => Deferred.toPromise(task(signal));
|
|
1551
1633
|
})(Task || (Task = {}));
|
|
1552
1634
|
|
|
1553
1635
|
// src/Core/Resource.ts
|
|
@@ -1560,7 +1642,7 @@ var Resource;
|
|
|
1560
1642
|
});
|
|
1561
1643
|
Resource2.use = (f) => (resource) => Task.from(
|
|
1562
1644
|
() => Deferred.toPromise(resource.acquire()).then(async (acquired) => {
|
|
1563
|
-
if (Result.
|
|
1645
|
+
if (Result.isError(acquired)) return acquired;
|
|
1564
1646
|
const a = acquired.value;
|
|
1565
1647
|
const usageResult = await Deferred.toPromise(f(a)());
|
|
1566
1648
|
await Deferred.toPromise(resource.release(a)());
|
|
@@ -1570,10 +1652,10 @@ var Resource;
|
|
|
1570
1652
|
Resource2.combine = (resourceA, resourceB) => ({
|
|
1571
1653
|
acquire: Task.from(
|
|
1572
1654
|
() => Deferred.toPromise(resourceA.acquire()).then(async (acquiredA) => {
|
|
1573
|
-
if (Result.
|
|
1655
|
+
if (Result.isError(acquiredA)) return acquiredA;
|
|
1574
1656
|
const a = acquiredA.value;
|
|
1575
1657
|
const acquiredB = await Deferred.toPromise(resourceB.acquire());
|
|
1576
|
-
if (Result.
|
|
1658
|
+
if (Result.isError(acquiredB)) {
|
|
1577
1659
|
await Deferred.toPromise(resourceA.release(a)());
|
|
1578
1660
|
return acquiredB;
|
|
1579
1661
|
}
|
|
@@ -1645,23 +1727,26 @@ var TaskMaybe;
|
|
|
1645
1727
|
var TaskResult;
|
|
1646
1728
|
((TaskResult2) => {
|
|
1647
1729
|
TaskResult2.ok = (value) => Task.resolve(Result.ok(value));
|
|
1648
|
-
TaskResult2.err = (error) => Task.resolve(Result.
|
|
1730
|
+
TaskResult2.err = (error) => Task.resolve(Result.error(error));
|
|
1649
1731
|
TaskResult2.tryCatch = (f, onError) => Task.from(
|
|
1650
|
-
(signal) => f(signal).then(Result.ok).catch((e) => Result.
|
|
1732
|
+
(signal) => f(signal).then(Result.ok).catch((e) => Result.error(onError(e)))
|
|
1651
1733
|
);
|
|
1652
1734
|
TaskResult2.map = (f) => (data) => Task.map(Result.map(f))(data);
|
|
1653
1735
|
TaskResult2.mapError = (f) => (data) => Task.map(Result.mapError(f))(data);
|
|
1654
|
-
TaskResult2.chain = (f) => (data) => Task.chain(
|
|
1736
|
+
TaskResult2.chain = (f) => (data) => Task.chain(
|
|
1737
|
+
(result) => Result.isOk(result) ? f(result.value) : Task.resolve(Result.error(result.error))
|
|
1738
|
+
)(
|
|
1655
1739
|
data
|
|
1656
1740
|
);
|
|
1657
1741
|
TaskResult2.fold = (onErr, onOk) => (data) => Task.map(Result.fold(onErr, onOk))(data);
|
|
1658
1742
|
TaskResult2.match = (cases) => (data) => Task.map(Result.match(cases))(data);
|
|
1659
1743
|
TaskResult2.recover = (fallback) => (data) => Task.chain(
|
|
1660
|
-
(result) => Result.
|
|
1744
|
+
(result) => Result.isError(result) ? fallback(result.error) : Task.resolve(result)
|
|
1661
1745
|
)(data);
|
|
1662
1746
|
TaskResult2.getOrElse = (defaultValue) => (data) => Task.map(Result.getOrElse(defaultValue))(data);
|
|
1663
1747
|
TaskResult2.tap = (f) => (data) => Task.map(Result.tap(f))(data);
|
|
1664
1748
|
TaskResult2.tapError = (f) => (data) => Task.map(Result.tapError(f))(data);
|
|
1749
|
+
TaskResult2.run = (signal) => (task) => Deferred.toPromise(task(signal));
|
|
1665
1750
|
})(TaskResult || (TaskResult = {}));
|
|
1666
1751
|
|
|
1667
1752
|
// src/Core/Validation.ts
|
|
@@ -1681,6 +1766,7 @@ var Validation;
|
|
|
1681
1766
|
});
|
|
1682
1767
|
Validation2.isValid = (data) => data.kind === "Valid";
|
|
1683
1768
|
Validation2.isInvalid = (data) => data.kind === "Invalid";
|
|
1769
|
+
Validation2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Validation2.valid)(a) : (0, Validation2.invalid)(onFalse(a));
|
|
1684
1770
|
Validation2.map = (f) => (data) => (0, Validation2.isValid)(data) ? (0, Validation2.valid)(f(data.value)) : data;
|
|
1685
1771
|
Validation2.ap = (arg) => (data) => {
|
|
1686
1772
|
if ((0, Validation2.isValid)(data) && (0, Validation2.isValid)(arg)) return (0, Validation2.valid)(data.value(arg.value));
|
|
@@ -1697,8 +1783,15 @@ var Validation;
|
|
|
1697
1783
|
if ((0, Validation2.isValid)(data)) f(data.value);
|
|
1698
1784
|
return data;
|
|
1699
1785
|
};
|
|
1786
|
+
Validation2.tapError = (f) => (data) => {
|
|
1787
|
+
if ((0, Validation2.isInvalid)(data)) f(data.errors);
|
|
1788
|
+
return data;
|
|
1789
|
+
};
|
|
1700
1790
|
Validation2.recover = (fallback) => (data) => (0, Validation2.isValid)(data) ? data : fallback(data.errors);
|
|
1701
|
-
Validation2.recoverUnless = (
|
|
1791
|
+
Validation2.recoverUnless = (isBlocked, fallback) => (data) => (0, Validation2.isInvalid)(data) && !data.errors.some(isBlocked) ? fallback() : data;
|
|
1792
|
+
Validation2.toResult = (data) => (0, Validation2.isValid)(data) ? Result.ok(data.value) : Result.error(data.errors);
|
|
1793
|
+
Validation2.toMaybe = (data) => (0, Validation2.isValid)(data) ? Maybe.some(data.value) : Maybe.none();
|
|
1794
|
+
Validation2.fromResult = (data) => data.kind === "Ok" ? (0, Validation2.valid)(data.value) : (0, Validation2.invalid)(data.error);
|
|
1702
1795
|
Validation2.product = (first, second) => {
|
|
1703
1796
|
if ((0, Validation2.isValid)(first) && (0, Validation2.isValid)(second)) return (0, Validation2.valid)([first.value, second.value]);
|
|
1704
1797
|
const errors = [
|
|
@@ -2003,7 +2096,7 @@ var Arr;
|
|
|
2003
2096
|
const result = [];
|
|
2004
2097
|
for (const a of data) {
|
|
2005
2098
|
const r = await Deferred.toPromise(f(a)());
|
|
2006
|
-
if (Result.
|
|
2099
|
+
if (Result.isError(r)) return r;
|
|
2007
2100
|
result.push(r.value);
|
|
2008
2101
|
}
|
|
2009
2102
|
return Result.ok(result);
|
|
@@ -2144,6 +2237,14 @@ var Dict;
|
|
|
2144
2237
|
}
|
|
2145
2238
|
return result;
|
|
2146
2239
|
};
|
|
2240
|
+
Dict2.filterMap = (f) => (m) => {
|
|
2241
|
+
const result = new globalThis.Map();
|
|
2242
|
+
for (const [key, value] of m) {
|
|
2243
|
+
const mapped = f(value);
|
|
2244
|
+
if (mapped.kind === "Some") result.set(key, mapped.value);
|
|
2245
|
+
}
|
|
2246
|
+
return result;
|
|
2247
|
+
};
|
|
2147
2248
|
Dict2.union = (other) => (m) => {
|
|
2148
2249
|
const result = new globalThis.Map(m);
|
|
2149
2250
|
for (const [k, v] of other) {
|
|
@@ -2204,13 +2305,13 @@ var Num;
|
|
|
2204
2305
|
Num2.add = (b) => (a) => a + b;
|
|
2205
2306
|
Num2.subtract = (b) => (a) => a - b;
|
|
2206
2307
|
Num2.multiply = (b) => (a) => a * b;
|
|
2207
|
-
Num2.divide = (b) => (a) => a / b;
|
|
2308
|
+
Num2.divide = (b) => (a) => b === 0 ? Maybe.none() : Maybe.some(a / b);
|
|
2208
2309
|
Num2.abs = (n) => Math.abs(n);
|
|
2209
2310
|
Num2.negate = (n) => -n;
|
|
2210
2311
|
Num2.round = (n) => Math.round(n);
|
|
2211
2312
|
Num2.floor = (n) => Math.floor(n);
|
|
2212
2313
|
Num2.ceil = (n) => Math.ceil(n);
|
|
2213
|
-
Num2.remainder = (divisor) => (n) => n % divisor;
|
|
2314
|
+
Num2.remainder = (divisor) => (n) => divisor === 0 ? Maybe.none() : Maybe.some(n % divisor);
|
|
2214
2315
|
})(Num || (Num = {}));
|
|
2215
2316
|
|
|
2216
2317
|
// src/Utils/Rec.ts
|
package/dist/index.mjs
CHANGED
|
@@ -44,7 +44,7 @@ import {
|
|
|
44
44
|
These,
|
|
45
45
|
Tuple,
|
|
46
46
|
Validation
|
|
47
|
-
} from "./chunk-
|
|
47
|
+
} from "./chunk-PV7JOUKL.mjs";
|
|
48
48
|
import {
|
|
49
49
|
Arr,
|
|
50
50
|
Dict,
|
|
@@ -52,13 +52,13 @@ import {
|
|
|
52
52
|
Rec,
|
|
53
53
|
Str,
|
|
54
54
|
Uniq
|
|
55
|
-
} from "./chunk-
|
|
55
|
+
} from "./chunk-FWYOEWJ2.mjs";
|
|
56
56
|
import {
|
|
57
57
|
Deferred,
|
|
58
58
|
Maybe,
|
|
59
59
|
Result,
|
|
60
60
|
Task
|
|
61
|
-
} from "./chunk-
|
|
61
|
+
} from "./chunk-SDGDJ7CU.mjs";
|
|
62
62
|
import {
|
|
63
63
|
Brand
|
|
64
64
|
} from "./chunk-BYWKZLHM.mjs";
|
package/dist/utils.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { M as Maybe, R as Result, T as Task } from './Task-
|
|
1
|
+
import { M as Maybe, R as Result, T as Task } from './Task-BDcKwFAj.mjs';
|
|
2
2
|
import { N as NonEmptyList } from './NonEmptyList-BlGFjor5.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -269,7 +269,7 @@ declare namespace Arr {
|
|
|
269
269
|
* ```ts
|
|
270
270
|
* pipe(
|
|
271
271
|
* [1, 2, 3],
|
|
272
|
-
* Arr.traverseResult(n => n > 0 ? Result.ok(n) : Result.
|
|
272
|
+
* Arr.traverseResult(n => n > 0 ? Result.ok(n) : Result.error("negative"))
|
|
273
273
|
* ); // Ok([1, 2, 3])
|
|
274
274
|
* ```
|
|
275
275
|
*/
|
|
@@ -684,6 +684,21 @@ declare namespace Dict {
|
|
|
684
684
|
* ```
|
|
685
685
|
*/
|
|
686
686
|
const compact: <K, A>(m: ReadonlyMap<K, Maybe<A>>) => ReadonlyMap<K, A>;
|
|
687
|
+
/**
|
|
688
|
+
* Applies `f` to each value. Entries where `f` returns `None` are removed; entries where
|
|
689
|
+
* `f` returns `Some` are kept with the unwrapped value. Combines map and filter in one pass.
|
|
690
|
+
*
|
|
691
|
+
* @example
|
|
692
|
+
* ```ts
|
|
693
|
+
* const parse = (s: string): Maybe<number> => {
|
|
694
|
+
* const n = Number(s);
|
|
695
|
+
* return isNaN(n) ? Maybe.none() : Maybe.some(n);
|
|
696
|
+
* };
|
|
697
|
+
* Dict.filterMap(parse)(Dict.fromRecord({ a: "1", b: "two", c: "3" }));
|
|
698
|
+
* // ReadonlyMap { "a" => 1, "c" => 3 }
|
|
699
|
+
* ```
|
|
700
|
+
*/
|
|
701
|
+
const filterMap: <A, B>(f: (a: A) => Maybe<B>) => <K>(m: ReadonlyMap<K, A>) => ReadonlyMap<K, B>;
|
|
687
702
|
/**
|
|
688
703
|
* Merges two dictionaries. When both contain the same key, the value from `other` takes
|
|
689
704
|
* precedence.
|
|
@@ -858,15 +873,16 @@ declare namespace Num {
|
|
|
858
873
|
*/
|
|
859
874
|
const multiply: (b: number) => (a: number) => number;
|
|
860
875
|
/**
|
|
861
|
-
* Divides a number by `b`. Data-last: `divide(b)(a)` = `a / b`.
|
|
876
|
+
* Divides a number by `b`. Returns `None` when `b` is zero. Data-last: `divide(b)(a)` = `a / b`.
|
|
862
877
|
*
|
|
863
878
|
* @example
|
|
864
879
|
* ```ts
|
|
865
|
-
* pipe(20, Num.divide(4));
|
|
866
|
-
* pipe(
|
|
880
|
+
* pipe(20, Num.divide(4)); // Some(5)
|
|
881
|
+
* pipe(5, Num.divide(0)); // None
|
|
882
|
+
* pipe([10, 20, 30], Arr.filterMap(Num.divide(10))); // [1, 2, 3]
|
|
867
883
|
* ```
|
|
868
884
|
*/
|
|
869
|
-
const divide: (b: number) => (a: number) => number
|
|
885
|
+
const divide: (b: number) => (a: number) => Maybe<number>;
|
|
870
886
|
/**
|
|
871
887
|
* Returns the absolute value of a number.
|
|
872
888
|
*
|
|
@@ -918,15 +934,17 @@ declare namespace Num {
|
|
|
918
934
|
*/
|
|
919
935
|
const ceil: (n: number) => number;
|
|
920
936
|
/**
|
|
921
|
-
* Returns the remainder of dividing a number by `divisor`.
|
|
937
|
+
* Returns the remainder of dividing a number by `divisor`. Returns `None` when `divisor` is zero.
|
|
938
|
+
* Data-last: `remainder(divisor)(a)` = `a % divisor`.
|
|
922
939
|
*
|
|
923
940
|
* @example
|
|
924
941
|
* ```ts
|
|
925
|
-
* pipe(10, Num.remainder(3));
|
|
926
|
-
* pipe(
|
|
942
|
+
* pipe(10, Num.remainder(3)); // Some(1)
|
|
943
|
+
* pipe(5, Num.remainder(0)); // None
|
|
944
|
+
* pipe([10, 11, 12], Arr.filterMap(Num.remainder(3))); // [1, 2, 0]
|
|
927
945
|
* ```
|
|
928
946
|
*/
|
|
929
|
-
const remainder: (divisor: number) => (n: number) => number
|
|
947
|
+
const remainder: (divisor: number) => (n: number) => Maybe<number>;
|
|
930
948
|
}
|
|
931
949
|
|
|
932
950
|
/**
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { M as Maybe, R as Result, T as Task } from './Task-
|
|
1
|
+
import { M as Maybe, R as Result, T as Task } from './Task-CnF22Q2o.js';
|
|
2
2
|
import { N as NonEmptyList } from './NonEmptyList-BlGFjor5.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -269,7 +269,7 @@ declare namespace Arr {
|
|
|
269
269
|
* ```ts
|
|
270
270
|
* pipe(
|
|
271
271
|
* [1, 2, 3],
|
|
272
|
-
* Arr.traverseResult(n => n > 0 ? Result.ok(n) : Result.
|
|
272
|
+
* Arr.traverseResult(n => n > 0 ? Result.ok(n) : Result.error("negative"))
|
|
273
273
|
* ); // Ok([1, 2, 3])
|
|
274
274
|
* ```
|
|
275
275
|
*/
|
|
@@ -684,6 +684,21 @@ declare namespace Dict {
|
|
|
684
684
|
* ```
|
|
685
685
|
*/
|
|
686
686
|
const compact: <K, A>(m: ReadonlyMap<K, Maybe<A>>) => ReadonlyMap<K, A>;
|
|
687
|
+
/**
|
|
688
|
+
* Applies `f` to each value. Entries where `f` returns `None` are removed; entries where
|
|
689
|
+
* `f` returns `Some` are kept with the unwrapped value. Combines map and filter in one pass.
|
|
690
|
+
*
|
|
691
|
+
* @example
|
|
692
|
+
* ```ts
|
|
693
|
+
* const parse = (s: string): Maybe<number> => {
|
|
694
|
+
* const n = Number(s);
|
|
695
|
+
* return isNaN(n) ? Maybe.none() : Maybe.some(n);
|
|
696
|
+
* };
|
|
697
|
+
* Dict.filterMap(parse)(Dict.fromRecord({ a: "1", b: "two", c: "3" }));
|
|
698
|
+
* // ReadonlyMap { "a" => 1, "c" => 3 }
|
|
699
|
+
* ```
|
|
700
|
+
*/
|
|
701
|
+
const filterMap: <A, B>(f: (a: A) => Maybe<B>) => <K>(m: ReadonlyMap<K, A>) => ReadonlyMap<K, B>;
|
|
687
702
|
/**
|
|
688
703
|
* Merges two dictionaries. When both contain the same key, the value from `other` takes
|
|
689
704
|
* precedence.
|
|
@@ -858,15 +873,16 @@ declare namespace Num {
|
|
|
858
873
|
*/
|
|
859
874
|
const multiply: (b: number) => (a: number) => number;
|
|
860
875
|
/**
|
|
861
|
-
* Divides a number by `b`. Data-last: `divide(b)(a)` = `a / b`.
|
|
876
|
+
* Divides a number by `b`. Returns `None` when `b` is zero. Data-last: `divide(b)(a)` = `a / b`.
|
|
862
877
|
*
|
|
863
878
|
* @example
|
|
864
879
|
* ```ts
|
|
865
|
-
* pipe(20, Num.divide(4));
|
|
866
|
-
* pipe(
|
|
880
|
+
* pipe(20, Num.divide(4)); // Some(5)
|
|
881
|
+
* pipe(5, Num.divide(0)); // None
|
|
882
|
+
* pipe([10, 20, 30], Arr.filterMap(Num.divide(10))); // [1, 2, 3]
|
|
867
883
|
* ```
|
|
868
884
|
*/
|
|
869
|
-
const divide: (b: number) => (a: number) => number
|
|
885
|
+
const divide: (b: number) => (a: number) => Maybe<number>;
|
|
870
886
|
/**
|
|
871
887
|
* Returns the absolute value of a number.
|
|
872
888
|
*
|
|
@@ -918,15 +934,17 @@ declare namespace Num {
|
|
|
918
934
|
*/
|
|
919
935
|
const ceil: (n: number) => number;
|
|
920
936
|
/**
|
|
921
|
-
* Returns the remainder of dividing a number by `divisor`.
|
|
937
|
+
* Returns the remainder of dividing a number by `divisor`. Returns `None` when `divisor` is zero.
|
|
938
|
+
* Data-last: `remainder(divisor)(a)` = `a % divisor`.
|
|
922
939
|
*
|
|
923
940
|
* @example
|
|
924
941
|
* ```ts
|
|
925
|
-
* pipe(10, Num.remainder(3));
|
|
926
|
-
* pipe(
|
|
942
|
+
* pipe(10, Num.remainder(3)); // Some(1)
|
|
943
|
+
* pipe(5, Num.remainder(0)); // None
|
|
944
|
+
* pipe([10, 11, 12], Arr.filterMap(Num.remainder(3))); // [1, 2, 0]
|
|
927
945
|
* ```
|
|
928
946
|
*/
|
|
929
|
-
const remainder: (divisor: number) => (n: number) => number
|
|
947
|
+
const remainder: (divisor: number) => (n: number) => Maybe<number>;
|
|
930
948
|
}
|
|
931
949
|
|
|
932
950
|
/**
|