@nlozgachev/pipelined 0.11.0 → 0.13.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.
Files changed (193) hide show
  1. package/LICENCE +28 -0
  2. package/README.md +1 -1
  3. package/{types/src/Types/NonEmptyList.d.ts → dist/NonEmptyList-BlGFjor5.d.mts} +4 -3
  4. package/dist/NonEmptyList-BlGFjor5.d.ts +30 -0
  5. package/dist/Task-BB8Wmc1J.d.ts +677 -0
  6. package/dist/Task-ChKyH0pF.d.mts +677 -0
  7. package/dist/chunk-DBIC62UV.mjs +6 -0
  8. package/dist/chunk-QPTGO5AS.mjs +150 -0
  9. package/dist/composition.d.mts +495 -0
  10. package/dist/composition.d.ts +495 -0
  11. package/dist/composition.js +188 -0
  12. package/dist/composition.mjs +135 -0
  13. package/dist/core.d.mts +2170 -0
  14. package/dist/core.d.ts +2170 -0
  15. package/dist/core.js +698 -0
  16. package/dist/core.mjs +517 -0
  17. package/dist/types.d.mts +54 -0
  18. package/{types/src/Types/Brand.d.ts → dist/types.d.ts} +6 -4
  19. package/dist/types.js +41 -0
  20. package/dist/types.mjs +14 -0
  21. package/dist/utils.d.mts +1285 -0
  22. package/dist/utils.d.ts +1285 -0
  23. package/dist/utils.js +722 -0
  24. package/dist/utils.mjs +553 -0
  25. package/package.json +63 -69
  26. package/esm/mod.js +0 -3
  27. package/esm/package.json +0 -3
  28. package/esm/src/Composition/compose.js +0 -3
  29. package/esm/src/Composition/converge.js +0 -3
  30. package/esm/src/Composition/curry.js +0 -42
  31. package/esm/src/Composition/flip.js +0 -20
  32. package/esm/src/Composition/flow.js +0 -8
  33. package/esm/src/Composition/fn.js +0 -85
  34. package/esm/src/Composition/index.js +0 -13
  35. package/esm/src/Composition/juxt.js +0 -3
  36. package/esm/src/Composition/memoize.js +0 -66
  37. package/esm/src/Composition/not.js +0 -25
  38. package/esm/src/Composition/on.js +0 -12
  39. package/esm/src/Composition/pipe.js +0 -3
  40. package/esm/src/Composition/tap.js +0 -33
  41. package/esm/src/Composition/uncurry.js +0 -32
  42. package/esm/src/Core/Deferred.js +0 -30
  43. package/esm/src/Core/InternalTypes.js +0 -1
  44. package/esm/src/Core/Lens.js +0 -98
  45. package/esm/src/Core/Logged.js +0 -111
  46. package/esm/src/Core/Option.js +0 -191
  47. package/esm/src/Core/Optional.js +0 -160
  48. package/esm/src/Core/Predicate.js +0 -133
  49. package/esm/src/Core/Reader.js +0 -134
  50. package/esm/src/Core/Refinement.js +0 -115
  51. package/esm/src/Core/RemoteData.js +0 -211
  52. package/esm/src/Core/Result.js +0 -170
  53. package/esm/src/Core/State.js +0 -181
  54. package/esm/src/Core/Task.js +0 -223
  55. package/esm/src/Core/TaskOption.js +0 -106
  56. package/esm/src/Core/TaskResult.js +0 -127
  57. package/esm/src/Core/TaskValidation.js +0 -128
  58. package/esm/src/Core/These.js +0 -245
  59. package/esm/src/Core/Validation.js +0 -212
  60. package/esm/src/Core/index.js +0 -17
  61. package/esm/src/Types/Brand.js +0 -28
  62. package/esm/src/Types/NonEmptyList.js +0 -14
  63. package/esm/src/Types/index.js +0 -2
  64. package/esm/src/Utils/Arr.js +0 -570
  65. package/esm/src/Utils/Num.js +0 -124
  66. package/esm/src/Utils/Rec.js +0 -215
  67. package/esm/src/Utils/Str.js +0 -134
  68. package/esm/src/Utils/index.js +0 -4
  69. package/script/mod.js +0 -19
  70. package/script/package.json +0 -3
  71. package/script/src/Composition/compose.js +0 -6
  72. package/script/src/Composition/converge.js +0 -6
  73. package/script/src/Composition/curry.js +0 -48
  74. package/script/src/Composition/flip.js +0 -24
  75. package/script/src/Composition/flow.js +0 -11
  76. package/script/src/Composition/fn.js +0 -98
  77. package/script/src/Composition/index.js +0 -29
  78. package/script/src/Composition/juxt.js +0 -6
  79. package/script/src/Composition/memoize.js +0 -71
  80. package/script/src/Composition/not.js +0 -29
  81. package/script/src/Composition/on.js +0 -16
  82. package/script/src/Composition/pipe.js +0 -6
  83. package/script/src/Composition/tap.js +0 -37
  84. package/script/src/Composition/uncurry.js +0 -38
  85. package/script/src/Core/Deferred.js +0 -33
  86. package/script/src/Core/InternalTypes.js +0 -2
  87. package/script/src/Core/Lens.js +0 -101
  88. package/script/src/Core/Logged.js +0 -114
  89. package/script/src/Core/Option.js +0 -194
  90. package/script/src/Core/Optional.js +0 -163
  91. package/script/src/Core/Predicate.js +0 -136
  92. package/script/src/Core/Reader.js +0 -137
  93. package/script/src/Core/Refinement.js +0 -118
  94. package/script/src/Core/RemoteData.js +0 -214
  95. package/script/src/Core/Result.js +0 -173
  96. package/script/src/Core/State.js +0 -184
  97. package/script/src/Core/Task.js +0 -226
  98. package/script/src/Core/TaskOption.js +0 -109
  99. package/script/src/Core/TaskResult.js +0 -130
  100. package/script/src/Core/TaskValidation.js +0 -131
  101. package/script/src/Core/These.js +0 -248
  102. package/script/src/Core/Validation.js +0 -215
  103. package/script/src/Core/index.js +0 -33
  104. package/script/src/Types/Brand.js +0 -31
  105. package/script/src/Types/NonEmptyList.js +0 -18
  106. package/script/src/Types/index.js +0 -18
  107. package/script/src/Utils/Arr.js +0 -573
  108. package/script/src/Utils/Num.js +0 -127
  109. package/script/src/Utils/Rec.js +0 -218
  110. package/script/src/Utils/Str.js +0 -137
  111. package/script/src/Utils/index.js +0 -20
  112. package/types/mod.d.ts +0 -4
  113. package/types/mod.d.ts.map +0 -1
  114. package/types/src/Composition/compose.d.ts +0 -33
  115. package/types/src/Composition/compose.d.ts.map +0 -1
  116. package/types/src/Composition/converge.d.ts +0 -21
  117. package/types/src/Composition/converge.d.ts.map +0 -1
  118. package/types/src/Composition/curry.d.ts +0 -43
  119. package/types/src/Composition/curry.d.ts.map +0 -1
  120. package/types/src/Composition/flip.d.ts +0 -21
  121. package/types/src/Composition/flip.d.ts.map +0 -1
  122. package/types/src/Composition/flow.d.ts +0 -56
  123. package/types/src/Composition/flow.d.ts.map +0 -1
  124. package/types/src/Composition/fn.d.ts +0 -76
  125. package/types/src/Composition/fn.d.ts.map +0 -1
  126. package/types/src/Composition/index.d.ts +0 -14
  127. package/types/src/Composition/index.d.ts.map +0 -1
  128. package/types/src/Composition/juxt.d.ts +0 -18
  129. package/types/src/Composition/juxt.d.ts.map +0 -1
  130. package/types/src/Composition/memoize.d.ts +0 -46
  131. package/types/src/Composition/memoize.d.ts.map +0 -1
  132. package/types/src/Composition/not.d.ts +0 -26
  133. package/types/src/Composition/not.d.ts.map +0 -1
  134. package/types/src/Composition/on.d.ts +0 -13
  135. package/types/src/Composition/on.d.ts.map +0 -1
  136. package/types/src/Composition/pipe.d.ts +0 -56
  137. package/types/src/Composition/pipe.d.ts.map +0 -1
  138. package/types/src/Composition/tap.d.ts +0 -31
  139. package/types/src/Composition/tap.d.ts.map +0 -1
  140. package/types/src/Composition/uncurry.d.ts +0 -54
  141. package/types/src/Composition/uncurry.d.ts.map +0 -1
  142. package/types/src/Core/Deferred.d.ts +0 -49
  143. package/types/src/Core/Deferred.d.ts.map +0 -1
  144. package/types/src/Core/InternalTypes.d.ts +0 -23
  145. package/types/src/Core/InternalTypes.d.ts.map +0 -1
  146. package/types/src/Core/Lens.d.ts +0 -118
  147. package/types/src/Core/Lens.d.ts.map +0 -1
  148. package/types/src/Core/Logged.d.ts +0 -126
  149. package/types/src/Core/Logged.d.ts.map +0 -1
  150. package/types/src/Core/Option.d.ts +0 -209
  151. package/types/src/Core/Option.d.ts.map +0 -1
  152. package/types/src/Core/Optional.d.ts +0 -158
  153. package/types/src/Core/Optional.d.ts.map +0 -1
  154. package/types/src/Core/Predicate.d.ts +0 -161
  155. package/types/src/Core/Predicate.d.ts.map +0 -1
  156. package/types/src/Core/Reader.d.ts +0 -156
  157. package/types/src/Core/Reader.d.ts.map +0 -1
  158. package/types/src/Core/Refinement.d.ts +0 -138
  159. package/types/src/Core/Refinement.d.ts.map +0 -1
  160. package/types/src/Core/RemoteData.d.ts +0 -197
  161. package/types/src/Core/RemoteData.d.ts.map +0 -1
  162. package/types/src/Core/Result.d.ts +0 -182
  163. package/types/src/Core/Result.d.ts.map +0 -1
  164. package/types/src/Core/State.d.ts +0 -192
  165. package/types/src/Core/State.d.ts.map +0 -1
  166. package/types/src/Core/Task.d.ts +0 -219
  167. package/types/src/Core/Task.d.ts.map +0 -1
  168. package/types/src/Core/TaskOption.d.ts +0 -121
  169. package/types/src/Core/TaskOption.d.ts.map +0 -1
  170. package/types/src/Core/TaskResult.d.ts +0 -119
  171. package/types/src/Core/TaskResult.d.ts.map +0 -1
  172. package/types/src/Core/TaskValidation.d.ts +0 -144
  173. package/types/src/Core/TaskValidation.d.ts.map +0 -1
  174. package/types/src/Core/These.d.ts +0 -225
  175. package/types/src/Core/These.d.ts.map +0 -1
  176. package/types/src/Core/Validation.d.ts +0 -203
  177. package/types/src/Core/Validation.d.ts.map +0 -1
  178. package/types/src/Core/index.d.ts +0 -18
  179. package/types/src/Core/index.d.ts.map +0 -1
  180. package/types/src/Types/Brand.d.ts.map +0 -1
  181. package/types/src/Types/NonEmptyList.d.ts.map +0 -1
  182. package/types/src/Types/index.d.ts +0 -3
  183. package/types/src/Types/index.d.ts.map +0 -1
  184. package/types/src/Utils/Arr.d.ts +0 -403
  185. package/types/src/Utils/Arr.d.ts.map +0 -1
  186. package/types/src/Utils/Num.d.ts +0 -110
  187. package/types/src/Utils/Num.d.ts.map +0 -1
  188. package/types/src/Utils/Rec.d.ts +0 -143
  189. package/types/src/Utils/Rec.d.ts.map +0 -1
  190. package/types/src/Utils/Str.d.ts +0 -128
  191. package/types/src/Utils/Str.d.ts.map +0 -1
  192. package/types/src/Utils/index.d.ts +0 -5
  193. package/types/src/Utils/index.d.ts.map +0 -1
@@ -1,248 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.These = void 0;
4
- var These;
5
- (function (These) {
6
- /**
7
- * Creates a These holding only a first value.
8
- *
9
- * @example
10
- * ```ts
11
- * These.first(42); // { kind: "First", first: 42 }
12
- * ```
13
- */
14
- These.first = (value) => ({ kind: "First", first: value });
15
- /**
16
- * Creates a These holding only a second value.
17
- *
18
- * @example
19
- * ```ts
20
- * These.second("warning"); // { kind: "Second", second: "warning" }
21
- * ```
22
- */
23
- These.second = (value) => ({ kind: "Second", second: value });
24
- /**
25
- * Creates a These holding both a first and a second value simultaneously.
26
- *
27
- * @example
28
- * ```ts
29
- * These.both(42, "Deprecated API used"); // { kind: "Both", first: 42, second: "Deprecated API used" }
30
- * ```
31
- */
32
- These.both = (first, second) => ({
33
- kind: "Both",
34
- first,
35
- second,
36
- });
37
- /**
38
- * Type guard — checks if a These holds only a first value.
39
- */
40
- These.isFirst = (data) => data.kind === "First";
41
- /**
42
- * Type guard — checks if a These holds only a second value.
43
- */
44
- These.isSecond = (data) => data.kind === "Second";
45
- /**
46
- * Type guard — checks if a These holds both values simultaneously.
47
- */
48
- These.isBoth = (data) => data.kind === "Both";
49
- /**
50
- * Returns true if the These contains a first value (First or Both).
51
- */
52
- These.hasFirst = (data) => data.kind === "First" || data.kind === "Both";
53
- /**
54
- * Returns true if the These contains a second value (Second or Both).
55
- */
56
- These.hasSecond = (data) => data.kind === "Second" || data.kind === "Both";
57
- /**
58
- * Transforms the first value, leaving the second unchanged.
59
- *
60
- * @example
61
- * ```ts
62
- * pipe(These.first(5), These.mapFirst(n => n * 2)); // First(10)
63
- * pipe(These.both(5, "warn"), These.mapFirst(n => n * 2)); // Both(10, "warn")
64
- * pipe(These.second("warn"), These.mapFirst(n => n * 2)); // Second("warn")
65
- * ```
66
- */
67
- These.mapFirst = (f) => (data) => {
68
- if (These.isSecond(data))
69
- return data;
70
- if (These.isFirst(data))
71
- return These.first(f(data.first));
72
- return These.both(f(data.first), data.second);
73
- };
74
- /**
75
- * Transforms the second value, leaving the first unchanged.
76
- *
77
- * @example
78
- * ```ts
79
- * pipe(These.second("warn"), These.mapSecond(e => e.toUpperCase())); // Second("WARN")
80
- * pipe(These.both(5, "warn"), These.mapSecond(e => e.toUpperCase())); // Both(5, "WARN")
81
- * ```
82
- */
83
- These.mapSecond = (f) => (data) => {
84
- if (These.isFirst(data))
85
- return data;
86
- if (These.isSecond(data))
87
- return These.second(f(data.second));
88
- return These.both(data.first, f(data.second));
89
- };
90
- /**
91
- * Transforms both the first and second values independently.
92
- *
93
- * @example
94
- * ```ts
95
- * pipe(
96
- * These.both(5, "warn"),
97
- * These.mapBoth(n => n * 2, e => e.toUpperCase())
98
- * ); // Both(10, "WARN")
99
- * ```
100
- */
101
- These.mapBoth = (onFirst, onSecond) => (data) => {
102
- if (These.isSecond(data))
103
- return These.second(onSecond(data.second));
104
- if (These.isFirst(data))
105
- return These.first(onFirst(data.first));
106
- return These.both(onFirst(data.first), onSecond(data.second));
107
- };
108
- /**
109
- * Chains These computations by passing the first value to f.
110
- * Second propagates unchanged; First and Both apply f to the first value.
111
- *
112
- * @example
113
- * ```ts
114
- * const double = (n: number): These<number, string> => These.first(n * 2);
115
- *
116
- * pipe(These.first(5), These.chainFirst(double)); // First(10)
117
- * pipe(These.both(5, "warn"), These.chainFirst(double)); // First(10)
118
- * pipe(These.second("warn"), These.chainFirst(double)); // Second("warn")
119
- * ```
120
- */
121
- These.chainFirst = (f) => (data) => {
122
- if (These.isSecond(data))
123
- return data;
124
- return f(data.first);
125
- };
126
- /**
127
- * Chains These computations by passing the second value to f.
128
- * First propagates unchanged; Second and Both apply f to the second value.
129
- *
130
- * @example
131
- * ```ts
132
- * const shout = (s: string): These<number, string> => These.second(s.toUpperCase());
133
- *
134
- * pipe(These.second("warn"), These.chainSecond(shout)); // Second("WARN")
135
- * pipe(These.both(5, "warn"), These.chainSecond(shout)); // Second("WARN")
136
- * pipe(These.first(5), These.chainSecond(shout)); // First(5)
137
- * ```
138
- */
139
- These.chainSecond = (f) => (data) => {
140
- if (These.isFirst(data))
141
- return data;
142
- return f(data.second);
143
- };
144
- /**
145
- * Extracts a value from a These by providing handlers for all three cases.
146
- *
147
- * @example
148
- * ```ts
149
- * pipe(
150
- * these,
151
- * These.fold(
152
- * a => `First: ${a}`,
153
- * b => `Second: ${b}`,
154
- * (a, b) => `Both: ${a} / ${b}`
155
- * )
156
- * );
157
- * ```
158
- */
159
- These.fold = (onFirst, onSecond, onBoth) => (data) => {
160
- if (These.isSecond(data))
161
- return onSecond(data.second);
162
- if (These.isFirst(data))
163
- return onFirst(data.first);
164
- return onBoth(data.first, data.second);
165
- };
166
- /**
167
- * Pattern matches on a These, returning the result of the matching case.
168
- *
169
- * @example
170
- * ```ts
171
- * pipe(
172
- * these,
173
- * These.match({
174
- * first: a => `First: ${a}`,
175
- * second: b => `Second: ${b}`,
176
- * both: (a, b) => `Both: ${a} / ${b}`
177
- * })
178
- * );
179
- * ```
180
- */
181
- These.match = (cases) => (data) => {
182
- if (These.isSecond(data))
183
- return cases.second(data.second);
184
- if (These.isFirst(data))
185
- return cases.first(data.first);
186
- return cases.both(data.first, data.second);
187
- };
188
- /**
189
- * Returns the first value, or a default if the These has no first value.
190
- * The default can be a different type, widening the result to `A | C`.
191
- *
192
- * @example
193
- * ```ts
194
- * pipe(These.first(5), These.getFirstOrElse(() => 0)); // 5
195
- * pipe(These.both(5, "warn"), These.getFirstOrElse(() => 0)); // 5
196
- * pipe(These.second("warn"), These.getFirstOrElse(() => 0)); // 0
197
- * pipe(These.second("warn"), These.getFirstOrElse(() => null)); // null — typed as number | null
198
- * ```
199
- */
200
- These.getFirstOrElse = (defaultValue) => (data) => These.hasFirst(data) ? data.first : defaultValue();
201
- /**
202
- * Returns the second value, or a default if the These has no second value.
203
- * The default can be a different type, widening the result to `B | D`.
204
- *
205
- * @example
206
- * ```ts
207
- * pipe(These.second("warn"), These.getSecondOrElse(() => "none")); // "warn"
208
- * pipe(These.both(5, "warn"), These.getSecondOrElse(() => "none")); // "warn"
209
- * pipe(These.first(5), These.getSecondOrElse(() => "none")); // "none"
210
- * pipe(These.first(5), These.getSecondOrElse(() => null)); // null — typed as string | null
211
- * ```
212
- */
213
- These.getSecondOrElse = (defaultValue) => (data) => These.hasSecond(data) ? data.second : defaultValue();
214
- /**
215
- * Executes a side effect on the first value without changing the These.
216
- * Useful for logging or debugging.
217
- *
218
- * @example
219
- * ```ts
220
- * pipe(These.first(5), These.tap(console.log)); // logs 5, returns First(5)
221
- * ```
222
- */
223
- These.tap = (f) => (data) => {
224
- if (These.hasFirst(data))
225
- f(data.first);
226
- return data;
227
- };
228
- /**
229
- * Swaps the roles of first and second values.
230
- * - First(a) → Second(a)
231
- * - Second(b) → First(b)
232
- * - Both(a, b) → Both(b, a)
233
- *
234
- * @example
235
- * ```ts
236
- * These.swap(These.first(5)); // Second(5)
237
- * These.swap(These.second("warn")); // First("warn")
238
- * These.swap(These.both(5, "warn")); // Both("warn", 5)
239
- * ```
240
- */
241
- These.swap = (data) => {
242
- if (These.isSecond(data))
243
- return These.first(data.second);
244
- if (These.isFirst(data))
245
- return These.second(data.first);
246
- return These.both(data.second, data.first);
247
- };
248
- })(These || (exports.These = These = {}));
@@ -1,215 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Validation = void 0;
4
- var Validation;
5
- (function (Validation) {
6
- /**
7
- * Wraps a value in a valid Validation.
8
- *
9
- * @example
10
- * ```ts
11
- * Validation.valid(42); // Valid(42)
12
- * ```
13
- */
14
- Validation.valid = (value) => ({
15
- kind: "Valid",
16
- value,
17
- });
18
- /**
19
- * Creates an invalid Validation from a single error.
20
- *
21
- * @example
22
- * ```ts
23
- * Validation.invalid("Invalid input");
24
- * ```
25
- */
26
- Validation.invalid = (error) => ({
27
- kind: "Invalid",
28
- errors: [error],
29
- });
30
- /**
31
- * Creates an invalid Validation from multiple errors.
32
- *
33
- * @example
34
- * ```ts
35
- * Validation.invalidAll(["Invalid input"]);
36
- * ```
37
- */
38
- Validation.invalidAll = (errors) => ({
39
- kind: "Invalid",
40
- errors,
41
- });
42
- /**
43
- * Type guard that checks if a Validation is valid.
44
- */
45
- Validation.isValid = (data) => data.kind === "Valid";
46
- /**
47
- * Type guard that checks if a Validation is invalid.
48
- */
49
- Validation.isInvalid = (data) => data.kind === "Invalid";
50
- /**
51
- * Transforms the success value inside a Validation.
52
- *
53
- * @example
54
- * ```ts
55
- * pipe(Validation.valid(5), Validation.map(n => n * 2)); // Valid(10)
56
- * pipe(Validation.invalid("oops"), Validation.map(n => n * 2)); // Invalid(["oops"])
57
- * ```
58
- */
59
- Validation.map = (f) => (data) => Validation.isValid(data) ? Validation.valid(f(data.value)) : data;
60
- /**
61
- * Applies a function wrapped in a Validation to a value wrapped in a Validation.
62
- * Accumulates errors from both sides.
63
- *
64
- * @example
65
- * ```ts
66
- * const add = (a: number) => (b: number) => a + b;
67
- * pipe(
68
- * Validation.valid(add),
69
- * Validation.ap(Validation.valid(5)),
70
- * Validation.ap(Validation.valid(3))
71
- * ); // Valid(8)
72
- *
73
- * pipe(
74
- * Validation.valid(add),
75
- * Validation.ap(Validation.invalid<string, number>("bad a")),
76
- * Validation.ap(Validation.invalid<string, number>("bad b"))
77
- * ); // Invalid(["bad a", "bad b"])
78
- * ```
79
- */
80
- Validation.ap = (arg) => (data) => {
81
- if (Validation.isValid(data) && Validation.isValid(arg))
82
- return Validation.valid(data.value(arg.value));
83
- const errors = [
84
- ...(Validation.isInvalid(data) ? data.errors : []),
85
- ...(Validation.isInvalid(arg) ? arg.errors : []),
86
- ];
87
- return Validation.invalidAll(errors);
88
- };
89
- /**
90
- * Extracts the value from a Validation by providing handlers for both cases.
91
- *
92
- * @example
93
- * ```ts
94
- * pipe(
95
- * Validation.valid(42),
96
- * Validation.fold(
97
- * errors => `Errors: ${errors.join(", ")}`,
98
- * value => `Value: ${value}`
99
- * )
100
- * );
101
- * ```
102
- */
103
- Validation.fold = (onInvalid, onValid) => (data) => Validation.isValid(data) ? onValid(data.value) : onInvalid(data.errors);
104
- /**
105
- * Pattern matches on a Validation, returning the result of the matching case.
106
- *
107
- * @example
108
- * ```ts
109
- * pipe(
110
- * validation,
111
- * Validation.match({
112
- * valid: value => `Got ${value}`,
113
- * invalid: errors => `Failed: ${errors.join(", ")}`
114
- * })
115
- * );
116
- * ```
117
- */
118
- Validation.match = (cases) => (data) => Validation.isValid(data) ? cases.valid(data.value) : cases.invalid(data.errors);
119
- /**
120
- * Returns the success value or a default value if the Validation is invalid.
121
- * The default can be a different type, widening the result to `A | B`.
122
- *
123
- * @example
124
- * ```ts
125
- * pipe(Validation.valid(5), Validation.getOrElse(() => 0)); // 5
126
- * pipe(Validation.invalid("oops"), Validation.getOrElse(() => 0)); // 0
127
- * pipe(Validation.invalid("oops"), Validation.getOrElse(() => null)); // null — typed as number | null
128
- * ```
129
- */
130
- Validation.getOrElse = (defaultValue) => (data) => Validation.isValid(data) ? data.value : defaultValue();
131
- /**
132
- * Executes a side effect on the success value without changing the Validation.
133
- *
134
- * @example
135
- * ```ts
136
- * pipe(
137
- * Validation.valid(5),
138
- * Validation.tap(n => console.log("Value:", n)),
139
- * Validation.map(n => n * 2)
140
- * );
141
- * ```
142
- */
143
- Validation.tap = (f) => (data) => {
144
- if (Validation.isValid(data))
145
- f(data.value);
146
- return data;
147
- };
148
- /**
149
- * Recovers from an Invalid state by providing a fallback Validation.
150
- * The fallback receives the accumulated error list so callers can inspect which errors occurred.
151
- * The fallback can produce a different success type, widening the result to `Validation<E, A | B>`.
152
- */
153
- Validation.recover = (fallback) => (data) => Validation.isValid(data) ? data : fallback(data.errors);
154
- /**
155
- * Recovers from an Invalid state unless the errors contain any of the blocked errors.
156
- * The fallback can produce a different success type, widening the result to `Validation<E, A | B>`.
157
- */
158
- Validation.recoverUnless = (blockedErrors, fallback) => (data) => Validation.isInvalid(data) &&
159
- !data.errors.some((err) => blockedErrors.includes(err))
160
- ? fallback()
161
- : data;
162
- /**
163
- * Combines two independent Validation instances into a tuple.
164
- * If both are Valid, returns Valid with both values as a tuple.
165
- * If either is Invalid, accumulates errors from both sides.
166
- *
167
- * @example
168
- * ```ts
169
- * Validation.product(
170
- * Validation.valid("alice"),
171
- * Validation.valid(30)
172
- * ); // Valid(["alice", 30])
173
- *
174
- * Validation.product(
175
- * Validation.invalid("Name required"),
176
- * Validation.invalid("Age must be >= 0")
177
- * ); // Invalid(["Name required", "Age must be >= 0"])
178
- * ```
179
- */
180
- Validation.product = (first, second) => {
181
- if (Validation.isValid(first) && Validation.isValid(second))
182
- return Validation.valid([first.value, second.value]);
183
- const errors = [
184
- ...(Validation.isInvalid(first) ? first.errors : []),
185
- ...(Validation.isInvalid(second) ? second.errors : []),
186
- ];
187
- return Validation.invalidAll(errors);
188
- };
189
- /**
190
- * Combines a non-empty list of Validation instances, accumulating all errors.
191
- * If all are Valid, returns Valid with all values collected into an array.
192
- * If any are Invalid, returns Invalid with all accumulated errors.
193
- *
194
- * @example
195
- * ```ts
196
- * Validation.productAll([
197
- * validateName(name),
198
- * validateEmail(email),
199
- * validateAge(age)
200
- * ]);
201
- * // Valid([name, email, age]) or Invalid([...all errors])
202
- * ```
203
- */
204
- Validation.productAll = (data) => {
205
- const values = [];
206
- const errors = [];
207
- for (const v of data) {
208
- if (Validation.isValid(v))
209
- values.push(v.value);
210
- else
211
- errors.push(...v.errors);
212
- }
213
- return errors.length > 0 ? Validation.invalidAll(errors) : Validation.valid(values);
214
- };
215
- })(Validation || (exports.Validation = Validation = {}));
@@ -1,33 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./Logged.js"), exports);
18
- __exportStar(require("./Deferred.js"), exports);
19
- __exportStar(require("./Lens.js"), exports);
20
- __exportStar(require("./Option.js"), exports);
21
- __exportStar(require("./Reader.js"), exports);
22
- __exportStar(require("./Optional.js"), exports);
23
- __exportStar(require("./Predicate.js"), exports);
24
- __exportStar(require("./Refinement.js"), exports);
25
- __exportStar(require("./RemoteData.js"), exports);
26
- __exportStar(require("./State.js"), exports);
27
- __exportStar(require("./Result.js"), exports);
28
- __exportStar(require("./Task.js"), exports);
29
- __exportStar(require("./TaskOption.js"), exports);
30
- __exportStar(require("./TaskResult.js"), exports);
31
- __exportStar(require("./TaskValidation.js"), exports);
32
- __exportStar(require("./These.js"), exports);
33
- __exportStar(require("./Validation.js"), exports);
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Brand = void 0;
4
- var Brand;
5
- (function (Brand) {
6
- /**
7
- * Returns a constructor that wraps a value of type T in brand K.
8
- * The resulting function performs an unchecked cast — only use when the raw
9
- * value is known to satisfy the brand's invariants.
10
- *
11
- * @example
12
- * ```ts
13
- * type PositiveNumber = Brand<"PositiveNumber", number>;
14
- * const toPositiveNumber = Brand.wrap<"PositiveNumber", number>();
15
- *
16
- * const n: PositiveNumber = toPositiveNumber(42);
17
- * ```
18
- */
19
- Brand.wrap = () => (value) => value;
20
- /**
21
- * Strips the brand and returns the underlying value.
22
- * Since Brand<K, T> extends T this is rarely needed, but can improve readability.
23
- *
24
- * @example
25
- * ```ts
26
- * const userId: UserId = toUserId("user-123");
27
- * const raw: string = Brand.unwrap(userId); // "user-123"
28
- * ```
29
- */
30
- Brand.unwrap = (branded) => branded;
31
- })(Brand || (exports.Brand = Brand = {}));
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isNonEmptyList = void 0;
4
- /**
5
- * Type guard that checks if an array is non-empty.
6
- *
7
- * @example
8
- * ```ts
9
- * const items: string[] = getItems();
10
- *
11
- * if (isNonEmptyList(items)) {
12
- * // TypeScript knows items has at least one element
13
- * const first = items[0]; // string, not string | undefined
14
- * }
15
- * ```
16
- */
17
- const isNonEmptyList = (list) => list.length > 0;
18
- exports.isNonEmptyList = isNonEmptyList;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./Brand.js"), exports);
18
- __exportStar(require("./NonEmptyList.js"), exports);