hono 3.12.1 → 3.12.2

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.
@@ -0,0 +1,2 @@
1
+ // src/adapter/netlify/index.ts
2
+ export * from "./mod.js";
@@ -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
  },
@@ -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);
@@ -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
  },
@@ -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,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';
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.2",
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",