unthrown 3.0.1 → 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 +194 -36
- 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 +194 -36
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -5
- 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
|
}
|
|
@@ -488,8 +516,12 @@ var AsyncRes = class AsyncRes {
|
|
|
488
516
|
* @example
|
|
489
517
|
* ```ts
|
|
490
518
|
* import { Ok } from "unthrown";
|
|
491
|
-
*
|
|
519
|
+
*
|
|
520
|
+
* Ok(2).map((n) => n + 1); // => Ok(3)
|
|
521
|
+
* Ok(42).unwrap(); // => 42
|
|
492
522
|
* ```
|
|
523
|
+
*
|
|
524
|
+
* @category Constructors
|
|
493
525
|
*/
|
|
494
526
|
function Ok(value) {
|
|
495
527
|
return okRes(value);
|
|
@@ -503,8 +535,12 @@ function Ok(value) {
|
|
|
503
535
|
* @example
|
|
504
536
|
* ```ts
|
|
505
537
|
* import { Err } from "unthrown";
|
|
506
|
-
*
|
|
538
|
+
*
|
|
539
|
+
* Err("not_found").map((n) => n + 1); // => Err("not_found") (map skipped)
|
|
540
|
+
* Err("not_found").unwrapErr(); // => "not_found"
|
|
507
541
|
* ```
|
|
542
|
+
*
|
|
543
|
+
* @category Constructors
|
|
508
544
|
*/
|
|
509
545
|
function Err(error) {
|
|
510
546
|
return errRes(error);
|
|
@@ -516,10 +552,16 @@ function Err(error) {
|
|
|
516
552
|
*
|
|
517
553
|
* @example
|
|
518
554
|
* ```ts
|
|
519
|
-
* 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
|
+
*
|
|
520
560
|
* declare const r: Result<number, string>;
|
|
521
561
|
* if (isOk(r)) r.value; // number, narrowed
|
|
522
562
|
* ```
|
|
563
|
+
*
|
|
564
|
+
* @category Guards
|
|
523
565
|
*/
|
|
524
566
|
function isOk(r) {
|
|
525
567
|
return r.tag === "Ok";
|
|
@@ -528,6 +570,19 @@ function isOk(r) {
|
|
|
528
570
|
* Type guard: narrow a {@link Result} to its `Err` variant, exposing `.error`.
|
|
529
571
|
*
|
|
530
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
|
|
531
586
|
*/
|
|
532
587
|
function isErr(r) {
|
|
533
588
|
return r.tag === "Err";
|
|
@@ -535,7 +590,27 @@ function isErr(r) {
|
|
|
535
590
|
/**
|
|
536
591
|
* Type guard: narrow a {@link Result} to its `Defect` variant, exposing `.cause`.
|
|
537
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
|
+
*
|
|
538
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
|
|
539
614
|
*/
|
|
540
615
|
function isDefect(r) {
|
|
541
616
|
return r.tag === "Defect";
|
|
@@ -563,6 +638,24 @@ function isDefect(r) {
|
|
|
563
638
|
* .map(({ user, org, label }) => render(user, org, label));
|
|
564
639
|
* // Result<View, NotFound>
|
|
565
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
|
|
566
659
|
*/
|
|
567
660
|
function Do() {
|
|
568
661
|
return Ok({});
|
|
@@ -612,10 +705,16 @@ function isDefectMarker(x) {
|
|
|
612
705
|
* @param value - the possibly-absent value.
|
|
613
706
|
* @param onAbsent - lazily produces the error for the absent case.
|
|
614
707
|
*
|
|
708
|
+
* @category Interop
|
|
709
|
+
*
|
|
615
710
|
* @example
|
|
616
711
|
* ```ts
|
|
617
712
|
* import { fromNullable } from "unthrown";
|
|
618
|
-
*
|
|
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)
|
|
619
718
|
* ```
|
|
620
719
|
*/
|
|
621
720
|
function fromNullable(value, onAbsent) {
|
|
@@ -646,11 +745,21 @@ function fromNullable(value, onAbsent) {
|
|
|
646
745
|
* unmodeled by returning `defect(cause)` (the helper passed as its second arg).
|
|
647
746
|
* @returns a function with the same arguments returning `Result<T, E>`.
|
|
648
747
|
*
|
|
748
|
+
* @category Interop
|
|
749
|
+
*
|
|
649
750
|
* @example
|
|
650
751
|
* ```ts
|
|
651
752
|
* import { fromThrowable } from "unthrown";
|
|
652
|
-
*
|
|
653
|
-
* 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")
|
|
654
763
|
* ```
|
|
655
764
|
*/
|
|
656
765
|
function fromThrowable(fn, qualify) {
|
|
@@ -685,17 +794,24 @@ function fromThrowable(fn, qualify) {
|
|
|
685
794
|
* @param qualify - triages a rejection `cause` into a modeled `E`, or marks it
|
|
686
795
|
* unmodeled by returning `defect(cause)` (the helper passed as its second arg).
|
|
687
796
|
*
|
|
797
|
+
* @category Interop
|
|
798
|
+
*
|
|
688
799
|
* @example
|
|
689
800
|
* ```ts
|
|
690
801
|
* import { fromPromise } from "unthrown";
|
|
802
|
+
*
|
|
803
|
+
* // A rejection with a NotFoundError becomes a modeled `Err`; anything else a Defect.
|
|
691
804
|
* const user = await fromPromise(fetchUser(id), (cause, defect) =>
|
|
692
805
|
* cause instanceof NotFoundError ? ("not_found" as const) : defect(cause),
|
|
693
806
|
* );
|
|
807
|
+
*
|
|
808
|
+
* user.unwrap(); // => the fetched user (on success)
|
|
809
|
+
* // when fetchUser rejects with NotFoundError: => Err("not_found")
|
|
694
810
|
* ```
|
|
695
811
|
*/
|
|
696
812
|
function fromPromise(promise, qualify) {
|
|
697
813
|
const triage = qualify;
|
|
698
|
-
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)));
|
|
699
815
|
}
|
|
700
816
|
/**
|
|
701
817
|
* Wrap a `Promise` asserted **not** to fail in any modeled way: any rejection
|
|
@@ -708,9 +824,20 @@ function fromPromise(promise, qualify) {
|
|
|
708
824
|
*
|
|
709
825
|
* @typeParam T - the resolved value type.
|
|
710
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
|
+
* ```
|
|
711
838
|
*/
|
|
712
839
|
function fromSafePromise(promise) {
|
|
713
|
-
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)));
|
|
714
841
|
}
|
|
715
842
|
function qualifyToResult(cause, qualify) {
|
|
716
843
|
try {
|
|
@@ -748,8 +875,10 @@ function foldRecord(results) {
|
|
|
748
875
|
let firstErr;
|
|
749
876
|
let firstDefect;
|
|
750
877
|
const values = {};
|
|
751
|
-
for (const [key, r] of Object.entries(results)) if (r.tag === "Defect")
|
|
752
|
-
|
|
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;
|
|
753
882
|
else Object.defineProperty(values, key, {
|
|
754
883
|
value: r.value,
|
|
755
884
|
enumerable: true,
|
|
@@ -770,11 +899,14 @@ function foldRecord(results) {
|
|
|
770
899
|
* collapses to `Result<T[], E>` with no cast. For a **record** keyed by name,
|
|
771
900
|
* use {@link allFromDict}.
|
|
772
901
|
*
|
|
902
|
+
* @category Aggregate
|
|
903
|
+
*
|
|
773
904
|
* @example
|
|
774
905
|
* ```ts
|
|
775
|
-
* import { all, Ok } from "unthrown";
|
|
776
|
-
*
|
|
777
|
-
* 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)
|
|
778
910
|
* ```
|
|
779
911
|
*/
|
|
780
912
|
function all(results) {
|
|
@@ -790,10 +922,14 @@ function all(results) {
|
|
|
790
922
|
* Same folding rules as {@link all}: first `Err` short-circuits, any `Defect`
|
|
791
923
|
* dominates. This is **not** error accumulation.
|
|
792
924
|
*
|
|
925
|
+
* @category Aggregate
|
|
926
|
+
*
|
|
793
927
|
* @example
|
|
794
928
|
* ```ts
|
|
795
|
-
* import { allFromDict, Ok } from "unthrown";
|
|
796
|
-
*
|
|
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")
|
|
797
933
|
* ```
|
|
798
934
|
*/
|
|
799
935
|
function allFromDict(results) {
|
|
@@ -809,10 +945,14 @@ function allFromDict(results) {
|
|
|
809
945
|
* short-circuits, any `Defect` dominates. As ever, the returned `AsyncResult`'s
|
|
810
946
|
* internal promise never rejects. For a **record**, use {@link allFromDictAsync}.
|
|
811
947
|
*
|
|
948
|
+
* @category Aggregate
|
|
949
|
+
*
|
|
812
950
|
* @example
|
|
813
951
|
* ```ts
|
|
814
952
|
* import { allAsync, fromSafePromise } from "unthrown";
|
|
815
|
-
*
|
|
953
|
+
*
|
|
954
|
+
* const both = allAsync([fromSafePromise(Promise.resolve(1)), fromSafePromise(Promise.resolve(2))]);
|
|
955
|
+
* (await both).unwrap(); // => [1, 2]
|
|
816
956
|
* ```
|
|
817
957
|
*/
|
|
818
958
|
function allAsync(results) {
|
|
@@ -826,10 +966,17 @@ function allAsync(results) {
|
|
|
826
966
|
* Resolved concurrently (order preserved), folded with the {@link all} rules,
|
|
827
967
|
* and the internal promise never rejects.
|
|
828
968
|
*
|
|
969
|
+
* @category Aggregate
|
|
970
|
+
*
|
|
829
971
|
* @example
|
|
830
972
|
* ```ts
|
|
831
973
|
* import { allFromDictAsync, fromSafePromise } from "unthrown";
|
|
832
|
-
*
|
|
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" }
|
|
833
980
|
* ```
|
|
834
981
|
*/
|
|
835
982
|
function allFromDictAsync(results) {
|
|
@@ -861,10 +1008,12 @@ function allFromDictAsync(results) {
|
|
|
861
1008
|
* (`AsyncResult.fromPromise`, `AsyncResult.all`, …), grouped by what they
|
|
862
1009
|
* return — a static lives in exactly one namespace.
|
|
863
1010
|
*
|
|
1011
|
+
* @category Facade
|
|
1012
|
+
*
|
|
864
1013
|
* @example
|
|
865
1014
|
* ```ts
|
|
866
1015
|
* import { Result } from "unthrown";
|
|
867
|
-
* Result.Ok(1).flatMap((n) => Result.Ok(n + 1)).unwrap(); // 2
|
|
1016
|
+
* Result.Ok(1).flatMap((n) => Result.Ok(n + 1)).unwrap(); // => 2
|
|
868
1017
|
* ```
|
|
869
1018
|
*/
|
|
870
1019
|
const Result = {
|
|
@@ -895,10 +1044,13 @@ const Result = {
|
|
|
895
1044
|
* {@link Result}, the free functions remain the primary, tree-shakeable API; the
|
|
896
1045
|
* value `AsyncResult` and the type {@link AsyncResult} share one name.
|
|
897
1046
|
*
|
|
1047
|
+
* @category Facade
|
|
1048
|
+
*
|
|
898
1049
|
* @example
|
|
899
1050
|
* ```ts
|
|
900
1051
|
* import { AsyncResult } from "unthrown";
|
|
901
1052
|
* const user = await AsyncResult.fromPromise(fetchUser(id), (c, defect) => defect(c));
|
|
1053
|
+
* user.unwrap(); // => the fetched user (on success)
|
|
902
1054
|
* ```
|
|
903
1055
|
*/
|
|
904
1056
|
const AsyncResult = {
|
|
@@ -917,7 +1069,10 @@ const AsyncResult = {
|
|
|
917
1069
|
* Extend the returned class to declare a concrete error. Supply the payload with
|
|
918
1070
|
* an instantiation expression; omit it for a payload-less error. A `message`
|
|
919
1071
|
* field in the payload is forwarded to `Error`. The `_tag` always reflects
|
|
920
|
-
* `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`.
|
|
921
1076
|
*
|
|
922
1077
|
* `_tag` is the discriminant used by {@link matchTags}; `Error.name` is the
|
|
923
1078
|
* human-facing label in stack traces and logs. By default they coincide, but
|
|
@@ -940,13 +1095,15 @@ const AsyncResult = {
|
|
|
940
1095
|
* @param options - optional overrides. `options.name` sets `Error.name`
|
|
941
1096
|
* independently of `tag` (defaults to `tag`).
|
|
942
1097
|
*
|
|
1098
|
+
* @category Tagged errors
|
|
1099
|
+
*
|
|
943
1100
|
* @example
|
|
944
1101
|
* ```ts
|
|
945
1102
|
* class NotFound extends TaggedError("NotFound") {}
|
|
946
1103
|
* class HttpError extends TaggedError("HttpError")<{ status: number }> {}
|
|
947
1104
|
*
|
|
948
|
-
* new NotFound()._tag; // "NotFound"
|
|
949
|
-
* new HttpError({ status: 500 }).status; // 500
|
|
1105
|
+
* new NotFound()._tag; // => "NotFound"
|
|
1106
|
+
* new HttpError({ status: 500 }).status; // => 500
|
|
950
1107
|
* ```
|
|
951
1108
|
*/
|
|
952
1109
|
function TaggedError(tag, options) {
|
|
@@ -965,8 +1122,9 @@ function TaggedError(tag, options) {
|
|
|
965
1122
|
}
|
|
966
1123
|
function matchTags(result, handlers) {
|
|
967
1124
|
const onErr = (error) => {
|
|
968
|
-
const
|
|
969
|
-
|
|
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);
|
|
970
1128
|
};
|
|
971
1129
|
return result.match({
|
|
972
1130
|
ok: handlers.Ok,
|