hono 4.2.2 → 4.2.4
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/cloudflare-workers/utils.js +1 -1
- package/dist/cjs/adapter/cloudflare-workers/utils.js +1 -1
- package/dist/cjs/client/client.js +5 -3
- package/dist/cjs/client/utils.js +12 -2
- package/dist/cjs/helper/ssg/index.js +2 -2
- package/dist/cjs/helper/ssg/middleware.js +15 -2
- package/dist/cjs/helper/ssg/ssg.js +2 -2
- package/dist/cjs/helper/testing/index.js +1 -1
- package/dist/cjs/jsx/streaming.js +37 -27
- package/dist/cjs/middleware/serve-static/index.js +1 -1
- package/dist/cjs/router/trie-router/node.js +0 -4
- package/dist/cjs/utils/jwt/jwt.js +1 -1
- package/dist/client/client.js +12 -4
- package/dist/client/utils.js +10 -1
- package/dist/helper/ssg/index.js +8 -2
- package/dist/helper/ssg/middleware.js +14 -2
- package/dist/helper/ssg/ssg.js +3 -3
- package/dist/helper/testing/index.js +1 -1
- package/dist/jsx/streaming.js +37 -27
- package/dist/middleware/serve-static/index.js +1 -1
- package/dist/router/trie-router/node.js +0 -4
- package/dist/types/client/utils.d.ts +1 -0
- package/dist/types/helper/ssg/index.d.ts +1 -1
- package/dist/types/helper/ssg/middleware.d.ts +6 -0
- package/dist/types/jsx/streaming.d.ts +1 -1
- package/dist/types/utils/jwt/jwt.d.ts +1 -1
- package/dist/types/validator/validator.d.ts +2 -2
- package/dist/utils/jwt/jwt.js +1 -1
- package/package.json +4 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/adapter/cloudflare-workers/utils.ts
|
|
2
2
|
var getContentFromKVAsset = async (path, options) => {
|
|
3
|
-
let ASSET_MANIFEST
|
|
3
|
+
let ASSET_MANIFEST;
|
|
4
4
|
if (options && options.manifest) {
|
|
5
5
|
if (typeof options.manifest === "string") {
|
|
6
6
|
ASSET_MANIFEST = JSON.parse(options.manifest);
|
|
@@ -22,7 +22,7 @@ __export(utils_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(utils_exports);
|
|
24
24
|
const getContentFromKVAsset = async (path, options) => {
|
|
25
|
-
let ASSET_MANIFEST
|
|
25
|
+
let ASSET_MANIFEST;
|
|
26
26
|
if (options && options.manifest) {
|
|
27
27
|
if (typeof options.manifest === "string") {
|
|
28
28
|
ASSET_MANIFEST = JSON.parse(options.manifest);
|
|
@@ -85,7 +85,6 @@ class ClientRequestImpl {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
let methodUpperCase = this.method.toUpperCase();
|
|
88
|
-
let setBody = !(methodUpperCase === "GET" || methodUpperCase === "HEAD");
|
|
89
88
|
const headerValues = {
|
|
90
89
|
...args?.header ?? {},
|
|
91
90
|
...typeof opt?.headers === "function" ? await opt.headers() : opt?.headers ? opt.headers : {}
|
|
@@ -108,7 +107,7 @@ class ClientRequestImpl {
|
|
|
108
107
|
url = url + "?" + this.queryParams.toString();
|
|
109
108
|
}
|
|
110
109
|
methodUpperCase = this.method.toUpperCase();
|
|
111
|
-
setBody = !(methodUpperCase === "GET" || methodUpperCase === "HEAD");
|
|
110
|
+
const setBody = !(methodUpperCase === "GET" || methodUpperCase === "HEAD");
|
|
112
111
|
return (opt?.fetch || fetch)(url, {
|
|
113
112
|
body: setBody ? this.rBody : void 0,
|
|
114
113
|
method: methodUpperCase,
|
|
@@ -134,7 +133,10 @@ const hc = (baseUrl, options) => createProxy((opts) => {
|
|
|
134
133
|
return new URL(url);
|
|
135
134
|
}
|
|
136
135
|
if (method === "ws") {
|
|
137
|
-
const targetUrl =
|
|
136
|
+
const targetUrl = (0, import_utils.replaceUrlProtocol)(
|
|
137
|
+
opts.args[0] && opts.args[0].param ? (0, import_utils.replaceUrlParam)(url, opts.args[0].param) : url,
|
|
138
|
+
"ws"
|
|
139
|
+
);
|
|
138
140
|
return new WebSocket(targetUrl);
|
|
139
141
|
}
|
|
140
142
|
const req = new ClientRequestImpl(url, method);
|
package/dist/cjs/client/utils.js
CHANGED
|
@@ -21,7 +21,8 @@ __export(utils_exports, {
|
|
|
21
21
|
deepMerge: () => deepMerge,
|
|
22
22
|
mergePath: () => mergePath,
|
|
23
23
|
removeIndexString: () => removeIndexString,
|
|
24
|
-
replaceUrlParam: () => replaceUrlParam
|
|
24
|
+
replaceUrlParam: () => replaceUrlParam,
|
|
25
|
+
replaceUrlProtocol: () => replaceUrlProtocol
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(utils_exports);
|
|
27
28
|
const mergePath = (base, path) => {
|
|
@@ -37,6 +38,14 @@ const replaceUrlParam = (urlString, params) => {
|
|
|
37
38
|
}
|
|
38
39
|
return urlString;
|
|
39
40
|
};
|
|
41
|
+
const replaceUrlProtocol = (urlString, protocol) => {
|
|
42
|
+
switch (protocol) {
|
|
43
|
+
case "ws":
|
|
44
|
+
return urlString.replace(/^http/, "ws");
|
|
45
|
+
case "http":
|
|
46
|
+
return urlString.replace(/^ws/, "http");
|
|
47
|
+
}
|
|
48
|
+
};
|
|
40
49
|
const removeIndexString = (urlSting) => {
|
|
41
50
|
return urlSting.replace(/\/index$/, "");
|
|
42
51
|
};
|
|
@@ -63,5 +72,6 @@ function deepMerge(target, source) {
|
|
|
63
72
|
deepMerge,
|
|
64
73
|
mergePath,
|
|
65
74
|
removeIndexString,
|
|
66
|
-
replaceUrlParam
|
|
75
|
+
replaceUrlParam,
|
|
76
|
+
replaceUrlProtocol
|
|
67
77
|
});
|
|
@@ -19,7 +19,7 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
|
|
|
19
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
20
|
var ssg_exports = {};
|
|
21
21
|
__export(ssg_exports, {
|
|
22
|
-
|
|
22
|
+
X_HONO_DISABLE_SSG_HEADER_KEY: () => import_middleware.X_HONO_DISABLE_SSG_HEADER_KEY,
|
|
23
23
|
disableSSG: () => import_middleware.disableSSG,
|
|
24
24
|
isSSGContext: () => import_middleware.isSSGContext,
|
|
25
25
|
onlySSG: () => import_middleware.onlySSG,
|
|
@@ -30,7 +30,7 @@ __reExport(ssg_exports, require("./ssg"), module.exports);
|
|
|
30
30
|
var import_middleware = require("./middleware");
|
|
31
31
|
// Annotate the CommonJS export names for ESM import in node:
|
|
32
32
|
0 && (module.exports = {
|
|
33
|
-
|
|
33
|
+
X_HONO_DISABLE_SSG_HEADER_KEY,
|
|
34
34
|
disableSSG,
|
|
35
35
|
isSSGContext,
|
|
36
36
|
onlySSG,
|
|
@@ -20,6 +20,7 @@ var middleware_exports = {};
|
|
|
20
20
|
__export(middleware_exports, {
|
|
21
21
|
SSG_CONTEXT: () => SSG_CONTEXT,
|
|
22
22
|
SSG_DISABLED_RESPONSE: () => SSG_DISABLED_RESPONSE,
|
|
23
|
+
X_HONO_DISABLE_SSG_HEADER_KEY: () => X_HONO_DISABLE_SSG_HEADER_KEY,
|
|
23
24
|
disableSSG: () => disableSSG,
|
|
24
25
|
isSSGContext: () => isSSGContext,
|
|
25
26
|
onlySSG: () => onlySSG,
|
|
@@ -27,7 +28,17 @@ __export(middleware_exports, {
|
|
|
27
28
|
});
|
|
28
29
|
module.exports = __toCommonJS(middleware_exports);
|
|
29
30
|
const SSG_CONTEXT = "HONO_SSG_CONTEXT";
|
|
30
|
-
const
|
|
31
|
+
const X_HONO_DISABLE_SSG_HEADER_KEY = "x-hono-disable-ssg";
|
|
32
|
+
const SSG_DISABLED_RESPONSE = (() => {
|
|
33
|
+
try {
|
|
34
|
+
return new Response("SSG is disabled", {
|
|
35
|
+
status: 404,
|
|
36
|
+
headers: { [X_HONO_DISABLE_SSG_HEADER_KEY]: "true" }
|
|
37
|
+
});
|
|
38
|
+
} catch (e) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
})();
|
|
31
42
|
const ssgParams = (params) => async (c, next) => {
|
|
32
43
|
;
|
|
33
44
|
c.req.raw.ssgParams = Array.isArray(params) ? params : await params(c);
|
|
@@ -36,7 +47,8 @@ const ssgParams = (params) => async (c, next) => {
|
|
|
36
47
|
const isSSGContext = (c) => !!c.env?.[SSG_CONTEXT];
|
|
37
48
|
const disableSSG = () => async function disableSSG2(c, next) {
|
|
38
49
|
if (isSSGContext(c)) {
|
|
39
|
-
|
|
50
|
+
c.header(X_HONO_DISABLE_SSG_HEADER_KEY, "true");
|
|
51
|
+
return c.notFound();
|
|
40
52
|
}
|
|
41
53
|
await next();
|
|
42
54
|
};
|
|
@@ -50,6 +62,7 @@ const onlySSG = () => async function onlySSG2(c, next) {
|
|
|
50
62
|
0 && (module.exports = {
|
|
51
63
|
SSG_CONTEXT,
|
|
52
64
|
SSG_DISABLED_RESPONSE,
|
|
65
|
+
X_HONO_DISABLE_SSG_HEADER_KEY,
|
|
53
66
|
disableSSG,
|
|
54
67
|
isSSGContext,
|
|
55
68
|
onlySSG,
|
|
@@ -109,7 +109,7 @@ const fetchRoutesContent = function* (app, beforeRequestHook, afterResponseHook,
|
|
|
109
109
|
[import_middleware.SSG_CONTEXT]: true
|
|
110
110
|
})
|
|
111
111
|
);
|
|
112
|
-
if (response
|
|
112
|
+
if (response.headers.get(import_middleware.X_HONO_DISABLE_SSG_HEADER_KEY)) {
|
|
113
113
|
resolveReq(void 0);
|
|
114
114
|
return;
|
|
115
115
|
}
|
|
@@ -165,7 +165,7 @@ const saveContentToFile = async (data, fsModule, outDir, extensionMap) => {
|
|
|
165
165
|
return filePath;
|
|
166
166
|
};
|
|
167
167
|
const toSSG = async (app, fs, options) => {
|
|
168
|
-
let result
|
|
168
|
+
let result;
|
|
169
169
|
const getInfoPromises = [];
|
|
170
170
|
const savePromises = [];
|
|
171
171
|
try {
|
|
@@ -26,7 +26,7 @@ const testClient = (app, Env, executionCtx) => {
|
|
|
26
26
|
const customFetch = (input, init) => {
|
|
27
27
|
return app.request(input, init, Env, executionCtx);
|
|
28
28
|
};
|
|
29
|
-
return (0, import_client.hc)("", { fetch: customFetch });
|
|
29
|
+
return (0, import_client.hc)("http://localhost", { fetch: customFetch });
|
|
30
30
|
};
|
|
31
31
|
// Annotate the CommonJS export names for ESM import in node:
|
|
32
32
|
0 && (module.exports = {
|
|
@@ -110,36 +110,46 @@ d.replaceWith(c.content)
|
|
|
110
110
|
};
|
|
111
111
|
Suspense[import_constants.DOM_RENDERER] = import_components2.Suspense;
|
|
112
112
|
const textEncoder = new TextEncoder();
|
|
113
|
-
const renderToReadableStream = (str) => {
|
|
113
|
+
const renderToReadableStream = (str, onError = console.trace) => {
|
|
114
114
|
const reader = new ReadableStream({
|
|
115
115
|
async start(controller) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
controller.enqueue(textEncoder.encode(resolved));
|
|
125
|
-
let resolvedCount = 0;
|
|
126
|
-
const callbacks = [];
|
|
127
|
-
const then = (promise) => {
|
|
128
|
-
callbacks.push(
|
|
129
|
-
promise.catch((err) => {
|
|
130
|
-
console.trace(err);
|
|
131
|
-
return "";
|
|
132
|
-
}).then(async (res) => {
|
|
133
|
-
res = await (0, import_html2.resolveCallback)(res, import_html2.HtmlEscapedCallbackPhase.BeforeStream, true, context);
|
|
134
|
-
res.callbacks?.map((c) => c({ phase: import_html2.HtmlEscapedCallbackPhase.Stream, context })).filter(Boolean).forEach(then);
|
|
135
|
-
resolvedCount++;
|
|
136
|
-
controller.enqueue(textEncoder.encode(res));
|
|
137
|
-
})
|
|
116
|
+
try {
|
|
117
|
+
const tmp = str instanceof Promise ? await str : await str.toString();
|
|
118
|
+
const context = typeof tmp === "object" ? tmp : {};
|
|
119
|
+
const resolved = await (0, import_html2.resolveCallback)(
|
|
120
|
+
tmp,
|
|
121
|
+
import_html2.HtmlEscapedCallbackPhase.BeforeStream,
|
|
122
|
+
true,
|
|
123
|
+
context
|
|
138
124
|
);
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
125
|
+
controller.enqueue(textEncoder.encode(resolved));
|
|
126
|
+
let resolvedCount = 0;
|
|
127
|
+
const callbacks = [];
|
|
128
|
+
const then = (promise) => {
|
|
129
|
+
callbacks.push(
|
|
130
|
+
promise.catch((err) => {
|
|
131
|
+
console.log(err);
|
|
132
|
+
onError(err);
|
|
133
|
+
return "";
|
|
134
|
+
}).then(async (res) => {
|
|
135
|
+
res = await (0, import_html2.resolveCallback)(
|
|
136
|
+
res,
|
|
137
|
+
import_html2.HtmlEscapedCallbackPhase.BeforeStream,
|
|
138
|
+
true,
|
|
139
|
+
context
|
|
140
|
+
);
|
|
141
|
+
res.callbacks?.map((c) => c({ phase: import_html2.HtmlEscapedCallbackPhase.Stream, context })).filter(Boolean).forEach(then);
|
|
142
|
+
resolvedCount++;
|
|
143
|
+
controller.enqueue(textEncoder.encode(res));
|
|
144
|
+
})
|
|
145
|
+
);
|
|
146
|
+
};
|
|
147
|
+
resolved.callbacks?.map((c) => c({ phase: import_html2.HtmlEscapedCallbackPhase.Stream, context })).filter(Boolean).forEach(then);
|
|
148
|
+
while (resolvedCount !== callbacks.length) {
|
|
149
|
+
await Promise.all(callbacks);
|
|
150
|
+
}
|
|
151
|
+
} catch (e) {
|
|
152
|
+
onError(e);
|
|
143
153
|
}
|
|
144
154
|
controller.close();
|
|
145
155
|
}
|
|
@@ -47,11 +47,9 @@ class Node {
|
|
|
47
47
|
let curNode = this;
|
|
48
48
|
const parts = (0, import_url.splitRoutingPath)(path);
|
|
49
49
|
const possibleKeys = [];
|
|
50
|
-
const parentPatterns = [];
|
|
51
50
|
for (let i = 0, len = parts.length; i < len; i++) {
|
|
52
51
|
const p = parts[i];
|
|
53
52
|
if (Object.keys(curNode.children).includes(p)) {
|
|
54
|
-
parentPatterns.push(...curNode.patterns);
|
|
55
53
|
curNode = curNode.children[p];
|
|
56
54
|
const pattern2 = (0, import_url.getPattern)(p);
|
|
57
55
|
if (pattern2) {
|
|
@@ -63,10 +61,8 @@ class Node {
|
|
|
63
61
|
const pattern = (0, import_url.getPattern)(p);
|
|
64
62
|
if (pattern) {
|
|
65
63
|
curNode.patterns.push(pattern);
|
|
66
|
-
parentPatterns.push(...curNode.patterns);
|
|
67
64
|
possibleKeys.push(pattern[1]);
|
|
68
65
|
}
|
|
69
|
-
parentPatterns.push(...curNode.patterns);
|
|
70
66
|
curNode = curNode.children[p];
|
|
71
67
|
}
|
|
72
68
|
if (!curNode.methods.length) {
|
|
@@ -34,7 +34,7 @@ const encodeJwtPart = (part) => (0, import_encode.encodeBase64Url)(import_utf8.u
|
|
|
34
34
|
const encodeSignaturePart = (buf) => (0, import_encode.encodeBase64Url)(buf).replace(/=/g, "");
|
|
35
35
|
const decodeJwtPart = (part) => JSON.parse(import_utf8.utf8Decoder.decode((0, import_encode.decodeBase64Url)(part)));
|
|
36
36
|
function isTokenHeader(obj) {
|
|
37
|
-
return typeof obj === "object" && obj !== null && "alg" in obj && Object.values(import_jwa.AlgorithmTypes).includes(obj.alg) && "typ" in obj
|
|
37
|
+
return typeof obj === "object" && obj !== null && "alg" in obj && Object.values(import_jwa.AlgorithmTypes).includes(obj.alg) && (!("typ" in obj) || obj.typ === "JWT");
|
|
38
38
|
}
|
|
39
39
|
const sign = async (payload, privateKey, alg = "HS256") => {
|
|
40
40
|
const encodedPayload = encodeJwtPart(payload);
|
package/dist/client/client.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
// src/client/client.ts
|
|
2
2
|
import { serialize } from "../utils/cookie.js";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
deepMerge,
|
|
5
|
+
mergePath,
|
|
6
|
+
removeIndexString,
|
|
7
|
+
replaceUrlParam,
|
|
8
|
+
replaceUrlProtocol
|
|
9
|
+
} from "./utils.js";
|
|
4
10
|
var createProxy = (callback, path) => {
|
|
5
11
|
const proxy = new Proxy(() => {
|
|
6
12
|
}, {
|
|
@@ -63,7 +69,6 @@ var ClientRequestImpl = class {
|
|
|
63
69
|
}
|
|
64
70
|
}
|
|
65
71
|
let methodUpperCase = this.method.toUpperCase();
|
|
66
|
-
let setBody = !(methodUpperCase === "GET" || methodUpperCase === "HEAD");
|
|
67
72
|
const headerValues = {
|
|
68
73
|
...args?.header ?? {},
|
|
69
74
|
...typeof opt?.headers === "function" ? await opt.headers() : opt?.headers ? opt.headers : {}
|
|
@@ -86,7 +91,7 @@ var ClientRequestImpl = class {
|
|
|
86
91
|
url = url + "?" + this.queryParams.toString();
|
|
87
92
|
}
|
|
88
93
|
methodUpperCase = this.method.toUpperCase();
|
|
89
|
-
setBody = !(methodUpperCase === "GET" || methodUpperCase === "HEAD");
|
|
94
|
+
const setBody = !(methodUpperCase === "GET" || methodUpperCase === "HEAD");
|
|
90
95
|
return (opt?.fetch || fetch)(url, {
|
|
91
96
|
body: setBody ? this.rBody : void 0,
|
|
92
97
|
method: methodUpperCase,
|
|
@@ -112,7 +117,10 @@ var hc = (baseUrl, options) => createProxy((opts) => {
|
|
|
112
117
|
return new URL(url);
|
|
113
118
|
}
|
|
114
119
|
if (method === "ws") {
|
|
115
|
-
const targetUrl =
|
|
120
|
+
const targetUrl = replaceUrlProtocol(
|
|
121
|
+
opts.args[0] && opts.args[0].param ? replaceUrlParam(url, opts.args[0].param) : url,
|
|
122
|
+
"ws"
|
|
123
|
+
);
|
|
116
124
|
return new WebSocket(targetUrl);
|
|
117
125
|
}
|
|
118
126
|
const req = new ClientRequestImpl(url, method);
|
package/dist/client/utils.js
CHANGED
|
@@ -12,6 +12,14 @@ var replaceUrlParam = (urlString, params) => {
|
|
|
12
12
|
}
|
|
13
13
|
return urlString;
|
|
14
14
|
};
|
|
15
|
+
var replaceUrlProtocol = (urlString, protocol) => {
|
|
16
|
+
switch (protocol) {
|
|
17
|
+
case "ws":
|
|
18
|
+
return urlString.replace(/^http/, "ws");
|
|
19
|
+
case "http":
|
|
20
|
+
return urlString.replace(/^ws/, "http");
|
|
21
|
+
}
|
|
22
|
+
};
|
|
15
23
|
var removeIndexString = (urlSting) => {
|
|
16
24
|
return urlSting.replace(/\/index$/, "");
|
|
17
25
|
};
|
|
@@ -37,5 +45,6 @@ export {
|
|
|
37
45
|
deepMerge,
|
|
38
46
|
mergePath,
|
|
39
47
|
removeIndexString,
|
|
40
|
-
replaceUrlParam
|
|
48
|
+
replaceUrlParam,
|
|
49
|
+
replaceUrlProtocol
|
|
41
50
|
};
|
package/dist/helper/ssg/index.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
// src/helper/ssg/index.ts
|
|
2
2
|
export * from "./ssg.js";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
X_HONO_DISABLE_SSG_HEADER_KEY,
|
|
5
|
+
ssgParams,
|
|
6
|
+
isSSGContext,
|
|
7
|
+
disableSSG,
|
|
8
|
+
onlySSG
|
|
9
|
+
} from "./middleware.js";
|
|
4
10
|
export {
|
|
5
|
-
|
|
11
|
+
X_HONO_DISABLE_SSG_HEADER_KEY,
|
|
6
12
|
disableSSG,
|
|
7
13
|
isSSGContext,
|
|
8
14
|
onlySSG,
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
// src/helper/ssg/middleware.ts
|
|
2
2
|
var SSG_CONTEXT = "HONO_SSG_CONTEXT";
|
|
3
|
-
var
|
|
3
|
+
var X_HONO_DISABLE_SSG_HEADER_KEY = "x-hono-disable-ssg";
|
|
4
|
+
var SSG_DISABLED_RESPONSE = (() => {
|
|
5
|
+
try {
|
|
6
|
+
return new Response("SSG is disabled", {
|
|
7
|
+
status: 404,
|
|
8
|
+
headers: { [X_HONO_DISABLE_SSG_HEADER_KEY]: "true" }
|
|
9
|
+
});
|
|
10
|
+
} catch (e) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
})();
|
|
4
14
|
var ssgParams = (params) => async (c, next) => {
|
|
5
15
|
;
|
|
6
16
|
c.req.raw.ssgParams = Array.isArray(params) ? params : await params(c);
|
|
@@ -9,7 +19,8 @@ var ssgParams = (params) => async (c, next) => {
|
|
|
9
19
|
var isSSGContext = (c) => !!c.env?.[SSG_CONTEXT];
|
|
10
20
|
var disableSSG = () => async function disableSSG2(c, next) {
|
|
11
21
|
if (isSSGContext(c)) {
|
|
12
|
-
|
|
22
|
+
c.header(X_HONO_DISABLE_SSG_HEADER_KEY, "true");
|
|
23
|
+
return c.notFound();
|
|
13
24
|
}
|
|
14
25
|
await next();
|
|
15
26
|
};
|
|
@@ -22,6 +33,7 @@ var onlySSG = () => async function onlySSG2(c, next) {
|
|
|
22
33
|
export {
|
|
23
34
|
SSG_CONTEXT,
|
|
24
35
|
SSG_DISABLED_RESPONSE,
|
|
36
|
+
X_HONO_DISABLE_SSG_HEADER_KEY,
|
|
25
37
|
disableSSG,
|
|
26
38
|
isSSGContext,
|
|
27
39
|
onlySSG,
|
package/dist/helper/ssg/ssg.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { replaceUrlParam } from "../../client/utils.js";
|
|
3
3
|
import { createPool } from "../../utils/concurrent.js";
|
|
4
4
|
import { getExtension } from "../../utils/mime.js";
|
|
5
|
-
import {
|
|
5
|
+
import { X_HONO_DISABLE_SSG_HEADER_KEY, SSG_CONTEXT } from "./middleware.js";
|
|
6
6
|
import { joinPaths, dirname, filterStaticGenerateRoutes } from "./utils.js";
|
|
7
7
|
var DEFAULT_CONCURRENCY = 2;
|
|
8
8
|
var generateFilePath = (routePath, outDir, mimeType, extensionMap) => {
|
|
@@ -84,7 +84,7 @@ var fetchRoutesContent = function* (app, beforeRequestHook, afterResponseHook, c
|
|
|
84
84
|
[SSG_CONTEXT]: true
|
|
85
85
|
})
|
|
86
86
|
);
|
|
87
|
-
if (response
|
|
87
|
+
if (response.headers.get(X_HONO_DISABLE_SSG_HEADER_KEY)) {
|
|
88
88
|
resolveReq(void 0);
|
|
89
89
|
return;
|
|
90
90
|
}
|
|
@@ -140,7 +140,7 @@ var saveContentToFile = async (data, fsModule, outDir, extensionMap) => {
|
|
|
140
140
|
return filePath;
|
|
141
141
|
};
|
|
142
142
|
var toSSG = async (app, fs, options) => {
|
|
143
|
-
let result
|
|
143
|
+
let result;
|
|
144
144
|
const getInfoPromises = [];
|
|
145
145
|
const savePromises = [];
|
|
146
146
|
try {
|
|
@@ -4,7 +4,7 @@ var testClient = (app, Env, executionCtx) => {
|
|
|
4
4
|
const customFetch = (input, init) => {
|
|
5
5
|
return app.request(input, init, Env, executionCtx);
|
|
6
6
|
};
|
|
7
|
-
return hc("", { fetch: customFetch });
|
|
7
|
+
return hc("http://localhost", { fetch: customFetch });
|
|
8
8
|
};
|
|
9
9
|
export {
|
|
10
10
|
testClient
|
package/dist/jsx/streaming.js
CHANGED
|
@@ -87,36 +87,46 @@ d.replaceWith(c.content)
|
|
|
87
87
|
};
|
|
88
88
|
Suspense[DOM_RENDERER] = SuspenseDomRenderer;
|
|
89
89
|
var textEncoder = new TextEncoder();
|
|
90
|
-
var renderToReadableStream = (str) => {
|
|
90
|
+
var renderToReadableStream = (str, onError = console.trace) => {
|
|
91
91
|
const reader = new ReadableStream({
|
|
92
92
|
async start(controller) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
controller.enqueue(textEncoder.encode(resolved));
|
|
102
|
-
let resolvedCount = 0;
|
|
103
|
-
const callbacks = [];
|
|
104
|
-
const then = (promise) => {
|
|
105
|
-
callbacks.push(
|
|
106
|
-
promise.catch((err) => {
|
|
107
|
-
console.trace(err);
|
|
108
|
-
return "";
|
|
109
|
-
}).then(async (res) => {
|
|
110
|
-
res = await resolveCallback(res, HtmlEscapedCallbackPhase.BeforeStream, true, context);
|
|
111
|
-
res.callbacks?.map((c) => c({ phase: HtmlEscapedCallbackPhase.Stream, context })).filter(Boolean).forEach(then);
|
|
112
|
-
resolvedCount++;
|
|
113
|
-
controller.enqueue(textEncoder.encode(res));
|
|
114
|
-
})
|
|
93
|
+
try {
|
|
94
|
+
const tmp = str instanceof Promise ? await str : await str.toString();
|
|
95
|
+
const context = typeof tmp === "object" ? tmp : {};
|
|
96
|
+
const resolved = await resolveCallback(
|
|
97
|
+
tmp,
|
|
98
|
+
HtmlEscapedCallbackPhase.BeforeStream,
|
|
99
|
+
true,
|
|
100
|
+
context
|
|
115
101
|
);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
102
|
+
controller.enqueue(textEncoder.encode(resolved));
|
|
103
|
+
let resolvedCount = 0;
|
|
104
|
+
const callbacks = [];
|
|
105
|
+
const then = (promise) => {
|
|
106
|
+
callbacks.push(
|
|
107
|
+
promise.catch((err) => {
|
|
108
|
+
console.log(err);
|
|
109
|
+
onError(err);
|
|
110
|
+
return "";
|
|
111
|
+
}).then(async (res) => {
|
|
112
|
+
res = await resolveCallback(
|
|
113
|
+
res,
|
|
114
|
+
HtmlEscapedCallbackPhase.BeforeStream,
|
|
115
|
+
true,
|
|
116
|
+
context
|
|
117
|
+
);
|
|
118
|
+
res.callbacks?.map((c) => c({ phase: HtmlEscapedCallbackPhase.Stream, context })).filter(Boolean).forEach(then);
|
|
119
|
+
resolvedCount++;
|
|
120
|
+
controller.enqueue(textEncoder.encode(res));
|
|
121
|
+
})
|
|
122
|
+
);
|
|
123
|
+
};
|
|
124
|
+
resolved.callbacks?.map((c) => c({ phase: HtmlEscapedCallbackPhase.Stream, context })).filter(Boolean).forEach(then);
|
|
125
|
+
while (resolvedCount !== callbacks.length) {
|
|
126
|
+
await Promise.all(callbacks);
|
|
127
|
+
}
|
|
128
|
+
} catch (e) {
|
|
129
|
+
onError(e);
|
|
120
130
|
}
|
|
121
131
|
controller.close();
|
|
122
132
|
}
|
|
@@ -25,11 +25,9 @@ var Node = class {
|
|
|
25
25
|
let curNode = this;
|
|
26
26
|
const parts = splitRoutingPath(path);
|
|
27
27
|
const possibleKeys = [];
|
|
28
|
-
const parentPatterns = [];
|
|
29
28
|
for (let i = 0, len = parts.length; i < len; i++) {
|
|
30
29
|
const p = parts[i];
|
|
31
30
|
if (Object.keys(curNode.children).includes(p)) {
|
|
32
|
-
parentPatterns.push(...curNode.patterns);
|
|
33
31
|
curNode = curNode.children[p];
|
|
34
32
|
const pattern2 = getPattern(p);
|
|
35
33
|
if (pattern2) {
|
|
@@ -41,10 +39,8 @@ var Node = class {
|
|
|
41
39
|
const pattern = getPattern(p);
|
|
42
40
|
if (pattern) {
|
|
43
41
|
curNode.patterns.push(pattern);
|
|
44
|
-
parentPatterns.push(...curNode.patterns);
|
|
45
42
|
possibleKeys.push(pattern[1]);
|
|
46
43
|
}
|
|
47
|
-
parentPatterns.push(...curNode.patterns);
|
|
48
44
|
curNode = curNode.children[p];
|
|
49
45
|
}
|
|
50
46
|
if (!curNode.methods.length) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare const mergePath: (base: string, path: string) => string;
|
|
2
2
|
export declare const replaceUrlParam: (urlString: string, params: Record<string, string>) => string;
|
|
3
|
+
export declare const replaceUrlProtocol: (urlString: string, protocol: 'ws' | 'http') => string;
|
|
3
4
|
export declare const removeIndexString: (urlSting: string) => string;
|
|
4
5
|
export declare function deepMerge<T>(target: T, source: Record<string, unknown>): T;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './ssg';
|
|
2
|
-
export {
|
|
2
|
+
export { X_HONO_DISABLE_SSG_HEADER_KEY, ssgParams, isSSGContext, disableSSG, onlySSG, } from './middleware';
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import type { Context } from '../../context';
|
|
2
2
|
import type { Env, MiddlewareHandler } from '../../types';
|
|
3
3
|
export declare const SSG_CONTEXT = "HONO_SSG_CONTEXT";
|
|
4
|
+
export declare const X_HONO_DISABLE_SSG_HEADER_KEY = "x-hono-disable-ssg";
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated
|
|
7
|
+
* Use `X_HONO_DISABLE_SSG_HEADER_KEY` instead.
|
|
8
|
+
* This constant will be removed in the next minor version.
|
|
9
|
+
*/
|
|
4
10
|
export declare const SSG_DISABLED_RESPONSE: Response;
|
|
5
11
|
interface SSGParam {
|
|
6
12
|
[key: string]: string;
|
|
@@ -13,4 +13,4 @@ export declare const Suspense: FC<PropsWithChildren<{
|
|
|
13
13
|
* `renderToReadableStream()` is an experimental feature.
|
|
14
14
|
* The API might be changed.
|
|
15
15
|
*/
|
|
16
|
-
export declare const renderToReadableStream: (str: HtmlEscapedString | Promise<HtmlEscapedString
|
|
16
|
+
export declare const renderToReadableStream: (str: HtmlEscapedString | Promise<HtmlEscapedString>, onError?: (e: unknown) => void) => ReadableStream<Uint8Array>;
|
|
@@ -3,7 +3,7 @@ import type { SignatureKey } from './jws';
|
|
|
3
3
|
import { type JWTPayload } from './types';
|
|
4
4
|
export interface TokenHeader {
|
|
5
5
|
alg: SignatureAlgorithm;
|
|
6
|
-
typ
|
|
6
|
+
typ?: 'JWT';
|
|
7
7
|
}
|
|
8
8
|
export declare function isTokenHeader(obj: any): obj is TokenHeader;
|
|
9
9
|
export declare const sign: (payload: JWTPayload, privateKey: SignatureKey, alg?: SignatureAlgorithm) => Promise<string>;
|
|
@@ -5,10 +5,10 @@ type ValidationTargetByMethod<M> = M extends 'get' | 'head' ? Exclude<keyof Vali
|
|
|
5
5
|
export type ValidationFunction<InputType, OutputType, E extends Env = {}, P extends string = string> = (value: InputType, c: Context<E, P>) => OutputType | Response | Promise<OutputType> | Promise<Response>;
|
|
6
6
|
type ExcludeResponseType<T> = T extends Response & TypedResponse<any> ? never : T;
|
|
7
7
|
export declare const validator: <InputType, P extends string, M extends string, U extends ValidationTargetByMethod<M>, OutputType = ValidationTargets[U], OutputTypeExcludeResponseType = ExcludeResponseType<OutputType>, P2 extends string = P, V extends {
|
|
8
|
-
in: { [K in U]: K extends "json" ? InputType : { [K2 in keyof OutputTypeExcludeResponseType]: ValidationTargets[K][K2]; }; };
|
|
8
|
+
in: { [K in U]: K extends "json" ? unknown extends InputType ? OutputTypeExcludeResponseType : InputType : { [K2 in keyof OutputTypeExcludeResponseType]: ValidationTargets[K][K2]; }; };
|
|
9
9
|
out: { [K_1 in U]: OutputTypeExcludeResponseType; };
|
|
10
10
|
} = {
|
|
11
|
-
in: { [K_2 in U]: K_2 extends "json" ? InputType : { [K2_1 in keyof OutputTypeExcludeResponseType]: ValidationTargets[K_2][K2_1]; }; };
|
|
11
|
+
in: { [K_2 in U]: K_2 extends "json" ? unknown extends InputType ? OutputTypeExcludeResponseType : InputType : { [K2_1 in keyof OutputTypeExcludeResponseType]: ValidationTargets[K_2][K2_1]; }; };
|
|
12
12
|
out: { [K_3 in U]: OutputTypeExcludeResponseType; };
|
|
13
13
|
}, E extends Env = any>(target: U, validationFunc: ValidationFunction<unknown extends InputType ? ValidationTargets[U] : InputType, OutputType, E, P2>) => MiddlewareHandler<E, P, V>;
|
|
14
14
|
export {};
|
package/dist/utils/jwt/jwt.js
CHANGED
|
@@ -15,7 +15,7 @@ var encodeJwtPart = (part) => encodeBase64Url(utf8Encoder.encode(JSON.stringify(
|
|
|
15
15
|
var encodeSignaturePart = (buf) => encodeBase64Url(buf).replace(/=/g, "");
|
|
16
16
|
var decodeJwtPart = (part) => JSON.parse(utf8Decoder.decode(decodeBase64Url(part)));
|
|
17
17
|
function isTokenHeader(obj) {
|
|
18
|
-
return typeof obj === "object" && obj !== null && "alg" in obj && Object.values(AlgorithmTypes).includes(obj.alg) && "typ" in obj
|
|
18
|
+
return typeof obj === "object" && obj !== null && "alg" in obj && Object.values(AlgorithmTypes).includes(obj.alg) && (!("typ" in obj) || obj.typ === "JWT");
|
|
19
19
|
}
|
|
20
20
|
var sign = async (payload, privateKey, alg = "HS256") => {
|
|
21
21
|
const encodedPayload = encodeJwtPart(payload);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hono",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.4",
|
|
4
4
|
"description": "Ultrafast web framework for the Edges",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -382,6 +382,9 @@
|
|
|
382
382
|
"etag": [
|
|
383
383
|
"./dist/types/middleware/etag"
|
|
384
384
|
],
|
|
385
|
+
"trailing-slash": [
|
|
386
|
+
"./dist/types/middleware/trailing-slash"
|
|
387
|
+
],
|
|
385
388
|
"html": [
|
|
386
389
|
"./dist/types/helper/html"
|
|
387
390
|
],
|