r2-explorer 1.1.6 → 1.1.8

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 (27) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +3 -1
  3. package/dashboard/assets/{AuthLayout.b8a06fe7.js → AuthLayout.6d3dedba.js} +1 -1
  4. package/dashboard/{spa/assets/EmailFilePage.6051a393.js → assets/EmailFilePage.a943bd55.js} +1 -1
  5. package/dashboard/{spa/assets/ErrorNotFound.0a48c788.js → assets/ErrorNotFound.266a56a2.js} +1 -1
  6. package/dashboard/{spa/assets/LoginPage.56938389.js → assets/LoginPage.0803e1e5.js} +1 -1
  7. package/dashboard/assets/{auth-store.56a803cf.js → auth-store.f9483c0c.js} +1 -1
  8. package/dashboard/assets/{auth.9b1934ac.js → auth.b65d49fb.js} +1 -1
  9. package/dashboard/assets/{bus.71537b60.js → bus.3b14b9bc.js} +1 -1
  10. package/dashboard/assets/{index.6c65756b.js → index.6a139c53.js} +2 -2
  11. package/dashboard/assets/{index.9dfc5b79.css → index.9da34366.css} +1 -1
  12. package/dashboard/index.html +2 -2
  13. package/dashboard/spa/assets/{AuthLayout.b8a06fe7.js → AuthLayout.6d3dedba.js} +1 -1
  14. package/dashboard/{assets/EmailFilePage.6051a393.js → spa/assets/EmailFilePage.a943bd55.js} +1 -1
  15. package/dashboard/{assets/ErrorNotFound.0a48c788.js → spa/assets/ErrorNotFound.266a56a2.js} +1 -1
  16. package/dashboard/{assets/LoginPage.56938389.js → spa/assets/LoginPage.0803e1e5.js} +1 -1
  17. package/dashboard/spa/assets/{auth-store.56a803cf.js → auth-store.f9483c0c.js} +1 -1
  18. package/dashboard/spa/assets/{auth.9b1934ac.js → auth.b65d49fb.js} +1 -1
  19. package/dashboard/spa/assets/{bus.71537b60.js → bus.3b14b9bc.js} +1 -1
  20. package/dashboard/spa/assets/{index.6c65756b.js → index.6a139c53.js} +2 -2
  21. package/dashboard/spa/assets/{index.9dfc5b79.css → index.9da34366.css} +1 -1
  22. package/dashboard/spa/index.html +2 -2
  23. package/dist/index.d.mts +5 -3
  24. package/dist/index.d.ts +5 -3
  25. package/dist/index.js +1859 -20
  26. package/dist/index.mjs +1856 -18
  27. package/package.json +6 -3
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -34,9 +35,1790 @@ __export(src_exports, {
34
35
  module.exports = __toCommonJS(src_exports);
35
36
  var import_cloudflare_access = require("@hono/cloudflare-access");
36
37
  var import_chanfana14 = require("chanfana");
37
- var import_hono = require("hono");
38
- var import_basic_auth = require("hono/basic-auth");
39
- var import_cors = require("hono/cors");
38
+
39
+ // ../../node_modules/.pnpm/hono@4.6.15/node_modules/hono/dist/utils/body.js
40
+ var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
41
+ const { all = false, dot = false } = options;
42
+ const headers = request instanceof HonoRequest ? request.raw.headers : request.headers;
43
+ const contentType = headers.get("Content-Type");
44
+ if (contentType?.startsWith("multipart/form-data") || contentType?.startsWith("application/x-www-form-urlencoded")) {
45
+ return parseFormData(request, { all, dot });
46
+ }
47
+ return {};
48
+ };
49
+ async function parseFormData(request, options) {
50
+ const formData = await request.formData();
51
+ if (formData) {
52
+ return convertFormDataToBodyData(formData, options);
53
+ }
54
+ return {};
55
+ }
56
+ function convertFormDataToBodyData(formData, options) {
57
+ const form = /* @__PURE__ */ Object.create(null);
58
+ formData.forEach((value, key) => {
59
+ const shouldParseAllValues = options.all || key.endsWith("[]");
60
+ if (!shouldParseAllValues) {
61
+ form[key] = value;
62
+ } else {
63
+ handleParsingAllValues(form, key, value);
64
+ }
65
+ });
66
+ if (options.dot) {
67
+ Object.entries(form).forEach(([key, value]) => {
68
+ const shouldParseDotValues = key.includes(".");
69
+ if (shouldParseDotValues) {
70
+ handleParsingNestedValues(form, key, value);
71
+ delete form[key];
72
+ }
73
+ });
74
+ }
75
+ return form;
76
+ }
77
+ var handleParsingAllValues = (form, key, value) => {
78
+ if (form[key] !== void 0) {
79
+ if (Array.isArray(form[key])) {
80
+ ;
81
+ form[key].push(value);
82
+ } else {
83
+ form[key] = [form[key], value];
84
+ }
85
+ } else {
86
+ form[key] = value;
87
+ }
88
+ };
89
+ var handleParsingNestedValues = (form, key, value) => {
90
+ let nestedForm = form;
91
+ const keys = key.split(".");
92
+ keys.forEach((key2, index) => {
93
+ if (index === keys.length - 1) {
94
+ nestedForm[key2] = value;
95
+ } else {
96
+ if (!nestedForm[key2] || typeof nestedForm[key2] !== "object" || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) {
97
+ nestedForm[key2] = /* @__PURE__ */ Object.create(null);
98
+ }
99
+ nestedForm = nestedForm[key2];
100
+ }
101
+ });
102
+ };
103
+
104
+ // ../../node_modules/.pnpm/hono@4.6.15/node_modules/hono/dist/utils/url.js
105
+ var splitPath = (path) => {
106
+ const paths = path.split("/");
107
+ if (paths[0] === "") {
108
+ paths.shift();
109
+ }
110
+ return paths;
111
+ };
112
+ var splitRoutingPath = (routePath) => {
113
+ const { groups, path } = extractGroupsFromPath(routePath);
114
+ const paths = splitPath(path);
115
+ return replaceGroupMarks(paths, groups);
116
+ };
117
+ var extractGroupsFromPath = (path) => {
118
+ const groups = [];
119
+ path = path.replace(/\{[^}]+\}/g, (match, index) => {
120
+ const mark = `@${index}`;
121
+ groups.push([mark, match]);
122
+ return mark;
123
+ });
124
+ return { groups, path };
125
+ };
126
+ var replaceGroupMarks = (paths, groups) => {
127
+ for (let i = groups.length - 1; i >= 0; i--) {
128
+ const [mark] = groups[i];
129
+ for (let j = paths.length - 1; j >= 0; j--) {
130
+ if (paths[j].includes(mark)) {
131
+ paths[j] = paths[j].replace(mark, groups[i][1]);
132
+ break;
133
+ }
134
+ }
135
+ }
136
+ return paths;
137
+ };
138
+ var patternCache = {};
139
+ var getPattern = (label) => {
140
+ if (label === "*") {
141
+ return "*";
142
+ }
143
+ const match = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
144
+ if (match) {
145
+ if (!patternCache[label]) {
146
+ if (match[2]) {
147
+ patternCache[label] = [label, match[1], new RegExp("^" + match[2] + "$")];
148
+ } else {
149
+ patternCache[label] = [label, match[1], true];
150
+ }
151
+ }
152
+ return patternCache[label];
153
+ }
154
+ return null;
155
+ };
156
+ var tryDecode = (str, decoder) => {
157
+ try {
158
+ return decoder(str);
159
+ } catch {
160
+ return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match) => {
161
+ try {
162
+ return decoder(match);
163
+ } catch {
164
+ return match;
165
+ }
166
+ });
167
+ }
168
+ };
169
+ var tryDecodeURI = (str) => tryDecode(str, decodeURI);
170
+ var getPath = (request) => {
171
+ const url = request.url;
172
+ const start = url.indexOf("/", 8);
173
+ let i = start;
174
+ for (; i < url.length; i++) {
175
+ const charCode = url.charCodeAt(i);
176
+ if (charCode === 37) {
177
+ const queryIndex = url.indexOf("?", i);
178
+ const path = url.slice(start, queryIndex === -1 ? void 0 : queryIndex);
179
+ return tryDecodeURI(path.includes("%25") ? path.replace(/%25/g, "%2525") : path);
180
+ } else if (charCode === 63) {
181
+ break;
182
+ }
183
+ }
184
+ return url.slice(start, i);
185
+ };
186
+ var getPathNoStrict = (request) => {
187
+ const result = getPath(request);
188
+ return result.length > 1 && result.at(-1) === "/" ? result.slice(0, -1) : result;
189
+ };
190
+ var mergePath = (...paths) => {
191
+ let p = "";
192
+ let endsWithSlash = false;
193
+ for (let path of paths) {
194
+ if (p.at(-1) === "/") {
195
+ p = p.slice(0, -1);
196
+ endsWithSlash = true;
197
+ }
198
+ if (path[0] !== "/") {
199
+ path = `/${path}`;
200
+ }
201
+ if (path === "/" && endsWithSlash) {
202
+ p = `${p}/`;
203
+ } else if (path !== "/") {
204
+ p = `${p}${path}`;
205
+ }
206
+ if (path === "/" && p === "") {
207
+ p = "/";
208
+ }
209
+ }
210
+ return p;
211
+ };
212
+ var checkOptionalParameter = (path) => {
213
+ if (!path.match(/\:.+\?$/)) {
214
+ return null;
215
+ }
216
+ const segments = path.split("/");
217
+ const results = [];
218
+ let basePath = "";
219
+ segments.forEach((segment) => {
220
+ if (segment !== "" && !/\:/.test(segment)) {
221
+ basePath += "/" + segment;
222
+ } else if (/\:/.test(segment)) {
223
+ if (/\?/.test(segment)) {
224
+ if (results.length === 0 && basePath === "") {
225
+ results.push("/");
226
+ } else {
227
+ results.push(basePath);
228
+ }
229
+ const optionalSegment = segment.replace("?", "");
230
+ basePath += "/" + optionalSegment;
231
+ results.push(basePath);
232
+ } else {
233
+ basePath += "/" + segment;
234
+ }
235
+ }
236
+ });
237
+ return results.filter((v, i, a) => a.indexOf(v) === i);
238
+ };
239
+ var _decodeURI = (value) => {
240
+ if (!/[%+]/.test(value)) {
241
+ return value;
242
+ }
243
+ if (value.indexOf("+") !== -1) {
244
+ value = value.replace(/\+/g, " ");
245
+ }
246
+ return value.indexOf("%") !== -1 ? decodeURIComponent_(value) : value;
247
+ };
248
+ var _getQueryParam = (url, key, multiple) => {
249
+ let encoded;
250
+ if (!multiple && key && !/[%+]/.test(key)) {
251
+ let keyIndex2 = url.indexOf(`?${key}`, 8);
252
+ if (keyIndex2 === -1) {
253
+ keyIndex2 = url.indexOf(`&${key}`, 8);
254
+ }
255
+ while (keyIndex2 !== -1) {
256
+ const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1);
257
+ if (trailingKeyCode === 61) {
258
+ const valueIndex = keyIndex2 + key.length + 2;
259
+ const endIndex = url.indexOf("&", valueIndex);
260
+ return _decodeURI(url.slice(valueIndex, endIndex === -1 ? void 0 : endIndex));
261
+ } else if (trailingKeyCode == 38 || isNaN(trailingKeyCode)) {
262
+ return "";
263
+ }
264
+ keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
265
+ }
266
+ encoded = /[%+]/.test(url);
267
+ if (!encoded) {
268
+ return void 0;
269
+ }
270
+ }
271
+ const results = {};
272
+ encoded ??= /[%+]/.test(url);
273
+ let keyIndex = url.indexOf("?", 8);
274
+ while (keyIndex !== -1) {
275
+ const nextKeyIndex = url.indexOf("&", keyIndex + 1);
276
+ let valueIndex = url.indexOf("=", keyIndex);
277
+ if (valueIndex > nextKeyIndex && nextKeyIndex !== -1) {
278
+ valueIndex = -1;
279
+ }
280
+ let name = url.slice(
281
+ keyIndex + 1,
282
+ valueIndex === -1 ? nextKeyIndex === -1 ? void 0 : nextKeyIndex : valueIndex
283
+ );
284
+ if (encoded) {
285
+ name = _decodeURI(name);
286
+ }
287
+ keyIndex = nextKeyIndex;
288
+ if (name === "") {
289
+ continue;
290
+ }
291
+ let value;
292
+ if (valueIndex === -1) {
293
+ value = "";
294
+ } else {
295
+ value = url.slice(valueIndex + 1, nextKeyIndex === -1 ? void 0 : nextKeyIndex);
296
+ if (encoded) {
297
+ value = _decodeURI(value);
298
+ }
299
+ }
300
+ if (multiple) {
301
+ if (!(results[name] && Array.isArray(results[name]))) {
302
+ results[name] = [];
303
+ }
304
+ ;
305
+ results[name].push(value);
306
+ } else {
307
+ results[name] ??= value;
308
+ }
309
+ }
310
+ return key ? results[key] : results;
311
+ };
312
+ var getQueryParam = _getQueryParam;
313
+ var getQueryParams = (url, key) => {
314
+ return _getQueryParam(url, key, true);
315
+ };
316
+ var decodeURIComponent_ = decodeURIComponent;
317
+
318
+ // ../../node_modules/.pnpm/hono@4.6.15/node_modules/hono/dist/request.js
319
+ var tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
320
+ var HonoRequest = class {
321
+ raw;
322
+ #validatedData;
323
+ #matchResult;
324
+ routeIndex = 0;
325
+ path;
326
+ bodyCache = {};
327
+ constructor(request, path = "/", matchResult = [[]]) {
328
+ this.raw = request;
329
+ this.path = path;
330
+ this.#matchResult = matchResult;
331
+ this.#validatedData = {};
332
+ }
333
+ param(key) {
334
+ return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
335
+ }
336
+ #getDecodedParam(key) {
337
+ const paramKey = this.#matchResult[0][this.routeIndex][1][key];
338
+ const param = this.#getParamValue(paramKey);
339
+ return param ? /\%/.test(param) ? tryDecodeURIComponent(param) : param : void 0;
340
+ }
341
+ #getAllDecodedParams() {
342
+ const decoded = {};
343
+ const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
344
+ for (const key of keys) {
345
+ const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
346
+ if (value && typeof value === "string") {
347
+ decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value;
348
+ }
349
+ }
350
+ return decoded;
351
+ }
352
+ #getParamValue(paramKey) {
353
+ return this.#matchResult[1] ? this.#matchResult[1][paramKey] : paramKey;
354
+ }
355
+ query(key) {
356
+ return getQueryParam(this.url, key);
357
+ }
358
+ queries(key) {
359
+ return getQueryParams(this.url, key);
360
+ }
361
+ header(name) {
362
+ if (name) {
363
+ return this.raw.headers.get(name.toLowerCase()) ?? void 0;
364
+ }
365
+ const headerData = {};
366
+ this.raw.headers.forEach((value, key) => {
367
+ headerData[key] = value;
368
+ });
369
+ return headerData;
370
+ }
371
+ async parseBody(options) {
372
+ return this.bodyCache.parsedBody ??= await parseBody(this, options);
373
+ }
374
+ #cachedBody = (key) => {
375
+ const { bodyCache, raw: raw2 } = this;
376
+ const cachedBody = bodyCache[key];
377
+ if (cachedBody) {
378
+ return cachedBody;
379
+ }
380
+ const anyCachedKey = Object.keys(bodyCache)[0];
381
+ if (anyCachedKey) {
382
+ return bodyCache[anyCachedKey].then((body) => {
383
+ if (anyCachedKey === "json") {
384
+ body = JSON.stringify(body);
385
+ }
386
+ return new Response(body)[key]();
387
+ });
388
+ }
389
+ return bodyCache[key] = raw2[key]();
390
+ };
391
+ json() {
392
+ return this.#cachedBody("json");
393
+ }
394
+ text() {
395
+ return this.#cachedBody("text");
396
+ }
397
+ arrayBuffer() {
398
+ return this.#cachedBody("arrayBuffer");
399
+ }
400
+ blob() {
401
+ return this.#cachedBody("blob");
402
+ }
403
+ formData() {
404
+ return this.#cachedBody("formData");
405
+ }
406
+ addValidatedData(target, data) {
407
+ this.#validatedData[target] = data;
408
+ }
409
+ valid(target) {
410
+ return this.#validatedData[target];
411
+ }
412
+ get url() {
413
+ return this.raw.url;
414
+ }
415
+ get method() {
416
+ return this.raw.method;
417
+ }
418
+ get matchedRoutes() {
419
+ return this.#matchResult[0].map(([[, route]]) => route);
420
+ }
421
+ get routePath() {
422
+ return this.#matchResult[0].map(([[, route]]) => route)[this.routeIndex].path;
423
+ }
424
+ };
425
+
426
+ // ../../node_modules/.pnpm/hono@4.6.15/node_modules/hono/dist/utils/html.js
427
+ var HtmlEscapedCallbackPhase = {
428
+ Stringify: 1,
429
+ BeforeStream: 2,
430
+ Stream: 3
431
+ };
432
+ var raw = (value, callbacks) => {
433
+ const escapedString = new String(value);
434
+ escapedString.isEscaped = true;
435
+ escapedString.callbacks = callbacks;
436
+ return escapedString;
437
+ };
438
+ var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) => {
439
+ if (typeof str === "object" && !(str instanceof String)) {
440
+ if (!(str instanceof Promise)) {
441
+ str = str.toString();
442
+ }
443
+ if (str instanceof Promise) {
444
+ str = await str;
445
+ }
446
+ }
447
+ const callbacks = str.callbacks;
448
+ if (!callbacks?.length) {
449
+ return Promise.resolve(str);
450
+ }
451
+ if (buffer) {
452
+ buffer[0] += str;
453
+ } else {
454
+ buffer = [str];
455
+ }
456
+ const resStr = Promise.all(callbacks.map((c) => c({ phase, buffer, context }))).then(
457
+ (res) => Promise.all(
458
+ res.filter(Boolean).map((str2) => resolveCallback(str2, phase, false, context, buffer))
459
+ ).then(() => buffer[0])
460
+ );
461
+ if (preserveCallbacks) {
462
+ return raw(await resStr, callbacks);
463
+ } else {
464
+ return resStr;
465
+ }
466
+ };
467
+
468
+ // ../../node_modules/.pnpm/hono@4.6.15/node_modules/hono/dist/context.js
469
+ var TEXT_PLAIN = "text/plain; charset=UTF-8";
470
+ var setHeaders = (headers, map = {}) => {
471
+ for (const key of Object.keys(map)) {
472
+ headers.set(key, map[key]);
473
+ }
474
+ return headers;
475
+ };
476
+ var Context = class {
477
+ #rawRequest;
478
+ #req;
479
+ env = {};
480
+ #var;
481
+ finalized = false;
482
+ error;
483
+ #status = 200;
484
+ #executionCtx;
485
+ #headers;
486
+ #preparedHeaders;
487
+ #res;
488
+ #isFresh = true;
489
+ #layout;
490
+ #renderer;
491
+ #notFoundHandler;
492
+ #matchResult;
493
+ #path;
494
+ constructor(req, options) {
495
+ this.#rawRequest = req;
496
+ if (options) {
497
+ this.#executionCtx = options.executionCtx;
498
+ this.env = options.env;
499
+ this.#notFoundHandler = options.notFoundHandler;
500
+ this.#path = options.path;
501
+ this.#matchResult = options.matchResult;
502
+ }
503
+ }
504
+ get req() {
505
+ this.#req ??= new HonoRequest(this.#rawRequest, this.#path, this.#matchResult);
506
+ return this.#req;
507
+ }
508
+ get event() {
509
+ if (this.#executionCtx && "respondWith" in this.#executionCtx) {
510
+ return this.#executionCtx;
511
+ } else {
512
+ throw Error("This context has no FetchEvent");
513
+ }
514
+ }
515
+ get executionCtx() {
516
+ if (this.#executionCtx) {
517
+ return this.#executionCtx;
518
+ } else {
519
+ throw Error("This context has no ExecutionContext");
520
+ }
521
+ }
522
+ get res() {
523
+ this.#isFresh = false;
524
+ return this.#res ||= new Response("404 Not Found", { status: 404 });
525
+ }
526
+ set res(_res) {
527
+ this.#isFresh = false;
528
+ if (this.#res && _res) {
529
+ try {
530
+ for (const [k, v] of this.#res.headers.entries()) {
531
+ if (k === "content-type") {
532
+ continue;
533
+ }
534
+ if (k === "set-cookie") {
535
+ const cookies = this.#res.headers.getSetCookie();
536
+ _res.headers.delete("set-cookie");
537
+ for (const cookie of cookies) {
538
+ _res.headers.append("set-cookie", cookie);
539
+ }
540
+ } else {
541
+ _res.headers.set(k, v);
542
+ }
543
+ }
544
+ } catch (e) {
545
+ if (e instanceof TypeError && e.message.includes("immutable")) {
546
+ this.res = new Response(_res.body, {
547
+ headers: _res.headers,
548
+ status: _res.status
549
+ });
550
+ return;
551
+ } else {
552
+ throw e;
553
+ }
554
+ }
555
+ }
556
+ this.#res = _res;
557
+ this.finalized = true;
558
+ }
559
+ render = (...args) => {
560
+ this.#renderer ??= (content) => this.html(content);
561
+ return this.#renderer(...args);
562
+ };
563
+ setLayout = (layout) => this.#layout = layout;
564
+ getLayout = () => this.#layout;
565
+ setRenderer = (renderer) => {
566
+ this.#renderer = renderer;
567
+ };
568
+ header = (name, value, options) => {
569
+ if (value === void 0) {
570
+ if (this.#headers) {
571
+ this.#headers.delete(name);
572
+ } else if (this.#preparedHeaders) {
573
+ delete this.#preparedHeaders[name.toLocaleLowerCase()];
574
+ }
575
+ if (this.finalized) {
576
+ this.res.headers.delete(name);
577
+ }
578
+ return;
579
+ }
580
+ if (options?.append) {
581
+ if (!this.#headers) {
582
+ this.#isFresh = false;
583
+ this.#headers = new Headers(this.#preparedHeaders);
584
+ this.#preparedHeaders = {};
585
+ }
586
+ this.#headers.append(name, value);
587
+ } else {
588
+ if (this.#headers) {
589
+ this.#headers.set(name, value);
590
+ } else {
591
+ this.#preparedHeaders ??= {};
592
+ this.#preparedHeaders[name.toLowerCase()] = value;
593
+ }
594
+ }
595
+ if (this.finalized) {
596
+ if (options?.append) {
597
+ this.res.headers.append(name, value);
598
+ } else {
599
+ this.res.headers.set(name, value);
600
+ }
601
+ }
602
+ };
603
+ status = (status) => {
604
+ this.#isFresh = false;
605
+ this.#status = status;
606
+ };
607
+ set = (key, value) => {
608
+ this.#var ??= /* @__PURE__ */ new Map();
609
+ this.#var.set(key, value);
610
+ };
611
+ get = (key) => {
612
+ return this.#var ? this.#var.get(key) : void 0;
613
+ };
614
+ get var() {
615
+ if (!this.#var) {
616
+ return {};
617
+ }
618
+ return Object.fromEntries(this.#var);
619
+ }
620
+ #newResponse(data, arg, headers) {
621
+ if (this.#isFresh && !headers && !arg && this.#status === 200) {
622
+ return new Response(data, {
623
+ headers: this.#preparedHeaders
624
+ });
625
+ }
626
+ if (arg && typeof arg !== "number") {
627
+ const header = new Headers(arg.headers);
628
+ if (this.#headers) {
629
+ this.#headers.forEach((v, k) => {
630
+ if (k === "set-cookie") {
631
+ header.append(k, v);
632
+ } else {
633
+ header.set(k, v);
634
+ }
635
+ });
636
+ }
637
+ const headers2 = setHeaders(header, this.#preparedHeaders);
638
+ return new Response(data, {
639
+ headers: headers2,
640
+ status: arg.status ?? this.#status
641
+ });
642
+ }
643
+ const status = typeof arg === "number" ? arg : this.#status;
644
+ this.#preparedHeaders ??= {};
645
+ this.#headers ??= new Headers();
646
+ setHeaders(this.#headers, this.#preparedHeaders);
647
+ if (this.#res) {
648
+ this.#res.headers.forEach((v, k) => {
649
+ if (k === "set-cookie") {
650
+ this.#headers?.append(k, v);
651
+ } else {
652
+ this.#headers?.set(k, v);
653
+ }
654
+ });
655
+ setHeaders(this.#headers, this.#preparedHeaders);
656
+ }
657
+ headers ??= {};
658
+ for (const [k, v] of Object.entries(headers)) {
659
+ if (typeof v === "string") {
660
+ this.#headers.set(k, v);
661
+ } else {
662
+ this.#headers.delete(k);
663
+ for (const v2 of v) {
664
+ this.#headers.append(k, v2);
665
+ }
666
+ }
667
+ }
668
+ return new Response(data, {
669
+ status,
670
+ headers: this.#headers
671
+ });
672
+ }
673
+ newResponse = (...args) => this.#newResponse(...args);
674
+ body = (data, arg, headers) => {
675
+ return typeof arg === "number" ? this.#newResponse(data, arg, headers) : this.#newResponse(data, arg);
676
+ };
677
+ text = (text, arg, headers) => {
678
+ if (!this.#preparedHeaders) {
679
+ if (this.#isFresh && !headers && !arg) {
680
+ return new Response(text);
681
+ }
682
+ this.#preparedHeaders = {};
683
+ }
684
+ this.#preparedHeaders["content-type"] = TEXT_PLAIN;
685
+ if (typeof arg === "number") {
686
+ return this.#newResponse(text, arg, headers);
687
+ }
688
+ return this.#newResponse(text, arg);
689
+ };
690
+ json = (object, arg, headers) => {
691
+ const body = JSON.stringify(object);
692
+ this.#preparedHeaders ??= {};
693
+ this.#preparedHeaders["content-type"] = "application/json";
694
+ return typeof arg === "number" ? this.#newResponse(body, arg, headers) : this.#newResponse(body, arg);
695
+ };
696
+ html = (html, arg, headers) => {
697
+ this.#preparedHeaders ??= {};
698
+ this.#preparedHeaders["content-type"] = "text/html; charset=UTF-8";
699
+ if (typeof html === "object") {
700
+ return resolveCallback(html, HtmlEscapedCallbackPhase.Stringify, false, {}).then((html2) => {
701
+ return typeof arg === "number" ? this.#newResponse(html2, arg, headers) : this.#newResponse(html2, arg);
702
+ });
703
+ }
704
+ return typeof arg === "number" ? this.#newResponse(html, arg, headers) : this.#newResponse(html, arg);
705
+ };
706
+ redirect = (location, status) => {
707
+ this.#headers ??= new Headers();
708
+ this.#headers.set("Location", String(location));
709
+ return this.newResponse(null, status ?? 302);
710
+ };
711
+ notFound = () => {
712
+ this.#notFoundHandler ??= () => new Response();
713
+ return this.#notFoundHandler(this);
714
+ };
715
+ };
716
+
717
+ // ../../node_modules/.pnpm/hono@4.6.15/node_modules/hono/dist/compose.js
718
+ var compose = (middleware, onError, onNotFound) => {
719
+ return (context, next) => {
720
+ let index = -1;
721
+ const isContext = context instanceof Context;
722
+ return dispatch(0);
723
+ async function dispatch(i) {
724
+ if (i <= index) {
725
+ throw new Error("next() called multiple times");
726
+ }
727
+ index = i;
728
+ let res;
729
+ let isError = false;
730
+ let handler;
731
+ if (middleware[i]) {
732
+ handler = middleware[i][0][0];
733
+ if (isContext) {
734
+ context.req.routeIndex = i;
735
+ }
736
+ } else {
737
+ handler = i === middleware.length && next || void 0;
738
+ }
739
+ if (!handler) {
740
+ if (isContext && context.finalized === false && onNotFound) {
741
+ res = await onNotFound(context);
742
+ }
743
+ } else {
744
+ try {
745
+ res = await handler(context, () => {
746
+ return dispatch(i + 1);
747
+ });
748
+ } catch (err) {
749
+ if (err instanceof Error && isContext && onError) {
750
+ context.error = err;
751
+ res = await onError(err, context);
752
+ isError = true;
753
+ } else {
754
+ throw err;
755
+ }
756
+ }
757
+ }
758
+ if (res && (context.finalized === false || isError)) {
759
+ context.res = res;
760
+ }
761
+ return context;
762
+ }
763
+ };
764
+ };
765
+
766
+ // ../../node_modules/.pnpm/hono@4.6.15/node_modules/hono/dist/router.js
767
+ var METHOD_NAME_ALL = "ALL";
768
+ var METHOD_NAME_ALL_LOWERCASE = "all";
769
+ var METHODS = ["get", "post", "put", "delete", "options", "patch"];
770
+ var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
771
+ var UnsupportedPathError = class extends Error {
772
+ };
773
+
774
+ // ../../node_modules/.pnpm/hono@4.6.15/node_modules/hono/dist/utils/constants.js
775
+ var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
776
+
777
+ // ../../node_modules/.pnpm/hono@4.6.15/node_modules/hono/dist/hono-base.js
778
+ var notFoundHandler = (c) => {
779
+ return c.text("404 Not Found", 404);
780
+ };
781
+ var errorHandler = (err, c) => {
782
+ if ("getResponse" in err) {
783
+ return err.getResponse();
784
+ }
785
+ console.error(err);
786
+ return c.text("Internal Server Error", 500);
787
+ };
788
+ var Hono = class {
789
+ get;
790
+ post;
791
+ put;
792
+ delete;
793
+ options;
794
+ patch;
795
+ all;
796
+ on;
797
+ use;
798
+ router;
799
+ getPath;
800
+ _basePath = "/";
801
+ #path = "/";
802
+ routes = [];
803
+ constructor(options = {}) {
804
+ const allMethods = [...METHODS, METHOD_NAME_ALL_LOWERCASE];
805
+ allMethods.forEach((method) => {
806
+ this[method] = (args1, ...args) => {
807
+ if (typeof args1 === "string") {
808
+ this.#path = args1;
809
+ } else {
810
+ this.#addRoute(method, this.#path, args1);
811
+ }
812
+ args.forEach((handler) => {
813
+ this.#addRoute(method, this.#path, handler);
814
+ });
815
+ return this;
816
+ };
817
+ });
818
+ this.on = (method, path, ...handlers) => {
819
+ for (const p of [path].flat()) {
820
+ this.#path = p;
821
+ for (const m of [method].flat()) {
822
+ handlers.map((handler) => {
823
+ this.#addRoute(m.toUpperCase(), this.#path, handler);
824
+ });
825
+ }
826
+ }
827
+ return this;
828
+ };
829
+ this.use = (arg1, ...handlers) => {
830
+ if (typeof arg1 === "string") {
831
+ this.#path = arg1;
832
+ } else {
833
+ this.#path = "*";
834
+ handlers.unshift(arg1);
835
+ }
836
+ handlers.forEach((handler) => {
837
+ this.#addRoute(METHOD_NAME_ALL, this.#path, handler);
838
+ });
839
+ return this;
840
+ };
841
+ const strict = options.strict ?? true;
842
+ delete options.strict;
843
+ Object.assign(this, options);
844
+ this.getPath = strict ? options.getPath ?? getPath : getPathNoStrict;
845
+ }
846
+ #clone() {
847
+ const clone = new Hono({
848
+ router: this.router,
849
+ getPath: this.getPath
850
+ });
851
+ clone.routes = this.routes;
852
+ return clone;
853
+ }
854
+ #notFoundHandler = notFoundHandler;
855
+ errorHandler = errorHandler;
856
+ route(path, app) {
857
+ const subApp = this.basePath(path);
858
+ app.routes.map((r) => {
859
+ let handler;
860
+ if (app.errorHandler === errorHandler) {
861
+ handler = r.handler;
862
+ } else {
863
+ handler = async (c, next) => (await compose([], app.errorHandler)(c, () => r.handler(c, next))).res;
864
+ handler[COMPOSED_HANDLER] = r.handler;
865
+ }
866
+ subApp.#addRoute(r.method, r.path, handler);
867
+ });
868
+ return this;
869
+ }
870
+ basePath(path) {
871
+ const subApp = this.#clone();
872
+ subApp._basePath = mergePath(this._basePath, path);
873
+ return subApp;
874
+ }
875
+ onError = (handler) => {
876
+ this.errorHandler = handler;
877
+ return this;
878
+ };
879
+ notFound = (handler) => {
880
+ this.#notFoundHandler = handler;
881
+ return this;
882
+ };
883
+ mount(path, applicationHandler, options) {
884
+ let replaceRequest;
885
+ let optionHandler;
886
+ if (options) {
887
+ if (typeof options === "function") {
888
+ optionHandler = options;
889
+ } else {
890
+ optionHandler = options.optionHandler;
891
+ replaceRequest = options.replaceRequest;
892
+ }
893
+ }
894
+ const getOptions = optionHandler ? (c) => {
895
+ const options2 = optionHandler(c);
896
+ return Array.isArray(options2) ? options2 : [options2];
897
+ } : (c) => {
898
+ let executionContext = void 0;
899
+ try {
900
+ executionContext = c.executionCtx;
901
+ } catch {
902
+ }
903
+ return [c.env, executionContext];
904
+ };
905
+ replaceRequest ||= (() => {
906
+ const mergedPath = mergePath(this._basePath, path);
907
+ const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length;
908
+ return (request) => {
909
+ const url = new URL(request.url);
910
+ url.pathname = url.pathname.slice(pathPrefixLength) || "/";
911
+ return new Request(url, request);
912
+ };
913
+ })();
914
+ const handler = async (c, next) => {
915
+ const res = await applicationHandler(replaceRequest(c.req.raw), ...getOptions(c));
916
+ if (res) {
917
+ return res;
918
+ }
919
+ await next();
920
+ };
921
+ this.#addRoute(METHOD_NAME_ALL, mergePath(path, "*"), handler);
922
+ return this;
923
+ }
924
+ #addRoute(method, path, handler) {
925
+ method = method.toUpperCase();
926
+ path = mergePath(this._basePath, path);
927
+ const r = { path, method, handler };
928
+ this.router.add(method, path, [handler, r]);
929
+ this.routes.push(r);
930
+ }
931
+ #handleError(err, c) {
932
+ if (err instanceof Error) {
933
+ return this.errorHandler(err, c);
934
+ }
935
+ throw err;
936
+ }
937
+ #dispatch(request, executionCtx, env, method) {
938
+ if (method === "HEAD") {
939
+ return (async () => new Response(null, await this.#dispatch(request, executionCtx, env, "GET")))();
940
+ }
941
+ const path = this.getPath(request, { env });
942
+ const matchResult = this.router.match(method, path);
943
+ const c = new Context(request, {
944
+ path,
945
+ matchResult,
946
+ env,
947
+ executionCtx,
948
+ notFoundHandler: this.#notFoundHandler
949
+ });
950
+ if (matchResult[0].length === 1) {
951
+ let res;
952
+ try {
953
+ res = matchResult[0][0][0][0](c, async () => {
954
+ c.res = await this.#notFoundHandler(c);
955
+ });
956
+ } catch (err) {
957
+ return this.#handleError(err, c);
958
+ }
959
+ return res instanceof Promise ? res.then(
960
+ (resolved) => resolved || (c.finalized ? c.res : this.#notFoundHandler(c))
961
+ ).catch((err) => this.#handleError(err, c)) : res ?? this.#notFoundHandler(c);
962
+ }
963
+ const composed = compose(matchResult[0], this.errorHandler, this.#notFoundHandler);
964
+ return (async () => {
965
+ try {
966
+ const context = await composed(c);
967
+ if (!context.finalized) {
968
+ throw new Error(
969
+ "Context is not finalized. Did you forget to return a Response object or `await next()`?"
970
+ );
971
+ }
972
+ return context.res;
973
+ } catch (err) {
974
+ return this.#handleError(err, c);
975
+ }
976
+ })();
977
+ }
978
+ fetch = (request, ...rest) => {
979
+ return this.#dispatch(request, rest[1], rest[0], request.method);
980
+ };
981
+ request = (input, requestInit, Env, executionCtx) => {
982
+ if (input instanceof Request) {
983
+ return this.fetch(requestInit ? new Request(input, requestInit) : input, Env, executionCtx);
984
+ }
985
+ input = input.toString();
986
+ return this.fetch(
987
+ new Request(
988
+ /^https?:\/\//.test(input) ? input : `http://localhost${mergePath("/", input)}`,
989
+ requestInit
990
+ ),
991
+ Env,
992
+ executionCtx
993
+ );
994
+ };
995
+ fire = () => {
996
+ addEventListener("fetch", (event) => {
997
+ event.respondWith(this.#dispatch(event.request, event, void 0, event.request.method));
998
+ });
999
+ };
1000
+ };
1001
+
1002
+ // ../../node_modules/.pnpm/hono@4.6.15/node_modules/hono/dist/router/reg-exp-router/node.js
1003
+ var LABEL_REG_EXP_STR = "[^/]+";
1004
+ var ONLY_WILDCARD_REG_EXP_STR = ".*";
1005
+ var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
1006
+ var PATH_ERROR = Symbol();
1007
+ var regExpMetaChars = new Set(".\\+*[^]$()");
1008
+ function compareKey(a, b) {
1009
+ if (a.length === 1) {
1010
+ return b.length === 1 ? a < b ? -1 : 1 : -1;
1011
+ }
1012
+ if (b.length === 1) {
1013
+ return 1;
1014
+ }
1015
+ if (a === ONLY_WILDCARD_REG_EXP_STR || a === TAIL_WILDCARD_REG_EXP_STR) {
1016
+ return 1;
1017
+ } else if (b === ONLY_WILDCARD_REG_EXP_STR || b === TAIL_WILDCARD_REG_EXP_STR) {
1018
+ return -1;
1019
+ }
1020
+ if (a === LABEL_REG_EXP_STR) {
1021
+ return 1;
1022
+ } else if (b === LABEL_REG_EXP_STR) {
1023
+ return -1;
1024
+ }
1025
+ return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
1026
+ }
1027
+ var Node = class {
1028
+ #index;
1029
+ #varIndex;
1030
+ #children = /* @__PURE__ */ Object.create(null);
1031
+ insert(tokens, index, paramMap, context, pathErrorCheckOnly) {
1032
+ if (tokens.length === 0) {
1033
+ if (this.#index !== void 0) {
1034
+ throw PATH_ERROR;
1035
+ }
1036
+ if (pathErrorCheckOnly) {
1037
+ return;
1038
+ }
1039
+ this.#index = index;
1040
+ return;
1041
+ }
1042
+ const [token, ...restTokens] = tokens;
1043
+ const pattern = token === "*" ? restTokens.length === 0 ? ["", "", ONLY_WILDCARD_REG_EXP_STR] : ["", "", LABEL_REG_EXP_STR] : token === "/*" ? ["", "", TAIL_WILDCARD_REG_EXP_STR] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
1044
+ let node;
1045
+ if (pattern) {
1046
+ const name = pattern[1];
1047
+ let regexpStr = pattern[2] || LABEL_REG_EXP_STR;
1048
+ if (name && pattern[2]) {
1049
+ regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
1050
+ if (/\((?!\?:)/.test(regexpStr)) {
1051
+ throw PATH_ERROR;
1052
+ }
1053
+ }
1054
+ node = this.#children[regexpStr];
1055
+ if (!node) {
1056
+ if (Object.keys(this.#children).some(
1057
+ (k) => k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
1058
+ )) {
1059
+ throw PATH_ERROR;
1060
+ }
1061
+ if (pathErrorCheckOnly) {
1062
+ return;
1063
+ }
1064
+ node = this.#children[regexpStr] = new Node();
1065
+ if (name !== "") {
1066
+ node.#varIndex = context.varIndex++;
1067
+ }
1068
+ }
1069
+ if (!pathErrorCheckOnly && name !== "") {
1070
+ paramMap.push([name, node.#varIndex]);
1071
+ }
1072
+ } else {
1073
+ node = this.#children[token];
1074
+ if (!node) {
1075
+ if (Object.keys(this.#children).some(
1076
+ (k) => k.length > 1 && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
1077
+ )) {
1078
+ throw PATH_ERROR;
1079
+ }
1080
+ if (pathErrorCheckOnly) {
1081
+ return;
1082
+ }
1083
+ node = this.#children[token] = new Node();
1084
+ }
1085
+ }
1086
+ node.insert(restTokens, index, paramMap, context, pathErrorCheckOnly);
1087
+ }
1088
+ buildRegExpStr() {
1089
+ const childKeys = Object.keys(this.#children).sort(compareKey);
1090
+ const strList = childKeys.map((k) => {
1091
+ const c = this.#children[k];
1092
+ return (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr();
1093
+ });
1094
+ if (typeof this.#index === "number") {
1095
+ strList.unshift(`#${this.#index}`);
1096
+ }
1097
+ if (strList.length === 0) {
1098
+ return "";
1099
+ }
1100
+ if (strList.length === 1) {
1101
+ return strList[0];
1102
+ }
1103
+ return "(?:" + strList.join("|") + ")";
1104
+ }
1105
+ };
1106
+
1107
+ // ../../node_modules/.pnpm/hono@4.6.15/node_modules/hono/dist/router/reg-exp-router/trie.js
1108
+ var Trie = class {
1109
+ #context = { varIndex: 0 };
1110
+ #root = new Node();
1111
+ insert(path, index, pathErrorCheckOnly) {
1112
+ const paramAssoc = [];
1113
+ const groups = [];
1114
+ for (let i = 0; ; ) {
1115
+ let replaced = false;
1116
+ path = path.replace(/\{[^}]+\}/g, (m) => {
1117
+ const mark = `@\\${i}`;
1118
+ groups[i] = [mark, m];
1119
+ i++;
1120
+ replaced = true;
1121
+ return mark;
1122
+ });
1123
+ if (!replaced) {
1124
+ break;
1125
+ }
1126
+ }
1127
+ const tokens = path.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
1128
+ for (let i = groups.length - 1; i >= 0; i--) {
1129
+ const [mark] = groups[i];
1130
+ for (let j = tokens.length - 1; j >= 0; j--) {
1131
+ if (tokens[j].indexOf(mark) !== -1) {
1132
+ tokens[j] = tokens[j].replace(mark, groups[i][1]);
1133
+ break;
1134
+ }
1135
+ }
1136
+ }
1137
+ this.#root.insert(tokens, index, paramAssoc, this.#context, pathErrorCheckOnly);
1138
+ return paramAssoc;
1139
+ }
1140
+ buildRegExp() {
1141
+ let regexp = this.#root.buildRegExpStr();
1142
+ if (regexp === "") {
1143
+ return [/^$/, [], []];
1144
+ }
1145
+ let captureIndex = 0;
1146
+ const indexReplacementMap = [];
1147
+ const paramReplacementMap = [];
1148
+ regexp = regexp.replace(/#(\d+)|@(\d+)|\.\*\$/g, (_, handlerIndex, paramIndex) => {
1149
+ if (handlerIndex !== void 0) {
1150
+ indexReplacementMap[++captureIndex] = Number(handlerIndex);
1151
+ return "$()";
1152
+ }
1153
+ if (paramIndex !== void 0) {
1154
+ paramReplacementMap[Number(paramIndex)] = ++captureIndex;
1155
+ return "";
1156
+ }
1157
+ return "";
1158
+ });
1159
+ return [new RegExp(`^${regexp}`), indexReplacementMap, paramReplacementMap];
1160
+ }
1161
+ };
1162
+
1163
+ // ../../node_modules/.pnpm/hono@4.6.15/node_modules/hono/dist/router/reg-exp-router/router.js
1164
+ var emptyParam = [];
1165
+ var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
1166
+ var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
1167
+ function buildWildcardRegExp(path) {
1168
+ return wildcardRegExpCache[path] ??= new RegExp(
1169
+ path === "*" ? "" : `^${path.replace(
1170
+ /\/\*$|([.\\+*[^\]$()])/g,
1171
+ (_, metaChar) => metaChar ? `\\${metaChar}` : "(?:|/.*)"
1172
+ )}$`
1173
+ );
1174
+ }
1175
+ function clearWildcardRegExpCache() {
1176
+ wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
1177
+ }
1178
+ function buildMatcherFromPreprocessedRoutes(routes) {
1179
+ const trie = new Trie();
1180
+ const handlerData = [];
1181
+ if (routes.length === 0) {
1182
+ return nullMatcher;
1183
+ }
1184
+ const routesWithStaticPathFlag = routes.map(
1185
+ (route) => [!/\*|\/:/.test(route[0]), ...route]
1186
+ ).sort(
1187
+ ([isStaticA, pathA], [isStaticB, pathB]) => isStaticA ? 1 : isStaticB ? -1 : pathA.length - pathB.length
1188
+ );
1189
+ const staticMap = /* @__PURE__ */ Object.create(null);
1190
+ for (let i = 0, j = -1, len = routesWithStaticPathFlag.length; i < len; i++) {
1191
+ const [pathErrorCheckOnly, path, handlers] = routesWithStaticPathFlag[i];
1192
+ if (pathErrorCheckOnly) {
1193
+ staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
1194
+ } else {
1195
+ j++;
1196
+ }
1197
+ let paramAssoc;
1198
+ try {
1199
+ paramAssoc = trie.insert(path, j, pathErrorCheckOnly);
1200
+ } catch (e) {
1201
+ throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
1202
+ }
1203
+ if (pathErrorCheckOnly) {
1204
+ continue;
1205
+ }
1206
+ handlerData[j] = handlers.map(([h, paramCount]) => {
1207
+ const paramIndexMap = /* @__PURE__ */ Object.create(null);
1208
+ paramCount -= 1;
1209
+ for (; paramCount >= 0; paramCount--) {
1210
+ const [key, value] = paramAssoc[paramCount];
1211
+ paramIndexMap[key] = value;
1212
+ }
1213
+ return [h, paramIndexMap];
1214
+ });
1215
+ }
1216
+ const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
1217
+ for (let i = 0, len = handlerData.length; i < len; i++) {
1218
+ for (let j = 0, len2 = handlerData[i].length; j < len2; j++) {
1219
+ const map = handlerData[i][j]?.[1];
1220
+ if (!map) {
1221
+ continue;
1222
+ }
1223
+ const keys = Object.keys(map);
1224
+ for (let k = 0, len3 = keys.length; k < len3; k++) {
1225
+ map[keys[k]] = paramReplacementMap[map[keys[k]]];
1226
+ }
1227
+ }
1228
+ }
1229
+ const handlerMap = [];
1230
+ for (const i in indexReplacementMap) {
1231
+ handlerMap[i] = handlerData[indexReplacementMap[i]];
1232
+ }
1233
+ return [regexp, handlerMap, staticMap];
1234
+ }
1235
+ function findMiddleware(middleware, path) {
1236
+ if (!middleware) {
1237
+ return void 0;
1238
+ }
1239
+ for (const k of Object.keys(middleware).sort((a, b) => b.length - a.length)) {
1240
+ if (buildWildcardRegExp(k).test(path)) {
1241
+ return [...middleware[k]];
1242
+ }
1243
+ }
1244
+ return void 0;
1245
+ }
1246
+ var RegExpRouter = class {
1247
+ name = "RegExpRouter";
1248
+ #middleware;
1249
+ #routes;
1250
+ constructor() {
1251
+ this.#middleware = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
1252
+ this.#routes = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
1253
+ }
1254
+ add(method, path, handler) {
1255
+ const middleware = this.#middleware;
1256
+ const routes = this.#routes;
1257
+ if (!middleware || !routes) {
1258
+ throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
1259
+ }
1260
+ if (!middleware[method]) {
1261
+ ;
1262
+ [middleware, routes].forEach((handlerMap) => {
1263
+ handlerMap[method] = /* @__PURE__ */ Object.create(null);
1264
+ Object.keys(handlerMap[METHOD_NAME_ALL]).forEach((p) => {
1265
+ handlerMap[method][p] = [...handlerMap[METHOD_NAME_ALL][p]];
1266
+ });
1267
+ });
1268
+ }
1269
+ if (path === "/*") {
1270
+ path = "*";
1271
+ }
1272
+ const paramCount = (path.match(/\/:/g) || []).length;
1273
+ if (/\*$/.test(path)) {
1274
+ const re = buildWildcardRegExp(path);
1275
+ if (method === METHOD_NAME_ALL) {
1276
+ Object.keys(middleware).forEach((m) => {
1277
+ middleware[m][path] ||= findMiddleware(middleware[m], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
1278
+ });
1279
+ } else {
1280
+ middleware[method][path] ||= findMiddleware(middleware[method], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
1281
+ }
1282
+ Object.keys(middleware).forEach((m) => {
1283
+ if (method === METHOD_NAME_ALL || method === m) {
1284
+ Object.keys(middleware[m]).forEach((p) => {
1285
+ re.test(p) && middleware[m][p].push([handler, paramCount]);
1286
+ });
1287
+ }
1288
+ });
1289
+ Object.keys(routes).forEach((m) => {
1290
+ if (method === METHOD_NAME_ALL || method === m) {
1291
+ Object.keys(routes[m]).forEach(
1292
+ (p) => re.test(p) && routes[m][p].push([handler, paramCount])
1293
+ );
1294
+ }
1295
+ });
1296
+ return;
1297
+ }
1298
+ const paths = checkOptionalParameter(path) || [path];
1299
+ for (let i = 0, len = paths.length; i < len; i++) {
1300
+ const path2 = paths[i];
1301
+ Object.keys(routes).forEach((m) => {
1302
+ if (method === METHOD_NAME_ALL || method === m) {
1303
+ routes[m][path2] ||= [
1304
+ ...findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || []
1305
+ ];
1306
+ routes[m][path2].push([handler, paramCount - len + i + 1]);
1307
+ }
1308
+ });
1309
+ }
1310
+ }
1311
+ match(method, path) {
1312
+ clearWildcardRegExpCache();
1313
+ const matchers = this.#buildAllMatchers();
1314
+ this.match = (method2, path2) => {
1315
+ const matcher = matchers[method2] || matchers[METHOD_NAME_ALL];
1316
+ const staticMatch = matcher[2][path2];
1317
+ if (staticMatch) {
1318
+ return staticMatch;
1319
+ }
1320
+ const match = path2.match(matcher[0]);
1321
+ if (!match) {
1322
+ return [[], emptyParam];
1323
+ }
1324
+ const index = match.indexOf("", 1);
1325
+ return [matcher[1][index], match];
1326
+ };
1327
+ return this.match(method, path);
1328
+ }
1329
+ #buildAllMatchers() {
1330
+ const matchers = /* @__PURE__ */ Object.create(null);
1331
+ Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
1332
+ matchers[method] ||= this.#buildMatcher(method);
1333
+ });
1334
+ this.#middleware = this.#routes = void 0;
1335
+ return matchers;
1336
+ }
1337
+ #buildMatcher(method) {
1338
+ const routes = [];
1339
+ let hasOwnRoute = method === METHOD_NAME_ALL;
1340
+ [this.#middleware, this.#routes].forEach((r) => {
1341
+ const ownRoute = r[method] ? Object.keys(r[method]).map((path) => [path, r[method][path]]) : [];
1342
+ if (ownRoute.length !== 0) {
1343
+ hasOwnRoute ||= true;
1344
+ routes.push(...ownRoute);
1345
+ } else if (method !== METHOD_NAME_ALL) {
1346
+ routes.push(
1347
+ ...Object.keys(r[METHOD_NAME_ALL]).map((path) => [path, r[METHOD_NAME_ALL][path]])
1348
+ );
1349
+ }
1350
+ });
1351
+ if (!hasOwnRoute) {
1352
+ return null;
1353
+ } else {
1354
+ return buildMatcherFromPreprocessedRoutes(routes);
1355
+ }
1356
+ }
1357
+ };
1358
+
1359
+ // ../../node_modules/.pnpm/hono@4.6.15/node_modules/hono/dist/router/smart-router/router.js
1360
+ var SmartRouter = class {
1361
+ name = "SmartRouter";
1362
+ #routers = [];
1363
+ #routes = [];
1364
+ constructor(init) {
1365
+ this.#routers = init.routers;
1366
+ }
1367
+ add(method, path, handler) {
1368
+ if (!this.#routes) {
1369
+ throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
1370
+ }
1371
+ this.#routes.push([method, path, handler]);
1372
+ }
1373
+ match(method, path) {
1374
+ if (!this.#routes) {
1375
+ throw new Error("Fatal error");
1376
+ }
1377
+ const routers = this.#routers;
1378
+ const routes = this.#routes;
1379
+ const len = routers.length;
1380
+ let i = 0;
1381
+ let res;
1382
+ for (; i < len; i++) {
1383
+ const router = routers[i];
1384
+ try {
1385
+ for (let i2 = 0, len2 = routes.length; i2 < len2; i2++) {
1386
+ router.add(...routes[i2]);
1387
+ }
1388
+ res = router.match(method, path);
1389
+ } catch (e) {
1390
+ if (e instanceof UnsupportedPathError) {
1391
+ continue;
1392
+ }
1393
+ throw e;
1394
+ }
1395
+ this.match = router.match.bind(router);
1396
+ this.#routers = [router];
1397
+ this.#routes = void 0;
1398
+ break;
1399
+ }
1400
+ if (i === len) {
1401
+ throw new Error("Fatal error");
1402
+ }
1403
+ this.name = `SmartRouter + ${this.activeRouter.name}`;
1404
+ return res;
1405
+ }
1406
+ get activeRouter() {
1407
+ if (this.#routes || this.#routers.length !== 1) {
1408
+ throw new Error("No active router has been determined yet.");
1409
+ }
1410
+ return this.#routers[0];
1411
+ }
1412
+ };
1413
+
1414
+ // ../../node_modules/.pnpm/hono@4.6.15/node_modules/hono/dist/router/trie-router/node.js
1415
+ var emptyParams = /* @__PURE__ */ Object.create(null);
1416
+ var Node2 = class {
1417
+ #methods;
1418
+ #children;
1419
+ #patterns;
1420
+ #order = 0;
1421
+ #params = emptyParams;
1422
+ constructor(method, handler, children) {
1423
+ this.#children = children || /* @__PURE__ */ Object.create(null);
1424
+ this.#methods = [];
1425
+ if (method && handler) {
1426
+ const m = /* @__PURE__ */ Object.create(null);
1427
+ m[method] = { handler, possibleKeys: [], score: 0 };
1428
+ this.#methods = [m];
1429
+ }
1430
+ this.#patterns = [];
1431
+ }
1432
+ insert(method, path, handler) {
1433
+ this.#order = ++this.#order;
1434
+ let curNode = this;
1435
+ const parts = splitRoutingPath(path);
1436
+ const possibleKeys = [];
1437
+ for (let i = 0, len = parts.length; i < len; i++) {
1438
+ const p = parts[i];
1439
+ if (Object.keys(curNode.#children).includes(p)) {
1440
+ curNode = curNode.#children[p];
1441
+ const pattern2 = getPattern(p);
1442
+ if (pattern2) {
1443
+ possibleKeys.push(pattern2[1]);
1444
+ }
1445
+ continue;
1446
+ }
1447
+ curNode.#children[p] = new Node2();
1448
+ const pattern = getPattern(p);
1449
+ if (pattern) {
1450
+ curNode.#patterns.push(pattern);
1451
+ possibleKeys.push(pattern[1]);
1452
+ }
1453
+ curNode = curNode.#children[p];
1454
+ }
1455
+ const m = /* @__PURE__ */ Object.create(null);
1456
+ const handlerSet = {
1457
+ handler,
1458
+ possibleKeys: possibleKeys.filter((v, i, a) => a.indexOf(v) === i),
1459
+ score: this.#order
1460
+ };
1461
+ m[method] = handlerSet;
1462
+ curNode.#methods.push(m);
1463
+ return curNode;
1464
+ }
1465
+ #getHandlerSets(node, method, nodeParams, params) {
1466
+ const handlerSets = [];
1467
+ for (let i = 0, len = node.#methods.length; i < len; i++) {
1468
+ const m = node.#methods[i];
1469
+ const handlerSet = m[method] || m[METHOD_NAME_ALL];
1470
+ const processedSet = {};
1471
+ if (handlerSet !== void 0) {
1472
+ handlerSet.params = /* @__PURE__ */ Object.create(null);
1473
+ handlerSets.push(handlerSet);
1474
+ if (nodeParams !== emptyParams || params && params !== emptyParams) {
1475
+ for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
1476
+ const key = handlerSet.possibleKeys[i2];
1477
+ const processed = processedSet[handlerSet.score];
1478
+ handlerSet.params[key] = params?.[key] && !processed ? params[key] : nodeParams[key] ?? params?.[key];
1479
+ processedSet[handlerSet.score] = true;
1480
+ }
1481
+ }
1482
+ }
1483
+ }
1484
+ return handlerSets;
1485
+ }
1486
+ search(method, path) {
1487
+ const handlerSets = [];
1488
+ this.#params = emptyParams;
1489
+ const curNode = this;
1490
+ let curNodes = [curNode];
1491
+ const parts = splitPath(path);
1492
+ for (let i = 0, len = parts.length; i < len; i++) {
1493
+ const part = parts[i];
1494
+ const isLast = i === len - 1;
1495
+ const tempNodes = [];
1496
+ for (let j = 0, len2 = curNodes.length; j < len2; j++) {
1497
+ const node = curNodes[j];
1498
+ const nextNode = node.#children[part];
1499
+ if (nextNode) {
1500
+ nextNode.#params = node.#params;
1501
+ if (isLast) {
1502
+ if (nextNode.#children["*"]) {
1503
+ handlerSets.push(
1504
+ ...this.#getHandlerSets(nextNode.#children["*"], method, node.#params)
1505
+ );
1506
+ }
1507
+ handlerSets.push(...this.#getHandlerSets(nextNode, method, node.#params));
1508
+ } else {
1509
+ tempNodes.push(nextNode);
1510
+ }
1511
+ }
1512
+ for (let k = 0, len3 = node.#patterns.length; k < len3; k++) {
1513
+ const pattern = node.#patterns[k];
1514
+ const params = node.#params === emptyParams ? {} : { ...node.#params };
1515
+ if (pattern === "*") {
1516
+ const astNode = node.#children["*"];
1517
+ if (astNode) {
1518
+ handlerSets.push(...this.#getHandlerSets(astNode, method, node.#params));
1519
+ tempNodes.push(astNode);
1520
+ }
1521
+ continue;
1522
+ }
1523
+ if (part === "") {
1524
+ continue;
1525
+ }
1526
+ const [key, name, matcher] = pattern;
1527
+ const child = node.#children[key];
1528
+ const restPathString = parts.slice(i).join("/");
1529
+ if (matcher instanceof RegExp && matcher.test(restPathString)) {
1530
+ params[name] = restPathString;
1531
+ handlerSets.push(...this.#getHandlerSets(child, method, node.#params, params));
1532
+ continue;
1533
+ }
1534
+ if (matcher === true || matcher.test(part)) {
1535
+ params[name] = part;
1536
+ if (isLast) {
1537
+ handlerSets.push(...this.#getHandlerSets(child, method, params, node.#params));
1538
+ if (child.#children["*"]) {
1539
+ handlerSets.push(
1540
+ ...this.#getHandlerSets(child.#children["*"], method, params, node.#params)
1541
+ );
1542
+ }
1543
+ } else {
1544
+ child.#params = params;
1545
+ tempNodes.push(child);
1546
+ }
1547
+ }
1548
+ }
1549
+ }
1550
+ curNodes = tempNodes;
1551
+ }
1552
+ if (handlerSets.length > 1) {
1553
+ handlerSets.sort((a, b) => {
1554
+ return a.score - b.score;
1555
+ });
1556
+ }
1557
+ return [handlerSets.map(({ handler, params }) => [handler, params])];
1558
+ }
1559
+ };
1560
+
1561
+ // ../../node_modules/.pnpm/hono@4.6.15/node_modules/hono/dist/router/trie-router/router.js
1562
+ var TrieRouter = class {
1563
+ name = "TrieRouter";
1564
+ #node;
1565
+ constructor() {
1566
+ this.#node = new Node2();
1567
+ }
1568
+ add(method, path, handler) {
1569
+ const results = checkOptionalParameter(path);
1570
+ if (results) {
1571
+ for (let i = 0, len = results.length; i < len; i++) {
1572
+ this.#node.insert(method, results[i], handler);
1573
+ }
1574
+ return;
1575
+ }
1576
+ this.#node.insert(method, path, handler);
1577
+ }
1578
+ match(method, path) {
1579
+ return this.#node.search(method, path);
1580
+ }
1581
+ };
1582
+
1583
+ // ../../node_modules/.pnpm/hono@4.6.15/node_modules/hono/dist/hono.js
1584
+ var Hono2 = class extends Hono {
1585
+ constructor(options = {}) {
1586
+ super(options);
1587
+ this.router = options.router ?? new SmartRouter({
1588
+ routers: [new RegExpRouter(), new TrieRouter()]
1589
+ });
1590
+ }
1591
+ };
1592
+
1593
+ // ../../node_modules/.pnpm/hono@4.6.15/node_modules/hono/dist/http-exception.js
1594
+ var HTTPException = class extends Error {
1595
+ res;
1596
+ status;
1597
+ constructor(status = 500, options) {
1598
+ super(options?.message, { cause: options?.cause });
1599
+ this.res = options?.res;
1600
+ this.status = status;
1601
+ }
1602
+ getResponse() {
1603
+ if (this.res) {
1604
+ const newResponse = new Response(this.res.body, {
1605
+ status: this.status,
1606
+ headers: this.res.headers
1607
+ });
1608
+ return newResponse;
1609
+ }
1610
+ return new Response(this.message, {
1611
+ status: this.status
1612
+ });
1613
+ }
1614
+ };
1615
+
1616
+ // ../../node_modules/.pnpm/hono@4.6.15/node_modules/hono/dist/utils/encode.js
1617
+ var decodeBase64 = (str) => {
1618
+ const binary = atob(str);
1619
+ const bytes = new Uint8Array(new ArrayBuffer(binary.length));
1620
+ const half = binary.length / 2;
1621
+ for (let i = 0, j = binary.length - 1; i <= half; i++, j--) {
1622
+ bytes[i] = binary.charCodeAt(i);
1623
+ bytes[j] = binary.charCodeAt(j);
1624
+ }
1625
+ return bytes;
1626
+ };
1627
+
1628
+ // ../../node_modules/.pnpm/hono@4.6.15/node_modules/hono/dist/utils/basic-auth.js
1629
+ var CREDENTIALS_REGEXP = /^ *(?:[Bb][Aa][Ss][Ii][Cc]) +([A-Za-z0-9._~+/-]+=*) *$/;
1630
+ var USER_PASS_REGEXP = /^([^:]*):(.*)$/;
1631
+ var utf8Decoder = new TextDecoder();
1632
+ var auth = (req) => {
1633
+ const match = CREDENTIALS_REGEXP.exec(req.headers.get("Authorization") || "");
1634
+ if (!match) {
1635
+ return void 0;
1636
+ }
1637
+ let userPass = void 0;
1638
+ try {
1639
+ userPass = USER_PASS_REGEXP.exec(utf8Decoder.decode(decodeBase64(match[1])));
1640
+ } catch {
1641
+ }
1642
+ if (!userPass) {
1643
+ return void 0;
1644
+ }
1645
+ return { username: userPass[1], password: userPass[2] };
1646
+ };
1647
+
1648
+ // ../../node_modules/.pnpm/hono@4.6.15/node_modules/hono/dist/utils/crypto.js
1649
+ var sha256 = async (data) => {
1650
+ const algorithm = { name: "SHA-256", alias: "sha256" };
1651
+ const hash = await createHash(data, algorithm);
1652
+ return hash;
1653
+ };
1654
+ var createHash = async (data, algorithm) => {
1655
+ let sourceBuffer;
1656
+ if (ArrayBuffer.isView(data) || data instanceof ArrayBuffer) {
1657
+ sourceBuffer = data;
1658
+ } else {
1659
+ if (typeof data === "object") {
1660
+ data = JSON.stringify(data);
1661
+ }
1662
+ sourceBuffer = new TextEncoder().encode(String(data));
1663
+ }
1664
+ if (crypto && crypto.subtle) {
1665
+ const buffer = await crypto.subtle.digest(
1666
+ {
1667
+ name: algorithm.name
1668
+ },
1669
+ sourceBuffer
1670
+ );
1671
+ const hash = Array.prototype.map.call(new Uint8Array(buffer), (x) => ("00" + x.toString(16)).slice(-2)).join("");
1672
+ return hash;
1673
+ }
1674
+ return null;
1675
+ };
1676
+
1677
+ // ../../node_modules/.pnpm/hono@4.6.15/node_modules/hono/dist/utils/buffer.js
1678
+ var timingSafeEqual = async (a, b, hashFunction) => {
1679
+ if (!hashFunction) {
1680
+ hashFunction = sha256;
1681
+ }
1682
+ const [sa, sb] = await Promise.all([hashFunction(a), hashFunction(b)]);
1683
+ if (!sa || !sb) {
1684
+ return false;
1685
+ }
1686
+ return sa === sb && a === b;
1687
+ };
1688
+
1689
+ // ../../node_modules/.pnpm/hono@4.6.15/node_modules/hono/dist/middleware/basic-auth/index.js
1690
+ var basicAuth = (options, ...users) => {
1691
+ const usernamePasswordInOptions = "username" in options && "password" in options;
1692
+ const verifyUserInOptions = "verifyUser" in options;
1693
+ if (!(usernamePasswordInOptions || verifyUserInOptions)) {
1694
+ throw new Error(
1695
+ 'basic auth middleware requires options for "username and password" or "verifyUser"'
1696
+ );
1697
+ }
1698
+ if (!options.realm) {
1699
+ options.realm = "Secure Area";
1700
+ }
1701
+ if (!options.invalidUserMessage) {
1702
+ options.invalidUserMessage = "Unauthorized";
1703
+ }
1704
+ if (usernamePasswordInOptions) {
1705
+ users.unshift({ username: options.username, password: options.password });
1706
+ }
1707
+ return async function basicAuth2(ctx, next) {
1708
+ const requestUser = auth(ctx.req.raw);
1709
+ if (requestUser) {
1710
+ if (verifyUserInOptions) {
1711
+ if (await options.verifyUser(requestUser.username, requestUser.password, ctx)) {
1712
+ await next();
1713
+ return;
1714
+ }
1715
+ } else {
1716
+ for (const user of users) {
1717
+ const [usernameEqual, passwordEqual] = await Promise.all([
1718
+ timingSafeEqual(user.username, requestUser.username, options.hashFunction),
1719
+ timingSafeEqual(user.password, requestUser.password, options.hashFunction)
1720
+ ]);
1721
+ if (usernameEqual && passwordEqual) {
1722
+ await next();
1723
+ return;
1724
+ }
1725
+ }
1726
+ }
1727
+ }
1728
+ const status = 401;
1729
+ const headers = {
1730
+ "WWW-Authenticate": 'Basic realm="' + options.realm?.replace(/"/g, '\\"') + '"'
1731
+ };
1732
+ const responseMessage = typeof options.invalidUserMessage === "function" ? await options.invalidUserMessage(ctx) : options.invalidUserMessage;
1733
+ const res = typeof responseMessage === "string" ? new Response(responseMessage, { status, headers }) : new Response(JSON.stringify(responseMessage), {
1734
+ status,
1735
+ headers: {
1736
+ ...headers,
1737
+ "content-type": "application/json"
1738
+ }
1739
+ });
1740
+ throw new HTTPException(status, { res });
1741
+ };
1742
+ };
1743
+
1744
+ // ../../node_modules/.pnpm/hono@4.6.15/node_modules/hono/dist/middleware/cors/index.js
1745
+ var cors = (options) => {
1746
+ const defaults = {
1747
+ origin: "*",
1748
+ allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"],
1749
+ allowHeaders: [],
1750
+ exposeHeaders: []
1751
+ };
1752
+ const opts = {
1753
+ ...defaults,
1754
+ ...options
1755
+ };
1756
+ const findAllowOrigin = ((optsOrigin) => {
1757
+ if (typeof optsOrigin === "string") {
1758
+ if (optsOrigin === "*") {
1759
+ return () => optsOrigin;
1760
+ } else {
1761
+ return (origin) => optsOrigin === origin ? origin : null;
1762
+ }
1763
+ } else if (typeof optsOrigin === "function") {
1764
+ return optsOrigin;
1765
+ } else {
1766
+ return (origin) => optsOrigin.includes(origin) ? origin : null;
1767
+ }
1768
+ })(opts.origin);
1769
+ return async function cors2(c, next) {
1770
+ function set(key, value) {
1771
+ c.res.headers.set(key, value);
1772
+ }
1773
+ const allowOrigin = findAllowOrigin(c.req.header("origin") || "", c);
1774
+ if (allowOrigin) {
1775
+ set("Access-Control-Allow-Origin", allowOrigin);
1776
+ }
1777
+ if (opts.origin !== "*") {
1778
+ const existingVary = c.req.header("Vary");
1779
+ if (existingVary) {
1780
+ set("Vary", existingVary);
1781
+ } else {
1782
+ set("Vary", "Origin");
1783
+ }
1784
+ }
1785
+ if (opts.credentials) {
1786
+ set("Access-Control-Allow-Credentials", "true");
1787
+ }
1788
+ if (opts.exposeHeaders?.length) {
1789
+ set("Access-Control-Expose-Headers", opts.exposeHeaders.join(","));
1790
+ }
1791
+ if (c.req.method === "OPTIONS") {
1792
+ if (opts.maxAge != null) {
1793
+ set("Access-Control-Max-Age", opts.maxAge.toString());
1794
+ }
1795
+ if (opts.allowMethods?.length) {
1796
+ set("Access-Control-Allow-Methods", opts.allowMethods.join(","));
1797
+ }
1798
+ let headers = opts.allowHeaders;
1799
+ if (!headers?.length) {
1800
+ const requestHeaders = c.req.header("Access-Control-Request-Headers");
1801
+ if (requestHeaders) {
1802
+ headers = requestHeaders.split(/\s*,\s*/);
1803
+ }
1804
+ }
1805
+ if (headers?.length) {
1806
+ set("Access-Control-Allow-Headers", headers.join(","));
1807
+ c.res.headers.append("Vary", "Access-Control-Request-Headers");
1808
+ }
1809
+ c.res.headers.delete("Content-Length");
1810
+ c.res.headers.delete("Content-Type");
1811
+ return new Response(null, {
1812
+ headers: c.res.headers,
1813
+ status: 204,
1814
+ statusText: "No Content"
1815
+ });
1816
+ }
1817
+ await next();
1818
+ };
1819
+ };
1820
+
1821
+ // src/index.ts
40
1822
  var import_zod13 = require("zod");
41
1823
 
42
1824
  // src/foundation/middlewares/readonly.ts
@@ -60,7 +1842,7 @@ async function readOnlyMiddleware(c, next) {
60
1842
  }
61
1843
 
62
1844
  // package.json
63
- var version = "1.1.6";
1845
+ var version = "1.1.8";
64
1846
 
65
1847
  // src/foundation/settings.ts
66
1848
  var settings = {
@@ -92,9 +1874,16 @@ var CreateFolder = class extends import_chanfana.OpenAPIRoute {
92
1874
  };
93
1875
  async handle(c) {
94
1876
  const data = await this.getValidatedData();
95
- const bucket = c.env[data.params.bucket];
1877
+ const bucketName = data.params.bucket;
1878
+ const bucket = c.env[bucketName];
1879
+ if (!bucket) {
1880
+ throw new HTTPException(500, {
1881
+ message: `Bucket binding not found: ${bucketName}`
1882
+ });
1883
+ }
96
1884
  const key = decodeURIComponent(escape(atob(data.body.key)));
97
- return await bucket.put(key, "R2 Explorer Folder");
1885
+ const folderKey = key.endsWith("/") ? key : `${key}/`;
1886
+ return await bucket.put(folderKey, "");
98
1887
  }
99
1888
  };
100
1889
 
@@ -123,7 +1912,13 @@ var DeleteObject = class extends import_chanfana2.OpenAPIRoute {
123
1912
  };
124
1913
  async handle(c) {
125
1914
  const data = await this.getValidatedData();
126
- const bucket = c.env[data.params.bucket];
1915
+ const bucketName = data.params.bucket;
1916
+ const bucket = c.env[bucketName];
1917
+ if (!bucket) {
1918
+ throw new HTTPException(500, {
1919
+ message: `Bucket binding not found: ${bucketName}`
1920
+ });
1921
+ }
127
1922
  const key = decodeURIComponent(escape(atob(data.body.key)));
128
1923
  await bucket.delete(key);
129
1924
  return { success: true };
@@ -153,7 +1948,13 @@ var GetObject = class extends import_chanfana3.OpenAPIRoute {
153
1948
  };
154
1949
  async handle(c) {
155
1950
  const data = await this.getValidatedData();
156
- const bucket = c.env[data.params.bucket];
1951
+ const bucketName = data.params.bucket;
1952
+ const bucket = c.env[bucketName];
1953
+ if (!bucket) {
1954
+ throw new HTTPException(500, {
1955
+ message: `Bucket binding not found: ${bucketName}`
1956
+ });
1957
+ }
157
1958
  let filePath;
158
1959
  try {
159
1960
  filePath = decodeURIComponent(escape(atob(data.params.key)));
@@ -196,7 +1997,13 @@ var HeadObject = class extends import_chanfana4.OpenAPIRoute {
196
1997
  };
197
1998
  async handle(c) {
198
1999
  const data = await this.getValidatedData();
199
- const bucket = c.env[data.params.bucket];
2000
+ const bucketName = data.params.bucket;
2001
+ const bucket = c.env[bucketName];
2002
+ if (!bucket) {
2003
+ throw new HTTPException(500, {
2004
+ message: `Bucket binding not found: ${bucketName}`
2005
+ });
2006
+ }
200
2007
  let filePath;
201
2008
  try {
202
2009
  filePath = decodeURIComponent(escape(atob(data.params.key)));
@@ -205,11 +2012,11 @@ var HeadObject = class extends import_chanfana4.OpenAPIRoute {
205
2012
  escape(atob(decodeURIComponent(data.params.key)))
206
2013
  );
207
2014
  }
208
- const object = await bucket.head(filePath);
209
- if (object === null) {
210
- return Response.json({ msg: "Object Not Found" }, { status: 404 });
2015
+ const objectMeta = await bucket.head(filePath);
2016
+ if (objectMeta === null) {
2017
+ throw new HTTPException(404, { message: "Object Not Found" });
211
2018
  }
212
- return object;
2019
+ return objectMeta;
213
2020
  }
214
2021
  };
215
2022
 
@@ -237,7 +2044,13 @@ var ListObjects = class extends import_chanfana5.OpenAPIRoute {
237
2044
  };
238
2045
  async handle(c) {
239
2046
  const data = await this.getValidatedData();
240
- const bucket = c.env[data.params.bucket];
2047
+ const bucketName = data.params.bucket;
2048
+ const bucket = c.env[bucketName];
2049
+ if (!bucket) {
2050
+ throw new HTTPException(500, {
2051
+ message: `Bucket binding not found: ${bucketName}`
2052
+ });
2053
+ }
241
2054
  c.header("Access-Control-Allow-Credentials", "asads");
242
2055
  return await bucket.list({
243
2056
  limit: data.query.limit,
@@ -277,10 +2090,21 @@ var MoveObject = class extends import_chanfana6.OpenAPIRoute {
277
2090
  };
278
2091
  async handle(c) {
279
2092
  const data = await this.getValidatedData();
280
- const bucket = c.env[data.params.bucket];
2093
+ const bucketName = data.params.bucket;
2094
+ const bucket = c.env[bucketName];
2095
+ if (!bucket) {
2096
+ throw new HTTPException(500, {
2097
+ message: `Bucket binding not found: ${bucketName}`
2098
+ });
2099
+ }
281
2100
  const oldKey = decodeURIComponent(escape(atob(data.body.oldKey)));
282
2101
  const newKey = decodeURIComponent(escape(atob(data.body.newKey)));
283
2102
  const object = await bucket.get(oldKey);
2103
+ if (object === null) {
2104
+ throw new HTTPException(404, {
2105
+ message: `Source object not found: ${oldKey}`
2106
+ });
2107
+ }
284
2108
  const resp = await bucket.put(newKey, object.body, {
285
2109
  customMetadata: object.customMetadata,
286
2110
  httpMetadata: object.httpMetadata
@@ -454,7 +2278,13 @@ var PutMetadata = class extends import_chanfana10.OpenAPIRoute {
454
2278
  };
455
2279
  async handle(c) {
456
2280
  const data = await this.getValidatedData();
457
- const bucket = c.env[data.params.bucket];
2281
+ const bucketName = data.params.bucket;
2282
+ const bucket = c.env[bucketName];
2283
+ if (!bucket) {
2284
+ throw new HTTPException(500, {
2285
+ message: `Bucket binding not found: ${bucketName}`
2286
+ });
2287
+ }
458
2288
  let filePath;
459
2289
  try {
460
2290
  filePath = decodeURIComponent(escape(atob(data.params.key)));
@@ -464,6 +2294,9 @@ var PutMetadata = class extends import_chanfana10.OpenAPIRoute {
464
2294
  );
465
2295
  }
466
2296
  const object = await bucket.get(filePath);
2297
+ if (object === null) {
2298
+ throw new HTTPException(404, { message: "Object not found" });
2299
+ }
467
2300
  return await bucket.put(filePath, object.body, {
468
2301
  customMetadata: data.body.customMetadata,
469
2302
  httpMetadata: data.body.httpMetadata
@@ -502,7 +2335,13 @@ var PutObject = class extends import_chanfana11.OpenAPIRoute {
502
2335
  };
503
2336
  async handle(c) {
504
2337
  const data = await this.getValidatedData();
505
- const bucket = c.env[data.params.bucket];
2338
+ const bucketName = data.params.bucket;
2339
+ const bucket = c.env[bucketName];
2340
+ if (!bucket) {
2341
+ throw new HTTPException(500, {
2342
+ message: `Bucket binding not found: ${bucketName}`
2343
+ });
2344
+ }
506
2345
  const key = decodeURIComponent(escape(atob(data.query.key)));
507
2346
  let customMetadata = void 0;
508
2347
  if (data.query.customMetadata) {
@@ -700,7 +2539,7 @@ function R2Explorer(config) {
700
2539
  }
701
2540
  ];
702
2541
  }
703
- const app = new import_hono.Hono();
2542
+ const app = new Hono2();
704
2543
  app.use("*", async (c, next) => {
705
2544
  c.set("config", config);
706
2545
  await next();
@@ -711,7 +2550,7 @@ function R2Explorer(config) {
711
2550
  generateOperationIds: false
712
2551
  });
713
2552
  if (config.cors === true) {
714
- app.use("/api/*", (0, import_cors.cors)());
2553
+ app.use("/api/*", cors());
715
2554
  }
716
2555
  if (config.readonly === true) {
717
2556
  app.use("/api/*", readOnlyMiddleware);
@@ -731,7 +2570,7 @@ function R2Explorer(config) {
731
2570
  });
732
2571
  app.use(
733
2572
  "/api/*",
734
- (0, import_basic_auth.basicAuth)({
2573
+ basicAuth({
735
2574
  invalidUserMessage: "Authentication error: Basic Auth required",
736
2575
  verifyUser: (username, password, c) => {
737
2576
  const users = Array.isArray(c.get("config").basicAuth) ? c.get("config").basicAuth : [c.get("config").basicAuth];