docs-i18n 0.2.2 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{assemble-ZHDLGVTL.js → assemble-IOHQYYHI.js} +4 -3
- package/dist/build-4EQEL4NI.js +12 -0
- package/dist/build2-3W5WMFHZ.js +4901 -0
- package/dist/chunk-3YNFMSJH.js +30 -0
- package/dist/chunk-55MBYBVK.js +368 -0
- package/dist/{chunk-PHDMD6EM.js → chunk-AKLW2MUS.js} +7 -29
- package/dist/chunk-FYDB7MZX.js +38944 -0
- package/dist/chunk-O35QHRY6.js +6 -0
- package/dist/chunk-PTIH4GGE.js +44 -0
- package/dist/{chunk-OSMPWXSQ.js → chunk-QSVWLTGQ.js} +1 -1
- package/dist/chunk-SUIDX6IZ.js +122 -0
- package/dist/chunk-VKKNQBDN.js +6487 -0
- package/dist/cli.js +7 -6
- package/dist/dist-6C32URTL.js +19 -0
- package/dist/dist-HOWMMQFV.js +6677 -0
- package/dist/false-JGP4AGWN.js +7 -0
- package/dist/main-QVE5TVA3.js +2505 -0
- package/dist/node-4GLCLDJ6.js +875 -0
- package/dist/node-NUDVMOF2.js +129 -0
- package/dist/postcss-3SK7VUC2.js +5886 -0
- package/dist/postcss-import-JD46KA2Z.js +458 -0
- package/dist/prompt-BYQIwEjg-TG7DLENB.js +915 -0
- package/dist/{rescan-OJTVWDAP.js → rescan-VB2PILB2.js} +3 -2
- package/dist/server-HUXOPTUA.js +550 -0
- package/dist/{status-ZG7F3FRT.js → status-EWQEACVF.js} +2 -1
- package/dist/translate-F3AQFN6X.js +707 -0
- package/package.json +3 -1
- package/src/admin/server/services/job-manager.ts +4 -3
- package/dist/chunk-I74LIORX.js +0 -11211
- package/dist/server-DPAACODY.js +0 -2744
- package/dist/translate-2PCYIWIG.js +0 -14531
package/dist/server-DPAACODY.js
DELETED
|
@@ -1,2744 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
init_parser,
|
|
3
|
-
parseMdx
|
|
4
|
-
} from "./chunk-I74LIORX.js";
|
|
5
|
-
import {
|
|
6
|
-
TranslationCache
|
|
7
|
-
} from "./chunk-XEOYZUHS.js";
|
|
8
|
-
import {
|
|
9
|
-
flattenSources
|
|
10
|
-
} from "./chunk-PHDMD6EM.js";
|
|
11
|
-
|
|
12
|
-
// src/admin/server/index.ts
|
|
13
|
-
import { createServer } from "http";
|
|
14
|
-
import { resolve as resolve2 } from "path";
|
|
15
|
-
|
|
16
|
-
// node_modules/hono/dist/compose.js
|
|
17
|
-
var compose = (middleware, onError, onNotFound) => {
|
|
18
|
-
return (context, next) => {
|
|
19
|
-
let index = -1;
|
|
20
|
-
return dispatch(0);
|
|
21
|
-
async function dispatch(i) {
|
|
22
|
-
if (i <= index) {
|
|
23
|
-
throw new Error("next() called multiple times");
|
|
24
|
-
}
|
|
25
|
-
index = i;
|
|
26
|
-
let res;
|
|
27
|
-
let isError = false;
|
|
28
|
-
let handler;
|
|
29
|
-
if (middleware[i]) {
|
|
30
|
-
handler = middleware[i][0][0];
|
|
31
|
-
context.req.routeIndex = i;
|
|
32
|
-
} else {
|
|
33
|
-
handler = i === middleware.length && next || void 0;
|
|
34
|
-
}
|
|
35
|
-
if (handler) {
|
|
36
|
-
try {
|
|
37
|
-
res = await handler(context, () => dispatch(i + 1));
|
|
38
|
-
} catch (err) {
|
|
39
|
-
if (err instanceof Error && onError) {
|
|
40
|
-
context.error = err;
|
|
41
|
-
res = await onError(err, context);
|
|
42
|
-
isError = true;
|
|
43
|
-
} else {
|
|
44
|
-
throw err;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
} else {
|
|
48
|
-
if (context.finalized === false && onNotFound) {
|
|
49
|
-
res = await onNotFound(context);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
if (res && (context.finalized === false || isError)) {
|
|
53
|
-
context.res = res;
|
|
54
|
-
}
|
|
55
|
-
return context;
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
// node_modules/hono/dist/request/constants.js
|
|
61
|
-
var GET_MATCH_RESULT = /* @__PURE__ */ Symbol();
|
|
62
|
-
|
|
63
|
-
// node_modules/hono/dist/utils/body.js
|
|
64
|
-
var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
|
|
65
|
-
const { all = false, dot = false } = options;
|
|
66
|
-
const headers = request instanceof HonoRequest ? request.raw.headers : request.headers;
|
|
67
|
-
const contentType = headers.get("Content-Type");
|
|
68
|
-
if (contentType?.startsWith("multipart/form-data") || contentType?.startsWith("application/x-www-form-urlencoded")) {
|
|
69
|
-
return parseFormData(request, { all, dot });
|
|
70
|
-
}
|
|
71
|
-
return {};
|
|
72
|
-
};
|
|
73
|
-
async function parseFormData(request, options) {
|
|
74
|
-
const formData = await request.formData();
|
|
75
|
-
if (formData) {
|
|
76
|
-
return convertFormDataToBodyData(formData, options);
|
|
77
|
-
}
|
|
78
|
-
return {};
|
|
79
|
-
}
|
|
80
|
-
function convertFormDataToBodyData(formData, options) {
|
|
81
|
-
const form = /* @__PURE__ */ Object.create(null);
|
|
82
|
-
formData.forEach((value, key) => {
|
|
83
|
-
const shouldParseAllValues = options.all || key.endsWith("[]");
|
|
84
|
-
if (!shouldParseAllValues) {
|
|
85
|
-
form[key] = value;
|
|
86
|
-
} else {
|
|
87
|
-
handleParsingAllValues(form, key, value);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
if (options.dot) {
|
|
91
|
-
Object.entries(form).forEach(([key, value]) => {
|
|
92
|
-
const shouldParseDotValues = key.includes(".");
|
|
93
|
-
if (shouldParseDotValues) {
|
|
94
|
-
handleParsingNestedValues(form, key, value);
|
|
95
|
-
delete form[key];
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
return form;
|
|
100
|
-
}
|
|
101
|
-
var handleParsingAllValues = (form, key, value) => {
|
|
102
|
-
if (form[key] !== void 0) {
|
|
103
|
-
if (Array.isArray(form[key])) {
|
|
104
|
-
;
|
|
105
|
-
form[key].push(value);
|
|
106
|
-
} else {
|
|
107
|
-
form[key] = [form[key], value];
|
|
108
|
-
}
|
|
109
|
-
} else {
|
|
110
|
-
if (!key.endsWith("[]")) {
|
|
111
|
-
form[key] = value;
|
|
112
|
-
} else {
|
|
113
|
-
form[key] = [value];
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
var handleParsingNestedValues = (form, key, value) => {
|
|
118
|
-
if (/(?:^|\.)__proto__\./.test(key)) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
let nestedForm = form;
|
|
122
|
-
const keys = key.split(".");
|
|
123
|
-
keys.forEach((key2, index) => {
|
|
124
|
-
if (index === keys.length - 1) {
|
|
125
|
-
nestedForm[key2] = value;
|
|
126
|
-
} else {
|
|
127
|
-
if (!nestedForm[key2] || typeof nestedForm[key2] !== "object" || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) {
|
|
128
|
-
nestedForm[key2] = /* @__PURE__ */ Object.create(null);
|
|
129
|
-
}
|
|
130
|
-
nestedForm = nestedForm[key2];
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
// node_modules/hono/dist/utils/url.js
|
|
136
|
-
var splitPath = (path) => {
|
|
137
|
-
const paths = path.split("/");
|
|
138
|
-
if (paths[0] === "") {
|
|
139
|
-
paths.shift();
|
|
140
|
-
}
|
|
141
|
-
return paths;
|
|
142
|
-
};
|
|
143
|
-
var splitRoutingPath = (routePath) => {
|
|
144
|
-
const { groups, path } = extractGroupsFromPath(routePath);
|
|
145
|
-
const paths = splitPath(path);
|
|
146
|
-
return replaceGroupMarks(paths, groups);
|
|
147
|
-
};
|
|
148
|
-
var extractGroupsFromPath = (path) => {
|
|
149
|
-
const groups = [];
|
|
150
|
-
path = path.replace(/\{[^}]+\}/g, (match2, index) => {
|
|
151
|
-
const mark = `@${index}`;
|
|
152
|
-
groups.push([mark, match2]);
|
|
153
|
-
return mark;
|
|
154
|
-
});
|
|
155
|
-
return { groups, path };
|
|
156
|
-
};
|
|
157
|
-
var replaceGroupMarks = (paths, groups) => {
|
|
158
|
-
for (let i = groups.length - 1; i >= 0; i--) {
|
|
159
|
-
const [mark] = groups[i];
|
|
160
|
-
for (let j = paths.length - 1; j >= 0; j--) {
|
|
161
|
-
if (paths[j].includes(mark)) {
|
|
162
|
-
paths[j] = paths[j].replace(mark, groups[i][1]);
|
|
163
|
-
break;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
return paths;
|
|
168
|
-
};
|
|
169
|
-
var patternCache = {};
|
|
170
|
-
var getPattern = (label, next) => {
|
|
171
|
-
if (label === "*") {
|
|
172
|
-
return "*";
|
|
173
|
-
}
|
|
174
|
-
const match2 = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
175
|
-
if (match2) {
|
|
176
|
-
const cacheKey = `${label}#${next}`;
|
|
177
|
-
if (!patternCache[cacheKey]) {
|
|
178
|
-
if (match2[2]) {
|
|
179
|
-
patternCache[cacheKey] = next && next[0] !== ":" && next[0] !== "*" ? [cacheKey, match2[1], new RegExp(`^${match2[2]}(?=/${next})`)] : [label, match2[1], new RegExp(`^${match2[2]}$`)];
|
|
180
|
-
} else {
|
|
181
|
-
patternCache[cacheKey] = [label, match2[1], true];
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
return patternCache[cacheKey];
|
|
185
|
-
}
|
|
186
|
-
return null;
|
|
187
|
-
};
|
|
188
|
-
var tryDecode = (str, decoder) => {
|
|
189
|
-
try {
|
|
190
|
-
return decoder(str);
|
|
191
|
-
} catch {
|
|
192
|
-
return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match2) => {
|
|
193
|
-
try {
|
|
194
|
-
return decoder(match2);
|
|
195
|
-
} catch {
|
|
196
|
-
return match2;
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
var tryDecodeURI = (str) => tryDecode(str, decodeURI);
|
|
202
|
-
var getPath = (request) => {
|
|
203
|
-
const url = request.url;
|
|
204
|
-
const start = url.indexOf("/", url.indexOf(":") + 4);
|
|
205
|
-
let i = start;
|
|
206
|
-
for (; i < url.length; i++) {
|
|
207
|
-
const charCode = url.charCodeAt(i);
|
|
208
|
-
if (charCode === 37) {
|
|
209
|
-
const queryIndex = url.indexOf("?", i);
|
|
210
|
-
const hashIndex = url.indexOf("#", i);
|
|
211
|
-
const end = queryIndex === -1 ? hashIndex === -1 ? void 0 : hashIndex : hashIndex === -1 ? queryIndex : Math.min(queryIndex, hashIndex);
|
|
212
|
-
const path = url.slice(start, end);
|
|
213
|
-
return tryDecodeURI(path.includes("%25") ? path.replace(/%25/g, "%2525") : path);
|
|
214
|
-
} else if (charCode === 63 || charCode === 35) {
|
|
215
|
-
break;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
return url.slice(start, i);
|
|
219
|
-
};
|
|
220
|
-
var getPathNoStrict = (request) => {
|
|
221
|
-
const result = getPath(request);
|
|
222
|
-
return result.length > 1 && result.at(-1) === "/" ? result.slice(0, -1) : result;
|
|
223
|
-
};
|
|
224
|
-
var mergePath = (base, sub, ...rest) => {
|
|
225
|
-
if (rest.length) {
|
|
226
|
-
sub = mergePath(sub, ...rest);
|
|
227
|
-
}
|
|
228
|
-
return `${base?.[0] === "/" ? "" : "/"}${base}${sub === "/" ? "" : `${base?.at(-1) === "/" ? "" : "/"}${sub?.[0] === "/" ? sub.slice(1) : sub}`}`;
|
|
229
|
-
};
|
|
230
|
-
var checkOptionalParameter = (path) => {
|
|
231
|
-
if (path.charCodeAt(path.length - 1) !== 63 || !path.includes(":")) {
|
|
232
|
-
return null;
|
|
233
|
-
}
|
|
234
|
-
const segments = path.split("/");
|
|
235
|
-
const results = [];
|
|
236
|
-
let basePath = "";
|
|
237
|
-
segments.forEach((segment) => {
|
|
238
|
-
if (segment !== "" && !/\:/.test(segment)) {
|
|
239
|
-
basePath += "/" + segment;
|
|
240
|
-
} else if (/\:/.test(segment)) {
|
|
241
|
-
if (/\?/.test(segment)) {
|
|
242
|
-
if (results.length === 0 && basePath === "") {
|
|
243
|
-
results.push("/");
|
|
244
|
-
} else {
|
|
245
|
-
results.push(basePath);
|
|
246
|
-
}
|
|
247
|
-
const optionalSegment = segment.replace("?", "");
|
|
248
|
-
basePath += "/" + optionalSegment;
|
|
249
|
-
results.push(basePath);
|
|
250
|
-
} else {
|
|
251
|
-
basePath += "/" + segment;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
return results.filter((v, i, a) => a.indexOf(v) === i);
|
|
256
|
-
};
|
|
257
|
-
var _decodeURI = (value) => {
|
|
258
|
-
if (!/[%+]/.test(value)) {
|
|
259
|
-
return value;
|
|
260
|
-
}
|
|
261
|
-
if (value.indexOf("+") !== -1) {
|
|
262
|
-
value = value.replace(/\+/g, " ");
|
|
263
|
-
}
|
|
264
|
-
return value.indexOf("%") !== -1 ? tryDecode(value, decodeURIComponent_) : value;
|
|
265
|
-
};
|
|
266
|
-
var _getQueryParam = (url, key, multiple) => {
|
|
267
|
-
let encoded;
|
|
268
|
-
if (!multiple && key && !/[%+]/.test(key)) {
|
|
269
|
-
let keyIndex2 = url.indexOf("?", 8);
|
|
270
|
-
if (keyIndex2 === -1) {
|
|
271
|
-
return void 0;
|
|
272
|
-
}
|
|
273
|
-
if (!url.startsWith(key, keyIndex2 + 1)) {
|
|
274
|
-
keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
|
275
|
-
}
|
|
276
|
-
while (keyIndex2 !== -1) {
|
|
277
|
-
const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1);
|
|
278
|
-
if (trailingKeyCode === 61) {
|
|
279
|
-
const valueIndex = keyIndex2 + key.length + 2;
|
|
280
|
-
const endIndex = url.indexOf("&", valueIndex);
|
|
281
|
-
return _decodeURI(url.slice(valueIndex, endIndex === -1 ? void 0 : endIndex));
|
|
282
|
-
} else if (trailingKeyCode == 38 || isNaN(trailingKeyCode)) {
|
|
283
|
-
return "";
|
|
284
|
-
}
|
|
285
|
-
keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
|
286
|
-
}
|
|
287
|
-
encoded = /[%+]/.test(url);
|
|
288
|
-
if (!encoded) {
|
|
289
|
-
return void 0;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
const results = {};
|
|
293
|
-
encoded ??= /[%+]/.test(url);
|
|
294
|
-
let keyIndex = url.indexOf("?", 8);
|
|
295
|
-
while (keyIndex !== -1) {
|
|
296
|
-
const nextKeyIndex = url.indexOf("&", keyIndex + 1);
|
|
297
|
-
let valueIndex = url.indexOf("=", keyIndex);
|
|
298
|
-
if (valueIndex > nextKeyIndex && nextKeyIndex !== -1) {
|
|
299
|
-
valueIndex = -1;
|
|
300
|
-
}
|
|
301
|
-
let name = url.slice(
|
|
302
|
-
keyIndex + 1,
|
|
303
|
-
valueIndex === -1 ? nextKeyIndex === -1 ? void 0 : nextKeyIndex : valueIndex
|
|
304
|
-
);
|
|
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 ? void 0 : 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
|
-
;
|
|
326
|
-
results[name].push(value);
|
|
327
|
-
} else {
|
|
328
|
-
results[name] ??= value;
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
return key ? results[key] : results;
|
|
332
|
-
};
|
|
333
|
-
var getQueryParam = _getQueryParam;
|
|
334
|
-
var getQueryParams = (url, key) => {
|
|
335
|
-
return _getQueryParam(url, key, true);
|
|
336
|
-
};
|
|
337
|
-
var decodeURIComponent_ = decodeURIComponent;
|
|
338
|
-
|
|
339
|
-
// node_modules/hono/dist/request.js
|
|
340
|
-
var tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
|
|
341
|
-
var HonoRequest = class {
|
|
342
|
-
/**
|
|
343
|
-
* `.raw` can get the raw Request object.
|
|
344
|
-
*
|
|
345
|
-
* @see {@link https://hono.dev/docs/api/request#raw}
|
|
346
|
-
*
|
|
347
|
-
* @example
|
|
348
|
-
* ```ts
|
|
349
|
-
* // For Cloudflare Workers
|
|
350
|
-
* app.post('/', async (c) => {
|
|
351
|
-
* const metadata = c.req.raw.cf?.hostMetadata?
|
|
352
|
-
* ...
|
|
353
|
-
* })
|
|
354
|
-
* ```
|
|
355
|
-
*/
|
|
356
|
-
raw;
|
|
357
|
-
#validatedData;
|
|
358
|
-
// Short name of validatedData
|
|
359
|
-
#matchResult;
|
|
360
|
-
routeIndex = 0;
|
|
361
|
-
/**
|
|
362
|
-
* `.path` can get the pathname of the request.
|
|
363
|
-
*
|
|
364
|
-
* @see {@link https://hono.dev/docs/api/request#path}
|
|
365
|
-
*
|
|
366
|
-
* @example
|
|
367
|
-
* ```ts
|
|
368
|
-
* app.get('/about/me', (c) => {
|
|
369
|
-
* const pathname = c.req.path // `/about/me`
|
|
370
|
-
* })
|
|
371
|
-
* ```
|
|
372
|
-
*/
|
|
373
|
-
path;
|
|
374
|
-
bodyCache = {};
|
|
375
|
-
constructor(request, path = "/", matchResult = [[]]) {
|
|
376
|
-
this.raw = request;
|
|
377
|
-
this.path = path;
|
|
378
|
-
this.#matchResult = matchResult;
|
|
379
|
-
this.#validatedData = {};
|
|
380
|
-
}
|
|
381
|
-
param(key) {
|
|
382
|
-
return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
|
|
383
|
-
}
|
|
384
|
-
#getDecodedParam(key) {
|
|
385
|
-
const paramKey = this.#matchResult[0][this.routeIndex][1][key];
|
|
386
|
-
const param = this.#getParamValue(paramKey);
|
|
387
|
-
return param && /\%/.test(param) ? tryDecodeURIComponent(param) : param;
|
|
388
|
-
}
|
|
389
|
-
#getAllDecodedParams() {
|
|
390
|
-
const decoded = {};
|
|
391
|
-
const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
|
|
392
|
-
for (const key of keys) {
|
|
393
|
-
const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
|
|
394
|
-
if (value !== void 0) {
|
|
395
|
-
decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value;
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
return decoded;
|
|
399
|
-
}
|
|
400
|
-
#getParamValue(paramKey) {
|
|
401
|
-
return this.#matchResult[1] ? this.#matchResult[1][paramKey] : paramKey;
|
|
402
|
-
}
|
|
403
|
-
query(key) {
|
|
404
|
-
return getQueryParam(this.url, key);
|
|
405
|
-
}
|
|
406
|
-
queries(key) {
|
|
407
|
-
return getQueryParams(this.url, key);
|
|
408
|
-
}
|
|
409
|
-
header(name) {
|
|
410
|
-
if (name) {
|
|
411
|
-
return this.raw.headers.get(name) ?? void 0;
|
|
412
|
-
}
|
|
413
|
-
const headerData = {};
|
|
414
|
-
this.raw.headers.forEach((value, key) => {
|
|
415
|
-
headerData[key] = value;
|
|
416
|
-
});
|
|
417
|
-
return headerData;
|
|
418
|
-
}
|
|
419
|
-
async parseBody(options) {
|
|
420
|
-
return this.bodyCache.parsedBody ??= await parseBody(this, options);
|
|
421
|
-
}
|
|
422
|
-
#cachedBody = (key) => {
|
|
423
|
-
const { bodyCache, raw: raw2 } = this;
|
|
424
|
-
const cachedBody = bodyCache[key];
|
|
425
|
-
if (cachedBody) {
|
|
426
|
-
return cachedBody;
|
|
427
|
-
}
|
|
428
|
-
const anyCachedKey = Object.keys(bodyCache)[0];
|
|
429
|
-
if (anyCachedKey) {
|
|
430
|
-
return bodyCache[anyCachedKey].then((body) => {
|
|
431
|
-
if (anyCachedKey === "json") {
|
|
432
|
-
body = JSON.stringify(body);
|
|
433
|
-
}
|
|
434
|
-
return new Response(body)[key]();
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
|
-
return bodyCache[key] = raw2[key]();
|
|
438
|
-
};
|
|
439
|
-
/**
|
|
440
|
-
* `.json()` can parse Request body of type `application/json`
|
|
441
|
-
*
|
|
442
|
-
* @see {@link https://hono.dev/docs/api/request#json}
|
|
443
|
-
*
|
|
444
|
-
* @example
|
|
445
|
-
* ```ts
|
|
446
|
-
* app.post('/entry', async (c) => {
|
|
447
|
-
* const body = await c.req.json()
|
|
448
|
-
* })
|
|
449
|
-
* ```
|
|
450
|
-
*/
|
|
451
|
-
json() {
|
|
452
|
-
return this.#cachedBody("text").then((text) => JSON.parse(text));
|
|
453
|
-
}
|
|
454
|
-
/**
|
|
455
|
-
* `.text()` can parse Request body of type `text/plain`
|
|
456
|
-
*
|
|
457
|
-
* @see {@link https://hono.dev/docs/api/request#text}
|
|
458
|
-
*
|
|
459
|
-
* @example
|
|
460
|
-
* ```ts
|
|
461
|
-
* app.post('/entry', async (c) => {
|
|
462
|
-
* const body = await c.req.text()
|
|
463
|
-
* })
|
|
464
|
-
* ```
|
|
465
|
-
*/
|
|
466
|
-
text() {
|
|
467
|
-
return this.#cachedBody("text");
|
|
468
|
-
}
|
|
469
|
-
/**
|
|
470
|
-
* `.arrayBuffer()` parse Request body as an `ArrayBuffer`
|
|
471
|
-
*
|
|
472
|
-
* @see {@link https://hono.dev/docs/api/request#arraybuffer}
|
|
473
|
-
*
|
|
474
|
-
* @example
|
|
475
|
-
* ```ts
|
|
476
|
-
* app.post('/entry', async (c) => {
|
|
477
|
-
* const body = await c.req.arrayBuffer()
|
|
478
|
-
* })
|
|
479
|
-
* ```
|
|
480
|
-
*/
|
|
481
|
-
arrayBuffer() {
|
|
482
|
-
return this.#cachedBody("arrayBuffer");
|
|
483
|
-
}
|
|
484
|
-
/**
|
|
485
|
-
* Parses the request body as a `Blob`.
|
|
486
|
-
* @example
|
|
487
|
-
* ```ts
|
|
488
|
-
* app.post('/entry', async (c) => {
|
|
489
|
-
* const body = await c.req.blob();
|
|
490
|
-
* });
|
|
491
|
-
* ```
|
|
492
|
-
* @see https://hono.dev/docs/api/request#blob
|
|
493
|
-
*/
|
|
494
|
-
blob() {
|
|
495
|
-
return this.#cachedBody("blob");
|
|
496
|
-
}
|
|
497
|
-
/**
|
|
498
|
-
* Parses the request body as `FormData`.
|
|
499
|
-
* @example
|
|
500
|
-
* ```ts
|
|
501
|
-
* app.post('/entry', async (c) => {
|
|
502
|
-
* const body = await c.req.formData();
|
|
503
|
-
* });
|
|
504
|
-
* ```
|
|
505
|
-
* @see https://hono.dev/docs/api/request#formdata
|
|
506
|
-
*/
|
|
507
|
-
formData() {
|
|
508
|
-
return this.#cachedBody("formData");
|
|
509
|
-
}
|
|
510
|
-
/**
|
|
511
|
-
* Adds validated data to the request.
|
|
512
|
-
*
|
|
513
|
-
* @param target - The target of the validation.
|
|
514
|
-
* @param data - The validated data to add.
|
|
515
|
-
*/
|
|
516
|
-
addValidatedData(target, data) {
|
|
517
|
-
this.#validatedData[target] = data;
|
|
518
|
-
}
|
|
519
|
-
valid(target) {
|
|
520
|
-
return this.#validatedData[target];
|
|
521
|
-
}
|
|
522
|
-
/**
|
|
523
|
-
* `.url()` can get the request url strings.
|
|
524
|
-
*
|
|
525
|
-
* @see {@link https://hono.dev/docs/api/request#url}
|
|
526
|
-
*
|
|
527
|
-
* @example
|
|
528
|
-
* ```ts
|
|
529
|
-
* app.get('/about/me', (c) => {
|
|
530
|
-
* const url = c.req.url // `http://localhost:8787/about/me`
|
|
531
|
-
* ...
|
|
532
|
-
* })
|
|
533
|
-
* ```
|
|
534
|
-
*/
|
|
535
|
-
get url() {
|
|
536
|
-
return this.raw.url;
|
|
537
|
-
}
|
|
538
|
-
/**
|
|
539
|
-
* `.method()` can get the method name of the request.
|
|
540
|
-
*
|
|
541
|
-
* @see {@link https://hono.dev/docs/api/request#method}
|
|
542
|
-
*
|
|
543
|
-
* @example
|
|
544
|
-
* ```ts
|
|
545
|
-
* app.get('/about/me', (c) => {
|
|
546
|
-
* const method = c.req.method // `GET`
|
|
547
|
-
* })
|
|
548
|
-
* ```
|
|
549
|
-
*/
|
|
550
|
-
get method() {
|
|
551
|
-
return this.raw.method;
|
|
552
|
-
}
|
|
553
|
-
get [GET_MATCH_RESULT]() {
|
|
554
|
-
return this.#matchResult;
|
|
555
|
-
}
|
|
556
|
-
/**
|
|
557
|
-
* `.matchedRoutes()` can return a matched route in the handler
|
|
558
|
-
*
|
|
559
|
-
* @deprecated
|
|
560
|
-
*
|
|
561
|
-
* Use matchedRoutes helper defined in "hono/route" instead.
|
|
562
|
-
*
|
|
563
|
-
* @see {@link https://hono.dev/docs/api/request#matchedroutes}
|
|
564
|
-
*
|
|
565
|
-
* @example
|
|
566
|
-
* ```ts
|
|
567
|
-
* app.use('*', async function logger(c, next) {
|
|
568
|
-
* await next()
|
|
569
|
-
* c.req.matchedRoutes.forEach(({ handler, method, path }, i) => {
|
|
570
|
-
* const name = handler.name || (handler.length < 2 ? '[handler]' : '[middleware]')
|
|
571
|
-
* console.log(
|
|
572
|
-
* method,
|
|
573
|
-
* ' ',
|
|
574
|
-
* path,
|
|
575
|
-
* ' '.repeat(Math.max(10 - path.length, 0)),
|
|
576
|
-
* name,
|
|
577
|
-
* i === c.req.routeIndex ? '<- respond from here' : ''
|
|
578
|
-
* )
|
|
579
|
-
* })
|
|
580
|
-
* })
|
|
581
|
-
* ```
|
|
582
|
-
*/
|
|
583
|
-
get matchedRoutes() {
|
|
584
|
-
return this.#matchResult[0].map(([[, route]]) => route);
|
|
585
|
-
}
|
|
586
|
-
/**
|
|
587
|
-
* `routePath()` can retrieve the path registered within the handler
|
|
588
|
-
*
|
|
589
|
-
* @deprecated
|
|
590
|
-
*
|
|
591
|
-
* Use routePath helper defined in "hono/route" instead.
|
|
592
|
-
*
|
|
593
|
-
* @see {@link https://hono.dev/docs/api/request#routepath}
|
|
594
|
-
*
|
|
595
|
-
* @example
|
|
596
|
-
* ```ts
|
|
597
|
-
* app.get('/posts/:id', (c) => {
|
|
598
|
-
* return c.json({ path: c.req.routePath })
|
|
599
|
-
* })
|
|
600
|
-
* ```
|
|
601
|
-
*/
|
|
602
|
-
get routePath() {
|
|
603
|
-
return this.#matchResult[0].map(([[, route]]) => route)[this.routeIndex].path;
|
|
604
|
-
}
|
|
605
|
-
};
|
|
606
|
-
|
|
607
|
-
// node_modules/hono/dist/utils/html.js
|
|
608
|
-
var HtmlEscapedCallbackPhase = {
|
|
609
|
-
Stringify: 1,
|
|
610
|
-
BeforeStream: 2,
|
|
611
|
-
Stream: 3
|
|
612
|
-
};
|
|
613
|
-
var raw = (value, callbacks) => {
|
|
614
|
-
const escapedString = new String(value);
|
|
615
|
-
escapedString.isEscaped = true;
|
|
616
|
-
escapedString.callbacks = callbacks;
|
|
617
|
-
return escapedString;
|
|
618
|
-
};
|
|
619
|
-
var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) => {
|
|
620
|
-
if (typeof str === "object" && !(str instanceof String)) {
|
|
621
|
-
if (!(str instanceof Promise)) {
|
|
622
|
-
str = str.toString();
|
|
623
|
-
}
|
|
624
|
-
if (str instanceof Promise) {
|
|
625
|
-
str = await str;
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
const callbacks = str.callbacks;
|
|
629
|
-
if (!callbacks?.length) {
|
|
630
|
-
return Promise.resolve(str);
|
|
631
|
-
}
|
|
632
|
-
if (buffer) {
|
|
633
|
-
buffer[0] += str;
|
|
634
|
-
} else {
|
|
635
|
-
buffer = [str];
|
|
636
|
-
}
|
|
637
|
-
const resStr = Promise.all(callbacks.map((c) => c({ phase, buffer, context }))).then(
|
|
638
|
-
(res) => Promise.all(
|
|
639
|
-
res.filter(Boolean).map((str2) => resolveCallback(str2, phase, false, context, buffer))
|
|
640
|
-
).then(() => buffer[0])
|
|
641
|
-
);
|
|
642
|
-
if (preserveCallbacks) {
|
|
643
|
-
return raw(await resStr, callbacks);
|
|
644
|
-
} else {
|
|
645
|
-
return resStr;
|
|
646
|
-
}
|
|
647
|
-
};
|
|
648
|
-
|
|
649
|
-
// node_modules/hono/dist/context.js
|
|
650
|
-
var TEXT_PLAIN = "text/plain; charset=UTF-8";
|
|
651
|
-
var setDefaultContentType = (contentType, headers) => {
|
|
652
|
-
return {
|
|
653
|
-
"Content-Type": contentType,
|
|
654
|
-
...headers
|
|
655
|
-
};
|
|
656
|
-
};
|
|
657
|
-
var createResponseInstance = (body, init) => new Response(body, init);
|
|
658
|
-
var Context = class {
|
|
659
|
-
#rawRequest;
|
|
660
|
-
#req;
|
|
661
|
-
/**
|
|
662
|
-
* `.env` can get bindings (environment variables, secrets, KV namespaces, D1 database, R2 bucket etc.) in Cloudflare Workers.
|
|
663
|
-
*
|
|
664
|
-
* @see {@link https://hono.dev/docs/api/context#env}
|
|
665
|
-
*
|
|
666
|
-
* @example
|
|
667
|
-
* ```ts
|
|
668
|
-
* // Environment object for Cloudflare Workers
|
|
669
|
-
* app.get('*', async c => {
|
|
670
|
-
* const counter = c.env.COUNTER
|
|
671
|
-
* })
|
|
672
|
-
* ```
|
|
673
|
-
*/
|
|
674
|
-
env = {};
|
|
675
|
-
#var;
|
|
676
|
-
finalized = false;
|
|
677
|
-
/**
|
|
678
|
-
* `.error` can get the error object from the middleware if the Handler throws an error.
|
|
679
|
-
*
|
|
680
|
-
* @see {@link https://hono.dev/docs/api/context#error}
|
|
681
|
-
*
|
|
682
|
-
* @example
|
|
683
|
-
* ```ts
|
|
684
|
-
* app.use('*', async (c, next) => {
|
|
685
|
-
* await next()
|
|
686
|
-
* if (c.error) {
|
|
687
|
-
* // do something...
|
|
688
|
-
* }
|
|
689
|
-
* })
|
|
690
|
-
* ```
|
|
691
|
-
*/
|
|
692
|
-
error;
|
|
693
|
-
#status;
|
|
694
|
-
#executionCtx;
|
|
695
|
-
#res;
|
|
696
|
-
#layout;
|
|
697
|
-
#renderer;
|
|
698
|
-
#notFoundHandler;
|
|
699
|
-
#preparedHeaders;
|
|
700
|
-
#matchResult;
|
|
701
|
-
#path;
|
|
702
|
-
/**
|
|
703
|
-
* Creates an instance of the Context class.
|
|
704
|
-
*
|
|
705
|
-
* @param req - The Request object.
|
|
706
|
-
* @param options - Optional configuration options for the context.
|
|
707
|
-
*/
|
|
708
|
-
constructor(req, options) {
|
|
709
|
-
this.#rawRequest = req;
|
|
710
|
-
if (options) {
|
|
711
|
-
this.#executionCtx = options.executionCtx;
|
|
712
|
-
this.env = options.env;
|
|
713
|
-
this.#notFoundHandler = options.notFoundHandler;
|
|
714
|
-
this.#path = options.path;
|
|
715
|
-
this.#matchResult = options.matchResult;
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
/**
|
|
719
|
-
* `.req` is the instance of {@link HonoRequest}.
|
|
720
|
-
*/
|
|
721
|
-
get req() {
|
|
722
|
-
this.#req ??= new HonoRequest(this.#rawRequest, this.#path, this.#matchResult);
|
|
723
|
-
return this.#req;
|
|
724
|
-
}
|
|
725
|
-
/**
|
|
726
|
-
* @see {@link https://hono.dev/docs/api/context#event}
|
|
727
|
-
* The FetchEvent associated with the current request.
|
|
728
|
-
*
|
|
729
|
-
* @throws Will throw an error if the context does not have a FetchEvent.
|
|
730
|
-
*/
|
|
731
|
-
get event() {
|
|
732
|
-
if (this.#executionCtx && "respondWith" in this.#executionCtx) {
|
|
733
|
-
return this.#executionCtx;
|
|
734
|
-
} else {
|
|
735
|
-
throw Error("This context has no FetchEvent");
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
/**
|
|
739
|
-
* @see {@link https://hono.dev/docs/api/context#executionctx}
|
|
740
|
-
* The ExecutionContext associated with the current request.
|
|
741
|
-
*
|
|
742
|
-
* @throws Will throw an error if the context does not have an ExecutionContext.
|
|
743
|
-
*/
|
|
744
|
-
get executionCtx() {
|
|
745
|
-
if (this.#executionCtx) {
|
|
746
|
-
return this.#executionCtx;
|
|
747
|
-
} else {
|
|
748
|
-
throw Error("This context has no ExecutionContext");
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
/**
|
|
752
|
-
* @see {@link https://hono.dev/docs/api/context#res}
|
|
753
|
-
* The Response object for the current request.
|
|
754
|
-
*/
|
|
755
|
-
get res() {
|
|
756
|
-
return this.#res ||= createResponseInstance(null, {
|
|
757
|
-
headers: this.#preparedHeaders ??= new Headers()
|
|
758
|
-
});
|
|
759
|
-
}
|
|
760
|
-
/**
|
|
761
|
-
* Sets the Response object for the current request.
|
|
762
|
-
*
|
|
763
|
-
* @param _res - The Response object to set.
|
|
764
|
-
*/
|
|
765
|
-
set res(_res) {
|
|
766
|
-
if (this.#res && _res) {
|
|
767
|
-
_res = createResponseInstance(_res.body, _res);
|
|
768
|
-
for (const [k, v] of this.#res.headers.entries()) {
|
|
769
|
-
if (k === "content-type") {
|
|
770
|
-
continue;
|
|
771
|
-
}
|
|
772
|
-
if (k === "set-cookie") {
|
|
773
|
-
const cookies = this.#res.headers.getSetCookie();
|
|
774
|
-
_res.headers.delete("set-cookie");
|
|
775
|
-
for (const cookie of cookies) {
|
|
776
|
-
_res.headers.append("set-cookie", cookie);
|
|
777
|
-
}
|
|
778
|
-
} else {
|
|
779
|
-
_res.headers.set(k, v);
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
this.#res = _res;
|
|
784
|
-
this.finalized = true;
|
|
785
|
-
}
|
|
786
|
-
/**
|
|
787
|
-
* `.render()` can create a response within a layout.
|
|
788
|
-
*
|
|
789
|
-
* @see {@link https://hono.dev/docs/api/context#render-setrenderer}
|
|
790
|
-
*
|
|
791
|
-
* @example
|
|
792
|
-
* ```ts
|
|
793
|
-
* app.get('/', (c) => {
|
|
794
|
-
* return c.render('Hello!')
|
|
795
|
-
* })
|
|
796
|
-
* ```
|
|
797
|
-
*/
|
|
798
|
-
render = (...args) => {
|
|
799
|
-
this.#renderer ??= (content) => this.html(content);
|
|
800
|
-
return this.#renderer(...args);
|
|
801
|
-
};
|
|
802
|
-
/**
|
|
803
|
-
* Sets the layout for the response.
|
|
804
|
-
*
|
|
805
|
-
* @param layout - The layout to set.
|
|
806
|
-
* @returns The layout function.
|
|
807
|
-
*/
|
|
808
|
-
setLayout = (layout) => this.#layout = layout;
|
|
809
|
-
/**
|
|
810
|
-
* Gets the current layout for the response.
|
|
811
|
-
*
|
|
812
|
-
* @returns The current layout function.
|
|
813
|
-
*/
|
|
814
|
-
getLayout = () => this.#layout;
|
|
815
|
-
/**
|
|
816
|
-
* `.setRenderer()` can set the layout in the custom middleware.
|
|
817
|
-
*
|
|
818
|
-
* @see {@link https://hono.dev/docs/api/context#render-setrenderer}
|
|
819
|
-
*
|
|
820
|
-
* @example
|
|
821
|
-
* ```tsx
|
|
822
|
-
* app.use('*', async (c, next) => {
|
|
823
|
-
* c.setRenderer((content) => {
|
|
824
|
-
* return c.html(
|
|
825
|
-
* <html>
|
|
826
|
-
* <body>
|
|
827
|
-
* <p>{content}</p>
|
|
828
|
-
* </body>
|
|
829
|
-
* </html>
|
|
830
|
-
* )
|
|
831
|
-
* })
|
|
832
|
-
* await next()
|
|
833
|
-
* })
|
|
834
|
-
* ```
|
|
835
|
-
*/
|
|
836
|
-
setRenderer = (renderer) => {
|
|
837
|
-
this.#renderer = renderer;
|
|
838
|
-
};
|
|
839
|
-
/**
|
|
840
|
-
* `.header()` can set headers.
|
|
841
|
-
*
|
|
842
|
-
* @see {@link https://hono.dev/docs/api/context#header}
|
|
843
|
-
*
|
|
844
|
-
* @example
|
|
845
|
-
* ```ts
|
|
846
|
-
* app.get('/welcome', (c) => {
|
|
847
|
-
* // Set headers
|
|
848
|
-
* c.header('X-Message', 'Hello!')
|
|
849
|
-
* c.header('Content-Type', 'text/plain')
|
|
850
|
-
*
|
|
851
|
-
* return c.body('Thank you for coming')
|
|
852
|
-
* })
|
|
853
|
-
* ```
|
|
854
|
-
*/
|
|
855
|
-
header = (name, value, options) => {
|
|
856
|
-
if (this.finalized) {
|
|
857
|
-
this.#res = createResponseInstance(this.#res.body, this.#res);
|
|
858
|
-
}
|
|
859
|
-
const headers = this.#res ? this.#res.headers : this.#preparedHeaders ??= new Headers();
|
|
860
|
-
if (value === void 0) {
|
|
861
|
-
headers.delete(name);
|
|
862
|
-
} else if (options?.append) {
|
|
863
|
-
headers.append(name, value);
|
|
864
|
-
} else {
|
|
865
|
-
headers.set(name, value);
|
|
866
|
-
}
|
|
867
|
-
};
|
|
868
|
-
status = (status) => {
|
|
869
|
-
this.#status = status;
|
|
870
|
-
};
|
|
871
|
-
/**
|
|
872
|
-
* `.set()` can set the value specified by the key.
|
|
873
|
-
*
|
|
874
|
-
* @see {@link https://hono.dev/docs/api/context#set-get}
|
|
875
|
-
*
|
|
876
|
-
* @example
|
|
877
|
-
* ```ts
|
|
878
|
-
* app.use('*', async (c, next) => {
|
|
879
|
-
* c.set('message', 'Hono is hot!!')
|
|
880
|
-
* await next()
|
|
881
|
-
* })
|
|
882
|
-
* ```
|
|
883
|
-
*/
|
|
884
|
-
set = (key, value) => {
|
|
885
|
-
this.#var ??= /* @__PURE__ */ new Map();
|
|
886
|
-
this.#var.set(key, value);
|
|
887
|
-
};
|
|
888
|
-
/**
|
|
889
|
-
* `.get()` can use the value specified by the key.
|
|
890
|
-
*
|
|
891
|
-
* @see {@link https://hono.dev/docs/api/context#set-get}
|
|
892
|
-
*
|
|
893
|
-
* @example
|
|
894
|
-
* ```ts
|
|
895
|
-
* app.get('/', (c) => {
|
|
896
|
-
* const message = c.get('message')
|
|
897
|
-
* return c.text(`The message is "${message}"`)
|
|
898
|
-
* })
|
|
899
|
-
* ```
|
|
900
|
-
*/
|
|
901
|
-
get = (key) => {
|
|
902
|
-
return this.#var ? this.#var.get(key) : void 0;
|
|
903
|
-
};
|
|
904
|
-
/**
|
|
905
|
-
* `.var` can access the value of a variable.
|
|
906
|
-
*
|
|
907
|
-
* @see {@link https://hono.dev/docs/api/context#var}
|
|
908
|
-
*
|
|
909
|
-
* @example
|
|
910
|
-
* ```ts
|
|
911
|
-
* const result = c.var.client.oneMethod()
|
|
912
|
-
* ```
|
|
913
|
-
*/
|
|
914
|
-
// c.var.propName is a read-only
|
|
915
|
-
get var() {
|
|
916
|
-
if (!this.#var) {
|
|
917
|
-
return {};
|
|
918
|
-
}
|
|
919
|
-
return Object.fromEntries(this.#var);
|
|
920
|
-
}
|
|
921
|
-
#newResponse(data, arg, headers) {
|
|
922
|
-
const responseHeaders = this.#res ? new Headers(this.#res.headers) : this.#preparedHeaders ?? new Headers();
|
|
923
|
-
if (typeof arg === "object" && "headers" in arg) {
|
|
924
|
-
const argHeaders = arg.headers instanceof Headers ? arg.headers : new Headers(arg.headers);
|
|
925
|
-
for (const [key, value] of argHeaders) {
|
|
926
|
-
if (key.toLowerCase() === "set-cookie") {
|
|
927
|
-
responseHeaders.append(key, value);
|
|
928
|
-
} else {
|
|
929
|
-
responseHeaders.set(key, value);
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
|
-
if (headers) {
|
|
934
|
-
for (const [k, v] of Object.entries(headers)) {
|
|
935
|
-
if (typeof v === "string") {
|
|
936
|
-
responseHeaders.set(k, v);
|
|
937
|
-
} else {
|
|
938
|
-
responseHeaders.delete(k);
|
|
939
|
-
for (const v2 of v) {
|
|
940
|
-
responseHeaders.append(k, v2);
|
|
941
|
-
}
|
|
942
|
-
}
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
const status = typeof arg === "number" ? arg : arg?.status ?? this.#status;
|
|
946
|
-
return createResponseInstance(data, { status, headers: responseHeaders });
|
|
947
|
-
}
|
|
948
|
-
newResponse = (...args) => this.#newResponse(...args);
|
|
949
|
-
/**
|
|
950
|
-
* `.body()` can return the HTTP response.
|
|
951
|
-
* You can set headers with `.header()` and set HTTP status code with `.status`.
|
|
952
|
-
* This can also be set in `.text()`, `.json()` and so on.
|
|
953
|
-
*
|
|
954
|
-
* @see {@link https://hono.dev/docs/api/context#body}
|
|
955
|
-
*
|
|
956
|
-
* @example
|
|
957
|
-
* ```ts
|
|
958
|
-
* app.get('/welcome', (c) => {
|
|
959
|
-
* // Set headers
|
|
960
|
-
* c.header('X-Message', 'Hello!')
|
|
961
|
-
* c.header('Content-Type', 'text/plain')
|
|
962
|
-
* // Set HTTP status code
|
|
963
|
-
* c.status(201)
|
|
964
|
-
*
|
|
965
|
-
* // Return the response body
|
|
966
|
-
* return c.body('Thank you for coming')
|
|
967
|
-
* })
|
|
968
|
-
* ```
|
|
969
|
-
*/
|
|
970
|
-
body = (data, arg, headers) => this.#newResponse(data, arg, headers);
|
|
971
|
-
/**
|
|
972
|
-
* `.text()` can render text as `Content-Type:text/plain`.
|
|
973
|
-
*
|
|
974
|
-
* @see {@link https://hono.dev/docs/api/context#text}
|
|
975
|
-
*
|
|
976
|
-
* @example
|
|
977
|
-
* ```ts
|
|
978
|
-
* app.get('/say', (c) => {
|
|
979
|
-
* return c.text('Hello!')
|
|
980
|
-
* })
|
|
981
|
-
* ```
|
|
982
|
-
*/
|
|
983
|
-
text = (text, arg, headers) => {
|
|
984
|
-
return !this.#preparedHeaders && !this.#status && !arg && !headers && !this.finalized ? new Response(text) : this.#newResponse(
|
|
985
|
-
text,
|
|
986
|
-
arg,
|
|
987
|
-
setDefaultContentType(TEXT_PLAIN, headers)
|
|
988
|
-
);
|
|
989
|
-
};
|
|
990
|
-
/**
|
|
991
|
-
* `.json()` can render JSON as `Content-Type:application/json`.
|
|
992
|
-
*
|
|
993
|
-
* @see {@link https://hono.dev/docs/api/context#json}
|
|
994
|
-
*
|
|
995
|
-
* @example
|
|
996
|
-
* ```ts
|
|
997
|
-
* app.get('/api', (c) => {
|
|
998
|
-
* return c.json({ message: 'Hello!' })
|
|
999
|
-
* })
|
|
1000
|
-
* ```
|
|
1001
|
-
*/
|
|
1002
|
-
json = (object, arg, headers) => {
|
|
1003
|
-
return this.#newResponse(
|
|
1004
|
-
JSON.stringify(object),
|
|
1005
|
-
arg,
|
|
1006
|
-
setDefaultContentType("application/json", headers)
|
|
1007
|
-
);
|
|
1008
|
-
};
|
|
1009
|
-
html = (html, arg, headers) => {
|
|
1010
|
-
const res = (html2) => this.#newResponse(html2, arg, setDefaultContentType("text/html; charset=UTF-8", headers));
|
|
1011
|
-
return typeof html === "object" ? resolveCallback(html, HtmlEscapedCallbackPhase.Stringify, false, {}).then(res) : res(html);
|
|
1012
|
-
};
|
|
1013
|
-
/**
|
|
1014
|
-
* `.redirect()` can Redirect, default status code is 302.
|
|
1015
|
-
*
|
|
1016
|
-
* @see {@link https://hono.dev/docs/api/context#redirect}
|
|
1017
|
-
*
|
|
1018
|
-
* @example
|
|
1019
|
-
* ```ts
|
|
1020
|
-
* app.get('/redirect', (c) => {
|
|
1021
|
-
* return c.redirect('/')
|
|
1022
|
-
* })
|
|
1023
|
-
* app.get('/redirect-permanently', (c) => {
|
|
1024
|
-
* return c.redirect('/', 301)
|
|
1025
|
-
* })
|
|
1026
|
-
* ```
|
|
1027
|
-
*/
|
|
1028
|
-
redirect = (location, status) => {
|
|
1029
|
-
const locationString = String(location);
|
|
1030
|
-
this.header(
|
|
1031
|
-
"Location",
|
|
1032
|
-
// Multibyes should be encoded
|
|
1033
|
-
// eslint-disable-next-line no-control-regex
|
|
1034
|
-
!/[^\x00-\xFF]/.test(locationString) ? locationString : encodeURI(locationString)
|
|
1035
|
-
);
|
|
1036
|
-
return this.newResponse(null, status ?? 302);
|
|
1037
|
-
};
|
|
1038
|
-
/**
|
|
1039
|
-
* `.notFound()` can return the Not Found Response.
|
|
1040
|
-
*
|
|
1041
|
-
* @see {@link https://hono.dev/docs/api/context#notfound}
|
|
1042
|
-
*
|
|
1043
|
-
* @example
|
|
1044
|
-
* ```ts
|
|
1045
|
-
* app.get('/notfound', (c) => {
|
|
1046
|
-
* return c.notFound()
|
|
1047
|
-
* })
|
|
1048
|
-
* ```
|
|
1049
|
-
*/
|
|
1050
|
-
notFound = () => {
|
|
1051
|
-
this.#notFoundHandler ??= () => createResponseInstance();
|
|
1052
|
-
return this.#notFoundHandler(this);
|
|
1053
|
-
};
|
|
1054
|
-
};
|
|
1055
|
-
|
|
1056
|
-
// node_modules/hono/dist/router.js
|
|
1057
|
-
var METHOD_NAME_ALL = "ALL";
|
|
1058
|
-
var METHOD_NAME_ALL_LOWERCASE = "all";
|
|
1059
|
-
var METHODS = ["get", "post", "put", "delete", "options", "patch"];
|
|
1060
|
-
var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
|
|
1061
|
-
var UnsupportedPathError = class extends Error {
|
|
1062
|
-
};
|
|
1063
|
-
|
|
1064
|
-
// node_modules/hono/dist/utils/constants.js
|
|
1065
|
-
var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
|
|
1066
|
-
|
|
1067
|
-
// node_modules/hono/dist/hono-base.js
|
|
1068
|
-
var notFoundHandler = (c) => {
|
|
1069
|
-
return c.text("404 Not Found", 404);
|
|
1070
|
-
};
|
|
1071
|
-
var errorHandler = (err, c) => {
|
|
1072
|
-
if ("getResponse" in err) {
|
|
1073
|
-
const res = err.getResponse();
|
|
1074
|
-
return c.newResponse(res.body, res);
|
|
1075
|
-
}
|
|
1076
|
-
console.error(err);
|
|
1077
|
-
return c.text("Internal Server Error", 500);
|
|
1078
|
-
};
|
|
1079
|
-
var Hono = class _Hono {
|
|
1080
|
-
get;
|
|
1081
|
-
post;
|
|
1082
|
-
put;
|
|
1083
|
-
delete;
|
|
1084
|
-
options;
|
|
1085
|
-
patch;
|
|
1086
|
-
all;
|
|
1087
|
-
on;
|
|
1088
|
-
use;
|
|
1089
|
-
/*
|
|
1090
|
-
This class is like an abstract class and does not have a router.
|
|
1091
|
-
To use it, inherit the class and implement router in the constructor.
|
|
1092
|
-
*/
|
|
1093
|
-
router;
|
|
1094
|
-
getPath;
|
|
1095
|
-
// Cannot use `#` because it requires visibility at JavaScript runtime.
|
|
1096
|
-
_basePath = "/";
|
|
1097
|
-
#path = "/";
|
|
1098
|
-
routes = [];
|
|
1099
|
-
constructor(options = {}) {
|
|
1100
|
-
const allMethods = [...METHODS, METHOD_NAME_ALL_LOWERCASE];
|
|
1101
|
-
allMethods.forEach((method) => {
|
|
1102
|
-
this[method] = (args1, ...args) => {
|
|
1103
|
-
if (typeof args1 === "string") {
|
|
1104
|
-
this.#path = args1;
|
|
1105
|
-
} else {
|
|
1106
|
-
this.#addRoute(method, this.#path, args1);
|
|
1107
|
-
}
|
|
1108
|
-
args.forEach((handler) => {
|
|
1109
|
-
this.#addRoute(method, this.#path, handler);
|
|
1110
|
-
});
|
|
1111
|
-
return this;
|
|
1112
|
-
};
|
|
1113
|
-
});
|
|
1114
|
-
this.on = (method, path, ...handlers) => {
|
|
1115
|
-
for (const p of [path].flat()) {
|
|
1116
|
-
this.#path = p;
|
|
1117
|
-
for (const m of [method].flat()) {
|
|
1118
|
-
handlers.map((handler) => {
|
|
1119
|
-
this.#addRoute(m.toUpperCase(), this.#path, handler);
|
|
1120
|
-
});
|
|
1121
|
-
}
|
|
1122
|
-
}
|
|
1123
|
-
return this;
|
|
1124
|
-
};
|
|
1125
|
-
this.use = (arg1, ...handlers) => {
|
|
1126
|
-
if (typeof arg1 === "string") {
|
|
1127
|
-
this.#path = arg1;
|
|
1128
|
-
} else {
|
|
1129
|
-
this.#path = "*";
|
|
1130
|
-
handlers.unshift(arg1);
|
|
1131
|
-
}
|
|
1132
|
-
handlers.forEach((handler) => {
|
|
1133
|
-
this.#addRoute(METHOD_NAME_ALL, this.#path, handler);
|
|
1134
|
-
});
|
|
1135
|
-
return this;
|
|
1136
|
-
};
|
|
1137
|
-
const { strict, ...optionsWithoutStrict } = options;
|
|
1138
|
-
Object.assign(this, optionsWithoutStrict);
|
|
1139
|
-
this.getPath = strict ?? true ? options.getPath ?? getPath : getPathNoStrict;
|
|
1140
|
-
}
|
|
1141
|
-
#clone() {
|
|
1142
|
-
const clone = new _Hono({
|
|
1143
|
-
router: this.router,
|
|
1144
|
-
getPath: this.getPath
|
|
1145
|
-
});
|
|
1146
|
-
clone.errorHandler = this.errorHandler;
|
|
1147
|
-
clone.#notFoundHandler = this.#notFoundHandler;
|
|
1148
|
-
clone.routes = this.routes;
|
|
1149
|
-
return clone;
|
|
1150
|
-
}
|
|
1151
|
-
#notFoundHandler = notFoundHandler;
|
|
1152
|
-
// Cannot use `#` because it requires visibility at JavaScript runtime.
|
|
1153
|
-
errorHandler = errorHandler;
|
|
1154
|
-
/**
|
|
1155
|
-
* `.route()` allows grouping other Hono instance in routes.
|
|
1156
|
-
*
|
|
1157
|
-
* @see {@link https://hono.dev/docs/api/routing#grouping}
|
|
1158
|
-
*
|
|
1159
|
-
* @param {string} path - base Path
|
|
1160
|
-
* @param {Hono} app - other Hono instance
|
|
1161
|
-
* @returns {Hono} routed Hono instance
|
|
1162
|
-
*
|
|
1163
|
-
* @example
|
|
1164
|
-
* ```ts
|
|
1165
|
-
* const app = new Hono()
|
|
1166
|
-
* const app2 = new Hono()
|
|
1167
|
-
*
|
|
1168
|
-
* app2.get("/user", (c) => c.text("user"))
|
|
1169
|
-
* app.route("/api", app2) // GET /api/user
|
|
1170
|
-
* ```
|
|
1171
|
-
*/
|
|
1172
|
-
route(path, app4) {
|
|
1173
|
-
const subApp = this.basePath(path);
|
|
1174
|
-
app4.routes.map((r) => {
|
|
1175
|
-
let handler;
|
|
1176
|
-
if (app4.errorHandler === errorHandler) {
|
|
1177
|
-
handler = r.handler;
|
|
1178
|
-
} else {
|
|
1179
|
-
handler = async (c, next) => (await compose([], app4.errorHandler)(c, () => r.handler(c, next))).res;
|
|
1180
|
-
handler[COMPOSED_HANDLER] = r.handler;
|
|
1181
|
-
}
|
|
1182
|
-
subApp.#addRoute(r.method, r.path, handler);
|
|
1183
|
-
});
|
|
1184
|
-
return this;
|
|
1185
|
-
}
|
|
1186
|
-
/**
|
|
1187
|
-
* `.basePath()` allows base paths to be specified.
|
|
1188
|
-
*
|
|
1189
|
-
* @see {@link https://hono.dev/docs/api/routing#base-path}
|
|
1190
|
-
*
|
|
1191
|
-
* @param {string} path - base Path
|
|
1192
|
-
* @returns {Hono} changed Hono instance
|
|
1193
|
-
*
|
|
1194
|
-
* @example
|
|
1195
|
-
* ```ts
|
|
1196
|
-
* const api = new Hono().basePath('/api')
|
|
1197
|
-
* ```
|
|
1198
|
-
*/
|
|
1199
|
-
basePath(path) {
|
|
1200
|
-
const subApp = this.#clone();
|
|
1201
|
-
subApp._basePath = mergePath(this._basePath, path);
|
|
1202
|
-
return subApp;
|
|
1203
|
-
}
|
|
1204
|
-
/**
|
|
1205
|
-
* `.onError()` handles an error and returns a customized Response.
|
|
1206
|
-
*
|
|
1207
|
-
* @see {@link https://hono.dev/docs/api/hono#error-handling}
|
|
1208
|
-
*
|
|
1209
|
-
* @param {ErrorHandler} handler - request Handler for error
|
|
1210
|
-
* @returns {Hono} changed Hono instance
|
|
1211
|
-
*
|
|
1212
|
-
* @example
|
|
1213
|
-
* ```ts
|
|
1214
|
-
* app.onError((err, c) => {
|
|
1215
|
-
* console.error(`${err}`)
|
|
1216
|
-
* return c.text('Custom Error Message', 500)
|
|
1217
|
-
* })
|
|
1218
|
-
* ```
|
|
1219
|
-
*/
|
|
1220
|
-
onError = (handler) => {
|
|
1221
|
-
this.errorHandler = handler;
|
|
1222
|
-
return this;
|
|
1223
|
-
};
|
|
1224
|
-
/**
|
|
1225
|
-
* `.notFound()` allows you to customize a Not Found Response.
|
|
1226
|
-
*
|
|
1227
|
-
* @see {@link https://hono.dev/docs/api/hono#not-found}
|
|
1228
|
-
*
|
|
1229
|
-
* @param {NotFoundHandler} handler - request handler for not-found
|
|
1230
|
-
* @returns {Hono} changed Hono instance
|
|
1231
|
-
*
|
|
1232
|
-
* @example
|
|
1233
|
-
* ```ts
|
|
1234
|
-
* app.notFound((c) => {
|
|
1235
|
-
* return c.text('Custom 404 Message', 404)
|
|
1236
|
-
* })
|
|
1237
|
-
* ```
|
|
1238
|
-
*/
|
|
1239
|
-
notFound = (handler) => {
|
|
1240
|
-
this.#notFoundHandler = handler;
|
|
1241
|
-
return this;
|
|
1242
|
-
};
|
|
1243
|
-
/**
|
|
1244
|
-
* `.mount()` allows you to mount applications built with other frameworks into your Hono application.
|
|
1245
|
-
*
|
|
1246
|
-
* @see {@link https://hono.dev/docs/api/hono#mount}
|
|
1247
|
-
*
|
|
1248
|
-
* @param {string} path - base Path
|
|
1249
|
-
* @param {Function} applicationHandler - other Request Handler
|
|
1250
|
-
* @param {MountOptions} [options] - options of `.mount()`
|
|
1251
|
-
* @returns {Hono} mounted Hono instance
|
|
1252
|
-
*
|
|
1253
|
-
* @example
|
|
1254
|
-
* ```ts
|
|
1255
|
-
* import { Router as IttyRouter } from 'itty-router'
|
|
1256
|
-
* import { Hono } from 'hono'
|
|
1257
|
-
* // Create itty-router application
|
|
1258
|
-
* const ittyRouter = IttyRouter()
|
|
1259
|
-
* // GET /itty-router/hello
|
|
1260
|
-
* ittyRouter.get('/hello', () => new Response('Hello from itty-router'))
|
|
1261
|
-
*
|
|
1262
|
-
* const app = new Hono()
|
|
1263
|
-
* app.mount('/itty-router', ittyRouter.handle)
|
|
1264
|
-
* ```
|
|
1265
|
-
*
|
|
1266
|
-
* @example
|
|
1267
|
-
* ```ts
|
|
1268
|
-
* const app = new Hono()
|
|
1269
|
-
* // Send the request to another application without modification.
|
|
1270
|
-
* app.mount('/app', anotherApp, {
|
|
1271
|
-
* replaceRequest: (req) => req,
|
|
1272
|
-
* })
|
|
1273
|
-
* ```
|
|
1274
|
-
*/
|
|
1275
|
-
mount(path, applicationHandler, options) {
|
|
1276
|
-
let replaceRequest;
|
|
1277
|
-
let optionHandler;
|
|
1278
|
-
if (options) {
|
|
1279
|
-
if (typeof options === "function") {
|
|
1280
|
-
optionHandler = options;
|
|
1281
|
-
} else {
|
|
1282
|
-
optionHandler = options.optionHandler;
|
|
1283
|
-
if (options.replaceRequest === false) {
|
|
1284
|
-
replaceRequest = (request) => request;
|
|
1285
|
-
} else {
|
|
1286
|
-
replaceRequest = options.replaceRequest;
|
|
1287
|
-
}
|
|
1288
|
-
}
|
|
1289
|
-
}
|
|
1290
|
-
const getOptions = optionHandler ? (c) => {
|
|
1291
|
-
const options2 = optionHandler(c);
|
|
1292
|
-
return Array.isArray(options2) ? options2 : [options2];
|
|
1293
|
-
} : (c) => {
|
|
1294
|
-
let executionContext = void 0;
|
|
1295
|
-
try {
|
|
1296
|
-
executionContext = c.executionCtx;
|
|
1297
|
-
} catch {
|
|
1298
|
-
}
|
|
1299
|
-
return [c.env, executionContext];
|
|
1300
|
-
};
|
|
1301
|
-
replaceRequest ||= (() => {
|
|
1302
|
-
const mergedPath = mergePath(this._basePath, path);
|
|
1303
|
-
const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length;
|
|
1304
|
-
return (request) => {
|
|
1305
|
-
const url = new URL(request.url);
|
|
1306
|
-
url.pathname = url.pathname.slice(pathPrefixLength) || "/";
|
|
1307
|
-
return new Request(url, request);
|
|
1308
|
-
};
|
|
1309
|
-
})();
|
|
1310
|
-
const handler = async (c, next) => {
|
|
1311
|
-
const res = await applicationHandler(replaceRequest(c.req.raw), ...getOptions(c));
|
|
1312
|
-
if (res) {
|
|
1313
|
-
return res;
|
|
1314
|
-
}
|
|
1315
|
-
await next();
|
|
1316
|
-
};
|
|
1317
|
-
this.#addRoute(METHOD_NAME_ALL, mergePath(path, "*"), handler);
|
|
1318
|
-
return this;
|
|
1319
|
-
}
|
|
1320
|
-
#addRoute(method, path, handler) {
|
|
1321
|
-
method = method.toUpperCase();
|
|
1322
|
-
path = mergePath(this._basePath, path);
|
|
1323
|
-
const r = { basePath: this._basePath, path, method, handler };
|
|
1324
|
-
this.router.add(method, path, [handler, r]);
|
|
1325
|
-
this.routes.push(r);
|
|
1326
|
-
}
|
|
1327
|
-
#handleError(err, c) {
|
|
1328
|
-
if (err instanceof Error) {
|
|
1329
|
-
return this.errorHandler(err, c);
|
|
1330
|
-
}
|
|
1331
|
-
throw err;
|
|
1332
|
-
}
|
|
1333
|
-
#dispatch(request, executionCtx, env, method) {
|
|
1334
|
-
if (method === "HEAD") {
|
|
1335
|
-
return (async () => new Response(null, await this.#dispatch(request, executionCtx, env, "GET")))();
|
|
1336
|
-
}
|
|
1337
|
-
const path = this.getPath(request, { env });
|
|
1338
|
-
const matchResult = this.router.match(method, path);
|
|
1339
|
-
const c = new Context(request, {
|
|
1340
|
-
path,
|
|
1341
|
-
matchResult,
|
|
1342
|
-
env,
|
|
1343
|
-
executionCtx,
|
|
1344
|
-
notFoundHandler: this.#notFoundHandler
|
|
1345
|
-
});
|
|
1346
|
-
if (matchResult[0].length === 1) {
|
|
1347
|
-
let res;
|
|
1348
|
-
try {
|
|
1349
|
-
res = matchResult[0][0][0][0](c, async () => {
|
|
1350
|
-
c.res = await this.#notFoundHandler(c);
|
|
1351
|
-
});
|
|
1352
|
-
} catch (err) {
|
|
1353
|
-
return this.#handleError(err, c);
|
|
1354
|
-
}
|
|
1355
|
-
return res instanceof Promise ? res.then(
|
|
1356
|
-
(resolved) => resolved || (c.finalized ? c.res : this.#notFoundHandler(c))
|
|
1357
|
-
).catch((err) => this.#handleError(err, c)) : res ?? this.#notFoundHandler(c);
|
|
1358
|
-
}
|
|
1359
|
-
const composed = compose(matchResult[0], this.errorHandler, this.#notFoundHandler);
|
|
1360
|
-
return (async () => {
|
|
1361
|
-
try {
|
|
1362
|
-
const context = await composed(c);
|
|
1363
|
-
if (!context.finalized) {
|
|
1364
|
-
throw new Error(
|
|
1365
|
-
"Context is not finalized. Did you forget to return a Response object or `await next()`?"
|
|
1366
|
-
);
|
|
1367
|
-
}
|
|
1368
|
-
return context.res;
|
|
1369
|
-
} catch (err) {
|
|
1370
|
-
return this.#handleError(err, c);
|
|
1371
|
-
}
|
|
1372
|
-
})();
|
|
1373
|
-
}
|
|
1374
|
-
/**
|
|
1375
|
-
* `.fetch()` will be entry point of your app.
|
|
1376
|
-
*
|
|
1377
|
-
* @see {@link https://hono.dev/docs/api/hono#fetch}
|
|
1378
|
-
*
|
|
1379
|
-
* @param {Request} request - request Object of request
|
|
1380
|
-
* @param {Env} Env - env Object
|
|
1381
|
-
* @param {ExecutionContext} - context of execution
|
|
1382
|
-
* @returns {Response | Promise<Response>} response of request
|
|
1383
|
-
*
|
|
1384
|
-
*/
|
|
1385
|
-
fetch = (request, ...rest) => {
|
|
1386
|
-
return this.#dispatch(request, rest[1], rest[0], request.method);
|
|
1387
|
-
};
|
|
1388
|
-
/**
|
|
1389
|
-
* `.request()` is a useful method for testing.
|
|
1390
|
-
* You can pass a URL or pathname to send a GET request.
|
|
1391
|
-
* app will return a Response object.
|
|
1392
|
-
* ```ts
|
|
1393
|
-
* test('GET /hello is ok', async () => {
|
|
1394
|
-
* const res = await app.request('/hello')
|
|
1395
|
-
* expect(res.status).toBe(200)
|
|
1396
|
-
* })
|
|
1397
|
-
* ```
|
|
1398
|
-
* @see https://hono.dev/docs/api/hono#request
|
|
1399
|
-
*/
|
|
1400
|
-
request = (input, requestInit, Env, executionCtx) => {
|
|
1401
|
-
if (input instanceof Request) {
|
|
1402
|
-
return this.fetch(requestInit ? new Request(input, requestInit) : input, Env, executionCtx);
|
|
1403
|
-
}
|
|
1404
|
-
input = input.toString();
|
|
1405
|
-
return this.fetch(
|
|
1406
|
-
new Request(
|
|
1407
|
-
/^https?:\/\//.test(input) ? input : `http://localhost${mergePath("/", input)}`,
|
|
1408
|
-
requestInit
|
|
1409
|
-
),
|
|
1410
|
-
Env,
|
|
1411
|
-
executionCtx
|
|
1412
|
-
);
|
|
1413
|
-
};
|
|
1414
|
-
/**
|
|
1415
|
-
* `.fire()` automatically adds a global fetch event listener.
|
|
1416
|
-
* This can be useful for environments that adhere to the Service Worker API, such as non-ES module Cloudflare Workers.
|
|
1417
|
-
* @deprecated
|
|
1418
|
-
* Use `fire` from `hono/service-worker` instead.
|
|
1419
|
-
* ```ts
|
|
1420
|
-
* import { Hono } from 'hono'
|
|
1421
|
-
* import { fire } from 'hono/service-worker'
|
|
1422
|
-
*
|
|
1423
|
-
* const app = new Hono()
|
|
1424
|
-
* // ...
|
|
1425
|
-
* fire(app)
|
|
1426
|
-
* ```
|
|
1427
|
-
* @see https://hono.dev/docs/api/hono#fire
|
|
1428
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API
|
|
1429
|
-
* @see https://developers.cloudflare.com/workers/reference/migrate-to-module-workers/
|
|
1430
|
-
*/
|
|
1431
|
-
fire = () => {
|
|
1432
|
-
addEventListener("fetch", (event) => {
|
|
1433
|
-
event.respondWith(this.#dispatch(event.request, event, void 0, event.request.method));
|
|
1434
|
-
});
|
|
1435
|
-
};
|
|
1436
|
-
};
|
|
1437
|
-
|
|
1438
|
-
// node_modules/hono/dist/router/reg-exp-router/matcher.js
|
|
1439
|
-
var emptyParam = [];
|
|
1440
|
-
function match(method, path) {
|
|
1441
|
-
const matchers = this.buildAllMatchers();
|
|
1442
|
-
const match2 = ((method2, path2) => {
|
|
1443
|
-
const matcher = matchers[method2] || matchers[METHOD_NAME_ALL];
|
|
1444
|
-
const staticMatch = matcher[2][path2];
|
|
1445
|
-
if (staticMatch) {
|
|
1446
|
-
return staticMatch;
|
|
1447
|
-
}
|
|
1448
|
-
const match3 = path2.match(matcher[0]);
|
|
1449
|
-
if (!match3) {
|
|
1450
|
-
return [[], emptyParam];
|
|
1451
|
-
}
|
|
1452
|
-
const index = match3.indexOf("", 1);
|
|
1453
|
-
return [matcher[1][index], match3];
|
|
1454
|
-
});
|
|
1455
|
-
this.match = match2;
|
|
1456
|
-
return match2(method, path);
|
|
1457
|
-
}
|
|
1458
|
-
|
|
1459
|
-
// node_modules/hono/dist/router/reg-exp-router/node.js
|
|
1460
|
-
var LABEL_REG_EXP_STR = "[^/]+";
|
|
1461
|
-
var ONLY_WILDCARD_REG_EXP_STR = ".*";
|
|
1462
|
-
var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
|
|
1463
|
-
var PATH_ERROR = /* @__PURE__ */ Symbol();
|
|
1464
|
-
var regExpMetaChars = new Set(".\\+*[^]$()");
|
|
1465
|
-
function compareKey(a, b) {
|
|
1466
|
-
if (a.length === 1) {
|
|
1467
|
-
return b.length === 1 ? a < b ? -1 : 1 : -1;
|
|
1468
|
-
}
|
|
1469
|
-
if (b.length === 1) {
|
|
1470
|
-
return 1;
|
|
1471
|
-
}
|
|
1472
|
-
if (a === ONLY_WILDCARD_REG_EXP_STR || a === TAIL_WILDCARD_REG_EXP_STR) {
|
|
1473
|
-
return 1;
|
|
1474
|
-
} else if (b === ONLY_WILDCARD_REG_EXP_STR || b === TAIL_WILDCARD_REG_EXP_STR) {
|
|
1475
|
-
return -1;
|
|
1476
|
-
}
|
|
1477
|
-
if (a === LABEL_REG_EXP_STR) {
|
|
1478
|
-
return 1;
|
|
1479
|
-
} else if (b === LABEL_REG_EXP_STR) {
|
|
1480
|
-
return -1;
|
|
1481
|
-
}
|
|
1482
|
-
return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
|
|
1483
|
-
}
|
|
1484
|
-
var Node = class _Node {
|
|
1485
|
-
#index;
|
|
1486
|
-
#varIndex;
|
|
1487
|
-
#children = /* @__PURE__ */ Object.create(null);
|
|
1488
|
-
insert(tokens, index, paramMap, context, pathErrorCheckOnly) {
|
|
1489
|
-
if (tokens.length === 0) {
|
|
1490
|
-
if (this.#index !== void 0) {
|
|
1491
|
-
throw PATH_ERROR;
|
|
1492
|
-
}
|
|
1493
|
-
if (pathErrorCheckOnly) {
|
|
1494
|
-
return;
|
|
1495
|
-
}
|
|
1496
|
-
this.#index = index;
|
|
1497
|
-
return;
|
|
1498
|
-
}
|
|
1499
|
-
const [token, ...restTokens] = tokens;
|
|
1500
|
-
const pattern = token === "*" ? restTokens.length === 0 ? ["", "", ONLY_WILDCARD_REG_EXP_STR] : ["", "", LABEL_REG_EXP_STR] : token === "/*" ? ["", "", TAIL_WILDCARD_REG_EXP_STR] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
1501
|
-
let node;
|
|
1502
|
-
if (pattern) {
|
|
1503
|
-
const name = pattern[1];
|
|
1504
|
-
let regexpStr = pattern[2] || LABEL_REG_EXP_STR;
|
|
1505
|
-
if (name && pattern[2]) {
|
|
1506
|
-
if (regexpStr === ".*") {
|
|
1507
|
-
throw PATH_ERROR;
|
|
1508
|
-
}
|
|
1509
|
-
regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
|
|
1510
|
-
if (/\((?!\?:)/.test(regexpStr)) {
|
|
1511
|
-
throw PATH_ERROR;
|
|
1512
|
-
}
|
|
1513
|
-
}
|
|
1514
|
-
node = this.#children[regexpStr];
|
|
1515
|
-
if (!node) {
|
|
1516
|
-
if (Object.keys(this.#children).some(
|
|
1517
|
-
(k) => k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
|
|
1518
|
-
)) {
|
|
1519
|
-
throw PATH_ERROR;
|
|
1520
|
-
}
|
|
1521
|
-
if (pathErrorCheckOnly) {
|
|
1522
|
-
return;
|
|
1523
|
-
}
|
|
1524
|
-
node = this.#children[regexpStr] = new _Node();
|
|
1525
|
-
if (name !== "") {
|
|
1526
|
-
node.#varIndex = context.varIndex++;
|
|
1527
|
-
}
|
|
1528
|
-
}
|
|
1529
|
-
if (!pathErrorCheckOnly && name !== "") {
|
|
1530
|
-
paramMap.push([name, node.#varIndex]);
|
|
1531
|
-
}
|
|
1532
|
-
} else {
|
|
1533
|
-
node = this.#children[token];
|
|
1534
|
-
if (!node) {
|
|
1535
|
-
if (Object.keys(this.#children).some(
|
|
1536
|
-
(k) => k.length > 1 && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
|
|
1537
|
-
)) {
|
|
1538
|
-
throw PATH_ERROR;
|
|
1539
|
-
}
|
|
1540
|
-
if (pathErrorCheckOnly) {
|
|
1541
|
-
return;
|
|
1542
|
-
}
|
|
1543
|
-
node = this.#children[token] = new _Node();
|
|
1544
|
-
}
|
|
1545
|
-
}
|
|
1546
|
-
node.insert(restTokens, index, paramMap, context, pathErrorCheckOnly);
|
|
1547
|
-
}
|
|
1548
|
-
buildRegExpStr() {
|
|
1549
|
-
const childKeys = Object.keys(this.#children).sort(compareKey);
|
|
1550
|
-
const strList = childKeys.map((k) => {
|
|
1551
|
-
const c = this.#children[k];
|
|
1552
|
-
return (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr();
|
|
1553
|
-
});
|
|
1554
|
-
if (typeof this.#index === "number") {
|
|
1555
|
-
strList.unshift(`#${this.#index}`);
|
|
1556
|
-
}
|
|
1557
|
-
if (strList.length === 0) {
|
|
1558
|
-
return "";
|
|
1559
|
-
}
|
|
1560
|
-
if (strList.length === 1) {
|
|
1561
|
-
return strList[0];
|
|
1562
|
-
}
|
|
1563
|
-
return "(?:" + strList.join("|") + ")";
|
|
1564
|
-
}
|
|
1565
|
-
};
|
|
1566
|
-
|
|
1567
|
-
// node_modules/hono/dist/router/reg-exp-router/trie.js
|
|
1568
|
-
var Trie = class {
|
|
1569
|
-
#context = { varIndex: 0 };
|
|
1570
|
-
#root = new Node();
|
|
1571
|
-
insert(path, index, pathErrorCheckOnly) {
|
|
1572
|
-
const paramAssoc = [];
|
|
1573
|
-
const groups = [];
|
|
1574
|
-
for (let i = 0; ; ) {
|
|
1575
|
-
let replaced = false;
|
|
1576
|
-
path = path.replace(/\{[^}]+\}/g, (m) => {
|
|
1577
|
-
const mark = `@\\${i}`;
|
|
1578
|
-
groups[i] = [mark, m];
|
|
1579
|
-
i++;
|
|
1580
|
-
replaced = true;
|
|
1581
|
-
return mark;
|
|
1582
|
-
});
|
|
1583
|
-
if (!replaced) {
|
|
1584
|
-
break;
|
|
1585
|
-
}
|
|
1586
|
-
}
|
|
1587
|
-
const tokens = path.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
|
|
1588
|
-
for (let i = groups.length - 1; i >= 0; i--) {
|
|
1589
|
-
const [mark] = groups[i];
|
|
1590
|
-
for (let j = tokens.length - 1; j >= 0; j--) {
|
|
1591
|
-
if (tokens[j].indexOf(mark) !== -1) {
|
|
1592
|
-
tokens[j] = tokens[j].replace(mark, groups[i][1]);
|
|
1593
|
-
break;
|
|
1594
|
-
}
|
|
1595
|
-
}
|
|
1596
|
-
}
|
|
1597
|
-
this.#root.insert(tokens, index, paramAssoc, this.#context, pathErrorCheckOnly);
|
|
1598
|
-
return paramAssoc;
|
|
1599
|
-
}
|
|
1600
|
-
buildRegExp() {
|
|
1601
|
-
let regexp = this.#root.buildRegExpStr();
|
|
1602
|
-
if (regexp === "") {
|
|
1603
|
-
return [/^$/, [], []];
|
|
1604
|
-
}
|
|
1605
|
-
let captureIndex = 0;
|
|
1606
|
-
const indexReplacementMap = [];
|
|
1607
|
-
const paramReplacementMap = [];
|
|
1608
|
-
regexp = regexp.replace(/#(\d+)|@(\d+)|\.\*\$/g, (_, handlerIndex, paramIndex) => {
|
|
1609
|
-
if (handlerIndex !== void 0) {
|
|
1610
|
-
indexReplacementMap[++captureIndex] = Number(handlerIndex);
|
|
1611
|
-
return "$()";
|
|
1612
|
-
}
|
|
1613
|
-
if (paramIndex !== void 0) {
|
|
1614
|
-
paramReplacementMap[Number(paramIndex)] = ++captureIndex;
|
|
1615
|
-
return "";
|
|
1616
|
-
}
|
|
1617
|
-
return "";
|
|
1618
|
-
});
|
|
1619
|
-
return [new RegExp(`^${regexp}`), indexReplacementMap, paramReplacementMap];
|
|
1620
|
-
}
|
|
1621
|
-
};
|
|
1622
|
-
|
|
1623
|
-
// node_modules/hono/dist/router/reg-exp-router/router.js
|
|
1624
|
-
var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
|
|
1625
|
-
var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
1626
|
-
function buildWildcardRegExp(path) {
|
|
1627
|
-
return wildcardRegExpCache[path] ??= new RegExp(
|
|
1628
|
-
path === "*" ? "" : `^${path.replace(
|
|
1629
|
-
/\/\*$|([.\\+*[^\]$()])/g,
|
|
1630
|
-
(_, metaChar) => metaChar ? `\\${metaChar}` : "(?:|/.*)"
|
|
1631
|
-
)}$`
|
|
1632
|
-
);
|
|
1633
|
-
}
|
|
1634
|
-
function clearWildcardRegExpCache() {
|
|
1635
|
-
wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
1636
|
-
}
|
|
1637
|
-
function buildMatcherFromPreprocessedRoutes(routes) {
|
|
1638
|
-
const trie = new Trie();
|
|
1639
|
-
const handlerData = [];
|
|
1640
|
-
if (routes.length === 0) {
|
|
1641
|
-
return nullMatcher;
|
|
1642
|
-
}
|
|
1643
|
-
const routesWithStaticPathFlag = routes.map(
|
|
1644
|
-
(route) => [!/\*|\/:/.test(route[0]), ...route]
|
|
1645
|
-
).sort(
|
|
1646
|
-
([isStaticA, pathA], [isStaticB, pathB]) => isStaticA ? 1 : isStaticB ? -1 : pathA.length - pathB.length
|
|
1647
|
-
);
|
|
1648
|
-
const staticMap = /* @__PURE__ */ Object.create(null);
|
|
1649
|
-
for (let i = 0, j = -1, len = routesWithStaticPathFlag.length; i < len; i++) {
|
|
1650
|
-
const [pathErrorCheckOnly, path, handlers] = routesWithStaticPathFlag[i];
|
|
1651
|
-
if (pathErrorCheckOnly) {
|
|
1652
|
-
staticMap[path] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
|
|
1653
|
-
} else {
|
|
1654
|
-
j++;
|
|
1655
|
-
}
|
|
1656
|
-
let paramAssoc;
|
|
1657
|
-
try {
|
|
1658
|
-
paramAssoc = trie.insert(path, j, pathErrorCheckOnly);
|
|
1659
|
-
} catch (e) {
|
|
1660
|
-
throw e === PATH_ERROR ? new UnsupportedPathError(path) : e;
|
|
1661
|
-
}
|
|
1662
|
-
if (pathErrorCheckOnly) {
|
|
1663
|
-
continue;
|
|
1664
|
-
}
|
|
1665
|
-
handlerData[j] = handlers.map(([h, paramCount]) => {
|
|
1666
|
-
const paramIndexMap = /* @__PURE__ */ Object.create(null);
|
|
1667
|
-
paramCount -= 1;
|
|
1668
|
-
for (; paramCount >= 0; paramCount--) {
|
|
1669
|
-
const [key, value] = paramAssoc[paramCount];
|
|
1670
|
-
paramIndexMap[key] = value;
|
|
1671
|
-
}
|
|
1672
|
-
return [h, paramIndexMap];
|
|
1673
|
-
});
|
|
1674
|
-
}
|
|
1675
|
-
const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
|
|
1676
|
-
for (let i = 0, len = handlerData.length; i < len; i++) {
|
|
1677
|
-
for (let j = 0, len2 = handlerData[i].length; j < len2; j++) {
|
|
1678
|
-
const map = handlerData[i][j]?.[1];
|
|
1679
|
-
if (!map) {
|
|
1680
|
-
continue;
|
|
1681
|
-
}
|
|
1682
|
-
const keys = Object.keys(map);
|
|
1683
|
-
for (let k = 0, len3 = keys.length; k < len3; k++) {
|
|
1684
|
-
map[keys[k]] = paramReplacementMap[map[keys[k]]];
|
|
1685
|
-
}
|
|
1686
|
-
}
|
|
1687
|
-
}
|
|
1688
|
-
const handlerMap = [];
|
|
1689
|
-
for (const i in indexReplacementMap) {
|
|
1690
|
-
handlerMap[i] = handlerData[indexReplacementMap[i]];
|
|
1691
|
-
}
|
|
1692
|
-
return [regexp, handlerMap, staticMap];
|
|
1693
|
-
}
|
|
1694
|
-
function findMiddleware(middleware, path) {
|
|
1695
|
-
if (!middleware) {
|
|
1696
|
-
return void 0;
|
|
1697
|
-
}
|
|
1698
|
-
for (const k of Object.keys(middleware).sort((a, b) => b.length - a.length)) {
|
|
1699
|
-
if (buildWildcardRegExp(k).test(path)) {
|
|
1700
|
-
return [...middleware[k]];
|
|
1701
|
-
}
|
|
1702
|
-
}
|
|
1703
|
-
return void 0;
|
|
1704
|
-
}
|
|
1705
|
-
var RegExpRouter = class {
|
|
1706
|
-
name = "RegExpRouter";
|
|
1707
|
-
#middleware;
|
|
1708
|
-
#routes;
|
|
1709
|
-
constructor() {
|
|
1710
|
-
this.#middleware = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
|
|
1711
|
-
this.#routes = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
|
|
1712
|
-
}
|
|
1713
|
-
add(method, path, handler) {
|
|
1714
|
-
const middleware = this.#middleware;
|
|
1715
|
-
const routes = this.#routes;
|
|
1716
|
-
if (!middleware || !routes) {
|
|
1717
|
-
throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
1718
|
-
}
|
|
1719
|
-
if (!middleware[method]) {
|
|
1720
|
-
;
|
|
1721
|
-
[middleware, routes].forEach((handlerMap) => {
|
|
1722
|
-
handlerMap[method] = /* @__PURE__ */ Object.create(null);
|
|
1723
|
-
Object.keys(handlerMap[METHOD_NAME_ALL]).forEach((p) => {
|
|
1724
|
-
handlerMap[method][p] = [...handlerMap[METHOD_NAME_ALL][p]];
|
|
1725
|
-
});
|
|
1726
|
-
});
|
|
1727
|
-
}
|
|
1728
|
-
if (path === "/*") {
|
|
1729
|
-
path = "*";
|
|
1730
|
-
}
|
|
1731
|
-
const paramCount = (path.match(/\/:/g) || []).length;
|
|
1732
|
-
if (/\*$/.test(path)) {
|
|
1733
|
-
const re = buildWildcardRegExp(path);
|
|
1734
|
-
if (method === METHOD_NAME_ALL) {
|
|
1735
|
-
Object.keys(middleware).forEach((m) => {
|
|
1736
|
-
middleware[m][path] ||= findMiddleware(middleware[m], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
|
|
1737
|
-
});
|
|
1738
|
-
} else {
|
|
1739
|
-
middleware[method][path] ||= findMiddleware(middleware[method], path) || findMiddleware(middleware[METHOD_NAME_ALL], path) || [];
|
|
1740
|
-
}
|
|
1741
|
-
Object.keys(middleware).forEach((m) => {
|
|
1742
|
-
if (method === METHOD_NAME_ALL || method === m) {
|
|
1743
|
-
Object.keys(middleware[m]).forEach((p) => {
|
|
1744
|
-
re.test(p) && middleware[m][p].push([handler, paramCount]);
|
|
1745
|
-
});
|
|
1746
|
-
}
|
|
1747
|
-
});
|
|
1748
|
-
Object.keys(routes).forEach((m) => {
|
|
1749
|
-
if (method === METHOD_NAME_ALL || method === m) {
|
|
1750
|
-
Object.keys(routes[m]).forEach(
|
|
1751
|
-
(p) => re.test(p) && routes[m][p].push([handler, paramCount])
|
|
1752
|
-
);
|
|
1753
|
-
}
|
|
1754
|
-
});
|
|
1755
|
-
return;
|
|
1756
|
-
}
|
|
1757
|
-
const paths = checkOptionalParameter(path) || [path];
|
|
1758
|
-
for (let i = 0, len = paths.length; i < len; i++) {
|
|
1759
|
-
const path2 = paths[i];
|
|
1760
|
-
Object.keys(routes).forEach((m) => {
|
|
1761
|
-
if (method === METHOD_NAME_ALL || method === m) {
|
|
1762
|
-
routes[m][path2] ||= [
|
|
1763
|
-
...findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || []
|
|
1764
|
-
];
|
|
1765
|
-
routes[m][path2].push([handler, paramCount - len + i + 1]);
|
|
1766
|
-
}
|
|
1767
|
-
});
|
|
1768
|
-
}
|
|
1769
|
-
}
|
|
1770
|
-
match = match;
|
|
1771
|
-
buildAllMatchers() {
|
|
1772
|
-
const matchers = /* @__PURE__ */ Object.create(null);
|
|
1773
|
-
Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
|
|
1774
|
-
matchers[method] ||= this.#buildMatcher(method);
|
|
1775
|
-
});
|
|
1776
|
-
this.#middleware = this.#routes = void 0;
|
|
1777
|
-
clearWildcardRegExpCache();
|
|
1778
|
-
return matchers;
|
|
1779
|
-
}
|
|
1780
|
-
#buildMatcher(method) {
|
|
1781
|
-
const routes = [];
|
|
1782
|
-
let hasOwnRoute = method === METHOD_NAME_ALL;
|
|
1783
|
-
[this.#middleware, this.#routes].forEach((r) => {
|
|
1784
|
-
const ownRoute = r[method] ? Object.keys(r[method]).map((path) => [path, r[method][path]]) : [];
|
|
1785
|
-
if (ownRoute.length !== 0) {
|
|
1786
|
-
hasOwnRoute ||= true;
|
|
1787
|
-
routes.push(...ownRoute);
|
|
1788
|
-
} else if (method !== METHOD_NAME_ALL) {
|
|
1789
|
-
routes.push(
|
|
1790
|
-
...Object.keys(r[METHOD_NAME_ALL]).map((path) => [path, r[METHOD_NAME_ALL][path]])
|
|
1791
|
-
);
|
|
1792
|
-
}
|
|
1793
|
-
});
|
|
1794
|
-
if (!hasOwnRoute) {
|
|
1795
|
-
return null;
|
|
1796
|
-
} else {
|
|
1797
|
-
return buildMatcherFromPreprocessedRoutes(routes);
|
|
1798
|
-
}
|
|
1799
|
-
}
|
|
1800
|
-
};
|
|
1801
|
-
|
|
1802
|
-
// node_modules/hono/dist/router/smart-router/router.js
|
|
1803
|
-
var SmartRouter = class {
|
|
1804
|
-
name = "SmartRouter";
|
|
1805
|
-
#routers = [];
|
|
1806
|
-
#routes = [];
|
|
1807
|
-
constructor(init) {
|
|
1808
|
-
this.#routers = init.routers;
|
|
1809
|
-
}
|
|
1810
|
-
add(method, path, handler) {
|
|
1811
|
-
if (!this.#routes) {
|
|
1812
|
-
throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
1813
|
-
}
|
|
1814
|
-
this.#routes.push([method, path, handler]);
|
|
1815
|
-
}
|
|
1816
|
-
match(method, path) {
|
|
1817
|
-
if (!this.#routes) {
|
|
1818
|
-
throw new Error("Fatal error");
|
|
1819
|
-
}
|
|
1820
|
-
const routers = this.#routers;
|
|
1821
|
-
const routes = this.#routes;
|
|
1822
|
-
const len = routers.length;
|
|
1823
|
-
let i = 0;
|
|
1824
|
-
let res;
|
|
1825
|
-
for (; i < len; i++) {
|
|
1826
|
-
const router = routers[i];
|
|
1827
|
-
try {
|
|
1828
|
-
for (let i2 = 0, len2 = routes.length; i2 < len2; i2++) {
|
|
1829
|
-
router.add(...routes[i2]);
|
|
1830
|
-
}
|
|
1831
|
-
res = router.match(method, path);
|
|
1832
|
-
} catch (e) {
|
|
1833
|
-
if (e instanceof UnsupportedPathError) {
|
|
1834
|
-
continue;
|
|
1835
|
-
}
|
|
1836
|
-
throw e;
|
|
1837
|
-
}
|
|
1838
|
-
this.match = router.match.bind(router);
|
|
1839
|
-
this.#routers = [router];
|
|
1840
|
-
this.#routes = void 0;
|
|
1841
|
-
break;
|
|
1842
|
-
}
|
|
1843
|
-
if (i === len) {
|
|
1844
|
-
throw new Error("Fatal error");
|
|
1845
|
-
}
|
|
1846
|
-
this.name = `SmartRouter + ${this.activeRouter.name}`;
|
|
1847
|
-
return res;
|
|
1848
|
-
}
|
|
1849
|
-
get activeRouter() {
|
|
1850
|
-
if (this.#routes || this.#routers.length !== 1) {
|
|
1851
|
-
throw new Error("No active router has been determined yet.");
|
|
1852
|
-
}
|
|
1853
|
-
return this.#routers[0];
|
|
1854
|
-
}
|
|
1855
|
-
};
|
|
1856
|
-
|
|
1857
|
-
// node_modules/hono/dist/router/trie-router/node.js
|
|
1858
|
-
var emptyParams = /* @__PURE__ */ Object.create(null);
|
|
1859
|
-
var hasChildren = (children) => {
|
|
1860
|
-
for (const _ in children) {
|
|
1861
|
-
return true;
|
|
1862
|
-
}
|
|
1863
|
-
return false;
|
|
1864
|
-
};
|
|
1865
|
-
var Node2 = class _Node2 {
|
|
1866
|
-
#methods;
|
|
1867
|
-
#children;
|
|
1868
|
-
#patterns;
|
|
1869
|
-
#order = 0;
|
|
1870
|
-
#params = emptyParams;
|
|
1871
|
-
constructor(method, handler, children) {
|
|
1872
|
-
this.#children = children || /* @__PURE__ */ Object.create(null);
|
|
1873
|
-
this.#methods = [];
|
|
1874
|
-
if (method && handler) {
|
|
1875
|
-
const m = /* @__PURE__ */ Object.create(null);
|
|
1876
|
-
m[method] = { handler, possibleKeys: [], score: 0 };
|
|
1877
|
-
this.#methods = [m];
|
|
1878
|
-
}
|
|
1879
|
-
this.#patterns = [];
|
|
1880
|
-
}
|
|
1881
|
-
insert(method, path, handler) {
|
|
1882
|
-
this.#order = ++this.#order;
|
|
1883
|
-
let curNode = this;
|
|
1884
|
-
const parts = splitRoutingPath(path);
|
|
1885
|
-
const possibleKeys = [];
|
|
1886
|
-
for (let i = 0, len = parts.length; i < len; i++) {
|
|
1887
|
-
const p = parts[i];
|
|
1888
|
-
const nextP = parts[i + 1];
|
|
1889
|
-
const pattern = getPattern(p, nextP);
|
|
1890
|
-
const key = Array.isArray(pattern) ? pattern[0] : p;
|
|
1891
|
-
if (key in curNode.#children) {
|
|
1892
|
-
curNode = curNode.#children[key];
|
|
1893
|
-
if (pattern) {
|
|
1894
|
-
possibleKeys.push(pattern[1]);
|
|
1895
|
-
}
|
|
1896
|
-
continue;
|
|
1897
|
-
}
|
|
1898
|
-
curNode.#children[key] = new _Node2();
|
|
1899
|
-
if (pattern) {
|
|
1900
|
-
curNode.#patterns.push(pattern);
|
|
1901
|
-
possibleKeys.push(pattern[1]);
|
|
1902
|
-
}
|
|
1903
|
-
curNode = curNode.#children[key];
|
|
1904
|
-
}
|
|
1905
|
-
curNode.#methods.push({
|
|
1906
|
-
[method]: {
|
|
1907
|
-
handler,
|
|
1908
|
-
possibleKeys: possibleKeys.filter((v, i, a) => a.indexOf(v) === i),
|
|
1909
|
-
score: this.#order
|
|
1910
|
-
}
|
|
1911
|
-
});
|
|
1912
|
-
return curNode;
|
|
1913
|
-
}
|
|
1914
|
-
#pushHandlerSets(handlerSets, node, method, nodeParams, params) {
|
|
1915
|
-
for (let i = 0, len = node.#methods.length; i < len; i++) {
|
|
1916
|
-
const m = node.#methods[i];
|
|
1917
|
-
const handlerSet = m[method] || m[METHOD_NAME_ALL];
|
|
1918
|
-
const processedSet = {};
|
|
1919
|
-
if (handlerSet !== void 0) {
|
|
1920
|
-
handlerSet.params = /* @__PURE__ */ Object.create(null);
|
|
1921
|
-
handlerSets.push(handlerSet);
|
|
1922
|
-
if (nodeParams !== emptyParams || params && params !== emptyParams) {
|
|
1923
|
-
for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
|
|
1924
|
-
const key = handlerSet.possibleKeys[i2];
|
|
1925
|
-
const processed = processedSet[handlerSet.score];
|
|
1926
|
-
handlerSet.params[key] = params?.[key] && !processed ? params[key] : nodeParams[key] ?? params?.[key];
|
|
1927
|
-
processedSet[handlerSet.score] = true;
|
|
1928
|
-
}
|
|
1929
|
-
}
|
|
1930
|
-
}
|
|
1931
|
-
}
|
|
1932
|
-
}
|
|
1933
|
-
search(method, path) {
|
|
1934
|
-
const handlerSets = [];
|
|
1935
|
-
this.#params = emptyParams;
|
|
1936
|
-
const curNode = this;
|
|
1937
|
-
let curNodes = [curNode];
|
|
1938
|
-
const parts = splitPath(path);
|
|
1939
|
-
const curNodesQueue = [];
|
|
1940
|
-
const len = parts.length;
|
|
1941
|
-
let partOffsets = null;
|
|
1942
|
-
for (let i = 0; i < len; i++) {
|
|
1943
|
-
const part = parts[i];
|
|
1944
|
-
const isLast = i === len - 1;
|
|
1945
|
-
const tempNodes = [];
|
|
1946
|
-
for (let j = 0, len2 = curNodes.length; j < len2; j++) {
|
|
1947
|
-
const node = curNodes[j];
|
|
1948
|
-
const nextNode = node.#children[part];
|
|
1949
|
-
if (nextNode) {
|
|
1950
|
-
nextNode.#params = node.#params;
|
|
1951
|
-
if (isLast) {
|
|
1952
|
-
if (nextNode.#children["*"]) {
|
|
1953
|
-
this.#pushHandlerSets(handlerSets, nextNode.#children["*"], method, node.#params);
|
|
1954
|
-
}
|
|
1955
|
-
this.#pushHandlerSets(handlerSets, nextNode, method, node.#params);
|
|
1956
|
-
} else {
|
|
1957
|
-
tempNodes.push(nextNode);
|
|
1958
|
-
}
|
|
1959
|
-
}
|
|
1960
|
-
for (let k = 0, len3 = node.#patterns.length; k < len3; k++) {
|
|
1961
|
-
const pattern = node.#patterns[k];
|
|
1962
|
-
const params = node.#params === emptyParams ? {} : { ...node.#params };
|
|
1963
|
-
if (pattern === "*") {
|
|
1964
|
-
const astNode = node.#children["*"];
|
|
1965
|
-
if (astNode) {
|
|
1966
|
-
this.#pushHandlerSets(handlerSets, astNode, method, node.#params);
|
|
1967
|
-
astNode.#params = params;
|
|
1968
|
-
tempNodes.push(astNode);
|
|
1969
|
-
}
|
|
1970
|
-
continue;
|
|
1971
|
-
}
|
|
1972
|
-
const [key, name, matcher] = pattern;
|
|
1973
|
-
if (!part && !(matcher instanceof RegExp)) {
|
|
1974
|
-
continue;
|
|
1975
|
-
}
|
|
1976
|
-
const child = node.#children[key];
|
|
1977
|
-
if (matcher instanceof RegExp) {
|
|
1978
|
-
if (partOffsets === null) {
|
|
1979
|
-
partOffsets = new Array(len);
|
|
1980
|
-
let offset = path[0] === "/" ? 1 : 0;
|
|
1981
|
-
for (let p = 0; p < len; p++) {
|
|
1982
|
-
partOffsets[p] = offset;
|
|
1983
|
-
offset += parts[p].length + 1;
|
|
1984
|
-
}
|
|
1985
|
-
}
|
|
1986
|
-
const restPathString = path.substring(partOffsets[i]);
|
|
1987
|
-
const m = matcher.exec(restPathString);
|
|
1988
|
-
if (m) {
|
|
1989
|
-
params[name] = m[0];
|
|
1990
|
-
this.#pushHandlerSets(handlerSets, child, method, node.#params, params);
|
|
1991
|
-
if (hasChildren(child.#children)) {
|
|
1992
|
-
child.#params = params;
|
|
1993
|
-
const componentCount = m[0].match(/\//)?.length ?? 0;
|
|
1994
|
-
const targetCurNodes = curNodesQueue[componentCount] ||= [];
|
|
1995
|
-
targetCurNodes.push(child);
|
|
1996
|
-
}
|
|
1997
|
-
continue;
|
|
1998
|
-
}
|
|
1999
|
-
}
|
|
2000
|
-
if (matcher === true || matcher.test(part)) {
|
|
2001
|
-
params[name] = part;
|
|
2002
|
-
if (isLast) {
|
|
2003
|
-
this.#pushHandlerSets(handlerSets, child, method, params, node.#params);
|
|
2004
|
-
if (child.#children["*"]) {
|
|
2005
|
-
this.#pushHandlerSets(
|
|
2006
|
-
handlerSets,
|
|
2007
|
-
child.#children["*"],
|
|
2008
|
-
method,
|
|
2009
|
-
params,
|
|
2010
|
-
node.#params
|
|
2011
|
-
);
|
|
2012
|
-
}
|
|
2013
|
-
} else {
|
|
2014
|
-
child.#params = params;
|
|
2015
|
-
tempNodes.push(child);
|
|
2016
|
-
}
|
|
2017
|
-
}
|
|
2018
|
-
}
|
|
2019
|
-
}
|
|
2020
|
-
const shifted = curNodesQueue.shift();
|
|
2021
|
-
curNodes = shifted ? tempNodes.concat(shifted) : tempNodes;
|
|
2022
|
-
}
|
|
2023
|
-
if (handlerSets.length > 1) {
|
|
2024
|
-
handlerSets.sort((a, b) => {
|
|
2025
|
-
return a.score - b.score;
|
|
2026
|
-
});
|
|
2027
|
-
}
|
|
2028
|
-
return [handlerSets.map(({ handler, params }) => [handler, params])];
|
|
2029
|
-
}
|
|
2030
|
-
};
|
|
2031
|
-
|
|
2032
|
-
// node_modules/hono/dist/router/trie-router/router.js
|
|
2033
|
-
var TrieRouter = class {
|
|
2034
|
-
name = "TrieRouter";
|
|
2035
|
-
#node;
|
|
2036
|
-
constructor() {
|
|
2037
|
-
this.#node = new Node2();
|
|
2038
|
-
}
|
|
2039
|
-
add(method, path, handler) {
|
|
2040
|
-
const results = checkOptionalParameter(path);
|
|
2041
|
-
if (results) {
|
|
2042
|
-
for (let i = 0, len = results.length; i < len; i++) {
|
|
2043
|
-
this.#node.insert(method, results[i], handler);
|
|
2044
|
-
}
|
|
2045
|
-
return;
|
|
2046
|
-
}
|
|
2047
|
-
this.#node.insert(method, path, handler);
|
|
2048
|
-
}
|
|
2049
|
-
match(method, path) {
|
|
2050
|
-
return this.#node.search(method, path);
|
|
2051
|
-
}
|
|
2052
|
-
};
|
|
2053
|
-
|
|
2054
|
-
// node_modules/hono/dist/hono.js
|
|
2055
|
-
var Hono2 = class extends Hono {
|
|
2056
|
-
/**
|
|
2057
|
-
* Creates an instance of the Hono class.
|
|
2058
|
-
*
|
|
2059
|
-
* @param options - Optional configuration options for the Hono instance.
|
|
2060
|
-
*/
|
|
2061
|
-
constructor(options = {}) {
|
|
2062
|
-
super(options);
|
|
2063
|
-
this.router = options.router ?? new SmartRouter({
|
|
2064
|
-
routers: [new RegExpRouter(), new TrieRouter()]
|
|
2065
|
-
});
|
|
2066
|
-
}
|
|
2067
|
-
};
|
|
2068
|
-
|
|
2069
|
-
// src/admin/server/services/status.ts
|
|
2070
|
-
import { existsSync, readdirSync, readFileSync } from "fs";
|
|
2071
|
-
import { join, resolve } from "path";
|
|
2072
|
-
init_parser();
|
|
2073
|
-
var _config;
|
|
2074
|
-
var _cache = null;
|
|
2075
|
-
function initStatus(config) {
|
|
2076
|
-
_config = config;
|
|
2077
|
-
_cache = null;
|
|
2078
|
-
}
|
|
2079
|
-
function getVersions() {
|
|
2080
|
-
return flattenSources(_config).map((s) => s.versionKey);
|
|
2081
|
-
}
|
|
2082
|
-
function getLangs() {
|
|
2083
|
-
return _config.languages;
|
|
2084
|
-
}
|
|
2085
|
-
function getCache() {
|
|
2086
|
-
if (!_cache) {
|
|
2087
|
-
_cache = new TranslationCache(resolve(_config.cacheDir ?? ".cache"));
|
|
2088
|
-
}
|
|
2089
|
-
return _cache;
|
|
2090
|
-
}
|
|
2091
|
-
function getSourcePath(versionKey) {
|
|
2092
|
-
const source = flattenSources(_config).find((s) => s.versionKey === versionKey);
|
|
2093
|
-
return source ? resolve(source.sourcePath) : null;
|
|
2094
|
-
}
|
|
2095
|
-
function walkFiles(dir) {
|
|
2096
|
-
const results = [];
|
|
2097
|
-
if (!existsSync(dir)) return results;
|
|
2098
|
-
const exts = (_config.include ?? ["**/*.mdx", "**/*.md"]).map((p) => p.replace("**/*", ""));
|
|
2099
|
-
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
2100
|
-
const fullPath = join(dir, entry.name);
|
|
2101
|
-
if (entry.isDirectory()) results.push(...walkFiles(fullPath));
|
|
2102
|
-
else if (exts.some((ext) => entry.name.endsWith(ext))) results.push(fullPath);
|
|
2103
|
-
}
|
|
2104
|
-
return results;
|
|
2105
|
-
}
|
|
2106
|
-
function ensureScanned(version) {
|
|
2107
|
-
const cache = getCache();
|
|
2108
|
-
const enDir = getSourcePath(version);
|
|
2109
|
-
if (!enDir || !existsSync(enDir)) return;
|
|
2110
|
-
const files = walkFiles(enDir);
|
|
2111
|
-
const currentCount = cache.sourceCount(version);
|
|
2112
|
-
if (currentCount >= files.length) return;
|
|
2113
|
-
cache.clearSources("", version);
|
|
2114
|
-
for (const file of files) {
|
|
2115
|
-
const relPath = file.slice(enDir.length + 1);
|
|
2116
|
-
const content = readFileSync(file, "utf8");
|
|
2117
|
-
const nodes = parseMdx(content);
|
|
2118
|
-
for (const node of nodes) {
|
|
2119
|
-
if (node.needsTranslation && node.md5) {
|
|
2120
|
-
const line = content.substring(0, node.startOffset).split("\n").length;
|
|
2121
|
-
cache.setSource(node.md5, node.rawText, node.type);
|
|
2122
|
-
cache.updateSource("", node.md5, relPath, line, version);
|
|
2123
|
-
}
|
|
2124
|
-
}
|
|
2125
|
-
}
|
|
2126
|
-
}
|
|
2127
|
-
function rescan(version) {
|
|
2128
|
-
const cache = getCache();
|
|
2129
|
-
const enDir = getSourcePath(version);
|
|
2130
|
-
if (!enDir || !existsSync(enDir)) return 0;
|
|
2131
|
-
const files = walkFiles(enDir);
|
|
2132
|
-
cache.clearSources("", version);
|
|
2133
|
-
for (const file of files) {
|
|
2134
|
-
const relPath = file.slice(enDir.length + 1);
|
|
2135
|
-
const content = readFileSync(file, "utf8");
|
|
2136
|
-
const nodes = parseMdx(content);
|
|
2137
|
-
for (const node of nodes) {
|
|
2138
|
-
if (node.needsTranslation && node.md5) {
|
|
2139
|
-
const line = content.substring(0, node.startOffset).split("\n").length;
|
|
2140
|
-
cache.setSource(node.md5, node.rawText, node.type);
|
|
2141
|
-
cache.updateSource("", node.md5, relPath, line, version);
|
|
2142
|
-
}
|
|
2143
|
-
}
|
|
2144
|
-
}
|
|
2145
|
-
return files.length;
|
|
2146
|
-
}
|
|
2147
|
-
function getOverview() {
|
|
2148
|
-
const cache = getCache();
|
|
2149
|
-
const versions = getVersions();
|
|
2150
|
-
const langs = getLangs();
|
|
2151
|
-
const result = {};
|
|
2152
|
-
for (const version of versions) {
|
|
2153
|
-
ensureScanned(version);
|
|
2154
|
-
const enDir = getSourcePath(version);
|
|
2155
|
-
const enFileCount = enDir && existsSync(enDir) ? walkFiles(enDir).length : 0;
|
|
2156
|
-
const langStats = {};
|
|
2157
|
-
for (const lang of langs) {
|
|
2158
|
-
const sections = cache.sectionStats(version, lang);
|
|
2159
|
-
let totalFiles = 0, translatedFiles = 0, totalNodes = 0, translatedNodes = 0;
|
|
2160
|
-
const sectionMap = {};
|
|
2161
|
-
for (const s of sections) {
|
|
2162
|
-
sectionMap[s.section] = s;
|
|
2163
|
-
totalFiles += s.totalFiles;
|
|
2164
|
-
translatedFiles += s.translatedFiles;
|
|
2165
|
-
totalNodes += s.totalNodes;
|
|
2166
|
-
translatedNodes += s.translatedNodes;
|
|
2167
|
-
}
|
|
2168
|
-
langStats[lang] = { sections: sectionMap, totalFiles, translatedFiles, totalNodes, translatedNodes };
|
|
2169
|
-
}
|
|
2170
|
-
result[version] = { enFileCount, langs: langStats };
|
|
2171
|
-
}
|
|
2172
|
-
return result;
|
|
2173
|
-
}
|
|
2174
|
-
function getFileCoverage(version, lang) {
|
|
2175
|
-
ensureScanned(version);
|
|
2176
|
-
return getCache().fileCoverage(version, lang);
|
|
2177
|
-
}
|
|
2178
|
-
function getFileBlocks(version, lang, file) {
|
|
2179
|
-
const enDir = getSourcePath(version);
|
|
2180
|
-
if (!enDir) return null;
|
|
2181
|
-
const enPath = join(enDir, file);
|
|
2182
|
-
if (!existsSync(enPath)) return null;
|
|
2183
|
-
const cache = getCache();
|
|
2184
|
-
const content = readFileSync(enPath, "utf8");
|
|
2185
|
-
const nodes = parseMdx(content);
|
|
2186
|
-
const blocks = [];
|
|
2187
|
-
let lastEnd = 0;
|
|
2188
|
-
for (const node of nodes) {
|
|
2189
|
-
if (node.startOffset > lastEnd) {
|
|
2190
|
-
const gap = content.substring(lastEnd, node.startOffset);
|
|
2191
|
-
blocks.push({ md5: null, type: "gap", source: gap, translation: null });
|
|
2192
|
-
}
|
|
2193
|
-
if (node.needsTranslation && node.md5) {
|
|
2194
|
-
const translation = lang === "en" ? null : cache.get(lang, node.md5) ?? null;
|
|
2195
|
-
blocks.push({ md5: node.md5, type: node.type, source: node.rawText, translation });
|
|
2196
|
-
} else {
|
|
2197
|
-
blocks.push({ md5: null, type: node.type, source: node.rawText, translation: null });
|
|
2198
|
-
}
|
|
2199
|
-
lastEnd = node.endOffset;
|
|
2200
|
-
}
|
|
2201
|
-
if (lastEnd < content.length) {
|
|
2202
|
-
const tail = content.substring(lastEnd);
|
|
2203
|
-
if (tail.trim()) blocks.push({ md5: null, type: "gap", source: tail, translation: null });
|
|
2204
|
-
}
|
|
2205
|
-
return blocks;
|
|
2206
|
-
}
|
|
2207
|
-
|
|
2208
|
-
// node_modules/hono/dist/utils/stream.js
|
|
2209
|
-
var StreamingApi = class {
|
|
2210
|
-
writer;
|
|
2211
|
-
encoder;
|
|
2212
|
-
writable;
|
|
2213
|
-
abortSubscribers = [];
|
|
2214
|
-
responseReadable;
|
|
2215
|
-
/**
|
|
2216
|
-
* Whether the stream has been aborted.
|
|
2217
|
-
*/
|
|
2218
|
-
aborted = false;
|
|
2219
|
-
/**
|
|
2220
|
-
* Whether the stream has been closed normally.
|
|
2221
|
-
*/
|
|
2222
|
-
closed = false;
|
|
2223
|
-
constructor(writable, _readable) {
|
|
2224
|
-
this.writable = writable;
|
|
2225
|
-
this.writer = writable.getWriter();
|
|
2226
|
-
this.encoder = new TextEncoder();
|
|
2227
|
-
const reader = _readable.getReader();
|
|
2228
|
-
this.abortSubscribers.push(async () => {
|
|
2229
|
-
await reader.cancel();
|
|
2230
|
-
});
|
|
2231
|
-
this.responseReadable = new ReadableStream({
|
|
2232
|
-
async pull(controller) {
|
|
2233
|
-
const { done, value } = await reader.read();
|
|
2234
|
-
done ? controller.close() : controller.enqueue(value);
|
|
2235
|
-
},
|
|
2236
|
-
cancel: () => {
|
|
2237
|
-
this.abort();
|
|
2238
|
-
}
|
|
2239
|
-
});
|
|
2240
|
-
}
|
|
2241
|
-
async write(input) {
|
|
2242
|
-
try {
|
|
2243
|
-
if (typeof input === "string") {
|
|
2244
|
-
input = this.encoder.encode(input);
|
|
2245
|
-
}
|
|
2246
|
-
await this.writer.write(input);
|
|
2247
|
-
} catch {
|
|
2248
|
-
}
|
|
2249
|
-
return this;
|
|
2250
|
-
}
|
|
2251
|
-
async writeln(input) {
|
|
2252
|
-
await this.write(input + "\n");
|
|
2253
|
-
return this;
|
|
2254
|
-
}
|
|
2255
|
-
sleep(ms) {
|
|
2256
|
-
return new Promise((res) => setTimeout(res, ms));
|
|
2257
|
-
}
|
|
2258
|
-
async close() {
|
|
2259
|
-
try {
|
|
2260
|
-
await this.writer.close();
|
|
2261
|
-
} catch {
|
|
2262
|
-
}
|
|
2263
|
-
this.closed = true;
|
|
2264
|
-
}
|
|
2265
|
-
async pipe(body) {
|
|
2266
|
-
this.writer.releaseLock();
|
|
2267
|
-
await body.pipeTo(this.writable, { preventClose: true });
|
|
2268
|
-
this.writer = this.writable.getWriter();
|
|
2269
|
-
}
|
|
2270
|
-
onAbort(listener) {
|
|
2271
|
-
this.abortSubscribers.push(listener);
|
|
2272
|
-
}
|
|
2273
|
-
/**
|
|
2274
|
-
* Abort the stream.
|
|
2275
|
-
* You can call this method when stream is aborted by external event.
|
|
2276
|
-
*/
|
|
2277
|
-
abort() {
|
|
2278
|
-
if (!this.aborted) {
|
|
2279
|
-
this.aborted = true;
|
|
2280
|
-
this.abortSubscribers.forEach((subscriber) => subscriber());
|
|
2281
|
-
}
|
|
2282
|
-
}
|
|
2283
|
-
};
|
|
2284
|
-
|
|
2285
|
-
// node_modules/hono/dist/helper/streaming/utils.js
|
|
2286
|
-
var isOldBunVersion = () => {
|
|
2287
|
-
const version = typeof Bun !== "undefined" ? Bun.version : void 0;
|
|
2288
|
-
if (version === void 0) {
|
|
2289
|
-
return false;
|
|
2290
|
-
}
|
|
2291
|
-
const result = version.startsWith("1.1") || version.startsWith("1.0") || version.startsWith("0.");
|
|
2292
|
-
isOldBunVersion = () => result;
|
|
2293
|
-
return result;
|
|
2294
|
-
};
|
|
2295
|
-
|
|
2296
|
-
// node_modules/hono/dist/helper/streaming/sse.js
|
|
2297
|
-
var SSEStreamingApi = class extends StreamingApi {
|
|
2298
|
-
constructor(writable, readable) {
|
|
2299
|
-
super(writable, readable);
|
|
2300
|
-
}
|
|
2301
|
-
async writeSSE(message) {
|
|
2302
|
-
const data = await resolveCallback(message.data, HtmlEscapedCallbackPhase.Stringify, false, {});
|
|
2303
|
-
const dataLines = data.split(/\r\n|\r|\n/).map((line) => {
|
|
2304
|
-
return `data: ${line}`;
|
|
2305
|
-
}).join("\n");
|
|
2306
|
-
for (const key of ["event", "id", "retry"]) {
|
|
2307
|
-
if (message[key] && /[\r\n]/.test(message[key])) {
|
|
2308
|
-
throw new Error(`${key} must not contain "\\r" or "\\n"`);
|
|
2309
|
-
}
|
|
2310
|
-
}
|
|
2311
|
-
const sseData = [
|
|
2312
|
-
message.event && `event: ${message.event}`,
|
|
2313
|
-
dataLines,
|
|
2314
|
-
message.id && `id: ${message.id}`,
|
|
2315
|
-
message.retry && `retry: ${message.retry}`
|
|
2316
|
-
].filter(Boolean).join("\n") + "\n\n";
|
|
2317
|
-
await this.write(sseData);
|
|
2318
|
-
}
|
|
2319
|
-
};
|
|
2320
|
-
var run = async (stream2, cb, onError) => {
|
|
2321
|
-
try {
|
|
2322
|
-
await cb(stream2);
|
|
2323
|
-
} catch (e) {
|
|
2324
|
-
if (e instanceof Error && onError) {
|
|
2325
|
-
await onError(e, stream2);
|
|
2326
|
-
await stream2.writeSSE({
|
|
2327
|
-
event: "error",
|
|
2328
|
-
data: e.message
|
|
2329
|
-
});
|
|
2330
|
-
} else {
|
|
2331
|
-
console.error(e);
|
|
2332
|
-
}
|
|
2333
|
-
} finally {
|
|
2334
|
-
stream2.close();
|
|
2335
|
-
}
|
|
2336
|
-
};
|
|
2337
|
-
var contextStash = /* @__PURE__ */ new WeakMap();
|
|
2338
|
-
var streamSSE = (c, cb, onError) => {
|
|
2339
|
-
const { readable, writable } = new TransformStream();
|
|
2340
|
-
const stream2 = new SSEStreamingApi(writable, readable);
|
|
2341
|
-
if (isOldBunVersion()) {
|
|
2342
|
-
c.req.raw.signal.addEventListener("abort", () => {
|
|
2343
|
-
if (!stream2.closed) {
|
|
2344
|
-
stream2.abort();
|
|
2345
|
-
}
|
|
2346
|
-
});
|
|
2347
|
-
}
|
|
2348
|
-
contextStash.set(stream2.responseReadable, c);
|
|
2349
|
-
c.header("Transfer-Encoding", "chunked");
|
|
2350
|
-
c.header("Content-Type", "text/event-stream");
|
|
2351
|
-
c.header("Cache-Control", "no-cache");
|
|
2352
|
-
c.header("Connection", "keep-alive");
|
|
2353
|
-
run(stream2, cb, onError);
|
|
2354
|
-
return c.newResponse(stream2.responseReadable);
|
|
2355
|
-
};
|
|
2356
|
-
|
|
2357
|
-
// src/admin/server/services/job-manager.ts
|
|
2358
|
-
import { spawn } from "child_process";
|
|
2359
|
-
var PROJECT_ROOT = process.cwd();
|
|
2360
|
-
var JobManager = class {
|
|
2361
|
-
jobs = /* @__PURE__ */ new Map();
|
|
2362
|
-
processes = /* @__PURE__ */ new Map();
|
|
2363
|
-
subscribers = /* @__PURE__ */ new Map();
|
|
2364
|
-
nextId = 1;
|
|
2365
|
-
start(opts) {
|
|
2366
|
-
for (const [, job2] of this.jobs) {
|
|
2367
|
-
if (job2.lang === opts.lang && job2.version === opts.version && job2.status === "running") {
|
|
2368
|
-
throw new Error(`Job already running for ${opts.lang}/${opts.version}`);
|
|
2369
|
-
}
|
|
2370
|
-
}
|
|
2371
|
-
const id = `job-${this.nextId++}`;
|
|
2372
|
-
const job = {
|
|
2373
|
-
id,
|
|
2374
|
-
lang: opts.lang,
|
|
2375
|
-
version: opts.version,
|
|
2376
|
-
project: opts.project ?? "",
|
|
2377
|
-
status: "running",
|
|
2378
|
-
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2379
|
-
logLines: [],
|
|
2380
|
-
translatedFiles: 0,
|
|
2381
|
-
totalFiles: 0,
|
|
2382
|
-
toTranslate: 0,
|
|
2383
|
-
errorFiles: 0
|
|
2384
|
-
};
|
|
2385
|
-
this.jobs.set(id, job);
|
|
2386
|
-
const args = [
|
|
2387
|
-
"src/cli.ts",
|
|
2388
|
-
// In dev; in production would be the installed bin
|
|
2389
|
-
"translate",
|
|
2390
|
-
"--lang",
|
|
2391
|
-
opts.lang,
|
|
2392
|
-
"--version",
|
|
2393
|
-
opts.version,
|
|
2394
|
-
"--max",
|
|
2395
|
-
String(opts.max ?? 999),
|
|
2396
|
-
"--concurrency",
|
|
2397
|
-
String(opts.concurrency ?? 3)
|
|
2398
|
-
];
|
|
2399
|
-
if (opts.project) args.push("--project", opts.project);
|
|
2400
|
-
if (opts.model) args.push("--model", opts.model);
|
|
2401
|
-
if (opts.files?.length) args.push("--files", opts.files.join(","));
|
|
2402
|
-
const proc = spawn("bun", args, {
|
|
2403
|
-
cwd: PROJECT_ROOT,
|
|
2404
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
2405
|
-
env: { ...process.env, NO_TTY: "1", FORCE_COLOR: "0" }
|
|
2406
|
-
});
|
|
2407
|
-
this.processes.set(id, proc);
|
|
2408
|
-
proc.stdout?.on("data", (d) => {
|
|
2409
|
-
for (const line of d.toString().split("\n").filter(Boolean)) {
|
|
2410
|
-
this.addLog(id, line);
|
|
2411
|
-
this.parseProgress(job, line);
|
|
2412
|
-
}
|
|
2413
|
-
});
|
|
2414
|
-
proc.stderr?.on("data", (d) => {
|
|
2415
|
-
for (const line of d.toString().split("\n").filter(Boolean)) {
|
|
2416
|
-
this.addLog(id, line);
|
|
2417
|
-
}
|
|
2418
|
-
});
|
|
2419
|
-
proc.on("exit", (code) => {
|
|
2420
|
-
job.status = code === 0 ? "completed" : "failed";
|
|
2421
|
-
job.exitCode = code;
|
|
2422
|
-
job.finishedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
2423
|
-
job.currentFile = void 0;
|
|
2424
|
-
this.addLog(id, `Process exited with code ${code}`);
|
|
2425
|
-
this.processes.delete(id);
|
|
2426
|
-
this.emit(id, { type: "exit", code });
|
|
2427
|
-
});
|
|
2428
|
-
proc.on("error", (err) => {
|
|
2429
|
-
job.status = "failed";
|
|
2430
|
-
job.finishedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
2431
|
-
this.addLog(id, `Process error: ${err.message}`);
|
|
2432
|
-
this.processes.delete(id);
|
|
2433
|
-
this.emit(id, { type: "exit", code: -1 });
|
|
2434
|
-
});
|
|
2435
|
-
return job;
|
|
2436
|
-
}
|
|
2437
|
-
cancel(id) {
|
|
2438
|
-
const proc = this.processes.get(id);
|
|
2439
|
-
const job = this.jobs.get(id);
|
|
2440
|
-
if (!proc || !job) return false;
|
|
2441
|
-
proc.kill("SIGTERM");
|
|
2442
|
-
job.status = "cancelled";
|
|
2443
|
-
job.finishedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
2444
|
-
this.processes.delete(id);
|
|
2445
|
-
this.emit(id, { type: "exit", code: null });
|
|
2446
|
-
return true;
|
|
2447
|
-
}
|
|
2448
|
-
list() {
|
|
2449
|
-
return [...this.jobs.values()].sort(
|
|
2450
|
-
(a, b) => new Date(b.startedAt).getTime() - new Date(a.startedAt).getTime()
|
|
2451
|
-
);
|
|
2452
|
-
}
|
|
2453
|
-
get(id) {
|
|
2454
|
-
return this.jobs.get(id);
|
|
2455
|
-
}
|
|
2456
|
-
remove(id) {
|
|
2457
|
-
const job = this.jobs.get(id);
|
|
2458
|
-
if (!job || job.status === "running") return false;
|
|
2459
|
-
this.jobs.delete(id);
|
|
2460
|
-
this.subscribers.delete(id);
|
|
2461
|
-
return true;
|
|
2462
|
-
}
|
|
2463
|
-
subscribe(id, callback) {
|
|
2464
|
-
if (!this.subscribers.has(id)) this.subscribers.set(id, /* @__PURE__ */ new Set());
|
|
2465
|
-
this.subscribers.get(id)?.add(callback);
|
|
2466
|
-
return () => {
|
|
2467
|
-
this.subscribers.get(id)?.delete(callback);
|
|
2468
|
-
};
|
|
2469
|
-
}
|
|
2470
|
-
addLog(id, line) {
|
|
2471
|
-
const job = this.jobs.get(id);
|
|
2472
|
-
if (!job) return;
|
|
2473
|
-
const ts = (/* @__PURE__ */ new Date()).toLocaleTimeString("en-US", { hour12: false });
|
|
2474
|
-
const entry = `[${ts}] ${line}`;
|
|
2475
|
-
job.logLines = job.logLines ?? [];
|
|
2476
|
-
job.logLines.push(entry);
|
|
2477
|
-
if (job.logLines.length > 500) job.logLines.shift();
|
|
2478
|
-
this.emit(id, { type: "log", data: entry });
|
|
2479
|
-
}
|
|
2480
|
-
emit(id, event) {
|
|
2481
|
-
this.subscribers.get(id)?.forEach((cb) => cb(event));
|
|
2482
|
-
}
|
|
2483
|
-
parseProgress(job, line) {
|
|
2484
|
-
const cached = line.match(/\+(\d+) cached/);
|
|
2485
|
-
if (cached) job.translatedFiles += Number.parseInt(cached[1], 10);
|
|
2486
|
-
const untranslated = line.match(/(\d+) untranslated keys/);
|
|
2487
|
-
if (untranslated) job.toTranslate = Number.parseInt(untranslated[1], 10);
|
|
2488
|
-
const chunk = line.match(/chunk \d+\/(\d+)/);
|
|
2489
|
-
if (chunk) job.totalFiles = Number.parseInt(chunk[1], 10);
|
|
2490
|
-
if (line.includes("\u23F3")) job.currentFile = line.replace(/^⏳\s*/, "");
|
|
2491
|
-
}
|
|
2492
|
-
};
|
|
2493
|
-
var jobManager = new JobManager();
|
|
2494
|
-
|
|
2495
|
-
// src/admin/server/routes/jobs.ts
|
|
2496
|
-
var app = new Hono2();
|
|
2497
|
-
app.get("/", (c) => {
|
|
2498
|
-
return c.json(
|
|
2499
|
-
jobManager.list().map((j) => ({
|
|
2500
|
-
...j,
|
|
2501
|
-
logLines: (j.logLines ?? []).slice(-20)
|
|
2502
|
-
// Last 20 lines in list view
|
|
2503
|
-
}))
|
|
2504
|
-
);
|
|
2505
|
-
});
|
|
2506
|
-
app.post("/", async (c) => {
|
|
2507
|
-
const body = await c.req.json();
|
|
2508
|
-
if (!body.lang || !body.version) {
|
|
2509
|
-
return c.json({ error: "Missing lang or version" }, 400);
|
|
2510
|
-
}
|
|
2511
|
-
try {
|
|
2512
|
-
const job = jobManager.start(body);
|
|
2513
|
-
return c.json(job, 201);
|
|
2514
|
-
} catch (err) {
|
|
2515
|
-
return c.json(
|
|
2516
|
-
{ error: err instanceof Error ? err.message : "Unknown error" },
|
|
2517
|
-
409
|
|
2518
|
-
);
|
|
2519
|
-
}
|
|
2520
|
-
});
|
|
2521
|
-
app.get("/:id", (c) => {
|
|
2522
|
-
const job = jobManager.get(c.req.param("id"));
|
|
2523
|
-
if (!job) return c.json({ error: "Job not found" }, 404);
|
|
2524
|
-
return c.json(job);
|
|
2525
|
-
});
|
|
2526
|
-
app.delete("/:id", (c) => {
|
|
2527
|
-
const id = c.req.param("id");
|
|
2528
|
-
const job = jobManager.get(id);
|
|
2529
|
-
if (!job) return c.json({ error: "Job not found" }, 404);
|
|
2530
|
-
if (job.status === "running") {
|
|
2531
|
-
jobManager.cancel(id);
|
|
2532
|
-
} else {
|
|
2533
|
-
jobManager.remove(id);
|
|
2534
|
-
}
|
|
2535
|
-
return c.json({ ok: true });
|
|
2536
|
-
});
|
|
2537
|
-
app.get("/:id/stream", (c) => {
|
|
2538
|
-
const id = c.req.param("id");
|
|
2539
|
-
const job = jobManager.get(id);
|
|
2540
|
-
if (!job) return c.json({ error: "Job not found" }, 404);
|
|
2541
|
-
return streamSSE(c, async (stream2) => {
|
|
2542
|
-
await stream2.writeSSE({
|
|
2543
|
-
data: JSON.stringify({
|
|
2544
|
-
type: "state",
|
|
2545
|
-
data: { ...job, logLines: (job.logLines ?? []).slice(-50) }
|
|
2546
|
-
}),
|
|
2547
|
-
event: "message"
|
|
2548
|
-
});
|
|
2549
|
-
const unsubscribe = jobManager.subscribe(id, async (event) => {
|
|
2550
|
-
try {
|
|
2551
|
-
await stream2.writeSSE({
|
|
2552
|
-
data: JSON.stringify(event),
|
|
2553
|
-
event: "message"
|
|
2554
|
-
});
|
|
2555
|
-
} catch {
|
|
2556
|
-
unsubscribe();
|
|
2557
|
-
}
|
|
2558
|
-
});
|
|
2559
|
-
while (true) {
|
|
2560
|
-
const currentJob = jobManager.get(id);
|
|
2561
|
-
if (!currentJob || currentJob.status !== "running") {
|
|
2562
|
-
await stream2.writeSSE({
|
|
2563
|
-
data: JSON.stringify({ type: "done", data: currentJob }),
|
|
2564
|
-
event: "message"
|
|
2565
|
-
});
|
|
2566
|
-
break;
|
|
2567
|
-
}
|
|
2568
|
-
await stream2.sleep(1e3);
|
|
2569
|
-
}
|
|
2570
|
-
unsubscribe();
|
|
2571
|
-
});
|
|
2572
|
-
});
|
|
2573
|
-
var jobs_default = app;
|
|
2574
|
-
|
|
2575
|
-
// src/admin/server/routes/models.ts
|
|
2576
|
-
var app2 = new Hono2();
|
|
2577
|
-
var cachedResult = null;
|
|
2578
|
-
var cacheTime = 0;
|
|
2579
|
-
var CACHE_TTL = 5 * 60 * 1e3;
|
|
2580
|
-
app2.get("/", async (c) => {
|
|
2581
|
-
const now = Date.now();
|
|
2582
|
-
if (cachedResult && now - cacheTime < CACHE_TTL) {
|
|
2583
|
-
return c.json(cachedResult);
|
|
2584
|
-
}
|
|
2585
|
-
try {
|
|
2586
|
-
const res = await fetch("https://openrouter.ai/api/v1/models");
|
|
2587
|
-
if (!res.ok) {
|
|
2588
|
-
return c.json({ error: `OpenRouter API error: ${res.status}` }, 502);
|
|
2589
|
-
}
|
|
2590
|
-
const { data } = await res.json();
|
|
2591
|
-
cachedResult = formatModels(data);
|
|
2592
|
-
cacheTime = now;
|
|
2593
|
-
return c.json(cachedResult);
|
|
2594
|
-
} catch (err) {
|
|
2595
|
-
return c.json(
|
|
2596
|
-
{ error: err instanceof Error ? err.message : "Failed to fetch models" },
|
|
2597
|
-
500
|
|
2598
|
-
);
|
|
2599
|
-
}
|
|
2600
|
-
});
|
|
2601
|
-
function formatModels(models) {
|
|
2602
|
-
return models.filter((m) => {
|
|
2603
|
-
if (!m.pricing) return false;
|
|
2604
|
-
const pp = Number.parseFloat(m.pricing.prompt);
|
|
2605
|
-
const cp = Number.parseFloat(m.pricing.completion);
|
|
2606
|
-
if (pp < 0 || cp < 0) return false;
|
|
2607
|
-
if (!m.architecture?.modality?.startsWith("text")) return false;
|
|
2608
|
-
if (!m.architecture.output_modalities?.includes("text")) return false;
|
|
2609
|
-
return true;
|
|
2610
|
-
}).map((m) => {
|
|
2611
|
-
const pp = Number.parseFloat(m.pricing.prompt) * 1e6;
|
|
2612
|
-
const cp = Number.parseFloat(m.pricing.completion) * 1e6;
|
|
2613
|
-
return {
|
|
2614
|
-
id: m.id,
|
|
2615
|
-
name: m.name,
|
|
2616
|
-
promptPrice: pp,
|
|
2617
|
-
completionPrice: cp,
|
|
2618
|
-
contextLength: m.context_length,
|
|
2619
|
-
maxOutput: m.top_provider?.max_completion_tokens ?? 0,
|
|
2620
|
-
isFree: pp === 0 && cp === 0,
|
|
2621
|
-
supportsJson: m.supported_parameters?.includes("response_format") || m.supported_parameters?.includes("structured_outputs"),
|
|
2622
|
-
supportsTools: m.supported_parameters?.includes("tools"),
|
|
2623
|
-
provider: m.id.split("/")[0]
|
|
2624
|
-
};
|
|
2625
|
-
}).sort((a, b) => a.promptPrice - b.promptPrice);
|
|
2626
|
-
}
|
|
2627
|
-
var models_default = app2;
|
|
2628
|
-
|
|
2629
|
-
// src/admin/server/routes/status.ts
|
|
2630
|
-
var app3 = new Hono2();
|
|
2631
|
-
app3.get("/", (c) => {
|
|
2632
|
-
return c.json({
|
|
2633
|
-
versions: getVersions(),
|
|
2634
|
-
langs: ["en", ...getLangs()],
|
|
2635
|
-
data: getOverview()
|
|
2636
|
-
});
|
|
2637
|
-
});
|
|
2638
|
-
app3.get("/:version/:lang", (c) => {
|
|
2639
|
-
const { version, lang } = c.req.param();
|
|
2640
|
-
if (lang === "en") {
|
|
2641
|
-
const anyLang = getLangs()[0];
|
|
2642
|
-
const coverage = getFileCoverage(version, anyLang);
|
|
2643
|
-
return c.json(coverage.map((f) => ({ file: f.file, total: f.total, translated: f.total })));
|
|
2644
|
-
}
|
|
2645
|
-
return c.json(getFileCoverage(version, lang));
|
|
2646
|
-
});
|
|
2647
|
-
app3.get("/:version/:lang/blocks", (c) => {
|
|
2648
|
-
const { version, lang } = c.req.param();
|
|
2649
|
-
const filePath = c.req.query("path");
|
|
2650
|
-
if (!filePath) return c.json({ error: "Missing path query param" }, 400);
|
|
2651
|
-
const blocks = getFileBlocks(version, lang, filePath);
|
|
2652
|
-
if (!blocks) return c.json({ error: "File not found" }, 404);
|
|
2653
|
-
return c.json({ file: filePath, lang, version, blocks });
|
|
2654
|
-
});
|
|
2655
|
-
app3.delete("/:version/:lang/cache", (c) => {
|
|
2656
|
-
const { lang } = c.req.param();
|
|
2657
|
-
const key = c.req.query("key");
|
|
2658
|
-
if (!key) return c.json({ error: "Missing key query param" }, 400);
|
|
2659
|
-
const cache = getCache();
|
|
2660
|
-
cache.db.prepare("DELETE FROM translations WHERE lang = ? AND key = ?").run(lang, key);
|
|
2661
|
-
return c.json({ deleted: key, lang });
|
|
2662
|
-
});
|
|
2663
|
-
app3.post("/:version/rescan", (c) => {
|
|
2664
|
-
const { version } = c.req.param();
|
|
2665
|
-
const count = rescan(version);
|
|
2666
|
-
return c.json({ version, files: count });
|
|
2667
|
-
});
|
|
2668
|
-
var status_default = app3;
|
|
2669
|
-
|
|
2670
|
-
// src/admin/server/index.ts
|
|
2671
|
-
async function startAdmin(config, port = 3456) {
|
|
2672
|
-
initStatus(config);
|
|
2673
|
-
const app4 = new Hono2();
|
|
2674
|
-
app4.route("/api/status", status_default);
|
|
2675
|
-
app4.route("/api/jobs", jobs_default);
|
|
2676
|
-
app4.route("/api/models", models_default);
|
|
2677
|
-
app4.get("/api/health", (c) => c.json({ ok: true }));
|
|
2678
|
-
app4.get("/api/config", (c) => c.json({ projectRoot: process.cwd() }));
|
|
2679
|
-
app4.post("/api/open-file", async (c) => {
|
|
2680
|
-
const { file } = await c.req.json();
|
|
2681
|
-
if (!file) return c.json({ error: "Missing file" }, 400);
|
|
2682
|
-
const fullPath = resolve2(process.cwd(), file);
|
|
2683
|
-
if (!fullPath.startsWith(process.cwd())) return c.json({ error: "Invalid path" }, 400);
|
|
2684
|
-
const candidates = process.env.EDITOR_CMD ? [process.env.EDITOR_CMD] : ["code", "cursor", "zed"];
|
|
2685
|
-
for (const cmd of candidates) {
|
|
2686
|
-
const which = Bun.spawn(["which", cmd], { stdio: ["ignore", "pipe", "ignore"] });
|
|
2687
|
-
await which.exited;
|
|
2688
|
-
if (which.exitCode === 0) {
|
|
2689
|
-
Bun.spawn([cmd, fullPath], { stdio: ["ignore", "ignore", "ignore"] });
|
|
2690
|
-
return c.json({ opened: fullPath, editor: cmd });
|
|
2691
|
-
}
|
|
2692
|
-
}
|
|
2693
|
-
const fallback = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
|
|
2694
|
-
Bun.spawn([fallback, fullPath], { stdio: ["ignore", "ignore", "ignore"] });
|
|
2695
|
-
return c.json({ opened: fullPath, editor: fallback });
|
|
2696
|
-
});
|
|
2697
|
-
const thisFile = new URL(import.meta.url).pathname;
|
|
2698
|
-
const pkgRoot = resolve2(thisFile, "..", "..");
|
|
2699
|
-
const adminRoot = resolve2(pkgRoot, "src", "admin");
|
|
2700
|
-
try {
|
|
2701
|
-
const { createServer: createViteServer } = await import("vite");
|
|
2702
|
-
const vite = await createViteServer({
|
|
2703
|
-
root: adminRoot,
|
|
2704
|
-
server: { middlewareMode: true },
|
|
2705
|
-
appType: "spa"
|
|
2706
|
-
});
|
|
2707
|
-
const server = createServer(async (req, res) => {
|
|
2708
|
-
const url = req.url ?? "/";
|
|
2709
|
-
if (url.startsWith("/api")) {
|
|
2710
|
-
const headers = new Headers();
|
|
2711
|
-
for (const [k, v] of Object.entries(req.headers)) {
|
|
2712
|
-
if (v) headers.set(k, Array.isArray(v) ? v.join(", ") : v);
|
|
2713
|
-
}
|
|
2714
|
-
const body = req.method !== "GET" && req.method !== "HEAD" ? await new Promise((r) => {
|
|
2715
|
-
let data = "";
|
|
2716
|
-
req.on("data", (c) => {
|
|
2717
|
-
data += c.toString();
|
|
2718
|
-
});
|
|
2719
|
-
req.on("end", () => r(data));
|
|
2720
|
-
}) : void 0;
|
|
2721
|
-
const webReq = new Request(`http://localhost:${port}${url}`, {
|
|
2722
|
-
method: req.method,
|
|
2723
|
-
headers,
|
|
2724
|
-
body
|
|
2725
|
-
});
|
|
2726
|
-
const webRes = await app4.fetch(webReq);
|
|
2727
|
-
res.writeHead(webRes.status, Object.fromEntries(webRes.headers.entries()));
|
|
2728
|
-
res.end(Buffer.from(await webRes.arrayBuffer()));
|
|
2729
|
-
return;
|
|
2730
|
-
}
|
|
2731
|
-
vite.middlewares(req, res);
|
|
2732
|
-
});
|
|
2733
|
-
server.listen(port, () => {
|
|
2734
|
-
console.log(`\u{1F310} docs-i18n admin \u2192 http://localhost:${port}`);
|
|
2735
|
-
});
|
|
2736
|
-
} catch {
|
|
2737
|
-
console.error("Failed to start admin UI (vite not available). API-only mode.");
|
|
2738
|
-
const server = Bun.serve({ port, fetch: app4.fetch });
|
|
2739
|
-
console.log(`\u{1F310} docs-i18n admin (API only) \u2192 http://localhost:${port}`);
|
|
2740
|
-
}
|
|
2741
|
-
}
|
|
2742
|
-
export {
|
|
2743
|
-
startAdmin
|
|
2744
|
-
};
|