hono 4.6.12 → 4.6.13

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.
@@ -159,7 +159,11 @@ var EventV1Processor = class extends EventProcessor {
159
159
  return event.httpMethod;
160
160
  }
161
161
  getQueryString(event) {
162
- return Object.entries(event.queryStringParameters || {}).filter(([, value]) => value).map(([key, value]) => `${key}=${value}`).join("&");
162
+ if (event.multiValueQueryStringParameters) {
163
+ return Object.entries(event.multiValueQueryStringParameters || {}).filter(([, value]) => value).map(([key, value]) => `${key}=${value.join(`&${key}=`)}`).join("&");
164
+ } else {
165
+ return Object.entries(event.queryStringParameters || {}).filter(([, value]) => value).map(([key, value]) => `${key}=${value}`).join("&");
166
+ }
163
167
  }
164
168
  getCookies(event, headers) {
165
169
  }
@@ -195,7 +195,11 @@ class EventV1Processor extends EventProcessor {
195
195
  return event.httpMethod;
196
196
  }
197
197
  getQueryString(event) {
198
- return Object.entries(event.queryStringParameters || {}).filter(([, value]) => value).map(([key, value]) => `${key}=${value}`).join("&");
198
+ if (event.multiValueQueryStringParameters) {
199
+ return Object.entries(event.multiValueQueryStringParameters || {}).filter(([, value]) => value).map(([key, value]) => `${key}=${value.join(`&${key}=`)}`).join("&");
200
+ } else {
201
+ return Object.entries(event.queryStringParameters || {}).filter(([, value]) => value).map(([key, value]) => `${key}=${value}`).join("&");
202
+ }
199
203
  }
200
204
  getCookies(event, headers) {
201
205
  }
@@ -112,20 +112,20 @@ class ClientRequestImpl {
112
112
  }
113
113
  const hc = (baseUrl, options) => createProxy(function proxyCallback(opts) {
114
114
  const parts = [...opts.path];
115
- if (parts[parts.length - 1] === "toString") {
116
- if (parts[parts.length - 2] === "name") {
117
- return parts[parts.length - 3] || "";
115
+ if (parts.at(-1) === "toString") {
116
+ if (parts.at(-2) === "name") {
117
+ return parts.at(-3) || "";
118
118
  }
119
119
  return proxyCallback.toString();
120
120
  }
121
- if (parts[parts.length - 1] === "valueOf") {
122
- if (parts[parts.length - 2] === "name") {
123
- return parts[parts.length - 3] || "";
121
+ if (parts.at(-1) === "valueOf") {
122
+ if (parts.at(-2) === "name") {
123
+ return parts.at(-3) || "";
124
124
  }
125
125
  return proxyCallback;
126
126
  }
127
127
  let method = "";
128
- if (/^\$/.test(parts[parts.length - 1])) {
128
+ if (/^\$/.test(parts.at(-1))) {
129
129
  const last = parts.pop();
130
130
  if (last) {
131
131
  method = last.replace(/^\$/, "");
@@ -55,7 +55,7 @@ const html = (strings, ...values) => {
55
55
  }
56
56
  }
57
57
  }
58
- buffer[0] += strings[strings.length - 1];
58
+ buffer[0] += strings.at(-1);
59
59
  return buffer.length === 1 ? "callbacks" in buffer ? (0, import_html.raw)((0, import_html.resolveCallbackSync)((0, import_html.raw)(buffer[0], buffer.callbacks))) : (0, import_html.raw)(buffer[0]) : (0, import_html.stringBufferToString)(buffer, buffer.callbacks);
60
60
  };
61
61
  // Annotate the CommonJS export names for ESM import in node:
@@ -90,7 +90,7 @@ const cors = (options) => {
90
90
  return new Response(null, {
91
91
  headers: c.res.headers,
92
92
  status: 204,
93
- statusText: c.res.statusText
93
+ statusText: "No Content"
94
94
  });
95
95
  }
96
96
  await next();
@@ -25,7 +25,7 @@ module.exports = __toCommonJS(trailing_slash_exports);
25
25
  const trimTrailingSlash = () => {
26
26
  return async function trimTrailingSlash2(c, next) {
27
27
  await next();
28
- if (c.res.status === 404 && c.req.method === "GET" && c.req.path !== "/" && c.req.path[c.req.path.length - 1] === "/") {
28
+ if (c.res.status === 404 && c.req.method === "GET" && c.req.path !== "/" && c.req.path.at(-1) === "/") {
29
29
  const url = new URL(c.req.url);
30
30
  url.pathname = url.pathname.substring(0, url.pathname.length - 1);
31
31
  c.res = c.redirect(url.toString(), 301);
@@ -35,7 +35,7 @@ const trimTrailingSlash = () => {
35
35
  const appendTrailingSlash = () => {
36
36
  return async function appendTrailingSlash2(c, next) {
37
37
  await next();
38
- if (c.res.status === 404 && c.req.method === "GET" && c.req.path[c.req.path.length - 1] !== "/") {
38
+ if (c.res.status === 404 && c.req.method === "GET" && c.req.path.at(-1) !== "/") {
39
39
  const url = new URL(c.req.url);
40
40
  url.pathname += "/";
41
41
  c.res = c.redirect(url.toString(), 301);
@@ -26,7 +26,7 @@ class PatternRouter {
26
26
  name = "PatternRouter";
27
27
  #routes = [];
28
28
  add(method, path, handler) {
29
- const endsWithWildcard = path[path.length - 1] === "*";
29
+ const endsWithWildcard = path.at(-1) === "*";
30
30
  if (endsWithWildcard) {
31
31
  path = path.slice(0, -2);
32
32
  }
@@ -18,6 +18,7 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var ipaddr_exports = {};
20
20
  __export(ipaddr_exports, {
21
+ convertIPv4BinaryToString: () => convertIPv4BinaryToString,
21
22
  convertIPv4ToBinary: () => convertIPv4ToBinary,
22
23
  convertIPv6BinaryToString: () => convertIPv6BinaryToString,
23
24
  convertIPv6ToBinary: () => convertIPv6ToBinary,
@@ -27,6 +28,13 @@ __export(ipaddr_exports, {
27
28
  module.exports = __toCommonJS(ipaddr_exports);
28
29
  const expandIPv6 = (ipV6) => {
29
30
  const sections = ipV6.split(":");
31
+ if (IPV4_REGEX.test(sections.at(-1))) {
32
+ sections.splice(
33
+ -1,
34
+ 1,
35
+ ...convertIPv6BinaryToString(convertIPv4ToBinary(sections.at(-1))).substring(2).split(":")
36
+ );
37
+ }
30
38
  for (let i = 0; i < sections.length; i++) {
31
39
  const node = sections[i];
32
40
  if (node !== "") {
@@ -65,7 +73,17 @@ const convertIPv6ToBinary = (ipv6) => {
65
73
  }
66
74
  return result;
67
75
  };
76
+ const convertIPv4BinaryToString = (ipV4) => {
77
+ const sections = [];
78
+ for (let i = 0; i < 4; i++) {
79
+ sections.push(ipV4 >> BigInt(8 * (3 - i)) & 0xffn);
80
+ }
81
+ return sections.join(".");
82
+ };
68
83
  const convertIPv6BinaryToString = (ipV6) => {
84
+ if (ipV6 >> 32n === 0xffffn) {
85
+ return `::ffff:${convertIPv4BinaryToString(ipV6 & 0xffffffffn)}`;
86
+ }
69
87
  const sections = [];
70
88
  for (let i = 0; i < 8; i++) {
71
89
  sections.push((ipV6 >> BigInt(16 * (7 - i)) & 0xffffn).toString(16));
@@ -101,6 +119,7 @@ const convertIPv6BinaryToString = (ipV6) => {
101
119
  };
102
120
  // Annotate the CommonJS export names for ESM import in node:
103
121
  0 && (module.exports = {
122
+ convertIPv4BinaryToString,
104
123
  convertIPv4ToBinary,
105
124
  convertIPv6BinaryToString,
106
125
  convertIPv6ToBinary,
@@ -119,13 +119,13 @@ const getQueryStrings = (url) => {
119
119
  };
120
120
  const getPathNoStrict = (request) => {
121
121
  const result = getPath(request);
122
- return result.length > 1 && result[result.length - 1] === "/" ? result.slice(0, -1) : result;
122
+ return result.length > 1 && result.at(-1) === "/" ? result.slice(0, -1) : result;
123
123
  };
124
124
  const mergePath = (...paths) => {
125
125
  let p = "";
126
126
  let endsWithSlash = false;
127
127
  for (let path of paths) {
128
- if (p[p.length - 1] === "/") {
128
+ if (p.at(-1) === "/") {
129
129
  p = p.slice(0, -1);
130
130
  endsWithSlash = true;
131
131
  }
@@ -97,20 +97,20 @@ var ClientRequestImpl = class {
97
97
  };
98
98
  var hc = (baseUrl, options) => createProxy(function proxyCallback(opts) {
99
99
  const parts = [...opts.path];
100
- if (parts[parts.length - 1] === "toString") {
101
- if (parts[parts.length - 2] === "name") {
102
- return parts[parts.length - 3] || "";
100
+ if (parts.at(-1) === "toString") {
101
+ if (parts.at(-2) === "name") {
102
+ return parts.at(-3) || "";
103
103
  }
104
104
  return proxyCallback.toString();
105
105
  }
106
- if (parts[parts.length - 1] === "valueOf") {
107
- if (parts[parts.length - 2] === "name") {
108
- return parts[parts.length - 3] || "";
106
+ if (parts.at(-1) === "valueOf") {
107
+ if (parts.at(-2) === "name") {
108
+ return parts.at(-3) || "";
109
109
  }
110
110
  return proxyCallback;
111
111
  }
112
112
  let method = "";
113
- if (/^\$/.test(parts[parts.length - 1])) {
113
+ if (/^\$/.test(parts.at(-1))) {
114
114
  const last = parts.pop();
115
115
  if (last) {
116
116
  method = last.replace(/^\$/, "");
@@ -32,7 +32,7 @@ var html = (strings, ...values) => {
32
32
  }
33
33
  }
34
34
  }
35
- buffer[0] += strings[strings.length - 1];
35
+ buffer[0] += strings.at(-1);
36
36
  return buffer.length === 1 ? "callbacks" in buffer ? raw(resolveCallbackSync(raw(buffer[0], buffer.callbacks))) : raw(buffer[0]) : stringBufferToString(buffer, buffer.callbacks);
37
37
  };
38
38
  export {
@@ -68,7 +68,7 @@ var cors = (options) => {
68
68
  return new Response(null, {
69
69
  headers: c.res.headers,
70
70
  status: 204,
71
- statusText: c.res.statusText
71
+ statusText: "No Content"
72
72
  });
73
73
  }
74
74
  await next();
@@ -2,7 +2,7 @@
2
2
  var trimTrailingSlash = () => {
3
3
  return async function trimTrailingSlash2(c, next) {
4
4
  await next();
5
- if (c.res.status === 404 && c.req.method === "GET" && c.req.path !== "/" && c.req.path[c.req.path.length - 1] === "/") {
5
+ if (c.res.status === 404 && c.req.method === "GET" && c.req.path !== "/" && c.req.path.at(-1) === "/") {
6
6
  const url = new URL(c.req.url);
7
7
  url.pathname = url.pathname.substring(0, url.pathname.length - 1);
8
8
  c.res = c.redirect(url.toString(), 301);
@@ -12,7 +12,7 @@ var trimTrailingSlash = () => {
12
12
  var appendTrailingSlash = () => {
13
13
  return async function appendTrailingSlash2(c, next) {
14
14
  await next();
15
- if (c.res.status === 404 && c.req.method === "GET" && c.req.path[c.req.path.length - 1] !== "/") {
15
+ if (c.res.status === 404 && c.req.method === "GET" && c.req.path.at(-1) !== "/") {
16
16
  const url = new URL(c.req.url);
17
17
  url.pathname += "/";
18
18
  c.res = c.redirect(url.toString(), 301);
@@ -4,7 +4,7 @@ var PatternRouter = class {
4
4
  name = "PatternRouter";
5
5
  #routes = [];
6
6
  add(method, path, handler) {
7
- const endsWithWildcard = path[path.length - 1] === "*";
7
+ const endsWithWildcard = path.at(-1) === "*";
8
8
  if (endsWithWildcard) {
9
9
  path = path.slice(0, -2);
10
10
  }
@@ -7,7 +7,10 @@ export type ServeStaticOptions<E extends Env = Env> = BaseServeStaticOptions<E>
7
7
  /**
8
8
  * @deprecated
9
9
  * `serveStatic` in the Cloudflare Workers adapter is deprecated.
10
- * If you want to create an application serving static assets, please consider using Cloudflare Pages.
11
- * You can start to create the Cloudflare Pages application with the `npm create hono@latest` command.
10
+ * You can serve static files directly using Cloudflare Static Assets.
11
+ * @see https://developers.cloudflare.com/workers/static-assets/
12
+ * Cloudflare Static Assets is currently in open beta. If this doesn't work for you,
13
+ * please consider using Cloudflare Pages. You can start to create the Cloudflare Pages
14
+ * application with the `npm create hono@latest` command.
12
15
  */
13
16
  export declare const serveStatic: <E extends Env = Env>(options: ServeStaticOptions<E>) => MiddlewareHandler;
@@ -26,6 +26,12 @@ export declare const convertIPv4ToBinary: (ipv4: string) => bigint;
26
26
  * @returns BigInt
27
27
  */
28
28
  export declare const convertIPv6ToBinary: (ipv6: string) => bigint;
29
+ /**
30
+ * Convert a binary representation of an IPv4 address to a string.
31
+ * @param ipV4 binary IPv4 Address
32
+ * @return IPv4 Address in string
33
+ */
34
+ export declare const convertIPv4BinaryToString: (ipV4: bigint) => string;
29
35
  /**
30
36
  * Convert a binary representation of an IPv6 address to a string.
31
37
  * @param ipV6 binary IPv6 Address
@@ -1,6 +1,13 @@
1
1
  // src/utils/ipaddr.ts
2
2
  var expandIPv6 = (ipV6) => {
3
3
  const sections = ipV6.split(":");
4
+ if (IPV4_REGEX.test(sections.at(-1))) {
5
+ sections.splice(
6
+ -1,
7
+ 1,
8
+ ...convertIPv6BinaryToString(convertIPv4ToBinary(sections.at(-1))).substring(2).split(":")
9
+ );
10
+ }
4
11
  for (let i = 0; i < sections.length; i++) {
5
12
  const node = sections[i];
6
13
  if (node !== "") {
@@ -39,7 +46,17 @@ var convertIPv6ToBinary = (ipv6) => {
39
46
  }
40
47
  return result;
41
48
  };
49
+ var convertIPv4BinaryToString = (ipV4) => {
50
+ const sections = [];
51
+ for (let i = 0; i < 4; i++) {
52
+ sections.push(ipV4 >> BigInt(8 * (3 - i)) & 0xffn);
53
+ }
54
+ return sections.join(".");
55
+ };
42
56
  var convertIPv6BinaryToString = (ipV6) => {
57
+ if (ipV6 >> 32n === 0xffffn) {
58
+ return `::ffff:${convertIPv4BinaryToString(ipV6 & 0xffffffffn)}`;
59
+ }
43
60
  const sections = [];
44
61
  for (let i = 0; i < 8; i++) {
45
62
  sections.push((ipV6 >> BigInt(16 * (7 - i)) & 0xffffn).toString(16));
@@ -74,6 +91,7 @@ var convertIPv6BinaryToString = (ipV6) => {
74
91
  return sections.join(":").replace(/:{2,}/g, "::");
75
92
  };
76
93
  export {
94
+ convertIPv4BinaryToString,
77
95
  convertIPv4ToBinary,
78
96
  convertIPv6BinaryToString,
79
97
  convertIPv6ToBinary,
package/dist/utils/url.js CHANGED
@@ -86,13 +86,13 @@ var getQueryStrings = (url) => {
86
86
  };
87
87
  var getPathNoStrict = (request) => {
88
88
  const result = getPath(request);
89
- return result.length > 1 && result[result.length - 1] === "/" ? result.slice(0, -1) : result;
89
+ return result.length > 1 && result.at(-1) === "/" ? result.slice(0, -1) : result;
90
90
  };
91
91
  var mergePath = (...paths) => {
92
92
  let p = "";
93
93
  let endsWithSlash = false;
94
94
  for (let path of paths) {
95
- if (p[p.length - 1] === "/") {
95
+ if (p.at(-1) === "/") {
96
96
  p = p.slice(0, -1);
97
97
  endsWithSlash = true;
98
98
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "4.6.12",
3
+ "version": "4.6.13",
4
4
  "description": "Web framework built on Web Standards",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",