hono 4.6.1 → 4.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/bun/serve-static.js +3 -3
- package/dist/adapter/deno/serve-static.js +1 -1
- package/dist/cjs/adapter/bun/serve-static.js +3 -3
- package/dist/cjs/adapter/deno/serve-static.js +1 -1
- package/dist/cjs/helper/ssg/middleware.js +1 -1
- package/dist/cjs/helper/streaming/sse.js +1 -1
- package/dist/cjs/jsx/base.js +5 -3
- package/dist/cjs/jsx/dom/hooks/index.js +2 -2
- package/dist/cjs/jsx/dom/index.js +1 -1
- package/dist/cjs/jsx/dom/intrinsic-element/components.js +2 -2
- package/dist/cjs/jsx/dom/render.js +1 -1
- package/dist/cjs/jsx/index.js +46 -46
- package/dist/cjs/jsx/intrinsic-element/components.js +3 -3
- package/dist/cjs/jsx/jsx-runtime.js +28 -1
- package/dist/cjs/jsx/streaming.js +7 -4
- package/dist/cjs/middleware/combine/index.js +3 -2
- package/dist/cjs/middleware/compress/index.js +2 -2
- package/dist/cjs/middleware/secure-headers/secure-headers.js +8 -1
- package/dist/cjs/middleware/serve-static/index.js +25 -12
- package/dist/cjs/router/pattern-router/router.js +1 -1
- package/dist/cjs/utils/compress.js +28 -0
- package/dist/cjs/utils/cookie.js +1 -1
- package/dist/cjs/utils/filepath.js +3 -0
- package/dist/cjs/utils/jwt/jwt.js +1 -1
- package/dist/cjs/utils/stream.js +2 -2
- package/dist/helper/ssg/middleware.js +1 -1
- package/dist/helper/streaming/sse.js +1 -1
- package/dist/jsx/base.js +4 -3
- package/dist/jsx/dom/hooks/index.js +2 -2
- package/dist/jsx/dom/index.js +1 -1
- package/dist/jsx/dom/intrinsic-element/components.js +2 -2
- package/dist/jsx/dom/render.js +1 -1
- package/dist/jsx/index.js +1 -1
- package/dist/jsx/intrinsic-element/components.js +3 -3
- package/dist/jsx/jsx-runtime.js +28 -1
- package/dist/jsx/streaming.js +7 -4
- package/dist/middleware/combine/index.js +3 -2
- package/dist/middleware/compress/index.js +2 -2
- package/dist/middleware/secure-headers/secure-headers.js +8 -1
- package/dist/middleware/serve-static/index.js +25 -12
- package/dist/router/pattern-router/router.js +1 -1
- package/dist/types/context.d.ts +1 -1
- package/dist/types/jsx/base.d.ts +1 -0
- package/dist/types/jsx/dom/index.d.ts +2 -2
- package/dist/types/jsx/dom/intrinsic-element/components.d.ts +1 -1
- package/dist/types/jsx/dom/server.d.ts +1 -1
- package/dist/types/jsx/hooks/index.d.ts +1 -1
- package/dist/types/jsx/index.d.ts +2 -2
- package/dist/types/jsx/intrinsic-element/components.d.ts +1 -1
- package/dist/types/jsx/jsx-runtime.d.ts +1 -1
- package/dist/types/jsx/streaming.d.ts +2 -1
- package/dist/types/middleware/jwt/jwt.d.ts +2 -2
- package/dist/types/middleware/secure-headers/secure-headers.d.ts +2 -0
- package/dist/types/types.d.ts +23 -23
- package/dist/types/utils/compress.d.ts +8 -0
- package/dist/types/utils/types.d.ts +3 -1
- package/dist/utils/compress.js +5 -0
- package/dist/utils/cookie.js +1 -1
- package/dist/utils/filepath.js +3 -0
- package/dist/utils/jwt/jwt.js +1 -1
- package/dist/utils/stream.js +2 -2
- package/package.json +15 -15
- package/perf-measures/type-check/generated/.gitkeep +0 -0
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// src/adapter/bun/serve-static.ts
|
|
2
|
-
import { serveStatic as baseServeStatic } from "../../middleware/serve-static/index.js";
|
|
3
2
|
import { stat } from "node:fs/promises";
|
|
3
|
+
import { serveStatic as baseServeStatic } from "../../middleware/serve-static/index.js";
|
|
4
4
|
var serveStatic = (options) => {
|
|
5
5
|
return async function serveStatic2(c, next) {
|
|
6
6
|
const getContent = async (path) => {
|
|
7
|
-
path = `./${path}`;
|
|
7
|
+
path = path.startsWith("/") ? path : `./${path}`;
|
|
8
8
|
const file = Bun.file(path);
|
|
9
9
|
return await file.exists() ? file : null;
|
|
10
10
|
};
|
|
11
11
|
const pathResolve = (path) => {
|
|
12
|
-
return `./${path}`;
|
|
12
|
+
return path.startsWith("/") ? path : `./${path}`;
|
|
13
13
|
};
|
|
14
14
|
const isDir = async (path) => {
|
|
15
15
|
let isDir2;
|
|
@@ -21,17 +21,17 @@ __export(serve_static_exports, {
|
|
|
21
21
|
serveStatic: () => serveStatic
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(serve_static_exports);
|
|
24
|
-
var import_serve_static = require("../../middleware/serve-static");
|
|
25
24
|
var import_promises = require("node:fs/promises");
|
|
25
|
+
var import_serve_static = require("../../middleware/serve-static");
|
|
26
26
|
const serveStatic = (options) => {
|
|
27
27
|
return async function serveStatic2(c, next) {
|
|
28
28
|
const getContent = async (path) => {
|
|
29
|
-
path = `./${path}`;
|
|
29
|
+
path = path.startsWith("/") ? path : `./${path}`;
|
|
30
30
|
const file = Bun.file(path);
|
|
31
31
|
return await file.exists() ? file : null;
|
|
32
32
|
};
|
|
33
33
|
const pathResolve = (path) => {
|
|
34
|
-
return `./${path}`;
|
|
34
|
+
return path.startsWith("/") ? path : `./${path}`;
|
|
35
35
|
};
|
|
36
36
|
const isDir = async (path) => {
|
|
37
37
|
let isDir2;
|
|
@@ -22,8 +22,8 @@ __export(sse_exports, {
|
|
|
22
22
|
streamSSE: () => streamSSE
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(sse_exports);
|
|
25
|
-
var import_stream = require("../../utils/stream");
|
|
26
25
|
var import_html = require("../../utils/html");
|
|
26
|
+
var import_stream = require("../../utils/stream");
|
|
27
27
|
class SSEStreamingApi extends import_stream.StreamingApi {
|
|
28
28
|
constructor(writable, readable) {
|
|
29
29
|
super(writable, readable);
|
package/dist/cjs/jsx/base.js
CHANGED
|
@@ -27,6 +27,7 @@ __export(base_exports, {
|
|
|
27
27
|
Fragment: () => Fragment,
|
|
28
28
|
JSXFragmentNode: () => JSXFragmentNode,
|
|
29
29
|
JSXNode: () => JSXNode,
|
|
30
|
+
booleanAttributes: () => booleanAttributes,
|
|
30
31
|
cloneElement: () => cloneElement,
|
|
31
32
|
getNameSpaceContext: () => getNameSpaceContext,
|
|
32
33
|
isValidElement: () => isValidElement,
|
|
@@ -38,11 +39,11 @@ __export(base_exports, {
|
|
|
38
39
|
module.exports = __toCommonJS(base_exports);
|
|
39
40
|
var import_html = require("../helper/html");
|
|
40
41
|
var import_html2 = require("../utils/html");
|
|
41
|
-
var import_context = require("./context");
|
|
42
42
|
var import_constants = require("./constants");
|
|
43
|
-
var
|
|
44
|
-
var intrinsicElementTags = __toESM(require("./intrinsic-element/components"), 1);
|
|
43
|
+
var import_context = require("./context");
|
|
45
44
|
var import_common = require("./intrinsic-element/common");
|
|
45
|
+
var intrinsicElementTags = __toESM(require("./intrinsic-element/components"), 1);
|
|
46
|
+
var import_utils = require("./utils");
|
|
46
47
|
let nameSpaceContext = void 0;
|
|
47
48
|
const getNameSpaceContext = () => nameSpaceContext;
|
|
48
49
|
const toSVGAttributeName = (key) => /[A-Z]/.test(key) && key.match(
|
|
@@ -342,6 +343,7 @@ const reactAPICompatVersion = "19.0.0-hono-jsx";
|
|
|
342
343
|
Fragment,
|
|
343
344
|
JSXFragmentNode,
|
|
344
345
|
JSXNode,
|
|
346
|
+
booleanAttributes,
|
|
345
347
|
cloneElement,
|
|
346
348
|
getNameSpaceContext,
|
|
347
349
|
isValidElement,
|
|
@@ -25,10 +25,10 @@ __export(hooks_exports, {
|
|
|
25
25
|
useOptimistic: () => useOptimistic
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(hooks_exports);
|
|
28
|
+
var import_constants = require("../../constants");
|
|
28
29
|
var import_context = require("../../context");
|
|
29
|
-
var import_context2 = require("../context");
|
|
30
30
|
var import_hooks = require("../../hooks");
|
|
31
|
-
var
|
|
31
|
+
var import_context2 = require("../context");
|
|
32
32
|
const FormContext = (0, import_context2.createContext)({
|
|
33
33
|
pending: false,
|
|
34
34
|
data: null,
|
|
@@ -64,9 +64,9 @@ var import_base = require("../base");
|
|
|
64
64
|
var import_children = require("../children");
|
|
65
65
|
var import_context = require("../context");
|
|
66
66
|
var import_hooks = require("../hooks");
|
|
67
|
-
var import_hooks2 = require("./hooks");
|
|
68
67
|
var import_components = require("./components");
|
|
69
68
|
var import_context2 = require("./context");
|
|
69
|
+
var import_hooks2 = require("./hooks");
|
|
70
70
|
var import_jsx_runtime = require("./jsx-runtime");
|
|
71
71
|
var import_render = require("./render");
|
|
72
72
|
var import_render2 = require("./render");
|
|
@@ -30,11 +30,11 @@ __export(components_exports, {
|
|
|
30
30
|
title: () => title
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(components_exports);
|
|
33
|
-
var import_render = require("../render");
|
|
34
33
|
var import_context = require("../../context");
|
|
35
34
|
var import_hooks = require("../../hooks");
|
|
36
|
-
var import_hooks2 = require("../hooks");
|
|
37
35
|
var import_common = require("../../intrinsic-element/common");
|
|
36
|
+
var import_hooks2 = require("../hooks");
|
|
37
|
+
var import_render = require("../render");
|
|
38
38
|
const clearCache = () => {
|
|
39
39
|
blockingPromiseMap = /* @__PURE__ */ Object.create(null);
|
|
40
40
|
createdElements = /* @__PURE__ */ Object.create(null);
|
package/dist/cjs/jsx/index.js
CHANGED
|
@@ -26,33 +26,33 @@ __export(jsx_exports, {
|
|
|
26
26
|
cloneElement: () => import_base.cloneElement,
|
|
27
27
|
createContext: () => import_context.createContext,
|
|
28
28
|
createElement: () => import_base.jsx,
|
|
29
|
-
createRef: () =>
|
|
29
|
+
createRef: () => import_hooks2.createRef,
|
|
30
30
|
default: () => jsx_default,
|
|
31
|
-
forwardRef: () =>
|
|
31
|
+
forwardRef: () => import_hooks2.forwardRef,
|
|
32
32
|
isValidElement: () => import_base.isValidElement,
|
|
33
33
|
jsx: () => import_base.jsx,
|
|
34
34
|
memo: () => import_base.memo,
|
|
35
|
-
startTransition: () =>
|
|
36
|
-
startViewTransition: () =>
|
|
37
|
-
use: () =>
|
|
38
|
-
useActionState: () =>
|
|
39
|
-
useCallback: () =>
|
|
35
|
+
startTransition: () => import_hooks2.startTransition,
|
|
36
|
+
startViewTransition: () => import_hooks2.startViewTransition,
|
|
37
|
+
use: () => import_hooks2.use,
|
|
38
|
+
useActionState: () => import_hooks.useActionState,
|
|
39
|
+
useCallback: () => import_hooks2.useCallback,
|
|
40
40
|
useContext: () => import_context.useContext,
|
|
41
|
-
useDebugValue: () =>
|
|
42
|
-
useDeferredValue: () =>
|
|
43
|
-
useEffect: () =>
|
|
44
|
-
useId: () =>
|
|
45
|
-
useImperativeHandle: () =>
|
|
46
|
-
useInsertionEffect: () =>
|
|
47
|
-
useLayoutEffect: () =>
|
|
48
|
-
useMemo: () =>
|
|
49
|
-
useOptimistic: () =>
|
|
50
|
-
useReducer: () =>
|
|
51
|
-
useRef: () =>
|
|
52
|
-
useState: () =>
|
|
53
|
-
useSyncExternalStore: () =>
|
|
54
|
-
useTransition: () =>
|
|
55
|
-
useViewTransition: () =>
|
|
41
|
+
useDebugValue: () => import_hooks2.useDebugValue,
|
|
42
|
+
useDeferredValue: () => import_hooks2.useDeferredValue,
|
|
43
|
+
useEffect: () => import_hooks2.useEffect,
|
|
44
|
+
useId: () => import_hooks2.useId,
|
|
45
|
+
useImperativeHandle: () => import_hooks2.useImperativeHandle,
|
|
46
|
+
useInsertionEffect: () => import_hooks2.useInsertionEffect,
|
|
47
|
+
useLayoutEffect: () => import_hooks2.useLayoutEffect,
|
|
48
|
+
useMemo: () => import_hooks2.useMemo,
|
|
49
|
+
useOptimistic: () => import_hooks.useOptimistic,
|
|
50
|
+
useReducer: () => import_hooks2.useReducer,
|
|
51
|
+
useRef: () => import_hooks2.useRef,
|
|
52
|
+
useState: () => import_hooks2.useState,
|
|
53
|
+
useSyncExternalStore: () => import_hooks2.useSyncExternalStore,
|
|
54
|
+
useTransition: () => import_hooks2.useTransition,
|
|
55
|
+
useViewTransition: () => import_hooks2.useViewTransition,
|
|
56
56
|
version: () => import_base.reactAPICompatVersion
|
|
57
57
|
});
|
|
58
58
|
module.exports = __toCommonJS(jsx_exports);
|
|
@@ -60,8 +60,8 @@ var import_base = require("./base");
|
|
|
60
60
|
var import_children = require("./children");
|
|
61
61
|
var import_components = require("./components");
|
|
62
62
|
var import_context = require("./context");
|
|
63
|
-
var import_hooks = require("./hooks");
|
|
64
|
-
var import_hooks2 = require("./
|
|
63
|
+
var import_hooks = require("./dom/hooks");
|
|
64
|
+
var import_hooks2 = require("./hooks");
|
|
65
65
|
var import_streaming = require("./streaming");
|
|
66
66
|
var jsx_default = {
|
|
67
67
|
version: import_base.reactAPICompatVersion,
|
|
@@ -74,28 +74,28 @@ var jsx_default = {
|
|
|
74
74
|
ErrorBoundary: import_components.ErrorBoundary,
|
|
75
75
|
createContext: import_context.createContext,
|
|
76
76
|
useContext: import_context.useContext,
|
|
77
|
-
useState:
|
|
78
|
-
useEffect:
|
|
79
|
-
useRef:
|
|
80
|
-
useCallback:
|
|
81
|
-
useReducer:
|
|
82
|
-
useId:
|
|
83
|
-
useDebugValue:
|
|
84
|
-
use:
|
|
85
|
-
startTransition:
|
|
86
|
-
useTransition:
|
|
87
|
-
useDeferredValue:
|
|
88
|
-
startViewTransition:
|
|
89
|
-
useViewTransition:
|
|
90
|
-
useMemo:
|
|
91
|
-
useLayoutEffect:
|
|
92
|
-
useInsertionEffect:
|
|
93
|
-
createRef:
|
|
94
|
-
forwardRef:
|
|
95
|
-
useImperativeHandle:
|
|
96
|
-
useSyncExternalStore:
|
|
97
|
-
useActionState:
|
|
98
|
-
useOptimistic:
|
|
77
|
+
useState: import_hooks2.useState,
|
|
78
|
+
useEffect: import_hooks2.useEffect,
|
|
79
|
+
useRef: import_hooks2.useRef,
|
|
80
|
+
useCallback: import_hooks2.useCallback,
|
|
81
|
+
useReducer: import_hooks2.useReducer,
|
|
82
|
+
useId: import_hooks2.useId,
|
|
83
|
+
useDebugValue: import_hooks2.useDebugValue,
|
|
84
|
+
use: import_hooks2.use,
|
|
85
|
+
startTransition: import_hooks2.startTransition,
|
|
86
|
+
useTransition: import_hooks2.useTransition,
|
|
87
|
+
useDeferredValue: import_hooks2.useDeferredValue,
|
|
88
|
+
startViewTransition: import_hooks2.startViewTransition,
|
|
89
|
+
useViewTransition: import_hooks2.useViewTransition,
|
|
90
|
+
useMemo: import_hooks2.useMemo,
|
|
91
|
+
useLayoutEffect: import_hooks2.useLayoutEffect,
|
|
92
|
+
useInsertionEffect: import_hooks2.useInsertionEffect,
|
|
93
|
+
createRef: import_hooks2.createRef,
|
|
94
|
+
forwardRef: import_hooks2.forwardRef,
|
|
95
|
+
useImperativeHandle: import_hooks2.useImperativeHandle,
|
|
96
|
+
useSyncExternalStore: import_hooks2.useSyncExternalStore,
|
|
97
|
+
useActionState: import_hooks.useActionState,
|
|
98
|
+
useOptimistic: import_hooks.useOptimistic,
|
|
99
99
|
Suspense: import_streaming.Suspense,
|
|
100
100
|
Children: import_children.Children
|
|
101
101
|
};
|
|
@@ -28,12 +28,12 @@ __export(components_exports, {
|
|
|
28
28
|
title: () => title
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(components_exports);
|
|
31
|
+
var import_html = require("../../helper/html");
|
|
31
32
|
var import_base = require("../base");
|
|
33
|
+
var import_children = require("../children");
|
|
34
|
+
var import_constants = require("../constants");
|
|
32
35
|
var import_context = require("../context");
|
|
33
|
-
var import_html = require("../../helper/html");
|
|
34
36
|
var import_common = require("./common");
|
|
35
|
-
var import_constants = require("../constants");
|
|
36
|
-
var import_children = require("../children");
|
|
37
37
|
const metaTagMap = /* @__PURE__ */ new WeakMap();
|
|
38
38
|
const insertIntoHead = (tagName, tag, props, precedence) => ({ buffer, context }) => {
|
|
39
39
|
if (!buffer) {
|
|
@@ -29,7 +29,34 @@ module.exports = __toCommonJS(jsx_runtime_exports);
|
|
|
29
29
|
var import_jsx_dev_runtime = require("./jsx-dev-runtime");
|
|
30
30
|
var import_jsx_dev_runtime2 = require("./jsx-dev-runtime");
|
|
31
31
|
var import_html = require("../helper/html");
|
|
32
|
-
|
|
32
|
+
var import_html2 = require("../utils/html");
|
|
33
|
+
var import_utils = require("./utils");
|
|
34
|
+
const jsxAttr = (key, v) => {
|
|
35
|
+
const buffer = [`${key}="`];
|
|
36
|
+
if (key === "style" && typeof v === "object") {
|
|
37
|
+
let styleStr = "";
|
|
38
|
+
(0, import_utils.styleObjectForEach)(v, (property, value) => {
|
|
39
|
+
if (value != null) {
|
|
40
|
+
styleStr += `${styleStr ? ";" : ""}${property}:${value}`;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
(0, import_html2.escapeToBuffer)(styleStr, buffer);
|
|
44
|
+
buffer[0] += '"';
|
|
45
|
+
} else if (typeof v === "string") {
|
|
46
|
+
(0, import_html2.escapeToBuffer)(v, buffer);
|
|
47
|
+
buffer[0] += '"';
|
|
48
|
+
} else if (v === null || v === void 0) {
|
|
49
|
+
return (0, import_html.raw)("");
|
|
50
|
+
} else if (typeof v === "number" || v.isEscaped) {
|
|
51
|
+
buffer[0] += `${v}"`;
|
|
52
|
+
} else if (v instanceof Promise) {
|
|
53
|
+
buffer.unshift('"', v);
|
|
54
|
+
} else {
|
|
55
|
+
(0, import_html2.escapeToBuffer)(v.toString(), buffer);
|
|
56
|
+
buffer[0] += '"';
|
|
57
|
+
}
|
|
58
|
+
return buffer.length === 1 ? (0, import_html.raw)(buffer[0]) : (0, import_html2.stringBufferToString)(buffer, void 0);
|
|
59
|
+
};
|
|
33
60
|
const jsxEscape = (value) => value;
|
|
34
61
|
// Annotate the CommonJS export names for ESM import in node:
|
|
35
62
|
0 && (module.exports = {
|
|
@@ -24,6 +24,7 @@ __export(streaming_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(streaming_exports);
|
|
25
25
|
var import_html = require("../helper/html");
|
|
26
26
|
var import_html2 = require("../utils/html");
|
|
27
|
+
var import_base = require("./base");
|
|
27
28
|
var import_components = require("./components");
|
|
28
29
|
var import_constants = require("./constants");
|
|
29
30
|
var import_components2 = require("./dom/components");
|
|
@@ -110,14 +111,16 @@ d.replaceWith(c.content)
|
|
|
110
111
|
};
|
|
111
112
|
Suspense[import_constants.DOM_RENDERER] = import_components2.Suspense;
|
|
112
113
|
const textEncoder = new TextEncoder();
|
|
113
|
-
const renderToReadableStream = (
|
|
114
|
+
const renderToReadableStream = (content, onError = console.trace) => {
|
|
114
115
|
const reader = new ReadableStream({
|
|
115
116
|
async start(controller) {
|
|
116
117
|
try {
|
|
117
|
-
|
|
118
|
-
|
|
118
|
+
if (content instanceof import_base.JSXNode) {
|
|
119
|
+
content = content.toString();
|
|
120
|
+
}
|
|
121
|
+
const context = typeof content === "object" ? content : {};
|
|
119
122
|
const resolved = await (0, import_html2.resolveCallback)(
|
|
120
|
-
|
|
123
|
+
content,
|
|
121
124
|
import_html2.HtmlEscapedCallbackPhase.BeforeStream,
|
|
122
125
|
true,
|
|
123
126
|
context
|
|
@@ -23,9 +23,9 @@ __export(combine_exports, {
|
|
|
23
23
|
some: () => some
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(combine_exports);
|
|
26
|
-
var import_trie_router = require("../../router/trie-router");
|
|
27
|
-
var import_router = require("../../router");
|
|
28
26
|
var import_compose = require("../../compose");
|
|
27
|
+
var import_router = require("../../router");
|
|
28
|
+
var import_trie_router = require("../../router/trie-router");
|
|
29
29
|
const some = (...middleware) => {
|
|
30
30
|
return async function some2(c, next) {
|
|
31
31
|
let lastError;
|
|
@@ -56,6 +56,7 @@ const every = (...middleware) => {
|
|
|
56
56
|
if (res === false) {
|
|
57
57
|
throw new Error("Unmet condition");
|
|
58
58
|
}
|
|
59
|
+
return res;
|
|
59
60
|
});
|
|
60
61
|
const handler = async (c, next) => (0, import_compose.compose)(wrappedMiddleware.map((m) => [[m, void 0], c.req.param()]))(c, next);
|
|
61
62
|
return async function every2(c, next) {
|
|
@@ -21,9 +21,9 @@ __export(compress_exports, {
|
|
|
21
21
|
compress: () => compress
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(compress_exports);
|
|
24
|
+
var import_compress = require("../../utils/compress");
|
|
24
25
|
const ENCODING_TYPES = ["gzip", "deflate"];
|
|
25
26
|
const cacheControlNoTransformRegExp = /(?:^|,)\s*?no-transform\s*?(?:,|$)/i;
|
|
26
|
-
const compressibleContentTypeRegExp = /^\s*(?:text\/[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|wasm|x-httpd-php|x-javascript|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml))(?:[;\s]|$)/i;
|
|
27
27
|
const compress = (options) => {
|
|
28
28
|
const threshold = options?.threshold ?? 1024;
|
|
29
29
|
return async function compress2(ctx, next) {
|
|
@@ -45,7 +45,7 @@ const compress = (options) => {
|
|
|
45
45
|
};
|
|
46
46
|
const shouldCompress = (res) => {
|
|
47
47
|
const type = res.headers.get("Content-Type");
|
|
48
|
-
return type &&
|
|
48
|
+
return type && import_compress.COMPRESSIBLE_CONTENT_TYPE_REGEX.test(type);
|
|
49
49
|
};
|
|
50
50
|
const shouldTransform = (res) => {
|
|
51
51
|
const cacheControl = res.headers.get("Cache-Control");
|
|
@@ -77,6 +77,13 @@ const secureHeaders = (customOptions) => {
|
|
|
77
77
|
}
|
|
78
78
|
headersToSet.push(["Content-Security-Policy", value]);
|
|
79
79
|
}
|
|
80
|
+
if (options.contentSecurityPolicyReportOnly) {
|
|
81
|
+
const [callback, value] = getCSPDirectives(options.contentSecurityPolicyReportOnly);
|
|
82
|
+
if (callback) {
|
|
83
|
+
callbacks.push(callback);
|
|
84
|
+
}
|
|
85
|
+
headersToSet.push(["Content-Security-Policy-Report-Only", value]);
|
|
86
|
+
}
|
|
80
87
|
if (options.permissionsPolicy && Object.keys(options.permissionsPolicy).length > 0) {
|
|
81
88
|
headersToSet.push([
|
|
82
89
|
"Permissions-Policy",
|
|
@@ -129,7 +136,7 @@ function getCSPDirectives(contentSecurityPolicy) {
|
|
|
129
136
|
resultValues.pop();
|
|
130
137
|
return callbacks.length === 0 ? [void 0, resultValues.join("")] : [
|
|
131
138
|
(ctx, headersToSet) => headersToSet.map((values) => {
|
|
132
|
-
if (values[0] === "Content-Security-Policy") {
|
|
139
|
+
if (values[0] === "Content-Security-Policy" || values[0] === "Content-Security-Policy-Report-Only") {
|
|
133
140
|
const clone = values[1].slice();
|
|
134
141
|
callbacks.forEach((cb) => {
|
|
135
142
|
cb(ctx, clone);
|
|
@@ -21,6 +21,7 @@ __export(serve_static_exports, {
|
|
|
21
21
|
serveStatic: () => serveStatic
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(serve_static_exports);
|
|
24
|
+
var import_compress = require("../../utils/compress");
|
|
24
25
|
var import_filepath = require("../../utils/filepath");
|
|
25
26
|
var import_mime = require("../../utils/mime");
|
|
26
27
|
const ENCODINGS = {
|
|
@@ -28,9 +29,20 @@ const ENCODINGS = {
|
|
|
28
29
|
zstd: ".zst",
|
|
29
30
|
gzip: ".gz"
|
|
30
31
|
};
|
|
32
|
+
const ENCODINGS_ORDERED_KEYS = Object.keys(ENCODINGS);
|
|
31
33
|
const DEFAULT_DOCUMENT = "index.html";
|
|
32
34
|
const defaultPathResolve = (path) => path;
|
|
33
35
|
const serveStatic = (options) => {
|
|
36
|
+
let isAbsoluteRoot = false;
|
|
37
|
+
let root;
|
|
38
|
+
if (options.root) {
|
|
39
|
+
if (options.root.startsWith("/")) {
|
|
40
|
+
isAbsoluteRoot = true;
|
|
41
|
+
root = new URL(`file://${options.root}`).pathname;
|
|
42
|
+
} else {
|
|
43
|
+
root = options.root;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
34
46
|
return async (c, next) => {
|
|
35
47
|
if (c.finalized) {
|
|
36
48
|
await next();
|
|
@@ -38,7 +50,6 @@ const serveStatic = (options) => {
|
|
|
38
50
|
}
|
|
39
51
|
let filename = options.path ?? decodeURI(c.req.path);
|
|
40
52
|
filename = options.rewriteRequestPath ? options.rewriteRequestPath(filename) : filename;
|
|
41
|
-
const root = options.root;
|
|
42
53
|
if (!filename.endsWith("/") && options.isDir) {
|
|
43
54
|
const path2 = (0, import_filepath.getFilePathWithoutDefaultDocument)({
|
|
44
55
|
filename,
|
|
@@ -56,6 +67,9 @@ const serveStatic = (options) => {
|
|
|
56
67
|
if (!path) {
|
|
57
68
|
return await next();
|
|
58
69
|
}
|
|
70
|
+
if (isAbsoluteRoot) {
|
|
71
|
+
path = "/" + path;
|
|
72
|
+
}
|
|
59
73
|
const getContent = options.getContent;
|
|
60
74
|
const pathResolve = options.pathResolve ?? defaultPathResolve;
|
|
61
75
|
path = pathResolve(path);
|
|
@@ -79,18 +93,17 @@ const serveStatic = (options) => {
|
|
|
79
93
|
if (content instanceof Response) {
|
|
80
94
|
return c.newResponse(content.body, content);
|
|
81
95
|
}
|
|
82
|
-
const mimeType = options.mimes ? (0, import_mime.getMimeType)(path, options.mimes) ?? (0, import_mime.getMimeType)(path) : (0, import_mime.getMimeType)(path);
|
|
83
|
-
if (mimeType) {
|
|
84
|
-
c.header("Content-Type", mimeType);
|
|
85
|
-
}
|
|
86
96
|
if (content) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
(
|
|
92
|
-
)
|
|
93
|
-
for (const encoding of
|
|
97
|
+
const mimeType = options.mimes && (0, import_mime.getMimeType)(path, options.mimes) || (0, import_mime.getMimeType)(path);
|
|
98
|
+
c.header("Content-Type", mimeType || "application/octet-stream");
|
|
99
|
+
if (options.precompressed && (!mimeType || import_compress.COMPRESSIBLE_CONTENT_TYPE_REGEX.test(mimeType))) {
|
|
100
|
+
const acceptEncodingSet = new Set(
|
|
101
|
+
c.req.header("Accept-Encoding")?.split(",").map((encoding) => encoding.trim())
|
|
102
|
+
);
|
|
103
|
+
for (const encoding of ENCODINGS_ORDERED_KEYS) {
|
|
104
|
+
if (!acceptEncodingSet.has(encoding)) {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
94
107
|
const compressedContent = await getContent(path + ENCODINGS[encoding], c);
|
|
95
108
|
if (compressedContent) {
|
|
96
109
|
content = compressedContent;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var compress_exports = {};
|
|
20
|
+
__export(compress_exports, {
|
|
21
|
+
COMPRESSIBLE_CONTENT_TYPE_REGEX: () => COMPRESSIBLE_CONTENT_TYPE_REGEX
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(compress_exports);
|
|
24
|
+
const COMPRESSIBLE_CONTENT_TYPE_REGEX = /^\s*(?:text\/[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|wasm|x-httpd-php|x-javascript|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml))(?:[;\s]|$)/i;
|
|
25
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
26
|
+
0 && (module.exports = {
|
|
27
|
+
COMPRESSIBLE_CONTENT_TYPE_REGEX
|
|
28
|
+
});
|
package/dist/cjs/utils/cookie.js
CHANGED
|
@@ -43,7 +43,7 @@ const verifySignature = async (base64Signature, value, secret) => {
|
|
|
43
43
|
signature[i] = signatureBinStr.charCodeAt(i);
|
|
44
44
|
}
|
|
45
45
|
return await crypto.subtle.verify(algorithm, secret, signature, new TextEncoder().encode(value));
|
|
46
|
-
} catch
|
|
46
|
+
} catch {
|
|
47
47
|
return false;
|
|
48
48
|
}
|
|
49
49
|
};
|
|
@@ -47,6 +47,9 @@ const getFilePathWithoutDefaultDocument = (options) => {
|
|
|
47
47
|
root = root.replace(/\/$/, "");
|
|
48
48
|
let path = root ? root + "/" + filename : filename;
|
|
49
49
|
path = path.replace(/^\.?\//, "");
|
|
50
|
+
if (root[0] !== "/" && path[0] === "/") {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
50
53
|
return path;
|
|
51
54
|
};
|
|
52
55
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/cjs/utils/stream.js
CHANGED
|
@@ -53,7 +53,7 @@ class StreamingApi {
|
|
|
53
53
|
input = this.encoder.encode(input);
|
|
54
54
|
}
|
|
55
55
|
await this.writer.write(input);
|
|
56
|
-
} catch
|
|
56
|
+
} catch {
|
|
57
57
|
}
|
|
58
58
|
return this;
|
|
59
59
|
}
|
|
@@ -67,7 +67,7 @@ class StreamingApi {
|
|
|
67
67
|
async close() {
|
|
68
68
|
try {
|
|
69
69
|
await this.writer.close();
|
|
70
|
-
} catch
|
|
70
|
+
} catch {
|
|
71
71
|
}
|
|
72
72
|
this.closed = true;
|
|
73
73
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/helper/streaming/sse.ts
|
|
2
|
-
import { StreamingApi } from "../../utils/stream.js";
|
|
3
2
|
import { HtmlEscapedCallbackPhase, resolveCallback } from "../../utils/html.js";
|
|
3
|
+
import { StreamingApi } from "../../utils/stream.js";
|
|
4
4
|
var SSEStreamingApi = class extends StreamingApi {
|
|
5
5
|
constructor(writable, readable) {
|
|
6
6
|
super(writable, readable);
|
package/dist/jsx/base.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// src/jsx/base.ts
|
|
2
2
|
import { raw } from "../helper/html/index.js";
|
|
3
3
|
import { escapeToBuffer, resolveCallbackSync, stringBufferToString } from "../utils/html.js";
|
|
4
|
-
import { createContext, globalContexts, useContext } from "./context.js";
|
|
5
4
|
import { DOM_RENDERER } from "./constants.js";
|
|
6
|
-
import {
|
|
7
|
-
import * as intrinsicElementTags from "./intrinsic-element/components.js";
|
|
5
|
+
import { createContext, globalContexts, useContext } from "./context.js";
|
|
8
6
|
import { domRenderers } from "./intrinsic-element/common.js";
|
|
7
|
+
import * as intrinsicElementTags from "./intrinsic-element/components.js";
|
|
8
|
+
import { normalizeIntrinsicElementKey, styleObjectForEach } from "./utils.js";
|
|
9
9
|
var nameSpaceContext = void 0;
|
|
10
10
|
var getNameSpaceContext = () => nameSpaceContext;
|
|
11
11
|
var toSVGAttributeName = (key) => /[A-Z]/.test(key) && key.match(
|
|
@@ -304,6 +304,7 @@ export {
|
|
|
304
304
|
Fragment,
|
|
305
305
|
JSXFragmentNode,
|
|
306
306
|
JSXNode,
|
|
307
|
+
booleanAttributes,
|
|
307
308
|
cloneElement,
|
|
308
309
|
getNameSpaceContext,
|
|
309
310
|
isValidElement,
|