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