@nlozgachev/pipelined 0.27.0 → 0.28.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 +191 -72
- package/dist/{Task-C8Pgm7EX.d.ts → Task-BW66NsGR.d.ts} +20 -11
- package/dist/{Task-vQb3-puQ.d.mts → Task-BZT0wedE.d.mts} +20 -11
- package/dist/{chunk-HHCRWQYN.mjs → chunk-7JF44HJH.mjs} +12 -8
- package/dist/{chunk-SBTMTAZF.mjs → chunk-CA3VE4YD.mjs} +3 -3
- package/dist/{chunk-YYVONF5X.mjs → chunk-QJS6D6MW.mjs} +12 -2
- package/dist/core.d.mts +71 -8
- package/dist/core.d.ts +71 -8
- package/dist/core.js +23 -9
- package/dist/core.mjs +2 -2
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +25 -11
- package/dist/index.mjs +3 -3
- package/dist/utils.d.mts +12 -9
- package/dist/utils.d.ts +12 -9
- package/dist/utils.js +14 -10
- package/dist/utils.mjs +2 -2
- package/package.json +1 -1
package/dist/core.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { M as Maybe, W as WithValue, a as WithLog, D as Deferred, R as Result, b as WithKind, c as WithError, d as RetryOptions, e as TimeoutOptions, f as WithTimeout, g as WithMinInterval, h as WithCooldown, i as WithConcurrency, j as WithSize, k as WithMs, l as WithN, T as Task, m as WithErrors, n as WithFirst, o as WithSecond } from './Task-
|
|
2
|
-
export { E as Err, N as None, O as Ok, S as Some } from './Task-
|
|
1
|
+
import { M as Maybe, W as WithValue, a as WithLog, D as Deferred, R as Result, b as WithKind, c as WithError, d as RetryOptions, e as TimeoutOptions, f as WithTimeout, g as WithMinInterval, h as WithCooldown, i as WithConcurrency, j as WithSize, k as WithMs, l as WithN, T as Task, m as WithErrors, n as WithFirst, o as WithSecond } from './Task-BZT0wedE.mjs';
|
|
2
|
+
export { E as Err, N as None, O as Ok, S as Some } from './Task-BZT0wedE.mjs';
|
|
3
3
|
import { N as NonEmptyList } from './NonEmptyList-BlGFjor5.mjs';
|
|
4
4
|
|
|
5
5
|
/** Keys of T for which undefined is assignable (i.e. optional fields). */
|
|
@@ -1481,19 +1481,19 @@ declare namespace RemoteData {
|
|
|
1481
1481
|
/**
|
|
1482
1482
|
* Creates a NotAsked RemoteData.
|
|
1483
1483
|
*/
|
|
1484
|
-
const notAsked:
|
|
1484
|
+
const notAsked: () => NotAsked;
|
|
1485
1485
|
/**
|
|
1486
1486
|
* Creates a Loading RemoteData.
|
|
1487
1487
|
*/
|
|
1488
|
-
const loading:
|
|
1488
|
+
const loading: () => Loading;
|
|
1489
1489
|
/**
|
|
1490
1490
|
* Creates a Failure RemoteData with the given error.
|
|
1491
1491
|
*/
|
|
1492
|
-
const failure: <E
|
|
1492
|
+
const failure: <E>(error: E) => Failure<E>;
|
|
1493
1493
|
/**
|
|
1494
1494
|
* Creates a Success RemoteData with the given value.
|
|
1495
1495
|
*/
|
|
1496
|
-
const success: <
|
|
1496
|
+
const success: <A>(value: A) => Success<A>;
|
|
1497
1497
|
/**
|
|
1498
1498
|
* Type guard that checks if a RemoteData is NotAsked.
|
|
1499
1499
|
*/
|
|
@@ -1620,6 +1620,20 @@ declare namespace RemoteData {
|
|
|
1620
1620
|
* ```
|
|
1621
1621
|
*/
|
|
1622
1622
|
const tap: <E, A>(f: (a: A) => void) => (data: RemoteData<E, A>) => RemoteData<E, A>;
|
|
1623
|
+
/**
|
|
1624
|
+
* Executes a side effect on the failure error without changing the RemoteData.
|
|
1625
|
+
* Useful for logging errors.
|
|
1626
|
+
*
|
|
1627
|
+
* @example
|
|
1628
|
+
* ```ts
|
|
1629
|
+
* pipe(
|
|
1630
|
+
* RemoteData.failure("not found"),
|
|
1631
|
+
* RemoteData.tapError(e => console.error("fetch failed:", e)),
|
|
1632
|
+
* RemoteData.map(render)
|
|
1633
|
+
* );
|
|
1634
|
+
* ```
|
|
1635
|
+
*/
|
|
1636
|
+
const tapError: <E, A>(f: (e: E) => void) => (data: RemoteData<E, A>) => RemoteData<E, A>;
|
|
1623
1637
|
/**
|
|
1624
1638
|
* Recovers from a Failure state by providing a fallback RemoteData.
|
|
1625
1639
|
* The fallback can produce a different success type, widening the result to `RemoteData<E, A | B>`.
|
|
@@ -2230,6 +2244,22 @@ declare namespace Validation {
|
|
|
2230
2244
|
* Type guard that checks if a Validation is invalid.
|
|
2231
2245
|
*/
|
|
2232
2246
|
const isInvalid: <E, A>(data: Validation<E, A>) => data is Invalid<E>;
|
|
2247
|
+
/**
|
|
2248
|
+
* Creates a Validation from a predicate applied to a value.
|
|
2249
|
+
* Returns Valid if the predicate passes, Invalid from `onFalse` otherwise.
|
|
2250
|
+
*
|
|
2251
|
+
* @example
|
|
2252
|
+
* ```ts
|
|
2253
|
+
* const validateName = Validation.fromPredicate(
|
|
2254
|
+
* (s: string) => s.length > 0,
|
|
2255
|
+
* () => "Name is required"
|
|
2256
|
+
* );
|
|
2257
|
+
*
|
|
2258
|
+
* validateName("Alice"); // Valid("Alice")
|
|
2259
|
+
* validateName(""); // Invalid(["Name is required"])
|
|
2260
|
+
* ```
|
|
2261
|
+
*/
|
|
2262
|
+
const fromPredicate: <E, A>(pred: (a: A) => boolean, onFalse: (a: A) => E) => (a: A) => Validation<E, A>;
|
|
2233
2263
|
/**
|
|
2234
2264
|
* Transforms the success value inside a Validation.
|
|
2235
2265
|
*
|
|
@@ -2319,6 +2349,20 @@ declare namespace Validation {
|
|
|
2319
2349
|
* ```
|
|
2320
2350
|
*/
|
|
2321
2351
|
const tap: <E, A>(f: (a: A) => void) => (data: Validation<E, A>) => Validation<E, A>;
|
|
2352
|
+
/**
|
|
2353
|
+
* Executes a side effect on the accumulated errors without changing the Validation.
|
|
2354
|
+
* Useful for logging or reporting validation failures.
|
|
2355
|
+
*
|
|
2356
|
+
* @example
|
|
2357
|
+
* ```ts
|
|
2358
|
+
* pipe(
|
|
2359
|
+
* Validation.invalid("Name required"),
|
|
2360
|
+
* Validation.tapError(errors => console.error("validation failed:", errors)),
|
|
2361
|
+
* Validation.map(toUser)
|
|
2362
|
+
* );
|
|
2363
|
+
* ```
|
|
2364
|
+
*/
|
|
2365
|
+
const tapError: <E, A>(f: (errors: NonEmptyList<E>) => void) => (data: Validation<E, A>) => Validation<E, A>;
|
|
2322
2366
|
/**
|
|
2323
2367
|
* Recovers from an Invalid state by providing a fallback Validation.
|
|
2324
2368
|
* The fallback receives the accumulated error list so callers can inspect which errors occurred.
|
|
@@ -2326,10 +2370,29 @@ declare namespace Validation {
|
|
|
2326
2370
|
*/
|
|
2327
2371
|
const recover: <E, A, B>(fallback: (errors: NonEmptyList<E>) => Validation<E, B>) => (data: Validation<E, A>) => Validation<E, A | B>;
|
|
2328
2372
|
/**
|
|
2329
|
-
* Recovers from an Invalid state unless
|
|
2373
|
+
* Recovers from an Invalid state unless `isBlocked` returns true for any of the accumulated errors.
|
|
2330
2374
|
* The fallback can produce a different success type, widening the result to `Validation<E, A | B>`.
|
|
2375
|
+
*
|
|
2376
|
+
* @example
|
|
2377
|
+
* ```ts
|
|
2378
|
+
* pipe(
|
|
2379
|
+
* Validation.invalid("field-error"),
|
|
2380
|
+
* Validation.recoverUnless(e => e === "fatal", () => Validation.valid(0))
|
|
2381
|
+
* ); // Valid(0)
|
|
2382
|
+
* ```
|
|
2383
|
+
*/
|
|
2384
|
+
const recoverUnless: <E, A, B>(isBlocked: (e: E) => boolean, fallback: () => Validation<E, B>) => (data: Validation<E, A>) => Validation<E, A | B>;
|
|
2385
|
+
/**
|
|
2386
|
+
* Converts a Validation to a Result.
|
|
2387
|
+
* Valid becomes Ok, Invalid becomes Err with the accumulated error list.
|
|
2388
|
+
*
|
|
2389
|
+
* @example
|
|
2390
|
+
* ```ts
|
|
2391
|
+
* Validation.toResult(Validation.valid(42)); // Ok(42)
|
|
2392
|
+
* Validation.toResult(Validation.invalid("oops")); // Err(["oops"])
|
|
2393
|
+
* ```
|
|
2331
2394
|
*/
|
|
2332
|
-
const
|
|
2395
|
+
const toResult: <E, A>(data: Validation<E, A>) => Result<NonEmptyList<E>, A>;
|
|
2333
2396
|
/**
|
|
2334
2397
|
* Combines two independent Validation instances into a tuple.
|
|
2335
2398
|
* If both are Valid, returns Valid with both values as a tuple.
|
package/dist/core.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { M as Maybe, W as WithValue, a as WithLog, D as Deferred, R as Result, b as WithKind, c as WithError, d as RetryOptions, e as TimeoutOptions, f as WithTimeout, g as WithMinInterval, h as WithCooldown, i as WithConcurrency, j as WithSize, k as WithMs, l as WithN, T as Task, m as WithErrors, n as WithFirst, o as WithSecond } from './Task-
|
|
2
|
-
export { E as Err, N as None, O as Ok, S as Some } from './Task-
|
|
1
|
+
import { M as Maybe, W as WithValue, a as WithLog, D as Deferred, R as Result, b as WithKind, c as WithError, d as RetryOptions, e as TimeoutOptions, f as WithTimeout, g as WithMinInterval, h as WithCooldown, i as WithConcurrency, j as WithSize, k as WithMs, l as WithN, T as Task, m as WithErrors, n as WithFirst, o as WithSecond } from './Task-BW66NsGR.js';
|
|
2
|
+
export { E as Err, N as None, O as Ok, S as Some } from './Task-BW66NsGR.js';
|
|
3
3
|
import { N as NonEmptyList } from './NonEmptyList-BlGFjor5.js';
|
|
4
4
|
|
|
5
5
|
/** Keys of T for which undefined is assignable (i.e. optional fields). */
|
|
@@ -1481,19 +1481,19 @@ declare namespace RemoteData {
|
|
|
1481
1481
|
/**
|
|
1482
1482
|
* Creates a NotAsked RemoteData.
|
|
1483
1483
|
*/
|
|
1484
|
-
const notAsked:
|
|
1484
|
+
const notAsked: () => NotAsked;
|
|
1485
1485
|
/**
|
|
1486
1486
|
* Creates a Loading RemoteData.
|
|
1487
1487
|
*/
|
|
1488
|
-
const loading:
|
|
1488
|
+
const loading: () => Loading;
|
|
1489
1489
|
/**
|
|
1490
1490
|
* Creates a Failure RemoteData with the given error.
|
|
1491
1491
|
*/
|
|
1492
|
-
const failure: <E
|
|
1492
|
+
const failure: <E>(error: E) => Failure<E>;
|
|
1493
1493
|
/**
|
|
1494
1494
|
* Creates a Success RemoteData with the given value.
|
|
1495
1495
|
*/
|
|
1496
|
-
const success: <
|
|
1496
|
+
const success: <A>(value: A) => Success<A>;
|
|
1497
1497
|
/**
|
|
1498
1498
|
* Type guard that checks if a RemoteData is NotAsked.
|
|
1499
1499
|
*/
|
|
@@ -1620,6 +1620,20 @@ declare namespace RemoteData {
|
|
|
1620
1620
|
* ```
|
|
1621
1621
|
*/
|
|
1622
1622
|
const tap: <E, A>(f: (a: A) => void) => (data: RemoteData<E, A>) => RemoteData<E, A>;
|
|
1623
|
+
/**
|
|
1624
|
+
* Executes a side effect on the failure error without changing the RemoteData.
|
|
1625
|
+
* Useful for logging errors.
|
|
1626
|
+
*
|
|
1627
|
+
* @example
|
|
1628
|
+
* ```ts
|
|
1629
|
+
* pipe(
|
|
1630
|
+
* RemoteData.failure("not found"),
|
|
1631
|
+
* RemoteData.tapError(e => console.error("fetch failed:", e)),
|
|
1632
|
+
* RemoteData.map(render)
|
|
1633
|
+
* );
|
|
1634
|
+
* ```
|
|
1635
|
+
*/
|
|
1636
|
+
const tapError: <E, A>(f: (e: E) => void) => (data: RemoteData<E, A>) => RemoteData<E, A>;
|
|
1623
1637
|
/**
|
|
1624
1638
|
* Recovers from a Failure state by providing a fallback RemoteData.
|
|
1625
1639
|
* The fallback can produce a different success type, widening the result to `RemoteData<E, A | B>`.
|
|
@@ -2230,6 +2244,22 @@ declare namespace Validation {
|
|
|
2230
2244
|
* Type guard that checks if a Validation is invalid.
|
|
2231
2245
|
*/
|
|
2232
2246
|
const isInvalid: <E, A>(data: Validation<E, A>) => data is Invalid<E>;
|
|
2247
|
+
/**
|
|
2248
|
+
* Creates a Validation from a predicate applied to a value.
|
|
2249
|
+
* Returns Valid if the predicate passes, Invalid from `onFalse` otherwise.
|
|
2250
|
+
*
|
|
2251
|
+
* @example
|
|
2252
|
+
* ```ts
|
|
2253
|
+
* const validateName = Validation.fromPredicate(
|
|
2254
|
+
* (s: string) => s.length > 0,
|
|
2255
|
+
* () => "Name is required"
|
|
2256
|
+
* );
|
|
2257
|
+
*
|
|
2258
|
+
* validateName("Alice"); // Valid("Alice")
|
|
2259
|
+
* validateName(""); // Invalid(["Name is required"])
|
|
2260
|
+
* ```
|
|
2261
|
+
*/
|
|
2262
|
+
const fromPredicate: <E, A>(pred: (a: A) => boolean, onFalse: (a: A) => E) => (a: A) => Validation<E, A>;
|
|
2233
2263
|
/**
|
|
2234
2264
|
* Transforms the success value inside a Validation.
|
|
2235
2265
|
*
|
|
@@ -2319,6 +2349,20 @@ declare namespace Validation {
|
|
|
2319
2349
|
* ```
|
|
2320
2350
|
*/
|
|
2321
2351
|
const tap: <E, A>(f: (a: A) => void) => (data: Validation<E, A>) => Validation<E, A>;
|
|
2352
|
+
/**
|
|
2353
|
+
* Executes a side effect on the accumulated errors without changing the Validation.
|
|
2354
|
+
* Useful for logging or reporting validation failures.
|
|
2355
|
+
*
|
|
2356
|
+
* @example
|
|
2357
|
+
* ```ts
|
|
2358
|
+
* pipe(
|
|
2359
|
+
* Validation.invalid("Name required"),
|
|
2360
|
+
* Validation.tapError(errors => console.error("validation failed:", errors)),
|
|
2361
|
+
* Validation.map(toUser)
|
|
2362
|
+
* );
|
|
2363
|
+
* ```
|
|
2364
|
+
*/
|
|
2365
|
+
const tapError: <E, A>(f: (errors: NonEmptyList<E>) => void) => (data: Validation<E, A>) => Validation<E, A>;
|
|
2322
2366
|
/**
|
|
2323
2367
|
* Recovers from an Invalid state by providing a fallback Validation.
|
|
2324
2368
|
* The fallback receives the accumulated error list so callers can inspect which errors occurred.
|
|
@@ -2326,10 +2370,29 @@ declare namespace Validation {
|
|
|
2326
2370
|
*/
|
|
2327
2371
|
const recover: <E, A, B>(fallback: (errors: NonEmptyList<E>) => Validation<E, B>) => (data: Validation<E, A>) => Validation<E, A | B>;
|
|
2328
2372
|
/**
|
|
2329
|
-
* Recovers from an Invalid state unless
|
|
2373
|
+
* Recovers from an Invalid state unless `isBlocked` returns true for any of the accumulated errors.
|
|
2330
2374
|
* The fallback can produce a different success type, widening the result to `Validation<E, A | B>`.
|
|
2375
|
+
*
|
|
2376
|
+
* @example
|
|
2377
|
+
* ```ts
|
|
2378
|
+
* pipe(
|
|
2379
|
+
* Validation.invalid("field-error"),
|
|
2380
|
+
* Validation.recoverUnless(e => e === "fatal", () => Validation.valid(0))
|
|
2381
|
+
* ); // Valid(0)
|
|
2382
|
+
* ```
|
|
2383
|
+
*/
|
|
2384
|
+
const recoverUnless: <E, A, B>(isBlocked: (e: E) => boolean, fallback: () => Validation<E, B>) => (data: Validation<E, A>) => Validation<E, A | B>;
|
|
2385
|
+
/**
|
|
2386
|
+
* Converts a Validation to a Result.
|
|
2387
|
+
* Valid becomes Ok, Invalid becomes Err with the accumulated error list.
|
|
2388
|
+
*
|
|
2389
|
+
* @example
|
|
2390
|
+
* ```ts
|
|
2391
|
+
* Validation.toResult(Validation.valid(42)); // Ok(42)
|
|
2392
|
+
* Validation.toResult(Validation.invalid("oops")); // Err(["oops"])
|
|
2393
|
+
* ```
|
|
2331
2394
|
*/
|
|
2332
|
-
const
|
|
2395
|
+
const toResult: <E, A>(data: Validation<E, A>) => Result<NonEmptyList<E>, A>;
|
|
2333
2396
|
/**
|
|
2334
2397
|
* Combines two independent Validation instances into a tuple.
|
|
2335
2398
|
* If both are Valid, returns Valid with both values as a tuple.
|
package/dist/core.js
CHANGED
|
@@ -132,7 +132,7 @@ var Result;
|
|
|
132
132
|
};
|
|
133
133
|
Result2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Result2.ok)(a) : (0, Result2.err)(onFalse(a));
|
|
134
134
|
Result2.recover = (fallback) => (data) => (0, Result2.isOk)(data) ? data : fallback(data.error);
|
|
135
|
-
Result2.recoverUnless = (
|
|
135
|
+
Result2.recoverUnless = (isBlocked, fallback) => (data) => (0, Result2.isErr)(data) && !isBlocked(data.error) ? fallback() : data;
|
|
136
136
|
Result2.toMaybe = (data) => (0, Result2.isOk)(data) ? Maybe.some(data.value) : Maybe.none();
|
|
137
137
|
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;
|
|
138
138
|
})(Result || (Result = {}));
|
|
@@ -148,7 +148,6 @@ var Maybe;
|
|
|
148
148
|
Maybe2.fromNullable = (value) => value === null || value === void 0 ? (0, Maybe2.none)() : (0, Maybe2.some)(value);
|
|
149
149
|
Maybe2.toNullable = (data) => (0, Maybe2.isSome)(data) ? data.value : null;
|
|
150
150
|
Maybe2.toUndefined = (data) => (0, Maybe2.isSome)(data) ? data.value : void 0;
|
|
151
|
-
Maybe2.fromUndefined = (value) => value === void 0 ? (0, Maybe2.none)() : (0, Maybe2.some)(value);
|
|
152
151
|
Maybe2.fromPredicate = (pred) => (a) => pred(a) ? (0, Maybe2.some)(a) : (0, Maybe2.none)();
|
|
153
152
|
Maybe2.toResult = (onNone) => (data) => (0, Maybe2.isSome)(data) ? Result.ok(data.value) : Result.err(onNone());
|
|
154
153
|
Maybe2.fromResult = (data) => Result.isOk(data) ? (0, Maybe2.some)(data.value) : (0, Maybe2.none)();
|
|
@@ -1201,6 +1200,10 @@ var RemoteData;
|
|
|
1201
1200
|
if ((0, RemoteData2.isSuccess)(data)) f(data.value);
|
|
1202
1201
|
return data;
|
|
1203
1202
|
};
|
|
1203
|
+
RemoteData2.tapError = (f) => (data) => {
|
|
1204
|
+
if ((0, RemoteData2.isFailure)(data)) f(data.error);
|
|
1205
|
+
return data;
|
|
1206
|
+
};
|
|
1204
1207
|
RemoteData2.recover = (fallback) => (data) => (0, RemoteData2.isFailure)(data) ? fallback(data.error) : data;
|
|
1205
1208
|
RemoteData2.toMaybe = (data) => (0, RemoteData2.isSuccess)(data) ? Maybe.some(data.value) : Maybe.none();
|
|
1206
1209
|
RemoteData2.toResult = (onNotReady) => (data) => (0, RemoteData2.isSuccess)(data) ? Result.ok(data.value) : Result.err((0, RemoteData2.isFailure)(data) ? data.error : onNotReady());
|
|
@@ -1253,13 +1256,14 @@ var Task;
|
|
|
1253
1256
|
return run(times);
|
|
1254
1257
|
});
|
|
1255
1258
|
Task2.repeatUntil = (options) => (task) => (0, Task2.from)((signal) => {
|
|
1256
|
-
const { when: predicate, delay: ms } = options;
|
|
1259
|
+
const { when: predicate, delay: ms, maxAttempts } = options;
|
|
1257
1260
|
const wait = () => ms !== void 0 && ms > 0 ? new Promise((r) => setTimeout(r, ms)) : Promise.resolve();
|
|
1258
|
-
const run = () => toPromise(task, signal).then((a) => {
|
|
1261
|
+
const run = (attempt) => toPromise(task, signal).then((a) => {
|
|
1259
1262
|
if (predicate(a)) return a;
|
|
1260
|
-
|
|
1263
|
+
if (maxAttempts !== void 0 && attempt >= maxAttempts) return a;
|
|
1264
|
+
return wait().then(() => run(attempt + 1));
|
|
1261
1265
|
});
|
|
1262
|
-
return run();
|
|
1266
|
+
return run(1);
|
|
1263
1267
|
});
|
|
1264
1268
|
Task2.race = (tasks) => (0, Task2.from)((signal) => Promise.race(tasks.map((t) => toPromise(t, signal))));
|
|
1265
1269
|
Task2.sequential = (tasks) => (0, Task2.from)(async (signal) => {
|
|
@@ -1290,8 +1294,12 @@ var Task;
|
|
|
1290
1294
|
]);
|
|
1291
1295
|
});
|
|
1292
1296
|
Task2.abortable = (factory) => {
|
|
1293
|
-
|
|
1297
|
+
let currentController = null;
|
|
1298
|
+
const abort = () => currentController?.abort();
|
|
1294
1299
|
const task = (outerSignal) => {
|
|
1300
|
+
currentController?.abort();
|
|
1301
|
+
currentController = new AbortController();
|
|
1302
|
+
const controller = currentController;
|
|
1295
1303
|
if (outerSignal) {
|
|
1296
1304
|
if (outerSignal.aborted) {
|
|
1297
1305
|
controller.abort(outerSignal.reason);
|
|
@@ -1301,7 +1309,7 @@ var Task;
|
|
|
1301
1309
|
}
|
|
1302
1310
|
return Deferred.fromPromise(factory(controller.signal));
|
|
1303
1311
|
};
|
|
1304
|
-
return { task, abort
|
|
1312
|
+
return { task, abort };
|
|
1305
1313
|
};
|
|
1306
1314
|
})(Task || (Task = {}));
|
|
1307
1315
|
|
|
@@ -1436,6 +1444,7 @@ var Validation;
|
|
|
1436
1444
|
});
|
|
1437
1445
|
Validation2.isValid = (data) => data.kind === "Valid";
|
|
1438
1446
|
Validation2.isInvalid = (data) => data.kind === "Invalid";
|
|
1447
|
+
Validation2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Validation2.valid)(a) : (0, Validation2.invalid)(onFalse(a));
|
|
1439
1448
|
Validation2.map = (f) => (data) => (0, Validation2.isValid)(data) ? (0, Validation2.valid)(f(data.value)) : data;
|
|
1440
1449
|
Validation2.ap = (arg) => (data) => {
|
|
1441
1450
|
if ((0, Validation2.isValid)(data) && (0, Validation2.isValid)(arg)) return (0, Validation2.valid)(data.value(arg.value));
|
|
@@ -1452,8 +1461,13 @@ var Validation;
|
|
|
1452
1461
|
if ((0, Validation2.isValid)(data)) f(data.value);
|
|
1453
1462
|
return data;
|
|
1454
1463
|
};
|
|
1464
|
+
Validation2.tapError = (f) => (data) => {
|
|
1465
|
+
if ((0, Validation2.isInvalid)(data)) f(data.errors);
|
|
1466
|
+
return data;
|
|
1467
|
+
};
|
|
1455
1468
|
Validation2.recover = (fallback) => (data) => (0, Validation2.isValid)(data) ? data : fallback(data.errors);
|
|
1456
|
-
Validation2.recoverUnless = (
|
|
1469
|
+
Validation2.recoverUnless = (isBlocked, fallback) => (data) => (0, Validation2.isInvalid)(data) && !data.errors.some(isBlocked) ? fallback() : data;
|
|
1470
|
+
Validation2.toResult = (data) => (0, Validation2.isValid)(data) ? Result.ok(data.value) : Result.err(data.errors);
|
|
1457
1471
|
Validation2.product = (first, second) => {
|
|
1458
1472
|
if ((0, Validation2.isValid)(first) && (0, Validation2.isValid)(second)) return (0, Validation2.valid)([first.value, second.value]);
|
|
1459
1473
|
const errors = [
|
package/dist/core.mjs
CHANGED
|
@@ -15,13 +15,13 @@ import {
|
|
|
15
15
|
These,
|
|
16
16
|
Tuple,
|
|
17
17
|
Validation
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-QJS6D6MW.mjs";
|
|
19
19
|
import {
|
|
20
20
|
Deferred,
|
|
21
21
|
Maybe,
|
|
22
22
|
Result,
|
|
23
23
|
Task
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-7JF44HJH.mjs";
|
|
25
25
|
export {
|
|
26
26
|
Deferred,
|
|
27
27
|
Lens,
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { and, compose, constFalse, constNull, constTrue, constUndefined, constVoid, constant, converge, curry, curry3, curry4, flip, flow, identity, juxt, memoize, memoizeWeak, not, on, once, or, pipe, tap, uncurry, uncurry3, uncurry4 } from './composition.mjs';
|
|
2
|
-
export { D as Deferred, E as Err, M as Maybe, N as None, O as Ok, R as Result, S as Some, T as Task } from './Task-
|
|
2
|
+
export { D as Deferred, E as Err, M as Maybe, N as None, O as Ok, R as Result, S as Some, T as Task } from './Task-BZT0wedE.mjs';
|
|
3
3
|
export { Failure, Invalid, Lens, Loading, Logged, NotAsked, Op, Optional, Predicate, Reader, Refinement, RemoteData, Resource, State, Success, TaskMaybe, TaskResult, TaskValidation, These, TheseBoth, TheseFirst, TheseSecond, Tuple, Valid, Validation } from './core.mjs';
|
|
4
4
|
export { Brand } from './types.mjs';
|
|
5
5
|
export { N as NonEmptyList, i as isNonEmptyList } from './NonEmptyList-BlGFjor5.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { and, compose, constFalse, constNull, constTrue, constUndefined, constVoid, constant, converge, curry, curry3, curry4, flip, flow, identity, juxt, memoize, memoizeWeak, not, on, once, or, pipe, tap, uncurry, uncurry3, uncurry4 } from './composition.js';
|
|
2
|
-
export { D as Deferred, E as Err, M as Maybe, N as None, O as Ok, R as Result, S as Some, T as Task } from './Task-
|
|
2
|
+
export { D as Deferred, E as Err, M as Maybe, N as None, O as Ok, R as Result, S as Some, T as Task } from './Task-BW66NsGR.js';
|
|
3
3
|
export { Failure, Invalid, Lens, Loading, Logged, NotAsked, Op, Optional, Predicate, Reader, Refinement, RemoteData, Resource, State, Success, TaskMaybe, TaskResult, TaskValidation, These, TheseBoth, TheseFirst, TheseSecond, Tuple, Valid, Validation } from './core.js';
|
|
4
4
|
export { Brand } from './types.js';
|
|
5
5
|
export { N as NonEmptyList, i as isNonEmptyList } from './NonEmptyList-BlGFjor5.js';
|
package/dist/index.js
CHANGED
|
@@ -377,7 +377,7 @@ var Result;
|
|
|
377
377
|
};
|
|
378
378
|
Result2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Result2.ok)(a) : (0, Result2.err)(onFalse(a));
|
|
379
379
|
Result2.recover = (fallback) => (data) => (0, Result2.isOk)(data) ? data : fallback(data.error);
|
|
380
|
-
Result2.recoverUnless = (
|
|
380
|
+
Result2.recoverUnless = (isBlocked, fallback) => (data) => (0, Result2.isErr)(data) && !isBlocked(data.error) ? fallback() : data;
|
|
381
381
|
Result2.toMaybe = (data) => (0, Result2.isOk)(data) ? Maybe.some(data.value) : Maybe.none();
|
|
382
382
|
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;
|
|
383
383
|
})(Result || (Result = {}));
|
|
@@ -393,7 +393,6 @@ var Maybe;
|
|
|
393
393
|
Maybe2.fromNullable = (value) => value === null || value === void 0 ? (0, Maybe2.none)() : (0, Maybe2.some)(value);
|
|
394
394
|
Maybe2.toNullable = (data) => (0, Maybe2.isSome)(data) ? data.value : null;
|
|
395
395
|
Maybe2.toUndefined = (data) => (0, Maybe2.isSome)(data) ? data.value : void 0;
|
|
396
|
-
Maybe2.fromUndefined = (value) => value === void 0 ? (0, Maybe2.none)() : (0, Maybe2.some)(value);
|
|
397
396
|
Maybe2.fromPredicate = (pred) => (a) => pred(a) ? (0, Maybe2.some)(a) : (0, Maybe2.none)();
|
|
398
397
|
Maybe2.toResult = (onNone) => (data) => (0, Maybe2.isSome)(data) ? Result.ok(data.value) : Result.err(onNone());
|
|
399
398
|
Maybe2.fromResult = (data) => Result.isOk(data) ? (0, Maybe2.some)(data.value) : (0, Maybe2.none)();
|
|
@@ -1446,6 +1445,10 @@ var RemoteData;
|
|
|
1446
1445
|
if ((0, RemoteData2.isSuccess)(data)) f(data.value);
|
|
1447
1446
|
return data;
|
|
1448
1447
|
};
|
|
1448
|
+
RemoteData2.tapError = (f) => (data) => {
|
|
1449
|
+
if ((0, RemoteData2.isFailure)(data)) f(data.error);
|
|
1450
|
+
return data;
|
|
1451
|
+
};
|
|
1449
1452
|
RemoteData2.recover = (fallback) => (data) => (0, RemoteData2.isFailure)(data) ? fallback(data.error) : data;
|
|
1450
1453
|
RemoteData2.toMaybe = (data) => (0, RemoteData2.isSuccess)(data) ? Maybe.some(data.value) : Maybe.none();
|
|
1451
1454
|
RemoteData2.toResult = (onNotReady) => (data) => (0, RemoteData2.isSuccess)(data) ? Result.ok(data.value) : Result.err((0, RemoteData2.isFailure)(data) ? data.error : onNotReady());
|
|
@@ -1498,13 +1501,14 @@ var Task;
|
|
|
1498
1501
|
return run(times);
|
|
1499
1502
|
});
|
|
1500
1503
|
Task2.repeatUntil = (options) => (task) => (0, Task2.from)((signal) => {
|
|
1501
|
-
const { when: predicate, delay: ms } = options;
|
|
1504
|
+
const { when: predicate, delay: ms, maxAttempts } = options;
|
|
1502
1505
|
const wait = () => ms !== void 0 && ms > 0 ? new Promise((r) => setTimeout(r, ms)) : Promise.resolve();
|
|
1503
|
-
const run = () => toPromise(task, signal).then((a) => {
|
|
1506
|
+
const run = (attempt) => toPromise(task, signal).then((a) => {
|
|
1504
1507
|
if (predicate(a)) return a;
|
|
1505
|
-
|
|
1508
|
+
if (maxAttempts !== void 0 && attempt >= maxAttempts) return a;
|
|
1509
|
+
return wait().then(() => run(attempt + 1));
|
|
1506
1510
|
});
|
|
1507
|
-
return run();
|
|
1511
|
+
return run(1);
|
|
1508
1512
|
});
|
|
1509
1513
|
Task2.race = (tasks) => (0, Task2.from)((signal) => Promise.race(tasks.map((t) => toPromise(t, signal))));
|
|
1510
1514
|
Task2.sequential = (tasks) => (0, Task2.from)(async (signal) => {
|
|
@@ -1535,8 +1539,12 @@ var Task;
|
|
|
1535
1539
|
]);
|
|
1536
1540
|
});
|
|
1537
1541
|
Task2.abortable = (factory) => {
|
|
1538
|
-
|
|
1542
|
+
let currentController = null;
|
|
1543
|
+
const abort = () => currentController?.abort();
|
|
1539
1544
|
const task = (outerSignal) => {
|
|
1545
|
+
currentController?.abort();
|
|
1546
|
+
currentController = new AbortController();
|
|
1547
|
+
const controller = currentController;
|
|
1540
1548
|
if (outerSignal) {
|
|
1541
1549
|
if (outerSignal.aborted) {
|
|
1542
1550
|
controller.abort(outerSignal.reason);
|
|
@@ -1546,7 +1554,7 @@ var Task;
|
|
|
1546
1554
|
}
|
|
1547
1555
|
return Deferred.fromPromise(factory(controller.signal));
|
|
1548
1556
|
};
|
|
1549
|
-
return { task, abort
|
|
1557
|
+
return { task, abort };
|
|
1550
1558
|
};
|
|
1551
1559
|
})(Task || (Task = {}));
|
|
1552
1560
|
|
|
@@ -1681,6 +1689,7 @@ var Validation;
|
|
|
1681
1689
|
});
|
|
1682
1690
|
Validation2.isValid = (data) => data.kind === "Valid";
|
|
1683
1691
|
Validation2.isInvalid = (data) => data.kind === "Invalid";
|
|
1692
|
+
Validation2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Validation2.valid)(a) : (0, Validation2.invalid)(onFalse(a));
|
|
1684
1693
|
Validation2.map = (f) => (data) => (0, Validation2.isValid)(data) ? (0, Validation2.valid)(f(data.value)) : data;
|
|
1685
1694
|
Validation2.ap = (arg) => (data) => {
|
|
1686
1695
|
if ((0, Validation2.isValid)(data) && (0, Validation2.isValid)(arg)) return (0, Validation2.valid)(data.value(arg.value));
|
|
@@ -1697,8 +1706,13 @@ var Validation;
|
|
|
1697
1706
|
if ((0, Validation2.isValid)(data)) f(data.value);
|
|
1698
1707
|
return data;
|
|
1699
1708
|
};
|
|
1709
|
+
Validation2.tapError = (f) => (data) => {
|
|
1710
|
+
if ((0, Validation2.isInvalid)(data)) f(data.errors);
|
|
1711
|
+
return data;
|
|
1712
|
+
};
|
|
1700
1713
|
Validation2.recover = (fallback) => (data) => (0, Validation2.isValid)(data) ? data : fallback(data.errors);
|
|
1701
|
-
Validation2.recoverUnless = (
|
|
1714
|
+
Validation2.recoverUnless = (isBlocked, fallback) => (data) => (0, Validation2.isInvalid)(data) && !data.errors.some(isBlocked) ? fallback() : data;
|
|
1715
|
+
Validation2.toResult = (data) => (0, Validation2.isValid)(data) ? Result.ok(data.value) : Result.err(data.errors);
|
|
1702
1716
|
Validation2.product = (first, second) => {
|
|
1703
1717
|
if ((0, Validation2.isValid)(first) && (0, Validation2.isValid)(second)) return (0, Validation2.valid)([first.value, second.value]);
|
|
1704
1718
|
const errors = [
|
|
@@ -2204,13 +2218,13 @@ var Num;
|
|
|
2204
2218
|
Num2.add = (b) => (a) => a + b;
|
|
2205
2219
|
Num2.subtract = (b) => (a) => a - b;
|
|
2206
2220
|
Num2.multiply = (b) => (a) => a * b;
|
|
2207
|
-
Num2.divide = (b) => (a) => a / b;
|
|
2221
|
+
Num2.divide = (b) => (a) => b === 0 ? Maybe.none() : Maybe.some(a / b);
|
|
2208
2222
|
Num2.abs = (n) => Math.abs(n);
|
|
2209
2223
|
Num2.negate = (n) => -n;
|
|
2210
2224
|
Num2.round = (n) => Math.round(n);
|
|
2211
2225
|
Num2.floor = (n) => Math.floor(n);
|
|
2212
2226
|
Num2.ceil = (n) => Math.ceil(n);
|
|
2213
|
-
Num2.remainder = (divisor) => (n) => n % divisor;
|
|
2227
|
+
Num2.remainder = (divisor) => (n) => divisor === 0 ? Maybe.none() : Maybe.some(n % divisor);
|
|
2214
2228
|
})(Num || (Num = {}));
|
|
2215
2229
|
|
|
2216
2230
|
// src/Utils/Rec.ts
|
package/dist/index.mjs
CHANGED
|
@@ -44,7 +44,7 @@ import {
|
|
|
44
44
|
These,
|
|
45
45
|
Tuple,
|
|
46
46
|
Validation
|
|
47
|
-
} from "./chunk-
|
|
47
|
+
} from "./chunk-QJS6D6MW.mjs";
|
|
48
48
|
import {
|
|
49
49
|
Arr,
|
|
50
50
|
Dict,
|
|
@@ -52,13 +52,13 @@ import {
|
|
|
52
52
|
Rec,
|
|
53
53
|
Str,
|
|
54
54
|
Uniq
|
|
55
|
-
} from "./chunk-
|
|
55
|
+
} from "./chunk-CA3VE4YD.mjs";
|
|
56
56
|
import {
|
|
57
57
|
Deferred,
|
|
58
58
|
Maybe,
|
|
59
59
|
Result,
|
|
60
60
|
Task
|
|
61
|
-
} from "./chunk-
|
|
61
|
+
} from "./chunk-7JF44HJH.mjs";
|
|
62
62
|
import {
|
|
63
63
|
Brand
|
|
64
64
|
} from "./chunk-BYWKZLHM.mjs";
|
package/dist/utils.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { M as Maybe, R as Result, T as Task } from './Task-
|
|
1
|
+
import { M as Maybe, R as Result, T as Task } from './Task-BZT0wedE.mjs';
|
|
2
2
|
import { N as NonEmptyList } from './NonEmptyList-BlGFjor5.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -858,15 +858,16 @@ declare namespace Num {
|
|
|
858
858
|
*/
|
|
859
859
|
const multiply: (b: number) => (a: number) => number;
|
|
860
860
|
/**
|
|
861
|
-
* Divides a number by `b`. Data-last: `divide(b)(a)` = `a / b`.
|
|
861
|
+
* Divides a number by `b`. Returns `None` when `b` is zero. Data-last: `divide(b)(a)` = `a / b`.
|
|
862
862
|
*
|
|
863
863
|
* @example
|
|
864
864
|
* ```ts
|
|
865
|
-
* pipe(20, Num.divide(4));
|
|
866
|
-
* pipe(
|
|
865
|
+
* pipe(20, Num.divide(4)); // Some(5)
|
|
866
|
+
* pipe(5, Num.divide(0)); // None
|
|
867
|
+
* pipe([10, 20, 30], Arr.filterMap(Num.divide(10))); // [1, 2, 3]
|
|
867
868
|
* ```
|
|
868
869
|
*/
|
|
869
|
-
const divide: (b: number) => (a: number) => number
|
|
870
|
+
const divide: (b: number) => (a: number) => Maybe<number>;
|
|
870
871
|
/**
|
|
871
872
|
* Returns the absolute value of a number.
|
|
872
873
|
*
|
|
@@ -918,15 +919,17 @@ declare namespace Num {
|
|
|
918
919
|
*/
|
|
919
920
|
const ceil: (n: number) => number;
|
|
920
921
|
/**
|
|
921
|
-
* Returns the remainder of dividing a number by `divisor`.
|
|
922
|
+
* Returns the remainder of dividing a number by `divisor`. Returns `None` when `divisor` is zero.
|
|
923
|
+
* Data-last: `remainder(divisor)(a)` = `a % divisor`.
|
|
922
924
|
*
|
|
923
925
|
* @example
|
|
924
926
|
* ```ts
|
|
925
|
-
* pipe(10, Num.remainder(3));
|
|
926
|
-
* pipe(
|
|
927
|
+
* pipe(10, Num.remainder(3)); // Some(1)
|
|
928
|
+
* pipe(5, Num.remainder(0)); // None
|
|
929
|
+
* pipe([10, 11, 12], Arr.filterMap(Num.remainder(3))); // [1, 2, 0]
|
|
927
930
|
* ```
|
|
928
931
|
*/
|
|
929
|
-
const remainder: (divisor: number) => (n: number) => number
|
|
932
|
+
const remainder: (divisor: number) => (n: number) => Maybe<number>;
|
|
930
933
|
}
|
|
931
934
|
|
|
932
935
|
/**
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { M as Maybe, R as Result, T as Task } from './Task-
|
|
1
|
+
import { M as Maybe, R as Result, T as Task } from './Task-BW66NsGR.js';
|
|
2
2
|
import { N as NonEmptyList } from './NonEmptyList-BlGFjor5.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -858,15 +858,16 @@ declare namespace Num {
|
|
|
858
858
|
*/
|
|
859
859
|
const multiply: (b: number) => (a: number) => number;
|
|
860
860
|
/**
|
|
861
|
-
* Divides a number by `b`. Data-last: `divide(b)(a)` = `a / b`.
|
|
861
|
+
* Divides a number by `b`. Returns `None` when `b` is zero. Data-last: `divide(b)(a)` = `a / b`.
|
|
862
862
|
*
|
|
863
863
|
* @example
|
|
864
864
|
* ```ts
|
|
865
|
-
* pipe(20, Num.divide(4));
|
|
866
|
-
* pipe(
|
|
865
|
+
* pipe(20, Num.divide(4)); // Some(5)
|
|
866
|
+
* pipe(5, Num.divide(0)); // None
|
|
867
|
+
* pipe([10, 20, 30], Arr.filterMap(Num.divide(10))); // [1, 2, 3]
|
|
867
868
|
* ```
|
|
868
869
|
*/
|
|
869
|
-
const divide: (b: number) => (a: number) => number
|
|
870
|
+
const divide: (b: number) => (a: number) => Maybe<number>;
|
|
870
871
|
/**
|
|
871
872
|
* Returns the absolute value of a number.
|
|
872
873
|
*
|
|
@@ -918,15 +919,17 @@ declare namespace Num {
|
|
|
918
919
|
*/
|
|
919
920
|
const ceil: (n: number) => number;
|
|
920
921
|
/**
|
|
921
|
-
* Returns the remainder of dividing a number by `divisor`.
|
|
922
|
+
* Returns the remainder of dividing a number by `divisor`. Returns `None` when `divisor` is zero.
|
|
923
|
+
* Data-last: `remainder(divisor)(a)` = `a % divisor`.
|
|
922
924
|
*
|
|
923
925
|
* @example
|
|
924
926
|
* ```ts
|
|
925
|
-
* pipe(10, Num.remainder(3));
|
|
926
|
-
* pipe(
|
|
927
|
+
* pipe(10, Num.remainder(3)); // Some(1)
|
|
928
|
+
* pipe(5, Num.remainder(0)); // None
|
|
929
|
+
* pipe([10, 11, 12], Arr.filterMap(Num.remainder(3))); // [1, 2, 0]
|
|
927
930
|
* ```
|
|
928
931
|
*/
|
|
929
|
-
const remainder: (divisor: number) => (n: number) => number
|
|
932
|
+
const remainder: (divisor: number) => (n: number) => Maybe<number>;
|
|
930
933
|
}
|
|
931
934
|
|
|
932
935
|
/**
|