@pvorona/failable 0.2.2 → 0.4.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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Typed success/failure results for expected failures in TypeScript.
4
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.
5
+ `Failable<T, E>` is a discriminated union of `Success<T>` and `Failure<E>`. In normal application code, return `success(...)` / `failure(...)`, then branch with `result.isSuccess` / `result.isError` on that local result. Reserve `isSuccess(...)` / `isFailure(...)` for validating hydrated values that arrive as `unknown`, and use `isFailableLike(...)` for plain transport shapes.
6
6
 
7
7
  ## Install
8
8
 
@@ -10,11 +10,13 @@ Typed success/failure results for expected failures in TypeScript.
10
10
  npm i @pvorona/failable
11
11
  ```
12
12
 
13
- ## Quick start
13
+ This package is ESM-only. Use `import` syntax; the published package declares `Node >=18`.
14
+
15
+ ## Quick Start
14
16
 
15
17
  ```ts
16
18
  import type { Failable } from '@pvorona/failable';
17
- import { failure, isFailure, success } from '@pvorona/failable';
19
+ import { failure, success } from '@pvorona/failable';
18
20
 
19
21
  function divide(a: number, b: number): Failable<number, string> {
20
22
  if (b === 0) return failure('Cannot divide by zero');
@@ -24,22 +26,26 @@ function divide(a: number, b: number): Failable<number, string> {
24
26
 
25
27
  const result = divide(10, 2);
26
28
 
27
- if (isFailure(result)) {
29
+ if (result.isError) {
28
30
  console.error(result.error);
29
31
  } else {
30
32
  console.log(result.data);
31
33
  }
32
34
  ```
33
35
 
34
- ## Core API
36
+ ## Everyday Usage
35
37
 
36
- ### `type Failable<T, E>`
38
+ ### Quick chooser
37
39
 
38
- Alias for `Success<T> | Failure<E>`.
40
+ - Use `createFailable(() => ...)` when the boundary is synchronous code that might throw.
41
+ - Use `await createFailable(promise)` when the boundary is async code that might reject.
42
+ - Use `run(...)` when each step already returns `Failable` and you want to compose the happy path.
43
+ - Use `throwIfError(result)` when you want to keep using the same `result` variable after narrowing.
44
+ - Use `result.getOrThrow()` when you want the success value itself in expression or return position.
39
45
 
40
- ### `success(data)` and `failure(error)`
46
+ ### Return `success(...)` and `failure(...)`
41
47
 
42
- Use these when you already know whether you are returning success or failure:
48
+ Use the explicit constructors when your function already knows which branch it should return:
43
49
 
44
50
  ```ts
45
51
  import { failure, success } from '@pvorona/failable';
@@ -48,79 +54,271 @@ const ok = success({ id: '1' });
48
54
  const err = failure({ code: 'bad_request' });
49
55
  ```
50
56
 
51
- ### `isSuccess(...)` and `isFailure(...)`
57
+ ### Branch and unwrap with helpers
52
58
 
53
- Use the guards or the instance booleans (`result.isSuccess` / `result.isError`) to branch:
59
+ Hydrated `Failable` values carry booleans and convenience methods. Start with ordinary branching on the result, then pick the helper that matches how you want to unwrap:
54
60
 
55
61
  ```ts
56
- import { failure, isSuccess, success } from '@pvorona/failable';
62
+ import { failure, success } from '@pvorona/failable';
57
63
 
58
- const result = Math.random() > 0.5 ? success(123) : failure('boom');
64
+ const portResult = Math.random() > 0.5
65
+ ? success(3000)
66
+ : failure('Missing port');
59
67
 
60
- if (isSuccess(result)) {
61
- console.log(result.data);
68
+ if (portResult.isError) {
69
+ console.error(portResult.error);
62
70
  } else {
63
- console.error(result.error);
71
+ console.log(portResult.data);
72
+ }
73
+
74
+ const port = portResult.getOr(3000);
75
+ const ensuredPort = portResult.or(3000);
76
+ console.log(port, ensuredPort.data);
77
+ ```
78
+
79
+ - `result.isSuccess` / `result.isError`: branch on a hydrated result
80
+ - `result.getOr(fallback)`: eagerly get the success value or a fallback
81
+ - `result.getOrElse(() => fallback)`: lazily compute a fallback value only on failure
82
+ - `result.or(fallback)`: eagerly recover to a `Success` result
83
+ - `result.orElse(() => fallback)`: lazily recover to a `Success` result only on failure
84
+ - `result.match(onSuccess, onFailure)`: map both branches to one output type
85
+ - `throwIfError(result)`: throw the stored failure unchanged and keep using the same result on success
86
+ - `result.getOrThrow()`: unwrap success as a value or throw the stored failure unchanged
87
+
88
+ Use `throwIfError(result)` when you want to keep the same result variable and continue with narrowed access to `result.data`:
89
+
90
+ ```ts
91
+ import {
92
+ failure,
93
+ success,
94
+ throwIfError,
95
+ type Failable,
96
+ } from '@pvorona/failable';
97
+
98
+ const portResult: Failable<number, string> = Math.random() > 0.5
99
+ ? success(3000)
100
+ : failure('Missing port');
101
+
102
+ throwIfError(portResult);
103
+ console.log(portResult.data);
104
+ ```
105
+
106
+ Use `getOrThrow()` when you want the success value itself in expression or return position:
107
+
108
+ ```ts
109
+ const requiredPort = portResult.getOrThrow();
110
+ console.log(requiredPort);
111
+ ```
112
+
113
+ Use the lazy forms when the fallback is expensive or has side effects:
114
+
115
+ ```ts
116
+ import { failure, success } from '@pvorona/failable';
117
+
118
+ function readFallbackPort() {
119
+ console.log('Reading fallback port from disk');
120
+ return 3000;
64
121
  }
122
+
123
+ const portResult = Math.random() > 0.5
124
+ ? success(8080)
125
+ : failure('Missing port');
126
+
127
+ const eagerPort = portResult.getOr(readFallbackPort());
128
+ const lazyPort = portResult.getOrElse(() => readFallbackPort());
129
+ const ensuredPort = portResult.orElse(() => readFallbackPort());
130
+
131
+ console.log(eagerPort, lazyPort, ensuredPort.data);
132
+ ```
133
+
134
+ `readFallbackPort()` runs before `getOr(...)` because the fallback expression is evaluated eagerly. With `getOrElse(...)` and `orElse(...)`, the callback runs only if the result is a failure.
135
+
136
+ `match(...)` is often clearer than a fallback when both branches need real handling:
137
+
138
+ ```ts
139
+ import { failure, success } from '@pvorona/failable';
140
+
141
+ const portResult = Math.random() > 0.5
142
+ ? success(3000)
143
+ : failure('Missing port');
144
+
145
+ const status = portResult.match(
146
+ (port) => `Listening on ${port}`,
147
+ (error) => `Cannot start server: ${error}`
148
+ );
65
149
  ```
66
150
 
67
- ### `createFailable(...)`
151
+ ### `createFailable(...)` for throwy or rejecting code
68
152
 
69
- `createFailable(...)` is a convenience wrapper when you want to capture thrown or rejected values:
153
+ `createFailable(...)` is the boundary helper for non-`Failable` code. Use it when you need to capture sync throws, promise rejections, or rehydrate an existing result shape. Unlike `run(...)`, it is not for `Failable`-to-`Failable` composition:
70
154
 
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`
155
+ - `createFailable(failable)` returns the same tagged hydrated instance
156
+ - `createFailable(failableLike)` rehydrates a strict wire shape into a real `Success` / `Failure`
157
+ - `createFailable(() => value)` captures synchronous throws into `Failure`
158
+ - `createFailable(promise)` captures async rejections into `Failure`
159
+ - If a callback returns, or a promise resolves to, a `Failable` or `FailableLike`, `createFailable(...)` preserves that result instead of nesting it inside `Success`
75
160
 
76
- Example:
161
+ Plain lookalike objects are not treated as hydrated `Failable` instances. If you have plain `{ status, data }` or `{ status, error }` transport data, validate it with `isFailableLike(...)` or pass it to `createFailable(...)` to rehydrate before calling instance methods.
162
+
163
+ If a helper already returns `Failable`, branch on it directly or compose it with `run(...)` instead of wrapping it again with `createFailable(...)`.
77
164
 
78
165
  ```ts
79
- import { createFailable, isFailure } from '@pvorona/failable';
166
+ import {
167
+ createFailable,
168
+ failure,
169
+ success,
170
+ type Failable,
171
+ } from '@pvorona/failable';
172
+
173
+ type PortError = {
174
+ readonly code: 'invalid_port';
175
+ };
176
+
177
+ function readPort(value: unknown): Failable<number, PortError> {
178
+ if (typeof value !== 'number') return failure({ code: 'invalid_port' });
80
179
 
81
- const responseResult = await createFailable(fetch('https://example.com/items'));
180
+ return success(value);
181
+ }
182
+
183
+ const configResult = createFailable(() => JSON.parse(rawConfig));
82
184
 
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}`);
185
+ if (configResult.isError) {
186
+ console.error('Invalid JSON:', configResult.error);
87
187
  } else {
88
- const text = await responseResult.data.text();
89
- const parseResult = createFailable(() => JSON.parse(text));
188
+ const portResult = readPort(configResult.data.port);
90
189
 
91
- if (isFailure(parseResult)) {
92
- console.error('Invalid JSON:', parseResult.error);
190
+ if (portResult.isError) {
191
+ console.error(portResult.error.code);
93
192
  } else {
94
- console.log(parseResult.data);
193
+ console.log(portResult.data);
95
194
  }
96
195
  }
97
196
  ```
98
197
 
99
- ## Important semantics
198
+ Pass promises directly when you want rejection capture:
199
+
200
+ ```ts
201
+ import { createFailable } from '@pvorona/failable';
202
+
203
+ const responseResult = await createFailable(fetch(url));
204
+ if (responseResult.isError) console.error(responseResult.error);
205
+ ```
206
+
207
+ `createFailable(() => promise)` is not the supported API. In TypeScript, obviously promise-returning callbacks such as `async () => ...` and `() => Promise.resolve(...)` are rejected. JS callers, plus `any`/`unknown`-typed callbacks, still rely on the runtime guard; those cases stay in the failure channel as an `Error` telling you to pass the promise directly instead. That guard error is preserved even when you pass a custom `normalizeError`.
208
+
209
+ ### `run(...)` for `Failable` composition
210
+
211
+ Use `run(...)` when each step already returns `Failable` and you want the happy path to read top-down. Inside both the sync and async builder forms, use `yield* get(result)` to unwrap success values. The mental model is simple: success values keep flowing forward, and the first yielded `Failure` short-circuits with that same `Failure` instance.
212
+
213
+ ```ts
214
+ import { failure, run, success, type Failable } from '@pvorona/failable';
215
+
216
+ function divide(a: number, b: number): Failable<number, string> {
217
+ if (b === 0) return failure('Cannot divide by zero');
100
218
 
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)`.
219
+ return success(a / b);
220
+ }
221
+
222
+ const result = run(function* ({ get }) {
223
+ const first = yield* get(divide(20, 2));
224
+ const second = yield* get(divide(first, 5));
225
+
226
+ return success(second);
227
+ });
228
+
229
+ if (result.isError) {
230
+ console.error(result.error);
231
+ } else {
232
+ console.log(result.data); // 2
233
+ }
234
+ ```
235
+
236
+ Async builders use the same composition pattern. Keep using `yield* get(...)`; do not switch to `await get(...)`:
237
+
238
+ ```ts
239
+ import { failure, run, success, type Failable } from '@pvorona/failable';
240
+
241
+ function divide(a: number, b: number): Failable<number, string> {
242
+ if (b === 0) return failure('Cannot divide by zero');
243
+
244
+ return success(a / b);
245
+ }
246
+
247
+ async function divideAsync(
248
+ a: number,
249
+ b: number,
250
+ ): Promise<Failable<number, string>> {
251
+ return divide(a, b);
252
+ }
253
+
254
+ const result = await run(async function* ({ get }) {
255
+ const first = yield* get(divide(20, 2));
256
+ const second = yield* get(divideAsync(first, 5));
257
+
258
+ return success(second);
259
+ });
260
+
261
+ if (result.isError) {
262
+ console.error(result.error);
263
+ } else {
264
+ console.log(result.data); // 2
265
+ }
266
+ ```
267
+
268
+ Important `run(...)` rules:
269
+
270
+ - Use `run(...)` for `Failable`-to-`Failable` composition. Use `createFailable(...)` when you need to capture sync throws, promise rejections, or rehydrate a `FailableLike`.
271
+ - In async builders, keep using `yield* get(...)`. Do not write `await get(...)`.
272
+ - `get(...)` accepts `Failable` sources in both modes and `PromiseLike<Failable>` sources in async builders only.
273
+ - Use `yield* get(failable)` inside the callback. Other interaction with `get` internals is unsupported and not part of the API contract.
274
+ - `get` exists only inside the generator callback; it is not a public export.
275
+ - Return `success(...)`, `failure(...)`, or another `Failable`. An empty generator or bare `return` becomes `Success<void>`, but raw return values are rejected.
276
+ - Throwing inside the generator is not converted into `Failure`, and rejected promised sources are not converted into `Failure`; foreign exceptions and rejections escape unchanged.
277
+ - Rare cleanup edge cases: cleanup `yield* get(...)` steps unwind before a yielded `Failure` returns, cleanup `Failure`s preserve the original `Failure` while outer `finally` blocks keep unwinding, and promised source rejections still unwind managed cleanup before rejecting. Direct `throw`s inside `finally` are outside that managed cleanup and can replace the in-flight failure or rejection.
278
+
279
+ ### Use guards for `unknown` values
280
+
281
+ Use `isFailable(...)`, `isSuccess(...)`, and `isFailure(...)` when you start from `unknown` and need to validate something that might already be a hydrated `Failable` instance. If you already have a local result from your own code, keep branching with `result.isSuccess` / `result.isError` instead of re-validating it with top-level guards:
282
+
283
+ ```ts
284
+ import { isFailable } from '@pvorona/failable';
285
+
286
+ const candidate: unknown = maybeFromAnotherModule();
287
+
288
+ if (isFailable(candidate) && candidate.isError) {
289
+ console.error(candidate.error);
290
+ }
291
+ ```
292
+
293
+ These guards only recognize tagged hydrated instances created by `success(...)`, `failure(...)`, or `createFailable(...)`. Plain objects that merely look similar are not enough.
294
+
295
+ Use `isSuccess(...)` / `isFailure(...)` when you only care about one branch. If you are validating plain wire data, use `isFailableLike(...)` and then rehydrate with `createFailable(...)` before calling instance methods.
296
+
297
+ ## Important Semantics
298
+
299
+ - Hydrated `Failable` values are frozen plain objects with methods. Prefer `result.isSuccess` / `result.isError`, and do not use `instanceof`.
300
+ - `run(...)` supports both `function*` and `async function*` builders. In both forms, use `yield* get(...)`; async builders still do not use `await get(...)`.
301
+ - `run(...)` short-circuits on the first yielded failure, preserves that original `Failure` instance unchanged, and enters `finally` cleanup before returning. Cleanup keeps unwinding while cleanup `yield* get(...)` steps succeed. Cleanup `Failure`s preserve the original `Failure` and continue into outer `finally` blocks, while promised cleanup rejections still escape unchanged.
302
+ - In async builders, promised `get(...)` source rejections still escape unchanged after managed `yield* get(...)` cleanup unwinds. Managed cleanup `Failure`s and managed cleanup promise rejections do not replace that original rejection. Direct `throw`s inside `finally` are outside managed cleanup: they still escape unchanged, and they can replace an in-flight yielded `Failure` or main-path rejection.
303
+ - `run(...)` composes existing `Failable` results only. It does not capture thrown values or rejected promises into `Failure`.
102
304
  - `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.
305
+ - `orElse(...)` and `getOrElse(...)` are lazy. The callback runs only on failure.
306
+ - `match(onSuccess, onFailure)` is useful when both branches should converge to the same output type.
307
+ - `throwIfError(result)` throws `result.error` unchanged on failures and narrows the same hydrated result to `Success<T>` on return.
308
+ - `throwIfError(result)` is deliberately minimal. It does not normalize or map errors; if you want `Error` values, normalize earlier with `createFailable(..., NormalizedErrors)` or a custom `normalizeError`.
309
+ - `isFailable(...)`, `isSuccess(...)`, and `isFailure(...)` recognize only tagged hydrated instances, not public-shape lookalikes.
310
+ - `isFailableLike(...)` remains the validator for transport shapes, and `createFailable(failableLike)` is the supported rehydration path before calling instance methods.
311
+ - `createFailable(...)` remains the boundary tool for capture. Use `createFailable(() => ...)` for synchronous throw capture and `await createFailable(promise)` for async rejection capture.
104
312
  - 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.
313
+ - `getOrThrow()` returns the success value and throws `result.error` unchanged on failures. Use `throwIfError(result)` when you want control-flow narrowing instead of a returned value.
314
+ - `createFailable(() => ...)` is for genuinely synchronous callbacks. TypeScript rejects obviously promise-returning callbacks, but JS callers and `any`/`unknown`-typed callbacks still rely on the runtime guard. If you already have a promise, pass it directly: `await createFailable(promise)`. That guard error stays actionable even when a custom `normalizeError` is present.
113
315
 
114
- ## Normalizing errors
316
+ ## Normalizing Errors
115
317
 
116
- If you want `Error`-shaped handling at the boundary, opt in explicitly:
318
+ If you want `Error`-shaped failures, opt in explicitly with `NormalizedErrors`:
117
319
 
118
320
  ```ts
119
- import {
120
- createFailable,
121
- isFailure,
122
- NormalizedErrors,
123
- } from '@pvorona/failable';
321
+ import { createFailable, NormalizedErrors } from '@pvorona/failable';
124
322
 
125
323
  const result = createFailable(
126
324
  () => {
@@ -129,12 +327,27 @@ const result = createFailable(
129
327
  NormalizedErrors
130
328
  );
131
329
 
132
- if (isFailure(result)) {
330
+ if (result.isError) {
133
331
  console.error(result.error.message);
134
332
  console.error(result.error.cause); // { code: 'bad_request' }
135
333
  }
136
334
  ```
137
335
 
336
+ The same preset also normalizes existing `failure(...)` values and rehydrated `FailableLike`
337
+ failures, while still passing through existing `Error` instances unchanged.
338
+
339
+ Built-in normalization behaves like this:
340
+
341
+ - existing `Error` values pass through unchanged
342
+ - arrays become `AggregateError`
343
+ - other values become `Error`
344
+ - the original raw value is preserved in `error.cause`
345
+
346
+ Custom normalization is different: `normalizeError` runs for failure values, including
347
+ existing `Error` instances, so you can wrap or replace them. The one exception is the
348
+ internal sync-only callback misuse guard error from `createFailable(() => promise)`,
349
+ which is preserved as-is so the actionable message survives.
350
+
138
351
  For custom normalization:
139
352
 
140
353
  ```ts
@@ -142,55 +355,36 @@ import { createFailable } from '@pvorona/failable';
142
355
 
143
356
  const result = createFailable(doThing, {
144
357
  normalizeError(error) {
145
- return error instanceof Error
146
- ? error
147
- : new Error('Operation failed', { cause: error });
358
+ return new Error('Operation failed', { cause: error });
148
359
  },
149
360
  });
150
361
  ```
151
362
 
152
- ## Structured-clone transport
363
+ ## Boundary Transport
153
364
 
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:
365
+ Hydrated `Failable` values do not survive structured cloning because they carry methods and runtime details. If you need to cross a message boundary, convert to a plain shape first and rehydrate on the receiving side:
155
366
 
156
367
  ```ts
157
368
  import { createFailable, toFailableLike } from '@pvorona/failable';
158
369
 
159
- const result = createFailable(() => JSON.parse('{"ok":true}'));
160
-
161
- // sender
162
370
  const wire = toFailableLike(result);
163
- postMessage(wire);
164
-
165
- // receiver
166
371
  const hydrated = createFailable(wire);
167
372
  ```
168
373
 
169
- The transport shape is:
170
-
171
- - `FailableLikeSuccess<T>`: `{ status: FailableStatus.Success, data: T }`
172
- - `FailableLikeFailure<E>`: `{ status: FailableStatus.Failure, error: E }`
173
-
174
- `FailableStatus` is a runtime object:
175
-
176
- ```ts
177
- import { FailableStatus, type FailableLike } from '@pvorona/failable';
178
-
179
- const wire: FailableLike<number, string> = {
180
- status: FailableStatus.Success,
181
- data: 1,
182
- };
183
- ```
374
+ `isFailableLike(...)` validates the strict wire shape `{ status, data }` or `{ status, error }`, and the inner `data` / `error` values must still be structured-cloneable.
184
375
 
185
- ## API at a glance
376
+ ## API At A Glance
186
377
 
187
378
  - `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
379
+ - `type Success<T>`: success variant with `isSuccess`, `data`, `or(...)`, `orElse(...)`, `getOr(...)`, `getOrElse(...)`, `match(...)`, and `getOrThrow()`
380
+ - `type Failure<E>`: failure variant with `isError`, `error`, `or(...)`, `orElse(...)`, `getOr(...)`, `getOrElse(...)`, `match(...)`, and `getOrThrow()`
381
+ - `type FailableLike<T, E>`: strict structured-clone-friendly wire shape
191
382
  - `const NormalizedErrors`: built-in token for `Error` normalization
192
383
  - `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
384
+ - `throwIfError(result)`: throw the stored failure unchanged and narrow the same result on success
385
+ - `run(...)`: compose sync or async `Failable` steps with short-circuiting
386
+ - `createFailable(...)`: wrap, preserve, rehydrate, or normalize results
387
+ - `isFailable(...)`, `isSuccess(...)`, `isFailure(...)`: runtime validators for tagged hydrated values
388
+ - `toFailableLike(...)`: convert a hydrated result into a plain transport shape
389
+ - `isFailableLike(...)`: validate the strict wire shape
390
+ - `const FailableStatus`: runtime `{ Success, Failure }` object for wire values
package/dist/index.js CHANGED
@@ -1,119 +1,294 @@
1
- import { isFunction as s, isObject as i, hasOwnPropertyValue as F, hasOwnKey as b } from "@pvorona/assert";
2
- import { notImplemented as f } from "@pvorona/not-implemented";
3
- const h = /* @__PURE__ */ Symbol("Failable"), d = /* @__PURE__ */ Symbol("Success"), m = /* @__PURE__ */ Symbol("Failure"), n = Object.freeze({
1
+ import { isFunction as d, isObject as l, hasOwnPropertyValue as b, hasOwnKey as F } from "@pvorona/assert";
2
+ import { notImplemented as i } from "@pvorona/not-implemented";
3
+ const g = /* @__PURE__ */ Symbol("Failable"), A = /* @__PURE__ */ Symbol("Success"), y = /* @__PURE__ */ Symbol("Failure"), u = Object.freeze({
4
4
  Success: "success",
5
5
  Failure: "failure"
6
- }), j = Object.freeze({
6
+ }), k = Object.freeze({
7
7
  mode: "normalized-errors"
8
8
  });
9
- function A(r) {
10
- return i(r) && Object.keys(r).length === 2 && F(r, "status", n.Success) && b(r, "data");
9
+ function P(r) {
10
+ return l(r) && Object.keys(r).length === 2 && b(r, "status", u.Success) && F(r, "data");
11
11
  }
12
- function w(r) {
13
- return i(r) && Object.keys(r).length === 2 && F(r, "status", n.Failure) && b(r, "error");
12
+ function G(r) {
13
+ return l(r) && Object.keys(r).length === 2 && b(r, "status", u.Failure) && F(r, "error");
14
14
  }
15
- function a(r) {
16
- return w(r) || A(r);
15
+ function w(r) {
16
+ return G(r) || P(r);
17
17
  }
18
- const E = {
19
- [h]: !0,
18
+ const m = {
19
+ [g]: !0,
20
20
  isSuccess: !1,
21
21
  isError: !1,
22
22
  data: null,
23
23
  error: null,
24
- or: f,
25
- getOr: f,
26
- getOrThrow: f
27
- }, y = (() => {
28
- const r = Object.create(E);
29
- return r[d] = !0, r.status = n.Success, r.isSuccess = !0, r.or = function() {
24
+ or: i,
25
+ orElse: i,
26
+ getOr: i,
27
+ getOrElse: i,
28
+ getOrThrow: i,
29
+ match: i
30
+ }, T = (() => {
31
+ const r = Object.create(m);
32
+ return r[A] = !0, r.status = u.Success, r.isSuccess = !0, r.or = function() {
33
+ return this;
34
+ }, r.orElse = function() {
30
35
  return this;
31
36
  }, r.getOr = function() {
32
37
  return this.data;
38
+ }, r.getOrElse = function() {
39
+ return this.data;
33
40
  }, r.getOrThrow = function() {
34
41
  return this.data;
42
+ }, r.match = function(t) {
43
+ return t(this.data);
35
44
  }, Object.freeze(r);
36
- })(), T = (() => {
37
- const r = Object.create(E);
38
- return r[m] = !0, r.status = n.Failure, r.isError = !0, r.or = function(t) {
39
- return c(t);
45
+ })(), C = (() => {
46
+ const r = Object.create(m);
47
+ return r[y] = !0, r.status = u.Failure, r.isError = !0, r.or = function(t) {
48
+ return a(t);
49
+ }, r.orElse = function(t) {
50
+ return a(t());
40
51
  }, r.getOr = function(t) {
41
52
  return t;
53
+ }, r.getOrElse = function(t) {
54
+ return t();
42
55
  }, r.getOrThrow = function() {
43
56
  throw this.error;
57
+ }, r.match = function(t, n) {
58
+ return n(this.error);
44
59
  }, Object.freeze(r);
45
60
  })();
46
- function O(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));
48
- }
49
- function g(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));
61
+ function h(r, e) {
62
+ return l(r) ? r[e] === !0 : !1;
51
63
  }
52
- function l(r) {
53
- return g(r) || O(r);
64
+ function c(r) {
65
+ return h(r, g);
54
66
  }
55
- function U(r) {
56
- return O(r);
67
+ function ur(r) {
68
+ return h(r, A);
57
69
  }
58
- function N(r) {
59
- return g(r);
70
+ function or(r) {
71
+ return h(r, y);
60
72
  }
61
- function c(r) {
62
- const e = Object.create(y);
73
+ function a(r) {
74
+ const e = Object.create(T);
63
75
  return e.data = r, Object.freeze(e);
64
76
  }
65
- function o(r) {
66
- const e = Object.create(T);
77
+ function E(r) {
78
+ const e = Object.create(C);
67
79
  return e.error = r, Object.freeze(e);
68
80
  }
69
- function G(r) {
70
- return r.status === n.Failure ? { status: n.Failure, error: r.error } : { status: n.Success, data: r.data };
81
+ function cr(r) {
82
+ if (r.status === u.Failure) throw r.error;
83
+ }
84
+ function sr(r) {
85
+ return r.status === u.Failure ? { status: u.Failure, error: r.error } : { status: u.Success, data: r.data };
86
+ }
87
+ const U = "`createFailable(() => ...)` only accepts synchronous callbacks. This callback returned a Promise. Pass the promise directly instead: `await createFailable(promise)`.", R = /* @__PURE__ */ Symbol(
88
+ "CreateFailablePromiseCallbackGuard"
89
+ ), N = /* @__PURE__ */ Symbol("RunGet");
90
+ class s {
91
+ [N] = !0;
92
+ source;
93
+ constructor(e) {
94
+ this.source = e;
95
+ }
96
+ static create(e) {
97
+ return new s(e);
98
+ }
99
+ }
100
+ const f = "`run()` generators must yield only values produced by `get(...)`. Use `yield* get(...)` in normal code.", B = "`run()` generators must return a `Failable` or finish without returning a value.";
101
+ function* x(r) {
102
+ return yield s.create(r);
103
+ }
104
+ async function* D(r) {
105
+ return yield s.create(r);
106
+ }
107
+ function O(r) {
108
+ return !l(r) && !d(r) ? !1 : d(r.then);
109
+ }
110
+ function M(r) {
111
+ return O(r) ? D(r) : x(r);
112
+ }
113
+ const z = Object.freeze({
114
+ get: M
115
+ });
116
+ function I(r) {
117
+ if (!(r instanceof s))
118
+ throw new Error(f);
119
+ const e = r.source;
120
+ if (!c(e))
121
+ throw new Error(f);
122
+ return e;
71
123
  }
72
- function R(r, e) {
73
- return l(r) ? u(r, e) : a(r) ? u(S(r), e) : s(r) ? L(r, e) : k(r, e);
124
+ async function p(r) {
125
+ if (!(r instanceof s))
126
+ throw new Error(f);
127
+ const e = await r.source;
128
+ if (!c(e))
129
+ throw new Error(f);
130
+ return e;
131
+ }
132
+ async function j(r) {
133
+ if (!(r instanceof s))
134
+ throw new Error(f);
135
+ let e;
136
+ try {
137
+ e = await r.source;
138
+ } catch (t) {
139
+ return { kind: "rejection", rejection: t };
140
+ }
141
+ if (!c(e))
142
+ throw new Error(f);
143
+ return { kind: "source", source: e };
144
+ }
145
+ function v(r, e) {
146
+ let t = r.return(e);
147
+ for (; !t.done; ) {
148
+ const n = I(t.value);
149
+ if (n.status === u.Failure) {
150
+ t = r.return(e);
151
+ continue;
152
+ }
153
+ t = r.next(n.data);
154
+ }
155
+ }
156
+ async function K(r, e) {
157
+ let t = await r.return(e);
158
+ for (; !t.done; ) {
159
+ const n = await p(t.value);
160
+ if (n.status === u.Failure) {
161
+ t = await r.return(e);
162
+ continue;
163
+ }
164
+ t = await r.next(n.data);
165
+ }
166
+ }
167
+ async function V(r) {
168
+ let e = await r.return(void 0);
169
+ for (; !e.done; ) {
170
+ const t = await j(e.value);
171
+ if (t.kind === "rejection") {
172
+ e = await r.return(void 0);
173
+ continue;
174
+ }
175
+ const n = t.source;
176
+ if (n.status === u.Failure) {
177
+ e = await r.return(void 0);
178
+ continue;
179
+ }
180
+ e = await r.next(n.data);
181
+ }
182
+ }
183
+ function _(r) {
184
+ if (c(r))
185
+ return r;
186
+ if (r === void 0)
187
+ return a(void 0);
188
+ throw new Error(B);
189
+ }
190
+ function H(r) {
191
+ return Symbol.asyncIterator in r;
192
+ }
193
+ function W(r) {
194
+ let e = r.next();
195
+ for (; !e.done; ) {
196
+ const t = I(e.value);
197
+ if (t.status === u.Failure)
198
+ return v(r, t), t;
199
+ e = r.next(t.data);
200
+ }
201
+ return _(e.value);
202
+ }
203
+ async function Y(r) {
204
+ let e = await r.next();
205
+ for (; !e.done; ) {
206
+ const t = await j(e.value);
207
+ if (t.kind === "rejection")
208
+ throw await V(r), t.rejection;
209
+ const n = t.source;
210
+ if (n.status === u.Failure)
211
+ return await K(r, n), n;
212
+ e = await r.next(n.data);
213
+ }
214
+ return _(e.value);
215
+ }
216
+ function ir(r) {
217
+ const e = r(z);
218
+ return H(e) ? Y(e) : W(e);
219
+ }
220
+ function ar(r, e) {
221
+ return c(r) ? o(r, e) : w(r) ? o(S(r), e) : d(r) ? X(r, e) : Z(r, e);
74
222
  }
75
223
  function S(r) {
76
- return r.status === n.Success ? c(r.data) : o(r.error);
224
+ return r.status === u.Success ? a(r.data) : E(r.error);
77
225
  }
78
- function L(r, e) {
226
+ function q() {
227
+ const r = new Error(
228
+ U
229
+ );
230
+ return Object.defineProperty(r, R, {
231
+ value: !0,
232
+ enumerable: !1,
233
+ configurable: !1,
234
+ writable: !1
235
+ }), r;
236
+ }
237
+ function J(r) {
238
+ return r instanceof Error ? Object.getOwnPropertyDescriptor(
239
+ r,
240
+ R
241
+ )?.value === !0 : !1;
242
+ }
243
+ function Q(r) {
244
+ Promise.resolve(r).catch(() => {
245
+ });
246
+ }
247
+ function X(r, e) {
79
248
  try {
80
249
  const t = r();
81
- return l(t) ? u(t, e) : a(t) ? u(S(t), e) : c(t);
250
+ return O(t) ? (Q(t), o(
251
+ E(q()),
252
+ e
253
+ )) : c(t) ? o(t, e) : w(t) ? o(S(t), e) : a(t);
82
254
  } catch (t) {
83
- return u(o(t), e);
255
+ return o(E(t), e);
84
256
  }
85
257
  }
86
- function k(r, e) {
258
+ function Z(r, e) {
87
259
  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)
260
+ (t) => c(t) ? o(t, e) : w(t) ? o(S(t), e) : a(t),
261
+ (t) => o(E(t), e)
90
262
  );
91
263
  }
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));
264
+ function o(r, e) {
265
+ if (r.status === u.Success || J(r.error)) return r;
266
+ const t = $(e);
267
+ return t === null || r.error instanceof Error && e !== void 0 && L(e) ? r : E(t(r.error));
95
268
  }
96
- function P(r) {
97
- return r === void 0 ? null : z(r) ? B : _(r) ? r.normalizeError : null;
269
+ function $(r) {
270
+ return r === void 0 ? null : L(r) ? er : rr(r) ? r.normalizeError : null;
98
271
  }
99
- function z(r) {
100
- return !i(r) || Object.keys(r).length !== 1 ? !1 : Object.getOwnPropertyDescriptor(r, "mode")?.value === j.mode;
272
+ function L(r) {
273
+ return !l(r) || Object.keys(r).length !== 1 ? !1 : Object.getOwnPropertyDescriptor(r, "mode")?.value === k.mode;
101
274
  }
102
- function _(r) {
103
- return i(r) ? s(r.normalizeError) : !1;
275
+ function rr(r) {
276
+ return l(r) ? d(r.normalizeError) : !1;
104
277
  }
105
- function B(r) {
278
+ function er(r) {
106
279
  return r instanceof Error ? r : Array.isArray(r) ? new AggregateError(r, "Multiple errors", { cause: r }) : new Error(String(r), { cause: r });
107
280
  }
108
281
  export {
109
- n as FailableStatus,
110
- j as NormalizedErrors,
111
- R as createFailable,
112
- o as failure,
113
- l as isFailable,
114
- a as isFailableLike,
115
- N as isFailure,
116
- U as isSuccess,
117
- c as success,
118
- G as toFailableLike
282
+ u as FailableStatus,
283
+ k as NormalizedErrors,
284
+ ar as createFailable,
285
+ E as failure,
286
+ c as isFailable,
287
+ w as isFailableLike,
288
+ or as isFailure,
289
+ ur as isSuccess,
290
+ ir as run,
291
+ a as success,
292
+ cr as throwIfError,
293
+ sr as toFailableLike
119
294
  };
@@ -10,7 +10,12 @@ export type CreateFailableNormalizeErrorOptions = {
10
10
  readonly normalizeError: (error: unknown) => Error;
11
11
  };
12
12
  type CreateFailableNormalizeErrorInput = typeof NormalizedErrors | CreateFailableNormalizeErrorOptions;
13
- export type Failable<T, E> = Success<T> | Failure<E>;
13
+ type Match<T, E> = <U>(onSuccess: (data: T) => U, onFailure: (error: E) => U) => U;
14
+ export type Failable<T, E> = ((Success<T> & {
15
+ readonly match: Match<T, E>;
16
+ }) | (Failure<E> & {
17
+ readonly match: Match<T, E>;
18
+ }));
14
19
  /**
15
20
  * Structured-clone-friendly representation of {@link Failable}.
16
21
  *
@@ -35,6 +40,12 @@ export type FailableLikeFailure<E> = {
35
40
  readonly status: typeof FailableStatus.Failure;
36
41
  readonly error: E;
37
42
  };
43
+ type SuccessMatch<T> = {
44
+ <U, E>(onSuccess: (data: T) => U, onFailure: (error: E) => U): U;
45
+ };
46
+ type FailureMatch<E> = {
47
+ <U, T>(onSuccess: (data: T) => U, onFailure: (error: E) => U): U;
48
+ };
38
49
  export declare function isFailableLike(value: unknown): value is FailableLike<unknown, unknown>;
39
50
  export type Success<T> = {
40
51
  readonly status: typeof FailableStatus.Success;
@@ -43,8 +54,11 @@ export type Success<T> = {
43
54
  readonly data: T;
44
55
  readonly error: null;
45
56
  readonly or: <U>(value: U) => Success<T>;
57
+ readonly orElse: <U>(getValue: () => U) => Success<T>;
46
58
  readonly getOr: <U>(value: U) => T;
59
+ readonly getOrElse: <U>(getValue: () => U) => T;
47
60
  readonly getOrThrow: () => T;
61
+ readonly match: SuccessMatch<T>;
48
62
  };
49
63
  export type Failure<E> = {
50
64
  readonly status: typeof FailableStatus.Failure;
@@ -53,20 +67,63 @@ export type Failure<E> = {
53
67
  readonly error: E;
54
68
  readonly data: null;
55
69
  readonly or: <U>(value: U) => Success<U>;
70
+ readonly orElse: <U>(getValue: () => U) => Success<U>;
56
71
  readonly getOr: <U>(value: U) => U;
72
+ readonly getOrElse: <U>(getValue: () => U) => U;
57
73
  readonly getOrThrow: () => never;
74
+ readonly match: FailureMatch<E>;
58
75
  };
59
76
  export declare function isFailable(value: unknown): value is Failable<unknown, unknown>;
60
77
  export declare function isSuccess(value: unknown): value is Success<unknown>;
61
78
  export declare function isFailure(value: unknown): value is Failure<unknown>;
62
79
  export declare function success<T = void>(data: T): Success<T>;
63
80
  export declare function failure<E = void>(error: E): Failure<E>;
81
+ /**
82
+ * Throw `result.error` unchanged on failure, or narrow the same result to {@link Success} on return.
83
+ *
84
+ * Use this when you want control-flow narrowing without replacing the original variable.
85
+ * Use `result.getOrThrow()` when you need the success value itself in expression or return position.
86
+ * If you need `Error`-shaped failures, normalize earlier with `createFailable(...)`.
87
+ */
88
+ export declare function throwIfError<T, E>(result: Failable<T, E>): asserts result is Success<T>;
64
89
  export declare function toFailableLike<T>(value: Success<T>): FailableLikeSuccess<T>;
65
90
  export declare function toFailableLike<E>(value: Failure<E>): FailableLikeFailure<E>;
66
91
  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>;
92
+ type InferCreateFailableFromValue<T, E = unknown> = [T] extends [never] ? Failure<E> : T extends Success<infer A> ? Success<A> : T extends Failure<infer A> ? Failure<A> : T extends FailableLikeSuccess<infer A> ? Success<A> : T extends FailableLikeFailure<infer A> ? Failure<A> : T extends Failable<infer A, infer B> ? Failable<A, B> : T extends FailableLike<infer A, infer B> ? Failable<A, B> : Failable<T, E>;
93
+ type IsAny<T> = 0 extends 1 & T ? true : false;
94
+ type HasKnownPromiseLikeReturn<T> = IsAny<T> extends true ? false : unknown extends T ? false : [Extract<T, PromiseLike<unknown>>] extends [never] ? false : true;
95
+ type CreateFailableSyncOnlyCallback<F extends () => unknown> = F & (HasKnownPromiseLikeReturn<ReturnType<F>> extends true ? {
96
+ readonly __createFailablePassPromiseDirectly: never;
97
+ } : unknown);
68
98
  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
99
  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>;
100
+ declare const RUN_GET_TAG: unique symbol;
101
+ declare class RunGet<T, E, TSource = Failable<T, E>> {
102
+ readonly [RUN_GET_TAG] = true;
103
+ readonly source: TSource;
104
+ private constructor();
105
+ static create<T, E, TSource extends Failable<T, E> | PromiseLike<Failable<T, E>>>(source: TSource): RunGet<T, E, TSource>;
106
+ }
107
+ type RunGetIterator<T, E> = Generator<RunGet<T, E>, T, unknown>;
108
+ type RunHelpers = {
109
+ readonly get: {
110
+ <T>(source: Success<T>): RunGetIterator<T, never>;
111
+ <E>(source: Failure<E>): RunGetIterator<never, E>;
112
+ <T, E>(source: Failable<T, E>): RunGetIterator<T, E>;
113
+ <T>(source: PromiseLike<Success<T>>): AsyncGenerator<RunGet<T, never, unknown>, T, unknown>;
114
+ <E>(source: PromiseLike<Failure<E>>): AsyncGenerator<RunGet<never, E, unknown>, never, unknown>;
115
+ <T, E>(source: PromiseLike<Failable<T, E>>): AsyncGenerator<RunGet<T, E, unknown>, T, unknown>;
116
+ };
117
+ };
118
+ type RunYield = RunGet<unknown, unknown>;
119
+ type RunReturn = void | Success<unknown> | Failure<unknown> | Failable<unknown, unknown>;
120
+ type InferRunYieldError<TYield> = TYield extends RunGet<unknown, infer TError, unknown> ? TError : never;
121
+ type InferRunReturnData<TResult> = TResult extends void ? void : TResult extends Success<infer TData> ? TData : TResult extends Failure<unknown> ? never : TResult extends Failable<infer TData, unknown> ? TData : never;
122
+ type InferRunReturnError<TResult> = TResult extends void ? never : TResult extends Success<unknown> ? never : TResult extends Failure<infer TError> ? TError : TResult extends Failable<unknown, infer TError> ? TError : never;
123
+ type InferRunError<TYield, TResult> = InferRunYieldError<TYield> | InferRunReturnError<TResult>;
124
+ type InferRunResult<TYield, TResult> = [TResult] extends [never] ? [InferRunYieldError<TYield>] extends [never] ? never : Failure<InferRunYieldError<TYield>> : [InferRunReturnData<TResult>] extends [never] ? Failure<InferRunError<TYield, TResult>> : [InferRunError<TYield, TResult>] extends [never] ? Success<InferRunReturnData<TResult>> : Failable<InferRunReturnData<TResult>, InferRunError<TYield, TResult>>;
125
+ export declare function run<TYield extends RunGet<unknown, unknown, unknown> = never, TResult extends RunReturn = RunReturn>(builder: (helpers: RunHelpers) => AsyncGenerator<TYield, TResult, unknown>): Promise<InferRunResult<TYield, TResult>>;
126
+ export declare function run<TYield extends RunYield = never, TResult extends RunReturn = RunReturn>(builder: (helpers: RunHelpers) => Generator<TYield, TResult, unknown>): InferRunResult<TYield, TResult>;
70
127
  export declare function createFailable<T>(value: Success<T>): Success<T>;
71
128
  export declare function createFailable<E>(value: Failure<E>): Failure<E>;
72
129
  export declare function createFailable<T, E>(value: Failable<T, E>): Failable<T, E>;
@@ -79,9 +136,21 @@ export declare function createFailable<T, E>(value: Failable<T, E>, normalizeOpt
79
136
  export declare function createFailable<T>(value: FailableLikeSuccess<T>, normalizeOption: CreateFailableNormalizeErrorInput): Success<T>;
80
137
  export declare function createFailable<E>(value: FailableLikeFailure<E>, normalizeOption: CreateFailableNormalizeErrorInput): Failure<Error>;
81
138
  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>;
139
+ /**
140
+ * Capture the boundary you actually have:
141
+ * - `createFailable(() => value)` for synchronous callbacks that may throw
142
+ * - `await createFailable(promise)` for promise-based code that may reject
143
+ * - `run(...)` when the steps already return `Failable`
144
+ *
145
+ * In TypeScript, obviously promise-returning callbacks like `async () => ...` and
146
+ * `() => Promise.resolve(...)` are rejected. JS callers, plus `any`/`unknown`-typed
147
+ * callbacks, still rely on the runtime guard and receive a `Failure<Error>` telling
148
+ * them to pass the promise directly instead. That guard error is preserved even when
149
+ * a custom `normalizeError` callback is provided.
150
+ */
85
151
  export declare function createFailable<T, P extends PromiseLike<T> = PromiseLike<T>>(promise: P, normalizeOption: CreateFailableNormalizeErrorInput): Promise<NormalizeCreateFailableResult<Awaited<P>>>;
152
+ export declare function createFailable<T, E = unknown, P extends PromiseLike<T> = PromiseLike<T>>(promise: P): InferReturnTypeFromPromise<T, E, P>;
153
+ export declare function createFailable<F extends () => unknown>(fun: CreateFailableSyncOnlyCallback<F>, normalizeOption: CreateFailableNormalizeErrorInput): NormalizeCreateFailableResult<ReturnType<F>>;
154
+ export declare function createFailable<F extends () => unknown, E = unknown>(fun: CreateFailableSyncOnlyCallback<F>): InferCreateFailableFromValue<ReturnType<F>, E>;
86
155
  export {};
87
156
  //# sourceMappingURL=failable.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"failable.d.ts","sourceRoot":"","sources":["../../src/lib/failable.ts"],"names":[],"mappings":"AAaA,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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AAC,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,SAAS,MAAM,OAAO,EACpD,GAAG,EAAE,8BAA8B,CAAC,CAAC,CAAC,EACtC,eAAe,EAAE,iCAAiC,GACjD,6BAA6B,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAChD,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,OAAO,EAAE,CAAC,GAAG,OAAO,EACjE,GAAG,EAAE,8BAA8B,CAAC,CAAC,CAAC,GACrC,4BAA4B,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pvorona/failable",
3
- "version": "0.2.2",
3
+ "version": "0.4.0",
4
4
  "description": "Typed success/failure results for expected failures in TypeScript.",
5
5
  "keywords": [
6
6
  "failable",
@@ -30,14 +30,18 @@
30
30
  "!**/*.tsbuildinfo"
31
31
  ],
32
32
  "scripts": {
33
+ "test-public-api": "vitest run --config vitest.public-surface.config.mts",
34
+ "typecheck-public-api": "tsc --project tests/consumer/tsconfig.json --noEmit",
33
35
  "check-package-surface": "node ./scripts/check-package-surface.mjs",
34
- "prepublishOnly": "npm run check-package-surface"
36
+ "check-public-surface": "npm run test-public-api && npm run typecheck-public-api && npm run check-package-surface",
37
+ "prepublishOnly": "npm exec nx run @pvorona/failable:check-public-surface"
35
38
  },
36
39
  "publishConfig": {
37
40
  "access": "public"
38
41
  },
39
42
  "dependencies": {
40
- "@pvorona/assert": "~0.1.0",
41
- "@pvorona/not-implemented": "~0.0.1"
43
+ "@pvorona/assert": "~1.0.0",
44
+ "@pvorona/not-implemented": "~0.0.1",
45
+ "@pvorona/types": "^0.0.0"
42
46
  }
43
47
  }