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.
- package/dist/adapter/netlify/index.js +2 -0
- package/dist/cjs/adapter/netlify/index.js +18 -0
- package/dist/cjs/client/client.js +1 -1
- package/dist/cjs/helper/streaming/sse.js +5 -17
- package/dist/cjs/jsx/jsx-dev-runtime.js +1 -1
- package/dist/cjs/middleware/cache/index.js +13 -4
- package/dist/cjs/utils/url.js +23 -5
- package/dist/client/client.js +1 -1
- package/dist/helper/streaming/sse.js +5 -17
- package/dist/jsx/jsx-dev-runtime.js +1 -1
- package/dist/middleware/cache/index.js +13 -4
- package/dist/types/adapter/netlify/handler.d.ts +1 -1
- package/dist/types/adapter/netlify/index.d.ts +1 -0
- package/dist/types/validator/validator.d.ts +4 -3
- package/dist/utils/url.js +23 -5
- package/package.json +14 -1
|
@@ -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);
|
|
@@ -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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
|
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
|
|
29
|
-
|
|
30
|
-
|
|
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
|
|
50
|
+
addHeader(c);
|
|
42
51
|
const response2 = c.res.clone();
|
|
43
52
|
if (options.wait) {
|
|
44
53
|
await cache3.put(key, response2);
|
package/dist/cjs/utils/url.js
CHANGED
|
@@ -121,12 +121,30 @@ const mergePath = (...paths) => {
|
|
|
121
121
|
return p;
|
|
122
122
|
};
|
|
123
123
|
const checkOptionalParameter = (path) => {
|
|
124
|
-
|
|
125
|
-
if (!match)
|
|
124
|
+
if (!path.match(/\:.+\?$/))
|
|
126
125
|
return null;
|
|
127
|
-
const
|
|
128
|
-
const
|
|
129
|
-
|
|
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)) {
|
package/dist/client/client.js
CHANGED
|
@@ -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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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,
|
|
@@ -3,9 +3,18 @@ var cache = (options) => {
|
|
|
3
3
|
if (options.wait === void 0) {
|
|
4
4
|
options.wait = false;
|
|
5
5
|
}
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
28
|
+
addHeader(c);
|
|
20
29
|
const response2 = c.res.clone();
|
|
21
30
|
if (options.wait) {
|
|
22
31
|
await cache3.put(key, response2);
|
|
@@ -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
|
-
|
|
93
|
-
if (!match)
|
|
92
|
+
if (!path.match(/\:.+\?$/))
|
|
94
93
|
return null;
|
|
95
|
-
const
|
|
96
|
-
const
|
|
97
|
-
|
|
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.
|
|
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
|
],
|