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.cjs
CHANGED
|
@@ -17,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
|
-
// src/http.ts
|
|
20
|
+
// src/server/http/index.ts
|
|
21
21
|
var http_exports = {};
|
|
22
22
|
__export(http_exports, {
|
|
23
23
|
Agent: () => Agent,
|
|
@@ -34,22 +34,89 @@ __export(http_exports, {
|
|
|
34
34
|
request: () => request
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(http_exports);
|
|
37
|
-
var import_node_events = require("events");
|
|
38
37
|
|
|
39
|
-
// src/
|
|
40
|
-
var
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
var isNode = runtime === "node";
|
|
46
|
-
var isBun = runtime === "bun";
|
|
47
|
-
var isDeno = runtime === "deno";
|
|
38
|
+
// src/server/http/agent.ts
|
|
39
|
+
var Agent = class {
|
|
40
|
+
constructor(options) {
|
|
41
|
+
this.options = options;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
48
44
|
|
|
49
|
-
// src/http.ts
|
|
45
|
+
// src/server/http/client-request.ts
|
|
46
|
+
var import_node_events = require("events");
|
|
47
|
+
|
|
48
|
+
// src/server/http/utils.ts
|
|
50
49
|
function queueCallback(callback) {
|
|
51
50
|
if (callback) queueMicrotask(callback);
|
|
52
51
|
}
|
|
52
|
+
function getRequestPath(url) {
|
|
53
|
+
if (!url) return "";
|
|
54
|
+
try {
|
|
55
|
+
const urlObj = new URL(url);
|
|
56
|
+
return urlObj.pathname + urlObj.search;
|
|
57
|
+
} catch {
|
|
58
|
+
return url;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function headersToRecord(headers) {
|
|
62
|
+
const result = /* @__PURE__ */ Object.create(null);
|
|
63
|
+
headers.forEach((value, key) => {
|
|
64
|
+
result[key] = value;
|
|
65
|
+
});
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
function headersToRawHeaders(headers) {
|
|
69
|
+
const rawHeaders = [];
|
|
70
|
+
headers.forEach((value, key) => {
|
|
71
|
+
rawHeaders.push(key, value);
|
|
72
|
+
});
|
|
73
|
+
return rawHeaders;
|
|
74
|
+
}
|
|
75
|
+
function normalizeRequestBodyChunk(chunk, encoding = "utf8") {
|
|
76
|
+
if (typeof chunk === "string") {
|
|
77
|
+
if (encoding !== "utf8" && typeof Buffer !== "undefined") {
|
|
78
|
+
return Buffer.from(chunk, encoding);
|
|
79
|
+
}
|
|
80
|
+
return chunk;
|
|
81
|
+
}
|
|
82
|
+
if (chunk instanceof Uint8Array) {
|
|
83
|
+
return chunk;
|
|
84
|
+
}
|
|
85
|
+
if (chunk instanceof ArrayBuffer) {
|
|
86
|
+
return new Uint8Array(chunk);
|
|
87
|
+
}
|
|
88
|
+
if (ArrayBuffer.isView(chunk)) {
|
|
89
|
+
return new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength);
|
|
90
|
+
}
|
|
91
|
+
return new TextEncoder().encode(String(chunk));
|
|
92
|
+
}
|
|
93
|
+
function buildRequestBody(chunks) {
|
|
94
|
+
if (chunks.length === 0) {
|
|
95
|
+
return void 0;
|
|
96
|
+
}
|
|
97
|
+
if (chunks.length === 1) {
|
|
98
|
+
return chunks[0];
|
|
99
|
+
}
|
|
100
|
+
if (chunks.every((chunk) => typeof chunk === "string")) {
|
|
101
|
+
return chunks.join("");
|
|
102
|
+
}
|
|
103
|
+
const encoder = new TextEncoder();
|
|
104
|
+
const bodyParts = chunks.map((chunk) => typeof chunk === "string" ? encoder.encode(chunk) : chunk);
|
|
105
|
+
const totalLength = bodyParts.reduce((sum, part) => sum + part.byteLength, 0);
|
|
106
|
+
const body = new Uint8Array(totalLength);
|
|
107
|
+
let offset = 0;
|
|
108
|
+
for (const part of bodyParts) {
|
|
109
|
+
body.set(part, offset);
|
|
110
|
+
offset += part.byteLength;
|
|
111
|
+
}
|
|
112
|
+
return body;
|
|
113
|
+
}
|
|
114
|
+
function isFetchResponse(value) {
|
|
115
|
+
return typeof value?.status === "number" && typeof value?.statusText === "string" && typeof value?.headers?.forEach === "function";
|
|
116
|
+
}
|
|
117
|
+
function isNodeIncomingMessage(value) {
|
|
118
|
+
return typeof value?.on === "function" && typeof value?.headers === "object" && (typeof value?.httpVersion === "string" || value?.socket !== void 0);
|
|
119
|
+
}
|
|
53
120
|
function headersToInit(headers) {
|
|
54
121
|
const result = {};
|
|
55
122
|
for (const key in headers) {
|
|
@@ -74,17 +141,73 @@ function closeAndEmit(server, callback) {
|
|
|
74
141
|
server.emit("close");
|
|
75
142
|
if (callback) queueMicrotask(() => callback());
|
|
76
143
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
http = require("http");
|
|
85
|
-
https = require("https");
|
|
144
|
+
|
|
145
|
+
// src/server/http/client-request.ts
|
|
146
|
+
var ClientRequest = class extends import_node_events.EventEmitter {
|
|
147
|
+
constructor(_url, _options = {}) {
|
|
148
|
+
super();
|
|
149
|
+
this._bodyChunks = [];
|
|
150
|
+
this._ended = false;
|
|
86
151
|
}
|
|
87
|
-
|
|
152
|
+
_setNativeRequest(nativeRequest) {
|
|
153
|
+
this._nativeRequest = nativeRequest;
|
|
154
|
+
}
|
|
155
|
+
_setExecutor(executor) {
|
|
156
|
+
this._executor = executor;
|
|
157
|
+
}
|
|
158
|
+
write(chunk, encoding, callback) {
|
|
159
|
+
if (this._ended) {
|
|
160
|
+
throw new Error("Cannot write after end");
|
|
161
|
+
}
|
|
162
|
+
if (typeof encoding === "function") {
|
|
163
|
+
callback = encoding;
|
|
164
|
+
encoding = void 0;
|
|
165
|
+
}
|
|
166
|
+
if (this._nativeRequest) {
|
|
167
|
+
const actualEncoding2 = typeof encoding === "string" ? encoding : void 0;
|
|
168
|
+
return this._nativeRequest.write(chunk, actualEncoding2, callback);
|
|
169
|
+
}
|
|
170
|
+
const actualEncoding = typeof encoding === "string" ? encoding : "utf8";
|
|
171
|
+
this._bodyChunks.push(normalizeRequestBodyChunk(chunk, actualEncoding));
|
|
172
|
+
queueCallback(callback);
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
end(chunk, encoding, callback) {
|
|
176
|
+
if (typeof chunk === "function") {
|
|
177
|
+
callback = chunk;
|
|
178
|
+
chunk = void 0;
|
|
179
|
+
encoding = void 0;
|
|
180
|
+
} else if (typeof encoding === "function") {
|
|
181
|
+
callback = encoding;
|
|
182
|
+
encoding = void 0;
|
|
183
|
+
}
|
|
184
|
+
if (this._ended) {
|
|
185
|
+
queueCallback(callback);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
this._ended = true;
|
|
189
|
+
if (this._nativeRequest) {
|
|
190
|
+
const actualEncoding = typeof encoding === "string" ? encoding : void 0;
|
|
191
|
+
if (chunk !== void 0) {
|
|
192
|
+
this._nativeRequest.end(chunk, actualEncoding, callback);
|
|
193
|
+
} else {
|
|
194
|
+
this._nativeRequest.end(callback);
|
|
195
|
+
}
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (chunk !== void 0) {
|
|
199
|
+
this._bodyChunks.push(normalizeRequestBodyChunk(chunk, typeof encoding === "string" ? encoding : "utf8"));
|
|
200
|
+
}
|
|
201
|
+
const executor = this._executor;
|
|
202
|
+
const body = buildRequestBody(this._bodyChunks);
|
|
203
|
+
if (executor) {
|
|
204
|
+
Promise.resolve().then(() => executor(body)).catch((error) => this.emit("error", error));
|
|
205
|
+
}
|
|
206
|
+
queueCallback(callback);
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
// src/server/http/constants.ts
|
|
88
211
|
var METHODS = [
|
|
89
212
|
"GET",
|
|
90
213
|
"POST",
|
|
@@ -152,13 +275,23 @@ var STATUS_CODES = {
|
|
|
152
275
|
510: "Not Extended",
|
|
153
276
|
511: "Network Authentication Required"
|
|
154
277
|
};
|
|
155
|
-
|
|
156
|
-
|
|
278
|
+
|
|
279
|
+
// src/server/http/incoming-message.ts
|
|
280
|
+
var import_node_events2 = require("events");
|
|
281
|
+
var IncomingMessage = class extends import_node_events2.EventEmitter {
|
|
282
|
+
constructor(req, requestMethod) {
|
|
157
283
|
super();
|
|
158
284
|
this.httpVersion = "1.1";
|
|
159
285
|
this.rawHeaders = [];
|
|
160
286
|
this._req = req;
|
|
161
|
-
if (
|
|
287
|
+
if (isFetchResponse(req)) {
|
|
288
|
+
this.method = requestMethod || "GET";
|
|
289
|
+
this.url = getRequestPath(req.url);
|
|
290
|
+
this.headers = headersToRecord(req.headers);
|
|
291
|
+
this.statusCode = req.status;
|
|
292
|
+
this.statusMessage = req.statusText;
|
|
293
|
+
this.rawHeaders = headersToRawHeaders(req.headers);
|
|
294
|
+
} else if (isNodeIncomingMessage(req)) {
|
|
162
295
|
this.method = req.method;
|
|
163
296
|
this.url = req.url;
|
|
164
297
|
this.headers = req.headers;
|
|
@@ -169,14 +302,13 @@ var IncomingMessage = class extends import_node_events.EventEmitter {
|
|
|
169
302
|
this.socket = req.socket;
|
|
170
303
|
} else {
|
|
171
304
|
this.method = req.method;
|
|
172
|
-
|
|
173
|
-
this.
|
|
174
|
-
this.
|
|
175
|
-
this.rawHeaders = [];
|
|
305
|
+
this.url = getRequestPath(req.url);
|
|
306
|
+
this.headers = headersToRecord(req.headers);
|
|
307
|
+
this.rawHeaders = headersToRawHeaders(req.headers);
|
|
176
308
|
}
|
|
177
309
|
}
|
|
178
310
|
async text() {
|
|
179
|
-
if (
|
|
311
|
+
if (isNodeIncomingMessage(this._req)) {
|
|
180
312
|
return new Promise((resolve, reject) => {
|
|
181
313
|
const chunks = [];
|
|
182
314
|
this._req.on("data", (chunk) => chunks.push(chunk));
|
|
@@ -187,14 +319,80 @@ var IncomingMessage = class extends import_node_events.EventEmitter {
|
|
|
187
319
|
return this._req.text();
|
|
188
320
|
}
|
|
189
321
|
async json() {
|
|
190
|
-
if (
|
|
322
|
+
if (isNodeIncomingMessage(this._req)) {
|
|
191
323
|
const text = await this.text();
|
|
192
324
|
return JSON.parse(text);
|
|
193
325
|
}
|
|
194
326
|
return this._req.json();
|
|
195
327
|
}
|
|
196
328
|
};
|
|
197
|
-
|
|
329
|
+
|
|
330
|
+
// src/shares/runtime.ts
|
|
331
|
+
var runtime = (() => {
|
|
332
|
+
if (typeof Deno !== "undefined") return "deno";
|
|
333
|
+
if (typeof Bun !== "undefined") return "bun";
|
|
334
|
+
return "node";
|
|
335
|
+
})();
|
|
336
|
+
var isNode = runtime === "node";
|
|
337
|
+
var isBun = runtime === "bun";
|
|
338
|
+
var isDeno = runtime === "deno";
|
|
339
|
+
|
|
340
|
+
// src/server/http/node-modules.ts
|
|
341
|
+
var http;
|
|
342
|
+
var https;
|
|
343
|
+
if (isNode && typeof process !== "undefined") {
|
|
344
|
+
try {
|
|
345
|
+
http = require("http");
|
|
346
|
+
https = require("https");
|
|
347
|
+
} catch {
|
|
348
|
+
http = require("http");
|
|
349
|
+
https = require("https");
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// src/server/http/request-api.ts
|
|
354
|
+
function request(url, options, callback) {
|
|
355
|
+
const urlString = typeof url === "string" ? url : url.toString();
|
|
356
|
+
const req = new ClientRequest(urlString, options);
|
|
357
|
+
if (isNode) {
|
|
358
|
+
const urlObj = new URL(urlString);
|
|
359
|
+
const client = urlObj.protocol === "https:" ? https : http;
|
|
360
|
+
const nodeReq = client.request(urlString, {
|
|
361
|
+
method: options?.method || "GET",
|
|
362
|
+
headers: options?.headers,
|
|
363
|
+
timeout: options?.timeout,
|
|
364
|
+
signal: options?.signal
|
|
365
|
+
}, (res) => {
|
|
366
|
+
const incomingMessage = new IncomingMessage(res);
|
|
367
|
+
if (callback) callback(incomingMessage);
|
|
368
|
+
req.emit("response", incomingMessage);
|
|
369
|
+
});
|
|
370
|
+
req._setNativeRequest(nodeReq);
|
|
371
|
+
nodeReq.on("error", (error) => req.emit("error", error));
|
|
372
|
+
} else {
|
|
373
|
+
req._setExecutor(async (body) => {
|
|
374
|
+
const response = await fetch(urlString, {
|
|
375
|
+
method: options?.method || "GET",
|
|
376
|
+
headers: options?.headers,
|
|
377
|
+
body,
|
|
378
|
+
signal: options?.signal
|
|
379
|
+
});
|
|
380
|
+
const incomingMessage = new IncomingMessage(response, options?.method || "GET");
|
|
381
|
+
if (callback) callback(incomingMessage);
|
|
382
|
+
req.emit("response", incomingMessage);
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
return req;
|
|
386
|
+
}
|
|
387
|
+
function get(url, options, callback) {
|
|
388
|
+
const req = request(url, { ...options, method: "GET" }, callback);
|
|
389
|
+
req.end();
|
|
390
|
+
return req;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// src/server/http/response.ts
|
|
394
|
+
var import_node_events3 = require("events");
|
|
395
|
+
var ServerResponse = class extends import_node_events3.EventEmitter {
|
|
198
396
|
constructor(_req, nodeRes) {
|
|
199
397
|
super();
|
|
200
398
|
this.statusCode = 200;
|
|
@@ -327,7 +525,6 @@ var ServerResponse = class extends import_node_events.EventEmitter {
|
|
|
327
525
|
_setResolver(resolve) {
|
|
328
526
|
this._resolve = resolve;
|
|
329
527
|
}
|
|
330
|
-
// Express.js-like methods
|
|
331
528
|
json(data, statusCode = 200) {
|
|
332
529
|
if (!this.headersSent) {
|
|
333
530
|
this.setHeader("Content-Type", "application/json");
|
|
@@ -351,7 +548,15 @@ var ServerResponse = class extends import_node_events.EventEmitter {
|
|
|
351
548
|
return this;
|
|
352
549
|
}
|
|
353
550
|
};
|
|
354
|
-
|
|
551
|
+
|
|
552
|
+
// src/server/http/runtime.ts
|
|
553
|
+
function getRuntime() {
|
|
554
|
+
return runtime;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
// src/server/http/server-runtime.ts
|
|
558
|
+
var import_node_events4 = require("events");
|
|
559
|
+
var Server = class extends import_node_events4.EventEmitter {
|
|
355
560
|
constructor(requestListener) {
|
|
356
561
|
super();
|
|
357
562
|
this._bunWebSocketServers = /* @__PURE__ */ new Set();
|
|
@@ -364,9 +569,28 @@ var Server = class extends import_node_events.EventEmitter {
|
|
|
364
569
|
unregisterWebSocketServer(wsServer) {
|
|
365
570
|
this._bunWebSocketServers.delete(wsServer);
|
|
366
571
|
}
|
|
572
|
+
resolvePmInheritedFd(explicitPort, explicitFd) {
|
|
573
|
+
if (typeof explicitFd === "number" && Number.isInteger(explicitFd) && explicitFd >= 0) {
|
|
574
|
+
return explicitFd;
|
|
575
|
+
}
|
|
576
|
+
const fdValue = process.env.ELIT_PM_LISTEN_FD;
|
|
577
|
+
if (!fdValue) {
|
|
578
|
+
return void 0;
|
|
579
|
+
}
|
|
580
|
+
const parsedFd = Number.parseInt(fdValue, 10);
|
|
581
|
+
if (!Number.isInteger(parsedFd) || parsedFd < 0) {
|
|
582
|
+
return void 0;
|
|
583
|
+
}
|
|
584
|
+
const publicPort = Number.parseInt(process.env.ELIT_PM_PUBLIC_PORT ?? process.env.ELIT_PM_PORT ?? "", 10);
|
|
585
|
+
if (Number.isInteger(explicitPort) && Number.isInteger(publicPort) && explicitPort !== publicPort) {
|
|
586
|
+
return void 0;
|
|
587
|
+
}
|
|
588
|
+
return parsedFd;
|
|
589
|
+
}
|
|
367
590
|
listen(...args) {
|
|
368
591
|
let port = 3e3;
|
|
369
592
|
let hostname = "0.0.0.0";
|
|
593
|
+
let fd;
|
|
370
594
|
let callback;
|
|
371
595
|
const firstArg = args[0];
|
|
372
596
|
if (typeof firstArg === "number") {
|
|
@@ -381,8 +605,10 @@ var Server = class extends import_node_events.EventEmitter {
|
|
|
381
605
|
} else if (firstArg && typeof firstArg === "object") {
|
|
382
606
|
port = firstArg.port || 3e3;
|
|
383
607
|
hostname = firstArg.hostname || "0.0.0.0";
|
|
608
|
+
fd = typeof firstArg.fd === "number" ? firstArg.fd : void 0;
|
|
384
609
|
callback = args[1];
|
|
385
610
|
}
|
|
611
|
+
fd = this.resolvePmInheritedFd(firstArg && typeof firstArg === "object" ? firstArg.port : port, fd);
|
|
386
612
|
const self = this;
|
|
387
613
|
if (isNode) {
|
|
388
614
|
this.nativeServer = http.createServer((req, res) => {
|
|
@@ -397,11 +623,19 @@ var Server = class extends import_node_events.EventEmitter {
|
|
|
397
623
|
this.nativeServer.on("upgrade", (req, socket, head) => {
|
|
398
624
|
self.emit("upgrade", req, socket, head);
|
|
399
625
|
});
|
|
400
|
-
|
|
401
|
-
this.
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
626
|
+
if (fd !== void 0) {
|
|
627
|
+
this.nativeServer.listen({ fd, exclusive: false }, () => {
|
|
628
|
+
this._listening = true;
|
|
629
|
+
this.emit("listening");
|
|
630
|
+
if (callback) callback();
|
|
631
|
+
});
|
|
632
|
+
} else {
|
|
633
|
+
this.nativeServer.listen(port, hostname, () => {
|
|
634
|
+
this._listening = true;
|
|
635
|
+
this.emit("listening");
|
|
636
|
+
if (callback) callback();
|
|
637
|
+
});
|
|
638
|
+
}
|
|
405
639
|
this.nativeServer.on("error", (err) => this.emit("error", err));
|
|
406
640
|
this.nativeServer.on("close", () => {
|
|
407
641
|
this._listening = false;
|
|
@@ -426,6 +660,8 @@ var Server = class extends import_node_events.EventEmitter {
|
|
|
426
660
|
const urlObj = new URL(req.url);
|
|
427
661
|
const pathname = urlObj.pathname;
|
|
428
662
|
const requestUrl = urlObj.pathname + urlObj.search;
|
|
663
|
+
const incomingHeaders = headersToRecord(req.headers);
|
|
664
|
+
const rawHeaders = headersToRawHeaders(req.headers);
|
|
429
665
|
const upgradeHeader = req.headers.get("upgrade");
|
|
430
666
|
if (upgradeHeader && upgradeHeader.toLowerCase() === "websocket") {
|
|
431
667
|
const matchingWebSocketServer = Array.from(this._bunWebSocketServers).find((wsServer) => {
|
|
@@ -462,9 +698,9 @@ var Server = class extends import_node_events.EventEmitter {
|
|
|
462
698
|
const incomingMessage = {
|
|
463
699
|
method: req.method,
|
|
464
700
|
url: requestUrl,
|
|
465
|
-
headers:
|
|
701
|
+
headers: incomingHeaders,
|
|
466
702
|
httpVersion: "1.1",
|
|
467
|
-
rawHeaders
|
|
703
|
+
rawHeaders,
|
|
468
704
|
_req: req,
|
|
469
705
|
text: () => req.text(),
|
|
470
706
|
json: () => req.json()
|
|
@@ -518,57 +754,148 @@ var Server = class extends import_node_events.EventEmitter {
|
|
|
518
754
|
this.writeHead(statusCode);
|
|
519
755
|
}
|
|
520
756
|
responseReady = true;
|
|
521
|
-
return this;
|
|
522
757
|
}
|
|
523
758
|
};
|
|
524
759
|
if (self.requestListener) {
|
|
525
760
|
self.requestListener(incomingMessage, serverResponse);
|
|
761
|
+
} else {
|
|
762
|
+
self.emit("request", incomingMessage, serverResponse);
|
|
526
763
|
}
|
|
527
|
-
if (responseReady) {
|
|
528
|
-
|
|
529
|
-
status: statusCode,
|
|
530
|
-
statusText: statusMessage,
|
|
531
|
-
headers
|
|
532
|
-
});
|
|
764
|
+
if (!responseReady) {
|
|
765
|
+
serverResponse.end();
|
|
533
766
|
}
|
|
534
|
-
return new
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
}
|
|
539
|
-
resolve(new Response(body, {
|
|
540
|
-
status: statusCode,
|
|
541
|
-
statusText: statusMessage,
|
|
542
|
-
headers
|
|
543
|
-
}));
|
|
544
|
-
};
|
|
767
|
+
return new Response(body, {
|
|
768
|
+
status: statusCode,
|
|
769
|
+
statusText: statusMessage,
|
|
770
|
+
headers
|
|
545
771
|
});
|
|
546
772
|
},
|
|
547
|
-
error:
|
|
773
|
+
error: (err) => {
|
|
774
|
+
this.emit("error", err);
|
|
775
|
+
return createErrorResponse();
|
|
776
|
+
}
|
|
548
777
|
});
|
|
778
|
+
this._listening = true;
|
|
549
779
|
emitListeningWithCallback(this, callback);
|
|
780
|
+
this.nativeServer.stop = this.nativeServer.stop || this.nativeServer.close;
|
|
781
|
+
this.nativeServer.close = this.nativeServer.close || this.nativeServer.stop;
|
|
782
|
+
this.nativeServer.on?.("close", () => {
|
|
783
|
+
this._listening = false;
|
|
784
|
+
this.emit("close");
|
|
785
|
+
});
|
|
550
786
|
} else if (isDeno) {
|
|
787
|
+
const server = this;
|
|
551
788
|
this.nativeServer = Deno.serve({
|
|
552
789
|
port,
|
|
553
|
-
hostname
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
790
|
+
hostname
|
|
791
|
+
}, async (req) => {
|
|
792
|
+
const urlObj = new URL(req.url);
|
|
793
|
+
const requestUrl = urlObj.pathname + urlObj.search;
|
|
794
|
+
const incomingHeaders = headersToRecord(req.headers);
|
|
795
|
+
const rawHeaders = headersToRawHeaders(req.headers);
|
|
796
|
+
const bodyChunks = [];
|
|
797
|
+
const responseHeaders = new Headers();
|
|
798
|
+
let statusCode = 200;
|
|
799
|
+
let statusText = "OK";
|
|
800
|
+
let responseClosed = false;
|
|
801
|
+
const incomingMessage = {
|
|
802
|
+
method: req.method,
|
|
803
|
+
url: requestUrl,
|
|
804
|
+
headers: incomingHeaders,
|
|
805
|
+
httpVersion: "1.1",
|
|
806
|
+
rawHeaders,
|
|
807
|
+
_req: req,
|
|
808
|
+
text: () => req.text(),
|
|
809
|
+
json: () => req.json()
|
|
810
|
+
};
|
|
811
|
+
const serverResponse = {
|
|
812
|
+
statusCode: 200,
|
|
813
|
+
statusMessage: "OK",
|
|
814
|
+
headersSent: false,
|
|
815
|
+
setHeader(name, value) {
|
|
816
|
+
responseHeaders.set(name, Array.isArray(value) ? value.join(", ") : String(value));
|
|
817
|
+
return this;
|
|
818
|
+
},
|
|
819
|
+
getHeader(name) {
|
|
820
|
+
return responseHeaders.get(name) ?? void 0;
|
|
821
|
+
},
|
|
822
|
+
getHeaders() {
|
|
823
|
+
const headers = {};
|
|
824
|
+
responseHeaders.forEach((value, key) => {
|
|
825
|
+
headers[key] = value;
|
|
826
|
+
});
|
|
827
|
+
return headers;
|
|
828
|
+
},
|
|
829
|
+
writeHead(status, arg2, arg3) {
|
|
830
|
+
statusCode = status;
|
|
831
|
+
this.statusCode = status;
|
|
832
|
+
this.headersSent = true;
|
|
833
|
+
if (typeof arg2 === "string") {
|
|
834
|
+
statusText = arg2;
|
|
835
|
+
this.statusMessage = arg2;
|
|
836
|
+
if (arg3) {
|
|
837
|
+
Object.entries(arg3).forEach(([key, value]) => {
|
|
838
|
+
responseHeaders.set(key, Array.isArray(value) ? value.join(", ") : String(value));
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
} else if (arg2) {
|
|
842
|
+
Object.entries(arg2).forEach(([key, value]) => {
|
|
843
|
+
responseHeaders.set(key, Array.isArray(value) ? value.join(", ") : String(value));
|
|
844
|
+
});
|
|
563
845
|
}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
846
|
+
return this;
|
|
847
|
+
},
|
|
848
|
+
write(chunk) {
|
|
849
|
+
if (!this.headersSent) {
|
|
850
|
+
this.writeHead(statusCode);
|
|
851
|
+
}
|
|
852
|
+
if (typeof chunk === "string") {
|
|
853
|
+
bodyChunks.push(new TextEncoder().encode(chunk));
|
|
854
|
+
} else if (chunk instanceof Uint8Array) {
|
|
855
|
+
bodyChunks.push(chunk);
|
|
856
|
+
} else if (chunk !== void 0 && chunk !== null) {
|
|
857
|
+
bodyChunks.push(new TextEncoder().encode(String(chunk)));
|
|
858
|
+
}
|
|
859
|
+
return true;
|
|
860
|
+
},
|
|
861
|
+
end(chunk) {
|
|
862
|
+
if (chunk !== void 0) {
|
|
863
|
+
this.write(chunk);
|
|
864
|
+
}
|
|
865
|
+
if (!this.headersSent) {
|
|
866
|
+
this.writeHead(statusCode);
|
|
867
|
+
}
|
|
868
|
+
responseClosed = true;
|
|
869
|
+
}
|
|
870
|
+
};
|
|
871
|
+
if (server.requestListener) {
|
|
872
|
+
server.requestListener(incomingMessage, serverResponse);
|
|
873
|
+
} else {
|
|
874
|
+
server.emit("request", incomingMessage, serverResponse);
|
|
569
875
|
}
|
|
876
|
+
if (!responseClosed) {
|
|
877
|
+
serverResponse.end();
|
|
878
|
+
}
|
|
879
|
+
const body = bodyChunks.length === 0 ? void 0 : (() => {
|
|
880
|
+
const totalLength = bodyChunks.reduce((sum, chunk) => sum + chunk.length, 0);
|
|
881
|
+
const output = new ArrayBuffer(totalLength);
|
|
882
|
+
const combined = new Uint8Array(output);
|
|
883
|
+
let offset = 0;
|
|
884
|
+
for (const chunk of bodyChunks) {
|
|
885
|
+
combined.set(chunk, offset);
|
|
886
|
+
offset += chunk.length;
|
|
887
|
+
}
|
|
888
|
+
return output;
|
|
889
|
+
})();
|
|
890
|
+
return new Response(body, {
|
|
891
|
+
status: statusCode,
|
|
892
|
+
statusText,
|
|
893
|
+
headers: responseHeaders
|
|
894
|
+
});
|
|
570
895
|
});
|
|
896
|
+
this._listening = true;
|
|
571
897
|
emitListeningWithCallback(this, callback);
|
|
898
|
+
this.nativeServer.finished.then(() => closeAndEmit(this)).catch((err) => this.emit("error", err));
|
|
572
899
|
}
|
|
573
900
|
return this;
|
|
574
901
|
}
|
|
@@ -597,9 +924,11 @@ var Server = class extends import_node_events.EventEmitter {
|
|
|
597
924
|
return createAddress(0, addr, "unix");
|
|
598
925
|
}
|
|
599
926
|
return addr;
|
|
600
|
-
}
|
|
927
|
+
}
|
|
928
|
+
if (isBun) {
|
|
601
929
|
return createAddress(this.nativeServer.port, this.nativeServer.hostname);
|
|
602
|
-
}
|
|
930
|
+
}
|
|
931
|
+
if (isDeno) {
|
|
603
932
|
const addr = this.nativeServer.addr;
|
|
604
933
|
return createAddress(addr.port, addr.hostname);
|
|
605
934
|
}
|
|
@@ -609,70 +938,12 @@ var Server = class extends import_node_events.EventEmitter {
|
|
|
609
938
|
return this._listening;
|
|
610
939
|
}
|
|
611
940
|
};
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
}
|
|
616
|
-
write(_chunk) {
|
|
617
|
-
return true;
|
|
618
|
-
}
|
|
619
|
-
end(callback) {
|
|
620
|
-
queueCallback(callback);
|
|
621
|
-
}
|
|
622
|
-
};
|
|
623
|
-
var Agent = class {
|
|
624
|
-
constructor(options) {
|
|
625
|
-
this.options = options;
|
|
626
|
-
}
|
|
627
|
-
};
|
|
628
|
-
function createServer(optionsOrListener, requestListener) {
|
|
629
|
-
return new Server(typeof optionsOrListener === "function" ? optionsOrListener : requestListener);
|
|
630
|
-
}
|
|
631
|
-
function request(url, options, callback) {
|
|
632
|
-
const urlString = typeof url === "string" ? url : url.toString();
|
|
633
|
-
const req = new ClientRequest(urlString, options);
|
|
634
|
-
if (isNode) {
|
|
635
|
-
const urlObj = new URL(urlString);
|
|
636
|
-
const client = urlObj.protocol === "https:" ? https : http;
|
|
637
|
-
const nodeReq = client.request(urlString, {
|
|
638
|
-
method: options?.method || "GET",
|
|
639
|
-
headers: options?.headers,
|
|
640
|
-
timeout: options?.timeout,
|
|
641
|
-
signal: options?.signal
|
|
642
|
-
}, (res) => {
|
|
643
|
-
const incomingMessage = new IncomingMessage(res);
|
|
644
|
-
if (callback) callback(incomingMessage);
|
|
645
|
-
req.emit("response", incomingMessage);
|
|
646
|
-
});
|
|
647
|
-
nodeReq.on("error", (error) => req.emit("error", error));
|
|
648
|
-
nodeReq.end();
|
|
649
|
-
} else {
|
|
650
|
-
queueMicrotask(async () => {
|
|
651
|
-
try {
|
|
652
|
-
const response = await fetch(urlString, {
|
|
653
|
-
method: options?.method || "GET",
|
|
654
|
-
headers: options?.headers,
|
|
655
|
-
signal: options?.signal
|
|
656
|
-
});
|
|
657
|
-
const fetchRequest = new Request(urlString);
|
|
658
|
-
const incomingMessage = new IncomingMessage(fetchRequest);
|
|
659
|
-
incomingMessage.statusCode = response.status;
|
|
660
|
-
incomingMessage.statusMessage = response.statusText;
|
|
661
|
-
if (callback) callback(incomingMessage);
|
|
662
|
-
req.emit("response", incomingMessage);
|
|
663
|
-
} catch (error) {
|
|
664
|
-
req.emit("error", error);
|
|
665
|
-
}
|
|
666
|
-
});
|
|
667
|
-
}
|
|
668
|
-
return req;
|
|
669
|
-
}
|
|
670
|
-
function get(url, options, callback) {
|
|
671
|
-
return request(url, { ...options, method: "GET" }, callback);
|
|
672
|
-
}
|
|
673
|
-
function getRuntime() {
|
|
674
|
-
return runtime;
|
|
941
|
+
function createServer(arg1, arg2) {
|
|
942
|
+
const requestListener = typeof arg1 === "function" ? arg1 : arg2;
|
|
943
|
+
return new Server(requestListener);
|
|
675
944
|
}
|
|
945
|
+
|
|
946
|
+
// src/server/http/index.ts
|
|
676
947
|
var http_default = {
|
|
677
948
|
createServer,
|
|
678
949
|
request,
|