@orchestraai/agent-tools 0.10.15 → 0.10.17
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/README.md +9 -0
- package/dist/commands/claude-setup.d.ts +1 -1
- package/dist/onboarding/init.js +6 -2
- package/dist/onboarding/init.js.map +1 -1
- package/dist/runtime/conversation/command-guard.js +1023 -63
- package/dist/runtime/conversation/command-guard.js.map +1 -1
- package/dist/runtime/conversation/shell-parse.d.ts +42 -0
- package/dist/runtime/conversation/shell-parse.js +517 -0
- package/dist/runtime/conversation/shell-parse.js.map +1 -0
- package/docs/security.md +11 -2
- package/install.sh +41 -7
- 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
- package/skills/install-agent-adapter/reference.md +8 -0
|
@@ -2,8 +2,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_compose = require("./compose.js");
|
|
3
3
|
const require_utils_url = require("./utils/url.js");
|
|
4
4
|
const require_context = require("./context.js");
|
|
5
|
+
const require_helper_route_index = require("./helper/route/index.js");
|
|
5
6
|
const require_router = require("./router.js");
|
|
6
7
|
const require_utils_constants = require("./utils/constants.js");
|
|
8
|
+
const require_utils_mount = require("./utils/mount.js");
|
|
7
9
|
//#region src/hono-base.ts
|
|
8
10
|
/**
|
|
9
11
|
* @module
|
|
@@ -184,6 +186,8 @@ var Hono = class Hono {
|
|
|
184
186
|
* @param {Function} applicationHandler - other Request Handler
|
|
185
187
|
* @param {MountOptions} [options] - options of `.mount()`
|
|
186
188
|
* @returns {Hono} mounted Hono instance
|
|
189
|
+
* @throws {Error} If automatic request rewriting encounters duplicate path parameter names or an optional regular expression parameter.
|
|
190
|
+
* @throws {HTTPException} With status 400 if automatic request rewriting cannot safely preserve the routed path.
|
|
187
191
|
*
|
|
188
192
|
* @example
|
|
189
193
|
* ```ts
|
|
@@ -228,17 +232,12 @@ var Hono = class Hono {
|
|
|
228
232
|
} catch {}
|
|
229
233
|
return [c.env, executionContext];
|
|
230
234
|
};
|
|
231
|
-
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
const url = new URL(request.url);
|
|
236
|
-
url.pathname = this.getPath(request).slice(pathPrefixLength) || "/";
|
|
237
|
-
return new Request(url, request);
|
|
238
|
-
};
|
|
239
|
-
})();
|
|
235
|
+
const defaultReplaceRequest = (c) => {
|
|
236
|
+
const mountedRoutePath = require_helper_route_index.routePath(c);
|
|
237
|
+
return require_utils_mount.createMountedRequest(c, mountedRoutePath.replace(/\/?\*$/, ""), mountedRoutePath);
|
|
238
|
+
};
|
|
240
239
|
const handler = async (c, next) => {
|
|
241
|
-
const res = await applicationHandler(replaceRequest(c.req.raw), ...getOptions(c));
|
|
240
|
+
const res = await applicationHandler(replaceRequest ? replaceRequest(c.req.raw) : defaultReplaceRequest(c), ...getOptions(c));
|
|
242
241
|
if (res) return res;
|
|
243
242
|
await next();
|
|
244
243
|
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_hono_base = require("./hono-base.js");
|
|
3
3
|
const require_router_reg_exp_router_router = require("./router/reg-exp-router/router.js");
|
|
4
|
-
require("./router/reg-exp-router/index.js");
|
|
5
4
|
const require_router_smart_router_router = require("./router/smart-router/router.js");
|
|
6
5
|
const require_router_trie_router_router = require("./router/trie-router/router.js");
|
|
7
6
|
require("./router/trie-router/index.js");
|
|
@@ -26,7 +26,7 @@ const emptyTags = [
|
|
|
26
26
|
"track",
|
|
27
27
|
"wbr"
|
|
28
28
|
];
|
|
29
|
-
const booleanAttributes = [
|
|
29
|
+
const booleanAttributes = /* @__PURE__ */ new Set([
|
|
30
30
|
"allowfullscreen",
|
|
31
31
|
"async",
|
|
32
32
|
"autofocus",
|
|
@@ -52,8 +52,11 @@ const booleanAttributes = [
|
|
|
52
52
|
"readonly",
|
|
53
53
|
"required",
|
|
54
54
|
"reversed",
|
|
55
|
-
"selected"
|
|
56
|
-
|
|
55
|
+
"selected",
|
|
56
|
+
"shadowrootclonable",
|
|
57
|
+
"shadowrootdelegatesfocus",
|
|
58
|
+
"shadowrootserializable"
|
|
59
|
+
]);
|
|
57
60
|
const resolveFunctionComponentResult = (result, suspendedContext) => result.then((resolved) => {
|
|
58
61
|
if (typeof resolved !== "string" && !Array.isArray(resolved) && !(resolved instanceof JSXNode)) return resolved;
|
|
59
62
|
const children = Array.isArray(resolved) ? resolved : [resolved];
|
|
@@ -64,6 +67,44 @@ const resolveFunctionComponentResult = (result, suspendedContext) => result.then
|
|
|
64
67
|
};
|
|
65
68
|
return suspendedContext ? suspendedContext(render) : require_jsx_context.runWithRenderContext(render);
|
|
66
69
|
});
|
|
70
|
+
const markRenderedJSX = (value) => {
|
|
71
|
+
value[require_jsx_constants.RENDERED_JSX] = true;
|
|
72
|
+
return value;
|
|
73
|
+
};
|
|
74
|
+
const isEscapedAttribute = (value) => value instanceof String && value.isEscaped && !(require_jsx_constants.RENDERED_JSX in value);
|
|
75
|
+
const objectToAttributeString = (v) => {
|
|
76
|
+
const s = v.toString();
|
|
77
|
+
return s instanceof Promise ? s.then(String) : String(s);
|
|
78
|
+
};
|
|
79
|
+
const attributeToBuffer = (buffer, prefix, key, v, tag) => {
|
|
80
|
+
if (key === "ref" || v === null || v === void 0) return;
|
|
81
|
+
if (typeof v === "boolean" && booleanAttributes.has(key)) {
|
|
82
|
+
if (v) buffer[0] += `${prefix}${key}=""`;
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (typeof v === "function") {
|
|
86
|
+
if (!key.startsWith("on")) throw new Error(`Invalid prop '${key}' of type 'function' supplied to ${tag ? `'${tag}'` : "a JSX element"}.`);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
buffer[0] += `${prefix}${key}="`;
|
|
90
|
+
if (key === "style" && typeof v === "object") {
|
|
91
|
+
let styleStr = "";
|
|
92
|
+
require_jsx_utils.styleObjectForEach(v, (property, value) => {
|
|
93
|
+
if (value != null) styleStr += `${styleStr ? ";" : ""}${property}:${value}`;
|
|
94
|
+
});
|
|
95
|
+
require_utils_html.escapeToBuffer(styleStr, buffer);
|
|
96
|
+
} else if (typeof v === "string") require_utils_html.escapeToBuffer(v, buffer);
|
|
97
|
+
else if (typeof v === "number" || isEscapedAttribute(v)) buffer[0] += `${v}`;
|
|
98
|
+
else {
|
|
99
|
+
const s = v instanceof Promise ? v.then((r) => typeof r === "object" && r !== null && !isEscapedAttribute(r) ? objectToAttributeString(r) : r) : objectToAttributeString(v);
|
|
100
|
+
if (s instanceof Promise) {
|
|
101
|
+
buffer.unshift("\"", s);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
require_utils_html.escapeToBuffer(s, buffer);
|
|
105
|
+
}
|
|
106
|
+
buffer[0] += "\"";
|
|
107
|
+
};
|
|
67
108
|
const childrenToStringToBuffer = (children, buffer) => {
|
|
68
109
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
69
110
|
const child = children[i];
|
|
@@ -79,7 +120,7 @@ const childrenToStringToBuffer = (children, buffer) => {
|
|
|
79
120
|
buffer.callbacks.push(...callbacks);
|
|
80
121
|
}
|
|
81
122
|
} else if (child instanceof Promise) buffer.unshift("", child);
|
|
82
|
-
else childrenToStringToBuffer(child, buffer);
|
|
123
|
+
else if (Array.isArray(child)) childrenToStringToBuffer(child, buffer);
|
|
83
124
|
}
|
|
84
125
|
};
|
|
85
126
|
const renderChildren = (children) => require_jsx_context.runWithRenderContext(() => {
|
|
@@ -115,7 +156,7 @@ var JSXNode = class {
|
|
|
115
156
|
const render = () => {
|
|
116
157
|
const buffer = [""];
|
|
117
158
|
this.toStringToBuffer(buffer);
|
|
118
|
-
return buffer.length === 1 ? "callbacks" in buffer ? require_utils_html.resolveCallbackSync(require_utils_html.raw(buffer[0], buffer.callbacks)).toString() : buffer[0] : require_utils_html.stringBufferToString(buffer, buffer.callbacks);
|
|
159
|
+
return buffer.length === 1 ? "callbacks" in buffer ? require_utils_html.resolveCallbackSync(require_utils_html.raw(buffer[0], buffer.callbacks)).toString() : buffer[0] : require_utils_html.stringBufferToString(buffer, buffer.callbacks).then(markRenderedJSX);
|
|
119
160
|
};
|
|
120
161
|
return require_jsx_context.runWithRenderContext(render);
|
|
121
162
|
}
|
|
@@ -128,34 +169,10 @@ var JSXNode = class {
|
|
|
128
169
|
for (let [key, v] of Object.entries(props)) {
|
|
129
170
|
key = normalizeKey(key);
|
|
130
171
|
if (!require_jsx_utils.isValidAttributeName(key)) continue;
|
|
131
|
-
if (key === "children") {} else if (key === "
|
|
132
|
-
let styleStr = "";
|
|
133
|
-
require_jsx_utils.styleObjectForEach(v, (property, value) => {
|
|
134
|
-
if (value != null) styleStr += `${styleStr ? ";" : ""}${property}:${value}`;
|
|
135
|
-
});
|
|
136
|
-
buffer[0] += " style=\"";
|
|
137
|
-
require_utils_html.escapeToBuffer(styleStr, buffer);
|
|
138
|
-
buffer[0] += "\"";
|
|
139
|
-
} else if (typeof v === "string") {
|
|
140
|
-
buffer[0] += ` ${key}="`;
|
|
141
|
-
require_utils_html.escapeToBuffer(v, buffer);
|
|
142
|
-
buffer[0] += "\"";
|
|
143
|
-
} else if (v === null || v === void 0) {} else if (typeof v === "number" || v.isEscaped) buffer[0] += ` ${key}="${v}"`;
|
|
144
|
-
else if (typeof v === "boolean" && booleanAttributes.includes(key)) {
|
|
145
|
-
if (v) buffer[0] += ` ${key}=""`;
|
|
146
|
-
} else if (key === "dangerouslySetInnerHTML") {
|
|
172
|
+
if (key === "children") {} else if (key === "dangerouslySetInnerHTML" && typeof v === "object" && v !== null && "__html" in v) {
|
|
147
173
|
if (children.length > 0) throw new Error("Can only set one of `children` or `props.dangerouslySetInnerHTML`.");
|
|
148
174
|
children = [require_utils_html.raw(v.__html)];
|
|
149
|
-
} else
|
|
150
|
-
buffer[0] += ` ${key}="`;
|
|
151
|
-
buffer.unshift("\"", v);
|
|
152
|
-
} else if (typeof v === "function") {
|
|
153
|
-
if (!key.startsWith("on") && key !== "ref") throw new Error(`Invalid prop '${key}' of type 'function' supplied to '${tag}'.`);
|
|
154
|
-
} else {
|
|
155
|
-
buffer[0] += ` ${key}="`;
|
|
156
|
-
require_utils_html.escapeToBuffer(v.toString(), buffer);
|
|
157
|
-
buffer[0] += "\"";
|
|
158
|
-
}
|
|
175
|
+
} else attributeToBuffer(buffer, " ", key, v, tag);
|
|
159
176
|
}
|
|
160
177
|
if (emptyTags.includes(tag) && children.length === 0) {
|
|
161
178
|
buffer[0] += "/>";
|
|
@@ -240,7 +257,7 @@ const cloneElement = (element, props, ...children) => {
|
|
|
240
257
|
if (children.length > 0) childrenToClone = children;
|
|
241
258
|
else {
|
|
242
259
|
const c = element.props.children;
|
|
243
|
-
childrenToClone = Array.isArray(c) ? c : [c];
|
|
260
|
+
childrenToClone = c !== void 0 ? Array.isArray(c) ? c : [c] : [];
|
|
244
261
|
}
|
|
245
262
|
return jsx(element.tag, {
|
|
246
263
|
...element.props,
|
|
@@ -252,6 +269,7 @@ const reactAPICompatVersion = "19.0.0-hono-jsx";
|
|
|
252
269
|
exports.Fragment = Fragment;
|
|
253
270
|
exports.JSXFragmentNode = JSXFragmentNode;
|
|
254
271
|
exports.JSXNode = JSXNode;
|
|
272
|
+
exports.attributeToBuffer = attributeToBuffer;
|
|
255
273
|
exports.booleanAttributes = booleanAttributes;
|
|
256
274
|
exports.cloneElement = cloneElement;
|
|
257
275
|
exports.getNameSpaceContext = getNameSpaceContext;
|
|
@@ -259,6 +277,7 @@ exports.isUntrustedObject = isUntrustedObject;
|
|
|
259
277
|
exports.isValidElement = isValidElement;
|
|
260
278
|
exports.jsx = jsx;
|
|
261
279
|
exports.jsxFn = jsxFn;
|
|
280
|
+
exports.markRenderedJSX = markRenderedJSX;
|
|
262
281
|
exports.memo = memo;
|
|
263
282
|
exports.reactAPICompatVersion = reactAPICompatVersion;
|
|
264
283
|
exports.renderChildren = renderChildren;
|
|
@@ -78,7 +78,7 @@ const ErrorBoundary = async ({ children, fallback, fallbackRender, onError }) =>
|
|
|
78
78
|
buffer[0] = buffer[0].replace(replaceRe, () => fallbackResString);
|
|
79
79
|
return fallbackCallbacks?.length ? require_utils_html.raw("", fallbackCallbacks) : "";
|
|
80
80
|
}
|
|
81
|
-
return require_utils_html.raw(`<template data-hono-target="E:${index}">${fallbackResString}</template><script>
|
|
81
|
+
return require_utils_html.raw(`<template data-hono-target="E:${index}">${fallbackResString}</template><script${nonce ? ` nonce="${nonce}"` : ""}>
|
|
82
82
|
((d,c,n) => {
|
|
83
83
|
c=d.currentScript.previousSibling
|
|
84
84
|
d=d.getElementById('E:${index}')
|
|
@@ -119,7 +119,7 @@ d.parentElement.insertBefore(c.content,d.nextSibling)
|
|
|
119
119
|
buffer[0] += content;
|
|
120
120
|
return require_utils_html.raw("", content.callbacks);
|
|
121
121
|
}
|
|
122
|
-
return require_utils_html.raw(content + (resolvedCount !== callbacks.length ? "" : `<script>
|
|
122
|
+
return require_utils_html.raw(content + (resolvedCount !== callbacks.length ? "" : `<script${nonce ? ` nonce="${nonce}"` : ""}>
|
|
123
123
|
((d,c,n) => {
|
|
124
124
|
d=d.getElementById('E:${index}')
|
|
125
125
|
if(!d)return
|
|
@@ -6,6 +6,7 @@ const DOM_STASH = Symbol("STASH");
|
|
|
6
6
|
const DOM_INTERNAL_TAG = Symbol("INTERNAL");
|
|
7
7
|
const DOM_MEMO = Symbol("MEMO");
|
|
8
8
|
const PERMALINK = Symbol("PERMALINK");
|
|
9
|
+
const RENDERED_JSX = Symbol("RENDERED_JSX");
|
|
9
10
|
//#endregion
|
|
10
11
|
exports.DOM_ERROR_HANDLER = DOM_ERROR_HANDLER;
|
|
11
12
|
exports.DOM_INTERNAL_TAG = DOM_INTERNAL_TAG;
|
|
@@ -13,3 +14,4 @@ exports.DOM_MEMO = DOM_MEMO;
|
|
|
13
14
|
exports.DOM_RENDERER = DOM_RENDERER;
|
|
14
15
|
exports.DOM_STASH = DOM_STASH;
|
|
15
16
|
exports.PERMALINK = PERMALINK;
|
|
17
|
+
exports.RENDERED_JSX = RENDERED_JSX;
|
|
@@ -132,11 +132,24 @@ const captureRenderContext = () => {
|
|
|
132
132
|
const createContext = (defaultValue) => {
|
|
133
133
|
const values = [defaultValue];
|
|
134
134
|
const context = ((props) => {
|
|
135
|
-
const
|
|
135
|
+
const renderChildrenOf = () => typeof props.children === "string" ? require_jsx_base.renderChildren([props.children]) : require_jsx_base.isUntrustedObject(props.children) ? require_jsx_base.renderUntrustedObject(props.children) : props.children ? (Array.isArray(props.children) ? new require_jsx_base.JSXFragmentNode("", {}, props.children) : props.children).toString() : require_utils_html.raw("");
|
|
136
|
+
const store = getCurrentStore();
|
|
137
|
+
const storage = store && loadAsyncLocalStorage();
|
|
138
|
+
if (store && storage) {
|
|
139
|
+
const ownStore = /* @__PURE__ */ new WeakMap();
|
|
140
|
+
for (const c of globalContexts) {
|
|
141
|
+
const current = store.get(c);
|
|
142
|
+
if (current) ownStore.set(c, [...current]);
|
|
143
|
+
}
|
|
144
|
+
getContextValuesIn(ownStore, context).push(props.value);
|
|
145
|
+
const rendered = storage.run(ownStore, renderChildrenOf);
|
|
146
|
+
return rendered instanceof Promise ? rendered.then((resString) => require_utils_html.raw(resString, resString.callbacks)) : require_utils_html.raw(rendered);
|
|
147
|
+
}
|
|
148
|
+
const contextValues = getContextValuesIn(store, context);
|
|
136
149
|
contextValues.push(props.value);
|
|
137
150
|
let rendered;
|
|
138
151
|
try {
|
|
139
|
-
rendered =
|
|
152
|
+
rendered = renderChildrenOf();
|
|
140
153
|
} catch (e) {
|
|
141
154
|
contextValues.pop();
|
|
142
155
|
throw e;
|
|
@@ -17,7 +17,7 @@ const Suspense = (({ children, fallback }) => {
|
|
|
17
17
|
res[require_jsx_constants.DOM_ERROR_HANDLER] = (err, retry) => {
|
|
18
18
|
if (!(err instanceof Promise)) throw err;
|
|
19
19
|
err.finally(retry);
|
|
20
|
-
return fallback;
|
|
20
|
+
return fallback || require_jsx_dom_jsx_dev_runtime.jsxDEV(require_jsx_dom_jsx_dev_runtime.Fragment, { children: fallback });
|
|
21
21
|
};
|
|
22
22
|
return res;
|
|
23
23
|
});
|
|
@@ -16,7 +16,10 @@ const FormContext = require_jsx_dom_context.createContext({
|
|
|
16
16
|
const actions = /* @__PURE__ */ new Set();
|
|
17
17
|
const registerAction = (action) => {
|
|
18
18
|
actions.add(action);
|
|
19
|
-
|
|
19
|
+
const remove = () => {
|
|
20
|
+
actions.delete(action);
|
|
21
|
+
};
|
|
22
|
+
action.then(remove, remove);
|
|
20
23
|
};
|
|
21
24
|
/**
|
|
22
25
|
* This hook returns the current form status
|
|
@@ -34,7 +37,7 @@ const useFormStatus = () => {
|
|
|
34
37
|
*/
|
|
35
38
|
const useOptimistic = (state, updateState) => {
|
|
36
39
|
const [optimisticState, setOptimisticState] = require_jsx_hooks_index.useState(state);
|
|
37
|
-
if (actions.size > 0) Promise.
|
|
40
|
+
if (actions.size > 0) Promise.allSettled(actions).then(() => {
|
|
38
41
|
setOptimisticState(state);
|
|
39
42
|
});
|
|
40
43
|
else setOptimisticState(state);
|
|
@@ -43,19 +46,46 @@ const useOptimistic = (state, updateState) => {
|
|
|
43
46
|
}, [])];
|
|
44
47
|
};
|
|
45
48
|
/**
|
|
46
|
-
* This hook returns the current state
|
|
49
|
+
* This hook returns the current state, a function to update the state by form action,
|
|
50
|
+
* and whether an action is pending
|
|
51
|
+
* Actions run one at a time, each receiving the state returned by the previous one
|
|
47
52
|
* @param fn
|
|
48
53
|
* @param initialState
|
|
49
54
|
* @param permalink
|
|
50
|
-
* @returns [T, (data: FormData) => void]
|
|
55
|
+
* @returns [T, (data: FormData) => Promise<void>, boolean]
|
|
51
56
|
*/
|
|
52
57
|
const useActionState = (fn, initialState, permalink) => {
|
|
53
58
|
const [state, setState] = require_jsx_hooks_index.useState(initialState);
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
59
|
+
const [pendingCount, setPendingCount] = require_jsx_hooks_index.useState(0);
|
|
60
|
+
const ref = require_jsx_hooks_index.useRef({
|
|
61
|
+
fn,
|
|
62
|
+
state: initialState,
|
|
63
|
+
pending: 0,
|
|
64
|
+
queue: Promise.resolve()
|
|
65
|
+
});
|
|
66
|
+
ref.current.fn = fn;
|
|
67
|
+
const actionState = require_jsx_hooks_index.useCallback((data) => {
|
|
68
|
+
const current = ref.current;
|
|
69
|
+
const run = async () => {
|
|
70
|
+
try {
|
|
71
|
+
current.state = await current.fn(current.state, data);
|
|
72
|
+
setState(current.state);
|
|
73
|
+
} finally {
|
|
74
|
+
current.pending--;
|
|
75
|
+
setPendingCount((count) => count - 1);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const result = current.pending++ ? current.queue.then(run) : run();
|
|
79
|
+
current.queue = result.catch(() => {});
|
|
80
|
+
setPendingCount((count) => count + 1);
|
|
81
|
+
return result;
|
|
82
|
+
}, []);
|
|
57
83
|
actionState[require_jsx_constants.PERMALINK] = permalink;
|
|
58
|
-
return [
|
|
84
|
+
return [
|
|
85
|
+
state,
|
|
86
|
+
actionState,
|
|
87
|
+
pendingCount > 0
|
|
88
|
+
];
|
|
59
89
|
};
|
|
60
90
|
//#endregion
|
|
61
91
|
exports.FormContext = FormContext;
|
|
@@ -218,12 +218,15 @@ const form = (props) => {
|
|
|
218
218
|
ev.preventDefault();
|
|
219
219
|
const formData = new FormData(ev.target);
|
|
220
220
|
setState([formData, true]);
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
221
|
+
try {
|
|
222
|
+
const actionRes = currentAction(formData);
|
|
223
|
+
if (actionRes instanceof Promise) {
|
|
224
|
+
require_jsx_dom_hooks_index.registerAction(actionRes);
|
|
225
|
+
await actionRes;
|
|
226
|
+
}
|
|
227
|
+
} finally {
|
|
228
|
+
setState([null, true]);
|
|
225
229
|
}
|
|
226
|
-
setState([null, true]);
|
|
227
230
|
}, []);
|
|
228
231
|
const ref = composeRef(props.ref, (el) => {
|
|
229
232
|
el.addEventListener("submit", onSubmit);
|
|
@@ -156,7 +156,11 @@ const findInsertBefore = (node) => {
|
|
|
156
156
|
};
|
|
157
157
|
const removeNode = (node) => {
|
|
158
158
|
if (!isNodeString(node)) {
|
|
159
|
-
node[require_jsx_constants.DOM_STASH]
|
|
159
|
+
const stash = node[require_jsx_constants.DOM_STASH];
|
|
160
|
+
if (stash?.[1][1]) {
|
|
161
|
+
stash[1][1].forEach((data) => data[2]?.());
|
|
162
|
+
delete stash[1][1];
|
|
163
|
+
}
|
|
160
164
|
refCleanupMap.get(node.e)?.();
|
|
161
165
|
if (node.p === 2) node.vC?.forEach((n) => n.p = 2);
|
|
162
166
|
node.vC?.forEach(removeNode);
|
|
@@ -213,8 +217,9 @@ const applyNodeObject = (node, container, isNew) => {
|
|
|
213
217
|
child.d = false;
|
|
214
218
|
el = child.e ||= document.createTextNode(child.t);
|
|
215
219
|
} else {
|
|
220
|
+
const isCreated = !child.e;
|
|
216
221
|
el = child.e ||= child.n ? document.createElementNS(child.n, child.tag) : document.createElement(child.tag);
|
|
217
|
-
applyProps(el, child.props, child.pP);
|
|
222
|
+
applyProps(el, child.props, isCreated ? void 0 : child.pP);
|
|
218
223
|
applyNodeObject(child, el, isNewLocal);
|
|
219
224
|
if (child.tag === "select") applySelectValue(el, child.props);
|
|
220
225
|
}
|
|
@@ -344,6 +349,7 @@ const build = (context, node, children) => {
|
|
|
344
349
|
prevNode = child;
|
|
345
350
|
}
|
|
346
351
|
}
|
|
352
|
+
if (prevNode && !prevNode.s) for (let p = prevNode; p && !isNodeString(p); p = p.vC?.at(-1)) p.nN = node.nN;
|
|
347
353
|
oldVChildren = oldChildrenByKey ? [...oldChildrenByKey.values()] : oldVChildren;
|
|
348
354
|
node.vR = buildWithPreviousChildren ? [...node.vC, ...oldVChildren || []] : oldVChildren || [];
|
|
349
355
|
node.vC = vChildren;
|
|
@@ -378,7 +384,7 @@ const build = (context, node, children) => {
|
|
|
378
384
|
if (context[0] === 1) context[1] = true;
|
|
379
385
|
else {
|
|
380
386
|
build(context, errorHandlerNode, [fallback]);
|
|
381
|
-
if ((errorHandler.length === 1 || context !== errorHandlerContext) && errorHandlerNode.c) {
|
|
387
|
+
if ((errorHandler.length === 1 || context !== errorHandlerContext) && errorHandlerNode.c && !context[5].some(([, , n]) => n === errorHandlerNode)) {
|
|
382
388
|
apply(errorHandlerNode, errorHandlerNode.c, false);
|
|
383
389
|
return;
|
|
384
390
|
}
|
|
@@ -1,30 +1,26 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_utils_html = require("../utils/html.js");
|
|
3
3
|
const require_helper_html_index = require("../helper/html/index.js");
|
|
4
|
+
const require_jsx_constants = require("./constants.js");
|
|
4
5
|
const require_jsx_utils = require("./utils.js");
|
|
5
6
|
const require_jsx_base = require("./base.js");
|
|
6
7
|
const require_jsx_jsx_dev_runtime = require("./jsx-dev-runtime.js");
|
|
7
8
|
//#region src/jsx/jsx-runtime.ts
|
|
9
|
+
const jsxTemplate = (strings, ...values) => {
|
|
10
|
+
const result = require_helper_html_index.html(strings, ...values);
|
|
11
|
+
return result instanceof Promise ? result.then(require_jsx_base.markRenderedJSX) : require_jsx_base.markRenderedJSX(result);
|
|
12
|
+
};
|
|
8
13
|
const jsxAttr = (key, v) => {
|
|
9
14
|
if (!require_jsx_utils.isValidAttributeName(key)) return require_utils_html.raw("");
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
let styleStr = "";
|
|
13
|
-
require_jsx_utils.styleObjectForEach(v, (property, value) => {
|
|
14
|
-
if (value != null) styleStr += `${styleStr ? ";" : ""}${property}:${value}`;
|
|
15
|
-
});
|
|
16
|
-
require_utils_html.escapeToBuffer(styleStr, buffer);
|
|
17
|
-
buffer[0] += "\"";
|
|
18
|
-
} else if (typeof v === "string") {
|
|
15
|
+
if (typeof v === "string") {
|
|
16
|
+
const buffer = [`${key}="`];
|
|
19
17
|
require_utils_html.escapeToBuffer(v, buffer);
|
|
20
|
-
buffer[0]
|
|
21
|
-
} else if (v === null || v === void 0) return require_utils_html.raw("");
|
|
22
|
-
else if (typeof v === "number" || v.isEscaped) buffer[0] += `${v}"`;
|
|
23
|
-
else if (v instanceof Promise) buffer.unshift("\"", v);
|
|
24
|
-
else {
|
|
25
|
-
require_utils_html.escapeToBuffer(v.toString(), buffer);
|
|
26
|
-
buffer[0] += "\"";
|
|
18
|
+
return require_utils_html.raw(buffer[0] + "\"");
|
|
27
19
|
}
|
|
20
|
+
let value = v;
|
|
21
|
+
if (typeof value === "function" && (key === "action" || key === "formaction")) value = require_jsx_constants.PERMALINK in value ? value[require_jsx_constants.PERMALINK] : void 0;
|
|
22
|
+
const buffer = [""];
|
|
23
|
+
require_jsx_base.attributeToBuffer(buffer, "", key, value);
|
|
28
24
|
return buffer.length === 1 ? require_utils_html.raw(buffer[0]) : require_utils_html.stringBufferToString(buffer, void 0);
|
|
29
25
|
};
|
|
30
26
|
const jsxEscape = (value) => value;
|
|
@@ -33,5 +29,5 @@ exports.Fragment = require_jsx_base.Fragment;
|
|
|
33
29
|
exports.jsx = require_jsx_jsx_dev_runtime.jsxDEV;
|
|
34
30
|
exports.jsxAttr = jsxAttr;
|
|
35
31
|
exports.jsxEscape = jsxEscape;
|
|
36
|
-
exports.jsxTemplate =
|
|
32
|
+
exports.jsxTemplate = jsxTemplate;
|
|
37
33
|
exports.jsxs = require_jsx_jsx_dev_runtime.jsxDEV;
|
|
@@ -16,6 +16,7 @@ const require_utils_basic_auth = require("../../utils/basic-auth.js");
|
|
|
16
16
|
* @param {Function} [options.verifyUser] - The function to verify user credentials.
|
|
17
17
|
* @param {string | object | MessageFunction} [options.invalidUserMessage="Unauthorized"] - The invalid user message.
|
|
18
18
|
* @param {Function} [options.onAuthSuccess] - Callback function called on successful authentication.
|
|
19
|
+
* @param {...{ username: string; password: string }} [users] - Additional user credentials.
|
|
19
20
|
* @returns {MiddlewareHandler} The middleware handler function.
|
|
20
21
|
* @throws {HTTPException} If neither "username and password" nor "verifyUser" options are provided.
|
|
21
22
|
*
|
|
@@ -62,6 +63,7 @@ const basicAuth = (options, ...users) => {
|
|
|
62
63
|
username: options.username,
|
|
63
64
|
password: options.password
|
|
64
65
|
});
|
|
66
|
+
for (const user of users) if (typeof user.username !== "string" || typeof user.password !== "string") throw new Error("basic auth middleware requires \"username\" and \"password\" to be strings");
|
|
65
67
|
return async function basicAuth(ctx, next) {
|
|
66
68
|
const requestUser = require_utils_basic_auth.auth(ctx.req.raw);
|
|
67
69
|
if (requestUser) {
|
|
@@ -81,7 +83,7 @@ const basicAuth = (options, ...users) => {
|
|
|
81
83
|
}
|
|
82
84
|
}
|
|
83
85
|
const status = 401;
|
|
84
|
-
const headers = { "WWW-Authenticate": "Basic realm=\"" + options.realm?.replace(/"/g, "
|
|
86
|
+
const headers = { "WWW-Authenticate": "Basic realm=\"" + options.realm?.replace(/[\\"]/g, "\\$&") + "\"" };
|
|
85
87
|
const responseMessage = typeof options.invalidUserMessage === "function" ? await options.invalidUserMessage(ctx) : options.invalidUserMessage;
|
|
86
88
|
const res = typeof responseMessage === "string" ? new Response(responseMessage, {
|
|
87
89
|
status,
|
|
@@ -45,7 +45,7 @@ const bearerAuth = (options) => {
|
|
|
45
45
|
if (!("token" in options || "verifyToken" in options)) throw new Error("bearer auth middleware requires options for \"token\" or \"verifyToken\"");
|
|
46
46
|
if (!options.realm) options.realm = "";
|
|
47
47
|
if (options.prefix === void 0) options.prefix = PREFIX;
|
|
48
|
-
const realm = options.realm?.replace(/"/g, "
|
|
48
|
+
const realm = options.realm?.replace(/[\\"]/g, "\\$&");
|
|
49
49
|
const prefix = options.prefix;
|
|
50
50
|
const tokenRegexp = new RegExp(`^${TOKEN_STRINGS}$`);
|
|
51
51
|
const wwwAuthenticatePrefix = prefix === "" ? "" : `${prefix} `;
|
|
@@ -53,6 +53,14 @@ const bearerAuth = (options) => {
|
|
|
53
53
|
const wwwAuthenticateHeaderValue = typeof wwwAuthenticateHeader === "function" ? await wwwAuthenticateHeader(c) : wwwAuthenticateHeader;
|
|
54
54
|
const headers = { "WWW-Authenticate": typeof wwwAuthenticateHeaderValue === "string" ? wwwAuthenticateHeaderValue : `${wwwAuthenticatePrefix}${Object.entries(wwwAuthenticateHeaderValue).map(([key, value]) => `${key}="${value}"`).join(",")}` };
|
|
55
55
|
const responseMessage = typeof messageOption === "function" ? await messageOption(c) : messageOption;
|
|
56
|
+
if (responseMessage instanceof Response) {
|
|
57
|
+
const resHeaders = new Headers(responseMessage.headers);
|
|
58
|
+
if (!resHeaders.has("WWW-Authenticate")) resHeaders.set("WWW-Authenticate", headers["WWW-Authenticate"]);
|
|
59
|
+
throw new require_http_exception.HTTPException(responseMessage.status, { res: new Response(responseMessage.body, {
|
|
60
|
+
status: responseMessage.status,
|
|
61
|
+
headers: resHeaders
|
|
62
|
+
}) });
|
|
63
|
+
}
|
|
56
64
|
const res = typeof responseMessage === "string" ? new Response(responseMessage, {
|
|
57
65
|
status,
|
|
58
66
|
headers
|
|
@@ -45,23 +45,22 @@ const bodyLimit = (options) => {
|
|
|
45
45
|
const hasTransferEncoding = c.req.raw.headers.has("transfer-encoding");
|
|
46
46
|
if (c.req.raw.headers.has("content-length") && !hasTransferEncoding) return parseInt(c.req.raw.headers.get("content-length") || "0", 10) > maxSize ? onError(c) : next();
|
|
47
47
|
let size = 0;
|
|
48
|
-
|
|
48
|
+
let buffer = /* @__PURE__ */ new Uint8Array(0);
|
|
49
49
|
const rawReader = c.req.raw.body.getReader();
|
|
50
50
|
for (;;) {
|
|
51
51
|
const { done, value } = await rawReader.read();
|
|
52
52
|
if (done) break;
|
|
53
|
+
const offset = size;
|
|
53
54
|
size += value.length;
|
|
54
55
|
if (size > maxSize) return onError(c);
|
|
55
|
-
|
|
56
|
+
if (size > buffer.length) {
|
|
57
|
+
const grown = new Uint8Array(Math.min(maxSize, Math.max(size, buffer.length * 2)));
|
|
58
|
+
grown.set(buffer.subarray(0, offset));
|
|
59
|
+
buffer = grown;
|
|
60
|
+
}
|
|
61
|
+
buffer.set(value, offset);
|
|
56
62
|
}
|
|
57
|
-
|
|
58
|
-
body: new ReadableStream({ start(controller) {
|
|
59
|
-
for (const chunk of chunks) controller.enqueue(chunk);
|
|
60
|
-
controller.close();
|
|
61
|
-
} }),
|
|
62
|
-
duplex: "half"
|
|
63
|
-
};
|
|
64
|
-
c.req.raw = new Request(c.req.raw, requestInit);
|
|
63
|
+
c.req.raw = new Request(c.req.raw, { body: buffer.subarray(0, size) });
|
|
65
64
|
return next();
|
|
66
65
|
};
|
|
67
66
|
};
|
|
@@ -93,6 +93,10 @@ const every = (...middleware) => {
|
|
|
93
93
|
c.req.routeIndex = currentRouteIndex;
|
|
94
94
|
const res = await m(c, next);
|
|
95
95
|
if (res === false) throw new Error("Unmet condition");
|
|
96
|
+
if (res === true) {
|
|
97
|
+
if (!c.finalized) await next();
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
96
100
|
return res;
|
|
97
101
|
}]]))(c, next);
|
|
98
102
|
};
|
|
@@ -59,14 +59,13 @@ const compress = (options) => {
|
|
|
59
59
|
return async function compress(ctx, next) {
|
|
60
60
|
await next();
|
|
61
61
|
const contentLength = ctx.res.headers.get("Content-Length");
|
|
62
|
-
if (ctx.res.status === 206 || ctx.res.headers.has("Content-Encoding") || ctx.res.headers.has("Transfer-Encoding") ||
|
|
62
|
+
if (ctx.res.status === 206 || ctx.res.headers.has("Content-Encoding") || ctx.res.headers.has("Transfer-Encoding") || contentLength && Number(contentLength) < threshold || !shouldCompress(ctx.res) || !shouldTransform(ctx.res)) return;
|
|
63
63
|
const current = ctx.res.headers.get("Vary");
|
|
64
64
|
if (current !== "*" && !(current && varyAcceptEncodingRegExp.test(current))) ctx.header("Vary", current ? `${current}, Accept-Encoding` : "Accept-Encoding");
|
|
65
65
|
const accepted = ctx.req.header("Accept-Encoding");
|
|
66
66
|
const encoding = selectEncoding(accepted, candidates);
|
|
67
67
|
if (!encoding || !ctx.res.body) return;
|
|
68
|
-
|
|
69
|
-
ctx.res = new Response(ctx.res.body.pipeThrough(stream), ctx.res);
|
|
68
|
+
ctx.res = ctx.req.method === "HEAD" ? new Response(null, ctx.res) : new Response(ctx.res.body.pipeThrough(new CompressionStream(encoding)), ctx.res);
|
|
70
69
|
ctx.res.headers.delete("Content-Length");
|
|
71
70
|
ctx.res.headers.set("Content-Encoding", encoding);
|
|
72
71
|
const etag = ctx.res.headers.get("ETag");
|
|
@@ -9,7 +9,7 @@ const secFetchSiteValues = [
|
|
|
9
9
|
];
|
|
10
10
|
const isSecFetchSite = (value) => secFetchSiteValues.includes(value);
|
|
11
11
|
const isSafeMethodRe = /^(GET|HEAD|OPTIONS)$/;
|
|
12
|
-
const
|
|
12
|
+
const isCsrfContentTypeRe = /^\b(application\/x-www-form-urlencoded|multipart\/form-data|text\/(?:plain|ping))\b/i;
|
|
13
13
|
/**
|
|
14
14
|
* CSRF Protection Middleware for Hono.
|
|
15
15
|
*
|
|
@@ -95,7 +95,7 @@ const csrf = (options) => {
|
|
|
95
95
|
return await secFetchSiteHandler(secFetchSite, c);
|
|
96
96
|
};
|
|
97
97
|
return async function csrf(c, next) {
|
|
98
|
-
if (!isSafeMethodRe.test(c.req.method) &&
|
|
98
|
+
if (!isSafeMethodRe.test(c.req.method) && isCsrfContentTypeRe.test(c.req.header("content-type") || "text/plain") && !await isAllowedSecFetchSite(c.req.header("sec-fetch-site"), c) && !await isAllowedOrigin(c.req.header("origin"), c)) {
|
|
99
99
|
const res = new Response("Forbidden", { status: 403 });
|
|
100
100
|
throw new require_http_exception.HTTPException(403, { res });
|
|
101
101
|
}
|
|
@@ -17,7 +17,8 @@ const RETAINED_304_HEADERS = [
|
|
|
17
17
|
];
|
|
18
18
|
const stripWeak = (tag) => tag.replace(/^W\//, "");
|
|
19
19
|
function etagMatches(etag, ifNoneMatch) {
|
|
20
|
-
|
|
20
|
+
const expected = stripWeak(etag);
|
|
21
|
+
return ifNoneMatch?.match(/"[^"]*"/g)?.some((tag) => tag === expected) ?? false;
|
|
21
22
|
}
|
|
22
23
|
function initializeGenerator(generator) {
|
|
23
24
|
if (!generator) {
|
|
@@ -65,6 +66,7 @@ const etag = (options) => {
|
|
|
65
66
|
etag = weak ? `W/"${hash}"` : `"${hash}"`;
|
|
66
67
|
}
|
|
67
68
|
if (ifNoneMatch === "*" || etagMatches(etag, ifNoneMatch)) {
|
|
69
|
+
await res.body?.cancel();
|
|
68
70
|
c.res = new Response(null, {
|
|
69
71
|
status: 304,
|
|
70
72
|
statusText: "Not Modified",
|
|
@@ -110,8 +110,8 @@ const jwk = (options, init) => {
|
|
|
110
110
|
};
|
|
111
111
|
};
|
|
112
112
|
function unauthorizedResponse(opts) {
|
|
113
|
-
const realm = (opts.realm ?? opts.ctx.req.url).replace(/"/g, "
|
|
114
|
-
const errDescription = opts.errDescription.replace(/"/g, "
|
|
113
|
+
const realm = (opts.realm ?? opts.ctx.req.url).replace(/[\\"]/g, "\\$&");
|
|
114
|
+
const errDescription = opts.errDescription.replace(/[\\"]/g, "\\$&");
|
|
115
115
|
return new Response("Unauthorized", {
|
|
116
116
|
status: 401,
|
|
117
117
|
statusText: opts.statusText,
|
|
@@ -104,8 +104,8 @@ const jwt = (options) => {
|
|
|
104
104
|
};
|
|
105
105
|
};
|
|
106
106
|
function unauthorizedResponse(opts) {
|
|
107
|
-
const realm = (opts.realm ?? opts.ctx.req.url).replace(/"/g, "
|
|
108
|
-
const errDescription = opts.errDescription.replace(/"/g, "
|
|
107
|
+
const realm = (opts.realm ?? opts.ctx.req.url).replace(/[\\"]/g, "\\$&");
|
|
108
|
+
const errDescription = opts.errDescription.replace(/[\\"]/g, "\\$&");
|
|
109
109
|
return new Response("Unauthorized", {
|
|
110
110
|
status: 401,
|
|
111
111
|
statusText: opts.statusText,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_helper_route_index = require("../../helper/route/index.js");
|
|
2
3
|
require("../../router.js");
|
|
3
4
|
const require_router_trie_router_router = require("../../router/trie-router/router.js");
|
|
4
5
|
require("../../router/trie-router/index.js");
|
|
5
|
-
const require_helper_route_index = require("../../helper/route/index.js");
|
|
6
6
|
//#region src/middleware/method-not-allowed/index.ts
|
|
7
7
|
/**
|
|
8
8
|
* Method Not Allowed Middleware for Hono.
|