@pvorona/failable 0.3.0 → 0.5.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,15 @@
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 normal application code, return `success(...)` / `failure(...)`, then branch with `result.isSuccess` / `result.isError`. Keep `isSuccess(...)` / `isFailure(...)` for validating hydrated unknown values, and use `isFailableLike(...)` for plain transport shapes.
5
+ Use `@pvorona/failable` when failure is part of normal control flow: invalid
6
+ input, missing config, not found, or a dependency call that can fail. Return a
7
+ `Failable<T, E>` instead of throwing, then handle the result explicitly.
8
+
9
+ A `Failable<T, E>` is either `Success<T>` or `Failure<E>`.
10
+
11
+ - `success(...)` / `failure(...)` create results
12
+ - `failable(...)` captures thrown or rejected boundaries
13
+ - `run(...)` composes multiple `Failable` steps
6
14
 
7
15
  ## Install
8
16
 
@@ -10,261 +18,433 @@ Typed success/failure results for expected failures in TypeScript.
10
18
  npm i @pvorona/failable
11
19
  ```
12
20
 
13
- This package is ESM-only. Use `import` syntax; the published package declares `Node >=18`.
21
+ This package is ESM-only and requires Node 18+.
22
+
23
+ ## Migration Note
24
+
25
+ If you are upgrading from the previous API name:
26
+
27
+ - `createFailable(x)` -> `failable(x)`
28
+ - `CreateFailableNormalizeErrorOptions` -> `FailableNormalizeErrorOptions`
29
+
30
+ ## Basic Usage
14
31
 
15
- ## Quick Start
32
+ Use `Failable` when callers need different behavior for different expected
33
+ failures. This is especially useful for business rules that schema validators do
34
+ not model for you:
16
35
 
17
36
  ```ts
18
- import type { Failable } from '@pvorona/failable';
19
- import { failure, success } from '@pvorona/failable';
37
+ import { failure, success, type Failable } from '@pvorona/failable';
38
+
39
+ type TransferRequest = {
40
+ fromAccountId: string;
41
+ toAccountId: string;
42
+ amountCents: number;
43
+ };
44
+
45
+ type TransferPlan = TransferRequest & {
46
+ feeCents: number;
47
+ };
48
+
49
+ type TransferError =
50
+ | { code: 'same_account' }
51
+ | { code: 'amount_too_small'; minAmountCents: number }
52
+ | {
53
+ code: 'insufficient_funds';
54
+ balanceCents: number;
55
+ attemptedCents: number;
56
+ };
57
+
58
+ function planTransfer(
59
+ request: TransferRequest,
60
+ balanceCents: number,
61
+ ): Failable<TransferPlan, TransferError> {
62
+ if (request.fromAccountId === request.toAccountId) {
63
+ return failure({ code: 'same_account' });
64
+ }
20
65
 
21
- function divide(a: number, b: number): Failable<number, string> {
22
- if (b === 0) return failure('Cannot divide by zero');
66
+ if (request.amountCents < 100) {
67
+ return failure({ code: 'amount_too_small', minAmountCents: 100 });
68
+ }
69
+
70
+ if (balanceCents < request.amountCents) {
71
+ return failure({
72
+ code: 'insufficient_funds',
73
+ balanceCents,
74
+ attemptedCents: request.amountCents,
75
+ });
76
+ }
23
77
 
24
- return success(a / b);
78
+ return success({ ...request, feeCents: 25 });
25
79
  }
26
80
 
27
- const result = divide(10, 2);
81
+ const result = planTransfer(
82
+ {
83
+ fromAccountId: 'checking',
84
+ toAccountId: 'savings',
85
+ amountCents: 10_000,
86
+ },
87
+ 4_500,
88
+ );
28
89
 
29
90
  if (result.isError) {
30
- console.error(result.error);
91
+ switch (result.error.code) {
92
+ case 'same_account':
93
+ console.error('Choose a different destination account');
94
+ break;
95
+ case 'amount_too_small':
96
+ console.error(`Transfers start at ${result.error.minAmountCents} cents`);
97
+ break;
98
+ case 'insufficient_funds':
99
+ console.error(
100
+ `Balance ${result.error.balanceCents} is below ${result.error.attemptedCents}`
101
+ );
102
+ break;
103
+ }
31
104
  } else {
32
- console.log(result.data);
105
+ console.log(result.data.feeCents);
33
106
  }
34
107
  ```
35
108
 
36
- ## Everyday Usage
109
+ That is the default usage model for this package: return a typed result that
110
+ carries both the success value and the expected failure reason.
37
111
 
38
- ### Return `success(...)` and `failure(...)`
112
+ ## Choose The Right API
39
113
 
40
- Use the explicit constructors when your function already knows which branch it should return:
114
+ | Need | Use |
115
+ | --- | --- |
116
+ | Return a successful or failed result from your own code | `success(...)` / `failure(...)` |
117
+ | Read the value or provide a fallback | `getOr(...)` / `getOrElse(...)` |
118
+ | Recover to `Success<T>` | `or(...)` / `orElse(...)` |
119
+ | Map both branches to one output | `match(onSuccess, onFailure)` |
120
+ | Throw the stored failure unchanged | `getOrThrow()` / `throwIfError(result)` |
121
+ | Capture a throwing or rejecting boundary | `failable(...)` |
122
+ | Compose multiple `Failable` steps | `run(...)` |
123
+ | Cross a structured-clone boundary | `toFailableLike(...)` + `failable(...)` |
124
+ | Validate `unknown` input | `isFailable(...)`, `isSuccess(...)`, `isFailure(...)`, `isFailableLike(...)` |
41
125
 
42
- ```ts
43
- import { failure, success } from '@pvorona/failable';
126
+ ## Unwrapping And Recovery
44
127
 
45
- const ok = success({ id: '1' });
46
- const err = failure({ code: 'bad_request' });
47
- ```
128
+ Start with ordinary branching on `result.isError` or `result.isSuccess`. When
129
+ you need a shorter form, use the helper that matches the job:
48
130
 
49
- ### Branch and unwrap with instance methods
131
+ - `result.getOr(fallback)`: return the success value or an eager fallback
132
+ - `result.getOrElse(() => fallback)`: same, but lazily
133
+ - `result.or(fallback)`: recover to `Success<T>` with an eager fallback
134
+ - `result.orElse(() => fallback)`: recover to `Success<T>` lazily
135
+ - `result.match(onSuccess, onFailure)`: map both branches to one output
136
+ - `result.getOrThrow()`: return the success value or throw `result.error`
137
+ - `throwIfError(result)`: throw `result.error` and narrow the same variable
50
138
 
51
- Hydrated `Failable` values carry booleans and convenience methods, so everyday code can stay local and direct:
139
+ Use the lazy forms when the fallback is expensive or has side effects.
52
140
 
53
141
  ```ts
54
- import { failure, success } from '@pvorona/failable';
142
+ import {
143
+ failure,
144
+ success,
145
+ throwIfError,
146
+ type Failable,
147
+ } from '@pvorona/failable';
55
148
 
56
- const portResult = Math.random() > 0.5
57
- ? success(3000)
58
- : failure('Missing port');
149
+ type QuoteError = {
150
+ code: 'pricing_unavailable';
151
+ };
59
152
 
60
- if (portResult.isError) {
61
- console.error(portResult.error);
62
- } else {
63
- const requiredPort = portResult.getOrThrow();
64
- console.log(requiredPort);
65
- }
153
+ const feeResult: Failable<number, QuoteError> =
154
+ Math.random() > 0.5
155
+ ? success(25)
156
+ : failure({ code: 'pricing_unavailable' });
157
+
158
+ const feeCents = feeResult.getOr(25);
159
+ const status = feeResult.match(
160
+ (value) => `Fee is ${value} cents`,
161
+ (error) => `Cannot quote fee: ${error.code}`
162
+ );
66
163
 
67
- const port = portResult.getOr(3000);
68
- const ensuredPort = portResult.or(3000);
69
- console.log(port, ensuredPort.data);
164
+ throwIfError(feeResult);
165
+ console.log(feeCents, status, feeResult.data);
70
166
  ```
71
167
 
72
- - `result.isSuccess` / `result.isError`: branch on a hydrated result
73
- - `result.getOr(fallback)`: eagerly get the success value or a fallback
74
- - `result.getOrElse(() => fallback)`: lazily compute a fallback value only on failure
75
- - `result.or(fallback)`: eagerly end up with `Success<T>`
76
- - `result.orElse(() => fallback)`: lazily recover to `Success<T>` only on failure
77
- - `result.match(onSuccess, onFailure)`: map both branches to one output type
78
- - `result.getOrThrow()`: unwrap success or throw the failure value
168
+ ## Capture Thrown Or Rejected Failures With `failable(...)`
79
169
 
80
- Use the lazy forms when the fallback is expensive or has side effects:
170
+ Use `failable(...)` at boundaries that throw or reject, then normalize
171
+ that failure once at the boundary if needed:
172
+
173
+ Using `TransferPlan` from above:
81
174
 
82
175
  ```ts
83
- import { failure, success } from '@pvorona/failable';
176
+ import {
177
+ failable,
178
+ run,
179
+ success,
180
+ type Failable,
181
+ } from '@pvorona/failable';
84
182
 
85
- function readFallbackPort() {
86
- console.log('Reading fallback port from disk');
87
- return 3000;
88
- }
183
+ type SubmitTransferError = Error;
89
184
 
90
- const portResult = Math.random() > 0.5
91
- ? success(8080)
92
- : failure('Missing port');
185
+ async function postToLedger(
186
+ plan: TransferPlan,
187
+ ): Promise<Failable<{ transferId: string }, SubmitTransferError>> {
188
+ const request = (async () => {
189
+ if (plan.amountCents > 5_000) {
190
+ throw { code: 'ledger_unavailable' } as const;
191
+ }
93
192
 
94
- const eagerPort = portResult.getOr(readFallbackPort());
95
- const lazyPort = portResult.getOrElse(() => readFallbackPort());
96
- const ensuredPort = portResult.orElse(() => readFallbackPort());
193
+ return { transferId: 'tr_123' };
194
+ })();
97
195
 
98
- console.log(eagerPort, lazyPort, ensuredPort.data);
196
+ return await failable(request, {
197
+ normalizeError(error) {
198
+ return new Error('Ledger unavailable', { cause: error });
199
+ },
200
+ });
201
+ }
202
+
203
+ async function submitTransfer(
204
+ plan: TransferPlan,
205
+ ): Promise<Failable<{ transferId: string }, SubmitTransferError>> {
206
+ return await run(async function* ({ get }) {
207
+ const created = yield* get(postToLedger(plan));
208
+
209
+ return success(created);
210
+ });
211
+ }
99
212
  ```
100
213
 
101
- `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.
214
+ `postToLedger(...)` is the boundary adapter. It uses
215
+ `failable(..., { normalizeError })` to capture a raw throw/rejection once
216
+ and expose one stable `Error` shape to the rest of the app. If you only need
217
+ generic `Error` normalization, `NormalizedErrors` is the built-in shortcut.
218
+ Once that helper already returns `Failable`, `submitTransfer(...)` can use
219
+ `run(...)` to compose it like any other step.
102
220
 
103
- `match(...)` is often clearer than a fallback when both branches need real handling:
221
+ Pass a promise directly when you want rejection capture:
104
222
 
105
223
  ```ts
106
- import { failure, success } from '@pvorona/failable';
224
+ const responseResult = await failable(fetch(url));
225
+ ```
107
226
 
108
- const portResult = Math.random() > 0.5
109
- ? success(3000)
110
- : failure('Missing port');
227
+ `failable(...)` can:
111
228
 
112
- const status = portResult.match(
113
- (port) => `Listening on ${port}`,
114
- (error) => `Cannot start server: ${error}`
115
- );
116
- ```
229
+ - preserve an existing `Failable`
230
+ - rehydrate a `FailableLike`
231
+ - capture sync throws from a callback
232
+ - capture promise rejections from a promise
233
+ - normalize failures with `NormalizedErrors` or a custom `normalizeError(...)`
234
+
235
+ By default, the thrown or rejected value becomes `.error` unchanged.
117
236
 
118
- ### `createFailable(...)` for throwy or rejecting code
237
+ Pass the promise itself when you want rejection capture.
238
+ `failable(async () => value)` is misuse and returns a `Failure<Error>` telling
239
+ you to pass the promise directly instead.
119
240
 
120
- `createFailable(...)` is the convenience entrypoint when you want to capture sync throws, promise rejections, or reuse an existing result shape:
241
+ ## Compose Existing `Failable` Steps With `run(...)`
121
242
 
122
- - `createFailable(failable)` returns the same tagged hydrated instance
123
- - `createFailable(failableLike)` rehydrates a strict wire shape into a real `Success` / `Failure`
124
- - `createFailable(() => value)` captures sync throws into `Failure`
125
- - `createFailable(promise)` captures promise rejections into `Failure`
126
- - If a callback returns, or a promise resolves to, a `Failable` or `FailableLike`, `createFailable(...)` preserves that result instead of nesting it inside `Success`
243
+ Use `run(...)` when each step already returns `Failable` and you want to write
244
+ the success path once:
127
245
 
128
- 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.
246
+ Without `run(...)`, composition often becomes an error ladder:
129
247
 
130
248
  ```ts
131
- import {
132
- createFailable,
133
- failure,
134
- success,
135
- type Failable,
136
- } from '@pvorona/failable';
249
+ import { failure, success, type Failable } from '@pvorona/failable';
137
250
 
138
- type PortError = {
139
- readonly code: 'invalid_port';
251
+ type Account = {
252
+ id: string;
253
+ balanceCents: number;
140
254
  };
141
255
 
142
- function readPort(value: unknown): Failable<number, PortError> {
143
- if (typeof value !== 'number') return failure({ code: 'invalid_port' });
144
-
145
- return success(value);
146
- }
256
+ type TransferPlanningError =
257
+ | TransferError
258
+ | { code: 'source_account_not_found'; accountId: string }
259
+ | { code: 'destination_account_not_found'; accountId: string };
147
260
 
148
- const configResult = createFailable(() => JSON.parse(rawConfig));
261
+ function readSourceAccount(
262
+ accountId: string,
263
+ ): Failable<Account, TransferPlanningError> {
264
+ if (accountId !== 'checking') {
265
+ return failure({ code: 'source_account_not_found', accountId });
266
+ }
149
267
 
150
- if (configResult.isError) {
151
- console.error('Invalid JSON:', configResult.error);
152
- } else {
153
- const portResult = createFailable(() => readPort(configResult.data.port));
268
+ return success({ id: 'checking', balanceCents: 5_000 });
269
+ }
154
270
 
155
- if (portResult.isError) {
156
- console.error(portResult.error.code);
157
- } else {
158
- console.log(portResult.data);
271
+ function readDestinationAccount(
272
+ accountId: string,
273
+ ): Failable<Account, TransferPlanningError> {
274
+ if (accountId !== 'savings') {
275
+ return failure({ code: 'destination_account_not_found', accountId });
159
276
  }
277
+
278
+ return success({ id: 'savings', balanceCents: 20_000 });
160
279
  }
161
- ```
162
280
 
163
- Pass promises directly when you want rejection capture:
281
+ function ensureDifferentAccounts(
282
+ source: Account,
283
+ destination: Account,
284
+ ): Failable<void, TransferPlanningError> {
285
+ if (source.id === destination.id) return failure({ code: 'same_account' });
164
286
 
165
- ```ts
166
- import { createFailable } from '@pvorona/failable';
287
+ return success(undefined);
288
+ }
167
289
 
168
- const responseResult = await createFailable(fetch(url));
169
- if (responseResult.isError) console.error(responseResult.error);
170
- ```
290
+ function ensureSufficientFunds(
291
+ source: Account,
292
+ amountCents: number,
293
+ ): Failable<Account, TransferPlanningError> {
294
+ if (source.balanceCents < amountCents) {
295
+ return failure({
296
+ code: 'insufficient_funds',
297
+ balanceCents: source.balanceCents,
298
+ attemptedCents: amountCents,
299
+ });
300
+ }
171
301
 
172
- ### Use guards for `unknown` values
302
+ return success(source);
303
+ }
173
304
 
174
- Use `isFailable(...)`, `isSuccess(...)`, and `isFailure(...)` when you are validating something that might already be a hydrated `Failable` instance:
305
+ function planTransfer(
306
+ request: TransferRequest,
307
+ ): Failable<TransferPlan, TransferPlanningError> {
308
+ const source = readSourceAccount(request.fromAccountId);
309
+ if (source.isError) return source;
175
310
 
176
- ```ts
177
- import { isFailable } from '@pvorona/failable';
311
+ const destination = readDestinationAccount(request.toAccountId);
312
+ if (destination.isError) return destination;
178
313
 
179
- const candidate: unknown = maybeFromAnotherModule();
314
+ const differentAccounts = ensureDifferentAccounts(source.data, destination.data);
315
+ if (differentAccounts.isError) return differentAccounts;
180
316
 
181
- if (isFailable(candidate) && candidate.isError) {
182
- console.error(candidate.error);
317
+ const fundedSource = ensureSufficientFunds(source.data, request.amountCents);
318
+ if (fundedSource.isError) return fundedSource;
319
+
320
+ return success({ ...request, feeCents: 25 });
183
321
  }
184
322
  ```
185
323
 
186
- These guards only recognize tagged hydrated instances created by `success(...)`, `failure(...)`, or `createFailable(...)`. Plain objects that merely look similar are not enough.
187
-
188
- 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.
324
+ With the same helpers, `run(...)` keeps the flow linear:
189
325
 
190
- ## Important Semantics
326
+ ```ts
327
+ import { run, success, type Failable } from '@pvorona/failable';
328
+
329
+ function planTransfer(
330
+ request: TransferRequest,
331
+ ): Failable<TransferPlan, TransferPlanningError> {
332
+ return run(function* ({ get }) {
333
+ const source = yield* get(readSourceAccount(request.fromAccountId));
334
+ const destination = yield* get(readDestinationAccount(request.toAccountId));
335
+ yield* get(ensureDifferentAccounts(source, destination));
336
+ yield* get(ensureSufficientFunds(source, request.amountCents));
337
+
338
+ return success({ ...request, feeCents: 25 });
339
+ });
340
+ }
341
+ ```
191
342
 
192
- - Hydrated `Failable` values are frozen plain objects with methods. Prefer `result.isSuccess` / `result.isError`, and do not use `instanceof`.
193
- - `or(...)` and `getOr(...)` are eager. The fallback expression runs before the method call.
194
- - `orElse(...)` and `getOrElse(...)` are lazy. The callback runs only on failure.
195
- - `match(onSuccess, onFailure)` is useful when both branches should converge to the same output type.
196
- - `isFailable(...)`, `isSuccess(...)`, and `isFailure(...)` recognize only tagged hydrated instances, not public-shape lookalikes.
197
- - `isFailableLike(...)` remains the validator for transport shapes, and `createFailable(failableLike)` is the supported rehydration path before calling instance methods.
198
- - By default, `createFailable(...)` preserves raw thrown and rejected values. If something throws `'boom'`, `{ code: 'bad_request' }`, or `[error1, error2]`, that exact value becomes `.error`.
199
- - `getOrThrow()` throws `result.error` unchanged on failures. If you want `Error` values, opt into normalization.
200
- - `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)`.
343
+ With one async rule added, the shape stays the same:
201
344
 
202
- ## Normalizing Errors
345
+ ```ts
346
+ import { failure, run, success, type Failable } from '@pvorona/failable';
203
347
 
204
- If you want `Error`-shaped failures, opt in explicitly with `NormalizedErrors`:
348
+ type TransferAsyncError =
349
+ | TransferPlanningError
350
+ | { code: 'daily_limit_exceeded'; remainingCents: number };
205
351
 
206
- ```ts
207
- import { createFailable, NormalizedErrors } from '@pvorona/failable';
352
+ const request = {
353
+ fromAccountId: 'checking',
354
+ toAccountId: 'savings',
355
+ amountCents: 2_500,
356
+ };
208
357
 
209
- const result = createFailable(
210
- () => {
211
- throw { code: 'bad_request' };
212
- },
213
- NormalizedErrors
214
- );
358
+ async function ensureWithinDailyLimit(
359
+ accountId: string,
360
+ amountCents: number,
361
+ ): Promise<Failable<void, TransferAsyncError>> {
362
+ const remainingCents = accountId === 'checking' ? 3_000 : 0;
363
+ if (amountCents > remainingCents) {
364
+ return failure({ code: 'daily_limit_exceeded', remainingCents });
365
+ }
215
366
 
216
- if (result.isError) {
217
- console.error(result.error.message);
218
- console.error(result.error.cause); // { code: 'bad_request' }
367
+ return success(undefined);
219
368
  }
369
+
370
+ const result = await run(async function* ({ get }) {
371
+ const source = yield* get(readSourceAccount(request.fromAccountId));
372
+ const destination = yield* get(readDestinationAccount(request.toAccountId));
373
+ yield* get(ensureDifferentAccounts(source, destination));
374
+ yield* get(ensureSufficientFunds(source, request.amountCents));
375
+ yield* get(ensureWithinDailyLimit(source.id, request.amountCents));
376
+
377
+ return success({ ...request, feeCents: 25 });
378
+ });
220
379
  ```
221
380
 
222
- The same option also normalizes existing `failure(...)` values and rehydrated `FailableLike` failures.
381
+ Keep these rules in mind:
223
382
 
224
- Built-in normalization behaves like this:
383
+ - `run(...)` composes existing `Failable` values
384
+ - if a yielded step fails, `run(...)` returns that original failure unchanged
385
+ - in async builders, keep using `yield* get(...)`; do not write `await get(...)`
386
+ - `run(...)` does not capture thrown values or rejected promises into `Failure`
387
+ - wrap throwing or rejecting boundaries with `failable(...)` before they
388
+ enter `run(...)`
225
389
 
226
- - existing `Error` values pass through unchanged
227
- - arrays become `AggregateError`
228
- - other values become `Error`
229
- - the original raw value is preserved in `error.cause`
390
+ ## Transport And Runtime Validation
230
391
 
231
- For custom normalization:
392
+ `Failable` values are hydrated objects with methods. Keep them inside your
393
+ process. If you need a structured-clone-friendly shape, convert to
394
+ `FailableLike<T, E>` before crossing the boundary and rehydrate on the other
395
+ side:
232
396
 
233
397
  ```ts
234
- import { createFailable } from '@pvorona/failable';
398
+ import {
399
+ failable,
400
+ toFailableLike,
401
+ } from '@pvorona/failable';
235
402
 
236
- const result = createFailable(doThing, {
237
- normalizeError(error) {
238
- return error instanceof Error
239
- ? error
240
- : new Error('Operation failed', { cause: error });
403
+ const result = planTransfer(
404
+ {
405
+ fromAccountId: 'checking',
406
+ toAccountId: 'savings',
407
+ amountCents: 2_500,
241
408
  },
242
- });
243
- ```
409
+ 5_000,
410
+ );
244
411
 
245
- ## Boundary Transport
412
+ const wire = toFailableLike(result);
413
+ const hydrated = failable(wire);
414
+ ```
246
415
 
247
- 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:
416
+ Use the runtime guards only when the input did not come from your own local
417
+ control flow:
248
418
 
249
419
  ```ts
250
- import { createFailable, toFailableLike } from '@pvorona/failable';
420
+ import { isFailable } from '@pvorona/failable';
251
421
 
252
- const wire = toFailableLike(result);
253
- const hydrated = createFailable(wire);
422
+ const candidate: unknown = maybeFromAnotherModule();
423
+
424
+ if (isFailable(candidate) && candidate.isError) {
425
+ console.error(candidate.error);
426
+ }
254
427
  ```
255
428
 
256
- `isFailableLike(...)` validates the strict wire shape `{ status, data }` or `{ status, error }`, and the inner `data` / `error` values must still be structured-cloneable.
429
+ - use `isFailable(...)`, `isSuccess(...)`, and `isFailure(...)` for `unknown`
430
+ values that might already be hydrated `Failable` results
431
+ - use `isFailableLike(...)` for plain transport shapes like
432
+ `{ status, data }` or `{ status, error }`
257
433
 
258
434
  ## API At A Glance
259
435
 
260
436
  - `type Failable<T, E>`: `Success<T> | Failure<E>`
261
- - `type Success<T>`: success variant with `isSuccess`, `data`, `or(...)`, `orElse(...)`, `getOr(...)`, `getOrElse(...)`, `match(...)`, and `getOrThrow()`
262
- - `type Failure<E>`: failure variant with `isError`, `error`, `or(...)`, `orElse(...)`, `getOr(...)`, `getOrElse(...)`, `match(...)`, and `getOrThrow()`
263
- - `type FailableLike<T, E>`: strict structured-clone-friendly wire shape
264
- - `const NormalizedErrors`: built-in token for `Error` normalization
265
- - `success(data)` / `failure(error)`: explicit constructors
266
- - `createFailable(...)`: wrap, preserve, rehydrate, or normalize results
267
- - `isFailable(...)`, `isSuccess(...)`, `isFailure(...)`: runtime validators for tagged hydrated values
268
- - `toFailableLike(...)`: convert a hydrated result into a plain transport shape
269
- - `isFailableLike(...)`: validate the strict wire shape
270
- - `const FailableStatus`: runtime `{ Success, Failure }` object for wire values
437
+ - `type Success<T>` / `type Failure<E>`: hydrated result variants
438
+ - `type FailableLike<T, E>`: structured-clone-friendly wire shape
439
+ - `success(data)` / `failure(error)`: create hydrated results
440
+ - `throwIfError(result)` / `result.getOrThrow()`: throw the stored failure
441
+ unchanged
442
+ - `failable(...)`: preserve, rehydrate, capture, or normalize failures at
443
+ a boundary
444
+ - `run(...)`: compose `Failable` steps without nested branching
445
+ - `toFailableLike(...)`: convert a hydrated result into a wire shape
446
+ - `isFailableLike(...)`: validate a wire shape
447
+ - `isFailable(...)`, `isSuccess(...)`, `isFailure(...)`: validate hydrated
448
+ results
449
+ - `NormalizedErrors`: built-in `Error` normalization for `failable(...)`
450
+ - `FailableStatus`: runtime success/failure status values
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- export * from './lib/failable.js';
1
+ export { FailableStatus, NormalizedErrors, failable, failure, isFailable, isFailableLike, isFailure, isSuccess, run, success, throwIfError, toFailableLike, } from './lib/failable.js';
2
+ export type { FailableNormalizeErrorOptions, Failable, FailableLike, FailableLikeFailure, FailableLikeSuccess, Failure, Success, } from './lib/failable.js';
2
3
  //# 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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,QAAQ,EACR,OAAO,EACP,UAAU,EACV,cAAc,EACd,SAAS,EACT,SAAS,EACT,GAAG,EACH,OAAO,EACP,YAAY,EACZ,cAAc,GACf,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EACV,6BAA6B,EAC7B,QAAQ,EACR,YAAY,EACZ,mBAAmB,EACnB,mBAAmB,EACnB,OAAO,EACP,OAAO,GACR,MAAM,mBAAmB,CAAC"}
package/dist/index.js CHANGED
@@ -1,35 +1,35 @@
1
- import { isFunction as S, isObject as o, hasOwnPropertyValue as F, hasOwnKey as b } from "@pvorona/assert";
2
- import { notImplemented as u } from "@pvorona/not-implemented";
3
- const h = /* @__PURE__ */ Symbol("Failable"), g = /* @__PURE__ */ Symbol("Success"), O = /* @__PURE__ */ Symbol("Failure"), n = Object.freeze({
1
+ import { isFunction as d, isObject as c, hasOwnPropertyValue as S, hasOwnKey as y } from "@pvorona/assert";
2
+ import { notImplemented as a } from "@pvorona/not-implemented";
3
+ const A = /* @__PURE__ */ Symbol("Failable"), F = /* @__PURE__ */ Symbol("Success"), O = /* @__PURE__ */ Symbol("Failure"), o = 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 o(r) && Object.keys(r).length === 2 && F(r, "status", n.Success) && b(r, "data");
9
+ function G(r) {
10
+ return c(r) && Object.keys(r).length === 2 && S(r, "status", o.Success) && y(r, "data");
11
11
  }
12
- function w(r) {
13
- return o(r) && Object.keys(r).length === 2 && F(r, "status", n.Failure) && b(r, "error");
12
+ function T(r) {
13
+ return c(r) && Object.keys(r).length === 2 && S(r, "status", o.Failure) && y(r, "error");
14
14
  }
15
- function a(r) {
16
- return w(r) || A(r);
15
+ function w(r) {
16
+ return T(r) || G(r);
17
17
  }
18
18
  const m = {
19
- [h]: !0,
19
+ [A]: !0,
20
20
  isSuccess: !1,
21
21
  isError: !1,
22
22
  data: null,
23
23
  error: null,
24
- or: u,
25
- orElse: u,
26
- getOr: u,
27
- getOrElse: u,
28
- getOrThrow: u,
29
- match: u
30
- }, y = (() => {
24
+ or: a,
25
+ orElse: a,
26
+ getOr: a,
27
+ getOrElse: a,
28
+ getOrThrow: a,
29
+ match: a
30
+ }, p = (() => {
31
31
  const r = Object.create(m);
32
- return r[g] = !0, r.status = n.Success, r.isSuccess = !0, r.or = function() {
32
+ return r[F] = !0, r.status = o.Success, r.isSuccess = !0, r.or = function() {
33
33
  return this;
34
34
  }, r.orElse = function() {
35
35
  return this;
@@ -42,90 +42,275 @@ const m = {
42
42
  }, r.match = function(t) {
43
43
  return t(this.data);
44
44
  }, Object.freeze(r);
45
- })(), L = (() => {
45
+ })(), N = (() => {
46
46
  const r = Object.create(m);
47
- return r[O] = !0, r.status = n.Failure, r.isError = !0, r.or = function(t) {
48
- return c(t);
47
+ return r[O] = !0, r.status = o.Failure, r.isError = !0, r.or = function(t) {
48
+ return f(t);
49
49
  }, r.orElse = function(t) {
50
- return c(t());
50
+ return f(t());
51
51
  }, r.getOr = function(t) {
52
52
  return t;
53
53
  }, r.getOrElse = function(t) {
54
54
  return t();
55
55
  }, r.getOrThrow = function() {
56
56
  throw this.error;
57
- }, r.match = function(t, d) {
58
- return d(this.error);
57
+ }, r.match = function(t, n) {
58
+ return n(this.error);
59
59
  }, Object.freeze(r);
60
60
  })();
61
- function f(r, e) {
62
- return o(r) ? r[e] === !0 : !1;
61
+ function b(r, e) {
62
+ return c(r) ? r[e] === !0 : !1;
63
63
  }
64
- function l(r) {
65
- return f(r, h);
64
+ function i(r) {
65
+ return b(r, A);
66
66
  }
67
- function U(r) {
68
- return f(r, g);
67
+ function ir(r) {
68
+ return b(r, F);
69
69
  }
70
- function N(r) {
71
- return f(r, O);
70
+ function sr(r) {
71
+ return b(r, O);
72
72
  }
73
- function c(r) {
74
- const e = Object.create(y);
73
+ function f(r) {
74
+ const e = Object.create(p);
75
75
  return e.data = r, Object.freeze(e);
76
76
  }
77
- function i(r) {
78
- const e = Object.create(L);
77
+ function E(r) {
78
+ const e = Object.create(N);
79
79
  return e.error = r, Object.freeze(e);
80
80
  }
81
- function G(r) {
82
- return r.status === n.Failure ? { status: n.Failure, error: r.error } : { status: n.Success, data: r.data };
81
+ function ar(r) {
82
+ if (r.status === o.Failure) throw r.error;
83
83
  }
84
- function R(r, e) {
85
- return l(r) ? s(r, e) : a(r) ? s(E(r), e) : S(r) ? T(r, e) : k(r, e);
84
+ function fr(r) {
85
+ return r.status === o.Failure ? { status: o.Failure, error: r.error } : { status: o.Success, data: r.data };
86
86
  }
87
- function E(r) {
88
- return r.status === n.Success ? c(r.data) : i(r.error);
87
+ const U = "`failable(() => ...)` only accepts synchronous callbacks. This callback returned a Promise. Pass the promise directly instead: `await failable(promise)`.", j = /* @__PURE__ */ Symbol("FailablePromiseCallbackGuard"), C = /* @__PURE__ */ Symbol("RunGet");
88
+ class s {
89
+ [C] = !0;
90
+ source;
91
+ constructor(e) {
92
+ this.source = e;
93
+ }
94
+ static create(e) {
95
+ return new s(e);
96
+ }
97
+ }
98
+ const l = "`run()` generators must yield only values produced by `get(...)`. Use `yield* get(...)` in normal code.", M = "`run()` generators must return a `Failable` or finish without returning a value.";
99
+ function* z(r) {
100
+ return yield s.create(r);
101
+ }
102
+ async function* B(r) {
103
+ return yield s.create(r);
104
+ }
105
+ function R(r) {
106
+ return !c(r) && !d(r) ? !1 : d(r.then);
107
+ }
108
+ function x(r) {
109
+ return R(r) ? B(r) : z(r);
110
+ }
111
+ const D = Object.freeze({
112
+ get: x
113
+ });
114
+ function I(r) {
115
+ if (!(r instanceof s))
116
+ throw new Error(l);
117
+ const e = r.source;
118
+ if (!i(e))
119
+ throw new Error(l);
120
+ return e;
121
+ }
122
+ async function V(r) {
123
+ if (!(r instanceof s))
124
+ throw new Error(l);
125
+ const e = await r.source;
126
+ if (!i(e))
127
+ throw new Error(l);
128
+ return e;
129
+ }
130
+ async function L(r) {
131
+ if (!(r instanceof s))
132
+ throw new Error(l);
133
+ let e;
134
+ try {
135
+ e = await r.source;
136
+ } catch (t) {
137
+ return { kind: "rejection", rejection: t };
138
+ }
139
+ if (!i(e))
140
+ throw new Error(l);
141
+ return { kind: "source", source: e };
142
+ }
143
+ function K(r, e) {
144
+ let t = r.return(e);
145
+ for (; !t.done; ) {
146
+ const n = I(t.value);
147
+ if (n.status === o.Failure) {
148
+ t = r.return(e);
149
+ continue;
150
+ }
151
+ t = r.next(n.data);
152
+ }
89
153
  }
90
- function T(r, e) {
154
+ async function H(r, e) {
155
+ let t = await r.return(e);
156
+ for (; !t.done; ) {
157
+ const n = await V(t.value);
158
+ if (n.status === o.Failure) {
159
+ t = await r.return(e);
160
+ continue;
161
+ }
162
+ t = await r.next(n.data);
163
+ }
164
+ }
165
+ async function J(r) {
166
+ let e = await r.return(void 0);
167
+ for (; !e.done; ) {
168
+ const t = await L(e.value);
169
+ if (t.kind === "rejection") {
170
+ e = await r.return(void 0);
171
+ continue;
172
+ }
173
+ const n = t.source;
174
+ if (n.status === o.Failure) {
175
+ e = await r.return(void 0);
176
+ continue;
177
+ }
178
+ e = await r.next(n.data);
179
+ }
180
+ }
181
+ function P(r) {
182
+ if (i(r))
183
+ return r;
184
+ if (r === void 0)
185
+ return f(void 0);
186
+ throw new Error(M);
187
+ }
188
+ function W(r) {
189
+ return Symbol.asyncIterator in r;
190
+ }
191
+ function Y(r) {
192
+ let e = r.next();
193
+ for (; !e.done; ) {
194
+ const t = I(e.value);
195
+ if (t.status === o.Failure)
196
+ return K(r, t), t;
197
+ e = r.next(t.data);
198
+ }
199
+ return P(e.value);
200
+ }
201
+ async function q(r) {
202
+ let e = await r.next();
203
+ for (; !e.done; ) {
204
+ const t = await L(e.value);
205
+ if (t.kind === "rejection")
206
+ throw await J(r), t.rejection;
207
+ const n = t.source;
208
+ if (n.status === o.Failure)
209
+ return await H(r, n), n;
210
+ e = await r.next(n.data);
211
+ }
212
+ return P(e.value);
213
+ }
214
+ function lr(r) {
215
+ const e = r(D);
216
+ return W(e) ? q(e) : Y(e);
217
+ }
218
+ function Er(r, e) {
219
+ return i(r) ? u(r, e) : w(r) ? u(g(r), e) : d(r) ? $(r, e) : v(r, e);
220
+ }
221
+ function g(r) {
222
+ return r.status === o.Success ? f(r.data) : E(r.error);
223
+ }
224
+ function Q() {
225
+ const r = new Error(
226
+ U
227
+ );
228
+ return Object.defineProperty(r, j, {
229
+ value: !0,
230
+ enumerable: !1,
231
+ configurable: !1,
232
+ writable: !1
233
+ }), r;
234
+ }
235
+ function X(r) {
236
+ return r instanceof Error ? Object.getOwnPropertyDescriptor(
237
+ r,
238
+ j
239
+ )?.value === !0 : !1;
240
+ }
241
+ function Z(r) {
242
+ Promise.resolve(r).catch(() => {
243
+ });
244
+ }
245
+ function $(r, e) {
91
246
  try {
92
247
  const t = r();
93
- return l(t) ? s(t, e) : a(t) ? s(E(t), e) : c(t);
248
+ return R(t) ? (Z(t), u(
249
+ E(Q()),
250
+ e
251
+ )) : i(t) ? u(t, e) : w(t) ? u(g(t), e) : f(t);
94
252
  } catch (t) {
95
- return s(i(t), e);
253
+ return u(E(t), e);
96
254
  }
97
255
  }
98
- function k(r, e) {
256
+ function v(r, e) {
99
257
  return Promise.resolve(r).then(
100
- (t) => l(t) ? s(t, e) : a(t) ? s(E(t), e) : c(t),
101
- (t) => s(i(t), e)
258
+ (t) => i(t) ? u(t, e) : w(t) ? u(g(t), e) : f(t),
259
+ (t) => u(E(t), e)
102
260
  );
103
261
  }
104
- function s(r, e) {
105
- const t = _(e);
106
- return t === null || r.status === n.Success || r.error instanceof Error ? r : i(t(r.error));
262
+ function u(r, e) {
263
+ if (r.status === o.Success || X(r.error)) return r;
264
+ const t = rr(e);
265
+ return t === null || r.error instanceof Error && e !== void 0 && _(e) ? r : E(t(r.error));
266
+ }
267
+ function rr(r) {
268
+ return r === void 0 ? null : _(r) ? or : er(r) ? r.normalizeError : null;
107
269
  }
108
270
  function _(r) {
109
- return r === void 0 ? null : z(r) ? B : I(r) ? r.normalizeError : null;
271
+ return !c(r) || Object.keys(r).length !== 1 ? !1 : Object.getOwnPropertyDescriptor(r, "mode")?.value === k.mode;
110
272
  }
111
- function z(r) {
112
- return !o(r) || Object.keys(r).length !== 1 ? !1 : Object.getOwnPropertyDescriptor(r, "mode")?.value === j.mode;
273
+ function er(r) {
274
+ return c(r) ? d(r.normalizeError) : !1;
113
275
  }
114
- function I(r) {
115
- return o(r) ? S(r.normalizeError) : !1;
276
+ function tr(r) {
277
+ if (!c(r) || Array.isArray(r)) return !1;
278
+ const e = Object.getPrototypeOf(r);
279
+ return e === Object.prototype || e === null;
280
+ }
281
+ function h(r) {
282
+ try {
283
+ const e = JSON.stringify(r);
284
+ if (typeof e == "string") return e;
285
+ } catch {
286
+ return null;
287
+ }
288
+ return null;
289
+ }
290
+ function nr(r) {
291
+ if (Object.getPrototypeOf(r) === null) {
292
+ const n = h(r);
293
+ return n !== null ? n : Object.prototype.toString.call(r);
294
+ }
295
+ const e = String(r);
296
+ if (e !== "[object Object]") return e;
297
+ const t = h(r);
298
+ return t === null ? e : t;
116
299
  }
117
- function B(r) {
118
- return r instanceof Error ? r : Array.isArray(r) ? new AggregateError(r, "Multiple errors", { cause: r }) : new Error(String(r), { cause: r });
300
+ function or(r) {
301
+ return r instanceof Error ? r : Array.isArray(r) ? new AggregateError(r, "Multiple errors", { cause: r }) : tr(r) ? new Error(nr(r), { cause: r }) : new Error(String(r), { cause: r });
119
302
  }
120
303
  export {
121
- n as FailableStatus,
122
- j as NormalizedErrors,
123
- R as createFailable,
124
- i as failure,
125
- l as isFailable,
126
- a as isFailableLike,
127
- N as isFailure,
128
- U as isSuccess,
129
- c as success,
130
- G as toFailableLike
304
+ o as FailableStatus,
305
+ k as NormalizedErrors,
306
+ Er as failable,
307
+ E as failure,
308
+ i as isFailable,
309
+ w as isFailableLike,
310
+ sr as isFailure,
311
+ ir as isSuccess,
312
+ lr as run,
313
+ f as success,
314
+ ar as throwIfError,
315
+ fr as toFailableLike
131
316
  };
@@ -6,16 +6,16 @@ export type FailableStatus = (typeof FailableStatus)[keyof typeof FailableStatus
6
6
  export declare const NormalizedErrors: Readonly<{
7
7
  readonly mode: "normalized-errors";
8
8
  }>;
9
- export type CreateFailableNormalizeErrorOptions = {
9
+ export type FailableNormalizeErrorOptions = {
10
10
  readonly normalizeError: (error: unknown) => Error;
11
11
  };
12
- type CreateFailableNormalizeErrorInput = typeof NormalizedErrors | CreateFailableNormalizeErrorOptions;
12
+ type FailableNormalizeErrorInput = typeof NormalizedErrors | FailableNormalizeErrorOptions;
13
13
  type Match<T, E> = <U>(onSuccess: (data: T) => U, onFailure: (error: E) => U) => U;
14
- export type Failable<T, E> = (Success<T> & {
14
+ export type Failable<T, E> = ((Success<T> & {
15
15
  readonly match: Match<T, E>;
16
16
  }) | (Failure<E> & {
17
17
  readonly match: Match<T, E>;
18
- });
18
+ }));
19
19
  /**
20
20
  * Structured-clone-friendly representation of {@link Failable}.
21
21
  *
@@ -27,7 +27,7 @@ export type Failable<T, E> = (Success<T> & {
27
27
  *
28
28
  * Boundary rule:
29
29
  * - **sender**: `toFailableLike(result)`
30
- * - **receiver**: `createFailable(message.result)` (rehydrates into a real {@link Failable})
30
+ * - **receiver**: `failable(message.result)` (rehydrates into a real {@link Failable})
31
31
  *
32
32
  * Note: `data` / `error` must themselves be structured-cloneable.
33
33
  */
@@ -78,27 +78,101 @@ export declare function isSuccess(value: unknown): value is Success<unknown>;
78
78
  export declare function isFailure(value: unknown): value is Failure<unknown>;
79
79
  export declare function success<T = void>(data: T): Success<T>;
80
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 `failable(...)`.
87
+ */
88
+ export declare function throwIfError<T, E>(result: Failable<T, E>): asserts result is Success<T>;
81
89
  export declare function toFailableLike<T>(value: Success<T>): FailableLikeSuccess<T>;
82
90
  export declare function toFailableLike<E>(value: Failure<E>): FailableLikeFailure<E>;
83
91
  export declare function toFailableLike<T, E>(value: Failable<T, E>): FailableLike<T, E>;
84
- 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 InferFailableFromValue<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 FailableSyncOnlyCallback<F extends () => unknown> = F & (HasKnownPromiseLikeReturn<ReturnType<F>> extends true ? {
96
+ readonly __failablePassPromiseDirectly: never;
97
+ } : unknown);
85
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>>;
86
- 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>;
87
- export declare function createFailable<T>(value: Success<T>): Success<T>;
88
- export declare function createFailable<E>(value: Failure<E>): Failure<E>;
89
- export declare function createFailable<T, E>(value: Failable<T, E>): Failable<T, E>;
90
- export declare function createFailable<T>(value: FailableLikeSuccess<T>): Success<T>;
91
- export declare function createFailable<E>(value: FailableLikeFailure<E>): Failure<E>;
92
- export declare function createFailable<T, E>(value: FailableLike<T, E>): Failable<T, E>;
93
- export declare function createFailable<T>(value: Success<T>, normalizeOption: CreateFailableNormalizeErrorInput): Success<T>;
94
- export declare function createFailable<E>(value: Failure<E>, normalizeOption: CreateFailableNormalizeErrorInput): Failure<Error>;
95
- export declare function createFailable<T, E>(value: Failable<T, E>, normalizeOption: CreateFailableNormalizeErrorInput): Failable<T, Error>;
96
- export declare function createFailable<T>(value: FailableLikeSuccess<T>, normalizeOption: CreateFailableNormalizeErrorInput): Success<T>;
97
- export declare function createFailable<E>(value: FailableLikeFailure<E>, normalizeOption: CreateFailableNormalizeErrorInput): Failure<Error>;
98
- export declare function createFailable<T, E>(value: FailableLike<T, E>, normalizeOption: CreateFailableNormalizeErrorInput): Failable<T, Error>;
99
- export declare function createFailable<F extends () => R, E = unknown, R = ReturnType<F>>(fun: F): InferReturnTypeFromFunction<F, E, R>;
100
- export declare function createFailable<F extends () => R, R = ReturnType<F>>(fun: F, normalizeOption: CreateFailableNormalizeErrorInput): NormalizeCreateFailableResult<R>;
101
- export declare function createFailable<T, E = unknown, P extends PromiseLike<T> = PromiseLike<T>>(promise: P): InferReturnTypeFromPromise<T, E, P>;
102
- export declare function createFailable<T, P extends PromiseLike<T> = PromiseLike<T>>(promise: P, normalizeOption: CreateFailableNormalizeErrorInput): Promise<NormalizeCreateFailableResult<Awaited<P>>>;
99
+ type NormalizeFailableResult<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, TSource extends Failable<T, E> = Failable<T, E>> = Generator<RunGet<T, E, TSource>, T, unknown>;
108
+ type AsyncRunGetIterator<T, E, TSource extends Failable<T, E> | PromiseLike<Failable<T, E>> = Failable<T, E> | PromiseLike<Failable<T, E>>> = AsyncGenerator<RunGet<T, E, TSource>, T, unknown>;
109
+ type RunHelpers = {
110
+ readonly get: {
111
+ <T>(source: Success<T>): RunGetIterator<T, never, Success<T>>;
112
+ <E>(source: Failure<E>): RunGetIterator<never, E, Failure<E>>;
113
+ <T, E>(source: Failable<T, E>): RunGetIterator<T, E, Failable<T, E>>;
114
+ <T>(source: PromiseLike<Success<T>>): AsyncRunGetIterator<T, never, PromiseLike<Success<T>>>;
115
+ <E>(source: PromiseLike<Failure<E>>): AsyncRunGetIterator<never, E, PromiseLike<Failure<E>>>;
116
+ <T, E>(source: PromiseLike<Failable<T, E>>): AsyncRunGetIterator<T, E, PromiseLike<Failable<T, E>>>;
117
+ };
118
+ };
119
+ type RunYield = RunGet<unknown, unknown, unknown>;
120
+ type RunReturn = void | Success<unknown> | Failure<unknown> | Failable<unknown, unknown>;
121
+ type InferRunYieldError<TYield> = TYield extends RunGet<unknown, infer TError, unknown> ? TError : never;
122
+ type InferRunGuaranteedFailureError<TYield> = TYield extends RunGet<unknown, infer TError, infer TSource> ? [TSource] extends [Failure<TError> | PromiseLike<Failure<TError>>] ? TError : never : never;
123
+ type RunReturnSuccessLike<TData = unknown> = {
124
+ readonly status: typeof FailableStatus.Success;
125
+ readonly data: TData;
126
+ readonly error: null;
127
+ };
128
+ type RunReturnFailureLike<TError = unknown> = {
129
+ readonly status: typeof FailableStatus.Failure;
130
+ readonly data: null;
131
+ readonly error: TError;
132
+ };
133
+ type MergeRunErrors<TYield, TError> = InferRunYieldError<TYield> | TError;
134
+ type InferRunSuccessResult<TYield, TData> = [InferRunYieldError<TYield>] extends [
135
+ never
136
+ ] ? Success<TData> : Failable<TData, InferRunYieldError<TYield>>;
137
+ type InferRunNeverSuccessResult<TYield> = [InferRunYieldError<TYield>] extends [
138
+ never
139
+ ] ? Success<never> : [InferRunGuaranteedFailureError<TYield>] extends [never] ? Failable<never, InferRunYieldError<TYield>> : Failure<InferRunYieldError<TYield>>;
140
+ type InferRunUnionReturnData<TResult> = ([Extract<TResult, void>] extends [never] ? never : void) | (Extract<TResult, RunReturnSuccessLike> extends {
141
+ readonly data: infer TData;
142
+ } ? TData : never);
143
+ type InferRunUnionReturnError<TResult> = Extract<TResult, RunReturnFailureLike> extends {
144
+ readonly error: infer TError;
145
+ } ? TError : never;
146
+ type InferRunResult<TYield, TResult> = [TResult] extends [never] ? [InferRunYieldError<TYield>] extends [never] ? never : Failure<InferRunYieldError<TYield>> : [TResult] extends [void] ? InferRunSuccessResult<TYield, void> : [TResult] extends [RunReturnSuccessLike<infer TData>] ? [TData] extends [never] ? InferRunNeverSuccessResult<TYield> : InferRunSuccessResult<TYield, TData> : [TResult] extends [RunReturnFailureLike<infer TError>] ? Failure<MergeRunErrors<TYield, TError>> : [MergeRunErrors<TYield, InferRunUnionReturnError<TResult>>] extends [never] ? Success<InferRunUnionReturnData<TResult>> : Failable<InferRunUnionReturnData<TResult>, MergeRunErrors<TYield, InferRunUnionReturnError<TResult>>>;
147
+ 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>>;
148
+ export declare function run<TYield extends RunYield = never, TResult extends RunReturn = RunReturn>(builder: (helpers: RunHelpers) => Generator<TYield, TResult, unknown>): InferRunResult<TYield, TResult>;
149
+ export declare function failable<T>(value: Success<T>): Success<T>;
150
+ export declare function failable<E>(value: Failure<E>): Failure<E>;
151
+ export declare function failable<T, E>(value: Failable<T, E>): Failable<T, E>;
152
+ export declare function failable<T>(value: FailableLikeSuccess<T>): Success<T>;
153
+ export declare function failable<E>(value: FailableLikeFailure<E>): Failure<E>;
154
+ export declare function failable<T, E>(value: FailableLike<T, E>): Failable<T, E>;
155
+ export declare function failable<T>(value: Success<T>, normalizeOption: FailableNormalizeErrorInput): Success<T>;
156
+ export declare function failable<E>(value: Failure<E>, normalizeOption: FailableNormalizeErrorInput): Failure<Error>;
157
+ export declare function failable<T, E>(value: Failable<T, E>, normalizeOption: FailableNormalizeErrorInput): Failable<T, Error>;
158
+ export declare function failable<T>(value: FailableLikeSuccess<T>, normalizeOption: FailableNormalizeErrorInput): Success<T>;
159
+ export declare function failable<E>(value: FailableLikeFailure<E>, normalizeOption: FailableNormalizeErrorInput): Failure<Error>;
160
+ export declare function failable<T, E>(value: FailableLike<T, E>, normalizeOption: FailableNormalizeErrorInput): Failable<T, Error>;
161
+ /**
162
+ * Capture the boundary you actually have:
163
+ * - `failable(() => value)` for synchronous callbacks that may throw
164
+ * - `await failable(promise)` for promise-based code that may reject
165
+ * - `run(...)` when the steps already return `Failable`
166
+ *
167
+ * In TypeScript, obviously promise-returning callbacks like `async () => ...` and
168
+ * `() => Promise.resolve(...)` are rejected. JS callers, plus `any`/`unknown`-typed
169
+ * callbacks, still rely on the runtime guard and receive a `Failure<Error>` telling
170
+ * them to pass the promise directly instead. That guard error is preserved even when
171
+ * a custom `normalizeError` callback is provided.
172
+ */
173
+ export declare function failable<T, P extends PromiseLike<T> = PromiseLike<T>>(promise: P, normalizeOption: FailableNormalizeErrorInput): Promise<NormalizeFailableResult<Awaited<P>>>;
174
+ export declare function failable<T, E = unknown, P extends PromiseLike<T> = PromiseLike<T>>(promise: P): InferReturnTypeFromPromise<T, E, P>;
175
+ export declare function failable<F extends () => unknown>(fun: FailableSyncOnlyCallback<F>, normalizeOption: FailableNormalizeErrorInput): NormalizeFailableResult<ReturnType<F>>;
176
+ export declare function failable<F extends () => unknown, E = unknown>(fun: FailableSyncOnlyCallback<F>): InferFailableFromValue<ReturnType<F>, E>;
103
177
  export {};
104
178
  //# 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,OA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GAAG,0BAA0B,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACnD,wBAAgB,QAAQ,CAAC,CAAC,SAAS,MAAM,OAAO,EAC9C,GAAG,EAAE,wBAAwB,CAAC,CAAC,CAAC,EAChC,eAAe,EAAE,2BAA2B,GAC3C,uBAAuB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1C,wBAAgB,QAAQ,CAAC,CAAC,SAAS,MAAM,OAAO,EAAE,CAAC,GAAG,OAAO,EAC3D,GAAG,EAAE,wBAAwB,CAAC,CAAC,CAAC,GAC/B,sBAAsB,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.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "Typed success/failure results for expected failures in TypeScript.",
5
5
  "keywords": [
6
6
  "failable",
@@ -30,14 +30,17 @@
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",
43
+ "@pvorona/assert": "~1.0.0",
41
44
  "@pvorona/not-implemented": "~0.0.1",
42
45
  "@pvorona/types": "^0.0.0"
43
46
  }