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