hono 4.1.7 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/cjs/helper/ssg/ssg.js +17 -14
  2. package/dist/cjs/jsx/dom/index.js +3 -0
  3. package/dist/cjs/jsx/hooks/index.js +4 -0
  4. package/dist/cjs/jsx/index.js +3 -0
  5. package/dist/cjs/middleware/basic-auth/index.js +22 -9
  6. package/dist/cjs/middleware/bearer-auth/index.js +4 -2
  7. package/dist/cjs/middleware/cache/index.js +22 -3
  8. package/dist/cjs/middleware/cors/index.js +1 -1
  9. package/dist/cjs/middleware/jwt/index.js +12 -6
  10. package/dist/cjs/middleware/method-override/index.js +106 -0
  11. package/dist/cjs/middleware/trailing-slash/index.js +49 -0
  12. package/dist/cjs/request.js +13 -4
  13. package/dist/cjs/test-utils/setup-vitest.js +5 -2
  14. package/dist/cjs/utils/jwt/index.js +2 -7
  15. package/dist/cjs/utils/jwt/jwa.js +43 -0
  16. package/dist/cjs/utils/jwt/jws.js +212 -0
  17. package/dist/cjs/utils/jwt/jwt.js +26 -72
  18. package/dist/cjs/utils/jwt/types.js +21 -8
  19. package/dist/cjs/utils/jwt/utf8.js +31 -0
  20. package/dist/cjs/validator/validator.js +2 -27
  21. package/dist/helper/ssg/ssg.js +16 -14
  22. package/dist/jsx/dom/index.js +3 -0
  23. package/dist/jsx/hooks/index.js +3 -0
  24. package/dist/jsx/index.js +3 -0
  25. package/dist/middleware/basic-auth/index.js +22 -9
  26. package/dist/middleware/bearer-auth/index.js +4 -2
  27. package/dist/middleware/cache/index.js +22 -3
  28. package/dist/middleware/cors/index.js +1 -1
  29. package/dist/middleware/jwt/index.js +12 -6
  30. package/dist/middleware/method-override/index.js +83 -0
  31. package/dist/middleware/trailing-slash/index.js +25 -0
  32. package/dist/request.js +13 -4
  33. package/dist/test-utils/setup-vitest.js +5 -2
  34. package/dist/types/helper/ssg/ssg.d.ts +3 -1
  35. package/dist/types/helper.d.ts +12 -0
  36. package/dist/types/jsx/dom/index.d.ts +3 -2
  37. package/dist/types/jsx/hooks/index.d.ts +1 -0
  38. package/dist/types/jsx/index.d.ts +3 -2
  39. package/dist/types/middleware/basic-auth/index.d.ts +9 -2
  40. package/dist/types/middleware/bearer-auth/index.d.ts +10 -2
  41. package/dist/types/middleware/cache/index.d.ts +1 -0
  42. package/dist/types/middleware/cors/index.d.ts +2 -1
  43. package/dist/types/middleware/jwt/index.d.ts +4 -3
  44. package/dist/types/middleware/method-override/index.d.ts +36 -0
  45. package/dist/types/middleware/trailing-slash/index.d.ts +13 -0
  46. package/dist/types/utils/jwt/index.d.ts +8 -1
  47. package/dist/types/utils/jwt/jwa.d.ts +16 -0
  48. package/dist/types/utils/jwt/jws.d.ts +4 -0
  49. package/dist/types/utils/jwt/jwt.d.ts +10 -5
  50. package/dist/types/utils/jwt/types.d.ts +30 -4
  51. package/dist/types/utils/jwt/utf8.d.ts +2 -0
  52. package/dist/utils/jwt/index.js +2 -1
  53. package/dist/utils/jwt/jwa.js +20 -0
  54. package/dist/utils/jwt/jws.js +188 -0
  55. package/dist/utils/jwt/jwt.js +24 -53
  56. package/dist/utils/jwt/types.js +19 -7
  57. package/dist/utils/jwt/utf8.js +7 -0
  58. package/dist/validator/validator.js +2 -27
  59. package/package.json +14 -1
@@ -18,6 +18,7 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var ssg_exports = {};
20
20
  __export(ssg_exports, {
21
+ defaultExtensionMap: () => defaultExtensionMap,
21
22
  fetchRoutesContent: () => fetchRoutesContent,
22
23
  saveContentToFile: () => saveContentToFile,
23
24
  toSSG: () => toSSG
@@ -29,8 +30,8 @@ var import_mime = require("../../utils/mime");
29
30
  var import_middleware = require("./middleware");
30
31
  var import_utils2 = require("./utils");
31
32
  const DEFAULT_CONCURRENCY = 2;
32
- const generateFilePath = (routePath, outDir, mimeType) => {
33
- const extension = determineExtension(mimeType);
33
+ const generateFilePath = (routePath, outDir, mimeType, extensionMap) => {
34
+ const extension = determineExtension(mimeType, extensionMap);
34
35
  if (routePath.endsWith(`.${extension}`)) {
35
36
  return (0, import_utils2.joinPaths)(outDir, routePath);
36
37
  }
@@ -56,17 +57,18 @@ const parseResponseContent = async (response) => {
56
57
  );
57
58
  }
58
59
  };
59
- const determineExtension = (mimeType) => {
60
- switch (mimeType) {
61
- case "text/html":
62
- return "html";
63
- case "text/xml":
64
- case "application/xml":
65
- return "xml";
66
- default: {
67
- return (0, import_mime.getExtension)(mimeType) || "html";
68
- }
60
+ const defaultExtensionMap = {
61
+ "text/html": "html",
62
+ "text/xml": "xml",
63
+ "application/xml": "xml",
64
+ "application/yaml": "yaml"
65
+ };
66
+ const determineExtension = (mimeType, userExtensionMap) => {
67
+ const extensionMap = userExtensionMap || defaultExtensionMap;
68
+ if (mimeType in extensionMap) {
69
+ return extensionMap[mimeType];
69
70
  }
71
+ return (0, import_mime.getExtension)(mimeType) || "html";
70
72
  };
71
73
  const fetchRoutesContent = function* (app, beforeRequestHook, afterResponseHook, concurrency) {
72
74
  const baseURL = "http://localhost";
@@ -143,13 +145,13 @@ const isDynamicRoute = (path) => {
143
145
  return path.split("/").some((segment) => segment.startsWith(":") || segment.includes("*"));
144
146
  };
145
147
  const createdDirs = /* @__PURE__ */ new Set();
146
- const saveContentToFile = async (data, fsModule, outDir) => {
148
+ const saveContentToFile = async (data, fsModule, outDir, extensionMap) => {
147
149
  const awaitedData = await data;
148
150
  if (!awaitedData) {
149
151
  return;
150
152
  }
151
153
  const { routePath, content, mimeType } = awaitedData;
152
- const filePath = generateFilePath(routePath, outDir, mimeType);
154
+ const filePath = generateFilePath(routePath, outDir, mimeType, extensionMap);
153
155
  const dirPath = (0, import_utils2.dirname)(filePath);
154
156
  if (!createdDirs.has(dirPath)) {
155
157
  await fsModule.mkdir(dirPath, { recursive: true });
@@ -207,6 +209,7 @@ const toSSG = async (app, fs, options) => {
207
209
  };
208
210
  // Annotate the CommonJS export names for ESM import in node:
209
211
  0 && (module.exports = {
212
+ defaultExtensionMap,
210
213
  fetchRoutesContent,
211
214
  saveContentToFile,
212
215
  toSSG
@@ -36,6 +36,7 @@ __export(dom_exports, {
36
36
  useDebugValue: () => import_hooks.useDebugValue,
37
37
  useDeferredValue: () => import_hooks.useDeferredValue,
38
38
  useEffect: () => import_hooks.useEffect,
39
+ useId: () => import_hooks.useId,
39
40
  useLayoutEffect: () => import_hooks.useLayoutEffect,
40
41
  useMemo: () => import_hooks.useMemo,
41
42
  useReducer: () => import_hooks.useReducer,
@@ -86,6 +87,7 @@ var dom_default = {
86
87
  useMemo: import_hooks.useMemo,
87
88
  useLayoutEffect: import_hooks.useLayoutEffect,
88
89
  useReducer: import_hooks.useReducer,
90
+ useId: import_hooks.useId,
89
91
  useDebugValue: import_hooks.useDebugValue,
90
92
  Suspense: import_components.Suspense,
91
93
  ErrorBoundary: import_components.ErrorBoundary,
@@ -115,6 +117,7 @@ var dom_default = {
115
117
  useDebugValue,
116
118
  useDeferredValue,
117
119
  useEffect,
120
+ useId,
118
121
  useLayoutEffect,
119
122
  useMemo,
120
123
  useReducer,
@@ -26,6 +26,7 @@ __export(hooks_exports, {
26
26
  useDebugValue: () => useDebugValue,
27
27
  useDeferredValue: () => useDeferredValue,
28
28
  useEffect: () => useEffect,
29
+ useId: () => useId,
29
30
  useLayoutEffect: () => useLayoutEffect,
30
31
  useMemo: () => useMemo,
31
32
  useReducer: () => useReducer,
@@ -294,6 +295,8 @@ const useMemo = (factory, deps) => {
294
295
  }
295
296
  return memoArray[hookIndex][0];
296
297
  };
298
+ let idCounter = 0;
299
+ const useId = () => useMemo(() => `:r${(idCounter++).toString(32)}:`, []);
297
300
  const useDebugValue = (_value, _formatter) => {
298
301
  };
299
302
  // Annotate the CommonJS export names for ESM import in node:
@@ -306,6 +309,7 @@ const useDebugValue = (_value, _formatter) => {
306
309
  useDebugValue,
307
310
  useDeferredValue,
308
311
  useEffect,
312
+ useId,
309
313
  useLayoutEffect,
310
314
  useMemo,
311
315
  useReducer,
@@ -37,6 +37,7 @@ __export(jsx_exports, {
37
37
  useDebugValue: () => import_hooks.useDebugValue,
38
38
  useDeferredValue: () => import_hooks.useDeferredValue,
39
39
  useEffect: () => import_hooks.useEffect,
40
+ useId: () => import_hooks.useId,
40
41
  useLayoutEffect: () => import_hooks.useLayoutEffect,
41
42
  useMemo: () => import_hooks.useMemo,
42
43
  useReducer: () => import_hooks.useReducer,
@@ -66,6 +67,7 @@ var jsx_default = {
66
67
  useRef: import_hooks.useRef,
67
68
  useCallback: import_hooks.useCallback,
68
69
  useReducer: import_hooks.useReducer,
70
+ useId: import_hooks.useId,
69
71
  useDebugValue: import_hooks.useDebugValue,
70
72
  use: import_hooks.use,
71
73
  startTransition: import_hooks.startTransition,
@@ -96,6 +98,7 @@ var jsx_default = {
96
98
  useDebugValue,
97
99
  useDeferredValue,
98
100
  useEffect,
101
+ useId,
99
102
  useLayoutEffect,
100
103
  useMemo,
101
104
  useReducer,
@@ -43,25 +43,38 @@ const auth = (req) => {
43
43
  return { username: userPass[1], password: userPass[2] };
44
44
  };
45
45
  const basicAuth = (options, ...users) => {
46
- if (!options) {
47
- throw new Error('basic auth middleware requires options for "username and password"');
46
+ const usernamePasswordInOptions = "username" in options && "password" in options;
47
+ const verifyUserInOptions = "verifyUser" in options;
48
+ if (!(usernamePasswordInOptions || verifyUserInOptions)) {
49
+ throw new Error(
50
+ 'basic auth middleware requires options for "username and password" or "verifyUser"'
51
+ );
48
52
  }
49
53
  if (!options.realm) {
50
54
  options.realm = "Secure Area";
51
55
  }
52
- users.unshift({ username: options.username, password: options.password });
56
+ if (usernamePasswordInOptions) {
57
+ users.unshift({ username: options.username, password: options.password });
58
+ }
53
59
  return async function basicAuth2(ctx, next) {
54
60
  const requestUser = auth(ctx.req);
55
61
  if (requestUser) {
56
- for (const user of users) {
57
- const [usernameEqual, passwordEqual] = await Promise.all([
58
- (0, import_buffer.timingSafeEqual)(user.username, requestUser.username, options.hashFunction),
59
- (0, import_buffer.timingSafeEqual)(user.password, requestUser.password, options.hashFunction)
60
- ]);
61
- if (usernameEqual && passwordEqual) {
62
+ if (verifyUserInOptions) {
63
+ if (await options.verifyUser(requestUser.username, requestUser.password, ctx)) {
62
64
  await next();
63
65
  return;
64
66
  }
67
+ } else {
68
+ for (const user of users) {
69
+ const [usernameEqual, passwordEqual] = await Promise.all([
70
+ (0, import_buffer.timingSafeEqual)(user.username, requestUser.username, options.hashFunction),
71
+ (0, import_buffer.timingSafeEqual)(user.password, requestUser.password, options.hashFunction)
72
+ ]);
73
+ if (usernameEqual && passwordEqual) {
74
+ await next();
75
+ return;
76
+ }
77
+ }
65
78
  }
66
79
  }
67
80
  const res = new Response("Unauthorized", {
@@ -26,7 +26,7 @@ var import_buffer = require("../../utils/buffer");
26
26
  const TOKEN_STRINGS = "[A-Za-z0-9._~+/-]+=*";
27
27
  const PREFIX = "Bearer";
28
28
  const bearerAuth = (options) => {
29
- if (!options.token) {
29
+ if (!("token" in options || "verifyToken" in options)) {
30
30
  throw new Error('bearer auth middleware requires options for "token"');
31
31
  }
32
32
  if (!options.realm) {
@@ -59,7 +59,9 @@ const bearerAuth = (options) => {
59
59
  throw new import_http_exception.HTTPException(400, { res });
60
60
  } else {
61
61
  let equal = false;
62
- if (typeof options.token === "string") {
62
+ if ("verifyToken" in options) {
63
+ equal = await options.verifyToken(match[1], c);
64
+ } else if (typeof options.token === "string") {
63
65
  equal = await (0, import_buffer.timingSafeEqual)(options.token, match[1], options.hashFunction);
64
66
  } else if (Array.isArray(options.token) && options.token.length > 0) {
65
67
  for (const token of options.token) {
@@ -29,11 +29,17 @@ const cache = (options) => {
29
29
  if (options.wait === void 0) {
30
30
  options.wait = false;
31
31
  }
32
- const directives = options.cacheControl?.split(",").map((directive) => directive.toLowerCase());
32
+ const cacheControlDirectives = options.cacheControl?.split(",").map((directive) => directive.toLowerCase());
33
+ const varyDirectives = Array.isArray(options.vary) ? options.vary : options.vary?.split(",").map((directive) => directive.trim());
34
+ if (options.vary?.includes("*")) {
35
+ throw new Error(
36
+ 'Middleware vary configuration cannot include "*", as it disallows effective caching.'
37
+ );
38
+ }
33
39
  const addHeader = (c) => {
34
- if (directives) {
40
+ if (cacheControlDirectives) {
35
41
  const existingDirectives = c.res.headers.get("Cache-Control")?.split(",").map((d) => d.trim().split("=", 1)[0]) ?? [];
36
- for (const directive of directives) {
42
+ for (const directive of cacheControlDirectives) {
37
43
  let [name, value] = directive.trim().split("=", 2);
38
44
  name = name.toLowerCase();
39
45
  if (!existingDirectives.includes(name)) {
@@ -41,6 +47,19 @@ const cache = (options) => {
41
47
  }
42
48
  }
43
49
  }
50
+ if (varyDirectives) {
51
+ const existingDirectives = c.res.headers.get("Vary")?.split(",").map((d) => d.trim()) ?? [];
52
+ const vary = Array.from(
53
+ new Set(
54
+ [...existingDirectives, ...varyDirectives].map((directive) => directive.toLowerCase())
55
+ )
56
+ ).sort();
57
+ if (vary.includes("*")) {
58
+ c.header("Vary", "*");
59
+ } else {
60
+ c.header("Vary", vary.join(", "));
61
+ }
62
+ }
44
63
  };
45
64
  return async function cache2(c, next) {
46
65
  const key = c.req.url;
@@ -45,7 +45,7 @@ const cors = (options) => {
45
45
  function set(key, value) {
46
46
  c.res.headers.set(key, value);
47
47
  }
48
- const allowOrigin = findAllowOrigin(c.req.header("origin") || "");
48
+ const allowOrigin = findAllowOrigin(c.req.header("origin") || "", c);
49
49
  if (allowOrigin) {
50
50
  set("Access-Control-Allow-Origin", allowOrigin);
51
51
  }
@@ -41,11 +41,13 @@ const jwt = (options) => {
41
41
  if (credentials) {
42
42
  const parts = credentials.split(/\s+/);
43
43
  if (parts.length !== 2) {
44
+ const errDescription = "invalid credentials structure";
44
45
  throw new import_http_exception.HTTPException(401, {
46
+ message: errDescription,
45
47
  res: unauthorizedResponse({
46
48
  ctx,
47
49
  error: "invalid_request",
48
- errDescription: "invalid credentials structure"
50
+ errDescription
49
51
  })
50
52
  });
51
53
  } else {
@@ -55,29 +57,33 @@ const jwt = (options) => {
55
57
  token = (0, import_cookie.getCookie)(ctx)[options.cookie];
56
58
  }
57
59
  if (!token) {
60
+ const errDescription = "no authorization included in request";
58
61
  throw new import_http_exception.HTTPException(401, {
62
+ message: errDescription,
59
63
  res: unauthorizedResponse({
60
64
  ctx,
61
65
  error: "invalid_request",
62
- errDescription: "no authorization included in request"
66
+ errDescription
63
67
  })
64
68
  });
65
69
  }
66
70
  let payload;
67
- let msg = "";
71
+ let cause;
68
72
  try {
69
73
  payload = await import_jwt.Jwt.verify(token, options.secret, options.alg);
70
74
  } catch (e) {
71
- msg = `${e}`;
75
+ cause = e;
72
76
  }
73
77
  if (!payload) {
74
78
  throw new import_http_exception.HTTPException(401, {
79
+ message: "Unauthorized",
75
80
  res: unauthorizedResponse({
76
81
  ctx,
77
82
  error: "invalid_token",
78
- statusText: msg,
83
+ statusText: "Unauthorized",
79
84
  errDescription: "token verification failure"
80
- })
85
+ }),
86
+ cause
81
87
  });
82
88
  }
83
89
  ctx.set("jwtPayload", payload);
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var method_override_exports = {};
20
+ __export(method_override_exports, {
21
+ methodOverride: () => methodOverride
22
+ });
23
+ module.exports = __toCommonJS(method_override_exports);
24
+ var import_url = require("url");
25
+ var import_body = require("../../utils/body");
26
+ const DEFAULT_METHOD_FORM_NAME = "_method";
27
+ const methodOverride = (options) => async function methodOverride2(c, next) {
28
+ if (c.req.method === "GET") {
29
+ return await next();
30
+ }
31
+ const app = options.app;
32
+ if (!(options.header || options.query)) {
33
+ const contentType = c.req.header("content-type");
34
+ const methodFormName = options.form || DEFAULT_METHOD_FORM_NAME;
35
+ const clonedRequest = c.req.raw.clone();
36
+ const newRequest = clonedRequest.clone();
37
+ if (contentType?.startsWith("multipart/form-data")) {
38
+ const form = await clonedRequest.formData();
39
+ const method = form.get(methodFormName);
40
+ if (method) {
41
+ const newForm = await newRequest.formData();
42
+ newForm.delete(methodFormName);
43
+ const newHeaders = new Headers(clonedRequest.headers);
44
+ newHeaders.delete("content-type");
45
+ newHeaders.delete("content-length");
46
+ const request = new Request(c.req.url, {
47
+ body: newForm,
48
+ headers: newHeaders,
49
+ method
50
+ });
51
+ return app.fetch(request, c.env, getExecutionCtx(c));
52
+ }
53
+ }
54
+ if (contentType === "application/x-www-form-urlencoded") {
55
+ const params = await (0, import_body.parseBody)(clonedRequest);
56
+ const method = params[methodFormName];
57
+ if (method) {
58
+ delete params[methodFormName];
59
+ const newParams = new import_url.URLSearchParams(params);
60
+ const request = new Request(newRequest, {
61
+ body: newParams,
62
+ method
63
+ });
64
+ return app.fetch(request, c.env, getExecutionCtx(c));
65
+ }
66
+ }
67
+ } else if (options.header) {
68
+ const headerName = options.header;
69
+ const method = c.req.header(headerName);
70
+ if (method) {
71
+ const newHeaders = new Headers(c.req.raw.headers);
72
+ newHeaders.delete(headerName);
73
+ const request = new Request(c.req.raw, {
74
+ headers: newHeaders,
75
+ method
76
+ });
77
+ return app.fetch(request, c.env, getExecutionCtx(c));
78
+ }
79
+ } else if (options.query) {
80
+ const queryName = options.query;
81
+ const method = c.req.query(queryName);
82
+ if (method) {
83
+ const url = new URL(c.req.url);
84
+ url.searchParams.delete(queryName);
85
+ const request = new Request(url.toString(), {
86
+ body: c.req.raw.body,
87
+ headers: c.req.raw.headers,
88
+ method
89
+ });
90
+ return app.fetch(request, c.env, getExecutionCtx(c));
91
+ }
92
+ }
93
+ await next();
94
+ };
95
+ const getExecutionCtx = (c) => {
96
+ let executionCtx;
97
+ try {
98
+ executionCtx = c.executionCtx;
99
+ } catch {
100
+ }
101
+ return executionCtx;
102
+ };
103
+ // Annotate the CommonJS export names for ESM import in node:
104
+ 0 && (module.exports = {
105
+ methodOverride
106
+ });
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var trailing_slash_exports = {};
20
+ __export(trailing_slash_exports, {
21
+ appendTrailingSlash: () => appendTrailingSlash,
22
+ trimTrailingSlash: () => trimTrailingSlash
23
+ });
24
+ module.exports = __toCommonJS(trailing_slash_exports);
25
+ const trimTrailingSlash = () => {
26
+ return async function trimTrailingSlash2(c, next) {
27
+ await next();
28
+ if (c.res.status === 404 && c.req.method === "GET" && c.req.path !== "/" && c.req.path[c.req.path.length - 1] === "/") {
29
+ const url = new URL(c.req.url);
30
+ url.pathname = url.pathname.substring(0, url.pathname.length - 1);
31
+ c.res = c.redirect(url.toString(), 301);
32
+ }
33
+ };
34
+ };
35
+ const appendTrailingSlash = () => {
36
+ return async function appendTrailingSlash2(c, next) {
37
+ await next();
38
+ if (c.res.status === 404 && c.req.method === "GET" && c.req.path[c.req.path.length - 1] !== "/") {
39
+ const url = new URL(c.req.url);
40
+ url.pathname += "/";
41
+ c.res = c.redirect(url.toString(), 301);
42
+ }
43
+ };
44
+ };
45
+ // Annotate the CommonJS export names for ESM import in node:
46
+ 0 && (module.exports = {
47
+ appendTrailingSlash,
48
+ trimTrailingSlash
49
+ });
@@ -88,10 +88,19 @@ class HonoRequest {
88
88
  if (cachedBody) {
89
89
  return cachedBody;
90
90
  }
91
- if (bodyCache.arrayBuffer) {
92
- return (async () => {
93
- return await new Response(bodyCache.arrayBuffer)[key]();
94
- })();
91
+ if (!bodyCache[key]) {
92
+ for (const keyOfBodyCache of Object.keys(bodyCache)) {
93
+ if (keyOfBodyCache === "parsedBody") {
94
+ continue;
95
+ }
96
+ return (async () => {
97
+ let body = await bodyCache[keyOfBodyCache];
98
+ if (keyOfBodyCache === "json") {
99
+ body = JSON.stringify(body);
100
+ }
101
+ return await new Response(body)[key]();
102
+ })();
103
+ }
95
104
  }
96
105
  return bodyCache[key] = raw[key]();
97
106
  };
@@ -17,9 +17,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
17
17
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
18
18
  mod
19
19
  ));
20
- var import_node_crypto = __toESM(require("node:crypto"), 1);
20
+ var nodeCrypto = __toESM(require("node:crypto"), 1);
21
21
  var import_vitest = require("vitest");
22
- import_vitest.vi.stubGlobal("crypto", import_node_crypto.default);
22
+ if (!globalThis.crypto) {
23
+ import_vitest.vi.stubGlobal("crypto", nodeCrypto);
24
+ import_vitest.vi.stubGlobal("CryptoKey", nodeCrypto.webcrypto.CryptoKey);
25
+ }
23
26
  class MockCache {
24
27
  name;
25
28
  store;
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,17 +15,14 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
- mod
23
- ));
24
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
19
  var jwt_exports = {};
26
20
  __export(jwt_exports, {
27
21
  Jwt: () => Jwt
28
22
  });
29
23
  module.exports = __toCommonJS(jwt_exports);
30
- var Jwt = __toESM(require("./jwt"), 1);
24
+ var import_jwt = require("./jwt");
25
+ const Jwt = { sign: import_jwt.sign, verify: import_jwt.verify, decode: import_jwt.decode };
31
26
  // Annotate the CommonJS export names for ESM import in node:
32
27
  0 && (module.exports = {
33
28
  Jwt
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var jwa_exports = {};
20
+ __export(jwa_exports, {
21
+ AlgorithmTypes: () => AlgorithmTypes
22
+ });
23
+ module.exports = __toCommonJS(jwa_exports);
24
+ var AlgorithmTypes = /* @__PURE__ */ ((AlgorithmTypes2) => {
25
+ AlgorithmTypes2["HS256"] = "HS256";
26
+ AlgorithmTypes2["HS384"] = "HS384";
27
+ AlgorithmTypes2["HS512"] = "HS512";
28
+ AlgorithmTypes2["RS256"] = "RS256";
29
+ AlgorithmTypes2["RS384"] = "RS384";
30
+ AlgorithmTypes2["RS512"] = "RS512";
31
+ AlgorithmTypes2["PS256"] = "PS256";
32
+ AlgorithmTypes2["PS384"] = "PS384";
33
+ AlgorithmTypes2["PS512"] = "PS512";
34
+ AlgorithmTypes2["ES256"] = "ES256";
35
+ AlgorithmTypes2["ES384"] = "ES384";
36
+ AlgorithmTypes2["ES512"] = "ES512";
37
+ AlgorithmTypes2["EdDSA"] = "EdDSA";
38
+ return AlgorithmTypes2;
39
+ })(AlgorithmTypes || {});
40
+ // Annotate the CommonJS export names for ESM import in node:
41
+ 0 && (module.exports = {
42
+ AlgorithmTypes
43
+ });