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.
Files changed (154) hide show
  1. package/Cargo.lock +1 -1
  2. package/Cargo.toml +1 -1
  3. package/README.md +6 -0
  4. package/dist/build.cjs +421 -331
  5. package/dist/build.d.ts +1 -16
  6. package/dist/build.js +420 -330
  7. package/dist/build.mjs +420 -330
  8. package/dist/chokidar.cjs +219 -182
  9. package/dist/chokidar.d.ts +25 -10
  10. package/dist/chokidar.js +217 -182
  11. package/dist/chokidar.mjs +218 -183
  12. package/dist/cli.cjs +21608 -20241
  13. package/dist/cli.d.ts +19 -37
  14. package/dist/cli.mjs +21262 -19910
  15. package/dist/config.cjs +357 -350
  16. package/dist/config.d.ts +19 -240
  17. package/dist/config.js +520 -515
  18. package/dist/config.mjs +346 -341
  19. package/dist/contracts-BeW9k0yZ.d.ts +54 -0
  20. package/dist/contracts-D7KIS-TK.d.ts +36 -0
  21. package/dist/coverage.cjs +448 -485
  22. package/dist/coverage.d.ts +13 -59
  23. package/dist/coverage.js +447 -484
  24. package/dist/coverage.mjs +447 -484
  25. package/dist/database.cjs +819 -828
  26. package/dist/database.d.ts +8 -24
  27. package/dist/database.js +818 -829
  28. package/dist/database.mjs +818 -829
  29. package/dist/desktop-auto-render.cjs +1700 -1522
  30. package/dist/desktop-auto-render.d.ts +4 -9
  31. package/dist/desktop-auto-render.js +1695 -1517
  32. package/dist/desktop-auto-render.mjs +1696 -1518
  33. package/dist/desktop.cjs +3 -1
  34. package/dist/desktop.d.ts +4 -1
  35. package/dist/desktop.js +1 -1
  36. package/dist/desktop.mjs +1 -1
  37. package/dist/dev-build.cjs +830 -0
  38. package/dist/dev-build.d.ts +53 -0
  39. package/dist/dev-build.js +3318 -0
  40. package/dist/dev-build.mjs +797 -0
  41. package/dist/dom.cjs +717 -590
  42. package/dist/dom.d.ts +2 -15
  43. package/dist/dom.js +714 -587
  44. package/dist/dom.mjs +716 -589
  45. package/dist/el.cjs +62 -52
  46. package/dist/el.d.ts +5 -10
  47. package/dist/el.js +60 -52
  48. package/dist/el.mjs +60 -52
  49. package/dist/fs.cjs +72 -63
  50. package/dist/fs.d.ts +22 -19
  51. package/dist/fs.js +71 -62
  52. package/dist/fs.mjs +71 -62
  53. package/dist/hmr.cjs +40 -14
  54. package/dist/hmr.d.ts +11 -23
  55. package/dist/hmr.js +38 -14
  56. package/dist/hmr.mjs +38 -14
  57. package/dist/http.cjs +251 -99
  58. package/dist/http.d.ts +38 -104
  59. package/dist/http.js +249 -99
  60. package/dist/http.mjs +249 -99
  61. package/dist/https.cjs +524 -228
  62. package/dist/https.d.ts +44 -36
  63. package/dist/https.js +520 -226
  64. package/dist/https.mjs +522 -228
  65. package/dist/index.cjs +7502 -7690
  66. package/dist/index.d.ts +8 -3
  67. package/dist/index.js +7486 -7676
  68. package/dist/index.mjs +7497 -7686
  69. package/dist/mime-types.cjs +10 -4
  70. package/dist/mime-types.d.ts +8 -11
  71. package/dist/mime-types.js +9 -3
  72. package/dist/mime-types.mjs +9 -3
  73. package/dist/native.cjs +8616 -8869
  74. package/dist/native.d.ts +7 -8
  75. package/dist/native.js +8682 -8935
  76. package/dist/native.mjs +8615 -8868
  77. package/dist/path.cjs +83 -77
  78. package/dist/path.d.ts +29 -29
  79. package/dist/path.js +82 -76
  80. package/dist/path.mjs +82 -76
  81. package/dist/pm.cjs +3300 -0
  82. package/dist/pm.d.ts +256 -0
  83. package/dist/pm.js +5638 -0
  84. package/dist/pm.mjs +3196 -0
  85. package/dist/preview-build.cjs +712 -0
  86. package/dist/preview-build.d.ts +59 -0
  87. package/dist/preview-build.js +3194 -0
  88. package/dist/preview-build.mjs +676 -0
  89. package/dist/render-context.cjs +13 -2
  90. package/dist/render-context.d.ts +9 -31
  91. package/dist/render-context.js +11 -2
  92. package/dist/render-context.mjs +11 -2
  93. package/dist/router.cjs +787 -645
  94. package/dist/router.d.ts +8 -12
  95. package/dist/router.js +786 -644
  96. package/dist/router.mjs +786 -644
  97. package/dist/runtime.cjs +1 -1
  98. package/dist/runtime.js +1 -1
  99. package/dist/runtime.mjs +1 -1
  100. package/dist/server.cjs +3315 -2603
  101. package/dist/server.d.ts +49 -4
  102. package/dist/server.js +7611 -2834
  103. package/dist/server.mjs +3317 -2607
  104. package/dist/smtp-server.cjs +128 -0
  105. package/dist/smtp-server.d.ts +27 -0
  106. package/dist/smtp-server.js +4199 -0
  107. package/dist/smtp-server.mjs +100 -0
  108. package/dist/state-DvEkDehk.d.ts +195 -0
  109. package/dist/state.cjs +768 -658
  110. package/dist/state.d.ts +11 -69
  111. package/dist/state.js +760 -650
  112. package/dist/state.mjs +767 -657
  113. package/dist/style.cjs +1011 -968
  114. package/dist/style.d.ts +13 -127
  115. package/dist/style.js +1009 -970
  116. package/dist/style.mjs +1011 -971
  117. package/dist/test-reporter.cjs +332 -316
  118. package/dist/test-reporter.d.ts +28 -33
  119. package/dist/test-reporter.js +328 -312
  120. package/dist/test-reporter.mjs +328 -312
  121. package/dist/test-runtime.cjs +927 -968
  122. package/dist/test-runtime.d.ts +24 -99
  123. package/dist/test-runtime.js +922 -965
  124. package/dist/test-runtime.mjs +922 -965
  125. package/dist/test.cjs +4428 -4273
  126. package/dist/test.d.ts +2 -8
  127. package/dist/test.js +4307 -4154
  128. package/dist/test.mjs +4419 -4267
  129. package/dist/types-BONVzPtp.d.ts +59 -0
  130. package/dist/types-BR4wMiVx.d.ts +32 -0
  131. package/dist/types-C4gKykuG.d.ts +23 -0
  132. package/dist/types-CIhpN1-K.d.ts +64 -0
  133. package/dist/types-Ckj8md_j.d.ts +84 -0
  134. package/dist/types-CpjQTAkX.d.ts +24 -0
  135. package/dist/types-D0LjrYjS.d.ts +14 -0
  136. package/dist/types-DAisuVr5.d.ts +75 -0
  137. package/dist/types-tJn88E1N.d.ts +242 -0
  138. package/dist/types.d.ts +71 -226
  139. package/dist/universal.cjs +1 -1
  140. package/dist/universal.d.ts +1 -5
  141. package/dist/universal.js +1 -1
  142. package/dist/universal.mjs +1 -1
  143. package/dist/websocket-XfyK23zD.d.ts +119 -0
  144. package/dist/ws.cjs +129 -108
  145. package/dist/ws.d.ts +21 -131
  146. package/dist/ws.js +128 -109
  147. package/dist/ws.mjs +128 -109
  148. package/dist/wss.cjs +757 -479
  149. package/dist/wss.d.ts +31 -28
  150. package/dist/wss.js +755 -479
  151. package/dist/wss.mjs +758 -482
  152. package/package.json +16 -1
  153. package/vendor/epaint-0.31.1/src/image.rs +418 -0
  154. package/dist/server-CcBFc2F5.d.ts +0 -449
package/dist/https.mjs CHANGED
@@ -26,42 +26,78 @@ var __copyProps = (to, from, except, desc) => {
26
26
  };
27
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
28
 
29
- // src/runtime.ts
30
- var runtime, isNode, isBun, isDeno;
31
- var init_runtime = __esm({
32
- "src/runtime.ts"() {
33
- "use strict";
34
- runtime = (() => {
35
- if (typeof Deno !== "undefined") return "deno";
36
- if (typeof Bun !== "undefined") return "bun";
37
- return "node";
38
- })();
39
- isNode = runtime === "node";
40
- isBun = runtime === "bun";
41
- isDeno = runtime === "deno";
42
- }
43
- });
44
-
45
- // src/http.ts
46
- var http_exports = {};
47
- __export(http_exports, {
48
- Agent: () => Agent,
49
- ClientRequest: () => ClientRequest,
50
- IncomingMessage: () => IncomingMessage,
51
- METHODS: () => METHODS,
52
- STATUS_CODES: () => STATUS_CODES,
53
- Server: () => Server,
54
- ServerResponse: () => ServerResponse,
55
- createServer: () => createServer,
56
- default: () => http_default,
57
- get: () => get,
58
- getRuntime: () => getRuntime,
59
- request: () => request
60
- });
61
- import { EventEmitter } from "events";
29
+ // src/server/http/utils.ts
62
30
  function queueCallback(callback) {
63
31
  if (callback) queueMicrotask(callback);
64
32
  }
33
+ function getRequestPath(url) {
34
+ if (!url) return "";
35
+ try {
36
+ const urlObj = new URL(url);
37
+ return urlObj.pathname + urlObj.search;
38
+ } catch {
39
+ return url;
40
+ }
41
+ }
42
+ function headersToRecord(headers) {
43
+ const result = /* @__PURE__ */ Object.create(null);
44
+ headers.forEach((value, key) => {
45
+ result[key] = value;
46
+ });
47
+ return result;
48
+ }
49
+ function headersToRawHeaders(headers) {
50
+ const rawHeaders = [];
51
+ headers.forEach((value, key) => {
52
+ rawHeaders.push(key, value);
53
+ });
54
+ return rawHeaders;
55
+ }
56
+ function normalizeRequestBodyChunk(chunk, encoding = "utf8") {
57
+ if (typeof chunk === "string") {
58
+ if (encoding !== "utf8" && typeof Buffer !== "undefined") {
59
+ return Buffer.from(chunk, encoding);
60
+ }
61
+ return chunk;
62
+ }
63
+ if (chunk instanceof Uint8Array) {
64
+ return chunk;
65
+ }
66
+ if (chunk instanceof ArrayBuffer) {
67
+ return new Uint8Array(chunk);
68
+ }
69
+ if (ArrayBuffer.isView(chunk)) {
70
+ return new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength);
71
+ }
72
+ return new TextEncoder().encode(String(chunk));
73
+ }
74
+ function buildRequestBody(chunks) {
75
+ if (chunks.length === 0) {
76
+ return void 0;
77
+ }
78
+ if (chunks.length === 1) {
79
+ return chunks[0];
80
+ }
81
+ if (chunks.every((chunk) => typeof chunk === "string")) {
82
+ return chunks.join("");
83
+ }
84
+ const encoder = new TextEncoder();
85
+ const bodyParts = chunks.map((chunk) => typeof chunk === "string" ? encoder.encode(chunk) : chunk);
86
+ const totalLength = bodyParts.reduce((sum, part) => sum + part.byteLength, 0);
87
+ const body = new Uint8Array(totalLength);
88
+ let offset = 0;
89
+ for (const part of bodyParts) {
90
+ body.set(part, offset);
91
+ offset += part.byteLength;
92
+ }
93
+ return body;
94
+ }
95
+ function isFetchResponse(value) {
96
+ return typeof value?.status === "number" && typeof value?.statusText === "string" && typeof value?.headers?.forEach === "function";
97
+ }
98
+ function isNodeIncomingMessage(value) {
99
+ return typeof value?.on === "function" && typeof value?.headers === "object" && (typeof value?.httpVersion === "string" || value?.socket !== void 0);
100
+ }
65
101
  function headersToInit(headers) {
66
102
  const result = {};
67
103
  for (const key in headers) {
@@ -86,68 +122,119 @@ function closeAndEmit(server, callback) {
86
122
  server.emit("close");
87
123
  if (callback) queueMicrotask(() => callback());
88
124
  }
89
- function createServer(optionsOrListener, requestListener) {
90
- return new Server(typeof optionsOrListener === "function" ? optionsOrListener : requestListener);
91
- }
92
- function request(url, options, callback) {
93
- const urlString = typeof url === "string" ? url : url.toString();
94
- const req = new ClientRequest(urlString, options);
95
- if (isNode) {
96
- const urlObj = new URL(urlString);
97
- const client = urlObj.protocol === "https:" ? https : http;
98
- const nodeReq = client.request(urlString, {
99
- method: options?.method || "GET",
100
- headers: options?.headers,
101
- timeout: options?.timeout,
102
- signal: options?.signal
103
- }, (res) => {
104
- const incomingMessage = new IncomingMessage(res);
105
- if (callback) callback(incomingMessage);
106
- req.emit("response", incomingMessage);
107
- });
108
- nodeReq.on("error", (error) => req.emit("error", error));
109
- nodeReq.end();
110
- } else {
111
- queueMicrotask(async () => {
112
- try {
113
- const response = await fetch(urlString, {
114
- method: options?.method || "GET",
115
- headers: options?.headers,
116
- signal: options?.signal
117
- });
118
- const fetchRequest = new Request(urlString);
119
- const incomingMessage = new IncomingMessage(fetchRequest);
120
- incomingMessage.statusCode = response.status;
121
- incomingMessage.statusMessage = response.statusText;
122
- if (callback) callback(incomingMessage);
123
- req.emit("response", incomingMessage);
124
- } catch (error) {
125
- req.emit("error", error);
125
+ var init_utils = __esm({
126
+ "src/server/http/utils.ts"() {
127
+ "use strict";
128
+ }
129
+ });
130
+
131
+ // src/shares/runtime.ts
132
+ var runtime, isNode, isBun, isDeno;
133
+ var init_runtime = __esm({
134
+ "src/shares/runtime.ts"() {
135
+ "use strict";
136
+ runtime = (() => {
137
+ if (typeof Deno !== "undefined") return "deno";
138
+ if (typeof Bun !== "undefined") return "bun";
139
+ return "node";
140
+ })();
141
+ isNode = runtime === "node";
142
+ isBun = runtime === "bun";
143
+ isDeno = runtime === "deno";
144
+ }
145
+ });
146
+
147
+ // src/server/http/agent.ts
148
+ var Agent2;
149
+ var init_agent = __esm({
150
+ "src/server/http/agent.ts"() {
151
+ "use strict";
152
+ Agent2 = class {
153
+ constructor(options) {
154
+ this.options = options;
126
155
  }
127
- });
156
+ };
128
157
  }
129
- return req;
130
- }
131
- function get(url, options, callback) {
132
- return request(url, { ...options, method: "GET" }, callback);
133
- }
134
- function getRuntime() {
135
- return runtime;
136
- }
137
- var http, https, METHODS, STATUS_CODES, IncomingMessage, ServerResponse, Server, ClientRequest, Agent, http_default;
138
- var init_http = __esm({
139
- "src/http.ts"() {
158
+ });
159
+
160
+ // src/server/http/client-request.ts
161
+ import { EventEmitter as EventEmitter2 } from "events";
162
+ var ClientRequest2;
163
+ var init_client_request = __esm({
164
+ "src/server/http/client-request.ts"() {
140
165
  "use strict";
141
- init_runtime();
142
- if (isNode && typeof process !== "undefined") {
143
- try {
144
- http = __require("http");
145
- https = __require("https");
146
- } catch (e) {
147
- http = __require("http");
148
- https = __require("https");
166
+ init_utils();
167
+ ClientRequest2 = class extends EventEmitter2 {
168
+ constructor(_url, _options = {}) {
169
+ super();
170
+ this._bodyChunks = [];
171
+ this._ended = false;
149
172
  }
150
- }
173
+ _setNativeRequest(nativeRequest) {
174
+ this._nativeRequest = nativeRequest;
175
+ }
176
+ _setExecutor(executor) {
177
+ this._executor = executor;
178
+ }
179
+ write(chunk, encoding, callback) {
180
+ if (this._ended) {
181
+ throw new Error("Cannot write after end");
182
+ }
183
+ if (typeof encoding === "function") {
184
+ callback = encoding;
185
+ encoding = void 0;
186
+ }
187
+ if (this._nativeRequest) {
188
+ const actualEncoding2 = typeof encoding === "string" ? encoding : void 0;
189
+ return this._nativeRequest.write(chunk, actualEncoding2, callback);
190
+ }
191
+ const actualEncoding = typeof encoding === "string" ? encoding : "utf8";
192
+ this._bodyChunks.push(normalizeRequestBodyChunk(chunk, actualEncoding));
193
+ queueCallback(callback);
194
+ return true;
195
+ }
196
+ end(chunk, encoding, callback) {
197
+ if (typeof chunk === "function") {
198
+ callback = chunk;
199
+ chunk = void 0;
200
+ encoding = void 0;
201
+ } else if (typeof encoding === "function") {
202
+ callback = encoding;
203
+ encoding = void 0;
204
+ }
205
+ if (this._ended) {
206
+ queueCallback(callback);
207
+ return;
208
+ }
209
+ this._ended = true;
210
+ if (this._nativeRequest) {
211
+ const actualEncoding = typeof encoding === "string" ? encoding : void 0;
212
+ if (chunk !== void 0) {
213
+ this._nativeRequest.end(chunk, actualEncoding, callback);
214
+ } else {
215
+ this._nativeRequest.end(callback);
216
+ }
217
+ return;
218
+ }
219
+ if (chunk !== void 0) {
220
+ this._bodyChunks.push(normalizeRequestBodyChunk(chunk, typeof encoding === "string" ? encoding : "utf8"));
221
+ }
222
+ const executor = this._executor;
223
+ const body = buildRequestBody(this._bodyChunks);
224
+ if (executor) {
225
+ Promise.resolve().then(() => executor(body)).catch((error) => this.emit("error", error));
226
+ }
227
+ queueCallback(callback);
228
+ }
229
+ };
230
+ }
231
+ });
232
+
233
+ // src/server/http/constants.ts
234
+ var METHODS, STATUS_CODES;
235
+ var init_constants = __esm({
236
+ "src/server/http/constants.ts"() {
237
+ "use strict";
151
238
  METHODS = [
152
239
  "GET",
153
240
  "POST",
@@ -215,13 +302,30 @@ var init_http = __esm({
215
302
  510: "Not Extended",
216
303
  511: "Network Authentication Required"
217
304
  };
218
- IncomingMessage = class extends EventEmitter {
219
- constructor(req) {
305
+ }
306
+ });
307
+
308
+ // src/server/http/incoming-message.ts
309
+ import { EventEmitter as EventEmitter3 } from "events";
310
+ var IncomingMessage;
311
+ var init_incoming_message = __esm({
312
+ "src/server/http/incoming-message.ts"() {
313
+ "use strict";
314
+ init_utils();
315
+ IncomingMessage = class extends EventEmitter3 {
316
+ constructor(req, requestMethod) {
220
317
  super();
221
318
  this.httpVersion = "1.1";
222
319
  this.rawHeaders = [];
223
320
  this._req = req;
224
- if (isNode) {
321
+ if (isFetchResponse(req)) {
322
+ this.method = requestMethod || "GET";
323
+ this.url = getRequestPath(req.url);
324
+ this.headers = headersToRecord(req.headers);
325
+ this.statusCode = req.status;
326
+ this.statusMessage = req.statusText;
327
+ this.rawHeaders = headersToRawHeaders(req.headers);
328
+ } else if (isNodeIncomingMessage(req)) {
225
329
  this.method = req.method;
226
330
  this.url = req.url;
227
331
  this.headers = req.headers;
@@ -232,14 +336,13 @@ var init_http = __esm({
232
336
  this.socket = req.socket;
233
337
  } else {
234
338
  this.method = req.method;
235
- const urlObj = new URL(req.url);
236
- this.url = urlObj.pathname + urlObj.search;
237
- this.headers = req.headers;
238
- this.rawHeaders = [];
339
+ this.url = getRequestPath(req.url);
340
+ this.headers = headersToRecord(req.headers);
341
+ this.rawHeaders = headersToRawHeaders(req.headers);
239
342
  }
240
343
  }
241
344
  async text() {
242
- if (isNode) {
345
+ if (isNodeIncomingMessage(this._req)) {
243
346
  return new Promise((resolve, reject) => {
244
347
  const chunks = [];
245
348
  this._req.on("data", (chunk) => chunks.push(chunk));
@@ -250,14 +353,92 @@ var init_http = __esm({
250
353
  return this._req.text();
251
354
  }
252
355
  async json() {
253
- if (isNode) {
356
+ if (isNodeIncomingMessage(this._req)) {
254
357
  const text = await this.text();
255
358
  return JSON.parse(text);
256
359
  }
257
360
  return this._req.json();
258
361
  }
259
362
  };
260
- ServerResponse = class extends EventEmitter {
363
+ }
364
+ });
365
+
366
+ // src/server/http/node-modules.ts
367
+ var http, https;
368
+ var init_node_modules = __esm({
369
+ "src/server/http/node-modules.ts"() {
370
+ "use strict";
371
+ init_runtime();
372
+ if (isNode && typeof process !== "undefined") {
373
+ try {
374
+ http = __require("http");
375
+ https = __require("https");
376
+ } catch {
377
+ http = __require("http");
378
+ https = __require("https");
379
+ }
380
+ }
381
+ }
382
+ });
383
+
384
+ // src/server/http/request-api.ts
385
+ function request(url, options, callback) {
386
+ const urlString = typeof url === "string" ? url : url.toString();
387
+ const req = new ClientRequest2(urlString, options);
388
+ if (isNode) {
389
+ const urlObj = new URL(urlString);
390
+ const client = urlObj.protocol === "https:" ? https : http;
391
+ const nodeReq = client.request(urlString, {
392
+ method: options?.method || "GET",
393
+ headers: options?.headers,
394
+ timeout: options?.timeout,
395
+ signal: options?.signal
396
+ }, (res) => {
397
+ const incomingMessage = new IncomingMessage(res);
398
+ if (callback) callback(incomingMessage);
399
+ req.emit("response", incomingMessage);
400
+ });
401
+ req._setNativeRequest(nodeReq);
402
+ nodeReq.on("error", (error) => req.emit("error", error));
403
+ } else {
404
+ req._setExecutor(async (body) => {
405
+ const response = await fetch(urlString, {
406
+ method: options?.method || "GET",
407
+ headers: options?.headers,
408
+ body,
409
+ signal: options?.signal
410
+ });
411
+ const incomingMessage = new IncomingMessage(response, options?.method || "GET");
412
+ if (callback) callback(incomingMessage);
413
+ req.emit("response", incomingMessage);
414
+ });
415
+ }
416
+ return req;
417
+ }
418
+ function get(url, options, callback) {
419
+ const req = request(url, { ...options, method: "GET" }, callback);
420
+ req.end();
421
+ return req;
422
+ }
423
+ var init_request_api = __esm({
424
+ "src/server/http/request-api.ts"() {
425
+ "use strict";
426
+ init_runtime();
427
+ init_client_request();
428
+ init_incoming_message();
429
+ init_node_modules();
430
+ }
431
+ });
432
+
433
+ // src/server/http/response.ts
434
+ import { EventEmitter as EventEmitter4 } from "events";
435
+ var ServerResponse;
436
+ var init_response = __esm({
437
+ "src/server/http/response.ts"() {
438
+ "use strict";
439
+ init_runtime();
440
+ init_utils();
441
+ ServerResponse = class extends EventEmitter4 {
261
442
  constructor(_req, nodeRes) {
262
443
  super();
263
444
  this.statusCode = 200;
@@ -390,7 +571,6 @@ var init_http = __esm({
390
571
  _setResolver(resolve) {
391
572
  this._resolve = resolve;
392
573
  }
393
- // Express.js-like methods
394
574
  json(data, statusCode = 200) {
395
575
  if (!this.headersSent) {
396
576
  this.setHeader("Content-Type", "application/json");
@@ -414,7 +594,35 @@ var init_http = __esm({
414
594
  return this;
415
595
  }
416
596
  };
417
- Server = class extends EventEmitter {
597
+ }
598
+ });
599
+
600
+ // src/server/http/runtime.ts
601
+ function getRuntime() {
602
+ return runtime;
603
+ }
604
+ var init_runtime2 = __esm({
605
+ "src/server/http/runtime.ts"() {
606
+ "use strict";
607
+ init_runtime();
608
+ }
609
+ });
610
+
611
+ // src/server/http/server-runtime.ts
612
+ import { EventEmitter as EventEmitter5 } from "events";
613
+ function createServer(optionsOrListener, requestListener) {
614
+ return new Server(typeof optionsOrListener === "function" ? optionsOrListener : requestListener);
615
+ }
616
+ var Server;
617
+ var init_server_runtime = __esm({
618
+ "src/server/http/server-runtime.ts"() {
619
+ "use strict";
620
+ init_runtime();
621
+ init_node_modules();
622
+ init_incoming_message();
623
+ init_response();
624
+ init_utils();
625
+ Server = class extends EventEmitter5 {
418
626
  constructor(requestListener) {
419
627
  super();
420
628
  this._bunWebSocketServers = /* @__PURE__ */ new Set();
@@ -489,6 +697,8 @@ var init_http = __esm({
489
697
  const urlObj = new URL(req.url);
490
698
  const pathname = urlObj.pathname;
491
699
  const requestUrl = urlObj.pathname + urlObj.search;
700
+ const incomingHeaders = headersToRecord(req.headers);
701
+ const rawHeaders = headersToRawHeaders(req.headers);
492
702
  const upgradeHeader = req.headers.get("upgrade");
493
703
  if (upgradeHeader && upgradeHeader.toLowerCase() === "websocket") {
494
704
  const matchingWebSocketServer = Array.from(this._bunWebSocketServers).find((wsServer) => {
@@ -525,9 +735,9 @@ var init_http = __esm({
525
735
  const incomingMessage = {
526
736
  method: req.method,
527
737
  url: requestUrl,
528
- headers: req.headers,
738
+ headers: incomingHeaders,
529
739
  httpVersion: "1.1",
530
- rawHeaders: [],
740
+ rawHeaders,
531
741
  _req: req,
532
742
  text: () => req.text(),
533
743
  json: () => req.json()
@@ -586,6 +796,8 @@ var init_http = __esm({
586
796
  };
587
797
  if (self.requestListener) {
588
798
  self.requestListener(incomingMessage, serverResponse);
799
+ } else {
800
+ self.emit("request", incomingMessage, serverResponse);
589
801
  }
590
802
  if (responseReady) {
591
803
  return new Response(body, {
@@ -660,9 +872,11 @@ var init_http = __esm({
660
872
  return createAddress(0, addr, "unix");
661
873
  }
662
874
  return addr;
663
- } else if (isBun) {
875
+ }
876
+ if (isBun) {
664
877
  return createAddress(this.nativeServer.port, this.nativeServer.hostname);
665
- } else if (isDeno) {
878
+ }
879
+ if (isDeno) {
666
880
  const addr = this.nativeServer.addr;
667
881
  return createAddress(addr.port, addr.hostname);
668
882
  }
@@ -672,22 +886,45 @@ var init_http = __esm({
672
886
  return this._listening;
673
887
  }
674
888
  };
675
- ClientRequest = class extends EventEmitter {
676
- constructor(_url, _options = {}) {
677
- super();
678
- }
679
- write(_chunk) {
680
- return true;
681
- }
682
- end(callback) {
683
- queueCallback(callback);
684
- }
685
- };
686
- Agent = class {
687
- constructor(options) {
688
- this.options = options;
689
- }
690
- };
889
+ }
890
+ });
891
+
892
+ // src/server/http/index.ts
893
+ var http_exports = {};
894
+ __export(http_exports, {
895
+ Agent: () => Agent2,
896
+ ClientRequest: () => ClientRequest2,
897
+ IncomingMessage: () => IncomingMessage,
898
+ METHODS: () => METHODS,
899
+ STATUS_CODES: () => STATUS_CODES,
900
+ Server: () => Server,
901
+ ServerResponse: () => ServerResponse,
902
+ createServer: () => createServer,
903
+ default: () => http_default,
904
+ get: () => get,
905
+ getRuntime: () => getRuntime,
906
+ request: () => request
907
+ });
908
+ var http_default;
909
+ var init_http = __esm({
910
+ "src/server/http/index.ts"() {
911
+ "use strict";
912
+ init_agent();
913
+ init_client_request();
914
+ init_constants();
915
+ init_incoming_message();
916
+ init_request_api();
917
+ init_response();
918
+ init_runtime2();
919
+ init_server_runtime();
920
+ init_agent();
921
+ init_client_request();
922
+ init_constants();
923
+ init_incoming_message();
924
+ init_request_api();
925
+ init_response();
926
+ init_runtime2();
927
+ init_server_runtime();
691
928
  http_default = {
692
929
  createServer,
693
930
  request,
@@ -695,8 +932,8 @@ var init_http = __esm({
695
932
  Server,
696
933
  IncomingMessage,
697
934
  ServerResponse,
698
- Agent,
699
- ClientRequest,
935
+ Agent: Agent2,
936
+ ClientRequest: ClientRequest2,
700
937
  METHODS,
701
938
  STATUS_CODES,
702
939
  getRuntime
@@ -704,28 +941,83 @@ var init_http = __esm({
704
941
  }
705
942
  });
706
943
 
707
- // src/https.ts
944
+ // src/server/https/agent.ts
945
+ var Agent = class {
946
+ constructor(options) {
947
+ this.options = options;
948
+ }
949
+ };
950
+
951
+ // src/server/https/client-request.ts
952
+ init_utils();
953
+ import { EventEmitter } from "events";
954
+ var ClientRequest = class extends EventEmitter {
955
+ constructor(_url, _options = {}) {
956
+ super();
957
+ this._bodyChunks = [];
958
+ this._ended = false;
959
+ }
960
+ _setNativeRequest(nativeRequest) {
961
+ this._nativeRequest = nativeRequest;
962
+ }
963
+ _setExecutor(executor) {
964
+ this._executor = executor;
965
+ }
966
+ write(chunk, encoding, callback) {
967
+ if (this._ended) {
968
+ throw new Error("Cannot write after end");
969
+ }
970
+ if (typeof encoding === "function") {
971
+ callback = encoding;
972
+ encoding = void 0;
973
+ }
974
+ if (this._nativeRequest) {
975
+ const actualEncoding = typeof encoding === "string" ? encoding : void 0;
976
+ return this._nativeRequest.write(chunk, actualEncoding, callback);
977
+ }
978
+ this._bodyChunks.push(normalizeRequestBodyChunk(chunk, typeof encoding === "string" ? encoding : "utf8"));
979
+ queueCallback(callback);
980
+ return true;
981
+ }
982
+ end(chunk, encoding, callback) {
983
+ if (typeof chunk === "function") {
984
+ callback = chunk;
985
+ chunk = void 0;
986
+ encoding = void 0;
987
+ } else if (typeof encoding === "function") {
988
+ callback = encoding;
989
+ encoding = void 0;
990
+ }
991
+ if (this._ended) {
992
+ queueCallback(callback);
993
+ return;
994
+ }
995
+ this._ended = true;
996
+ if (this._nativeRequest) {
997
+ const actualEncoding = typeof encoding === "string" ? encoding : void 0;
998
+ if (chunk !== void 0) {
999
+ this._nativeRequest.end(chunk, actualEncoding, callback);
1000
+ } else {
1001
+ this._nativeRequest.end(callback);
1002
+ }
1003
+ return;
1004
+ }
1005
+ if (chunk !== void 0) {
1006
+ this._bodyChunks.push(normalizeRequestBodyChunk(chunk, typeof encoding === "string" ? encoding : "utf8"));
1007
+ }
1008
+ const executor = this._executor;
1009
+ const body = buildRequestBody(this._bodyChunks);
1010
+ if (executor) {
1011
+ Promise.resolve().then(() => executor(body)).catch((error) => this.emit("error", error));
1012
+ }
1013
+ queueCallback(callback);
1014
+ }
1015
+ };
1016
+
1017
+ // src/server/https/request-api.ts
708
1018
  init_runtime();
709
- import { EventEmitter as EventEmitter2 } from "events";
710
- function queueCallback2(callback) {
711
- if (callback) queueMicrotask(callback);
712
- }
713
- function createErrorResponse2() {
714
- return new Response("Internal Server Error", { status: 500 });
715
- }
716
- function createAddress2(port, address, family = "IPv4") {
717
- return { port, family, address };
718
- }
719
- function emitListeningWithCallback2(server, callback) {
720
- server._listening = true;
721
- server.emit("listening");
722
- queueCallback2(callback);
723
- }
724
- function closeAndEmit2(server, callback) {
725
- server._listening = false;
726
- server.emit("close");
727
- if (callback) queueMicrotask(() => callback());
728
- }
1019
+
1020
+ // src/server/https/http-classes.ts
729
1021
  function loadHttpClasses() {
730
1022
  const httpModule = (init_http(), __toCommonJS(http_exports));
731
1023
  return {
@@ -733,9 +1025,70 @@ function loadHttpClasses() {
733
1025
  ServerResponse: httpModule.ServerResponse
734
1026
  };
735
1027
  }
1028
+
1029
+ // src/server/https/node-modules.ts
1030
+ init_runtime();
736
1031
  var https2;
737
- var Server2 = class extends EventEmitter2 {
738
- constructor(options, requestListener) {
1032
+ if (isNode && typeof process !== "undefined") {
1033
+ try {
1034
+ https2 = __require("https");
1035
+ } catch {
1036
+ https2 = __require("https");
1037
+ }
1038
+ }
1039
+
1040
+ // src/server/https/request-api.ts
1041
+ function request2(url, options, callback) {
1042
+ const urlString = typeof url === "string" ? url : url.toString();
1043
+ const req = new ClientRequest(urlString, options);
1044
+ if (isNode) {
1045
+ const { IncomingMessage: IncomingMessage2 } = loadHttpClasses();
1046
+ const nodeReq = https2.request(urlString, {
1047
+ method: options?.method || "GET",
1048
+ headers: options?.headers,
1049
+ timeout: options?.timeout,
1050
+ signal: options?.signal
1051
+ }, (res) => {
1052
+ const incomingMessage = new IncomingMessage2(res);
1053
+ if (callback) callback(incomingMessage);
1054
+ req.emit("response", incomingMessage);
1055
+ });
1056
+ req._setNativeRequest(nodeReq);
1057
+ nodeReq.on("error", (error) => req.emit("error", error));
1058
+ } else {
1059
+ const { IncomingMessage: IncomingMessage2 } = loadHttpClasses();
1060
+ req._setExecutor(async (body) => {
1061
+ const response = await fetch(urlString, {
1062
+ method: options?.method || "GET",
1063
+ headers: options?.headers,
1064
+ body,
1065
+ signal: options?.signal
1066
+ });
1067
+ const incomingMessage = new IncomingMessage2(response, options?.method || "GET");
1068
+ if (callback) callback(incomingMessage);
1069
+ req.emit("response", incomingMessage);
1070
+ });
1071
+ }
1072
+ return req;
1073
+ }
1074
+ function get2(url, options, callback) {
1075
+ const req = request2(url, { ...options, method: "GET" }, callback);
1076
+ req.end();
1077
+ return req;
1078
+ }
1079
+
1080
+ // src/server/https/runtime.ts
1081
+ init_runtime();
1082
+ function getRuntime2() {
1083
+ return runtime;
1084
+ }
1085
+
1086
+ // src/server/https/server-runtime.ts
1087
+ init_runtime();
1088
+ init_utils();
1089
+ import { EventEmitter as EventEmitter6 } from "events";
1090
+ var Server2 = class extends EventEmitter6 {
1091
+ constructor(options = {}, requestListener) {
739
1092
  super();
740
1093
  this._listening = false;
741
1094
  this.options = options;
@@ -763,7 +1116,6 @@ var Server2 = class extends EventEmitter2 {
763
1116
  const self = this;
764
1117
  if (isNode) {
765
1118
  const { IncomingMessage: IncomingMessage2, ServerResponse: ServerResponse2 } = loadHttpClasses();
766
- if (!https2) https2 = __require("https");
767
1119
  this.nativeServer = https2.createServer(this.options, (req, res) => {
768
1120
  const incomingMessage = new IncomingMessage2(req);
769
1121
  const serverResponse = new ServerResponse2(incomingMessage, res);
@@ -802,7 +1154,7 @@ var Server2 = class extends EventEmitter2 {
802
1154
  },
803
1155
  error: (error) => {
804
1156
  this.emit("error", error);
805
- return createErrorResponse2();
1157
+ return createErrorResponse();
806
1158
  }
807
1159
  };
808
1160
  if (this.options.key || this.options.cert) {
@@ -816,7 +1168,7 @@ var Server2 = class extends EventEmitter2 {
816
1168
  tlsOptions.tls = this.options.tls;
817
1169
  }
818
1170
  this.nativeServer = Bun.serve(tlsOptions);
819
- emitListeningWithCallback2(this, callback);
1171
+ emitListeningWithCallback(this, callback);
820
1172
  } else if (isDeno) {
821
1173
  const { IncomingMessage: IncomingMessage2, ServerResponse: ServerResponse2 } = loadHttpClasses();
822
1174
  const serveOptions = {
@@ -836,7 +1188,7 @@ var Server2 = class extends EventEmitter2 {
836
1188
  },
837
1189
  onError: (error) => {
838
1190
  this.emit("error", error);
839
- return createErrorResponse2();
1191
+ return createErrorResponse();
840
1192
  }
841
1193
  };
842
1194
  if (this.options.key && this.options.cert) {
@@ -844,23 +1196,23 @@ var Server2 = class extends EventEmitter2 {
844
1196
  serveOptions.key = this.options.key;
845
1197
  }
846
1198
  this.nativeServer = Deno.serve(serveOptions);
847
- emitListeningWithCallback2(this, callback);
1199
+ emitListeningWithCallback(this, callback);
848
1200
  }
849
1201
  return this;
850
1202
  }
851
1203
  close(callback) {
852
1204
  if (!this.nativeServer) {
853
- if (callback) queueMicrotask(() => callback());
1205
+ if (callback) queueCallback(() => callback());
854
1206
  return this;
855
1207
  }
856
1208
  if (isNode) {
857
1209
  this.nativeServer.close(callback);
858
1210
  } else if (isBun) {
859
1211
  this.nativeServer.stop();
860
- closeAndEmit2(this, callback);
1212
+ closeAndEmit(this, callback);
861
1213
  } else if (isDeno) {
862
1214
  this.nativeServer.shutdown();
863
- closeAndEmit2(this, callback);
1215
+ closeAndEmit(this, callback);
864
1216
  }
865
1217
  return this;
866
1218
  }
@@ -870,14 +1222,16 @@ var Server2 = class extends EventEmitter2 {
870
1222
  const addr = this.nativeServer.address();
871
1223
  if (!addr) return null;
872
1224
  if (typeof addr === "string") {
873
- return createAddress2(0, addr, "unix");
1225
+ return createAddress(0, addr, "unix");
874
1226
  }
875
1227
  return addr;
876
- } else if (isBun) {
877
- return createAddress2(this.nativeServer.port, this.nativeServer.hostname);
878
- } else if (isDeno) {
1228
+ }
1229
+ if (isBun) {
1230
+ return createAddress(this.nativeServer.port, this.nativeServer.hostname);
1231
+ }
1232
+ if (isDeno) {
879
1233
  const addr = this.nativeServer.addr;
880
- return createAddress2(addr.port, addr.hostname);
1234
+ return createAddress(addr.port, addr.hostname);
881
1235
  }
882
1236
  return null;
883
1237
  }
@@ -885,83 +1239,23 @@ var Server2 = class extends EventEmitter2 {
885
1239
  return this._listening;
886
1240
  }
887
1241
  };
888
- var ClientRequest2 = class extends EventEmitter2 {
889
- constructor(_url, _options = {}) {
890
- super();
891
- }
892
- write(_chunk) {
893
- return true;
894
- }
895
- end(callback) {
896
- queueCallback2(callback);
897
- }
898
- };
899
- var Agent2 = class {
900
- constructor(options) {
901
- this.options = options;
902
- }
903
- };
904
- function createServer2(options, requestListener) {
1242
+ function createServer2(options = {}, requestListener) {
905
1243
  return new Server2(options, requestListener);
906
1244
  }
907
- function request2(url, options, callback) {
908
- const urlString = typeof url === "string" ? url : url.toString();
909
- const req = new ClientRequest2(urlString, options);
910
- if (isNode) {
911
- const { IncomingMessage: IncomingMessage2 } = loadHttpClasses();
912
- if (!https2) https2 = __require("https");
913
- const nodeReq = https2.request(urlString, {
914
- method: options?.method || "GET",
915
- headers: options?.headers,
916
- timeout: options?.timeout,
917
- signal: options?.signal
918
- }, (res) => {
919
- const incomingMessage = new IncomingMessage2(res);
920
- if (callback) callback(incomingMessage);
921
- req.emit("response", incomingMessage);
922
- });
923
- nodeReq.on("error", (error) => req.emit("error", error));
924
- nodeReq.end();
925
- } else {
926
- const { IncomingMessage: IncomingMessage2 } = loadHttpClasses();
927
- queueMicrotask(async () => {
928
- try {
929
- const response = await fetch(urlString, {
930
- method: options?.method || "GET",
931
- headers: options?.headers,
932
- signal: options?.signal
933
- });
934
- const fetchRequest = new Request(urlString);
935
- const incomingMessage = new IncomingMessage2(fetchRequest);
936
- incomingMessage.statusCode = response.status;
937
- incomingMessage.statusMessage = response.statusText;
938
- if (callback) callback(incomingMessage);
939
- req.emit("response", incomingMessage);
940
- } catch (error) {
941
- req.emit("error", error);
942
- }
943
- });
944
- }
945
- return req;
946
- }
947
- function get2(url, options, callback) {
948
- return request2(url, { ...options, method: "GET" }, callback);
949
- }
950
- function getRuntime2() {
951
- return runtime;
952
- }
1245
+
1246
+ // src/server/https/index.ts
953
1247
  var https_default = {
954
1248
  createServer: createServer2,
955
1249
  request: request2,
956
1250
  get: get2,
957
1251
  Server: Server2,
958
- Agent: Agent2,
959
- ClientRequest: ClientRequest2,
1252
+ Agent,
1253
+ ClientRequest,
960
1254
  getRuntime: getRuntime2
961
1255
  };
962
1256
  export {
963
- Agent2 as Agent,
964
- ClientRequest2 as ClientRequest,
1257
+ Agent,
1258
+ ClientRequest,
965
1259
  Server2 as Server,
966
1260
  createServer2 as createServer,
967
1261
  https_default as default,