hono 4.13.2 → 4.13.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/cjs/client/client.js +25 -11
- package/dist/cjs/client/utils.js +4 -1
- package/dist/cjs/context.js +4 -0
- package/dist/cjs/helper/accepts/accepts.js +36 -2
- package/dist/cjs/jsx/dom/render.js +2 -0
- package/dist/cjs/middleware/cors/index.js +1 -1
- package/dist/cjs/middleware/csrf/index.js +1 -1
- package/dist/cjs/middleware/etag/digest.js +1 -1
- package/dist/cjs/middleware/etag/index.js +3 -3
- package/dist/cjs/middleware/pretty-json/index.js +3 -1
- package/dist/cjs/request.js +8 -4
- package/dist/cjs/router/linear-router/router.js +7 -2
- package/dist/cjs/router/pattern-router/router.js +3 -9
- package/dist/cjs/router/reg-exp-router/node.js +10 -3
- package/dist/cjs/router/reg-exp-router/router.js +47 -83
- package/dist/cjs/router/reg-exp-router/trie.js +2 -1
- package/dist/cjs/router/trie-router/node.js +46 -69
- package/dist/cjs/router/trie-router/router.js +3 -11
- package/dist/cjs/router/utils.js +27 -0
- package/dist/cjs/utils/cookie.js +1 -1
- package/dist/cjs/utils/ipaddr.js +5 -3
- package/dist/cjs/utils/stream.js +7 -1
- package/dist/client/client.js +25 -11
- package/dist/client/utils.js +4 -1
- package/dist/context.js +4 -0
- package/dist/helper/accepts/accepts.js +36 -2
- package/dist/jsx/dom/render.js +2 -0
- package/dist/middleware/cors/index.js +1 -1
- package/dist/middleware/csrf/index.js +1 -1
- package/dist/middleware/etag/digest.js +1 -1
- package/dist/middleware/etag/index.js +3 -3
- package/dist/middleware/pretty-json/index.js +3 -1
- package/dist/request.js +8 -4
- package/dist/router/linear-router/router.js +7 -2
- package/dist/router/pattern-router/router.js +3 -9
- package/dist/router/reg-exp-router/node.js +6 -2
- package/dist/router/reg-exp-router/router.js +53 -84
- package/dist/router/reg-exp-router/trie.js +2 -1
- package/dist/router/trie-router/node.js +46 -69
- package/dist/router/trie-router/router.js +3 -11
- package/dist/router/utils.js +5 -0
- package/dist/types/context.d.ts +4 -0
- package/dist/types/router/reg-exp-router/node.d.ts +3 -0
- package/dist/types/router/trie-router/node.d.ts +1 -2
- package/dist/types/router/trie-router/router.d.ts +0 -1
- package/dist/types/router/utils.d.ts +1 -0
- package/dist/utils/cookie.js +1 -1
- package/dist/utils/ipaddr.js +5 -3
- package/dist/utils/stream.js +7 -1
- package/package.json +1 -1
|
@@ -5,25 +5,25 @@ import {
|
|
|
5
5
|
UnsupportedPathError
|
|
6
6
|
} from "../../router.js";
|
|
7
7
|
import { checkOptionalParameter } from "../../utils/url.js";
|
|
8
|
+
import { createNullObject } from "../utils.js";
|
|
8
9
|
import { match, emptyParam } from "./matcher.js";
|
|
9
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
LABEL_REG_EXP_STR,
|
|
12
|
+
ONLY_WILDCARD_REG_EXP_STR,
|
|
13
|
+
PATH_ERROR,
|
|
14
|
+
TAIL_WILDCARD_REG_EXP_STR
|
|
15
|
+
} from "./node.js";
|
|
10
16
|
import { Trie } from "./trie.js";
|
|
11
|
-
var wildcardRegExpCache =
|
|
17
|
+
var wildcardRegExpCache = createNullObject();
|
|
12
18
|
function buildWildcardRegExp(path) {
|
|
13
19
|
return wildcardRegExpCache[path] ??= new RegExp(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
(
|
|
20
|
+
`^${path.replace(
|
|
21
|
+
/\/:[^/{}]+(?:\{\[\^\/]\+})?(?=[/{]|$)|\/?\*$|([.\\+*[^\]$()?{}|])/g,
|
|
22
|
+
(match2, metaChar) => metaChar ? `\\${metaChar}` : match2 === "/*" ? TAIL_WILDCARD_REG_EXP_STR : match2 === "*" ? ONLY_WILDCARD_REG_EXP_STR : `/:${LABEL_REG_EXP_STR}`
|
|
17
23
|
)}$`
|
|
18
24
|
);
|
|
19
25
|
}
|
|
20
|
-
function clearWildcardRegExpCache() {
|
|
21
|
-
wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
22
|
-
}
|
|
23
26
|
function findMiddleware(middleware, path) {
|
|
24
|
-
if (!middleware) {
|
|
25
|
-
return void 0;
|
|
26
|
-
}
|
|
27
27
|
for (const k of Object.keys(middleware).sort((a, b) => b.length - a.length)) {
|
|
28
28
|
if (buildWildcardRegExp(k).test(path)) {
|
|
29
29
|
return [...middleware[k]];
|
|
@@ -37,8 +37,8 @@ var RegExpRouter = class {
|
|
|
37
37
|
#routes;
|
|
38
38
|
#tries;
|
|
39
39
|
constructor() {
|
|
40
|
-
this.#middleware = { [METHOD_NAME_ALL]:
|
|
41
|
-
this.#routes = { [METHOD_NAME_ALL]:
|
|
40
|
+
this.#middleware = { [METHOD_NAME_ALL]: createNullObject() };
|
|
41
|
+
this.#routes = { [METHOD_NAME_ALL]: createNullObject() };
|
|
42
42
|
this.#tries = { [METHOD_NAME_ALL]: new Trie() };
|
|
43
43
|
}
|
|
44
44
|
#insertPath(method, path) {
|
|
@@ -51,117 +51,86 @@ var RegExpRouter = class {
|
|
|
51
51
|
add(method, path, handler) {
|
|
52
52
|
const middleware = this.#middleware;
|
|
53
53
|
const routes = this.#routes;
|
|
54
|
-
if (!middleware
|
|
54
|
+
if (!middleware) {
|
|
55
55
|
throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
56
56
|
}
|
|
57
57
|
if (!middleware[method]) {
|
|
58
58
|
this.#tries[method] = new Trie();
|
|
59
|
-
[middleware, routes]
|
|
60
|
-
handlerMap[method] =
|
|
61
|
-
|
|
59
|
+
for (const handlerMap of [middleware, routes]) {
|
|
60
|
+
handlerMap[method] = createNullObject();
|
|
61
|
+
for (const p in handlerMap[METHOD_NAME_ALL]) {
|
|
62
62
|
handlerMap[method][p] = [...handlerMap[METHOD_NAME_ALL][p]];
|
|
63
63
|
this.#insertPath(method, p);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
66
|
}
|
|
67
67
|
if (path === "/*") {
|
|
68
68
|
path = "*";
|
|
69
69
|
}
|
|
70
|
-
const
|
|
70
|
+
const methods = method === METHOD_NAME_ALL ? Object.keys(middleware) : [method];
|
|
71
71
|
if (/\*$/.test(path)) {
|
|
72
72
|
const re = buildWildcardRegExp(path);
|
|
73
|
-
|
|
74
|
-
if (
|
|
73
|
+
for (const m of methods) {
|
|
74
|
+
if (!middleware[m][path]) {
|
|
75
75
|
this.#insertPath(m, path);
|
|
76
76
|
middleware[m][path] = findMiddleware(middleware[m], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
|
|
77
77
|
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
re.test(p) &&
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
Object.keys(routes).forEach((m) => {
|
|
87
|
-
if (method === METHOD_NAME_ALL || method === m) {
|
|
88
|
-
Object.keys(routes[m]).forEach(
|
|
89
|
-
(p) => re.test(p) && routes[m][p].push([handler, paramCount])
|
|
90
|
-
);
|
|
78
|
+
}
|
|
79
|
+
for (const handlerMap of [middleware, routes]) {
|
|
80
|
+
for (const m of methods) {
|
|
81
|
+
for (const p in handlerMap[m]) {
|
|
82
|
+
re.test(p) && handlerMap[m][p].push([handler, path]);
|
|
83
|
+
}
|
|
91
84
|
}
|
|
92
|
-
}
|
|
85
|
+
}
|
|
93
86
|
return;
|
|
94
87
|
}
|
|
95
88
|
const paths = checkOptionalParameter(path) || [path];
|
|
96
|
-
for (
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
this.#insertPath(m, path2);
|
|
102
|
-
routes[m][path2] = [
|
|
103
|
-
...findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || []
|
|
104
|
-
];
|
|
105
|
-
}
|
|
106
|
-
routes[m][path2].push([handler, paramCount - len + i + 1]);
|
|
89
|
+
for (const path2 of paths) {
|
|
90
|
+
for (const m of methods) {
|
|
91
|
+
if (!routes[m][path2]) {
|
|
92
|
+
this.#insertPath(m, path2);
|
|
93
|
+
routes[m][path2] = findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || [];
|
|
107
94
|
}
|
|
108
|
-
|
|
95
|
+
routes[m][path2].push([handler, path2]);
|
|
96
|
+
}
|
|
109
97
|
}
|
|
110
98
|
}
|
|
111
99
|
match = match;
|
|
112
100
|
buildAllMatchers() {
|
|
113
|
-
const matchers =
|
|
114
|
-
Object.keys(this.#routes)
|
|
115
|
-
matchers[method]
|
|
116
|
-
}
|
|
101
|
+
const matchers = createNullObject();
|
|
102
|
+
for (const method of Object.keys(this.#routes)) {
|
|
103
|
+
matchers[method] = this.#buildMatcher(method);
|
|
104
|
+
}
|
|
117
105
|
this.#middleware = this.#routes = this.#tries = void 0;
|
|
118
|
-
|
|
106
|
+
wildcardRegExpCache = createNullObject();
|
|
119
107
|
return matchers;
|
|
120
108
|
}
|
|
121
109
|
#buildMatcher(method) {
|
|
122
110
|
const middleware = this.#middleware[method];
|
|
123
111
|
const routes = this.#routes[method];
|
|
124
112
|
const trie = this.#tries[method];
|
|
125
|
-
const staticMap =
|
|
113
|
+
const staticMap = createNullObject();
|
|
126
114
|
const handlerData = [];
|
|
127
|
-
[
|
|
115
|
+
const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
|
|
116
|
+
for (const r of [middleware, routes]) {
|
|
128
117
|
for (const path in r) {
|
|
129
118
|
const handlers = r[path];
|
|
130
119
|
const pathData = trie.paths[path];
|
|
131
120
|
if (!pathData) {
|
|
132
|
-
staticMap[path] = [handlers.map(([h]) => [h,
|
|
133
|
-
continue;
|
|
134
|
-
}
|
|
135
|
-
const paramAssoc = pathData[1];
|
|
136
|
-
handlerData[pathData[0]] = handlers.map(([h, paramCount]) => {
|
|
137
|
-
const paramIndexMap = /* @__PURE__ */ Object.create(null);
|
|
138
|
-
paramCount -= 1;
|
|
139
|
-
for (; paramCount >= 0; paramCount--) {
|
|
140
|
-
const [key, value] = paramAssoc[paramCount];
|
|
141
|
-
paramIndexMap[key] = value;
|
|
142
|
-
}
|
|
143
|
-
return [h, paramIndexMap];
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
|
|
148
|
-
for (let i = 0, len = handlerData.length; i < len; i++) {
|
|
149
|
-
for (let j = 0, len2 = handlerData[i].length; j < len2; j++) {
|
|
150
|
-
const map = handlerData[i][j]?.[1];
|
|
151
|
-
if (!map) {
|
|
121
|
+
staticMap[path] = [handlers.map(([h]) => [h, createNullObject()]), emptyParam];
|
|
152
122
|
continue;
|
|
153
123
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
124
|
+
handlerData[pathData[0]] = handlers.map(([h, handlerPath]) => [
|
|
125
|
+
h,
|
|
126
|
+
trie.paths[handlerPath][1].reduceRight((map, [key], i) => {
|
|
127
|
+
map[key] = paramReplacementMap[pathData[1][i][1]];
|
|
128
|
+
return map;
|
|
129
|
+
}, createNullObject())
|
|
130
|
+
]);
|
|
158
131
|
}
|
|
159
132
|
}
|
|
160
|
-
|
|
161
|
-
for (const i in indexReplacementMap) {
|
|
162
|
-
handlerMap[i] = handlerData[indexReplacementMap[i]];
|
|
163
|
-
}
|
|
164
|
-
return [regexp, handlerMap, staticMap];
|
|
133
|
+
return [regexp, indexReplacementMap.map((i) => handlerData[i]), staticMap];
|
|
165
134
|
}
|
|
166
135
|
};
|
|
167
136
|
export {
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// src/router/reg-exp-router/trie.ts
|
|
2
|
+
import { createNullObject } from "../utils.js";
|
|
2
3
|
import { Node } from "./node.js";
|
|
3
4
|
var Trie = class {
|
|
4
5
|
#context = { varIndex: 0 };
|
|
5
6
|
#root = new Node();
|
|
6
7
|
#index = 0;
|
|
7
8
|
// dynamic path -> [handler index, param assoc]; static paths are not registered
|
|
8
|
-
paths =
|
|
9
|
+
paths = createNullObject();
|
|
9
10
|
insert(path, isStatic) {
|
|
10
11
|
if (isStatic) {
|
|
11
12
|
this.#root.insert(path.split(""), 0, [], this.#context, true);
|
|
@@ -1,77 +1,53 @@
|
|
|
1
1
|
// src/router/trie-router/node.ts
|
|
2
2
|
import { METHOD_NAME_ALL } from "../../router.js";
|
|
3
3
|
import { getPattern, splitPath, splitRoutingPath } from "../../utils/url.js";
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
return true;
|
|
8
|
-
}
|
|
9
|
-
return false;
|
|
10
|
-
};
|
|
4
|
+
import { createNullObject } from "../utils.js";
|
|
5
|
+
var emptyParams = createNullObject();
|
|
6
|
+
var order = 0;
|
|
11
7
|
var Node = class _Node {
|
|
12
|
-
#methods;
|
|
13
|
-
#children;
|
|
14
|
-
#patterns;
|
|
15
|
-
#
|
|
8
|
+
#methods = [];
|
|
9
|
+
#children = createNullObject();
|
|
10
|
+
#patterns = [];
|
|
11
|
+
#pattern;
|
|
16
12
|
#params = emptyParams;
|
|
17
|
-
constructor(method, handler, children) {
|
|
18
|
-
this.#children = children || /* @__PURE__ */ Object.create(null);
|
|
19
|
-
this.#methods = [];
|
|
20
|
-
if (method && handler) {
|
|
21
|
-
const m = /* @__PURE__ */ Object.create(null);
|
|
22
|
-
m[method] = { handler, possibleKeys: [], score: 0 };
|
|
23
|
-
this.#methods = [m];
|
|
24
|
-
}
|
|
25
|
-
this.#patterns = [];
|
|
26
|
-
}
|
|
27
13
|
insert(method, path, handler) {
|
|
28
|
-
this.#order = ++this.#order;
|
|
29
14
|
let curNode = this;
|
|
30
15
|
const parts = splitRoutingPath(path);
|
|
31
|
-
const possibleKeys =
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const nextP = parts[i
|
|
35
|
-
const pattern = getPattern(p, nextP);
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
continue;
|
|
16
|
+
const possibleKeys = /* @__PURE__ */ new Set();
|
|
17
|
+
let i = 0;
|
|
18
|
+
for (const p of parts) {
|
|
19
|
+
const nextP = parts[++i];
|
|
20
|
+
const pattern = getPattern(p, nextP) || (nextP === void 0 && p && p.indexOf("*") === p.length - 1 ? p : null);
|
|
21
|
+
const isParam = Array.isArray(pattern);
|
|
22
|
+
const key = isParam ? pattern[0] : pattern || p;
|
|
23
|
+
const child = curNode.#children[key] ||= new _Node();
|
|
24
|
+
if (pattern && !child.#pattern) {
|
|
25
|
+
child.#pattern = pattern;
|
|
26
|
+
curNode.#patterns.push(child);
|
|
43
27
|
}
|
|
44
|
-
curNode
|
|
45
|
-
if (
|
|
46
|
-
|
|
47
|
-
possibleKeys.push(pattern[1]);
|
|
28
|
+
curNode = child;
|
|
29
|
+
if (isParam) {
|
|
30
|
+
possibleKeys.add(pattern[1]);
|
|
48
31
|
}
|
|
49
|
-
curNode = curNode.#children[key];
|
|
50
32
|
}
|
|
51
33
|
curNode.#methods.push({
|
|
52
34
|
[method]: {
|
|
53
35
|
handler,
|
|
54
|
-
possibleKeys: possibleKeys
|
|
55
|
-
score:
|
|
36
|
+
possibleKeys: [...possibleKeys],
|
|
37
|
+
score: ++order
|
|
56
38
|
}
|
|
57
39
|
});
|
|
58
|
-
return curNode;
|
|
59
40
|
}
|
|
60
41
|
#pushHandlerSets(handlerSets, node, method, nodeParams, params) {
|
|
61
42
|
for (let i = 0, len = node.#methods.length; i < len; i++) {
|
|
62
43
|
const m = node.#methods[i];
|
|
63
44
|
const handlerSet = m[method] || m[METHOD_NAME_ALL];
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
handlerSet.params = /* @__PURE__ */ Object.create(null);
|
|
45
|
+
if (handlerSet) {
|
|
46
|
+
handlerSet.params = createNullObject();
|
|
67
47
|
handlerSets.push(handlerSet);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const processed = processedSet[handlerSet.score];
|
|
72
|
-
handlerSet.params[key] = params?.[key] && !processed ? params[key] : nodeParams[key] ?? params?.[key];
|
|
73
|
-
processedSet[handlerSet.score] = true;
|
|
74
|
-
}
|
|
48
|
+
for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
|
|
49
|
+
const key = handlerSet.possibleKeys[i2];
|
|
50
|
+
handlerSet.params[key] = params?.[key] && !i2 ? params[key] : nodeParams[key] ?? params?.[key];
|
|
75
51
|
}
|
|
76
52
|
}
|
|
77
53
|
}
|
|
@@ -103,33 +79,33 @@ var Node = class _Node {
|
|
|
103
79
|
tempNodes.push(nextNode);
|
|
104
80
|
}
|
|
105
81
|
}
|
|
106
|
-
for (
|
|
107
|
-
const pattern =
|
|
82
|
+
for (const child of node.#patterns) {
|
|
83
|
+
const pattern = child.#pattern;
|
|
108
84
|
const params = node.#params === emptyParams ? {} : { ...node.#params };
|
|
109
|
-
if (pattern === "
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
85
|
+
if (typeof pattern === "string") {
|
|
86
|
+
if (pattern === "*" || part.startsWith(pattern.slice(0, -1))) {
|
|
87
|
+
this.#pushHandlerSets(handlerSets, child, method, node.#params);
|
|
88
|
+
if (pattern === "*") {
|
|
89
|
+
child.#params = params;
|
|
90
|
+
tempNodes.push(child);
|
|
91
|
+
}
|
|
115
92
|
}
|
|
116
93
|
continue;
|
|
117
94
|
}
|
|
118
|
-
const [
|
|
119
|
-
if (!part &&
|
|
95
|
+
const [, name, matcher] = pattern;
|
|
96
|
+
if (!part && matcher === true) {
|
|
120
97
|
continue;
|
|
121
98
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
partOffsets = new Array(len);
|
|
99
|
+
if (matcher !== true) {
|
|
100
|
+
if (!partOffsets) {
|
|
101
|
+
partOffsets = [];
|
|
126
102
|
let offset = path[0] === "/" ? 1 : 0;
|
|
127
103
|
for (let p = 0; p < len; p++) {
|
|
128
104
|
partOffsets[p] = offset;
|
|
129
105
|
offset += parts[p].length + 1;
|
|
130
106
|
}
|
|
131
107
|
}
|
|
132
|
-
const restPathString = path.
|
|
108
|
+
const restPathString = path.slice(partOffsets[i]);
|
|
133
109
|
const m = matcher.exec(restPathString);
|
|
134
110
|
if (m) {
|
|
135
111
|
params[name] = m[0];
|
|
@@ -143,11 +119,12 @@ var Node = class _Node {
|
|
|
143
119
|
params
|
|
144
120
|
);
|
|
145
121
|
}
|
|
146
|
-
|
|
122
|
+
for (const _ in child.#children) {
|
|
147
123
|
child.#params = params;
|
|
148
124
|
const componentCount = m[0].match(/\//g)?.length ?? 0;
|
|
149
125
|
const targetCurNodes = curNodesQueue[componentCount] ||= [];
|
|
150
126
|
targetCurNodes.push(child);
|
|
127
|
+
break;
|
|
151
128
|
}
|
|
152
129
|
continue;
|
|
153
130
|
}
|
|
@@ -175,7 +152,7 @@ var Node = class _Node {
|
|
|
175
152
|
const shifted = curNodesQueue.shift();
|
|
176
153
|
curNodes = shifted ? tempNodes.concat(shifted) : tempNodes;
|
|
177
154
|
}
|
|
178
|
-
if (handlerSets
|
|
155
|
+
if (handlerSets[1]) {
|
|
179
156
|
handlerSets.sort((a, b) => {
|
|
180
157
|
return a.score - b.score;
|
|
181
158
|
});
|
|
@@ -3,19 +3,11 @@ import { checkOptionalParameter } from "../../utils/url.js";
|
|
|
3
3
|
import { Node } from "./node.js";
|
|
4
4
|
var TrieRouter = class {
|
|
5
5
|
name = "TrieRouter";
|
|
6
|
-
#node;
|
|
7
|
-
constructor() {
|
|
8
|
-
this.#node = new Node();
|
|
9
|
-
}
|
|
6
|
+
#node = new Node();
|
|
10
7
|
add(method, path, handler) {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
for (let i = 0, len = results.length; i < len; i++) {
|
|
14
|
-
this.#node.insert(method, results[i], handler);
|
|
15
|
-
}
|
|
16
|
-
return;
|
|
8
|
+
for (const result of checkOptionalParameter(path) || [path]) {
|
|
9
|
+
this.#node.insert(method, result, handler);
|
|
17
10
|
}
|
|
18
|
-
this.#node.insert(method, path, handler);
|
|
19
11
|
}
|
|
20
12
|
match(method, path) {
|
|
21
13
|
return this.#node.search(method, path);
|
package/dist/types/context.d.ts
CHANGED
|
@@ -323,6 +323,10 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
|
|
|
323
323
|
* c.header('X-Message', 'Hello!')
|
|
324
324
|
* c.header('Content-Type', 'text/plain')
|
|
325
325
|
*
|
|
326
|
+
* // Append multiple headers using the append option (e.g. Vary)
|
|
327
|
+
* c.header('Vary', 'Accept-Encoding', { append: true })
|
|
328
|
+
* c.header('Vary', 'User-Agent', { append: true })
|
|
329
|
+
*
|
|
326
330
|
* return c.body('Thank you for coming')
|
|
327
331
|
* })
|
|
328
332
|
* ```
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export declare const LABEL_REG_EXP_STR = "[^/]+";
|
|
2
|
+
export declare const ONLY_WILDCARD_REG_EXP_STR = ".*";
|
|
3
|
+
export declare const TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
|
|
1
4
|
export declare const PATH_ERROR: unique symbol;
|
|
2
5
|
export type ParamAssocArray = [string, number][];
|
|
3
6
|
export interface Context {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { Params } from '../../router';
|
|
2
2
|
export declare class Node<T> {
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
insert(method: string, path: string, handler: T): Node<T>;
|
|
4
|
+
insert(method: string, path: string, handler: T): void;
|
|
6
5
|
search(method: string, path: string): [[T, Params][]];
|
|
7
6
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createNullObject: () => any;
|
package/dist/utils/cookie.js
CHANGED
|
@@ -77,7 +77,7 @@ var parseSigned = async (cookie, secret, name) => {
|
|
|
77
77
|
const secretKey = await getCryptoKey(secret);
|
|
78
78
|
for (const [key, value] of Object.entries(parse(cookie, name))) {
|
|
79
79
|
const signatureStartPos = value.lastIndexOf(".");
|
|
80
|
-
if (signatureStartPos <
|
|
80
|
+
if (signatureStartPos < 0) {
|
|
81
81
|
continue;
|
|
82
82
|
}
|
|
83
83
|
const signedValue = value.substring(0, signatureStartPos);
|
package/dist/utils/ipaddr.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
// src/utils/ipaddr.ts
|
|
2
2
|
var expandIPv6 = (ipV6) => {
|
|
3
3
|
const sections = ipV6.split(":");
|
|
4
|
-
|
|
4
|
+
const lastSection = sections.at(-1);
|
|
5
|
+
if (IPV4_REGEX.test(lastSection)) {
|
|
6
|
+
const octets = lastSection.split(".").map(Number);
|
|
5
7
|
sections.splice(
|
|
6
8
|
-1,
|
|
7
9
|
1,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
(octets[0] << 8 | octets[1]).toString(16),
|
|
11
|
+
(octets[2] << 8 | octets[3]).toString(16)
|
|
10
12
|
);
|
|
11
13
|
}
|
|
12
14
|
for (let i = 0; i < sections.length; i++) {
|
package/dist/utils/stream.js
CHANGED
|
@@ -75,7 +75,13 @@ var StreamingApi = class {
|
|
|
75
75
|
abort() {
|
|
76
76
|
if (!this.aborted) {
|
|
77
77
|
this.aborted = true;
|
|
78
|
-
this.abortSubscribers.forEach((subscriber) =>
|
|
78
|
+
this.abortSubscribers.forEach((subscriber) => {
|
|
79
|
+
try {
|
|
80
|
+
void Promise.resolve(subscriber()).catch(() => {
|
|
81
|
+
});
|
|
82
|
+
} catch {
|
|
83
|
+
}
|
|
84
|
+
});
|
|
79
85
|
}
|
|
80
86
|
}
|
|
81
87
|
};
|