unthrown 3.0.0 → 3.1.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.
- package/README.md +5 -2
- package/dist/index.cjs +199 -43
- package/dist/index.d.cts +506 -107
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +506 -107
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +199 -43
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
- package/docs/index.md +0 -1407
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/constructors.ts","../src/core.ts","../src/do.ts","../src/defect.ts","../src/interop.ts","../src/facade.ts","../src/tagged.ts"],"mappings":";;AAQA;;;;;KAAY,QAAA,oBAA4B,CAAA,GAAI,CAAA,CAAE,CAAA;;;;;;;AAAC;AAU/C;KAAY,KAAA,2BAAgC,QAAA,CAAS,IAAA,CAAK,CAAA,EAAG,CAAA,qBAAsB,CAAA,GAAI,CAAA
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/constructors.ts","../src/core.ts","../src/do.ts","../src/defect.ts","../src/interop.ts","../src/facade.ts","../src/tagged.ts"],"mappings":";;AAQA;;;;;KAAY,QAAA,oBAA4B,CAAA,GAAI,CAAA,CAAE,CAAA;;;;;;;AAAC;AAU/C;KAAY,KAAA,2BAAgC,QAAA,CAAS,IAAA,CAAK,CAAA,EAAG,CAAA,qBAAsB,CAAA,GAAI,CAAA;;;;;;;;;;;;;;;;;KAkB3E,WAAA,OAAkB,CAAA,WAAY,WAAW;;AAlBmC;AAkBxF;;;;;;;;AAAqD;AAoBrD;;;;;KAAY,aAAA;EAYkB;;;;;;;;;;;EAA5B,GAAA,IAAO,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,CAAA,GAAI,WAAA,CAAY,CAAA,IAAK,QAAA,CAAO,CAAA,EAAG,CAAA;EA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AyD,gBAAA,IACpE,OAAA,CAAQ,CAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
* re-thrown (with its original stack) instead.
|
|
15
15
|
*
|
|
16
16
|
* @typeParam E - the type of the {@link UnwrapError.error} it carries.
|
|
17
|
+
*
|
|
18
|
+
* @category Errors
|
|
17
19
|
*/
|
|
18
20
|
var UnwrapError = class extends Error {
|
|
19
21
|
/**
|
|
@@ -128,7 +130,7 @@ var Res = class {
|
|
|
128
130
|
f(this.error);
|
|
129
131
|
return this;
|
|
130
132
|
} catch (cause) {
|
|
131
|
-
return
|
|
133
|
+
return observerThrowToDefect(cause, this.error);
|
|
132
134
|
}
|
|
133
135
|
}
|
|
134
136
|
flatTapErr(f) {
|
|
@@ -137,7 +139,7 @@ var Res = class {
|
|
|
137
139
|
const r = f(this.error);
|
|
138
140
|
return r.tag === "Ok" ? this : passThrough(r);
|
|
139
141
|
} catch (cause) {
|
|
140
|
-
return
|
|
142
|
+
return observerThrowToDefect(cause, this.error);
|
|
141
143
|
}
|
|
142
144
|
}
|
|
143
145
|
recoverDefect(f) {
|
|
@@ -154,7 +156,7 @@ var Res = class {
|
|
|
154
156
|
f(this.cause);
|
|
155
157
|
return this;
|
|
156
158
|
} catch (cause) {
|
|
157
|
-
return
|
|
159
|
+
return observerThrowToDefect(cause, this.cause);
|
|
158
160
|
}
|
|
159
161
|
}
|
|
160
162
|
match(cases) {
|
|
@@ -217,10 +219,10 @@ const RESULT_PROTO = Res.prototype;
|
|
|
217
219
|
* @internal
|
|
218
220
|
*/
|
|
219
221
|
function okRes(value) {
|
|
220
|
-
return Object.assign(Object.create(RESULT_PROTO), {
|
|
222
|
+
return Object.freeze(Object.assign(Object.create(RESULT_PROTO), {
|
|
221
223
|
tag: "Ok",
|
|
222
224
|
value
|
|
223
|
-
});
|
|
225
|
+
}));
|
|
224
226
|
}
|
|
225
227
|
/**
|
|
226
228
|
* Construct an `Err` result.
|
|
@@ -228,10 +230,10 @@ function okRes(value) {
|
|
|
228
230
|
* @internal
|
|
229
231
|
*/
|
|
230
232
|
function errRes(error) {
|
|
231
|
-
return Object.assign(Object.create(RESULT_PROTO), {
|
|
233
|
+
return Object.freeze(Object.assign(Object.create(RESULT_PROTO), {
|
|
232
234
|
tag: "Err",
|
|
233
235
|
error
|
|
234
|
-
});
|
|
236
|
+
}));
|
|
235
237
|
}
|
|
236
238
|
/**
|
|
237
239
|
* Construct a `Defect` result.
|
|
@@ -239,10 +241,10 @@ function errRes(error) {
|
|
|
239
241
|
* @internal
|
|
240
242
|
*/
|
|
241
243
|
function defectRes(cause) {
|
|
242
|
-
return Object.assign(Object.create(RESULT_PROTO), {
|
|
244
|
+
return Object.freeze(Object.assign(Object.create(RESULT_PROTO), {
|
|
243
245
|
tag: "Defect",
|
|
244
246
|
cause
|
|
245
|
-
});
|
|
247
|
+
}));
|
|
246
248
|
}
|
|
247
249
|
/**
|
|
248
250
|
* Type guard: is `x` a {@link Result} (any of `Ok` / `Err` / `Defect`)?
|
|
@@ -255,6 +257,20 @@ function defectRes(cause) {
|
|
|
255
257
|
* is not a `Result` and returns `false`.
|
|
256
258
|
*
|
|
257
259
|
* @returns `true` when `x` is a `Result` produced by this library.
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* ```ts
|
|
263
|
+
* import { isResult, Ok } from "unthrown";
|
|
264
|
+
*
|
|
265
|
+
* isResult(Ok(1)); // => true
|
|
266
|
+
* isResult({ tag: "Ok" }); // => false (look-alike, wrong prototype)
|
|
267
|
+
* isResult(Ok(1).toAsync()); // => false (an AsyncResult is not a Result)
|
|
268
|
+
*
|
|
269
|
+
* const x: unknown = Ok(1);
|
|
270
|
+
* if (isResult(x)) x.match({ ok: () => 1, err: () => 0, defect: () => -1 });
|
|
271
|
+
* ```
|
|
272
|
+
*
|
|
273
|
+
* @category Guards
|
|
258
274
|
*/
|
|
259
275
|
function isResult(x) {
|
|
260
276
|
return x instanceof Res;
|
|
@@ -273,6 +289,18 @@ function passThrough(self) {
|
|
|
273
289
|
return self;
|
|
274
290
|
}
|
|
275
291
|
/**
|
|
292
|
+
* A throw inside a *failure observer* (`tapErr` / `tapDefect` / `flatTapErr`)
|
|
293
|
+
* must not destroy the failure being observed — that is the exact place (e.g. a
|
|
294
|
+
* failing error-logger) where losing the underlying failure hurts most. The
|
|
295
|
+
* resulting Defect aggregates both: `errors[0]` is the observer's throw,
|
|
296
|
+
* `errors[1]` the original failure.
|
|
297
|
+
*
|
|
298
|
+
* @internal
|
|
299
|
+
*/
|
|
300
|
+
function observerThrowToDefect(thrown, original) {
|
|
301
|
+
return defectRes(new AggregateError([thrown, original], "unthrown: a failure-observer callback threw; errors[0] is the callback's throw, errors[1] the original failure"));
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
276
304
|
* Validate that a `bind`/`let` scope is a real (non-null) object before merging a
|
|
277
305
|
* key into it.
|
|
278
306
|
*
|
|
@@ -291,7 +319,7 @@ function passThrough(self) {
|
|
|
291
319
|
* @internal
|
|
292
320
|
*/
|
|
293
321
|
function scopeOf(value) {
|
|
294
|
-
if (typeof value !== "object" || value === null) throw new TypeError("bind/let requires an object scope — start a do-chain with Do()");
|
|
322
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new TypeError("bind/let requires an object scope — start a do-chain with Do()");
|
|
295
323
|
return value;
|
|
296
324
|
}
|
|
297
325
|
/**
|
|
@@ -419,7 +447,7 @@ var AsyncRes = class AsyncRes {
|
|
|
419
447
|
f(r.error);
|
|
420
448
|
return r;
|
|
421
449
|
} catch (cause) {
|
|
422
|
-
return
|
|
450
|
+
return observerThrowToDefect(cause, r.error);
|
|
423
451
|
}
|
|
424
452
|
}));
|
|
425
453
|
}
|
|
@@ -430,7 +458,7 @@ var AsyncRes = class AsyncRes {
|
|
|
430
458
|
const inner = await f(r.error);
|
|
431
459
|
return inner.tag === "Ok" ? passThrough(r) : passThrough(inner);
|
|
432
460
|
} catch (cause) {
|
|
433
|
-
return
|
|
461
|
+
return observerThrowToDefect(cause, r.error);
|
|
434
462
|
}
|
|
435
463
|
}));
|
|
436
464
|
}
|
|
@@ -451,7 +479,7 @@ var AsyncRes = class AsyncRes {
|
|
|
451
479
|
f(r.cause);
|
|
452
480
|
return r;
|
|
453
481
|
} catch (cause) {
|
|
454
|
-
return
|
|
482
|
+
return observerThrowToDefect(cause, r.cause);
|
|
455
483
|
}
|
|
456
484
|
}));
|
|
457
485
|
}
|
|
@@ -468,11 +496,7 @@ var AsyncRes = class AsyncRes {
|
|
|
468
496
|
return this.promise.then((r) => r.unwrapOr(fallback));
|
|
469
497
|
}
|
|
470
498
|
unwrapOrElse(f) {
|
|
471
|
-
return this.promise.then((r) =>
|
|
472
|
-
if (r.tag === "Ok") return r.value;
|
|
473
|
-
if (r.tag === "Defect") throw r.cause;
|
|
474
|
-
return f(r.error);
|
|
475
|
-
});
|
|
499
|
+
return this.promise.then((r) => r.unwrapOrElse(f));
|
|
476
500
|
}
|
|
477
501
|
getOrNull() {
|
|
478
502
|
return this.promise.then((r) => r.getOrNull());
|
|
@@ -492,8 +516,12 @@ var AsyncRes = class AsyncRes {
|
|
|
492
516
|
* @example
|
|
493
517
|
* ```ts
|
|
494
518
|
* import { Ok } from "unthrown";
|
|
495
|
-
*
|
|
519
|
+
*
|
|
520
|
+
* Ok(2).map((n) => n + 1); // => Ok(3)
|
|
521
|
+
* Ok(42).unwrap(); // => 42
|
|
496
522
|
* ```
|
|
523
|
+
*
|
|
524
|
+
* @category Constructors
|
|
497
525
|
*/
|
|
498
526
|
function Ok(value) {
|
|
499
527
|
return okRes(value);
|
|
@@ -507,8 +535,12 @@ function Ok(value) {
|
|
|
507
535
|
* @example
|
|
508
536
|
* ```ts
|
|
509
537
|
* import { Err } from "unthrown";
|
|
510
|
-
*
|
|
538
|
+
*
|
|
539
|
+
* Err("not_found").map((n) => n + 1); // => Err("not_found") (map skipped)
|
|
540
|
+
* Err("not_found").unwrapErr(); // => "not_found"
|
|
511
541
|
* ```
|
|
542
|
+
*
|
|
543
|
+
* @category Constructors
|
|
512
544
|
*/
|
|
513
545
|
function Err(error) {
|
|
514
546
|
return errRes(error);
|
|
@@ -520,10 +552,16 @@ function Err(error) {
|
|
|
520
552
|
*
|
|
521
553
|
* @example
|
|
522
554
|
* ```ts
|
|
523
|
-
* import { isOk, type Result } from "unthrown";
|
|
555
|
+
* import { isOk, Ok, Err, type Result } from "unthrown";
|
|
556
|
+
*
|
|
557
|
+
* isOk(Ok(1)); // => true
|
|
558
|
+
* isOk(Err("boom")); // => false
|
|
559
|
+
*
|
|
524
560
|
* declare const r: Result<number, string>;
|
|
525
561
|
* if (isOk(r)) r.value; // number, narrowed
|
|
526
562
|
* ```
|
|
563
|
+
*
|
|
564
|
+
* @category Guards
|
|
527
565
|
*/
|
|
528
566
|
function isOk(r) {
|
|
529
567
|
return r.tag === "Ok";
|
|
@@ -532,6 +570,19 @@ function isOk(r) {
|
|
|
532
570
|
* Type guard: narrow a {@link Result} to its `Err` variant, exposing `.error`.
|
|
533
571
|
*
|
|
534
572
|
* @returns `true` when `r` is `Err`.
|
|
573
|
+
*
|
|
574
|
+
* @example
|
|
575
|
+
* ```ts
|
|
576
|
+
* import { isErr, Ok, Err, type Result } from "unthrown";
|
|
577
|
+
*
|
|
578
|
+
* isErr(Err("boom")); // => true
|
|
579
|
+
* isErr(Ok(1)); // => false
|
|
580
|
+
*
|
|
581
|
+
* declare const r: Result<number, string>;
|
|
582
|
+
* if (isErr(r)) r.error; // string, narrowed
|
|
583
|
+
* ```
|
|
584
|
+
*
|
|
585
|
+
* @category Guards
|
|
535
586
|
*/
|
|
536
587
|
function isErr(r) {
|
|
537
588
|
return r.tag === "Err";
|
|
@@ -539,7 +590,27 @@ function isErr(r) {
|
|
|
539
590
|
/**
|
|
540
591
|
* Type guard: narrow a {@link Result} to its `Defect` variant, exposing `.cause`.
|
|
541
592
|
*
|
|
593
|
+
* @remarks
|
|
594
|
+
* A `Defect` has no public constructor — it only arises at a boundary (e.g. a
|
|
595
|
+
* callback throwing inside a combinator). This guard is how you detect one.
|
|
596
|
+
*
|
|
542
597
|
* @returns `true` when `r` is a `Defect`.
|
|
598
|
+
*
|
|
599
|
+
* @example
|
|
600
|
+
* ```ts
|
|
601
|
+
* import { isDefect, Ok } from "unthrown";
|
|
602
|
+
*
|
|
603
|
+
* // A throw inside a combinator is captured as a Defect:
|
|
604
|
+
* const r = Ok(1).map(() => {
|
|
605
|
+
* throw new Error("boom");
|
|
606
|
+
* });
|
|
607
|
+
* isDefect(r); // => true
|
|
608
|
+
* isDefect(Ok(1)); // => false
|
|
609
|
+
*
|
|
610
|
+
* if (isDefect(r)) r.cause; // unknown, narrowed
|
|
611
|
+
* ```
|
|
612
|
+
*
|
|
613
|
+
* @category Guards
|
|
543
614
|
*/
|
|
544
615
|
function isDefect(r) {
|
|
545
616
|
return r.tag === "Defect";
|
|
@@ -567,6 +638,24 @@ function isDefect(r) {
|
|
|
567
638
|
* .map(({ user, org, label }) => render(user, org, label));
|
|
568
639
|
* // Result<View, NotFound>
|
|
569
640
|
* ```
|
|
641
|
+
*
|
|
642
|
+
* @example
|
|
643
|
+
* ```ts
|
|
644
|
+
* import { Do, Ok, Err } from "unthrown";
|
|
645
|
+
*
|
|
646
|
+
* // Ok path — the scope accumulates:
|
|
647
|
+
* Do()
|
|
648
|
+
* .bind("a", () => Ok(2))
|
|
649
|
+
* .let("b", ({ a }) => a * 10)
|
|
650
|
+
* .map(({ a, b }) => a + b); // => Ok(22)
|
|
651
|
+
*
|
|
652
|
+
* // Err path — the first Err short-circuits the rest:
|
|
653
|
+
* Do()
|
|
654
|
+
* .bind("a", () => Err("boom"))
|
|
655
|
+
* .let("b", ({ a }) => a); // => Err("boom")
|
|
656
|
+
* ```
|
|
657
|
+
*
|
|
658
|
+
* @category Do-notation
|
|
570
659
|
*/
|
|
571
660
|
function Do() {
|
|
572
661
|
return Ok({});
|
|
@@ -616,10 +705,16 @@ function isDefectMarker(x) {
|
|
|
616
705
|
* @param value - the possibly-absent value.
|
|
617
706
|
* @param onAbsent - lazily produces the error for the absent case.
|
|
618
707
|
*
|
|
708
|
+
* @category Interop
|
|
709
|
+
*
|
|
619
710
|
* @example
|
|
620
711
|
* ```ts
|
|
621
712
|
* import { fromNullable } from "unthrown";
|
|
622
|
-
*
|
|
713
|
+
*
|
|
714
|
+
* const map = new Map([["a", 1]]);
|
|
715
|
+
* fromNullable(map.get("a"), () => "absent").unwrap(); // => 1
|
|
716
|
+
* fromNullable(map.get("z"), () => "absent"); // => Err("absent")
|
|
717
|
+
* fromNullable(0, () => "absent").unwrap(); // => 0 (falsy but present)
|
|
623
718
|
* ```
|
|
624
719
|
*/
|
|
625
720
|
function fromNullable(value, onAbsent) {
|
|
@@ -650,11 +745,21 @@ function fromNullable(value, onAbsent) {
|
|
|
650
745
|
* unmodeled by returning `defect(cause)` (the helper passed as its second arg).
|
|
651
746
|
* @returns a function with the same arguments returning `Result<T, E>`.
|
|
652
747
|
*
|
|
748
|
+
* @category Interop
|
|
749
|
+
*
|
|
653
750
|
* @example
|
|
654
751
|
* ```ts
|
|
655
752
|
* import { fromThrowable } from "unthrown";
|
|
656
|
-
*
|
|
657
|
-
* parse
|
|
753
|
+
*
|
|
754
|
+
* // Model the parse failure as an `Err`, everything unexpected as a `Defect`.
|
|
755
|
+
* const parse = fromThrowable(
|
|
756
|
+
* (text: string) => JSON.parse(text) as unknown,
|
|
757
|
+
* (cause, defect) =>
|
|
758
|
+
* cause instanceof SyntaxError ? ("invalid_json" as const) : defect(cause),
|
|
759
|
+
* );
|
|
760
|
+
*
|
|
761
|
+
* parse('{"ok":true}').unwrap(); // => { ok: true }
|
|
762
|
+
* parse("nope"); // => Err("invalid_json")
|
|
658
763
|
* ```
|
|
659
764
|
*/
|
|
660
765
|
function fromThrowable(fn, qualify) {
|
|
@@ -689,17 +794,24 @@ function fromThrowable(fn, qualify) {
|
|
|
689
794
|
* @param qualify - triages a rejection `cause` into a modeled `E`, or marks it
|
|
690
795
|
* unmodeled by returning `defect(cause)` (the helper passed as its second arg).
|
|
691
796
|
*
|
|
797
|
+
* @category Interop
|
|
798
|
+
*
|
|
692
799
|
* @example
|
|
693
800
|
* ```ts
|
|
694
801
|
* import { fromPromise } from "unthrown";
|
|
802
|
+
*
|
|
803
|
+
* // A rejection with a NotFoundError becomes a modeled `Err`; anything else a Defect.
|
|
695
804
|
* const user = await fromPromise(fetchUser(id), (cause, defect) =>
|
|
696
805
|
* cause instanceof NotFoundError ? ("not_found" as const) : defect(cause),
|
|
697
806
|
* );
|
|
807
|
+
*
|
|
808
|
+
* user.unwrap(); // => the fetched user (on success)
|
|
809
|
+
* // when fetchUser rejects with NotFoundError: => Err("not_found")
|
|
698
810
|
* ```
|
|
699
811
|
*/
|
|
700
812
|
function fromPromise(promise, qualify) {
|
|
701
813
|
const triage = qualify;
|
|
702
|
-
return new AsyncRes((typeof promise === "function" ? Promise.resolve().then(promise) : promise).then((value) => okRes(value), (cause) => qualifyToResult(cause, triage)));
|
|
814
|
+
return new AsyncRes((typeof promise === "function" ? Promise.resolve().then(promise) : Promise.resolve(promise)).then((value) => okRes(value), (cause) => qualifyToResult(cause, triage)));
|
|
703
815
|
}
|
|
704
816
|
/**
|
|
705
817
|
* Wrap a `Promise` asserted **not** to fail in any modeled way: any rejection
|
|
@@ -712,9 +824,20 @@ function fromPromise(promise, qualify) {
|
|
|
712
824
|
*
|
|
713
825
|
* @typeParam T - the resolved value type.
|
|
714
826
|
* @param promise - the promise, or a thunk returning one.
|
|
827
|
+
*
|
|
828
|
+
* @category Interop
|
|
829
|
+
*
|
|
830
|
+
* @example
|
|
831
|
+
* ```ts
|
|
832
|
+
* import { fromSafePromise } from "unthrown";
|
|
833
|
+
*
|
|
834
|
+
* (await fromSafePromise(Promise.resolve(3))).unwrap(); // => 3
|
|
835
|
+
* // a rejection becomes a Defect (never a modeled Err):
|
|
836
|
+
* await fromSafePromise(Promise.reject(new Error("boom"))); // => Defect(Error("boom"))
|
|
837
|
+
* ```
|
|
715
838
|
*/
|
|
716
839
|
function fromSafePromise(promise) {
|
|
717
|
-
return new AsyncRes((typeof promise === "function" ? Promise.resolve().then(promise) : promise).then((value) => okRes(value), (cause) => defectRes(cause)));
|
|
840
|
+
return new AsyncRes((typeof promise === "function" ? Promise.resolve().then(promise) : Promise.resolve(promise)).then((value) => okRes(value), (cause) => defectRes(cause)));
|
|
718
841
|
}
|
|
719
842
|
function qualifyToResult(cause, qualify) {
|
|
720
843
|
try {
|
|
@@ -734,8 +857,10 @@ function foldArray(results) {
|
|
|
734
857
|
let firstErr;
|
|
735
858
|
let firstDefect;
|
|
736
859
|
const values = [];
|
|
737
|
-
for (const r of results) if (r.tag === "Defect")
|
|
738
|
-
|
|
860
|
+
for (const r of results) if (r.tag === "Defect") {
|
|
861
|
+
firstDefect ??= r;
|
|
862
|
+
break;
|
|
863
|
+
} else if (r.tag === "Err") firstErr ??= r;
|
|
739
864
|
else values.push(r.value);
|
|
740
865
|
return firstDefect ?? firstErr ?? Ok(values);
|
|
741
866
|
}
|
|
@@ -750,8 +875,10 @@ function foldRecord(results) {
|
|
|
750
875
|
let firstErr;
|
|
751
876
|
let firstDefect;
|
|
752
877
|
const values = {};
|
|
753
|
-
for (const [key, r] of Object.entries(results)) if (r.tag === "Defect")
|
|
754
|
-
|
|
878
|
+
for (const [key, r] of Object.entries(results)) if (r.tag === "Defect") {
|
|
879
|
+
firstDefect ??= r;
|
|
880
|
+
break;
|
|
881
|
+
} else if (r.tag === "Err") firstErr ??= r;
|
|
755
882
|
else Object.defineProperty(values, key, {
|
|
756
883
|
value: r.value,
|
|
757
884
|
enumerable: true,
|
|
@@ -772,11 +899,14 @@ function foldRecord(results) {
|
|
|
772
899
|
* collapses to `Result<T[], E>` with no cast. For a **record** keyed by name,
|
|
773
900
|
* use {@link allFromDict}.
|
|
774
901
|
*
|
|
902
|
+
* @category Aggregate
|
|
903
|
+
*
|
|
775
904
|
* @example
|
|
776
905
|
* ```ts
|
|
777
|
-
* import { all, Ok } from "unthrown";
|
|
778
|
-
*
|
|
779
|
-
* all([Ok(1), Ok(
|
|
906
|
+
* import { all, Ok, Err } from "unthrown";
|
|
907
|
+
*
|
|
908
|
+
* all([Ok(1), Ok("a"), Ok(true)]).unwrap(); // => [1, "a", true] (typed [number, string, boolean])
|
|
909
|
+
* all([Ok(1), Err("e"), Ok(3)]); // => Err("e") (short-circuits on the first Err)
|
|
780
910
|
* ```
|
|
781
911
|
*/
|
|
782
912
|
function all(results) {
|
|
@@ -792,10 +922,14 @@ function all(results) {
|
|
|
792
922
|
* Same folding rules as {@link all}: first `Err` short-circuits, any `Defect`
|
|
793
923
|
* dominates. This is **not** error accumulation.
|
|
794
924
|
*
|
|
925
|
+
* @category Aggregate
|
|
926
|
+
*
|
|
795
927
|
* @example
|
|
796
928
|
* ```ts
|
|
797
|
-
* import { allFromDict, Ok } from "unthrown";
|
|
798
|
-
*
|
|
929
|
+
* import { allFromDict, Ok, Err } from "unthrown";
|
|
930
|
+
*
|
|
931
|
+
* allFromDict({ id: Ok(1), name: Ok("ada") }).unwrap(); // => { id: 1, name: "ada" }
|
|
932
|
+
* allFromDict({ id: Ok(1), name: Err("missing") }); // => Err("missing")
|
|
799
933
|
* ```
|
|
800
934
|
*/
|
|
801
935
|
function allFromDict(results) {
|
|
@@ -811,10 +945,14 @@ function allFromDict(results) {
|
|
|
811
945
|
* short-circuits, any `Defect` dominates. As ever, the returned `AsyncResult`'s
|
|
812
946
|
* internal promise never rejects. For a **record**, use {@link allFromDictAsync}.
|
|
813
947
|
*
|
|
948
|
+
* @category Aggregate
|
|
949
|
+
*
|
|
814
950
|
* @example
|
|
815
951
|
* ```ts
|
|
816
952
|
* import { allAsync, fromSafePromise } from "unthrown";
|
|
817
|
-
*
|
|
953
|
+
*
|
|
954
|
+
* const both = allAsync([fromSafePromise(Promise.resolve(1)), fromSafePromise(Promise.resolve(2))]);
|
|
955
|
+
* (await both).unwrap(); // => [1, 2]
|
|
818
956
|
* ```
|
|
819
957
|
*/
|
|
820
958
|
function allAsync(results) {
|
|
@@ -828,10 +966,17 @@ function allAsync(results) {
|
|
|
828
966
|
* Resolved concurrently (order preserved), folded with the {@link all} rules,
|
|
829
967
|
* and the internal promise never rejects.
|
|
830
968
|
*
|
|
969
|
+
* @category Aggregate
|
|
970
|
+
*
|
|
831
971
|
* @example
|
|
832
972
|
* ```ts
|
|
833
973
|
* import { allFromDictAsync, fromSafePromise } from "unthrown";
|
|
834
|
-
*
|
|
974
|
+
*
|
|
975
|
+
* const both = allFromDictAsync({
|
|
976
|
+
* a: fromSafePromise(Promise.resolve(1)),
|
|
977
|
+
* b: fromSafePromise(Promise.resolve("x")),
|
|
978
|
+
* });
|
|
979
|
+
* (await both).unwrap(); // => { a: 1, b: "x" }
|
|
835
980
|
* ```
|
|
836
981
|
*/
|
|
837
982
|
function allFromDictAsync(results) {
|
|
@@ -863,10 +1008,12 @@ function allFromDictAsync(results) {
|
|
|
863
1008
|
* (`AsyncResult.fromPromise`, `AsyncResult.all`, …), grouped by what they
|
|
864
1009
|
* return — a static lives in exactly one namespace.
|
|
865
1010
|
*
|
|
1011
|
+
* @category Facade
|
|
1012
|
+
*
|
|
866
1013
|
* @example
|
|
867
1014
|
* ```ts
|
|
868
1015
|
* import { Result } from "unthrown";
|
|
869
|
-
* Result.Ok(1).flatMap((n) => Result.Ok(n + 1)).unwrap(); // 2
|
|
1016
|
+
* Result.Ok(1).flatMap((n) => Result.Ok(n + 1)).unwrap(); // => 2
|
|
870
1017
|
* ```
|
|
871
1018
|
*/
|
|
872
1019
|
const Result = {
|
|
@@ -897,10 +1044,13 @@ const Result = {
|
|
|
897
1044
|
* {@link Result}, the free functions remain the primary, tree-shakeable API; the
|
|
898
1045
|
* value `AsyncResult` and the type {@link AsyncResult} share one name.
|
|
899
1046
|
*
|
|
1047
|
+
* @category Facade
|
|
1048
|
+
*
|
|
900
1049
|
* @example
|
|
901
1050
|
* ```ts
|
|
902
1051
|
* import { AsyncResult } from "unthrown";
|
|
903
1052
|
* const user = await AsyncResult.fromPromise(fetchUser(id), (c, defect) => defect(c));
|
|
1053
|
+
* user.unwrap(); // => the fetched user (on success)
|
|
904
1054
|
* ```
|
|
905
1055
|
*/
|
|
906
1056
|
const AsyncResult = {
|
|
@@ -919,7 +1069,10 @@ const AsyncResult = {
|
|
|
919
1069
|
* Extend the returned class to declare a concrete error. Supply the payload with
|
|
920
1070
|
* an instantiation expression; omit it for a payload-less error. A `message`
|
|
921
1071
|
* field in the payload is forwarded to `Error`. The `_tag` always reflects
|
|
922
|
-
* `tag` and cannot be overridden by the payload.
|
|
1072
|
+
* `tag` and cannot be overridden by the payload. `name` is likewise reserved —
|
|
1073
|
+
* it is the display label (set it with `options.name`); a payload `name` is
|
|
1074
|
+
* rejected at compile time (and excluded from the instance type), so it can't
|
|
1075
|
+
* shadow `Error.name`.
|
|
923
1076
|
*
|
|
924
1077
|
* `_tag` is the discriminant used by {@link matchTags}; `Error.name` is the
|
|
925
1078
|
* human-facing label in stack traces and logs. By default they coincide, but
|
|
@@ -942,13 +1095,15 @@ const AsyncResult = {
|
|
|
942
1095
|
* @param options - optional overrides. `options.name` sets `Error.name`
|
|
943
1096
|
* independently of `tag` (defaults to `tag`).
|
|
944
1097
|
*
|
|
1098
|
+
* @category Tagged errors
|
|
1099
|
+
*
|
|
945
1100
|
* @example
|
|
946
1101
|
* ```ts
|
|
947
1102
|
* class NotFound extends TaggedError("NotFound") {}
|
|
948
1103
|
* class HttpError extends TaggedError("HttpError")<{ status: number }> {}
|
|
949
1104
|
*
|
|
950
|
-
* new NotFound()._tag; // "NotFound"
|
|
951
|
-
* new HttpError({ status: 500 }).status; // 500
|
|
1105
|
+
* new NotFound()._tag; // => "NotFound"
|
|
1106
|
+
* new HttpError({ status: 500 }).status; // => 500
|
|
952
1107
|
* ```
|
|
953
1108
|
*/
|
|
954
1109
|
function TaggedError(tag, options) {
|
|
@@ -967,8 +1122,9 @@ function TaggedError(tag, options) {
|
|
|
967
1122
|
}
|
|
968
1123
|
function matchTags(result, handlers) {
|
|
969
1124
|
const onErr = (error) => {
|
|
970
|
-
const
|
|
971
|
-
|
|
1125
|
+
const tag = error._tag;
|
|
1126
|
+
const handler = tag === "Ok" || tag === "Defect" || !Object.hasOwn(handlers, tag) ? void 0 : handlers[tag];
|
|
1127
|
+
return handler ? handler(error) : handlers.Defect(error);
|
|
972
1128
|
};
|
|
973
1129
|
return result.match({
|
|
974
1130
|
ok: handlers.Ok,
|