@pvorona/failable 0.0.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +117 -254
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +95 -56
- package/dist/lib/failable.d.ts +46 -84
- package/dist/lib/failable.d.ts.map +1 -1
- package/package.json +12 -1
- package/dist/lib/constants.d.ts +0 -4
- package/dist/lib/constants.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# @pvorona/failable
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Typed success/failure results for expected failures in TypeScript.
|
|
4
|
+
|
|
5
|
+
`Failable<T, E>` is a discriminated union of `Success<T>` and `Failure<E>`. In the common case, you model the return type explicitly, construct with `success(...)` / `failure(...)`, and branch with `isSuccess(...)` / `isFailure(...)` or the `isSuccess` / `isError` flags.
|
|
4
6
|
|
|
5
7
|
## Install
|
|
6
8
|
|
|
@@ -8,326 +10,187 @@ A typed result type for expected failures. `Failable<T, E>` is a discriminated u
|
|
|
8
10
|
npm i @pvorona/failable
|
|
9
11
|
```
|
|
10
12
|
|
|
11
|
-
##
|
|
13
|
+
## Quick start
|
|
12
14
|
|
|
13
15
|
```ts
|
|
14
|
-
import { Failable } from '@pvorona/failable';
|
|
16
|
+
import type { Failable } from '@pvorona/failable';
|
|
17
|
+
import { failure, isFailure, success } from '@pvorona/failable';
|
|
15
18
|
|
|
16
|
-
|
|
19
|
+
function divide(a: number, b: number): Failable<number, string> {
|
|
20
|
+
if (b === 0) return failure('Cannot divide by zero');
|
|
17
21
|
|
|
18
|
-
|
|
19
|
-
console.log(result.data);
|
|
20
|
-
} else {
|
|
21
|
-
console.error(result.error);
|
|
22
|
+
return success(a / b);
|
|
22
23
|
}
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
### Factories
|
|
26
|
-
|
|
27
|
-
```ts
|
|
28
|
-
import { Failable } from '@pvorona/failable';
|
|
29
|
-
|
|
30
|
-
const success = Failable.ofSuccess(42);
|
|
31
|
-
const failure = Failable.ofError(new Error('boom'));
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
### Fallbacks
|
|
35
|
-
|
|
36
|
-
```ts
|
|
37
|
-
import { Failable } from '@pvorona/failable';
|
|
38
|
-
|
|
39
|
-
const failure = Failable.ofError(new Error('boom'));
|
|
40
|
-
|
|
41
|
-
const value = failure.getOr('default'); // 'default'
|
|
42
|
-
const recovered = failure.or('fallback'); // Success<'fallback'>
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
### Wrapping async work
|
|
46
|
-
|
|
47
|
-
```ts
|
|
48
|
-
import { Failable } from '@pvorona/failable';
|
|
49
|
-
|
|
50
|
-
const result = await Failable.from(fetch('/api'));
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
### Structured-clone transport
|
|
54
|
-
|
|
55
|
-
`Failable` instances use Symbols and prototype methods that do not survive structured cloning (`postMessage`, `chrome.runtime.sendMessage`, etc.). Convert to a plain object first:
|
|
56
|
-
|
|
57
|
-
```ts
|
|
58
|
-
import { Failable } from '@pvorona/failable';
|
|
59
|
-
|
|
60
|
-
// sender
|
|
61
|
-
const wire = Failable.toFailableLike(result);
|
|
62
|
-
postMessage(wire);
|
|
63
|
-
|
|
64
|
-
// receiver
|
|
65
|
-
const hydrated = Failable.from(wire);
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
## API
|
|
69
|
-
|
|
70
|
-
### `const enum FailableStatus`
|
|
71
24
|
|
|
72
|
-
|
|
25
|
+
const result = divide(10, 2);
|
|
73
26
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
27
|
+
if (isFailure(result)) {
|
|
28
|
+
console.error(result.error);
|
|
29
|
+
} else {
|
|
30
|
+
console.log(result.data);
|
|
78
31
|
}
|
|
79
32
|
```
|
|
80
33
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
```ts
|
|
84
|
-
import { FailableStatus, type FailableLike } from '@pvorona/failable';
|
|
85
|
-
|
|
86
|
-
const ok: FailableLike<number, string> = {
|
|
87
|
-
status: FailableStatus.Success,
|
|
88
|
-
data: 1,
|
|
89
|
-
};
|
|
90
|
-
```
|
|
34
|
+
## Core API
|
|
91
35
|
|
|
92
36
|
### `type Failable<T, E>`
|
|
93
37
|
|
|
94
38
|
Alias for `Success<T> | Failure<E>`.
|
|
95
39
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
```ts
|
|
99
|
-
import type { Failable } from '@pvorona/failable';
|
|
100
|
-
import { Failable as FailableNS } from '@pvorona/failable';
|
|
101
|
-
|
|
102
|
-
export function parseIntSafe(input: string): Failable<number, Error> {
|
|
103
|
-
const n = Number(input);
|
|
104
|
-
if (!Number.isInteger(n)) return FailableNS.ofError(new Error('Not an int'));
|
|
105
|
-
|
|
106
|
-
return FailableNS.ofSuccess(n);
|
|
107
|
-
}
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
### `type Success<T>`
|
|
40
|
+
### `success(data)` and `failure(error)`
|
|
111
41
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
Key fields/methods:
|
|
115
|
-
|
|
116
|
-
- `status: 'success'`, `isSuccess: true`, `isError: false`
|
|
117
|
-
- `data: T`, `error: null`
|
|
118
|
-
- `or(value)` returns itself
|
|
119
|
-
- `getOr(_)` returns `data`
|
|
120
|
-
- `getOrThrow()` returns `data`
|
|
121
|
-
|
|
122
|
-
Example:
|
|
42
|
+
Use these when you already know whether you are returning success or failure:
|
|
123
43
|
|
|
124
44
|
```ts
|
|
125
|
-
import {
|
|
45
|
+
import { failure, success } from '@pvorona/failable';
|
|
126
46
|
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
s.or('x'); // Success<number>
|
|
47
|
+
const ok = success({ id: '1' });
|
|
48
|
+
const err = failure({ code: 'bad_request' });
|
|
130
49
|
```
|
|
131
50
|
|
|
132
|
-
### `
|
|
51
|
+
### `isSuccess(...)` and `isFailure(...)`
|
|
133
52
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
Key fields/methods:
|
|
137
|
-
|
|
138
|
-
- `status: 'failure'`, `isSuccess: false`, `isError: true`
|
|
139
|
-
- `error: E`, `data: null`
|
|
140
|
-
- `or(value)` converts to `Success<typeof value>`
|
|
141
|
-
- `getOr(fallback)` returns `fallback`
|
|
142
|
-
- `getOrThrow()` throws `error`
|
|
143
|
-
|
|
144
|
-
Example:
|
|
53
|
+
Use the guards or the instance booleans (`result.isSuccess` / `result.isError`) to branch:
|
|
145
54
|
|
|
146
55
|
```ts
|
|
147
|
-
import {
|
|
148
|
-
|
|
149
|
-
const f = Failable.ofError(new Error('boom'));
|
|
150
|
-
f.getOr('default'); // 'default'
|
|
151
|
-
f.or(42).data; // 42
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
### `type FailableLike<T, E>`
|
|
155
|
-
|
|
156
|
-
Structured-clone-friendly representation of a result:
|
|
56
|
+
import { failure, isSuccess, success } from '@pvorona/failable';
|
|
157
57
|
|
|
158
|
-
|
|
159
|
-
- `{ status: 'failure', error }`
|
|
58
|
+
const result = Math.random() > 0.5 ? success(123) : failure('boom');
|
|
160
59
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
type Wire = FailableLike<{ id: string }, { code: string }>;
|
|
60
|
+
if (isSuccess(result)) {
|
|
61
|
+
console.log(result.data);
|
|
62
|
+
} else {
|
|
63
|
+
console.error(result.error);
|
|
64
|
+
}
|
|
167
65
|
```
|
|
168
66
|
|
|
169
|
-
### `
|
|
170
|
-
|
|
171
|
-
The success-shaped `FailableLike`.
|
|
172
|
-
|
|
173
|
-
Example:
|
|
174
|
-
|
|
175
|
-
```ts
|
|
176
|
-
import { FailableStatus, type FailableLikeSuccess } from '@pvorona/failable';
|
|
177
|
-
|
|
178
|
-
const wireOk: FailableLikeSuccess<number> = {
|
|
179
|
-
status: FailableStatus.Success,
|
|
180
|
-
data: 1,
|
|
181
|
-
};
|
|
182
|
-
```
|
|
67
|
+
### `createFailable(...)`
|
|
183
68
|
|
|
184
|
-
|
|
69
|
+
`createFailable(...)` is a convenience wrapper when you want to capture thrown or rejected values:
|
|
185
70
|
|
|
186
|
-
|
|
71
|
+
- `createFailable(failable)` returns the same instance
|
|
72
|
+
- `createFailable(failableLike)` rehydrates into a real `Success` / `Failure`
|
|
73
|
+
- `createFailable(() => value)` captures sync throws into `Failure`
|
|
74
|
+
- `createFailable(promise)` captures promise rejections into `Failure`
|
|
187
75
|
|
|
188
76
|
Example:
|
|
189
77
|
|
|
190
78
|
```ts
|
|
191
|
-
import {
|
|
192
|
-
|
|
193
|
-
const wireErr: FailableLikeFailure<string> = {
|
|
194
|
-
status: FailableStatus.Failure,
|
|
195
|
-
error: 'bad_request',
|
|
196
|
-
};
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
### `FailableTag`, `SuccessTag`, `FailureTag` (Symbols)
|
|
79
|
+
import { createFailable, isFailure } from '@pvorona/failable';
|
|
200
80
|
|
|
201
|
-
|
|
81
|
+
const responseResult = await createFailable(fetch('https://example.com/items'));
|
|
202
82
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
(
|
|
215
|
-
|
|
83
|
+
if (isFailure(responseResult)) {
|
|
84
|
+
console.error('Network failure:', responseResult.error);
|
|
85
|
+
} else if (!responseResult.data.ok) {
|
|
86
|
+
console.error(`Unexpected status: ${responseResult.data.status}`);
|
|
87
|
+
} else {
|
|
88
|
+
const text = await responseResult.data.text();
|
|
89
|
+
const parseResult = createFailable(() => JSON.parse(text));
|
|
90
|
+
|
|
91
|
+
if (isFailure(parseResult)) {
|
|
92
|
+
console.error('Invalid JSON:', parseResult.error);
|
|
93
|
+
} else {
|
|
94
|
+
console.log(parseResult.data);
|
|
95
|
+
}
|
|
216
96
|
}
|
|
217
97
|
```
|
|
218
98
|
|
|
219
|
-
|
|
99
|
+
## Important semantics
|
|
220
100
|
|
|
221
|
-
|
|
101
|
+
- `createFailable(async () => value)` is a footgun. The async function itself is treated as a sync return value, so the result is `Success<Promise<T>>`. If you want rejection capture, pass the promise directly: `await createFailable(somePromise)`.
|
|
102
|
+
- `or(...)` and `getOr(...)` are eager. The fallback expression runs before the method call.
|
|
103
|
+
- `isFailableLike(...)` is intentionally strict. It only accepts exactly `{ status, data }` or `{ status, error }` with no extra enumerable keys.
|
|
104
|
+
- By default, `createFailable(...)` preserves raw thrown and rejected values. If something throws `'boom'`, `{ code: 'bad_request' }`, or `[error1, error2]`, that exact value becomes `.error`.
|
|
105
|
+
- `createFailable(input, NormalizedErrors)` converts non-`Error` failures into `Error` values:
|
|
106
|
+
- existing `Error` values pass through unchanged
|
|
107
|
+
- arrays become `AggregateError`
|
|
108
|
+
- other values become `Error`
|
|
109
|
+
- the original raw value is preserved in `error.cause`
|
|
110
|
+
- `createFailable(input, { normalizeError })` lets you supply your own normalization strategy.
|
|
111
|
+
- The library still uses private runtime tags internally for hydrated instances, but those details are not part of the public API.
|
|
112
|
+
- This package is ESM-only. Use `import` syntax; there is no `require` export condition.
|
|
222
113
|
|
|
223
|
-
|
|
114
|
+
## Normalizing errors
|
|
224
115
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
```ts
|
|
228
|
-
import { Failable } from '@pvorona/failable';
|
|
229
|
-
|
|
230
|
-
const ok = Failable.ofSuccess({ id: '1' });
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
#### `Failable.ofError<E>(error: E): Failure<E>`
|
|
234
|
-
|
|
235
|
-
Example:
|
|
116
|
+
If you want `Error`-shaped handling at the boundary, opt in explicitly:
|
|
236
117
|
|
|
237
118
|
```ts
|
|
238
|
-
import {
|
|
119
|
+
import {
|
|
120
|
+
createFailable,
|
|
121
|
+
isFailure,
|
|
122
|
+
NormalizedErrors,
|
|
123
|
+
} from '@pvorona/failable';
|
|
239
124
|
|
|
240
|
-
const
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
Example:
|
|
125
|
+
const result = createFailable(
|
|
126
|
+
() => {
|
|
127
|
+
throw { code: 'bad_request' };
|
|
128
|
+
},
|
|
129
|
+
NormalizedErrors
|
|
130
|
+
);
|
|
248
131
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
const maybe: unknown = Failable.ofSuccess(1);
|
|
253
|
-
if (Failable.isFailable(maybe)) {
|
|
254
|
-
// narrowed
|
|
132
|
+
if (isFailure(result)) {
|
|
133
|
+
console.error(result.error.message);
|
|
134
|
+
console.error(result.error.cause); // { code: 'bad_request' }
|
|
255
135
|
}
|
|
256
136
|
```
|
|
257
137
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
Example:
|
|
138
|
+
For custom normalization:
|
|
261
139
|
|
|
262
140
|
```ts
|
|
263
|
-
import {
|
|
141
|
+
import { createFailable } from '@pvorona/failable';
|
|
264
142
|
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
143
|
+
const result = createFailable(doThing, {
|
|
144
|
+
normalizeError(error) {
|
|
145
|
+
return error instanceof Error
|
|
146
|
+
? error
|
|
147
|
+
: new Error('Operation failed', { cause: error });
|
|
148
|
+
},
|
|
149
|
+
});
|
|
269
150
|
```
|
|
270
151
|
|
|
271
|
-
|
|
152
|
+
## Structured-clone transport
|
|
272
153
|
|
|
273
|
-
|
|
154
|
+
Hydrated `Failable` instances have methods and private runtime details that do not survive structured cloning (`postMessage`, `MessagePort`, extension messaging, etc.). Convert them to plain objects first:
|
|
274
155
|
|
|
275
156
|
```ts
|
|
276
|
-
import {
|
|
277
|
-
|
|
278
|
-
const maybe: unknown = Failable.ofError('nope');
|
|
279
|
-
if (Failable.isFailure(maybe)) {
|
|
280
|
-
console.log(maybe.error);
|
|
281
|
-
}
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
#### `Failable.toFailableLike(result): FailableLike<...>`
|
|
157
|
+
import { createFailable, toFailableLike } from '@pvorona/failable';
|
|
285
158
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
Example:
|
|
159
|
+
const result = createFailable(() => JSON.parse('{"ok":true}'));
|
|
289
160
|
|
|
290
|
-
|
|
291
|
-
|
|
161
|
+
// sender
|
|
162
|
+
const wire = toFailableLike(result);
|
|
163
|
+
postMessage(wire);
|
|
292
164
|
|
|
293
|
-
|
|
294
|
-
const
|
|
165
|
+
// receiver
|
|
166
|
+
const hydrated = createFailable(wire);
|
|
295
167
|
```
|
|
296
168
|
|
|
297
|
-
|
|
169
|
+
The transport shape is:
|
|
298
170
|
|
|
299
|
-
|
|
171
|
+
- `FailableLikeSuccess<T>`: `{ status: FailableStatus.Success, data: T }`
|
|
172
|
+
- `FailableLikeFailure<E>`: `{ status: FailableStatus.Failure, error: E }`
|
|
300
173
|
|
|
301
|
-
|
|
174
|
+
`FailableStatus` is a runtime object:
|
|
302
175
|
|
|
303
176
|
```ts
|
|
304
|
-
import {
|
|
177
|
+
import { FailableStatus, type FailableLike } from '@pvorona/failable';
|
|
305
178
|
|
|
306
|
-
const wire:
|
|
307
|
-
|
|
179
|
+
const wire: FailableLike<number, string> = {
|
|
180
|
+
status: FailableStatus.Success,
|
|
181
|
+
data: 1,
|
|
182
|
+
};
|
|
308
183
|
```
|
|
309
184
|
|
|
310
|
-
|
|
185
|
+
## API at a glance
|
|
311
186
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
- `
|
|
315
|
-
- `
|
|
316
|
-
- `
|
|
317
|
-
- `
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
import { Failable } from '@pvorona/failable';
|
|
323
|
-
|
|
324
|
-
// function wrapper (captures throws)
|
|
325
|
-
const res1 = Failable.from(() => JSON.parse('{'));
|
|
326
|
-
|
|
327
|
-
// promise wrapper (captures rejections)
|
|
328
|
-
const res2 = await Failable.from(fetch('https://example.com'));
|
|
329
|
-
|
|
330
|
-
// rehydrate from structured clone
|
|
331
|
-
const wire = Failable.toFailableLike(Failable.ofError('bad'));
|
|
332
|
-
const hydrated = Failable.from(wire);
|
|
333
|
-
```
|
|
187
|
+
- `type Failable<T, E>`: `Success<T> | Failure<E>`
|
|
188
|
+
- `type Success<T>`: success variant with `data`, `or(...)`, `getOr(...)`, and `getOrThrow()`
|
|
189
|
+
- `type Failure<E>`: failure variant with `error`, `or(...)`, `getOr(...)`, and `getOrThrow()`
|
|
190
|
+
- `const FailableStatus`: runtime `{ Success, Failure }` object
|
|
191
|
+
- `const NormalizedErrors`: built-in token for `Error` normalization
|
|
192
|
+
- `success(data)` / `failure(error)`: explicit constructors
|
|
193
|
+
- `isFailable(...)`, `isSuccess(...)`, `isFailure(...)`: runtime guards for hydrated values
|
|
194
|
+
- `toFailableLike(...)`: convert a hydrated result into a structured-clone-friendly value
|
|
195
|
+
- `isFailableLike(...)`: validate the strict structured-clone shape
|
|
196
|
+
- `createFailable(...)`: wrap, rehydrate, or normalize results
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,80 +1,119 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { notImplemented as
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { isFunction as s, isObject as i } from "@pvorona/assert";
|
|
2
|
+
import { notImplemented as f } from "@pvorona/not-implemented";
|
|
3
|
+
const E = /* @__PURE__ */ Symbol("Failable"), g = /* @__PURE__ */ Symbol("Success"), h = /* @__PURE__ */ Symbol("Failure"), n = Object.freeze({
|
|
4
|
+
Success: "success",
|
|
5
|
+
Failure: "failure"
|
|
6
|
+
}), d = Object.freeze({
|
|
7
|
+
mode: "normalized-errors"
|
|
8
|
+
});
|
|
9
|
+
function j(r) {
|
|
10
|
+
return i(r) && Object.keys(r).length === 2 && Object.getOwnPropertyDescriptor(r, "status")?.value === n.Success && Object.prototype.hasOwnProperty.call(r, "data");
|
|
7
11
|
}
|
|
8
|
-
function
|
|
9
|
-
return
|
|
12
|
+
function m(r) {
|
|
13
|
+
return i(r) && Object.keys(r).length === 2 && Object.getOwnPropertyDescriptor(r, "status")?.value === n.Failure && Object.prototype.hasOwnProperty.call(r, "error");
|
|
14
|
+
}
|
|
15
|
+
function a(r) {
|
|
16
|
+
return m(r) || j(r);
|
|
10
17
|
}
|
|
11
|
-
const
|
|
12
|
-
[
|
|
18
|
+
const b = {
|
|
19
|
+
[E]: !0,
|
|
13
20
|
isSuccess: !1,
|
|
14
21
|
isError: !1,
|
|
15
22
|
data: null,
|
|
16
23
|
error: null,
|
|
17
|
-
or:
|
|
18
|
-
getOr:
|
|
19
|
-
getOrThrow:
|
|
20
|
-
},
|
|
21
|
-
const r = Object.create(
|
|
22
|
-
return r[
|
|
24
|
+
or: f,
|
|
25
|
+
getOr: f,
|
|
26
|
+
getOrThrow: f
|
|
27
|
+
}, w = (() => {
|
|
28
|
+
const r = Object.create(b);
|
|
29
|
+
return r[g] = !0, r.status = n.Success, r.isSuccess = !0, r.or = function() {
|
|
23
30
|
return this;
|
|
24
31
|
}, r.getOr = function() {
|
|
25
32
|
return this.data;
|
|
26
33
|
}, r.getOrThrow = function() {
|
|
27
34
|
return this.data;
|
|
28
35
|
}, Object.freeze(r);
|
|
29
|
-
})(),
|
|
30
|
-
const r = Object.create(
|
|
31
|
-
return r[
|
|
32
|
-
return t
|
|
33
|
-
}, r.getOr = function(
|
|
34
|
-
return
|
|
36
|
+
})(), y = (() => {
|
|
37
|
+
const r = Object.create(b);
|
|
38
|
+
return r[h] = !0, r.status = n.Failure, r.isError = !0, r.or = function(t) {
|
|
39
|
+
return c(t);
|
|
40
|
+
}, r.getOr = function(t) {
|
|
41
|
+
return t;
|
|
35
42
|
}, r.getOrThrow = function() {
|
|
36
43
|
throw this.error;
|
|
37
44
|
}, Object.freeze(r);
|
|
38
|
-
})()
|
|
39
|
-
|
|
40
|
-
isSuccess
|
|
41
|
-
isFailure: (r) => s(r) && r[a] === !0,
|
|
42
|
-
ofSuccess: (r) => {
|
|
43
|
-
const e = Object.create(S);
|
|
44
|
-
return e.data = r, Object.freeze(e);
|
|
45
|
-
},
|
|
46
|
-
ofError: (r) => {
|
|
47
|
-
const e = Object.create(g);
|
|
48
|
-
return e.error = r, Object.freeze(e);
|
|
49
|
-
},
|
|
50
|
-
toFailableLike: h,
|
|
51
|
-
isFailableLike: (r) => F(r) || O(r),
|
|
52
|
-
from: j
|
|
53
|
-
};
|
|
54
|
-
function h(r) {
|
|
55
|
-
return r.status === "failure" ? { status: "failure", error: r.error } : { status: "success", data: r.data };
|
|
45
|
+
})();
|
|
46
|
+
function F(r) {
|
|
47
|
+
return !(!i(r) || r.status !== n.Success || r.isSuccess !== !0 || r.isError !== !1 || !("data" in r) || r.error !== null || !s(r.or) || !s(r.getOr) || !s(r.getOrThrow));
|
|
56
48
|
}
|
|
57
|
-
function
|
|
58
|
-
return
|
|
49
|
+
function O(r) {
|
|
50
|
+
return !(!i(r) || r.status !== n.Failure || r.isSuccess !== !1 || r.isError !== !0 || !("error" in r) || r.data !== null || !s(r.or) || !s(r.getOr) || !s(r.getOrThrow));
|
|
59
51
|
}
|
|
60
|
-
function
|
|
61
|
-
return
|
|
52
|
+
function l(r) {
|
|
53
|
+
return O(r) || F(r);
|
|
62
54
|
}
|
|
63
|
-
function
|
|
55
|
+
function B(r) {
|
|
56
|
+
return F(r);
|
|
57
|
+
}
|
|
58
|
+
function C(r) {
|
|
59
|
+
return O(r);
|
|
60
|
+
}
|
|
61
|
+
function c(r) {
|
|
62
|
+
const e = Object.create(w);
|
|
63
|
+
return e.data = r, Object.freeze(e);
|
|
64
|
+
}
|
|
65
|
+
function o(r) {
|
|
66
|
+
const e = Object.create(y);
|
|
67
|
+
return e.error = r, Object.freeze(e);
|
|
68
|
+
}
|
|
69
|
+
function I(r) {
|
|
70
|
+
return r.status === n.Failure ? { status: n.Failure, error: r.error } : { status: n.Success, data: r.data };
|
|
71
|
+
}
|
|
72
|
+
function U(r, e) {
|
|
73
|
+
return l(r) ? u(r, e) : a(r) ? u(S(r), e) : s(r) ? A(r, e) : p(r, e);
|
|
74
|
+
}
|
|
75
|
+
function S(r) {
|
|
76
|
+
return r.status === n.Success ? c(r.data) : o(r.error);
|
|
77
|
+
}
|
|
78
|
+
function A(r, e) {
|
|
64
79
|
try {
|
|
65
|
-
const
|
|
66
|
-
return t
|
|
67
|
-
} catch (
|
|
68
|
-
return t
|
|
80
|
+
const t = r();
|
|
81
|
+
return l(t) ? u(t, e) : a(t) ? u(S(t), e) : c(t);
|
|
82
|
+
} catch (t) {
|
|
83
|
+
return u(o(t), e);
|
|
69
84
|
}
|
|
70
85
|
}
|
|
71
|
-
function p(r) {
|
|
72
|
-
return
|
|
86
|
+
function p(r, e) {
|
|
87
|
+
return Promise.resolve(r).then(
|
|
88
|
+
(t) => l(t) ? u(t, e) : a(t) ? u(S(t), e) : c(t),
|
|
89
|
+
(t) => u(o(t), e)
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
function u(r, e) {
|
|
93
|
+
const t = P(e);
|
|
94
|
+
return t === null || r.status === n.Success || r.error instanceof Error ? r : o(t(r.error));
|
|
95
|
+
}
|
|
96
|
+
function P(r) {
|
|
97
|
+
return r === void 0 ? null : T(r) ? k : L(r) ? r.normalizeError : null;
|
|
98
|
+
}
|
|
99
|
+
function T(r) {
|
|
100
|
+
return !i(r) || Object.keys(r).length !== 1 ? !1 : Object.getOwnPropertyDescriptor(r, "mode")?.value === d.mode;
|
|
101
|
+
}
|
|
102
|
+
function L(r) {
|
|
103
|
+
return i(r) ? s(r.normalizeError) : !1;
|
|
104
|
+
}
|
|
105
|
+
function k(r) {
|
|
106
|
+
return r instanceof Error ? r : Array.isArray(r) ? new AggregateError(r, "Multiple errors", { cause: r }) : new Error(String(r), { cause: r });
|
|
73
107
|
}
|
|
74
108
|
export {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
109
|
+
n as FailableStatus,
|
|
110
|
+
d as NormalizedErrors,
|
|
111
|
+
U as createFailable,
|
|
112
|
+
o as failure,
|
|
113
|
+
l as isFailable,
|
|
114
|
+
a as isFailableLike,
|
|
115
|
+
C as isFailure,
|
|
116
|
+
B as isSuccess,
|
|
117
|
+
c as success,
|
|
118
|
+
I as toFailableLike
|
|
80
119
|
};
|
package/dist/lib/failable.d.ts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export declare const FailableStatus: Readonly<{
|
|
2
|
+
readonly Success: "success";
|
|
3
|
+
readonly Failure: "failure";
|
|
4
|
+
}>;
|
|
5
|
+
export type FailableStatus = (typeof FailableStatus)[keyof typeof FailableStatus];
|
|
6
|
+
export declare const NormalizedErrors: Readonly<{
|
|
7
|
+
readonly mode: "normalized-errors";
|
|
8
|
+
}>;
|
|
9
|
+
export type CreateFailableNormalizeErrorOptions = {
|
|
10
|
+
readonly normalizeError: (error: unknown) => Error;
|
|
11
|
+
};
|
|
12
|
+
type CreateFailableNormalizeErrorInput = typeof NormalizedErrors | CreateFailableNormalizeErrorOptions;
|
|
6
13
|
export type Failable<T, E> = Success<T> | Failure<E>;
|
|
7
14
|
/**
|
|
8
15
|
* Structured-clone-friendly representation of {@link Failable}.
|
|
@@ -14,24 +21,23 @@ export type Failable<T, E> = Success<T> | Failure<E>;
|
|
|
14
21
|
* A {@link Failable} instance relies on Symbols and prototype methods, which do not survive structured cloning.
|
|
15
22
|
*
|
|
16
23
|
* Boundary rule:
|
|
17
|
-
* - **sender**: `
|
|
18
|
-
* - **receiver**: `
|
|
24
|
+
* - **sender**: `toFailableLike(result)`
|
|
25
|
+
* - **receiver**: `createFailable(message.result)` (rehydrates into a real {@link Failable})
|
|
19
26
|
*
|
|
20
27
|
* Note: `data` / `error` must themselves be structured-cloneable.
|
|
21
28
|
*/
|
|
22
29
|
export type FailableLike<T, E> = FailableLikeSuccess<T> | FailableLikeFailure<E>;
|
|
23
30
|
export type FailableLikeSuccess<T> = {
|
|
24
|
-
readonly status: FailableStatus.Success;
|
|
31
|
+
readonly status: typeof FailableStatus.Success;
|
|
25
32
|
readonly data: T;
|
|
26
33
|
};
|
|
27
34
|
export type FailableLikeFailure<E> = {
|
|
28
|
-
readonly status: FailableStatus.Failure;
|
|
35
|
+
readonly status: typeof FailableStatus.Failure;
|
|
29
36
|
readonly error: E;
|
|
30
37
|
};
|
|
38
|
+
export declare function isFailableLike(value: unknown): value is FailableLike<unknown, unknown>;
|
|
31
39
|
export type Success<T> = {
|
|
32
|
-
readonly
|
|
33
|
-
readonly [SuccessTag]: true;
|
|
34
|
-
readonly status: FailableStatus.Success;
|
|
40
|
+
readonly status: typeof FailableStatus.Success;
|
|
35
41
|
readonly isSuccess: true;
|
|
36
42
|
readonly isError: false;
|
|
37
43
|
readonly data: T;
|
|
@@ -41,9 +47,7 @@ export type Success<T> = {
|
|
|
41
47
|
readonly getOrThrow: () => T;
|
|
42
48
|
};
|
|
43
49
|
export type Failure<E> = {
|
|
44
|
-
readonly
|
|
45
|
-
readonly [FailureTag]: true;
|
|
46
|
-
readonly status: FailableStatus.Failure;
|
|
50
|
+
readonly status: typeof FailableStatus.Failure;
|
|
47
51
|
readonly isSuccess: false;
|
|
48
52
|
readonly isError: true;
|
|
49
53
|
readonly error: E;
|
|
@@ -52,74 +56,32 @@ export type Failure<E> = {
|
|
|
52
56
|
readonly getOr: <U>(value: U) => U;
|
|
53
57
|
readonly getOrThrow: () => never;
|
|
54
58
|
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
* - `from(promise)` captures rejection values into `Failure` and preserves/rehydrates resolved
|
|
83
|
-
* `Failable` / `FailableLike`.
|
|
84
|
-
*
|
|
85
|
-
* Gotchas:
|
|
86
|
-
* - `Failable.isFailableLike` is intentionally strict: only `{ status, data }` or `{ status, error }`
|
|
87
|
-
* with no extra enumerable keys. If you need metadata, wrap it: `{ result: failableLike, meta }`.
|
|
88
|
-
* - `or(...)` and `getOr(...)` are eager (fallback is evaluated before the call). Use branching for
|
|
89
|
-
* lazy fallbacks.
|
|
90
|
-
* - No error normalization is performed: whatever you throw/reject becomes `.error`.
|
|
91
|
-
* - `from(() => somePromise)` does NOT await; pass the promise directly: `from(somePromise)`.
|
|
92
|
-
*
|
|
93
|
-
* @example
|
|
94
|
-
* const res = Failable.from(() => JSON.parse(text));
|
|
95
|
-
* if (res.isSuccess) return res.data;
|
|
96
|
-
* console.error(res.error);
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* // Structured-clone transport
|
|
100
|
-
* const wire = Failable.toFailableLike(res);
|
|
101
|
-
* // ... send wire ...
|
|
102
|
-
* const hydrated = Failable.from(wire);
|
|
103
|
-
*/
|
|
104
|
-
export declare const Failable: {
|
|
105
|
-
readonly isFailable: (value: unknown) => value is Failable<unknown, unknown>;
|
|
106
|
-
readonly isSuccess: (value: unknown) => value is Success<unknown>;
|
|
107
|
-
readonly isFailure: (value: unknown) => value is Failure<unknown>;
|
|
108
|
-
readonly ofSuccess: <T = void>(data: T) => Success<T>;
|
|
109
|
-
readonly ofError: <E = void>(error: E) => Failure<E>;
|
|
110
|
-
readonly toFailableLike: typeof toFailableLike;
|
|
111
|
-
readonly isFailableLike: (value: unknown) => value is FailableLike<unknown, unknown>;
|
|
112
|
-
readonly from: typeof from;
|
|
113
|
-
};
|
|
114
|
-
declare function toFailableLike<T>(value: Success<T>): FailableLikeSuccess<T>;
|
|
115
|
-
declare function toFailableLike<E>(value: Failure<E>): FailableLikeFailure<E>;
|
|
116
|
-
declare function toFailableLike<T, E>(value: Failable<T, E>): FailableLike<T, E>;
|
|
117
|
-
type InferReturnTypeFromFunction<F extends () => R, E = Error, R = ReturnType<F>> = [R] extends [never] ? Failure<E> : R extends Success<infer A> ? Success<A> : R extends Failure<infer A> ? Failure<A> : R extends FailableLikeSuccess<infer A> ? Success<A> : R extends FailableLikeFailure<infer A> ? Failure<A> : R extends Failable<infer A, infer B> ? Failable<A, B> : Failable<R, E>;
|
|
118
|
-
type InferReturnTypeFromPromise<T, E = Error, P extends PromiseLike<T> = PromiseLike<T>> = [Awaited<P>] extends [never] ? Promise<Failure<E>> : Awaited<P> extends Promise<Success<infer A>> ? Promise<Success<A>> : Awaited<P> extends Promise<Failure<infer A>> ? Promise<Failure<A>> : Awaited<P> extends Failable<unknown, unknown> ? Promise<Awaited<P>> : Awaited<P> extends FailableLikeSuccess<infer A> ? Promise<Success<A>> : Awaited<P> extends FailableLikeFailure<infer A> ? Promise<Failure<A>> : Awaited<P> extends FailableLike<infer A, infer B> ? Promise<Failable<A, B>> : Promise<Failable<Awaited<P>, E>>;
|
|
119
|
-
declare function from<T>(value: FailableLikeSuccess<T>): Success<T>;
|
|
120
|
-
declare function from<E>(value: FailableLikeFailure<E>): Failure<E>;
|
|
121
|
-
declare function from<T, E>(value: FailableLike<T, E>): Failable<T, E>;
|
|
122
|
-
declare function from<F extends () => R, E = Error, R = ReturnType<F>>(fun: F): InferReturnTypeFromFunction<F, E, R>;
|
|
123
|
-
declare function from<T, E = Error, P extends PromiseLike<T> = PromiseLike<T>>(promise: P): InferReturnTypeFromPromise<T, E, P>;
|
|
59
|
+
export declare function isFailable(value: unknown): value is Failable<unknown, unknown>;
|
|
60
|
+
export declare function isSuccess(value: unknown): value is Success<unknown>;
|
|
61
|
+
export declare function isFailure(value: unknown): value is Failure<unknown>;
|
|
62
|
+
export declare function success<T = void>(data: T): Success<T>;
|
|
63
|
+
export declare function failure<E = void>(error: E): Failure<E>;
|
|
64
|
+
export declare function toFailableLike<T>(value: Success<T>): FailableLikeSuccess<T>;
|
|
65
|
+
export declare function toFailableLike<E>(value: Failure<E>): FailableLikeFailure<E>;
|
|
66
|
+
export declare function toFailableLike<T, E>(value: Failable<T, E>): FailableLike<T, E>;
|
|
67
|
+
type InferReturnTypeFromFunction<F extends () => R, E = unknown, R = ReturnType<F>> = [R] extends [never] ? Failure<E> : R extends Success<infer A> ? Success<A> : R extends Failure<infer A> ? Failure<A> : R extends FailableLikeSuccess<infer A> ? Success<A> : R extends FailableLikeFailure<infer A> ? Failure<A> : R extends Failable<infer A, infer B> ? Failable<A, B> : R extends FailableLike<infer A, infer B> ? Failable<A, B> : Failable<R, E>;
|
|
68
|
+
type InferReturnTypeFromPromise<T, E = unknown, P extends PromiseLike<T> = PromiseLike<T>> = [Awaited<P>] extends [never] ? Promise<Failure<E>> : Awaited<P> extends Success<infer A> ? Promise<Success<A>> : Awaited<P> extends Failure<infer A> ? Promise<Failure<A>> : Awaited<P> extends Failable<unknown, unknown> ? Promise<Awaited<P>> : Awaited<P> extends FailableLikeSuccess<infer A> ? Promise<Success<A>> : Awaited<P> extends FailableLikeFailure<infer A> ? Promise<Failure<A>> : Awaited<P> extends FailableLike<infer A, infer B> ? Promise<Failable<A, B>> : Promise<Failable<Awaited<P>, E>>;
|
|
69
|
+
type NormalizeCreateFailableResult<T> = [T] extends [never] ? Failure<Error> : T extends Success<infer A> ? Success<A> : T extends Failure<unknown> ? Failure<Error> : T extends FailableLikeSuccess<infer A> ? Success<A> : T extends FailableLikeFailure<unknown> ? Failure<Error> : T extends Failable<infer A, unknown> ? Failable<A, Error> : T extends FailableLike<infer A, unknown> ? Failable<A, Error> : Failable<T, Error>;
|
|
70
|
+
export declare function createFailable<T>(value: Success<T>): Success<T>;
|
|
71
|
+
export declare function createFailable<E>(value: Failure<E>): Failure<E>;
|
|
72
|
+
export declare function createFailable<T, E>(value: Failable<T, E>): Failable<T, E>;
|
|
73
|
+
export declare function createFailable<T>(value: FailableLikeSuccess<T>): Success<T>;
|
|
74
|
+
export declare function createFailable<E>(value: FailableLikeFailure<E>): Failure<E>;
|
|
75
|
+
export declare function createFailable<T, E>(value: FailableLike<T, E>): Failable<T, E>;
|
|
76
|
+
export declare function createFailable<T>(value: Success<T>, normalizeOption: CreateFailableNormalizeErrorInput): Success<T>;
|
|
77
|
+
export declare function createFailable<E>(value: Failure<E>, normalizeOption: CreateFailableNormalizeErrorInput): Failure<Error>;
|
|
78
|
+
export declare function createFailable<T, E>(value: Failable<T, E>, normalizeOption: CreateFailableNormalizeErrorInput): Failable<T, Error>;
|
|
79
|
+
export declare function createFailable<T>(value: FailableLikeSuccess<T>, normalizeOption: CreateFailableNormalizeErrorInput): Success<T>;
|
|
80
|
+
export declare function createFailable<E>(value: FailableLikeFailure<E>, normalizeOption: CreateFailableNormalizeErrorInput): Failure<Error>;
|
|
81
|
+
export declare function createFailable<T, E>(value: FailableLike<T, E>, normalizeOption: CreateFailableNormalizeErrorInput): Failable<T, Error>;
|
|
82
|
+
export declare function createFailable<F extends () => R, E = unknown, R = ReturnType<F>>(fun: F): InferReturnTypeFromFunction<F, E, R>;
|
|
83
|
+
export declare function createFailable<F extends () => R, R = ReturnType<F>>(fun: F, normalizeOption: CreateFailableNormalizeErrorInput): NormalizeCreateFailableResult<R>;
|
|
84
|
+
export declare function createFailable<T, E = unknown, P extends PromiseLike<T> = PromiseLike<T>>(promise: P): InferReturnTypeFromPromise<T, E, P>;
|
|
85
|
+
export declare function createFailable<T, P extends PromiseLike<T> = PromiseLike<T>>(promise: P, normalizeOption: CreateFailableNormalizeErrorInput): Promise<NormalizeCreateFailableResult<Awaited<P>>>;
|
|
124
86
|
export {};
|
|
125
87
|
//# sourceMappingURL=failable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"failable.d.ts","sourceRoot":"","sources":["../../src/lib/failable.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"failable.d.ts","sourceRoot":"","sources":["../../src/lib/failable.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,cAAc;;;EAGhB,CAAC;AAEZ,MAAM,MAAM,cAAc,GACxB,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,OAAO,cAAc,CAAC,CAAC;AAEvD,eAAO,MAAM,gBAAgB;;EAElB,CAAC;AAEZ,MAAM,MAAM,mCAAmC,GAAG;IAChD,QAAQ,CAAC,cAAc,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,CAAC;CACpD,CAAC;AAEF,KAAK,iCAAiC,GAClC,OAAO,gBAAgB,GACvB,mCAAmC,CAAC;AAExC,MAAM,MAAM,QAAQ,CAAC,CAAC,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAErD;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,CAAC,IACzB,mBAAmB,CAAC,CAAC,CAAC,GACtB,mBAAmB,CAAC,CAAC,CAAC,CAAC;AAE3B,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI;IACnC,QAAQ,CAAC,MAAM,EAAE,OAAO,cAAc,CAAC,OAAO,CAAC;IAC/C,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,mBAAmB,CAAC,CA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ClB,wBAAgB,cAAc,CAAC,CAAC,EAAE,CAAC,EACjC,KAAK,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,EACzB,eAAe,EAAE,iCAAiC,GACjD,QAAQ,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AACtB,wBAAgB,cAAc,CAC5B,CAAC,SAAS,MAAM,CAAC,EACjB,CAAC,GAAG,OAAO,EACX,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,EACjB,GAAG,EAAE,CAAC,GAAG,2BAA2B,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAChD,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,EACjE,GAAG,EAAE,CAAC,EACN,eAAe,EAAE,iCAAiC,GACjD,6BAA6B,CAAC,CAAC,CAAC,CAAC;AACpC,wBAAgB,cAAc,CAC5B,CAAC,EACD,CAAC,GAAG,OAAO,EACX,CAAC,SAAS,WAAW,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,EACzC,OAAO,EAAE,CAAC,GAAG,0BAA0B,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACnD,wBAAgB,cAAc,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,EACzE,OAAO,EAAE,CAAC,EACV,eAAe,EAAE,iCAAiC,GACjD,OAAO,CAAC,6BAA6B,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pvorona/failable",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Typed success/failure results for expected failures in TypeScript.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"failable",
|
|
7
|
+
"result",
|
|
8
|
+
"typescript",
|
|
9
|
+
"error-handling"
|
|
10
|
+
],
|
|
4
11
|
"license": "MIT",
|
|
5
12
|
"type": "module",
|
|
13
|
+
"sideEffects": false,
|
|
6
14
|
"main": "./dist/index.js",
|
|
7
15
|
"module": "./dist/index.js",
|
|
8
16
|
"types": "./dist/index.d.ts",
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=18"
|
|
19
|
+
},
|
|
9
20
|
"exports": {
|
|
10
21
|
"./package.json": "./package.json",
|
|
11
22
|
".": {
|
package/dist/lib/constants.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/lib/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,eAAqB,CAAC;AAC9C,eAAO,MAAM,UAAU,eAAoB,CAAC;AAC5C,eAAO,MAAM,UAAU,eAAoB,CAAC"}
|