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