@kanjijs/platform-hono 0.2.0-beta.1
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/README.md +29 -0
- package/dist/index.js +3336 -0
- package/package.json +22 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,3336 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// ../../node_modules/.bun/hono@4.11.4/node_modules/hono/dist/compose.js
|
|
3
|
+
var compose = (middleware, onError, onNotFound) => {
|
|
4
|
+
return (context, next) => {
|
|
5
|
+
let index = -1;
|
|
6
|
+
return dispatch(0);
|
|
7
|
+
async function dispatch(i) {
|
|
8
|
+
if (i <= index) {
|
|
9
|
+
throw new Error("next() called multiple times");
|
|
10
|
+
}
|
|
11
|
+
index = i;
|
|
12
|
+
let res;
|
|
13
|
+
let isError = false;
|
|
14
|
+
let handler;
|
|
15
|
+
if (middleware[i]) {
|
|
16
|
+
handler = middleware[i][0][0];
|
|
17
|
+
context.req.routeIndex = i;
|
|
18
|
+
} else {
|
|
19
|
+
handler = i === middleware.length && next || undefined;
|
|
20
|
+
}
|
|
21
|
+
if (handler) {
|
|
22
|
+
try {
|
|
23
|
+
res = await handler(context, () => dispatch(i + 1));
|
|
24
|
+
} catch (err) {
|
|
25
|
+
if (err instanceof Error && onError) {
|
|
26
|
+
context.error = err;
|
|
27
|
+
res = await onError(err, context);
|
|
28
|
+
isError = true;
|
|
29
|
+
} else {
|
|
30
|
+
throw err;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
} else {
|
|
34
|
+
if (context.finalized === false && onNotFound) {
|
|
35
|
+
res = await onNotFound(context);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (res && (context.finalized === false || isError)) {
|
|
39
|
+
context.res = res;
|
|
40
|
+
}
|
|
41
|
+
return context;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// ../../node_modules/.bun/hono@4.11.4/node_modules/hono/dist/http-exception.js
|
|
47
|
+
var HTTPException = class extends Error {
|
|
48
|
+
res;
|
|
49
|
+
status;
|
|
50
|
+
constructor(status = 500, options) {
|
|
51
|
+
super(options?.message, { cause: options?.cause });
|
|
52
|
+
this.res = options?.res;
|
|
53
|
+
this.status = status;
|
|
54
|
+
}
|
|
55
|
+
getResponse() {
|
|
56
|
+
if (this.res) {
|
|
57
|
+
const newResponse = new Response(this.res.body, {
|
|
58
|
+
status: this.status,
|
|
59
|
+
headers: this.res.headers
|
|
60
|
+
});
|
|
61
|
+
return newResponse;
|
|
62
|
+
}
|
|
63
|
+
return new Response(this.message, {
|
|
64
|
+
status: this.status
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// ../../node_modules/.bun/hono@4.11.4/node_modules/hono/dist/request/constants.js
|
|
70
|
+
var GET_MATCH_RESULT = /* @__PURE__ */ Symbol();
|
|
71
|
+
|
|
72
|
+
// ../../node_modules/.bun/hono@4.11.4/node_modules/hono/dist/utils/body.js
|
|
73
|
+
var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
|
|
74
|
+
const { all = false, dot = false } = options;
|
|
75
|
+
const headers = request instanceof HonoRequest ? request.raw.headers : request.headers;
|
|
76
|
+
const contentType = headers.get("Content-Type");
|
|
77
|
+
if (contentType?.startsWith("multipart/form-data") || contentType?.startsWith("application/x-www-form-urlencoded")) {
|
|
78
|
+
return parseFormData(request, { all, dot });
|
|
79
|
+
}
|
|
80
|
+
return {};
|
|
81
|
+
};
|
|
82
|
+
async function parseFormData(request, options) {
|
|
83
|
+
const formData = await request.formData();
|
|
84
|
+
if (formData) {
|
|
85
|
+
return convertFormDataToBodyData(formData, options);
|
|
86
|
+
}
|
|
87
|
+
return {};
|
|
88
|
+
}
|
|
89
|
+
function convertFormDataToBodyData(formData, options) {
|
|
90
|
+
const form = /* @__PURE__ */ Object.create(null);
|
|
91
|
+
formData.forEach((value, key) => {
|
|
92
|
+
const shouldParseAllValues = options.all || key.endsWith("[]");
|
|
93
|
+
if (!shouldParseAllValues) {
|
|
94
|
+
form[key] = value;
|
|
95
|
+
} else {
|
|
96
|
+
handleParsingAllValues(form, key, value);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
if (options.dot) {
|
|
100
|
+
Object.entries(form).forEach(([key, value]) => {
|
|
101
|
+
const shouldParseDotValues = key.includes(".");
|
|
102
|
+
if (shouldParseDotValues) {
|
|
103
|
+
handleParsingNestedValues(form, key, value);
|
|
104
|
+
delete form[key];
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return form;
|
|
109
|
+
}
|
|
110
|
+
var handleParsingAllValues = (form, key, value) => {
|
|
111
|
+
if (form[key] !== undefined) {
|
|
112
|
+
if (Array.isArray(form[key])) {
|
|
113
|
+
form[key].push(value);
|
|
114
|
+
} else {
|
|
115
|
+
form[key] = [form[key], value];
|
|
116
|
+
}
|
|
117
|
+
} else {
|
|
118
|
+
if (!key.endsWith("[]")) {
|
|
119
|
+
form[key] = value;
|
|
120
|
+
} else {
|
|
121
|
+
form[key] = [value];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
var handleParsingNestedValues = (form, key, value) => {
|
|
126
|
+
let nestedForm = form;
|
|
127
|
+
const keys = key.split(".");
|
|
128
|
+
keys.forEach((key2, index) => {
|
|
129
|
+
if (index === keys.length - 1) {
|
|
130
|
+
nestedForm[key2] = value;
|
|
131
|
+
} else {
|
|
132
|
+
if (!nestedForm[key2] || typeof nestedForm[key2] !== "object" || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) {
|
|
133
|
+
nestedForm[key2] = /* @__PURE__ */ Object.create(null);
|
|
134
|
+
}
|
|
135
|
+
nestedForm = nestedForm[key2];
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
// ../../node_modules/.bun/hono@4.11.4/node_modules/hono/dist/utils/url.js
|
|
141
|
+
var splitPath = (path) => {
|
|
142
|
+
const paths = path.split("/");
|
|
143
|
+
if (paths[0] === "") {
|
|
144
|
+
paths.shift();
|
|
145
|
+
}
|
|
146
|
+
return paths;
|
|
147
|
+
};
|
|
148
|
+
var splitRoutingPath = (routePath) => {
|
|
149
|
+
const { groups, path } = extractGroupsFromPath(routePath);
|
|
150
|
+
const paths = splitPath(path);
|
|
151
|
+
return replaceGroupMarks(paths, groups);
|
|
152
|
+
};
|
|
153
|
+
var extractGroupsFromPath = (path) => {
|
|
154
|
+
const groups = [];
|
|
155
|
+
path = path.replace(/\{[^}]+\}/g, (match, index) => {
|
|
156
|
+
const mark = `@${index}`;
|
|
157
|
+
groups.push([mark, match]);
|
|
158
|
+
return mark;
|
|
159
|
+
});
|
|
160
|
+
return { groups, path };
|
|
161
|
+
};
|
|
162
|
+
var replaceGroupMarks = (paths, groups) => {
|
|
163
|
+
for (let i = groups.length - 1;i >= 0; i--) {
|
|
164
|
+
const [mark] = groups[i];
|
|
165
|
+
for (let j = paths.length - 1;j >= 0; j--) {
|
|
166
|
+
if (paths[j].includes(mark)) {
|
|
167
|
+
paths[j] = paths[j].replace(mark, groups[i][1]);
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return paths;
|
|
173
|
+
};
|
|
174
|
+
var patternCache = {};
|
|
175
|
+
var getPattern = (label, next) => {
|
|
176
|
+
if (label === "*") {
|
|
177
|
+
return "*";
|
|
178
|
+
}
|
|
179
|
+
const match = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
180
|
+
if (match) {
|
|
181
|
+
const cacheKey = `${label}#${next}`;
|
|
182
|
+
if (!patternCache[cacheKey]) {
|
|
183
|
+
if (match[2]) {
|
|
184
|
+
patternCache[cacheKey] = next && next[0] !== ":" && next[0] !== "*" ? [cacheKey, match[1], new RegExp(`^${match[2]}(?=/${next})`)] : [label, match[1], new RegExp(`^${match[2]}$`)];
|
|
185
|
+
} else {
|
|
186
|
+
patternCache[cacheKey] = [label, match[1], true];
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return patternCache[cacheKey];
|
|
190
|
+
}
|
|
191
|
+
return null;
|
|
192
|
+
};
|
|
193
|
+
var tryDecode = (str, decoder) => {
|
|
194
|
+
try {
|
|
195
|
+
return decoder(str);
|
|
196
|
+
} catch {
|
|
197
|
+
return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match) => {
|
|
198
|
+
try {
|
|
199
|
+
return decoder(match);
|
|
200
|
+
} catch {
|
|
201
|
+
return match;
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
var tryDecodeURI = (str) => tryDecode(str, decodeURI);
|
|
207
|
+
var getPath = (request) => {
|
|
208
|
+
const url = request.url;
|
|
209
|
+
const start = url.indexOf("/", url.indexOf(":") + 4);
|
|
210
|
+
let i = start;
|
|
211
|
+
for (;i < url.length; i++) {
|
|
212
|
+
const charCode = url.charCodeAt(i);
|
|
213
|
+
if (charCode === 37) {
|
|
214
|
+
const queryIndex = url.indexOf("?", i);
|
|
215
|
+
const path = url.slice(start, queryIndex === -1 ? undefined : queryIndex);
|
|
216
|
+
return tryDecodeURI(path.includes("%25") ? path.replace(/%25/g, "%2525") : path);
|
|
217
|
+
} else if (charCode === 63) {
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return url.slice(start, i);
|
|
222
|
+
};
|
|
223
|
+
var getPathNoStrict = (request) => {
|
|
224
|
+
const result = getPath(request);
|
|
225
|
+
return result.length > 1 && result.at(-1) === "/" ? result.slice(0, -1) : result;
|
|
226
|
+
};
|
|
227
|
+
var mergePath = (base, sub, ...rest) => {
|
|
228
|
+
if (rest.length) {
|
|
229
|
+
sub = mergePath(sub, ...rest);
|
|
230
|
+
}
|
|
231
|
+
return `${base?.[0] === "/" ? "" : "/"}${base}${sub === "/" ? "" : `${base?.at(-1) === "/" ? "" : "/"}${sub?.[0] === "/" ? sub.slice(1) : sub}`}`;
|
|
232
|
+
};
|
|
233
|
+
var checkOptionalParameter = (path) => {
|
|
234
|
+
if (path.charCodeAt(path.length - 1) !== 63 || !path.includes(":")) {
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
const segments = path.split("/");
|
|
238
|
+
const results = [];
|
|
239
|
+
let basePath = "";
|
|
240
|
+
segments.forEach((segment) => {
|
|
241
|
+
if (segment !== "" && !/\:/.test(segment)) {
|
|
242
|
+
basePath += "/" + segment;
|
|
243
|
+
} else if (/\:/.test(segment)) {
|
|
244
|
+
if (/\?/.test(segment)) {
|
|
245
|
+
if (results.length === 0 && basePath === "") {
|
|
246
|
+
results.push("/");
|
|
247
|
+
} else {
|
|
248
|
+
results.push(basePath);
|
|
249
|
+
}
|
|
250
|
+
const optionalSegment = segment.replace("?", "");
|
|
251
|
+
basePath += "/" + optionalSegment;
|
|
252
|
+
results.push(basePath);
|
|
253
|
+
} else {
|
|
254
|
+
basePath += "/" + segment;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
return results.filter((v, i, a) => a.indexOf(v) === i);
|
|
259
|
+
};
|
|
260
|
+
var _decodeURI = (value) => {
|
|
261
|
+
if (!/[%+]/.test(value)) {
|
|
262
|
+
return value;
|
|
263
|
+
}
|
|
264
|
+
if (value.indexOf("+") !== -1) {
|
|
265
|
+
value = value.replace(/\+/g, " ");
|
|
266
|
+
}
|
|
267
|
+
return value.indexOf("%") !== -1 ? tryDecode(value, decodeURIComponent_) : value;
|
|
268
|
+
};
|
|
269
|
+
var _getQueryParam = (url, key, multiple) => {
|
|
270
|
+
let encoded;
|
|
271
|
+
if (!multiple && key && !/[%+]/.test(key)) {
|
|
272
|
+
let keyIndex2 = url.indexOf("?", 8);
|
|
273
|
+
if (keyIndex2 === -1) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
if (!url.startsWith(key, keyIndex2 + 1)) {
|
|
277
|
+
keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
|
278
|
+
}
|
|
279
|
+
while (keyIndex2 !== -1) {
|
|
280
|
+
const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1);
|
|
281
|
+
if (trailingKeyCode === 61) {
|
|
282
|
+
const valueIndex = keyIndex2 + key.length + 2;
|
|
283
|
+
const endIndex = url.indexOf("&", valueIndex);
|
|
284
|
+
return _decodeURI(url.slice(valueIndex, endIndex === -1 ? undefined : endIndex));
|
|
285
|
+
} else if (trailingKeyCode == 38 || isNaN(trailingKeyCode)) {
|
|
286
|
+
return "";
|
|
287
|
+
}
|
|
288
|
+
keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
|
289
|
+
}
|
|
290
|
+
encoded = /[%+]/.test(url);
|
|
291
|
+
if (!encoded) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
const results = {};
|
|
296
|
+
encoded ??= /[%+]/.test(url);
|
|
297
|
+
let keyIndex = url.indexOf("?", 8);
|
|
298
|
+
while (keyIndex !== -1) {
|
|
299
|
+
const nextKeyIndex = url.indexOf("&", keyIndex + 1);
|
|
300
|
+
let valueIndex = url.indexOf("=", keyIndex);
|
|
301
|
+
if (valueIndex > nextKeyIndex && nextKeyIndex !== -1) {
|
|
302
|
+
valueIndex = -1;
|
|
303
|
+
}
|
|
304
|
+
let name = url.slice(keyIndex + 1, valueIndex === -1 ? nextKeyIndex === -1 ? undefined : nextKeyIndex : valueIndex);
|
|
305
|
+
if (encoded) {
|
|
306
|
+
name = _decodeURI(name);
|
|
307
|
+
}
|
|
308
|
+
keyIndex = nextKeyIndex;
|
|
309
|
+
if (name === "") {
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
let value;
|
|
313
|
+
if (valueIndex === -1) {
|
|
314
|
+
value = "";
|
|
315
|
+
} else {
|
|
316
|
+
value = url.slice(valueIndex + 1, nextKeyIndex === -1 ? undefined : nextKeyIndex);
|
|
317
|
+
if (encoded) {
|
|
318
|
+
value = _decodeURI(value);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
if (multiple) {
|
|
322
|
+
if (!(results[name] && Array.isArray(results[name]))) {
|
|
323
|
+
results[name] = [];
|
|
324
|
+
}
|
|
325
|
+
results[name].push(value);
|
|
326
|
+
} else {
|
|
327
|
+
results[name] ??= value;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return key ? results[key] : results;
|
|
331
|
+
};
|
|
332
|
+
var getQueryParam = _getQueryParam;
|
|
333
|
+
var getQueryParams = (url, key) => {
|
|
334
|
+
return _getQueryParam(url, key, true);
|
|
335
|
+
};
|
|
336
|
+
var decodeURIComponent_ = decodeURIComponent;
|
|
337
|
+
|
|
338
|
+
// ../../node_modules/.bun/hono@4.11.4/node_modules/hono/dist/request.js
|
|
339
|
+
var tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
|
|
340
|
+
var HonoRequest = class {
|
|
341
|
+
raw;
|
|
342
|
+
#validatedData;
|
|
343
|
+
#matchResult;
|
|
344
|
+
routeIndex = 0;
|
|
345
|
+
path;
|
|
346
|
+
bodyCache = {};
|
|
347
|
+
constructor(request, path = "/", matchResult = [[]]) {
|
|
348
|
+
this.raw = request;
|
|
349
|
+
this.path = path;
|
|
350
|
+
this.#matchResult = matchResult;
|
|
351
|
+
this.#validatedData = {};
|
|
352
|
+
}
|
|
353
|
+
param(key) {
|
|
354
|
+
return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
|
|
355
|
+
}
|
|
356
|
+
#getDecodedParam(key) {
|
|
357
|
+
const paramKey = this.#matchResult[0][this.routeIndex][1][key];
|
|
358
|
+
const param = this.#getParamValue(paramKey);
|
|
359
|
+
return param && /\%/.test(param) ? tryDecodeURIComponent(param) : param;
|
|
360
|
+
}
|
|
361
|
+
#getAllDecodedParams() {
|
|
362
|
+
const decoded = {};
|
|
363
|
+
const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
|
|
364
|
+
for (const key of keys) {
|
|
365
|
+
const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
|
|
366
|
+
if (value !== undefined) {
|
|
367
|
+
decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return decoded;
|
|
371
|
+
}
|
|
372
|
+
#getParamValue(paramKey) {
|
|
373
|
+
return this.#matchResult[1] ? this.#matchResult[1][paramKey] : paramKey;
|
|
374
|
+
}
|
|
375
|
+
query(key) {
|
|
376
|
+
return getQueryParam(this.url, key);
|
|
377
|
+
}
|
|
378
|
+
queries(key) {
|
|
379
|
+
return getQueryParams(this.url, key);
|
|
380
|
+
}
|
|
381
|
+
header(name) {
|
|
382
|
+
if (name) {
|
|
383
|
+
return this.raw.headers.get(name) ?? undefined;
|
|
384
|
+
}
|
|
385
|
+
const headerData = {};
|
|
386
|
+
this.raw.headers.forEach((value, key) => {
|
|
387
|
+
headerData[key] = value;
|
|
388
|
+
});
|
|
389
|
+
return headerData;
|
|
390
|
+
}
|
|
391
|
+
async parseBody(options) {
|
|
392
|
+
return this.bodyCache.parsedBody ??= await parseBody(this, options);
|
|
393
|
+
}
|
|
394
|
+
#cachedBody = (key) => {
|
|
395
|
+
const { bodyCache, raw } = this;
|
|
396
|
+
const cachedBody = bodyCache[key];
|
|
397
|
+
if (cachedBody) {
|
|
398
|
+
return cachedBody;
|
|
399
|
+
}
|
|
400
|
+
const anyCachedKey = Object.keys(bodyCache)[0];
|
|
401
|
+
if (anyCachedKey) {
|
|
402
|
+
return bodyCache[anyCachedKey].then((body) => {
|
|
403
|
+
if (anyCachedKey === "json") {
|
|
404
|
+
body = JSON.stringify(body);
|
|
405
|
+
}
|
|
406
|
+
return new Response(body)[key]();
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
return bodyCache[key] = raw[key]();
|
|
410
|
+
};
|
|
411
|
+
json() {
|
|
412
|
+
return this.#cachedBody("text").then((text) => JSON.parse(text));
|
|
413
|
+
}
|
|
414
|
+
text() {
|
|
415
|
+
return this.#cachedBody("text");
|
|
416
|
+
}
|
|
417
|
+
arrayBuffer() {
|
|
418
|
+
return this.#cachedBody("arrayBuffer");
|
|
419
|
+
}
|
|
420
|
+
blob() {
|
|
421
|
+
return this.#cachedBody("blob");
|
|
422
|
+
}
|
|
423
|
+
formData() {
|
|
424
|
+
return this.#cachedBody("formData");
|
|
425
|
+
}
|
|
426
|
+
addValidatedData(target, data) {
|
|
427
|
+
this.#validatedData[target] = data;
|
|
428
|
+
}
|
|
429
|
+
valid(target) {
|
|
430
|
+
return this.#validatedData[target];
|
|
431
|
+
}
|
|
432
|
+
get url() {
|
|
433
|
+
return this.raw.url;
|
|
434
|
+
}
|
|
435
|
+
get method() {
|
|
436
|
+
return this.raw.method;
|
|
437
|
+
}
|
|
438
|
+
get [GET_MATCH_RESULT]() {
|
|
439
|
+
return this.#matchResult;
|
|
440
|
+
}
|
|
441
|
+
get matchedRoutes() {
|
|
442
|
+
return this.#matchResult[0].map(([[, route]]) => route);
|
|
443
|
+
}
|
|
444
|
+
get routePath() {
|
|
445
|
+
return this.#matchResult[0].map(([[, route]]) => route)[this.routeIndex].path;
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
// ../../node_modules/.bun/hono@4.11.4/node_modules/hono/dist/utils/html.js
|
|
450
|
+
var HtmlEscapedCallbackPhase = {
|
|
451
|
+
Stringify: 1,
|
|
452
|
+
BeforeStream: 2,
|
|
453
|
+
Stream: 3
|
|
454
|
+
};
|
|
455
|
+
var raw = (value, callbacks) => {
|
|
456
|
+
const escapedString = new String(value);
|
|
457
|
+
escapedString.isEscaped = true;
|
|
458
|
+
escapedString.callbacks = callbacks;
|
|
459
|
+
return escapedString;
|
|
460
|
+
};
|
|
461
|
+
var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) => {
|
|
462
|
+
if (typeof str === "object" && !(str instanceof String)) {
|
|
463
|
+
if (!(str instanceof Promise)) {
|
|
464
|
+
str = str.toString();
|
|
465
|
+
}
|
|
466
|
+
if (str instanceof Promise) {
|
|
467
|
+
str = await str;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
const callbacks = str.callbacks;
|
|
471
|
+
if (!callbacks?.length) {
|
|
472
|
+
return Promise.resolve(str);
|
|
473
|
+
}
|
|
474
|
+
if (buffer) {
|
|
475
|
+
buffer[0] += str;
|
|
476
|
+
} else {
|
|
477
|
+
buffer = [str];
|
|
478
|
+
}
|
|
479
|
+
const resStr = Promise.all(callbacks.map((c) => c({ phase, buffer, context }))).then((res) => Promise.all(res.filter(Boolean).map((str2) => resolveCallback(str2, phase, false, context, buffer))).then(() => buffer[0]));
|
|
480
|
+
if (preserveCallbacks) {
|
|
481
|
+
return raw(await resStr, callbacks);
|
|
482
|
+
} else {
|
|
483
|
+
return resStr;
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
// ../../node_modules/.bun/hono@4.11.4/node_modules/hono/dist/context.js
|
|
488
|
+
var TEXT_PLAIN = "text/plain; charset=UTF-8";
|
|
489
|
+
var setDefaultContentType = (contentType, headers) => {
|
|
490
|
+
return {
|
|
491
|
+
"Content-Type": contentType,
|
|
492
|
+
...headers
|
|
493
|
+
};
|
|
494
|
+
};
|
|
495
|
+
var Context = class {
|
|
496
|
+
#rawRequest;
|
|
497
|
+
#req;
|
|
498
|
+
env = {};
|
|
499
|
+
#var;
|
|
500
|
+
finalized = false;
|
|
501
|
+
error;
|
|
502
|
+
#status;
|
|
503
|
+
#executionCtx;
|
|
504
|
+
#res;
|
|
505
|
+
#layout;
|
|
506
|
+
#renderer;
|
|
507
|
+
#notFoundHandler;
|
|
508
|
+
#preparedHeaders;
|
|
509
|
+
#matchResult;
|
|
510
|
+
#path;
|
|
511
|
+
constructor(req, options) {
|
|
512
|
+
this.#rawRequest = req;
|
|
513
|
+
if (options) {
|
|
514
|
+
this.#executionCtx = options.executionCtx;
|
|
515
|
+
this.env = options.env;
|
|
516
|
+
this.#notFoundHandler = options.notFoundHandler;
|
|
517
|
+
this.#path = options.path;
|
|
518
|
+
this.#matchResult = options.matchResult;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
get req() {
|
|
522
|
+
this.#req ??= new HonoRequest(this.#rawRequest, this.#path, this.#matchResult);
|
|
523
|
+
return this.#req;
|
|
524
|
+
}
|
|
525
|
+
get event() {
|
|
526
|
+
if (this.#executionCtx && "respondWith" in this.#executionCtx) {
|
|
527
|
+
return this.#executionCtx;
|
|
528
|
+
} else {
|
|
529
|
+
throw Error("This context has no FetchEvent");
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
get executionCtx() {
|
|
533
|
+
if (this.#executionCtx) {
|
|
534
|
+
return this.#executionCtx;
|
|
535
|
+
} else {
|
|
536
|
+
throw Error("This context has no ExecutionContext");
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
get res() {
|
|
540
|
+
return this.#res ||= new Response(null, {
|
|
541
|
+
headers: this.#preparedHeaders ??= new Headers
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
set res(_res) {
|
|
545
|
+
if (this.#res && _res) {
|
|
546
|
+
_res = new Response(_res.body, _res);
|
|
547
|
+
for (const [k, v] of this.#res.headers.entries()) {
|
|
548
|
+
if (k === "content-type") {
|
|
549
|
+
continue;
|
|
550
|
+
}
|
|
551
|
+
if (k === "set-cookie") {
|
|
552
|
+
const cookies = this.#res.headers.getSetCookie();
|
|
553
|
+
_res.headers.delete("set-cookie");
|
|
554
|
+
for (const cookie of cookies) {
|
|
555
|
+
_res.headers.append("set-cookie", cookie);
|
|
556
|
+
}
|
|
557
|
+
} else {
|
|
558
|
+
_res.headers.set(k, v);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
this.#res = _res;
|
|
563
|
+
this.finalized = true;
|
|
564
|
+
}
|
|
565
|
+
render = (...args) => {
|
|
566
|
+
this.#renderer ??= (content) => this.html(content);
|
|
567
|
+
return this.#renderer(...args);
|
|
568
|
+
};
|
|
569
|
+
setLayout = (layout) => this.#layout = layout;
|
|
570
|
+
getLayout = () => this.#layout;
|
|
571
|
+
setRenderer = (renderer) => {
|
|
572
|
+
this.#renderer = renderer;
|
|
573
|
+
};
|
|
574
|
+
header = (name, value, options) => {
|
|
575
|
+
if (this.finalized) {
|
|
576
|
+
this.#res = new Response(this.#res.body, this.#res);
|
|
577
|
+
}
|
|
578
|
+
const headers = this.#res ? this.#res.headers : this.#preparedHeaders ??= new Headers;
|
|
579
|
+
if (value === undefined) {
|
|
580
|
+
headers.delete(name);
|
|
581
|
+
} else if (options?.append) {
|
|
582
|
+
headers.append(name, value);
|
|
583
|
+
} else {
|
|
584
|
+
headers.set(name, value);
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
status = (status) => {
|
|
588
|
+
this.#status = status;
|
|
589
|
+
};
|
|
590
|
+
set = (key, value) => {
|
|
591
|
+
this.#var ??= /* @__PURE__ */ new Map;
|
|
592
|
+
this.#var.set(key, value);
|
|
593
|
+
};
|
|
594
|
+
get = (key) => {
|
|
595
|
+
return this.#var ? this.#var.get(key) : undefined;
|
|
596
|
+
};
|
|
597
|
+
get var() {
|
|
598
|
+
if (!this.#var) {
|
|
599
|
+
return {};
|
|
600
|
+
}
|
|
601
|
+
return Object.fromEntries(this.#var);
|
|
602
|
+
}
|
|
603
|
+
#newResponse(data, arg, headers) {
|
|
604
|
+
const responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders ?? new Headers;
|
|
605
|
+
if (typeof arg === "object" && "headers" in arg) {
|
|
606
|
+
const argHeaders = arg.headers instanceof Headers ? arg.headers : new Headers(arg.headers);
|
|
607
|
+
for (const [key, value] of argHeaders) {
|
|
608
|
+
if (key.toLowerCase() === "set-cookie") {
|
|
609
|
+
responseHeaders.append(key, value);
|
|
610
|
+
} else {
|
|
611
|
+
responseHeaders.set(key, value);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
if (headers) {
|
|
616
|
+
for (const [k, v] of Object.entries(headers)) {
|
|
617
|
+
if (typeof v === "string") {
|
|
618
|
+
responseHeaders.set(k, v);
|
|
619
|
+
} else {
|
|
620
|
+
responseHeaders.delete(k);
|
|
621
|
+
for (const v2 of v) {
|
|
622
|
+
responseHeaders.append(k, v2);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
const status = typeof arg === "number" ? arg : arg?.status ?? this.#status;
|
|
628
|
+
return new Response(data, { status, headers: responseHeaders });
|
|
629
|
+
}
|
|
630
|
+
newResponse = (...args) => this.#newResponse(...args);
|
|
631
|
+
body = (data, arg, headers) => this.#newResponse(data, arg, headers);
|
|
632
|
+
text = (text, arg, headers) => {
|
|
633
|
+
return !this.#preparedHeaders && !this.#status && !arg && !headers && !this.finalized ? new Response(text) : this.#newResponse(text, arg, setDefaultContentType(TEXT_PLAIN, headers));
|
|
634
|
+
};
|
|
635
|
+
json = (object, arg, headers) => {
|
|
636
|
+
return this.#newResponse(JSON.stringify(object), arg, setDefaultContentType("application/json", headers));
|
|
637
|
+
};
|
|
638
|
+
html = (html, arg, headers) => {
|
|
639
|
+
const res = (html2) => this.#newResponse(html2, arg, setDefaultContentType("text/html; charset=UTF-8", headers));
|
|
640
|
+
return typeof html === "object" ? resolveCallback(html, HtmlEscapedCallbackPhase.Stringify, false, {}).then(res) : res(html);
|
|
641
|
+
};
|
|
642
|
+
redirect = (location, status) => {
|
|
643
|
+
const locationString = String(location);
|
|
644
|
+
this.header("Location", !/[^\x00-\xFF]/.test(locationString) ? locationString : encodeURI(locationString));
|
|
645
|
+
return this.newResponse(null, status ?? 302);
|
|
646
|
+
};
|
|
647
|
+
notFound = () => {
|
|
648
|
+
this.#notFoundHandler ??= () => new Response;
|
|
649
|
+
return this.#notFoundHandler(this);
|
|
650
|
+
};
|
|
651
|
+
};
|
|
652
|
+
|
|
653
|
+
// ../../node_modules/.bun/hono@4.11.4/node_modules/hono/dist/router.js
|
|
654
|
+
var METHOD_NAME_ALL = "ALL";
|
|
655
|
+
var METHOD_NAME_ALL_LOWERCASE = "all";
|
|
656
|
+
var METHODS = ["get", "post", "put", "delete", "options", "patch"];
|
|
657
|
+
var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
|
|
658
|
+
var UnsupportedPathError = class extends Error {
|
|
659
|
+
};
|
|
660
|
+
|
|
661
|
+
// ../../node_modules/.bun/hono@4.11.4/node_modules/hono/dist/utils/constants.js
|
|
662
|
+
var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
|
|
663
|
+
|
|
664
|
+
// ../../node_modules/.bun/hono@4.11.4/node_modules/hono/dist/hono-base.js
|
|
665
|
+
var notFoundHandler = (c) => {
|
|
666
|
+
return c.text("404 Not Found", 404);
|
|
667
|
+
};
|
|
668
|
+
var errorHandler = (err, c) => {
|
|
669
|
+
if ("getResponse" in err) {
|
|
670
|
+
const res = err.getResponse();
|
|
671
|
+
return c.newResponse(res.body, res);
|
|
672
|
+
}
|
|
673
|
+
console.error(err);
|
|
674
|
+
return c.text("Internal Server Error", 500);
|
|
675
|
+
};
|
|
676
|
+
var Hono = class _Hono {
|
|
677
|
+
get;
|
|
678
|
+
post;
|
|
679
|
+
put;
|
|
680
|
+
delete;
|
|
681
|
+
options;
|
|
682
|
+
patch;
|
|
683
|
+
all;
|
|
684
|
+
on;
|
|
685
|
+
use;
|
|
686
|
+
router;
|
|
687
|
+
getPath;
|
|
688
|
+
_basePath = "/";
|
|
689
|
+
#path = "/";
|
|
690
|
+
routes = [];
|
|
691
|
+
constructor(options = {}) {
|
|
692
|
+
const allMethods = [...METHODS, METHOD_NAME_ALL_LOWERCASE];
|
|
693
|
+
allMethods.forEach((method) => {
|
|
694
|
+
this[method] = (args1, ...args) => {
|
|
695
|
+
if (typeof args1 === "string") {
|
|
696
|
+
this.#path = args1;
|
|
697
|
+
} else {
|
|
698
|
+
this.#addRoute(method, this.#path, args1);
|
|
699
|
+
}
|
|
700
|
+
args.forEach((handler) => {
|
|
701
|
+
this.#addRoute(method, this.#path, handler);
|
|
702
|
+
});
|
|
703
|
+
return this;
|
|
704
|
+
};
|
|
705
|
+
});
|
|
706
|
+
this.on = (method, path, ...handlers) => {
|
|
707
|
+
for (const p of [path].flat()) {
|
|
708
|
+
this.#path = p;
|
|
709
|
+
for (const m of [method].flat()) {
|
|
710
|
+
handlers.map((handler) => {
|
|
711
|
+
this.#addRoute(m.toUpperCase(), this.#path, handler);
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
return this;
|
|
716
|
+
};
|
|
717
|
+
this.use = (arg1, ...handlers) => {
|
|
718
|
+
if (typeof arg1 === "string") {
|
|
719
|
+
this.#path = arg1;
|
|
720
|
+
} else {
|
|
721
|
+
this.#path = "*";
|
|
722
|
+
handlers.unshift(arg1);
|
|
723
|
+
}
|
|
724
|
+
handlers.forEach((handler) => {
|
|
725
|
+
this.#addRoute(METHOD_NAME_ALL, this.#path, handler);
|
|
726
|
+
});
|
|
727
|
+
return this;
|
|
728
|
+
};
|
|
729
|
+
const { strict, ...optionsWithoutStrict } = options;
|
|
730
|
+
Object.assign(this, optionsWithoutStrict);
|
|
731
|
+
this.getPath = strict ?? true ? options.getPath ?? getPath : getPathNoStrict;
|
|
732
|
+
}
|
|
733
|
+
#clone() {
|
|
734
|
+
const clone = new _Hono({
|
|
735
|
+
router: this.router,
|
|
736
|
+
getPath: this.getPath
|
|
737
|
+
});
|
|
738
|
+
clone.errorHandler = this.errorHandler;
|
|
739
|
+
clone.#notFoundHandler = this.#notFoundHandler;
|
|
740
|
+
clone.routes = this.routes;
|
|
741
|
+
return clone;
|
|
742
|
+
}
|
|
743
|
+
#notFoundHandler = notFoundHandler;
|
|
744
|
+
errorHandler = errorHandler;
|
|
745
|
+
route(path, app) {
|
|
746
|
+
const subApp = this.basePath(path);
|
|
747
|
+
app.routes.map((r) => {
|
|
748
|
+
let handler;
|
|
749
|
+
if (app.errorHandler === errorHandler) {
|
|
750
|
+
handler = r.handler;
|
|
751
|
+
} else {
|
|
752
|
+
handler = async (c, next) => (await compose([], app.errorHandler)(c, () => r.handler(c, next))).res;
|
|
753
|
+
handler[COMPOSED_HANDLER] = r.handler;
|
|
754
|
+
}
|
|
755
|
+
subApp.#addRoute(r.method, r.path, handler);
|
|
756
|
+
});
|
|
757
|
+
return this;
|
|
758
|
+
}
|
|
759
|
+
basePath(path) {
|
|
760
|
+
const subApp = this.#clone();
|
|
761
|
+
subApp._basePath = mergePath(this._basePath, path);
|
|
762
|
+
return subApp;
|
|
763
|
+
}
|
|
764
|
+
onError = (handler) => {
|
|
765
|
+
this.errorHandler = handler;
|
|
766
|
+
return this;
|
|
767
|
+
};
|
|
768
|
+
notFound = (handler) => {
|
|
769
|
+
this.#notFoundHandler = handler;
|
|
770
|
+
return this;
|
|
771
|
+
};
|
|
772
|
+
mount(path, applicationHandler, options) {
|
|
773
|
+
let replaceRequest;
|
|
774
|
+
let optionHandler;
|
|
775
|
+
if (options) {
|
|
776
|
+
if (typeof options === "function") {
|
|
777
|
+
optionHandler = options;
|
|
778
|
+
} else {
|
|
779
|
+
optionHandler = options.optionHandler;
|
|
780
|
+
if (options.replaceRequest === false) {
|
|
781
|
+
replaceRequest = (request) => request;
|
|
782
|
+
} else {
|
|
783
|
+
replaceRequest = options.replaceRequest;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
const getOptions = optionHandler ? (c) => {
|
|
788
|
+
const options2 = optionHandler(c);
|
|
789
|
+
return Array.isArray(options2) ? options2 : [options2];
|
|
790
|
+
} : (c) => {
|
|
791
|
+
let executionContext = undefined;
|
|
792
|
+
try {
|
|
793
|
+
executionContext = c.executionCtx;
|
|
794
|
+
} catch {}
|
|
795
|
+
return [c.env, executionContext];
|
|
796
|
+
};
|
|
797
|
+
replaceRequest ||= (() => {
|
|
798
|
+
const mergedPath = mergePath(this._basePath, path);
|
|
799
|
+
const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length;
|
|
800
|
+
return (request) => {
|
|
801
|
+
const url = new URL(request.url);
|
|
802
|
+
url.pathname = url.pathname.slice(pathPrefixLength) || "/";
|
|
803
|
+
return new Request(url, request);
|
|
804
|
+
};
|
|
805
|
+
})();
|
|
806
|
+
const handler = async (c, next) => {
|
|
807
|
+
const res = await applicationHandler(replaceRequest(c.req.raw), ...getOptions(c));
|
|
808
|
+
if (res) {
|
|
809
|
+
return res;
|
|
810
|
+
}
|
|
811
|
+
await next();
|
|
812
|
+
};
|
|
813
|
+
this.#addRoute(METHOD_NAME_ALL, mergePath(path, "*"), handler);
|
|
814
|
+
return this;
|
|
815
|
+
}
|
|
816
|
+
#addRoute(method, path, handler) {
|
|
817
|
+
method = method.toUpperCase();
|
|
818
|
+
path = mergePath(this._basePath, path);
|
|
819
|
+
const r = { basePath: this._basePath, path, method, handler };
|
|
820
|
+
this.router.add(method, path, [handler, r]);
|
|
821
|
+
this.routes.push(r);
|
|
822
|
+
}
|
|
823
|
+
#handleError(err, c) {
|
|
824
|
+
if (err instanceof Error) {
|
|
825
|
+
return this.errorHandler(err, c);
|
|
826
|
+
}
|
|
827
|
+
throw err;
|
|
828
|
+
}
|
|
829
|
+
#dispatch(request, executionCtx, env, method) {
|
|
830
|
+
if (method === "HEAD") {
|
|
831
|
+
return (async () => new Response(null, await this.#dispatch(request, executionCtx, env, "GET")))();
|
|
832
|
+
}
|
|
833
|
+
const path = this.getPath(request, { env });
|
|
834
|
+
const matchResult = this.router.match(method, path);
|
|
835
|
+
const c = new Context(request, {
|
|
836
|
+
path,
|
|
837
|
+
matchResult,
|
|
838
|
+
env,
|
|
839
|
+
executionCtx,
|
|
840
|
+
notFoundHandler: this.#notFoundHandler
|
|
841
|
+
});
|
|
842
|
+
if (matchResult[0].length === 1) {
|
|
843
|
+
let res;
|
|
844
|
+
try {
|
|
845
|
+
res = matchResult[0][0][0][0](c, async () => {
|
|
846
|
+
c.res = await this.#notFoundHandler(c);
|
|
847
|
+
});
|
|
848
|
+
} catch (err) {
|
|
849
|
+
return this.#handleError(err, c);
|
|
850
|
+
}
|
|
851
|
+
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);
|
|
852
|
+
}
|
|
853
|
+
const composed = compose(matchResult[0], this.errorHandler, this.#notFoundHandler);
|
|
854
|
+
return (async () => {
|
|
855
|
+
try {
|
|
856
|
+
const context = await composed(c);
|
|
857
|
+
if (!context.finalized) {
|
|
858
|
+
throw new Error("Context is not finalized. Did you forget to return a Response object or `await next()`?");
|
|
859
|
+
}
|
|
860
|
+
return context.res;
|
|
861
|
+
} catch (err) {
|
|
862
|
+
return this.#handleError(err, c);
|
|
863
|
+
}
|
|
864
|
+
})();
|
|
865
|
+
}
|
|
866
|
+
fetch = (request, ...rest) => {
|
|
867
|
+
return this.#dispatch(request, rest[1], rest[0], request.method);
|
|
868
|
+
};
|
|
869
|
+
request = (input, requestInit, Env, executionCtx) => {
|
|
870
|
+
if (input instanceof Request) {
|
|
871
|
+
return this.fetch(requestInit ? new Request(input, requestInit) : input, Env, executionCtx);
|
|
872
|
+
}
|
|
873
|
+
input = input.toString();
|
|
874
|
+
return this.fetch(new Request(/^https?:\/\//.test(input) ? input : `http://localhost${mergePath("/", input)}`, requestInit), Env, executionCtx);
|
|
875
|
+
};
|
|
876
|
+
fire = () => {
|
|
877
|
+
addEventListener("fetch", (event) => {
|
|
878
|
+
event.respondWith(this.#dispatch(event.request, event, undefined, event.request.method));
|
|
879
|
+
});
|
|
880
|
+
};
|
|
881
|
+
};
|
|
882
|
+
|
|
883
|
+
// ../../node_modules/.bun/hono@4.11.4/node_modules/hono/dist/router/reg-exp-router/matcher.js
|
|
884
|
+
var emptyParam = [];
|
|
885
|
+
function match(method, path) {
|
|
886
|
+
const matchers = this.buildAllMatchers();
|
|
887
|
+
const match2 = (method2, path2) => {
|
|
888
|
+
const matcher = matchers[method2] || matchers[METHOD_NAME_ALL];
|
|
889
|
+
const staticMatch = matcher[2][path2];
|
|
890
|
+
if (staticMatch) {
|
|
891
|
+
return staticMatch;
|
|
892
|
+
}
|
|
893
|
+
const match3 = path2.match(matcher[0]);
|
|
894
|
+
if (!match3) {
|
|
895
|
+
return [[], emptyParam];
|
|
896
|
+
}
|
|
897
|
+
const index = match3.indexOf("", 1);
|
|
898
|
+
return [matcher[1][index], match3];
|
|
899
|
+
};
|
|
900
|
+
this.match = match2;
|
|
901
|
+
return match2(method, path);
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
// ../../node_modules/.bun/hono@4.11.4/node_modules/hono/dist/router/reg-exp-router/node.js
|
|
905
|
+
var LABEL_REG_EXP_STR = "[^/]+";
|
|
906
|
+
var ONLY_WILDCARD_REG_EXP_STR = ".*";
|
|
907
|
+
var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
|
|
908
|
+
var PATH_ERROR = /* @__PURE__ */ Symbol();
|
|
909
|
+
var regExpMetaChars = new Set(".\\+*[^]$()");
|
|
910
|
+
function compareKey(a, b) {
|
|
911
|
+
if (a.length === 1) {
|
|
912
|
+
return b.length === 1 ? a < b ? -1 : 1 : -1;
|
|
913
|
+
}
|
|
914
|
+
if (b.length === 1) {
|
|
915
|
+
return 1;
|
|
916
|
+
}
|
|
917
|
+
if (a === ONLY_WILDCARD_REG_EXP_STR || a === TAIL_WILDCARD_REG_EXP_STR) {
|
|
918
|
+
return 1;
|
|
919
|
+
} else if (b === ONLY_WILDCARD_REG_EXP_STR || b === TAIL_WILDCARD_REG_EXP_STR) {
|
|
920
|
+
return -1;
|
|
921
|
+
}
|
|
922
|
+
if (a === LABEL_REG_EXP_STR) {
|
|
923
|
+
return 1;
|
|
924
|
+
} else if (b === LABEL_REG_EXP_STR) {
|
|
925
|
+
return -1;
|
|
926
|
+
}
|
|
927
|
+
return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
|
|
928
|
+
}
|
|
929
|
+
var Node = class _Node {
|
|
930
|
+
#index;
|
|
931
|
+
#varIndex;
|
|
932
|
+
#children = /* @__PURE__ */ Object.create(null);
|
|
933
|
+
insert(tokens, index, paramMap, context, pathErrorCheckOnly) {
|
|
934
|
+
if (tokens.length === 0) {
|
|
935
|
+
if (this.#index !== undefined) {
|
|
936
|
+
throw PATH_ERROR;
|
|
937
|
+
}
|
|
938
|
+
if (pathErrorCheckOnly) {
|
|
939
|
+
return;
|
|
940
|
+
}
|
|
941
|
+
this.#index = index;
|
|
942
|
+
return;
|
|
943
|
+
}
|
|
944
|
+
const [token, ...restTokens] = tokens;
|
|
945
|
+
const pattern = token === "*" ? restTokens.length === 0 ? ["", "", ONLY_WILDCARD_REG_EXP_STR] : ["", "", LABEL_REG_EXP_STR] : token === "/*" ? ["", "", TAIL_WILDCARD_REG_EXP_STR] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
946
|
+
let node;
|
|
947
|
+
if (pattern) {
|
|
948
|
+
const name = pattern[1];
|
|
949
|
+
let regexpStr = pattern[2] || LABEL_REG_EXP_STR;
|
|
950
|
+
if (name && pattern[2]) {
|
|
951
|
+
if (regexpStr === ".*") {
|
|
952
|
+
throw PATH_ERROR;
|
|
953
|
+
}
|
|
954
|
+
regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
|
|
955
|
+
if (/\((?!\?:)/.test(regexpStr)) {
|
|
956
|
+
throw PATH_ERROR;
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
node = this.#children[regexpStr];
|
|
960
|
+
if (!node) {
|
|
961
|
+
if (Object.keys(this.#children).some((k) => k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR)) {
|
|
962
|
+
throw PATH_ERROR;
|
|
963
|
+
}
|
|
964
|
+
if (pathErrorCheckOnly) {
|
|
965
|
+
return;
|
|
966
|
+
}
|
|
967
|
+
node = this.#children[regexpStr] = new _Node;
|
|
968
|
+
if (name !== "") {
|
|
969
|
+
node.#varIndex = context.varIndex++;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
if (!pathErrorCheckOnly && name !== "") {
|
|
973
|
+
paramMap.push([name, node.#varIndex]);
|
|
974
|
+
}
|
|
975
|
+
} else {
|
|
976
|
+
node = this.#children[token];
|
|
977
|
+
if (!node) {
|
|
978
|
+
if (Object.keys(this.#children).some((k) => k.length > 1 && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR)) {
|
|
979
|
+
throw PATH_ERROR;
|
|
980
|
+
}
|
|
981
|
+
if (pathErrorCheckOnly) {
|
|
982
|
+
return;
|
|
983
|
+
}
|
|
984
|
+
node = this.#children[token] = new _Node;
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
node.insert(restTokens, index, paramMap, context, pathErrorCheckOnly);
|
|
988
|
+
}
|
|
989
|
+
buildRegExpStr() {
|
|
990
|
+
const childKeys = Object.keys(this.#children).sort(compareKey);
|
|
991
|
+
const strList = childKeys.map((k) => {
|
|
992
|
+
const c = this.#children[k];
|
|
993
|
+
return (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr();
|
|
994
|
+
});
|
|
995
|
+
if (typeof this.#index === "number") {
|
|
996
|
+
strList.unshift(`#${this.#index}`);
|
|
997
|
+
}
|
|
998
|
+
if (strList.length === 0) {
|
|
999
|
+
return "";
|
|
1000
|
+
}
|
|
1001
|
+
if (strList.length === 1) {
|
|
1002
|
+
return strList[0];
|
|
1003
|
+
}
|
|
1004
|
+
return "(?:" + strList.join("|") + ")";
|
|
1005
|
+
}
|
|
1006
|
+
};
|
|
1007
|
+
|
|
1008
|
+
// ../../node_modules/.bun/hono@4.11.4/node_modules/hono/dist/router/reg-exp-router/trie.js
|
|
1009
|
+
var Trie = class {
|
|
1010
|
+
#context = { varIndex: 0 };
|
|
1011
|
+
#root = new Node;
|
|
1012
|
+
insert(path, index, pathErrorCheckOnly) {
|
|
1013
|
+
const paramAssoc = [];
|
|
1014
|
+
const groups = [];
|
|
1015
|
+
for (let i = 0;; ) {
|
|
1016
|
+
let replaced = false;
|
|
1017
|
+
path = path.replace(/\{[^}]+\}/g, (m) => {
|
|
1018
|
+
const mark = `@\\${i}`;
|
|
1019
|
+
groups[i] = [mark, m];
|
|
1020
|
+
i++;
|
|
1021
|
+
replaced = true;
|
|
1022
|
+
return mark;
|
|
1023
|
+
});
|
|
1024
|
+
if (!replaced) {
|
|
1025
|
+
break;
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
const tokens = path.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
|
|
1029
|
+
for (let i = groups.length - 1;i >= 0; i--) {
|
|
1030
|
+
const [mark] = groups[i];
|
|
1031
|
+
for (let j = tokens.length - 1;j >= 0; j--) {
|
|
1032
|
+
if (tokens[j].indexOf(mark) !== -1) {
|
|
1033
|
+
tokens[j] = tokens[j].replace(mark, groups[i][1]);
|
|
1034
|
+
break;
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
this.#root.insert(tokens, index, paramAssoc, this.#context, pathErrorCheckOnly);
|
|
1039
|
+
return paramAssoc;
|
|
1040
|
+
}
|
|
1041
|
+
buildRegExp() {
|
|
1042
|
+
let regexp = this.#root.buildRegExpStr();
|
|
1043
|
+
if (regexp === "") {
|
|
1044
|
+
return [/^$/, [], []];
|
|
1045
|
+
}
|
|
1046
|
+
let captureIndex = 0;
|
|
1047
|
+
const indexReplacementMap = [];
|
|
1048
|
+
const paramReplacementMap = [];
|
|
1049
|
+
regexp = regexp.replace(/#(\d+)|@(\d+)|\.\*\$/g, (_, handlerIndex, paramIndex) => {
|
|
1050
|
+
if (handlerIndex !== undefined) {
|
|
1051
|
+
indexReplacementMap[++captureIndex] = Number(handlerIndex);
|
|
1052
|
+
return "$()";
|
|
1053
|
+
}
|
|
1054
|
+
if (paramIndex !== undefined) {
|
|
1055
|
+
paramReplacementMap[Number(paramIndex)] = ++captureIndex;
|
|
1056
|
+
return "";
|
|
1057
|
+
}
|
|
1058
|
+
return "";
|
|
1059
|
+
});
|
|
1060
|
+
return [new RegExp(`^${regexp}`), indexReplacementMap, paramReplacementMap];
|
|
1061
|
+
}
|
|
1062
|
+
};
|
|
1063
|
+
|
|
1064
|
+
// ../../node_modules/.bun/hono@4.11.4/node_modules/hono/dist/router/reg-exp-router/router.js
|
|
1065
|
+
var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
|
|
1066
|
+
var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
1067
|
+
function buildWildcardRegExp(path) {
|
|
1068
|
+
return wildcardRegExpCache[path] ??= new RegExp(path === "*" ? "" : `^${path.replace(/\/\*$|([.\\+*[^\]$()])/g, (_, metaChar) => metaChar ? `\\${metaChar}` : "(?:|/.*)")}$`);
|
|
1069
|
+
}
|
|
1070
|
+
function clearWildcardRegExpCache() {
|
|
1071
|
+
wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
1072
|
+
}
|
|
1073
|
+
function buildMatcherFromPreprocessedRoutes(routes) {
|
|
1074
|
+
const trie = new Trie;
|
|
1075
|
+
const handlerData = [];
|
|
1076
|
+
if (routes.length === 0) {
|
|
1077
|
+
return nullMatcher;
|
|
1078
|
+
}
|
|
1079
|
+
const routesWithStaticPathFlag = routes.map((route) => [!/\*|\/:/.test(route[0]), ...route]).sort(([isStaticA, pathA], [isStaticB, pathB]) => isStaticA ? 1 : isStaticB ? -1 : pathA.length - pathB.length);
|
|
1080
|
+
const staticMap = /* @__PURE__ */ Object.create(null);
|
|
1081
|
+
for (let i = 0, j = -1, len = routesWithStaticPathFlag.length;i < len; i++) {
|
|
1082
|
+
const [pathErrorCheckOnly, path, handlers] = routesWithStaticPathFlag[i];
|
|
1083
|
+
if (pathErrorCheckOnly) {
|
|
1084
|
+
staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
|
|
1085
|
+
} else {
|
|
1086
|
+
j++;
|
|
1087
|
+
}
|
|
1088
|
+
let paramAssoc;
|
|
1089
|
+
try {
|
|
1090
|
+
paramAssoc = trie.insert(path, j, pathErrorCheckOnly);
|
|
1091
|
+
} catch (e) {
|
|
1092
|
+
throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
|
|
1093
|
+
}
|
|
1094
|
+
if (pathErrorCheckOnly) {
|
|
1095
|
+
continue;
|
|
1096
|
+
}
|
|
1097
|
+
handlerData[j] = handlers.map(([h, paramCount]) => {
|
|
1098
|
+
const paramIndexMap = /* @__PURE__ */ Object.create(null);
|
|
1099
|
+
paramCount -= 1;
|
|
1100
|
+
for (;paramCount >= 0; paramCount--) {
|
|
1101
|
+
const [key, value] = paramAssoc[paramCount];
|
|
1102
|
+
paramIndexMap[key] = value;
|
|
1103
|
+
}
|
|
1104
|
+
return [h, paramIndexMap];
|
|
1105
|
+
});
|
|
1106
|
+
}
|
|
1107
|
+
const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
|
|
1108
|
+
for (let i = 0, len = handlerData.length;i < len; i++) {
|
|
1109
|
+
for (let j = 0, len2 = handlerData[i].length;j < len2; j++) {
|
|
1110
|
+
const map = handlerData[i][j]?.[1];
|
|
1111
|
+
if (!map) {
|
|
1112
|
+
continue;
|
|
1113
|
+
}
|
|
1114
|
+
const keys = Object.keys(map);
|
|
1115
|
+
for (let k = 0, len3 = keys.length;k < len3; k++) {
|
|
1116
|
+
map[keys[k]] = paramReplacementMap[map[keys[k]]];
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
const handlerMap = [];
|
|
1121
|
+
for (const i in indexReplacementMap) {
|
|
1122
|
+
handlerMap[i] = handlerData[indexReplacementMap[i]];
|
|
1123
|
+
}
|
|
1124
|
+
return [regexp, handlerMap, staticMap];
|
|
1125
|
+
}
|
|
1126
|
+
function findMiddleware(middleware, path) {
|
|
1127
|
+
if (!middleware) {
|
|
1128
|
+
return;
|
|
1129
|
+
}
|
|
1130
|
+
for (const k of Object.keys(middleware).sort((a, b) => b.length - a.length)) {
|
|
1131
|
+
if (buildWildcardRegExp(k).test(path)) {
|
|
1132
|
+
return [...middleware[k]];
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
return;
|
|
1136
|
+
}
|
|
1137
|
+
var RegExpRouter = class {
|
|
1138
|
+
name = "RegExpRouter";
|
|
1139
|
+
#middleware;
|
|
1140
|
+
#routes;
|
|
1141
|
+
constructor() {
|
|
1142
|
+
this.#middleware = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
|
|
1143
|
+
this.#routes = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
|
|
1144
|
+
}
|
|
1145
|
+
add(method, path, handler) {
|
|
1146
|
+
const middleware = this.#middleware;
|
|
1147
|
+
const routes = this.#routes;
|
|
1148
|
+
if (!middleware || !routes) {
|
|
1149
|
+
throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
1150
|
+
}
|
|
1151
|
+
if (!middleware[method]) {
|
|
1152
|
+
[middleware, routes].forEach((handlerMap) => {
|
|
1153
|
+
handlerMap[method] = /* @__PURE__ */ Object.create(null);
|
|
1154
|
+
Object.keys(handlerMap[METHOD_NAME_ALL]).forEach((p) => {
|
|
1155
|
+
handlerMap[method][p] = [...handlerMap[METHOD_NAME_ALL][p]];
|
|
1156
|
+
});
|
|
1157
|
+
});
|
|
1158
|
+
}
|
|
1159
|
+
if (path === "/*") {
|
|
1160
|
+
path = "*";
|
|
1161
|
+
}
|
|
1162
|
+
const paramCount = (path.match(/\/:/g) || []).length;
|
|
1163
|
+
if (/\*$/.test(path)) {
|
|
1164
|
+
const re = buildWildcardRegExp(path);
|
|
1165
|
+
if (method === METHOD_NAME_ALL) {
|
|
1166
|
+
Object.keys(middleware).forEach((m) => {
|
|
1167
|
+
middleware[m][path] ||= findMiddleware(middleware[m], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
|
|
1168
|
+
});
|
|
1169
|
+
} else {
|
|
1170
|
+
middleware[method][path] ||= findMiddleware(middleware[method], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
|
|
1171
|
+
}
|
|
1172
|
+
Object.keys(middleware).forEach((m) => {
|
|
1173
|
+
if (method === METHOD_NAME_ALL || method === m) {
|
|
1174
|
+
Object.keys(middleware[m]).forEach((p) => {
|
|
1175
|
+
re.test(p) && middleware[m][p].push([handler, paramCount]);
|
|
1176
|
+
});
|
|
1177
|
+
}
|
|
1178
|
+
});
|
|
1179
|
+
Object.keys(routes).forEach((m) => {
|
|
1180
|
+
if (method === METHOD_NAME_ALL || method === m) {
|
|
1181
|
+
Object.keys(routes[m]).forEach((p) => re.test(p) && routes[m][p].push([handler, paramCount]));
|
|
1182
|
+
}
|
|
1183
|
+
});
|
|
1184
|
+
return;
|
|
1185
|
+
}
|
|
1186
|
+
const paths = checkOptionalParameter(path) || [path];
|
|
1187
|
+
for (let i = 0, len = paths.length;i < len; i++) {
|
|
1188
|
+
const path2 = paths[i];
|
|
1189
|
+
Object.keys(routes).forEach((m) => {
|
|
1190
|
+
if (method === METHOD_NAME_ALL || method === m) {
|
|
1191
|
+
routes[m][path2] ||= [
|
|
1192
|
+
...findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || []
|
|
1193
|
+
];
|
|
1194
|
+
routes[m][path2].push([handler, paramCount - len + i + 1]);
|
|
1195
|
+
}
|
|
1196
|
+
});
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
match = match;
|
|
1200
|
+
buildAllMatchers() {
|
|
1201
|
+
const matchers = /* @__PURE__ */ Object.create(null);
|
|
1202
|
+
Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
|
|
1203
|
+
matchers[method] ||= this.#buildMatcher(method);
|
|
1204
|
+
});
|
|
1205
|
+
this.#middleware = this.#routes = undefined;
|
|
1206
|
+
clearWildcardRegExpCache();
|
|
1207
|
+
return matchers;
|
|
1208
|
+
}
|
|
1209
|
+
#buildMatcher(method) {
|
|
1210
|
+
const routes = [];
|
|
1211
|
+
let hasOwnRoute = method === METHOD_NAME_ALL;
|
|
1212
|
+
[this.#middleware, this.#routes].forEach((r) => {
|
|
1213
|
+
const ownRoute = r[method] ? Object.keys(r[method]).map((path) => [path, r[method][path]]) : [];
|
|
1214
|
+
if (ownRoute.length !== 0) {
|
|
1215
|
+
hasOwnRoute ||= true;
|
|
1216
|
+
routes.push(...ownRoute);
|
|
1217
|
+
} else if (method !== METHOD_NAME_ALL) {
|
|
1218
|
+
routes.push(...Object.keys(r[METHOD_NAME_ALL]).map((path) => [path, r[METHOD_NAME_ALL][path]]));
|
|
1219
|
+
}
|
|
1220
|
+
});
|
|
1221
|
+
if (!hasOwnRoute) {
|
|
1222
|
+
return null;
|
|
1223
|
+
} else {
|
|
1224
|
+
return buildMatcherFromPreprocessedRoutes(routes);
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
};
|
|
1228
|
+
|
|
1229
|
+
// ../../node_modules/.bun/hono@4.11.4/node_modules/hono/dist/router/reg-exp-router/prepared-router.js
|
|
1230
|
+
var PreparedRegExpRouter = class {
|
|
1231
|
+
name = "PreparedRegExpRouter";
|
|
1232
|
+
#matchers;
|
|
1233
|
+
#relocateMap;
|
|
1234
|
+
constructor(matchers, relocateMap) {
|
|
1235
|
+
this.#matchers = matchers;
|
|
1236
|
+
this.#relocateMap = relocateMap;
|
|
1237
|
+
}
|
|
1238
|
+
#addWildcard(method, handlerData) {
|
|
1239
|
+
const matcher = this.#matchers[method];
|
|
1240
|
+
matcher[1].forEach((list) => list && list.push(handlerData));
|
|
1241
|
+
Object.values(matcher[2]).forEach((list) => list[0].push(handlerData));
|
|
1242
|
+
}
|
|
1243
|
+
#addPath(method, path, handler, indexes, map) {
|
|
1244
|
+
const matcher = this.#matchers[method];
|
|
1245
|
+
if (!map) {
|
|
1246
|
+
matcher[2][path][0].push([handler, {}]);
|
|
1247
|
+
} else {
|
|
1248
|
+
indexes.forEach((index) => {
|
|
1249
|
+
if (typeof index === "number") {
|
|
1250
|
+
matcher[1][index].push([handler, map]);
|
|
1251
|
+
} else {
|
|
1252
|
+
matcher[2][index || path][0].push([handler, map]);
|
|
1253
|
+
}
|
|
1254
|
+
});
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
add(method, path, handler) {
|
|
1258
|
+
if (!this.#matchers[method]) {
|
|
1259
|
+
const all = this.#matchers[METHOD_NAME_ALL];
|
|
1260
|
+
const staticMap = {};
|
|
1261
|
+
for (const key in all[2]) {
|
|
1262
|
+
staticMap[key] = [all[2][key][0].slice(), emptyParam];
|
|
1263
|
+
}
|
|
1264
|
+
this.#matchers[method] = [
|
|
1265
|
+
all[0],
|
|
1266
|
+
all[1].map((list) => Array.isArray(list) ? list.slice() : 0),
|
|
1267
|
+
staticMap
|
|
1268
|
+
];
|
|
1269
|
+
}
|
|
1270
|
+
if (path === "/*" || path === "*") {
|
|
1271
|
+
const handlerData = [handler, {}];
|
|
1272
|
+
if (method === METHOD_NAME_ALL) {
|
|
1273
|
+
for (const m in this.#matchers) {
|
|
1274
|
+
this.#addWildcard(m, handlerData);
|
|
1275
|
+
}
|
|
1276
|
+
} else {
|
|
1277
|
+
this.#addWildcard(method, handlerData);
|
|
1278
|
+
}
|
|
1279
|
+
return;
|
|
1280
|
+
}
|
|
1281
|
+
const data = this.#relocateMap[path];
|
|
1282
|
+
if (!data) {
|
|
1283
|
+
throw new Error(`Path ${path} is not registered`);
|
|
1284
|
+
}
|
|
1285
|
+
for (const [indexes, map] of data) {
|
|
1286
|
+
if (method === METHOD_NAME_ALL) {
|
|
1287
|
+
for (const m in this.#matchers) {
|
|
1288
|
+
this.#addPath(m, path, handler, indexes, map);
|
|
1289
|
+
}
|
|
1290
|
+
} else {
|
|
1291
|
+
this.#addPath(method, path, handler, indexes, map);
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
buildAllMatchers() {
|
|
1296
|
+
return this.#matchers;
|
|
1297
|
+
}
|
|
1298
|
+
match = match;
|
|
1299
|
+
};
|
|
1300
|
+
|
|
1301
|
+
// ../../node_modules/.bun/hono@4.11.4/node_modules/hono/dist/router/smart-router/router.js
|
|
1302
|
+
var SmartRouter = class {
|
|
1303
|
+
name = "SmartRouter";
|
|
1304
|
+
#routers = [];
|
|
1305
|
+
#routes = [];
|
|
1306
|
+
constructor(init) {
|
|
1307
|
+
this.#routers = init.routers;
|
|
1308
|
+
}
|
|
1309
|
+
add(method, path, handler) {
|
|
1310
|
+
if (!this.#routes) {
|
|
1311
|
+
throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
1312
|
+
}
|
|
1313
|
+
this.#routes.push([method, path, handler]);
|
|
1314
|
+
}
|
|
1315
|
+
match(method, path) {
|
|
1316
|
+
if (!this.#routes) {
|
|
1317
|
+
throw new Error("Fatal error");
|
|
1318
|
+
}
|
|
1319
|
+
const routers = this.#routers;
|
|
1320
|
+
const routes = this.#routes;
|
|
1321
|
+
const len = routers.length;
|
|
1322
|
+
let i = 0;
|
|
1323
|
+
let res;
|
|
1324
|
+
for (;i < len; i++) {
|
|
1325
|
+
const router = routers[i];
|
|
1326
|
+
try {
|
|
1327
|
+
for (let i2 = 0, len2 = routes.length;i2 < len2; i2++) {
|
|
1328
|
+
router.add(...routes[i2]);
|
|
1329
|
+
}
|
|
1330
|
+
res = router.match(method, path);
|
|
1331
|
+
} catch (e) {
|
|
1332
|
+
if (e instanceof UnsupportedPathError) {
|
|
1333
|
+
continue;
|
|
1334
|
+
}
|
|
1335
|
+
throw e;
|
|
1336
|
+
}
|
|
1337
|
+
this.match = router.match.bind(router);
|
|
1338
|
+
this.#routers = [router];
|
|
1339
|
+
this.#routes = undefined;
|
|
1340
|
+
break;
|
|
1341
|
+
}
|
|
1342
|
+
if (i === len) {
|
|
1343
|
+
throw new Error("Fatal error");
|
|
1344
|
+
}
|
|
1345
|
+
this.name = `SmartRouter + ${this.activeRouter.name}`;
|
|
1346
|
+
return res;
|
|
1347
|
+
}
|
|
1348
|
+
get activeRouter() {
|
|
1349
|
+
if (this.#routes || this.#routers.length !== 1) {
|
|
1350
|
+
throw new Error("No active router has been determined yet.");
|
|
1351
|
+
}
|
|
1352
|
+
return this.#routers[0];
|
|
1353
|
+
}
|
|
1354
|
+
};
|
|
1355
|
+
|
|
1356
|
+
// ../../node_modules/.bun/hono@4.11.4/node_modules/hono/dist/router/trie-router/node.js
|
|
1357
|
+
var emptyParams = /* @__PURE__ */ Object.create(null);
|
|
1358
|
+
var Node2 = class _Node2 {
|
|
1359
|
+
#methods;
|
|
1360
|
+
#children;
|
|
1361
|
+
#patterns;
|
|
1362
|
+
#order = 0;
|
|
1363
|
+
#params = emptyParams;
|
|
1364
|
+
constructor(method, handler, children) {
|
|
1365
|
+
this.#children = children || /* @__PURE__ */ Object.create(null);
|
|
1366
|
+
this.#methods = [];
|
|
1367
|
+
if (method && handler) {
|
|
1368
|
+
const m = /* @__PURE__ */ Object.create(null);
|
|
1369
|
+
m[method] = { handler, possibleKeys: [], score: 0 };
|
|
1370
|
+
this.#methods = [m];
|
|
1371
|
+
}
|
|
1372
|
+
this.#patterns = [];
|
|
1373
|
+
}
|
|
1374
|
+
insert(method, path, handler) {
|
|
1375
|
+
this.#order = ++this.#order;
|
|
1376
|
+
let curNode = this;
|
|
1377
|
+
const parts = splitRoutingPath(path);
|
|
1378
|
+
const possibleKeys = [];
|
|
1379
|
+
for (let i = 0, len = parts.length;i < len; i++) {
|
|
1380
|
+
const p = parts[i];
|
|
1381
|
+
const nextP = parts[i + 1];
|
|
1382
|
+
const pattern = getPattern(p, nextP);
|
|
1383
|
+
const key = Array.isArray(pattern) ? pattern[0] : p;
|
|
1384
|
+
if (key in curNode.#children) {
|
|
1385
|
+
curNode = curNode.#children[key];
|
|
1386
|
+
if (pattern) {
|
|
1387
|
+
possibleKeys.push(pattern[1]);
|
|
1388
|
+
}
|
|
1389
|
+
continue;
|
|
1390
|
+
}
|
|
1391
|
+
curNode.#children[key] = new _Node2;
|
|
1392
|
+
if (pattern) {
|
|
1393
|
+
curNode.#patterns.push(pattern);
|
|
1394
|
+
possibleKeys.push(pattern[1]);
|
|
1395
|
+
}
|
|
1396
|
+
curNode = curNode.#children[key];
|
|
1397
|
+
}
|
|
1398
|
+
curNode.#methods.push({
|
|
1399
|
+
[method]: {
|
|
1400
|
+
handler,
|
|
1401
|
+
possibleKeys: possibleKeys.filter((v, i, a) => a.indexOf(v) === i),
|
|
1402
|
+
score: this.#order
|
|
1403
|
+
}
|
|
1404
|
+
});
|
|
1405
|
+
return curNode;
|
|
1406
|
+
}
|
|
1407
|
+
#getHandlerSets(node, method, nodeParams, params) {
|
|
1408
|
+
const handlerSets = [];
|
|
1409
|
+
for (let i = 0, len = node.#methods.length;i < len; i++) {
|
|
1410
|
+
const m = node.#methods[i];
|
|
1411
|
+
const handlerSet = m[method] || m[METHOD_NAME_ALL];
|
|
1412
|
+
const processedSet = {};
|
|
1413
|
+
if (handlerSet !== undefined) {
|
|
1414
|
+
handlerSet.params = /* @__PURE__ */ Object.create(null);
|
|
1415
|
+
handlerSets.push(handlerSet);
|
|
1416
|
+
if (nodeParams !== emptyParams || params && params !== emptyParams) {
|
|
1417
|
+
for (let i2 = 0, len2 = handlerSet.possibleKeys.length;i2 < len2; i2++) {
|
|
1418
|
+
const key = handlerSet.possibleKeys[i2];
|
|
1419
|
+
const processed = processedSet[handlerSet.score];
|
|
1420
|
+
handlerSet.params[key] = params?.[key] && !processed ? params[key] : nodeParams[key] ?? params?.[key];
|
|
1421
|
+
processedSet[handlerSet.score] = true;
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
return handlerSets;
|
|
1427
|
+
}
|
|
1428
|
+
search(method, path) {
|
|
1429
|
+
const handlerSets = [];
|
|
1430
|
+
this.#params = emptyParams;
|
|
1431
|
+
const curNode = this;
|
|
1432
|
+
let curNodes = [curNode];
|
|
1433
|
+
const parts = splitPath(path);
|
|
1434
|
+
const curNodesQueue = [];
|
|
1435
|
+
for (let i = 0, len = parts.length;i < len; i++) {
|
|
1436
|
+
const part = parts[i];
|
|
1437
|
+
const isLast = i === len - 1;
|
|
1438
|
+
const tempNodes = [];
|
|
1439
|
+
for (let j = 0, len2 = curNodes.length;j < len2; j++) {
|
|
1440
|
+
const node = curNodes[j];
|
|
1441
|
+
const nextNode = node.#children[part];
|
|
1442
|
+
if (nextNode) {
|
|
1443
|
+
nextNode.#params = node.#params;
|
|
1444
|
+
if (isLast) {
|
|
1445
|
+
if (nextNode.#children["*"]) {
|
|
1446
|
+
handlerSets.push(...this.#getHandlerSets(nextNode.#children["*"], method, node.#params));
|
|
1447
|
+
}
|
|
1448
|
+
handlerSets.push(...this.#getHandlerSets(nextNode, method, node.#params));
|
|
1449
|
+
} else {
|
|
1450
|
+
tempNodes.push(nextNode);
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
for (let k = 0, len3 = node.#patterns.length;k < len3; k++) {
|
|
1454
|
+
const pattern = node.#patterns[k];
|
|
1455
|
+
const params = node.#params === emptyParams ? {} : { ...node.#params };
|
|
1456
|
+
if (pattern === "*") {
|
|
1457
|
+
const astNode = node.#children["*"];
|
|
1458
|
+
if (astNode) {
|
|
1459
|
+
handlerSets.push(...this.#getHandlerSets(astNode, method, node.#params));
|
|
1460
|
+
astNode.#params = params;
|
|
1461
|
+
tempNodes.push(astNode);
|
|
1462
|
+
}
|
|
1463
|
+
continue;
|
|
1464
|
+
}
|
|
1465
|
+
const [key, name, matcher] = pattern;
|
|
1466
|
+
if (!part && !(matcher instanceof RegExp)) {
|
|
1467
|
+
continue;
|
|
1468
|
+
}
|
|
1469
|
+
const child = node.#children[key];
|
|
1470
|
+
const restPathString = parts.slice(i).join("/");
|
|
1471
|
+
if (matcher instanceof RegExp) {
|
|
1472
|
+
const m = matcher.exec(restPathString);
|
|
1473
|
+
if (m) {
|
|
1474
|
+
params[name] = m[0];
|
|
1475
|
+
handlerSets.push(...this.#getHandlerSets(child, method, node.#params, params));
|
|
1476
|
+
if (Object.keys(child.#children).length) {
|
|
1477
|
+
child.#params = params;
|
|
1478
|
+
const componentCount = m[0].match(/\//)?.length ?? 0;
|
|
1479
|
+
const targetCurNodes = curNodesQueue[componentCount] ||= [];
|
|
1480
|
+
targetCurNodes.push(child);
|
|
1481
|
+
}
|
|
1482
|
+
continue;
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
if (matcher === true || matcher.test(part)) {
|
|
1486
|
+
params[name] = part;
|
|
1487
|
+
if (isLast) {
|
|
1488
|
+
handlerSets.push(...this.#getHandlerSets(child, method, params, node.#params));
|
|
1489
|
+
if (child.#children["*"]) {
|
|
1490
|
+
handlerSets.push(...this.#getHandlerSets(child.#children["*"], method, params, node.#params));
|
|
1491
|
+
}
|
|
1492
|
+
} else {
|
|
1493
|
+
child.#params = params;
|
|
1494
|
+
tempNodes.push(child);
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
curNodes = tempNodes.concat(curNodesQueue.shift() ?? []);
|
|
1500
|
+
}
|
|
1501
|
+
if (handlerSets.length > 1) {
|
|
1502
|
+
handlerSets.sort((a, b) => {
|
|
1503
|
+
return a.score - b.score;
|
|
1504
|
+
});
|
|
1505
|
+
}
|
|
1506
|
+
return [handlerSets.map(({ handler, params }) => [handler, params])];
|
|
1507
|
+
}
|
|
1508
|
+
};
|
|
1509
|
+
|
|
1510
|
+
// ../../node_modules/.bun/hono@4.11.4/node_modules/hono/dist/router/trie-router/router.js
|
|
1511
|
+
var TrieRouter = class {
|
|
1512
|
+
name = "TrieRouter";
|
|
1513
|
+
#node;
|
|
1514
|
+
constructor() {
|
|
1515
|
+
this.#node = new Node2;
|
|
1516
|
+
}
|
|
1517
|
+
add(method, path, handler) {
|
|
1518
|
+
const results = checkOptionalParameter(path);
|
|
1519
|
+
if (results) {
|
|
1520
|
+
for (let i = 0, len = results.length;i < len; i++) {
|
|
1521
|
+
this.#node.insert(method, results[i], handler);
|
|
1522
|
+
}
|
|
1523
|
+
return;
|
|
1524
|
+
}
|
|
1525
|
+
this.#node.insert(method, path, handler);
|
|
1526
|
+
}
|
|
1527
|
+
match(method, path) {
|
|
1528
|
+
return this.#node.search(method, path);
|
|
1529
|
+
}
|
|
1530
|
+
};
|
|
1531
|
+
|
|
1532
|
+
// ../../node_modules/.bun/hono@4.11.4/node_modules/hono/dist/hono.js
|
|
1533
|
+
var Hono2 = class extends Hono {
|
|
1534
|
+
constructor(options = {}) {
|
|
1535
|
+
super(options);
|
|
1536
|
+
this.router = options.router ?? new SmartRouter({
|
|
1537
|
+
routers: [new RegExpRouter, new TrieRouter]
|
|
1538
|
+
});
|
|
1539
|
+
}
|
|
1540
|
+
};
|
|
1541
|
+
|
|
1542
|
+
// ../../node_modules/.bun/hono@4.11.4/node_modules/hono/dist/middleware/cors/index.js
|
|
1543
|
+
var cors = (options) => {
|
|
1544
|
+
const defaults = {
|
|
1545
|
+
origin: "*",
|
|
1546
|
+
allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"],
|
|
1547
|
+
allowHeaders: [],
|
|
1548
|
+
exposeHeaders: []
|
|
1549
|
+
};
|
|
1550
|
+
const opts = {
|
|
1551
|
+
...defaults,
|
|
1552
|
+
...options
|
|
1553
|
+
};
|
|
1554
|
+
const findAllowOrigin = ((optsOrigin) => {
|
|
1555
|
+
if (typeof optsOrigin === "string") {
|
|
1556
|
+
if (optsOrigin === "*") {
|
|
1557
|
+
return () => optsOrigin;
|
|
1558
|
+
} else {
|
|
1559
|
+
return (origin) => optsOrigin === origin ? origin : null;
|
|
1560
|
+
}
|
|
1561
|
+
} else if (typeof optsOrigin === "function") {
|
|
1562
|
+
return optsOrigin;
|
|
1563
|
+
} else {
|
|
1564
|
+
return (origin) => optsOrigin.includes(origin) ? origin : null;
|
|
1565
|
+
}
|
|
1566
|
+
})(opts.origin);
|
|
1567
|
+
const findAllowMethods = ((optsAllowMethods) => {
|
|
1568
|
+
if (typeof optsAllowMethods === "function") {
|
|
1569
|
+
return optsAllowMethods;
|
|
1570
|
+
} else if (Array.isArray(optsAllowMethods)) {
|
|
1571
|
+
return () => optsAllowMethods;
|
|
1572
|
+
} else {
|
|
1573
|
+
return () => [];
|
|
1574
|
+
}
|
|
1575
|
+
})(opts.allowMethods);
|
|
1576
|
+
return async function cors2(c, next) {
|
|
1577
|
+
function set(key, value) {
|
|
1578
|
+
c.res.headers.set(key, value);
|
|
1579
|
+
}
|
|
1580
|
+
const allowOrigin = await findAllowOrigin(c.req.header("origin") || "", c);
|
|
1581
|
+
if (allowOrigin) {
|
|
1582
|
+
set("Access-Control-Allow-Origin", allowOrigin);
|
|
1583
|
+
}
|
|
1584
|
+
if (opts.credentials) {
|
|
1585
|
+
set("Access-Control-Allow-Credentials", "true");
|
|
1586
|
+
}
|
|
1587
|
+
if (opts.exposeHeaders?.length) {
|
|
1588
|
+
set("Access-Control-Expose-Headers", opts.exposeHeaders.join(","));
|
|
1589
|
+
}
|
|
1590
|
+
if (c.req.method === "OPTIONS") {
|
|
1591
|
+
if (opts.origin !== "*") {
|
|
1592
|
+
set("Vary", "Origin");
|
|
1593
|
+
}
|
|
1594
|
+
if (opts.maxAge != null) {
|
|
1595
|
+
set("Access-Control-Max-Age", opts.maxAge.toString());
|
|
1596
|
+
}
|
|
1597
|
+
const allowMethods = await findAllowMethods(c.req.header("origin") || "", c);
|
|
1598
|
+
if (allowMethods.length) {
|
|
1599
|
+
set("Access-Control-Allow-Methods", allowMethods.join(","));
|
|
1600
|
+
}
|
|
1601
|
+
let headers = opts.allowHeaders;
|
|
1602
|
+
if (!headers?.length) {
|
|
1603
|
+
const requestHeaders = c.req.header("Access-Control-Request-Headers");
|
|
1604
|
+
if (requestHeaders) {
|
|
1605
|
+
headers = requestHeaders.split(/\s*,\s*/);
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
if (headers?.length) {
|
|
1609
|
+
set("Access-Control-Allow-Headers", headers.join(","));
|
|
1610
|
+
c.res.headers.append("Vary", "Access-Control-Request-Headers");
|
|
1611
|
+
}
|
|
1612
|
+
c.res.headers.delete("Content-Length");
|
|
1613
|
+
c.res.headers.delete("Content-Type");
|
|
1614
|
+
return new Response(null, {
|
|
1615
|
+
headers: c.res.headers,
|
|
1616
|
+
status: 204,
|
|
1617
|
+
statusText: "No Content"
|
|
1618
|
+
});
|
|
1619
|
+
}
|
|
1620
|
+
await next();
|
|
1621
|
+
if (opts.origin !== "*") {
|
|
1622
|
+
c.header("Vary", "Origin", { append: true });
|
|
1623
|
+
}
|
|
1624
|
+
};
|
|
1625
|
+
};
|
|
1626
|
+
|
|
1627
|
+
// ../../node_modules/.bun/hono@4.11.4/node_modules/hono/dist/middleware/secure-headers/secure-headers.js
|
|
1628
|
+
var HEADERS_MAP = {
|
|
1629
|
+
crossOriginEmbedderPolicy: ["Cross-Origin-Embedder-Policy", "require-corp"],
|
|
1630
|
+
crossOriginResourcePolicy: ["Cross-Origin-Resource-Policy", "same-origin"],
|
|
1631
|
+
crossOriginOpenerPolicy: ["Cross-Origin-Opener-Policy", "same-origin"],
|
|
1632
|
+
originAgentCluster: ["Origin-Agent-Cluster", "?1"],
|
|
1633
|
+
referrerPolicy: ["Referrer-Policy", "no-referrer"],
|
|
1634
|
+
strictTransportSecurity: ["Strict-Transport-Security", "max-age=15552000; includeSubDomains"],
|
|
1635
|
+
xContentTypeOptions: ["X-Content-Type-Options", "nosniff"],
|
|
1636
|
+
xDnsPrefetchControl: ["X-DNS-Prefetch-Control", "off"],
|
|
1637
|
+
xDownloadOptions: ["X-Download-Options", "noopen"],
|
|
1638
|
+
xFrameOptions: ["X-Frame-Options", "SAMEORIGIN"],
|
|
1639
|
+
xPermittedCrossDomainPolicies: ["X-Permitted-Cross-Domain-Policies", "none"],
|
|
1640
|
+
xXssProtection: ["X-XSS-Protection", "0"]
|
|
1641
|
+
};
|
|
1642
|
+
var DEFAULT_OPTIONS = {
|
|
1643
|
+
crossOriginEmbedderPolicy: false,
|
|
1644
|
+
crossOriginResourcePolicy: true,
|
|
1645
|
+
crossOriginOpenerPolicy: true,
|
|
1646
|
+
originAgentCluster: true,
|
|
1647
|
+
referrerPolicy: true,
|
|
1648
|
+
strictTransportSecurity: true,
|
|
1649
|
+
xContentTypeOptions: true,
|
|
1650
|
+
xDnsPrefetchControl: true,
|
|
1651
|
+
xDownloadOptions: true,
|
|
1652
|
+
xFrameOptions: true,
|
|
1653
|
+
xPermittedCrossDomainPolicies: true,
|
|
1654
|
+
xXssProtection: true,
|
|
1655
|
+
removePoweredBy: true,
|
|
1656
|
+
permissionsPolicy: {}
|
|
1657
|
+
};
|
|
1658
|
+
var secureHeaders = (customOptions) => {
|
|
1659
|
+
const options = { ...DEFAULT_OPTIONS, ...customOptions };
|
|
1660
|
+
const headersToSet = getFilteredHeaders(options);
|
|
1661
|
+
const callbacks = [];
|
|
1662
|
+
if (options.contentSecurityPolicy) {
|
|
1663
|
+
const [callback, value] = getCSPDirectives(options.contentSecurityPolicy);
|
|
1664
|
+
if (callback) {
|
|
1665
|
+
callbacks.push(callback);
|
|
1666
|
+
}
|
|
1667
|
+
headersToSet.push(["Content-Security-Policy", value]);
|
|
1668
|
+
}
|
|
1669
|
+
if (options.contentSecurityPolicyReportOnly) {
|
|
1670
|
+
const [callback, value] = getCSPDirectives(options.contentSecurityPolicyReportOnly);
|
|
1671
|
+
if (callback) {
|
|
1672
|
+
callbacks.push(callback);
|
|
1673
|
+
}
|
|
1674
|
+
headersToSet.push(["Content-Security-Policy-Report-Only", value]);
|
|
1675
|
+
}
|
|
1676
|
+
if (options.permissionsPolicy && Object.keys(options.permissionsPolicy).length > 0) {
|
|
1677
|
+
headersToSet.push([
|
|
1678
|
+
"Permissions-Policy",
|
|
1679
|
+
getPermissionsPolicyDirectives(options.permissionsPolicy)
|
|
1680
|
+
]);
|
|
1681
|
+
}
|
|
1682
|
+
if (options.reportingEndpoints) {
|
|
1683
|
+
headersToSet.push(["Reporting-Endpoints", getReportingEndpoints(options.reportingEndpoints)]);
|
|
1684
|
+
}
|
|
1685
|
+
if (options.reportTo) {
|
|
1686
|
+
headersToSet.push(["Report-To", getReportToOptions(options.reportTo)]);
|
|
1687
|
+
}
|
|
1688
|
+
return async function secureHeaders2(ctx, next) {
|
|
1689
|
+
const headersToSetForReq = callbacks.length === 0 ? headersToSet : callbacks.reduce((acc, cb) => cb(ctx, acc), headersToSet);
|
|
1690
|
+
await next();
|
|
1691
|
+
setHeaders(ctx, headersToSetForReq);
|
|
1692
|
+
if (options?.removePoweredBy) {
|
|
1693
|
+
ctx.res.headers.delete("X-Powered-By");
|
|
1694
|
+
}
|
|
1695
|
+
};
|
|
1696
|
+
};
|
|
1697
|
+
function getFilteredHeaders(options) {
|
|
1698
|
+
return Object.entries(HEADERS_MAP).filter(([key]) => options[key]).map(([key, defaultValue]) => {
|
|
1699
|
+
const overrideValue = options[key];
|
|
1700
|
+
return typeof overrideValue === "string" ? [defaultValue[0], overrideValue] : defaultValue;
|
|
1701
|
+
});
|
|
1702
|
+
}
|
|
1703
|
+
function getCSPDirectives(contentSecurityPolicy) {
|
|
1704
|
+
const callbacks = [];
|
|
1705
|
+
const resultValues = [];
|
|
1706
|
+
for (const [directive, value] of Object.entries(contentSecurityPolicy)) {
|
|
1707
|
+
const valueArray = Array.isArray(value) ? value : [value];
|
|
1708
|
+
valueArray.forEach((value2, i) => {
|
|
1709
|
+
if (typeof value2 === "function") {
|
|
1710
|
+
const index = i * 2 + 2 + resultValues.length;
|
|
1711
|
+
callbacks.push((ctx, values) => {
|
|
1712
|
+
values[index] = value2(ctx, directive);
|
|
1713
|
+
});
|
|
1714
|
+
}
|
|
1715
|
+
});
|
|
1716
|
+
resultValues.push(directive.replace(/[A-Z]+(?![a-z])|[A-Z]/g, (match2, offset) => offset ? "-" + match2.toLowerCase() : match2.toLowerCase()), ...valueArray.flatMap((value2) => [" ", value2]), "; ");
|
|
1717
|
+
}
|
|
1718
|
+
resultValues.pop();
|
|
1719
|
+
return callbacks.length === 0 ? [undefined, resultValues.join("")] : [
|
|
1720
|
+
(ctx, headersToSet) => headersToSet.map((values) => {
|
|
1721
|
+
if (values[0] === "Content-Security-Policy" || values[0] === "Content-Security-Policy-Report-Only") {
|
|
1722
|
+
const clone = values[1].slice();
|
|
1723
|
+
callbacks.forEach((cb) => {
|
|
1724
|
+
cb(ctx, clone);
|
|
1725
|
+
});
|
|
1726
|
+
return [values[0], clone.join("")];
|
|
1727
|
+
} else {
|
|
1728
|
+
return values;
|
|
1729
|
+
}
|
|
1730
|
+
}),
|
|
1731
|
+
resultValues
|
|
1732
|
+
];
|
|
1733
|
+
}
|
|
1734
|
+
function getPermissionsPolicyDirectives(policy) {
|
|
1735
|
+
return Object.entries(policy).map(([directive, value]) => {
|
|
1736
|
+
const kebabDirective = camelToKebab(directive);
|
|
1737
|
+
if (typeof value === "boolean") {
|
|
1738
|
+
return `${kebabDirective}=${value ? "*" : "none"}`;
|
|
1739
|
+
}
|
|
1740
|
+
if (Array.isArray(value)) {
|
|
1741
|
+
if (value.length === 0) {
|
|
1742
|
+
return `${kebabDirective}=()`;
|
|
1743
|
+
}
|
|
1744
|
+
if (value.length === 1 && (value[0] === "*" || value[0] === "none")) {
|
|
1745
|
+
return `${kebabDirective}=${value[0]}`;
|
|
1746
|
+
}
|
|
1747
|
+
const allowlist = value.map((item) => ["self", "src"].includes(item) ? item : `"${item}"`);
|
|
1748
|
+
return `${kebabDirective}=(${allowlist.join(" ")})`;
|
|
1749
|
+
}
|
|
1750
|
+
return "";
|
|
1751
|
+
}).filter(Boolean).join(", ");
|
|
1752
|
+
}
|
|
1753
|
+
function camelToKebab(str) {
|
|
1754
|
+
return str.replace(/([a-z\d])([A-Z])/g, "$1-$2").toLowerCase();
|
|
1755
|
+
}
|
|
1756
|
+
function getReportingEndpoints(reportingEndpoints = []) {
|
|
1757
|
+
return reportingEndpoints.map((endpoint) => `${endpoint.name}="${endpoint.url}"`).join(", ");
|
|
1758
|
+
}
|
|
1759
|
+
function getReportToOptions(reportTo = []) {
|
|
1760
|
+
return reportTo.map((option) => JSON.stringify(option)).join(", ");
|
|
1761
|
+
}
|
|
1762
|
+
function setHeaders(ctx, headersToSet) {
|
|
1763
|
+
headersToSet.forEach(([header, value]) => {
|
|
1764
|
+
ctx.res.headers.set(header, value);
|
|
1765
|
+
});
|
|
1766
|
+
}
|
|
1767
|
+
|
|
1768
|
+
// ../../node_modules/.bun/hono@4.11.4/node_modules/hono/dist/utils/color.js
|
|
1769
|
+
function getColorEnabled() {
|
|
1770
|
+
const { process, Deno } = globalThis;
|
|
1771
|
+
const isNoColor = typeof Deno?.noColor === "boolean" ? Deno.noColor : process !== undefined ? "NO_COLOR" in process?.env : false;
|
|
1772
|
+
return !isNoColor;
|
|
1773
|
+
}
|
|
1774
|
+
async function getColorEnabledAsync() {
|
|
1775
|
+
const { navigator } = globalThis;
|
|
1776
|
+
const cfWorkers = "cloudflare:workers";
|
|
1777
|
+
const isNoColor = navigator !== undefined && navigator.userAgent === "Cloudflare-Workers" ? await (async () => {
|
|
1778
|
+
try {
|
|
1779
|
+
return "NO_COLOR" in ((await import(cfWorkers)).env ?? {});
|
|
1780
|
+
} catch {
|
|
1781
|
+
return false;
|
|
1782
|
+
}
|
|
1783
|
+
})() : !getColorEnabled();
|
|
1784
|
+
return !isNoColor;
|
|
1785
|
+
}
|
|
1786
|
+
|
|
1787
|
+
// ../../node_modules/.bun/hono@4.11.4/node_modules/hono/dist/middleware/logger/index.js
|
|
1788
|
+
var humanize = (times) => {
|
|
1789
|
+
const [delimiter, separator] = [",", "."];
|
|
1790
|
+
const orderTimes = times.map((v) => v.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1" + delimiter));
|
|
1791
|
+
return orderTimes.join(separator);
|
|
1792
|
+
};
|
|
1793
|
+
var time = (start) => {
|
|
1794
|
+
const delta = Date.now() - start;
|
|
1795
|
+
return humanize([delta < 1000 ? delta + "ms" : Math.round(delta / 1000) + "s"]);
|
|
1796
|
+
};
|
|
1797
|
+
var colorStatus = async (status) => {
|
|
1798
|
+
const colorEnabled = await getColorEnabledAsync();
|
|
1799
|
+
if (colorEnabled) {
|
|
1800
|
+
switch (status / 100 | 0) {
|
|
1801
|
+
case 5:
|
|
1802
|
+
return `\x1B[31m${status}\x1B[0m`;
|
|
1803
|
+
case 4:
|
|
1804
|
+
return `\x1B[33m${status}\x1B[0m`;
|
|
1805
|
+
case 3:
|
|
1806
|
+
return `\x1B[36m${status}\x1B[0m`;
|
|
1807
|
+
case 2:
|
|
1808
|
+
return `\x1B[32m${status}\x1B[0m`;
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
return `${status}`;
|
|
1812
|
+
};
|
|
1813
|
+
async function log(fn, prefix, method, path, status = 0, elapsed) {
|
|
1814
|
+
const out = prefix === "<--" ? `${prefix} ${method} ${path}` : `${prefix} ${method} ${path} ${await colorStatus(status)} ${elapsed}`;
|
|
1815
|
+
fn(out);
|
|
1816
|
+
}
|
|
1817
|
+
var logger = (fn = console.log) => {
|
|
1818
|
+
return async function logger2(c, next) {
|
|
1819
|
+
const { method, url } = c.req;
|
|
1820
|
+
const path = url.slice(url.indexOf("/", 8));
|
|
1821
|
+
await log(fn, "<--", method, path);
|
|
1822
|
+
const start = Date.now();
|
|
1823
|
+
await next();
|
|
1824
|
+
await log(fn, "-->", method, path, c.res.status, time(start));
|
|
1825
|
+
};
|
|
1826
|
+
};
|
|
1827
|
+
|
|
1828
|
+
// ../core/dist/index.js
|
|
1829
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
1830
|
+
var __create = Object.create;
|
|
1831
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
1832
|
+
var __defProp = Object.defineProperty;
|
|
1833
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
1834
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
1835
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
1836
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
1837
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
1838
|
+
for (let key of __getOwnPropNames(mod))
|
|
1839
|
+
if (!__hasOwnProp.call(to, key))
|
|
1840
|
+
__defProp(to, key, {
|
|
1841
|
+
get: () => mod[key],
|
|
1842
|
+
enumerable: true
|
|
1843
|
+
});
|
|
1844
|
+
return to;
|
|
1845
|
+
};
|
|
1846
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
1847
|
+
var require_Reflect = __commonJS(() => {
|
|
1848
|
+
/*! *****************************************************************************
|
|
1849
|
+
Copyright (C) Microsoft. All rights reserved.
|
|
1850
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
1851
|
+
this file except in compliance with the License. You may obtain a copy of the
|
|
1852
|
+
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
1853
|
+
|
|
1854
|
+
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
1855
|
+
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
1856
|
+
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
1857
|
+
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
1858
|
+
|
|
1859
|
+
See the Apache Version 2.0 License for specific language governing permissions
|
|
1860
|
+
and limitations under the License.
|
|
1861
|
+
***************************************************************************** */
|
|
1862
|
+
var Reflect2;
|
|
1863
|
+
(function(Reflect3) {
|
|
1864
|
+
(function(factory) {
|
|
1865
|
+
var root = typeof globalThis === "object" ? globalThis : typeof global === "object" ? global : typeof self === "object" ? self : typeof this === "object" ? this : sloppyModeThis();
|
|
1866
|
+
var exporter = makeExporter(Reflect3);
|
|
1867
|
+
if (typeof root.Reflect !== "undefined") {
|
|
1868
|
+
exporter = makeExporter(root.Reflect, exporter);
|
|
1869
|
+
}
|
|
1870
|
+
factory(exporter, root);
|
|
1871
|
+
if (typeof root.Reflect === "undefined") {
|
|
1872
|
+
root.Reflect = Reflect3;
|
|
1873
|
+
}
|
|
1874
|
+
function makeExporter(target, previous) {
|
|
1875
|
+
return function(key, value) {
|
|
1876
|
+
Object.defineProperty(target, key, { configurable: true, writable: true, value });
|
|
1877
|
+
if (previous)
|
|
1878
|
+
previous(key, value);
|
|
1879
|
+
};
|
|
1880
|
+
}
|
|
1881
|
+
function functionThis() {
|
|
1882
|
+
try {
|
|
1883
|
+
return Function("return this;")();
|
|
1884
|
+
} catch (_) {}
|
|
1885
|
+
}
|
|
1886
|
+
function indirectEvalThis() {
|
|
1887
|
+
try {
|
|
1888
|
+
return (undefined, eval)("(function() { return this; })()");
|
|
1889
|
+
} catch (_) {}
|
|
1890
|
+
}
|
|
1891
|
+
function sloppyModeThis() {
|
|
1892
|
+
return functionThis() || indirectEvalThis();
|
|
1893
|
+
}
|
|
1894
|
+
})(function(exporter, root) {
|
|
1895
|
+
var hasOwn = Object.prototype.hasOwnProperty;
|
|
1896
|
+
var supportsSymbol = typeof Symbol === "function";
|
|
1897
|
+
var toPrimitiveSymbol = supportsSymbol && typeof Symbol.toPrimitive !== "undefined" ? Symbol.toPrimitive : "@@toPrimitive";
|
|
1898
|
+
var iteratorSymbol = supportsSymbol && typeof Symbol.iterator !== "undefined" ? Symbol.iterator : "@@iterator";
|
|
1899
|
+
var supportsCreate = typeof Object.create === "function";
|
|
1900
|
+
var supportsProto = { __proto__: [] } instanceof Array;
|
|
1901
|
+
var downLevel = !supportsCreate && !supportsProto;
|
|
1902
|
+
var HashMap = {
|
|
1903
|
+
create: supportsCreate ? function() {
|
|
1904
|
+
return MakeDictionary(Object.create(null));
|
|
1905
|
+
} : supportsProto ? function() {
|
|
1906
|
+
return MakeDictionary({ __proto__: null });
|
|
1907
|
+
} : function() {
|
|
1908
|
+
return MakeDictionary({});
|
|
1909
|
+
},
|
|
1910
|
+
has: downLevel ? function(map, key) {
|
|
1911
|
+
return hasOwn.call(map, key);
|
|
1912
|
+
} : function(map, key) {
|
|
1913
|
+
return key in map;
|
|
1914
|
+
},
|
|
1915
|
+
get: downLevel ? function(map, key) {
|
|
1916
|
+
return hasOwn.call(map, key) ? map[key] : undefined;
|
|
1917
|
+
} : function(map, key) {
|
|
1918
|
+
return map[key];
|
|
1919
|
+
}
|
|
1920
|
+
};
|
|
1921
|
+
var functionPrototype = Object.getPrototypeOf(Function);
|
|
1922
|
+
var _Map = typeof Map === "function" && typeof Map.prototype.entries === "function" ? Map : CreateMapPolyfill();
|
|
1923
|
+
var _Set = typeof Set === "function" && typeof Set.prototype.entries === "function" ? Set : CreateSetPolyfill();
|
|
1924
|
+
var _WeakMap = typeof WeakMap === "function" ? WeakMap : CreateWeakMapPolyfill();
|
|
1925
|
+
var registrySymbol = supportsSymbol ? Symbol.for("@reflect-metadata:registry") : undefined;
|
|
1926
|
+
var metadataRegistry = GetOrCreateMetadataRegistry();
|
|
1927
|
+
var metadataProvider = CreateMetadataProvider(metadataRegistry);
|
|
1928
|
+
function decorate(decorators, target, propertyKey, attributes) {
|
|
1929
|
+
if (!IsUndefined(propertyKey)) {
|
|
1930
|
+
if (!IsArray(decorators))
|
|
1931
|
+
throw new TypeError;
|
|
1932
|
+
if (!IsObject(target))
|
|
1933
|
+
throw new TypeError;
|
|
1934
|
+
if (!IsObject(attributes) && !IsUndefined(attributes) && !IsNull(attributes))
|
|
1935
|
+
throw new TypeError;
|
|
1936
|
+
if (IsNull(attributes))
|
|
1937
|
+
attributes = undefined;
|
|
1938
|
+
propertyKey = ToPropertyKey(propertyKey);
|
|
1939
|
+
return DecorateProperty(decorators, target, propertyKey, attributes);
|
|
1940
|
+
} else {
|
|
1941
|
+
if (!IsArray(decorators))
|
|
1942
|
+
throw new TypeError;
|
|
1943
|
+
if (!IsConstructor(target))
|
|
1944
|
+
throw new TypeError;
|
|
1945
|
+
return DecorateConstructor(decorators, target);
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
exporter("decorate", decorate);
|
|
1949
|
+
function metadata(metadataKey, metadataValue) {
|
|
1950
|
+
function decorator(target, propertyKey) {
|
|
1951
|
+
if (!IsObject(target))
|
|
1952
|
+
throw new TypeError;
|
|
1953
|
+
if (!IsUndefined(propertyKey) && !IsPropertyKey(propertyKey))
|
|
1954
|
+
throw new TypeError;
|
|
1955
|
+
OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, propertyKey);
|
|
1956
|
+
}
|
|
1957
|
+
return decorator;
|
|
1958
|
+
}
|
|
1959
|
+
exporter("metadata", metadata);
|
|
1960
|
+
function defineMetadata(metadataKey, metadataValue, target, propertyKey) {
|
|
1961
|
+
if (!IsObject(target))
|
|
1962
|
+
throw new TypeError;
|
|
1963
|
+
if (!IsUndefined(propertyKey))
|
|
1964
|
+
propertyKey = ToPropertyKey(propertyKey);
|
|
1965
|
+
return OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, propertyKey);
|
|
1966
|
+
}
|
|
1967
|
+
exporter("defineMetadata", defineMetadata);
|
|
1968
|
+
function hasMetadata(metadataKey, target, propertyKey) {
|
|
1969
|
+
if (!IsObject(target))
|
|
1970
|
+
throw new TypeError;
|
|
1971
|
+
if (!IsUndefined(propertyKey))
|
|
1972
|
+
propertyKey = ToPropertyKey(propertyKey);
|
|
1973
|
+
return OrdinaryHasMetadata(metadataKey, target, propertyKey);
|
|
1974
|
+
}
|
|
1975
|
+
exporter("hasMetadata", hasMetadata);
|
|
1976
|
+
function hasOwnMetadata(metadataKey, target, propertyKey) {
|
|
1977
|
+
if (!IsObject(target))
|
|
1978
|
+
throw new TypeError;
|
|
1979
|
+
if (!IsUndefined(propertyKey))
|
|
1980
|
+
propertyKey = ToPropertyKey(propertyKey);
|
|
1981
|
+
return OrdinaryHasOwnMetadata(metadataKey, target, propertyKey);
|
|
1982
|
+
}
|
|
1983
|
+
exporter("hasOwnMetadata", hasOwnMetadata);
|
|
1984
|
+
function getMetadata(metadataKey, target, propertyKey) {
|
|
1985
|
+
if (!IsObject(target))
|
|
1986
|
+
throw new TypeError;
|
|
1987
|
+
if (!IsUndefined(propertyKey))
|
|
1988
|
+
propertyKey = ToPropertyKey(propertyKey);
|
|
1989
|
+
return OrdinaryGetMetadata(metadataKey, target, propertyKey);
|
|
1990
|
+
}
|
|
1991
|
+
exporter("getMetadata", getMetadata);
|
|
1992
|
+
function getOwnMetadata(metadataKey, target, propertyKey) {
|
|
1993
|
+
if (!IsObject(target))
|
|
1994
|
+
throw new TypeError;
|
|
1995
|
+
if (!IsUndefined(propertyKey))
|
|
1996
|
+
propertyKey = ToPropertyKey(propertyKey);
|
|
1997
|
+
return OrdinaryGetOwnMetadata(metadataKey, target, propertyKey);
|
|
1998
|
+
}
|
|
1999
|
+
exporter("getOwnMetadata", getOwnMetadata);
|
|
2000
|
+
function getMetadataKeys(target, propertyKey) {
|
|
2001
|
+
if (!IsObject(target))
|
|
2002
|
+
throw new TypeError;
|
|
2003
|
+
if (!IsUndefined(propertyKey))
|
|
2004
|
+
propertyKey = ToPropertyKey(propertyKey);
|
|
2005
|
+
return OrdinaryMetadataKeys(target, propertyKey);
|
|
2006
|
+
}
|
|
2007
|
+
exporter("getMetadataKeys", getMetadataKeys);
|
|
2008
|
+
function getOwnMetadataKeys(target, propertyKey) {
|
|
2009
|
+
if (!IsObject(target))
|
|
2010
|
+
throw new TypeError;
|
|
2011
|
+
if (!IsUndefined(propertyKey))
|
|
2012
|
+
propertyKey = ToPropertyKey(propertyKey);
|
|
2013
|
+
return OrdinaryOwnMetadataKeys(target, propertyKey);
|
|
2014
|
+
}
|
|
2015
|
+
exporter("getOwnMetadataKeys", getOwnMetadataKeys);
|
|
2016
|
+
function deleteMetadata(metadataKey, target, propertyKey) {
|
|
2017
|
+
if (!IsObject(target))
|
|
2018
|
+
throw new TypeError;
|
|
2019
|
+
if (!IsUndefined(propertyKey))
|
|
2020
|
+
propertyKey = ToPropertyKey(propertyKey);
|
|
2021
|
+
if (!IsObject(target))
|
|
2022
|
+
throw new TypeError;
|
|
2023
|
+
if (!IsUndefined(propertyKey))
|
|
2024
|
+
propertyKey = ToPropertyKey(propertyKey);
|
|
2025
|
+
var provider = GetMetadataProvider(target, propertyKey, false);
|
|
2026
|
+
if (IsUndefined(provider))
|
|
2027
|
+
return false;
|
|
2028
|
+
return provider.OrdinaryDeleteMetadata(metadataKey, target, propertyKey);
|
|
2029
|
+
}
|
|
2030
|
+
exporter("deleteMetadata", deleteMetadata);
|
|
2031
|
+
function DecorateConstructor(decorators, target) {
|
|
2032
|
+
for (var i = decorators.length - 1;i >= 0; --i) {
|
|
2033
|
+
var decorator = decorators[i];
|
|
2034
|
+
var decorated = decorator(target);
|
|
2035
|
+
if (!IsUndefined(decorated) && !IsNull(decorated)) {
|
|
2036
|
+
if (!IsConstructor(decorated))
|
|
2037
|
+
throw new TypeError;
|
|
2038
|
+
target = decorated;
|
|
2039
|
+
}
|
|
2040
|
+
}
|
|
2041
|
+
return target;
|
|
2042
|
+
}
|
|
2043
|
+
function DecorateProperty(decorators, target, propertyKey, descriptor) {
|
|
2044
|
+
for (var i = decorators.length - 1;i >= 0; --i) {
|
|
2045
|
+
var decorator = decorators[i];
|
|
2046
|
+
var decorated = decorator(target, propertyKey, descriptor);
|
|
2047
|
+
if (!IsUndefined(decorated) && !IsNull(decorated)) {
|
|
2048
|
+
if (!IsObject(decorated))
|
|
2049
|
+
throw new TypeError;
|
|
2050
|
+
descriptor = decorated;
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
return descriptor;
|
|
2054
|
+
}
|
|
2055
|
+
function OrdinaryHasMetadata(MetadataKey, O, P) {
|
|
2056
|
+
var hasOwn2 = OrdinaryHasOwnMetadata(MetadataKey, O, P);
|
|
2057
|
+
if (hasOwn2)
|
|
2058
|
+
return true;
|
|
2059
|
+
var parent = OrdinaryGetPrototypeOf(O);
|
|
2060
|
+
if (!IsNull(parent))
|
|
2061
|
+
return OrdinaryHasMetadata(MetadataKey, parent, P);
|
|
2062
|
+
return false;
|
|
2063
|
+
}
|
|
2064
|
+
function OrdinaryHasOwnMetadata(MetadataKey, O, P) {
|
|
2065
|
+
var provider = GetMetadataProvider(O, P, false);
|
|
2066
|
+
if (IsUndefined(provider))
|
|
2067
|
+
return false;
|
|
2068
|
+
return ToBoolean(provider.OrdinaryHasOwnMetadata(MetadataKey, O, P));
|
|
2069
|
+
}
|
|
2070
|
+
function OrdinaryGetMetadata(MetadataKey, O, P) {
|
|
2071
|
+
var hasOwn2 = OrdinaryHasOwnMetadata(MetadataKey, O, P);
|
|
2072
|
+
if (hasOwn2)
|
|
2073
|
+
return OrdinaryGetOwnMetadata(MetadataKey, O, P);
|
|
2074
|
+
var parent = OrdinaryGetPrototypeOf(O);
|
|
2075
|
+
if (!IsNull(parent))
|
|
2076
|
+
return OrdinaryGetMetadata(MetadataKey, parent, P);
|
|
2077
|
+
return;
|
|
2078
|
+
}
|
|
2079
|
+
function OrdinaryGetOwnMetadata(MetadataKey, O, P) {
|
|
2080
|
+
var provider = GetMetadataProvider(O, P, false);
|
|
2081
|
+
if (IsUndefined(provider))
|
|
2082
|
+
return;
|
|
2083
|
+
return provider.OrdinaryGetOwnMetadata(MetadataKey, O, P);
|
|
2084
|
+
}
|
|
2085
|
+
function OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P) {
|
|
2086
|
+
var provider = GetMetadataProvider(O, P, true);
|
|
2087
|
+
provider.OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P);
|
|
2088
|
+
}
|
|
2089
|
+
function OrdinaryMetadataKeys(O, P) {
|
|
2090
|
+
var ownKeys = OrdinaryOwnMetadataKeys(O, P);
|
|
2091
|
+
var parent = OrdinaryGetPrototypeOf(O);
|
|
2092
|
+
if (parent === null)
|
|
2093
|
+
return ownKeys;
|
|
2094
|
+
var parentKeys = OrdinaryMetadataKeys(parent, P);
|
|
2095
|
+
if (parentKeys.length <= 0)
|
|
2096
|
+
return ownKeys;
|
|
2097
|
+
if (ownKeys.length <= 0)
|
|
2098
|
+
return parentKeys;
|
|
2099
|
+
var set = new _Set;
|
|
2100
|
+
var keys = [];
|
|
2101
|
+
for (var _i = 0, ownKeys_1 = ownKeys;_i < ownKeys_1.length; _i++) {
|
|
2102
|
+
var key = ownKeys_1[_i];
|
|
2103
|
+
var hasKey = set.has(key);
|
|
2104
|
+
if (!hasKey) {
|
|
2105
|
+
set.add(key);
|
|
2106
|
+
keys.push(key);
|
|
2107
|
+
}
|
|
2108
|
+
}
|
|
2109
|
+
for (var _a = 0, parentKeys_1 = parentKeys;_a < parentKeys_1.length; _a++) {
|
|
2110
|
+
var key = parentKeys_1[_a];
|
|
2111
|
+
var hasKey = set.has(key);
|
|
2112
|
+
if (!hasKey) {
|
|
2113
|
+
set.add(key);
|
|
2114
|
+
keys.push(key);
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
return keys;
|
|
2118
|
+
}
|
|
2119
|
+
function OrdinaryOwnMetadataKeys(O, P) {
|
|
2120
|
+
var provider = GetMetadataProvider(O, P, false);
|
|
2121
|
+
if (!provider) {
|
|
2122
|
+
return [];
|
|
2123
|
+
}
|
|
2124
|
+
return provider.OrdinaryOwnMetadataKeys(O, P);
|
|
2125
|
+
}
|
|
2126
|
+
function Type(x) {
|
|
2127
|
+
if (x === null)
|
|
2128
|
+
return 1;
|
|
2129
|
+
switch (typeof x) {
|
|
2130
|
+
case "undefined":
|
|
2131
|
+
return 0;
|
|
2132
|
+
case "boolean":
|
|
2133
|
+
return 2;
|
|
2134
|
+
case "string":
|
|
2135
|
+
return 3;
|
|
2136
|
+
case "symbol":
|
|
2137
|
+
return 4;
|
|
2138
|
+
case "number":
|
|
2139
|
+
return 5;
|
|
2140
|
+
case "object":
|
|
2141
|
+
return x === null ? 1 : 6;
|
|
2142
|
+
default:
|
|
2143
|
+
return 6;
|
|
2144
|
+
}
|
|
2145
|
+
}
|
|
2146
|
+
function IsUndefined(x) {
|
|
2147
|
+
return x === undefined;
|
|
2148
|
+
}
|
|
2149
|
+
function IsNull(x) {
|
|
2150
|
+
return x === null;
|
|
2151
|
+
}
|
|
2152
|
+
function IsSymbol(x) {
|
|
2153
|
+
return typeof x === "symbol";
|
|
2154
|
+
}
|
|
2155
|
+
function IsObject(x) {
|
|
2156
|
+
return typeof x === "object" ? x !== null : typeof x === "function";
|
|
2157
|
+
}
|
|
2158
|
+
function ToPrimitive(input, PreferredType) {
|
|
2159
|
+
switch (Type(input)) {
|
|
2160
|
+
case 0:
|
|
2161
|
+
return input;
|
|
2162
|
+
case 1:
|
|
2163
|
+
return input;
|
|
2164
|
+
case 2:
|
|
2165
|
+
return input;
|
|
2166
|
+
case 3:
|
|
2167
|
+
return input;
|
|
2168
|
+
case 4:
|
|
2169
|
+
return input;
|
|
2170
|
+
case 5:
|
|
2171
|
+
return input;
|
|
2172
|
+
}
|
|
2173
|
+
var hint = PreferredType === 3 ? "string" : PreferredType === 5 ? "number" : "default";
|
|
2174
|
+
var exoticToPrim = GetMethod(input, toPrimitiveSymbol);
|
|
2175
|
+
if (exoticToPrim !== undefined) {
|
|
2176
|
+
var result = exoticToPrim.call(input, hint);
|
|
2177
|
+
if (IsObject(result))
|
|
2178
|
+
throw new TypeError;
|
|
2179
|
+
return result;
|
|
2180
|
+
}
|
|
2181
|
+
return OrdinaryToPrimitive(input, hint === "default" ? "number" : hint);
|
|
2182
|
+
}
|
|
2183
|
+
function OrdinaryToPrimitive(O, hint) {
|
|
2184
|
+
if (hint === "string") {
|
|
2185
|
+
var toString_1 = O.toString;
|
|
2186
|
+
if (IsCallable(toString_1)) {
|
|
2187
|
+
var result = toString_1.call(O);
|
|
2188
|
+
if (!IsObject(result))
|
|
2189
|
+
return result;
|
|
2190
|
+
}
|
|
2191
|
+
var valueOf = O.valueOf;
|
|
2192
|
+
if (IsCallable(valueOf)) {
|
|
2193
|
+
var result = valueOf.call(O);
|
|
2194
|
+
if (!IsObject(result))
|
|
2195
|
+
return result;
|
|
2196
|
+
}
|
|
2197
|
+
} else {
|
|
2198
|
+
var valueOf = O.valueOf;
|
|
2199
|
+
if (IsCallable(valueOf)) {
|
|
2200
|
+
var result = valueOf.call(O);
|
|
2201
|
+
if (!IsObject(result))
|
|
2202
|
+
return result;
|
|
2203
|
+
}
|
|
2204
|
+
var toString_2 = O.toString;
|
|
2205
|
+
if (IsCallable(toString_2)) {
|
|
2206
|
+
var result = toString_2.call(O);
|
|
2207
|
+
if (!IsObject(result))
|
|
2208
|
+
return result;
|
|
2209
|
+
}
|
|
2210
|
+
}
|
|
2211
|
+
throw new TypeError;
|
|
2212
|
+
}
|
|
2213
|
+
function ToBoolean(argument) {
|
|
2214
|
+
return !!argument;
|
|
2215
|
+
}
|
|
2216
|
+
function ToString(argument) {
|
|
2217
|
+
return "" + argument;
|
|
2218
|
+
}
|
|
2219
|
+
function ToPropertyKey(argument) {
|
|
2220
|
+
var key = ToPrimitive(argument, 3);
|
|
2221
|
+
if (IsSymbol(key))
|
|
2222
|
+
return key;
|
|
2223
|
+
return ToString(key);
|
|
2224
|
+
}
|
|
2225
|
+
function IsArray(argument) {
|
|
2226
|
+
return Array.isArray ? Array.isArray(argument) : argument instanceof Object ? argument instanceof Array : Object.prototype.toString.call(argument) === "[object Array]";
|
|
2227
|
+
}
|
|
2228
|
+
function IsCallable(argument) {
|
|
2229
|
+
return typeof argument === "function";
|
|
2230
|
+
}
|
|
2231
|
+
function IsConstructor(argument) {
|
|
2232
|
+
return typeof argument === "function";
|
|
2233
|
+
}
|
|
2234
|
+
function IsPropertyKey(argument) {
|
|
2235
|
+
switch (Type(argument)) {
|
|
2236
|
+
case 3:
|
|
2237
|
+
return true;
|
|
2238
|
+
case 4:
|
|
2239
|
+
return true;
|
|
2240
|
+
default:
|
|
2241
|
+
return false;
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
function SameValueZero(x, y) {
|
|
2245
|
+
return x === y || x !== x && y !== y;
|
|
2246
|
+
}
|
|
2247
|
+
function GetMethod(V, P) {
|
|
2248
|
+
var func = V[P];
|
|
2249
|
+
if (func === undefined || func === null)
|
|
2250
|
+
return;
|
|
2251
|
+
if (!IsCallable(func))
|
|
2252
|
+
throw new TypeError;
|
|
2253
|
+
return func;
|
|
2254
|
+
}
|
|
2255
|
+
function GetIterator(obj) {
|
|
2256
|
+
var method = GetMethod(obj, iteratorSymbol);
|
|
2257
|
+
if (!IsCallable(method))
|
|
2258
|
+
throw new TypeError;
|
|
2259
|
+
var iterator = method.call(obj);
|
|
2260
|
+
if (!IsObject(iterator))
|
|
2261
|
+
throw new TypeError;
|
|
2262
|
+
return iterator;
|
|
2263
|
+
}
|
|
2264
|
+
function IteratorValue(iterResult) {
|
|
2265
|
+
return iterResult.value;
|
|
2266
|
+
}
|
|
2267
|
+
function IteratorStep(iterator) {
|
|
2268
|
+
var result = iterator.next();
|
|
2269
|
+
return result.done ? false : result;
|
|
2270
|
+
}
|
|
2271
|
+
function IteratorClose(iterator) {
|
|
2272
|
+
var f = iterator["return"];
|
|
2273
|
+
if (f)
|
|
2274
|
+
f.call(iterator);
|
|
2275
|
+
}
|
|
2276
|
+
function OrdinaryGetPrototypeOf(O) {
|
|
2277
|
+
var proto = Object.getPrototypeOf(O);
|
|
2278
|
+
if (typeof O !== "function" || O === functionPrototype)
|
|
2279
|
+
return proto;
|
|
2280
|
+
if (proto !== functionPrototype)
|
|
2281
|
+
return proto;
|
|
2282
|
+
var prototype = O.prototype;
|
|
2283
|
+
var prototypeProto = prototype && Object.getPrototypeOf(prototype);
|
|
2284
|
+
if (prototypeProto == null || prototypeProto === Object.prototype)
|
|
2285
|
+
return proto;
|
|
2286
|
+
var constructor = prototypeProto.constructor;
|
|
2287
|
+
if (typeof constructor !== "function")
|
|
2288
|
+
return proto;
|
|
2289
|
+
if (constructor === O)
|
|
2290
|
+
return proto;
|
|
2291
|
+
return constructor;
|
|
2292
|
+
}
|
|
2293
|
+
function CreateMetadataRegistry() {
|
|
2294
|
+
var fallback;
|
|
2295
|
+
if (!IsUndefined(registrySymbol) && typeof root.Reflect !== "undefined" && !(registrySymbol in root.Reflect) && typeof root.Reflect.defineMetadata === "function") {
|
|
2296
|
+
fallback = CreateFallbackProvider(root.Reflect);
|
|
2297
|
+
}
|
|
2298
|
+
var first;
|
|
2299
|
+
var second;
|
|
2300
|
+
var rest;
|
|
2301
|
+
var targetProviderMap = new _WeakMap;
|
|
2302
|
+
var registry = {
|
|
2303
|
+
registerProvider,
|
|
2304
|
+
getProvider,
|
|
2305
|
+
setProvider
|
|
2306
|
+
};
|
|
2307
|
+
return registry;
|
|
2308
|
+
function registerProvider(provider) {
|
|
2309
|
+
if (!Object.isExtensible(registry)) {
|
|
2310
|
+
throw new Error("Cannot add provider to a frozen registry.");
|
|
2311
|
+
}
|
|
2312
|
+
switch (true) {
|
|
2313
|
+
case fallback === provider:
|
|
2314
|
+
break;
|
|
2315
|
+
case IsUndefined(first):
|
|
2316
|
+
first = provider;
|
|
2317
|
+
break;
|
|
2318
|
+
case first === provider:
|
|
2319
|
+
break;
|
|
2320
|
+
case IsUndefined(second):
|
|
2321
|
+
second = provider;
|
|
2322
|
+
break;
|
|
2323
|
+
case second === provider:
|
|
2324
|
+
break;
|
|
2325
|
+
default:
|
|
2326
|
+
if (rest === undefined)
|
|
2327
|
+
rest = new _Set;
|
|
2328
|
+
rest.add(provider);
|
|
2329
|
+
break;
|
|
2330
|
+
}
|
|
2331
|
+
}
|
|
2332
|
+
function getProviderNoCache(O, P) {
|
|
2333
|
+
if (!IsUndefined(first)) {
|
|
2334
|
+
if (first.isProviderFor(O, P))
|
|
2335
|
+
return first;
|
|
2336
|
+
if (!IsUndefined(second)) {
|
|
2337
|
+
if (second.isProviderFor(O, P))
|
|
2338
|
+
return first;
|
|
2339
|
+
if (!IsUndefined(rest)) {
|
|
2340
|
+
var iterator = GetIterator(rest);
|
|
2341
|
+
while (true) {
|
|
2342
|
+
var next = IteratorStep(iterator);
|
|
2343
|
+
if (!next) {
|
|
2344
|
+
return;
|
|
2345
|
+
}
|
|
2346
|
+
var provider = IteratorValue(next);
|
|
2347
|
+
if (provider.isProviderFor(O, P)) {
|
|
2348
|
+
IteratorClose(iterator);
|
|
2349
|
+
return provider;
|
|
2350
|
+
}
|
|
2351
|
+
}
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
if (!IsUndefined(fallback) && fallback.isProviderFor(O, P)) {
|
|
2356
|
+
return fallback;
|
|
2357
|
+
}
|
|
2358
|
+
return;
|
|
2359
|
+
}
|
|
2360
|
+
function getProvider(O, P) {
|
|
2361
|
+
var providerMap = targetProviderMap.get(O);
|
|
2362
|
+
var provider;
|
|
2363
|
+
if (!IsUndefined(providerMap)) {
|
|
2364
|
+
provider = providerMap.get(P);
|
|
2365
|
+
}
|
|
2366
|
+
if (!IsUndefined(provider)) {
|
|
2367
|
+
return provider;
|
|
2368
|
+
}
|
|
2369
|
+
provider = getProviderNoCache(O, P);
|
|
2370
|
+
if (!IsUndefined(provider)) {
|
|
2371
|
+
if (IsUndefined(providerMap)) {
|
|
2372
|
+
providerMap = new _Map;
|
|
2373
|
+
targetProviderMap.set(O, providerMap);
|
|
2374
|
+
}
|
|
2375
|
+
providerMap.set(P, provider);
|
|
2376
|
+
}
|
|
2377
|
+
return provider;
|
|
2378
|
+
}
|
|
2379
|
+
function hasProvider(provider) {
|
|
2380
|
+
if (IsUndefined(provider))
|
|
2381
|
+
throw new TypeError;
|
|
2382
|
+
return first === provider || second === provider || !IsUndefined(rest) && rest.has(provider);
|
|
2383
|
+
}
|
|
2384
|
+
function setProvider(O, P, provider) {
|
|
2385
|
+
if (!hasProvider(provider)) {
|
|
2386
|
+
throw new Error("Metadata provider not registered.");
|
|
2387
|
+
}
|
|
2388
|
+
var existingProvider = getProvider(O, P);
|
|
2389
|
+
if (existingProvider !== provider) {
|
|
2390
|
+
if (!IsUndefined(existingProvider)) {
|
|
2391
|
+
return false;
|
|
2392
|
+
}
|
|
2393
|
+
var providerMap = targetProviderMap.get(O);
|
|
2394
|
+
if (IsUndefined(providerMap)) {
|
|
2395
|
+
providerMap = new _Map;
|
|
2396
|
+
targetProviderMap.set(O, providerMap);
|
|
2397
|
+
}
|
|
2398
|
+
providerMap.set(P, provider);
|
|
2399
|
+
}
|
|
2400
|
+
return true;
|
|
2401
|
+
}
|
|
2402
|
+
}
|
|
2403
|
+
function GetOrCreateMetadataRegistry() {
|
|
2404
|
+
var metadataRegistry2;
|
|
2405
|
+
if (!IsUndefined(registrySymbol) && IsObject(root.Reflect) && Object.isExtensible(root.Reflect)) {
|
|
2406
|
+
metadataRegistry2 = root.Reflect[registrySymbol];
|
|
2407
|
+
}
|
|
2408
|
+
if (IsUndefined(metadataRegistry2)) {
|
|
2409
|
+
metadataRegistry2 = CreateMetadataRegistry();
|
|
2410
|
+
}
|
|
2411
|
+
if (!IsUndefined(registrySymbol) && IsObject(root.Reflect) && Object.isExtensible(root.Reflect)) {
|
|
2412
|
+
Object.defineProperty(root.Reflect, registrySymbol, {
|
|
2413
|
+
enumerable: false,
|
|
2414
|
+
configurable: false,
|
|
2415
|
+
writable: false,
|
|
2416
|
+
value: metadataRegistry2
|
|
2417
|
+
});
|
|
2418
|
+
}
|
|
2419
|
+
return metadataRegistry2;
|
|
2420
|
+
}
|
|
2421
|
+
function CreateMetadataProvider(registry) {
|
|
2422
|
+
var metadata2 = new _WeakMap;
|
|
2423
|
+
var provider = {
|
|
2424
|
+
isProviderFor: function(O, P) {
|
|
2425
|
+
var targetMetadata = metadata2.get(O);
|
|
2426
|
+
if (IsUndefined(targetMetadata))
|
|
2427
|
+
return false;
|
|
2428
|
+
return targetMetadata.has(P);
|
|
2429
|
+
},
|
|
2430
|
+
OrdinaryDefineOwnMetadata: OrdinaryDefineOwnMetadata2,
|
|
2431
|
+
OrdinaryHasOwnMetadata: OrdinaryHasOwnMetadata2,
|
|
2432
|
+
OrdinaryGetOwnMetadata: OrdinaryGetOwnMetadata2,
|
|
2433
|
+
OrdinaryOwnMetadataKeys: OrdinaryOwnMetadataKeys2,
|
|
2434
|
+
OrdinaryDeleteMetadata
|
|
2435
|
+
};
|
|
2436
|
+
metadataRegistry.registerProvider(provider);
|
|
2437
|
+
return provider;
|
|
2438
|
+
function GetOrCreateMetadataMap(O, P, Create) {
|
|
2439
|
+
var targetMetadata = metadata2.get(O);
|
|
2440
|
+
var createdTargetMetadata = false;
|
|
2441
|
+
if (IsUndefined(targetMetadata)) {
|
|
2442
|
+
if (!Create)
|
|
2443
|
+
return;
|
|
2444
|
+
targetMetadata = new _Map;
|
|
2445
|
+
metadata2.set(O, targetMetadata);
|
|
2446
|
+
createdTargetMetadata = true;
|
|
2447
|
+
}
|
|
2448
|
+
var metadataMap = targetMetadata.get(P);
|
|
2449
|
+
if (IsUndefined(metadataMap)) {
|
|
2450
|
+
if (!Create)
|
|
2451
|
+
return;
|
|
2452
|
+
metadataMap = new _Map;
|
|
2453
|
+
targetMetadata.set(P, metadataMap);
|
|
2454
|
+
if (!registry.setProvider(O, P, provider)) {
|
|
2455
|
+
targetMetadata.delete(P);
|
|
2456
|
+
if (createdTargetMetadata) {
|
|
2457
|
+
metadata2.delete(O);
|
|
2458
|
+
}
|
|
2459
|
+
throw new Error("Wrong provider for target.");
|
|
2460
|
+
}
|
|
2461
|
+
}
|
|
2462
|
+
return metadataMap;
|
|
2463
|
+
}
|
|
2464
|
+
function OrdinaryHasOwnMetadata2(MetadataKey, O, P) {
|
|
2465
|
+
var metadataMap = GetOrCreateMetadataMap(O, P, false);
|
|
2466
|
+
if (IsUndefined(metadataMap))
|
|
2467
|
+
return false;
|
|
2468
|
+
return ToBoolean(metadataMap.has(MetadataKey));
|
|
2469
|
+
}
|
|
2470
|
+
function OrdinaryGetOwnMetadata2(MetadataKey, O, P) {
|
|
2471
|
+
var metadataMap = GetOrCreateMetadataMap(O, P, false);
|
|
2472
|
+
if (IsUndefined(metadataMap))
|
|
2473
|
+
return;
|
|
2474
|
+
return metadataMap.get(MetadataKey);
|
|
2475
|
+
}
|
|
2476
|
+
function OrdinaryDefineOwnMetadata2(MetadataKey, MetadataValue, O, P) {
|
|
2477
|
+
var metadataMap = GetOrCreateMetadataMap(O, P, true);
|
|
2478
|
+
metadataMap.set(MetadataKey, MetadataValue);
|
|
2479
|
+
}
|
|
2480
|
+
function OrdinaryOwnMetadataKeys2(O, P) {
|
|
2481
|
+
var keys = [];
|
|
2482
|
+
var metadataMap = GetOrCreateMetadataMap(O, P, false);
|
|
2483
|
+
if (IsUndefined(metadataMap))
|
|
2484
|
+
return keys;
|
|
2485
|
+
var keysObj = metadataMap.keys();
|
|
2486
|
+
var iterator = GetIterator(keysObj);
|
|
2487
|
+
var k = 0;
|
|
2488
|
+
while (true) {
|
|
2489
|
+
var next = IteratorStep(iterator);
|
|
2490
|
+
if (!next) {
|
|
2491
|
+
keys.length = k;
|
|
2492
|
+
return keys;
|
|
2493
|
+
}
|
|
2494
|
+
var nextValue = IteratorValue(next);
|
|
2495
|
+
try {
|
|
2496
|
+
keys[k] = nextValue;
|
|
2497
|
+
} catch (e) {
|
|
2498
|
+
try {
|
|
2499
|
+
IteratorClose(iterator);
|
|
2500
|
+
} finally {
|
|
2501
|
+
throw e;
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
k++;
|
|
2505
|
+
}
|
|
2506
|
+
}
|
|
2507
|
+
function OrdinaryDeleteMetadata(MetadataKey, O, P) {
|
|
2508
|
+
var metadataMap = GetOrCreateMetadataMap(O, P, false);
|
|
2509
|
+
if (IsUndefined(metadataMap))
|
|
2510
|
+
return false;
|
|
2511
|
+
if (!metadataMap.delete(MetadataKey))
|
|
2512
|
+
return false;
|
|
2513
|
+
if (metadataMap.size === 0) {
|
|
2514
|
+
var targetMetadata = metadata2.get(O);
|
|
2515
|
+
if (!IsUndefined(targetMetadata)) {
|
|
2516
|
+
targetMetadata.delete(P);
|
|
2517
|
+
if (targetMetadata.size === 0) {
|
|
2518
|
+
metadata2.delete(targetMetadata);
|
|
2519
|
+
}
|
|
2520
|
+
}
|
|
2521
|
+
}
|
|
2522
|
+
return true;
|
|
2523
|
+
}
|
|
2524
|
+
}
|
|
2525
|
+
function CreateFallbackProvider(reflect) {
|
|
2526
|
+
var { defineMetadata: defineMetadata2, hasOwnMetadata: hasOwnMetadata2, getOwnMetadata: getOwnMetadata2, getOwnMetadataKeys: getOwnMetadataKeys2, deleteMetadata: deleteMetadata2 } = reflect;
|
|
2527
|
+
var metadataOwner = new _WeakMap;
|
|
2528
|
+
var provider = {
|
|
2529
|
+
isProviderFor: function(O, P) {
|
|
2530
|
+
var metadataPropertySet = metadataOwner.get(O);
|
|
2531
|
+
if (!IsUndefined(metadataPropertySet) && metadataPropertySet.has(P)) {
|
|
2532
|
+
return true;
|
|
2533
|
+
}
|
|
2534
|
+
if (getOwnMetadataKeys2(O, P).length) {
|
|
2535
|
+
if (IsUndefined(metadataPropertySet)) {
|
|
2536
|
+
metadataPropertySet = new _Set;
|
|
2537
|
+
metadataOwner.set(O, metadataPropertySet);
|
|
2538
|
+
}
|
|
2539
|
+
metadataPropertySet.add(P);
|
|
2540
|
+
return true;
|
|
2541
|
+
}
|
|
2542
|
+
return false;
|
|
2543
|
+
},
|
|
2544
|
+
OrdinaryDefineOwnMetadata: defineMetadata2,
|
|
2545
|
+
OrdinaryHasOwnMetadata: hasOwnMetadata2,
|
|
2546
|
+
OrdinaryGetOwnMetadata: getOwnMetadata2,
|
|
2547
|
+
OrdinaryOwnMetadataKeys: getOwnMetadataKeys2,
|
|
2548
|
+
OrdinaryDeleteMetadata: deleteMetadata2
|
|
2549
|
+
};
|
|
2550
|
+
return provider;
|
|
2551
|
+
}
|
|
2552
|
+
function GetMetadataProvider(O, P, Create) {
|
|
2553
|
+
var registeredProvider = metadataRegistry.getProvider(O, P);
|
|
2554
|
+
if (!IsUndefined(registeredProvider)) {
|
|
2555
|
+
return registeredProvider;
|
|
2556
|
+
}
|
|
2557
|
+
if (Create) {
|
|
2558
|
+
if (metadataRegistry.setProvider(O, P, metadataProvider)) {
|
|
2559
|
+
return metadataProvider;
|
|
2560
|
+
}
|
|
2561
|
+
throw new Error("Illegal state.");
|
|
2562
|
+
}
|
|
2563
|
+
return;
|
|
2564
|
+
}
|
|
2565
|
+
function CreateMapPolyfill() {
|
|
2566
|
+
var cacheSentinel = {};
|
|
2567
|
+
var arraySentinel = [];
|
|
2568
|
+
var MapIterator = function() {
|
|
2569
|
+
function MapIterator2(keys, values, selector) {
|
|
2570
|
+
this._index = 0;
|
|
2571
|
+
this._keys = keys;
|
|
2572
|
+
this._values = values;
|
|
2573
|
+
this._selector = selector;
|
|
2574
|
+
}
|
|
2575
|
+
MapIterator2.prototype["@@iterator"] = function() {
|
|
2576
|
+
return this;
|
|
2577
|
+
};
|
|
2578
|
+
MapIterator2.prototype[iteratorSymbol] = function() {
|
|
2579
|
+
return this;
|
|
2580
|
+
};
|
|
2581
|
+
MapIterator2.prototype.next = function() {
|
|
2582
|
+
var index = this._index;
|
|
2583
|
+
if (index >= 0 && index < this._keys.length) {
|
|
2584
|
+
var result = this._selector(this._keys[index], this._values[index]);
|
|
2585
|
+
if (index + 1 >= this._keys.length) {
|
|
2586
|
+
this._index = -1;
|
|
2587
|
+
this._keys = arraySentinel;
|
|
2588
|
+
this._values = arraySentinel;
|
|
2589
|
+
} else {
|
|
2590
|
+
this._index++;
|
|
2591
|
+
}
|
|
2592
|
+
return { value: result, done: false };
|
|
2593
|
+
}
|
|
2594
|
+
return { value: undefined, done: true };
|
|
2595
|
+
};
|
|
2596
|
+
MapIterator2.prototype.throw = function(error) {
|
|
2597
|
+
if (this._index >= 0) {
|
|
2598
|
+
this._index = -1;
|
|
2599
|
+
this._keys = arraySentinel;
|
|
2600
|
+
this._values = arraySentinel;
|
|
2601
|
+
}
|
|
2602
|
+
throw error;
|
|
2603
|
+
};
|
|
2604
|
+
MapIterator2.prototype.return = function(value) {
|
|
2605
|
+
if (this._index >= 0) {
|
|
2606
|
+
this._index = -1;
|
|
2607
|
+
this._keys = arraySentinel;
|
|
2608
|
+
this._values = arraySentinel;
|
|
2609
|
+
}
|
|
2610
|
+
return { value, done: true };
|
|
2611
|
+
};
|
|
2612
|
+
return MapIterator2;
|
|
2613
|
+
}();
|
|
2614
|
+
var Map2 = function() {
|
|
2615
|
+
function Map3() {
|
|
2616
|
+
this._keys = [];
|
|
2617
|
+
this._values = [];
|
|
2618
|
+
this._cacheKey = cacheSentinel;
|
|
2619
|
+
this._cacheIndex = -2;
|
|
2620
|
+
}
|
|
2621
|
+
Object.defineProperty(Map3.prototype, "size", {
|
|
2622
|
+
get: function() {
|
|
2623
|
+
return this._keys.length;
|
|
2624
|
+
},
|
|
2625
|
+
enumerable: true,
|
|
2626
|
+
configurable: true
|
|
2627
|
+
});
|
|
2628
|
+
Map3.prototype.has = function(key) {
|
|
2629
|
+
return this._find(key, false) >= 0;
|
|
2630
|
+
};
|
|
2631
|
+
Map3.prototype.get = function(key) {
|
|
2632
|
+
var index = this._find(key, false);
|
|
2633
|
+
return index >= 0 ? this._values[index] : undefined;
|
|
2634
|
+
};
|
|
2635
|
+
Map3.prototype.set = function(key, value) {
|
|
2636
|
+
var index = this._find(key, true);
|
|
2637
|
+
this._values[index] = value;
|
|
2638
|
+
return this;
|
|
2639
|
+
};
|
|
2640
|
+
Map3.prototype.delete = function(key) {
|
|
2641
|
+
var index = this._find(key, false);
|
|
2642
|
+
if (index >= 0) {
|
|
2643
|
+
var size = this._keys.length;
|
|
2644
|
+
for (var i = index + 1;i < size; i++) {
|
|
2645
|
+
this._keys[i - 1] = this._keys[i];
|
|
2646
|
+
this._values[i - 1] = this._values[i];
|
|
2647
|
+
}
|
|
2648
|
+
this._keys.length--;
|
|
2649
|
+
this._values.length--;
|
|
2650
|
+
if (SameValueZero(key, this._cacheKey)) {
|
|
2651
|
+
this._cacheKey = cacheSentinel;
|
|
2652
|
+
this._cacheIndex = -2;
|
|
2653
|
+
}
|
|
2654
|
+
return true;
|
|
2655
|
+
}
|
|
2656
|
+
return false;
|
|
2657
|
+
};
|
|
2658
|
+
Map3.prototype.clear = function() {
|
|
2659
|
+
this._keys.length = 0;
|
|
2660
|
+
this._values.length = 0;
|
|
2661
|
+
this._cacheKey = cacheSentinel;
|
|
2662
|
+
this._cacheIndex = -2;
|
|
2663
|
+
};
|
|
2664
|
+
Map3.prototype.keys = function() {
|
|
2665
|
+
return new MapIterator(this._keys, this._values, getKey);
|
|
2666
|
+
};
|
|
2667
|
+
Map3.prototype.values = function() {
|
|
2668
|
+
return new MapIterator(this._keys, this._values, getValue);
|
|
2669
|
+
};
|
|
2670
|
+
Map3.prototype.entries = function() {
|
|
2671
|
+
return new MapIterator(this._keys, this._values, getEntry);
|
|
2672
|
+
};
|
|
2673
|
+
Map3.prototype["@@iterator"] = function() {
|
|
2674
|
+
return this.entries();
|
|
2675
|
+
};
|
|
2676
|
+
Map3.prototype[iteratorSymbol] = function() {
|
|
2677
|
+
return this.entries();
|
|
2678
|
+
};
|
|
2679
|
+
Map3.prototype._find = function(key, insert) {
|
|
2680
|
+
if (!SameValueZero(this._cacheKey, key)) {
|
|
2681
|
+
this._cacheIndex = -1;
|
|
2682
|
+
for (var i = 0;i < this._keys.length; i++) {
|
|
2683
|
+
if (SameValueZero(this._keys[i], key)) {
|
|
2684
|
+
this._cacheIndex = i;
|
|
2685
|
+
break;
|
|
2686
|
+
}
|
|
2687
|
+
}
|
|
2688
|
+
}
|
|
2689
|
+
if (this._cacheIndex < 0 && insert) {
|
|
2690
|
+
this._cacheIndex = this._keys.length;
|
|
2691
|
+
this._keys.push(key);
|
|
2692
|
+
this._values.push(undefined);
|
|
2693
|
+
}
|
|
2694
|
+
return this._cacheIndex;
|
|
2695
|
+
};
|
|
2696
|
+
return Map3;
|
|
2697
|
+
}();
|
|
2698
|
+
return Map2;
|
|
2699
|
+
function getKey(key, _) {
|
|
2700
|
+
return key;
|
|
2701
|
+
}
|
|
2702
|
+
function getValue(_, value) {
|
|
2703
|
+
return value;
|
|
2704
|
+
}
|
|
2705
|
+
function getEntry(key, value) {
|
|
2706
|
+
return [key, value];
|
|
2707
|
+
}
|
|
2708
|
+
}
|
|
2709
|
+
function CreateSetPolyfill() {
|
|
2710
|
+
var Set2 = function() {
|
|
2711
|
+
function Set3() {
|
|
2712
|
+
this._map = new _Map;
|
|
2713
|
+
}
|
|
2714
|
+
Object.defineProperty(Set3.prototype, "size", {
|
|
2715
|
+
get: function() {
|
|
2716
|
+
return this._map.size;
|
|
2717
|
+
},
|
|
2718
|
+
enumerable: true,
|
|
2719
|
+
configurable: true
|
|
2720
|
+
});
|
|
2721
|
+
Set3.prototype.has = function(value) {
|
|
2722
|
+
return this._map.has(value);
|
|
2723
|
+
};
|
|
2724
|
+
Set3.prototype.add = function(value) {
|
|
2725
|
+
return this._map.set(value, value), this;
|
|
2726
|
+
};
|
|
2727
|
+
Set3.prototype.delete = function(value) {
|
|
2728
|
+
return this._map.delete(value);
|
|
2729
|
+
};
|
|
2730
|
+
Set3.prototype.clear = function() {
|
|
2731
|
+
this._map.clear();
|
|
2732
|
+
};
|
|
2733
|
+
Set3.prototype.keys = function() {
|
|
2734
|
+
return this._map.keys();
|
|
2735
|
+
};
|
|
2736
|
+
Set3.prototype.values = function() {
|
|
2737
|
+
return this._map.keys();
|
|
2738
|
+
};
|
|
2739
|
+
Set3.prototype.entries = function() {
|
|
2740
|
+
return this._map.entries();
|
|
2741
|
+
};
|
|
2742
|
+
Set3.prototype["@@iterator"] = function() {
|
|
2743
|
+
return this.keys();
|
|
2744
|
+
};
|
|
2745
|
+
Set3.prototype[iteratorSymbol] = function() {
|
|
2746
|
+
return this.keys();
|
|
2747
|
+
};
|
|
2748
|
+
return Set3;
|
|
2749
|
+
}();
|
|
2750
|
+
return Set2;
|
|
2751
|
+
}
|
|
2752
|
+
function CreateWeakMapPolyfill() {
|
|
2753
|
+
var UUID_SIZE = 16;
|
|
2754
|
+
var keys = HashMap.create();
|
|
2755
|
+
var rootKey = CreateUniqueKey();
|
|
2756
|
+
return function() {
|
|
2757
|
+
function WeakMap2() {
|
|
2758
|
+
this._key = CreateUniqueKey();
|
|
2759
|
+
}
|
|
2760
|
+
WeakMap2.prototype.has = function(target) {
|
|
2761
|
+
var table = GetOrCreateWeakMapTable(target, false);
|
|
2762
|
+
return table !== undefined ? HashMap.has(table, this._key) : false;
|
|
2763
|
+
};
|
|
2764
|
+
WeakMap2.prototype.get = function(target) {
|
|
2765
|
+
var table = GetOrCreateWeakMapTable(target, false);
|
|
2766
|
+
return table !== undefined ? HashMap.get(table, this._key) : undefined;
|
|
2767
|
+
};
|
|
2768
|
+
WeakMap2.prototype.set = function(target, value) {
|
|
2769
|
+
var table = GetOrCreateWeakMapTable(target, true);
|
|
2770
|
+
table[this._key] = value;
|
|
2771
|
+
return this;
|
|
2772
|
+
};
|
|
2773
|
+
WeakMap2.prototype.delete = function(target) {
|
|
2774
|
+
var table = GetOrCreateWeakMapTable(target, false);
|
|
2775
|
+
return table !== undefined ? delete table[this._key] : false;
|
|
2776
|
+
};
|
|
2777
|
+
WeakMap2.prototype.clear = function() {
|
|
2778
|
+
this._key = CreateUniqueKey();
|
|
2779
|
+
};
|
|
2780
|
+
return WeakMap2;
|
|
2781
|
+
}();
|
|
2782
|
+
function CreateUniqueKey() {
|
|
2783
|
+
var key;
|
|
2784
|
+
do
|
|
2785
|
+
key = "@@WeakMap@@" + CreateUUID();
|
|
2786
|
+
while (HashMap.has(keys, key));
|
|
2787
|
+
keys[key] = true;
|
|
2788
|
+
return key;
|
|
2789
|
+
}
|
|
2790
|
+
function GetOrCreateWeakMapTable(target, create) {
|
|
2791
|
+
if (!hasOwn.call(target, rootKey)) {
|
|
2792
|
+
if (!create)
|
|
2793
|
+
return;
|
|
2794
|
+
Object.defineProperty(target, rootKey, { value: HashMap.create() });
|
|
2795
|
+
}
|
|
2796
|
+
return target[rootKey];
|
|
2797
|
+
}
|
|
2798
|
+
function FillRandomBytes(buffer, size) {
|
|
2799
|
+
for (var i = 0;i < size; ++i)
|
|
2800
|
+
buffer[i] = Math.random() * 255 | 0;
|
|
2801
|
+
return buffer;
|
|
2802
|
+
}
|
|
2803
|
+
function GenRandomBytes(size) {
|
|
2804
|
+
if (typeof Uint8Array === "function") {
|
|
2805
|
+
var array = new Uint8Array(size);
|
|
2806
|
+
if (typeof crypto !== "undefined") {
|
|
2807
|
+
crypto.getRandomValues(array);
|
|
2808
|
+
} else if (typeof msCrypto !== "undefined") {
|
|
2809
|
+
msCrypto.getRandomValues(array);
|
|
2810
|
+
} else {
|
|
2811
|
+
FillRandomBytes(array, size);
|
|
2812
|
+
}
|
|
2813
|
+
return array;
|
|
2814
|
+
}
|
|
2815
|
+
return FillRandomBytes(new Array(size), size);
|
|
2816
|
+
}
|
|
2817
|
+
function CreateUUID() {
|
|
2818
|
+
var data = GenRandomBytes(UUID_SIZE);
|
|
2819
|
+
data[6] = data[6] & 79 | 64;
|
|
2820
|
+
data[8] = data[8] & 191 | 128;
|
|
2821
|
+
var result = "";
|
|
2822
|
+
for (var offset = 0;offset < UUID_SIZE; ++offset) {
|
|
2823
|
+
var byte = data[offset];
|
|
2824
|
+
if (offset === 4 || offset === 6 || offset === 8)
|
|
2825
|
+
result += "-";
|
|
2826
|
+
if (byte < 16)
|
|
2827
|
+
result += "0";
|
|
2828
|
+
result += byte.toString(16).toLowerCase();
|
|
2829
|
+
}
|
|
2830
|
+
return result;
|
|
2831
|
+
}
|
|
2832
|
+
}
|
|
2833
|
+
function MakeDictionary(obj) {
|
|
2834
|
+
obj.__ = undefined;
|
|
2835
|
+
delete obj.__;
|
|
2836
|
+
return obj;
|
|
2837
|
+
}
|
|
2838
|
+
});
|
|
2839
|
+
})(Reflect2 || (Reflect2 = {}));
|
|
2840
|
+
});
|
|
2841
|
+
var import_reflect_metadata = __toESM(require_Reflect(), 1);
|
|
2842
|
+
var methodMetadataStore = new WeakMap;
|
|
2843
|
+
var controllerMetadataStore = new WeakMap;
|
|
2844
|
+
var moduleMetadataStore = new WeakMap;
|
|
2845
|
+
var injectionMetadataStore = new WeakMap;
|
|
2846
|
+
var MetadataStorage = {
|
|
2847
|
+
addRoute(target, methodName, meta) {
|
|
2848
|
+
let methods = methodMetadataStore.get(target);
|
|
2849
|
+
if (!methods) {
|
|
2850
|
+
methods = new Map;
|
|
2851
|
+
methodMetadataStore.set(target, methods);
|
|
2852
|
+
}
|
|
2853
|
+
const existing = methods.get(methodName) || {};
|
|
2854
|
+
methods.set(methodName, { ...existing, ...meta });
|
|
2855
|
+
},
|
|
2856
|
+
addContract(target, methodName, contract) {
|
|
2857
|
+
let methods = methodMetadataStore.get(target);
|
|
2858
|
+
if (!methods) {
|
|
2859
|
+
methods = new Map;
|
|
2860
|
+
methodMetadataStore.set(target, methods);
|
|
2861
|
+
}
|
|
2862
|
+
const existing = methods.get(methodName) || {};
|
|
2863
|
+
existing.contract = contract;
|
|
2864
|
+
methods.set(methodName, existing);
|
|
2865
|
+
},
|
|
2866
|
+
addMiddleware(target, middleware, methodName) {
|
|
2867
|
+
if (methodName) {
|
|
2868
|
+
let methods = methodMetadataStore.get(target);
|
|
2869
|
+
if (!methods) {
|
|
2870
|
+
methods = new Map;
|
|
2871
|
+
methodMetadataStore.set(target, methods);
|
|
2872
|
+
}
|
|
2873
|
+
const existing = methods.get(methodName) || {};
|
|
2874
|
+
existing.middlewares = [...existing.middlewares || [], middleware];
|
|
2875
|
+
methods.set(methodName, existing);
|
|
2876
|
+
} else {
|
|
2877
|
+
const existing = controllerMetadataStore.get(target) || { prefix: "/" };
|
|
2878
|
+
existing.middlewares = [...existing.middlewares || [], middleware];
|
|
2879
|
+
controllerMetadataStore.set(target, existing);
|
|
2880
|
+
}
|
|
2881
|
+
},
|
|
2882
|
+
getRoutes(target) {
|
|
2883
|
+
return methodMetadataStore.get(target);
|
|
2884
|
+
},
|
|
2885
|
+
setController(target, meta) {
|
|
2886
|
+
controllerMetadataStore.set(target, meta);
|
|
2887
|
+
},
|
|
2888
|
+
getController(target) {
|
|
2889
|
+
return controllerMetadataStore.get(target);
|
|
2890
|
+
},
|
|
2891
|
+
defineModule(target, meta) {
|
|
2892
|
+
moduleMetadataStore.set(target, meta);
|
|
2893
|
+
},
|
|
2894
|
+
getModule(target) {
|
|
2895
|
+
return moduleMetadataStore.get(target);
|
|
2896
|
+
},
|
|
2897
|
+
addInjection(target, index, token) {
|
|
2898
|
+
let injections = injectionMetadataStore.get(target);
|
|
2899
|
+
if (!injections) {
|
|
2900
|
+
injections = new Map;
|
|
2901
|
+
injectionMetadataStore.set(target, injections);
|
|
2902
|
+
}
|
|
2903
|
+
injections.set(index, token);
|
|
2904
|
+
},
|
|
2905
|
+
getInjections(target) {
|
|
2906
|
+
return injectionMetadataStore.get(target);
|
|
2907
|
+
}
|
|
2908
|
+
};
|
|
2909
|
+
function createMethodDecorator(method) {
|
|
2910
|
+
return (path = "/") => {
|
|
2911
|
+
return (target, propertyKey) => {
|
|
2912
|
+
MetadataStorage.addRoute(target, propertyKey, {
|
|
2913
|
+
method,
|
|
2914
|
+
path
|
|
2915
|
+
});
|
|
2916
|
+
};
|
|
2917
|
+
};
|
|
2918
|
+
}
|
|
2919
|
+
var Get = createMethodDecorator("GET");
|
|
2920
|
+
var Post = createMethodDecorator("POST");
|
|
2921
|
+
var Put = createMethodDecorator("PUT");
|
|
2922
|
+
var Delete = createMethodDecorator("DELETE");
|
|
2923
|
+
var Patch = createMethodDecorator("PATCH");
|
|
2924
|
+
var import_reflect_metadata2 = __toESM(require_Reflect(), 1);
|
|
2925
|
+
|
|
2926
|
+
class KanjijsIoC {
|
|
2927
|
+
static providers = new Map;
|
|
2928
|
+
static register(tokenOrTarget, provider) {
|
|
2929
|
+
if (provider) {
|
|
2930
|
+
if ("useValue" in provider) {
|
|
2931
|
+
this.providers.set(tokenOrTarget, { useValue: provider.useValue });
|
|
2932
|
+
} else if ("useClass" in provider) {
|
|
2933
|
+
this.providers.set(tokenOrTarget, { useClass: provider.useClass });
|
|
2934
|
+
}
|
|
2935
|
+
} else {
|
|
2936
|
+
this.providers.set(tokenOrTarget, { useClass: tokenOrTarget });
|
|
2937
|
+
}
|
|
2938
|
+
}
|
|
2939
|
+
static resolve(target) {
|
|
2940
|
+
let provider = this.providers.get(target);
|
|
2941
|
+
if (!provider && typeof target === "function") {
|
|
2942
|
+
provider = { useClass: target };
|
|
2943
|
+
this.providers.set(target, provider);
|
|
2944
|
+
}
|
|
2945
|
+
if (!provider) {
|
|
2946
|
+
throw new Error(`Provider not found for token: ${target?.name || target}`);
|
|
2947
|
+
}
|
|
2948
|
+
if (provider.instance) {
|
|
2949
|
+
return provider.instance;
|
|
2950
|
+
}
|
|
2951
|
+
console.log(`[DI] Creating NEW instance for ${target?.name || String(target)}`);
|
|
2952
|
+
if (provider.useValue !== undefined) {
|
|
2953
|
+
provider.instance = provider.useValue;
|
|
2954
|
+
} else if (provider.useClass) {
|
|
2955
|
+
const ConcreteClass = provider.useClass;
|
|
2956
|
+
const paramTypes = Reflect.getMetadata("design:paramtypes", ConcreteClass) || [];
|
|
2957
|
+
const injectionTokens = MetadataStorage.getInjections(ConcreteClass) || new Map;
|
|
2958
|
+
const injections = paramTypes.map((token, index) => {
|
|
2959
|
+
const overrideToken = injectionTokens.get(index);
|
|
2960
|
+
return KanjijsIoC.resolve(overrideToken || token);
|
|
2961
|
+
});
|
|
2962
|
+
provider.instance = new ConcreteClass(...injections);
|
|
2963
|
+
}
|
|
2964
|
+
return provider.instance;
|
|
2965
|
+
}
|
|
2966
|
+
static clear() {
|
|
2967
|
+
this.providers.clear();
|
|
2968
|
+
}
|
|
2969
|
+
}
|
|
2970
|
+
|
|
2971
|
+
class Container {
|
|
2972
|
+
providers = new Map;
|
|
2973
|
+
register(token, provider) {
|
|
2974
|
+
this.providers.set(token, provider);
|
|
2975
|
+
}
|
|
2976
|
+
resolve(token) {
|
|
2977
|
+
const provider = this.providers.get(token);
|
|
2978
|
+
if (!provider) {
|
|
2979
|
+
throw new Error(`[DI] Provider not found for token: ${token?.name || String(token)}`);
|
|
2980
|
+
}
|
|
2981
|
+
if (provider.instance) {
|
|
2982
|
+
return provider.instance;
|
|
2983
|
+
}
|
|
2984
|
+
if (provider.useValue !== undefined) {
|
|
2985
|
+
provider.instance = provider.useValue;
|
|
2986
|
+
} else if (provider.useClass) {
|
|
2987
|
+
const ConcreteClass = provider.useClass;
|
|
2988
|
+
const paramTypes = Reflect.getMetadata("design:paramtypes", ConcreteClass) || [];
|
|
2989
|
+
const injectionTokens = MetadataStorage.getInjections(ConcreteClass) || new Map;
|
|
2990
|
+
const injections = paramTypes.map((paramToken, index) => {
|
|
2991
|
+
const overrideToken = injectionTokens.get(index);
|
|
2992
|
+
return this.resolve(overrideToken || paramToken);
|
|
2993
|
+
});
|
|
2994
|
+
provider.instance = new ConcreteClass(...injections);
|
|
2995
|
+
} else if (provider.useFactory) {
|
|
2996
|
+
const injections = (provider.inject || []).map((token2) => this.resolve(token2));
|
|
2997
|
+
provider.instance = provider.useFactory(...injections);
|
|
2998
|
+
}
|
|
2999
|
+
return provider.instance;
|
|
3000
|
+
}
|
|
3001
|
+
}
|
|
3002
|
+
var kanjijsContext = new AsyncLocalStorage;
|
|
3003
|
+
class HttpException extends Error {
|
|
3004
|
+
response;
|
|
3005
|
+
status;
|
|
3006
|
+
constructor(response, status) {
|
|
3007
|
+
super(typeof response === "string" ? response : JSON.stringify(response));
|
|
3008
|
+
this.response = response;
|
|
3009
|
+
this.status = status;
|
|
3010
|
+
this.name = "HttpException";
|
|
3011
|
+
}
|
|
3012
|
+
getResponse() {
|
|
3013
|
+
return this.response;
|
|
3014
|
+
}
|
|
3015
|
+
getStatus() {
|
|
3016
|
+
return this.status;
|
|
3017
|
+
}
|
|
3018
|
+
}
|
|
3019
|
+
|
|
3020
|
+
class ModuleCompiler {
|
|
3021
|
+
nodes = new Map;
|
|
3022
|
+
globalExportedTokens = new Set;
|
|
3023
|
+
compile(rootModule) {
|
|
3024
|
+
this.scan(rootModule);
|
|
3025
|
+
this.validate();
|
|
3026
|
+
const container = new Container;
|
|
3027
|
+
for (const node of this.nodes.values()) {
|
|
3028
|
+
for (const [token, provider] of node.providers) {
|
|
3029
|
+
container.register(token, provider);
|
|
3030
|
+
}
|
|
3031
|
+
}
|
|
3032
|
+
return container;
|
|
3033
|
+
}
|
|
3034
|
+
scan(target) {
|
|
3035
|
+
const moduleClass = "module" in target ? target.module : target;
|
|
3036
|
+
if (this.nodes.has(moduleClass)) {
|
|
3037
|
+
return this.nodes.get(moduleClass);
|
|
3038
|
+
}
|
|
3039
|
+
const node = {
|
|
3040
|
+
module: moduleClass,
|
|
3041
|
+
imports: new Set,
|
|
3042
|
+
providers: new Map,
|
|
3043
|
+
exports: new Set,
|
|
3044
|
+
isGlobal: false
|
|
3045
|
+
};
|
|
3046
|
+
this.nodes.set(moduleClass, node);
|
|
3047
|
+
const meta = MetadataStorage.getModule(moduleClass) || {};
|
|
3048
|
+
const dynamicMeta = "module" in target ? target : {};
|
|
3049
|
+
const allProviders = [...meta.providers || [], ...dynamicMeta.providers || []];
|
|
3050
|
+
this.processProviders(node, allProviders);
|
|
3051
|
+
const allExports = [...meta.exports || [], ...dynamicMeta.exports || []];
|
|
3052
|
+
for (const token of allExports) {
|
|
3053
|
+
node.exports.add(token);
|
|
3054
|
+
}
|
|
3055
|
+
if (meta.global || dynamicMeta.global) {
|
|
3056
|
+
node.isGlobal = true;
|
|
3057
|
+
for (const token of node.exports) {
|
|
3058
|
+
this.globalExportedTokens.add(token);
|
|
3059
|
+
}
|
|
3060
|
+
}
|
|
3061
|
+
const allImports = [...meta.imports || [], ...dynamicMeta.imports || []];
|
|
3062
|
+
for (const imp of allImports) {
|
|
3063
|
+
const importedNode = this.scan(imp);
|
|
3064
|
+
node.imports.add(importedNode);
|
|
3065
|
+
}
|
|
3066
|
+
const controllers = meta.controllers || [];
|
|
3067
|
+
for (const controller of controllers) {
|
|
3068
|
+
node.providers.set(controller, { useClass: controller, provide: controller });
|
|
3069
|
+
}
|
|
3070
|
+
return node;
|
|
3071
|
+
}
|
|
3072
|
+
processProviders(node, providers) {
|
|
3073
|
+
for (const provider of providers) {
|
|
3074
|
+
let token;
|
|
3075
|
+
let definition;
|
|
3076
|
+
if (typeof provider === "function") {
|
|
3077
|
+
token = provider;
|
|
3078
|
+
definition = { useClass: provider, provide: provider };
|
|
3079
|
+
} else {
|
|
3080
|
+
token = provider.provide;
|
|
3081
|
+
definition = provider;
|
|
3082
|
+
}
|
|
3083
|
+
node.providers.set(token, definition);
|
|
3084
|
+
}
|
|
3085
|
+
}
|
|
3086
|
+
validate() {
|
|
3087
|
+
for (const node of this.nodes.values()) {
|
|
3088
|
+
const visibleTokens = new Set;
|
|
3089
|
+
for (const token of node.providers.keys()) {
|
|
3090
|
+
visibleTokens.add(token);
|
|
3091
|
+
}
|
|
3092
|
+
for (const imp of node.imports) {
|
|
3093
|
+
for (const exp of imp.exports) {
|
|
3094
|
+
visibleTokens.add(exp);
|
|
3095
|
+
}
|
|
3096
|
+
}
|
|
3097
|
+
for (const globalToken of this.globalExportedTokens) {
|
|
3098
|
+
visibleTokens.add(globalToken);
|
|
3099
|
+
}
|
|
3100
|
+
for (const [token, provider] of node.providers) {
|
|
3101
|
+
this.checkDependencies(provider, visibleTokens, node.module.name);
|
|
3102
|
+
}
|
|
3103
|
+
}
|
|
3104
|
+
}
|
|
3105
|
+
checkDependencies(provider, visibleTokens, moduleName) {
|
|
3106
|
+
let dependencies = [];
|
|
3107
|
+
let targetName = "";
|
|
3108
|
+
if ("useClass" in provider && provider.useClass) {
|
|
3109
|
+
const clazz = provider.useClass;
|
|
3110
|
+
targetName = clazz.name;
|
|
3111
|
+
const paramTypes = Reflect.getMetadata("design:paramtypes", clazz) || [];
|
|
3112
|
+
const injectionTokens = MetadataStorage.getInjections(clazz) || new Map;
|
|
3113
|
+
dependencies = paramTypes.map((t, i) => injectionTokens.get(i) || t);
|
|
3114
|
+
} else if ("useFactory" in provider && provider.useFactory) {
|
|
3115
|
+
targetName = provider.provide?.name || String(provider.provide);
|
|
3116
|
+
dependencies = provider.inject || [];
|
|
3117
|
+
}
|
|
3118
|
+
for (const dep of dependencies) {
|
|
3119
|
+
if (!visibleTokens.has(dep)) {
|
|
3120
|
+
const depName = dep?.name || String(dep);
|
|
3121
|
+
throw new Error(`[Kanjijs] strict-di-error: Provider '${targetName}' in Module '${moduleName}' ` + `depends on '${depName}', but it is not visible. ` + `Make sure it is imported and exported by the source module.`);
|
|
3122
|
+
}
|
|
3123
|
+
}
|
|
3124
|
+
}
|
|
3125
|
+
}
|
|
3126
|
+
var GLOBAL_MIDDLEWARE_TOKEN = Symbol("GLOBAL_MIDDLEWARE_TOKEN");
|
|
3127
|
+
|
|
3128
|
+
// src/middleware.ts
|
|
3129
|
+
function createValidationMiddleware(spec, validator) {
|
|
3130
|
+
return async (c, next) => {
|
|
3131
|
+
const validated = {};
|
|
3132
|
+
const issues = [];
|
|
3133
|
+
if (spec.request?.params) {
|
|
3134
|
+
const data = c.req.param();
|
|
3135
|
+
const result = await validator.parse(spec.request.params, data);
|
|
3136
|
+
if (!result.success) {
|
|
3137
|
+
issues.push(...result.issues);
|
|
3138
|
+
} else {
|
|
3139
|
+
validated.params = result.data;
|
|
3140
|
+
}
|
|
3141
|
+
}
|
|
3142
|
+
if (spec.request?.query) {
|
|
3143
|
+
const data = c.req.query();
|
|
3144
|
+
const result = await validator.parse(spec.request.query, data);
|
|
3145
|
+
if (!result.success) {
|
|
3146
|
+
issues.push(...result.issues);
|
|
3147
|
+
} else {
|
|
3148
|
+
validated.query = result.data;
|
|
3149
|
+
}
|
|
3150
|
+
}
|
|
3151
|
+
if (spec.request?.headers) {
|
|
3152
|
+
const data = c.req.header();
|
|
3153
|
+
const result = await validator.parse(spec.request.headers, data);
|
|
3154
|
+
if (!result.success) {
|
|
3155
|
+
issues.push(...result.issues);
|
|
3156
|
+
} else {
|
|
3157
|
+
validated.headers = result.data;
|
|
3158
|
+
}
|
|
3159
|
+
}
|
|
3160
|
+
if (spec.request?.body) {
|
|
3161
|
+
const contentType = c.req.header("Content-Type") || "";
|
|
3162
|
+
if (contentType.includes("application/json")) {
|
|
3163
|
+
try {
|
|
3164
|
+
const data = await c.req.json();
|
|
3165
|
+
const result = await validator.parse(spec.request.body, data);
|
|
3166
|
+
if (!result.success) {
|
|
3167
|
+
issues.push(...result.issues);
|
|
3168
|
+
} else {
|
|
3169
|
+
validated.body = result.data;
|
|
3170
|
+
}
|
|
3171
|
+
} catch {
|
|
3172
|
+
issues.push({ code: "invalid_json", message: "Invalid JSON body" });
|
|
3173
|
+
}
|
|
3174
|
+
}
|
|
3175
|
+
}
|
|
3176
|
+
if (issues.length > 0) {
|
|
3177
|
+
return c.json({
|
|
3178
|
+
error: "VALIDATION_ERROR",
|
|
3179
|
+
message: "Request validation failed",
|
|
3180
|
+
issues
|
|
3181
|
+
}, 400);
|
|
3182
|
+
}
|
|
3183
|
+
c.set("kanjijs.validated.params", validated.params);
|
|
3184
|
+
c.set("kanjijs.validated.query", validated.query);
|
|
3185
|
+
c.set("kanjijs.validated.headers", validated.headers);
|
|
3186
|
+
c.set("kanjijs.validated.body", validated.body);
|
|
3187
|
+
c.set("kanjijs.validated", validated);
|
|
3188
|
+
await next();
|
|
3189
|
+
};
|
|
3190
|
+
}
|
|
3191
|
+
|
|
3192
|
+
// src/filter.ts
|
|
3193
|
+
class KanjijsExceptionFilter {
|
|
3194
|
+
catch(exception, c) {
|
|
3195
|
+
let status = 500;
|
|
3196
|
+
let message = "Internal Server Error";
|
|
3197
|
+
let errorType = "InternalServerError";
|
|
3198
|
+
if (exception instanceof HttpException) {
|
|
3199
|
+
status = exception.getStatus();
|
|
3200
|
+
message = exception.getResponse();
|
|
3201
|
+
errorType = "HttpException";
|
|
3202
|
+
} else if (exception instanceof HTTPException) {
|
|
3203
|
+
status = exception.status;
|
|
3204
|
+
message = exception.message;
|
|
3205
|
+
errorType = "HonoHttpException";
|
|
3206
|
+
} else if (exception?.name === "ZodError" || Array.isArray(exception?.issues)) {
|
|
3207
|
+
status = 400;
|
|
3208
|
+
message = exception.issues;
|
|
3209
|
+
errorType = "ValidationError";
|
|
3210
|
+
} else if (exception instanceof Error) {
|
|
3211
|
+
message = exception.message;
|
|
3212
|
+
errorType = exception.name;
|
|
3213
|
+
}
|
|
3214
|
+
return c.json({
|
|
3215
|
+
statusCode: status,
|
|
3216
|
+
message,
|
|
3217
|
+
error: errorType,
|
|
3218
|
+
timestamp: new Date().toISOString(),
|
|
3219
|
+
requestId: c.header("x-request-id")
|
|
3220
|
+
}, status);
|
|
3221
|
+
}
|
|
3222
|
+
}
|
|
3223
|
+
|
|
3224
|
+
// src/adapter.ts
|
|
3225
|
+
class KanjijsAdapter {
|
|
3226
|
+
static create(rootModule, optionsOrValidator) {
|
|
3227
|
+
const app = new Hono2({ strict: false });
|
|
3228
|
+
let validator;
|
|
3229
|
+
let globalPrefix = "";
|
|
3230
|
+
const options = {};
|
|
3231
|
+
if (optionsOrValidator) {
|
|
3232
|
+
if ("validate" in optionsOrValidator && typeof optionsOrValidator.validate === "function") {
|
|
3233
|
+
validator = optionsOrValidator;
|
|
3234
|
+
} else {
|
|
3235
|
+
const opts = optionsOrValidator;
|
|
3236
|
+
validator = opts.validator;
|
|
3237
|
+
globalPrefix = opts.globalPrefix || "";
|
|
3238
|
+
options.cors = opts.cors;
|
|
3239
|
+
options.helmet = opts.helmet;
|
|
3240
|
+
options.morgan = opts.morgan;
|
|
3241
|
+
}
|
|
3242
|
+
}
|
|
3243
|
+
if (options.morgan) {
|
|
3244
|
+
const loggerOpts = typeof options.morgan === "boolean" ? undefined : options.morgan;
|
|
3245
|
+
app.use("*", logger(loggerOpts));
|
|
3246
|
+
}
|
|
3247
|
+
if (options.helmet) {
|
|
3248
|
+
const helmetOpts = typeof options.helmet === "boolean" ? undefined : options.helmet;
|
|
3249
|
+
app.use("*", secureHeaders(helmetOpts));
|
|
3250
|
+
}
|
|
3251
|
+
if (options.cors) {
|
|
3252
|
+
const corsOpts = typeof options.cors === "boolean" ? undefined : options.cors;
|
|
3253
|
+
app.use("*", cors(corsOpts));
|
|
3254
|
+
}
|
|
3255
|
+
if (globalPrefix) {
|
|
3256
|
+
if (!globalPrefix.startsWith("/"))
|
|
3257
|
+
globalPrefix = `/${globalPrefix}`;
|
|
3258
|
+
if (globalPrefix.endsWith("/"))
|
|
3259
|
+
globalPrefix = globalPrefix.slice(0, -1);
|
|
3260
|
+
}
|
|
3261
|
+
const exceptionFilter = new KanjijsExceptionFilter;
|
|
3262
|
+
app.onError((err, c) => exceptionFilter.catch(err, c));
|
|
3263
|
+
app.notFound((c) => exceptionFilter.catch(new HTTPException(404, { message: "Not Found" }), c));
|
|
3264
|
+
app.use("*", async (c, next) => {
|
|
3265
|
+
const requestId = c.req.header("x-request-id") || crypto.randomUUID();
|
|
3266
|
+
c.header("x-request-id", requestId);
|
|
3267
|
+
await kanjijsContext.run({ requestId }, async () => {
|
|
3268
|
+
await next();
|
|
3269
|
+
});
|
|
3270
|
+
});
|
|
3271
|
+
const compiler = new ModuleCompiler;
|
|
3272
|
+
const container = compiler.compile(rootModule);
|
|
3273
|
+
try {
|
|
3274
|
+
const globalMiddleware = container.resolve(GLOBAL_MIDDLEWARE_TOKEN);
|
|
3275
|
+
if (globalMiddleware) {
|
|
3276
|
+
console.log("[Kanjijs] Registering Global Middleware!!!");
|
|
3277
|
+
app.use("*", globalMiddleware);
|
|
3278
|
+
}
|
|
3279
|
+
} catch (e) {}
|
|
3280
|
+
const visited = new Set;
|
|
3281
|
+
const controllers = this.findControllers(rootModule, visited);
|
|
3282
|
+
for (const ControllerClass of controllers) {
|
|
3283
|
+
this.registerController(ControllerClass, app, validator, globalPrefix, container);
|
|
3284
|
+
}
|
|
3285
|
+
return { app, container };
|
|
3286
|
+
}
|
|
3287
|
+
static findControllers(target, visited) {
|
|
3288
|
+
const moduleClass = target.module || target;
|
|
3289
|
+
if (visited.has(moduleClass))
|
|
3290
|
+
return [];
|
|
3291
|
+
visited.add(moduleClass);
|
|
3292
|
+
const meta = MetadataStorage.getModule(moduleClass);
|
|
3293
|
+
if (!meta)
|
|
3294
|
+
return [];
|
|
3295
|
+
const controllers = [...meta.controllers || []];
|
|
3296
|
+
const imports = [...meta.imports || [], ...target.imports || []];
|
|
3297
|
+
for (const imp of imports) {
|
|
3298
|
+
controllers.push(...this.findControllers(imp, visited));
|
|
3299
|
+
}
|
|
3300
|
+
return controllers;
|
|
3301
|
+
}
|
|
3302
|
+
static registerController(ControllerClass, app, validator, globalPrefix, container) {
|
|
3303
|
+
const instance = container.resolve(ControllerClass);
|
|
3304
|
+
const controllerMeta = MetadataStorage.getController(ControllerClass);
|
|
3305
|
+
if (!controllerMeta)
|
|
3306
|
+
return;
|
|
3307
|
+
const prefix = controllerMeta.prefix;
|
|
3308
|
+
const routes = MetadataStorage.getRoutes(ControllerClass.prototype);
|
|
3309
|
+
if (!routes)
|
|
3310
|
+
return;
|
|
3311
|
+
for (const [methodName, routeMeta] of routes) {
|
|
3312
|
+
let fullPath = `${globalPrefix}${prefix}${routeMeta.path}`.replace(/\/+/g, "/");
|
|
3313
|
+
if (fullPath !== "/" && fullPath.endsWith("/")) {
|
|
3314
|
+
fullPath = fullPath.slice(0, -1);
|
|
3315
|
+
}
|
|
3316
|
+
console.log(`[Kanjijs] Registering ${routeMeta.method} ${fullPath}`);
|
|
3317
|
+
const handlers = [];
|
|
3318
|
+
if (controllerMeta.middlewares) {
|
|
3319
|
+
handlers.push(...controllerMeta.middlewares);
|
|
3320
|
+
}
|
|
3321
|
+
if (routeMeta.middlewares) {
|
|
3322
|
+
handlers.push(...routeMeta.middlewares);
|
|
3323
|
+
}
|
|
3324
|
+
if (routeMeta.contract && validator) {
|
|
3325
|
+
handlers.push(createValidationMiddleware(routeMeta.contract, validator));
|
|
3326
|
+
}
|
|
3327
|
+
handlers.push(async (c) => {
|
|
3328
|
+
return instance[methodName](c);
|
|
3329
|
+
});
|
|
3330
|
+
app.on([routeMeta.method], [fullPath], ...handlers);
|
|
3331
|
+
}
|
|
3332
|
+
}
|
|
3333
|
+
}
|
|
3334
|
+
export {
|
|
3335
|
+
KanjijsAdapter
|
|
3336
|
+
};
|