@orpc/openapi 2.0.0-beta.47 → 2.0.0-beta.49
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/README.md +6 -7
- package/dist/adapters/aws-lambda/index.d.ts +10 -22
- package/dist/adapters/aws-lambda/index.js +1 -0
- package/dist/adapters/aws-lambda/openapi-handler.d.ts +18 -0
- package/dist/adapters/aws-lambda/openapi-handler.js +18 -0
- package/dist/adapters/fastify/index.d.ts +1 -23
- package/dist/adapters/fastify/index.js +1 -0
- package/dist/adapters/fastify/openapi-handler.d.ts +15 -0
- package/dist/adapters/fastify/openapi-handler.js +15 -0
- package/dist/adapters/fetch/index.d.ts +2 -37
- package/dist/adapters/fetch/index.js +2 -0
- package/dist/adapters/fetch/openapi-handler.d.ts +15 -0
- package/dist/adapters/fetch/openapi-handler.js +15 -0
- package/dist/adapters/fetch/openapi-link.d.ts +21 -0
- package/dist/adapters/fetch/openapi-link.js +20 -0
- package/dist/adapters/node/index.d.ts +1 -23
- package/dist/adapters/node/index.js +1 -0
- package/dist/adapters/node/openapi-handler.d.ts +15 -0
- package/dist/adapters/node/openapi-handler.js +15 -0
- package/dist/adapters/standard/index.d.ts +3 -56
- package/dist/adapters/standard/index.js +3 -0
- package/dist/adapters/standard/openapi-handler-codec.d.ts +62 -0
- package/dist/adapters/standard/openapi-handler-codec.js +220 -0
- package/dist/adapters/standard/{index.d.mts → openapi-link-codec.d.ts} +25 -19
- package/dist/adapters/standard/openapi-link-codec.js +405 -0
- package/dist/adapters/standard/openapi-matcher.d.ts +29 -0
- package/dist/adapters/standard/openapi-matcher.js +108 -0
- package/dist/adapters/standard/utils.d.ts +4 -0
- package/dist/adapters/standard/utils.js +47 -0
- package/dist/bracket-notation.d.ts +26 -0
- package/dist/bracket-notation.js +185 -0
- package/dist/client-factory.d.ts +24 -0
- package/dist/client-factory.js +13 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.js +4 -0
- package/dist/extensions/route.d.ts +3 -7
- package/dist/extensions/route.js +12 -0
- package/dist/helpers/{index.d.mts → form-data.d.ts} +2 -4
- package/dist/helpers/form-data.js +90 -0
- package/dist/helpers/index.d.ts +1 -59
- package/dist/helpers/index.js +1 -0
- package/dist/index.d.ts +12 -165
- package/dist/index.js +11 -0
- package/dist/{shared/openapi.zGZlCOwp.d.mts → meta.d.ts} +14 -18
- package/dist/meta.js +84 -0
- package/dist/openapi-generator-components.d.ts +31 -0
- package/dist/openapi-generator-components.js +275 -0
- package/dist/openapi-generator-operation.d.ts +34 -0
- package/dist/openapi-generator-operation.js +469 -0
- package/dist/openapi-generator.d.ts +92 -0
- package/dist/openapi-generator.js +147 -0
- package/dist/openapi-json-serializer.d.ts +79 -0
- package/dist/openapi-json-serializer.js +260 -0
- package/dist/openapi-serializer.d.ts +43 -0
- package/dist/openapi-serializer.js +93 -0
- package/dist/plugins/index.d.ts +1 -121
- package/dist/plugins/index.js +1 -0
- package/dist/plugins/{index.d.mts → openapi-reference.d.ts} +15 -21
- package/dist/plugins/openapi-reference.js +187 -0
- package/dist/router-utils.d.ts +20 -0
- package/dist/router-utils.js +36 -0
- package/dist/types.d.ts +31 -0
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +14 -0
- package/dist/utils.js +47 -0
- package/package.json +69 -71
- package/dist/adapters/aws-lambda/index.d.mts +0 -27
- package/dist/adapters/aws-lambda/index.mjs +0 -21
- package/dist/adapters/fastify/index.d.mts +0 -23
- package/dist/adapters/fastify/index.mjs +0 -21
- package/dist/adapters/fetch/index.d.mts +0 -37
- package/dist/adapters/fetch/index.mjs +0 -34
- package/dist/adapters/node/index.d.mts +0 -23
- package/dist/adapters/node/index.mjs +0 -21
- package/dist/adapters/standard/index.mjs +0 -12
- package/dist/extensions/route.d.mts +0 -41
- package/dist/extensions/route.mjs +0 -14
- package/dist/helpers/index.mjs +0 -39
- package/dist/index.d.mts +0 -166
- package/dist/index.mjs +0 -780
- package/dist/plugins/index.mjs +0 -167
- package/dist/shared/openapi.B9PQzqBn.mjs +0 -49
- package/dist/shared/openapi.CQkXu1nY.mjs +0 -366
- package/dist/shared/openapi.Covi8zVE.d.mts +0 -33
- package/dist/shared/openapi.Covi8zVE.d.ts +0 -33
- package/dist/shared/openapi.DfmCR1pB.d.mts +0 -94
- package/dist/shared/openapi.DtEVcxuW.mjs +0 -149
- package/dist/shared/openapi.E3ZBiweM.mjs +0 -353
- package/dist/shared/openapi.Y4K_-I5W.d.ts +0 -94
- package/dist/shared/openapi.YMRD3b4R.d.mts +0 -157
- package/dist/shared/openapi.YMRD3b4R.d.ts +0 -157
- package/dist/shared/openapi.g7ucL05o.mjs +0 -410
- package/dist/shared/openapi.zGZlCOwp.d.ts +0 -329
|
@@ -1,410 +0,0 @@
|
|
|
1
|
-
import { COMMON_ERROR_STATUS_MAP } from '@orpc/client';
|
|
2
|
-
import { walkProcedureContractsSync, unlazy, resolveContractProcedure, Procedure, DEFAULT_SUCCESS_STATUS, DEFAULT_ERROR_STATUS } from '@orpc/server';
|
|
3
|
-
import { value, pathToHttpPath, mergeHttpPath, safeDecodeURIComponent, safeEncodeURIComponent, setOwn, NullProtoObj, isTypescriptObject, isPlainObject, stringifyJSON, getOwn, parseEmptyableJSON } from '@orpc/shared';
|
|
4
|
-
import { parseStandardUrl } from '@standard-server/core';
|
|
5
|
-
import { D as DEFAULT_OPENAPI_METHOD, g as getDynamicPathParams, O as OpenAPISerializer, a as DEFAULT_OPENAPI_INPUT_STRUCTURE, i as isBodylessMethod, b as DEFAULT_OPENAPI_OUTPUT_STRUCTURE } from './openapi.E3ZBiweM.mjs';
|
|
6
|
-
import { g as getOpenAPIMeta } from './openapi.B9PQzqBn.mjs';
|
|
7
|
-
import { createRouter, addRoute, findRoute, findAllRoutes, routeToRegExp } from 'rou3';
|
|
8
|
-
|
|
9
|
-
const ROU3_RAW_CHARS = String.raw`\w!$&'()*+,\-.:;=@[\\\]|~`;
|
|
10
|
-
const NORMALIZABLE_PATHNAME_REGEX = new RegExp(`[^${ROU3_RAW_CHARS}/]`);
|
|
11
|
-
const ROU3_ENCODED_SEGMENT_TEXT_REGEX = new RegExp(`[^${ROU3_RAW_CHARS}]+`, "g");
|
|
12
|
-
class OpenAPIMatcher {
|
|
13
|
-
filter;
|
|
14
|
-
rootRouter;
|
|
15
|
-
tree = createRouter();
|
|
16
|
-
pendingLazyRouters = /* @__PURE__ */ new Set();
|
|
17
|
-
constructor(router, options = {}) {
|
|
18
|
-
this.filter = options.filter ?? true;
|
|
19
|
-
this.rootRouter = router;
|
|
20
|
-
this.index(router);
|
|
21
|
-
}
|
|
22
|
-
index(router, path = []) {
|
|
23
|
-
const routes = [];
|
|
24
|
-
const lazyResults = walkProcedureContractsSync(router, (contract, path2) => {
|
|
25
|
-
if (!value(this.filter, contract, path2)) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
const meta = getOpenAPIMeta(contract);
|
|
29
|
-
const method = meta?.method ?? DEFAULT_OPENAPI_METHOD;
|
|
30
|
-
const postHttpPath = meta?.path ?? pathToHttpPath(path2);
|
|
31
|
-
const openapiPath = meta?.prefix ? mergeHttpPath(meta.prefix, postHttpPath) : postHttpPath;
|
|
32
|
-
const { pattern, ...route } = toRou3Route(openapiPath);
|
|
33
|
-
routes.push({
|
|
34
|
-
method,
|
|
35
|
-
pattern,
|
|
36
|
-
entry: {
|
|
37
|
-
path: path2,
|
|
38
|
-
contract,
|
|
39
|
-
procedure: contract instanceof Procedure ? contract : void 0,
|
|
40
|
-
...route
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
}, path);
|
|
44
|
-
const pendingLazyRouters = lazyResults.map((result) => {
|
|
45
|
-
const prefix = getOpenAPIMeta(result.router)?.prefix;
|
|
46
|
-
return {
|
|
47
|
-
...result,
|
|
48
|
-
matcher: prefix ? toRou3PrefixMatcher(prefix) : void 0
|
|
49
|
-
};
|
|
50
|
-
});
|
|
51
|
-
for (const { method, pattern, entry } of routes) {
|
|
52
|
-
addRoute(this.tree, method, pattern, entry);
|
|
53
|
-
}
|
|
54
|
-
for (const pending of pendingLazyRouters) {
|
|
55
|
-
this.pendingLazyRouters.add(pending);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
async match(method, pathname, prefix) {
|
|
59
|
-
if (prefix) {
|
|
60
|
-
if (!pathname.startsWith(prefix)) {
|
|
61
|
-
return void 0;
|
|
62
|
-
}
|
|
63
|
-
const charAfterPrefix = pathname[prefix.length];
|
|
64
|
-
if (charAfterPrefix === "/") {
|
|
65
|
-
pathname = pathname.slice(prefix.length);
|
|
66
|
-
} else if (charAfterPrefix === void 0) {
|
|
67
|
-
pathname = "/";
|
|
68
|
-
} else if (prefix[prefix.length - 1] === "/") {
|
|
69
|
-
pathname = pathname.slice(prefix.length - 1);
|
|
70
|
-
} else {
|
|
71
|
-
return void 0;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
pathname = normalizeRou3Path(pathname);
|
|
75
|
-
const loading = this.resolvePendingLazyRouters(pathname);
|
|
76
|
-
if (loading !== void 0) {
|
|
77
|
-
await loading;
|
|
78
|
-
}
|
|
79
|
-
const match = this.findMatch(method, pathname);
|
|
80
|
-
if (match === void 0) {
|
|
81
|
-
return void 0;
|
|
82
|
-
}
|
|
83
|
-
const entry = match.data;
|
|
84
|
-
return {
|
|
85
|
-
path: entry.path,
|
|
86
|
-
procedure: entry.procedure ?? await this.resolveProcedure(entry),
|
|
87
|
-
params: entry.params && decodeParams(entry.params, match.params)
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
findMatch(method, pathname) {
|
|
91
|
-
const match = findRoute(this.tree, method, pathname);
|
|
92
|
-
if (match === void 0 || !hasEmptyCatchAll(match)) {
|
|
93
|
-
return match;
|
|
94
|
-
}
|
|
95
|
-
return findAllRoutes(this.tree, method, pathname).reverse().find((match2) => !hasEmptyCatchAll(match2));
|
|
96
|
-
}
|
|
97
|
-
resolvePendingLazyRouters(pathname) {
|
|
98
|
-
for (const pending of this.pendingLazyRouters) {
|
|
99
|
-
if (pending.matcher === void 0 || pending.matcher.test(pathname)) {
|
|
100
|
-
return this.loadPendingLazyRouters(pathname);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
async loadPendingLazyRouters(pathname) {
|
|
105
|
-
for (const pending of this.pendingLazyRouters) {
|
|
106
|
-
if (pending.matcher === void 0 || pending.matcher.test(pathname)) {
|
|
107
|
-
await this.loadPendingLazyRouter(pending);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
loadPendingLazyRouter(pending) {
|
|
112
|
-
if (pending.loading === void 0) {
|
|
113
|
-
pending.loading = this.indexPendingLazyRouter(pending).catch((error) => {
|
|
114
|
-
pending.loading = void 0;
|
|
115
|
-
throw error;
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
return pending.loading;
|
|
119
|
-
}
|
|
120
|
-
async indexPendingLazyRouter(pending) {
|
|
121
|
-
const { default: router } = await unlazy(pending.router);
|
|
122
|
-
this.index(router, pending.path);
|
|
123
|
-
this.pendingLazyRouters.delete(pending);
|
|
124
|
-
}
|
|
125
|
-
async resolveProcedure(entry) {
|
|
126
|
-
entry.procedure = await resolveContractProcedure(this.rootRouter, entry.contract, entry.path);
|
|
127
|
-
return entry.procedure;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
function toRou3Route(path) {
|
|
131
|
-
const dynamicParams = getDynamicPathParams(path);
|
|
132
|
-
if (!dynamicParams) {
|
|
133
|
-
return { pattern: toRou3Literal(path) };
|
|
134
|
-
}
|
|
135
|
-
let pattern = "";
|
|
136
|
-
let literalStart = 0;
|
|
137
|
-
let catchAllKey;
|
|
138
|
-
const params = [];
|
|
139
|
-
for (const param of dynamicParams) {
|
|
140
|
-
const key = `p${params.length}`;
|
|
141
|
-
params.push([key, param.parameterName]);
|
|
142
|
-
pattern += toRou3Literal(path.slice(literalStart, param.startIndex));
|
|
143
|
-
literalStart = param.startIndex + param.segment.length;
|
|
144
|
-
if (param.allowsSlash) {
|
|
145
|
-
if (catchAllKey !== void 0) {
|
|
146
|
-
throw new TypeError(`OpenAPI path "${path}" has more than one catch-all param ({+name}), but only one is supported per path.`);
|
|
147
|
-
}
|
|
148
|
-
catchAllKey = key;
|
|
149
|
-
pattern += `:${key}(.*)`;
|
|
150
|
-
} else {
|
|
151
|
-
pattern += `:${key}`;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
pattern += toRou3Literal(path.slice(literalStart));
|
|
155
|
-
return { pattern, params, catchAllKey };
|
|
156
|
-
}
|
|
157
|
-
const ROU3_SYNTAX_REGEX = /[\\:*?+(){}]|(?<![^/])\.(?=\.?(?:\/|$))/g;
|
|
158
|
-
function toRou3Literal(text) {
|
|
159
|
-
return normalizeRou3Path(text).replace(ROU3_SYNTAX_REGEX, "\\$&");
|
|
160
|
-
}
|
|
161
|
-
function normalizeRou3Path(path) {
|
|
162
|
-
if (!NORMALIZABLE_PATHNAME_REGEX.test(path)) {
|
|
163
|
-
return path;
|
|
164
|
-
}
|
|
165
|
-
return path.split("/").map((segment) => NORMALIZABLE_PATHNAME_REGEX.test(segment) ? safeDecodeURIComponent(segment).replace(ROU3_ENCODED_SEGMENT_TEXT_REGEX, safeEncodeURIComponent) : segment).join("/");
|
|
166
|
-
}
|
|
167
|
-
function toRou3PrefixMatcher(prefix) {
|
|
168
|
-
const catchAll = getDynamicPathParams(prefix)?.find((param) => param.allowsSlash);
|
|
169
|
-
const head = catchAll ? prefix.slice(0, catchAll.startIndex) : prefix;
|
|
170
|
-
return routeToRegExp(mergeHttpPath(toRou3Route(head).pattern, "/**"));
|
|
171
|
-
}
|
|
172
|
-
function hasEmptyCatchAll(match) {
|
|
173
|
-
return match.data.catchAllKey !== void 0 && !match.params?.[match.data.catchAllKey];
|
|
174
|
-
}
|
|
175
|
-
function decodeParams(params, values) {
|
|
176
|
-
const decoded = {};
|
|
177
|
-
for (const [rou3Key, name] of params) {
|
|
178
|
-
setOwn(decoded, name, safeDecodeURIComponent(values[rou3Key]));
|
|
179
|
-
}
|
|
180
|
-
return decoded;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function serializeHeaders(headers, serializer) {
|
|
184
|
-
const result = new NullProtoObj();
|
|
185
|
-
for (const [key, value] of Object.entries(headers)) {
|
|
186
|
-
if (Array.isArray(value)) {
|
|
187
|
-
const lines = [];
|
|
188
|
-
for (const item of value) {
|
|
189
|
-
const line2 = serializeHeaderValue(item, serializer);
|
|
190
|
-
if (line2 !== void 0) {
|
|
191
|
-
lines.push(line2);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
result[key] = lines;
|
|
195
|
-
continue;
|
|
196
|
-
}
|
|
197
|
-
const line = serializeHeaderValue(value, serializer);
|
|
198
|
-
if (line !== void 0) {
|
|
199
|
-
result[key] = line;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
return result;
|
|
203
|
-
}
|
|
204
|
-
function serializeHeaderValue(value, serializer) {
|
|
205
|
-
const serialized = serializer.serializeJson(value).json;
|
|
206
|
-
if (Array.isArray(serialized)) {
|
|
207
|
-
return serialized.filter((item) => item !== void 0 && item !== null).map(String).join(",");
|
|
208
|
-
}
|
|
209
|
-
if (isTypescriptObject(serialized)) {
|
|
210
|
-
return Object.entries(serialized).filter(([, val]) => val !== void 0 && val !== null).map(([key, val]) => `${String(key)},${String(val)}`).join(",");
|
|
211
|
-
}
|
|
212
|
-
if (serialized !== void 0 && serialized !== null) {
|
|
213
|
-
return String(serialized);
|
|
214
|
-
}
|
|
215
|
-
return void 0;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
class OpenAPIHandlerCodecCore {
|
|
219
|
-
serializer;
|
|
220
|
-
errorStatusMap;
|
|
221
|
-
errorResponseBodyEncoder;
|
|
222
|
-
errorResponseContentType;
|
|
223
|
-
constructor(options = {}) {
|
|
224
|
-
this.serializer = options.serializer ?? new OpenAPISerializer();
|
|
225
|
-
this.errorStatusMap = options.errorStatusMap ?? COMMON_ERROR_STATUS_MAP;
|
|
226
|
-
this.errorResponseBodyEncoder = options.errorResponseBodyEncoder;
|
|
227
|
-
this.errorResponseContentType = options.errorResponseContentType;
|
|
228
|
-
}
|
|
229
|
-
async decodeInput(matched, request) {
|
|
230
|
-
const meta = getOpenAPIMeta(matched.procedure);
|
|
231
|
-
const inputStructure = meta?.inputStructure ?? DEFAULT_OPENAPI_INPUT_STRUCTURE;
|
|
232
|
-
const params = this.deserializeParams(matched.params, meta?.paramsStyles);
|
|
233
|
-
if (inputStructure === "compact") {
|
|
234
|
-
const data = isBodylessMethod(request.method) ? this.deserializeQuery(request.url, meta?.queryStyles) : this.serializer.deserialize(await request.resolveBody(meta?.requestBodyHint));
|
|
235
|
-
if (data === void 0) {
|
|
236
|
-
return params;
|
|
237
|
-
}
|
|
238
|
-
if (!params || Object.keys(params).length < 1) {
|
|
239
|
-
return data;
|
|
240
|
-
}
|
|
241
|
-
if (!isPlainObject(data)) {
|
|
242
|
-
return params;
|
|
243
|
-
}
|
|
244
|
-
return {
|
|
245
|
-
...data,
|
|
246
|
-
...params
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
return {
|
|
250
|
-
params,
|
|
251
|
-
query: this.deserializeQuery(request.url, meta?.queryStyles),
|
|
252
|
-
headers: request.headers,
|
|
253
|
-
body: this.serializer.deserialize(await request.resolveBody(meta?.requestBodyHint))
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* @throws {TypeError} If `outputStructure` is "detailed" and the output doesn't match the expected structure.
|
|
258
|
-
*/
|
|
259
|
-
encodeOutput(output, procedure, path) {
|
|
260
|
-
const meta = getOpenAPIMeta(procedure);
|
|
261
|
-
const successStatus = meta?.successStatus ?? DEFAULT_SUCCESS_STATUS;
|
|
262
|
-
const outputStructure = meta?.outputStructure ?? DEFAULT_OPENAPI_OUTPUT_STRUCTURE;
|
|
263
|
-
if (outputStructure === "compact") {
|
|
264
|
-
return {
|
|
265
|
-
status: successStatus,
|
|
266
|
-
headers: {},
|
|
267
|
-
body: this.serializer.serialize(output)
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
if (!isValidDetailedOutput(output)) {
|
|
271
|
-
throw new TypeError(`
|
|
272
|
-
Invalid "detailed" output structure returned by procedure (${path.join(".")}):
|
|
273
|
-
\u2022 Expected an object with optional properties:
|
|
274
|
-
- status (number <400)
|
|
275
|
-
- headers (object)
|
|
276
|
-
- body (any)
|
|
277
|
-
\u2022 No extra keys allowed.
|
|
278
|
-
|
|
279
|
-
Actual value:
|
|
280
|
-
${stringifyJSON(output)}
|
|
281
|
-
`);
|
|
282
|
-
}
|
|
283
|
-
return {
|
|
284
|
-
status: output.status ?? successStatus,
|
|
285
|
-
headers: output.headers !== void 0 ? serializeHeaders(output.headers, this.serializer) : {},
|
|
286
|
-
body: this.serializer.serialize(output.body)
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
encodeError(error) {
|
|
290
|
-
const status = getOwn(this.errorStatusMap, error.code) ?? DEFAULT_ERROR_STATUS;
|
|
291
|
-
return {
|
|
292
|
-
status,
|
|
293
|
-
headers: this.errorResponseContentType !== void 0 ? { "content-type": this.errorResponseContentType } : {},
|
|
294
|
-
body: this.serializer.serialize(this.errorResponseBodyEncoder?.(error) ?? error.toJSON())
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
deserializeQuery(url, styles) {
|
|
298
|
-
const [, search] = parseStandardUrl(url);
|
|
299
|
-
const searchParams = new URLSearchParams(search);
|
|
300
|
-
const parsed = this.serializer.deserialize(searchParams);
|
|
301
|
-
if (!styles || !isPlainObject(parsed)) {
|
|
302
|
-
return parsed;
|
|
303
|
-
}
|
|
304
|
-
Object.entries(styles).forEach(([key, hint]) => {
|
|
305
|
-
if (hint === void 0) {
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
const values = searchParams.getAll(key);
|
|
309
|
-
let parsedValue;
|
|
310
|
-
if (hint === "primitive") {
|
|
311
|
-
parsedValue = values.at(-1);
|
|
312
|
-
} else if (hint === "array") {
|
|
313
|
-
parsedValue = values;
|
|
314
|
-
} else if (hint === "comma-delimited-array") {
|
|
315
|
-
parsedValue = decodeDelimitedArray(values.at(-1), ",");
|
|
316
|
-
} else if (hint === "comma-delimited-object") {
|
|
317
|
-
parsedValue = decodeDelimitedObject(values.at(-1), ",");
|
|
318
|
-
} else if (hint === "space-delimited-array") {
|
|
319
|
-
parsedValue = decodeDelimitedArray(values.at(-1), " ");
|
|
320
|
-
} else if (hint === "space-delimited-object") {
|
|
321
|
-
parsedValue = decodeDelimitedObject(values.at(-1), " ");
|
|
322
|
-
} else if (hint === "pipe-delimited-array") {
|
|
323
|
-
parsedValue = decodeDelimitedArray(values.at(-1), "|");
|
|
324
|
-
} else if (hint === "pipe-delimited-object") {
|
|
325
|
-
parsedValue = decodeDelimitedObject(values.at(-1), "|");
|
|
326
|
-
} else {
|
|
327
|
-
const last = values.at(-1);
|
|
328
|
-
try {
|
|
329
|
-
parsedValue = parseEmptyableJSON(last);
|
|
330
|
-
} catch {
|
|
331
|
-
parsedValue = last;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
parsed[key] = this.serializer.deserialize(parsedValue);
|
|
335
|
-
});
|
|
336
|
-
return parsed;
|
|
337
|
-
}
|
|
338
|
-
deserializeParams(params, styles) {
|
|
339
|
-
if (!params || !styles) {
|
|
340
|
-
return params;
|
|
341
|
-
}
|
|
342
|
-
const parsed = { ...params };
|
|
343
|
-
Object.entries(styles).forEach(([key, hint]) => {
|
|
344
|
-
const value = getOwn(params, key);
|
|
345
|
-
if (hint === void 0 || hint === "primitive" || value === void 0) {
|
|
346
|
-
return;
|
|
347
|
-
}
|
|
348
|
-
if (hint === "comma-delimited-array") {
|
|
349
|
-
parsed[key] = decodeDelimitedArray(value, ",");
|
|
350
|
-
} else {
|
|
351
|
-
parsed[key] = decodeDelimitedObject(value, ",");
|
|
352
|
-
}
|
|
353
|
-
});
|
|
354
|
-
return parsed;
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
class OpenAPIHandlerCodec extends OpenAPIHandlerCodecCore {
|
|
358
|
-
matcher;
|
|
359
|
-
constructor(router, options = {}) {
|
|
360
|
-
super(options);
|
|
361
|
-
this.matcher = new OpenAPIMatcher(router, options);
|
|
362
|
-
}
|
|
363
|
-
async resolveProcedure(request, options) {
|
|
364
|
-
const [pathname] = parseStandardUrl(request.url);
|
|
365
|
-
const matched = await this.matcher.match(request.method, pathname, options.prefix);
|
|
366
|
-
if (!matched) {
|
|
367
|
-
return void 0;
|
|
368
|
-
}
|
|
369
|
-
return {
|
|
370
|
-
procedure: matched.procedure,
|
|
371
|
-
path: matched.path,
|
|
372
|
-
decodeInput: () => this.decodeInput(matched, request)
|
|
373
|
-
};
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
function isValidDetailedOutput(output) {
|
|
377
|
-
if (!isTypescriptObject(output)) {
|
|
378
|
-
return false;
|
|
379
|
-
}
|
|
380
|
-
if (Object.keys(output).some((key) => key !== "status" && key !== "headers" && key !== "body")) {
|
|
381
|
-
return false;
|
|
382
|
-
}
|
|
383
|
-
if (output.status !== void 0 && (typeof output.status !== "number" || !Number.isInteger(output.status) || output.status > 399)) {
|
|
384
|
-
return false;
|
|
385
|
-
}
|
|
386
|
-
if (output.headers !== void 0 && !isTypescriptObject(output.headers)) {
|
|
387
|
-
return false;
|
|
388
|
-
}
|
|
389
|
-
return true;
|
|
390
|
-
}
|
|
391
|
-
function decodeDelimitedArray(value, delimiter) {
|
|
392
|
-
if (value === void 0) {
|
|
393
|
-
return void 0;
|
|
394
|
-
}
|
|
395
|
-
return value.split(delimiter);
|
|
396
|
-
}
|
|
397
|
-
function decodeDelimitedObject(value, delimiter) {
|
|
398
|
-
if (value === void 0) {
|
|
399
|
-
return void 0;
|
|
400
|
-
}
|
|
401
|
-
const obj = new NullProtoObj();
|
|
402
|
-
const parts = value.split(delimiter);
|
|
403
|
-
for (let i = 0; i < parts.length; i += 2) {
|
|
404
|
-
const key = parts[i];
|
|
405
|
-
obj[key] = parts[i + 1];
|
|
406
|
-
}
|
|
407
|
-
return obj;
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
export { OpenAPIHandlerCodec as O, OpenAPIHandlerCodecCore as a, OpenAPIMatcher as b, serializeHeaders as s };
|