r2-explorer 1.1.7 → 1.1.9

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