@hot-updater/console 0.12.6 → 0.12.7
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/assets/index-CiYz-DpZ.js +585 -0
- package/dist/assets/index-y9HrkcYR.css +1 -0
- package/dist/index.cjs +2464 -1943
- package/dist/index.html +2 -2
- package/dist/index.js +971 -451
- package/dist/src/components/ui/button.d.ts +1 -1
- package/dist/src/components/ui/toast.d.ts +41 -0
- package/dist/src/lib/api.d.ts +2 -11
- package/dist/src-server/index.d.ts +2 -11
- package/dist/src-server/rpc.d.ts +3 -23
- package/package.json +7 -8
- package/dist/assets/index-B_xkX-3E.js +0 -585
- package/dist/assets/index-CvELDnIr.css +0 -1
- package/dist/src-server/type.spec.d.ts +0 -1
package/dist/index.cjs
CHANGED
|
@@ -2,7 +2,838 @@
|
|
|
2
2
|
const __rslib_import_meta_url__ = /*#__PURE__*/ function() {
|
|
3
3
|
return 'undefined' == typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
|
|
4
4
|
}();
|
|
5
|
-
var
|
|
5
|
+
var __webpack_modules__ = {
|
|
6
|
+
"../../node_modules/.pnpm/@hono+typia-validator@0.1.0_hono@4.6.3_typia@8.0.3_@samchon+openapi@3.1.0_typescript@5.6.3_/node_modules/@hono/typia-validator/dist/cjs/index.js": function(__unused_webpack_module, exports1, __webpack_require__) {
|
|
7
|
+
exports1.typiaValidator = void 0;
|
|
8
|
+
const validator_1 = __webpack_require__("../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/cjs/validator/index.js");
|
|
9
|
+
const typiaValidator = (target, validate, hook)=>(0, validator_1.validator)(target, async (value, c)=>{
|
|
10
|
+
const result = validate(value);
|
|
11
|
+
if (hook) {
|
|
12
|
+
const hookResult = await hook({
|
|
13
|
+
...result,
|
|
14
|
+
data: value
|
|
15
|
+
}, c);
|
|
16
|
+
if (hookResult) {
|
|
17
|
+
if (hookResult instanceof Response || hookResult instanceof Promise) return hookResult;
|
|
18
|
+
if ('response' in hookResult) return hookResult.response;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (!result.success) return c.json({
|
|
22
|
+
success: false,
|
|
23
|
+
error: result.errors
|
|
24
|
+
}, 400);
|
|
25
|
+
return result.data;
|
|
26
|
+
});
|
|
27
|
+
exports1.typiaValidator = typiaValidator;
|
|
28
|
+
},
|
|
29
|
+
"../../node_modules/.pnpm/typia@8.0.3_@samchon+openapi@3.1.0_typescript@5.6.3/node_modules/typia/lib/internal/_validateReport.js": function(__unused_webpack_module, exports1) {
|
|
30
|
+
exports1._validateReport = void 0;
|
|
31
|
+
const _validateReport = (array)=>{
|
|
32
|
+
const reportable = (path)=>{
|
|
33
|
+
if (0 === array.length) return true;
|
|
34
|
+
const last = array[array.length - 1].path;
|
|
35
|
+
return path.length > last.length || last.substring(0, path.length) !== path;
|
|
36
|
+
};
|
|
37
|
+
return (exceptable, error)=>{
|
|
38
|
+
if (exceptable && reportable(error.path)) array.push(error);
|
|
39
|
+
return false;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
exports1._validateReport = _validateReport;
|
|
43
|
+
},
|
|
44
|
+
"../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/cjs/helper/cookie/index.js": function(module, __unused_webpack_exports, __webpack_require__) {
|
|
45
|
+
var __defProp = Object.defineProperty;
|
|
46
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
47
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
48
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
49
|
+
var __export = (target, all)=>{
|
|
50
|
+
for(var name in all)__defProp(target, name, {
|
|
51
|
+
get: all[name],
|
|
52
|
+
enumerable: true
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
var __copyProps = (to, from, except, desc)=>{
|
|
56
|
+
if (from && "object" == typeof from || "function" == typeof from) {
|
|
57
|
+
for (let key of __getOwnPropNames(from))if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
58
|
+
get: ()=>from[key],
|
|
59
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return to;
|
|
63
|
+
};
|
|
64
|
+
var __toCommonJS = (mod)=>__copyProps(__defProp({}, "__esModule", {
|
|
65
|
+
value: true
|
|
66
|
+
}), mod);
|
|
67
|
+
var cookie_exports = {};
|
|
68
|
+
__export(cookie_exports, {
|
|
69
|
+
deleteCookie: ()=>deleteCookie,
|
|
70
|
+
getCookie: ()=>getCookie,
|
|
71
|
+
getSignedCookie: ()=>getSignedCookie,
|
|
72
|
+
setCookie: ()=>setCookie,
|
|
73
|
+
setSignedCookie: ()=>setSignedCookie
|
|
74
|
+
});
|
|
75
|
+
module.exports = __toCommonJS(cookie_exports);
|
|
76
|
+
var import_cookie = __webpack_require__("../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/cjs/utils/cookie.js");
|
|
77
|
+
const getCookie = (c, key, prefix)=>{
|
|
78
|
+
const cookie = c.req.raw.headers.get("Cookie");
|
|
79
|
+
if ("string" == typeof key) {
|
|
80
|
+
if (!cookie) return;
|
|
81
|
+
let finalKey = key;
|
|
82
|
+
if ("secure" === prefix) finalKey = "__Secure-" + key;
|
|
83
|
+
else if ("host" === prefix) finalKey = "__Host-" + key;
|
|
84
|
+
const obj2 = (0, import_cookie.parse)(cookie, finalKey);
|
|
85
|
+
return obj2[finalKey];
|
|
86
|
+
}
|
|
87
|
+
if (!cookie) return {};
|
|
88
|
+
const obj = (0, import_cookie.parse)(cookie);
|
|
89
|
+
return obj;
|
|
90
|
+
};
|
|
91
|
+
const getSignedCookie = async (c, secret, key, prefix)=>{
|
|
92
|
+
const cookie = c.req.raw.headers.get("Cookie");
|
|
93
|
+
if ("string" == typeof key) {
|
|
94
|
+
if (!cookie) return;
|
|
95
|
+
let finalKey = key;
|
|
96
|
+
if ("secure" === prefix) finalKey = "__Secure-" + key;
|
|
97
|
+
else if ("host" === prefix) finalKey = "__Host-" + key;
|
|
98
|
+
const obj2 = await (0, import_cookie.parseSigned)(cookie, secret, finalKey);
|
|
99
|
+
return obj2[finalKey];
|
|
100
|
+
}
|
|
101
|
+
if (!cookie) return {};
|
|
102
|
+
const obj = await (0, import_cookie.parseSigned)(cookie, secret);
|
|
103
|
+
return obj;
|
|
104
|
+
};
|
|
105
|
+
const setCookie = (c, name, value, opt)=>{
|
|
106
|
+
let cookie;
|
|
107
|
+
cookie = opt?.prefix === "secure" ? (0, import_cookie.serialize)("__Secure-" + name, value, {
|
|
108
|
+
path: "/",
|
|
109
|
+
...opt,
|
|
110
|
+
secure: true
|
|
111
|
+
}) : opt?.prefix === "host" ? (0, import_cookie.serialize)("__Host-" + name, value, {
|
|
112
|
+
...opt,
|
|
113
|
+
path: "/",
|
|
114
|
+
secure: true,
|
|
115
|
+
domain: void 0
|
|
116
|
+
}) : (0, import_cookie.serialize)(name, value, {
|
|
117
|
+
path: "/",
|
|
118
|
+
...opt
|
|
119
|
+
});
|
|
120
|
+
c.header("set-cookie", cookie, {
|
|
121
|
+
append: true
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
const setSignedCookie = async (c, name, value, secret, opt)=>{
|
|
125
|
+
let cookie;
|
|
126
|
+
cookie = opt?.prefix === "secure" ? await (0, import_cookie.serializeSigned)("__Secure-" + name, value, secret, {
|
|
127
|
+
path: "/",
|
|
128
|
+
...opt,
|
|
129
|
+
secure: true
|
|
130
|
+
}) : opt?.prefix === "host" ? await (0, import_cookie.serializeSigned)("__Host-" + name, value, secret, {
|
|
131
|
+
...opt,
|
|
132
|
+
path: "/",
|
|
133
|
+
secure: true,
|
|
134
|
+
domain: void 0
|
|
135
|
+
}) : await (0, import_cookie.serializeSigned)(name, value, secret, {
|
|
136
|
+
path: "/",
|
|
137
|
+
...opt
|
|
138
|
+
});
|
|
139
|
+
c.header("set-cookie", cookie, {
|
|
140
|
+
append: true
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
const deleteCookie = (c, name, opt)=>{
|
|
144
|
+
const deletedCookie = getCookie(c, name);
|
|
145
|
+
setCookie(c, name, "", {
|
|
146
|
+
...opt,
|
|
147
|
+
maxAge: 0
|
|
148
|
+
});
|
|
149
|
+
return deletedCookie;
|
|
150
|
+
};
|
|
151
|
+
},
|
|
152
|
+
"../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/cjs/http-exception.js": function(module) {
|
|
153
|
+
var __defProp = Object.defineProperty;
|
|
154
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
155
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
156
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
157
|
+
var __export = (target, all)=>{
|
|
158
|
+
for(var name in all)__defProp(target, name, {
|
|
159
|
+
get: all[name],
|
|
160
|
+
enumerable: true
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
var __copyProps = (to, from, except, desc)=>{
|
|
164
|
+
if (from && "object" == typeof from || "function" == typeof from) {
|
|
165
|
+
for (let key of __getOwnPropNames(from))if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
166
|
+
get: ()=>from[key],
|
|
167
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
return to;
|
|
171
|
+
};
|
|
172
|
+
var __toCommonJS = (mod)=>__copyProps(__defProp({}, "__esModule", {
|
|
173
|
+
value: true
|
|
174
|
+
}), mod);
|
|
175
|
+
var http_exception_exports = {};
|
|
176
|
+
__export(http_exception_exports, {
|
|
177
|
+
HTTPException: ()=>HTTPException
|
|
178
|
+
});
|
|
179
|
+
module.exports = __toCommonJS(http_exception_exports);
|
|
180
|
+
class HTTPException extends Error {
|
|
181
|
+
res;
|
|
182
|
+
status;
|
|
183
|
+
constructor(status = 500, options){
|
|
184
|
+
super(options?.message, {
|
|
185
|
+
cause: options?.cause
|
|
186
|
+
});
|
|
187
|
+
this.res = options?.res;
|
|
188
|
+
this.status = status;
|
|
189
|
+
}
|
|
190
|
+
getResponse() {
|
|
191
|
+
if (this.res) {
|
|
192
|
+
const newResponse = new Response(this.res.body, {
|
|
193
|
+
status: this.status,
|
|
194
|
+
headers: this.res.headers
|
|
195
|
+
});
|
|
196
|
+
return newResponse;
|
|
197
|
+
}
|
|
198
|
+
return new Response(this.message, {
|
|
199
|
+
status: this.status
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
"../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/cjs/utils/buffer.js": function(module, __unused_webpack_exports, __webpack_require__) {
|
|
205
|
+
var __defProp = Object.defineProperty;
|
|
206
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
207
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
208
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
209
|
+
var __export = (target, all)=>{
|
|
210
|
+
for(var name in all)__defProp(target, name, {
|
|
211
|
+
get: all[name],
|
|
212
|
+
enumerable: true
|
|
213
|
+
});
|
|
214
|
+
};
|
|
215
|
+
var __copyProps = (to, from, except, desc)=>{
|
|
216
|
+
if (from && "object" == typeof from || "function" == typeof from) {
|
|
217
|
+
for (let key of __getOwnPropNames(from))if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
218
|
+
get: ()=>from[key],
|
|
219
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
return to;
|
|
223
|
+
};
|
|
224
|
+
var __toCommonJS = (mod)=>__copyProps(__defProp({}, "__esModule", {
|
|
225
|
+
value: true
|
|
226
|
+
}), mod);
|
|
227
|
+
var buffer_exports = {};
|
|
228
|
+
__export(buffer_exports, {
|
|
229
|
+
bufferToFormData: ()=>bufferToFormData,
|
|
230
|
+
bufferToString: ()=>bufferToString,
|
|
231
|
+
equal: ()=>equal,
|
|
232
|
+
timingSafeEqual: ()=>timingSafeEqual
|
|
233
|
+
});
|
|
234
|
+
module.exports = __toCommonJS(buffer_exports);
|
|
235
|
+
var import_crypto = __webpack_require__("../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/cjs/utils/crypto.js");
|
|
236
|
+
const equal = (a, b)=>{
|
|
237
|
+
if (a === b) return true;
|
|
238
|
+
if (a.byteLength !== b.byteLength) return false;
|
|
239
|
+
const va = new DataView(a);
|
|
240
|
+
const vb = new DataView(b);
|
|
241
|
+
let i = va.byteLength;
|
|
242
|
+
while(i--)if (va.getUint8(i) !== vb.getUint8(i)) return false;
|
|
243
|
+
return true;
|
|
244
|
+
};
|
|
245
|
+
const timingSafeEqual = async (a, b, hashFunction)=>{
|
|
246
|
+
if (!hashFunction) hashFunction = import_crypto.sha256;
|
|
247
|
+
const [sa, sb] = await Promise.all([
|
|
248
|
+
hashFunction(a),
|
|
249
|
+
hashFunction(b)
|
|
250
|
+
]);
|
|
251
|
+
if (!sa || !sb) return false;
|
|
252
|
+
return sa === sb && a === b;
|
|
253
|
+
};
|
|
254
|
+
const bufferToString = (buffer)=>{
|
|
255
|
+
if (buffer instanceof ArrayBuffer) {
|
|
256
|
+
const enc = new TextDecoder("utf-8");
|
|
257
|
+
return enc.decode(buffer);
|
|
258
|
+
}
|
|
259
|
+
return buffer;
|
|
260
|
+
};
|
|
261
|
+
const bufferToFormData = (arrayBuffer, contentType)=>{
|
|
262
|
+
const response = new Response(arrayBuffer, {
|
|
263
|
+
headers: {
|
|
264
|
+
"Content-Type": contentType
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
return response.formData();
|
|
268
|
+
};
|
|
269
|
+
},
|
|
270
|
+
"../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/cjs/utils/cookie.js": function(module, __unused_webpack_exports, __webpack_require__) {
|
|
271
|
+
var __defProp = Object.defineProperty;
|
|
272
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
273
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
274
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
275
|
+
var __export = (target, all)=>{
|
|
276
|
+
for(var name in all)__defProp(target, name, {
|
|
277
|
+
get: all[name],
|
|
278
|
+
enumerable: true
|
|
279
|
+
});
|
|
280
|
+
};
|
|
281
|
+
var __copyProps = (to, from, except, desc)=>{
|
|
282
|
+
if (from && "object" == typeof from || "function" == typeof from) {
|
|
283
|
+
for (let key of __getOwnPropNames(from))if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
284
|
+
get: ()=>from[key],
|
|
285
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
return to;
|
|
289
|
+
};
|
|
290
|
+
var __toCommonJS = (mod)=>__copyProps(__defProp({}, "__esModule", {
|
|
291
|
+
value: true
|
|
292
|
+
}), mod);
|
|
293
|
+
var cookie_exports = {};
|
|
294
|
+
__export(cookie_exports, {
|
|
295
|
+
parse: ()=>parse,
|
|
296
|
+
parseSigned: ()=>parseSigned,
|
|
297
|
+
serialize: ()=>serialize,
|
|
298
|
+
serializeSigned: ()=>serializeSigned
|
|
299
|
+
});
|
|
300
|
+
module.exports = __toCommonJS(cookie_exports);
|
|
301
|
+
var import_url = __webpack_require__("../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/cjs/utils/url.js");
|
|
302
|
+
const algorithm = {
|
|
303
|
+
name: "HMAC",
|
|
304
|
+
hash: "SHA-256"
|
|
305
|
+
};
|
|
306
|
+
const getCryptoKey = async (secret)=>{
|
|
307
|
+
const secretBuf = "string" == typeof secret ? new TextEncoder().encode(secret) : secret;
|
|
308
|
+
return await crypto.subtle.importKey("raw", secretBuf, algorithm, false, [
|
|
309
|
+
"sign",
|
|
310
|
+
"verify"
|
|
311
|
+
]);
|
|
312
|
+
};
|
|
313
|
+
const makeSignature = async (value, secret)=>{
|
|
314
|
+
const key = await getCryptoKey(secret);
|
|
315
|
+
const signature = await crypto.subtle.sign(algorithm.name, key, new TextEncoder().encode(value));
|
|
316
|
+
return btoa(String.fromCharCode(...new Uint8Array(signature)));
|
|
317
|
+
};
|
|
318
|
+
const verifySignature = async (base64Signature, value, secret)=>{
|
|
319
|
+
try {
|
|
320
|
+
const signatureBinStr = atob(base64Signature);
|
|
321
|
+
const signature = new Uint8Array(signatureBinStr.length);
|
|
322
|
+
for(let i = 0, len = signatureBinStr.length; i < len; i++)signature[i] = signatureBinStr.charCodeAt(i);
|
|
323
|
+
return await crypto.subtle.verify(algorithm, secret, signature, new TextEncoder().encode(value));
|
|
324
|
+
} catch {
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
const validCookieNameRegEx = /^[\w!#$%&'*.^`|~+-]+$/;
|
|
329
|
+
const validCookieValueRegEx = /^[ !#-:<-[\]-~]*$/;
|
|
330
|
+
const parse = (cookie, name)=>{
|
|
331
|
+
const pairs = cookie.trim().split(";");
|
|
332
|
+
return pairs.reduce((parsedCookie, pairStr)=>{
|
|
333
|
+
pairStr = pairStr.trim();
|
|
334
|
+
const valueStartPos = pairStr.indexOf("=");
|
|
335
|
+
if (-1 === valueStartPos) return parsedCookie;
|
|
336
|
+
const cookieName = pairStr.substring(0, valueStartPos).trim();
|
|
337
|
+
if (name && name !== cookieName || !validCookieNameRegEx.test(cookieName)) return parsedCookie;
|
|
338
|
+
let cookieValue = pairStr.substring(valueStartPos + 1).trim();
|
|
339
|
+
if (cookieValue.startsWith('"') && cookieValue.endsWith('"')) cookieValue = cookieValue.slice(1, -1);
|
|
340
|
+
if (validCookieValueRegEx.test(cookieValue)) parsedCookie[cookieName] = (0, import_url.decodeURIComponent_)(cookieValue);
|
|
341
|
+
return parsedCookie;
|
|
342
|
+
}, {});
|
|
343
|
+
};
|
|
344
|
+
const parseSigned = async (cookie, secret, name)=>{
|
|
345
|
+
const parsedCookie = {};
|
|
346
|
+
const secretKey = await getCryptoKey(secret);
|
|
347
|
+
for (const [key, value] of Object.entries(parse(cookie, name))){
|
|
348
|
+
const signatureStartPos = value.lastIndexOf(".");
|
|
349
|
+
if (signatureStartPos < 1) continue;
|
|
350
|
+
const signedValue = value.substring(0, signatureStartPos);
|
|
351
|
+
const signature = value.substring(signatureStartPos + 1);
|
|
352
|
+
if (44 !== signature.length || !signature.endsWith("=")) continue;
|
|
353
|
+
const isVerified = await verifySignature(signature, signedValue, secretKey);
|
|
354
|
+
parsedCookie[key] = isVerified ? signedValue : false;
|
|
355
|
+
}
|
|
356
|
+
return parsedCookie;
|
|
357
|
+
};
|
|
358
|
+
const _serialize = (name, value, opt = {})=>{
|
|
359
|
+
let cookie = `${name}=${value}`;
|
|
360
|
+
if (name.startsWith("__Secure-") && !opt.secure) throw new Error("__Secure- Cookie must have Secure attributes");
|
|
361
|
+
if (name.startsWith("__Host-")) {
|
|
362
|
+
if (!opt.secure) throw new Error("__Host- Cookie must have Secure attributes");
|
|
363
|
+
if ("/" !== opt.path) throw new Error('__Host- Cookie must have Path attributes with "/"');
|
|
364
|
+
if (opt.domain) throw new Error("__Host- Cookie must not have Domain attributes");
|
|
365
|
+
}
|
|
366
|
+
if (opt && "number" == typeof opt.maxAge && opt.maxAge >= 0) {
|
|
367
|
+
if (opt.maxAge > 3456e4) throw new Error("Cookies Max-Age SHOULD NOT be greater than 400 days (34560000 seconds) in duration.");
|
|
368
|
+
cookie += `; Max-Age=${Math.floor(opt.maxAge)}`;
|
|
369
|
+
}
|
|
370
|
+
if (opt.domain && "host" !== opt.prefix) cookie += `; Domain=${opt.domain}`;
|
|
371
|
+
if (opt.path) cookie += `; Path=${opt.path}`;
|
|
372
|
+
if (opt.expires) {
|
|
373
|
+
if (opt.expires.getTime() - Date.now() > 3456e7) throw new Error("Cookies Expires SHOULD NOT be greater than 400 days (34560000 seconds) in the future.");
|
|
374
|
+
cookie += `; Expires=${opt.expires.toUTCString()}`;
|
|
375
|
+
}
|
|
376
|
+
if (opt.httpOnly) cookie += "; HttpOnly";
|
|
377
|
+
if (opt.secure) cookie += "; Secure";
|
|
378
|
+
if (opt.sameSite) cookie += `; SameSite=${opt.sameSite.charAt(0).toUpperCase() + opt.sameSite.slice(1)}`;
|
|
379
|
+
if (opt.partitioned) {
|
|
380
|
+
if (!opt.secure) throw new Error("Partitioned Cookie must have Secure attributes");
|
|
381
|
+
cookie += "; Partitioned";
|
|
382
|
+
}
|
|
383
|
+
return cookie;
|
|
384
|
+
};
|
|
385
|
+
const serialize = (name, value, opt)=>{
|
|
386
|
+
value = encodeURIComponent(value);
|
|
387
|
+
return _serialize(name, value, opt);
|
|
388
|
+
};
|
|
389
|
+
const serializeSigned = async (name, value, secret, opt = {})=>{
|
|
390
|
+
const signature = await makeSignature(value, secret);
|
|
391
|
+
value = `${value}.${signature}`;
|
|
392
|
+
value = encodeURIComponent(value);
|
|
393
|
+
return _serialize(name, value, opt);
|
|
394
|
+
};
|
|
395
|
+
},
|
|
396
|
+
"../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/cjs/utils/crypto.js": function(module) {
|
|
397
|
+
var __defProp = Object.defineProperty;
|
|
398
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
399
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
400
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
401
|
+
var __export = (target, all)=>{
|
|
402
|
+
for(var name in all)__defProp(target, name, {
|
|
403
|
+
get: all[name],
|
|
404
|
+
enumerable: true
|
|
405
|
+
});
|
|
406
|
+
};
|
|
407
|
+
var __copyProps = (to, from, except, desc)=>{
|
|
408
|
+
if (from && "object" == typeof from || "function" == typeof from) {
|
|
409
|
+
for (let key of __getOwnPropNames(from))if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
410
|
+
get: ()=>from[key],
|
|
411
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
return to;
|
|
415
|
+
};
|
|
416
|
+
var __toCommonJS = (mod)=>__copyProps(__defProp({}, "__esModule", {
|
|
417
|
+
value: true
|
|
418
|
+
}), mod);
|
|
419
|
+
var crypto_exports = {};
|
|
420
|
+
__export(crypto_exports, {
|
|
421
|
+
createHash: ()=>createHash,
|
|
422
|
+
md5: ()=>md5,
|
|
423
|
+
sha1: ()=>sha1,
|
|
424
|
+
sha256: ()=>sha256
|
|
425
|
+
});
|
|
426
|
+
module.exports = __toCommonJS(crypto_exports);
|
|
427
|
+
const sha256 = async (data)=>{
|
|
428
|
+
const algorithm = {
|
|
429
|
+
name: "SHA-256",
|
|
430
|
+
alias: "sha256"
|
|
431
|
+
};
|
|
432
|
+
const hash = await createHash(data, algorithm);
|
|
433
|
+
return hash;
|
|
434
|
+
};
|
|
435
|
+
const sha1 = async (data)=>{
|
|
436
|
+
const algorithm = {
|
|
437
|
+
name: "SHA-1",
|
|
438
|
+
alias: "sha1"
|
|
439
|
+
};
|
|
440
|
+
const hash = await createHash(data, algorithm);
|
|
441
|
+
return hash;
|
|
442
|
+
};
|
|
443
|
+
const md5 = async (data)=>{
|
|
444
|
+
const algorithm = {
|
|
445
|
+
name: "MD5",
|
|
446
|
+
alias: "md5"
|
|
447
|
+
};
|
|
448
|
+
const hash = await createHash(data, algorithm);
|
|
449
|
+
return hash;
|
|
450
|
+
};
|
|
451
|
+
const createHash = async (data, algorithm)=>{
|
|
452
|
+
let sourceBuffer;
|
|
453
|
+
if (data instanceof ReadableStream) {
|
|
454
|
+
let body = "";
|
|
455
|
+
const reader = data.getReader();
|
|
456
|
+
await reader?.read().then(async (chuck)=>{
|
|
457
|
+
const value = await createHash(chuck.value || "", algorithm);
|
|
458
|
+
body += value;
|
|
459
|
+
});
|
|
460
|
+
return body;
|
|
461
|
+
}
|
|
462
|
+
if (ArrayBuffer.isView(data) || data instanceof ArrayBuffer) sourceBuffer = data;
|
|
463
|
+
else {
|
|
464
|
+
if ("object" == typeof data) data = JSON.stringify(data);
|
|
465
|
+
sourceBuffer = new TextEncoder().encode(String(data));
|
|
466
|
+
}
|
|
467
|
+
if (crypto && crypto.subtle) {
|
|
468
|
+
const buffer = await crypto.subtle.digest({
|
|
469
|
+
name: algorithm.name
|
|
470
|
+
}, sourceBuffer);
|
|
471
|
+
const hash = Array.prototype.map.call(new Uint8Array(buffer), (x)=>("00" + x.toString(16)).slice(-2)).join("");
|
|
472
|
+
return hash;
|
|
473
|
+
}
|
|
474
|
+
return null;
|
|
475
|
+
};
|
|
476
|
+
},
|
|
477
|
+
"../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/cjs/utils/url.js": function(module) {
|
|
478
|
+
var __defProp = Object.defineProperty;
|
|
479
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
480
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
481
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
482
|
+
var __export = (target, all)=>{
|
|
483
|
+
for(var name in all)__defProp(target, name, {
|
|
484
|
+
get: all[name],
|
|
485
|
+
enumerable: true
|
|
486
|
+
});
|
|
487
|
+
};
|
|
488
|
+
var __copyProps = (to, from, except, desc)=>{
|
|
489
|
+
if (from && "object" == typeof from || "function" == typeof from) {
|
|
490
|
+
for (let key of __getOwnPropNames(from))if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
491
|
+
get: ()=>from[key],
|
|
492
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
return to;
|
|
496
|
+
};
|
|
497
|
+
var __toCommonJS = (mod)=>__copyProps(__defProp({}, "__esModule", {
|
|
498
|
+
value: true
|
|
499
|
+
}), mod);
|
|
500
|
+
var url_exports = {};
|
|
501
|
+
__export(url_exports, {
|
|
502
|
+
checkOptionalParameter: ()=>checkOptionalParameter,
|
|
503
|
+
decodeURIComponent_: ()=>decodeURIComponent_,
|
|
504
|
+
getPath: ()=>getPath,
|
|
505
|
+
getPathNoStrict: ()=>getPathNoStrict,
|
|
506
|
+
getPattern: ()=>getPattern,
|
|
507
|
+
getQueryParam: ()=>getQueryParam,
|
|
508
|
+
getQueryParams: ()=>getQueryParams,
|
|
509
|
+
getQueryStrings: ()=>getQueryStrings,
|
|
510
|
+
mergePath: ()=>mergePath,
|
|
511
|
+
splitPath: ()=>splitPath,
|
|
512
|
+
splitRoutingPath: ()=>splitRoutingPath
|
|
513
|
+
});
|
|
514
|
+
module.exports = __toCommonJS(url_exports);
|
|
515
|
+
const splitPath = (path)=>{
|
|
516
|
+
const paths = path.split("/");
|
|
517
|
+
if ("" === paths[0]) paths.shift();
|
|
518
|
+
return paths;
|
|
519
|
+
};
|
|
520
|
+
const splitRoutingPath = (routePath)=>{
|
|
521
|
+
const { groups, path } = extractGroupsFromPath(routePath);
|
|
522
|
+
const paths = splitPath(path);
|
|
523
|
+
return replaceGroupMarks(paths, groups);
|
|
524
|
+
};
|
|
525
|
+
const extractGroupsFromPath = (path)=>{
|
|
526
|
+
const groups = [];
|
|
527
|
+
path = path.replace(/\{[^}]+\}/g, (match, index)=>{
|
|
528
|
+
const mark = `@${index}`;
|
|
529
|
+
groups.push([
|
|
530
|
+
mark,
|
|
531
|
+
match
|
|
532
|
+
]);
|
|
533
|
+
return mark;
|
|
534
|
+
});
|
|
535
|
+
return {
|
|
536
|
+
groups,
|
|
537
|
+
path
|
|
538
|
+
};
|
|
539
|
+
};
|
|
540
|
+
const replaceGroupMarks = (paths, groups)=>{
|
|
541
|
+
for(let i = groups.length - 1; i >= 0; i--){
|
|
542
|
+
const [mark] = groups[i];
|
|
543
|
+
for(let j = paths.length - 1; j >= 0; j--)if (paths[j].includes(mark)) {
|
|
544
|
+
paths[j] = paths[j].replace(mark, groups[i][1]);
|
|
545
|
+
break;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
return paths;
|
|
549
|
+
};
|
|
550
|
+
const patternCache = {};
|
|
551
|
+
const getPattern = (label)=>{
|
|
552
|
+
if ("*" === label) return "*";
|
|
553
|
+
const match = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
554
|
+
if (match) {
|
|
555
|
+
if (!patternCache[label]) {
|
|
556
|
+
if (match[2]) patternCache[label] = [
|
|
557
|
+
label,
|
|
558
|
+
match[1],
|
|
559
|
+
new RegExp("^" + match[2] + "$")
|
|
560
|
+
];
|
|
561
|
+
else patternCache[label] = [
|
|
562
|
+
label,
|
|
563
|
+
match[1],
|
|
564
|
+
true
|
|
565
|
+
];
|
|
566
|
+
}
|
|
567
|
+
return patternCache[label];
|
|
568
|
+
}
|
|
569
|
+
return null;
|
|
570
|
+
};
|
|
571
|
+
const tryDecodeURI = (str)=>{
|
|
572
|
+
try {
|
|
573
|
+
return decodeURI(str);
|
|
574
|
+
} catch {
|
|
575
|
+
return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match)=>{
|
|
576
|
+
try {
|
|
577
|
+
return decodeURI(match);
|
|
578
|
+
} catch {
|
|
579
|
+
return match;
|
|
580
|
+
}
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
const getPath = (request)=>{
|
|
585
|
+
const url = request.url;
|
|
586
|
+
const start = url.indexOf("/", 8);
|
|
587
|
+
let i = start;
|
|
588
|
+
for(; i < url.length; i++){
|
|
589
|
+
const charCode = url.charCodeAt(i);
|
|
590
|
+
if (37 === charCode) {
|
|
591
|
+
const queryIndex = url.indexOf("?", i);
|
|
592
|
+
const path = url.slice(start, -1 === queryIndex ? void 0 : queryIndex);
|
|
593
|
+
return tryDecodeURI(path.includes("%25") ? path.replace(/%25/g, "%2525") : path);
|
|
594
|
+
}
|
|
595
|
+
if (63 === charCode) break;
|
|
596
|
+
}
|
|
597
|
+
return url.slice(start, i);
|
|
598
|
+
};
|
|
599
|
+
const getQueryStrings = (url)=>{
|
|
600
|
+
const queryIndex = url.indexOf("?", 8);
|
|
601
|
+
return -1 === queryIndex ? "" : "?" + url.slice(queryIndex + 1);
|
|
602
|
+
};
|
|
603
|
+
const getPathNoStrict = (request)=>{
|
|
604
|
+
const result = getPath(request);
|
|
605
|
+
return result.length > 1 && "/" === result[result.length - 1] ? result.slice(0, -1) : result;
|
|
606
|
+
};
|
|
607
|
+
const mergePath = (...paths)=>{
|
|
608
|
+
let p = "";
|
|
609
|
+
let endsWithSlash = false;
|
|
610
|
+
for (let path of paths){
|
|
611
|
+
if ("/" === p[p.length - 1]) {
|
|
612
|
+
p = p.slice(0, -1);
|
|
613
|
+
endsWithSlash = true;
|
|
614
|
+
}
|
|
615
|
+
if ("/" !== path[0]) path = `/${path}`;
|
|
616
|
+
if ("/" === path && endsWithSlash) p = `${p}/`;
|
|
617
|
+
else if ("/" !== path) p = `${p}${path}`;
|
|
618
|
+
if ("/" === path && "" === p) p = "/";
|
|
619
|
+
}
|
|
620
|
+
return p;
|
|
621
|
+
};
|
|
622
|
+
const checkOptionalParameter = (path)=>{
|
|
623
|
+
if (!path.match(/\:.+\?$/)) return null;
|
|
624
|
+
const segments = path.split("/");
|
|
625
|
+
const results = [];
|
|
626
|
+
let basePath = "";
|
|
627
|
+
segments.forEach((segment)=>{
|
|
628
|
+
if ("" === segment || /\:/.test(segment)) {
|
|
629
|
+
if (/\:/.test(segment)) {
|
|
630
|
+
if (/\?/.test(segment)) {
|
|
631
|
+
if (0 === results.length && "" === basePath) results.push("/");
|
|
632
|
+
else results.push(basePath);
|
|
633
|
+
const optionalSegment = segment.replace("?", "");
|
|
634
|
+
basePath += "/" + optionalSegment;
|
|
635
|
+
results.push(basePath);
|
|
636
|
+
} else basePath += "/" + segment;
|
|
637
|
+
}
|
|
638
|
+
} else basePath += "/" + segment;
|
|
639
|
+
});
|
|
640
|
+
return results.filter((v, i, a)=>a.indexOf(v) === i);
|
|
641
|
+
};
|
|
642
|
+
const _decodeURI = (value)=>{
|
|
643
|
+
if (!/[%+]/.test(value)) return value;
|
|
644
|
+
if (-1 !== value.indexOf("+")) value = value.replace(/\+/g, " ");
|
|
645
|
+
return /%/.test(value) ? decodeURIComponent_(value) : value;
|
|
646
|
+
};
|
|
647
|
+
const _getQueryParam = (url, key, multiple)=>{
|
|
648
|
+
let encoded;
|
|
649
|
+
if (!multiple && key && !/[%+]/.test(key)) {
|
|
650
|
+
let keyIndex2 = url.indexOf(`?${key}`, 8);
|
|
651
|
+
if (-1 === keyIndex2) keyIndex2 = url.indexOf(`&${key}`, 8);
|
|
652
|
+
while(-1 !== keyIndex2){
|
|
653
|
+
const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1);
|
|
654
|
+
if (61 === trailingKeyCode) {
|
|
655
|
+
const valueIndex = keyIndex2 + key.length + 2;
|
|
656
|
+
const endIndex = url.indexOf("&", valueIndex);
|
|
657
|
+
return _decodeURI(url.slice(valueIndex, -1 === endIndex ? void 0 : endIndex));
|
|
658
|
+
}
|
|
659
|
+
if (38 == trailingKeyCode || isNaN(trailingKeyCode)) return "";
|
|
660
|
+
keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
|
661
|
+
}
|
|
662
|
+
encoded = /[%+]/.test(url);
|
|
663
|
+
if (!encoded) return;
|
|
664
|
+
}
|
|
665
|
+
const results = {};
|
|
666
|
+
encoded ??= /[%+]/.test(url);
|
|
667
|
+
let keyIndex = url.indexOf("?", 8);
|
|
668
|
+
while(-1 !== keyIndex){
|
|
669
|
+
const nextKeyIndex = url.indexOf("&", keyIndex + 1);
|
|
670
|
+
let valueIndex = url.indexOf("=", keyIndex);
|
|
671
|
+
if (valueIndex > nextKeyIndex && -1 !== nextKeyIndex) valueIndex = -1;
|
|
672
|
+
let name = url.slice(keyIndex + 1, -1 === valueIndex ? -1 === nextKeyIndex ? void 0 : nextKeyIndex : valueIndex);
|
|
673
|
+
if (encoded) name = _decodeURI(name);
|
|
674
|
+
keyIndex = nextKeyIndex;
|
|
675
|
+
if ("" === name) continue;
|
|
676
|
+
let value;
|
|
677
|
+
if (-1 === valueIndex) value = "";
|
|
678
|
+
else {
|
|
679
|
+
value = url.slice(valueIndex + 1, -1 === nextKeyIndex ? void 0 : nextKeyIndex);
|
|
680
|
+
if (encoded) value = _decodeURI(value);
|
|
681
|
+
}
|
|
682
|
+
if (multiple) {
|
|
683
|
+
if (!(results[name] && Array.isArray(results[name]))) results[name] = [];
|
|
684
|
+
results[name].push(value);
|
|
685
|
+
} else results[name] ??= value;
|
|
686
|
+
}
|
|
687
|
+
return key ? results[key] : results;
|
|
688
|
+
};
|
|
689
|
+
const getQueryParam = _getQueryParam;
|
|
690
|
+
const getQueryParams = (url, key)=>_getQueryParam(url, key, true);
|
|
691
|
+
const decodeURIComponent_ = decodeURIComponent;
|
|
692
|
+
},
|
|
693
|
+
"../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/cjs/validator/index.js": function(module, __unused_webpack_exports, __webpack_require__) {
|
|
694
|
+
var __defProp = Object.defineProperty;
|
|
695
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
696
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
697
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
698
|
+
var __export = (target, all)=>{
|
|
699
|
+
for(var name in all)__defProp(target, name, {
|
|
700
|
+
get: all[name],
|
|
701
|
+
enumerable: true
|
|
702
|
+
});
|
|
703
|
+
};
|
|
704
|
+
var __copyProps = (to, from, except, desc)=>{
|
|
705
|
+
if (from && "object" == typeof from || "function" == typeof from) {
|
|
706
|
+
for (let key of __getOwnPropNames(from))if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
707
|
+
get: ()=>from[key],
|
|
708
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
return to;
|
|
712
|
+
};
|
|
713
|
+
var __toCommonJS = (mod)=>__copyProps(__defProp({}, "__esModule", {
|
|
714
|
+
value: true
|
|
715
|
+
}), mod);
|
|
716
|
+
var validator_exports = {};
|
|
717
|
+
__export(validator_exports, {
|
|
718
|
+
validator: ()=>import_validator.validator
|
|
719
|
+
});
|
|
720
|
+
module.exports = __toCommonJS(validator_exports);
|
|
721
|
+
var import_validator = __webpack_require__("../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/cjs/validator/validator.js");
|
|
722
|
+
},
|
|
723
|
+
"../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/cjs/validator/validator.js": function(module, __unused_webpack_exports, __webpack_require__) {
|
|
724
|
+
var __defProp = Object.defineProperty;
|
|
725
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
726
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
727
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
728
|
+
var __export = (target, all)=>{
|
|
729
|
+
for(var name in all)__defProp(target, name, {
|
|
730
|
+
get: all[name],
|
|
731
|
+
enumerable: true
|
|
732
|
+
});
|
|
733
|
+
};
|
|
734
|
+
var __copyProps = (to, from, except, desc)=>{
|
|
735
|
+
if (from && "object" == typeof from || "function" == typeof from) {
|
|
736
|
+
for (let key of __getOwnPropNames(from))if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
737
|
+
get: ()=>from[key],
|
|
738
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
return to;
|
|
742
|
+
};
|
|
743
|
+
var __toCommonJS = (mod)=>__copyProps(__defProp({}, "__esModule", {
|
|
744
|
+
value: true
|
|
745
|
+
}), mod);
|
|
746
|
+
var validator_exports = {};
|
|
747
|
+
__export(validator_exports, {
|
|
748
|
+
validator: ()=>validator
|
|
749
|
+
});
|
|
750
|
+
module.exports = __toCommonJS(validator_exports);
|
|
751
|
+
var import_cookie = __webpack_require__("../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/cjs/helper/cookie/index.js");
|
|
752
|
+
var import_http_exception = __webpack_require__("../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/cjs/http-exception.js");
|
|
753
|
+
var import_buffer = __webpack_require__("../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/cjs/utils/buffer.js");
|
|
754
|
+
const jsonRegex = /^application\/([a-z-\.]+\+)?json(;\s*[a-zA-Z0-9\-]+\=([^;]+))*$/;
|
|
755
|
+
const multipartRegex = /^multipart\/form-data(;\s?boundary=[a-zA-Z0-9'"()+_,\-./:=?]+)?$/;
|
|
756
|
+
const urlencodedRegex = /^application\/x-www-form-urlencoded(;\s*[a-zA-Z0-9\-]+\=([^;]+))*$/;
|
|
757
|
+
const validator = (target, validationFunc)=>async (c, next)=>{
|
|
758
|
+
let value = {};
|
|
759
|
+
const contentType = c.req.header("Content-Type");
|
|
760
|
+
switch(target){
|
|
761
|
+
case "json":
|
|
762
|
+
if (!contentType || !jsonRegex.test(contentType)) break;
|
|
763
|
+
try {
|
|
764
|
+
value = await c.req.json();
|
|
765
|
+
} catch {
|
|
766
|
+
const message = "Malformed JSON in request body";
|
|
767
|
+
throw new import_http_exception.HTTPException(400, {
|
|
768
|
+
message
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
break;
|
|
772
|
+
case "form":
|
|
773
|
+
{
|
|
774
|
+
if (!contentType || !(multipartRegex.test(contentType) || urlencodedRegex.test(contentType))) break;
|
|
775
|
+
let formData;
|
|
776
|
+
if (c.req.bodyCache.formData) formData = await c.req.bodyCache.formData;
|
|
777
|
+
else try {
|
|
778
|
+
const arrayBuffer = await c.req.arrayBuffer();
|
|
779
|
+
formData = await (0, import_buffer.bufferToFormData)(arrayBuffer, contentType);
|
|
780
|
+
c.req.bodyCache.formData = formData;
|
|
781
|
+
} catch (e) {
|
|
782
|
+
let message = "Malformed FormData request.";
|
|
783
|
+
message += e instanceof Error ? ` ${e.message}` : ` ${String(e)}`;
|
|
784
|
+
throw new import_http_exception.HTTPException(400, {
|
|
785
|
+
message
|
|
786
|
+
});
|
|
787
|
+
}
|
|
788
|
+
const form = {};
|
|
789
|
+
formData.forEach((value2, key)=>{
|
|
790
|
+
if (key.endsWith("[]")) (form[key] ??= []).push(value2);
|
|
791
|
+
else if (Array.isArray(form[key])) form[key].push(value2);
|
|
792
|
+
else if (key in form) form[key] = [
|
|
793
|
+
form[key],
|
|
794
|
+
value2
|
|
795
|
+
];
|
|
796
|
+
else form[key] = value2;
|
|
797
|
+
});
|
|
798
|
+
value = form;
|
|
799
|
+
break;
|
|
800
|
+
}
|
|
801
|
+
case "query":
|
|
802
|
+
value = Object.fromEntries(Object.entries(c.req.queries()).map(([k, v])=>1 === v.length ? [
|
|
803
|
+
k,
|
|
804
|
+
v[0]
|
|
805
|
+
] : [
|
|
806
|
+
k,
|
|
807
|
+
v
|
|
808
|
+
]));
|
|
809
|
+
break;
|
|
810
|
+
case "param":
|
|
811
|
+
value = c.req.param();
|
|
812
|
+
break;
|
|
813
|
+
case "header":
|
|
814
|
+
value = c.req.header();
|
|
815
|
+
break;
|
|
816
|
+
case "cookie":
|
|
817
|
+
value = (0, import_cookie.getCookie)(c);
|
|
818
|
+
break;
|
|
819
|
+
}
|
|
820
|
+
const res = await validationFunc(value, c);
|
|
821
|
+
if (res instanceof Response) return res;
|
|
822
|
+
c.req.addValidatedData(target, res);
|
|
823
|
+
await next();
|
|
824
|
+
};
|
|
825
|
+
}
|
|
826
|
+
};
|
|
827
|
+
var __webpack_module_cache__ = {};
|
|
828
|
+
function __webpack_require__(moduleId) {
|
|
829
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
830
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
831
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
832
|
+
exports: {}
|
|
833
|
+
};
|
|
834
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
835
|
+
return module.exports;
|
|
836
|
+
}
|
|
6
837
|
(()=>{
|
|
7
838
|
__webpack_require__.n = (module)=>{
|
|
8
839
|
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
@@ -34,2062 +865,1752 @@ var __webpack_require__ = {};
|
|
|
34
865
|
};
|
|
35
866
|
})();
|
|
36
867
|
var __webpack_exports__ = {};
|
|
37
|
-
|
|
38
|
-
__webpack_require__.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const external_path_namespaceObject = require("path");
|
|
42
|
-
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
43
|
-
const external_url_namespaceObject = require("url");
|
|
44
|
-
var getFilePath = (options)=>{
|
|
45
|
-
let filename = options.filename;
|
|
46
|
-
const defaultDocument = options.defaultDocument || "index.html";
|
|
47
|
-
if (filename.endsWith("/")) filename = filename.concat(defaultDocument);
|
|
48
|
-
else if (!filename.match(/\.[a-zA-Z0-9_-]+$/)) filename = filename.concat("/" + defaultDocument);
|
|
49
|
-
const path = getFilePathWithoutDefaultDocument({
|
|
50
|
-
root: options.root,
|
|
51
|
-
filename
|
|
52
|
-
});
|
|
53
|
-
return path;
|
|
54
|
-
};
|
|
55
|
-
var getFilePathWithoutDefaultDocument = (options)=>{
|
|
56
|
-
let root = options.root || "";
|
|
57
|
-
let filename = options.filename;
|
|
58
|
-
if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename)) return;
|
|
59
|
-
filename = filename.replace(/^\.?[\/\\]/, "");
|
|
60
|
-
filename = filename.replace(/\\/, "/");
|
|
61
|
-
root = root.replace(/\/$/, "");
|
|
62
|
-
let path = root ? root + "/" + filename : filename;
|
|
63
|
-
path = path.replace(/^\.?\//, "");
|
|
64
|
-
if ("/" !== root[0] && "/" === path[0]) return;
|
|
65
|
-
return path;
|
|
66
|
-
};
|
|
67
|
-
var getMimeType = (filename, mimes = baseMimes)=>{
|
|
68
|
-
const regexp = /\.([a-zA-Z0-9]+?)$/;
|
|
69
|
-
const match = filename.match(regexp);
|
|
70
|
-
if (!match) return;
|
|
71
|
-
let mimeType = mimes[match[1]];
|
|
72
|
-
if (mimeType && mimeType.startsWith("text") || "application/json" === mimeType) mimeType += "; charset=utf-8";
|
|
73
|
-
return mimeType;
|
|
74
|
-
};
|
|
75
|
-
var baseMimes = {
|
|
76
|
-
aac: "audio/aac",
|
|
77
|
-
avi: "video/x-msvideo",
|
|
78
|
-
avif: "image/avif",
|
|
79
|
-
av1: "video/av1",
|
|
80
|
-
bin: "application/octet-stream",
|
|
81
|
-
bmp: "image/bmp",
|
|
82
|
-
css: "text/css",
|
|
83
|
-
csv: "text/csv",
|
|
84
|
-
eot: "application/vnd.ms-fontobject",
|
|
85
|
-
epub: "application/epub+zip",
|
|
86
|
-
gif: "image/gif",
|
|
87
|
-
gz: "application/gzip",
|
|
88
|
-
htm: "text/html",
|
|
89
|
-
html: "text/html",
|
|
90
|
-
ico: "image/x-icon",
|
|
91
|
-
ics: "text/calendar",
|
|
92
|
-
jpeg: "image/jpeg",
|
|
93
|
-
jpg: "image/jpeg",
|
|
94
|
-
js: "text/javascript",
|
|
95
|
-
json: "application/json",
|
|
96
|
-
jsonld: "application/ld+json",
|
|
97
|
-
map: "application/json",
|
|
98
|
-
mid: "audio/x-midi",
|
|
99
|
-
midi: "audio/x-midi",
|
|
100
|
-
mjs: "text/javascript",
|
|
101
|
-
mp3: "audio/mpeg",
|
|
102
|
-
mp4: "video/mp4",
|
|
103
|
-
mpeg: "video/mpeg",
|
|
104
|
-
oga: "audio/ogg",
|
|
105
|
-
ogv: "video/ogg",
|
|
106
|
-
ogx: "application/ogg",
|
|
107
|
-
opus: "audio/opus",
|
|
108
|
-
otf: "font/otf",
|
|
109
|
-
pdf: "application/pdf",
|
|
110
|
-
png: "image/png",
|
|
111
|
-
rtf: "application/rtf",
|
|
112
|
-
svg: "image/svg+xml",
|
|
113
|
-
tif: "image/tiff",
|
|
114
|
-
tiff: "image/tiff",
|
|
115
|
-
ts: "video/mp2t",
|
|
116
|
-
ttf: "font/ttf",
|
|
117
|
-
txt: "text/plain",
|
|
118
|
-
wasm: "application/wasm",
|
|
119
|
-
webm: "video/webm",
|
|
120
|
-
weba: "audio/webm",
|
|
121
|
-
webp: "image/webp",
|
|
122
|
-
woff: "font/woff",
|
|
123
|
-
woff2: "font/woff2",
|
|
124
|
-
xhtml: "application/xhtml+xml",
|
|
125
|
-
xml: "application/xml",
|
|
126
|
-
zip: "application/zip",
|
|
127
|
-
"3gp": "video/3gpp",
|
|
128
|
-
"3g2": "video/3gpp2",
|
|
129
|
-
gltf: "model/gltf+json",
|
|
130
|
-
glb: "model/gltf-binary"
|
|
131
|
-
};
|
|
132
|
-
const external_fs_namespaceObject = require("fs");
|
|
133
|
-
var COMPRESSIBLE_CONTENT_TYPE_REGEX = /^\s*(?:text\/[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|wasm|x-httpd-php|x-javascript|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml))(?:[;\s]|$)/i;
|
|
134
|
-
var ENCODINGS = {
|
|
135
|
-
br: ".br",
|
|
136
|
-
zstd: ".zst",
|
|
137
|
-
gzip: ".gz"
|
|
138
|
-
};
|
|
139
|
-
var ENCODINGS_ORDERED_KEYS = Object.keys(ENCODINGS);
|
|
140
|
-
var createStreamBody = (stream)=>{
|
|
141
|
-
const body = new ReadableStream({
|
|
142
|
-
start (controller) {
|
|
143
|
-
stream.on("data", (chunk)=>{
|
|
144
|
-
controller.enqueue(chunk);
|
|
145
|
-
});
|
|
146
|
-
stream.on("end", ()=>{
|
|
147
|
-
controller.close();
|
|
148
|
-
});
|
|
149
|
-
},
|
|
150
|
-
cancel () {
|
|
151
|
-
stream.destroy();
|
|
152
|
-
}
|
|
868
|
+
(()=>{
|
|
869
|
+
__webpack_require__.r(__webpack_exports__);
|
|
870
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
871
|
+
default: ()=>src_server_rslib_entry_
|
|
153
872
|
});
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
var
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
let path =
|
|
176
|
-
|
|
177
|
-
|
|
873
|
+
const external_path_namespaceObject = require("path");
|
|
874
|
+
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
875
|
+
const external_url_namespaceObject = require("url");
|
|
876
|
+
var getFilePath = (options)=>{
|
|
877
|
+
let filename = options.filename;
|
|
878
|
+
const defaultDocument = options.defaultDocument || "index.html";
|
|
879
|
+
if (filename.endsWith("/")) filename = filename.concat(defaultDocument);
|
|
880
|
+
else if (!filename.match(/\.[a-zA-Z0-9_-]+$/)) filename = filename.concat("/" + defaultDocument);
|
|
881
|
+
const path = getFilePathWithoutDefaultDocument({
|
|
882
|
+
root: options.root,
|
|
883
|
+
filename
|
|
884
|
+
});
|
|
885
|
+
return path;
|
|
886
|
+
};
|
|
887
|
+
var getFilePathWithoutDefaultDocument = (options)=>{
|
|
888
|
+
let root = options.root || "";
|
|
889
|
+
let filename = options.filename;
|
|
890
|
+
if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename)) return;
|
|
891
|
+
filename = filename.replace(/^\.?[\/\\]/, "");
|
|
892
|
+
filename = filename.replace(/\\/, "/");
|
|
893
|
+
root = root.replace(/\/$/, "");
|
|
894
|
+
let path = root ? root + "/" + filename : filename;
|
|
895
|
+
path = path.replace(/^\.?\//, "");
|
|
896
|
+
if ("/" !== root[0] && "/" === path[0]) return;
|
|
897
|
+
return path;
|
|
898
|
+
};
|
|
899
|
+
var getMimeType = (filename, mimes = baseMimes)=>{
|
|
900
|
+
const regexp = /\.([a-zA-Z0-9]+?)$/;
|
|
901
|
+
const match = filename.match(regexp);
|
|
902
|
+
if (!match) return;
|
|
903
|
+
let mimeType = mimes[match[1]];
|
|
904
|
+
if (mimeType && mimeType.startsWith("text") || "application/json" === mimeType) mimeType += "; charset=utf-8";
|
|
905
|
+
return mimeType;
|
|
906
|
+
};
|
|
907
|
+
var baseMimes = {
|
|
908
|
+
aac: "audio/aac",
|
|
909
|
+
avi: "video/x-msvideo",
|
|
910
|
+
avif: "image/avif",
|
|
911
|
+
av1: "video/av1",
|
|
912
|
+
bin: "application/octet-stream",
|
|
913
|
+
bmp: "image/bmp",
|
|
914
|
+
css: "text/css",
|
|
915
|
+
csv: "text/csv",
|
|
916
|
+
eot: "application/vnd.ms-fontobject",
|
|
917
|
+
epub: "application/epub+zip",
|
|
918
|
+
gif: "image/gif",
|
|
919
|
+
gz: "application/gzip",
|
|
920
|
+
htm: "text/html",
|
|
921
|
+
html: "text/html",
|
|
922
|
+
ico: "image/x-icon",
|
|
923
|
+
ics: "text/calendar",
|
|
924
|
+
jpeg: "image/jpeg",
|
|
925
|
+
jpg: "image/jpeg",
|
|
926
|
+
js: "text/javascript",
|
|
927
|
+
json: "application/json",
|
|
928
|
+
jsonld: "application/ld+json",
|
|
929
|
+
map: "application/json",
|
|
930
|
+
mid: "audio/x-midi",
|
|
931
|
+
midi: "audio/x-midi",
|
|
932
|
+
mjs: "text/javascript",
|
|
933
|
+
mp3: "audio/mpeg",
|
|
934
|
+
mp4: "video/mp4",
|
|
935
|
+
mpeg: "video/mpeg",
|
|
936
|
+
oga: "audio/ogg",
|
|
937
|
+
ogv: "video/ogg",
|
|
938
|
+
ogx: "application/ogg",
|
|
939
|
+
opus: "audio/opus",
|
|
940
|
+
otf: "font/otf",
|
|
941
|
+
pdf: "application/pdf",
|
|
942
|
+
png: "image/png",
|
|
943
|
+
rtf: "application/rtf",
|
|
944
|
+
svg: "image/svg+xml",
|
|
945
|
+
tif: "image/tiff",
|
|
946
|
+
tiff: "image/tiff",
|
|
947
|
+
ts: "video/mp2t",
|
|
948
|
+
ttf: "font/ttf",
|
|
949
|
+
txt: "text/plain",
|
|
950
|
+
wasm: "application/wasm",
|
|
951
|
+
webm: "video/webm",
|
|
952
|
+
weba: "audio/webm",
|
|
953
|
+
webp: "image/webp",
|
|
954
|
+
woff: "font/woff",
|
|
955
|
+
woff2: "font/woff2",
|
|
956
|
+
xhtml: "application/xhtml+xml",
|
|
957
|
+
xml: "application/xml",
|
|
958
|
+
zip: "application/zip",
|
|
959
|
+
"3gp": "video/3gpp",
|
|
960
|
+
"3g2": "video/3gpp2",
|
|
961
|
+
gltf: "model/gltf+json",
|
|
962
|
+
glb: "model/gltf-binary"
|
|
963
|
+
};
|
|
964
|
+
const external_fs_namespaceObject = require("fs");
|
|
965
|
+
var COMPRESSIBLE_CONTENT_TYPE_REGEX = /^\s*(?:text\/[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|wasm|x-httpd-php|x-javascript|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml))(?:[;\s]|$)/i;
|
|
966
|
+
var ENCODINGS = {
|
|
967
|
+
br: ".br",
|
|
968
|
+
zstd: ".zst",
|
|
969
|
+
gzip: ".gz"
|
|
970
|
+
};
|
|
971
|
+
var ENCODINGS_ORDERED_KEYS = Object.keys(ENCODINGS);
|
|
972
|
+
var createStreamBody = (stream)=>{
|
|
973
|
+
const body = new ReadableStream({
|
|
974
|
+
start (controller) {
|
|
975
|
+
stream.on("data", (chunk)=>{
|
|
976
|
+
controller.enqueue(chunk);
|
|
977
|
+
});
|
|
978
|
+
stream.on("end", ()=>{
|
|
979
|
+
controller.close();
|
|
980
|
+
});
|
|
981
|
+
},
|
|
982
|
+
cancel () {
|
|
983
|
+
stream.destroy();
|
|
984
|
+
}
|
|
178
985
|
});
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
986
|
+
return body;
|
|
987
|
+
};
|
|
988
|
+
var addCurrentDirPrefix = (path)=>`./${path}`;
|
|
989
|
+
var getStats = (path)=>{
|
|
990
|
+
let stats;
|
|
991
|
+
try {
|
|
992
|
+
stats = (0, external_fs_namespaceObject.lstatSync)(path);
|
|
993
|
+
} catch {}
|
|
994
|
+
return stats;
|
|
995
|
+
};
|
|
996
|
+
var serveStatic = (options = {
|
|
997
|
+
root: ""
|
|
998
|
+
})=>async (c, next)=>{
|
|
999
|
+
if (c.finalized) return next();
|
|
1000
|
+
let filename;
|
|
1001
|
+
try {
|
|
1002
|
+
filename = options.path ?? decodeURIComponent(c.req.path);
|
|
1003
|
+
} catch {
|
|
1004
|
+
await options.onNotFound?.(c.req.path, c);
|
|
1005
|
+
return next();
|
|
1006
|
+
}
|
|
1007
|
+
let path = getFilePathWithoutDefaultDocument({
|
|
184
1008
|
filename: options.rewriteRequestPath ? options.rewriteRequestPath(filename) : filename,
|
|
185
|
-
root: options.root
|
|
186
|
-
defaultDocument: options.index ?? "index.html"
|
|
1009
|
+
root: options.root
|
|
187
1010
|
});
|
|
188
1011
|
if (!path) return next();
|
|
189
1012
|
path = addCurrentDirPrefix(path);
|
|
190
|
-
stats = getStats(path);
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
1013
|
+
let stats = getStats(path);
|
|
1014
|
+
if (stats && stats.isDirectory()) {
|
|
1015
|
+
path = getFilePath({
|
|
1016
|
+
filename: options.rewriteRequestPath ? options.rewriteRequestPath(filename) : filename,
|
|
1017
|
+
root: options.root,
|
|
1018
|
+
defaultDocument: options.index ?? "index.html"
|
|
1019
|
+
});
|
|
1020
|
+
if (!path) return next();
|
|
1021
|
+
path = addCurrentDirPrefix(path);
|
|
1022
|
+
stats = getStats(path);
|
|
1023
|
+
}
|
|
1024
|
+
if (!stats) {
|
|
1025
|
+
await options.onNotFound?.(path, c);
|
|
1026
|
+
return next();
|
|
1027
|
+
}
|
|
1028
|
+
await options.onFound?.(path, c);
|
|
1029
|
+
const mimeType = getMimeType(path);
|
|
1030
|
+
c.header("Content-Type", mimeType || "application/octet-stream");
|
|
1031
|
+
if (options.precompressed && (!mimeType || COMPRESSIBLE_CONTENT_TYPE_REGEX.test(mimeType))) {
|
|
1032
|
+
const acceptEncodingSet = new Set(c.req.header("Accept-Encoding")?.split(",").map((encoding)=>encoding.trim()));
|
|
1033
|
+
for (const encoding of ENCODINGS_ORDERED_KEYS){
|
|
1034
|
+
if (!acceptEncodingSet.has(encoding)) continue;
|
|
1035
|
+
const precompressedStats = getStats(path + ENCODINGS[encoding]);
|
|
1036
|
+
if (precompressedStats) {
|
|
1037
|
+
c.header("Content-Encoding", encoding);
|
|
1038
|
+
c.header("Vary", "Accept-Encoding", {
|
|
1039
|
+
append: true
|
|
1040
|
+
});
|
|
1041
|
+
stats = precompressedStats;
|
|
1042
|
+
path += ENCODINGS[encoding];
|
|
1043
|
+
break;
|
|
1044
|
+
}
|
|
212
1045
|
}
|
|
213
1046
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
1047
|
+
const size = stats.size;
|
|
1048
|
+
if ("HEAD" == c.req.method || "OPTIONS" == c.req.method) {
|
|
1049
|
+
c.header("Content-Length", size.toString());
|
|
1050
|
+
c.status(200);
|
|
1051
|
+
return c.body(null);
|
|
1052
|
+
}
|
|
1053
|
+
const range = c.req.header("range") || "";
|
|
1054
|
+
if (!range) {
|
|
1055
|
+
c.header("Content-Length", size.toString());
|
|
1056
|
+
return c.body(createStreamBody((0, external_fs_namespaceObject.createReadStream)(path)), 200);
|
|
1057
|
+
}
|
|
1058
|
+
c.header("Accept-Ranges", "bytes");
|
|
1059
|
+
c.header("Date", stats.birthtime.toUTCString());
|
|
1060
|
+
const parts = range.replace(/bytes=/, "").split("-", 2);
|
|
1061
|
+
const start = parts[0] ? parseInt(parts[0], 10) : 0;
|
|
1062
|
+
let end = parts[1] ? parseInt(parts[1], 10) : stats.size - 1;
|
|
1063
|
+
if (size < end - start + 1) end = size - 1;
|
|
1064
|
+
const chunksize = end - start + 1;
|
|
1065
|
+
const stream = (0, external_fs_namespaceObject.createReadStream)(path, {
|
|
1066
|
+
start,
|
|
1067
|
+
end
|
|
1068
|
+
});
|
|
1069
|
+
c.header("Content-Length", chunksize.toString());
|
|
1070
|
+
c.header("Content-Range", `bytes ${start}-${end}/${stats.size}`);
|
|
1071
|
+
return c.body(createStreamBody(stream), 206);
|
|
1072
|
+
};
|
|
1073
|
+
var parseBody = async (request, options = /* @__PURE__ */ Object.create(null))=>{
|
|
1074
|
+
const { all = false, dot = false } = options;
|
|
1075
|
+
const headers = request instanceof HonoRequest ? request.raw.headers : request.headers;
|
|
1076
|
+
const contentType = headers.get("Content-Type");
|
|
1077
|
+
if (contentType?.startsWith("multipart/form-data") || contentType?.startsWith("application/x-www-form-urlencoded")) return parseFormData(request, {
|
|
1078
|
+
all,
|
|
1079
|
+
dot
|
|
236
1080
|
});
|
|
237
|
-
|
|
238
|
-
c.header("Content-Range", `bytes ${start}-${end}/${stats.size}`);
|
|
239
|
-
return c.body(createStreamBody(stream), 206);
|
|
1081
|
+
return {};
|
|
240
1082
|
};
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
formData.forEach((value, key)=>{
|
|
259
|
-
const shouldParseAllValues = options.all || key.endsWith("[]");
|
|
260
|
-
if (shouldParseAllValues) handleParsingAllValues(form, key, value);
|
|
261
|
-
else form[key] = value;
|
|
262
|
-
});
|
|
263
|
-
if (options.dot) Object.entries(form).forEach(([key, value])=>{
|
|
264
|
-
const shouldParseDotValues = key.includes(".");
|
|
265
|
-
if (shouldParseDotValues) {
|
|
266
|
-
handleParsingNestedValues(form, key, value);
|
|
267
|
-
delete form[key];
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
return form;
|
|
271
|
-
}
|
|
272
|
-
var handleParsingAllValues = (form, key, value)=>{
|
|
273
|
-
if (void 0 !== form[key]) {
|
|
274
|
-
if (Array.isArray(form[key])) form[key].push(value);
|
|
275
|
-
else form[key] = [
|
|
276
|
-
form[key],
|
|
277
|
-
value
|
|
278
|
-
];
|
|
279
|
-
} else form[key] = value;
|
|
280
|
-
};
|
|
281
|
-
var handleParsingNestedValues = (form, key, value)=>{
|
|
282
|
-
let nestedForm = form;
|
|
283
|
-
const keys = key.split(".");
|
|
284
|
-
keys.forEach((key2, index)=>{
|
|
285
|
-
if (index === keys.length - 1) nestedForm[key2] = value;
|
|
286
|
-
else {
|
|
287
|
-
if (!nestedForm[key2] || "object" != typeof nestedForm[key2] || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) nestedForm[key2] = /* @__PURE__ */ Object.create(null);
|
|
288
|
-
nestedForm = nestedForm[key2];
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
};
|
|
292
|
-
var splitPath = (path)=>{
|
|
293
|
-
const paths = path.split("/");
|
|
294
|
-
if ("" === paths[0]) paths.shift();
|
|
295
|
-
return paths;
|
|
296
|
-
};
|
|
297
|
-
var splitRoutingPath = (routePath)=>{
|
|
298
|
-
const { groups, path } = extractGroupsFromPath(routePath);
|
|
299
|
-
const paths = splitPath(path);
|
|
300
|
-
return replaceGroupMarks(paths, groups);
|
|
301
|
-
};
|
|
302
|
-
var extractGroupsFromPath = (path)=>{
|
|
303
|
-
const groups = [];
|
|
304
|
-
path = path.replace(/\{[^}]+\}/g, (match, index)=>{
|
|
305
|
-
const mark = `@${index}`;
|
|
306
|
-
groups.push([
|
|
307
|
-
mark,
|
|
308
|
-
match
|
|
309
|
-
]);
|
|
310
|
-
return mark;
|
|
311
|
-
});
|
|
312
|
-
return {
|
|
313
|
-
groups,
|
|
314
|
-
path
|
|
315
|
-
};
|
|
316
|
-
};
|
|
317
|
-
var replaceGroupMarks = (paths, groups)=>{
|
|
318
|
-
for(let i = groups.length - 1; i >= 0; i--){
|
|
319
|
-
const [mark] = groups[i];
|
|
320
|
-
for(let j = paths.length - 1; j >= 0; j--)if (paths[j].includes(mark)) {
|
|
321
|
-
paths[j] = paths[j].replace(mark, groups[i][1]);
|
|
322
|
-
break;
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
return paths;
|
|
326
|
-
};
|
|
327
|
-
var patternCache = {};
|
|
328
|
-
var getPattern = (label)=>{
|
|
329
|
-
if ("*" === label) return "*";
|
|
330
|
-
const match = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
331
|
-
if (match) {
|
|
332
|
-
if (!patternCache[label]) {
|
|
333
|
-
if (match[2]) patternCache[label] = [
|
|
334
|
-
label,
|
|
335
|
-
match[1],
|
|
336
|
-
new RegExp("^" + match[2] + "$")
|
|
337
|
-
];
|
|
338
|
-
else patternCache[label] = [
|
|
339
|
-
label,
|
|
340
|
-
match[1],
|
|
341
|
-
true
|
|
342
|
-
];
|
|
343
|
-
}
|
|
344
|
-
return patternCache[label];
|
|
345
|
-
}
|
|
346
|
-
return null;
|
|
347
|
-
};
|
|
348
|
-
var tryDecodeURI = (str)=>{
|
|
349
|
-
try {
|
|
350
|
-
return decodeURI(str);
|
|
351
|
-
} catch {
|
|
352
|
-
return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match)=>{
|
|
353
|
-
try {
|
|
354
|
-
return decodeURI(match);
|
|
355
|
-
} catch {
|
|
356
|
-
return match;
|
|
1083
|
+
async function parseFormData(request, options) {
|
|
1084
|
+
const formData = await request.formData();
|
|
1085
|
+
if (formData) return convertFormDataToBodyData(formData, options);
|
|
1086
|
+
return {};
|
|
1087
|
+
}
|
|
1088
|
+
function convertFormDataToBodyData(formData, options) {
|
|
1089
|
+
const form = /* @__PURE__ */ Object.create(null);
|
|
1090
|
+
formData.forEach((value, key)=>{
|
|
1091
|
+
const shouldParseAllValues = options.all || key.endsWith("[]");
|
|
1092
|
+
if (shouldParseAllValues) handleParsingAllValues(form, key, value);
|
|
1093
|
+
else form[key] = value;
|
|
1094
|
+
});
|
|
1095
|
+
if (options.dot) Object.entries(form).forEach(([key, value])=>{
|
|
1096
|
+
const shouldParseDotValues = key.includes(".");
|
|
1097
|
+
if (shouldParseDotValues) {
|
|
1098
|
+
handleParsingNestedValues(form, key, value);
|
|
1099
|
+
delete form[key];
|
|
357
1100
|
}
|
|
358
1101
|
});
|
|
359
|
-
|
|
360
|
-
}
|
|
361
|
-
var
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
return result.length > 1 && "/" === result[result.length - 1] ? result.slice(0, -1) : result;
|
|
379
|
-
};
|
|
380
|
-
var mergePath = (...paths)=>{
|
|
381
|
-
let p = "";
|
|
382
|
-
let endsWithSlash = false;
|
|
383
|
-
for (let path of paths){
|
|
384
|
-
if ("/" === p[p.length - 1]) {
|
|
385
|
-
p = p.slice(0, -1);
|
|
386
|
-
endsWithSlash = true;
|
|
387
|
-
}
|
|
388
|
-
if ("/" !== path[0]) path = `/${path}`;
|
|
389
|
-
if ("/" === path && endsWithSlash) p = `${p}/`;
|
|
390
|
-
else if ("/" !== path) p = `${p}${path}`;
|
|
391
|
-
if ("/" === path && "" === p) p = "/";
|
|
392
|
-
}
|
|
393
|
-
return p;
|
|
394
|
-
};
|
|
395
|
-
var checkOptionalParameter = (path)=>{
|
|
396
|
-
if (!path.match(/\:.+\?$/)) return null;
|
|
397
|
-
const segments = path.split("/");
|
|
398
|
-
const results = [];
|
|
399
|
-
let basePath = "";
|
|
400
|
-
segments.forEach((segment)=>{
|
|
401
|
-
if ("" === segment || /\:/.test(segment)) {
|
|
402
|
-
if (/\:/.test(segment)) {
|
|
403
|
-
if (/\?/.test(segment)) {
|
|
404
|
-
if (0 === results.length && "" === basePath) results.push("/");
|
|
405
|
-
else results.push(basePath);
|
|
406
|
-
const optionalSegment = segment.replace("?", "");
|
|
407
|
-
basePath += "/" + optionalSegment;
|
|
408
|
-
results.push(basePath);
|
|
409
|
-
} else basePath += "/" + segment;
|
|
1102
|
+
return form;
|
|
1103
|
+
}
|
|
1104
|
+
var handleParsingAllValues = (form, key, value)=>{
|
|
1105
|
+
if (void 0 !== form[key]) {
|
|
1106
|
+
if (Array.isArray(form[key])) form[key].push(value);
|
|
1107
|
+
else form[key] = [
|
|
1108
|
+
form[key],
|
|
1109
|
+
value
|
|
1110
|
+
];
|
|
1111
|
+
} else form[key] = value;
|
|
1112
|
+
};
|
|
1113
|
+
var handleParsingNestedValues = (form, key, value)=>{
|
|
1114
|
+
let nestedForm = form;
|
|
1115
|
+
const keys = key.split(".");
|
|
1116
|
+
keys.forEach((key2, index)=>{
|
|
1117
|
+
if (index === keys.length - 1) nestedForm[key2] = value;
|
|
1118
|
+
else {
|
|
1119
|
+
if (!nestedForm[key2] || "object" != typeof nestedForm[key2] || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) nestedForm[key2] = /* @__PURE__ */ Object.create(null);
|
|
1120
|
+
nestedForm = nestedForm[key2];
|
|
410
1121
|
}
|
|
411
|
-
} else basePath += "/" + segment;
|
|
412
|
-
});
|
|
413
|
-
return results.filter((v, i, a)=>a.indexOf(v) === i);
|
|
414
|
-
};
|
|
415
|
-
var _decodeURI = (value)=>{
|
|
416
|
-
if (!/[%+]/.test(value)) return value;
|
|
417
|
-
if (-1 !== value.indexOf("+")) value = value.replace(/\+/g, " ");
|
|
418
|
-
return /%/.test(value) ? decodeURIComponent_(value) : value;
|
|
419
|
-
};
|
|
420
|
-
var _getQueryParam = (url, key, multiple)=>{
|
|
421
|
-
let encoded;
|
|
422
|
-
if (!multiple && key && !/[%+]/.test(key)) {
|
|
423
|
-
let keyIndex2 = url.indexOf(`?${key}`, 8);
|
|
424
|
-
if (-1 === keyIndex2) keyIndex2 = url.indexOf(`&${key}`, 8);
|
|
425
|
-
while(-1 !== keyIndex2){
|
|
426
|
-
const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1);
|
|
427
|
-
if (61 === trailingKeyCode) {
|
|
428
|
-
const valueIndex = keyIndex2 + key.length + 2;
|
|
429
|
-
const endIndex = url.indexOf("&", valueIndex);
|
|
430
|
-
return _decodeURI(url.slice(valueIndex, -1 === endIndex ? void 0 : endIndex));
|
|
431
|
-
}
|
|
432
|
-
if (38 == trailingKeyCode || isNaN(trailingKeyCode)) return "";
|
|
433
|
-
keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
|
434
|
-
}
|
|
435
|
-
encoded = /[%+]/.test(url);
|
|
436
|
-
if (!encoded) return;
|
|
437
|
-
}
|
|
438
|
-
const results = {};
|
|
439
|
-
encoded ??= /[%+]/.test(url);
|
|
440
|
-
let keyIndex = url.indexOf("?", 8);
|
|
441
|
-
while(-1 !== keyIndex){
|
|
442
|
-
const nextKeyIndex = url.indexOf("&", keyIndex + 1);
|
|
443
|
-
let valueIndex = url.indexOf("=", keyIndex);
|
|
444
|
-
if (valueIndex > nextKeyIndex && -1 !== nextKeyIndex) valueIndex = -1;
|
|
445
|
-
let name = url.slice(keyIndex + 1, -1 === valueIndex ? -1 === nextKeyIndex ? void 0 : nextKeyIndex : valueIndex);
|
|
446
|
-
if (encoded) name = _decodeURI(name);
|
|
447
|
-
keyIndex = nextKeyIndex;
|
|
448
|
-
if ("" === name) continue;
|
|
449
|
-
let value;
|
|
450
|
-
if (-1 === valueIndex) value = "";
|
|
451
|
-
else {
|
|
452
|
-
value = url.slice(valueIndex + 1, -1 === nextKeyIndex ? void 0 : nextKeyIndex);
|
|
453
|
-
if (encoded) value = _decodeURI(value);
|
|
454
|
-
}
|
|
455
|
-
if (multiple) {
|
|
456
|
-
if (!(results[name] && Array.isArray(results[name]))) results[name] = [];
|
|
457
|
-
results[name].push(value);
|
|
458
|
-
} else results[name] ??= value;
|
|
459
|
-
}
|
|
460
|
-
return key ? results[key] : results;
|
|
461
|
-
};
|
|
462
|
-
var getQueryParam = _getQueryParam;
|
|
463
|
-
var getQueryParams = (url, key)=>_getQueryParam(url, key, true);
|
|
464
|
-
var decodeURIComponent_ = decodeURIComponent;
|
|
465
|
-
var HonoRequest = class {
|
|
466
|
-
raw;
|
|
467
|
-
#validatedData;
|
|
468
|
-
#matchResult;
|
|
469
|
-
routeIndex = 0;
|
|
470
|
-
path;
|
|
471
|
-
bodyCache = {};
|
|
472
|
-
constructor(request, path = "/", matchResult = [
|
|
473
|
-
[]
|
|
474
|
-
]){
|
|
475
|
-
this.raw = request;
|
|
476
|
-
this.path = path;
|
|
477
|
-
this.#matchResult = matchResult;
|
|
478
|
-
this.#validatedData = {};
|
|
479
|
-
}
|
|
480
|
-
param(key) {
|
|
481
|
-
return key ? this.getDecodedParam(key) : this.getAllDecodedParams();
|
|
482
|
-
}
|
|
483
|
-
getDecodedParam(key) {
|
|
484
|
-
const paramKey = this.#matchResult[0][this.routeIndex][1][key];
|
|
485
|
-
const param = this.getParamValue(paramKey);
|
|
486
|
-
return param ? /\%/.test(param) ? decodeURIComponent_(param) : param : void 0;
|
|
487
|
-
}
|
|
488
|
-
getAllDecodedParams() {
|
|
489
|
-
const decoded = {};
|
|
490
|
-
const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
|
|
491
|
-
for (const key of keys){
|
|
492
|
-
const value = this.getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
|
|
493
|
-
if (value && "string" == typeof value) decoded[key] = /\%/.test(value) ? decodeURIComponent_(value) : value;
|
|
494
|
-
}
|
|
495
|
-
return decoded;
|
|
496
|
-
}
|
|
497
|
-
getParamValue(paramKey) {
|
|
498
|
-
return this.#matchResult[1] ? this.#matchResult[1][paramKey] : paramKey;
|
|
499
|
-
}
|
|
500
|
-
query(key) {
|
|
501
|
-
return getQueryParam(this.url, key);
|
|
502
|
-
}
|
|
503
|
-
queries(key) {
|
|
504
|
-
return getQueryParams(this.url, key);
|
|
505
|
-
}
|
|
506
|
-
header(name) {
|
|
507
|
-
if (name) return this.raw.headers.get(name.toLowerCase()) ?? void 0;
|
|
508
|
-
const headerData = {};
|
|
509
|
-
this.raw.headers.forEach((value, key)=>{
|
|
510
|
-
headerData[key] = value;
|
|
511
1122
|
});
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
const
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
1123
|
+
};
|
|
1124
|
+
var splitPath = (path)=>{
|
|
1125
|
+
const paths = path.split("/");
|
|
1126
|
+
if ("" === paths[0]) paths.shift();
|
|
1127
|
+
return paths;
|
|
1128
|
+
};
|
|
1129
|
+
var splitRoutingPath = (routePath)=>{
|
|
1130
|
+
const { groups, path } = extractGroupsFromPath(routePath);
|
|
1131
|
+
const paths = splitPath(path);
|
|
1132
|
+
return replaceGroupMarks(paths, groups);
|
|
1133
|
+
};
|
|
1134
|
+
var extractGroupsFromPath = (path)=>{
|
|
1135
|
+
const groups = [];
|
|
1136
|
+
path = path.replace(/\{[^}]+\}/g, (match, index)=>{
|
|
1137
|
+
const mark = `@${index}`;
|
|
1138
|
+
groups.push([
|
|
1139
|
+
mark,
|
|
1140
|
+
match
|
|
1141
|
+
]);
|
|
1142
|
+
return mark;
|
|
525
1143
|
});
|
|
526
|
-
return
|
|
1144
|
+
return {
|
|
1145
|
+
groups,
|
|
1146
|
+
path
|
|
1147
|
+
};
|
|
527
1148
|
};
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
return this.cachedBody("arrayBuffer");
|
|
536
|
-
}
|
|
537
|
-
blob() {
|
|
538
|
-
return this.cachedBody("blob");
|
|
539
|
-
}
|
|
540
|
-
formData() {
|
|
541
|
-
return this.cachedBody("formData");
|
|
542
|
-
}
|
|
543
|
-
addValidatedData(target, data) {
|
|
544
|
-
this.#validatedData[target] = data;
|
|
545
|
-
}
|
|
546
|
-
valid(target) {
|
|
547
|
-
return this.#validatedData[target];
|
|
548
|
-
}
|
|
549
|
-
get url() {
|
|
550
|
-
return this.raw.url;
|
|
551
|
-
}
|
|
552
|
-
get method() {
|
|
553
|
-
return this.raw.method;
|
|
554
|
-
}
|
|
555
|
-
get matchedRoutes() {
|
|
556
|
-
return this.#matchResult[0].map(([[, route]])=>route);
|
|
557
|
-
}
|
|
558
|
-
get routePath() {
|
|
559
|
-
return this.#matchResult[0].map(([[, route]])=>route)[this.routeIndex].path;
|
|
560
|
-
}
|
|
561
|
-
};
|
|
562
|
-
var HtmlEscapedCallbackPhase = {
|
|
563
|
-
Stringify: 1,
|
|
564
|
-
BeforeStream: 2,
|
|
565
|
-
Stream: 3
|
|
566
|
-
};
|
|
567
|
-
var html_raw = (value, callbacks)=>{
|
|
568
|
-
const escapedString = new String(value);
|
|
569
|
-
escapedString.isEscaped = true;
|
|
570
|
-
escapedString.callbacks = callbacks;
|
|
571
|
-
return escapedString;
|
|
572
|
-
};
|
|
573
|
-
var resolveCallback = async (str, phase, preserveCallbacks, context, buffer)=>{
|
|
574
|
-
if ("object" == typeof str && !(str instanceof String)) {
|
|
575
|
-
if (!(str instanceof Promise)) str = str.toString();
|
|
576
|
-
if (str instanceof Promise) str = await str;
|
|
577
|
-
}
|
|
578
|
-
const callbacks = str.callbacks;
|
|
579
|
-
if (!callbacks?.length) return Promise.resolve(str);
|
|
580
|
-
if (buffer) buffer[0] += str;
|
|
581
|
-
else buffer = [
|
|
582
|
-
str
|
|
583
|
-
];
|
|
584
|
-
const resStr = Promise.all(callbacks.map((c)=>c({
|
|
585
|
-
phase,
|
|
586
|
-
buffer,
|
|
587
|
-
context
|
|
588
|
-
}))).then((res)=>Promise.all(res.filter(Boolean).map((str2)=>resolveCallback(str2, phase, false, context, buffer))).then(()=>buffer[0]));
|
|
589
|
-
if (preserveCallbacks) return html_raw(await resStr, callbacks);
|
|
590
|
-
return resStr;
|
|
591
|
-
};
|
|
592
|
-
var TEXT_PLAIN = "text/plain; charset=UTF-8";
|
|
593
|
-
var setHeaders = (headers, map = {})=>{
|
|
594
|
-
Object.entries(map).forEach(([key, value])=>headers.set(key, value));
|
|
595
|
-
return headers;
|
|
596
|
-
};
|
|
597
|
-
var Context = class {
|
|
598
|
-
#rawRequest;
|
|
599
|
-
#req;
|
|
600
|
-
env = {};
|
|
601
|
-
#var;
|
|
602
|
-
finalized = false;
|
|
603
|
-
error;
|
|
604
|
-
#status = 200;
|
|
605
|
-
#executionCtx;
|
|
606
|
-
#headers;
|
|
607
|
-
#preparedHeaders;
|
|
608
|
-
#res;
|
|
609
|
-
#isFresh = true;
|
|
610
|
-
#layout;
|
|
611
|
-
#renderer;
|
|
612
|
-
#notFoundHandler;
|
|
613
|
-
#matchResult;
|
|
614
|
-
#path;
|
|
615
|
-
constructor(req, options){
|
|
616
|
-
this.#rawRequest = req;
|
|
617
|
-
if (options) {
|
|
618
|
-
this.#executionCtx = options.executionCtx;
|
|
619
|
-
this.env = options.env;
|
|
620
|
-
this.#notFoundHandler = options.notFoundHandler;
|
|
621
|
-
this.#path = options.path;
|
|
622
|
-
this.#matchResult = options.matchResult;
|
|
1149
|
+
var replaceGroupMarks = (paths, groups)=>{
|
|
1150
|
+
for(let i = groups.length - 1; i >= 0; i--){
|
|
1151
|
+
const [mark] = groups[i];
|
|
1152
|
+
for(let j = paths.length - 1; j >= 0; j--)if (paths[j].includes(mark)) {
|
|
1153
|
+
paths[j] = paths[j].replace(mark, groups[i][1]);
|
|
1154
|
+
break;
|
|
1155
|
+
}
|
|
623
1156
|
}
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
if (
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
}
|
|
643
|
-
set res(_res) {
|
|
644
|
-
this.#isFresh = false;
|
|
645
|
-
if (this.#res && _res) try {
|
|
646
|
-
for (const [k, v] of this.#res.headers.entries())if ("content-type" !== k) {
|
|
647
|
-
if ("set-cookie" === k) {
|
|
648
|
-
const cookies = this.#res.headers.getSetCookie();
|
|
649
|
-
_res.headers.delete("set-cookie");
|
|
650
|
-
for (const cookie of cookies)_res.headers.append("set-cookie", cookie);
|
|
651
|
-
} else _res.headers.set(k, v);
|
|
652
|
-
}
|
|
653
|
-
} catch (e) {
|
|
654
|
-
if (e instanceof TypeError && e.message.includes("immutable")) {
|
|
655
|
-
this.res = new Response(_res.body, {
|
|
656
|
-
headers: _res.headers,
|
|
657
|
-
status: _res.status
|
|
658
|
-
});
|
|
659
|
-
return;
|
|
1157
|
+
return paths;
|
|
1158
|
+
};
|
|
1159
|
+
var patternCache = {};
|
|
1160
|
+
var getPattern = (label)=>{
|
|
1161
|
+
if ("*" === label) return "*";
|
|
1162
|
+
const match = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
1163
|
+
if (match) {
|
|
1164
|
+
if (!patternCache[label]) {
|
|
1165
|
+
if (match[2]) patternCache[label] = [
|
|
1166
|
+
label,
|
|
1167
|
+
match[1],
|
|
1168
|
+
new RegExp("^" + match[2] + "$")
|
|
1169
|
+
];
|
|
1170
|
+
else patternCache[label] = [
|
|
1171
|
+
label,
|
|
1172
|
+
match[1],
|
|
1173
|
+
true
|
|
1174
|
+
];
|
|
660
1175
|
}
|
|
661
|
-
|
|
1176
|
+
return patternCache[label];
|
|
662
1177
|
}
|
|
663
|
-
|
|
664
|
-
this.finalized = true;
|
|
665
|
-
}
|
|
666
|
-
render = (...args)=>{
|
|
667
|
-
this.#renderer ??= (content)=>this.html(content);
|
|
668
|
-
return this.#renderer(...args);
|
|
1178
|
+
return null;
|
|
669
1179
|
};
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
1180
|
+
var tryDecodeURI = (str)=>{
|
|
1181
|
+
try {
|
|
1182
|
+
return decodeURI(str);
|
|
1183
|
+
} catch {
|
|
1184
|
+
return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match)=>{
|
|
1185
|
+
try {
|
|
1186
|
+
return decodeURI(match);
|
|
1187
|
+
} catch {
|
|
1188
|
+
return match;
|
|
1189
|
+
}
|
|
1190
|
+
});
|
|
1191
|
+
}
|
|
674
1192
|
};
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
this.#headers = new Headers(this.#preparedHeaders);
|
|
686
|
-
this.#preparedHeaders = {};
|
|
1193
|
+
var getPath = (request)=>{
|
|
1194
|
+
const url = request.url;
|
|
1195
|
+
const start = url.indexOf("/", 8);
|
|
1196
|
+
let i = start;
|
|
1197
|
+
for(; i < url.length; i++){
|
|
1198
|
+
const charCode = url.charCodeAt(i);
|
|
1199
|
+
if (37 === charCode) {
|
|
1200
|
+
const queryIndex = url.indexOf("?", i);
|
|
1201
|
+
const path = url.slice(start, -1 === queryIndex ? void 0 : queryIndex);
|
|
1202
|
+
return tryDecodeURI(path.includes("%25") ? path.replace(/%25/g, "%2525") : path);
|
|
687
1203
|
}
|
|
688
|
-
|
|
689
|
-
} else if (this.#headers) this.#headers.set(name, value);
|
|
690
|
-
else {
|
|
691
|
-
this.#preparedHeaders ??= {};
|
|
692
|
-
this.#preparedHeaders[name.toLowerCase()] = value;
|
|
693
|
-
}
|
|
694
|
-
if (this.finalized) {
|
|
695
|
-
if (options?.append) this.res.headers.append(name, value);
|
|
696
|
-
else this.res.headers.set(name, value);
|
|
1204
|
+
if (63 === charCode) break;
|
|
697
1205
|
}
|
|
1206
|
+
return url.slice(start, i);
|
|
698
1207
|
};
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
1208
|
+
var getPathNoStrict = (request)=>{
|
|
1209
|
+
const result = getPath(request);
|
|
1210
|
+
return result.length > 1 && "/" === result[result.length - 1] ? result.slice(0, -1) : result;
|
|
702
1211
|
};
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
1212
|
+
var mergePath = (...paths)=>{
|
|
1213
|
+
let p = "";
|
|
1214
|
+
let endsWithSlash = false;
|
|
1215
|
+
for (let path of paths){
|
|
1216
|
+
if ("/" === p[p.length - 1]) {
|
|
1217
|
+
p = p.slice(0, -1);
|
|
1218
|
+
endsWithSlash = true;
|
|
1219
|
+
}
|
|
1220
|
+
if ("/" !== path[0]) path = `/${path}`;
|
|
1221
|
+
if ("/" === path && endsWithSlash) p = `${p}/`;
|
|
1222
|
+
else if ("/" !== path) p = `${p}${path}`;
|
|
1223
|
+
if ("/" === path && "" === p) p = "/";
|
|
1224
|
+
}
|
|
1225
|
+
return p;
|
|
706
1226
|
};
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
1227
|
+
var checkOptionalParameter = (path)=>{
|
|
1228
|
+
if (!path.match(/\:.+\?$/)) return null;
|
|
1229
|
+
const segments = path.split("/");
|
|
1230
|
+
const results = [];
|
|
1231
|
+
let basePath = "";
|
|
1232
|
+
segments.forEach((segment)=>{
|
|
1233
|
+
if ("" === segment || /\:/.test(segment)) {
|
|
1234
|
+
if (/\:/.test(segment)) {
|
|
1235
|
+
if (/\?/.test(segment)) {
|
|
1236
|
+
if (0 === results.length && "" === basePath) results.push("/");
|
|
1237
|
+
else results.push(basePath);
|
|
1238
|
+
const optionalSegment = segment.replace("?", "");
|
|
1239
|
+
basePath += "/" + optionalSegment;
|
|
1240
|
+
results.push(basePath);
|
|
1241
|
+
} else basePath += "/" + segment;
|
|
1242
|
+
}
|
|
1243
|
+
} else basePath += "/" + segment;
|
|
715
1244
|
});
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
1245
|
+
return results.filter((v, i, a)=>a.indexOf(v) === i);
|
|
1246
|
+
};
|
|
1247
|
+
var _decodeURI = (value)=>{
|
|
1248
|
+
if (!/[%+]/.test(value)) return value;
|
|
1249
|
+
if (-1 !== value.indexOf("+")) value = value.replace(/\+/g, " ");
|
|
1250
|
+
return /%/.test(value) ? decodeURIComponent_(value) : value;
|
|
1251
|
+
};
|
|
1252
|
+
var _getQueryParam = (url, key, multiple)=>{
|
|
1253
|
+
let encoded;
|
|
1254
|
+
if (!multiple && key && !/[%+]/.test(key)) {
|
|
1255
|
+
let keyIndex2 = url.indexOf(`?${key}`, 8);
|
|
1256
|
+
if (-1 === keyIndex2) keyIndex2 = url.indexOf(`&${key}`, 8);
|
|
1257
|
+
while(-1 !== keyIndex2){
|
|
1258
|
+
const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1);
|
|
1259
|
+
if (61 === trailingKeyCode) {
|
|
1260
|
+
const valueIndex = keyIndex2 + key.length + 2;
|
|
1261
|
+
const endIndex = url.indexOf("&", valueIndex);
|
|
1262
|
+
return _decodeURI(url.slice(valueIndex, -1 === endIndex ? void 0 : endIndex));
|
|
1263
|
+
}
|
|
1264
|
+
if (38 == trailingKeyCode || isNaN(trailingKeyCode)) return "";
|
|
1265
|
+
keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
|
1266
|
+
}
|
|
1267
|
+
encoded = /[%+]/.test(url);
|
|
1268
|
+
if (!encoded) return;
|
|
1269
|
+
}
|
|
1270
|
+
const results = {};
|
|
1271
|
+
encoded ??= /[%+]/.test(url);
|
|
1272
|
+
let keyIndex = url.indexOf("?", 8);
|
|
1273
|
+
while(-1 !== keyIndex){
|
|
1274
|
+
const nextKeyIndex = url.indexOf("&", keyIndex + 1);
|
|
1275
|
+
let valueIndex = url.indexOf("=", keyIndex);
|
|
1276
|
+
if (valueIndex > nextKeyIndex && -1 !== nextKeyIndex) valueIndex = -1;
|
|
1277
|
+
let name = url.slice(keyIndex + 1, -1 === valueIndex ? -1 === nextKeyIndex ? void 0 : nextKeyIndex : valueIndex);
|
|
1278
|
+
if (encoded) name = _decodeURI(name);
|
|
1279
|
+
keyIndex = nextKeyIndex;
|
|
1280
|
+
if ("" === name) continue;
|
|
1281
|
+
let value;
|
|
1282
|
+
if (-1 === valueIndex) value = "";
|
|
1283
|
+
else {
|
|
1284
|
+
value = url.slice(valueIndex + 1, -1 === nextKeyIndex ? void 0 : nextKeyIndex);
|
|
1285
|
+
if (encoded) value = _decodeURI(value);
|
|
1286
|
+
}
|
|
1287
|
+
if (multiple) {
|
|
1288
|
+
if (!(results[name] && Array.isArray(results[name]))) results[name] = [];
|
|
1289
|
+
results[name].push(value);
|
|
1290
|
+
} else results[name] ??= value;
|
|
1291
|
+
}
|
|
1292
|
+
return key ? results[key] : results;
|
|
1293
|
+
};
|
|
1294
|
+
var getQueryParam = _getQueryParam;
|
|
1295
|
+
var getQueryParams = (url, key)=>_getQueryParam(url, key, true);
|
|
1296
|
+
var decodeURIComponent_ = decodeURIComponent;
|
|
1297
|
+
var HonoRequest = class {
|
|
1298
|
+
raw;
|
|
1299
|
+
#validatedData;
|
|
1300
|
+
#matchResult;
|
|
1301
|
+
routeIndex = 0;
|
|
1302
|
+
path;
|
|
1303
|
+
bodyCache = {};
|
|
1304
|
+
constructor(request, path = "/", matchResult = [
|
|
1305
|
+
[]
|
|
1306
|
+
]){
|
|
1307
|
+
this.raw = request;
|
|
1308
|
+
this.path = path;
|
|
1309
|
+
this.#matchResult = matchResult;
|
|
1310
|
+
this.#validatedData = {};
|
|
1311
|
+
}
|
|
1312
|
+
param(key) {
|
|
1313
|
+
return key ? this.getDecodedParam(key) : this.getAllDecodedParams();
|
|
1314
|
+
}
|
|
1315
|
+
getDecodedParam(key) {
|
|
1316
|
+
const paramKey = this.#matchResult[0][this.routeIndex][1][key];
|
|
1317
|
+
const param = this.getParamValue(paramKey);
|
|
1318
|
+
return param ? /\%/.test(param) ? decodeURIComponent_(param) : param : void 0;
|
|
1319
|
+
}
|
|
1320
|
+
getAllDecodedParams() {
|
|
1321
|
+
const decoded = {};
|
|
1322
|
+
const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
|
|
1323
|
+
for (const key of keys){
|
|
1324
|
+
const value = this.getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
|
|
1325
|
+
if (value && "string" == typeof value) decoded[key] = /\%/.test(value) ? decodeURIComponent_(value) : value;
|
|
1326
|
+
}
|
|
1327
|
+
return decoded;
|
|
1328
|
+
}
|
|
1329
|
+
getParamValue(paramKey) {
|
|
1330
|
+
return this.#matchResult[1] ? this.#matchResult[1][paramKey] : paramKey;
|
|
1331
|
+
}
|
|
1332
|
+
query(key) {
|
|
1333
|
+
return getQueryParam(this.url, key);
|
|
1334
|
+
}
|
|
1335
|
+
queries(key) {
|
|
1336
|
+
return getQueryParams(this.url, key);
|
|
1337
|
+
}
|
|
1338
|
+
header(name) {
|
|
1339
|
+
if (name) return this.raw.headers.get(name.toLowerCase()) ?? void 0;
|
|
1340
|
+
const headerData = {};
|
|
1341
|
+
this.raw.headers.forEach((value, key)=>{
|
|
1342
|
+
headerData[key] = value;
|
|
726
1343
|
});
|
|
1344
|
+
return headerData;
|
|
727
1345
|
}
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
1346
|
+
async parseBody(options) {
|
|
1347
|
+
return this.bodyCache.parsedBody ??= await parseBody(this, options);
|
|
1348
|
+
}
|
|
1349
|
+
cachedBody = (key)=>{
|
|
1350
|
+
const { bodyCache, raw } = this;
|
|
1351
|
+
const cachedBody = bodyCache[key];
|
|
1352
|
+
if (cachedBody) return cachedBody;
|
|
1353
|
+
const anyCachedKey = Object.keys(bodyCache)[0];
|
|
1354
|
+
if (anyCachedKey) return bodyCache[anyCachedKey].then((body)=>{
|
|
1355
|
+
if ("json" === anyCachedKey) body = JSON.stringify(body);
|
|
1356
|
+
return new Response(body)[key]();
|
|
736
1357
|
});
|
|
737
|
-
|
|
1358
|
+
return bodyCache[key] = raw[key]();
|
|
1359
|
+
};
|
|
1360
|
+
json() {
|
|
1361
|
+
return this.cachedBody("json");
|
|
738
1362
|
}
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
1363
|
+
text() {
|
|
1364
|
+
return this.cachedBody("text");
|
|
1365
|
+
}
|
|
1366
|
+
arrayBuffer() {
|
|
1367
|
+
return this.cachedBody("arrayBuffer");
|
|
1368
|
+
}
|
|
1369
|
+
blob() {
|
|
1370
|
+
return this.cachedBody("blob");
|
|
1371
|
+
}
|
|
1372
|
+
formData() {
|
|
1373
|
+
return this.cachedBody("formData");
|
|
1374
|
+
}
|
|
1375
|
+
addValidatedData(target, data) {
|
|
1376
|
+
this.#validatedData[target] = data;
|
|
1377
|
+
}
|
|
1378
|
+
valid(target) {
|
|
1379
|
+
return this.#validatedData[target];
|
|
1380
|
+
}
|
|
1381
|
+
get url() {
|
|
1382
|
+
return this.raw.url;
|
|
1383
|
+
}
|
|
1384
|
+
get method() {
|
|
1385
|
+
return this.raw.method;
|
|
1386
|
+
}
|
|
1387
|
+
get matchedRoutes() {
|
|
1388
|
+
return this.#matchResult[0].map(([[, route]])=>route);
|
|
1389
|
+
}
|
|
1390
|
+
get routePath() {
|
|
1391
|
+
return this.#matchResult[0].map(([[, route]])=>route)[this.routeIndex].path;
|
|
744
1392
|
}
|
|
745
|
-
return new Response(data, {
|
|
746
|
-
status,
|
|
747
|
-
headers: this.#headers
|
|
748
|
-
});
|
|
749
|
-
};
|
|
750
|
-
body = (data, arg, headers)=>"number" == typeof arg ? this.newResponse(data, arg, headers) : this.newResponse(data, arg);
|
|
751
|
-
text = (text, arg, headers)=>{
|
|
752
|
-
if (!this.#preparedHeaders) {
|
|
753
|
-
if (this.#isFresh && !headers && !arg) return new Response(text);
|
|
754
|
-
this.#preparedHeaders = {};
|
|
755
|
-
}
|
|
756
|
-
this.#preparedHeaders["content-type"] = TEXT_PLAIN;
|
|
757
|
-
return "number" == typeof arg ? this.newResponse(text, arg, headers) : this.newResponse(text, arg);
|
|
758
1393
|
};
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
return "number" == typeof arg ? this.newResponse(body, arg, headers) : this.newResponse(body, arg);
|
|
1394
|
+
var HtmlEscapedCallbackPhase = {
|
|
1395
|
+
Stringify: 1,
|
|
1396
|
+
BeforeStream: 2,
|
|
1397
|
+
Stream: 3
|
|
764
1398
|
};
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
return
|
|
1399
|
+
var html_raw = (value, callbacks)=>{
|
|
1400
|
+
const escapedString = new String(value);
|
|
1401
|
+
escapedString.isEscaped = true;
|
|
1402
|
+
escapedString.callbacks = callbacks;
|
|
1403
|
+
return escapedString;
|
|
770
1404
|
};
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
1405
|
+
var resolveCallback = async (str, phase, preserveCallbacks, context, buffer)=>{
|
|
1406
|
+
if ("object" == typeof str && !(str instanceof String)) {
|
|
1407
|
+
if (!(str instanceof Promise)) str = str.toString();
|
|
1408
|
+
if (str instanceof Promise) str = await str;
|
|
1409
|
+
}
|
|
1410
|
+
const callbacks = str.callbacks;
|
|
1411
|
+
if (!callbacks?.length) return Promise.resolve(str);
|
|
1412
|
+
if (buffer) buffer[0] += str;
|
|
1413
|
+
else buffer = [
|
|
1414
|
+
str
|
|
1415
|
+
];
|
|
1416
|
+
const resStr = Promise.all(callbacks.map((c)=>c({
|
|
1417
|
+
phase,
|
|
1418
|
+
buffer,
|
|
1419
|
+
context
|
|
1420
|
+
}))).then((res)=>Promise.all(res.filter(Boolean).map((str2)=>resolveCallback(str2, phase, false, context, buffer))).then(()=>buffer[0]));
|
|
1421
|
+
if (preserveCallbacks) return html_raw(await resStr, callbacks);
|
|
1422
|
+
return resStr;
|
|
775
1423
|
};
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
1424
|
+
var TEXT_PLAIN = "text/plain; charset=UTF-8";
|
|
1425
|
+
var setHeaders = (headers, map = {})=>{
|
|
1426
|
+
Object.entries(map).forEach(([key, value])=>headers.set(key, value));
|
|
1427
|
+
return headers;
|
|
779
1428
|
};
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
1429
|
+
var Context = class {
|
|
1430
|
+
#rawRequest;
|
|
1431
|
+
#req;
|
|
1432
|
+
env = {};
|
|
1433
|
+
#var;
|
|
1434
|
+
finalized = false;
|
|
1435
|
+
error;
|
|
1436
|
+
#status = 200;
|
|
1437
|
+
#executionCtx;
|
|
1438
|
+
#headers;
|
|
1439
|
+
#preparedHeaders;
|
|
1440
|
+
#res;
|
|
1441
|
+
#isFresh = true;
|
|
1442
|
+
#layout;
|
|
1443
|
+
#renderer;
|
|
1444
|
+
#notFoundHandler;
|
|
1445
|
+
#matchResult;
|
|
1446
|
+
#path;
|
|
1447
|
+
constructor(req, options){
|
|
1448
|
+
this.#rawRequest = req;
|
|
1449
|
+
if (options) {
|
|
1450
|
+
this.#executionCtx = options.executionCtx;
|
|
1451
|
+
this.env = options.env;
|
|
1452
|
+
this.#notFoundHandler = options.notFoundHandler;
|
|
1453
|
+
this.#path = options.path;
|
|
1454
|
+
this.#matchResult = options.matchResult;
|
|
1455
|
+
}
|
|
806
1456
|
}
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
const allMethods = [
|
|
845
|
-
...METHODS,
|
|
846
|
-
METHOD_NAME_ALL_LOWERCASE
|
|
847
|
-
];
|
|
848
|
-
allMethods.forEach((method)=>{
|
|
849
|
-
this[method] = (args1, ...args)=>{
|
|
850
|
-
if ("string" == typeof args1) this.#path = args1;
|
|
851
|
-
else this.addRoute(method, this.#path, args1);
|
|
852
|
-
args.forEach((handler)=>{
|
|
853
|
-
if ("string" != typeof handler) this.addRoute(method, this.#path, handler);
|
|
854
|
-
});
|
|
855
|
-
return this;
|
|
856
|
-
};
|
|
857
|
-
});
|
|
858
|
-
this.on = (method, path, ...handlers)=>{
|
|
859
|
-
for (const p of [
|
|
860
|
-
path
|
|
861
|
-
].flat()){
|
|
862
|
-
this.#path = p;
|
|
863
|
-
for (const m of [
|
|
864
|
-
method
|
|
865
|
-
].flat())handlers.map((handler)=>{
|
|
866
|
-
this.addRoute(m.toUpperCase(), this.#path, handler);
|
|
867
|
-
});
|
|
1457
|
+
get req() {
|
|
1458
|
+
this.#req ??= new HonoRequest(this.#rawRequest, this.#path, this.#matchResult);
|
|
1459
|
+
return this.#req;
|
|
1460
|
+
}
|
|
1461
|
+
get event() {
|
|
1462
|
+
if (this.#executionCtx && "respondWith" in this.#executionCtx) return this.#executionCtx;
|
|
1463
|
+
throw Error("This context has no FetchEvent");
|
|
1464
|
+
}
|
|
1465
|
+
get executionCtx() {
|
|
1466
|
+
if (this.#executionCtx) return this.#executionCtx;
|
|
1467
|
+
throw Error("This context has no ExecutionContext");
|
|
1468
|
+
}
|
|
1469
|
+
get res() {
|
|
1470
|
+
this.#isFresh = false;
|
|
1471
|
+
return this.#res ||= new Response("404 Not Found", {
|
|
1472
|
+
status: 404
|
|
1473
|
+
});
|
|
1474
|
+
}
|
|
1475
|
+
set res(_res) {
|
|
1476
|
+
this.#isFresh = false;
|
|
1477
|
+
if (this.#res && _res) try {
|
|
1478
|
+
for (const [k, v] of this.#res.headers.entries())if ("content-type" !== k) {
|
|
1479
|
+
if ("set-cookie" === k) {
|
|
1480
|
+
const cookies = this.#res.headers.getSetCookie();
|
|
1481
|
+
_res.headers.delete("set-cookie");
|
|
1482
|
+
for (const cookie of cookies)_res.headers.append("set-cookie", cookie);
|
|
1483
|
+
} else _res.headers.set(k, v);
|
|
1484
|
+
}
|
|
1485
|
+
} catch (e) {
|
|
1486
|
+
if (e instanceof TypeError && e.message.includes("immutable")) {
|
|
1487
|
+
this.res = new Response(_res.body, {
|
|
1488
|
+
headers: _res.headers,
|
|
1489
|
+
status: _res.status
|
|
1490
|
+
});
|
|
1491
|
+
return;
|
|
1492
|
+
}
|
|
1493
|
+
throw e;
|
|
868
1494
|
}
|
|
869
|
-
|
|
1495
|
+
this.#res = _res;
|
|
1496
|
+
this.finalized = true;
|
|
1497
|
+
}
|
|
1498
|
+
render = (...args)=>{
|
|
1499
|
+
this.#renderer ??= (content)=>this.html(content);
|
|
1500
|
+
return this.#renderer(...args);
|
|
870
1501
|
};
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
handlers.unshift(arg1);
|
|
876
|
-
}
|
|
877
|
-
handlers.forEach((handler)=>{
|
|
878
|
-
this.addRoute(METHOD_NAME_ALL, this.#path, handler);
|
|
879
|
-
});
|
|
880
|
-
return this;
|
|
1502
|
+
setLayout = (layout)=>this.#layout = layout;
|
|
1503
|
+
getLayout = ()=>this.#layout;
|
|
1504
|
+
setRenderer = (renderer)=>{
|
|
1505
|
+
this.#renderer = renderer;
|
|
881
1506
|
};
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
const clone = new Hono({
|
|
889
|
-
router: this.router,
|
|
890
|
-
getPath: this.getPath
|
|
891
|
-
});
|
|
892
|
-
clone.routes = this.routes;
|
|
893
|
-
return clone;
|
|
894
|
-
}
|
|
895
|
-
notFoundHandler = notFoundHandler;
|
|
896
|
-
errorHandler = errorHandler;
|
|
897
|
-
route(path, app) {
|
|
898
|
-
const subApp = this.basePath(path);
|
|
899
|
-
app.routes.map((r)=>{
|
|
900
|
-
let handler;
|
|
901
|
-
if (app.errorHandler === errorHandler) handler = r.handler;
|
|
902
|
-
else {
|
|
903
|
-
handler = async (c, next)=>(await compose([], app.errorHandler)(c, ()=>r.handler(c, next))).res;
|
|
904
|
-
handler[COMPOSED_HANDLER] = r.handler;
|
|
1507
|
+
header = (name, value, options)=>{
|
|
1508
|
+
if (void 0 === value) {
|
|
1509
|
+
if (this.#headers) this.#headers.delete(name);
|
|
1510
|
+
else if (this.#preparedHeaders) delete this.#preparedHeaders[name.toLocaleLowerCase()];
|
|
1511
|
+
if (this.finalized) this.res.headers.delete(name);
|
|
1512
|
+
return;
|
|
905
1513
|
}
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
}
|
|
915
|
-
onError = (handler)=>{
|
|
916
|
-
this.errorHandler = handler;
|
|
917
|
-
return this;
|
|
918
|
-
};
|
|
919
|
-
notFound = (handler)=>{
|
|
920
|
-
this.notFoundHandler = handler;
|
|
921
|
-
return this;
|
|
922
|
-
};
|
|
923
|
-
mount(path, applicationHandler, options) {
|
|
924
|
-
let replaceRequest;
|
|
925
|
-
let optionHandler;
|
|
926
|
-
if (options) {
|
|
927
|
-
if ("function" == typeof options) optionHandler = options;
|
|
1514
|
+
if (options?.append) {
|
|
1515
|
+
if (!this.#headers) {
|
|
1516
|
+
this.#isFresh = false;
|
|
1517
|
+
this.#headers = new Headers(this.#preparedHeaders);
|
|
1518
|
+
this.#preparedHeaders = {};
|
|
1519
|
+
}
|
|
1520
|
+
this.#headers.append(name, value);
|
|
1521
|
+
} else if (this.#headers) this.#headers.set(name, value);
|
|
928
1522
|
else {
|
|
929
|
-
|
|
930
|
-
|
|
1523
|
+
this.#preparedHeaders ??= {};
|
|
1524
|
+
this.#preparedHeaders[name.toLowerCase()] = value;
|
|
1525
|
+
}
|
|
1526
|
+
if (this.finalized) {
|
|
1527
|
+
if (options?.append) this.res.headers.append(name, value);
|
|
1528
|
+
else this.res.headers.set(name, value);
|
|
931
1529
|
}
|
|
932
|
-
}
|
|
933
|
-
const getOptions = optionHandler ? (c)=>{
|
|
934
|
-
const options2 = optionHandler(c);
|
|
935
|
-
return Array.isArray(options2) ? options2 : [
|
|
936
|
-
options2
|
|
937
|
-
];
|
|
938
|
-
} : (c)=>{
|
|
939
|
-
let executionContext;
|
|
940
|
-
try {
|
|
941
|
-
executionContext = c.executionCtx;
|
|
942
|
-
} catch {}
|
|
943
|
-
return [
|
|
944
|
-
c.env,
|
|
945
|
-
executionContext
|
|
946
|
-
];
|
|
947
1530
|
};
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
r
|
|
976
|
-
]);
|
|
977
|
-
this.routes.push(r);
|
|
978
|
-
}
|
|
979
|
-
matchRoute(method, path) {
|
|
980
|
-
return this.router.match(method, path);
|
|
981
|
-
}
|
|
982
|
-
handleError(err, c) {
|
|
983
|
-
if (err instanceof Error) return this.errorHandler(err, c);
|
|
984
|
-
throw err;
|
|
985
|
-
}
|
|
986
|
-
dispatch(request, executionCtx, env, method) {
|
|
987
|
-
if ("HEAD" === method) return (async ()=>new Response(null, await this.dispatch(request, executionCtx, env, "GET")))();
|
|
988
|
-
const path = this.getPath(request, {
|
|
989
|
-
env
|
|
990
|
-
});
|
|
991
|
-
const matchResult = this.matchRoute(method, path);
|
|
992
|
-
const c = new Context(request, {
|
|
993
|
-
path,
|
|
994
|
-
matchResult,
|
|
995
|
-
env,
|
|
996
|
-
executionCtx,
|
|
997
|
-
notFoundHandler: this.notFoundHandler
|
|
998
|
-
});
|
|
999
|
-
if (1 === matchResult[0].length) {
|
|
1000
|
-
let res;
|
|
1001
|
-
try {
|
|
1002
|
-
res = matchResult[0][0][0][0](c, async ()=>{
|
|
1003
|
-
c.res = await this.notFoundHandler(c);
|
|
1531
|
+
status = (status)=>{
|
|
1532
|
+
this.#isFresh = false;
|
|
1533
|
+
this.#status = status;
|
|
1534
|
+
};
|
|
1535
|
+
set = (key, value)=>{
|
|
1536
|
+
this.#var ??= /* @__PURE__ */ new Map();
|
|
1537
|
+
this.#var.set(key, value);
|
|
1538
|
+
};
|
|
1539
|
+
get = (key)=>this.#var ? this.#var.get(key) : void 0;
|
|
1540
|
+
get var() {
|
|
1541
|
+
if (!this.#var) return {};
|
|
1542
|
+
return Object.fromEntries(this.#var);
|
|
1543
|
+
}
|
|
1544
|
+
newResponse = (data, arg, headers)=>{
|
|
1545
|
+
if (this.#isFresh && !headers && !arg && 200 === this.#status) return new Response(data, {
|
|
1546
|
+
headers: this.#preparedHeaders
|
|
1547
|
+
});
|
|
1548
|
+
if (arg && "number" != typeof arg) {
|
|
1549
|
+
const header = new Headers(arg.headers);
|
|
1550
|
+
if (this.#headers) this.#headers.forEach((v, k)=>{
|
|
1551
|
+
if ("set-cookie" === k) header.append(k, v);
|
|
1552
|
+
else header.set(k, v);
|
|
1553
|
+
});
|
|
1554
|
+
const headers2 = setHeaders(header, this.#preparedHeaders);
|
|
1555
|
+
return new Response(data, {
|
|
1556
|
+
headers: headers2,
|
|
1557
|
+
status: arg.status ?? this.#status
|
|
1004
1558
|
});
|
|
1005
|
-
} catch (err) {
|
|
1006
|
-
return this.handleError(err, c);
|
|
1007
1559
|
}
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1560
|
+
const status = "number" == typeof arg ? arg : this.#status;
|
|
1561
|
+
this.#preparedHeaders ??= {};
|
|
1562
|
+
this.#headers ??= new Headers();
|
|
1563
|
+
setHeaders(this.#headers, this.#preparedHeaders);
|
|
1564
|
+
if (this.#res) {
|
|
1565
|
+
this.#res.headers.forEach((v, k)=>{
|
|
1566
|
+
if ("set-cookie" === k) this.#headers?.append(k, v);
|
|
1567
|
+
else this.#headers?.set(k, v);
|
|
1568
|
+
});
|
|
1569
|
+
setHeaders(this.#headers, this.#preparedHeaders);
|
|
1018
1570
|
}
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
if (void 0 !== requestInit) input = new Request(input, requestInit);
|
|
1025
|
-
return this.fetch(input, Env, executionCtx);
|
|
1026
|
-
}
|
|
1027
|
-
input = input.toString();
|
|
1028
|
-
const path = /^https?:\/\//.test(input) ? input : `http://localhost${mergePath("/", input)}`;
|
|
1029
|
-
const req = new Request(path, requestInit);
|
|
1030
|
-
return this.fetch(req, Env, executionCtx);
|
|
1031
|
-
};
|
|
1032
|
-
fire = ()=>{
|
|
1033
|
-
addEventListener("fetch", (event)=>{
|
|
1034
|
-
event.respondWith(this.dispatch(event.request, event, void 0, event.request.method));
|
|
1035
|
-
});
|
|
1036
|
-
};
|
|
1037
|
-
};
|
|
1038
|
-
var LABEL_REG_EXP_STR = "[^/]+";
|
|
1039
|
-
var ONLY_WILDCARD_REG_EXP_STR = ".*";
|
|
1040
|
-
var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
|
|
1041
|
-
var PATH_ERROR = Symbol();
|
|
1042
|
-
var regExpMetaChars = new Set(".\\+*[^]$()");
|
|
1043
|
-
function compareKey(a, b) {
|
|
1044
|
-
if (1 === a.length) return 1 === b.length ? a < b ? -1 : 1 : -1;
|
|
1045
|
-
if (1 === b.length) return 1;
|
|
1046
|
-
if (a === ONLY_WILDCARD_REG_EXP_STR || a === TAIL_WILDCARD_REG_EXP_STR) return 1;
|
|
1047
|
-
if (b === ONLY_WILDCARD_REG_EXP_STR || b === TAIL_WILDCARD_REG_EXP_STR) return -1;
|
|
1048
|
-
if (a === LABEL_REG_EXP_STR) return 1;
|
|
1049
|
-
if (b === LABEL_REG_EXP_STR) return -1;
|
|
1050
|
-
return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
|
|
1051
|
-
}
|
|
1052
|
-
var Node = class {
|
|
1053
|
-
index;
|
|
1054
|
-
varIndex;
|
|
1055
|
-
children = /* @__PURE__ */ Object.create(null);
|
|
1056
|
-
insert(tokens, index, paramMap, context, pathErrorCheckOnly) {
|
|
1057
|
-
if (0 === tokens.length) {
|
|
1058
|
-
if (void 0 !== this.index) throw PATH_ERROR;
|
|
1059
|
-
if (pathErrorCheckOnly) return;
|
|
1060
|
-
this.index = index;
|
|
1061
|
-
return;
|
|
1062
|
-
}
|
|
1063
|
-
const [token, ...restTokens] = tokens;
|
|
1064
|
-
const pattern = "*" === token ? 0 === restTokens.length ? [
|
|
1065
|
-
"",
|
|
1066
|
-
"",
|
|
1067
|
-
ONLY_WILDCARD_REG_EXP_STR
|
|
1068
|
-
] : [
|
|
1069
|
-
"",
|
|
1070
|
-
"",
|
|
1071
|
-
LABEL_REG_EXP_STR
|
|
1072
|
-
] : "/*" === token ? [
|
|
1073
|
-
"",
|
|
1074
|
-
"",
|
|
1075
|
-
TAIL_WILDCARD_REG_EXP_STR
|
|
1076
|
-
] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
1077
|
-
let node;
|
|
1078
|
-
if (pattern) {
|
|
1079
|
-
const name = pattern[1];
|
|
1080
|
-
let regexpStr = pattern[2] || LABEL_REG_EXP_STR;
|
|
1081
|
-
if (name && pattern[2]) {
|
|
1082
|
-
regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
|
|
1083
|
-
if (/\((?!\?:)/.test(regexpStr)) throw PATH_ERROR;
|
|
1084
|
-
}
|
|
1085
|
-
node = this.children[regexpStr];
|
|
1086
|
-
if (!node) {
|
|
1087
|
-
if (Object.keys(this.children).some((k)=>k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR)) throw PATH_ERROR;
|
|
1088
|
-
if (pathErrorCheckOnly) return;
|
|
1089
|
-
node = this.children[regexpStr] = new Node();
|
|
1090
|
-
if ("" !== name) node.varIndex = context.varIndex++;
|
|
1571
|
+
headers ??= {};
|
|
1572
|
+
for (const [k, v] of Object.entries(headers))if ("string" == typeof v) this.#headers.set(k, v);
|
|
1573
|
+
else {
|
|
1574
|
+
this.#headers.delete(k);
|
|
1575
|
+
for (const v2 of v)this.#headers.append(k, v2);
|
|
1091
1576
|
}
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
}
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
if (
|
|
1101
|
-
|
|
1577
|
+
return new Response(data, {
|
|
1578
|
+
status,
|
|
1579
|
+
headers: this.#headers
|
|
1580
|
+
});
|
|
1581
|
+
};
|
|
1582
|
+
body = (data, arg, headers)=>"number" == typeof arg ? this.newResponse(data, arg, headers) : this.newResponse(data, arg);
|
|
1583
|
+
text = (text, arg, headers)=>{
|
|
1584
|
+
if (!this.#preparedHeaders) {
|
|
1585
|
+
if (this.#isFresh && !headers && !arg) return new Response(text);
|
|
1586
|
+
this.#preparedHeaders = {};
|
|
1102
1587
|
}
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
return
|
|
1111
|
-
}
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
};
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1588
|
+
this.#preparedHeaders["content-type"] = TEXT_PLAIN;
|
|
1589
|
+
return "number" == typeof arg ? this.newResponse(text, arg, headers) : this.newResponse(text, arg);
|
|
1590
|
+
};
|
|
1591
|
+
json = (object, arg, headers)=>{
|
|
1592
|
+
const body = JSON.stringify(object);
|
|
1593
|
+
this.#preparedHeaders ??= {};
|
|
1594
|
+
this.#preparedHeaders["content-type"] = "application/json; charset=UTF-8";
|
|
1595
|
+
return "number" == typeof arg ? this.newResponse(body, arg, headers) : this.newResponse(body, arg);
|
|
1596
|
+
};
|
|
1597
|
+
html = (html, arg, headers)=>{
|
|
1598
|
+
this.#preparedHeaders ??= {};
|
|
1599
|
+
this.#preparedHeaders["content-type"] = "text/html; charset=UTF-8";
|
|
1600
|
+
if ("object" == typeof html) return resolveCallback(html, HtmlEscapedCallbackPhase.Stringify, false, {}).then((html2)=>"number" == typeof arg ? this.newResponse(html2, arg, headers) : this.newResponse(html2, arg));
|
|
1601
|
+
return "number" == typeof arg ? this.newResponse(html, arg, headers) : this.newResponse(html, arg);
|
|
1602
|
+
};
|
|
1603
|
+
redirect = (location, status)=>{
|
|
1604
|
+
this.#headers ??= new Headers();
|
|
1605
|
+
this.#headers.set("Location", location);
|
|
1606
|
+
return this.newResponse(null, status ?? 302);
|
|
1607
|
+
};
|
|
1608
|
+
notFound = ()=>{
|
|
1609
|
+
this.#notFoundHandler ??= ()=>new Response();
|
|
1610
|
+
return this.#notFoundHandler(this);
|
|
1611
|
+
};
|
|
1121
1612
|
};
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
i
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1613
|
+
var compose = (middleware, onError, onNotFound)=>(context, next)=>{
|
|
1614
|
+
let index = -1;
|
|
1615
|
+
return dispatch(0);
|
|
1616
|
+
async function dispatch(i) {
|
|
1617
|
+
if (i <= index) throw new Error("next() called multiple times");
|
|
1618
|
+
index = i;
|
|
1619
|
+
let res;
|
|
1620
|
+
let isError = false;
|
|
1621
|
+
let handler;
|
|
1622
|
+
if (middleware[i]) {
|
|
1623
|
+
handler = middleware[i][0][0];
|
|
1624
|
+
if (context instanceof Context) context.req.routeIndex = i;
|
|
1625
|
+
} else handler = i === middleware.length && next || void 0;
|
|
1626
|
+
if (handler) try {
|
|
1627
|
+
res = await handler(context, ()=>dispatch(i + 1));
|
|
1628
|
+
} catch (err) {
|
|
1629
|
+
if (err instanceof Error && context instanceof Context && onError) {
|
|
1630
|
+
context.error = err;
|
|
1631
|
+
res = await onError(err, context);
|
|
1632
|
+
isError = true;
|
|
1633
|
+
} else throw err;
|
|
1634
|
+
}
|
|
1635
|
+
else if (context instanceof Context && false === context.finalized && onNotFound) res = await onNotFound(context);
|
|
1636
|
+
if (res && (false === context.finalized || isError)) context.res = res;
|
|
1637
|
+
return context;
|
|
1146
1638
|
}
|
|
1639
|
+
};
|
|
1640
|
+
var METHOD_NAME_ALL = "ALL";
|
|
1641
|
+
var METHOD_NAME_ALL_LOWERCASE = "all";
|
|
1642
|
+
var METHODS = [
|
|
1643
|
+
"get",
|
|
1644
|
+
"post",
|
|
1645
|
+
"put",
|
|
1646
|
+
"delete",
|
|
1647
|
+
"options",
|
|
1648
|
+
"patch"
|
|
1649
|
+
];
|
|
1650
|
+
var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
|
|
1651
|
+
var UnsupportedPathError = class extends Error {
|
|
1652
|
+
};
|
|
1653
|
+
var COMPOSED_HANDLER = Symbol("composedHandler");
|
|
1654
|
+
var notFoundHandler = (c)=>c.text("404 Not Found", 404);
|
|
1655
|
+
var errorHandler = (err, c)=>{
|
|
1656
|
+
if ("getResponse" in err) return err.getResponse();
|
|
1657
|
+
console.error(err);
|
|
1658
|
+
return c.text("Internal Server Error", 500);
|
|
1659
|
+
};
|
|
1660
|
+
var Hono = class {
|
|
1661
|
+
get;
|
|
1662
|
+
post;
|
|
1663
|
+
put;
|
|
1664
|
+
delete;
|
|
1665
|
+
options;
|
|
1666
|
+
patch;
|
|
1667
|
+
all;
|
|
1668
|
+
on;
|
|
1669
|
+
use;
|
|
1670
|
+
router;
|
|
1671
|
+
getPath;
|
|
1672
|
+
_basePath = "/";
|
|
1673
|
+
#path = "/";
|
|
1674
|
+
routes = [];
|
|
1675
|
+
constructor(options = {}){
|
|
1676
|
+
const allMethods = [
|
|
1677
|
+
...METHODS,
|
|
1678
|
+
METHOD_NAME_ALL_LOWERCASE
|
|
1679
|
+
];
|
|
1680
|
+
allMethods.forEach((method)=>{
|
|
1681
|
+
this[method] = (args1, ...args)=>{
|
|
1682
|
+
if ("string" == typeof args1) this.#path = args1;
|
|
1683
|
+
else this.addRoute(method, this.#path, args1);
|
|
1684
|
+
args.forEach((handler)=>{
|
|
1685
|
+
if ("string" != typeof handler) this.addRoute(method, this.#path, handler);
|
|
1686
|
+
});
|
|
1687
|
+
return this;
|
|
1688
|
+
};
|
|
1689
|
+
});
|
|
1690
|
+
this.on = (method, path, ...handlers)=>{
|
|
1691
|
+
for (const p of [
|
|
1692
|
+
path
|
|
1693
|
+
].flat()){
|
|
1694
|
+
this.#path = p;
|
|
1695
|
+
for (const m of [
|
|
1696
|
+
method
|
|
1697
|
+
].flat())handlers.map((handler)=>{
|
|
1698
|
+
this.addRoute(m.toUpperCase(), this.#path, handler);
|
|
1699
|
+
});
|
|
1700
|
+
}
|
|
1701
|
+
return this;
|
|
1702
|
+
};
|
|
1703
|
+
this.use = (arg1, ...handlers)=>{
|
|
1704
|
+
if ("string" == typeof arg1) this.#path = arg1;
|
|
1705
|
+
else {
|
|
1706
|
+
this.#path = "*";
|
|
1707
|
+
handlers.unshift(arg1);
|
|
1708
|
+
}
|
|
1709
|
+
handlers.forEach((handler)=>{
|
|
1710
|
+
this.addRoute(METHOD_NAME_ALL, this.#path, handler);
|
|
1711
|
+
});
|
|
1712
|
+
return this;
|
|
1713
|
+
};
|
|
1714
|
+
const strict = options.strict ?? true;
|
|
1715
|
+
delete options.strict;
|
|
1716
|
+
Object.assign(this, options);
|
|
1717
|
+
this.getPath = strict ? options.getPath ?? getPath : getPathNoStrict;
|
|
1147
1718
|
}
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
}
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
[],
|
|
1180
|
-
/* @__PURE__ */ Object.create(null)
|
|
1181
|
-
];
|
|
1182
|
-
var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
1183
|
-
function buildWildcardRegExp(path) {
|
|
1184
|
-
return wildcardRegExpCache[path] ??= new RegExp("*" === path ? "" : `^${path.replace(/\/\*$|([.\\+*[^\]$()])/g, (_, metaChar)=>metaChar ? `\\${metaChar}` : "(?:|/.*)")}$`);
|
|
1185
|
-
}
|
|
1186
|
-
function clearWildcardRegExpCache() {
|
|
1187
|
-
wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
1188
|
-
}
|
|
1189
|
-
function buildMatcherFromPreprocessedRoutes(routes) {
|
|
1190
|
-
const trie = new Trie();
|
|
1191
|
-
const handlerData = [];
|
|
1192
|
-
if (0 === routes.length) return nullMatcher;
|
|
1193
|
-
const routesWithStaticPathFlag = routes.map((route)=>[
|
|
1194
|
-
!/\*|\/:/.test(route[0]),
|
|
1195
|
-
...route
|
|
1196
|
-
]).sort(([isStaticA, pathA], [isStaticB, pathB])=>isStaticA ? 1 : isStaticB ? -1 : pathA.length - pathB.length);
|
|
1197
|
-
const staticMap = /* @__PURE__ */ Object.create(null);
|
|
1198
|
-
for(let i = 0, j = -1, len = routesWithStaticPathFlag.length; i < len; i++){
|
|
1199
|
-
const [pathErrorCheckOnly, path, handlers] = routesWithStaticPathFlag[i];
|
|
1200
|
-
if (pathErrorCheckOnly) staticMap[path] = [
|
|
1201
|
-
handlers.map(([h])=>[
|
|
1202
|
-
h,
|
|
1203
|
-
/* @__PURE__ */ Object.create(null)
|
|
1204
|
-
]),
|
|
1205
|
-
emptyParam
|
|
1206
|
-
];
|
|
1207
|
-
else j++;
|
|
1208
|
-
let paramAssoc;
|
|
1209
|
-
try {
|
|
1210
|
-
paramAssoc = trie.insert(path, j, pathErrorCheckOnly);
|
|
1211
|
-
} catch (e) {
|
|
1212
|
-
throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
|
|
1213
|
-
}
|
|
1214
|
-
if (!pathErrorCheckOnly) handlerData[j] = handlers.map(([h, paramCount])=>{
|
|
1215
|
-
const paramIndexMap = /* @__PURE__ */ Object.create(null);
|
|
1216
|
-
paramCount -= 1;
|
|
1217
|
-
for(; paramCount >= 0; paramCount--){
|
|
1218
|
-
const [key, value] = paramAssoc[paramCount];
|
|
1219
|
-
paramIndexMap[key] = value;
|
|
1220
|
-
}
|
|
1221
|
-
return [
|
|
1222
|
-
h,
|
|
1223
|
-
paramIndexMap
|
|
1224
|
-
];
|
|
1225
|
-
});
|
|
1226
|
-
}
|
|
1227
|
-
const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
|
|
1228
|
-
for(let i = 0, len = handlerData.length; i < len; i++)for(let j = 0, len2 = handlerData[i].length; j < len2; j++){
|
|
1229
|
-
const map = handlerData[i][j]?.[1];
|
|
1230
|
-
if (!map) continue;
|
|
1231
|
-
const keys = Object.keys(map);
|
|
1232
|
-
for(let k = 0, len3 = keys.length; k < len3; k++)map[keys[k]] = paramReplacementMap[map[keys[k]]];
|
|
1233
|
-
}
|
|
1234
|
-
const handlerMap = [];
|
|
1235
|
-
for(const i in indexReplacementMap)handlerMap[i] = handlerData[indexReplacementMap[i]];
|
|
1236
|
-
return [
|
|
1237
|
-
regexp,
|
|
1238
|
-
handlerMap,
|
|
1239
|
-
staticMap
|
|
1240
|
-
];
|
|
1241
|
-
}
|
|
1242
|
-
function findMiddleware(middleware, path) {
|
|
1243
|
-
if (!middleware) return;
|
|
1244
|
-
for (const k of Object.keys(middleware).sort((a, b)=>b.length - a.length))if (buildWildcardRegExp(k).test(path)) return [
|
|
1245
|
-
...middleware[k]
|
|
1246
|
-
];
|
|
1247
|
-
}
|
|
1248
|
-
var RegExpRouter = class {
|
|
1249
|
-
name = "RegExpRouter";
|
|
1250
|
-
middleware;
|
|
1251
|
-
routes;
|
|
1252
|
-
constructor(){
|
|
1253
|
-
this.middleware = {
|
|
1254
|
-
[METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null)
|
|
1719
|
+
clone() {
|
|
1720
|
+
const clone = new Hono({
|
|
1721
|
+
router: this.router,
|
|
1722
|
+
getPath: this.getPath
|
|
1723
|
+
});
|
|
1724
|
+
clone.routes = this.routes;
|
|
1725
|
+
return clone;
|
|
1726
|
+
}
|
|
1727
|
+
notFoundHandler = notFoundHandler;
|
|
1728
|
+
errorHandler = errorHandler;
|
|
1729
|
+
route(path, app) {
|
|
1730
|
+
const subApp = this.basePath(path);
|
|
1731
|
+
app.routes.map((r)=>{
|
|
1732
|
+
let handler;
|
|
1733
|
+
if (app.errorHandler === errorHandler) handler = r.handler;
|
|
1734
|
+
else {
|
|
1735
|
+
handler = async (c, next)=>(await compose([], app.errorHandler)(c, ()=>r.handler(c, next))).res;
|
|
1736
|
+
handler[COMPOSED_HANDLER] = r.handler;
|
|
1737
|
+
}
|
|
1738
|
+
subApp.addRoute(r.method, r.path, handler);
|
|
1739
|
+
});
|
|
1740
|
+
return this;
|
|
1741
|
+
}
|
|
1742
|
+
basePath(path) {
|
|
1743
|
+
const subApp = this.clone();
|
|
1744
|
+
subApp._basePath = mergePath(this._basePath, path);
|
|
1745
|
+
return subApp;
|
|
1746
|
+
}
|
|
1747
|
+
onError = (handler)=>{
|
|
1748
|
+
this.errorHandler = handler;
|
|
1749
|
+
return this;
|
|
1255
1750
|
};
|
|
1256
|
-
|
|
1257
|
-
|
|
1751
|
+
notFound = (handler)=>{
|
|
1752
|
+
this.notFoundHandler = handler;
|
|
1753
|
+
return this;
|
|
1258
1754
|
};
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1755
|
+
mount(path, applicationHandler, options) {
|
|
1756
|
+
let replaceRequest;
|
|
1757
|
+
let optionHandler;
|
|
1758
|
+
if (options) {
|
|
1759
|
+
if ("function" == typeof options) optionHandler = options;
|
|
1760
|
+
else {
|
|
1761
|
+
optionHandler = options.optionHandler;
|
|
1762
|
+
replaceRequest = options.replaceRequest;
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
const getOptions = optionHandler ? (c)=>{
|
|
1766
|
+
const options2 = optionHandler(c);
|
|
1767
|
+
return Array.isArray(options2) ? options2 : [
|
|
1768
|
+
options2
|
|
1769
|
+
];
|
|
1770
|
+
} : (c)=>{
|
|
1771
|
+
let executionContext;
|
|
1772
|
+
try {
|
|
1773
|
+
executionContext = c.executionCtx;
|
|
1774
|
+
} catch {}
|
|
1775
|
+
return [
|
|
1776
|
+
c.env,
|
|
1777
|
+
executionContext
|
|
1271
1778
|
];
|
|
1779
|
+
};
|
|
1780
|
+
replaceRequest ||= (()=>{
|
|
1781
|
+
const mergedPath = mergePath(this._basePath, path);
|
|
1782
|
+
const pathPrefixLength = "/" === mergedPath ? 0 : mergedPath.length;
|
|
1783
|
+
return (request)=>{
|
|
1784
|
+
const url = new URL(request.url);
|
|
1785
|
+
url.pathname = url.pathname.slice(pathPrefixLength) || "/";
|
|
1786
|
+
return new Request(url, request);
|
|
1787
|
+
};
|
|
1788
|
+
})();
|
|
1789
|
+
const handler = async (c, next)=>{
|
|
1790
|
+
const res = await applicationHandler(replaceRequest(c.req.raw), ...getOptions(c));
|
|
1791
|
+
if (res) return res;
|
|
1792
|
+
await next();
|
|
1793
|
+
};
|
|
1794
|
+
this.addRoute(METHOD_NAME_ALL, mergePath(path, "*"), handler);
|
|
1795
|
+
return this;
|
|
1796
|
+
}
|
|
1797
|
+
addRoute(method, path, handler) {
|
|
1798
|
+
method = method.toUpperCase();
|
|
1799
|
+
path = mergePath(this._basePath, path);
|
|
1800
|
+
const r = {
|
|
1801
|
+
path,
|
|
1802
|
+
method,
|
|
1803
|
+
handler
|
|
1804
|
+
};
|
|
1805
|
+
this.router.add(method, path, [
|
|
1806
|
+
handler,
|
|
1807
|
+
r
|
|
1808
|
+
]);
|
|
1809
|
+
this.routes.push(r);
|
|
1810
|
+
}
|
|
1811
|
+
matchRoute(method, path) {
|
|
1812
|
+
return this.router.match(method, path);
|
|
1813
|
+
}
|
|
1814
|
+
handleError(err, c) {
|
|
1815
|
+
if (err instanceof Error) return this.errorHandler(err, c);
|
|
1816
|
+
throw err;
|
|
1817
|
+
}
|
|
1818
|
+
dispatch(request, executionCtx, env, method) {
|
|
1819
|
+
if ("HEAD" === method) return (async ()=>new Response(null, await this.dispatch(request, executionCtx, env, "GET")))();
|
|
1820
|
+
const path = this.getPath(request, {
|
|
1821
|
+
env
|
|
1272
1822
|
});
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1823
|
+
const matchResult = this.matchRoute(method, path);
|
|
1824
|
+
const c = new Context(request, {
|
|
1825
|
+
path,
|
|
1826
|
+
matchResult,
|
|
1827
|
+
env,
|
|
1828
|
+
executionCtx,
|
|
1829
|
+
notFoundHandler: this.notFoundHandler
|
|
1280
1830
|
});
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1831
|
+
if (1 === matchResult[0].length) {
|
|
1832
|
+
let res;
|
|
1833
|
+
try {
|
|
1834
|
+
res = matchResult[0][0][0][0](c, async ()=>{
|
|
1835
|
+
c.res = await this.notFoundHandler(c);
|
|
1836
|
+
});
|
|
1837
|
+
} catch (err) {
|
|
1838
|
+
return this.handleError(err, c);
|
|
1839
|
+
}
|
|
1840
|
+
return res instanceof Promise ? res.then((resolved)=>resolved || (c.finalized ? c.res : this.notFoundHandler(c))).catch((err)=>this.handleError(err, c)) : res ?? this.notFoundHandler(c);
|
|
1841
|
+
}
|
|
1842
|
+
const composed = compose(matchResult[0], this.errorHandler, this.notFoundHandler);
|
|
1843
|
+
return (async ()=>{
|
|
1844
|
+
try {
|
|
1845
|
+
const context = await composed(c);
|
|
1846
|
+
if (!context.finalized) throw new Error("Context is not finalized. Did you forget to return a Response object or `await next()`?");
|
|
1847
|
+
return context.res;
|
|
1848
|
+
} catch (err) {
|
|
1849
|
+
return this.handleError(err, c);
|
|
1850
|
+
}
|
|
1851
|
+
})();
|
|
1852
|
+
}
|
|
1853
|
+
fetch = (request, ...rest)=>this.dispatch(request, rest[1], rest[0], request.method);
|
|
1854
|
+
request = (input, requestInit, Env, executionCtx)=>{
|
|
1855
|
+
if (input instanceof Request) {
|
|
1856
|
+
if (void 0 !== requestInit) input = new Request(input, requestInit);
|
|
1857
|
+
return this.fetch(input, Env, executionCtx);
|
|
1858
|
+
}
|
|
1859
|
+
input = input.toString();
|
|
1860
|
+
const path = /^https?:\/\//.test(input) ? input : `http://localhost${mergePath("/", input)}`;
|
|
1861
|
+
const req = new Request(path, requestInit);
|
|
1862
|
+
return this.fetch(req, Env, executionCtx);
|
|
1863
|
+
};
|
|
1864
|
+
fire = ()=>{
|
|
1865
|
+
addEventListener("fetch", (event)=>{
|
|
1866
|
+
event.respondWith(this.dispatch(event.request, event, void 0, event.request.method));
|
|
1289
1867
|
});
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1868
|
+
};
|
|
1869
|
+
};
|
|
1870
|
+
var LABEL_REG_EXP_STR = "[^/]+";
|
|
1871
|
+
var ONLY_WILDCARD_REG_EXP_STR = ".*";
|
|
1872
|
+
var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
|
|
1873
|
+
var PATH_ERROR = Symbol();
|
|
1874
|
+
var regExpMetaChars = new Set(".\\+*[^]$()");
|
|
1875
|
+
function compareKey(a, b) {
|
|
1876
|
+
if (1 === a.length) return 1 === b.length ? a < b ? -1 : 1 : -1;
|
|
1877
|
+
if (1 === b.length) return 1;
|
|
1878
|
+
if (a === ONLY_WILDCARD_REG_EXP_STR || a === TAIL_WILDCARD_REG_EXP_STR) return 1;
|
|
1879
|
+
if (b === ONLY_WILDCARD_REG_EXP_STR || b === TAIL_WILDCARD_REG_EXP_STR) return -1;
|
|
1880
|
+
if (a === LABEL_REG_EXP_STR) return 1;
|
|
1881
|
+
if (b === LABEL_REG_EXP_STR) return -1;
|
|
1882
|
+
return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
|
|
1883
|
+
}
|
|
1884
|
+
var Node = class {
|
|
1885
|
+
index;
|
|
1886
|
+
varIndex;
|
|
1887
|
+
children = /* @__PURE__ */ Object.create(null);
|
|
1888
|
+
insert(tokens, index, paramMap, context, pathErrorCheckOnly) {
|
|
1889
|
+
if (0 === tokens.length) {
|
|
1890
|
+
if (void 0 !== this.index) throw PATH_ERROR;
|
|
1891
|
+
if (pathErrorCheckOnly) return;
|
|
1892
|
+
this.index = index;
|
|
1893
|
+
return;
|
|
1894
|
+
}
|
|
1895
|
+
const [token, ...restTokens] = tokens;
|
|
1896
|
+
const pattern = "*" === token ? 0 === restTokens.length ? [
|
|
1897
|
+
"",
|
|
1898
|
+
"",
|
|
1899
|
+
ONLY_WILDCARD_REG_EXP_STR
|
|
1900
|
+
] : [
|
|
1901
|
+
"",
|
|
1902
|
+
"",
|
|
1903
|
+
LABEL_REG_EXP_STR
|
|
1904
|
+
] : "/*" === token ? [
|
|
1905
|
+
"",
|
|
1906
|
+
"",
|
|
1907
|
+
TAIL_WILDCARD_REG_EXP_STR
|
|
1908
|
+
] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
1909
|
+
let node;
|
|
1910
|
+
if (pattern) {
|
|
1911
|
+
const name = pattern[1];
|
|
1912
|
+
let regexpStr = pattern[2] || LABEL_REG_EXP_STR;
|
|
1913
|
+
if (name && pattern[2]) {
|
|
1914
|
+
regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
|
|
1915
|
+
if (/\((?!\?:)/.test(regexpStr)) throw PATH_ERROR;
|
|
1916
|
+
}
|
|
1917
|
+
node = this.children[regexpStr];
|
|
1918
|
+
if (!node) {
|
|
1919
|
+
if (Object.keys(this.children).some((k)=>k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR)) throw PATH_ERROR;
|
|
1920
|
+
if (pathErrorCheckOnly) return;
|
|
1921
|
+
node = this.children[regexpStr] = new Node();
|
|
1922
|
+
if ("" !== name) node.varIndex = context.varIndex++;
|
|
1923
|
+
}
|
|
1924
|
+
if (!pathErrorCheckOnly && "" !== name) paramMap.push([
|
|
1925
|
+
name,
|
|
1926
|
+
node.varIndex
|
|
1927
|
+
]);
|
|
1928
|
+
} else {
|
|
1929
|
+
node = this.children[token];
|
|
1930
|
+
if (!node) {
|
|
1931
|
+
if (Object.keys(this.children).some((k)=>k.length > 1 && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR)) throw PATH_ERROR;
|
|
1932
|
+
if (pathErrorCheckOnly) return;
|
|
1933
|
+
node = this.children[token] = new Node();
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
node.insert(restTokens, index, paramMap, context, pathErrorCheckOnly);
|
|
1937
|
+
}
|
|
1938
|
+
buildRegExpStr() {
|
|
1939
|
+
const childKeys = Object.keys(this.children).sort(compareKey);
|
|
1940
|
+
const strList = childKeys.map((k)=>{
|
|
1941
|
+
const c = this.children[k];
|
|
1942
|
+
return ("number" == typeof c.varIndex ? `(${k})@${c.varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr();
|
|
1295
1943
|
});
|
|
1296
|
-
|
|
1944
|
+
if ("number" == typeof this.index) strList.unshift(`#${this.index}`);
|
|
1945
|
+
if (0 === strList.length) return "";
|
|
1946
|
+
if (1 === strList.length) return strList[0];
|
|
1947
|
+
return "(?:" + strList.join("|") + ")";
|
|
1297
1948
|
}
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1949
|
+
};
|
|
1950
|
+
var Trie = class {
|
|
1951
|
+
context = {
|
|
1952
|
+
varIndex: 0
|
|
1953
|
+
};
|
|
1954
|
+
root = new Node();
|
|
1955
|
+
insert(path, index, pathErrorCheckOnly) {
|
|
1956
|
+
const paramAssoc = [];
|
|
1957
|
+
const groups = [];
|
|
1958
|
+
for(let i = 0;;){
|
|
1959
|
+
let replaced = false;
|
|
1960
|
+
path = path.replace(/\{[^}]+\}/g, (m)=>{
|
|
1961
|
+
const mark = `@\\${i}`;
|
|
1962
|
+
groups[i] = [
|
|
1963
|
+
mark,
|
|
1964
|
+
m
|
|
1307
1965
|
];
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1966
|
+
i++;
|
|
1967
|
+
replaced = true;
|
|
1968
|
+
return mark;
|
|
1969
|
+
});
|
|
1970
|
+
if (!replaced) break;
|
|
1971
|
+
}
|
|
1972
|
+
const tokens = path.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
|
|
1973
|
+
for(let i = groups.length - 1; i >= 0; i--){
|
|
1974
|
+
const [mark] = groups[i];
|
|
1975
|
+
for(let j = tokens.length - 1; j >= 0; j--)if (-1 !== tokens[j].indexOf(mark)) {
|
|
1976
|
+
tokens[j] = tokens[j].replace(mark, groups[i][1]);
|
|
1977
|
+
break;
|
|
1312
1978
|
}
|
|
1313
|
-
}
|
|
1979
|
+
}
|
|
1980
|
+
this.root.insert(tokens, index, paramAssoc, this.context, pathErrorCheckOnly);
|
|
1981
|
+
return paramAssoc;
|
|
1314
1982
|
}
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
this.match = (method2, path2)=>{
|
|
1320
|
-
const matcher = matchers[method2] || matchers[METHOD_NAME_ALL];
|
|
1321
|
-
const staticMatch = matcher[2][path2];
|
|
1322
|
-
if (staticMatch) return staticMatch;
|
|
1323
|
-
const match = path2.match(matcher[0]);
|
|
1324
|
-
if (!match) return [
|
|
1983
|
+
buildRegExp() {
|
|
1984
|
+
let regexp = this.root.buildRegExpStr();
|
|
1985
|
+
if ("" === regexp) return [
|
|
1986
|
+
/^$/,
|
|
1325
1987
|
[],
|
|
1326
|
-
|
|
1988
|
+
[]
|
|
1327
1989
|
];
|
|
1328
|
-
|
|
1990
|
+
let captureIndex = 0;
|
|
1991
|
+
const indexReplacementMap = [];
|
|
1992
|
+
const paramReplacementMap = [];
|
|
1993
|
+
regexp = regexp.replace(/#(\d+)|@(\d+)|\.\*\$/g, (_, handlerIndex, paramIndex)=>{
|
|
1994
|
+
if (void 0 !== handlerIndex) {
|
|
1995
|
+
indexReplacementMap[++captureIndex] = Number(handlerIndex);
|
|
1996
|
+
return "$()";
|
|
1997
|
+
}
|
|
1998
|
+
if (void 0 !== paramIndex) paramReplacementMap[Number(paramIndex)] = ++captureIndex;
|
|
1999
|
+
return "";
|
|
2000
|
+
});
|
|
1329
2001
|
return [
|
|
1330
|
-
|
|
1331
|
-
|
|
2002
|
+
new RegExp(`^${regexp}`),
|
|
2003
|
+
indexReplacementMap,
|
|
2004
|
+
paramReplacementMap
|
|
1332
2005
|
];
|
|
1333
|
-
}
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
[
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
});
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
[
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
}
|
|
1369
|
-
};
|
|
1370
|
-
var SmartRouter = class {
|
|
1371
|
-
name = "SmartRouter";
|
|
1372
|
-
routers = [];
|
|
1373
|
-
routes = [];
|
|
1374
|
-
constructor(init){
|
|
1375
|
-
Object.assign(this, init);
|
|
1376
|
-
}
|
|
1377
|
-
add(method, path, handler) {
|
|
1378
|
-
if (!this.routes) throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
1379
|
-
this.routes.push([
|
|
1380
|
-
method,
|
|
1381
|
-
path,
|
|
1382
|
-
handler
|
|
1383
|
-
]);
|
|
1384
|
-
}
|
|
1385
|
-
match(method, path) {
|
|
1386
|
-
if (!this.routes) throw new Error("Fatal error");
|
|
1387
|
-
const { routers, routes } = this;
|
|
1388
|
-
const len = routers.length;
|
|
1389
|
-
let i = 0;
|
|
1390
|
-
let res;
|
|
1391
|
-
for(; i < len; i++){
|
|
1392
|
-
const router = routers[i];
|
|
2006
|
+
}
|
|
2007
|
+
};
|
|
2008
|
+
var emptyParam = [];
|
|
2009
|
+
var nullMatcher = [
|
|
2010
|
+
/^$/,
|
|
2011
|
+
[],
|
|
2012
|
+
/* @__PURE__ */ Object.create(null)
|
|
2013
|
+
];
|
|
2014
|
+
var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
2015
|
+
function buildWildcardRegExp(path) {
|
|
2016
|
+
return wildcardRegExpCache[path] ??= new RegExp("*" === path ? "" : `^${path.replace(/\/\*$|([.\\+*[^\]$()])/g, (_, metaChar)=>metaChar ? `\\${metaChar}` : "(?:|/.*)")}$`);
|
|
2017
|
+
}
|
|
2018
|
+
function clearWildcardRegExpCache() {
|
|
2019
|
+
wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
2020
|
+
}
|
|
2021
|
+
function buildMatcherFromPreprocessedRoutes(routes) {
|
|
2022
|
+
const trie = new Trie();
|
|
2023
|
+
const handlerData = [];
|
|
2024
|
+
if (0 === routes.length) return nullMatcher;
|
|
2025
|
+
const routesWithStaticPathFlag = routes.map((route)=>[
|
|
2026
|
+
!/\*|\/:/.test(route[0]),
|
|
2027
|
+
...route
|
|
2028
|
+
]).sort(([isStaticA, pathA], [isStaticB, pathB])=>isStaticA ? 1 : isStaticB ? -1 : pathA.length - pathB.length);
|
|
2029
|
+
const staticMap = /* @__PURE__ */ Object.create(null);
|
|
2030
|
+
for(let i = 0, j = -1, len = routesWithStaticPathFlag.length; i < len; i++){
|
|
2031
|
+
const [pathErrorCheckOnly, path, handlers] = routesWithStaticPathFlag[i];
|
|
2032
|
+
if (pathErrorCheckOnly) staticMap[path] = [
|
|
2033
|
+
handlers.map(([h])=>[
|
|
2034
|
+
h,
|
|
2035
|
+
/* @__PURE__ */ Object.create(null)
|
|
2036
|
+
]),
|
|
2037
|
+
emptyParam
|
|
2038
|
+
];
|
|
2039
|
+
else j++;
|
|
2040
|
+
let paramAssoc;
|
|
1393
2041
|
try {
|
|
1394
|
-
|
|
1395
|
-
router.add(...args);
|
|
1396
|
-
});
|
|
1397
|
-
res = router.match(method, path);
|
|
2042
|
+
paramAssoc = trie.insert(path, j, pathErrorCheckOnly);
|
|
1398
2043
|
} catch (e) {
|
|
1399
|
-
|
|
1400
|
-
throw e;
|
|
2044
|
+
throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
|
|
1401
2045
|
}
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
2046
|
+
if (!pathErrorCheckOnly) handlerData[j] = handlers.map(([h, paramCount])=>{
|
|
2047
|
+
const paramIndexMap = /* @__PURE__ */ Object.create(null);
|
|
2048
|
+
paramCount -= 1;
|
|
2049
|
+
for(; paramCount >= 0; paramCount--){
|
|
2050
|
+
const [key, value] = paramAssoc[paramCount];
|
|
2051
|
+
paramIndexMap[key] = value;
|
|
2052
|
+
}
|
|
2053
|
+
return [
|
|
2054
|
+
h,
|
|
2055
|
+
paramIndexMap
|
|
2056
|
+
];
|
|
2057
|
+
});
|
|
2058
|
+
}
|
|
2059
|
+
const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
|
|
2060
|
+
for(let i = 0, len = handlerData.length; i < len; i++)for(let j = 0, len2 = handlerData[i].length; j < len2; j++){
|
|
2061
|
+
const map = handlerData[i][j]?.[1];
|
|
2062
|
+
if (!map) continue;
|
|
2063
|
+
const keys = Object.keys(map);
|
|
2064
|
+
for(let k = 0, len3 = keys.length; k < len3; k++)map[keys[k]] = paramReplacementMap[map[keys[k]]];
|
|
1408
2065
|
}
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
return
|
|
2066
|
+
const handlerMap = [];
|
|
2067
|
+
for(const i in indexReplacementMap)handlerMap[i] = handlerData[indexReplacementMap[i]];
|
|
2068
|
+
return [
|
|
2069
|
+
regexp,
|
|
2070
|
+
handlerMap,
|
|
2071
|
+
staticMap
|
|
2072
|
+
];
|
|
1412
2073
|
}
|
|
1413
|
-
|
|
1414
|
-
if (
|
|
1415
|
-
return
|
|
2074
|
+
function findMiddleware(middleware, path) {
|
|
2075
|
+
if (!middleware) return;
|
|
2076
|
+
for (const k of Object.keys(middleware).sort((a, b)=>b.length - a.length))if (buildWildcardRegExp(k).test(path)) return [
|
|
2077
|
+
...middleware[k]
|
|
2078
|
+
];
|
|
1416
2079
|
}
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
this.methods = [];
|
|
1428
|
-
this.name = "";
|
|
1429
|
-
if (method && handler) {
|
|
1430
|
-
const m = /* @__PURE__ */ Object.create(null);
|
|
1431
|
-
m[method] = {
|
|
1432
|
-
handler,
|
|
1433
|
-
possibleKeys: [],
|
|
1434
|
-
score: 0,
|
|
1435
|
-
name: this.name
|
|
2080
|
+
var RegExpRouter = class {
|
|
2081
|
+
name = "RegExpRouter";
|
|
2082
|
+
middleware;
|
|
2083
|
+
routes;
|
|
2084
|
+
constructor(){
|
|
2085
|
+
this.middleware = {
|
|
2086
|
+
[METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null)
|
|
2087
|
+
};
|
|
2088
|
+
this.routes = {
|
|
2089
|
+
[METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null)
|
|
1436
2090
|
};
|
|
1437
|
-
this.methods = [
|
|
1438
|
-
m
|
|
1439
|
-
];
|
|
1440
2091
|
}
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
const pattern2 = getPattern(p);
|
|
1454
|
-
if (pattern2) possibleKeys.push(pattern2[1]);
|
|
1455
|
-
continue;
|
|
1456
|
-
}
|
|
1457
|
-
curNode.children[p] = new node_Node();
|
|
1458
|
-
const pattern = getPattern(p);
|
|
1459
|
-
if (pattern) {
|
|
1460
|
-
curNode.patterns.push(pattern);
|
|
1461
|
-
possibleKeys.push(pattern[1]);
|
|
1462
|
-
}
|
|
1463
|
-
curNode = curNode.children[p];
|
|
1464
|
-
}
|
|
1465
|
-
if (!curNode.methods.length) curNode.methods = [];
|
|
1466
|
-
const m = /* @__PURE__ */ Object.create(null);
|
|
1467
|
-
const handlerSet = {
|
|
1468
|
-
handler,
|
|
1469
|
-
possibleKeys: possibleKeys.filter((v, i, a)=>a.indexOf(v) === i),
|
|
1470
|
-
name: this.name,
|
|
1471
|
-
score: this.order
|
|
1472
|
-
};
|
|
1473
|
-
m[method] = handlerSet;
|
|
1474
|
-
curNode.methods.push(m);
|
|
1475
|
-
return curNode;
|
|
1476
|
-
}
|
|
1477
|
-
gHSets(node, method, nodeParams, params) {
|
|
1478
|
-
const handlerSets = [];
|
|
1479
|
-
for(let i = 0, len = node.methods.length; i < len; i++){
|
|
1480
|
-
const m = node.methods[i];
|
|
1481
|
-
const handlerSet = m[method] || m[METHOD_NAME_ALL];
|
|
1482
|
-
const processedSet = /* @__PURE__ */ Object.create(null);
|
|
1483
|
-
if (void 0 !== handlerSet) {
|
|
1484
|
-
handlerSet.params = /* @__PURE__ */ Object.create(null);
|
|
1485
|
-
handlerSet.possibleKeys.forEach((key)=>{
|
|
1486
|
-
const processed = processedSet[handlerSet.name];
|
|
1487
|
-
handlerSet.params[key] = params[key] && !processed ? params[key] : nodeParams[key] ?? params[key];
|
|
1488
|
-
processedSet[handlerSet.name] = true;
|
|
2092
|
+
add(method, path, handler) {
|
|
2093
|
+
const { middleware, routes } = this;
|
|
2094
|
+
if (!middleware || !routes) throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
2095
|
+
if (!middleware[method]) [
|
|
2096
|
+
middleware,
|
|
2097
|
+
routes
|
|
2098
|
+
].forEach((handlerMap)=>{
|
|
2099
|
+
handlerMap[method] = /* @__PURE__ */ Object.create(null);
|
|
2100
|
+
Object.keys(handlerMap[METHOD_NAME_ALL]).forEach((p)=>{
|
|
2101
|
+
handlerMap[method][p] = [
|
|
2102
|
+
...handlerMap[METHOD_NAME_ALL][p]
|
|
2103
|
+
];
|
|
1489
2104
|
});
|
|
1490
|
-
|
|
2105
|
+
});
|
|
2106
|
+
if ("/*" === path) path = "*";
|
|
2107
|
+
const paramCount = (path.match(/\/:/g) || []).length;
|
|
2108
|
+
if (/\*$/.test(path)) {
|
|
2109
|
+
const re = buildWildcardRegExp(path);
|
|
2110
|
+
if (method === METHOD_NAME_ALL) Object.keys(middleware).forEach((m)=>{
|
|
2111
|
+
middleware[m][path] ||= findMiddleware(middleware[m], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
|
|
2112
|
+
});
|
|
2113
|
+
else middleware[method][path] ||= findMiddleware(middleware[method], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
|
|
2114
|
+
Object.keys(middleware).forEach((m)=>{
|
|
2115
|
+
if (method === METHOD_NAME_ALL || method === m) Object.keys(middleware[m]).forEach((p)=>{
|
|
2116
|
+
re.test(p) && middleware[m][p].push([
|
|
2117
|
+
handler,
|
|
2118
|
+
paramCount
|
|
2119
|
+
]);
|
|
2120
|
+
});
|
|
2121
|
+
});
|
|
2122
|
+
Object.keys(routes).forEach((m)=>{
|
|
2123
|
+
if (method === METHOD_NAME_ALL || method === m) Object.keys(routes[m]).forEach((p)=>re.test(p) && routes[m][p].push([
|
|
2124
|
+
handler,
|
|
2125
|
+
paramCount
|
|
2126
|
+
]));
|
|
2127
|
+
});
|
|
2128
|
+
return;
|
|
1491
2129
|
}
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
const tempNodes = [];
|
|
1507
|
-
for(let j = 0, len2 = curNodes.length; j < len2; j++){
|
|
1508
|
-
const node = curNodes[j];
|
|
1509
|
-
const nextNode = node.children[part];
|
|
1510
|
-
if (nextNode) {
|
|
1511
|
-
nextNode.params = node.params;
|
|
1512
|
-
if (true === isLast) {
|
|
1513
|
-
if (nextNode.children["*"]) handlerSets.push(...this.gHSets(nextNode.children["*"], method, node.params, /* @__PURE__ */ Object.create(null)));
|
|
1514
|
-
handlerSets.push(...this.gHSets(nextNode, method, node.params, /* @__PURE__ */ Object.create(null)));
|
|
1515
|
-
} else tempNodes.push(nextNode);
|
|
1516
|
-
}
|
|
1517
|
-
for(let k = 0, len3 = node.patterns.length; k < len3; k++){
|
|
1518
|
-
const pattern = node.patterns[k];
|
|
1519
|
-
const params = {
|
|
1520
|
-
...node.params
|
|
1521
|
-
};
|
|
1522
|
-
if ("*" === pattern) {
|
|
1523
|
-
const astNode = node.children["*"];
|
|
1524
|
-
if (astNode) {
|
|
1525
|
-
handlerSets.push(...this.gHSets(astNode, method, node.params, /* @__PURE__ */ Object.create(null)));
|
|
1526
|
-
tempNodes.push(astNode);
|
|
1527
|
-
}
|
|
1528
|
-
continue;
|
|
1529
|
-
}
|
|
1530
|
-
if ("" === part) continue;
|
|
1531
|
-
const [key, name, matcher] = pattern;
|
|
1532
|
-
const child = node.children[key];
|
|
1533
|
-
const restPathString = parts.slice(i).join("/");
|
|
1534
|
-
if (matcher instanceof RegExp && matcher.test(restPathString)) {
|
|
1535
|
-
params[name] = restPathString;
|
|
1536
|
-
handlerSets.push(...this.gHSets(child, method, node.params, params));
|
|
1537
|
-
continue;
|
|
1538
|
-
}
|
|
1539
|
-
if (true === matcher || matcher instanceof RegExp && matcher.test(part)) {
|
|
1540
|
-
if ("string" == typeof key) {
|
|
1541
|
-
params[name] = part;
|
|
1542
|
-
if (true === isLast) {
|
|
1543
|
-
handlerSets.push(...this.gHSets(child, method, params, node.params));
|
|
1544
|
-
if (child.children["*"]) handlerSets.push(...this.gHSets(child.children["*"], method, params, node.params));
|
|
1545
|
-
} else {
|
|
1546
|
-
child.params = params;
|
|
1547
|
-
tempNodes.push(child);
|
|
1548
|
-
}
|
|
1549
|
-
}
|
|
2130
|
+
const paths = checkOptionalParameter(path) || [
|
|
2131
|
+
path
|
|
2132
|
+
];
|
|
2133
|
+
for(let i = 0, len = paths.length; i < len; i++){
|
|
2134
|
+
const path2 = paths[i];
|
|
2135
|
+
Object.keys(routes).forEach((m)=>{
|
|
2136
|
+
if (method === METHOD_NAME_ALL || method === m) {
|
|
2137
|
+
routes[m][path2] ||= [
|
|
2138
|
+
...findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || []
|
|
2139
|
+
];
|
|
2140
|
+
routes[m][path2].push([
|
|
2141
|
+
handler,
|
|
2142
|
+
paramCount - len + i + 1
|
|
2143
|
+
]);
|
|
1550
2144
|
}
|
|
1551
|
-
}
|
|
2145
|
+
});
|
|
1552
2146
|
}
|
|
1553
|
-
curNodes = tempNodes;
|
|
1554
2147
|
}
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
]
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
return;
|
|
2148
|
+
match(method, path) {
|
|
2149
|
+
clearWildcardRegExpCache();
|
|
2150
|
+
const matchers = this.buildAllMatchers();
|
|
2151
|
+
this.match = (method2, path2)=>{
|
|
2152
|
+
const matcher = matchers[method2] || matchers[METHOD_NAME_ALL];
|
|
2153
|
+
const staticMatch = matcher[2][path2];
|
|
2154
|
+
if (staticMatch) return staticMatch;
|
|
2155
|
+
const match = path2.match(matcher[0]);
|
|
2156
|
+
if (!match) return [
|
|
2157
|
+
[],
|
|
2158
|
+
emptyParam
|
|
2159
|
+
];
|
|
2160
|
+
const index = match.indexOf("", 1);
|
|
2161
|
+
return [
|
|
2162
|
+
matcher[1][index],
|
|
2163
|
+
match
|
|
2164
|
+
];
|
|
2165
|
+
};
|
|
2166
|
+
return this.match(method, path);
|
|
1575
2167
|
}
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
constructor(options = {}){
|
|
1584
|
-
super(options);
|
|
1585
|
-
this.router = options.router ?? new SmartRouter({
|
|
1586
|
-
routers: [
|
|
1587
|
-
new RegExpRouter(),
|
|
1588
|
-
new TrieRouter()
|
|
1589
|
-
]
|
|
1590
|
-
});
|
|
1591
|
-
}
|
|
1592
|
-
};
|
|
1593
|
-
var validCookieNameRegEx = /^[\w!#$%&'*.^`|~+-]+$/;
|
|
1594
|
-
var validCookieValueRegEx = /^[ !#-:<-[\]-~]*$/;
|
|
1595
|
-
var parse = (cookie, name)=>{
|
|
1596
|
-
const pairs = cookie.trim().split(";");
|
|
1597
|
-
return pairs.reduce((parsedCookie, pairStr)=>{
|
|
1598
|
-
pairStr = pairStr.trim();
|
|
1599
|
-
const valueStartPos = pairStr.indexOf("=");
|
|
1600
|
-
if (-1 === valueStartPos) return parsedCookie;
|
|
1601
|
-
const cookieName = pairStr.substring(0, valueStartPos).trim();
|
|
1602
|
-
if (name && name !== cookieName || !validCookieNameRegEx.test(cookieName)) return parsedCookie;
|
|
1603
|
-
let cookieValue = pairStr.substring(valueStartPos + 1).trim();
|
|
1604
|
-
if (cookieValue.startsWith('"') && cookieValue.endsWith('"')) cookieValue = cookieValue.slice(1, -1);
|
|
1605
|
-
if (validCookieValueRegEx.test(cookieValue)) parsedCookie[cookieName] = decodeURIComponent_(cookieValue);
|
|
1606
|
-
return parsedCookie;
|
|
1607
|
-
}, {});
|
|
1608
|
-
};
|
|
1609
|
-
var getCookie = (c, key, prefix)=>{
|
|
1610
|
-
const cookie = c.req.raw.headers.get("Cookie");
|
|
1611
|
-
if ("string" == typeof key) {
|
|
1612
|
-
if (!cookie) return;
|
|
1613
|
-
let finalKey = key;
|
|
1614
|
-
if ("secure" === prefix) finalKey = "__Secure-" + key;
|
|
1615
|
-
else if ("host" === prefix) finalKey = "__Host-" + key;
|
|
1616
|
-
const obj2 = parse(cookie, finalKey);
|
|
1617
|
-
return obj2[finalKey];
|
|
1618
|
-
}
|
|
1619
|
-
if (!cookie) return {};
|
|
1620
|
-
const obj = parse(cookie);
|
|
1621
|
-
return obj;
|
|
1622
|
-
};
|
|
1623
|
-
var HTTPException = class extends Error {
|
|
1624
|
-
res;
|
|
1625
|
-
status;
|
|
1626
|
-
constructor(status = 500, options){
|
|
1627
|
-
super(options?.message, {
|
|
1628
|
-
cause: options?.cause
|
|
1629
|
-
});
|
|
1630
|
-
this.res = options?.res;
|
|
1631
|
-
this.status = status;
|
|
1632
|
-
}
|
|
1633
|
-
getResponse() {
|
|
1634
|
-
if (this.res) {
|
|
1635
|
-
const newResponse = new Response(this.res.body, {
|
|
1636
|
-
status: this.status,
|
|
1637
|
-
headers: this.res.headers
|
|
2168
|
+
buildAllMatchers() {
|
|
2169
|
+
const matchers = /* @__PURE__ */ Object.create(null);
|
|
2170
|
+
[
|
|
2171
|
+
...Object.keys(this.routes),
|
|
2172
|
+
...Object.keys(this.middleware)
|
|
2173
|
+
].forEach((method)=>{
|
|
2174
|
+
matchers[method] ||= this.buildMatcher(method);
|
|
1638
2175
|
});
|
|
1639
|
-
|
|
2176
|
+
this.middleware = this.routes = void 0;
|
|
2177
|
+
return matchers;
|
|
1640
2178
|
}
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
2179
|
+
buildMatcher(method) {
|
|
2180
|
+
const routes = [];
|
|
2181
|
+
let hasOwnRoute = method === METHOD_NAME_ALL;
|
|
2182
|
+
[
|
|
2183
|
+
this.middleware,
|
|
2184
|
+
this.routes
|
|
2185
|
+
].forEach((r)=>{
|
|
2186
|
+
const ownRoute = r[method] ? Object.keys(r[method]).map((path)=>[
|
|
2187
|
+
path,
|
|
2188
|
+
r[method][path]
|
|
2189
|
+
]) : [];
|
|
2190
|
+
if (0 !== ownRoute.length) {
|
|
2191
|
+
hasOwnRoute ||= true;
|
|
2192
|
+
routes.push(...ownRoute);
|
|
2193
|
+
} else if (method !== METHOD_NAME_ALL) routes.push(...Object.keys(r[METHOD_NAME_ALL]).map((path)=>[
|
|
2194
|
+
path,
|
|
2195
|
+
r[METHOD_NAME_ALL][path]
|
|
2196
|
+
]));
|
|
2197
|
+
});
|
|
2198
|
+
if (!hasOwnRoute) return null;
|
|
2199
|
+
return buildMatcherFromPreprocessedRoutes(routes);
|
|
1650
2200
|
}
|
|
1651
|
-
}
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
2201
|
+
};
|
|
2202
|
+
var SmartRouter = class {
|
|
2203
|
+
name = "SmartRouter";
|
|
2204
|
+
routers = [];
|
|
2205
|
+
routes = [];
|
|
2206
|
+
constructor(init){
|
|
2207
|
+
Object.assign(this, init);
|
|
2208
|
+
}
|
|
2209
|
+
add(method, path, handler) {
|
|
2210
|
+
if (!this.routes) throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
2211
|
+
this.routes.push([
|
|
2212
|
+
method,
|
|
2213
|
+
path,
|
|
2214
|
+
handler
|
|
2215
|
+
]);
|
|
2216
|
+
}
|
|
2217
|
+
match(method, path) {
|
|
2218
|
+
if (!this.routes) throw new Error("Fatal error");
|
|
2219
|
+
const { routers, routes } = this;
|
|
2220
|
+
const len = routers.length;
|
|
2221
|
+
let i = 0;
|
|
2222
|
+
let res;
|
|
2223
|
+
for(; i < len; i++){
|
|
2224
|
+
const router = routers[i];
|
|
1663
2225
|
try {
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
const message = "Malformed JSON in request body";
|
|
1667
|
-
throw new HTTPException(400, {
|
|
1668
|
-
message
|
|
1669
|
-
});
|
|
1670
|
-
}
|
|
1671
|
-
break;
|
|
1672
|
-
case "form":
|
|
1673
|
-
{
|
|
1674
|
-
if (!contentType || !(multipartRegex.test(contentType) || urlencodedRegex.test(contentType))) break;
|
|
1675
|
-
let formData;
|
|
1676
|
-
if (c.req.bodyCache.formData) formData = await c.req.bodyCache.formData;
|
|
1677
|
-
else try {
|
|
1678
|
-
const arrayBuffer = await c.req.arrayBuffer();
|
|
1679
|
-
formData = await bufferToFormData(arrayBuffer, contentType);
|
|
1680
|
-
c.req.bodyCache.formData = formData;
|
|
1681
|
-
} catch (e) {
|
|
1682
|
-
let message = "Malformed FormData request.";
|
|
1683
|
-
message += e instanceof Error ? ` ${e.message}` : ` ${String(e)}`;
|
|
1684
|
-
throw new HTTPException(400, {
|
|
1685
|
-
message
|
|
1686
|
-
});
|
|
1687
|
-
}
|
|
1688
|
-
const form = {};
|
|
1689
|
-
formData.forEach((value2, key)=>{
|
|
1690
|
-
if (key.endsWith("[]")) (form[key] ??= []).push(value2);
|
|
1691
|
-
else if (Array.isArray(form[key])) form[key].push(value2);
|
|
1692
|
-
else if (key in form) form[key] = [
|
|
1693
|
-
form[key],
|
|
1694
|
-
value2
|
|
1695
|
-
];
|
|
1696
|
-
else form[key] = value2;
|
|
2226
|
+
routes.forEach((args)=>{
|
|
2227
|
+
router.add(...args);
|
|
1697
2228
|
});
|
|
1698
|
-
|
|
1699
|
-
|
|
2229
|
+
res = router.match(method, path);
|
|
2230
|
+
} catch (e) {
|
|
2231
|
+
if (e instanceof UnsupportedPathError) continue;
|
|
2232
|
+
throw e;
|
|
1700
2233
|
}
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
k,
|
|
1707
|
-
v
|
|
1708
|
-
]));
|
|
1709
|
-
break;
|
|
1710
|
-
case "param":
|
|
1711
|
-
value = c.req.param();
|
|
1712
|
-
break;
|
|
1713
|
-
case "header":
|
|
1714
|
-
value = c.req.header();
|
|
1715
|
-
break;
|
|
1716
|
-
case "cookie":
|
|
1717
|
-
value = getCookie(c);
|
|
2234
|
+
this.match = router.match.bind(router);
|
|
2235
|
+
this.routers = [
|
|
2236
|
+
router
|
|
2237
|
+
];
|
|
2238
|
+
this.routes = void 0;
|
|
1718
2239
|
break;
|
|
2240
|
+
}
|
|
2241
|
+
if (i === len) throw new Error("Fatal error");
|
|
2242
|
+
this.name = `SmartRouter + ${this.activeRouter.name}`;
|
|
2243
|
+
return res;
|
|
1719
2244
|
}
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
await next();
|
|
1724
|
-
};
|
|
1725
|
-
var store;
|
|
1726
|
-
function getGlobalConfig(config2) {
|
|
1727
|
-
return {
|
|
1728
|
-
lang: config2?.lang ?? store?.lang,
|
|
1729
|
-
message: config2?.message,
|
|
1730
|
-
abortEarly: config2?.abortEarly ?? store?.abortEarly,
|
|
1731
|
-
abortPipeEarly: config2?.abortPipeEarly ?? store?.abortPipeEarly
|
|
1732
|
-
};
|
|
1733
|
-
}
|
|
1734
|
-
var store2;
|
|
1735
|
-
function getGlobalMessage(lang) {
|
|
1736
|
-
return store2?.get(lang);
|
|
1737
|
-
}
|
|
1738
|
-
var store3;
|
|
1739
|
-
function getSchemaMessage(lang) {
|
|
1740
|
-
return store3?.get(lang);
|
|
1741
|
-
}
|
|
1742
|
-
var store4;
|
|
1743
|
-
function getSpecificMessage(reference, lang) {
|
|
1744
|
-
return store4?.get(reference)?.get(lang);
|
|
1745
|
-
}
|
|
1746
|
-
function _stringify(input) {
|
|
1747
|
-
const type = typeof input;
|
|
1748
|
-
if ("string" === type) return `"${input}"`;
|
|
1749
|
-
if ("number" === type || "bigint" === type || "boolean" === type) return `${input}`;
|
|
1750
|
-
if ("object" === type || "function" === type) return (input && Object.getPrototypeOf(input)?.constructor?.name) ?? "null";
|
|
1751
|
-
return type;
|
|
1752
|
-
}
|
|
1753
|
-
function _addIssue(context, label, dataset, config2, other) {
|
|
1754
|
-
const input = other && "input" in other ? other.input : dataset.value;
|
|
1755
|
-
const expected = other?.expected ?? context.expects ?? null;
|
|
1756
|
-
const received = other?.received ?? _stringify(input);
|
|
1757
|
-
const issue = {
|
|
1758
|
-
kind: context.kind,
|
|
1759
|
-
type: context.type,
|
|
1760
|
-
input,
|
|
1761
|
-
expected,
|
|
1762
|
-
received,
|
|
1763
|
-
message: `Invalid ${label}: ${expected ? `Expected ${expected} but r` : "R"}eceived ${received}`,
|
|
1764
|
-
requirement: context.requirement,
|
|
1765
|
-
path: other?.path,
|
|
1766
|
-
issues: other?.issues,
|
|
1767
|
-
lang: config2.lang,
|
|
1768
|
-
abortEarly: config2.abortEarly,
|
|
1769
|
-
abortPipeEarly: config2.abortPipeEarly
|
|
1770
|
-
};
|
|
1771
|
-
const isSchema = "schema" === context.kind;
|
|
1772
|
-
const message = other?.message ?? context.message ?? getSpecificMessage(context.reference, issue.lang) ?? (isSchema ? getSchemaMessage(issue.lang) : null) ?? config2.message ?? getGlobalMessage(issue.lang);
|
|
1773
|
-
if (message) issue.message = "function" == typeof message ? message(issue) : message;
|
|
1774
|
-
if (isSchema) dataset.typed = false;
|
|
1775
|
-
if (dataset.issues) dataset.issues.push(issue);
|
|
1776
|
-
else dataset.issues = [
|
|
1777
|
-
issue
|
|
1778
|
-
];
|
|
1779
|
-
}
|
|
1780
|
-
function _joinExpects(values, separator) {
|
|
1781
|
-
const list = [
|
|
1782
|
-
...new Set(values)
|
|
1783
|
-
];
|
|
1784
|
-
if (list.length > 1) return `(${list.join(` ${separator} `)})`;
|
|
1785
|
-
return list[0] ?? "never";
|
|
1786
|
-
}
|
|
1787
|
-
function getDefault(schema, dataset, config2) {
|
|
1788
|
-
return "function" == typeof schema.default ? schema.default(dataset, config2) : schema.default;
|
|
1789
|
-
}
|
|
1790
|
-
function dist_boolean(message) {
|
|
1791
|
-
return {
|
|
1792
|
-
kind: "schema",
|
|
1793
|
-
type: "boolean",
|
|
1794
|
-
reference: dist_boolean,
|
|
1795
|
-
expects: "boolean",
|
|
1796
|
-
async: false,
|
|
1797
|
-
message,
|
|
1798
|
-
_run (dataset, config2) {
|
|
1799
|
-
if ("boolean" == typeof dataset.value) dataset.typed = true;
|
|
1800
|
-
else _addIssue(this, "type", dataset, config2);
|
|
1801
|
-
return dataset;
|
|
2245
|
+
get activeRouter() {
|
|
2246
|
+
if (this.routes || 1 !== this.routers.length) throw new Error("No active router has been determined yet.");
|
|
2247
|
+
return this.routers[0];
|
|
1802
2248
|
}
|
|
1803
2249
|
};
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
if (
|
|
1816
|
-
|
|
1817
|
-
|
|
2250
|
+
var node_Node = class {
|
|
2251
|
+
methods;
|
|
2252
|
+
children;
|
|
2253
|
+
patterns;
|
|
2254
|
+
order = 0;
|
|
2255
|
+
name;
|
|
2256
|
+
params = /* @__PURE__ */ Object.create(null);
|
|
2257
|
+
constructor(method, handler, children){
|
|
2258
|
+
this.children = children || /* @__PURE__ */ Object.create(null);
|
|
2259
|
+
this.methods = [];
|
|
2260
|
+
this.name = "";
|
|
2261
|
+
if (method && handler) {
|
|
2262
|
+
const m = /* @__PURE__ */ Object.create(null);
|
|
2263
|
+
m[method] = {
|
|
2264
|
+
handler,
|
|
2265
|
+
possibleKeys: [],
|
|
2266
|
+
score: 0,
|
|
2267
|
+
name: this.name
|
|
2268
|
+
};
|
|
2269
|
+
this.methods = [
|
|
2270
|
+
m
|
|
2271
|
+
];
|
|
2272
|
+
}
|
|
2273
|
+
this.patterns = [];
|
|
1818
2274
|
}
|
|
1819
|
-
|
|
1820
|
-
}
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
if (null === dataset.value) {
|
|
1833
|
-
dataset.typed = true;
|
|
1834
|
-
return dataset;
|
|
2275
|
+
insert(method, path, handler) {
|
|
2276
|
+
this.name = `${method} ${path}`;
|
|
2277
|
+
this.order = ++this.order;
|
|
2278
|
+
let curNode = this;
|
|
2279
|
+
const parts = splitRoutingPath(path);
|
|
2280
|
+
const possibleKeys = [];
|
|
2281
|
+
for(let i = 0, len = parts.length; i < len; i++){
|
|
2282
|
+
const p = parts[i];
|
|
2283
|
+
if (Object.keys(curNode.children).includes(p)) {
|
|
2284
|
+
curNode = curNode.children[p];
|
|
2285
|
+
const pattern2 = getPattern(p);
|
|
2286
|
+
if (pattern2) possibleKeys.push(pattern2[1]);
|
|
2287
|
+
continue;
|
|
1835
2288
|
}
|
|
2289
|
+
curNode.children[p] = new node_Node();
|
|
2290
|
+
const pattern = getPattern(p);
|
|
2291
|
+
if (pattern) {
|
|
2292
|
+
curNode.patterns.push(pattern);
|
|
2293
|
+
possibleKeys.push(pattern[1]);
|
|
2294
|
+
}
|
|
2295
|
+
curNode = curNode.children[p];
|
|
1836
2296
|
}
|
|
1837
|
-
|
|
2297
|
+
if (!curNode.methods.length) curNode.methods = [];
|
|
2298
|
+
const m = /* @__PURE__ */ Object.create(null);
|
|
2299
|
+
const handlerSet = {
|
|
2300
|
+
handler,
|
|
2301
|
+
possibleKeys: possibleKeys.filter((v, i, a)=>a.indexOf(v) === i),
|
|
2302
|
+
name: this.name,
|
|
2303
|
+
score: this.order
|
|
2304
|
+
};
|
|
2305
|
+
m[method] = handlerSet;
|
|
2306
|
+
curNode.methods.push(m);
|
|
2307
|
+
return curNode;
|
|
1838
2308
|
}
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
2309
|
+
gHSets(node, method, nodeParams, params) {
|
|
2310
|
+
const handlerSets = [];
|
|
2311
|
+
for(let i = 0, len = node.methods.length; i < len; i++){
|
|
2312
|
+
const m = node.methods[i];
|
|
2313
|
+
const handlerSet = m[method] || m[METHOD_NAME_ALL];
|
|
2314
|
+
const processedSet = /* @__PURE__ */ Object.create(null);
|
|
2315
|
+
if (void 0 !== handlerSet) {
|
|
2316
|
+
handlerSet.params = /* @__PURE__ */ Object.create(null);
|
|
2317
|
+
handlerSet.possibleKeys.forEach((key)=>{
|
|
2318
|
+
const processed = processedSet[handlerSet.name];
|
|
2319
|
+
handlerSet.params[key] = params[key] && !processed ? params[key] : nodeParams[key] ?? params[key];
|
|
2320
|
+
processedSet[handlerSet.name] = true;
|
|
2321
|
+
});
|
|
2322
|
+
handlerSets.push(handlerSet);
|
|
2323
|
+
}
|
|
2324
|
+
}
|
|
2325
|
+
return handlerSets;
|
|
2326
|
+
}
|
|
2327
|
+
search(method, path) {
|
|
2328
|
+
const handlerSets = [];
|
|
2329
|
+
this.params = /* @__PURE__ */ Object.create(null);
|
|
2330
|
+
const curNode = this;
|
|
2331
|
+
let curNodes = [
|
|
2332
|
+
curNode
|
|
2333
|
+
];
|
|
2334
|
+
const parts = splitPath(path);
|
|
2335
|
+
for(let i = 0, len = parts.length; i < len; i++){
|
|
2336
|
+
const part = parts[i];
|
|
2337
|
+
const isLast = i === len - 1;
|
|
2338
|
+
const tempNodes = [];
|
|
2339
|
+
for(let j = 0, len2 = curNodes.length; j < len2; j++){
|
|
2340
|
+
const node = curNodes[j];
|
|
2341
|
+
const nextNode = node.children[part];
|
|
2342
|
+
if (nextNode) {
|
|
2343
|
+
nextNode.params = node.params;
|
|
2344
|
+
if (true === isLast) {
|
|
2345
|
+
if (nextNode.children["*"]) handlerSets.push(...this.gHSets(nextNode.children["*"], method, node.params, /* @__PURE__ */ Object.create(null)));
|
|
2346
|
+
handlerSets.push(...this.gHSets(nextNode, method, node.params, /* @__PURE__ */ Object.create(null)));
|
|
2347
|
+
} else tempNodes.push(nextNode);
|
|
2348
|
+
}
|
|
2349
|
+
for(let k = 0, len3 = node.patterns.length; k < len3; k++){
|
|
2350
|
+
const pattern = node.patterns[k];
|
|
2351
|
+
const params = {
|
|
2352
|
+
...node.params
|
|
1870
2353
|
};
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
2354
|
+
if ("*" === pattern) {
|
|
2355
|
+
const astNode = node.children["*"];
|
|
2356
|
+
if (astNode) {
|
|
2357
|
+
handlerSets.push(...this.gHSets(astNode, method, node.params, /* @__PURE__ */ Object.create(null)));
|
|
2358
|
+
tempNodes.push(astNode);
|
|
2359
|
+
}
|
|
2360
|
+
continue;
|
|
1877
2361
|
}
|
|
1878
|
-
if (
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
2362
|
+
if ("" === part) continue;
|
|
2363
|
+
const [key, name, matcher] = pattern;
|
|
2364
|
+
const child = node.children[key];
|
|
2365
|
+
const restPathString = parts.slice(i).join("/");
|
|
2366
|
+
if (matcher instanceof RegExp && matcher.test(restPathString)) {
|
|
2367
|
+
params[name] = restPathString;
|
|
2368
|
+
handlerSets.push(...this.gHSets(child, method, node.params, params));
|
|
2369
|
+
continue;
|
|
2370
|
+
}
|
|
2371
|
+
if (true === matcher || matcher instanceof RegExp && matcher.test(part)) {
|
|
2372
|
+
if ("string" == typeof key) {
|
|
2373
|
+
params[name] = part;
|
|
2374
|
+
if (true === isLast) {
|
|
2375
|
+
handlerSets.push(...this.gHSets(child, method, params, node.params));
|
|
2376
|
+
if (child.children["*"]) handlerSets.push(...this.gHSets(child.children["*"], method, params, node.params));
|
|
2377
|
+
} else {
|
|
2378
|
+
child.params = params;
|
|
2379
|
+
tempNodes.push(child);
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
1882
2382
|
}
|
|
1883
2383
|
}
|
|
1884
|
-
if (!valueDataset.typed) dataset.typed = false;
|
|
1885
|
-
if (void 0 !== valueDataset.value || key in input) dataset.value[key] = valueDataset.value;
|
|
1886
2384
|
}
|
|
1887
|
-
|
|
1888
|
-
|
|
2385
|
+
curNodes = tempNodes;
|
|
2386
|
+
}
|
|
2387
|
+
const results = handlerSets.sort((a, b)=>a.score - b.score);
|
|
2388
|
+
return [
|
|
2389
|
+
results.map(({ handler, params })=>[
|
|
2390
|
+
handler,
|
|
2391
|
+
params
|
|
2392
|
+
])
|
|
2393
|
+
];
|
|
1889
2394
|
}
|
|
1890
2395
|
};
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
if ("default" in this) dataset.value = getDefault(this, dataset, config2);
|
|
1903
|
-
if (void 0 === dataset.value) {
|
|
1904
|
-
dataset.typed = true;
|
|
1905
|
-
return dataset;
|
|
1906
|
-
}
|
|
2396
|
+
var TrieRouter = class {
|
|
2397
|
+
name = "TrieRouter";
|
|
2398
|
+
node;
|
|
2399
|
+
constructor(){
|
|
2400
|
+
this.node = new node_Node();
|
|
2401
|
+
}
|
|
2402
|
+
add(method, path, handler) {
|
|
2403
|
+
const results = checkOptionalParameter(path);
|
|
2404
|
+
if (results) {
|
|
2405
|
+
for (const p of results)this.node.insert(method, p, handler);
|
|
2406
|
+
return;
|
|
1907
2407
|
}
|
|
1908
|
-
|
|
2408
|
+
this.node.insert(method, path, handler);
|
|
2409
|
+
}
|
|
2410
|
+
match(method, path) {
|
|
2411
|
+
return this.node.search(method, path);
|
|
1909
2412
|
}
|
|
1910
2413
|
};
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
async: false,
|
|
1921
|
-
message,
|
|
1922
|
-
_run (dataset, config2) {
|
|
1923
|
-
if ("string" == typeof dataset.value) dataset.typed = true;
|
|
1924
|
-
else _addIssue(this, "type", dataset, config2);
|
|
1925
|
-
return dataset;
|
|
2414
|
+
var hono_Hono = class extends Hono {
|
|
2415
|
+
constructor(options = {}){
|
|
2416
|
+
super(options);
|
|
2417
|
+
this.router = options.router ?? new SmartRouter({
|
|
2418
|
+
routers: [
|
|
2419
|
+
new RegExpRouter(),
|
|
2420
|
+
new TrieRouter()
|
|
2421
|
+
]
|
|
2422
|
+
});
|
|
1926
2423
|
}
|
|
1927
2424
|
};
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
optionDataset
|
|
1966
|
-
];
|
|
2425
|
+
var _validateReport = __webpack_require__("../../node_modules/.pnpm/typia@8.0.3_@samchon+openapi@3.1.0_typescript@5.6.3/node_modules/typia/lib/internal/_validateReport.js");
|
|
2426
|
+
var cjs = __webpack_require__("../../node_modules/.pnpm/@hono+typia-validator@0.1.0_hono@4.6.3_typia@8.0.3_@samchon+openapi@3.1.0_typescript@5.6.3_/node_modules/@hono/typia-validator/dist/cjs/index.js");
|
|
2427
|
+
const plugin_core_namespaceObject = require("@hot-updater/plugin-core");
|
|
2428
|
+
const bundleIdValidator = (()=>{
|
|
2429
|
+
const _io0 = (input)=>"string" == typeof input.bundleId;
|
|
2430
|
+
const _vo0 = (input, _path, _exceptionable = true)=>[
|
|
2431
|
+
"string" == typeof input.bundleId || _report(_exceptionable, {
|
|
2432
|
+
path: _path + ".bundleId",
|
|
2433
|
+
expected: "string",
|
|
2434
|
+
value: input.bundleId
|
|
2435
|
+
})
|
|
2436
|
+
].every((flag)=>flag);
|
|
2437
|
+
const __is = (input)=>"object" == typeof input && null !== input && _io0(input);
|
|
2438
|
+
let errors;
|
|
2439
|
+
let _report;
|
|
2440
|
+
return (input)=>{
|
|
2441
|
+
if (false === __is(input)) {
|
|
2442
|
+
errors = [];
|
|
2443
|
+
_report = _validateReport._validateReport(errors);
|
|
2444
|
+
((input, _path, _exceptionable = true)=>("object" == typeof input && null !== input || _report(true, {
|
|
2445
|
+
path: _path + "",
|
|
2446
|
+
expected: "__type",
|
|
2447
|
+
value: input
|
|
2448
|
+
})) && _vo0(input, _path + "", true) || _report(true, {
|
|
2449
|
+
path: _path + "",
|
|
2450
|
+
expected: "__type",
|
|
2451
|
+
value: input
|
|
2452
|
+
}))(input, "$input", true);
|
|
2453
|
+
const success = 0 === errors.length;
|
|
2454
|
+
return success ? {
|
|
2455
|
+
success,
|
|
2456
|
+
data: input
|
|
2457
|
+
} : {
|
|
2458
|
+
success,
|
|
2459
|
+
errors,
|
|
2460
|
+
data: input
|
|
2461
|
+
};
|
|
1967
2462
|
}
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
2463
|
+
return {
|
|
2464
|
+
success: true,
|
|
2465
|
+
data: input
|
|
2466
|
+
};
|
|
2467
|
+
};
|
|
2468
|
+
})();
|
|
2469
|
+
const updateBundleValidator = (()=>{
|
|
2470
|
+
const _io0 = (input)=>"string" == typeof input.targetBundleId && "object" == typeof input.bundle && null !== input.bundle && false === Array.isArray(input.bundle) && _io1(input.bundle);
|
|
2471
|
+
const _io1 = (input)=>(void 0 === input.id || "string" == typeof input.id) && (void 0 === input.platform || "ios" === input.platform || "android" === input.platform) && (void 0 === input.targetAppVersion || "string" == typeof input.targetAppVersion) && (void 0 === input.shouldForceUpdate || "boolean" == typeof input.shouldForceUpdate) && (void 0 === input.enabled || "boolean" == typeof input.enabled) && (void 0 === input.fileUrl || "string" == typeof input.fileUrl) && (void 0 === input.fileHash || "string" == typeof input.fileHash) && (null === input.gitCommitHash || void 0 === input.gitCommitHash || "string" == typeof input.gitCommitHash) && (null === input.message || void 0 === input.message || "string" == typeof input.message);
|
|
2472
|
+
const _vo0 = (input, _path, _exceptionable = true)=>[
|
|
2473
|
+
"string" == typeof input.targetBundleId || _report(_exceptionable, {
|
|
2474
|
+
path: _path + ".targetBundleId",
|
|
2475
|
+
expected: "string",
|
|
2476
|
+
value: input.targetBundleId
|
|
2477
|
+
}),
|
|
2478
|
+
("object" == typeof input.bundle && null !== input.bundle && false === Array.isArray(input.bundle) || _report(_exceptionable, {
|
|
2479
|
+
path: _path + ".bundle",
|
|
2480
|
+
expected: "Partial<Bundle>",
|
|
2481
|
+
value: input.bundle
|
|
2482
|
+
})) && _vo1(input.bundle, _path + ".bundle", _exceptionable) || _report(_exceptionable, {
|
|
2483
|
+
path: _path + ".bundle",
|
|
2484
|
+
expected: "Partial<Bundle>",
|
|
2485
|
+
value: input.bundle
|
|
2486
|
+
})
|
|
2487
|
+
].every((flag)=>flag);
|
|
2488
|
+
const _vo1 = (input, _path, _exceptionable = true)=>[
|
|
2489
|
+
void 0 === input.id || "string" == typeof input.id || _report(_exceptionable, {
|
|
2490
|
+
path: _path + ".id",
|
|
2491
|
+
expected: "(string | undefined)",
|
|
2492
|
+
value: input.id
|
|
2493
|
+
}),
|
|
2494
|
+
void 0 === input.platform || "ios" === input.platform || "android" === input.platform || _report(_exceptionable, {
|
|
2495
|
+
path: _path + ".platform",
|
|
2496
|
+
expected: "(\"android\" | \"ios\" | undefined)",
|
|
2497
|
+
value: input.platform
|
|
2498
|
+
}),
|
|
2499
|
+
void 0 === input.targetAppVersion || "string" == typeof input.targetAppVersion || _report(_exceptionable, {
|
|
2500
|
+
path: _path + ".targetAppVersion",
|
|
2501
|
+
expected: "(string | undefined)",
|
|
2502
|
+
value: input.targetAppVersion
|
|
2503
|
+
}),
|
|
2504
|
+
void 0 === input.shouldForceUpdate || "boolean" == typeof input.shouldForceUpdate || _report(_exceptionable, {
|
|
2505
|
+
path: _path + ".shouldForceUpdate",
|
|
2506
|
+
expected: "(boolean | undefined)",
|
|
2507
|
+
value: input.shouldForceUpdate
|
|
2508
|
+
}),
|
|
2509
|
+
void 0 === input.enabled || "boolean" == typeof input.enabled || _report(_exceptionable, {
|
|
2510
|
+
path: _path + ".enabled",
|
|
2511
|
+
expected: "(boolean | undefined)",
|
|
2512
|
+
value: input.enabled
|
|
2513
|
+
}),
|
|
2514
|
+
void 0 === input.fileUrl || "string" == typeof input.fileUrl || _report(_exceptionable, {
|
|
2515
|
+
path: _path + ".fileUrl",
|
|
2516
|
+
expected: "(string | undefined)",
|
|
2517
|
+
value: input.fileUrl
|
|
2518
|
+
}),
|
|
2519
|
+
void 0 === input.fileHash || "string" == typeof input.fileHash || _report(_exceptionable, {
|
|
2520
|
+
path: _path + ".fileHash",
|
|
2521
|
+
expected: "(string | undefined)",
|
|
2522
|
+
value: input.fileHash
|
|
2523
|
+
}),
|
|
2524
|
+
null === input.gitCommitHash || void 0 === input.gitCommitHash || "string" == typeof input.gitCommitHash || _report(_exceptionable, {
|
|
2525
|
+
path: _path + ".gitCommitHash",
|
|
2526
|
+
expected: "(null | string | undefined)",
|
|
2527
|
+
value: input.gitCommitHash
|
|
2528
|
+
}),
|
|
2529
|
+
null === input.message || void 0 === input.message || "string" == typeof input.message || _report(_exceptionable, {
|
|
2530
|
+
path: _path + ".message",
|
|
2531
|
+
expected: "(null | string | undefined)",
|
|
2532
|
+
value: input.message
|
|
2533
|
+
})
|
|
2534
|
+
].every((flag)=>flag);
|
|
2535
|
+
const __is = (input)=>"object" == typeof input && null !== input && _io0(input);
|
|
2536
|
+
let errors;
|
|
2537
|
+
let _report;
|
|
2538
|
+
return (input)=>{
|
|
2539
|
+
if (false === __is(input)) {
|
|
2540
|
+
errors = [];
|
|
2541
|
+
_report = _validateReport._validateReport(errors);
|
|
2542
|
+
((input, _path, _exceptionable = true)=>("object" == typeof input && null !== input || _report(true, {
|
|
2543
|
+
path: _path + "",
|
|
2544
|
+
expected: "__type",
|
|
2545
|
+
value: input
|
|
2546
|
+
})) && _vo0(input, _path + "", true) || _report(true, {
|
|
2547
|
+
path: _path + "",
|
|
2548
|
+
expected: "__type",
|
|
2549
|
+
value: input
|
|
2550
|
+
}))(input, "$input", true);
|
|
2551
|
+
const success = 0 === errors.length;
|
|
2552
|
+
return success ? {
|
|
2553
|
+
success,
|
|
2554
|
+
data: input
|
|
2555
|
+
} : {
|
|
2556
|
+
success,
|
|
2557
|
+
errors,
|
|
2558
|
+
data: input
|
|
2559
|
+
};
|
|
1980
2560
|
}
|
|
1981
|
-
return
|
|
2561
|
+
return {
|
|
2562
|
+
success: true,
|
|
2563
|
+
data: input
|
|
2564
|
+
};
|
|
2565
|
+
};
|
|
2566
|
+
})();
|
|
2567
|
+
let rpc_config = null;
|
|
2568
|
+
let rpc_databasePlugin = null;
|
|
2569
|
+
const prepareConfig = async ()=>{
|
|
2570
|
+
if (!rpc_config) {
|
|
2571
|
+
rpc_config = await (0, plugin_core_namespaceObject.loadConfig)({
|
|
2572
|
+
platform: "console"
|
|
2573
|
+
});
|
|
2574
|
+
rpc_databasePlugin = await rpc_config?.database({
|
|
2575
|
+
cwd: plugin_core_namespaceObject.getCwd()
|
|
2576
|
+
}) ?? null;
|
|
1982
2577
|
}
|
|
2578
|
+
return {
|
|
2579
|
+
config: rpc_config,
|
|
2580
|
+
databasePlugin: rpc_databasePlugin
|
|
2581
|
+
};
|
|
1983
2582
|
};
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
};
|
|
1989
|
-
for (const key of keys)delete entries[key];
|
|
1990
|
-
return {
|
|
1991
|
-
...schema,
|
|
1992
|
-
entries
|
|
1993
|
-
};
|
|
1994
|
-
}
|
|
1995
|
-
function partial(schema, keys) {
|
|
1996
|
-
const entries = {};
|
|
1997
|
-
for(const key in schema.entries)entries[key] = !keys || keys.includes(key) ? optional(schema.entries[key]) : schema.entries[key];
|
|
1998
|
-
return {
|
|
1999
|
-
...schema,
|
|
2000
|
-
entries
|
|
2001
|
-
};
|
|
2002
|
-
}
|
|
2003
|
-
async function safeParseAsync(schema, input, config2) {
|
|
2004
|
-
const dataset = await schema._run({
|
|
2005
|
-
typed: false,
|
|
2006
|
-
value: input
|
|
2007
|
-
}, getGlobalConfig(config2));
|
|
2008
|
-
return {
|
|
2009
|
-
typed: dataset.typed,
|
|
2010
|
-
success: !dataset.issues,
|
|
2011
|
-
output: dataset.value,
|
|
2012
|
-
issues: dataset.issues
|
|
2013
|
-
};
|
|
2014
|
-
}
|
|
2015
|
-
var vValidator = (target, schema, hook)=>validator(target, async (value, c)=>{
|
|
2016
|
-
const result = await safeParseAsync(schema, value);
|
|
2017
|
-
if (hook) {
|
|
2018
|
-
const hookResult = hook(result, c);
|
|
2019
|
-
if (hookResult instanceof Response || hookResult instanceof Promise) return hookResult;
|
|
2020
|
-
}
|
|
2021
|
-
if (!result.success) return c.json(result, 400);
|
|
2022
|
-
const data = result.output;
|
|
2023
|
-
return data;
|
|
2024
|
-
});
|
|
2025
|
-
const plugin_core_namespaceObject = require("@hot-updater/plugin-core");
|
|
2026
|
-
const bundleSchema = dist_object({
|
|
2027
|
-
platform: union([
|
|
2028
|
-
literal("ios"),
|
|
2029
|
-
literal("android")
|
|
2030
|
-
]),
|
|
2031
|
-
targetAppVersion: string(),
|
|
2032
|
-
id: string(),
|
|
2033
|
-
shouldForceUpdate: dist_boolean(),
|
|
2034
|
-
enabled: dist_boolean(),
|
|
2035
|
-
fileUrl: string(),
|
|
2036
|
-
fileHash: string(),
|
|
2037
|
-
gitCommitHash: nullable(string()),
|
|
2038
|
-
message: nullable(string())
|
|
2039
|
-
});
|
|
2040
|
-
let rpc_config = null;
|
|
2041
|
-
let rpc_databasePlugin = null;
|
|
2042
|
-
const prepareConfig = async ()=>{
|
|
2043
|
-
if (!rpc_config) {
|
|
2044
|
-
rpc_config = await (0, plugin_core_namespaceObject.loadConfig)({
|
|
2045
|
-
platform: "console"
|
|
2583
|
+
const rpc = new hono_Hono().get("/getConfig", async (c)=>{
|
|
2584
|
+
const { config } = await prepareConfig();
|
|
2585
|
+
return c.json({
|
|
2586
|
+
console: config?.console
|
|
2046
2587
|
});
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
databasePlugin
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2588
|
+
}).get("/isConfigLoaded", (c)=>c.json(null !== rpc_config)).get("/getBundles", async (c)=>{
|
|
2589
|
+
const { databasePlugin } = await prepareConfig();
|
|
2590
|
+
const bundles = await databasePlugin?.getBundles(true);
|
|
2591
|
+
return c.json(bundles ?? []);
|
|
2592
|
+
}).get("/getBundleById", (0, cjs.typiaValidator)("query", bundleIdValidator), async (c)=>{
|
|
2593
|
+
const { bundleId } = c.req.valid("query");
|
|
2594
|
+
const { databasePlugin } = await prepareConfig();
|
|
2595
|
+
const bundle = await databasePlugin?.getBundleById(bundleId);
|
|
2596
|
+
return c.json(bundle ?? null);
|
|
2597
|
+
}).post("/updateBundle", (0, cjs.typiaValidator)("json", updateBundleValidator), async (c)=>{
|
|
2598
|
+
const { targetBundleId, bundle } = c.req.valid("json");
|
|
2599
|
+
const { databasePlugin } = await prepareConfig();
|
|
2600
|
+
await databasePlugin?.updateBundle(targetBundleId, bundle);
|
|
2601
|
+
await databasePlugin?.commitBundle();
|
|
2602
|
+
return c.json(true);
|
|
2060
2603
|
});
|
|
2061
|
-
|
|
2062
|
-
const
|
|
2063
|
-
const
|
|
2064
|
-
|
|
2065
|
-
}).get("
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
const
|
|
2070
|
-
|
|
2071
|
-
return c.json(bundle ?? null);
|
|
2072
|
-
}).post("/updateBundle", vValidator("json", dist_object({
|
|
2073
|
-
targetBundleId: string(),
|
|
2074
|
-
bundle: partial(omit(bundleSchema, [
|
|
2075
|
-
"id"
|
|
2076
|
-
]))
|
|
2077
|
-
})), async (c)=>{
|
|
2078
|
-
const { targetBundleId, bundle } = c.req.valid("json");
|
|
2079
|
-
const { databasePlugin } = await prepareConfig();
|
|
2080
|
-
await databasePlugin?.updateBundle(targetBundleId, bundle);
|
|
2081
|
-
await databasePlugin?.commitBundle();
|
|
2082
|
-
return c.json(true);
|
|
2083
|
-
});
|
|
2084
|
-
const src_server_rslib_entry_dirname = external_path_default().dirname((0, external_url_namespaceObject.fileURLToPath)(__rslib_import_meta_url__));
|
|
2085
|
-
const relativePathToScript = external_path_default().relative(process.cwd(), src_server_rslib_entry_dirname);
|
|
2086
|
-
const src_server_rslib_entry_app = new hono_Hono().get("/ping", (c)=>c.text("pong")).route("/rpc", rpc).use("/assets/*", serveStatic({
|
|
2087
|
-
root: relativePathToScript
|
|
2088
|
-
})).get("*", serveStatic({
|
|
2089
|
-
root: relativePathToScript,
|
|
2090
|
-
path: "index.html"
|
|
2091
|
-
}));
|
|
2092
|
-
const src_server_rslib_entry_ = src_server_rslib_entry_app;
|
|
2604
|
+
const src_server_rslib_entry_dirname = external_path_default().dirname((0, external_url_namespaceObject.fileURLToPath)(__rslib_import_meta_url__));
|
|
2605
|
+
const relativePathToScript = external_path_default().relative(process.cwd(), src_server_rslib_entry_dirname);
|
|
2606
|
+
const src_server_rslib_entry_app = new hono_Hono().get("/ping", (c)=>c.text("pong")).route("/rpc", rpc).use("/assets/*", serveStatic({
|
|
2607
|
+
root: relativePathToScript
|
|
2608
|
+
})).get("*", serveStatic({
|
|
2609
|
+
root: relativePathToScript,
|
|
2610
|
+
path: "index.html"
|
|
2611
|
+
}));
|
|
2612
|
+
const src_server_rslib_entry_ = src_server_rslib_entry_app;
|
|
2613
|
+
})();
|
|
2093
2614
|
var __webpack_export_target__ = exports;
|
|
2094
2615
|
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
2095
2616
|
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
|