@distilled.cloud/core 0.0.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/category.d.ts +260 -0
- package/lib/category.d.ts.map +1 -0
- package/lib/category.js +264 -0
- package/lib/category.js.map +1 -0
- package/lib/client.d.ts +123 -0
- package/lib/client.d.ts.map +1 -0
- package/lib/client.js +268 -0
- package/lib/client.js.map +1 -0
- package/lib/errors.d.ts +181 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +122 -0
- package/lib/errors.js.map +1 -0
- package/lib/json-patch.d.ts +44 -0
- package/lib/json-patch.d.ts.map +1 -0
- package/lib/json-patch.js +208 -0
- package/lib/json-patch.js.map +1 -0
- package/lib/pagination.d.ts +74 -0
- package/lib/pagination.d.ts.map +1 -0
- package/lib/pagination.js +130 -0
- package/lib/pagination.js.map +1 -0
- package/lib/retry.d.ts +99 -0
- package/lib/retry.d.ts.map +1 -0
- package/lib/retry.js +106 -0
- package/lib/retry.js.map +1 -0
- package/lib/sensitive.d.ts +50 -0
- package/lib/sensitive.d.ts.map +1 -0
- package/lib/sensitive.js +64 -0
- package/lib/sensitive.js.map +1 -0
- package/lib/traits.d.ts +265 -0
- package/lib/traits.d.ts.map +1 -0
- package/lib/traits.js +470 -0
- package/lib/traits.js.map +1 -0
- package/package.json +66 -5
- package/src/category.ts +406 -0
- package/src/client.ts +511 -0
- package/src/errors.ts +156 -0
- package/src/json-patch.ts +261 -0
- package/src/pagination.ts +222 -0
- package/src/retry.ts +177 -0
- package/src/sensitive.ts +74 -0
- package/src/traits.ts +627 -0
- package/README.md +0 -15
- package/bun.lock +0 -26
- package/index.ts +0 -1
- package/tsconfig.json +0 -29
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error Category System
|
|
3
|
+
*
|
|
4
|
+
* Provides a unified error classification system across all SDKs.
|
|
5
|
+
* Error classes are decorated with categories using `.pipe()` on Schema.TaggedError classes,
|
|
6
|
+
* enabling semantic error handling (e.g., catch all auth errors regardless of provider).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import * as Category from "@distilled.cloud/sdk-core/category";
|
|
11
|
+
*
|
|
12
|
+
* export class Unauthorized extends Schema.TaggedErrorClass<Unauthorized>()(
|
|
13
|
+
* "Unauthorized",
|
|
14
|
+
* { message: Schema.String },
|
|
15
|
+
* ).pipe(Category.withAuthError) {}
|
|
16
|
+
*
|
|
17
|
+
* // Catch by category
|
|
18
|
+
* effect.pipe(Category.catchAuthError((err) => Effect.succeed("handled")))
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
import * as Effect from "effect/Effect";
|
|
22
|
+
export declare const AuthError = "AuthError";
|
|
23
|
+
export declare const BadRequestError = "BadRequestError";
|
|
24
|
+
export declare const ConflictError = "ConflictError";
|
|
25
|
+
export declare const NotFoundError = "NotFoundError";
|
|
26
|
+
export declare const QuotaError = "QuotaError";
|
|
27
|
+
export declare const ServerError = "ServerError";
|
|
28
|
+
export declare const ThrottlingError = "ThrottlingError";
|
|
29
|
+
export declare const NetworkError = "NetworkError";
|
|
30
|
+
export declare const ParseError = "ParseError";
|
|
31
|
+
export declare const ConfigurationError = "ConfigurationError";
|
|
32
|
+
export declare const TimeoutError = "TimeoutError";
|
|
33
|
+
export declare const RetryableError = "RetryableError";
|
|
34
|
+
export declare const LockedError = "LockedError";
|
|
35
|
+
export declare const AbortedError = "AbortedError";
|
|
36
|
+
export declare const AlreadyExistsError = "AlreadyExistsError";
|
|
37
|
+
export declare const DependencyViolationError = "DependencyViolationError";
|
|
38
|
+
export type Category = typeof AuthError | typeof BadRequestError | typeof ConflictError | typeof NotFoundError | typeof QuotaError | typeof ServerError | typeof ThrottlingError | typeof NetworkError | typeof ParseError | typeof ConfigurationError | typeof TimeoutError | typeof RetryableError | typeof LockedError | typeof AbortedError | typeof AlreadyExistsError | typeof DependencyViolationError;
|
|
39
|
+
/**
|
|
40
|
+
* Key for storing categories on error prototypes.
|
|
41
|
+
* Shared across all SDKs so category checking works uniformly.
|
|
42
|
+
*/
|
|
43
|
+
export declare const categoriesKey = "@distilled.cloud/error/categories";
|
|
44
|
+
/**
|
|
45
|
+
* Key for storing retryable trait on error prototypes.
|
|
46
|
+
* Separate from categories - indicates this error should be retried.
|
|
47
|
+
*/
|
|
48
|
+
export declare const retryableKey = "@distilled.cloud/error/retryable";
|
|
49
|
+
export interface RetryableInfo {
|
|
50
|
+
/** If true, this is a throttling error (use longer backoff) */
|
|
51
|
+
throttling?: boolean;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Add one or more categories to an error class.
|
|
55
|
+
* Use with .pipe() on Schema.TaggedError classes.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* export class MyError extends Schema.TaggedErrorClass<MyError>()(
|
|
60
|
+
* "MyError",
|
|
61
|
+
* { message: Schema.String },
|
|
62
|
+
* ).pipe(Category.withCategory(Category.AuthError)) {}
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare const withCategory: <Categories extends Category[]>(...categories: Categories) => <Args extends any[], Ret, C extends new (...args: Args) => Ret>(C: C) => C & (new (...args: Args) => Ret & {
|
|
66
|
+
"@distilled.cloud/error/categories": { [Cat in Categories[number]]: true; };
|
|
67
|
+
});
|
|
68
|
+
/**
|
|
69
|
+
* Mark an error class as retryable.
|
|
70
|
+
* Use with .pipe() on Schema.TaggedError classes.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* // Standard retryable error
|
|
75
|
+
* export class TransientError extends Schema.TaggedErrorClass<TransientError>()(
|
|
76
|
+
* "TransientError",
|
|
77
|
+
* { message: Schema.String },
|
|
78
|
+
* ).pipe(Category.withRetryable()) {}
|
|
79
|
+
*
|
|
80
|
+
* // Throttling error (uses longer backoff)
|
|
81
|
+
* export class RateLimitError extends Schema.TaggedErrorClass<RateLimitError>()(
|
|
82
|
+
* "RateLimitError",
|
|
83
|
+
* { message: Schema.String },
|
|
84
|
+
* ).pipe(Category.withRetryable({ throttling: true })) {}
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export declare const withRetryable: (info?: RetryableInfo) => <Args extends any[], Ret, C extends new (...args: Args) => Ret>(C: C) => C & (new (...args: Args) => Ret & {
|
|
88
|
+
"@distilled.cloud/error/retryable": RetryableInfo;
|
|
89
|
+
});
|
|
90
|
+
export declare const withAuthError: <Args extends any[], Ret, C_1 extends new (...args: Args) => Ret>(C: C_1) => C_1 & (new (...args: Args) => Ret & {
|
|
91
|
+
"@distilled.cloud/error/categories": {
|
|
92
|
+
AuthError: true;
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
export declare const withBadRequestError: <Args extends any[], Ret, C_1 extends new (...args: Args) => Ret>(C: C_1) => C_1 & (new (...args: Args) => Ret & {
|
|
96
|
+
"@distilled.cloud/error/categories": {
|
|
97
|
+
BadRequestError: true;
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
export declare const withConflictError: <Args extends any[], Ret, C_1 extends new (...args: Args) => Ret>(C: C_1) => C_1 & (new (...args: Args) => Ret & {
|
|
101
|
+
"@distilled.cloud/error/categories": {
|
|
102
|
+
ConflictError: true;
|
|
103
|
+
};
|
|
104
|
+
});
|
|
105
|
+
export declare const withNotFoundError: <Args extends any[], Ret, C_1 extends new (...args: Args) => Ret>(C: C_1) => C_1 & (new (...args: Args) => Ret & {
|
|
106
|
+
"@distilled.cloud/error/categories": {
|
|
107
|
+
NotFoundError: true;
|
|
108
|
+
};
|
|
109
|
+
});
|
|
110
|
+
export declare const withQuotaError: <Args extends any[], Ret, C_1 extends new (...args: Args) => Ret>(C: C_1) => C_1 & (new (...args: Args) => Ret & {
|
|
111
|
+
"@distilled.cloud/error/categories": {
|
|
112
|
+
QuotaError: true;
|
|
113
|
+
};
|
|
114
|
+
});
|
|
115
|
+
export declare const withServerError: <Args extends any[], Ret, C_1 extends new (...args: Args) => Ret>(C: C_1) => C_1 & (new (...args: Args) => Ret & {
|
|
116
|
+
"@distilled.cloud/error/categories": {
|
|
117
|
+
ServerError: true;
|
|
118
|
+
};
|
|
119
|
+
});
|
|
120
|
+
export declare const withThrottlingError: <Args extends any[], Ret, C_1 extends new (...args: Args) => Ret>(C: C_1) => C_1 & (new (...args: Args) => Ret & {
|
|
121
|
+
"@distilled.cloud/error/categories": {
|
|
122
|
+
ThrottlingError: true;
|
|
123
|
+
};
|
|
124
|
+
});
|
|
125
|
+
export declare const withNetworkError: <Args extends any[], Ret, C_1 extends new (...args: Args) => Ret>(C: C_1) => C_1 & (new (...args: Args) => Ret & {
|
|
126
|
+
"@distilled.cloud/error/categories": {
|
|
127
|
+
NetworkError: true;
|
|
128
|
+
};
|
|
129
|
+
});
|
|
130
|
+
export declare const withParseError: <Args extends any[], Ret, C_1 extends new (...args: Args) => Ret>(C: C_1) => C_1 & (new (...args: Args) => Ret & {
|
|
131
|
+
"@distilled.cloud/error/categories": {
|
|
132
|
+
ParseError: true;
|
|
133
|
+
};
|
|
134
|
+
});
|
|
135
|
+
export declare const withConfigurationError: <Args extends any[], Ret, C_1 extends new (...args: Args) => Ret>(C: C_1) => C_1 & (new (...args: Args) => Ret & {
|
|
136
|
+
"@distilled.cloud/error/categories": {
|
|
137
|
+
ConfigurationError: true;
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
export declare const withTimeoutError: <Args extends any[], Ret, C_1 extends new (...args: Args) => Ret>(C: C_1) => C_1 & (new (...args: Args) => Ret & {
|
|
141
|
+
"@distilled.cloud/error/categories": {
|
|
142
|
+
TimeoutError: true;
|
|
143
|
+
};
|
|
144
|
+
});
|
|
145
|
+
export declare const withRetryableError: <Args extends any[], Ret, C_1 extends new (...args: Args) => Ret>(C: C_1) => C_1 & (new (...args: Args) => Ret & {
|
|
146
|
+
"@distilled.cloud/error/categories": {
|
|
147
|
+
RetryableError: true;
|
|
148
|
+
};
|
|
149
|
+
});
|
|
150
|
+
export declare const withLockedError: <Args extends any[], Ret, C_1 extends new (...args: Args) => Ret>(C: C_1) => C_1 & (new (...args: Args) => Ret & {
|
|
151
|
+
"@distilled.cloud/error/categories": {
|
|
152
|
+
LockedError: true;
|
|
153
|
+
};
|
|
154
|
+
});
|
|
155
|
+
export declare const withAbortedError: <Args extends any[], Ret, C_1 extends new (...args: Args) => Ret>(C: C_1) => C_1 & (new (...args: Args) => Ret & {
|
|
156
|
+
"@distilled.cloud/error/categories": {
|
|
157
|
+
AbortedError: true;
|
|
158
|
+
};
|
|
159
|
+
});
|
|
160
|
+
export declare const withAlreadyExistsError: <Args extends any[], Ret, C_1 extends new (...args: Args) => Ret>(C: C_1) => C_1 & (new (...args: Args) => Ret & {
|
|
161
|
+
"@distilled.cloud/error/categories": {
|
|
162
|
+
AlreadyExistsError: true;
|
|
163
|
+
};
|
|
164
|
+
});
|
|
165
|
+
export declare const withDependencyViolationError: <Args extends any[], Ret, C_1 extends new (...args: Args) => Ret>(C: C_1) => C_1 & (new (...args: Args) => Ret & {
|
|
166
|
+
"@distilled.cloud/error/categories": {
|
|
167
|
+
DependencyViolationError: true;
|
|
168
|
+
};
|
|
169
|
+
});
|
|
170
|
+
/**
|
|
171
|
+
* Check if an error has a specific category.
|
|
172
|
+
*/
|
|
173
|
+
export declare const hasCategory: (error: unknown, category: Category) => boolean;
|
|
174
|
+
export declare const isAuthError: (error: unknown) => boolean;
|
|
175
|
+
export declare const isBadRequestError: (error: unknown) => boolean;
|
|
176
|
+
export declare const isConflictError: (error: unknown) => boolean;
|
|
177
|
+
export declare const isNotFoundError: (error: unknown) => boolean;
|
|
178
|
+
export declare const isQuotaError: (error: unknown) => boolean;
|
|
179
|
+
export declare const isServerError: (error: unknown) => boolean;
|
|
180
|
+
export declare const isThrottlingError: (error: unknown) => boolean;
|
|
181
|
+
export declare const isNetworkError: (error: unknown) => boolean;
|
|
182
|
+
export declare const isParseError: (error: unknown) => boolean;
|
|
183
|
+
export declare const isConfigurationError: (error: unknown) => boolean;
|
|
184
|
+
export declare const isTimeoutError: (error: unknown) => boolean;
|
|
185
|
+
export declare const isRetryableError: (error: unknown) => boolean;
|
|
186
|
+
export declare const isLockedError: (error: unknown) => boolean;
|
|
187
|
+
export declare const isAbortedError: (error: unknown) => boolean;
|
|
188
|
+
export declare const isAlreadyExistsError: (error: unknown) => boolean;
|
|
189
|
+
export declare const isDependencyViolationError: (error: unknown) => boolean;
|
|
190
|
+
/**
|
|
191
|
+
* Check if an error has the retryable trait (set via withRetryable).
|
|
192
|
+
*/
|
|
193
|
+
export declare const isRetryable: (error: unknown) => boolean;
|
|
194
|
+
/**
|
|
195
|
+
* Check if an error is a throttling error.
|
|
196
|
+
* Either has ThrottlingError category or retryable trait with throttling: true.
|
|
197
|
+
*/
|
|
198
|
+
export declare const isThrottling: (error: unknown) => boolean;
|
|
199
|
+
/**
|
|
200
|
+
* Check if an error is a transient error that should be automatically retried.
|
|
201
|
+
* Transient errors include:
|
|
202
|
+
* - Errors marked with withRetryable()
|
|
203
|
+
* - RetryableError category
|
|
204
|
+
* - ThrottlingError (rate limiting)
|
|
205
|
+
* - ServerError (5xx responses)
|
|
206
|
+
* - NetworkError (connection issues)
|
|
207
|
+
* - TimeoutError (request timed out)
|
|
208
|
+
* - LockedError (423 - resource temporarily locked)
|
|
209
|
+
*/
|
|
210
|
+
export declare const isTransientError: (error: unknown) => boolean;
|
|
211
|
+
export type AllKeys<E> = E extends {
|
|
212
|
+
[categoriesKey]: infer Q;
|
|
213
|
+
} ? keyof Q : never;
|
|
214
|
+
export type ExtractAll<E, Cats extends PropertyKey> = Cats extends any ? Extract<E, {
|
|
215
|
+
[categoriesKey]: {
|
|
216
|
+
[K in Cats]: any;
|
|
217
|
+
};
|
|
218
|
+
}> : never;
|
|
219
|
+
/**
|
|
220
|
+
* Catch errors matching any of the specified categories.
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```ts
|
|
224
|
+
* effect.pipe(
|
|
225
|
+
* Category.catchErrors(Category.AuthError, Category.NotFoundError, (err) =>
|
|
226
|
+
* Effect.succeed("handled")
|
|
227
|
+
* )
|
|
228
|
+
* )
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
export declare const catchErrors: <Categories extends Category[], A2, E2, R2>(...args: [...Categories, (err: any) => Effect.Effect<A2, E2, R2>]) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A | A2, E | E2, R | R2>;
|
|
232
|
+
export { catchErrors as catch };
|
|
233
|
+
export declare const catchAuthError: <A2, E2, R2>(f: (err: any) => Effect.Effect<A2, E2, R2>) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A | A2, E | E2, R | R2>;
|
|
234
|
+
export declare const catchBadRequestError: <A2, E2, R2>(f: (err: any) => Effect.Effect<A2, E2, R2>) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A | A2, E | E2, R | R2>;
|
|
235
|
+
export declare const catchConflictError: <A2, E2, R2>(f: (err: any) => Effect.Effect<A2, E2, R2>) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A | A2, E | E2, R | R2>;
|
|
236
|
+
export declare const catchNotFoundError: <A2, E2, R2>(f: (err: any) => Effect.Effect<A2, E2, R2>) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A | A2, E | E2, R | R2>;
|
|
237
|
+
export declare const catchQuotaError: <A2, E2, R2>(f: (err: any) => Effect.Effect<A2, E2, R2>) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A | A2, E | E2, R | R2>;
|
|
238
|
+
export declare const catchServerError: <A2, E2, R2>(f: (err: any) => Effect.Effect<A2, E2, R2>) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A | A2, E | E2, R | R2>;
|
|
239
|
+
export declare const catchThrottlingError: <A2, E2, R2>(f: (err: any) => Effect.Effect<A2, E2, R2>) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A | A2, E | E2, R | R2>;
|
|
240
|
+
export declare const catchNetworkError: <A2, E2, R2>(f: (err: any) => Effect.Effect<A2, E2, R2>) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A | A2, E | E2, R | R2>;
|
|
241
|
+
export declare const catchParseError: <A2, E2, R2>(f: (err: any) => Effect.Effect<A2, E2, R2>) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A | A2, E | E2, R | R2>;
|
|
242
|
+
export declare const catchConfigurationError: <A2, E2, R2>(f: (err: any) => Effect.Effect<A2, E2, R2>) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A | A2, E | E2, R | R2>;
|
|
243
|
+
export declare const catchTimeoutError: <A2, E2, R2>(f: (err: any) => Effect.Effect<A2, E2, R2>) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A | A2, E | E2, R | R2>;
|
|
244
|
+
export declare const catchRetryableError: <A2, E2, R2>(f: (err: any) => Effect.Effect<A2, E2, R2>) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A | A2, E | E2, R | R2>;
|
|
245
|
+
export declare const catchLockedError: <A2, E2, R2>(f: (err: any) => Effect.Effect<A2, E2, R2>) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A | A2, E | E2, R | R2>;
|
|
246
|
+
export declare const catchAbortedError: <A2, E2, R2>(f: (err: any) => Effect.Effect<A2, E2, R2>) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A | A2, E | E2, R | R2>;
|
|
247
|
+
export declare const catchAlreadyExistsError: <A2, E2, R2>(f: (err: any) => Effect.Effect<A2, E2, R2>) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A | A2, E | E2, R | R2>;
|
|
248
|
+
export declare const catchDependencyViolationError: <A2, E2, R2>(f: (err: any) => Effect.Effect<A2, E2, R2>) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A | A2, E | E2, R | R2>;
|
|
249
|
+
/**
|
|
250
|
+
* Catch errors with specified categories with full type narrowing.
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```ts
|
|
254
|
+
* effect.pipe(
|
|
255
|
+
* Category.catchCategory(Category.AuthError, (err) => Effect.succeed("handled"))
|
|
256
|
+
* )
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
export declare const catchCategory: <E, const Categories extends AllKeys<E>[], A2, E2, R2>(...args: [...Categories, f: (err: ExtractAll<E, Categories[number]>) => Effect.Effect<A2, E2, R2>]) => <A, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A | A2, E2 | Exclude<E, ExtractAll<E, Categories[number]>>, R | R2>;
|
|
260
|
+
//# sourceMappingURL=category.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"category.d.ts","sourceRoot":"","sources":["../src/category.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAOxC,eAAO,MAAM,SAAS,cAAc,CAAC;AACrC,eAAO,MAAM,eAAe,oBAAoB,CAAC;AACjD,eAAO,MAAM,aAAa,kBAAkB,CAAC;AAC7C,eAAO,MAAM,aAAa,kBAAkB,CAAC;AAC7C,eAAO,MAAM,UAAU,eAAe,CAAC;AACvC,eAAO,MAAM,WAAW,gBAAgB,CAAC;AACzC,eAAO,MAAM,eAAe,oBAAoB,CAAC;AACjD,eAAO,MAAM,YAAY,iBAAiB,CAAC;AAC3C,eAAO,MAAM,UAAU,eAAe,CAAC;AACvC,eAAO,MAAM,kBAAkB,uBAAuB,CAAC;AACvD,eAAO,MAAM,YAAY,iBAAiB,CAAC;AAC3C,eAAO,MAAM,cAAc,mBAAmB,CAAC;AAC/C,eAAO,MAAM,WAAW,gBAAgB,CAAC;AACzC,eAAO,MAAM,YAAY,iBAAiB,CAAC;AA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AAiB,GAlD3B,EAAE,EAAE,EAAE,EAAE,EAAE,kDACV,CAAC,EAAE,CAAC,EAAE,CAAC,0EAiDgD,CAAC;AAC3D,eAAO,MAAM,uBAAuB,GAnDjC,EAAE,EAAE,EAAE,EAAE,EAAE,kDACV,CAAC,EAAE,CAAC,EAAE,CAAC,0EAkD4D,CAAC;AACvE,eAAO,MAAM,6BAA6B,GApDvC,EAAE,EAAE,EAAE,EAAE,EAAE,kDACV,CAAC,EAAE,CAAC,EAAE,CAAC,0EAqDT,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,GACvB,CAAC,QAAQ,UAAU,uBAA4B,EAAE,EAAE,EAAE,EAAE,EAAE,0GAMzD,CAAC,EAAE,CAAC,sHAyBJ,CAAC"}
|
package/lib/category.js
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error Category System
|
|
3
|
+
*
|
|
4
|
+
* Provides a unified error classification system across all SDKs.
|
|
5
|
+
* Error classes are decorated with categories using `.pipe()` on Schema.TaggedError classes,
|
|
6
|
+
* enabling semantic error handling (e.g., catch all auth errors regardless of provider).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import * as Category from "@distilled.cloud/sdk-core/category";
|
|
11
|
+
*
|
|
12
|
+
* export class Unauthorized extends Schema.TaggedErrorClass<Unauthorized>()(
|
|
13
|
+
* "Unauthorized",
|
|
14
|
+
* { message: Schema.String },
|
|
15
|
+
* ).pipe(Category.withAuthError) {}
|
|
16
|
+
*
|
|
17
|
+
* // Catch by category
|
|
18
|
+
* effect.pipe(Category.catchAuthError((err) => Effect.succeed("handled")))
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
import * as Effect from "effect/Effect";
|
|
22
|
+
import * as Predicate from "effect/Predicate";
|
|
23
|
+
// ============================================================================
|
|
24
|
+
// Error Category Constants
|
|
25
|
+
// ============================================================================
|
|
26
|
+
export const AuthError = "AuthError";
|
|
27
|
+
export const BadRequestError = "BadRequestError";
|
|
28
|
+
export const ConflictError = "ConflictError";
|
|
29
|
+
export const NotFoundError = "NotFoundError";
|
|
30
|
+
export const QuotaError = "QuotaError";
|
|
31
|
+
export const ServerError = "ServerError";
|
|
32
|
+
export const ThrottlingError = "ThrottlingError";
|
|
33
|
+
export const NetworkError = "NetworkError";
|
|
34
|
+
export const ParseError = "ParseError";
|
|
35
|
+
export const ConfigurationError = "ConfigurationError";
|
|
36
|
+
export const TimeoutError = "TimeoutError";
|
|
37
|
+
export const RetryableError = "RetryableError";
|
|
38
|
+
export const LockedError = "LockedError";
|
|
39
|
+
export const AbortedError = "AbortedError";
|
|
40
|
+
export const AlreadyExistsError = "AlreadyExistsError";
|
|
41
|
+
export const DependencyViolationError = "DependencyViolationError";
|
|
42
|
+
// ============================================================================
|
|
43
|
+
// Category Storage Key
|
|
44
|
+
// ============================================================================
|
|
45
|
+
/**
|
|
46
|
+
* Key for storing categories on error prototypes.
|
|
47
|
+
* Shared across all SDKs so category checking works uniformly.
|
|
48
|
+
*/
|
|
49
|
+
export const categoriesKey = "@distilled.cloud/error/categories";
|
|
50
|
+
/**
|
|
51
|
+
* Key for storing retryable trait on error prototypes.
|
|
52
|
+
* Separate from categories - indicates this error should be retried.
|
|
53
|
+
*/
|
|
54
|
+
export const retryableKey = "@distilled.cloud/error/retryable";
|
|
55
|
+
// ============================================================================
|
|
56
|
+
// Category Decorator
|
|
57
|
+
// ============================================================================
|
|
58
|
+
/**
|
|
59
|
+
* Add one or more categories to an error class.
|
|
60
|
+
* Use with .pipe() on Schema.TaggedError classes.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* export class MyError extends Schema.TaggedErrorClass<MyError>()(
|
|
65
|
+
* "MyError",
|
|
66
|
+
* { message: Schema.String },
|
|
67
|
+
* ).pipe(Category.withCategory(Category.AuthError)) {}
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export const withCategory = (...categories) => (C) => {
|
|
71
|
+
for (const category of categories) {
|
|
72
|
+
if (!(categoriesKey in C.prototype)) {
|
|
73
|
+
C.prototype[categoriesKey] = {};
|
|
74
|
+
}
|
|
75
|
+
C.prototype[categoriesKey][category] = true;
|
|
76
|
+
}
|
|
77
|
+
return C;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Mark an error class as retryable.
|
|
81
|
+
* Use with .pipe() on Schema.TaggedError classes.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* // Standard retryable error
|
|
86
|
+
* export class TransientError extends Schema.TaggedErrorClass<TransientError>()(
|
|
87
|
+
* "TransientError",
|
|
88
|
+
* { message: Schema.String },
|
|
89
|
+
* ).pipe(Category.withRetryable()) {}
|
|
90
|
+
*
|
|
91
|
+
* // Throttling error (uses longer backoff)
|
|
92
|
+
* export class RateLimitError extends Schema.TaggedErrorClass<RateLimitError>()(
|
|
93
|
+
* "RateLimitError",
|
|
94
|
+
* { message: Schema.String },
|
|
95
|
+
* ).pipe(Category.withRetryable({ throttling: true })) {}
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export const withRetryable = (info = {}) => (C) => {
|
|
99
|
+
C.prototype[retryableKey] = info;
|
|
100
|
+
return C;
|
|
101
|
+
};
|
|
102
|
+
// ============================================================================
|
|
103
|
+
// Category Decorators (convenience functions for common categories)
|
|
104
|
+
// ============================================================================
|
|
105
|
+
export const withAuthError = withCategory(AuthError);
|
|
106
|
+
export const withBadRequestError = withCategory(BadRequestError);
|
|
107
|
+
export const withConflictError = withCategory(ConflictError);
|
|
108
|
+
export const withNotFoundError = withCategory(NotFoundError);
|
|
109
|
+
export const withQuotaError = withCategory(QuotaError);
|
|
110
|
+
export const withServerError = withCategory(ServerError);
|
|
111
|
+
export const withThrottlingError = withCategory(ThrottlingError);
|
|
112
|
+
export const withNetworkError = withCategory(NetworkError);
|
|
113
|
+
export const withParseError = withCategory(ParseError);
|
|
114
|
+
export const withConfigurationError = withCategory(ConfigurationError);
|
|
115
|
+
export const withTimeoutError = withCategory(TimeoutError);
|
|
116
|
+
export const withRetryableError = withCategory(RetryableError);
|
|
117
|
+
export const withLockedError = withCategory(LockedError);
|
|
118
|
+
export const withAbortedError = withCategory(AbortedError);
|
|
119
|
+
export const withAlreadyExistsError = withCategory(AlreadyExistsError);
|
|
120
|
+
export const withDependencyViolationError = withCategory(DependencyViolationError);
|
|
121
|
+
// ============================================================================
|
|
122
|
+
// Category Predicates
|
|
123
|
+
// ============================================================================
|
|
124
|
+
/**
|
|
125
|
+
* Check if an error has a specific category.
|
|
126
|
+
*/
|
|
127
|
+
export const hasCategory = (error, category) => {
|
|
128
|
+
if (Predicate.isObject(error) &&
|
|
129
|
+
Predicate.hasProperty(categoriesKey)(error)) {
|
|
130
|
+
// @ts-expect-error - dynamic property access
|
|
131
|
+
return category in error[categoriesKey];
|
|
132
|
+
}
|
|
133
|
+
return false;
|
|
134
|
+
};
|
|
135
|
+
export const isAuthError = (error) => hasCategory(error, AuthError);
|
|
136
|
+
export const isBadRequestError = (error) => hasCategory(error, BadRequestError);
|
|
137
|
+
export const isConflictError = (error) => hasCategory(error, ConflictError);
|
|
138
|
+
export const isNotFoundError = (error) => hasCategory(error, NotFoundError);
|
|
139
|
+
export const isQuotaError = (error) => hasCategory(error, QuotaError);
|
|
140
|
+
export const isServerError = (error) => hasCategory(error, ServerError);
|
|
141
|
+
export const isThrottlingError = (error) => hasCategory(error, ThrottlingError);
|
|
142
|
+
export const isNetworkError = (error) => hasCategory(error, NetworkError);
|
|
143
|
+
export const isParseError = (error) => hasCategory(error, ParseError);
|
|
144
|
+
export const isConfigurationError = (error) => hasCategory(error, ConfigurationError);
|
|
145
|
+
export const isTimeoutError = (error) => hasCategory(error, TimeoutError);
|
|
146
|
+
export const isRetryableError = (error) => hasCategory(error, RetryableError);
|
|
147
|
+
export const isLockedError = (error) => hasCategory(error, LockedError);
|
|
148
|
+
export const isAbortedError = (error) => hasCategory(error, AbortedError);
|
|
149
|
+
export const isAlreadyExistsError = (error) => hasCategory(error, AlreadyExistsError);
|
|
150
|
+
export const isDependencyViolationError = (error) => hasCategory(error, DependencyViolationError);
|
|
151
|
+
// ============================================================================
|
|
152
|
+
// Transient Error Detection (for retry logic)
|
|
153
|
+
// ============================================================================
|
|
154
|
+
/**
|
|
155
|
+
* Check if an error has the retryable trait (set via withRetryable).
|
|
156
|
+
*/
|
|
157
|
+
export const isRetryable = (error) => {
|
|
158
|
+
if (Predicate.isObject(error) && Predicate.hasProperty(retryableKey)(error)) {
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
return false;
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Check if an error is a throttling error.
|
|
165
|
+
* Either has ThrottlingError category or retryable trait with throttling: true.
|
|
166
|
+
*/
|
|
167
|
+
export const isThrottling = (error) => {
|
|
168
|
+
if (Predicate.isObject(error) && Predicate.hasProperty(retryableKey)(error)) {
|
|
169
|
+
// @ts-expect-error - dynamic property access
|
|
170
|
+
return error[retryableKey]?.throttling === true;
|
|
171
|
+
}
|
|
172
|
+
return hasCategory(error, ThrottlingError);
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Check if an error is a transient error that should be automatically retried.
|
|
176
|
+
* Transient errors include:
|
|
177
|
+
* - Errors marked with withRetryable()
|
|
178
|
+
* - RetryableError category
|
|
179
|
+
* - ThrottlingError (rate limiting)
|
|
180
|
+
* - ServerError (5xx responses)
|
|
181
|
+
* - NetworkError (connection issues)
|
|
182
|
+
* - TimeoutError (request timed out)
|
|
183
|
+
* - LockedError (423 - resource temporarily locked)
|
|
184
|
+
*/
|
|
185
|
+
export const isTransientError = (error) => {
|
|
186
|
+
// Check for retryable trait first
|
|
187
|
+
if (isRetryable(error)) {
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
// Fall back to category-based checking
|
|
191
|
+
return (hasCategory(error, RetryableError) ||
|
|
192
|
+
hasCategory(error, ThrottlingError) ||
|
|
193
|
+
hasCategory(error, ServerError) ||
|
|
194
|
+
hasCategory(error, NetworkError) ||
|
|
195
|
+
hasCategory(error, TimeoutError) ||
|
|
196
|
+
hasCategory(error, LockedError));
|
|
197
|
+
};
|
|
198
|
+
// ============================================================================
|
|
199
|
+
// Category Catchers
|
|
200
|
+
// ============================================================================
|
|
201
|
+
const makeCatcher = (category) => (f) => (effect) => Effect.catchIf(effect, (e) => hasCategory(e, category), f);
|
|
202
|
+
/**
|
|
203
|
+
* Catch errors matching any of the specified categories.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```ts
|
|
207
|
+
* effect.pipe(
|
|
208
|
+
* Category.catchErrors(Category.AuthError, Category.NotFoundError, (err) =>
|
|
209
|
+
* Effect.succeed("handled")
|
|
210
|
+
* )
|
|
211
|
+
* )
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
export const catchErrors = (...args) => (effect) => {
|
|
215
|
+
const handler = args.pop();
|
|
216
|
+
const categories = args;
|
|
217
|
+
return Effect.catchIf(effect, (e) => categories.some((cat) => hasCategory(e, cat)), handler);
|
|
218
|
+
};
|
|
219
|
+
// Alias for convenience
|
|
220
|
+
export { catchErrors as catch };
|
|
221
|
+
export const catchAuthError = makeCatcher(AuthError);
|
|
222
|
+
export const catchBadRequestError = makeCatcher(BadRequestError);
|
|
223
|
+
export const catchConflictError = makeCatcher(ConflictError);
|
|
224
|
+
export const catchNotFoundError = makeCatcher(NotFoundError);
|
|
225
|
+
export const catchQuotaError = makeCatcher(QuotaError);
|
|
226
|
+
export const catchServerError = makeCatcher(ServerError);
|
|
227
|
+
export const catchThrottlingError = makeCatcher(ThrottlingError);
|
|
228
|
+
export const catchNetworkError = makeCatcher(NetworkError);
|
|
229
|
+
export const catchParseError = makeCatcher(ParseError);
|
|
230
|
+
export const catchConfigurationError = makeCatcher(ConfigurationError);
|
|
231
|
+
export const catchTimeoutError = makeCatcher(TimeoutError);
|
|
232
|
+
export const catchRetryableError = makeCatcher(RetryableError);
|
|
233
|
+
export const catchLockedError = makeCatcher(LockedError);
|
|
234
|
+
export const catchAbortedError = makeCatcher(AbortedError);
|
|
235
|
+
export const catchAlreadyExistsError = makeCatcher(AlreadyExistsError);
|
|
236
|
+
export const catchDependencyViolationError = makeCatcher(DependencyViolationError);
|
|
237
|
+
/**
|
|
238
|
+
* Catch errors with specified categories with full type narrowing.
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```ts
|
|
242
|
+
* effect.pipe(
|
|
243
|
+
* Category.catchCategory(Category.AuthError, (err) => Effect.succeed("handled"))
|
|
244
|
+
* )
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
247
|
+
export const catchCategory = (...args) => (effect) => {
|
|
248
|
+
const f = args.pop();
|
|
249
|
+
const categories = args;
|
|
250
|
+
return Effect.catchIf(effect, (e) => {
|
|
251
|
+
if (Predicate.isObject(e) && Predicate.hasProperty(categoriesKey)(e)) {
|
|
252
|
+
for (const cat of categories) {
|
|
253
|
+
// @ts-expect-error - dynamic property access
|
|
254
|
+
if (cat in e[categoriesKey]) {
|
|
255
|
+
return true;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return false;
|
|
260
|
+
},
|
|
261
|
+
// @ts-expect-error - type narrowing limitation
|
|
262
|
+
(e) => f(e));
|
|
263
|
+
};
|
|
264
|
+
//# sourceMappingURL=category.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"category.js","sourceRoot":"","sources":["../src/category.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAC;AAE9C,+EAA+E;AAC/E,2BAA2B;AAC3B,+EAA+E;AAE/E,MAAM,CAAC,MAAM,SAAS,GAAG,WAAW,CAAC;AACrC,MAAM,C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