hono 4.6.8 → 4.6.10

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 (96) hide show
  1. package/dist/adapter/cloudflare-workers/websocket.js +34 -39
  2. package/dist/adapter/deno/serve-static.js +5 -1
  3. package/dist/adapter/lambda-edge/handler.js +1 -1
  4. package/dist/cjs/adapter/cloudflare-workers/websocket.js +34 -39
  5. package/dist/cjs/adapter/deno/serve-static.js +5 -1
  6. package/dist/cjs/adapter/lambda-edge/handler.js +1 -1
  7. package/dist/cjs/client/client.js +3 -3
  8. package/dist/cjs/compose.js +4 -3
  9. package/dist/cjs/context.js +12 -9
  10. package/dist/cjs/helper/html/index.js +1 -1
  11. package/dist/cjs/helper/ssg/ssg.js +2 -2
  12. package/dist/cjs/helper/ssg/utils.js +2 -2
  13. package/dist/cjs/hono-base.js +38 -41
  14. package/dist/cjs/jsx/base.js +8 -3
  15. package/dist/cjs/jsx/constants.js +3 -0
  16. package/dist/cjs/jsx/dom/index.js +8 -2
  17. package/dist/cjs/jsx/dom/render.js +15 -12
  18. package/dist/cjs/middleware/combine/index.js +15 -9
  19. package/dist/cjs/middleware/etag/digest.js +59 -0
  20. package/dist/cjs/middleware/etag/index.js +5 -2
  21. package/dist/cjs/middleware/ip-restriction/index.js +3 -3
  22. package/dist/cjs/middleware/jsx-renderer/index.js +2 -1
  23. package/dist/cjs/middleware/logger/index.js +13 -11
  24. package/dist/cjs/middleware/timing/timing.js +5 -7
  25. package/dist/cjs/request.js +15 -14
  26. package/dist/cjs/router/linear-router/router.js +4 -4
  27. package/dist/cjs/router/pattern-router/router.js +4 -4
  28. package/dist/cjs/router/reg-exp-router/node.js +18 -18
  29. package/dist/cjs/router/reg-exp-router/router.js +13 -12
  30. package/dist/cjs/router/reg-exp-router/trie.js +6 -6
  31. package/dist/cjs/router/smart-router/router.js +12 -11
  32. package/dist/cjs/router/trie-router/node.js +53 -47
  33. package/dist/cjs/router/trie-router/router.js +5 -5
  34. package/dist/cjs/utils/color.js +1 -1
  35. package/dist/cjs/utils/cookie.js +13 -6
  36. package/dist/cjs/utils/crypto.js +0 -9
  37. package/dist/cjs/utils/jwt/jwt.js +1 -1
  38. package/dist/cjs/utils/mime.js +2 -1
  39. package/dist/cjs/utils/url.js +9 -6
  40. package/dist/client/client.js +3 -3
  41. package/dist/compose.js +4 -3
  42. package/dist/context.js +12 -9
  43. package/dist/helper/html/index.js +1 -1
  44. package/dist/helper/ssg/ssg.js +2 -2
  45. package/dist/helper/ssg/utils.js +2 -2
  46. package/dist/hono-base.js +38 -41
  47. package/dist/jsx/base.js +7 -3
  48. package/dist/jsx/constants.js +2 -0
  49. package/dist/jsx/dom/index.js +7 -1
  50. package/dist/jsx/dom/render.js +22 -13
  51. package/dist/middleware/combine/index.js +15 -9
  52. package/dist/middleware/etag/digest.js +36 -0
  53. package/dist/middleware/etag/index.js +5 -2
  54. package/dist/middleware/ip-restriction/index.js +3 -3
  55. package/dist/middleware/jsx-renderer/index.js +2 -1
  56. package/dist/middleware/logger/index.js +13 -11
  57. package/dist/middleware/timing/timing.js +5 -7
  58. package/dist/request.js +16 -15
  59. package/dist/router/linear-router/router.js +4 -4
  60. package/dist/router/pattern-router/router.js +4 -4
  61. package/dist/router/reg-exp-router/node.js +18 -18
  62. package/dist/router/reg-exp-router/router.js +13 -12
  63. package/dist/router/reg-exp-router/trie.js +6 -6
  64. package/dist/router/smart-router/router.js +12 -11
  65. package/dist/router/trie-router/node.js +53 -47
  66. package/dist/router/trie-router/router.js +5 -5
  67. package/dist/types/adapter/cloudflare-workers/websocket.d.ts +2 -2
  68. package/dist/types/adapter/deno/websocket.d.ts +1 -20
  69. package/dist/types/adapter/service-worker/index.d.ts +1 -1
  70. package/dist/types/compose.d.ts +5 -2
  71. package/dist/types/context.d.ts +1 -1
  72. package/dist/types/helper/websocket/index.d.ts +1 -1
  73. package/dist/types/hono-base.d.ts +1 -1
  74. package/dist/types/jsx/base.d.ts +5 -0
  75. package/dist/types/jsx/constants.d.ts +1 -0
  76. package/dist/types/jsx/dom/index.d.ts +6 -5
  77. package/dist/types/jsx/dom/render.d.ts +1 -0
  78. package/dist/types/middleware/etag/digest.d.ts +1 -0
  79. package/dist/types/router/linear-router/router.d.ts +0 -5
  80. package/dist/types/router/reg-exp-router/node.d.ts +0 -3
  81. package/dist/types/router/reg-exp-router/router.d.ts +0 -7
  82. package/dist/types/router/reg-exp-router/trie.d.ts +1 -4
  83. package/dist/types/router/smart-router/router.d.ts +3 -7
  84. package/dist/types/router/trie-router/node.d.ts +0 -12
  85. package/dist/types/router/trie-router/router.d.ts +0 -2
  86. package/dist/types/utils/body.d.ts +2 -2
  87. package/dist/types/utils/crypto.d.ts +2 -1
  88. package/dist/types/utils/mime.d.ts +58 -1
  89. package/dist/types/utils/url.d.ts +3 -0
  90. package/dist/utils/color.js +1 -1
  91. package/dist/utils/cookie.js +13 -6
  92. package/dist/utils/crypto.js +0 -9
  93. package/dist/utils/jwt/jwt.js +1 -1
  94. package/dist/utils/mime.js +2 -1
  95. package/dist/utils/url.js +7 -5
  96. package/package.json +20 -12
@@ -1,13 +1,9 @@
1
1
  import type { Result, Router } from '../../router';
2
2
  export declare class SmartRouter<T> implements Router<T> {
3
3
  name: string;
4
- routers: Router<T>[];
5
- routes?: [
6
- string,
7
- string,
8
- T
9
- ][];
10
- constructor(init: Pick<SmartRouter<T>, "routers">);
4
+ constructor(init: {
5
+ routers: Router<T>[];
6
+ });
11
7
  add(method: string, path: string, handler: T): void;
12
8
  match(method: string, path: string): Result<T>;
13
9
  get activeRouter(): Router<T>;
@@ -1,16 +1,5 @@
1
1
  import type { Params } from '../../router';
2
- import type { Pattern } from '../../utils/url';
3
- type HandlerSet<T> = {
4
- handler: T;
5
- possibleKeys: string[];
6
- score: number;
7
- };
8
2
  export declare class Node<T> {
9
- methods: Record<string, HandlerSet<T>>[];
10
- children: Record<string, Node<T>>;
11
- patterns: Pattern[];
12
- order: number;
13
- params: Record<string, string>;
14
3
  constructor(method?: string, handler?: T, children?: Record<string, Node<T>>);
15
4
  insert(method: string, path: string, handler: T): Node<T>;
16
5
  search(method: string, path: string): [
@@ -20,4 +9,3 @@ export declare class Node<T> {
20
9
  ][]
21
10
  ];
22
11
  }
23
- export {};
@@ -1,8 +1,6 @@
1
1
  import type { Result, Router } from '../../router';
2
- import { Node } from './node';
3
2
  export declare class TrieRouter<T> implements Router<T> {
4
3
  name: string;
5
- node: Node<T>;
6
4
  constructor();
7
5
  add(method: string, path: string, handler: T): void;
8
6
  match(method: string, path: string): Result<T>;
@@ -5,10 +5,10 @@
5
5
  import { HonoRequest } from '../request';
6
6
  type BodyDataValueDot = {
7
7
  [x: string]: string | File | BodyDataValueDot;
8
- } & {};
8
+ };
9
9
  type BodyDataValueDotAll = {
10
10
  [x: string]: string | File | (string | File)[] | BodyDataValueDotAll;
11
- } & {};
11
+ };
12
12
  type SimplifyBodyData<T> = {
13
13
  [K in keyof T]: string | File | (string | File)[] | BodyDataValueDotAll extends T[K] ? string | File | (string | File)[] | BodyDataValueDotAll : string | File | BodyDataValueDot extends T[K] ? string | File | BodyDataValueDot : string | File | (string | File)[] extends T[K] ? string | File | (string | File)[] : string | File;
14
14
  } & {};
@@ -2,11 +2,12 @@
2
2
  * @module
3
3
  * Crypto utility.
4
4
  */
5
+ import type { JSONValue } from './types';
5
6
  type Algorithm = {
6
7
  name: string;
7
8
  alias: string;
8
9
  };
9
- type Data = string | boolean | number | object | ArrayBufferView | ArrayBuffer | ReadableStream;
10
+ type Data = string | boolean | number | JSONValue | ArrayBufferView | ArrayBuffer;
10
11
  export declare const sha256: (data: Data) => Promise<string | null>;
11
12
  export declare const sha1: (data: Data) => Promise<string | null>;
12
13
  export declare const md5: (data: Data) => Promise<string | null>;
@@ -8,5 +8,62 @@ export { baseMimes as mimes };
8
8
  /**
9
9
  * Union types for BaseMime
10
10
  */
11
- export type BaseMime = "audio/aac" | "video/x-msvideo" | "image/avif" | "video/av1" | "application/octet-stream" | "image/bmp" | "text/css" | "text/csv" | "application/vnd.ms-fontobject" | "application/epub+zip" | "image/gif" | "application/gzip" | "text/html" | "image/x-icon" | "text/calendar" | "image/jpeg" | "text/javascript" | "application/json" | "application/ld+json" | "audio/x-midi" | "audio/mpeg" | "video/mp4" | "video/mpeg" | "audio/ogg" | "video/ogg" | "application/ogg" | "audio/opus" | "font/otf" | "application/pdf" | "image/png" | "application/rtf" | "image/svg+xml" | "image/tiff" | "video/mp2t" | "font/ttf" | "text/plain" | "application/wasm" | "video/webm" | "audio/webm" | "image/webp" | "font/woff" | "font/woff2" | "application/xhtml+xml" | "application/xml" | "application/zip" | "video/3gpp" | "video/3gpp2" | "model/gltf+json" | "model/gltf-binary";
11
+ export type BaseMime = (typeof _baseMimes)[keyof typeof _baseMimes];
12
+ declare const _baseMimes: {
13
+ readonly aac: "audio/aac";
14
+ readonly avi: "video/x-msvideo";
15
+ readonly avif: "image/avif";
16
+ readonly av1: "video/av1";
17
+ readonly bin: "application/octet-stream";
18
+ readonly bmp: "image/bmp";
19
+ readonly css: "text/css";
20
+ readonly csv: "text/csv";
21
+ readonly eot: "application/vnd.ms-fontobject";
22
+ readonly epub: "application/epub+zip";
23
+ readonly gif: "image/gif";
24
+ readonly gz: "application/gzip";
25
+ readonly htm: "text/html";
26
+ readonly html: "text/html";
27
+ readonly ico: "image/x-icon";
28
+ readonly ics: "text/calendar";
29
+ readonly jpeg: "image/jpeg";
30
+ readonly jpg: "image/jpeg";
31
+ readonly js: "text/javascript";
32
+ readonly json: "application/json";
33
+ readonly jsonld: "application/ld+json";
34
+ readonly map: "application/json";
35
+ readonly mid: "audio/x-midi";
36
+ readonly midi: "audio/x-midi";
37
+ readonly mjs: "text/javascript";
38
+ readonly mp3: "audio/mpeg";
39
+ readonly mp4: "video/mp4";
40
+ readonly mpeg: "video/mpeg";
41
+ readonly oga: "audio/ogg";
42
+ readonly ogv: "video/ogg";
43
+ readonly ogx: "application/ogg";
44
+ readonly opus: "audio/opus";
45
+ readonly otf: "font/otf";
46
+ readonly pdf: "application/pdf";
47
+ readonly png: "image/png";
48
+ readonly rtf: "application/rtf";
49
+ readonly svg: "image/svg+xml";
50
+ readonly tif: "image/tiff";
51
+ readonly tiff: "image/tiff";
52
+ readonly ts: "video/mp2t";
53
+ readonly ttf: "font/ttf";
54
+ readonly txt: "text/plain";
55
+ readonly wasm: "application/wasm";
56
+ readonly webm: "video/webm";
57
+ readonly weba: "audio/webm";
58
+ readonly webp: "image/webp";
59
+ readonly woff: "font/woff";
60
+ readonly woff2: "font/woff2";
61
+ readonly xhtml: "application/xhtml+xml";
62
+ readonly xml: "application/xml";
63
+ readonly zip: "application/zip";
64
+ readonly "3gp": "video/3gpp";
65
+ readonly "3g2": "video/3gpp2";
66
+ readonly gltf: "model/gltf+json";
67
+ readonly glb: "model/gltf-binary";
68
+ };
12
69
  declare const baseMimes: Record<string, BaseMime>;
@@ -10,6 +10,8 @@ export type Pattern = readonly [
10
10
  export declare const splitPath: (path: string) => string[];
11
11
  export declare const splitRoutingPath: (routePath: string) => string[];
12
12
  export declare const getPattern: (label: string) => Pattern | null;
13
+ type Decoder = (str: string) => string;
14
+ export declare const tryDecode: (str: string, decoder: Decoder) => string;
13
15
  export declare const getPath: (request: Request) => string;
14
16
  export declare const getQueryStrings: (url: string) => string;
15
17
  export declare const getPathNoStrict: (request: Request) => string;
@@ -18,3 +20,4 @@ export declare const checkOptionalParameter: (path: string) => string[] | null;
18
20
  export declare const getQueryParam: (url: string, key?: string) => string | undefined | Record<string, string>;
19
21
  export declare const getQueryParams: (url: string, key?: string) => string[] | undefined | Record<string, string[]>;
20
22
  export declare const decodeURIComponent_: typeof decodeURIComponent;
23
+ export {};
@@ -1,7 +1,7 @@
1
1
  // src/utils/color.ts
2
2
  function getColorEnabled() {
3
3
  const { process, Deno } = globalThis;
4
- const isNoColor = typeof Deno?.noColor === "boolean" ? Deno.noColor : typeof process !== "undefined" ? "NO_COLOR" in process?.env : false;
4
+ const isNoColor = typeof Deno?.noColor === "boolean" ? Deno.noColor : process !== void 0 ? "NO_COLOR" in process?.env : false;
5
5
  return !isNoColor;
6
6
  }
7
7
  export {
@@ -25,16 +25,20 @@ var verifySignature = async (base64Signature, value, secret) => {
25
25
  var validCookieNameRegEx = /^[\w!#$%&'*.^`|~+-]+$/;
26
26
  var validCookieValueRegEx = /^[ !#-:<-[\]-~]*$/;
27
27
  var parse = (cookie, name) => {
28
+ if (name && cookie.indexOf(name) === -1) {
29
+ return {};
30
+ }
28
31
  const pairs = cookie.trim().split(";");
29
- return pairs.reduce((parsedCookie, pairStr) => {
32
+ const parsedCookie = {};
33
+ for (let pairStr of pairs) {
30
34
  pairStr = pairStr.trim();
31
35
  const valueStartPos = pairStr.indexOf("=");
32
36
  if (valueStartPos === -1) {
33
- return parsedCookie;
37
+ continue;
34
38
  }
35
39
  const cookieName = pairStr.substring(0, valueStartPos).trim();
36
40
  if (name && name !== cookieName || !validCookieNameRegEx.test(cookieName)) {
37
- return parsedCookie;
41
+ continue;
38
42
  }
39
43
  let cookieValue = pairStr.substring(valueStartPos + 1).trim();
40
44
  if (cookieValue.startsWith('"') && cookieValue.endsWith('"')) {
@@ -42,9 +46,12 @@ var parse = (cookie, name) => {
42
46
  }
43
47
  if (validCookieValueRegEx.test(cookieValue)) {
44
48
  parsedCookie[cookieName] = decodeURIComponent_(cookieValue);
49
+ if (name) {
50
+ break;
51
+ }
45
52
  }
46
- return parsedCookie;
47
- }, {});
53
+ }
54
+ return parsedCookie;
48
55
  };
49
56
  var parseSigned = async (cookie, secret, name) => {
50
57
  const parsedCookie = {};
@@ -86,7 +93,7 @@ var _serialize = (name, value, opt = {}) => {
86
93
  "Cookies Max-Age SHOULD NOT be greater than 400 days (34560000 seconds) in duration."
87
94
  );
88
95
  }
89
- cookie += `; Max-Age=${Math.floor(opt.maxAge)}`;
96
+ cookie += `; Max-Age=${opt.maxAge | 0}`;
90
97
  }
91
98
  if (opt.domain && opt.prefix !== "host") {
92
99
  cookie += `; Domain=${opt.domain}`;
@@ -16,15 +16,6 @@ var md5 = async (data) => {
16
16
  };
17
17
  var createHash = async (data, algorithm) => {
18
18
  let sourceBuffer;
19
- if (data instanceof ReadableStream) {
20
- let body = "";
21
- const reader = data.getReader();
22
- await reader?.read().then(async (chuck) => {
23
- const value = await createHash(chuck.value || "", algorithm);
24
- body += value;
25
- });
26
- return body;
27
- }
28
19
  if (ArrayBuffer.isView(data) || data instanceof ArrayBuffer) {
29
20
  sourceBuffer = data;
30
21
  } else {
@@ -38,7 +38,7 @@ var verify = async (token, publicKey, alg = "HS256") => {
38
38
  if (!isTokenHeader(header)) {
39
39
  throw new JwtHeaderInvalid(header);
40
40
  }
41
- const now = Math.floor(Date.now() / 1e3);
41
+ const now = Date.now() / 1e3 | 0;
42
42
  if (payload.nbf && payload.nbf > now) {
43
43
  throw new JwtTokenNotBefore(token);
44
44
  }
@@ -18,7 +18,7 @@ var getExtension = (mimeType) => {
18
18
  }
19
19
  }
20
20
  };
21
- var baseMimes = {
21
+ var _baseMimes = {
22
22
  aac: "audio/aac",
23
23
  avi: "video/x-msvideo",
24
24
  avif: "image/avif",
@@ -75,6 +75,7 @@ var baseMimes = {
75
75
  gltf: "model/gltf+json",
76
76
  glb: "model/gltf-binary"
77
77
  };
78
+ var baseMimes = _baseMimes;
78
79
  export {
79
80
  getExtension,
80
81
  getMimeType,
package/dist/utils/url.js CHANGED
@@ -50,19 +50,20 @@ var getPattern = (label) => {
50
50
  }
51
51
  return null;
52
52
  };
53
- var tryDecodeURI = (str) => {
53
+ var tryDecode = (str, decoder) => {
54
54
  try {
55
- return decodeURI(str);
55
+ return decoder(str);
56
56
  } catch {
57
57
  return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match) => {
58
58
  try {
59
- return decodeURI(match);
59
+ return decoder(match);
60
60
  } catch {
61
61
  return match;
62
62
  }
63
63
  });
64
64
  }
65
65
  };
66
+ var tryDecodeURI = (str) => tryDecode(str, decodeURI);
66
67
  var getPath = (request) => {
67
68
  const url = request.url;
68
69
  const start = url.indexOf("/", 8);
@@ -143,7 +144,7 @@ var _decodeURI = (value) => {
143
144
  if (value.indexOf("+") !== -1) {
144
145
  value = value.replace(/\+/g, " ");
145
146
  }
146
- return /%/.test(value) ? decodeURIComponent_(value) : value;
147
+ return value.indexOf("%") !== -1 ? decodeURIComponent_(value) : value;
147
148
  };
148
149
  var _getQueryParam = (url, key, multiple) => {
149
150
  let encoded;
@@ -225,5 +226,6 @@ export {
225
226
  getQueryStrings,
226
227
  mergePath,
227
228
  splitPath,
228
- splitRoutingPath
229
+ splitRoutingPath,
230
+ tryDecode
229
231
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "4.6.8",
3
+ "version": "4.6.10",
4
4
  "description": "Web framework built on Web Standards",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",
@@ -39,6 +39,11 @@
39
39
  "import": "./dist/index.js",
40
40
  "require": "./dist/cjs/index.js"
41
41
  },
42
+ "./request": {
43
+ "types": "./dist/types/request.d.ts",
44
+ "import": "./dist/request.js",
45
+ "require": "./dist/cjs/request.js"
46
+ },
42
47
  "./types": {
43
48
  "types": "./dist/types/types.d.ts",
44
49
  "import": "./dist/types.js",
@@ -387,6 +392,9 @@
387
392
  },
388
393
  "typesVersions": {
389
394
  "*": {
395
+ "request": [
396
+ "./dist/types/request"
397
+ ],
390
398
  "types": [
391
399
  "./dist/types/types"
392
400
  ],
@@ -619,29 +627,29 @@
619
627
  ],
620
628
  "devDependencies": {
621
629
  "@hono/eslint-config": "^1.0.2",
622
- "@hono/node-server": "^1.8.2",
623
- "@types/glob": "^8.0.0",
624
- "@types/jsdom": "^21.1.4",
630
+ "@hono/node-server": "^1.13.5",
631
+ "@types/glob": "^8.1.0",
632
+ "@types/jsdom": "^21.1.7",
625
633
  "@types/node": "20.11.4",
626
- "@types/supertest": "^2.0.12",
634
+ "@types/supertest": "^2.0.16",
627
635
  "@vitest/coverage-v8": "^2.0.5",
628
636
  "arg": "^5.0.2",
629
- "bun-types": "^1.1.30",
630
- "esbuild": "^0.15.12",
637
+ "bun-types": "^1.1.34",
638
+ "esbuild": "^0.15.18",
631
639
  "eslint": "^9.10.0",
632
640
  "glob": "^11.0.0",
633
641
  "jsdom": "^22.1.0",
634
- "msw": "^2.3.0",
642
+ "msw": "^2.6.0",
635
643
  "np": "7.7.0",
636
644
  "prettier": "^2.6.2",
637
- "publint": "^0.1.8",
638
- "supertest": "^6.3.3",
645
+ "publint": "^0.1.16",
646
+ "supertest": "^6.3.4",
639
647
  "typescript": "^5.3.3",
640
648
  "vite-plugin-fastly-js-compute": "^0.4.2",
641
649
  "vitest": "^2.0.5",
642
650
  "wrangler": "3.58.0",
643
- "ws": "^8.17.0",
644
- "zod": "^3.20.2"
651
+ "ws": "^8.18.0",
652
+ "zod": "^3.23.8"
645
653
  },
646
654
  "engines": {
647
655
  "node": ">=16.9.0"