awaitly 1.31.1 → 1.32.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/dist/adapters.cjs +2 -2
- package/dist/adapters.cjs.map +1 -1
- package/dist/adapters.d.cts +3 -1
- package/dist/adapters.d.ts +3 -1
- package/dist/adapters.js +2 -2
- package/dist/adapters.js.map +1 -1
- package/dist/batch.cjs +2 -2
- package/dist/batch.cjs.map +1 -1
- package/dist/batch.d.cts +3 -1
- package/dist/batch.d.ts +3 -1
- package/dist/batch.js +2 -2
- package/dist/batch.js.map +1 -1
- package/dist/circuit-breaker.cjs +2 -2
- package/dist/circuit-breaker.cjs.map +1 -1
- package/dist/circuit-breaker.d.cts +3 -1
- package/dist/circuit-breaker.d.ts +3 -1
- package/dist/circuit-breaker.js +2 -2
- package/dist/circuit-breaker.js.map +1 -1
- package/dist/conditional.d.cts +3 -1
- package/dist/conditional.d.ts +3 -1
- package/dist/core.cjs +2 -2
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +2 -1
- package/dist/core.d.ts +2 -1
- package/dist/core.js +2 -2
- package/dist/core.js.map +1 -1
- package/dist/diagnostics.cjs +3 -3
- package/dist/diagnostics.cjs.map +1 -1
- package/dist/diagnostics.d.cts +3 -1
- package/dist/diagnostics.d.ts +3 -1
- package/dist/diagnostics.js +3 -3
- package/dist/diagnostics.js.map +1 -1
- package/dist/durable.cjs +3 -3
- package/dist/durable.cjs.map +1 -1
- package/dist/durable.d.cts +8 -361
- package/dist/durable.d.ts +8 -361
- package/dist/durable.js +3 -3
- package/dist/durable.js.map +1 -1
- package/dist/engine.cjs +11 -0
- package/dist/engine.cjs.map +1 -0
- package/dist/engine.d.cts +114 -0
- package/dist/engine.d.ts +114 -0
- package/dist/engine.js +11 -0
- package/dist/engine.js.map +1 -0
- package/dist/errors-entry-CMH73Eym.d.cts +339 -0
- package/dist/errors-entry-DOt5UUl4.d.ts +339 -0
- package/dist/errors.cjs +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts +2 -318
- package/dist/errors.d.ts +2 -318
- package/dist/errors.js +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/fetch.cjs +2 -2
- package/dist/fetch.cjs.map +1 -1
- package/dist/fetch.d.cts +3 -1
- package/dist/fetch.d.ts +3 -1
- package/dist/fetch.js +2 -2
- package/dist/fetch.js.map +1 -1
- package/dist/functional.cjs +1 -1
- package/dist/functional.cjs.map +1 -1
- package/dist/functional.d.cts +2 -0
- package/dist/functional.d.ts +2 -0
- package/dist/functional.js +1 -1
- package/dist/functional.js.map +1 -1
- package/dist/{guards-PU64_GKv.d.cts → guards-B79mP5Q8.d.cts} +3 -3
- package/dist/{guards-B5lgMJq0.d.ts → guards-BUq6NJCM.d.ts} +3 -3
- package/dist/{hitl-Dyiy0R1v.d.cts → hitl-BCqkMAHw.d.cts} +2 -2
- package/dist/{hitl-BjeSm1sJ.d.ts → hitl-BZtPx0aU.d.ts} +2 -2
- package/dist/hitl.cjs +2 -2
- package/dist/hitl.cjs.map +1 -1
- package/dist/hitl.d.cts +9 -6
- package/dist/hitl.d.ts +9 -6
- package/dist/hitl.js +2 -2
- package/dist/hitl.js.map +1 -1
- package/dist/index-BVUAOWGG.d.ts +417 -0
- package/dist/index-CQnpmUcC.d.cts +417 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/otel.d.cts +3 -1
- package/dist/otel.d.ts +3 -1
- package/dist/{persistence-entry-B3ukwbb5.d.ts → persistence-entry-ClFhxd2Q.d.ts} +11 -5
- package/dist/{persistence-entry-CgVzswbg.d.cts → persistence-entry-jflY61az.d.cts} +11 -5
- package/dist/persistence.d.cts +6 -3
- package/dist/persistence.d.ts +6 -3
- package/dist/policies.d.cts +3 -1
- package/dist/policies.d.ts +3 -1
- package/dist/ratelimit.cjs +2 -2
- package/dist/ratelimit.cjs.map +1 -1
- package/dist/ratelimit.d.cts +3 -1
- package/dist/ratelimit.d.ts +3 -1
- package/dist/ratelimit.js +2 -2
- package/dist/ratelimit.js.map +1 -1
- package/dist/reliability.cjs +2 -2
- package/dist/reliability.cjs.map +1 -1
- package/dist/reliability.d.cts +3 -1
- package/dist/reliability.d.ts +3 -1
- package/dist/reliability.js +2 -2
- package/dist/reliability.js.map +1 -1
- package/dist/resolver.cjs +2 -2
- package/dist/resolver.cjs.map +1 -1
- package/dist/resolver.d.cts +5 -3
- package/dist/resolver.d.ts +5 -3
- package/dist/resolver.js +2 -2
- package/dist/resolver.js.map +1 -1
- package/dist/resource.cjs +2 -2
- package/dist/resource.cjs.map +1 -1
- package/dist/resource.d.cts +3 -1
- package/dist/resource.d.ts +3 -1
- package/dist/resource.js +2 -2
- package/dist/resource.js.map +1 -1
- package/dist/result/retry.cjs +1 -1
- package/dist/result/retry.cjs.map +1 -1
- package/dist/result/retry.d.cts +2 -0
- package/dist/result/retry.d.ts +2 -0
- package/dist/result/retry.js +1 -1
- package/dist/result/retry.js.map +1 -1
- package/dist/result.cjs +1 -1
- package/dist/result.cjs.map +1 -1
- package/dist/result.d.cts +8 -23
- package/dist/result.d.ts +8 -23
- package/dist/result.js +1 -1
- package/dist/result.js.map +1 -1
- package/dist/{run-entry-C1uFytM6.d.cts → run-entry-rw7zll_G.d.ts} +16 -45
- package/dist/{run-entry-C1uFytM6.d.ts → run-entry-yQu63Yj9.d.cts} +16 -45
- package/dist/run.cjs +2 -2
- package/dist/run.cjs.map +1 -1
- package/dist/run.d.cts +3 -1
- package/dist/run.d.ts +3 -1
- package/dist/run.js +2 -2
- package/dist/run.js.map +1 -1
- package/dist/saga.cjs +2 -2
- package/dist/saga.cjs.map +1 -1
- package/dist/saga.d.cts +3 -1
- package/dist/saga.d.ts +3 -1
- package/dist/saga.js +2 -2
- package/dist/saga.js.map +1 -1
- package/dist/singleflight.d.cts +3 -1
- package/dist/singleflight.d.ts +3 -1
- package/dist/streaming.cjs +4 -4
- package/dist/streaming.cjs.map +1 -1
- package/dist/streaming.d.cts +5 -3
- package/dist/streaming.d.ts +5 -3
- package/dist/streaming.js +4 -4
- package/dist/streaming.js.map +1 -1
- package/dist/testing.cjs +8 -4
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +87 -4
- package/dist/testing.d.ts +87 -4
- package/dist/testing.js +8 -4
- package/dist/testing.js.map +1 -1
- package/dist/{types-wa_wTOn3.d.ts → types-CuWK5AlK.d.ts} +1 -1
- package/dist/{types-DUWrNIJu.d.cts → types-uR3JpwvF.d.cts} +1 -1
- package/dist/webhook.cjs +2 -2
- package/dist/webhook.cjs.map +1 -1
- package/dist/webhook.d.cts +7 -4
- package/dist/webhook.d.ts +7 -4
- package/dist/webhook.js +2 -2
- package/dist/webhook.js.map +1 -1
- package/dist/workflow.cjs +3 -3
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +47 -11
- package/dist/workflow.d.ts +47 -11
- package/dist/workflow.js +3 -3
- package/dist/workflow.js.map +1 -1
- package/package.json +15 -1
package/dist/errors.d.ts
CHANGED
|
@@ -1,318 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* awaitly/errors
|
|
5
|
-
*
|
|
6
|
-
* Pre-built error types for common failure scenarios.
|
|
7
|
-
* Uses TaggedError for type-safe exhaustive matching.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```typescript
|
|
11
|
-
* import { TimeoutError, RetryExhaustedError, RateLimitError, CircuitOpenError } from 'awaitly/errors';
|
|
12
|
-
*
|
|
13
|
-
* // Create errors
|
|
14
|
-
* const timeout = new TimeoutError({ operation: 'fetchUser', ms: 5000 });
|
|
15
|
-
* const retryFailed = new RetryExhaustedError({ operation: 'sendEmail', attempts: 3 });
|
|
16
|
-
*
|
|
17
|
-
* // Pattern match
|
|
18
|
-
* TaggedError.match(error, {
|
|
19
|
-
* TimeoutError: (e) => `${e.operation} timed out after ${e.ms}ms`,
|
|
20
|
-
* RetryExhaustedError: (e) => `${e.operation} failed after ${e.attempts} attempts`,
|
|
21
|
-
* RateLimitError: (e) => `Rate limit exceeded, retry after ${e.retryAfterMs}ms`,
|
|
22
|
-
* CircuitOpenError: (e) => `Circuit ${e.circuitName} is open`,
|
|
23
|
-
* });
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
/**
|
|
27
|
-
* Factory function to create tagged error classes with default values.
|
|
28
|
-
*
|
|
29
|
-
* This is a convenience wrapper around TaggedError that allows specifying
|
|
30
|
-
* default property values for error types.
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```typescript
|
|
34
|
-
* // Define custom error with defaults
|
|
35
|
-
* const NetworkError = makeError('NetworkError', {
|
|
36
|
-
* defaults: { retryable: true },
|
|
37
|
-
* message: (p) => `Network error: ${p.reason}`,
|
|
38
|
-
* });
|
|
39
|
-
*
|
|
40
|
-
* class MyNetworkError extends NetworkError<{ reason: string; code?: number }> {}
|
|
41
|
-
*
|
|
42
|
-
* const error = new MyNetworkError({ reason: 'Connection refused' });
|
|
43
|
-
* // error.retryable === true (from defaults)
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
declare function makeError<Tag extends string>(tag: Tag, options?: {
|
|
47
|
-
message?: (props: Record<string, unknown>) => string;
|
|
48
|
-
defaults?: Record<string, unknown>;
|
|
49
|
-
}): {
|
|
50
|
-
new (props?: Record<string, unknown>): {
|
|
51
|
-
readonly [x: string]: unknown;
|
|
52
|
-
readonly _tag: Tag;
|
|
53
|
-
name: string;
|
|
54
|
-
message: string;
|
|
55
|
-
stack?: string;
|
|
56
|
-
cause?: unknown;
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
declare const TimeoutError_base: TaggedErrorConstructor<"TimeoutError", {
|
|
60
|
-
/** Name of the operation that timed out */
|
|
61
|
-
operation?: string;
|
|
62
|
-
/** Timeout duration in milliseconds */
|
|
63
|
-
ms: number;
|
|
64
|
-
}>;
|
|
65
|
-
/**
|
|
66
|
-
* Error thrown when an operation times out.
|
|
67
|
-
*
|
|
68
|
-
* @example
|
|
69
|
-
* ```typescript
|
|
70
|
-
* const error = new TimeoutError({
|
|
71
|
-
* operation: 'fetchUser',
|
|
72
|
-
* ms: 5000,
|
|
73
|
-
* });
|
|
74
|
-
* console.log(error.message); // "TimeoutError: fetchUser timed out after 5000ms"
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
declare class TimeoutError extends TimeoutError_base {
|
|
78
|
-
}
|
|
79
|
-
declare const RetryExhaustedError_base: TaggedErrorConstructor<"RetryExhaustedError", {
|
|
80
|
-
/** Name of the operation that failed */
|
|
81
|
-
operation?: string;
|
|
82
|
-
/** Total number of retry attempts made */
|
|
83
|
-
attempts: number;
|
|
84
|
-
/** The last error encountered before giving up */
|
|
85
|
-
lastError?: unknown;
|
|
86
|
-
}>;
|
|
87
|
-
/**
|
|
88
|
-
* Error thrown when all retry attempts are exhausted.
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```typescript
|
|
92
|
-
* const error = new RetryExhaustedError({
|
|
93
|
-
* operation: 'sendEmail',
|
|
94
|
-
* attempts: 3,
|
|
95
|
-
* lastError: originalError,
|
|
96
|
-
* });
|
|
97
|
-
* console.log(error.message); // "RetryExhaustedError: sendEmail failed after 3 attempts"
|
|
98
|
-
* ```
|
|
99
|
-
*/
|
|
100
|
-
declare class RetryExhaustedError extends RetryExhaustedError_base {
|
|
101
|
-
}
|
|
102
|
-
declare const RateLimitError_base: TaggedErrorConstructor<"RateLimitError", {
|
|
103
|
-
/** Name of the rate limiter that was exceeded */
|
|
104
|
-
limiterName?: string;
|
|
105
|
-
/** Time in milliseconds until the rate limit resets */
|
|
106
|
-
retryAfterMs?: number;
|
|
107
|
-
}>;
|
|
108
|
-
/**
|
|
109
|
-
* Error thrown when a rate limit is exceeded.
|
|
110
|
-
*
|
|
111
|
-
* @example
|
|
112
|
-
* ```typescript
|
|
113
|
-
* const error = new RateLimitError({
|
|
114
|
-
* limiterName: 'api-calls',
|
|
115
|
-
* retryAfterMs: 1000,
|
|
116
|
-
* });
|
|
117
|
-
* console.log(error.message); // "RateLimitError: Rate limit exceeded for api-calls"
|
|
118
|
-
* ```
|
|
119
|
-
*/
|
|
120
|
-
declare class RateLimitError extends RateLimitError_base {
|
|
121
|
-
}
|
|
122
|
-
declare const CircuitBreakerOpenError_base: TaggedErrorConstructor<"CircuitBreakerOpenError", {
|
|
123
|
-
/** Name of the circuit breaker */
|
|
124
|
-
circuitName: string;
|
|
125
|
-
/** Current state of the circuit */
|
|
126
|
-
state?: "OPEN" | "HALF_OPEN";
|
|
127
|
-
/** Time in milliseconds until the circuit may close */
|
|
128
|
-
retryAfterMs?: number;
|
|
129
|
-
}>;
|
|
130
|
-
/**
|
|
131
|
-
* Error thrown when a circuit breaker is open.
|
|
132
|
-
*
|
|
133
|
-
* @example
|
|
134
|
-
* ```typescript
|
|
135
|
-
* const error = new CircuitBreakerOpenError({
|
|
136
|
-
* circuitName: 'payment-api',
|
|
137
|
-
* state: 'OPEN',
|
|
138
|
-
* retryAfterMs: 30000,
|
|
139
|
-
* });
|
|
140
|
-
* console.log(error.message); // "CircuitBreakerOpenError: Circuit payment-api is OPEN"
|
|
141
|
-
* ```
|
|
142
|
-
*/
|
|
143
|
-
declare class CircuitBreakerOpenError extends CircuitBreakerOpenError_base {
|
|
144
|
-
}
|
|
145
|
-
declare const ValidationError_base: TaggedErrorConstructor<"ValidationError", {
|
|
146
|
-
/** Field that failed validation */
|
|
147
|
-
field: string;
|
|
148
|
-
/** Reason for validation failure */
|
|
149
|
-
reason: string;
|
|
150
|
-
/** Raw value that failed validation */
|
|
151
|
-
value?: unknown;
|
|
152
|
-
}>;
|
|
153
|
-
/**
|
|
154
|
-
* Error thrown when validation fails.
|
|
155
|
-
*
|
|
156
|
-
* @example
|
|
157
|
-
* ```typescript
|
|
158
|
-
* const error = new ValidationError({
|
|
159
|
-
* field: 'email',
|
|
160
|
-
* reason: 'Invalid email format',
|
|
161
|
-
* });
|
|
162
|
-
* console.log(error.message); // "ValidationError: Invalid email - Invalid email format"
|
|
163
|
-
* ```
|
|
164
|
-
*/
|
|
165
|
-
declare class ValidationError extends ValidationError_base {
|
|
166
|
-
}
|
|
167
|
-
declare const NotFoundError_base: TaggedErrorConstructor<"NotFoundError", {
|
|
168
|
-
/** Type of resource that was not found */
|
|
169
|
-
resource: string;
|
|
170
|
-
/** Identifier of the missing resource */
|
|
171
|
-
id?: string;
|
|
172
|
-
}>;
|
|
173
|
-
/**
|
|
174
|
-
* Error thrown when a resource is not found.
|
|
175
|
-
*
|
|
176
|
-
* @example
|
|
177
|
-
* ```typescript
|
|
178
|
-
* const error = new NotFoundError({
|
|
179
|
-
* resource: 'User',
|
|
180
|
-
* id: '123',
|
|
181
|
-
* });
|
|
182
|
-
* console.log(error.message); // "NotFoundError: User with id 123 not found"
|
|
183
|
-
* ```
|
|
184
|
-
*/
|
|
185
|
-
declare class NotFoundError extends NotFoundError_base {
|
|
186
|
-
}
|
|
187
|
-
declare const UnauthorizedError_base: TaggedErrorConstructor<"UnauthorizedError", {
|
|
188
|
-
/** Action that was attempted */
|
|
189
|
-
action?: string;
|
|
190
|
-
/** Resource that was being accessed */
|
|
191
|
-
resource?: string;
|
|
192
|
-
/** Reason for denial */
|
|
193
|
-
reason?: string;
|
|
194
|
-
}>;
|
|
195
|
-
/**
|
|
196
|
-
* Error thrown when access is denied.
|
|
197
|
-
*
|
|
198
|
-
* @example
|
|
199
|
-
* ```typescript
|
|
200
|
-
* const error = new UnauthorizedError({
|
|
201
|
-
* action: 'delete',
|
|
202
|
-
* resource: 'User',
|
|
203
|
-
* });
|
|
204
|
-
* console.log(error.message); // "UnauthorizedError: Not authorized to delete User"
|
|
205
|
-
* ```
|
|
206
|
-
*/
|
|
207
|
-
declare class UnauthorizedError extends UnauthorizedError_base {
|
|
208
|
-
}
|
|
209
|
-
declare const NetworkError_base: TaggedErrorConstructor<"NetworkError", {
|
|
210
|
-
/** URL that was being accessed */
|
|
211
|
-
url?: string;
|
|
212
|
-
/** Reason for the network failure */
|
|
213
|
-
reason: string;
|
|
214
|
-
/** Whether this error is retryable */
|
|
215
|
-
retryable?: boolean;
|
|
216
|
-
/** HTTP status code if applicable */
|
|
217
|
-
statusCode?: number;
|
|
218
|
-
}>;
|
|
219
|
-
/**
|
|
220
|
-
* Error thrown for network-related failures.
|
|
221
|
-
*
|
|
222
|
-
* @example
|
|
223
|
-
* ```typescript
|
|
224
|
-
* const error = new NetworkError({
|
|
225
|
-
* url: 'https://api.example.com/users',
|
|
226
|
-
* reason: 'Connection refused',
|
|
227
|
-
* retryable: true,
|
|
228
|
-
* });
|
|
229
|
-
* ```
|
|
230
|
-
*/
|
|
231
|
-
declare class NetworkError extends NetworkError_base {
|
|
232
|
-
}
|
|
233
|
-
declare const CompensationError_base: TaggedErrorConstructor<"CompensationError", {
|
|
234
|
-
/** Step that triggered compensation */
|
|
235
|
-
step: string;
|
|
236
|
-
/** The original error that caused compensation */
|
|
237
|
-
originalError?: unknown;
|
|
238
|
-
/** Error that occurred during compensation */
|
|
239
|
-
compensationError?: unknown;
|
|
240
|
-
}>;
|
|
241
|
-
/**
|
|
242
|
-
* Error thrown when a saga compensation fails.
|
|
243
|
-
*
|
|
244
|
-
* @example
|
|
245
|
-
* ```typescript
|
|
246
|
-
* const error = new CompensationError({
|
|
247
|
-
* step: 'chargeCard',
|
|
248
|
-
* originalError: paymentError,
|
|
249
|
-
* compensationError: refundError,
|
|
250
|
-
* });
|
|
251
|
-
* ```
|
|
252
|
-
*/
|
|
253
|
-
declare class CompensationError extends CompensationError_base {
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Union of all pre-built error types.
|
|
257
|
-
* Useful for exhaustive pattern matching.
|
|
258
|
-
*
|
|
259
|
-
* @example
|
|
260
|
-
* ```typescript
|
|
261
|
-
* function handleError(error: AwaitlyError): string {
|
|
262
|
-
* return TaggedError.match(error, {
|
|
263
|
-
* TimeoutError: (e) => `Timeout: ${e.ms}ms`,
|
|
264
|
-
* RetryExhaustedError: (e) => `Retries: ${e.attempts}`,
|
|
265
|
-
* RateLimitError: (e) => `Rate limited`,
|
|
266
|
-
* CircuitBreakerOpenError: (e) => `Circuit open: ${e.circuitName}`,
|
|
267
|
-
* ValidationError: (e) => `Invalid: ${e.field}`,
|
|
268
|
-
* NotFoundError: (e) => `Not found: ${e.resource}`,
|
|
269
|
-
* UnauthorizedError: (e) => `Unauthorized`,
|
|
270
|
-
* NetworkError: (e) => `Network: ${e.reason}`,
|
|
271
|
-
* CompensationError: (e) => `Compensation failed: ${e.step}`,
|
|
272
|
-
* });
|
|
273
|
-
* }
|
|
274
|
-
* ```
|
|
275
|
-
*/
|
|
276
|
-
type AwaitlyError = TimeoutError | RetryExhaustedError | RateLimitError | CircuitBreakerOpenError | ValidationError | NotFoundError | UnauthorizedError | NetworkError | CompensationError;
|
|
277
|
-
/**
|
|
278
|
-
* Check if an error is a TimeoutError.
|
|
279
|
-
*/
|
|
280
|
-
declare function isTimeoutError(error: unknown): error is TimeoutError;
|
|
281
|
-
/**
|
|
282
|
-
* Check if an error is a RetryExhaustedError.
|
|
283
|
-
*/
|
|
284
|
-
declare function isRetryExhaustedError(error: unknown): error is RetryExhaustedError;
|
|
285
|
-
/**
|
|
286
|
-
* Check if an error is a RateLimitError.
|
|
287
|
-
*/
|
|
288
|
-
declare function isRateLimitError(error: unknown): error is RateLimitError;
|
|
289
|
-
/**
|
|
290
|
-
* Check if an error is a CircuitBreakerOpenError.
|
|
291
|
-
*/
|
|
292
|
-
declare function isCircuitBreakerOpenError(error: unknown): error is CircuitBreakerOpenError;
|
|
293
|
-
/**
|
|
294
|
-
* Check if an error is a ValidationError.
|
|
295
|
-
*/
|
|
296
|
-
declare function isValidationError(error: unknown): error is ValidationError;
|
|
297
|
-
/**
|
|
298
|
-
* Check if an error is a NotFoundError.
|
|
299
|
-
*/
|
|
300
|
-
declare function isNotFoundError(error: unknown): error is NotFoundError;
|
|
301
|
-
/**
|
|
302
|
-
* Check if an error is an UnauthorizedError.
|
|
303
|
-
*/
|
|
304
|
-
declare function isUnauthorizedError(error: unknown): error is UnauthorizedError;
|
|
305
|
-
/**
|
|
306
|
-
* Check if an error is a NetworkError.
|
|
307
|
-
*/
|
|
308
|
-
declare function isNetworkError(error: unknown): error is NetworkError;
|
|
309
|
-
/**
|
|
310
|
-
* Check if an error is a CompensationError.
|
|
311
|
-
*/
|
|
312
|
-
declare function isCompensationError(error: unknown): error is CompensationError;
|
|
313
|
-
/**
|
|
314
|
-
* Check if an error is any AwaitlyError.
|
|
315
|
-
*/
|
|
316
|
-
declare function isAwaitlyError(error: unknown): error is AwaitlyError;
|
|
317
|
-
|
|
318
|
-
export { type AwaitlyError, CircuitBreakerOpenError, CompensationError, NetworkError, NotFoundError, RateLimitError, RetryExhaustedError, TimeoutError, UnauthorizedError, ValidationError, isAwaitlyError, isCircuitBreakerOpenError, isCompensationError, isNetworkError, isNotFoundError, isRateLimitError, isRetryExhaustedError, isTimeoutError, isUnauthorizedError, isValidationError, makeError };
|
|
1
|
+
export { A as AwaitlyError, C as CircuitBreakerOpenError, a as CompensationError, N as NetworkError, b as NotFoundError, R as RateLimitError, c as RetryExhaustedError, T as TimeoutError, d as UnauthorizedError, V as ValidationError, i as isAwaitlyError, e as isCircuitBreakerOpenError, f as isCompensationError, g as isNetworkError, h as isNotFoundError, j as isRateLimitError, k as isRetryExhaustedError, l as isTimeoutError, m as isUnauthorizedError, n as isValidationError, o as makeError } from './errors-entry-DOt5UUl4.js';
|
|
2
|
+
import './tagged-error.js';
|
package/dist/errors.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var i=class extends Error{_tag};function t(e,r){return class extends i{_tag=e;constructor(s,n){let g=r?.message?r.message(s??{}):e;if(super(g),this.name=e,Object.setPrototypeOf(this,new.target.prototype),s&&typeof s=="object"){let{_tag:o,name:u,message:d,stack:E,...a}=s,c=Object.prototype.hasOwnProperty.call(a,"cause"),
|
|
1
|
+
var i=class extends Error{_tag};function t(e,r){return class extends i{_tag=e;constructor(s,n){let g=r?.message?r.message(s??{}):e;if(super(g),this.name=e,Object.setPrototypeOf(this,new.target.prototype),s&&typeof s=="object"){let{_tag:o,name:u,message:d,stack:E,...a}=s,c=Object.prototype.hasOwnProperty.call(a,"cause"),_=c?a.cause:void 0;c&&delete a.cause;let R=n?.cause!==void 0;if(c&&R)throw new TypeError("TaggedError: cannot provide 'cause' in props when also setting ErrorOptions.cause");Object.assign(this,a),c&&(this.cause=_),R&&(this.cause=n?.cause)}else n?.cause!==void 0&&(this.cause=n.cause)}}}Object.defineProperty(t,Symbol.hasInstance,{value:e=>e instanceof i});(g=>{function e(o){return o instanceof Error}g.isError=e;function r(o){return o instanceof i}g.isTaggedError=r;function s(o,u){let d=o._tag,E=u[d];return E(o)}g.match=s;function n(o,u,d){let E=o._tag,a=u[E];return a?a(o):d(o)}g.matchPartial=n})(t||={});function C(e,r){let s=r?.message??(()=>e),n=r?.defaults??{},g=t(e,{message:o=>s({...n,...o})});return class extends g{constructor(o){super({...n,...o}),Object.assign(this,{...n,...o})}}}var p=class extends t("TimeoutError",{message:r=>r.operation?`TimeoutError: ${r.operation} timed out after ${r.ms}ms`:`TimeoutError: Operation timed out after ${r.ms}ms`}){},m=class extends t("RetryExhaustedError",{message:r=>r.operation?`RetryExhaustedError: ${r.operation} failed after ${r.attempts} attempts`:`RetryExhaustedError: Operation failed after ${r.attempts} attempts`}){},x=class extends t("RateLimitError",{message:r=>r.limiterName?`RateLimitError: Rate limit exceeded for ${r.limiterName}${r.retryAfterMs?`, retry after ${r.retryAfterMs}ms`:""}`:`RateLimitError: Rate limit exceeded${r.retryAfterMs?`, retry after ${r.retryAfterMs}ms`:""}`}){},l=class extends t("CircuitBreakerOpenError",{message:r=>`CircuitBreakerOpenError: Circuit ${r.circuitName} is ${r.state??"OPEN"}${r.retryAfterMs?`, retry after ${Math.ceil(r.retryAfterMs/1e3)}s`:""}`}){},f=class extends t("ValidationError",{message:r=>`ValidationError: Invalid ${r.field} - ${r.reason}`}){},T=class extends t("NotFoundError",{message:r=>r.id?`NotFoundError: ${r.resource} with id ${r.id} not found`:`NotFoundError: ${r.resource} not found`}){},y=class extends t("UnauthorizedError",{message:r=>r.reason?`UnauthorizedError: ${r.reason}`:r.action&&r.resource?`UnauthorizedError: Not authorized to ${r.action} ${r.resource}`:"UnauthorizedError: Access denied"}){},k=class extends t("NetworkError",{message:r=>r.url?`NetworkError: ${r.reason} (${r.url})`:`NetworkError: ${r.reason}`}){},w=class extends t("CompensationError",{message:r=>`CompensationError: Failed to compensate step ${r.step}`}){},h=class extends t("UnexpectedError",{message:r=>`UnexpectedError: ${r.cause instanceof Error?r.cause.message:String(r.cause??"unknown")}`}){};function P(e){return t.isTaggedError(e)&&e._tag==="TimeoutError"}function O(e){return t.isTaggedError(e)&&e._tag==="RetryExhaustedError"}function $(e){return t.isTaggedError(e)&&e._tag==="RateLimitError"}function H(e){return t.isTaggedError(e)&&e._tag==="CircuitBreakerOpenError"}function N(e){return t.isTaggedError(e)&&e._tag==="ValidationError"}function A(e){return t.isTaggedError(e)&&e._tag==="NotFoundError"}function B(e){return t.isTaggedError(e)&&e._tag==="UnauthorizedError"}function b(e){return t.isTaggedError(e)&&e._tag==="NetworkError"}function F(e){return t.isTaggedError(e)&&e._tag==="CompensationError"}function K(e){if(!t.isTaggedError(e))return!1;let r=e._tag;return["TimeoutError","RetryExhaustedError","RateLimitError","CircuitBreakerOpenError","ValidationError","NotFoundError","UnauthorizedError","NetworkError","CompensationError"].includes(r)}export{l as CircuitBreakerOpenError,w as CompensationError,k as NetworkError,T as NotFoundError,x as RateLimitError,m as RetryExhaustedError,p as TimeoutError,y as UnauthorizedError,f as ValidationError,K as isAwaitlyError,H as isCircuitBreakerOpenError,F as isCompensationError,b as isNetworkError,A as isNotFoundError,$ as isRateLimitError,O as isRetryExhaustedError,P as isTimeoutError,B as isUnauthorizedError,N as isValidationError,C as makeError};
|
|
2
2
|
//# sourceMappingURL=errors.js.map
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/tagged-error.ts","../src/errors.ts"],"sourcesContent":["/**\n * awaitly/tagged-error\n *\n * Factory for creating tagged error types with exhaustive pattern matching.\n * Enables TypeScript to enforce that all error variants are handled.\n *\n * @example\n * ```typescript\n * // Define error types (Props via generic)\n * class NotFoundError extends TaggedError(\"NotFoundError\")<{\n * id: string;\n * resource: string;\n * }> {}\n *\n * // Define with type-safe message (Props inferred from callback annotation)\n * class ValidationError extends TaggedError(\"ValidationError\", {\n * message: (p: { field: string; reason: string }) => `Invalid ${p.field}: ${p.reason}`,\n * }) {}\n *\n * // Create instances\n * const error = new NotFoundError({ id: \"123\", resource: \"User\" });\n *\n * // Runtime type check: instanceof TaggedError works!\n * console.log(error instanceof TaggedError); // true\n *\n * // Exhaustive matching\n * type AppError = NotFoundError | ValidationError;\n * const message = TaggedError.match(error as AppError, {\n * NotFoundError: (e) => `Missing: ${e.resource} ${e.id}`,\n * ValidationError: (e) => `Invalid ${e.field}: ${e.reason}`,\n * });\n * ```\n */\n\n/**\n * Options for Error constructor (compatible with ES2022 ErrorOptions).\n */\nexport interface TaggedErrorOptions {\n cause?: unknown;\n}\n\n/**\n * Options for TaggedError factory with type-safe message callback.\n */\nexport interface TaggedErrorCreateOptions<Props extends Record<string, unknown>> {\n /** Custom message generator from props. Annotate parameter for type safety. */\n message: (props: Props) => string;\n}\n\n/**\n * Base interface for all tagged errors.\n */\nexport interface TaggedErrorBase extends Error {\n readonly _tag: string;\n}\n\n/**\n * Internal base class for instanceof checks.\n * All TaggedError-created classes extend this.\n * @internal\n */\nclass InternalTaggedErrorBase extends Error implements TaggedErrorBase {\n readonly _tag!: string;\n}\n\n/**\n * Instance type for factory-created TaggedErrors.\n */\ntype TaggedErrorInstance<Tag extends string, Props> = TaggedErrorBase & {\n readonly _tag: Tag;\n} & Readonly<Props>;\n\n/**\n * Constructor args type - conditionally optional based on whether Props has required fields.\n * - If Props is empty or all properties are optional: props argument is optional\n * - If Props has any required properties: props argument is required\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\ntype ConstructorArgs<Props extends Record<string, unknown>> = {} extends Props\n ? [props?: Props | void, options?: TaggedErrorOptions]\n : [props: Props, options?: TaggedErrorOptions];\n\n/**\n * Constructor type returned by TaggedError factory.\n */\nexport interface TaggedErrorConstructor<\n Tag extends string,\n Props extends Record<string, unknown>,\n> {\n new (...args: ConstructorArgs<Props>): TaggedErrorInstance<Tag, Props>;\n readonly prototype: TaggedErrorInstance<Tag, Props>;\n}\n\n/**\n * Generic class factory type that allows `<Props>` parameterization.\n * This enables the Effect.js-style syntax: `class X extends TaggedError(\"X\")<Props> {}`\n * @internal\n */\nexport interface TaggedErrorClassFactory<Tag extends string> {\n new <Props extends Record<string, unknown> = Record<string, never>>(\n ...args: ConstructorArgs<Props>\n ): TaggedErrorInstance<Tag, Props>;\n}\n\n/**\n * Helper type to extract return type from a function type.\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype FnReturnType<T> = T extends (...args: any[]) => infer R ? R : never;\n\n/**\n * Helper type to get union of return types from all handlers.\n * @internal\n */\ntype HandlersReturnType<H> = { [K in keyof H]: FnReturnType<H[K]> }[keyof H];\n\n/**\n * Helper type to extract keys whose values are definitely functions (not undefined).\n * Only excludes a tag from the fallback type if its handler is guaranteed to be\n * a function. Keys where the value type includes undefined are NOT excluded,\n * ensuring type safety with dynamic/conditional handlers.\n * @internal\n */\ntype DefinitelyHandledKeys<H> = {\n [K in keyof H]-?: undefined extends H[K] ? never : K;\n}[keyof H];\n\n/**\n * Factory function to create tagged error classes.\n *\n * Two usage patterns:\n *\n * 1. **Props via generic** (default message is tag name):\n * ```typescript\n * class NotFoundError extends TaggedError(\"NotFoundError\")<{ id: string }> {}\n * ```\n *\n * 2. **Props inferred from message callback** (type-safe message):\n * ```typescript\n * class NotFoundError extends TaggedError(\"NotFoundError\", {\n * message: (p: { id: string }) => `Not found: ${p.id}`,\n * }) {}\n * ```\n *\n * Both support `instanceof TaggedError` checks at runtime.\n *\n * @param tag - The unique tag string for this error type\n * @param options - Optional configuration with message generator (annotate param for type safety)\n * @returns A class constructor that can be extended\n */\n\n// Overload 1: No options - use <Props> generic syntax, default message is tag\nfunction TaggedError<Tag extends string>(\n tag: Tag\n): TaggedErrorClassFactory<Tag>;\n\n// Overload 2: With message option - Props inferred from callback parameter annotation\nfunction TaggedError<Tag extends string, Props extends Record<string, unknown>>(\n tag: Tag,\n options: TaggedErrorCreateOptions<Props>\n): TaggedErrorConstructor<Tag, Props>;\n\n// Implementation\nfunction TaggedError<Tag extends string, Props extends Record<string, unknown>>(\n tag: Tag,\n options?: TaggedErrorCreateOptions<Props>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): any {\n return class extends InternalTaggedErrorBase {\n override readonly _tag: Tag = tag;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(props?: any, errorOptions?: TaggedErrorOptions) {\n // Generate message: call callback if provided (even for prop-less errors), else use tag\n const message = options?.message ? options.message(props ?? {}) : tag;\n\n super(message);\n this.name = tag;\n\n // Maintains proper prototype chain for instanceof checks\n Object.setPrototypeOf(this, new.target.prototype);\n\n // Assign props to instance, stripping reserved keys:\n // - _tag: discriminant for pattern matching (cannot be forged)\n // - name, message, stack: Error internals (preserve for logging/debugging)\n // Note: 'cause' is allowed as a user prop (common for domain errors)\n if (props && typeof props === \"object\") {\n const {\n _tag: _,\n name: _n,\n message: _m,\n stack: _s,\n ...safeProps\n } = props;\n\n const hasUserCause = Object.prototype.hasOwnProperty.call(\n safeProps,\n \"cause\"\n );\n const userCause = hasUserCause\n ? (safeProps as { cause?: unknown }).cause\n : undefined;\n if (hasUserCause) {\n delete (safeProps as { cause?: unknown }).cause;\n }\n\n const hasOptionsCause = errorOptions?.cause !== undefined;\n if (hasUserCause && hasOptionsCause) {\n throw new TypeError(\n \"TaggedError: cannot provide 'cause' in props when also setting ErrorOptions.cause\"\n );\n }\n\n Object.assign(this, safeProps);\n\n if (hasUserCause) {\n (this as { cause?: unknown }).cause = userCause;\n }\n if (hasOptionsCause) {\n (this as { cause?: unknown }).cause = errorOptions?.cause;\n }\n } else if (errorOptions?.cause !== undefined) {\n (this as { cause?: unknown }).cause = errorOptions.cause;\n }\n }\n };\n}\n\n// Add Symbol.hasInstance so `instanceof TaggedError` works\nObject.defineProperty(TaggedError, Symbol.hasInstance, {\n value: (instance: unknown): boolean => instance instanceof InternalTaggedErrorBase,\n});\n\n/**\n * Namespace for static methods on TaggedError.\n */\n// eslint-disable-next-line @typescript-eslint/no-namespace\nnamespace TaggedError {\n /**\n * Type guard to check if a value is an Error instance.\n */\n export function isError(value: unknown): value is Error {\n return value instanceof Error;\n }\n\n /**\n * Type guard to check if a value is a TaggedError instance.\n * Uses the same check as `instanceof TaggedError` - only genuine\n * TaggedError instances (created via the factory) pass this guard.\n */\n export function isTaggedError(value: unknown): value is TaggedErrorBase {\n return value instanceof InternalTaggedErrorBase;\n }\n\n /**\n * Exhaustively matches on a tagged error, requiring handlers for all variants.\n *\n * TypeScript will error if any variant in the error union is not handled.\n *\n * @remarks When to use: You want compile-time enforcement that every tagged variant is handled.\n *\n * @param error - The tagged error to match\n * @param handlers - Object mapping _tag values to handler functions\n * @returns The return value of the matched handler\n *\n * @example\n * ```typescript\n * type AppError = NotFoundError | ValidationError;\n *\n * const message = TaggedError.match(error, {\n * NotFoundError: (e) => `Not found: ${e.id}`,\n * ValidationError: (e) => `Invalid: ${e.field}`,\n * });\n * ```\n */\n export function match<\n E extends TaggedErrorBase,\n H extends { [K in E[\"_tag\"]]: (e: Extract<E, { _tag: K }>) => unknown },\n >(error: E, handlers: H): HandlersReturnType<H> {\n const tag = error._tag as E[\"_tag\"];\n const handler = handlers[tag];\n return handler(\n error as Extract<E, { _tag: typeof tag }>\n ) as HandlersReturnType<H>;\n }\n\n /**\n * Partially matches on a tagged error with a fallback for unhandled variants.\n *\n * The fallback receives variants that are NOT definitely handled. A tag is\n * considered \"definitely handled\" only if its handler is a function (not\n * `undefined`). This ensures type safety even with dynamic/conditional handlers:\n *\n * ```typescript\n * const maybeHandle = featureFlag ? (e) => e.id : undefined;\n * TaggedError.matchPartial(\n * error,\n * { NotFoundError: maybeHandle }, // maybeHandle might be undefined\n * (e) => e._tag // e correctly includes NotFoundError\n * );\n * ```\n *\n * @param error - The tagged error to match\n * @param handlers - Partial object mapping _tag values to handler functions\n * @param otherwise - Fallback handler for unmatched variants\n * @returns The return value of the matched handler or fallback\n *\n * @example\n * ```typescript\n * const message = TaggedError.matchPartial(\n * error,\n * { NotFoundError: (e) => `Not found: ${e.id}` },\n * (e) => `Other error: ${e.message}`\n * );\n * ```\n */\n export function matchPartial<\n E extends TaggedErrorBase,\n H extends Partial<{\n [K in E[\"_tag\"]]: (e: Extract<E, { _tag: K }>) => unknown;\n }>,\n T,\n >(\n error: E,\n handlers: H,\n otherwise: (e: Exclude<E, { _tag: DefinitelyHandledKeys<H> }>) => T\n ): HandlersReturnType<H> | T {\n const tag = error._tag as E[\"_tag\"];\n const handler = handlers[tag];\n if (handler) {\n return handler(\n error as Extract<E, { _tag: typeof tag }>\n ) as HandlersReturnType<H>;\n }\n return otherwise(error as Exclude<E, { _tag: DefinitelyHandledKeys<H> }>);\n }\n}\n\nexport { TaggedError };\n\n/**\n * Helper type to extract the _tag literal type from a TaggedError.\n *\n * @example\n * ```typescript\n * class MyError extends TaggedError(\"MyError\")<{ id: string }> {}\n * type Tag = TagOf<MyError>; // \"MyError\"\n * ```\n */\nexport type TagOf<E extends TaggedErrorBase> = E[\"_tag\"];\n\n/**\n * Helper type to extract a specific variant from a TaggedError union by tag.\n *\n * @example\n * ```typescript\n * type AppError = NotFoundError | ValidationError;\n * type NotFound = ErrorByTag<AppError, \"NotFoundError\">; // NotFoundError\n * ```\n */\nexport type ErrorByTag<\n E extends TaggedErrorBase,\n Tag extends E[\"_tag\"],\n> = Extract<E, { _tag: Tag }>;\n\n/**\n * Reserved keys that are stripped from user props at runtime.\n * These keys cannot be used as user-defined properties:\n * - _tag: discriminant for pattern matching\n * - name, message, stack: Error internals (preserved for logging/debugging)\n *\n * Note: 'cause' is NOT reserved - it can be used as a user prop.\n */\ntype ReservedErrorKeys = \"_tag\" | \"name\" | \"message\" | \"stack\";\n\n/**\n * Helper type to extract props from a TaggedError.\n * Excludes reserved keys that are stripped at runtime.\n *\n * @example\n * ```typescript\n * class MyError extends TaggedError(\"MyError\")<{ id: string }> {}\n * type Props = PropsOf<MyError>; // { id: string }\n *\n * // 'cause' is allowed as a user prop\n * class DomainError extends TaggedError(\"DomainError\")<{ cause: { field: string } }> {}\n * type DomainProps = PropsOf<DomainError>; // { cause: { field: string } }\n * ```\n */\nexport type PropsOf<E extends TaggedErrorBase> = Omit<E, ReservedErrorKeys>;\n","/**\n * awaitly/errors\n *\n * Pre-built error types for common failure scenarios.\n * Uses TaggedError for type-safe exhaustive matching.\n *\n * @example\n * ```typescript\n * import { TimeoutError, RetryExhaustedError, RateLimitError, CircuitOpenError } from 'awaitly/errors';\n *\n * // Create errors\n * const timeout = new TimeoutError({ operation: 'fetchUser', ms: 5000 });\n * const retryFailed = new RetryExhaustedError({ operation: 'sendEmail', attempts: 3 });\n *\n * // Pattern match\n * TaggedError.match(error, {\n * TimeoutError: (e) => `${e.operation} timed out after ${e.ms}ms`,\n * RetryExhaustedError: (e) => `${e.operation} failed after ${e.attempts} attempts`,\n * RateLimitError: (e) => `Rate limit exceeded, retry after ${e.retryAfterMs}ms`,\n * CircuitOpenError: (e) => `Circuit ${e.circuitName} is open`,\n * });\n * ```\n */\n\nimport { TaggedError } from \"./tagged-error\";\n\n// =============================================================================\n// Error Factory\n// =============================================================================\n\n/**\n * Factory function to create tagged error classes with default values.\n *\n * This is a convenience wrapper around TaggedError that allows specifying\n * default property values for error types.\n *\n * @example\n * ```typescript\n * // Define custom error with defaults\n * const NetworkError = makeError('NetworkError', {\n * defaults: { retryable: true },\n * message: (p) => `Network error: ${p.reason}`,\n * });\n *\n * class MyNetworkError extends NetworkError<{ reason: string; code?: number }> {}\n *\n * const error = new MyNetworkError({ reason: 'Connection refused' });\n * // error.retryable === true (from defaults)\n * ```\n */\nexport function makeError<Tag extends string>(\n tag: Tag,\n options?: {\n message?: (props: Record<string, unknown>) => string;\n defaults?: Record<string, unknown>;\n }\n) {\n const messageGenerator = options?.message ?? (() => tag);\n const defaults = options?.defaults ?? {};\n\n // Create base class using TaggedError\n const BaseClass = TaggedError(tag, {\n message: (props: Record<string, unknown>) =>\n messageGenerator({ ...defaults, ...props }),\n });\n\n // Return a factory that applies defaults\n return class extends BaseClass {\n constructor(props?: Record<string, unknown>) {\n super({ ...defaults, ...props } as Record<string, unknown>);\n // Apply defaults to instance\n Object.assign(this, { ...defaults, ...props });\n }\n };\n}\n\n// =============================================================================\n// Pre-built Error Types\n// =============================================================================\n\n/**\n * Error thrown when an operation times out.\n *\n * @example\n * ```typescript\n * const error = new TimeoutError({\n * operation: 'fetchUser',\n * ms: 5000,\n * });\n * console.log(error.message); // \"TimeoutError: fetchUser timed out after 5000ms\"\n * ```\n */\nexport class TimeoutError extends TaggedError(\"TimeoutError\", {\n message: (p: {\n /** Name of the operation that timed out */\n operation?: string;\n /** Timeout duration in milliseconds */\n ms: number;\n }) =>\n p.operation\n ? `TimeoutError: ${p.operation} timed out after ${p.ms}ms`\n : `TimeoutError: Operation timed out after ${p.ms}ms`,\n}) {}\n\n/**\n * Error thrown when all retry attempts are exhausted.\n *\n * @example\n * ```typescript\n * const error = new RetryExhaustedError({\n * operation: 'sendEmail',\n * attempts: 3,\n * lastError: originalError,\n * });\n * console.log(error.message); // \"RetryExhaustedError: sendEmail failed after 3 attempts\"\n * ```\n */\nexport class RetryExhaustedError extends TaggedError(\"RetryExhaustedError\", {\n message: (p: {\n /** Name of the operation that failed */\n operation?: string;\n /** Total number of retry attempts made */\n attempts: number;\n /** The last error encountered before giving up */\n lastError?: unknown;\n }) =>\n p.operation\n ? `RetryExhaustedError: ${p.operation} failed after ${p.attempts} attempts`\n : `RetryExhaustedError: Operation failed after ${p.attempts} attempts`,\n}) {}\n\n/**\n * Error thrown when a rate limit is exceeded.\n *\n * @example\n * ```typescript\n * const error = new RateLimitError({\n * limiterName: 'api-calls',\n * retryAfterMs: 1000,\n * });\n * console.log(error.message); // \"RateLimitError: Rate limit exceeded for api-calls\"\n * ```\n */\nexport class RateLimitError extends TaggedError(\"RateLimitError\", {\n message: (p: {\n /** Name of the rate limiter that was exceeded */\n limiterName?: string;\n /** Time in milliseconds until the rate limit resets */\n retryAfterMs?: number;\n }) =>\n p.limiterName\n ? `RateLimitError: Rate limit exceeded for ${p.limiterName}${p.retryAfterMs ? `, retry after ${p.retryAfterMs}ms` : \"\"}`\n : `RateLimitError: Rate limit exceeded${p.retryAfterMs ? `, retry after ${p.retryAfterMs}ms` : \"\"}`,\n}) {}\n\n/**\n * Error thrown when a circuit breaker is open.\n *\n * @example\n * ```typescript\n * const error = new CircuitBreakerOpenError({\n * circuitName: 'payment-api',\n * state: 'OPEN',\n * retryAfterMs: 30000,\n * });\n * console.log(error.message); // \"CircuitBreakerOpenError: Circuit payment-api is OPEN\"\n * ```\n */\nexport class CircuitBreakerOpenError extends TaggedError(\n \"CircuitBreakerOpenError\",\n {\n message: (p: {\n /** Name of the circuit breaker */\n circuitName: string;\n /** Current state of the circuit */\n state?: \"OPEN\" | \"HALF_OPEN\";\n /** Time in milliseconds until the circuit may close */\n retryAfterMs?: number;\n }) =>\n `CircuitBreakerOpenError: Circuit ${p.circuitName} is ${p.state ?? \"OPEN\"}${p.retryAfterMs ? `, retry after ${Math.ceil(p.retryAfterMs / 1000)}s` : \"\"}`,\n }\n) {}\n\n/**\n * Error thrown when validation fails.\n *\n * @example\n * ```typescript\n * const error = new ValidationError({\n * field: 'email',\n * reason: 'Invalid email format',\n * });\n * console.log(error.message); // \"ValidationError: Invalid email - Invalid email format\"\n * ```\n */\nexport class ValidationError extends TaggedError(\"ValidationError\", {\n message: (p: {\n /** Field that failed validation */\n field: string;\n /** Reason for validation failure */\n reason: string;\n /** Raw value that failed validation */\n value?: unknown;\n }) => `ValidationError: Invalid ${p.field} - ${p.reason}`,\n}) {}\n\n/**\n * Error thrown when a resource is not found.\n *\n * @example\n * ```typescript\n * const error = new NotFoundError({\n * resource: 'User',\n * id: '123',\n * });\n * console.log(error.message); // \"NotFoundError: User with id 123 not found\"\n * ```\n */\nexport class NotFoundError extends TaggedError(\"NotFoundError\", {\n message: (p: {\n /** Type of resource that was not found */\n resource: string;\n /** Identifier of the missing resource */\n id?: string;\n }) =>\n p.id\n ? `NotFoundError: ${p.resource} with id ${p.id} not found`\n : `NotFoundError: ${p.resource} not found`,\n}) {}\n\n/**\n * Error thrown when access is denied.\n *\n * @example\n * ```typescript\n * const error = new UnauthorizedError({\n * action: 'delete',\n * resource: 'User',\n * });\n * console.log(error.message); // \"UnauthorizedError: Not authorized to delete User\"\n * ```\n */\nexport class UnauthorizedError extends TaggedError(\"UnauthorizedError\", {\n message: (p: {\n /** Action that was attempted */\n action?: string;\n /** Resource that was being accessed */\n resource?: string;\n /** Reason for denial */\n reason?: string;\n }) =>\n p.reason\n ? `UnauthorizedError: ${p.reason}`\n : p.action && p.resource\n ? `UnauthorizedError: Not authorized to ${p.action} ${p.resource}`\n : \"UnauthorizedError: Access denied\",\n}) {}\n\n/**\n * Error thrown for network-related failures.\n *\n * @example\n * ```typescript\n * const error = new NetworkError({\n * url: 'https://api.example.com/users',\n * reason: 'Connection refused',\n * retryable: true,\n * });\n * ```\n */\nexport class NetworkError extends TaggedError(\"NetworkError\", {\n message: (p: {\n /** URL that was being accessed */\n url?: string;\n /** Reason for the network failure */\n reason: string;\n /** Whether this error is retryable */\n retryable?: boolean;\n /** HTTP status code if applicable */\n statusCode?: number;\n }) =>\n p.url\n ? `NetworkError: ${p.reason} (${p.url})`\n : `NetworkError: ${p.reason}`,\n}) {}\n\n/**\n * Error thrown when a saga compensation fails.\n *\n * @example\n * ```typescript\n * const error = new CompensationError({\n * step: 'chargeCard',\n * originalError: paymentError,\n * compensationError: refundError,\n * });\n * ```\n */\nexport class CompensationError extends TaggedError(\"CompensationError\", {\n message: (p: {\n /** Step that triggered compensation */\n step: string;\n /** The original error that caused compensation */\n originalError?: unknown;\n /** Error that occurred during compensation */\n compensationError?: unknown;\n }) => `CompensationError: Failed to compensate step ${p.step}`,\n}) {}\n\n// =============================================================================\n// Union Type for Common Errors\n// =============================================================================\n\n/**\n * Union of all pre-built error types.\n * Useful for exhaustive pattern matching.\n *\n * @example\n * ```typescript\n * function handleError(error: AwaitlyError): string {\n * return TaggedError.match(error, {\n * TimeoutError: (e) => `Timeout: ${e.ms}ms`,\n * RetryExhaustedError: (e) => `Retries: ${e.attempts}`,\n * RateLimitError: (e) => `Rate limited`,\n * CircuitBreakerOpenError: (e) => `Circuit open: ${e.circuitName}`,\n * ValidationError: (e) => `Invalid: ${e.field}`,\n * NotFoundError: (e) => `Not found: ${e.resource}`,\n * UnauthorizedError: (e) => `Unauthorized`,\n * NetworkError: (e) => `Network: ${e.reason}`,\n * CompensationError: (e) => `Compensation failed: ${e.step}`,\n * });\n * }\n * ```\n */\nexport type AwaitlyError =\n | TimeoutError\n | RetryExhaustedError\n | RateLimitError\n | CircuitBreakerOpenError\n | ValidationError\n | NotFoundError\n | UnauthorizedError\n | NetworkError\n | CompensationError;\n\n// =============================================================================\n// Type Guards\n// =============================================================================\n\n/**\n * Check if an error is a TimeoutError.\n */\nexport function isTimeoutError(error: unknown): error is TimeoutError {\n return TaggedError.isTaggedError(error) && error._tag === \"TimeoutError\";\n}\n\n/**\n * Check if an error is a RetryExhaustedError.\n */\nexport function isRetryExhaustedError(\n error: unknown\n): error is RetryExhaustedError {\n return (\n TaggedError.isTaggedError(error) && error._tag === \"RetryExhaustedError\"\n );\n}\n\n/**\n * Check if an error is a RateLimitError.\n */\nexport function isRateLimitError(error: unknown): error is RateLimitError {\n return TaggedError.isTaggedError(error) && error._tag === \"RateLimitError\";\n}\n\n/**\n * Check if an error is a CircuitBreakerOpenError.\n */\nexport function isCircuitBreakerOpenError(\n error: unknown\n): error is CircuitBreakerOpenError {\n return (\n TaggedError.isTaggedError(error) && error._tag === \"CircuitBreakerOpenError\"\n );\n}\n\n/**\n * Check if an error is a ValidationError.\n */\nexport function isValidationError(error: unknown): error is ValidationError {\n return TaggedError.isTaggedError(error) && error._tag === \"ValidationError\";\n}\n\n/**\n * Check if an error is a NotFoundError.\n */\nexport function isNotFoundError(error: unknown): error is NotFoundError {\n return TaggedError.isTaggedError(error) && error._tag === \"NotFoundError\";\n}\n\n/**\n * Check if an error is an UnauthorizedError.\n */\nexport function isUnauthorizedError(\n error: unknown\n): error is UnauthorizedError {\n return TaggedError.isTaggedError(error) && error._tag === \"UnauthorizedError\";\n}\n\n/**\n * Check if an error is a NetworkError.\n */\nexport function isNetworkError(error: unknown): error is NetworkError {\n return TaggedError.isTaggedError(error) && error._tag === \"NetworkError\";\n}\n\n/**\n * Check if an error is a CompensationError.\n */\nexport function isCompensationError(\n error: unknown\n): error is CompensationError {\n return TaggedError.isTaggedError(error) && error._tag === \"CompensationError\";\n}\n\n/**\n * Check if an error is any AwaitlyError.\n */\nexport function isAwaitlyError(error: unknown): error is AwaitlyError {\n if (!TaggedError.isTaggedError(error)) return false;\n const tag = error._tag;\n return [\n \"TimeoutError\",\n \"RetryExhaustedError\",\n \"RateLimitError\",\n \"CircuitBreakerOpenError\",\n \"ValidationError\",\n \"NotFoundError\",\n \"UnauthorizedError\",\n \"NetworkError\",\n \"CompensationError\",\n ].includes(tag);\n}\n"],"mappings":"AA6DA,IAAMA,EAAN,cAAsC,KAAiC,CAC5D,IACX,EAsGA,SAASC,EACPC,EACAC,EAEK,CACL,OAAO,cAAcH,CAAwB,CACzB,KAAYE,EAG9B,YAAYE,EAAaC,EAAmC,CAE1D,IAAMC,EAAUH,GAAS,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CAKO,SAASO,EAAeP,EAAuC,CACpE,OAAOb,EAAY,cAAca,CAAK,GAAKA,EAAM,OAAS,cAC5D,CAKO,SAASQ,EACdR,EAC4B,CAC5B,OAAOb,EAAY,cAAca,CAAK,GAAKA,EAAM,OAAS,mBAC5D,CAKO,SAASS,EAAeT,EAAuC,CACpE,GAAI,CAACb,EAAY,cAAca,CAAK,EAAG,MAAO,GAC9C,IAAMlB,EAAMkB,EAAM,KAClB,MAAO,CACL,eACA,sBACA,iBACA,0BACA,kBACA,gBACA,oBACA,eACA,mBACF,EAAE,SAASlB,CAAG,CAChB","names":["InternalTaggedErrorBase","TaggedError","tag","options","props","errorOptions","message","_","_n","_m","_s","safeProps","hasUserCause","userCause","hasOptionsCause","instance","isError","value","isTaggedError","match","error","handlers","handler","matchPartial","otherwise","makeError","tag","options","messageGenerator","defaults","BaseClass","TaggedError","props","TimeoutError","p","RetryExhaustedError","RateLimitError","CircuitBreakerOpenError","ValidationError","NotFoundError","UnauthorizedError","NetworkError","CompensationError","isTimeoutError","error","isRetryExhaustedError","isRateLimitError","isCircuitBreakerOpenError","isValidationError","isNotFoundError","isUnauthorizedError","isNetworkError","isCompensationError","isAwaitlyError"]}
|
|
1
|
+
{"version":3,"sources":["../src/tagged-error.ts","../src/errors.ts"],"sourcesContent":["/**\n * awaitly/tagged-error\n *\n * Factory for creating tagged error types with exhaustive pattern matching.\n * Enables TypeScript to enforce that all error variants are handled.\n *\n * @example\n * ```typescript\n * // Define error types (Props via generic)\n * class NotFoundError extends TaggedError(\"NotFoundError\")<{\n * id: string;\n * resource: string;\n * }> {}\n *\n * // Define with type-safe message (Props inferred from callback annotation)\n * class ValidationError extends TaggedError(\"ValidationError\", {\n * message: (p: { field: string; reason: string }) => `Invalid ${p.field}: ${p.reason}`,\n * }) {}\n *\n * // Create instances\n * const error = new NotFoundError({ id: \"123\", resource: \"User\" });\n *\n * // Runtime type check: instanceof TaggedError works!\n * console.log(error instanceof TaggedError); // true\n *\n * // Exhaustive matching\n * type AppError = NotFoundError | ValidationError;\n * const message = TaggedError.match(error as AppError, {\n * NotFoundError: (e) => `Missing: ${e.resource} ${e.id}`,\n * ValidationError: (e) => `Invalid ${e.field}: ${e.reason}`,\n * });\n * ```\n */\n\n/**\n * Options for Error constructor (compatible with ES2022 ErrorOptions).\n */\nexport interface TaggedErrorOptions {\n cause?: unknown;\n}\n\n/**\n * Options for TaggedError factory with type-safe message callback.\n */\nexport interface TaggedErrorCreateOptions<Props extends Record<string, unknown>> {\n /** Custom message generator from props. Annotate parameter for type safety. */\n message: (props: Props) => string;\n}\n\n/**\n * Base interface for all tagged errors.\n */\nexport interface TaggedErrorBase extends Error {\n readonly _tag: string;\n}\n\n/**\n * Internal base class for instanceof checks.\n * All TaggedError-created classes extend this.\n * @internal\n */\nclass InternalTaggedErrorBase extends Error implements TaggedErrorBase {\n readonly _tag!: string;\n}\n\n/**\n * Instance type for factory-created TaggedErrors.\n */\ntype TaggedErrorInstance<Tag extends string, Props> = TaggedErrorBase & {\n readonly _tag: Tag;\n} & Readonly<Props>;\n\n/**\n * Constructor args type - conditionally optional based on whether Props has required fields.\n * - If Props is empty or all properties are optional: props argument is optional\n * - If Props has any required properties: props argument is required\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\ntype ConstructorArgs<Props extends Record<string, unknown>> = {} extends Props\n ? [props?: Props | void, options?: TaggedErrorOptions]\n : [props: Props, options?: TaggedErrorOptions];\n\n/**\n * Constructor type returned by TaggedError factory.\n */\nexport interface TaggedErrorConstructor<\n Tag extends string,\n Props extends Record<string, unknown>,\n> {\n new (...args: ConstructorArgs<Props>): TaggedErrorInstance<Tag, Props>;\n readonly prototype: TaggedErrorInstance<Tag, Props>;\n}\n\n/**\n * Generic class factory type that allows `<Props>` parameterization.\n * This enables the Effect.js-style syntax: `class X extends TaggedError(\"X\")<Props> {}`\n * @internal\n */\nexport interface TaggedErrorClassFactory<Tag extends string> {\n new <Props extends Record<string, unknown> = Record<string, never>>(\n ...args: ConstructorArgs<Props>\n ): TaggedErrorInstance<Tag, Props>;\n}\n\n/**\n * Helper type to extract return type from a function type.\n * @internal\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype FnReturnType<T> = T extends (...args: any[]) => infer R ? R : never;\n\n/**\n * Helper type to get union of return types from all handlers.\n * @internal\n */\ntype HandlersReturnType<H> = { [K in keyof H]: FnReturnType<H[K]> }[keyof H];\n\n/**\n * Helper type to extract keys whose values are definitely functions (not undefined).\n * Only excludes a tag from the fallback type if its handler is guaranteed to be\n * a function. Keys where the value type includes undefined are NOT excluded,\n * ensuring type safety with dynamic/conditional handlers.\n * @internal\n */\ntype DefinitelyHandledKeys<H> = {\n [K in keyof H]-?: undefined extends H[K] ? never : K;\n}[keyof H];\n\n/**\n * Factory function to create tagged error classes.\n *\n * Two usage patterns:\n *\n * 1. **Props via generic** (default message is tag name):\n * ```typescript\n * class NotFoundError extends TaggedError(\"NotFoundError\")<{ id: string }> {}\n * ```\n *\n * 2. **Props inferred from message callback** (type-safe message):\n * ```typescript\n * class NotFoundError extends TaggedError(\"NotFoundError\", {\n * message: (p: { id: string }) => `Not found: ${p.id}`,\n * }) {}\n * ```\n *\n * Both support `instanceof TaggedError` checks at runtime.\n *\n * @param tag - The unique tag string for this error type\n * @param options - Optional configuration with message generator (annotate param for type safety)\n * @returns A class constructor that can be extended\n */\n\n// Overload 1: No options - use <Props> generic syntax, default message is tag\nfunction TaggedError<Tag extends string>(\n tag: Tag\n): TaggedErrorClassFactory<Tag>;\n\n// Overload 2: With message option - Props inferred from callback parameter annotation\nfunction TaggedError<Tag extends string, Props extends Record<string, unknown>>(\n tag: Tag,\n options: TaggedErrorCreateOptions<Props>\n): TaggedErrorConstructor<Tag, Props>;\n\n// Implementation\nfunction TaggedError<Tag extends string, Props extends Record<string, unknown>>(\n tag: Tag,\n options?: TaggedErrorCreateOptions<Props>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): any {\n return class extends InternalTaggedErrorBase {\n override readonly _tag: Tag = tag;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(props?: any, errorOptions?: TaggedErrorOptions) {\n // Generate message: call callback if provided (even for prop-less errors), else use tag\n const message = options?.message ? options.message(props ?? {}) : tag;\n\n super(message);\n this.name = tag;\n\n // Maintains proper prototype chain for instanceof checks\n Object.setPrototypeOf(this, new.target.prototype);\n\n // Assign props to instance, stripping reserved keys:\n // - _tag: discriminant for pattern matching (cannot be forged)\n // - name, message, stack: Error internals (preserve for logging/debugging)\n // Note: 'cause' is allowed as a user prop (common for domain errors)\n if (props && typeof props === \"object\") {\n const {\n _tag: _,\n name: _n,\n message: _m,\n stack: _s,\n ...safeProps\n } = props;\n\n const hasUserCause = Object.prototype.hasOwnProperty.call(\n safeProps,\n \"cause\"\n );\n const userCause = hasUserCause\n ? (safeProps as { cause?: unknown }).cause\n : undefined;\n if (hasUserCause) {\n delete (safeProps as { cause?: unknown }).cause;\n }\n\n const hasOptionsCause = errorOptions?.cause !== undefined;\n if (hasUserCause && hasOptionsCause) {\n throw new TypeError(\n \"TaggedError: cannot provide 'cause' in props when also setting ErrorOptions.cause\"\n );\n }\n\n Object.assign(this, safeProps);\n\n if (hasUserCause) {\n (this as { cause?: unknown }).cause = userCause;\n }\n if (hasOptionsCause) {\n (this as { cause?: unknown }).cause = errorOptions?.cause;\n }\n } else if (errorOptions?.cause !== undefined) {\n (this as { cause?: unknown }).cause = errorOptions.cause;\n }\n }\n };\n}\n\n// Add Symbol.hasInstance so `instanceof TaggedError` works\nObject.defineProperty(TaggedError, Symbol.hasInstance, {\n value: (instance: unknown): boolean => instance instanceof InternalTaggedErrorBase,\n});\n\n/**\n * Namespace for static methods on TaggedError.\n */\n// eslint-disable-next-line @typescript-eslint/no-namespace\nnamespace TaggedError {\n /**\n * Type guard to check if a value is an Error instance.\n */\n export function isError(value: unknown): value is Error {\n return value instanceof Error;\n }\n\n /**\n * Type guard to check if a value is a TaggedError instance.\n * Uses the same check as `instanceof TaggedError` - only genuine\n * TaggedError instances (created via the factory) pass this guard.\n */\n export function isTaggedError(value: unknown): value is TaggedErrorBase {\n return value instanceof InternalTaggedErrorBase;\n }\n\n /**\n * Exhaustively matches on a tagged error, requiring handlers for all variants.\n *\n * TypeScript will error if any variant in the error union is not handled.\n *\n * @remarks When to use: You want compile-time enforcement that every tagged variant is handled.\n *\n * @param error - The tagged error to match\n * @param handlers - Object mapping _tag values to handler functions\n * @returns The return value of the matched handler\n *\n * @example\n * ```typescript\n * type AppError = NotFoundError | ValidationError;\n *\n * const message = TaggedError.match(error, {\n * NotFoundError: (e) => `Not found: ${e.id}`,\n * ValidationError: (e) => `Invalid: ${e.field}`,\n * });\n * ```\n */\n export function match<\n E extends TaggedErrorBase,\n H extends { [K in E[\"_tag\"]]: (e: Extract<E, { _tag: K }>) => unknown },\n >(error: E, handlers: H): HandlersReturnType<H> {\n const tag = error._tag as E[\"_tag\"];\n const handler = handlers[tag];\n return handler(\n error as Extract<E, { _tag: typeof tag }>\n ) as HandlersReturnType<H>;\n }\n\n /**\n * Partially matches on a tagged error with a fallback for unhandled variants.\n *\n * The fallback receives variants that are NOT definitely handled. A tag is\n * considered \"definitely handled\" only if its handler is a function (not\n * `undefined`). This ensures type safety even with dynamic/conditional handlers:\n *\n * ```typescript\n * const maybeHandle = featureFlag ? (e) => e.id : undefined;\n * TaggedError.matchPartial(\n * error,\n * { NotFoundError: maybeHandle }, // maybeHandle might be undefined\n * (e) => e._tag // e correctly includes NotFoundError\n * );\n * ```\n *\n * @param error - The tagged error to match\n * @param handlers - Partial object mapping _tag values to handler functions\n * @param otherwise - Fallback handler for unmatched variants\n * @returns The return value of the matched handler or fallback\n *\n * @example\n * ```typescript\n * const message = TaggedError.matchPartial(\n * error,\n * { NotFoundError: (e) => `Not found: ${e.id}` },\n * (e) => `Other error: ${e.message}`\n * );\n * ```\n */\n export function matchPartial<\n E extends TaggedErrorBase,\n H extends Partial<{\n [K in E[\"_tag\"]]: (e: Extract<E, { _tag: K }>) => unknown;\n }>,\n T,\n >(\n error: E,\n handlers: H,\n otherwise: (e: Exclude<E, { _tag: DefinitelyHandledKeys<H> }>) => T\n ): HandlersReturnType<H> | T {\n const tag = error._tag as E[\"_tag\"];\n const handler = handlers[tag];\n if (handler) {\n return handler(\n error as Extract<E, { _tag: typeof tag }>\n ) as HandlersReturnType<H>;\n }\n return otherwise(error as Exclude<E, { _tag: DefinitelyHandledKeys<H> }>);\n }\n}\n\nexport { TaggedError };\n\n/**\n * Helper type to extract the _tag literal type from a TaggedError.\n *\n * @example\n * ```typescript\n * class MyError extends TaggedError(\"MyError\")<{ id: string }> {}\n * type Tag = TagOf<MyError>; // \"MyError\"\n * ```\n */\nexport type TagOf<E extends TaggedErrorBase> = E[\"_tag\"];\n\n/**\n * Helper type to extract a specific variant from a TaggedError union by tag.\n *\n * @example\n * ```typescript\n * type AppError = NotFoundError | ValidationError;\n * type NotFound = ErrorByTag<AppError, \"NotFoundError\">; // NotFoundError\n * ```\n */\nexport type ErrorByTag<\n E extends TaggedErrorBase,\n Tag extends E[\"_tag\"],\n> = Extract<E, { _tag: Tag }>;\n\n/**\n * Reserved keys that are stripped from user props at runtime.\n * These keys cannot be used as user-defined properties:\n * - _tag: discriminant for pattern matching\n * - name, message, stack: Error internals (preserved for logging/debugging)\n *\n * Note: 'cause' is NOT reserved - it can be used as a user prop.\n */\ntype ReservedErrorKeys = \"_tag\" | \"name\" | \"message\" | \"stack\";\n\n/**\n * Helper type to extract props from a TaggedError.\n * Excludes reserved keys that are stripped at runtime.\n *\n * @example\n * ```typescript\n * class MyError extends TaggedError(\"MyError\")<{ id: string }> {}\n * type Props = PropsOf<MyError>; // { id: string }\n *\n * // 'cause' is allowed as a user prop\n * class DomainError extends TaggedError(\"DomainError\")<{ cause: { field: string } }> {}\n * type DomainProps = PropsOf<DomainError>; // { cause: { field: string } }\n * ```\n */\nexport type PropsOf<E extends TaggedErrorBase> = Omit<E, ReservedErrorKeys>;\n","/**\n * awaitly/errors\n *\n * Pre-built error types for common failure scenarios.\n * Uses TaggedError for type-safe exhaustive matching.\n *\n * @example\n * ```typescript\n * import { TimeoutError, RetryExhaustedError, RateLimitError, CircuitOpenError } from 'awaitly/errors';\n *\n * // Create errors\n * const timeout = new TimeoutError({ operation: 'fetchUser', ms: 5000 });\n * const retryFailed = new RetryExhaustedError({ operation: 'sendEmail', attempts: 3 });\n *\n * // Pattern match\n * TaggedError.match(error, {\n * TimeoutError: (e) => `${e.operation} timed out after ${e.ms}ms`,\n * RetryExhaustedError: (e) => `${e.operation} failed after ${e.attempts} attempts`,\n * RateLimitError: (e) => `Rate limit exceeded, retry after ${e.retryAfterMs}ms`,\n * CircuitOpenError: (e) => `Circuit ${e.circuitName} is open`,\n * });\n * ```\n */\n\nimport { TaggedError } from \"./tagged-error\";\n\n// =============================================================================\n// Error Factory\n// =============================================================================\n\n/**\n * Factory function to create tagged error classes with default values.\n *\n * This is a convenience wrapper around TaggedError that allows specifying\n * default property values for error types.\n *\n * @example\n * ```typescript\n * // Define custom error with defaults\n * const NetworkError = makeError('NetworkError', {\n * defaults: { retryable: true },\n * message: (p) => `Network error: ${p.reason}`,\n * });\n *\n * class MyNetworkError extends NetworkError<{ reason: string; code?: number }> {}\n *\n * const error = new MyNetworkError({ reason: 'Connection refused' });\n * // error.retryable === true (from defaults)\n * ```\n */\nexport function makeError<Tag extends string>(\n tag: Tag,\n options?: {\n message?: (props: Record<string, unknown>) => string;\n defaults?: Record<string, unknown>;\n }\n) {\n const messageGenerator = options?.message ?? (() => tag);\n const defaults = options?.defaults ?? {};\n\n // Create base class using TaggedError\n const BaseClass = TaggedError(tag, {\n message: (props: Record<string, unknown>) =>\n messageGenerator({ ...defaults, ...props }),\n });\n\n // Return a factory that applies defaults\n return class extends BaseClass {\n constructor(props?: Record<string, unknown>) {\n super({ ...defaults, ...props } as Record<string, unknown>);\n // Apply defaults to instance\n Object.assign(this, { ...defaults, ...props });\n }\n };\n}\n\n// =============================================================================\n// Pre-built Error Types\n// =============================================================================\n\n/**\n * Error thrown when an operation times out.\n *\n * @example\n * ```typescript\n * const error = new TimeoutError({\n * operation: 'fetchUser',\n * ms: 5000,\n * });\n * console.log(error.message); // \"TimeoutError: fetchUser timed out after 5000ms\"\n * ```\n */\nexport class TimeoutError extends TaggedError(\"TimeoutError\", {\n message: (p: {\n /** Name of the operation that timed out */\n operation?: string;\n /** Timeout duration in milliseconds */\n ms: number;\n }) =>\n p.operation\n ? `TimeoutError: ${p.operation} timed out after ${p.ms}ms`\n : `TimeoutError: Operation timed out after ${p.ms}ms`,\n}) {}\n\n/**\n * Error thrown when all retry attempts are exhausted.\n *\n * @example\n * ```typescript\n * const error = new RetryExhaustedError({\n * operation: 'sendEmail',\n * attempts: 3,\n * lastError: originalError,\n * });\n * console.log(error.message); // \"RetryExhaustedError: sendEmail failed after 3 attempts\"\n * ```\n */\nexport class RetryExhaustedError extends TaggedError(\"RetryExhaustedError\", {\n message: (p: {\n /** Name of the operation that failed */\n operation?: string;\n /** Total number of retry attempts made */\n attempts: number;\n /** The last error encountered before giving up */\n lastError?: unknown;\n }) =>\n p.operation\n ? `RetryExhaustedError: ${p.operation} failed after ${p.attempts} attempts`\n : `RetryExhaustedError: Operation failed after ${p.attempts} attempts`,\n}) {}\n\n/**\n * Error thrown when a rate limit is exceeded.\n *\n * @example\n * ```typescript\n * const error = new RateLimitError({\n * limiterName: 'api-calls',\n * retryAfterMs: 1000,\n * });\n * console.log(error.message); // \"RateLimitError: Rate limit exceeded for api-calls\"\n * ```\n */\nexport class RateLimitError extends TaggedError(\"RateLimitError\", {\n message: (p: {\n /** Name of the rate limiter that was exceeded */\n limiterName?: string;\n /** Time in milliseconds until the rate limit resets */\n retryAfterMs?: number;\n }) =>\n p.limiterName\n ? `RateLimitError: Rate limit exceeded for ${p.limiterName}${p.retryAfterMs ? `, retry after ${p.retryAfterMs}ms` : \"\"}`\n : `RateLimitError: Rate limit exceeded${p.retryAfterMs ? `, retry after ${p.retryAfterMs}ms` : \"\"}`,\n}) {}\n\n/**\n * Error thrown when a circuit breaker is open.\n *\n * @example\n * ```typescript\n * const error = new CircuitBreakerOpenError({\n * circuitName: 'payment-api',\n * state: 'OPEN',\n * retryAfterMs: 30000,\n * });\n * console.log(error.message); // \"CircuitBreakerOpenError: Circuit payment-api is OPEN\"\n * ```\n */\nexport class CircuitBreakerOpenError extends TaggedError(\n \"CircuitBreakerOpenError\",\n {\n message: (p: {\n /** Name of the circuit breaker */\n circuitName: string;\n /** Current state of the circuit */\n state?: \"OPEN\" | \"HALF_OPEN\";\n /** Time in milliseconds until the circuit may close */\n retryAfterMs?: number;\n }) =>\n `CircuitBreakerOpenError: Circuit ${p.circuitName} is ${p.state ?? \"OPEN\"}${p.retryAfterMs ? `, retry after ${Math.ceil(p.retryAfterMs / 1000)}s` : \"\"}`,\n }\n) {}\n\n/**\n * Error thrown when validation fails.\n *\n * @example\n * ```typescript\n * const error = new ValidationError({\n * field: 'email',\n * reason: 'Invalid email format',\n * });\n * console.log(error.message); // \"ValidationError: Invalid email - Invalid email format\"\n * ```\n */\nexport class ValidationError extends TaggedError(\"ValidationError\", {\n message: (p: {\n /** Field that failed validation */\n field: string;\n /** Reason for validation failure */\n reason: string;\n /** Raw value that failed validation */\n value?: unknown;\n }) => `ValidationError: Invalid ${p.field} - ${p.reason}`,\n}) {}\n\n/**\n * Error thrown when a resource is not found.\n *\n * @example\n * ```typescript\n * const error = new NotFoundError({\n * resource: 'User',\n * id: '123',\n * });\n * console.log(error.message); // \"NotFoundError: User with id 123 not found\"\n * ```\n */\nexport class NotFoundError extends TaggedError(\"NotFoundError\", {\n message: (p: {\n /** Type of resource that was not found */\n resource: string;\n /** Identifier of the missing resource */\n id?: string;\n }) =>\n p.id\n ? `NotFoundError: ${p.resource} with id ${p.id} not found`\n : `NotFoundError: ${p.resource} not found`,\n}) {}\n\n/**\n * Error thrown when access is denied.\n *\n * @example\n * ```typescript\n * const error = new UnauthorizedError({\n * action: 'delete',\n * resource: 'User',\n * });\n * console.log(error.message); // \"UnauthorizedError: Not authorized to delete User\"\n * ```\n */\nexport class UnauthorizedError extends TaggedError(\"UnauthorizedError\", {\n message: (p: {\n /** Action that was attempted */\n action?: string;\n /** Resource that was being accessed */\n resource?: string;\n /** Reason for denial */\n reason?: string;\n }) =>\n p.reason\n ? `UnauthorizedError: ${p.reason}`\n : p.action && p.resource\n ? `UnauthorizedError: Not authorized to ${p.action} ${p.resource}`\n : \"UnauthorizedError: Access denied\",\n}) {}\n\n/**\n * Error thrown for network-related failures.\n *\n * @example\n * ```typescript\n * const error = new NetworkError({\n * url: 'https://api.example.com/users',\n * reason: 'Connection refused',\n * retryable: true,\n * });\n * ```\n */\nexport class NetworkError extends TaggedError(\"NetworkError\", {\n message: (p: {\n /** URL that was being accessed */\n url?: string;\n /** Reason for the network failure */\n reason: string;\n /** Whether this error is retryable */\n retryable?: boolean;\n /** HTTP status code if applicable */\n statusCode?: number;\n }) =>\n p.url\n ? `NetworkError: ${p.reason} (${p.url})`\n : `NetworkError: ${p.reason}`,\n}) {}\n\n/**\n * Error thrown when a saga compensation fails.\n *\n * @example\n * ```typescript\n * const error = new CompensationError({\n * step: 'chargeCard',\n * originalError: paymentError,\n * compensationError: refundError,\n * });\n * ```\n */\nexport class CompensationError extends TaggedError(\"CompensationError\", {\n message: (p: {\n /** Step that triggered compensation */\n step: string;\n /** The original error that caused compensation */\n originalError?: unknown;\n /** Error that occurred during compensation */\n compensationError?: unknown;\n }) => `CompensationError: Failed to compensate step ${p.step}`,\n}) {}\n\n// =============================================================================\n// Unexpected Error\n// =============================================================================\n\n/**\n * Default error type for uncaught exceptions and cancellation in workflows.\n * This is the default `U` type when `catchUnexpected` is not provided.\n *\n * @example\n * ```typescript\n * // Automatically used as the default — no need to pass catchUnexpected:\n * const workflow = createWorkflow(\"checkout\", { chargeCard, sendEmail });\n *\n * // Equivalent to:\n * const workflow = createWorkflow(\"checkout\", { chargeCard, sendEmail }, {\n * catchUnexpected: (cause) => new UnexpectedError({ cause }),\n * });\n * ```\n */\nexport class UnexpectedError extends TaggedError(\"UnexpectedError\", {\n message: (p: {\n /** The original thrown value or cancellation error */\n cause?: unknown;\n }) => `UnexpectedError: ${p.cause instanceof Error ? p.cause.message : String(p.cause ?? \"unknown\")}`,\n}) {}\n\n\n// =============================================================================\n// Union Type for Common Errors\n// =============================================================================\n\n/**\n * Union of all pre-built error types.\n * Useful for exhaustive pattern matching.\n *\n * @example\n * ```typescript\n * function handleError(error: AwaitlyError): string {\n * return TaggedError.match(error, {\n * TimeoutError: (e) => `Timeout: ${e.ms}ms`,\n * RetryExhaustedError: (e) => `Retries: ${e.attempts}`,\n * RateLimitError: (e) => `Rate limited`,\n * CircuitBreakerOpenError: (e) => `Circuit open: ${e.circuitName}`,\n * ValidationError: (e) => `Invalid: ${e.field}`,\n * NotFoundError: (e) => `Not found: ${e.resource}`,\n * UnauthorizedError: (e) => `Unauthorized`,\n * NetworkError: (e) => `Network: ${e.reason}`,\n * CompensationError: (e) => `Compensation failed: ${e.step}`,\n * });\n * }\n * ```\n */\nexport type AwaitlyError =\n | TimeoutError\n | RetryExhaustedError\n | RateLimitError\n | CircuitBreakerOpenError\n | ValidationError\n | NotFoundError\n | UnauthorizedError\n | NetworkError\n | CompensationError;\n\n// =============================================================================\n// Type Guards\n// =============================================================================\n\n/**\n * Check if an error is a TimeoutError.\n */\nexport function isTimeoutError(error: unknown): error is TimeoutError {\n return TaggedError.isTaggedError(error) && error._tag === \"TimeoutError\";\n}\n\n/**\n * Check if an error is a RetryExhaustedError.\n */\nexport function isRetryExhaustedError(\n error: unknown\n): error is RetryExhaustedError {\n return (\n TaggedError.isTaggedError(error) && error._tag === \"RetryExhaustedError\"\n );\n}\n\n/**\n * Check if an error is a RateLimitError.\n */\nexport function isRateLimitError(error: unknown): error is RateLimitError {\n return TaggedError.isTaggedError(error) && error._tag === \"RateLimitError\";\n}\n\n/**\n * Check if an error is a CircuitBreakerOpenError.\n */\nexport function isCircuitBreakerOpenError(\n error: unknown\n): error is CircuitBreakerOpenError {\n return (\n TaggedError.isTaggedError(error) && error._tag === \"CircuitBreakerOpenError\"\n );\n}\n\n/**\n * Check if an error is a ValidationError.\n */\nexport function isValidationError(error: unknown): error is ValidationError {\n return TaggedError.isTaggedError(error) && error._tag === \"ValidationError\";\n}\n\n/**\n * Check if an error is a NotFoundError.\n */\nexport function isNotFoundError(error: unknown): error is NotFoundError {\n return TaggedError.isTaggedError(error) && error._tag === \"NotFoundError\";\n}\n\n/**\n * Check if an error is an UnauthorizedError.\n */\nexport function isUnauthorizedError(\n error: unknown\n): error is UnauthorizedError {\n return TaggedError.isTaggedError(error) && error._tag === \"UnauthorizedError\";\n}\n\n/**\n * Check if an error is a NetworkError.\n */\nexport function isNetworkError(error: unknown): error is NetworkError {\n return TaggedError.isTaggedError(error) && error._tag === \"NetworkError\";\n}\n\n/**\n * Check if an error is a CompensationError.\n */\nexport function isCompensationError(\n error: unknown\n): error is CompensationError {\n return TaggedError.isTaggedError(error) && error._tag === \"CompensationError\";\n}\n\n/**\n * Check if an error is any AwaitlyError.\n */\nexport function isAwaitlyError(error: unknown): error is AwaitlyError {\n if (!TaggedError.isTaggedError(error)) return false;\n const tag = error._tag;\n return [\n \"TimeoutError\",\n \"RetryExhaustedError\",\n \"RateLimitError\",\n \"CircuitBreakerOpenError\",\n \"ValidationError\",\n \"NotFoundError\",\n \"UnauthorizedError\",\n \"NetworkError\",\n \"CompensationError\",\n ].includes(tag);\n}\n"],"mappings":"AA6DA,IAAMA,EAAN,cAAsC,KAAiC,CAC5D,IACX,EAsGA,SAASC,EACPC,EACAC,EAEK,CACL,OAAO,cAAcH,CAAwB,CACzB,KAAYE,EAG9B,YAAYE,EAAaC,EAAmC,CAE1D,IAAMC,EAAUH,GAAS,QAAUA,EAAQ,QAAQC,GAAS,CAAC,CAAC,EAAIF,EAYlE,GAVA,MAAMI,CAAO,EACb,KAAK,KAAOJ,EAGZ,OAAO,eAAe,KAAM,WAAW,SAAS,EAM5CE,GAAS,OAAOA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,EAAM,OAAS,mBAC5D,CAKO,SAASO,EAAeP,EAAuC,CACpE,OAAOd,EAAY,cAAcc,CAAK,GAAKA,EAAM,OAAS,cAC5D,CAKO,SAASQ,EACdR,EAC4B,CAC5B,OAAOd,EAAY,cAAcc,CAAK,GAAKA,EAAM,OAAS,mBAC5D,CAKO,SAASS,EAAeT,EAAuC,CACpE,GAAI,CAACd,EAAY,cAAcc,CAAK,EAAG,MAAO,GAC9C,IAAMnB,EAAMmB,EAAM,KAClB,MAAO,CACL,eACA,sBACA,iBACA,0BACA,kBACA,gBACA,oBACA,eACA,mBACF,EAAE,SAASnB,CAAG,CAChB","names":["InternalTaggedErrorBase","TaggedError","tag","options","props","errorOptions","message","_","_n","_m","_s","safeProps","hasUserCause","userCause","hasOptionsCause","instance","isError","value","isTaggedError","match","error","handlers","handler","matchPartial","otherwise","makeError","tag","options","messageGenerator","defaults","BaseClass","TaggedError","props","TimeoutError","p","RetryExhaustedError","RateLimitError","CircuitBreakerOpenError","ValidationError","NotFoundError","UnauthorizedError","NetworkError","CompensationError","UnexpectedError","isTimeoutError","error","isRetryExhaustedError","isRateLimitError","isCircuitBreakerOpenError","isValidationError","isNotFoundError","isUnauthorizedError","isNetworkError","isCompensationError","isAwaitlyError"]}
|