@apisurf/wireui 0.1.2
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/LICENSE +15 -0
- package/README.md +157 -0
- package/bin/wireui.mjs +233 -0
- package/dist/nitro.json +17 -0
- package/dist/public/assets/collections-CLHcfRfi.js +1 -0
- package/dist/public/assets/globals-CZiNFGaK.css +1 -0
- package/dist/public/assets/index-D5VFd_3H.js +14 -0
- package/dist/public/assets/kv-table-oB5gcq0i.js +2 -0
- package/dist/public/assets/query-BKAhHNIi.js +19 -0
- package/dist/public/assets/requests._requestId-Bu7E2eoI.js +1 -0
- package/dist/public/assets/routes-DDY2CfzA.js +1 -0
- package/dist/public/assets/runs._runId-CzwtVjYq.js +1 -0
- package/dist/public/assets/scoped-DB8raIWx.js +1 -0
- package/dist/public/assets/split-Br1RX2I4.js +1 -0
- package/dist/public/favicon.svg +1 -0
- package/dist/server/_chunks/ssr-renderer.mjs +26 -0
- package/dist/server/_libs/@tanstack/react-router+[...].mjs +15246 -0
- package/dist/server/_libs/h3+rou3+srvx.mjs +2086 -0
- package/dist/server/_libs/hookable.mjs +41 -0
- package/dist/server/_libs/tanstack__history.mjs +369 -0
- package/dist/server/_libs/ufo.mjs +64 -0
- package/dist/server/_runtime.mjs +35 -0
- package/dist/server/_ssr/api-Dw1Zb_PK.mjs +931 -0
- package/dist/server/_ssr/collections-CqidTQpw.mjs +495 -0
- package/dist/server/_ssr/empty-plugin-adapters-CCuiUfKt.mjs +5 -0
- package/dist/server/_ssr/kv-table-DQUkoItO.mjs +458 -0
- package/dist/server/_ssr/query-D4so9xiY.mjs +416 -0
- package/dist/server/_ssr/requests._requestId-BFukRwqL.mjs +942 -0
- package/dist/server/_ssr/router-CPcgc_kh.mjs +3176 -0
- package/dist/server/_ssr/routes-DaV9vGHn.mjs +375 -0
- package/dist/server/_ssr/runs._runId-Df_LmPHa.mjs +836 -0
- package/dist/server/_ssr/scoped-CnQ56K8h.mjs +42 -0
- package/dist/server/_ssr/split-DWrMIs7K.mjs +115 -0
- package/dist/server/_ssr/ssr.mjs +6827 -0
- package/dist/server/_ssr/start-zk_ZfrWl.mjs +4 -0
- package/dist/server/_tanstack-start-manifest_v-CARKjHfs.mjs +50 -0
- package/dist/server/index.mjs +368 -0
- package/package.json +71 -0
|
@@ -0,0 +1,2086 @@
|
|
|
1
|
+
import nodeHTTP from "node:http";
|
|
2
|
+
import { PassThrough, Readable } from "node:stream";
|
|
3
|
+
import { pipeline } from "node:stream/promises";
|
|
4
|
+
import nodeHTTPS from "node:https";
|
|
5
|
+
import nodeHTTP2 from "node:http2";
|
|
6
|
+
//#region ../../node_modules/.pnpm/srvx@1.0.5/node_modules/srvx/dist/_chunks/_url.mjs
|
|
7
|
+
function lazyInherit(target, source, sourceKey) {
|
|
8
|
+
for (const key of [...Object.getOwnPropertyNames(source), ...Object.getOwnPropertySymbols(source)]) {
|
|
9
|
+
if (key === "constructor") continue;
|
|
10
|
+
const targetDesc = Object.getOwnPropertyDescriptor(target, key);
|
|
11
|
+
const desc = Object.getOwnPropertyDescriptor(source, key);
|
|
12
|
+
let modified = false;
|
|
13
|
+
if (desc.get) {
|
|
14
|
+
modified = true;
|
|
15
|
+
desc.get = targetDesc?.get || function() {
|
|
16
|
+
return this[sourceKey][key];
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
if (desc.set) {
|
|
20
|
+
modified = true;
|
|
21
|
+
desc.set = targetDesc?.set || function(value) {
|
|
22
|
+
this[sourceKey][key] = value;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
if (!targetDesc?.value && typeof desc.value === "function") {
|
|
26
|
+
modified = true;
|
|
27
|
+
desc.value = function(...args) {
|
|
28
|
+
return this[sourceKey][key](...args);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
if (modified) Object.defineProperty(target, key, desc);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
var _needsNormRE = /(?:(?:^|\/)(?:\.|\.\.|%2e|%2e\.|\.%2e|%2e%2e)(?:\/|$))|[\\^#"<>{}`\x00-\x20\x7f-\uffff]/i;
|
|
35
|
+
var _searchNeedsNormRE = /[#"'<>\x00-\x20\x7f-\uffff]/;
|
|
36
|
+
var FastURL = /* @__PURE__ */ (() => {
|
|
37
|
+
const NativeURL = globalThis.URL;
|
|
38
|
+
const NativeSearchParams = globalThis.URLSearchParams;
|
|
39
|
+
const FastURLSearchParams = class URLSearchParams {
|
|
40
|
+
#owner;
|
|
41
|
+
#params;
|
|
42
|
+
constructor(owner) {
|
|
43
|
+
this.#owner = owner;
|
|
44
|
+
}
|
|
45
|
+
static [Symbol.hasInstance](val) {
|
|
46
|
+
return val instanceof NativeSearchParams;
|
|
47
|
+
}
|
|
48
|
+
_adopt(params) {
|
|
49
|
+
this.#params = params;
|
|
50
|
+
}
|
|
51
|
+
get _params() {
|
|
52
|
+
if (!this.#params) {
|
|
53
|
+
const search = this.#owner.search;
|
|
54
|
+
this.#params ??= new NativeSearchParams(search);
|
|
55
|
+
}
|
|
56
|
+
return this.#params;
|
|
57
|
+
}
|
|
58
|
+
#mutable() {
|
|
59
|
+
this.#owner._url;
|
|
60
|
+
return this.#params;
|
|
61
|
+
}
|
|
62
|
+
append(name, value) {
|
|
63
|
+
this.#mutable().append(name, value);
|
|
64
|
+
}
|
|
65
|
+
set(name, value) {
|
|
66
|
+
this.#mutable().set(name, value);
|
|
67
|
+
}
|
|
68
|
+
delete(name, value) {
|
|
69
|
+
this.#mutable().delete(name, value);
|
|
70
|
+
}
|
|
71
|
+
sort() {
|
|
72
|
+
this.#mutable().sort();
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
lazyInherit(FastURLSearchParams.prototype, NativeSearchParams.prototype, "_params");
|
|
76
|
+
Object.setPrototypeOf(FastURLSearchParams.prototype, NativeSearchParams.prototype);
|
|
77
|
+
Object.setPrototypeOf(FastURLSearchParams, NativeSearchParams);
|
|
78
|
+
const FastURL = class URL {
|
|
79
|
+
#url;
|
|
80
|
+
#href;
|
|
81
|
+
#protocol;
|
|
82
|
+
#host;
|
|
83
|
+
#pathname;
|
|
84
|
+
#search;
|
|
85
|
+
#searchParams;
|
|
86
|
+
#pos;
|
|
87
|
+
constructor(url) {
|
|
88
|
+
if (typeof url === "string") {
|
|
89
|
+
const isOriginForm = url[0] === "/";
|
|
90
|
+
if (isOriginForm && !_searchNeedsNormRE.test(url)) this.#href = `http://localhost${url}`;
|
|
91
|
+
else this.#url = new NativeURL(isOriginForm ? `http://localhost${url}` : url);
|
|
92
|
+
} else if (_needsNormRE.test(url.pathname) || url.search && _searchNeedsNormRE.test(url.search)) this.#url = new NativeURL(`${url.protocol || "http:"}//${url.host || "localhost"}${url.pathname}${url.search || ""}`);
|
|
93
|
+
else {
|
|
94
|
+
this.#protocol = url.protocol;
|
|
95
|
+
this.#host = url.host;
|
|
96
|
+
this.#pathname = url.pathname;
|
|
97
|
+
this.#search = url.search;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
static [Symbol.hasInstance](val) {
|
|
101
|
+
return val instanceof NativeURL;
|
|
102
|
+
}
|
|
103
|
+
get _url() {
|
|
104
|
+
if (this.#url) return this.#url;
|
|
105
|
+
this.#url = new NativeURL(this.href);
|
|
106
|
+
this.#href = void 0;
|
|
107
|
+
this.#protocol = void 0;
|
|
108
|
+
this.#host = void 0;
|
|
109
|
+
this.#pathname = void 0;
|
|
110
|
+
this.#search = void 0;
|
|
111
|
+
this.#pos = void 0;
|
|
112
|
+
this.#searchParams?._adopt(this.#url.searchParams);
|
|
113
|
+
return this.#url;
|
|
114
|
+
}
|
|
115
|
+
get href() {
|
|
116
|
+
if (this.#url) return this.#url.href;
|
|
117
|
+
if (!this.#href) this.#href = `${this.#protocol || "http:"}//${this.#host || "localhost"}${this.#pathname || "/"}${this.#search || ""}`;
|
|
118
|
+
return this.#href;
|
|
119
|
+
}
|
|
120
|
+
#getPos() {
|
|
121
|
+
if (!this.#pos) {
|
|
122
|
+
const url = this.href;
|
|
123
|
+
const protoIndex = url.indexOf("://");
|
|
124
|
+
const pathnameIndex = protoIndex === -1 ? -1 : url.indexOf("/", protoIndex + 4);
|
|
125
|
+
const qIndex = pathnameIndex === -1 ? -1 : url.indexOf("?", pathnameIndex);
|
|
126
|
+
this.#pos = [
|
|
127
|
+
protoIndex,
|
|
128
|
+
pathnameIndex,
|
|
129
|
+
qIndex
|
|
130
|
+
];
|
|
131
|
+
}
|
|
132
|
+
return this.#pos;
|
|
133
|
+
}
|
|
134
|
+
get pathname() {
|
|
135
|
+
if (this.#url) return this.#url.pathname;
|
|
136
|
+
if (this.#pathname === void 0) {
|
|
137
|
+
const [, pathnameIndex, queryIndex] = this.#getPos();
|
|
138
|
+
if (pathnameIndex === -1) return this._url.pathname;
|
|
139
|
+
this.#pathname = this.href.slice(pathnameIndex, queryIndex === -1 ? void 0 : queryIndex);
|
|
140
|
+
}
|
|
141
|
+
return this.#pathname;
|
|
142
|
+
}
|
|
143
|
+
get search() {
|
|
144
|
+
if (this.#url) return this.#url.search;
|
|
145
|
+
if (this.#search === void 0) {
|
|
146
|
+
const [, pathnameIndex, queryIndex] = this.#getPos();
|
|
147
|
+
if (pathnameIndex === -1) return this._url.search;
|
|
148
|
+
const url = this.href;
|
|
149
|
+
this.#search = queryIndex === -1 || queryIndex === url.length - 1 ? "" : url.slice(queryIndex);
|
|
150
|
+
}
|
|
151
|
+
return this.#search;
|
|
152
|
+
}
|
|
153
|
+
get searchParams() {
|
|
154
|
+
if (this.#searchParams) return this.#searchParams;
|
|
155
|
+
if (this.#url) return this.#url.searchParams;
|
|
156
|
+
return this.#searchParams = new FastURLSearchParams(this);
|
|
157
|
+
}
|
|
158
|
+
get protocol() {
|
|
159
|
+
if (this.#url) return this.#url.protocol;
|
|
160
|
+
if (this.#protocol === void 0) {
|
|
161
|
+
const [protocolIndex] = this.#getPos();
|
|
162
|
+
if (protocolIndex === -1) return this._url.protocol;
|
|
163
|
+
const url = this.href;
|
|
164
|
+
this.#protocol = url.slice(0, protocolIndex + 1);
|
|
165
|
+
}
|
|
166
|
+
return this.#protocol;
|
|
167
|
+
}
|
|
168
|
+
get hash() {
|
|
169
|
+
if (this.#url) return this.#url.hash;
|
|
170
|
+
return "";
|
|
171
|
+
}
|
|
172
|
+
toString() {
|
|
173
|
+
return this.href;
|
|
174
|
+
}
|
|
175
|
+
toJSON() {
|
|
176
|
+
return this.href;
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
lazyInherit(FastURL.prototype, NativeURL.prototype, "_url");
|
|
180
|
+
Object.setPrototypeOf(FastURL.prototype, NativeURL.prototype);
|
|
181
|
+
Object.setPrototypeOf(FastURL, NativeURL);
|
|
182
|
+
return FastURL;
|
|
183
|
+
})();
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region ../../node_modules/.pnpm/srvx@1.0.5/node_modules/srvx/dist/_chunks/_utils2.mjs
|
|
186
|
+
function resolvePortAndHost(opts) {
|
|
187
|
+
const _port = opts.port ?? globalThis.process?.env.PORT ?? 3e3;
|
|
188
|
+
const port = typeof _port === "number" ? _port : Number.parseInt(_port, 10);
|
|
189
|
+
if (Number.isNaN(port) || port < 0 || port > 65535) throw new RangeError(`Port must be a number between 0 and 65535 (got "${_port}").`);
|
|
190
|
+
return {
|
|
191
|
+
port,
|
|
192
|
+
hostname: opts.hostname ?? globalThis.process?.env.HOST
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function fmtURL(host, port, secure) {
|
|
196
|
+
if (!host || !port) return;
|
|
197
|
+
if (host.includes(":")) host = `[${host}]`;
|
|
198
|
+
return `http${secure ? "s" : ""}://${host}:${port}/`;
|
|
199
|
+
}
|
|
200
|
+
function printListening(opts, url) {
|
|
201
|
+
if (!url || (opts.silent ?? globalThis.process?.env?.TEST)) return;
|
|
202
|
+
let additionalInfo = "";
|
|
203
|
+
try {
|
|
204
|
+
const _url = new URL(url);
|
|
205
|
+
if (_url.hostname === "[::]" || _url.hostname === "0.0.0.0") {
|
|
206
|
+
_url.hostname = "localhost";
|
|
207
|
+
url = _url.href;
|
|
208
|
+
additionalInfo = " (all interfaces)";
|
|
209
|
+
}
|
|
210
|
+
} catch {}
|
|
211
|
+
let listeningOn = `➜ Listening on:`;
|
|
212
|
+
if (globalThis.process.stdout?.isTTY) {
|
|
213
|
+
listeningOn = `\u001B[32m${listeningOn}\u001B[0m`;
|
|
214
|
+
url = `\u001B[36m${url}\u001B[0m`;
|
|
215
|
+
additionalInfo = `\u001B[2m${additionalInfo}\u001B[0m`;
|
|
216
|
+
}
|
|
217
|
+
console.log(`${listeningOn} ${url}${additionalInfo}`);
|
|
218
|
+
}
|
|
219
|
+
function resolveTLSOptions(opts) {
|
|
220
|
+
if (!opts.tls || opts.protocol === "http") return;
|
|
221
|
+
const cert = resolveCertOrKey(opts.tls.cert);
|
|
222
|
+
const key = resolveCertOrKey(opts.tls.key);
|
|
223
|
+
if (!cert && !key) {
|
|
224
|
+
if (opts.protocol === "https") throw new TypeError("TLS `cert` and `key` must be provided for `https` protocol.");
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
if (!cert || !key) throw new TypeError("TLS `cert` and `key` must be provided together.");
|
|
228
|
+
return {
|
|
229
|
+
cert,
|
|
230
|
+
key,
|
|
231
|
+
passphrase: opts.tls.passphrase
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
function resolveCertOrKey(value) {
|
|
235
|
+
if (!value) return;
|
|
236
|
+
if (typeof value !== "string") throw new TypeError("TLS certificate and key must be strings in PEM format or file paths.");
|
|
237
|
+
if (value.startsWith("-----BEGIN ")) return value;
|
|
238
|
+
const { readFileSync } = process.getBuiltinModule("node:fs");
|
|
239
|
+
return readFileSync(value, "utf8");
|
|
240
|
+
}
|
|
241
|
+
function createWaitUntil() {
|
|
242
|
+
const promises = /* @__PURE__ */ new Set();
|
|
243
|
+
return {
|
|
244
|
+
waitUntil: (promise) => {
|
|
245
|
+
if (typeof promise?.then !== "function") return;
|
|
246
|
+
const chained = Promise.resolve(promise).catch(console.error).finally(() => {
|
|
247
|
+
promises.delete(chained);
|
|
248
|
+
});
|
|
249
|
+
promises.add(chained);
|
|
250
|
+
},
|
|
251
|
+
wait: () => {
|
|
252
|
+
return Promise.all(promises);
|
|
253
|
+
},
|
|
254
|
+
get _size() {
|
|
255
|
+
return promises.size;
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
//#endregion
|
|
260
|
+
//#region ../../node_modules/.pnpm/srvx@1.0.5/node_modules/srvx/dist/body-limit.mjs
|
|
261
|
+
function limitBodyStream(stream, maxRequestBodySize, options) {
|
|
262
|
+
const createError = options?.createError ?? createBodyTooLargeError;
|
|
263
|
+
const reader = stream.getReader();
|
|
264
|
+
let size = 0;
|
|
265
|
+
return new ReadableStream({
|
|
266
|
+
async pull(controller) {
|
|
267
|
+
const { done, value } = await reader.read();
|
|
268
|
+
if (done) {
|
|
269
|
+
controller.close();
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
size += value.byteLength;
|
|
273
|
+
if (size > maxRequestBodySize) {
|
|
274
|
+
const error = createError(maxRequestBodySize);
|
|
275
|
+
reader.cancel(error).catch(() => {});
|
|
276
|
+
controller.error(error);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
controller.enqueue(value);
|
|
280
|
+
},
|
|
281
|
+
cancel(reason) {
|
|
282
|
+
return reader.cancel(reason);
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
var BodyTooLargeError = class extends Error {
|
|
287
|
+
code = "ERR_BODY_TOO_LARGE";
|
|
288
|
+
statusCode = 413;
|
|
289
|
+
status = 413;
|
|
290
|
+
statusText = "Content Too Large";
|
|
291
|
+
get name() {
|
|
292
|
+
return "HTTPError";
|
|
293
|
+
}
|
|
294
|
+
toJSON() {
|
|
295
|
+
return {
|
|
296
|
+
status: this.status,
|
|
297
|
+
statusText: this.statusText,
|
|
298
|
+
message: this.message
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
function createBodyTooLargeError(maxRequestBodySize) {
|
|
303
|
+
return new BodyTooLargeError(`Request body exceeds the maximum allowed size of ${maxRequestBodySize} bytes.`);
|
|
304
|
+
}
|
|
305
|
+
//#endregion
|
|
306
|
+
//#region ../../node_modules/.pnpm/srvx@1.0.5/node_modules/srvx/dist/_chunks/_utils.mjs
|
|
307
|
+
var noColor = /* @__PURE__ */ (() => {
|
|
308
|
+
const proc = globalThis.process;
|
|
309
|
+
const env = proc?.env ?? {};
|
|
310
|
+
if (env.FORCE_COLOR) return false;
|
|
311
|
+
if (env.NO_COLOR || env.TERM === "dumb") return true;
|
|
312
|
+
return !proc?.stdout?.isTTY;
|
|
313
|
+
})();
|
|
314
|
+
var _c = (c, r = 39) => (t) => noColor ? t : `\u001B[${c}m${t}\u001B[${r}m`;
|
|
315
|
+
var bold = /* @__PURE__ */ _c(1, 22);
|
|
316
|
+
var red = /* @__PURE__ */ _c(31);
|
|
317
|
+
var green = /* @__PURE__ */ _c(32);
|
|
318
|
+
var gray = /* @__PURE__ */ _c(90);
|
|
319
|
+
//#endregion
|
|
320
|
+
//#region ../../node_modules/.pnpm/srvx@1.0.5/node_modules/srvx/dist/_chunks/_plugins.mjs
|
|
321
|
+
function wrapFetch(server) {
|
|
322
|
+
let composed = server.options.fetch;
|
|
323
|
+
const middleware = server.options.middleware;
|
|
324
|
+
if (middleware) for (let i = middleware.length - 1; i >= 0; i--) {
|
|
325
|
+
const mw = middleware[i];
|
|
326
|
+
const next = composed;
|
|
327
|
+
composed = (request) => mw(request, () => next(request));
|
|
328
|
+
}
|
|
329
|
+
return composed;
|
|
330
|
+
}
|
|
331
|
+
var errorPlugin = (server) => {
|
|
332
|
+
const errorHandler = server.options.error;
|
|
333
|
+
if (!errorHandler) return;
|
|
334
|
+
server.options.middleware.unshift((_req, next) => {
|
|
335
|
+
try {
|
|
336
|
+
const res = next();
|
|
337
|
+
return typeof res?.then === "function" ? res.then(void 0, (error) => errorHandler(error)) : res;
|
|
338
|
+
} catch (error) {
|
|
339
|
+
return errorHandler(error);
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
};
|
|
343
|
+
var gracefulShutdownPlugin = (server) => {
|
|
344
|
+
const config = server.options?.gracefulShutdown;
|
|
345
|
+
if (!globalThis.process?.on || config === false || config === void 0 && (process.env.CI || process.env.TEST)) return;
|
|
346
|
+
const gracefulTimeout = config === true || !config?.gracefulTimeout ? Number.parseInt(process.env.SERVER_SHUTDOWN_TIMEOUT || "") || 5 : config.gracefulTimeout;
|
|
347
|
+
let isClosing = false;
|
|
348
|
+
let isClosed = false;
|
|
349
|
+
const w = server.options.silent ? () => {} : process.stderr.write.bind(process.stderr);
|
|
350
|
+
const forceClose = async () => {
|
|
351
|
+
if (isClosed) return;
|
|
352
|
+
w(red("\x1B[2K\rForcibly closing connections...\n"));
|
|
353
|
+
isClosed = true;
|
|
354
|
+
await server.close(true);
|
|
355
|
+
};
|
|
356
|
+
const shutdown = async () => {
|
|
357
|
+
if (isClosing || isClosed) return;
|
|
358
|
+
setTimeout(() => {
|
|
359
|
+
globalThis.process.once("SIGINT", forceClose);
|
|
360
|
+
}, 100);
|
|
361
|
+
isClosing = true;
|
|
362
|
+
const closePromise = server.close();
|
|
363
|
+
for (let remaining = gracefulTimeout; remaining > 0; remaining--) {
|
|
364
|
+
w(gray(`\rStopping server gracefully (${remaining}s)... Press ${bold("Ctrl+C")} again to force close.`));
|
|
365
|
+
if (await Promise.race([closePromise.then(() => true), new Promise((r) => setTimeout(() => r(false), 1e3))])) {
|
|
366
|
+
w("\x1B[2K\r" + green("Server closed successfully.\n"));
|
|
367
|
+
isClosed = true;
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
w("\x1B[2K\rGraceful shutdown timed out.\n");
|
|
372
|
+
await forceClose();
|
|
373
|
+
};
|
|
374
|
+
for (const sig of ["SIGINT", "SIGTERM"]) globalThis.process.on(sig, shutdown);
|
|
375
|
+
};
|
|
376
|
+
//#endregion
|
|
377
|
+
//#region ../../node_modules/.pnpm/srvx@1.0.5/node_modules/srvx/dist/_chunks/_trust-proxy.mjs
|
|
378
|
+
function isTrustedProxy(trustProxy, remoteAddress) {
|
|
379
|
+
if (trustProxy === void 0 || trustProxy === false) return false;
|
|
380
|
+
if (trustProxy === true) return true;
|
|
381
|
+
if (trustProxy === "loopback") return isLoopbackAddress(remoteAddress);
|
|
382
|
+
if (remoteAddress === void 0) return false;
|
|
383
|
+
if (trustProxy.includes(remoteAddress)) return true;
|
|
384
|
+
const mapped = ipv4FromMapped(remoteAddress);
|
|
385
|
+
return mapped !== void 0 && trustProxy.includes(mapped);
|
|
386
|
+
}
|
|
387
|
+
function ipv4FromMapped(address) {
|
|
388
|
+
return address.startsWith("::ffff:") && address.includes(".") ? address.slice(7) : void 0;
|
|
389
|
+
}
|
|
390
|
+
function isLoopbackAddress(address) {
|
|
391
|
+
return !!address && (address === "::1" || address.startsWith("127.") || address.startsWith("::ffff:127."));
|
|
392
|
+
}
|
|
393
|
+
var HOST_RE = /^(\[(?:[A-Fa-f0-9:.]+)\]|(?:[A-Za-z0-9_-]+\.)*[A-Za-z0-9_-]+|(?:\d{1,3}\.){3}\d{1,3})(:\d{1,5})?$/;
|
|
394
|
+
function forwardedList(value) {
|
|
395
|
+
if (!value) return [];
|
|
396
|
+
const raw = Array.isArray(value) ? value.join(",") : value;
|
|
397
|
+
const out = [];
|
|
398
|
+
for (const part of raw.split(",")) {
|
|
399
|
+
const entry = part.trim();
|
|
400
|
+
if (entry) out.push(entry);
|
|
401
|
+
}
|
|
402
|
+
return out;
|
|
403
|
+
}
|
|
404
|
+
function resolveClientIP(trustProxy, peer, forwardedFor) {
|
|
405
|
+
if (!isTrustedProxy(trustProxy, peer)) return peer;
|
|
406
|
+
const list = forwardedList(forwardedFor);
|
|
407
|
+
for (let i = list.length - 1; i >= 0; i--) if (!isTrustedProxy(trustProxy, list[i])) return list[i];
|
|
408
|
+
return list.length > 0 ? list[0] : peer;
|
|
409
|
+
}
|
|
410
|
+
function trustedHops(trustProxy, peer, forwardedFor) {
|
|
411
|
+
if (!isTrustedProxy(trustProxy, peer)) return 0;
|
|
412
|
+
const list = forwardedList(forwardedFor);
|
|
413
|
+
let hops = 1;
|
|
414
|
+
for (let i = list.length - 1; i >= 0; i--) {
|
|
415
|
+
if (!isTrustedProxy(trustProxy, list[i])) return hops;
|
|
416
|
+
hops++;
|
|
417
|
+
}
|
|
418
|
+
return Number.POSITIVE_INFINITY;
|
|
419
|
+
}
|
|
420
|
+
function forwardedHopValue(value, hops) {
|
|
421
|
+
if (hops <= 0) return;
|
|
422
|
+
const list = forwardedList(value);
|
|
423
|
+
if (list.length === 0) return;
|
|
424
|
+
return list[Math.max(0, list.length - hops)];
|
|
425
|
+
}
|
|
426
|
+
//#endregion
|
|
427
|
+
//#region ../../node_modules/.pnpm/srvx@1.0.5/node_modules/srvx/dist/adapters/node.mjs
|
|
428
|
+
function sendNodeResponseDetached(nodeRes, webRes, silent) {
|
|
429
|
+
try {
|
|
430
|
+
return _sendNodeResponse(nodeRes, webRes, true);
|
|
431
|
+
} catch (error) {
|
|
432
|
+
handleSendError(nodeRes, error, silent);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
function handleSendError(nodeRes, error, silent) {
|
|
436
|
+
if (!silent) console.error("[srvx] Failed to send response:", error);
|
|
437
|
+
failResponse(nodeRes);
|
|
438
|
+
}
|
|
439
|
+
function sendErrorResponse(nodeRes, error, silent) {
|
|
440
|
+
if (!silent) console.error("[srvx] Unhandled error in fetch handler:", error);
|
|
441
|
+
failResponse(nodeRes);
|
|
442
|
+
}
|
|
443
|
+
function failResponse(nodeRes) {
|
|
444
|
+
if (nodeRes.writableEnded) return;
|
|
445
|
+
if (nodeRes.headersSent) nodeRes.destroy();
|
|
446
|
+
else {
|
|
447
|
+
nodeRes.statusCode = 500;
|
|
448
|
+
if (nodeRes.req?.httpVersion !== "2.0") nodeRes.statusMessage = "";
|
|
449
|
+
nodeRes.end();
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
function _sendNodeResponse(nodeRes, webRes, detached) {
|
|
453
|
+
if (!webRes) {
|
|
454
|
+
nodeRes.statusCode = 500;
|
|
455
|
+
return endNodeResponse(nodeRes, detached);
|
|
456
|
+
}
|
|
457
|
+
if (webRes._toNodeResponse) {
|
|
458
|
+
const res = webRes._toNodeResponse();
|
|
459
|
+
if (res.body) {
|
|
460
|
+
if (res.body instanceof ReadableStream) {
|
|
461
|
+
writeHead(nodeRes, res.status, res.statusText, res.headers);
|
|
462
|
+
return streamBody(res.body, nodeRes);
|
|
463
|
+
} else if (typeof res.body?.pipe === "function") return pipeBody(res.body, nodeRes, res.status, res.statusText, res.headers);
|
|
464
|
+
writeHead(nodeRes, res.status, res.statusText, res.headers);
|
|
465
|
+
nodeRes.write(res.body);
|
|
466
|
+
} else writeHead(nodeRes, res.status, res.statusText, res.headers);
|
|
467
|
+
return endNodeResponse(nodeRes, detached);
|
|
468
|
+
}
|
|
469
|
+
const rawHeaders = [];
|
|
470
|
+
for (const [key, value] of webRes.headers) rawHeaders.push(key, value);
|
|
471
|
+
writeHead(nodeRes, webRes.status, webRes.statusText, rawHeaders);
|
|
472
|
+
return webRes.body ? streamBody(webRes.body, nodeRes) : endNodeResponse(nodeRes, detached);
|
|
473
|
+
}
|
|
474
|
+
function writeHead(nodeRes, status, statusText, rawHeaders) {
|
|
475
|
+
if (!nodeRes.headersSent) {
|
|
476
|
+
if (nodeRes.req?.httpVersion === "2.0") nodeRes.writeHead(status, rawHeaders);
|
|
477
|
+
else nodeRes.writeHead(status, safeStatusText(statusText), rawHeaders);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
var INVALID_REASON_PHRASE_RE = /[^\t\u0020-\u007E\u0080-\u00FF]/g;
|
|
481
|
+
function safeStatusText(statusText) {
|
|
482
|
+
return typeof statusText === "string" && statusText ? statusText.replace(INVALID_REASON_PHRASE_RE, "") : statusText;
|
|
483
|
+
}
|
|
484
|
+
function endNodeResponse(nodeRes, detached) {
|
|
485
|
+
if (detached) {
|
|
486
|
+
nodeRes.end();
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
return new Promise((resolve) => nodeRes.end(resolve));
|
|
490
|
+
}
|
|
491
|
+
function pipeBody(stream, nodeRes, status, statusText, headers) {
|
|
492
|
+
if (nodeRes.destroyed) {
|
|
493
|
+
stream.destroy?.();
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
if (nodeRes.req?.method === "HEAD") {
|
|
497
|
+
if (typeof stream.destroy === "function") stream.destroy();
|
|
498
|
+
else stream.abort?.();
|
|
499
|
+
writeHead(nodeRes, status, statusText, headers);
|
|
500
|
+
return endNodeResponse(nodeRes);
|
|
501
|
+
}
|
|
502
|
+
if (typeof stream.on !== "function" || typeof stream.destroy !== "function") {
|
|
503
|
+
writeHead(nodeRes, status, statusText, headers);
|
|
504
|
+
stream.pipe(nodeRes);
|
|
505
|
+
return new Promise((resolve) => nodeRes.on("close", resolve));
|
|
506
|
+
}
|
|
507
|
+
if (stream.destroyed) {
|
|
508
|
+
writeHead(nodeRes, 500, "Internal Server Error", []);
|
|
509
|
+
return endNodeResponse(nodeRes);
|
|
510
|
+
}
|
|
511
|
+
return new Promise((resolve) => {
|
|
512
|
+
function cleanup() {
|
|
513
|
+
stream.off("error", onEarlyError);
|
|
514
|
+
stream.off("readable", onReadable);
|
|
515
|
+
nodeRes.off("close", onResClose);
|
|
516
|
+
}
|
|
517
|
+
function onEarlyError() {
|
|
518
|
+
cleanup();
|
|
519
|
+
stream.destroy();
|
|
520
|
+
writeHead(nodeRes, 500, "Internal Server Error", []);
|
|
521
|
+
endNodeResponse(nodeRes).then(resolve);
|
|
522
|
+
}
|
|
523
|
+
function onReadable() {
|
|
524
|
+
cleanup();
|
|
525
|
+
if (nodeRes.destroyed) {
|
|
526
|
+
stream.destroy();
|
|
527
|
+
return resolve();
|
|
528
|
+
}
|
|
529
|
+
writeHead(nodeRes, status, statusText, headers);
|
|
530
|
+
pipeline(stream, nodeRes).catch(() => {}).then(() => resolve());
|
|
531
|
+
}
|
|
532
|
+
function onResClose() {
|
|
533
|
+
cleanup();
|
|
534
|
+
stream.destroy();
|
|
535
|
+
resolve();
|
|
536
|
+
}
|
|
537
|
+
stream.once("error", onEarlyError);
|
|
538
|
+
stream.once("readable", onReadable);
|
|
539
|
+
nodeRes.once("close", onResClose);
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
function streamBody(stream, nodeRes) {
|
|
543
|
+
if (nodeRes.destroyed) {
|
|
544
|
+
stream.cancel().catch(() => {});
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
if (nodeRes.req?.method === "HEAD") {
|
|
548
|
+
stream.cancel().catch(() => {});
|
|
549
|
+
return endNodeResponse(nodeRes);
|
|
550
|
+
}
|
|
551
|
+
const reader = stream.getReader();
|
|
552
|
+
function streamCancel(error) {
|
|
553
|
+
reader.cancel(error).catch(() => {});
|
|
554
|
+
if (error) nodeRes.destroy(error);
|
|
555
|
+
}
|
|
556
|
+
function streamHandle({ done, value }) {
|
|
557
|
+
try {
|
|
558
|
+
if (done) nodeRes.end();
|
|
559
|
+
else if (nodeRes.write(value)) reader.read().then(streamHandle, streamCancel);
|
|
560
|
+
else nodeRes.once("drain", () => reader.read().then(streamHandle, streamCancel));
|
|
561
|
+
} catch (error) {
|
|
562
|
+
streamCancel(error instanceof Error ? error : void 0);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
nodeRes.on("close", streamCancel);
|
|
566
|
+
nodeRes.on("error", streamCancel);
|
|
567
|
+
reader.read().then(streamHandle, streamCancel);
|
|
568
|
+
return reader.closed.catch(streamCancel).finally(() => {
|
|
569
|
+
nodeRes.off("close", streamCancel);
|
|
570
|
+
nodeRes.off("error", streamCancel);
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
var NodeRequestURL = class extends FastURL {
|
|
574
|
+
constructor({ req, hops = 0 }) {
|
|
575
|
+
const path = req.url || "/";
|
|
576
|
+
const trusted = hops > 0;
|
|
577
|
+
const forwardedHost = forwardedHopValue(req.headers["x-forwarded-host"], hops);
|
|
578
|
+
let host = (forwardedHost && HOST_RE.test(forwardedHost) ? forwardedHost : void 0) || req.headers.host || req.headers[":authority"];
|
|
579
|
+
if (host && !HOST_RE.test(host)) host = "_invalid_";
|
|
580
|
+
else if (!host) {
|
|
581
|
+
if (req.socket) host = `${req.socket.localFamily === "IPv6" ? "[" + req.socket.localAddress + "]" : req.socket.localAddress}:${req.socket?.localPort || "80"}`;
|
|
582
|
+
else host = "localhost";
|
|
583
|
+
}
|
|
584
|
+
const forwardedProto = forwardedHopValue(req.headers["x-forwarded-proto"], hops);
|
|
585
|
+
const protocol = req.socket?.encrypted || forwardedProto === "https" || trusted && req.headers[":scheme"] === "https" ? "https:" : "http:";
|
|
586
|
+
if (path[0] === "/") {
|
|
587
|
+
const qIndex = path.indexOf("?");
|
|
588
|
+
super({
|
|
589
|
+
protocol,
|
|
590
|
+
host,
|
|
591
|
+
pathname: qIndex === -1 ? path : path.slice(0, qIndex) || "/",
|
|
592
|
+
search: qIndex === -1 ? "" : path.slice(qIndex) || ""
|
|
593
|
+
});
|
|
594
|
+
} else if (path === "*") super({
|
|
595
|
+
protocol,
|
|
596
|
+
host,
|
|
597
|
+
pathname: "/*",
|
|
598
|
+
search: ""
|
|
599
|
+
});
|
|
600
|
+
else {
|
|
601
|
+
const target = URL.canParse(path) ? new URL(path) : void 0;
|
|
602
|
+
if (target) {
|
|
603
|
+
const targetHost = target.host;
|
|
604
|
+
const targetPath = target.pathname;
|
|
605
|
+
super({
|
|
606
|
+
protocol,
|
|
607
|
+
host: targetHost ? HOST_RE.test(targetHost) ? targetHost : "_invalid_" : host,
|
|
608
|
+
pathname: targetPath ? targetPath[0] === "/" ? targetPath : `/${targetPath}` : "/",
|
|
609
|
+
search: target.search
|
|
610
|
+
});
|
|
611
|
+
} else super({
|
|
612
|
+
protocol,
|
|
613
|
+
host,
|
|
614
|
+
pathname: "/",
|
|
615
|
+
search: ""
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
};
|
|
620
|
+
function isValidAbsoluteForm(target) {
|
|
621
|
+
if (!URL.canParse(target)) return false;
|
|
622
|
+
const url = new URL(target);
|
|
623
|
+
return (url.protocol === "http:" || url.protocol === "https:") && url.host !== "";
|
|
624
|
+
}
|
|
625
|
+
var _nonJoinedHeaders = /* @__PURE__ */ new Set([
|
|
626
|
+
"age",
|
|
627
|
+
"authorization",
|
|
628
|
+
"content-length",
|
|
629
|
+
"content-type",
|
|
630
|
+
"etag",
|
|
631
|
+
"expires",
|
|
632
|
+
"from",
|
|
633
|
+
"host",
|
|
634
|
+
"if-modified-since",
|
|
635
|
+
"if-unmodified-since",
|
|
636
|
+
"last-modified",
|
|
637
|
+
"location",
|
|
638
|
+
"max-forwards",
|
|
639
|
+
"proxy-authorization",
|
|
640
|
+
"referer",
|
|
641
|
+
"retry-after",
|
|
642
|
+
"server",
|
|
643
|
+
"user-agent"
|
|
644
|
+
]);
|
|
645
|
+
var _validHeaderNameRE = /^[!#$%&'*+\-.^_`|~\dA-Za-z]+$/;
|
|
646
|
+
function _isRepeated(rawHeaders, lowerName) {
|
|
647
|
+
let seen = false;
|
|
648
|
+
for (let i = 0; i < rawHeaders.length; i += 2) {
|
|
649
|
+
const key = rawHeaders[i];
|
|
650
|
+
if (key.length === lowerName.length && key.toLowerCase() === lowerName) {
|
|
651
|
+
if (seen) return true;
|
|
652
|
+
seen = true;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
return false;
|
|
656
|
+
}
|
|
657
|
+
var NodeRequestHeaders = /* @__PURE__ */ (() => {
|
|
658
|
+
const NativeHeaders = globalThis.Headers;
|
|
659
|
+
class Headers {
|
|
660
|
+
#req;
|
|
661
|
+
#headers;
|
|
662
|
+
constructor(req) {
|
|
663
|
+
this.#req = req;
|
|
664
|
+
}
|
|
665
|
+
static [Symbol.hasInstance](val) {
|
|
666
|
+
return val instanceof NativeHeaders;
|
|
667
|
+
}
|
|
668
|
+
_adopt(headers) {
|
|
669
|
+
this.#headers = headers;
|
|
670
|
+
}
|
|
671
|
+
get _headers() {
|
|
672
|
+
if (!this.#headers) {
|
|
673
|
+
const headers = new NativeHeaders();
|
|
674
|
+
const rawHeaders = this.#req.rawHeaders;
|
|
675
|
+
const len = rawHeaders.length;
|
|
676
|
+
for (let i = 0; i < len; i += 2) {
|
|
677
|
+
const key = rawHeaders[i];
|
|
678
|
+
if (key.charCodeAt(0) === 58) continue;
|
|
679
|
+
const value = rawHeaders[i + 1];
|
|
680
|
+
headers.append(key, value);
|
|
681
|
+
}
|
|
682
|
+
this.#headers = headers;
|
|
683
|
+
}
|
|
684
|
+
return this.#headers;
|
|
685
|
+
}
|
|
686
|
+
get(name) {
|
|
687
|
+
if (this.#headers) return this.#headers.get(name);
|
|
688
|
+
const lower = name.toLowerCase();
|
|
689
|
+
if (lower.charCodeAt(0) === 58) return this._headers.get(name);
|
|
690
|
+
const value = this.#req.headers[lower];
|
|
691
|
+
if (typeof value === "string") return _nonJoinedHeaders.has(lower) && _isRepeated(this.#req.rawHeaders, lower) ? this._headers.get(name) : value;
|
|
692
|
+
if (Array.isArray(value)) return value.join(", ");
|
|
693
|
+
return lower !== "__proto__" && _validHeaderNameRE.test(name) ? null : this._headers.get(name);
|
|
694
|
+
}
|
|
695
|
+
has(name) {
|
|
696
|
+
if (this.#headers) return this.#headers.has(name);
|
|
697
|
+
const lower = name.toLowerCase();
|
|
698
|
+
if (lower.charCodeAt(0) === 58) return this._headers.has(name);
|
|
699
|
+
if (Object.hasOwn(this.#req.headers, lower)) return true;
|
|
700
|
+
return lower !== "__proto__" && _validHeaderNameRE.test(name) ? false : this._headers.has(name);
|
|
701
|
+
}
|
|
702
|
+
getSetCookie() {
|
|
703
|
+
if (this.#headers) return this.#headers.getSetCookie();
|
|
704
|
+
const value = this.#req.headers["set-cookie"];
|
|
705
|
+
return Array.isArray(value) ? value.slice() : value ? [value] : [];
|
|
706
|
+
}
|
|
707
|
+
entries() {
|
|
708
|
+
return this._headers.entries();
|
|
709
|
+
}
|
|
710
|
+
[Symbol.iterator]() {
|
|
711
|
+
return this.entries();
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
lazyInherit(Headers.prototype, NativeHeaders.prototype, "_headers");
|
|
715
|
+
Object.setPrototypeOf(Headers, NativeHeaders);
|
|
716
|
+
Object.setPrototypeOf(Headers.prototype, NativeHeaders.prototype);
|
|
717
|
+
return Headers;
|
|
718
|
+
})();
|
|
719
|
+
var kNativeRequest = /* @__PURE__ */ Symbol.for("srvx.nativeRequest");
|
|
720
|
+
function bodyUnusable() {
|
|
721
|
+
return /* @__PURE__ */ new TypeError("Body is unusable: Body has already been read");
|
|
722
|
+
}
|
|
723
|
+
function abortError() {
|
|
724
|
+
return new DOMException("The request was aborted.", "AbortError");
|
|
725
|
+
}
|
|
726
|
+
function erroredStream(error) {
|
|
727
|
+
return new ReadableStream({ start(controller) {
|
|
728
|
+
controller.error(error);
|
|
729
|
+
} });
|
|
730
|
+
}
|
|
731
|
+
function isClientGone(req) {
|
|
732
|
+
return req.aborted || !!req.errored || req.destroyed && !req.complete;
|
|
733
|
+
}
|
|
734
|
+
function isBodySourceFinished(req) {
|
|
735
|
+
return isClientGone(req) || req.destroyed || req.readableEnded;
|
|
736
|
+
}
|
|
737
|
+
var NodeRequest = /* @__PURE__ */ (() => {
|
|
738
|
+
const NativeRequest = getNativeRequest();
|
|
739
|
+
class Request {
|
|
740
|
+
runtime;
|
|
741
|
+
waitUntil;
|
|
742
|
+
#req;
|
|
743
|
+
#url;
|
|
744
|
+
#bodyStream;
|
|
745
|
+
#bodyUsed = false;
|
|
746
|
+
#request;
|
|
747
|
+
#headers;
|
|
748
|
+
#abortController;
|
|
749
|
+
#maxRequestBodySize;
|
|
750
|
+
#trustProxy;
|
|
751
|
+
#ip;
|
|
752
|
+
#ipResolved = false;
|
|
753
|
+
#remoteAddress;
|
|
754
|
+
#remoteResolved = false;
|
|
755
|
+
#hops;
|
|
756
|
+
constructor(ctx) {
|
|
757
|
+
this.#req = ctx.req;
|
|
758
|
+
this.#maxRequestBodySize = ctx.maxRequestBodySize;
|
|
759
|
+
this.#trustProxy = ctx.trustProxy;
|
|
760
|
+
this.runtime = {
|
|
761
|
+
name: "node",
|
|
762
|
+
node: ctx
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
static [Symbol.hasInstance](val) {
|
|
766
|
+
return val instanceof NativeRequest;
|
|
767
|
+
}
|
|
768
|
+
#remoteAddr() {
|
|
769
|
+
if (!this.#remoteResolved) {
|
|
770
|
+
this.#remoteResolved = true;
|
|
771
|
+
this.#remoteAddress = this.#req.socket?.remoteAddress;
|
|
772
|
+
}
|
|
773
|
+
return this.#remoteAddress;
|
|
774
|
+
}
|
|
775
|
+
#resolveHops() {
|
|
776
|
+
if (this.#hops === void 0) this.#hops = trustedHops(this.#trustProxy, this.#remoteAddr(), this.#req.headers["x-forwarded-for"]);
|
|
777
|
+
return this.#hops;
|
|
778
|
+
}
|
|
779
|
+
get ip() {
|
|
780
|
+
if (this.#ipResolved) return this.#ip;
|
|
781
|
+
this.#ipResolved = true;
|
|
782
|
+
return this.#ip = resolveClientIP(this.#trustProxy, this.#remoteAddr(), this.#req.headers["x-forwarded-for"]);
|
|
783
|
+
}
|
|
784
|
+
get method() {
|
|
785
|
+
if (this.#request) return this.#request.method;
|
|
786
|
+
return this.#req.method || "GET";
|
|
787
|
+
}
|
|
788
|
+
get _url() {
|
|
789
|
+
return this.#url ||= new NodeRequestURL({
|
|
790
|
+
req: this.#req,
|
|
791
|
+
hops: this.#resolveHops()
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
set _url(url) {
|
|
795
|
+
this.#url = url;
|
|
796
|
+
}
|
|
797
|
+
get url() {
|
|
798
|
+
if (this.#request) return this.#request.url;
|
|
799
|
+
return this._url.href;
|
|
800
|
+
}
|
|
801
|
+
get headers() {
|
|
802
|
+
return this.#headers ||= new NodeRequestHeaders(this.#req);
|
|
803
|
+
}
|
|
804
|
+
get _abortController() {
|
|
805
|
+
if (!this.#abortController) {
|
|
806
|
+
this.#abortController = new AbortController();
|
|
807
|
+
const { req, res } = this.runtime.node;
|
|
808
|
+
const abortController = this.#abortController;
|
|
809
|
+
const abort = (err) => abortController.abort?.(err);
|
|
810
|
+
if (res) {
|
|
811
|
+
const onClose = () => {
|
|
812
|
+
const reqError = req.errored;
|
|
813
|
+
if (reqError) abort(reqError);
|
|
814
|
+
else if (!res.writableEnded) abort();
|
|
815
|
+
};
|
|
816
|
+
res.once("close", onClose);
|
|
817
|
+
if (res.destroyed || isClientGone(req)) onClose();
|
|
818
|
+
} else {
|
|
819
|
+
const onClose = () => {
|
|
820
|
+
if (!req.complete || req.aborted) abort();
|
|
821
|
+
};
|
|
822
|
+
req.once("close", onClose);
|
|
823
|
+
if (isClientGone(req)) onClose();
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
return this.#abortController;
|
|
827
|
+
}
|
|
828
|
+
get signal() {
|
|
829
|
+
return this.#request ? this.#request.signal : this._abortController.signal;
|
|
830
|
+
}
|
|
831
|
+
#hasBody() {
|
|
832
|
+
const method = this.method;
|
|
833
|
+
return method !== "GET" && method !== "HEAD";
|
|
834
|
+
}
|
|
835
|
+
get body() {
|
|
836
|
+
if (this.#request) return this.#request.body;
|
|
837
|
+
if (this.#bodyStream === void 0) {
|
|
838
|
+
let stream = null;
|
|
839
|
+
if (this.#hasBody() && !this.#bodyUsed) {
|
|
840
|
+
if (isBodySourceFinished(this.#req)) stream = erroredStream(this.#bodyError());
|
|
841
|
+
else stream = Readable.toWeb(this.#req);
|
|
842
|
+
}
|
|
843
|
+
if (stream && this.#maxRequestBodySize !== void 0) stream = limitBodyStream(stream, this.#maxRequestBodySize);
|
|
844
|
+
this.#bodyStream = stream;
|
|
845
|
+
}
|
|
846
|
+
return this.#bodyStream;
|
|
847
|
+
}
|
|
848
|
+
get bodyUsed() {
|
|
849
|
+
if (this.#isBodyUsed()) return true;
|
|
850
|
+
return this.#request ? this.#request.bodyUsed : false;
|
|
851
|
+
}
|
|
852
|
+
#isBodyUsed() {
|
|
853
|
+
if (!this.#bodyUsed && this.#bodyStream && Readable.isDisturbed(this.#bodyStream)) this.#bodyUsed = true;
|
|
854
|
+
return this.#bodyUsed;
|
|
855
|
+
}
|
|
856
|
+
#bodyError() {
|
|
857
|
+
const signal = this._abortController.signal;
|
|
858
|
+
if (signal.aborted) return signal.reason;
|
|
859
|
+
return this.#req.errored || (isClientGone(this.#req) ? abortError() : bodyUnusable());
|
|
860
|
+
}
|
|
861
|
+
#readBuffered() {
|
|
862
|
+
if ("rawBody" in this.#req && Buffer.isBuffer(this.#req.rawBody)) return readBody(this.#req, this.#maxRequestBodySize);
|
|
863
|
+
if (isBodySourceFinished(this.#req)) return Promise.reject(this.#bodyError());
|
|
864
|
+
return readBody(this.#req, this.#maxRequestBodySize);
|
|
865
|
+
}
|
|
866
|
+
text() {
|
|
867
|
+
if (this.#isBodyUsed()) return Promise.reject(bodyUnusable());
|
|
868
|
+
if (this.#request) return this.#request.text();
|
|
869
|
+
if (!this.#hasBody()) return Promise.resolve("");
|
|
870
|
+
this.#bodyUsed = true;
|
|
871
|
+
if (this.#bodyStream !== void 0) try {
|
|
872
|
+
return new Response(this.#bodyStream).text();
|
|
873
|
+
} catch (error) {
|
|
874
|
+
return Promise.reject(error);
|
|
875
|
+
}
|
|
876
|
+
return this.#readBuffered().then((buf) => buf.toString());
|
|
877
|
+
}
|
|
878
|
+
json() {
|
|
879
|
+
if (this.#isBodyUsed()) return Promise.reject(bodyUnusable());
|
|
880
|
+
if (this.#request) return this.#request.json();
|
|
881
|
+
if (!this.#hasBody()) return Promise.resolve().then(() => JSON.parse(""));
|
|
882
|
+
this.#bodyUsed = true;
|
|
883
|
+
if (this.#bodyStream !== void 0) try {
|
|
884
|
+
return new Response(this.#bodyStream).json();
|
|
885
|
+
} catch (error) {
|
|
886
|
+
return Promise.reject(error);
|
|
887
|
+
}
|
|
888
|
+
return this.#readBuffered().then((buf) => JSON.parse(buf.toString()));
|
|
889
|
+
}
|
|
890
|
+
arrayBuffer() {
|
|
891
|
+
return this.#consumeNative("arrayBuffer");
|
|
892
|
+
}
|
|
893
|
+
bytes() {
|
|
894
|
+
return this.#consumeNative("bytes");
|
|
895
|
+
}
|
|
896
|
+
blob() {
|
|
897
|
+
return this.#consumeNative("blob");
|
|
898
|
+
}
|
|
899
|
+
formData() {
|
|
900
|
+
return this.#consumeNative("formData");
|
|
901
|
+
}
|
|
902
|
+
#consumeNative(method) {
|
|
903
|
+
if (this.#isBodyUsed()) return Promise.reject(bodyUnusable());
|
|
904
|
+
try {
|
|
905
|
+
return this._request[method]();
|
|
906
|
+
} catch (error) {
|
|
907
|
+
return Promise.reject(error);
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
get _request() {
|
|
911
|
+
if (!this.#request) {
|
|
912
|
+
const body = this.#isBodyUsed() ? null : this.body;
|
|
913
|
+
this.#request = new NativeRequest(this.url, {
|
|
914
|
+
method: this.method,
|
|
915
|
+
headers: this.headers,
|
|
916
|
+
signal: this._abortController.signal,
|
|
917
|
+
body,
|
|
918
|
+
duplex: body ? "half" : void 0
|
|
919
|
+
});
|
|
920
|
+
this.#headers._adopt(this.#request.headers);
|
|
921
|
+
this.#bodyStream = void 0;
|
|
922
|
+
}
|
|
923
|
+
return this.#request;
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
lazyInherit(Request.prototype, NativeRequest.prototype, "_request");
|
|
927
|
+
Object.setPrototypeOf(Request.prototype, NativeRequest.prototype);
|
|
928
|
+
return Request;
|
|
929
|
+
})();
|
|
930
|
+
function readBody(req, maxRequestBodySize) {
|
|
931
|
+
if ("rawBody" in req && Buffer.isBuffer(req.rawBody)) {
|
|
932
|
+
if (maxRequestBodySize !== void 0 && req.rawBody.length > maxRequestBodySize) return Promise.reject(createBodyTooLargeError(maxRequestBodySize));
|
|
933
|
+
return Promise.resolve(req.rawBody);
|
|
934
|
+
}
|
|
935
|
+
return new Promise((resolve, reject) => {
|
|
936
|
+
const chunks = [];
|
|
937
|
+
let size = 0;
|
|
938
|
+
const cleanup = () => {
|
|
939
|
+
req.off("data", onData);
|
|
940
|
+
req.off("end", onEnd);
|
|
941
|
+
req.off("error", onError);
|
|
942
|
+
req.off("close", onClose);
|
|
943
|
+
};
|
|
944
|
+
const onData = (chunk) => {
|
|
945
|
+
if (maxRequestBodySize !== void 0) {
|
|
946
|
+
size += chunk.length;
|
|
947
|
+
if (size > maxRequestBodySize) {
|
|
948
|
+
cleanup();
|
|
949
|
+
req.pause?.();
|
|
950
|
+
reject(createBodyTooLargeError(maxRequestBodySize));
|
|
951
|
+
return;
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
chunks.push(chunk);
|
|
955
|
+
};
|
|
956
|
+
const onError = (err) => {
|
|
957
|
+
cleanup();
|
|
958
|
+
reject(err);
|
|
959
|
+
};
|
|
960
|
+
const onEnd = () => {
|
|
961
|
+
cleanup();
|
|
962
|
+
if (isClientGone(req)) {
|
|
963
|
+
reject(req.errored || abortError());
|
|
964
|
+
return;
|
|
965
|
+
}
|
|
966
|
+
resolve(chunks.length === 1 ? chunks[0] : Buffer.concat(chunks));
|
|
967
|
+
};
|
|
968
|
+
const onClose = () => {
|
|
969
|
+
cleanup();
|
|
970
|
+
reject(req.errored || abortError());
|
|
971
|
+
};
|
|
972
|
+
req.on("data", onData).once("end", onEnd).once("error", onError).once("close", onClose);
|
|
973
|
+
});
|
|
974
|
+
}
|
|
975
|
+
function getNativeRequest() {
|
|
976
|
+
let R = globalThis[kNativeRequest] || globalThis.Request;
|
|
977
|
+
while (R?._srvx) R = Object.getPrototypeOf(R);
|
|
978
|
+
return globalThis[kNativeRequest] ??= R;
|
|
979
|
+
}
|
|
980
|
+
var NodeResponse = /* @__PURE__ */ (() => {
|
|
981
|
+
const NativeResponse = globalThis.Response;
|
|
982
|
+
class NodeResponse {
|
|
983
|
+
#body;
|
|
984
|
+
#init;
|
|
985
|
+
#headers;
|
|
986
|
+
#response;
|
|
987
|
+
constructor(body, init) {
|
|
988
|
+
this.#body = body;
|
|
989
|
+
this.#init = init;
|
|
990
|
+
}
|
|
991
|
+
static [Symbol.hasInstance](val) {
|
|
992
|
+
return val instanceof NativeResponse;
|
|
993
|
+
}
|
|
994
|
+
static json(data, init) {
|
|
995
|
+
const body = JSON.stringify(data);
|
|
996
|
+
if (body === void 0) throw new TypeError("Value is not JSON serializable");
|
|
997
|
+
let headers = init?.headers;
|
|
998
|
+
if (!headers) headers = { "content-type": "application/json" };
|
|
999
|
+
else {
|
|
1000
|
+
const merged = new Headers(headers);
|
|
1001
|
+
if (!merged.has("content-type")) merged.set("content-type", "application/json");
|
|
1002
|
+
headers = merged;
|
|
1003
|
+
}
|
|
1004
|
+
return new NodeResponse(body, init ? {
|
|
1005
|
+
...init,
|
|
1006
|
+
headers
|
|
1007
|
+
} : { headers });
|
|
1008
|
+
}
|
|
1009
|
+
get status() {
|
|
1010
|
+
return this.#response?.status || this.#init?.status || 200;
|
|
1011
|
+
}
|
|
1012
|
+
get statusText() {
|
|
1013
|
+
return this.#response?.statusText || this.#init?.statusText || "";
|
|
1014
|
+
}
|
|
1015
|
+
get headers() {
|
|
1016
|
+
if (this.#response) return this.#response.headers;
|
|
1017
|
+
if (this.#headers) return this.#headers;
|
|
1018
|
+
return this.#headers = new Headers(this.#init?.headers);
|
|
1019
|
+
}
|
|
1020
|
+
get ok() {
|
|
1021
|
+
if (this.#response) return this.#response.ok;
|
|
1022
|
+
const status = this.status;
|
|
1023
|
+
return status >= 200 && status < 300;
|
|
1024
|
+
}
|
|
1025
|
+
get _response() {
|
|
1026
|
+
if (this.#response) return this.#response;
|
|
1027
|
+
let body = this.#body;
|
|
1028
|
+
if (body && typeof body.pipe === "function" && !(body instanceof Readable)) {
|
|
1029
|
+
const stream = new PassThrough();
|
|
1030
|
+
body.pipe(stream);
|
|
1031
|
+
const abort = body.abort;
|
|
1032
|
+
if (abort) stream.once("close", () => abort());
|
|
1033
|
+
body = stream;
|
|
1034
|
+
}
|
|
1035
|
+
this.#response = new NativeResponse(body, this.#headers ? {
|
|
1036
|
+
...this.#init,
|
|
1037
|
+
headers: this.#headers
|
|
1038
|
+
} : this.#init);
|
|
1039
|
+
this.#init = void 0;
|
|
1040
|
+
this.#headers = void 0;
|
|
1041
|
+
this.#body = void 0;
|
|
1042
|
+
return this.#response;
|
|
1043
|
+
}
|
|
1044
|
+
_toNodeResponse() {
|
|
1045
|
+
const status = this.status;
|
|
1046
|
+
const statusText = this.statusText;
|
|
1047
|
+
let body;
|
|
1048
|
+
let contentType;
|
|
1049
|
+
let contentLength;
|
|
1050
|
+
if (this.#response) body = this.#response.body;
|
|
1051
|
+
else if (this.#body != null) {
|
|
1052
|
+
if (this.#body instanceof ReadableStream) body = this.#body;
|
|
1053
|
+
else if (typeof this.#body === "string") {
|
|
1054
|
+
body = this.#body;
|
|
1055
|
+
contentType = "text/plain; charset=UTF-8";
|
|
1056
|
+
contentLength = Buffer.byteLength(this.#body);
|
|
1057
|
+
} else if (this.#body instanceof ArrayBuffer) {
|
|
1058
|
+
body = Buffer.from(this.#body);
|
|
1059
|
+
contentLength = this.#body.byteLength;
|
|
1060
|
+
} else if (this.#body instanceof Uint8Array) {
|
|
1061
|
+
body = this.#body;
|
|
1062
|
+
contentLength = this.#body.byteLength;
|
|
1063
|
+
} else if (this.#body instanceof DataView) {
|
|
1064
|
+
body = Buffer.from(this.#body.buffer, this.#body.byteOffset, this.#body.byteLength);
|
|
1065
|
+
contentLength = this.#body.byteLength;
|
|
1066
|
+
} else if (this.#body instanceof Blob) {
|
|
1067
|
+
body = this.#body.stream();
|
|
1068
|
+
contentType = this.#body.type;
|
|
1069
|
+
contentLength = this.#body.size;
|
|
1070
|
+
} else if (typeof this.#body.pipe === "function") body = this.#body;
|
|
1071
|
+
else body = this._response.body;
|
|
1072
|
+
}
|
|
1073
|
+
const headers = [];
|
|
1074
|
+
const initHeaders = this.#init?.headers;
|
|
1075
|
+
const headerEntries = this.#response?.headers || this.#headers || (initHeaders ? Array.isArray(initHeaders) ? initHeaders : initHeaders?.entries ? initHeaders.entries() : Object.entries(initHeaders) : void 0);
|
|
1076
|
+
let hasContentTypeHeader;
|
|
1077
|
+
let hasContentLength;
|
|
1078
|
+
if (headerEntries) for (const [key, value] of headerEntries) {
|
|
1079
|
+
const lowerKey = typeof key === "string" ? key.toLowerCase() : String(key);
|
|
1080
|
+
if (Array.isArray(value)) for (const v of value) headers.push(lowerKey, v);
|
|
1081
|
+
else headers.push(lowerKey, value);
|
|
1082
|
+
if (lowerKey === "content-type") hasContentTypeHeader = true;
|
|
1083
|
+
else if (lowerKey === "content-length") hasContentLength = true;
|
|
1084
|
+
}
|
|
1085
|
+
if (contentType && !hasContentTypeHeader) headers.push("content-type", contentType);
|
|
1086
|
+
if (contentLength != null && !hasContentLength) headers.push("content-length", String(contentLength));
|
|
1087
|
+
this.#init = void 0;
|
|
1088
|
+
this.#headers = void 0;
|
|
1089
|
+
this.#response = void 0;
|
|
1090
|
+
this.#body = void 0;
|
|
1091
|
+
return {
|
|
1092
|
+
status,
|
|
1093
|
+
statusText,
|
|
1094
|
+
headers,
|
|
1095
|
+
body
|
|
1096
|
+
};
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
lazyInherit(NodeResponse.prototype, NativeResponse.prototype, "_response");
|
|
1100
|
+
Object.setPrototypeOf(NodeResponse, NativeResponse);
|
|
1101
|
+
Object.setPrototypeOf(NodeResponse.prototype, NativeResponse.prototype);
|
|
1102
|
+
return NodeResponse;
|
|
1103
|
+
})();
|
|
1104
|
+
function serve(options) {
|
|
1105
|
+
return new NodeServer(options);
|
|
1106
|
+
}
|
|
1107
|
+
var NodeServer = class {
|
|
1108
|
+
runtime = "node";
|
|
1109
|
+
options;
|
|
1110
|
+
node;
|
|
1111
|
+
serveOptions;
|
|
1112
|
+
fetch;
|
|
1113
|
+
waitUntil;
|
|
1114
|
+
#isSecure;
|
|
1115
|
+
#listeningPromise;
|
|
1116
|
+
#listenError;
|
|
1117
|
+
#listenErrorObserved;
|
|
1118
|
+
#wait;
|
|
1119
|
+
constructor(options) {
|
|
1120
|
+
this.options = {
|
|
1121
|
+
...options,
|
|
1122
|
+
middleware: [...options.middleware || []]
|
|
1123
|
+
};
|
|
1124
|
+
for (const plugin of options.plugins || []) plugin(this);
|
|
1125
|
+
errorPlugin(this);
|
|
1126
|
+
const fetchHandler = this.fetch = wrapFetch(this);
|
|
1127
|
+
const handler = (nodeReq, nodeRes) => {
|
|
1128
|
+
const reqUrl = nodeReq.url;
|
|
1129
|
+
if (reqUrl && reqUrl[0] !== "/" && reqUrl !== "*" && !isValidAbsoluteForm(reqUrl)) {
|
|
1130
|
+
nodeRes.statusCode = 400;
|
|
1131
|
+
nodeRes.end();
|
|
1132
|
+
return;
|
|
1133
|
+
}
|
|
1134
|
+
const request = new NodeRequest({
|
|
1135
|
+
req: nodeReq,
|
|
1136
|
+
res: nodeRes,
|
|
1137
|
+
maxRequestBodySize: this.options.maxRequestBodySize,
|
|
1138
|
+
trustProxy: this.options.trustProxy
|
|
1139
|
+
});
|
|
1140
|
+
request.waitUntil = this.#wait?.waitUntil;
|
|
1141
|
+
let res;
|
|
1142
|
+
try {
|
|
1143
|
+
res = fetchHandler(request);
|
|
1144
|
+
} catch (error) {
|
|
1145
|
+
return sendErrorResponse(nodeRes, error, this.options.silent);
|
|
1146
|
+
}
|
|
1147
|
+
return typeof res?.then === "function" ? res.then((resolvedRes) => sendNodeResponseDetached(nodeRes, resolvedRes, this.options.silent), (error) => sendErrorResponse(nodeRes, error, this.options.silent)) : sendNodeResponseDetached(nodeRes, res, this.options.silent);
|
|
1148
|
+
};
|
|
1149
|
+
this.node = {
|
|
1150
|
+
handler,
|
|
1151
|
+
server: void 0
|
|
1152
|
+
};
|
|
1153
|
+
const loader = globalThis.__srvxLoader__;
|
|
1154
|
+
if (loader) {
|
|
1155
|
+
loader({ server: this });
|
|
1156
|
+
return;
|
|
1157
|
+
}
|
|
1158
|
+
gracefulShutdownPlugin(this);
|
|
1159
|
+
this.#wait = createWaitUntil();
|
|
1160
|
+
this.waitUntil = this.#wait.waitUntil;
|
|
1161
|
+
const tls = resolveTLSOptions(this.options);
|
|
1162
|
+
const { port, hostname: host } = resolvePortAndHost(this.options);
|
|
1163
|
+
this.serveOptions = {
|
|
1164
|
+
port,
|
|
1165
|
+
host,
|
|
1166
|
+
exclusive: !this.options.reusePort,
|
|
1167
|
+
reusePort: this.options.reusePort,
|
|
1168
|
+
...tls,
|
|
1169
|
+
...this.options.node
|
|
1170
|
+
};
|
|
1171
|
+
let server;
|
|
1172
|
+
this.#isSecure = !!this.serveOptions.cert && this.options.protocol !== "http";
|
|
1173
|
+
if (this.options.node?.http2 ?? this.#isSecure) {
|
|
1174
|
+
if (this.#isSecure) server = nodeHTTP2.createSecureServer({
|
|
1175
|
+
allowHTTP1: true,
|
|
1176
|
+
...this.serveOptions
|
|
1177
|
+
}, handler);
|
|
1178
|
+
else throw new Error("node.http2 option requires tls certificate!");
|
|
1179
|
+
} else if (this.#isSecure) server = nodeHTTPS.createServer(this.serveOptions, handler);
|
|
1180
|
+
else server = nodeHTTP.createServer(this.serveOptions, handler);
|
|
1181
|
+
this.node.server = server;
|
|
1182
|
+
if (!options.manual) this.serve().catch((error) => this.#reportUnobservedListenError(error));
|
|
1183
|
+
}
|
|
1184
|
+
#reportUnobservedListenError(error) {
|
|
1185
|
+
if (this.#listenErrorObserved) return;
|
|
1186
|
+
if (!this.options.silent) console.error("[srvx] Failed to start server:", error);
|
|
1187
|
+
const process = globalThis.process;
|
|
1188
|
+
if (process && !process.exitCode) process.exitCode = 1;
|
|
1189
|
+
}
|
|
1190
|
+
serve() {
|
|
1191
|
+
if (this.#listeningPromise) return this.#listeningPromise.then(() => this);
|
|
1192
|
+
const server = this.node?.server;
|
|
1193
|
+
if (!server) return Promise.reject(/* @__PURE__ */ new Error("Server not initialized"));
|
|
1194
|
+
this.#listenError = void 0;
|
|
1195
|
+
this.#listeningPromise = new Promise((resolve, reject) => {
|
|
1196
|
+
const onError = (error) => {
|
|
1197
|
+
server.off("listening", onListening);
|
|
1198
|
+
this.#listenError = error;
|
|
1199
|
+
this.#listeningPromise = void 0;
|
|
1200
|
+
reject(error);
|
|
1201
|
+
};
|
|
1202
|
+
const onListening = () => {
|
|
1203
|
+
server.off("error", onError);
|
|
1204
|
+
printListening(this.options, this.url);
|
|
1205
|
+
resolve();
|
|
1206
|
+
};
|
|
1207
|
+
server.once("error", onError);
|
|
1208
|
+
server.once("listening", onListening);
|
|
1209
|
+
server.listen(this.serveOptions);
|
|
1210
|
+
});
|
|
1211
|
+
return this.#listeningPromise.then(() => this);
|
|
1212
|
+
}
|
|
1213
|
+
get url() {
|
|
1214
|
+
const addr = this.node?.server?.address();
|
|
1215
|
+
if (!addr) return;
|
|
1216
|
+
return typeof addr === "string" ? addr : fmtURL(addr.address, addr.port, this.#isSecure);
|
|
1217
|
+
}
|
|
1218
|
+
ready() {
|
|
1219
|
+
this.#listenErrorObserved = true;
|
|
1220
|
+
if (this.#listenError) return Promise.reject(this.#listenError);
|
|
1221
|
+
return Promise.resolve(this.#listeningPromise).then(() => this);
|
|
1222
|
+
}
|
|
1223
|
+
async close(closeAll) {
|
|
1224
|
+
await Promise.all([this.#wait?.wait(), new Promise((resolve, reject) => {
|
|
1225
|
+
const server = this.node?.server;
|
|
1226
|
+
if (server && closeAll && "closeAllConnections" in server) server.closeAllConnections();
|
|
1227
|
+
if (!server || !server.listening) return resolve();
|
|
1228
|
+
server.close((error) => error ? reject(error) : resolve());
|
|
1229
|
+
})]);
|
|
1230
|
+
}
|
|
1231
|
+
};
|
|
1232
|
+
//#endregion
|
|
1233
|
+
//#region ../../node_modules/.pnpm/rou3@0.9.2/node_modules/rou3/dist/index.mjs
|
|
1234
|
+
var NullProtoObj = /* @__PURE__ */ (() => {
|
|
1235
|
+
const e = function() {};
|
|
1236
|
+
return e.prototype = Object.create(null), Object.freeze(e.prototype), e;
|
|
1237
|
+
})();
|
|
1238
|
+
//#endregion
|
|
1239
|
+
//#region ../../node_modules/.pnpm/h3@2.0.1-rc.32_crossws@0.4.12_srvx@1.0.5__ocache@0.3.0/node_modules/h3/dist/response.mjs
|
|
1240
|
+
var NEEDLESS_ESCAPE_SRC = String.raw`%(?:2[146-9A-E]|3[0-9ABD]|4[0-9A-F]|5[0-9ABDF]|6[1-9A-F]|7[0-9ACE])`;
|
|
1241
|
+
var NEEDLESS_ESCAPE_RE = /* @__PURE__ */ new RegExp(NEEDLESS_ESCAPE_SRC, "i");
|
|
1242
|
+
var NEEDLESS_ESCAPE_RE_G = /* @__PURE__ */ new RegExp(NEEDLESS_ESCAPE_SRC, "gi");
|
|
1243
|
+
function isNonCanonicalPathname(pathname) {
|
|
1244
|
+
return NEEDLESS_ESCAPE_RE.test(pathname);
|
|
1245
|
+
}
|
|
1246
|
+
function canonicalPathname(pathname) {
|
|
1247
|
+
return pathname.replace(NEEDLESS_ESCAPE_RE_G, (m) => String.fromCharCode(Number.parseInt(m.slice(1), 16)));
|
|
1248
|
+
}
|
|
1249
|
+
function decodePathname(pathname) {
|
|
1250
|
+
try {
|
|
1251
|
+
return decodeURI(pathname);
|
|
1252
|
+
} catch {
|
|
1253
|
+
return;
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
var ENCODED_SEP_RE_G$1 = /%(?:25)*(?:2f|5c)/gi;
|
|
1257
|
+
var ENCODED_SEP_FLAT_RE_G = /%(?:2f|5c)/gi;
|
|
1258
|
+
function decodePreservingSeparators(value, opts) {
|
|
1259
|
+
if (!value.includes("%")) return value;
|
|
1260
|
+
const decode = opts?.decode || decodeURIComponent;
|
|
1261
|
+
const re = opts?.nested === false ? ENCODED_SEP_FLAT_RE_G : ENCODED_SEP_RE_G$1;
|
|
1262
|
+
let result = "";
|
|
1263
|
+
let lastIndex = 0;
|
|
1264
|
+
re.lastIndex = 0;
|
|
1265
|
+
for (let m; m = re.exec(value);) {
|
|
1266
|
+
result += decode(value.slice(lastIndex, m.index)) + m[0];
|
|
1267
|
+
lastIndex = m.index + m[0].length;
|
|
1268
|
+
}
|
|
1269
|
+
return result + decode(value.slice(lastIndex));
|
|
1270
|
+
}
|
|
1271
|
+
var kEventNS = "h3.internal.event.";
|
|
1272
|
+
var kEventRes = /* @__PURE__ */ Symbol.for(`${kEventNS}res`);
|
|
1273
|
+
var kEventResHeaders = /* @__PURE__ */ Symbol.for(`${kEventNS}res.headers`);
|
|
1274
|
+
var kEventResErrHeaders = /* @__PURE__ */ Symbol.for(`${kEventNS}res.err.headers`);
|
|
1275
|
+
var kMalformedURL = /* @__PURE__ */ Symbol.for(`${kEventNS}malformed`);
|
|
1276
|
+
var H3Event = class {
|
|
1277
|
+
app;
|
|
1278
|
+
req;
|
|
1279
|
+
url;
|
|
1280
|
+
context;
|
|
1281
|
+
static __is_event__ = true;
|
|
1282
|
+
constructor(req, context, app) {
|
|
1283
|
+
this.context = req.context = context || req.context || new NullProtoObj();
|
|
1284
|
+
this.req = req;
|
|
1285
|
+
this.app = app;
|
|
1286
|
+
const _url = req._url;
|
|
1287
|
+
let url = _url && _url instanceof URL ? _url : new FastURL(req.url);
|
|
1288
|
+
const pathname = url.pathname;
|
|
1289
|
+
if (pathname.includes("%")) {
|
|
1290
|
+
if (decodePathname(pathname) === void 0) this[kMalformedURL] = true;
|
|
1291
|
+
else if (isNonCanonicalPathname(pathname)) url = new FastURL(`${url.protocol}//${url.host}${canonicalPathname(pathname)}${url.search}`);
|
|
1292
|
+
}
|
|
1293
|
+
this.url = url;
|
|
1294
|
+
}
|
|
1295
|
+
get res() {
|
|
1296
|
+
return this[kEventRes] ||= new H3EventResponse();
|
|
1297
|
+
}
|
|
1298
|
+
get runtime() {
|
|
1299
|
+
return this.req.runtime;
|
|
1300
|
+
}
|
|
1301
|
+
waitUntil(promise) {
|
|
1302
|
+
this.req.waitUntil?.(promise);
|
|
1303
|
+
}
|
|
1304
|
+
toString() {
|
|
1305
|
+
return `[${this.req.method}] ${this.req.url}`;
|
|
1306
|
+
}
|
|
1307
|
+
toJSON() {
|
|
1308
|
+
return this.toString();
|
|
1309
|
+
}
|
|
1310
|
+
get node() {
|
|
1311
|
+
return this.req.runtime?.node;
|
|
1312
|
+
}
|
|
1313
|
+
get headers() {
|
|
1314
|
+
return this.req.headers;
|
|
1315
|
+
}
|
|
1316
|
+
get path() {
|
|
1317
|
+
return this.url.pathname + this.url.search;
|
|
1318
|
+
}
|
|
1319
|
+
get method() {
|
|
1320
|
+
return this.req.method;
|
|
1321
|
+
}
|
|
1322
|
+
};
|
|
1323
|
+
var H3EventResponse = class {
|
|
1324
|
+
status;
|
|
1325
|
+
statusText;
|
|
1326
|
+
get headers() {
|
|
1327
|
+
return this[kEventResHeaders] ||= new Headers();
|
|
1328
|
+
}
|
|
1329
|
+
get errHeaders() {
|
|
1330
|
+
return this[kEventResErrHeaders] ||= new Headers();
|
|
1331
|
+
}
|
|
1332
|
+
};
|
|
1333
|
+
var DISALLOWED_STATUS_CHARS = /[^\u0009\u0020-\u007E]/g;
|
|
1334
|
+
function sanitizeStatusMessage(statusMessage = "") {
|
|
1335
|
+
return statusMessage.replace(DISALLOWED_STATUS_CHARS, "");
|
|
1336
|
+
}
|
|
1337
|
+
function sanitizeStatusCode(statusCode, defaultStatusCode = 200) {
|
|
1338
|
+
if (!statusCode) return defaultStatusCode;
|
|
1339
|
+
if (typeof statusCode === "string") statusCode = +statusCode;
|
|
1340
|
+
if (!Number.isInteger(statusCode) || statusCode < 100 || statusCode > 599) return defaultStatusCode;
|
|
1341
|
+
return statusCode;
|
|
1342
|
+
}
|
|
1343
|
+
var HTTPError = class HTTPError extends Error {
|
|
1344
|
+
get name() {
|
|
1345
|
+
return "HTTPError";
|
|
1346
|
+
}
|
|
1347
|
+
status;
|
|
1348
|
+
statusText;
|
|
1349
|
+
headers;
|
|
1350
|
+
cause;
|
|
1351
|
+
data;
|
|
1352
|
+
body;
|
|
1353
|
+
unhandled;
|
|
1354
|
+
static isError(input) {
|
|
1355
|
+
return input instanceof Error && input?.name === "HTTPError" && input.status > 99;
|
|
1356
|
+
}
|
|
1357
|
+
static status(status, statusText, details) {
|
|
1358
|
+
return new HTTPError({
|
|
1359
|
+
...details,
|
|
1360
|
+
statusText,
|
|
1361
|
+
status
|
|
1362
|
+
});
|
|
1363
|
+
}
|
|
1364
|
+
constructor(arg1, arg2) {
|
|
1365
|
+
let messageInput;
|
|
1366
|
+
let details;
|
|
1367
|
+
if (typeof arg1 === "string") {
|
|
1368
|
+
messageInput = arg1;
|
|
1369
|
+
details = arg2;
|
|
1370
|
+
} else details = arg1;
|
|
1371
|
+
const status = sanitizeStatusCode(details?.status || details?.statusCode || (details?.cause)?.status || (details?.cause)?.statusCode, 500);
|
|
1372
|
+
const statusText = sanitizeStatusMessage(details?.statusText || details?.statusMessage || (details?.cause)?.statusText || (details?.cause)?.statusMessage);
|
|
1373
|
+
const message = messageInput || details?.message || (details?.cause)?.message || details?.statusText || details?.statusMessage || [
|
|
1374
|
+
"HTTPError",
|
|
1375
|
+
status,
|
|
1376
|
+
statusText
|
|
1377
|
+
].filter(Boolean).join(" ");
|
|
1378
|
+
super(message, { cause: details });
|
|
1379
|
+
this.cause = details;
|
|
1380
|
+
this.status = status;
|
|
1381
|
+
this.statusText = statusText || void 0;
|
|
1382
|
+
const rawHeaders = details?.headers || (details?.cause)?.headers;
|
|
1383
|
+
this.headers = rawHeaders ? new Headers(rawHeaders) : void 0;
|
|
1384
|
+
this.unhandled = details?.unhandled ?? (details?.cause)?.unhandled ?? void 0;
|
|
1385
|
+
this.data = details?.data;
|
|
1386
|
+
this.body = details?.body;
|
|
1387
|
+
}
|
|
1388
|
+
get statusCode() {
|
|
1389
|
+
return this.status;
|
|
1390
|
+
}
|
|
1391
|
+
get statusMessage() {
|
|
1392
|
+
return this.statusText;
|
|
1393
|
+
}
|
|
1394
|
+
toJSON() {
|
|
1395
|
+
const unhandled = this.unhandled;
|
|
1396
|
+
return {
|
|
1397
|
+
status: this.status,
|
|
1398
|
+
statusText: this.statusText,
|
|
1399
|
+
unhandled,
|
|
1400
|
+
message: unhandled ? "HTTPError" : this.message,
|
|
1401
|
+
data: unhandled ? void 0 : this.data,
|
|
1402
|
+
...unhandled ? void 0 : this.body
|
|
1403
|
+
};
|
|
1404
|
+
}
|
|
1405
|
+
};
|
|
1406
|
+
function isJSONSerializable(value, _type) {
|
|
1407
|
+
if (value === null || value === void 0) return true;
|
|
1408
|
+
if (_type !== "object") return _type === "boolean" || _type === "number" || _type === "string";
|
|
1409
|
+
if (typeof value.toJSON === "function") return true;
|
|
1410
|
+
if (Array.isArray(value)) return true;
|
|
1411
|
+
if (typeof value.pipe === "function" || typeof value.pipeTo === "function") return false;
|
|
1412
|
+
if (value instanceof NullProtoObj) return true;
|
|
1413
|
+
const proto = Object.getPrototypeOf(value);
|
|
1414
|
+
return proto === Object.prototype || proto === null;
|
|
1415
|
+
}
|
|
1416
|
+
var kEventDispose = /* @__PURE__ */ Symbol.for("h3.internal.event.dispose");
|
|
1417
|
+
var kNotFound = /* @__PURE__ */ Symbol.for("h3.notFound");
|
|
1418
|
+
var kHandled = /* @__PURE__ */ Symbol.for("h3.handled");
|
|
1419
|
+
function toResponse(val, event, config = {}) {
|
|
1420
|
+
if (typeof val?.then === "function") return val.then((resolvedVal) => toResponse(resolvedVal, event, config), (r) => toResponse(toError(r), event, config));
|
|
1421
|
+
let response;
|
|
1422
|
+
try {
|
|
1423
|
+
response = prepareResponse(val, event, config);
|
|
1424
|
+
} catch (error) {
|
|
1425
|
+
return toResponse(toError(error), event, config);
|
|
1426
|
+
}
|
|
1427
|
+
if (typeof response?.then === "function") return toResponse(response, event, config);
|
|
1428
|
+
const { onResponse } = config;
|
|
1429
|
+
if (onResponse) return Promise.resolve().then(() => onResponse(response, event)).catch((error) => {
|
|
1430
|
+
if (!config.silent) console.error(error);
|
|
1431
|
+
}).then(() => event[kEventDispose]?.observe(response, val) ?? response);
|
|
1432
|
+
return event[kEventDispose]?.observe(response, val) ?? response;
|
|
1433
|
+
}
|
|
1434
|
+
function toError(value) {
|
|
1435
|
+
if (value === kNotFound || value === kHandled || value instanceof Error) return value;
|
|
1436
|
+
if (typeof value === "number") return new HTTPError({ status: value });
|
|
1437
|
+
const error = new HTTPError({
|
|
1438
|
+
status: 500,
|
|
1439
|
+
unhandled: true
|
|
1440
|
+
});
|
|
1441
|
+
error.cause = value;
|
|
1442
|
+
return error;
|
|
1443
|
+
}
|
|
1444
|
+
var kHTTPResponse = /* @__PURE__ */ Symbol.for("h3.HTTPResponse");
|
|
1445
|
+
var HTTPResponse = class {
|
|
1446
|
+
#headers;
|
|
1447
|
+
#init;
|
|
1448
|
+
body;
|
|
1449
|
+
constructor(body, init) {
|
|
1450
|
+
this.body = body;
|
|
1451
|
+
this.#init = init;
|
|
1452
|
+
}
|
|
1453
|
+
get status() {
|
|
1454
|
+
return this.#init?.status;
|
|
1455
|
+
}
|
|
1456
|
+
get statusText() {
|
|
1457
|
+
return this.#init?.statusText;
|
|
1458
|
+
}
|
|
1459
|
+
get headers() {
|
|
1460
|
+
return this.#headers ||= new Headers(this.#init?.headers);
|
|
1461
|
+
}
|
|
1462
|
+
};
|
|
1463
|
+
HTTPResponse.prototype[kHTTPResponse] = true;
|
|
1464
|
+
function prepareResponse(val, event, config, nested) {
|
|
1465
|
+
if (val === kHandled) return new NodeResponse(null);
|
|
1466
|
+
if (val === kNotFound) val = new HTTPError({
|
|
1467
|
+
status: 404,
|
|
1468
|
+
message: `Cannot find any route matching [${event.req.method}] ${event.url}`
|
|
1469
|
+
});
|
|
1470
|
+
if (val && val instanceof Error) {
|
|
1471
|
+
const isHTTPError = HTTPError.isError(val);
|
|
1472
|
+
const error = isHTTPError ? val : new HTTPError(val);
|
|
1473
|
+
if (!isHTTPError) {
|
|
1474
|
+
error.unhandled = true;
|
|
1475
|
+
if (val?.stack) error.stack = val.stack;
|
|
1476
|
+
}
|
|
1477
|
+
if (error.unhandled && !config.silent) console.error(error);
|
|
1478
|
+
const { onError } = config;
|
|
1479
|
+
const errHeaders = event[kEventRes]?.[kEventResErrHeaders];
|
|
1480
|
+
if (onError && !nested) return Promise.resolve().then(() => onError(error, event)).catch(toError).then((newVal) => prepareResponse(newVal ?? val, event, config, true));
|
|
1481
|
+
event[kEventRes] = void 0;
|
|
1482
|
+
return errorResponse(error, config.debug, errHeaders);
|
|
1483
|
+
}
|
|
1484
|
+
const preparedRes = event[kEventRes];
|
|
1485
|
+
let preparedHeaders = preparedRes?.[kEventResHeaders];
|
|
1486
|
+
event[kEventRes] = void 0;
|
|
1487
|
+
if (!(val instanceof Response)) {
|
|
1488
|
+
const res = prepareResponseBody(val, event, config);
|
|
1489
|
+
const rawStatus = res.status || preparedRes?.status;
|
|
1490
|
+
const status = rawStatus ? sanitizeStatusCode(rawStatus) : void 0;
|
|
1491
|
+
const rawStatusText = res.statusText || preparedRes?.statusText;
|
|
1492
|
+
return new NodeResponse(nullBody(event.req.method, status) ? null : res.body, {
|
|
1493
|
+
status,
|
|
1494
|
+
statusText: rawStatusText === void 0 ? void 0 : sanitizeStatusMessage(rawStatusText),
|
|
1495
|
+
headers: res.headers && preparedHeaders ? mergeHeaders(res.headers, preparedHeaders) : res.headers || preparedHeaders
|
|
1496
|
+
});
|
|
1497
|
+
}
|
|
1498
|
+
if (val.status >= 400) preparedHeaders = preparedRes?.[kEventResErrHeaders];
|
|
1499
|
+
if (preparedHeaders && !nested && !preparedHeaders.keys().next().done) return new NodeResponse(nullBody(event.req.method, val.status) ? null : val.body, {
|
|
1500
|
+
status: val.status,
|
|
1501
|
+
statusText: val.statusText,
|
|
1502
|
+
headers: mergeHeaders(val.headers, preparedHeaders)
|
|
1503
|
+
});
|
|
1504
|
+
return event.req.method === "HEAD" && val.body !== null ? new NodeResponse(null, {
|
|
1505
|
+
status: val.status,
|
|
1506
|
+
statusText: val.statusText,
|
|
1507
|
+
headers: val.headers
|
|
1508
|
+
}) : val;
|
|
1509
|
+
}
|
|
1510
|
+
function mergeHeaders(base, overrides, target = new Headers(base)) {
|
|
1511
|
+
for (const [name, value] of overrides) if (name === "set-cookie") target.append(name, value);
|
|
1512
|
+
else target.set(name, value);
|
|
1513
|
+
return target;
|
|
1514
|
+
}
|
|
1515
|
+
var frozen = (name) => (...args) => {
|
|
1516
|
+
throw new Error(`Headers are frozen (${name} ${args.join(", ")})`);
|
|
1517
|
+
};
|
|
1518
|
+
var FrozenHeaders = class extends Headers {
|
|
1519
|
+
set = frozen("set");
|
|
1520
|
+
append = frozen("append");
|
|
1521
|
+
delete = frozen("delete");
|
|
1522
|
+
};
|
|
1523
|
+
var emptyHeaders = /* @__PURE__ */ new FrozenHeaders({ "content-length": "0" });
|
|
1524
|
+
var jsonHeaders = /* @__PURE__ */ new FrozenHeaders({ "content-type": "application/json;charset=UTF-8" });
|
|
1525
|
+
function prepareResponseBody(val, event, config) {
|
|
1526
|
+
if (val === null || val === void 0) return {
|
|
1527
|
+
body: "",
|
|
1528
|
+
headers: emptyHeaders
|
|
1529
|
+
};
|
|
1530
|
+
const valType = typeof val;
|
|
1531
|
+
if (valType === "string") return { body: val };
|
|
1532
|
+
if (val instanceof Uint8Array) return {
|
|
1533
|
+
body: val,
|
|
1534
|
+
headers: new Headers({ "content-length": val.byteLength.toString() })
|
|
1535
|
+
};
|
|
1536
|
+
if (val instanceof HTTPResponse || val?.[kHTTPResponse] === true) return val;
|
|
1537
|
+
if (isJSONSerializable(val, valType)) return {
|
|
1538
|
+
body: JSON.stringify(val, void 0, config.debug ? 2 : void 0),
|
|
1539
|
+
headers: jsonHeaders
|
|
1540
|
+
};
|
|
1541
|
+
if (valType === "bigint") return {
|
|
1542
|
+
body: val.toString(),
|
|
1543
|
+
headers: jsonHeaders
|
|
1544
|
+
};
|
|
1545
|
+
if (val instanceof Blob) {
|
|
1546
|
+
const headers = new Headers({
|
|
1547
|
+
"content-type": val.type,
|
|
1548
|
+
"content-length": val.size.toString()
|
|
1549
|
+
});
|
|
1550
|
+
let filename = val.name;
|
|
1551
|
+
if (filename) {
|
|
1552
|
+
filename = encodeURIComponent(filename);
|
|
1553
|
+
headers.set("content-disposition", `filename="${filename}"; filename*=UTF-8''${filename}`);
|
|
1554
|
+
}
|
|
1555
|
+
return {
|
|
1556
|
+
body: val.stream(),
|
|
1557
|
+
headers
|
|
1558
|
+
};
|
|
1559
|
+
}
|
|
1560
|
+
if (valType === "symbol") return { body: val.toString() };
|
|
1561
|
+
if (valType === "function") return { body: `${val.name}()` };
|
|
1562
|
+
return { body: val };
|
|
1563
|
+
}
|
|
1564
|
+
function nullBody(method, status) {
|
|
1565
|
+
return method === "HEAD" || status === 100 || status === 101 || status === 102 || status === 204 || status === 205 || status === 304;
|
|
1566
|
+
}
|
|
1567
|
+
function errorResponse(error, debug, errHeaders) {
|
|
1568
|
+
let headers = error.headers ? mergeHeaders(jsonHeaders, error.headers) : new Headers(jsonHeaders);
|
|
1569
|
+
if (errHeaders) headers = mergeHeaders(headers, errHeaders);
|
|
1570
|
+
return new NodeResponse(JSON.stringify({
|
|
1571
|
+
...error.toJSON(),
|
|
1572
|
+
stack: debug && error.stack ? error.stack.split("\n").map((l) => l.trim()) : void 0
|
|
1573
|
+
}, void 0, debug ? 2 : void 0), {
|
|
1574
|
+
status: error.status,
|
|
1575
|
+
statusText: error.statusText,
|
|
1576
|
+
headers
|
|
1577
|
+
});
|
|
1578
|
+
}
|
|
1579
|
+
//#endregion
|
|
1580
|
+
//#region ../../node_modules/.pnpm/h3@2.0.1-rc.32_crossws@0.4.12_srvx@1.0.5__ocache@0.3.0/node_modules/h3/dist/middleware.mjs
|
|
1581
|
+
function composeMiddleware(middleware) {
|
|
1582
|
+
let chain = (event, handler) => handler(event);
|
|
1583
|
+
for (let i = middleware.length - 1; i >= 0; i--) {
|
|
1584
|
+
const fn = middleware[i];
|
|
1585
|
+
const inner = chain;
|
|
1586
|
+
chain = (event, handler) => callLayer(fn, event, handler, inner);
|
|
1587
|
+
}
|
|
1588
|
+
return chain;
|
|
1589
|
+
}
|
|
1590
|
+
function composeHandler(middleware, handler) {
|
|
1591
|
+
const chain = composeMiddleware(middleware);
|
|
1592
|
+
return function _composedHandler(event) {
|
|
1593
|
+
return chain(event, handler);
|
|
1594
|
+
};
|
|
1595
|
+
}
|
|
1596
|
+
function callMiddleware(event, middleware, handler, index = 0) {
|
|
1597
|
+
return index === middleware.length ? handler(event) : callLayer(middleware[index], event, handler, (_event, _handler) => callMiddleware(_event, middleware, _handler, index + 1));
|
|
1598
|
+
}
|
|
1599
|
+
function callLayer(fn, event, handler, inner) {
|
|
1600
|
+
let nextCalled;
|
|
1601
|
+
let nextResult;
|
|
1602
|
+
const next = () => {
|
|
1603
|
+
if (nextCalled) return nextResult;
|
|
1604
|
+
nextCalled = true;
|
|
1605
|
+
nextResult = inner(event, handler);
|
|
1606
|
+
return nextResult;
|
|
1607
|
+
};
|
|
1608
|
+
const ret = fn(event, next);
|
|
1609
|
+
return isUnhandledResponse(ret) ? next() : typeof ret?.then === "function" ? ret.then((resolved) => isUnhandledResponse(resolved) ? next() : resolved) : ret;
|
|
1610
|
+
}
|
|
1611
|
+
function isUnhandledResponse(val) {
|
|
1612
|
+
return val === void 0 || val === kNotFound;
|
|
1613
|
+
}
|
|
1614
|
+
//#endregion
|
|
1615
|
+
//#region ../../node_modules/.pnpm/h3@2.0.1-rc.32_crossws@0.4.12_srvx@1.0.5__ocache@0.3.0/node_modules/h3/dist/cache.mjs
|
|
1616
|
+
function toRequest(input, options) {
|
|
1617
|
+
if (typeof input === "string") {
|
|
1618
|
+
let url = input;
|
|
1619
|
+
if (url[0] === "/") url = `http://${safeHost((options?.headers ? new Headers(options.headers) : void 0)?.get("host"))}${url}`;
|
|
1620
|
+
return new Request(url, options);
|
|
1621
|
+
} else if (options || input instanceof URL) return new Request(input, options);
|
|
1622
|
+
return input;
|
|
1623
|
+
}
|
|
1624
|
+
function safeHost(host) {
|
|
1625
|
+
return host && !/[/\\?#@\s]/.test(host) ? host : "localhost";
|
|
1626
|
+
}
|
|
1627
|
+
function defineHandler(input) {
|
|
1628
|
+
if (typeof input === "function") return handlerWithFetch(input);
|
|
1629
|
+
const handler = input.handler || (input.fetch ? function _fetchHandler(event) {
|
|
1630
|
+
return input.fetch(event.req);
|
|
1631
|
+
} : NoHandler);
|
|
1632
|
+
const composed = input.middleware?.length && composeHandler(input.middleware, handler);
|
|
1633
|
+
const eventHandler = handlerWithFetch(composed || handler);
|
|
1634
|
+
return Object.assign(eventHandler, input, composed && { fetch: eventHandler.fetch });
|
|
1635
|
+
}
|
|
1636
|
+
function handlerWithFetch(handler) {
|
|
1637
|
+
if ("fetch" in handler) return handler;
|
|
1638
|
+
return Object.assign(handler, { fetch: (req) => {
|
|
1639
|
+
if (typeof req === "string") req = new URL(req, "http://_");
|
|
1640
|
+
if (req instanceof URL) req = new Request(req);
|
|
1641
|
+
const event = new H3Event(req);
|
|
1642
|
+
try {
|
|
1643
|
+
return Promise.resolve(toResponse(handler(event), event));
|
|
1644
|
+
} catch (error) {
|
|
1645
|
+
return Promise.resolve(toResponse(toError(error), event));
|
|
1646
|
+
}
|
|
1647
|
+
} });
|
|
1648
|
+
}
|
|
1649
|
+
function defineLazyEventHandler(loader) {
|
|
1650
|
+
let handler;
|
|
1651
|
+
let promise;
|
|
1652
|
+
return defineHandler(function lazyHandler(event) {
|
|
1653
|
+
return handler ? handler(event) : (promise ??= Promise.resolve(loader()).then(function resolveLazyHandler(r) {
|
|
1654
|
+
handler = toEventHandler(r) || toEventHandler(r.default);
|
|
1655
|
+
if (typeof handler !== "function") throw new TypeError("Invalid lazy handler", { cause: { resolved: r } });
|
|
1656
|
+
return handler;
|
|
1657
|
+
})).then((r) => r(event));
|
|
1658
|
+
});
|
|
1659
|
+
}
|
|
1660
|
+
function toEventHandler(handler) {
|
|
1661
|
+
if (typeof handler === "function") return handler;
|
|
1662
|
+
if (typeof handler?.handler === "function" && handler.constructor?.["~h3"]) return handler.handler;
|
|
1663
|
+
if (typeof handler?.fetch === "function") return function _fetchHandler(event) {
|
|
1664
|
+
return handler.fetch(event.req);
|
|
1665
|
+
};
|
|
1666
|
+
}
|
|
1667
|
+
var NoHandler = () => kNotFound;
|
|
1668
|
+
var H3Core = class {
|
|
1669
|
+
static "~h3" = true;
|
|
1670
|
+
config;
|
|
1671
|
+
"~middleware";
|
|
1672
|
+
"~routes" = [];
|
|
1673
|
+
"~dispatch";
|
|
1674
|
+
"~composed";
|
|
1675
|
+
constructor(config = {}) {
|
|
1676
|
+
this["~middleware"] = [];
|
|
1677
|
+
this.config = config;
|
|
1678
|
+
this.fetch = this.fetch.bind(this);
|
|
1679
|
+
this.handler = this.handler.bind(this);
|
|
1680
|
+
}
|
|
1681
|
+
fetch(request) {
|
|
1682
|
+
return this["~request"](request);
|
|
1683
|
+
}
|
|
1684
|
+
handler(event) {
|
|
1685
|
+
const route = this["~findRoute"](event);
|
|
1686
|
+
if (route) {
|
|
1687
|
+
event.context.params = route.params;
|
|
1688
|
+
event.context.matchedRoute = route.data;
|
|
1689
|
+
}
|
|
1690
|
+
return (this["~dispatch"] ??= createDispatcher(this))(event, route);
|
|
1691
|
+
}
|
|
1692
|
+
"~request"(request, context) {
|
|
1693
|
+
const event = new H3Event(request, context, this);
|
|
1694
|
+
let handlerRes;
|
|
1695
|
+
try {
|
|
1696
|
+
if (event[kMalformedURL] && !this.config.allowMalformedURL) throw new HTTPError({
|
|
1697
|
+
status: 400,
|
|
1698
|
+
message: "Bad Request"
|
|
1699
|
+
});
|
|
1700
|
+
if (this.config.onRequest) {
|
|
1701
|
+
const hookRes = this.config.onRequest(event);
|
|
1702
|
+
handlerRes = typeof hookRes?.then === "function" ? hookRes.then(() => this.handler(event)) : this.handler(event);
|
|
1703
|
+
} else handlerRes = this.handler(event);
|
|
1704
|
+
} catch (error) {
|
|
1705
|
+
handlerRes = Promise.reject(error);
|
|
1706
|
+
}
|
|
1707
|
+
return toResponse(handlerRes, event, this.config);
|
|
1708
|
+
}
|
|
1709
|
+
"~findRoute"(_event) {}
|
|
1710
|
+
"~addRoute"(_route) {
|
|
1711
|
+
this["~routes"].push(_route);
|
|
1712
|
+
}
|
|
1713
|
+
"~getMiddleware"(_event, _route) {
|
|
1714
|
+
return this["~middleware"];
|
|
1715
|
+
}
|
|
1716
|
+
};
|
|
1717
|
+
function createDispatcher(app) {
|
|
1718
|
+
if (app["~getMiddleware"] !== H3Core.prototype["~getMiddleware"]) return (event, route) => callMiddleware(event, app["~getMiddleware"](event, route || void 0), routeHandler(route));
|
|
1719
|
+
const middleware = app["~middleware"];
|
|
1720
|
+
if (middleware.length === 0) return (event, route) => routeHandler(route)(event);
|
|
1721
|
+
const composed = app["~composed"] ??= composeMiddleware(middleware);
|
|
1722
|
+
return (event, route) => composed(event, routeHandler(route));
|
|
1723
|
+
}
|
|
1724
|
+
function routeHandler(route) {
|
|
1725
|
+
const data = route?.data;
|
|
1726
|
+
if (!data) return NoHandler;
|
|
1727
|
+
return data.middleware?.length ? data["~composed"] ??= composeHandler(data.middleware, data.handler) : data.handler;
|
|
1728
|
+
}
|
|
1729
|
+
//#endregion
|
|
1730
|
+
//#region ../../node_modules/.pnpm/h3@2.0.1-rc.32_crossws@0.4.12_srvx@1.0.5__ocache@0.3.0/node_modules/h3/dist/path.mjs
|
|
1731
|
+
var DOT_SEGMENT_SRC = String.raw`(?:^|/)(?:\.|%(?:25)*2e){1,2}(?:/|$)`;
|
|
1732
|
+
var ENCODED_SEP_SRC = String.raw`%(?:25)*(?:2f|5c)`;
|
|
1733
|
+
var ENCODED_SEP_RE_G = /* @__PURE__ */ new RegExp(ENCODED_SEP_SRC, "gi");
|
|
1734
|
+
var TRIGGER_RES = /* @__PURE__ */ (() => {
|
|
1735
|
+
const base = String.raw`\\|` + DOT_SEGMENT_SRC;
|
|
1736
|
+
return [
|
|
1737
|
+
new RegExp(base, "i"),
|
|
1738
|
+
new RegExp(`${base}|${ENCODED_SEP_SRC}`, "i"),
|
|
1739
|
+
new RegExp(`${base}|//`, "i"),
|
|
1740
|
+
new RegExp(`${base}|${ENCODED_SEP_SRC}|//`, "i")
|
|
1741
|
+
];
|
|
1742
|
+
})();
|
|
1743
|
+
var ENCODED_DOT_RE_G = /%(?:25)*2e/gi;
|
|
1744
|
+
function resolveDotSegments(path, opts) {
|
|
1745
|
+
if (path[0] !== "/" || path[1] === "/" || path[1] === "\\") path = "/" + path.replace(/^[/\\]+/, "");
|
|
1746
|
+
if (isCanonicalPath(path, opts)) return path;
|
|
1747
|
+
const decodeSlashes = opts?.decodeSlashes;
|
|
1748
|
+
const mergeSlashes = opts?.mergeSlashes;
|
|
1749
|
+
let normalized = path.includes("\\") ? path.replaceAll("\\", "/") : path;
|
|
1750
|
+
if (decodeSlashes) normalized = normalized.replace(ENCODED_SEP_RE_G, "/");
|
|
1751
|
+
const segments = normalized.split("/");
|
|
1752
|
+
const lastIndex = segments.length - 1;
|
|
1753
|
+
const resolved = [];
|
|
1754
|
+
for (let i = 0; i <= lastIndex; i++) {
|
|
1755
|
+
const segment = segments[i];
|
|
1756
|
+
const normalizedSegment = segment.includes("%") ? segment.replace(ENCODED_DOT_RE_G, ".") : segment;
|
|
1757
|
+
const isDotSegment = normalizedSegment === "." || normalizedSegment === "..";
|
|
1758
|
+
if (normalizedSegment === "..") {
|
|
1759
|
+
if (resolved.length > 1) resolved.pop();
|
|
1760
|
+
} else if (mergeSlashes && normalizedSegment === "" && i > 0 && i < lastIndex) {} else if (!isDotSegment) resolved.push(segment);
|
|
1761
|
+
if (isDotSegment && i === lastIndex) resolved.push("");
|
|
1762
|
+
}
|
|
1763
|
+
return (resolved.join("/") || "/").replace(/^\/+/, "/");
|
|
1764
|
+
}
|
|
1765
|
+
function isCanonicalPath(path, opts) {
|
|
1766
|
+
return path[0] === "/" && path[1] !== "/" && path[1] !== "\\" && !TRIGGER_RES[(opts?.decodeSlashes ? 1 : 0) | (opts?.mergeSlashes ? 2 : 0)].test(path);
|
|
1767
|
+
}
|
|
1768
|
+
//#endregion
|
|
1769
|
+
//#region ../../node_modules/.pnpm/h3@2.0.1-rc.32_crossws@0.4.12_srvx@1.0.5__ocache@0.3.0/node_modules/h3/dist/_utils.mjs
|
|
1770
|
+
var CANONICAL_OPTS = { decodeSlashes: true };
|
|
1771
|
+
var MERGED_OPTS = {
|
|
1772
|
+
decodeSlashes: true,
|
|
1773
|
+
mergeSlashes: true
|
|
1774
|
+
};
|
|
1775
|
+
function canonicalPath(pathname) {
|
|
1776
|
+
return resolveDotSegments(pathname, CANONICAL_OPTS);
|
|
1777
|
+
}
|
|
1778
|
+
function decodedPath(pathname) {
|
|
1779
|
+
let decoded = pathname;
|
|
1780
|
+
for (let pass = 0; hasDecodableEscape(decoded); pass++) {
|
|
1781
|
+
if (pass >= MAX_PASSES) return decoded;
|
|
1782
|
+
const input = pass < EXACT_PASSES ? decoded : flattenNesting(decoded);
|
|
1783
|
+
let next;
|
|
1784
|
+
try {
|
|
1785
|
+
next = decodePreservingSeparators(input);
|
|
1786
|
+
} catch {
|
|
1787
|
+
return input;
|
|
1788
|
+
}
|
|
1789
|
+
if (next === input) return input;
|
|
1790
|
+
decoded = next;
|
|
1791
|
+
}
|
|
1792
|
+
return decoded;
|
|
1793
|
+
}
|
|
1794
|
+
var EXACT_PASSES = 8;
|
|
1795
|
+
var MAX_PASSES = 24;
|
|
1796
|
+
var CHAR_2 = 50;
|
|
1797
|
+
var CHAR_5 = 53;
|
|
1798
|
+
function needsCanonicalPasses(pathname) {
|
|
1799
|
+
return !isCanonicalPath(pathname, MERGED_OPTS);
|
|
1800
|
+
}
|
|
1801
|
+
function mergedCanonicalPath(pathname, canonical) {
|
|
1802
|
+
const merged = resolveDotSegments(pathname, MERGED_OPTS);
|
|
1803
|
+
return merged === canonical ? void 0 : merged;
|
|
1804
|
+
}
|
|
1805
|
+
function hasDecodableEscape(value) {
|
|
1806
|
+
for (let i = value.indexOf("%"); i !== -1; i = value.indexOf("%", i + 1)) {
|
|
1807
|
+
const byte = escapeByte(value, nestingEnd(value, i));
|
|
1808
|
+
if (byte !== 47 && byte !== 92) return true;
|
|
1809
|
+
}
|
|
1810
|
+
return false;
|
|
1811
|
+
}
|
|
1812
|
+
function flattenNesting(path) {
|
|
1813
|
+
let flat = "";
|
|
1814
|
+
let last = 0;
|
|
1815
|
+
for (let i = path.indexOf("%"); i !== -1; i = path.indexOf("%", i + 1)) {
|
|
1816
|
+
const end = nestingEnd(path, i);
|
|
1817
|
+
if (end === i + 1) continue;
|
|
1818
|
+
const byte = escapeByte(path, end);
|
|
1819
|
+
if (byte === 47 || byte === 92) continue;
|
|
1820
|
+
flat += path.slice(last, i) + (byte === -1 ? "%25" : "%");
|
|
1821
|
+
last = end;
|
|
1822
|
+
}
|
|
1823
|
+
return last === 0 ? path : flat + path.slice(last);
|
|
1824
|
+
}
|
|
1825
|
+
function nestingEnd(value, index) {
|
|
1826
|
+
let end = index + 1;
|
|
1827
|
+
while (value.charCodeAt(end) === CHAR_2 && value.charCodeAt(end + 1) === CHAR_5) end += 2;
|
|
1828
|
+
return end;
|
|
1829
|
+
}
|
|
1830
|
+
function escapeByte(value, index) {
|
|
1831
|
+
const high = hexDigit(value.charCodeAt(index));
|
|
1832
|
+
const low = hexDigit(value.charCodeAt(index + 1));
|
|
1833
|
+
return high === -1 || low === -1 ? -1 : high * 16 + low;
|
|
1834
|
+
}
|
|
1835
|
+
function hexDigit(code) {
|
|
1836
|
+
if (code >= 48 && code <= 57) return code - 48;
|
|
1837
|
+
if (code >= 97 && code <= 102) return code - 87;
|
|
1838
|
+
if (code >= 65 && code <= 70) return code - 55;
|
|
1839
|
+
return -1;
|
|
1840
|
+
}
|
|
1841
|
+
//#endregion
|
|
1842
|
+
//#region ../../node_modules/.pnpm/h3@2.0.1-rc.32_crossws@0.4.12_srvx@1.0.5__ocache@0.3.0/node_modules/h3/dist/normalize.mjs
|
|
1843
|
+
function mergeMatchedRouteRules(rawLayers, altLayers, canOverride) {
|
|
1844
|
+
const resets = /* @__PURE__ */ new Set();
|
|
1845
|
+
const routeRules = resolveLayers(rawLayers, resets);
|
|
1846
|
+
for (const layers of altLayers || []) unionLayers(routeRules, layers, canOverride, resets);
|
|
1847
|
+
return routeRules;
|
|
1848
|
+
}
|
|
1849
|
+
function unionLayers(routeRules, layers, canOverride, resets) {
|
|
1850
|
+
if (!layers?.length) return;
|
|
1851
|
+
const resolved = resolveLayers(layers, resets);
|
|
1852
|
+
for (const [name, rule] of Object.entries(resolved)) {
|
|
1853
|
+
const current = routeRules[name];
|
|
1854
|
+
if (current) {
|
|
1855
|
+
if (canOverride && !canOverride(current.route, rule.route)) continue;
|
|
1856
|
+
} else if (resets?.has(name) && !rule.handler?.restricting) continue;
|
|
1857
|
+
mergeRouteRule(routeRules, name, rule, rule.params);
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
function resolveLayers(layers, resets) {
|
|
1861
|
+
const firstData = layers?.[0]?.data;
|
|
1862
|
+
if (firstData && !Array.isArray(firstData)) return resolvePreMergedLayers(layers, resets);
|
|
1863
|
+
const routeRules = emptyRouteRules();
|
|
1864
|
+
for (const layer of orderedLayers(layers)) for (const entry of layer.data) {
|
|
1865
|
+
if (entry.options === false) resets?.add(entry.name);
|
|
1866
|
+
mergeRouteRule(routeRules, entry.name, entry, layer.params);
|
|
1867
|
+
}
|
|
1868
|
+
return routeRules;
|
|
1869
|
+
}
|
|
1870
|
+
function isMergeableObject(value) {
|
|
1871
|
+
return value !== null && typeof value === "object";
|
|
1872
|
+
}
|
|
1873
|
+
function emptyRouteRules() {
|
|
1874
|
+
return Object.create(null);
|
|
1875
|
+
}
|
|
1876
|
+
function mergeRuleOptions(current, incoming) {
|
|
1877
|
+
return isMergeableObject(current) && isMergeableObject(incoming) ? {
|
|
1878
|
+
...current,
|
|
1879
|
+
...incoming
|
|
1880
|
+
} : incoming;
|
|
1881
|
+
}
|
|
1882
|
+
function orderedLayers(layers) {
|
|
1883
|
+
if (!layers || layers.length < 2) return layers || [];
|
|
1884
|
+
let ordered = layers;
|
|
1885
|
+
for (let i = 1; i < ordered.length; i++) {
|
|
1886
|
+
const layer = ordered[i];
|
|
1887
|
+
const rank = layerRank(layer);
|
|
1888
|
+
let j = i - 1;
|
|
1889
|
+
while (j >= 0 && layerRank(ordered[j]) > rank) {
|
|
1890
|
+
if (ordered === layers) ordered = [...layers];
|
|
1891
|
+
ordered[j + 1] = ordered[j];
|
|
1892
|
+
j--;
|
|
1893
|
+
}
|
|
1894
|
+
if (j + 1 !== i) ordered[j + 1] = layer;
|
|
1895
|
+
}
|
|
1896
|
+
return ordered;
|
|
1897
|
+
}
|
|
1898
|
+
function layerRank(layer) {
|
|
1899
|
+
return layer.data[0]?.rank ?? 0;
|
|
1900
|
+
}
|
|
1901
|
+
function resolvePreMergedLayers(rawLayers, resets) {
|
|
1902
|
+
const layers = rawLayers.length < 2 ? rawLayers : [...rawLayers].sort((a, b) => a.data.rank - b.data.rank);
|
|
1903
|
+
const routeRules = emptyRouteRules();
|
|
1904
|
+
const winning = layers[layers.length - 1].data;
|
|
1905
|
+
if (resets && winning.resets) for (const name of winning.resets) resets.add(name);
|
|
1906
|
+
for (const entry of winning.rules) {
|
|
1907
|
+
const paramRoutes = entry.paramRoutes;
|
|
1908
|
+
let params;
|
|
1909
|
+
for (const layer of layers) {
|
|
1910
|
+
const layerParams = layer.params;
|
|
1911
|
+
if (!layerParams) continue;
|
|
1912
|
+
const layerRoute = layer.data.route;
|
|
1913
|
+
if (paramRoutes ? paramRoutes.includes(layerRoute) : layerRoute === entry.route) params = params ? {
|
|
1914
|
+
...params,
|
|
1915
|
+
...layerParams
|
|
1916
|
+
} : layerParams;
|
|
1917
|
+
}
|
|
1918
|
+
routeRules[entry.name] = {
|
|
1919
|
+
route: entry.route,
|
|
1920
|
+
options: entry.options,
|
|
1921
|
+
handler: entry.handler,
|
|
1922
|
+
params
|
|
1923
|
+
};
|
|
1924
|
+
}
|
|
1925
|
+
return routeRules;
|
|
1926
|
+
}
|
|
1927
|
+
function mergeRouteRule(routeRules, ruleName, rule, params) {
|
|
1928
|
+
const name = ruleName;
|
|
1929
|
+
const currentRule = routeRules[name];
|
|
1930
|
+
if (currentRule) {
|
|
1931
|
+
if (rule.options === false) {
|
|
1932
|
+
delete routeRules[name];
|
|
1933
|
+
return;
|
|
1934
|
+
}
|
|
1935
|
+
currentRule.options = mergeRuleOptions(currentRule.options, rule.options);
|
|
1936
|
+
currentRule.route = rule.route;
|
|
1937
|
+
if (currentRule.params || params) currentRule.params = {
|
|
1938
|
+
...currentRule.params,
|
|
1939
|
+
...params
|
|
1940
|
+
};
|
|
1941
|
+
} else if (rule.options !== false) routeRules[name] = {
|
|
1942
|
+
route: rule.route,
|
|
1943
|
+
options: rule.options,
|
|
1944
|
+
handler: rule.handler,
|
|
1945
|
+
params
|
|
1946
|
+
};
|
|
1947
|
+
}
|
|
1948
|
+
var headers = {
|
|
1949
|
+
order: -1,
|
|
1950
|
+
handler: (m) => {
|
|
1951
|
+
const entries = Object.entries(m.options || {});
|
|
1952
|
+
return async function headersRouteRule(event, next) {
|
|
1953
|
+
try {
|
|
1954
|
+
return await next();
|
|
1955
|
+
} finally {
|
|
1956
|
+
for (const [key, value] of entries) {
|
|
1957
|
+
event.res.headers.set(key, value);
|
|
1958
|
+
event.res.errHeaders.set(key, value);
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
};
|
|
1962
|
+
}
|
|
1963
|
+
};
|
|
1964
|
+
var OPAQUE_SEGMENT_RE = /[()\\]/;
|
|
1965
|
+
var CONCRETE_SEGMENT_RE = /^[^:*(){}\\]+$/;
|
|
1966
|
+
var ZERO_MATCHABLE_SEGMENT_RE = /^:.*[?*]$/;
|
|
1967
|
+
var canOverrideRouteShape = (currentRoute, incomingRoute) => {
|
|
1968
|
+
if (currentRoute === incomingRoute) return true;
|
|
1969
|
+
const current = currentRoute.split("/");
|
|
1970
|
+
const incoming = incomingRoute.split("/");
|
|
1971
|
+
for (let i = 0; i < current.length; i++) {
|
|
1972
|
+
const cur = current[i];
|
|
1973
|
+
if (cur === "**") return i === current.length - 1 && incoming.length > i && !incoming.slice(i).some((segment) => ZERO_MATCHABLE_SEGMENT_RE.test(segment));
|
|
1974
|
+
const inc = incoming[i];
|
|
1975
|
+
if (inc === void 0) return false;
|
|
1976
|
+
if (cur === inc) continue;
|
|
1977
|
+
if ((cur === "*" || cur.startsWith(":") && !OPAQUE_SEGMENT_RE.test(cur)) && CONCRETE_SEGMENT_RE.test(inc)) continue;
|
|
1978
|
+
return false;
|
|
1979
|
+
}
|
|
1980
|
+
return current.length === incoming.length;
|
|
1981
|
+
};
|
|
1982
|
+
function createMatcherFromFind(findRouteRules, canOverride = canOverrideRouteShape) {
|
|
1983
|
+
return (method, pathname) => {
|
|
1984
|
+
const rawLayers = findRouteRules(method, pathname);
|
|
1985
|
+
let altLayers;
|
|
1986
|
+
let hasAltMatch = false;
|
|
1987
|
+
const readings = alternateReadings(pathname);
|
|
1988
|
+
if (readings) {
|
|
1989
|
+
altLayers = [];
|
|
1990
|
+
for (const reading of readings) {
|
|
1991
|
+
const layers = findRouteRules(method, reading);
|
|
1992
|
+
if (layers?.length) hasAltMatch = true;
|
|
1993
|
+
altLayers.push(layers);
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
if (!rawLayers?.length && !hasAltMatch) return {
|
|
1997
|
+
routeRules: {},
|
|
1998
|
+
matchedRules: {},
|
|
1999
|
+
routeRuleMiddleware: []
|
|
2000
|
+
};
|
|
2001
|
+
const matchedRules = mergeMatchedRouteRules(rawLayers, altLayers, canOverride);
|
|
2002
|
+
return {
|
|
2003
|
+
routeRules: toRouteRules(matchedRules),
|
|
2004
|
+
matchedRules,
|
|
2005
|
+
routeRuleMiddleware: buildRouteRuleMiddleware(matchedRules)
|
|
2006
|
+
};
|
|
2007
|
+
};
|
|
2008
|
+
}
|
|
2009
|
+
function toRouteRules(matchedRules) {
|
|
2010
|
+
const routeRules = Object.create(null);
|
|
2011
|
+
for (const name in matchedRules) routeRules[name] = matchedRules[name].options;
|
|
2012
|
+
return routeRules;
|
|
2013
|
+
}
|
|
2014
|
+
function buildRouteRuleMiddleware(matchedRules) {
|
|
2015
|
+
const routeRuleMiddleware = [];
|
|
2016
|
+
const rules = Object.entries(matchedRules);
|
|
2017
|
+
if (rules.length > 1) rules.sort(compareRuleOrder);
|
|
2018
|
+
for (const [, rule] of rules) {
|
|
2019
|
+
if (!rule.handler) continue;
|
|
2020
|
+
routeRuleMiddleware.push(rule.handler.handler(rule));
|
|
2021
|
+
}
|
|
2022
|
+
return routeRuleMiddleware;
|
|
2023
|
+
}
|
|
2024
|
+
function memoizeRouteRulesMatcher(matcher, opts) {
|
|
2025
|
+
const max = opts?.max ?? 1024;
|
|
2026
|
+
if (max <= 0) return matcher;
|
|
2027
|
+
const memo = /* @__PURE__ */ new Map();
|
|
2028
|
+
let hand;
|
|
2029
|
+
const evict = () => {
|
|
2030
|
+
for (;;) {
|
|
2031
|
+
let next = hand?.next();
|
|
2032
|
+
if (!next || next.done) {
|
|
2033
|
+
hand = memo.values();
|
|
2034
|
+
next = hand.next();
|
|
2035
|
+
if (next.done) return;
|
|
2036
|
+
}
|
|
2037
|
+
const entry = next.value;
|
|
2038
|
+
if (entry.visited) entry.visited = false;
|
|
2039
|
+
else {
|
|
2040
|
+
memo.delete(entry.key);
|
|
2041
|
+
return;
|
|
2042
|
+
}
|
|
2043
|
+
}
|
|
2044
|
+
};
|
|
2045
|
+
return (method, pathname) => {
|
|
2046
|
+
const key = method + " " + pathname;
|
|
2047
|
+
const entry = memo.get(key);
|
|
2048
|
+
if (entry) {
|
|
2049
|
+
entry.visited = true;
|
|
2050
|
+
return entry.result;
|
|
2051
|
+
}
|
|
2052
|
+
const result = matcher(method, pathname);
|
|
2053
|
+
if (memo.size >= max) evict();
|
|
2054
|
+
memo.set(key, {
|
|
2055
|
+
key,
|
|
2056
|
+
result,
|
|
2057
|
+
visited: false
|
|
2058
|
+
});
|
|
2059
|
+
return result;
|
|
2060
|
+
};
|
|
2061
|
+
}
|
|
2062
|
+
function alternateReadings(pathname) {
|
|
2063
|
+
const decoded = decodedPath(pathname);
|
|
2064
|
+
if (decoded === pathname && !needsCanonicalPasses(pathname)) return;
|
|
2065
|
+
const readings = [];
|
|
2066
|
+
for (const spelling of decoded === pathname ? [pathname] : [pathname, decoded]) {
|
|
2067
|
+
if (!needsCanonicalPasses(spelling)) {
|
|
2068
|
+
pushReading(readings, pathname, spelling);
|
|
2069
|
+
continue;
|
|
2070
|
+
}
|
|
2071
|
+
const canonical = canonicalPath(spelling);
|
|
2072
|
+
pushReading(readings, pathname, canonical);
|
|
2073
|
+
const merged = mergedCanonicalPath(spelling, canonical);
|
|
2074
|
+
if (merged !== void 0) pushReading(readings, pathname, merged);
|
|
2075
|
+
}
|
|
2076
|
+
return readings.length > 0 ? readings : void 0;
|
|
2077
|
+
}
|
|
2078
|
+
function pushReading(readings, pathname, reading) {
|
|
2079
|
+
if (reading !== pathname && !readings.includes(reading)) readings.push(reading);
|
|
2080
|
+
}
|
|
2081
|
+
var compareRuleOrder = (a, b) => orderWeight(a[1].handler) - orderWeight(b[1].handler) || (a[0] < b[0] ? -1 : 1);
|
|
2082
|
+
function orderWeight(handler) {
|
|
2083
|
+
return handler?.order ?? 0;
|
|
2084
|
+
}
|
|
2085
|
+
//#endregion
|
|
2086
|
+
export { H3Core, HTTPError, NodeResponse, composeMiddleware, createMatcherFromFind, defineHandler, defineLazyEventHandler, headers, memoizeRouteRulesMatcher, serve, toEventHandler, toRequest };
|