unthrown 3.0.1 → 4.0.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 +215 -43
- package/dist/index.d.cts +556 -120
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +556 -120
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +215 -43
- 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;;;;;;;;;;KAW3E,aAAA;EAXgC;;;;;;;;AAA4C;EAqBtF,GAAA,IAAO,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,CAAA,GAAI,QAAA,CAAO,CAAA,EAAG,CAAA;EAVf;;;;;;;;;;EAqBvB,OAAA,QAAe,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,QAAA,CAAO,CAAA,EAAG,EAAA,IAAM,QAAA,CAAO,CAAA,EAAG,CAAA,GAAI,EAAA;EAAP;;;;;;;;EASvD,GAAA,CAAI,CAAA,GAAI,KAAA,EAAO,CAAA,YAAa,QAAA,CAAO,CAAA,EAAG,CAAA;EAiBO;;;;;;;;;;;;;;;;EAA7C,OAAA,KAAY,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,QAAA,UAAgB,EAAA,IAAM,QAAA,CAAO,CAAA,EAAG,CAAA,GAAI,EAAA;EAuB9D;;;;;;;;;;;;;;;;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;APPc;AAU/C;;;;;;KOSY,sBAAA;EAAA,eACK,KAAA,OAAY,IAAA,QAAY,CAAA,wBAAyB,CAAA,GAAI,mBAAA,CAAoB,GAAA,EAAK,CAAA;AAAA;;;;;;;;;;;;;;APVP;AAWxF;;;;;;;;;;;;;;;;;;;;;;;;;;iBO0CgB,WAAA,qBACd,GAAA,EAAK,GAAA,EACL,OAAA;EAAA,SAAqB,IAAA;AAAA,IACpB,sBAAA,CAAuB,GAAA;;;;;;;;;;KA4Bd,WAAA;EAA2B,IAAA;AAAA;EACrC,EAAA,GAAK,KAAA,EAAO,CAAA,KAAM,CAAA;EAClB,MAAA,GAAS,KAAA,cAAmB,CAAA;AAAA,YAClB,CAAA,YAAa,KAAA,EAAO,OAAA,CAAQ,CAAA;EAAK,IAAA,EAAM,CAAA;AAAA,OAAS,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAgC5C,SAAA;EAAyB,IAAA;AAAA,MACvC,MAAA,EAAQ,QAAA,CAAO,CAAA,EAAG,CAAA,GAClB,QAAA,EAAU,WAAA,CAAY,CAAA,EAAG,CAAA,EAAG,CAAA,IAC3B,CAAA;AAAA,iBACa,SAAA;EAAyB,IAAA;AAAA,MACvC,MAAA,EAAQ,aAAA,CAAY,CAAA,EAAG,CAAA,GACvB,QAAA,EAAU,WAAA,CAAY,CAAA,EAAG,CAAA,EAAG,CAAA,IAC3B,OAAA,CAAQ,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,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2CW,SAAA;EAAyB,IAAA;AAAA,MACvC,MAAA,EAAQ,QAAA,CAAO,CAAA,EAAG,CAAA,GAClB,QAAA,EAAU,WAAA,CAAY,CAAA,EAAG,CAAA,EAAG,CAAA,MACxB,OAAA,CAAQ,CAAA,wDAAyD,gBAAA,IACpE,CAAA;AAAA,iBACa,SAAA;EAAyB,IAAA;AAAA,MACvC,MAAA,EAAQ,aAAA,CAAY,CAAA,EAAG,CAAA,GACvB,QAAA,EAAU,WAAA,CAAY,CAAA,EAAG,CAAA,EAAG,CAAA,MACxB,OAAA,CAAQ,CAAA,wDAAyD,gBAAA,IACpE,OAAA,CAAQ,CAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -13,7 +13,14 @@
|
|
|
13
13
|
* A `Defect` is never wrapped in an `UnwrapError`: its original cause is
|
|
14
14
|
* re-thrown (with its original stack) instead.
|
|
15
15
|
*
|
|
16
|
+
* `unwrap()` and `unwrapErr()` are type-gated (`this: Result<T, never>` /
|
|
17
|
+
* `Result<never, E>`), so the wrong-variant branch that throws this is
|
|
18
|
+
* unreachable through well-typed code — it remains only as a defensive guard
|
|
19
|
+
* against unsound runtime misuse (e.g. an `as` cast past the gate).
|
|
20
|
+
*
|
|
16
21
|
* @typeParam E - the type of the {@link UnwrapError.error} it carries.
|
|
22
|
+
*
|
|
23
|
+
* @category Errors
|
|
17
24
|
*/
|
|
18
25
|
var UnwrapError = class extends Error {
|
|
19
26
|
/**
|
|
@@ -128,7 +135,7 @@ var Res = class {
|
|
|
128
135
|
f(this.error);
|
|
129
136
|
return this;
|
|
130
137
|
} catch (cause) {
|
|
131
|
-
return
|
|
138
|
+
return observerThrowToDefect(cause, this.error);
|
|
132
139
|
}
|
|
133
140
|
}
|
|
134
141
|
flatTapErr(f) {
|
|
@@ -137,7 +144,7 @@ var Res = class {
|
|
|
137
144
|
const r = f(this.error);
|
|
138
145
|
return r.tag === "Ok" ? this : passThrough(r);
|
|
139
146
|
} catch (cause) {
|
|
140
|
-
return
|
|
147
|
+
return observerThrowToDefect(cause, this.error);
|
|
141
148
|
}
|
|
142
149
|
}
|
|
143
150
|
recoverDefect(f) {
|
|
@@ -154,7 +161,7 @@ var Res = class {
|
|
|
154
161
|
f(this.cause);
|
|
155
162
|
return this;
|
|
156
163
|
} catch (cause) {
|
|
157
|
-
return
|
|
164
|
+
return observerThrowToDefect(cause, this.cause);
|
|
158
165
|
}
|
|
159
166
|
}
|
|
160
167
|
match(cases) {
|
|
@@ -217,10 +224,10 @@ const RESULT_PROTO = Res.prototype;
|
|
|
217
224
|
* @internal
|
|
218
225
|
*/
|
|
219
226
|
function okRes(value) {
|
|
220
|
-
return Object.assign(Object.create(RESULT_PROTO), {
|
|
227
|
+
return Object.freeze(Object.assign(Object.create(RESULT_PROTO), {
|
|
221
228
|
tag: "Ok",
|
|
222
229
|
value
|
|
223
|
-
});
|
|
230
|
+
}));
|
|
224
231
|
}
|
|
225
232
|
/**
|
|
226
233
|
* Construct an `Err` result.
|
|
@@ -228,10 +235,10 @@ function okRes(value) {
|
|
|
228
235
|
* @internal
|
|
229
236
|
*/
|
|
230
237
|
function errRes(error) {
|
|
231
|
-
return Object.assign(Object.create(RESULT_PROTO), {
|
|
238
|
+
return Object.freeze(Object.assign(Object.create(RESULT_PROTO), {
|
|
232
239
|
tag: "Err",
|
|
233
240
|
error
|
|
234
|
-
});
|
|
241
|
+
}));
|
|
235
242
|
}
|
|
236
243
|
/**
|
|
237
244
|
* Construct a `Defect` result.
|
|
@@ -239,10 +246,10 @@ function errRes(error) {
|
|
|
239
246
|
* @internal
|
|
240
247
|
*/
|
|
241
248
|
function defectRes(cause) {
|
|
242
|
-
return Object.assign(Object.create(RESULT_PROTO), {
|
|
249
|
+
return Object.freeze(Object.assign(Object.create(RESULT_PROTO), {
|
|
243
250
|
tag: "Defect",
|
|
244
251
|
cause
|
|
245
|
-
});
|
|
252
|
+
}));
|
|
246
253
|
}
|
|
247
254
|
/**
|
|
248
255
|
* Type guard: is `x` a {@link Result} (any of `Ok` / `Err` / `Defect`)?
|
|
@@ -255,6 +262,20 @@ function defectRes(cause) {
|
|
|
255
262
|
* is not a `Result` and returns `false`.
|
|
256
263
|
*
|
|
257
264
|
* @returns `true` when `x` is a `Result` produced by this library.
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* ```ts
|
|
268
|
+
* import { isResult, Ok } from "unthrown";
|
|
269
|
+
*
|
|
270
|
+
* isResult(Ok(1)); // => true
|
|
271
|
+
* isResult({ tag: "Ok" }); // => false (look-alike, wrong prototype)
|
|
272
|
+
* isResult(Ok(1).toAsync()); // => false (an AsyncResult is not a Result)
|
|
273
|
+
*
|
|
274
|
+
* const x: unknown = Ok(1);
|
|
275
|
+
* if (isResult(x)) x.match({ ok: () => 1, err: () => 0, defect: () => -1 });
|
|
276
|
+
* ```
|
|
277
|
+
*
|
|
278
|
+
* @category Guards
|
|
258
279
|
*/
|
|
259
280
|
function isResult(x) {
|
|
260
281
|
return x instanceof Res;
|
|
@@ -273,6 +294,18 @@ function passThrough(self) {
|
|
|
273
294
|
return self;
|
|
274
295
|
}
|
|
275
296
|
/**
|
|
297
|
+
* A throw inside a *failure observer* (`tapErr` / `tapDefect` / `flatTapErr`)
|
|
298
|
+
* must not destroy the failure being observed — that is the exact place (e.g. a
|
|
299
|
+
* failing error-logger) where losing the underlying failure hurts most. The
|
|
300
|
+
* resulting Defect aggregates both: `errors[0]` is the observer's throw,
|
|
301
|
+
* `errors[1]` the original failure.
|
|
302
|
+
*
|
|
303
|
+
* @internal
|
|
304
|
+
*/
|
|
305
|
+
function observerThrowToDefect(thrown, original) {
|
|
306
|
+
return defectRes(new AggregateError([thrown, original], "unthrown: a failure-observer callback threw; errors[0] is the callback's throw, errors[1] the original failure"));
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
276
309
|
* Validate that a `bind`/`let` scope is a real (non-null) object before merging a
|
|
277
310
|
* key into it.
|
|
278
311
|
*
|
|
@@ -291,7 +324,7 @@ function passThrough(self) {
|
|
|
291
324
|
* @internal
|
|
292
325
|
*/
|
|
293
326
|
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()");
|
|
327
|
+
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
328
|
return value;
|
|
296
329
|
}
|
|
297
330
|
/**
|
|
@@ -419,7 +452,7 @@ var AsyncRes = class AsyncRes {
|
|
|
419
452
|
f(r.error);
|
|
420
453
|
return r;
|
|
421
454
|
} catch (cause) {
|
|
422
|
-
return
|
|
455
|
+
return observerThrowToDefect(cause, r.error);
|
|
423
456
|
}
|
|
424
457
|
}));
|
|
425
458
|
}
|
|
@@ -430,7 +463,7 @@ var AsyncRes = class AsyncRes {
|
|
|
430
463
|
const inner = await f(r.error);
|
|
431
464
|
return inner.tag === "Ok" ? passThrough(r) : passThrough(inner);
|
|
432
465
|
} catch (cause) {
|
|
433
|
-
return
|
|
466
|
+
return observerThrowToDefect(cause, r.error);
|
|
434
467
|
}
|
|
435
468
|
}));
|
|
436
469
|
}
|
|
@@ -451,7 +484,7 @@ var AsyncRes = class AsyncRes {
|
|
|
451
484
|
f(r.cause);
|
|
452
485
|
return r;
|
|
453
486
|
} catch (cause) {
|
|
454
|
-
return
|
|
487
|
+
return observerThrowToDefect(cause, r.cause);
|
|
455
488
|
}
|
|
456
489
|
}));
|
|
457
490
|
}
|
|
@@ -488,8 +521,12 @@ var AsyncRes = class AsyncRes {
|
|
|
488
521
|
* @example
|
|
489
522
|
* ```ts
|
|
490
523
|
* import { Ok } from "unthrown";
|
|
491
|
-
*
|
|
524
|
+
*
|
|
525
|
+
* Ok(2).map((n) => n + 1); // => Ok(3)
|
|
526
|
+
* Ok(42).unwrap(); // => 42
|
|
492
527
|
* ```
|
|
528
|
+
*
|
|
529
|
+
* @category Constructors
|
|
493
530
|
*/
|
|
494
531
|
function Ok(value) {
|
|
495
532
|
return okRes(value);
|
|
@@ -503,8 +540,12 @@ function Ok(value) {
|
|
|
503
540
|
* @example
|
|
504
541
|
* ```ts
|
|
505
542
|
* import { Err } from "unthrown";
|
|
506
|
-
*
|
|
543
|
+
*
|
|
544
|
+
* Err("not_found").map((n) => n + 1); // => Err("not_found") (map skipped)
|
|
545
|
+
* Err("not_found").unwrapErr(); // => "not_found"
|
|
507
546
|
* ```
|
|
547
|
+
*
|
|
548
|
+
* @category Constructors
|
|
508
549
|
*/
|
|
509
550
|
function Err(error) {
|
|
510
551
|
return errRes(error);
|
|
@@ -516,10 +557,16 @@ function Err(error) {
|
|
|
516
557
|
*
|
|
517
558
|
* @example
|
|
518
559
|
* ```ts
|
|
519
|
-
* import { isOk, type Result } from "unthrown";
|
|
560
|
+
* import { isOk, Ok, Err, type Result } from "unthrown";
|
|
561
|
+
*
|
|
562
|
+
* isOk(Ok(1)); // => true
|
|
563
|
+
* isOk(Err("boom")); // => false
|
|
564
|
+
*
|
|
520
565
|
* declare const r: Result<number, string>;
|
|
521
566
|
* if (isOk(r)) r.value; // number, narrowed
|
|
522
567
|
* ```
|
|
568
|
+
*
|
|
569
|
+
* @category Guards
|
|
523
570
|
*/
|
|
524
571
|
function isOk(r) {
|
|
525
572
|
return r.tag === "Ok";
|
|
@@ -528,6 +575,19 @@ function isOk(r) {
|
|
|
528
575
|
* Type guard: narrow a {@link Result} to its `Err` variant, exposing `.error`.
|
|
529
576
|
*
|
|
530
577
|
* @returns `true` when `r` is `Err`.
|
|
578
|
+
*
|
|
579
|
+
* @example
|
|
580
|
+
* ```ts
|
|
581
|
+
* import { isErr, Ok, Err, type Result } from "unthrown";
|
|
582
|
+
*
|
|
583
|
+
* isErr(Err("boom")); // => true
|
|
584
|
+
* isErr(Ok(1)); // => false
|
|
585
|
+
*
|
|
586
|
+
* declare const r: Result<number, string>;
|
|
587
|
+
* if (isErr(r)) r.error; // string, narrowed
|
|
588
|
+
* ```
|
|
589
|
+
*
|
|
590
|
+
* @category Guards
|
|
531
591
|
*/
|
|
532
592
|
function isErr(r) {
|
|
533
593
|
return r.tag === "Err";
|
|
@@ -535,7 +595,27 @@ function isErr(r) {
|
|
|
535
595
|
/**
|
|
536
596
|
* Type guard: narrow a {@link Result} to its `Defect` variant, exposing `.cause`.
|
|
537
597
|
*
|
|
598
|
+
* @remarks
|
|
599
|
+
* A `Defect` has no public constructor — it only arises at a boundary (e.g. a
|
|
600
|
+
* callback throwing inside a combinator). This guard is how you detect one.
|
|
601
|
+
*
|
|
538
602
|
* @returns `true` when `r` is a `Defect`.
|
|
603
|
+
*
|
|
604
|
+
* @example
|
|
605
|
+
* ```ts
|
|
606
|
+
* import { isDefect, Ok } from "unthrown";
|
|
607
|
+
*
|
|
608
|
+
* // A throw inside a combinator is captured as a Defect:
|
|
609
|
+
* const r = Ok(1).map(() => {
|
|
610
|
+
* throw new Error("boom");
|
|
611
|
+
* });
|
|
612
|
+
* isDefect(r); // => true
|
|
613
|
+
* isDefect(Ok(1)); // => false
|
|
614
|
+
*
|
|
615
|
+
* if (isDefect(r)) r.cause; // unknown, narrowed
|
|
616
|
+
* ```
|
|
617
|
+
*
|
|
618
|
+
* @category Guards
|
|
539
619
|
*/
|
|
540
620
|
function isDefect(r) {
|
|
541
621
|
return r.tag === "Defect";
|
|
@@ -563,6 +643,24 @@ function isDefect(r) {
|
|
|
563
643
|
* .map(({ user, org, label }) => render(user, org, label));
|
|
564
644
|
* // Result<View, NotFound>
|
|
565
645
|
* ```
|
|
646
|
+
*
|
|
647
|
+
* @example
|
|
648
|
+
* ```ts
|
|
649
|
+
* import { Do, Ok, Err } from "unthrown";
|
|
650
|
+
*
|
|
651
|
+
* // Ok path — the scope accumulates:
|
|
652
|
+
* Do()
|
|
653
|
+
* .bind("a", () => Ok(2))
|
|
654
|
+
* .let("b", ({ a }) => a * 10)
|
|
655
|
+
* .map(({ a, b }) => a + b); // => Ok(22)
|
|
656
|
+
*
|
|
657
|
+
* // Err path — the first Err short-circuits the rest:
|
|
658
|
+
* Do()
|
|
659
|
+
* .bind("a", () => Err("boom"))
|
|
660
|
+
* .let("b", ({ a }) => a); // => Err("boom")
|
|
661
|
+
* ```
|
|
662
|
+
*
|
|
663
|
+
* @category Do-notation
|
|
566
664
|
*/
|
|
567
665
|
function Do() {
|
|
568
666
|
return Ok({});
|
|
@@ -612,10 +710,16 @@ function isDefectMarker(x) {
|
|
|
612
710
|
* @param value - the possibly-absent value.
|
|
613
711
|
* @param onAbsent - lazily produces the error for the absent case.
|
|
614
712
|
*
|
|
713
|
+
* @category Interop
|
|
714
|
+
*
|
|
615
715
|
* @example
|
|
616
716
|
* ```ts
|
|
617
717
|
* import { fromNullable } from "unthrown";
|
|
618
|
-
*
|
|
718
|
+
*
|
|
719
|
+
* const map = new Map([["a", 1]]);
|
|
720
|
+
* fromNullable(map.get("a"), () => "absent").unwrapOr(0); // => 1
|
|
721
|
+
* fromNullable(map.get("z"), () => "absent"); // => Err("absent")
|
|
722
|
+
* fromNullable(0, () => "absent").unwrapOr(-1); // => 0 (falsy but present)
|
|
619
723
|
* ```
|
|
620
724
|
*/
|
|
621
725
|
function fromNullable(value, onAbsent) {
|
|
@@ -646,11 +750,21 @@ function fromNullable(value, onAbsent) {
|
|
|
646
750
|
* unmodeled by returning `defect(cause)` (the helper passed as its second arg).
|
|
647
751
|
* @returns a function with the same arguments returning `Result<T, E>`.
|
|
648
752
|
*
|
|
753
|
+
* @category Interop
|
|
754
|
+
*
|
|
649
755
|
* @example
|
|
650
756
|
* ```ts
|
|
651
757
|
* import { fromThrowable } from "unthrown";
|
|
652
|
-
*
|
|
653
|
-
* parse
|
|
758
|
+
*
|
|
759
|
+
* // Model the parse failure as an `Err`, everything unexpected as a `Defect`.
|
|
760
|
+
* const parse = fromThrowable(
|
|
761
|
+
* (text: string) => JSON.parse(text) as unknown,
|
|
762
|
+
* (cause, defect) =>
|
|
763
|
+
* cause instanceof SyntaxError ? ("invalid_json" as const) : defect(cause),
|
|
764
|
+
* );
|
|
765
|
+
*
|
|
766
|
+
* parse('{"ok":true}').unwrapOr(null); // => { ok: true }
|
|
767
|
+
* parse("nope"); // => Err("invalid_json")
|
|
654
768
|
* ```
|
|
655
769
|
*/
|
|
656
770
|
function fromThrowable(fn, qualify) {
|
|
@@ -685,17 +799,24 @@ function fromThrowable(fn, qualify) {
|
|
|
685
799
|
* @param qualify - triages a rejection `cause` into a modeled `E`, or marks it
|
|
686
800
|
* unmodeled by returning `defect(cause)` (the helper passed as its second arg).
|
|
687
801
|
*
|
|
802
|
+
* @category Interop
|
|
803
|
+
*
|
|
688
804
|
* @example
|
|
689
805
|
* ```ts
|
|
690
806
|
* import { fromPromise } from "unthrown";
|
|
807
|
+
*
|
|
808
|
+
* // A rejection with a NotFoundError becomes a modeled `Err`; anything else a Defect.
|
|
691
809
|
* const user = await fromPromise(fetchUser(id), (cause, defect) =>
|
|
692
810
|
* cause instanceof NotFoundError ? ("not_found" as const) : defect(cause),
|
|
693
811
|
* );
|
|
812
|
+
*
|
|
813
|
+
* if (user.isOk()) user.value; // => the fetched user
|
|
814
|
+
* // when fetchUser rejects with NotFoundError: user is Err("not_found")
|
|
694
815
|
* ```
|
|
695
816
|
*/
|
|
696
817
|
function fromPromise(promise, qualify) {
|
|
697
818
|
const triage = qualify;
|
|
698
|
-
return new AsyncRes((typeof promise === "function" ? Promise.resolve().then(promise) : promise).then((value) => okRes(value), (cause) => qualifyToResult(cause, triage)));
|
|
819
|
+
return new AsyncRes((typeof promise === "function" ? Promise.resolve().then(promise) : Promise.resolve(promise)).then((value) => okRes(value), (cause) => qualifyToResult(cause, triage)));
|
|
699
820
|
}
|
|
700
821
|
/**
|
|
701
822
|
* Wrap a `Promise` asserted **not** to fail in any modeled way: any rejection
|
|
@@ -708,9 +829,20 @@ function fromPromise(promise, qualify) {
|
|
|
708
829
|
*
|
|
709
830
|
* @typeParam T - the resolved value type.
|
|
710
831
|
* @param promise - the promise, or a thunk returning one.
|
|
832
|
+
*
|
|
833
|
+
* @category Interop
|
|
834
|
+
*
|
|
835
|
+
* @example
|
|
836
|
+
* ```ts
|
|
837
|
+
* import { fromSafePromise } from "unthrown";
|
|
838
|
+
*
|
|
839
|
+
* (await fromSafePromise(Promise.resolve(3))).unwrap(); // => 3
|
|
840
|
+
* // a rejection becomes a Defect (never a modeled Err):
|
|
841
|
+
* await fromSafePromise(Promise.reject(new Error("boom"))); // => Defect(Error("boom"))
|
|
842
|
+
* ```
|
|
711
843
|
*/
|
|
712
844
|
function fromSafePromise(promise) {
|
|
713
|
-
return new AsyncRes((typeof promise === "function" ? Promise.resolve().then(promise) : promise).then((value) => okRes(value), (cause) => defectRes(cause)));
|
|
845
|
+
return new AsyncRes((typeof promise === "function" ? Promise.resolve().then(promise) : Promise.resolve(promise)).then((value) => okRes(value), (cause) => defectRes(cause)));
|
|
714
846
|
}
|
|
715
847
|
function qualifyToResult(cause, qualify) {
|
|
716
848
|
try {
|
|
@@ -748,8 +880,10 @@ function foldRecord(results) {
|
|
|
748
880
|
let firstErr;
|
|
749
881
|
let firstDefect;
|
|
750
882
|
const values = {};
|
|
751
|
-
for (const [key, r] of Object.entries(results)) if (r.tag === "Defect")
|
|
752
|
-
|
|
883
|
+
for (const [key, r] of Object.entries(results)) if (r.tag === "Defect") {
|
|
884
|
+
firstDefect ??= r;
|
|
885
|
+
break;
|
|
886
|
+
} else if (r.tag === "Err") firstErr ??= r;
|
|
753
887
|
else Object.defineProperty(values, key, {
|
|
754
888
|
value: r.value,
|
|
755
889
|
enumerable: true,
|
|
@@ -770,11 +904,14 @@ function foldRecord(results) {
|
|
|
770
904
|
* collapses to `Result<T[], E>` with no cast. For a **record** keyed by name,
|
|
771
905
|
* use {@link allFromDict}.
|
|
772
906
|
*
|
|
907
|
+
* @category Aggregate
|
|
908
|
+
*
|
|
773
909
|
* @example
|
|
774
910
|
* ```ts
|
|
775
|
-
* import { all, Ok } from "unthrown";
|
|
776
|
-
*
|
|
777
|
-
* all([Ok(1), Ok(
|
|
911
|
+
* import { all, Ok, Err } from "unthrown";
|
|
912
|
+
*
|
|
913
|
+
* all([Ok(1), Ok("a"), Ok(true)]).unwrap(); // => [1, "a", true] (typed [number, string, boolean])
|
|
914
|
+
* all([Ok(1), Err("e"), Ok(3)]); // => Err("e") (short-circuits on the first Err)
|
|
778
915
|
* ```
|
|
779
916
|
*/
|
|
780
917
|
function all(results) {
|
|
@@ -790,10 +927,14 @@ function all(results) {
|
|
|
790
927
|
* Same folding rules as {@link all}: first `Err` short-circuits, any `Defect`
|
|
791
928
|
* dominates. This is **not** error accumulation.
|
|
792
929
|
*
|
|
930
|
+
* @category Aggregate
|
|
931
|
+
*
|
|
793
932
|
* @example
|
|
794
933
|
* ```ts
|
|
795
|
-
* import { allFromDict, Ok } from "unthrown";
|
|
796
|
-
*
|
|
934
|
+
* import { allFromDict, Ok, Err } from "unthrown";
|
|
935
|
+
*
|
|
936
|
+
* allFromDict({ id: Ok(1), name: Ok("ada") }).unwrap(); // => { id: 1, name: "ada" }
|
|
937
|
+
* allFromDict({ id: Ok(1), name: Err("missing") }); // => Err("missing")
|
|
797
938
|
* ```
|
|
798
939
|
*/
|
|
799
940
|
function allFromDict(results) {
|
|
@@ -809,10 +950,14 @@ function allFromDict(results) {
|
|
|
809
950
|
* short-circuits, any `Defect` dominates. As ever, the returned `AsyncResult`'s
|
|
810
951
|
* internal promise never rejects. For a **record**, use {@link allFromDictAsync}.
|
|
811
952
|
*
|
|
953
|
+
* @category Aggregate
|
|
954
|
+
*
|
|
812
955
|
* @example
|
|
813
956
|
* ```ts
|
|
814
957
|
* import { allAsync, fromSafePromise } from "unthrown";
|
|
815
|
-
*
|
|
958
|
+
*
|
|
959
|
+
* const both = allAsync([fromSafePromise(Promise.resolve(1)), fromSafePromise(Promise.resolve(2))]);
|
|
960
|
+
* (await both).unwrap(); // => [1, 2]
|
|
816
961
|
* ```
|
|
817
962
|
*/
|
|
818
963
|
function allAsync(results) {
|
|
@@ -826,10 +971,17 @@ function allAsync(results) {
|
|
|
826
971
|
* Resolved concurrently (order preserved), folded with the {@link all} rules,
|
|
827
972
|
* and the internal promise never rejects.
|
|
828
973
|
*
|
|
974
|
+
* @category Aggregate
|
|
975
|
+
*
|
|
829
976
|
* @example
|
|
830
977
|
* ```ts
|
|
831
978
|
* import { allFromDictAsync, fromSafePromise } from "unthrown";
|
|
832
|
-
*
|
|
979
|
+
*
|
|
980
|
+
* const both = allFromDictAsync({
|
|
981
|
+
* a: fromSafePromise(Promise.resolve(1)),
|
|
982
|
+
* b: fromSafePromise(Promise.resolve("x")),
|
|
983
|
+
* });
|
|
984
|
+
* (await both).unwrap(); // => { a: 1, b: "x" }
|
|
833
985
|
* ```
|
|
834
986
|
*/
|
|
835
987
|
function allFromDictAsync(results) {
|
|
@@ -861,10 +1013,12 @@ function allFromDictAsync(results) {
|
|
|
861
1013
|
* (`AsyncResult.fromPromise`, `AsyncResult.all`, …), grouped by what they
|
|
862
1014
|
* return — a static lives in exactly one namespace.
|
|
863
1015
|
*
|
|
1016
|
+
* @category Facade
|
|
1017
|
+
*
|
|
864
1018
|
* @example
|
|
865
1019
|
* ```ts
|
|
866
1020
|
* import { Result } from "unthrown";
|
|
867
|
-
* Result.Ok(1).flatMap((n) => Result.Ok(n + 1)).unwrap(); // 2
|
|
1021
|
+
* Result.Ok(1).flatMap((n) => Result.Ok(n + 1)).unwrap(); // => 2
|
|
868
1022
|
* ```
|
|
869
1023
|
*/
|
|
870
1024
|
const Result = {
|
|
@@ -895,10 +1049,13 @@ const Result = {
|
|
|
895
1049
|
* {@link Result}, the free functions remain the primary, tree-shakeable API; the
|
|
896
1050
|
* value `AsyncResult` and the type {@link AsyncResult} share one name.
|
|
897
1051
|
*
|
|
1052
|
+
* @category Facade
|
|
1053
|
+
*
|
|
898
1054
|
* @example
|
|
899
1055
|
* ```ts
|
|
900
1056
|
* import { AsyncResult } from "unthrown";
|
|
901
1057
|
* const user = await AsyncResult.fromPromise(fetchUser(id), (c, defect) => defect(c));
|
|
1058
|
+
* user.unwrap(); // => the fetched user (on success)
|
|
902
1059
|
* ```
|
|
903
1060
|
*/
|
|
904
1061
|
const AsyncResult = {
|
|
@@ -915,9 +1072,17 @@ const AsyncResult = {
|
|
|
915
1072
|
*
|
|
916
1073
|
* @remarks
|
|
917
1074
|
* Extend the returned class to declare a concrete error. Supply the payload with
|
|
918
|
-
* an instantiation expression; omit it for a payload-less error.
|
|
919
|
-
*
|
|
920
|
-
*
|
|
1075
|
+
* an instantiation expression; omit it for a payload-less error. The `message`
|
|
1076
|
+
* is **not** a payload field — it is the human string owned by `Error`, not
|
|
1077
|
+
* structured data, so it is reserved. Define it once per subclass the standard
|
|
1078
|
+
* way, `override message = "…"` (it may interpolate the payload via `this`,
|
|
1079
|
+
* which the base populates before the subclass field initialiser runs); a
|
|
1080
|
+
* payload `message` is rejected at compile time, so contextual detail lives in
|
|
1081
|
+
* typed fields, never baked into per-call prose. The `_tag` always reflects
|
|
1082
|
+
* `tag` and cannot be overridden by the payload. `name` is likewise reserved —
|
|
1083
|
+
* it is the display label (set it with `options.name`); a payload `name` is
|
|
1084
|
+
* rejected at compile time (and excluded from the instance type), so it can't
|
|
1085
|
+
* shadow `Error.name`.
|
|
921
1086
|
*
|
|
922
1087
|
* `_tag` is the discriminant used by {@link matchTags}; `Error.name` is the
|
|
923
1088
|
* human-facing label in stack traces and logs. By default they coincide, but
|
|
@@ -928,11 +1093,14 @@ const AsyncResult = {
|
|
|
928
1093
|
* ```ts
|
|
929
1094
|
* class RetryableError extends TaggedError("@my-lib/RetryableError", {
|
|
930
1095
|
* name: "RetryableError",
|
|
931
|
-
* })
|
|
1096
|
+
* }) {
|
|
1097
|
+
* override message = "operation failed; safe to retry";
|
|
1098
|
+
* }
|
|
932
1099
|
*
|
|
933
|
-
* const e = new RetryableError(
|
|
934
|
-
* e._tag;
|
|
935
|
-
* e.name;
|
|
1100
|
+
* const e = new RetryableError();
|
|
1101
|
+
* e._tag; // "@my-lib/RetryableError" — namespaced discriminant
|
|
1102
|
+
* e.name; // "RetryableError" — clean display name
|
|
1103
|
+
* e.message; // "operation failed; safe to retry" — the standard Error.message
|
|
936
1104
|
* ```
|
|
937
1105
|
*
|
|
938
1106
|
* @typeParam Tag - the string literal discriminant.
|
|
@@ -940,13 +1108,15 @@ const AsyncResult = {
|
|
|
940
1108
|
* @param options - optional overrides. `options.name` sets `Error.name`
|
|
941
1109
|
* independently of `tag` (defaults to `tag`).
|
|
942
1110
|
*
|
|
1111
|
+
* @category Tagged errors
|
|
1112
|
+
*
|
|
943
1113
|
* @example
|
|
944
1114
|
* ```ts
|
|
945
1115
|
* class NotFound extends TaggedError("NotFound") {}
|
|
946
1116
|
* class HttpError extends TaggedError("HttpError")<{ status: number }> {}
|
|
947
1117
|
*
|
|
948
|
-
* new NotFound()._tag; // "NotFound"
|
|
949
|
-
* new HttpError({ status: 500 }).status; // 500
|
|
1118
|
+
* new NotFound()._tag; // => "NotFound"
|
|
1119
|
+
* new HttpError({ status: 500 }).status; // => 500
|
|
950
1120
|
* ```
|
|
951
1121
|
*/
|
|
952
1122
|
function TaggedError(tag, options) {
|
|
@@ -954,10 +1124,11 @@ function TaggedError(tag, options) {
|
|
|
954
1124
|
class TaggedErrorBase extends Error {
|
|
955
1125
|
_tag;
|
|
956
1126
|
constructor(props) {
|
|
957
|
-
super(
|
|
1127
|
+
super();
|
|
958
1128
|
if (props) Object.assign(this, props);
|
|
959
1129
|
this._tag = tag;
|
|
960
1130
|
this.name = displayName;
|
|
1131
|
+
delete this.message;
|
|
961
1132
|
Object.setPrototypeOf(this, new.target.prototype);
|
|
962
1133
|
}
|
|
963
1134
|
}
|
|
@@ -965,8 +1136,9 @@ function TaggedError(tag, options) {
|
|
|
965
1136
|
}
|
|
966
1137
|
function matchTags(result, handlers) {
|
|
967
1138
|
const onErr = (error) => {
|
|
968
|
-
const
|
|
969
|
-
|
|
1139
|
+
const tag = error._tag;
|
|
1140
|
+
const handler = tag === "Ok" || tag === "Defect" || !Object.hasOwn(handlers, tag) ? void 0 : handlers[tag];
|
|
1141
|
+
return handler ? handler(error) : handlers.Defect(error);
|
|
970
1142
|
};
|
|
971
1143
|
return result.match({
|
|
972
1144
|
ok: handlers.Ok,
|