hono 4.6.13 → 4.6.14

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.
@@ -245,7 +245,7 @@ class Context {
245
245
  json = (object, arg, headers) => {
246
246
  const body = JSON.stringify(object);
247
247
  this.#preparedHeaders ??= {};
248
- this.#preparedHeaders["content-type"] = "application/json; charset=UTF-8";
248
+ this.#preparedHeaders["content-type"] = "application/json";
249
249
  return typeof arg === "number" ? this.#newResponse(body, arg, headers) : this.#newResponse(body, arg);
250
250
  };
251
251
  html = (html, arg, headers) => {
@@ -36,7 +36,8 @@ const stream = (c, cb, onError) => {
36
36
  try {
37
37
  await cb(stream2);
38
38
  } catch (e) {
39
- if (e instanceof Error && onError) {
39
+ if (e === void 0) {
40
+ } else if (e instanceof Error && onError) {
40
41
  await onError(e, stream2);
41
42
  } else {
42
43
  console.error(e);
@@ -71,7 +71,7 @@ const basicAuth = (options, ...users) => {
71
71
  status,
72
72
  headers: {
73
73
  ...headers,
74
- "content-type": "application/json; charset=UTF-8"
74
+ "content-type": "application/json"
75
75
  }
76
76
  });
77
77
  throw new import_http_exception.HTTPException(status, { res });
@@ -49,7 +49,7 @@ const bearerAuth = (options) => {
49
49
  status,
50
50
  headers: {
51
51
  ...headers,
52
- "content-type": "application/json; charset=UTF-8"
52
+ "content-type": "application/json"
53
53
  }
54
54
  });
55
55
  throw new import_http_exception.HTTPException(status, { res });
@@ -22,6 +22,7 @@ __export(router_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(router_exports);
24
24
  var import_router = require("../../router");
25
+ const emptyParams = /* @__PURE__ */ Object.create(null);
25
26
  class PatternRouter {
26
27
  name = "PatternRouter";
27
28
  #routes = [];
@@ -55,7 +56,7 @@ class PatternRouter {
55
56
  if (routeMethod === method || routeMethod === import_router.METHOD_NAME_ALL) {
56
57
  const match = pattern.exec(path);
57
58
  if (match) {
58
- handlers.push([handler, match.groups || /* @__PURE__ */ Object.create(null)]);
59
+ handlers.push([handler, match.groups || emptyParams]);
59
60
  }
60
61
  }
61
62
  }
@@ -23,12 +23,13 @@ __export(node_exports, {
23
23
  module.exports = __toCommonJS(node_exports);
24
24
  var import_router = require("../../router");
25
25
  var import_url = require("../../utils/url");
26
+ const emptyParams = /* @__PURE__ */ Object.create(null);
26
27
  class Node {
27
28
  #methods;
28
29
  #children;
29
30
  #patterns;
30
31
  #order = 0;
31
- #params = /* @__PURE__ */ Object.create(null);
32
+ #params = emptyParams;
32
33
  constructor(method, handler, children) {
33
34
  this.#children = children || /* @__PURE__ */ Object.create(null);
34
35
  this.#methods = [];
@@ -80,20 +81,22 @@ class Node {
80
81
  const processedSet = {};
81
82
  if (handlerSet !== void 0) {
82
83
  handlerSet.params = /* @__PURE__ */ Object.create(null);
83
- for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
84
- const key = handlerSet.possibleKeys[i2];
85
- const processed = processedSet[handlerSet.score];
86
- handlerSet.params[key] = params[key] && !processed ? params[key] : nodeParams[key] ?? params[key];
87
- processedSet[handlerSet.score] = true;
88
- }
89
84
  handlerSets.push(handlerSet);
85
+ if (nodeParams !== emptyParams || params && params !== emptyParams) {
86
+ for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
87
+ const key = handlerSet.possibleKeys[i2];
88
+ const processed = processedSet[handlerSet.score];
89
+ handlerSet.params[key] = params?.[key] && !processed ? params[key] : nodeParams[key] ?? params?.[key];
90
+ processedSet[handlerSet.score] = true;
91
+ }
92
+ }
90
93
  }
91
94
  }
92
95
  return handlerSets;
93
96
  }
94
97
  search(method, path) {
95
98
  const handlerSets = [];
96
- this.#params = /* @__PURE__ */ Object.create(null);
99
+ this.#params = emptyParams;
97
100
  const curNode = this;
98
101
  let curNodes = [curNode];
99
102
  const parts = (0, import_url.splitPath)(path);
@@ -109,30 +112,21 @@ class Node {
109
112
  if (isLast) {
110
113
  if (nextNode.#children["*"]) {
111
114
  handlerSets.push(
112
- ...this.#getHandlerSets(
113
- nextNode.#children["*"],
114
- method,
115
- node.#params,
116
- /* @__PURE__ */ Object.create(null)
117
- )
115
+ ...this.#getHandlerSets(nextNode.#children["*"], method, node.#params)
118
116
  );
119
117
  }
120
- handlerSets.push(
121
- ...this.#getHandlerSets(nextNode, method, node.#params, /* @__PURE__ */ Object.create(null))
122
- );
118
+ handlerSets.push(...this.#getHandlerSets(nextNode, method, node.#params));
123
119
  } else {
124
120
  tempNodes.push(nextNode);
125
121
  }
126
122
  }
127
123
  for (let k = 0, len3 = node.#patterns.length; k < len3; k++) {
128
124
  const pattern = node.#patterns[k];
129
- const params = { ...node.#params };
125
+ const params = node.#params === emptyParams ? {} : { ...node.#params };
130
126
  if (pattern === "*") {
131
127
  const astNode = node.#children["*"];
132
128
  if (astNode) {
133
- handlerSets.push(
134
- ...this.#getHandlerSets(astNode, method, node.#params, /* @__PURE__ */ Object.create(null))
135
- );
129
+ handlerSets.push(...this.#getHandlerSets(astNode, method, node.#params));
136
130
  tempNodes.push(astNode);
137
131
  }
138
132
  continue;
@@ -30,7 +30,7 @@ const getMimeType = (filename, mimes = baseMimes) => {
30
30
  return;
31
31
  }
32
32
  let mimeType = mimes[match[1]];
33
- if (mimeType && mimeType.startsWith("text") || mimeType === "application/json") {
33
+ if (mimeType && mimeType.startsWith("text")) {
34
34
  mimeType += "; charset=utf-8";
35
35
  }
36
36
  return mimeType;
package/dist/context.js CHANGED
@@ -222,7 +222,7 @@ var Context = class {
222
222
  json = (object, arg, headers) => {
223
223
  const body = JSON.stringify(object);
224
224
  this.#preparedHeaders ??= {};
225
- this.#preparedHeaders["content-type"] = "application/json; charset=UTF-8";
225
+ this.#preparedHeaders["content-type"] = "application/json";
226
226
  return typeof arg === "number" ? this.#newResponse(body, arg, headers) : this.#newResponse(body, arg);
227
227
  };
228
228
  html = (html, arg, headers) => {
@@ -14,7 +14,8 @@ var stream = (c, cb, onError) => {
14
14
  try {
15
15
  await cb(stream2);
16
16
  } catch (e) {
17
- if (e instanceof Error && onError) {
17
+ if (e === void 0) {
18
+ } else if (e instanceof Error && onError) {
18
19
  await onError(e, stream2);
19
20
  } else {
20
21
  console.error(e);
@@ -49,7 +49,7 @@ var basicAuth = (options, ...users) => {
49
49
  status,
50
50
  headers: {
51
51
  ...headers,
52
- "content-type": "application/json; charset=UTF-8"
52
+ "content-type": "application/json"
53
53
  }
54
54
  });
55
55
  throw new HTTPException(status, { res });
@@ -27,7 +27,7 @@ var bearerAuth = (options) => {
27
27
  status,
28
28
  headers: {
29
29
  ...headers,
30
- "content-type": "application/json; charset=UTF-8"
30
+ "content-type": "application/json"
31
31
  }
32
32
  });
33
33
  throw new HTTPException(status, { res });
@@ -1,5 +1,6 @@
1
1
  // src/router/pattern-router/router.ts
2
2
  import { METHOD_NAME_ALL, UnsupportedPathError } from "../../router.js";
3
+ var emptyParams = /* @__PURE__ */ Object.create(null);
3
4
  var PatternRouter = class {
4
5
  name = "PatternRouter";
5
6
  #routes = [];
@@ -33,7 +34,7 @@ var PatternRouter = class {
33
34
  if (routeMethod === method || routeMethod === METHOD_NAME_ALL) {
34
35
  const match = pattern.exec(path);
35
36
  if (match) {
36
- handlers.push([handler, match.groups || /* @__PURE__ */ Object.create(null)]);
37
+ handlers.push([handler, match.groups || emptyParams]);
37
38
  }
38
39
  }
39
40
  }
@@ -1,12 +1,13 @@
1
1
  // src/router/trie-router/node.ts
2
2
  import { METHOD_NAME_ALL } from "../../router.js";
3
3
  import { getPattern, splitPath, splitRoutingPath } from "../../utils/url.js";
4
+ var emptyParams = /* @__PURE__ */ Object.create(null);
4
5
  var Node = class {
5
6
  #methods;
6
7
  #children;
7
8
  #patterns;
8
9
  #order = 0;
9
- #params = /* @__PURE__ */ Object.create(null);
10
+ #params = emptyParams;
10
11
  constructor(method, handler, children) {
11
12
  this.#children = children || /* @__PURE__ */ Object.create(null);
12
13
  this.#methods = [];
@@ -58,20 +59,22 @@ var Node = class {
58
59
  const processedSet = {};
59
60
  if (handlerSet !== void 0) {
60
61
  handlerSet.params = /* @__PURE__ */ Object.create(null);
61
- for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
62
- const key = handlerSet.possibleKeys[i2];
63
- const processed = processedSet[handlerSet.score];
64
- handlerSet.params[key] = params[key] && !processed ? params[key] : nodeParams[key] ?? params[key];
65
- processedSet[handlerSet.score] = true;
66
- }
67
62
  handlerSets.push(handlerSet);
63
+ if (nodeParams !== emptyParams || params && params !== emptyParams) {
64
+ for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
65
+ const key = handlerSet.possibleKeys[i2];
66
+ const processed = processedSet[handlerSet.score];
67
+ handlerSet.params[key] = params?.[key] && !processed ? params[key] : nodeParams[key] ?? params?.[key];
68
+ processedSet[handlerSet.score] = true;
69
+ }
70
+ }
68
71
  }
69
72
  }
70
73
  return handlerSets;
71
74
  }
72
75
  search(method, path) {
73
76
  const handlerSets = [];
74
- this.#params = /* @__PURE__ */ Object.create(null);
77
+ this.#params = emptyParams;
75
78
  const curNode = this;
76
79
  let curNodes = [curNode];
77
80
  const parts = splitPath(path);
@@ -87,30 +90,21 @@ var Node = class {
87
90
  if (isLast) {
88
91
  if (nextNode.#children["*"]) {
89
92
  handlerSets.push(
90
- ...this.#getHandlerSets(
91
- nextNode.#children["*"],
92
- method,
93
- node.#params,
94
- /* @__PURE__ */ Object.create(null)
95
- )
93
+ ...this.#getHandlerSets(nextNode.#children["*"], method, node.#params)
96
94
  );
97
95
  }
98
- handlerSets.push(
99
- ...this.#getHandlerSets(nextNode, method, node.#params, /* @__PURE__ */ Object.create(null))
100
- );
96
+ handlerSets.push(...this.#getHandlerSets(nextNode, method, node.#params));
101
97
  } else {
102
98
  tempNodes.push(nextNode);
103
99
  }
104
100
  }
105
101
  for (let k = 0, len3 = node.#patterns.length; k < len3; k++) {
106
102
  const pattern = node.#patterns[k];
107
- const params = { ...node.#params };
103
+ const params = node.#params === emptyParams ? {} : { ...node.#params };
108
104
  if (pattern === "*") {
109
105
  const astNode = node.#children["*"];
110
106
  if (astNode) {
111
- handlerSets.push(
112
- ...this.#getHandlerSets(astNode, method, node.#params, /* @__PURE__ */ Object.create(null))
113
- );
107
+ handlerSets.push(...this.#getHandlerSets(astNode, method, node.#params));
114
108
  tempNodes.push(astNode);
115
109
  }
116
110
  continue;
@@ -6,7 +6,7 @@ var getMimeType = (filename, mimes = baseMimes) => {
6
6
  return;
7
7
  }
8
8
  let mimeType = mimes[match[1]];
9
- if (mimeType && mimeType.startsWith("text") || mimeType === "application/json") {
9
+ if (mimeType && mimeType.startsWith("text")) {
10
10
  mimeType += "; charset=utf-8";
11
11
  }
12
12
  return mimeType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "4.6.13",
3
+ "version": "4.6.14",
4
4
  "description": "Web framework built on Web Standards",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",