@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,121 +0,0 @@
1
- import { Option } from "./Option.js";
2
- import { Task } from "./Task.js";
3
- import { TaskResult } from "./TaskResult.js";
4
- /**
5
- * A Task that resolves to an optional value.
6
- * Combines async operations with the Option type for values that may not exist.
7
- *
8
- * @example
9
- * ```ts
10
- * const findUser = (id: string): TaskOption<User> =>
11
- * TaskOption.tryCatch(() => db.users.findById(id));
12
- *
13
- * pipe(
14
- * findUser("123"),
15
- * TaskOption.map(user => user.name),
16
- * TaskOption.getOrElse(() => "Unknown")
17
- * )();
18
- * ```
19
- */
20
- export type TaskOption<A> = Task<Option<A>>;
21
- export declare namespace TaskOption {
22
- /**
23
- * Wraps a value in a Some inside a Task.
24
- */
25
- const some: <A>(value: A) => TaskOption<A>;
26
- /**
27
- * Creates a TaskOption that resolves to None.
28
- */
29
- const none: <A = never>() => TaskOption<A>;
30
- /**
31
- * Lifts an Option into a TaskOption.
32
- */
33
- const fromOption: <A>(option: Option<A>) => TaskOption<A>;
34
- /**
35
- * Lifts a Task into a TaskOption by wrapping its result in Some.
36
- */
37
- const fromTask: <A>(task: Task<A>) => TaskOption<A>;
38
- /**
39
- * Creates a TaskOption from a Promise-returning function.
40
- * Returns Some if the promise resolves, None if it rejects.
41
- *
42
- * @example
43
- * ```ts
44
- * const fetchUser = TaskOption.tryCatch(() =>
45
- * fetch("/user/1").then(r => r.json())
46
- * );
47
- * ```
48
- */
49
- const tryCatch: <A>(f: () => Promise<A>) => TaskOption<A>;
50
- /**
51
- * Transforms the value inside a TaskOption.
52
- */
53
- const map: <A, B>(f: (a: A) => B) => (data: TaskOption<A>) => TaskOption<B>;
54
- /**
55
- * Chains TaskOption computations. If the first resolves to Some, passes the
56
- * value to f. If the first resolves to None, propagates None.
57
- *
58
- * @example
59
- * ```ts
60
- * pipe(
61
- * findUser("123"),
62
- * TaskOption.chain(user => findOrg(user.orgId))
63
- * )();
64
- * ```
65
- */
66
- const chain: <A, B>(f: (a: A) => TaskOption<B>) => (data: TaskOption<A>) => TaskOption<B>;
67
- /**
68
- * Applies a function wrapped in a TaskOption to a value wrapped in a TaskOption.
69
- * Both Tasks run in parallel.
70
- */
71
- const ap: <A>(arg: TaskOption<A>) => <B>(data: TaskOption<(a: A) => B>) => TaskOption<B>;
72
- /**
73
- * Extracts a value from a TaskOption by providing handlers for both cases.
74
- */
75
- const fold: <A, B>(onNone: () => B, onSome: (a: A) => B) => (data: TaskOption<A>) => Task<B>;
76
- /**
77
- * Pattern matches on a TaskOption, returning a Task of the result.
78
- *
79
- * @example
80
- * ```ts
81
- * pipe(
82
- * findUser("123"),
83
- * TaskOption.match({
84
- * some: user => `Hello, ${user.name}`,
85
- * none: () => "User not found"
86
- * })
87
- * )();
88
- * ```
89
- */
90
- const match: <A, B>(cases: {
91
- none: () => B;
92
- some: (a: A) => B;
93
- }) => (data: TaskOption<A>) => Task<B>;
94
- /**
95
- * Returns the value or a default if the TaskOption resolves to None.
96
- * The default can be a different type, widening the result to `Task<A | B>`.
97
- */
98
- const getOrElse: <A, B>(defaultValue: () => B) => (data: TaskOption<A>) => Task<A | B>;
99
- /**
100
- * Executes a side effect on the value without changing the TaskOption.
101
- * Useful for logging or debugging.
102
- */
103
- const tap: <A>(f: (a: A) => void) => (data: TaskOption<A>) => TaskOption<A>;
104
- /**
105
- * Filters the value inside a TaskOption. Returns None if the predicate fails.
106
- */
107
- const filter: <A>(predicate: (a: A) => boolean) => (data: TaskOption<A>) => TaskOption<A>;
108
- /**
109
- * Converts a TaskOption to a TaskResult, using onNone to produce the error value.
110
- *
111
- * @example
112
- * ```ts
113
- * pipe(
114
- * findUser("123"),
115
- * TaskOption.toTaskResult(() => "User not found")
116
- * );
117
- * ```
118
- */
119
- const toTaskResult: <E>(onNone: () => E) => <A>(data: TaskOption<A>) => TaskResult<E, A>;
120
- }
121
- //# sourceMappingURL=TaskOption.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TaskOption.d.ts","sourceRoot":"","sources":["../../../src/src/Core/TaskOption.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,IA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IAAI,GAAI,CAAC,EAAE,CAAC,EAAE,QAAQ,MAAM,CAAC,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,MAAM,UAAU,CAAC,CAAC,CAAC,KAAG,IAAI,CAAC,CAAC,CACrD,CAAC;IAE7C;;;;;;;;;;;;;OAaG;IACI,MAAM,KAAK,GAAI,CAAC,EAAE,CAAC,EAAE,OAAO;QAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAA;KAAE,MAAM,MAAM,UAAU,CAAC,CAAC,CAAC,KAAG,IAAI,CAAC,CAAC,CACrE,CAAC;IAErC;;;OAGG;IACI,MAAM,SAAS,GAAI,CAAC,EAAE,CAAC,EAAE,cAAc,MAAM,CAAC,MAAM,MAAM,UAAU,CAAC,CAAC,CAAC,KAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CACtC,CAAC;IAEtD;;;OAGG;IACI,MAAM,GAAG,GAAI,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,MAAM,MAAM,UAAU,CAAC,CAAC,CAAC,KAAG,UAAU,CAAC,CAAC,CAAkC,CAAC;IAEnH;;OAEG;IACI,MAAM,MAAM,GAAI,CAAC,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,KAAK,OAAO,MAAM,MAAM,UAAU,CAAC,CAAC,CAAC,KAAG,UAAU,CAAC,CAAC,CACrD,CAAC;IAE1C;;;;;;;;;;OAUG;IACI,MAAM,YAAY,GAAI,CAAC,EAAE,QAAQ,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,UAAU,CAAC,CAAC,CAAC,KAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CACrD,CAAC;CACzC"}
@@ -1,119 +0,0 @@
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 ok: <E, A>(value: A) => TaskResult<E, A>;
22
- /**
23
- * Creates a failed TaskResult with the given error.
24
- */
25
- const err: <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
- * The fallback can produce a different success type, widening the result to `TaskResult<E, A | B>`.
67
- */
68
- const recover: <E, A, B>(fallback: (e: E) => TaskResult<E, B>) => (data: TaskResult<E, A>) => TaskResult<E, A | B>;
69
- /**
70
- * Returns the success value or a default value if the TaskResult is an error.
71
- * The default can be a different type, widening the result to `Task<A | B>`.
72
- */
73
- const getOrElse: <E, A, B>(defaultValue: () => B) => (data: TaskResult<E, A>) => Task<A | B>;
74
- /**
75
- * Executes a side effect on the success value without changing the TaskResult.
76
- * Useful for logging or debugging.
77
- */
78
- const tap: <E, A>(f: (a: A) => void) => (data: TaskResult<E, A>) => TaskResult<E, A>;
79
- /**
80
- * Re-runs a TaskResult on `Err` with configurable attempts, backoff, and retry condition.
81
- *
82
- * @param options.attempts - Total number of attempts (1 = no retry, 3 = up to 3 tries)
83
- * @param options.backoff - Fixed delay in ms, or a function `(attempt) => ms` for computed delay
84
- * @param options.when - Only retry when this returns true; defaults to always retry on Err
85
- *
86
- * @example
87
- * ```ts
88
- * // Retry up to 3 times with exponential backoff
89
- * pipe(
90
- * fetchUser,
91
- * TaskResult.retry({ attempts: 3, backoff: n => n * 1000 })
92
- * );
93
- *
94
- * // Only retry on network errors, not auth errors
95
- * pipe(
96
- * fetchUser,
97
- * TaskResult.retry({ attempts: 3, when: e => e instanceof NetworkError })
98
- * );
99
- * ```
100
- */
101
- const retry: <E>(options: {
102
- attempts: number;
103
- backoff?: number | ((attempt: number) => number);
104
- when?: (error: E) => boolean;
105
- }) => <A>(data: TaskResult<E, A>) => TaskResult<E, A>;
106
- /**
107
- * Fails a TaskResult with a typed error if it does not resolve within the given time.
108
- *
109
- * @example
110
- * ```ts
111
- * pipe(
112
- * fetchUser,
113
- * TaskResult.timeout(5000, () => new TimeoutError("fetch user timed out"))
114
- * );
115
- * ```
116
- */
117
- const timeout: <E>(ms: number, onTimeout: () => E) => <A>(data: TaskResult<E, A>) => TaskResult<E, A>;
118
- }
119
- //# sourceMappingURL=TaskResult.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TaskResult.d.ts","sourceRoot":"","sources":["../../../src/src/Core/TaskResult.ts"],"names":[],"mappings":"AACA,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;IAC3B;;OAEG;IACI,MAAM,EAAE,GAAI,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,KAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CAAmC,CAAC;IAEvF;;OAEG;IACI,MAAM,GAAG,GAAI,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,KAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CAAoC,CAAC;IAEzF;;;;;;;;;;;;OAYG;IACI,MAAM,QAAQ,GAAI,CAAC,EAAE,CAAC,EAC5B,GAAG,MAAM,OAAO,CAAC,CAAC,CAAC,EACnB,SAAS,CAAC,CAAC,EAAE,OAAO,KAAK,CAAC,KACxB,UAAU,CAAC,CAAC,EAAE,CAAC,CAKhB,CAAC;IAEH;;OAEG;IACI,MAAM,GAAG,GAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CAClD,CAAC;IAExC;;OAEG;IACI,MAAM,QAAQ,GAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,MAAM,UAAU,CAAC,CAAC,EAA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,CAAC,KAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CACzC,CAAC;IAEzD;;;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,CACrD,CAAC;IAErC;;;;;;;;;;;;;;;;;;;;;OAqBG;IACI,MAAM,KAAK,GAAI,CAAC,EAAE,SAAS;QACjC,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC;QACjD,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC;KAC7B,MACA,CAAC,EAAE,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CAoBzC,CAAC;IAEJ;;;;;;;;;;OAUG;IACI,MAAM,OAAO,GAAI,CAAC,EAAE,IAAI,MAAM,EAAE,WAAW,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CAYvG,CAAC;CACJ"}
@@ -1,144 +0,0 @@
1
- import { NonEmptyList } from "../Types/NonEmptyList.js";
2
- import { Task } from "./Task.js";
3
- import { Validation } from "./Validation.js";
4
- /**
5
- * A Task that resolves to a Validation — combining async operations with
6
- * error accumulation. Unlike TaskResult, multiple failures are collected
7
- * rather than short-circuiting on the first error.
8
- *
9
- * @example
10
- * ```ts
11
- * const validateName = (name: string): TaskValidation<string, string> =>
12
- * name.length > 0
13
- * ? TaskValidation.valid(name)
14
- * : TaskValidation.invalid("Name is required");
15
- *
16
- * // Accumulate errors from multiple async validations using ap
17
- * pipe(
18
- * TaskValidation.valid((name: string) => (age: number) => ({ name, age })),
19
- * TaskValidation.ap(validateName("")),
20
- * TaskValidation.ap(validateAge(-1))
21
- * )();
22
- * // Invalid(["Name is required", "Age must be positive"])
23
- * ```
24
- */
25
- export type TaskValidation<E, A> = Task<Validation<E, A>>;
26
- export declare namespace TaskValidation {
27
- /**
28
- * Wraps a value in a valid TaskValidation.
29
- */
30
- const valid: <E, A>(value: A) => TaskValidation<E, A>;
31
- /**
32
- * Creates a failed TaskValidation with a single error.
33
- */
34
- const invalid: <E, A>(error: E) => TaskValidation<E, A>;
35
- /**
36
- * Creates an invalid TaskValidation from multiple errors.
37
- */
38
- const invalidAll: <E, A>(errors: NonEmptyList<E>) => TaskValidation<E, A>;
39
- /**
40
- * Lifts a Validation into a TaskValidation.
41
- */
42
- const fromValidation: <E, A>(validation: Validation<E, A>) => TaskValidation<E, A>;
43
- /**
44
- * Creates a TaskValidation from a Promise-returning function.
45
- * Catches any errors and transforms them using the onError function.
46
- *
47
- * @example
48
- * ```ts
49
- * const fetchUser = (id: string): TaskValidation<string, User> =>
50
- * TaskValidation.tryCatch(
51
- * () => fetch(`/users/${id}`).then(r => r.json()),
52
- * e => `Failed to fetch user: ${e}`
53
- * );
54
- * ```
55
- */
56
- const tryCatch: <E, A>(f: () => Promise<A>, onError: (e: unknown) => E) => TaskValidation<E, A>;
57
- /**
58
- * Transforms the success value inside a TaskValidation.
59
- */
60
- const map: <E, A, B>(f: (a: A) => B) => (data: TaskValidation<E, A>) => TaskValidation<E, B>;
61
- /**
62
- * Applies a function wrapped in a TaskValidation to a value wrapped in a
63
- * TaskValidation. Both Tasks run in parallel and errors from both sides
64
- * are accumulated.
65
- *
66
- * @example
67
- * ```ts
68
- * pipe(
69
- * TaskValidation.valid((name: string) => (age: number) => ({ name, age })),
70
- * TaskValidation.ap(validateName(name)),
71
- * TaskValidation.ap(validateAge(age))
72
- * )();
73
- * ```
74
- */
75
- const ap: <E, A>(arg: TaskValidation<E, A>) => <B>(data: TaskValidation<E, (a: A) => B>) => TaskValidation<E, B>;
76
- /**
77
- * Extracts a value from a TaskValidation by providing handlers for both cases.
78
- */
79
- const fold: <E, A, B>(onInvalid: (errors: NonEmptyList<E>) => B, onValid: (a: A) => B) => (data: TaskValidation<E, A>) => Task<B>;
80
- /**
81
- * Pattern matches on a TaskValidation, returning a Task of the result.
82
- *
83
- * @example
84
- * ```ts
85
- * pipe(
86
- * validateForm(input),
87
- * TaskValidation.match({
88
- * valid: data => save(data),
89
- * invalid: errors => showErrors(errors)
90
- * })
91
- * )();
92
- * ```
93
- */
94
- const match: <E, A, B>(cases: {
95
- valid: (a: A) => B;
96
- invalid: (errors: NonEmptyList<E>) => B;
97
- }) => (data: TaskValidation<E, A>) => Task<B>;
98
- /**
99
- * Returns the success value or a default value if the TaskValidation is invalid.
100
- * The default can be a different type, widening the result to `Task<A | B>`.
101
- */
102
- const getOrElse: <E, A, B>(defaultValue: () => B) => (data: TaskValidation<E, A>) => Task<A | B>;
103
- /**
104
- * Executes a side effect on the success value without changing the TaskValidation.
105
- * Useful for logging or debugging.
106
- */
107
- const tap: <E, A>(f: (a: A) => void) => (data: TaskValidation<E, A>) => TaskValidation<E, A>;
108
- /**
109
- * Recovers from an Invalid state by providing a fallback TaskValidation.
110
- * The fallback receives the accumulated error list so callers can inspect which errors occurred.
111
- * The fallback can produce a different success type, widening the result to `TaskValidation<E, A | B>`.
112
- */
113
- const recover: <E, A, B>(fallback: (errors: NonEmptyList<E>) => TaskValidation<E, B>) => (data: TaskValidation<E, A>) => TaskValidation<E, A | B>;
114
- /**
115
- * Runs two TaskValidations concurrently and combines their results into a tuple.
116
- * If both are Valid, returns Valid with both values. If either fails, accumulates
117
- * errors from both sides.
118
- *
119
- * @example
120
- * ```ts
121
- * await TaskValidation.product(
122
- * validateName(form.name),
123
- * validateAge(form.age),
124
- * )(); // Valid(["Alice", 30]) or Invalid([...errors])
125
- * ```
126
- */
127
- const product: <E, A, B>(first: TaskValidation<E, A>, second: TaskValidation<E, B>) => TaskValidation<E, readonly [A, B]>;
128
- /**
129
- * Runs all TaskValidations concurrently and collects results.
130
- * If all are Valid, returns Valid with all values as an array.
131
- * If any fail, returns Invalid with all accumulated errors.
132
- *
133
- * @example
134
- * ```ts
135
- * await TaskValidation.productAll([
136
- * validateName(form.name),
137
- * validateEmail(form.email),
138
- * validateAge(form.age),
139
- * ])(); // Valid([name, email, age]) or Invalid([...all errors])
140
- * ```
141
- */
142
- const productAll: <E, A>(data: NonEmptyList<TaskValidation<E, A>>) => TaskValidation<E, readonly A[]>;
143
- }
144
- //# sourceMappingURL=TaskValidation.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TaskValidation.d.ts","sourceRoot":"","sources":["../../../src/src/Core/TaskValidation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAE1D,yBAAiB,cAAc,CAAC;IAC/B;;OAEG;IACI,MAAM,KAAK,GAAI,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,KAAG,cAAc,CAAC,CAAC,EAAE,CAAC,CAA0C,CAAC;IAErG;;OAEG;IACI,MAAM,OAAO,GAAI,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,KAAG,cAAc,CAAC,CAAC,EAAE,CAAC,CAA4C,CAAC;IAEzG;;OAEG;IACI,MAAM,UAAU,GAAI,CAAC,EAAE,CAAC,EAC9B,QAAQ,YAAY,CAAC,CAAC,CAAC,KACrB,cAAc,CAAC,CAAC,EAAE,CAAC,CAAgD,CAAC;IAEvE;;OAEG;IACI,MAAM,cAAc,GAAI,CAAC,EAAE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S,CAAC,EAAE,CAI/B,CAAC;CACH"}
@@ -1,225 +0,0 @@
1
- import { WithFirst, WithKind, WithSecond } from "./InternalTypes.js";
2
- /**
3
- * These<A, B> is an inclusive-OR type: it holds a first value (A), a second
4
- * value (B), or both simultaneously. Neither side carries a success/failure
5
- * connotation — it is a neutral pair where any combination is valid.
6
- *
7
- * - First(a) — only a first value
8
- * - Second(b) — only a second value
9
- * - Both(a, b) — first and second values simultaneously
10
- *
11
- * A common use: lenient parsers or processors that carry a diagnostic note
12
- * alongside a result, without losing either piece of information.
13
- *
14
- * @example
15
- * ```ts
16
- * const parse = (s: string): These<number, string> => {
17
- * const trimmed = s.trim();
18
- * const n = parseFloat(trimmed);
19
- * if (isNaN(n)) return These.second("Not a number");
20
- * if (s !== trimmed) return These.both(n, "Leading/trailing whitespace trimmed");
21
- * return These.first(n);
22
- * };
23
- * ```
24
- */
25
- export type These<A, B> = TheseFirst<A> | TheseSecond<B> | TheseBoth<A, B>;
26
- export type TheseFirst<T> = WithKind<"First"> & WithFirst<T>;
27
- export type TheseSecond<T> = WithKind<"Second"> & WithSecond<T>;
28
- export type TheseBoth<First, Second> = WithKind<"Both"> & WithFirst<First> & WithSecond<Second>;
29
- export declare namespace These {
30
- /**
31
- * Creates a These holding only a first value.
32
- *
33
- * @example
34
- * ```ts
35
- * These.first(42); // { kind: "First", first: 42 }
36
- * ```
37
- */
38
- const first: <A>(value: A) => TheseFirst<A>;
39
- /**
40
- * Creates a These holding only a second value.
41
- *
42
- * @example
43
- * ```ts
44
- * These.second("warning"); // { kind: "Second", second: "warning" }
45
- * ```
46
- */
47
- const second: <B>(value: B) => TheseSecond<B>;
48
- /**
49
- * Creates a These holding both a first and a second value simultaneously.
50
- *
51
- * @example
52
- * ```ts
53
- * These.both(42, "Deprecated API used"); // { kind: "Both", first: 42, second: "Deprecated API used" }
54
- * ```
55
- */
56
- const both: <A, B>(first: A, second: B) => TheseBoth<A, B>;
57
- /**
58
- * Type guard — checks if a These holds only a first value.
59
- */
60
- const isFirst: <A, B>(data: These<A, B>) => data is TheseFirst<A>;
61
- /**
62
- * Type guard — checks if a These holds only a second value.
63
- */
64
- const isSecond: <A, B>(data: These<A, B>) => data is TheseSecond<B>;
65
- /**
66
- * Type guard — checks if a These holds both values simultaneously.
67
- */
68
- const isBoth: <A, B>(data: These<A, B>) => data is TheseBoth<A, B>;
69
- /**
70
- * Returns true if the These contains a first value (First or Both).
71
- */
72
- const hasFirst: <A, B>(data: These<A, B>) => data is TheseFirst<A> | TheseBoth<A, B>;
73
- /**
74
- * Returns true if the These contains a second value (Second or Both).
75
- */
76
- const hasSecond: <A, B>(data: These<A, B>) => data is TheseSecond<B> | TheseBoth<A, B>;
77
- /**
78
- * Transforms the first value, leaving the second unchanged.
79
- *
80
- * @example
81
- * ```ts
82
- * pipe(These.first(5), These.mapFirst(n => n * 2)); // First(10)
83
- * pipe(These.both(5, "warn"), These.mapFirst(n => n * 2)); // Both(10, "warn")
84
- * pipe(These.second("warn"), These.mapFirst(n => n * 2)); // Second("warn")
85
- * ```
86
- */
87
- const mapFirst: <A, C>(f: (a: A) => C) => <B>(data: These<A, B>) => These<C, B>;
88
- /**
89
- * Transforms the second value, leaving the first unchanged.
90
- *
91
- * @example
92
- * ```ts
93
- * pipe(These.second("warn"), These.mapSecond(e => e.toUpperCase())); // Second("WARN")
94
- * pipe(These.both(5, "warn"), These.mapSecond(e => e.toUpperCase())); // Both(5, "WARN")
95
- * ```
96
- */
97
- const mapSecond: <B, D>(f: (b: B) => D) => <A>(data: These<A, B>) => These<A, D>;
98
- /**
99
- * Transforms both the first and second values independently.
100
- *
101
- * @example
102
- * ```ts
103
- * pipe(
104
- * These.both(5, "warn"),
105
- * These.mapBoth(n => n * 2, e => e.toUpperCase())
106
- * ); // Both(10, "WARN")
107
- * ```
108
- */
109
- const mapBoth: <A, C, B, D>(onFirst: (a: A) => C, onSecond: (b: B) => D) => (data: These<A, B>) => These<C, D>;
110
- /**
111
- * Chains These computations by passing the first value to f.
112
- * Second propagates unchanged; First and Both apply f to the first value.
113
- *
114
- * @example
115
- * ```ts
116
- * const double = (n: number): These<number, string> => These.first(n * 2);
117
- *
118
- * pipe(These.first(5), These.chainFirst(double)); // First(10)
119
- * pipe(These.both(5, "warn"), These.chainFirst(double)); // First(10)
120
- * pipe(These.second("warn"), These.chainFirst(double)); // Second("warn")
121
- * ```
122
- */
123
- const chainFirst: <A, B, C>(f: (a: A) => These<C, B>) => (data: These<A, B>) => These<C, B>;
124
- /**
125
- * Chains These computations by passing the second value to f.
126
- * First propagates unchanged; Second and Both apply f to the second value.
127
- *
128
- * @example
129
- * ```ts
130
- * const shout = (s: string): These<number, string> => These.second(s.toUpperCase());
131
- *
132
- * pipe(These.second("warn"), These.chainSecond(shout)); // Second("WARN")
133
- * pipe(These.both(5, "warn"), These.chainSecond(shout)); // Second("WARN")
134
- * pipe(These.first(5), These.chainSecond(shout)); // First(5)
135
- * ```
136
- */
137
- const chainSecond: <A, B, D>(f: (b: B) => These<A, D>) => (data: These<A, B>) => These<A, D>;
138
- /**
139
- * Extracts a value from a These by providing handlers for all three cases.
140
- *
141
- * @example
142
- * ```ts
143
- * pipe(
144
- * these,
145
- * These.fold(
146
- * a => `First: ${a}`,
147
- * b => `Second: ${b}`,
148
- * (a, b) => `Both: ${a} / ${b}`
149
- * )
150
- * );
151
- * ```
152
- */
153
- const fold: <A, B, C>(onFirst: (a: A) => C, onSecond: (b: B) => C, onBoth: (a: A, b: B) => C) => (data: These<A, B>) => C;
154
- /**
155
- * Pattern matches on a These, returning the result of the matching case.
156
- *
157
- * @example
158
- * ```ts
159
- * pipe(
160
- * these,
161
- * These.match({
162
- * first: a => `First: ${a}`,
163
- * second: b => `Second: ${b}`,
164
- * both: (a, b) => `Both: ${a} / ${b}`
165
- * })
166
- * );
167
- * ```
168
- */
169
- const match: <A, B, C>(cases: {
170
- first: (a: A) => C;
171
- second: (b: B) => C;
172
- both: (a: A, b: B) => C;
173
- }) => (data: These<A, B>) => C;
174
- /**
175
- * Returns the first value, or a default if the These has no first value.
176
- * The default can be a different type, widening the result to `A | C`.
177
- *
178
- * @example
179
- * ```ts
180
- * pipe(These.first(5), These.getFirstOrElse(() => 0)); // 5
181
- * pipe(These.both(5, "warn"), These.getFirstOrElse(() => 0)); // 5
182
- * pipe(These.second("warn"), These.getFirstOrElse(() => 0)); // 0
183
- * pipe(These.second("warn"), These.getFirstOrElse(() => null)); // null — typed as number | null
184
- * ```
185
- */
186
- const getFirstOrElse: <A, C>(defaultValue: () => C) => <B>(data: These<A, B>) => A | C;
187
- /**
188
- * Returns the second value, or a default if the These has no second value.
189
- * The default can be a different type, widening the result to `B | D`.
190
- *
191
- * @example
192
- * ```ts
193
- * pipe(These.second("warn"), These.getSecondOrElse(() => "none")); // "warn"
194
- * pipe(These.both(5, "warn"), These.getSecondOrElse(() => "none")); // "warn"
195
- * pipe(These.first(5), These.getSecondOrElse(() => "none")); // "none"
196
- * pipe(These.first(5), These.getSecondOrElse(() => null)); // null — typed as string | null
197
- * ```
198
- */
199
- const getSecondOrElse: <B, D>(defaultValue: () => D) => <A>(data: These<A, B>) => B | D;
200
- /**
201
- * Executes a side effect on the first value without changing the These.
202
- * Useful for logging or debugging.
203
- *
204
- * @example
205
- * ```ts
206
- * pipe(These.first(5), These.tap(console.log)); // logs 5, returns First(5)
207
- * ```
208
- */
209
- const tap: <A>(f: (a: A) => void) => <B>(data: These<A, B>) => These<A, B>;
210
- /**
211
- * Swaps the roles of first and second values.
212
- * - First(a) → Second(a)
213
- * - Second(b) → First(b)
214
- * - Both(a, b) → Both(b, a)
215
- *
216
- * @example
217
- * ```ts
218
- * These.swap(These.first(5)); // Second(5)
219
- * These.swap(These.second("warn")); // First("warn")
220
- * These.swap(These.both(5, "warn")); // Both("warn", 5)
221
- * ```
222
- */
223
- const swap: <A, B>(data: These<A, B>) => These<B, A>;
224
- }
225
- //# sourceMappingURL=These.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"These.d.ts","sourceRoot":"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