elit 3.6.6 → 3.6.8
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/Cargo.lock +1 -1
- package/Cargo.toml +1 -1
- package/README.md +20 -1
- package/dist/build.cjs +421 -331
- package/dist/build.d.ts +1 -19
- package/dist/build.js +420 -330
- package/dist/build.mjs +420 -330
- package/dist/chokidar.cjs +219 -182
- package/dist/chokidar.d.ts +25 -10
- package/dist/chokidar.js +217 -182
- package/dist/chokidar.mjs +218 -183
- package/dist/cli.cjs +25197 -22128
- package/dist/cli.d.ts +19 -37
- package/dist/cli.mjs +26668 -23614
- package/dist/config.cjs +357 -350
- package/dist/config.d.ts +17 -245
- package/dist/config.js +520 -515
- package/dist/config.mjs +346 -341
- package/dist/contracts-D7KIS-TK.d.ts +36 -0
- package/dist/contracts-_0p1-15U.d.ts +54 -0
- package/dist/coverage.cjs +448 -485
- package/dist/coverage.d.ts +13 -62
- package/dist/coverage.js +447 -484
- package/dist/coverage.mjs +447 -484
- package/dist/database.cjs +819 -828
- package/dist/database.d.ts +8 -24
- package/dist/database.js +818 -829
- package/dist/database.mjs +818 -829
- package/dist/desktop-auto-render.cjs +1700 -1523
- package/dist/desktop-auto-render.d.ts +4 -12
- package/dist/desktop-auto-render.js +1695 -1518
- package/dist/desktop-auto-render.mjs +1696 -1519
- package/dist/desktop.cjs +3 -1
- package/dist/desktop.d.ts +4 -1
- package/dist/desktop.js +1 -1
- package/dist/desktop.mjs +1 -1
- package/dist/dev-build.cjs +830 -0
- package/dist/dev-build.d.ts +53 -0
- package/dist/dev-build.js +3318 -0
- package/dist/dev-build.mjs +797 -0
- package/dist/dom.cjs +717 -591
- package/dist/dom.d.ts +2 -17
- package/dist/dom.js +714 -588
- package/dist/dom.mjs +716 -590
- package/dist/el.cjs +62 -52
- package/dist/el.d.ts +5 -12
- package/dist/el.js +60 -52
- package/dist/el.mjs +60 -52
- package/dist/fs.cjs +72 -63
- package/dist/fs.d.ts +22 -19
- package/dist/fs.js +71 -62
- package/dist/fs.mjs +71 -62
- package/dist/hmr.cjs +40 -14
- package/dist/hmr.d.ts +11 -23
- package/dist/hmr.js +38 -14
- package/dist/hmr.mjs +38 -14
- package/dist/http.cjs +411 -140
- package/dist/http.d.ts +40 -112
- package/dist/http.js +409 -140
- package/dist/http.mjs +409 -140
- package/dist/https.cjs +716 -272
- package/dist/https.d.ts +46 -41
- package/dist/https.js +712 -270
- package/dist/https.mjs +714 -272
- package/dist/index.cjs +7502 -7691
- package/dist/index.d.ts +6 -3
- package/dist/index.js +7486 -7677
- package/dist/index.mjs +7497 -7687
- package/dist/mime-types.cjs +10 -4
- package/dist/mime-types.d.ts +8 -11
- package/dist/mime-types.js +9 -3
- package/dist/mime-types.mjs +9 -3
- package/dist/native.cjs +8616 -8870
- package/dist/native.d.ts +7 -10
- package/dist/native.js +8682 -8936
- package/dist/native.mjs +8615 -8869
- package/dist/path.cjs +83 -77
- package/dist/path.d.ts +29 -29
- package/dist/path.js +82 -76
- package/dist/path.mjs +82 -76
- package/dist/pm-node-shared-listener-bootstrap.cjs +75 -0
- package/dist/pm.cjs +5267 -0
- package/dist/pm.d.ts +331 -0
- package/dist/pm.js +7575 -0
- package/dist/pm.mjs +5148 -0
- package/dist/preview-build.cjs +712 -0
- package/dist/preview-build.d.ts +59 -0
- package/dist/preview-build.js +3194 -0
- package/dist/preview-build.mjs +676 -0
- package/dist/render-context.cjs +13 -2
- package/dist/render-context.d.ts +9 -34
- package/dist/render-context.js +11 -2
- package/dist/render-context.mjs +11 -2
- package/dist/router.cjs +787 -646
- package/dist/router.d.ts +8 -14
- package/dist/router.js +786 -645
- package/dist/router.mjs +786 -645
- package/dist/runtime.cjs +1 -1
- package/dist/runtime.js +1 -1
- package/dist/runtime.mjs +1 -1
- package/dist/server.cjs +3702 -2883
- package/dist/server.d.ts +47 -5
- package/dist/server.js +4007 -3165
- package/dist/server.mjs +3665 -2848
- package/dist/smtp-server.cjs +16 -3
- package/dist/smtp-server.d.ts +12 -26
- package/dist/smtp-server.js +55 -17
- package/dist/smtp-server.mjs +16 -3
- package/dist/state.cjs +768 -659
- package/dist/state.d.ts +11 -71
- package/dist/state.js +760 -651
- package/dist/state.mjs +767 -658
- package/dist/style.cjs +1011 -968
- package/dist/style.d.ts +13 -127
- package/dist/style.js +1009 -970
- package/dist/style.mjs +1011 -971
- package/dist/test-reporter.cjs +332 -316
- package/dist/test-reporter.d.ts +28 -33
- package/dist/test-reporter.js +328 -312
- package/dist/test-reporter.mjs +328 -312
- package/dist/test-runtime.cjs +927 -968
- package/dist/test-runtime.d.ts +24 -99
- package/dist/test-runtime.js +922 -965
- package/dist/test-runtime.mjs +922 -965
- package/dist/test.cjs +4428 -4273
- package/dist/test.d.ts +2 -8
- package/dist/test.js +4307 -4154
- package/dist/test.mjs +4419 -4267
- package/dist/types-BONVzPtp.d.ts +59 -0
- package/dist/types-BR4wMiVx.d.ts +32 -0
- package/dist/types-BayMVo_k.d.ts +278 -0
- package/dist/types-C4gKykuG.d.ts +23 -0
- package/dist/types-C70T-42Z.d.ts +64 -0
- package/dist/types-Ckj8md_j.d.ts +84 -0
- package/dist/types-CpjQTAkX.d.ts +24 -0
- package/dist/types-D0LjrYjS.d.ts +14 -0
- package/dist/types-DPOgoGs-.d.ts +81 -0
- package/dist/types-fiLday0L.d.ts +199 -0
- package/dist/types.d.ts +54 -237
- package/dist/universal.cjs +1 -1
- package/dist/universal.d.ts +1 -7
- package/dist/universal.js +1 -1
- package/dist/universal.mjs +1 -1
- package/dist/websocket-BLBEAnhp.d.ts +119 -0
- package/dist/ws.cjs +129 -108
- package/dist/ws.d.ts +21 -131
- package/dist/ws.js +128 -109
- package/dist/ws.mjs +128 -109
- package/dist/wss.cjs +938 -512
- package/dist/wss.d.ts +31 -28
- package/dist/wss.js +932 -508
- package/dist/wss.mjs +936 -512
- package/package.json +18 -6
- package/vendor/epaint-0.31.1/src/image.rs +418 -0
- package/dist/server-uMQvZAll.d.ts +0 -458
package/dist/http.js
CHANGED
|
@@ -7,23 +7,88 @@
|
|
|
7
7
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
8
8
|
});
|
|
9
9
|
|
|
10
|
-
// src/http.ts
|
|
11
|
-
var
|
|
10
|
+
// src/server/http/agent.ts
|
|
11
|
+
var Agent = class {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.options = options;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
12
16
|
|
|
13
|
-
// src/
|
|
14
|
-
var
|
|
15
|
-
if (typeof Deno !== "undefined") return "deno";
|
|
16
|
-
if (typeof Bun !== "undefined") return "bun";
|
|
17
|
-
return "node";
|
|
18
|
-
})();
|
|
19
|
-
var isNode = runtime === "node";
|
|
20
|
-
var isBun = runtime === "bun";
|
|
21
|
-
var isDeno = runtime === "deno";
|
|
17
|
+
// src/server/http/client-request.ts
|
|
18
|
+
var import_node_events = __require("events");
|
|
22
19
|
|
|
23
|
-
// src/http.ts
|
|
20
|
+
// src/server/http/utils.ts
|
|
24
21
|
function queueCallback(callback) {
|
|
25
22
|
if (callback) queueMicrotask(callback);
|
|
26
23
|
}
|
|
24
|
+
function getRequestPath(url) {
|
|
25
|
+
if (!url) return "";
|
|
26
|
+
try {
|
|
27
|
+
const urlObj = new URL(url);
|
|
28
|
+
return urlObj.pathname + urlObj.search;
|
|
29
|
+
} catch {
|
|
30
|
+
return url;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function headersToRecord(headers) {
|
|
34
|
+
const result = /* @__PURE__ */ Object.create(null);
|
|
35
|
+
headers.forEach((value, key) => {
|
|
36
|
+
result[key] = value;
|
|
37
|
+
});
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
function headersToRawHeaders(headers) {
|
|
41
|
+
const rawHeaders = [];
|
|
42
|
+
headers.forEach((value, key) => {
|
|
43
|
+
rawHeaders.push(key, value);
|
|
44
|
+
});
|
|
45
|
+
return rawHeaders;
|
|
46
|
+
}
|
|
47
|
+
function normalizeRequestBodyChunk(chunk, encoding = "utf8") {
|
|
48
|
+
if (typeof chunk === "string") {
|
|
49
|
+
if (encoding !== "utf8" && typeof Buffer !== "undefined") {
|
|
50
|
+
return Buffer.from(chunk, encoding);
|
|
51
|
+
}
|
|
52
|
+
return chunk;
|
|
53
|
+
}
|
|
54
|
+
if (chunk instanceof Uint8Array) {
|
|
55
|
+
return chunk;
|
|
56
|
+
}
|
|
57
|
+
if (chunk instanceof ArrayBuffer) {
|
|
58
|
+
return new Uint8Array(chunk);
|
|
59
|
+
}
|
|
60
|
+
if (ArrayBuffer.isView(chunk)) {
|
|
61
|
+
return new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength);
|
|
62
|
+
}
|
|
63
|
+
return new TextEncoder().encode(String(chunk));
|
|
64
|
+
}
|
|
65
|
+
function buildRequestBody(chunks) {
|
|
66
|
+
if (chunks.length === 0) {
|
|
67
|
+
return void 0;
|
|
68
|
+
}
|
|
69
|
+
if (chunks.length === 1) {
|
|
70
|
+
return chunks[0];
|
|
71
|
+
}
|
|
72
|
+
if (chunks.every((chunk) => typeof chunk === "string")) {
|
|
73
|
+
return chunks.join("");
|
|
74
|
+
}
|
|
75
|
+
const encoder = new TextEncoder();
|
|
76
|
+
const bodyParts = chunks.map((chunk) => typeof chunk === "string" ? encoder.encode(chunk) : chunk);
|
|
77
|
+
const totalLength = bodyParts.reduce((sum, part) => sum + part.byteLength, 0);
|
|
78
|
+
const body = new Uint8Array(totalLength);
|
|
79
|
+
let offset = 0;
|
|
80
|
+
for (const part of bodyParts) {
|
|
81
|
+
body.set(part, offset);
|
|
82
|
+
offset += part.byteLength;
|
|
83
|
+
}
|
|
84
|
+
return body;
|
|
85
|
+
}
|
|
86
|
+
function isFetchResponse(value) {
|
|
87
|
+
return typeof value?.status === "number" && typeof value?.statusText === "string" && typeof value?.headers?.forEach === "function";
|
|
88
|
+
}
|
|
89
|
+
function isNodeIncomingMessage(value) {
|
|
90
|
+
return typeof value?.on === "function" && typeof value?.headers === "object" && (typeof value?.httpVersion === "string" || value?.socket !== void 0);
|
|
91
|
+
}
|
|
27
92
|
function headersToInit(headers) {
|
|
28
93
|
const result = {};
|
|
29
94
|
for (const key in headers) {
|
|
@@ -48,17 +113,73 @@
|
|
|
48
113
|
server.emit("close");
|
|
49
114
|
if (callback) queueMicrotask(() => callback());
|
|
50
115
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
http = __require("http");
|
|
59
|
-
https = __require("https");
|
|
116
|
+
|
|
117
|
+
// src/server/http/client-request.ts
|
|
118
|
+
var ClientRequest = class extends import_node_events.EventEmitter {
|
|
119
|
+
constructor(_url, _options = {}) {
|
|
120
|
+
super();
|
|
121
|
+
this._bodyChunks = [];
|
|
122
|
+
this._ended = false;
|
|
60
123
|
}
|
|
61
|
-
|
|
124
|
+
_setNativeRequest(nativeRequest) {
|
|
125
|
+
this._nativeRequest = nativeRequest;
|
|
126
|
+
}
|
|
127
|
+
_setExecutor(executor) {
|
|
128
|
+
this._executor = executor;
|
|
129
|
+
}
|
|
130
|
+
write(chunk, encoding, callback) {
|
|
131
|
+
if (this._ended) {
|
|
132
|
+
throw new Error("Cannot write after end");
|
|
133
|
+
}
|
|
134
|
+
if (typeof encoding === "function") {
|
|
135
|
+
callback = encoding;
|
|
136
|
+
encoding = void 0;
|
|
137
|
+
}
|
|
138
|
+
if (this._nativeRequest) {
|
|
139
|
+
const actualEncoding2 = typeof encoding === "string" ? encoding : void 0;
|
|
140
|
+
return this._nativeRequest.write(chunk, actualEncoding2, callback);
|
|
141
|
+
}
|
|
142
|
+
const actualEncoding = typeof encoding === "string" ? encoding : "utf8";
|
|
143
|
+
this._bodyChunks.push(normalizeRequestBodyChunk(chunk, actualEncoding));
|
|
144
|
+
queueCallback(callback);
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
end(chunk, encoding, callback) {
|
|
148
|
+
if (typeof chunk === "function") {
|
|
149
|
+
callback = chunk;
|
|
150
|
+
chunk = void 0;
|
|
151
|
+
encoding = void 0;
|
|
152
|
+
} else if (typeof encoding === "function") {
|
|
153
|
+
callback = encoding;
|
|
154
|
+
encoding = void 0;
|
|
155
|
+
}
|
|
156
|
+
if (this._ended) {
|
|
157
|
+
queueCallback(callback);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
this._ended = true;
|
|
161
|
+
if (this._nativeRequest) {
|
|
162
|
+
const actualEncoding = typeof encoding === "string" ? encoding : void 0;
|
|
163
|
+
if (chunk !== void 0) {
|
|
164
|
+
this._nativeRequest.end(chunk, actualEncoding, callback);
|
|
165
|
+
} else {
|
|
166
|
+
this._nativeRequest.end(callback);
|
|
167
|
+
}
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (chunk !== void 0) {
|
|
171
|
+
this._bodyChunks.push(normalizeRequestBodyChunk(chunk, typeof encoding === "string" ? encoding : "utf8"));
|
|
172
|
+
}
|
|
173
|
+
const executor = this._executor;
|
|
174
|
+
const body = buildRequestBody(this._bodyChunks);
|
|
175
|
+
if (executor) {
|
|
176
|
+
Promise.resolve().then(() => executor(body)).catch((error) => this.emit("error", error));
|
|
177
|
+
}
|
|
178
|
+
queueCallback(callback);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
// src/server/http/constants.ts
|
|
62
183
|
var METHODS = [
|
|
63
184
|
"GET",
|
|
64
185
|
"POST",
|
|
@@ -126,13 +247,23 @@
|
|
|
126
247
|
510: "Not Extended",
|
|
127
248
|
511: "Network Authentication Required"
|
|
128
249
|
};
|
|
129
|
-
|
|
130
|
-
|
|
250
|
+
|
|
251
|
+
// src/server/http/incoming-message.ts
|
|
252
|
+
var import_node_events2 = __require("events");
|
|
253
|
+
var IncomingMessage = class extends import_node_events2.EventEmitter {
|
|
254
|
+
constructor(req, requestMethod) {
|
|
131
255
|
super();
|
|
132
256
|
this.httpVersion = "1.1";
|
|
133
257
|
this.rawHeaders = [];
|
|
134
258
|
this._req = req;
|
|
135
|
-
if (
|
|
259
|
+
if (isFetchResponse(req)) {
|
|
260
|
+
this.method = requestMethod || "GET";
|
|
261
|
+
this.url = getRequestPath(req.url);
|
|
262
|
+
this.headers = headersToRecord(req.headers);
|
|
263
|
+
this.statusCode = req.status;
|
|
264
|
+
this.statusMessage = req.statusText;
|
|
265
|
+
this.rawHeaders = headersToRawHeaders(req.headers);
|
|
266
|
+
} else if (isNodeIncomingMessage(req)) {
|
|
136
267
|
this.method = req.method;
|
|
137
268
|
this.url = req.url;
|
|
138
269
|
this.headers = req.headers;
|
|
@@ -143,14 +274,13 @@
|
|
|
143
274
|
this.socket = req.socket;
|
|
144
275
|
} else {
|
|
145
276
|
this.method = req.method;
|
|
146
|
-
|
|
147
|
-
this.
|
|
148
|
-
this.
|
|
149
|
-
this.rawHeaders = [];
|
|
277
|
+
this.url = getRequestPath(req.url);
|
|
278
|
+
this.headers = headersToRecord(req.headers);
|
|
279
|
+
this.rawHeaders = headersToRawHeaders(req.headers);
|
|
150
280
|
}
|
|
151
281
|
}
|
|
152
282
|
async text() {
|
|
153
|
-
if (
|
|
283
|
+
if (isNodeIncomingMessage(this._req)) {
|
|
154
284
|
return new Promise((resolve, reject) => {
|
|
155
285
|
const chunks = [];
|
|
156
286
|
this._req.on("data", (chunk) => chunks.push(chunk));
|
|
@@ -161,14 +291,80 @@
|
|
|
161
291
|
return this._req.text();
|
|
162
292
|
}
|
|
163
293
|
async json() {
|
|
164
|
-
if (
|
|
294
|
+
if (isNodeIncomingMessage(this._req)) {
|
|
165
295
|
const text = await this.text();
|
|
166
296
|
return JSON.parse(text);
|
|
167
297
|
}
|
|
168
298
|
return this._req.json();
|
|
169
299
|
}
|
|
170
300
|
};
|
|
171
|
-
|
|
301
|
+
|
|
302
|
+
// src/shares/runtime.ts
|
|
303
|
+
var runtime = (() => {
|
|
304
|
+
if (typeof Deno !== "undefined") return "deno";
|
|
305
|
+
if (typeof Bun !== "undefined") return "bun";
|
|
306
|
+
return "node";
|
|
307
|
+
})();
|
|
308
|
+
var isNode = runtime === "node";
|
|
309
|
+
var isBun = runtime === "bun";
|
|
310
|
+
var isDeno = runtime === "deno";
|
|
311
|
+
|
|
312
|
+
// src/server/http/node-modules.ts
|
|
313
|
+
var http;
|
|
314
|
+
var https;
|
|
315
|
+
if (isNode && typeof process !== "undefined") {
|
|
316
|
+
try {
|
|
317
|
+
http = __require("http");
|
|
318
|
+
https = __require("https");
|
|
319
|
+
} catch {
|
|
320
|
+
http = __require("http");
|
|
321
|
+
https = __require("https");
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// src/server/http/request-api.ts
|
|
326
|
+
function request(url, options, callback) {
|
|
327
|
+
const urlString = typeof url === "string" ? url : url.toString();
|
|
328
|
+
const req = new ClientRequest(urlString, options);
|
|
329
|
+
if (isNode) {
|
|
330
|
+
const urlObj = new URL(urlString);
|
|
331
|
+
const client = urlObj.protocol === "https:" ? https : http;
|
|
332
|
+
const nodeReq = client.request(urlString, {
|
|
333
|
+
method: options?.method || "GET",
|
|
334
|
+
headers: options?.headers,
|
|
335
|
+
timeout: options?.timeout,
|
|
336
|
+
signal: options?.signal
|
|
337
|
+
}, (res) => {
|
|
338
|
+
const incomingMessage = new IncomingMessage(res);
|
|
339
|
+
if (callback) callback(incomingMessage);
|
|
340
|
+
req.emit("response", incomingMessage);
|
|
341
|
+
});
|
|
342
|
+
req._setNativeRequest(nodeReq);
|
|
343
|
+
nodeReq.on("error", (error) => req.emit("error", error));
|
|
344
|
+
} else {
|
|
345
|
+
req._setExecutor(async (body) => {
|
|
346
|
+
const response = await fetch(urlString, {
|
|
347
|
+
method: options?.method || "GET",
|
|
348
|
+
headers: options?.headers,
|
|
349
|
+
body,
|
|
350
|
+
signal: options?.signal
|
|
351
|
+
});
|
|
352
|
+
const incomingMessage = new IncomingMessage(response, options?.method || "GET");
|
|
353
|
+
if (callback) callback(incomingMessage);
|
|
354
|
+
req.emit("response", incomingMessage);
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
return req;
|
|
358
|
+
}
|
|
359
|
+
function get(url, options, callback) {
|
|
360
|
+
const req = request(url, { ...options, method: "GET" }, callback);
|
|
361
|
+
req.end();
|
|
362
|
+
return req;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// src/server/http/response.ts
|
|
366
|
+
var import_node_events3 = __require("events");
|
|
367
|
+
var ServerResponse = class extends import_node_events3.EventEmitter {
|
|
172
368
|
constructor(_req, nodeRes) {
|
|
173
369
|
super();
|
|
174
370
|
this.statusCode = 200;
|
|
@@ -301,7 +497,6 @@
|
|
|
301
497
|
_setResolver(resolve) {
|
|
302
498
|
this._resolve = resolve;
|
|
303
499
|
}
|
|
304
|
-
// Express.js-like methods
|
|
305
500
|
json(data, statusCode = 200) {
|
|
306
501
|
if (!this.headersSent) {
|
|
307
502
|
this.setHeader("Content-Type", "application/json");
|
|
@@ -325,7 +520,15 @@
|
|
|
325
520
|
return this;
|
|
326
521
|
}
|
|
327
522
|
};
|
|
328
|
-
|
|
523
|
+
|
|
524
|
+
// src/server/http/runtime.ts
|
|
525
|
+
function getRuntime() {
|
|
526
|
+
return runtime;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
// src/server/http/server-runtime.ts
|
|
530
|
+
var import_node_events4 = __require("events");
|
|
531
|
+
var Server = class extends import_node_events4.EventEmitter {
|
|
329
532
|
constructor(requestListener) {
|
|
330
533
|
super();
|
|
331
534
|
this._bunWebSocketServers = /* @__PURE__ */ new Set();
|
|
@@ -338,9 +541,28 @@
|
|
|
338
541
|
unregisterWebSocketServer(wsServer) {
|
|
339
542
|
this._bunWebSocketServers.delete(wsServer);
|
|
340
543
|
}
|
|
544
|
+
resolvePmInheritedFd(explicitPort, explicitFd) {
|
|
545
|
+
if (typeof explicitFd === "number" && Number.isInteger(explicitFd) && explicitFd >= 0) {
|
|
546
|
+
return explicitFd;
|
|
547
|
+
}
|
|
548
|
+
const fdValue = process.env.ELIT_PM_LISTEN_FD;
|
|
549
|
+
if (!fdValue) {
|
|
550
|
+
return void 0;
|
|
551
|
+
}
|
|
552
|
+
const parsedFd = Number.parseInt(fdValue, 10);
|
|
553
|
+
if (!Number.isInteger(parsedFd) || parsedFd < 0) {
|
|
554
|
+
return void 0;
|
|
555
|
+
}
|
|
556
|
+
const publicPort = Number.parseInt(process.env.ELIT_PM_PUBLIC_PORT ?? process.env.ELIT_PM_PORT ?? "", 10);
|
|
557
|
+
if (Number.isInteger(explicitPort) && Number.isInteger(publicPort) && explicitPort !== publicPort) {
|
|
558
|
+
return void 0;
|
|
559
|
+
}
|
|
560
|
+
return parsedFd;
|
|
561
|
+
}
|
|
341
562
|
listen(...args) {
|
|
342
563
|
let port = 3e3;
|
|
343
564
|
let hostname = "0.0.0.0";
|
|
565
|
+
let fd;
|
|
344
566
|
let callback;
|
|
345
567
|
const firstArg = args[0];
|
|
346
568
|
if (typeof firstArg === "number") {
|
|
@@ -355,8 +577,10 @@
|
|
|
355
577
|
} else if (firstArg && typeof firstArg === "object") {
|
|
356
578
|
port = firstArg.port || 3e3;
|
|
357
579
|
hostname = firstArg.hostname || "0.0.0.0";
|
|
580
|
+
fd = typeof firstArg.fd === "number" ? firstArg.fd : void 0;
|
|
358
581
|
callback = args[1];
|
|
359
582
|
}
|
|
583
|
+
fd = this.resolvePmInheritedFd(firstArg && typeof firstArg === "object" ? firstArg.port : port, fd);
|
|
360
584
|
const self = this;
|
|
361
585
|
if (isNode) {
|
|
362
586
|
this.nativeServer = http.createServer((req, res) => {
|
|
@@ -371,11 +595,19 @@
|
|
|
371
595
|
this.nativeServer.on("upgrade", (req, socket, head) => {
|
|
372
596
|
self.emit("upgrade", req, socket, head);
|
|
373
597
|
});
|
|
374
|
-
|
|
375
|
-
this.
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
598
|
+
if (fd !== void 0) {
|
|
599
|
+
this.nativeServer.listen({ fd, exclusive: false }, () => {
|
|
600
|
+
this._listening = true;
|
|
601
|
+
this.emit("listening");
|
|
602
|
+
if (callback) callback();
|
|
603
|
+
});
|
|
604
|
+
} else {
|
|
605
|
+
this.nativeServer.listen(port, hostname, () => {
|
|
606
|
+
this._listening = true;
|
|
607
|
+
this.emit("listening");
|
|
608
|
+
if (callback) callback();
|
|
609
|
+
});
|
|
610
|
+
}
|
|
379
611
|
this.nativeServer.on("error", (err) => this.emit("error", err));
|
|
380
612
|
this.nativeServer.on("close", () => {
|
|
381
613
|
this._listening = false;
|
|
@@ -400,6 +632,8 @@
|
|
|
400
632
|
const urlObj = new URL(req.url);
|
|
401
633
|
const pathname = urlObj.pathname;
|
|
402
634
|
const requestUrl = urlObj.pathname + urlObj.search;
|
|
635
|
+
const incomingHeaders = headersToRecord(req.headers);
|
|
636
|
+
const rawHeaders = headersToRawHeaders(req.headers);
|
|
403
637
|
const upgradeHeader = req.headers.get("upgrade");
|
|
404
638
|
if (upgradeHeader && upgradeHeader.toLowerCase() === "websocket") {
|
|
405
639
|
const matchingWebSocketServer = Array.from(this._bunWebSocketServers).find((wsServer) => {
|
|
@@ -436,9 +670,9 @@
|
|
|
436
670
|
const incomingMessage = {
|
|
437
671
|
method: req.method,
|
|
438
672
|
url: requestUrl,
|
|
439
|
-
headers:
|
|
673
|
+
headers: incomingHeaders,
|
|
440
674
|
httpVersion: "1.1",
|
|
441
|
-
rawHeaders
|
|
675
|
+
rawHeaders,
|
|
442
676
|
_req: req,
|
|
443
677
|
text: () => req.text(),
|
|
444
678
|
json: () => req.json()
|
|
@@ -492,57 +726,148 @@
|
|
|
492
726
|
this.writeHead(statusCode);
|
|
493
727
|
}
|
|
494
728
|
responseReady = true;
|
|
495
|
-
return this;
|
|
496
729
|
}
|
|
497
730
|
};
|
|
498
731
|
if (self.requestListener) {
|
|
499
732
|
self.requestListener(incomingMessage, serverResponse);
|
|
733
|
+
} else {
|
|
734
|
+
self.emit("request", incomingMessage, serverResponse);
|
|
500
735
|
}
|
|
501
|
-
if (responseReady) {
|
|
502
|
-
|
|
503
|
-
status: statusCode,
|
|
504
|
-
statusText: statusMessage,
|
|
505
|
-
headers
|
|
506
|
-
});
|
|
736
|
+
if (!responseReady) {
|
|
737
|
+
serverResponse.end();
|
|
507
738
|
}
|
|
508
|
-
return new
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
}
|
|
513
|
-
resolve(new Response(body, {
|
|
514
|
-
status: statusCode,
|
|
515
|
-
statusText: statusMessage,
|
|
516
|
-
headers
|
|
517
|
-
}));
|
|
518
|
-
};
|
|
739
|
+
return new Response(body, {
|
|
740
|
+
status: statusCode,
|
|
741
|
+
statusText: statusMessage,
|
|
742
|
+
headers
|
|
519
743
|
});
|
|
520
744
|
},
|
|
521
|
-
error:
|
|
745
|
+
error: (err) => {
|
|
746
|
+
this.emit("error", err);
|
|
747
|
+
return createErrorResponse();
|
|
748
|
+
}
|
|
522
749
|
});
|
|
750
|
+
this._listening = true;
|
|
523
751
|
emitListeningWithCallback(this, callback);
|
|
752
|
+
this.nativeServer.stop = this.nativeServer.stop || this.nativeServer.close;
|
|
753
|
+
this.nativeServer.close = this.nativeServer.close || this.nativeServer.stop;
|
|
754
|
+
this.nativeServer.on?.("close", () => {
|
|
755
|
+
this._listening = false;
|
|
756
|
+
this.emit("close");
|
|
757
|
+
});
|
|
524
758
|
} else if (isDeno) {
|
|
759
|
+
const server = this;
|
|
525
760
|
this.nativeServer = Deno.serve({
|
|
526
761
|
port,
|
|
527
|
-
hostname
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
762
|
+
hostname
|
|
763
|
+
}, async (req) => {
|
|
764
|
+
const urlObj = new URL(req.url);
|
|
765
|
+
const requestUrl = urlObj.pathname + urlObj.search;
|
|
766
|
+
const incomingHeaders = headersToRecord(req.headers);
|
|
767
|
+
const rawHeaders = headersToRawHeaders(req.headers);
|
|
768
|
+
const bodyChunks = [];
|
|
769
|
+
const responseHeaders = new Headers();
|
|
770
|
+
let statusCode = 200;
|
|
771
|
+
let statusText = "OK";
|
|
772
|
+
let responseClosed = false;
|
|
773
|
+
const incomingMessage = {
|
|
774
|
+
method: req.method,
|
|
775
|
+
url: requestUrl,
|
|
776
|
+
headers: incomingHeaders,
|
|
777
|
+
httpVersion: "1.1",
|
|
778
|
+
rawHeaders,
|
|
779
|
+
_req: req,
|
|
780
|
+
text: () => req.text(),
|
|
781
|
+
json: () => req.json()
|
|
782
|
+
};
|
|
783
|
+
const serverResponse = {
|
|
784
|
+
statusCode: 200,
|
|
785
|
+
statusMessage: "OK",
|
|
786
|
+
headersSent: false,
|
|
787
|
+
setHeader(name, value) {
|
|
788
|
+
responseHeaders.set(name, Array.isArray(value) ? value.join(", ") : String(value));
|
|
789
|
+
return this;
|
|
790
|
+
},
|
|
791
|
+
getHeader(name) {
|
|
792
|
+
return responseHeaders.get(name) ?? void 0;
|
|
793
|
+
},
|
|
794
|
+
getHeaders() {
|
|
795
|
+
const headers = {};
|
|
796
|
+
responseHeaders.forEach((value, key) => {
|
|
797
|
+
headers[key] = value;
|
|
798
|
+
});
|
|
799
|
+
return headers;
|
|
800
|
+
},
|
|
801
|
+
writeHead(status, arg2, arg3) {
|
|
802
|
+
statusCode = status;
|
|
803
|
+
this.statusCode = status;
|
|
804
|
+
this.headersSent = true;
|
|
805
|
+
if (typeof arg2 === "string") {
|
|
806
|
+
statusText = arg2;
|
|
807
|
+
this.statusMessage = arg2;
|
|
808
|
+
if (arg3) {
|
|
809
|
+
Object.entries(arg3).forEach(([key, value]) => {
|
|
810
|
+
responseHeaders.set(key, Array.isArray(value) ? value.join(", ") : String(value));
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
} else if (arg2) {
|
|
814
|
+
Object.entries(arg2).forEach(([key, value]) => {
|
|
815
|
+
responseHeaders.set(key, Array.isArray(value) ? value.join(", ") : String(value));
|
|
816
|
+
});
|
|
537
817
|
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
818
|
+
return this;
|
|
819
|
+
},
|
|
820
|
+
write(chunk) {
|
|
821
|
+
if (!this.headersSent) {
|
|
822
|
+
this.writeHead(statusCode);
|
|
823
|
+
}
|
|
824
|
+
if (typeof chunk === "string") {
|
|
825
|
+
bodyChunks.push(new TextEncoder().encode(chunk));
|
|
826
|
+
} else if (chunk instanceof Uint8Array) {
|
|
827
|
+
bodyChunks.push(chunk);
|
|
828
|
+
} else if (chunk !== void 0 && chunk !== null) {
|
|
829
|
+
bodyChunks.push(new TextEncoder().encode(String(chunk)));
|
|
830
|
+
}
|
|
831
|
+
return true;
|
|
832
|
+
},
|
|
833
|
+
end(chunk) {
|
|
834
|
+
if (chunk !== void 0) {
|
|
835
|
+
this.write(chunk);
|
|
836
|
+
}
|
|
837
|
+
if (!this.headersSent) {
|
|
838
|
+
this.writeHead(statusCode);
|
|
839
|
+
}
|
|
840
|
+
responseClosed = true;
|
|
841
|
+
}
|
|
842
|
+
};
|
|
843
|
+
if (server.requestListener) {
|
|
844
|
+
server.requestListener(incomingMessage, serverResponse);
|
|
845
|
+
} else {
|
|
846
|
+
server.emit("request", incomingMessage, serverResponse);
|
|
847
|
+
}
|
|
848
|
+
if (!responseClosed) {
|
|
849
|
+
serverResponse.end();
|
|
543
850
|
}
|
|
851
|
+
const body = bodyChunks.length === 0 ? void 0 : (() => {
|
|
852
|
+
const totalLength = bodyChunks.reduce((sum, chunk) => sum + chunk.length, 0);
|
|
853
|
+
const output = new ArrayBuffer(totalLength);
|
|
854
|
+
const combined = new Uint8Array(output);
|
|
855
|
+
let offset = 0;
|
|
856
|
+
for (const chunk of bodyChunks) {
|
|
857
|
+
combined.set(chunk, offset);
|
|
858
|
+
offset += chunk.length;
|
|
859
|
+
}
|
|
860
|
+
return output;
|
|
861
|
+
})();
|
|
862
|
+
return new Response(body, {
|
|
863
|
+
status: statusCode,
|
|
864
|
+
statusText,
|
|
865
|
+
headers: responseHeaders
|
|
866
|
+
});
|
|
544
867
|
});
|
|
868
|
+
this._listening = true;
|
|
545
869
|
emitListeningWithCallback(this, callback);
|
|
870
|
+
this.nativeServer.finished.then(() => closeAndEmit(this)).catch((err) => this.emit("error", err));
|
|
546
871
|
}
|
|
547
872
|
return this;
|
|
548
873
|
}
|
|
@@ -571,9 +896,11 @@
|
|
|
571
896
|
return createAddress(0, addr, "unix");
|
|
572
897
|
}
|
|
573
898
|
return addr;
|
|
574
|
-
}
|
|
899
|
+
}
|
|
900
|
+
if (isBun) {
|
|
575
901
|
return createAddress(this.nativeServer.port, this.nativeServer.hostname);
|
|
576
|
-
}
|
|
902
|
+
}
|
|
903
|
+
if (isDeno) {
|
|
577
904
|
const addr = this.nativeServer.addr;
|
|
578
905
|
return createAddress(addr.port, addr.hostname);
|
|
579
906
|
}
|
|
@@ -583,70 +910,12 @@
|
|
|
583
910
|
return this._listening;
|
|
584
911
|
}
|
|
585
912
|
};
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
}
|
|
590
|
-
write(_chunk) {
|
|
591
|
-
return true;
|
|
592
|
-
}
|
|
593
|
-
end(callback) {
|
|
594
|
-
queueCallback(callback);
|
|
595
|
-
}
|
|
596
|
-
};
|
|
597
|
-
var Agent = class {
|
|
598
|
-
constructor(options) {
|
|
599
|
-
this.options = options;
|
|
600
|
-
}
|
|
601
|
-
};
|
|
602
|
-
function createServer(optionsOrListener, requestListener) {
|
|
603
|
-
return new Server(typeof optionsOrListener === "function" ? optionsOrListener : requestListener);
|
|
604
|
-
}
|
|
605
|
-
function request(url, options, callback) {
|
|
606
|
-
const urlString = typeof url === "string" ? url : url.toString();
|
|
607
|
-
const req = new ClientRequest(urlString, options);
|
|
608
|
-
if (isNode) {
|
|
609
|
-
const urlObj = new URL(urlString);
|
|
610
|
-
const client = urlObj.protocol === "https:" ? https : http;
|
|
611
|
-
const nodeReq = client.request(urlString, {
|
|
612
|
-
method: options?.method || "GET",
|
|
613
|
-
headers: options?.headers,
|
|
614
|
-
timeout: options?.timeout,
|
|
615
|
-
signal: options?.signal
|
|
616
|
-
}, (res) => {
|
|
617
|
-
const incomingMessage = new IncomingMessage(res);
|
|
618
|
-
if (callback) callback(incomingMessage);
|
|
619
|
-
req.emit("response", incomingMessage);
|
|
620
|
-
});
|
|
621
|
-
nodeReq.on("error", (error) => req.emit("error", error));
|
|
622
|
-
nodeReq.end();
|
|
623
|
-
} else {
|
|
624
|
-
queueMicrotask(async () => {
|
|
625
|
-
try {
|
|
626
|
-
const response = await fetch(urlString, {
|
|
627
|
-
method: options?.method || "GET",
|
|
628
|
-
headers: options?.headers,
|
|
629
|
-
signal: options?.signal
|
|
630
|
-
});
|
|
631
|
-
const fetchRequest = new Request(urlString);
|
|
632
|
-
const incomingMessage = new IncomingMessage(fetchRequest);
|
|
633
|
-
incomingMessage.statusCode = response.status;
|
|
634
|
-
incomingMessage.statusMessage = response.statusText;
|
|
635
|
-
if (callback) callback(incomingMessage);
|
|
636
|
-
req.emit("response", incomingMessage);
|
|
637
|
-
} catch (error) {
|
|
638
|
-
req.emit("error", error);
|
|
639
|
-
}
|
|
640
|
-
});
|
|
641
|
-
}
|
|
642
|
-
return req;
|
|
643
|
-
}
|
|
644
|
-
function get(url, options, callback) {
|
|
645
|
-
return request(url, { ...options, method: "GET" }, callback);
|
|
646
|
-
}
|
|
647
|
-
function getRuntime() {
|
|
648
|
-
return runtime;
|
|
913
|
+
function createServer(arg1, arg2) {
|
|
914
|
+
const requestListener = typeof arg1 === "function" ? arg1 : arg2;
|
|
915
|
+
return new Server(requestListener);
|
|
649
916
|
}
|
|
917
|
+
|
|
918
|
+
// src/server/http/index.ts
|
|
650
919
|
var http_default = {
|
|
651
920
|
createServer,
|
|
652
921
|
request,
|