@nlozgachev/pipekit 0.1.6
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 +182 -0
- package/esm/mod.js +3 -0
- package/esm/package.json +3 -0
- package/esm/src/Composition/compose.js +3 -0
- package/esm/src/Composition/curry.js +42 -0
- package/esm/src/Composition/flip.js +20 -0
- package/esm/src/Composition/flow.js +8 -0
- package/esm/src/Composition/fn.js +85 -0
- package/esm/src/Composition/index.js +10 -0
- package/esm/src/Composition/memoize.js +66 -0
- package/esm/src/Composition/not.js +25 -0
- package/esm/src/Composition/pipe.js +3 -0
- package/esm/src/Composition/tap.js +33 -0
- package/esm/src/Composition/uncurry.js +32 -0
- package/esm/src/Core/Arr.js +461 -0
- package/esm/src/Core/InternalTypes.js +1 -0
- package/esm/src/Core/Option.js +195 -0
- package/esm/src/Core/Rec.js +167 -0
- package/esm/src/Core/RemoteData.js +210 -0
- package/esm/src/Core/Result.js +173 -0
- package/esm/src/Core/Task.js +108 -0
- package/esm/src/Core/TaskResult.js +63 -0
- package/esm/src/Core/Validation.js +215 -0
- package/esm/src/Core/index.js +8 -0
- package/esm/src/Types/NonEmptyList.js +14 -0
- package/esm/src/Types/index.js +1 -0
- package/package.json +60 -0
- package/script/mod.js +19 -0
- package/script/package.json +3 -0
- package/script/src/Composition/compose.js +6 -0
- package/script/src/Composition/curry.js +48 -0
- package/script/src/Composition/flip.js +24 -0
- package/script/src/Composition/flow.js +11 -0
- package/script/src/Composition/fn.js +98 -0
- package/script/src/Composition/index.js +26 -0
- package/script/src/Composition/memoize.js +71 -0
- package/script/src/Composition/not.js +29 -0
- package/script/src/Composition/pipe.js +6 -0
- package/script/src/Composition/tap.js +37 -0
- package/script/src/Composition/uncurry.js +38 -0
- package/script/src/Core/Arr.js +464 -0
- package/script/src/Core/InternalTypes.js +2 -0
- package/script/src/Core/Option.js +198 -0
- package/script/src/Core/Rec.js +170 -0
- package/script/src/Core/RemoteData.js +213 -0
- package/script/src/Core/Result.js +176 -0
- package/script/src/Core/Task.js +111 -0
- package/script/src/Core/TaskResult.js +66 -0
- package/script/src/Core/Validation.js +218 -0
- package/script/src/Core/index.js +24 -0
- package/script/src/Types/NonEmptyList.js +18 -0
- package/script/src/Types/index.js +17 -0
- package/types/mod.d.ts +4 -0
- package/types/mod.d.ts.map +1 -0
- package/types/src/Composition/compose.d.ts +33 -0
- package/types/src/Composition/compose.d.ts.map +1 -0
- package/types/src/Composition/curry.d.ts +43 -0
- package/types/src/Composition/curry.d.ts.map +1 -0
- package/types/src/Composition/flip.d.ts +21 -0
- package/types/src/Composition/flip.d.ts.map +1 -0
- package/types/src/Composition/flow.d.ts +56 -0
- package/types/src/Composition/flow.d.ts.map +1 -0
- package/types/src/Composition/fn.d.ts +76 -0
- package/types/src/Composition/fn.d.ts.map +1 -0
- package/types/src/Composition/index.d.ts +11 -0
- package/types/src/Composition/index.d.ts.map +1 -0
- package/types/src/Composition/memoize.d.ts +46 -0
- package/types/src/Composition/memoize.d.ts.map +1 -0
- package/types/src/Composition/not.d.ts +26 -0
- package/types/src/Composition/not.d.ts.map +1 -0
- package/types/src/Composition/pipe.d.ts +56 -0
- package/types/src/Composition/pipe.d.ts.map +1 -0
- package/types/src/Composition/tap.d.ts +31 -0
- package/types/src/Composition/tap.d.ts.map +1 -0
- package/types/src/Composition/uncurry.d.ts +54 -0
- package/types/src/Composition/uncurry.d.ts.map +1 -0
- package/types/src/Core/Arr.d.ts +355 -0
- package/types/src/Core/Arr.d.ts.map +1 -0
- package/types/src/Core/InternalTypes.d.ts +14 -0
- package/types/src/Core/InternalTypes.d.ts.map +1 -0
- package/types/src/Core/Option.d.ts +214 -0
- package/types/src/Core/Option.d.ts.map +1 -0
- package/types/src/Core/Rec.d.ts +121 -0
- package/types/src/Core/Rec.d.ts.map +1 -0
- package/types/src/Core/RemoteData.d.ts +196 -0
- package/types/src/Core/RemoteData.d.ts.map +1 -0
- package/types/src/Core/Result.d.ts +185 -0
- package/types/src/Core/Result.d.ts.map +1 -0
- package/types/src/Core/Task.d.ts +125 -0
- package/types/src/Core/Task.d.ts.map +1 -0
- package/types/src/Core/TaskResult.d.ts +78 -0
- package/types/src/Core/TaskResult.d.ts.map +1 -0
- package/types/src/Core/Validation.d.ts +217 -0
- package/types/src/Core/Validation.d.ts.map +1 -0
- package/types/src/Core/index.d.ts +9 -0
- package/types/src/Core/index.d.ts.map +1 -0
- package/types/src/Types/NonEmptyList.d.ts +29 -0
- package/types/src/Types/NonEmptyList.d.ts.map +1 -0
- package/types/src/Types/index.d.ts +2 -0
- package/types/src/Types/index.d.ts.map +1 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Result } from "./Result.js";
|
|
2
|
+
import { Task } from "./Task.js";
|
|
3
|
+
/**
|
|
4
|
+
* A Task that can fail with an error of type E or succeed with a value of type A.
|
|
5
|
+
* Combines async operations with typed error handling.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const fetchUser = (id: string): TaskResult<Error, User> =>
|
|
10
|
+
* TaskResult.tryCatch(
|
|
11
|
+
* () => fetch(`/users/${id}`).then(r => r.json()),
|
|
12
|
+
* (e) => new Error(`Failed to fetch user: ${e}`)
|
|
13
|
+
* );
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export type TaskResult<E, A> = Task<Result<E, A>>;
|
|
17
|
+
export declare namespace TaskResult {
|
|
18
|
+
/**
|
|
19
|
+
* Wraps a value in a successful TaskResult.
|
|
20
|
+
*/
|
|
21
|
+
const of: <E, A>(value: A) => TaskResult<E, A>;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a failed TaskResult with the given error.
|
|
24
|
+
*/
|
|
25
|
+
const fail: <E, A>(error: E) => TaskResult<E, A>;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a TaskResult from a function that may throw.
|
|
28
|
+
* Catches any errors and transforms them using the onError function.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const parseJson = (s: string): TaskResult<string, unknown> =>
|
|
33
|
+
* TaskResult.tryCatch(
|
|
34
|
+
* async () => JSON.parse(s),
|
|
35
|
+
* (e) => `Parse error: ${e}`
|
|
36
|
+
* );
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
const tryCatch: <E, A>(f: () => Promise<A>, onError: (e: unknown) => E) => TaskResult<E, A>;
|
|
40
|
+
/**
|
|
41
|
+
* Transforms the success value inside a TaskResult.
|
|
42
|
+
*/
|
|
43
|
+
const map: <E, A, B>(f: (a: A) => B) => (data: TaskResult<E, A>) => TaskResult<E, B>;
|
|
44
|
+
/**
|
|
45
|
+
* Transforms the error value inside a TaskResult.
|
|
46
|
+
*/
|
|
47
|
+
const mapError: <E, F, A>(f: (e: E) => F) => (data: TaskResult<E, A>) => TaskResult<F, A>;
|
|
48
|
+
/**
|
|
49
|
+
* Chains TaskResult computations. If the first succeeds, passes the value to f.
|
|
50
|
+
* If the first fails, propagates the error.
|
|
51
|
+
*/
|
|
52
|
+
const chain: <E, A, B>(f: (a: A) => TaskResult<E, B>) => (data: TaskResult<E, A>) => TaskResult<E, B>;
|
|
53
|
+
/**
|
|
54
|
+
* Extracts the value from a TaskResult by providing handlers for both cases.
|
|
55
|
+
*/
|
|
56
|
+
const fold: <E, A, B>(onErr: (e: E) => B, onOk: (a: A) => B) => (data: TaskResult<E, A>) => Task<B>;
|
|
57
|
+
/**
|
|
58
|
+
* Pattern matches on a TaskResult, returning a Task of the result.
|
|
59
|
+
*/
|
|
60
|
+
const match: <E, A, B>(cases: {
|
|
61
|
+
err: (e: E) => B;
|
|
62
|
+
ok: (a: A) => B;
|
|
63
|
+
}) => (data: TaskResult<E, A>) => Task<B>;
|
|
64
|
+
/**
|
|
65
|
+
* Recovers from an error by providing a fallback TaskResult.
|
|
66
|
+
*/
|
|
67
|
+
const recover: <E, A>(fallback: (e: E) => TaskResult<E, A>) => (data: TaskResult<E, A>) => TaskResult<E, A>;
|
|
68
|
+
/**
|
|
69
|
+
* Returns the success value or a default value if the TaskResult is an error.
|
|
70
|
+
*/
|
|
71
|
+
const getOrElse: <E, A>(defaultValue: A) => (data: TaskResult<E, A>) => Task<A>;
|
|
72
|
+
/**
|
|
73
|
+
* Executes a side effect on the success value without changing the TaskResult.
|
|
74
|
+
* Useful for logging or debugging.
|
|
75
|
+
*/
|
|
76
|
+
const tap: <E, A>(f: (a: A) => void) => (data: TaskResult<E, A>) => TaskResult<E, A>;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=TaskResult.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TaskResult.d.ts","sourceRoot":"","sources":["../../../src/src/Core/TaskResult.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAElD,yBAAiB,UAAU,CAAC;IAC1B;;OAEG;IACI,MAAM,EAAE,GAAI,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,KAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CAAgC,CAAC;IAEpF;;OAEG;IACI,MAAM,IAAI,GAAI,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,KAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CAAiC,CAAC;IAEvF;;;;;;;;;;;;OAYG;IACI,MAAM,QAAQ,GAClB,CAAC,EAAE,CAAC,EAAE,GAAG,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,EAAE,OAAO,KAAK,CAAC,KAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CAG7B,CAAC;IAE9C;;OAEG;IACI,MAAM,GAAG,GA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,UAAU,CAAC,CAAC,EAAE,CAAC,KAAK,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CAGhF,CAAC;IAEZ;;OAEG;IACI,MAAM,SAAS,GAAI,CAAC,EAAE,CAAC,EAAE,cAAc,CAAC,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,IAAI,CAAC,CAAC,CAC9B,CAAC;IAEvD;;;OAGG;IACI,MAAM,GAAG,GAAI,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CACpD,CAAC;CACvC"}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { NonEmptyList } from "../Types/NonEmptyList.js";
|
|
2
|
+
import { WithErrors, WithKind, WithValue } from "./InternalTypes.js";
|
|
3
|
+
/**
|
|
4
|
+
* Validation represents a value that is either valid with a success value,
|
|
5
|
+
* or invalid with accumulated errors.
|
|
6
|
+
* Unlike Result, Validation can accumulate multiple errors instead of short-circuiting.
|
|
7
|
+
*
|
|
8
|
+
* Use Validation when you need to collect all errors (e.g., form validation).
|
|
9
|
+
* Use Result when you want to fail fast on the first error.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const validateName = (name: string): Validation<string, string> =>
|
|
14
|
+
* name.length > 0 ? Validation.of(name) : Validation.fail("Name is required");
|
|
15
|
+
*
|
|
16
|
+
* const validateAge = (age: number): Validation<string, number> =>
|
|
17
|
+
* age >= 0 ? Validation.of(age) : Validation.fail("Age must be positive");
|
|
18
|
+
*
|
|
19
|
+
* // Accumulates all errors using ap
|
|
20
|
+
* pipe(
|
|
21
|
+
* Validation.of((name: string) => (age: number) => ({ name, age })),
|
|
22
|
+
* Validation.ap(validateName("")),
|
|
23
|
+
* Validation.ap(validateAge(-1))
|
|
24
|
+
* );
|
|
25
|
+
* // Invalid(["Name is required", "Age must be positive"])
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export type Validation<E, A> = Valid<A> | Invalid<E>;
|
|
29
|
+
export type Valid<A> = WithKind<"Valid"> & WithValue<A>;
|
|
30
|
+
export type Invalid<E> = WithKind<"Invalid"> & WithErrors<E>;
|
|
31
|
+
export declare namespace Validation {
|
|
32
|
+
/**
|
|
33
|
+
* Wraps a value in a valid Validation.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* Validation.of(42); // Valid(42)
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
const of: <E, A>(value: A) => Validation<E, A>;
|
|
41
|
+
/**
|
|
42
|
+
* Creates a valid Validation with the given value.
|
|
43
|
+
*/
|
|
44
|
+
const toValid: <A>(value: A) => Valid<A>;
|
|
45
|
+
/**
|
|
46
|
+
* Type guard that checks if a Validation is valid.
|
|
47
|
+
*/
|
|
48
|
+
const isValid: <E, A>(data: Validation<E, A>) => data is Valid<A>;
|
|
49
|
+
/**
|
|
50
|
+
* Creates an invalid Validation with the given errors.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* Validation.toInvalid(["Email is invalid", "Password too short"]);
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
const toInvalid: <E>(errors: NonEmptyList<E>) => Invalid<E>;
|
|
58
|
+
/**
|
|
59
|
+
* Type guard that checks if a Validation is invalid.
|
|
60
|
+
*/
|
|
61
|
+
const isInvalid: <E, A>(data: Validation<E, A>) => data is Invalid<E>;
|
|
62
|
+
/**
|
|
63
|
+
* Creates an invalid Validation from a single error.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* Validation.fail("Invalid input");
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
const fail: <E, A>(error: E) => Validation<E, A>;
|
|
71
|
+
/**
|
|
72
|
+
* Transforms the success value inside a Validation.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* pipe(Validation.of(5), Validation.map(n => n * 2)); // Valid(10)
|
|
77
|
+
* pipe(Validation.fail("oops"), Validation.map(n => n * 2)); // Invalid(["oops"])
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
const map: <A, B>(f: (a: A) => B) => <E>(data: Validation<E, A>) => Validation<E, B>;
|
|
81
|
+
/**
|
|
82
|
+
* Chains Validation computations. If the first is Valid, passes the value to f.
|
|
83
|
+
* If the first is Invalid, propagates the errors.
|
|
84
|
+
*
|
|
85
|
+
* Note: chain short-circuits on first error. Use `ap` to accumulate errors.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* const validatePositive = (n: number): Validation<string, number> =>
|
|
90
|
+
* n > 0 ? Validation.of(n) : Validation.fail("Must be positive");
|
|
91
|
+
*
|
|
92
|
+
* pipe(Validation.of(5), Validation.chain(validatePositive)); // Valid(5)
|
|
93
|
+
* pipe(Validation.of(-1), Validation.chain(validatePositive)); // Invalid(["Must be positive"])
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
const chain: <E, A, B>(f: (a: A) => Validation<E, B>) => (data: Validation<E, A>) => Validation<E, B>;
|
|
97
|
+
/**
|
|
98
|
+
* Applies a function wrapped in a Validation to a value wrapped in a Validation.
|
|
99
|
+
* Accumulates errors from both sides.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* const add = (a: number) => (b: number) => a + b;
|
|
104
|
+
* pipe(
|
|
105
|
+
* Validation.of(add),
|
|
106
|
+
* Validation.ap(Validation.of(5)),
|
|
107
|
+
* Validation.ap(Validation.of(3))
|
|
108
|
+
* ); // Valid(8)
|
|
109
|
+
*
|
|
110
|
+
* pipe(
|
|
111
|
+
* Validation.of(add),
|
|
112
|
+
* Validation.ap(Validation.fail<string, number>("bad a")),
|
|
113
|
+
* Validation.ap(Validation.fail<string, number>("bad b"))
|
|
114
|
+
* ); // Invalid(["bad a", "bad b"])
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
const ap: <E, A>(arg: Validation<E, A>) => <B>(data: Validation<E, (a: A) => B>) => Validation<E, B>;
|
|
118
|
+
/**
|
|
119
|
+
* Extracts the value from a Validation by providing handlers for both cases.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* pipe(
|
|
124
|
+
* Validation.of(42),
|
|
125
|
+
* Validation.fold(
|
|
126
|
+
* errors => `Errors: ${errors.join(", ")}`,
|
|
127
|
+
* value => `Value: ${value}`
|
|
128
|
+
* )
|
|
129
|
+
* );
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
const fold: <E, A, B>(onInvalid: (errors: NonEmptyList<E>) => B, onValid: (a: A) => B) => (data: Validation<E, A>) => B;
|
|
133
|
+
/**
|
|
134
|
+
* Pattern matches on a Validation, returning the result of the matching case.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* pipe(
|
|
139
|
+
* validation,
|
|
140
|
+
* Validation.match({
|
|
141
|
+
* valid: value => `Got ${value}`,
|
|
142
|
+
* invalid: errors => `Failed: ${errors.join(", ")}`
|
|
143
|
+
* })
|
|
144
|
+
* );
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
const match: <E, A, B>(cases: {
|
|
148
|
+
valid: (a: A) => B;
|
|
149
|
+
invalid: (errors: NonEmptyList<E>) => B;
|
|
150
|
+
}) => (data: Validation<E, A>) => B;
|
|
151
|
+
/**
|
|
152
|
+
* Returns the success value or a default value if the Validation is invalid.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```ts
|
|
156
|
+
* pipe(Validation.of(5), Validation.getOrElse(0)); // 5
|
|
157
|
+
* pipe(Validation.fail("oops"), Validation.getOrElse(0)); // 0
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
const getOrElse: <E, A>(defaultValue: A) => (data: Validation<E, A>) => A;
|
|
161
|
+
/**
|
|
162
|
+
* Executes a side effect on the success value without changing the Validation.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* pipe(
|
|
167
|
+
* Validation.of(5),
|
|
168
|
+
* Validation.tap(n => console.log("Value:", n)),
|
|
169
|
+
* Validation.map(n => n * 2)
|
|
170
|
+
* );
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
const tap: <E, A>(f: (a: A) => void) => (data: Validation<E, A>) => Validation<E, A>;
|
|
174
|
+
/**
|
|
175
|
+
* Recovers from an Invalid state by providing a fallback Validation.
|
|
176
|
+
*/
|
|
177
|
+
const recover: <E, A>(fallback: () => Validation<E, A>) => (data: Validation<E, A>) => Validation<E, A>;
|
|
178
|
+
/**
|
|
179
|
+
* Recovers from an Invalid state unless the errors contain any of the blocked errors.
|
|
180
|
+
*/
|
|
181
|
+
const recoverUnless: <E, A>(blockedErrors: readonly E[], fallback: () => Validation<E, A>) => (data: Validation<E, A>) => Validation<E, A>;
|
|
182
|
+
/**
|
|
183
|
+
* Combines two Validation instances, accumulating errors from both.
|
|
184
|
+
* If both are Valid, returns the second valid value.
|
|
185
|
+
* If either is Invalid, combines their errors into a single Invalid.
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```ts
|
|
189
|
+
* Validation.combine(
|
|
190
|
+
* Validation.fail("Error 1"),
|
|
191
|
+
* Validation.fail("Error 2")
|
|
192
|
+
* ); // Invalid(["Error 1", "Error 2"])
|
|
193
|
+
*
|
|
194
|
+
* Validation.combine(
|
|
195
|
+
* Validation.of("a"),
|
|
196
|
+
* Validation.of("b")
|
|
197
|
+
* ); // Valid("b")
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
const combine: <E, A>(first: Validation<E, A>, second: Validation<E, A>) => Validation<E, A>;
|
|
201
|
+
/**
|
|
202
|
+
* Combines multiple Validation instances, accumulating all errors.
|
|
203
|
+
* If all are Valid, returns the last valid value.
|
|
204
|
+
* Returns undefined for an empty array.
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```ts
|
|
208
|
+
* Validation.combineAll([
|
|
209
|
+
* validateName(name),
|
|
210
|
+
* validateEmail(email),
|
|
211
|
+
* validateAge(age)
|
|
212
|
+
* ]);
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
const combineAll: <E, A>(data: Validation<E, A>[]) => Validation<E, A> | undefined;
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=Validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Validation.d.ts","sourceRoot":"","sources":["../../../src/src/Core/Validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAErD,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,QAAQ,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;AACxD,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,QAAQ,CAAC,SAAS,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;AAE7D,yBAAiB,UAAU,CAAC;IAC1B;;;;;;;OAOG;IACI,MAAM,EAAE,GAAI,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,KA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AAC,CAAC,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CAClD,CAAC;IAEtC;;OAEG;IACI,MAAM,aAAa,GACvB,CAAC,EAAE,CAAC,EAAE,eAAe,SAAS,CAAC,EAAE,EAAE,UAAU,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,MACnE,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CAI/B,CAAC;IAEb;;;;;;;;;;;;;;;;;OAiBG;IACI,MAAM,OAAO,GAAI,CAAC,EAAE,CAAC,EAC1B,OAAO,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,EACvB,QAAQ,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,KACvB,UAAU,CAAC,CAAC,EAAE,CAAC,CASjB,CAAC;IAEF;;;;;;;;;;;;;OAaG;IACI,MAAM,UAAU,GAAI,CAAC,EAAE,CAAC,EAC7B,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,KACvB,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SACoD,CAAC;CAC5E"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./Arr.js";
|
|
2
|
+
export * from "./Option.js";
|
|
3
|
+
export * from "./Rec.js";
|
|
4
|
+
export * from "./RemoteData.js";
|
|
5
|
+
export * from "./Result.js";
|
|
6
|
+
export * from "./Task.js";
|
|
7
|
+
export * from "./TaskResult.js";
|
|
8
|
+
export * from "./Validation.js";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/Core/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A list that is guaranteed to have at least one element.
|
|
3
|
+
* Useful for ensuring functions receive non-empty input and for
|
|
4
|
+
* accumulating errors in Validation.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* const errors: NonEmptyList<string> = ["First error", "Second error"];
|
|
9
|
+
*
|
|
10
|
+
* // TypeScript ensures at least one element:
|
|
11
|
+
* const invalid: NonEmptyList<string> = []; // Error!
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export type NonEmptyList<A> = readonly [A, ...A[]];
|
|
15
|
+
/**
|
|
16
|
+
* Type guard that checks if an array is non-empty.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const items: string[] = getItems();
|
|
21
|
+
*
|
|
22
|
+
* if (isNonEmptyList(items)) {
|
|
23
|
+
* // TypeScript knows items has at least one element
|
|
24
|
+
* const first = items[0]; // string, not string | undefined
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare const isNonEmptyList: <A>(list: readonly A[]) => list is NonEmptyList<A>;
|
|
29
|
+
//# sourceMappingURL=NonEmptyList.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NonEmptyList.d.ts","sourceRoot":"","sources":["../../../src/src/Types/NonEmptyList.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;AAEnD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,EAC9B,MAAM,SAAS,CAAC,EAAE,KACjB,IAAI,IAAI,YAAY,CAAC,CAAC,CAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/Types/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
|