hono 4.3.11 → 4.4.0
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/README.md +2 -3
- package/dist/adapter/aws-lambda/handler.js +12 -9
- package/dist/adapter/bun/conninfo.js +21 -0
- package/dist/adapter/bun/index.js +2 -0
- package/dist/adapter/bun/websocket.js +1 -3
- package/dist/adapter/cloudflare-workers/conninfo.js +10 -0
- package/dist/adapter/cloudflare-workers/websocket.js +2 -6
- package/dist/adapter/deno/conninfo.js +15 -0
- package/dist/adapter/deno/index.js +2 -0
- package/dist/adapter/lambda-edge/handler.js +3 -3
- package/dist/cjs/adapter/aws-lambda/handler.js +12 -9
- package/dist/cjs/adapter/bun/conninfo.js +44 -0
- package/dist/cjs/adapter/bun/index.js +3 -0
- package/dist/cjs/adapter/cloudflare-workers/conninfo.js +33 -0
- package/dist/cjs/adapter/cloudflare-workers/websocket.js +2 -6
- package/dist/cjs/adapter/deno/conninfo.js +38 -0
- package/dist/cjs/adapter/deno/index.js +3 -0
- package/dist/cjs/adapter/lambda-edge/handler.js +3 -3
- package/dist/cjs/helper/conninfo/index.js +16 -0
- package/dist/cjs/helper/ssg/ssg.js +64 -3
- package/dist/cjs/helper/streaming/text.js +1 -1
- package/dist/cjs/hono-base.js +10 -6
- package/dist/cjs/jsx/base.js +5 -2
- package/dist/cjs/jsx/dom/client.js +68 -0
- package/dist/cjs/jsx/dom/index.js +8 -4
- package/dist/cjs/jsx/dom/jsx-dev-runtime.js +6 -20
- package/dist/cjs/jsx/dom/render.js +41 -25
- package/dist/cjs/jsx/dom/utils.js +15 -0
- package/dist/cjs/jsx/hooks/index.js +4 -1
- package/dist/cjs/jsx/index.js +8 -4
- package/dist/cjs/middleware/jwt/index.js +5 -82
- package/dist/cjs/middleware/jwt/jwt.js +111 -0
- package/dist/cjs/middleware/secure-headers/index.js +3 -123
- package/dist/cjs/middleware/secure-headers/secure-headers.js +150 -0
- package/dist/cjs/middleware/timeout/index.js +48 -0
- package/dist/cjs/middleware/timing/index.js +5 -89
- package/dist/cjs/middleware/timing/timing.js +118 -0
- package/dist/cjs/utils/body.js +34 -9
- package/dist/cjs/utils/jwt/jws.js +4 -5
- package/dist/cjs/utils/jwt/jwt.js +6 -7
- package/dist/cjs/utils/url.js +26 -2
- package/dist/helper/css/index.js +4 -4
- package/dist/helper/html/index.js +1 -1
- package/dist/helper/ssg/ssg.js +63 -5
- package/dist/helper/streaming/text.js +1 -1
- package/dist/hono-base.js +11 -7
- package/dist/jsx/base.js +3 -1
- package/dist/jsx/dom/client.js +44 -0
- package/dist/jsx/dom/css.js +4 -4
- package/dist/jsx/dom/index.js +25 -21
- package/dist/jsx/dom/jsx-dev-runtime.js +6 -20
- package/dist/jsx/dom/render.js +40 -26
- package/dist/jsx/dom/utils.js +14 -0
- package/dist/jsx/hooks/index.js +4 -2
- package/dist/jsx/index.js +22 -18
- package/dist/jsx/jsx-runtime.js +1 -1
- package/dist/middleware/jsx-renderer/index.js +1 -1
- package/dist/middleware/jwt/index.js +1 -78
- package/dist/middleware/jwt/jwt.js +85 -0
- package/dist/middleware/secure-headers/index.js +1 -121
- package/dist/middleware/secure-headers/secure-headers.js +126 -0
- package/dist/middleware/timeout/index.js +25 -0
- package/dist/middleware/timing/index.js +1 -85
- package/dist/middleware/timing/timing.js +92 -0
- package/dist/request.js +1 -1
- package/dist/router/reg-exp-router/router.js +2 -2
- package/dist/router/smart-router/router.js +1 -1
- package/dist/router/trie-router/node.js +1 -1
- package/dist/types/adapter/aws-lambda/handler.d.ts +3 -3
- package/dist/types/adapter/aws-lambda/index.d.ts +4 -0
- package/dist/types/adapter/bun/conninfo.d.ts +7 -0
- package/dist/types/adapter/bun/index.d.ts +5 -0
- package/dist/types/adapter/bun/websocket.d.ts +2 -3
- package/dist/types/adapter/cloudflare-pages/index.d.ts +4 -0
- package/dist/types/adapter/cloudflare-workers/conninfo.d.ts +2 -0
- package/dist/types/adapter/cloudflare-workers/index.d.ts +4 -0
- package/dist/types/adapter/cloudflare-workers/serve-static-module.d.ts +2 -2
- package/dist/types/adapter/cloudflare-workers/serve-static.d.ts +1 -2
- package/dist/types/adapter/cloudflare-workers/utils.d.ts +1 -2
- package/dist/types/adapter/deno/conninfo.d.ts +7 -0
- package/dist/types/adapter/deno/index.d.ts +5 -0
- package/dist/types/adapter/lambda-edge/handler.d.ts +1 -2
- package/dist/types/adapter/lambda-edge/index.d.ts +4 -0
- package/dist/types/adapter/netlify/handler.d.ts +1 -7
- package/dist/types/adapter/netlify/index.d.ts +4 -0
- package/dist/types/adapter/netlify/mod.d.ts +0 -1
- package/dist/types/adapter/vercel/index.d.ts +4 -0
- package/dist/types/client/index.d.ts +4 -0
- package/dist/types/compose.d.ts +1 -1
- package/dist/types/helper/accepts/index.d.ts +4 -0
- package/dist/types/helper/adapter/index.d.ts +4 -0
- package/dist/types/helper/conninfo/index.d.ts +40 -0
- package/dist/types/helper/cookie/index.d.ts +5 -1
- package/dist/types/helper/css/index.d.ts +4 -0
- package/dist/types/helper/dev/index.d.ts +4 -0
- package/dist/types/helper/factory/index.d.ts +4 -0
- package/dist/types/helper/html/index.d.ts +4 -0
- package/dist/types/helper/ssg/index.d.ts +4 -0
- package/dist/types/helper/ssg/ssg.d.ts +6 -3
- package/dist/types/helper/streaming/index.d.ts +4 -0
- package/dist/types/helper/testing/index.d.ts +4 -0
- package/dist/types/helper/websocket/index.d.ts +4 -0
- package/dist/types/hono-base.d.ts +15 -15
- package/dist/types/http-exception.d.ts +4 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/jsx/base.d.ts +10 -11
- package/dist/types/jsx/components.d.ts +1 -1
- package/dist/types/jsx/context.d.ts +1 -1
- package/dist/types/jsx/dom/client.d.ts +26 -0
- package/dist/types/jsx/dom/components.d.ts +2 -2
- package/dist/types/jsx/dom/css.d.ts +31 -20
- package/dist/types/jsx/dom/index.d.ts +13 -7
- package/dist/types/jsx/dom/jsx-dev-runtime.d.ts +5 -1
- package/dist/types/jsx/dom/jsx-runtime.d.ts +4 -0
- package/dist/types/jsx/dom/render.d.ts +4 -3
- package/dist/types/jsx/dom/utils.d.ts +6 -0
- package/dist/types/jsx/hooks/index.d.ts +4 -0
- package/dist/types/jsx/index.d.ts +13 -7
- package/dist/types/jsx/intrinsic-elements.d.ts +629 -630
- package/dist/types/jsx/jsx-dev-runtime.d.ts +5 -0
- package/dist/types/jsx/jsx-runtime.d.ts +5 -0
- package/dist/types/jsx/streaming.d.ts +5 -1
- package/dist/types/jsx/types.d.ts +1 -0
- package/dist/types/middleware/basic-auth/index.d.ts +35 -0
- package/dist/types/middleware/bearer-auth/index.d.ts +33 -0
- package/dist/types/middleware/body-limit/index.d.ts +28 -11
- package/dist/types/middleware/cache/index.d.ts +29 -0
- package/dist/types/middleware/compress/index.d.ts +20 -0
- package/dist/types/middleware/cors/index.d.ts +43 -0
- package/dist/types/middleware/csrf/index.d.ts +41 -0
- package/dist/types/middleware/etag/index.d.ts +24 -0
- package/dist/types/middleware/jsx-renderer/index.d.ts +63 -2
- package/dist/types/middleware/jwt/index.d.ts +5 -17
- package/dist/types/middleware/jwt/jwt.d.ts +48 -0
- package/dist/types/middleware/logger/index.d.ts +20 -0
- package/dist/types/middleware/method-override/index.d.ts +22 -10
- package/dist/types/middleware/powered-by/index.d.ts +4 -0
- package/dist/types/middleware/pretty-json/index.d.ts +23 -0
- package/dist/types/middleware/secure-headers/index.d.ts +6 -64
- package/dist/types/middleware/secure-headers/secure-headers.d.ts +97 -0
- package/dist/types/middleware/serve-static/index.d.ts +4 -0
- package/dist/types/middleware/timeout/index.d.ts +31 -0
- package/dist/types/middleware/timing/index.d.ts +5 -29
- package/dist/types/middleware/timing/timing.d.ts +111 -0
- package/dist/types/middleware/trailing-slash/index.d.ts +29 -5
- package/dist/types/preset/quick.d.ts +4 -0
- package/dist/types/preset/tiny.d.ts +4 -0
- package/dist/types/request.d.ts +5 -4
- package/dist/types/router/linear-router/index.d.ts +4 -0
- package/dist/types/router/linear-router/router.d.ts +1 -1
- package/dist/types/router/pattern-router/index.d.ts +4 -0
- package/dist/types/router/reg-exp-router/index.d.ts +4 -0
- package/dist/types/router/reg-exp-router/router.d.ts +1 -1
- package/dist/types/router/reg-exp-router/trie.d.ts +1 -1
- package/dist/types/router/smart-router/index.d.ts +4 -0
- package/dist/types/router/smart-router/router.d.ts +1 -1
- package/dist/types/router/trie-router/index.d.ts +4 -0
- package/dist/types/router.d.ts +4 -0
- package/dist/types/types.d.ts +4 -0
- package/dist/types/utils/body.d.ts +61 -3
- package/dist/types/utils/buffer.d.ts +4 -0
- package/dist/types/utils/color.d.ts +4 -0
- package/dist/types/utils/concurrent.d.ts +4 -0
- package/dist/types/utils/cookie.d.ts +4 -0
- package/dist/types/utils/crypto.d.ts +4 -0
- package/dist/types/utils/encode.d.ts +4 -0
- package/dist/types/utils/filepath.d.ts +4 -0
- package/dist/types/utils/handler.d.ts +4 -0
- package/dist/types/utils/html.d.ts +4 -0
- package/dist/types/utils/http-status.d.ts +4 -0
- package/dist/types/utils/jwt/index.d.ts +4 -0
- package/dist/types/utils/jwt/jwt.d.ts +3 -3
- package/dist/types/utils/mime.d.ts +4 -0
- package/dist/types/utils/stream.d.ts +4 -0
- package/dist/types/utils/types.d.ts +4 -0
- package/dist/types/utils/url.d.ts +4 -0
- package/dist/types/validator/index.d.ts +4 -0
- package/dist/types/validator/validator.d.ts +1 -1
- package/dist/utils/body.js +34 -9
- package/dist/utils/jwt/index.js +1 -1
- package/dist/utils/jwt/jws.js +1 -2
- package/dist/utils/jwt/jwt.js +5 -5
- package/dist/utils/url.js +26 -2
- package/package.json +27 -6
- package/dist/cjs/adapter/aws-lambda/awslambda.d.js +0 -1
- package/dist/cjs/helper.js +0 -44
- package/dist/helper.js +0 -18
- /package/dist/{adapter/aws-lambda/awslambda.d.js → helper/conninfo/index.js} +0 -0
package/dist/cjs/utils/body.js
CHANGED
|
@@ -22,11 +22,12 @@ __export(body_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(body_exports);
|
|
24
24
|
var import_request = require("../request");
|
|
25
|
-
const parseBody = async (request, options =
|
|
25
|
+
const parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
|
|
26
|
+
const { all = false, dot = false } = options;
|
|
26
27
|
const headers = request instanceof import_request.HonoRequest ? request.raw.headers : request.headers;
|
|
27
28
|
const contentType = headers.get("Content-Type");
|
|
28
29
|
if (contentType !== null && contentType.startsWith("multipart/form-data") || contentType !== null && contentType.startsWith("application/x-www-form-urlencoded")) {
|
|
29
|
-
return parseFormData(request,
|
|
30
|
+
return parseFormData(request, { all, dot });
|
|
30
31
|
}
|
|
31
32
|
return {};
|
|
32
33
|
};
|
|
@@ -38,7 +39,7 @@ async function parseFormData(request, options) {
|
|
|
38
39
|
return {};
|
|
39
40
|
}
|
|
40
41
|
function convertFormDataToBodyData(formData, options) {
|
|
41
|
-
const form =
|
|
42
|
+
const form = /* @__PURE__ */ Object.create(null);
|
|
42
43
|
formData.forEach((value, key) => {
|
|
43
44
|
const shouldParseAllValues = options.all || key.endsWith("[]");
|
|
44
45
|
if (!shouldParseAllValues) {
|
|
@@ -47,19 +48,43 @@ function convertFormDataToBodyData(formData, options) {
|
|
|
47
48
|
handleParsingAllValues(form, key, value);
|
|
48
49
|
}
|
|
49
50
|
});
|
|
51
|
+
if (options.dot) {
|
|
52
|
+
Object.entries(form).forEach(([key, value]) => {
|
|
53
|
+
const shouldParseDotValues = key.includes(".");
|
|
54
|
+
if (shouldParseDotValues) {
|
|
55
|
+
handleParsingNestedValues(form, key, value);
|
|
56
|
+
delete form[key];
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
50
60
|
return form;
|
|
51
61
|
}
|
|
52
62
|
const handleParsingAllValues = (form, key, value) => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
63
|
+
if (form[key] !== void 0) {
|
|
64
|
+
if (Array.isArray(form[key])) {
|
|
65
|
+
;
|
|
66
|
+
form[key].push(value);
|
|
67
|
+
} else {
|
|
68
|
+
form[key] = [form[key], value];
|
|
69
|
+
}
|
|
59
70
|
} else {
|
|
60
71
|
form[key] = value;
|
|
61
72
|
}
|
|
62
73
|
};
|
|
74
|
+
const handleParsingNestedValues = (form, key, value) => {
|
|
75
|
+
let nestedForm = form;
|
|
76
|
+
const keys = key.split(".");
|
|
77
|
+
keys.forEach((key2, index) => {
|
|
78
|
+
if (index === keys.length - 1) {
|
|
79
|
+
nestedForm[key2] = value;
|
|
80
|
+
} else {
|
|
81
|
+
if (!nestedForm[key2] || typeof nestedForm[key2] !== "object" || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) {
|
|
82
|
+
nestedForm[key2] = /* @__PURE__ */ Object.create(null);
|
|
83
|
+
}
|
|
84
|
+
nestedForm = nestedForm[key2];
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
};
|
|
63
88
|
// Annotate the CommonJS export names for ESM import in node:
|
|
64
89
|
0 && (module.exports = {
|
|
65
90
|
parseBody
|
|
@@ -25,7 +25,6 @@ module.exports = __toCommonJS(jws_exports);
|
|
|
25
25
|
var import_adapter = require("../../helper/adapter");
|
|
26
26
|
var import_encode = require("../encode");
|
|
27
27
|
var import_types = require("./types");
|
|
28
|
-
var import_types2 = require("./types");
|
|
29
28
|
var import_utf8 = require("./utf8");
|
|
30
29
|
async function signing(privateKey, alg, data) {
|
|
31
30
|
const algorithm = getKeyAlgorithm(alg);
|
|
@@ -50,7 +49,7 @@ async function importPrivateKey(key, alg) {
|
|
|
50
49
|
}
|
|
51
50
|
return key;
|
|
52
51
|
}
|
|
53
|
-
const usages = [
|
|
52
|
+
const usages = [import_types.CryptoKeyUsage.Sign];
|
|
54
53
|
if (typeof key === "object") {
|
|
55
54
|
return await crypto.subtle.importKey("jwk", key, alg, false, usages);
|
|
56
55
|
}
|
|
@@ -71,11 +70,11 @@ async function importPublicKey(key, alg) {
|
|
|
71
70
|
}
|
|
72
71
|
if (typeof key === "string" && key.includes("PRIVATE")) {
|
|
73
72
|
const privateKey = await crypto.subtle.importKey("pkcs8", pemToBinary(key), alg, true, [
|
|
74
|
-
|
|
73
|
+
import_types.CryptoKeyUsage.Sign
|
|
75
74
|
]);
|
|
76
75
|
key = await exportPublicJwkFrom(privateKey);
|
|
77
76
|
}
|
|
78
|
-
const usages = [
|
|
77
|
+
const usages = [import_types.CryptoKeyUsage.Verify];
|
|
79
78
|
if (typeof key === "object") {
|
|
80
79
|
return await crypto.subtle.importKey("jwk", key, alg, false, usages);
|
|
81
80
|
}
|
|
@@ -95,7 +94,7 @@ async function exportPublicJwkFrom(privateKey) {
|
|
|
95
94
|
const { kty } = jwk;
|
|
96
95
|
const { alg, e, n } = jwk;
|
|
97
96
|
const { crv, x, y } = jwk;
|
|
98
|
-
return { kty, alg, e, n, crv, x, y, key_ops: [
|
|
97
|
+
return { kty, alg, e, n, crv, x, y, key_ops: [import_types.CryptoKeyUsage.Verify] };
|
|
99
98
|
}
|
|
100
99
|
function getKeyAlgorithm(name) {
|
|
101
100
|
switch (name) {
|
|
@@ -28,7 +28,6 @@ var import_encode = require("../../utils/encode");
|
|
|
28
28
|
var import_jwa = require("./jwa");
|
|
29
29
|
var import_jws = require("./jws");
|
|
30
30
|
var import_types = require("./types");
|
|
31
|
-
var import_types2 = require("./types");
|
|
32
31
|
var import_utf8 = require("./utf8");
|
|
33
32
|
const encodeJwtPart = (part) => (0, import_encode.encodeBase64Url)(import_utf8.utf8Encoder.encode(JSON.stringify(part))).replace(/=/g, "");
|
|
34
33
|
const encodeSignaturePart = (buf) => (0, import_encode.encodeBase64Url)(buf).replace(/=/g, "");
|
|
@@ -51,7 +50,7 @@ const sign = async (payload, privateKey, alg = "HS256") => {
|
|
|
51
50
|
const verify = async (token, publicKey, alg = "HS256") => {
|
|
52
51
|
const tokenParts = token.split(".");
|
|
53
52
|
if (tokenParts.length !== 3) {
|
|
54
|
-
throw new
|
|
53
|
+
throw new import_types.JwtTokenInvalid(token);
|
|
55
54
|
}
|
|
56
55
|
const { header, payload } = decode(token);
|
|
57
56
|
if (!isTokenHeader(header)) {
|
|
@@ -59,13 +58,13 @@ const verify = async (token, publicKey, alg = "HS256") => {
|
|
|
59
58
|
}
|
|
60
59
|
const now = Math.floor(Date.now() / 1e3);
|
|
61
60
|
if (payload.nbf && payload.nbf > now) {
|
|
62
|
-
throw new
|
|
61
|
+
throw new import_types.JwtTokenNotBefore(token);
|
|
63
62
|
}
|
|
64
63
|
if (payload.exp && payload.exp <= now) {
|
|
65
|
-
throw new
|
|
64
|
+
throw new import_types.JwtTokenExpired(token);
|
|
66
65
|
}
|
|
67
66
|
if (payload.iat && now < payload.iat) {
|
|
68
|
-
throw new
|
|
67
|
+
throw new import_types.JwtTokenIssuedAt(now, payload.iat);
|
|
69
68
|
}
|
|
70
69
|
const headerPayload = token.substring(0, token.lastIndexOf("."));
|
|
71
70
|
const verified = await (0, import_jws.verifying)(
|
|
@@ -75,7 +74,7 @@ const verify = async (token, publicKey, alg = "HS256") => {
|
|
|
75
74
|
import_utf8.utf8Encoder.encode(headerPayload)
|
|
76
75
|
);
|
|
77
76
|
if (!verified) {
|
|
78
|
-
throw new
|
|
77
|
+
throw new import_types.JwtTokenSignatureMismatched(token);
|
|
79
78
|
}
|
|
80
79
|
return payload;
|
|
81
80
|
};
|
|
@@ -89,7 +88,7 @@ const decode = (token) => {
|
|
|
89
88
|
payload
|
|
90
89
|
};
|
|
91
90
|
} catch (e) {
|
|
92
|
-
throw new
|
|
91
|
+
throw new import_types.JwtTokenInvalid(token);
|
|
93
92
|
}
|
|
94
93
|
};
|
|
95
94
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/cjs/utils/url.js
CHANGED
|
@@ -82,10 +82,34 @@ const getPattern = (label) => {
|
|
|
82
82
|
}
|
|
83
83
|
return null;
|
|
84
84
|
};
|
|
85
|
+
const tryDecodeURI = (str) => {
|
|
86
|
+
try {
|
|
87
|
+
return decodeURI(str);
|
|
88
|
+
} catch {
|
|
89
|
+
return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match) => {
|
|
90
|
+
try {
|
|
91
|
+
return decodeURI(match);
|
|
92
|
+
} catch {
|
|
93
|
+
return match;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
};
|
|
85
98
|
const getPath = (request) => {
|
|
86
99
|
const url = request.url;
|
|
87
|
-
const
|
|
88
|
-
|
|
100
|
+
const start = url.indexOf("/", 8);
|
|
101
|
+
let i = start;
|
|
102
|
+
for (; i < url.length; i++) {
|
|
103
|
+
const charCode = url.charCodeAt(i);
|
|
104
|
+
if (charCode === 37) {
|
|
105
|
+
const queryIndex = url.indexOf("?", i);
|
|
106
|
+
const path = url.slice(start, queryIndex === -1 ? void 0 : queryIndex);
|
|
107
|
+
return tryDecodeURI(path.includes("%25") ? path.replace(/%25/g, "%2525") : path);
|
|
108
|
+
} else if (charCode === 63) {
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return url.slice(start, i);
|
|
89
113
|
};
|
|
90
114
|
const getQueryStrings = (url) => {
|
|
91
115
|
const queryIndex = url.indexOf("?", 8);
|
package/dist/helper/css/index.js
CHANGED
|
@@ -3,12 +3,12 @@ import { raw } from "../../helper/html/index.js";
|
|
|
3
3
|
import { DOM_RENDERER } from "../../jsx/constants.js";
|
|
4
4
|
import { createCssJsxDomObjects } from "../../jsx/dom/css.js";
|
|
5
5
|
import {
|
|
6
|
-
SELECTOR,
|
|
7
6
|
CLASS_NAME,
|
|
8
|
-
STYLE_STRING,
|
|
9
|
-
SELECTORS,
|
|
10
|
-
PSEUDO_GLOBAL_SELECTOR,
|
|
11
7
|
DEFAULT_STYLE_ID,
|
|
8
|
+
PSEUDO_GLOBAL_SELECTOR,
|
|
9
|
+
SELECTOR,
|
|
10
|
+
SELECTORS,
|
|
11
|
+
STYLE_STRING,
|
|
12
12
|
cssCommon,
|
|
13
13
|
cxCommon,
|
|
14
14
|
keyframesCommon,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/helper/html/index.ts
|
|
2
|
-
import { escapeToBuffer,
|
|
2
|
+
import { escapeToBuffer, raw, stringBufferToString } from "../../utils/html.js";
|
|
3
3
|
var html = (strings, ...values) => {
|
|
4
4
|
const buffer = [""];
|
|
5
5
|
for (let i = 0, len = strings.length - 1; i < len; i++) {
|
package/dist/helper/ssg/ssg.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { replaceUrlParam } from "../../client/utils.js";
|
|
3
3
|
import { createPool } from "../../utils/concurrent.js";
|
|
4
4
|
import { getExtension } from "../../utils/mime.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { SSG_CONTEXT, X_HONO_DISABLE_SSG_HEADER_KEY } from "./middleware.js";
|
|
6
|
+
import { dirname, filterStaticGenerateRoutes, joinPaths } from "./utils.js";
|
|
7
7
|
var DEFAULT_CONCURRENCY = 2;
|
|
8
8
|
var DEFAULT_CONTENT_TYPE = "text/plain";
|
|
9
9
|
var generateFilePath = (routePath, outDir, mimeType, extensionMap) => {
|
|
@@ -46,6 +46,52 @@ var determineExtension = (mimeType, userExtensionMap) => {
|
|
|
46
46
|
}
|
|
47
47
|
return getExtension(mimeType) || "html";
|
|
48
48
|
};
|
|
49
|
+
var combineBeforeRequestHooks = (hooks) => {
|
|
50
|
+
if (!Array.isArray(hooks)) {
|
|
51
|
+
return hooks;
|
|
52
|
+
}
|
|
53
|
+
return async (req) => {
|
|
54
|
+
let currentReq = req;
|
|
55
|
+
for (const hook of hooks) {
|
|
56
|
+
const result = await hook(currentReq);
|
|
57
|
+
if (result === false) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
if (result instanceof Request) {
|
|
61
|
+
currentReq = result;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return currentReq;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
var combineAfterResponseHooks = (hooks) => {
|
|
68
|
+
if (!Array.isArray(hooks)) {
|
|
69
|
+
return hooks;
|
|
70
|
+
}
|
|
71
|
+
return async (res) => {
|
|
72
|
+
let currentRes = res;
|
|
73
|
+
for (const hook of hooks) {
|
|
74
|
+
const result = await hook(currentRes);
|
|
75
|
+
if (result === false) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
if (result instanceof Response) {
|
|
79
|
+
currentRes = result;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return currentRes;
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
var combineAfterGenerateHooks = (hooks) => {
|
|
86
|
+
if (!Array.isArray(hooks)) {
|
|
87
|
+
return hooks;
|
|
88
|
+
}
|
|
89
|
+
return async (result) => {
|
|
90
|
+
for (const hook of hooks) {
|
|
91
|
+
await hook(result);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
};
|
|
49
95
|
var fetchRoutesContent = function* (app, beforeRequestHook, afterResponseHook, concurrency) {
|
|
50
96
|
const baseURL = "http://localhost";
|
|
51
97
|
const pool = createPool({ concurrency });
|
|
@@ -147,10 +193,16 @@ var toSSG = async (app, fs, options) => {
|
|
|
147
193
|
try {
|
|
148
194
|
const outputDir = options?.dir ?? "./static";
|
|
149
195
|
const concurrency = options?.concurrency ?? DEFAULT_CONCURRENCY;
|
|
196
|
+
const combinedBeforeRequestHook = combineBeforeRequestHooks(
|
|
197
|
+
options?.beforeRequestHook || ((req) => req)
|
|
198
|
+
);
|
|
199
|
+
const combinedAfterResponseHook = combineAfterResponseHooks(
|
|
200
|
+
options?.afterResponseHook || ((req) => req)
|
|
201
|
+
);
|
|
150
202
|
const getInfoGen = fetchRoutesContent(
|
|
151
203
|
app,
|
|
152
|
-
|
|
153
|
-
|
|
204
|
+
combinedBeforeRequestHook,
|
|
205
|
+
combinedAfterResponseHook,
|
|
154
206
|
concurrency
|
|
155
207
|
);
|
|
156
208
|
for (const getInfo of getInfoGen) {
|
|
@@ -180,10 +232,16 @@ var toSSG = async (app, fs, options) => {
|
|
|
180
232
|
const errorObj = error instanceof Error ? error : new Error(String(error));
|
|
181
233
|
result = { success: false, files: [], error: errorObj };
|
|
182
234
|
}
|
|
183
|
-
|
|
235
|
+
if (options?.afterGenerateHook) {
|
|
236
|
+
const conbinedAfterGenerateHooks = combineAfterGenerateHooks(options?.afterGenerateHook);
|
|
237
|
+
await conbinedAfterGenerateHooks(result);
|
|
238
|
+
}
|
|
184
239
|
return result;
|
|
185
240
|
};
|
|
186
241
|
export {
|
|
242
|
+
combineAfterGenerateHooks,
|
|
243
|
+
combineAfterResponseHooks,
|
|
244
|
+
combineBeforeRequestHooks,
|
|
187
245
|
defaultExtensionMap,
|
|
188
246
|
fetchRoutesContent,
|
|
189
247
|
saveContentToFile,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/helper/streaming/text.ts
|
|
2
2
|
import { TEXT_PLAIN } from "../../context.js";
|
|
3
|
-
import { stream } from "
|
|
3
|
+
import { stream } from ".//index.js";
|
|
4
4
|
var streamText = (c, cb, onError) => {
|
|
5
5
|
c.header("Content-Type", TEXT_PLAIN);
|
|
6
6
|
c.header("X-Content-Type-Options", "nosniff");
|
package/dist/hono-base.js
CHANGED
|
@@ -3,13 +3,9 @@ import { compose } from "./compose.js";
|
|
|
3
3
|
import { Context } from "./context.js";
|
|
4
4
|
import { HTTPException } from "./http-exception.js";
|
|
5
5
|
import { HonoRequest } from "./request.js";
|
|
6
|
-
import { METHOD_NAME_ALL, METHOD_NAME_ALL_LOWERCASE
|
|
6
|
+
import { METHODS, METHOD_NAME_ALL, METHOD_NAME_ALL_LOWERCASE } from "./router.js";
|
|
7
7
|
import { getPath, getPathNoStrict, getQueryStrings, mergePath } from "./utils/url.js";
|
|
8
8
|
var COMPOSED_HANDLER = Symbol("composedHandler");
|
|
9
|
-
function defineDynamicClass() {
|
|
10
|
-
return class {
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
9
|
var notFoundHandler = (c) => {
|
|
14
10
|
return c.text("404 Not Found", 404);
|
|
15
11
|
};
|
|
@@ -20,14 +16,22 @@ var errorHandler = (err, c) => {
|
|
|
20
16
|
console.error(err);
|
|
21
17
|
return c.text("Internal Server Error", 500);
|
|
22
18
|
};
|
|
23
|
-
var Hono = class
|
|
19
|
+
var Hono = class {
|
|
20
|
+
get;
|
|
21
|
+
post;
|
|
22
|
+
put;
|
|
23
|
+
delete;
|
|
24
|
+
options;
|
|
25
|
+
patch;
|
|
26
|
+
all;
|
|
27
|
+
on;
|
|
28
|
+
use;
|
|
24
29
|
router;
|
|
25
30
|
getPath;
|
|
26
31
|
_basePath = "/";
|
|
27
32
|
#path = "/";
|
|
28
33
|
routes = [];
|
|
29
34
|
constructor(options = {}) {
|
|
30
|
-
super();
|
|
31
35
|
const allMethods = [...METHODS, METHOD_NAME_ALL_LOWERCASE];
|
|
32
36
|
allMethods.forEach((method) => {
|
|
33
37
|
this[method] = (args1, ...args) => {
|
package/dist/jsx/base.js
CHANGED
|
@@ -261,6 +261,7 @@ var cloneElement = (element, props, ...children) => {
|
|
|
261
261
|
...children
|
|
262
262
|
);
|
|
263
263
|
};
|
|
264
|
+
var reactAPICompatVersion = "18.0.0-hono-jsx";
|
|
264
265
|
export {
|
|
265
266
|
Fragment,
|
|
266
267
|
JSXFragmentNode,
|
|
@@ -269,5 +270,6 @@ export {
|
|
|
269
270
|
isValidElement,
|
|
270
271
|
jsx,
|
|
271
272
|
jsxFn,
|
|
272
|
-
memo
|
|
273
|
+
memo,
|
|
274
|
+
reactAPICompatVersion
|
|
273
275
|
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// src/jsx/dom/client.ts
|
|
2
|
+
import { useState } from "../hooks/index.js";
|
|
3
|
+
import { buildNode, renderNode } from "./render.js";
|
|
4
|
+
var createRoot = (element, options = {}) => {
|
|
5
|
+
let setJsxNode = void 0;
|
|
6
|
+
if (Object.keys(options).length > 0) {
|
|
7
|
+
console.warn("createRoot options are not supported yet");
|
|
8
|
+
}
|
|
9
|
+
return {
|
|
10
|
+
render(jsxNode) {
|
|
11
|
+
if (setJsxNode === null) {
|
|
12
|
+
throw new Error("Cannot update an unmounted root");
|
|
13
|
+
}
|
|
14
|
+
if (setJsxNode) {
|
|
15
|
+
setJsxNode(jsxNode);
|
|
16
|
+
} else {
|
|
17
|
+
renderNode(
|
|
18
|
+
buildNode({
|
|
19
|
+
tag: () => {
|
|
20
|
+
const [_jsxNode, _setJsxNode] = useState(jsxNode);
|
|
21
|
+
setJsxNode = _setJsxNode;
|
|
22
|
+
return _jsxNode;
|
|
23
|
+
},
|
|
24
|
+
props: {}
|
|
25
|
+
}),
|
|
26
|
+
element
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
unmount() {
|
|
31
|
+
setJsxNode?.(null);
|
|
32
|
+
setJsxNode = null;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
var hydrateRoot = (element, reactNode, options = {}) => {
|
|
37
|
+
const root = createRoot(element, options);
|
|
38
|
+
root.render(reactNode);
|
|
39
|
+
return root;
|
|
40
|
+
};
|
|
41
|
+
export {
|
|
42
|
+
createRoot,
|
|
43
|
+
hydrateRoot
|
|
44
|
+
};
|
package/dist/jsx/dom/css.js
CHANGED
package/dist/jsx/dom/index.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
// src/jsx/dom/index.ts
|
|
2
|
-
import { memo,
|
|
2
|
+
import { isValidElement, memo, reactAPICompatVersion } from "../base.js";
|
|
3
3
|
import { Children } from "../children.js";
|
|
4
4
|
import { useContext } from "../context.js";
|
|
5
5
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
useRef,
|
|
9
|
-
useCallback,
|
|
10
|
-
use,
|
|
6
|
+
createRef,
|
|
7
|
+
forwardRef,
|
|
11
8
|
startTransition,
|
|
12
|
-
useTransition,
|
|
13
|
-
useDeferredValue,
|
|
14
9
|
startViewTransition,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
useLayoutEffect,
|
|
18
|
-
useReducer,
|
|
19
|
-
useId,
|
|
10
|
+
use,
|
|
11
|
+
useCallback,
|
|
20
12
|
useDebugValue,
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
useDeferredValue,
|
|
14
|
+
useEffect,
|
|
15
|
+
useId,
|
|
23
16
|
useImperativeHandle,
|
|
24
|
-
|
|
17
|
+
useInsertionEffect,
|
|
18
|
+
useLayoutEffect,
|
|
19
|
+
useMemo,
|
|
20
|
+
useReducer,
|
|
21
|
+
useRef,
|
|
22
|
+
useState,
|
|
23
|
+
useSyncExternalStore,
|
|
24
|
+
useTransition,
|
|
25
|
+
useViewTransition
|
|
25
26
|
} from "../hooks/index.js";
|
|
26
|
-
import {
|
|
27
|
+
import { ErrorBoundary, Suspense } from "./components.js";
|
|
27
28
|
import { createContext } from "./context.js";
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
29
|
+
import { Fragment, jsx } from "./jsx-runtime.js";
|
|
30
|
+
import { createPortal, flushSync } from "./render.js";
|
|
30
31
|
import { render } from "./render.js";
|
|
31
|
-
export * from "../types.js";
|
|
32
32
|
var createElement = (tag, props, ...children) => {
|
|
33
33
|
const jsxProps = props ? { ...props } : {};
|
|
34
34
|
if (children.length) {
|
|
@@ -53,6 +53,7 @@ var cloneElement = (element, props, ...children) => {
|
|
|
53
53
|
);
|
|
54
54
|
};
|
|
55
55
|
var dom_default = {
|
|
56
|
+
version: reactAPICompatVersion,
|
|
56
57
|
useState,
|
|
57
58
|
useEffect,
|
|
58
59
|
useRef,
|
|
@@ -65,6 +66,7 @@ var dom_default = {
|
|
|
65
66
|
useViewTransition,
|
|
66
67
|
useMemo,
|
|
67
68
|
useLayoutEffect,
|
|
69
|
+
useInsertionEffect,
|
|
68
70
|
useReducer,
|
|
69
71
|
useId,
|
|
70
72
|
useDebugValue,
|
|
@@ -112,6 +114,7 @@ export {
|
|
|
112
114
|
useEffect,
|
|
113
115
|
useId,
|
|
114
116
|
useImperativeHandle,
|
|
117
|
+
useInsertionEffect,
|
|
115
118
|
useLayoutEffect,
|
|
116
119
|
useMemo,
|
|
117
120
|
useReducer,
|
|
@@ -119,5 +122,6 @@ export {
|
|
|
119
122
|
useState,
|
|
120
123
|
useSyncExternalStore,
|
|
121
124
|
useTransition,
|
|
122
|
-
useViewTransition
|
|
125
|
+
useViewTransition,
|
|
126
|
+
reactAPICompatVersion as version
|
|
123
127
|
};
|
|
@@ -1,29 +1,15 @@
|
|
|
1
1
|
// src/jsx/dom/jsx-dev-runtime.ts
|
|
2
2
|
import { normalizeIntrinsicElementProps } from "../utils.js";
|
|
3
|
-
|
|
4
|
-
type: {
|
|
5
|
-
get() {
|
|
6
|
-
return this.tag;
|
|
7
|
-
}
|
|
8
|
-
},
|
|
9
|
-
ref: {
|
|
10
|
-
get() {
|
|
11
|
-
return this.props?.ref;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
};
|
|
3
|
+
import { newJSXNode } from "./utils.js";
|
|
15
4
|
var jsxDEV = (tag, props, key) => {
|
|
16
5
|
if (typeof tag === "string") {
|
|
17
6
|
normalizeIntrinsicElementProps(props);
|
|
18
7
|
}
|
|
19
|
-
return
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
},
|
|
25
|
-
JSXNodeCompatPrototype
|
|
26
|
-
);
|
|
8
|
+
return newJSXNode({
|
|
9
|
+
tag,
|
|
10
|
+
props,
|
|
11
|
+
key
|
|
12
|
+
});
|
|
27
13
|
};
|
|
28
14
|
var Fragment = (props) => jsxDEV("", props, void 0);
|
|
29
15
|
export {
|