@shirudo/result 1.1.0 → 1.2.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 +90 -38
- package/dist/collections.cjs +181 -9
- package/dist/collections.cjs.map +1 -0
- package/dist/collections.d.cts +101 -3
- package/dist/collections.d.cts.map +1 -0
- package/dist/collections.d.mts +101 -3
- package/dist/collections.d.mts.map +1 -0
- package/dist/collections.mjs +175 -3
- package/dist/collections.mjs.map +1 -0
- package/dist/errors-CVgC7NII.cjs +278 -0
- package/dist/errors-CVgC7NII.cjs.map +1 -0
- package/dist/errors-MuakEcnM.mjs +146 -0
- package/dist/errors-MuakEcnM.mjs.map +1 -0
- package/dist/errors.cjs +22 -130
- package/dist/errors.d.cts +9 -9
- package/dist/errors.d.cts.map +1 -1
- package/dist/errors.d.mts +9 -9
- package/dist/errors.d.mts.map +1 -1
- package/dist/errors.mjs +2 -109
- package/dist/index.cjs +99 -69
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +87 -74
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +87 -74
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +64 -34
- package/dist/index.mjs.map +1 -1
- package/dist/operators.cjs +412 -31
- package/dist/operators.cjs.map +1 -0
- package/dist/operators.d.cts +211 -3
- package/dist/operators.d.cts.map +1 -0
- package/dist/operators.d.mts +211 -3
- package/dist/operators.d.mts.map +1 -0
- package/dist/operators.mjs +384 -3
- package/dist/operators.mjs.map +1 -0
- package/dist/{result-q9Na2bGa.mjs → result-DQCpkuOJ.mjs} +36 -17
- package/dist/result-DQCpkuOJ.mjs.map +1 -0
- package/dist/{result-BBOGxvSH.cjs → result-DoqQufvR.cjs} +36 -17
- package/dist/result-DoqQufvR.cjs.map +1 -0
- package/dist/{sequence-DDwePRLd.d.cts → sequence-CmugKPbu.d.cts} +105 -84
- package/dist/sequence-CmugKPbu.d.cts.map +1 -0
- package/dist/{sequence-DDwePRLd.d.mts → sequence-CmugKPbu.d.mts} +105 -84
- package/dist/sequence-CmugKPbu.d.mts.map +1 -0
- package/package.json +20 -12
- package/dist/errors.cjs.map +0 -1
- package/dist/errors.mjs.map +0 -1
- package/dist/flatten-B_XIkaOK.cjs +0 -208
- package/dist/flatten-B_XIkaOK.cjs.map +0 -1
- package/dist/flatten-C7D6Kttf.d.mts +0 -81
- package/dist/flatten-C7D6Kttf.d.mts.map +0 -1
- package/dist/flatten-ChTL5BfA.mjs +0 -167
- package/dist/flatten-ChTL5BfA.mjs.map +0 -1
- package/dist/flatten-D0K8UcQH.d.cts +0 -81
- package/dist/flatten-D0K8UcQH.d.cts.map +0 -1
- package/dist/result-BBOGxvSH.cjs.map +0 -1
- package/dist/result-q9Na2bGa.mjs.map +0 -1
- package/dist/sequence-DDwePRLd.d.cts.map +0 -1
- package/dist/sequence-DDwePRLd.d.mts.map +0 -1
- package/dist/swap-BnyMBdD_.cjs +0 -552
- package/dist/swap-BnyMBdD_.cjs.map +0 -1
- package/dist/swap-CFD2g1cB.mjs +0 -385
- package/dist/swap-CFD2g1cB.mjs.map +0 -1
- package/dist/swap-CrHQZIax.d.cts +0 -212
- package/dist/swap-CrHQZIax.d.cts.map +0 -1
- package/dist/swap-DT4LdRFV.d.mts +0 -212
- package/dist/swap-DT4LdRFV.d.mts.map +0 -1
package/dist/collections.d.mts
CHANGED
|
@@ -1,3 +1,101 @@
|
|
|
1
|
-
import { n as sequence, t as all } from "./sequence-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { E as Awaitable, n as sequence, s as Result, t as all } from "./sequence-CmugKPbu.mjs";
|
|
2
|
+
//#region src/core/sequenceRecord.d.ts
|
|
3
|
+
type OkValueOf$3<R> = R extends Result<infer T, any> ? T : never;
|
|
4
|
+
type ErrValueOf$3<R> = R extends Result<any, infer E> ? E : never;
|
|
5
|
+
/**
|
|
6
|
+
* Like `sequence`, but for Records/Objects.
|
|
7
|
+
* Short-circuits on the first Err.
|
|
8
|
+
*
|
|
9
|
+
* A non-enumerable own property is an input only when it holds a `Result`, so a
|
|
10
|
+
* hidden helper field of another type is ignored. An array throws, because its
|
|
11
|
+
* indices would sequence into an object; use `sequence` for a list.
|
|
12
|
+
*/
|
|
13
|
+
declare function sequenceRecord<const R extends { readonly [K in keyof R]: Result<any, any>; }>(record: R): Result<{ [K in keyof R]: OkValueOf$3<R[K]>; }, ErrValueOf$3<R[keyof R]>>;
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/core/collectFirstOk.d.ts
|
|
16
|
+
type OkValueOf$2<R> = R extends Result<infer T, any> ? T : never;
|
|
17
|
+
type ErrValueOf$2<R> = R extends Result<any, infer E> ? E : never;
|
|
18
|
+
/**
|
|
19
|
+
* Parse a set of `Result`s, short-circuits when an input value is `Ok`.
|
|
20
|
+
* If no `Ok` is found, returns an `Err` containing the collected error values.
|
|
21
|
+
* Useful for "try multiple approaches until one works" patterns.
|
|
22
|
+
*/
|
|
23
|
+
declare function collectFirstOk<const Results extends readonly Result<any, any>[]>(results: Results): Result<OkValueOf$2<Results[number]>, ErrValueOf$2<Results[number]>[]>;
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/core/collectFirstOkAsync.d.ts
|
|
26
|
+
type CollectFirstOkAsyncInput$1 = Promise<Result<any, any>> | (() => Awaitable<Result<any, any>>);
|
|
27
|
+
type ResolvedResult$1<I> = I extends (() => infer R) ? Awaited<R> : I extends Promise<infer R> ? R : never;
|
|
28
|
+
type OkValueOfInput$1<I> = ResolvedResult$1<I> extends Result<infer T, any> ? T : never;
|
|
29
|
+
type ErrValueOfInput$1<I> = ResolvedResult$1<I> extends Result<any, infer E> ? E : never;
|
|
30
|
+
/**
|
|
31
|
+
* Async version of collectFirstOk.
|
|
32
|
+
*
|
|
33
|
+
* - Takes either already started Promises or "Thunks" (`() => Awaitable<Result<...>>`).
|
|
34
|
+
* A thunk that throws synchronously is a programmer error: the call rejects
|
|
35
|
+
* with that exception.
|
|
36
|
+
* - Processes inputs strictly sequentially (like `for ... of` + `await`).
|
|
37
|
+
* - Returns the first `Ok` and collects all errors if no `Ok` is found.
|
|
38
|
+
* - A fulfilled value that is not a `Result` is a programmer error: the call
|
|
39
|
+
* rejects with `InvalidResultStateError`.
|
|
40
|
+
* - A rejected input counts as a failed attempt. Without `errorMapper` the
|
|
41
|
+
* collected errors are `unknown[]`, because a rejection reason can be
|
|
42
|
+
* anything. `errorMapper` turns each rejection reason into a typed error;
|
|
43
|
+
* `Err` values pass through untouched, and bugs inside the mapper are rethrown.
|
|
44
|
+
*/
|
|
45
|
+
declare function collectFirstOkAsync<const Inputs extends readonly CollectFirstOkAsyncInput$1[]>(inputs: Inputs): Promise<Result<OkValueOfInput$1<Inputs[number]>, unknown[]>>;
|
|
46
|
+
declare function collectFirstOkAsync<const Inputs extends readonly CollectFirstOkAsyncInput$1[], F>(inputs: Inputs, errorMapper: (error: unknown) => F): Promise<Result<OkValueOfInput$1<Inputs[number]>, Array<ErrValueOfInput$1<Inputs[number]> | F>>>;
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/core/collectFirstOkParallelAsync.d.ts
|
|
49
|
+
type CollectFirstOkAsyncInput = Promise<Result<any, any>> | (() => Awaitable<Result<any, any>>);
|
|
50
|
+
type ResolvedResult<I> = I extends (() => infer R) ? Awaited<R> : I extends Promise<infer R> ? R : never;
|
|
51
|
+
type OkValueOfInput<I> = ResolvedResult<I> extends Result<infer T, any> ? T : never;
|
|
52
|
+
type ErrValueOfInput<I> = ResolvedResult<I> extends Result<any, infer E> ? E : never;
|
|
53
|
+
/**
|
|
54
|
+
* Parallel version of `collectFirstOkAsync`.
|
|
55
|
+
*
|
|
56
|
+
* - Starts all inputs immediately (Promises or Thunks). A thunk that throws
|
|
57
|
+
* synchronously is a programmer error: the call rejects with that exception,
|
|
58
|
+
* as `collectFirstOkAsync` does.
|
|
59
|
+
* - Returns the first `Ok` as soon as it is available.
|
|
60
|
+
* - If no `Ok` is found, returns an `Err` with all error values (in input order).
|
|
61
|
+
* - A fulfilled value that is not a `Result` is a programmer error: the call
|
|
62
|
+
* rejects with `InvalidResultStateError`, unless an `Ok` already won the race.
|
|
63
|
+
* - A rejected input counts as a failed attempt. Without `errorMapper` the
|
|
64
|
+
* collected errors are `unknown[]`, because a rejection reason can be
|
|
65
|
+
* anything. `errorMapper` turns each rejection reason into a typed error;
|
|
66
|
+
* `Err` values pass through untouched, and bugs inside the mapper are rethrown.
|
|
67
|
+
* - If multiple inputs provide an `Ok`, the one that completes first wins.
|
|
68
|
+
* In case of simultaneous completion, the first observed result wins.
|
|
69
|
+
* - If no `Ok` arrives and at least one input never settles, the Promise remains pending.
|
|
70
|
+
*/
|
|
71
|
+
declare function collectFirstOkParallelAsync<const Inputs extends readonly CollectFirstOkAsyncInput[]>(inputs: Inputs): Promise<Result<OkValueOfInput<Inputs[number]>, unknown[]>>;
|
|
72
|
+
declare function collectFirstOkParallelAsync<const Inputs extends readonly CollectFirstOkAsyncInput[], F>(inputs: Inputs, errorMapper: (error: unknown) => F): Promise<Result<OkValueOfInput<Inputs[number]>, Array<ErrValueOfInput<Inputs[number]> | F>>>;
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/core/collectAllErrors.d.ts
|
|
75
|
+
type OkValueOf$1<R> = R extends Result<infer T, any> ? T : never;
|
|
76
|
+
type ErrValueOf$1<R> = R extends Result<any, infer E> ? E : never;
|
|
77
|
+
type CollectionValues<Results extends readonly Result<any, any>[]> = { -readonly [K in keyof Results]: OkValueOf$1<Results[K]>; };
|
|
78
|
+
/**
|
|
79
|
+
* Combines a list of Results.
|
|
80
|
+
* Return Ok(values) only if all are Ok, otherwise Err([errors]).
|
|
81
|
+
*/
|
|
82
|
+
declare function collectAllErrors<const Results extends readonly Result<any, any>[]>(results: Results): Result<CollectionValues<Results>, Array<ErrValueOf$1<Results[number]>>>;
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/core/partition.d.ts
|
|
85
|
+
type OkValueOf<R> = R extends Result<infer T, any> ? T : never;
|
|
86
|
+
type ErrValueOf<R> = R extends Result<any, infer E> ? E : never;
|
|
87
|
+
/**
|
|
88
|
+
* Partitions Results into Ok values and Err errors.
|
|
89
|
+
*/
|
|
90
|
+
declare function partition<const Results extends readonly Result<any, any>[]>(results: Results): [oks: Array<OkValueOf<Results[number]>>, errs: Array<ErrValueOf<Results[number]>>];
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/core/flatten.d.ts
|
|
93
|
+
/**
|
|
94
|
+
* Flattens a nested Result.
|
|
95
|
+
* Result<Result<T, E>, E> → Result<T, E>
|
|
96
|
+
* Corresponds to Rust `flatten`.
|
|
97
|
+
*/
|
|
98
|
+
declare function flatten<T, E>(result: Result<Result<T, E>, E>): Result<T, E>;
|
|
99
|
+
//#endregion
|
|
100
|
+
export { all, collectAllErrors, collectFirstOk, collectFirstOkAsync, collectFirstOkParallelAsync, flatten, partition, sequence, sequenceRecord };
|
|
101
|
+
//# sourceMappingURL=collections.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collections.d.mts","names":[],"sources":["../src/core/sequenceRecord.ts","../src/core/collectFirstOk.ts","../src/core/collectFirstOkAsync.ts","../src/core/collectFirstOkParallelAsync.ts","../src/core/collectAllErrors.ts","../src/core/partition.ts","../src/core/flatten.ts"],"mappings":";;KAKK,YAAU,KAAK,UAAU,aAAa,UAAU;KAChD,aAAW,KAAK,UAAU,kBAAkB,KAAK;;;;;;;;;iBAUtC,qBAAqB,sBAAsB,WAAW,IAAI,qBACtE,QAAQ,IACT,UAAU,WAAW,IAAI,YAAU,EAAE,QAAO,aAAW,QAAQ;;;KCd7D,YAAU,KAAK,UAAU,aAAa,UAAU;KAChD,aAAW,KAAK,UAAU,kBAAkB,KAAK;;;;;;iBAOtC,qBAAqB,yBAAyB,oBAC1D,SAAS,UACV,OAAO,YAAU,kBAAkB,aAAW;;;KCR5C,6BACC,QAAQ,2BACD,UAAU;KAElB,iBAAe,KAAK,uBAAsB,KAAI,QA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@@ -1,4 +1,176 @@
|
|
|
1
|
-
import { g as sequence, h as all } from "./result-
|
|
2
|
-
import {
|
|
1
|
+
import { c as ok, g as sequence, h as all, i as err, v as isResult } from "./result-DQCpkuOJ.mjs";
|
|
2
|
+
import { p as InvalidResultStateError } from "./errors-MuakEcnM.mjs";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
//#region src/core/sequenceRecord.ts
|
|
5
|
+
/**
|
|
6
|
+
* Like `sequence`, but for Records/Objects.
|
|
7
|
+
* Short-circuits on the first Err.
|
|
8
|
+
*
|
|
9
|
+
* A non-enumerable own property is an input only when it holds a `Result`, so a
|
|
10
|
+
* hidden helper field of another type is ignored. An array throws, because its
|
|
11
|
+
* indices would sequence into an object; use `sequence` for a list.
|
|
12
|
+
*/
|
|
13
|
+
function sequenceRecord(record) {
|
|
14
|
+
if (Array.isArray(record)) throw new InvalidResultStateError("sequenceRecord");
|
|
15
|
+
const out = {};
|
|
16
|
+
for (const key of Reflect.ownKeys(record)) {
|
|
17
|
+
const result = record[key];
|
|
18
|
+
if (!isResult(result)) {
|
|
19
|
+
if (!Object.getOwnPropertyDescriptor(record, key)?.enumerable) continue;
|
|
20
|
+
throw new InvalidResultStateError("sequenceRecord");
|
|
21
|
+
}
|
|
22
|
+
if (result.isOk()) {
|
|
23
|
+
out[key] = result.value;
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (result.isErr()) return result;
|
|
27
|
+
throw new InvalidResultStateError("sequenceRecord");
|
|
28
|
+
}
|
|
29
|
+
return ok(out);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/core/collectFirstOk.ts
|
|
34
|
+
/**
|
|
35
|
+
* Parse a set of `Result`s, short-circuits when an input value is `Ok`.
|
|
36
|
+
* If no `Ok` is found, returns an `Err` containing the collected error values.
|
|
37
|
+
* Useful for "try multiple approaches until one works" patterns.
|
|
38
|
+
*/
|
|
39
|
+
function collectFirstOk(results) {
|
|
40
|
+
const errors = [];
|
|
41
|
+
for (const result of results) {
|
|
42
|
+
if (result.isOk()) return ok(result.value);
|
|
43
|
+
if (result.isErr()) {
|
|
44
|
+
errors.push(result.error);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
throw new InvalidResultStateError("collectFirstOk");
|
|
48
|
+
}
|
|
49
|
+
return err(errors);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/core/collectFirstOkAsync.ts
|
|
54
|
+
async function collectFirstOkAsync(inputs, errorMapper) {
|
|
55
|
+
const errors = [];
|
|
56
|
+
for (const input of inputs) {
|
|
57
|
+
const pendingResult = typeof input === "function" ? input() : input;
|
|
58
|
+
let result;
|
|
59
|
+
try {
|
|
60
|
+
result = await pendingResult;
|
|
61
|
+
} catch (error) {
|
|
62
|
+
errors.push(errorMapper ? errorMapper(error) : error);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (isResult(result)) {
|
|
66
|
+
if (result.isOk()) return ok(result.value);
|
|
67
|
+
if (result.isErr()) {
|
|
68
|
+
errors.push(result.error);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
throw new InvalidResultStateError("collectFirstOkAsync");
|
|
73
|
+
}
|
|
74
|
+
return err(errors);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/core/collectFirstOkParallelAsync.ts
|
|
79
|
+
async function collectFirstOkParallelAsync(inputs, errorMapper) {
|
|
80
|
+
if (inputs.length === 0) return err([]);
|
|
81
|
+
const started = [];
|
|
82
|
+
try {
|
|
83
|
+
for (const input of inputs) started.push(typeof input === "function" ? Promise.resolve(input()) : input);
|
|
84
|
+
} catch (bug) {
|
|
85
|
+
for (const promise of started) promise.catch(() => {});
|
|
86
|
+
throw bug;
|
|
87
|
+
}
|
|
88
|
+
const firstOk = new Promise((resolve, reject) => {
|
|
89
|
+
for (const promise of started) promise.then((value) => {
|
|
90
|
+
if (!isResult(value)) reject(new InvalidResultStateError("collectFirstOkParallelAsync"));
|
|
91
|
+
else if (value.isOk()) resolve(ok(value.value));
|
|
92
|
+
}, () => {});
|
|
93
|
+
});
|
|
94
|
+
const allErrors = Promise.allSettled(started).then((settled) => {
|
|
95
|
+
const errors = [];
|
|
96
|
+
for (const entry of settled) {
|
|
97
|
+
if (entry.status === "rejected") {
|
|
98
|
+
errors.push(errorMapper ? errorMapper(entry.reason) : entry.reason);
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const result = entry.value;
|
|
102
|
+
if (isResult(result)) {
|
|
103
|
+
if (result.isErr()) {
|
|
104
|
+
errors.push(result.error);
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (result.isOk()) continue;
|
|
108
|
+
}
|
|
109
|
+
throw new InvalidResultStateError("collectFirstOkParallelAsync");
|
|
110
|
+
}
|
|
111
|
+
return err(errors);
|
|
112
|
+
});
|
|
113
|
+
return Promise.race([firstOk, allErrors]);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/core/collectAllErrors.ts
|
|
118
|
+
/**
|
|
119
|
+
* Combines a list of Results.
|
|
120
|
+
* Return Ok(values) only if all are Ok, otherwise Err([errors]).
|
|
121
|
+
*/
|
|
122
|
+
function collectAllErrors(results) {
|
|
123
|
+
const values = [];
|
|
124
|
+
const errors = [];
|
|
125
|
+
for (const result of results) {
|
|
126
|
+
if (result.isOk()) {
|
|
127
|
+
values.push(result.value);
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (result.isErr()) {
|
|
131
|
+
errors.push(result.error);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
throw new InvalidResultStateError("collectAllErrors");
|
|
135
|
+
}
|
|
136
|
+
return errors.length === 0 ? ok(values) : err(errors);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region src/core/partition.ts
|
|
141
|
+
/**
|
|
142
|
+
* Partitions Results into Ok values and Err errors.
|
|
143
|
+
*/
|
|
144
|
+
function partition(results) {
|
|
145
|
+
const oks = [];
|
|
146
|
+
const errs = [];
|
|
147
|
+
for (const result of results) {
|
|
148
|
+
if (result.isOk()) {
|
|
149
|
+
oks.push(result.value);
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
if (result.isErr()) {
|
|
153
|
+
errs.push(result.error);
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
throw new InvalidResultStateError("partition");
|
|
157
|
+
}
|
|
158
|
+
return [oks, errs];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
//#endregion
|
|
162
|
+
//#region src/core/flatten.ts
|
|
163
|
+
/**
|
|
164
|
+
* Flattens a nested Result.
|
|
165
|
+
* Result<Result<T, E>, E> → Result<T, E>
|
|
166
|
+
* Corresponds to Rust `flatten`.
|
|
167
|
+
*/
|
|
168
|
+
function flatten(result) {
|
|
169
|
+
if (result.isOk()) return result.value;
|
|
170
|
+
if (result.isErr()) return result;
|
|
171
|
+
throw new InvalidResultStateError("flatten");
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
//#endregion
|
|
175
|
+
export { all, collectAllErrors, collectFirstOk, collectFirstOkAsync, collectFirstOkParallelAsync, flatten, partition, sequence, sequenceRecord };
|
|
176
|
+
//# sourceMappingURL=collections.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collections.mjs","names":[],"sources":["../src/core/sequenceRecord.ts","../src/core/collectFirstOk.ts","../src/core/collectFirstOkAsync.ts","../src/core/collectFirstOkParallelAsync.ts","../src/core/collectAllErrors.ts","../src/core/partition.ts","../src/core/flatten.ts"],"sourcesContent":["import type { Result } from './result';\nimport { ok } from './result';\nimport { InvalidResultStateError } from '../errors';\nimport { isResult } from './isResult';\n\ntype OkValueOf<R> = R extends Result<infer T, any> ? T : never;\ntype ErrValueOf<R> = R extends Result<any, infer E> ? E : never;\n\n/**\n * Like `sequence`, but for Records/Objects.\n * Short-circuits on the first Err.\n *\n * A non-enumerable own property is an input only when it holds a `Result`, so a\n * hidden helper field of another type is ignored. An array throws, because its\n * indices would sequence into an object; use `sequence` for a list.\n */\nexport function sequenceRecord<const R extends { readonly [K in keyof R]: Result<any, any> }>(\n record: R\n): Result<{ [K in keyof R]: OkValueOf<R[K]> }, ErrValueOf<R[keyof R]>> {\n type Out = { [K in keyof R]: OkValueOf<R[K]> };\n type E = ErrValueOf<R[keyof R]>;\n\n // An array reaches this point only from JavaScript, and it would sequence\n // into an object keyed by its indices: `length` is a non-enumerable\n // non-Result and the rule below would skip it. A list of Results belongs to\n // `sequence()`, so the mistake fails here instead of returning a wrong shape.\n if (Array.isArray(record)) throw new InvalidResultStateError('sequenceRecord');\n\n const out: Partial<Out> = {};\n\n // `Reflect.ownKeys` keeps the symbol keys, which the signature supports, and\n // it also visits the non-enumerable properties. `keyof R` sees those too, so\n // a hidden Result stays an input. A hidden value of another type is a helper\n // field that the caller attached, and it is skipped instead of rejected.\n for (const key of Reflect.ownKeys(record) as Array<keyof R>) {\n const result = record[key];\n\n if (!isResult(result)) {\n if (!Object.getOwnPropertyDescriptor(record, key)?.enumerable) continue;\n throw new InvalidResultStateError('sequenceRecord');\n }\n\n if (result.isOk()) {\n out[key] = result.value as Out[typeof key];\n continue;\n }\n if (result.isErr()) return result as unknown as Result<Out, E>;\n throw new InvalidResultStateError('sequenceRecord');\n }\n\n return ok<Out, E>(out as Out);\n}\n","import type { Result } from './result';\nimport { ok, err } from './result';\nimport { InvalidResultStateError } from '../errors';\n\ntype OkValueOf<R> = R extends Result<infer T, any> ? T : never;\ntype ErrValueOf<R> = R extends Result<any, infer E> ? E : never;\n\n/**\n * Parse a set of `Result`s, short-circuits when an input value is `Ok`.\n * If no `Ok` is found, returns an `Err` containing the collected error values.\n * Useful for \"try multiple approaches until one works\" patterns.\n */\nexport function collectFirstOk<const Results extends readonly Result<any, any>[]>(\n results: Results\n): Result<OkValueOf<Results[number]>, ErrValueOf<Results[number]>[]> {\n const errors: Array<ErrValueOf<Results[number]>> = [];\n\n for (const result of results) {\n if (result.isOk()) {\n return ok<OkValueOf<Results[number]>, ErrValueOf<Results[number]>[]>(\n result.value as OkValueOf<Results[number]>\n );\n }\n if (result.isErr()) {\n errors.push(result.error as ErrValueOf<Results[number]>);\n continue;\n }\n throw new InvalidResultStateError('collectFirstOk');\n }\n\n return err<ErrValueOf<Results[number]>[], OkValueOf<Results[number]>>(errors);\n}\n","import type { Result } from './result';\nimport { ok, err } from './result';\nimport type { Awaitable } from './pipeable';\nimport { isResult } from './isResult';\nimport { InvalidResultStateError } from '../errors';\n\ntype CollectFirstOkAsyncInput =\n | Promise<Result<any, any>>\n | (() => Awaitable<Result<any, any>>);\n\ntype ResolvedResult<I> = I extends () => infer R ? Awaited<R> : I extends Promise<infer R> ? R : never;\ntype OkValueOfInput<I> = ResolvedResult<I> extends Result<infer T, any> ? T : never;\ntype ErrValueOfInput<I> = ResolvedResult<I> extends Result<any, infer E> ? E : never;\n\n/**\n * Async version of collectFirstOk.\n *\n * - Takes either already started Promises or \"Thunks\" (`() => Awaitable<Result<...>>`).\n * A thunk that throws synchronously is a programmer error: the call rejects\n * with that exception.\n * - Processes inputs strictly sequentially (like `for ... of` + `await`).\n * - Returns the first `Ok` and collects all errors if no `Ok` is found.\n * - A fulfilled value that is not a `Result` is a programmer error: the call\n * rejects with `InvalidResultStateError`.\n * - A rejected input counts as a failed attempt. Without `errorMapper` the\n * collected errors are `unknown[]`, because a rejection reason can be\n * anything. `errorMapper` turns each rejection reason into a typed error;\n * `Err` values pass through untouched, and bugs inside the mapper are rethrown.\n */\nexport function collectFirstOkAsync<const Inputs extends readonly CollectFirstOkAsyncInput[]>(\n inputs: Inputs\n): Promise<Result<OkValueOfInput<Inputs[number]>, unknown[]>>;\nexport function collectFirstOkAsync<const Inputs extends readonly CollectFirstOkAsyncInput[], F>(\n inputs: Inputs,\n errorMapper: (error: unknown) => F\n): Promise<Result<OkValueOfInput<Inputs[number]>, Array<ErrValueOfInput<Inputs[number]> | F>>>;\nexport async function collectFirstOkAsync<const Inputs extends readonly CollectFirstOkAsyncInput[], F>(\n inputs: Inputs,\n errorMapper?: (error: unknown) => F\n): Promise<Result<OkValueOfInput<Inputs[number]>, Array<ErrValueOfInput<Inputs[number]> | F>>> {\n type OkValue = OkValueOfInput<Inputs[number]>;\n type ErrValue = ErrValueOfInput<Inputs[number]> | F;\n\n const errors: ErrValue[] = [];\n\n for (const input of inputs) {\n const pendingResult = typeof input === 'function' ? input() : input;\n let result: unknown;\n try {\n result = await pendingResult;\n } catch (error) {\n errors.push(errorMapper ? errorMapper(error) : (error as F));\n continue;\n }\n\n if (isResult(result)) {\n if (result.isOk()) {\n return ok<OkValue, ErrValue[]>(result.value as OkValue);\n }\n if (result.isErr()) {\n errors.push(result.error as ErrValue);\n continue;\n }\n }\n throw new InvalidResultStateError('collectFirstOkAsync');\n }\n\n return err<ErrValue[], OkValue>(errors);\n}\n","import type { Awaitable } from './pipeable';\nimport type { Result } from './result';\nimport { err, ok } from './result';\nimport { isResult } from './isResult';\nimport { InvalidResultStateError } from '../errors';\n\ntype CollectFirstOkAsyncInput = Promise<Result<any, any>> | (() => Awaitable<Result<any, any>>);\n\ntype ResolvedResult<I> = I extends () => infer R ? Awaited<R> : I extends Promise<infer R> ? R : never;\ntype OkValueOfInput<I> = ResolvedResult<I> extends Result<infer T, any> ? T : never;\ntype ErrValueOfInput<I> = ResolvedResult<I> extends Result<any, infer E> ? E : never;\n\n/**\n * Parallel version of `collectFirstOkAsync`.\n *\n * - Starts all inputs immediately (Promises or Thunks). A thunk that throws\n * synchronously is a programmer error: the call rejects with that exception,\n * as `collectFirstOkAsync` does.\n * - Returns the first `Ok` as soon as it is available.\n * - If no `Ok` is found, returns an `Err` with all error values (in input order).\n * - A fulfilled value that is not a `Result` is a programmer error: the call\n * rejects with `InvalidResultStateError`, unless an `Ok` already won the race.\n * - A rejected input counts as a failed attempt. Without `errorMapper` the\n * collected errors are `unknown[]`, because a rejection reason can be\n * anything. `errorMapper` turns each rejection reason into a typed error;\n * `Err` values pass through untouched, and bugs inside the mapper are rethrown.\n * - If multiple inputs provide an `Ok`, the one that completes first wins.\n * In case of simultaneous completion, the first observed result wins.\n * - If no `Ok` arrives and at least one input never settles, the Promise remains pending.\n */\nexport function collectFirstOkParallelAsync<const Inputs extends readonly CollectFirstOkAsyncInput[]>(\n inputs: Inputs\n): Promise<Result<OkValueOfInput<Inputs[number]>, unknown[]>>;\nexport function collectFirstOkParallelAsync<const Inputs extends readonly CollectFirstOkAsyncInput[], F>(\n inputs: Inputs,\n errorMapper: (error: unknown) => F\n): Promise<Result<OkValueOfInput<Inputs[number]>, Array<ErrValueOfInput<Inputs[number]> | F>>>;\nexport async function collectFirstOkParallelAsync<const Inputs extends readonly CollectFirstOkAsyncInput[], F>(\n inputs: Inputs,\n errorMapper?: (error: unknown) => F\n): Promise<Result<OkValueOfInput<Inputs[number]>, Array<ErrValueOfInput<Inputs[number]> | F>>> {\n type OkValue = OkValueOfInput<Inputs[number]>;\n type ErrValue = ErrValueOfInput<Inputs[number]> | F;\n\n if (inputs.length === 0) {\n return err<ErrValue[], OkValue>([]);\n }\n\n // Discarding the outcomes of the attempts that already started keeps an\n // abandoned rejection from surfacing as an unhandled rejection.\n const started: Promise<unknown>[] = [];\n try {\n for (const input of inputs) {\n started.push(typeof input === 'function' ? Promise.resolve(input()) : input);\n }\n } catch (bug) {\n for (const promise of started) promise.catch(() => {});\n throw bug;\n }\n\n const firstOk = new Promise<Result<OkValue, ErrValue[]>>((resolve, reject) => {\n for (const promise of started) {\n promise.then(\n (value) => {\n if (!isResult(value)) {\n reject(new InvalidResultStateError('collectFirstOkParallelAsync'));\n } else if (value.isOk()) {\n resolve(ok<OkValue, ErrValue[]>(value.value as OkValue));\n }\n },\n () => {\n // A rejection is a failed attempt; allSettled below collects it.\n }\n );\n }\n });\n\n const allErrors = Promise.allSettled(started).then((settled) => {\n const errors: ErrValue[] = [];\n for (const entry of settled) {\n if (entry.status === 'rejected') {\n errors.push(errorMapper ? errorMapper(entry.reason) : (entry.reason as F));\n continue;\n }\n const result = entry.value;\n if (isResult(result)) {\n if (result.isErr()) {\n errors.push(result.error as ErrValue);\n continue;\n }\n if (result.isOk()) continue;\n }\n throw new InvalidResultStateError('collectFirstOkParallelAsync');\n }\n return err<ErrValue[], OkValue>(errors);\n });\n\n return Promise.race([firstOk, allErrors]);\n}\n","import type { Result } from './result';\nimport { ok, err } from './result';\nimport { InvalidResultStateError } from '../errors';\n\ntype OkValueOf<R> = R extends Result<infer T, any> ? T : never;\ntype ErrValueOf<R> = R extends Result<any, infer E> ? E : never;\ntype CollectionValues<Results extends readonly Result<any, any>[]> = {\n -readonly [K in keyof Results]: OkValueOf<Results[K]>;\n};\n\n/**\n * Combines a list of Results.\n * Return Ok(values) only if all are Ok, otherwise Err([errors]).\n */\nexport function collectAllErrors<const Results extends readonly Result<any, any>[]>(\n results: Results\n): Result<CollectionValues<Results>, Array<ErrValueOf<Results[number]>>> {\n const values: Array<OkValueOf<Results[number]>> = [];\n const errors: Array<ErrValueOf<Results[number]>> = [];\n\n for (const result of results) {\n if (result.isOk()) {\n values.push(result.value as OkValueOf<Results[number]>);\n continue;\n }\n if (result.isErr()) {\n errors.push(result.error as ErrValueOf<Results[number]>);\n continue;\n }\n throw new InvalidResultStateError('collectAllErrors');\n }\n\n return errors.length === 0\n ? ok<CollectionValues<Results>, Array<ErrValueOf<Results[number]>>>(values as CollectionValues<Results>)\n : err<Array<ErrValueOf<Results[number]>>, CollectionValues<Results>>(errors);\n}\n","import type { Result } from './result';\nimport { InvalidResultStateError } from '../errors';\n\ntype OkValueOf<R> = R extends Result<infer T, any> ? T : never;\ntype ErrValueOf<R> = R extends Result<any, infer E> ? E : never;\n\n/**\n * Partitions Results into Ok values and Err errors.\n */\nexport function partition<const Results extends readonly Result<any, any>[]>(\n results: Results\n): [oks: Array<OkValueOf<Results[number]>>, errs: Array<ErrValueOf<Results[number]>>] {\n const oks: Array<OkValueOf<Results[number]>> = [];\n const errs: Array<ErrValueOf<Results[number]>> = [];\n\n for (const result of results) {\n if (result.isOk()) {\n oks.push(result.value as OkValueOf<Results[number]>);\n continue;\n }\n if (result.isErr()) {\n errs.push(result.error as ErrValueOf<Results[number]>);\n continue;\n }\n throw new InvalidResultStateError('partition');\n }\n\n return [oks, errs];\n}\n","import type { Result } from './result';\nimport { InvalidResultStateError } from '../errors';\n\n/**\n * Flattens a nested Result.\n * Result<Result<T, E>, E> → Result<T, E>\n * Corresponds to Rust `flatten`.\n */\nexport function flatten<T, E>(result: Result<Result<T, E>, E>): Result<T, E> {\n if (result.isOk()) {\n return result.value;\n }\n if (result.isErr()) return result as unknown as Result<T, E>;\n throw new InvalidResultStateError('flatten');\n}\n"],"mappings":";;;;;;;;;;;;AAgBA,SAAgB,eACZ,QACmE;CAQnE,IAAI,MAAM,QAAQ,MAAM,GAAG,MAAM,IAAI,wBAAwB,gBAAgB;CAE7E,MAAM,MAAoB,CAAC;CAM3B,KAAK,MAAM,OAAO,QAAQ,QAAQ,MAAM,GAAqB;EACzD,MAAM,SAAS,OAAO;EAEtB,IAAI,CAAC,SAAS,MAAM,GAAG;GACnB,IAAI,CAAC,OAAO,yBAAyB,QAAQ,GAAG,CAAC,EAAE,YAAY;GAC/D,MAAM,IAAI,wBAAwB,gBAAgB;EACtD;EAEA,IAAI,OAAO,KAAK,GAAG;GACf,IAAI,OAAO,OAAO;GAClB;EACJ;EACA,IAAI,OAAO,MAAM,GAAG,OAAO;EAC3B,MAAM,IAAI,wBAAwB,gBAAgB;CACtD;CAEA,OAAO,GAAW,GAAU;AAChC;;;;;;;;;ACvCA,SAAgB,eACZ,SACiE;CACjE,MAAM,SAA6C,CAAC;CAEpD,KAAK,MAAM,UAAU,SAAS;EAC1B,IAAI,OAAO,KAAK,GACZ,OAAO,GACH,OAAO,KACX;EAEJ,IAAI,OAAO,MAAM,GAAG;G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zE,IAAI,OAAO,KAAK,GACZ,OAAO,OAAO;CAElB,IAAI,OAAO,MAAM,GAAG,OAAO;CAC3B,MAAM,IAAI,wBAAwB,SAAS;AAC/C"}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/describeValue.ts
|
|
3
|
+
const describeUnprintable = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
return Object.prototype.toString.call(value);
|
|
6
|
+
} catch {
|
|
7
|
+
return `[unprintable ${typeof value}]`;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Formats a foreign value for an error message.
|
|
12
|
+
*
|
|
13
|
+
* `String(value)` runs the `toString`, `valueOf` or `Symbol.toPrimitive` of
|
|
14
|
+
* that value. An object with a null prototype has none of them, and a hostile
|
|
15
|
+
* one throws. Without this guard the conversion failure replaces the coded
|
|
16
|
+
* library error, and a caller that matches on the code never sees it.
|
|
17
|
+
*/
|
|
18
|
+
function describeValue(value) {
|
|
19
|
+
try {
|
|
20
|
+
return String(value);
|
|
21
|
+
} catch {
|
|
22
|
+
return describeUnprintable(value);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Formats the `message` of a foreign error value, or the value itself when it
|
|
27
|
+
* carries none. The property access belongs to the value, not to this library:
|
|
28
|
+
* a getter or a Proxy trap can throw, and then the value itself is described.
|
|
29
|
+
*/
|
|
30
|
+
function describeErrorMessage(value) {
|
|
31
|
+
try {
|
|
32
|
+
if (value !== null && typeof value === "object" && "message" in value) return describeValue(value.message);
|
|
33
|
+
} catch {}
|
|
34
|
+
return describeValue(value);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/errors.ts
|
|
39
|
+
const ERR_INVALID_RESULT_STATE = "ERR_INVALID_RESULT_STATE";
|
|
40
|
+
/** @deprecated Use {@link ERR_INVALID_RESULT_STATE} instead. */
|
|
41
|
+
const ERR_INVALID_STATE = ERR_INVALID_RESULT_STATE;
|
|
42
|
+
const ERR_TASK_YIELD_NOT_RESULT = "ERR_TASK_YIELD_NOT_RESULT";
|
|
43
|
+
const ERR_MATCH_ON_OK = "ERR_MATCH_ON_OK";
|
|
44
|
+
const ERR_MATCH_ERR_HANDLER_NOT_RESULT = "ERR_MATCH_ERR_HANDLER_NOT_RESULT";
|
|
45
|
+
const ERR_MATCH_TAG_MISSING_HANDLER = "ERR_MATCH_TAG_MISSING_HANDLER";
|
|
46
|
+
const ERR_UNWRAP_ON_ERR = "ERR_UNWRAP_ON_ERR";
|
|
47
|
+
const ERR_UNWRAP_ERR_ON_OK = "ERR_UNWRAP_ERR_ON_OK";
|
|
48
|
+
const ERR_EXPECT_OK = "ERR_EXPECT_OK";
|
|
49
|
+
const ERR_EXPECT_ERR = "ERR_EXPECT_ERR";
|
|
50
|
+
const formatResultErrorMessage = (code, message, context) => {
|
|
51
|
+
if (context) return `${code}: ${message} (context: ${context})`;
|
|
52
|
+
return `${code}: ${message}`;
|
|
53
|
+
};
|
|
54
|
+
var ResultError = class extends Error {
|
|
55
|
+
code;
|
|
56
|
+
context;
|
|
57
|
+
constructor(message, code, context) {
|
|
58
|
+
super(formatResultErrorMessage(code, message, context));
|
|
59
|
+
this.code = code;
|
|
60
|
+
this.context = context;
|
|
61
|
+
this.name = new.target.name;
|
|
62
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var ResultTypeError = class extends TypeError {
|
|
66
|
+
code;
|
|
67
|
+
context;
|
|
68
|
+
constructor(message, code, context) {
|
|
69
|
+
super(formatResultErrorMessage(code, message, context));
|
|
70
|
+
this.code = code;
|
|
71
|
+
this.context = context;
|
|
72
|
+
this.name = new.target.name;
|
|
73
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const INVALID_RESULT_STATE_MESSAGE = "Unreachable: Result is neither Ok nor Err";
|
|
77
|
+
var InvalidResultStateError = class extends ResultError {
|
|
78
|
+
constructor(context) {
|
|
79
|
+
super(INVALID_RESULT_STATE_MESSAGE, ERR_INVALID_RESULT_STATE, context);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var TaskYieldNotResultError = class extends ResultTypeError {
|
|
83
|
+
yieldedValue;
|
|
84
|
+
constructor(yieldedValue) {
|
|
85
|
+
super("task() expected yielded values to be Result. Use `yield*` on a Result.", ERR_TASK_YIELD_NOT_RESULT);
|
|
86
|
+
this.yieldedValue = yieldedValue;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
var MatchOnOkError = class extends ResultTypeError {
|
|
90
|
+
constructor(methodName = "match") {
|
|
91
|
+
super(`${methodName}() can only be called on Err results. Use \`if (result.isErr()) { ... }\` first.`, ERR_MATCH_ON_OK);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
var MatchErrHandlerNotResultError = class extends ResultTypeError {
|
|
95
|
+
handlerName;
|
|
96
|
+
returnedValue;
|
|
97
|
+
constructor(handlerName, returnedValue) {
|
|
98
|
+
super(`matchErr().${handlerName}() handlers must return a Result. Wrap values with ok(...) or err(...).`, ERR_MATCH_ERR_HANDLER_NOT_RESULT);
|
|
99
|
+
this.handlerName = handlerName;
|
|
100
|
+
this.returnedValue = returnedValue;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
var MatchTagMissingHandlerError = class extends ResultTypeError {
|
|
104
|
+
tagValue;
|
|
105
|
+
constructor(tagValue) {
|
|
106
|
+
super(`matchTag() has no handler for tag "${describeValue(tagValue)}".`, ERR_MATCH_TAG_MISSING_HANDLER);
|
|
107
|
+
this.tagValue = tagValue;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
var UnwrapOnErrError = class extends ResultTypeError {
|
|
111
|
+
errorValue;
|
|
112
|
+
constructor(errorValue) {
|
|
113
|
+
super(`Called unwrap() on Err: ${describeValue(errorValue)}`, ERR_UNWRAP_ON_ERR);
|
|
114
|
+
this.errorValue = errorValue;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
var UnwrapErrOnOkError = class extends ResultTypeError {
|
|
118
|
+
okValue;
|
|
119
|
+
constructor(okValue) {
|
|
120
|
+
super(`Called unwrapErr() on Ok: ${describeValue(okValue)}`, ERR_UNWRAP_ERR_ON_OK);
|
|
121
|
+
this.okValue = okValue;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
var ExpectOkError = class extends ResultError {
|
|
125
|
+
expectedMessage;
|
|
126
|
+
errorValue;
|
|
127
|
+
constructor(expectedMessage, errorValue) {
|
|
128
|
+
super(errorValue === void 0 ? expectedMessage : `${expectedMessage}: ${describeValue(errorValue)}`, ERR_EXPECT_OK);
|
|
129
|
+
this.expectedMessage = expectedMessage;
|
|
130
|
+
this.errorValue = errorValue;
|
|
131
|
+
if (errorValue !== void 0) this.cause = errorValue;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
var ExpectErrError = class extends ResultError {
|
|
135
|
+
expectedMessage;
|
|
136
|
+
okValue;
|
|
137
|
+
constructor(expectedMessage, okValue) {
|
|
138
|
+
super(okValue === void 0 ? expectedMessage : `${expectedMessage}: ${describeValue(okValue)}`, ERR_EXPECT_ERR);
|
|
139
|
+
this.expectedMessage = expectedMessage;
|
|
140
|
+
this.okValue = okValue;
|
|
141
|
+
if (okValue !== void 0) this.cause = okValue;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
//#endregion
|
|
146
|
+
Object.defineProperty(exports, 'ERR_EXPECT_ERR', {
|
|
147
|
+
enumerable: true,
|
|
148
|
+
get: function () {
|
|
149
|
+
return ERR_EXPECT_ERR;
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
Object.defineProperty(exports, 'ERR_EXPECT_OK', {
|
|
153
|
+
enumerable: true,
|
|
154
|
+
get: function () {
|
|
155
|
+
return ERR_EXPECT_OK;
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
Object.defineProperty(exports, 'ERR_INVALID_RESULT_STATE', {
|
|
159
|
+
enumerable: true,
|
|
160
|
+
get: function () {
|
|
161
|
+
return ERR_INVALID_RESULT_STATE;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
Object.defineProperty(exports, 'ERR_INVALID_STATE', {
|
|
165
|
+
enumerable: true,
|
|
166
|
+
get: function () {
|
|
167
|
+
return ERR_INVALID_STATE;
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
Object.defineProperty(exports, 'ERR_MATCH_ERR_HANDLER_NOT_RESULT', {
|
|
171
|
+
enumerable: true,
|
|
172
|
+
get: function () {
|
|
173
|
+
return ERR_MATCH_ERR_HANDLER_NOT_RESULT;
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
Object.defineProperty(exports, 'ERR_MATCH_ON_OK', {
|
|
177
|
+
enumerable: true,
|
|
178
|
+
get: function () {
|
|
179
|
+
return ERR_MATCH_ON_OK;
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
Object.defineProperty(exports, 'ERR_MATCH_TAG_MISSING_HANDLER', {
|
|
183
|
+
enumerable: true,
|
|
184
|
+
get: function () {
|
|
185
|
+
return ERR_MATCH_TAG_MISSING_HANDLER;
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
Object.defineProperty(exports, 'ERR_TASK_YIELD_NOT_RESULT', {
|
|
189
|
+
enumerable: true,
|
|
190
|
+
get: function () {
|
|
191
|
+
return ERR_TASK_YIELD_NOT_RESULT;
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
Object.defineProperty(exports, 'ERR_UNWRAP_ERR_ON_OK', {
|
|
195
|
+
enumerable: true,
|
|
196
|
+
get: function () {
|
|
197
|
+
return ERR_UNWRAP_ERR_ON_OK;
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
Object.defineProperty(exports, 'ERR_UNWRAP_ON_ERR', {
|
|
201
|
+
enumerable: true,
|
|
202
|
+
get: function () {
|
|
203
|
+
return ERR_UNWRAP_ON_ERR;
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
Object.defineProperty(exports, 'ExpectErrError', {
|
|
207
|
+
enumerable: true,
|
|
208
|
+
get: function () {
|
|
209
|
+
return ExpectErrError;
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
Object.defineProperty(exports, 'ExpectOkError', {
|
|
213
|
+
enumerable: true,
|
|
214
|
+
get: function () {
|
|
215
|
+
return ExpectOkError;
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
Object.defineProperty(exports, 'InvalidResultStateError', {
|
|
219
|
+
enumerable: true,
|
|
220
|
+
get: function () {
|
|
221
|
+
return InvalidResultStateError;
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
Object.defineProperty(exports, 'MatchErrHandlerNotResultError', {
|
|
225
|
+
enumerable: true,
|
|
226
|
+
get: function () {
|
|
227
|
+
return MatchErrHandlerNotResultError;
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
Object.defineProperty(exports, 'MatchOnOkError', {
|
|
231
|
+
enumerable: true,
|
|
232
|
+
get: function () {
|
|
233
|
+
return MatchOnOkError;
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
Object.defineProperty(exports, 'MatchTagMissingHandlerError', {
|
|
237
|
+
enumerable: true,
|
|
238
|
+
get: function () {
|
|
239
|
+
return MatchTagMissingHandlerError;
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
Object.defineProperty(exports, 'ResultError', {
|
|
243
|
+
enumerable: true,
|
|
244
|
+
get: function () {
|
|
245
|
+
return ResultError;
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
Object.defineProperty(exports, 'ResultTypeError', {
|
|
249
|
+
enumerable: true,
|
|
250
|
+
get: function () {
|
|
251
|
+
return ResultTypeError;
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
Object.defineProperty(exports, 'TaskYieldNotResultError', {
|
|
255
|
+
enumerable: true,
|
|
256
|
+
get: function () {
|
|
257
|
+
return TaskYieldNotResultError;
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
Object.defineProperty(exports, 'UnwrapErrOnOkError', {
|
|
261
|
+
enumerable: true,
|
|
262
|
+
get: function () {
|
|
263
|
+
return UnwrapErrOnOkError;
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
Object.defineProperty(exports, 'UnwrapOnErrError', {
|
|
267
|
+
enumerable: true,
|
|
268
|
+
get: function () {
|
|
269
|
+
return UnwrapOnErrError;
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
Object.defineProperty(exports, 'describeErrorMessage', {
|
|
273
|
+
enumerable: true,
|
|
274
|
+
get: function () {
|
|
275
|
+
return describeErrorMessage;
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
//# sourceMappingURL=errors-CVgC7NII.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors-CVgC7NII.cjs","names":[],"sources":["../src/describeValue.ts","../src/errors.ts"],"sourcesContent":["// `Object.prototype.toString` reads `Symbol.toStringTag`, which can be a\n// getter that throws, so even the fallback needs its own guard.\nconst describeUnprintable = (value: unknown): string => {\n try {\n return Object.prototype.toString.call(value);\n } catch {\n return `[unprintable ${typeof value}]`;\n }\n};\n\n/**\n * Formats a foreign value for an error message.\n *\n * `String(value)` runs the `toString`, `valueOf` or `Symbol.toPrimitive` of\n * that value. An object with a null prototype has none of them, and a hostile\n * one throws. Without this guard the conversion failure replaces the coded\n * library error, and a caller that matches on the code never sees it.\n */\nexport function describeValue(value: unknown): string {\n try {\n return String(value);\n } catch {\n return describeUnprintable(value);\n }\n}\n\n/**\n * Formats the `message` of a foreign error value, or the value itself when it\n * carries none. The property access belongs to the value, not to this library:\n * a getter or a Proxy trap can throw, and then the value itself is described.\n */\nexport function describeErrorMessage(value: unknown): string {\n try {\n if (value !== null && typeof value === 'object' && 'message' in value) {\n return describeValue((value as { message: unknown }).message);\n }\n } catch {\n // The `in` check or the getter threw, so fall through to the value.\n }\n\n return describeValue(value);\n}\n","import { describeValue } from './describeValue';\n\nexport const ERR_INVALID_RESULT_STATE = 'ERR_INVALID_RESULT_STATE' as const;\n/** @deprecated Use {@link ERR_INVALID_RESULT_STATE} instead. */\nexport const ERR_INVALID_STATE: typeof ERR_INVALID_RESULT_STATE = ERR_INVALID_RESULT_STATE;\nexport const ERR_TASK_YIELD_NOT_RESULT = 'ERR_TASK_YIELD_NOT_RESULT' as const;\nexport const ERR_MATCH_ON_OK = 'ERR_MATCH_ON_OK' as const;\nexport const ERR_MATCH_ERR_HANDLER_NOT_RESULT = 'ERR_MATCH_ERR_HANDLER_NOT_RESULT' as const;\nexport const ERR_MATCH_TAG_MISSING_HANDLER = 'ERR_MATCH_TAG_MISSING_HANDLER' as const;\nexport const ERR_UNWRAP_ON_ERR = 'ERR_UNWRAP_ON_ERR' as const;\nexport const ERR_UNWRAP_ERR_ON_OK = 'ERR_UNWRAP_ERR_ON_OK' as const;\nexport const ERR_EXPECT_OK = 'ERR_EXPECT_OK' as const;\nexport const ERR_EXPECT_ERR = 'ERR_EXPECT_ERR' as const;\n\nexport type ResultErrorCode =\n | typeof ERR_INVALID_RESULT_STATE\n | typeof ERR_TASK_YIELD_NOT_RESULT\n | typeof ERR_MATCH_ON_OK\n | typeof ERR_MATCH_ERR_HANDLER_NOT_RESULT\n | typeof ERR_MATCH_TAG_MISSING_HANDLER\n | typeof ERR_UNWRAP_ON_ERR\n | typeof ERR_UNWRAP_ERR_ON_OK\n | typeof ERR_EXPECT_OK\n | typeof ERR_EXPECT_ERR;\n\nconst formatResultErrorMessage = (code: ResultErrorCode, message: string, context?: string): string => {\n if (context) {\n return `${code}: ${message} (context: ${context})`;\n }\n return `${code}: ${message}`;\n};\n\nexport class ResultError extends Error {\n readonly code: ResultErrorCode;\n readonly context?: string;\n\n constructor(message: string, code: ResultErrorCode, context?: string) {\n super(formatResultErrorMessage(code, message, context));\n this.code = code;\n this.context = context;\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class ResultTypeError extends TypeError {\n readonly code: ResultErrorCode;\n readonly context?: string;\n\n constructor(message: string, code: ResultErrorCode, context?: string) {\n super(formatResultErrorMessage(code, message, context));\n this.code = code;\n this.context = context;\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nconst INVALID_RESULT_STATE_MESSAGE = 'Unreachable: Result is neither Ok nor Err';\n\nexport class InvalidResultStateError extends ResultError {\n constructor(context?: string) {\n super(INVALID_RESULT_STATE_MESSAGE, ERR_INVALID_RESULT_STATE, context);\n }\n}\n\nexport class TaskYieldNotResultError extends ResultTypeError {\n readonly yieldedValue: unknown;\n\n constructor(yieldedValue: unknown) {\n super('task() expected yielded values to be Result. Use `yield*` on a Result.', ERR_TASK_YIELD_NOT_RESULT);\n this.yieldedValue = yieldedValue;\n }\n}\n\nexport class MatchOnOkError extends ResultTypeError {\n constructor(methodName = 'match') {\n super(`${methodName}() can only be called on Err results. Use \\`if (result.isErr()) { ... }\\` first.`, ERR_MATCH_ON_OK);\n }\n}\n\nexport class MatchErrHandlerNotResultError extends ResultTypeError {\n readonly handlerName: string;\n readonly returnedValue: unknown;\n\n constructor(handlerName: string, returnedValue: unknown) {\n super(`matchErr().${handlerName}() handlers must return a Result. Wrap values with ok(...) or err(...).`, ERR_MATCH_ERR_HANDLER_NOT_RESULT);\n this.handlerName = handlerName;\n this.returnedValue = returnedValue;\n }\n}\n\nexport class MatchTagMissingHandlerError extends ResultTypeError {\n readonly tagValue: unknown;\n\n constructor(tagValue: unknown) {\n super(`matchTag() has no handler for tag \"${describeValue(tagValue)}\".`, ERR_MATCH_TAG_MISSING_HANDLER);\n this.tagValue = tagValue;\n }\n}\n\nexport class UnwrapOnErrError extends ResultTypeError {\n readonly errorValue: unknown;\n\n constructor(errorValue: unknown) {\n super(`Called unwrap() on Err: ${describeValue(errorValue)}`, ERR_UNWRAP_ON_ERR);\n this.errorValue = errorValue;\n }\n}\n\nexport class UnwrapErrOnOkError extends ResultTypeError {\n readonly okValue: unknown;\n\n constructor(okValue: unknown) {\n super(`Called unwrapErr() on Ok: ${describeValue(okValue)}`, ERR_UNWRAP_ERR_ON_OK);\n this.okValue = okValue;\n }\n}\n\nexport class ExpectOkError extends ResultError {\n readonly expectedMessage: string;\n readonly errorValue: unknown;\n\n constructor(expectedMessage: string, errorValue?: unknown) {\n super(errorValue === undefined ? expectedMessage : `${expectedMessage}: ${describeValue(errorValue)}`, ERR_EXPECT_OK);\n this.expectedMessage = expectedMessage;\n this.errorValue = errorValue;\n if (errorValue !== undefined) this.cause = errorValue;\n }\n}\n\nexport class ExpectErrError extends ResultError {\n readonly expectedMessage: string;\n readonly okValue: unknown;\n\n constructor(expectedMessage: string, okValue?: unknown) {\n super(okValue === undefined ? expectedMessage : `${expectedMessage}: ${describeValue(okValue)}`, ERR_EXPECT_ERR);\n this.expectedMessage = expectedMessage;\n this.okValue = okValue;\n if (okValue !== undefined) this.cause = okValue;\n }\n}\n"],"mappings":";;AAEA,MAAM,uBAAuB,UAA2B;CACpD,IAAI;EACA,OAAO,OAAO,UAAU,SAAS,KAAK,KAAK;CAC/C,QAAQ;EACJ,OAAO,gBAAgB,OAAO,MAAM;CACxC;AACJ;;;;;;;;;AAUA,SAAgB,cAAc,OAAwB;CAClD,IAAI;EACA,OAAO,OAAO,KAAK;CACvB,QAAQ;EACJ,OAAO,oBAAoB,KAAK;CACpC;AACJ;;;;;;AAOA,SAAgB,qBAAqB,OAAwB;CACzD,IAAI;EACA,IAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,aAAa,OAC5D,OAAO,cAAe,MAA+B,OAAO;CAEpE,QAAQ,CAER;CAEA,OAAO,cAAc,KAAK;AAC9B;;;;ACvCA,MAAa,2BAA2B;;AAExC,MAAa,oBAAqD;AAClE,MAAa,4BAA4B;AACzC,MAAa,kBAAkB;AAC/B,MAAa,mCAAmC;AAChD,MAAa,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