likec4 1.48.0 → 1.49.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.
Files changed (113) hide show
  1. package/README.md +11 -1
  2. package/__app__/src/likec4.js +5595 -4127
  3. package/__app__/src/routes/index.js +3 -153
  4. package/__app__/src/routes/projects.js +21 -1087
  5. package/__app__/src/routes/single.js +1221 -16
  6. package/__app__/src/style.css +1 -1
  7. package/__app__/src/vendors.js +3507 -894
  8. package/__app__/src/webcomponent.js +1 -1
  9. package/config/schema.json +155 -143
  10. package/dist/THIRD-PARTY-LICENSES.md +1739 -0
  11. package/dist/_chunks/GraphvizBinaryAdapter.mjs +72 -0
  12. package/dist/_chunks/filenames.mjs +14 -0
  13. package/dist/_chunks/index.d.mts +224 -129
  14. package/dist/_chunks/index2.d.mts +2033 -1908
  15. package/dist/_chunks/libs/@chevrotain/gast.mjs +1 -3969
  16. package/dist/_chunks/libs/@chevrotain/regexp-to-ast.mjs +9 -785
  17. package/dist/_chunks/libs/@chevrotain/utils.mjs +1 -37
  18. package/dist/_chunks/libs/@hono/mcp.mjs +34 -0
  19. package/dist/_chunks/libs/@hono/node-server.mjs +1 -436
  20. package/dist/_chunks/libs/@logtape/logtape.d.mts +741 -0
  21. package/dist/_chunks/libs/@logtape/logtape.mjs +6 -1354
  22. package/dist/_chunks/libs/@lume/kiwi.mjs +1 -1355
  23. package/dist/_chunks/libs/@modelcontextprotocol/sdk.d.mts +14 -14
  24. package/dist/_chunks/libs/@modelcontextprotocol/sdk.mjs +12 -25105
  25. package/dist/_chunks/libs/@msgpack/msgpack.mjs +1 -1503
  26. package/dist/_chunks/libs/@nanostores/react.mjs +1 -30
  27. package/dist/_chunks/libs/@smithy/util-base64.mjs +1 -100
  28. package/dist/_chunks/libs/ajv.mjs +1 -777
  29. package/dist/_chunks/libs/atomically.mjs +1 -362
  30. package/dist/_chunks/libs/birpc.mjs +1 -201
  31. package/dist/_chunks/libs/chevrotain-allstar.mjs +2 -850
  32. package/dist/_chunks/libs/chevrotain.mjs +55 -6229
  33. package/dist/_chunks/libs/conf.mjs +1 -2258
  34. package/dist/_chunks/libs/defu.mjs +1 -42
  35. package/dist/_chunks/libs/esm-env.mjs +1 -5
  36. package/dist/_chunks/libs/eventemitter3.mjs +1 -243
  37. package/dist/_chunks/libs/fast-equals.mjs +1 -446
  38. package/dist/_chunks/libs/find-up-simple.mjs +1 -24
  39. package/dist/_chunks/libs/get-port.mjs +1 -107
  40. package/dist/_chunks/libs/is-docker.mjs +1 -26
  41. package/dist/_chunks/libs/is-error-instance.mjs +1 -26
  42. package/dist/_chunks/libs/is-inside-container.mjs +1 -20
  43. package/dist/_chunks/libs/is-plain-obj.mjs +1 -9
  44. package/dist/_chunks/libs/isexe.mjs +1 -127
  45. package/dist/_chunks/libs/json5.mjs +14 -959
  46. package/dist/_chunks/libs/khroma.mjs +1 -605
  47. package/dist/_chunks/libs/ky.mjs +2 -807
  48. package/dist/_chunks/libs/langium.d.mts +2880 -2844
  49. package/dist/_chunks/libs/langium.mjs +32 -20351
  50. package/dist/_chunks/libs/merge-error-cause.mjs +2 -746
  51. package/dist/_chunks/libs/nanostores.mjs +1 -198
  52. package/dist/_chunks/libs/p-limit.mjs +1 -120
  53. package/dist/_chunks/libs/p-queue.mjs +1 -449
  54. package/dist/_chunks/libs/package-manager-detector.mjs +1 -559
  55. package/dist/_chunks/libs/package-up.mjs +1 -10
  56. package/dist/_chunks/libs/parse-ms.mjs +1 -36
  57. package/dist/_chunks/libs/pathe.mjs +1 -0
  58. package/dist/_chunks/libs/picomatch.mjs +1 -1673
  59. package/dist/_chunks/libs/pretty-ms.mjs +1 -80
  60. package/dist/_chunks/libs/remeda.mjs +1 -690
  61. package/dist/_chunks/libs/safe-stringify.mjs +1 -21
  62. package/dist/_chunks/libs/strip-indent.mjs +1 -15
  63. package/dist/_chunks/libs/tinyrainbow.mjs +1 -88
  64. package/dist/_chunks/libs/ts-graphviz.mjs +4 -725
  65. package/dist/_chunks/libs/ufo.mjs +1 -240
  66. package/dist/_chunks/libs/which.mjs +1 -84
  67. package/dist/_chunks/libs/word-wrap.mjs +12 -43
  68. package/dist/_chunks/node.mjs +481 -0
  69. package/dist/_chunks/plugin.mjs +98 -772
  70. package/dist/_chunks/rolldown-runtime.mjs +1 -48
  71. package/dist/_chunks/sequence-view.mjs +1 -575
  72. package/dist/cli/index.mjs +127 -1846
  73. package/dist/config/index.d.mts +2 -2
  74. package/dist/config/index.mjs +1 -6
  75. package/dist/index.d.mts +148 -7
  76. package/dist/index.mjs +1 -21
  77. package/dist/model/builder.mjs +1 -3
  78. package/dist/model/index.d.mts +57 -3
  79. package/dist/model/index.mjs +1 -5
  80. package/dist/vite-plugin/index.d.mts +4 -3
  81. package/dist/vite-plugin/index.mjs +1 -22
  82. package/dist/vite-plugin/internal.d.mts +5 -5
  83. package/dist/vite-plugin/internal.mjs +1 -68
  84. package/package.json +60 -41
  85. package/react/{index.d.ts → index.d.mts} +112 -70
  86. package/react/{index.js → index.mjs} +21361 -22064
  87. package/react/package.json +2 -5
  88. package/vite-plugin-modules.d.ts +5 -5
  89. package/dist/_chunks/LikeC4.d.mts +0 -121
  90. package/dist/_chunks/LikeC4.mjs +0 -202
  91. package/dist/_chunks/config-app.prod.d.mts +0 -18
  92. package/dist/_chunks/config-app.prod.mjs +0 -188
  93. package/dist/_chunks/config-webcomponent.prod.mjs +0 -71
  94. package/dist/_chunks/define-config.mjs +0 -409
  95. package/dist/_chunks/index3.d.mts +0 -60
  96. package/dist/_chunks/index4.d.mts +0 -1
  97. package/dist/_chunks/libs/@smithy/is-array-buffer.mjs +0 -10
  98. package/dist/_chunks/libs/hono.mjs +0 -1829
  99. package/dist/_chunks/libs/nanoid.mjs +0 -29
  100. package/dist/_chunks/model.mjs +0 -12
  101. package/dist/_chunks/module.d.mts +0 -71
  102. package/dist/_chunks/module.mjs +0 -18657
  103. package/dist/_chunks/vite-build.mjs +0 -69
  104. package/dist/_chunks/vite-dev.mjs +0 -79
  105. package/dist/_chunks/vite-preview.mjs +0 -27
  106. package/dist/language/module.d.mts +0 -5
  107. package/dist/language/module.mjs +0 -20
  108. package/dist/vite/vite-build.d.mts +0 -26
  109. package/dist/vite/vite-build.mjs +0 -27
  110. package/dist/vite/vite-dev.d.mts +0 -34
  111. package/dist/vite/vite-dev.mjs +0 -29
  112. package/dist/vite/vite-preview.d.mts +0 -20
  113. package/dist/vite/vite-preview.mjs +0 -26
@@ -1,1829 +0,0 @@
1
- //#region ../../node_modules/.pnpm/hono@4.11.6/node_modules/hono/dist/compose.js
2
- var compose = (middleware, onError, onNotFound) => {
3
- return (context, next) => {
4
- let index = -1;
5
- return dispatch(0);
6
- async function dispatch(i) {
7
- if (i <= index) throw new Error("next() called multiple times");
8
- index = i;
9
- let res;
10
- let isError = false;
11
- let handler;
12
- if (middleware[i]) {
13
- handler = middleware[i][0][0];
14
- context.req.routeIndex = i;
15
- } else handler = i === middleware.length && next || void 0;
16
- if (handler) try {
17
- res = await handler(context, () => dispatch(i + 1));
18
- } catch (err) {
19
- if (err instanceof Error && onError) {
20
- context.error = err;
21
- res = await onError(err, context);
22
- isError = true;
23
- } else throw err;
24
- }
25
- else if (context.finalized === false && onNotFound) res = await onNotFound(context);
26
- if (res && (context.finalized === false || isError)) context.res = res;
27
- return context;
28
- }
29
- };
30
- };
31
-
32
- //#endregion
33
- //#region ../../node_modules/.pnpm/hono@4.11.6/node_modules/hono/dist/request/constants.js
34
- var GET_MATCH_RESULT = /* @__PURE__ */ Symbol();
35
-
36
- //#endregion
37
- //#region ../../node_modules/.pnpm/hono@4.11.6/node_modules/hono/dist/utils/body.js
38
- var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
39
- const { all = false, dot = false } = options;
40
- const contentType = (request instanceof HonoRequest ? request.raw.headers : request.headers).get("Content-Type");
41
- if (contentType?.startsWith("multipart/form-data") || contentType?.startsWith("application/x-www-form-urlencoded")) return parseFormData(request, {
42
- all,
43
- dot
44
- });
45
- return {};
46
- };
47
- async function parseFormData(request, options) {
48
- const formData = await request.formData();
49
- if (formData) return convertFormDataToBodyData(formData, options);
50
- return {};
51
- }
52
- function convertFormDataToBodyData(formData, options) {
53
- const form = /* @__PURE__ */ Object.create(null);
54
- formData.forEach((value, key) => {
55
- if (!(options.all || key.endsWith("[]"))) form[key] = value;
56
- else handleParsingAllValues(form, key, value);
57
- });
58
- if (options.dot) Object.entries(form).forEach(([key, value]) => {
59
- if (key.includes(".")) {
60
- handleParsingNestedValues(form, key, value);
61
- delete form[key];
62
- }
63
- });
64
- return form;
65
- }
66
- var handleParsingAllValues = (form, key, value) => {
67
- if (form[key] !== void 0) if (Array.isArray(form[key])) form[key].push(value);
68
- else form[key] = [form[key], value];
69
- else if (!key.endsWith("[]")) form[key] = value;
70
- else form[key] = [value];
71
- };
72
- var handleParsingNestedValues = (form, key, value) => {
73
- let nestedForm = form;
74
- const keys = key.split(".");
75
- keys.forEach((key2, index) => {
76
- if (index === keys.length - 1) nestedForm[key2] = value;
77
- else {
78
- if (!nestedForm[key2] || typeof nestedForm[key2] !== "object" || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) nestedForm[key2] = /* @__PURE__ */ Object.create(null);
79
- nestedForm = nestedForm[key2];
80
- }
81
- });
82
- };
83
-
84
- //#endregion
85
- //#region ../../node_modules/.pnpm/hono@4.11.6/node_modules/hono/dist/utils/url.js
86
- var splitPath = (path) => {
87
- const paths = path.split("/");
88
- if (paths[0] === "") paths.shift();
89
- return paths;
90
- };
91
- var splitRoutingPath = (routePath) => {
92
- const { groups, path } = extractGroupsFromPath(routePath);
93
- return replaceGroupMarks(splitPath(path), groups);
94
- };
95
- var extractGroupsFromPath = (path) => {
96
- const groups = [];
97
- path = path.replace(/\{[^}]+\}/g, (match, index) => {
98
- const mark = `@${index}`;
99
- groups.push([mark, match]);
100
- return mark;
101
- });
102
- return {
103
- groups,
104
- path
105
- };
106
- };
107
- var replaceGroupMarks = (paths, groups) => {
108
- for (let i = groups.length - 1; i >= 0; i--) {
109
- const [mark] = groups[i];
110
- for (let j = paths.length - 1; j >= 0; j--) if (paths[j].includes(mark)) {
111
- paths[j] = paths[j].replace(mark, groups[i][1]);
112
- break;
113
- }
114
- }
115
- return paths;
116
- };
117
- var patternCache = {};
118
- var getPattern = (label, next) => {
119
- if (label === "*") return "*";
120
- const match = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
121
- if (match) {
122
- const cacheKey = `${label}#${next}`;
123
- if (!patternCache[cacheKey]) if (match[2]) patternCache[cacheKey] = next && next[0] !== ":" && next[0] !== "*" ? [
124
- cacheKey,
125
- match[1],
126
- new RegExp(`^${match[2]}(?=/${next})`)
127
- ] : [
128
- label,
129
- match[1],
130
- new RegExp(`^${match[2]}$`)
131
- ];
132
- else patternCache[cacheKey] = [
133
- label,
134
- match[1],
135
- true
136
- ];
137
- return patternCache[cacheKey];
138
- }
139
- return null;
140
- };
141
- var tryDecode = (str, decoder) => {
142
- try {
143
- return decoder(str);
144
- } catch {
145
- return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match) => {
146
- try {
147
- return decoder(match);
148
- } catch {
149
- return match;
150
- }
151
- });
152
- }
153
- };
154
- var tryDecodeURI = (str) => tryDecode(str, decodeURI);
155
- var getPath = (request) => {
156
- const url = request.url;
157
- const start = url.indexOf("/", url.indexOf(":") + 4);
158
- let i = start;
159
- for (; i < url.length; i++) {
160
- const charCode = url.charCodeAt(i);
161
- if (charCode === 37) {
162
- const queryIndex = url.indexOf("?", i);
163
- const path = url.slice(start, queryIndex === -1 ? void 0 : queryIndex);
164
- return tryDecodeURI(path.includes("%25") ? path.replace(/%25/g, "%2525") : path);
165
- } else if (charCode === 63) break;
166
- }
167
- return url.slice(start, i);
168
- };
169
- var getPathNoStrict = (request) => {
170
- const result = getPath(request);
171
- return result.length > 1 && result.at(-1) === "/" ? result.slice(0, -1) : result;
172
- };
173
- var mergePath = (base, sub, ...rest) => {
174
- if (rest.length) sub = mergePath(sub, ...rest);
175
- return `${base?.[0] === "/" ? "" : "/"}${base}${sub === "/" ? "" : `${base?.at(-1) === "/" ? "" : "/"}${sub?.[0] === "/" ? sub.slice(1) : sub}`}`;
176
- };
177
- var checkOptionalParameter = (path) => {
178
- if (path.charCodeAt(path.length - 1) !== 63 || !path.includes(":")) return null;
179
- const segments = path.split("/");
180
- const results = [];
181
- let basePath = "";
182
- segments.forEach((segment) => {
183
- if (segment !== "" && !/\:/.test(segment)) basePath += "/" + segment;
184
- else if (/\:/.test(segment)) if (/\?/.test(segment)) {
185
- if (results.length === 0 && basePath === "") results.push("/");
186
- else results.push(basePath);
187
- const optionalSegment = segment.replace("?", "");
188
- basePath += "/" + optionalSegment;
189
- results.push(basePath);
190
- } else basePath += "/" + segment;
191
- });
192
- return results.filter((v, i, a) => a.indexOf(v) === i);
193
- };
194
- var _decodeURI = (value) => {
195
- if (!/[%+]/.test(value)) return value;
196
- if (value.indexOf("+") !== -1) value = value.replace(/\+/g, " ");
197
- return value.indexOf("%") !== -1 ? tryDecode(value, decodeURIComponent_) : value;
198
- };
199
- var _getQueryParam = (url, key, multiple) => {
200
- let encoded;
201
- if (!multiple && key && !/[%+]/.test(key)) {
202
- let keyIndex2 = url.indexOf("?", 8);
203
- if (keyIndex2 === -1) return;
204
- if (!url.startsWith(key, keyIndex2 + 1)) keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
205
- while (keyIndex2 !== -1) {
206
- const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1);
207
- if (trailingKeyCode === 61) {
208
- const valueIndex = keyIndex2 + key.length + 2;
209
- const endIndex = url.indexOf("&", valueIndex);
210
- return _decodeURI(url.slice(valueIndex, endIndex === -1 ? void 0 : endIndex));
211
- } else if (trailingKeyCode == 38 || isNaN(trailingKeyCode)) return "";
212
- keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
213
- }
214
- encoded = /[%+]/.test(url);
215
- if (!encoded) return;
216
- }
217
- const results = {};
218
- encoded ??= /[%+]/.test(url);
219
- let keyIndex = url.indexOf("?", 8);
220
- while (keyIndex !== -1) {
221
- const nextKeyIndex = url.indexOf("&", keyIndex + 1);
222
- let valueIndex = url.indexOf("=", keyIndex);
223
- if (valueIndex > nextKeyIndex && nextKeyIndex !== -1) valueIndex = -1;
224
- let name = url.slice(keyIndex + 1, valueIndex === -1 ? nextKeyIndex === -1 ? void 0 : nextKeyIndex : valueIndex);
225
- if (encoded) name = _decodeURI(name);
226
- keyIndex = nextKeyIndex;
227
- if (name === "") continue;
228
- let value;
229
- if (valueIndex === -1) value = "";
230
- else {
231
- value = url.slice(valueIndex + 1, nextKeyIndex === -1 ? void 0 : nextKeyIndex);
232
- if (encoded) value = _decodeURI(value);
233
- }
234
- if (multiple) {
235
- if (!(results[name] && Array.isArray(results[name]))) results[name] = [];
236
- results[name].push(value);
237
- } else results[name] ??= value;
238
- }
239
- return key ? results[key] : results;
240
- };
241
- var getQueryParam = _getQueryParam;
242
- var getQueryParams = (url, key) => {
243
- return _getQueryParam(url, key, true);
244
- };
245
- var decodeURIComponent_ = decodeURIComponent;
246
-
247
- //#endregion
248
- //#region ../../node_modules/.pnpm/hono@4.11.6/node_modules/hono/dist/request.js
249
- var tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
250
- var HonoRequest = class {
251
- /**
252
- * `.raw` can get the raw Request object.
253
- *
254
- * @see {@link https://hono.dev/docs/api/request#raw}
255
- *
256
- * @example
257
- * ```ts
258
- * // For Cloudflare Workers
259
- * app.post('/', async (c) => {
260
- * const metadata = c.req.raw.cf?.hostMetadata?
261
- * ...
262
- * })
263
- * ```
264
- */
265
- raw;
266
- #validatedData;
267
- #matchResult;
268
- routeIndex = 0;
269
- /**
270
- * `.path` can get the pathname of the request.
271
- *
272
- * @see {@link https://hono.dev/docs/api/request#path}
273
- *
274
- * @example
275
- * ```ts
276
- * app.get('/about/me', (c) => {
277
- * const pathname = c.req.path // `/about/me`
278
- * })
279
- * ```
280
- */
281
- path;
282
- bodyCache = {};
283
- constructor(request, path = "/", matchResult = [[]]) {
284
- this.raw = request;
285
- this.path = path;
286
- this.#matchResult = matchResult;
287
- this.#validatedData = {};
288
- }
289
- param(key) {
290
- return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
291
- }
292
- #getDecodedParam(key) {
293
- const paramKey = this.#matchResult[0][this.routeIndex][1][key];
294
- const param = this.#getParamValue(paramKey);
295
- return param && /\%/.test(param) ? tryDecodeURIComponent(param) : param;
296
- }
297
- #getAllDecodedParams() {
298
- const decoded = {};
299
- const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
300
- for (const key of keys) {
301
- const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
302
- if (value !== void 0) decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value;
303
- }
304
- return decoded;
305
- }
306
- #getParamValue(paramKey) {
307
- return this.#matchResult[1] ? this.#matchResult[1][paramKey] : paramKey;
308
- }
309
- query(key) {
310
- return getQueryParam(this.url, key);
311
- }
312
- queries(key) {
313
- return getQueryParams(this.url, key);
314
- }
315
- header(name) {
316
- if (name) return this.raw.headers.get(name) ?? void 0;
317
- const headerData = {};
318
- this.raw.headers.forEach((value, key) => {
319
- headerData[key] = value;
320
- });
321
- return headerData;
322
- }
323
- async parseBody(options) {
324
- return this.bodyCache.parsedBody ??= await parseBody(this, options);
325
- }
326
- #cachedBody = (key) => {
327
- const { bodyCache, raw } = this;
328
- const cachedBody = bodyCache[key];
329
- if (cachedBody) return cachedBody;
330
- const anyCachedKey = Object.keys(bodyCache)[0];
331
- if (anyCachedKey) return bodyCache[anyCachedKey].then((body) => {
332
- if (anyCachedKey === "json") body = JSON.stringify(body);
333
- return new Response(body)[key]();
334
- });
335
- return bodyCache[key] = raw[key]();
336
- };
337
- /**
338
- * `.json()` can parse Request body of type `application/json`
339
- *
340
- * @see {@link https://hono.dev/docs/api/request#json}
341
- *
342
- * @example
343
- * ```ts
344
- * app.post('/entry', async (c) => {
345
- * const body = await c.req.json()
346
- * })
347
- * ```
348
- */
349
- json() {
350
- return this.#cachedBody("text").then((text) => JSON.parse(text));
351
- }
352
- /**
353
- * `.text()` can parse Request body of type `text/plain`
354
- *
355
- * @see {@link https://hono.dev/docs/api/request#text}
356
- *
357
- * @example
358
- * ```ts
359
- * app.post('/entry', async (c) => {
360
- * const body = await c.req.text()
361
- * })
362
- * ```
363
- */
364
- text() {
365
- return this.#cachedBody("text");
366
- }
367
- /**
368
- * `.arrayBuffer()` parse Request body as an `ArrayBuffer`
369
- *
370
- * @see {@link https://hono.dev/docs/api/request#arraybuffer}
371
- *
372
- * @example
373
- * ```ts
374
- * app.post('/entry', async (c) => {
375
- * const body = await c.req.arrayBuffer()
376
- * })
377
- * ```
378
- */
379
- arrayBuffer() {
380
- return this.#cachedBody("arrayBuffer");
381
- }
382
- /**
383
- * Parses the request body as a `Blob`.
384
- * @example
385
- * ```ts
386
- * app.post('/entry', async (c) => {
387
- * const body = await c.req.blob();
388
- * });
389
- * ```
390
- * @see https://hono.dev/docs/api/request#blob
391
- */
392
- blob() {
393
- return this.#cachedBody("blob");
394
- }
395
- /**
396
- * Parses the request body as `FormData`.
397
- * @example
398
- * ```ts
399
- * app.post('/entry', async (c) => {
400
- * const body = await c.req.formData();
401
- * });
402
- * ```
403
- * @see https://hono.dev/docs/api/request#formdata
404
- */
405
- formData() {
406
- return this.#cachedBody("formData");
407
- }
408
- /**
409
- * Adds validated data to the request.
410
- *
411
- * @param target - The target of the validation.
412
- * @param data - The validated data to add.
413
- */
414
- addValidatedData(target, data) {
415
- this.#validatedData[target] = data;
416
- }
417
- valid(target) {
418
- return this.#validatedData[target];
419
- }
420
- /**
421
- * `.url()` can get the request url strings.
422
- *
423
- * @see {@link https://hono.dev/docs/api/request#url}
424
- *
425
- * @example
426
- * ```ts
427
- * app.get('/about/me', (c) => {
428
- * const url = c.req.url // `http://localhost:8787/about/me`
429
- * ...
430
- * })
431
- * ```
432
- */
433
- get url() {
434
- return this.raw.url;
435
- }
436
- /**
437
- * `.method()` can get the method name of the request.
438
- *
439
- * @see {@link https://hono.dev/docs/api/request#method}
440
- *
441
- * @example
442
- * ```ts
443
- * app.get('/about/me', (c) => {
444
- * const method = c.req.method // `GET`
445
- * })
446
- * ```
447
- */
448
- get method() {
449
- return this.raw.method;
450
- }
451
- get [GET_MATCH_RESULT]() {
452
- return this.#matchResult;
453
- }
454
- /**
455
- * `.matchedRoutes()` can return a matched route in the handler
456
- *
457
- * @deprecated
458
- *
459
- * Use matchedRoutes helper defined in "hono/route" instead.
460
- *
461
- * @see {@link https://hono.dev/docs/api/request#matchedroutes}
462
- *
463
- * @example
464
- * ```ts
465
- * app.use('*', async function logger(c, next) {
466
- * await next()
467
- * c.req.matchedRoutes.forEach(({ handler, method, path }, i) => {
468
- * const name = handler.name || (handler.length < 2 ? '[handler]' : '[middleware]')
469
- * console.log(
470
- * method,
471
- * ' ',
472
- * path,
473
- * ' '.repeat(Math.max(10 - path.length, 0)),
474
- * name,
475
- * i === c.req.routeIndex ? '<- respond from here' : ''
476
- * )
477
- * })
478
- * })
479
- * ```
480
- */
481
- get matchedRoutes() {
482
- return this.#matchResult[0].map(([[, route]]) => route);
483
- }
484
- /**
485
- * `routePath()` can retrieve the path registered within the handler
486
- *
487
- * @deprecated
488
- *
489
- * Use routePath helper defined in "hono/route" instead.
490
- *
491
- * @see {@link https://hono.dev/docs/api/request#routepath}
492
- *
493
- * @example
494
- * ```ts
495
- * app.get('/posts/:id', (c) => {
496
- * return c.json({ path: c.req.routePath })
497
- * })
498
- * ```
499
- */
500
- get routePath() {
501
- return this.#matchResult[0].map(([[, route]]) => route)[this.routeIndex].path;
502
- }
503
- };
504
-
505
- //#endregion
506
- //#region ../../node_modules/.pnpm/hono@4.11.6/node_modules/hono/dist/utils/html.js
507
- var HtmlEscapedCallbackPhase = {
508
- Stringify: 1,
509
- BeforeStream: 2,
510
- Stream: 3
511
- };
512
- var raw = (value, callbacks) => {
513
- const escapedString = new String(value);
514
- escapedString.isEscaped = true;
515
- escapedString.callbacks = callbacks;
516
- return escapedString;
517
- };
518
- var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) => {
519
- if (typeof str === "object" && !(str instanceof String)) {
520
- if (!(str instanceof Promise)) str = str.toString();
521
- if (str instanceof Promise) str = await str;
522
- }
523
- const callbacks = str.callbacks;
524
- if (!callbacks?.length) return Promise.resolve(str);
525
- if (buffer) buffer[0] += str;
526
- else buffer = [str];
527
- const resStr = Promise.all(callbacks.map((c) => c({
528
- phase,
529
- buffer,
530
- context
531
- }))).then((res) => Promise.all(res.filter(Boolean).map((str2) => resolveCallback(str2, phase, false, context, buffer))).then(() => buffer[0]));
532
- if (preserveCallbacks) return raw(await resStr, callbacks);
533
- else return resStr;
534
- };
535
-
536
- //#endregion
537
- //#region ../../node_modules/.pnpm/hono@4.11.6/node_modules/hono/dist/context.js
538
- var TEXT_PLAIN = "text/plain; charset=UTF-8";
539
- var setDefaultContentType = (contentType, headers) => {
540
- return {
541
- "Content-Type": contentType,
542
- ...headers
543
- };
544
- };
545
- var Context = class {
546
- #rawRequest;
547
- #req;
548
- /**
549
- * `.env` can get bindings (environment variables, secrets, KV namespaces, D1 database, R2 bucket etc.) in Cloudflare Workers.
550
- *
551
- * @see {@link https://hono.dev/docs/api/context#env}
552
- *
553
- * @example
554
- * ```ts
555
- * // Environment object for Cloudflare Workers
556
- * app.get('*', async c => {
557
- * const counter = c.env.COUNTER
558
- * })
559
- * ```
560
- */
561
- env = {};
562
- #var;
563
- finalized = false;
564
- /**
565
- * `.error` can get the error object from the middleware if the Handler throws an error.
566
- *
567
- * @see {@link https://hono.dev/docs/api/context#error}
568
- *
569
- * @example
570
- * ```ts
571
- * app.use('*', async (c, next) => {
572
- * await next()
573
- * if (c.error) {
574
- * // do something...
575
- * }
576
- * })
577
- * ```
578
- */
579
- error;
580
- #status;
581
- #executionCtx;
582
- #res;
583
- #layout;
584
- #renderer;
585
- #notFoundHandler;
586
- #preparedHeaders;
587
- #matchResult;
588
- #path;
589
- /**
590
- * Creates an instance of the Context class.
591
- *
592
- * @param req - The Request object.
593
- * @param options - Optional configuration options for the context.
594
- */
595
- constructor(req, options) {
596
- this.#rawRequest = req;
597
- if (options) {
598
- this.#executionCtx = options.executionCtx;
599
- this.env = options.env;
600
- this.#notFoundHandler = options.notFoundHandler;
601
- this.#path = options.path;
602
- this.#matchResult = options.matchResult;
603
- }
604
- }
605
- /**
606
- * `.req` is the instance of {@link HonoRequest}.
607
- */
608
- get req() {
609
- this.#req ??= new HonoRequest(this.#rawRequest, this.#path, this.#matchResult);
610
- return this.#req;
611
- }
612
- /**
613
- * @see {@link https://hono.dev/docs/api/context#event}
614
- * The FetchEvent associated with the current request.
615
- *
616
- * @throws Will throw an error if the context does not have a FetchEvent.
617
- */
618
- get event() {
619
- if (this.#executionCtx && "respondWith" in this.#executionCtx) return this.#executionCtx;
620
- else throw Error("This context has no FetchEvent");
621
- }
622
- /**
623
- * @see {@link https://hono.dev/docs/api/context#executionctx}
624
- * The ExecutionContext associated with the current request.
625
- *
626
- * @throws Will throw an error if the context does not have an ExecutionContext.
627
- */
628
- get executionCtx() {
629
- if (this.#executionCtx) return this.#executionCtx;
630
- else throw Error("This context has no ExecutionContext");
631
- }
632
- /**
633
- * @see {@link https://hono.dev/docs/api/context#res}
634
- * The Response object for the current request.
635
- */
636
- get res() {
637
- return this.#res ||= new Response(null, { headers: this.#preparedHeaders ??= new Headers() });
638
- }
639
- /**
640
- * Sets the Response object for the current request.
641
- *
642
- * @param _res - The Response object to set.
643
- */
644
- set res(_res) {
645
- if (this.#res && _res) {
646
- _res = new Response(_res.body, _res);
647
- for (const [k, v] of this.#res.headers.entries()) {
648
- if (k === "content-type") continue;
649
- if (k === "set-cookie") {
650
- const cookies = this.#res.headers.getSetCookie();
651
- _res.headers.delete("set-cookie");
652
- for (const cookie of cookies) _res.headers.append("set-cookie", cookie);
653
- } else _res.headers.set(k, v);
654
- }
655
- }
656
- this.#res = _res;
657
- this.finalized = true;
658
- }
659
- /**
660
- * `.render()` can create a response within a layout.
661
- *
662
- * @see {@link https://hono.dev/docs/api/context#render-setrenderer}
663
- *
664
- * @example
665
- * ```ts
666
- * app.get('/', (c) => {
667
- * return c.render('Hello!')
668
- * })
669
- * ```
670
- */
671
- render = (...args) => {
672
- this.#renderer ??= (content) => this.html(content);
673
- return this.#renderer(...args);
674
- };
675
- /**
676
- * Sets the layout for the response.
677
- *
678
- * @param layout - The layout to set.
679
- * @returns The layout function.
680
- */
681
- setLayout = (layout) => this.#layout = layout;
682
- /**
683
- * Gets the current layout for the response.
684
- *
685
- * @returns The current layout function.
686
- */
687
- getLayout = () => this.#layout;
688
- /**
689
- * `.setRenderer()` can set the layout in the custom middleware.
690
- *
691
- * @see {@link https://hono.dev/docs/api/context#render-setrenderer}
692
- *
693
- * @example
694
- * ```tsx
695
- * app.use('*', async (c, next) => {
696
- * c.setRenderer((content) => {
697
- * return c.html(
698
- * <html>
699
- * <body>
700
- * <p>{content}</p>
701
- * </body>
702
- * </html>
703
- * )
704
- * })
705
- * await next()
706
- * })
707
- * ```
708
- */
709
- setRenderer = (renderer) => {
710
- this.#renderer = renderer;
711
- };
712
- /**
713
- * `.header()` can set headers.
714
- *
715
- * @see {@link https://hono.dev/docs/api/context#header}
716
- *
717
- * @example
718
- * ```ts
719
- * app.get('/welcome', (c) => {
720
- * // Set headers
721
- * c.header('X-Message', 'Hello!')
722
- * c.header('Content-Type', 'text/plain')
723
- *
724
- * return c.body('Thank you for coming')
725
- * })
726
- * ```
727
- */
728
- header = (name, value, options) => {
729
- if (this.finalized) this.#res = new Response(this.#res.body, this.#res);
730
- const headers = this.#res ? this.#res.headers : this.#preparedHeaders ??= new Headers();
731
- if (value === void 0) headers.delete(name);
732
- else if (options?.append) headers.append(name, value);
733
- else headers.set(name, value);
734
- };
735
- status = (status) => {
736
- this.#status = status;
737
- };
738
- /**
739
- * `.set()` can set the value specified by the key.
740
- *
741
- * @see {@link https://hono.dev/docs/api/context#set-get}
742
- *
743
- * @example
744
- * ```ts
745
- * app.use('*', async (c, next) => {
746
- * c.set('message', 'Hono is hot!!')
747
- * await next()
748
- * })
749
- * ```
750
- */
751
- set = (key, value) => {
752
- this.#var ??= /* @__PURE__ */ new Map();
753
- this.#var.set(key, value);
754
- };
755
- /**
756
- * `.get()` can use the value specified by the key.
757
- *
758
- * @see {@link https://hono.dev/docs/api/context#set-get}
759
- *
760
- * @example
761
- * ```ts
762
- * app.get('/', (c) => {
763
- * const message = c.get('message')
764
- * return c.text(`The message is "${message}"`)
765
- * })
766
- * ```
767
- */
768
- get = (key) => {
769
- return this.#var ? this.#var.get(key) : void 0;
770
- };
771
- /**
772
- * `.var` can access the value of a variable.
773
- *
774
- * @see {@link https://hono.dev/docs/api/context#var}
775
- *
776
- * @example
777
- * ```ts
778
- * const result = c.var.client.oneMethod()
779
- * ```
780
- */
781
- get var() {
782
- if (!this.#var) return {};
783
- return Object.fromEntries(this.#var);
784
- }
785
- #newResponse(data, arg, headers) {
786
- const responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders ?? new Headers();
787
- if (typeof arg === "object" && "headers" in arg) {
788
- const argHeaders = arg.headers instanceof Headers ? arg.headers : new Headers(arg.headers);
789
- for (const [key, value] of argHeaders) if (key.toLowerCase() === "set-cookie") responseHeaders.append(key, value);
790
- else responseHeaders.set(key, value);
791
- }
792
- if (headers) for (const [k, v] of Object.entries(headers)) if (typeof v === "string") responseHeaders.set(k, v);
793
- else {
794
- responseHeaders.delete(k);
795
- for (const v2 of v) responseHeaders.append(k, v2);
796
- }
797
- const status = typeof arg === "number" ? arg : arg?.status ?? this.#status;
798
- return new Response(data, {
799
- status,
800
- headers: responseHeaders
801
- });
802
- }
803
- newResponse = (...args) => this.#newResponse(...args);
804
- /**
805
- * `.body()` can return the HTTP response.
806
- * You can set headers with `.header()` and set HTTP status code with `.status`.
807
- * This can also be set in `.text()`, `.json()` and so on.
808
- *
809
- * @see {@link https://hono.dev/docs/api/context#body}
810
- *
811
- * @example
812
- * ```ts
813
- * app.get('/welcome', (c) => {
814
- * // Set headers
815
- * c.header('X-Message', 'Hello!')
816
- * c.header('Content-Type', 'text/plain')
817
- * // Set HTTP status code
818
- * c.status(201)
819
- *
820
- * // Return the response body
821
- * return c.body('Thank you for coming')
822
- * })
823
- * ```
824
- */
825
- body = (data, arg, headers) => this.#newResponse(data, arg, headers);
826
- /**
827
- * `.text()` can render text as `Content-Type:text/plain`.
828
- *
829
- * @see {@link https://hono.dev/docs/api/context#text}
830
- *
831
- * @example
832
- * ```ts
833
- * app.get('/say', (c) => {
834
- * return c.text('Hello!')
835
- * })
836
- * ```
837
- */
838
- text = (text, arg, headers) => {
839
- return !this.#preparedHeaders && !this.#status && !arg && !headers && !this.finalized ? new Response(text) : this.#newResponse(text, arg, setDefaultContentType(TEXT_PLAIN, headers));
840
- };
841
- /**
842
- * `.json()` can render JSON as `Content-Type:application/json`.
843
- *
844
- * @see {@link https://hono.dev/docs/api/context#json}
845
- *
846
- * @example
847
- * ```ts
848
- * app.get('/api', (c) => {
849
- * return c.json({ message: 'Hello!' })
850
- * })
851
- * ```
852
- */
853
- json = (object, arg, headers) => {
854
- return this.#newResponse(JSON.stringify(object), arg, setDefaultContentType("application/json", headers));
855
- };
856
- html = (html, arg, headers) => {
857
- const res = (html2) => this.#newResponse(html2, arg, setDefaultContentType("text/html; charset=UTF-8", headers));
858
- return typeof html === "object" ? resolveCallback(html, HtmlEscapedCallbackPhase.Stringify, false, {}).then(res) : res(html);
859
- };
860
- /**
861
- * `.redirect()` can Redirect, default status code is 302.
862
- *
863
- * @see {@link https://hono.dev/docs/api/context#redirect}
864
- *
865
- * @example
866
- * ```ts
867
- * app.get('/redirect', (c) => {
868
- * return c.redirect('/')
869
- * })
870
- * app.get('/redirect-permanently', (c) => {
871
- * return c.redirect('/', 301)
872
- * })
873
- * ```
874
- */
875
- redirect = (location, status) => {
876
- const locationString = String(location);
877
- this.header("Location", !/[^\x00-\xFF]/.test(locationString) ? locationString : encodeURI(locationString));
878
- return this.newResponse(null, status ?? 302);
879
- };
880
- /**
881
- * `.notFound()` can return the Not Found Response.
882
- *
883
- * @see {@link https://hono.dev/docs/api/context#notfound}
884
- *
885
- * @example
886
- * ```ts
887
- * app.get('/notfound', (c) => {
888
- * return c.notFound()
889
- * })
890
- * ```
891
- */
892
- notFound = () => {
893
- this.#notFoundHandler ??= () => new Response();
894
- return this.#notFoundHandler(this);
895
- };
896
- };
897
-
898
- //#endregion
899
- //#region ../../node_modules/.pnpm/hono@4.11.6/node_modules/hono/dist/router.js
900
- var METHOD_NAME_ALL = "ALL";
901
- var METHOD_NAME_ALL_LOWERCASE = "all";
902
- var METHODS = [
903
- "get",
904
- "post",
905
- "put",
906
- "delete",
907
- "options",
908
- "patch"
909
- ];
910
- var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
911
- var UnsupportedPathError = class extends Error {};
912
-
913
- //#endregion
914
- //#region ../../node_modules/.pnpm/hono@4.11.6/node_modules/hono/dist/utils/constants.js
915
- var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
916
-
917
- //#endregion
918
- //#region ../../node_modules/.pnpm/hono@4.11.6/node_modules/hono/dist/hono-base.js
919
- var notFoundHandler = (c) => {
920
- return c.text("404 Not Found", 404);
921
- };
922
- var errorHandler = (err, c) => {
923
- if ("getResponse" in err) {
924
- const res = err.getResponse();
925
- return c.newResponse(res.body, res);
926
- }
927
- console.error(err);
928
- return c.text("Internal Server Error", 500);
929
- };
930
- var Hono$1 = class _Hono {
931
- get;
932
- post;
933
- put;
934
- delete;
935
- options;
936
- patch;
937
- all;
938
- on;
939
- use;
940
- router;
941
- getPath;
942
- _basePath = "/";
943
- #path = "/";
944
- routes = [];
945
- constructor(options = {}) {
946
- [...METHODS, METHOD_NAME_ALL_LOWERCASE].forEach((method) => {
947
- this[method] = (args1, ...args) => {
948
- if (typeof args1 === "string") this.#path = args1;
949
- else this.#addRoute(method, this.#path, args1);
950
- args.forEach((handler) => {
951
- this.#addRoute(method, this.#path, handler);
952
- });
953
- return this;
954
- };
955
- });
956
- this.on = (method, path, ...handlers) => {
957
- for (const p of [path].flat()) {
958
- this.#path = p;
959
- for (const m of [method].flat()) handlers.map((handler) => {
960
- this.#addRoute(m.toUpperCase(), this.#path, handler);
961
- });
962
- }
963
- return this;
964
- };
965
- this.use = (arg1, ...handlers) => {
966
- if (typeof arg1 === "string") this.#path = arg1;
967
- else {
968
- this.#path = "*";
969
- handlers.unshift(arg1);
970
- }
971
- handlers.forEach((handler) => {
972
- this.#addRoute(METHOD_NAME_ALL, this.#path, handler);
973
- });
974
- return this;
975
- };
976
- const { strict, ...optionsWithoutStrict } = options;
977
- Object.assign(this, optionsWithoutStrict);
978
- this.getPath = strict ?? true ? options.getPath ?? getPath : getPathNoStrict;
979
- }
980
- #clone() {
981
- const clone = new _Hono({
982
- router: this.router,
983
- getPath: this.getPath
984
- });
985
- clone.errorHandler = this.errorHandler;
986
- clone.#notFoundHandler = this.#notFoundHandler;
987
- clone.routes = this.routes;
988
- return clone;
989
- }
990
- #notFoundHandler = notFoundHandler;
991
- errorHandler = errorHandler;
992
- /**
993
- * `.route()` allows grouping other Hono instance in routes.
994
- *
995
- * @see {@link https://hono.dev/docs/api/routing#grouping}
996
- *
997
- * @param {string} path - base Path
998
- * @param {Hono} app - other Hono instance
999
- * @returns {Hono} routed Hono instance
1000
- *
1001
- * @example
1002
- * ```ts
1003
- * const app = new Hono()
1004
- * const app2 = new Hono()
1005
- *
1006
- * app2.get("/user", (c) => c.text("user"))
1007
- * app.route("/api", app2) // GET /api/user
1008
- * ```
1009
- */
1010
- route(path, app) {
1011
- const subApp = this.basePath(path);
1012
- app.routes.map((r) => {
1013
- let handler;
1014
- if (app.errorHandler === errorHandler) handler = r.handler;
1015
- else {
1016
- handler = async (c, next) => (await compose([], app.errorHandler)(c, () => r.handler(c, next))).res;
1017
- handler[COMPOSED_HANDLER] = r.handler;
1018
- }
1019
- subApp.#addRoute(r.method, r.path, handler);
1020
- });
1021
- return this;
1022
- }
1023
- /**
1024
- * `.basePath()` allows base paths to be specified.
1025
- *
1026
- * @see {@link https://hono.dev/docs/api/routing#base-path}
1027
- *
1028
- * @param {string} path - base Path
1029
- * @returns {Hono} changed Hono instance
1030
- *
1031
- * @example
1032
- * ```ts
1033
- * const api = new Hono().basePath('/api')
1034
- * ```
1035
- */
1036
- basePath(path) {
1037
- const subApp = this.#clone();
1038
- subApp._basePath = mergePath(this._basePath, path);
1039
- return subApp;
1040
- }
1041
- /**
1042
- * `.onError()` handles an error and returns a customized Response.
1043
- *
1044
- * @see {@link https://hono.dev/docs/api/hono#error-handling}
1045
- *
1046
- * @param {ErrorHandler} handler - request Handler for error
1047
- * @returns {Hono} changed Hono instance
1048
- *
1049
- * @example
1050
- * ```ts
1051
- * app.onError((err, c) => {
1052
- * console.error(`${err}`)
1053
- * return c.text('Custom Error Message', 500)
1054
- * })
1055
- * ```
1056
- */
1057
- onError = (handler) => {
1058
- this.errorHandler = handler;
1059
- return this;
1060
- };
1061
- /**
1062
- * `.notFound()` allows you to customize a Not Found Response.
1063
- *
1064
- * @see {@link https://hono.dev/docs/api/hono#not-found}
1065
- *
1066
- * @param {NotFoundHandler} handler - request handler for not-found
1067
- * @returns {Hono} changed Hono instance
1068
- *
1069
- * @example
1070
- * ```ts
1071
- * app.notFound((c) => {
1072
- * return c.text('Custom 404 Message', 404)
1073
- * })
1074
- * ```
1075
- */
1076
- notFound = (handler) => {
1077
- this.#notFoundHandler = handler;
1078
- return this;
1079
- };
1080
- /**
1081
- * `.mount()` allows you to mount applications built with other frameworks into your Hono application.
1082
- *
1083
- * @see {@link https://hono.dev/docs/api/hono#mount}
1084
- *
1085
- * @param {string} path - base Path
1086
- * @param {Function} applicationHandler - other Request Handler
1087
- * @param {MountOptions} [options] - options of `.mount()`
1088
- * @returns {Hono} mounted Hono instance
1089
- *
1090
- * @example
1091
- * ```ts
1092
- * import { Router as IttyRouter } from 'itty-router'
1093
- * import { Hono } from 'hono'
1094
- * // Create itty-router application
1095
- * const ittyRouter = IttyRouter()
1096
- * // GET /itty-router/hello
1097
- * ittyRouter.get('/hello', () => new Response('Hello from itty-router'))
1098
- *
1099
- * const app = new Hono()
1100
- * app.mount('/itty-router', ittyRouter.handle)
1101
- * ```
1102
- *
1103
- * @example
1104
- * ```ts
1105
- * const app = new Hono()
1106
- * // Send the request to another application without modification.
1107
- * app.mount('/app', anotherApp, {
1108
- * replaceRequest: (req) => req,
1109
- * })
1110
- * ```
1111
- */
1112
- mount(path, applicationHandler, options) {
1113
- let replaceRequest;
1114
- let optionHandler;
1115
- if (options) if (typeof options === "function") optionHandler = options;
1116
- else {
1117
- optionHandler = options.optionHandler;
1118
- if (options.replaceRequest === false) replaceRequest = (request) => request;
1119
- else replaceRequest = options.replaceRequest;
1120
- }
1121
- const getOptions = optionHandler ? (c) => {
1122
- const options2 = optionHandler(c);
1123
- return Array.isArray(options2) ? options2 : [options2];
1124
- } : (c) => {
1125
- let executionContext = void 0;
1126
- try {
1127
- executionContext = c.executionCtx;
1128
- } catch {}
1129
- return [c.env, executionContext];
1130
- };
1131
- replaceRequest ||= (() => {
1132
- const mergedPath = mergePath(this._basePath, path);
1133
- const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length;
1134
- return (request) => {
1135
- const url = new URL(request.url);
1136
- url.pathname = url.pathname.slice(pathPrefixLength) || "/";
1137
- return new Request(url, request);
1138
- };
1139
- })();
1140
- const handler = async (c, next) => {
1141
- const res = await applicationHandler(replaceRequest(c.req.raw), ...getOptions(c));
1142
- if (res) return res;
1143
- await next();
1144
- };
1145
- this.#addRoute(METHOD_NAME_ALL, mergePath(path, "*"), handler);
1146
- return this;
1147
- }
1148
- #addRoute(method, path, handler) {
1149
- method = method.toUpperCase();
1150
- path = mergePath(this._basePath, path);
1151
- const r = {
1152
- basePath: this._basePath,
1153
- path,
1154
- method,
1155
- handler
1156
- };
1157
- this.router.add(method, path, [handler, r]);
1158
- this.routes.push(r);
1159
- }
1160
- #handleError(err, c) {
1161
- if (err instanceof Error) return this.errorHandler(err, c);
1162
- throw err;
1163
- }
1164
- #dispatch(request, executionCtx, env, method) {
1165
- if (method === "HEAD") return (async () => new Response(null, await this.#dispatch(request, executionCtx, env, "GET")))();
1166
- const path = this.getPath(request, { env });
1167
- const matchResult = this.router.match(method, path);
1168
- const c = new Context(request, {
1169
- path,
1170
- matchResult,
1171
- env,
1172
- executionCtx,
1173
- notFoundHandler: this.#notFoundHandler
1174
- });
1175
- if (matchResult[0].length === 1) {
1176
- let res;
1177
- try {
1178
- res = matchResult[0][0][0][0](c, async () => {
1179
- c.res = await this.#notFoundHandler(c);
1180
- });
1181
- } catch (err) {
1182
- return this.#handleError(err, c);
1183
- }
1184
- return res instanceof Promise ? res.then((resolved) => resolved || (c.finalized ? c.res : this.#notFoundHandler(c))).catch((err) => this.#handleError(err, c)) : res ?? this.#notFoundHandler(c);
1185
- }
1186
- const composed = compose(matchResult[0], this.errorHandler, this.#notFoundHandler);
1187
- return (async () => {
1188
- try {
1189
- const context = await composed(c);
1190
- if (!context.finalized) throw new Error("Context is not finalized. Did you forget to return a Response object or `await next()`?");
1191
- return context.res;
1192
- } catch (err) {
1193
- return this.#handleError(err, c);
1194
- }
1195
- })();
1196
- }
1197
- /**
1198
- * `.fetch()` will be entry point of your app.
1199
- *
1200
- * @see {@link https://hono.dev/docs/api/hono#fetch}
1201
- *
1202
- * @param {Request} request - request Object of request
1203
- * @param {Env} Env - env Object
1204
- * @param {ExecutionContext} - context of execution
1205
- * @returns {Response | Promise<Response>} response of request
1206
- *
1207
- */
1208
- fetch = (request, ...rest) => {
1209
- return this.#dispatch(request, rest[1], rest[0], request.method);
1210
- };
1211
- /**
1212
- * `.request()` is a useful method for testing.
1213
- * You can pass a URL or pathname to send a GET request.
1214
- * app will return a Response object.
1215
- * ```ts
1216
- * test('GET /hello is ok', async () => {
1217
- * const res = await app.request('/hello')
1218
- * expect(res.status).toBe(200)
1219
- * })
1220
- * ```
1221
- * @see https://hono.dev/docs/api/hono#request
1222
- */
1223
- request = (input, requestInit, Env, executionCtx) => {
1224
- if (input instanceof Request) return this.fetch(requestInit ? new Request(input, requestInit) : input, Env, executionCtx);
1225
- input = input.toString();
1226
- return this.fetch(new Request(/^https?:\/\//.test(input) ? input : `http://localhost${mergePath("/", input)}`, requestInit), Env, executionCtx);
1227
- };
1228
- /**
1229
- * `.fire()` automatically adds a global fetch event listener.
1230
- * This can be useful for environments that adhere to the Service Worker API, such as non-ES module Cloudflare Workers.
1231
- * @deprecated
1232
- * Use `fire` from `hono/service-worker` instead.
1233
- * ```ts
1234
- * import { Hono } from 'hono'
1235
- * import { fire } from 'hono/service-worker'
1236
- *
1237
- * const app = new Hono()
1238
- * // ...
1239
- * fire(app)
1240
- * ```
1241
- * @see https://hono.dev/docs/api/hono#fire
1242
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API
1243
- * @see https://developers.cloudflare.com/workers/reference/migrate-to-module-workers/
1244
- */
1245
- fire = () => {
1246
- addEventListener("fetch", (event) => {
1247
- event.respondWith(this.#dispatch(event.request, event, void 0, event.request.method));
1248
- });
1249
- };
1250
- };
1251
-
1252
- //#endregion
1253
- //#region ../../node_modules/.pnpm/hono@4.11.6/node_modules/hono/dist/router/reg-exp-router/matcher.js
1254
- var emptyParam = [];
1255
- function match(method, path) {
1256
- const matchers = this.buildAllMatchers();
1257
- const match2 = ((method2, path2) => {
1258
- const matcher = matchers[method2] || matchers[METHOD_NAME_ALL];
1259
- const staticMatch = matcher[2][path2];
1260
- if (staticMatch) return staticMatch;
1261
- const match3 = path2.match(matcher[0]);
1262
- if (!match3) return [[], emptyParam];
1263
- const index = match3.indexOf("", 1);
1264
- return [matcher[1][index], match3];
1265
- });
1266
- this.match = match2;
1267
- return match2(method, path);
1268
- }
1269
-
1270
- //#endregion
1271
- //#region ../../node_modules/.pnpm/hono@4.11.6/node_modules/hono/dist/router/reg-exp-router/node.js
1272
- var LABEL_REG_EXP_STR = "[^/]+";
1273
- var ONLY_WILDCARD_REG_EXP_STR = ".*";
1274
- var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
1275
- var PATH_ERROR = /* @__PURE__ */ Symbol();
1276
- var regExpMetaChars = /* @__PURE__ */ new Set(".\\+*[^]$()");
1277
- function compareKey(a, b) {
1278
- if (a.length === 1) return b.length === 1 ? a < b ? -1 : 1 : -1;
1279
- if (b.length === 1) return 1;
1280
- if (a === ONLY_WILDCARD_REG_EXP_STR || a === TAIL_WILDCARD_REG_EXP_STR) return 1;
1281
- else if (b === ONLY_WILDCARD_REG_EXP_STR || b === TAIL_WILDCARD_REG_EXP_STR) return -1;
1282
- if (a === LABEL_REG_EXP_STR) return 1;
1283
- else if (b === LABEL_REG_EXP_STR) return -1;
1284
- return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
1285
- }
1286
- var Node$1 = class _Node {
1287
- #index;
1288
- #varIndex;
1289
- #children = /* @__PURE__ */ Object.create(null);
1290
- insert(tokens, index, paramMap, context, pathErrorCheckOnly) {
1291
- if (tokens.length === 0) {
1292
- if (this.#index !== void 0) throw PATH_ERROR;
1293
- if (pathErrorCheckOnly) return;
1294
- this.#index = index;
1295
- return;
1296
- }
1297
- const [token, ...restTokens] = tokens;
1298
- const pattern = token === "*" ? restTokens.length === 0 ? [
1299
- "",
1300
- "",
1301
- ONLY_WILDCARD_REG_EXP_STR
1302
- ] : [
1303
- "",
1304
- "",
1305
- LABEL_REG_EXP_STR
1306
- ] : token === "/*" ? [
1307
- "",
1308
- "",
1309
- TAIL_WILDCARD_REG_EXP_STR
1310
- ] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
1311
- let node;
1312
- if (pattern) {
1313
- const name = pattern[1];
1314
- let regexpStr = pattern[2] || LABEL_REG_EXP_STR;
1315
- if (name && pattern[2]) {
1316
- if (regexpStr === ".*") throw PATH_ERROR;
1317
- regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
1318
- if (/\((?!\?:)/.test(regexpStr)) throw PATH_ERROR;
1319
- }
1320
- node = this.#children[regexpStr];
1321
- if (!node) {
1322
- if (Object.keys(this.#children).some((k) => k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR)) throw PATH_ERROR;
1323
- if (pathErrorCheckOnly) return;
1324
- node = this.#children[regexpStr] = new _Node();
1325
- if (name !== "") node.#varIndex = context.varIndex++;
1326
- }
1327
- if (!pathErrorCheckOnly && name !== "") paramMap.push([name, node.#varIndex]);
1328
- } else {
1329
- node = this.#children[token];
1330
- if (!node) {
1331
- if (Object.keys(this.#children).some((k) => k.length > 1 && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR)) throw PATH_ERROR;
1332
- if (pathErrorCheckOnly) return;
1333
- node = this.#children[token] = new _Node();
1334
- }
1335
- }
1336
- node.insert(restTokens, index, paramMap, context, pathErrorCheckOnly);
1337
- }
1338
- buildRegExpStr() {
1339
- const strList = Object.keys(this.#children).sort(compareKey).map((k) => {
1340
- const c = this.#children[k];
1341
- return (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr();
1342
- });
1343
- if (typeof this.#index === "number") strList.unshift(`#${this.#index}`);
1344
- if (strList.length === 0) return "";
1345
- if (strList.length === 1) return strList[0];
1346
- return "(?:" + strList.join("|") + ")";
1347
- }
1348
- };
1349
-
1350
- //#endregion
1351
- //#region ../../node_modules/.pnpm/hono@4.11.6/node_modules/hono/dist/router/reg-exp-router/trie.js
1352
- var Trie = class {
1353
- #context = { varIndex: 0 };
1354
- #root = new Node$1();
1355
- insert(path, index, pathErrorCheckOnly) {
1356
- const paramAssoc = [];
1357
- const groups = [];
1358
- for (let i = 0;;) {
1359
- let replaced = false;
1360
- path = path.replace(/\{[^}]+\}/g, (m) => {
1361
- const mark = `@\\${i}`;
1362
- groups[i] = [mark, m];
1363
- i++;
1364
- replaced = true;
1365
- return mark;
1366
- });
1367
- if (!replaced) break;
1368
- }
1369
- const tokens = path.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
1370
- for (let i = groups.length - 1; i >= 0; i--) {
1371
- const [mark] = groups[i];
1372
- for (let j = tokens.length - 1; j >= 0; j--) if (tokens[j].indexOf(mark) !== -1) {
1373
- tokens[j] = tokens[j].replace(mark, groups[i][1]);
1374
- break;
1375
- }
1376
- }
1377
- this.#root.insert(tokens, index, paramAssoc, this.#context, pathErrorCheckOnly);
1378
- return paramAssoc;
1379
- }
1380
- buildRegExp() {
1381
- let regexp = this.#root.buildRegExpStr();
1382
- if (regexp === "") return [
1383
- /^$/,
1384
- [],
1385
- []
1386
- ];
1387
- let captureIndex = 0;
1388
- const indexReplacementMap = [];
1389
- const paramReplacementMap = [];
1390
- regexp = regexp.replace(/#(\d+)|@(\d+)|\.\*\$/g, (_, handlerIndex, paramIndex) => {
1391
- if (handlerIndex !== void 0) {
1392
- indexReplacementMap[++captureIndex] = Number(handlerIndex);
1393
- return "$()";
1394
- }
1395
- if (paramIndex !== void 0) {
1396
- paramReplacementMap[Number(paramIndex)] = ++captureIndex;
1397
- return "";
1398
- }
1399
- return "";
1400
- });
1401
- return [
1402
- new RegExp(`^${regexp}`),
1403
- indexReplacementMap,
1404
- paramReplacementMap
1405
- ];
1406
- }
1407
- };
1408
-
1409
- //#endregion
1410
- //#region ../../node_modules/.pnpm/hono@4.11.6/node_modules/hono/dist/router/reg-exp-router/router.js
1411
- var nullMatcher = [
1412
- /^$/,
1413
- [],
1414
- /* @__PURE__ */ Object.create(null)
1415
- ];
1416
- var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
1417
- function buildWildcardRegExp(path) {
1418
- return wildcardRegExpCache[path] ??= new RegExp(path === "*" ? "" : `^${path.replace(/\/\*$|([.\\+*[^\]$()])/g, (_, metaChar) => metaChar ? `\\${metaChar}` : "(?:|/.*)")}$`);
1419
- }
1420
- function clearWildcardRegExpCache() {
1421
- wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
1422
- }
1423
- function buildMatcherFromPreprocessedRoutes(routes) {
1424
- const trie = new Trie();
1425
- const handlerData = [];
1426
- if (routes.length === 0) return nullMatcher;
1427
- const routesWithStaticPathFlag = routes.map((route) => [!/\*|\/:/.test(route[0]), ...route]).sort(([isStaticA, pathA], [isStaticB, pathB]) => isStaticA ? 1 : isStaticB ? -1 : pathA.length - pathB.length);
1428
- const staticMap = /* @__PURE__ */ Object.create(null);
1429
- for (let i = 0, j = -1, len = routesWithStaticPathFlag.length; i < len; i++) {
1430
- const [pathErrorCheckOnly, path, handlers] = routesWithStaticPathFlag[i];
1431
- if (pathErrorCheckOnly) staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
1432
- else j++;
1433
- let paramAssoc;
1434
- try {
1435
- paramAssoc = trie.insert(path, j, pathErrorCheckOnly);
1436
- } catch (e) {
1437
- throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
1438
- }
1439
- if (pathErrorCheckOnly) continue;
1440
- handlerData[j] = handlers.map(([h, paramCount]) => {
1441
- const paramIndexMap = /* @__PURE__ */ Object.create(null);
1442
- paramCount -= 1;
1443
- for (; paramCount >= 0; paramCount--) {
1444
- const [key, value] = paramAssoc[paramCount];
1445
- paramIndexMap[key] = value;
1446
- }
1447
- return [h, paramIndexMap];
1448
- });
1449
- }
1450
- const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
1451
- for (let i = 0, len = handlerData.length; i < len; i++) for (let j = 0, len2 = handlerData[i].length; j < len2; j++) {
1452
- const map = handlerData[i][j]?.[1];
1453
- if (!map) continue;
1454
- const keys = Object.keys(map);
1455
- for (let k = 0, len3 = keys.length; k < len3; k++) map[keys[k]] = paramReplacementMap[map[keys[k]]];
1456
- }
1457
- const handlerMap = [];
1458
- for (const i in indexReplacementMap) handlerMap[i] = handlerData[indexReplacementMap[i]];
1459
- return [
1460
- regexp,
1461
- handlerMap,
1462
- staticMap
1463
- ];
1464
- }
1465
- function findMiddleware(middleware, path) {
1466
- if (!middleware) return;
1467
- for (const k of Object.keys(middleware).sort((a, b) => b.length - a.length)) if (buildWildcardRegExp(k).test(path)) return [...middleware[k]];
1468
- }
1469
- var RegExpRouter = class {
1470
- name = "RegExpRouter";
1471
- #middleware;
1472
- #routes;
1473
- constructor() {
1474
- this.#middleware = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
1475
- this.#routes = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
1476
- }
1477
- add(method, path, handler) {
1478
- const middleware = this.#middleware;
1479
- const routes = this.#routes;
1480
- if (!middleware || !routes) throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
1481
- if (!middleware[method]) [middleware, routes].forEach((handlerMap) => {
1482
- handlerMap[method] = /* @__PURE__ */ Object.create(null);
1483
- Object.keys(handlerMap[METHOD_NAME_ALL]).forEach((p) => {
1484
- handlerMap[method][p] = [...handlerMap[METHOD_NAME_ALL][p]];
1485
- });
1486
- });
1487
- if (path === "/*") path = "*";
1488
- const paramCount = (path.match(/\/:/g) || []).length;
1489
- if (/\*$/.test(path)) {
1490
- const re = buildWildcardRegExp(path);
1491
- if (method === METHOD_NAME_ALL) Object.keys(middleware).forEach((m) => {
1492
- middleware[m][path] ||= findMiddleware(middleware[m], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
1493
- });
1494
- else middleware[method][path] ||= findMiddleware(middleware[method], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
1495
- Object.keys(middleware).forEach((m) => {
1496
- if (method === METHOD_NAME_ALL || method === m) Object.keys(middleware[m]).forEach((p) => {
1497
- re.test(p) && middleware[m][p].push([handler, paramCount]);
1498
- });
1499
- });
1500
- Object.keys(routes).forEach((m) => {
1501
- if (method === METHOD_NAME_ALL || method === m) Object.keys(routes[m]).forEach((p) => re.test(p) && routes[m][p].push([handler, paramCount]));
1502
- });
1503
- return;
1504
- }
1505
- const paths = checkOptionalParameter(path) || [path];
1506
- for (let i = 0, len = paths.length; i < len; i++) {
1507
- const path2 = paths[i];
1508
- Object.keys(routes).forEach((m) => {
1509
- if (method === METHOD_NAME_ALL || method === m) {
1510
- routes[m][path2] ||= [...findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || []];
1511
- routes[m][path2].push([handler, paramCount - len + i + 1]);
1512
- }
1513
- });
1514
- }
1515
- }
1516
- match = match;
1517
- buildAllMatchers() {
1518
- const matchers = /* @__PURE__ */ Object.create(null);
1519
- Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
1520
- matchers[method] ||= this.#buildMatcher(method);
1521
- });
1522
- this.#middleware = this.#routes = void 0;
1523
- clearWildcardRegExpCache();
1524
- return matchers;
1525
- }
1526
- #buildMatcher(method) {
1527
- const routes = [];
1528
- let hasOwnRoute = method === METHOD_NAME_ALL;
1529
- [this.#middleware, this.#routes].forEach((r) => {
1530
- const ownRoute = r[method] ? Object.keys(r[method]).map((path) => [path, r[method][path]]) : [];
1531
- if (ownRoute.length !== 0) {
1532
- hasOwnRoute ||= true;
1533
- routes.push(...ownRoute);
1534
- } else if (method !== METHOD_NAME_ALL) routes.push(...Object.keys(r[METHOD_NAME_ALL]).map((path) => [path, r[METHOD_NAME_ALL][path]]));
1535
- });
1536
- if (!hasOwnRoute) return null;
1537
- else return buildMatcherFromPreprocessedRoutes(routes);
1538
- }
1539
- };
1540
-
1541
- //#endregion
1542
- //#region ../../node_modules/.pnpm/hono@4.11.6/node_modules/hono/dist/router/smart-router/router.js
1543
- var SmartRouter = class {
1544
- name = "SmartRouter";
1545
- #routers = [];
1546
- #routes = [];
1547
- constructor(init) {
1548
- this.#routers = init.routers;
1549
- }
1550
- add(method, path, handler) {
1551
- if (!this.#routes) throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
1552
- this.#routes.push([
1553
- method,
1554
- path,
1555
- handler
1556
- ]);
1557
- }
1558
- match(method, path) {
1559
- if (!this.#routes) throw new Error("Fatal error");
1560
- const routers = this.#routers;
1561
- const routes = this.#routes;
1562
- const len = routers.length;
1563
- let i = 0;
1564
- let res;
1565
- for (; i < len; i++) {
1566
- const router = routers[i];
1567
- try {
1568
- for (let i2 = 0, len2 = routes.length; i2 < len2; i2++) router.add(...routes[i2]);
1569
- res = router.match(method, path);
1570
- } catch (e) {
1571
- if (e instanceof UnsupportedPathError) continue;
1572
- throw e;
1573
- }
1574
- this.match = router.match.bind(router);
1575
- this.#routers = [router];
1576
- this.#routes = void 0;
1577
- break;
1578
- }
1579
- if (i === len) throw new Error("Fatal error");
1580
- this.name = `SmartRouter + ${this.activeRouter.name}`;
1581
- return res;
1582
- }
1583
- get activeRouter() {
1584
- if (this.#routes || this.#routers.length !== 1) throw new Error("No active router has been determined yet.");
1585
- return this.#routers[0];
1586
- }
1587
- };
1588
-
1589
- //#endregion
1590
- //#region ../../node_modules/.pnpm/hono@4.11.6/node_modules/hono/dist/router/trie-router/node.js
1591
- var emptyParams = /* @__PURE__ */ Object.create(null);
1592
- var Node = class _Node {
1593
- #methods;
1594
- #children;
1595
- #patterns;
1596
- #order = 0;
1597
- #params = emptyParams;
1598
- constructor(method, handler, children) {
1599
- this.#children = children || /* @__PURE__ */ Object.create(null);
1600
- this.#methods = [];
1601
- if (method && handler) {
1602
- const m = /* @__PURE__ */ Object.create(null);
1603
- m[method] = {
1604
- handler,
1605
- possibleKeys: [],
1606
- score: 0
1607
- };
1608
- this.#methods = [m];
1609
- }
1610
- this.#patterns = [];
1611
- }
1612
- insert(method, path, handler) {
1613
- this.#order = ++this.#order;
1614
- let curNode = this;
1615
- const parts = splitRoutingPath(path);
1616
- const possibleKeys = [];
1617
- for (let i = 0, len = parts.length; i < len; i++) {
1618
- const p = parts[i];
1619
- const nextP = parts[i + 1];
1620
- const pattern = getPattern(p, nextP);
1621
- const key = Array.isArray(pattern) ? pattern[0] : p;
1622
- if (key in curNode.#children) {
1623
- curNode = curNode.#children[key];
1624
- if (pattern) possibleKeys.push(pattern[1]);
1625
- continue;
1626
- }
1627
- curNode.#children[key] = new _Node();
1628
- if (pattern) {
1629
- curNode.#patterns.push(pattern);
1630
- possibleKeys.push(pattern[1]);
1631
- }
1632
- curNode = curNode.#children[key];
1633
- }
1634
- curNode.#methods.push({ [method]: {
1635
- handler,
1636
- possibleKeys: possibleKeys.filter((v, i, a) => a.indexOf(v) === i),
1637
- score: this.#order
1638
- } });
1639
- return curNode;
1640
- }
1641
- #getHandlerSets(node, method, nodeParams, params) {
1642
- const handlerSets = [];
1643
- for (let i = 0, len = node.#methods.length; i < len; i++) {
1644
- const m = node.#methods[i];
1645
- const handlerSet = m[method] || m[METHOD_NAME_ALL];
1646
- const processedSet = {};
1647
- if (handlerSet !== void 0) {
1648
- handlerSet.params = /* @__PURE__ */ Object.create(null);
1649
- handlerSets.push(handlerSet);
1650
- if (nodeParams !== emptyParams || params && params !== emptyParams) for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
1651
- const key = handlerSet.possibleKeys[i2];
1652
- const processed = processedSet[handlerSet.score];
1653
- handlerSet.params[key] = params?.[key] && !processed ? params[key] : nodeParams[key] ?? params?.[key];
1654
- processedSet[handlerSet.score] = true;
1655
- }
1656
- }
1657
- }
1658
- return handlerSets;
1659
- }
1660
- search(method, path) {
1661
- const handlerSets = [];
1662
- this.#params = emptyParams;
1663
- let curNodes = [this];
1664
- const parts = splitPath(path);
1665
- const curNodesQueue = [];
1666
- for (let i = 0, len = parts.length; i < len; i++) {
1667
- const part = parts[i];
1668
- const isLast = i === len - 1;
1669
- const tempNodes = [];
1670
- for (let j = 0, len2 = curNodes.length; j < len2; j++) {
1671
- const node = curNodes[j];
1672
- const nextNode = node.#children[part];
1673
- if (nextNode) {
1674
- nextNode.#params = node.#params;
1675
- if (isLast) {
1676
- if (nextNode.#children["*"]) handlerSets.push(...this.#getHandlerSets(nextNode.#children["*"], method, node.#params));
1677
- handlerSets.push(...this.#getHandlerSets(nextNode, method, node.#params));
1678
- } else tempNodes.push(nextNode);
1679
- }
1680
- for (let k = 0, len3 = node.#patterns.length; k < len3; k++) {
1681
- const pattern = node.#patterns[k];
1682
- const params = node.#params === emptyParams ? {} : { ...node.#params };
1683
- if (pattern === "*") {
1684
- const astNode = node.#children["*"];
1685
- if (astNode) {
1686
- handlerSets.push(...this.#getHandlerSets(astNode, method, node.#params));
1687
- astNode.#params = params;
1688
- tempNodes.push(astNode);
1689
- }
1690
- continue;
1691
- }
1692
- const [key, name, matcher] = pattern;
1693
- if (!part && !(matcher instanceof RegExp)) continue;
1694
- const child = node.#children[key];
1695
- const restPathString = parts.slice(i).join("/");
1696
- if (matcher instanceof RegExp) {
1697
- const m = matcher.exec(restPathString);
1698
- if (m) {
1699
- params[name] = m[0];
1700
- handlerSets.push(...this.#getHandlerSets(child, method, node.#params, params));
1701
- if (Object.keys(child.#children).length) {
1702
- child.#params = params;
1703
- const componentCount = m[0].match(/\//)?.length ?? 0;
1704
- (curNodesQueue[componentCount] ||= []).push(child);
1705
- }
1706
- continue;
1707
- }
1708
- }
1709
- if (matcher === true || matcher.test(part)) {
1710
- params[name] = part;
1711
- if (isLast) {
1712
- handlerSets.push(...this.#getHandlerSets(child, method, params, node.#params));
1713
- if (child.#children["*"]) handlerSets.push(...this.#getHandlerSets(child.#children["*"], method, params, node.#params));
1714
- } else {
1715
- child.#params = params;
1716
- tempNodes.push(child);
1717
- }
1718
- }
1719
- }
1720
- }
1721
- curNodes = tempNodes.concat(curNodesQueue.shift() ?? []);
1722
- }
1723
- if (handlerSets.length > 1) handlerSets.sort((a, b) => {
1724
- return a.score - b.score;
1725
- });
1726
- return [handlerSets.map(({ handler, params }) => [handler, params])];
1727
- }
1728
- };
1729
-
1730
- //#endregion
1731
- //#region ../../node_modules/.pnpm/hono@4.11.6/node_modules/hono/dist/router/trie-router/router.js
1732
- var TrieRouter = class {
1733
- name = "TrieRouter";
1734
- #node;
1735
- constructor() {
1736
- this.#node = new Node();
1737
- }
1738
- add(method, path, handler) {
1739
- const results = checkOptionalParameter(path);
1740
- if (results) {
1741
- for (let i = 0, len = results.length; i < len; i++) this.#node.insert(method, results[i], handler);
1742
- return;
1743
- }
1744
- this.#node.insert(method, path, handler);
1745
- }
1746
- match(method, path) {
1747
- return this.#node.search(method, path);
1748
- }
1749
- };
1750
-
1751
- //#endregion
1752
- //#region ../../node_modules/.pnpm/hono@4.11.6/node_modules/hono/dist/hono.js
1753
- var Hono = class extends Hono$1 {
1754
- /**
1755
- * Creates an instance of the Hono class.
1756
- *
1757
- * @param options - Optional configuration options for the Hono instance.
1758
- */
1759
- constructor(options = {}) {
1760
- super(options);
1761
- this.router = options.router ?? new SmartRouter({ routers: [new RegExpRouter(), new TrieRouter()] });
1762
- }
1763
- };
1764
-
1765
- //#endregion
1766
- //#region ../../node_modules/.pnpm/hono@4.11.6/node_modules/hono/dist/middleware/cors/index.js
1767
- var cors = (options) => {
1768
- const opts = {
1769
- origin: "*",
1770
- allowMethods: [
1771
- "GET",
1772
- "HEAD",
1773
- "PUT",
1774
- "POST",
1775
- "DELETE",
1776
- "PATCH"
1777
- ],
1778
- allowHeaders: [],
1779
- exposeHeaders: [],
1780
- ...options
1781
- };
1782
- const findAllowOrigin = ((optsOrigin) => {
1783
- if (typeof optsOrigin === "string") if (optsOrigin === "*") return () => optsOrigin;
1784
- else return (origin) => optsOrigin === origin ? origin : null;
1785
- else if (typeof optsOrigin === "function") return optsOrigin;
1786
- else return (origin) => optsOrigin.includes(origin) ? origin : null;
1787
- })(opts.origin);
1788
- const findAllowMethods = ((optsAllowMethods) => {
1789
- if (typeof optsAllowMethods === "function") return optsAllowMethods;
1790
- else if (Array.isArray(optsAllowMethods)) return () => optsAllowMethods;
1791
- else return () => [];
1792
- })(opts.allowMethods);
1793
- return async function cors2(c, next) {
1794
- function set(key, value) {
1795
- c.res.headers.set(key, value);
1796
- }
1797
- const allowOrigin = await findAllowOrigin(c.req.header("origin") || "", c);
1798
- if (allowOrigin) set("Access-Control-Allow-Origin", allowOrigin);
1799
- if (opts.credentials) set("Access-Control-Allow-Credentials", "true");
1800
- if (opts.exposeHeaders?.length) set("Access-Control-Expose-Headers", opts.exposeHeaders.join(","));
1801
- if (c.req.method === "OPTIONS") {
1802
- if (opts.origin !== "*") set("Vary", "Origin");
1803
- if (opts.maxAge != null) set("Access-Control-Max-Age", opts.maxAge.toString());
1804
- const allowMethods = await findAllowMethods(c.req.header("origin") || "", c);
1805
- if (allowMethods.length) set("Access-Control-Allow-Methods", allowMethods.join(","));
1806
- let headers = opts.allowHeaders;
1807
- if (!headers?.length) {
1808
- const requestHeaders = c.req.header("Access-Control-Request-Headers");
1809
- if (requestHeaders) headers = requestHeaders.split(/\s*,\s*/);
1810
- }
1811
- if (headers?.length) {
1812
- set("Access-Control-Allow-Headers", headers.join(","));
1813
- c.res.headers.append("Vary", "Access-Control-Request-Headers");
1814
- }
1815
- c.res.headers.delete("Content-Length");
1816
- c.res.headers.delete("Content-Type");
1817
- return new Response(null, {
1818
- headers: c.res.headers,
1819
- status: 204,
1820
- statusText: "No Content"
1821
- });
1822
- }
1823
- await next();
1824
- if (opts.origin !== "*") c.header("Vary", "Origin", { append: true });
1825
- };
1826
- };
1827
-
1828
- //#endregion
1829
- export { Hono as n, cors as t };