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
@@ -258,13 +258,19 @@ const applyNodeObject = (node, container, isNew) => {
258
258
  remove.forEach(removeNode);
259
259
  const childNodes = isNew ? void 0 : container.childNodes;
260
260
  let offset;
261
+ let insertBeforeNode = null;
261
262
  if (isNew) {
262
263
  offset = -1;
264
+ } else if (!childNodes.length) {
265
+ offset = 0;
263
266
  } else {
264
- offset = (childNodes.length && (findChildNodeIndex(childNodes, findInsertBefore(node.nN)) ?? findChildNodeIndex(
265
- childNodes,
266
- next.find((n) => n.tag !== HONO_PORTAL_ELEMENT && n.e)?.e
267
- ))) ?? -1;
267
+ const offsetByNextNode = findChildNodeIndex(childNodes, findInsertBefore(node.nN));
268
+ if (offsetByNextNode !== void 0) {
269
+ insertBeforeNode = childNodes[offsetByNextNode];
270
+ offset = offsetByNextNode;
271
+ } else {
272
+ offset = findChildNodeIndex(childNodes, next.find((n) => n.tag !== HONO_PORTAL_ELEMENT && n.e)?.e) ?? -1;
273
+ }
268
274
  if (offset === -1) {
269
275
  isNew = true;
270
276
  }
@@ -299,7 +305,7 @@ const applyNodeObject = (node, container, isNew) => {
299
305
  if (childNodes[offset + 1] === el) {
300
306
  container.appendChild(childNodes[offset]);
301
307
  } else {
302
- container.insertBefore(el, childNodes[offset] || null);
308
+ container.insertBefore(el, insertBeforeNode || childNodes[offset] || null);
303
309
  }
304
310
  }
305
311
  }
@@ -381,12 +387,8 @@ const build = (context, node, children) => {
381
387
  if (typeof child.tag === "function") {
382
388
  oldChild[import_constants.DOM_STASH][2] = child[import_constants.DOM_STASH][2] || [];
383
389
  oldChild[import_constants.DOM_STASH][3] = child[import_constants.DOM_STASH][3];
384
- if (!oldChild.f) {
385
- const prevPropsKeys = Object.keys(pP);
386
- const currentProps = oldChild.props;
387
- if (prevPropsKeys.length === Object.keys(currentProps).length && prevPropsKeys.every((k) => k in currentProps && currentProps[k] === pP[k])) {
388
- oldChild.s = true;
389
- }
390
+ if (!oldChild.f && ((oldChild.o || oldChild) === child.o || oldChild.tag[import_constants.DOM_MEMO]?.(pP, oldChild.props))) {
391
+ oldChild.s = true;
390
392
  }
391
393
  }
392
394
  child = oldChild;
@@ -473,7 +475,8 @@ const buildNode = (node) => {
473
475
  key: node.key,
474
476
  f: node.f,
475
477
  type: node.tag,
476
- ref: node.props.ref
478
+ ref: node.props.ref,
479
+ o: node.o || node
477
480
  };
478
481
  }
479
482
  if (typeof node.tag === "function") {
@@ -0,0 +1,59 @@
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 digest_exports = {};
20
+ __export(digest_exports, {
21
+ generateDigest: () => generateDigest
22
+ });
23
+ module.exports = __toCommonJS(digest_exports);
24
+ const mergeBuffers = (buffer1, buffer2) => {
25
+ if (!buffer1) {
26
+ return buffer2;
27
+ }
28
+ const merged = new Uint8Array(buffer1.byteLength + buffer2.byteLength);
29
+ merged.set(new Uint8Array(buffer1), 0);
30
+ merged.set(buffer2, buffer1.byteLength);
31
+ return merged;
32
+ };
33
+ const generateDigest = async (stream) => {
34
+ if (!stream || !crypto || !crypto.subtle) {
35
+ return null;
36
+ }
37
+ let result = void 0;
38
+ const reader = stream.getReader();
39
+ for (; ; ) {
40
+ const { value, done } = await reader.read();
41
+ if (done) {
42
+ break;
43
+ }
44
+ result = await crypto.subtle.digest(
45
+ {
46
+ name: "SHA-1"
47
+ },
48
+ mergeBuffers(result, value)
49
+ );
50
+ }
51
+ if (!result) {
52
+ return null;
53
+ }
54
+ return Array.prototype.map.call(new Uint8Array(result), (x) => x.toString(16).padStart(2, "0")).join("");
55
+ };
56
+ // Annotate the CommonJS export names for ESM import in node:
57
+ 0 && (module.exports = {
58
+ generateDigest
59
+ });
@@ -22,7 +22,7 @@ __export(etag_exports, {
22
22
  etag: () => etag
23
23
  });
24
24
  module.exports = __toCommonJS(etag_exports);
25
- var import_crypto = require("../../utils/crypto");
25
+ var import_digest = require("./digest");
26
26
  const RETAINED_304_HEADERS = [
27
27
  "cache-control",
28
28
  "content-location",
@@ -43,7 +43,10 @@ const etag = (options) => {
43
43
  const res = c.res;
44
44
  let etag3 = res.headers.get("ETag");
45
45
  if (!etag3) {
46
- const hash = await (0, import_crypto.sha1)(res.clone().body || "");
46
+ const hash = await (0, import_digest.generateDigest)(res.clone().body);
47
+ if (hash === null) {
48
+ return;
49
+ }
47
50
  etag3 = weak ? `W/"${hash}"` : `"${hash}"`;
48
51
  }
49
52
  if (etagMatches(etag3, ifNoneMatch)) {
@@ -35,14 +35,14 @@ const buildMatcher = (rules) => {
35
35
  functionRules.push(rule);
36
36
  } else {
37
37
  if (IS_CIDR_NOTATION_REGEX.test(rule)) {
38
- const splittedRule = rule.split("/");
39
- const addrStr = splittedRule[0];
38
+ const separatedRule = rule.split("/");
39
+ const addrStr = separatedRule[0];
40
40
  const type2 = (0, import_ipaddr.distinctRemoteAddr)(addrStr);
41
41
  if (type2 === void 0) {
42
42
  throw new TypeError(`Invalid rule: ${rule}`);
43
43
  }
44
44
  const isIPv4 = type2 === "IPv4";
45
- const prefix = parseInt(splittedRule[1]);
45
+ const prefix = parseInt(separatedRule[1]);
46
46
  if (isIPv4 ? prefix === 32 : prefix === 128) {
47
47
  rule = addrStr;
48
48
  } else {
@@ -32,7 +32,8 @@ const createRenderer = (c, Layout, component, options) => (children, props) => {
32
32
  const currentLayout = component ? (0, import_jsx.jsx)(
33
33
  (props2) => component(props2, c),
34
34
  {
35
- ...{ Layout, ...props }
35
+ Layout,
36
+ ...props
36
37
  },
37
38
  children
38
39
  ) : children;
@@ -40,17 +40,19 @@ const time = (start) => {
40
40
  };
41
41
  const colorStatus = (status) => {
42
42
  const colorEnabled = (0, import_color.getColorEnabled)();
43
- const out = {
44
- 7: colorEnabled ? `\x1B[35m${status}\x1B[0m` : `${status}`,
45
- 5: colorEnabled ? `\x1B[31m${status}\x1B[0m` : `${status}`,
46
- 4: colorEnabled ? `\x1B[33m${status}\x1B[0m` : `${status}`,
47
- 3: colorEnabled ? `\x1B[36m${status}\x1B[0m` : `${status}`,
48
- 2: colorEnabled ? `\x1B[32m${status}\x1B[0m` : `${status}`,
49
- 1: colorEnabled ? `\x1B[32m${status}\x1B[0m` : `${status}`,
50
- 0: colorEnabled ? `\x1B[33m${status}\x1B[0m` : `${status}`
51
- };
52
- const calculateStatus = status / 100 | 0;
53
- return out[calculateStatus];
43
+ if (colorEnabled) {
44
+ switch (status / 100 | 0) {
45
+ case 5:
46
+ return `\x1B[31m${status}\x1B[0m`;
47
+ case 4:
48
+ return `\x1B[33m${status}\x1B[0m`;
49
+ case 3:
50
+ return `\x1B[36m${status}\x1B[0m`;
51
+ case 2:
52
+ return `\x1B[32m${status}\x1B[0m`;
53
+ }
54
+ }
55
+ return `${status}`;
54
56
  };
55
57
  function log(fn, prefix, method, path, status = 0, elapsed) {
56
58
  const out = prefix === "<--" /* Incoming */ ? `${prefix} ${method} ${path}` : `${prefix} ${method} ${path} ${colorStatus(status)} ${elapsed}`;
@@ -34,13 +34,11 @@ const getTime = () => {
34
34
  };
35
35
  const timing = (config) => {
36
36
  const options = {
37
- ...{
38
- total: true,
39
- enabled: true,
40
- totalDescription: "Total Response Time",
41
- autoEnd: true,
42
- crossOrigin: false
43
- },
37
+ total: true,
38
+ enabled: true,
39
+ totalDescription: "Total Response Time",
40
+ autoEnd: true,
41
+ crossOrigin: false,
44
42
  ...config
45
43
  };
46
44
  return async function timing2(c, next) {
@@ -23,6 +23,7 @@ __export(request_exports, {
23
23
  module.exports = __toCommonJS(request_exports);
24
24
  var import_body = require("./utils/body");
25
25
  var import_url = require("./utils/url");
26
+ const tryDecodeURIComponent = (str) => (0, import_url.tryDecode)(str, import_url.decodeURIComponent_);
26
27
  class HonoRequest {
27
28
  raw;
28
29
  #validatedData;
@@ -37,25 +38,25 @@ class HonoRequest {
37
38
  this.#validatedData = {};
38
39
  }
39
40
  param(key) {
40
- return key ? this.getDecodedParam(key) : this.getAllDecodedParams();
41
+ return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
41
42
  }
42
- getDecodedParam(key) {
43
+ #getDecodedParam(key) {
43
44
  const paramKey = this.#matchResult[0][this.routeIndex][1][key];
44
- const param = this.getParamValue(paramKey);
45
- return param ? /\%/.test(param) ? (0, import_url.decodeURIComponent_)(param) : param : void 0;
45
+ const param = this.#getParamValue(paramKey);
46
+ return param ? /\%/.test(param) ? tryDecodeURIComponent(param) : param : void 0;
46
47
  }
47
- getAllDecodedParams() {
48
+ #getAllDecodedParams() {
48
49
  const decoded = {};
49
50
  const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
50
51
  for (const key of keys) {
51
- const value = this.getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
52
+ const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
52
53
  if (value && typeof value === "string") {
53
- decoded[key] = /\%/.test(value) ? (0, import_url.decodeURIComponent_)(value) : value;
54
+ decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value;
54
55
  }
55
56
  }
56
57
  return decoded;
57
58
  }
58
- getParamValue(paramKey) {
59
+ #getParamValue(paramKey) {
59
60
  return this.#matchResult[1] ? this.#matchResult[1][paramKey] : paramKey;
60
61
  }
61
62
  query(key) {
@@ -77,7 +78,7 @@ class HonoRequest {
77
78
  async parseBody(options) {
78
79
  return this.bodyCache.parsedBody ??= await (0, import_body.parseBody)(this, options);
79
80
  }
80
- cachedBody = (key) => {
81
+ #cachedBody = (key) => {
81
82
  const { bodyCache, raw } = this;
82
83
  const cachedBody = bodyCache[key];
83
84
  if (cachedBody) {
@@ -95,19 +96,19 @@ class HonoRequest {
95
96
  return bodyCache[key] = raw[key]();
96
97
  };
97
98
  json() {
98
- return this.cachedBody("json");
99
+ return this.#cachedBody("json");
99
100
  }
100
101
  text() {
101
- return this.cachedBody("text");
102
+ return this.#cachedBody("text");
102
103
  }
103
104
  arrayBuffer() {
104
- return this.cachedBody("arrayBuffer");
105
+ return this.#cachedBody("arrayBuffer");
105
106
  }
106
107
  blob() {
107
- return this.cachedBody("blob");
108
+ return this.#cachedBody("blob");
108
109
  }
109
110
  formData() {
110
- return this.cachedBody("formData");
111
+ return this.#cachedBody("formData");
111
112
  }
112
113
  addValidatedData(target, data) {
113
114
  this.#validatedData[target] = data;
@@ -24,7 +24,7 @@ module.exports = __toCommonJS(router_exports);
24
24
  var import_router = require("../../router");
25
25
  class PatternRouter {
26
26
  name = "PatternRouter";
27
- routes = [];
27
+ #routes = [];
28
28
  add(method, path, handler) {
29
29
  const endsWithWildcard = path[path.length - 1] === "*";
30
30
  if (endsWithWildcard) {
@@ -46,12 +46,12 @@ class PatternRouter {
46
46
  } catch {
47
47
  throw new import_router.UnsupportedPathError();
48
48
  }
49
- this.routes.push([re, method, handler]);
49
+ this.#routes.push([re, method, handler]);
50
50
  }
51
51
  match(method, path) {
52
52
  const handlers = [];
53
- for (let i = 0, len = this.routes.length; i < len; i++) {
54
- const [pattern, routeMethod, handler] = this.routes[i];
53
+ for (let i = 0, len = this.#routes.length; i < len; i++) {
54
+ const [pattern, routeMethod, handler] = this.#routes[i];
55
55
  if (routeMethod === method || routeMethod === import_router.METHOD_NAME_ALL) {
56
56
  const match = pattern.exec(path);
57
57
  if (match) {
@@ -173,7 +173,7 @@ class RegExpRouter {
173
173
  }
174
174
  match(method, path) {
175
175
  clearWildcardRegExpCache();
176
- const matchers = this.buildAllMatchers();
176
+ const matchers = this.#buildAllMatchers();
177
177
  this.match = (method2, path2) => {
178
178
  const matcher = matchers[method2] || matchers[import_router.METHOD_NAME_ALL];
179
179
  const staticMatch = matcher[2][path2];
@@ -189,15 +189,15 @@ class RegExpRouter {
189
189
  };
190
190
  return this.match(method, path);
191
191
  }
192
- buildAllMatchers() {
192
+ #buildAllMatchers() {
193
193
  const matchers = /* @__PURE__ */ Object.create(null);
194
- [...Object.keys(this.routes), ...Object.keys(this.middleware)].forEach((method) => {
195
- matchers[method] ||= this.buildMatcher(method);
194
+ Object.keys(this.routes).concat(Object.keys(this.middleware)).forEach((method) => {
195
+ matchers[method] ||= this.#buildMatcher(method);
196
196
  });
197
197
  this.middleware = this.routes = void 0;
198
198
  return matchers;
199
199
  }
200
- buildMatcher(method) {
200
+ #buildMatcher(method) {
201
201
  const routes = [];
202
202
  let hasOwnRoute = method === import_router.METHOD_NAME_ALL;
203
203
  [this.middleware, this.routes].forEach((r) => {
@@ -63,11 +63,11 @@ class Trie {
63
63
  const indexReplacementMap = [];
64
64
  const paramReplacementMap = [];
65
65
  regexp = regexp.replace(/#(\d+)|@(\d+)|\.\*\$/g, (_, handlerIndex, paramIndex) => {
66
- if (typeof handlerIndex !== "undefined") {
66
+ if (handlerIndex !== void 0) {
67
67
  indexReplacementMap[++captureIndex] = Number(handlerIndex);
68
68
  return "$()";
69
69
  }
70
- if (typeof paramIndex !== "undefined") {
70
+ if (paramIndex !== void 0) {
71
71
  paramReplacementMap[Number(paramIndex)] = ++captureIndex;
72
72
  return "";
73
73
  }
@@ -75,7 +75,7 @@ class Node {
75
75
  curNode.methods.push(m);
76
76
  return curNode;
77
77
  }
78
- gHSets(node, method, nodeParams, params) {
78
+ #gHSets(node, method, nodeParams, params) {
79
79
  const handlerSets = [];
80
80
  for (let i = 0, len = node.methods.length; i < len; i++) {
81
81
  const m = node.methods[i];
@@ -112,10 +112,10 @@ class Node {
112
112
  if (isLast) {
113
113
  if (nextNode.children["*"]) {
114
114
  handlerSets.push(
115
- ...this.gHSets(nextNode.children["*"], method, node.params, /* @__PURE__ */ Object.create(null))
115
+ ...this.#gHSets(nextNode.children["*"], method, node.params, /* @__PURE__ */ Object.create(null))
116
116
  );
117
117
  }
118
- handlerSets.push(...this.gHSets(nextNode, method, node.params, /* @__PURE__ */ Object.create(null)));
118
+ handlerSets.push(...this.#gHSets(nextNode, method, node.params, /* @__PURE__ */ Object.create(null)));
119
119
  } else {
120
120
  tempNodes.push(nextNode);
121
121
  }
@@ -126,7 +126,7 @@ class Node {
126
126
  if (pattern === "*") {
127
127
  const astNode = node.children["*"];
128
128
  if (astNode) {
129
- handlerSets.push(...this.gHSets(astNode, method, node.params, /* @__PURE__ */ Object.create(null)));
129
+ handlerSets.push(...this.#gHSets(astNode, method, node.params, /* @__PURE__ */ Object.create(null)));
130
130
  tempNodes.push(astNode);
131
131
  }
132
132
  continue;
@@ -139,16 +139,18 @@ class Node {
139
139
  const restPathString = parts.slice(i).join("/");
140
140
  if (matcher instanceof RegExp && matcher.test(restPathString)) {
141
141
  params[name] = restPathString;
142
- handlerSets.push(...this.gHSets(child, method, node.params, params));
142
+ handlerSets.push(...this.#gHSets(child, method, node.params, params));
143
143
  continue;
144
144
  }
145
145
  if (matcher === true || matcher.test(part)) {
146
146
  if (typeof key === "string") {
147
147
  params[name] = part;
148
148
  if (isLast) {
149
- handlerSets.push(...this.gHSets(child, method, params, node.params));
149
+ handlerSets.push(...this.#gHSets(child, method, params, node.params));
150
150
  if (child.children["*"]) {
151
- handlerSets.push(...this.gHSets(child.children["*"], method, params, node.params));
151
+ handlerSets.push(
152
+ ...this.#gHSets(child.children["*"], method, params, node.params)
153
+ );
152
154
  }
153
155
  } else {
154
156
  child.params = params;
@@ -23,7 +23,7 @@ __export(color_exports, {
23
23
  module.exports = __toCommonJS(color_exports);
24
24
  function getColorEnabled() {
25
25
  const { process, Deno } = globalThis;
26
- const isNoColor = typeof Deno?.noColor === "boolean" ? Deno.noColor : typeof process !== "undefined" ? "NO_COLOR" in process?.env : false;
26
+ const isNoColor = typeof Deno?.noColor === "boolean" ? Deno.noColor : process !== void 0 ? "NO_COLOR" in process?.env : false;
27
27
  return !isNoColor;
28
28
  }
29
29
  // Annotate the CommonJS export names for ESM import in node:
@@ -50,16 +50,20 @@ const verifySignature = async (base64Signature, value, secret) => {
50
50
  const validCookieNameRegEx = /^[\w!#$%&'*.^`|~+-]+$/;
51
51
  const validCookieValueRegEx = /^[ !#-:<-[\]-~]*$/;
52
52
  const parse = (cookie, name) => {
53
+ if (name && cookie.indexOf(name) === -1) {
54
+ return {};
55
+ }
53
56
  const pairs = cookie.trim().split(";");
54
- return pairs.reduce((parsedCookie, pairStr) => {
57
+ const parsedCookie = {};
58
+ for (let pairStr of pairs) {
55
59
  pairStr = pairStr.trim();
56
60
  const valueStartPos = pairStr.indexOf("=");
57
61
  if (valueStartPos === -1) {
58
- return parsedCookie;
62
+ continue;
59
63
  }
60
64
  const cookieName = pairStr.substring(0, valueStartPos).trim();
61
65
  if (name && name !== cookieName || !validCookieNameRegEx.test(cookieName)) {
62
- return parsedCookie;
66
+ continue;
63
67
  }
64
68
  let cookieValue = pairStr.substring(valueStartPos + 1).trim();
65
69
  if (cookieValue.startsWith('"') && cookieValue.endsWith('"')) {
@@ -67,9 +71,12 @@ const parse = (cookie, name) => {
67
71
  }
68
72
  if (validCookieValueRegEx.test(cookieValue)) {
69
73
  parsedCookie[cookieName] = (0, import_url.decodeURIComponent_)(cookieValue);
74
+ if (name) {
75
+ break;
76
+ }
70
77
  }
71
- return parsedCookie;
72
- }, {});
78
+ }
79
+ return parsedCookie;
73
80
  };
74
81
  const parseSigned = async (cookie, secret, name) => {
75
82
  const parsedCookie = {};
@@ -111,7 +118,7 @@ const _serialize = (name, value, opt = {}) => {
111
118
  "Cookies Max-Age SHOULD NOT be greater than 400 days (34560000 seconds) in duration."
112
119
  );
113
120
  }
114
- cookie += `; Max-Age=${Math.floor(opt.maxAge)}`;
121
+ cookie += `; Max-Age=${opt.maxAge | 0}`;
115
122
  }
116
123
  if (opt.domain && opt.prefix !== "host") {
117
124
  cookie += `; Domain=${opt.domain}`;
@@ -41,15 +41,6 @@ const md5 = async (data) => {
41
41
  };
42
42
  const createHash = async (data, algorithm) => {
43
43
  let sourceBuffer;
44
- if (data instanceof ReadableStream) {
45
- let body = "";
46
- const reader = data.getReader();
47
- await reader?.read().then(async (chuck) => {
48
- const value = await createHash(chuck.value || "", algorithm);
49
- body += value;
50
- });
51
- return body;
52
- }
53
44
  if (ArrayBuffer.isView(data) || data instanceof ArrayBuffer) {
54
45
  sourceBuffer = data;
55
46
  } else {
@@ -56,7 +56,7 @@ const verify = async (token, publicKey, alg = "HS256") => {
56
56
  if (!isTokenHeader(header)) {
57
57
  throw new import_types.JwtHeaderInvalid(header);
58
58
  }
59
- const now = Math.floor(Date.now() / 1e3);
59
+ const now = Date.now() / 1e3 | 0;
60
60
  if (payload.nbf && payload.nbf > now) {
61
61
  throw new import_types.JwtTokenNotBefore(token);
62
62
  }
@@ -42,7 +42,7 @@ const getExtension = (mimeType) => {
42
42
  }
43
43
  }
44
44
  };
45
- const baseMimes = {
45
+ const _baseMimes = {
46
46
  aac: "audio/aac",
47
47
  avi: "video/x-msvideo",
48
48
  avif: "image/avif",
@@ -99,6 +99,7 @@ const baseMimes = {
99
99
  gltf: "model/gltf+json",
100
100
  glb: "model/gltf-binary"
101
101
  };
102
+ const baseMimes = _baseMimes;
102
103
  // Annotate the CommonJS export names for ESM import in node:
103
104
  0 && (module.exports = {
104
105
  getExtension,
@@ -28,7 +28,8 @@ __export(url_exports, {
28
28
  getQueryStrings: () => getQueryStrings,
29
29
  mergePath: () => mergePath,
30
30
  splitPath: () => splitPath,
31
- splitRoutingPath: () => splitRoutingPath
31
+ splitRoutingPath: () => splitRoutingPath,
32
+ tryDecode: () => tryDecode
32
33
  });
33
34
  module.exports = __toCommonJS(url_exports);
34
35
  const splitPath = (path) => {
@@ -82,19 +83,20 @@ const getPattern = (label) => {
82
83
  }
83
84
  return null;
84
85
  };
85
- const tryDecodeURI = (str) => {
86
+ const tryDecode = (str, decoder) => {
86
87
  try {
87
- return decodeURI(str);
88
+ return decoder(str);
88
89
  } catch {
89
90
  return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match) => {
90
91
  try {
91
- return decodeURI(match);
92
+ return decoder(match);
92
93
  } catch {
93
94
  return match;
94
95
  }
95
96
  });
96
97
  }
97
98
  };
99
+ const tryDecodeURI = (str) => tryDecode(str, decodeURI);
98
100
  const getPath = (request) => {
99
101
  const url = request.url;
100
102
  const start = url.indexOf("/", 8);
@@ -175,7 +177,7 @@ const _decodeURI = (value) => {
175
177
  if (value.indexOf("+") !== -1) {
176
178
  value = value.replace(/\+/g, " ");
177
179
  }
178
- return /%/.test(value) ? decodeURIComponent_(value) : value;
180
+ return value.indexOf("%") !== -1 ? decodeURIComponent_(value) : value;
179
181
  };
180
182
  const _getQueryParam = (url, key, multiple) => {
181
183
  let encoded;
@@ -258,5 +260,6 @@ const decodeURIComponent_ = decodeURIComponent;
258
260
  getQueryStrings,
259
261
  mergePath,
260
262
  splitPath,
261
- splitRoutingPath
263
+ splitRoutingPath,
264
+ tryDecode
262
265
  });
@@ -65,8 +65,8 @@ var ClientRequestImpl = class {
65
65
  }
66
66
  let methodUpperCase = this.method.toUpperCase();
67
67
  const headerValues = {
68
- ...args?.header ?? {},
69
- ...typeof opt?.headers === "function" ? await opt.headers() : opt?.headers ? opt.headers : {}
68
+ ...args?.header,
69
+ ...typeof opt?.headers === "function" ? await opt.headers() : opt?.headers
70
70
  };
71
71
  if (args?.cookie) {
72
72
  const cookies = [];
@@ -157,7 +157,7 @@ var hc = (baseUrl, options) => createProxy(function proxyCallback(opts) {
157
157
  const req = new ClientRequestImpl(url, method);
158
158
  if (method) {
159
159
  options ??= {};
160
- const args = deepMerge(options, { ...opts.args[1] ?? {} });
160
+ const args = deepMerge(options, { ...opts.args[1] });
161
161
  return req.fetch(opts.args[0], args);
162
162
  }
163
163
  return req;
package/dist/compose.js CHANGED
@@ -3,6 +3,7 @@ import { Context } from "./context.js";
3
3
  var compose = (middleware, onError, onNotFound) => {
4
4
  return (context, next) => {
5
5
  let index = -1;
6
+ const isContext = context instanceof Context;
6
7
  return dispatch(0);
7
8
  async function dispatch(i) {
8
9
  if (i <= index) {
@@ -14,14 +15,14 @@ var compose = (middleware, onError, onNotFound) => {
14
15
  let handler;
15
16
  if (middleware[i]) {
16
17
  handler = middleware[i][0][0];
17
- if (context instanceof Context) {
18
+ if (isContext) {
18
19
  context.req.routeIndex = i;
19
20
  }
20
21
  } else {
21
22
  handler = i === middleware.length && next || void 0;
22
23
  }
23
24
  if (!handler) {
24
- if (context instanceof Context && context.finalized === false && onNotFound) {
25
+ if (isContext && context.finalized === false && onNotFound) {
25
26
  res = await onNotFound(context);
26
27
  }
27
28
  } else {
@@ -30,7 +31,7 @@ var compose = (middleware, onError, onNotFound) => {
30
31
  return dispatch(i + 1);
31
32
  });
32
33
  } catch (err) {
33
- if (err instanceof Error && context instanceof Context && onError) {
34
+ if (err instanceof Error && isContext && onError) {
34
35
  context.error = err;
35
36
  res = await onError(err, context);
36
37
  isError = true;