hono 4.1.2 → 4.1.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.
- package/dist/cjs/helper/ssg/ssg.js +9 -8
- package/dist/cjs/helper.js +16 -0
- package/dist/cjs/jsx/base.js +4 -2
- package/dist/cjs/validator/validator.js +30 -13
- package/dist/helper/ssg/ssg.js +9 -8
- package/dist/helper.js +6 -0
- package/dist/jsx/base.js +4 -2
- package/dist/types/helper/ssg/ssg.d.ts +2 -2
- package/dist/validator/validator.js +30 -13
- package/package.json +1 -1
|
@@ -74,15 +74,16 @@ const fetchRoutesContent = function* (app, beforeRequestHook, afterResponseHook,
|
|
|
74
74
|
for (const route of (0, import_utils2.filterStaticGenerateRoutes)(app)) {
|
|
75
75
|
const thisRouteBaseURL = new URL(route.path, baseURL).toString();
|
|
76
76
|
let forGetInfoURLRequest = new Request(thisRouteBaseURL);
|
|
77
|
-
if (beforeRequestHook) {
|
|
78
|
-
const maybeRequest = beforeRequestHook(forGetInfoURLRequest);
|
|
79
|
-
if (!maybeRequest) {
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
forGetInfoURLRequest = maybeRequest;
|
|
83
|
-
}
|
|
84
77
|
yield new Promise(async (resolveGetInfo, rejectGetInfo) => {
|
|
85
78
|
try {
|
|
79
|
+
if (beforeRequestHook) {
|
|
80
|
+
const maybeRequest = await beforeRequestHook(forGetInfoURLRequest);
|
|
81
|
+
if (!maybeRequest) {
|
|
82
|
+
resolveGetInfo(void 0);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
forGetInfoURLRequest = maybeRequest;
|
|
86
|
+
}
|
|
86
87
|
await pool.run(() => app.fetch(forGetInfoURLRequest));
|
|
87
88
|
if (!forGetInfoURLRequest.ssgParams) {
|
|
88
89
|
if (isDynamicRoute(route.path)) {
|
|
@@ -111,7 +112,7 @@ const fetchRoutesContent = function* (app, beforeRequestHook, afterResponseHook,
|
|
|
111
112
|
return;
|
|
112
113
|
}
|
|
113
114
|
if (afterResponseHook) {
|
|
114
|
-
const maybeResponse = afterResponseHook(response);
|
|
115
|
+
const maybeResponse = await afterResponseHook(response);
|
|
115
116
|
if (!maybeResponse) {
|
|
116
117
|
resolveReq(void 0);
|
|
117
118
|
return;
|
package/dist/cjs/helper.js
CHANGED
|
@@ -3,6 +3,10 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
6
10
|
var __copyProps = (to, from, except, desc) => {
|
|
7
11
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
12
|
for (let key of __getOwnPropNames(from))
|
|
@@ -14,6 +18,11 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
14
18
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
20
|
var helper_exports = {};
|
|
21
|
+
__export(helper_exports, {
|
|
22
|
+
jwtDecode: () => import_jwt.decode,
|
|
23
|
+
jwtSign: () => import_jwt.sign,
|
|
24
|
+
jwtVerify: () => import_jwt.verify
|
|
25
|
+
});
|
|
17
26
|
module.exports = __toCommonJS(helper_exports);
|
|
18
27
|
__reExport(helper_exports, require("./helper/accepts"), module.exports);
|
|
19
28
|
__reExport(helper_exports, require("./helper/adapter"), module.exports);
|
|
@@ -26,3 +35,10 @@ __reExport(helper_exports, require("./helper/testing"), module.exports);
|
|
|
26
35
|
__reExport(helper_exports, require("./helper/dev"), module.exports);
|
|
27
36
|
__reExport(helper_exports, require("./adapter/deno/ssg"), module.exports);
|
|
28
37
|
__reExport(helper_exports, require("./adapter/deno/websocket"), module.exports);
|
|
38
|
+
var import_jwt = require("./middleware/jwt");
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
jwtDecode,
|
|
42
|
+
jwtSign,
|
|
43
|
+
jwtVerify
|
|
44
|
+
});
|
package/dist/cjs/jsx/base.js
CHANGED
|
@@ -135,7 +135,9 @@ class JSXNode {
|
|
|
135
135
|
const property = k.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
136
136
|
return `${property}:${v[k]}`;
|
|
137
137
|
}).join(";");
|
|
138
|
-
buffer[0] +=
|
|
138
|
+
buffer[0] += ' style="';
|
|
139
|
+
(0, import_html2.escapeToBuffer)(styles, buffer);
|
|
140
|
+
buffer[0] += '"';
|
|
139
141
|
} else if (typeof v === "string") {
|
|
140
142
|
buffer[0] += ` ${key}="`;
|
|
141
143
|
(0, import_html2.escapeToBuffer)(v, buffer);
|
|
@@ -165,7 +167,7 @@ class JSXNode {
|
|
|
165
167
|
buffer[0] += '"';
|
|
166
168
|
}
|
|
167
169
|
}
|
|
168
|
-
if (emptyTags.includes(tag)) {
|
|
170
|
+
if (emptyTags.includes(tag) && children.length === 0) {
|
|
169
171
|
buffer[0] += "/>";
|
|
170
172
|
return;
|
|
171
173
|
}
|
|
@@ -28,6 +28,7 @@ const validator = (target, validationFunc) => {
|
|
|
28
28
|
return async (c, next) => {
|
|
29
29
|
let value = {};
|
|
30
30
|
const contentType = c.req.header("Content-Type");
|
|
31
|
+
const bodyTypes = ["text", "arrayBuffer", "blob"];
|
|
31
32
|
switch (target) {
|
|
32
33
|
case "json":
|
|
33
34
|
if (!contentType || !contentType.startsWith("application/json")) {
|
|
@@ -35,11 +36,19 @@ const validator = (target, validationFunc) => {
|
|
|
35
36
|
throw new import_http_exception.HTTPException(400, { message });
|
|
36
37
|
}
|
|
37
38
|
if (c.req.bodyCache.json) {
|
|
38
|
-
value =
|
|
39
|
+
value = c.req.bodyCache.json;
|
|
39
40
|
break;
|
|
40
41
|
}
|
|
41
42
|
try {
|
|
42
|
-
|
|
43
|
+
let arrayBuffer = void 0;
|
|
44
|
+
for (const type of bodyTypes) {
|
|
45
|
+
const body = c.req.bodyCache[type];
|
|
46
|
+
if (body) {
|
|
47
|
+
arrayBuffer = await new Response(await body).arrayBuffer();
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
arrayBuffer ??= await c.req.raw.arrayBuffer();
|
|
43
52
|
value = await new Response(arrayBuffer).json();
|
|
44
53
|
c.req.bodyCache.json = value;
|
|
45
54
|
c.req.bodyCache.arrayBuffer = arrayBuffer;
|
|
@@ -49,23 +58,31 @@ const validator = (target, validationFunc) => {
|
|
|
49
58
|
}
|
|
50
59
|
break;
|
|
51
60
|
case "form": {
|
|
61
|
+
if (!contentType) {
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
52
64
|
if (c.req.bodyCache.formData) {
|
|
53
65
|
value = c.req.bodyCache.formData;
|
|
54
66
|
break;
|
|
55
67
|
}
|
|
56
68
|
try {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
});
|
|
65
|
-
value = form;
|
|
66
|
-
c.req.bodyCache.formData = formData;
|
|
67
|
-
c.req.bodyCache.arrayBuffer = arrayBuffer;
|
|
69
|
+
let arrayBuffer = void 0;
|
|
70
|
+
for (const type of bodyTypes) {
|
|
71
|
+
const body = c.req.bodyCache[type];
|
|
72
|
+
if (body) {
|
|
73
|
+
arrayBuffer = await new Response(await body).arrayBuffer();
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
68
76
|
}
|
|
77
|
+
arrayBuffer ??= await c.req.arrayBuffer();
|
|
78
|
+
const formData = await (0, import_buffer.bufferToFormData)(arrayBuffer, contentType);
|
|
79
|
+
const form = {};
|
|
80
|
+
formData.forEach((value2, key) => {
|
|
81
|
+
form[key] = value2;
|
|
82
|
+
});
|
|
83
|
+
value = form;
|
|
84
|
+
c.req.bodyCache.formData = formData;
|
|
85
|
+
c.req.bodyCache.arrayBuffer = arrayBuffer;
|
|
69
86
|
} catch (e) {
|
|
70
87
|
let message = "Malformed FormData request.";
|
|
71
88
|
message += e instanceof Error ? ` ${e.message}` : ` ${String(e)}`;
|
package/dist/helper/ssg/ssg.js
CHANGED
|
@@ -50,15 +50,16 @@ var fetchRoutesContent = function* (app, beforeRequestHook, afterResponseHook, c
|
|
|
50
50
|
for (const route of filterStaticGenerateRoutes(app)) {
|
|
51
51
|
const thisRouteBaseURL = new URL(route.path, baseURL).toString();
|
|
52
52
|
let forGetInfoURLRequest = new Request(thisRouteBaseURL);
|
|
53
|
-
if (beforeRequestHook) {
|
|
54
|
-
const maybeRequest = beforeRequestHook(forGetInfoURLRequest);
|
|
55
|
-
if (!maybeRequest) {
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
forGetInfoURLRequest = maybeRequest;
|
|
59
|
-
}
|
|
60
53
|
yield new Promise(async (resolveGetInfo, rejectGetInfo) => {
|
|
61
54
|
try {
|
|
55
|
+
if (beforeRequestHook) {
|
|
56
|
+
const maybeRequest = await beforeRequestHook(forGetInfoURLRequest);
|
|
57
|
+
if (!maybeRequest) {
|
|
58
|
+
resolveGetInfo(void 0);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
forGetInfoURLRequest = maybeRequest;
|
|
62
|
+
}
|
|
62
63
|
await pool.run(() => app.fetch(forGetInfoURLRequest));
|
|
63
64
|
if (!forGetInfoURLRequest.ssgParams) {
|
|
64
65
|
if (isDynamicRoute(route.path)) {
|
|
@@ -87,7 +88,7 @@ var fetchRoutesContent = function* (app, beforeRequestHook, afterResponseHook, c
|
|
|
87
88
|
return;
|
|
88
89
|
}
|
|
89
90
|
if (afterResponseHook) {
|
|
90
|
-
const maybeResponse = afterResponseHook(response);
|
|
91
|
+
const maybeResponse = await afterResponseHook(response);
|
|
91
92
|
if (!maybeResponse) {
|
|
92
93
|
resolveReq(void 0);
|
|
93
94
|
return;
|
package/dist/helper.js
CHANGED
|
@@ -10,3 +10,9 @@ export * from "./helper/testing/index.js";
|
|
|
10
10
|
export * from "./helper/dev/index.js";
|
|
11
11
|
export * from "./adapter/deno/ssg.js";
|
|
12
12
|
export * from "./adapter/deno/websocket.js";
|
|
13
|
+
import { decode, sign, verify } from "./middleware/jwt/index.js";
|
|
14
|
+
export {
|
|
15
|
+
decode as jwtDecode,
|
|
16
|
+
sign as jwtSign,
|
|
17
|
+
verify as jwtVerify
|
|
18
|
+
};
|
package/dist/jsx/base.js
CHANGED
|
@@ -106,7 +106,9 @@ var JSXNode = class {
|
|
|
106
106
|
const property = k.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
107
107
|
return `${property}:${v[k]}`;
|
|
108
108
|
}).join(";");
|
|
109
|
-
buffer[0] +=
|
|
109
|
+
buffer[0] += ' style="';
|
|
110
|
+
escapeToBuffer(styles, buffer);
|
|
111
|
+
buffer[0] += '"';
|
|
110
112
|
} else if (typeof v === "string") {
|
|
111
113
|
buffer[0] += ` ${key}="`;
|
|
112
114
|
escapeToBuffer(v, buffer);
|
|
@@ -136,7 +138,7 @@ var JSXNode = class {
|
|
|
136
138
|
buffer[0] += '"';
|
|
137
139
|
}
|
|
138
140
|
}
|
|
139
|
-
if (emptyTags.includes(tag)) {
|
|
141
|
+
if (emptyTags.includes(tag) && children.length === 0) {
|
|
140
142
|
buffer[0] += "/>";
|
|
141
143
|
return;
|
|
142
144
|
}
|
|
@@ -21,8 +21,8 @@ export interface ToSSGResult {
|
|
|
21
21
|
files: string[];
|
|
22
22
|
error?: Error;
|
|
23
23
|
}
|
|
24
|
-
export type BeforeRequestHook = (req: Request) => Request | false
|
|
25
|
-
export type AfterResponseHook = (res: Response) => Response | false
|
|
24
|
+
export type BeforeRequestHook = (req: Request) => Request | false | Promise<Request | false>;
|
|
25
|
+
export type AfterResponseHook = (res: Response) => Response | false | Promise<Response | false>;
|
|
26
26
|
export type AfterGenerateHook = (result: ToSSGResult) => void | Promise<void>;
|
|
27
27
|
export interface ToSSGOptions {
|
|
28
28
|
dir?: string;
|
|
@@ -6,6 +6,7 @@ var validator = (target, validationFunc) => {
|
|
|
6
6
|
return async (c, next) => {
|
|
7
7
|
let value = {};
|
|
8
8
|
const contentType = c.req.header("Content-Type");
|
|
9
|
+
const bodyTypes = ["text", "arrayBuffer", "blob"];
|
|
9
10
|
switch (target) {
|
|
10
11
|
case "json":
|
|
11
12
|
if (!contentType || !contentType.startsWith("application/json")) {
|
|
@@ -13,11 +14,19 @@ var validator = (target, validationFunc) => {
|
|
|
13
14
|
throw new HTTPException(400, { message });
|
|
14
15
|
}
|
|
15
16
|
if (c.req.bodyCache.json) {
|
|
16
|
-
value =
|
|
17
|
+
value = c.req.bodyCache.json;
|
|
17
18
|
break;
|
|
18
19
|
}
|
|
19
20
|
try {
|
|
20
|
-
|
|
21
|
+
let arrayBuffer = void 0;
|
|
22
|
+
for (const type of bodyTypes) {
|
|
23
|
+
const body = c.req.bodyCache[type];
|
|
24
|
+
if (body) {
|
|
25
|
+
arrayBuffer = await new Response(await body).arrayBuffer();
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
arrayBuffer ??= await c.req.raw.arrayBuffer();
|
|
21
30
|
value = await new Response(arrayBuffer).json();
|
|
22
31
|
c.req.bodyCache.json = value;
|
|
23
32
|
c.req.bodyCache.arrayBuffer = arrayBuffer;
|
|
@@ -27,23 +36,31 @@ var validator = (target, validationFunc) => {
|
|
|
27
36
|
}
|
|
28
37
|
break;
|
|
29
38
|
case "form": {
|
|
39
|
+
if (!contentType) {
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
30
42
|
if (c.req.bodyCache.formData) {
|
|
31
43
|
value = c.req.bodyCache.formData;
|
|
32
44
|
break;
|
|
33
45
|
}
|
|
34
46
|
try {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
});
|
|
43
|
-
value = form;
|
|
44
|
-
c.req.bodyCache.formData = formData;
|
|
45
|
-
c.req.bodyCache.arrayBuffer = arrayBuffer;
|
|
47
|
+
let arrayBuffer = void 0;
|
|
48
|
+
for (const type of bodyTypes) {
|
|
49
|
+
const body = c.req.bodyCache[type];
|
|
50
|
+
if (body) {
|
|
51
|
+
arrayBuffer = await new Response(await body).arrayBuffer();
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
46
54
|
}
|
|
55
|
+
arrayBuffer ??= await c.req.arrayBuffer();
|
|
56
|
+
const formData = await bufferToFormData(arrayBuffer, contentType);
|
|
57
|
+
const form = {};
|
|
58
|
+
formData.forEach((value2, key) => {
|
|
59
|
+
form[key] = value2;
|
|
60
|
+
});
|
|
61
|
+
value = form;
|
|
62
|
+
c.req.bodyCache.formData = formData;
|
|
63
|
+
c.req.bodyCache.arrayBuffer = arrayBuffer;
|
|
47
64
|
} catch (e) {
|
|
48
65
|
let message = "Malformed FormData request.";
|
|
49
66
|
message += e instanceof Error ? ` ${e.message}` : ` ${String(e)}`;
|