@nlozgachev/pipelined 0.26.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-7brqoQrb.d.ts → Task-BW66NsGR.d.ts} +43 -11
- package/dist/{Task-BoqaFsUR.d.mts → Task-BZT0wedE.d.mts} +43 -11
- package/dist/{chunk-Z3DYYR43.mjs → chunk-7JF44HJH.mjs} +14 -8
- package/dist/{chunk-6H373E63.mjs → chunk-CA3VE4YD.mjs} +20 -2
- package/dist/{chunk-NTISCH7Z.mjs → chunk-QJS6D6MW.mjs} +13 -2
- package/dist/core.d.mts +82 -8
- package/dist/core.d.ts +82 -8
- package/dist/core.js +26 -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 +45 -10
- package/dist/index.mjs +3 -3
- package/dist/utils.d.mts +140 -5
- package/dist/utils.d.ts +140 -5
- package/dist/utils.js +33 -9
- package/dist/utils.mjs +2 -2
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
Maybe,
|
|
4
4
|
Result,
|
|
5
5
|
Task
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-7JF44HJH.mjs";
|
|
7
7
|
import {
|
|
8
8
|
isNonEmptyList
|
|
9
9
|
} from "./chunk-DBIC62UV.mjs";
|
|
@@ -35,6 +35,12 @@ var Arr;
|
|
|
35
35
|
for (let i = 0; i < n; i++) result[i] = f(data[i]);
|
|
36
36
|
return result;
|
|
37
37
|
};
|
|
38
|
+
Arr2.mapWithIndex = (f) => (data) => {
|
|
39
|
+
const n = data.length;
|
|
40
|
+
const result = new Array(n);
|
|
41
|
+
for (let i = 0; i < n; i++) result[i] = f(i, data[i]);
|
|
42
|
+
return result;
|
|
43
|
+
};
|
|
38
44
|
Arr2.filter = (predicate) => (data) => {
|
|
39
45
|
const n = data.length;
|
|
40
46
|
const result = [];
|
|
@@ -361,7 +367,13 @@ var Num;
|
|
|
361
367
|
Num2.add = (b) => (a) => a + b;
|
|
362
368
|
Num2.subtract = (b) => (a) => a - b;
|
|
363
369
|
Num2.multiply = (b) => (a) => a * b;
|
|
364
|
-
Num2.divide = (b) => (a) => a / b;
|
|
370
|
+
Num2.divide = (b) => (a) => b === 0 ? Maybe.none() : Maybe.some(a / b);
|
|
371
|
+
Num2.abs = (n) => Math.abs(n);
|
|
372
|
+
Num2.negate = (n) => -n;
|
|
373
|
+
Num2.round = (n) => Math.round(n);
|
|
374
|
+
Num2.floor = (n) => Math.floor(n);
|
|
375
|
+
Num2.ceil = (n) => Math.ceil(n);
|
|
376
|
+
Num2.remainder = (divisor) => (n) => divisor === 0 ? Maybe.none() : Maybe.some(n % divisor);
|
|
365
377
|
})(Num || (Num = {}));
|
|
366
378
|
|
|
367
379
|
// src/Utils/Rec.ts
|
|
@@ -487,6 +499,12 @@ var Str;
|
|
|
487
499
|
Str2.toLowerCase = (s) => s.toLowerCase();
|
|
488
500
|
Str2.lines = (s) => s.split(/\r?\n|\r/);
|
|
489
501
|
Str2.words = (s) => s.trim().split(/\s+/).filter(Boolean);
|
|
502
|
+
Str2.isEmpty = (s) => s.length === 0;
|
|
503
|
+
Str2.isBlank = (s) => s.trim().length === 0;
|
|
504
|
+
Str2.length = (s) => s.length;
|
|
505
|
+
Str2.slice = (start, end) => (s) => s.slice(start, end);
|
|
506
|
+
Str2.padStart = (maxLength, fillString) => (s) => s.padStart(maxLength, fillString);
|
|
507
|
+
Str2.padEnd = (maxLength, fillString) => (s) => s.padEnd(maxLength, fillString);
|
|
490
508
|
Str2.parse = {
|
|
491
509
|
/**
|
|
492
510
|
* Parses a string as an integer (base 10). Returns `None` if the result is `NaN`.
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
Maybe,
|
|
4
4
|
Result,
|
|
5
5
|
Task
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-7JF44HJH.mjs";
|
|
7
7
|
|
|
8
8
|
// src/Core/Lens.ts
|
|
9
9
|
var Lens;
|
|
@@ -1089,10 +1089,15 @@ var RemoteData;
|
|
|
1089
1089
|
if ((0, RemoteData2.isSuccess)(data)) f(data.value);
|
|
1090
1090
|
return data;
|
|
1091
1091
|
};
|
|
1092
|
+
RemoteData2.tapError = (f) => (data) => {
|
|
1093
|
+
if ((0, RemoteData2.isFailure)(data)) f(data.error);
|
|
1094
|
+
return data;
|
|
1095
|
+
};
|
|
1092
1096
|
RemoteData2.recover = (fallback) => (data) => (0, RemoteData2.isFailure)(data) ? fallback(data.error) : data;
|
|
1093
1097
|
RemoteData2.toMaybe = (data) => (0, RemoteData2.isSuccess)(data) ? Maybe.some(data.value) : Maybe.none();
|
|
1094
1098
|
RemoteData2.toResult = (onNotReady) => (data) => (0, RemoteData2.isSuccess)(data) ? Result.ok(data.value) : Result.err((0, RemoteData2.isFailure)(data) ? data.error : onNotReady());
|
|
1095
1099
|
RemoteData2.fromResult = (data) => Result.isOk(data) ? (0, RemoteData2.success)(data.value) : (0, RemoteData2.failure)(data.error);
|
|
1100
|
+
RemoteData2.fromMaybe = (onNone) => (data) => Maybe.isSome(data) ? (0, RemoteData2.success)(data.value) : (0, RemoteData2.failure)(onNone());
|
|
1096
1101
|
})(RemoteData || (RemoteData = {}));
|
|
1097
1102
|
|
|
1098
1103
|
// src/Core/Resource.ts
|
|
@@ -1226,6 +1231,7 @@ var Validation;
|
|
|
1226
1231
|
});
|
|
1227
1232
|
Validation2.isValid = (data) => data.kind === "Valid";
|
|
1228
1233
|
Validation2.isInvalid = (data) => data.kind === "Invalid";
|
|
1234
|
+
Validation2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Validation2.valid)(a) : (0, Validation2.invalid)(onFalse(a));
|
|
1229
1235
|
Validation2.map = (f) => (data) => (0, Validation2.isValid)(data) ? (0, Validation2.valid)(f(data.value)) : data;
|
|
1230
1236
|
Validation2.ap = (arg) => (data) => {
|
|
1231
1237
|
if ((0, Validation2.isValid)(data) && (0, Validation2.isValid)(arg)) return (0, Validation2.valid)(data.value(arg.value));
|
|
@@ -1242,8 +1248,13 @@ var Validation;
|
|
|
1242
1248
|
if ((0, Validation2.isValid)(data)) f(data.value);
|
|
1243
1249
|
return data;
|
|
1244
1250
|
};
|
|
1251
|
+
Validation2.tapError = (f) => (data) => {
|
|
1252
|
+
if ((0, Validation2.isInvalid)(data)) f(data.errors);
|
|
1253
|
+
return data;
|
|
1254
|
+
};
|
|
1245
1255
|
Validation2.recover = (fallback) => (data) => (0, Validation2.isValid)(data) ? data : fallback(data.errors);
|
|
1246
|
-
Validation2.recoverUnless = (
|
|
1256
|
+
Validation2.recoverUnless = (isBlocked, fallback) => (data) => (0, Validation2.isInvalid)(data) && !data.errors.some(isBlocked) ? fallback() : data;
|
|
1257
|
+
Validation2.toResult = (data) => (0, Validation2.isValid)(data) ? Result.ok(data.value) : Result.err(data.errors);
|
|
1247
1258
|
Validation2.product = (first, second) => {
|
|
1248
1259
|
if ((0, Validation2.isValid)(first) && (0, Validation2.isValid)(second)) return (0, Validation2.valid)([first.value, second.value]);
|
|
1249
1260
|
const errors = [
|
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>`.
|
|
@@ -1655,6 +1669,17 @@ declare namespace RemoteData {
|
|
|
1655
1669
|
* ```
|
|
1656
1670
|
*/
|
|
1657
1671
|
const fromResult: <E, A>(data: Result<E, A>) => RemoteData<E, A>;
|
|
1672
|
+
/**
|
|
1673
|
+
* Converts a Maybe to a RemoteData.
|
|
1674
|
+
* Some becomes Success, None becomes Failure using the onNone error producer.
|
|
1675
|
+
*
|
|
1676
|
+
* @example
|
|
1677
|
+
* ```ts
|
|
1678
|
+
* pipe(Maybe.some(user), RemoteData.fromMaybe(() => "not found")); // Success(user)
|
|
1679
|
+
* pipe(Maybe.none(), RemoteData.fromMaybe(() => "not found")); // Failure("not found")
|
|
1680
|
+
* ```
|
|
1681
|
+
*/
|
|
1682
|
+
const fromMaybe: <E>(onNone: () => E) => <A>(data: Maybe<A>) => RemoteData<E, A>;
|
|
1658
1683
|
}
|
|
1659
1684
|
|
|
1660
1685
|
/**
|
|
@@ -2219,6 +2244,22 @@ declare namespace Validation {
|
|
|
2219
2244
|
* Type guard that checks if a Validation is invalid.
|
|
2220
2245
|
*/
|
|
2221
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>;
|
|
2222
2263
|
/**
|
|
2223
2264
|
* Transforms the success value inside a Validation.
|
|
2224
2265
|
*
|
|
@@ -2308,6 +2349,20 @@ declare namespace Validation {
|
|
|
2308
2349
|
* ```
|
|
2309
2350
|
*/
|
|
2310
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>;
|
|
2311
2366
|
/**
|
|
2312
2367
|
* Recovers from an Invalid state by providing a fallback Validation.
|
|
2313
2368
|
* The fallback receives the accumulated error list so callers can inspect which errors occurred.
|
|
@@ -2315,10 +2370,29 @@ declare namespace Validation {
|
|
|
2315
2370
|
*/
|
|
2316
2371
|
const recover: <E, A, B>(fallback: (errors: NonEmptyList<E>) => Validation<E, B>) => (data: Validation<E, A>) => Validation<E, A | B>;
|
|
2317
2372
|
/**
|
|
2318
|
-
* Recovers from an Invalid state unless
|
|
2373
|
+
* Recovers from an Invalid state unless `isBlocked` returns true for any of the accumulated errors.
|
|
2319
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
|
+
* ```
|
|
2320
2394
|
*/
|
|
2321
|
-
const
|
|
2395
|
+
const toResult: <E, A>(data: Validation<E, A>) => Result<NonEmptyList<E>, A>;
|
|
2322
2396
|
/**
|
|
2323
2397
|
* Combines two independent Validation instances into a tuple.
|
|
2324
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>`.
|
|
@@ -1655,6 +1669,17 @@ declare namespace RemoteData {
|
|
|
1655
1669
|
* ```
|
|
1656
1670
|
*/
|
|
1657
1671
|
const fromResult: <E, A>(data: Result<E, A>) => RemoteData<E, A>;
|
|
1672
|
+
/**
|
|
1673
|
+
* Converts a Maybe to a RemoteData.
|
|
1674
|
+
* Some becomes Success, None becomes Failure using the onNone error producer.
|
|
1675
|
+
*
|
|
1676
|
+
* @example
|
|
1677
|
+
* ```ts
|
|
1678
|
+
* pipe(Maybe.some(user), RemoteData.fromMaybe(() => "not found")); // Success(user)
|
|
1679
|
+
* pipe(Maybe.none(), RemoteData.fromMaybe(() => "not found")); // Failure("not found")
|
|
1680
|
+
* ```
|
|
1681
|
+
*/
|
|
1682
|
+
const fromMaybe: <E>(onNone: () => E) => <A>(data: Maybe<A>) => RemoteData<E, A>;
|
|
1658
1683
|
}
|
|
1659
1684
|
|
|
1660
1685
|
/**
|
|
@@ -2219,6 +2244,22 @@ declare namespace Validation {
|
|
|
2219
2244
|
* Type guard that checks if a Validation is invalid.
|
|
2220
2245
|
*/
|
|
2221
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>;
|
|
2222
2263
|
/**
|
|
2223
2264
|
* Transforms the success value inside a Validation.
|
|
2224
2265
|
*
|
|
@@ -2308,6 +2349,20 @@ declare namespace Validation {
|
|
|
2308
2349
|
* ```
|
|
2309
2350
|
*/
|
|
2310
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>;
|
|
2311
2366
|
/**
|
|
2312
2367
|
* Recovers from an Invalid state by providing a fallback Validation.
|
|
2313
2368
|
* The fallback receives the accumulated error list so callers can inspect which errors occurred.
|
|
@@ -2315,10 +2370,29 @@ declare namespace Validation {
|
|
|
2315
2370
|
*/
|
|
2316
2371
|
const recover: <E, A, B>(fallback: (errors: NonEmptyList<E>) => Validation<E, B>) => (data: Validation<E, A>) => Validation<E, A | B>;
|
|
2317
2372
|
/**
|
|
2318
|
-
* Recovers from an Invalid state unless
|
|
2373
|
+
* Recovers from an Invalid state unless `isBlocked` returns true for any of the accumulated errors.
|
|
2319
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
|
+
* ```
|
|
2320
2394
|
*/
|
|
2321
|
-
const
|
|
2395
|
+
const toResult: <E, A>(data: Validation<E, A>) => Result<NonEmptyList<E>, A>;
|
|
2322
2396
|
/**
|
|
2323
2397
|
* Combines two independent Validation instances into a tuple.
|
|
2324
2398
|
* If both are Valid, returns Valid with both values as a tuple.
|
package/dist/core.js
CHANGED
|
@@ -130,8 +130,9 @@ var Result;
|
|
|
130
130
|
if ((0, Result2.isErr)(data)) f(data.error);
|
|
131
131
|
return data;
|
|
132
132
|
};
|
|
133
|
+
Result2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Result2.ok)(a) : (0, Result2.err)(onFalse(a));
|
|
133
134
|
Result2.recover = (fallback) => (data) => (0, Result2.isOk)(data) ? data : fallback(data.error);
|
|
134
|
-
Result2.recoverUnless = (
|
|
135
|
+
Result2.recoverUnless = (isBlocked, fallback) => (data) => (0, Result2.isErr)(data) && !isBlocked(data.error) ? fallback() : data;
|
|
135
136
|
Result2.toMaybe = (data) => (0, Result2.isOk)(data) ? Maybe.some(data.value) : Maybe.none();
|
|
136
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;
|
|
137
138
|
})(Result || (Result = {}));
|
|
@@ -147,7 +148,6 @@ var Maybe;
|
|
|
147
148
|
Maybe2.fromNullable = (value) => value === null || value === void 0 ? (0, Maybe2.none)() : (0, Maybe2.some)(value);
|
|
148
149
|
Maybe2.toNullable = (data) => (0, Maybe2.isSome)(data) ? data.value : null;
|
|
149
150
|
Maybe2.toUndefined = (data) => (0, Maybe2.isSome)(data) ? data.value : void 0;
|
|
150
|
-
Maybe2.fromUndefined = (value) => value === void 0 ? (0, Maybe2.none)() : (0, Maybe2.some)(value);
|
|
151
151
|
Maybe2.fromPredicate = (pred) => (a) => pred(a) ? (0, Maybe2.some)(a) : (0, Maybe2.none)();
|
|
152
152
|
Maybe2.toResult = (onNone) => (data) => (0, Maybe2.isSome)(data) ? Result.ok(data.value) : Result.err(onNone());
|
|
153
153
|
Maybe2.fromResult = (data) => Result.isOk(data) ? (0, Maybe2.some)(data.value) : (0, Maybe2.none)();
|
|
@@ -1200,10 +1200,15 @@ var RemoteData;
|
|
|
1200
1200
|
if ((0, RemoteData2.isSuccess)(data)) f(data.value);
|
|
1201
1201
|
return data;
|
|
1202
1202
|
};
|
|
1203
|
+
RemoteData2.tapError = (f) => (data) => {
|
|
1204
|
+
if ((0, RemoteData2.isFailure)(data)) f(data.error);
|
|
1205
|
+
return data;
|
|
1206
|
+
};
|
|
1203
1207
|
RemoteData2.recover = (fallback) => (data) => (0, RemoteData2.isFailure)(data) ? fallback(data.error) : data;
|
|
1204
1208
|
RemoteData2.toMaybe = (data) => (0, RemoteData2.isSuccess)(data) ? Maybe.some(data.value) : Maybe.none();
|
|
1205
1209
|
RemoteData2.toResult = (onNotReady) => (data) => (0, RemoteData2.isSuccess)(data) ? Result.ok(data.value) : Result.err((0, RemoteData2.isFailure)(data) ? data.error : onNotReady());
|
|
1206
1210
|
RemoteData2.fromResult = (data) => Result.isOk(data) ? (0, RemoteData2.success)(data.value) : (0, RemoteData2.failure)(data.error);
|
|
1211
|
+
RemoteData2.fromMaybe = (onNone) => (data) => Maybe.isSome(data) ? (0, RemoteData2.success)(data.value) : (0, RemoteData2.failure)(onNone());
|
|
1207
1212
|
})(RemoteData || (RemoteData = {}));
|
|
1208
1213
|
|
|
1209
1214
|
// src/Core/Task.ts
|
|
@@ -1212,6 +1217,7 @@ var Task;
|
|
|
1212
1217
|
((Task2) => {
|
|
1213
1218
|
Task2.resolve = (value) => () => Deferred.fromPromise(Promise.resolve(value));
|
|
1214
1219
|
Task2.from = (f) => (signal) => Deferred.fromPromise(f(signal));
|
|
1220
|
+
Task2.fromSync = (f) => () => Deferred.fromPromise(Promise.resolve(f()));
|
|
1215
1221
|
Task2.map = (f) => (data) => (0, Task2.from)((signal) => toPromise(data, signal).then(f));
|
|
1216
1222
|
Task2.chain = (f) => (data) => (0, Task2.from)((signal) => toPromise(data, signal).then((a) => toPromise(f(a), signal)));
|
|
1217
1223
|
Task2.ap = (arg) => (data) => (0, Task2.from)(
|
|
@@ -1250,13 +1256,14 @@ var Task;
|
|
|
1250
1256
|
return run(times);
|
|
1251
1257
|
});
|
|
1252
1258
|
Task2.repeatUntil = (options) => (task) => (0, Task2.from)((signal) => {
|
|
1253
|
-
const { when: predicate, delay: ms } = options;
|
|
1259
|
+
const { when: predicate, delay: ms, maxAttempts } = options;
|
|
1254
1260
|
const wait = () => ms !== void 0 && ms > 0 ? new Promise((r) => setTimeout(r, ms)) : Promise.resolve();
|
|
1255
|
-
const run = () => toPromise(task, signal).then((a) => {
|
|
1261
|
+
const run = (attempt) => toPromise(task, signal).then((a) => {
|
|
1256
1262
|
if (predicate(a)) return a;
|
|
1257
|
-
|
|
1263
|
+
if (maxAttempts !== void 0 && attempt >= maxAttempts) return a;
|
|
1264
|
+
return wait().then(() => run(attempt + 1));
|
|
1258
1265
|
});
|
|
1259
|
-
return run();
|
|
1266
|
+
return run(1);
|
|
1260
1267
|
});
|
|
1261
1268
|
Task2.race = (tasks) => (0, Task2.from)((signal) => Promise.race(tasks.map((t) => toPromise(t, signal))));
|
|
1262
1269
|
Task2.sequential = (tasks) => (0, Task2.from)(async (signal) => {
|
|
@@ -1287,8 +1294,12 @@ var Task;
|
|
|
1287
1294
|
]);
|
|
1288
1295
|
});
|
|
1289
1296
|
Task2.abortable = (factory) => {
|
|
1290
|
-
|
|
1297
|
+
let currentController = null;
|
|
1298
|
+
const abort = () => currentController?.abort();
|
|
1291
1299
|
const task = (outerSignal) => {
|
|
1300
|
+
currentController?.abort();
|
|
1301
|
+
currentController = new AbortController();
|
|
1302
|
+
const controller = currentController;
|
|
1292
1303
|
if (outerSignal) {
|
|
1293
1304
|
if (outerSignal.aborted) {
|
|
1294
1305
|
controller.abort(outerSignal.reason);
|
|
@@ -1298,7 +1309,7 @@ var Task;
|
|
|
1298
1309
|
}
|
|
1299
1310
|
return Deferred.fromPromise(factory(controller.signal));
|
|
1300
1311
|
};
|
|
1301
|
-
return { task, abort
|
|
1312
|
+
return { task, abort };
|
|
1302
1313
|
};
|
|
1303
1314
|
})(Task || (Task = {}));
|
|
1304
1315
|
|
|
@@ -1433,6 +1444,7 @@ var Validation;
|
|
|
1433
1444
|
});
|
|
1434
1445
|
Validation2.isValid = (data) => data.kind === "Valid";
|
|
1435
1446
|
Validation2.isInvalid = (data) => data.kind === "Invalid";
|
|
1447
|
+
Validation2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Validation2.valid)(a) : (0, Validation2.invalid)(onFalse(a));
|
|
1436
1448
|
Validation2.map = (f) => (data) => (0, Validation2.isValid)(data) ? (0, Validation2.valid)(f(data.value)) : data;
|
|
1437
1449
|
Validation2.ap = (arg) => (data) => {
|
|
1438
1450
|
if ((0, Validation2.isValid)(data) && (0, Validation2.isValid)(arg)) return (0, Validation2.valid)(data.value(arg.value));
|
|
@@ -1449,8 +1461,13 @@ var Validation;
|
|
|
1449
1461
|
if ((0, Validation2.isValid)(data)) f(data.value);
|
|
1450
1462
|
return data;
|
|
1451
1463
|
};
|
|
1464
|
+
Validation2.tapError = (f) => (data) => {
|
|
1465
|
+
if ((0, Validation2.isInvalid)(data)) f(data.errors);
|
|
1466
|
+
return data;
|
|
1467
|
+
};
|
|
1452
1468
|
Validation2.recover = (fallback) => (data) => (0, Validation2.isValid)(data) ? data : fallback(data.errors);
|
|
1453
|
-
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);
|
|
1454
1471
|
Validation2.product = (first, second) => {
|
|
1455
1472
|
if ((0, Validation2.isValid)(first) && (0, Validation2.isValid)(second)) return (0, Validation2.valid)([first.value, second.value]);
|
|
1456
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';
|