@orchestraai/agent-tools 0.10.16 → 0.10.18
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/.agents/plugins/marketplace.json +1 -1
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/.cursor-plugin/plugin.json +1 -1
- package/.devin/adapter.json +1 -1
- package/.hermes/adapter.json +1 -1
- package/.opencode/adapter.json +1 -1
- package/dist/commands/claude-setup.d.ts +1 -1
- package/dist/runtime/conversation/command-guard.js +1347 -63
- package/dist/runtime/conversation/command-guard.js.map +1 -1
- package/dist/runtime/conversation/shell-parse.d.ts +44 -0
- package/dist/runtime/conversation/shell-parse.js +525 -0
- package/dist/runtime/conversation/shell-parse.js.map +1 -0
- package/docs/security.md +18 -2
- package/node_modules/@hono/node-server/dist/index.cjs +63 -17
- package/node_modules/@hono/node-server/dist/index.mjs +63 -17
- package/node_modules/@hono/node-server/dist/serve-static.cjs +1 -1
- package/node_modules/@hono/node-server/dist/serve-static.mjs +1 -1
- package/node_modules/@hono/node-server/package.json +1 -1
- package/node_modules/cross-spawn/README.md +19 -3
- package/node_modules/cross-spawn/lib/parse.js +38 -10
- package/node_modules/cross-spawn/lib/util/escape.js +84 -25
- package/node_modules/cross-spawn/lib/util/readShebang.js +8 -2
- package/node_modules/cross-spawn/lib/util/resolveCommand.js +8 -1
- package/node_modules/cross-spawn/package.json +21 -24
- package/node_modules/hono/README.md +2 -3
- package/node_modules/hono/dist/adapter/aws-lambda/handler.js +2 -2
- package/node_modules/hono/dist/adapter/bun/websocket.js +19 -4
- package/node_modules/hono/dist/adapter/lambda-edge/handler.js +5 -1
- package/node_modules/hono/dist/cjs/adapter/aws-lambda/handler.js +2 -2
- package/node_modules/hono/dist/cjs/adapter/bun/websocket.js +19 -4
- package/node_modules/hono/dist/cjs/adapter/lambda-edge/handler.js +5 -1
- package/node_modules/hono/dist/cjs/client/fetch-result-please.js +1 -1
- package/node_modules/hono/dist/cjs/client/utils.js +9 -5
- package/node_modules/hono/dist/cjs/context.js +1 -1
- package/node_modules/hono/dist/cjs/helper/accepts/accepts.js +7 -1
- package/node_modules/hono/dist/cjs/helper/css/common.js +11 -8
- package/node_modules/hono/dist/cjs/helper/css/index.js +1 -1
- package/node_modules/hono/dist/cjs/helper/proxy/index.js +2 -0
- package/node_modules/hono/dist/cjs/helper/route/index.js +3 -1
- package/node_modules/hono/dist/cjs/helper/ssg/ssg.js +5 -3
- package/node_modules/hono/dist/cjs/helper/streaming/sse.js +6 -2
- package/node_modules/hono/dist/cjs/hono-base.js +9 -10
- package/node_modules/hono/dist/cjs/hono.js +0 -1
- package/node_modules/hono/dist/cjs/jsx/base.js +51 -32
- package/node_modules/hono/dist/cjs/jsx/components.js +2 -2
- package/node_modules/hono/dist/cjs/jsx/constants.js +2 -0
- package/node_modules/hono/dist/cjs/jsx/context.js +15 -2
- package/node_modules/hono/dist/cjs/jsx/dom/components.js +1 -1
- package/node_modules/hono/dist/cjs/jsx/dom/hooks/index.js +38 -8
- package/node_modules/hono/dist/cjs/jsx/dom/intrinsic-element/components.js +8 -5
- package/node_modules/hono/dist/cjs/jsx/dom/render.js +9 -3
- package/node_modules/hono/dist/cjs/jsx/jsx-runtime.js +13 -17
- package/node_modules/hono/dist/cjs/middleware/basic-auth/index.js +3 -1
- package/node_modules/hono/dist/cjs/middleware/bearer-auth/index.js +9 -1
- package/node_modules/hono/dist/cjs/middleware/body-limit/index.js +9 -10
- package/node_modules/hono/dist/cjs/middleware/combine/index.js +4 -0
- package/node_modules/hono/dist/cjs/middleware/compress/index.js +2 -3
- package/node_modules/hono/dist/cjs/middleware/csrf/index.js +2 -2
- package/node_modules/hono/dist/cjs/middleware/etag/index.js +3 -1
- package/node_modules/hono/dist/cjs/middleware/jwk/jwk.js +2 -2
- package/node_modules/hono/dist/cjs/middleware/jwt/jwt.js +2 -2
- package/node_modules/hono/dist/cjs/middleware/method-not-allowed/index.js +1 -1
- package/node_modules/hono/dist/cjs/middleware/method-override/index.js +35 -12
- package/node_modules/hono/dist/cjs/middleware/mount/index.js +5 -4
- package/node_modules/hono/dist/cjs/middleware/pretty-json/index.js +1 -0
- package/node_modules/hono/dist/cjs/middleware/request-id/request-id.js +3 -3
- package/node_modules/hono/dist/cjs/middleware/secure-headers/secure-headers.js +6 -3
- package/node_modules/hono/dist/cjs/middleware/serve-static/index.js +4 -2
- package/node_modules/hono/dist/cjs/middleware/timing/timing.js +4 -3
- package/node_modules/hono/dist/cjs/router/reg-exp-router/node.js +13 -11
- package/node_modules/hono/dist/cjs/router/reg-exp-router/prepared-router.js +4 -4
- package/node_modules/hono/dist/cjs/router/reg-exp-router/router.js +39 -51
- package/node_modules/hono/dist/cjs/router/reg-exp-router/trie.js +15 -5
- package/node_modules/hono/dist/cjs/router/trie-router/node.js +6 -4
- package/node_modules/hono/dist/cjs/utils/body.js +2 -1
- package/node_modules/hono/dist/cjs/utils/cookie.js +3 -3
- package/node_modules/hono/dist/cjs/utils/html.js +5 -0
- package/node_modules/hono/dist/cjs/utils/jwt/jwt.js +8 -5
- package/node_modules/hono/dist/cjs/utils/mime.js +3 -2
- package/node_modules/hono/dist/cjs/utils/mount.js +59 -0
- package/node_modules/hono/dist/cjs/utils/url.js +23 -11
- package/node_modules/hono/dist/cjs/validator/validator.js +5 -5
- package/node_modules/hono/dist/client/fetch-result-please.js +1 -1
- package/node_modules/hono/dist/client/utils.js +9 -5
- package/node_modules/hono/dist/context.js +1 -1
- package/node_modules/hono/dist/helper/accepts/accepts.js +7 -1
- package/node_modules/hono/dist/helper/css/common.js +11 -8
- package/node_modules/hono/dist/helper/css/index.js +1 -1
- package/node_modules/hono/dist/helper/proxy/index.js +2 -0
- package/node_modules/hono/dist/helper/route/index.js +3 -1
- package/node_modules/hono/dist/helper/ssg/ssg.js +5 -3
- package/node_modules/hono/dist/helper/streaming/sse.js +6 -2
- package/node_modules/hono/dist/hono-base.js +9 -10
- package/node_modules/hono/dist/hono.js +0 -1
- package/node_modules/hono/dist/jsx/base.js +51 -34
- package/node_modules/hono/dist/jsx/components.js +2 -2
- package/node_modules/hono/dist/jsx/constants.js +2 -1
- package/node_modules/hono/dist/jsx/context.js +15 -2
- package/node_modules/hono/dist/jsx/dom/components.js +2 -2
- package/node_modules/hono/dist/jsx/dom/hooks/index.js +39 -9
- package/node_modules/hono/dist/jsx/dom/intrinsic-element/components.js +8 -5
- package/node_modules/hono/dist/jsx/dom/render.js +9 -3
- package/node_modules/hono/dist/jsx/jsx-runtime.js +15 -19
- package/node_modules/hono/dist/middleware/basic-auth/index.js +3 -1
- package/node_modules/hono/dist/middleware/bearer-auth/index.js +9 -1
- package/node_modules/hono/dist/middleware/body-limit/index.js +9 -10
- package/node_modules/hono/dist/middleware/combine/index.js +4 -0
- package/node_modules/hono/dist/middleware/compress/index.js +2 -3
- package/node_modules/hono/dist/middleware/csrf/index.js +2 -2
- package/node_modules/hono/dist/middleware/etag/index.js +3 -1
- package/node_modules/hono/dist/middleware/jwk/jwk.js +2 -2
- package/node_modules/hono/dist/middleware/jwt/jwt.js +2 -2
- package/node_modules/hono/dist/middleware/method-not-allowed/index.js +1 -1
- package/node_modules/hono/dist/middleware/method-override/index.js +35 -12
- package/node_modules/hono/dist/middleware/mount/index.js +5 -4
- package/node_modules/hono/dist/middleware/pretty-json/index.js +1 -0
- package/node_modules/hono/dist/middleware/request-id/request-id.js +3 -3
- package/node_modules/hono/dist/middleware/secure-headers/secure-headers.js +6 -3
- package/node_modules/hono/dist/middleware/serve-static/index.js +4 -2
- package/node_modules/hono/dist/middleware/timing/timing.js +4 -3
- package/node_modules/hono/dist/router/reg-exp-router/node.js +13 -11
- package/node_modules/hono/dist/router/reg-exp-router/prepared-router.js +5 -5
- package/node_modules/hono/dist/router/reg-exp-router/router.js +40 -52
- package/node_modules/hono/dist/router/reg-exp-router/trie.js +15 -5
- package/node_modules/hono/dist/router/trie-router/node.js +6 -4
- package/node_modules/hono/dist/types/adapter/aws-lambda/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/bun/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/bun/ssg.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/cloudflare-pages/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/cloudflare-workers/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/deno/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/deno/ssg.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/lambda-edge/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/netlify/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/adapter/vercel/conninfo.d.ts +1 -1
- package/node_modules/hono/dist/types/helper/accepts/accepts.d.ts +5 -0
- package/node_modules/hono/dist/types/helper/factory/index.d.ts +1 -1
- package/node_modules/hono/dist/types/helper/ssg/ssg.d.ts +6 -1
- package/node_modules/hono/dist/types/helper/streaming/sse.d.ts +1 -1
- package/node_modules/hono/dist/types/helper/streaming/stream.d.ts +1 -1
- package/node_modules/hono/dist/types/helper/streaming/text.d.ts +1 -1
- package/node_modules/hono/dist/types/helper/testing/index.d.ts +2 -1
- package/node_modules/hono/dist/types/helper/websocket/index.d.ts +13 -3
- package/node_modules/hono/dist/types/hono-base.d.ts +23 -9
- package/node_modules/hono/dist/types/index.d.ts +1 -1
- package/node_modules/hono/dist/types/jsx/base.d.ts +6 -3
- package/node_modules/hono/dist/types/jsx/components.d.ts +2 -2
- package/node_modules/hono/dist/types/jsx/constants.d.ts +1 -0
- package/node_modules/hono/dist/types/jsx/context.d.ts +2 -2
- package/node_modules/hono/dist/types/jsx/dom/components.d.ts +2 -2
- package/node_modules/hono/dist/types/jsx/dom/css.d.ts +2 -2
- package/node_modules/hono/dist/types/jsx/dom/hooks/index.d.ts +5 -3
- package/node_modules/hono/dist/types/jsx/dom/index.d.ts +1 -1
- package/node_modules/hono/dist/types/jsx/dom/server.d.ts +1 -1
- package/node_modules/hono/dist/types/jsx/index.d.ts +1 -1
- package/node_modules/hono/dist/types/jsx/jsx-runtime.d.ts +2 -1
- package/node_modules/hono/dist/types/jsx/streaming.d.ts +4 -3
- package/node_modules/hono/dist/types/middleware/basic-auth/index.d.ts +1 -0
- package/node_modules/hono/dist/types/middleware/bearer-auth/index.d.ts +2 -1
- package/node_modules/hono/dist/types/middleware/ip-restriction/index.d.ts +3 -3
- package/node_modules/hono/dist/types/middleware/jsx-renderer/index.d.ts +3 -3
- package/node_modules/hono/dist/types/middleware/mount/index.d.ts +2 -0
- package/node_modules/hono/dist/types/middleware/request-id/request-id.d.ts +3 -3
- package/node_modules/hono/dist/types/middleware/secure-headers/secure-headers.d.ts +2 -0
- package/node_modules/hono/dist/types/router/reg-exp-router/node.d.ts +3 -3
- package/node_modules/hono/dist/types/router/reg-exp-router/trie.d.ts +1 -1
- package/node_modules/hono/dist/types/utils/cookie.d.ts +1 -1
- package/node_modules/hono/dist/types/utils/ipaddr.d.ts +1 -1
- package/node_modules/hono/dist/types/utils/jwt/jwt.d.ts +4 -2
- package/node_modules/hono/dist/types/utils/mount.d.ts +4 -0
- package/node_modules/hono/dist/types/utils/types.d.ts +12 -2
- package/node_modules/hono/dist/utils/body.js +2 -1
- package/node_modules/hono/dist/utils/cookie.js +3 -3
- package/node_modules/hono/dist/utils/html.js +5 -0
- package/node_modules/hono/dist/utils/jwt/jwt.js +8 -5
- package/node_modules/hono/dist/utils/mime.js +3 -2
- package/node_modules/hono/dist/utils/mount.js +58 -0
- package/node_modules/hono/dist/utils/url.js +23 -11
- package/node_modules/hono/dist/validator/validator.js +5 -5
- package/node_modules/hono/package.json +1 -1
- package/package.json +1 -1
|
@@ -7,10 +7,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
7
7
|
const getMimeType = (filename, mimes = baseMimes) => {
|
|
8
8
|
const match = filename.match(/\.([a-zA-Z0-9]+?)$/);
|
|
9
9
|
if (!match) return;
|
|
10
|
-
|
|
10
|
+
const mimeType = mimes[match[1].toLowerCase()];
|
|
11
|
+
return typeof mimeType === "string" ? mimeType : void 0;
|
|
11
12
|
};
|
|
12
13
|
const getExtension = (mimeType) => {
|
|
13
|
-
const baseType = mimeType.split(";", 1)[0].trim();
|
|
14
|
+
const baseType = mimeType.split(";", 1)[0].trim().toLowerCase();
|
|
14
15
|
for (const ext in baseMimes) {
|
|
15
16
|
const stored = baseMimes[ext];
|
|
16
17
|
if (stored === mimeType || stored.split(";", 1)[0].trim() === baseType) return ext;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_http_exception = require("../http-exception.js");
|
|
3
|
+
const require_request_constants = require("../request/constants.js");
|
|
4
|
+
const require_utils_url = require("./url.js");
|
|
5
|
+
//#region src/utils/mount.ts
|
|
6
|
+
const countTrailingSlashes = (path) => {
|
|
7
|
+
let index = path.length;
|
|
8
|
+
while (index > 0 && path.charCodeAt(index - 1) === 47) index--;
|
|
9
|
+
return path.length - index;
|
|
10
|
+
};
|
|
11
|
+
const getPathPrefixLength = (c, pathPrefix, routePath) => {
|
|
12
|
+
if (!/[:*]/.test(pathPrefix)) return pathPrefix.length;
|
|
13
|
+
const path = c.req.path;
|
|
14
|
+
const matchResult = c.req[require_request_constants.GET_MATCH_RESULT];
|
|
15
|
+
const paramNames = /* @__PURE__ */ new Set();
|
|
16
|
+
let length = 0;
|
|
17
|
+
for (const part of require_utils_url.splitRoutingPath(pathPrefix)) {
|
|
18
|
+
if (part[0] === ":" && part.endsWith("}?")) throw new Error(`mount(): Optional regular expression parameters are not supported in "${routePath}".`);
|
|
19
|
+
const pattern = require_utils_url.getPattern(part);
|
|
20
|
+
if (pattern && pattern !== "*") {
|
|
21
|
+
const name = pattern[1];
|
|
22
|
+
if (paramNames.has(name)) throw new Error(`mount(): Duplicate path parameter "${name}" in "${routePath}".`);
|
|
23
|
+
paramNames.add(name);
|
|
24
|
+
}
|
|
25
|
+
if (pattern && pattern !== "*" && pattern[2] !== true) {
|
|
26
|
+
const value = matchResult.length === 2 ? matchResult[1][matchResult[0][c.req.routeIndex][1][pattern[1]]] : matchResult[0][c.req.routeIndex][1][pattern[1]];
|
|
27
|
+
length += value.length + 1;
|
|
28
|
+
} else if (pattern || part.endsWith("*")) {
|
|
29
|
+
const end = path.indexOf("/", length + 1);
|
|
30
|
+
length = end === -1 ? path.length : end;
|
|
31
|
+
} else length += part.length + 1;
|
|
32
|
+
}
|
|
33
|
+
return length;
|
|
34
|
+
};
|
|
35
|
+
const createMountedRequest = (c, pathPrefix, routePath) => {
|
|
36
|
+
if (/[^/]\*$/.test(routePath)) throw new Error(`mount(): Wildcard must follow "/" in "${routePath}".`);
|
|
37
|
+
const prefixLength = getPathPrefixLength(c, pathPrefix, routePath);
|
|
38
|
+
const path = c.req.path.slice(prefixLength) || "/";
|
|
39
|
+
if (prefixLength > c.req.path.length || path[0] !== "/" || /\/(?:\.|%2e){1,2}(?:\/|$)/i.test(path)) throw new require_http_exception.HTTPException(400, { message: "Invalid mounted path" });
|
|
40
|
+
const rawUrl = c.req.raw.url;
|
|
41
|
+
if (/^[^/?#]*\/\/[^/?#\\]*[?#\\]/.test(rawUrl)) throw new require_http_exception.HTTPException(400, { message: "Invalid mounted path" });
|
|
42
|
+
const rawPathEnd = rawUrl.search(/[?#]/);
|
|
43
|
+
const rawTrailingSlashes = countTrailingSlashes(rawPathEnd === -1 ? rawUrl : rawUrl.slice(0, rawPathEnd));
|
|
44
|
+
if (rawTrailingSlashes > 1 && countTrailingSlashes(c.req.path) === rawTrailingSlashes - 1) throw new require_http_exception.HTTPException(400, { message: "Invalid mounted path" });
|
|
45
|
+
const url = new URL(rawUrl);
|
|
46
|
+
url.pathname = path.replace(/[\\\t\n\r]/g, encodeURIComponent);
|
|
47
|
+
if (path.includes("%")) {
|
|
48
|
+
let decoded;
|
|
49
|
+
try {
|
|
50
|
+
decoded = decodeURI(path);
|
|
51
|
+
} catch {}
|
|
52
|
+
if (decoded === void 0) {
|
|
53
|
+
if (require_utils_url.tryDecode(url.pathname, (value) => decodeURI(value.replace(/%25/g, "%2525"))) !== path) throw new require_http_exception.HTTPException(400, { message: "Invalid mounted path" });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return new Request(url, c.req.raw);
|
|
57
|
+
};
|
|
58
|
+
//#endregion
|
|
59
|
+
exports.createMountedRequest = createMountedRequest;
|
|
@@ -42,11 +42,11 @@ const getPattern = (label, next) => {
|
|
|
42
42
|
if (match[2]) patternCache[cacheKey] = next && next[0] !== ":" && next[0] !== "*" ? [
|
|
43
43
|
cacheKey,
|
|
44
44
|
match[1],
|
|
45
|
-
new RegExp(
|
|
45
|
+
new RegExp(`^(?:${match[2]})(?=/${next})`)
|
|
46
46
|
] : [
|
|
47
47
|
label,
|
|
48
48
|
match[1],
|
|
49
|
-
new RegExp(
|
|
49
|
+
new RegExp(`^(?:${match[2]})$`)
|
|
50
50
|
];
|
|
51
51
|
else patternCache[cacheKey] = [
|
|
52
52
|
label,
|
|
@@ -81,9 +81,10 @@ const tryDecode = (str, decoder) => {
|
|
|
81
81
|
* tryDecodeURI('Hello%20World/%A4%A2') // 'Hello World/%A4%A2'
|
|
82
82
|
*/
|
|
83
83
|
const tryDecodeURI = (str) => tryDecode(str, decodeURI);
|
|
84
|
+
const decodeURIWithPreservedPercent = (value) => decodeURI(value.includes("%25") ? value.replace(/%25/g, "%2525") : value);
|
|
84
85
|
const getPath = (request) => {
|
|
85
86
|
const url = request.url;
|
|
86
|
-
const start = url.indexOf("/", url.indexOf(":") + 4);
|
|
87
|
+
const start = url.charCodeAt(0) === 47 ? 0 : url.indexOf("/", url.indexOf(":") + 4);
|
|
87
88
|
let i = start;
|
|
88
89
|
for (; i < url.length; i++) {
|
|
89
90
|
const charCode = url.charCodeAt(i);
|
|
@@ -92,7 +93,13 @@ const getPath = (request) => {
|
|
|
92
93
|
const hashIndex = url.indexOf("#", i);
|
|
93
94
|
const end = queryIndex === -1 ? hashIndex === -1 ? void 0 : hashIndex : hashIndex === -1 ? queryIndex : Math.min(queryIndex, hashIndex);
|
|
94
95
|
const path = url.slice(start, end);
|
|
95
|
-
|
|
96
|
+
const decoded = tryDecode(path, decodeURIWithPreservedPercent);
|
|
97
|
+
if (/%(?![0-9A-Fa-f]{2})/.test(path)) {
|
|
98
|
+
const rewritten = new URL("http://localhost");
|
|
99
|
+
rewritten.pathname = decoded.replace(/[\\\t\n\r]/g, encodeURIComponent);
|
|
100
|
+
if (tryDecode(rewritten.pathname, decodeURIWithPreservedPercent) !== decoded) return tryDecode(path.replace(/%(?![0-9A-Fa-f]{2})/g, "%25"), decodeURIWithPreservedPercent);
|
|
101
|
+
}
|
|
102
|
+
return decoded;
|
|
96
103
|
} else if (charCode === 63 || charCode === 35) break;
|
|
97
104
|
}
|
|
98
105
|
return url.slice(start, i);
|
|
@@ -153,17 +160,22 @@ const _getQueryParam = (url, key, multiple) => {
|
|
|
153
160
|
const hashIndex = url.indexOf("#", 8);
|
|
154
161
|
if (hashIndex !== -1) url = url.slice(0, hashIndex);
|
|
155
162
|
let encoded;
|
|
156
|
-
if (!multiple && key &&
|
|
157
|
-
|
|
163
|
+
if (!multiple && key && !/[%+&=]/.test(key)) {
|
|
164
|
+
const queryIndex = url.indexOf("?", 8);
|
|
165
|
+
let keyIndex = queryIndex;
|
|
158
166
|
if (keyIndex === -1) return;
|
|
159
167
|
if (!url.startsWith(key, keyIndex + 1)) keyIndex = url.indexOf(`&${key}`, keyIndex + 1);
|
|
160
168
|
while (keyIndex !== -1) {
|
|
161
169
|
const trailingKeyCode = url.charCodeAt(keyIndex + key.length + 1);
|
|
162
|
-
if (trailingKeyCode === 61) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
170
|
+
if (trailingKeyCode === 61 || trailingKeyCode === 38 || isNaN(trailingKeyCode)) {
|
|
171
|
+
if (keyIndex > queryIndex && /(?:^|&)[^=&]*[%+]/.test(url.slice(queryIndex + 1, keyIndex))) break;
|
|
172
|
+
if (trailingKeyCode === 61) {
|
|
173
|
+
const valueIndex = keyIndex + key.length + 2;
|
|
174
|
+
const endIndex = url.indexOf("&", valueIndex);
|
|
175
|
+
return _decodeURI(url.slice(valueIndex, endIndex === -1 ? void 0 : endIndex));
|
|
176
|
+
}
|
|
177
|
+
return "";
|
|
178
|
+
}
|
|
167
179
|
keyIndex = url.indexOf(`&${key}`, keyIndex + 1);
|
|
168
180
|
}
|
|
169
181
|
encoded = /[%+]/.test(url);
|
|
@@ -3,16 +3,16 @@ const require_http_exception = require("../http-exception.js");
|
|
|
3
3
|
const require_utils_buffer = require("../utils/buffer.js");
|
|
4
4
|
const require_helper_cookie_index = require("../helper/cookie/index.js");
|
|
5
5
|
//#region src/validator/validator.ts
|
|
6
|
-
const jsonRegex = /^application\/([
|
|
7
|
-
const
|
|
8
|
-
const urlencodedRegex = /^application\/x-www-form-urlencoded(;\s*[a-zA-Z0-9\-]+\=([^;]+))*$/i;
|
|
6
|
+
const jsonRegex = /^application\/([\w.-]+\+)?json$/i;
|
|
7
|
+
const getMediaType = (contentType) => contentType.split(";")[0].trim().toLowerCase();
|
|
9
8
|
const validator = (target, validationFunc) => {
|
|
10
9
|
return async (c, next) => {
|
|
11
10
|
let value = {};
|
|
12
11
|
const contentType = c.req.header("Content-Type");
|
|
12
|
+
const mediaType = contentType ? getMediaType(contentType) : "";
|
|
13
13
|
switch (target) {
|
|
14
14
|
case "json":
|
|
15
|
-
if (!
|
|
15
|
+
if (!jsonRegex.test(mediaType)) break;
|
|
16
16
|
try {
|
|
17
17
|
value = await c.req.json();
|
|
18
18
|
} catch {
|
|
@@ -20,7 +20,7 @@ const validator = (target, validationFunc) => {
|
|
|
20
20
|
}
|
|
21
21
|
break;
|
|
22
22
|
case "form": {
|
|
23
|
-
if (
|
|
23
|
+
if (mediaType !== "multipart/form-data" && mediaType !== "application/x-www-form-urlencoded") break;
|
|
24
24
|
let formData;
|
|
25
25
|
if (c.req.bodyCache.formData) formData = await c.req.bodyCache.formData;
|
|
26
26
|
else try {
|
|
@@ -57,7 +57,7 @@ const jsonRegex = /^application\/(?:[\w!#$%&*.^`~-]*\+)?json(?:;.+)?$/i;
|
|
|
57
57
|
function detectResponseType(response) {
|
|
58
58
|
const _contentType = response.headers.get("content-type");
|
|
59
59
|
if (!_contentType) return "text";
|
|
60
|
-
const contentType = _contentType.split(";").shift();
|
|
60
|
+
const contentType = _contentType.split(";").shift().trim();
|
|
61
61
|
if (jsonRegex.test(contentType)) return "json";
|
|
62
62
|
return "text";
|
|
63
63
|
}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { DetailedError, fetchRP } from "./fetch-result-please.js";
|
|
2
2
|
//#region src/client/utils.ts
|
|
3
3
|
const mergePath = (base, path) => {
|
|
4
|
-
|
|
5
|
-
base
|
|
4
|
+
let end = base.length;
|
|
5
|
+
while (base[end - 1] === "/") end--;
|
|
6
6
|
path = path.replace(/^\/+/, "");
|
|
7
|
-
return base + path;
|
|
7
|
+
return base.slice(0, end) + "/" + path;
|
|
8
8
|
};
|
|
9
|
+
const networkPathRegExp = /^(?:[/\\][\t\n\r]*){2}/;
|
|
9
10
|
const replaceUrlParam = (urlString, params) => {
|
|
11
|
+
const isNetworkPath = networkPathRegExp.test(urlString);
|
|
10
12
|
for (const [k, v] of Object.entries(params)) {
|
|
11
13
|
const reg = new RegExp("/:" + k + "(?:{[^/]+})?\\??(?=/|$)");
|
|
12
14
|
urlString = urlString.replace(reg, () => v ? `/${v}` : "");
|
|
13
15
|
}
|
|
14
|
-
return urlString;
|
|
16
|
+
return !isNetworkPath && networkPathRegExp.test(urlString) ? urlString.replace(/^[/\\\t\n\r]+/, "/") : urlString;
|
|
15
17
|
};
|
|
16
18
|
const buildSearchParams = (query) => {
|
|
17
19
|
const searchParams = new URLSearchParams();
|
|
@@ -36,7 +38,9 @@ const removeIndexString = (urlString) => {
|
|
|
36
38
|
return urlString.replace(/\/index(?=\?|$)/, "");
|
|
37
39
|
};
|
|
38
40
|
function isObject(item) {
|
|
39
|
-
|
|
41
|
+
if (typeof item !== "object" || item === null) return false;
|
|
42
|
+
const proto = Object.getPrototypeOf(item);
|
|
43
|
+
return proto === null || Object.getPrototypeOf(proto) === null;
|
|
40
44
|
}
|
|
41
45
|
function deepMerge(target, source) {
|
|
42
46
|
if (!isObject(target) && !isObject(source)) return source;
|
|
@@ -197,7 +197,7 @@ var Context = class {
|
|
|
197
197
|
* ```
|
|
198
198
|
*/
|
|
199
199
|
header = (name, value, options) => {
|
|
200
|
-
if (this.finalized) this.#res = createResponseInstance(this.#res.body, this.#res);
|
|
200
|
+
if (this.finalized && !this.#res.bodyUsed) this.#res = createResponseInstance(this.#res.body, this.#res);
|
|
201
201
|
const headers = this.#res ? this.#res.headers : this.#preparedHeaders ??= new Headers();
|
|
202
202
|
if (value === void 0) headers.delete(name);
|
|
203
203
|
else if (options?.append) headers.append(name, value);
|
|
@@ -19,18 +19,24 @@ const getSpecificity = (type) => {
|
|
|
19
19
|
};
|
|
20
20
|
const defaultMatch = (accepts, config) => {
|
|
21
21
|
const { supports, default: defaultSupport } = config;
|
|
22
|
+
const exactTypes = new Set(accepts.filter((accept) => getSpecificity(accept.type) === 3).map((accept) => accept.type.toLowerCase()));
|
|
22
23
|
const sortedAccepts = accepts.filter((accept) => accept.q > 0).sort((a, b) => {
|
|
23
24
|
if (b.q !== a.q) return b.q - a.q;
|
|
24
25
|
return getSpecificity(b.type) - getSpecificity(a.type);
|
|
25
26
|
});
|
|
26
27
|
for (const accept of sortedAccepts) {
|
|
27
|
-
const matched = supports.find((supported) => matchType(accept.type, supported));
|
|
28
|
+
const matched = supports.find((supported) => matchType(accept.type, supported) && (getSpecificity(accept.type) !== 2 || !exactTypes.has(supported.toLowerCase())));
|
|
28
29
|
if (matched) return matched;
|
|
29
30
|
}
|
|
30
31
|
return defaultSupport;
|
|
31
32
|
};
|
|
32
33
|
/**
|
|
33
34
|
* Match the accept header with the given options.
|
|
35
|
+
*
|
|
36
|
+
* @param {Context} c - The context of the request.
|
|
37
|
+
* @param {acceptsOptions} options - The options for matching the accept header.
|
|
38
|
+
* @returns {string} The matched supported value or the default value.
|
|
39
|
+
*
|
|
34
40
|
* @example
|
|
35
41
|
* ```ts
|
|
36
42
|
* app.get('/users', (c) => {
|
|
@@ -45,7 +45,11 @@ const isValidKeyframeName = (name) => isValidClassName(name) && !RESERVED_KEYFRA
|
|
|
45
45
|
const defaultOnInvalidSlug = (slug) => {
|
|
46
46
|
console.warn(`Invalid slug: ${slug}`);
|
|
47
47
|
};
|
|
48
|
-
const cssStringReStr = [
|
|
48
|
+
const cssStringReStr = [
|
|
49
|
+
"\"(?:(?:\\\\[\\s\\S]|[^\"\\\\])*)\"",
|
|
50
|
+
"'(?:(?:\\\\[\\s\\S]|[^'\\\\])*)'",
|
|
51
|
+
"url\\(\\s*[^)\"'\\s]*\\s*\\)"
|
|
52
|
+
].join("|");
|
|
49
53
|
const minifyCssRe = new RegExp([
|
|
50
54
|
"(" + cssStringReStr + ")",
|
|
51
55
|
"(?:" + [
|
|
@@ -55,11 +59,12 @@ const minifyCssRe = new RegExp([
|
|
|
55
59
|
"\\s+$"
|
|
56
60
|
].join("|") + ")",
|
|
57
61
|
"\\s*;\\s*(}|$)\\s*",
|
|
58
|
-
"\\s*([{}
|
|
62
|
+
"\\s*([{};,])\\s*",
|
|
63
|
+
"(:)\\s*",
|
|
59
64
|
"(\\s)\\s+"
|
|
60
65
|
].join("|"), "g");
|
|
61
66
|
const minify = (css) => {
|
|
62
|
-
return css.replace(minifyCssRe, (_, $1, $2, $3, $4) => $1 || $2 || $3 || $4 || "");
|
|
67
|
+
return css.replace(minifyCssRe, (_, $1, $2, $3, $4, $5) => $1 || $2 || $3 || $4 || $5 || "");
|
|
63
68
|
};
|
|
64
69
|
const buildStyleString = (strings, values) => {
|
|
65
70
|
const selectors = [];
|
|
@@ -74,10 +79,8 @@ const buildStyleString = (strings, values) => {
|
|
|
74
79
|
for (let j = 0, len = vArray.length; j < len; j++) {
|
|
75
80
|
let value = vArray[j];
|
|
76
81
|
if (typeof value === "boolean" || value === null || value === void 0) continue;
|
|
77
|
-
if (typeof value === "string")
|
|
78
|
-
|
|
79
|
-
else styleString += value;
|
|
80
|
-
} else if (typeof value === "number") styleString += value;
|
|
82
|
+
if (typeof value === "string") styleString += value.replace(/[\\"']/g, "\\$&");
|
|
83
|
+
else if (typeof value === "number") styleString += value;
|
|
81
84
|
else if (value[CSS_ESCAPED]) styleString += value[CSS_ESCAPED];
|
|
82
85
|
else if (value[CLASS_NAME].startsWith("@keyframes ")) {
|
|
83
86
|
selectors.push(value);
|
|
@@ -102,7 +105,7 @@ const buildStyleString = (strings, values) => {
|
|
|
102
105
|
}
|
|
103
106
|
return [
|
|
104
107
|
label,
|
|
105
|
-
minify(styleString),
|
|
108
|
+
minify(styleString).replace(/<\//g, "<\\/"),
|
|
106
109
|
selectors,
|
|
107
110
|
externalClassNames
|
|
108
111
|
];
|
|
@@ -20,7 +20,7 @@ const createCssContext = ({ id, classNameSlug, onInvalidSlug }) => {
|
|
|
20
20
|
const [cssJsxDomObject, StyleRenderToDom] = createCssJsxDomObjects({ id });
|
|
21
21
|
const contextMap = /* @__PURE__ */ new WeakMap();
|
|
22
22
|
const nonceMap = /* @__PURE__ */ new WeakMap();
|
|
23
|
-
const replaceStyleRe = new RegExp(`(<style id="${id}"(?: nonce="[^"]*")?>.*?)(</style>)
|
|
23
|
+
const replaceStyleRe = new RegExp(`(<style id="${id}"(?: nonce="[^"]*")?>.*?)(</style>)`, "s");
|
|
24
24
|
const newCssClassNameObject = (cssClassName) => {
|
|
25
25
|
const appendStyle = ({ buffer, context }) => {
|
|
26
26
|
const [toAdd, added] = contextMap.get(context);
|
|
@@ -99,6 +99,8 @@ const proxy = async (input, proxyInit) => {
|
|
|
99
99
|
...buildRequestInitFromRequest(raw, strictConnectionProcessing),
|
|
100
100
|
...preprocessRequestInit(requestInit)
|
|
101
101
|
});
|
|
102
|
+
req.headers.delete("transfer-encoding");
|
|
103
|
+
req.headers.delete("keep-alive");
|
|
102
104
|
req.headers.delete("accept-encoding");
|
|
103
105
|
const res = await (customFetch || fetch)(req);
|
|
104
106
|
const resHeaders = new Headers(res.headers);
|
|
@@ -110,7 +110,9 @@ const basePath = (c, index) => {
|
|
|
110
110
|
const pattern = getPattern(paths[i], paths[i + 1]);
|
|
111
111
|
if (pattern) {
|
|
112
112
|
const re = pattern[2] === true || pattern === "*" ? /[^\/]+/ : pattern[2];
|
|
113
|
-
|
|
113
|
+
const restPath = reqPath.substring(basePathLength + 1);
|
|
114
|
+
const segment = restPath.split("/", 1)[0];
|
|
115
|
+
basePathLength += (restPath.match(re)?.[0] ?? (re.test(segment) ? segment : "")).length;
|
|
114
116
|
} else basePathLength += paths[i].length;
|
|
115
117
|
basePathLength += 1;
|
|
116
118
|
}
|
|
@@ -38,6 +38,8 @@ const defaultExtensionMap = {
|
|
|
38
38
|
const determineExtension = (mimeType, userExtensionMap) => {
|
|
39
39
|
const extensionMap = userExtensionMap || defaultExtensionMap;
|
|
40
40
|
if (mimeType in extensionMap) return extensionMap[mimeType];
|
|
41
|
+
const lowerCasedMimeType = mimeType.toLowerCase();
|
|
42
|
+
if (lowerCasedMimeType in extensionMap) return extensionMap[lowerCasedMimeType];
|
|
41
43
|
return getExtension(mimeType) || "html";
|
|
42
44
|
};
|
|
43
45
|
const combineBeforeRequestHooks = (hooks) => {
|
|
@@ -141,8 +143,7 @@ const fetchRoutesContent = function* (app, beforeRequestHook, afterResponseHook,
|
|
|
141
143
|
* `saveContentToFile` is an experimental feature.
|
|
142
144
|
* The API might be changed.
|
|
143
145
|
*/
|
|
144
|
-
const createdDirs = /* @__PURE__ */ new Set()
|
|
145
|
-
const saveContentToFile = async (data, fsModule, outDir, extensionMap) => {
|
|
146
|
+
const saveContentToFile = async (data, fsModule, outDir, extensionMap, createdDirs = /* @__PURE__ */ new Set()) => {
|
|
146
147
|
const awaitedData = await data;
|
|
147
148
|
if (!awaitedData) return;
|
|
148
149
|
const { routePath, content, mimeType } = awaitedData;
|
|
@@ -182,10 +183,11 @@ const toSSG = async (app, fs, options) => {
|
|
|
182
183
|
const concurrency = options?.concurrency ?? DEFAULT_CONCURRENCY;
|
|
183
184
|
const combinedBeforeRequestHook = combineBeforeRequestHooks(beforeRequestHooks.length > 0 ? beforeRequestHooks : [(req) => req]);
|
|
184
185
|
const combinedAfterResponseHook = combineAfterResponseHooks(afterResponseHooks.length > 0 ? afterResponseHooks : [(req) => req]);
|
|
186
|
+
const createdDirs = /* @__PURE__ */ new Set();
|
|
185
187
|
const getInfoGen = fetchRoutesContent(app, combinedBeforeRequestHook, combinedAfterResponseHook, concurrency);
|
|
186
188
|
for (const getInfo of getInfoGen) getInfoPromises.push(getInfo.then((getContentGen) => {
|
|
187
189
|
if (!getContentGen) return;
|
|
188
|
-
for (const content of getContentGen) savePromises.push(saveContentToFile(content, fs, outputDir, options?.extensionMap).catch((e) => e));
|
|
190
|
+
for (const content of getContentGen) savePromises.push(saveContentToFile(content, fs, outputDir, options?.extensionMap, createdDirs).catch((e) => e));
|
|
189
191
|
}));
|
|
190
192
|
await Promise.all(getInfoPromises);
|
|
191
193
|
const files = [];
|
|
@@ -10,9 +10,13 @@ var SSEStreamingApi = class extends StreamingApi {
|
|
|
10
10
|
const dataLines = (await resolveCallback(message.data, HtmlEscapedCallbackPhase.Stringify, false, {})).split(/\r\n|\r|\n/).map((line) => {
|
|
11
11
|
return `data: ${line}`;
|
|
12
12
|
}).join("\n");
|
|
13
|
-
for (const key of [
|
|
13
|
+
for (const key of [
|
|
14
|
+
"event",
|
|
15
|
+
"id",
|
|
16
|
+
"retry"
|
|
17
|
+
]) {
|
|
14
18
|
const value = message[key];
|
|
15
|
-
if (value && /[\r\n]/.test(value)) throw new Error(`${key} must not contain "\\r" or "\\n"`);
|
|
19
|
+
if (value && /[\r\n]/.test(String(value))) throw new Error(`${key} must not contain "\\r" or "\\n"`);
|
|
16
20
|
}
|
|
17
21
|
const sseData = [
|
|
18
22
|
message.event && `event: ${message.event}`,
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { compose } from "./compose.js";
|
|
2
2
|
import { getPath, getPathNoStrict, mergePath } from "./utils/url.js";
|
|
3
3
|
import { Context } from "./context.js";
|
|
4
|
+
import { routePath } from "./helper/route/index.js";
|
|
4
5
|
import { METHODS } from "./router.js";
|
|
5
6
|
import { COMPOSED_HANDLER } from "./utils/constants.js";
|
|
7
|
+
import { createMountedRequest } from "./utils/mount.js";
|
|
6
8
|
//#region src/hono-base.ts
|
|
7
9
|
/**
|
|
8
10
|
* @module
|
|
@@ -183,6 +185,8 @@ var Hono = class Hono {
|
|
|
183
185
|
* @param {Function} applicationHandler - other Request Handler
|
|
184
186
|
* @param {MountOptions} [options] - options of `.mount()`
|
|
185
187
|
* @returns {Hono} mounted Hono instance
|
|
188
|
+
* @throws {Error} If automatic request rewriting encounters duplicate path parameter names or an optional regular expression parameter.
|
|
189
|
+
* @throws {HTTPException} With status 400 if automatic request rewriting cannot safely preserve the routed path.
|
|
186
190
|
*
|
|
187
191
|
* @example
|
|
188
192
|
* ```ts
|
|
@@ -227,17 +231,12 @@ var Hono = class Hono {
|
|
|
227
231
|
} catch {}
|
|
228
232
|
return [c.env, executionContext];
|
|
229
233
|
};
|
|
230
|
-
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
const url = new URL(request.url);
|
|
235
|
-
url.pathname = this.getPath(request).slice(pathPrefixLength) || "/";
|
|
236
|
-
return new Request(url, request);
|
|
237
|
-
};
|
|
238
|
-
})();
|
|
234
|
+
const defaultReplaceRequest = (c) => {
|
|
235
|
+
const mountedRoutePath = routePath(c);
|
|
236
|
+
return createMountedRequest(c, mountedRoutePath.replace(/\/?\*$/, ""), mountedRoutePath);
|
|
237
|
+
};
|
|
239
238
|
const handler = async (c, next) => {
|
|
240
|
-
const res = await applicationHandler(replaceRequest(c.req.raw), ...getOptions(c));
|
|
239
|
+
const res = await applicationHandler(replaceRequest ? replaceRequest(c.req.raw) : defaultReplaceRequest(c), ...getOptions(c));
|
|
241
240
|
if (res) return res;
|
|
242
241
|
await next();
|
|
243
242
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { HonoBase as Hono$1 } from "./hono-base.js";
|
|
2
2
|
import { RegExpRouter } from "./router/reg-exp-router/router.js";
|
|
3
|
-
import "./router/reg-exp-router/index.js";
|
|
4
3
|
import { SmartRouter } from "./router/smart-router/router.js";
|
|
5
4
|
import { TrieRouter } from "./router/trie-router/router.js";
|
|
6
5
|
import "./router/trie-router/index.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { escapeToBuffer, raw, resolveCallbackSync, stringBufferToString } from "../utils/html.js";
|
|
2
|
-
import { DOM_MEMO, DOM_RENDERER } from "./constants.js";
|
|
2
|
+
import { DOM_MEMO, DOM_RENDERER, RENDERED_JSX } from "./constants.js";
|
|
3
3
|
import { captureRenderContext, createContext, globalContexts, runWithRenderContext, useContext } from "./context.js";
|
|
4
4
|
import { domRenderers } from "./intrinsic-element/common.js";
|
|
5
5
|
import { components_exports } from "./intrinsic-element/components.js";
|
|
@@ -25,7 +25,7 @@ const emptyTags = [
|
|
|
25
25
|
"track",
|
|
26
26
|
"wbr"
|
|
27
27
|
];
|
|
28
|
-
const booleanAttributes = [
|
|
28
|
+
const booleanAttributes = /* @__PURE__ */ new Set([
|
|
29
29
|
"allowfullscreen",
|
|
30
30
|
"async",
|
|
31
31
|
"autofocus",
|
|
@@ -51,8 +51,11 @@ const booleanAttributes = [
|
|
|
51
51
|
"readonly",
|
|
52
52
|
"required",
|
|
53
53
|
"reversed",
|
|
54
|
-
"selected"
|
|
55
|
-
|
|
54
|
+
"selected",
|
|
55
|
+
"shadowrootclonable",
|
|
56
|
+
"shadowrootdelegatesfocus",
|
|
57
|
+
"shadowrootserializable"
|
|
58
|
+
]);
|
|
56
59
|
const resolveFunctionComponentResult = (result, suspendedContext) => result.then((resolved) => {
|
|
57
60
|
if (typeof resolved !== "string" && !Array.isArray(resolved) && !(resolved instanceof JSXNode)) return resolved;
|
|
58
61
|
const children = Array.isArray(resolved) ? resolved : [resolved];
|
|
@@ -63,6 +66,44 @@ const resolveFunctionComponentResult = (result, suspendedContext) => result.then
|
|
|
63
66
|
};
|
|
64
67
|
return suspendedContext ? suspendedContext(render) : runWithRenderContext(render);
|
|
65
68
|
});
|
|
69
|
+
const markRenderedJSX = (value) => {
|
|
70
|
+
value[RENDERED_JSX] = true;
|
|
71
|
+
return value;
|
|
72
|
+
};
|
|
73
|
+
const isEscapedAttribute = (value) => value instanceof String && value.isEscaped && !(RENDERED_JSX in value);
|
|
74
|
+
const objectToAttributeString = (v) => {
|
|
75
|
+
const s = v.toString();
|
|
76
|
+
return s instanceof Promise ? s.then(String) : String(s);
|
|
77
|
+
};
|
|
78
|
+
const attributeToBuffer = (buffer, prefix, key, v, tag) => {
|
|
79
|
+
if (key === "ref" || v === null || v === void 0) return;
|
|
80
|
+
if (typeof v === "boolean" && booleanAttributes.has(key)) {
|
|
81
|
+
if (v) buffer[0] += `${prefix}${key}=""`;
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (typeof v === "function") {
|
|
85
|
+
if (!key.startsWith("on")) throw new Error(`Invalid prop '${key}' of type 'function' supplied to ${tag ? `'${tag}'` : "a JSX element"}.`);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
buffer[0] += `${prefix}${key}="`;
|
|
89
|
+
if (key === "style" && typeof v === "object") {
|
|
90
|
+
let styleStr = "";
|
|
91
|
+
styleObjectForEach(v, (property, value) => {
|
|
92
|
+
if (value != null) styleStr += `${styleStr ? ";" : ""}${property}:${value}`;
|
|
93
|
+
});
|
|
94
|
+
escapeToBuffer(styleStr, buffer);
|
|
95
|
+
} else if (typeof v === "string") escapeToBuffer(v, buffer);
|
|
96
|
+
else if (typeof v === "number" || isEscapedAttribute(v)) buffer[0] += `${v}`;
|
|
97
|
+
else {
|
|
98
|
+
const s = v instanceof Promise ? v.then((r) => typeof r === "object" && r !== null && !isEscapedAttribute(r) ? objectToAttributeString(r) : r) : objectToAttributeString(v);
|
|
99
|
+
if (s instanceof Promise) {
|
|
100
|
+
buffer.unshift("\"", s);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
escapeToBuffer(s, buffer);
|
|
104
|
+
}
|
|
105
|
+
buffer[0] += "\"";
|
|
106
|
+
};
|
|
66
107
|
const childrenToStringToBuffer = (children, buffer) => {
|
|
67
108
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
68
109
|
const child = children[i];
|
|
@@ -78,7 +119,7 @@ const childrenToStringToBuffer = (children, buffer) => {
|
|
|
78
119
|
buffer.callbacks.push(...callbacks);
|
|
79
120
|
}
|
|
80
121
|
} else if (child instanceof Promise) buffer.unshift("", child);
|
|
81
|
-
else childrenToStringToBuffer(child, buffer);
|
|
122
|
+
else if (Array.isArray(child)) childrenToStringToBuffer(child, buffer);
|
|
82
123
|
}
|
|
83
124
|
};
|
|
84
125
|
const renderChildren = (children) => runWithRenderContext(() => {
|
|
@@ -114,7 +155,7 @@ var JSXNode = class {
|
|
|
114
155
|
const render = () => {
|
|
115
156
|
const buffer = [""];
|
|
116
157
|
this.toStringToBuffer(buffer);
|
|
117
|
-
return buffer.length === 1 ? "callbacks" in buffer ? resolveCallbackSync(raw(buffer[0], buffer.callbacks)).toString() : buffer[0] : stringBufferToString(buffer, buffer.callbacks);
|
|
158
|
+
return buffer.length === 1 ? "callbacks" in buffer ? resolveCallbackSync(raw(buffer[0], buffer.callbacks)).toString() : buffer[0] : stringBufferToString(buffer, buffer.callbacks).then(markRenderedJSX);
|
|
118
159
|
};
|
|
119
160
|
return runWithRenderContext(render);
|
|
120
161
|
}
|
|
@@ -127,34 +168,10 @@ var JSXNode = class {
|
|
|
127
168
|
for (let [key, v] of Object.entries(props)) {
|
|
128
169
|
key = normalizeKey(key);
|
|
129
170
|
if (!isValidAttributeName(key)) continue;
|
|
130
|
-
if (key === "children") {} else if (key === "
|
|
131
|
-
let styleStr = "";
|
|
132
|
-
styleObjectForEach(v, (property, value) => {
|
|
133
|
-
if (value != null) styleStr += `${styleStr ? ";" : ""}${property}:${value}`;
|
|
134
|
-
});
|
|
135
|
-
buffer[0] += " style=\"";
|
|
136
|
-
escapeToBuffer(styleStr, buffer);
|
|
137
|
-
buffer[0] += "\"";
|
|
138
|
-
} else if (typeof v === "string") {
|
|
139
|
-
buffer[0] += ` ${key}="`;
|
|
140
|
-
escapeToBuffer(v, buffer);
|
|
141
|
-
buffer[0] += "\"";
|
|
142
|
-
} else if (v === null || v === void 0) {} else if (typeof v === "number" || v.isEscaped) buffer[0] += ` ${key}="${v}"`;
|
|
143
|
-
else if (typeof v === "boolean" && booleanAttributes.includes(key)) {
|
|
144
|
-
if (v) buffer[0] += ` ${key}=""`;
|
|
145
|
-
} else if (key === "dangerouslySetInnerHTML") {
|
|
171
|
+
if (key === "children") {} else if (key === "dangerouslySetInnerHTML" && typeof v === "object" && v !== null && "__html" in v) {
|
|
146
172
|
if (children.length > 0) throw new Error("Can only set one of `children` or `props.dangerouslySetInnerHTML`.");
|
|
147
173
|
children = [raw(v.__html)];
|
|
148
|
-
} else
|
|
149
|
-
buffer[0] += ` ${key}="`;
|
|
150
|
-
buffer.unshift("\"", v);
|
|
151
|
-
} else if (typeof v === "function") {
|
|
152
|
-
if (!key.startsWith("on") && key !== "ref") throw new Error(`Invalid prop '${key}' of type 'function' supplied to '${tag}'.`);
|
|
153
|
-
} else {
|
|
154
|
-
buffer[0] += ` ${key}="`;
|
|
155
|
-
escapeToBuffer(v.toString(), buffer);
|
|
156
|
-
buffer[0] += "\"";
|
|
157
|
-
}
|
|
174
|
+
} else attributeToBuffer(buffer, " ", key, v, tag);
|
|
158
175
|
}
|
|
159
176
|
if (emptyTags.includes(tag) && children.length === 0) {
|
|
160
177
|
buffer[0] += "/>";
|
|
@@ -239,7 +256,7 @@ const cloneElement = (element, props, ...children) => {
|
|
|
239
256
|
if (children.length > 0) childrenToClone = children;
|
|
240
257
|
else {
|
|
241
258
|
const c = element.props.children;
|
|
242
|
-
childrenToClone = Array.isArray(c) ? c : [c];
|
|
259
|
+
childrenToClone = c !== void 0 ? Array.isArray(c) ? c : [c] : [];
|
|
243
260
|
}
|
|
244
261
|
return jsx(element.tag, {
|
|
245
262
|
...element.props,
|
|
@@ -248,4 +265,4 @@ const cloneElement = (element, props, ...children) => {
|
|
|
248
265
|
};
|
|
249
266
|
const reactAPICompatVersion = "19.0.0-hono-jsx";
|
|
250
267
|
//#endregion
|
|
251
|
-
export { Fragment, JSXFragmentNode, JSXNode, booleanAttributes, cloneElement, getNameSpaceContext, isUntrustedObject, isValidElement, jsx, jsxFn, memo, reactAPICompatVersion, renderChildren, renderUntrustedObject, shallowEqual };
|
|
268
|
+
export { Fragment, JSXFragmentNode, JSXNode, attributeToBuffer, booleanAttributes, cloneElement, getNameSpaceContext, isUntrustedObject, isValidElement, jsx, jsxFn, markRenderedJSX, memo, reactAPICompatVersion, renderChildren, renderUntrustedObject, shallowEqual };
|
|
@@ -77,7 +77,7 @@ const ErrorBoundary = async ({ children, fallback, fallbackRender, onError }) =>
|
|
|
77
77
|
buffer[0] = buffer[0].replace(replaceRe, () => fallbackResString);
|
|
78
78
|
return fallbackCallbacks?.length ? raw("", fallbackCallbacks) : "";
|
|
79
79
|
}
|
|
80
|
-
return raw(`<template data-hono-target="E:${index}">${fallbackResString}</template><script>
|
|
80
|
+
return raw(`<template data-hono-target="E:${index}">${fallbackResString}</template><script${nonce ? ` nonce="${nonce}"` : ""}>
|
|
81
81
|
((d,c,n) => {
|
|
82
82
|
c=d.currentScript.previousSibling
|
|
83
83
|
d=d.getElementById('E:${index}')
|
|
@@ -118,7 +118,7 @@ d.parentElement.insertBefore(c.content,d.nextSibling)
|
|
|
118
118
|
buffer[0] += content;
|
|
119
119
|
return raw("", content.callbacks);
|
|
120
120
|
}
|
|
121
|
-
return raw(content + (resolvedCount !== callbacks.length ? "" : `<script>
|
|
121
|
+
return raw(content + (resolvedCount !== callbacks.length ? "" : `<script${nonce ? ` nonce="${nonce}"` : ""}>
|
|
122
122
|
((d,c,n) => {
|
|
123
123
|
d=d.getElementById('E:${index}')
|
|
124
124
|
if(!d)return
|
|
@@ -5,5 +5,6 @@ const DOM_STASH = Symbol("STASH");
|
|
|
5
5
|
const DOM_INTERNAL_TAG = Symbol("INTERNAL");
|
|
6
6
|
const DOM_MEMO = Symbol("MEMO");
|
|
7
7
|
const PERMALINK = Symbol("PERMALINK");
|
|
8
|
+
const RENDERED_JSX = Symbol("RENDERED_JSX");
|
|
8
9
|
//#endregion
|
|
9
|
-
export { DOM_ERROR_HANDLER, DOM_INTERNAL_TAG, DOM_MEMO, DOM_RENDERER, DOM_STASH, PERMALINK };
|
|
10
|
+
export { DOM_ERROR_HANDLER, DOM_INTERNAL_TAG, DOM_MEMO, DOM_RENDERER, DOM_STASH, PERMALINK, RENDERED_JSX };
|
|
@@ -131,11 +131,24 @@ const captureRenderContext = () => {
|
|
|
131
131
|
const createContext = (defaultValue) => {
|
|
132
132
|
const values = [defaultValue];
|
|
133
133
|
const context = ((props) => {
|
|
134
|
-
const
|
|
134
|
+
const renderChildrenOf = () => typeof props.children === "string" ? renderChildren([props.children]) : isUntrustedObject(props.children) ? renderUntrustedObject(props.children) : props.children ? (Array.isArray(props.children) ? new JSXFragmentNode("", {}, props.children) : props.children).toString() : raw("");
|
|
135
|
+
const store = getCurrentStore();
|
|
136
|
+
const storage = store && loadAsyncLocalStorage();
|
|
137
|
+
if (store && storage) {
|
|
138
|
+
const ownStore = /* @__PURE__ */ new WeakMap();
|
|
139
|
+
for (const c of globalContexts) {
|
|
140
|
+
const current = store.get(c);
|
|
141
|
+
if (current) ownStore.set(c, [...current]);
|
|
142
|
+
}
|
|
143
|
+
getContextValuesIn(ownStore, context).push(props.value);
|
|
144
|
+
const rendered = storage.run(ownStore, renderChildrenOf);
|
|
145
|
+
return rendered instanceof Promise ? rendered.then((resString) => raw(resString, resString.callbacks)) : raw(rendered);
|
|
146
|
+
}
|
|
147
|
+
const contextValues = getContextValuesIn(store, context);
|
|
135
148
|
contextValues.push(props.value);
|
|
136
149
|
let rendered;
|
|
137
150
|
try {
|
|
138
|
-
rendered =
|
|
151
|
+
rendered = renderChildrenOf();
|
|
139
152
|
} catch (e) {
|
|
140
153
|
contextValues.pop();
|
|
141
154
|
throw e;
|