@shirudo/result 1.0.1 → 1.1.1
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 +86 -38
- package/dist/collections.cjs +4 -3
- package/dist/collections.d.cts +2 -2
- package/dist/collections.d.mts +2 -2
- package/dist/collections.mjs +2 -2
- package/dist/errors.cjs +131 -20
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +63 -2
- package/dist/errors.d.cts.map +1 -0
- package/dist/errors.d.mts +63 -2
- package/dist/errors.d.mts.map +1 -0
- package/dist/errors.mjs +109 -2
- package/dist/errors.mjs.map +1 -0
- package/dist/{flatten-Df9U40nO.cjs → flatten-B_XIkaOK.cjs} +29 -3
- package/dist/flatten-B_XIkaOK.cjs.map +1 -0
- package/dist/flatten-C7D6Kttf.d.mts +81 -0
- package/dist/flatten-C7D6Kttf.d.mts.map +1 -0
- package/dist/{flatten-C6Y9hx79.mjs → flatten-ChTL5BfA.mjs} +24 -4
- package/dist/flatten-ChTL5BfA.mjs.map +1 -0
- package/dist/flatten-D0K8UcQH.d.cts +81 -0
- package/dist/flatten-D0K8UcQH.d.cts.map +1 -0
- package/dist/index.cjs +90 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +78 -58
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +78 -58
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +58 -12
- package/dist/index.mjs.map +1 -1
- package/dist/operators.cjs +31 -30
- package/dist/operators.d.cts +2 -2
- package/dist/operators.d.mts +2 -2
- package/dist/operators.mjs +2 -2
- package/dist/{result-CY-KIivk.cjs → result-BBOGxvSH.cjs} +86 -503
- package/dist/result-BBOGxvSH.cjs.map +1 -0
- package/dist/{result-DKKaNdOx.mjs → result-q9Na2bGa.mjs} +87 -372
- package/dist/result-q9Na2bGa.mjs.map +1 -0
- package/dist/sequence-DDwePRLd.d.cts +283 -0
- package/dist/sequence-DDwePRLd.d.cts.map +1 -0
- package/dist/sequence-DDwePRLd.d.mts +283 -0
- package/dist/sequence-DDwePRLd.d.mts.map +1 -0
- package/dist/swap-BnyMBdD_.cjs +552 -0
- package/dist/swap-BnyMBdD_.cjs.map +1 -0
- package/dist/swap-CFD2g1cB.mjs +385 -0
- package/dist/swap-CFD2g1cB.mjs.map +1 -0
- package/dist/swap-CrHQZIax.d.cts +212 -0
- package/dist/swap-CrHQZIax.d.cts.map +1 -0
- package/dist/swap-DT4LdRFV.d.mts +212 -0
- package/dist/swap-DT4LdRFV.d.mts.map +1 -0
- package/package.json +9 -8
- package/dist/errors-2WOswg7r.mjs +0 -95
- package/dist/errors-2WOswg7r.mjs.map +0 -1
- package/dist/errors-BFjY06EV.d.cts +0 -55
- package/dist/errors-BFjY06EV.d.cts.map +0 -1
- package/dist/errors-C5qGMRiU.d.mts +0 -55
- package/dist/errors-C5qGMRiU.d.mts.map +0 -1
- package/dist/errors-D2EMzJQl.cjs +0 -209
- package/dist/errors-D2EMzJQl.cjs.map +0 -1
- package/dist/flatten-B8bN6fiI.d.mts +0 -71
- package/dist/flatten-B8bN6fiI.d.mts.map +0 -1
- package/dist/flatten-C6Y9hx79.mjs.map +0 -1
- package/dist/flatten-DK7eJKPx.d.cts +0 -71
- package/dist/flatten-DK7eJKPx.d.cts.map +0 -1
- package/dist/flatten-Df9U40nO.cjs.map +0 -1
- package/dist/mapOrElse-B0_4r6Jn.mjs +0 -96
- package/dist/mapOrElse-B0_4r6Jn.mjs.map +0 -1
- package/dist/mapOrElse-B5gx9x2E.d.mts +0 -64
- package/dist/mapOrElse-B5gx9x2E.d.mts.map +0 -1
- package/dist/mapOrElse-DIe7LkYV.d.cts +0 -64
- package/dist/mapOrElse-DIe7LkYV.d.cts.map +0 -1
- package/dist/mapOrElse-H-GvAUka.cjs +0 -137
- package/dist/mapOrElse-H-GvAUka.cjs.map +0 -1
- package/dist/result-CY-KIivk.cjs.map +0 -1
- package/dist/result-DKKaNdOx.mjs.map +0 -1
- package/dist/sequence-Br6tAIIu.d.cts +0 -419
- package/dist/sequence-Br6tAIIu.d.cts.map +0 -1
- package/dist/sequence-C0jlR3AY.d.mts +0 -419
- package/dist/sequence-C0jlR3AY.d.mts.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as collectFirstOkAsync, i as collectFirstOkParallelAsync, n as partition, o as
|
|
3
|
-
import {
|
|
4
|
-
import { a as
|
|
1
|
+
import { S as Awaitable, _ as tryFn, a as Ok, b as isResult, c as ResultType, d as fromPromise, f as fromThrowable, g as tryAsync, h as okIfLazy, i as Err, l as err, m as okIf, n as sequence, o as OperatorFunction, p as ok, r as AsyncOperatorFunction, s as Result, t as all, u as fromNullable, v as combine, x as matchTag, y as zip } from "./sequence-DDwePRLd.mjs";
|
|
2
|
+
import { a as collectFirstOkAsync, i as collectFirstOkParallelAsync, n as partition, o as collectFirstOk, r as collectAllErrors, s as sequenceRecord, t as flatten } from "./flatten-C7D6Kttf.mjs";
|
|
3
|
+
import { ERR_EXPECT_ERR, ERR_EXPECT_OK, ERR_INVALID_RESULT_STATE, ERR_INVALID_STATE, ERR_MATCH_ERR_HANDLER_NOT_RESULT, ERR_MATCH_ON_OK, ERR_MATCH_TAG_MISSING_HANDLER, ERR_TASK_YIELD_NOT_RESULT, ERR_UNWRAP_ERR_ON_OK, ERR_UNWRAP_ON_ERR, ExpectErrError, ExpectOkError, InvalidResultStateError, MatchErrHandlerNotResultError, MatchOnOkError, MatchTagMissingHandlerError, ResultError, ResultErrorCode, ResultTypeError, TaskYieldNotResultError, UnwrapErrOnOkError, UnwrapOnErrError } from "./errors.mjs";
|
|
4
|
+
import { C as tap, D as mapErr, E as mapBoth, O as map, S as filter, T as bimap, _ as recoverWith, a as or, b as match, c as tryCatchAsync, d as filterAsync, f as tapAsync, g as recover, h as mapAsync, i as orElse, l as matchAsync, m as mapErrAsync, n as mapOrElse, o as and, p as flatMapAsync, r as mapOr, s as tryMapAsync, t as swap, u as foldAsync, v as tryMap, w as flatMap, x as fold, y as tryCatch } from "./swap-DT4LdRFV.mjs";
|
|
5
5
|
|
|
6
6
|
//#region src/gen.d.ts
|
|
7
7
|
type AnyGenerator<Y = unknown, R = unknown, N = unknown> = Generator<Y, R, N> | AsyncGenerator<Y, R, N>;
|
|
@@ -11,118 +11,138 @@ type AwaitedReturn<R> = Awaited<R>;
|
|
|
11
11
|
type OkOfReturn<R> = AwaitedReturn<R> extends Result<infer T, any> ? T : AwaitedReturn<R>;
|
|
12
12
|
type ErrOfReturn<R> = AwaitedReturn<R> extends Result<any, infer E> ? E : never;
|
|
13
13
|
/**
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
* Generator-based do-notation for `Result`.
|
|
15
|
+
*
|
|
16
|
+
* Usage:
|
|
17
|
+
* ```ts
|
|
18
|
+
* const out = await task(async function* () {
|
|
19
|
+
* const user = yield* await fromPromise(findUser(1));
|
|
20
|
+
* const email = yield* validate(user.email);
|
|
21
|
+
* return email;
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
25
|
declare function task<const Y, const R>(makeGenerator: () => AnyGenerator<Y, R, unknown>): Promise<Result<OkOfReturn<R>, ErrorOfYield<Y> | ErrOfReturn<R>>>;
|
|
26
26
|
declare function task<const Y, const R, EThrown>(makeGenerator: () => AnyGenerator<Y, R, unknown>, onThrow: OnThrow<EThrown>): Promise<Result<OkOfReturn<R>, ErrorOfYield<Y> | ErrOfReturn<R> | EThrown>>;
|
|
27
27
|
declare const gen: typeof task;
|
|
28
28
|
//#endregion
|
|
29
29
|
//#region src/core/unwrap.d.ts
|
|
30
30
|
/**
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
* Returns the value or throws an Error.
|
|
32
|
+
* Corresponds to Rust `unwrap`.
|
|
33
|
+
*/
|
|
34
34
|
declare function unwrap<T, E>(result: Result<T, E>): T;
|
|
35
35
|
//#endregion
|
|
36
36
|
//#region src/core/unwrapOr.d.ts
|
|
37
37
|
/**
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
* Returns the value or a default value.
|
|
39
|
+
* Pure function alternative to the instance method.
|
|
40
|
+
*/
|
|
41
41
|
declare function unwrapOr<T, E>(result: Result<T, E>, defaultValue: T): T;
|
|
42
42
|
//#endregion
|
|
43
43
|
//#region src/core/unwrapOrElse.d.ts
|
|
44
44
|
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
* Returns the value or calculates a default value using a function.
|
|
46
|
+
* Corresponds to Rust `unwrap_or_else`.
|
|
47
|
+
*/
|
|
48
48
|
declare function unwrapOrElse<T, E>(result: Result<T, E>, fn: (error: E) => T): T;
|
|
49
49
|
//#endregion
|
|
50
50
|
//#region src/core/unwrapOrDefault.d.ts
|
|
51
51
|
/**
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
* Alias for `unwrapOr`.
|
|
53
|
+
*
|
|
54
|
+
* @deprecated Use {@link unwrapOr} instead. The name is misleading: Rust's
|
|
55
|
+
* `unwrap_or_default` takes no argument (it uses the type's `Default`),
|
|
56
|
+
* whereas this function requires an explicit default value — which is exactly
|
|
57
|
+
* what `unwrapOr` does.
|
|
58
|
+
*/
|
|
55
59
|
declare function unwrapOrDefault<T, E>(result: Result<T, E>, defaultValue: T): T;
|
|
56
60
|
//#endregion
|
|
57
61
|
//#region src/core/unwrapOrThrow.d.ts
|
|
58
62
|
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
63
|
+
* Returns the value or throws the original Err value (not wrapped).
|
|
64
|
+
* Useful to preserve `Error` instances including stack traces.
|
|
65
|
+
*/
|
|
62
66
|
declare function unwrapOrThrow<T, E>(result: Result<T, E>): T;
|
|
63
67
|
//#endregion
|
|
64
68
|
//#region src/core/unwrapErr.d.ts
|
|
65
69
|
/**
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
70
|
+
* Returns the error or throws an Error.
|
|
71
|
+
* Corresponds to Rust `unwrap_err`.
|
|
72
|
+
*/
|
|
69
73
|
declare function unwrapErr<T, E>(result: Result<T, E>): E;
|
|
70
74
|
//#endregion
|
|
71
75
|
//#region src/core/expectResult.d.ts
|
|
72
76
|
/**
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
77
|
+
* Returns the value or throws an Error with a custom message.
|
|
78
|
+
* Corresponds to Rust `expect`.
|
|
79
|
+
*/
|
|
76
80
|
declare function expectResult<T, E>(result: Result<T, E>, message: string): T;
|
|
77
81
|
//#endregion
|
|
78
82
|
//#region src/core/expectErr.d.ts
|
|
79
83
|
/**
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
84
|
+
* Returns the error or throws an Error with a custom message.
|
|
85
|
+
* Corresponds to Rust `expect_err`.
|
|
86
|
+
*/
|
|
83
87
|
declare function expectErr<T, E>(result: Result<T, E>, message: string): E;
|
|
84
88
|
//#endregion
|
|
89
|
+
//#region src/core/fromSerialized.d.ts
|
|
90
|
+
/**
|
|
91
|
+
* Rebuilds a `Result` from its serialized discriminated form
|
|
92
|
+
* (`{ _tag: 'Ok', value }` / `{ _tag: 'Err', error }`), the shape produced
|
|
93
|
+
* by `Result.toSerialized()` and by `JSON.stringify` on a Result.
|
|
94
|
+
*
|
|
95
|
+
* Throws `InvalidResultStateError` for data that is not in that shape.
|
|
96
|
+
*/
|
|
97
|
+
declare function fromSerialized<T, E>(data: ResultType<T, E>): Result<T, E>;
|
|
98
|
+
//#endregion
|
|
85
99
|
//#region src/core/toPromise.d.ts
|
|
86
100
|
/**
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
101
|
+
* Converts a Result to a Promise.
|
|
102
|
+
* Ok → resolve(value), Err → reject(error)
|
|
103
|
+
*/
|
|
90
104
|
declare function toPromise<T, E>(result: Result<T, E>): Promise<T>;
|
|
91
105
|
//#endregion
|
|
92
106
|
//#region src/core/toNullable.d.ts
|
|
93
107
|
/**
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
108
|
+
* Converts a Result to `T | null`.
|
|
109
|
+
* Ok → value, Err → null
|
|
110
|
+
*/
|
|
97
111
|
declare function toNullable<T, E>(result: Result<T, E>): T | null;
|
|
98
112
|
//#endregion
|
|
99
113
|
//#region src/core/isOk.d.ts
|
|
100
114
|
/**
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
115
|
+
* Checks if a Result is Ok.
|
|
116
|
+
* Pure function alternative to the instance method.
|
|
117
|
+
*/
|
|
104
118
|
declare function isOk<T, E>(result: Result<T, E>): result is Ok<T, E>;
|
|
105
119
|
//#endregion
|
|
106
120
|
//#region src/core/isErr.d.ts
|
|
107
121
|
/**
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
122
|
+
* Checks if a Result is Err.
|
|
123
|
+
* Pure function alternative to the instance method.
|
|
124
|
+
*/
|
|
111
125
|
declare function isErr<T, E>(result: Result<T, E>): result is Err<T, E>;
|
|
112
126
|
//#endregion
|
|
113
127
|
//#region src/core/contains.d.ts
|
|
114
128
|
/**
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
129
|
+
* Checks if the Result contains a specific value.
|
|
130
|
+
* Corresponds to Rust `contains`.
|
|
131
|
+
*
|
|
132
|
+
* Comparison uses `Object.is` (SameValue): `NaN` matches `NaN`, `+0` and
|
|
133
|
+
* `-0` are distinct, and objects are compared by reference.
|
|
134
|
+
*/
|
|
118
135
|
declare function contains<T, E>(result: Result<T, E>, value: T): boolean;
|
|
119
136
|
//#endregion
|
|
120
137
|
//#region src/core/containsErr.d.ts
|
|
121
138
|
/**
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
139
|
+
* Checks if the Result contains a specific error.
|
|
140
|
+
* Analogous to `contains` for the Err case.
|
|
141
|
+
*
|
|
142
|
+
* Comparison uses `Object.is` (SameValue): `NaN` matches `NaN`, `+0` and
|
|
143
|
+
* `-0` are distinct, and objects are compared by reference.
|
|
144
|
+
*/
|
|
125
145
|
declare function containsErr<T, E>(result: Result<T, E>, error: E): boolean;
|
|
126
146
|
//#endregion
|
|
127
|
-
export { AsyncOperatorFunction, Awaitable, ERR_EXPECT_ERR, ERR_EXPECT_OK, ERR_INVALID_RESULT_STATE, ERR_INVALID_STATE, ERR_MATCH_ERR_HANDLER_NOT_RESULT, ERR_MATCH_ON_OK, ERR_TASK_YIELD_NOT_RESULT, ERR_UNWRAP_ERR_ON_OK, ERR_UNWRAP_ON_ERR, Err, ExpectErrError, ExpectOkError, InvalidResultStateError, MatchErrHandlerNotResultError, MatchOnOkError, Ok, OperatorFunction, Result, ResultError, ResultErrorCode, ResultType, ResultTypeError, TaskYieldNotResultError, UnwrapErrOnOkError, UnwrapOnErrError, all, and, bimap, collectAllErrors, collectFirstOk, collectFirstOkAsync, collectFirstOkParallelAsync, combine, contains, containsErr, err, expectErr, expectResult, filter, filterAsync, flatMap, flatMapAsync, flatten, fold, foldAsync, fromNullable, fromPromise, fromThrowable, gen, isErr, isOk, isResult, map, mapAsync, mapBoth, mapErr, mapErrAsync, mapOr, mapOrElse, match, matchAsync, matchTag, ok, okIf, okIfLazy, or, orElse, partition, recover, recoverWith, sequence, sequenceRecord, swap, tap, tapAsync, task, toNullable, toPromise, tryAsync, tryCatch, tryCatchAsync, tryFn, tryMap, tryMapAsync, unwrap, unwrapErr, unwrapOr, unwrapOrDefault, unwrapOrElse, unwrapOrThrow, zip };
|
|
147
|
+
export { AsyncOperatorFunction, type Awaitable, ERR_EXPECT_ERR, ERR_EXPECT_OK, ERR_INVALID_RESULT_STATE, ERR_INVALID_STATE, ERR_MATCH_ERR_HANDLER_NOT_RESULT, ERR_MATCH_ON_OK, ERR_MATCH_TAG_MISSING_HANDLER, ERR_TASK_YIELD_NOT_RESULT, ERR_UNWRAP_ERR_ON_OK, ERR_UNWRAP_ON_ERR, Err, ExpectErrError, ExpectOkError, InvalidResultStateError, MatchErrHandlerNotResultError, MatchOnOkError, MatchTagMissingHandlerError, Ok, OperatorFunction, Result, ResultError, ResultErrorCode, ResultType, ResultTypeError, TaskYieldNotResultError, UnwrapErrOnOkError, UnwrapOnErrError, all, and, bimap, collectAllErrors, collectFirstOk, collectFirstOkAsync, collectFirstOkParallelAsync, combine, contains, containsErr, err, expectErr, expectResult, filter, filterAsync, flatMap, flatMapAsync, flatten, fold, foldAsync, fromNullable, fromPromise, fromSerialized, fromThrowable, gen, isErr, isOk, isResult, map, mapAsync, mapBoth, mapErr, mapErrAsync, mapOr, mapOrElse, match, matchAsync, matchTag, ok, okIf, okIfLazy, or, orElse, partition, recover, recoverWith, sequence, sequenceRecord, swap, tap, tapAsync, task, toNullable, toPromise, tryAsync, tryCatch, tryCatchAsync, tryFn, tryMap, tryMapAsync, unwrap, unwrapErr, unwrapOr, unwrapOrDefault, unwrapOrElse, unwrapOrThrow, zip };
|
|
128
148
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/gen.ts","../src/core/unwrap.ts","../src/core/unwrapOr.ts","../src/core/unwrapOrElse.ts","../src/core/unwrapOrDefault.ts","../src/core/unwrapOrThrow.ts","../src/core/unwrapErr.ts","../src/core/expectResult.ts","../src/core/expectErr.ts","../src/core/toPromise.ts","../src/core/toNullable.ts","../src/core/isOk.ts","../src/core/isErr.ts","../src/core/contains.ts","../src/core/containsErr.ts"],"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/gen.ts","../src/core/unwrap.ts","../src/core/unwrapOr.ts","../src/core/unwrapOrElse.ts","../src/core/unwrapOrDefault.ts","../src/core/unwrapOrThrow.ts","../src/core/unwrapErr.ts","../src/core/expectResult.ts","../src/core/expectErr.ts","../src/core/fromSerialized.ts","../src/core/toPromise.ts","../src/core/toNullable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A,EAAO,CAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { a as
|
|
4
|
-
import { a as collectFirstOkAsync, i as collectFirstOkParallelAsync, n as partition, o as
|
|
1
|
+
import { _ as matchTag, a as fromNullable, c as ok, d as tryAsync, f as tryFn, g as sequence, h as all, i as err, l as okIf, m as zip, n as Ok, o as fromPromise, p as combine, r as Result, s as fromThrowable, t as Err, u as okIfLazy, v as isResult } from "./result-q9Na2bGa.mjs";
|
|
2
|
+
import { ERR_EXPECT_ERR, ERR_EXPECT_OK, ERR_INVALID_RESULT_STATE, ERR_INVALID_STATE, ERR_MATCH_ERR_HANDLER_NOT_RESULT, ERR_MATCH_ON_OK, ERR_MATCH_TAG_MISSING_HANDLER, ERR_TASK_YIELD_NOT_RESULT, ERR_UNWRAP_ERR_ON_OK, ERR_UNWRAP_ON_ERR, ExpectErrError, ExpectOkError, InvalidResultStateError, MatchErrHandlerNotResultError, MatchOnOkError, MatchTagMissingHandlerError, ResultError, ResultTypeError, TaskYieldNotResultError, UnwrapErrOnOkError, UnwrapOnErrError } from "./errors.mjs";
|
|
3
|
+
import { C as tap, D as mapErr, E as mapBoth, O as map, S as filter, T as bimap, _ as recoverWith, a as or, b as match, c as tryCatchAsync, d as filterAsync, f as tapAsync, g as recover, h as mapAsync, i as orElse, l as matchAsync, m as mapErrAsync, n as mapOrElse, o as and, p as flatMapAsync, r as mapOr, s as tryMapAsync, t as swap, u as foldAsync, v as tryMap, w as flatMap, x as fold, y as tryCatch } from "./swap-CFD2g1cB.mjs";
|
|
4
|
+
import { a as collectFirstOkAsync, i as collectFirstOkParallelAsync, n as partition, o as collectFirstOk, r as collectAllErrors, s as sequenceRecord, t as flatten } from "./flatten-ChTL5BfA.mjs";
|
|
5
5
|
|
|
6
6
|
//#region src/gen.ts
|
|
7
7
|
async function task(makeGenerator, onThrow) {
|
|
8
8
|
const iterator = makeGenerator();
|
|
9
9
|
let input = void 0;
|
|
10
|
+
const runGeneratorReturn = async () => {
|
|
11
|
+
if (typeof iterator.return !== "function") return;
|
|
12
|
+
let step = await iterator.return(void 0);
|
|
13
|
+
while (!step.done) step = await iterator.next(void 0);
|
|
14
|
+
};
|
|
10
15
|
while (true) {
|
|
11
16
|
let step;
|
|
12
17
|
try {
|
|
@@ -24,20 +29,34 @@ async function task(makeGenerator, onThrow) {
|
|
|
24
29
|
return err(onThrow(caught));
|
|
25
30
|
}
|
|
26
31
|
const yielded = step.value;
|
|
27
|
-
if (!isResult(yielded))
|
|
32
|
+
if (!isResult(yielded)) {
|
|
33
|
+
try {
|
|
34
|
+
await runGeneratorReturn();
|
|
35
|
+
} catch (caught) {
|
|
36
|
+
if (!onThrow) throw caught;
|
|
37
|
+
return err(onThrow(caught));
|
|
38
|
+
}
|
|
39
|
+
throw new TaskYieldNotResultError(yielded);
|
|
40
|
+
}
|
|
28
41
|
if (yielded.isOk()) {
|
|
29
42
|
input = yielded.value;
|
|
30
43
|
continue;
|
|
31
44
|
}
|
|
32
45
|
if (yielded.isErr()) {
|
|
33
46
|
try {
|
|
34
|
-
|
|
47
|
+
await runGeneratorReturn();
|
|
35
48
|
} catch (caught) {
|
|
36
49
|
if (!onThrow) throw caught;
|
|
37
50
|
return err(onThrow(caught));
|
|
38
51
|
}
|
|
39
52
|
return yielded;
|
|
40
53
|
}
|
|
54
|
+
try {
|
|
55
|
+
await runGeneratorReturn();
|
|
56
|
+
} catch (caught) {
|
|
57
|
+
if (!onThrow) throw caught;
|
|
58
|
+
return err(onThrow(caught));
|
|
59
|
+
}
|
|
41
60
|
throw new InvalidResultStateError("task");
|
|
42
61
|
}
|
|
43
62
|
}
|
|
@@ -83,7 +102,11 @@ function unwrapOrElse(result, fn) {
|
|
|
83
102
|
//#region src/core/unwrapOrDefault.ts
|
|
84
103
|
/**
|
|
85
104
|
* Alias for `unwrapOr`.
|
|
86
|
-
*
|
|
105
|
+
*
|
|
106
|
+
* @deprecated Use {@link unwrapOr} instead. The name is misleading: Rust's
|
|
107
|
+
* `unwrap_or_default` takes no argument (it uses the type's `Default`),
|
|
108
|
+
* whereas this function requires an explicit default value — which is exactly
|
|
109
|
+
* what `unwrapOr` does.
|
|
87
110
|
*/
|
|
88
111
|
function unwrapOrDefault(result, defaultValue) {
|
|
89
112
|
return unwrapOr(result, defaultValue);
|
|
@@ -121,7 +144,7 @@ function unwrapErr(result) {
|
|
|
121
144
|
*/
|
|
122
145
|
function expectResult(result, message) {
|
|
123
146
|
if (result.isOk()) return result.value;
|
|
124
|
-
if (result.isErr()) throw new ExpectOkError(message);
|
|
147
|
+
if (result.isErr()) throw new ExpectOkError(message, result.error);
|
|
125
148
|
throw new InvalidResultStateError("expectResult");
|
|
126
149
|
}
|
|
127
150
|
|
|
@@ -133,10 +156,27 @@ function expectResult(result, message) {
|
|
|
133
156
|
*/
|
|
134
157
|
function expectErr(result, message) {
|
|
135
158
|
if (result.isErr()) return result.error;
|
|
136
|
-
if (result.isOk()) throw new ExpectErrError(message);
|
|
159
|
+
if (result.isOk()) throw new ExpectErrError(message, result.value);
|
|
137
160
|
throw new InvalidResultStateError("expectErr");
|
|
138
161
|
}
|
|
139
162
|
|
|
163
|
+
//#endregion
|
|
164
|
+
//#region src/core/fromSerialized.ts
|
|
165
|
+
/**
|
|
166
|
+
* Rebuilds a `Result` from its serialized discriminated form
|
|
167
|
+
* (`{ _tag: 'Ok', value }` / `{ _tag: 'Err', error }`), the shape produced
|
|
168
|
+
* by `Result.toSerialized()` and by `JSON.stringify` on a Result.
|
|
169
|
+
*
|
|
170
|
+
* Throws `InvalidResultStateError` for data that is not in that shape.
|
|
171
|
+
*/
|
|
172
|
+
function fromSerialized(data) {
|
|
173
|
+
if (data !== null && typeof data === "object") {
|
|
174
|
+
if (data._tag === "Ok" && "value" in data) return ok(data.value);
|
|
175
|
+
if (data._tag === "Err" && "error" in data) return err(data.error);
|
|
176
|
+
}
|
|
177
|
+
throw new InvalidResultStateError("fromSerialized");
|
|
178
|
+
}
|
|
179
|
+
|
|
140
180
|
//#endregion
|
|
141
181
|
//#region src/core/toPromise.ts
|
|
142
182
|
/**
|
|
@@ -190,9 +230,12 @@ function isErr(result) {
|
|
|
190
230
|
/**
|
|
191
231
|
* Checks if the Result contains a specific value.
|
|
192
232
|
* Corresponds to Rust `contains`.
|
|
233
|
+
*
|
|
234
|
+
* Comparison uses `Object.is` (SameValue): `NaN` matches `NaN`, `+0` and
|
|
235
|
+
* `-0` are distinct, and objects are compared by reference.
|
|
193
236
|
*/
|
|
194
237
|
function contains(result, value) {
|
|
195
|
-
if (result.isOk()) return result.value
|
|
238
|
+
if (result.isOk()) return Object.is(result.value, value);
|
|
196
239
|
if (result.isErr()) return false;
|
|
197
240
|
throw new InvalidResultStateError("contains");
|
|
198
241
|
}
|
|
@@ -202,13 +245,16 @@ function contains(result, value) {
|
|
|
202
245
|
/**
|
|
203
246
|
* Checks if the Result contains a specific error.
|
|
204
247
|
* Analogous to `contains` for the Err case.
|
|
248
|
+
*
|
|
249
|
+
* Comparison uses `Object.is` (SameValue): `NaN` matches `NaN`, `+0` and
|
|
250
|
+
* `-0` are distinct, and objects are compared by reference.
|
|
205
251
|
*/
|
|
206
252
|
function containsErr(result, error) {
|
|
207
|
-
if (result.isErr()) return result.error
|
|
253
|
+
if (result.isErr()) return Object.is(result.error, error);
|
|
208
254
|
if (result.isOk()) return false;
|
|
209
255
|
throw new InvalidResultStateError("containsErr");
|
|
210
256
|
}
|
|
211
257
|
|
|
212
258
|
//#endregion
|
|
213
|
-
export { ERR_EXPECT_ERR, ERR_EXPECT_OK, ERR_INVALID_RESULT_STATE, ERR_INVALID_STATE, ERR_MATCH_ERR_HANDLER_NOT_RESULT, ERR_MATCH_ON_OK, ERR_TASK_YIELD_NOT_RESULT, ERR_UNWRAP_ERR_ON_OK, ERR_UNWRAP_ON_ERR, Err, ExpectErrError, ExpectOkError, InvalidResultStateError, MatchErrHandlerNotResultError, MatchOnOkError, Ok, Result, ResultError, ResultTypeError, TaskYieldNotResultError, UnwrapErrOnOkError, UnwrapOnErrError, all, and, bimap, collectAllErrors, collectFirstOk, collectFirstOkAsync, collectFirstOkParallelAsync, combine, contains, containsErr, err, expectErr, expectResult, filter, filterAsync, flatMap, flatMapAsync, flatten, fold, foldAsync, fromNullable, fromPromise, fromThrowable, gen, isErr, isOk, isResult, map, mapAsync, mapBoth, mapErr, mapErrAsync, mapOr, mapOrElse, match, matchAsync, matchTag, ok, okIf, okIfLazy, or, orElse, partition, recover, recoverWith, sequence, sequenceRecord, swap, tap, tapAsync, task, toNullable, toPromise, tryAsync, tryCatch, tryCatchAsync, tryFn, tryMap, tryMapAsync, unwrap, unwrapErr, unwrapOr, unwrapOrDefault, unwrapOrElse, unwrapOrThrow, zip };
|
|
259
|
+
export { ERR_EXPECT_ERR, ERR_EXPECT_OK, ERR_INVALID_RESULT_STATE, ERR_INVALID_STATE, ERR_MATCH_ERR_HANDLER_NOT_RESULT, ERR_MATCH_ON_OK, ERR_MATCH_TAG_MISSING_HANDLER, ERR_TASK_YIELD_NOT_RESULT, ERR_UNWRAP_ERR_ON_OK, ERR_UNWRAP_ON_ERR, Err, ExpectErrError, ExpectOkError, InvalidResultStateError, MatchErrHandlerNotResultError, MatchOnOkError, MatchTagMissingHandlerError, Ok, Result, ResultError, ResultTypeError, TaskYieldNotResultError, UnwrapErrOnOkError, UnwrapOnErrError, all, and, bimap, collectAllErrors, collectFirstOk, collectFirstOkAsync, collectFirstOkParallelAsync, combine, contains, containsErr, err, expectErr, expectResult, filter, filterAsync, flatMap, flatMapAsync, flatten, fold, foldAsync, fromNullable, fromPromise, fromSerialized, fromThrowable, gen, isErr, isOk, isResult, map, mapAsync, mapBoth, mapErr, mapErrAsync, mapOr, mapOrElse, match, matchAsync, matchTag, ok, okIf, okIfLazy, or, orElse, partition, recover, recoverWith, sequence, sequenceRecord, swap, tap, tapAsync, task, toNullable, toPromise, tryAsync, tryCatch, tryCatchAsync, tryFn, tryMap, tryMapAsync, unwrap, unwrapErr, unwrapOr, unwrapOrDefault, unwrapOrElse, unwrapOrThrow, zip };
|
|
214
260
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["input: unknown","step: IteratorResult<Y, R>"],"sources":["../src/gen.ts","../src/core/unwrap.ts","../src/core/unwrapOr.ts","../src/core/unwrapOrElse.ts","../src/core/unwrapOrDefault.ts","../src/core/unwrapOrThrow.ts","../src/core/unwrapErr.ts","../src/core/expectResult.ts","../src/core/expectErr.ts","../src/core/toPromise.ts","../src/core/toNullable.ts","../src/core/isOk.ts","../src/core/isErr.ts","../src/core/contains.ts","../src/core/containsErr.ts"],"sourcesContent":["import type { Result } from './core/result';\nimport { err, ok } from './core/result';\nimport { isResult } from './core/isResult';\nimport { InvalidResultStateError, TaskYieldNotResultError } from './errors';\n\ntype AnyGenerator<Y = unknown, R = unknown, N = unknown> = Generator<Y, R, N> | AsyncGenerator<Y, R, N>;\n\ntype ErrorOfYield<Y> = Y extends Result<any, infer E> ? E : never;\n\ntype OnThrow<E> = (error: unknown) => E;\n\ntype AwaitedReturn<R> = Awaited<R>;\ntype OkOfReturn<R> = AwaitedReturn<R> extends Result<infer T, any> ? T : AwaitedReturn<R>;\ntype ErrOfReturn<R> = AwaitedReturn<R> extends Result<any, infer E> ? E : never;\n\n/**\n * Generator-based do-notation for `Result`.\n *\n * Usage:\n * ```ts\n * const out = await task(async function* () {\n * const user = yield* await fromPromise(findUser(1));\n * const email = yield* validate(user.email);\n * return email;\n * });\n * ```\n */\nexport async function task<const Y, const R>(\n makeGenerator: () => AnyGenerator<Y, R, unknown>\n): Promise<Result<OkOfReturn<R>, ErrorOfYield<Y> | ErrOfReturn<R>>>;\nexport async function task<const Y, const R, EThrown>(\n makeGenerator: () => AnyGenerator<Y, R, unknown>,\n onThrow: OnThrow<EThrown>\n): Promise<Result<OkOfReturn<R>, ErrorOfYield<Y> | ErrOfReturn<R> | EThrown>>;\nexport async function task<const Y, const R, EThrown>(\n makeGenerator: () => AnyGenerator<Y, R, unknown>,\n onThrow?: OnThrow<EThrown>\n): Promise<Result<OkOfReturn<R>, ErrorOfYield<Y> | ErrOfReturn<R> | EThrown>> {\n const iterator = makeGenerator();\n let input: unknown = undefined;\n\n while (true) {\n let step: IteratorResult<Y, R>;\n try {\n step = await iterator.next(input);\n } catch (caught) {\n if (!onThrow) throw caught;\n return err<ErrorOfYield<Y> | ErrOfReturn<R> | EThrown, OkOfReturn<R>>(onThrow(caught));\n }\n\n if (step.done) {\n try {\n const awaited = await step.value;\n if (isResult(awaited)) {\n return awaited as Result<OkOfReturn<R>, ErrorOfYield<Y> | ErrOfReturn<R> | EThrown>;\n }\n return ok<OkOfReturn<R>, ErrorOfYield<Y> | ErrOfReturn<R> | EThrown>(awaited as OkOfReturn<R>);\n } catch (caught) {\n if (!onThrow) throw caught;\n return err<ErrorOfYield<Y> | ErrOfReturn<R> | EThrown, OkOfReturn<R>>(onThrow(caught));\n }\n }\n\n const yielded = step.value as unknown;\n if (!isResult(yielded)) {\n throw new TaskYieldNotResultError(yielded);\n }\n\n if (yielded.isOk()) {\n input = yielded.value;\n continue;\n }\n\n if (yielded.isErr()) {\n try {\n if (typeof iterator.return === 'function') {\n await iterator.return(undefined as unknown as R);\n }\n } catch (caught) {\n if (!onThrow) throw caught;\n return err<ErrorOfYield<Y> | ErrOfReturn<R> | EThrown, OkOfReturn<R>>(onThrow(caught));\n }\n\n return yielded as Result<OkOfReturn<R>, ErrorOfYield<Y> | ErrOfReturn<R> | EThrown>;\n }\n\n throw new InvalidResultStateError('task');\n }\n}\n\nexport const gen = task;\n","import type { Result } from './result';\nimport { InvalidResultStateError, UnwrapOnErrError } from '../errors';\n\n/**\n * Returns the value or throws an Error.\n * Corresponds to Rust `unwrap`.\n */\nexport function unwrap<T, E>(result: Result<T, E>): T {\n if (result.isOk()) {\n return result.value;\n }\n if (result.isErr()) throw new UnwrapOnErrError(result.error);\n throw new InvalidResultStateError('unwrap');\n}\n","import type { Result } from './result';\nimport { InvalidResultStateError } from '../errors';\n\n/**\n * Returns the value or a default value.\n * Pure function alternative to the instance method.\n */\nexport function unwrapOr<T, E>(result: Result<T, E>, defaultValue: T): T {\n if (result.isOk()) return result.value;\n if (result.isErr()) return defaultValue;\n throw new InvalidResultStateError('unwrapOr');\n}\n","import type { Result } from './result';\nimport { InvalidResultStateError } from '../errors';\n\n/**\n * Returns the value or calculates a default value using a function.\n * Corresponds to Rust `unwrap_or_else`.\n */\nexport function unwrapOrElse<T, E>(result: Result<T, E>, fn: (error: E) => T): T {\n if (result.isOk()) return result.value;\n if (result.isErr()) return fn(result.error);\n throw new InvalidResultStateError('unwrapOrElse');\n}\n","import type { Result } from './result';\nimport { unwrapOr } from './unwrapOr';\n\n/**\n * Alias for `unwrapOr`.\n * Corresponds to Rust `unwrap_or_default` (with explicit default value).\n */\nexport function unwrapOrDefault<T, E>(result: Result<T, E>, defaultValue: T): T {\n return unwrapOr(result, defaultValue);\n}\n\n","import type { Result } from './result';\nimport { InvalidResultStateError } from '../errors';\n\n/**\n * Returns the value or throws the original Err value (not wrapped).\n * Useful to preserve `Error` instances including stack traces.\n */\nexport function unwrapOrThrow<T, E>(result: Result<T, E>): T {\n if (result.isOk()) return result.value;\n if (result.isErr()) throw result.error;\n throw new InvalidResultStateError('unwrapOrThrow');\n}\n","import type { Result } from './result';\nimport { InvalidResultStateError, UnwrapErrOnOkError } from '../errors';\n\n/**\n * Returns the error or throws an Error.\n * Corresponds to Rust `unwrap_err`.\n */\nexport function unwrapErr<T, E>(result: Result<T, E>): E {\n if (result.isErr()) {\n return result.error;\n }\n if (result.isOk()) throw new UnwrapErrOnOkError(result.value);\n throw new InvalidResultStateError('unwrapErr');\n}\n","import type { Result } from './result';\nimport { ExpectOkError, InvalidResultStateError } from '../errors';\n\n/**\n * Returns the value or throws an Error with a custom message.\n * Corresponds to Rust `expect`.\n */\nexport function expectResult<T, E>(result: Result<T, E>, message: string): T {\n if (result.isOk()) {\n return result.value;\n }\n if (result.isErr()) {\n throw new ExpectOkError(message);\n }\n throw new InvalidResultStateError('expectResult');\n}\n","import type { Result } from './result';\nimport { ExpectErrError, InvalidResultStateError } from '../errors';\n\n/**\n * Returns the error or throws an Error with a custom message.\n * Corresponds to Rust `expect_err`.\n */\nexport function expectErr<T, E>(result: Result<T, E>, message: string): E {\n if (result.isErr()) {\n return result.error;\n }\n if (result.isOk()) {\n throw new ExpectErrError(message);\n }\n throw new InvalidResultStateError('expectErr');\n}\n","import type { Result } from './result';\nimport { InvalidResultStateError } from '../errors';\n\n/**\n * Converts a Result to a Promise.\n * Ok → resolve(value), Err → reject(error)\n */\nexport function toPromise<T, E>(result: Result<T, E>): Promise<T> {\n if (result.isOk()) {\n return Promise.resolve(result.value);\n }\n if (result.isErr()) return Promise.reject(result.error);\n throw new InvalidResultStateError('toPromise');\n}\n","import type { Result } from './result';\nimport { InvalidResultStateError } from '../errors';\n\n/**\n * Converts a Result to `T | null`.\n * Ok → value, Err → null\n */\nexport function toNullable<T, E>(result: Result<T, E>): T | null {\n if (result.isOk()) return result.value;\n if (result.isErr()) return null;\n throw new InvalidResultStateError('toNullable');\n}\n","import type { Ok, Result } from './result';\nimport { InvalidResultStateError } from '../errors';\n\n/**\n * Checks if a Result is Ok.\n * Pure function alternative to the instance method.\n */\nexport function isOk<T, E>(result: Result<T, E>): result is Ok<T, E> {\n if (result.isOk()) return true;\n if (result.isErr()) return false;\n throw new InvalidResultStateError('isOk');\n}\n","import type { Err, Result } from './result';\nimport { InvalidResultStateError } from '../errors';\n\n/**\n * Checks if a Result is Err.\n * Pure function alternative to the instance method.\n */\nexport function isErr<T, E>(result: Result<T, E>): result is Err<T, E> {\n if (result.isErr()) return true;\n if (result.isOk()) return false;\n throw new InvalidResultStateError('isErr');\n}\n","import type { Result } from './result';\nimport { InvalidResultStateError } from '../errors';\n\n/**\n * Checks if the Result contains a specific value.\n * Corresponds to Rust `contains`.\n */\nexport function contains<T, E>(result: Result<T, E>, value: T): boolean {\n if (result.isOk()) return result.value === value;\n if (result.isErr()) return false;\n throw new InvalidResultStateError('contains');\n}\n","import type { Result } from './result';\nimport { InvalidResultStateError } from '../errors';\n\n/**\n * Checks if the Result contains a specific error.\n * Analogous to `contains` for the Err case.\n */\nexport function containsErr<T, E>(result: Result<T, E>, error: E): boolean {\n if (result.isErr()) return result.error === error;\n if (result.isOk()) return false;\n throw new InvalidResultStateError('containsErr');\n}\n"],"mappings":";;;;;;AAkCA,eAAsB,KAClB,eACA,SAC0E;CAC1E,MAAM,WAAW,eAAe;CAChC,IAAIA,QAAiB;AAErB,QAAO,MAAM;EACT,IAAIC;AACJ,MAAI;AACA,UAAO,MAAM,SAAS,KAAK,MAAM;WAC5B,QAAQ;AACb,OAAI,CAAC,QAAS,OAAM;AACpB,UAAO,IAA+D,QAAQ,OAAO,CAAC;;AAG1F,MAAI,KAAK,KACL,KAAI;GACA,MAAM,UAAU,MAAM,KAAK;AAC3B,OAAI,SAAS,QAAQ,CACjB,QAAO;AAEX,UAAO,GAA8D,QAAyB;WACzF,QAAQ;AACb,OAAI,CAAC,QAAS,OAAM;AACpB,UAAO,IAA+D,QAAQ,OAAO,CAAC;;EAI9F,MAAM,UAAU,KAAK;AACrB,MAAI,CAAC,SAAS,QAAQ,CAClB,OAAM,IAAI,wBAAwB,QAAQ;AAG9C,MAAI,QAAQ,MAAM,EAAE;AAChB,WAAQ,QAAQ;AAChB;;AAGJ,MAAI,QAAQ,OAAO,EAAE;AACjB,OAAI;AACA,QAAI,OAAO,SAAS,WAAW,WAC3B,OAAM,SAAS,OAAO,OAA0B;YAE/C,QAAQ;AACb,QAAI,CAAC,QAAS,OAAM;AACpB,WAAO,IAA+D,QAAQ,OAAO,CAAC;;AAG1F,UAAO;;AAGX,QAAM,IAAI,wBAAwB,OAAO;;;AAIjD,MAAa,MAAM;;;;;;;;ACnFnB,SAAgB,OAAa,QAAyB;AAClD,KAAI,OAAO,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AgB,UAAgB,QAAkC;AAC9D,KAAI,OAAO,MAAM,CACb,QAAO,QAAQ,QAAQ,OAAO,MAAM;AAExC,KAAI,OAAO,OAAO,CAAE,QAAO,QAAQ,OAAO,OAAO,MAAM;AACvD,OAAM,IAAI,wBAAwB,YAAY;;;;;;;;;ACLlD,SAAgB,WAAiB,QAAgC;AAC7D,KAAI,OAAO,MAAM,CAAE,QAAO,OAAO;AACjC,KAAI,OAAO,OAAO,CAAE,QAAO;AAC3B,OAAM,IAAI,wBAAwB,aAAa;;;;;;;;;ACHnD,SAAgB,KAAW,QAA0C;AACjE,KAAI,OAAO,MAAM,CAAE,QAAO;AAC1B,KAAI,OAAO,OAAO,CAAE,QAAO;AAC3B,OAAM,IAAI,wBAAwB,OAAO;;;;;;;;;ACH7C,SAAgB,MAAY,QAA2C;AACnE,KAAI,OAAO,OAAO,CAAE,QAAO;AAC3B,KAAI,OAAO,MAAM,CAAE,QAAO;AAC1B,OAAM,IAAI,wBAAwB,QAAQ;;;;;;;;;ACH9C,SAAgB,SAAe,QAAsB,OAAmB;AACpE,KAAI,OAAO,MAAM,CAAE,QAAO,OAAO,UAAU;AAC3C,KAAI,OAAO,OAAO,CAAE,QAAO;AAC3B,OAAM,IAAI,wBAAwB,WAAW;;;;;;;;;ACHjD,SAAgB,YAAkB,QAAsB,OAAmB;AACvE,KAAI,OAAO,OAAO,CAAE,QAAO,OAAO,UAAU;AAC5C,KAAI,OAAO,MAAM,CAAE,QAAO;AAC1B,OAAM,IAAI,wBAAwB,cAAc"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/gen.ts","../src/core/unwrap.ts","../src/core/unwrapOr.ts","../src/core/unwrapOrElse.ts","../src/core/unwrapOrDefault.ts","../src/core/unwrapOrThrow.ts","../src/core/unwrapErr.ts","../src/core/expectResult.ts","../src/core/expectErr.ts","../src/core/fromSerialized.ts","../src/core/toPromise.ts","../src/core/toNullable.ts","../src/core/isOk.ts","../src/core/isErr.ts","../src/core/contains.ts","../src/core/containsErr.ts"],"sourcesContent":["import type { Result } from './core/result';\nimport { err, ok } from './core/result';\nimport { isResult } from './core/isResult';\nimport { InvalidResultStateError, TaskYieldNotResultError } from './errors';\n\ntype AnyGenerator<Y = unknown, R = unknown, N = unknown> = Generator<Y, R, N> | AsyncGenerator<Y, R, N>;\n\ntype ErrorOfYield<Y> = Y extends Result<any, infer E> ? E : never;\n\ntype OnThrow<E> = (error: unknown) => E;\n\ntype AwaitedReturn<R> = Awaited<R>;\ntype OkOfReturn<R> = AwaitedReturn<R> extends Result<infer T, any> ? T : AwaitedReturn<R>;\ntype ErrOfReturn<R> = AwaitedReturn<R> extends Result<any, infer E> ? E : never;\n\n/**\n * Generator-based do-notation for `Result`.\n *\n * Usage:\n * ```ts\n * const out = await task(async function* () {\n * const user = yield* await fromPromise(findUser(1));\n * const email = yield* validate(user.email);\n * return email;\n * });\n * ```\n */\nexport async function task<const Y, const R>(\n makeGenerator: () => AnyGenerator<Y, R, unknown>\n): Promise<Result<OkOfReturn<R>, ErrorOfYield<Y> | ErrOfReturn<R>>>;\nexport async function task<const Y, const R, EThrown>(\n makeGenerator: () => AnyGenerator<Y, R, unknown>,\n onThrow: OnThrow<EThrown>\n): Promise<Result<OkOfReturn<R>, ErrorOfYield<Y> | ErrOfReturn<R> | EThrown>>;\nexport async function task<const Y, const R, EThrown>(\n makeGenerator: () => AnyGenerator<Y, R, unknown>,\n onThrow?: OnThrow<EThrown>\n): Promise<Result<OkOfReturn<R>, ErrorOfYield<Y> | ErrOfReturn<R> | EThrown>> {\n const iterator = makeGenerator();\n let input: unknown = undefined;\n\n // Resume the suspended generator as if it returned, so its `finally`\n // blocks run before we abort the workflow (short-circuit or error path).\n const runGeneratorReturn = async (): Promise<void> => {\n if (typeof iterator.return !== 'function') return;\n // A `yield` inside a `finally` block suspends the generator again\n // ({done: false}). Resume with next() so the remaining cleanup code\n // still runs — calling return() again would abort the rest of that\n // finally block. The pending return completion ends the generator\n // once all finally blocks have finished.\n let step = await iterator.return(undefined as unknown as R);\n while (!step.done) {\n step = await iterator.next(undefined);\n }\n };\n\n while (true) {\n let step: IteratorResult<Y, R>;\n try {\n step = await iterator.next(input);\n } catch (caught) {\n if (!onThrow) throw caught;\n return err<ErrorOfYield<Y> | ErrOfReturn<R> | EThrown, OkOfReturn<R>>(onThrow(caught));\n }\n\n if (step.done) {\n try {\n const awaited = await step.value;\n if (isResult(awaited)) {\n return awaited as Result<OkOfReturn<R>, ErrorOfYield<Y> | ErrOfReturn<R> | EThrown>;\n }\n return ok<OkOfReturn<R>, ErrorOfYield<Y> | ErrOfReturn<R> | EThrown>(awaited as OkOfReturn<R>);\n } catch (caught) {\n if (!onThrow) throw caught;\n return err<ErrorOfYield<Y> | ErrOfReturn<R> | EThrown, OkOfReturn<R>>(onThrow(caught));\n }\n }\n\n const yielded = step.value as unknown;\n if (!isResult(yielded)) {\n try {\n await runGeneratorReturn();\n } catch (caught) {\n if (!onThrow) throw caught;\n return err<ErrorOfYield<Y> | ErrOfReturn<R> | EThrown, OkOfReturn<R>>(onThrow(caught));\n }\n throw new TaskYieldNotResultError(yielded);\n }\n\n if (yielded.isOk()) {\n input = yielded.value;\n continue;\n }\n\n if (yielded.isErr()) {\n try {\n await runGeneratorReturn();\n } catch (caught) {\n if (!onThrow) throw caught;\n return err<ErrorOfYield<Y> | ErrOfReturn<R> | EThrown, OkOfReturn<R>>(onThrow(caught));\n }\n\n return yielded as Result<OkOfReturn<R>, ErrorOfYield<Y> | ErrOfReturn<R> | EThrown>;\n }\n\n try {\n await runGeneratorReturn();\n } catch (caught) {\n if (!onThrow) throw caught;\n return err<ErrorOfYield<Y> | ErrOfReturn<R> | EThrown, OkOfReturn<R>>(onThrow(caught));\n }\n throw new InvalidResultStateError('task');\n }\n}\n\nexport const gen: typeof task = task;\n","import type { Result } from './result';\nimport { InvalidResultStateError, UnwrapOnErrError } from '../errors';\n\n/**\n * Returns the value or throws an Error.\n * Corresponds to Rust `unwrap`.\n */\nexport function unwrap<T, E>(result: Result<T, E>): T {\n if (result.isOk()) {\n return result.value;\n }\n if (result.isErr()) throw new UnwrapOnErrError(result.error);\n throw new InvalidResultStateError('unwrap');\n}\n","import type { Result } from './result';\nimport { InvalidResultStateError } from '../errors';\n\n/**\n * Returns the value or a default value.\n * Pure function alternative to the instance method.\n */\nexport function unwrapOr<T, E>(result: Result<T, E>, defaultValue: T): T {\n if (result.isOk()) return result.value;\n if (result.isErr()) return defaultValue;\n throw new InvalidResultStateError('unwrapOr');\n}\n","import type { Result } from './result';\nimport { InvalidResultStateError } from '../errors';\n\n/**\n * Returns the value or calculates a default value using a function.\n * Corresponds to Rust `unwrap_or_else`.\n */\nexport function unwrapOrElse<T, E>(result: Result<T, E>, fn: (error: E) => T): T {\n if (result.isOk()) return result.value;\n if (result.isErr()) return fn(result.error);\n throw new InvalidResultStateError('unwrapOrElse');\n}\n","import type { Result } from './result';\nimport { unwrapOr } from './unwrapOr';\n\n/**\n * Alias for `unwrapOr`.\n *\n * @deprecated Use {@link unwrapOr} instead. The name is misleading: Rust's\n * `unwrap_or_default` takes no argument (it uses the type's `Default`),\n * whereas this function requires an explicit default value — which is exactly\n * what `unwrapOr` does.\n */\nexport function unwrapOrDefault<T, E>(result: Result<T, E>, defaultValue: T): T {\n return unwrapOr(result, defaultValue);\n}\n\n","import type { Result } from './result';\nimport { InvalidResultStateError } from '../errors';\n\n/**\n * Returns the value or throws the original Err value (not wrapped).\n * Useful to preserve `Error` instances including stack traces.\n */\nexport function unwrapOrThrow<T, E>(result: Result<T, E>): T {\n if (result.isOk()) return result.value;\n if (result.isErr()) throw result.error;\n throw new InvalidResultStateError('unwrapOrThrow');\n}\n","import type { Result } from './result';\nimport { InvalidResultStateError, UnwrapErrOnOkError } from '../errors';\n\n/**\n * Returns the error or throws an Error.\n * Corresponds to Rust `unwrap_err`.\n */\nexport function unwrapErr<T, E>(result: Result<T, E>): E {\n if (result.isErr()) {\n return result.error;\n }\n if (result.isOk()) throw new UnwrapErrOnOkError(result.value);\n throw new InvalidResultStateError('unwrapErr');\n}\n","import type { Result } from './result';\nimport { ExpectOkError, InvalidResultStateError } from '../errors';\n\n/**\n * Returns the value or throws an Error with a custom message.\n * Corresponds to Rust `expect`.\n */\nexport function expectResult<T, E>(result: Result<T, E>, message: string): T {\n if (result.isOk()) {\n return result.value;\n }\n if (result.isErr()) {\n throw new ExpectOkError(message, result.error);\n }\n throw new InvalidResultStateError('expectResult');\n}\n","import type { Result } from './result';\nimport { ExpectErrError, InvalidResultStateError } from '../errors';\n\n/**\n * Returns the error or throws an Error with a custom message.\n * Corresponds to Rust `expect_err`.\n */\nexport function expectErr<T, E>(result: Result<T, E>, message: string): E {\n if (result.isErr()) {\n return result.error;\n }\n if (result.isOk()) {\n throw new ExpectErrError(message, result.value);\n }\n throw new InvalidResultStateError('expectErr');\n}\n","import type { Result, ResultType } from './result';\nimport { err, ok } from './result';\nimport { InvalidResultStateError } from '../errors';\n\n/**\n * Rebuilds a `Result` from its serialized discriminated form\n * (`{ _tag: 'Ok', value }` / `{ _tag: 'Err', error }`), the shape produced\n * by `Result.toSerialized()` and by `JSON.stringify` on a Result.\n *\n * Throws `InvalidResultStateError` for data that is not in that shape.\n */\nexport function fromSerialized<T, E>(data: ResultType<T, E>): Result<T, E> {\n if (data !== null && typeof data === 'object') {\n if (data._tag === 'Ok' && 'value' in data) return ok<T, E>(data.value);\n if (data._tag === 'Err' && 'error' in data) return err<E, T>(data.error);\n }\n throw new InvalidResultStateError('fromSerialized');\n}\n","import type { Result } from './result';\nimport { InvalidResultStateError } from '../errors';\n\n/**\n * Converts a Result to a Promise.\n * Ok → resolve(value), Err → reject(error)\n */\nexport function toPromise<T, E>(result: Result<T, E>): Promise<T> {\n if (result.isOk()) {\n return Promise.resolve(result.value);\n }\n if (result.isErr()) return Promise.reject(result.error);\n throw new InvalidResultStateError('toPromise');\n}\n","import type { Result } from './result';\nimport { InvalidResultStateError } from '../errors';\n\n/**\n * Converts a Result to `T | null`.\n * Ok → value, Err → null\n */\nexport function toNullable<T, E>(result: Result<T, E>): T | null {\n if (result.isOk()) return result.value;\n if (result.isErr()) return null;\n throw new InvalidResultStateError('toNullable');\n}\n","import type { Ok, Result } from './result';\nimport { InvalidResultStateError } from '../errors';\n\n/**\n * Checks if a Result is Ok.\n * Pure function alternative to the instance method.\n */\nexport function isOk<T, E>(result: Result<T, E>): result is Ok<T, E> {\n if (result.isOk()) return true;\n if (result.isErr()) return false;\n throw new InvalidResultStateError('isOk');\n}\n","import type { Err, Result } from './result';\nimport { InvalidResultStateError } from '../errors';\n\n/**\n * Checks if a Result is Err.\n * Pure function alternative to the instance method.\n */\nexport function isErr<T, E>(result: Result<T, E>): result is Err<T, E> {\n if (result.isErr()) return true;\n if (result.isOk()) return false;\n throw new InvalidResultStateError('isErr');\n}\n","import type { Result } from './result';\nimport { InvalidResultStateError } from '../errors';\n\n/**\n * Checks if the Result contains a specific value.\n * Corresponds to Rust `contains`.\n *\n * Comparison uses `Object.is` (SameValue): `NaN` matches `NaN`, `+0` and\n * `-0` are distinct, and objects are compared by reference.\n */\nexport function contains<T, E>(result: Result<T, E>, value: T): boolean {\n if (result.isOk()) return Object.is(result.value, value);\n if (result.isErr()) return false;\n throw new InvalidResultStateError('contains');\n}\n","import type { Result } from './result';\nimport { InvalidResultStateError } from '../errors';\n\n/**\n * Checks if the Result contains a specific error.\n * Analogous to `contains` for the Err case.\n *\n * Comparison uses `Object.is` (SameValue): `NaN` matches `NaN`, `+0` and\n * `-0` are distinct, and objects are compared by reference.\n */\nexport function containsErr<T, E>(result: Result<T, E>, error: E): boolean {\n if (result.isErr()) return Object.is(result.error, error);\n if (result.isOk()) return false;\n throw new InvalidResultStateError('containsErr');\n}\n"],"mappings":";;;;;;AAkCA,eAAsB,KAClB,eACA,SAC0E;CAC1E,MAAM,WAAW,cAAc;CAC/B,IAAI,QAAiB;CAIrB,MAAM,qBAAqB,YAA2B;EAClD,IAAI,OAAO,SAAS,WAAW,YAAY;EAM3C,IAAI,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AO,KAAK,GAAG,OAAO;CAC1B,MAAM,IAAI,wBAAwB,aAAa;AACnD"}
|
package/dist/operators.cjs
CHANGED
|
@@ -1,33 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_result = require('./result-BBOGxvSH.cjs');
|
|
3
|
+
const require_swap = require('./swap-BnyMBdD_.cjs');
|
|
3
4
|
|
|
4
|
-
exports.and =
|
|
5
|
-
exports.bimap =
|
|
5
|
+
exports.and = require_swap.and;
|
|
6
|
+
exports.bimap = require_swap.bimap;
|
|
6
7
|
exports.combine = require_result.combine;
|
|
7
|
-
exports.filter =
|
|
8
|
-
exports.filterAsync =
|
|
9
|
-
exports.flatMap =
|
|
10
|
-
exports.flatMapAsync =
|
|
11
|
-
exports.fold =
|
|
12
|
-
exports.foldAsync =
|
|
13
|
-
exports.map =
|
|
14
|
-
exports.mapAsync =
|
|
15
|
-
exports.mapBoth =
|
|
16
|
-
exports.mapErr =
|
|
17
|
-
exports.mapErrAsync =
|
|
18
|
-
exports.mapOr =
|
|
19
|
-
exports.mapOrElse =
|
|
20
|
-
exports.match =
|
|
21
|
-
exports.matchAsync =
|
|
22
|
-
exports.or =
|
|
23
|
-
exports.orElse =
|
|
24
|
-
exports.recover =
|
|
25
|
-
exports.recoverWith =
|
|
26
|
-
exports.swap =
|
|
27
|
-
exports.tap =
|
|
28
|
-
exports.tapAsync =
|
|
29
|
-
exports.tryCatch =
|
|
30
|
-
exports.tryCatchAsync =
|
|
31
|
-
exports.tryMap =
|
|
32
|
-
exports.tryMapAsync =
|
|
8
|
+
exports.filter = require_swap.filter;
|
|
9
|
+
exports.filterAsync = require_swap.filterAsync;
|
|
10
|
+
exports.flatMap = require_swap.flatMap;
|
|
11
|
+
exports.flatMapAsync = require_swap.flatMapAsync;
|
|
12
|
+
exports.fold = require_swap.fold;
|
|
13
|
+
exports.foldAsync = require_swap.foldAsync;
|
|
14
|
+
exports.map = require_swap.map;
|
|
15
|
+
exports.mapAsync = require_swap.mapAsync;
|
|
16
|
+
exports.mapBoth = require_swap.mapBoth;
|
|
17
|
+
exports.mapErr = require_swap.mapErr;
|
|
18
|
+
exports.mapErrAsync = require_swap.mapErrAsync;
|
|
19
|
+
exports.mapOr = require_swap.mapOr;
|
|
20
|
+
exports.mapOrElse = require_swap.mapOrElse;
|
|
21
|
+
exports.match = require_swap.match;
|
|
22
|
+
exports.matchAsync = require_swap.matchAsync;
|
|
23
|
+
exports.or = require_swap.or;
|
|
24
|
+
exports.orElse = require_swap.orElse;
|
|
25
|
+
exports.recover = require_swap.recover;
|
|
26
|
+
exports.recoverWith = require_swap.recoverWith;
|
|
27
|
+
exports.swap = require_swap.swap;
|
|
28
|
+
exports.tap = require_swap.tap;
|
|
29
|
+
exports.tapAsync = require_swap.tapAsync;
|
|
30
|
+
exports.tryCatch = require_swap.tryCatch;
|
|
31
|
+
exports.tryCatchAsync = require_swap.tryCatchAsync;
|
|
32
|
+
exports.tryMap = require_swap.tryMap;
|
|
33
|
+
exports.tryMapAsync = require_swap.tryMapAsync;
|
|
33
34
|
exports.zip = require_result.zip;
|
package/dist/operators.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as
|
|
1
|
+
import { v as combine, y as zip } from "./sequence-DDwePRLd.cjs";
|
|
2
|
+
import { C as tap, D as mapErr, E as mapBoth, O as map, S as filter, T as bimap, _ as recoverWith, a as or, b as match, c as tryCatchAsync, d as filterAsync, f as tapAsync, g as recover, h as mapAsync, i as orElse, l as matchAsync, m as mapErrAsync, n as mapOrElse, o as and, p as flatMapAsync, r as mapOr, s as tryMapAsync, t as swap, u as foldAsync, v as tryMap, w as flatMap, x as fold, y as tryCatch } from "./swap-CrHQZIax.cjs";
|
|
3
3
|
export { and, bimap, combine, filter, filterAsync, flatMap, flatMapAsync, fold, foldAsync, map, mapAsync, mapBoth, mapErr, mapErrAsync, mapOr, mapOrElse, match, matchAsync, or, orElse, recover, recoverWith, swap, tap, tapAsync, tryCatch, tryCatchAsync, tryMap, tryMapAsync, zip };
|
package/dist/operators.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as
|
|
1
|
+
import { v as combine, y as zip } from "./sequence-DDwePRLd.mjs";
|
|
2
|
+
import { C as tap, D as mapErr, E as mapBoth, O as map, S as filter, T as bimap, _ as recoverWith, a as or, b as match, c as tryCatchAsync, d as filterAsync, f as tapAsync, g as recover, h as mapAsync, i as orElse, l as matchAsync, m as mapErrAsync, n as mapOrElse, o as and, p as flatMapAsync, r as mapOr, s as tryMapAsync, t as swap, u as foldAsync, v as tryMap, w as flatMap, x as fold, y as tryCatch } from "./swap-DT4LdRFV.mjs";
|
|
3
3
|
export { and, bimap, combine, filter, filterAsync, flatMap, flatMapAsync, fold, foldAsync, map, mapAsync, mapBoth, mapErr, mapErrAsync, mapOr, mapOrElse, match, matchAsync, or, orElse, recover, recoverWith, swap, tap, tapAsync, tryCatch, tryCatchAsync, tryMap, tryMapAsync, zip };
|
package/dist/operators.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as
|
|
1
|
+
import { m as zip, p as combine } from "./result-q9Na2bGa.mjs";
|
|
2
|
+
import { C as tap, D as mapErr, E as mapBoth, O as map, S as filter, T as bimap, _ as recoverWith, a as or, b as match, c as tryCatchAsync, d as filterAsync, f as tapAsync, g as recover, h as mapAsync, i as orElse, l as matchAsync, m as mapErrAsync, n as mapOrElse, o as and, p as flatMapAsync, r as mapOr, s as tryMapAsync, t as swap, u as foldAsync, v as tryMap, w as flatMap, x as fold, y as tryCatch } from "./swap-CFD2g1cB.mjs";
|
|
3
3
|
|
|
4
4
|
export { and, bimap, combine, filter, filterAsync, flatMap, flatMapAsync, fold, foldAsync, map, mapAsync, mapBoth, mapErr, mapErrAsync, mapOr, mapOrElse, match, matchAsync, or, orElse, recover, recoverWith, swap, tap, tapAsync, tryCatch, tryCatchAsync, tryMap, tryMapAsync, zip };
|