@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.
@@ -0,0 +1,624 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
+ import * as Cause from "effect/Cause";
3
+ import * as Effect from "effect/Effect";
4
+ import * as Exit from "effect/Exit";
5
+ import { constTrue, dual, identity } from "effect/Function";
6
+ import * as Option from "effect/Option";
7
+ import * as Schema_ from "effect/Schema";
8
+ import { pipeArguments } from "effect/Pipeable";
9
+ import { hasProperty, isIterable, isTagged } from "effect/Predicate";
10
+ import * as Either from "effect/Result";
11
+ import * as Match from "effect/Match";
12
+ import * as Clock from "effect/Clock";
13
+ import * as Equal$1 from "effect/Equal";
14
+ import * as Hash from "effect/Hash";
15
+ import * as SchemaIssue from "effect/SchemaIssue";
16
+ import * as SchemaParser from "effect/SchemaParser";
17
+ import * as SchemaTransformation from "effect/SchemaTransformation";
18
+ //#region src/internal/ResultValues.ts
19
+ const now = () => Effect.runSync(Clock.currentTimeMillis);
20
+ /**
21
+ * Runtime identifier attached to `Result` values and used by `isResult`.
22
+ *
23
+ * @category type IDs
24
+ * @since 4.0.0
25
+ */
26
+ const TypeId = "~effect-atom/atom/Result";
27
+ /**
28
+ * Shared prototype every `Result` variant inherits from. The three
29
+ * constructors (`initial`, `success`, `failure`) use it; `waiting` in
30
+ * `Result.ts` also reaches it directly.
31
+ *
32
+ * The schema codec (`internal/result-schema.ts`) serializes only the tagged
33
+ * variant fields (`value`, `waiting`, `timestamp`, `cause`,
34
+ * `previousSuccess`) — nothing added to this prototype is wire-carried, so
35
+ * any future proto-private state must be mirrored in that encode/decode pair.
36
+ *
37
+ * @since 4.0.0
38
+ */
39
+ const ResultProto = {
40
+ [TypeId]: {
41
+ E: identity,
42
+ A: identity
43
+ },
44
+ pipe() {
45
+ return pipeArguments(this, arguments);
46
+ },
47
+ [Equal$1.symbol](that) {
48
+ if (this.waiting !== that.waiting) return false;
49
+ return Match.value(this).pipe(Match.tag("Initial", () => Match.value(that).pipe(Match.tag("Initial", () => true), Match.orElse(() => false))), Match.tag("Success", (s) => Match.value(that).pipe(Match.tag("Success", (t) => Equal$1.equals(s.value, t.value)), Match.orElse(() => false))), Match.tag("Failure", (f) => Match.value(that).pipe(Match.tag("Failure", (g) => Equal$1.equals(f.cause, g.cause)), Match.orElse(() => false))), Match.exhaustive);
50
+ },
51
+ [Hash.symbol]() {
52
+ const tagHash = Hash.string(`${this._tag}:${this.waiting}`);
53
+ return Match.value(this).pipe(Match.tag("Initial", () => tagHash), Match.tag("Success", (s) => Hash.combine(tagHash)(Hash.hash(s.value))), Match.tag("Failure", (f) => Hash.combine(tagHash)(Hash.hash(f.cause))), Match.exhaustive);
54
+ }
55
+ };
56
+ /**
57
+ * Returns `true` when a value is an `Result`.
58
+ *
59
+ * @category guards
60
+ * @since 4.0.0
61
+ */
62
+ const isResult = (u) => hasProperty(u, TypeId);
63
+ /**
64
+ * Creates an `Initial` result, optionally marking it as waiting.
65
+ *
66
+ * @category constructors
67
+ * @since 4.0.0
68
+ */
69
+ const initial = (waiting = false) => {
70
+ return {
71
+ ...ResultProto,
72
+ _tag: "Initial",
73
+ waiting
74
+ };
75
+ };
76
+ /**
77
+ * Creates a `Success` result with a value and optional `waiting` flag or
78
+ * timestamp override.
79
+ *
80
+ * @category constructors
81
+ * @since 4.0.0
82
+ */
83
+ const success = (value, options) => {
84
+ return {
85
+ ...ResultProto,
86
+ _tag: "Success",
87
+ value,
88
+ waiting: options?.waiting ?? false,
89
+ timestamp: options?.timestamp ?? now()
90
+ };
91
+ };
92
+ /**
93
+ * Creates a `Failure` result from a `Cause`, optionally preserving a previous
94
+ * success and marking the result as waiting.
95
+ *
96
+ * @category constructors
97
+ * @since 4.0.0
98
+ */
99
+ const failure = (cause, options) => {
100
+ return {
101
+ ...ResultProto,
102
+ _tag: "Failure",
103
+ cause,
104
+ ...options?.previousSuccess === void 0 ? { previousSuccess: Option.none() } : { previousSuccess: options.previousSuccess },
105
+ waiting: options?.waiting ?? false
106
+ };
107
+ };
108
+ //#endregion
109
+ //#region src/internal/ResultSchema.ts
110
+ /**
111
+ * Creates a schema for `Result` values using optional schemas for success values and failure errors.
112
+ *
113
+ * @category schemas
114
+ * @since 4.0.0
115
+ */
116
+ const Schema = (options) => {
117
+ const success_ = options.success ?? Schema_.Never;
118
+ const error_ = options.error ?? Schema_.Never;
119
+ const schema = Schema_.declareConstructor()([success_, Schema_.Cause(error_, Schema_.Defect())], ([value, cause]) => (input, ast, options) => {
120
+ if (!isResult(input)) return Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
121
+ if (!hasProperty(input, "value") && !hasProperty(input, "cause")) return Effect.succeed(initial(input.waiting));
122
+ if (hasProperty(input, "cause")) {
123
+ const prevSuccessEffect = input.previousSuccess.pipe(Option.map((ps) => Effect.mapBothEager(SchemaParser.decodeUnknownEffect(value)(ps.value, options), {
124
+ onSuccess: (value) => Option.some(success(value, ps)),
125
+ onFailure: (issue) => new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["previousSuccess", "value"], issue)], input, options)
126
+ })), Option.getOrElse(() => Effect.succeedNone));
127
+ const causeEffect = Effect.mapErrorEager(SchemaParser.decodeUnknownEffect(cause)(input.cause, options), (issue) => new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["cause"], issue)], input, options));
128
+ return Effect.flatMapEager(prevSuccessEffect, (previousSuccess) => Effect.mapEager(causeEffect, (cause) => failure(cause, {
129
+ previousSuccess,
130
+ waiting: input.waiting
131
+ })));
132
+ }
133
+ return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(value)(input.value, options), {
134
+ onSuccess: (value) => success(value, input),
135
+ onFailure: (issue) => new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["value"], issue)], input, options)
136
+ });
137
+ }, {
138
+ expected: "Result",
139
+ toCodec([value, cause]) {
140
+ const SuccessSchema = Schema_.TaggedStruct("Success", {
141
+ value,
142
+ waiting: Schema_.Boolean,
143
+ timestamp: Schema_.Finite
144
+ });
145
+ return Schema_.link()(Schema_.Union([
146
+ Schema_.TaggedStruct("Initial", { waiting: Schema_.Boolean }),
147
+ SuccessSchema,
148
+ Schema_.TaggedStruct("Failure", {
149
+ cause,
150
+ previousSuccess: Schema_.Option(SuccessSchema),
151
+ waiting: Schema_.Boolean
152
+ })
153
+ ]), SchemaTransformation.transform({
154
+ decode: (encoded) => {
155
+ if (hasProperty(encoded, "value")) return success(encoded.value, {
156
+ waiting: encoded.waiting,
157
+ timestamp: encoded.timestamp
158
+ });
159
+ if (hasProperty(encoded, "cause")) return failure(encoded.cause, {
160
+ previousSuccess: Option.map(encoded.previousSuccess, (ps) => success(ps.value, ps)),
161
+ waiting: encoded.waiting
162
+ });
163
+ return initial(encoded.waiting);
164
+ },
165
+ encode(result) {
166
+ if (hasProperty(result, "value")) return {
167
+ _tag: "Success",
168
+ value: result.value,
169
+ waiting: result.waiting,
170
+ timestamp: result.timestamp
171
+ };
172
+ if (hasProperty(result, "cause")) return {
173
+ _tag: "Failure",
174
+ cause: result.cause,
175
+ previousSuccess: result.previousSuccess,
176
+ waiting: result.waiting
177
+ };
178
+ return {
179
+ _tag: "Initial",
180
+ waiting: result.waiting
181
+ };
182
+ }
183
+ }));
184
+ },
185
+ toEquivalence: Equal$1.asEquivalence,
186
+ toArbitrary: () => (fc) => fc.constant(initial(false)),
187
+ toFormatter: ([value, cause]) => (t) => {
188
+ if (hasProperty(t, "value")) return `Result.Success(${value(t.value)}, ${t.waiting}, ${t.timestamp})`;
189
+ if (hasProperty(t, "cause")) return `Result.Failure(${cause(t.cause)}, ${t.waiting})`;
190
+ return `Result.Initial(${t.waiting})`;
191
+ }
192
+ });
193
+ return Object.assign(schema, {
194
+ success: success_,
195
+ error: error_
196
+ });
197
+ };
198
+ /**
199
+ * A codec for `Result` values built from the given success and error schemas.
200
+ *
201
+ * @internal
202
+ */
203
+ const schemaCodec = (success, error) => Schema({
204
+ success,
205
+ error
206
+ });
207
+ //#endregion
208
+ //#region src/Result.ts
209
+ /**
210
+ * Represents observable state for asynchronous values.
211
+ *
212
+ * `Result<A, E>` records whether asynchronous work has no value yet,
213
+ * succeeded with an `A`, or failed with an `E`. Every state also carries a
214
+ * `waiting` flag, so callers can keep showing the current value while newer
215
+ * work is loading, refreshing, retrying, or recovering. This module includes
216
+ * constructors, checks, accessors, mapping and matching helpers, ways to combine
217
+ * several results, and schemas for encoding or decoding results.
218
+ *
219
+ * @since 4.0.0
220
+ */
221
+ var Result_exports = /* @__PURE__ */ __exportAll({
222
+ Schema: () => Schema,
223
+ TypeId: () => TypeId,
224
+ all: () => all,
225
+ builder: () => builder,
226
+ cause: () => cause,
227
+ error: () => error,
228
+ fail: () => fail,
229
+ failWithPrevious: () => failWithPrevious,
230
+ failure: () => failure,
231
+ failureWithPrevious: () => failureWithPrevious,
232
+ flatMap: () => flatMap,
233
+ fromExit: () => fromExit,
234
+ fromExitWithPrevious: () => fromExitWithPrevious,
235
+ getOrElse: () => getOrElse,
236
+ getOrThrow: () => getOrThrow,
237
+ initial: () => initial,
238
+ isAsyncResult: () => isResult,
239
+ isFailure: () => isFailure,
240
+ isInitial: () => isInitial,
241
+ isInterrupted: () => isInterrupted,
242
+ isNotInitial: () => isNotInitial,
243
+ isResult: () => isResult,
244
+ isSuccess: () => isSuccess,
245
+ isWaiting: () => isWaiting,
246
+ map: () => map,
247
+ match: () => match,
248
+ matchWithError: () => matchWithError,
249
+ matchWithWaiting: () => matchWithWaiting,
250
+ replacePrevious: () => replacePrevious,
251
+ success: () => success,
252
+ toExit: () => toExit,
253
+ touch: () => touch,
254
+ value: () => value,
255
+ waiting: () => waiting,
256
+ waitingFrom: () => waitingFrom
257
+ });
258
+ /**
259
+ * Returns whether an `Result` is currently waiting for an asynchronous computation or refresh to finish.
260
+ *
261
+ * @category predicates
262
+ * @since 4.0.0
263
+ */
264
+ const isWaiting = (result) => result.waiting;
265
+ /**
266
+ * Converts an `Exit` into a `Success` when it succeeds or a `Failure` carrying the exit cause when it fails.
267
+ *
268
+ * @category constructors
269
+ * @since 4.0.0
270
+ */
271
+ const fromExit = (exit) => Exit.isSuccess(exit) ? success(exit.value) : failure(exit.cause);
272
+ /**
273
+ * Converts an `Exit` to a result, preserving the latest previous success when the exit is a failure.
274
+ *
275
+ * @category constructors
276
+ * @since 4.0.0
277
+ */
278
+ const fromExitWithPrevious = (exit, previous) => Exit.isSuccess(exit) ? success(exit.value) : failureWithPrevious(exit.cause, { previous });
279
+ /**
280
+ * Creates a waiting result from an optional previous result, using `Initial(true)` when no previous result exists.
281
+ *
282
+ * @category constructors
283
+ * @since 4.0.0
284
+ */
285
+ const waitingFrom = (previous) => {
286
+ if (Option.isNone(previous)) return initial(true);
287
+ return waiting(previous.value);
288
+ };
289
+ /**
290
+ * Returns `true` when an `Result` is in the `Initial` state.
291
+ *
292
+ * @category guards
293
+ * @since 4.0.0
294
+ */
295
+ const isInitial = (result) => isTagged(result, "Initial");
296
+ /**
297
+ * Returns `true` when an `Result` is either `Success` or `Failure`.
298
+ *
299
+ * @category guards
300
+ * @since 4.0.0
301
+ */
302
+ const isNotInitial = (result) => !isInitial(result);
303
+ /**
304
+ * Returns `true` when an `Result` is a `Success`.
305
+ *
306
+ * @category guards
307
+ * @since 4.0.0
308
+ */
309
+ const isSuccess = (result) => isTagged(result, "Success");
310
+ /**
311
+ * Returns `true` when an `Result` is a `Failure`.
312
+ *
313
+ * @category guards
314
+ * @since 4.0.0
315
+ */
316
+ const isFailure = (result) => isTagged(result, "Failure");
317
+ /**
318
+ * Returns `true` when an `Result` is a `Failure` whose cause contains only interruptions.
319
+ *
320
+ * @category guards
321
+ * @since 4.0.0
322
+ */
323
+ const isInterrupted = (result) => isFailure(result) && Cause.hasInterruptsOnly(result.cause);
324
+ /**
325
+ * Creates a `Failure` result from a `Cause`, carrying forward the latest success stored in a previous result.
326
+ *
327
+ * @category constructors
328
+ * @since 4.0.0
329
+ */
330
+ const failureWithPrevious = (cause, options) => failure(cause, {
331
+ previousSuccess: Option.flatMap(options.previous, (result) => isSuccess(result) ? Option.some(result) : isFailure(result) ? result.previousSuccess : Option.none()),
332
+ waiting: options.waiting
333
+ });
334
+ /**
335
+ * Creates a `Failure` result from a typed error, wrapping it in `Cause.fail`.
336
+ *
337
+ * @category constructors
338
+ * @since 4.0.0
339
+ */
340
+ const fail = (error, options) => failure(Cause.fail(error), options);
341
+ /**
342
+ * Creates a `Failure` result from a typed error while carrying forward the latest success stored in a previous result.
343
+ *
344
+ * @category constructors
345
+ * @since 4.0.0
346
+ */
347
+ const failWithPrevious = (error, options) => failureWithPrevious(Cause.fail(error), options);
348
+ /**
349
+ * Marks an `Result` as waiting, optionally touching the timestamp when the result is a `Success`.
350
+ *
351
+ * @category constructors
352
+ * @since 4.0.0
353
+ */
354
+ const waiting = (self, options) => {
355
+ if (self.waiting) return options?.touch ? touch(self) : self;
356
+ const result = {
357
+ ...self,
358
+ waiting: true
359
+ };
360
+ return options?.touch ? touch(result) : result;
361
+ };
362
+ /**
363
+ * Refreshes the timestamp of a `Success` result while preserving its value and waiting flag; non-success results are returned unchanged.
364
+ *
365
+ * @category combinators
366
+ * @since 4.0.0
367
+ */
368
+ const touch = (result) => {
369
+ if (isSuccess(result)) return {
370
+ ...result,
371
+ timestamp: Effect.runSync(Clock.currentTimeMillis)
372
+ };
373
+ return result;
374
+ };
375
+ function replacePrevious(self, previous) {
376
+ return isFailure(self) ? failureWithPrevious(self.cause, {
377
+ previous,
378
+ waiting: self.waiting
379
+ }) : self;
380
+ }
381
+ /**
382
+ * Returns the current success value, or the previous success value stored in a failure, as an `Option`.
383
+ *
384
+ * @category accessors
385
+ * @since 4.0.0
386
+ */
387
+ const value = (self) => {
388
+ if (isSuccess(self)) return Option.some(self.value);
389
+ if (isFailure(self)) return Option.map(self.previousSuccess, (s) => s.value);
390
+ return Option.none();
391
+ };
392
+ /**
393
+ * Returns the available value from `value`, or evaluates the fallback when no current or previous success exists.
394
+ *
395
+ * @category accessors
396
+ * @since 4.0.0
397
+ */
398
+ const getOrElse = dual(2, (self, orElse) => Option.getOrElse(value(self), orElse));
399
+ /**
400
+ * Returns the available value from `value`, or throws `NoSuchElementError` when no current or previous success exists.
401
+ *
402
+ * @category accessors
403
+ * @since 4.0.0
404
+ */
405
+ const getOrThrow = (self) => Option.getOrThrowWith(value(self), () => new Cause.NoSuchElementError("Result.getOrThrow: no value found"));
406
+ /**
407
+ * Returns the failure cause when the result is a `Failure`, otherwise `None`.
408
+ *
409
+ * @category accessors
410
+ * @since 4.0.0
411
+ */
412
+ const cause = (self) => isFailure(self) ? Option.some(self.cause) : Option.none();
413
+ /**
414
+ * Returns the first typed error from a failure cause, or `None` for successes, initial results, defects, and interrupt-only causes.
415
+ *
416
+ * @category accessors
417
+ * @since 4.0.0
418
+ */
419
+ const error = (self) => isFailure(self) ? Cause.findErrorOption(self.cause) : Option.none();
420
+ /**
421
+ * Converts a result to an `Exit`, succeeding with a success value, failing with a failure cause, or failing with `NoSuchElementError` for `Initial`.
422
+ *
423
+ * @category combinators
424
+ * @since 4.0.0
425
+ */
426
+ const toExit = (self) => {
427
+ if (isSuccess(self)) return Exit.succeed(self.value);
428
+ if (isFailure(self)) return Exit.failCause(self.cause);
429
+ return Exit.fail(new Cause.NoSuchElementError());
430
+ };
431
+ /**
432
+ * Maps the success value of an `Result`, also mapping any previous success stored in a failure while leaving initial results unchanged.
433
+ *
434
+ * @category combinators
435
+ * @since 4.0.0
436
+ */
437
+ const map = dual(2, (self, f) => {
438
+ if (isSuccess(self)) return success(f(self.value), self);
439
+ if (isFailure(self)) return failure(self.cause, {
440
+ previousSuccess: Option.map(self.previousSuccess, (s) => success(f(s.value), s)),
441
+ waiting: self.waiting
442
+ });
443
+ return initial(self.waiting);
444
+ });
445
+ /**
446
+ * Maps the success value of an `Result` and flattens the result.
447
+ *
448
+ * **When to use**
449
+ *
450
+ * Use to sequence computations that may return another `Result` while
451
+ * preserving initial and failure states.
452
+ *
453
+ * **Details**
454
+ *
455
+ * Initial results are left unchanged. Failures preserve their cause and remap
456
+ * the stored previous success when the mapping function returns a success.
457
+ *
458
+ * @category combinators
459
+ * @since 4.0.0
460
+ */
461
+ const flatMap = dual(2, (self, f) => {
462
+ if (isSuccess(self)) return f(self.value, self);
463
+ if (isFailure(self)) return failure(self.cause, {
464
+ previousSuccess: Option.flatMap(self.previousSuccess, (s) => {
465
+ const next = f(s.value, s);
466
+ return isSuccess(next) ? Option.some(next) : Option.none();
467
+ }),
468
+ waiting: self.waiting
469
+ });
470
+ return initial(self.waiting);
471
+ });
472
+ /**
473
+ * Pattern matches an `Result` by calling the handler for `Initial`, `Failure`, or `Success`.
474
+ *
475
+ * @category combinators
476
+ * @since 4.0.0
477
+ */
478
+ const match = dual(2, (self, options) => {
479
+ if (isSuccess(self)) return options.onSuccess(self);
480
+ if (isFailure(self)) return options.onFailure(self);
481
+ return options.onInitial(self);
482
+ });
483
+ /**
484
+ * Pattern matches a result, handling successes and initials directly while splitting failures into typed errors or squashed non-error causes passed to `onDefect`.
485
+ *
486
+ * @category combinators
487
+ * @since 4.0.0
488
+ */
489
+ const matchWithError = dual(2, (self, options) => {
490
+ if (isSuccess(self)) return options.onSuccess(self);
491
+ if (isFailure(self)) {
492
+ const result = Cause.findError(self.cause);
493
+ if (Either.isFailure(result)) return options.onDefect(Cause.squash(result.failure), self);
494
+ return options.onError(result.success, self);
495
+ }
496
+ return options.onInitial(self);
497
+ });
498
+ /**
499
+ * 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.
500
+ *
501
+ * @category combinators
502
+ * @since 4.0.0
503
+ */
504
+ const matchWithWaiting = dual(2, (self, options) => {
505
+ if (self.waiting) return options.onWaiting(self);
506
+ if (isSuccess(self)) return options.onSuccess(self);
507
+ if (isFailure(self)) {
508
+ const e = Cause.findError(self.cause);
509
+ if (Either.isFailure(e)) return options.onDefect(Cause.squash(e.failure), self);
510
+ return options.onError(e.success, self);
511
+ }
512
+ return options.onWaiting(self);
513
+ });
514
+ function all(results) {
515
+ return allImpl(results);
516
+ }
517
+ const allImpl = (results) => {
518
+ let waiting = false;
519
+ if (isIterable(results)) {
520
+ const successes = [];
521
+ for (const result of results) {
522
+ if (!isResult(result)) {
523
+ successes.push(result);
524
+ continue;
525
+ }
526
+ if (!isSuccess(result)) return result;
527
+ successes.push(result.value);
528
+ if (result.waiting) waiting = true;
529
+ }
530
+ return success(successes, { waiting });
531
+ }
532
+ const successes = {};
533
+ for (const [key, result] of Object.entries(results)) {
534
+ if (!isResult(result)) {
535
+ successes[key] = result;
536
+ continue;
537
+ }
538
+ if (!isSuccess(result)) return result;
539
+ successes[key] = result.value;
540
+ if (result.waiting) waiting = true;
541
+ }
542
+ return success(successes, { waiting });
543
+ };
544
+ /**
545
+ * The implementation signature is erased because `Builder` is a phantom state
546
+ * machine and `BuilderImpl` is not. `Builder` records what has been handled in
547
+ * its own parameters - `onError` returns a builder whose error type is `never`,
548
+ * `onDefect` drops `Defect` from the outstanding set - while the class keeps one
549
+ * mutable value and its parameters unchanged, so no instantiation of it relates
550
+ * to `BuilderFor` (measured: TS2322 through `onWaiting` into `onErrorIf`). The
551
+ * declaration above is the contract; the class is the mechanism.
552
+ */
553
+ function builder(self) {
554
+ return new BuilderImpl(self);
555
+ }
556
+ var BuilderImpl = class {
557
+ constructor(result) {
558
+ this.result = result;
559
+ }
560
+ result;
561
+ output = Option.none();
562
+ when(refinement, f) {
563
+ if (Option.isNone(this.output) && refinement(this.result)) {
564
+ const b = f(this.result);
565
+ if (Option.isSome(b)) this.output = b;
566
+ }
567
+ return this;
568
+ }
569
+ pipe() {
570
+ return pipeArguments(this, arguments);
571
+ }
572
+ onWaiting(f) {
573
+ return this.when((r) => r.waiting, (r) => Option.some(f(r)));
574
+ }
575
+ onInitialOrWaiting(f) {
576
+ return this.when((r) => isInitial(r) || r.waiting, (r) => Option.some(f(r)));
577
+ }
578
+ onInitial(f) {
579
+ return this.when(isInitial, (r) => Option.some(f(r)));
580
+ }
581
+ onSuccess(f) {
582
+ return this.when(isSuccess, (r) => Option.some(f(r.value, r)));
583
+ }
584
+ onFailure(f) {
585
+ return this.when(isFailure, (r) => Option.some(f(r.cause, r)));
586
+ }
587
+ onError(f) {
588
+ return this.onErrorIf(constTrue, f);
589
+ }
590
+ onErrorIf(refinement, f) {
591
+ return this.when(isFailure, (result) => Cause.findErrorOption(result.cause).pipe(Option.filter(refinement), Option.map((error) => f(error, result))));
592
+ }
593
+ onErrorTag(tag, f) {
594
+ return this.onErrorIf((e) => typeof tag === "string" ? isTagged(e, tag) : tag.some((t) => isTagged(e, t)), f);
595
+ }
596
+ onDefect(f) {
597
+ return this.when(isFailure, (result) => {
598
+ const defect = Cause.findDefect(result.cause);
599
+ return Either.isFailure(defect) ? Option.none() : Option.some(f(defect.success, result));
600
+ });
601
+ }
602
+ onInterrupt(f) {
603
+ return this.when(isFailure, (result) => {
604
+ const interruptors = Cause.filterInterruptors(result.cause);
605
+ return Either.isFailure(interruptors) ? Option.none() : Option.some(f(interruptors.success, result));
606
+ });
607
+ }
608
+ orElse(orElse) {
609
+ return Option.getOrElse(this.output, orElse);
610
+ }
611
+ orNull() {
612
+ return Option.getOrNull(this.output);
613
+ }
614
+ render() {
615
+ if (Option.isSome(this.output)) return this.output.value;
616
+ else if (isFailure(this.result)) throw Cause.squash(this.result.cause);
617
+ return null;
618
+ }
619
+ exhaustive() {
620
+ return this.render();
621
+ }
622
+ };
623
+ //#endregion
624
+ export { Schema as A, matchWithWaiting as C, value as D, touch as E, isResult as F, success as I, TypeId as M, failure as N, waiting as O, initial as P, matchWithError as S, toExit as T, isNotInitial as _, error as a, map as b, failureWithPrevious as c, fromExitWithPrevious as d, getOrElse as f, isInterrupted as g, isInitial as h, cause as i, schemaCodec as j, waitingFrom as k, flatMap as l, isFailure as m, all as n, fail as o, getOrThrow as p, builder as r, failWithPrevious as s, Result_exports as t, fromExit as u, isSuccess as v, replacePrevious as w, match as x, isWaiting as y };
@@ -0,0 +1,2 @@
1
+ import { A as touch, B as failure, C as isWaiting, D as matchWithWaiting, E as matchWithError, F as Failure, H as isResult, I as Initial, L as Result, M as waiting, N as waitingFrom, O as replacePrevious, P as Schema, R as Success, S as isSuccess, T as match, U as success, V as initial, _ as getOrThrow, a as With, b as isInterrupted, c as cause, d as failWithPrevious, f as failureWithPrevious, g as getOrElse, h as fromExitWithPrevious, j as value, k as toExit, l as error, m as fromExit, n as Defect, o as all, p as flatMap, r as Interrupt, s as builder, t as Builder, u as fail, v as isFailure, w as map, x as isNotInitial, y as isInitial, z as TypeId } from "./Result-BHH-qTvm.js";
2
+ export { Builder, Defect, type Failure, type Initial, Interrupt, type Result, Schema, type Success, TypeId, With, all, builder, cause, error, fail, failWithPrevious, failure, failureWithPrevious, flatMap, fromExit, fromExitWithPrevious, getOrElse, getOrThrow, initial, isResult as isAsyncResult, isResult, isFailure, isInitial, isInterrupted, isNotInitial, isSuccess, isWaiting, map, match, matchWithError, matchWithWaiting, replacePrevious, success, toExit, touch, value, waiting, waitingFrom };
@@ -0,0 +1,2 @@
1
+ import { A as Schema, C as matchWithWaiting, D as value, E as touch, F as isResult, I as success, M as TypeId, N as failure, O as waiting, P as initial, S as matchWithError, T as toExit, _ as isNotInitial, a as error, b as map, c as failureWithPrevious, d as fromExitWithPrevious, f as getOrElse, g as isInterrupted, h as isInitial, i as cause, k as waitingFrom, l as flatMap, m as isFailure, n as all, o as fail, p as getOrThrow, r as builder, s as failWithPrevious, u as fromExit, v as isSuccess, w as replacePrevious, x as match, y as isWaiting } from "./Result-rlUvoHzK.mjs";
2
+ export { Schema, TypeId, all, builder, cause, error, fail, failWithPrevious, failure, failureWithPrevious, flatMap, fromExit, fromExitWithPrevious, getOrElse, getOrThrow, initial, isResult as isAsyncResult, isResult, isFailure, isInitial, isInterrupted, isNotInitial, isSuccess, isWaiting, map, match, matchWithError, matchWithWaiting, replacePrevious, success, toExit, touch, value, waiting, waitingFrom };
@@ -0,0 +1,7 @@
1
+ import { a as Atom_d_exports, vt as Registry_d_exports } from "./Atom-BgqgP-Qc.js";
2
+ import { i as Result_d_exports } from "./Result-BHH-qTvm.js";
3
+ import { t as AtomHttpApi_d_exports } from "./AtomHttpApi.js";
4
+ import { t as AtomRef_d_exports } from "./AtomRef.js";
5
+ import { t as AtomRpc_d_exports } from "./AtomRpc.js";
6
+ import { t as Hydration_d_exports } from "./Hydration.js";
7
+ export { Atom_d_exports as Atom, AtomHttpApi_d_exports as AtomHttpApi, AtomRef_d_exports as AtomRef, AtomRpc_d_exports as AtomRpc, Hydration_d_exports as Hydration, Registry_d_exports as Registry, Result_d_exports as Result };
package/dist/index.mjs ADDED
@@ -0,0 +1,8 @@
1
+ import { t as Atom_exports } from "./Atom-DVWTGeoV.mjs";
2
+ import { r as Registry_exports } from "./Registry-BE4aKSZk.mjs";
3
+ import { t as Result_exports } from "./Result-rlUvoHzK.mjs";
4
+ import { t as AtomHttpApi_exports } from "./AtomHttpApi.mjs";
5
+ import { t as AtomRef_exports } from "./AtomRef.mjs";
6
+ import { t as AtomRpc_exports } from "./AtomRpc.mjs";
7
+ import { t as Hydration_exports } from "./Hydration.mjs";
8
+ export { Atom_exports as Atom, AtomHttpApi_exports as AtomHttpApi, AtomRef_exports as AtomRef, AtomRpc_exports as AtomRpc, Hydration_exports as Hydration, Registry_exports as Registry, Result_exports as Result };
@@ -0,0 +1,13 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __defProp = Object.defineProperty;
3
+ var __exportAll = (all, no_symbols) => {
4
+ let target = {};
5
+ for (var name in all) __defProp(target, name, {
6
+ get: all[name],
7
+ enumerable: true
8
+ });
9
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
10
+ return target;
11
+ };
12
+ //#endregion
13
+ export { __exportAll as t };