@orpc/openapi 0.17.0 → 0.18.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/chunk-UPDKQRQG.js +665 -0
- package/dist/fetch.js +27 -693
- package/dist/index.js +39 -16
- package/dist/src/fetch/bracket-notation.d.ts +84 -0
- package/dist/src/fetch/index.d.ts +9 -3
- package/dist/src/fetch/input-builder-full.d.ts +11 -0
- package/dist/src/fetch/input-builder-simple.d.ts +6 -0
- package/dist/src/fetch/openapi-handler-server.d.ts +7 -0
- package/dist/src/fetch/openapi-handler-serverless.d.ts +7 -0
- package/dist/src/fetch/openapi-handler.d.ts +28 -0
- package/dist/src/fetch/openapi-payload-codec.d.ts +13 -0
- package/dist/src/fetch/openapi-procedure-matcher.d.ts +19 -0
- package/dist/src/fetch/schema-coercer.d.ts +10 -0
- package/dist/src/generator.d.ts +2 -0
- package/dist/src/utils.d.ts +2 -2
- package/package.json +9 -7
- package/dist/chunk-CMRY2Z4J.js +0 -54
- package/dist/src/fetch/base-handler.d.ts +0 -13
- package/dist/src/fetch/server-handler.d.ts +0 -3
- package/dist/src/fetch/serverless-handler.d.ts +0 -3
package/dist/fetch.js
CHANGED
|
@@ -1,697 +1,31 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const context = await value(options.context);
|
|
17
|
-
const accept = options.request.headers.get("Accept") || void 0;
|
|
18
|
-
const serializer = new OpenAPISerializer({ accept });
|
|
19
|
-
const handler = async () => {
|
|
20
|
-
const url = new URL(options.request.url);
|
|
21
|
-
const pathname = `/${trim(url.pathname.replace(options.prefix ?? "", ""), "/")}`;
|
|
22
|
-
const customMethod = options.request.method === "POST" ? url.searchParams.get("method")?.toUpperCase() : void 0;
|
|
23
|
-
const method = customMethod || options.request.method;
|
|
24
|
-
const match = await resolveRouter(options.router, method, pathname);
|
|
25
|
-
if (!match) {
|
|
26
|
-
throw new ORPCError({ code: "NOT_FOUND", message: "Not found" });
|
|
27
|
-
}
|
|
28
|
-
const { path, procedure } = match;
|
|
29
|
-
const params = procedure["~orpc"].contract["~orpc"].InputSchema ? zodCoerce(
|
|
30
|
-
procedure["~orpc"].contract["~orpc"].InputSchema,
|
|
31
|
-
match.params,
|
|
32
|
-
{ bracketNotation: true }
|
|
33
|
-
) : match.params;
|
|
34
|
-
const input = await deserializeInput(options.request, procedure);
|
|
35
|
-
const mergedInput = mergeParamsAndInput(params, input);
|
|
36
|
-
const caller = createProcedureClient({
|
|
37
|
-
context,
|
|
38
|
-
procedure,
|
|
39
|
-
path
|
|
40
|
-
});
|
|
41
|
-
const output = await caller(mergedInput, { signal: options.signal });
|
|
42
|
-
const { body, headers } = serializer.serialize(output);
|
|
43
|
-
return new Response(body, {
|
|
44
|
-
status: 200,
|
|
45
|
-
headers
|
|
46
|
-
});
|
|
47
|
-
};
|
|
48
|
-
try {
|
|
49
|
-
return await executeWithHooks({
|
|
50
|
-
context,
|
|
51
|
-
hooks: options,
|
|
52
|
-
execute: handler,
|
|
53
|
-
input: options.request,
|
|
54
|
-
meta: {
|
|
55
|
-
signal: options.signal
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
} catch (e) {
|
|
59
|
-
const error = toORPCError(e);
|
|
60
|
-
try {
|
|
61
|
-
const { body, headers } = serializer.serialize(error.toJSON());
|
|
62
|
-
return new Response(body, {
|
|
63
|
-
status: error.status,
|
|
64
|
-
headers
|
|
65
|
-
});
|
|
66
|
-
} catch (e2) {
|
|
67
|
-
const error2 = toORPCError(e2);
|
|
68
|
-
const { body, headers } = new OpenAPISerializer().serialize(
|
|
69
|
-
error2.toJSON()
|
|
70
|
-
);
|
|
71
|
-
return new Response(body, {
|
|
72
|
-
status: error2.status,
|
|
73
|
-
headers
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
var routingCache = /* @__PURE__ */ new Map();
|
|
80
|
-
var pendingCache = /* @__PURE__ */ new Map();
|
|
81
|
-
function createResolveRouter(createHonoRouter) {
|
|
82
|
-
const addRoutes = (routing, pending, options) => {
|
|
83
|
-
const lazies = eachContractProcedureLeaf(options, ({ path, contract }) => {
|
|
84
|
-
const method = contract["~orpc"].route?.method ?? "POST";
|
|
85
|
-
const httpPath = contract["~orpc"].route?.path ? openAPIPathToRouterPath(contract["~orpc"].route?.path) : `/${path.map(encodeURIComponent).join("/")}`;
|
|
86
|
-
routing.add(method, httpPath, path);
|
|
87
|
-
});
|
|
88
|
-
pending.ref.push(...lazies);
|
|
89
|
-
};
|
|
90
|
-
return async (router, method, pathname) => {
|
|
91
|
-
const pending = (() => {
|
|
92
|
-
let pending2 = pendingCache.get(router);
|
|
93
|
-
if (!pending2) {
|
|
94
|
-
pending2 = { ref: [] };
|
|
95
|
-
pendingCache.set(router, pending2);
|
|
96
|
-
}
|
|
97
|
-
return pending2;
|
|
98
|
-
})();
|
|
99
|
-
const routing = (() => {
|
|
100
|
-
let routing2 = routingCache.get(router);
|
|
101
|
-
if (!routing2) {
|
|
102
|
-
routing2 = createHonoRouter();
|
|
103
|
-
routingCache.set(router, routing2);
|
|
104
|
-
addRoutes(routing2, pending, { router, path: [] });
|
|
105
|
-
}
|
|
106
|
-
return routing2;
|
|
107
|
-
})();
|
|
108
|
-
const newPending = [];
|
|
109
|
-
for (const item of pending.ref) {
|
|
110
|
-
const lazyPrefix = getLazyRouterPrefix(item.lazy);
|
|
111
|
-
if (lazyPrefix && !pathname.startsWith(lazyPrefix) && !pathname.startsWith(`/${item.path.map(encodeURIComponent).join("/")}`)) {
|
|
112
|
-
newPending.push(item);
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
const router2 = (await item.lazy[LAZY_LOADER_SYMBOL]()).default;
|
|
116
|
-
addRoutes(routing, pending, { path: item.path, router: router2 });
|
|
117
|
-
}
|
|
118
|
-
pending.ref = newPending;
|
|
119
|
-
const [matches, params_] = routing.match(method, pathname);
|
|
120
|
-
const [match] = matches.sort((a, b) => {
|
|
121
|
-
return Object.keys(a[1]).length - Object.keys(b[1]).length;
|
|
122
|
-
});
|
|
123
|
-
if (!match) {
|
|
124
|
-
return void 0;
|
|
125
|
-
}
|
|
126
|
-
const path = match[0];
|
|
127
|
-
const params = params_ ? mapValues(
|
|
128
|
-
match[1],
|
|
129
|
-
(v) => params_[v]
|
|
130
|
-
) : match[1];
|
|
131
|
-
const { default: maybeProcedure } = await unlazy(getRouterChild(router, ...path));
|
|
132
|
-
if (!isProcedure(maybeProcedure)) {
|
|
133
|
-
return void 0;
|
|
134
|
-
}
|
|
135
|
-
return {
|
|
136
|
-
path,
|
|
137
|
-
procedure: maybeProcedure,
|
|
138
|
-
params: { ...params }
|
|
139
|
-
// params from hono not a normal object, so we need spread here
|
|
140
|
-
};
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
function mergeParamsAndInput(coercedParams, input) {
|
|
144
|
-
if (Object.keys(coercedParams).length === 0) {
|
|
145
|
-
return input;
|
|
146
|
-
}
|
|
147
|
-
if (!isPlainObject(input)) {
|
|
148
|
-
return coercedParams;
|
|
149
|
-
}
|
|
150
|
-
return {
|
|
151
|
-
...coercedParams,
|
|
152
|
-
...input
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
async function deserializeInput(request, procedure) {
|
|
156
|
-
const deserializer = new OpenAPIDeserializer({
|
|
157
|
-
schema: procedure["~orpc"].contract["~orpc"].InputSchema
|
|
158
|
-
});
|
|
159
|
-
try {
|
|
160
|
-
return await deserializer.deserialize(request);
|
|
161
|
-
} catch (e) {
|
|
162
|
-
throw new ORPCError({
|
|
163
|
-
code: "BAD_REQUEST",
|
|
164
|
-
message: "Cannot parse request. Please check the request body and Content-Type header.",
|
|
165
|
-
cause: e
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
function toORPCError(e) {
|
|
170
|
-
return e instanceof ORPCError ? e : new ORPCError({
|
|
171
|
-
code: "INTERNAL_SERVER_ERROR",
|
|
172
|
-
message: "Internal server error",
|
|
173
|
-
cause: e
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
function openAPIPathToRouterPath(path) {
|
|
177
|
-
return standardizeHTTPPath(path).replace(/\{([^}]+)\}/g, ":$1");
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// ../../node_modules/.pnpm/hono@4.6.13/node_modules/hono/dist/router.js
|
|
181
|
-
var METHOD_NAME_ALL = "ALL";
|
|
182
|
-
var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
|
|
183
|
-
var UnsupportedPathError = class extends Error {
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
// ../../node_modules/.pnpm/hono@4.6.13/node_modules/hono/dist/utils/url.js
|
|
187
|
-
var checkOptionalParameter = (path) => {
|
|
188
|
-
if (!path.match(/\:.+\?$/)) {
|
|
189
|
-
return null;
|
|
190
|
-
}
|
|
191
|
-
const segments = path.split("/");
|
|
192
|
-
const results = [];
|
|
193
|
-
let basePath = "";
|
|
194
|
-
segments.forEach((segment) => {
|
|
195
|
-
if (segment !== "" && !/\:/.test(segment)) {
|
|
196
|
-
basePath += "/" + segment;
|
|
197
|
-
} else if (/\:/.test(segment)) {
|
|
198
|
-
if (/\?/.test(segment)) {
|
|
199
|
-
if (results.length === 0 && basePath === "") {
|
|
200
|
-
results.push("/");
|
|
201
|
-
} else {
|
|
202
|
-
results.push(basePath);
|
|
203
|
-
}
|
|
204
|
-
const optionalSegment = segment.replace("?", "");
|
|
205
|
-
basePath += "/" + optionalSegment;
|
|
206
|
-
results.push(basePath);
|
|
207
|
-
} else {
|
|
208
|
-
basePath += "/" + segment;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
return results.filter((v, i, a) => a.indexOf(v) === i);
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
// ../../node_modules/.pnpm/hono@4.6.13/node_modules/hono/dist/router/reg-exp-router/node.js
|
|
216
|
-
var LABEL_REG_EXP_STR = "[^/]+";
|
|
217
|
-
var ONLY_WILDCARD_REG_EXP_STR = ".*";
|
|
218
|
-
var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
|
|
219
|
-
var PATH_ERROR = Symbol();
|
|
220
|
-
var regExpMetaChars = new Set(".\\+*[^]$()");
|
|
221
|
-
function compareKey(a, b) {
|
|
222
|
-
if (a.length === 1) {
|
|
223
|
-
return b.length === 1 ? a < b ? -1 : 1 : -1;
|
|
224
|
-
}
|
|
225
|
-
if (b.length === 1) {
|
|
226
|
-
return 1;
|
|
227
|
-
}
|
|
228
|
-
if (a === ONLY_WILDCARD_REG_EXP_STR || a === TAIL_WILDCARD_REG_EXP_STR) {
|
|
229
|
-
return 1;
|
|
230
|
-
} else if (b === ONLY_WILDCARD_REG_EXP_STR || b === TAIL_WILDCARD_REG_EXP_STR) {
|
|
231
|
-
return -1;
|
|
232
|
-
}
|
|
233
|
-
if (a === LABEL_REG_EXP_STR) {
|
|
234
|
-
return 1;
|
|
235
|
-
} else if (b === LABEL_REG_EXP_STR) {
|
|
236
|
-
return -1;
|
|
237
|
-
}
|
|
238
|
-
return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
|
|
239
|
-
}
|
|
240
|
-
var Node = class {
|
|
241
|
-
#index;
|
|
242
|
-
#varIndex;
|
|
243
|
-
#children = /* @__PURE__ */ Object.create(null);
|
|
244
|
-
insert(tokens, index, paramMap, context, pathErrorCheckOnly) {
|
|
245
|
-
if (tokens.length === 0) {
|
|
246
|
-
if (this.#index !== void 0) {
|
|
247
|
-
throw PATH_ERROR;
|
|
248
|
-
}
|
|
249
|
-
if (pathErrorCheckOnly) {
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
this.#index = index;
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
const [token, ...restTokens] = tokens;
|
|
256
|
-
const pattern = token === "*" ? restTokens.length === 0 ? ["", "", ONLY_WILDCARD_REG_EXP_STR] : ["", "", LABEL_REG_EXP_STR] : token === "/*" ? ["", "", TAIL_WILDCARD_REG_EXP_STR] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
257
|
-
let node;
|
|
258
|
-
if (pattern) {
|
|
259
|
-
const name = pattern[1];
|
|
260
|
-
let regexpStr = pattern[2] || LABEL_REG_EXP_STR;
|
|
261
|
-
if (name && pattern[2]) {
|
|
262
|
-
regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
|
|
263
|
-
if (/\((?!\?:)/.test(regexpStr)) {
|
|
264
|
-
throw PATH_ERROR;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
node = this.#children[regexpStr];
|
|
268
|
-
if (!node) {
|
|
269
|
-
if (Object.keys(this.#children).some(
|
|
270
|
-
(k) => k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
|
|
271
|
-
)) {
|
|
272
|
-
throw PATH_ERROR;
|
|
273
|
-
}
|
|
274
|
-
if (pathErrorCheckOnly) {
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
node = this.#children[regexpStr] = new Node();
|
|
278
|
-
if (name !== "") {
|
|
279
|
-
node.#varIndex = context.varIndex++;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
if (!pathErrorCheckOnly && name !== "") {
|
|
283
|
-
paramMap.push([name, node.#varIndex]);
|
|
284
|
-
}
|
|
285
|
-
} else {
|
|
286
|
-
node = this.#children[token];
|
|
287
|
-
if (!node) {
|
|
288
|
-
if (Object.keys(this.#children).some(
|
|
289
|
-
(k) => k.length > 1 && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
|
|
290
|
-
)) {
|
|
291
|
-
throw PATH_ERROR;
|
|
292
|
-
}
|
|
293
|
-
if (pathErrorCheckOnly) {
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
node = this.#children[token] = new Node();
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
node.insert(restTokens, index, paramMap, context, pathErrorCheckOnly);
|
|
300
|
-
}
|
|
301
|
-
buildRegExpStr() {
|
|
302
|
-
const childKeys = Object.keys(this.#children).sort(compareKey);
|
|
303
|
-
const strList = childKeys.map((k) => {
|
|
304
|
-
const c = this.#children[k];
|
|
305
|
-
return (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr();
|
|
306
|
-
});
|
|
307
|
-
if (typeof this.#index === "number") {
|
|
308
|
-
strList.unshift(`#${this.#index}`);
|
|
309
|
-
}
|
|
310
|
-
if (strList.length === 0) {
|
|
311
|
-
return "";
|
|
312
|
-
}
|
|
313
|
-
if (strList.length === 1) {
|
|
314
|
-
return strList[0];
|
|
315
|
-
}
|
|
316
|
-
return "(?:" + strList.join("|") + ")";
|
|
317
|
-
}
|
|
318
|
-
};
|
|
319
|
-
|
|
320
|
-
// ../../node_modules/.pnpm/hono@4.6.13/node_modules/hono/dist/router/reg-exp-router/trie.js
|
|
321
|
-
var Trie = class {
|
|
322
|
-
#context = { varIndex: 0 };
|
|
323
|
-
#root = new Node();
|
|
324
|
-
insert(path, index, pathErrorCheckOnly) {
|
|
325
|
-
const paramAssoc = [];
|
|
326
|
-
const groups = [];
|
|
327
|
-
for (let i = 0; ; ) {
|
|
328
|
-
let replaced = false;
|
|
329
|
-
path = path.replace(/\{[^}]+\}/g, (m) => {
|
|
330
|
-
const mark = `@\\${i}`;
|
|
331
|
-
groups[i] = [mark, m];
|
|
332
|
-
i++;
|
|
333
|
-
replaced = true;
|
|
334
|
-
return mark;
|
|
335
|
-
});
|
|
336
|
-
if (!replaced) {
|
|
337
|
-
break;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
const tokens = path.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
|
|
341
|
-
for (let i = groups.length - 1; i >= 0; i--) {
|
|
342
|
-
const [mark] = groups[i];
|
|
343
|
-
for (let j = tokens.length - 1; j >= 0; j--) {
|
|
344
|
-
if (tokens[j].indexOf(mark) !== -1) {
|
|
345
|
-
tokens[j] = tokens[j].replace(mark, groups[i][1]);
|
|
346
|
-
break;
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
this.#root.insert(tokens, index, paramAssoc, this.#context, pathErrorCheckOnly);
|
|
351
|
-
return paramAssoc;
|
|
352
|
-
}
|
|
353
|
-
buildRegExp() {
|
|
354
|
-
let regexp = this.#root.buildRegExpStr();
|
|
355
|
-
if (regexp === "") {
|
|
356
|
-
return [/^$/, [], []];
|
|
357
|
-
}
|
|
358
|
-
let captureIndex = 0;
|
|
359
|
-
const indexReplacementMap = [];
|
|
360
|
-
const paramReplacementMap = [];
|
|
361
|
-
regexp = regexp.replace(/#(\d+)|@(\d+)|\.\*\$/g, (_, handlerIndex, paramIndex) => {
|
|
362
|
-
if (handlerIndex !== void 0) {
|
|
363
|
-
indexReplacementMap[++captureIndex] = Number(handlerIndex);
|
|
364
|
-
return "$()";
|
|
365
|
-
}
|
|
366
|
-
if (paramIndex !== void 0) {
|
|
367
|
-
paramReplacementMap[Number(paramIndex)] = ++captureIndex;
|
|
368
|
-
return "";
|
|
369
|
-
}
|
|
370
|
-
return "";
|
|
371
|
-
});
|
|
372
|
-
return [new RegExp(`^${regexp}`), indexReplacementMap, paramReplacementMap];
|
|
373
|
-
}
|
|
374
|
-
};
|
|
375
|
-
|
|
376
|
-
// ../../node_modules/.pnpm/hono@4.6.13/node_modules/hono/dist/router/reg-exp-router/router.js
|
|
377
|
-
var emptyParam = [];
|
|
378
|
-
var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
|
|
379
|
-
var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
380
|
-
function buildWildcardRegExp(path) {
|
|
381
|
-
return wildcardRegExpCache[path] ??= new RegExp(
|
|
382
|
-
path === "*" ? "" : `^${path.replace(
|
|
383
|
-
/\/\*$|([.\\+*[^\]$()])/g,
|
|
384
|
-
(_, metaChar) => metaChar ? `\\${metaChar}` : "(?:|/.*)"
|
|
385
|
-
)}$`
|
|
386
|
-
);
|
|
387
|
-
}
|
|
388
|
-
function clearWildcardRegExpCache() {
|
|
389
|
-
wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
390
|
-
}
|
|
391
|
-
function buildMatcherFromPreprocessedRoutes(routes) {
|
|
392
|
-
const trie = new Trie();
|
|
393
|
-
const handlerData = [];
|
|
394
|
-
if (routes.length === 0) {
|
|
395
|
-
return nullMatcher;
|
|
396
|
-
}
|
|
397
|
-
const routesWithStaticPathFlag = routes.map(
|
|
398
|
-
(route) => [!/\*|\/:/.test(route[0]), ...route]
|
|
399
|
-
).sort(
|
|
400
|
-
([isStaticA, pathA], [isStaticB, pathB]) => isStaticA ? 1 : isStaticB ? -1 : pathA.length - pathB.length
|
|
401
|
-
);
|
|
402
|
-
const staticMap = /* @__PURE__ */ Object.create(null);
|
|
403
|
-
for (let i = 0, j = -1, len = routesWithStaticPathFlag.length; i < len; i++) {
|
|
404
|
-
const [pathErrorCheckOnly, path, handlers] = routesWithStaticPathFlag[i];
|
|
405
|
-
if (pathErrorCheckOnly) {
|
|
406
|
-
staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
|
|
407
|
-
} else {
|
|
408
|
-
j++;
|
|
409
|
-
}
|
|
410
|
-
let paramAssoc;
|
|
411
|
-
try {
|
|
412
|
-
paramAssoc = trie.insert(path, j, pathErrorCheckOnly);
|
|
413
|
-
} catch (e) {
|
|
414
|
-
throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
|
|
415
|
-
}
|
|
416
|
-
if (pathErrorCheckOnly) {
|
|
417
|
-
continue;
|
|
418
|
-
}
|
|
419
|
-
handlerData[j] = handlers.map(([h, paramCount]) => {
|
|
420
|
-
const paramIndexMap = /* @__PURE__ */ Object.create(null);
|
|
421
|
-
paramCount -= 1;
|
|
422
|
-
for (; paramCount >= 0; paramCount--) {
|
|
423
|
-
const [key, value2] = paramAssoc[paramCount];
|
|
424
|
-
paramIndexMap[key] = value2;
|
|
425
|
-
}
|
|
426
|
-
return [h, paramIndexMap];
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
|
-
const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
|
|
430
|
-
for (let i = 0, len = handlerData.length; i < len; i++) {
|
|
431
|
-
for (let j = 0, len2 = handlerData[i].length; j < len2; j++) {
|
|
432
|
-
const map = handlerData[i][j]?.[1];
|
|
433
|
-
if (!map) {
|
|
434
|
-
continue;
|
|
435
|
-
}
|
|
436
|
-
const keys = Object.keys(map);
|
|
437
|
-
for (let k = 0, len3 = keys.length; k < len3; k++) {
|
|
438
|
-
map[keys[k]] = paramReplacementMap[map[keys[k]]];
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
const handlerMap = [];
|
|
443
|
-
for (const i in indexReplacementMap) {
|
|
444
|
-
handlerMap[i] = handlerData[indexReplacementMap[i]];
|
|
445
|
-
}
|
|
446
|
-
return [regexp, handlerMap, staticMap];
|
|
447
|
-
}
|
|
448
|
-
function findMiddleware(middleware, path) {
|
|
449
|
-
if (!middleware) {
|
|
450
|
-
return void 0;
|
|
451
|
-
}
|
|
452
|
-
for (const k of Object.keys(middleware).sort((a, b) => b.length - a.length)) {
|
|
453
|
-
if (buildWildcardRegExp(k).test(path)) {
|
|
454
|
-
return [...middleware[k]];
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
return void 0;
|
|
458
|
-
}
|
|
459
|
-
var RegExpRouter = class {
|
|
460
|
-
name = "RegExpRouter";
|
|
461
|
-
#middleware;
|
|
462
|
-
#routes;
|
|
463
|
-
constructor() {
|
|
464
|
-
this.#middleware = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
|
|
465
|
-
this.#routes = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
|
|
466
|
-
}
|
|
467
|
-
add(method, path, handler) {
|
|
468
|
-
const middleware = this.#middleware;
|
|
469
|
-
const routes = this.#routes;
|
|
470
|
-
if (!middleware || !routes) {
|
|
471
|
-
throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
472
|
-
}
|
|
473
|
-
if (!middleware[method]) {
|
|
474
|
-
;
|
|
475
|
-
[middleware, routes].forEach((handlerMap) => {
|
|
476
|
-
handlerMap[method] = /* @__PURE__ */ Object.create(null);
|
|
477
|
-
Object.keys(handlerMap[METHOD_NAME_ALL]).forEach((p) => {
|
|
478
|
-
handlerMap[method][p] = [...handlerMap[METHOD_NAME_ALL][p]];
|
|
479
|
-
});
|
|
480
|
-
});
|
|
481
|
-
}
|
|
482
|
-
if (path === "/*") {
|
|
483
|
-
path = "*";
|
|
484
|
-
}
|
|
485
|
-
const paramCount = (path.match(/\/:/g) || []).length;
|
|
486
|
-
if (/\*$/.test(path)) {
|
|
487
|
-
const re = buildWildcardRegExp(path);
|
|
488
|
-
if (method === METHOD_NAME_ALL) {
|
|
489
|
-
Object.keys(middleware).forEach((m) => {
|
|
490
|
-
middleware[m][path] ||= findMiddleware(middleware[m], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
|
|
491
|
-
});
|
|
492
|
-
} else {
|
|
493
|
-
middleware[method][path] ||= findMiddleware(middleware[method], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
|
|
494
|
-
}
|
|
495
|
-
Object.keys(middleware).forEach((m) => {
|
|
496
|
-
if (method === METHOD_NAME_ALL || method === m) {
|
|
497
|
-
Object.keys(middleware[m]).forEach((p) => {
|
|
498
|
-
re.test(p) && middleware[m][p].push([handler, paramCount]);
|
|
499
|
-
});
|
|
500
|
-
}
|
|
501
|
-
});
|
|
502
|
-
Object.keys(routes).forEach((m) => {
|
|
503
|
-
if (method === METHOD_NAME_ALL || method === m) {
|
|
504
|
-
Object.keys(routes[m]).forEach(
|
|
505
|
-
(p) => re.test(p) && routes[m][p].push([handler, paramCount])
|
|
506
|
-
);
|
|
507
|
-
}
|
|
508
|
-
});
|
|
509
|
-
return;
|
|
510
|
-
}
|
|
511
|
-
const paths = checkOptionalParameter(path) || [path];
|
|
512
|
-
for (let i = 0, len = paths.length; i < len; i++) {
|
|
513
|
-
const path2 = paths[i];
|
|
514
|
-
Object.keys(routes).forEach((m) => {
|
|
515
|
-
if (method === METHOD_NAME_ALL || method === m) {
|
|
516
|
-
routes[m][path2] ||= [
|
|
517
|
-
...findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || []
|
|
518
|
-
];
|
|
519
|
-
routes[m][path2].push([handler, paramCount - len + i + 1]);
|
|
520
|
-
}
|
|
521
|
-
});
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
match(method, path) {
|
|
525
|
-
clearWildcardRegExpCache();
|
|
526
|
-
const matchers = this.#buildAllMatchers();
|
|
527
|
-
this.match = (method2, path2) => {
|
|
528
|
-
const matcher = matchers[method2] || matchers[METHOD_NAME_ALL];
|
|
529
|
-
const staticMatch = matcher[2][path2];
|
|
530
|
-
if (staticMatch) {
|
|
531
|
-
return staticMatch;
|
|
532
|
-
}
|
|
533
|
-
const match = path2.match(matcher[0]);
|
|
534
|
-
if (!match) {
|
|
535
|
-
return [[], emptyParam];
|
|
536
|
-
}
|
|
537
|
-
const index = match.indexOf("", 1);
|
|
538
|
-
return [matcher[1][index], match];
|
|
539
|
-
};
|
|
540
|
-
return this.match(method, path);
|
|
541
|
-
}
|
|
542
|
-
#buildAllMatchers() {
|
|
543
|
-
const matchers = /* @__PURE__ */ Object.create(null);
|
|
544
|
-
Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
|
|
545
|
-
matchers[method] ||= this.#buildMatcher(method);
|
|
546
|
-
});
|
|
547
|
-
this.#middleware = this.#routes = void 0;
|
|
548
|
-
return matchers;
|
|
549
|
-
}
|
|
550
|
-
#buildMatcher(method) {
|
|
551
|
-
const routes = [];
|
|
552
|
-
let hasOwnRoute = method === METHOD_NAME_ALL;
|
|
553
|
-
[this.#middleware, this.#routes].forEach((r) => {
|
|
554
|
-
const ownRoute = r[method] ? Object.keys(r[method]).map((path) => [path, r[method][path]]) : [];
|
|
555
|
-
if (ownRoute.length !== 0) {
|
|
556
|
-
hasOwnRoute ||= true;
|
|
557
|
-
routes.push(...ownRoute);
|
|
558
|
-
} else if (method !== METHOD_NAME_ALL) {
|
|
559
|
-
routes.push(
|
|
560
|
-
...Object.keys(r[METHOD_NAME_ALL]).map((path) => [path, r[METHOD_NAME_ALL][path]])
|
|
561
|
-
);
|
|
562
|
-
}
|
|
563
|
-
});
|
|
564
|
-
if (!hasOwnRoute) {
|
|
565
|
-
return null;
|
|
566
|
-
} else {
|
|
567
|
-
return buildMatcherFromPreprocessedRoutes(routes);
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
};
|
|
571
|
-
|
|
572
|
-
// src/fetch/server-handler.ts
|
|
573
|
-
function createOpenAPIServerHandler() {
|
|
574
|
-
return createOpenAPIHandler(() => new RegExpRouter());
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
// ../../node_modules/.pnpm/hono@4.6.13/node_modules/hono/dist/router/linear-router/router.js
|
|
578
|
-
var emptyParams = /* @__PURE__ */ Object.create(null);
|
|
579
|
-
var splitPathRe = /\/(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/[^\/\?]+|(\?)/g;
|
|
580
|
-
var splitByStarRe = /\*/;
|
|
581
|
-
var LinearRouter = class {
|
|
582
|
-
name = "LinearRouter";
|
|
583
|
-
#routes = [];
|
|
584
|
-
add(method, path, handler) {
|
|
585
|
-
for (let i = 0, paths = checkOptionalParameter(path) || [path], len = paths.length; i < len; i++) {
|
|
586
|
-
this.#routes.push([method, paths[i], handler]);
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
match(method, path) {
|
|
590
|
-
const handlers = [];
|
|
591
|
-
ROUTES_LOOP:
|
|
592
|
-
for (let i = 0, len = this.#routes.length; i < len; i++) {
|
|
593
|
-
const [routeMethod, routePath, handler] = this.#routes[i];
|
|
594
|
-
if (routeMethod === method || routeMethod === METHOD_NAME_ALL) {
|
|
595
|
-
if (routePath === "*" || routePath === "/*") {
|
|
596
|
-
handlers.push([handler, emptyParams]);
|
|
597
|
-
continue;
|
|
598
|
-
}
|
|
599
|
-
const hasStar = routePath.indexOf("*") !== -1;
|
|
600
|
-
const hasLabel = routePath.indexOf(":") !== -1;
|
|
601
|
-
if (!hasStar && !hasLabel) {
|
|
602
|
-
if (routePath === path || routePath + "/" === path) {
|
|
603
|
-
handlers.push([handler, emptyParams]);
|
|
604
|
-
}
|
|
605
|
-
} else if (hasStar && !hasLabel) {
|
|
606
|
-
const endsWithStar = routePath.charCodeAt(routePath.length - 1) === 42;
|
|
607
|
-
const parts = (endsWithStar ? routePath.slice(0, -2) : routePath).split(splitByStarRe);
|
|
608
|
-
const lastIndex = parts.length - 1;
|
|
609
|
-
for (let j = 0, pos = 0, len2 = parts.length; j < len2; j++) {
|
|
610
|
-
const part = parts[j];
|
|
611
|
-
const index = path.indexOf(part, pos);
|
|
612
|
-
if (index !== pos) {
|
|
613
|
-
continue ROUTES_LOOP;
|
|
614
|
-
}
|
|
615
|
-
pos += part.length;
|
|
616
|
-
if (j === lastIndex) {
|
|
617
|
-
if (!endsWithStar && pos !== path.length && !(pos === path.length - 1 && path.charCodeAt(pos) === 47)) {
|
|
618
|
-
continue ROUTES_LOOP;
|
|
619
|
-
}
|
|
620
|
-
} else {
|
|
621
|
-
const index2 = path.indexOf("/", pos);
|
|
622
|
-
if (index2 === -1) {
|
|
623
|
-
continue ROUTES_LOOP;
|
|
624
|
-
}
|
|
625
|
-
pos = index2;
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
handlers.push([handler, emptyParams]);
|
|
629
|
-
} else if (hasLabel && !hasStar) {
|
|
630
|
-
const params = /* @__PURE__ */ Object.create(null);
|
|
631
|
-
const parts = routePath.match(splitPathRe);
|
|
632
|
-
const lastIndex = parts.length - 1;
|
|
633
|
-
for (let j = 0, pos = 0, len2 = parts.length; j < len2; j++) {
|
|
634
|
-
if (pos === -1 || pos >= path.length) {
|
|
635
|
-
continue ROUTES_LOOP;
|
|
636
|
-
}
|
|
637
|
-
const part = parts[j];
|
|
638
|
-
if (part.charCodeAt(1) === 58) {
|
|
639
|
-
let name = part.slice(2);
|
|
640
|
-
let value2;
|
|
641
|
-
if (name.charCodeAt(name.length - 1) === 125) {
|
|
642
|
-
const openBracePos = name.indexOf("{");
|
|
643
|
-
const pattern = name.slice(openBracePos + 1, -1);
|
|
644
|
-
const restPath = path.slice(pos + 1);
|
|
645
|
-
const match = new RegExp(pattern, "d").exec(restPath);
|
|
646
|
-
if (!match || match.indices[0][0] !== 0 || match.indices[0][1] === 0) {
|
|
647
|
-
continue ROUTES_LOOP;
|
|
648
|
-
}
|
|
649
|
-
name = name.slice(0, openBracePos);
|
|
650
|
-
value2 = restPath.slice(...match.indices[0]);
|
|
651
|
-
pos += match.indices[0][1] + 1;
|
|
652
|
-
} else {
|
|
653
|
-
let endValuePos = path.indexOf("/", pos + 1);
|
|
654
|
-
if (endValuePos === -1) {
|
|
655
|
-
if (pos + 1 === path.length) {
|
|
656
|
-
continue ROUTES_LOOP;
|
|
657
|
-
}
|
|
658
|
-
endValuePos = path.length;
|
|
659
|
-
}
|
|
660
|
-
value2 = path.slice(pos + 1, endValuePos);
|
|
661
|
-
pos = endValuePos;
|
|
662
|
-
}
|
|
663
|
-
params[name] ||= value2;
|
|
664
|
-
} else {
|
|
665
|
-
const index = path.indexOf(part, pos);
|
|
666
|
-
if (index !== pos) {
|
|
667
|
-
continue ROUTES_LOOP;
|
|
668
|
-
}
|
|
669
|
-
pos += part.length;
|
|
670
|
-
}
|
|
671
|
-
if (j === lastIndex) {
|
|
672
|
-
if (pos !== path.length && !(pos === path.length - 1 && path.charCodeAt(pos) === 47)) {
|
|
673
|
-
continue ROUTES_LOOP;
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
handlers.push([handler, params]);
|
|
678
|
-
} else if (hasLabel && hasStar) {
|
|
679
|
-
throw new UnsupportedPathError();
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
return [handlers];
|
|
684
|
-
}
|
|
685
|
-
};
|
|
686
|
-
|
|
687
|
-
// src/fetch/serverless-handler.ts
|
|
688
|
-
function createOpenAPIServerlessHandler() {
|
|
689
|
-
return createOpenAPIHandler(() => new LinearRouter());
|
|
690
|
-
}
|
|
2
|
+
CompositeSchemaCoercer,
|
|
3
|
+
InputBuilderFull,
|
|
4
|
+
InputBuilderSimple,
|
|
5
|
+
OpenAPIHandler,
|
|
6
|
+
OpenAPIPayloadCodec,
|
|
7
|
+
OpenAPIProcedureMatcher,
|
|
8
|
+
OpenAPIServerHandler,
|
|
9
|
+
OpenAPIServerlessHandler,
|
|
10
|
+
deserialize,
|
|
11
|
+
escapeSegment,
|
|
12
|
+
parsePath,
|
|
13
|
+
serialize,
|
|
14
|
+
stringifyPath
|
|
15
|
+
} from "./chunk-UPDKQRQG.js";
|
|
691
16
|
export {
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
17
|
+
CompositeSchemaCoercer,
|
|
18
|
+
InputBuilderFull,
|
|
19
|
+
InputBuilderSimple,
|
|
20
|
+
OpenAPIHandler,
|
|
21
|
+
OpenAPIPayloadCodec,
|
|
22
|
+
OpenAPIProcedureMatcher,
|
|
23
|
+
OpenAPIServerHandler,
|
|
24
|
+
OpenAPIServerlessHandler,
|
|
25
|
+
deserialize,
|
|
26
|
+
escapeSegment,
|
|
27
|
+
parsePath,
|
|
28
|
+
serialize,
|
|
29
|
+
stringifyPath
|
|
696
30
|
};
|
|
697
31
|
//# sourceMappingURL=fetch.js.map
|