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