elit 3.6.5 → 3.6.7
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 +6 -0
- package/dist/build.cjs +421 -331
- package/dist/build.d.ts +1 -16
- 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 +21608 -20241
- package/dist/cli.d.ts +19 -37
- package/dist/cli.mjs +21262 -19910
- package/dist/config.cjs +357 -350
- package/dist/config.d.ts +19 -240
- package/dist/config.js +520 -515
- package/dist/config.mjs +346 -341
- package/dist/contracts-BeW9k0yZ.d.ts +54 -0
- package/dist/contracts-D7KIS-TK.d.ts +36 -0
- package/dist/coverage.cjs +448 -485
- package/dist/coverage.d.ts +13 -59
- 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 -1522
- package/dist/desktop-auto-render.d.ts +4 -9
- package/dist/desktop-auto-render.js +1695 -1517
- package/dist/desktop-auto-render.mjs +1696 -1518
- 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 -590
- package/dist/dom.d.ts +2 -15
- package/dist/dom.js +714 -587
- package/dist/dom.mjs +716 -589
- package/dist/el.cjs +62 -52
- package/dist/el.d.ts +5 -10
- 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 +251 -99
- package/dist/http.d.ts +38 -104
- package/dist/http.js +249 -99
- package/dist/http.mjs +249 -99
- package/dist/https.cjs +524 -228
- package/dist/https.d.ts +44 -36
- package/dist/https.js +520 -226
- package/dist/https.mjs +522 -228
- package/dist/index.cjs +7502 -7690
- package/dist/index.d.ts +8 -3
- package/dist/index.js +7486 -7676
- package/dist/index.mjs +7497 -7686
- 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 -8869
- package/dist/native.d.ts +7 -8
- package/dist/native.js +8682 -8935
- package/dist/native.mjs +8615 -8868
- 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.cjs +3300 -0
- package/dist/pm.d.ts +256 -0
- package/dist/pm.js +5638 -0
- package/dist/pm.mjs +3196 -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 -31
- package/dist/render-context.js +11 -2
- package/dist/render-context.mjs +11 -2
- package/dist/router.cjs +787 -645
- package/dist/router.d.ts +8 -12
- package/dist/router.js +786 -644
- package/dist/router.mjs +786 -644
- package/dist/runtime.cjs +1 -1
- package/dist/runtime.js +1 -1
- package/dist/runtime.mjs +1 -1
- package/dist/server.cjs +3315 -2603
- package/dist/server.d.ts +49 -4
- package/dist/server.js +7611 -2834
- package/dist/server.mjs +3317 -2607
- package/dist/smtp-server.cjs +128 -0
- package/dist/smtp-server.d.ts +27 -0
- package/dist/smtp-server.js +4199 -0
- package/dist/smtp-server.mjs +100 -0
- package/dist/state-DvEkDehk.d.ts +195 -0
- package/dist/state.cjs +768 -658
- package/dist/state.d.ts +11 -69
- package/dist/state.js +760 -650
- package/dist/state.mjs +767 -657
- 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-C4gKykuG.d.ts +23 -0
- package/dist/types-CIhpN1-K.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-DAisuVr5.d.ts +75 -0
- package/dist/types-tJn88E1N.d.ts +242 -0
- package/dist/types.d.ts +71 -226
- package/dist/universal.cjs +1 -1
- package/dist/universal.d.ts +1 -5
- package/dist/universal.js +1 -1
- package/dist/universal.mjs +1 -1
- package/dist/websocket-XfyK23zD.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 +757 -479
- package/dist/wss.d.ts +31 -28
- package/dist/wss.js +755 -479
- package/dist/wss.mjs +758 -482
- package/package.json +16 -1
- package/vendor/epaint-0.31.1/src/image.rs +418 -0
- package/dist/server-CcBFc2F5.d.ts +0 -449
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
|
-
|
|
46
|
-
|
|
47
|
-
var
|
|
38
|
+
// src/server/http/agent.ts
|
|
39
|
+
var Agent = class {
|
|
40
|
+
constructor(options) {
|
|
41
|
+
this.options = options;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// src/server/http/client-request.ts
|
|
46
|
+
var import_node_events = require("events");
|
|
48
47
|
|
|
49
|
-
// src/http.ts
|
|
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();
|
|
@@ -426,6 +631,8 @@ var Server = class extends import_node_events.EventEmitter {
|
|
|
426
631
|
const urlObj = new URL(req.url);
|
|
427
632
|
const pathname = urlObj.pathname;
|
|
428
633
|
const requestUrl = urlObj.pathname + urlObj.search;
|
|
634
|
+
const incomingHeaders = headersToRecord(req.headers);
|
|
635
|
+
const rawHeaders = headersToRawHeaders(req.headers);
|
|
429
636
|
const upgradeHeader = req.headers.get("upgrade");
|
|
430
637
|
if (upgradeHeader && upgradeHeader.toLowerCase() === "websocket") {
|
|
431
638
|
const matchingWebSocketServer = Array.from(this._bunWebSocketServers).find((wsServer) => {
|
|
@@ -462,9 +669,9 @@ var Server = class extends import_node_events.EventEmitter {
|
|
|
462
669
|
const incomingMessage = {
|
|
463
670
|
method: req.method,
|
|
464
671
|
url: requestUrl,
|
|
465
|
-
headers:
|
|
672
|
+
headers: incomingHeaders,
|
|
466
673
|
httpVersion: "1.1",
|
|
467
|
-
rawHeaders
|
|
674
|
+
rawHeaders,
|
|
468
675
|
_req: req,
|
|
469
676
|
text: () => req.text(),
|
|
470
677
|
json: () => req.json()
|
|
@@ -523,6 +730,8 @@ var Server = class extends import_node_events.EventEmitter {
|
|
|
523
730
|
};
|
|
524
731
|
if (self.requestListener) {
|
|
525
732
|
self.requestListener(incomingMessage, serverResponse);
|
|
733
|
+
} else {
|
|
734
|
+
self.emit("request", incomingMessage, serverResponse);
|
|
526
735
|
}
|
|
527
736
|
if (responseReady) {
|
|
528
737
|
return new Response(body, {
|
|
@@ -597,9 +806,11 @@ var Server = class extends import_node_events.EventEmitter {
|
|
|
597
806
|
return createAddress(0, addr, "unix");
|
|
598
807
|
}
|
|
599
808
|
return addr;
|
|
600
|
-
}
|
|
809
|
+
}
|
|
810
|
+
if (isBun) {
|
|
601
811
|
return createAddress(this.nativeServer.port, this.nativeServer.hostname);
|
|
602
|
-
}
|
|
812
|
+
}
|
|
813
|
+
if (isDeno) {
|
|
603
814
|
const addr = this.nativeServer.addr;
|
|
604
815
|
return createAddress(addr.port, addr.hostname);
|
|
605
816
|
}
|
|
@@ -609,70 +820,11 @@ var Server = class extends import_node_events.EventEmitter {
|
|
|
609
820
|
return this._listening;
|
|
610
821
|
}
|
|
611
822
|
};
|
|
612
|
-
var ClientRequest = class extends import_node_events.EventEmitter {
|
|
613
|
-
constructor(_url, _options = {}) {
|
|
614
|
-
super();
|
|
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
823
|
function createServer(optionsOrListener, requestListener) {
|
|
629
824
|
return new Server(typeof optionsOrListener === "function" ? optionsOrListener : requestListener);
|
|
630
825
|
}
|
|
631
|
-
|
|
632
|
-
|
|
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;
|
|
675
|
-
}
|
|
826
|
+
|
|
827
|
+
// src/server/http/index.ts
|
|
676
828
|
var http_default = {
|
|
677
829
|
createServer,
|
|
678
830
|
request,
|
package/dist/http.d.ts
CHANGED
|
@@ -1,75 +1,44 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
|
+
import { R as RequestOptions, I as IncomingMessage, a as RequestListener, b as ServerOptions, S as ServerResponse } from './types-DAisuVr5.js';
|
|
3
|
+
export { c as IncomingHttpHeaders, O as OutgoingHttpHeaders } from './types-DAisuVr5.js';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
|
-
* HTTP
|
|
5
|
-
* Ultra-optimized for maximum performance across Node.js, Bun, and Deno
|
|
6
|
-
*
|
|
7
|
-
* Performance optimizations:
|
|
8
|
-
* - Bun fast path: Zero class instantiation (object literals only)
|
|
9
|
-
* - Eliminated EventEmitter overhead for Bun/Deno
|
|
10
|
-
* - Zero-copy headers conversion
|
|
11
|
-
* - Inline response creation
|
|
12
|
-
* - Reduced object allocations
|
|
13
|
-
* - Direct closure capture (no resolver indirection)
|
|
6
|
+
* HTTP Agent
|
|
14
7
|
*/
|
|
8
|
+
declare class Agent {
|
|
9
|
+
options?: any | undefined;
|
|
10
|
+
constructor(options?: any | undefined);
|
|
11
|
+
}
|
|
15
12
|
|
|
16
13
|
/**
|
|
17
|
-
*
|
|
18
|
-
*/
|
|
19
|
-
declare const METHODS: readonly ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE"];
|
|
20
|
-
/**
|
|
21
|
-
* HTTP Status Codes (compact object)
|
|
14
|
+
* Client request - lightweight wrapper
|
|
22
15
|
*/
|
|
23
|
-
declare
|
|
16
|
+
declare class ClientRequest extends EventEmitter {
|
|
17
|
+
private _nativeRequest?;
|
|
18
|
+
private _bodyChunks;
|
|
19
|
+
private _executor?;
|
|
20
|
+
private _ended;
|
|
21
|
+
constructor(_url: string | URL, _options?: RequestOptions);
|
|
22
|
+
_setNativeRequest(nativeRequest: any): void;
|
|
23
|
+
_setExecutor(executor: (body: BodyInit | undefined) => Promise<void> | void): void;
|
|
24
|
+
write(chunk: any, encoding?: BufferEncoding | (() => void), callback?: () => void): boolean;
|
|
25
|
+
end(chunk?: any, encoding?: BufferEncoding | (() => void), callback?: () => void): void;
|
|
26
|
+
}
|
|
27
|
+
|
|
24
28
|
/**
|
|
25
|
-
* HTTP
|
|
29
|
+
* Make HTTP request - optimized per runtime
|
|
26
30
|
*/
|
|
27
|
-
|
|
28
|
-
type OutgoingHttpHeaders = Record<string, string | string[] | number>;
|
|
31
|
+
declare function request(url: string | URL, options?: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest;
|
|
29
32
|
/**
|
|
30
|
-
*
|
|
33
|
+
* Make HTTP GET request
|
|
31
34
|
*/
|
|
32
|
-
declare
|
|
33
|
-
|
|
34
|
-
url: string;
|
|
35
|
-
headers: IncomingHttpHeaders;
|
|
36
|
-
statusCode?: number;
|
|
37
|
-
statusMessage?: string;
|
|
38
|
-
httpVersion: string;
|
|
39
|
-
rawHeaders: string[];
|
|
40
|
-
socket: any;
|
|
41
|
-
private _req;
|
|
42
|
-
constructor(req: any);
|
|
43
|
-
text(): Promise<string>;
|
|
44
|
-
json(): Promise<any>;
|
|
45
|
-
}
|
|
35
|
+
declare function get(url: string | URL, options?: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest;
|
|
36
|
+
|
|
46
37
|
/**
|
|
47
|
-
*
|
|
38
|
+
* Get current runtime
|
|
48
39
|
*/
|
|
49
|
-
declare
|
|
50
|
-
|
|
51
|
-
statusMessage: string;
|
|
52
|
-
headersSent: boolean;
|
|
53
|
-
private _headers;
|
|
54
|
-
private _body;
|
|
55
|
-
private _resolve?;
|
|
56
|
-
private _finished;
|
|
57
|
-
private _nodeRes?;
|
|
58
|
-
constructor(_req?: IncomingMessage, nodeRes?: any);
|
|
59
|
-
setHeader(name: string, value: string | string[] | number): this;
|
|
60
|
-
getHeader(name: string): string | string[] | number | undefined;
|
|
61
|
-
getHeaders(): OutgoingHttpHeaders;
|
|
62
|
-
getHeaderNames(): string[];
|
|
63
|
-
hasHeader(name: string): boolean;
|
|
64
|
-
removeHeader(name: string): void;
|
|
65
|
-
writeHead(statusCode: number, statusMessage?: string | OutgoingHttpHeaders, headers?: OutgoingHttpHeaders): this;
|
|
66
|
-
write(chunk: any, encoding?: BufferEncoding | (() => void), callback?: () => void): boolean;
|
|
67
|
-
end(chunk?: any, encoding?: BufferEncoding | (() => void), callback?: () => void): this;
|
|
68
|
-
_setResolver(resolve: (response: Response) => void): void;
|
|
69
|
-
json(data: any, statusCode?: number): this;
|
|
70
|
-
send(data: any): this;
|
|
71
|
-
status(code: number): this;
|
|
72
|
-
}
|
|
40
|
+
declare function getRuntime(): 'node' | 'bun' | 'deno';
|
|
41
|
+
|
|
73
42
|
/**
|
|
74
43
|
* Server - Optimized for each runtime
|
|
75
44
|
*/
|
|
@@ -97,61 +66,26 @@ declare class Server extends EventEmitter {
|
|
|
97
66
|
} | null;
|
|
98
67
|
get listening(): boolean;
|
|
99
68
|
}
|
|
100
|
-
/**
|
|
101
|
-
* Request listener type
|
|
102
|
-
*/
|
|
103
|
-
type RequestListener = (req: IncomingMessage, res: ServerResponse) => void;
|
|
104
|
-
/**
|
|
105
|
-
* Request options
|
|
106
|
-
*/
|
|
107
|
-
interface RequestOptions {
|
|
108
|
-
method?: string;
|
|
109
|
-
headers?: OutgoingHttpHeaders;
|
|
110
|
-
timeout?: number;
|
|
111
|
-
signal?: AbortSignal;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Server options
|
|
115
|
-
*/
|
|
116
|
-
interface ServerOptions {
|
|
117
|
-
IncomingMessage?: typeof IncomingMessage;
|
|
118
|
-
ServerResponse?: typeof ServerResponse;
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Client request - lightweight wrapper
|
|
122
|
-
*/
|
|
123
|
-
declare class ClientRequest extends EventEmitter {
|
|
124
|
-
constructor(_url: string | URL, _options?: RequestOptions);
|
|
125
|
-
write(_chunk: any): boolean;
|
|
126
|
-
end(callback?: () => void): void;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* HTTP Agent
|
|
130
|
-
*/
|
|
131
|
-
declare class Agent {
|
|
132
|
-
options?: any | undefined;
|
|
133
|
-
constructor(options?: any | undefined);
|
|
134
|
-
}
|
|
135
69
|
/**
|
|
136
70
|
* Create HTTP server
|
|
137
71
|
*/
|
|
138
72
|
declare function createServer(requestListener?: RequestListener): Server;
|
|
139
73
|
declare function createServer(options: ServerOptions, requestListener?: RequestListener): Server;
|
|
74
|
+
|
|
140
75
|
/**
|
|
141
|
-
*
|
|
142
|
-
*/
|
|
143
|
-
declare function request(url: string | URL, options?: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest;
|
|
144
|
-
/**
|
|
145
|
-
* Make HTTP GET request
|
|
76
|
+
* HTTP Methods
|
|
146
77
|
*/
|
|
147
|
-
declare
|
|
78
|
+
declare const METHODS: readonly ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT", "TRACE"];
|
|
148
79
|
/**
|
|
149
|
-
*
|
|
80
|
+
* HTTP Status Codes (compact object)
|
|
150
81
|
*/
|
|
151
|
-
declare
|
|
82
|
+
declare const STATUS_CODES: Record<number, string>;
|
|
83
|
+
|
|
152
84
|
/**
|
|
153
|
-
*
|
|
85
|
+
* HTTP module with unified API across runtimes
|
|
86
|
+
* Ultra-optimized for maximum performance across Node.js, Bun, and Deno
|
|
154
87
|
*/
|
|
88
|
+
|
|
155
89
|
declare const _default: {
|
|
156
90
|
createServer: typeof createServer;
|
|
157
91
|
request: typeof request;
|
|
@@ -166,4 +100,4 @@ declare const _default: {
|
|
|
166
100
|
getRuntime: typeof getRuntime;
|
|
167
101
|
};
|
|
168
102
|
|
|
169
|
-
export { Agent, ClientRequest,
|
|
103
|
+
export { Agent, ClientRequest, IncomingMessage, METHODS, RequestListener, RequestOptions, STATUS_CODES, Server, ServerOptions, ServerResponse, createServer, _default as default, get, getRuntime, request };
|