hono 4.6.8 → 4.6.10
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/websocket.js +34 -39
- package/dist/adapter/deno/serve-static.js +5 -1
- package/dist/adapter/lambda-edge/handler.js +1 -1
- package/dist/cjs/adapter/cloudflare-workers/websocket.js +34 -39
- package/dist/cjs/adapter/deno/serve-static.js +5 -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/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/hono-base.js +38 -41
- 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/combine/index.js +15 -9
- 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/linear-router/router.js +4 -4
- package/dist/cjs/router/pattern-router/router.js +4 -4
- package/dist/cjs/router/reg-exp-router/node.js +18 -18
- package/dist/cjs/router/reg-exp-router/router.js +13 -12
- package/dist/cjs/router/reg-exp-router/trie.js +6 -6
- package/dist/cjs/router/smart-router/router.js +12 -11
- package/dist/cjs/router/trie-router/node.js +53 -47
- package/dist/cjs/router/trie-router/router.js +5 -5
- 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/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/html/index.js +1 -1
- package/dist/helper/ssg/ssg.js +2 -2
- package/dist/helper/ssg/utils.js +2 -2
- package/dist/hono-base.js +38 -41
- 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/combine/index.js +15 -9
- 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/linear-router/router.js +4 -4
- package/dist/router/pattern-router/router.js +4 -4
- package/dist/router/reg-exp-router/node.js +18 -18
- package/dist/router/reg-exp-router/router.js +13 -12
- package/dist/router/reg-exp-router/trie.js +6 -6
- package/dist/router/smart-router/router.js +12 -11
- package/dist/router/trie-router/node.js +53 -47
- package/dist/router/trie-router/router.js +5 -5
- package/dist/types/adapter/cloudflare-workers/websocket.d.ts +2 -2
- package/dist/types/adapter/deno/websocket.d.ts +1 -20
- package/dist/types/adapter/service-worker/index.d.ts +1 -1
- package/dist/types/compose.d.ts +5 -2
- package/dist/types/context.d.ts +1 -1
- package/dist/types/helper/websocket/index.d.ts +1 -1
- 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/router/linear-router/router.d.ts +0 -5
- package/dist/types/router/reg-exp-router/node.d.ts +0 -3
- package/dist/types/router/reg-exp-router/router.d.ts +0 -7
- package/dist/types/router/reg-exp-router/trie.d.ts +1 -4
- package/dist/types/router/smart-router/router.d.ts +3 -7
- package/dist/types/router/trie-router/node.d.ts +0 -12
- package/dist/types/router/trie-router/router.d.ts +0 -2
- package/dist/types/utils/body.d.ts +2 -2
- package/dist/types/utils/crypto.d.ts +2 -1
- 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/jwt/jwt.js +1 -1
- package/dist/utils/mime.js +2 -1
- package/dist/utils/url.js +7 -5
- package/package.json +20 -12
|
@@ -24,18 +24,18 @@ function compareKey(a, b) {
|
|
|
24
24
|
return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
|
|
25
25
|
}
|
|
26
26
|
var Node = class {
|
|
27
|
-
index;
|
|
28
|
-
varIndex;
|
|
29
|
-
children = /* @__PURE__ */ Object.create(null);
|
|
27
|
+
#index;
|
|
28
|
+
#varIndex;
|
|
29
|
+
#children = /* @__PURE__ */ Object.create(null);
|
|
30
30
|
insert(tokens, index, paramMap, context, pathErrorCheckOnly) {
|
|
31
31
|
if (tokens.length === 0) {
|
|
32
|
-
if (this
|
|
32
|
+
if (this.#index !== void 0) {
|
|
33
33
|
throw PATH_ERROR;
|
|
34
34
|
}
|
|
35
35
|
if (pathErrorCheckOnly) {
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
|
-
this
|
|
38
|
+
this.#index = index;
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
41
41
|
const [token, ...restTokens] = tokens;
|
|
@@ -50,9 +50,9 @@ var Node = class {
|
|
|
50
50
|
throw PATH_ERROR;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
node = this
|
|
53
|
+
node = this.#children[regexpStr];
|
|
54
54
|
if (!node) {
|
|
55
|
-
if (Object.keys(this
|
|
55
|
+
if (Object.keys(this.#children).some(
|
|
56
56
|
(k) => k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
|
|
57
57
|
)) {
|
|
58
58
|
throw PATH_ERROR;
|
|
@@ -60,18 +60,18 @@ var Node = class {
|
|
|
60
60
|
if (pathErrorCheckOnly) {
|
|
61
61
|
return;
|
|
62
62
|
}
|
|
63
|
-
node = this
|
|
63
|
+
node = this.#children[regexpStr] = new Node();
|
|
64
64
|
if (name !== "") {
|
|
65
|
-
node
|
|
65
|
+
node.#varIndex = context.varIndex++;
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
if (!pathErrorCheckOnly && name !== "") {
|
|
69
|
-
paramMap.push([name, node
|
|
69
|
+
paramMap.push([name, node.#varIndex]);
|
|
70
70
|
}
|
|
71
71
|
} else {
|
|
72
|
-
node = this
|
|
72
|
+
node = this.#children[token];
|
|
73
73
|
if (!node) {
|
|
74
|
-
if (Object.keys(this
|
|
74
|
+
if (Object.keys(this.#children).some(
|
|
75
75
|
(k) => k.length > 1 && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
|
|
76
76
|
)) {
|
|
77
77
|
throw PATH_ERROR;
|
|
@@ -79,19 +79,19 @@ var Node = class {
|
|
|
79
79
|
if (pathErrorCheckOnly) {
|
|
80
80
|
return;
|
|
81
81
|
}
|
|
82
|
-
node = this
|
|
82
|
+
node = this.#children[token] = new Node();
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
node.insert(restTokens, index, paramMap, context, pathErrorCheckOnly);
|
|
86
86
|
}
|
|
87
87
|
buildRegExpStr() {
|
|
88
|
-
const childKeys = Object.keys(this
|
|
88
|
+
const childKeys = Object.keys(this.#children).sort(compareKey);
|
|
89
89
|
const strList = childKeys.map((k) => {
|
|
90
|
-
const c = this
|
|
91
|
-
return (typeof c
|
|
90
|
+
const c = this.#children[k];
|
|
91
|
+
return (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr();
|
|
92
92
|
});
|
|
93
|
-
if (typeof this
|
|
94
|
-
strList.unshift(`#${this
|
|
93
|
+
if (typeof this.#index === "number") {
|
|
94
|
+
strList.unshift(`#${this.#index}`);
|
|
95
95
|
}
|
|
96
96
|
if (strList.length === 0) {
|
|
97
97
|
return "";
|
|
@@ -91,14 +91,15 @@ function findMiddleware(middleware, path) {
|
|
|
91
91
|
}
|
|
92
92
|
var RegExpRouter = class {
|
|
93
93
|
name = "RegExpRouter";
|
|
94
|
-
middleware;
|
|
95
|
-
routes;
|
|
94
|
+
#middleware;
|
|
95
|
+
#routes;
|
|
96
96
|
constructor() {
|
|
97
|
-
this
|
|
98
|
-
this
|
|
97
|
+
this.#middleware = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
|
|
98
|
+
this.#routes = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
|
|
99
99
|
}
|
|
100
100
|
add(method, path, handler) {
|
|
101
|
-
const
|
|
101
|
+
const middleware = this.#middleware;
|
|
102
|
+
const routes = this.#routes;
|
|
102
103
|
if (!middleware || !routes) {
|
|
103
104
|
throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
104
105
|
}
|
|
@@ -155,7 +156,7 @@ var RegExpRouter = class {
|
|
|
155
156
|
}
|
|
156
157
|
match(method, path) {
|
|
157
158
|
clearWildcardRegExpCache();
|
|
158
|
-
const matchers = this
|
|
159
|
+
const matchers = this.#buildAllMatchers();
|
|
159
160
|
this.match = (method2, path2) => {
|
|
160
161
|
const matcher = matchers[method2] || matchers[METHOD_NAME_ALL];
|
|
161
162
|
const staticMatch = matcher[2][path2];
|
|
@@ -171,18 +172,18 @@ var RegExpRouter = class {
|
|
|
171
172
|
};
|
|
172
173
|
return this.match(method, path);
|
|
173
174
|
}
|
|
174
|
-
buildAllMatchers() {
|
|
175
|
+
#buildAllMatchers() {
|
|
175
176
|
const matchers = /* @__PURE__ */ Object.create(null);
|
|
176
|
-
|
|
177
|
-
matchers[method] ||= this
|
|
177
|
+
Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
|
|
178
|
+
matchers[method] ||= this.#buildMatcher(method);
|
|
178
179
|
});
|
|
179
|
-
this
|
|
180
|
+
this.#middleware = this.#routes = void 0;
|
|
180
181
|
return matchers;
|
|
181
182
|
}
|
|
182
|
-
buildMatcher(method) {
|
|
183
|
+
#buildMatcher(method) {
|
|
183
184
|
const routes = [];
|
|
184
185
|
let hasOwnRoute = method === METHOD_NAME_ALL;
|
|
185
|
-
[this
|
|
186
|
+
[this.#middleware, this.#routes].forEach((r) => {
|
|
186
187
|
const ownRoute = r[method] ? Object.keys(r[method]).map((path) => [path, r[method][path]]) : [];
|
|
187
188
|
if (ownRoute.length !== 0) {
|
|
188
189
|
hasOwnRoute ||= true;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// src/router/reg-exp-router/trie.ts
|
|
2
2
|
import { Node } from "./node.js";
|
|
3
3
|
var Trie = class {
|
|
4
|
-
context = { varIndex: 0 };
|
|
5
|
-
root = new Node();
|
|
4
|
+
#context = { varIndex: 0 };
|
|
5
|
+
#root = new Node();
|
|
6
6
|
insert(path, index, pathErrorCheckOnly) {
|
|
7
7
|
const paramAssoc = [];
|
|
8
8
|
const groups = [];
|
|
@@ -29,11 +29,11 @@ var Trie = class {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
this
|
|
32
|
+
this.#root.insert(tokens, index, paramAssoc, this.#context, pathErrorCheckOnly);
|
|
33
33
|
return paramAssoc;
|
|
34
34
|
}
|
|
35
35
|
buildRegExp() {
|
|
36
|
-
let regexp = this
|
|
36
|
+
let regexp = this.#root.buildRegExpStr();
|
|
37
37
|
if (regexp === "") {
|
|
38
38
|
return [/^$/, [], []];
|
|
39
39
|
}
|
|
@@ -41,11 +41,11 @@ var Trie = class {
|
|
|
41
41
|
const indexReplacementMap = [];
|
|
42
42
|
const paramReplacementMap = [];
|
|
43
43
|
regexp = regexp.replace(/#(\d+)|@(\d+)|\.\*\$/g, (_, handlerIndex, paramIndex) => {
|
|
44
|
-
if (
|
|
44
|
+
if (handlerIndex !== void 0) {
|
|
45
45
|
indexReplacementMap[++captureIndex] = Number(handlerIndex);
|
|
46
46
|
return "$()";
|
|
47
47
|
}
|
|
48
|
-
if (
|
|
48
|
+
if (paramIndex !== void 0) {
|
|
49
49
|
paramReplacementMap[Number(paramIndex)] = ++captureIndex;
|
|
50
50
|
return "";
|
|
51
51
|
}
|
|
@@ -2,22 +2,23 @@
|
|
|
2
2
|
import { MESSAGE_MATCHER_IS_ALREADY_BUILT, UnsupportedPathError } from "../../router.js";
|
|
3
3
|
var SmartRouter = class {
|
|
4
4
|
name = "SmartRouter";
|
|
5
|
-
routers = [];
|
|
6
|
-
routes = [];
|
|
5
|
+
#routers = [];
|
|
6
|
+
#routes = [];
|
|
7
7
|
constructor(init) {
|
|
8
|
-
|
|
8
|
+
this.#routers = init.routers;
|
|
9
9
|
}
|
|
10
10
|
add(method, path, handler) {
|
|
11
|
-
if (!this
|
|
11
|
+
if (!this.#routes) {
|
|
12
12
|
throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
13
13
|
}
|
|
14
|
-
this
|
|
14
|
+
this.#routes.push([method, path, handler]);
|
|
15
15
|
}
|
|
16
16
|
match(method, path) {
|
|
17
|
-
if (!this
|
|
17
|
+
if (!this.#routes) {
|
|
18
18
|
throw new Error("Fatal error");
|
|
19
19
|
}
|
|
20
|
-
const
|
|
20
|
+
const routers = this.#routers;
|
|
21
|
+
const routes = this.#routes;
|
|
21
22
|
const len = routers.length;
|
|
22
23
|
let i = 0;
|
|
23
24
|
let res;
|
|
@@ -35,8 +36,8 @@ var SmartRouter = class {
|
|
|
35
36
|
throw e;
|
|
36
37
|
}
|
|
37
38
|
this.match = router.match.bind(router);
|
|
38
|
-
this
|
|
39
|
-
this
|
|
39
|
+
this.#routers = [router];
|
|
40
|
+
this.#routes = void 0;
|
|
40
41
|
break;
|
|
41
42
|
}
|
|
42
43
|
if (i === len) {
|
|
@@ -46,10 +47,10 @@ var SmartRouter = class {
|
|
|
46
47
|
return res;
|
|
47
48
|
}
|
|
48
49
|
get activeRouter() {
|
|
49
|
-
if (this
|
|
50
|
+
if (this.#routes || this.#routers.length !== 1) {
|
|
50
51
|
throw new Error("No active router has been determined yet.");
|
|
51
52
|
}
|
|
52
|
-
return this
|
|
53
|
+
return this.#routers[0];
|
|
53
54
|
}
|
|
54
55
|
};
|
|
55
56
|
export {
|
|
@@ -2,63 +2,60 @@
|
|
|
2
2
|
import { METHOD_NAME_ALL } from "../../router.js";
|
|
3
3
|
import { getPattern, splitPath, splitRoutingPath } from "../../utils/url.js";
|
|
4
4
|
var Node = class {
|
|
5
|
-
methods;
|
|
6
|
-
children;
|
|
7
|
-
patterns;
|
|
8
|
-
order = 0;
|
|
9
|
-
params = /* @__PURE__ */ Object.create(null);
|
|
5
|
+
#methods;
|
|
6
|
+
#children;
|
|
7
|
+
#patterns;
|
|
8
|
+
#order = 0;
|
|
9
|
+
#params = /* @__PURE__ */ Object.create(null);
|
|
10
10
|
constructor(method, handler, children) {
|
|
11
|
-
this
|
|
12
|
-
this
|
|
11
|
+
this.#children = children || /* @__PURE__ */ Object.create(null);
|
|
12
|
+
this.#methods = [];
|
|
13
13
|
if (method && handler) {
|
|
14
14
|
const m = /* @__PURE__ */ Object.create(null);
|
|
15
15
|
m[method] = { handler, possibleKeys: [], score: 0 };
|
|
16
|
-
this
|
|
16
|
+
this.#methods = [m];
|
|
17
17
|
}
|
|
18
|
-
this
|
|
18
|
+
this.#patterns = [];
|
|
19
19
|
}
|
|
20
20
|
insert(method, path, handler) {
|
|
21
|
-
this
|
|
21
|
+
this.#order = ++this.#order;
|
|
22
22
|
let curNode = this;
|
|
23
23
|
const parts = splitRoutingPath(path);
|
|
24
24
|
const possibleKeys = [];
|
|
25
25
|
for (let i = 0, len = parts.length; i < len; i++) {
|
|
26
26
|
const p = parts[i];
|
|
27
|
-
if (Object.keys(curNode
|
|
28
|
-
curNode = curNode
|
|
27
|
+
if (Object.keys(curNode.#children).includes(p)) {
|
|
28
|
+
curNode = curNode.#children[p];
|
|
29
29
|
const pattern2 = getPattern(p);
|
|
30
30
|
if (pattern2) {
|
|
31
31
|
possibleKeys.push(pattern2[1]);
|
|
32
32
|
}
|
|
33
33
|
continue;
|
|
34
34
|
}
|
|
35
|
-
curNode
|
|
35
|
+
curNode.#children[p] = new Node();
|
|
36
36
|
const pattern = getPattern(p);
|
|
37
37
|
if (pattern) {
|
|
38
|
-
curNode
|
|
38
|
+
curNode.#patterns.push(pattern);
|
|
39
39
|
possibleKeys.push(pattern[1]);
|
|
40
40
|
}
|
|
41
|
-
curNode = curNode
|
|
42
|
-
}
|
|
43
|
-
if (!curNode.methods.length) {
|
|
44
|
-
curNode.methods = [];
|
|
41
|
+
curNode = curNode.#children[p];
|
|
45
42
|
}
|
|
46
43
|
const m = /* @__PURE__ */ Object.create(null);
|
|
47
44
|
const handlerSet = {
|
|
48
45
|
handler,
|
|
49
46
|
possibleKeys: possibleKeys.filter((v, i, a) => a.indexOf(v) === i),
|
|
50
|
-
score: this
|
|
47
|
+
score: this.#order
|
|
51
48
|
};
|
|
52
49
|
m[method] = handlerSet;
|
|
53
|
-
curNode
|
|
50
|
+
curNode.#methods.push(m);
|
|
54
51
|
return curNode;
|
|
55
52
|
}
|
|
56
|
-
|
|
53
|
+
#getHandlerSets(node, method, nodeParams, params) {
|
|
57
54
|
const handlerSets = [];
|
|
58
|
-
for (let i = 0, len = node
|
|
59
|
-
const m = node
|
|
55
|
+
for (let i = 0, len = node.#methods.length; i < len; i++) {
|
|
56
|
+
const m = node.#methods[i];
|
|
60
57
|
const handlerSet = m[method] || m[METHOD_NAME_ALL];
|
|
61
|
-
const processedSet =
|
|
58
|
+
const processedSet = {};
|
|
62
59
|
if (handlerSet !== void 0) {
|
|
63
60
|
handlerSet.params = /* @__PURE__ */ Object.create(null);
|
|
64
61
|
for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
|
|
@@ -74,7 +71,7 @@ var Node = class {
|
|
|
74
71
|
}
|
|
75
72
|
search(method, path) {
|
|
76
73
|
const handlerSets = [];
|
|
77
|
-
this
|
|
74
|
+
this.#params = /* @__PURE__ */ Object.create(null);
|
|
78
75
|
const curNode = this;
|
|
79
76
|
let curNodes = [curNode];
|
|
80
77
|
const parts = splitPath(path);
|
|
@@ -84,27 +81,36 @@ var Node = class {
|
|
|
84
81
|
const tempNodes = [];
|
|
85
82
|
for (let j = 0, len2 = curNodes.length; j < len2; j++) {
|
|
86
83
|
const node = curNodes[j];
|
|
87
|
-
const nextNode = node
|
|
84
|
+
const nextNode = node.#children[part];
|
|
88
85
|
if (nextNode) {
|
|
89
|
-
nextNode
|
|
86
|
+
nextNode.#params = node.#params;
|
|
90
87
|
if (isLast) {
|
|
91
|
-
if (nextNode
|
|
88
|
+
if (nextNode.#children["*"]) {
|
|
92
89
|
handlerSets.push(
|
|
93
|
-
...this
|
|
90
|
+
...this.#getHandlerSets(
|
|
91
|
+
nextNode.#children["*"],
|
|
92
|
+
method,
|
|
93
|
+
node.#params,
|
|
94
|
+
/* @__PURE__ */ Object.create(null)
|
|
95
|
+
)
|
|
94
96
|
);
|
|
95
97
|
}
|
|
96
|
-
handlerSets.push(
|
|
98
|
+
handlerSets.push(
|
|
99
|
+
...this.#getHandlerSets(nextNode, method, node.#params, /* @__PURE__ */ Object.create(null))
|
|
100
|
+
);
|
|
97
101
|
} else {
|
|
98
102
|
tempNodes.push(nextNode);
|
|
99
103
|
}
|
|
100
104
|
}
|
|
101
|
-
for (let k = 0, len3 = node
|
|
102
|
-
const pattern = node
|
|
103
|
-
const params = { ...node
|
|
105
|
+
for (let k = 0, len3 = node.#patterns.length; k < len3; k++) {
|
|
106
|
+
const pattern = node.#patterns[k];
|
|
107
|
+
const params = { ...node.#params };
|
|
104
108
|
if (pattern === "*") {
|
|
105
|
-
const astNode = node
|
|
109
|
+
const astNode = node.#children["*"];
|
|
106
110
|
if (astNode) {
|
|
107
|
-
handlerSets.push(
|
|
111
|
+
handlerSets.push(
|
|
112
|
+
...this.#getHandlerSets(astNode, method, node.#params, /* @__PURE__ */ Object.create(null))
|
|
113
|
+
);
|
|
108
114
|
tempNodes.push(astNode);
|
|
109
115
|
}
|
|
110
116
|
continue;
|
|
@@ -113,25 +119,25 @@ var Node = class {
|
|
|
113
119
|
continue;
|
|
114
120
|
}
|
|
115
121
|
const [key, name, matcher] = pattern;
|
|
116
|
-
const child = node
|
|
122
|
+
const child = node.#children[key];
|
|
117
123
|
const restPathString = parts.slice(i).join("/");
|
|
118
124
|
if (matcher instanceof RegExp && matcher.test(restPathString)) {
|
|
119
125
|
params[name] = restPathString;
|
|
120
|
-
handlerSets.push(...this
|
|
126
|
+
handlerSets.push(...this.#getHandlerSets(child, method, node.#params, params));
|
|
121
127
|
continue;
|
|
122
128
|
}
|
|
123
129
|
if (matcher === true || matcher.test(part)) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
} else {
|
|
132
|
-
child.params = params;
|
|
133
|
-
tempNodes.push(child);
|
|
130
|
+
params[name] = part;
|
|
131
|
+
if (isLast) {
|
|
132
|
+
handlerSets.push(...this.#getHandlerSets(child, method, params, node.#params));
|
|
133
|
+
if (child.#children["*"]) {
|
|
134
|
+
handlerSets.push(
|
|
135
|
+
...this.#getHandlerSets(child.#children["*"], method, params, node.#params)
|
|
136
|
+
);
|
|
134
137
|
}
|
|
138
|
+
} else {
|
|
139
|
+
child.#params = params;
|
|
140
|
+
tempNodes.push(child);
|
|
135
141
|
}
|
|
136
142
|
}
|
|
137
143
|
}
|
|
@@ -3,22 +3,22 @@ import { checkOptionalParameter } from "../../utils/url.js";
|
|
|
3
3
|
import { Node } from "./node.js";
|
|
4
4
|
var TrieRouter = class {
|
|
5
5
|
name = "TrieRouter";
|
|
6
|
-
node;
|
|
6
|
+
#node;
|
|
7
7
|
constructor() {
|
|
8
|
-
this
|
|
8
|
+
this.#node = new Node();
|
|
9
9
|
}
|
|
10
10
|
add(method, path, handler) {
|
|
11
11
|
const results = checkOptionalParameter(path);
|
|
12
12
|
if (results) {
|
|
13
13
|
for (let i = 0, len = results.length; i < len; i++) {
|
|
14
|
-
this
|
|
14
|
+
this.#node.insert(method, results[i], handler);
|
|
15
15
|
}
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
|
-
this
|
|
18
|
+
this.#node.insert(method, path, handler);
|
|
19
19
|
}
|
|
20
20
|
match(method, path) {
|
|
21
|
-
return this
|
|
21
|
+
return this.#node.search(method, path);
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
24
|
export {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { UpgradeWebSocket } from '../../helper/websocket';
|
|
2
|
-
export declare const upgradeWebSocket: UpgradeWebSocket<WebSocket
|
|
1
|
+
import type { UpgradeWebSocket, WSEvents } from '../../helper/websocket';
|
|
2
|
+
export declare const upgradeWebSocket: UpgradeWebSocket<WebSocket, any, Omit<WSEvents<WebSocket>, "onOpen">>;
|
|
@@ -1,21 +1,2 @@
|
|
|
1
1
|
import type { UpgradeWebSocket } from '../../helper/websocket';
|
|
2
|
-
export
|
|
3
|
-
/**
|
|
4
|
-
* Sets the `.protocol` property on the client side web socket to the
|
|
5
|
-
* value provided here, which should be one of the strings specified in the
|
|
6
|
-
* `protocols` parameter when requesting the web socket. This is intended
|
|
7
|
-
* for clients and servers to specify sub-protocols to use to communicate to
|
|
8
|
-
* each other.
|
|
9
|
-
*/
|
|
10
|
-
protocol?: string;
|
|
11
|
-
/**
|
|
12
|
-
* If the client does not respond to this frame with a
|
|
13
|
-
* `pong` within the timeout specified, the connection is deemed
|
|
14
|
-
* unhealthy and is closed. The `close` and `error` event will be emitted.
|
|
15
|
-
*
|
|
16
|
-
* The unit is seconds, with a default of 30.
|
|
17
|
-
* Set to `0` to disable timeouts.
|
|
18
|
-
*/
|
|
19
|
-
idleTimeout?: number;
|
|
20
|
-
}
|
|
21
|
-
export declare const upgradeWebSocket: UpgradeWebSocket<WebSocket, UpgradeWebSocketOptions>;
|
|
2
|
+
export declare const upgradeWebSocket: UpgradeWebSocket<WebSocket, Deno.UpgradeWebSocketOptions>;
|
package/dist/types/compose.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { ParamIndexMap, Params } from './router';
|
|
2
1
|
import type { Env, ErrorHandler, NotFoundHandler } from './types';
|
|
3
2
|
/**
|
|
4
3
|
* Interface representing the context for a composition operation.
|
|
@@ -31,6 +30,10 @@ export declare const compose: <C extends ComposeContext, E extends Env = Env>(mi
|
|
|
31
30
|
Function,
|
|
32
31
|
unknown
|
|
33
32
|
],
|
|
34
|
-
|
|
33
|
+
unknown
|
|
34
|
+
][] | [
|
|
35
|
+
[
|
|
36
|
+
Function
|
|
37
|
+
]
|
|
35
38
|
][], onError?: ErrorHandler<E>, onNotFound?: NotFoundHandler<E>) => ((context: C, next?: Function) => Promise<C>);
|
|
36
39
|
export {};
|
package/dist/types/context.d.ts
CHANGED
|
@@ -434,7 +434,7 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
|
|
|
434
434
|
* })
|
|
435
435
|
* ```
|
|
436
436
|
*/
|
|
437
|
-
redirect: <T extends RedirectStatusCode = 302>(location: string, status?: T) => Response & TypedResponse<undefined, T, "redirect">;
|
|
437
|
+
redirect: <T extends RedirectStatusCode = 302>(location: string | URL, status?: T) => Response & TypedResponse<undefined, T, "redirect">;
|
|
438
438
|
/**
|
|
439
439
|
* `.notFound()` can return the Not Found Response.
|
|
440
440
|
*
|
|
@@ -16,7 +16,7 @@ export interface WSEvents<T = unknown> {
|
|
|
16
16
|
/**
|
|
17
17
|
* Upgrade WebSocket Type
|
|
18
18
|
*/
|
|
19
|
-
export type UpgradeWebSocket<T = unknown, U = any
|
|
19
|
+
export type UpgradeWebSocket<T = unknown, U = any, _WSEvents = WSEvents<T>> = (createEvents: (c: Context) => _WSEvents | Promise<_WSEvents>, options?: U) => MiddlewareHandler<any, string, {
|
|
20
20
|
outputFormat: "ws";
|
|
21
21
|
}>;
|
|
22
22
|
/**
|
package/dist/types/jsx/base.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { HtmlEscaped, HtmlEscapedString, StringBufferWithCallbacks } from '../utils/html';
|
|
2
|
+
import { DOM_MEMO } from './constants';
|
|
2
3
|
import type { Context } from './context';
|
|
3
4
|
import type { JSX as HonoJSX, IntrinsicElements as IntrinsicElementsDefined } from './intrinsic-elements';
|
|
4
5
|
export type Props = Record<string, any>;
|
|
@@ -45,6 +46,10 @@ export declare class JSXFragmentNode extends JSXNode {
|
|
|
45
46
|
}
|
|
46
47
|
export declare const jsx: (tag: string | Function, props: Props | null, ...children: (string | number | HtmlEscapedString)[]) => JSXNode;
|
|
47
48
|
export declare const jsxFn: (tag: string | Function, props: Props, children: (string | number | HtmlEscapedString)[]) => JSXNode;
|
|
49
|
+
export declare const shallowEqual: (a: Props, b: Props) => boolean;
|
|
50
|
+
export type MemorableFC<T> = FC<T> & {
|
|
51
|
+
[DOM_MEMO]: (prevProps: Readonly<T>, nextProps: Readonly<T>) => boolean;
|
|
52
|
+
};
|
|
48
53
|
export declare const memo: <T>(component: FC<T>, propsAreEqual?: (prevProps: Readonly<T>, nextProps: Readonly<T>) => boolean) => FC<T>;
|
|
49
54
|
export declare const Fragment: ({ children, }: {
|
|
50
55
|
key?: string;
|
|
@@ -2,4 +2,5 @@ export declare const DOM_RENDERER: unique symbol;
|
|
|
2
2
|
export declare const DOM_ERROR_HANDLER: unique symbol;
|
|
3
3
|
export declare const DOM_STASH: unique symbol;
|
|
4
4
|
export declare const DOM_INTERNAL_TAG: unique symbol;
|
|
5
|
+
export declare const DOM_MEMO: unique symbol;
|
|
5
6
|
export declare const PERMALINK: unique symbol;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* @module
|
|
3
3
|
* This module provides APIs for `hono/jsx/dom`.
|
|
4
4
|
*/
|
|
5
|
-
import { isValidElement,
|
|
6
|
-
import type { Child, DOMAttributes, JSX, JSXNode, Props } from '../base';
|
|
5
|
+
import { isValidElement, reactAPICompatVersion } from '../base';
|
|
6
|
+
import type { Child, DOMAttributes, JSX, JSXNode, Props, FC } from '../base';
|
|
7
7
|
import { Children } from '../children';
|
|
8
8
|
import { useContext } from '../context';
|
|
9
9
|
import { createRef, forwardRef, startTransition, startViewTransition, use, useCallback, useDebugValue, useDeferredValue, useEffect, useId, useImperativeHandle, useInsertionEffect, useLayoutEffect, useMemo, useReducer, useRef, useState, useSyncExternalStore, useTransition, useViewTransition } from '../hooks';
|
|
@@ -15,6 +15,7 @@ import { createPortal, flushSync } from './render';
|
|
|
15
15
|
export { render } from './render';
|
|
16
16
|
declare const createElement: (tag: string | ((props: Props) => JSXNode), props: Props | null, ...children: Child[]) => JSXNode;
|
|
17
17
|
declare const cloneElement: <T extends JSXNode | JSX.Element>(element: T, props: Props, ...children: Child[]) => T;
|
|
18
|
+
declare const memo: <T>(component: FC<T>, propsAreEqual?: (prevProps: Readonly<T>, nextProps: Readonly<T>) => boolean) => FC<T>;
|
|
18
19
|
export { reactAPICompatVersion as version, createElement as jsx, useState, useEffect, useRef, useCallback, use, startTransition, useTransition, useDeferredValue, startViewTransition, useViewTransition, useMemo, useLayoutEffect, useInsertionEffect, useReducer, useId, useDebugValue, createRef, forwardRef, useImperativeHandle, useSyncExternalStore, useFormStatus, useActionState, useOptimistic, Suspense, ErrorBoundary, createContext, useContext, memo, isValidElement, createElement, cloneElement, Children, Fragment, Fragment as StrictMode, DOMAttributes, flushSync, createPortal, };
|
|
19
20
|
declare const _default: {
|
|
20
21
|
version: string;
|
|
@@ -77,17 +78,17 @@ declare const _default: {
|
|
|
77
78
|
T,
|
|
78
79
|
(action: N) => void
|
|
79
80
|
];
|
|
80
|
-
Suspense:
|
|
81
|
+
Suspense: FC<import("..").PropsWithChildren<{
|
|
81
82
|
fallback: any;
|
|
82
83
|
}>>;
|
|
83
|
-
ErrorBoundary:
|
|
84
|
+
ErrorBoundary: FC<import("..").PropsWithChildren<{
|
|
84
85
|
fallback?: Child;
|
|
85
86
|
fallbackRender?: import("../components").FallbackRender;
|
|
86
87
|
onError?: import("../components").ErrorHandler;
|
|
87
88
|
}>>;
|
|
88
89
|
createContext: <T>(defaultValue: T) => import("..").Context<T>;
|
|
89
90
|
useContext: <T>(context: import("..").Context<T>) => T;
|
|
90
|
-
memo: <T>(component:
|
|
91
|
+
memo: <T>(component: FC<T>, propsAreEqual?: (prevProps: Readonly<T>, nextProps: Readonly<T>) => boolean) => FC<T>;
|
|
91
92
|
isValidElement: (element: unknown) => element is JSXNode;
|
|
92
93
|
createElement: (tag: string | ((props: Props) => JSXNode), props: Props | null, ...children: Child[]) => JSXNode;
|
|
93
94
|
cloneElement: <T extends JSXNode | JSX.Element>(element: T, props: Props, ...children: Child[]) => T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const generateDigest: (stream: ReadableStream<Uint8Array> | null) => Promise<string | null>;
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import type { Result, Router } from '../../router';
|
|
2
2
|
export declare class LinearRouter<T> implements Router<T> {
|
|
3
3
|
name: string;
|
|
4
|
-
routes: [
|
|
5
|
-
string,
|
|
6
|
-
string,
|
|
7
|
-
T
|
|
8
|
-
][];
|
|
9
4
|
add(method: string, path: string, handler: T): void;
|
|
10
5
|
match(method: string, path: string): Result<T>;
|
|
11
6
|
}
|
|
@@ -7,9 +7,6 @@ export interface Context {
|
|
|
7
7
|
varIndex: number;
|
|
8
8
|
}
|
|
9
9
|
export declare class Node {
|
|
10
|
-
index?: number;
|
|
11
|
-
varIndex?: number;
|
|
12
|
-
children: Record<string, Node>;
|
|
13
10
|
insert(tokens: readonly string[], index: number, paramMap: ParamAssocArray, context: Context, pathErrorCheckOnly: boolean): void;
|
|
14
11
|
buildRegExpStr(): string;
|
|
15
12
|
}
|
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import type { Result, Router } from '../../router';
|
|
2
|
-
type HandlerWithMetadata<T> = [
|
|
3
|
-
T,
|
|
4
|
-
number
|
|
5
|
-
];
|
|
6
2
|
export declare class RegExpRouter<T> implements Router<T> {
|
|
7
3
|
name: string;
|
|
8
|
-
middleware?: Record<string, Record<string, HandlerWithMetadata<T>[]>>;
|
|
9
|
-
routes?: Record<string, Record<string, HandlerWithMetadata<T>[]>>;
|
|
10
4
|
constructor();
|
|
11
5
|
add(method: string, path: string, handler: T): void;
|
|
12
6
|
match(method: string, path: string): Result<T>;
|
|
13
7
|
}
|
|
14
|
-
export {};
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { Node } from './node';
|
|
1
|
+
import type { ParamAssocArray } from './node';
|
|
3
2
|
export type ReplacementMap = number[];
|
|
4
3
|
export declare class Trie {
|
|
5
|
-
context: Context;
|
|
6
|
-
root: Node;
|
|
7
4
|
insert(path: string, index: number, pathErrorCheckOnly: boolean): ParamAssocArray;
|
|
8
5
|
buildRegExp(): [
|
|
9
6
|
RegExp,
|