@outfitter/contracts 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions.d.ts +8 -3
- package/dist/assert/index.d.ts +7 -3
- package/dist/assert/index.js +32 -1
- package/dist/context.d.ts +8 -3
- package/dist/context.js +1 -1
- package/dist/envelope.d.ts +6 -2
- package/dist/envelope.js +5 -6
- package/dist/errors.d.ts +6 -2
- package/dist/errors.js +7 -1
- package/dist/from-fetch.d.ts +7 -0
- package/dist/from-fetch.js +110 -0
- package/dist/handler.d.ts +7 -2
- package/dist/hints.d.ts +2 -0
- package/dist/hints.js +1 -0
- package/dist/index.d.ts +24 -13
- package/dist/index.js +5 -3
- package/dist/internal/error-base.d.ts +2 -0
- package/dist/internal/error-base.js +31 -0
- package/dist/internal/error-operational.d.ts +3 -0
- package/dist/internal/error-operational.js +125 -0
- package/dist/internal/error-serialization.d.ts +7 -0
- package/dist/{shared/@outfitter/contracts-5k6q4n48.js → internal/error-serialization.js} +28 -67
- package/dist/internal/error-taxonomy.d.ts +2 -0
- package/dist/internal/error-taxonomy.js +21 -0
- package/dist/internal/error-validation.d.ts +3 -0
- package/dist/internal/error-validation.js +121 -0
- package/dist/internal/safe-json.d.ts +7 -0
- package/dist/internal/safe-json.js +66 -0
- package/dist/internal/schema-converters.d.ts +26 -0
- package/dist/internal/schema-converters.js +12 -0
- package/dist/internal/schema-primitives.d.ts +10 -0
- package/dist/internal/schema-primitives.js +9 -0
- package/dist/internal/schema-types.d.ts +2 -0
- package/dist/internal/schema-types.js +9 -0
- package/dist/recovery.d.ts +6 -2
- package/dist/resilience.d.ts +6 -2
- package/dist/resilience.js +6 -2
- package/dist/schema.d.ts +2 -1
- package/dist/schema.js +15 -187
- package/dist/serialization.d.ts +8 -2
- package/dist/serialization.js +1 -3
- package/dist/shared/@outfitter/{contracts-k71jqd1m.d.ts → contracts-10p5q75w.d.ts} +1 -1
- package/dist/shared/@outfitter/contracts-1zzcpfyg.d.ts +40 -0
- package/dist/shared/@outfitter/contracts-3f5k5tg5.d.ts +28 -0
- package/dist/shared/@outfitter/contracts-3qmyq81n.d.ts +78 -0
- package/dist/shared/@outfitter/contracts-3re9d4bp.js +114 -0
- package/dist/shared/@outfitter/contracts-735ecmbq.d.ts +107 -0
- package/dist/shared/@outfitter/contracts-7a0xmwbg.d.ts +11 -0
- package/dist/shared/@outfitter/contracts-8cmkh2db.d.ts +31 -0
- package/dist/shared/@outfitter/{contracts-agmt8915.js → contracts-c3qfce25.js} +3 -0
- package/dist/shared/@outfitter/{contracts-1waabxbk.d.ts → contracts-drwd9ywk.d.ts} +4 -1
- package/dist/shared/@outfitter/contracts-hgh47193.js +46 -0
- package/dist/shared/@outfitter/contracts-hrepwwne.js +62 -0
- package/dist/shared/@outfitter/contracts-jtn6b927.js +18 -0
- package/dist/shared/@outfitter/contracts-jtt6dnmg.js +2 -0
- package/dist/shared/@outfitter/contracts-jyhqr766.js +25 -0
- package/dist/shared/@outfitter/contracts-mehpmvwp.d.ts +164 -0
- package/dist/shared/@outfitter/contracts-msxdg52h.d.ts +125 -0
- package/dist/shared/@outfitter/{contracts-95cc3y06.d.ts → contracts-mt027fqj.d.ts} +2 -1
- package/dist/shared/@outfitter/contracts-njb2art4.d.ts +174 -0
- package/dist/shared/@outfitter/contracts-p77yjs4g.d.ts +46 -0
- package/dist/shared/@outfitter/contracts-qpbv29bg.d.ts +59 -0
- package/dist/shared/@outfitter/contracts-sawwfgb5.js +111 -0
- package/dist/shared/@outfitter/{contracts-e4m948m7.d.ts → contracts-t4txv24h.d.ts} +2 -1
- package/dist/shared/@outfitter/contracts-vbgt9rfn.d.ts +74 -0
- package/dist/shared/@outfitter/{contracts-56pcsavx.d.ts → contracts-vhajx4gg.d.ts} +8 -2
- package/dist/shared/@outfitter/contracts-vhr2ep6b.js +3 -0
- package/dist/shared/@outfitter/contracts-w7nvcwrp.d.ts +44 -0
- package/dist/shared/@outfitter/contracts-x0ppyt7e.d.ts +76 -0
- package/dist/shared/@outfitter/{contracts-0akf2sm6.d.ts → contracts-zma4mscd.d.ts} +16 -1
- package/dist/shared/@outfitter/contracts-zsgxsa91.d.ts +84 -0
- package/dist/stream.d.ts +2 -0
- package/dist/stream.js +1 -0
- package/dist/validation.d.ts +7 -3
- package/dist/validation.js +8 -36
- package/dist/wrap-error.d.ts +7 -0
- package/dist/wrap-error.js +71 -0
- package/package.json +41 -17
- package/dist/shared/@outfitter/contracts-31penhwa.d.ts +0 -81
- package/dist/shared/@outfitter/contracts-3gswmhb1.d.ts +0 -446
- package/dist/shared/@outfitter/contracts-9wtm5nsw.d.ts +0 -42
- package/dist/shared/@outfitter/contracts-mmg0npfk.d.ts +0 -30
- package/dist/shared/@outfitter/contracts-phjhz5q3.js +0 -293
- package/dist/shared/@outfitter/contracts-t79engf9.d.ts +0 -60
|
@@ -1,293 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
// packages/contracts/src/errors.ts
|
|
3
|
-
import { TaggedError } from "better-result";
|
|
4
|
-
var exitCodeMap = {
|
|
5
|
-
validation: 1,
|
|
6
|
-
not_found: 2,
|
|
7
|
-
conflict: 3,
|
|
8
|
-
permission: 4,
|
|
9
|
-
timeout: 5,
|
|
10
|
-
rate_limit: 6,
|
|
11
|
-
network: 7,
|
|
12
|
-
internal: 8,
|
|
13
|
-
auth: 9,
|
|
14
|
-
cancelled: 130
|
|
15
|
-
};
|
|
16
|
-
var statusCodeMap = {
|
|
17
|
-
validation: 400,
|
|
18
|
-
not_found: 404,
|
|
19
|
-
conflict: 409,
|
|
20
|
-
permission: 403,
|
|
21
|
-
timeout: 504,
|
|
22
|
-
rate_limit: 429,
|
|
23
|
-
network: 502,
|
|
24
|
-
internal: 500,
|
|
25
|
-
auth: 401,
|
|
26
|
-
cancelled: 499
|
|
27
|
-
};
|
|
28
|
-
var ERROR_CODES = {
|
|
29
|
-
validation: {
|
|
30
|
-
FIELD_REQUIRED: 1001,
|
|
31
|
-
INVALID_FORMAT: 1002,
|
|
32
|
-
OUT_OF_RANGE: 1003,
|
|
33
|
-
TYPE_MISMATCH: 1004,
|
|
34
|
-
AMBIGUOUS_MATCH: 1005
|
|
35
|
-
},
|
|
36
|
-
not_found: {
|
|
37
|
-
RESOURCE_NOT_FOUND: 2001,
|
|
38
|
-
FILE_NOT_FOUND: 2002
|
|
39
|
-
},
|
|
40
|
-
conflict: {
|
|
41
|
-
ALREADY_EXISTS: 3001,
|
|
42
|
-
VERSION_MISMATCH: 3002
|
|
43
|
-
},
|
|
44
|
-
permission: {
|
|
45
|
-
FORBIDDEN: 4001,
|
|
46
|
-
INSUFFICIENT_RIGHTS: 4002
|
|
47
|
-
},
|
|
48
|
-
timeout: {
|
|
49
|
-
OPERATION_TIMEOUT: 5001,
|
|
50
|
-
CONNECTION_TIMEOUT: 5002
|
|
51
|
-
},
|
|
52
|
-
rate_limit: {
|
|
53
|
-
QUOTA_EXCEEDED: 6001,
|
|
54
|
-
THROTTLED: 6002
|
|
55
|
-
},
|
|
56
|
-
network: {
|
|
57
|
-
CONNECTION_REFUSED: 7001,
|
|
58
|
-
DNS_FAILED: 7002
|
|
59
|
-
},
|
|
60
|
-
internal: {
|
|
61
|
-
UNEXPECTED_STATE: 8001,
|
|
62
|
-
ASSERTION_FAILED: 8002
|
|
63
|
-
},
|
|
64
|
-
auth: {
|
|
65
|
-
INVALID_TOKEN: 9001,
|
|
66
|
-
EXPIRED_TOKEN: 9002
|
|
67
|
-
},
|
|
68
|
-
cancelled: {
|
|
69
|
-
USER_CANCELLED: 10001,
|
|
70
|
-
SIGNAL_RECEIVED: 10002
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
function getExitCode(category) {
|
|
74
|
-
return exitCodeMap[category];
|
|
75
|
-
}
|
|
76
|
-
function getStatusCode(category) {
|
|
77
|
-
return statusCodeMap[category];
|
|
78
|
-
}
|
|
79
|
-
var ValidationErrorBase = TaggedError("ValidationError")();
|
|
80
|
-
var AmbiguousErrorBase = TaggedError("AmbiguousError")();
|
|
81
|
-
var AssertionErrorBase = TaggedError("AssertionError")();
|
|
82
|
-
var NotFoundErrorBase = TaggedError("NotFoundError")();
|
|
83
|
-
var AlreadyExistsErrorBase = TaggedError("AlreadyExistsError")();
|
|
84
|
-
var ConflictErrorBase = TaggedError("ConflictError")();
|
|
85
|
-
var PermissionErrorBase = TaggedError("PermissionError")();
|
|
86
|
-
var TimeoutErrorBase = TaggedError("TimeoutError")();
|
|
87
|
-
var RateLimitErrorBase = TaggedError("RateLimitError")();
|
|
88
|
-
var NetworkErrorBase = TaggedError("NetworkError")();
|
|
89
|
-
var InternalErrorBase = TaggedError("InternalError")();
|
|
90
|
-
var AuthErrorBase = TaggedError("AuthError")();
|
|
91
|
-
var CancelledErrorBase = TaggedError("CancelledError")();
|
|
92
|
-
|
|
93
|
-
class ValidationError extends ValidationErrorBase {
|
|
94
|
-
category = "validation";
|
|
95
|
-
static create(field, reason, context) {
|
|
96
|
-
return new ValidationError({
|
|
97
|
-
message: `${field}: ${reason}`,
|
|
98
|
-
field,
|
|
99
|
-
...context != null && { context }
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
static fromMessage(message, context) {
|
|
103
|
-
return new ValidationError({
|
|
104
|
-
message,
|
|
105
|
-
...context != null && { context }
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
exitCode() {
|
|
109
|
-
return getExitCode(this.category);
|
|
110
|
-
}
|
|
111
|
-
statusCode() {
|
|
112
|
-
return getStatusCode(this.category);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
class AmbiguousError extends AmbiguousErrorBase {
|
|
117
|
-
category = "validation";
|
|
118
|
-
static create(what, candidates, context) {
|
|
119
|
-
return new AmbiguousError({
|
|
120
|
-
message: `Ambiguous ${what}: ${candidates.length} matches found`,
|
|
121
|
-
candidates,
|
|
122
|
-
...context != null && { context }
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
exitCode() {
|
|
126
|
-
return getExitCode(this.category);
|
|
127
|
-
}
|
|
128
|
-
statusCode() {
|
|
129
|
-
return getStatusCode(this.category);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
class AssertionError extends AssertionErrorBase {
|
|
134
|
-
category = "internal";
|
|
135
|
-
exitCode() {
|
|
136
|
-
return getExitCode(this.category);
|
|
137
|
-
}
|
|
138
|
-
statusCode() {
|
|
139
|
-
return getStatusCode(this.category);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
class NotFoundError extends NotFoundErrorBase {
|
|
144
|
-
category = "not_found";
|
|
145
|
-
static create(resourceType, resourceId, context) {
|
|
146
|
-
return new NotFoundError({
|
|
147
|
-
message: `${resourceType} not found: ${resourceId}`,
|
|
148
|
-
resourceType,
|
|
149
|
-
resourceId,
|
|
150
|
-
...context != null && { context }
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
exitCode() {
|
|
154
|
-
return getExitCode(this.category);
|
|
155
|
-
}
|
|
156
|
-
statusCode() {
|
|
157
|
-
return getStatusCode(this.category);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
class AlreadyExistsError extends AlreadyExistsErrorBase {
|
|
162
|
-
category = "conflict";
|
|
163
|
-
static create(resourceType, resourceId, context) {
|
|
164
|
-
return new AlreadyExistsError({
|
|
165
|
-
message: `${resourceType} already exists: ${resourceId}`,
|
|
166
|
-
resourceType,
|
|
167
|
-
resourceId,
|
|
168
|
-
...context != null && { context }
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
exitCode() {
|
|
172
|
-
return getExitCode(this.category);
|
|
173
|
-
}
|
|
174
|
-
statusCode() {
|
|
175
|
-
return getStatusCode(this.category);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
class ConflictError extends ConflictErrorBase {
|
|
180
|
-
category = "conflict";
|
|
181
|
-
static create(message, context) {
|
|
182
|
-
return new ConflictError({ message, ...context != null && { context } });
|
|
183
|
-
}
|
|
184
|
-
exitCode() {
|
|
185
|
-
return getExitCode(this.category);
|
|
186
|
-
}
|
|
187
|
-
statusCode() {
|
|
188
|
-
return getStatusCode(this.category);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
class PermissionError extends PermissionErrorBase {
|
|
193
|
-
category = "permission";
|
|
194
|
-
static create(message, context) {
|
|
195
|
-
return new PermissionError({
|
|
196
|
-
message,
|
|
197
|
-
...context != null && { context }
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
exitCode() {
|
|
201
|
-
return getExitCode(this.category);
|
|
202
|
-
}
|
|
203
|
-
statusCode() {
|
|
204
|
-
return getStatusCode(this.category);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
class TimeoutError extends TimeoutErrorBase {
|
|
209
|
-
category = "timeout";
|
|
210
|
-
static create(operation, timeoutMs) {
|
|
211
|
-
return new TimeoutError({
|
|
212
|
-
message: `${operation} timed out after ${timeoutMs}ms`,
|
|
213
|
-
operation,
|
|
214
|
-
timeoutMs
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
exitCode() {
|
|
218
|
-
return getExitCode(this.category);
|
|
219
|
-
}
|
|
220
|
-
statusCode() {
|
|
221
|
-
return getStatusCode(this.category);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
class RateLimitError extends RateLimitErrorBase {
|
|
226
|
-
category = "rate_limit";
|
|
227
|
-
static create(message, retryAfterSeconds) {
|
|
228
|
-
return new RateLimitError({
|
|
229
|
-
message,
|
|
230
|
-
...retryAfterSeconds != null && { retryAfterSeconds }
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
exitCode() {
|
|
234
|
-
return getExitCode(this.category);
|
|
235
|
-
}
|
|
236
|
-
statusCode() {
|
|
237
|
-
return getStatusCode(this.category);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
class NetworkError extends NetworkErrorBase {
|
|
242
|
-
category = "network";
|
|
243
|
-
static create(message, context) {
|
|
244
|
-
return new NetworkError({ message, ...context != null && { context } });
|
|
245
|
-
}
|
|
246
|
-
exitCode() {
|
|
247
|
-
return getExitCode(this.category);
|
|
248
|
-
}
|
|
249
|
-
statusCode() {
|
|
250
|
-
return getStatusCode(this.category);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
class InternalError extends InternalErrorBase {
|
|
255
|
-
category = "internal";
|
|
256
|
-
static create(message, context) {
|
|
257
|
-
return new InternalError({ message, ...context != null && { context } });
|
|
258
|
-
}
|
|
259
|
-
exitCode() {
|
|
260
|
-
return getExitCode(this.category);
|
|
261
|
-
}
|
|
262
|
-
statusCode() {
|
|
263
|
-
return getStatusCode(this.category);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
class AuthError extends AuthErrorBase {
|
|
268
|
-
category = "auth";
|
|
269
|
-
static create(message, reason) {
|
|
270
|
-
return new AuthError({ message, ...reason != null && { reason } });
|
|
271
|
-
}
|
|
272
|
-
exitCode() {
|
|
273
|
-
return getExitCode(this.category);
|
|
274
|
-
}
|
|
275
|
-
statusCode() {
|
|
276
|
-
return getStatusCode(this.category);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
class CancelledError extends CancelledErrorBase {
|
|
281
|
-
category = "cancelled";
|
|
282
|
-
static create(message) {
|
|
283
|
-
return new CancelledError({ message });
|
|
284
|
-
}
|
|
285
|
-
exitCode() {
|
|
286
|
-
return getExitCode(this.category);
|
|
287
|
-
}
|
|
288
|
-
statusCode() {
|
|
289
|
-
return getStatusCode(this.category);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
export { exitCodeMap, statusCodeMap, ERROR_CODES, getExitCode, getStatusCode, ValidationError, AmbiguousError, AssertionError, NotFoundError, AlreadyExistsError, ConflictError, PermissionError, TimeoutError, RateLimitError, NetworkError, InternalError, AuthError, CancelledError };
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
/**
|
|
3
|
-
* JSON Schema representation.
|
|
4
|
-
*/
|
|
5
|
-
interface JsonSchema {
|
|
6
|
-
$defs?: Record<string, JsonSchema>;
|
|
7
|
-
$ref?: string;
|
|
8
|
-
$schema?: string;
|
|
9
|
-
additionalProperties?: boolean | JsonSchema;
|
|
10
|
-
allOf?: JsonSchema[];
|
|
11
|
-
anyOf?: JsonSchema[];
|
|
12
|
-
const?: unknown;
|
|
13
|
-
default?: unknown;
|
|
14
|
-
definitions?: Record<string, JsonSchema>;
|
|
15
|
-
description?: string;
|
|
16
|
-
enum?: unknown[];
|
|
17
|
-
exclusiveMaximum?: number;
|
|
18
|
-
exclusiveMinimum?: number;
|
|
19
|
-
format?: string;
|
|
20
|
-
items?: JsonSchema | JsonSchema[];
|
|
21
|
-
maximum?: number;
|
|
22
|
-
maxLength?: number;
|
|
23
|
-
minimum?: number;
|
|
24
|
-
minLength?: number;
|
|
25
|
-
not?: JsonSchema | Record<string, never>;
|
|
26
|
-
oneOf?: JsonSchema[];
|
|
27
|
-
pattern?: string;
|
|
28
|
-
properties?: Record<string, JsonSchema>;
|
|
29
|
-
required?: string[];
|
|
30
|
-
type?: string;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Convert a Zod schema to JSON Schema format.
|
|
34
|
-
*
|
|
35
|
-
* This is a simplified converter that handles common Zod types.
|
|
36
|
-
* For complex schemas, consider using a full zod-to-json-schema library.
|
|
37
|
-
*
|
|
38
|
-
* @param schema - Zod schema to convert
|
|
39
|
-
* @returns JSON Schema representation
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* ```typescript
|
|
43
|
-
* const zodSchema = z.object({
|
|
44
|
-
* name: z.string(),
|
|
45
|
-
* age: z.number().optional(),
|
|
46
|
-
* });
|
|
47
|
-
*
|
|
48
|
-
* const jsonSchema = zodToJsonSchema(zodSchema);
|
|
49
|
-
* // {
|
|
50
|
-
* // type: "object",
|
|
51
|
-
* // properties: {
|
|
52
|
-
* // name: { type: "string" },
|
|
53
|
-
* // age: { type: "number" },
|
|
54
|
-
* // },
|
|
55
|
-
* // required: ["name"],
|
|
56
|
-
* // }
|
|
57
|
-
* ```
|
|
58
|
-
*/
|
|
59
|
-
declare function zodToJsonSchema(schema: z.ZodType<unknown>): JsonSchema;
|
|
60
|
-
export { JsonSchema, zodToJsonSchema };
|