@hot-updater/console 0.1.5 → 0.2.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 (35) hide show
  1. package/dist/index.cjs +1909 -2236
  2. package/dist/index.html +1 -1
  3. package/dist/index.js +1868 -2219
  4. package/dist/src/App.d.ts +2 -0
  5. package/dist/src/components/spash-screen.d.ts +1 -0
  6. package/dist/src/components/ui/button.d.ts +15 -0
  7. package/dist/src/components/ui/label.d.ts +3 -0
  8. package/dist/src/components/ui/navigation-menu.d.ts +35 -0
  9. package/dist/src/components/ui/pagination.d.ts +27 -0
  10. package/dist/src/components/ui/sheet.d.ts +26 -0
  11. package/dist/src/components/ui/sonner.d.ts +5 -0
  12. package/dist/src/components/ui/switch.d.ts +20 -0
  13. package/dist/src/components/ui/table.d.ts +10 -0
  14. package/dist/src/components/ui/text-field.d.ts +26 -0
  15. package/dist/src/index.d.ts +1 -0
  16. package/dist/src/lib/api.d.ts +98 -0
  17. package/dist/src/lib/extract-timestamp-from-uuidv7.d.ts +1 -0
  18. package/dist/src/lib/utils.d.ts +2 -0
  19. package/dist/src/routes/_components/columns.d.ts +3 -0
  20. package/dist/src/routes/_components/data-table.d.ts +9 -0
  21. package/dist/src/routes/_components/edit-bundle-sheet-content.d.ts +5 -0
  22. package/dist/src/routes/index.d.ts +1 -0
  23. package/dist/src-server/index.d.ts +112 -0
  24. package/dist/src-server/rpc.d.ts +112 -0
  25. package/dist/src-server/type.test.d.ts +1 -0
  26. package/dist/static/css/index.4ed6b07e.css +1 -0
  27. package/dist/static/js/742.e04944e6.js +5 -0
  28. package/dist/static/js/index.7055a4a0.js +1 -0
  29. package/package.json +8 -5
  30. package/dist/index.d.cts +0 -101
  31. package/dist/index.d.ts +0 -101
  32. package/dist/static/css/index.8b7116d7.css +0 -1
  33. package/dist/static/js/85.cfaeff33.js +0 -5
  34. package/dist/static/js/index.566f7a26.js +0 -1
  35. /package/dist/static/js/{85.cfaeff33.js.LICENSE.txt → 742.e04944e6.js.LICENSE.txt} +0 -0
package/dist/index.cjs CHANGED
@@ -1,2422 +1,2095 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __typeError = (msg) => {
9
- throw TypeError(msg);
10
- };
11
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
- var __export = (target, all) => {
13
- for (var name in all)
14
- __defProp(target, name, { get: all[name], enumerable: true });
15
- };
16
- var __copyProps = (to, from, except, desc) => {
17
- if (from && typeof from === "object" || typeof from === "function") {
18
- for (let key of __getOwnPropNames(from))
19
- if (!__hasOwnProp.call(to, key) && key !== except)
20
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
- }
22
- return to;
23
- };
24
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25
- // If the importer is in node compatibility mode or this is not an ESM
26
- // file that has been converted to a CommonJS file using a Babel-
27
- // compatible transform (i.e. "__esModule" has not been set), then set
28
- // "default" to the CommonJS "module.exports" for node compatibility.
29
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
30
- mod
31
- ));
32
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
33
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
34
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
35
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
36
- var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
37
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
38
-
39
- // src-server/index.ts
40
- var src_server_exports = {};
41
- __export(src_server_exports, {
42
- default: () => src_server_default
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = function(module) {
5
+ var getter = module && module.__esModule ? function() {
6
+ return module['default'];
7
+ } : function() {
8
+ return module;
9
+ };
10
+ __webpack_require__.d(getter, {
11
+ a: getter
12
+ });
13
+ return getter;
14
+ };
15
+ })();
16
+ (()=>{
17
+ __webpack_require__.d = function(exports1, definition) {
18
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
19
+ enumerable: true,
20
+ get: definition[key]
21
+ });
22
+ };
23
+ })();
24
+ (()=>{
25
+ __webpack_require__.o = function(obj, prop) {
26
+ return Object.prototype.hasOwnProperty.call(obj, prop);
27
+ };
28
+ })();
29
+ (()=>{
30
+ __webpack_require__.r = function(exports1) {
31
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
32
+ value: 'Module'
33
+ });
34
+ Object.defineProperty(exports1, '__esModule', {
35
+ value: true
36
+ });
37
+ };
38
+ })();
39
+ var __webpack_exports__ = {};
40
+ __webpack_require__.r(__webpack_exports__);
41
+ __webpack_require__.d(__webpack_exports__, {
42
+ default: ()=>src_server_rslib_entry_
43
43
  });
44
- module.exports = __toCommonJS(src_server_exports);
45
- var import_path = __toESM(require("path"), 1);
46
-
47
- // ../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/utils/filepath.js
48
- var getFilePath = (options) => {
49
- let filename = options.filename;
50
- const defaultDocument = options.defaultDocument || "index.html";
51
- if (filename.endsWith("/")) {
52
- filename = filename.concat(defaultDocument);
53
- } else if (!filename.match(/\.[a-zA-Z0-9_-]+$/)) {
54
- filename = filename.concat("/" + defaultDocument);
55
- }
56
- const path2 = getFilePathWithoutDefaultDocument({
57
- root: options.root,
58
- filename
59
- });
60
- return path2;
44
+ const external_path_namespaceObject = require("path");
45
+ var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
46
+ var getFilePath = (options)=>{
47
+ let filename = options.filename;
48
+ const defaultDocument = options.defaultDocument || "index.html";
49
+ if (filename.endsWith("/")) filename = filename.concat(defaultDocument);
50
+ else if (!filename.match(/\.[a-zA-Z0-9_-]+$/)) filename = filename.concat("/" + defaultDocument);
51
+ const path = getFilePathWithoutDefaultDocument({
52
+ root: options.root,
53
+ filename
54
+ });
55
+ return path;
61
56
  };
62
- var getFilePathWithoutDefaultDocument = (options) => {
63
- let root = options.root || "";
64
- let filename = options.filename;
65
- if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename)) {
66
- return;
67
- }
68
- filename = filename.replace(/^\.?[\/\\]/, "");
69
- filename = filename.replace(/\\/, "/");
70
- root = root.replace(/\/$/, "");
71
- let path2 = root ? root + "/" + filename : filename;
72
- path2 = path2.replace(/^\.?\//, "");
73
- if (root[0] !== "/" && path2[0] === "/") {
74
- return;
75
- }
76
- return path2;
57
+ var getFilePathWithoutDefaultDocument = (options)=>{
58
+ let root = options.root || "";
59
+ let filename = options.filename;
60
+ if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename)) return;
61
+ filename = filename.replace(/^\.?[\/\\]/, "");
62
+ filename = filename.replace(/\\/, "/");
63
+ root = root.replace(/\/$/, "");
64
+ let path = root ? root + "/" + filename : filename;
65
+ path = path.replace(/^\.?\//, "");
66
+ if ("/" !== root[0] && "/" === path[0]) return;
67
+ return path;
77
68
  };
78
-
79
- // ../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/utils/mime.js
80
- var getMimeType = (filename, mimes = baseMimes) => {
81
- const regexp = /\.([a-zA-Z0-9]+?)$/;
82
- const match = filename.match(regexp);
83
- if (!match) {
84
- return;
85
- }
86
- let mimeType = mimes[match[1]];
87
- if (mimeType && mimeType.startsWith("text") || mimeType === "application/json") {
88
- mimeType += "; charset=utf-8";
89
- }
90
- return mimeType;
69
+ var getMimeType = (filename, mimes = baseMimes)=>{
70
+ const regexp = /\.([a-zA-Z0-9]+?)$/;
71
+ const match = filename.match(regexp);
72
+ if (!match) return;
73
+ let mimeType = mimes[match[1]];
74
+ if (mimeType && mimeType.startsWith("text") || "application/json" === mimeType) mimeType += "; charset=utf-8";
75
+ return mimeType;
91
76
  };
92
77
  var baseMimes = {
93
- aac: "audio/aac",
94
- avi: "video/x-msvideo",
95
- avif: "image/avif",
96
- av1: "video/av1",
97
- bin: "application/octet-stream",
98
- bmp: "image/bmp",
99
- css: "text/css",
100
- csv: "text/csv",
101
- eot: "application/vnd.ms-fontobject",
102
- epub: "application/epub+zip",
103
- gif: "image/gif",
104
- gz: "application/gzip",
105
- htm: "text/html",
106
- html: "text/html",
107
- ico: "image/x-icon",
108
- ics: "text/calendar",
109
- jpeg: "image/jpeg",
110
- jpg: "image/jpeg",
111
- js: "text/javascript",
112
- json: "application/json",
113
- jsonld: "application/ld+json",
114
- map: "application/json",
115
- mid: "audio/x-midi",
116
- midi: "audio/x-midi",
117
- mjs: "text/javascript",
118
- mp3: "audio/mpeg",
119
- mp4: "video/mp4",
120
- mpeg: "video/mpeg",
121
- oga: "audio/ogg",
122
- ogv: "video/ogg",
123
- ogx: "application/ogg",
124
- opus: "audio/opus",
125
- otf: "font/otf",
126
- pdf: "application/pdf",
127
- png: "image/png",
128
- rtf: "application/rtf",
129
- svg: "image/svg+xml",
130
- tif: "image/tiff",
131
- tiff: "image/tiff",
132
- ts: "video/mp2t",
133
- ttf: "font/ttf",
134
- txt: "text/plain",
135
- wasm: "application/wasm",
136
- webm: "video/webm",
137
- weba: "audio/webm",
138
- webp: "image/webp",
139
- woff: "font/woff",
140
- woff2: "font/woff2",
141
- xhtml: "application/xhtml+xml",
142
- xml: "application/xml",
143
- zip: "application/zip",
144
- "3gp": "video/3gpp",
145
- "3g2": "video/3gpp2",
146
- gltf: "model/gltf+json",
147
- glb: "model/gltf-binary"
78
+ aac: "audio/aac",
79
+ avi: "video/x-msvideo",
80
+ avif: "image/avif",
81
+ av1: "video/av1",
82
+ bin: "application/octet-stream",
83
+ bmp: "image/bmp",
84
+ css: "text/css",
85
+ csv: "text/csv",
86
+ eot: "application/vnd.ms-fontobject",
87
+ epub: "application/epub+zip",
88
+ gif: "image/gif",
89
+ gz: "application/gzip",
90
+ htm: "text/html",
91
+ html: "text/html",
92
+ ico: "image/x-icon",
93
+ ics: "text/calendar",
94
+ jpeg: "image/jpeg",
95
+ jpg: "image/jpeg",
96
+ js: "text/javascript",
97
+ json: "application/json",
98
+ jsonld: "application/ld+json",
99
+ map: "application/json",
100
+ mid: "audio/x-midi",
101
+ midi: "audio/x-midi",
102
+ mjs: "text/javascript",
103
+ mp3: "audio/mpeg",
104
+ mp4: "video/mp4",
105
+ mpeg: "video/mpeg",
106
+ oga: "audio/ogg",
107
+ ogv: "video/ogg",
108
+ ogx: "application/ogg",
109
+ opus: "audio/opus",
110
+ otf: "font/otf",
111
+ pdf: "application/pdf",
112
+ png: "image/png",
113
+ rtf: "application/rtf",
114
+ svg: "image/svg+xml",
115
+ tif: "image/tiff",
116
+ tiff: "image/tiff",
117
+ ts: "video/mp2t",
118
+ ttf: "font/ttf",
119
+ txt: "text/plain",
120
+ wasm: "application/wasm",
121
+ webm: "video/webm",
122
+ weba: "audio/webm",
123
+ webp: "image/webp",
124
+ woff: "font/woff",
125
+ woff2: "font/woff2",
126
+ xhtml: "application/xhtml+xml",
127
+ xml: "application/xml",
128
+ zip: "application/zip",
129
+ "3gp": "video/3gpp",
130
+ "3g2": "video/3gpp2",
131
+ gltf: "model/gltf+json",
132
+ glb: "model/gltf-binary"
148
133
  };
149
-
150
- // ../../node_modules/.pnpm/@hono+node-server@1.13.4_hono@4.6.3/node_modules/@hono/node-server/dist/serve-static.mjs
151
- var import_fs = require("fs");
134
+ const external_fs_namespaceObject = require("fs");
152
135
  var COMPRESSIBLE_CONTENT_TYPE_REGEX = /^\s*(?:text\/[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|wasm|x-httpd-php|x-javascript|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml))(?:[;\s]|$)/i;
153
136
  var ENCODINGS = {
154
- br: ".br",
155
- zstd: ".zst",
156
- gzip: ".gz"
137
+ br: ".br",
138
+ zstd: ".zst",
139
+ gzip: ".gz"
157
140
  };
158
141
  var ENCODINGS_ORDERED_KEYS = Object.keys(ENCODINGS);
159
- var createStreamBody = (stream) => {
160
- const body = new ReadableStream({
161
- start(controller) {
162
- stream.on("data", (chunk) => {
163
- controller.enqueue(chunk);
164
- });
165
- stream.on("end", () => {
166
- controller.close();
167
- });
168
- },
169
- cancel() {
170
- stream.destroy();
171
- }
172
- });
173
- return body;
174
- };
175
- var addCurrentDirPrefix = (path2) => {
176
- return `./${path2}`;
177
- };
178
- var getStats = (path2) => {
179
- let stats;
180
- try {
181
- stats = (0, import_fs.lstatSync)(path2);
182
- } catch {
183
- }
184
- return stats;
142
+ var createStreamBody = (stream)=>{
143
+ const body = new ReadableStream({
144
+ start (controller) {
145
+ stream.on("data", (chunk)=>{
146
+ controller.enqueue(chunk);
147
+ });
148
+ stream.on("end", ()=>{
149
+ controller.close();
150
+ });
151
+ },
152
+ cancel () {
153
+ stream.destroy();
154
+ }
155
+ });
156
+ return body;
185
157
  };
186
- var serveStatic = (options = { root: "" }) => {
187
- return async (c, next) => {
188
- if (c.finalized) {
189
- return next();
190
- }
191
- let filename;
158
+ var addCurrentDirPrefix = (path)=>`./${path}`;
159
+ var getStats = (path)=>{
160
+ let stats;
192
161
  try {
193
- filename = options.path ?? decodeURIComponent(c.req.path);
194
- } catch {
195
- await options.onNotFound?.(c.req.path, c);
196
- return next();
197
- }
198
- let path2 = getFilePathWithoutDefaultDocument({
199
- filename: options.rewriteRequestPath ? options.rewriteRequestPath(filename) : filename,
200
- root: options.root
201
- });
202
- if (path2) {
203
- path2 = addCurrentDirPrefix(path2);
204
- } else {
205
- return next();
206
- }
207
- let stats = getStats(path2);
208
- if (stats && stats.isDirectory()) {
209
- path2 = getFilePath({
210
- filename: options.rewriteRequestPath ? options.rewriteRequestPath(filename) : filename,
211
- root: options.root,
212
- defaultDocument: options.index ?? "index.html"
213
- });
214
- if (path2) {
215
- path2 = addCurrentDirPrefix(path2);
216
- } else {
217
- return next();
218
- }
219
- stats = getStats(path2);
220
- }
221
- if (!stats) {
222
- await options.onNotFound?.(path2, c);
223
- return next();
224
- }
225
- await options.onFound?.(path2, c);
226
- const mimeType = getMimeType(path2);
227
- c.header("Content-Type", mimeType || "application/octet-stream");
228
- if (options.precompressed && (!mimeType || COMPRESSIBLE_CONTENT_TYPE_REGEX.test(mimeType))) {
229
- const acceptEncodingSet = new Set(
230
- c.req.header("Accept-Encoding")?.split(",").map((encoding) => encoding.trim())
231
- );
232
- for (const encoding of ENCODINGS_ORDERED_KEYS) {
233
- if (!acceptEncodingSet.has(encoding)) {
234
- continue;
162
+ stats = (0, external_fs_namespaceObject.lstatSync)(path);
163
+ } catch {}
164
+ return stats;
165
+ };
166
+ var serveStatic = (options = {
167
+ root: ""
168
+ })=>async (c, next)=>{
169
+ if (c.finalized) return next();
170
+ let filename;
171
+ try {
172
+ filename = options.path ?? decodeURIComponent(c.req.path);
173
+ } catch {
174
+ await options.onNotFound?.(c.req.path, c);
175
+ return next();
235
176
  }
236
- const precompressedStats = getStats(path2 + ENCODINGS[encoding]);
237
- if (precompressedStats) {
238
- c.header("Content-Encoding", encoding);
239
- c.header("Vary", "Accept-Encoding", { append: true });
240
- stats = precompressedStats;
241
- path2 = path2 + ENCODINGS[encoding];
242
- break;
177
+ let path = getFilePathWithoutDefaultDocument({
178
+ filename: options.rewriteRequestPath ? options.rewriteRequestPath(filename) : filename,
179
+ root: options.root
180
+ });
181
+ if (!path) return next();
182
+ path = addCurrentDirPrefix(path);
183
+ let stats = getStats(path);
184
+ if (stats && stats.isDirectory()) {
185
+ path = getFilePath({
186
+ filename: options.rewriteRequestPath ? options.rewriteRequestPath(filename) : filename,
187
+ root: options.root,
188
+ defaultDocument: options.index ?? "index.html"
189
+ });
190
+ if (!path) return next();
191
+ path = addCurrentDirPrefix(path);
192
+ stats = getStats(path);
243
193
  }
244
- }
245
- }
246
- const size = stats.size;
247
- if (c.req.method == "HEAD" || c.req.method == "OPTIONS") {
248
- c.header("Content-Length", size.toString());
249
- c.status(200);
250
- return c.body(null);
251
- }
252
- const range = c.req.header("range") || "";
253
- if (!range) {
254
- c.header("Content-Length", size.toString());
255
- return c.body(createStreamBody((0, import_fs.createReadStream)(path2)), 200);
256
- }
257
- c.header("Accept-Ranges", "bytes");
258
- c.header("Date", stats.birthtime.toUTCString());
259
- const parts = range.replace(/bytes=/, "").split("-", 2);
260
- const start = parts[0] ? parseInt(parts[0], 10) : 0;
261
- let end = parts[1] ? parseInt(parts[1], 10) : stats.size - 1;
262
- if (size < end - start + 1) {
263
- end = size - 1;
264
- }
265
- const chunksize = end - start + 1;
266
- const stream = (0, import_fs.createReadStream)(path2, { start, end });
267
- c.header("Content-Length", chunksize.toString());
268
- c.header("Content-Range", `bytes ${start}-${end}/${stats.size}`);
269
- return c.body(createStreamBody(stream), 206);
270
- };
271
- };
272
-
273
- // ../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/utils/body.js
274
- var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
275
- const { all = false, dot = false } = options;
276
- const headers = request instanceof HonoRequest ? request.raw.headers : request.headers;
277
- const contentType = headers.get("Content-Type");
278
- if (contentType?.startsWith("multipart/form-data") || contentType?.startsWith("application/x-www-form-urlencoded")) {
279
- return parseFormData(request, { all, dot });
280
- }
281
- return {};
194
+ if (!stats) {
195
+ await options.onNotFound?.(path, c);
196
+ return next();
197
+ }
198
+ await options.onFound?.(path, c);
199
+ const mimeType = getMimeType(path);
200
+ c.header("Content-Type", mimeType || "application/octet-stream");
201
+ if (options.precompressed && (!mimeType || COMPRESSIBLE_CONTENT_TYPE_REGEX.test(mimeType))) {
202
+ const acceptEncodingSet = new Set(c.req.header("Accept-Encoding")?.split(",").map((encoding)=>encoding.trim()));
203
+ for (const encoding of ENCODINGS_ORDERED_KEYS){
204
+ if (!acceptEncodingSet.has(encoding)) continue;
205
+ const precompressedStats = getStats(path + ENCODINGS[encoding]);
206
+ if (precompressedStats) {
207
+ c.header("Content-Encoding", encoding);
208
+ c.header("Vary", "Accept-Encoding", {
209
+ append: true
210
+ });
211
+ stats = precompressedStats;
212
+ path += ENCODINGS[encoding];
213
+ break;
214
+ }
215
+ }
216
+ }
217
+ const size = stats.size;
218
+ if ("HEAD" == c.req.method || "OPTIONS" == c.req.method) {
219
+ c.header("Content-Length", size.toString());
220
+ c.status(200);
221
+ return c.body(null);
222
+ }
223
+ const range = c.req.header("range") || "";
224
+ if (!range) {
225
+ c.header("Content-Length", size.toString());
226
+ return c.body(createStreamBody((0, external_fs_namespaceObject.createReadStream)(path)), 200);
227
+ }
228
+ c.header("Accept-Ranges", "bytes");
229
+ c.header("Date", stats.birthtime.toUTCString());
230
+ const parts = range.replace(/bytes=/, "").split("-", 2);
231
+ const start = parts[0] ? parseInt(parts[0], 10) : 0;
232
+ let end = parts[1] ? parseInt(parts[1], 10) : stats.size - 1;
233
+ if (size < end - start + 1) end = size - 1;
234
+ const chunksize = end - start + 1;
235
+ const stream = (0, external_fs_namespaceObject.createReadStream)(path, {
236
+ start,
237
+ end
238
+ });
239
+ c.header("Content-Length", chunksize.toString());
240
+ c.header("Content-Range", `bytes ${start}-${end}/${stats.size}`);
241
+ return c.body(createStreamBody(stream), 206);
242
+ };
243
+ var parseBody = async (request, options = /* @__PURE__ */ Object.create(null))=>{
244
+ const { all = false, dot = false } = options;
245
+ const headers = request instanceof HonoRequest ? request.raw.headers : request.headers;
246
+ const contentType = headers.get("Content-Type");
247
+ if (contentType?.startsWith("multipart/form-data") || contentType?.startsWith("application/x-www-form-urlencoded")) return parseFormData(request, {
248
+ all,
249
+ dot
250
+ });
251
+ return {};
282
252
  };
283
253
  async function parseFormData(request, options) {
284
- const formData = await request.formData();
285
- if (formData) {
286
- return convertFormDataToBodyData(formData, options);
287
- }
288
- return {};
254
+ const formData = await request.formData();
255
+ if (formData) return convertFormDataToBodyData(formData, options);
256
+ return {};
289
257
  }
290
258
  function convertFormDataToBodyData(formData, options) {
291
- const form = /* @__PURE__ */ Object.create(null);
292
- formData.forEach((value, key) => {
293
- const shouldParseAllValues = options.all || key.endsWith("[]");
294
- if (!shouldParseAllValues) {
295
- form[key] = value;
296
- } else {
297
- handleParsingAllValues(form, key, value);
298
- }
299
- });
300
- if (options.dot) {
301
- Object.entries(form).forEach(([key, value]) => {
302
- const shouldParseDotValues = key.includes(".");
303
- if (shouldParseDotValues) {
304
- handleParsingNestedValues(form, key, value);
305
- delete form[key];
306
- }
259
+ const form = /* @__PURE__ */ Object.create(null);
260
+ formData.forEach((value, key)=>{
261
+ const shouldParseAllValues = options.all || key.endsWith("[]");
262
+ if (shouldParseAllValues) handleParsingAllValues(form, key, value);
263
+ else form[key] = value;
264
+ });
265
+ if (options.dot) Object.entries(form).forEach(([key, value])=>{
266
+ const shouldParseDotValues = key.includes(".");
267
+ if (shouldParseDotValues) {
268
+ handleParsingNestedValues(form, key, value);
269
+ delete form[key];
270
+ }
307
271
  });
308
- }
309
- return form;
272
+ return form;
310
273
  }
311
- var handleParsingAllValues = (form, key, value) => {
312
- if (form[key] !== void 0) {
313
- if (Array.isArray(form[key])) {
314
- ;
315
- form[key].push(value);
316
- } else {
317
- form[key] = [form[key], value];
318
- }
319
- } else {
320
- form[key] = value;
321
- }
274
+ var handleParsingAllValues = (form, key, value)=>{
275
+ if (void 0 !== form[key]) {
276
+ if (Array.isArray(form[key])) form[key].push(value);
277
+ else form[key] = [
278
+ form[key],
279
+ value
280
+ ];
281
+ } else form[key] = value;
322
282
  };
323
- var handleParsingNestedValues = (form, key, value) => {
324
- let nestedForm = form;
325
- const keys = key.split(".");
326
- keys.forEach((key2, index) => {
327
- if (index === keys.length - 1) {
328
- nestedForm[key2] = value;
329
- } else {
330
- if (!nestedForm[key2] || typeof nestedForm[key2] !== "object" || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) {
331
- nestedForm[key2] = /* @__PURE__ */ Object.create(null);
332
- }
333
- nestedForm = nestedForm[key2];
334
- }
335
- });
283
+ var handleParsingNestedValues = (form, key, value)=>{
284
+ let nestedForm = form;
285
+ const keys = key.split(".");
286
+ keys.forEach((key2, index)=>{
287
+ if (index === keys.length - 1) nestedForm[key2] = value;
288
+ else {
289
+ if (!nestedForm[key2] || "object" != typeof nestedForm[key2] || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) nestedForm[key2] = /* @__PURE__ */ Object.create(null);
290
+ nestedForm = nestedForm[key2];
291
+ }
292
+ });
336
293
  };
337
-
338
- // ../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/utils/url.js
339
- var splitPath = (path2) => {
340
- const paths = path2.split("/");
341
- if (paths[0] === "") {
342
- paths.shift();
343
- }
344
- return paths;
294
+ var splitPath = (path)=>{
295
+ const paths = path.split("/");
296
+ if ("" === paths[0]) paths.shift();
297
+ return paths;
345
298
  };
346
- var splitRoutingPath = (routePath) => {
347
- const { groups, path: path2 } = extractGroupsFromPath(routePath);
348
- const paths = splitPath(path2);
349
- return replaceGroupMarks(paths, groups);
299
+ var splitRoutingPath = (routePath)=>{
300
+ const { groups, path } = extractGroupsFromPath(routePath);
301
+ const paths = splitPath(path);
302
+ return replaceGroupMarks(paths, groups);
350
303
  };
351
- var extractGroupsFromPath = (path2) => {
352
- const groups = [];
353
- path2 = path2.replace(/\{[^}]+\}/g, (match, index) => {
354
- const mark = `@${index}`;
355
- groups.push([mark, match]);
356
- return mark;
357
- });
358
- return { groups, path: path2 };
304
+ var extractGroupsFromPath = (path)=>{
305
+ const groups = [];
306
+ path = path.replace(/\{[^}]+\}/g, (match, index)=>{
307
+ const mark = `@${index}`;
308
+ groups.push([
309
+ mark,
310
+ match
311
+ ]);
312
+ return mark;
313
+ });
314
+ return {
315
+ groups,
316
+ path
317
+ };
359
318
  };
360
- var replaceGroupMarks = (paths, groups) => {
361
- for (let i = groups.length - 1; i >= 0; i--) {
362
- const [mark] = groups[i];
363
- for (let j = paths.length - 1; j >= 0; j--) {
364
- if (paths[j].includes(mark)) {
365
- paths[j] = paths[j].replace(mark, groups[i][1]);
366
- break;
367
- }
368
- }
369
- }
370
- return paths;
319
+ var replaceGroupMarks = (paths, groups)=>{
320
+ for(let i = groups.length - 1; i >= 0; i--){
321
+ const [mark] = groups[i];
322
+ for(let j = paths.length - 1; j >= 0; j--)if (paths[j].includes(mark)) {
323
+ paths[j] = paths[j].replace(mark, groups[i][1]);
324
+ break;
325
+ }
326
+ }
327
+ return paths;
371
328
  };
372
329
  var patternCache = {};
373
- var getPattern = (label) => {
374
- if (label === "*") {
375
- return "*";
376
- }
377
- const match = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
378
- if (match) {
379
- if (!patternCache[label]) {
380
- if (match[2]) {
381
- patternCache[label] = [label, match[1], new RegExp("^" + match[2] + "$")];
382
- } else {
383
- patternCache[label] = [label, match[1], true];
384
- }
385
- }
386
- return patternCache[label];
387
- }
388
- return null;
389
- };
390
- var tryDecodeURI = (str) => {
391
- try {
392
- return decodeURI(str);
393
- } catch {
394
- return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match) => {
395
- try {
396
- return decodeURI(match);
397
- } catch {
398
- return match;
399
- }
400
- });
401
- }
330
+ var getPattern = (label)=>{
331
+ if ("*" === label) return "*";
332
+ const match = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
333
+ if (match) {
334
+ if (!patternCache[label]) {
335
+ if (match[2]) patternCache[label] = [
336
+ label,
337
+ match[1],
338
+ new RegExp("^" + match[2] + "$")
339
+ ];
340
+ else patternCache[label] = [
341
+ label,
342
+ match[1],
343
+ true
344
+ ];
345
+ }
346
+ return patternCache[label];
347
+ }
348
+ return null;
402
349
  };
403
- var getPath = (request) => {
404
- const url = request.url;
405
- const start = url.indexOf("/", 8);
406
- let i = start;
407
- for (; i < url.length; i++) {
408
- const charCode = url.charCodeAt(i);
409
- if (charCode === 37) {
410
- const queryIndex = url.indexOf("?", i);
411
- const path2 = url.slice(start, queryIndex === -1 ? void 0 : queryIndex);
412
- return tryDecodeURI(path2.includes("%25") ? path2.replace(/%25/g, "%2525") : path2);
413
- } else if (charCode === 63) {
414
- break;
415
- }
416
- }
417
- return url.slice(start, i);
350
+ var tryDecodeURI = (str)=>{
351
+ try {
352
+ return decodeURI(str);
353
+ } catch {
354
+ return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match)=>{
355
+ try {
356
+ return decodeURI(match);
357
+ } catch {
358
+ return match;
359
+ }
360
+ });
361
+ }
418
362
  };
419
- var getPathNoStrict = (request) => {
420
- const result = getPath(request);
421
- return result.length > 1 && result[result.length - 1] === "/" ? result.slice(0, -1) : result;
363
+ var getPath = (request)=>{
364
+ const url = request.url;
365
+ const start = url.indexOf("/", 8);
366
+ let i = start;
367
+ for(; i < url.length; i++){
368
+ const charCode = url.charCodeAt(i);
369
+ if (37 === charCode) {
370
+ const queryIndex = url.indexOf("?", i);
371
+ const path = url.slice(start, -1 === queryIndex ? void 0 : queryIndex);
372
+ return tryDecodeURI(path.includes("%25") ? path.replace(/%25/g, "%2525") : path);
373
+ }
374
+ if (63 === charCode) break;
375
+ }
376
+ return url.slice(start, i);
422
377
  };
423
- var mergePath = (...paths) => {
424
- let p = "";
425
- let endsWithSlash = false;
426
- for (let path2 of paths) {
427
- if (p[p.length - 1] === "/") {
428
- p = p.slice(0, -1);
429
- endsWithSlash = true;
430
- }
431
- if (path2[0] !== "/") {
432
- path2 = `/${path2}`;
433
- }
434
- if (path2 === "/" && endsWithSlash) {
435
- p = `${p}/`;
436
- } else if (path2 !== "/") {
437
- p = `${p}${path2}`;
438
- }
439
- if (path2 === "/" && p === "") {
440
- p = "/";
441
- }
442
- }
443
- return p;
378
+ var getPathNoStrict = (request)=>{
379
+ const result = getPath(request);
380
+ return result.length > 1 && "/" === result[result.length - 1] ? result.slice(0, -1) : result;
444
381
  };
445
- var checkOptionalParameter = (path2) => {
446
- if (!path2.match(/\:.+\?$/)) {
447
- return null;
448
- }
449
- const segments = path2.split("/");
450
- const results = [];
451
- let basePath = "";
452
- segments.forEach((segment) => {
453
- if (segment !== "" && !/\:/.test(segment)) {
454
- basePath += "/" + segment;
455
- } else if (/\:/.test(segment)) {
456
- if (/\?/.test(segment)) {
457
- if (results.length === 0 && basePath === "") {
458
- results.push("/");
459
- } else {
460
- results.push(basePath);
382
+ var mergePath = (...paths)=>{
383
+ let p = "";
384
+ let endsWithSlash = false;
385
+ for (let path of paths){
386
+ if ("/" === p[p.length - 1]) {
387
+ p = p.slice(0, -1);
388
+ endsWithSlash = true;
461
389
  }
462
- const optionalSegment = segment.replace("?", "");
463
- basePath += "/" + optionalSegment;
464
- results.push(basePath);
465
- } else {
466
- basePath += "/" + segment;
467
- }
468
- }
469
- });
470
- return results.filter((v, i, a) => a.indexOf(v) === i);
390
+ if ("/" !== path[0]) path = `/${path}`;
391
+ if ("/" === path && endsWithSlash) p = `${p}/`;
392
+ else if ("/" !== path) p = `${p}${path}`;
393
+ if ("/" === path && "" === p) p = "/";
394
+ }
395
+ return p;
471
396
  };
472
- var _decodeURI = (value) => {
473
- if (!/[%+]/.test(value)) {
474
- return value;
475
- }
476
- if (value.indexOf("+") !== -1) {
477
- value = value.replace(/\+/g, " ");
478
- }
479
- return /%/.test(value) ? decodeURIComponent_(value) : value;
397
+ var checkOptionalParameter = (path)=>{
398
+ if (!path.match(/\:.+\?$/)) return null;
399
+ const segments = path.split("/");
400
+ const results = [];
401
+ let basePath = "";
402
+ segments.forEach((segment)=>{
403
+ if ("" === segment || /\:/.test(segment)) {
404
+ if (/\:/.test(segment)) {
405
+ if (/\?/.test(segment)) {
406
+ if (0 === results.length && "" === basePath) results.push("/");
407
+ else results.push(basePath);
408
+ const optionalSegment = segment.replace("?", "");
409
+ basePath += "/" + optionalSegment;
410
+ results.push(basePath);
411
+ } else basePath += "/" + segment;
412
+ }
413
+ } else basePath += "/" + segment;
414
+ });
415
+ return results.filter((v, i, a)=>a.indexOf(v) === i);
480
416
  };
481
- var _getQueryParam = (url, key, multiple) => {
482
- let encoded;
483
- if (!multiple && key && !/[%+]/.test(key)) {
484
- let keyIndex2 = url.indexOf(`?${key}`, 8);
485
- if (keyIndex2 === -1) {
486
- keyIndex2 = url.indexOf(`&${key}`, 8);
487
- }
488
- while (keyIndex2 !== -1) {
489
- const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1);
490
- if (trailingKeyCode === 61) {
491
- const valueIndex = keyIndex2 + key.length + 2;
492
- const endIndex = url.indexOf("&", valueIndex);
493
- return _decodeURI(url.slice(valueIndex, endIndex === -1 ? void 0 : endIndex));
494
- } else if (trailingKeyCode == 38 || isNaN(trailingKeyCode)) {
495
- return "";
496
- }
497
- keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
498
- }
499
- encoded = /[%+]/.test(url);
500
- if (!encoded) {
501
- return void 0;
502
- }
503
- }
504
- const results = {};
505
- encoded ?? (encoded = /[%+]/.test(url));
506
- let keyIndex = url.indexOf("?", 8);
507
- while (keyIndex !== -1) {
508
- const nextKeyIndex = url.indexOf("&", keyIndex + 1);
509
- let valueIndex = url.indexOf("=", keyIndex);
510
- if (valueIndex > nextKeyIndex && nextKeyIndex !== -1) {
511
- valueIndex = -1;
512
- }
513
- let name = url.slice(
514
- keyIndex + 1,
515
- valueIndex === -1 ? nextKeyIndex === -1 ? void 0 : nextKeyIndex : valueIndex
516
- );
517
- if (encoded) {
518
- name = _decodeURI(name);
519
- }
520
- keyIndex = nextKeyIndex;
521
- if (name === "") {
522
- continue;
523
- }
524
- let value;
525
- if (valueIndex === -1) {
526
- value = "";
527
- } else {
528
- value = url.slice(valueIndex + 1, nextKeyIndex === -1 ? void 0 : nextKeyIndex);
529
- if (encoded) {
530
- value = _decodeURI(value);
531
- }
532
- }
533
- if (multiple) {
534
- if (!(results[name] && Array.isArray(results[name]))) {
535
- results[name] = [];
536
- }
537
- ;
538
- results[name].push(value);
539
- } else {
540
- results[name] ?? (results[name] = value);
541
- }
542
- }
543
- return key ? results[key] : results;
417
+ var _decodeURI = (value)=>{
418
+ if (!/[%+]/.test(value)) return value;
419
+ if (-1 !== value.indexOf("+")) value = value.replace(/\+/g, " ");
420
+ return /%/.test(value) ? decodeURIComponent_(value) : value;
544
421
  };
545
- var getQueryParam = _getQueryParam;
546
- var getQueryParams = (url, key) => {
547
- return _getQueryParam(url, key, true);
422
+ var _getQueryParam = (url, key, multiple)=>{
423
+ let encoded;
424
+ if (!multiple && key && !/[%+]/.test(key)) {
425
+ let keyIndex2 = url.indexOf(`?${key}`, 8);
426
+ if (-1 === keyIndex2) keyIndex2 = url.indexOf(`&${key}`, 8);
427
+ while(-1 !== keyIndex2){
428
+ const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1);
429
+ if (61 === trailingKeyCode) {
430
+ const valueIndex = keyIndex2 + key.length + 2;
431
+ const endIndex = url.indexOf("&", valueIndex);
432
+ return _decodeURI(url.slice(valueIndex, -1 === endIndex ? void 0 : endIndex));
433
+ }
434
+ if (38 == trailingKeyCode || isNaN(trailingKeyCode)) return "";
435
+ keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
436
+ }
437
+ encoded = /[%+]/.test(url);
438
+ if (!encoded) return;
439
+ }
440
+ const results = {};
441
+ encoded ??= /[%+]/.test(url);
442
+ let keyIndex = url.indexOf("?", 8);
443
+ while(-1 !== keyIndex){
444
+ const nextKeyIndex = url.indexOf("&", keyIndex + 1);
445
+ let valueIndex = url.indexOf("=", keyIndex);
446
+ if (valueIndex > nextKeyIndex && -1 !== nextKeyIndex) valueIndex = -1;
447
+ let name = url.slice(keyIndex + 1, -1 === valueIndex ? -1 === nextKeyIndex ? void 0 : nextKeyIndex : valueIndex);
448
+ if (encoded) name = _decodeURI(name);
449
+ keyIndex = nextKeyIndex;
450
+ if ("" === name) continue;
451
+ let value;
452
+ if (-1 === valueIndex) value = "";
453
+ else {
454
+ value = url.slice(valueIndex + 1, -1 === nextKeyIndex ? void 0 : nextKeyIndex);
455
+ if (encoded) value = _decodeURI(value);
456
+ }
457
+ if (multiple) {
458
+ if (!(results[name] && Array.isArray(results[name]))) results[name] = [];
459
+ results[name].push(value);
460
+ } else results[name] ??= value;
461
+ }
462
+ return key ? results[key] : results;
548
463
  };
464
+ var getQueryParam = _getQueryParam;
465
+ var getQueryParams = (url, key)=>_getQueryParam(url, key, true);
549
466
  var decodeURIComponent_ = decodeURIComponent;
550
-
551
- // ../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/request.js
552
- var _validatedData, _matchResult, _a;
553
- var HonoRequest = (_a = class {
554
- constructor(request, path2 = "/", matchResult = [[]]) {
555
- __publicField(this, "raw");
556
- __privateAdd(this, _validatedData);
557
- __privateAdd(this, _matchResult);
558
- __publicField(this, "routeIndex", 0);
559
- __publicField(this, "path");
560
- __publicField(this, "bodyCache", {});
561
- __publicField(this, "cachedBody", (key) => {
562
- const { bodyCache, raw: raw2 } = this;
563
- const cachedBody = bodyCache[key];
564
- if (cachedBody) {
565
- return cachedBody;
566
- }
567
- const anyCachedKey = Object.keys(bodyCache)[0];
568
- if (anyCachedKey) {
569
- return bodyCache[anyCachedKey].then((body) => {
570
- if (anyCachedKey === "json") {
571
- body = JSON.stringify(body);
572
- }
573
- return new Response(body)[key]();
467
+ var HonoRequest = class {
468
+ raw;
469
+ #validatedData;
470
+ #matchResult;
471
+ routeIndex = 0;
472
+ path;
473
+ bodyCache = {};
474
+ constructor(request, path = "/", matchResult = [
475
+ []
476
+ ]){
477
+ this.raw = request;
478
+ this.path = path;
479
+ this.#matchResult = matchResult;
480
+ this.#validatedData = {};
481
+ }
482
+ param(key) {
483
+ return key ? this.getDecodedParam(key) : this.getAllDecodedParams();
484
+ }
485
+ getDecodedParam(key) {
486
+ const paramKey = this.#matchResult[0][this.routeIndex][1][key];
487
+ const param = this.getParamValue(paramKey);
488
+ return param ? /\%/.test(param) ? decodeURIComponent_(param) : param : void 0;
489
+ }
490
+ getAllDecodedParams() {
491
+ const decoded = {};
492
+ const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
493
+ for (const key of keys){
494
+ const value = this.getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
495
+ if (value && "string" == typeof value) decoded[key] = /\%/.test(value) ? decodeURIComponent_(value) : value;
496
+ }
497
+ return decoded;
498
+ }
499
+ getParamValue(paramKey) {
500
+ return this.#matchResult[1] ? this.#matchResult[1][paramKey] : paramKey;
501
+ }
502
+ query(key) {
503
+ return getQueryParam(this.url, key);
504
+ }
505
+ queries(key) {
506
+ return getQueryParams(this.url, key);
507
+ }
508
+ header(name) {
509
+ if (name) return this.raw.headers.get(name.toLowerCase()) ?? void 0;
510
+ const headerData = {};
511
+ this.raw.headers.forEach((value, key)=>{
512
+ headerData[key] = value;
574
513
  });
575
- }
576
- return bodyCache[key] = raw2[key]();
577
- });
578
- this.raw = request;
579
- this.path = path2;
580
- __privateSet(this, _matchResult, matchResult);
581
- __privateSet(this, _validatedData, {});
582
- }
583
- param(key) {
584
- return key ? this.getDecodedParam(key) : this.getAllDecodedParams();
585
- }
586
- getDecodedParam(key) {
587
- const paramKey = __privateGet(this, _matchResult)[0][this.routeIndex][1][key];
588
- const param = this.getParamValue(paramKey);
589
- return param ? /\%/.test(param) ? decodeURIComponent_(param) : param : void 0;
590
- }
591
- getAllDecodedParams() {
592
- const decoded = {};
593
- const keys = Object.keys(__privateGet(this, _matchResult)[0][this.routeIndex][1]);
594
- for (const key of keys) {
595
- const value = this.getParamValue(__privateGet(this, _matchResult)[0][this.routeIndex][1][key]);
596
- if (value && typeof value === "string") {
597
- decoded[key] = /\%/.test(value) ? decodeURIComponent_(value) : value;
598
- }
599
- }
600
- return decoded;
601
- }
602
- getParamValue(paramKey) {
603
- return __privateGet(this, _matchResult)[1] ? __privateGet(this, _matchResult)[1][paramKey] : paramKey;
604
- }
605
- query(key) {
606
- return getQueryParam(this.url, key);
607
- }
608
- queries(key) {
609
- return getQueryParams(this.url, key);
610
- }
611
- header(name) {
612
- if (name) {
613
- return this.raw.headers.get(name.toLowerCase()) ?? void 0;
614
- }
615
- const headerData = {};
616
- this.raw.headers.forEach((value, key) => {
617
- headerData[key] = value;
618
- });
619
- return headerData;
620
- }
621
- async parseBody(options) {
622
- var _a4;
623
- return (_a4 = this.bodyCache).parsedBody ?? (_a4.parsedBody = await parseBody(this, options));
624
- }
625
- json() {
626
- return this.cachedBody("json");
627
- }
628
- text() {
629
- return this.cachedBody("text");
630
- }
631
- arrayBuffer() {
632
- return this.cachedBody("arrayBuffer");
633
- }
634
- blob() {
635
- return this.cachedBody("blob");
636
- }
637
- formData() {
638
- return this.cachedBody("formData");
639
- }
640
- addValidatedData(target, data) {
641
- __privateGet(this, _validatedData)[target] = data;
642
- }
643
- valid(target) {
644
- return __privateGet(this, _validatedData)[target];
645
- }
646
- get url() {
647
- return this.raw.url;
648
- }
649
- get method() {
650
- return this.raw.method;
651
- }
652
- get matchedRoutes() {
653
- return __privateGet(this, _matchResult)[0].map(([[, route]]) => route);
654
- }
655
- get routePath() {
656
- return __privateGet(this, _matchResult)[0].map(([[, route]]) => route)[this.routeIndex].path;
657
- }
658
- }, _validatedData = new WeakMap(), _matchResult = new WeakMap(), _a);
659
-
660
- // ../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/utils/html.js
514
+ return headerData;
515
+ }
516
+ async parseBody(options) {
517
+ return this.bodyCache.parsedBody ??= await parseBody(this, options);
518
+ }
519
+ cachedBody = (key)=>{
520
+ const { bodyCache, raw } = this;
521
+ const cachedBody = bodyCache[key];
522
+ if (cachedBody) return cachedBody;
523
+ const anyCachedKey = Object.keys(bodyCache)[0];
524
+ if (anyCachedKey) return bodyCache[anyCachedKey].then((body)=>{
525
+ if ("json" === anyCachedKey) body = JSON.stringify(body);
526
+ return new Response(body)[key]();
527
+ });
528
+ return bodyCache[key] = raw[key]();
529
+ };
530
+ json() {
531
+ return this.cachedBody("json");
532
+ }
533
+ text() {
534
+ return this.cachedBody("text");
535
+ }
536
+ arrayBuffer() {
537
+ return this.cachedBody("arrayBuffer");
538
+ }
539
+ blob() {
540
+ return this.cachedBody("blob");
541
+ }
542
+ formData() {
543
+ return this.cachedBody("formData");
544
+ }
545
+ addValidatedData(target, data) {
546
+ this.#validatedData[target] = data;
547
+ }
548
+ valid(target) {
549
+ return this.#validatedData[target];
550
+ }
551
+ get url() {
552
+ return this.raw.url;
553
+ }
554
+ get method() {
555
+ return this.raw.method;
556
+ }
557
+ get matchedRoutes() {
558
+ return this.#matchResult[0].map(([[, route]])=>route);
559
+ }
560
+ get routePath() {
561
+ return this.#matchResult[0].map(([[, route]])=>route)[this.routeIndex].path;
562
+ }
563
+ };
661
564
  var HtmlEscapedCallbackPhase = {
662
- Stringify: 1,
663
- BeforeStream: 2,
664
- Stream: 3
565
+ Stringify: 1,
566
+ BeforeStream: 2,
567
+ Stream: 3
665
568
  };
666
- var raw = (value, callbacks) => {
667
- const escapedString = new String(value);
668
- escapedString.isEscaped = true;
669
- escapedString.callbacks = callbacks;
670
- return escapedString;
569
+ var html_raw = (value, callbacks)=>{
570
+ const escapedString = new String(value);
571
+ escapedString.isEscaped = true;
572
+ escapedString.callbacks = callbacks;
573
+ return escapedString;
671
574
  };
672
- var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) => {
673
- if (typeof str === "object" && !(str instanceof String)) {
674
- if (!(str instanceof Promise)) {
675
- str = str.toString();
676
- }
677
- if (str instanceof Promise) {
678
- str = await str;
679
- }
680
- }
681
- const callbacks = str.callbacks;
682
- if (!callbacks?.length) {
683
- return Promise.resolve(str);
684
- }
685
- if (buffer) {
686
- buffer[0] += str;
687
- } else {
688
- buffer = [str];
689
- }
690
- const resStr = Promise.all(callbacks.map((c) => c({ phase, buffer, context }))).then(
691
- (res) => Promise.all(
692
- res.filter(Boolean).map((str2) => resolveCallback(str2, phase, false, context, buffer))
693
- ).then(() => buffer[0])
694
- );
695
- if (preserveCallbacks) {
696
- return raw(await resStr, callbacks);
697
- } else {
575
+ var resolveCallback = async (str, phase, preserveCallbacks, context, buffer)=>{
576
+ if ("object" == typeof str && !(str instanceof String)) {
577
+ if (!(str instanceof Promise)) str = str.toString();
578
+ if (str instanceof Promise) str = await str;
579
+ }
580
+ const callbacks = str.callbacks;
581
+ if (!callbacks?.length) return Promise.resolve(str);
582
+ if (buffer) buffer[0] += str;
583
+ else buffer = [
584
+ str
585
+ ];
586
+ const resStr = Promise.all(callbacks.map((c)=>c({
587
+ phase,
588
+ buffer,
589
+ context
590
+ }))).then((res)=>Promise.all(res.filter(Boolean).map((str2)=>resolveCallback(str2, phase, false, context, buffer))).then(()=>buffer[0]));
591
+ if (preserveCallbacks) return html_raw(await resStr, callbacks);
698
592
  return resStr;
699
- }
700
593
  };
701
-
702
- // ../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/context.js
703
594
  var TEXT_PLAIN = "text/plain; charset=UTF-8";
704
- var setHeaders = (headers, map = {}) => {
705
- Object.entries(map).forEach(([key, value]) => headers.set(key, value));
706
- return headers;
595
+ var setHeaders = (headers, map = {})=>{
596
+ Object.entries(map).forEach(([key, value])=>headers.set(key, value));
597
+ return headers;
707
598
  };
708
- var _rawRequest, _req, _var, _status, _executionCtx, _headers, _preparedHeaders, _res, _isFresh, _layout, _renderer, _notFoundHandler, _matchResult2, _path, _a2;
709
- var Context = (_a2 = class {
710
- constructor(req, options) {
711
- __privateAdd(this, _rawRequest);
712
- __privateAdd(this, _req);
713
- __publicField(this, "env", {});
714
- __privateAdd(this, _var);
715
- __publicField(this, "finalized", false);
716
- __publicField(this, "error");
717
- __privateAdd(this, _status, 200);
718
- __privateAdd(this, _executionCtx);
719
- __privateAdd(this, _headers);
720
- __privateAdd(this, _preparedHeaders);
721
- __privateAdd(this, _res);
722
- __privateAdd(this, _isFresh, true);
723
- __privateAdd(this, _layout);
724
- __privateAdd(this, _renderer);
725
- __privateAdd(this, _notFoundHandler);
726
- __privateAdd(this, _matchResult2);
727
- __privateAdd(this, _path);
728
- __publicField(this, "render", (...args) => {
729
- __privateGet(this, _renderer) ?? __privateSet(this, _renderer, (content) => this.html(content));
730
- return __privateGet(this, _renderer).call(this, ...args);
731
- });
732
- __publicField(this, "setLayout", (layout) => __privateSet(this, _layout, layout));
733
- __publicField(this, "getLayout", () => __privateGet(this, _layout));
734
- __publicField(this, "setRenderer", (renderer) => {
735
- __privateSet(this, _renderer, renderer);
736
- });
737
- __publicField(this, "header", (name, value, options) => {
738
- if (value === void 0) {
739
- if (__privateGet(this, _headers)) {
740
- __privateGet(this, _headers).delete(name);
741
- } else if (__privateGet(this, _preparedHeaders)) {
742
- delete __privateGet(this, _preparedHeaders)[name.toLocaleLowerCase()];
599
+ var Context = class {
600
+ #rawRequest;
601
+ #req;
602
+ env = {};
603
+ #var;
604
+ finalized = false;
605
+ error;
606
+ #status = 200;
607
+ #executionCtx;
608
+ #headers;
609
+ #preparedHeaders;
610
+ #res;
611
+ #isFresh = true;
612
+ #layout;
613
+ #renderer;
614
+ #notFoundHandler;
615
+ #matchResult;
616
+ #path;
617
+ constructor(req, options){
618
+ this.#rawRequest = req;
619
+ if (options) {
620
+ this.#executionCtx = options.executionCtx;
621
+ this.env = options.env;
622
+ this.#notFoundHandler = options.notFoundHandler;
623
+ this.#path = options.path;
624
+ this.#matchResult = options.matchResult;
743
625
  }
744
- if (this.finalized) {
745
- this.res.headers.delete(name);
746
- }
747
- return;
748
- }
749
- if (options?.append) {
750
- if (!__privateGet(this, _headers)) {
751
- __privateSet(this, _isFresh, false);
752
- __privateSet(this, _headers, new Headers(__privateGet(this, _preparedHeaders)));
753
- __privateSet(this, _preparedHeaders, {});
626
+ }
627
+ get req() {
628
+ this.#req ??= new HonoRequest(this.#rawRequest, this.#path, this.#matchResult);
629
+ return this.#req;
630
+ }
631
+ get event() {
632
+ if (this.#executionCtx && "respondWith" in this.#executionCtx) return this.#executionCtx;
633
+ throw Error("This context has no FetchEvent");
634
+ }
635
+ get executionCtx() {
636
+ if (this.#executionCtx) return this.#executionCtx;
637
+ throw Error("This context has no ExecutionContext");
638
+ }
639
+ get res() {
640
+ this.#isFresh = false;
641
+ return this.#res ||= new Response("404 Not Found", {
642
+ status: 404
643
+ });
644
+ }
645
+ set res(_res) {
646
+ this.#isFresh = false;
647
+ if (this.#res && _res) try {
648
+ for (const [k, v] of this.#res.headers.entries()){
649
+ if ("content-type" !== k) if ("set-cookie" === k) {
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
+ } catch (e) {
656
+ if (e instanceof TypeError && e.message.includes("immutable")) {
657
+ this.res = new Response(_res.body, {
658
+ headers: _res.headers,
659
+ status: _res.status
660
+ });
661
+ return;
662
+ }
663
+ throw e;
754
664
  }
755
- __privateGet(this, _headers).append(name, value);
756
- } else {
757
- if (__privateGet(this, _headers)) {
758
- __privateGet(this, _headers).set(name, value);
759
- } else {
760
- __privateGet(this, _preparedHeaders) ?? __privateSet(this, _preparedHeaders, {});
761
- __privateGet(this, _preparedHeaders)[name.toLowerCase()] = value;
665
+ this.#res = _res;
666
+ this.finalized = true;
667
+ }
668
+ render = (...args)=>{
669
+ this.#renderer ??= (content)=>this.html(content);
670
+ return this.#renderer(...args);
671
+ };
672
+ setLayout = (layout)=>this.#layout = layout;
673
+ getLayout = ()=>this.#layout;
674
+ setRenderer = (renderer)=>{
675
+ this.#renderer = renderer;
676
+ };
677
+ header = (name, value, options)=>{
678
+ if (void 0 === value) {
679
+ if (this.#headers) this.#headers.delete(name);
680
+ else if (this.#preparedHeaders) delete this.#preparedHeaders[name.toLocaleLowerCase()];
681
+ if (this.finalized) this.res.headers.delete(name);
682
+ return;
762
683
  }
763
- }
764
- if (this.finalized) {
765
684
  if (options?.append) {
766
- this.res.headers.append(name, value);
767
- } else {
768
- this.res.headers.set(name, value);
769
- }
770
- }
771
- });
772
- __publicField(this, "status", (status) => {
773
- __privateSet(this, _isFresh, false);
774
- __privateSet(this, _status, status);
775
- });
776
- __publicField(this, "set", (key, value) => {
777
- __privateGet(this, _var) ?? __privateSet(this, _var, /* @__PURE__ */ new Map());
778
- __privateGet(this, _var).set(key, value);
779
- });
780
- __publicField(this, "get", (key) => {
781
- return __privateGet(this, _var) ? __privateGet(this, _var).get(key) : void 0;
782
- });
783
- __publicField(this, "newResponse", (data, arg, headers) => {
784
- if (__privateGet(this, _isFresh) && !headers && !arg && __privateGet(this, _status) === 200) {
785
- return new Response(data, {
786
- headers: __privateGet(this, _preparedHeaders)
787
- });
788
- }
789
- if (arg && typeof arg !== "number") {
790
- const header = new Headers(arg.headers);
791
- if (__privateGet(this, _headers)) {
792
- __privateGet(this, _headers).forEach((v, k) => {
793
- if (k === "set-cookie") {
794
- header.append(k, v);
795
- } else {
796
- header.set(k, v);
685
+ if (!this.#headers) {
686
+ this.#isFresh = false;
687
+ this.#headers = new Headers(this.#preparedHeaders);
688
+ this.#preparedHeaders = {};
797
689
  }
798
- });
690
+ this.#headers.append(name, value);
691
+ } else if (this.#headers) this.#headers.set(name, value);
692
+ else {
693
+ this.#preparedHeaders ??= {};
694
+ this.#preparedHeaders[name.toLowerCase()] = value;
799
695
  }
800
- const headers2 = setHeaders(header, __privateGet(this, _preparedHeaders));
801
- return new Response(data, {
802
- headers: headers2,
803
- status: arg.status ?? __privateGet(this, _status)
804
- });
805
- }
806
- const status = typeof arg === "number" ? arg : __privateGet(this, _status);
807
- __privateGet(this, _preparedHeaders) ?? __privateSet(this, _preparedHeaders, {});
808
- __privateGet(this, _headers) ?? __privateSet(this, _headers, new Headers());
809
- setHeaders(__privateGet(this, _headers), __privateGet(this, _preparedHeaders));
810
- if (__privateGet(this, _res)) {
811
- __privateGet(this, _res).headers.forEach((v, k) => {
812
- if (k === "set-cookie") {
813
- __privateGet(this, _headers)?.append(k, v);
814
- } else {
815
- __privateGet(this, _headers)?.set(k, v);
816
- }
817
- });
818
- setHeaders(__privateGet(this, _headers), __privateGet(this, _preparedHeaders));
819
- }
820
- headers ?? (headers = {});
821
- for (const [k, v] of Object.entries(headers)) {
822
- if (typeof v === "string") {
823
- __privateGet(this, _headers).set(k, v);
824
- } else {
825
- __privateGet(this, _headers).delete(k);
826
- for (const v2 of v) {
827
- __privateGet(this, _headers).append(k, v2);
828
- }
829
- }
830
- }
831
- return new Response(data, {
832
- status,
833
- headers: __privateGet(this, _headers)
834
- });
835
- });
836
- __publicField(this, "body", (data, arg, headers) => {
837
- return typeof arg === "number" ? this.newResponse(data, arg, headers) : this.newResponse(data, arg);
838
- });
839
- __publicField(this, "text", (text, arg, headers) => {
840
- if (!__privateGet(this, _preparedHeaders)) {
841
- if (__privateGet(this, _isFresh) && !headers && !arg) {
842
- return new Response(text);
696
+ if (this.finalized) {
697
+ if (options?.append) this.res.headers.append(name, value);
698
+ else this.res.headers.set(name, value);
843
699
  }
844
- __privateSet(this, _preparedHeaders, {});
845
- }
846
- __privateGet(this, _preparedHeaders)["content-type"] = TEXT_PLAIN;
847
- return typeof arg === "number" ? this.newResponse(text, arg, headers) : this.newResponse(text, arg);
848
- });
849
- __publicField(this, "json", (object2, arg, headers) => {
850
- const body = JSON.stringify(object2);
851
- __privateGet(this, _preparedHeaders) ?? __privateSet(this, _preparedHeaders, {});
852
- __privateGet(this, _preparedHeaders)["content-type"] = "application/json; charset=UTF-8";
853
- return typeof arg === "number" ? this.newResponse(body, arg, headers) : this.newResponse(body, arg);
854
- });
855
- __publicField(this, "html", (html, arg, headers) => {
856
- __privateGet(this, _preparedHeaders) ?? __privateSet(this, _preparedHeaders, {});
857
- __privateGet(this, _preparedHeaders)["content-type"] = "text/html; charset=UTF-8";
858
- if (typeof html === "object") {
859
- return resolveCallback(html, HtmlEscapedCallbackPhase.Stringify, false, {}).then((html2) => {
860
- return typeof arg === "number" ? this.newResponse(html2, arg, headers) : this.newResponse(html2, arg);
700
+ };
701
+ status = (status)=>{
702
+ this.#isFresh = false;
703
+ this.#status = status;
704
+ };
705
+ set = (key, value)=>{
706
+ this.#var ??= /* @__PURE__ */ new Map();
707
+ this.#var.set(key, value);
708
+ };
709
+ get = (key)=>this.#var ? this.#var.get(key) : void 0;
710
+ get var() {
711
+ if (!this.#var) return {};
712
+ return Object.fromEntries(this.#var);
713
+ }
714
+ newResponse = (data, arg, headers)=>{
715
+ if (this.#isFresh && !headers && !arg && 200 === this.#status) return new Response(data, {
716
+ headers: this.#preparedHeaders
861
717
  });
862
- }
863
- return typeof arg === "number" ? this.newResponse(html, arg, headers) : this.newResponse(html, arg);
864
- });
865
- __publicField(this, "redirect", (location, status) => {
866
- __privateGet(this, _headers) ?? __privateSet(this, _headers, new Headers());
867
- __privateGet(this, _headers).set("Location", location);
868
- return this.newResponse(null, status ?? 302);
869
- });
870
- __publicField(this, "notFound", () => {
871
- __privateGet(this, _notFoundHandler) ?? __privateSet(this, _notFoundHandler, () => new Response());
872
- return __privateGet(this, _notFoundHandler).call(this, this);
873
- });
874
- __privateSet(this, _rawRequest, req);
875
- if (options) {
876
- __privateSet(this, _executionCtx, options.executionCtx);
877
- this.env = options.env;
878
- __privateSet(this, _notFoundHandler, options.notFoundHandler);
879
- __privateSet(this, _path, options.path);
880
- __privateSet(this, _matchResult2, options.matchResult);
881
- }
882
- }
883
- get req() {
884
- __privateGet(this, _req) ?? __privateSet(this, _req, new HonoRequest(__privateGet(this, _rawRequest), __privateGet(this, _path), __privateGet(this, _matchResult2)));
885
- return __privateGet(this, _req);
886
- }
887
- get event() {
888
- if (__privateGet(this, _executionCtx) && "respondWith" in __privateGet(this, _executionCtx)) {
889
- return __privateGet(this, _executionCtx);
890
- } else {
891
- throw Error("This context has no FetchEvent");
892
- }
893
- }
894
- get executionCtx() {
895
- if (__privateGet(this, _executionCtx)) {
896
- return __privateGet(this, _executionCtx);
897
- } else {
898
- throw Error("This context has no ExecutionContext");
899
- }
900
- }
901
- get res() {
902
- __privateSet(this, _isFresh, false);
903
- return __privateGet(this, _res) || __privateSet(this, _res, new Response("404 Not Found", { status: 404 }));
904
- }
905
- set res(_res2) {
906
- __privateSet(this, _isFresh, false);
907
- if (__privateGet(this, _res) && _res2) {
908
- try {
909
- for (const [k, v] of __privateGet(this, _res).headers.entries()) {
910
- if (k === "content-type") {
911
- continue;
912
- }
913
- if (k === "set-cookie") {
914
- const cookies = __privateGet(this, _res).headers.getSetCookie();
915
- _res2.headers.delete("set-cookie");
916
- for (const cookie of cookies) {
917
- _res2.headers.append("set-cookie", cookie);
918
- }
919
- } else {
920
- _res2.headers.set(k, v);
921
- }
922
- }
923
- } catch (e) {
924
- if (e instanceof TypeError && e.message.includes("immutable")) {
925
- this.res = new Response(_res2.body, {
926
- headers: _res2.headers,
927
- status: _res2.status
928
- });
929
- return;
930
- } else {
931
- throw e;
718
+ if (arg && "number" != typeof arg) {
719
+ const header = new Headers(arg.headers);
720
+ if (this.#headers) this.#headers.forEach((v, k)=>{
721
+ if ("set-cookie" === k) header.append(k, v);
722
+ else header.set(k, v);
723
+ });
724
+ const headers2 = setHeaders(header, this.#preparedHeaders);
725
+ return new Response(data, {
726
+ headers: headers2,
727
+ status: arg.status ?? this.#status
728
+ });
932
729
  }
933
- }
934
- }
935
- __privateSet(this, _res, _res2);
936
- this.finalized = true;
937
- }
938
- get var() {
939
- if (!__privateGet(this, _var)) {
940
- return {};
941
- }
942
- return Object.fromEntries(__privateGet(this, _var));
943
- }
944
- }, _rawRequest = new WeakMap(), _req = new WeakMap(), _var = new WeakMap(), _status = new WeakMap(), _executionCtx = new WeakMap(), _headers = new WeakMap(), _preparedHeaders = new WeakMap(), _res = new WeakMap(), _isFresh = new WeakMap(), _layout = new WeakMap(), _renderer = new WeakMap(), _notFoundHandler = new WeakMap(), _matchResult2 = new WeakMap(), _path = new WeakMap(), _a2);
945
-
946
- // ../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/compose.js
947
- var compose = (middleware, onError, onNotFound) => {
948
- return (context, next) => {
949
- let index = -1;
950
- return dispatch(0);
951
- async function dispatch(i) {
952
- if (i <= index) {
953
- throw new Error("next() called multiple times");
954
- }
955
- index = i;
956
- let res;
957
- let isError = false;
958
- let handler;
959
- if (middleware[i]) {
960
- handler = middleware[i][0][0];
961
- if (context instanceof Context) {
962
- context.req.routeIndex = i;
730
+ const status = "number" == typeof arg ? arg : this.#status;
731
+ this.#preparedHeaders ??= {};
732
+ this.#headers ??= new Headers();
733
+ setHeaders(this.#headers, this.#preparedHeaders);
734
+ if (this.#res) {
735
+ this.#res.headers.forEach((v, k)=>{
736
+ if ("set-cookie" === k) this.#headers?.append(k, v);
737
+ else this.#headers?.set(k, v);
738
+ });
739
+ setHeaders(this.#headers, this.#preparedHeaders);
963
740
  }
964
- } else {
965
- handler = i === middleware.length && next || void 0;
966
- }
967
- if (!handler) {
968
- if (context instanceof Context && context.finalized === false && onNotFound) {
969
- res = await onNotFound(context);
741
+ headers ??= {};
742
+ for (const [k, v] of Object.entries(headers))if ("string" == typeof v) this.#headers.set(k, v);
743
+ else {
744
+ this.#headers.delete(k);
745
+ for (const v2 of v)this.#headers.append(k, v2);
970
746
  }
971
- } else {
972
- try {
973
- res = await handler(context, () => {
974
- return dispatch(i + 1);
975
- });
976
- } catch (err) {
977
- if (err instanceof Error && context instanceof Context && onError) {
978
- context.error = err;
979
- res = await onError(err, context);
980
- isError = true;
981
- } else {
982
- throw err;
983
- }
747
+ return new Response(data, {
748
+ status,
749
+ headers: this.#headers
750
+ });
751
+ };
752
+ body = (data, arg, headers)=>"number" == typeof arg ? this.newResponse(data, arg, headers) : this.newResponse(data, arg);
753
+ text = (text, arg, headers)=>{
754
+ if (!this.#preparedHeaders) {
755
+ if (this.#isFresh && !headers && !arg) return new Response(text);
756
+ this.#preparedHeaders = {};
984
757
  }
985
- }
986
- if (res && (context.finalized === false || isError)) {
987
- context.res = res;
988
- }
989
- return context;
990
- }
991
- };
758
+ this.#preparedHeaders["content-type"] = TEXT_PLAIN;
759
+ return "number" == typeof arg ? this.newResponse(text, arg, headers) : this.newResponse(text, arg);
760
+ };
761
+ json = (object, arg, headers)=>{
762
+ const body = JSON.stringify(object);
763
+ this.#preparedHeaders ??= {};
764
+ this.#preparedHeaders["content-type"] = "application/json; charset=UTF-8";
765
+ return "number" == typeof arg ? this.newResponse(body, arg, headers) : this.newResponse(body, arg);
766
+ };
767
+ html = (html, arg, headers)=>{
768
+ this.#preparedHeaders ??= {};
769
+ this.#preparedHeaders["content-type"] = "text/html; charset=UTF-8";
770
+ if ("object" == typeof html) return resolveCallback(html, HtmlEscapedCallbackPhase.Stringify, false, {}).then((html2)=>"number" == typeof arg ? this.newResponse(html2, arg, headers) : this.newResponse(html2, arg));
771
+ return "number" == typeof arg ? this.newResponse(html, arg, headers) : this.newResponse(html, arg);
772
+ };
773
+ redirect = (location, status)=>{
774
+ this.#headers ??= new Headers();
775
+ this.#headers.set("Location", location);
776
+ return this.newResponse(null, status ?? 302);
777
+ };
778
+ notFound = ()=>{
779
+ this.#notFoundHandler ??= ()=>new Response();
780
+ return this.#notFoundHandler(this);
781
+ };
992
782
  };
993
-
994
- // ../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/router.js
783
+ var compose = (middleware, onError, onNotFound)=>(context, next)=>{
784
+ let index = -1;
785
+ return dispatch(0);
786
+ async function dispatch(i) {
787
+ if (i <= index) throw new Error("next() called multiple times");
788
+ index = i;
789
+ let res;
790
+ let isError = false;
791
+ let handler;
792
+ if (middleware[i]) {
793
+ handler = middleware[i][0][0];
794
+ if (context instanceof Context) context.req.routeIndex = i;
795
+ } else handler = i === middleware.length && next || void 0;
796
+ if (handler) try {
797
+ res = await handler(context, ()=>dispatch(i + 1));
798
+ } catch (err) {
799
+ if (err instanceof Error && context instanceof Context && onError) {
800
+ context.error = err;
801
+ res = await onError(err, context);
802
+ isError = true;
803
+ } else throw err;
804
+ }
805
+ else if (context instanceof Context && false === context.finalized && onNotFound) res = await onNotFound(context);
806
+ if (res && (false === context.finalized || isError)) context.res = res;
807
+ return context;
808
+ }
809
+ };
995
810
  var METHOD_NAME_ALL = "ALL";
996
811
  var METHOD_NAME_ALL_LOWERCASE = "all";
997
- var METHODS = ["get", "post", "put", "delete", "options", "patch"];
812
+ var METHODS = [
813
+ "get",
814
+ "post",
815
+ "put",
816
+ "delete",
817
+ "options",
818
+ "patch"
819
+ ];
998
820
  var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
999
821
  var UnsupportedPathError = class extends Error {
1000
822
  };
1001
-
1002
- // ../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/hono-base.js
1003
823
  var COMPOSED_HANDLER = Symbol("composedHandler");
1004
- var notFoundHandler = (c) => {
1005
- return c.text("404 Not Found", 404);
824
+ var notFoundHandler = (c)=>c.text("404 Not Found", 404);
825
+ var errorHandler = (err, c)=>{
826
+ if ("getResponse" in err) return err.getResponse();
827
+ console.error(err);
828
+ return c.text("Internal Server Error", 500);
1006
829
  };
1007
- var errorHandler = (err, c) => {
1008
- if ("getResponse" in err) {
1009
- return err.getResponse();
1010
- }
1011
- console.error(err);
1012
- return c.text("Internal Server Error", 500);
1013
- };
1014
- var _path2, _a3;
1015
- var Hono = (_a3 = class {
1016
- constructor(options = {}) {
1017
- __publicField(this, "get");
1018
- __publicField(this, "post");
1019
- __publicField(this, "put");
1020
- __publicField(this, "delete");
1021
- __publicField(this, "options");
1022
- __publicField(this, "patch");
1023
- __publicField(this, "all");
1024
- __publicField(this, "on");
1025
- __publicField(this, "use");
1026
- __publicField(this, "router");
1027
- __publicField(this, "getPath");
1028
- __publicField(this, "_basePath", "/");
1029
- __privateAdd(this, _path2, "/");
1030
- __publicField(this, "routes", []);
1031
- __publicField(this, "notFoundHandler", notFoundHandler);
1032
- __publicField(this, "errorHandler", errorHandler);
1033
- __publicField(this, "onError", (handler) => {
1034
- this.errorHandler = handler;
1035
- return this;
1036
- });
1037
- __publicField(this, "notFound", (handler) => {
1038
- this.notFoundHandler = handler;
1039
- return this;
1040
- });
1041
- __publicField(this, "fetch", (request, ...rest) => {
1042
- return this.dispatch(request, rest[1], rest[0], request.method);
1043
- });
1044
- __publicField(this, "request", (input, requestInit, Env, executionCtx) => {
1045
- if (input instanceof Request) {
1046
- if (requestInit !== void 0) {
1047
- input = new Request(input, requestInit);
1048
- }
1049
- return this.fetch(input, Env, executionCtx);
1050
- }
1051
- input = input.toString();
1052
- const path2 = /^https?:\/\//.test(input) ? input : `http://localhost${mergePath("/", input)}`;
1053
- const req = new Request(path2, requestInit);
1054
- return this.fetch(req, Env, executionCtx);
1055
- });
1056
- __publicField(this, "fire", () => {
1057
- addEventListener("fetch", (event) => {
1058
- event.respondWith(this.dispatch(event.request, event, void 0, event.request.method));
1059
- });
1060
- });
1061
- const allMethods = [...METHODS, METHOD_NAME_ALL_LOWERCASE];
1062
- allMethods.forEach((method) => {
1063
- this[method] = (args1, ...args) => {
1064
- if (typeof args1 === "string") {
1065
- __privateSet(this, _path2, args1);
1066
- } else {
1067
- this.addRoute(method, __privateGet(this, _path2), args1);
1068
- }
1069
- args.forEach((handler) => {
1070
- if (typeof handler !== "string") {
1071
- this.addRoute(method, __privateGet(this, _path2), handler);
1072
- }
830
+ var Hono = class {
831
+ get;
832
+ post;
833
+ put;
834
+ delete;
835
+ options;
836
+ patch;
837
+ all;
838
+ on;
839
+ use;
840
+ router;
841
+ getPath;
842
+ _basePath = "/";
843
+ #path = "/";
844
+ routes = [];
845
+ constructor(options = {}){
846
+ const allMethods = [
847
+ ...METHODS,
848
+ METHOD_NAME_ALL_LOWERCASE
849
+ ];
850
+ allMethods.forEach((method)=>{
851
+ this[method] = (args1, ...args)=>{
852
+ if ("string" == typeof args1) this.#path = args1;
853
+ else this.addRoute(method, this.#path, args1);
854
+ args.forEach((handler)=>{
855
+ if ("string" != typeof handler) this.addRoute(method, this.#path, handler);
856
+ });
857
+ return this;
858
+ };
859
+ });
860
+ this.on = (method, path, ...handlers)=>{
861
+ for (const p of [
862
+ path
863
+ ].flat()){
864
+ this.#path = p;
865
+ for (const m of [
866
+ method
867
+ ].flat())handlers.map((handler)=>{
868
+ this.addRoute(m.toUpperCase(), this.#path, handler);
869
+ });
870
+ }
871
+ return this;
872
+ };
873
+ this.use = (arg1, ...handlers)=>{
874
+ if ("string" == typeof arg1) this.#path = arg1;
875
+ else {
876
+ this.#path = "*";
877
+ handlers.unshift(arg1);
878
+ }
879
+ handlers.forEach((handler)=>{
880
+ this.addRoute(METHOD_NAME_ALL, this.#path, handler);
881
+ });
882
+ return this;
883
+ };
884
+ const strict = options.strict ?? true;
885
+ delete options.strict;
886
+ Object.assign(this, options);
887
+ this.getPath = strict ? options.getPath ?? getPath : getPathNoStrict;
888
+ }
889
+ clone() {
890
+ const clone = new Hono({
891
+ router: this.router,
892
+ getPath: this.getPath
893
+ });
894
+ clone.routes = this.routes;
895
+ return clone;
896
+ }
897
+ notFoundHandler = notFoundHandler;
898
+ errorHandler = errorHandler;
899
+ route(path, app) {
900
+ const subApp = this.basePath(path);
901
+ app.routes.map((r)=>{
902
+ let handler;
903
+ if (app.errorHandler === errorHandler) handler = r.handler;
904
+ else {
905
+ handler = async (c, next)=>(await compose([], app.errorHandler)(c, ()=>r.handler(c, next))).res;
906
+ handler[COMPOSED_HANDLER] = r.handler;
907
+ }
908
+ subApp.addRoute(r.method, r.path, handler);
1073
909
  });
1074
910
  return this;
1075
- };
1076
- });
1077
- this.on = (method, path2, ...handlers) => {
1078
- for (const p of [path2].flat()) {
1079
- __privateSet(this, _path2, p);
1080
- for (const m of [method].flat()) {
1081
- handlers.map((handler) => {
1082
- this.addRoute(m.toUpperCase(), __privateGet(this, _path2), handler);
1083
- });
1084
- }
1085
- }
1086
- return this;
1087
- };
1088
- this.use = (arg1, ...handlers) => {
1089
- if (typeof arg1 === "string") {
1090
- __privateSet(this, _path2, arg1);
1091
- } else {
1092
- __privateSet(this, _path2, "*");
1093
- handlers.unshift(arg1);
1094
- }
1095
- handlers.forEach((handler) => {
1096
- this.addRoute(METHOD_NAME_ALL, __privateGet(this, _path2), handler);
1097
- });
1098
- return this;
1099
- };
1100
- const strict = options.strict ?? true;
1101
- delete options.strict;
1102
- Object.assign(this, options);
1103
- this.getPath = strict ? options.getPath ?? getPath : getPathNoStrict;
1104
- }
1105
- clone() {
1106
- const clone = new Hono({
1107
- router: this.router,
1108
- getPath: this.getPath
1109
- });
1110
- clone.routes = this.routes;
1111
- return clone;
1112
- }
1113
- route(path2, app2) {
1114
- const subApp = this.basePath(path2);
1115
- app2.routes.map((r) => {
1116
- let handler;
1117
- if (app2.errorHandler === errorHandler) {
1118
- handler = r.handler;
1119
- } else {
1120
- handler = async (c, next) => (await compose([], app2.errorHandler)(c, () => r.handler(c, next))).res;
1121
- handler[COMPOSED_HANDLER] = r.handler;
1122
- }
1123
- subApp.addRoute(r.method, r.path, handler);
1124
- });
1125
- return this;
1126
- }
1127
- basePath(path2) {
1128
- const subApp = this.clone();
1129
- subApp._basePath = mergePath(this._basePath, path2);
1130
- return subApp;
1131
- }
1132
- mount(path2, applicationHandler, options) {
1133
- let replaceRequest;
1134
- let optionHandler;
1135
- if (options) {
1136
- if (typeof options === "function") {
1137
- optionHandler = options;
1138
- } else {
1139
- optionHandler = options.optionHandler;
1140
- replaceRequest = options.replaceRequest;
1141
- }
1142
- }
1143
- const getOptions = optionHandler ? (c) => {
1144
- const options2 = optionHandler(c);
1145
- return Array.isArray(options2) ? options2 : [options2];
1146
- } : (c) => {
1147
- let executionContext = void 0;
1148
- try {
1149
- executionContext = c.executionCtx;
1150
- } catch {
1151
- }
1152
- return [c.env, executionContext];
911
+ }
912
+ basePath(path) {
913
+ const subApp = this.clone();
914
+ subApp._basePath = mergePath(this._basePath, path);
915
+ return subApp;
916
+ }
917
+ onError = (handler)=>{
918
+ this.errorHandler = handler;
919
+ return this;
1153
920
  };
1154
- replaceRequest || (replaceRequest = (() => {
1155
- const mergedPath = mergePath(this._basePath, path2);
1156
- const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length;
1157
- return (request) => {
1158
- const url = new URL(request.url);
1159
- url.pathname = url.pathname.slice(pathPrefixLength) || "/";
1160
- return new Request(url, request);
1161
- };
1162
- })());
1163
- const handler = async (c, next) => {
1164
- const res = await applicationHandler(replaceRequest(c.req.raw), ...getOptions(c));
1165
- if (res) {
1166
- return res;
1167
- }
1168
- await next();
921
+ notFound = (handler)=>{
922
+ this.notFoundHandler = handler;
923
+ return this;
1169
924
  };
1170
- this.addRoute(METHOD_NAME_ALL, mergePath(path2, "*"), handler);
1171
- return this;
1172
- }
1173
- addRoute(method, path2, handler) {
1174
- method = method.toUpperCase();
1175
- path2 = mergePath(this._basePath, path2);
1176
- const r = { path: path2, method, handler };
1177
- this.router.add(method, path2, [handler, r]);
1178
- this.routes.push(r);
1179
- }
1180
- matchRoute(method, path2) {
1181
- return this.router.match(method, path2);
1182
- }
1183
- handleError(err, c) {
1184
- if (err instanceof Error) {
1185
- return this.errorHandler(err, c);
1186
- }
1187
- throw err;
1188
- }
1189
- dispatch(request, executionCtx, env, method) {
1190
- if (method === "HEAD") {
1191
- return (async () => new Response(null, await this.dispatch(request, executionCtx, env, "GET")))();
1192
- }
1193
- const path2 = this.getPath(request, { env });
1194
- const matchResult = this.matchRoute(method, path2);
1195
- const c = new Context(request, {
1196
- path: path2,
1197
- matchResult,
1198
- env,
1199
- executionCtx,
1200
- notFoundHandler: this.notFoundHandler
1201
- });
1202
- if (matchResult[0].length === 1) {
1203
- let res;
1204
- try {
1205
- res = matchResult[0][0][0][0](c, async () => {
1206
- c.res = await this.notFoundHandler(c);
925
+ mount(path, applicationHandler, options) {
926
+ let replaceRequest;
927
+ let optionHandler;
928
+ if (options) {
929
+ if ("function" == typeof options) optionHandler = options;
930
+ else {
931
+ optionHandler = options.optionHandler;
932
+ replaceRequest = options.replaceRequest;
933
+ }
934
+ }
935
+ const getOptions = optionHandler ? (c)=>{
936
+ const options2 = optionHandler(c);
937
+ return Array.isArray(options2) ? options2 : [
938
+ options2
939
+ ];
940
+ } : (c)=>{
941
+ let executionContext;
942
+ try {
943
+ executionContext = c.executionCtx;
944
+ } catch {}
945
+ return [
946
+ c.env,
947
+ executionContext
948
+ ];
949
+ };
950
+ replaceRequest ||= (()=>{
951
+ const mergedPath = mergePath(this._basePath, path);
952
+ const pathPrefixLength = "/" === mergedPath ? 0 : mergedPath.length;
953
+ return (request)=>{
954
+ const url = new URL(request.url);
955
+ url.pathname = url.pathname.slice(pathPrefixLength) || "/";
956
+ return new Request(url, request);
957
+ };
958
+ })();
959
+ const handler = async (c, next)=>{
960
+ const res = await applicationHandler(replaceRequest(c.req.raw), ...getOptions(c));
961
+ if (res) return res;
962
+ await next();
963
+ };
964
+ this.addRoute(METHOD_NAME_ALL, mergePath(path, "*"), handler);
965
+ return this;
966
+ }
967
+ addRoute(method, path, handler) {
968
+ method = method.toUpperCase();
969
+ path = mergePath(this._basePath, path);
970
+ const r = {
971
+ path,
972
+ method,
973
+ handler
974
+ };
975
+ this.router.add(method, path, [
976
+ handler,
977
+ r
978
+ ]);
979
+ this.routes.push(r);
980
+ }
981
+ matchRoute(method, path) {
982
+ return this.router.match(method, path);
983
+ }
984
+ handleError(err, c) {
985
+ if (err instanceof Error) return this.errorHandler(err, c);
986
+ throw err;
987
+ }
988
+ dispatch(request, executionCtx, env, method) {
989
+ if ("HEAD" === method) return (async ()=>new Response(null, await this.dispatch(request, executionCtx, env, "GET")))();
990
+ const path = this.getPath(request, {
991
+ env
992
+ });
993
+ const matchResult = this.matchRoute(method, path);
994
+ const c = new Context(request, {
995
+ path,
996
+ matchResult,
997
+ env,
998
+ executionCtx,
999
+ notFoundHandler: this.notFoundHandler
1207
1000
  });
1208
- } catch (err) {
1209
- return this.handleError(err, c);
1210
- }
1211
- return res instanceof Promise ? res.then(
1212
- (resolved) => resolved || (c.finalized ? c.res : this.notFoundHandler(c))
1213
- ).catch((err) => this.handleError(err, c)) : res ?? this.notFoundHandler(c);
1214
- }
1215
- const composed = compose(matchResult[0], this.errorHandler, this.notFoundHandler);
1216
- return (async () => {
1217
- try {
1218
- const context = await composed(c);
1219
- if (!context.finalized) {
1220
- throw new Error(
1221
- "Context is not finalized. Did you forget to return a Response object or `await next()`?"
1222
- );
1001
+ if (1 === matchResult[0].length) {
1002
+ let res;
1003
+ try {
1004
+ res = matchResult[0][0][0][0](c, async ()=>{
1005
+ c.res = await this.notFoundHandler(c);
1006
+ });
1007
+ } catch (err) {
1008
+ return this.handleError(err, c);
1009
+ }
1010
+ 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);
1223
1011
  }
1224
- return context.res;
1225
- } catch (err) {
1226
- return this.handleError(err, c);
1227
- }
1228
- })();
1229
- }
1230
- }, _path2 = new WeakMap(), _a3);
1231
-
1232
- // ../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/router/reg-exp-router/node.js
1012
+ const composed = compose(matchResult[0], this.errorHandler, this.notFoundHandler);
1013
+ return (async ()=>{
1014
+ try {
1015
+ const context = await composed(c);
1016
+ if (!context.finalized) throw new Error("Context is not finalized. Did you forget to return a Response object or `await next()`?");
1017
+ return context.res;
1018
+ } catch (err) {
1019
+ return this.handleError(err, c);
1020
+ }
1021
+ })();
1022
+ }
1023
+ fetch = (request, ...rest)=>this.dispatch(request, rest[1], rest[0], request.method);
1024
+ request = (input, requestInit, Env, executionCtx)=>{
1025
+ if (input instanceof Request) {
1026
+ if (void 0 !== requestInit) input = new Request(input, requestInit);
1027
+ return this.fetch(input, Env, executionCtx);
1028
+ }
1029
+ input = input.toString();
1030
+ const path = /^https?:\/\//.test(input) ? input : `http://localhost${mergePath("/", input)}`;
1031
+ const req = new Request(path, requestInit);
1032
+ return this.fetch(req, Env, executionCtx);
1033
+ };
1034
+ fire = ()=>{
1035
+ addEventListener("fetch", (event)=>{
1036
+ event.respondWith(this.dispatch(event.request, event, void 0, event.request.method));
1037
+ });
1038
+ };
1039
+ };
1233
1040
  var LABEL_REG_EXP_STR = "[^/]+";
1234
1041
  var ONLY_WILDCARD_REG_EXP_STR = ".*";
1235
1042
  var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
1236
1043
  var PATH_ERROR = Symbol();
1237
1044
  var regExpMetaChars = new Set(".\\+*[^]$()");
1238
1045
  function compareKey(a, b) {
1239
- if (a.length === 1) {
1240
- return b.length === 1 ? a < b ? -1 : 1 : -1;
1241
- }
1242
- if (b.length === 1) {
1243
- return 1;
1244
- }
1245
- if (a === ONLY_WILDCARD_REG_EXP_STR || a === TAIL_WILDCARD_REG_EXP_STR) {
1246
- return 1;
1247
- } else if (b === ONLY_WILDCARD_REG_EXP_STR || b === TAIL_WILDCARD_REG_EXP_STR) {
1248
- return -1;
1249
- }
1250
- if (a === LABEL_REG_EXP_STR) {
1251
- return 1;
1252
- } else if (b === LABEL_REG_EXP_STR) {
1253
- return -1;
1254
- }
1255
- return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
1046
+ if (1 === a.length) return 1 === b.length ? a < b ? -1 : 1 : -1;
1047
+ if (1 === b.length) return 1;
1048
+ if (a === ONLY_WILDCARD_REG_EXP_STR || a === TAIL_WILDCARD_REG_EXP_STR) return 1;
1049
+ if (b === ONLY_WILDCARD_REG_EXP_STR || b === TAIL_WILDCARD_REG_EXP_STR) return -1;
1050
+ if (a === LABEL_REG_EXP_STR) return 1;
1051
+ if (b === LABEL_REG_EXP_STR) return -1;
1052
+ return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
1256
1053
  }
1257
1054
  var Node = class {
1258
- constructor() {
1259
- __publicField(this, "index");
1260
- __publicField(this, "varIndex");
1261
- __publicField(this, "children", /* @__PURE__ */ Object.create(null));
1262
- }
1263
- insert(tokens, index, paramMap, context, pathErrorCheckOnly) {
1264
- if (tokens.length === 0) {
1265
- if (this.index !== void 0) {
1266
- throw PATH_ERROR;
1267
- }
1268
- if (pathErrorCheckOnly) {
1269
- return;
1270
- }
1271
- this.index = index;
1272
- return;
1273
- }
1274
- const [token, ...restTokens] = tokens;
1275
- const pattern = token === "*" ? restTokens.length === 0 ? ["", "", ONLY_WILDCARD_REG_EXP_STR] : ["", "", LABEL_REG_EXP_STR] : token === "/*" ? ["", "", TAIL_WILDCARD_REG_EXP_STR] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
1276
- let node;
1277
- if (pattern) {
1278
- const name = pattern[1];
1279
- let regexpStr = pattern[2] || LABEL_REG_EXP_STR;
1280
- if (name && pattern[2]) {
1281
- regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
1282
- if (/\((?!\?:)/.test(regexpStr)) {
1283
- throw PATH_ERROR;
1284
- }
1285
- }
1286
- node = this.children[regexpStr];
1287
- if (!node) {
1288
- if (Object.keys(this.children).some(
1289
- (k) => k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
1290
- )) {
1291
- throw PATH_ERROR;
1292
- }
1293
- if (pathErrorCheckOnly) {
1294
- return;
1295
- }
1296
- node = this.children[regexpStr] = new Node();
1297
- if (name !== "") {
1298
- node.varIndex = context.varIndex++;
1055
+ index;
1056
+ varIndex;
1057
+ children = /* @__PURE__ */ Object.create(null);
1058
+ insert(tokens, index, paramMap, context, pathErrorCheckOnly) {
1059
+ if (0 === tokens.length) {
1060
+ if (void 0 !== this.index) throw PATH_ERROR;
1061
+ if (pathErrorCheckOnly) return;
1062
+ this.index = index;
1063
+ return;
1299
1064
  }
1300
- }
1301
- if (!pathErrorCheckOnly && name !== "") {
1302
- paramMap.push([name, node.varIndex]);
1303
- }
1304
- } else {
1305
- node = this.children[token];
1306
- if (!node) {
1307
- if (Object.keys(this.children).some(
1308
- (k) => k.length > 1 && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
1309
- )) {
1310
- throw PATH_ERROR;
1311
- }
1312
- if (pathErrorCheckOnly) {
1313
- return;
1065
+ const [token, ...restTokens] = tokens;
1066
+ const pattern = "*" === token ? 0 === restTokens.length ? [
1067
+ "",
1068
+ "",
1069
+ ONLY_WILDCARD_REG_EXP_STR
1070
+ ] : [
1071
+ "",
1072
+ "",
1073
+ LABEL_REG_EXP_STR
1074
+ ] : "/*" === token ? [
1075
+ "",
1076
+ "",
1077
+ TAIL_WILDCARD_REG_EXP_STR
1078
+ ] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
1079
+ let node;
1080
+ if (pattern) {
1081
+ const name = pattern[1];
1082
+ let regexpStr = pattern[2] || LABEL_REG_EXP_STR;
1083
+ if (name && pattern[2]) {
1084
+ regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
1085
+ if (/\((?!\?:)/.test(regexpStr)) throw PATH_ERROR;
1086
+ }
1087
+ node = this.children[regexpStr];
1088
+ if (!node) {
1089
+ if (Object.keys(this.children).some((k)=>k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR)) throw PATH_ERROR;
1090
+ if (pathErrorCheckOnly) return;
1091
+ node = this.children[regexpStr] = new Node();
1092
+ if ("" !== name) node.varIndex = context.varIndex++;
1093
+ }
1094
+ if (!pathErrorCheckOnly && "" !== name) paramMap.push([
1095
+ name,
1096
+ node.varIndex
1097
+ ]);
1098
+ } else {
1099
+ node = this.children[token];
1100
+ if (!node) {
1101
+ 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;
1102
+ if (pathErrorCheckOnly) return;
1103
+ node = this.children[token] = new Node();
1104
+ }
1314
1105
  }
1315
- node = this.children[token] = new Node();
1316
- }
1317
- }
1318
- node.insert(restTokens, index, paramMap, context, pathErrorCheckOnly);
1319
- }
1320
- buildRegExpStr() {
1321
- const childKeys = Object.keys(this.children).sort(compareKey);
1322
- const strList = childKeys.map((k) => {
1323
- const c = this.children[k];
1324
- return (typeof c.varIndex === "number" ? `(${k})@${c.varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr();
1325
- });
1326
- if (typeof this.index === "number") {
1327
- strList.unshift(`#${this.index}`);
1328
- }
1329
- if (strList.length === 0) {
1330
- return "";
1106
+ node.insert(restTokens, index, paramMap, context, pathErrorCheckOnly);
1331
1107
  }
1332
- if (strList.length === 1) {
1333
- return strList[0];
1108
+ buildRegExpStr() {
1109
+ const childKeys = Object.keys(this.children).sort(compareKey);
1110
+ const strList = childKeys.map((k)=>{
1111
+ const c = this.children[k];
1112
+ return ("number" == typeof c.varIndex ? `(${k})@${c.varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr();
1113
+ });
1114
+ if ("number" == typeof this.index) strList.unshift(`#${this.index}`);
1115
+ if (0 === strList.length) return "";
1116
+ if (1 === strList.length) return strList[0];
1117
+ return "(?:" + strList.join("|") + ")";
1334
1118
  }
1335
- return "(?:" + strList.join("|") + ")";
1336
- }
1337
1119
  };
1338
-
1339
- // ../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/router/reg-exp-router/trie.js
1340
1120
  var Trie = class {
1341
- constructor() {
1342
- __publicField(this, "context", { varIndex: 0 });
1343
- __publicField(this, "root", new Node());
1344
- }
1345
- insert(path2, index, pathErrorCheckOnly) {
1346
- const paramAssoc = [];
1347
- const groups = [];
1348
- for (let i = 0; ; ) {
1349
- let replaced = false;
1350
- path2 = path2.replace(/\{[^}]+\}/g, (m) => {
1351
- const mark = `@\\${i}`;
1352
- groups[i] = [mark, m];
1353
- i++;
1354
- replaced = true;
1355
- return mark;
1356
- });
1357
- if (!replaced) {
1358
- break;
1359
- }
1360
- }
1361
- const tokens = path2.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
1362
- for (let i = groups.length - 1; i >= 0; i--) {
1363
- const [mark] = groups[i];
1364
- for (let j = tokens.length - 1; j >= 0; j--) {
1365
- if (tokens[j].indexOf(mark) !== -1) {
1366
- tokens[j] = tokens[j].replace(mark, groups[i][1]);
1367
- break;
1121
+ context = {
1122
+ varIndex: 0
1123
+ };
1124
+ root = new Node();
1125
+ insert(path, index, pathErrorCheckOnly) {
1126
+ const paramAssoc = [];
1127
+ const groups = [];
1128
+ for(let i = 0;;){
1129
+ let replaced = false;
1130
+ path = path.replace(/\{[^}]+\}/g, (m)=>{
1131
+ const mark = `@\\${i}`;
1132
+ groups[i] = [
1133
+ mark,
1134
+ m
1135
+ ];
1136
+ i++;
1137
+ replaced = true;
1138
+ return mark;
1139
+ });
1140
+ if (!replaced) break;
1368
1141
  }
1369
- }
1370
- }
1371
- this.root.insert(tokens, index, paramAssoc, this.context, pathErrorCheckOnly);
1372
- return paramAssoc;
1373
- }
1374
- buildRegExp() {
1375
- let regexp = this.root.buildRegExpStr();
1376
- if (regexp === "") {
1377
- return [/^$/, [], []];
1378
- }
1379
- let captureIndex = 0;
1380
- const indexReplacementMap = [];
1381
- const paramReplacementMap = [];
1382
- regexp = regexp.replace(/#(\d+)|@(\d+)|\.\*\$/g, (_, handlerIndex, paramIndex) => {
1383
- if (typeof handlerIndex !== "undefined") {
1384
- indexReplacementMap[++captureIndex] = Number(handlerIndex);
1385
- return "$()";
1386
- }
1387
- if (typeof paramIndex !== "undefined") {
1388
- paramReplacementMap[Number(paramIndex)] = ++captureIndex;
1389
- return "";
1390
- }
1391
- return "";
1392
- });
1393
- return [new RegExp(`^${regexp}`), indexReplacementMap, paramReplacementMap];
1394
- }
1142
+ const tokens = path.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
1143
+ for(let i = groups.length - 1; i >= 0; i--){
1144
+ const [mark] = groups[i];
1145
+ for(let j = tokens.length - 1; j >= 0; j--)if (-1 !== tokens[j].indexOf(mark)) {
1146
+ tokens[j] = tokens[j].replace(mark, groups[i][1]);
1147
+ break;
1148
+ }
1149
+ }
1150
+ this.root.insert(tokens, index, paramAssoc, this.context, pathErrorCheckOnly);
1151
+ return paramAssoc;
1152
+ }
1153
+ buildRegExp() {
1154
+ let regexp = this.root.buildRegExpStr();
1155
+ if ("" === regexp) return [
1156
+ /^$/,
1157
+ [],
1158
+ []
1159
+ ];
1160
+ let captureIndex = 0;
1161
+ const indexReplacementMap = [];
1162
+ const paramReplacementMap = [];
1163
+ regexp = regexp.replace(/#(\d+)|@(\d+)|\.\*\$/g, (_, handlerIndex, paramIndex)=>{
1164
+ if (void 0 !== handlerIndex) {
1165
+ indexReplacementMap[++captureIndex] = Number(handlerIndex);
1166
+ return "$()";
1167
+ }
1168
+ if (void 0 !== paramIndex) paramReplacementMap[Number(paramIndex)] = ++captureIndex;
1169
+ return "";
1170
+ });
1171
+ return [
1172
+ new RegExp(`^${regexp}`),
1173
+ indexReplacementMap,
1174
+ paramReplacementMap
1175
+ ];
1176
+ }
1395
1177
  };
1396
-
1397
- // ../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/router/reg-exp-router/router.js
1398
1178
  var emptyParam = [];
1399
- var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
1179
+ var nullMatcher = [
1180
+ /^$/,
1181
+ [],
1182
+ /* @__PURE__ */ Object.create(null)
1183
+ ];
1400
1184
  var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
1401
- function buildWildcardRegExp(path2) {
1402
- return wildcardRegExpCache[path2] ?? (wildcardRegExpCache[path2] = new RegExp(
1403
- path2 === "*" ? "" : `^${path2.replace(
1404
- /\/\*$|([.\\+*[^\]$()])/g,
1405
- (_, metaChar) => metaChar ? `\\${metaChar}` : "(?:|/.*)"
1406
- )}$`
1407
- ));
1185
+ function buildWildcardRegExp(path) {
1186
+ return wildcardRegExpCache[path] ??= new RegExp("*" === path ? "" : `^${path.replace(/\/\*$|([.\\+*[^\]$()])/g, (_, metaChar)=>metaChar ? `\\${metaChar}` : "(?:|/.*)")}$`);
1408
1187
  }
1409
1188
  function clearWildcardRegExpCache() {
1410
- wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
1189
+ wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
1411
1190
  }
1412
1191
  function buildMatcherFromPreprocessedRoutes(routes) {
1413
- const trie = new Trie();
1414
- const handlerData = [];
1415
- if (routes.length === 0) {
1416
- return nullMatcher;
1417
- }
1418
- const routesWithStaticPathFlag = routes.map(
1419
- (route) => [!/\*|\/:/.test(route[0]), ...route]
1420
- ).sort(
1421
- ([isStaticA, pathA], [isStaticB, pathB]) => isStaticA ? 1 : isStaticB ? -1 : pathA.length - pathB.length
1422
- );
1423
- const staticMap = /* @__PURE__ */ Object.create(null);
1424
- for (let i = 0, j = -1, len = routesWithStaticPathFlag.length; i < len; i++) {
1425
- const [pathErrorCheckOnly, path2, handlers] = routesWithStaticPathFlag[i];
1426
- if (pathErrorCheckOnly) {
1427
- staticMap[path2] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
1428
- } else {
1429
- j++;
1430
- }
1431
- let paramAssoc;
1432
- try {
1433
- paramAssoc = trie.insert(path2, j, pathErrorCheckOnly);
1434
- } catch (e) {
1435
- throw e === PATH_ERROR ? new UnsupportedPathError(path2) : e;
1436
- }
1437
- if (pathErrorCheckOnly) {
1438
- continue;
1439
- }
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++) {
1452
- for (let j = 0, len2 = handlerData[i].length; j < len2; j++) {
1453
- const map = handlerData[i][j]?.[1];
1454
- if (!map) {
1455
- continue;
1456
- }
1457
- const keys = Object.keys(map);
1458
- for (let k = 0, len3 = keys.length; k < len3; k++) {
1459
- map[keys[k]] = paramReplacementMap[map[keys[k]]];
1460
- }
1461
- }
1462
- }
1463
- const handlerMap = [];
1464
- for (const i in indexReplacementMap) {
1465
- handlerMap[i] = handlerData[indexReplacementMap[i]];
1466
- }
1467
- return [regexp, handlerMap, staticMap];
1192
+ const trie = new Trie();
1193
+ const handlerData = [];
1194
+ if (0 === routes.length) return nullMatcher;
1195
+ const routesWithStaticPathFlag = routes.map((route)=>[
1196
+ !/\*|\/:/.test(route[0]),
1197
+ ...route
1198
+ ]).sort(([isStaticA, pathA], [isStaticB, pathB])=>isStaticA ? 1 : isStaticB ? -1 : pathA.length - pathB.length);
1199
+ const staticMap = /* @__PURE__ */ Object.create(null);
1200
+ for(let i = 0, j = -1, len = routesWithStaticPathFlag.length; i < len; i++){
1201
+ const [pathErrorCheckOnly, path, handlers] = routesWithStaticPathFlag[i];
1202
+ if (pathErrorCheckOnly) staticMap[path] = [
1203
+ handlers.map(([h])=>[
1204
+ h,
1205
+ /* @__PURE__ */ Object.create(null)
1206
+ ]),
1207
+ emptyParam
1208
+ ];
1209
+ else j++;
1210
+ let paramAssoc;
1211
+ try {
1212
+ paramAssoc = trie.insert(path, j, pathErrorCheckOnly);
1213
+ } catch (e) {
1214
+ throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
1215
+ }
1216
+ if (!pathErrorCheckOnly) handlerData[j] = handlers.map(([h, paramCount])=>{
1217
+ const paramIndexMap = /* @__PURE__ */ Object.create(null);
1218
+ paramCount -= 1;
1219
+ for(; paramCount >= 0; paramCount--){
1220
+ const [key, value] = paramAssoc[paramCount];
1221
+ paramIndexMap[key] = value;
1222
+ }
1223
+ return [
1224
+ h,
1225
+ paramIndexMap
1226
+ ];
1227
+ });
1228
+ }
1229
+ const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
1230
+ for(let i = 0, len = handlerData.length; i < len; i++)for(let j = 0, len2 = handlerData[i].length; j < len2; j++){
1231
+ const map = handlerData[i][j]?.[1];
1232
+ if (!map) continue;
1233
+ const keys = Object.keys(map);
1234
+ for(let k = 0, len3 = keys.length; k < len3; k++)map[keys[k]] = paramReplacementMap[map[keys[k]]];
1235
+ }
1236
+ const handlerMap = [];
1237
+ for(const i in indexReplacementMap)handlerMap[i] = handlerData[indexReplacementMap[i]];
1238
+ return [
1239
+ regexp,
1240
+ handlerMap,
1241
+ staticMap
1242
+ ];
1468
1243
  }
1469
- function findMiddleware(middleware, path2) {
1470
- if (!middleware) {
1471
- return void 0;
1472
- }
1473
- for (const k of Object.keys(middleware).sort((a, b) => b.length - a.length)) {
1474
- if (buildWildcardRegExp(k).test(path2)) {
1475
- return [...middleware[k]];
1476
- }
1477
- }
1478
- return void 0;
1244
+ function findMiddleware(middleware, path) {
1245
+ if (!middleware) return;
1246
+ for (const k of Object.keys(middleware).sort((a, b)=>b.length - a.length))if (buildWildcardRegExp(k).test(path)) return [
1247
+ ...middleware[k]
1248
+ ];
1479
1249
  }
1480
1250
  var RegExpRouter = class {
1481
- constructor() {
1482
- __publicField(this, "name", "RegExpRouter");
1483
- __publicField(this, "middleware");
1484
- __publicField(this, "routes");
1485
- this.middleware = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
1486
- this.routes = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
1487
- }
1488
- add(method, path2, handler) {
1489
- var _a4;
1490
- const { middleware, routes } = this;
1491
- if (!middleware || !routes) {
1492
- throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
1493
- }
1494
- if (!middleware[method]) {
1495
- ;
1496
- [middleware, routes].forEach((handlerMap) => {
1497
- handlerMap[method] = /* @__PURE__ */ Object.create(null);
1498
- Object.keys(handlerMap[METHOD_NAME_ALL]).forEach((p) => {
1499
- handlerMap[method][p] = [...handlerMap[METHOD_NAME_ALL][p]];
1251
+ name = "RegExpRouter";
1252
+ middleware;
1253
+ routes;
1254
+ constructor(){
1255
+ this.middleware = {
1256
+ [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null)
1257
+ };
1258
+ this.routes = {
1259
+ [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null)
1260
+ };
1261
+ }
1262
+ add(method, path, handler) {
1263
+ const { middleware, routes } = this;
1264
+ if (!middleware || !routes) throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
1265
+ if (!middleware[method]) [
1266
+ middleware,
1267
+ routes
1268
+ ].forEach((handlerMap)=>{
1269
+ handlerMap[method] = /* @__PURE__ */ Object.create(null);
1270
+ Object.keys(handlerMap[METHOD_NAME_ALL]).forEach((p)=>{
1271
+ handlerMap[method][p] = [
1272
+ ...handlerMap[METHOD_NAME_ALL][p]
1273
+ ];
1274
+ });
1500
1275
  });
1501
- });
1502
- }
1503
- if (path2 === "/*") {
1504
- path2 = "*";
1505
- }
1506
- const paramCount = (path2.match(/\/:/g) || []).length;
1507
- if (/\*$/.test(path2)) {
1508
- const re = buildWildcardRegExp(path2);
1509
- if (method === METHOD_NAME_ALL) {
1510
- Object.keys(middleware).forEach((m) => {
1511
- var _a5;
1512
- (_a5 = middleware[m])[path2] || (_a5[path2] = findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || []);
1513
- });
1514
- } else {
1515
- (_a4 = middleware[method])[path2] || (_a4[path2] = findMiddleware(middleware[method], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || []);
1516
- }
1517
- Object.keys(middleware).forEach((m) => {
1518
- if (method === METHOD_NAME_ALL || method === m) {
1519
- Object.keys(middleware[m]).forEach((p) => {
1520
- re.test(p) && middleware[m][p].push([handler, paramCount]);
1521
- });
1522
- }
1523
- });
1524
- Object.keys(routes).forEach((m) => {
1525
- if (method === METHOD_NAME_ALL || method === m) {
1526
- Object.keys(routes[m]).forEach(
1527
- (p) => re.test(p) && routes[m][p].push([handler, paramCount])
1528
- );
1276
+ if ("/*" === path) path = "*";
1277
+ const paramCount = (path.match(/\/:/g) || []).length;
1278
+ if (/\*$/.test(path)) {
1279
+ const re = buildWildcardRegExp(path);
1280
+ if (method === METHOD_NAME_ALL) Object.keys(middleware).forEach((m)=>{
1281
+ middleware[m][path] ||= findMiddleware(middleware[m], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
1282
+ });
1283
+ else middleware[method][path] ||= findMiddleware(middleware[method], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
1284
+ Object.keys(middleware).forEach((m)=>{
1285
+ if (method === METHOD_NAME_ALL || method === m) Object.keys(middleware[m]).forEach((p)=>{
1286
+ re.test(p) && middleware[m][p].push([
1287
+ handler,
1288
+ paramCount
1289
+ ]);
1290
+ });
1291
+ });
1292
+ Object.keys(routes).forEach((m)=>{
1293
+ if (method === METHOD_NAME_ALL || method === m) Object.keys(routes[m]).forEach((p)=>re.test(p) && routes[m][p].push([
1294
+ handler,
1295
+ paramCount
1296
+ ]));
1297
+ });
1298
+ return;
1529
1299
  }
1530
- });
1531
- return;
1532
- }
1533
- const paths = checkOptionalParameter(path2) || [path2];
1534
- for (let i = 0, len = paths.length; i < len; i++) {
1535
- const path22 = paths[i];
1536
- Object.keys(routes).forEach((m) => {
1537
- var _a5;
1538
- if (method === METHOD_NAME_ALL || method === m) {
1539
- (_a5 = routes[m])[path22] || (_a5[path22] = [
1540
- ...findMiddleware(middleware[m], path22) || findMiddleware(middleware[METHOD_NAME_ALL], path22) || []
1541
- ]);
1542
- routes[m][path22].push([handler, paramCount - len + i + 1]);
1300
+ const paths = checkOptionalParameter(path) || [
1301
+ path
1302
+ ];
1303
+ for(let i = 0, len = paths.length; i < len; i++){
1304
+ const path2 = paths[i];
1305
+ Object.keys(routes).forEach((m)=>{
1306
+ if (method === METHOD_NAME_ALL || method === m) {
1307
+ routes[m][path2] ||= [
1308
+ ...findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || []
1309
+ ];
1310
+ routes[m][path2].push([
1311
+ handler,
1312
+ paramCount - len + i + 1
1313
+ ]);
1314
+ }
1315
+ });
1543
1316
  }
1544
- });
1545
- }
1546
- }
1547
- match(method, path2) {
1548
- clearWildcardRegExpCache();
1549
- const matchers = this.buildAllMatchers();
1550
- this.match = (method2, path22) => {
1551
- const matcher = matchers[method2] || matchers[METHOD_NAME_ALL];
1552
- const staticMatch = matcher[2][path22];
1553
- if (staticMatch) {
1554
- return staticMatch;
1555
- }
1556
- const match = path22.match(matcher[0]);
1557
- if (!match) {
1558
- return [[], emptyParam];
1559
- }
1560
- const index = match.indexOf("", 1);
1561
- return [matcher[1][index], match];
1562
- };
1563
- return this.match(method, path2);
1564
- }
1565
- buildAllMatchers() {
1566
- const matchers = /* @__PURE__ */ Object.create(null);
1567
- [...Object.keys(this.routes), ...Object.keys(this.middleware)].forEach((method) => {
1568
- matchers[method] || (matchers[method] = this.buildMatcher(method));
1569
- });
1570
- this.middleware = this.routes = void 0;
1571
- return matchers;
1572
- }
1573
- buildMatcher(method) {
1574
- const routes = [];
1575
- let hasOwnRoute = method === METHOD_NAME_ALL;
1576
- [this.middleware, this.routes].forEach((r) => {
1577
- const ownRoute = r[method] ? Object.keys(r[method]).map((path2) => [path2, r[method][path2]]) : [];
1578
- if (ownRoute.length !== 0) {
1579
- hasOwnRoute || (hasOwnRoute = true);
1580
- routes.push(...ownRoute);
1581
- } else if (method !== METHOD_NAME_ALL) {
1582
- routes.push(
1583
- ...Object.keys(r[METHOD_NAME_ALL]).map((path2) => [path2, r[METHOD_NAME_ALL][path2]])
1584
- );
1585
- }
1586
- });
1587
- if (!hasOwnRoute) {
1588
- return null;
1589
- } else {
1590
- return buildMatcherFromPreprocessedRoutes(routes);
1591
1317
  }
1592
- }
1318
+ match(method, path) {
1319
+ clearWildcardRegExpCache();
1320
+ const matchers = this.buildAllMatchers();
1321
+ this.match = (method2, path2)=>{
1322
+ const matcher = matchers[method2] || matchers[METHOD_NAME_ALL];
1323
+ const staticMatch = matcher[2][path2];
1324
+ if (staticMatch) return staticMatch;
1325
+ const match = path2.match(matcher[0]);
1326
+ if (!match) return [
1327
+ [],
1328
+ emptyParam
1329
+ ];
1330
+ const index = match.indexOf("", 1);
1331
+ return [
1332
+ matcher[1][index],
1333
+ match
1334
+ ];
1335
+ };
1336
+ return this.match(method, path);
1337
+ }
1338
+ buildAllMatchers() {
1339
+ const matchers = /* @__PURE__ */ Object.create(null);
1340
+ [
1341
+ ...Object.keys(this.routes),
1342
+ ...Object.keys(this.middleware)
1343
+ ].forEach((method)=>{
1344
+ matchers[method] ||= this.buildMatcher(method);
1345
+ });
1346
+ this.middleware = this.routes = void 0;
1347
+ return matchers;
1348
+ }
1349
+ buildMatcher(method) {
1350
+ const routes = [];
1351
+ let hasOwnRoute = method === METHOD_NAME_ALL;
1352
+ [
1353
+ this.middleware,
1354
+ this.routes
1355
+ ].forEach((r)=>{
1356
+ const ownRoute = r[method] ? Object.keys(r[method]).map((path)=>[
1357
+ path,
1358
+ r[method][path]
1359
+ ]) : [];
1360
+ if (0 !== ownRoute.length) {
1361
+ hasOwnRoute ||= true;
1362
+ routes.push(...ownRoute);
1363
+ } else if (method !== METHOD_NAME_ALL) routes.push(...Object.keys(r[METHOD_NAME_ALL]).map((path)=>[
1364
+ path,
1365
+ r[METHOD_NAME_ALL][path]
1366
+ ]));
1367
+ });
1368
+ if (!hasOwnRoute) return null;
1369
+ return buildMatcherFromPreprocessedRoutes(routes);
1370
+ }
1593
1371
  };
1594
-
1595
- // ../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/router/smart-router/router.js
1596
1372
  var SmartRouter = class {
1597
- constructor(init) {
1598
- __publicField(this, "name", "SmartRouter");
1599
- __publicField(this, "routers", []);
1600
- __publicField(this, "routes", []);
1601
- Object.assign(this, init);
1602
- }
1603
- add(method, path2, handler) {
1604
- if (!this.routes) {
1605
- throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
1606
- }
1607
- this.routes.push([method, path2, handler]);
1608
- }
1609
- match(method, path2) {
1610
- if (!this.routes) {
1611
- throw new Error("Fatal error");
1612
- }
1613
- const { routers, routes } = this;
1614
- const len = routers.length;
1615
- let i = 0;
1616
- let res;
1617
- for (; i < len; i++) {
1618
- const router = routers[i];
1619
- try {
1620
- routes.forEach((args) => {
1621
- router.add(...args);
1622
- });
1623
- res = router.match(method, path2);
1624
- } catch (e) {
1625
- if (e instanceof UnsupportedPathError) {
1626
- continue;
1373
+ name = "SmartRouter";
1374
+ routers = [];
1375
+ routes = [];
1376
+ constructor(init){
1377
+ Object.assign(this, init);
1378
+ }
1379
+ add(method, path, handler) {
1380
+ if (!this.routes) throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
1381
+ this.routes.push([
1382
+ method,
1383
+ path,
1384
+ handler
1385
+ ]);
1386
+ }
1387
+ match(method, path) {
1388
+ if (!this.routes) throw new Error("Fatal error");
1389
+ const { routers, routes } = this;
1390
+ const len = routers.length;
1391
+ let i = 0;
1392
+ let res;
1393
+ for(; i < len; i++){
1394
+ const router = routers[i];
1395
+ try {
1396
+ routes.forEach((args)=>{
1397
+ router.add(...args);
1398
+ });
1399
+ res = router.match(method, path);
1400
+ } catch (e) {
1401
+ if (e instanceof UnsupportedPathError) continue;
1402
+ throw e;
1403
+ }
1404
+ this.match = router.match.bind(router);
1405
+ this.routers = [
1406
+ router
1407
+ ];
1408
+ this.routes = void 0;
1409
+ break;
1627
1410
  }
1628
- throw e;
1629
- }
1630
- this.match = router.match.bind(router);
1631
- this.routers = [router];
1632
- this.routes = void 0;
1633
- break;
1634
- }
1635
- if (i === len) {
1636
- throw new Error("Fatal error");
1637
- }
1638
- this.name = `SmartRouter + ${this.activeRouter.name}`;
1639
- return res;
1640
- }
1641
- get activeRouter() {
1642
- if (this.routes || this.routers.length !== 1) {
1643
- throw new Error("No active router has been determined yet.");
1644
- }
1645
- return this.routers[0];
1646
- }
1411
+ if (i === len) throw new Error("Fatal error");
1412
+ this.name = `SmartRouter + ${this.activeRouter.name}`;
1413
+ return res;
1414
+ }
1415
+ get activeRouter() {
1416
+ if (this.routes || 1 !== this.routers.length) throw new Error("No active router has been determined yet.");
1417
+ return this.routers[0];
1418
+ }
1647
1419
  };
1648
-
1649
- // ../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/router/trie-router/node.js
1650
- var Node2 = class {
1651
- constructor(method, handler, children) {
1652
- __publicField(this, "methods");
1653
- __publicField(this, "children");
1654
- __publicField(this, "patterns");
1655
- __publicField(this, "order", 0);
1656
- __publicField(this, "name");
1657
- __publicField(this, "params", /* @__PURE__ */ Object.create(null));
1658
- this.children = children || /* @__PURE__ */ Object.create(null);
1659
- this.methods = [];
1660
- this.name = "";
1661
- if (method && handler) {
1662
- const m = /* @__PURE__ */ Object.create(null);
1663
- m[method] = { handler, possibleKeys: [], score: 0, name: this.name };
1664
- this.methods = [m];
1665
- }
1666
- this.patterns = [];
1667
- }
1668
- insert(method, path2, handler) {
1669
- this.name = `${method} ${path2}`;
1670
- this.order = ++this.order;
1671
- let curNode = this;
1672
- const parts = splitRoutingPath(path2);
1673
- const possibleKeys = [];
1674
- for (let i = 0, len = parts.length; i < len; i++) {
1675
- const p = parts[i];
1676
- if (Object.keys(curNode.children).includes(p)) {
1677
- curNode = curNode.children[p];
1678
- const pattern2 = getPattern(p);
1679
- if (pattern2) {
1680
- possibleKeys.push(pattern2[1]);
1420
+ var node_Node = class {
1421
+ methods;
1422
+ children;
1423
+ patterns;
1424
+ order = 0;
1425
+ name;
1426
+ params = /* @__PURE__ */ Object.create(null);
1427
+ constructor(method, handler, children){
1428
+ this.children = children || /* @__PURE__ */ Object.create(null);
1429
+ this.methods = [];
1430
+ this.name = "";
1431
+ if (method && handler) {
1432
+ const m = /* @__PURE__ */ Object.create(null);
1433
+ m[method] = {
1434
+ handler,
1435
+ possibleKeys: [],
1436
+ score: 0,
1437
+ name: this.name
1438
+ };
1439
+ this.methods = [
1440
+ m
1441
+ ];
1681
1442
  }
1682
- continue;
1683
- }
1684
- curNode.children[p] = new Node2();
1685
- const pattern = getPattern(p);
1686
- if (pattern) {
1687
- curNode.patterns.push(pattern);
1688
- possibleKeys.push(pattern[1]);
1689
- }
1690
- curNode = curNode.children[p];
1691
- }
1692
- if (!curNode.methods.length) {
1693
- curNode.methods = [];
1694
- }
1695
- const m = /* @__PURE__ */ Object.create(null);
1696
- const handlerSet = {
1697
- handler,
1698
- possibleKeys: possibleKeys.filter((v, i, a) => a.indexOf(v) === i),
1699
- name: this.name,
1700
- score: this.order
1701
- };
1702
- m[method] = handlerSet;
1703
- curNode.methods.push(m);
1704
- return curNode;
1705
- }
1706
- gHSets(node, method, nodeParams, params) {
1707
- const handlerSets = [];
1708
- for (let i = 0, len = node.methods.length; i < len; i++) {
1709
- const m = node.methods[i];
1710
- const handlerSet = m[method] || m[METHOD_NAME_ALL];
1711
- const processedSet = /* @__PURE__ */ Object.create(null);
1712
- if (handlerSet !== void 0) {
1713
- handlerSet.params = /* @__PURE__ */ Object.create(null);
1714
- handlerSet.possibleKeys.forEach((key) => {
1715
- const processed = processedSet[handlerSet.name];
1716
- handlerSet.params[key] = params[key] && !processed ? params[key] : nodeParams[key] ?? params[key];
1717
- processedSet[handlerSet.name] = true;
1718
- });
1719
- handlerSets.push(handlerSet);
1720
- }
1721
- }
1722
- return handlerSets;
1723
- }
1724
- search(method, path2) {
1725
- const handlerSets = [];
1726
- this.params = /* @__PURE__ */ Object.create(null);
1727
- const curNode = this;
1728
- let curNodes = [curNode];
1729
- const parts = splitPath(path2);
1730
- for (let i = 0, len = parts.length; i < len; i++) {
1731
- const part = parts[i];
1732
- const isLast = i === len - 1;
1733
- const tempNodes = [];
1734
- for (let j = 0, len2 = curNodes.length; j < len2; j++) {
1735
- const node = curNodes[j];
1736
- const nextNode = node.children[part];
1737
- if (nextNode) {
1738
- nextNode.params = node.params;
1739
- if (isLast === true) {
1740
- if (nextNode.children["*"]) {
1741
- handlerSets.push(
1742
- ...this.gHSets(nextNode.children["*"], method, node.params, /* @__PURE__ */ Object.create(null))
1743
- );
1443
+ this.patterns = [];
1444
+ }
1445
+ insert(method, path, handler) {
1446
+ this.name = `${method} ${path}`;
1447
+ this.order = ++this.order;
1448
+ let curNode = this;
1449
+ const parts = splitRoutingPath(path);
1450
+ const possibleKeys = [];
1451
+ for(let i = 0, len = parts.length; i < len; i++){
1452
+ const p = parts[i];
1453
+ if (Object.keys(curNode.children).includes(p)) {
1454
+ curNode = curNode.children[p];
1455
+ const pattern2 = getPattern(p);
1456
+ if (pattern2) possibleKeys.push(pattern2[1]);
1457
+ continue;
1458
+ }
1459
+ curNode.children[p] = new node_Node();
1460
+ const pattern = getPattern(p);
1461
+ if (pattern) {
1462
+ curNode.patterns.push(pattern);
1463
+ possibleKeys.push(pattern[1]);
1744
1464
  }
1745
- handlerSets.push(...this.gHSets(nextNode, method, node.params, /* @__PURE__ */ Object.create(null)));
1746
- } else {
1747
- tempNodes.push(nextNode);
1748
- }
1465
+ curNode = curNode.children[p];
1749
1466
  }
1750
- for (let k = 0, len3 = node.patterns.length; k < len3; k++) {
1751
- const pattern = node.patterns[k];
1752
- const params = { ...node.params };
1753
- if (pattern === "*") {
1754
- const astNode = node.children["*"];
1755
- if (astNode) {
1756
- handlerSets.push(...this.gHSets(astNode, method, node.params, /* @__PURE__ */ Object.create(null)));
1757
- tempNodes.push(astNode);
1467
+ if (!curNode.methods.length) curNode.methods = [];
1468
+ const m = /* @__PURE__ */ Object.create(null);
1469
+ const handlerSet = {
1470
+ handler,
1471
+ possibleKeys: possibleKeys.filter((v, i, a)=>a.indexOf(v) === i),
1472
+ name: this.name,
1473
+ score: this.order
1474
+ };
1475
+ m[method] = handlerSet;
1476
+ curNode.methods.push(m);
1477
+ return curNode;
1478
+ }
1479
+ gHSets(node, method, nodeParams, params) {
1480
+ const handlerSets = [];
1481
+ for(let i = 0, len = node.methods.length; i < len; i++){
1482
+ const m = node.methods[i];
1483
+ const handlerSet = m[method] || m[METHOD_NAME_ALL];
1484
+ const processedSet = /* @__PURE__ */ Object.create(null);
1485
+ if (void 0 !== handlerSet) {
1486
+ handlerSet.params = /* @__PURE__ */ Object.create(null);
1487
+ handlerSet.possibleKeys.forEach((key)=>{
1488
+ const processed = processedSet[handlerSet.name];
1489
+ handlerSet.params[key] = params[key] && !processed ? params[key] : nodeParams[key] ?? params[key];
1490
+ processedSet[handlerSet.name] = true;
1491
+ });
1492
+ handlerSets.push(handlerSet);
1758
1493
  }
1759
- continue;
1760
- }
1761
- if (part === "") {
1762
- continue;
1763
- }
1764
- const [key, name, matcher] = pattern;
1765
- const child = node.children[key];
1766
- const restPathString = parts.slice(i).join("/");
1767
- if (matcher instanceof RegExp && matcher.test(restPathString)) {
1768
- params[name] = restPathString;
1769
- handlerSets.push(...this.gHSets(child, method, node.params, params));
1770
- continue;
1771
- }
1772
- if (matcher === true || matcher instanceof RegExp && matcher.test(part)) {
1773
- if (typeof key === "string") {
1774
- params[name] = part;
1775
- if (isLast === true) {
1776
- handlerSets.push(...this.gHSets(child, method, params, node.params));
1777
- if (child.children["*"]) {
1778
- handlerSets.push(...this.gHSets(child.children["*"], method, params, node.params));
1494
+ }
1495
+ return handlerSets;
1496
+ }
1497
+ search(method, path) {
1498
+ const handlerSets = [];
1499
+ this.params = /* @__PURE__ */ Object.create(null);
1500
+ const curNode = this;
1501
+ let curNodes = [
1502
+ curNode
1503
+ ];
1504
+ const parts = splitPath(path);
1505
+ for(let i = 0, len = parts.length; i < len; i++){
1506
+ const part = parts[i];
1507
+ const isLast = i === len - 1;
1508
+ const tempNodes = [];
1509
+ for(let j = 0, len2 = curNodes.length; j < len2; j++){
1510
+ const node = curNodes[j];
1511
+ const nextNode = node.children[part];
1512
+ if (nextNode) {
1513
+ nextNode.params = node.params;
1514
+ if (true === isLast) {
1515
+ if (nextNode.children["*"]) handlerSets.push(...this.gHSets(nextNode.children["*"], method, node.params, /* @__PURE__ */ Object.create(null)));
1516
+ handlerSets.push(...this.gHSets(nextNode, method, node.params, /* @__PURE__ */ Object.create(null)));
1517
+ } else tempNodes.push(nextNode);
1518
+ }
1519
+ for(let k = 0, len3 = node.patterns.length; k < len3; k++){
1520
+ const pattern = node.patterns[k];
1521
+ const params = {
1522
+ ...node.params
1523
+ };
1524
+ if ("*" === pattern) {
1525
+ const astNode = node.children["*"];
1526
+ if (astNode) {
1527
+ handlerSets.push(...this.gHSets(astNode, method, node.params, /* @__PURE__ */ Object.create(null)));
1528
+ tempNodes.push(astNode);
1529
+ }
1530
+ continue;
1531
+ }
1532
+ if ("" === part) continue;
1533
+ const [key, name, matcher] = pattern;
1534
+ const child = node.children[key];
1535
+ const restPathString = parts.slice(i).join("/");
1536
+ if (matcher instanceof RegExp && matcher.test(restPathString)) {
1537
+ params[name] = restPathString;
1538
+ handlerSets.push(...this.gHSets(child, method, node.params, params));
1539
+ continue;
1540
+ }
1541
+ if (true === matcher || matcher instanceof RegExp && matcher.test(part)) {
1542
+ if ("string" == typeof key) {
1543
+ params[name] = part;
1544
+ if (true === isLast) {
1545
+ handlerSets.push(...this.gHSets(child, method, params, node.params));
1546
+ if (child.children["*"]) handlerSets.push(...this.gHSets(child.children["*"], method, params, node.params));
1547
+ } else {
1548
+ child.params = params;
1549
+ tempNodes.push(child);
1550
+ }
1551
+ }
1552
+ }
1779
1553
  }
1780
- } else {
1781
- child.params = params;
1782
- tempNodes.push(child);
1783
- }
1784
1554
  }
1785
- }
1555
+ curNodes = tempNodes;
1786
1556
  }
1787
- }
1788
- curNodes = tempNodes;
1557
+ const results = handlerSets.sort((a, b)=>a.score - b.score);
1558
+ return [
1559
+ results.map(({ handler, params })=>[
1560
+ handler,
1561
+ params
1562
+ ])
1563
+ ];
1789
1564
  }
1790
- const results = handlerSets.sort((a, b) => {
1791
- return a.score - b.score;
1792
- });
1793
- return [results.map(({ handler, params }) => [handler, params])];
1794
- }
1795
1565
  };
1796
-
1797
- // ../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/router/trie-router/router.js
1798
1566
  var TrieRouter = class {
1799
- constructor() {
1800
- __publicField(this, "name", "TrieRouter");
1801
- __publicField(this, "node");
1802
- this.node = new Node2();
1803
- }
1804
- add(method, path2, handler) {
1805
- const results = checkOptionalParameter(path2);
1806
- if (results) {
1807
- for (const p of results) {
1808
- this.node.insert(method, p, handler);
1809
- }
1810
- return;
1811
- }
1812
- this.node.insert(method, path2, handler);
1813
- }
1814
- match(method, path2) {
1815
- return this.node.search(method, path2);
1816
- }
1567
+ name = "TrieRouter";
1568
+ node;
1569
+ constructor(){
1570
+ this.node = new node_Node();
1571
+ }
1572
+ add(method, path, handler) {
1573
+ const results = checkOptionalParameter(path);
1574
+ if (results) {
1575
+ for (const p of results)this.node.insert(method, p, handler);
1576
+ return;
1577
+ }
1578
+ this.node.insert(method, path, handler);
1579
+ }
1580
+ match(method, path) {
1581
+ return this.node.search(method, path);
1582
+ }
1817
1583
  };
1818
-
1819
- // ../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/hono.js
1820
- var Hono2 = class extends Hono {
1821
- constructor(options = {}) {
1822
- super(options);
1823
- this.router = options.router ?? new SmartRouter({
1824
- routers: [new RegExpRouter(), new TrieRouter()]
1825
- });
1826
- }
1584
+ var hono_Hono = class extends Hono {
1585
+ constructor(options = {}){
1586
+ super(options);
1587
+ this.router = options.router ?? new SmartRouter({
1588
+ routers: [
1589
+ new RegExpRouter(),
1590
+ new TrieRouter()
1591
+ ]
1592
+ });
1593
+ }
1827
1594
  };
1828
-
1829
- // ../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/utils/cookie.js
1830
1595
  var validCookieNameRegEx = /^[\w!#$%&'*.^`|~+-]+$/;
1831
1596
  var validCookieValueRegEx = /^[ !#-:<-[\]-~]*$/;
1832
- var parse = (cookie, name) => {
1833
- const pairs = cookie.trim().split(";");
1834
- return pairs.reduce((parsedCookie, pairStr) => {
1835
- pairStr = pairStr.trim();
1836
- const valueStartPos = pairStr.indexOf("=");
1837
- if (valueStartPos === -1) {
1838
- return parsedCookie;
1839
- }
1840
- const cookieName = pairStr.substring(0, valueStartPos).trim();
1841
- if (name && name !== cookieName || !validCookieNameRegEx.test(cookieName)) {
1842
- return parsedCookie;
1843
- }
1844
- let cookieValue = pairStr.substring(valueStartPos + 1).trim();
1845
- if (cookieValue.startsWith('"') && cookieValue.endsWith('"')) {
1846
- cookieValue = cookieValue.slice(1, -1);
1847
- }
1848
- if (validCookieValueRegEx.test(cookieValue)) {
1849
- parsedCookie[cookieName] = decodeURIComponent_(cookieValue);
1850
- }
1851
- return parsedCookie;
1852
- }, {});
1597
+ var parse = (cookie, name)=>{
1598
+ const pairs = cookie.trim().split(";");
1599
+ return pairs.reduce((parsedCookie, pairStr)=>{
1600
+ pairStr = pairStr.trim();
1601
+ const valueStartPos = pairStr.indexOf("=");
1602
+ if (-1 === valueStartPos) return parsedCookie;
1603
+ const cookieName = pairStr.substring(0, valueStartPos).trim();
1604
+ if (name && name !== cookieName || !validCookieNameRegEx.test(cookieName)) return parsedCookie;
1605
+ let cookieValue = pairStr.substring(valueStartPos + 1).trim();
1606
+ if (cookieValue.startsWith('"') && cookieValue.endsWith('"')) cookieValue = cookieValue.slice(1, -1);
1607
+ if (validCookieValueRegEx.test(cookieValue)) parsedCookie[cookieName] = decodeURIComponent_(cookieValue);
1608
+ return parsedCookie;
1609
+ }, {});
1853
1610
  };
1854
-
1855
- // ../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/helper/cookie/index.js
1856
- var getCookie = (c, key, prefix) => {
1857
- const cookie = c.req.raw.headers.get("Cookie");
1858
- if (typeof key === "string") {
1859
- if (!cookie) {
1860
- return void 0;
1861
- }
1862
- let finalKey = key;
1863
- if (prefix === "secure") {
1864
- finalKey = "__Secure-" + key;
1865
- } else if (prefix === "host") {
1866
- finalKey = "__Host-" + key;
1867
- }
1868
- const obj2 = parse(cookie, finalKey);
1869
- return obj2[finalKey];
1870
- }
1871
- if (!cookie) {
1872
- return {};
1873
- }
1874
- const obj = parse(cookie);
1875
- return obj;
1611
+ var getCookie = (c, key, prefix)=>{
1612
+ const cookie = c.req.raw.headers.get("Cookie");
1613
+ if ("string" == typeof key) {
1614
+ if (!cookie) return;
1615
+ let finalKey = key;
1616
+ if ("secure" === prefix) finalKey = "__Secure-" + key;
1617
+ else if ("host" === prefix) finalKey = "__Host-" + key;
1618
+ const obj2 = parse(cookie, finalKey);
1619
+ return obj2[finalKey];
1620
+ }
1621
+ if (!cookie) return {};
1622
+ const obj = parse(cookie);
1623
+ return obj;
1876
1624
  };
1877
-
1878
- // ../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/http-exception.js
1879
1625
  var HTTPException = class extends Error {
1880
- constructor(status = 500, options) {
1881
- super(options?.message, { cause: options?.cause });
1882
- __publicField(this, "res");
1883
- __publicField(this, "status");
1884
- this.res = options?.res;
1885
- this.status = status;
1886
- }
1887
- getResponse() {
1888
- if (this.res) {
1889
- const newResponse = new Response(this.res.body, {
1890
- status: this.status,
1891
- headers: this.res.headers
1892
- });
1893
- return newResponse;
1894
- }
1895
- return new Response(this.message, {
1896
- status: this.status
1897
- });
1898
- }
1626
+ res;
1627
+ status;
1628
+ constructor(status = 500, options){
1629
+ super(options?.message, {
1630
+ cause: options?.cause
1631
+ });
1632
+ this.res = options?.res;
1633
+ this.status = status;
1634
+ }
1635
+ getResponse() {
1636
+ if (this.res) {
1637
+ const newResponse = new Response(this.res.body, {
1638
+ status: this.status,
1639
+ headers: this.res.headers
1640
+ });
1641
+ return newResponse;
1642
+ }
1643
+ return new Response(this.message, {
1644
+ status: this.status
1645
+ });
1646
+ }
1899
1647
  };
1900
-
1901
- // ../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/utils/buffer.js
1902
- var bufferToFormData = (arrayBuffer, contentType) => {
1903
- const response = new Response(arrayBuffer, {
1904
- headers: {
1905
- "Content-Type": contentType
1906
- }
1907
- });
1908
- return response.formData();
1648
+ var bufferToFormData = (arrayBuffer, contentType)=>{
1649
+ const response = new Response(arrayBuffer, {
1650
+ headers: {
1651
+ "Content-Type": contentType
1652
+ }
1653
+ });
1654
+ return response.formData();
1909
1655
  };
1910
-
1911
- // ../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/validator/validator.js
1912
1656
  var jsonRegex = /^application\/([a-z-\.]+\+)?json(;\s*[a-zA-Z0-9\-]+\=([^;]+))*$/;
1913
1657
  var multipartRegex = /^multipart\/form-data(;\s?boundary=[a-zA-Z0-9'"()+_,\-./:=?]+)?$/;
1914
1658
  var urlencodedRegex = /^application\/x-www-form-urlencoded(;\s*[a-zA-Z0-9\-]+\=([^;]+))*$/;
1915
- var validator = (target, validationFunc) => {
1916
- return async (c, next) => {
1917
- let value = {};
1918
- const contentType = c.req.header("Content-Type");
1919
- switch (target) {
1920
- case "json":
1921
- if (!contentType || !jsonRegex.test(contentType)) {
1922
- break;
1923
- }
1924
- try {
1925
- value = await c.req.json();
1926
- } catch {
1927
- const message = "Malformed JSON in request body";
1928
- throw new HTTPException(400, { message });
1929
- }
1930
- break;
1931
- case "form": {
1932
- if (!contentType || !(multipartRegex.test(contentType) || urlencodedRegex.test(contentType))) {
1933
- break;
1934
- }
1935
- let formData;
1936
- if (c.req.bodyCache.formData) {
1937
- formData = await c.req.bodyCache.formData;
1938
- } else {
1939
- try {
1940
- const arrayBuffer = await c.req.arrayBuffer();
1941
- formData = await bufferToFormData(arrayBuffer, contentType);
1942
- c.req.bodyCache.formData = formData;
1943
- } catch (e) {
1944
- let message = "Malformed FormData request.";
1945
- message += e instanceof Error ? ` ${e.message}` : ` ${String(e)}`;
1946
- throw new HTTPException(400, { message });
1947
- }
1659
+ var validator = (target, validationFunc)=>async (c, next)=>{
1660
+ let value = {};
1661
+ const contentType = c.req.header("Content-Type");
1662
+ switch(target){
1663
+ case "json":
1664
+ if (!contentType || !jsonRegex.test(contentType)) break;
1665
+ try {
1666
+ value = await c.req.json();
1667
+ } catch {
1668
+ const message = "Malformed JSON in request body";
1669
+ throw new HTTPException(400, {
1670
+ message
1671
+ });
1672
+ }
1673
+ break;
1674
+ case "form":
1675
+ {
1676
+ if (!contentType || !(multipartRegex.test(contentType) || urlencodedRegex.test(contentType))) break;
1677
+ let formData;
1678
+ if (c.req.bodyCache.formData) formData = await c.req.bodyCache.formData;
1679
+ else try {
1680
+ const arrayBuffer = await c.req.arrayBuffer();
1681
+ formData = await bufferToFormData(arrayBuffer, contentType);
1682
+ c.req.bodyCache.formData = formData;
1683
+ } catch (e) {
1684
+ let message = "Malformed FormData request.";
1685
+ message += e instanceof Error ? ` ${e.message}` : ` ${String(e)}`;
1686
+ throw new HTTPException(400, {
1687
+ message
1688
+ });
1689
+ }
1690
+ const form = {};
1691
+ formData.forEach((value2, key)=>{
1692
+ if (key.endsWith("[]")) (form[key] ??= []).push(value2);
1693
+ else if (Array.isArray(form[key])) form[key].push(value2);
1694
+ else if (key in form) form[key] = [
1695
+ form[key],
1696
+ value2
1697
+ ];
1698
+ else form[key] = value2;
1699
+ });
1700
+ value = form;
1701
+ break;
1702
+ }
1703
+ case "query":
1704
+ value = Object.fromEntries(Object.entries(c.req.queries()).map(([k, v])=>1 === v.length ? [
1705
+ k,
1706
+ v[0]
1707
+ ] : [
1708
+ k,
1709
+ v
1710
+ ]));
1711
+ break;
1712
+ case "param":
1713
+ value = c.req.param();
1714
+ break;
1715
+ case "header":
1716
+ value = c.req.header();
1717
+ break;
1718
+ case "cookie":
1719
+ value = getCookie(c);
1720
+ break;
1948
1721
  }
1949
- const form = {};
1950
- formData.forEach((value2, key) => {
1951
- if (key.endsWith("[]")) {
1952
- ;
1953
- (form[key] ?? (form[key] = [])).push(value2);
1954
- } else if (Array.isArray(form[key])) {
1955
- ;
1956
- form[key].push(value2);
1957
- } else if (key in form) {
1958
- form[key] = [form[key], value2];
1959
- } else {
1960
- form[key] = value2;
1961
- }
1962
- });
1963
- value = form;
1964
- break;
1965
- }
1966
- case "query":
1967
- value = Object.fromEntries(
1968
- Object.entries(c.req.queries()).map(([k, v]) => {
1969
- return v.length === 1 ? [k, v[0]] : [k, v];
1970
- })
1971
- );
1972
- break;
1973
- case "param":
1974
- value = c.req.param();
1975
- break;
1976
- case "header":
1977
- value = c.req.header();
1978
- break;
1979
- case "cookie":
1980
- value = getCookie(c);
1981
- break;
1982
- }
1983
- const res = await validationFunc(value, c);
1984
- if (res instanceof Response) {
1985
- return res;
1986
- }
1987
- c.req.addValidatedData(target, res);
1988
- await next();
1989
- };
1990
- };
1991
-
1992
- // ../../node_modules/.pnpm/valibot@0.42.1_typescript@5.6.3/node_modules/valibot/dist/index.js
1722
+ const res = await validationFunc(value, c);
1723
+ if (res instanceof Response) return res;
1724
+ c.req.addValidatedData(target, res);
1725
+ await next();
1726
+ };
1993
1727
  var store;
1994
1728
  function getGlobalConfig(config2) {
1995
- return {
1996
- lang: config2?.lang ?? store?.lang,
1997
- message: config2?.message,
1998
- abortEarly: config2?.abortEarly ?? store?.abortEarly,
1999
- abortPipeEarly: config2?.abortPipeEarly ?? store?.abortPipeEarly
2000
- };
1729
+ return {
1730
+ lang: config2?.lang ?? store?.lang,
1731
+ message: config2?.message,
1732
+ abortEarly: config2?.abortEarly ?? store?.abortEarly,
1733
+ abortPipeEarly: config2?.abortPipeEarly ?? store?.abortPipeEarly
1734
+ };
2001
1735
  }
2002
1736
  var store2;
2003
1737
  function getGlobalMessage(lang) {
2004
- return store2?.get(lang);
1738
+ return store2?.get(lang);
2005
1739
  }
2006
1740
  var store3;
2007
1741
  function getSchemaMessage(lang) {
2008
- return store3?.get(lang);
1742
+ return store3?.get(lang);
2009
1743
  }
2010
1744
  var store4;
2011
1745
  function getSpecificMessage(reference, lang) {
2012
- return store4?.get(reference)?.get(lang);
1746
+ return store4?.get(reference)?.get(lang);
2013
1747
  }
2014
1748
  function _stringify(input) {
2015
- const type = typeof input;
2016
- if (type === "string") {
2017
- return `"${input}"`;
2018
- }
2019
- if (type === "number" || type === "bigint" || type === "boolean") {
2020
- return `${input}`;
2021
- }
2022
- if (type === "object" || type === "function") {
2023
- return (input && Object.getPrototypeOf(input)?.constructor?.name) ?? "null";
2024
- }
2025
- return type;
1749
+ const type = typeof input;
1750
+ if ("string" === type) return `"${input}"`;
1751
+ if ("number" === type || "bigint" === type || "boolean" === type) return `${input}`;
1752
+ if ("object" === type || "function" === type) return (input && Object.getPrototypeOf(input)?.constructor?.name) ?? "null";
1753
+ return type;
2026
1754
  }
2027
1755
  function _addIssue(context, label, dataset, config2, other) {
2028
- const input = other && "input" in other ? other.input : dataset.value;
2029
- const expected = other?.expected ?? context.expects ?? null;
2030
- const received = other?.received ?? _stringify(input);
2031
- const issue = {
2032
- kind: context.kind,
2033
- type: context.type,
2034
- input,
2035
- expected,
2036
- received,
2037
- message: `Invalid ${label}: ${expected ? `Expected ${expected} but r` : "R"}eceived ${received}`,
2038
- requirement: context.requirement,
2039
- path: other?.path,
2040
- issues: other?.issues,
2041
- lang: config2.lang,
2042
- abortEarly: config2.abortEarly,
2043
- abortPipeEarly: config2.abortPipeEarly
2044
- };
2045
- const isSchema = context.kind === "schema";
2046
- const message = other?.message ?? context.message ?? getSpecificMessage(context.reference, issue.lang) ?? (isSchema ? getSchemaMessage(issue.lang) : null) ?? config2.message ?? getGlobalMessage(issue.lang);
2047
- if (message) {
2048
- issue.message = typeof message === "function" ? (
2049
- // @ts-expect-error
2050
- message(issue)
2051
- ) : message;
2052
- }
2053
- if (isSchema) {
2054
- dataset.typed = false;
2055
- }
2056
- if (dataset.issues) {
2057
- dataset.issues.push(issue);
2058
- } else {
2059
- dataset.issues = [issue];
2060
- }
1756
+ const input = other && "input" in other ? other.input : dataset.value;
1757
+ const expected = other?.expected ?? context.expects ?? null;
1758
+ const received = other?.received ?? _stringify(input);
1759
+ const issue = {
1760
+ kind: context.kind,
1761
+ type: context.type,
1762
+ input,
1763
+ expected,
1764
+ received,
1765
+ message: `Invalid ${label}: ${expected ? `Expected ${expected} but r` : "R"}eceived ${received}`,
1766
+ requirement: context.requirement,
1767
+ path: other?.path,
1768
+ issues: other?.issues,
1769
+ lang: config2.lang,
1770
+ abortEarly: config2.abortEarly,
1771
+ abortPipeEarly: config2.abortPipeEarly
1772
+ };
1773
+ const isSchema = "schema" === context.kind;
1774
+ const message = other?.message ?? context.message ?? getSpecificMessage(context.reference, issue.lang) ?? (isSchema ? getSchemaMessage(issue.lang) : null) ?? config2.message ?? getGlobalMessage(issue.lang);
1775
+ if (message) issue.message = "function" == typeof message ? message(issue) : message;
1776
+ if (isSchema) dataset.typed = false;
1777
+ if (dataset.issues) dataset.issues.push(issue);
1778
+ else dataset.issues = [
1779
+ issue
1780
+ ];
2061
1781
  }
2062
1782
  function _joinExpects(values, separator) {
2063
- const list = [...new Set(values)];
2064
- if (list.length > 1) {
2065
- return `(${list.join(` ${separator} `)})`;
2066
- }
2067
- return list[0] ?? "never";
1783
+ const list = [
1784
+ ...new Set(values)
1785
+ ];
1786
+ if (list.length > 1) return `(${list.join(` ${separator} `)})`;
1787
+ return list[0] ?? "never";
2068
1788
  }
2069
1789
  function getDefault(schema, dataset, config2) {
2070
- return typeof schema.default === "function" ? (
2071
- // @ts-expect-error
2072
- schema.default(dataset, config2)
2073
- ) : (
2074
- // @ts-expect-error
2075
- schema.default
2076
- );
1790
+ return "function" == typeof schema.default ? schema.default(dataset, config2) : schema.default;
2077
1791
  }
2078
- function boolean(message) {
2079
- return {
2080
- kind: "schema",
2081
- type: "boolean",
2082
- reference: boolean,
2083
- expects: "boolean",
2084
- async: false,
2085
- message,
2086
- _run(dataset, config2) {
2087
- if (typeof dataset.value === "boolean") {
2088
- dataset.typed = true;
2089
- } else {
2090
- _addIssue(this, "type", dataset, config2);
2091
- }
2092
- return dataset;
2093
- }
2094
- };
1792
+ function dist_boolean(message) {
1793
+ return {
1794
+ kind: "schema",
1795
+ type: "boolean",
1796
+ reference: dist_boolean,
1797
+ expects: "boolean",
1798
+ async: false,
1799
+ message,
1800
+ _run (dataset, config2) {
1801
+ if ("boolean" == typeof dataset.value) dataset.typed = true;
1802
+ else _addIssue(this, "type", dataset, config2);
1803
+ return dataset;
1804
+ }
1805
+ };
2095
1806
  }
2096
1807
  function literal(literal_, message) {
2097
- return {
2098
- kind: "schema",
2099
- type: "literal",
2100
- reference: literal,
2101
- expects: _stringify(literal_),
2102
- async: false,
2103
- literal: literal_,
2104
- message,
2105
- _run(dataset, config2) {
2106
- if (dataset.value === this.literal) {
2107
- dataset.typed = true;
2108
- } else {
2109
- _addIssue(this, "type", dataset, config2);
2110
- }
2111
- return dataset;
2112
- }
2113
- };
1808
+ return {
1809
+ kind: "schema",
1810
+ type: "literal",
1811
+ reference: literal,
1812
+ expects: _stringify(literal_),
1813
+ async: false,
1814
+ literal: literal_,
1815
+ message,
1816
+ _run (dataset, config2) {
1817
+ if (dataset.value === this.literal) dataset.typed = true;
1818
+ else _addIssue(this, "type", dataset, config2);
1819
+ return dataset;
1820
+ }
1821
+ };
2114
1822
  }
2115
- function object(entries, message) {
2116
- return {
2117
- kind: "schema",
2118
- type: "object",
2119
- reference: object,
2120
- expects: "Object",
2121
- async: false,
2122
- entries,
2123
- message,
2124
- _run(dataset, config2) {
2125
- const input = dataset.value;
2126
- if (input && typeof input === "object") {
2127
- dataset.typed = true;
2128
- dataset.value = {};
2129
- for (const key in this.entries) {
2130
- const value2 = input[key];
2131
- const valueDataset = this.entries[key]._run(
2132
- { typed: false, value: value2 },
2133
- config2
2134
- );
2135
- if (valueDataset.issues) {
2136
- const pathItem = {
2137
- type: "object",
2138
- origin: "value",
2139
- input,
2140
- key,
2141
- value: value2
2142
- };
2143
- for (const issue of valueDataset.issues) {
2144
- if (issue.path) {
2145
- issue.path.unshift(pathItem);
2146
- } else {
2147
- issue.path = [pathItem];
2148
- }
2149
- dataset.issues?.push(issue);
2150
- }
2151
- if (!dataset.issues) {
2152
- dataset.issues = valueDataset.issues;
2153
- }
2154
- if (config2.abortEarly) {
2155
- dataset.typed = false;
2156
- break;
1823
+ function nullable(wrapped, ...args) {
1824
+ const schema = {
1825
+ kind: "schema",
1826
+ type: "nullable",
1827
+ reference: nullable,
1828
+ expects: `(${wrapped.expects} | null)`,
1829
+ async: false,
1830
+ wrapped,
1831
+ _run (dataset, config2) {
1832
+ if (null === dataset.value) {
1833
+ if ("default" in this) dataset.value = getDefault(this, dataset, config2);
1834
+ if (null === dataset.value) {
1835
+ dataset.typed = true;
1836
+ return dataset;
1837
+ }
2157
1838
  }
2158
- }
2159
- if (!valueDataset.typed) {
2160
- dataset.typed = false;
2161
- }
2162
- if (valueDataset.value !== void 0 || key in input) {
2163
- dataset.value[key] = valueDataset.value;
2164
- }
1839
+ return this.wrapped._run(dataset, config2);
2165
1840
  }
2166
- } else {
2167
- _addIssue(this, "type", dataset, config2);
2168
- }
2169
- return dataset;
2170
- }
2171
- };
1841
+ };
1842
+ if (0 in args) schema.default = args[0];
1843
+ return schema;
2172
1844
  }
2173
- function optional(wrapped, ...args) {
2174
- const schema = {
2175
- kind: "schema",
2176
- type: "optional",
2177
- reference: optional,
2178
- expects: `(${wrapped.expects} | undefined)`,
2179
- async: false,
2180
- wrapped,
2181
- _run(dataset, config2) {
2182
- if (dataset.value === void 0) {
2183
- if ("default" in this) {
2184
- dataset.value = getDefault(
2185
- this,
2186
- dataset,
2187
- config2
2188
- );
1845
+ function dist_object(entries, message) {
1846
+ return {
1847
+ kind: "schema",
1848
+ type: "object",
1849
+ reference: dist_object,
1850
+ expects: "Object",
1851
+ async: false,
1852
+ entries,
1853
+ message,
1854
+ _run (dataset, config2) {
1855
+ const input = dataset.value;
1856
+ if (input && "object" == typeof input) {
1857
+ dataset.typed = true;
1858
+ dataset.value = {};
1859
+ for(const key in this.entries){
1860
+ const value2 = input[key];
1861
+ const valueDataset = this.entries[key]._run({
1862
+ typed: false,
1863
+ value: value2
1864
+ }, config2);
1865
+ if (valueDataset.issues) {
1866
+ const pathItem = {
1867
+ type: "object",
1868
+ origin: "value",
1869
+ input,
1870
+ key,
1871
+ value: value2
1872
+ };
1873
+ for (const issue of valueDataset.issues){
1874
+ if (issue.path) issue.path.unshift(pathItem);
1875
+ else issue.path = [
1876
+ pathItem
1877
+ ];
1878
+ dataset.issues?.push(issue);
1879
+ }
1880
+ if (!dataset.issues) dataset.issues = valueDataset.issues;
1881
+ if (config2.abortEarly) {
1882
+ dataset.typed = false;
1883
+ break;
1884
+ }
1885
+ }
1886
+ if (!valueDataset.typed) dataset.typed = false;
1887
+ if (void 0 !== valueDataset.value || key in input) dataset.value[key] = valueDataset.value;
1888
+ }
1889
+ } else _addIssue(this, "type", dataset, config2);
1890
+ return dataset;
2189
1891
  }
2190
- if (dataset.value === void 0) {
2191
- dataset.typed = true;
2192
- return dataset;
1892
+ };
1893
+ }
1894
+ function optional(wrapped, ...args) {
1895
+ const schema = {
1896
+ kind: "schema",
1897
+ type: "optional",
1898
+ reference: optional,
1899
+ expects: `(${wrapped.expects} | undefined)`,
1900
+ async: false,
1901
+ wrapped,
1902
+ _run (dataset, config2) {
1903
+ if (void 0 === dataset.value) {
1904
+ if ("default" in this) dataset.value = getDefault(this, dataset, config2);
1905
+ if (void 0 === dataset.value) {
1906
+ dataset.typed = true;
1907
+ return dataset;
1908
+ }
1909
+ }
1910
+ return this.wrapped._run(dataset, config2);
2193
1911
  }
2194
- }
2195
- return this.wrapped._run(dataset, config2);
2196
- }
2197
- };
2198
- if (0 in args) {
2199
- schema.default = args[0];
2200
- }
2201
- return schema;
1912
+ };
1913
+ if (0 in args) schema.default = args[0];
1914
+ return schema;
2202
1915
  }
2203
1916
  function string(message) {
2204
- return {
2205
- kind: "schema",
2206
- type: "string",
2207
- reference: string,
2208
- expects: "string",
2209
- async: false,
2210
- message,
2211
- _run(dataset, config2) {
2212
- if (typeof dataset.value === "string") {
2213
- dataset.typed = true;
2214
- } else {
2215
- _addIssue(this, "type", dataset, config2);
2216
- }
2217
- return dataset;
2218
- }
2219
- };
1917
+ return {
1918
+ kind: "schema",
1919
+ type: "string",
1920
+ reference: string,
1921
+ expects: "string",
1922
+ async: false,
1923
+ message,
1924
+ _run (dataset, config2) {
1925
+ if ("string" == typeof dataset.value) dataset.typed = true;
1926
+ else _addIssue(this, "type", dataset, config2);
1927
+ return dataset;
1928
+ }
1929
+ };
2220
1930
  }
2221
1931
  function _subIssues(datasets) {
2222
- let issues;
2223
- if (datasets) {
2224
- for (const dataset of datasets) {
2225
- if (issues) {
2226
- issues.push(...dataset.issues);
2227
- } else {
2228
- issues = dataset.issues;
2229
- }
2230
- }
2231
- }
2232
- return issues;
1932
+ let issues;
1933
+ if (datasets) for (const dataset of datasets)if (issues) issues.push(...dataset.issues);
1934
+ else issues = dataset.issues;
1935
+ return issues;
2233
1936
  }
2234
1937
  function union(options, message) {
2235
- return {
2236
- kind: "schema",
2237
- type: "union",
2238
- reference: union,
2239
- expects: _joinExpects(
2240
- options.map((option) => option.expects),
2241
- "|"
2242
- ),
2243
- async: false,
2244
- options,
2245
- message,
2246
- _run(dataset, config2) {
2247
- let validDataset;
2248
- let typedDatasets;
2249
- let untypedDatasets;
2250
- for (const schema of this.options) {
2251
- const optionDataset = schema._run(
2252
- { typed: false, value: dataset.value },
2253
- config2
2254
- );
2255
- if (optionDataset.typed) {
2256
- if (optionDataset.issues) {
1938
+ return {
1939
+ kind: "schema",
1940
+ type: "union",
1941
+ reference: union,
1942
+ expects: _joinExpects(options.map((option)=>option.expects), "|"),
1943
+ async: false,
1944
+ options,
1945
+ message,
1946
+ _run (dataset, config2) {
1947
+ let validDataset;
1948
+ let typedDatasets;
1949
+ let untypedDatasets;
1950
+ for (const schema of this.options){
1951
+ const optionDataset = schema._run({
1952
+ typed: false,
1953
+ value: dataset.value
1954
+ }, config2);
1955
+ if (optionDataset.typed) {
1956
+ if (optionDataset.issues) {
1957
+ if (typedDatasets) typedDatasets.push(optionDataset);
1958
+ else typedDatasets = [
1959
+ optionDataset
1960
+ ];
1961
+ } else {
1962
+ validDataset = optionDataset;
1963
+ break;
1964
+ }
1965
+ } else if (untypedDatasets) untypedDatasets.push(optionDataset);
1966
+ else untypedDatasets = [
1967
+ optionDataset
1968
+ ];
1969
+ }
1970
+ if (validDataset) return validDataset;
2257
1971
  if (typedDatasets) {
2258
- typedDatasets.push(optionDataset);
1972
+ if (1 === typedDatasets.length) return typedDatasets[0];
1973
+ _addIssue(this, "type", dataset, config2, {
1974
+ issues: _subIssues(typedDatasets)
1975
+ });
1976
+ dataset.typed = true;
2259
1977
  } else {
2260
- typedDatasets = [optionDataset];
1978
+ if (untypedDatasets?.length === 1) return untypedDatasets[0];
1979
+ _addIssue(this, "type", dataset, config2, {
1980
+ issues: _subIssues(untypedDatasets)
1981
+ });
2261
1982
  }
2262
- } else {
2263
- validDataset = optionDataset;
2264
- break;
2265
- }
2266
- } else {
2267
- if (untypedDatasets) {
2268
- untypedDatasets.push(optionDataset);
2269
- } else {
2270
- untypedDatasets = [optionDataset];
2271
- }
1983
+ return dataset;
2272
1984
  }
2273
- }
2274
- if (validDataset) {
2275
- return validDataset;
2276
- }
2277
- if (typedDatasets) {
2278
- if (typedDatasets.length === 1) {
2279
- return typedDatasets[0];
2280
- }
2281
- _addIssue(this, "type", dataset, config2, {
2282
- issues: _subIssues(typedDatasets)
2283
- });
2284
- dataset.typed = true;
2285
- } else if (untypedDatasets?.length === 1) {
2286
- return untypedDatasets[0];
2287
- } else {
2288
- _addIssue(this, "type", dataset, config2, {
2289
- issues: _subIssues(untypedDatasets)
2290
- });
2291
- }
2292
- return dataset;
2293
- }
2294
- };
1985
+ };
2295
1986
  }
2296
1987
  function omit(schema, keys) {
2297
- const entries = {
2298
- ...schema.entries
2299
- };
2300
- for (const key of keys) {
2301
- delete entries[key];
2302
- }
2303
- return { ...schema, entries };
1988
+ const entries = {
1989
+ ...schema.entries
1990
+ };
1991
+ for (const key of keys)delete entries[key];
1992
+ return {
1993
+ ...schema,
1994
+ entries
1995
+ };
2304
1996
  }
2305
1997
  function partial(schema, keys) {
2306
- const entries = {};
2307
- for (const key in schema.entries) {
2308
- entries[key] = !keys || keys.includes(key) ? optional(schema.entries[key]) : schema.entries[key];
2309
- }
2310
- return { ...schema, entries };
1998
+ const entries = {};
1999
+ for(const key in schema.entries)entries[key] = !keys || keys.includes(key) ? optional(schema.entries[key]) : schema.entries[key];
2000
+ return {
2001
+ ...schema,
2002
+ entries
2003
+ };
2311
2004
  }
2312
2005
  async function safeParseAsync(schema, input, config2) {
2313
- const dataset = await schema._run(
2314
- { typed: false, value: input },
2315
- getGlobalConfig(config2)
2316
- );
2317
- return {
2318
- typed: dataset.typed,
2319
- success: !dataset.issues,
2320
- output: dataset.value,
2321
- issues: dataset.issues
2322
- };
2006
+ const dataset = await schema._run({
2007
+ typed: false,
2008
+ value: input
2009
+ }, getGlobalConfig(config2));
2010
+ return {
2011
+ typed: dataset.typed,
2012
+ success: !dataset.issues,
2013
+ output: dataset.value,
2014
+ issues: dataset.issues
2015
+ };
2323
2016
  }
2324
-
2325
- // ../../node_modules/.pnpm/@hono+valibot-validator@0.4.1_hono@4.6.3_valibot@0.42.1_typescript@5.6.3_/node_modules/@hono/valibot-validator/dist/index.js
2326
- var vValidator = (target, schema, hook) => (
2327
- // @ts-expect-error not typed well
2328
- validator(target, async (value, c) => {
2329
- const result = await safeParseAsync(schema, value);
2330
- if (hook) {
2331
- const hookResult = hook(result, c);
2332
- if (hookResult instanceof Response || hookResult instanceof Promise) {
2333
- return hookResult;
2334
- }
2335
- }
2336
- if (!result.success) {
2337
- return c.json(result, 400);
2338
- }
2339
- const data = result.output;
2340
- return data;
2341
- })
2342
- );
2343
-
2344
- // src-server/rpc.ts
2345
- var import_plugin_core = require("@hot-updater/plugin-core");
2346
- var bundleSchema = object({
2347
- platform: union([literal("ios"), literal("android")]),
2348
- targetVersion: string(),
2349
- id: string(),
2350
- forceUpdate: boolean(),
2351
- enabled: boolean(),
2352
- file: string(),
2353
- hash: string(),
2354
- message: optional(string(), "")
2017
+ var vValidator = (target, schema, hook)=>validator(target, async (value, c)=>{
2018
+ const result = await safeParseAsync(schema, value);
2019
+ if (hook) {
2020
+ const hookResult = hook(result, c);
2021
+ if (hookResult instanceof Response || hookResult instanceof Promise) return hookResult;
2022
+ }
2023
+ if (!result.success) return c.json(result, 400);
2024
+ const data = result.output;
2025
+ return data;
2026
+ });
2027
+ const plugin_core_namespaceObject = require("@hot-updater/plugin-core");
2028
+ const bundleSchema = dist_object({
2029
+ platform: union([
2030
+ literal("ios"),
2031
+ literal("android")
2032
+ ]),
2033
+ targetAppVersion: string(),
2034
+ id: string(),
2035
+ forceUpdate: dist_boolean(),
2036
+ enabled: dist_boolean(),
2037
+ fileUrl: string(),
2038
+ fileHash: string(),
2039
+ gitCommitHash: nullable(string()),
2040
+ message: nullable(string())
2355
2041
  });
2356
- var config = null;
2357
- var rpc = new Hono2().get("/loadConfig", async (c) => {
2358
- config = await (0, import_plugin_core.loadConfig)();
2359
- return c.json(true);
2360
- }).get("/isConfigLoaded", (c) => {
2361
- return c.json(config !== null);
2362
- }).get("/getBundles", async (c) => {
2363
- if (!config) {
2364
- config = await (0, import_plugin_core.loadConfig)();
2365
- }
2366
- const databasePlugin = config?.database({
2367
- cwd: (0, import_plugin_core.getCwd)()
2368
- });
2369
- const bundles = await databasePlugin?.getBundles();
2370
- return c.json(bundles ?? []);
2371
- }).post(
2372
- "/getBundleById",
2373
- vValidator("json", object({ bundleId: string() })),
2374
- async (c) => {
2042
+ let rpc_config = null;
2043
+ const rpc = new hono_Hono().get("/loadConfig", async (c)=>{
2044
+ rpc_config = await (0, plugin_core_namespaceObject.loadConfig)();
2045
+ return c.json(true);
2046
+ }).get("/getConfig", async (c)=>{
2047
+ if (!rpc_config) rpc_config = await (0, plugin_core_namespaceObject.loadConfig)();
2048
+ return c.json({
2049
+ console: rpc_config?.console
2050
+ });
2051
+ }).get("/isConfigLoaded", (c)=>c.json(null !== rpc_config)).get("/getBundles", async (c)=>{
2052
+ if (!rpc_config) rpc_config = await (0, plugin_core_namespaceObject.loadConfig)();
2053
+ const databasePlugin = rpc_config?.database({
2054
+ cwd: plugin_core_namespaceObject.getCwd()
2055
+ });
2056
+ const bundles = await databasePlugin?.getBundles();
2057
+ return c.json(bundles ?? []);
2058
+ }).post("/getBundleById", vValidator("json", dist_object({
2059
+ bundleId: string()
2060
+ })), async (c)=>{
2375
2061
  const { bundleId } = c.req.valid("json");
2376
- if (!config) {
2377
- config = await (0, import_plugin_core.loadConfig)();
2378
- }
2379
- const databasePlugin = config?.database({
2380
- cwd: (0, import_plugin_core.getCwd)()
2062
+ if (!rpc_config) rpc_config = await (0, plugin_core_namespaceObject.loadConfig)();
2063
+ const databasePlugin = rpc_config?.database({
2064
+ cwd: plugin_core_namespaceObject.getCwd()
2381
2065
  });
2382
2066
  const bundle = await databasePlugin?.getBundleById(bundleId);
2383
2067
  return c.json(bundle ?? null);
2384
- }
2385
- ).post(
2386
- "/updateBundle",
2387
- vValidator(
2388
- "json",
2389
- object({
2390
- targetBundleId: string(),
2391
- bundle: partial(omit(bundleSchema, ["id"]))
2392
- })
2393
- ),
2394
- async (c) => {
2068
+ }).post("/updateBundle", vValidator("json", dist_object({
2069
+ targetBundleId: string(),
2070
+ bundle: partial(omit(bundleSchema, [
2071
+ "id"
2072
+ ]))
2073
+ })), async (c)=>{
2395
2074
  const { targetBundleId, bundle } = c.req.valid("json");
2396
- if (!config) {
2397
- config = await (0, import_plugin_core.loadConfig)();
2398
- }
2399
- const databasePlugin = config?.database({
2400
- cwd: (0, import_plugin_core.getCwd)()
2075
+ if (!rpc_config) rpc_config = await (0, plugin_core_namespaceObject.loadConfig)();
2076
+ const databasePlugin = rpc_config?.database({
2077
+ cwd: plugin_core_namespaceObject.getCwd()
2401
2078
  });
2402
2079
  await databasePlugin?.updateBundle(targetBundleId, bundle);
2403
2080
  await databasePlugin?.commitBundle();
2404
2081
  return c.json(true);
2405
- }
2406
- );
2407
-
2408
- // src-server/index.ts
2409
- var relativePathToScript = import_path.default.relative(process.cwd(), __dirname);
2410
- var app = new Hono2().get("/ping", (c) => c.text("pong")).route("/rpc", rpc).use(
2411
- "/static/*",
2412
- serveStatic({
2082
+ });
2083
+ const relativePathToScript = external_path_default().relative(process.cwd(), __dirname);
2084
+ const src_server_rslib_entry_app = new hono_Hono().get("/ping", (c)=>c.text("pong")).route("/rpc", rpc).use("/static/*", serveStatic({
2413
2085
  root: relativePathToScript
2414
- })
2415
- ).get(
2416
- "*",
2417
- serveStatic({
2086
+ })).get("*", serveStatic({
2418
2087
  root: relativePathToScript,
2419
2088
  path: "index.html"
2420
- })
2421
- );
2422
- var src_server_default = app;
2089
+ }));
2090
+ const src_server_rslib_entry_ = src_server_rslib_entry_app;
2091
+ var __webpack_export_target__ = exports;
2092
+ for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
2093
+ if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
2094
+ value: true
2095
+ });