@systemfsoftware/effect-atom 0.5.3
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/LICENSE +231 -0
- package/README.md +30 -0
- package/dist/Atom-BgqgP-Qc.d.ts +1287 -0
- package/dist/Atom-BhgqoTsf.mjs +1348 -0
- package/dist/Atom-CxKJ3i4d.d.ts +1257 -0
- package/dist/Atom-DGWqaX9a.d.ts +1257 -0
- package/dist/Atom-DVWTGeoV.mjs +1449 -0
- package/dist/Atom-NsW01Gu1.mjs +1348 -0
- package/dist/Atom.d.ts +2 -0
- package/dist/Atom.mjs +2 -0
- package/dist/AtomHttpApi.d.ts +74 -0
- package/dist/AtomHttpApi.mjs +129 -0
- package/dist/AtomRef.d.ts +91 -0
- package/dist/AtomRef.mjs +248 -0
- package/dist/AtomRpc.d.ts +73 -0
- package/dist/AtomRpc.mjs +111 -0
- package/dist/Hydration.d.ts +75 -0
- package/dist/Hydration.mjs +113 -0
- package/dist/Registry-B1ULaW2_.mjs +769 -0
- package/dist/Registry-BE4aKSZk.mjs +823 -0
- package/dist/Registry-DhP1TSer.mjs +769 -0
- package/dist/Registry.d.ts +2 -0
- package/dist/Registry.mjs +2 -0
- package/dist/Result-B2vSp_sE.d.ts +480 -0
- package/dist/Result-BHH-qTvm.d.ts +491 -0
- package/dist/Result-CAjFdzam.d.ts +490 -0
- package/dist/Result-D8FNEzuX.mjs +633 -0
- package/dist/Result-DwtHFH70.mjs +663 -0
- package/dist/Result-rlUvoHzK.mjs +624 -0
- package/dist/Result.d.ts +2 -0
- package/dist/Result.mjs +2 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.mjs +8 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/package.json +94 -0
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
import * as Cause from "effect/Cause";
|
|
2
|
+
import * as Exit from "effect/Exit";
|
|
3
|
+
import { LazyArg } from "effect/Function";
|
|
4
|
+
import * as Option from "effect/Option";
|
|
5
|
+
import * as Schema_ from "effect/Schema";
|
|
6
|
+
import { Pipeable } from "effect/Pipeable";
|
|
7
|
+
import { Predicate, Refinement } from "effect/Predicate";
|
|
8
|
+
import * as Types from "effect/Types";
|
|
9
|
+
//#region src/internal/result-values.d.ts
|
|
10
|
+
/**
|
|
11
|
+
* Type-level identifier used to recognize `Result` values.
|
|
12
|
+
*
|
|
13
|
+
* @category type IDs
|
|
14
|
+
* @since 4.0.0
|
|
15
|
+
*/
|
|
16
|
+
type TypeId = '~effect-atom/atom/Result';
|
|
17
|
+
/**
|
|
18
|
+
* Runtime identifier attached to `Result` values and used by `isResult`.
|
|
19
|
+
*
|
|
20
|
+
* @category type IDs
|
|
21
|
+
* @since 4.0.0
|
|
22
|
+
*/
|
|
23
|
+
declare const TypeId: TypeId;
|
|
24
|
+
/**
|
|
25
|
+
* Namespace containing the shared prototype shape and type-level helpers for
|
|
26
|
+
* `Result` values. The interface members are declared ahead of their use in
|
|
27
|
+
* the variant interfaces below.
|
|
28
|
+
*
|
|
29
|
+
* @since 4.0.0
|
|
30
|
+
*/
|
|
31
|
+
declare namespace Result {
|
|
32
|
+
/**
|
|
33
|
+
* Common prototype fields implemented by every `Result` variant, including
|
|
34
|
+
* pipeability, the type marker, phantom type members, and the `waiting` flag.
|
|
35
|
+
*
|
|
36
|
+
* @category models
|
|
37
|
+
* @since 4.0.0
|
|
38
|
+
*/
|
|
39
|
+
interface Proto<A, E> extends Pipeable {
|
|
40
|
+
readonly [TypeId]: {
|
|
41
|
+
readonly E: (_: never) => E;
|
|
42
|
+
readonly A: (_: never) => A;
|
|
43
|
+
};
|
|
44
|
+
readonly waiting: boolean;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Extracts the success value type from an `Result`.
|
|
48
|
+
*
|
|
49
|
+
* @category utility types
|
|
50
|
+
* @since 4.0.0
|
|
51
|
+
*/
|
|
52
|
+
type Success<R> = R extends Result<infer A, infer _> ? A : never;
|
|
53
|
+
/**
|
|
54
|
+
* Extracts the failure error type from an `Result`.
|
|
55
|
+
*
|
|
56
|
+
* @category utility types
|
|
57
|
+
* @since 4.0.0
|
|
58
|
+
*/
|
|
59
|
+
type Failure<R> = R extends Result<infer _, infer E> ? E : never;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Represents the state of an asynchronous value as `Initial`, `Success`, or
|
|
63
|
+
* `Failure`, with a `waiting` flag for in-flight refreshes.
|
|
64
|
+
*
|
|
65
|
+
* @category models
|
|
66
|
+
* @since 4.0.0
|
|
67
|
+
*/
|
|
68
|
+
type Result<A, E = never> = Initial<A, E> | Success<A, E> | Failure<A, E>;
|
|
69
|
+
/**
|
|
70
|
+
* Initial `Result` state before a success value or failure cause is available.
|
|
71
|
+
*
|
|
72
|
+
* @category models
|
|
73
|
+
* @since 4.0.0
|
|
74
|
+
*/
|
|
75
|
+
interface Initial<A, E = never> extends Result.Proto<A, E> {
|
|
76
|
+
readonly _tag: 'Initial';
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Successful `Result` containing the current value, its timestamp, and the
|
|
80
|
+
* shared waiting flag.
|
|
81
|
+
*
|
|
82
|
+
* @category models
|
|
83
|
+
* @since 4.0.0
|
|
84
|
+
*/
|
|
85
|
+
interface Success<A, E = never> extends Result.Proto<A, E> {
|
|
86
|
+
readonly _tag: 'Success';
|
|
87
|
+
readonly value: A;
|
|
88
|
+
readonly timestamp: number;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Failed `Result` containing a failure cause and the latest previous success
|
|
92
|
+
* when one is available.
|
|
93
|
+
*
|
|
94
|
+
* @category models
|
|
95
|
+
* @since 4.0.0
|
|
96
|
+
*/
|
|
97
|
+
interface Failure<A, E = never> extends Result.Proto<A, E> {
|
|
98
|
+
readonly _tag: 'Failure';
|
|
99
|
+
readonly cause: Cause.Cause<E>;
|
|
100
|
+
readonly previousSuccess: Option.Option<Success<A, E>>;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Returns `true` when a value is an `Result`.
|
|
104
|
+
*
|
|
105
|
+
* @category guards
|
|
106
|
+
* @since 4.0.0
|
|
107
|
+
*/
|
|
108
|
+
declare const isResult: (u: unknown) => u is Result<unknown, unknown>;
|
|
109
|
+
/**
|
|
110
|
+
* Creates an `Initial` result, optionally marking it as waiting.
|
|
111
|
+
*
|
|
112
|
+
* @category constructors
|
|
113
|
+
* @since 4.0.0
|
|
114
|
+
*/
|
|
115
|
+
declare const initial: <A = never, E = never>(waiting?: boolean) => Initial<A, E>;
|
|
116
|
+
/**
|
|
117
|
+
* Creates a `Success` result with a value and optional `waiting` flag or
|
|
118
|
+
* timestamp override.
|
|
119
|
+
*
|
|
120
|
+
* @category constructors
|
|
121
|
+
* @since 4.0.0
|
|
122
|
+
*/
|
|
123
|
+
declare const success: <A, E = never>(value: A, options?: {
|
|
124
|
+
readonly waiting?: boolean | undefined;
|
|
125
|
+
readonly timestamp?: number | undefined;
|
|
126
|
+
}) => Success<A, E>;
|
|
127
|
+
/**
|
|
128
|
+
* Creates a `Failure` result from a `Cause`, optionally preserving a previous
|
|
129
|
+
* success and marking the result as waiting.
|
|
130
|
+
*
|
|
131
|
+
* @category constructors
|
|
132
|
+
* @since 4.0.0
|
|
133
|
+
*/
|
|
134
|
+
declare const failure: <A, E = never>(cause: Cause.Cause<E>, options?: {
|
|
135
|
+
readonly previousSuccess?: Option.Option<Success<A, E>> | undefined;
|
|
136
|
+
readonly waiting?: boolean | undefined;
|
|
137
|
+
}) => Failure<A, E>;
|
|
138
|
+
//#endregion
|
|
139
|
+
//#region src/internal/result-schema.d.ts
|
|
140
|
+
/**
|
|
141
|
+
* Schema interface for `Result` values, retaining the schemas used for success values and failure errors.
|
|
142
|
+
*
|
|
143
|
+
* @category schemas
|
|
144
|
+
* @since 4.0.0
|
|
145
|
+
*/
|
|
146
|
+
interface Schema<Success extends Schema_.Constraint, Error extends Schema_.Constraint> extends Schema_.declareConstructor<Result<Success['Type'], Error['Type']>, Result<Success['Encoded'], Error['Encoded']>, readonly [Success, Schema_.Cause<Error, Schema_.Defect>]> {
|
|
147
|
+
readonly success: Success;
|
|
148
|
+
readonly error: Error;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Creates a schema for `Result` values using optional schemas for success values and failure errors.
|
|
152
|
+
*
|
|
153
|
+
* @category schemas
|
|
154
|
+
* @since 4.0.0
|
|
155
|
+
*/
|
|
156
|
+
declare const Schema: <A extends Schema_.Constraint = Schema_.Never, E extends Schema_.Constraint = Schema_.Never>(options: {
|
|
157
|
+
readonly success?: A | undefined;
|
|
158
|
+
readonly error?: E | undefined;
|
|
159
|
+
}) => Schema<A, E>;
|
|
160
|
+
declare namespace Result_d_exports {
|
|
161
|
+
export { Builder, Defect, Failure, Initial, Interrupt, Result, Schema, Success, TypeId, With, all, builder, cause, error, fail, failWithPrevious, failure, failureWithPrevious, flatMap, fromExit, fromExitWithPrevious, getOrElse, getOrThrow, initial, isResult as isAsyncResult, isFailure, isInitial, isInterrupted, isNotInitial, isResult, isSuccess, isWaiting, map, match, matchWithError, matchWithWaiting, replacePrevious, success, toExit, touch, value, waiting, waitingFrom };
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Rebuilds an `Result` with new success and failure types while preserving the variant of another result.
|
|
165
|
+
*
|
|
166
|
+
* @category utility types
|
|
167
|
+
* @since 4.0.0
|
|
168
|
+
*/
|
|
169
|
+
type With<R extends Result<any, any>, A, E> = R extends Initial<infer _A, infer _E> ? Initial<A, E> : R extends Success<infer _A, infer _E> ? Success<A, E> : R extends Failure<infer _A, infer _E> ? Failure<A, E> : never;
|
|
170
|
+
/**
|
|
171
|
+
* Returns whether an `Result` is currently waiting for an asynchronous computation or refresh to finish.
|
|
172
|
+
*
|
|
173
|
+
* @category predicates
|
|
174
|
+
* @since 4.0.0
|
|
175
|
+
*/
|
|
176
|
+
declare const isWaiting: <A, E>(result: Result<A, E>) => boolean;
|
|
177
|
+
/**
|
|
178
|
+
* Converts an `Exit` into a `Success` when it succeeds or a `Failure` carrying the exit cause when it fails.
|
|
179
|
+
*
|
|
180
|
+
* @category constructors
|
|
181
|
+
* @since 4.0.0
|
|
182
|
+
*/
|
|
183
|
+
declare const fromExit: <A, E>(exit: Exit.Exit<A, E>) => Success<A, E> | Failure<A, E>;
|
|
184
|
+
/**
|
|
185
|
+
* Converts an `Exit` to a result, preserving the latest previous success when the exit is a failure.
|
|
186
|
+
*
|
|
187
|
+
* @category constructors
|
|
188
|
+
* @since 4.0.0
|
|
189
|
+
*/
|
|
190
|
+
declare const fromExitWithPrevious: <A, E>(exit: Exit.Exit<A, E>, previous: Option.Option<Result<A, E>>) => Success<A, E> | Failure<A, E>;
|
|
191
|
+
/**
|
|
192
|
+
* Creates a waiting result from an optional previous result, using `Initial(true)` when no previous result exists.
|
|
193
|
+
*
|
|
194
|
+
* @category constructors
|
|
195
|
+
* @since 4.0.0
|
|
196
|
+
*/
|
|
197
|
+
declare const waitingFrom: <A, E>(previous: Option.Option<Result<A, E>>) => Result<A, E>;
|
|
198
|
+
/**
|
|
199
|
+
* Returns `true` when an `Result` is in the `Initial` state.
|
|
200
|
+
*
|
|
201
|
+
* @category guards
|
|
202
|
+
* @since 4.0.0
|
|
203
|
+
*/
|
|
204
|
+
declare const isInitial: <A, E>(result: Result<A, E>) => result is Initial<A, E>;
|
|
205
|
+
/**
|
|
206
|
+
* Returns `true` when an `Result` is either `Success` or `Failure`.
|
|
207
|
+
*
|
|
208
|
+
* @category guards
|
|
209
|
+
* @since 4.0.0
|
|
210
|
+
*/
|
|
211
|
+
declare const isNotInitial: <A, E>(result: Result<A, E>) => result is Success<A, E> | Failure<A, E>;
|
|
212
|
+
/**
|
|
213
|
+
* Returns `true` when an `Result` is a `Success`.
|
|
214
|
+
*
|
|
215
|
+
* @category guards
|
|
216
|
+
* @since 4.0.0
|
|
217
|
+
*/
|
|
218
|
+
declare const isSuccess: <A, E>(result: Result<A, E>) => result is Success<A, E>;
|
|
219
|
+
/**
|
|
220
|
+
* Returns `true` when an `Result` is a `Failure`.
|
|
221
|
+
*
|
|
222
|
+
* @category guards
|
|
223
|
+
* @since 4.0.0
|
|
224
|
+
*/
|
|
225
|
+
declare const isFailure: <A, E>(result: Result<A, E>) => result is Failure<A, E>;
|
|
226
|
+
/**
|
|
227
|
+
* Returns `true` when an `Result` is a `Failure` whose cause contains only interruptions.
|
|
228
|
+
*
|
|
229
|
+
* @category guards
|
|
230
|
+
* @since 4.0.0
|
|
231
|
+
*/
|
|
232
|
+
declare const isInterrupted: <A, E>(result: Result<A, E>) => result is Failure<A, E>;
|
|
233
|
+
/**
|
|
234
|
+
* Creates a `Failure` result from a `Cause`, carrying forward the latest success stored in a previous result.
|
|
235
|
+
*
|
|
236
|
+
* @category constructors
|
|
237
|
+
* @since 4.0.0
|
|
238
|
+
*/
|
|
239
|
+
declare const failureWithPrevious: <A, E>(cause: Cause.Cause<E>, options: {
|
|
240
|
+
readonly previous: Option.Option<Result<A, E>>;
|
|
241
|
+
readonly waiting?: boolean | undefined;
|
|
242
|
+
}) => Failure<A, E>;
|
|
243
|
+
/**
|
|
244
|
+
* Creates a `Failure` result from a typed error, wrapping it in `Cause.fail`.
|
|
245
|
+
*
|
|
246
|
+
* @category constructors
|
|
247
|
+
* @since 4.0.0
|
|
248
|
+
*/
|
|
249
|
+
declare const fail: <E, A = never>(error: E, options?: {
|
|
250
|
+
readonly previousSuccess?: Option.Option<Success<A, E>> | undefined;
|
|
251
|
+
readonly waiting?: boolean | undefined;
|
|
252
|
+
}) => Failure<A, E>;
|
|
253
|
+
/**
|
|
254
|
+
* Creates a `Failure` result from a typed error while carrying forward the latest success stored in a previous result.
|
|
255
|
+
*
|
|
256
|
+
* @category constructors
|
|
257
|
+
* @since 4.0.0
|
|
258
|
+
*/
|
|
259
|
+
declare const failWithPrevious: <A, E>(error: E, options: {
|
|
260
|
+
readonly previous: Option.Option<Result<A, E>>;
|
|
261
|
+
readonly waiting?: boolean | undefined;
|
|
262
|
+
}) => Failure<A, E>;
|
|
263
|
+
/**
|
|
264
|
+
* Marks an `Result` as waiting, optionally touching the timestamp when the result is a `Success`.
|
|
265
|
+
*
|
|
266
|
+
* @category constructors
|
|
267
|
+
* @since 4.0.0
|
|
268
|
+
*/
|
|
269
|
+
declare const waiting: <R extends Result<any, any>>(self: R, options?: {
|
|
270
|
+
readonly touch?: boolean | undefined;
|
|
271
|
+
}) => R;
|
|
272
|
+
/**
|
|
273
|
+
* Refreshes the timestamp of a `Success` result while preserving its value and waiting flag; non-success results are returned unchanged.
|
|
274
|
+
*
|
|
275
|
+
* @category combinators
|
|
276
|
+
* @since 4.0.0
|
|
277
|
+
*/
|
|
278
|
+
declare const touch: <A extends Result<any, any>>(result: A) => A;
|
|
279
|
+
/**
|
|
280
|
+
* Replaces a `Failure` value's stored previous success with the latest success
|
|
281
|
+
* found in another result.
|
|
282
|
+
*
|
|
283
|
+
* @category combinators
|
|
284
|
+
* @since 4.0.0
|
|
285
|
+
*/
|
|
286
|
+
declare const replacePrevious: <R extends Result<any, any>, XE, A>(self: R, previous: Option.Option<Result<A, XE>>) => With<R, A, Result.Failure<R>>;
|
|
287
|
+
/**
|
|
288
|
+
* Returns the current success value, or the previous success value stored in a failure, as an `Option`.
|
|
289
|
+
*
|
|
290
|
+
* @category accessors
|
|
291
|
+
* @since 4.0.0
|
|
292
|
+
*/
|
|
293
|
+
declare const value: <A, E>(self: Result<A, E>) => Option.Option<A>;
|
|
294
|
+
/**
|
|
295
|
+
* Returns the available value from `value`, or evaluates the fallback when no current or previous success exists.
|
|
296
|
+
*
|
|
297
|
+
* @category accessors
|
|
298
|
+
* @since 4.0.0
|
|
299
|
+
*/
|
|
300
|
+
declare const getOrElse: {
|
|
301
|
+
<B>(orElse: LazyArg<B>): <A, E>(self: Result<A, E>) => A | B;
|
|
302
|
+
<A, E, B>(self: Result<A, E>, orElse: LazyArg<B>): A | B;
|
|
303
|
+
};
|
|
304
|
+
/**
|
|
305
|
+
* Returns the available value from `value`, or throws `NoSuchElementError` when no current or previous success exists.
|
|
306
|
+
*
|
|
307
|
+
* @category accessors
|
|
308
|
+
* @since 4.0.0
|
|
309
|
+
*/
|
|
310
|
+
declare const getOrThrow: <A, E>(self: Result<A, E>) => A;
|
|
311
|
+
/**
|
|
312
|
+
* Returns the failure cause when the result is a `Failure`, otherwise `None`.
|
|
313
|
+
*
|
|
314
|
+
* @category accessors
|
|
315
|
+
* @since 4.0.0
|
|
316
|
+
*/
|
|
317
|
+
declare const cause: <A, E>(self: Result<A, E>) => Option.Option<Cause.Cause<E>>;
|
|
318
|
+
/**
|
|
319
|
+
* Returns the first typed error from a failure cause, or `None` for successes, initial results, defects, and interrupt-only causes.
|
|
320
|
+
*
|
|
321
|
+
* @category accessors
|
|
322
|
+
* @since 4.0.0
|
|
323
|
+
*/
|
|
324
|
+
declare const error: <A, E>(self: Result<A, E>) => Option.Option<E>;
|
|
325
|
+
/**
|
|
326
|
+
* Converts a result to an `Exit`, succeeding with a success value, failing with a failure cause, or failing with `NoSuchElementError` for `Initial`.
|
|
327
|
+
*
|
|
328
|
+
* @category combinators
|
|
329
|
+
* @since 4.0.0
|
|
330
|
+
*/
|
|
331
|
+
declare const toExit: {
|
|
332
|
+
<A, E>(self: Success<A, E> | Failure<A, E>): Exit.Exit<A, E>;
|
|
333
|
+
<A, E>(self: Result<A, E>): Exit.Exit<A, E | Cause.NoSuchElementError>;
|
|
334
|
+
};
|
|
335
|
+
/**
|
|
336
|
+
* Maps the success value of an `Result`, also mapping any previous success stored in a failure while leaving initial results unchanged.
|
|
337
|
+
*
|
|
338
|
+
* @category combinators
|
|
339
|
+
* @since 4.0.0
|
|
340
|
+
*/
|
|
341
|
+
declare const map: {
|
|
342
|
+
<A, B>(f: (a: A) => B): <E>(self: Result<A, E>) => Result<B, E>;
|
|
343
|
+
<E, A, B>(self: Result<A, E>, f: (a: A) => B): Result<B, E>;
|
|
344
|
+
};
|
|
345
|
+
/**
|
|
346
|
+
* Maps the success value of an `Result` and flattens the result.
|
|
347
|
+
*
|
|
348
|
+
* **When to use**
|
|
349
|
+
*
|
|
350
|
+
* Use to sequence computations that may return another `Result` while
|
|
351
|
+
* preserving initial and failure states.
|
|
352
|
+
*
|
|
353
|
+
* **Details**
|
|
354
|
+
*
|
|
355
|
+
* Initial results are left unchanged. Failures preserve their cause and remap
|
|
356
|
+
* the stored previous success when the mapping function returns a success.
|
|
357
|
+
*
|
|
358
|
+
* @category combinators
|
|
359
|
+
* @since 4.0.0
|
|
360
|
+
*/
|
|
361
|
+
declare const flatMap: {
|
|
362
|
+
<A, E, B, E2>(f: (a: A, prev: Success<A, E>) => Result<B, E2>): (self: Result<A, E>) => Result<B, E | E2>;
|
|
363
|
+
<E, A, B, E2>(self: Result<A, E>, f: (a: A, prev: Success<A, E>) => Result<B, E2>): Result<B, E | E2>;
|
|
364
|
+
};
|
|
365
|
+
/**
|
|
366
|
+
* Pattern matches an `Result` by calling the handler for `Initial`, `Failure`, or `Success`.
|
|
367
|
+
*
|
|
368
|
+
* @category combinators
|
|
369
|
+
* @since 4.0.0
|
|
370
|
+
*/
|
|
371
|
+
declare const match: {
|
|
372
|
+
<A, E, X, Y, Z>(options: {
|
|
373
|
+
readonly onInitial: (_: Initial<A, E>) => X;
|
|
374
|
+
readonly onFailure: (_: Failure<A, E>) => Y;
|
|
375
|
+
readonly onSuccess: (_: Success<A, E>) => Z;
|
|
376
|
+
}): (self: Result<A, E>) => X | Y | Z;
|
|
377
|
+
<A, E, X, Y, Z>(self: Result<A, E>, options: {
|
|
378
|
+
readonly onInitial: (_: Initial<A, E>) => X;
|
|
379
|
+
readonly onFailure: (_: Failure<A, E>) => Y;
|
|
380
|
+
readonly onSuccess: (_: Success<A, E>) => Z;
|
|
381
|
+
}): X | Y | Z;
|
|
382
|
+
};
|
|
383
|
+
/**
|
|
384
|
+
* Pattern matches a result, handling successes and initials directly while splitting failures into typed errors or squashed non-error causes passed to `onDefect`.
|
|
385
|
+
*
|
|
386
|
+
* @category combinators
|
|
387
|
+
* @since 4.0.0
|
|
388
|
+
*/
|
|
389
|
+
declare const matchWithError: {
|
|
390
|
+
<A, E, W, X, Y, Z>(options: {
|
|
391
|
+
readonly onInitial: (_: Initial<A, E>) => W;
|
|
392
|
+
readonly onError: (error: E, _: Failure<A, E>) => X;
|
|
393
|
+
readonly onDefect: (defect: unknown, _: Failure<A, E>) => Y;
|
|
394
|
+
readonly onSuccess: (_: Success<A, E>) => Z;
|
|
395
|
+
}): (self: Result<A, E>) => W | X | Y | Z;
|
|
396
|
+
<A, E, W, X, Y, Z>(self: Result<A, E>, options: {
|
|
397
|
+
readonly onInitial: (_: Initial<A, E>) => W;
|
|
398
|
+
readonly onError: (error: E, _: Failure<A, E>) => X;
|
|
399
|
+
readonly onDefect: (defect: unknown, _: Failure<A, E>) => Y;
|
|
400
|
+
readonly onSuccess: (_: Success<A, E>) => Z;
|
|
401
|
+
}): W | X | Y | Z;
|
|
402
|
+
};
|
|
403
|
+
/**
|
|
404
|
+
* Pattern matches a result by calling `onWaiting` for waiting or initial states, otherwise handling successes and splitting failures into typed errors or squashed non-error causes.
|
|
405
|
+
*
|
|
406
|
+
* @category combinators
|
|
407
|
+
* @since 4.0.0
|
|
408
|
+
*/
|
|
409
|
+
declare const matchWithWaiting: {
|
|
410
|
+
<A, E, W, X, Y, Z>(options: {
|
|
411
|
+
readonly onWaiting: (_: Result<A, E>) => W;
|
|
412
|
+
readonly onError: (error: E, _: Failure<A, E>) => X;
|
|
413
|
+
readonly onDefect: (defect: unknown, _: Failure<A, E>) => Y;
|
|
414
|
+
readonly onSuccess: (_: Success<A, E>) => Z;
|
|
415
|
+
}): (self: Result<A, E>) => W | X | Y | Z;
|
|
416
|
+
<A, E, W, X, Y, Z>(self: Result<A, E>, options: {
|
|
417
|
+
readonly onWaiting: (_: Result<A, E>) => W;
|
|
418
|
+
readonly onError: (error: E, _: Failure<A, E>) => X;
|
|
419
|
+
readonly onDefect: (defect: unknown, _: Failure<A, E>) => Y;
|
|
420
|
+
readonly onSuccess: (_: Success<A, E>) => Z;
|
|
421
|
+
}): W | X | Y | Z;
|
|
422
|
+
};
|
|
423
|
+
/**
|
|
424
|
+
* Combines an iterable or record of `Result` and plain values into one `Result`, returning the first non-success result or a success of the collected values marked waiting when any input success is waiting.
|
|
425
|
+
*
|
|
426
|
+
* @category combinators
|
|
427
|
+
* @since 4.0.0
|
|
428
|
+
*/
|
|
429
|
+
type AllSuccess<Arg> = [Arg] extends [readonly any[]] ? { -readonly [K in keyof Arg]: [Arg[K]] extends [Result<infer _A, infer _E>] ? _A : Arg[K]; } : [Arg] extends [Iterable<infer _A>] ? _A extends Result<infer _AA, infer _E> ? _AA : _A : [Arg] extends [Record<string, any>] ? { -readonly [K in keyof Arg]: [Arg[K]] extends [Result<infer _A, infer _E>] ? _A : Arg[K]; } : never;
|
|
430
|
+
type AllError<Arg> = [Arg] extends [readonly any[]] ? Result.Failure<Arg[number]> : [Arg] extends [Iterable<infer _A>] ? Result.Failure<_A> : [Arg] extends [Record<string, any>] ? Result.Failure<Arg[keyof Arg]> : never;
|
|
431
|
+
declare const all: <const Arg extends Iterable<any> | Record<string, any>>(results: Arg) => Result<AllSuccess<Arg>, AllError<Arg>>;
|
|
432
|
+
/**
|
|
433
|
+
* Creates a typed builder for rendering an `Result` by handling waiting, initial, success, error, defect, interrupt, and failure cases.
|
|
434
|
+
*
|
|
435
|
+
* @category constructors
|
|
436
|
+
* @since 4.0.0
|
|
437
|
+
*/
|
|
438
|
+
type BuilderFor<A extends Result<any, any>> = Builder<never, A extends Success<infer _A, infer _E> ? _A : never, A extends Failure<infer _A, infer _E> ? _E : never, A extends Initial<infer _A, infer _E> ? true : never, A extends Failure<infer _A, infer _E> ? Defect | Interrupt : never>;
|
|
439
|
+
declare const builder: <A extends Result<any, any>>(self: A) => BuilderFor<A>;
|
|
440
|
+
/**
|
|
441
|
+
* Type marker used by `Builder` to track whether defect failures still need to be handled.
|
|
442
|
+
*
|
|
443
|
+
* @category utility types
|
|
444
|
+
* @since 4.0.0
|
|
445
|
+
*/
|
|
446
|
+
interface Defect {
|
|
447
|
+
readonly _: unique symbol;
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Type marker used by `Builder` to track whether interrupt failures still need to be handled.
|
|
451
|
+
*
|
|
452
|
+
* @category utility types
|
|
453
|
+
* @since 4.0.0
|
|
454
|
+
*/
|
|
455
|
+
interface Interrupt {
|
|
456
|
+
readonly _: unique symbol;
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Fluent renderer for `Result` values that tracks unhandled cases at the type level and exposes `exhaustive` only after all possible cases are handled.
|
|
460
|
+
*
|
|
461
|
+
* @category models
|
|
462
|
+
* @since 4.0.0
|
|
463
|
+
*/
|
|
464
|
+
type Builder<Out, A, E, I, F> = Pipeable & {
|
|
465
|
+
onWaiting<B>(f: (result: Result<A, E>) => B): Builder<Out | B, A, E, I, F>;
|
|
466
|
+
orElse<B>(orElse: LazyArg<B>): Out | B;
|
|
467
|
+
orNull(): Out | null;
|
|
468
|
+
render(): [A | I] extends [never] ? Out : Out | null;
|
|
469
|
+
} & ([A | E | I | F] extends [never] ? {
|
|
470
|
+
exhaustive(): Out;
|
|
471
|
+
} : unknown) & ([I] extends [never] ? unknown : {
|
|
472
|
+
onInitial<B>(f: (result: Initial<A, E>) => B): Builder<Out | B, A, E, never, F>;
|
|
473
|
+
onInitialOrWaiting<B>(f: (result: Result<A, E>) => B): Builder<Out | B, A, E, never, F>;
|
|
474
|
+
}) & ([A] extends [never] ? unknown : {
|
|
475
|
+
onSuccess<B>(f: (value: A, result: Success<A, E>) => B): Builder<Out | B, never, E, I, F>;
|
|
476
|
+
}) & ([E] extends [never] ? unknown : {
|
|
477
|
+
onError<B>(f: (error: E, result: Failure<A, E>) => B): Builder<Out | B, A, never, I, F>;
|
|
478
|
+
onErrorIf<B extends E, C>(refinement: Refinement<E, B>, f: (error: B, result: Failure<A, E>) => C): Builder<Out | C, A, Types.EqualsWith<E, B, E, Exclude<E, B>>, I, F>;
|
|
479
|
+
onErrorIf<C>(predicate: Predicate<E>, f: (error: E, result: Failure<A, E>) => C): Builder<Out | C, A, E, I, F>;
|
|
480
|
+
onErrorTag<const Tags extends readonly Types.Tags<E>[], B>(tags: Tags, f: (error: Types.ExtractTag<E, Tags[number]>, result: Failure<A, E>) => B): Builder<Out | B, A, Types.ExcludeTag<E, Tags[number]>, I, F>;
|
|
481
|
+
onErrorTag<const Tag extends Types.Tags<E>, B>(tag: Tag, f: (error: Types.ExtractTag<E, Tag>, result: Failure<A, E>) => B): Builder<Out | B, A, Types.ExcludeTag<E, Tag>, I, F>;
|
|
482
|
+
}) & ([E | F] extends [never] ? unknown : {
|
|
483
|
+
onFailure<B>(f: (cause: Cause.Cause<E>, result: Failure<A, E>) => B): Builder<Out | B, A, never, I, never>;
|
|
484
|
+
}) & (Interrupt extends F ? {
|
|
485
|
+
onInterrupt<B>(f: (interruptors: ReadonlySet<number>, result: Failure<A, E>) => B): Builder<Out | B, A, E, I, Exclude<F, Interrupt>>;
|
|
486
|
+
} : unknown) & (Defect extends F ? {
|
|
487
|
+
onDefect<B>(f: (defect: unknown, result: Failure<A, E>) => B): Builder<Out | B, A, E, I, Exclude<F, Defect>>;
|
|
488
|
+
} : unknown);
|
|
489
|
+
//#endregion
|
|
490
|
+
export { touch as A, failure as B, isWaiting as C, matchWithWaiting as D, matchWithError as E, Failure as F, isResult as H, Initial as I, Result as L, waiting as M, waitingFrom as N, replacePrevious as O, Schema as P, Success as R, isSuccess as S, match as T, success as U, initial as V, getOrThrow as _, With as a, isInterrupted as b, cause as c, failWithPrevious as d, failureWithPrevious as f, getOrElse as g, fromExitWithPrevious as h, Result_d_exports as i, value as j, toExit as k, error as l, fromExit as m, Defect as n, all as o, flatMap as p, Interrupt as r, builder as s, Builder as t, fail as u, isFailure as v, map as w, isNotInitial as x, isInitial as y, TypeId as z };
|