hono 3.12.0 → 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
  },
@@ -23,7 +23,6 @@ __export(sse_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(sse_exports);
25
25
  var import_stream = require("../../utils/stream");
26
- var import__ = require(".");
27
26
  class SSEStreamingApi extends import_stream.StreamingApi {
28
27
  constructor(writable, readable) {
29
28
  super(writable, readable);
@@ -43,22 +42,11 @@ const setSSEHeaders = (context) => {
43
42
  context.header("Connection", "keep-alive");
44
43
  };
45
44
  const streamSSE = (c, cb) => {
46
- return (0, import__.stream)(c, async (originalStream) => {
47
- const { readable, writable } = new TransformStream();
48
- const stream2 = new SSEStreamingApi(writable, readable);
49
- originalStream.pipe(stream2.responseReadable).catch((err) => {
50
- console.error("Error in stream piping: ", err);
51
- stream2.close();
52
- });
53
- setSSEHeaders(c);
54
- try {
55
- await cb(stream2);
56
- } catch (err) {
57
- console.error("Error during streaming: ", err);
58
- } finally {
59
- await stream2.close();
60
- }
61
- });
45
+ const { readable, writable } = new TransformStream();
46
+ const stream = new SSEStreamingApi(writable, readable);
47
+ cb(stream).finally(() => stream.close());
48
+ setSSEHeaders(c);
49
+ return c.newResponse(stream.responseReadable);
62
50
  };
63
51
  // Annotate the CommonJS export names for ESM import in node:
64
52
  0 && (module.exports = {
@@ -25,7 +25,7 @@ module.exports = __toCommonJS(jsx_dev_runtime_exports);
25
25
  var import__ = require(".");
26
26
  var import__2 = require(".");
27
27
  function jsxDEV(tag, props) {
28
- if (!props?.children) {
28
+ if (!props || !("children" in props)) {
29
29
  return (0, import__.jsx)(tag, props);
30
30
  }
31
31
  const children = props.children;
@@ -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
  },
@@ -1,6 +1,5 @@
1
1
  // src/helper/streaming/sse.ts
2
2
  import { StreamingApi } from "../../utils/stream.js";
3
- import { stream } from "./index.js";
4
3
  var SSEStreamingApi = class extends StreamingApi {
5
4
  constructor(writable, readable) {
6
5
  super(writable, readable);
@@ -20,22 +19,11 @@ var setSSEHeaders = (context) => {
20
19
  context.header("Connection", "keep-alive");
21
20
  };
22
21
  var streamSSE = (c, cb) => {
23
- return stream(c, async (originalStream) => {
24
- const { readable, writable } = new TransformStream();
25
- const stream2 = new SSEStreamingApi(writable, readable);
26
- originalStream.pipe(stream2.responseReadable).catch((err) => {
27
- console.error("Error in stream piping: ", err);
28
- stream2.close();
29
- });
30
- setSSEHeaders(c);
31
- try {
32
- await cb(stream2);
33
- } catch (err) {
34
- console.error("Error during streaming: ", err);
35
- } finally {
36
- await stream2.close();
37
- }
38
- });
22
+ const { readable, writable } = new TransformStream();
23
+ const stream = new SSEStreamingApi(writable, readable);
24
+ cb(stream).finally(() => stream.close());
25
+ setSSEHeaders(c);
26
+ return c.newResponse(stream.responseReadable);
39
27
  };
40
28
  export {
41
29
  SSEStreamingApi,
@@ -2,7 +2,7 @@
2
2
  import { jsx } from "./index.js";
3
3
  import { Fragment } from "./index.js";
4
4
  function jsxDEV(tag, props) {
5
- if (!props?.children) {
5
+ if (!props || !("children" in props)) {
6
6
  return jsx(tag, props);
7
7
  }
8
8
  const children = props.children;
@@ -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';
@@ -1,13 +1,14 @@
1
1
  import type { Context } from '../context';
2
- import type { Env, ValidationTargets, MiddlewareHandler } from '../types';
2
+ import type { Env, ValidationTargets, MiddlewareHandler, TypedResponse } from '../types';
3
3
  type ValidationTargetKeysWithBody = 'form' | 'json';
4
4
  type ValidationTargetByMethod<M> = M extends 'get' | 'head' ? Exclude<keyof ValidationTargets, ValidationTargetKeysWithBody> : keyof ValidationTargets;
5
5
  export type ValidationFunction<InputType, OutputType, E extends Env = {}, P extends string = string> = (value: InputType, c: Context<E, P>) => OutputType | Response | Promise<OutputType> | Promise<Response>;
6
+ type ExcludeResponseType<T> = T extends Response & TypedResponse<any> ? never : T;
6
7
  export declare const validator: <InputType, P extends string, M extends string, U extends ValidationTargetByMethod<M>, OutputType = ValidationTargets[U], P2 extends string = P, V extends {
7
8
  in: { [K in U]: unknown extends InputType ? OutputType : InputType; };
8
- out: { [K_1 in U]: OutputType; };
9
+ out: { [K_1 in U]: ExcludeResponseType<OutputType>; };
9
10
  } = {
10
11
  in: { [K_2 in U]: unknown extends InputType ? OutputType : InputType; };
11
- out: { [K_3 in U]: OutputType; };
12
+ out: { [K_3 in U]: ExcludeResponseType<OutputType>; };
12
13
  }, E extends Env = any>(target: U, validationFunc: ValidationFunction<unknown extends InputType ? ValidationTargets[U] : InputType, OutputType, E, P2>) => MiddlewareHandler<E, P, V>;
13
14
  export {};
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.0",
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",
@@ -179,6 +179,11 @@
179
179
  "import": "./dist/validator/index.js",
180
180
  "require": "./dist/cjs/validator/index.js"
181
181
  },
182
+ "./router": {
183
+ "types": "./dist/types/router.d.ts",
184
+ "import": "./dist/router.js",
185
+ "require": "./dist/cjs/router.js"
186
+ },
182
187
  "./router/reg-exp-router": {
183
188
  "types": "./dist/types/router/reg-exp-router/index.d.ts",
184
189
  "import": "./dist/router/reg-exp-router/index.js",
@@ -264,6 +269,11 @@
264
269
  "import": "./dist/adapter/vercel/index.js",
265
270
  "require": "./dist/cjs/adapter/vercel/index.js"
266
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
+ },
267
277
  "./lambda-edge": {
268
278
  "types": "./dist/types/adapter/lambda-edge/index.d.ts",
269
279
  "import": "./dist/adapter/lambda-edge/index.js",
@@ -366,6 +376,9 @@
366
376
  "validator": [
367
377
  "./dist/types/validator/index.d.ts"
368
378
  ],
379
+ "router": [
380
+ "./dist/types/router.d.ts"
381
+ ],
369
382
  "router/reg-exp-router": [
370
383
  "./dist/types/router/reg-exp-router/router.d.ts"
371
384
  ],