@nlozgachev/pipelined 0.33.0 → 0.34.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 +67 -37
- 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
|
@@ -3,35 +3,20 @@ import {
|
|
|
3
3
|
Maybe,
|
|
4
4
|
Result,
|
|
5
5
|
Task
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-DLBHVYII.mjs";
|
|
7
|
+
import {
|
|
8
|
+
Duration
|
|
9
|
+
} from "./chunk-VWVPHDZO.mjs";
|
|
7
10
|
|
|
8
11
|
// src/Core/Combinable.ts
|
|
9
12
|
var Combinable;
|
|
10
13
|
((Combinable2) => {
|
|
11
|
-
Combinable2.string = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
15
|
-
Combinable2.
|
|
16
|
-
|
|
17
|
-
combine: (b) => (a) => a + b
|
|
18
|
-
};
|
|
19
|
-
Combinable2.product = {
|
|
20
|
-
empty: 1,
|
|
21
|
-
combine: (b) => (a) => a * b
|
|
22
|
-
};
|
|
23
|
-
Combinable2.all = {
|
|
24
|
-
empty: true,
|
|
25
|
-
combine: (b) => (a) => a && b
|
|
26
|
-
};
|
|
27
|
-
Combinable2.any = {
|
|
28
|
-
empty: false,
|
|
29
|
-
combine: (b) => (a) => a || b
|
|
30
|
-
};
|
|
31
|
-
Combinable2.array = () => ({
|
|
32
|
-
empty: [],
|
|
33
|
-
combine: (b) => (a) => [...a, ...b]
|
|
34
|
-
});
|
|
14
|
+
Combinable2.string = { empty: "", combine: (b) => (a) => a + b };
|
|
15
|
+
Combinable2.sum = { empty: 0, combine: (b) => (a) => a + b };
|
|
16
|
+
Combinable2.product = { empty: 1, combine: (b) => (a) => a * b };
|
|
17
|
+
Combinable2.all = { empty: true, combine: (b) => (a) => a && b };
|
|
18
|
+
Combinable2.any = { empty: false, combine: (b) => (a) => a || b };
|
|
19
|
+
Combinable2.array = () => ({ empty: [], combine: (b) => (a) => [...a, ...b] });
|
|
35
20
|
Combinable2.maybe = (inner) => ({
|
|
36
21
|
empty: Maybe.none(),
|
|
37
22
|
combine: (b) => (a) => Maybe.isNone(a) ? b : Maybe.isNone(b) ? a : Maybe.some(inner.combine(b.value)(a.value))
|
|
@@ -81,17 +66,11 @@ var Lazy;
|
|
|
81
66
|
var Lens;
|
|
82
67
|
((Lens2) => {
|
|
83
68
|
Lens2.make = (get2, set2) => ({ get: get2, set: set2 });
|
|
84
|
-
Lens2.prop = () => (key) => (0, Lens2.make)(
|
|
85
|
-
(s) => s[key],
|
|
86
|
-
(a) => (s) => ({ ...s, [key]: a })
|
|
87
|
-
);
|
|
69
|
+
Lens2.prop = () => (key) => (0, Lens2.make)((s) => s[key], (a) => (s) => ({ ...s, [key]: a }));
|
|
88
70
|
Lens2.get = (lens) => (s) => lens.get(s);
|
|
89
71
|
Lens2.set = (lens) => (a) => (s) => lens.set(a)(s);
|
|
90
72
|
Lens2.modify = (lens) => (f) => (s) => lens.set(f(lens.get(s)))(s);
|
|
91
|
-
Lens2.andThen = (inner) => (outer) => (0, Lens2.make)(
|
|
92
|
-
(s) => inner.get(outer.get(s)),
|
|
93
|
-
(b) => (s) => outer.set(inner.set(b)(outer.get(s)))(s)
|
|
94
|
-
);
|
|
73
|
+
Lens2.andThen = (inner) => (outer) => (0, Lens2.make)((s) => inner.get(outer.get(s)), (b) => (s) => outer.set(inner.set(b)(outer.get(s)))(s));
|
|
95
74
|
Lens2.andThenOptional = (inner) => (outer) => ({
|
|
96
75
|
get: (s) => inner.get(outer.get(s)),
|
|
97
76
|
set: (b) => (s) => outer.set(inner.set(b)(outer.get(s)))(s)
|
|
@@ -134,11 +113,15 @@ var _evictedNil = { kind: "OpNil", reason: "evicted" };
|
|
|
134
113
|
var _idle = { kind: "Idle" };
|
|
135
114
|
var _pending = { kind: "Pending" };
|
|
136
115
|
var ok = (value) => ({ kind: "OpOk", value });
|
|
137
|
-
var err = (error) => ({ kind: "
|
|
138
|
-
var
|
|
139
|
-
|
|
116
|
+
var err = (error) => ({ kind: "OpErr", error });
|
|
117
|
+
var getMs = (duration) => Duration.toMilliseconds(duration);
|
|
118
|
+
var cancellableWait = (duration, signal) => {
|
|
119
|
+
const rawMs = getMs(duration);
|
|
120
|
+
if (rawMs <= 0) {
|
|
121
|
+
return Promise.resolve();
|
|
122
|
+
}
|
|
140
123
|
return new Promise((resolve) => {
|
|
141
|
-
const id = setTimeout(resolve,
|
|
124
|
+
const id = setTimeout(resolve, rawMs);
|
|
142
125
|
signal.addEventListener("abort", () => {
|
|
143
126
|
clearTimeout(id);
|
|
144
127
|
resolve();
|
|
@@ -147,23 +130,41 @@ var cancellableWait = (ms, signal) => {
|
|
|
147
130
|
};
|
|
148
131
|
var runWithRetry = (op, input, signal, options, onRetrying) => {
|
|
149
132
|
const { attempts, backoff, when: shouldRetry } = options;
|
|
150
|
-
const getDelay = (n) =>
|
|
133
|
+
const getDelay = (n) => {
|
|
134
|
+
if (backoff === void 0) {
|
|
135
|
+
return void 0;
|
|
136
|
+
}
|
|
137
|
+
return typeof backoff === "function" ? backoff(n) : backoff;
|
|
138
|
+
};
|
|
151
139
|
const attempt = async (left) => {
|
|
152
140
|
const result = await Deferred.toPromise(op._factory(input, signal));
|
|
153
|
-
if (result === null || signal.aborted)
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
if (
|
|
141
|
+
if (result === null || signal.aborted) {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
if (result.kind === "Ok") {
|
|
145
|
+
return result;
|
|
146
|
+
}
|
|
147
|
+
if (left <= 1) {
|
|
148
|
+
return result;
|
|
149
|
+
}
|
|
150
|
+
if (shouldRetry !== void 0 && !shouldRetry(result.error)) {
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
157
153
|
const attemptNumber = attempts - left + 1;
|
|
158
|
-
const
|
|
154
|
+
const delayDuration = getDelay(attemptNumber);
|
|
155
|
+
const ms = delayDuration ? getMs(delayDuration) : 0;
|
|
159
156
|
onRetrying({
|
|
160
157
|
kind: "Retrying",
|
|
161
158
|
attempt: attemptNumber,
|
|
162
159
|
lastError: result.error,
|
|
163
160
|
...ms > 0 ? { nextRetryIn: ms } : {}
|
|
164
161
|
});
|
|
165
|
-
|
|
166
|
-
|
|
162
|
+
if (delayDuration) {
|
|
163
|
+
await cancellableWait(delayDuration, signal);
|
|
164
|
+
}
|
|
165
|
+
if (signal.aborted) {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
167
168
|
return attempt(left - 1);
|
|
168
169
|
};
|
|
169
170
|
return attempt(attempts);
|
|
@@ -172,7 +173,9 @@ var execute = (op, input, controller, retryOptions, timeoutOptions, onRetrying)
|
|
|
172
173
|
const { signal } = controller;
|
|
173
174
|
const toOutcome = (r) => r === null ? _abortedNil : r.kind === "Ok" ? ok(r.value) : err(r.error);
|
|
174
175
|
const runPromise = retryOptions !== void 0 && onRetrying !== void 0 ? runWithRetry(op, input, signal, retryOptions, onRetrying).then(toOutcome) : Deferred.toPromise(op._factory(input, signal)).then(toOutcome);
|
|
175
|
-
if (timeoutOptions === void 0)
|
|
176
|
+
if (timeoutOptions === void 0) {
|
|
177
|
+
return Deferred.fromPromise(runPromise);
|
|
178
|
+
}
|
|
176
179
|
let timerId;
|
|
177
180
|
return Deferred.fromPromise(Promise.race([
|
|
178
181
|
runPromise.then((outcome) => {
|
|
@@ -183,7 +186,7 @@ var execute = (op, input, controller, retryOptions, timeoutOptions, onRetrying)
|
|
|
183
186
|
timerId = setTimeout(() => {
|
|
184
187
|
controller.abort();
|
|
185
188
|
resolve(err(timeoutOptions.onTimeout()));
|
|
186
|
-
}, timeoutOptions.
|
|
189
|
+
}, getMs(timeoutOptions.duration));
|
|
187
190
|
})
|
|
188
191
|
]));
|
|
189
192
|
};
|
|
@@ -209,14 +212,20 @@ var makeRestartable = (op, minInterval, retryOptions, timeoutOptions) => {
|
|
|
209
212
|
const controller = currentController;
|
|
210
213
|
prev?.(_replacedNil);
|
|
211
214
|
const startExecution = () => {
|
|
212
|
-
if (currentController !== controller)
|
|
215
|
+
if (currentController !== controller) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
213
218
|
lastStartTime = Date.now();
|
|
214
219
|
emit(_pending);
|
|
215
220
|
const onRetrying = retryOptions ? (r) => {
|
|
216
|
-
if (currentController === controller)
|
|
221
|
+
if (currentController === controller) {
|
|
222
|
+
emit(r);
|
|
223
|
+
}
|
|
217
224
|
} : void 0;
|
|
218
225
|
execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
|
|
219
|
-
if (currentController !== controller)
|
|
226
|
+
if (currentController !== controller) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
220
229
|
const r = currentResolve;
|
|
221
230
|
currentResolve = void 0;
|
|
222
231
|
currentController = void 0;
|
|
@@ -224,12 +233,14 @@ var makeRestartable = (op, minInterval, retryOptions, timeoutOptions) => {
|
|
|
224
233
|
r?.(outcome);
|
|
225
234
|
});
|
|
226
235
|
};
|
|
227
|
-
const gap = minInterval !== void 0 ? Math.max(0, minInterval - (Date.now() - lastStartTime)) : 0;
|
|
236
|
+
const gap = minInterval !== void 0 ? Math.max(0, getMs(minInterval) - (Date.now() - lastStartTime)) : 0;
|
|
228
237
|
if (gap > 0) {
|
|
229
238
|
waitController = new AbortController();
|
|
230
239
|
const wc = waitController;
|
|
231
|
-
cancellableWait(gap, wc.signal).then(() => {
|
|
232
|
-
if (waitController === wc)
|
|
240
|
+
cancellableWait(Duration.milliseconds(gap), wc.signal).then(() => {
|
|
241
|
+
if (waitController === wc) {
|
|
242
|
+
waitController = void 0;
|
|
243
|
+
}
|
|
233
244
|
startExecution();
|
|
234
245
|
});
|
|
235
246
|
} else {
|
|
@@ -244,7 +255,9 @@ var makeRestartable = (op, minInterval, retryOptions, timeoutOptions) => {
|
|
|
244
255
|
currentController = void 0;
|
|
245
256
|
const r = currentResolve;
|
|
246
257
|
currentResolve = void 0;
|
|
247
|
-
if (currentState.kind !== "Idle")
|
|
258
|
+
if (currentState.kind !== "Idle") {
|
|
259
|
+
emit(_abortedNil);
|
|
260
|
+
}
|
|
248
261
|
r?.(_abortedNil);
|
|
249
262
|
};
|
|
250
263
|
return {
|
|
@@ -255,13 +268,15 @@ var makeRestartable = (op, minInterval, retryOptions, timeoutOptions) => {
|
|
|
255
268
|
abort,
|
|
256
269
|
subscribe: (cb) => {
|
|
257
270
|
subscribers.add(cb);
|
|
258
|
-
if (currentState.kind !== "Idle")
|
|
271
|
+
if (currentState.kind !== "Idle") {
|
|
272
|
+
cb(currentState);
|
|
273
|
+
}
|
|
259
274
|
return () => subscribers.delete(cb);
|
|
260
275
|
},
|
|
261
276
|
reset: () => emit(_idle),
|
|
262
277
|
poll: (input, { interval }) => {
|
|
263
278
|
void run(input);
|
|
264
|
-
const id = setInterval(() => void run(input), interval);
|
|
279
|
+
const id = setInterval(() => void run(input), getMs(interval));
|
|
265
280
|
return () => clearInterval(id);
|
|
266
281
|
}
|
|
267
282
|
};
|
|
@@ -287,19 +302,26 @@ var makeExclusive = (op, cooldown, retryOptions, timeoutOptions) => {
|
|
|
287
302
|
const controller = currentController;
|
|
288
303
|
emit(_pending);
|
|
289
304
|
const onRetrying = retryOptions ? (r) => {
|
|
290
|
-
if (currentController === controller)
|
|
305
|
+
if (currentController === controller) {
|
|
306
|
+
emit(r);
|
|
307
|
+
}
|
|
291
308
|
} : void 0;
|
|
292
309
|
execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
|
|
293
|
-
if (currentController !== controller)
|
|
310
|
+
if (currentController !== controller) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
294
313
|
const r = currentResolve;
|
|
295
314
|
currentResolve = void 0;
|
|
296
315
|
currentController = void 0;
|
|
297
316
|
emit(outcome);
|
|
298
317
|
r?.(outcome);
|
|
299
|
-
if (cooldown !== void 0
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
318
|
+
if (cooldown !== void 0) {
|
|
319
|
+
const rawCooldown = getMs(cooldown);
|
|
320
|
+
if (rawCooldown > 0) {
|
|
321
|
+
cooldownTimer = setTimeout(() => {
|
|
322
|
+
cooldownTimer = void 0;
|
|
323
|
+
}, rawCooldown);
|
|
324
|
+
}
|
|
303
325
|
}
|
|
304
326
|
});
|
|
305
327
|
})
|
|
@@ -314,7 +336,9 @@ var makeExclusive = (op, cooldown, retryOptions, timeoutOptions) => {
|
|
|
314
336
|
currentController = void 0;
|
|
315
337
|
const r = currentResolve;
|
|
316
338
|
currentResolve = void 0;
|
|
317
|
-
if (currentState.kind !== "Idle")
|
|
339
|
+
if (currentState.kind !== "Idle") {
|
|
340
|
+
emit(_abortedNil);
|
|
341
|
+
}
|
|
318
342
|
r?.(_abortedNil);
|
|
319
343
|
};
|
|
320
344
|
return {
|
|
@@ -325,13 +349,15 @@ var makeExclusive = (op, cooldown, retryOptions, timeoutOptions) => {
|
|
|
325
349
|
abort,
|
|
326
350
|
subscribe: (cb) => {
|
|
327
351
|
subscribers.add(cb);
|
|
328
|
-
if (currentState.kind !== "Idle")
|
|
352
|
+
if (currentState.kind !== "Idle") {
|
|
353
|
+
cb(currentState);
|
|
354
|
+
}
|
|
329
355
|
return () => subscribers.delete(cb);
|
|
330
356
|
},
|
|
331
357
|
reset: () => emit(_idle),
|
|
332
358
|
poll: (input, { interval }) => {
|
|
333
359
|
void run(input);
|
|
334
|
-
const id = setInterval(() => void run(input), interval);
|
|
360
|
+
const id = setInterval(() => void run(input), getMs(interval));
|
|
335
361
|
return () => clearInterval(id);
|
|
336
362
|
}
|
|
337
363
|
};
|
|
@@ -356,12 +382,16 @@ var makeQueue = (op, maxSize, overflow, concurrency, dedupe, retryOptions, timeo
|
|
|
356
382
|
inflightResolvers.push(resolve);
|
|
357
383
|
emit(_pending);
|
|
358
384
|
const onRetrying = retryOptions ? (r) => {
|
|
359
|
-
if (generation === myGeneration && inflightControllers.has(controller))
|
|
385
|
+
if (generation === myGeneration && inflightControllers.has(controller)) {
|
|
386
|
+
emit(r);
|
|
387
|
+
}
|
|
360
388
|
} : void 0;
|
|
361
389
|
execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
|
|
362
390
|
inflightControllers.delete(controller);
|
|
363
391
|
const idx = inflightResolvers.indexOf(resolve);
|
|
364
|
-
if (idx !== -1)
|
|
392
|
+
if (idx !== -1) {
|
|
393
|
+
inflightResolvers.splice(idx, 1);
|
|
394
|
+
}
|
|
365
395
|
if (generation !== myGeneration) {
|
|
366
396
|
resolve(_abortedNil);
|
|
367
397
|
return;
|
|
@@ -418,7 +448,9 @@ var makeQueue = (op, maxSize, overflow, concurrency, dedupe, retryOptions, timeo
|
|
|
418
448
|
const toResolve = inflightResolvers.splice(0);
|
|
419
449
|
const queuedResolvers = queue.splice(0).map((item) => item.resolve);
|
|
420
450
|
inFlight = 0;
|
|
421
|
-
if (currentState.kind !== "Idle")
|
|
451
|
+
if (currentState.kind !== "Idle") {
|
|
452
|
+
emit(_abortedNil);
|
|
453
|
+
}
|
|
422
454
|
toResolve.forEach((r) => r(_abortedNil));
|
|
423
455
|
queuedResolvers.forEach((r) => r(_abortedNil));
|
|
424
456
|
};
|
|
@@ -430,13 +462,15 @@ var makeQueue = (op, maxSize, overflow, concurrency, dedupe, retryOptions, timeo
|
|
|
430
462
|
abort,
|
|
431
463
|
subscribe: (cb) => {
|
|
432
464
|
subscribers.add(cb);
|
|
433
|
-
if (currentState.kind !== "Idle")
|
|
465
|
+
if (currentState.kind !== "Idle") {
|
|
466
|
+
cb(currentState);
|
|
467
|
+
}
|
|
434
468
|
return () => subscribers.delete(cb);
|
|
435
469
|
},
|
|
436
470
|
reset: () => emit(_idle),
|
|
437
471
|
poll: (input, { interval }) => {
|
|
438
472
|
void run(input);
|
|
439
|
-
const id = setInterval(() => void run(input), interval);
|
|
473
|
+
const id = setInterval(() => void run(input), getMs(interval));
|
|
440
474
|
return () => clearInterval(id);
|
|
441
475
|
}
|
|
442
476
|
};
|
|
@@ -458,10 +492,14 @@ var makeBuffered = (op, size, retryOptions, timeoutOptions) => {
|
|
|
458
492
|
const controller = currentController;
|
|
459
493
|
emit(_pending);
|
|
460
494
|
const onRetrying = retryOptions ? (r) => {
|
|
461
|
-
if (currentController === controller)
|
|
495
|
+
if (currentController === controller) {
|
|
496
|
+
emit(r);
|
|
497
|
+
}
|
|
462
498
|
} : void 0;
|
|
463
499
|
execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
|
|
464
|
-
if (currentController !== controller)
|
|
500
|
+
if (currentController !== controller) {
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
465
503
|
const r = currentResolve;
|
|
466
504
|
currentResolve = void 0;
|
|
467
505
|
currentController = void 0;
|
|
@@ -494,7 +532,9 @@ var makeBuffered = (op, size, retryOptions, timeoutOptions) => {
|
|
|
494
532
|
const cr = currentResolve;
|
|
495
533
|
currentResolve = void 0;
|
|
496
534
|
const bufferedResolvers = buffer.splice(0).map((item) => item.resolve);
|
|
497
|
-
if (currentState.kind !== "Idle")
|
|
535
|
+
if (currentState.kind !== "Idle") {
|
|
536
|
+
emit(_abortedNil);
|
|
537
|
+
}
|
|
498
538
|
cr?.(_abortedNil);
|
|
499
539
|
bufferedResolvers.forEach((r) => r(_abortedNil));
|
|
500
540
|
};
|
|
@@ -506,18 +546,20 @@ var makeBuffered = (op, size, retryOptions, timeoutOptions) => {
|
|
|
506
546
|
abort,
|
|
507
547
|
subscribe: (cb) => {
|
|
508
548
|
subscribers.add(cb);
|
|
509
|
-
if (currentState.kind !== "Idle")
|
|
549
|
+
if (currentState.kind !== "Idle") {
|
|
550
|
+
cb(currentState);
|
|
551
|
+
}
|
|
510
552
|
return () => subscribers.delete(cb);
|
|
511
553
|
},
|
|
512
554
|
reset: () => emit(_idle),
|
|
513
555
|
poll: (input, { interval }) => {
|
|
514
556
|
void run(input);
|
|
515
|
-
const id = setInterval(() => void run(input), interval);
|
|
557
|
+
const id = setInterval(() => void run(input), getMs(interval));
|
|
516
558
|
return () => clearInterval(id);
|
|
517
559
|
}
|
|
518
560
|
};
|
|
519
561
|
};
|
|
520
|
-
var makeDebounced = (op,
|
|
562
|
+
var makeDebounced = (op, duration, leading, maxWait, retryOptions, timeoutOptions) => {
|
|
521
563
|
let currentState = _idle;
|
|
522
564
|
let currentController;
|
|
523
565
|
let currentResolve;
|
|
@@ -538,10 +580,14 @@ var makeDebounced = (op, ms, leading, maxWait, retryOptions, timeoutOptions) =>
|
|
|
538
580
|
leadingResolve = resolve;
|
|
539
581
|
emit(_pending);
|
|
540
582
|
const onRetrying = retryOptions ? (r) => {
|
|
541
|
-
if (leadingController === controller)
|
|
583
|
+
if (leadingController === controller) {
|
|
584
|
+
emit(r);
|
|
585
|
+
}
|
|
542
586
|
} : void 0;
|
|
543
587
|
execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
|
|
544
|
-
if (leadingController !== controller)
|
|
588
|
+
if (leadingController !== controller) {
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
545
591
|
const r = leadingResolve;
|
|
546
592
|
leadingResolve = void 0;
|
|
547
593
|
leadingController = void 0;
|
|
@@ -554,7 +600,9 @@ var makeDebounced = (op, ms, leading, maxWait, retryOptions, timeoutOptions) =>
|
|
|
554
600
|
firstCallAt = 0;
|
|
555
601
|
const capturedResolve = pendingResolve;
|
|
556
602
|
pendingResolve = void 0;
|
|
557
|
-
if (capturedResolve === void 0)
|
|
603
|
+
if (capturedResolve === void 0) {
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
558
606
|
currentResolve = capturedResolve;
|
|
559
607
|
const toRun = pendingInput;
|
|
560
608
|
pendingInput = void 0;
|
|
@@ -562,10 +610,14 @@ var makeDebounced = (op, ms, leading, maxWait, retryOptions, timeoutOptions) =>
|
|
|
562
610
|
const controller = currentController;
|
|
563
611
|
emit(_pending);
|
|
564
612
|
const onRetrying = retryOptions ? (r) => {
|
|
565
|
-
if (currentController === controller)
|
|
613
|
+
if (currentController === controller) {
|
|
614
|
+
emit(r);
|
|
615
|
+
}
|
|
566
616
|
} : void 0;
|
|
567
617
|
execute(op, toRun, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
|
|
568
|
-
if (currentController !== controller)
|
|
618
|
+
if (currentController !== controller) {
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
569
621
|
const r = currentResolve;
|
|
570
622
|
currentResolve = void 0;
|
|
571
623
|
currentController = void 0;
|
|
@@ -574,11 +626,13 @@ var makeDebounced = (op, ms, leading, maxWait, retryOptions, timeoutOptions) =>
|
|
|
574
626
|
});
|
|
575
627
|
};
|
|
576
628
|
const scheduleTrailing = () => {
|
|
577
|
-
if (timerId !== void 0)
|
|
578
|
-
|
|
629
|
+
if (timerId !== void 0) {
|
|
630
|
+
clearTimeout(timerId);
|
|
631
|
+
}
|
|
632
|
+
let delay = getMs(duration);
|
|
579
633
|
if (maxWait !== void 0 && firstCallAt > 0) {
|
|
580
|
-
const maxDelay = firstCallAt + maxWait - Date.now();
|
|
581
|
-
delay = Math.min(
|
|
634
|
+
const maxDelay = firstCallAt + getMs(maxWait) - Date.now();
|
|
635
|
+
delay = Math.min(getMs(duration), Math.max(0, maxDelay));
|
|
582
636
|
}
|
|
583
637
|
timerId = setTimeout(fireTrailing, delay);
|
|
584
638
|
};
|
|
@@ -621,7 +675,9 @@ var makeDebounced = (op, ms, leading, maxWait, retryOptions, timeoutOptions) =>
|
|
|
621
675
|
leadingResolve = void 0;
|
|
622
676
|
leadingController?.abort();
|
|
623
677
|
leadingController = void 0;
|
|
624
|
-
if (currentState.kind !== "Idle")
|
|
678
|
+
if (currentState.kind !== "Idle") {
|
|
679
|
+
emit(_abortedNil);
|
|
680
|
+
}
|
|
625
681
|
pr?.(_abortedNil);
|
|
626
682
|
cr?.(_abortedNil);
|
|
627
683
|
lr?.(_abortedNil);
|
|
@@ -634,18 +690,20 @@ var makeDebounced = (op, ms, leading, maxWait, retryOptions, timeoutOptions) =>
|
|
|
634
690
|
abort,
|
|
635
691
|
subscribe: (cb) => {
|
|
636
692
|
subscribers.add(cb);
|
|
637
|
-
if (currentState.kind !== "Idle")
|
|
693
|
+
if (currentState.kind !== "Idle") {
|
|
694
|
+
cb(currentState);
|
|
695
|
+
}
|
|
638
696
|
return () => subscribers.delete(cb);
|
|
639
697
|
},
|
|
640
698
|
reset: () => emit(_idle),
|
|
641
699
|
poll: (input, { interval }) => {
|
|
642
700
|
void run(input);
|
|
643
|
-
const id = setInterval(() => void run(input), interval);
|
|
701
|
+
const id = setInterval(() => void run(input), getMs(interval));
|
|
644
702
|
return () => clearInterval(id);
|
|
645
703
|
}
|
|
646
704
|
};
|
|
647
705
|
};
|
|
648
|
-
var makeThrottled = (op,
|
|
706
|
+
var makeThrottled = (op, duration, trailing, retryOptions, timeoutOptions) => {
|
|
649
707
|
let currentState = _idle;
|
|
650
708
|
let currentController;
|
|
651
709
|
let currentResolve;
|
|
@@ -663,10 +721,14 @@ var makeThrottled = (op, ms, trailing, retryOptions, timeoutOptions) => {
|
|
|
663
721
|
const controller = currentController;
|
|
664
722
|
emit(_pending);
|
|
665
723
|
const onRetrying = retryOptions ? (r) => {
|
|
666
|
-
if (currentController === controller)
|
|
724
|
+
if (currentController === controller) {
|
|
725
|
+
emit(r);
|
|
726
|
+
}
|
|
667
727
|
} : void 0;
|
|
668
728
|
execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
|
|
669
|
-
if (currentController !== controller)
|
|
729
|
+
if (currentController !== controller) {
|
|
730
|
+
return;
|
|
731
|
+
}
|
|
670
732
|
const r = currentResolve;
|
|
671
733
|
currentResolve = void 0;
|
|
672
734
|
currentController = void 0;
|
|
@@ -685,7 +747,7 @@ var makeThrottled = (op, ms, trailing, retryOptions, timeoutOptions) => {
|
|
|
685
747
|
fireOp(input, resolve);
|
|
686
748
|
startCooldown();
|
|
687
749
|
}
|
|
688
|
-
},
|
|
750
|
+
}, getMs(duration));
|
|
689
751
|
};
|
|
690
752
|
const run = (input) => {
|
|
691
753
|
if (cooldownTimer !== void 0) {
|
|
@@ -720,7 +782,9 @@ var makeThrottled = (op, ms, trailing, retryOptions, timeoutOptions) => {
|
|
|
720
782
|
const pr = pendingResolve;
|
|
721
783
|
pendingResolve = void 0;
|
|
722
784
|
pendingInput = void 0;
|
|
723
|
-
if (currentState.kind !== "Idle")
|
|
785
|
+
if (currentState.kind !== "Idle") {
|
|
786
|
+
emit(_abortedNil);
|
|
787
|
+
}
|
|
724
788
|
cr?.(_abortedNil);
|
|
725
789
|
pr?.(_abortedNil);
|
|
726
790
|
};
|
|
@@ -732,13 +796,15 @@ var makeThrottled = (op, ms, trailing, retryOptions, timeoutOptions) => {
|
|
|
732
796
|
abort,
|
|
733
797
|
subscribe: (cb) => {
|
|
734
798
|
subscribers.add(cb);
|
|
735
|
-
if (currentState.kind !== "Idle")
|
|
799
|
+
if (currentState.kind !== "Idle") {
|
|
800
|
+
cb(currentState);
|
|
801
|
+
}
|
|
736
802
|
return () => subscribers.delete(cb);
|
|
737
803
|
},
|
|
738
804
|
reset: () => emit(_idle),
|
|
739
805
|
poll: (input, { interval }) => {
|
|
740
806
|
void run(input);
|
|
741
|
-
const id = setInterval(() => void run(input), interval);
|
|
807
|
+
const id = setInterval(() => void run(input), getMs(interval));
|
|
742
808
|
return () => clearInterval(id);
|
|
743
809
|
}
|
|
744
810
|
};
|
|
@@ -762,12 +828,16 @@ var makeConcurrent = (op, n, overflow, retryOptions, timeoutOptions) => {
|
|
|
762
828
|
inflightResolvers.push(resolve);
|
|
763
829
|
emit(_pending);
|
|
764
830
|
const onRetrying = retryOptions ? (r) => {
|
|
765
|
-
if (generation === myGeneration && controllers.has(controller))
|
|
831
|
+
if (generation === myGeneration && controllers.has(controller)) {
|
|
832
|
+
emit(r);
|
|
833
|
+
}
|
|
766
834
|
} : void 0;
|
|
767
835
|
execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
|
|
768
836
|
controllers.delete(controller);
|
|
769
837
|
const idx = inflightResolvers.indexOf(resolve);
|
|
770
|
-
if (idx !== -1)
|
|
838
|
+
if (idx !== -1) {
|
|
839
|
+
inflightResolvers.splice(idx, 1);
|
|
840
|
+
}
|
|
771
841
|
if (generation !== myGeneration) {
|
|
772
842
|
resolve(_abortedNil);
|
|
773
843
|
return;
|
|
@@ -807,7 +877,9 @@ var makeConcurrent = (op, n, overflow, retryOptions, timeoutOptions) => {
|
|
|
807
877
|
const toResolve = inflightResolvers.splice(0);
|
|
808
878
|
const queuedResolvers = overflowQueue.splice(0).map((item) => item.resolve);
|
|
809
879
|
inflight = 0;
|
|
810
|
-
if (currentState.kind !== "Idle")
|
|
880
|
+
if (currentState.kind !== "Idle") {
|
|
881
|
+
emit(_abortedNil);
|
|
882
|
+
}
|
|
811
883
|
toResolve.forEach((r) => r(_abortedNil));
|
|
812
884
|
queuedResolvers.forEach((r) => r(_abortedNil));
|
|
813
885
|
};
|
|
@@ -819,13 +891,15 @@ var makeConcurrent = (op, n, overflow, retryOptions, timeoutOptions) => {
|
|
|
819
891
|
abort,
|
|
820
892
|
subscribe: (cb) => {
|
|
821
893
|
subscribers.add(cb);
|
|
822
|
-
if (currentState.kind !== "Idle")
|
|
894
|
+
if (currentState.kind !== "Idle") {
|
|
895
|
+
cb(currentState);
|
|
896
|
+
}
|
|
823
897
|
return () => subscribers.delete(cb);
|
|
824
898
|
},
|
|
825
899
|
reset: () => emit(_idle),
|
|
826
900
|
poll: (input, { interval }) => {
|
|
827
901
|
void run(input);
|
|
828
|
-
const id = setInterval(() => void run(input), interval);
|
|
902
|
+
const id = setInterval(() => void run(input), getMs(interval));
|
|
829
903
|
return () => clearInterval(id);
|
|
830
904
|
}
|
|
831
905
|
};
|
|
@@ -856,7 +930,7 @@ var makeKeyed = (op, keyFn, perKey, timeoutOptions) => {
|
|
|
856
930
|
slots.set(k, { controller, resolve });
|
|
857
931
|
stateMap.set(k, _pending);
|
|
858
932
|
emitSnapshot();
|
|
859
|
-
execute(op, input, controller, void 0, timeoutOptions
|
|
933
|
+
execute(op, input, controller, void 0, timeoutOptions).then((outcome) => {
|
|
860
934
|
const slot = slots.get(k);
|
|
861
935
|
if (!slot || slot.controller !== controller) {
|
|
862
936
|
resolve(_abortedNil);
|
|
@@ -889,7 +963,9 @@ var makeKeyed = (op, keyFn, perKey, timeoutOptions) => {
|
|
|
889
963
|
stateMap.set(k, _abortedNil);
|
|
890
964
|
}
|
|
891
965
|
slots.clear();
|
|
892
|
-
if (toResolve.length > 0)
|
|
966
|
+
if (toResolve.length > 0) {
|
|
967
|
+
emitSnapshot();
|
|
968
|
+
}
|
|
893
969
|
toResolve.forEach((r) => r(_abortedNil));
|
|
894
970
|
}
|
|
895
971
|
};
|
|
@@ -901,7 +977,9 @@ var makeKeyed = (op, keyFn, perKey, timeoutOptions) => {
|
|
|
901
977
|
abort,
|
|
902
978
|
subscribe: (cb) => {
|
|
903
979
|
subscribers.add(cb);
|
|
904
|
-
if (stateMap.size > 0)
|
|
980
|
+
if (stateMap.size > 0) {
|
|
981
|
+
cb(new Map(stateMap));
|
|
982
|
+
}
|
|
905
983
|
return () => subscribers.delete(cb);
|
|
906
984
|
},
|
|
907
985
|
reset: () => {
|
|
@@ -910,7 +988,7 @@ var makeKeyed = (op, keyFn, perKey, timeoutOptions) => {
|
|
|
910
988
|
},
|
|
911
989
|
poll: (input, { interval }) => {
|
|
912
990
|
void run(input);
|
|
913
|
-
const id = setInterval(() => void run(input), interval);
|
|
991
|
+
const id = setInterval(() => void run(input), getMs(interval));
|
|
914
992
|
return () => clearInterval(id);
|
|
915
993
|
}
|
|
916
994
|
};
|
|
@@ -935,10 +1013,14 @@ var makeOnce = (op, retryOptions, timeoutOptions) => {
|
|
|
935
1013
|
const controller = currentController;
|
|
936
1014
|
emit(_pending);
|
|
937
1015
|
const onRetrying = retryOptions ? (r) => {
|
|
938
|
-
if (currentController === controller)
|
|
1016
|
+
if (currentController === controller) {
|
|
1017
|
+
emit(r);
|
|
1018
|
+
}
|
|
939
1019
|
} : void 0;
|
|
940
1020
|
execute(op, input, controller, retryOptions, timeoutOptions, onRetrying).then((outcome) => {
|
|
941
|
-
if (currentController !== controller)
|
|
1021
|
+
if (currentController !== controller) {
|
|
1022
|
+
return;
|
|
1023
|
+
}
|
|
942
1024
|
const r = currentResolve;
|
|
943
1025
|
currentResolve = void 0;
|
|
944
1026
|
currentController = void 0;
|
|
@@ -953,7 +1035,9 @@ var makeOnce = (op, retryOptions, timeoutOptions) => {
|
|
|
953
1035
|
currentController = void 0;
|
|
954
1036
|
const r = currentResolve;
|
|
955
1037
|
currentResolve = void 0;
|
|
956
|
-
if (currentState.kind !== "Idle")
|
|
1038
|
+
if (currentState.kind !== "Idle") {
|
|
1039
|
+
emit(_abortedNil);
|
|
1040
|
+
}
|
|
957
1041
|
r?.(_abortedNil);
|
|
958
1042
|
};
|
|
959
1043
|
return {
|
|
@@ -964,13 +1048,15 @@ var makeOnce = (op, retryOptions, timeoutOptions) => {
|
|
|
964
1048
|
abort,
|
|
965
1049
|
subscribe: (cb) => {
|
|
966
1050
|
subscribers.add(cb);
|
|
967
|
-
if (currentState.kind !== "Idle")
|
|
1051
|
+
if (currentState.kind !== "Idle") {
|
|
1052
|
+
cb(currentState);
|
|
1053
|
+
}
|
|
968
1054
|
return () => subscribers.delete(cb);
|
|
969
1055
|
},
|
|
970
1056
|
reset: () => emit(_idle),
|
|
971
1057
|
poll: (input, { interval }) => {
|
|
972
1058
|
void run(input);
|
|
973
|
-
const id = setInterval(() => void run(input), interval);
|
|
1059
|
+
const id = setInterval(() => void run(input), getMs(interval));
|
|
974
1060
|
return () => clearInterval(id);
|
|
975
1061
|
}
|
|
976
1062
|
};
|
|
@@ -982,62 +1068,80 @@ var Op;
|
|
|
982
1068
|
Op2.nil = (reason) => ({ kind: "OpNil", reason });
|
|
983
1069
|
Op2.create = (factory, onError) => ({
|
|
984
1070
|
_factory: (input, signal) => Deferred.fromPromise(
|
|
985
|
-
factory(signal)(input).then((value) => Result.ok(value)).catch(
|
|
1071
|
+
factory(signal)(input).then((value) => Result.ok(value)).catch(
|
|
1072
|
+
(error) => signal.aborted ? null : Result.err(onError(error))
|
|
1073
|
+
)
|
|
986
1074
|
)
|
|
987
1075
|
});
|
|
988
|
-
Op2.lift = (f) => (0, Op2.create)(
|
|
989
|
-
(signal) => (input) => f(input, signal),
|
|
990
|
-
(e) => e
|
|
991
|
-
);
|
|
1076
|
+
Op2.lift = (f) => (0, Op2.create)((signal) => (input) => f(input, signal), (e) => e);
|
|
992
1077
|
Op2.ok = (value) => ({ kind: "OpOk", value });
|
|
993
|
-
Op2.
|
|
1078
|
+
Op2.err = (error) => ({ kind: "OpErr", error });
|
|
994
1079
|
Op2.isIdle = (state) => state.kind === "Idle";
|
|
995
1080
|
Op2.isPending = (state) => state.kind === "Pending";
|
|
996
1081
|
Op2.isQueued = (state) => state.kind === "Queued";
|
|
997
1082
|
Op2.isRetrying = (state) => state.kind === "Retrying";
|
|
998
1083
|
Op2.isOk = (state) => state.kind === "OpOk";
|
|
999
|
-
Op2.
|
|
1084
|
+
Op2.isErr = (state) => state.kind === "OpErr";
|
|
1000
1085
|
Op2.isNil = (state) => state.kind === "OpNil";
|
|
1001
1086
|
Op2.match = (cases) => (outcome) => {
|
|
1002
|
-
if (outcome.kind === "OpOk")
|
|
1003
|
-
|
|
1087
|
+
if (outcome.kind === "OpOk") {
|
|
1088
|
+
return cases.ok(outcome.value);
|
|
1089
|
+
}
|
|
1090
|
+
if (outcome.kind === "OpErr") {
|
|
1091
|
+
return cases.err(outcome.error);
|
|
1092
|
+
}
|
|
1004
1093
|
return cases.nil();
|
|
1005
1094
|
};
|
|
1006
|
-
Op2.fold = (
|
|
1007
|
-
if (outcome.kind === "OpOk")
|
|
1008
|
-
|
|
1095
|
+
Op2.fold = (onErr, onOk, onNil) => (outcome) => {
|
|
1096
|
+
if (outcome.kind === "OpOk") {
|
|
1097
|
+
return onOk(outcome.value);
|
|
1098
|
+
}
|
|
1099
|
+
if (outcome.kind === "OpErr") {
|
|
1100
|
+
return onErr(outcome.error);
|
|
1101
|
+
}
|
|
1009
1102
|
return onNil();
|
|
1010
1103
|
};
|
|
1011
1104
|
Op2.getOrElse = (defaultValue) => (outcome) => outcome.kind === "OpOk" ? outcome.value : defaultValue();
|
|
1012
1105
|
Op2.map = (f) => (outcome) => outcome.kind === "OpOk" ? (0, Op2.ok)(f(outcome.value)) : outcome;
|
|
1013
|
-
Op2.mapError = (f) => (outcome) => outcome.kind === "
|
|
1106
|
+
Op2.mapError = (f) => (outcome) => outcome.kind === "OpErr" ? (0, Op2.err)(f(outcome.error)) : outcome;
|
|
1014
1107
|
Op2.chain = (f) => (outcome) => outcome.kind === "OpOk" ? f(outcome.value) : outcome;
|
|
1015
1108
|
Op2.tap = (f) => (outcome) => {
|
|
1016
|
-
if (outcome.kind === "OpOk")
|
|
1109
|
+
if (outcome.kind === "OpOk") {
|
|
1110
|
+
f(outcome.value);
|
|
1111
|
+
}
|
|
1017
1112
|
return outcome;
|
|
1018
1113
|
};
|
|
1019
|
-
Op2.recover = (f) => (outcome) => outcome.kind === "
|
|
1114
|
+
Op2.recover = (f) => (outcome) => outcome.kind === "OpErr" ? f(outcome.error) : outcome;
|
|
1020
1115
|
Op2.toResult = (onNil) => (outcome) => {
|
|
1021
|
-
if (outcome.kind === "OpOk")
|
|
1022
|
-
|
|
1023
|
-
|
|
1116
|
+
if (outcome.kind === "OpOk") {
|
|
1117
|
+
return Result.ok(outcome.value);
|
|
1118
|
+
}
|
|
1119
|
+
if (outcome.kind === "OpErr") {
|
|
1120
|
+
return Result.err(outcome.error);
|
|
1121
|
+
}
|
|
1122
|
+
return Result.err(onNil());
|
|
1024
1123
|
};
|
|
1025
1124
|
Op2.toMaybe = (outcome) => outcome.kind === "OpOk" ? Maybe.some(outcome.value) : Maybe.none();
|
|
1026
1125
|
Op2.all = (invocations) => Deferred.fromPromise(Promise.all(invocations.map(Deferred.toPromise)));
|
|
1027
1126
|
Op2.race = (invocations) => Deferred.fromPromise(Promise.race(invocations.map(Deferred.toPromise)));
|
|
1028
1127
|
Op2.wire = (source, f) => source.subscribe((state) => {
|
|
1029
|
-
if ((0, Op2.isOk)(state))
|
|
1128
|
+
if ((0, Op2.isOk)(state)) {
|
|
1129
|
+
f(state.value);
|
|
1130
|
+
}
|
|
1030
1131
|
});
|
|
1031
1132
|
function interpret(op, options) {
|
|
1032
1133
|
const { strategy, retry: retryOptions, timeout: timeoutOptions } = options;
|
|
1033
1134
|
switch (strategy) {
|
|
1034
|
-
case "once":
|
|
1135
|
+
case "once": {
|
|
1035
1136
|
return makeOnce(op, retryOptions, timeoutOptions);
|
|
1036
|
-
|
|
1137
|
+
}
|
|
1138
|
+
case "restartable": {
|
|
1037
1139
|
return makeRestartable(op, options.minInterval, retryOptions, timeoutOptions);
|
|
1038
|
-
|
|
1140
|
+
}
|
|
1141
|
+
case "exclusive": {
|
|
1039
1142
|
return makeExclusive(op, options.cooldown, retryOptions, timeoutOptions);
|
|
1040
|
-
|
|
1143
|
+
}
|
|
1144
|
+
case "queue": {
|
|
1041
1145
|
return makeQueue(
|
|
1042
1146
|
op,
|
|
1043
1147
|
options.maxSize,
|
|
@@ -1047,13 +1151,24 @@ var Op;
|
|
|
1047
1151
|
retryOptions,
|
|
1048
1152
|
timeoutOptions
|
|
1049
1153
|
);
|
|
1050
|
-
|
|
1154
|
+
}
|
|
1155
|
+
case "buffered": {
|
|
1051
1156
|
return makeBuffered(op, options.size, retryOptions, timeoutOptions);
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1157
|
+
}
|
|
1158
|
+
case "debounced": {
|
|
1159
|
+
return makeDebounced(
|
|
1160
|
+
op,
|
|
1161
|
+
options.duration,
|
|
1162
|
+
options.leading ?? false,
|
|
1163
|
+
options.maxWait,
|
|
1164
|
+
retryOptions,
|
|
1165
|
+
timeoutOptions
|
|
1166
|
+
);
|
|
1167
|
+
}
|
|
1168
|
+
case "throttled": {
|
|
1169
|
+
return makeThrottled(op, options.duration, options.trailing ?? false, retryOptions, timeoutOptions);
|
|
1170
|
+
}
|
|
1171
|
+
case "concurrent": {
|
|
1057
1172
|
return makeConcurrent(
|
|
1058
1173
|
op,
|
|
1059
1174
|
options.n ?? 1,
|
|
@@ -1061,8 +1176,10 @@ var Op;
|
|
|
1061
1176
|
retryOptions,
|
|
1062
1177
|
timeoutOptions
|
|
1063
1178
|
);
|
|
1064
|
-
|
|
1179
|
+
}
|
|
1180
|
+
case "keyed": {
|
|
1065
1181
|
return makeKeyed(op, options.key ?? ((i) => i), options.perKey ?? "exclusive", timeoutOptions);
|
|
1182
|
+
}
|
|
1066
1183
|
}
|
|
1067
1184
|
}
|
|
1068
1185
|
Op2.interpret = interpret;
|
|
@@ -1072,22 +1189,18 @@ var Op;
|
|
|
1072
1189
|
var Optional;
|
|
1073
1190
|
((Optional2) => {
|
|
1074
1191
|
Optional2.make = (get2, set2) => ({ get: get2, set: set2 });
|
|
1075
|
-
Optional2.prop = () => (key) => (0, Optional2.make)(
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
Optional2.index = (i) => (0, Optional2.make)(
|
|
1083
|
-
(arr) => i >= 0 && i < arr.length ? Maybe.some(arr[i]) : Maybe.none(),
|
|
1084
|
-
(a) => (arr) => {
|
|
1085
|
-
if (i < 0 || i >= arr.length) return arr;
|
|
1086
|
-
const copy = [...arr];
|
|
1087
|
-
copy[i] = a;
|
|
1088
|
-
return copy;
|
|
1192
|
+
Optional2.prop = () => (key) => (0, Optional2.make)((s) => {
|
|
1193
|
+
const val = s[key];
|
|
1194
|
+
return val !== null && val !== void 0 ? Maybe.some(val) : Maybe.none();
|
|
1195
|
+
}, (a) => (s) => ({ ...s, [key]: a }));
|
|
1196
|
+
Optional2.index = (i) => (0, Optional2.make)((arr) => i >= 0 && i < arr.length ? Maybe.some(arr[i]) : Maybe.none(), (a) => (arr) => {
|
|
1197
|
+
if (i < 0 || i >= arr.length) {
|
|
1198
|
+
return arr;
|
|
1089
1199
|
}
|
|
1090
|
-
|
|
1200
|
+
const copy = [...arr];
|
|
1201
|
+
copy[i] = a;
|
|
1202
|
+
return copy;
|
|
1203
|
+
});
|
|
1091
1204
|
Optional2.get = (opt) => (s) => opt.get(s);
|
|
1092
1205
|
Optional2.set = (opt) => (a) => (s) => opt.set(a)(s);
|
|
1093
1206
|
Optional2.modify = (opt) => (f) => (s) => {
|
|
@@ -1106,26 +1219,20 @@ var Optional;
|
|
|
1106
1219
|
const val = opt.get(s);
|
|
1107
1220
|
return val.kind === "Some" ? cases.some(val.value) : cases.none();
|
|
1108
1221
|
};
|
|
1109
|
-
Optional2.andThen = (inner) => (outer) => (0, Optional2.make)(
|
|
1110
|
-
(s)
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
(b)
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
(s)
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
},
|
|
1124
|
-
(b) => (s) => {
|
|
1125
|
-
const mid = outer.get(s);
|
|
1126
|
-
return mid.kind === "None" ? s : outer.set(inner.set(b)(mid.value))(s);
|
|
1127
|
-
}
|
|
1128
|
-
);
|
|
1222
|
+
Optional2.andThen = (inner) => (outer) => (0, Optional2.make)((s) => {
|
|
1223
|
+
const mid = outer.get(s);
|
|
1224
|
+
return mid.kind === "None" ? Maybe.none() : inner.get(mid.value);
|
|
1225
|
+
}, (b) => (s) => {
|
|
1226
|
+
const mid = outer.get(s);
|
|
1227
|
+
return mid.kind === "None" ? s : outer.set(inner.set(b)(mid.value))(s);
|
|
1228
|
+
});
|
|
1229
|
+
Optional2.andThenLens = (inner) => (outer) => (0, Optional2.make)((s) => {
|
|
1230
|
+
const mid = outer.get(s);
|
|
1231
|
+
return mid.kind === "None" ? Maybe.none() : Maybe.some(inner.get(mid.value));
|
|
1232
|
+
}, (b) => (s) => {
|
|
1233
|
+
const mid = outer.get(s);
|
|
1234
|
+
return mid.kind === "None" ? s : outer.set(inner.set(b)(mid.value))(s);
|
|
1235
|
+
});
|
|
1129
1236
|
})(Optional || (Optional = {}));
|
|
1130
1237
|
|
|
1131
1238
|
// src/Core/Ordering.ts
|
|
@@ -1180,7 +1287,7 @@ var Refinement;
|
|
|
1180
1287
|
Refinement2.and = (second) => (first) => (a) => first(a) && second(a);
|
|
1181
1288
|
Refinement2.or = (second) => (first) => (a) => first(a) || second(a);
|
|
1182
1289
|
Refinement2.toFilter = (r) => (a) => r(a) ? Maybe.some(a) : Maybe.none();
|
|
1183
|
-
Refinement2.toResult = (r, onFail) => (a) => r(a) ? Result.ok(a) : Result.
|
|
1290
|
+
Refinement2.toResult = (r, onFail) => (a) => r(a) ? Result.ok(a) : Result.err(onFail(a));
|
|
1184
1291
|
})(Refinement || (Refinement = {}));
|
|
1185
1292
|
|
|
1186
1293
|
// src/Core/RemoteData.ts
|
|
@@ -1190,14 +1297,8 @@ var RemoteData;
|
|
|
1190
1297
|
((RemoteData2) => {
|
|
1191
1298
|
RemoteData2.notAsked = () => _notAsked;
|
|
1192
1299
|
RemoteData2.loading = () => _loading;
|
|
1193
|
-
RemoteData2.failure = (error) => ({
|
|
1194
|
-
|
|
1195
|
-
error
|
|
1196
|
-
});
|
|
1197
|
-
RemoteData2.success = (value) => ({
|
|
1198
|
-
kind: "Success",
|
|
1199
|
-
value
|
|
1200
|
-
});
|
|
1300
|
+
RemoteData2.failure = (error) => ({ kind: "Failure", error });
|
|
1301
|
+
RemoteData2.success = (value) => ({ kind: "Success", value });
|
|
1201
1302
|
RemoteData2.isNotAsked = (data) => data.kind === "NotAsked";
|
|
1202
1303
|
RemoteData2.isLoading = (data) => data.kind === "Loading";
|
|
1203
1304
|
RemoteData2.isFailure = (data) => data.kind === "Failure";
|
|
@@ -1209,47 +1310,65 @@ var RemoteData;
|
|
|
1209
1310
|
if ((0, RemoteData2.isSuccess)(data) && (0, RemoteData2.isSuccess)(arg)) {
|
|
1210
1311
|
return (0, RemoteData2.success)(data.value(arg.value));
|
|
1211
1312
|
}
|
|
1212
|
-
if ((0, RemoteData2.isFailure)(data))
|
|
1213
|
-
|
|
1214
|
-
|
|
1313
|
+
if ((0, RemoteData2.isFailure)(data)) {
|
|
1314
|
+
return data;
|
|
1315
|
+
}
|
|
1316
|
+
if ((0, RemoteData2.isFailure)(arg)) {
|
|
1317
|
+
return arg;
|
|
1318
|
+
}
|
|
1319
|
+
if ((0, RemoteData2.isLoading)(data) || (0, RemoteData2.isLoading)(arg)) {
|
|
1320
|
+
return (0, RemoteData2.loading)();
|
|
1321
|
+
}
|
|
1215
1322
|
return (0, RemoteData2.notAsked)();
|
|
1216
1323
|
};
|
|
1217
1324
|
RemoteData2.fold = (onNotAsked, onLoading, onFailure, onSuccess) => (data) => {
|
|
1218
1325
|
switch (data.kind) {
|
|
1219
|
-
case "NotAsked":
|
|
1326
|
+
case "NotAsked": {
|
|
1220
1327
|
return onNotAsked();
|
|
1221
|
-
|
|
1328
|
+
}
|
|
1329
|
+
case "Loading": {
|
|
1222
1330
|
return onLoading();
|
|
1223
|
-
|
|
1331
|
+
}
|
|
1332
|
+
case "Failure": {
|
|
1224
1333
|
return onFailure(data.error);
|
|
1225
|
-
|
|
1334
|
+
}
|
|
1335
|
+
case "Success": {
|
|
1226
1336
|
return onSuccess(data.value);
|
|
1337
|
+
}
|
|
1227
1338
|
}
|
|
1228
1339
|
};
|
|
1229
1340
|
RemoteData2.match = (cases) => (data) => {
|
|
1230
1341
|
switch (data.kind) {
|
|
1231
|
-
case "NotAsked":
|
|
1342
|
+
case "NotAsked": {
|
|
1232
1343
|
return cases.notAsked();
|
|
1233
|
-
|
|
1344
|
+
}
|
|
1345
|
+
case "Loading": {
|
|
1234
1346
|
return cases.loading();
|
|
1235
|
-
|
|
1347
|
+
}
|
|
1348
|
+
case "Failure": {
|
|
1236
1349
|
return cases.failure(data.error);
|
|
1237
|
-
|
|
1350
|
+
}
|
|
1351
|
+
case "Success": {
|
|
1238
1352
|
return cases.success(data.value);
|
|
1353
|
+
}
|
|
1239
1354
|
}
|
|
1240
1355
|
};
|
|
1241
1356
|
RemoteData2.getOrElse = (defaultValue) => (data) => (0, RemoteData2.isSuccess)(data) ? data.value : defaultValue();
|
|
1242
1357
|
RemoteData2.tap = (f) => (data) => {
|
|
1243
|
-
if ((0, RemoteData2.isSuccess)(data))
|
|
1358
|
+
if ((0, RemoteData2.isSuccess)(data)) {
|
|
1359
|
+
f(data.value);
|
|
1360
|
+
}
|
|
1244
1361
|
return data;
|
|
1245
1362
|
};
|
|
1246
1363
|
RemoteData2.tapError = (f) => (data) => {
|
|
1247
|
-
if ((0, RemoteData2.isFailure)(data))
|
|
1364
|
+
if ((0, RemoteData2.isFailure)(data)) {
|
|
1365
|
+
f(data.error);
|
|
1366
|
+
}
|
|
1248
1367
|
return data;
|
|
1249
1368
|
};
|
|
1250
1369
|
RemoteData2.recover = (fallback) => (data) => (0, RemoteData2.isFailure)(data) ? fallback(data.error) : data;
|
|
1251
1370
|
RemoteData2.toMaybe = (data) => (0, RemoteData2.isSuccess)(data) ? Maybe.some(data.value) : Maybe.none();
|
|
1252
|
-
RemoteData2.toResult = (onNotReady) => (data) => (0, RemoteData2.isSuccess)(data) ? Result.ok(data.value) : Result.
|
|
1371
|
+
RemoteData2.toResult = (onNotReady) => (data) => (0, RemoteData2.isSuccess)(data) ? Result.ok(data.value) : Result.err((0, RemoteData2.isFailure)(data) ? data.error : onNotReady());
|
|
1253
1372
|
RemoteData2.fromResult = (data) => Result.isOk(data) ? (0, RemoteData2.success)(data.value) : (0, RemoteData2.failure)(data.error);
|
|
1254
1373
|
RemoteData2.fromMaybe = (onNone) => (data) => Maybe.isSome(data) ? (0, RemoteData2.success)(data.value) : (0, RemoteData2.failure)(onNone());
|
|
1255
1374
|
RemoteData2.filter = (pred, onFalse) => (data) => (0, RemoteData2.isSuccess)(data) ? pred(data.value) ? data : (0, RemoteData2.failure)(onFalse(data.value)) : data;
|
|
@@ -1258,14 +1377,19 @@ var RemoteData;
|
|
|
1258
1377
|
// src/Core/Resource.ts
|
|
1259
1378
|
var Resource;
|
|
1260
1379
|
((Resource2) => {
|
|
1261
|
-
Resource2.make = (acquire, release) => ({
|
|
1380
|
+
Resource2.make = (acquire, release) => ({
|
|
1381
|
+
acquire,
|
|
1382
|
+
release
|
|
1383
|
+
});
|
|
1262
1384
|
Resource2.fromTask = (acquire, release) => ({
|
|
1263
1385
|
acquire: Task.map((a) => Result.ok(a))(acquire),
|
|
1264
1386
|
release
|
|
1265
1387
|
});
|
|
1266
1388
|
Resource2.use = (f) => (resource) => Task.from(
|
|
1267
1389
|
(signal) => Deferred.toPromise(resource.acquire(signal)).then(async (acquired) => {
|
|
1268
|
-
if (Result.
|
|
1390
|
+
if (Result.isErr(acquired)) {
|
|
1391
|
+
return acquired;
|
|
1392
|
+
}
|
|
1269
1393
|
const a = acquired.value;
|
|
1270
1394
|
try {
|
|
1271
1395
|
const usageResult = await Deferred.toPromise(f(a)(signal));
|
|
@@ -1278,10 +1402,12 @@ var Resource;
|
|
|
1278
1402
|
Resource2.combine = (resourceA, resourceB) => ({
|
|
1279
1403
|
acquire: Task.from(
|
|
1280
1404
|
(signal) => Deferred.toPromise(resourceA.acquire(signal)).then(async (acquiredA) => {
|
|
1281
|
-
if (Result.
|
|
1405
|
+
if (Result.isErr(acquiredA)) {
|
|
1406
|
+
return acquiredA;
|
|
1407
|
+
}
|
|
1282
1408
|
const a = acquiredA.value;
|
|
1283
1409
|
const acquiredB = await Deferred.toPromise(resourceB.acquire(signal));
|
|
1284
|
-
if (Result.
|
|
1410
|
+
if (Result.isErr(acquiredB)) {
|
|
1285
1411
|
await Deferred.toPromise(resourceA.release(a)(signal));
|
|
1286
1412
|
return acquiredB;
|
|
1287
1413
|
}
|
|
@@ -1334,16 +1460,13 @@ var TaskMaybe;
|
|
|
1334
1460
|
TaskMaybe2.fromNullable = (value) => Task.resolve(Maybe.fromNullable(value));
|
|
1335
1461
|
TaskMaybe2.fromResult = (result) => Task.resolve(Result.toMaybe(result));
|
|
1336
1462
|
TaskMaybe2.fromTask = (task) => Task.map(Maybe.some)(task);
|
|
1337
|
-
TaskMaybe2.tryCatch = (f) => Task.from(
|
|
1338
|
-
(signal) => f(signal).then(Maybe.some).catch(() => Maybe.none())
|
|
1339
|
-
);
|
|
1463
|
+
TaskMaybe2.tryCatch = (f) => Task.from((signal) => f(signal).then(Maybe.some).catch(() => Maybe.none()));
|
|
1340
1464
|
TaskMaybe2.map = (f) => (data) => Task.map(Maybe.map(f))(data);
|
|
1341
1465
|
TaskMaybe2.chain = (f) => (data) => Task.chain((option) => Maybe.isSome(option) ? f(option.value) : Task.resolve(Maybe.none()))(data);
|
|
1342
1466
|
TaskMaybe2.ap = (arg) => (data) => Task.from(
|
|
1343
|
-
(signal) => Promise.all([
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
]).then(([of_, oa]) => Maybe.ap(oa)(of_))
|
|
1467
|
+
(signal) => Promise.all([Deferred.toPromise(data(signal)), Deferred.toPromise(arg(signal))]).then(
|
|
1468
|
+
([of_, oa]) => Maybe.ap(oa)(of_)
|
|
1469
|
+
)
|
|
1347
1470
|
);
|
|
1348
1471
|
TaskMaybe2.fold = (onNone, onSome) => (data) => Task.map(Maybe.fold(onNone, onSome))(data);
|
|
1349
1472
|
TaskMaybe2.match = (cases) => (data) => Task.map(Maybe.match(cases))(data);
|
|
@@ -1357,36 +1480,29 @@ var TaskMaybe;
|
|
|
1357
1480
|
var TaskResult;
|
|
1358
1481
|
((TaskResult2) => {
|
|
1359
1482
|
TaskResult2.ok = (value) => Task.resolve(Result.ok(value));
|
|
1360
|
-
TaskResult2.err = (error) => Task.resolve(Result.
|
|
1361
|
-
TaskResult2.fromNullable = (onNull) => (value) => Task.resolve(value === null || value === void 0 ? Result.
|
|
1362
|
-
TaskResult2.fromMaybe = (onNone) => (maybe) => Task.resolve(Maybe.isNone(maybe) ? Result.
|
|
1483
|
+
TaskResult2.err = (error) => Task.resolve(Result.err(error));
|
|
1484
|
+
TaskResult2.fromNullable = (onNull) => (value) => Task.resolve(value === null || value === void 0 ? Result.err(onNull()) : Result.ok(value));
|
|
1485
|
+
TaskResult2.fromMaybe = (onNone) => (maybe) => Task.resolve(Maybe.isNone(maybe) ? Result.err(onNone()) : Result.ok(maybe.value));
|
|
1363
1486
|
TaskResult2.fromResult = (result) => Task.resolve(result);
|
|
1364
|
-
TaskResult2.fromThrowable = (f, onError) => (...args) => Task.from(
|
|
1365
|
-
|
|
1366
|
-
);
|
|
1367
|
-
TaskResult2.tryCatch = (f, onError) => Task.from(
|
|
1368
|
-
(signal) => f(signal).then(Result.ok).catch((e) => Result.error(onError(e)))
|
|
1369
|
-
);
|
|
1487
|
+
TaskResult2.fromThrowable = (f, onError) => (...args) => Task.from(() => f(...args).then(Result.ok).catch((error) => Result.err(onError(error))));
|
|
1488
|
+
TaskResult2.tryCatch = (f, onError) => Task.from((signal) => f(signal).then(Result.ok).catch((error) => Result.err(onError(error))));
|
|
1370
1489
|
TaskResult2.map = (f) => (data) => Task.map(Result.map(f))(data);
|
|
1371
1490
|
TaskResult2.mapError = (f) => (data) => Task.map(Result.mapError(f))(data);
|
|
1372
|
-
TaskResult2.chain = (f) => (data) => Task.chain(
|
|
1373
|
-
(result) => Result.isOk(result) ? f(result.value) : Task.resolve(Result.error(result.error))
|
|
1374
|
-
)(
|
|
1491
|
+
TaskResult2.chain = (f) => (data) => Task.chain((result) => Result.isOk(result) ? f(result.value) : Task.resolve(Result.err(result.error)))(
|
|
1375
1492
|
data
|
|
1376
1493
|
);
|
|
1377
1494
|
TaskResult2.fold = (onErr, onOk) => (data) => Task.map(Result.fold(onErr, onOk))(data);
|
|
1378
1495
|
TaskResult2.match = (cases) => (data) => Task.map(Result.match(cases))(data);
|
|
1379
1496
|
TaskResult2.recover = (fallback) => (data) => Task.chain(
|
|
1380
|
-
(result) => Result.
|
|
1497
|
+
(result) => Result.isErr(result) ? fallback(result.error) : Task.resolve(result)
|
|
1381
1498
|
)(data);
|
|
1382
1499
|
TaskResult2.getOrElse = (defaultValue) => (data) => Task.map(Result.getOrElse(defaultValue))(data);
|
|
1383
1500
|
TaskResult2.tap = (f) => (data) => Task.map(Result.tap(f))(data);
|
|
1384
1501
|
TaskResult2.tapError = (f) => (data) => Task.map(Result.tapError(f))(data);
|
|
1385
1502
|
TaskResult2.ap = (arg) => (data) => Task.from(
|
|
1386
|
-
(signal) => Promise.all([
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
]).then(([of_, oa]) => Result.ap(oa)(of_))
|
|
1503
|
+
(signal) => Promise.all([Deferred.toPromise(data(signal)), Deferred.toPromise(arg(signal))]).then(
|
|
1504
|
+
([of_, oa]) => Result.ap(oa)(of_)
|
|
1505
|
+
)
|
|
1390
1506
|
);
|
|
1391
1507
|
TaskResult2.run = (signal) => (task) => Deferred.toPromise(task(signal));
|
|
1392
1508
|
})(TaskResult || (TaskResult = {}));
|
|
@@ -1394,102 +1510,97 @@ var TaskResult;
|
|
|
1394
1510
|
// src/Core/Validation.ts
|
|
1395
1511
|
var Validation;
|
|
1396
1512
|
((Validation2) => {
|
|
1397
|
-
Validation2.
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
Validation2.
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
Validation2.
|
|
1406
|
-
|
|
1407
|
-
errors
|
|
1408
|
-
});
|
|
1409
|
-
Validation2.isValid = (data) => data.kind === "Valid";
|
|
1410
|
-
Validation2.isInvalid = (data) => data.kind === "Invalid";
|
|
1411
|
-
Validation2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Validation2.valid)(a) : (0, Validation2.invalid)(onFalse(a));
|
|
1412
|
-
Validation2.fromNullable = (onNull) => (value) => value === null || value === void 0 ? (0, Validation2.invalid)(onNull()) : (0, Validation2.valid)(value);
|
|
1413
|
-
Validation2.fromMaybe = (onNone) => (maybe) => Maybe.isNone(maybe) ? (0, Validation2.invalid)(onNone()) : (0, Validation2.valid)(maybe.value);
|
|
1414
|
-
Validation2.map = (f) => (data) => (0, Validation2.isValid)(data) ? (0, Validation2.valid)(f(data.value)) : data;
|
|
1513
|
+
Validation2.passed = (value) => ({ kind: "Passed", value });
|
|
1514
|
+
Validation2.failed = (error) => ({ kind: "Failed", errors: [error] });
|
|
1515
|
+
Validation2.failedAll = (errors) => ({ kind: "Failed", errors });
|
|
1516
|
+
Validation2.isPassed = (data) => data.kind === "Passed";
|
|
1517
|
+
Validation2.isFailed = (data) => data.kind === "Failed";
|
|
1518
|
+
Validation2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Validation2.passed)(a) : (0, Validation2.failed)(onFalse(a));
|
|
1519
|
+
Validation2.fromNullable = (onNull) => (value) => value === null || value === void 0 ? (0, Validation2.failed)(onNull()) : (0, Validation2.passed)(value);
|
|
1520
|
+
Validation2.fromMaybe = (onNone) => (maybe) => Maybe.isNone(maybe) ? (0, Validation2.failed)(onNone()) : (0, Validation2.passed)(maybe.value);
|
|
1521
|
+
Validation2.map = (f) => (data) => (0, Validation2.isPassed)(data) ? (0, Validation2.passed)(f(data.value)) : data;
|
|
1522
|
+
Validation2.mapError = (f) => (data) => (0, Validation2.isFailed)(data) ? (0, Validation2.failedAll)(data.errors.map(f)) : data;
|
|
1415
1523
|
Validation2.ap = (arg) => (data) => {
|
|
1416
|
-
if ((0, Validation2.
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
Validation2.
|
|
1424
|
-
Validation2.
|
|
1425
|
-
Validation2.getOrElse = (defaultValue) => (data) => (0, Validation2.isValid)(data) ? data.value : defaultValue();
|
|
1524
|
+
if ((0, Validation2.isPassed)(data) && (0, Validation2.isPassed)(arg)) {
|
|
1525
|
+
return (0, Validation2.passed)(data.value(arg.value));
|
|
1526
|
+
}
|
|
1527
|
+
const errors = [...(0, Validation2.isFailed)(data) ? data.errors : [], ...(0, Validation2.isFailed)(arg) ? arg.errors : []];
|
|
1528
|
+
return (0, Validation2.failedAll)(errors);
|
|
1529
|
+
};
|
|
1530
|
+
Validation2.fold = (onFailed, onPassed) => (data) => (0, Validation2.isPassed)(data) ? onPassed(data.value) : onFailed(data.errors);
|
|
1531
|
+
Validation2.match = (cases) => (data) => (0, Validation2.isPassed)(data) ? cases.passed(data.value) : cases.failed(data.errors);
|
|
1532
|
+
Validation2.getOrElse = (defaultValue) => (data) => (0, Validation2.isPassed)(data) ? data.value : defaultValue();
|
|
1426
1533
|
Validation2.tap = (f) => (data) => {
|
|
1427
|
-
if ((0, Validation2.
|
|
1534
|
+
if ((0, Validation2.isPassed)(data)) {
|
|
1535
|
+
f(data.value);
|
|
1536
|
+
}
|
|
1428
1537
|
return data;
|
|
1429
1538
|
};
|
|
1430
1539
|
Validation2.tapError = (f) => (data) => {
|
|
1431
|
-
if ((0, Validation2.
|
|
1540
|
+
if ((0, Validation2.isFailed)(data)) {
|
|
1541
|
+
f(data.errors);
|
|
1542
|
+
}
|
|
1432
1543
|
return data;
|
|
1433
1544
|
};
|
|
1434
|
-
Validation2.recover = (fallback) => (data) => (0, Validation2.
|
|
1435
|
-
Validation2.recoverUnless = (isBlocked, fallback) => (data) => (0, Validation2.
|
|
1436
|
-
Validation2.toResult = (data) => (0, Validation2.
|
|
1437
|
-
Validation2.toMaybe = (data) => (0, Validation2.
|
|
1438
|
-
Validation2.fromResult = (data) => data.kind === "Ok" ? (0, Validation2.
|
|
1545
|
+
Validation2.recover = (fallback) => (data) => (0, Validation2.isPassed)(data) ? data : fallback(data.errors);
|
|
1546
|
+
Validation2.recoverUnless = (isBlocked, fallback) => (data) => (0, Validation2.isFailed)(data) && !data.errors.some(isBlocked) ? fallback() : data;
|
|
1547
|
+
Validation2.toResult = (data) => (0, Validation2.isPassed)(data) ? Result.ok(data.value) : Result.err(data.errors);
|
|
1548
|
+
Validation2.toMaybe = (data) => (0, Validation2.isPassed)(data) ? Maybe.some(data.value) : Maybe.none();
|
|
1549
|
+
Validation2.fromResult = (data) => data.kind === "Ok" ? (0, Validation2.passed)(data.value) : (0, Validation2.failed)(data.error);
|
|
1439
1550
|
Validation2.product = (first, second) => {
|
|
1440
|
-
if ((0, Validation2.
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
return (0, Validation2.invalidAll)(errors);
|
|
1551
|
+
if ((0, Validation2.isPassed)(first) && (0, Validation2.isPassed)(second)) {
|
|
1552
|
+
return (0, Validation2.passed)([first.value, second.value]);
|
|
1553
|
+
}
|
|
1554
|
+
const errors = [...(0, Validation2.isFailed)(first) ? first.errors : [], ...(0, Validation2.isFailed)(second) ? second.errors : []];
|
|
1555
|
+
return (0, Validation2.failedAll)(errors);
|
|
1446
1556
|
};
|
|
1447
1557
|
Validation2.productAll = (data) => {
|
|
1448
1558
|
const values = [];
|
|
1449
1559
|
const errors = [];
|
|
1450
1560
|
for (const v of data) {
|
|
1451
|
-
if ((0, Validation2.
|
|
1452
|
-
|
|
1561
|
+
if ((0, Validation2.isPassed)(v)) {
|
|
1562
|
+
values.push(v.value);
|
|
1563
|
+
} else {
|
|
1564
|
+
errors.push(...v.errors);
|
|
1565
|
+
}
|
|
1453
1566
|
}
|
|
1454
|
-
return errors.length > 0 ? (0, Validation2.
|
|
1567
|
+
return errors.length > 0 ? (0, Validation2.failedAll)(errors) : (0, Validation2.passed)(values);
|
|
1455
1568
|
};
|
|
1456
1569
|
})(Validation || (Validation = {}));
|
|
1457
1570
|
|
|
1458
1571
|
// src/Core/TaskValidation.ts
|
|
1459
1572
|
var TaskValidation;
|
|
1460
1573
|
((TaskValidation2) => {
|
|
1461
|
-
TaskValidation2.
|
|
1462
|
-
TaskValidation2.
|
|
1463
|
-
TaskValidation2.
|
|
1574
|
+
TaskValidation2.passed = (value) => Task.resolve(Validation.passed(value));
|
|
1575
|
+
TaskValidation2.failed = (error) => Task.resolve(Validation.failed(error));
|
|
1576
|
+
TaskValidation2.failedAll = (errors) => Task.resolve(Validation.failedAll(errors));
|
|
1464
1577
|
TaskValidation2.fromValidation = (validation) => Task.resolve(validation);
|
|
1465
|
-
TaskValidation2.fromNullable = (onNull) => (value) => Task.resolve(value === null || value === void 0 ? Validation.
|
|
1466
|
-
TaskValidation2.fromMaybe = (onNone) => (maybe) => Task.resolve(Maybe.isNone(maybe) ? Validation.
|
|
1578
|
+
TaskValidation2.fromNullable = (onNull) => (value) => Task.resolve(value === null || value === void 0 ? Validation.failed(onNull()) : Validation.passed(value));
|
|
1579
|
+
TaskValidation2.fromMaybe = (onNone) => (maybe) => Task.resolve(Maybe.isNone(maybe) ? Validation.failed(onNone()) : Validation.passed(maybe.value));
|
|
1467
1580
|
TaskValidation2.fromResult = (result) => Task.resolve(Validation.fromResult(result));
|
|
1468
|
-
TaskValidation2.tryCatch = (f, onError) => Task.from(
|
|
1469
|
-
(signal) => f(signal).then(Validation.valid).catch((e) => Validation.invalid(onError(e)))
|
|
1470
|
-
);
|
|
1581
|
+
TaskValidation2.tryCatch = (f, onError) => Task.from((signal) => f(signal).then(Validation.passed).catch((error) => Validation.failed(onError(error))));
|
|
1471
1582
|
TaskValidation2.map = (f) => (data) => Task.map(Validation.map(f))(data);
|
|
1472
1583
|
TaskValidation2.ap = (arg) => (data) => Task.from(
|
|
1473
|
-
(signal) => Promise.all([
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
]).then(([vf, va]) => Validation.ap(va)(vf))
|
|
1584
|
+
(signal) => Promise.all([Deferred.toPromise(data(signal)), Deferred.toPromise(arg(signal))]).then(
|
|
1585
|
+
([vf, va]) => Validation.ap(va)(vf)
|
|
1586
|
+
)
|
|
1477
1587
|
);
|
|
1478
|
-
TaskValidation2.fold = (
|
|
1588
|
+
TaskValidation2.fold = (onFailed, onPassed) => (data) => Task.map(Validation.fold(onFailed, onPassed))(data);
|
|
1479
1589
|
TaskValidation2.match = (cases) => (data) => Task.map(Validation.match(cases))(data);
|
|
1480
1590
|
TaskValidation2.getOrElse = (defaultValue) => (data) => Task.map(Validation.getOrElse(defaultValue))(data);
|
|
1481
1591
|
TaskValidation2.tap = (f) => (data) => Task.map(Validation.tap(f))(data);
|
|
1482
1592
|
TaskValidation2.recover = (fallback) => (data) => Task.chain(
|
|
1483
|
-
(validation) => Validation.
|
|
1593
|
+
(validation) => Validation.isPassed(validation) ? Task.resolve(validation) : fallback(validation.errors)
|
|
1484
1594
|
)(data);
|
|
1485
1595
|
TaskValidation2.product = (first, second) => Task.from(
|
|
1486
|
-
(signal) => Promise.all([
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
]).then(([va, vb]) => Validation.product(va, vb))
|
|
1596
|
+
(signal) => Promise.all([Deferred.toPromise(first(signal)), Deferred.toPromise(second(signal))]).then(
|
|
1597
|
+
([va, vb]) => Validation.product(va, vb)
|
|
1598
|
+
)
|
|
1490
1599
|
);
|
|
1491
1600
|
TaskValidation2.productAll = (data) => Task.from(
|
|
1492
|
-
(signal) => Promise.all(data.map((t) => Deferred.toPromise(t(signal)))).then(
|
|
1601
|
+
(signal) => Promise.all(data.map((t) => Deferred.toPromise(t(signal)))).then(
|
|
1602
|
+
(results) => Validation.productAll(results)
|
|
1603
|
+
)
|
|
1493
1604
|
);
|
|
1494
1605
|
})(TaskValidation || (TaskValidation = {}));
|
|
1495
1606
|
|
|
@@ -1498,58 +1609,84 @@ var These;
|
|
|
1498
1609
|
((These2) => {
|
|
1499
1610
|
These2.first = (value) => ({ kind: "First", first: value });
|
|
1500
1611
|
These2.second = (value) => ({ kind: "Second", second: value });
|
|
1501
|
-
These2.both = (
|
|
1502
|
-
kind: "Both",
|
|
1503
|
-
first: first2,
|
|
1504
|
-
second: second2
|
|
1505
|
-
});
|
|
1612
|
+
These2.both = (f, s) => ({ kind: "Both", first: f, second: s });
|
|
1506
1613
|
These2.isFirst = (data) => data.kind === "First";
|
|
1507
1614
|
These2.isSecond = (data) => data.kind === "Second";
|
|
1508
1615
|
These2.isBoth = (data) => data.kind === "Both";
|
|
1509
1616
|
These2.hasFirst = (data) => data.kind === "First" || data.kind === "Both";
|
|
1510
1617
|
These2.hasSecond = (data) => data.kind === "Second" || data.kind === "Both";
|
|
1511
1618
|
These2.mapFirst = (f) => (data) => {
|
|
1512
|
-
if ((0, These2.isSecond)(data))
|
|
1513
|
-
|
|
1619
|
+
if ((0, These2.isSecond)(data)) {
|
|
1620
|
+
return data;
|
|
1621
|
+
}
|
|
1622
|
+
if ((0, These2.isFirst)(data)) {
|
|
1623
|
+
return (0, These2.first)(f(data.first));
|
|
1624
|
+
}
|
|
1514
1625
|
return (0, These2.both)(f(data.first), data.second);
|
|
1515
1626
|
};
|
|
1516
1627
|
These2.mapSecond = (f) => (data) => {
|
|
1517
|
-
if ((0, These2.isFirst)(data))
|
|
1518
|
-
|
|
1628
|
+
if ((0, These2.isFirst)(data)) {
|
|
1629
|
+
return data;
|
|
1630
|
+
}
|
|
1631
|
+
if ((0, These2.isSecond)(data)) {
|
|
1632
|
+
return (0, These2.second)(f(data.second));
|
|
1633
|
+
}
|
|
1519
1634
|
return (0, These2.both)(data.first, f(data.second));
|
|
1520
1635
|
};
|
|
1521
1636
|
These2.mapBoth = (onFirst, onSecond) => (data) => {
|
|
1522
|
-
if ((0, These2.isSecond)(data))
|
|
1523
|
-
|
|
1637
|
+
if ((0, These2.isSecond)(data)) {
|
|
1638
|
+
return (0, These2.second)(onSecond(data.second));
|
|
1639
|
+
}
|
|
1640
|
+
if ((0, These2.isFirst)(data)) {
|
|
1641
|
+
return (0, These2.first)(onFirst(data.first));
|
|
1642
|
+
}
|
|
1524
1643
|
return (0, These2.both)(onFirst(data.first), onSecond(data.second));
|
|
1525
1644
|
};
|
|
1526
1645
|
These2.chainFirst = (f) => (data) => {
|
|
1527
|
-
if ((0, These2.isSecond)(data))
|
|
1646
|
+
if ((0, These2.isSecond)(data)) {
|
|
1647
|
+
return data;
|
|
1648
|
+
}
|
|
1528
1649
|
return f(data.first);
|
|
1529
1650
|
};
|
|
1530
1651
|
These2.chainSecond = (f) => (data) => {
|
|
1531
|
-
if ((0, These2.isFirst)(data))
|
|
1652
|
+
if ((0, These2.isFirst)(data)) {
|
|
1653
|
+
return data;
|
|
1654
|
+
}
|
|
1532
1655
|
return f(data.second);
|
|
1533
1656
|
};
|
|
1534
1657
|
These2.fold = (onFirst, onSecond, onBoth) => (data) => {
|
|
1535
|
-
if ((0, These2.isSecond)(data))
|
|
1536
|
-
|
|
1658
|
+
if ((0, These2.isSecond)(data)) {
|
|
1659
|
+
return onSecond(data.second);
|
|
1660
|
+
}
|
|
1661
|
+
if ((0, These2.isFirst)(data)) {
|
|
1662
|
+
return onFirst(data.first);
|
|
1663
|
+
}
|
|
1537
1664
|
return onBoth(data.first, data.second);
|
|
1538
1665
|
};
|
|
1539
1666
|
These2.match = (cases) => (data) => {
|
|
1540
|
-
if ((0, These2.isSecond)(data))
|
|
1541
|
-
|
|
1667
|
+
if ((0, These2.isSecond)(data)) {
|
|
1668
|
+
return cases.second(data.second);
|
|
1669
|
+
}
|
|
1670
|
+
if ((0, These2.isFirst)(data)) {
|
|
1671
|
+
return cases.first(data.first);
|
|
1672
|
+
}
|
|
1542
1673
|
return cases.both(data.first, data.second);
|
|
1543
1674
|
};
|
|
1544
1675
|
These2.getFirstOrElse = (defaultValue) => (data) => (0, These2.hasFirst)(data) ? data.first : defaultValue();
|
|
1545
1676
|
These2.getSecondOrElse = (defaultValue) => (data) => (0, These2.hasSecond)(data) ? data.second : defaultValue();
|
|
1546
1677
|
These2.tap = (f) => (data) => {
|
|
1547
|
-
if ((0, These2.hasFirst)(data))
|
|
1678
|
+
if ((0, These2.hasFirst)(data)) {
|
|
1679
|
+
f(data.first);
|
|
1680
|
+
}
|
|
1548
1681
|
return data;
|
|
1549
1682
|
};
|
|
1550
1683
|
These2.swap = (data) => {
|
|
1551
|
-
if ((0, These2.isSecond)(data))
|
|
1552
|
-
|
|
1684
|
+
if ((0, These2.isSecond)(data)) {
|
|
1685
|
+
return (0, These2.first)(data.second);
|
|
1686
|
+
}
|
|
1687
|
+
if ((0, These2.isFirst)(data)) {
|
|
1688
|
+
return (0, These2.second)(data.first);
|
|
1689
|
+
}
|
|
1553
1690
|
return (0, These2.both)(data.second, data.first);
|
|
1554
1691
|
};
|
|
1555
1692
|
})(These || (These = {}));
|