@pvorona/failable 0.1.0 → 0.2.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 CHANGED
@@ -1,6 +1,8 @@
1
1
  # @pvorona/failable
2
2
 
3
- A typed result type for expected failures. `Failable<T, E>` is a discriminated union of `Success<T>` and `Failure<E>`, with ergonomic accessors and structured-clone support.
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,322 +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
- ## Usage
13
+ ## Quick start
12
14
 
13
15
  ```ts
14
- import { createFailable } from '@pvorona/failable';
16
+ import type { Failable } from '@pvorona/failable';
17
+ import { failure, isFailure, success } from '@pvorona/failable';
15
18
 
16
- const result = createFailable(() => JSON.parse(text));
19
+ function divide(a: number, b: number): Failable<number, string> {
20
+ if (b === 0) return failure('Cannot divide by zero');
17
21
 
18
- if (result.isSuccess) {
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 { failure, success } from '@pvorona/failable';
29
-
30
- const ok = success(42);
31
- const err = failure(new Error('boom'));
32
- ```
33
-
34
- ### Fallbacks
35
-
36
- ```ts
37
- import { failure } from '@pvorona/failable';
38
-
39
- const err = failure(new Error('boom'));
40
-
41
- const value = err.getOr('default'); // 'default'
42
- const recovered = err.or('fallback'); // Success<'fallback'>
43
- ```
44
-
45
- ### Wrapping async work
46
-
47
- ```ts
48
- import { createFailable } from '@pvorona/failable';
49
-
50
- const result = await createFailable(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 { createFailable, toFailableLike } from '@pvorona/failable';
59
-
60
- // sender
61
- const wire = toFailableLike(result);
62
- postMessage(wire);
63
-
64
- // receiver
65
- const hydrated = createFailable(wire);
66
- ```
67
-
68
- ## API
69
24
 
70
- ### `const enum FailableStatus`
25
+ const result = divide(10, 2);
71
26
 
72
- The discriminant for `FailableLike` and `Failable` instances.
73
-
74
- ```ts
75
- export const enum FailableStatus {
76
- Success = 'success',
77
- Failure = 'failure',
27
+ if (isFailure(result)) {
28
+ console.error(result.error);
29
+ } else {
30
+ console.log(result.data);
78
31
  }
79
32
  ```
80
33
 
81
- Example:
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
- Example:
97
-
98
- ```ts
99
- import type { Failable } from '@pvorona/failable';
100
- import { failure, success } from '@pvorona/failable';
101
-
102
- export function parseIntSafe(input: string): Failable<number, Error> {
103
- const n = Number(input);
104
- if (!Number.isInteger(n)) return failure(new Error('Not an int'));
105
-
106
- return success(n);
107
- }
108
- ```
109
-
110
- ### `type Success<T>`
40
+ ### `success(data)` and `failure(error)`
111
41
 
112
- The success variant.
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 { success } from '@pvorona/failable';
45
+ import { failure, success } from '@pvorona/failable';
126
46
 
127
- const s = success(123);
128
- s.getOr(0); // 123
129
- s.or('x'); // Success<number>
47
+ const ok = success({ id: '1' });
48
+ const err = failure({ code: 'bad_request' });
130
49
  ```
131
50
 
132
- ### `type Failure<E>`
133
-
134
- The failure variant.
51
+ ### `isSuccess(...)` and `isFailure(...)`
135
52
 
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 { failure } from '@pvorona/failable';
148
-
149
- const f = failure(new Error('boom'));
150
- f.getOr('default'); // 'default'
151
- f.or(42).data; // 42
152
- ```
153
-
154
- ### `type FailableLike<T, E>`
56
+ import { failure, isSuccess, success } from '@pvorona/failable';
155
57
 
156
- Structured-clone-friendly representation of a result:
58
+ const result = Math.random() > 0.5 ? success(123) : failure('boom');
157
59
 
158
- - `{ status: 'success', data }`
159
- - `{ status: 'failure', error }`
160
-
161
- Example:
162
-
163
- ```ts
164
- import type { FailableLike } from '@pvorona/failable';
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
- ### `type FailableLikeSuccess<T>`
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
- ### `type FailableLikeFailure<E>`
69
+ `createFailable(...)` is a convenience wrapper when you want to capture thrown or rejected values:
185
70
 
186
- The failure-shaped `FailableLike`.
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 { FailableStatus, type FailableLikeFailure } from '@pvorona/failable';
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
- Low-level Symbol tags used to mark hydrated `Failable` instances at runtime.
81
+ const responseResult = await createFailable(fetch('https://example.com/items'));
202
82
 
203
- Most code should prefer `result.isSuccess` / `result.isError` or the guards `isSuccess(...)` / `isFailure(...)`.
204
-
205
- Example (advanced):
206
-
207
- ```ts
208
- import { FailableTag } from '@pvorona/failable';
209
-
210
- export function isHydratedFailable(value: unknown): boolean {
211
- return (
212
- typeof value === 'object' &&
213
- value !== null &&
214
- (value as any)[FailableTag] === true
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
- ### `success<T>(data: T): Success<T>`
99
+ ## Important semantics
220
100
 
221
- Example:
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
- ```ts
224
- import { success } from '@pvorona/failable';
114
+ ## Normalizing errors
225
115
 
226
- const ok = success({ id: '1' });
227
- ```
228
-
229
- ### `failure<E>(error: E): Failure<E>`
230
-
231
- Example:
116
+ If you want `Error`-shaped handling at the boundary, opt in explicitly:
232
117
 
233
118
  ```ts
234
- import { failure } from '@pvorona/failable';
235
-
236
- const err = failure({ code: 'bad_request' });
237
- ```
119
+ import {
120
+ createFailable,
121
+ isFailure,
122
+ NormalizedErrors,
123
+ } from '@pvorona/failable';
238
124
 
239
- ### `isFailable(value): value is Failable<unknown, unknown>`
125
+ const result = createFailable(
126
+ () => {
127
+ throw { code: 'bad_request' };
128
+ },
129
+ NormalizedErrors
130
+ );
240
131
 
241
- Checks whether a value is a hydrated `Failable` instance (Symbol-tagged).
242
-
243
- Example:
244
-
245
- ```ts
246
- import { isFailable, success } from '@pvorona/failable';
247
-
248
- const maybe: unknown = success(1);
249
- if (isFailable(maybe)) {
250
- // narrowed
132
+ if (isFailure(result)) {
133
+ console.error(result.error.message);
134
+ console.error(result.error.cause); // { code: 'bad_request' }
251
135
  }
252
136
  ```
253
137
 
254
- ### `isSuccess(value): value is Success<unknown>`
255
-
256
- Example:
138
+ For custom normalization:
257
139
 
258
140
  ```ts
259
- import { isSuccess, success } from '@pvorona/failable';
141
+ import { createFailable } from '@pvorona/failable';
260
142
 
261
- const maybe: unknown = success(1);
262
- if (isSuccess(maybe)) {
263
- maybe.data; // ok
264
- }
143
+ const result = createFailable(doThing, {
144
+ normalizeError(error) {
145
+ return error instanceof Error
146
+ ? error
147
+ : new Error('Operation failed', { cause: error });
148
+ },
149
+ });
265
150
  ```
266
151
 
267
- ### `isFailure(value): value is Failure<unknown>`
152
+ ## Structured-clone transport
268
153
 
269
- Example:
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:
270
155
 
271
156
  ```ts
272
- import { failure, isFailure } from '@pvorona/failable';
273
-
274
- const maybe: unknown = failure('nope');
275
- if (isFailure(maybe)) {
276
- console.log(maybe.error);
277
- }
278
- ```
279
-
280
- ### `toFailableLike(result): FailableLike<...>`
281
-
282
- Converts a hydrated `Failable` into a structured-clone-friendly representation.
157
+ import { createFailable, toFailableLike } from '@pvorona/failable';
283
158
 
284
- Example:
159
+ const result = createFailable(() => JSON.parse('{"ok":true}'));
285
160
 
286
- ```ts
287
- import { success, toFailableLike } from '@pvorona/failable';
161
+ // sender
162
+ const wire = toFailableLike(result);
163
+ postMessage(wire);
288
164
 
289
- const res = success(1);
290
- const wire = toFailableLike(res);
165
+ // receiver
166
+ const hydrated = createFailable(wire);
291
167
  ```
292
168
 
293
- ### `isFailableLike(value): value is FailableLike<unknown, unknown>`
169
+ The transport shape is:
294
170
 
295
- Strictly checks for `{ status, data }` or `{ status, error }` with no extra enumerable keys.
171
+ - `FailableLikeSuccess<T>`: `{ status: FailableStatus.Success, data: T }`
172
+ - `FailableLikeFailure<E>`: `{ status: FailableStatus.Failure, error: E }`
296
173
 
297
- Example:
174
+ `FailableStatus` is a runtime object:
298
175
 
299
176
  ```ts
300
- import { isFailableLike } from '@pvorona/failable';
177
+ import { FailableStatus, type FailableLike } from '@pvorona/failable';
301
178
 
302
- const wire: unknown = { status: 'success', data: 1 };
303
- isFailableLike(wire); // true
179
+ const wire: FailableLike<number, string> = {
180
+ status: FailableStatus.Success,
181
+ data: 1,
182
+ };
304
183
  ```
305
184
 
306
- ### `createFailable(...)`
185
+ ## API at a glance
307
186
 
308
- Overloads:
309
-
310
- - `createFailable(failable)` returns the same instance
311
- - `createFailable(failableLike)` rehydrates into a real `Success` / `Failure`
312
- - `createFailable(() => value)` captures throws into `Failure`
313
- - `createFailable(promise)` captures rejections into `Failure`
314
-
315
- Examples:
316
-
317
- ```ts
318
- import { createFailable, failure, toFailableLike } from '@pvorona/failable';
319
-
320
- // function wrapper (captures throws)
321
- const res1 = createFailable(() => JSON.parse('{'));
322
-
323
- // promise wrapper (captures rejections)
324
- const res2 = await createFailable(fetch('https://example.com'));
325
-
326
- // rehydrate from structured clone
327
- const wire = toFailableLike(failure('bad'));
328
- const hydrated = createFailable(wire);
329
- ```
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
@@ -1,3 +1,2 @@
1
1
  export * from './lib/failable.js';
2
- export * from './lib/constants.js';
3
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,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,92 +1,119 @@
1
- import { isFunction as F, isObject as e } from "@pvorona/assert";
2
- import { notImplemented as c } from "@pvorona/not-implemented";
3
- const f = /* @__PURE__ */ Symbol("Failable"), O = /* @__PURE__ */ Symbol("Success"), l = /* @__PURE__ */ Symbol("Failure");
4
- var S = /* @__PURE__ */ ((r) => (r.Success = "success", r.Failure = "failure", r))(S || {});
5
- function g(r) {
6
- return e(r) && Object.keys(r).length === 2 && Object.getOwnPropertyDescriptor(r, "status")?.value === "success" && Object.prototype.hasOwnProperty.call(r, "data");
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 h(r) {
9
- return e(r) && Object.keys(r).length === 2 && Object.getOwnPropertyDescriptor(r, "status")?.value === "failure" && Object.prototype.hasOwnProperty.call(r, "error");
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");
10
14
  }
11
- function u(r) {
12
- return h(r) || g(r);
15
+ function a(r) {
16
+ return m(r) || j(r);
13
17
  }
14
18
  const b = {
15
- [f]: !0,
19
+ [E]: !0,
16
20
  isSuccess: !1,
17
21
  isError: !1,
18
22
  data: null,
19
23
  error: null,
20
- or: c,
21
- getOr: c,
22
- getOrThrow: c
23
- }, j = (() => {
24
+ or: f,
25
+ getOr: f,
26
+ getOrThrow: f
27
+ }, w = (() => {
24
28
  const r = Object.create(b);
25
- return r[O] = !0, r.status = "success", r.isSuccess = !0, r.or = function() {
29
+ return r[g] = !0, r.status = n.Success, r.isSuccess = !0, r.or = function() {
26
30
  return this;
27
31
  }, r.getOr = function() {
28
32
  return this.data;
29
33
  }, r.getOrThrow = function() {
30
34
  return this.data;
31
35
  }, Object.freeze(r);
32
- })(), m = (() => {
36
+ })(), y = (() => {
33
37
  const r = Object.create(b);
34
- return r[l] = !0, r.status = "failure", r.isError = !0, r.or = function(s) {
35
- return n(s);
36
- }, r.getOr = function(s) {
37
- return s;
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;
38
42
  }, r.getOrThrow = function() {
39
43
  throw this.error;
40
44
  }, Object.freeze(r);
41
45
  })();
42
- function o(r) {
43
- return e(r) && r[f] === !0;
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));
44
48
  }
45
- function E(r) {
46
- return e(r) && r[O] === !0;
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));
47
51
  }
48
- function T(r) {
49
- return e(r) && r[l] === !0;
52
+ function l(r) {
53
+ return O(r) || F(r);
50
54
  }
51
- function n(r) {
52
- const t = Object.create(j);
53
- return t.data = r, Object.freeze(t);
55
+ function B(r) {
56
+ return F(r);
54
57
  }
55
- function i(r) {
56
- const t = Object.create(m);
57
- return t.error = r, Object.freeze(t);
58
+ function C(r) {
59
+ return O(r);
58
60
  }
59
- function A(r) {
60
- return r.status === "failure" ? { status: "failure", error: r.error } : { status: "success", data: r.data };
61
+ function c(r) {
62
+ const e = Object.create(w);
63
+ return e.data = r, Object.freeze(e);
61
64
  }
62
- function L(r) {
63
- return o(r) ? r : u(r) ? a(r) : F(r) ? p(r) : y(r);
65
+ function o(r) {
66
+ const e = Object.create(y);
67
+ return e.error = r, Object.freeze(e);
64
68
  }
65
- function a(r) {
66
- return r.status === "success" ? n(r.data) : i(r.error);
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);
67
77
  }
68
- function p(r) {
78
+ function A(r, e) {
69
79
  try {
70
80
  const t = r();
71
- return o(t) ? t : u(t) ? a(t) : n(t);
81
+ return l(t) ? u(t, e) : a(t) ? u(S(t), e) : c(t);
72
82
  } catch (t) {
73
- return i(t);
83
+ return u(o(t), e);
74
84
  }
75
85
  }
76
- function y(r) {
77
- return Promise.resolve(r).then((t) => o(t) ? t : u(t) ? a(t) : n(t), i);
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 });
78
107
  }
79
108
  export {
80
- S as FailableStatus,
81
- f as FailableTag,
82
- l as FailureTag,
83
- O as SuccessTag,
84
- L as createFailable,
85
- i as failure,
86
- o as isFailable,
87
- u as isFailableLike,
88
- T as isFailure,
89
- E as isSuccess,
90
- n as success,
91
- A as toFailableLike
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
92
119
  };
@@ -1,8 +1,15 @@
1
- import { FailableTag, SuccessTag, FailureTag } from './constants.js';
2
- export declare const enum FailableStatus {
3
- Success = "success",
4
- Failure = "failure"
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}.
@@ -21,18 +28,16 @@ export type Failable<T, E> = Success<T> | Failure<E>;
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
  };
31
38
  export declare function isFailableLike(value: unknown): value is FailableLike<unknown, unknown>;
32
39
  export type Success<T> = {
33
- readonly [FailableTag]: true;
34
- readonly [SuccessTag]: true;
35
- readonly status: FailableStatus.Success;
40
+ readonly status: typeof FailableStatus.Success;
36
41
  readonly isSuccess: true;
37
42
  readonly isError: false;
38
43
  readonly data: T;
@@ -42,9 +47,7 @@ export type Success<T> = {
42
47
  readonly getOrThrow: () => T;
43
48
  };
44
49
  export type Failure<E> = {
45
- readonly [FailableTag]: true;
46
- readonly [FailureTag]: true;
47
- readonly status: FailableStatus.Failure;
50
+ readonly status: typeof FailableStatus.Failure;
48
51
  readonly isSuccess: false;
49
52
  readonly isError: true;
50
53
  readonly error: E;
@@ -53,55 +56,6 @@ export type Failure<E> = {
53
56
  readonly getOr: <U>(value: U) => U;
54
57
  readonly getOrThrow: () => never;
55
58
  };
56
- /**
57
- * Factory + utilities for the {@link Failable} result type.
58
- *
59
- * `Failable<T, E>` is a discriminated union of:
60
- * - {@link Success}: `{ status: 'success', isSuccess: true, data: T, error: null }`
61
- * - {@link Failure}: `{ status: 'failure', isError: true, error: E, data: null }`
62
- *
63
- * Design goals:
64
- * - Prefer explicit, typed results over exceptions.
65
- * - Provide tiny ergonomics (`or`, `getOr`, `getOrThrow`) with minimal allocation.
66
- * - Support transport across structured-clone boundaries via {@link FailableLike}.
67
- *
68
- * Runtime model / invariants:
69
- * - Instances are shallow-immutable (`Object.freeze`) and tagged with Symbols.
70
- * - They are NOT class instances; do not use `instanceof`. Prefer `result.isSuccess` / `result.isError`
71
- * or the guards {@link isSuccess} / {@link isFailure}.
72
- * - Exactly one of `data` / `error` is non-null.
73
- *
74
- * Structured-clone boundary rule (RPC, `postMessage`, `chrome.*` messaging):
75
- * - **sender**: `toFailableLike(result)`
76
- * - **receiver**: `createFailable(payload)` (rehydrates methods + Symbol tags)
77
- *
78
- * `createFailable(...)` overloads:
79
- * - `createFailable(failable)` returns the same instance (no wrapping).
80
- * - `createFailable(failableLike)` rehydrates into a real `Success` / `Failure`.
81
- * - `createFailable(() => value)` captures thrown values into `Failure` and preserves/rehydrates returned
82
- * `Failable` / `FailableLike`.
83
- * - `createFailable(promise)` captures rejection values into `Failure` and preserves/rehydrates resolved
84
- * `Failable` / `FailableLike`.
85
- *
86
- * Gotchas:
87
- * - `isFailableLike` is intentionally strict: only `{ status, data }` or `{ status, error }`
88
- * with no extra enumerable keys. If you need metadata, wrap it: `{ result: failableLike, meta }`.
89
- * - `or(...)` and `getOr(...)` are eager (fallback is evaluated before the call). Use branching for
90
- * lazy fallbacks.
91
- * - No error normalization is performed: whatever you throw/reject becomes `.error`.
92
- * - `createFailable(() => somePromise)` does NOT await; pass the promise directly: `createFailable(somePromise)`.
93
- *
94
- * @example
95
- * const res = createFailable(() => JSON.parse(text));
96
- * if (res.isSuccess) return res.data;
97
- * console.error(res.error);
98
- *
99
- * @example
100
- * // Structured-clone transport
101
- * const wire = toFailableLike(res);
102
- * // ... send wire ...
103
- * const hydrated = createFailable(wire);
104
- */
105
59
  export declare function isFailable(value: unknown): value is Failable<unknown, unknown>;
106
60
  export declare function isSuccess(value: unknown): value is Success<unknown>;
107
61
  export declare function isFailure(value: unknown): value is Failure<unknown>;
@@ -110,12 +64,24 @@ export declare function failure<E = void>(error: E): Failure<E>;
110
64
  export declare function toFailableLike<T>(value: Success<T>): FailableLikeSuccess<T>;
111
65
  export declare function toFailableLike<E>(value: Failure<E>): FailableLikeFailure<E>;
112
66
  export declare function toFailableLike<T, E>(value: Failable<T, E>): FailableLike<T, E>;
113
- 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>;
114
- 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>>;
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>;
115
73
  export declare function createFailable<T>(value: FailableLikeSuccess<T>): Success<T>;
116
74
  export declare function createFailable<E>(value: FailableLikeFailure<E>): Failure<E>;
117
75
  export declare function createFailable<T, E>(value: FailableLike<T, E>): Failable<T, E>;
118
- export declare function createFailable<F extends () => R, E = Error, R = ReturnType<F>>(fun: F): InferReturnTypeFromFunction<F, E, R>;
119
- export declare function createFailable<T, E = Error, P extends PromiseLike<T> = PromiseLike<T>>(promise: P): InferReturnTypeFromPromise<T, E, P>;
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>>>;
120
86
  export {};
121
87
  //# sourceMappingURL=failable.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"failable.d.ts","sourceRoot":"","sources":["../../src/lib/failable.ts"],"names":[],"mappings":"AAEA,OAAO,EAA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OAAO,CAAC,6BAA6B,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,15 +1,25 @@
1
1
  {
2
2
  "name": "@pvorona/failable",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
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
  ".": {
12
- "@pvorona/source": "./src/index.ts",
13
23
  "types": "./dist/index.d.ts",
14
24
  "import": "./dist/index.js",
15
25
  "default": "./dist/index.js"
@@ -19,6 +29,10 @@
19
29
  "dist",
20
30
  "!**/*.tsbuildinfo"
21
31
  ],
32
+ "scripts": {
33
+ "check-package-surface": "node ./scripts/check-package-surface.mjs",
34
+ "prepublishOnly": "npm run check-package-surface"
35
+ },
22
36
  "publishConfig": {
23
37
  "access": "public"
24
38
  },
@@ -1,4 +0,0 @@
1
- export declare const FailableTag: unique symbol;
2
- export declare const SuccessTag: unique symbol;
3
- export declare const FailureTag: unique symbol;
4
- //# sourceMappingURL=constants.d.ts.map
@@ -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"}