@nlozgachev/pipelined 0.42.0 → 0.44.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 +10 -10
- package/dist/InternalTypes-7o9-yrHq.d.ts +118 -0
- package/dist/InternalTypes-BL23H8Qr.d.mts +118 -0
- package/dist/{Task-BprUabHP.d.mts → Validation-DM2eh6wj.d.ts} +877 -113
- package/dist/{Task-Dt3ZMen6.d.ts → Validation-Dz70wtcG.d.mts} +877 -113
- package/dist/{chunk-GBB6LVLI.mjs → chunk-74JKKJ4R.mjs} +0 -4
- package/dist/{chunk-6VYLZTAM.mjs → chunk-LKTOK5IT.mjs} +157 -69
- package/dist/{chunk-OAP765G3.mjs → chunk-ND476266.mjs} +179 -134
- package/dist/{chunk-F6SBU7GB.mjs → chunk-X6XQX3OZ.mjs} +3 -3
- package/dist/composition.d.mts +45 -44
- package/dist/composition.d.ts +45 -44
- package/dist/composition.js +2 -2
- package/dist/composition.mjs +2 -2
- package/dist/core.d.mts +11 -813
- package/dist/core.d.ts +11 -813
- package/dist/core.js +176 -132
- package/dist/core.mjs +2 -2
- package/dist/index.d.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +332 -203
- package/dist/index.mjs +5 -7
- package/dist/types.d.mts +112 -17
- package/dist/types.d.ts +112 -17
- package/dist/types.js +2 -7
- package/dist/types.mjs +3 -5
- package/dist/utils.d.mts +345 -89
- package/dist/utils.d.ts +345 -89
- package/dist/utils.js +429 -107
- package/dist/utils.mjs +3 -3
- package/package.json +6 -6
- package/dist/Duration-BTeT9D-q.d.mts +0 -127
- package/dist/Duration-BTeT9D-q.d.ts +0 -127
package/dist/core.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { M as Maybe,
|
|
2
|
-
export { E as Equality, a as Err, N as None, O as Ok, b as Ordering, S as Some } from './
|
|
3
|
-
import { D as
|
|
4
|
-
import {
|
|
1
|
+
import { M as Maybe, R as Result, T as Task } from './Validation-DM2eh6wj.js';
|
|
2
|
+
export { E as Equality, a as Err, F as Failed, N as None, O as Ok, b as Ordering, P as Passed, S as Some, c as TaskMaybe, d as TaskResult, e as TaskValidation, V as Validation } from './Validation-DM2eh6wj.js';
|
|
3
|
+
import { n as WithValue, h as WithLog, D as Deferred, g as WithKind, d as WithError, R as RetryOptions, a as TimeoutOptions, m as WithTimeout, i as WithMinInterval, b as WithCooldown, W as WithConcurrency, l as WithSize, c as WithDuration, j as WithN, f as WithFirst, k as WithSecond } from './InternalTypes-7o9-yrHq.js';
|
|
4
|
+
import { Duration } from './types.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* A type that can combine two values of type `A` into one, with a neutral starting value.
|
|
@@ -1972,7 +1972,7 @@ declare namespace RemoteData {
|
|
|
1972
1972
|
*
|
|
1973
1973
|
* @example
|
|
1974
1974
|
* ```ts
|
|
1975
|
-
* const result = await
|
|
1975
|
+
* const result = await Task.Result.tryCatch(fetchUser, String)();
|
|
1976
1976
|
* setState(RemoteData.fromResult(result)); // Success(user) or Failure(msg)
|
|
1977
1977
|
* ```
|
|
1978
1978
|
*/
|
|
@@ -2021,7 +2021,7 @@ declare namespace RemoteData {
|
|
|
2021
2021
|
* @example
|
|
2022
2022
|
* ```ts
|
|
2023
2023
|
* const dbResource = Resource.make(
|
|
2024
|
-
*
|
|
2024
|
+
* Task.Result.tryCatch(() => openConnection(config), (e) => new DbError(e)),
|
|
2025
2025
|
* (conn) => Task.from(() => conn.close())
|
|
2026
2026
|
* );
|
|
2027
2027
|
*
|
|
@@ -2033,7 +2033,7 @@ declare namespace RemoteData {
|
|
|
2033
2033
|
* ```
|
|
2034
2034
|
*/
|
|
2035
2035
|
type Resource<E, A> = {
|
|
2036
|
-
readonly acquire:
|
|
2036
|
+
readonly acquire: Task.Result<E, A>;
|
|
2037
2037
|
readonly release: (a: A) => Task<void>;
|
|
2038
2038
|
};
|
|
2039
2039
|
declare namespace Resource {
|
|
@@ -2043,12 +2043,12 @@ declare namespace Resource {
|
|
|
2043
2043
|
* @example
|
|
2044
2044
|
* ```ts
|
|
2045
2045
|
* const fileResource = Resource.make(
|
|
2046
|
-
*
|
|
2046
|
+
* Task.Result.tryCatch(() => fs.promises.open("data.csv", "r"), toFileError),
|
|
2047
2047
|
* (handle) => Task.from(() => handle.close())
|
|
2048
2048
|
* );
|
|
2049
2049
|
* ```
|
|
2050
2050
|
*/
|
|
2051
|
-
const make: <E, A>(acquire:
|
|
2051
|
+
const make: <E, A>(acquire: Task.Result<E, A>, release: (a: A) => Task<void>) => Resource<E, A>;
|
|
2052
2052
|
/**
|
|
2053
2053
|
* Creates a Resource from an acquire operation that cannot fail.
|
|
2054
2054
|
* Use this when opening the resource is guaranteed to succeed, such as
|
|
@@ -2078,7 +2078,7 @@ declare namespace Resource {
|
|
|
2078
2078
|
* // conn is closed whether the query succeeds or fails
|
|
2079
2079
|
* ```
|
|
2080
2080
|
*/
|
|
2081
|
-
const use: <E, A, B>(f: (a: A) =>
|
|
2081
|
+
const use: <E, A, B>(f: (a: A) => Task.Result<E, B>) => (resource: Resource<E, A>) => Task.Result<E, B>;
|
|
2082
2082
|
/**
|
|
2083
2083
|
* Acquires two resources in sequence and presents them as a tuple.
|
|
2084
2084
|
* Resources are released in reverse order: the second is released before the first.
|
|
@@ -2312,483 +2312,6 @@ declare namespace State {
|
|
|
2312
2312
|
const bind: <K extends string, S, A, B>(key: K, f: (a: A) => State<S, B>) => (data: State<S, A>) => State<S, A & { [P in K]: B; }>;
|
|
2313
2313
|
}
|
|
2314
2314
|
|
|
2315
|
-
/**
|
|
2316
|
-
* A Task that resolves to an optional value.
|
|
2317
|
-
* Combines async operations with the Maybe type for values that may not exist.
|
|
2318
|
-
*
|
|
2319
|
-
* @example
|
|
2320
|
-
* ```ts
|
|
2321
|
-
* const findUser = (id: string): TaskMaybe<User> =>
|
|
2322
|
-
* TaskMaybe.tryCatch(() => db.users.findById(id));
|
|
2323
|
-
*
|
|
2324
|
-
* pipe(
|
|
2325
|
-
* findUser("123"),
|
|
2326
|
-
* TaskMaybe.map(user => user.name),
|
|
2327
|
-
* TaskMaybe.getOrElse(() => "Unknown")
|
|
2328
|
-
* )();
|
|
2329
|
-
* ```
|
|
2330
|
-
*/
|
|
2331
|
-
type TaskMaybe<A> = Task<Maybe<A>>;
|
|
2332
|
-
declare namespace TaskMaybe {
|
|
2333
|
-
/**
|
|
2334
|
-
* Wraps a value in a Some inside a Task.
|
|
2335
|
-
*/
|
|
2336
|
-
const some: <A>(value: A) => TaskMaybe<A>;
|
|
2337
|
-
/**
|
|
2338
|
-
* Creates a TaskMaybe that resolves to None.
|
|
2339
|
-
*/
|
|
2340
|
-
const none: <A = never>() => TaskMaybe<A>;
|
|
2341
|
-
/**
|
|
2342
|
-
* Lifts an Option into a TaskMaybe.
|
|
2343
|
-
*/
|
|
2344
|
-
const fromMaybe: <A>(option: Maybe<A>) => TaskMaybe<A>;
|
|
2345
|
-
/**
|
|
2346
|
-
* Creates a TaskMaybe from a nullable value.
|
|
2347
|
-
* Returns Some if the value is not null or undefined, None otherwise.
|
|
2348
|
-
*/
|
|
2349
|
-
const fromNullable: <A>(value: A | null | undefined) => TaskMaybe<A>;
|
|
2350
|
-
/**
|
|
2351
|
-
* Creates a TaskMaybe from a Result.
|
|
2352
|
-
* Ok becomes Some, Error becomes None (the error value is discarded).
|
|
2353
|
-
*/
|
|
2354
|
-
const fromResult: <E, A>(result: Result<E, A>) => TaskMaybe<A>;
|
|
2355
|
-
/**
|
|
2356
|
-
* Lifts a Task into a TaskMaybe by wrapping its result in Some.
|
|
2357
|
-
*/
|
|
2358
|
-
const fromTask: <A>(task: Task<A>) => TaskMaybe<A>;
|
|
2359
|
-
/**
|
|
2360
|
-
* Creates a TaskMaybe from a Promise-returning function.
|
|
2361
|
-
* Returns Some if the promise resolves, None if it rejects.
|
|
2362
|
-
* The factory optionally receives an `AbortSignal` forwarded from the call site.
|
|
2363
|
-
*
|
|
2364
|
-
* @example
|
|
2365
|
-
* ```ts
|
|
2366
|
-
* const fetchUser = TaskMaybe.tryCatch((signal) =>
|
|
2367
|
-
* fetch("/user/1", { signal }).then(r => r.json())
|
|
2368
|
-
* );
|
|
2369
|
-
* ```
|
|
2370
|
-
*/
|
|
2371
|
-
const tryCatch: <A>(f: (signal?: AbortSignal) => Promise<A>) => TaskMaybe<A>;
|
|
2372
|
-
/**
|
|
2373
|
-
* Transforms the value inside a TaskMaybe.
|
|
2374
|
-
*/
|
|
2375
|
-
const map: <A, B>(f: (a: A) => B) => (data: TaskMaybe<A>) => TaskMaybe<B>;
|
|
2376
|
-
/**
|
|
2377
|
-
* Chains TaskMaybe computations. If the first resolves to Some, passes the
|
|
2378
|
-
* value to f. If the first resolves to None, propagates None.
|
|
2379
|
-
*
|
|
2380
|
-
* @example
|
|
2381
|
-
* ```ts
|
|
2382
|
-
* pipe(
|
|
2383
|
-
* findUser("123"),
|
|
2384
|
-
* TaskMaybe.chain(user => findOrg(user.orgId))
|
|
2385
|
-
* )();
|
|
2386
|
-
* ```
|
|
2387
|
-
*/
|
|
2388
|
-
const chain: <A, B>(f: (a: A) => TaskMaybe<B>) => (data: TaskMaybe<A>) => TaskMaybe<B>;
|
|
2389
|
-
/**
|
|
2390
|
-
* Applies a function wrapped in a TaskMaybe to a value wrapped in a TaskMaybe.
|
|
2391
|
-
* Both Tasks run in parallel.
|
|
2392
|
-
*/
|
|
2393
|
-
const ap: <A>(arg: TaskMaybe<A>) => <B>(data: TaskMaybe<(a: A) => B>) => TaskMaybe<B>;
|
|
2394
|
-
/**
|
|
2395
|
-
* Extracts a value from a TaskMaybe by providing handlers for both cases.
|
|
2396
|
-
*/
|
|
2397
|
-
const fold: <A, B>(onNone: () => B, onSome: (a: A) => B) => (data: TaskMaybe<A>) => Task<B>;
|
|
2398
|
-
/**
|
|
2399
|
-
* Pattern matches on a TaskMaybe, returning a Task of the result.
|
|
2400
|
-
*
|
|
2401
|
-
* @example
|
|
2402
|
-
* ```ts
|
|
2403
|
-
* pipe(
|
|
2404
|
-
* findUser("123"),
|
|
2405
|
-
* TaskMaybe.match({
|
|
2406
|
-
* some: user => `Hello, ${user.name}`,
|
|
2407
|
-
* none: () => "User not found"
|
|
2408
|
-
* })
|
|
2409
|
-
* )();
|
|
2410
|
-
* ```
|
|
2411
|
-
*/
|
|
2412
|
-
const match: <A, B>(cases: {
|
|
2413
|
-
none: () => B;
|
|
2414
|
-
some: (a: A) => B;
|
|
2415
|
-
}) => (data: TaskMaybe<A>) => Task<B>;
|
|
2416
|
-
/**
|
|
2417
|
-
* Returns the value or a default if the TaskMaybe resolves to None.
|
|
2418
|
-
* The default can be a different type, widening the result to `Task<A | B>`.
|
|
2419
|
-
*/
|
|
2420
|
-
const getOrElse: <A, B>(defaultValue: () => B) => (data: TaskMaybe<A>) => Task<A | B>;
|
|
2421
|
-
/**
|
|
2422
|
-
* Executes a side effect on the value without changing the TaskMaybe.
|
|
2423
|
-
* Useful for logging or debugging.
|
|
2424
|
-
*/
|
|
2425
|
-
const tap: <A>(f: (a: A) => void) => (data: TaskMaybe<A>) => TaskMaybe<A>;
|
|
2426
|
-
/**
|
|
2427
|
-
* Filters the value inside a TaskMaybe. Returns None if the predicate fails.
|
|
2428
|
-
*/
|
|
2429
|
-
const filter: <A>(predicate: (a: A) => boolean) => (data: TaskMaybe<A>) => TaskMaybe<A>;
|
|
2430
|
-
/**
|
|
2431
|
-
* Converts a TaskMaybe to a TaskResult, using onNone to produce the error value.
|
|
2432
|
-
*
|
|
2433
|
-
* @example
|
|
2434
|
-
* ```ts
|
|
2435
|
-
* pipe(
|
|
2436
|
-
* findUser("123"),
|
|
2437
|
-
* TaskMaybe.toTaskResult(() => "User not found")
|
|
2438
|
-
* );
|
|
2439
|
-
* ```
|
|
2440
|
-
*/
|
|
2441
|
-
const toTaskResult: <E>(onNone: () => E) => <A>(data: TaskMaybe<A>) => TaskResult<E, A>;
|
|
2442
|
-
/**
|
|
2443
|
-
* Lifts a TaskMaybe value into an accumulator object.
|
|
2444
|
-
*
|
|
2445
|
-
* @example
|
|
2446
|
-
* ```ts
|
|
2447
|
-
* pipe(TaskMaybe.some(42), TaskMaybe.bindTo("value")); // TaskMaybe({ value: 42 })
|
|
2448
|
-
* ```
|
|
2449
|
-
*/
|
|
2450
|
-
const bindTo: <K extends string>(key: K) => <A>(data: TaskMaybe<A>) => TaskMaybe<{ [P in K]: A; }>;
|
|
2451
|
-
/**
|
|
2452
|
-
* Evaluates a new TaskMaybe using the current accumulator and attaches the output to a new key.
|
|
2453
|
-
*
|
|
2454
|
-
* @example
|
|
2455
|
-
* ```ts
|
|
2456
|
-
* pipe(
|
|
2457
|
-
* TaskMaybe.some({ a: 1 }),
|
|
2458
|
-
* TaskMaybe.bind("b", ({ a }) => TaskMaybe.some(a + 1))
|
|
2459
|
-
* ); // TaskMaybe({ a: 1, b: 2 })
|
|
2460
|
-
* ```
|
|
2461
|
-
*/
|
|
2462
|
-
const bind: <K extends string, A, B>(key: K, f: (a: A) => TaskMaybe<B>) => (data: TaskMaybe<A>) => TaskMaybe<A & { [P in K]: B; }>;
|
|
2463
|
-
}
|
|
2464
|
-
|
|
2465
|
-
/**
|
|
2466
|
-
* A Task that can fail with an error of type E or succeed with a value of type A.
|
|
2467
|
-
* Combines async operations with typed error handling.
|
|
2468
|
-
*
|
|
2469
|
-
* @example
|
|
2470
|
-
* ```ts
|
|
2471
|
-
* const fetchUser = (id: string): TaskResult<Error, User> =>
|
|
2472
|
-
* TaskResult.tryCatch(
|
|
2473
|
-
* (signal) => fetch(`/users/${id}`, { signal }).then(r => r.json()),
|
|
2474
|
-
* (e) => new Error(`Failed to fetch user: ${e}`)
|
|
2475
|
-
* );
|
|
2476
|
-
* ```
|
|
2477
|
-
*/
|
|
2478
|
-
type TaskResult<E, A> = Task<Result<E, A>>;
|
|
2479
|
-
declare namespace TaskResult {
|
|
2480
|
-
/**
|
|
2481
|
-
* Wraps a value in a successful TaskResult.
|
|
2482
|
-
*/
|
|
2483
|
-
const ok: <E, A>(value: A) => TaskResult<E, A>;
|
|
2484
|
-
/**
|
|
2485
|
-
* Creates a failed TaskResult with the given error.
|
|
2486
|
-
*/
|
|
2487
|
-
const err: <E, A>(error: E) => TaskResult<E, A>;
|
|
2488
|
-
/**
|
|
2489
|
-
* Creates a TaskResult from a nullable value.
|
|
2490
|
-
* Returns Ok if the value is not null or undefined, err from onNull otherwise.
|
|
2491
|
-
*/
|
|
2492
|
-
const fromNullable: <E>(onNull: () => E) => <A>(value: A | null | undefined) => TaskResult<E, A>;
|
|
2493
|
-
/**
|
|
2494
|
-
* Creates a TaskResult from a Maybe.
|
|
2495
|
-
* Some becomes Ok, None becomes err from onNone.
|
|
2496
|
-
*/
|
|
2497
|
-
const fromMaybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => TaskResult<E, A>;
|
|
2498
|
-
/**
|
|
2499
|
-
* Lifts a Result into a TaskResult.
|
|
2500
|
-
*/
|
|
2501
|
-
const fromResult: <E, A>(result: Result<E, A>) => TaskResult<E, A>;
|
|
2502
|
-
/**
|
|
2503
|
-
* Wraps a Promise-returning function of any arguments, returning a new function
|
|
2504
|
-
* that catches rejections and returns a TaskResult.
|
|
2505
|
-
*/
|
|
2506
|
-
const fromThrowable: <Args extends readonly unknown[], A, E>(f: (...args: Args) => Promise<A>, onError: (e: unknown) => E) => (...args: Args) => TaskResult<E, A>;
|
|
2507
|
-
/**
|
|
2508
|
-
* Creates a TaskResult from a function that may throw.
|
|
2509
|
-
* Catches any errors and transforms them using the onError function.
|
|
2510
|
-
* The factory optionally receives an `AbortSignal` forwarded from the call site.
|
|
2511
|
-
*
|
|
2512
|
-
* @example
|
|
2513
|
-
* ```ts
|
|
2514
|
-
* const fetchUser = (id: string): TaskResult<string, User> =>
|
|
2515
|
-
* TaskResult.tryCatch(
|
|
2516
|
-
* (signal) => fetch(`/users/${id}`, { signal }).then(r => r.json()),
|
|
2517
|
-
* String
|
|
2518
|
-
* );
|
|
2519
|
-
* ```
|
|
2520
|
-
*/
|
|
2521
|
-
const tryCatch: <E, A>(f: (signal?: AbortSignal) => Promise<A>, onError: (e: unknown) => E) => TaskResult<E, A>;
|
|
2522
|
-
/**
|
|
2523
|
-
* Transforms the success value inside a TaskResult.
|
|
2524
|
-
*/
|
|
2525
|
-
const map: <E, A, B>(f: (a: A) => B) => (data: TaskResult<E, A>) => TaskResult<E, B>;
|
|
2526
|
-
/**
|
|
2527
|
-
* Transforms the error value inside a TaskResult.
|
|
2528
|
-
*/
|
|
2529
|
-
const mapError: <E, F, A>(f: (e: E) => F) => (data: TaskResult<E, A>) => TaskResult<F, A>;
|
|
2530
|
-
/**
|
|
2531
|
-
* Chains TaskResult computations. If the first succeeds, passes the value to f.
|
|
2532
|
-
* If the first fails, propagates the error.
|
|
2533
|
-
*/
|
|
2534
|
-
const chain: <E, A, B>(f: (a: A) => TaskResult<E, B>) => (data: TaskResult<E, A>) => TaskResult<E, B>;
|
|
2535
|
-
/**
|
|
2536
|
-
* Extracts the value from a TaskResult by providing handlers for both cases.
|
|
2537
|
-
*/
|
|
2538
|
-
const fold: <E, A, B>(onErr: (e: E) => B, onOk: (a: A) => B) => (data: TaskResult<E, A>) => Task<B>;
|
|
2539
|
-
/**
|
|
2540
|
-
* Pattern matches on a TaskResult, returning a Task of the result.
|
|
2541
|
-
*/
|
|
2542
|
-
const match: <E, A, B>(cases: {
|
|
2543
|
-
err: (e: E) => B;
|
|
2544
|
-
ok: (a: A) => B;
|
|
2545
|
-
}) => (data: TaskResult<E, A>) => Task<B>;
|
|
2546
|
-
/**
|
|
2547
|
-
* Recovers from an error by providing a fallback TaskResult.
|
|
2548
|
-
* The fallback can produce a different success type, widening the result to `TaskResult<E, A | B>`.
|
|
2549
|
-
*/
|
|
2550
|
-
const recover: <E, A, B>(fallback: (e: E) => TaskResult<E, B>) => (data: TaskResult<E, A>) => TaskResult<E, A | B>;
|
|
2551
|
-
/**
|
|
2552
|
-
* Returns the success value or a default value if the TaskResult is an error.
|
|
2553
|
-
* The default can be a different type, widening the result to `Task<A | B>`.
|
|
2554
|
-
*/
|
|
2555
|
-
const getOrElse: <E, A, B>(defaultValue: () => B) => (data: TaskResult<E, A>) => Task<A | B>;
|
|
2556
|
-
/**
|
|
2557
|
-
* Executes a side effect on the success value without changing the TaskResult.
|
|
2558
|
-
* Useful for logging or debugging.
|
|
2559
|
-
*/
|
|
2560
|
-
const tap: <E, A>(f: (a: A) => void) => (data: TaskResult<E, A>) => TaskResult<E, A>;
|
|
2561
|
-
/**
|
|
2562
|
-
* Executes a side effect on the error value without changing the TaskResult.
|
|
2563
|
-
* Useful for logging or reporting async errors.
|
|
2564
|
-
*
|
|
2565
|
-
* @example
|
|
2566
|
-
* ```ts
|
|
2567
|
-
* pipe(
|
|
2568
|
-
* fetchUser(id),
|
|
2569
|
-
* TaskResult.tapError(e => console.error("fetch failed:", e)),
|
|
2570
|
-
* TaskResult.chain(saveToCache),
|
|
2571
|
-
* )
|
|
2572
|
-
* ```
|
|
2573
|
-
*/
|
|
2574
|
-
const tapError: <E, A>(f: (e: E) => void) => (data: TaskResult<E, A>) => TaskResult<E, A>;
|
|
2575
|
-
/**
|
|
2576
|
-
* Applies a function wrapped in a TaskResult to a value wrapped in a TaskResult.
|
|
2577
|
-
* Both Tasks run in parallel.
|
|
2578
|
-
*/
|
|
2579
|
-
const ap: <E, A>(arg: TaskResult<E, A>) => <B>(data: TaskResult<E, (a: A) => B>) => TaskResult<E, B>;
|
|
2580
|
-
/**
|
|
2581
|
-
* Executes a `TaskResult` with an optional signal, returning `Promise<Result<E, A>>`.
|
|
2582
|
-
* Use as a terminal step in a `pipe` chain.
|
|
2583
|
-
*
|
|
2584
|
-
* @example
|
|
2585
|
-
* ```ts
|
|
2586
|
-
* const controller = new AbortController();
|
|
2587
|
-
* const result = await pipe(
|
|
2588
|
-
* fetchUser("42"),
|
|
2589
|
-
* TaskResult.chain(user => fetchPosts(user.id)),
|
|
2590
|
-
* TaskResult.run(controller.signal),
|
|
2591
|
-
* );
|
|
2592
|
-
* if (Result.isOk(result)) render(result.value);
|
|
2593
|
-
* ```
|
|
2594
|
-
*/
|
|
2595
|
-
const run: (signal?: AbortSignal) => <E, A>(task: TaskResult<E, A>) => Deferred<Result<E, A>>;
|
|
2596
|
-
/**
|
|
2597
|
-
* Converts a TaskResult value into an object containing a single property.
|
|
2598
|
-
* Initiates the pipeline accumulator record.
|
|
2599
|
-
*
|
|
2600
|
-
* @example
|
|
2601
|
-
* ```ts
|
|
2602
|
-
* pipe(TaskResult.ok(42), TaskResult.bindTo("value")); // TaskResult({ value: 42 })
|
|
2603
|
-
* ```
|
|
2604
|
-
*/
|
|
2605
|
-
const bindTo: <K extends string>(key: K) => <E, A>(data: TaskResult<E, A>) => TaskResult<E, { [P in K]: A; }>;
|
|
2606
|
-
/**
|
|
2607
|
-
* Evaluates a new TaskResult using the current accumulator and attaches the output to a new key.
|
|
2608
|
-
*
|
|
2609
|
-
* @example
|
|
2610
|
-
* ```ts
|
|
2611
|
-
* pipe(
|
|
2612
|
-
* TaskResult.ok({ a: 1 }),
|
|
2613
|
-
* TaskResult.bind("b", ({ a }) => TaskResult.ok(a + 1))
|
|
2614
|
-
* ); // TaskResult({ a: 1, b: 2 })
|
|
2615
|
-
* ```
|
|
2616
|
-
*/
|
|
2617
|
-
const bind: <K extends string, E, A, B>(key: K, f: (a: A) => TaskResult<E, B>) => (data: TaskResult<E, A>) => TaskResult<E, A & { [P in K]: B; }>;
|
|
2618
|
-
/**
|
|
2619
|
-
* Combines a record of TaskResults into a single TaskResult of a record.
|
|
2620
|
-
* Evaluates all tasks in parallel, forwarding the AbortSignal down to each sub-task.
|
|
2621
|
-
* Returns the first Err encountered in key order.
|
|
2622
|
-
*
|
|
2623
|
-
* @example
|
|
2624
|
-
* ```ts
|
|
2625
|
-
* TaskResult.struct({
|
|
2626
|
-
* name: TaskResult.ok("Alice"),
|
|
2627
|
-
* age: TaskResult.ok(30)
|
|
2628
|
-
* }); // TaskResult({ name: "Alice", age: 30 })
|
|
2629
|
-
* ```
|
|
2630
|
-
*/
|
|
2631
|
-
const struct: <E, R extends Record<string, any>>(fields: { [K in keyof R]: TaskResult<E, R[K]>; }) => TaskResult<E, R>;
|
|
2632
|
-
}
|
|
2633
|
-
|
|
2634
|
-
/**
|
|
2635
|
-
* A Task that resolves to a Validation — combining async operations with
|
|
2636
|
-
* error accumulation. Unlike TaskResult, multiple failures are collected
|
|
2637
|
-
* rather than short-circuiting on the first error.
|
|
2638
|
-
*
|
|
2639
|
-
* @example
|
|
2640
|
-
* ```ts
|
|
2641
|
-
* const validateName = (name: string): TaskValidation<string, string> =>
|
|
2642
|
-
* name.length > 0
|
|
2643
|
-
* ? TaskValidation.passed(name)
|
|
2644
|
-
* : TaskValidation.failed("Name is required");
|
|
2645
|
-
*
|
|
2646
|
-
* // Accumulate errors from multiple async validations using ap
|
|
2647
|
-
* pipe(
|
|
2648
|
-
* TaskValidation.passed((name: string) => (age: number) => ({ name, age })),
|
|
2649
|
-
* TaskValidation.ap(validateName("")),
|
|
2650
|
-
* TaskValidation.ap(validateAge(-1))
|
|
2651
|
-
* )();
|
|
2652
|
-
* // Failed(["Name is required", "Age must be positive"])
|
|
2653
|
-
* ```
|
|
2654
|
-
*/
|
|
2655
|
-
type TaskValidation<E, A> = Task<Validation<E, A>>;
|
|
2656
|
-
declare namespace TaskValidation {
|
|
2657
|
-
/**
|
|
2658
|
-
* Wraps a value in a passed TaskValidation.
|
|
2659
|
-
*/
|
|
2660
|
-
const passed: <E, A>(value: A) => TaskValidation<E, A>;
|
|
2661
|
-
/**
|
|
2662
|
-
* Creates a failed TaskValidation with a single error.
|
|
2663
|
-
*/
|
|
2664
|
-
const failed: <E, A>(error: E) => TaskValidation<E, A>;
|
|
2665
|
-
/**
|
|
2666
|
-
* Creates a failed TaskValidation from multiple errors.
|
|
2667
|
-
*/
|
|
2668
|
-
const failedAll: <E, A>(errors: NonEmptyList<E>) => TaskValidation<E, A>;
|
|
2669
|
-
/**
|
|
2670
|
-
* Lifts a Validation into a TaskValidation.
|
|
2671
|
-
*/
|
|
2672
|
-
const fromValidation: <E, A>(validation: Validation<E, A>) => TaskValidation<E, A>;
|
|
2673
|
-
/**
|
|
2674
|
-
* Creates a TaskValidation from a nullable value.
|
|
2675
|
-
* If the value is null or undefined, returns Failed with the error from onNull.
|
|
2676
|
-
* Otherwise, returns Passed.
|
|
2677
|
-
*/
|
|
2678
|
-
const fromNullable: <E>(onNull: () => E) => <A>(value: A | null | undefined) => TaskValidation<E, A>;
|
|
2679
|
-
/**
|
|
2680
|
-
* Creates a TaskValidation from a Maybe.
|
|
2681
|
-
* Some becomes Passed, None becomes Failed with the error from onNone.
|
|
2682
|
-
*/
|
|
2683
|
-
const fromMaybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => TaskValidation<E, A>;
|
|
2684
|
-
/**
|
|
2685
|
-
* Creates a TaskValidation from a Result.
|
|
2686
|
-
* Ok becomes Passed, Err(e) becomes Failed([e]).
|
|
2687
|
-
*/
|
|
2688
|
-
const fromResult: <E, A>(result: Result<E, A>) => TaskValidation<E, A>;
|
|
2689
|
-
/**
|
|
2690
|
-
* Creates a TaskValidation from a Promise-returning function.
|
|
2691
|
-
* Catches any errors and transforms them using the onError function.
|
|
2692
|
-
* The factory optionally receives an `AbortSignal` forwarded from the call site.
|
|
2693
|
-
*
|
|
2694
|
-
* @example
|
|
2695
|
-
* ```ts
|
|
2696
|
-
* const fetchUser = (id: string): TaskValidation<string, User> =>
|
|
2697
|
-
* TaskValidation.tryCatch(
|
|
2698
|
-
* (signal) => fetch(`/users/${id}`, { signal }).then(r => r.json()),
|
|
2699
|
-
* e => `Failed to fetch user: ${e}`
|
|
2700
|
-
* );
|
|
2701
|
-
* ```
|
|
2702
|
-
*/
|
|
2703
|
-
const tryCatch: <E, A>(f: (signal?: AbortSignal) => Promise<A>, onError: (e: unknown) => E) => TaskValidation<E, A>;
|
|
2704
|
-
/**
|
|
2705
|
-
* Transforms the success value inside a TaskValidation.
|
|
2706
|
-
*/
|
|
2707
|
-
const map: <E, A, B>(f: (a: A) => B) => (data: TaskValidation<E, A>) => TaskValidation<E, B>;
|
|
2708
|
-
/**
|
|
2709
|
-
* Applies a function wrapped in a TaskValidation to a value wrapped in a
|
|
2710
|
-
* TaskValidation. Both Tasks run in parallel and errors from both sides
|
|
2711
|
-
* are accumulated.
|
|
2712
|
-
*
|
|
2713
|
-
* @example
|
|
2714
|
-
* ```ts
|
|
2715
|
-
* pipe(
|
|
2716
|
-
* TaskValidation.passed((name: string) => (age: number) => ({ name, age })),
|
|
2717
|
-
* TaskValidation.ap(validateName(name)),
|
|
2718
|
-
* TaskValidation.ap(validateAge(age))
|
|
2719
|
-
* )();
|
|
2720
|
-
* ```
|
|
2721
|
-
*/
|
|
2722
|
-
const ap: <E, A>(arg: TaskValidation<E, A>) => <B>(data: TaskValidation<E, (a: A) => B>) => TaskValidation<E, B>;
|
|
2723
|
-
/**
|
|
2724
|
-
* Extracts a value from a TaskValidation by providing handlers for both cases.
|
|
2725
|
-
*/
|
|
2726
|
-
const fold: <E, A, B>(onFailed: (errors: NonEmptyList<E>) => B, onPassed: (a: A) => B) => (data: TaskValidation<E, A>) => Task<B>;
|
|
2727
|
-
/**
|
|
2728
|
-
* Pattern matches on a TaskValidation, returning a Task of the result.
|
|
2729
|
-
*
|
|
2730
|
-
* @example
|
|
2731
|
-
* ```ts
|
|
2732
|
-
* pipe(
|
|
2733
|
-
* validateForm(input),
|
|
2734
|
-
* TaskValidation.match({
|
|
2735
|
-
* passed: data => save(data),
|
|
2736
|
-
* failed: errors => showErrors(errors)
|
|
2737
|
-
* })
|
|
2738
|
-
* )();
|
|
2739
|
-
* ```
|
|
2740
|
-
*/
|
|
2741
|
-
const match: <E, A, B>(cases: {
|
|
2742
|
-
passed: (a: A) => B;
|
|
2743
|
-
failed: (errors: NonEmptyList<E>) => B;
|
|
2744
|
-
}) => (data: TaskValidation<E, A>) => Task<B>;
|
|
2745
|
-
/**
|
|
2746
|
-
* Returns the success value or a default value if the TaskValidation is failed.
|
|
2747
|
-
* The default can be a different type, widening the result to `Task<A | B>`.
|
|
2748
|
-
*/
|
|
2749
|
-
const getOrElse: <E, A, B>(defaultValue: () => B) => (data: TaskValidation<E, A>) => Task<A | B>;
|
|
2750
|
-
/**
|
|
2751
|
-
* Executes a side effect on the success value without changing the TaskValidation.
|
|
2752
|
-
* Useful for logging or debugging.
|
|
2753
|
-
*/
|
|
2754
|
-
const tap: <E, A>(f: (a: A) => void) => (data: TaskValidation<E, A>) => TaskValidation<E, A>;
|
|
2755
|
-
/**
|
|
2756
|
-
* Recovers from a Failed state by providing a fallback TaskValidation.
|
|
2757
|
-
* The fallback receives the accumulated error list so callers can inspect which errors occurred.
|
|
2758
|
-
* The fallback can produce a different success type, widening the result to `TaskValidation<E, A | B>`.
|
|
2759
|
-
*/
|
|
2760
|
-
const recover: <E, A, B>(fallback: (errors: NonEmptyList<E>) => TaskValidation<E, B>) => (data: TaskValidation<E, A>) => TaskValidation<E, A | B>;
|
|
2761
|
-
/**
|
|
2762
|
-
* Runs two TaskValidations concurrently and combines their results into a tuple.
|
|
2763
|
-
* If both are Passed, returns Passed with both values. If either fails, accumulates
|
|
2764
|
-
* errors from both sides.
|
|
2765
|
-
*
|
|
2766
|
-
* @example
|
|
2767
|
-
* ```ts
|
|
2768
|
-
* await TaskValidation.product(
|
|
2769
|
-
* validateName(form.name),
|
|
2770
|
-
* validateAge(form.age),
|
|
2771
|
-
* )(); // Passed(["Alice", 30]) or Failed([...errors])
|
|
2772
|
-
* ```
|
|
2773
|
-
*/
|
|
2774
|
-
const product: <E, A, B>(first: TaskValidation<E, A>, second: TaskValidation<E, B>) => TaskValidation<E, readonly [A, B]>;
|
|
2775
|
-
/**
|
|
2776
|
-
* Runs all TaskValidations concurrently and collects results.
|
|
2777
|
-
* If all are Passed, returns Passed with all values as an array.
|
|
2778
|
-
* If any fail, returns Failed with all accumulated errors.
|
|
2779
|
-
*
|
|
2780
|
-
* @example
|
|
2781
|
-
* ```ts
|
|
2782
|
-
* await TaskValidation.productAll([
|
|
2783
|
-
* validateName(form.name),
|
|
2784
|
-
* validateEmail(form.email),
|
|
2785
|
-
* validateAge(form.age),
|
|
2786
|
-
* ])(); // Passed([name, email, age]) or Failed([...all errors])
|
|
2787
|
-
* ```
|
|
2788
|
-
*/
|
|
2789
|
-
const productAll: <E, A>(data: NonEmptyList<TaskValidation<E, A>>) => TaskValidation<E, readonly A[]>;
|
|
2790
|
-
}
|
|
2791
|
-
|
|
2792
2315
|
type TheseFirst<T> = WithKind<"First"> & WithFirst<T>;
|
|
2793
2316
|
type TheseSecond<T> = WithKind<"Second"> & WithSecond<T>;
|
|
2794
2317
|
type TheseBoth<First, Second> = WithKind<"Both"> & WithFirst<First> & WithSecond<Second>;
|
|
@@ -3142,329 +2665,4 @@ declare namespace Tuple {
|
|
|
3142
2665
|
const tap: <A, B>(f: (a: A, b: B) => void) => (tuple: Tuple<A, B>) => Tuple<A, B>;
|
|
3143
2666
|
}
|
|
3144
2667
|
|
|
3145
|
-
type
|
|
3146
|
-
type Failed<E> = WithKind<"Failed"> & WithErrors<E>;
|
|
3147
|
-
/**
|
|
3148
|
-
* Validation represents a value that is either passed with a success value,
|
|
3149
|
-
* or failed with accumulated errors.
|
|
3150
|
-
* Unlike Result, Validation can accumulate multiple errors instead of short-circuiting.
|
|
3151
|
-
*
|
|
3152
|
-
* Use Validation when you need to collect all errors (e.g., form validation).
|
|
3153
|
-
* Use Result when you want to fail fast on the first error.
|
|
3154
|
-
*
|
|
3155
|
-
* @example
|
|
3156
|
-
* ```ts
|
|
3157
|
-
* const validateName = (name: string): Validation<string, string> =>
|
|
3158
|
-
* name.length > 0 ? Validation.passed(name) : Validation.failed("Name is required");
|
|
3159
|
-
*
|
|
3160
|
-
* const validateAge = (age: number): Validation<string, number> =>
|
|
3161
|
-
* age >= 0 ? Validation.passed(age) : Validation.failed("Age must be positive");
|
|
3162
|
-
*
|
|
3163
|
-
* // Accumulates all errors using ap
|
|
3164
|
-
* pipe(
|
|
3165
|
-
* Validation.passed((name: string) => (age: number) => ({ name, age })),
|
|
3166
|
-
* Validation.ap(validateName("")),
|
|
3167
|
-
* Validation.ap(validateAge(-1))
|
|
3168
|
-
* );
|
|
3169
|
-
* // Failed(["Name is required", "Age must be positive"])
|
|
3170
|
-
* ```
|
|
3171
|
-
*/
|
|
3172
|
-
type Validation<E, A> = Passed<A> | Failed<E>;
|
|
3173
|
-
declare namespace Validation {
|
|
3174
|
-
/**
|
|
3175
|
-
* Wraps a value in a passed Validation.
|
|
3176
|
-
*
|
|
3177
|
-
* @example
|
|
3178
|
-
* ```ts
|
|
3179
|
-
* Validation.passed(42); // Passed(42)
|
|
3180
|
-
* ```
|
|
3181
|
-
*/
|
|
3182
|
-
const passed: <E, A>(value: A) => Validation<E, A>;
|
|
3183
|
-
/**
|
|
3184
|
-
* Creates a failed Validation from a single error.
|
|
3185
|
-
*
|
|
3186
|
-
* @example
|
|
3187
|
-
* ```ts
|
|
3188
|
-
* Validation.failed("Invalid input");
|
|
3189
|
-
* ```
|
|
3190
|
-
*/
|
|
3191
|
-
const failed: <E>(error: E) => Failed<E>;
|
|
3192
|
-
/**
|
|
3193
|
-
* Creates a failed Validation from multiple errors.
|
|
3194
|
-
*
|
|
3195
|
-
* @example
|
|
3196
|
-
* ```ts
|
|
3197
|
-
* Validation.failedAll(["Invalid input"]);
|
|
3198
|
-
* ```
|
|
3199
|
-
*/
|
|
3200
|
-
const failedAll: <E>(errors: NonEmptyList<E>) => Failed<E>;
|
|
3201
|
-
/**
|
|
3202
|
-
* Type guard that checks if a Validation is passed.
|
|
3203
|
-
*/
|
|
3204
|
-
const isPassed: <E, A>(data: Validation<E, A>) => data is Passed<A>;
|
|
3205
|
-
/**
|
|
3206
|
-
* Type guard that checks if a Validation is failed.
|
|
3207
|
-
*/
|
|
3208
|
-
const isFailed: <E, A>(data: Validation<E, A>) => data is Failed<E>;
|
|
3209
|
-
/**
|
|
3210
|
-
* Creates a Validation from a predicate applied to a value.
|
|
3211
|
-
* Returns Passed if the predicate passes, Failed from `onFalse` otherwise.
|
|
3212
|
-
*
|
|
3213
|
-
* @example
|
|
3214
|
-
* ```ts
|
|
3215
|
-
* const validateName = Validation.fromPredicate(
|
|
3216
|
-
* (s: string) => s.length > 0,
|
|
3217
|
-
* () => "Name is required"
|
|
3218
|
-
* );
|
|
3219
|
-
*
|
|
3220
|
-
* validateName("Alice"); // Passed("Alice")
|
|
3221
|
-
* validateName(""); // Failed(["Name is required"])
|
|
3222
|
-
* ```
|
|
3223
|
-
*/
|
|
3224
|
-
const fromPredicate: <E, A>(pred: (a: A) => boolean, onFalse: (a: A) => E) => (a: A) => Validation<E, A>;
|
|
3225
|
-
/**
|
|
3226
|
-
* Creates a Validation from a nullable value.
|
|
3227
|
-
* If the value is null or undefined, returns Failed with the error from onNull.
|
|
3228
|
-
* Otherwise, returns Passed.
|
|
3229
|
-
*
|
|
3230
|
-
* @example
|
|
3231
|
-
* ```ts
|
|
3232
|
-
* pipe(null, Validation.fromNullable(() => "is null")); // Failed(["is null"])
|
|
3233
|
-
* pipe(42, Validation.fromNullable(() => "is null")); // Passed(42)
|
|
3234
|
-
* ```
|
|
3235
|
-
*/
|
|
3236
|
-
const fromNullable: <E>(onNull: () => E) => <A>(value: A | null | undefined) => Validation<E, A>;
|
|
3237
|
-
/**
|
|
3238
|
-
* Creates a Validation from a Maybe.
|
|
3239
|
-
* If the Maybe is None, returns Failed with the error from onNone.
|
|
3240
|
-
* Otherwise, returns Passed.
|
|
3241
|
-
*
|
|
3242
|
-
* @example
|
|
3243
|
-
* ```ts
|
|
3244
|
-
* pipe(Maybe.none(), Validation.fromMaybe(() => "is none")); // Failed(["is none"])
|
|
3245
|
-
* pipe(Maybe.some(42), Validation.fromMaybe(() => "is none")); // Passed(42)
|
|
3246
|
-
* ```
|
|
3247
|
-
*/
|
|
3248
|
-
const fromMaybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => Validation<E, A>;
|
|
3249
|
-
/**
|
|
3250
|
-
* Transforms the success value inside a Validation.
|
|
3251
|
-
*
|
|
3252
|
-
* @example
|
|
3253
|
-
* ```ts
|
|
3254
|
-
* pipe(Validation.passed(5), Validation.map(n => n * 2)); // Passed(10)
|
|
3255
|
-
* pipe(Validation.failed("oops"), Validation.map(n => n * 2)); // Failed(["oops"])
|
|
3256
|
-
* ```
|
|
3257
|
-
*/
|
|
3258
|
-
const map: <A, B>(f: (a: A) => B) => <E>(data: Validation<E, A>) => Validation<E, B>;
|
|
3259
|
-
/**
|
|
3260
|
-
* Transforms the error list inside a Validation.
|
|
3261
|
-
*
|
|
3262
|
-
* @example
|
|
3263
|
-
* ```ts
|
|
3264
|
-
* pipe(Validation.failed("oops"), Validation.mapError(e => e.toUpperCase())); // Failed(["OOPS"])
|
|
3265
|
-
* ```
|
|
3266
|
-
*/
|
|
3267
|
-
const mapError: <E, F, A>(f: (e: E) => F) => (data: Validation<E, A>) => Validation<F, A>;
|
|
3268
|
-
/**
|
|
3269
|
-
* Applies a function wrapped in a Validation to a value wrapped in a Validation.
|
|
3270
|
-
* Accumulates errors from both sides.
|
|
3271
|
-
*
|
|
3272
|
-
* @example
|
|
3273
|
-
* ```ts
|
|
3274
|
-
* const add = (a: number) => (b: number) => a + b;
|
|
3275
|
-
* pipe(
|
|
3276
|
-
* Validation.passed(add),
|
|
3277
|
-
* Validation.ap(Validation.passed(5)),
|
|
3278
|
-
* Validation.ap(Validation.passed(3))
|
|
3279
|
-
* ); // Passed(8)
|
|
3280
|
-
*
|
|
3281
|
-
* pipe(
|
|
3282
|
-
* Validation.passed(add),
|
|
3283
|
-
* Validation.ap(Validation.failed<string, number>("bad a")),
|
|
3284
|
-
* Validation.ap(Validation.failed<string, number>("bad b"))
|
|
3285
|
-
* ); // Failed(["bad a", "bad b"])
|
|
3286
|
-
* ```
|
|
3287
|
-
*/
|
|
3288
|
-
const ap: <E, A>(arg: Validation<E, A>) => <B>(data: Validation<E, (a: A) => B>) => Validation<E, B>;
|
|
3289
|
-
/**
|
|
3290
|
-
* Extracts the value from a Validation by providing handlers for both cases.
|
|
3291
|
-
*
|
|
3292
|
-
* @example
|
|
3293
|
-
* ```ts
|
|
3294
|
-
* pipe(
|
|
3295
|
-
* Validation.passed(42),
|
|
3296
|
-
* Validation.fold(
|
|
3297
|
-
* errors => `Errors: ${errors.join(", ")}`,
|
|
3298
|
-
* value => `Value: ${value}`
|
|
3299
|
-
* )
|
|
3300
|
-
* );
|
|
3301
|
-
* ```
|
|
3302
|
-
*/
|
|
3303
|
-
const fold: <E, A, B>(onFailed: (errors: NonEmptyList<E>) => B, onPassed: (a: A) => B) => (data: Validation<E, A>) => B;
|
|
3304
|
-
/**
|
|
3305
|
-
* Pattern matches on a Validation, returning the result of the matching case.
|
|
3306
|
-
*
|
|
3307
|
-
* @example
|
|
3308
|
-
* ```ts
|
|
3309
|
-
* pipe(
|
|
3310
|
-
* validation,
|
|
3311
|
-
* Validation.match({
|
|
3312
|
-
* passed: value => `Got ${value}`,
|
|
3313
|
-
* failed: errors => `Failed: ${errors.join(", ")}`
|
|
3314
|
-
* })
|
|
3315
|
-
* );
|
|
3316
|
-
* ```
|
|
3317
|
-
*/
|
|
3318
|
-
const match: <E, A, B>(cases: {
|
|
3319
|
-
passed: (a: A) => B;
|
|
3320
|
-
failed: (errors: NonEmptyList<E>) => B;
|
|
3321
|
-
}) => (data: Validation<E, A>) => B;
|
|
3322
|
-
/**
|
|
3323
|
-
* Returns the success value or a default value if the Validation is failed.
|
|
3324
|
-
* The default can be a different type, widening the result to `A | B`.
|
|
3325
|
-
*
|
|
3326
|
-
* @example
|
|
3327
|
-
* ```ts
|
|
3328
|
-
* pipe(Validation.passed(5), Validation.getOrElse(() => 0)); // 5
|
|
3329
|
-
* pipe(Validation.failed("oops"), Validation.getOrElse(() => 0)); // 0
|
|
3330
|
-
* pipe(Validation.failed("oops"), Validation.getOrElse(() => null)); // null — typed as number | null
|
|
3331
|
-
* ```
|
|
3332
|
-
*/
|
|
3333
|
-
const getOrElse: <E, A, B>(defaultValue: () => B) => (data: Validation<E, A>) => A | B;
|
|
3334
|
-
/**
|
|
3335
|
-
* Executes a side effect on the success value without changing the Validation.
|
|
3336
|
-
*
|
|
3337
|
-
* @example
|
|
3338
|
-
* ```ts
|
|
3339
|
-
* pipe(
|
|
3340
|
-
* Validation.passed(5),
|
|
3341
|
-
* Validation.tap(n => console.log("Value:", n)),
|
|
3342
|
-
* Validation.map(n => n * 2)
|
|
3343
|
-
* );
|
|
3344
|
-
* ```
|
|
3345
|
-
*/
|
|
3346
|
-
const tap: <E, A>(f: (a: A) => void) => (data: Validation<E, A>) => Validation<E, A>;
|
|
3347
|
-
/**
|
|
3348
|
-
* Executes a side effect on the accumulated errors without changing the Validation.
|
|
3349
|
-
* Useful for logging or reporting validation failures.
|
|
3350
|
-
*
|
|
3351
|
-
* @example
|
|
3352
|
-
* ```ts
|
|
3353
|
-
* pipe(
|
|
3354
|
-
* Validation.failed("Name required"),
|
|
3355
|
-
* Validation.tapError(errors => console.error("validation failed:", errors)),
|
|
3356
|
-
* Validation.map(toUser)
|
|
3357
|
-
* );
|
|
3358
|
-
* ```
|
|
3359
|
-
*/
|
|
3360
|
-
const tapError: <E, A>(f: (errors: NonEmptyList<E>) => void) => (data: Validation<E, A>) => Validation<E, A>;
|
|
3361
|
-
/**
|
|
3362
|
-
* Recovers from a Failed state by providing a fallback Validation.
|
|
3363
|
-
* The fallback receives the accumulated error list so callers can inspect which errors occurred.
|
|
3364
|
-
* The fallback can produce a different success type, widening the result to `Validation<E, A | B>`.
|
|
3365
|
-
*/
|
|
3366
|
-
const recover: <E, A, B>(fallback: (errors: NonEmptyList<E>) => Validation<E, B>) => (data: Validation<E, A>) => Validation<E, A | B>;
|
|
3367
|
-
/**
|
|
3368
|
-
* Recovers from a Failed state unless `isBlocked` returns true for any of the accumulated errors.
|
|
3369
|
-
* The fallback can produce a different success type, widening the result to `Validation<E, A | B>`.
|
|
3370
|
-
*
|
|
3371
|
-
* @example
|
|
3372
|
-
* ```ts
|
|
3373
|
-
* pipe(
|
|
3374
|
-
* Validation.failed("field-error"),
|
|
3375
|
-
* Validation.recoverUnless(e => e === "fatal", () => Validation.passed(0))
|
|
3376
|
-
* ); // Passed(0)
|
|
3377
|
-
* ```
|
|
3378
|
-
*/
|
|
3379
|
-
const recoverUnless: <E, A, B>(isBlocked: (e: E) => boolean, fallback: () => Validation<E, B>) => (data: Validation<E, A>) => Validation<E, A | B>;
|
|
3380
|
-
/**
|
|
3381
|
-
* Converts a Validation to a Result.
|
|
3382
|
-
* Passed becomes Ok, Failed becomes Err with the accumulated error list.
|
|
3383
|
-
*
|
|
3384
|
-
* @example
|
|
3385
|
-
* ```ts
|
|
3386
|
-
* Validation.toResult(Validation.passed(42)); // Ok(42)
|
|
3387
|
-
* Validation.toResult(Validation.failed("oops")); // Err(["oops"])
|
|
3388
|
-
* ```
|
|
3389
|
-
*/
|
|
3390
|
-
const toResult: <E, A>(data: Validation<E, A>) => Result<NonEmptyList<E>, A>;
|
|
3391
|
-
/**
|
|
3392
|
-
* Converts a Validation to a Maybe. `Passed` becomes `Some`; `Failed` becomes `None`
|
|
3393
|
-
* (errors are discarded).
|
|
3394
|
-
*
|
|
3395
|
-
* @example
|
|
3396
|
-
* ```ts
|
|
3397
|
-
* Validation.toMaybe(Validation.passed(42)); // Some(42)
|
|
3398
|
-
* Validation.toMaybe(Validation.failed("bad")); // None
|
|
3399
|
-
* ```
|
|
3400
|
-
*/
|
|
3401
|
-
const toMaybe: <E, A>(data: Validation<E, A>) => Maybe<A>;
|
|
3402
|
-
/**
|
|
3403
|
-
* Converts a `Result` to a `Validation`. `Ok` becomes `Passed`; `Err(e)` becomes `Failed([e])`.
|
|
3404
|
-
*
|
|
3405
|
-
* Useful when bridging from error-short-circuiting `Result` pipelines into
|
|
3406
|
-
* error-accumulating `Validation` pipelines.
|
|
3407
|
-
*
|
|
3408
|
-
* @example
|
|
3409
|
-
* ```ts
|
|
3410
|
-
* Validation.fromResult(Result.ok(42)); // Passed(42)
|
|
3411
|
-
* Validation.fromResult(Result.err("bad")); // Failed(["bad"])
|
|
3412
|
-
* ```
|
|
3413
|
-
*/
|
|
3414
|
-
const fromResult: <E, A>(data: Result<E, A>) => Validation<E, A>;
|
|
3415
|
-
/**
|
|
3416
|
-
* Combines two independent Validation instances into a tuple.
|
|
3417
|
-
* If both are Passed, returns Passed with both values as a tuple.
|
|
3418
|
-
* If either is Failed, accumulates errors from both sides.
|
|
3419
|
-
*
|
|
3420
|
-
* @example
|
|
3421
|
-
* ```ts
|
|
3422
|
-
* Validation.product(
|
|
3423
|
-
* Validation.passed("alice"),
|
|
3424
|
-
* Validation.passed(30)
|
|
3425
|
-
* ); // Passed(["alice", 30])
|
|
3426
|
-
*
|
|
3427
|
-
* Validation.product(
|
|
3428
|
-
* Validation.failed("Name required"),
|
|
3429
|
-
* Validation.failed("Age must be >= 0")
|
|
3430
|
-
* ); // Failed(["Name required", "Age must be >= 0"])
|
|
3431
|
-
* ```
|
|
3432
|
-
*/
|
|
3433
|
-
const product: <E, A, B>(first: Validation<E, A>, second: Validation<E, B>) => Validation<E, readonly [A, B]>;
|
|
3434
|
-
/**
|
|
3435
|
-
* Combines a non-empty list of Validation instances, accumulating all errors.
|
|
3436
|
-
* If all are Passed, returns Passed with all values collected into an array.
|
|
3437
|
-
* If any are Failed, returns Failed with all accumulated errors.
|
|
3438
|
-
*
|
|
3439
|
-
* @example
|
|
3440
|
-
* ```ts
|
|
3441
|
-
* Validation.productAll([
|
|
3442
|
-
* validateName(name),
|
|
3443
|
-
* validateEmail(email),
|
|
3444
|
-
* validateAge(age)
|
|
3445
|
-
* ]);
|
|
3446
|
-
* // Passed([name, email, age]) or Failed([...all errors])
|
|
3447
|
-
* ```
|
|
3448
|
-
*/
|
|
3449
|
-
const productAll: <E, A>(data: NonEmptyList<Validation<E, A>>) => Validation<E, readonly A[]>;
|
|
3450
|
-
/**
|
|
3451
|
-
* Combines a record of Validations into a single Validation of a record.
|
|
3452
|
-
* Accumulates all failed branches' errors.
|
|
3453
|
-
*
|
|
3454
|
-
* @example
|
|
3455
|
-
* ```ts
|
|
3456
|
-
* Validation.struct({
|
|
3457
|
-
* name: Validation.passed("Alice"),
|
|
3458
|
-
* age: Validation.passed(30)
|
|
3459
|
-
* }); // Passed({ name: "Alice", age: 30 })
|
|
3460
|
-
*
|
|
3461
|
-
* Validation.struct({
|
|
3462
|
-
* name: Validation.failed("Name required"),
|
|
3463
|
-
* age: Validation.failed("Age must be >= 0")
|
|
3464
|
-
* }); // Failed(["Name required", "Age must be >= 0"])
|
|
3465
|
-
* ```
|
|
3466
|
-
*/
|
|
3467
|
-
const struct: <E, R extends Record<string, any>>(fields: { [K in keyof R]: Validation<E, R[K]>; }) => Validation<E, R>;
|
|
3468
|
-
}
|
|
3469
|
-
|
|
3470
|
-
export { Combinable, Deferred, type Failed, type Failure, Lazy, Lens, type Loading, Logged, Maybe, type NotAsked, Op, Optional, type Passed, Predicate, Reader, Refinement, RemoteData, Resource, Result, State, type Success, Task, TaskMaybe, TaskResult, TaskValidation, These, type TheseBoth, type TheseFirst, type TheseSecond, Tuple, Validation };
|
|
2668
|
+
export { Combinable, Deferred, type Failure, Lazy, Lens, type Loading, Logged, Maybe, type NotAsked, Op, Optional, Predicate, Reader, Refinement, RemoteData, Resource, Result, State, type Success, Task, These, type TheseBoth, type TheseFirst, type TheseSecond, Tuple };
|