hono 3.12.1 → 3.12.3

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.
@@ -30,7 +30,8 @@ var createResult = async (res) => {
30
30
  return {
31
31
  status: res.status.toString(),
32
32
  headers: convertHeaders(res.headers),
33
- body
33
+ body,
34
+ ...isBase64Encoded ? { bodyEncoding: "base64" } : {}
34
35
  };
35
36
  };
36
37
  var createRequest = (event) => {
@@ -0,0 +1,2 @@
1
+ // src/adapter/netlify/index.ts
2
+ export * from "./mod.js";
@@ -59,7 +59,8 @@ const createResult = async (res) => {
59
59
  return {
60
60
  status: res.status.toString(),
61
61
  headers: convertHeaders(res.headers),
62
- body
62
+ body,
63
+ ...isBase64Encoded ? { bodyEncoding: "base64" } : {}
63
64
  };
64
65
  };
65
66
  const createRequest = (event) => {
@@ -0,0 +1,18 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var netlify_exports = {};
17
+ module.exports = __toCommonJS(netlify_exports);
18
+ __reExport(netlify_exports, require("./mod"), module.exports);
@@ -27,7 +27,7 @@ const createProxy = (callback, path) => {
27
27
  const proxy = new Proxy(() => {
28
28
  }, {
29
29
  get(_obj, key) {
30
- if (typeof key !== "string")
30
+ if (typeof key !== "string" || key === "then")
31
31
  return void 0;
32
32
  return createProxy(callback, [...path, key]);
33
33
  },
@@ -241,9 +241,17 @@ class Context {
241
241
  __privateSet(this, _isFresh, false);
242
242
  if (__privateGet(this, _res) && _res2) {
243
243
  __privateGet(this, _res).headers.delete("content-type");
244
- __privateGet(this, _res).headers.forEach((v, k) => {
245
- _res2.headers.set(k, v);
246
- });
244
+ for (const [k, v] of __privateGet(this, _res).headers.entries()) {
245
+ if (k === "set-cookie") {
246
+ const cookies = __privateGet(this, _res).headers.getSetCookie();
247
+ _res2.headers.delete("set-cookie");
248
+ for (const cookie of cookies) {
249
+ _res2.headers.append("set-cookie", cookie);
250
+ }
251
+ } else {
252
+ _res2.headers.set(k, v);
253
+ }
254
+ }
247
255
  }
248
256
  __privateSet(this, _res, _res2);
249
257
  this.finalized = true;
@@ -25,9 +25,18 @@ const cache = (options) => {
25
25
  if (options.wait === void 0) {
26
26
  options.wait = false;
27
27
  }
28
- const addHeader = (response) => {
29
- if (options.cacheControl)
30
- response.headers.set("Cache-Control", options.cacheControl);
28
+ const directives = options.cacheControl?.split(",").map((directive) => directive.toLowerCase());
29
+ const addHeader = (c) => {
30
+ if (directives) {
31
+ const existingDirectives = c.res.headers.get("Cache-Control")?.split(",").map((d) => d.trim().split("=", 1)[0]) ?? [];
32
+ for (const directive of directives) {
33
+ let [name, value] = directive.trim().split("=", 2);
34
+ name = name.toLowerCase();
35
+ if (!existingDirectives.includes(name)) {
36
+ c.header("Cache-Control", `${name}${value ? `=${value}` : ""}`, { append: true });
37
+ }
38
+ }
39
+ }
31
40
  };
32
41
  return async function cache2(c, next) {
33
42
  const key = c.req.url;
@@ -38,7 +47,7 @@ const cache = (options) => {
38
47
  if (!c.res.ok) {
39
48
  return;
40
49
  }
41
- addHeader(c.res);
50
+ addHeader(c);
42
51
  const response2 = c.res.clone();
43
52
  if (options.wait) {
44
53
  await cache3.put(key, response2);
@@ -22,6 +22,7 @@ __export(router_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(router_exports);
24
24
  var import_router = require("../../router");
25
+ var import_url = require("../../utils/url");
25
26
  const emptyParams = {};
26
27
  const splitPathRe = /\/(:\w+(?:{[^}]+})?)|\/[^\/\?]+|(\?)/g;
27
28
  const splitByStarRe = /\*/;
@@ -31,12 +32,10 @@ class LinearRouter {
31
32
  this.routes = [];
32
33
  }
33
34
  add(method, path, handler) {
34
- if (path.charCodeAt(path.length - 1) === 63) {
35
- this.routes.push([method, path.slice(0, -1), handler]);
36
- this.routes.push([method, path.replace(/\/[^/]+$/, ""), handler]);
37
- } else {
38
- this.routes.push([method, path, handler]);
39
- }
35
+ ;
36
+ ((0, import_url.checkOptionalParameter)(path) || [path]).forEach((p) => {
37
+ this.routes.push([method, p, handler]);
38
+ });
40
39
  }
41
40
  match(method, path) {
42
41
  const handlers = [];
@@ -167,10 +167,7 @@ class RegExpRouter {
167
167
  (_a2 = routes[m])[path2] || (_a2[path2] = [
168
168
  ...findMiddleware(middleware[m], path2) || findMiddleware(middleware[import_router.METHOD_NAME_ALL], path2) || []
169
169
  ]);
170
- routes[m][path2].push([
171
- handler,
172
- paths.length === 2 && i === 0 ? paramCount - 1 : paramCount
173
- ]);
170
+ routes[m][path2].push([handler, paramCount - len + i + 1]);
174
171
  }
175
172
  });
176
173
  }
@@ -121,12 +121,30 @@ const mergePath = (...paths) => {
121
121
  return p;
122
122
  };
123
123
  const checkOptionalParameter = (path) => {
124
- const match = path.match(/^(.+|)(\/\:[^\/]+)\?$/);
125
- if (!match)
124
+ if (!path.match(/\:.+\?$/))
126
125
  return null;
127
- const base = match[1];
128
- const optional = base + match[2];
129
- return [base === "" ? "/" : base.replace(/\/$/, ""), optional];
126
+ const segments = path.split("/");
127
+ const results = [];
128
+ let basePath = "";
129
+ segments.forEach((segment) => {
130
+ if (segment !== "" && !/\:/.test(segment)) {
131
+ basePath += "/" + segment;
132
+ } else if (/\:/.test(segment)) {
133
+ if (/\?/.test(segment)) {
134
+ if (results.length === 0 && basePath === "") {
135
+ results.push("/");
136
+ } else {
137
+ results.push(basePath);
138
+ }
139
+ const optionalSegment = segment.replace("?", "");
140
+ basePath += "/" + optionalSegment;
141
+ results.push(basePath);
142
+ } else {
143
+ basePath += "/" + segment;
144
+ }
145
+ }
146
+ });
147
+ return results.filter((v, i, a) => a.indexOf(v) === i);
130
148
  };
131
149
  const _decodeURI = (value) => {
132
150
  if (!/[%+]/.test(value)) {
@@ -5,7 +5,7 @@ var createProxy = (callback, path) => {
5
5
  const proxy = new Proxy(() => {
6
6
  }, {
7
7
  get(_obj, key) {
8
- if (typeof key !== "string")
8
+ if (typeof key !== "string" || key === "then")
9
9
  return void 0;
10
10
  return createProxy(callback, [...path, key]);
11
11
  },
package/dist/context.js CHANGED
@@ -219,9 +219,17 @@ var Context = class {
219
219
  __privateSet(this, _isFresh, false);
220
220
  if (__privateGet(this, _res) && _res2) {
221
221
  __privateGet(this, _res).headers.delete("content-type");
222
- __privateGet(this, _res).headers.forEach((v, k) => {
223
- _res2.headers.set(k, v);
224
- });
222
+ for (const [k, v] of __privateGet(this, _res).headers.entries()) {
223
+ if (k === "set-cookie") {
224
+ const cookies = __privateGet(this, _res).headers.getSetCookie();
225
+ _res2.headers.delete("set-cookie");
226
+ for (const cookie of cookies) {
227
+ _res2.headers.append("set-cookie", cookie);
228
+ }
229
+ } else {
230
+ _res2.headers.set(k, v);
231
+ }
232
+ }
225
233
  }
226
234
  __privateSet(this, _res, _res2);
227
235
  this.finalized = true;
@@ -3,9 +3,18 @@ var cache = (options) => {
3
3
  if (options.wait === void 0) {
4
4
  options.wait = false;
5
5
  }
6
- const addHeader = (response) => {
7
- if (options.cacheControl)
8
- response.headers.set("Cache-Control", options.cacheControl);
6
+ const directives = options.cacheControl?.split(",").map((directive) => directive.toLowerCase());
7
+ const addHeader = (c) => {
8
+ if (directives) {
9
+ const existingDirectives = c.res.headers.get("Cache-Control")?.split(",").map((d) => d.trim().split("=", 1)[0]) ?? [];
10
+ for (const directive of directives) {
11
+ let [name, value] = directive.trim().split("=", 2);
12
+ name = name.toLowerCase();
13
+ if (!existingDirectives.includes(name)) {
14
+ c.header("Cache-Control", `${name}${value ? `=${value}` : ""}`, { append: true });
15
+ }
16
+ }
17
+ }
9
18
  };
10
19
  return async function cache2(c, next) {
11
20
  const key = c.req.url;
@@ -16,7 +25,7 @@ var cache = (options) => {
16
25
  if (!c.res.ok) {
17
26
  return;
18
27
  }
19
- addHeader(c.res);
28
+ addHeader(c);
20
29
  const response2 = c.res.clone();
21
30
  if (options.wait) {
22
31
  await cache3.put(key, response2);
@@ -1,5 +1,6 @@
1
1
  // src/router/linear-router/router.ts
2
2
  import { METHOD_NAME_ALL, UnsupportedPathError } from "../../router.js";
3
+ import { checkOptionalParameter } from "../../utils/url.js";
3
4
  var emptyParams = {};
4
5
  var splitPathRe = /\/(:\w+(?:{[^}]+})?)|\/[^\/\?]+|(\?)/g;
5
6
  var splitByStarRe = /\*/;
@@ -9,12 +10,10 @@ var LinearRouter = class {
9
10
  this.routes = [];
10
11
  }
11
12
  add(method, path, handler) {
12
- if (path.charCodeAt(path.length - 1) === 63) {
13
- this.routes.push([method, path.slice(0, -1), handler]);
14
- this.routes.push([method, path.replace(/\/[^/]+$/, ""), handler]);
15
- } else {
16
- this.routes.push([method, path, handler]);
17
- }
13
+ ;
14
+ (checkOptionalParameter(path) || [path]).forEach((p) => {
15
+ this.routes.push([method, p, handler]);
16
+ });
18
17
  }
19
18
  match(method, path) {
20
19
  const handlers = [];
@@ -150,10 +150,7 @@ var RegExpRouter = class {
150
150
  (_a2 = routes[m])[path2] || (_a2[path2] = [
151
151
  ...findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || []
152
152
  ]);
153
- routes[m][path2].push([
154
- handler,
155
- paths.length === 2 && i === 0 ? paramCount - 1 : paramCount
156
- ]);
153
+ routes[m][path2].push([handler, paramCount - len + i + 1]);
157
154
  }
158
155
  });
159
156
  }
@@ -1,5 +1,5 @@
1
1
  import type { Context } from 'https://edge.netlify.com/';
2
- import type { Hono } from '../../';
2
+ import type { Hono } from '../../hono';
3
3
  export type Env = {
4
4
  Bindings: {
5
5
  context: Context;
@@ -0,0 +1 @@
1
+ export * from './mod';
@@ -1,2 +1,2 @@
1
1
  export { hc } from './client';
2
- export type { InferResponseType, InferRequestType, Fetch, ClientRequestOptions } from './types';
2
+ export type { InferResponseType, InferRequestType, Fetch, ClientRequestOptions, ClientRequest, ClientResponse, } from './types';
package/dist/utils/url.js CHANGED
@@ -89,12 +89,30 @@ var mergePath = (...paths) => {
89
89
  return p;
90
90
  };
91
91
  var checkOptionalParameter = (path) => {
92
- const match = path.match(/^(.+|)(\/\:[^\/]+)\?$/);
93
- if (!match)
92
+ if (!path.match(/\:.+\?$/))
94
93
  return null;
95
- const base = match[1];
96
- const optional = base + match[2];
97
- return [base === "" ? "/" : base.replace(/\/$/, ""), optional];
94
+ const segments = path.split("/");
95
+ const results = [];
96
+ let basePath = "";
97
+ segments.forEach((segment) => {
98
+ if (segment !== "" && !/\:/.test(segment)) {
99
+ basePath += "/" + segment;
100
+ } else if (/\:/.test(segment)) {
101
+ if (/\?/.test(segment)) {
102
+ if (results.length === 0 && basePath === "") {
103
+ results.push("/");
104
+ } else {
105
+ results.push(basePath);
106
+ }
107
+ const optionalSegment = segment.replace("?", "");
108
+ basePath += "/" + optionalSegment;
109
+ results.push(basePath);
110
+ } else {
111
+ basePath += "/" + segment;
112
+ }
113
+ }
114
+ });
115
+ return results.filter((v, i, a) => a.indexOf(v) === i);
98
116
  };
99
117
  var _decodeURI = (value) => {
100
118
  if (!/[%+]/.test(value)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "3.12.1",
3
+ "version": "3.12.3",
4
4
  "description": "Ultrafast web framework for the Edges",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",
@@ -269,6 +269,11 @@
269
269
  "import": "./dist/adapter/vercel/index.js",
270
270
  "require": "./dist/cjs/adapter/vercel/index.js"
271
271
  },
272
+ "./netlify": {
273
+ "types": "./dist/types/adapter/netlify/index.d.ts",
274
+ "import": "./dist/adapter/netlify/index.js",
275
+ "require": "./dist/cjs/adapter/netlify/index.js"
276
+ },
272
277
  "./lambda-edge": {
273
278
  "types": "./dist/types/adapter/lambda-edge/index.d.ts",
274
279
  "import": "./dist/adapter/lambda-edge/index.js",