hono 4.6.7 → 4.6.9
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/websocket.js +4 -6
- package/dist/adapter/cloudflare-workers/websocket.js +34 -39
- package/dist/adapter/deno/serve-static.js +2 -1
- package/dist/adapter/lambda-edge/handler.js +1 -1
- package/dist/cjs/adapter/bun/websocket.js +4 -6
- package/dist/cjs/adapter/cloudflare-workers/websocket.js +34 -39
- package/dist/cjs/adapter/deno/serve-static.js +2 -1
- package/dist/cjs/adapter/lambda-edge/handler.js +1 -1
- package/dist/cjs/client/client.js +3 -3
- package/dist/cjs/compose.js +4 -3
- package/dist/cjs/context.js +12 -9
- package/dist/cjs/helper/cookie/index.js +1 -1
- package/dist/cjs/helper/html/index.js +1 -1
- package/dist/cjs/helper/ssg/ssg.js +2 -2
- package/dist/cjs/helper/ssg/utils.js +2 -2
- package/dist/cjs/helper/websocket/index.js +1 -4
- package/dist/cjs/hono-base.js +29 -32
- package/dist/cjs/jsx/base.js +8 -3
- package/dist/cjs/jsx/constants.js +3 -0
- package/dist/cjs/jsx/dom/index.js +8 -2
- package/dist/cjs/jsx/dom/render.js +15 -12
- package/dist/cjs/middleware/etag/digest.js +59 -0
- package/dist/cjs/middleware/etag/index.js +5 -2
- package/dist/cjs/middleware/ip-restriction/index.js +3 -3
- package/dist/cjs/middleware/jsx-renderer/index.js +2 -1
- package/dist/cjs/middleware/logger/index.js +13 -11
- package/dist/cjs/middleware/timing/timing.js +5 -7
- package/dist/cjs/request.js +15 -14
- package/dist/cjs/router/pattern-router/router.js +4 -4
- package/dist/cjs/router/reg-exp-router/router.js +5 -5
- package/dist/cjs/router/reg-exp-router/trie.js +2 -2
- package/dist/cjs/router/trie-router/node.js +9 -7
- package/dist/cjs/utils/color.js +1 -1
- package/dist/cjs/utils/cookie.js +13 -6
- package/dist/cjs/utils/crypto.js +0 -9
- package/dist/cjs/utils/headers.js +16 -0
- package/dist/cjs/utils/jwt/jwt.js +1 -1
- package/dist/cjs/utils/mime.js +2 -1
- package/dist/cjs/utils/url.js +9 -6
- package/dist/client/client.js +3 -3
- package/dist/compose.js +4 -3
- package/dist/context.js +12 -9
- package/dist/helper/cookie/index.js +1 -1
- package/dist/helper/html/index.js +1 -1
- package/dist/helper/ssg/ssg.js +2 -2
- package/dist/helper/ssg/utils.js +2 -2
- package/dist/helper/websocket/index.js +1 -4
- package/dist/hono-base.js +29 -32
- package/dist/jsx/base.js +7 -3
- package/dist/jsx/constants.js +2 -0
- package/dist/jsx/dom/index.js +7 -1
- package/dist/jsx/dom/render.js +22 -13
- package/dist/middleware/etag/digest.js +36 -0
- package/dist/middleware/etag/index.js +5 -2
- package/dist/middleware/ip-restriction/index.js +3 -3
- package/dist/middleware/jsx-renderer/index.js +2 -1
- package/dist/middleware/logger/index.js +13 -11
- package/dist/middleware/timing/timing.js +5 -7
- package/dist/request.js +16 -15
- package/dist/router/pattern-router/router.js +4 -4
- package/dist/router/reg-exp-router/router.js +5 -5
- package/dist/router/reg-exp-router/trie.js +2 -2
- package/dist/router/trie-router/node.js +9 -7
- package/dist/types/adapter/bun/websocket.d.ts +5 -3
- package/dist/types/adapter/cloudflare-workers/websocket.d.ts +2 -2
- package/dist/types/adapter/deno/websocket.d.ts +1 -20
- package/dist/types/context.d.ts +2 -2
- package/dist/types/helper/accepts/accepts.d.ts +1 -1
- package/dist/types/helper/websocket/index.d.ts +3 -3
- package/dist/types/hono-base.d.ts +1 -1
- package/dist/types/jsx/base.d.ts +5 -0
- package/dist/types/jsx/constants.d.ts +1 -0
- package/dist/types/jsx/dom/index.d.ts +6 -5
- package/dist/types/jsx/dom/render.d.ts +1 -0
- package/dist/types/middleware/etag/digest.d.ts +1 -0
- package/dist/types/request.d.ts +3 -1
- package/dist/types/types.d.ts +71 -70
- package/dist/types/utils/body.d.ts +2 -2
- package/dist/types/utils/cookie.d.ts +4 -4
- package/dist/types/utils/crypto.d.ts +2 -1
- package/dist/types/utils/headers.d.ts +8 -0
- package/dist/types/utils/mime.d.ts +58 -1
- package/dist/types/utils/url.d.ts +3 -0
- package/dist/utils/color.js +1 -1
- package/dist/utils/cookie.js +13 -6
- package/dist/utils/crypto.js +0 -9
- package/dist/utils/headers.js +0 -0
- package/dist/utils/jwt/jwt.js +1 -1
- package/dist/utils/mime.js +2 -1
- package/dist/utils/url.js +7 -5
- package/package.json +1 -1
package/dist/cjs/jsx/base.js
CHANGED
|
@@ -34,7 +34,8 @@ __export(base_exports, {
|
|
|
34
34
|
jsx: () => jsx,
|
|
35
35
|
jsxFn: () => jsxFn,
|
|
36
36
|
memo: () => memo,
|
|
37
|
-
reactAPICompatVersion: () => reactAPICompatVersion
|
|
37
|
+
reactAPICompatVersion: () => reactAPICompatVersion,
|
|
38
|
+
shallowEqual: () => shallowEqual
|
|
38
39
|
});
|
|
39
40
|
module.exports = __toCommonJS(base_exports);
|
|
40
41
|
var import_html = require("../helper/html");
|
|
@@ -308,13 +309,16 @@ const shallowEqual = (a, b) => {
|
|
|
308
309
|
const memo = (component, propsAreEqual = shallowEqual) => {
|
|
309
310
|
let computed = null;
|
|
310
311
|
let prevProps = void 0;
|
|
311
|
-
|
|
312
|
+
const wrapper = (props) => {
|
|
312
313
|
if (prevProps && !propsAreEqual(prevProps, props)) {
|
|
313
314
|
computed = null;
|
|
314
315
|
}
|
|
315
316
|
prevProps = props;
|
|
316
317
|
return computed ||= component(props);
|
|
317
318
|
};
|
|
319
|
+
wrapper[import_constants.DOM_MEMO] = propsAreEqual;
|
|
320
|
+
wrapper[import_constants.DOM_RENDERER] = component;
|
|
321
|
+
return wrapper;
|
|
318
322
|
};
|
|
319
323
|
const Fragment = ({
|
|
320
324
|
children
|
|
@@ -350,5 +354,6 @@ const reactAPICompatVersion = "19.0.0-hono-jsx";
|
|
|
350
354
|
jsx,
|
|
351
355
|
jsxFn,
|
|
352
356
|
memo,
|
|
353
|
-
reactAPICompatVersion
|
|
357
|
+
reactAPICompatVersion,
|
|
358
|
+
shallowEqual
|
|
354
359
|
});
|
|
@@ -20,6 +20,7 @@ var constants_exports = {};
|
|
|
20
20
|
__export(constants_exports, {
|
|
21
21
|
DOM_ERROR_HANDLER: () => DOM_ERROR_HANDLER,
|
|
22
22
|
DOM_INTERNAL_TAG: () => DOM_INTERNAL_TAG,
|
|
23
|
+
DOM_MEMO: () => DOM_MEMO,
|
|
23
24
|
DOM_RENDERER: () => DOM_RENDERER,
|
|
24
25
|
DOM_STASH: () => DOM_STASH,
|
|
25
26
|
PERMALINK: () => PERMALINK
|
|
@@ -29,11 +30,13 @@ const DOM_RENDERER = Symbol("RENDERER");
|
|
|
29
30
|
const DOM_ERROR_HANDLER = Symbol("ERROR_HANDLER");
|
|
30
31
|
const DOM_STASH = Symbol("STASH");
|
|
31
32
|
const DOM_INTERNAL_TAG = Symbol("INTERNAL");
|
|
33
|
+
const DOM_MEMO = Symbol("MEMO");
|
|
32
34
|
const PERMALINK = Symbol("PERMALINK");
|
|
33
35
|
// Annotate the CommonJS export names for ESM import in node:
|
|
34
36
|
0 && (module.exports = {
|
|
35
37
|
DOM_ERROR_HANDLER,
|
|
36
38
|
DOM_INTERNAL_TAG,
|
|
39
|
+
DOM_MEMO,
|
|
37
40
|
DOM_RENDERER,
|
|
38
41
|
DOM_STASH,
|
|
39
42
|
PERMALINK
|
|
@@ -33,7 +33,7 @@ __export(dom_exports, {
|
|
|
33
33
|
forwardRef: () => import_hooks.forwardRef,
|
|
34
34
|
isValidElement: () => import_base.isValidElement,
|
|
35
35
|
jsx: () => createElement,
|
|
36
|
-
memo: () =>
|
|
36
|
+
memo: () => memo,
|
|
37
37
|
render: () => import_render2.render,
|
|
38
38
|
startTransition: () => import_hooks.startTransition,
|
|
39
39
|
startViewTransition: () => import_hooks.startViewTransition,
|
|
@@ -62,6 +62,7 @@ __export(dom_exports, {
|
|
|
62
62
|
module.exports = __toCommonJS(dom_exports);
|
|
63
63
|
var import_base = require("../base");
|
|
64
64
|
var import_children = require("../children");
|
|
65
|
+
var import_constants = require("../constants");
|
|
65
66
|
var import_context = require("../context");
|
|
66
67
|
var import_hooks = require("../hooks");
|
|
67
68
|
var import_components = require("./components");
|
|
@@ -93,6 +94,11 @@ const cloneElement = (element, props, ...children) => {
|
|
|
93
94
|
element.key
|
|
94
95
|
);
|
|
95
96
|
};
|
|
97
|
+
const memo = (component, propsAreEqual = import_base.shallowEqual) => {
|
|
98
|
+
const wrapper = (props) => component(props);
|
|
99
|
+
wrapper[import_constants.DOM_MEMO] = propsAreEqual;
|
|
100
|
+
return wrapper;
|
|
101
|
+
};
|
|
96
102
|
var dom_default = {
|
|
97
103
|
version: import_base.reactAPICompatVersion,
|
|
98
104
|
useState: import_hooks.useState,
|
|
@@ -122,7 +128,7 @@ var dom_default = {
|
|
|
122
128
|
ErrorBoundary: import_components.ErrorBoundary,
|
|
123
129
|
createContext: import_context2.createContext,
|
|
124
130
|
useContext: import_context.useContext,
|
|
125
|
-
memo
|
|
131
|
+
memo,
|
|
126
132
|
isValidElement: import_base.isValidElement,
|
|
127
133
|
createElement,
|
|
128
134
|
cloneElement,
|
|
@@ -258,13 +258,19 @@ const applyNodeObject = (node, container, isNew) => {
|
|
|
258
258
|
remove.forEach(removeNode);
|
|
259
259
|
const childNodes = isNew ? void 0 : container.childNodes;
|
|
260
260
|
let offset;
|
|
261
|
+
let insertBeforeNode = null;
|
|
261
262
|
if (isNew) {
|
|
262
263
|
offset = -1;
|
|
264
|
+
} else if (!childNodes.length) {
|
|
265
|
+
offset = 0;
|
|
263
266
|
} else {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
267
|
+
const offsetByNextNode = findChildNodeIndex(childNodes, findInsertBefore(node.nN));
|
|
268
|
+
if (offsetByNextNode !== void 0) {
|
|
269
|
+
insertBeforeNode = childNodes[offsetByNextNode];
|
|
270
|
+
offset = offsetByNextNode;
|
|
271
|
+
} else {
|
|
272
|
+
offset = findChildNodeIndex(childNodes, next.find((n) => n.tag !== HONO_PORTAL_ELEMENT && n.e)?.e) ?? -1;
|
|
273
|
+
}
|
|
268
274
|
if (offset === -1) {
|
|
269
275
|
isNew = true;
|
|
270
276
|
}
|
|
@@ -299,7 +305,7 @@ const applyNodeObject = (node, container, isNew) => {
|
|
|
299
305
|
if (childNodes[offset + 1] === el) {
|
|
300
306
|
container.appendChild(childNodes[offset]);
|
|
301
307
|
} else {
|
|
302
|
-
container.insertBefore(el, childNodes[offset] || null);
|
|
308
|
+
container.insertBefore(el, insertBeforeNode || childNodes[offset] || null);
|
|
303
309
|
}
|
|
304
310
|
}
|
|
305
311
|
}
|
|
@@ -381,12 +387,8 @@ const build = (context, node, children) => {
|
|
|
381
387
|
if (typeof child.tag === "function") {
|
|
382
388
|
oldChild[import_constants.DOM_STASH][2] = child[import_constants.DOM_STASH][2] || [];
|
|
383
389
|
oldChild[import_constants.DOM_STASH][3] = child[import_constants.DOM_STASH][3];
|
|
384
|
-
if (!oldChild.f) {
|
|
385
|
-
|
|
386
|
-
const currentProps = oldChild.props;
|
|
387
|
-
if (prevPropsKeys.length === Object.keys(currentProps).length && prevPropsKeys.every((k) => k in currentProps && currentProps[k] === pP[k])) {
|
|
388
|
-
oldChild.s = true;
|
|
389
|
-
}
|
|
390
|
+
if (!oldChild.f && ((oldChild.o || oldChild) === child.o || oldChild.tag[import_constants.DOM_MEMO]?.(pP, oldChild.props))) {
|
|
391
|
+
oldChild.s = true;
|
|
390
392
|
}
|
|
391
393
|
}
|
|
392
394
|
child = oldChild;
|
|
@@ -473,7 +475,8 @@ const buildNode = (node) => {
|
|
|
473
475
|
key: node.key,
|
|
474
476
|
f: node.f,
|
|
475
477
|
type: node.tag,
|
|
476
|
-
ref: node.props.ref
|
|
478
|
+
ref: node.props.ref,
|
|
479
|
+
o: node.o || node
|
|
477
480
|
};
|
|
478
481
|
}
|
|
479
482
|
if (typeof node.tag === "function") {
|
|
@@ -0,0 +1,59 @@
|
|
|
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 digest_exports = {};
|
|
20
|
+
__export(digest_exports, {
|
|
21
|
+
generateDigest: () => generateDigest
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(digest_exports);
|
|
24
|
+
const mergeBuffers = (buffer1, buffer2) => {
|
|
25
|
+
if (!buffer1) {
|
|
26
|
+
return buffer2;
|
|
27
|
+
}
|
|
28
|
+
const merged = new Uint8Array(buffer1.byteLength + buffer2.byteLength);
|
|
29
|
+
merged.set(new Uint8Array(buffer1), 0);
|
|
30
|
+
merged.set(buffer2, buffer1.byteLength);
|
|
31
|
+
return merged;
|
|
32
|
+
};
|
|
33
|
+
const generateDigest = async (stream) => {
|
|
34
|
+
if (!stream || !crypto || !crypto.subtle) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
let result = void 0;
|
|
38
|
+
const reader = stream.getReader();
|
|
39
|
+
for (; ; ) {
|
|
40
|
+
const { value, done } = await reader.read();
|
|
41
|
+
if (done) {
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
result = await crypto.subtle.digest(
|
|
45
|
+
{
|
|
46
|
+
name: "SHA-1"
|
|
47
|
+
},
|
|
48
|
+
mergeBuffers(result, value)
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
if (!result) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
return Array.prototype.map.call(new Uint8Array(result), (x) => x.toString(16).padStart(2, "0")).join("");
|
|
55
|
+
};
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
generateDigest
|
|
59
|
+
});
|
|
@@ -22,7 +22,7 @@ __export(etag_exports, {
|
|
|
22
22
|
etag: () => etag
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(etag_exports);
|
|
25
|
-
var
|
|
25
|
+
var import_digest = require("./digest");
|
|
26
26
|
const RETAINED_304_HEADERS = [
|
|
27
27
|
"cache-control",
|
|
28
28
|
"content-location",
|
|
@@ -43,7 +43,10 @@ const etag = (options) => {
|
|
|
43
43
|
const res = c.res;
|
|
44
44
|
let etag3 = res.headers.get("ETag");
|
|
45
45
|
if (!etag3) {
|
|
46
|
-
const hash = await (0,
|
|
46
|
+
const hash = await (0, import_digest.generateDigest)(res.clone().body);
|
|
47
|
+
if (hash === null) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
47
50
|
etag3 = weak ? `W/"${hash}"` : `"${hash}"`;
|
|
48
51
|
}
|
|
49
52
|
if (etagMatches(etag3, ifNoneMatch)) {
|
|
@@ -35,14 +35,14 @@ const buildMatcher = (rules) => {
|
|
|
35
35
|
functionRules.push(rule);
|
|
36
36
|
} else {
|
|
37
37
|
if (IS_CIDR_NOTATION_REGEX.test(rule)) {
|
|
38
|
-
const
|
|
39
|
-
const addrStr =
|
|
38
|
+
const separatedRule = rule.split("/");
|
|
39
|
+
const addrStr = separatedRule[0];
|
|
40
40
|
const type2 = (0, import_ipaddr.distinctRemoteAddr)(addrStr);
|
|
41
41
|
if (type2 === void 0) {
|
|
42
42
|
throw new TypeError(`Invalid rule: ${rule}`);
|
|
43
43
|
}
|
|
44
44
|
const isIPv4 = type2 === "IPv4";
|
|
45
|
-
const prefix = parseInt(
|
|
45
|
+
const prefix = parseInt(separatedRule[1]);
|
|
46
46
|
if (isIPv4 ? prefix === 32 : prefix === 128) {
|
|
47
47
|
rule = addrStr;
|
|
48
48
|
} else {
|
|
@@ -32,7 +32,8 @@ const createRenderer = (c, Layout, component, options) => (children, props) => {
|
|
|
32
32
|
const currentLayout = component ? (0, import_jsx.jsx)(
|
|
33
33
|
(props2) => component(props2, c),
|
|
34
34
|
{
|
|
35
|
-
|
|
35
|
+
Layout,
|
|
36
|
+
...props
|
|
36
37
|
},
|
|
37
38
|
children
|
|
38
39
|
) : children;
|
|
@@ -40,17 +40,19 @@ const time = (start) => {
|
|
|
40
40
|
};
|
|
41
41
|
const colorStatus = (status) => {
|
|
42
42
|
const colorEnabled = (0, import_color.getColorEnabled)();
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
43
|
+
if (colorEnabled) {
|
|
44
|
+
switch (status / 100 | 0) {
|
|
45
|
+
case 5:
|
|
46
|
+
return `\x1B[31m${status}\x1B[0m`;
|
|
47
|
+
case 4:
|
|
48
|
+
return `\x1B[33m${status}\x1B[0m`;
|
|
49
|
+
case 3:
|
|
50
|
+
return `\x1B[36m${status}\x1B[0m`;
|
|
51
|
+
case 2:
|
|
52
|
+
return `\x1B[32m${status}\x1B[0m`;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return `${status}`;
|
|
54
56
|
};
|
|
55
57
|
function log(fn, prefix, method, path, status = 0, elapsed) {
|
|
56
58
|
const out = prefix === "<--" /* Incoming */ ? `${prefix} ${method} ${path}` : `${prefix} ${method} ${path} ${colorStatus(status)} ${elapsed}`;
|
|
@@ -34,13 +34,11 @@ const getTime = () => {
|
|
|
34
34
|
};
|
|
35
35
|
const timing = (config) => {
|
|
36
36
|
const options = {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
crossOrigin: false
|
|
43
|
-
},
|
|
37
|
+
total: true,
|
|
38
|
+
enabled: true,
|
|
39
|
+
totalDescription: "Total Response Time",
|
|
40
|
+
autoEnd: true,
|
|
41
|
+
crossOrigin: false,
|
|
44
42
|
...config
|
|
45
43
|
};
|
|
46
44
|
return async function timing2(c, next) {
|
package/dist/cjs/request.js
CHANGED
|
@@ -23,6 +23,7 @@ __export(request_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(request_exports);
|
|
24
24
|
var import_body = require("./utils/body");
|
|
25
25
|
var import_url = require("./utils/url");
|
|
26
|
+
const tryDecodeURIComponent = (str) => (0, import_url.tryDecode)(str, import_url.decodeURIComponent_);
|
|
26
27
|
class HonoRequest {
|
|
27
28
|
raw;
|
|
28
29
|
#validatedData;
|
|
@@ -37,25 +38,25 @@ class HonoRequest {
|
|
|
37
38
|
this.#validatedData = {};
|
|
38
39
|
}
|
|
39
40
|
param(key) {
|
|
40
|
-
return key ? this
|
|
41
|
+
return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
|
|
41
42
|
}
|
|
42
|
-
getDecodedParam(key) {
|
|
43
|
+
#getDecodedParam(key) {
|
|
43
44
|
const paramKey = this.#matchResult[0][this.routeIndex][1][key];
|
|
44
|
-
const param = this
|
|
45
|
-
return param ? /\%/.test(param) ? (
|
|
45
|
+
const param = this.#getParamValue(paramKey);
|
|
46
|
+
return param ? /\%/.test(param) ? tryDecodeURIComponent(param) : param : void 0;
|
|
46
47
|
}
|
|
47
|
-
getAllDecodedParams() {
|
|
48
|
+
#getAllDecodedParams() {
|
|
48
49
|
const decoded = {};
|
|
49
50
|
const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
|
|
50
51
|
for (const key of keys) {
|
|
51
|
-
const value = this
|
|
52
|
+
const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
|
|
52
53
|
if (value && typeof value === "string") {
|
|
53
|
-
decoded[key] = /\%/.test(value) ? (
|
|
54
|
+
decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value;
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
return decoded;
|
|
57
58
|
}
|
|
58
|
-
getParamValue(paramKey) {
|
|
59
|
+
#getParamValue(paramKey) {
|
|
59
60
|
return this.#matchResult[1] ? this.#matchResult[1][paramKey] : paramKey;
|
|
60
61
|
}
|
|
61
62
|
query(key) {
|
|
@@ -77,7 +78,7 @@ class HonoRequest {
|
|
|
77
78
|
async parseBody(options) {
|
|
78
79
|
return this.bodyCache.parsedBody ??= await (0, import_body.parseBody)(this, options);
|
|
79
80
|
}
|
|
80
|
-
cachedBody = (key) => {
|
|
81
|
+
#cachedBody = (key) => {
|
|
81
82
|
const { bodyCache, raw } = this;
|
|
82
83
|
const cachedBody = bodyCache[key];
|
|
83
84
|
if (cachedBody) {
|
|
@@ -95,19 +96,19 @@ class HonoRequest {
|
|
|
95
96
|
return bodyCache[key] = raw[key]();
|
|
96
97
|
};
|
|
97
98
|
json() {
|
|
98
|
-
return this
|
|
99
|
+
return this.#cachedBody("json");
|
|
99
100
|
}
|
|
100
101
|
text() {
|
|
101
|
-
return this
|
|
102
|
+
return this.#cachedBody("text");
|
|
102
103
|
}
|
|
103
104
|
arrayBuffer() {
|
|
104
|
-
return this
|
|
105
|
+
return this.#cachedBody("arrayBuffer");
|
|
105
106
|
}
|
|
106
107
|
blob() {
|
|
107
|
-
return this
|
|
108
|
+
return this.#cachedBody("blob");
|
|
108
109
|
}
|
|
109
110
|
formData() {
|
|
110
|
-
return this
|
|
111
|
+
return this.#cachedBody("formData");
|
|
111
112
|
}
|
|
112
113
|
addValidatedData(target, data) {
|
|
113
114
|
this.#validatedData[target] = data;
|
|
@@ -24,7 +24,7 @@ module.exports = __toCommonJS(router_exports);
|
|
|
24
24
|
var import_router = require("../../router");
|
|
25
25
|
class PatternRouter {
|
|
26
26
|
name = "PatternRouter";
|
|
27
|
-
routes = [];
|
|
27
|
+
#routes = [];
|
|
28
28
|
add(method, path, handler) {
|
|
29
29
|
const endsWithWildcard = path[path.length - 1] === "*";
|
|
30
30
|
if (endsWithWildcard) {
|
|
@@ -46,12 +46,12 @@ class PatternRouter {
|
|
|
46
46
|
} catch {
|
|
47
47
|
throw new import_router.UnsupportedPathError();
|
|
48
48
|
}
|
|
49
|
-
this
|
|
49
|
+
this.#routes.push([re, method, handler]);
|
|
50
50
|
}
|
|
51
51
|
match(method, path) {
|
|
52
52
|
const handlers = [];
|
|
53
|
-
for (let i = 0, len = this
|
|
54
|
-
const [pattern, routeMethod, handler] = this
|
|
53
|
+
for (let i = 0, len = this.#routes.length; i < len; i++) {
|
|
54
|
+
const [pattern, routeMethod, handler] = this.#routes[i];
|
|
55
55
|
if (routeMethod === method || routeMethod === import_router.METHOD_NAME_ALL) {
|
|
56
56
|
const match = pattern.exec(path);
|
|
57
57
|
if (match) {
|
|
@@ -173,7 +173,7 @@ class RegExpRouter {
|
|
|
173
173
|
}
|
|
174
174
|
match(method, path) {
|
|
175
175
|
clearWildcardRegExpCache();
|
|
176
|
-
const matchers = this
|
|
176
|
+
const matchers = this.#buildAllMatchers();
|
|
177
177
|
this.match = (method2, path2) => {
|
|
178
178
|
const matcher = matchers[method2] || matchers[import_router.METHOD_NAME_ALL];
|
|
179
179
|
const staticMatch = matcher[2][path2];
|
|
@@ -189,15 +189,15 @@ class RegExpRouter {
|
|
|
189
189
|
};
|
|
190
190
|
return this.match(method, path);
|
|
191
191
|
}
|
|
192
|
-
buildAllMatchers() {
|
|
192
|
+
#buildAllMatchers() {
|
|
193
193
|
const matchers = /* @__PURE__ */ Object.create(null);
|
|
194
|
-
|
|
195
|
-
matchers[method] ||= this
|
|
194
|
+
Object.keys(this.routes).concat(Object.keys(this.middleware)).forEach((method) => {
|
|
195
|
+
matchers[method] ||= this.#buildMatcher(method);
|
|
196
196
|
});
|
|
197
197
|
this.middleware = this.routes = void 0;
|
|
198
198
|
return matchers;
|
|
199
199
|
}
|
|
200
|
-
buildMatcher(method) {
|
|
200
|
+
#buildMatcher(method) {
|
|
201
201
|
const routes = [];
|
|
202
202
|
let hasOwnRoute = method === import_router.METHOD_NAME_ALL;
|
|
203
203
|
[this.middleware, this.routes].forEach((r) => {
|
|
@@ -63,11 +63,11 @@ class Trie {
|
|
|
63
63
|
const indexReplacementMap = [];
|
|
64
64
|
const paramReplacementMap = [];
|
|
65
65
|
regexp = regexp.replace(/#(\d+)|@(\d+)|\.\*\$/g, (_, handlerIndex, paramIndex) => {
|
|
66
|
-
if (
|
|
66
|
+
if (handlerIndex !== void 0) {
|
|
67
67
|
indexReplacementMap[++captureIndex] = Number(handlerIndex);
|
|
68
68
|
return "$()";
|
|
69
69
|
}
|
|
70
|
-
if (
|
|
70
|
+
if (paramIndex !== void 0) {
|
|
71
71
|
paramReplacementMap[Number(paramIndex)] = ++captureIndex;
|
|
72
72
|
return "";
|
|
73
73
|
}
|
|
@@ -75,7 +75,7 @@ class Node {
|
|
|
75
75
|
curNode.methods.push(m);
|
|
76
76
|
return curNode;
|
|
77
77
|
}
|
|
78
|
-
gHSets(node, method, nodeParams, params) {
|
|
78
|
+
#gHSets(node, method, nodeParams, params) {
|
|
79
79
|
const handlerSets = [];
|
|
80
80
|
for (let i = 0, len = node.methods.length; i < len; i++) {
|
|
81
81
|
const m = node.methods[i];
|
|
@@ -112,10 +112,10 @@ class Node {
|
|
|
112
112
|
if (isLast) {
|
|
113
113
|
if (nextNode.children["*"]) {
|
|
114
114
|
handlerSets.push(
|
|
115
|
-
...this
|
|
115
|
+
...this.#gHSets(nextNode.children["*"], method, node.params, /* @__PURE__ */ Object.create(null))
|
|
116
116
|
);
|
|
117
117
|
}
|
|
118
|
-
handlerSets.push(...this
|
|
118
|
+
handlerSets.push(...this.#gHSets(nextNode, method, node.params, /* @__PURE__ */ Object.create(null)));
|
|
119
119
|
} else {
|
|
120
120
|
tempNodes.push(nextNode);
|
|
121
121
|
}
|
|
@@ -126,7 +126,7 @@ class Node {
|
|
|
126
126
|
if (pattern === "*") {
|
|
127
127
|
const astNode = node.children["*"];
|
|
128
128
|
if (astNode) {
|
|
129
|
-
handlerSets.push(...this
|
|
129
|
+
handlerSets.push(...this.#gHSets(astNode, method, node.params, /* @__PURE__ */ Object.create(null)));
|
|
130
130
|
tempNodes.push(astNode);
|
|
131
131
|
}
|
|
132
132
|
continue;
|
|
@@ -139,16 +139,18 @@ class Node {
|
|
|
139
139
|
const restPathString = parts.slice(i).join("/");
|
|
140
140
|
if (matcher instanceof RegExp && matcher.test(restPathString)) {
|
|
141
141
|
params[name] = restPathString;
|
|
142
|
-
handlerSets.push(...this
|
|
142
|
+
handlerSets.push(...this.#gHSets(child, method, node.params, params));
|
|
143
143
|
continue;
|
|
144
144
|
}
|
|
145
145
|
if (matcher === true || matcher.test(part)) {
|
|
146
146
|
if (typeof key === "string") {
|
|
147
147
|
params[name] = part;
|
|
148
148
|
if (isLast) {
|
|
149
|
-
handlerSets.push(...this
|
|
149
|
+
handlerSets.push(...this.#gHSets(child, method, params, node.params));
|
|
150
150
|
if (child.children["*"]) {
|
|
151
|
-
handlerSets.push(
|
|
151
|
+
handlerSets.push(
|
|
152
|
+
...this.#gHSets(child.children["*"], method, params, node.params)
|
|
153
|
+
);
|
|
152
154
|
}
|
|
153
155
|
} else {
|
|
154
156
|
child.params = params;
|
package/dist/cjs/utils/color.js
CHANGED
|
@@ -23,7 +23,7 @@ __export(color_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(color_exports);
|
|
24
24
|
function getColorEnabled() {
|
|
25
25
|
const { process, Deno } = globalThis;
|
|
26
|
-
const isNoColor = typeof Deno?.noColor === "boolean" ? Deno.noColor :
|
|
26
|
+
const isNoColor = typeof Deno?.noColor === "boolean" ? Deno.noColor : process !== void 0 ? "NO_COLOR" in process?.env : false;
|
|
27
27
|
return !isNoColor;
|
|
28
28
|
}
|
|
29
29
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/cjs/utils/cookie.js
CHANGED
|
@@ -50,16 +50,20 @@ const verifySignature = async (base64Signature, value, secret) => {
|
|
|
50
50
|
const validCookieNameRegEx = /^[\w!#$%&'*.^`|~+-]+$/;
|
|
51
51
|
const validCookieValueRegEx = /^[ !#-:<-[\]-~]*$/;
|
|
52
52
|
const parse = (cookie, name) => {
|
|
53
|
+
if (name && cookie.indexOf(name) === -1) {
|
|
54
|
+
return {};
|
|
55
|
+
}
|
|
53
56
|
const pairs = cookie.trim().split(";");
|
|
54
|
-
|
|
57
|
+
const parsedCookie = {};
|
|
58
|
+
for (let pairStr of pairs) {
|
|
55
59
|
pairStr = pairStr.trim();
|
|
56
60
|
const valueStartPos = pairStr.indexOf("=");
|
|
57
61
|
if (valueStartPos === -1) {
|
|
58
|
-
|
|
62
|
+
continue;
|
|
59
63
|
}
|
|
60
64
|
const cookieName = pairStr.substring(0, valueStartPos).trim();
|
|
61
65
|
if (name && name !== cookieName || !validCookieNameRegEx.test(cookieName)) {
|
|
62
|
-
|
|
66
|
+
continue;
|
|
63
67
|
}
|
|
64
68
|
let cookieValue = pairStr.substring(valueStartPos + 1).trim();
|
|
65
69
|
if (cookieValue.startsWith('"') && cookieValue.endsWith('"')) {
|
|
@@ -67,9 +71,12 @@ const parse = (cookie, name) => {
|
|
|
67
71
|
}
|
|
68
72
|
if (validCookieValueRegEx.test(cookieValue)) {
|
|
69
73
|
parsedCookie[cookieName] = (0, import_url.decodeURIComponent_)(cookieValue);
|
|
74
|
+
if (name) {
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
70
77
|
}
|
|
71
|
-
|
|
72
|
-
|
|
78
|
+
}
|
|
79
|
+
return parsedCookie;
|
|
73
80
|
};
|
|
74
81
|
const parseSigned = async (cookie, secret, name) => {
|
|
75
82
|
const parsedCookie = {};
|
|
@@ -111,7 +118,7 @@ const _serialize = (name, value, opt = {}) => {
|
|
|
111
118
|
"Cookies Max-Age SHOULD NOT be greater than 400 days (34560000 seconds) in duration."
|
|
112
119
|
);
|
|
113
120
|
}
|
|
114
|
-
cookie += `; Max-Age=${
|
|
121
|
+
cookie += `; Max-Age=${opt.maxAge | 0}`;
|
|
115
122
|
}
|
|
116
123
|
if (opt.domain && opt.prefix !== "host") {
|
|
117
124
|
cookie += `; Domain=${opt.domain}`;
|
package/dist/cjs/utils/crypto.js
CHANGED
|
@@ -41,15 +41,6 @@ const md5 = async (data) => {
|
|
|
41
41
|
};
|
|
42
42
|
const createHash = async (data, algorithm) => {
|
|
43
43
|
let sourceBuffer;
|
|
44
|
-
if (data instanceof ReadableStream) {
|
|
45
|
-
let body = "";
|
|
46
|
-
const reader = data.getReader();
|
|
47
|
-
await reader?.read().then(async (chuck) => {
|
|
48
|
-
const value = await createHash(chuck.value || "", algorithm);
|
|
49
|
-
body += value;
|
|
50
|
-
});
|
|
51
|
-
return body;
|
|
52
|
-
}
|
|
53
44
|
if (ArrayBuffer.isView(data) || data instanceof ArrayBuffer) {
|
|
54
45
|
sourceBuffer = data;
|
|
55
46
|
} else {
|
|
@@ -0,0 +1,16 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var headers_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(headers_exports);
|
|
@@ -56,7 +56,7 @@ const verify = async (token, publicKey, alg = "HS256") => {
|
|
|
56
56
|
if (!isTokenHeader(header)) {
|
|
57
57
|
throw new import_types.JwtHeaderInvalid(header);
|
|
58
58
|
}
|
|
59
|
-
const now =
|
|
59
|
+
const now = Date.now() / 1e3 | 0;
|
|
60
60
|
if (payload.nbf && payload.nbf > now) {
|
|
61
61
|
throw new import_types.JwtTokenNotBefore(token);
|
|
62
62
|
}
|
package/dist/cjs/utils/mime.js
CHANGED
|
@@ -42,7 +42,7 @@ const getExtension = (mimeType) => {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
|
-
const
|
|
45
|
+
const _baseMimes = {
|
|
46
46
|
aac: "audio/aac",
|
|
47
47
|
avi: "video/x-msvideo",
|
|
48
48
|
avif: "image/avif",
|
|
@@ -99,6 +99,7 @@ const baseMimes = {
|
|
|
99
99
|
gltf: "model/gltf+json",
|
|
100
100
|
glb: "model/gltf-binary"
|
|
101
101
|
};
|
|
102
|
+
const baseMimes = _baseMimes;
|
|
102
103
|
// Annotate the CommonJS export names for ESM import in node:
|
|
103
104
|
0 && (module.exports = {
|
|
104
105
|
getExtension,
|