hono 4.1.1 → 4.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/helper/ssg/ssg.js +9 -8
- package/dist/cjs/helper.js +16 -0
- package/dist/cjs/jsx/base.js +4 -2
- package/dist/cjs/router/linear-router/router.js +2 -2
- package/dist/cjs/router/pattern-router/router.js +9 -12
- package/dist/cjs/router/reg-exp-router/node.js +3 -2
- package/dist/cjs/router/reg-exp-router/router.js +10 -10
- package/dist/cjs/router/trie-router/node.js +12 -10
- package/dist/cjs/utils/cookie.js +1 -1
- package/dist/cjs/utils/url.js +3 -2
- package/dist/cjs/validator/validator.js +30 -13
- package/dist/helper/ssg/ssg.js +9 -8
- package/dist/helper.js +6 -0
- package/dist/jsx/base.js +4 -2
- package/dist/router/linear-router/router.js +2 -2
- package/dist/router/pattern-router/router.js +9 -12
- package/dist/router/reg-exp-router/node.js +3 -2
- package/dist/router/reg-exp-router/router.js +10 -10
- package/dist/router/trie-router/node.js +12 -10
- package/dist/types/helper/ssg/ssg.d.ts +2 -2
- package/dist/types/types.d.ts +1 -1
- package/dist/types/utils/cookie.d.ts +19 -2
- package/dist/utils/cookie.js +1 -1
- package/dist/utils/url.js +3 -2
- package/dist/validator/validator.js +30 -13
- package/package.json +1 -1
|
@@ -74,15 +74,16 @@ const fetchRoutesContent = function* (app, beforeRequestHook, afterResponseHook,
|
|
|
74
74
|
for (const route of (0, import_utils2.filterStaticGenerateRoutes)(app)) {
|
|
75
75
|
const thisRouteBaseURL = new URL(route.path, baseURL).toString();
|
|
76
76
|
let forGetInfoURLRequest = new Request(thisRouteBaseURL);
|
|
77
|
-
if (beforeRequestHook) {
|
|
78
|
-
const maybeRequest = beforeRequestHook(forGetInfoURLRequest);
|
|
79
|
-
if (!maybeRequest) {
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
forGetInfoURLRequest = maybeRequest;
|
|
83
|
-
}
|
|
84
77
|
yield new Promise(async (resolveGetInfo, rejectGetInfo) => {
|
|
85
78
|
try {
|
|
79
|
+
if (beforeRequestHook) {
|
|
80
|
+
const maybeRequest = await beforeRequestHook(forGetInfoURLRequest);
|
|
81
|
+
if (!maybeRequest) {
|
|
82
|
+
resolveGetInfo(void 0);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
forGetInfoURLRequest = maybeRequest;
|
|
86
|
+
}
|
|
86
87
|
await pool.run(() => app.fetch(forGetInfoURLRequest));
|
|
87
88
|
if (!forGetInfoURLRequest.ssgParams) {
|
|
88
89
|
if (isDynamicRoute(route.path)) {
|
|
@@ -111,7 +112,7 @@ const fetchRoutesContent = function* (app, beforeRequestHook, afterResponseHook,
|
|
|
111
112
|
return;
|
|
112
113
|
}
|
|
113
114
|
if (afterResponseHook) {
|
|
114
|
-
const maybeResponse = afterResponseHook(response);
|
|
115
|
+
const maybeResponse = await afterResponseHook(response);
|
|
115
116
|
if (!maybeResponse) {
|
|
116
117
|
resolveReq(void 0);
|
|
117
118
|
return;
|
package/dist/cjs/helper.js
CHANGED
|
@@ -3,6 +3,10 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
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
|
+
};
|
|
6
10
|
var __copyProps = (to, from, except, desc) => {
|
|
7
11
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
12
|
for (let key of __getOwnPropNames(from))
|
|
@@ -14,6 +18,11 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
14
18
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
20
|
var helper_exports = {};
|
|
21
|
+
__export(helper_exports, {
|
|
22
|
+
jwtDecode: () => import_jwt.decode,
|
|
23
|
+
jwtSign: () => import_jwt.sign,
|
|
24
|
+
jwtVerify: () => import_jwt.verify
|
|
25
|
+
});
|
|
17
26
|
module.exports = __toCommonJS(helper_exports);
|
|
18
27
|
__reExport(helper_exports, require("./helper/accepts"), module.exports);
|
|
19
28
|
__reExport(helper_exports, require("./helper/adapter"), module.exports);
|
|
@@ -26,3 +35,10 @@ __reExport(helper_exports, require("./helper/testing"), module.exports);
|
|
|
26
35
|
__reExport(helper_exports, require("./helper/dev"), module.exports);
|
|
27
36
|
__reExport(helper_exports, require("./adapter/deno/ssg"), module.exports);
|
|
28
37
|
__reExport(helper_exports, require("./adapter/deno/websocket"), module.exports);
|
|
38
|
+
var import_jwt = require("./middleware/jwt");
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
jwtDecode,
|
|
42
|
+
jwtSign,
|
|
43
|
+
jwtVerify
|
|
44
|
+
});
|
package/dist/cjs/jsx/base.js
CHANGED
|
@@ -135,7 +135,9 @@ class JSXNode {
|
|
|
135
135
|
const property = k.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
136
136
|
return `${property}:${v[k]}`;
|
|
137
137
|
}).join(";");
|
|
138
|
-
buffer[0] +=
|
|
138
|
+
buffer[0] += ' style="';
|
|
139
|
+
(0, import_html2.escapeToBuffer)(styles, buffer);
|
|
140
|
+
buffer[0] += '"';
|
|
139
141
|
} else if (typeof v === "string") {
|
|
140
142
|
buffer[0] += ` ${key}="`;
|
|
141
143
|
(0, import_html2.escapeToBuffer)(v, buffer);
|
|
@@ -165,7 +167,7 @@ class JSXNode {
|
|
|
165
167
|
buffer[0] += '"';
|
|
166
168
|
}
|
|
167
169
|
}
|
|
168
|
-
if (emptyTags.includes(tag)) {
|
|
170
|
+
if (emptyTags.includes(tag) && children.length === 0) {
|
|
169
171
|
buffer[0] += "/>";
|
|
170
172
|
return;
|
|
171
173
|
}
|
|
@@ -23,7 +23,7 @@ __export(router_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(router_exports);
|
|
24
24
|
var import_router = require("../../router");
|
|
25
25
|
var import_url = require("../../utils/url");
|
|
26
|
-
const emptyParams =
|
|
26
|
+
const emptyParams = /* @__PURE__ */ Object.create(null);
|
|
27
27
|
const splitPathRe = /\/(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/[^\/\?]+|(\?)/g;
|
|
28
28
|
const splitByStarRe = /\*/;
|
|
29
29
|
class LinearRouter {
|
|
@@ -78,7 +78,7 @@ class LinearRouter {
|
|
|
78
78
|
}
|
|
79
79
|
handlers.push([handler, emptyParams]);
|
|
80
80
|
} else if (hasLabel && !hasStar) {
|
|
81
|
-
const params =
|
|
81
|
+
const params = /* @__PURE__ */ Object.create(null);
|
|
82
82
|
const parts = routePath.match(splitPathRe);
|
|
83
83
|
const lastIndex = parts.length - 1;
|
|
84
84
|
for (let j = 0, pos = 0, len2 = parts.length; j < len2; j++) {
|
|
@@ -30,19 +30,16 @@ class PatternRouter {
|
|
|
30
30
|
if (endsWithWildcard) {
|
|
31
31
|
path = path.slice(0, -2);
|
|
32
32
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
this.add(method,
|
|
36
|
-
parts.pop();
|
|
33
|
+
if (path.at(-1) === "?") {
|
|
34
|
+
path = path.slice(0, -1);
|
|
35
|
+
this.add(method, path.replace(/\/[^/]+$/, ""), handler);
|
|
37
36
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
} else if (parts[i] === "/*") {
|
|
43
|
-
parts[i] = "/[^/]+";
|
|
37
|
+
const parts = (path.match(/\/?(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/?[^\/\?]+/g) || []).map(
|
|
38
|
+
(part) => {
|
|
39
|
+
const match = part.match(/^\/:([^{]+)(?:{(.*)})?/);
|
|
40
|
+
return match ? `/(?<${match[1]}>${match[2] || "[^/]+"})` : part === "/*" ? "/[^/]+" : part.replace(/[.\\+*[^\]$()]/g, "\\$&");
|
|
44
41
|
}
|
|
45
|
-
|
|
42
|
+
);
|
|
46
43
|
let re;
|
|
47
44
|
try {
|
|
48
45
|
re = new RegExp(`^${parts.join("")}${endsWithWildcard ? "" : "/?$"}`);
|
|
@@ -57,7 +54,7 @@ class PatternRouter {
|
|
|
57
54
|
if (routeMethod === import_router.METHOD_NAME_ALL || routeMethod === method) {
|
|
58
55
|
const match = pattern.exec(path);
|
|
59
56
|
if (match) {
|
|
60
|
-
handlers.push([handler, match.groups ||
|
|
57
|
+
handlers.push([handler, match.groups || /* @__PURE__ */ Object.create(null)]);
|
|
61
58
|
}
|
|
62
59
|
}
|
|
63
60
|
}
|
|
@@ -26,6 +26,7 @@ const LABEL_REG_EXP_STR = "[^/]+";
|
|
|
26
26
|
const ONLY_WILDCARD_REG_EXP_STR = ".*";
|
|
27
27
|
const TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
|
|
28
28
|
const PATH_ERROR = Symbol();
|
|
29
|
+
const regExpMetaChars = new Set(".\\+*[^]$()");
|
|
29
30
|
function compareKey(a, b) {
|
|
30
31
|
if (a.length === 1) {
|
|
31
32
|
return b.length === 1 ? a < b ? -1 : 1 : -1;
|
|
@@ -48,7 +49,7 @@ function compareKey(a, b) {
|
|
|
48
49
|
class Node {
|
|
49
50
|
index;
|
|
50
51
|
varIndex;
|
|
51
|
-
children =
|
|
52
|
+
children = /* @__PURE__ */ Object.create(null);
|
|
52
53
|
insert(tokens, index, paramMap, context, pathErrorCheckOnly) {
|
|
53
54
|
if (tokens.length === 0) {
|
|
54
55
|
if (this.index !== void 0) {
|
|
@@ -110,7 +111,7 @@ class Node {
|
|
|
110
111
|
const childKeys = Object.keys(this.children).sort(compareKey);
|
|
111
112
|
const strList = childKeys.map((k) => {
|
|
112
113
|
const c = this.children[k];
|
|
113
|
-
return (typeof c.varIndex === "number" ? `(${k})@${c.varIndex}` : k) + c.buildRegExpStr();
|
|
114
|
+
return (typeof c.varIndex === "number" ? `(${k})@${c.varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr();
|
|
114
115
|
});
|
|
115
116
|
if (typeof this.index === "number") {
|
|
116
117
|
strList.unshift(`#${this.index}`);
|
|
@@ -26,15 +26,15 @@ var import_url = require("../../utils/url");
|
|
|
26
26
|
var import_node = require("./node");
|
|
27
27
|
var import_trie = require("./trie");
|
|
28
28
|
const emptyParam = [];
|
|
29
|
-
const nullMatcher = [/^$/, [],
|
|
30
|
-
let wildcardRegExpCache =
|
|
29
|
+
const nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
|
|
30
|
+
let wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
31
31
|
function buildWildcardRegExp(path) {
|
|
32
32
|
return wildcardRegExpCache[path] ??= new RegExp(
|
|
33
33
|
path === "*" ? "" : `^${path.replace(/\/\*/, "(?:|/.*)")}$`
|
|
34
34
|
);
|
|
35
35
|
}
|
|
36
36
|
function clearWildcardRegExpCache() {
|
|
37
|
-
wildcardRegExpCache =
|
|
37
|
+
wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
38
38
|
}
|
|
39
39
|
function buildMatcherFromPreprocessedRoutes(routes) {
|
|
40
40
|
const trie = new import_trie.Trie();
|
|
@@ -47,11 +47,11 @@ function buildMatcherFromPreprocessedRoutes(routes) {
|
|
|
47
47
|
).sort(
|
|
48
48
|
([isStaticA, pathA], [isStaticB, pathB]) => isStaticA ? 1 : isStaticB ? -1 : pathA.length - pathB.length
|
|
49
49
|
);
|
|
50
|
-
const staticMap =
|
|
50
|
+
const staticMap = /* @__PURE__ */ Object.create(null);
|
|
51
51
|
for (let i = 0, j = -1, len = routesWithStaticPathFlag.length; i < len; i++) {
|
|
52
52
|
const [pathErrorCheckOnly, path, handlers] = routesWithStaticPathFlag[i];
|
|
53
53
|
if (pathErrorCheckOnly) {
|
|
54
|
-
staticMap[path] = [handlers.map(([h]) => [h,
|
|
54
|
+
staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
|
|
55
55
|
} else {
|
|
56
56
|
j++;
|
|
57
57
|
}
|
|
@@ -65,7 +65,7 @@ function buildMatcherFromPreprocessedRoutes(routes) {
|
|
|
65
65
|
continue;
|
|
66
66
|
}
|
|
67
67
|
handlerData[j] = handlers.map(([h, paramCount]) => {
|
|
68
|
-
const paramIndexMap =
|
|
68
|
+
const paramIndexMap = /* @__PURE__ */ Object.create(null);
|
|
69
69
|
paramCount -= 1;
|
|
70
70
|
for (; paramCount >= 0; paramCount--) {
|
|
71
71
|
const [key, value] = paramAssoc[paramCount];
|
|
@@ -109,8 +109,8 @@ class RegExpRouter {
|
|
|
109
109
|
middleware;
|
|
110
110
|
routes;
|
|
111
111
|
constructor() {
|
|
112
|
-
this.middleware = { [import_router.METHOD_NAME_ALL]:
|
|
113
|
-
this.routes = { [import_router.METHOD_NAME_ALL]:
|
|
112
|
+
this.middleware = { [import_router.METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
|
|
113
|
+
this.routes = { [import_router.METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
|
|
114
114
|
}
|
|
115
115
|
add(method, path, handler) {
|
|
116
116
|
const { middleware, routes } = this;
|
|
@@ -120,7 +120,7 @@ class RegExpRouter {
|
|
|
120
120
|
if (!middleware[method]) {
|
|
121
121
|
;
|
|
122
122
|
[middleware, routes].forEach((handlerMap) => {
|
|
123
|
-
handlerMap[method] =
|
|
123
|
+
handlerMap[method] = /* @__PURE__ */ Object.create(null);
|
|
124
124
|
Object.keys(handlerMap[import_router.METHOD_NAME_ALL]).forEach((p) => {
|
|
125
125
|
handlerMap[method][p] = [...handlerMap[import_router.METHOD_NAME_ALL][p]];
|
|
126
126
|
});
|
|
@@ -187,7 +187,7 @@ class RegExpRouter {
|
|
|
187
187
|
return this.match(method, path);
|
|
188
188
|
}
|
|
189
189
|
buildAllMatchers() {
|
|
190
|
-
const matchers =
|
|
190
|
+
const matchers = /* @__PURE__ */ Object.create(null);
|
|
191
191
|
[...Object.keys(this.routes), ...Object.keys(this.middleware)].forEach((method) => {
|
|
192
192
|
matchers[method] ||= this.buildMatcher(method);
|
|
193
193
|
});
|
|
@@ -29,13 +29,13 @@ class Node {
|
|
|
29
29
|
patterns;
|
|
30
30
|
order = 0;
|
|
31
31
|
name;
|
|
32
|
-
params =
|
|
32
|
+
params = /* @__PURE__ */ Object.create(null);
|
|
33
33
|
constructor(method, handler, children) {
|
|
34
|
-
this.children = children ||
|
|
34
|
+
this.children = children || /* @__PURE__ */ Object.create(null);
|
|
35
35
|
this.methods = [];
|
|
36
36
|
this.name = "";
|
|
37
37
|
if (method && handler) {
|
|
38
|
-
const m =
|
|
38
|
+
const m = /* @__PURE__ */ Object.create(null);
|
|
39
39
|
m[method] = { handler, possibleKeys: [], score: 0, name: this.name };
|
|
40
40
|
this.methods = [m];
|
|
41
41
|
}
|
|
@@ -72,7 +72,7 @@ class Node {
|
|
|
72
72
|
if (!curNode.methods.length) {
|
|
73
73
|
curNode.methods = [];
|
|
74
74
|
}
|
|
75
|
-
const m =
|
|
75
|
+
const m = /* @__PURE__ */ Object.create(null);
|
|
76
76
|
const handlerSet = {
|
|
77
77
|
handler,
|
|
78
78
|
possibleKeys: possibleKeys.filter((v, i, a) => a.indexOf(v) === i),
|
|
@@ -88,9 +88,9 @@ class Node {
|
|
|
88
88
|
for (let i = 0, len = node.methods.length; i < len; i++) {
|
|
89
89
|
const m = node.methods[i];
|
|
90
90
|
const handlerSet = m[method] || m[import_router.METHOD_NAME_ALL];
|
|
91
|
-
const processedSet =
|
|
91
|
+
const processedSet = /* @__PURE__ */ Object.create(null);
|
|
92
92
|
if (handlerSet !== void 0) {
|
|
93
|
-
handlerSet.params =
|
|
93
|
+
handlerSet.params = /* @__PURE__ */ Object.create(null);
|
|
94
94
|
handlerSet.possibleKeys.forEach((key) => {
|
|
95
95
|
const processed = processedSet[handlerSet.name];
|
|
96
96
|
handlerSet.params[key] = params[key] && !processed ? params[key] : nodeParams[key] ?? params[key];
|
|
@@ -103,7 +103,7 @@ class Node {
|
|
|
103
103
|
}
|
|
104
104
|
search(method, path) {
|
|
105
105
|
const handlerSets = [];
|
|
106
|
-
this.params =
|
|
106
|
+
this.params = /* @__PURE__ */ Object.create(null);
|
|
107
107
|
const curNode = this;
|
|
108
108
|
let curNodes = [curNode];
|
|
109
109
|
const parts = (0, import_url.splitPath)(path);
|
|
@@ -118,9 +118,11 @@ class Node {
|
|
|
118
118
|
nextNode.params = node.params;
|
|
119
119
|
if (isLast === true) {
|
|
120
120
|
if (nextNode.children["*"]) {
|
|
121
|
-
handlerSets.push(
|
|
121
|
+
handlerSets.push(
|
|
122
|
+
...this.gHSets(nextNode.children["*"], method, node.params, /* @__PURE__ */ Object.create(null))
|
|
123
|
+
);
|
|
122
124
|
}
|
|
123
|
-
handlerSets.push(...this.gHSets(nextNode, method, node.params,
|
|
125
|
+
handlerSets.push(...this.gHSets(nextNode, method, node.params, /* @__PURE__ */ Object.create(null)));
|
|
124
126
|
} else {
|
|
125
127
|
tempNodes.push(nextNode);
|
|
126
128
|
}
|
|
@@ -131,7 +133,7 @@ class Node {
|
|
|
131
133
|
if (pattern === "*") {
|
|
132
134
|
const astNode = node.children["*"];
|
|
133
135
|
if (astNode) {
|
|
134
|
-
handlerSets.push(...this.gHSets(astNode, method, node.params,
|
|
136
|
+
handlerSets.push(...this.gHSets(astNode, method, node.params, /* @__PURE__ */ Object.create(null)));
|
|
135
137
|
tempNodes.push(astNode);
|
|
136
138
|
}
|
|
137
139
|
continue;
|
package/dist/cjs/utils/cookie.js
CHANGED
|
@@ -144,7 +144,7 @@ const _serialize = (name, value, opt = {}) => {
|
|
|
144
144
|
}
|
|
145
145
|
return cookie;
|
|
146
146
|
};
|
|
147
|
-
const serialize = (name, value, opt
|
|
147
|
+
const serialize = (name, value, opt) => {
|
|
148
148
|
value = encodeURIComponent(value);
|
|
149
149
|
return _serialize(name, value, opt);
|
|
150
150
|
};
|
package/dist/cjs/utils/url.js
CHANGED
|
@@ -83,8 +83,9 @@ const getPattern = (label) => {
|
|
|
83
83
|
return null;
|
|
84
84
|
};
|
|
85
85
|
const getPath = (request) => {
|
|
86
|
-
const
|
|
87
|
-
|
|
86
|
+
const url = request.url;
|
|
87
|
+
const queryIndex = url.indexOf("?", 8);
|
|
88
|
+
return url.slice(url.indexOf("/", 8), queryIndex === -1 ? void 0 : queryIndex);
|
|
88
89
|
};
|
|
89
90
|
const getQueryStrings = (url) => {
|
|
90
91
|
const queryIndex = url.indexOf("?", 8);
|
|
@@ -28,6 +28,7 @@ const validator = (target, validationFunc) => {
|
|
|
28
28
|
return async (c, next) => {
|
|
29
29
|
let value = {};
|
|
30
30
|
const contentType = c.req.header("Content-Type");
|
|
31
|
+
const bodyTypes = ["text", "arrayBuffer", "blob"];
|
|
31
32
|
switch (target) {
|
|
32
33
|
case "json":
|
|
33
34
|
if (!contentType || !contentType.startsWith("application/json")) {
|
|
@@ -35,11 +36,19 @@ const validator = (target, validationFunc) => {
|
|
|
35
36
|
throw new import_http_exception.HTTPException(400, { message });
|
|
36
37
|
}
|
|
37
38
|
if (c.req.bodyCache.json) {
|
|
38
|
-
value =
|
|
39
|
+
value = c.req.bodyCache.json;
|
|
39
40
|
break;
|
|
40
41
|
}
|
|
41
42
|
try {
|
|
42
|
-
|
|
43
|
+
let arrayBuffer = void 0;
|
|
44
|
+
for (const type of bodyTypes) {
|
|
45
|
+
const body = c.req.bodyCache[type];
|
|
46
|
+
if (body) {
|
|
47
|
+
arrayBuffer = await new Response(await body).arrayBuffer();
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
arrayBuffer ??= await c.req.raw.arrayBuffer();
|
|
43
52
|
value = await new Response(arrayBuffer).json();
|
|
44
53
|
c.req.bodyCache.json = value;
|
|
45
54
|
c.req.bodyCache.arrayBuffer = arrayBuffer;
|
|
@@ -49,23 +58,31 @@ const validator = (target, validationFunc) => {
|
|
|
49
58
|
}
|
|
50
59
|
break;
|
|
51
60
|
case "form": {
|
|
61
|
+
if (!contentType) {
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
52
64
|
if (c.req.bodyCache.formData) {
|
|
53
65
|
value = c.req.bodyCache.formData;
|
|
54
66
|
break;
|
|
55
67
|
}
|
|
56
68
|
try {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
});
|
|
65
|
-
value = form;
|
|
66
|
-
c.req.bodyCache.formData = formData;
|
|
67
|
-
c.req.bodyCache.arrayBuffer = arrayBuffer;
|
|
69
|
+
let arrayBuffer = void 0;
|
|
70
|
+
for (const type of bodyTypes) {
|
|
71
|
+
const body = c.req.bodyCache[type];
|
|
72
|
+
if (body) {
|
|
73
|
+
arrayBuffer = await new Response(await body).arrayBuffer();
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
68
76
|
}
|
|
77
|
+
arrayBuffer ??= await c.req.arrayBuffer();
|
|
78
|
+
const formData = await (0, import_buffer.bufferToFormData)(arrayBuffer, contentType);
|
|
79
|
+
const form = {};
|
|
80
|
+
formData.forEach((value2, key) => {
|
|
81
|
+
form[key] = value2;
|
|
82
|
+
});
|
|
83
|
+
value = form;
|
|
84
|
+
c.req.bodyCache.formData = formData;
|
|
85
|
+
c.req.bodyCache.arrayBuffer = arrayBuffer;
|
|
69
86
|
} catch (e) {
|
|
70
87
|
let message = "Malformed FormData request.";
|
|
71
88
|
message += e instanceof Error ? ` ${e.message}` : ` ${String(e)}`;
|
package/dist/helper/ssg/ssg.js
CHANGED
|
@@ -50,15 +50,16 @@ var fetchRoutesContent = function* (app, beforeRequestHook, afterResponseHook, c
|
|
|
50
50
|
for (const route of filterStaticGenerateRoutes(app)) {
|
|
51
51
|
const thisRouteBaseURL = new URL(route.path, baseURL).toString();
|
|
52
52
|
let forGetInfoURLRequest = new Request(thisRouteBaseURL);
|
|
53
|
-
if (beforeRequestHook) {
|
|
54
|
-
const maybeRequest = beforeRequestHook(forGetInfoURLRequest);
|
|
55
|
-
if (!maybeRequest) {
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
forGetInfoURLRequest = maybeRequest;
|
|
59
|
-
}
|
|
60
53
|
yield new Promise(async (resolveGetInfo, rejectGetInfo) => {
|
|
61
54
|
try {
|
|
55
|
+
if (beforeRequestHook) {
|
|
56
|
+
const maybeRequest = await beforeRequestHook(forGetInfoURLRequest);
|
|
57
|
+
if (!maybeRequest) {
|
|
58
|
+
resolveGetInfo(void 0);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
forGetInfoURLRequest = maybeRequest;
|
|
62
|
+
}
|
|
62
63
|
await pool.run(() => app.fetch(forGetInfoURLRequest));
|
|
63
64
|
if (!forGetInfoURLRequest.ssgParams) {
|
|
64
65
|
if (isDynamicRoute(route.path)) {
|
|
@@ -87,7 +88,7 @@ var fetchRoutesContent = function* (app, beforeRequestHook, afterResponseHook, c
|
|
|
87
88
|
return;
|
|
88
89
|
}
|
|
89
90
|
if (afterResponseHook) {
|
|
90
|
-
const maybeResponse = afterResponseHook(response);
|
|
91
|
+
const maybeResponse = await afterResponseHook(response);
|
|
91
92
|
if (!maybeResponse) {
|
|
92
93
|
resolveReq(void 0);
|
|
93
94
|
return;
|
package/dist/helper.js
CHANGED
|
@@ -10,3 +10,9 @@ export * from "./helper/testing/index.js";
|
|
|
10
10
|
export * from "./helper/dev/index.js";
|
|
11
11
|
export * from "./adapter/deno/ssg.js";
|
|
12
12
|
export * from "./adapter/deno/websocket.js";
|
|
13
|
+
import { decode, sign, verify } from "./middleware/jwt/index.js";
|
|
14
|
+
export {
|
|
15
|
+
decode as jwtDecode,
|
|
16
|
+
sign as jwtSign,
|
|
17
|
+
verify as jwtVerify
|
|
18
|
+
};
|
package/dist/jsx/base.js
CHANGED
|
@@ -106,7 +106,9 @@ var JSXNode = class {
|
|
|
106
106
|
const property = k.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
107
107
|
return `${property}:${v[k]}`;
|
|
108
108
|
}).join(";");
|
|
109
|
-
buffer[0] +=
|
|
109
|
+
buffer[0] += ' style="';
|
|
110
|
+
escapeToBuffer(styles, buffer);
|
|
111
|
+
buffer[0] += '"';
|
|
110
112
|
} else if (typeof v === "string") {
|
|
111
113
|
buffer[0] += ` ${key}="`;
|
|
112
114
|
escapeToBuffer(v, buffer);
|
|
@@ -136,7 +138,7 @@ var JSXNode = class {
|
|
|
136
138
|
buffer[0] += '"';
|
|
137
139
|
}
|
|
138
140
|
}
|
|
139
|
-
if (emptyTags.includes(tag)) {
|
|
141
|
+
if (emptyTags.includes(tag) && children.length === 0) {
|
|
140
142
|
buffer[0] += "/>";
|
|
141
143
|
return;
|
|
142
144
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/router/linear-router/router.ts
|
|
2
2
|
import { METHOD_NAME_ALL, UnsupportedPathError } from "../../router.js";
|
|
3
3
|
import { checkOptionalParameter } from "../../utils/url.js";
|
|
4
|
-
var emptyParams =
|
|
4
|
+
var emptyParams = /* @__PURE__ */ Object.create(null);
|
|
5
5
|
var splitPathRe = /\/(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/[^\/\?]+|(\?)/g;
|
|
6
6
|
var splitByStarRe = /\*/;
|
|
7
7
|
var LinearRouter = class {
|
|
@@ -56,7 +56,7 @@ var LinearRouter = class {
|
|
|
56
56
|
}
|
|
57
57
|
handlers.push([handler, emptyParams]);
|
|
58
58
|
} else if (hasLabel && !hasStar) {
|
|
59
|
-
const params =
|
|
59
|
+
const params = /* @__PURE__ */ Object.create(null);
|
|
60
60
|
const parts = routePath.match(splitPathRe);
|
|
61
61
|
const lastIndex = parts.length - 1;
|
|
62
62
|
for (let j = 0, pos = 0, len2 = parts.length; j < len2; j++) {
|
|
@@ -8,19 +8,16 @@ var PatternRouter = class {
|
|
|
8
8
|
if (endsWithWildcard) {
|
|
9
9
|
path = path.slice(0, -2);
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
this.add(method,
|
|
14
|
-
parts.pop();
|
|
11
|
+
if (path.at(-1) === "?") {
|
|
12
|
+
path = path.slice(0, -1);
|
|
13
|
+
this.add(method, path.replace(/\/[^/]+$/, ""), handler);
|
|
15
14
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
} else if (parts[i] === "/*") {
|
|
21
|
-
parts[i] = "/[^/]+";
|
|
15
|
+
const parts = (path.match(/\/?(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/?[^\/\?]+/g) || []).map(
|
|
16
|
+
(part) => {
|
|
17
|
+
const match = part.match(/^\/:([^{]+)(?:{(.*)})?/);
|
|
18
|
+
return match ? `/(?<${match[1]}>${match[2] || "[^/]+"})` : part === "/*" ? "/[^/]+" : part.replace(/[.\\+*[^\]$()]/g, "\\$&");
|
|
22
19
|
}
|
|
23
|
-
|
|
20
|
+
);
|
|
24
21
|
let re;
|
|
25
22
|
try {
|
|
26
23
|
re = new RegExp(`^${parts.join("")}${endsWithWildcard ? "" : "/?$"}`);
|
|
@@ -35,7 +32,7 @@ var PatternRouter = class {
|
|
|
35
32
|
if (routeMethod === METHOD_NAME_ALL || routeMethod === method) {
|
|
36
33
|
const match = pattern.exec(path);
|
|
37
34
|
if (match) {
|
|
38
|
-
handlers.push([handler, match.groups ||
|
|
35
|
+
handlers.push([handler, match.groups || /* @__PURE__ */ Object.create(null)]);
|
|
39
36
|
}
|
|
40
37
|
}
|
|
41
38
|
}
|
|
@@ -3,6 +3,7 @@ var LABEL_REG_EXP_STR = "[^/]+";
|
|
|
3
3
|
var ONLY_WILDCARD_REG_EXP_STR = ".*";
|
|
4
4
|
var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
|
|
5
5
|
var PATH_ERROR = Symbol();
|
|
6
|
+
var regExpMetaChars = new Set(".\\+*[^]$()");
|
|
6
7
|
function compareKey(a, b) {
|
|
7
8
|
if (a.length === 1) {
|
|
8
9
|
return b.length === 1 ? a < b ? -1 : 1 : -1;
|
|
@@ -25,7 +26,7 @@ function compareKey(a, b) {
|
|
|
25
26
|
var Node = class {
|
|
26
27
|
index;
|
|
27
28
|
varIndex;
|
|
28
|
-
children =
|
|
29
|
+
children = /* @__PURE__ */ Object.create(null);
|
|
29
30
|
insert(tokens, index, paramMap, context, pathErrorCheckOnly) {
|
|
30
31
|
if (tokens.length === 0) {
|
|
31
32
|
if (this.index !== void 0) {
|
|
@@ -87,7 +88,7 @@ var Node = class {
|
|
|
87
88
|
const childKeys = Object.keys(this.children).sort(compareKey);
|
|
88
89
|
const strList = childKeys.map((k) => {
|
|
89
90
|
const c = this.children[k];
|
|
90
|
-
return (typeof c.varIndex === "number" ? `(${k})@${c.varIndex}` : k) + c.buildRegExpStr();
|
|
91
|
+
return (typeof c.varIndex === "number" ? `(${k})@${c.varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr();
|
|
91
92
|
});
|
|
92
93
|
if (typeof this.index === "number") {
|
|
93
94
|
strList.unshift(`#${this.index}`);
|
|
@@ -8,15 +8,15 @@ import { checkOptionalParameter } from "../../utils/url.js";
|
|
|
8
8
|
import { PATH_ERROR } from "./node.js";
|
|
9
9
|
import { Trie } from "./trie.js";
|
|
10
10
|
var emptyParam = [];
|
|
11
|
-
var nullMatcher = [/^$/, [],
|
|
12
|
-
var wildcardRegExpCache =
|
|
11
|
+
var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
|
|
12
|
+
var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
13
13
|
function buildWildcardRegExp(path) {
|
|
14
14
|
return wildcardRegExpCache[path] ??= new RegExp(
|
|
15
15
|
path === "*" ? "" : `^${path.replace(/\/\*/, "(?:|/.*)")}$`
|
|
16
16
|
);
|
|
17
17
|
}
|
|
18
18
|
function clearWildcardRegExpCache() {
|
|
19
|
-
wildcardRegExpCache =
|
|
19
|
+
wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
20
20
|
}
|
|
21
21
|
function buildMatcherFromPreprocessedRoutes(routes) {
|
|
22
22
|
const trie = new Trie();
|
|
@@ -29,11 +29,11 @@ function buildMatcherFromPreprocessedRoutes(routes) {
|
|
|
29
29
|
).sort(
|
|
30
30
|
([isStaticA, pathA], [isStaticB, pathB]) => isStaticA ? 1 : isStaticB ? -1 : pathA.length - pathB.length
|
|
31
31
|
);
|
|
32
|
-
const staticMap =
|
|
32
|
+
const staticMap = /* @__PURE__ */ Object.create(null);
|
|
33
33
|
for (let i = 0, j = -1, len = routesWithStaticPathFlag.length; i < len; i++) {
|
|
34
34
|
const [pathErrorCheckOnly, path, handlers] = routesWithStaticPathFlag[i];
|
|
35
35
|
if (pathErrorCheckOnly) {
|
|
36
|
-
staticMap[path] = [handlers.map(([h]) => [h,
|
|
36
|
+
staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
|
|
37
37
|
} else {
|
|
38
38
|
j++;
|
|
39
39
|
}
|
|
@@ -47,7 +47,7 @@ function buildMatcherFromPreprocessedRoutes(routes) {
|
|
|
47
47
|
continue;
|
|
48
48
|
}
|
|
49
49
|
handlerData[j] = handlers.map(([h, paramCount]) => {
|
|
50
|
-
const paramIndexMap =
|
|
50
|
+
const paramIndexMap = /* @__PURE__ */ Object.create(null);
|
|
51
51
|
paramCount -= 1;
|
|
52
52
|
for (; paramCount >= 0; paramCount--) {
|
|
53
53
|
const [key, value] = paramAssoc[paramCount];
|
|
@@ -91,8 +91,8 @@ var RegExpRouter = class {
|
|
|
91
91
|
middleware;
|
|
92
92
|
routes;
|
|
93
93
|
constructor() {
|
|
94
|
-
this.middleware = { [METHOD_NAME_ALL]:
|
|
95
|
-
this.routes = { [METHOD_NAME_ALL]:
|
|
94
|
+
this.middleware = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
|
|
95
|
+
this.routes = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
|
|
96
96
|
}
|
|
97
97
|
add(method, path, handler) {
|
|
98
98
|
const { middleware, routes } = this;
|
|
@@ -102,7 +102,7 @@ var RegExpRouter = class {
|
|
|
102
102
|
if (!middleware[method]) {
|
|
103
103
|
;
|
|
104
104
|
[middleware, routes].forEach((handlerMap) => {
|
|
105
|
-
handlerMap[method] =
|
|
105
|
+
handlerMap[method] = /* @__PURE__ */ Object.create(null);
|
|
106
106
|
Object.keys(handlerMap[METHOD_NAME_ALL]).forEach((p) => {
|
|
107
107
|
handlerMap[method][p] = [...handlerMap[METHOD_NAME_ALL][p]];
|
|
108
108
|
});
|
|
@@ -169,7 +169,7 @@ var RegExpRouter = class {
|
|
|
169
169
|
return this.match(method, path);
|
|
170
170
|
}
|
|
171
171
|
buildAllMatchers() {
|
|
172
|
-
const matchers =
|
|
172
|
+
const matchers = /* @__PURE__ */ Object.create(null);
|
|
173
173
|
[...Object.keys(this.routes), ...Object.keys(this.middleware)].forEach((method) => {
|
|
174
174
|
matchers[method] ||= this.buildMatcher(method);
|
|
175
175
|
});
|
|
@@ -7,13 +7,13 @@ var Node = class {
|
|
|
7
7
|
patterns;
|
|
8
8
|
order = 0;
|
|
9
9
|
name;
|
|
10
|
-
params =
|
|
10
|
+
params = /* @__PURE__ */ Object.create(null);
|
|
11
11
|
constructor(method, handler, children) {
|
|
12
|
-
this.children = children ||
|
|
12
|
+
this.children = children || /* @__PURE__ */ Object.create(null);
|
|
13
13
|
this.methods = [];
|
|
14
14
|
this.name = "";
|
|
15
15
|
if (method && handler) {
|
|
16
|
-
const m =
|
|
16
|
+
const m = /* @__PURE__ */ Object.create(null);
|
|
17
17
|
m[method] = { handler, possibleKeys: [], score: 0, name: this.name };
|
|
18
18
|
this.methods = [m];
|
|
19
19
|
}
|
|
@@ -50,7 +50,7 @@ var Node = class {
|
|
|
50
50
|
if (!curNode.methods.length) {
|
|
51
51
|
curNode.methods = [];
|
|
52
52
|
}
|
|
53
|
-
const m =
|
|
53
|
+
const m = /* @__PURE__ */ Object.create(null);
|
|
54
54
|
const handlerSet = {
|
|
55
55
|
handler,
|
|
56
56
|
possibleKeys: possibleKeys.filter((v, i, a) => a.indexOf(v) === i),
|
|
@@ -66,9 +66,9 @@ var Node = class {
|
|
|
66
66
|
for (let i = 0, len = node.methods.length; i < len; i++) {
|
|
67
67
|
const m = node.methods[i];
|
|
68
68
|
const handlerSet = m[method] || m[METHOD_NAME_ALL];
|
|
69
|
-
const processedSet =
|
|
69
|
+
const processedSet = /* @__PURE__ */ Object.create(null);
|
|
70
70
|
if (handlerSet !== void 0) {
|
|
71
|
-
handlerSet.params =
|
|
71
|
+
handlerSet.params = /* @__PURE__ */ Object.create(null);
|
|
72
72
|
handlerSet.possibleKeys.forEach((key) => {
|
|
73
73
|
const processed = processedSet[handlerSet.name];
|
|
74
74
|
handlerSet.params[key] = params[key] && !processed ? params[key] : nodeParams[key] ?? params[key];
|
|
@@ -81,7 +81,7 @@ var Node = class {
|
|
|
81
81
|
}
|
|
82
82
|
search(method, path) {
|
|
83
83
|
const handlerSets = [];
|
|
84
|
-
this.params =
|
|
84
|
+
this.params = /* @__PURE__ */ Object.create(null);
|
|
85
85
|
const curNode = this;
|
|
86
86
|
let curNodes = [curNode];
|
|
87
87
|
const parts = splitPath(path);
|
|
@@ -96,9 +96,11 @@ var Node = class {
|
|
|
96
96
|
nextNode.params = node.params;
|
|
97
97
|
if (isLast === true) {
|
|
98
98
|
if (nextNode.children["*"]) {
|
|
99
|
-
handlerSets.push(
|
|
99
|
+
handlerSets.push(
|
|
100
|
+
...this.gHSets(nextNode.children["*"], method, node.params, /* @__PURE__ */ Object.create(null))
|
|
101
|
+
);
|
|
100
102
|
}
|
|
101
|
-
handlerSets.push(...this.gHSets(nextNode, method, node.params,
|
|
103
|
+
handlerSets.push(...this.gHSets(nextNode, method, node.params, /* @__PURE__ */ Object.create(null)));
|
|
102
104
|
} else {
|
|
103
105
|
tempNodes.push(nextNode);
|
|
104
106
|
}
|
|
@@ -109,7 +111,7 @@ var Node = class {
|
|
|
109
111
|
if (pattern === "*") {
|
|
110
112
|
const astNode = node.children["*"];
|
|
111
113
|
if (astNode) {
|
|
112
|
-
handlerSets.push(...this.gHSets(astNode, method, node.params,
|
|
114
|
+
handlerSets.push(...this.gHSets(astNode, method, node.params, /* @__PURE__ */ Object.create(null)));
|
|
113
115
|
tempNodes.push(astNode);
|
|
114
116
|
}
|
|
115
117
|
continue;
|
|
@@ -21,8 +21,8 @@ export interface ToSSGResult {
|
|
|
21
21
|
files: string[];
|
|
22
22
|
error?: Error;
|
|
23
23
|
}
|
|
24
|
-
export type BeforeRequestHook = (req: Request) => Request | false
|
|
25
|
-
export type AfterResponseHook = (res: Response) => Response | false
|
|
24
|
+
export type BeforeRequestHook = (req: Request) => Request | false | Promise<Request | false>;
|
|
25
|
+
export type AfterResponseHook = (res: Response) => Response | false | Promise<Response | false>;
|
|
26
26
|
export type AfterGenerateHook = (result: ToSSGResult) => void | Promise<void>;
|
|
27
27
|
export interface ToSSGOptions {
|
|
28
28
|
dir?: string;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -412,7 +412,7 @@ export type AddParam<I, P extends string> = ParamKeys<P> extends never ? I : I e
|
|
|
412
412
|
param: UnionToIntersection<ParamKeyToRecord<ParamKeys<P>>>;
|
|
413
413
|
};
|
|
414
414
|
type AddDollar<T extends string> = `$${Lowercase<T>}`;
|
|
415
|
-
export type MergePath<A extends string, B extends string> = A extends '' ? B : A extends '/' ? B : A extends `${infer P}/` ? B extends `/${infer Q}` ? `${P}/${Q}` : `${P}/${B}` : B extends `/${infer Q}` ? Q extends '' ? A : `${A}/${Q}` : `${A}/${B}`;
|
|
415
|
+
export type MergePath<A extends string, B extends string> = B extends '' ? MergePath<A, '/'> : A extends '' ? B : A extends '/' ? B : A extends `${infer P}/` ? B extends `/${infer Q}` ? `${P}/${Q}` : `${P}/${B}` : B extends `/${infer Q}` ? Q extends '' ? A : `${A}/${Q}` : `${A}/${B}`;
|
|
416
416
|
export type TypedResponse<T = unknown> = {
|
|
417
417
|
data: T;
|
|
418
418
|
format: 'json';
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
export type Cookie = Record<string, string>;
|
|
2
2
|
export type SignedCookie = Record<string, string | false>;
|
|
3
|
+
type PartitionCookieConstraint = {
|
|
4
|
+
partition: true;
|
|
5
|
+
secure: true;
|
|
6
|
+
} | {
|
|
7
|
+
partition?: boolean;
|
|
8
|
+
secure?: boolean;
|
|
9
|
+
};
|
|
10
|
+
type SecureCookieConstraint = {
|
|
11
|
+
secure: true;
|
|
12
|
+
};
|
|
13
|
+
type HostCookieConstraint = {
|
|
14
|
+
secure: true;
|
|
15
|
+
path: '/';
|
|
16
|
+
domain?: undefined;
|
|
17
|
+
};
|
|
3
18
|
export type CookieOptions = {
|
|
4
19
|
domain?: string;
|
|
5
20
|
expires?: Date;
|
|
@@ -11,9 +26,11 @@ export type CookieOptions = {
|
|
|
11
26
|
sameSite?: 'Strict' | 'Lax' | 'None';
|
|
12
27
|
partitioned?: boolean;
|
|
13
28
|
prefix?: CookiePrefixOptions;
|
|
14
|
-
};
|
|
29
|
+
} & PartitionCookieConstraint;
|
|
15
30
|
export type CookiePrefixOptions = 'host' | 'secure';
|
|
31
|
+
export type CookieConstraint<Name> = Name extends `__Secure-${string}` ? CookieOptions & SecureCookieConstraint : Name extends `__Host-${string}` ? CookieOptions & HostCookieConstraint : CookieOptions;
|
|
16
32
|
export declare const parse: (cookie: string, name?: string) => Cookie;
|
|
17
33
|
export declare const parseSigned: (cookie: string, secret: string | BufferSource, name?: string) => Promise<SignedCookie>;
|
|
18
|
-
export declare const serialize: (name:
|
|
34
|
+
export declare const serialize: <Name extends string>(name: Name, value: string, opt?: CookieConstraint<Name> | undefined) => string;
|
|
19
35
|
export declare const serializeSigned: (name: string, value: string, secret: string | BufferSource, opt?: CookieOptions) => Promise<string>;
|
|
36
|
+
export {};
|
package/dist/utils/cookie.js
CHANGED
|
@@ -119,7 +119,7 @@ var _serialize = (name, value, opt = {}) => {
|
|
|
119
119
|
}
|
|
120
120
|
return cookie;
|
|
121
121
|
};
|
|
122
|
-
var serialize = (name, value, opt
|
|
122
|
+
var serialize = (name, value, opt) => {
|
|
123
123
|
value = encodeURIComponent(value);
|
|
124
124
|
return _serialize(name, value, opt);
|
|
125
125
|
};
|
package/dist/utils/url.js
CHANGED
|
@@ -51,8 +51,9 @@ var getPattern = (label) => {
|
|
|
51
51
|
return null;
|
|
52
52
|
};
|
|
53
53
|
var getPath = (request) => {
|
|
54
|
-
const
|
|
55
|
-
|
|
54
|
+
const url = request.url;
|
|
55
|
+
const queryIndex = url.indexOf("?", 8);
|
|
56
|
+
return url.slice(url.indexOf("/", 8), queryIndex === -1 ? void 0 : queryIndex);
|
|
56
57
|
};
|
|
57
58
|
var getQueryStrings = (url) => {
|
|
58
59
|
const queryIndex = url.indexOf("?", 8);
|
|
@@ -6,6 +6,7 @@ var validator = (target, validationFunc) => {
|
|
|
6
6
|
return async (c, next) => {
|
|
7
7
|
let value = {};
|
|
8
8
|
const contentType = c.req.header("Content-Type");
|
|
9
|
+
const bodyTypes = ["text", "arrayBuffer", "blob"];
|
|
9
10
|
switch (target) {
|
|
10
11
|
case "json":
|
|
11
12
|
if (!contentType || !contentType.startsWith("application/json")) {
|
|
@@ -13,11 +14,19 @@ var validator = (target, validationFunc) => {
|
|
|
13
14
|
throw new HTTPException(400, { message });
|
|
14
15
|
}
|
|
15
16
|
if (c.req.bodyCache.json) {
|
|
16
|
-
value =
|
|
17
|
+
value = c.req.bodyCache.json;
|
|
17
18
|
break;
|
|
18
19
|
}
|
|
19
20
|
try {
|
|
20
|
-
|
|
21
|
+
let arrayBuffer = void 0;
|
|
22
|
+
for (const type of bodyTypes) {
|
|
23
|
+
const body = c.req.bodyCache[type];
|
|
24
|
+
if (body) {
|
|
25
|
+
arrayBuffer = await new Response(await body).arrayBuffer();
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
arrayBuffer ??= await c.req.raw.arrayBuffer();
|
|
21
30
|
value = await new Response(arrayBuffer).json();
|
|
22
31
|
c.req.bodyCache.json = value;
|
|
23
32
|
c.req.bodyCache.arrayBuffer = arrayBuffer;
|
|
@@ -27,23 +36,31 @@ var validator = (target, validationFunc) => {
|
|
|
27
36
|
}
|
|
28
37
|
break;
|
|
29
38
|
case "form": {
|
|
39
|
+
if (!contentType) {
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
30
42
|
if (c.req.bodyCache.formData) {
|
|
31
43
|
value = c.req.bodyCache.formData;
|
|
32
44
|
break;
|
|
33
45
|
}
|
|
34
46
|
try {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
});
|
|
43
|
-
value = form;
|
|
44
|
-
c.req.bodyCache.formData = formData;
|
|
45
|
-
c.req.bodyCache.arrayBuffer = arrayBuffer;
|
|
47
|
+
let arrayBuffer = void 0;
|
|
48
|
+
for (const type of bodyTypes) {
|
|
49
|
+
const body = c.req.bodyCache[type];
|
|
50
|
+
if (body) {
|
|
51
|
+
arrayBuffer = await new Response(await body).arrayBuffer();
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
46
54
|
}
|
|
55
|
+
arrayBuffer ??= await c.req.arrayBuffer();
|
|
56
|
+
const formData = await bufferToFormData(arrayBuffer, contentType);
|
|
57
|
+
const form = {};
|
|
58
|
+
formData.forEach((value2, key) => {
|
|
59
|
+
form[key] = value2;
|
|
60
|
+
});
|
|
61
|
+
value = form;
|
|
62
|
+
c.req.bodyCache.formData = formData;
|
|
63
|
+
c.req.bodyCache.arrayBuffer = arrayBuffer;
|
|
47
64
|
} catch (e) {
|
|
48
65
|
let message = "Malformed FormData request.";
|
|
49
66
|
message += e instanceof Error ? ` ${e.message}` : ` ${String(e)}`;
|