@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/README.md
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
# @shirudo/result
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A `Result<T, E>` type for TypeScript. Functions return their failures instead of throwing them.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
```ts docs-check:skip
|
|
6
|
+
function loadUser(id: string): Result<User, UserError>
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
The failure is part of the signature: callers see exactly what can go wrong, the compiler insists both cases are handled, and `value`/`error` are only accessible after narrowing. What used to be a forgotten `catch` is now a type error.
|
|
10
|
+
|
|
11
|
+
The rest of the package is tooling around that one type: pipe operators, async variants, generator-based do-notation, exhaustive error matching, and collection helpers. The library has zero dependencies, ships as ESM and CJS, and runs on Node 20+ and edge runtimes.
|
|
6
12
|
|
|
7
13
|
[](https://github.com/shi-rudo/result-ts/actions/workflows/ci.yml)
|
|
8
14
|
[](https://www.npmjs.com/package/@shirudo/result)
|
|
9
15
|
[](./LICENSE)
|
|
10
|
-
[](https://www.typescriptlang.org/)
|
|
11
|
-
[](https://nodejs.org/)
|
|
12
|
-

|
|
13
16
|
|
|
14
17
|
## Installation
|
|
15
18
|
|
|
@@ -22,12 +25,13 @@ yarn add @shirudo/result
|
|
|
22
25
|
## Quick Start
|
|
23
26
|
|
|
24
27
|
```ts
|
|
25
|
-
import { Result } from '@shirudo/result';
|
|
28
|
+
import { err, ok, type Result } from '@shirudo/result';
|
|
29
|
+
import { map, match } from '@shirudo/result/operators';
|
|
26
30
|
|
|
27
31
|
type User = { id: string; email: string; active: boolean };
|
|
28
32
|
type UserError =
|
|
29
|
-
| {
|
|
30
|
-
| {
|
|
33
|
+
| { code: 'not-found'; id: string }
|
|
34
|
+
| { code: 'inactive'; id: string };
|
|
31
35
|
|
|
32
36
|
const users = new Map<string, User>([
|
|
33
37
|
['1', { id: '1', email: 'ada@example.com', active: true }],
|
|
@@ -35,35 +39,53 @@ const users = new Map<string, User>([
|
|
|
35
39
|
|
|
36
40
|
function loadUser(id: string): Result<User, UserError> {
|
|
37
41
|
const user = users.get(id);
|
|
38
|
-
if (!user) return
|
|
39
|
-
if (!user.active) return
|
|
40
|
-
return
|
|
42
|
+
if (!user) return err({ code: 'not-found', id });
|
|
43
|
+
if (!user.active) return err({ code: 'inactive', id });
|
|
44
|
+
return ok(user);
|
|
41
45
|
}
|
|
42
46
|
|
|
47
|
+
// Narrow explicitly:
|
|
43
48
|
const result = loadUser('1');
|
|
44
|
-
|
|
45
49
|
if (result.isOk()) {
|
|
46
|
-
console.log(result.value.email);
|
|
47
|
-
} else {
|
|
48
|
-
switch (result.error.type) {
|
|
49
|
-
case 'not-found':
|
|
50
|
-
console.error(`Missing user ${result.error.id}`);
|
|
51
|
-
break;
|
|
52
|
-
case 'inactive':
|
|
53
|
-
console.error(`Inactive user ${result.error.id}`);
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
50
|
+
console.log(result.value.email); // `value` is only accessible in this branch
|
|
56
51
|
}
|
|
52
|
+
|
|
53
|
+
// Or compose and resolve in one expression. `map` only runs on Ok,
|
|
54
|
+
// and the error keeps its type all the way to `match`:
|
|
55
|
+
const message = loadUser('1').pipe(
|
|
56
|
+
map(user => `Welcome back, ${user.email}`),
|
|
57
|
+
match({
|
|
58
|
+
ok: greeting => greeting,
|
|
59
|
+
err: error =>
|
|
60
|
+
error.code === 'not-found'
|
|
61
|
+
? `No user with id ${error.id}`
|
|
62
|
+
: `User ${error.id} is deactivated`,
|
|
63
|
+
}),
|
|
64
|
+
);
|
|
57
65
|
```
|
|
58
66
|
|
|
59
|
-
## Why
|
|
67
|
+
## Why Result Instead of try/catch?
|
|
68
|
+
|
|
69
|
+
TypeScript cannot type a `catch` block: every thrown value arrives as `unknown`, and nothing in a function's signature reveals that it throws at all. Callers either remember to catch, or they find out in production.
|
|
70
|
+
|
|
71
|
+
A `Result<User, UserError>` puts the failure into the signature. The compiler forces both states to be handled, narrows `value` and `error` access to the matching state (as in the Quick Start above), and keeps the error type intact across every transformation.
|
|
72
|
+
|
|
73
|
+
## Why This Library?
|
|
74
|
+
|
|
75
|
+
There are several Result implementations for TypeScript. This one is built around a few hard guarantees:
|
|
76
|
+
|
|
77
|
+
- **Error types that cannot lie.** Declaring an explicit error type requires an error mapper: `fromPromise<User, ApiError>(promise)` without one is a compile error, so `E` never silently holds an unmapped `unknown`. And bugs inside the mapper itself are rethrown instead of being disguised as `Err` values.
|
|
78
|
+
- **Exhaustive matching, checked at compile time.** `matchError().when(NotFoundError, ...).run()` only compiles once every error case is handled, and `matchTag` does the same for discriminated unions. Add a new error variant, and every unhandled match site turns red.
|
|
79
|
+
- **Four interchangeable styles, one type.** Explicit `isOk()`/`isErr()` checks, `pipe`/`pipeAsync` operator chains, generator-based do-notation (`task`), and builder-based error matching all work on the same immutable, frozen `Result`. Use whichever style fits each call site.
|
|
80
|
+
- **Safe at runtime boundaries.** `isResult()` validates an internal brand plus payload shape instead of accepting lookalike objects, and `toSerialized()`/`fromSerialized()` round-trip Results through JSON without ambiguity.
|
|
81
|
+
- **Zero dependencies, runs anywhere.** The package ships ESM and CJS builds with tree-shakeable subpath exports, and it runs on Node 20+ and in edge runtimes.
|
|
82
|
+
- **Verified, not promised.** Every TypeScript snippet in this README and the docs is compile-checked in CI, the API is covered by 400+ runtime tests plus compile-time type tests, and the package exports are verified for ESM, CJS, and TypeScript consumers.
|
|
60
83
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
-
|
|
64
|
-
-
|
|
65
|
-
-
|
|
66
|
-
- Package exports are tested for ESM, CJS, and TypeScript consumers.
|
|
84
|
+
## When Not to Use It
|
|
85
|
+
|
|
86
|
+
- If your codebase is already built on [Effect](https://effect.website/), you do not need this package. Its `Either`/`Exit` types come with the surrounding ecosystem.
|
|
87
|
+
- For short scripts and prototypes, plain `try`/`catch` is often the simpler tool. The value of typed errors grows with the number of call sites that must handle them.
|
|
88
|
+
- Keep throwing for programmer errors. Broken invariants and failed assertions should crash loudly; `Result` is for failures the caller is expected to handle.
|
|
67
89
|
|
|
68
90
|
## Common Workflows
|
|
69
91
|
|
|
@@ -74,14 +96,14 @@ import { Result } from '@shirudo/result';
|
|
|
74
96
|
|
|
75
97
|
const parseJson = Result.fromThrowable(
|
|
76
98
|
JSON.parse,
|
|
77
|
-
error => ({
|
|
99
|
+
error => ({ code: 'parse' as const, cause: error }),
|
|
78
100
|
);
|
|
79
101
|
|
|
80
102
|
const parsed = parseJson('{"valid": true}');
|
|
81
103
|
|
|
82
104
|
const response = await Result.fromPromise(
|
|
83
105
|
Promise.resolve({ ok: true }),
|
|
84
|
-
error => ({
|
|
106
|
+
error => ({ code: 'network' as const, cause: error }),
|
|
85
107
|
);
|
|
86
108
|
```
|
|
87
109
|
|
|
@@ -131,27 +153,53 @@ function findUser(id: string) {
|
|
|
131
153
|
function ensureEmail(user: { id: string; email?: string }) {
|
|
132
154
|
return user.email
|
|
133
155
|
? Result.ok(user.email)
|
|
134
|
-
: Result.err({
|
|
156
|
+
: Result.err({ code: 'missing-email' as const, id: user.id });
|
|
135
157
|
}
|
|
136
158
|
|
|
137
|
-
const
|
|
159
|
+
const emailResult = await task(function* () {
|
|
138
160
|
const user = yield* findUser('1');
|
|
139
161
|
return yield* ensureEmail(user);
|
|
140
162
|
});
|
|
141
163
|
```
|
|
142
164
|
|
|
165
|
+
### Handle error classes exhaustively
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
import { Result } from '@shirudo/result';
|
|
169
|
+
|
|
170
|
+
class NotFoundError extends Error {
|
|
171
|
+
readonly code = 'not-found';
|
|
172
|
+
}
|
|
173
|
+
class RateLimitError extends Error {
|
|
174
|
+
readonly code = 'rate-limited';
|
|
175
|
+
constructor(readonly retryAfter: number) {
|
|
176
|
+
super(`rate limited, retry in ${retryAfter}s`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const result: Result<string, NotFoundError | RateLimitError> = Result.err(new RateLimitError(30));
|
|
181
|
+
|
|
182
|
+
if (result.isErr()) {
|
|
183
|
+
const message = result
|
|
184
|
+
.matchError()
|
|
185
|
+
.when(NotFoundError, () => 'No such record')
|
|
186
|
+
.when(RateLimitError, error => `Retry in ${error.retryAfter}s`)
|
|
187
|
+
.run(); // run() only compiles because every error class is handled
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
143
191
|
### Match discriminated-union errors
|
|
144
192
|
|
|
145
193
|
```ts
|
|
146
194
|
import { Result, matchTag } from '@shirudo/result';
|
|
147
195
|
|
|
148
196
|
type DomainError =
|
|
149
|
-
| {
|
|
150
|
-
| {
|
|
197
|
+
| { code: 'network'; retryAfter: number }
|
|
198
|
+
| { code: 'validation'; field: string };
|
|
151
199
|
|
|
152
|
-
const failed = Result.err<DomainError>({
|
|
200
|
+
const failed = Result.err<DomainError>({ code: 'network', retryAfter: 30 });
|
|
153
201
|
|
|
154
|
-
const message = matchTag(failed, '
|
|
202
|
+
const message = matchTag(failed, 'code', {
|
|
155
203
|
network: error => `Retry in ${error.retryAfter}s`,
|
|
156
204
|
validation: error => `Invalid field: ${error.field}`,
|
|
157
205
|
});
|
|
@@ -186,7 +234,7 @@ The full documentation lives in `docs/` and is built with VitePress.
|
|
|
186
234
|
- [Collections](docs/api/collections.md)
|
|
187
235
|
- [Error Classes](docs/api/errors.md)
|
|
188
236
|
- [Version 1 Migration](docs/migration/v1.md)
|
|
189
|
-
- [Design Decisions](docs/decisions/lazy-async-abstraction.md)
|
|
237
|
+
- [Design Decisions](docs/decisions/lazy-async-abstraction.md) ([Defensive State Checks](docs/decisions/defensive-state-checks.md))
|
|
190
238
|
|
|
191
239
|
## Development
|
|
192
240
|
|
package/dist/collections.cjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_result = require('./result-BBOGxvSH.cjs');
|
|
3
|
+
const require_flatten = require('./flatten-B_XIkaOK.cjs');
|
|
3
4
|
|
|
4
5
|
exports.all = require_result.all;
|
|
5
6
|
exports.collectAllErrors = require_flatten.collectAllErrors;
|
|
6
|
-
exports.collectFirstOk =
|
|
7
|
+
exports.collectFirstOk = require_flatten.collectFirstOk;
|
|
7
8
|
exports.collectFirstOkAsync = require_flatten.collectFirstOkAsync;
|
|
8
9
|
exports.collectFirstOkParallelAsync = require_flatten.collectFirstOkParallelAsync;
|
|
9
10
|
exports.flatten = require_flatten.flatten;
|
package/dist/collections.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as collectFirstOkAsync, i as collectFirstOkParallelAsync, n as partition, o as
|
|
1
|
+
import { n as sequence, t as all } from "./sequence-DDwePRLd.cjs";
|
|
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-D0K8UcQH.cjs";
|
|
3
3
|
export { all, collectAllErrors, collectFirstOk, collectFirstOkAsync, collectFirstOkParallelAsync, flatten, partition, sequence, sequenceRecord };
|
package/dist/collections.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as collectFirstOkAsync, i as collectFirstOkParallelAsync, n as partition, o as
|
|
1
|
+
import { n as sequence, t as all } 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
3
|
export { all, collectAllErrors, collectFirstOk, collectFirstOkAsync, collectFirstOkParallelAsync, flatten, partition, sequence, sequenceRecord };
|
package/dist/collections.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as collectFirstOkAsync, i as collectFirstOkParallelAsync, n as partition, o as
|
|
1
|
+
import { g as sequence, h as all } from "./result-q9Na2bGa.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-ChTL5BfA.mjs";
|
|
3
3
|
|
|
4
4
|
export { all, collectAllErrors, collectFirstOk, collectFirstOkAsync, collectFirstOkParallelAsync, flatten, partition, sequence, sequenceRecord };
|
package/dist/errors.cjs
CHANGED
|
@@ -1,21 +1,132 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
3
|
+
//#region src/errors.ts
|
|
4
|
+
const ERR_INVALID_RESULT_STATE = "ERR_INVALID_RESULT_STATE";
|
|
5
|
+
/** @deprecated Use {@link ERR_INVALID_RESULT_STATE} instead. */
|
|
6
|
+
const ERR_INVALID_STATE = ERR_INVALID_RESULT_STATE;
|
|
7
|
+
const ERR_TASK_YIELD_NOT_RESULT = "ERR_TASK_YIELD_NOT_RESULT";
|
|
8
|
+
const ERR_MATCH_ON_OK = "ERR_MATCH_ON_OK";
|
|
9
|
+
const ERR_MATCH_ERR_HANDLER_NOT_RESULT = "ERR_MATCH_ERR_HANDLER_NOT_RESULT";
|
|
10
|
+
const ERR_MATCH_TAG_MISSING_HANDLER = "ERR_MATCH_TAG_MISSING_HANDLER";
|
|
11
|
+
const ERR_UNWRAP_ON_ERR = "ERR_UNWRAP_ON_ERR";
|
|
12
|
+
const ERR_UNWRAP_ERR_ON_OK = "ERR_UNWRAP_ERR_ON_OK";
|
|
13
|
+
const ERR_EXPECT_OK = "ERR_EXPECT_OK";
|
|
14
|
+
const ERR_EXPECT_ERR = "ERR_EXPECT_ERR";
|
|
15
|
+
const formatResultErrorMessage = (code, message, context) => {
|
|
16
|
+
if (context) return `${code}: ${message} (context: ${context})`;
|
|
17
|
+
return `${code}: ${message}`;
|
|
18
|
+
};
|
|
19
|
+
var ResultError = class extends Error {
|
|
20
|
+
code;
|
|
21
|
+
context;
|
|
22
|
+
constructor(message, code, context) {
|
|
23
|
+
super(formatResultErrorMessage(code, message, context));
|
|
24
|
+
this.code = code;
|
|
25
|
+
this.context = context;
|
|
26
|
+
this.name = new.target.name;
|
|
27
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var ResultTypeError = class extends TypeError {
|
|
31
|
+
code;
|
|
32
|
+
context;
|
|
33
|
+
constructor(message, code, context) {
|
|
34
|
+
super(formatResultErrorMessage(code, message, context));
|
|
35
|
+
this.code = code;
|
|
36
|
+
this.context = context;
|
|
37
|
+
this.name = new.target.name;
|
|
38
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const INVALID_RESULT_STATE_MESSAGE = "Unreachable: Result is neither Ok nor Err";
|
|
42
|
+
var InvalidResultStateError = class extends ResultError {
|
|
43
|
+
constructor(context) {
|
|
44
|
+
super(INVALID_RESULT_STATE_MESSAGE, ERR_INVALID_RESULT_STATE, context);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var TaskYieldNotResultError = class extends ResultTypeError {
|
|
48
|
+
yieldedValue;
|
|
49
|
+
constructor(yieldedValue) {
|
|
50
|
+
super("task() expected yielded values to be Result. Use `yield*` on a Result.", ERR_TASK_YIELD_NOT_RESULT);
|
|
51
|
+
this.yieldedValue = yieldedValue;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var MatchOnOkError = class extends ResultTypeError {
|
|
55
|
+
constructor(methodName = "match") {
|
|
56
|
+
super(`${methodName}() can only be called on Err results. Use \`if (result.isErr()) { ... }\` first.`, ERR_MATCH_ON_OK);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var MatchErrHandlerNotResultError = class extends ResultTypeError {
|
|
60
|
+
handlerName;
|
|
61
|
+
returnedValue;
|
|
62
|
+
constructor(handlerName, returnedValue) {
|
|
63
|
+
super(`matchErr().${handlerName}() handlers must return a Result. Wrap values with ok(...) or err(...).`, ERR_MATCH_ERR_HANDLER_NOT_RESULT);
|
|
64
|
+
this.handlerName = handlerName;
|
|
65
|
+
this.returnedValue = returnedValue;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
var MatchTagMissingHandlerError = class extends ResultTypeError {
|
|
69
|
+
tagValue;
|
|
70
|
+
constructor(tagValue) {
|
|
71
|
+
super(`matchTag() has no handler for tag "${String(tagValue)}".`, ERR_MATCH_TAG_MISSING_HANDLER);
|
|
72
|
+
this.tagValue = tagValue;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
var UnwrapOnErrError = class extends ResultTypeError {
|
|
76
|
+
errorValue;
|
|
77
|
+
constructor(errorValue) {
|
|
78
|
+
super(`Called unwrap() on Err: ${String(errorValue)}`, ERR_UNWRAP_ON_ERR);
|
|
79
|
+
this.errorValue = errorValue;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var UnwrapErrOnOkError = class extends ResultTypeError {
|
|
83
|
+
okValue;
|
|
84
|
+
constructor(okValue) {
|
|
85
|
+
super(`Called unwrapErr() on Ok: ${String(okValue)}`, ERR_UNWRAP_ERR_ON_OK);
|
|
86
|
+
this.okValue = okValue;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
var ExpectOkError = class extends ResultError {
|
|
90
|
+
expectedMessage;
|
|
91
|
+
errorValue;
|
|
92
|
+
constructor(expectedMessage, errorValue) {
|
|
93
|
+
super(errorValue === void 0 ? expectedMessage : `${expectedMessage}: ${String(errorValue)}`, ERR_EXPECT_OK);
|
|
94
|
+
this.expectedMessage = expectedMessage;
|
|
95
|
+
this.errorValue = errorValue;
|
|
96
|
+
if (errorValue !== void 0) this.cause = errorValue;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
var ExpectErrError = class extends ResultError {
|
|
100
|
+
expectedMessage;
|
|
101
|
+
okValue;
|
|
102
|
+
constructor(expectedMessage, okValue) {
|
|
103
|
+
super(okValue === void 0 ? expectedMessage : `${expectedMessage}: ${String(okValue)}`, ERR_EXPECT_ERR);
|
|
104
|
+
this.expectedMessage = expectedMessage;
|
|
105
|
+
this.okValue = okValue;
|
|
106
|
+
if (okValue !== void 0) this.cause = okValue;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
//#endregion
|
|
111
|
+
exports.ERR_EXPECT_ERR = ERR_EXPECT_ERR;
|
|
112
|
+
exports.ERR_EXPECT_OK = ERR_EXPECT_OK;
|
|
113
|
+
exports.ERR_INVALID_RESULT_STATE = ERR_INVALID_RESULT_STATE;
|
|
114
|
+
exports.ERR_INVALID_STATE = ERR_INVALID_STATE;
|
|
115
|
+
exports.ERR_MATCH_ERR_HANDLER_NOT_RESULT = ERR_MATCH_ERR_HANDLER_NOT_RESULT;
|
|
116
|
+
exports.ERR_MATCH_ON_OK = ERR_MATCH_ON_OK;
|
|
117
|
+
exports.ERR_MATCH_TAG_MISSING_HANDLER = ERR_MATCH_TAG_MISSING_HANDLER;
|
|
118
|
+
exports.ERR_TASK_YIELD_NOT_RESULT = ERR_TASK_YIELD_NOT_RESULT;
|
|
119
|
+
exports.ERR_UNWRAP_ERR_ON_OK = ERR_UNWRAP_ERR_ON_OK;
|
|
120
|
+
exports.ERR_UNWRAP_ON_ERR = ERR_UNWRAP_ON_ERR;
|
|
121
|
+
exports.ExpectErrError = ExpectErrError;
|
|
122
|
+
exports.ExpectOkError = ExpectOkError;
|
|
123
|
+
exports.InvalidResultStateError = InvalidResultStateError;
|
|
124
|
+
exports.MatchErrHandlerNotResultError = MatchErrHandlerNotResultError;
|
|
125
|
+
exports.MatchOnOkError = MatchOnOkError;
|
|
126
|
+
exports.MatchTagMissingHandlerError = MatchTagMissingHandlerError;
|
|
127
|
+
exports.ResultError = ResultError;
|
|
128
|
+
exports.ResultTypeError = ResultTypeError;
|
|
129
|
+
exports.TaskYieldNotResultError = TaskYieldNotResultError;
|
|
130
|
+
exports.UnwrapErrOnOkError = UnwrapErrOnOkError;
|
|
131
|
+
exports.UnwrapOnErrError = UnwrapOnErrError;
|
|
132
|
+
//# sourceMappingURL=errors.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["export 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 \"${String(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: ${String(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: ${String(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}: ${String(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}: ${String(okValue)}`, ERR_EXPECT_ERR);\n this.expectedMessage = expectedMessage;\n this.okValue = okValue;\n if (okValue !== undefined) this.cause = okValue;\n }\n}\n"],"mappings":";;;AAAA,MAAa,2BAA2B;;AAExC,MAAa,oBAAqD;AAClE,MAAa,4BAA4B;AACzC,MAAa,kBAAkB;AAC/B,MAAa,mCAAmC;AAChD,MAAa,gCAAgC;AAC7C,MAAa,oBAAoB;AACjC,MAAa,uBAAuB;AACpC,MAAa,gBAAgB;AAC7B,MAAa,iBAAiB;AAa9B,MAAM,4BAA4B,MAAuB,SAAiB,YAA6B;CACnG,IAAI,SACA,OAAO,GAAG,KAAK,IAAI,QAAQ,aAAa,QAAQ;CAEpD,OAAO,GAAG,KAAK,IAAI;AACvB;AAEA,IAAa,cAAb,cAAiC,MAAM;CACnC,AAAS;CACT,AAAS;CAET,YAAY,SAAiB,MAAuB,SAAkB;EAClE,MAAM,yBAAyB,MAAM,SAAS,OAAO,CAAC;EACtD,KAAK,OAAO;EACZ,KAAK,UAAU;EACf,KAAK,OAAO,IAAI,OAAO;EACvB,OAAO,eAAe,MAAM,IAAI,OAAO,SAAS;CACpD;AACJ;AAEA,IAAa,kBAAb,cAAqC,UAAU;CAC3C,AAAS;CACT,AAAS;CAET,YAAY,SAAiB,MAAuB,SAAkB;EAClE,MAAM,yBAAyB,MAAM,SAAS,OAAO,CAAC;EACtD,KAAK,OAAO;EACZ,KAAK,UAAU;EACf,KAAK,OAAO,IAAI,OAAO;EACvB,OAAO,eAAe,MAAM,IAAI,OAAO,SAAS;CACpD;AACJ;AAEA,MAAM,+BAA+B;AAErC,IAAa,0BAAb,cAA6C,YAAY;CACrD,YAAY,SAAkB;EAC1B,MAAM,8BAA8B,0BAA0B,OAAO;CACzE;AACJ;AAEA,IAAa,0BAAb,cAA6C,gBAAgB;CACzD,AAAS;CAET,YAAY,cAAuB;EAC/B,MAAM,0EAA0E,yBAAyB;EACzG,KAAK,eAAe;CACxB;AACJ;AAEA,IAAa,iBAAb,cAAoC,gBAAgB;CAChD,YAAY,aAAa,SAAS;EAC9B,MAAM,GAAG,WAAW,mFAAmF,eAAe;CAC1H;AACJ;AAEA,IAAa,gCAAb,cAAmD,gBAAgB;CAC/D,AAAS;CACT,AAAS;CAET,YAAY,aAAqB,eAAwB;EACrD,MAAM,cAAc,YAAY,0EAA0E,gCAAgC;EAC1I,KAAK,cAAc;EACnB,KAAK,gBAAgB;CACzB;AACJ;AAEA,IAAa,8BAAb,cAAiD,gBAAgB;CAC7D,AAAS;CAET,YAAY,UAAmB;EAC3B,MAAM,sCAAsC,OAAO,QAAQ,EAAE,KAAK,6BAA6B;EAC/F,KAAK,WAAW;CACpB;AACJ;AAEA,IAAa,mBAAb,cAAsC,gBAAgB;CAClD,AAAS;CAET,YAAY,YAAqB;EAC7B,MAAM,2BAA2B,OAAO,UAAU,KAAK,iBAAiB;EACxE,KAAK,aAAa;CACtB;AACJ;AAEA,IAAa,qBAAb,cAAwC,gBAAgB;CACpD,AAAS;CAET,YAAY,SAAkB;EAC1B,MAAM,6BAA6B,OAAO,OAAO,KAAK,oBAAoB;EAC1E,KAAK,UAAU;CACnB;AACJ;AAEA,IAAa,gBAAb,cAAmC,YAAY;CAC3C,AAAS;CACT,AAAS;CAET,YAAY,iBAAyB,YAAsB;EACvD,MAAM,eAAe,SAAY,kBAAkB,GAAG,gBAAgB,IAAI,OAAO,UAAU,KAAK,aAAa;EAC7G,KAAK,kBAAkB;EACvB,KAAK,aAAa;EAClB,IAAI,eAAe,QAAW,KAAK,QAAQ;CAC/C;AACJ;AAEA,IAAa,iBAAb,cAAoC,YAAY;CAC5C,AAAS;CACT,AAAS;CAET,YAAY,iBAAyB,SAAmB;EACpD,MAAM,YAAY,SAAY,kBAAkB,GAAG,gBAAgB,IAAI,OAAO,OAAO,KAAK,cAAc;EACxG,KAAK,kBAAkB;EACvB,KAAK,UAAU;EACf,IAAI,YAAY,QAAW,KAAK,QAAQ;CAC5C;AACJ"}
|
package/dist/errors.d.cts
CHANGED
|
@@ -1,2 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/errors.d.ts
|
|
2
|
+
declare const ERR_INVALID_RESULT_STATE: "ERR_INVALID_RESULT_STATE";
|
|
3
|
+
/** @deprecated Use {@link ERR_INVALID_RESULT_STATE} instead. */
|
|
4
|
+
declare const ERR_INVALID_STATE: typeof ERR_INVALID_RESULT_STATE;
|
|
5
|
+
declare const ERR_TASK_YIELD_NOT_RESULT: "ERR_TASK_YIELD_NOT_RESULT";
|
|
6
|
+
declare const ERR_MATCH_ON_OK: "ERR_MATCH_ON_OK";
|
|
7
|
+
declare const ERR_MATCH_ERR_HANDLER_NOT_RESULT: "ERR_MATCH_ERR_HANDLER_NOT_RESULT";
|
|
8
|
+
declare const ERR_MATCH_TAG_MISSING_HANDLER: "ERR_MATCH_TAG_MISSING_HANDLER";
|
|
9
|
+
declare const ERR_UNWRAP_ON_ERR: "ERR_UNWRAP_ON_ERR";
|
|
10
|
+
declare const ERR_UNWRAP_ERR_ON_OK: "ERR_UNWRAP_ERR_ON_OK";
|
|
11
|
+
declare const ERR_EXPECT_OK: "ERR_EXPECT_OK";
|
|
12
|
+
declare const ERR_EXPECT_ERR: "ERR_EXPECT_ERR";
|
|
13
|
+
type ResultErrorCode = typeof ERR_INVALID_RESULT_STATE | typeof ERR_TASK_YIELD_NOT_RESULT | typeof ERR_MATCH_ON_OK | typeof ERR_MATCH_ERR_HANDLER_NOT_RESULT | typeof ERR_MATCH_TAG_MISSING_HANDLER | typeof ERR_UNWRAP_ON_ERR | typeof ERR_UNWRAP_ERR_ON_OK | typeof ERR_EXPECT_OK | typeof ERR_EXPECT_ERR;
|
|
14
|
+
declare class ResultError extends Error {
|
|
15
|
+
readonly code: ResultErrorCode;
|
|
16
|
+
readonly context?: string;
|
|
17
|
+
constructor(message: string, code: ResultErrorCode, context?: string);
|
|
18
|
+
}
|
|
19
|
+
declare class ResultTypeError extends TypeError {
|
|
20
|
+
readonly code: ResultErrorCode;
|
|
21
|
+
readonly context?: string;
|
|
22
|
+
constructor(message: string, code: ResultErrorCode, context?: string);
|
|
23
|
+
}
|
|
24
|
+
declare class InvalidResultStateError extends ResultError {
|
|
25
|
+
constructor(context?: string);
|
|
26
|
+
}
|
|
27
|
+
declare class TaskYieldNotResultError extends ResultTypeError {
|
|
28
|
+
readonly yieldedValue: unknown;
|
|
29
|
+
constructor(yieldedValue: unknown);
|
|
30
|
+
}
|
|
31
|
+
declare class MatchOnOkError extends ResultTypeError {
|
|
32
|
+
constructor(methodName?: string);
|
|
33
|
+
}
|
|
34
|
+
declare class MatchErrHandlerNotResultError extends ResultTypeError {
|
|
35
|
+
readonly handlerName: string;
|
|
36
|
+
readonly returnedValue: unknown;
|
|
37
|
+
constructor(handlerName: string, returnedValue: unknown);
|
|
38
|
+
}
|
|
39
|
+
declare class MatchTagMissingHandlerError extends ResultTypeError {
|
|
40
|
+
readonly tagValue: unknown;
|
|
41
|
+
constructor(tagValue: unknown);
|
|
42
|
+
}
|
|
43
|
+
declare class UnwrapOnErrError extends ResultTypeError {
|
|
44
|
+
readonly errorValue: unknown;
|
|
45
|
+
constructor(errorValue: unknown);
|
|
46
|
+
}
|
|
47
|
+
declare class UnwrapErrOnOkError extends ResultTypeError {
|
|
48
|
+
readonly okValue: unknown;
|
|
49
|
+
constructor(okValue: unknown);
|
|
50
|
+
}
|
|
51
|
+
declare class ExpectOkError extends ResultError {
|
|
52
|
+
readonly expectedMessage: string;
|
|
53
|
+
readonly errorValue: unknown;
|
|
54
|
+
constructor(expectedMessage: string, errorValue?: unknown);
|
|
55
|
+
}
|
|
56
|
+
declare class ExpectErrError extends ResultError {
|
|
57
|
+
readonly expectedMessage: string;
|
|
58
|
+
readonly okValue: unknown;
|
|
59
|
+
constructor(expectedMessage: string, okValue?: unknown);
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
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, ExpectErrError, ExpectOkError, InvalidResultStateError, MatchErrHandlerNotResultError, MatchOnOkError, MatchTagMissingHandlerError, ResultError, ResultErrorCode, ResultTypeError, TaskYieldNotResultError, UnwrapErrOnOkError, UnwrapOnErrError };
|
|
63
|
+
//# sourceMappingURL=errors.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.cts","names":[],"sources":["../src/errors.ts"],"mappings":";cAAa,wBAAA;AAAb;AAAA,cAEa,iBAAA,SAA0B,wBAAA;AAAA,cAC1B,yBAAA;AAAA,cACA,eAAA;AAAA,cACA,gCAAA;AAAA,cACA,6BAAA;AAAA,cACA,iBAAA;AAAA,cACA,oBAAA;AAAA,cACA,aAAA;AAAA,cACA,cAAA;AAAA,KAED,eAAA,UACC,wBAAA,UACA,yBAAA,UACA,eAAA,UACA,gCAAA,UACA,6BAAA,UACA,iBAAA,UACA,oBAAA,UACA,aAAA,UACA,cAAA;AAAA,cASA,WAAA,SAAoB,KAAA;EAAA,SACpB,IAAA,EAAM,eAAA;EAAA,SACN,OAAA;EAET,WAAA,CAAY,OAAA,UAAiB,IAAA,EAAM,eAAA,EAAiB,OAAA;AAAA;AAAA,cAS3C,eAAA,SAAwB,SAAA;EAAA,SACxB,IAAA,EAAM,eAAA;EAAA,SACN,OAAA;EAET,WAAA,CAAY,OAAA,UAAiB,IAAA,EAAM,eAAA,EAAiB,OAAA;AAAA;AAAA,cAW3C,uBAAA,SAAgC,WAAA;EACzC,WAAA,CAAY,OAAA;AAAA;AAAA,cAKH,uBAAA,SAAgC,eAAA;EAAA,SAChC,YAAA;EAET,WAAA,CAAY,YAAA;AAAA;AAAA,cAMH,cAAA,SAAuB,eAAA;EAChC,WAAA,CAAY,UAAA;AAAA;AAAA,cAKH,6BAAA,SAAsC,eAAA;EAAA,SACtC,WAAA;EAAA,SACA,aAAA;EAET,WAAA,CAAY,WAAA,UAAqB,aAAA;AAAA;AAAA,cAOxB,2BAAA,SAAoC,eAAA;EAAA,SACpC,QAAA;EAET,WAAA,CAAY,QAAA;AAAA;AAAA,cAMH,gBAAA,SAAyB,eAAA;EAAA,SACzB,UAAA;EAET,WAAA,CAAY,UAAA;AAAA;AAAA,cAMH,kBAAA,SAA2B,eAAA;EAAA,SAC3B,OAAA;EAET,WAAA,CAAY,OAAA;AAAA;AAAA,cAMH,aAAA,SAAsB,WAAA;EAAA,SACtB,eAAA;EAAA,SACA,UAAA;EAET,WAAA,CAAY,eAAA,UAAyB,UAAA;AAAA;AAAA,cAQ5B,cAAA,SAAuB,WAAA;EAAA,SACvB,eAAA;EAAA,SACA,OAAA;EAET,WAAA,CAAY,eAAA,UAAyB,OAAA;AAAA"}
|
package/dist/errors.d.mts
CHANGED
|
@@ -1,2 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/errors.d.ts
|
|
2
|
+
declare const ERR_INVALID_RESULT_STATE: "ERR_INVALID_RESULT_STATE";
|
|
3
|
+
/** @deprecated Use {@link ERR_INVALID_RESULT_STATE} instead. */
|
|
4
|
+
declare const ERR_INVALID_STATE: typeof ERR_INVALID_RESULT_STATE;
|
|
5
|
+
declare const ERR_TASK_YIELD_NOT_RESULT: "ERR_TASK_YIELD_NOT_RESULT";
|
|
6
|
+
declare const ERR_MATCH_ON_OK: "ERR_MATCH_ON_OK";
|
|
7
|
+
declare const ERR_MATCH_ERR_HANDLER_NOT_RESULT: "ERR_MATCH_ERR_HANDLER_NOT_RESULT";
|
|
8
|
+
declare const ERR_MATCH_TAG_MISSING_HANDLER: "ERR_MATCH_TAG_MISSING_HANDLER";
|
|
9
|
+
declare const ERR_UNWRAP_ON_ERR: "ERR_UNWRAP_ON_ERR";
|
|
10
|
+
declare const ERR_UNWRAP_ERR_ON_OK: "ERR_UNWRAP_ERR_ON_OK";
|
|
11
|
+
declare const ERR_EXPECT_OK: "ERR_EXPECT_OK";
|
|
12
|
+
declare const ERR_EXPECT_ERR: "ERR_EXPECT_ERR";
|
|
13
|
+
type ResultErrorCode = typeof ERR_INVALID_RESULT_STATE | typeof ERR_TASK_YIELD_NOT_RESULT | typeof ERR_MATCH_ON_OK | typeof ERR_MATCH_ERR_HANDLER_NOT_RESULT | typeof ERR_MATCH_TAG_MISSING_HANDLER | typeof ERR_UNWRAP_ON_ERR | typeof ERR_UNWRAP_ERR_ON_OK | typeof ERR_EXPECT_OK | typeof ERR_EXPECT_ERR;
|
|
14
|
+
declare class ResultError extends Error {
|
|
15
|
+
readonly code: ResultErrorCode;
|
|
16
|
+
readonly context?: string;
|
|
17
|
+
constructor(message: string, code: ResultErrorCode, context?: string);
|
|
18
|
+
}
|
|
19
|
+
declare class ResultTypeError extends TypeError {
|
|
20
|
+
readonly code: ResultErrorCode;
|
|
21
|
+
readonly context?: string;
|
|
22
|
+
constructor(message: string, code: ResultErrorCode, context?: string);
|
|
23
|
+
}
|
|
24
|
+
declare class InvalidResultStateError extends ResultError {
|
|
25
|
+
constructor(context?: string);
|
|
26
|
+
}
|
|
27
|
+
declare class TaskYieldNotResultError extends ResultTypeError {
|
|
28
|
+
readonly yieldedValue: unknown;
|
|
29
|
+
constructor(yieldedValue: unknown);
|
|
30
|
+
}
|
|
31
|
+
declare class MatchOnOkError extends ResultTypeError {
|
|
32
|
+
constructor(methodName?: string);
|
|
33
|
+
}
|
|
34
|
+
declare class MatchErrHandlerNotResultError extends ResultTypeError {
|
|
35
|
+
readonly handlerName: string;
|
|
36
|
+
readonly returnedValue: unknown;
|
|
37
|
+
constructor(handlerName: string, returnedValue: unknown);
|
|
38
|
+
}
|
|
39
|
+
declare class MatchTagMissingHandlerError extends ResultTypeError {
|
|
40
|
+
readonly tagValue: unknown;
|
|
41
|
+
constructor(tagValue: unknown);
|
|
42
|
+
}
|
|
43
|
+
declare class UnwrapOnErrError extends ResultTypeError {
|
|
44
|
+
readonly errorValue: unknown;
|
|
45
|
+
constructor(errorValue: unknown);
|
|
46
|
+
}
|
|
47
|
+
declare class UnwrapErrOnOkError extends ResultTypeError {
|
|
48
|
+
readonly okValue: unknown;
|
|
49
|
+
constructor(okValue: unknown);
|
|
50
|
+
}
|
|
51
|
+
declare class ExpectOkError extends ResultError {
|
|
52
|
+
readonly expectedMessage: string;
|
|
53
|
+
readonly errorValue: unknown;
|
|
54
|
+
constructor(expectedMessage: string, errorValue?: unknown);
|
|
55
|
+
}
|
|
56
|
+
declare class ExpectErrError extends ResultError {
|
|
57
|
+
readonly expectedMessage: string;
|
|
58
|
+
readonly okValue: unknown;
|
|
59
|
+
constructor(expectedMessage: string, okValue?: unknown);
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
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, ExpectErrError, ExpectOkError, InvalidResultStateError, MatchErrHandlerNotResultError, MatchOnOkError, MatchTagMissingHandlerError, ResultError, ResultErrorCode, ResultTypeError, TaskYieldNotResultError, UnwrapErrOnOkError, UnwrapOnErrError };
|
|
63
|
+
//# sourceMappingURL=errors.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.mts","names":[],"sources":["../src/errors.ts"],"mappings":";cAAa,wBAAA;AAAb;AAAA,cAEa,iBAAA,SAA0B,wBAAA;AAAA,cAC1B,yBAAA;AAAA,cACA,eAAA;AAAA,cACA,gCAAA;AAAA,cACA,6BAAA;AAAA,cACA,iBAAA;AAAA,cACA,oBAAA;AAAA,cACA,aAAA;AAAA,cACA,cAAA;AAAA,KAED,eAAA,UACC,wBAAA,UACA,yBAAA,UACA,eAAA,UACA,gCAAA,UACA,6BAAA,UACA,iBAAA,UACA,oBAAA,UACA,aAAA,UACA,cAAA;AAAA,cASA,WAAA,SAAoB,KAAA;EAAA,SACpB,IAAA,EAAM,eAAA;EAAA,SACN,OAAA;EAET,WAAA,CAAY,OAAA,UAAiB,IAAA,EAAM,eAAA,EAAiB,OAAA;AAAA;AAAA,cAS3C,eAAA,SAAwB,SAAA;EAAA,SACxB,IAAA,EAAM,eAAA;EAAA,SACN,OAAA;EAET,WAAA,CAAY,OAAA,UAAiB,IAAA,EAAM,eAAA,EAAiB,OAAA;AAAA;AAAA,cAW3C,uBAAA,SAAgC,WAAA;EACzC,WAAA,CAAY,OAAA;AAAA;AAAA,cAKH,uBAAA,SAAgC,eAAA;EAAA,SAChC,YAAA;EAET,WAAA,CAAY,YAAA;AAAA;AAAA,cAMH,cAAA,SAAuB,eAAA;EAChC,WAAA,CAAY,UAAA;AAAA;AAAA,cAKH,6BAAA,SAAsC,eAAA;EAAA,SACtC,WAAA;EAAA,SACA,aAAA;EAET,WAAA,CAAY,WAAA,UAAqB,aAAA;AAAA;AAAA,cAOxB,2BAAA,SAAoC,eAAA;EAAA,SACpC,QAAA;EAET,WAAA,CAAY,QAAA;AAAA;AAAA,cAMH,gBAAA,SAAyB,eAAA;EAAA,SACzB,UAAA;EAET,WAAA,CAAY,UAAA;AAAA;AAAA,cAMH,kBAAA,SAA2B,eAAA;EAAA,SAC3B,OAAA;EAET,WAAA,CAAY,OAAA;AAAA;AAAA,cAMH,aAAA,SAAsB,WAAA;EAAA,SACtB,eAAA;EAAA,SACA,UAAA;EAET,WAAA,CAAY,eAAA,UAAyB,UAAA;AAAA;AAAA,cAQ5B,cAAA,SAAuB,WAAA;EAAA,SACvB,eAAA;EAAA,SACA,OAAA;EAET,WAAA,CAAY,eAAA,UAAyB,OAAA;AAAA"}
|