@nlozgachev/pipelined 0.33.0 → 0.35.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 +75 -40
- package/dist/{Task-5na0QzS4.d.mts → Task-DXsuurnc.d.mts} +54 -55
- package/dist/{Task-DeiWgoeJ.d.ts → Task-zAY4kSVB.d.ts} +54 -55
- package/dist/{chunk-FZX4MTRI.mjs → chunk-5AWUAG7G.mjs} +445 -308
- package/dist/{chunk-NRF2FVPZ.mjs → chunk-AHEZFTMT.mjs} +64 -32
- package/dist/{chunk-GSTKY7MF.mjs → chunk-DLBHVYII.mjs} +69 -52
- package/dist/{chunk-W53ZYTLX.mjs → chunk-IJFFWBKW.mjs} +184 -64
- package/dist/composition.d.mts +8 -7
- package/dist/composition.d.ts +8 -7
- package/dist/composition.js +64 -32
- package/dist/composition.mjs +1 -1
- package/dist/core.d.mts +172 -163
- package/dist/core.d.ts +172 -163
- package/dist/core.js +535 -384
- package/dist/core.mjs +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +783 -480
- package/dist/index.mjs +4 -4
- package/dist/utils.d.mts +8 -7
- package/dist/utils.d.ts +8 -7
- package/dist/utils.js +252 -115
- package/dist/utils.mjs +2 -2
- package/package.json +9 -9
package/dist/core.js
CHANGED
|
@@ -51,44 +51,48 @@ module.exports = __toCommonJS(Core_exports);
|
|
|
51
51
|
var Result;
|
|
52
52
|
((Result2) => {
|
|
53
53
|
Result2.ok = (value) => ({ kind: "Ok", value });
|
|
54
|
-
Result2.
|
|
54
|
+
Result2.err = (e) => ({ kind: "Err", error: e });
|
|
55
55
|
Result2.isOk = (data) => data.kind === "Ok";
|
|
56
|
-
Result2.
|
|
56
|
+
Result2.isErr = (data) => data.kind === "Err";
|
|
57
57
|
Result2.tryCatch = (f, onError) => {
|
|
58
58
|
try {
|
|
59
59
|
return (0, Result2.ok)(f());
|
|
60
|
-
} catch (
|
|
61
|
-
return (0, Result2.
|
|
60
|
+
} catch (error) {
|
|
61
|
+
return (0, Result2.err)(onError(error));
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
64
|
Result2.map = (f) => (data) => (0, Result2.isOk)(data) ? (0, Result2.ok)(f(data.value)) : data;
|
|
65
|
-
Result2.mapError = (f) => (data) => (0, Result2.
|
|
65
|
+
Result2.mapError = (f) => (data) => (0, Result2.isErr)(data) ? (0, Result2.err)(f(data.error)) : data;
|
|
66
66
|
Result2.chain = (f) => (data) => (0, Result2.isOk)(data) ? f(data.value) : data;
|
|
67
67
|
Result2.fold = (onErr, onOk) => (data) => (0, Result2.isOk)(data) ? onOk(data.value) : onErr(data.error);
|
|
68
68
|
Result2.match = (cases) => (data) => (0, Result2.isOk)(data) ? cases.ok(data.value) : cases.err(data.error);
|
|
69
69
|
Result2.getOrElse = (defaultValue) => (data) => (0, Result2.isOk)(data) ? data.value : defaultValue();
|
|
70
70
|
Result2.tap = (f) => (data) => {
|
|
71
|
-
if ((0, Result2.isOk)(data))
|
|
71
|
+
if ((0, Result2.isOk)(data)) {
|
|
72
|
+
f(data.value);
|
|
73
|
+
}
|
|
72
74
|
return data;
|
|
73
75
|
};
|
|
74
76
|
Result2.tapError = (f) => (data) => {
|
|
75
|
-
if ((0, Result2.
|
|
77
|
+
if ((0, Result2.isErr)(data)) {
|
|
78
|
+
f(data.error);
|
|
79
|
+
}
|
|
76
80
|
return data;
|
|
77
81
|
};
|
|
78
|
-
Result2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Result2.ok)(a) : (0, Result2.
|
|
79
|
-
Result2.fromNullable = (onNull) => (value) => value === null || value === void 0 ? (0, Result2.
|
|
80
|
-
Result2.fromMaybe = (onNone) => (maybe) => Maybe.isNone(maybe) ? (0, Result2.
|
|
82
|
+
Result2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Result2.ok)(a) : (0, Result2.err)(onFalse(a));
|
|
83
|
+
Result2.fromNullable = (onNull) => (value) => value === null || value === void 0 ? (0, Result2.err)(onNull()) : (0, Result2.ok)(value);
|
|
84
|
+
Result2.fromMaybe = (onNone) => (maybe) => Maybe.isNone(maybe) ? (0, Result2.err)(onNone()) : (0, Result2.ok)(maybe.value);
|
|
81
85
|
Result2.fromThrowable = (f, onError) => (...args) => {
|
|
82
86
|
try {
|
|
83
87
|
return (0, Result2.ok)(f(...args));
|
|
84
|
-
} catch (
|
|
85
|
-
return (0, Result2.
|
|
88
|
+
} catch (error) {
|
|
89
|
+
return (0, Result2.err)(onError(error));
|
|
86
90
|
}
|
|
87
91
|
};
|
|
88
92
|
Result2.recover = (fallback) => (data) => (0, Result2.isOk)(data) ? data : fallback(data.error);
|
|
89
|
-
Result2.recoverUnless = (isBlocked, fallback) => (data) => (0, Result2.
|
|
93
|
+
Result2.recoverUnless = (isBlocked, fallback) => (data) => (0, Result2.isErr)(data) && !isBlocked(data.error) ? fallback() : data;
|
|
90
94
|
Result2.toMaybe = (data) => (0, Result2.isOk)(data) ? Maybe.some(data.value) : Maybe.none();
|
|
91
|
-
Result2.ap = (arg) => (data) => (0, Result2.isOk)(data) && (0, Result2.isOk)(arg) ? (0, Result2.ok)(data.value(arg.value)) : (0, Result2.
|
|
95
|
+
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;
|
|
92
96
|
})(Result || (Result = {}));
|
|
93
97
|
|
|
94
98
|
// src/Core/Maybe.ts
|
|
@@ -103,7 +107,7 @@ var Maybe;
|
|
|
103
107
|
Maybe2.toNullable = (data) => (0, Maybe2.isSome)(data) ? data.value : null;
|
|
104
108
|
Maybe2.toUndefined = (data) => (0, Maybe2.isSome)(data) ? data.value : void 0;
|
|
105
109
|
Maybe2.fromPredicate = (pred) => (a) => pred(a) ? (0, Maybe2.some)(a) : (0, Maybe2.none)();
|
|
106
|
-
Maybe2.toResult = (onNone) => (data) => (0, Maybe2.isSome)(data) ? Result.ok(data.value) : Result.
|
|
110
|
+
Maybe2.toResult = (onNone) => (data) => (0, Maybe2.isSome)(data) ? Result.ok(data.value) : Result.err(onNone());
|
|
107
111
|
Maybe2.fromResult = (data) => Result.isOk(data) ? (0, Maybe2.some)(data.value) : (0, Maybe2.none)();
|
|
108
112
|
Maybe2.map = (f) => (data) => (0, Maybe2.isSome)(data) ? (0, Maybe2.some)(f(data.value)) : data;
|
|
109
113
|
Maybe2.chain = (f) => (data) => (0, Maybe2.isSome)(data) ? f(data.value) : data;
|
|
@@ -111,7 +115,9 @@ var Maybe;
|
|
|
111
115
|
Maybe2.match = (cases) => (data) => (0, Maybe2.isSome)(data) ? cases.some(data.value) : cases.none();
|
|
112
116
|
Maybe2.getOrElse = (defaultValue) => (data) => (0, Maybe2.isSome)(data) ? data.value : defaultValue();
|
|
113
117
|
Maybe2.tap = (f) => (data) => {
|
|
114
|
-
if ((0, Maybe2.isSome)(data))
|
|
118
|
+
if ((0, Maybe2.isSome)(data)) {
|
|
119
|
+
f(data.value);
|
|
120
|
+
}
|
|
115
121
|
return data;
|
|
116
122
|
};
|
|
117
123
|
Maybe2.filter = (predicate) => (data) => (0, Maybe2.isSome)(data) ? predicate(data.value) ? data : (0, Maybe2.none)() : data;
|
|
@@ -122,30 +128,12 @@ var Maybe;
|
|
|
122
128
|
// src/Core/Combinable.ts
|
|
123
129
|
var Combinable;
|
|
124
130
|
((Combinable2) => {
|
|
125
|
-
Combinable2.string = {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
};
|
|
129
|
-
Combinable2.
|
|
130
|
-
|
|
131
|
-
combine: (b) => (a) => a + b
|
|
132
|
-
};
|
|
133
|
-
Combinable2.product = {
|
|
134
|
-
empty: 1,
|
|
135
|
-
combine: (b) => (a) => a * b
|
|
136
|
-
};
|
|
137
|
-
Combinable2.all = {
|
|
138
|
-
empty: true,
|
|
139
|
-
combine: (b) => (a) => a && b
|
|
140
|
-
};
|
|
141
|
-
Combinable2.any = {
|
|
142
|
-
empty: false,
|
|
143
|
-
combine: (b) => (a) => a || b
|
|
144
|
-
};
|
|
145
|
-
Combinable2.array = () => ({
|
|
146
|
-
empty: [],
|
|
147
|
-
combine: (b) => (a) => [...a, ...b]
|
|
148
|
-
});
|
|
131
|
+
Combinable2.string = { empty: "", combine: (b) => (a) => a + b };
|
|
132
|
+
Combinable2.sum = { empty: 0, combine: (b) => (a) => a + b };
|
|
133
|
+
Combinable2.product = { empty: 1, combine: (b) => (a) => a * b };
|
|
134
|
+
Combinable2.all = { empty: true, combine: (b) => (a) => a && b };
|
|
135
|
+
Combinable2.any = { empty: false, combine: (b) => (a) => a || b };
|
|
136
|
+
Combinable2.array = () => ({ empty: [], combine: (b) => (a) => [...a, ...b] });
|
|
149
137
|
Combinable2.maybe = (inner) => ({
|
|
150
138
|
empty: Maybe.none(),
|
|
151
139
|
combine: (b) => (a) => Maybe.isNone(a) ? b : Maybe.isNone(b) ? a : Maybe.some(inner.combine(b.value)(a.value))
|
|
@@ -205,17 +193,11 @@ var Lazy;
|
|
|
205
193
|
var Lens;
|
|
206
194
|
((Lens2) => {
|
|
207
195
|
Lens2.make = (get2, set2) => ({ get: get2, set: set2 });
|
|
208
|
-
Lens2.prop = () => (key) => (0, Lens2.make)(
|
|
209
|
-
(s) => s[key],
|
|
210
|
-
(a) => (s) => ({ ...s, [key]: a })
|
|
211
|
-
);
|
|
196
|
+
Lens2.prop = () => (key) => (0, Lens2.make)((s) => s[key], (a) => (s) => ({ ...s, [key]: a }));
|
|
212
197
|
Lens2.get = (lens) => (s) => lens.get(s);
|
|
213
198
|
Lens2.set = (lens) => (a) => (s) => lens.set(a)(s);
|
|
214
199
|
Lens2.modify = (lens) => (f) => (s) => lens.set(f(lens.get(s)))(s);
|
|
215
|
-
Lens2.andThen = (inner) => (outer) => (0, Lens2.make)(
|
|
216
|
-
(s) => inner.get(outer.get(s)),
|
|
217
|
-
(b) => (s) => outer.set(inner.set(b)(outer.get(s)))(s)
|
|
218
|
-
);
|
|
200
|
+
Lens2.andThen = (inner) => (outer) => (0, Lens2.make)((s) => inner.get(outer.get(s)), (b) => (s) => outer.set(inner.set(b)(outer.get(s)))(s));
|
|
219
201
|
Lens2.andThenOptional = (inner) => (outer) => ({
|
|
220
202
|
get: (s) => inner.get(outer.get(s)),
|
|
221
203
|
set: (b) => (s) => outer.set(inner.set(b)(outer.get(s)))(s)
|
|
@@ -250,6 +232,31 @@ var Logged;
|
|
|
250
232
|
Logged2.run = (data) => [data.value, data.log];
|
|
251
233
|
})(Logged || (Logged = {}));
|
|
252
234
|
|
|
235
|
+
// src/Types/Brand.ts
|
|
236
|
+
var Brand;
|
|
237
|
+
((Brand2) => {
|
|
238
|
+
Brand2.wrap = () => (value) => value;
|
|
239
|
+
Brand2.unwrap = (branded) => branded;
|
|
240
|
+
})(Brand || (Brand = {}));
|
|
241
|
+
|
|
242
|
+
// src/Types/Duration.ts
|
|
243
|
+
var Duration;
|
|
244
|
+
((Duration2) => {
|
|
245
|
+
const wrap = Brand.wrap();
|
|
246
|
+
Duration2.milliseconds = (ms) => wrap(ms);
|
|
247
|
+
Duration2.seconds = (s) => wrap(s * 1e3);
|
|
248
|
+
Duration2.minutes = (m) => wrap(m * 60 * 1e3);
|
|
249
|
+
Duration2.hours = (h) => wrap(h * 60 * 60 * 1e3);
|
|
250
|
+
Duration2.days = (d) => wrap(d * 24 * 60 * 60 * 1e3);
|
|
251
|
+
Duration2.toMilliseconds = (d) => Brand.unwrap(d);
|
|
252
|
+
Duration2.toSeconds = (d) => Brand.unwrap(d) / 1e3;
|
|
253
|
+
Duration2.toMinutes = (d) => Brand.unwrap(d) / (60 * 1e3);
|
|
254
|
+
Duration2.toHours = (d) => Brand.unwrap(d) / (60 * 60 * 1e3);
|
|
255
|
+
Duration2.toDays = (d) => Brand.unwrap(d) / (24 * 60 * 60 * 1e3);
|
|
256
|
+
Duration2.add = (other) => (self) => wrap(Brand.unwrap(self) + Brand.unwrap(other));
|
|
257
|
+
Duration2.subtract = (other) => (self) => wrap(Brand.unwrap(self) - Brand.unwrap(other));
|
|
258
|
+
})(Duration || (Duration = {}));
|
|
259
|
+
|
|
253
260
|
// src/internal/Op.util.ts
|
|
254
261
|
var _abortedNil = { kind: "OpNil", reason: "aborted" };
|
|
255
262
|
var _droppedNil = { kind: "OpNil", reason: "dropped" };
|
|
@@ -258,11 +265,15 @@ var _evictedNil = { kind: "OpNil", reason: "evicted" };
|
|
|
258
265
|
var _idle = { kind: "Idle" };
|
|
259
266
|
var _pending = { kind: "Pending" };
|
|
260
267
|
var ok = (value) => ({ kind: "OpOk", value });
|
|
261
|
-
var err = (error) => ({ kind: "
|
|
262
|
-
var
|
|
263
|
-
|
|
268
|
+
var err = (error) => ({ kind: "OpErr", error });
|
|
269
|
+
var getMs = (duration) => Duration.toMilliseconds(duration);
|
|
270
|
+
var cancellableWait = (duration, signal) => {
|
|
271
|
+
const rawMs = getMs(duration);
|
|
272
|
+
if (rawMs <= 0) {
|
|
273
|
+
return Promise.resolve();
|
|
274
|
+
}
|
|
264
275
|
return new Promise((resolve) => {
|
|
265
|
-
const id = setTimeout(resolve,
|
|
276
|
+
const id = setTimeout(resolve, rawMs);
|
|
266
277
|
signal.addEventListener("abort", () => {
|
|
267
278
|
clearTimeout(id);
|
|
268
279
|
resolve();
|
|
@@ -271,23 +282,41 @@ var cancellableWait = (ms, signal) => {
|
|
|
271
282
|
};
|
|
272
283
|
var runWithRetry = (op, input, signal, options, onRetrying) => {
|
|
273
284
|
const { attempts, backoff, when: shouldRetry } = options;
|
|
274
|
-
const getDelay = (n) =>
|
|
285
|
+
const getDelay = (n) => {
|
|
286
|
+
if (backoff === void 0) {
|
|
287
|
+
return void 0;
|
|
288
|
+
}
|
|
289
|
+
return typeof backoff === "function" ? backoff(n) : backoff;
|
|
290
|
+
};
|
|
275
291
|
const attempt = async (left) => {
|
|
276
292
|
const result = await Deferred.toPromise(op._factory(input, signal));
|
|
277
|
-
if (result === null || signal.aborted)
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
if (
|
|
293
|
+
if (result === null || signal.aborted) {
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
if (result.kind === "Ok") {
|
|
297
|
+
return result;
|
|
298
|
+
}
|
|
299
|
+
if (left <= 1) {
|
|
300
|
+
return result;
|
|
301
|
+
}
|
|
302
|
+
if (shouldRetry !== void 0 && !shouldRetry(result.error)) {
|
|
303
|
+
return result;
|
|
304
|
+
}
|
|
281
305
|
const attemptNumber = attempts - left + 1;
|
|
282
|
-
const
|
|
306
|
+
const delayDuration = getDelay(attemptNumber);
|
|
307
|
+
const ms = delayDuration ? getMs(delayDuration) : 0;
|
|
283
308
|
onRetrying({
|
|
284
309
|
kind: "Retrying",
|
|
285
310
|
attempt: attemptNumber,
|
|
286
311
|
lastError: result.error,
|
|
287
312
|
...ms > 0 ? { nextRetryIn: ms } : {}
|
|
288
313
|
});
|
|
289
|
-
|
|
290
|
-
|
|
314
|
+
if (delayDuration) {
|
|
315
|
+
await cancellableWait(delayDuration, signal);
|
|
316
|
+
}
|
|
317
|
+
if (signal.aborted) {
|
|
318
|
+
return null;
|
|
319
|
+
}
|
|
291
320
|
return attempt(left - 1);
|
|
292
321
|
};
|
|
293
322
|
return attempt(attempts);
|
|
@@ -296,7 +325,9 @@ var execute = (op, input, controller, retryOptions, timeoutOptions, onRetrying)
|
|
|
296
325
|
const { signal } = controller;
|
|
297
326
|
const toOutcome = (r) => r === null ? _abortedNil : r.kind === "Ok" ? ok(r.value) : err(r.error);
|
|
298
327
|
const runPromise = retryOptions !== void 0 && onRetrying !== void 0 ? runWithRetry(op, input, signal, retryOptions, onRetrying).then(toOutcome) : Deferred.toPromise(op._factory(input, signal)).then(toOutcome);
|
|
299
|
-
if (timeoutOptions === void 0)
|
|
328
|
+
if (timeoutOptions === void 0) {
|
|
329
|
+
return Deferred.fromPromise(runPromise);
|
|
330
|
+
}
|
|
300
331
|
let timerId;
|
|
301
332
|
return Deferred.fromPromise(Promise.race([
|
|
302
333
|
runPromise.then((outcome) => {
|
|
@@ -307,7 +338,7 @@ var execute = (op, input, controller, retryOptions, timeoutOptions, onRetrying)
|
|
|
307
338
|
timerId = setTimeout(() => {
|
|
308
339
|
controller.abort();
|
|
309
340
|
resolve(err(timeoutOptions.onTimeout()));
|
|
310
|
-
}, timeoutOptions.
|
|
341
|
+
}, getMs(timeoutOptions.duration));
|
|
311
342
|
})
|
|
312
343
|
]));
|
|
313
344
|
};
|
|
@@ -333,14 +364,20 @@ var makeRestartable = (op, minInterval, retryOptions, timeoutOptions) => {
|
|
|
333
364
|
const controller = currentController;
|
|
334
365
|
prev?.(_replacedNil);
|
|
335
366
|
const startExecution = () => {
|
|
336
|
-
if (currentController !== controller)
|
|
367
|
+
if (currentController !== controller) {
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
337
370
|
lastStartTime = Date.now();
|
|
338
371
|
emit(_pending);
|
|
339
372
|
const onRetrying = retryOptions ? (r) => {
|
|
340
|
-
if (currentController === controller)
|
|
373
|
+
if (currentController === controller) {
|
|
374
|
+
emit(r);
|
|
375
|
+
}
|
|
341
376
|
} : void 0;
|
|
342
377
|
execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
|
|
343
|
-
if (currentController !== controller)
|
|
378
|
+
if (currentController !== controller) {
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
344
381
|
const r = currentResolve;
|
|
345
382
|
currentResolve = void 0;
|
|
346
383
|
currentController = void 0;
|
|
@@ -348,12 +385,14 @@ var makeRestartable = (op, minInterval, retryOptions, timeoutOptions) => {
|
|
|
348
385
|
r?.(outcome);
|
|
349
386
|
});
|
|
350
387
|
};
|
|
351
|
-
const gap = minInterval !== void 0 ? Math.max(0, minInterval - (Date.now() - lastStartTime)) : 0;
|
|
388
|
+
const gap = minInterval !== void 0 ? Math.max(0, getMs(minInterval) - (Date.now() - lastStartTime)) : 0;
|
|
352
389
|
if (gap > 0) {
|
|
353
390
|
waitController = new AbortController();
|
|
354
391
|
const wc = waitController;
|
|
355
|
-
cancellableWait(gap, wc.signal).then(() => {
|
|
356
|
-
if (waitController === wc)
|
|
392
|
+
cancellableWait(Duration.milliseconds(gap), wc.signal).then(() => {
|
|
393
|
+
if (waitController === wc) {
|
|
394
|
+
waitController = void 0;
|
|
395
|
+
}
|
|
357
396
|
startExecution();
|
|
358
397
|
});
|
|
359
398
|
} else {
|
|
@@ -368,7 +407,9 @@ var makeRestartable = (op, minInterval, retryOptions, timeoutOptions) => {
|
|
|
368
407
|
currentController = void 0;
|
|
369
408
|
const r = currentResolve;
|
|
370
409
|
currentResolve = void 0;
|
|
371
|
-
if (currentState.kind !== "Idle")
|
|
410
|
+
if (currentState.kind !== "Idle") {
|
|
411
|
+
emit(_abortedNil);
|
|
412
|
+
}
|
|
372
413
|
r?.(_abortedNil);
|
|
373
414
|
};
|
|
374
415
|
return {
|
|
@@ -379,13 +420,15 @@ var makeRestartable = (op, minInterval, retryOptions, timeoutOptions) => {
|
|
|
379
420
|
abort,
|
|
380
421
|
subscribe: (cb) => {
|
|
381
422
|
subscribers.add(cb);
|
|
382
|
-
if (currentState.kind !== "Idle")
|
|
423
|
+
if (currentState.kind !== "Idle") {
|
|
424
|
+
cb(currentState);
|
|
425
|
+
}
|
|
383
426
|
return () => subscribers.delete(cb);
|
|
384
427
|
},
|
|
385
428
|
reset: () => emit(_idle),
|
|
386
429
|
poll: (input, { interval }) => {
|
|
387
430
|
void run(input);
|
|
388
|
-
const id = setInterval(() => void run(input), interval);
|
|
431
|
+
const id = setInterval(() => void run(input), getMs(interval));
|
|
389
432
|
return () => clearInterval(id);
|
|
390
433
|
}
|
|
391
434
|
};
|
|
@@ -411,19 +454,26 @@ var makeExclusive = (op, cooldown, retryOptions, timeoutOptions) => {
|
|
|
411
454
|
const controller = currentController;
|
|
412
455
|
emit(_pending);
|
|
413
456
|
const onRetrying = retryOptions ? (r) => {
|
|
414
|
-
if (currentController === controller)
|
|
457
|
+
if (currentController === controller) {
|
|
458
|
+
emit(r);
|
|
459
|
+
}
|
|
415
460
|
} : void 0;
|
|
416
461
|
execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
|
|
417
|
-
if (currentController !== controller)
|
|
462
|
+
if (currentController !== controller) {
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
418
465
|
const r = currentResolve;
|
|
419
466
|
currentResolve = void 0;
|
|
420
467
|
currentController = void 0;
|
|
421
468
|
emit(outcome);
|
|
422
469
|
r?.(outcome);
|
|
423
|
-
if (cooldown !== void 0
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
470
|
+
if (cooldown !== void 0) {
|
|
471
|
+
const rawCooldown = getMs(cooldown);
|
|
472
|
+
if (rawCooldown > 0) {
|
|
473
|
+
cooldownTimer = setTimeout(() => {
|
|
474
|
+
cooldownTimer = void 0;
|
|
475
|
+
}, rawCooldown);
|
|
476
|
+
}
|
|
427
477
|
}
|
|
428
478
|
});
|
|
429
479
|
})
|
|
@@ -438,7 +488,9 @@ var makeExclusive = (op, cooldown, retryOptions, timeoutOptions) => {
|
|
|
438
488
|
currentController = void 0;
|
|
439
489
|
const r = currentResolve;
|
|
440
490
|
currentResolve = void 0;
|
|
441
|
-
if (currentState.kind !== "Idle")
|
|
491
|
+
if (currentState.kind !== "Idle") {
|
|
492
|
+
emit(_abortedNil);
|
|
493
|
+
}
|
|
442
494
|
r?.(_abortedNil);
|
|
443
495
|
};
|
|
444
496
|
return {
|
|
@@ -449,13 +501,15 @@ var makeExclusive = (op, cooldown, retryOptions, timeoutOptions) => {
|
|
|
449
501
|
abort,
|
|
450
502
|
subscribe: (cb) => {
|
|
451
503
|
subscribers.add(cb);
|
|
452
|
-
if (currentState.kind !== "Idle")
|
|
504
|
+
if (currentState.kind !== "Idle") {
|
|
505
|
+
cb(currentState);
|
|
506
|
+
}
|
|
453
507
|
return () => subscribers.delete(cb);
|
|
454
508
|
},
|
|
455
509
|
reset: () => emit(_idle),
|
|
456
510
|
poll: (input, { interval }) => {
|
|
457
511
|
void run(input);
|
|
458
|
-
const id = setInterval(() => void run(input), interval);
|
|
512
|
+
const id = setInterval(() => void run(input), getMs(interval));
|
|
459
513
|
return () => clearInterval(id);
|
|
460
514
|
}
|
|
461
515
|
};
|
|
@@ -480,12 +534,16 @@ var makeQueue = (op, maxSize, overflow, concurrency, dedupe, retryOptions, timeo
|
|
|
480
534
|
inflightResolvers.push(resolve);
|
|
481
535
|
emit(_pending);
|
|
482
536
|
const onRetrying = retryOptions ? (r) => {
|
|
483
|
-
if (generation === myGeneration && inflightControllers.has(controller))
|
|
537
|
+
if (generation === myGeneration && inflightControllers.has(controller)) {
|
|
538
|
+
emit(r);
|
|
539
|
+
}
|
|
484
540
|
} : void 0;
|
|
485
541
|
execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
|
|
486
542
|
inflightControllers.delete(controller);
|
|
487
543
|
const idx = inflightResolvers.indexOf(resolve);
|
|
488
|
-
if (idx !== -1)
|
|
544
|
+
if (idx !== -1) {
|
|
545
|
+
inflightResolvers.splice(idx, 1);
|
|
546
|
+
}
|
|
489
547
|
if (generation !== myGeneration) {
|
|
490
548
|
resolve(_abortedNil);
|
|
491
549
|
return;
|
|
@@ -542,7 +600,9 @@ var makeQueue = (op, maxSize, overflow, concurrency, dedupe, retryOptions, timeo
|
|
|
542
600
|
const toResolve = inflightResolvers.splice(0);
|
|
543
601
|
const queuedResolvers = queue.splice(0).map((item) => item.resolve);
|
|
544
602
|
inFlight = 0;
|
|
545
|
-
if (currentState.kind !== "Idle")
|
|
603
|
+
if (currentState.kind !== "Idle") {
|
|
604
|
+
emit(_abortedNil);
|
|
605
|
+
}
|
|
546
606
|
toResolve.forEach((r) => r(_abortedNil));
|
|
547
607
|
queuedResolvers.forEach((r) => r(_abortedNil));
|
|
548
608
|
};
|
|
@@ -554,13 +614,15 @@ var makeQueue = (op, maxSize, overflow, concurrency, dedupe, retryOptions, timeo
|
|
|
554
614
|
abort,
|
|
555
615
|
subscribe: (cb) => {
|
|
556
616
|
subscribers.add(cb);
|
|
557
|
-
if (currentState.kind !== "Idle")
|
|
617
|
+
if (currentState.kind !== "Idle") {
|
|
618
|
+
cb(currentState);
|
|
619
|
+
}
|
|
558
620
|
return () => subscribers.delete(cb);
|
|
559
621
|
},
|
|
560
622
|
reset: () => emit(_idle),
|
|
561
623
|
poll: (input, { interval }) => {
|
|
562
624
|
void run(input);
|
|
563
|
-
const id = setInterval(() => void run(input), interval);
|
|
625
|
+
const id = setInterval(() => void run(input), getMs(interval));
|
|
564
626
|
return () => clearInterval(id);
|
|
565
627
|
}
|
|
566
628
|
};
|
|
@@ -582,10 +644,14 @@ var makeBuffered = (op, size, retryOptions, timeoutOptions) => {
|
|
|
582
644
|
const controller = currentController;
|
|
583
645
|
emit(_pending);
|
|
584
646
|
const onRetrying = retryOptions ? (r) => {
|
|
585
|
-
if (currentController === controller)
|
|
647
|
+
if (currentController === controller) {
|
|
648
|
+
emit(r);
|
|
649
|
+
}
|
|
586
650
|
} : void 0;
|
|
587
651
|
execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
|
|
588
|
-
if (currentController !== controller)
|
|
652
|
+
if (currentController !== controller) {
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
589
655
|
const r = currentResolve;
|
|
590
656
|
currentResolve = void 0;
|
|
591
657
|
currentController = void 0;
|
|
@@ -618,7 +684,9 @@ var makeBuffered = (op, size, retryOptions, timeoutOptions) => {
|
|
|
618
684
|
const cr = currentResolve;
|
|
619
685
|
currentResolve = void 0;
|
|
620
686
|
const bufferedResolvers = buffer.splice(0).map((item) => item.resolve);
|
|
621
|
-
if (currentState.kind !== "Idle")
|
|
687
|
+
if (currentState.kind !== "Idle") {
|
|
688
|
+
emit(_abortedNil);
|
|
689
|
+
}
|
|
622
690
|
cr?.(_abortedNil);
|
|
623
691
|
bufferedResolvers.forEach((r) => r(_abortedNil));
|
|
624
692
|
};
|
|
@@ -630,18 +698,20 @@ var makeBuffered = (op, size, retryOptions, timeoutOptions) => {
|
|
|
630
698
|
abort,
|
|
631
699
|
subscribe: (cb) => {
|
|
632
700
|
subscribers.add(cb);
|
|
633
|
-
if (currentState.kind !== "Idle")
|
|
701
|
+
if (currentState.kind !== "Idle") {
|
|
702
|
+
cb(currentState);
|
|
703
|
+
}
|
|
634
704
|
return () => subscribers.delete(cb);
|
|
635
705
|
},
|
|
636
706
|
reset: () => emit(_idle),
|
|
637
707
|
poll: (input, { interval }) => {
|
|
638
708
|
void run(input);
|
|
639
|
-
const id = setInterval(() => void run(input), interval);
|
|
709
|
+
const id = setInterval(() => void run(input), getMs(interval));
|
|
640
710
|
return () => clearInterval(id);
|
|
641
711
|
}
|
|
642
712
|
};
|
|
643
713
|
};
|
|
644
|
-
var makeDebounced = (op,
|
|
714
|
+
var makeDebounced = (op, duration, leading, maxWait, retryOptions, timeoutOptions) => {
|
|
645
715
|
let currentState = _idle;
|
|
646
716
|
let currentController;
|
|
647
717
|
let currentResolve;
|
|
@@ -662,10 +732,14 @@ var makeDebounced = (op, ms, leading, maxWait, retryOptions, timeoutOptions) =>
|
|
|
662
732
|
leadingResolve = resolve;
|
|
663
733
|
emit(_pending);
|
|
664
734
|
const onRetrying = retryOptions ? (r) => {
|
|
665
|
-
if (leadingController === controller)
|
|
735
|
+
if (leadingController === controller) {
|
|
736
|
+
emit(r);
|
|
737
|
+
}
|
|
666
738
|
} : void 0;
|
|
667
739
|
execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
|
|
668
|
-
if (leadingController !== controller)
|
|
740
|
+
if (leadingController !== controller) {
|
|
741
|
+
return;
|
|
742
|
+
}
|
|
669
743
|
const r = leadingResolve;
|
|
670
744
|
leadingResolve = void 0;
|
|
671
745
|
leadingController = void 0;
|
|
@@ -678,7 +752,9 @@ var makeDebounced = (op, ms, leading, maxWait, retryOptions, timeoutOptions) =>
|
|
|
678
752
|
firstCallAt = 0;
|
|
679
753
|
const capturedResolve = pendingResolve;
|
|
680
754
|
pendingResolve = void 0;
|
|
681
|
-
if (capturedResolve === void 0)
|
|
755
|
+
if (capturedResolve === void 0) {
|
|
756
|
+
return;
|
|
757
|
+
}
|
|
682
758
|
currentResolve = capturedResolve;
|
|
683
759
|
const toRun = pendingInput;
|
|
684
760
|
pendingInput = void 0;
|
|
@@ -686,10 +762,14 @@ var makeDebounced = (op, ms, leading, maxWait, retryOptions, timeoutOptions) =>
|
|
|
686
762
|
const controller = currentController;
|
|
687
763
|
emit(_pending);
|
|
688
764
|
const onRetrying = retryOptions ? (r) => {
|
|
689
|
-
if (currentController === controller)
|
|
765
|
+
if (currentController === controller) {
|
|
766
|
+
emit(r);
|
|
767
|
+
}
|
|
690
768
|
} : void 0;
|
|
691
769
|
execute(op, toRun, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
|
|
692
|
-
if (currentController !== controller)
|
|
770
|
+
if (currentController !== controller) {
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
693
773
|
const r = currentResolve;
|
|
694
774
|
currentResolve = void 0;
|
|
695
775
|
currentController = void 0;
|
|
@@ -698,11 +778,13 @@ var makeDebounced = (op, ms, leading, maxWait, retryOptions, timeoutOptions) =>
|
|
|
698
778
|
});
|
|
699
779
|
};
|
|
700
780
|
const scheduleTrailing = () => {
|
|
701
|
-
if (timerId !== void 0)
|
|
702
|
-
|
|
781
|
+
if (timerId !== void 0) {
|
|
782
|
+
clearTimeout(timerId);
|
|
783
|
+
}
|
|
784
|
+
let delay = getMs(duration);
|
|
703
785
|
if (maxWait !== void 0 && firstCallAt > 0) {
|
|
704
|
-
const maxDelay = firstCallAt + maxWait - Date.now();
|
|
705
|
-
delay = Math.min(
|
|
786
|
+
const maxDelay = firstCallAt + getMs(maxWait) - Date.now();
|
|
787
|
+
delay = Math.min(getMs(duration), Math.max(0, maxDelay));
|
|
706
788
|
}
|
|
707
789
|
timerId = setTimeout(fireTrailing, delay);
|
|
708
790
|
};
|
|
@@ -745,7 +827,9 @@ var makeDebounced = (op, ms, leading, maxWait, retryOptions, timeoutOptions) =>
|
|
|
745
827
|
leadingResolve = void 0;
|
|
746
828
|
leadingController?.abort();
|
|
747
829
|
leadingController = void 0;
|
|
748
|
-
if (currentState.kind !== "Idle")
|
|
830
|
+
if (currentState.kind !== "Idle") {
|
|
831
|
+
emit(_abortedNil);
|
|
832
|
+
}
|
|
749
833
|
pr?.(_abortedNil);
|
|
750
834
|
cr?.(_abortedNil);
|
|
751
835
|
lr?.(_abortedNil);
|
|
@@ -758,18 +842,20 @@ var makeDebounced = (op, ms, leading, maxWait, retryOptions, timeoutOptions) =>
|
|
|
758
842
|
abort,
|
|
759
843
|
subscribe: (cb) => {
|
|
760
844
|
subscribers.add(cb);
|
|
761
|
-
if (currentState.kind !== "Idle")
|
|
845
|
+
if (currentState.kind !== "Idle") {
|
|
846
|
+
cb(currentState);
|
|
847
|
+
}
|
|
762
848
|
return () => subscribers.delete(cb);
|
|
763
849
|
},
|
|
764
850
|
reset: () => emit(_idle),
|
|
765
851
|
poll: (input, { interval }) => {
|
|
766
852
|
void run(input);
|
|
767
|
-
const id = setInterval(() => void run(input), interval);
|
|
853
|
+
const id = setInterval(() => void run(input), getMs(interval));
|
|
768
854
|
return () => clearInterval(id);
|
|
769
855
|
}
|
|
770
856
|
};
|
|
771
857
|
};
|
|
772
|
-
var makeThrottled = (op,
|
|
858
|
+
var makeThrottled = (op, duration, trailing, retryOptions, timeoutOptions) => {
|
|
773
859
|
let currentState = _idle;
|
|
774
860
|
let currentController;
|
|
775
861
|
let currentResolve;
|
|
@@ -787,10 +873,14 @@ var makeThrottled = (op, ms, trailing, retryOptions, timeoutOptions) => {
|
|
|
787
873
|
const controller = currentController;
|
|
788
874
|
emit(_pending);
|
|
789
875
|
const onRetrying = retryOptions ? (r) => {
|
|
790
|
-
if (currentController === controller)
|
|
876
|
+
if (currentController === controller) {
|
|
877
|
+
emit(r);
|
|
878
|
+
}
|
|
791
879
|
} : void 0;
|
|
792
880
|
execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
|
|
793
|
-
if (currentController !== controller)
|
|
881
|
+
if (currentController !== controller) {
|
|
882
|
+
return;
|
|
883
|
+
}
|
|
794
884
|
const r = currentResolve;
|
|
795
885
|
currentResolve = void 0;
|
|
796
886
|
currentController = void 0;
|
|
@@ -809,7 +899,7 @@ var makeThrottled = (op, ms, trailing, retryOptions, timeoutOptions) => {
|
|
|
809
899
|
fireOp(input, resolve);
|
|
810
900
|
startCooldown();
|
|
811
901
|
}
|
|
812
|
-
},
|
|
902
|
+
}, getMs(duration));
|
|
813
903
|
};
|
|
814
904
|
const run = (input) => {
|
|
815
905
|
if (cooldownTimer !== void 0) {
|
|
@@ -844,7 +934,9 @@ var makeThrottled = (op, ms, trailing, retryOptions, timeoutOptions) => {
|
|
|
844
934
|
const pr = pendingResolve;
|
|
845
935
|
pendingResolve = void 0;
|
|
846
936
|
pendingInput = void 0;
|
|
847
|
-
if (currentState.kind !== "Idle")
|
|
937
|
+
if (currentState.kind !== "Idle") {
|
|
938
|
+
emit(_abortedNil);
|
|
939
|
+
}
|
|
848
940
|
cr?.(_abortedNil);
|
|
849
941
|
pr?.(_abortedNil);
|
|
850
942
|
};
|
|
@@ -856,13 +948,15 @@ var makeThrottled = (op, ms, trailing, retryOptions, timeoutOptions) => {
|
|
|
856
948
|
abort,
|
|
857
949
|
subscribe: (cb) => {
|
|
858
950
|
subscribers.add(cb);
|
|
859
|
-
if (currentState.kind !== "Idle")
|
|
951
|
+
if (currentState.kind !== "Idle") {
|
|
952
|
+
cb(currentState);
|
|
953
|
+
}
|
|
860
954
|
return () => subscribers.delete(cb);
|
|
861
955
|
},
|
|
862
956
|
reset: () => emit(_idle),
|
|
863
957
|
poll: (input, { interval }) => {
|
|
864
958
|
void run(input);
|
|
865
|
-
const id = setInterval(() => void run(input), interval);
|
|
959
|
+
const id = setInterval(() => void run(input), getMs(interval));
|
|
866
960
|
return () => clearInterval(id);
|
|
867
961
|
}
|
|
868
962
|
};
|
|
@@ -886,12 +980,16 @@ var makeConcurrent = (op, n, overflow, retryOptions, timeoutOptions) => {
|
|
|
886
980
|
inflightResolvers.push(resolve);
|
|
887
981
|
emit(_pending);
|
|
888
982
|
const onRetrying = retryOptions ? (r) => {
|
|
889
|
-
if (generation === myGeneration && controllers.has(controller))
|
|
983
|
+
if (generation === myGeneration && controllers.has(controller)) {
|
|
984
|
+
emit(r);
|
|
985
|
+
}
|
|
890
986
|
} : void 0;
|
|
891
987
|
execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
|
|
892
988
|
controllers.delete(controller);
|
|
893
989
|
const idx = inflightResolvers.indexOf(resolve);
|
|
894
|
-
if (idx !== -1)
|
|
990
|
+
if (idx !== -1) {
|
|
991
|
+
inflightResolvers.splice(idx, 1);
|
|
992
|
+
}
|
|
895
993
|
if (generation !== myGeneration) {
|
|
896
994
|
resolve(_abortedNil);
|
|
897
995
|
return;
|
|
@@ -931,7 +1029,9 @@ var makeConcurrent = (op, n, overflow, retryOptions, timeoutOptions) => {
|
|
|
931
1029
|
const toResolve = inflightResolvers.splice(0);
|
|
932
1030
|
const queuedResolvers = overflowQueue.splice(0).map((item) => item.resolve);
|
|
933
1031
|
inflight = 0;
|
|
934
|
-
if (currentState.kind !== "Idle")
|
|
1032
|
+
if (currentState.kind !== "Idle") {
|
|
1033
|
+
emit(_abortedNil);
|
|
1034
|
+
}
|
|
935
1035
|
toResolve.forEach((r) => r(_abortedNil));
|
|
936
1036
|
queuedResolvers.forEach((r) => r(_abortedNil));
|
|
937
1037
|
};
|
|
@@ -943,13 +1043,15 @@ var makeConcurrent = (op, n, overflow, retryOptions, timeoutOptions) => {
|
|
|
943
1043
|
abort,
|
|
944
1044
|
subscribe: (cb) => {
|
|
945
1045
|
subscribers.add(cb);
|
|
946
|
-
if (currentState.kind !== "Idle")
|
|
1046
|
+
if (currentState.kind !== "Idle") {
|
|
1047
|
+
cb(currentState);
|
|
1048
|
+
}
|
|
947
1049
|
return () => subscribers.delete(cb);
|
|
948
1050
|
},
|
|
949
1051
|
reset: () => emit(_idle),
|
|
950
1052
|
poll: (input, { interval }) => {
|
|
951
1053
|
void run(input);
|
|
952
|
-
const id = setInterval(() => void run(input), interval);
|
|
1054
|
+
const id = setInterval(() => void run(input), getMs(interval));
|
|
953
1055
|
return () => clearInterval(id);
|
|
954
1056
|
}
|
|
955
1057
|
};
|
|
@@ -980,7 +1082,7 @@ var makeKeyed = (op, keyFn, perKey, timeoutOptions) => {
|
|
|
980
1082
|
slots.set(k, { controller, resolve });
|
|
981
1083
|
stateMap.set(k, _pending);
|
|
982
1084
|
emitSnapshot();
|
|
983
|
-
execute(op, input, controller, void 0, timeoutOptions
|
|
1085
|
+
execute(op, input, controller, void 0, timeoutOptions).then((outcome) => {
|
|
984
1086
|
const slot = slots.get(k);
|
|
985
1087
|
if (!slot || slot.controller !== controller) {
|
|
986
1088
|
resolve(_abortedNil);
|
|
@@ -1013,7 +1115,9 @@ var makeKeyed = (op, keyFn, perKey, timeoutOptions) => {
|
|
|
1013
1115
|
stateMap.set(k, _abortedNil);
|
|
1014
1116
|
}
|
|
1015
1117
|
slots.clear();
|
|
1016
|
-
if (toResolve.length > 0)
|
|
1118
|
+
if (toResolve.length > 0) {
|
|
1119
|
+
emitSnapshot();
|
|
1120
|
+
}
|
|
1017
1121
|
toResolve.forEach((r) => r(_abortedNil));
|
|
1018
1122
|
}
|
|
1019
1123
|
};
|
|
@@ -1025,7 +1129,9 @@ var makeKeyed = (op, keyFn, perKey, timeoutOptions) => {
|
|
|
1025
1129
|
abort,
|
|
1026
1130
|
subscribe: (cb) => {
|
|
1027
1131
|
subscribers.add(cb);
|
|
1028
|
-
if (stateMap.size > 0)
|
|
1132
|
+
if (stateMap.size > 0) {
|
|
1133
|
+
cb(new Map(stateMap));
|
|
1134
|
+
}
|
|
1029
1135
|
return () => subscribers.delete(cb);
|
|
1030
1136
|
},
|
|
1031
1137
|
reset: () => {
|
|
@@ -1034,7 +1140,7 @@ var makeKeyed = (op, keyFn, perKey, timeoutOptions) => {
|
|
|
1034
1140
|
},
|
|
1035
1141
|
poll: (input, { interval }) => {
|
|
1036
1142
|
void run(input);
|
|
1037
|
-
const id = setInterval(() => void run(input), interval);
|
|
1143
|
+
const id = setInterval(() => void run(input), getMs(interval));
|
|
1038
1144
|
return () => clearInterval(id);
|
|
1039
1145
|
}
|
|
1040
1146
|
};
|
|
@@ -1059,10 +1165,14 @@ var makeOnce = (op, retryOptions, timeoutOptions) => {
|
|
|
1059
1165
|
const controller = currentController;
|
|
1060
1166
|
emit(_pending);
|
|
1061
1167
|
const onRetrying = retryOptions ? (r) => {
|
|
1062
|
-
if (currentController === controller)
|
|
1168
|
+
if (currentController === controller) {
|
|
1169
|
+
emit(r);
|
|
1170
|
+
}
|
|
1063
1171
|
} : void 0;
|
|
1064
1172
|
execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
|
|
1065
|
-
if (currentController !== controller)
|
|
1173
|
+
if (currentController !== controller) {
|
|
1174
|
+
return;
|
|
1175
|
+
}
|
|
1066
1176
|
const r = currentResolve;
|
|
1067
1177
|
currentResolve = void 0;
|
|
1068
1178
|
currentController = void 0;
|
|
@@ -1077,7 +1187,9 @@ var makeOnce = (op, retryOptions, timeoutOptions) => {
|
|
|
1077
1187
|
currentController = void 0;
|
|
1078
1188
|
const r = currentResolve;
|
|
1079
1189
|
currentResolve = void 0;
|
|
1080
|
-
if (currentState.kind !== "Idle")
|
|
1190
|
+
if (currentState.kind !== "Idle") {
|
|
1191
|
+
emit(_abortedNil);
|
|
1192
|
+
}
|
|
1081
1193
|
r?.(_abortedNil);
|
|
1082
1194
|
};
|
|
1083
1195
|
return {
|
|
@@ -1088,13 +1200,15 @@ var makeOnce = (op, retryOptions, timeoutOptions) => {
|
|
|
1088
1200
|
abort,
|
|
1089
1201
|
subscribe: (cb) => {
|
|
1090
1202
|
subscribers.add(cb);
|
|
1091
|
-
if (currentState.kind !== "Idle")
|
|
1203
|
+
if (currentState.kind !== "Idle") {
|
|
1204
|
+
cb(currentState);
|
|
1205
|
+
}
|
|
1092
1206
|
return () => subscribers.delete(cb);
|
|
1093
1207
|
},
|
|
1094
1208
|
reset: () => emit(_idle),
|
|
1095
1209
|
poll: (input, { interval }) => {
|
|
1096
1210
|
void run(input);
|
|
1097
|
-
const id = setInterval(() => void run(input), interval);
|
|
1211
|
+
const id = setInterval(() => void run(input), getMs(interval));
|
|
1098
1212
|
return () => clearInterval(id);
|
|
1099
1213
|
}
|
|
1100
1214
|
};
|
|
@@ -1106,62 +1220,80 @@ var Op;
|
|
|
1106
1220
|
Op2.nil = (reason) => ({ kind: "OpNil", reason });
|
|
1107
1221
|
Op2.create = (factory, onError) => ({
|
|
1108
1222
|
_factory: (input, signal) => Deferred.fromPromise(
|
|
1109
|
-
factory(signal)(input).then((value) => Result.ok(value)).catch(
|
|
1223
|
+
factory(signal)(input).then((value) => Result.ok(value)).catch(
|
|
1224
|
+
(error) => signal.aborted ? null : Result.err(onError(error))
|
|
1225
|
+
)
|
|
1110
1226
|
)
|
|
1111
1227
|
});
|
|
1112
|
-
Op2.lift = (f) => (0, Op2.create)(
|
|
1113
|
-
(signal) => (input) => f(input, signal),
|
|
1114
|
-
(e) => e
|
|
1115
|
-
);
|
|
1228
|
+
Op2.lift = (f) => (0, Op2.create)((signal) => (input) => f(input, signal), (e) => e);
|
|
1116
1229
|
Op2.ok = (value) => ({ kind: "OpOk", value });
|
|
1117
|
-
Op2.
|
|
1230
|
+
Op2.err = (error) => ({ kind: "OpErr", error });
|
|
1118
1231
|
Op2.isIdle = (state) => state.kind === "Idle";
|
|
1119
1232
|
Op2.isPending = (state) => state.kind === "Pending";
|
|
1120
1233
|
Op2.isQueued = (state) => state.kind === "Queued";
|
|
1121
1234
|
Op2.isRetrying = (state) => state.kind === "Retrying";
|
|
1122
1235
|
Op2.isOk = (state) => state.kind === "OpOk";
|
|
1123
|
-
Op2.
|
|
1236
|
+
Op2.isErr = (state) => state.kind === "OpErr";
|
|
1124
1237
|
Op2.isNil = (state) => state.kind === "OpNil";
|
|
1125
1238
|
Op2.match = (cases) => (outcome) => {
|
|
1126
|
-
if (outcome.kind === "OpOk")
|
|
1127
|
-
|
|
1239
|
+
if (outcome.kind === "OpOk") {
|
|
1240
|
+
return cases.ok(outcome.value);
|
|
1241
|
+
}
|
|
1242
|
+
if (outcome.kind === "OpErr") {
|
|
1243
|
+
return cases.err(outcome.error);
|
|
1244
|
+
}
|
|
1128
1245
|
return cases.nil();
|
|
1129
1246
|
};
|
|
1130
|
-
Op2.fold = (
|
|
1131
|
-
if (outcome.kind === "OpOk")
|
|
1132
|
-
|
|
1247
|
+
Op2.fold = (onErr, onOk, onNil) => (outcome) => {
|
|
1248
|
+
if (outcome.kind === "OpOk") {
|
|
1249
|
+
return onOk(outcome.value);
|
|
1250
|
+
}
|
|
1251
|
+
if (outcome.kind === "OpErr") {
|
|
1252
|
+
return onErr(outcome.error);
|
|
1253
|
+
}
|
|
1133
1254
|
return onNil();
|
|
1134
1255
|
};
|
|
1135
1256
|
Op2.getOrElse = (defaultValue) => (outcome) => outcome.kind === "OpOk" ? outcome.value : defaultValue();
|
|
1136
1257
|
Op2.map = (f) => (outcome) => outcome.kind === "OpOk" ? (0, Op2.ok)(f(outcome.value)) : outcome;
|
|
1137
|
-
Op2.mapError = (f) => (outcome) => outcome.kind === "
|
|
1258
|
+
Op2.mapError = (f) => (outcome) => outcome.kind === "OpErr" ? (0, Op2.err)(f(outcome.error)) : outcome;
|
|
1138
1259
|
Op2.chain = (f) => (outcome) => outcome.kind === "OpOk" ? f(outcome.value) : outcome;
|
|
1139
1260
|
Op2.tap = (f) => (outcome) => {
|
|
1140
|
-
if (outcome.kind === "OpOk")
|
|
1261
|
+
if (outcome.kind === "OpOk") {
|
|
1262
|
+
f(outcome.value);
|
|
1263
|
+
}
|
|
1141
1264
|
return outcome;
|
|
1142
1265
|
};
|
|
1143
|
-
Op2.recover = (f) => (outcome) => outcome.kind === "
|
|
1266
|
+
Op2.recover = (f) => (outcome) => outcome.kind === "OpErr" ? f(outcome.error) : outcome;
|
|
1144
1267
|
Op2.toResult = (onNil) => (outcome) => {
|
|
1145
|
-
if (outcome.kind === "OpOk")
|
|
1146
|
-
|
|
1147
|
-
|
|
1268
|
+
if (outcome.kind === "OpOk") {
|
|
1269
|
+
return Result.ok(outcome.value);
|
|
1270
|
+
}
|
|
1271
|
+
if (outcome.kind === "OpErr") {
|
|
1272
|
+
return Result.err(outcome.error);
|
|
1273
|
+
}
|
|
1274
|
+
return Result.err(onNil());
|
|
1148
1275
|
};
|
|
1149
1276
|
Op2.toMaybe = (outcome) => outcome.kind === "OpOk" ? Maybe.some(outcome.value) : Maybe.none();
|
|
1150
1277
|
Op2.all = (invocations) => Deferred.fromPromise(Promise.all(invocations.map(Deferred.toPromise)));
|
|
1151
1278
|
Op2.race = (invocations) => Deferred.fromPromise(Promise.race(invocations.map(Deferred.toPromise)));
|
|
1152
1279
|
Op2.wire = (source, f) => source.subscribe((state) => {
|
|
1153
|
-
if ((0, Op2.isOk)(state))
|
|
1280
|
+
if ((0, Op2.isOk)(state)) {
|
|
1281
|
+
f(state.value);
|
|
1282
|
+
}
|
|
1154
1283
|
});
|
|
1155
1284
|
function interpret(op, options) {
|
|
1156
1285
|
const { strategy, retry: retryOptions, timeout: timeoutOptions } = options;
|
|
1157
1286
|
switch (strategy) {
|
|
1158
|
-
case "once":
|
|
1287
|
+
case "once": {
|
|
1159
1288
|
return makeOnce(op, retryOptions, timeoutOptions);
|
|
1160
|
-
|
|
1289
|
+
}
|
|
1290
|
+
case "restartable": {
|
|
1161
1291
|
return makeRestartable(op, options.minInterval, retryOptions, timeoutOptions);
|
|
1162
|
-
|
|
1292
|
+
}
|
|
1293
|
+
case "exclusive": {
|
|
1163
1294
|
return makeExclusive(op, options.cooldown, retryOptions, timeoutOptions);
|
|
1164
|
-
|
|
1295
|
+
}
|
|
1296
|
+
case "queue": {
|
|
1165
1297
|
return makeQueue(
|
|
1166
1298
|
op,
|
|
1167
1299
|
options.maxSize,
|
|
@@ -1171,13 +1303,24 @@ var Op;
|
|
|
1171
1303
|
retryOptions,
|
|
1172
1304
|
timeoutOptions
|
|
1173
1305
|
);
|
|
1174
|
-
|
|
1306
|
+
}
|
|
1307
|
+
case "buffered": {
|
|
1175
1308
|
return makeBuffered(op, options.size, retryOptions, timeoutOptions);
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1309
|
+
}
|
|
1310
|
+
case "debounced": {
|
|
1311
|
+
return makeDebounced(
|
|
1312
|
+
op,
|
|
1313
|
+
options.duration,
|
|
1314
|
+
options.leading ?? false,
|
|
1315
|
+
options.maxWait,
|
|
1316
|
+
retryOptions,
|
|
1317
|
+
timeoutOptions
|
|
1318
|
+
);
|
|
1319
|
+
}
|
|
1320
|
+
case "throttled": {
|
|
1321
|
+
return makeThrottled(op, options.duration, options.trailing ?? false, retryOptions, timeoutOptions);
|
|
1322
|
+
}
|
|
1323
|
+
case "concurrent": {
|
|
1181
1324
|
return makeConcurrent(
|
|
1182
1325
|
op,
|
|
1183
1326
|
options.n ?? 1,
|
|
@@ -1185,8 +1328,10 @@ var Op;
|
|
|
1185
1328
|
retryOptions,
|
|
1186
1329
|
timeoutOptions
|
|
1187
1330
|
);
|
|
1188
|
-
|
|
1331
|
+
}
|
|
1332
|
+
case "keyed": {
|
|
1189
1333
|
return makeKeyed(op, options.key ?? ((i) => i), options.perKey ?? "exclusive", timeoutOptions);
|
|
1334
|
+
}
|
|
1190
1335
|
}
|
|
1191
1336
|
}
|
|
1192
1337
|
Op2.interpret = interpret;
|
|
@@ -1196,22 +1341,18 @@ var Op;
|
|
|
1196
1341
|
var Optional;
|
|
1197
1342
|
((Optional2) => {
|
|
1198
1343
|
Optional2.make = (get2, set2) => ({ get: get2, set: set2 });
|
|
1199
|
-
Optional2.prop = () => (key) => (0, Optional2.make)(
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
Optional2.index = (i) => (0, Optional2.make)(
|
|
1207
|
-
(arr) => i >= 0 && i < arr.length ? Maybe.some(arr[i]) : Maybe.none(),
|
|
1208
|
-
(a) => (arr) => {
|
|
1209
|
-
if (i < 0 || i >= arr.length) return arr;
|
|
1210
|
-
const copy = [...arr];
|
|
1211
|
-
copy[i] = a;
|
|
1212
|
-
return copy;
|
|
1344
|
+
Optional2.prop = () => (key) => (0, Optional2.make)((s) => {
|
|
1345
|
+
const val = s[key];
|
|
1346
|
+
return val !== null && val !== void 0 ? Maybe.some(val) : Maybe.none();
|
|
1347
|
+
}, (a) => (s) => ({ ...s, [key]: a }));
|
|
1348
|
+
Optional2.index = (i) => (0, Optional2.make)((arr) => i >= 0 && i < arr.length ? Maybe.some(arr[i]) : Maybe.none(), (a) => (arr) => {
|
|
1349
|
+
if (i < 0 || i >= arr.length) {
|
|
1350
|
+
return arr;
|
|
1213
1351
|
}
|
|
1214
|
-
|
|
1352
|
+
const copy = [...arr];
|
|
1353
|
+
copy[i] = a;
|
|
1354
|
+
return copy;
|
|
1355
|
+
});
|
|
1215
1356
|
Optional2.get = (opt) => (s) => opt.get(s);
|
|
1216
1357
|
Optional2.set = (opt) => (a) => (s) => opt.set(a)(s);
|
|
1217
1358
|
Optional2.modify = (opt) => (f) => (s) => {
|
|
@@ -1230,26 +1371,20 @@ var Optional;
|
|
|
1230
1371
|
const val = opt.get(s);
|
|
1231
1372
|
return val.kind === "Some" ? cases.some(val.value) : cases.none();
|
|
1232
1373
|
};
|
|
1233
|
-
Optional2.andThen = (inner) => (outer) => (0, Optional2.make)(
|
|
1234
|
-
(s)
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
(b)
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
(s)
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
},
|
|
1248
|
-
(b) => (s) => {
|
|
1249
|
-
const mid = outer.get(s);
|
|
1250
|
-
return mid.kind === "None" ? s : outer.set(inner.set(b)(mid.value))(s);
|
|
1251
|
-
}
|
|
1252
|
-
);
|
|
1374
|
+
Optional2.andThen = (inner) => (outer) => (0, Optional2.make)((s) => {
|
|
1375
|
+
const mid = outer.get(s);
|
|
1376
|
+
return mid.kind === "None" ? Maybe.none() : inner.get(mid.value);
|
|
1377
|
+
}, (b) => (s) => {
|
|
1378
|
+
const mid = outer.get(s);
|
|
1379
|
+
return mid.kind === "None" ? s : outer.set(inner.set(b)(mid.value))(s);
|
|
1380
|
+
});
|
|
1381
|
+
Optional2.andThenLens = (inner) => (outer) => (0, Optional2.make)((s) => {
|
|
1382
|
+
const mid = outer.get(s);
|
|
1383
|
+
return mid.kind === "None" ? Maybe.none() : Maybe.some(inner.get(mid.value));
|
|
1384
|
+
}, (b) => (s) => {
|
|
1385
|
+
const mid = outer.get(s);
|
|
1386
|
+
return mid.kind === "None" ? s : outer.set(inner.set(b)(mid.value))(s);
|
|
1387
|
+
});
|
|
1253
1388
|
})(Optional || (Optional = {}));
|
|
1254
1389
|
|
|
1255
1390
|
// src/Core/Ordering.ts
|
|
@@ -1304,7 +1439,7 @@ var Refinement;
|
|
|
1304
1439
|
Refinement2.and = (second) => (first) => (a) => first(a) && second(a);
|
|
1305
1440
|
Refinement2.or = (second) => (first) => (a) => first(a) || second(a);
|
|
1306
1441
|
Refinement2.toFilter = (r) => (a) => r(a) ? Maybe.some(a) : Maybe.none();
|
|
1307
|
-
Refinement2.toResult = (r, onFail) => (a) => r(a) ? Result.ok(a) : Result.
|
|
1442
|
+
Refinement2.toResult = (r, onFail) => (a) => r(a) ? Result.ok(a) : Result.err(onFail(a));
|
|
1308
1443
|
})(Refinement || (Refinement = {}));
|
|
1309
1444
|
|
|
1310
1445
|
// src/Core/RemoteData.ts
|
|
@@ -1314,14 +1449,8 @@ var RemoteData;
|
|
|
1314
1449
|
((RemoteData2) => {
|
|
1315
1450
|
RemoteData2.notAsked = () => _notAsked;
|
|
1316
1451
|
RemoteData2.loading = () => _loading;
|
|
1317
|
-
RemoteData2.failure = (error) => ({
|
|
1318
|
-
|
|
1319
|
-
error
|
|
1320
|
-
});
|
|
1321
|
-
RemoteData2.success = (value) => ({
|
|
1322
|
-
kind: "Success",
|
|
1323
|
-
value
|
|
1324
|
-
});
|
|
1452
|
+
RemoteData2.failure = (error) => ({ kind: "Failure", error });
|
|
1453
|
+
RemoteData2.success = (value) => ({ kind: "Success", value });
|
|
1325
1454
|
RemoteData2.isNotAsked = (data) => data.kind === "NotAsked";
|
|
1326
1455
|
RemoteData2.isLoading = (data) => data.kind === "Loading";
|
|
1327
1456
|
RemoteData2.isFailure = (data) => data.kind === "Failure";
|
|
@@ -1333,80 +1462,73 @@ var RemoteData;
|
|
|
1333
1462
|
if ((0, RemoteData2.isSuccess)(data) && (0, RemoteData2.isSuccess)(arg)) {
|
|
1334
1463
|
return (0, RemoteData2.success)(data.value(arg.value));
|
|
1335
1464
|
}
|
|
1336
|
-
if ((0, RemoteData2.isFailure)(data))
|
|
1337
|
-
|
|
1338
|
-
|
|
1465
|
+
if ((0, RemoteData2.isFailure)(data)) {
|
|
1466
|
+
return data;
|
|
1467
|
+
}
|
|
1468
|
+
if ((0, RemoteData2.isFailure)(arg)) {
|
|
1469
|
+
return arg;
|
|
1470
|
+
}
|
|
1471
|
+
if ((0, RemoteData2.isLoading)(data) || (0, RemoteData2.isLoading)(arg)) {
|
|
1472
|
+
return (0, RemoteData2.loading)();
|
|
1473
|
+
}
|
|
1339
1474
|
return (0, RemoteData2.notAsked)();
|
|
1340
1475
|
};
|
|
1341
1476
|
RemoteData2.fold = (onNotAsked, onLoading, onFailure, onSuccess) => (data) => {
|
|
1342
1477
|
switch (data.kind) {
|
|
1343
|
-
case "NotAsked":
|
|
1478
|
+
case "NotAsked": {
|
|
1344
1479
|
return onNotAsked();
|
|
1345
|
-
|
|
1480
|
+
}
|
|
1481
|
+
case "Loading": {
|
|
1346
1482
|
return onLoading();
|
|
1347
|
-
|
|
1483
|
+
}
|
|
1484
|
+
case "Failure": {
|
|
1348
1485
|
return onFailure(data.error);
|
|
1349
|
-
|
|
1486
|
+
}
|
|
1487
|
+
case "Success": {
|
|
1350
1488
|
return onSuccess(data.value);
|
|
1489
|
+
}
|
|
1351
1490
|
}
|
|
1352
1491
|
};
|
|
1353
1492
|
RemoteData2.match = (cases) => (data) => {
|
|
1354
1493
|
switch (data.kind) {
|
|
1355
|
-
case "NotAsked":
|
|
1494
|
+
case "NotAsked": {
|
|
1356
1495
|
return cases.notAsked();
|
|
1357
|
-
|
|
1496
|
+
}
|
|
1497
|
+
case "Loading": {
|
|
1358
1498
|
return cases.loading();
|
|
1359
|
-
|
|
1499
|
+
}
|
|
1500
|
+
case "Failure": {
|
|
1360
1501
|
return cases.failure(data.error);
|
|
1361
|
-
|
|
1502
|
+
}
|
|
1503
|
+
case "Success": {
|
|
1362
1504
|
return cases.success(data.value);
|
|
1505
|
+
}
|
|
1363
1506
|
}
|
|
1364
1507
|
};
|
|
1365
1508
|
RemoteData2.getOrElse = (defaultValue) => (data) => (0, RemoteData2.isSuccess)(data) ? data.value : defaultValue();
|
|
1366
1509
|
RemoteData2.tap = (f) => (data) => {
|
|
1367
|
-
if ((0, RemoteData2.isSuccess)(data))
|
|
1510
|
+
if ((0, RemoteData2.isSuccess)(data)) {
|
|
1511
|
+
f(data.value);
|
|
1512
|
+
}
|
|
1368
1513
|
return data;
|
|
1369
1514
|
};
|
|
1370
1515
|
RemoteData2.tapError = (f) => (data) => {
|
|
1371
|
-
if ((0, RemoteData2.isFailure)(data))
|
|
1516
|
+
if ((0, RemoteData2.isFailure)(data)) {
|
|
1517
|
+
f(data.error);
|
|
1518
|
+
}
|
|
1372
1519
|
return data;
|
|
1373
1520
|
};
|
|
1374
1521
|
RemoteData2.recover = (fallback) => (data) => (0, RemoteData2.isFailure)(data) ? fallback(data.error) : data;
|
|
1375
1522
|
RemoteData2.toMaybe = (data) => (0, RemoteData2.isSuccess)(data) ? Maybe.some(data.value) : Maybe.none();
|
|
1376
|
-
RemoteData2.toResult = (onNotReady) => (data) => (0, RemoteData2.isSuccess)(data) ? Result.ok(data.value) : Result.
|
|
1523
|
+
RemoteData2.toResult = (onNotReady) => (data) => (0, RemoteData2.isSuccess)(data) ? Result.ok(data.value) : Result.err((0, RemoteData2.isFailure)(data) ? data.error : onNotReady());
|
|
1377
1524
|
RemoteData2.fromResult = (data) => Result.isOk(data) ? (0, RemoteData2.success)(data.value) : (0, RemoteData2.failure)(data.error);
|
|
1378
1525
|
RemoteData2.fromMaybe = (onNone) => (data) => Maybe.isSome(data) ? (0, RemoteData2.success)(data.value) : (0, RemoteData2.failure)(onNone());
|
|
1379
1526
|
RemoteData2.filter = (pred, onFalse) => (data) => (0, RemoteData2.isSuccess)(data) ? pred(data.value) ? data : (0, RemoteData2.failure)(onFalse(data.value)) : data;
|
|
1380
1527
|
})(RemoteData || (RemoteData = {}));
|
|
1381
1528
|
|
|
1382
|
-
// src/Types/Brand.ts
|
|
1383
|
-
var Brand;
|
|
1384
|
-
((Brand2) => {
|
|
1385
|
-
Brand2.wrap = () => (value) => value;
|
|
1386
|
-
Brand2.unwrap = (branded) => branded;
|
|
1387
|
-
})(Brand || (Brand = {}));
|
|
1388
|
-
|
|
1389
|
-
// src/Types/Duration.ts
|
|
1390
|
-
var Duration;
|
|
1391
|
-
((Duration2) => {
|
|
1392
|
-
const wrap = Brand.wrap();
|
|
1393
|
-
Duration2.milliseconds = (ms) => wrap(ms);
|
|
1394
|
-
Duration2.seconds = (s) => wrap(s * 1e3);
|
|
1395
|
-
Duration2.minutes = (m) => wrap(m * 60 * 1e3);
|
|
1396
|
-
Duration2.hours = (h) => wrap(h * 60 * 60 * 1e3);
|
|
1397
|
-
Duration2.days = (d) => wrap(d * 24 * 60 * 60 * 1e3);
|
|
1398
|
-
Duration2.toMilliseconds = (d) => Brand.unwrap(d);
|
|
1399
|
-
Duration2.toSeconds = (d) => Brand.unwrap(d) / 1e3;
|
|
1400
|
-
Duration2.toMinutes = (d) => Brand.unwrap(d) / (60 * 1e3);
|
|
1401
|
-
Duration2.toHours = (d) => Brand.unwrap(d) / (60 * 60 * 1e3);
|
|
1402
|
-
Duration2.toDays = (d) => Brand.unwrap(d) / (24 * 60 * 60 * 1e3);
|
|
1403
|
-
Duration2.add = (other) => (self) => wrap(Brand.unwrap(self) + Brand.unwrap(other));
|
|
1404
|
-
Duration2.subtract = (other) => (self) => wrap(Brand.unwrap(self) - Brand.unwrap(other));
|
|
1405
|
-
})(Duration || (Duration = {}));
|
|
1406
|
-
|
|
1407
1529
|
// src/Core/Task.ts
|
|
1408
1530
|
var toPromise = (task, signal) => Deferred.toPromise(task(signal));
|
|
1409
|
-
var
|
|
1531
|
+
var getMs2 = (duration) => Duration.toMilliseconds(duration);
|
|
1410
1532
|
var Task;
|
|
1411
1533
|
((Task2) => {
|
|
1412
1534
|
Task2.resolve = (value) => () => Deferred.fromPromise(Promise.resolve(value));
|
|
@@ -1414,12 +1536,7 @@ var Task;
|
|
|
1414
1536
|
Task2.fromSync = (f) => () => Deferred.fromPromise(Promise.resolve(f()));
|
|
1415
1537
|
Task2.map = (f) => (data) => (0, Task2.from)((signal) => toPromise(data, signal).then(f));
|
|
1416
1538
|
Task2.chain = (f) => (data) => (0, Task2.from)((signal) => toPromise(data, signal).then((a) => toPromise(f(a), signal)));
|
|
1417
|
-
Task2.ap = (arg) => (data) => (0, Task2.from)(
|
|
1418
|
-
(signal) => Promise.all([
|
|
1419
|
-
toPromise(data, signal),
|
|
1420
|
-
toPromise(arg, signal)
|
|
1421
|
-
]).then(([f, a]) => f(a))
|
|
1422
|
-
);
|
|
1539
|
+
Task2.ap = (arg) => (data) => (0, Task2.from)((signal) => Promise.all([toPromise(data, signal), toPromise(arg, signal)]).then(([f, a]) => f(a)));
|
|
1423
1540
|
Task2.tap = (f) => (data) => (0, Task2.from)(
|
|
1424
1541
|
(signal) => toPromise(data, signal).then((a) => {
|
|
1425
1542
|
f(a);
|
|
@@ -1429,35 +1546,39 @@ var Task;
|
|
|
1429
1546
|
Task2.all = (tasks) => (0, Task2.from)(
|
|
1430
1547
|
(signal) => Promise.all(tasks.map((t) => toPromise(t, signal)))
|
|
1431
1548
|
);
|
|
1432
|
-
Task2.delay = (
|
|
1433
|
-
(signal) => new Promise((
|
|
1434
|
-
let timerId
|
|
1549
|
+
Task2.delay = (duration) => (data) => (0, Task2.from)(
|
|
1550
|
+
(signal) => new Promise((res) => {
|
|
1551
|
+
let timerId;
|
|
1435
1552
|
const onAbort = () => {
|
|
1436
1553
|
if (timerId !== void 0) {
|
|
1437
1554
|
clearTimeout(timerId);
|
|
1438
1555
|
}
|
|
1439
|
-
|
|
1556
|
+
res(toPromise(data, signal));
|
|
1440
1557
|
};
|
|
1441
1558
|
if (signal) {
|
|
1442
1559
|
if (signal.aborted) {
|
|
1443
|
-
return
|
|
1560
|
+
return res(toPromise(data, signal));
|
|
1444
1561
|
}
|
|
1445
1562
|
signal.addEventListener("abort", onAbort, { once: true });
|
|
1446
1563
|
}
|
|
1447
1564
|
timerId = setTimeout(() => {
|
|
1448
1565
|
signal?.removeEventListener("abort", onAbort);
|
|
1449
|
-
|
|
1450
|
-
},
|
|
1566
|
+
res(toPromise(data, signal));
|
|
1567
|
+
}, getMs2(duration));
|
|
1451
1568
|
})
|
|
1452
1569
|
);
|
|
1453
1570
|
Task2.repeat = (options) => (task) => (0, Task2.from)((signal) => {
|
|
1454
|
-
const { times, delay:
|
|
1455
|
-
if (times <= 0)
|
|
1571
|
+
const { times, delay: delayDuration } = options;
|
|
1572
|
+
if (times <= 0) {
|
|
1573
|
+
return Promise.resolve([]);
|
|
1574
|
+
}
|
|
1456
1575
|
const results = [];
|
|
1457
1576
|
const wait = () => {
|
|
1458
|
-
if (signal?.aborted)
|
|
1577
|
+
if (signal?.aborted) {
|
|
1578
|
+
return Promise.resolve();
|
|
1579
|
+
}
|
|
1459
1580
|
return new Promise((r) => {
|
|
1460
|
-
let timerId
|
|
1581
|
+
let timerId;
|
|
1461
1582
|
const onAbort = () => {
|
|
1462
1583
|
if (timerId !== void 0) {
|
|
1463
1584
|
clearTimeout(timerId);
|
|
@@ -1470,7 +1591,7 @@ var Task;
|
|
|
1470
1591
|
timerId = setTimeout(() => {
|
|
1471
1592
|
signal?.removeEventListener("abort", onAbort);
|
|
1472
1593
|
r();
|
|
1473
|
-
},
|
|
1594
|
+
}, delayDuration ? getMs2(delayDuration) : 0);
|
|
1474
1595
|
});
|
|
1475
1596
|
};
|
|
1476
1597
|
const run2 = (left) => {
|
|
@@ -1479,18 +1600,22 @@ var Task;
|
|
|
1479
1600
|
}
|
|
1480
1601
|
return toPromise(task, signal).then((a) => {
|
|
1481
1602
|
results.push(a);
|
|
1482
|
-
if (left <= 1 || signal?.aborted)
|
|
1603
|
+
if (left <= 1 || signal?.aborted) {
|
|
1604
|
+
return results;
|
|
1605
|
+
}
|
|
1483
1606
|
return wait().then(() => run2(left - 1));
|
|
1484
1607
|
});
|
|
1485
1608
|
};
|
|
1486
1609
|
return run2(times);
|
|
1487
1610
|
});
|
|
1488
1611
|
Task2.repeatUntil = (options) => (task) => (0, Task2.from)((signal) => {
|
|
1489
|
-
const { when: predicate, delay:
|
|
1612
|
+
const { when: predicate, delay: delayDuration, maxAttempts } = options;
|
|
1490
1613
|
const wait = () => {
|
|
1491
|
-
if (signal?.aborted)
|
|
1614
|
+
if (signal?.aborted) {
|
|
1615
|
+
return Promise.resolve();
|
|
1616
|
+
}
|
|
1492
1617
|
return new Promise((r) => {
|
|
1493
|
-
let timerId
|
|
1618
|
+
let timerId;
|
|
1494
1619
|
const onAbort = () => {
|
|
1495
1620
|
if (timerId !== void 0) {
|
|
1496
1621
|
clearTimeout(timerId);
|
|
@@ -1503,7 +1628,7 @@ var Task;
|
|
|
1503
1628
|
timerId = setTimeout(() => {
|
|
1504
1629
|
signal?.removeEventListener("abort", onAbort);
|
|
1505
1630
|
r();
|
|
1506
|
-
},
|
|
1631
|
+
}, delayDuration ? getMs2(delayDuration) : 0);
|
|
1507
1632
|
});
|
|
1508
1633
|
};
|
|
1509
1634
|
const run2 = (attempt, lastValue) => {
|
|
@@ -1511,9 +1636,15 @@ var Task;
|
|
|
1511
1636
|
return Promise.resolve(lastValue);
|
|
1512
1637
|
}
|
|
1513
1638
|
return toPromise(task, signal).then((a) => {
|
|
1514
|
-
if (predicate(a))
|
|
1515
|
-
|
|
1516
|
-
|
|
1639
|
+
if (predicate(a)) {
|
|
1640
|
+
return a;
|
|
1641
|
+
}
|
|
1642
|
+
if (maxAttempts !== void 0 && attempt >= maxAttempts) {
|
|
1643
|
+
return a;
|
|
1644
|
+
}
|
|
1645
|
+
if (signal?.aborted) {
|
|
1646
|
+
return a;
|
|
1647
|
+
}
|
|
1517
1648
|
return wait().then(() => run2(attempt + 1, a));
|
|
1518
1649
|
});
|
|
1519
1650
|
};
|
|
@@ -1527,7 +1658,9 @@ var Task;
|
|
|
1527
1658
|
return (0, Task2.from)((outerSignal) => {
|
|
1528
1659
|
const controllers = tasks.map(() => new AbortController());
|
|
1529
1660
|
const onOuterAbort = () => {
|
|
1530
|
-
for (const ctrl of controllers)
|
|
1661
|
+
for (const ctrl of controllers) {
|
|
1662
|
+
ctrl.abort();
|
|
1663
|
+
}
|
|
1531
1664
|
};
|
|
1532
1665
|
if (outerSignal) {
|
|
1533
1666
|
if (outerSignal.aborted) {
|
|
@@ -1562,19 +1695,19 @@ var Task;
|
|
|
1562
1695
|
}
|
|
1563
1696
|
return results;
|
|
1564
1697
|
});
|
|
1565
|
-
Task2.timeout = (
|
|
1698
|
+
Task2.timeout = (duration, onTimeout) => (task) => (0, Task2.from)((outerSignal) => {
|
|
1566
1699
|
const controller = new AbortController();
|
|
1567
1700
|
let timerId;
|
|
1568
|
-
|
|
1701
|
+
function cleanUp() {
|
|
1569
1702
|
if (timerId !== void 0) {
|
|
1570
1703
|
clearTimeout(timerId);
|
|
1571
1704
|
}
|
|
1572
1705
|
outerSignal?.removeEventListener("abort", onOuterAbort);
|
|
1573
|
-
}
|
|
1574
|
-
|
|
1706
|
+
}
|
|
1707
|
+
function onOuterAbort() {
|
|
1575
1708
|
cleanUp();
|
|
1576
1709
|
controller.abort();
|
|
1577
|
-
}
|
|
1710
|
+
}
|
|
1578
1711
|
if (outerSignal) {
|
|
1579
1712
|
if (outerSignal.aborted) {
|
|
1580
1713
|
controller.abort();
|
|
@@ -1587,12 +1720,12 @@ var Task;
|
|
|
1587
1720
|
cleanUp();
|
|
1588
1721
|
return Result.ok(a);
|
|
1589
1722
|
}),
|
|
1590
|
-
new Promise((
|
|
1723
|
+
new Promise((res) => {
|
|
1591
1724
|
timerId = setTimeout(() => {
|
|
1592
1725
|
controller.abort();
|
|
1593
1726
|
cleanUp();
|
|
1594
|
-
|
|
1595
|
-
},
|
|
1727
|
+
res(Result.err(onTimeout()));
|
|
1728
|
+
}, getMs2(duration));
|
|
1596
1729
|
})
|
|
1597
1730
|
]);
|
|
1598
1731
|
});
|
|
@@ -1620,14 +1753,19 @@ var Task;
|
|
|
1620
1753
|
// src/Core/Resource.ts
|
|
1621
1754
|
var Resource;
|
|
1622
1755
|
((Resource2) => {
|
|
1623
|
-
Resource2.make = (acquire, release) => ({
|
|
1756
|
+
Resource2.make = (acquire, release) => ({
|
|
1757
|
+
acquire,
|
|
1758
|
+
release
|
|
1759
|
+
});
|
|
1624
1760
|
Resource2.fromTask = (acquire, release) => ({
|
|
1625
1761
|
acquire: Task.map((a) => Result.ok(a))(acquire),
|
|
1626
1762
|
release
|
|
1627
1763
|
});
|
|
1628
1764
|
Resource2.use = (f) => (resource) => Task.from(
|
|
1629
1765
|
(signal) => Deferred.toPromise(resource.acquire(signal)).then(async (acquired) => {
|
|
1630
|
-
if (Result.
|
|
1766
|
+
if (Result.isErr(acquired)) {
|
|
1767
|
+
return acquired;
|
|
1768
|
+
}
|
|
1631
1769
|
const a = acquired.value;
|
|
1632
1770
|
try {
|
|
1633
1771
|
const usageResult = await Deferred.toPromise(f(a)(signal));
|
|
@@ -1640,10 +1778,12 @@ var Resource;
|
|
|
1640
1778
|
Resource2.combine = (resourceA, resourceB) => ({
|
|
1641
1779
|
acquire: Task.from(
|
|
1642
1780
|
(signal) => Deferred.toPromise(resourceA.acquire(signal)).then(async (acquiredA) => {
|
|
1643
|
-
if (Result.
|
|
1781
|
+
if (Result.isErr(acquiredA)) {
|
|
1782
|
+
return acquiredA;
|
|
1783
|
+
}
|
|
1644
1784
|
const a = acquiredA.value;
|
|
1645
1785
|
const acquiredB = await Deferred.toPromise(resourceB.acquire(signal));
|
|
1646
|
-
if (Result.
|
|
1786
|
+
if (Result.isErr(acquiredB)) {
|
|
1647
1787
|
await Deferred.toPromise(resourceA.release(a)(signal));
|
|
1648
1788
|
return acquiredB;
|
|
1649
1789
|
}
|
|
@@ -1696,16 +1836,13 @@ var TaskMaybe;
|
|
|
1696
1836
|
TaskMaybe2.fromNullable = (value) => Task.resolve(Maybe.fromNullable(value));
|
|
1697
1837
|
TaskMaybe2.fromResult = (result) => Task.resolve(Result.toMaybe(result));
|
|
1698
1838
|
TaskMaybe2.fromTask = (task) => Task.map(Maybe.some)(task);
|
|
1699
|
-
TaskMaybe2.tryCatch = (f) => Task.from(
|
|
1700
|
-
(signal) => f(signal).then(Maybe.some).catch(() => Maybe.none())
|
|
1701
|
-
);
|
|
1839
|
+
TaskMaybe2.tryCatch = (f) => Task.from((signal) => f(signal).then(Maybe.some).catch(() => Maybe.none()));
|
|
1702
1840
|
TaskMaybe2.map = (f) => (data) => Task.map(Maybe.map(f))(data);
|
|
1703
1841
|
TaskMaybe2.chain = (f) => (data) => Task.chain((option) => Maybe.isSome(option) ? f(option.value) : Task.resolve(Maybe.none()))(data);
|
|
1704
1842
|
TaskMaybe2.ap = (arg) => (data) => Task.from(
|
|
1705
|
-
(signal) => Promise.all([
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
]).then(([of_, oa]) => Maybe.ap(oa)(of_))
|
|
1843
|
+
(signal) => Promise.all([Deferred.toPromise(data(signal)), Deferred.toPromise(arg(signal))]).then(
|
|
1844
|
+
([of_, oa]) => Maybe.ap(oa)(of_)
|
|
1845
|
+
)
|
|
1709
1846
|
);
|
|
1710
1847
|
TaskMaybe2.fold = (onNone, onSome) => (data) => Task.map(Maybe.fold(onNone, onSome))(data);
|
|
1711
1848
|
TaskMaybe2.match = (cases) => (data) => Task.map(Maybe.match(cases))(data);
|
|
@@ -1719,36 +1856,29 @@ var TaskMaybe;
|
|
|
1719
1856
|
var TaskResult;
|
|
1720
1857
|
((TaskResult2) => {
|
|
1721
1858
|
TaskResult2.ok = (value) => Task.resolve(Result.ok(value));
|
|
1722
|
-
TaskResult2.err = (error) => Task.resolve(Result.
|
|
1723
|
-
TaskResult2.fromNullable = (onNull) => (value) => Task.resolve(value === null || value === void 0 ? Result.
|
|
1724
|
-
TaskResult2.fromMaybe = (onNone) => (maybe) => Task.resolve(Maybe.isNone(maybe) ? Result.
|
|
1859
|
+
TaskResult2.err = (error) => Task.resolve(Result.err(error));
|
|
1860
|
+
TaskResult2.fromNullable = (onNull) => (value) => Task.resolve(value === null || value === void 0 ? Result.err(onNull()) : Result.ok(value));
|
|
1861
|
+
TaskResult2.fromMaybe = (onNone) => (maybe) => Task.resolve(Maybe.isNone(maybe) ? Result.err(onNone()) : Result.ok(maybe.value));
|
|
1725
1862
|
TaskResult2.fromResult = (result) => Task.resolve(result);
|
|
1726
|
-
TaskResult2.fromThrowable = (f, onError) => (...args) => Task.from(
|
|
1727
|
-
|
|
1728
|
-
);
|
|
1729
|
-
TaskResult2.tryCatch = (f, onError) => Task.from(
|
|
1730
|
-
(signal) => f(signal).then(Result.ok).catch((e) => Result.error(onError(e)))
|
|
1731
|
-
);
|
|
1863
|
+
TaskResult2.fromThrowable = (f, onError) => (...args) => Task.from(() => f(...args).then(Result.ok).catch((error) => Result.err(onError(error))));
|
|
1864
|
+
TaskResult2.tryCatch = (f, onError) => Task.from((signal) => f(signal).then(Result.ok).catch((error) => Result.err(onError(error))));
|
|
1732
1865
|
TaskResult2.map = (f) => (data) => Task.map(Result.map(f))(data);
|
|
1733
1866
|
TaskResult2.mapError = (f) => (data) => Task.map(Result.mapError(f))(data);
|
|
1734
|
-
TaskResult2.chain = (f) => (data) => Task.chain(
|
|
1735
|
-
(result) => Result.isOk(result) ? f(result.value) : Task.resolve(Result.error(result.error))
|
|
1736
|
-
)(
|
|
1867
|
+
TaskResult2.chain = (f) => (data) => Task.chain((result) => Result.isOk(result) ? f(result.value) : Task.resolve(Result.err(result.error)))(
|
|
1737
1868
|
data
|
|
1738
1869
|
);
|
|
1739
1870
|
TaskResult2.fold = (onErr, onOk) => (data) => Task.map(Result.fold(onErr, onOk))(data);
|
|
1740
1871
|
TaskResult2.match = (cases) => (data) => Task.map(Result.match(cases))(data);
|
|
1741
1872
|
TaskResult2.recover = (fallback) => (data) => Task.chain(
|
|
1742
|
-
(result) => Result.
|
|
1873
|
+
(result) => Result.isErr(result) ? fallback(result.error) : Task.resolve(result)
|
|
1743
1874
|
)(data);
|
|
1744
1875
|
TaskResult2.getOrElse = (defaultValue) => (data) => Task.map(Result.getOrElse(defaultValue))(data);
|
|
1745
1876
|
TaskResult2.tap = (f) => (data) => Task.map(Result.tap(f))(data);
|
|
1746
1877
|
TaskResult2.tapError = (f) => (data) => Task.map(Result.tapError(f))(data);
|
|
1747
1878
|
TaskResult2.ap = (arg) => (data) => Task.from(
|
|
1748
|
-
(signal) => Promise.all([
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
]).then(([of_, oa]) => Result.ap(oa)(of_))
|
|
1879
|
+
(signal) => Promise.all([Deferred.toPromise(data(signal)), Deferred.toPromise(arg(signal))]).then(
|
|
1880
|
+
([of_, oa]) => Result.ap(oa)(of_)
|
|
1881
|
+
)
|
|
1752
1882
|
);
|
|
1753
1883
|
TaskResult2.run = (signal) => (task) => Deferred.toPromise(task(signal));
|
|
1754
1884
|
})(TaskResult || (TaskResult = {}));
|
|
@@ -1756,102 +1886,97 @@ var TaskResult;
|
|
|
1756
1886
|
// src/Core/Validation.ts
|
|
1757
1887
|
var Validation;
|
|
1758
1888
|
((Validation2) => {
|
|
1759
|
-
Validation2.
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
Validation2.
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
Validation2.
|
|
1768
|
-
|
|
1769
|
-
errors
|
|
1770
|
-
});
|
|
1771
|
-
Validation2.isValid = (data) => data.kind === "Valid";
|
|
1772
|
-
Validation2.isInvalid = (data) => data.kind === "Invalid";
|
|
1773
|
-
Validation2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Validation2.valid)(a) : (0, Validation2.invalid)(onFalse(a));
|
|
1774
|
-
Validation2.fromNullable = (onNull) => (value) => value === null || value === void 0 ? (0, Validation2.invalid)(onNull()) : (0, Validation2.valid)(value);
|
|
1775
|
-
Validation2.fromMaybe = (onNone) => (maybe) => Maybe.isNone(maybe) ? (0, Validation2.invalid)(onNone()) : (0, Validation2.valid)(maybe.value);
|
|
1776
|
-
Validation2.map = (f) => (data) => (0, Validation2.isValid)(data) ? (0, Validation2.valid)(f(data.value)) : data;
|
|
1889
|
+
Validation2.passed = (value) => ({ kind: "Passed", value });
|
|
1890
|
+
Validation2.failed = (error) => ({ kind: "Failed", errors: [error] });
|
|
1891
|
+
Validation2.failedAll = (errors) => ({ kind: "Failed", errors });
|
|
1892
|
+
Validation2.isPassed = (data) => data.kind === "Passed";
|
|
1893
|
+
Validation2.isFailed = (data) => data.kind === "Failed";
|
|
1894
|
+
Validation2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Validation2.passed)(a) : (0, Validation2.failed)(onFalse(a));
|
|
1895
|
+
Validation2.fromNullable = (onNull) => (value) => value === null || value === void 0 ? (0, Validation2.failed)(onNull()) : (0, Validation2.passed)(value);
|
|
1896
|
+
Validation2.fromMaybe = (onNone) => (maybe) => Maybe.isNone(maybe) ? (0, Validation2.failed)(onNone()) : (0, Validation2.passed)(maybe.value);
|
|
1897
|
+
Validation2.map = (f) => (data) => (0, Validation2.isPassed)(data) ? (0, Validation2.passed)(f(data.value)) : data;
|
|
1898
|
+
Validation2.mapError = (f) => (data) => (0, Validation2.isFailed)(data) ? (0, Validation2.failedAll)(data.errors.map(f)) : data;
|
|
1777
1899
|
Validation2.ap = (arg) => (data) => {
|
|
1778
|
-
if ((0, Validation2.
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
Validation2.
|
|
1786
|
-
Validation2.
|
|
1787
|
-
Validation2.getOrElse = (defaultValue) => (data) => (0, Validation2.isValid)(data) ? data.value : defaultValue();
|
|
1900
|
+
if ((0, Validation2.isPassed)(data) && (0, Validation2.isPassed)(arg)) {
|
|
1901
|
+
return (0, Validation2.passed)(data.value(arg.value));
|
|
1902
|
+
}
|
|
1903
|
+
const errors = [...(0, Validation2.isFailed)(data) ? data.errors : [], ...(0, Validation2.isFailed)(arg) ? arg.errors : []];
|
|
1904
|
+
return (0, Validation2.failedAll)(errors);
|
|
1905
|
+
};
|
|
1906
|
+
Validation2.fold = (onFailed, onPassed) => (data) => (0, Validation2.isPassed)(data) ? onPassed(data.value) : onFailed(data.errors);
|
|
1907
|
+
Validation2.match = (cases) => (data) => (0, Validation2.isPassed)(data) ? cases.passed(data.value) : cases.failed(data.errors);
|
|
1908
|
+
Validation2.getOrElse = (defaultValue) => (data) => (0, Validation2.isPassed)(data) ? data.value : defaultValue();
|
|
1788
1909
|
Validation2.tap = (f) => (data) => {
|
|
1789
|
-
if ((0, Validation2.
|
|
1910
|
+
if ((0, Validation2.isPassed)(data)) {
|
|
1911
|
+
f(data.value);
|
|
1912
|
+
}
|
|
1790
1913
|
return data;
|
|
1791
1914
|
};
|
|
1792
1915
|
Validation2.tapError = (f) => (data) => {
|
|
1793
|
-
if ((0, Validation2.
|
|
1916
|
+
if ((0, Validation2.isFailed)(data)) {
|
|
1917
|
+
f(data.errors);
|
|
1918
|
+
}
|
|
1794
1919
|
return data;
|
|
1795
1920
|
};
|
|
1796
|
-
Validation2.recover = (fallback) => (data) => (0, Validation2.
|
|
1797
|
-
Validation2.recoverUnless = (isBlocked, fallback) => (data) => (0, Validation2.
|
|
1798
|
-
Validation2.toResult = (data) => (0, Validation2.
|
|
1799
|
-
Validation2.toMaybe = (data) => (0, Validation2.
|
|
1800
|
-
Validation2.fromResult = (data) => data.kind === "Ok" ? (0, Validation2.
|
|
1921
|
+
Validation2.recover = (fallback) => (data) => (0, Validation2.isPassed)(data) ? data : fallback(data.errors);
|
|
1922
|
+
Validation2.recoverUnless = (isBlocked, fallback) => (data) => (0, Validation2.isFailed)(data) && !data.errors.some(isBlocked) ? fallback() : data;
|
|
1923
|
+
Validation2.toResult = (data) => (0, Validation2.isPassed)(data) ? Result.ok(data.value) : Result.err(data.errors);
|
|
1924
|
+
Validation2.toMaybe = (data) => (0, Validation2.isPassed)(data) ? Maybe.some(data.value) : Maybe.none();
|
|
1925
|
+
Validation2.fromResult = (data) => data.kind === "Ok" ? (0, Validation2.passed)(data.value) : (0, Validation2.failed)(data.error);
|
|
1801
1926
|
Validation2.product = (first, second) => {
|
|
1802
|
-
if ((0, Validation2.
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
return (0, Validation2.invalidAll)(errors);
|
|
1927
|
+
if ((0, Validation2.isPassed)(first) && (0, Validation2.isPassed)(second)) {
|
|
1928
|
+
return (0, Validation2.passed)([first.value, second.value]);
|
|
1929
|
+
}
|
|
1930
|
+
const errors = [...(0, Validation2.isFailed)(first) ? first.errors : [], ...(0, Validation2.isFailed)(second) ? second.errors : []];
|
|
1931
|
+
return (0, Validation2.failedAll)(errors);
|
|
1808
1932
|
};
|
|
1809
1933
|
Validation2.productAll = (data) => {
|
|
1810
1934
|
const values = [];
|
|
1811
1935
|
const errors = [];
|
|
1812
1936
|
for (const v of data) {
|
|
1813
|
-
if ((0, Validation2.
|
|
1814
|
-
|
|
1937
|
+
if ((0, Validation2.isPassed)(v)) {
|
|
1938
|
+
values.push(v.value);
|
|
1939
|
+
} else {
|
|
1940
|
+
errors.push(...v.errors);
|
|
1941
|
+
}
|
|
1815
1942
|
}
|
|
1816
|
-
return errors.length > 0 ? (0, Validation2.
|
|
1943
|
+
return errors.length > 0 ? (0, Validation2.failedAll)(errors) : (0, Validation2.passed)(values);
|
|
1817
1944
|
};
|
|
1818
1945
|
})(Validation || (Validation = {}));
|
|
1819
1946
|
|
|
1820
1947
|
// src/Core/TaskValidation.ts
|
|
1821
1948
|
var TaskValidation;
|
|
1822
1949
|
((TaskValidation2) => {
|
|
1823
|
-
TaskValidation2.
|
|
1824
|
-
TaskValidation2.
|
|
1825
|
-
TaskValidation2.
|
|
1950
|
+
TaskValidation2.passed = (value) => Task.resolve(Validation.passed(value));
|
|
1951
|
+
TaskValidation2.failed = (error) => Task.resolve(Validation.failed(error));
|
|
1952
|
+
TaskValidation2.failedAll = (errors) => Task.resolve(Validation.failedAll(errors));
|
|
1826
1953
|
TaskValidation2.fromValidation = (validation) => Task.resolve(validation);
|
|
1827
|
-
TaskValidation2.fromNullable = (onNull) => (value) => Task.resolve(value === null || value === void 0 ? Validation.
|
|
1828
|
-
TaskValidation2.fromMaybe = (onNone) => (maybe) => Task.resolve(Maybe.isNone(maybe) ? Validation.
|
|
1954
|
+
TaskValidation2.fromNullable = (onNull) => (value) => Task.resolve(value === null || value === void 0 ? Validation.failed(onNull()) : Validation.passed(value));
|
|
1955
|
+
TaskValidation2.fromMaybe = (onNone) => (maybe) => Task.resolve(Maybe.isNone(maybe) ? Validation.failed(onNone()) : Validation.passed(maybe.value));
|
|
1829
1956
|
TaskValidation2.fromResult = (result) => Task.resolve(Validation.fromResult(result));
|
|
1830
|
-
TaskValidation2.tryCatch = (f, onError) => Task.from(
|
|
1831
|
-
(signal) => f(signal).then(Validation.valid).catch((e) => Validation.invalid(onError(e)))
|
|
1832
|
-
);
|
|
1957
|
+
TaskValidation2.tryCatch = (f, onError) => Task.from((signal) => f(signal).then(Validation.passed).catch((error) => Validation.failed(onError(error))));
|
|
1833
1958
|
TaskValidation2.map = (f) => (data) => Task.map(Validation.map(f))(data);
|
|
1834
1959
|
TaskValidation2.ap = (arg) => (data) => Task.from(
|
|
1835
|
-
(signal) => Promise.all([
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
]).then(([vf, va]) => Validation.ap(va)(vf))
|
|
1960
|
+
(signal) => Promise.all([Deferred.toPromise(data(signal)), Deferred.toPromise(arg(signal))]).then(
|
|
1961
|
+
([vf, va]) => Validation.ap(va)(vf)
|
|
1962
|
+
)
|
|
1839
1963
|
);
|
|
1840
|
-
TaskValidation2.fold = (
|
|
1964
|
+
TaskValidation2.fold = (onFailed, onPassed) => (data) => Task.map(Validation.fold(onFailed, onPassed))(data);
|
|
1841
1965
|
TaskValidation2.match = (cases) => (data) => Task.map(Validation.match(cases))(data);
|
|
1842
1966
|
TaskValidation2.getOrElse = (defaultValue) => (data) => Task.map(Validation.getOrElse(defaultValue))(data);
|
|
1843
1967
|
TaskValidation2.tap = (f) => (data) => Task.map(Validation.tap(f))(data);
|
|
1844
1968
|
TaskValidation2.recover = (fallback) => (data) => Task.chain(
|
|
1845
|
-
(validation) => Validation.
|
|
1969
|
+
(validation) => Validation.isPassed(validation) ? Task.resolve(validation) : fallback(validation.errors)
|
|
1846
1970
|
)(data);
|
|
1847
1971
|
TaskValidation2.product = (first, second) => Task.from(
|
|
1848
|
-
(signal) => Promise.all([
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
]).then(([va, vb]) => Validation.product(va, vb))
|
|
1972
|
+
(signal) => Promise.all([Deferred.toPromise(first(signal)), Deferred.toPromise(second(signal))]).then(
|
|
1973
|
+
([va, vb]) => Validation.product(va, vb)
|
|
1974
|
+
)
|
|
1852
1975
|
);
|
|
1853
1976
|
TaskValidation2.productAll = (data) => Task.from(
|
|
1854
|
-
(signal) => Promise.all(data.map((t) => Deferred.toPromise(t(signal)))).then(
|
|
1977
|
+
(signal) => Promise.all(data.map((t) => Deferred.toPromise(t(signal)))).then(
|
|
1978
|
+
(results) => Validation.productAll(results)
|
|
1979
|
+
)
|
|
1855
1980
|
);
|
|
1856
1981
|
})(TaskValidation || (TaskValidation = {}));
|
|
1857
1982
|
|
|
@@ -1860,58 +1985,84 @@ var These;
|
|
|
1860
1985
|
((These2) => {
|
|
1861
1986
|
These2.first = (value) => ({ kind: "First", first: value });
|
|
1862
1987
|
These2.second = (value) => ({ kind: "Second", second: value });
|
|
1863
|
-
These2.both = (
|
|
1864
|
-
kind: "Both",
|
|
1865
|
-
first: first2,
|
|
1866
|
-
second: second2
|
|
1867
|
-
});
|
|
1988
|
+
These2.both = (f, s) => ({ kind: "Both", first: f, second: s });
|
|
1868
1989
|
These2.isFirst = (data) => data.kind === "First";
|
|
1869
1990
|
These2.isSecond = (data) => data.kind === "Second";
|
|
1870
1991
|
These2.isBoth = (data) => data.kind === "Both";
|
|
1871
1992
|
These2.hasFirst = (data) => data.kind === "First" || data.kind === "Both";
|
|
1872
1993
|
These2.hasSecond = (data) => data.kind === "Second" || data.kind === "Both";
|
|
1873
1994
|
These2.mapFirst = (f) => (data) => {
|
|
1874
|
-
if ((0, These2.isSecond)(data))
|
|
1875
|
-
|
|
1995
|
+
if ((0, These2.isSecond)(data)) {
|
|
1996
|
+
return data;
|
|
1997
|
+
}
|
|
1998
|
+
if ((0, These2.isFirst)(data)) {
|
|
1999
|
+
return (0, These2.first)(f(data.first));
|
|
2000
|
+
}
|
|
1876
2001
|
return (0, These2.both)(f(data.first), data.second);
|
|
1877
2002
|
};
|
|
1878
2003
|
These2.mapSecond = (f) => (data) => {
|
|
1879
|
-
if ((0, These2.isFirst)(data))
|
|
1880
|
-
|
|
2004
|
+
if ((0, These2.isFirst)(data)) {
|
|
2005
|
+
return data;
|
|
2006
|
+
}
|
|
2007
|
+
if ((0, These2.isSecond)(data)) {
|
|
2008
|
+
return (0, These2.second)(f(data.second));
|
|
2009
|
+
}
|
|
1881
2010
|
return (0, These2.both)(data.first, f(data.second));
|
|
1882
2011
|
};
|
|
1883
2012
|
These2.mapBoth = (onFirst, onSecond) => (data) => {
|
|
1884
|
-
if ((0, These2.isSecond)(data))
|
|
1885
|
-
|
|
2013
|
+
if ((0, These2.isSecond)(data)) {
|
|
2014
|
+
return (0, These2.second)(onSecond(data.second));
|
|
2015
|
+
}
|
|
2016
|
+
if ((0, These2.isFirst)(data)) {
|
|
2017
|
+
return (0, These2.first)(onFirst(data.first));
|
|
2018
|
+
}
|
|
1886
2019
|
return (0, These2.both)(onFirst(data.first), onSecond(data.second));
|
|
1887
2020
|
};
|
|
1888
2021
|
These2.chainFirst = (f) => (data) => {
|
|
1889
|
-
if ((0, These2.isSecond)(data))
|
|
2022
|
+
if ((0, These2.isSecond)(data)) {
|
|
2023
|
+
return data;
|
|
2024
|
+
}
|
|
1890
2025
|
return f(data.first);
|
|
1891
2026
|
};
|
|
1892
2027
|
These2.chainSecond = (f) => (data) => {
|
|
1893
|
-
if ((0, These2.isFirst)(data))
|
|
2028
|
+
if ((0, These2.isFirst)(data)) {
|
|
2029
|
+
return data;
|
|
2030
|
+
}
|
|
1894
2031
|
return f(data.second);
|
|
1895
2032
|
};
|
|
1896
2033
|
These2.fold = (onFirst, onSecond, onBoth) => (data) => {
|
|
1897
|
-
if ((0, These2.isSecond)(data))
|
|
1898
|
-
|
|
2034
|
+
if ((0, These2.isSecond)(data)) {
|
|
2035
|
+
return onSecond(data.second);
|
|
2036
|
+
}
|
|
2037
|
+
if ((0, These2.isFirst)(data)) {
|
|
2038
|
+
return onFirst(data.first);
|
|
2039
|
+
}
|
|
1899
2040
|
return onBoth(data.first, data.second);
|
|
1900
2041
|
};
|
|
1901
2042
|
These2.match = (cases) => (data) => {
|
|
1902
|
-
if ((0, These2.isSecond)(data))
|
|
1903
|
-
|
|
2043
|
+
if ((0, These2.isSecond)(data)) {
|
|
2044
|
+
return cases.second(data.second);
|
|
2045
|
+
}
|
|
2046
|
+
if ((0, These2.isFirst)(data)) {
|
|
2047
|
+
return cases.first(data.first);
|
|
2048
|
+
}
|
|
1904
2049
|
return cases.both(data.first, data.second);
|
|
1905
2050
|
};
|
|
1906
2051
|
These2.getFirstOrElse = (defaultValue) => (data) => (0, These2.hasFirst)(data) ? data.first : defaultValue();
|
|
1907
2052
|
These2.getSecondOrElse = (defaultValue) => (data) => (0, These2.hasSecond)(data) ? data.second : defaultValue();
|
|
1908
2053
|
These2.tap = (f) => (data) => {
|
|
1909
|
-
if ((0, These2.hasFirst)(data))
|
|
2054
|
+
if ((0, These2.hasFirst)(data)) {
|
|
2055
|
+
f(data.first);
|
|
2056
|
+
}
|
|
1910
2057
|
return data;
|
|
1911
2058
|
};
|
|
1912
2059
|
These2.swap = (data) => {
|
|
1913
|
-
if ((0, These2.isSecond)(data))
|
|
1914
|
-
|
|
2060
|
+
if ((0, These2.isSecond)(data)) {
|
|
2061
|
+
return (0, These2.first)(data.second);
|
|
2062
|
+
}
|
|
2063
|
+
if ((0, These2.isFirst)(data)) {
|
|
2064
|
+
return (0, These2.second)(data.first);
|
|
2065
|
+
}
|
|
1915
2066
|
return (0, These2.both)(data.second, data.first);
|
|
1916
2067
|
};
|
|
1917
2068
|
})(These || (These = {}));
|