hono 4.6.8 → 4.6.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 (77) hide show
  1. package/dist/adapter/cloudflare-workers/websocket.js +34 -39
  2. package/dist/adapter/deno/serve-static.js +2 -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 +2 -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 +29 -32
  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/etag/digest.js +59 -0
  19. package/dist/cjs/middleware/etag/index.js +5 -2
  20. package/dist/cjs/middleware/ip-restriction/index.js +3 -3
  21. package/dist/cjs/middleware/jsx-renderer/index.js +2 -1
  22. package/dist/cjs/middleware/logger/index.js +13 -11
  23. package/dist/cjs/middleware/timing/timing.js +5 -7
  24. package/dist/cjs/request.js +15 -14
  25. package/dist/cjs/router/pattern-router/router.js +4 -4
  26. package/dist/cjs/router/reg-exp-router/router.js +5 -5
  27. package/dist/cjs/router/reg-exp-router/trie.js +2 -2
  28. package/dist/cjs/router/trie-router/node.js +9 -7
  29. package/dist/cjs/utils/color.js +1 -1
  30. package/dist/cjs/utils/cookie.js +13 -6
  31. package/dist/cjs/utils/crypto.js +0 -9
  32. package/dist/cjs/utils/jwt/jwt.js +1 -1
  33. package/dist/cjs/utils/mime.js +2 -1
  34. package/dist/cjs/utils/url.js +9 -6
  35. package/dist/client/client.js +3 -3
  36. package/dist/compose.js +4 -3
  37. package/dist/context.js +12 -9
  38. package/dist/helper/html/index.js +1 -1
  39. package/dist/helper/ssg/ssg.js +2 -2
  40. package/dist/helper/ssg/utils.js +2 -2
  41. package/dist/hono-base.js +29 -32
  42. package/dist/jsx/base.js +7 -3
  43. package/dist/jsx/constants.js +2 -0
  44. package/dist/jsx/dom/index.js +7 -1
  45. package/dist/jsx/dom/render.js +22 -13
  46. package/dist/middleware/etag/digest.js +36 -0
  47. package/dist/middleware/etag/index.js +5 -2
  48. package/dist/middleware/ip-restriction/index.js +3 -3
  49. package/dist/middleware/jsx-renderer/index.js +2 -1
  50. package/dist/middleware/logger/index.js +13 -11
  51. package/dist/middleware/timing/timing.js +5 -7
  52. package/dist/request.js +16 -15
  53. package/dist/router/pattern-router/router.js +4 -4
  54. package/dist/router/reg-exp-router/router.js +5 -5
  55. package/dist/router/reg-exp-router/trie.js +2 -2
  56. package/dist/router/trie-router/node.js +9 -7
  57. package/dist/types/adapter/cloudflare-workers/websocket.d.ts +2 -2
  58. package/dist/types/adapter/deno/websocket.d.ts +1 -20
  59. package/dist/types/context.d.ts +1 -1
  60. package/dist/types/helper/websocket/index.d.ts +1 -1
  61. package/dist/types/hono-base.d.ts +1 -1
  62. package/dist/types/jsx/base.d.ts +5 -0
  63. package/dist/types/jsx/constants.d.ts +1 -0
  64. package/dist/types/jsx/dom/index.d.ts +6 -5
  65. package/dist/types/jsx/dom/render.d.ts +1 -0
  66. package/dist/types/middleware/etag/digest.d.ts +1 -0
  67. package/dist/types/utils/body.d.ts +2 -2
  68. package/dist/types/utils/crypto.d.ts +2 -1
  69. package/dist/types/utils/mime.d.ts +58 -1
  70. package/dist/types/utils/url.d.ts +3 -0
  71. package/dist/utils/color.js +1 -1
  72. package/dist/utils/cookie.js +13 -6
  73. package/dist/utils/crypto.js +0 -9
  74. package/dist/utils/jwt/jwt.js +1 -1
  75. package/dist/utils/mime.js +2 -1
  76. package/dist/utils/url.js +7 -5
  77. package/package.json +1 -1
@@ -155,7 +155,7 @@ var RegExpRouter = class {
155
155
  }
156
156
  match(method, path) {
157
157
  clearWildcardRegExpCache();
158
- const matchers = this.buildAllMatchers();
158
+ const matchers = this.#buildAllMatchers();
159
159
  this.match = (method2, path2) => {
160
160
  const matcher = matchers[method2] || matchers[METHOD_NAME_ALL];
161
161
  const staticMatch = matcher[2][path2];
@@ -171,15 +171,15 @@ var RegExpRouter = class {
171
171
  };
172
172
  return this.match(method, path);
173
173
  }
174
- buildAllMatchers() {
174
+ #buildAllMatchers() {
175
175
  const matchers = /* @__PURE__ */ Object.create(null);
176
- [...Object.keys(this.routes), ...Object.keys(this.middleware)].forEach((method) => {
177
- matchers[method] ||= this.buildMatcher(method);
176
+ Object.keys(this.routes).concat(Object.keys(this.middleware)).forEach((method) => {
177
+ matchers[method] ||= this.#buildMatcher(method);
178
178
  });
179
179
  this.middleware = this.routes = void 0;
180
180
  return matchers;
181
181
  }
182
- buildMatcher(method) {
182
+ #buildMatcher(method) {
183
183
  const routes = [];
184
184
  let hasOwnRoute = method === METHOD_NAME_ALL;
185
185
  [this.middleware, this.routes].forEach((r) => {
@@ -41,11 +41,11 @@ var Trie = class {
41
41
  const indexReplacementMap = [];
42
42
  const paramReplacementMap = [];
43
43
  regexp = regexp.replace(/#(\d+)|@(\d+)|\.\*\$/g, (_, handlerIndex, paramIndex) => {
44
- if (typeof handlerIndex !== "undefined") {
44
+ if (handlerIndex !== void 0) {
45
45
  indexReplacementMap[++captureIndex] = Number(handlerIndex);
46
46
  return "$()";
47
47
  }
48
- if (typeof paramIndex !== "undefined") {
48
+ if (paramIndex !== void 0) {
49
49
  paramReplacementMap[Number(paramIndex)] = ++captureIndex;
50
50
  return "";
51
51
  }
@@ -53,7 +53,7 @@ var Node = class {
53
53
  curNode.methods.push(m);
54
54
  return curNode;
55
55
  }
56
- gHSets(node, method, nodeParams, params) {
56
+ #gHSets(node, method, nodeParams, params) {
57
57
  const handlerSets = [];
58
58
  for (let i = 0, len = node.methods.length; i < len; i++) {
59
59
  const m = node.methods[i];
@@ -90,10 +90,10 @@ var Node = class {
90
90
  if (isLast) {
91
91
  if (nextNode.children["*"]) {
92
92
  handlerSets.push(
93
- ...this.gHSets(nextNode.children["*"], method, node.params, /* @__PURE__ */ Object.create(null))
93
+ ...this.#gHSets(nextNode.children["*"], method, node.params, /* @__PURE__ */ Object.create(null))
94
94
  );
95
95
  }
96
- handlerSets.push(...this.gHSets(nextNode, method, node.params, /* @__PURE__ */ Object.create(null)));
96
+ handlerSets.push(...this.#gHSets(nextNode, method, node.params, /* @__PURE__ */ Object.create(null)));
97
97
  } else {
98
98
  tempNodes.push(nextNode);
99
99
  }
@@ -104,7 +104,7 @@ var Node = class {
104
104
  if (pattern === "*") {
105
105
  const astNode = node.children["*"];
106
106
  if (astNode) {
107
- handlerSets.push(...this.gHSets(astNode, method, node.params, /* @__PURE__ */ Object.create(null)));
107
+ handlerSets.push(...this.#gHSets(astNode, method, node.params, /* @__PURE__ */ Object.create(null)));
108
108
  tempNodes.push(astNode);
109
109
  }
110
110
  continue;
@@ -117,16 +117,18 @@ var Node = class {
117
117
  const restPathString = parts.slice(i).join("/");
118
118
  if (matcher instanceof RegExp && matcher.test(restPathString)) {
119
119
  params[name] = restPathString;
120
- handlerSets.push(...this.gHSets(child, method, node.params, params));
120
+ handlerSets.push(...this.#gHSets(child, method, node.params, params));
121
121
  continue;
122
122
  }
123
123
  if (matcher === true || matcher.test(part)) {
124
124
  if (typeof key === "string") {
125
125
  params[name] = part;
126
126
  if (isLast) {
127
- handlerSets.push(...this.gHSets(child, method, params, node.params));
127
+ handlerSets.push(...this.#gHSets(child, method, params, node.params));
128
128
  if (child.children["*"]) {
129
- handlerSets.push(...this.gHSets(child.children["*"], method, params, node.params));
129
+ handlerSets.push(
130
+ ...this.#gHSets(child.children["*"], method, params, node.params)
131
+ );
130
132
  }
131
133
  } else {
132
134
  child.params = params;
@@ -1,2 +1,2 @@
1
- import type { UpgradeWebSocket } from '../../helper/websocket';
2
- export declare const upgradeWebSocket: UpgradeWebSocket<WebSocket>;
1
+ import type { UpgradeWebSocket, WSEvents } from '../../helper/websocket';
2
+ export declare const upgradeWebSocket: UpgradeWebSocket<WebSocket, any, Omit<WSEvents<WebSocket>, "onOpen">>;
@@ -1,21 +1,2 @@
1
1
  import type { UpgradeWebSocket } from '../../helper/websocket';
2
- export interface UpgradeWebSocketOptions {
3
- /**
4
- * Sets the `.protocol` property on the client side web socket to the
5
- * value provided here, which should be one of the strings specified in the
6
- * `protocols` parameter when requesting the web socket. This is intended
7
- * for clients and servers to specify sub-protocols to use to communicate to
8
- * each other.
9
- */
10
- protocol?: string;
11
- /**
12
- * If the client does not respond to this frame with a
13
- * `pong` within the timeout specified, the connection is deemed
14
- * unhealthy and is closed. The `close` and `error` event will be emitted.
15
- *
16
- * The unit is seconds, with a default of 30.
17
- * Set to `0` to disable timeouts.
18
- */
19
- idleTimeout?: number;
20
- }
21
- export declare const upgradeWebSocket: UpgradeWebSocket<WebSocket, UpgradeWebSocketOptions>;
2
+ export declare const upgradeWebSocket: UpgradeWebSocket<WebSocket, Deno.UpgradeWebSocketOptions>;
@@ -434,7 +434,7 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
434
434
  * })
435
435
  * ```
436
436
  */
437
- redirect: <T extends RedirectStatusCode = 302>(location: string, status?: T) => Response & TypedResponse<undefined, T, "redirect">;
437
+ redirect: <T extends RedirectStatusCode = 302>(location: string | URL, status?: T) => Response & TypedResponse<undefined, T, "redirect">;
438
438
  /**
439
439
  * `.notFound()` can return the Not Found Response.
440
440
  *
@@ -16,7 +16,7 @@ export interface WSEvents<T = unknown> {
16
16
  /**
17
17
  * Upgrade WebSocket Type
18
18
  */
19
- export type UpgradeWebSocket<T = unknown, U = any> = (createEvents: (c: Context) => WSEvents<T> | Promise<WSEvents<T>>, options?: U) => MiddlewareHandler<any, string, {
19
+ export type UpgradeWebSocket<T = unknown, U = any, _WSEvents = WSEvents<T>> = (createEvents: (c: Context) => _WSEvents | Promise<_WSEvents>, options?: U) => MiddlewareHandler<any, string, {
20
20
  outputFormat: "ws";
21
21
  }>;
22
22
  /**
@@ -23,7 +23,7 @@ export type HonoOptions<E extends Env> = {
23
23
  */
24
24
  strict?: boolean;
25
25
  /**
26
- * `router` option specifices which router to use.
26
+ * `router` option specifies which router to use.
27
27
  *
28
28
  * @see {@link https://hono.dev/docs/api/hono#router-option}
29
29
  *
@@ -1,4 +1,5 @@
1
1
  import type { HtmlEscaped, HtmlEscapedString, StringBufferWithCallbacks } from '../utils/html';
2
+ import { DOM_MEMO } from './constants';
2
3
  import type { Context } from './context';
3
4
  import type { JSX as HonoJSX, IntrinsicElements as IntrinsicElementsDefined } from './intrinsic-elements';
4
5
  export type Props = Record<string, any>;
@@ -45,6 +46,10 @@ export declare class JSXFragmentNode extends JSXNode {
45
46
  }
46
47
  export declare const jsx: (tag: string | Function, props: Props | null, ...children: (string | number | HtmlEscapedString)[]) => JSXNode;
47
48
  export declare const jsxFn: (tag: string | Function, props: Props, children: (string | number | HtmlEscapedString)[]) => JSXNode;
49
+ export declare const shallowEqual: (a: Props, b: Props) => boolean;
50
+ export type MemorableFC<T> = FC<T> & {
51
+ [DOM_MEMO]: (prevProps: Readonly<T>, nextProps: Readonly<T>) => boolean;
52
+ };
48
53
  export declare const memo: <T>(component: FC<T>, propsAreEqual?: (prevProps: Readonly<T>, nextProps: Readonly<T>) => boolean) => FC<T>;
49
54
  export declare const Fragment: ({ children, }: {
50
55
  key?: string;
@@ -2,4 +2,5 @@ export declare const DOM_RENDERER: unique symbol;
2
2
  export declare const DOM_ERROR_HANDLER: unique symbol;
3
3
  export declare const DOM_STASH: unique symbol;
4
4
  export declare const DOM_INTERNAL_TAG: unique symbol;
5
+ export declare const DOM_MEMO: unique symbol;
5
6
  export declare const PERMALINK: unique symbol;
@@ -2,8 +2,8 @@
2
2
  * @module
3
3
  * This module provides APIs for `hono/jsx/dom`.
4
4
  */
5
- import { isValidElement, memo, reactAPICompatVersion } from '../base';
6
- import type { Child, DOMAttributes, JSX, JSXNode, Props } from '../base';
5
+ import { isValidElement, reactAPICompatVersion } from '../base';
6
+ import type { Child, DOMAttributes, JSX, JSXNode, Props, FC } from '../base';
7
7
  import { Children } from '../children';
8
8
  import { useContext } from '../context';
9
9
  import { createRef, forwardRef, startTransition, startViewTransition, use, useCallback, useDebugValue, useDeferredValue, useEffect, useId, useImperativeHandle, useInsertionEffect, useLayoutEffect, useMemo, useReducer, useRef, useState, useSyncExternalStore, useTransition, useViewTransition } from '../hooks';
@@ -15,6 +15,7 @@ import { createPortal, flushSync } from './render';
15
15
  export { render } from './render';
16
16
  declare const createElement: (tag: string | ((props: Props) => JSXNode), props: Props | null, ...children: Child[]) => JSXNode;
17
17
  declare const cloneElement: <T extends JSXNode | JSX.Element>(element: T, props: Props, ...children: Child[]) => T;
18
+ declare const memo: <T>(component: FC<T>, propsAreEqual?: (prevProps: Readonly<T>, nextProps: Readonly<T>) => boolean) => FC<T>;
18
19
  export { reactAPICompatVersion as version, createElement as jsx, useState, useEffect, useRef, useCallback, use, startTransition, useTransition, useDeferredValue, startViewTransition, useViewTransition, useMemo, useLayoutEffect, useInsertionEffect, useReducer, useId, useDebugValue, createRef, forwardRef, useImperativeHandle, useSyncExternalStore, useFormStatus, useActionState, useOptimistic, Suspense, ErrorBoundary, createContext, useContext, memo, isValidElement, createElement, cloneElement, Children, Fragment, Fragment as StrictMode, DOMAttributes, flushSync, createPortal, };
19
20
  declare const _default: {
20
21
  version: string;
@@ -77,17 +78,17 @@ declare const _default: {
77
78
  T,
78
79
  (action: N) => void
79
80
  ];
80
- Suspense: import("..").FC<import("..").PropsWithChildren<{
81
+ Suspense: FC<import("..").PropsWithChildren<{
81
82
  fallback: any;
82
83
  }>>;
83
- ErrorBoundary: import("..").FC<import("..").PropsWithChildren<{
84
+ ErrorBoundary: FC<import("..").PropsWithChildren<{
84
85
  fallback?: Child;
85
86
  fallbackRender?: import("../components").FallbackRender;
86
87
  onError?: import("../components").ErrorHandler;
87
88
  }>>;
88
89
  createContext: <T>(defaultValue: T) => import("..").Context<T>;
89
90
  useContext: <T>(context: import("..").Context<T>) => T;
90
- memo: <T>(component: import("..").FC<T>, propsAreEqual?: (prevProps: Readonly<T>, nextProps: Readonly<T>) => boolean) => import("..").FC<T>;
91
+ memo: <T>(component: FC<T>, propsAreEqual?: (prevProps: Readonly<T>, nextProps: Readonly<T>) => boolean) => FC<T>;
91
92
  isValidElement: (element: unknown) => element is JSXNode;
92
93
  createElement: (tag: string | ((props: Props) => JSXNode), props: Props | null, ...children: Child[]) => JSXNode;
93
94
  cloneElement: <T extends JSXNode | JSX.Element>(element: T, props: Props, ...children: Child[]) => T;
@@ -25,6 +25,7 @@ export type NodeObject = {
25
25
  e: SupportedElement | Text | undefined;
26
26
  p?: PreserveNodeType;
27
27
  a?: boolean;
28
+ o?: NodeObject;
28
29
  [DOM_STASH]: [
29
30
  number,
30
31
  any[][],
@@ -0,0 +1 @@
1
+ export declare const generateDigest: (stream: ReadableStream<Uint8Array> | null) => Promise<string | null>;
@@ -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.9",
4
4
  "description": "Web framework built on Web Standards",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",