@rexeus/typeweaver-core 0.2.0 → 0.3.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/index.cjs +431 -0
- package/dist/index.d.cts +355 -0
- package/dist/index.d.ts +15 -7
- package/dist/index.js +114 -79
- package/package.json +14 -7
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
HttpMethod: () => HttpMethod,
|
|
24
|
+
HttpOperationDefinition: () => HttpOperationDefinition,
|
|
25
|
+
HttpRequestDefinition: () => HttpRequestDefinition,
|
|
26
|
+
HttpResponse: () => HttpResponse,
|
|
27
|
+
HttpResponseDefinition: () => HttpResponseDefinition,
|
|
28
|
+
HttpStatusCode: () => HttpStatusCode,
|
|
29
|
+
HttpStatusCodeNameMap: () => HttpStatusCodeNameMap,
|
|
30
|
+
RequestValidationError: () => RequestValidationError,
|
|
31
|
+
ResponseValidationError: () => ResponseValidationError,
|
|
32
|
+
UnknownResponse: () => UnknownResponse
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(index_exports);
|
|
35
|
+
|
|
36
|
+
// src/HttpStatusCode.ts
|
|
37
|
+
var HttpStatusCode = /* @__PURE__ */ ((HttpStatusCode3) => {
|
|
38
|
+
HttpStatusCode3[HttpStatusCode3["OK"] = 200] = "OK";
|
|
39
|
+
HttpStatusCode3[HttpStatusCode3["CREATED"] = 201] = "CREATED";
|
|
40
|
+
HttpStatusCode3[HttpStatusCode3["ACCEPTED"] = 202] = "ACCEPTED";
|
|
41
|
+
HttpStatusCode3[HttpStatusCode3["NO_CONTENT"] = 204] = "NO_CONTENT";
|
|
42
|
+
HttpStatusCode3[HttpStatusCode3["RESET_CONTENT"] = 205] = "RESET_CONTENT";
|
|
43
|
+
HttpStatusCode3[HttpStatusCode3["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
|
|
44
|
+
HttpStatusCode3[HttpStatusCode3["MULTI_STATUS"] = 207] = "MULTI_STATUS";
|
|
45
|
+
HttpStatusCode3[HttpStatusCode3["ALREADY_REPORTED"] = 208] = "ALREADY_REPORTED";
|
|
46
|
+
HttpStatusCode3[HttpStatusCode3["IM_USED"] = 226] = "IM_USED";
|
|
47
|
+
HttpStatusCode3[HttpStatusCode3["MULTIPLE_CHOICES"] = 300] = "MULTIPLE_CHOICES";
|
|
48
|
+
HttpStatusCode3[HttpStatusCode3["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
|
|
49
|
+
HttpStatusCode3[HttpStatusCode3["FOUND"] = 302] = "FOUND";
|
|
50
|
+
HttpStatusCode3[HttpStatusCode3["SEE_OTHER"] = 303] = "SEE_OTHER";
|
|
51
|
+
HttpStatusCode3[HttpStatusCode3["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
|
|
52
|
+
HttpStatusCode3[HttpStatusCode3["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
|
|
53
|
+
HttpStatusCode3[HttpStatusCode3["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
|
|
54
|
+
HttpStatusCode3[HttpStatusCode3["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
|
55
|
+
HttpStatusCode3[HttpStatusCode3["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
|
|
56
|
+
HttpStatusCode3[HttpStatusCode3["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
|
|
57
|
+
HttpStatusCode3[HttpStatusCode3["FORBIDDEN"] = 403] = "FORBIDDEN";
|
|
58
|
+
HttpStatusCode3[HttpStatusCode3["NOT_FOUND"] = 404] = "NOT_FOUND";
|
|
59
|
+
HttpStatusCode3[HttpStatusCode3["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
|
|
60
|
+
HttpStatusCode3[HttpStatusCode3["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
|
|
61
|
+
HttpStatusCode3[HttpStatusCode3["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
|
|
62
|
+
HttpStatusCode3[HttpStatusCode3["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
|
|
63
|
+
HttpStatusCode3[HttpStatusCode3["CONFLICT"] = 409] = "CONFLICT";
|
|
64
|
+
HttpStatusCode3[HttpStatusCode3["GONE"] = 410] = "GONE";
|
|
65
|
+
HttpStatusCode3[HttpStatusCode3["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
|
|
66
|
+
HttpStatusCode3[HttpStatusCode3["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
|
|
67
|
+
HttpStatusCode3[HttpStatusCode3["PAYLOAD_TOO_LARGE"] = 413] = "PAYLOAD_TOO_LARGE";
|
|
68
|
+
HttpStatusCode3[HttpStatusCode3["URI_TOO_LONG"] = 414] = "URI_TOO_LONG";
|
|
69
|
+
HttpStatusCode3[HttpStatusCode3["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
|
|
70
|
+
HttpStatusCode3[HttpStatusCode3["RANGE_NOT_SATISFIABLE"] = 416] = "RANGE_NOT_SATISFIABLE";
|
|
71
|
+
HttpStatusCode3[HttpStatusCode3["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
|
|
72
|
+
HttpStatusCode3[HttpStatusCode3["IM_A_TEAPOT"] = 418] = "IM_A_TEAPOT";
|
|
73
|
+
HttpStatusCode3[HttpStatusCode3["MISDIRECTED_REQUEST"] = 421] = "MISDIRECTED_REQUEST";
|
|
74
|
+
HttpStatusCode3[HttpStatusCode3["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
|
|
75
|
+
HttpStatusCode3[HttpStatusCode3["LOCKED"] = 423] = "LOCKED";
|
|
76
|
+
HttpStatusCode3[HttpStatusCode3["FAILED_DEPENDENCY"] = 424] = "FAILED_DEPENDENCY";
|
|
77
|
+
HttpStatusCode3[HttpStatusCode3["UPGRADE_REQUIRED"] = 426] = "UPGRADE_REQUIRED";
|
|
78
|
+
HttpStatusCode3[HttpStatusCode3["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED";
|
|
79
|
+
HttpStatusCode3[HttpStatusCode3["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
|
|
80
|
+
HttpStatusCode3[HttpStatusCode3["REQUEST_HEADER_FIELDS_TOO_LARGE"] = 431] = "REQUEST_HEADER_FIELDS_TOO_LARGE";
|
|
81
|
+
HttpStatusCode3[HttpStatusCode3["UNAVAILABLE_FOR_LEGAL_REASONS"] = 451] = "UNAVAILABLE_FOR_LEGAL_REASONS";
|
|
82
|
+
HttpStatusCode3[HttpStatusCode3["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
|
|
83
|
+
HttpStatusCode3[HttpStatusCode3["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
|
|
84
|
+
HttpStatusCode3[HttpStatusCode3["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
|
|
85
|
+
HttpStatusCode3[HttpStatusCode3["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
|
|
86
|
+
HttpStatusCode3[HttpStatusCode3["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
|
|
87
|
+
HttpStatusCode3[HttpStatusCode3["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
|
|
88
|
+
HttpStatusCode3[HttpStatusCode3["VARIANT_ALSO_NEGOTIATES"] = 506] = "VARIANT_ALSO_NEGOTIATES";
|
|
89
|
+
HttpStatusCode3[HttpStatusCode3["INSUFFICIENT_STORAGE"] = 507] = "INSUFFICIENT_STORAGE";
|
|
90
|
+
HttpStatusCode3[HttpStatusCode3["LOOP_DETECTED"] = 508] = "LOOP_DETECTED";
|
|
91
|
+
HttpStatusCode3[HttpStatusCode3["NOT_EXTENDED"] = 510] = "NOT_EXTENDED";
|
|
92
|
+
HttpStatusCode3[HttpStatusCode3["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
|
|
93
|
+
return HttpStatusCode3;
|
|
94
|
+
})(HttpStatusCode || {});
|
|
95
|
+
var HttpStatusCodeNameMap = {
|
|
96
|
+
[200 /* OK */]: "Ok",
|
|
97
|
+
[201 /* CREATED */]: "Created",
|
|
98
|
+
[202 /* ACCEPTED */]: "Accepted",
|
|
99
|
+
[204 /* NO_CONTENT */]: "NoContent",
|
|
100
|
+
[205 /* RESET_CONTENT */]: "ResetContent",
|
|
101
|
+
[206 /* PARTIAL_CONTENT */]: "PartialContent",
|
|
102
|
+
[207 /* MULTI_STATUS */]: "MultiStatus",
|
|
103
|
+
[208 /* ALREADY_REPORTED */]: "AlreadyReported",
|
|
104
|
+
[226 /* IM_USED */]: "ImUsed",
|
|
105
|
+
[300 /* MULTIPLE_CHOICES */]: "MultipleChoices",
|
|
106
|
+
[301 /* MOVED_PERMANENTLY */]: "MovedPermanently",
|
|
107
|
+
[302 /* FOUND */]: "Found",
|
|
108
|
+
[303 /* SEE_OTHER */]: "SeeOther",
|
|
109
|
+
[304 /* NOT_MODIFIED */]: "NotModified",
|
|
110
|
+
[307 /* TEMPORARY_REDIRECT */]: "TemporaryRedirect",
|
|
111
|
+
[308 /* PERMANENT_REDIRECT */]: "PermanentRedirect",
|
|
112
|
+
[400 /* BAD_REQUEST */]: "BadRequest",
|
|
113
|
+
[401 /* UNAUTHORIZED */]: "Unauthorized",
|
|
114
|
+
[402 /* PAYMENT_REQUIRED */]: "PaymentRequired",
|
|
115
|
+
[403 /* FORBIDDEN */]: "Forbidden",
|
|
116
|
+
[404 /* NOT_FOUND */]: "NotFound",
|
|
117
|
+
[405 /* METHOD_NOT_ALLOWED */]: "MethodNotAllowed",
|
|
118
|
+
[406 /* NOT_ACCEPTABLE */]: "NotAcceptable",
|
|
119
|
+
[407 /* PROXY_AUTHENTICATION_REQUIRED */]: "ProxyAuthenticationRequired",
|
|
120
|
+
[408 /* REQUEST_TIMEOUT */]: "RequestTimeout",
|
|
121
|
+
[409 /* CONFLICT */]: "Conflict",
|
|
122
|
+
[410 /* GONE */]: "Gone",
|
|
123
|
+
[411 /* LENGTH_REQUIRED */]: "LengthRequired",
|
|
124
|
+
[412 /* PRECONDITION_FAILED */]: "PreconditionFailed",
|
|
125
|
+
[413 /* PAYLOAD_TOO_LARGE */]: "PayloadTooLarge",
|
|
126
|
+
[414 /* URI_TOO_LONG */]: "UriTooLong",
|
|
127
|
+
[415 /* UNSUPPORTED_MEDIA_TYPE */]: "UnsupportedMediaType",
|
|
128
|
+
[416 /* RANGE_NOT_SATISFIABLE */]: "RangeNotSatisfiable",
|
|
129
|
+
[417 /* EXPECTATION_FAILED */]: "ExpectationFailed",
|
|
130
|
+
[418 /* IM_A_TEAPOT */]: "ImATeapot",
|
|
131
|
+
[421 /* MISDIRECTED_REQUEST */]: "MisdirectedRequest",
|
|
132
|
+
[422 /* UNPROCESSABLE_ENTITY */]: "UnprocessableEntity",
|
|
133
|
+
[423 /* LOCKED */]: "Locked",
|
|
134
|
+
[424 /* FAILED_DEPENDENCY */]: "FailedDependency",
|
|
135
|
+
[426 /* UPGRADE_REQUIRED */]: "UpgradeRequired",
|
|
136
|
+
[428 /* PRECONDITION_REQUIRED */]: "PreconditionRequired",
|
|
137
|
+
[429 /* TOO_MANY_REQUESTS */]: "TooManyRequests",
|
|
138
|
+
[431 /* REQUEST_HEADER_FIELDS_TOO_LARGE */]: "RequestHeaderFieldsTooLarge",
|
|
139
|
+
[451 /* UNAVAILABLE_FOR_LEGAL_REASONS */]: "UnavailableForLegalReasons",
|
|
140
|
+
[500 /* INTERNAL_SERVER_ERROR */]: "InternalServerError",
|
|
141
|
+
[501 /* NOT_IMPLEMENTED */]: "NotImplemented",
|
|
142
|
+
[502 /* BAD_GATEWAY */]: "BadGateway",
|
|
143
|
+
[503 /* SERVICE_UNAVAILABLE */]: "ServiceUnavailable",
|
|
144
|
+
[504 /* GATEWAY_TIMEOUT */]: "GatewayTimeout",
|
|
145
|
+
[505 /* HTTP_VERSION_NOT_SUPPORTED */]: "HttpVersionNotSupported",
|
|
146
|
+
[506 /* VARIANT_ALSO_NEGOTIATES */]: "VariantAlsoNegotiates",
|
|
147
|
+
[507 /* INSUFFICIENT_STORAGE */]: "InsufficientStorage",
|
|
148
|
+
[508 /* LOOP_DETECTED */]: "LoopDetected",
|
|
149
|
+
[510 /* NOT_EXTENDED */]: "NotExtended",
|
|
150
|
+
[511 /* NETWORK_AUTHENTICATION_REQUIRED */]: "NetworkAuthenticationRequired"
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
// src/HttpResponse.ts
|
|
154
|
+
var HttpResponse = class {
|
|
155
|
+
constructor(statusCode, header, body) {
|
|
156
|
+
this.statusCode = statusCode;
|
|
157
|
+
this.header = header;
|
|
158
|
+
this.body = body;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
// src/HttpMethod.ts
|
|
163
|
+
var HttpMethod = /* @__PURE__ */ ((HttpMethod3) => {
|
|
164
|
+
HttpMethod3["GET"] = "GET";
|
|
165
|
+
HttpMethod3["POST"] = "POST";
|
|
166
|
+
HttpMethod3["PUT"] = "PUT";
|
|
167
|
+
HttpMethod3["DELETE"] = "DELETE";
|
|
168
|
+
HttpMethod3["PATCH"] = "PATCH";
|
|
169
|
+
HttpMethod3["OPTIONS"] = "OPTIONS";
|
|
170
|
+
HttpMethod3["HEAD"] = "HEAD";
|
|
171
|
+
return HttpMethod3;
|
|
172
|
+
})(HttpMethod || {});
|
|
173
|
+
|
|
174
|
+
// src/HttpOperationDefinition.ts
|
|
175
|
+
var HttpOperationDefinition = class {
|
|
176
|
+
operationId;
|
|
177
|
+
path;
|
|
178
|
+
method;
|
|
179
|
+
summary;
|
|
180
|
+
request;
|
|
181
|
+
responses;
|
|
182
|
+
constructor(definition) {
|
|
183
|
+
this.operationId = definition.operationId;
|
|
184
|
+
this.path = definition.path;
|
|
185
|
+
this.method = definition.method;
|
|
186
|
+
this.summary = definition.summary;
|
|
187
|
+
this.request = definition.request;
|
|
188
|
+
this.responses = definition.responses;
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
// src/HttpRequestDefinition.ts
|
|
193
|
+
var HttpRequestDefinition = class {
|
|
194
|
+
header;
|
|
195
|
+
param;
|
|
196
|
+
query;
|
|
197
|
+
body;
|
|
198
|
+
constructor(definition) {
|
|
199
|
+
this.header = definition.header;
|
|
200
|
+
this.param = definition.param;
|
|
201
|
+
this.query = definition.query;
|
|
202
|
+
this.body = definition.body;
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
// src/HttpResponseDefinition.ts
|
|
207
|
+
var import_zod = require("zod");
|
|
208
|
+
var HttpResponseDefinition = class _HttpResponseDefinition {
|
|
209
|
+
constructor(definition) {
|
|
210
|
+
this.definition = definition;
|
|
211
|
+
this.name = definition.name;
|
|
212
|
+
this.statusCode = definition.statusCode;
|
|
213
|
+
this.description = definition.description;
|
|
214
|
+
this.header = definition.header;
|
|
215
|
+
this.body = definition.body;
|
|
216
|
+
}
|
|
217
|
+
name;
|
|
218
|
+
statusCode;
|
|
219
|
+
description;
|
|
220
|
+
header;
|
|
221
|
+
body;
|
|
222
|
+
extend(definition) {
|
|
223
|
+
const mergedHeader = (() => {
|
|
224
|
+
if (this.header instanceof import_zod.z.ZodRecord || definition.header instanceof import_zod.z.ZodRecord || this.header instanceof import_zod.z.ZodOptional && this.header.unwrap() instanceof import_zod.z.ZodRecord || definition.header instanceof import_zod.z.ZodOptional && definition.header.unwrap() instanceof import_zod.z.ZodRecord) {
|
|
225
|
+
throw new Error("Cannot merge ZodRecord headers");
|
|
226
|
+
}
|
|
227
|
+
if (!this.header && !definition.header) return void 0;
|
|
228
|
+
if (!this.header) return definition.header;
|
|
229
|
+
if (!definition.header) return this.header;
|
|
230
|
+
const mergedHeader2 = import_zod.z.object({
|
|
231
|
+
...this.header instanceof import_zod.z.ZodObject ? this.header.shape : this.header.unwrap().shape,
|
|
232
|
+
...definition.header instanceof import_zod.z.ZodObject ? definition.header.shape : definition.header.unwrap().shape
|
|
233
|
+
});
|
|
234
|
+
if (Object.values(mergedHeader2.shape).every(
|
|
235
|
+
(schema) => schema instanceof import_zod.z.ZodOptional
|
|
236
|
+
)) {
|
|
237
|
+
return mergedHeader2.optional();
|
|
238
|
+
}
|
|
239
|
+
return mergedHeader2;
|
|
240
|
+
})();
|
|
241
|
+
const mergedBody = (() => {
|
|
242
|
+
if (!this.body && !definition.body) return void 0;
|
|
243
|
+
if (!this.body) return definition.body;
|
|
244
|
+
if (!definition.body) return this.body;
|
|
245
|
+
if (this.body instanceof import_zod.z.ZodObject && definition.body instanceof import_zod.z.ZodObject) {
|
|
246
|
+
return import_zod.z.object({
|
|
247
|
+
...this.body.shape,
|
|
248
|
+
...definition.body.shape
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
return definition.body;
|
|
252
|
+
})();
|
|
253
|
+
const baseDefinition = {
|
|
254
|
+
...this.definition,
|
|
255
|
+
name: definition.name,
|
|
256
|
+
statusCode: definition.statusCode ?? this.statusCode,
|
|
257
|
+
description: definition.description ?? this.description,
|
|
258
|
+
header: mergedHeader,
|
|
259
|
+
body: mergedBody
|
|
260
|
+
};
|
|
261
|
+
return new _HttpResponseDefinition(baseDefinition);
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
// src/RequestValidationError.ts
|
|
266
|
+
var RequestValidationError = class extends Error {
|
|
267
|
+
message;
|
|
268
|
+
/** Validation issues found in HTTP headers */
|
|
269
|
+
headerIssues = [];
|
|
270
|
+
/** Validation issues found in request body */
|
|
271
|
+
bodyIssues = [];
|
|
272
|
+
/** Validation issues found in query parameters */
|
|
273
|
+
queryIssues = [];
|
|
274
|
+
/** Validation issues found in path parameters */
|
|
275
|
+
pathParamIssues = [];
|
|
276
|
+
constructor(input) {
|
|
277
|
+
const message = "Invalid request";
|
|
278
|
+
super(message);
|
|
279
|
+
this.message = message;
|
|
280
|
+
if (input?.headerIssues) {
|
|
281
|
+
this.headerIssues = input.headerIssues;
|
|
282
|
+
}
|
|
283
|
+
if (input?.bodyIssues) {
|
|
284
|
+
this.bodyIssues = input.bodyIssues;
|
|
285
|
+
}
|
|
286
|
+
if (input?.queryIssues) {
|
|
287
|
+
this.queryIssues = input.queryIssues;
|
|
288
|
+
}
|
|
289
|
+
if (input?.pathParamIssues) {
|
|
290
|
+
this.pathParamIssues = input.pathParamIssues;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Adds header validation issues to the error.
|
|
295
|
+
* @param issues - Array of Zod validation issues
|
|
296
|
+
*/
|
|
297
|
+
addHeaderIssues(issues) {
|
|
298
|
+
this.headerIssues.push(...issues);
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Adds body validation issues to the error.
|
|
302
|
+
* @param issues - Array of Zod validation issues
|
|
303
|
+
*/
|
|
304
|
+
addBodyIssues(issues) {
|
|
305
|
+
this.bodyIssues.push(...issues);
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Adds query parameter validation issues to the error.
|
|
309
|
+
* @param issues - Array of Zod validation issues
|
|
310
|
+
*/
|
|
311
|
+
addQueryIssues(issues) {
|
|
312
|
+
this.queryIssues.push(...issues);
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Adds path parameter validation issues to the error.
|
|
316
|
+
* @param issues - Array of Zod validation issues
|
|
317
|
+
*/
|
|
318
|
+
addPathParamIssues(issues) {
|
|
319
|
+
this.pathParamIssues.push(...issues);
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Checks if this error contains any validation issues.
|
|
323
|
+
* @returns true if any category has issues, false otherwise
|
|
324
|
+
*/
|
|
325
|
+
hasIssues() {
|
|
326
|
+
return this.headerIssues.length > 0 || this.bodyIssues.length > 0 || this.queryIssues.length > 0 || this.pathParamIssues.length > 0;
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
// src/ResponseValidationError.ts
|
|
331
|
+
var ResponseValidationError = class extends Error {
|
|
332
|
+
constructor(statusCode, input) {
|
|
333
|
+
const message = `Response validation failed for status code '${statusCode}'`;
|
|
334
|
+
super(message);
|
|
335
|
+
this.statusCode = statusCode;
|
|
336
|
+
this.message = message;
|
|
337
|
+
this.issues = input?.issues ?? [];
|
|
338
|
+
}
|
|
339
|
+
message;
|
|
340
|
+
issues;
|
|
341
|
+
addHeaderIssues(responseName, issues) {
|
|
342
|
+
this.addResponseIssues(responseName, issues);
|
|
343
|
+
}
|
|
344
|
+
addBodyIssues(responseName, issues) {
|
|
345
|
+
this.addResponseIssues(responseName, [], issues);
|
|
346
|
+
}
|
|
347
|
+
addResponseIssues(responseName, headerIssues = [], bodyIssues = []) {
|
|
348
|
+
if (headerIssues.length === 0 && bodyIssues.length === 0) {
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
const issue = this.issues.find(
|
|
352
|
+
(i) => i.type === "INVALID_RESPONSE" && i.responseName === responseName
|
|
353
|
+
);
|
|
354
|
+
if (!issue) {
|
|
355
|
+
this.issues.push({
|
|
356
|
+
type: "INVALID_RESPONSE",
|
|
357
|
+
responseName,
|
|
358
|
+
headerIssues,
|
|
359
|
+
bodyIssues
|
|
360
|
+
});
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
if (headerIssues.length > 0) {
|
|
364
|
+
issue.headerIssues.push(...headerIssues);
|
|
365
|
+
}
|
|
366
|
+
if (bodyIssues.length > 0) {
|
|
367
|
+
issue.bodyIssues.push(...bodyIssues);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
addStatusCodeIssue(expectedStatusCodes) {
|
|
371
|
+
const statusCodeIssue = this.issues.find(
|
|
372
|
+
(i) => i.type === "INVALID_STATUS_CODE"
|
|
373
|
+
);
|
|
374
|
+
if (statusCodeIssue) {
|
|
375
|
+
statusCodeIssue.expectedStatusCodes.push(...expectedStatusCodes);
|
|
376
|
+
} else {
|
|
377
|
+
this.issues.push({
|
|
378
|
+
type: "INVALID_STATUS_CODE",
|
|
379
|
+
invalidStatusCode: this.statusCode,
|
|
380
|
+
expectedStatusCodes
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
getResponseHeaderIssues(responseName) {
|
|
385
|
+
const issue = this.issues.find(
|
|
386
|
+
(i) => i.type === "INVALID_RESPONSE" && i.responseName === responseName
|
|
387
|
+
);
|
|
388
|
+
return issue ? issue.headerIssues : [];
|
|
389
|
+
}
|
|
390
|
+
getResponseBodyIssues(responseName) {
|
|
391
|
+
const issue = this.issues.find(
|
|
392
|
+
(i) => i.type === "INVALID_RESPONSE" && i.responseName === responseName
|
|
393
|
+
);
|
|
394
|
+
return issue ? issue.bodyIssues : [];
|
|
395
|
+
}
|
|
396
|
+
hasResponseIssues(responseName) {
|
|
397
|
+
if (responseName) {
|
|
398
|
+
return this.issues.some(
|
|
399
|
+
(issue) => issue.type === "INVALID_RESPONSE" && issue.responseName === responseName
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
return this.issues.some((issue) => issue.type === "INVALID_RESPONSE");
|
|
403
|
+
}
|
|
404
|
+
hasStatusCodeIssues() {
|
|
405
|
+
return this.issues.some((issue) => issue.type === "INVALID_STATUS_CODE");
|
|
406
|
+
}
|
|
407
|
+
hasIssues() {
|
|
408
|
+
return this.issues.length > 0;
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
// src/UnknownResponse.ts
|
|
413
|
+
var UnknownResponse = class extends HttpResponse {
|
|
414
|
+
constructor(statusCode, header, body, validationError) {
|
|
415
|
+
super(statusCode, header, body);
|
|
416
|
+
this.validationError = validationError;
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
420
|
+
0 && (module.exports = {
|
|
421
|
+
HttpMethod,
|
|
422
|
+
HttpOperationDefinition,
|
|
423
|
+
HttpRequestDefinition,
|
|
424
|
+
HttpResponse,
|
|
425
|
+
HttpResponseDefinition,
|
|
426
|
+
HttpStatusCode,
|
|
427
|
+
HttpStatusCodeNameMap,
|
|
428
|
+
RequestValidationError,
|
|
429
|
+
ResponseValidationError,
|
|
430
|
+
UnknownResponse
|
|
431
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import { ZodType, ZodObject, ZodString, ZodStringFormat, ZodLiteral, ZodEnum, ZodOptional, ZodArray, ZodRecord } from 'zod';
|
|
2
|
+
import { $ZodIssue } from 'zod/v4/core';
|
|
3
|
+
|
|
4
|
+
type IHttpBody = any | undefined;
|
|
5
|
+
type HttpBodySchema = ZodType;
|
|
6
|
+
|
|
7
|
+
type IHttpHeader = Record<string, string | string[]> | undefined;
|
|
8
|
+
type ZodStringType$1 = ZodString | ZodStringFormat | ZodLiteral<string> | ZodEnum<Record<string, string>>;
|
|
9
|
+
type HttpHeaderValue = ZodStringType$1 | ZodOptional<ZodStringType$1> | ZodArray<ZodStringType$1> | ZodOptional<ZodArray<ZodStringType$1>>;
|
|
10
|
+
type HttpHeaderObject = ZodObject<Record<string, HttpHeaderValue>> | ZodRecord<ZodStringType$1, HttpHeaderValue>;
|
|
11
|
+
type HttpHeaderSchema = HttpHeaderObject | ZodOptional<HttpHeaderObject>;
|
|
12
|
+
|
|
13
|
+
declare enum HttpMethod {
|
|
14
|
+
GET = "GET",
|
|
15
|
+
POST = "POST",
|
|
16
|
+
PUT = "PUT",
|
|
17
|
+
DELETE = "DELETE",
|
|
18
|
+
PATCH = "PATCH",
|
|
19
|
+
OPTIONS = "OPTIONS",
|
|
20
|
+
HEAD = "HEAD"
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type IHttpParam = Record<string, string> | undefined;
|
|
24
|
+
type HttpParamValue = ZodString | ZodStringFormat | ZodLiteral<string> | ZodEnum<Record<string, string>>;
|
|
25
|
+
type HttpParamSchema = ZodObject<Record<string, HttpParamValue>>;
|
|
26
|
+
|
|
27
|
+
type IHttpQuery = Record<string, string | string[]> | undefined;
|
|
28
|
+
type ZodStringType = ZodString | ZodStringFormat | ZodLiteral<string> | ZodEnum<Record<string, string>>;
|
|
29
|
+
type HttpQueryValue = ZodStringType | ZodOptional<ZodStringType> | ZodArray<ZodStringType> | ZodOptional<ZodArray<ZodStringType>>;
|
|
30
|
+
type HttpQueryObject = ZodObject<Record<string, HttpQueryValue>> | ZodRecord<ZodStringType, HttpQueryValue>;
|
|
31
|
+
type HttpQuerySchema = HttpQueryObject | ZodOptional<HttpQueryObject>;
|
|
32
|
+
|
|
33
|
+
type IHttpRequest<Header extends IHttpHeader = IHttpHeader, Param extends IHttpParam = IHttpParam, Query extends IHttpQuery = IHttpQuery, Body extends IHttpBody = IHttpBody> = {
|
|
34
|
+
body?: Body;
|
|
35
|
+
query?: Query;
|
|
36
|
+
param?: Param;
|
|
37
|
+
header?: Header;
|
|
38
|
+
path: string;
|
|
39
|
+
method: HttpMethod;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
declare enum HttpStatusCode {
|
|
43
|
+
OK = 200,
|
|
44
|
+
CREATED = 201,
|
|
45
|
+
ACCEPTED = 202,
|
|
46
|
+
NO_CONTENT = 204,
|
|
47
|
+
RESET_CONTENT = 205,
|
|
48
|
+
PARTIAL_CONTENT = 206,
|
|
49
|
+
MULTI_STATUS = 207,
|
|
50
|
+
ALREADY_REPORTED = 208,
|
|
51
|
+
IM_USED = 226,
|
|
52
|
+
MULTIPLE_CHOICES = 300,
|
|
53
|
+
MOVED_PERMANENTLY = 301,
|
|
54
|
+
FOUND = 302,
|
|
55
|
+
SEE_OTHER = 303,
|
|
56
|
+
NOT_MODIFIED = 304,
|
|
57
|
+
TEMPORARY_REDIRECT = 307,
|
|
58
|
+
PERMANENT_REDIRECT = 308,
|
|
59
|
+
BAD_REQUEST = 400,
|
|
60
|
+
UNAUTHORIZED = 401,
|
|
61
|
+
PAYMENT_REQUIRED = 402,
|
|
62
|
+
FORBIDDEN = 403,
|
|
63
|
+
NOT_FOUND = 404,
|
|
64
|
+
METHOD_NOT_ALLOWED = 405,
|
|
65
|
+
NOT_ACCEPTABLE = 406,
|
|
66
|
+
PROXY_AUTHENTICATION_REQUIRED = 407,
|
|
67
|
+
REQUEST_TIMEOUT = 408,
|
|
68
|
+
CONFLICT = 409,
|
|
69
|
+
GONE = 410,
|
|
70
|
+
LENGTH_REQUIRED = 411,
|
|
71
|
+
PRECONDITION_FAILED = 412,
|
|
72
|
+
PAYLOAD_TOO_LARGE = 413,
|
|
73
|
+
URI_TOO_LONG = 414,
|
|
74
|
+
UNSUPPORTED_MEDIA_TYPE = 415,
|
|
75
|
+
RANGE_NOT_SATISFIABLE = 416,
|
|
76
|
+
EXPECTATION_FAILED = 417,
|
|
77
|
+
IM_A_TEAPOT = 418,
|
|
78
|
+
MISDIRECTED_REQUEST = 421,
|
|
79
|
+
UNPROCESSABLE_ENTITY = 422,
|
|
80
|
+
LOCKED = 423,
|
|
81
|
+
FAILED_DEPENDENCY = 424,
|
|
82
|
+
UPGRADE_REQUIRED = 426,
|
|
83
|
+
PRECONDITION_REQUIRED = 428,
|
|
84
|
+
TOO_MANY_REQUESTS = 429,
|
|
85
|
+
REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
|
|
86
|
+
UNAVAILABLE_FOR_LEGAL_REASONS = 451,
|
|
87
|
+
INTERNAL_SERVER_ERROR = 500,
|
|
88
|
+
NOT_IMPLEMENTED = 501,
|
|
89
|
+
BAD_GATEWAY = 502,
|
|
90
|
+
SERVICE_UNAVAILABLE = 503,
|
|
91
|
+
GATEWAY_TIMEOUT = 504,
|
|
92
|
+
HTTP_VERSION_NOT_SUPPORTED = 505,
|
|
93
|
+
VARIANT_ALSO_NEGOTIATES = 506,
|
|
94
|
+
INSUFFICIENT_STORAGE = 507,
|
|
95
|
+
LOOP_DETECTED = 508,
|
|
96
|
+
NOT_EXTENDED = 510,
|
|
97
|
+
NETWORK_AUTHENTICATION_REQUIRED = 511
|
|
98
|
+
}
|
|
99
|
+
type HttpStatusCodeNameMapKey = (typeof HttpStatusCode)[keyof typeof HttpStatusCode];
|
|
100
|
+
declare const HttpStatusCodeNameMap: Record<HttpStatusCodeNameMapKey, string>;
|
|
101
|
+
|
|
102
|
+
type IHttpResponse<Header extends IHttpHeader = IHttpHeader, Body extends IHttpBody = IHttpBody> = {
|
|
103
|
+
statusCode: HttpStatusCode;
|
|
104
|
+
header?: Header;
|
|
105
|
+
body?: Body;
|
|
106
|
+
};
|
|
107
|
+
declare class HttpResponse<Header extends IHttpHeader = IHttpHeader, Body extends IHttpBody = IHttpBody> implements IHttpResponse<Header, Body> {
|
|
108
|
+
readonly statusCode: HttpStatusCode;
|
|
109
|
+
readonly header: Header;
|
|
110
|
+
readonly body: Body;
|
|
111
|
+
constructor(statusCode: HttpStatusCode, header: Header, body: Body);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
type IHttpRequestDefinition<THeader extends HttpHeaderSchema | undefined = HttpHeaderSchema | undefined, TParam extends HttpParamSchema | undefined = HttpParamSchema | undefined, TQuery extends HttpQuerySchema | undefined = HttpQuerySchema | undefined, TBody extends HttpBodySchema | undefined = HttpBodySchema | undefined> = {
|
|
115
|
+
header?: THeader;
|
|
116
|
+
param?: TParam;
|
|
117
|
+
query?: TQuery;
|
|
118
|
+
body?: TBody;
|
|
119
|
+
};
|
|
120
|
+
declare class HttpRequestDefinition<THeader extends HttpHeaderSchema | undefined, TParam extends HttpParamSchema | undefined, TQuery extends HttpQuerySchema | undefined, TBody extends HttpBodySchema | undefined> implements IHttpRequestDefinition<THeader, TParam, TQuery, TBody> {
|
|
121
|
+
readonly header?: THeader;
|
|
122
|
+
readonly param?: TParam;
|
|
123
|
+
readonly query?: TQuery;
|
|
124
|
+
readonly body?: TBody;
|
|
125
|
+
constructor(definition: IHttpRequestDefinition<THeader, TParam, TQuery, TBody>);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
type IHttpResponseDefinition<TName extends string = string, TStatusCode extends HttpStatusCode = HttpStatusCode, TDescription extends string = string, THeader extends HttpHeaderSchema | undefined = HttpHeaderSchema | undefined, TBody extends HttpBodySchema | undefined = HttpBodySchema | undefined> = {
|
|
129
|
+
name: TName;
|
|
130
|
+
statusCode: TStatusCode;
|
|
131
|
+
description: TDescription;
|
|
132
|
+
header?: THeader;
|
|
133
|
+
body?: TBody;
|
|
134
|
+
};
|
|
135
|
+
type IExtendHttpResponseDefinition<TName extends string, TStatusCode extends HttpStatusCode, TDescription extends string, THeader extends HttpHeaderSchema | undefined, TBody extends HttpBodySchema | undefined> = Partial<IHttpResponseDefinition<TName, TStatusCode, TDescription, THeader, TBody>> & Pick<IHttpResponseDefinition<TName, TStatusCode, TDescription, THeader, TBody>, "name">;
|
|
136
|
+
declare class HttpResponseDefinition<TName extends string, TStatusCode extends HttpStatusCode, TDescription extends string, THeader extends HttpHeaderSchema | undefined, TBody extends HttpBodySchema | undefined, TIsShared extends boolean> {
|
|
137
|
+
private definition;
|
|
138
|
+
name: TName;
|
|
139
|
+
statusCode: TStatusCode;
|
|
140
|
+
description: TDescription;
|
|
141
|
+
header?: THeader;
|
|
142
|
+
body?: TBody;
|
|
143
|
+
constructor(definition: IHttpResponseDefinition<TName, TStatusCode, TDescription, THeader, TBody>);
|
|
144
|
+
extend<EName extends string, EStatusCode extends HttpStatusCode = TStatusCode, EDescription extends string = TDescription, EHeader extends HttpHeaderSchema | undefined = THeader, EBody extends HttpBodySchema | undefined = TBody, EIsShared extends boolean = TIsShared>(definition: IExtendHttpResponseDefinition<EName, EStatusCode, EDescription, EHeader, EBody>): HttpResponseDefinition<EName, EStatusCode, EDescription, THeader extends undefined ? EHeader : EHeader extends undefined ? THeader : THeader & EHeader, TBody extends undefined ? EBody : EBody extends undefined ? TBody : TBody & EBody, EIsShared>;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Interface for HTTP operation definitions.
|
|
149
|
+
*
|
|
150
|
+
* Represents a complete HTTP API operation with:
|
|
151
|
+
* - Unique operation identifier
|
|
152
|
+
* - HTTP method and path
|
|
153
|
+
* - Request definition (headers, params, query, body)
|
|
154
|
+
* - Response definitions for different status codes
|
|
155
|
+
*
|
|
156
|
+
* @template TOperationId - The operation identifier literal type
|
|
157
|
+
* @template TPath - The URL path literal type
|
|
158
|
+
* @template TMethod - The HTTP method type
|
|
159
|
+
* @template TSummary - The operation summary literal type
|
|
160
|
+
* @template THeader - The header schema type
|
|
161
|
+
* @template TParam - The path parameter schema type
|
|
162
|
+
* @template TQuery - The query parameter schema type
|
|
163
|
+
* @template TBody - The request body schema type
|
|
164
|
+
* @template TRequest - The complete request definition type
|
|
165
|
+
* @template TResponses - The array of response definitions
|
|
166
|
+
*/
|
|
167
|
+
type IHttpOperationDefinition<TOperationId extends string = string, TPath extends string = string, TMethod extends HttpMethod = HttpMethod, TSummary extends string = string, THeader extends HttpHeaderSchema | undefined = HttpHeaderSchema | undefined, TParam extends HttpParamSchema | undefined = HttpParamSchema | undefined, TQuery extends HttpQuerySchema | undefined = HttpQuerySchema | undefined, TBody extends HttpBodySchema | undefined = HttpBodySchema | undefined, TRequest extends IHttpRequestDefinition<THeader, TParam, TQuery, TBody> = IHttpRequestDefinition<THeader, TParam, TQuery, TBody>, TResponses extends IHttpResponseDefinition[] = IHttpResponseDefinition[]> = {
|
|
168
|
+
operationId: TOperationId;
|
|
169
|
+
path: TPath;
|
|
170
|
+
method: TMethod;
|
|
171
|
+
summary: TSummary;
|
|
172
|
+
request: TRequest;
|
|
173
|
+
responses: TResponses;
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* Concrete implementation of HTTP operation definition.
|
|
177
|
+
*
|
|
178
|
+
* This class provides a type-safe way to define HTTP API operations with:
|
|
179
|
+
* - Full TypeScript type inference for all components
|
|
180
|
+
* - Integration with Zod schemas for runtime validation
|
|
181
|
+
* - Support for multiple response definitions per operation
|
|
182
|
+
* - OpenAPI-compatible structure
|
|
183
|
+
*
|
|
184
|
+
* The extensive generic parameters enable complete type safety from
|
|
185
|
+
* definition through to runtime execution and code generation.
|
|
186
|
+
*
|
|
187
|
+
* @template TOperationId - The operation identifier literal type
|
|
188
|
+
* @template TPath - The URL path literal type
|
|
189
|
+
* @template TMethod - The HTTP method type
|
|
190
|
+
* @template TSummary - The operation summary literal type
|
|
191
|
+
* @template THeader - The header schema type
|
|
192
|
+
* @template TParam - The path parameter schema type
|
|
193
|
+
* @template TQuery - The query parameter schema type
|
|
194
|
+
* @template TBody - The request body schema type
|
|
195
|
+
* @template TRequest - The complete request definition type
|
|
196
|
+
* @template TResponses - The array of response definitions
|
|
197
|
+
*/
|
|
198
|
+
declare class HttpOperationDefinition<TOperationId extends string, TPath extends string, TMethod extends HttpMethod, TSummary extends string, THeader extends HttpHeaderSchema | undefined, TParam extends HttpParamSchema | undefined, TQuery extends HttpQuerySchema | undefined, TBody extends HttpBodySchema | undefined, TRequest extends IHttpRequestDefinition<THeader, TParam, TQuery, TBody>, TResponses extends IHttpResponseDefinition[]> implements IHttpOperationDefinition<TOperationId, TPath, TMethod, TSummary, THeader, TParam, TQuery, TBody, TRequest, TResponses> {
|
|
199
|
+
readonly operationId: TOperationId;
|
|
200
|
+
readonly path: TPath;
|
|
201
|
+
readonly method: TMethod;
|
|
202
|
+
readonly summary: TSummary;
|
|
203
|
+
readonly request: TRequest;
|
|
204
|
+
readonly responses: TResponses;
|
|
205
|
+
constructor(definition: IHttpOperationDefinition<TOperationId, TPath, TMethod, TSummary, THeader, TParam, TQuery, TBody, TRequest, TResponses>);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Input configuration for RequestValidationError.
|
|
210
|
+
*/
|
|
211
|
+
type RequestValidationErrorInput = {
|
|
212
|
+
/** Validation issues found in HTTP headers */
|
|
213
|
+
headerIssues?: $ZodIssue[];
|
|
214
|
+
/** Validation issues found in request body */
|
|
215
|
+
bodyIssues?: $ZodIssue[];
|
|
216
|
+
/** Validation issues found in query parameters */
|
|
217
|
+
queryIssues?: $ZodIssue[];
|
|
218
|
+
/** Validation issues found in path parameters */
|
|
219
|
+
pathParamIssues?: $ZodIssue[];
|
|
220
|
+
};
|
|
221
|
+
/**
|
|
222
|
+
* Error thrown when HTTP request validation fails.
|
|
223
|
+
*
|
|
224
|
+
* This error provides detailed information about validation failures across
|
|
225
|
+
* different parts of an HTTP request. Each category of issues is stored
|
|
226
|
+
* separately for precise error reporting and debugging.
|
|
227
|
+
*
|
|
228
|
+
* The error integrates with Zod's issue format, making it compatible with
|
|
229
|
+
* Zod schema validation while maintaining flexibility for custom validators.
|
|
230
|
+
*/
|
|
231
|
+
declare class RequestValidationError extends Error {
|
|
232
|
+
readonly message: string;
|
|
233
|
+
/** Validation issues found in HTTP headers */
|
|
234
|
+
readonly headerIssues: $ZodIssue[];
|
|
235
|
+
/** Validation issues found in request body */
|
|
236
|
+
readonly bodyIssues: $ZodIssue[];
|
|
237
|
+
/** Validation issues found in query parameters */
|
|
238
|
+
readonly queryIssues: $ZodIssue[];
|
|
239
|
+
/** Validation issues found in path parameters */
|
|
240
|
+
readonly pathParamIssues: $ZodIssue[];
|
|
241
|
+
constructor(input?: RequestValidationErrorInput);
|
|
242
|
+
/**
|
|
243
|
+
* Adds header validation issues to the error.
|
|
244
|
+
* @param issues - Array of Zod validation issues
|
|
245
|
+
*/
|
|
246
|
+
addHeaderIssues(issues: $ZodIssue[]): void;
|
|
247
|
+
/**
|
|
248
|
+
* Adds body validation issues to the error.
|
|
249
|
+
* @param issues - Array of Zod validation issues
|
|
250
|
+
*/
|
|
251
|
+
addBodyIssues(issues: $ZodIssue[]): void;
|
|
252
|
+
/**
|
|
253
|
+
* Adds query parameter validation issues to the error.
|
|
254
|
+
* @param issues - Array of Zod validation issues
|
|
255
|
+
*/
|
|
256
|
+
addQueryIssues(issues: $ZodIssue[]): void;
|
|
257
|
+
/**
|
|
258
|
+
* Adds path parameter validation issues to the error.
|
|
259
|
+
* @param issues - Array of Zod validation issues
|
|
260
|
+
*/
|
|
261
|
+
addPathParamIssues(issues: $ZodIssue[]): void;
|
|
262
|
+
/**
|
|
263
|
+
* Checks if this error contains any validation issues.
|
|
264
|
+
* @returns true if any category has issues, false otherwise
|
|
265
|
+
*/
|
|
266
|
+
hasIssues(): boolean;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
type ValidationSuccessResult$1<T> = {
|
|
270
|
+
isValid: true;
|
|
271
|
+
data: T;
|
|
272
|
+
};
|
|
273
|
+
type ValidationFailureResult$1 = {
|
|
274
|
+
isValid: false;
|
|
275
|
+
error: RequestValidationError;
|
|
276
|
+
};
|
|
277
|
+
type SafeRequestValidationResult<T> = ValidationSuccessResult$1<T> | ValidationFailureResult$1;
|
|
278
|
+
/**
|
|
279
|
+
* Interface for HTTP request validators.
|
|
280
|
+
*/
|
|
281
|
+
type IRequestValidator = {
|
|
282
|
+
/**
|
|
283
|
+
* Validates a request and returns a result object.
|
|
284
|
+
* Does not throw errors.
|
|
285
|
+
*/
|
|
286
|
+
safeValidate(request: IHttpRequest): SafeRequestValidationResult<IHttpRequest>;
|
|
287
|
+
/**
|
|
288
|
+
* Validates a request and returns the validated request.
|
|
289
|
+
* @throws {RequestValidationError} If validation fails
|
|
290
|
+
*/
|
|
291
|
+
validate(request: IHttpRequest): IHttpRequest;
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
type InvalidResponseIssue = {
|
|
295
|
+
readonly type: "INVALID_RESPONSE";
|
|
296
|
+
readonly responseName: string;
|
|
297
|
+
readonly headerIssues: $ZodIssue[];
|
|
298
|
+
readonly bodyIssues: $ZodIssue[];
|
|
299
|
+
};
|
|
300
|
+
type InvalidStatusCodeIssue = {
|
|
301
|
+
readonly type: "INVALID_STATUS_CODE";
|
|
302
|
+
readonly invalidStatusCode: HttpStatusCode;
|
|
303
|
+
readonly expectedStatusCodes: HttpStatusCode[];
|
|
304
|
+
};
|
|
305
|
+
type ValidationIssue = InvalidResponseIssue | InvalidStatusCodeIssue;
|
|
306
|
+
type ResponseValidationErrorInput = {
|
|
307
|
+
readonly issues?: ValidationIssue[];
|
|
308
|
+
};
|
|
309
|
+
declare class ResponseValidationError extends Error {
|
|
310
|
+
readonly statusCode: HttpStatusCode;
|
|
311
|
+
readonly message: string;
|
|
312
|
+
readonly issues: ValidationIssue[];
|
|
313
|
+
constructor(statusCode: HttpStatusCode, input?: ResponseValidationErrorInput);
|
|
314
|
+
addHeaderIssues(responseName: string, issues: $ZodIssue[]): void;
|
|
315
|
+
addBodyIssues(responseName: string, issues: $ZodIssue[]): void;
|
|
316
|
+
addResponseIssues(responseName: string, headerIssues?: $ZodIssue[], bodyIssues?: $ZodIssue[]): void;
|
|
317
|
+
addStatusCodeIssue(expectedStatusCodes: HttpStatusCode[]): void;
|
|
318
|
+
getResponseHeaderIssues(responseName: string): $ZodIssue[];
|
|
319
|
+
getResponseBodyIssues(responseName: string): $ZodIssue[];
|
|
320
|
+
hasResponseIssues(responseName?: string | undefined): boolean;
|
|
321
|
+
hasStatusCodeIssues(): boolean;
|
|
322
|
+
hasIssues(): boolean;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
type ValidationSuccessResult<T> = {
|
|
326
|
+
readonly isValid: true;
|
|
327
|
+
readonly data: T;
|
|
328
|
+
};
|
|
329
|
+
type ValidationFailureResult = {
|
|
330
|
+
readonly isValid: false;
|
|
331
|
+
readonly error: ResponseValidationError;
|
|
332
|
+
};
|
|
333
|
+
type SafeResponseValidationResult<T> = ValidationSuccessResult<T> | ValidationFailureResult;
|
|
334
|
+
/**
|
|
335
|
+
* Interface for HTTP response validators.
|
|
336
|
+
*/
|
|
337
|
+
type IResponseValidator = {
|
|
338
|
+
/**
|
|
339
|
+
* Validates a response and returns a result object.
|
|
340
|
+
* Does not throw errors.
|
|
341
|
+
*/
|
|
342
|
+
safeValidate(response: IHttpResponse): SafeResponseValidationResult<IHttpResponse>;
|
|
343
|
+
/**
|
|
344
|
+
* Validates a response and returns the validated response.
|
|
345
|
+
* @throws {ResponseValidationError} If validation fails
|
|
346
|
+
*/
|
|
347
|
+
validate(response: IHttpResponse): IHttpResponse;
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
declare class UnknownResponse<Header extends IHttpHeader = IHttpHeader, Body extends IHttpBody = unknown> extends HttpResponse<Header, Body> {
|
|
351
|
+
readonly validationError: ResponseValidationError;
|
|
352
|
+
constructor(statusCode: HttpStatusCode, header: Header, body: Body, validationError: ResponseValidationError);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export { type HttpBodySchema, type HttpHeaderSchema, HttpMethod, HttpOperationDefinition, type HttpParamSchema, type HttpQuerySchema, HttpRequestDefinition, HttpResponse, HttpResponseDefinition, HttpStatusCode, HttpStatusCodeNameMap, type IExtendHttpResponseDefinition, type IHttpBody, type IHttpHeader, type IHttpOperationDefinition, type IHttpParam, type IHttpQuery, type IHttpRequest, type IHttpRequestDefinition, type IHttpResponse, type IHttpResponseDefinition, type IRequestValidator, type IResponseValidator, type InvalidResponseIssue, type InvalidStatusCodeIssue, RequestValidationError, type RequestValidationErrorInput, ResponseValidationError, type ResponseValidationErrorInput, type SafeRequestValidationResult, type SafeResponseValidationResult, UnknownResponse, type ValidationIssue };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { ZodType, ZodObject, ZodString, ZodStringFormat, ZodLiteral, ZodEnum, ZodOptional, ZodArray } from 'zod';
|
|
1
|
+
import { ZodType, ZodObject, ZodString, ZodStringFormat, ZodLiteral, ZodEnum, ZodOptional, ZodArray, ZodRecord } from 'zod';
|
|
2
2
|
import { $ZodIssue } from 'zod/v4/core';
|
|
3
3
|
|
|
4
4
|
type IHttpBody = any | undefined;
|
|
5
5
|
type HttpBodySchema = ZodType;
|
|
6
6
|
|
|
7
7
|
type IHttpHeader = Record<string, string | string[]> | undefined;
|
|
8
|
-
type
|
|
9
|
-
type
|
|
8
|
+
type ZodStringType$1 = ZodString | ZodStringFormat | ZodLiteral<string> | ZodEnum<Record<string, string>>;
|
|
9
|
+
type HttpHeaderValue = ZodStringType$1 | ZodOptional<ZodStringType$1> | ZodArray<ZodStringType$1> | ZodOptional<ZodArray<ZodStringType$1>>;
|
|
10
|
+
type HttpHeaderObject = ZodObject<Record<string, HttpHeaderValue>> | ZodRecord<ZodStringType$1, HttpHeaderValue>;
|
|
10
11
|
type HttpHeaderSchema = HttpHeaderObject | ZodOptional<HttpHeaderObject>;
|
|
11
12
|
|
|
12
13
|
declare enum HttpMethod {
|
|
@@ -24,8 +25,9 @@ type HttpParamValue = ZodString | ZodStringFormat | ZodLiteral<string> | ZodEnum
|
|
|
24
25
|
type HttpParamSchema = ZodObject<Record<string, HttpParamValue>>;
|
|
25
26
|
|
|
26
27
|
type IHttpQuery = Record<string, string | string[]> | undefined;
|
|
27
|
-
type
|
|
28
|
-
type
|
|
28
|
+
type ZodStringType = ZodString | ZodStringFormat | ZodLiteral<string> | ZodEnum<Record<string, string>>;
|
|
29
|
+
type HttpQueryValue = ZodStringType | ZodOptional<ZodStringType> | ZodArray<ZodStringType> | ZodOptional<ZodArray<ZodStringType>>;
|
|
30
|
+
type HttpQueryObject = ZodObject<Record<string, HttpQueryValue>> | ZodRecord<ZodStringType, HttpQueryValue>;
|
|
29
31
|
type HttpQuerySchema = HttpQueryObject | ZodOptional<HttpQueryObject>;
|
|
30
32
|
|
|
31
33
|
type IHttpRequest<Header extends IHttpHeader = IHttpHeader, Param extends IHttpParam = IHttpParam, Query extends IHttpQuery = IHttpQuery, Body extends IHttpBody = IHttpBody> = {
|
|
@@ -47,6 +49,13 @@ declare enum HttpStatusCode {
|
|
|
47
49
|
MULTI_STATUS = 207,
|
|
48
50
|
ALREADY_REPORTED = 208,
|
|
49
51
|
IM_USED = 226,
|
|
52
|
+
MULTIPLE_CHOICES = 300,
|
|
53
|
+
MOVED_PERMANENTLY = 301,
|
|
54
|
+
FOUND = 302,
|
|
55
|
+
SEE_OTHER = 303,
|
|
56
|
+
NOT_MODIFIED = 304,
|
|
57
|
+
TEMPORARY_REDIRECT = 307,
|
|
58
|
+
PERMANENT_REDIRECT = 308,
|
|
50
59
|
BAD_REQUEST = 400,
|
|
51
60
|
UNAUTHORIZED = 401,
|
|
52
61
|
PAYMENT_REQUIRED = 402,
|
|
@@ -343,5 +352,4 @@ declare class UnknownResponse<Header extends IHttpHeader = IHttpHeader, Body ext
|
|
|
343
352
|
constructor(statusCode: HttpStatusCode, header: Header, body: Body, validationError: ResponseValidationError);
|
|
344
353
|
}
|
|
345
354
|
|
|
346
|
-
export { HttpMethod, HttpOperationDefinition, HttpRequestDefinition, HttpResponse, HttpResponseDefinition, HttpStatusCode, HttpStatusCodeNameMap, RequestValidationError, ResponseValidationError, UnknownResponse };
|
|
347
|
-
export type { HttpBodySchema, HttpHeaderSchema, HttpParamSchema, HttpQuerySchema, IExtendHttpResponseDefinition, IHttpBody, IHttpHeader, IHttpOperationDefinition, IHttpParam, IHttpQuery, IHttpRequest, IHttpRequestDefinition, IHttpResponse, IHttpResponseDefinition, IRequestValidator, IResponseValidator, InvalidResponseIssue, InvalidStatusCodeIssue, RequestValidationErrorInput, ResponseValidationErrorInput, SafeRequestValidationResult, SafeResponseValidationResult, ValidationIssue };
|
|
355
|
+
export { type HttpBodySchema, type HttpHeaderSchema, HttpMethod, HttpOperationDefinition, type HttpParamSchema, type HttpQuerySchema, HttpRequestDefinition, HttpResponse, HttpResponseDefinition, HttpStatusCode, HttpStatusCodeNameMap, type IExtendHttpResponseDefinition, type IHttpBody, type IHttpHeader, type IHttpOperationDefinition, type IHttpParam, type IHttpQuery, type IHttpRequest, type IHttpRequestDefinition, type IHttpResponse, type IHttpResponseDefinition, type IRequestValidator, type IResponseValidator, type InvalidResponseIssue, type InvalidStatusCodeIssue, RequestValidationError, type RequestValidationErrorInput, ResponseValidationError, type ResponseValidationErrorInput, type SafeRequestValidationResult, type SafeResponseValidationResult, UnknownResponse, type ValidationIssue };
|
package/dist/index.js
CHANGED
|
@@ -1,57 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
1
|
+
// src/HttpStatusCode.ts
|
|
2
|
+
var HttpStatusCode = /* @__PURE__ */ ((HttpStatusCode3) => {
|
|
3
|
+
HttpStatusCode3[HttpStatusCode3["OK"] = 200] = "OK";
|
|
4
|
+
HttpStatusCode3[HttpStatusCode3["CREATED"] = 201] = "CREATED";
|
|
5
|
+
HttpStatusCode3[HttpStatusCode3["ACCEPTED"] = 202] = "ACCEPTED";
|
|
6
|
+
HttpStatusCode3[HttpStatusCode3["NO_CONTENT"] = 204] = "NO_CONTENT";
|
|
7
|
+
HttpStatusCode3[HttpStatusCode3["RESET_CONTENT"] = 205] = "RESET_CONTENT";
|
|
8
|
+
HttpStatusCode3[HttpStatusCode3["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
|
|
9
|
+
HttpStatusCode3[HttpStatusCode3["MULTI_STATUS"] = 207] = "MULTI_STATUS";
|
|
10
|
+
HttpStatusCode3[HttpStatusCode3["ALREADY_REPORTED"] = 208] = "ALREADY_REPORTED";
|
|
11
|
+
HttpStatusCode3[HttpStatusCode3["IM_USED"] = 226] = "IM_USED";
|
|
12
|
+
HttpStatusCode3[HttpStatusCode3["MULTIPLE_CHOICES"] = 300] = "MULTIPLE_CHOICES";
|
|
13
|
+
HttpStatusCode3[HttpStatusCode3["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
|
|
14
|
+
HttpStatusCode3[HttpStatusCode3["FOUND"] = 302] = "FOUND";
|
|
15
|
+
HttpStatusCode3[HttpStatusCode3["SEE_OTHER"] = 303] = "SEE_OTHER";
|
|
16
|
+
HttpStatusCode3[HttpStatusCode3["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
|
|
17
|
+
HttpStatusCode3[HttpStatusCode3["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
|
|
18
|
+
HttpStatusCode3[HttpStatusCode3["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
|
|
19
|
+
HttpStatusCode3[HttpStatusCode3["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
|
20
|
+
HttpStatusCode3[HttpStatusCode3["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
|
|
21
|
+
HttpStatusCode3[HttpStatusCode3["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
|
|
22
|
+
HttpStatusCode3[HttpStatusCode3["FORBIDDEN"] = 403] = "FORBIDDEN";
|
|
23
|
+
HttpStatusCode3[HttpStatusCode3["NOT_FOUND"] = 404] = "NOT_FOUND";
|
|
24
|
+
HttpStatusCode3[HttpStatusCode3["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
|
|
25
|
+
HttpStatusCode3[HttpStatusCode3["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
|
|
26
|
+
HttpStatusCode3[HttpStatusCode3["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
|
|
27
|
+
HttpStatusCode3[HttpStatusCode3["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
|
|
28
|
+
HttpStatusCode3[HttpStatusCode3["CONFLICT"] = 409] = "CONFLICT";
|
|
29
|
+
HttpStatusCode3[HttpStatusCode3["GONE"] = 410] = "GONE";
|
|
30
|
+
HttpStatusCode3[HttpStatusCode3["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
|
|
31
|
+
HttpStatusCode3[HttpStatusCode3["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
|
|
32
|
+
HttpStatusCode3[HttpStatusCode3["PAYLOAD_TOO_LARGE"] = 413] = "PAYLOAD_TOO_LARGE";
|
|
33
|
+
HttpStatusCode3[HttpStatusCode3["URI_TOO_LONG"] = 414] = "URI_TOO_LONG";
|
|
34
|
+
HttpStatusCode3[HttpStatusCode3["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
|
|
35
|
+
HttpStatusCode3[HttpStatusCode3["RANGE_NOT_SATISFIABLE"] = 416] = "RANGE_NOT_SATISFIABLE";
|
|
36
|
+
HttpStatusCode3[HttpStatusCode3["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
|
|
37
|
+
HttpStatusCode3[HttpStatusCode3["IM_A_TEAPOT"] = 418] = "IM_A_TEAPOT";
|
|
38
|
+
HttpStatusCode3[HttpStatusCode3["MISDIRECTED_REQUEST"] = 421] = "MISDIRECTED_REQUEST";
|
|
39
|
+
HttpStatusCode3[HttpStatusCode3["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
|
|
40
|
+
HttpStatusCode3[HttpStatusCode3["LOCKED"] = 423] = "LOCKED";
|
|
41
|
+
HttpStatusCode3[HttpStatusCode3["FAILED_DEPENDENCY"] = 424] = "FAILED_DEPENDENCY";
|
|
42
|
+
HttpStatusCode3[HttpStatusCode3["UPGRADE_REQUIRED"] = 426] = "UPGRADE_REQUIRED";
|
|
43
|
+
HttpStatusCode3[HttpStatusCode3["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED";
|
|
44
|
+
HttpStatusCode3[HttpStatusCode3["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
|
|
45
|
+
HttpStatusCode3[HttpStatusCode3["REQUEST_HEADER_FIELDS_TOO_LARGE"] = 431] = "REQUEST_HEADER_FIELDS_TOO_LARGE";
|
|
46
|
+
HttpStatusCode3[HttpStatusCode3["UNAVAILABLE_FOR_LEGAL_REASONS"] = 451] = "UNAVAILABLE_FOR_LEGAL_REASONS";
|
|
47
|
+
HttpStatusCode3[HttpStatusCode3["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
|
|
48
|
+
HttpStatusCode3[HttpStatusCode3["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
|
|
49
|
+
HttpStatusCode3[HttpStatusCode3["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
|
|
50
|
+
HttpStatusCode3[HttpStatusCode3["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
|
|
51
|
+
HttpStatusCode3[HttpStatusCode3["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
|
|
52
|
+
HttpStatusCode3[HttpStatusCode3["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
|
|
53
|
+
HttpStatusCode3[HttpStatusCode3["VARIANT_ALSO_NEGOTIATES"] = 506] = "VARIANT_ALSO_NEGOTIATES";
|
|
54
|
+
HttpStatusCode3[HttpStatusCode3["INSUFFICIENT_STORAGE"] = 507] = "INSUFFICIENT_STORAGE";
|
|
55
|
+
HttpStatusCode3[HttpStatusCode3["LOOP_DETECTED"] = 508] = "LOOP_DETECTED";
|
|
56
|
+
HttpStatusCode3[HttpStatusCode3["NOT_EXTENDED"] = 510] = "NOT_EXTENDED";
|
|
57
|
+
HttpStatusCode3[HttpStatusCode3["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
|
|
58
|
+
return HttpStatusCode3;
|
|
53
59
|
})(HttpStatusCode || {});
|
|
54
|
-
|
|
60
|
+
var HttpStatusCodeNameMap = {
|
|
55
61
|
[200 /* OK */]: "Ok",
|
|
56
62
|
[201 /* CREATED */]: "Created",
|
|
57
63
|
[202 /* ACCEPTED */]: "Accepted",
|
|
@@ -61,6 +67,13 @@ const HttpStatusCodeNameMap = {
|
|
|
61
67
|
[207 /* MULTI_STATUS */]: "MultiStatus",
|
|
62
68
|
[208 /* ALREADY_REPORTED */]: "AlreadyReported",
|
|
63
69
|
[226 /* IM_USED */]: "ImUsed",
|
|
70
|
+
[300 /* MULTIPLE_CHOICES */]: "MultipleChoices",
|
|
71
|
+
[301 /* MOVED_PERMANENTLY */]: "MovedPermanently",
|
|
72
|
+
[302 /* FOUND */]: "Found",
|
|
73
|
+
[303 /* SEE_OTHER */]: "SeeOther",
|
|
74
|
+
[304 /* NOT_MODIFIED */]: "NotModified",
|
|
75
|
+
[307 /* TEMPORARY_REDIRECT */]: "TemporaryRedirect",
|
|
76
|
+
[308 /* PERMANENT_REDIRECT */]: "PermanentRedirect",
|
|
64
77
|
[400 /* BAD_REQUEST */]: "BadRequest",
|
|
65
78
|
[401 /* UNAUTHORIZED */]: "Unauthorized",
|
|
66
79
|
[402 /* PAYMENT_REQUIRED */]: "PaymentRequired",
|
|
@@ -102,26 +115,29 @@ const HttpStatusCodeNameMap = {
|
|
|
102
115
|
[511 /* NETWORK_AUTHENTICATION_REQUIRED */]: "NetworkAuthenticationRequired"
|
|
103
116
|
};
|
|
104
117
|
|
|
105
|
-
|
|
118
|
+
// src/HttpResponse.ts
|
|
119
|
+
var HttpResponse = class {
|
|
106
120
|
constructor(statusCode, header, body) {
|
|
107
121
|
this.statusCode = statusCode;
|
|
108
122
|
this.header = header;
|
|
109
123
|
this.body = body;
|
|
110
124
|
}
|
|
111
|
-
}
|
|
125
|
+
};
|
|
112
126
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
127
|
+
// src/HttpMethod.ts
|
|
128
|
+
var HttpMethod = /* @__PURE__ */ ((HttpMethod3) => {
|
|
129
|
+
HttpMethod3["GET"] = "GET";
|
|
130
|
+
HttpMethod3["POST"] = "POST";
|
|
131
|
+
HttpMethod3["PUT"] = "PUT";
|
|
132
|
+
HttpMethod3["DELETE"] = "DELETE";
|
|
133
|
+
HttpMethod3["PATCH"] = "PATCH";
|
|
134
|
+
HttpMethod3["OPTIONS"] = "OPTIONS";
|
|
135
|
+
HttpMethod3["HEAD"] = "HEAD";
|
|
136
|
+
return HttpMethod3;
|
|
122
137
|
})(HttpMethod || {});
|
|
123
138
|
|
|
124
|
-
|
|
139
|
+
// src/HttpOperationDefinition.ts
|
|
140
|
+
var HttpOperationDefinition = class {
|
|
125
141
|
operationId;
|
|
126
142
|
path;
|
|
127
143
|
method;
|
|
@@ -136,9 +152,10 @@ class HttpOperationDefinition {
|
|
|
136
152
|
this.request = definition.request;
|
|
137
153
|
this.responses = definition.responses;
|
|
138
154
|
}
|
|
139
|
-
}
|
|
155
|
+
};
|
|
140
156
|
|
|
141
|
-
|
|
157
|
+
// src/HttpRequestDefinition.ts
|
|
158
|
+
var HttpRequestDefinition = class {
|
|
142
159
|
header;
|
|
143
160
|
param;
|
|
144
161
|
query;
|
|
@@ -149,9 +166,11 @@ class HttpRequestDefinition {
|
|
|
149
166
|
this.query = definition.query;
|
|
150
167
|
this.body = definition.body;
|
|
151
168
|
}
|
|
152
|
-
}
|
|
169
|
+
};
|
|
153
170
|
|
|
154
|
-
|
|
171
|
+
// src/HttpResponseDefinition.ts
|
|
172
|
+
import { z } from "zod";
|
|
173
|
+
var HttpResponseDefinition = class _HttpResponseDefinition {
|
|
155
174
|
constructor(definition) {
|
|
156
175
|
this.definition = definition;
|
|
157
176
|
this.name = definition.name;
|
|
@@ -167,6 +186,9 @@ class HttpResponseDefinition {
|
|
|
167
186
|
body;
|
|
168
187
|
extend(definition) {
|
|
169
188
|
const mergedHeader = (() => {
|
|
189
|
+
if (this.header instanceof z.ZodRecord || definition.header instanceof z.ZodRecord || this.header instanceof z.ZodOptional && this.header.unwrap() instanceof z.ZodRecord || definition.header instanceof z.ZodOptional && definition.header.unwrap() instanceof z.ZodRecord) {
|
|
190
|
+
throw new Error("Cannot merge ZodRecord headers");
|
|
191
|
+
}
|
|
170
192
|
if (!this.header && !definition.header) return void 0;
|
|
171
193
|
if (!this.header) return definition.header;
|
|
172
194
|
if (!definition.header) return this.header;
|
|
@@ -201,11 +223,12 @@ class HttpResponseDefinition {
|
|
|
201
223
|
header: mergedHeader,
|
|
202
224
|
body: mergedBody
|
|
203
225
|
};
|
|
204
|
-
return new
|
|
226
|
+
return new _HttpResponseDefinition(baseDefinition);
|
|
205
227
|
}
|
|
206
|
-
}
|
|
228
|
+
};
|
|
207
229
|
|
|
208
|
-
|
|
230
|
+
// src/RequestValidationError.ts
|
|
231
|
+
var RequestValidationError = class extends Error {
|
|
209
232
|
message;
|
|
210
233
|
/** Validation issues found in HTTP headers */
|
|
211
234
|
headerIssues = [];
|
|
@@ -267,9 +290,10 @@ class RequestValidationError extends Error {
|
|
|
267
290
|
hasIssues() {
|
|
268
291
|
return this.headerIssues.length > 0 || this.bodyIssues.length > 0 || this.queryIssues.length > 0 || this.pathParamIssues.length > 0;
|
|
269
292
|
}
|
|
270
|
-
}
|
|
293
|
+
};
|
|
271
294
|
|
|
272
|
-
|
|
295
|
+
// src/ResponseValidationError.ts
|
|
296
|
+
var ResponseValidationError = class extends Error {
|
|
273
297
|
constructor(statusCode, input) {
|
|
274
298
|
const message = `Response validation failed for status code '${statusCode}'`;
|
|
275
299
|
super(message);
|
|
@@ -348,13 +372,24 @@ class ResponseValidationError extends Error {
|
|
|
348
372
|
hasIssues() {
|
|
349
373
|
return this.issues.length > 0;
|
|
350
374
|
}
|
|
351
|
-
}
|
|
375
|
+
};
|
|
352
376
|
|
|
353
|
-
|
|
377
|
+
// src/UnknownResponse.ts
|
|
378
|
+
var UnknownResponse = class extends HttpResponse {
|
|
354
379
|
constructor(statusCode, header, body, validationError) {
|
|
355
380
|
super(statusCode, header, body);
|
|
356
381
|
this.validationError = validationError;
|
|
357
382
|
}
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
|
|
383
|
+
};
|
|
384
|
+
export {
|
|
385
|
+
HttpMethod,
|
|
386
|
+
HttpOperationDefinition,
|
|
387
|
+
HttpRequestDefinition,
|
|
388
|
+
HttpResponse,
|
|
389
|
+
HttpResponseDefinition,
|
|
390
|
+
HttpStatusCode,
|
|
391
|
+
HttpStatusCodeNameMap,
|
|
392
|
+
RequestValidationError,
|
|
393
|
+
ResponseValidationError,
|
|
394
|
+
UnknownResponse
|
|
395
|
+
};
|
package/package.json
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rexeus/typeweaver-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Runtime utilities and shared types to drive type-safe API definitions. Powered by Typeweaver 🧵✨",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "dist/index.
|
|
6
|
+
"main": "dist/index.cjs",
|
|
7
|
+
"module": "dist/index.js",
|
|
7
8
|
"types": "dist/index.d.ts",
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
10
|
-
"import":
|
|
11
|
-
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
12
19
|
}
|
|
13
20
|
},
|
|
14
21
|
"files": [
|
|
@@ -39,15 +46,15 @@
|
|
|
39
46
|
},
|
|
40
47
|
"homepage": "https://github.com/rexeus/typeweaver#readme",
|
|
41
48
|
"peerDependencies": {
|
|
42
|
-
"zod": "^4.
|
|
49
|
+
"zod": "^4.3.5"
|
|
43
50
|
},
|
|
44
51
|
"devDependencies": {
|
|
45
|
-
"zod": "^4.
|
|
52
|
+
"zod": "^4.3.5"
|
|
46
53
|
},
|
|
47
54
|
"scripts": {
|
|
48
55
|
"typecheck": "tsc --noEmit",
|
|
49
56
|
"format": "prettier --write .",
|
|
50
|
-
"build": "
|
|
57
|
+
"build": "tsup && cp ../../LICENSE ../../NOTICE ./dist/",
|
|
51
58
|
"preversion": "npm run build"
|
|
52
59
|
}
|
|
53
60
|
}
|