aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/js/node/net.js24
-rw-r--r--src/js/out/InternalModuleRegistryConstants.h6
-rw-r--r--test/js/third_party/postgres/postgres.test.ts14
3 files changed, 36 insertions, 8 deletions
diff --git a/src/js/node/net.js b/src/js/node/net.js
index fc0aba548..f8da33d53 100644
--- a/src/js/node/net.js
+++ b/src/js/node/net.js
@@ -66,6 +66,9 @@ const bunSocketServerOptions = Symbol.for("::bunnetserveroptions::");
const bunSocketInternal = Symbol.for("::bunnetsocketinternal::");
const bunTLSConnectOptions = Symbol.for("::buntlsconnectoptions::");
+function closeNT(self) {
+ self.emit("close");
+}
function endNT(socket, callback, err) {
socket.end();
callback(err);
@@ -320,7 +323,7 @@ const Socket = (function (InternalSocket) {
this._parent = this;
this._parentWrap = this;
this.#pendingRead = undefined;
- this.#upgraded = false;
+ this.#upgraded = null;
if (socket instanceof Socket) {
this.#socket = socket;
}
@@ -355,6 +358,14 @@ const Socket = (function (InternalSocket) {
Socket.#Drain(socket);
}
+ #closeRawConnection() {
+ const connection = this.#upgraded;
+ connection[bunSocketInternal] = null;
+ connection.unref();
+ connection.destroy();
+ process.nextTick(closeNT, connection);
+ }
+
connect(port, host, connectListener) {
var path;
var connection = this.#socket;
@@ -455,7 +466,7 @@ const Socket = (function (InternalSocket) {
if (socket) {
this.connecting = true;
- this.#upgraded = true;
+ this.#upgraded = connection;
const result = socket.upgradeTLS({
data: this,
tls,
@@ -466,6 +477,7 @@ const Socket = (function (InternalSocket) {
// replace socket
connection[bunSocketInternal] = raw;
raw.timeout(raw.timeout);
+ this.once("end", this.#closeRawConnection);
raw.connecting = false;
this[bunSocketInternal] = tls;
} else {
@@ -479,7 +491,7 @@ const Socket = (function (InternalSocket) {
if (!socket) return;
this.connecting = true;
- this.#upgraded = true;
+ this.#upgraded = connection;
const result = socket.upgradeTLS({
data: this,
tls,
@@ -491,6 +503,7 @@ const Socket = (function (InternalSocket) {
// replace socket
connection[bunSocketInternal] = raw;
raw.timeout(raw.timeout);
+ this.once("end", this.#closeRawConnection);
raw.connecting = false;
this[bunSocketInternal] = tls;
} else {
@@ -537,6 +550,7 @@ const Socket = (function (InternalSocket) {
_final(callback) {
this[bunSocketInternal]?.end();
callback();
+ process.nextTick(closeNT, this);
}
get localAddress() {
@@ -559,8 +573,10 @@ const Socket = (function (InternalSocket) {
const queue = this.#readQueue;
let chunk;
while ((chunk = queue.peek())) {
- if (!this.push(chunk)) return;
+ const can_continue = !this.push(chunk);
+ // always remove from queue push will queue it internally if needed
queue.shift();
+ if (!can_continue) break;
}
}
diff --git a/src/js/out/InternalModuleRegistryConstants.h b/src/js/out/InternalModuleRegistryConstants.h
index 15a33c4a5..4693d99d1 100644
--- a/src/js/out/InternalModuleRegistryConstants.h
+++ b/src/js/out/InternalModuleRegistryConstants.h
@@ -114,7 +114,7 @@ static constexpr ASCIILiteral NodeInspectorCode = "(function (){\"use strict\";/
//
//
-static constexpr ASCIILiteral NodeNetCode = "(function (){\"use strict\";// src/js/out/tmp/node/net.ts\nvar isIPv4 = function(s) {\n return IPv4Reg.test(s);\n}, isIPv6 = function(s) {\n return IPv6Reg.test(s);\n}, isIP = function(s) {\n if (isIPv4(s))\n return 4;\n if (isIPv6(s))\n return 6;\n return 0;\n}, endNT = function(socket, callback, err) {\n socket.end(), callback(err);\n}, createConnection = function(port, host, connectListener) {\n if (typeof port === \"object\")\n return new Socket(port).connect(port, host, connectListener);\n return new Socket().connect(port, host, connectListener);\n}, emitErrorNextTick = function(self, error) {\n self.emit(\"error\", error);\n}, emitErrorAndCloseNextTick = function(self, error) {\n self.emit(\"error\", error), self.emit(\"close\");\n}, emitListeningNextTick = function(self, onListen) {\n if (typeof onListen === \"function\")\n try {\n onListen();\n } catch (err) {\n self.emit(\"error\", err);\n }\n self.emit(\"listening\");\n}, createServer = function(options, connectionListener) {\n return new Server(options, connectionListener);\n}, $, { Duplex } = @getInternalField(@internalModuleRegistry, 39) || @createInternalModuleById(39), EventEmitter = @getInternalField(@internalModuleRegistry, 20) || @createInternalModuleById(20);\nvar IPv4Reg = new @RegExp(\"^((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$\");\nvar IPv6Reg = new @RegExp(\"^((\?:(\?:[0-9a-fA-F]{1,4}):){7}(\?:(\?:[0-9a-fA-F]{1,4})|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){6}(\?:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|:(\?:[0-9a-fA-F]{1,4})|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){5}(\?::((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,2}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){4}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,1}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,3}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){3}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,2}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,4}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){2}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,3}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,5}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){1}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,4}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,6}|:)|(\?::((\?::(\?:[0-9a-fA-F]{1,4})){0,5}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(\?::(\?:[0-9a-fA-F]{1,4})){1,7}|:)))(%[0-9a-zA-Z-.:]{1,})\?$\"), { connect: bunConnect } = Bun, { setTimeout } = globalThis, bunTlsSymbol = Symbol.for(\"::buntls::\"), bunSocketServerHandlers = Symbol.for(\"::bunsocket_serverhandlers::\"), bunSocketServerConnections = Symbol.for(\"::bunnetserverconnections::\"), bunSocketServerOptions = Symbol.for(\"::bunnetserveroptions::\"), bunSocketInternal = Symbol.for(\"::bunnetsocketinternal::\"), bunTLSConnectOptions = Symbol.for(\"::buntlsconnectoptions::\"), SocketClass, Socket = function(InternalSocket) {\n SocketClass = InternalSocket, Object.defineProperty(SocketClass.prototype, Symbol.toStringTag, {\n value: \"Socket\",\n enumerable: !1\n });\n function Socket3(options) {\n return new InternalSocket(options);\n }\n return Socket3.prototype = InternalSocket.prototype, Object.defineProperty(Socket3, Symbol.hasInstance, {\n value(instance) {\n return instance instanceof InternalSocket;\n }\n });\n}(class Socket2 extends Duplex {\n static #Handlers = {\n close: Socket2.#Close,\n data({ data: self }, buffer) {\n self.bytesRead += buffer.length;\n const queue = self.#readQueue;\n if (queue.isEmpty()) {\n if (self.push(buffer))\n return;\n }\n queue.push(buffer);\n },\n drain: Socket2.#Drain,\n end: Socket2.#Close,\n error(socket, error) {\n const self = socket.data, callback = self.#writeCallback;\n if (callback)\n self.#writeCallback = null, callback(error);\n self.emit(\"error\", error);\n },\n open(socket) {\n const self = socket.data;\n socket.timeout(self.timeout), socket.ref(), self[bunSocketInternal] = socket, self.connecting = !1;\n const options = self[bunTLSConnectOptions];\n if (options) {\n const { session } = options;\n if (session)\n self.setSession(session);\n }\n if (!self.#upgraded)\n self.emit(\"connect\", self);\n Socket2.#Drain(socket);\n },\n handshake(socket, success, verifyError) {\n const { data: self } = socket;\n self._securePending = !1, self.secureConnecting = !1, self._secureEstablished = !!success, self.emit(\"secure\", self);\n const { checkServerIdentity } = self[bunTLSConnectOptions];\n if (!verifyError && typeof checkServerIdentity === \"function\" && self.servername) {\n const cert = self.getPeerCertificate(!0);\n verifyError = checkServerIdentity(self.servername, cert);\n }\n if (self._requestCert || self._rejectUnauthorized) {\n if (verifyError) {\n if (self.authorized = !1, self.authorizationError = verifyError.code || verifyError.message, self._rejectUnauthorized) {\n self.destroy(verifyError);\n return;\n }\n }\n } else\n self.authorized = !0;\n self.emit(\"secureConnect\", verifyError);\n },\n timeout(socket) {\n const self = socket.data;\n self.emit(\"timeout\", self);\n },\n binaryType: \"buffer\"\n };\n static #Close(socket) {\n const self = socket.data;\n if (self.#closed)\n return;\n self.#closed = !0, self[bunSocketInternal] = null;\n const queue = self.#readQueue;\n if (queue.isEmpty()) {\n if (self.push(null))\n return;\n }\n queue.push(null);\n }\n static #Drain(socket) {\n const self = socket.data, callback = self.#writeCallback;\n if (callback) {\n const chunk = self.#writeChunk, written = socket.write(chunk);\n if (self.bytesWritten += written, written < chunk.length)\n self.#writeChunk = chunk.slice(written);\n else\n self.#writeCallback = null, self.#writeChunk = null, callback(null);\n }\n }\n static [bunSocketServerHandlers] = {\n data: Socket2.#Handlers.data,\n close(socket) {\n Socket2.#Handlers.close(socket), this.data[bunSocketServerConnections]--;\n },\n end(socket) {\n Socket2.#Handlers.end(socket), this.data[bunSocketServerConnections]--;\n },\n open(socket) {\n const self = this.data, options = self[bunSocketServerOptions], { pauseOnConnect, connectionListener, InternalSocketClass, requestCert, rejectUnauthorized } = options, _socket = new InternalSocketClass({});\n if (_socket.isServer = !0, _socket._requestCert = requestCert, _socket._rejectUnauthorized = rejectUnauthorized, _socket.#attach(this.localPort, socket), self.maxConnections && self[bunSocketServerConnections] >= self.maxConnections) {\n const data = {\n localAddress: _socket.localAddress,\n localPort: _socket.localPort,\n localFamily: _socket.localFamily,\n remoteAddress: _socket.remoteAddress,\n remotePort: _socket.remotePort,\n remoteFamily: _socket.remoteFamily || \"IPv4\"\n };\n socket.end(), self.emit(\"drop\", data);\n return;\n }\n if (!pauseOnConnect)\n _socket.resume();\n if (self[bunSocketServerConnections]++, typeof connectionListener == \"function\")\n if (InternalSocketClass.name === \"TLSSocket\")\n self.once(\"secureConnection\", () => connectionListener(_socket));\n else\n connectionListener(_socket);\n self.emit(\"connection\", _socket);\n },\n handshake(socket, success, verifyError) {\n const { data: self } = socket;\n if (self.emit(\"secure\", self), self._securePending = !1, self.secureConnecting = !1, self._secureEstablished = !!success, self._requestCert || self._rejectUnauthorized) {\n if (verifyError) {\n if (self.authorized = !1, self.authorizationError = verifyError.code || verifyError.message, self._rejectUnauthorized) {\n self.destroy(verifyError);\n return;\n }\n }\n } else\n self.authorized = !0;\n self.emit(\"secureConnection\", verifyError);\n },\n error(socket, error) {\n Socket2.#Handlers.error(socket, error), this.data.emit(\"error\", error);\n },\n timeout: Socket2.#Handlers.timeout,\n connectError: Socket2.#Handlers.connectError,\n drain: Socket2.#Handlers.drain,\n binaryType: \"buffer\"\n };\n bytesRead = 0;\n bytesWritten = 0;\n #closed = !1;\n connecting = !1;\n localAddress = \"127.0.0.1\";\n #readQueue = @createFIFO();\n remotePort;\n [bunSocketInternal] = null;\n [bunTLSConnectOptions] = null;\n timeout = 0;\n #writeCallback;\n #writeChunk;\n #pendingRead;\n isServer = !1;\n _handle;\n _parent;\n _parentWrap;\n #socket;\n #upgraded;\n constructor(options) {\n const { socket, signal, write, read, allowHalfOpen = !1, ...opts } = options || {};\n super({\n ...opts,\n allowHalfOpen,\n readable: !0,\n writable: !0\n });\n if (this._handle = this, this._parent = this, this._parentWrap = this, this.#pendingRead = @undefined, this.#upgraded = !1, socket instanceof Socket2)\n this.#socket = socket;\n signal\?.once(\"abort\", () => this.destroy()), this.once(\"connect\", () => this.emit(\"ready\"));\n }\n address() {\n return {\n address: this.localAddress,\n family: this.localFamily,\n port: this.localPort\n };\n }\n get bufferSize() {\n return this.writableLength;\n }\n #attach(port, socket) {\n if (this.remotePort = port, socket.data = this, socket.timeout(this.timeout), socket.ref(), this[bunSocketInternal] = socket, this.connecting = !1, !this.#upgraded)\n this.emit(\"connect\", this);\n Socket2.#Drain(socket);\n }\n connect(port, host, connectListener) {\n var path, connection = this.#socket, _checkServerIdentity = @undefined;\n if (typeof port === \"string\") {\n if (path = port, port = @undefined, typeof host === \"function\")\n connectListener = host, host = @undefined;\n } else if (typeof host == \"function\") {\n if (typeof port === \"string\")\n path = port, port = @undefined;\n connectListener = host, host = @undefined;\n }\n if (typeof port == \"object\") {\n var {\n port,\n host,\n path,\n socket,\n localAddress,\n localPort,\n family,\n hints,\n lookup,\n noDelay,\n keepAlive,\n keepAliveInitialDelay,\n requestCert,\n rejectUnauthorized,\n pauseOnConnect,\n servername,\n checkServerIdentity,\n session\n } = port;\n if (_checkServerIdentity = checkServerIdentity, this.servername = servername, socket)\n connection = socket;\n }\n if (!pauseOnConnect)\n this.resume();\n this.connecting = !0, this.remotePort = port;\n const bunTLS = this[bunTlsSymbol];\n var tls = @undefined;\n if (typeof bunTLS === \"function\") {\n if (tls = bunTLS.call(this, port, host, !0), this._requestCert = !0, this._rejectUnauthorized = rejectUnauthorized, tls) {\n if (tls.rejectUnauthorized = rejectUnauthorized, tls.requestCert = !0, tls.session = session || tls.session, this.servername = tls.servername, tls.checkServerIdentity = _checkServerIdentity || tls.checkServerIdentity, this[bunTLSConnectOptions] = tls, !connection && tls.socket)\n connection = tls.socket;\n }\n if (connection) {\n if (typeof connection !== \"object\" || !(connection instanceof Socket2) || typeof connection[bunTlsSymbol] === \"function\")\n @throwTypeError(\"socket must be an instance of net.Socket\");\n }\n if (this.authorized = !1, this.secureConnecting = !0, this._secureEstablished = !1, this._securePending = !0, connectListener)\n this.on(\"secureConnect\", connectListener);\n } else if (connectListener)\n this.on(\"connect\", connectListener);\n try {\n if (connection) {\n const socket2 = connection[bunSocketInternal];\n if (socket2) {\n this.connecting = !0, this.#upgraded = !0;\n const result = socket2.upgradeTLS({\n data: this,\n tls,\n socket: Socket2.#Handlers\n });\n if (result) {\n const [raw, tls2] = result;\n connection[bunSocketInternal] = raw, raw.timeout(raw.timeout), raw.connecting = !1, this[bunSocketInternal] = tls2;\n } else\n throw this[bunSocketInternal] = null, new Error(\"Invalid socket\");\n } else\n connection.once(\"connect\", () => {\n const socket3 = connection[bunSocketInternal];\n if (!socket3)\n return;\n this.connecting = !0, this.#upgraded = !0;\n const result = socket3.upgradeTLS({\n data: this,\n tls,\n socket: Socket2.#Handlers\n });\n if (result) {\n const [raw, tls2] = result;\n connection[bunSocketInternal] = raw, raw.timeout(raw.timeout), raw.connecting = !1, this[bunSocketInternal] = tls2;\n } else\n throw this[bunSocketInternal] = null, new Error(\"Invalid socket\");\n });\n } else if (path)\n bunConnect({\n data: this,\n unix: path,\n socket: Socket2.#Handlers,\n tls\n }).catch((error) => {\n this.emit(\"error\", error), this.emit(\"close\");\n });\n else\n bunConnect({\n data: this,\n hostname: host || \"localhost\",\n port,\n socket: Socket2.#Handlers,\n tls\n }).catch((error) => {\n this.emit(\"error\", error), this.emit(\"close\");\n });\n } catch (error) {\n process.nextTick(emitErrorAndCloseNextTick, this, error);\n }\n return this;\n }\n _destroy(err, callback) {\n const socket = this[bunSocketInternal];\n socket && process.nextTick(endNT, socket, callback, err);\n }\n _final(callback) {\n this[bunSocketInternal]\?.end(), callback();\n }\n get localAddress() {\n return \"127.0.0.1\";\n }\n get localFamily() {\n return \"IPv4\";\n }\n get localPort() {\n return this[bunSocketInternal]\?.localPort;\n }\n get pending() {\n return this.connecting;\n }\n _read(size) {\n const queue = this.#readQueue;\n let chunk;\n while (chunk = queue.peek()) {\n if (!this.push(chunk))\n return;\n queue.shift();\n }\n }\n get readyState() {\n if (this.connecting)\n return \"opening\";\n if (this.readable)\n return this.writable \? \"open\" : \"readOnly\";\n else\n return this.writable \? \"writeOnly\" : \"closed\";\n }\n ref() {\n this[bunSocketInternal]\?.ref();\n }\n get remoteAddress() {\n return this[bunSocketInternal]\?.remoteAddress;\n }\n get remoteFamily() {\n return \"IPv4\";\n }\n resetAndDestroy() {\n this[bunSocketInternal]\?.end();\n }\n setKeepAlive(enable = !1, initialDelay = 0) {\n return this;\n }\n setNoDelay(noDelay = !0) {\n return this;\n }\n setTimeout(timeout, callback) {\n if (this[bunSocketInternal]\?.timeout(timeout), this.timeout = timeout, callback)\n this.once(\"timeout\", callback);\n return this;\n }\n unref() {\n this[bunSocketInternal]\?.unref();\n }\n _write(chunk, encoding, callback) {\n if (typeof chunk == \"string\" && encoding !== \"ascii\")\n chunk = @Buffer.from(chunk, encoding);\n var written = this[bunSocketInternal]\?.write(chunk);\n if (written == chunk.length)\n callback();\n else if (this.#writeCallback)\n callback(new Error(\"overlapping _write()\"));\n else {\n if (written > 0)\n if (typeof chunk == \"string\")\n chunk = chunk.slice(written);\n else\n chunk = chunk.subarray(written);\n this.#writeCallback = callback, this.#writeChunk = chunk;\n }\n }\n}), connect = createConnection;\n\nclass Server extends EventEmitter {\n #server;\n #listening = !1;\n [bunSocketServerConnections] = 0;\n [bunSocketServerOptions];\n maxConnections = 0;\n constructor(options, connectionListener) {\n super();\n if (typeof options === \"function\")\n connectionListener = options, options = {};\n else if (options == null || typeof options === \"object\")\n options = { ...options };\n else\n throw new Error(\"bun-net-polyfill: invalid arguments\");\n const { maxConnections } = options;\n this.maxConnections = Number.isSafeInteger(maxConnections) && maxConnections > 0 \? maxConnections : 0, options.connectionListener = connectionListener, this[bunSocketServerOptions] = options;\n }\n ref() {\n return this.#server\?.ref(), this;\n }\n unref() {\n return this.#server\?.unref(), this;\n }\n close(callback) {\n if (this.#server) {\n if (this.#server.stop(!0), this.#server = null, this.#listening = !1, this[bunSocketServerConnections] = 0, this.emit(\"close\"), typeof callback === \"function\")\n callback();\n return this;\n }\n if (typeof callback === \"function\") {\n const error = new Error(\"Server is not running\");\n error.code = \"ERR_SERVER_NOT_RUNNING\", callback(error);\n }\n return this;\n }\n address() {\n const server = this.#server;\n if (server) {\n const unix = server.unix;\n if (unix)\n return unix;\n let address = server.hostname;\n const type = isIP(address), port = server.port;\n if (typeof port === \"number\")\n return {\n port,\n address,\n family: type \? `IPv${type}` : @undefined\n };\n if (type)\n return {\n address,\n family: type \? `IPv${type}` : @undefined\n };\n return address;\n }\n return null;\n }\n getConnections(callback) {\n if (typeof callback === \"function\")\n callback(null, this.#server \? this[bunSocketServerConnections] : 0);\n return this;\n }\n listen(port, hostname, onListen) {\n let backlog, path, exclusive = !1;\n if (typeof port === \"string\") {\n if (Number.isSafeInteger(hostname)) {\n if (hostname > 0)\n backlog = hostname;\n } else if (typeof hostname === \"function\")\n onListen = hostname;\n path = port, hostname = @undefined, port = @undefined;\n } else {\n if (typeof hostname === \"function\")\n onListen = hostname, hostname = @undefined;\n if (typeof port === \"function\")\n onListen = port, port = 0;\n else if (typeof port === \"object\") {\n const options = port;\n options.signal\?.addEventListener(\"abort\", () => this.close()), hostname = options.host, exclusive = options.exclusive === !0;\n const path2 = options.path;\n if (port = options.port, !Number.isSafeInteger(port) || port < 0)\n if (path2)\n hostname = path2, port = @undefined;\n else {\n let message = 'The argument \\'options\\' must have the property \"port\" or \"path\"';\n try {\n message = `${message}. Received ${JSON.stringify(options)}`;\n } catch {\n }\n const error = @makeTypeError(message);\n throw error.code = \"ERR_INVALID_ARG_VALUE\", error;\n }\n else if (!Number.isSafeInteger(port) || port < 0)\n port = 0;\n if (typeof port.callback === \"function\")\n onListen = port\?.callback;\n } else if (!Number.isSafeInteger(port) || port < 0)\n port = 0;\n hostname = hostname || \"::\";\n }\n try {\n var tls = @undefined, TLSSocketClass = @undefined;\n const bunTLS = this[bunTlsSymbol], options = this[bunSocketServerOptions];\n if (typeof bunTLS === \"function\")\n [tls, TLSSocketClass] = bunTLS.call(this, port, hostname, !1), options.servername = tls.serverName, options.InternalSocketClass = TLSSocketClass;\n else\n options.InternalSocketClass = SocketClass;\n this.#server = Bun.listen(path \? {\n exclusive,\n unix: path,\n tls,\n socket: SocketClass[bunSocketServerHandlers]\n } : {\n exclusive,\n port,\n hostname,\n tls,\n socket: SocketClass[bunSocketServerHandlers]\n }), this.#server.data = this, this.#listening = !0, setTimeout(emitListeningNextTick, 1, this, onListen);\n } catch (err) {\n this.#listening = !1, setTimeout(emitErrorNextTick, 1, this, err);\n }\n return this;\n }\n}\n$ = {\n createServer,\n Server,\n createConnection,\n connect,\n isIP,\n isIPv4,\n isIPv6,\n Socket,\n [Symbol.for(\"::bunternal::\")]: SocketClass\n};\nreturn $})\n"_s;
+static constexpr ASCIILiteral NodeNetCode = "(function (){\"use strict\";// src/js/out/tmp/node/net.ts\nvar isIPv4 = function(s) {\n return IPv4Reg.test(s);\n}, isIPv6 = function(s) {\n return IPv6Reg.test(s);\n}, isIP = function(s) {\n if (isIPv4(s))\n return 4;\n if (isIPv6(s))\n return 6;\n return 0;\n}, closeNT = function(self) {\n self.emit(\"close\");\n}, endNT = function(socket, callback, err) {\n socket.end(), callback(err);\n}, createConnection = function(port, host, connectListener) {\n if (typeof port === \"object\")\n return new Socket(port).connect(port, host, connectListener);\n return new Socket().connect(port, host, connectListener);\n}, emitErrorNextTick = function(self, error) {\n self.emit(\"error\", error);\n}, emitErrorAndCloseNextTick = function(self, error) {\n self.emit(\"error\", error), self.emit(\"close\");\n}, emitListeningNextTick = function(self, onListen) {\n if (typeof onListen === \"function\")\n try {\n onListen();\n } catch (err) {\n self.emit(\"error\", err);\n }\n self.emit(\"listening\");\n}, createServer = function(options, connectionListener) {\n return new Server(options, connectionListener);\n}, $, { Duplex } = @getInternalField(@internalModuleRegistry, 39) || @createInternalModuleById(39), EventEmitter = @getInternalField(@internalModuleRegistry, 20) || @createInternalModuleById(20);\nvar IPv4Reg = new @RegExp(\"^((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$\");\nvar IPv6Reg = new @RegExp(\"^((\?:(\?:[0-9a-fA-F]{1,4}):){7}(\?:(\?:[0-9a-fA-F]{1,4})|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){6}(\?:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|:(\?:[0-9a-fA-F]{1,4})|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){5}(\?::((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,2}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){4}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,1}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,3}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){3}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,2}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,4}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){2}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,3}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,5}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){1}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,4}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,6}|:)|(\?::((\?::(\?:[0-9a-fA-F]{1,4})){0,5}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(\?::(\?:[0-9a-fA-F]{1,4})){1,7}|:)))(%[0-9a-zA-Z-.:]{1,})\?$\"), { connect: bunConnect } = Bun, { setTimeout } = globalThis, bunTlsSymbol = Symbol.for(\"::buntls::\"), bunSocketServerHandlers = Symbol.for(\"::bunsocket_serverhandlers::\"), bunSocketServerConnections = Symbol.for(\"::bunnetserverconnections::\"), bunSocketServerOptions = Symbol.for(\"::bunnetserveroptions::\"), bunSocketInternal = Symbol.for(\"::bunnetsocketinternal::\"), bunTLSConnectOptions = Symbol.for(\"::buntlsconnectoptions::\"), SocketClass, Socket = function(InternalSocket) {\n SocketClass = InternalSocket, Object.defineProperty(SocketClass.prototype, Symbol.toStringTag, {\n value: \"Socket\",\n enumerable: !1\n });\n function Socket3(options) {\n return new InternalSocket(options);\n }\n return Socket3.prototype = InternalSocket.prototype, Object.defineProperty(Socket3, Symbol.hasInstance, {\n value(instance) {\n return instance instanceof InternalSocket;\n }\n });\n}(class Socket2 extends Duplex {\n static #Handlers = {\n close: Socket2.#Close,\n data({ data: self }, buffer) {\n self.bytesRead += buffer.length;\n const queue = self.#readQueue;\n if (queue.isEmpty()) {\n if (self.push(buffer))\n return;\n }\n queue.push(buffer);\n },\n drain: Socket2.#Drain,\n end: Socket2.#Close,\n error(socket, error) {\n const self = socket.data, callback = self.#writeCallback;\n if (callback)\n self.#writeCallback = null, callback(error);\n self.emit(\"error\", error);\n },\n open(socket) {\n const self = socket.data;\n socket.timeout(self.timeout), socket.ref(), self[bunSocketInternal] = socket, self.connecting = !1;\n const options = self[bunTLSConnectOptions];\n if (options) {\n const { session } = options;\n if (session)\n self.setSession(session);\n }\n if (!self.#upgraded)\n self.emit(\"connect\", self);\n Socket2.#Drain(socket);\n },\n handshake(socket, success, verifyError) {\n const { data: self } = socket;\n self._securePending = !1, self.secureConnecting = !1, self._secureEstablished = !!success, self.emit(\"secure\", self);\n const { checkServerIdentity } = self[bunTLSConnectOptions];\n if (!verifyError && typeof checkServerIdentity === \"function\" && self.servername) {\n const cert = self.getPeerCertificate(!0);\n verifyError = checkServerIdentity(self.servername, cert);\n }\n if (self._requestCert || self._rejectUnauthorized) {\n if (verifyError) {\n if (self.authorized = !1, self.authorizationError = verifyError.code || verifyError.message, self._rejectUnauthorized) {\n self.destroy(verifyError);\n return;\n }\n }\n } else\n self.authorized = !0;\n self.emit(\"secureConnect\", verifyError);\n },\n timeout(socket) {\n const self = socket.data;\n self.emit(\"timeout\", self);\n },\n binaryType: \"buffer\"\n };\n static #Close(socket) {\n const self = socket.data;\n if (self.#closed)\n return;\n self.#closed = !0, self[bunSocketInternal] = null;\n const queue = self.#readQueue;\n if (queue.isEmpty()) {\n if (self.push(null))\n return;\n }\n queue.push(null);\n }\n static #Drain(socket) {\n const self = socket.data, callback = self.#writeCallback;\n if (callback) {\n const chunk = self.#writeChunk, written = socket.write(chunk);\n if (self.bytesWritten += written, written < chunk.length)\n self.#writeChunk = chunk.slice(written);\n else\n self.#writeCallback = null, self.#writeChunk = null, callback(null);\n }\n }\n static [bunSocketServerHandlers] = {\n data: Socket2.#Handlers.data,\n close(socket) {\n Socket2.#Handlers.close(socket), this.data[bunSocketServerConnections]--;\n },\n end(socket) {\n Socket2.#Handlers.end(socket), this.data[bunSocketServerConnections]--;\n },\n open(socket) {\n const self = this.data, options = self[bunSocketServerOptions], { pauseOnConnect, connectionListener, InternalSocketClass, requestCert, rejectUnauthorized } = options, _socket = new InternalSocketClass({});\n if (_socket.isServer = !0, _socket._requestCert = requestCert, _socket._rejectUnauthorized = rejectUnauthorized, _socket.#attach(this.localPort, socket), self.maxConnections && self[bunSocketServerConnections] >= self.maxConnections) {\n const data = {\n localAddress: _socket.localAddress,\n localPort: _socket.localPort,\n localFamily: _socket.localFamily,\n remoteAddress: _socket.remoteAddress,\n remotePort: _socket.remotePort,\n remoteFamily: _socket.remoteFamily || \"IPv4\"\n };\n socket.end(), self.emit(\"drop\", data);\n return;\n }\n if (!pauseOnConnect)\n _socket.resume();\n if (self[bunSocketServerConnections]++, typeof connectionListener == \"function\")\n if (InternalSocketClass.name === \"TLSSocket\")\n self.once(\"secureConnection\", () => connectionListener(_socket));\n else\n connectionListener(_socket);\n self.emit(\"connection\", _socket);\n },\n handshake(socket, success, verifyError) {\n const { data: self } = socket;\n if (self.emit(\"secure\", self), self._securePending = !1, self.secureConnecting = !1, self._secureEstablished = !!success, self._requestCert || self._rejectUnauthorized) {\n if (verifyError) {\n if (self.authorized = !1, self.authorizationError = verifyError.code || verifyError.message, self._rejectUnauthorized) {\n self.destroy(verifyError);\n return;\n }\n }\n } else\n self.authorized = !0;\n self.emit(\"secureConnection\", verifyError);\n },\n error(socket, error) {\n Socket2.#Handlers.error(socket, error), this.data.emit(\"error\", error);\n },\n timeout: Socket2.#Handlers.timeout,\n connectError: Socket2.#Handlers.connectError,\n drain: Socket2.#Handlers.drain,\n binaryType: \"buffer\"\n };\n bytesRead = 0;\n bytesWritten = 0;\n #closed = !1;\n connecting = !1;\n localAddress = \"127.0.0.1\";\n #readQueue = @createFIFO();\n remotePort;\n [bunSocketInternal] = null;\n [bunTLSConnectOptions] = null;\n timeout = 0;\n #writeCallback;\n #writeChunk;\n #pendingRead;\n isServer = !1;\n _handle;\n _parent;\n _parentWrap;\n #socket;\n #upgraded;\n constructor(options) {\n const { socket, signal, write, read, allowHalfOpen = !1, ...opts } = options || {};\n super({\n ...opts,\n allowHalfOpen,\n readable: !0,\n writable: !0\n });\n if (this._handle = this, this._parent = this, this._parentWrap = this, this.#pendingRead = @undefined, this.#upgraded = null, socket instanceof Socket2)\n this.#socket = socket;\n signal\?.once(\"abort\", () => this.destroy()), this.once(\"connect\", () => this.emit(\"ready\"));\n }\n address() {\n return {\n address: this.localAddress,\n family: this.localFamily,\n port: this.localPort\n };\n }\n get bufferSize() {\n return this.writableLength;\n }\n #attach(port, socket) {\n if (this.remotePort = port, socket.data = this, socket.timeout(this.timeout), socket.ref(), this[bunSocketInternal] = socket, this.connecting = !1, !this.#upgraded)\n this.emit(\"connect\", this);\n Socket2.#Drain(socket);\n }\n #closeRawConnection() {\n const connection = this.#upgraded;\n connection[bunSocketInternal] = null, connection.unref(), connection.destroy(), process.nextTick(closeNT, connection);\n }\n connect(port, host, connectListener) {\n var path, connection = this.#socket, _checkServerIdentity = @undefined;\n if (typeof port === \"string\") {\n if (path = port, port = @undefined, typeof host === \"function\")\n connectListener = host, host = @undefined;\n } else if (typeof host == \"function\") {\n if (typeof port === \"string\")\n path = port, port = @undefined;\n connectListener = host, host = @undefined;\n }\n if (typeof port == \"object\") {\n var {\n port,\n host,\n path,\n socket,\n localAddress,\n localPort,\n family,\n hints,\n lookup,\n noDelay,\n keepAlive,\n keepAliveInitialDelay,\n requestCert,\n rejectUnauthorized,\n pauseOnConnect,\n servername,\n checkServerIdentity,\n session\n } = port;\n if (_checkServerIdentity = checkServerIdentity, this.servername = servername, socket)\n connection = socket;\n }\n if (!pauseOnConnect)\n this.resume();\n this.connecting = !0, this.remotePort = port;\n const bunTLS = this[bunTlsSymbol];\n var tls = @undefined;\n if (typeof bunTLS === \"function\") {\n if (tls = bunTLS.call(this, port, host, !0), this._requestCert = !0, this._rejectUnauthorized = rejectUnauthorized, tls) {\n if (tls.rejectUnauthorized = rejectUnauthorized, tls.requestCert = !0, tls.session = session || tls.session, this.servername = tls.servername, tls.checkServerIdentity = _checkServerIdentity || tls.checkServerIdentity, this[bunTLSConnectOptions] = tls, !connection && tls.socket)\n connection = tls.socket;\n }\n if (connection) {\n if (typeof connection !== \"object\" || !(connection instanceof Socket2) || typeof connection[bunTlsSymbol] === \"function\")\n @throwTypeError(\"socket must be an instance of net.Socket\");\n }\n if (this.authorized = !1, this.secureConnecting = !0, this._secureEstablished = !1, this._securePending = !0, connectListener)\n this.on(\"secureConnect\", connectListener);\n } else if (connectListener)\n this.on(\"connect\", connectListener);\n try {\n if (connection) {\n const socket2 = connection[bunSocketInternal];\n if (socket2) {\n this.connecting = !0, this.#upgraded = connection;\n const result = socket2.upgradeTLS({\n data: this,\n tls,\n socket: Socket2.#Handlers\n });\n if (result) {\n const [raw, tls2] = result;\n connection[bunSocketInternal] = raw, raw.timeout(raw.timeout), this.once(\"end\", this.#closeRawConnection), raw.connecting = !1, this[bunSocketInternal] = tls2;\n } else\n throw this[bunSocketInternal] = null, new Error(\"Invalid socket\");\n } else\n connection.once(\"connect\", () => {\n const socket3 = connection[bunSocketInternal];\n if (!socket3)\n return;\n this.connecting = !0, this.#upgraded = connection;\n const result = socket3.upgradeTLS({\n data: this,\n tls,\n socket: Socket2.#Handlers\n });\n if (result) {\n const [raw, tls2] = result;\n connection[bunSocketInternal] = raw, raw.timeout(raw.timeout), this.once(\"end\", this.#closeRawConnection), raw.connecting = !1, this[bunSocketInternal] = tls2;\n } else\n throw this[bunSocketInternal] = null, new Error(\"Invalid socket\");\n });\n } else if (path)\n bunConnect({\n data: this,\n unix: path,\n socket: Socket2.#Handlers,\n tls\n }).catch((error) => {\n this.emit(\"error\", error), this.emit(\"close\");\n });\n else\n bunConnect({\n data: this,\n hostname: host || \"localhost\",\n port,\n socket: Socket2.#Handlers,\n tls\n }).catch((error) => {\n this.emit(\"error\", error), this.emit(\"close\");\n });\n } catch (error) {\n process.nextTick(emitErrorAndCloseNextTick, this, error);\n }\n return this;\n }\n _destroy(err, callback) {\n const socket = this[bunSocketInternal];\n socket && process.nextTick(endNT, socket, callback, err);\n }\n _final(callback) {\n this[bunSocketInternal]\?.end(), callback(), process.nextTick(closeNT, this);\n }\n get localAddress() {\n return \"127.0.0.1\";\n }\n get localFamily() {\n return \"IPv4\";\n }\n get localPort() {\n return this[bunSocketInternal]\?.localPort;\n }\n get pending() {\n return this.connecting;\n }\n _read(size) {\n const queue = this.#readQueue;\n let chunk;\n while (chunk = queue.peek()) {\n const success = !this.push(chunk);\n if (queue.shift(), !success)\n break;\n }\n }\n get readyState() {\n if (this.connecting)\n return \"opening\";\n if (this.readable)\n return this.writable \? \"open\" : \"readOnly\";\n else\n return this.writable \? \"writeOnly\" : \"closed\";\n }\n ref() {\n this[bunSocketInternal]\?.ref();\n }\n get remoteAddress() {\n return this[bunSocketInternal]\?.remoteAddress;\n }\n get remoteFamily() {\n return \"IPv4\";\n }\n resetAndDestroy() {\n this[bunSocketInternal]\?.end();\n }\n setKeepAlive(enable = !1, initialDelay = 0) {\n return this;\n }\n setNoDelay(noDelay = !0) {\n return this;\n }\n setTimeout(timeout, callback) {\n if (this[bunSocketInternal]\?.timeout(timeout), this.timeout = timeout, callback)\n this.once(\"timeout\", callback);\n return this;\n }\n unref() {\n this[bunSocketInternal]\?.unref();\n }\n _write(chunk, encoding, callback) {\n if (typeof chunk == \"string\" && encoding !== \"ascii\")\n chunk = @Buffer.from(chunk, encoding);\n var written = this[bunSocketInternal]\?.write(chunk);\n if (written == chunk.length)\n callback();\n else if (this.#writeCallback)\n callback(new Error(\"overlapping _write()\"));\n else {\n if (written > 0)\n if (typeof chunk == \"string\")\n chunk = chunk.slice(written);\n else\n chunk = chunk.subarray(written);\n this.#writeCallback = callback, this.#writeChunk = chunk;\n }\n }\n}), connect = createConnection;\n\nclass Server extends EventEmitter {\n #server;\n #listening = !1;\n [bunSocketServerConnections] = 0;\n [bunSocketServerOptions];\n maxConnections = 0;\n constructor(options, connectionListener) {\n super();\n if (typeof options === \"function\")\n connectionListener = options, options = {};\n else if (options == null || typeof options === \"object\")\n options = { ...options };\n else\n throw new Error(\"bun-net-polyfill: invalid arguments\");\n const { maxConnections } = options;\n this.maxConnections = Number.isSafeInteger(maxConnections) && maxConnections > 0 \? maxConnections : 0, options.connectionListener = connectionListener, this[bunSocketServerOptions] = options;\n }\n ref() {\n return this.#server\?.ref(), this;\n }\n unref() {\n return this.#server\?.unref(), this;\n }\n close(callback) {\n if (this.#server) {\n if (this.#server.stop(!0), this.#server = null, this.#listening = !1, this[bunSocketServerConnections] = 0, this.emit(\"close\"), typeof callback === \"function\")\n callback();\n return this;\n }\n if (typeof callback === \"function\") {\n const error = new Error(\"Server is not running\");\n error.code = \"ERR_SERVER_NOT_RUNNING\", callback(error);\n }\n return this;\n }\n address() {\n const server = this.#server;\n if (server) {\n const unix = server.unix;\n if (unix)\n return unix;\n let address = server.hostname;\n const type = isIP(address), port = server.port;\n if (typeof port === \"number\")\n return {\n port,\n address,\n family: type \? `IPv${type}` : @undefined\n };\n if (type)\n return {\n address,\n family: type \? `IPv${type}` : @undefined\n };\n return address;\n }\n return null;\n }\n getConnections(callback) {\n if (typeof callback === \"function\")\n callback(null, this.#server \? this[bunSocketServerConnections] : 0);\n return this;\n }\n listen(port, hostname, onListen) {\n let backlog, path, exclusive = !1;\n if (typeof port === \"string\") {\n if (Number.isSafeInteger(hostname)) {\n if (hostname > 0)\n backlog = hostname;\n } else if (typeof hostname === \"function\")\n onListen = hostname;\n path = port, hostname = @undefined, port = @undefined;\n } else {\n if (typeof hostname === \"function\")\n onListen = hostname, hostname = @undefined;\n if (typeof port === \"function\")\n onListen = port, port = 0;\n else if (typeof port === \"object\") {\n const options = port;\n options.signal\?.addEventListener(\"abort\", () => this.close()), hostname = options.host, exclusive = options.exclusive === !0;\n const path2 = options.path;\n if (port = options.port, !Number.isSafeInteger(port) || port < 0)\n if (path2)\n hostname = path2, port = @undefined;\n else {\n let message = 'The argument \\'options\\' must have the property \"port\" or \"path\"';\n try {\n message = `${message}. Received ${JSON.stringify(options)}`;\n } catch {\n }\n const error = @makeTypeError(message);\n throw error.code = \"ERR_INVALID_ARG_VALUE\", error;\n }\n else if (!Number.isSafeInteger(port) || port < 0)\n port = 0;\n if (typeof port.callback === \"function\")\n onListen = port\?.callback;\n } else if (!Number.isSafeInteger(port) || port < 0)\n port = 0;\n hostname = hostname || \"::\";\n }\n try {\n var tls = @undefined, TLSSocketClass = @undefined;\n const bunTLS = this[bunTlsSymbol], options = this[bunSocketServerOptions];\n if (typeof bunTLS === \"function\")\n [tls, TLSSocketClass] = bunTLS.call(this, port, hostname, !1), options.servername = tls.serverName, options.InternalSocketClass = TLSSocketClass;\n else\n options.InternalSocketClass = SocketClass;\n this.#server = Bun.listen(path \? {\n exclusive,\n unix: path,\n tls,\n socket: SocketClass[bunSocketServerHandlers]\n } : {\n exclusive,\n port,\n hostname,\n tls,\n socket: SocketClass[bunSocketServerHandlers]\n }), this.#server.data = this, this.#listening = !0, setTimeout(emitListeningNextTick, 1, this, onListen);\n } catch (err) {\n this.#listening = !1, setTimeout(emitErrorNextTick, 1, this, err);\n }\n return this;\n }\n}\n$ = {\n createServer,\n Server,\n createConnection,\n connect,\n isIP,\n isIPv4,\n isIPv6,\n Socket,\n [Symbol.for(\"::bunternal::\")]: SocketClass\n};\nreturn $})\n"_s;
//
//
@@ -363,7 +363,7 @@ static constexpr ASCIILiteral NodeInspectorCode = "(function (){\"use strict\";/
//
//
-static constexpr ASCIILiteral NodeNetCode = "(function (){\"use strict\";// src/js/out/tmp/node/net.ts\nvar isIPv4 = function(s) {\n return IPv4Reg.test(s);\n}, isIPv6 = function(s) {\n return IPv6Reg.test(s);\n}, isIP = function(s) {\n if (isIPv4(s))\n return 4;\n if (isIPv6(s))\n return 6;\n return 0;\n}, endNT = function(socket, callback, err) {\n socket.end(), callback(err);\n}, createConnection = function(port, host, connectListener) {\n if (typeof port === \"object\")\n return new Socket(port).connect(port, host, connectListener);\n return new Socket().connect(port, host, connectListener);\n}, emitErrorNextTick = function(self, error) {\n self.emit(\"error\", error);\n}, emitErrorAndCloseNextTick = function(self, error) {\n self.emit(\"error\", error), self.emit(\"close\");\n}, emitListeningNextTick = function(self, onListen) {\n if (typeof onListen === \"function\")\n try {\n onListen();\n } catch (err) {\n self.emit(\"error\", err);\n }\n self.emit(\"listening\");\n}, createServer = function(options, connectionListener) {\n return new Server(options, connectionListener);\n}, $, { Duplex } = @getInternalField(@internalModuleRegistry, 39) || @createInternalModuleById(39), EventEmitter = @getInternalField(@internalModuleRegistry, 20) || @createInternalModuleById(20);\nvar IPv4Reg = new @RegExp(\"^((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$\");\nvar IPv6Reg = new @RegExp(\"^((\?:(\?:[0-9a-fA-F]{1,4}):){7}(\?:(\?:[0-9a-fA-F]{1,4})|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){6}(\?:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|:(\?:[0-9a-fA-F]{1,4})|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){5}(\?::((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,2}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){4}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,1}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,3}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){3}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,2}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,4}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){2}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,3}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,5}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){1}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,4}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,6}|:)|(\?::((\?::(\?:[0-9a-fA-F]{1,4})){0,5}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(\?::(\?:[0-9a-fA-F]{1,4})){1,7}|:)))(%[0-9a-zA-Z-.:]{1,})\?$\"), { connect: bunConnect } = Bun, { setTimeout } = globalThis, bunTlsSymbol = Symbol.for(\"::buntls::\"), bunSocketServerHandlers = Symbol.for(\"::bunsocket_serverhandlers::\"), bunSocketServerConnections = Symbol.for(\"::bunnetserverconnections::\"), bunSocketServerOptions = Symbol.for(\"::bunnetserveroptions::\"), bunSocketInternal = Symbol.for(\"::bunnetsocketinternal::\"), bunTLSConnectOptions = Symbol.for(\"::buntlsconnectoptions::\"), SocketClass, Socket = function(InternalSocket) {\n SocketClass = InternalSocket, Object.defineProperty(SocketClass.prototype, Symbol.toStringTag, {\n value: \"Socket\",\n enumerable: !1\n });\n function Socket3(options) {\n return new InternalSocket(options);\n }\n return Socket3.prototype = InternalSocket.prototype, Object.defineProperty(Socket3, Symbol.hasInstance, {\n value(instance) {\n return instance instanceof InternalSocket;\n }\n });\n}(class Socket2 extends Duplex {\n static #Handlers = {\n close: Socket2.#Close,\n data({ data: self }, buffer) {\n self.bytesRead += buffer.length;\n const queue = self.#readQueue;\n if (queue.isEmpty()) {\n if (self.push(buffer))\n return;\n }\n queue.push(buffer);\n },\n drain: Socket2.#Drain,\n end: Socket2.#Close,\n error(socket, error) {\n const self = socket.data, callback = self.#writeCallback;\n if (callback)\n self.#writeCallback = null, callback(error);\n self.emit(\"error\", error);\n },\n open(socket) {\n const self = socket.data;\n socket.timeout(self.timeout), socket.ref(), self[bunSocketInternal] = socket, self.connecting = !1;\n const options = self[bunTLSConnectOptions];\n if (options) {\n const { session } = options;\n if (session)\n self.setSession(session);\n }\n if (!self.#upgraded)\n self.emit(\"connect\", self);\n Socket2.#Drain(socket);\n },\n handshake(socket, success, verifyError) {\n const { data: self } = socket;\n self._securePending = !1, self.secureConnecting = !1, self._secureEstablished = !!success, self.emit(\"secure\", self);\n const { checkServerIdentity } = self[bunTLSConnectOptions];\n if (!verifyError && typeof checkServerIdentity === \"function\" && self.servername) {\n const cert = self.getPeerCertificate(!0);\n verifyError = checkServerIdentity(self.servername, cert);\n }\n if (self._requestCert || self._rejectUnauthorized) {\n if (verifyError) {\n if (self.authorized = !1, self.authorizationError = verifyError.code || verifyError.message, self._rejectUnauthorized) {\n self.destroy(verifyError);\n return;\n }\n }\n } else\n self.authorized = !0;\n self.emit(\"secureConnect\", verifyError);\n },\n timeout(socket) {\n const self = socket.data;\n self.emit(\"timeout\", self);\n },\n binaryType: \"buffer\"\n };\n static #Close(socket) {\n const self = socket.data;\n if (self.#closed)\n return;\n self.#closed = !0, self[bunSocketInternal] = null;\n const queue = self.#readQueue;\n if (queue.isEmpty()) {\n if (self.push(null))\n return;\n }\n queue.push(null);\n }\n static #Drain(socket) {\n const self = socket.data, callback = self.#writeCallback;\n if (callback) {\n const chunk = self.#writeChunk, written = socket.write(chunk);\n if (self.bytesWritten += written, written < chunk.length)\n self.#writeChunk = chunk.slice(written);\n else\n self.#writeCallback = null, self.#writeChunk = null, callback(null);\n }\n }\n static [bunSocketServerHandlers] = {\n data: Socket2.#Handlers.data,\n close(socket) {\n Socket2.#Handlers.close(socket), this.data[bunSocketServerConnections]--;\n },\n end(socket) {\n Socket2.#Handlers.end(socket), this.data[bunSocketServerConnections]--;\n },\n open(socket) {\n const self = this.data, options = self[bunSocketServerOptions], { pauseOnConnect, connectionListener, InternalSocketClass, requestCert, rejectUnauthorized } = options, _socket = new InternalSocketClass({});\n if (_socket.isServer = !0, _socket._requestCert = requestCert, _socket._rejectUnauthorized = rejectUnauthorized, _socket.#attach(this.localPort, socket), self.maxConnections && self[bunSocketServerConnections] >= self.maxConnections) {\n const data = {\n localAddress: _socket.localAddress,\n localPort: _socket.localPort,\n localFamily: _socket.localFamily,\n remoteAddress: _socket.remoteAddress,\n remotePort: _socket.remotePort,\n remoteFamily: _socket.remoteFamily || \"IPv4\"\n };\n socket.end(), self.emit(\"drop\", data);\n return;\n }\n if (!pauseOnConnect)\n _socket.resume();\n if (self[bunSocketServerConnections]++, typeof connectionListener == \"function\")\n if (InternalSocketClass.name === \"TLSSocket\")\n self.once(\"secureConnection\", () => connectionListener(_socket));\n else\n connectionListener(_socket);\n self.emit(\"connection\", _socket);\n },\n handshake(socket, success, verifyError) {\n const { data: self } = socket;\n if (self.emit(\"secure\", self), self._securePending = !1, self.secureConnecting = !1, self._secureEstablished = !!success, self._requestCert || self._rejectUnauthorized) {\n if (verifyError) {\n if (self.authorized = !1, self.authorizationError = verifyError.code || verifyError.message, self._rejectUnauthorized) {\n self.destroy(verifyError);\n return;\n }\n }\n } else\n self.authorized = !0;\n self.emit(\"secureConnection\", verifyError);\n },\n error(socket, error) {\n Socket2.#Handlers.error(socket, error), this.data.emit(\"error\", error);\n },\n timeout: Socket2.#Handlers.timeout,\n connectError: Socket2.#Handlers.connectError,\n drain: Socket2.#Handlers.drain,\n binaryType: \"buffer\"\n };\n bytesRead = 0;\n bytesWritten = 0;\n #closed = !1;\n connecting = !1;\n localAddress = \"127.0.0.1\";\n #readQueue = @createFIFO();\n remotePort;\n [bunSocketInternal] = null;\n [bunTLSConnectOptions] = null;\n timeout = 0;\n #writeCallback;\n #writeChunk;\n #pendingRead;\n isServer = !1;\n _handle;\n _parent;\n _parentWrap;\n #socket;\n #upgraded;\n constructor(options) {\n const { socket, signal, write, read, allowHalfOpen = !1, ...opts } = options || {};\n super({\n ...opts,\n allowHalfOpen,\n readable: !0,\n writable: !0\n });\n if (this._handle = this, this._parent = this, this._parentWrap = this, this.#pendingRead = @undefined, this.#upgraded = !1, socket instanceof Socket2)\n this.#socket = socket;\n signal\?.once(\"abort\", () => this.destroy()), this.once(\"connect\", () => this.emit(\"ready\"));\n }\n address() {\n return {\n address: this.localAddress,\n family: this.localFamily,\n port: this.localPort\n };\n }\n get bufferSize() {\n return this.writableLength;\n }\n #attach(port, socket) {\n if (this.remotePort = port, socket.data = this, socket.timeout(this.timeout), socket.ref(), this[bunSocketInternal] = socket, this.connecting = !1, !this.#upgraded)\n this.emit(\"connect\", this);\n Socket2.#Drain(socket);\n }\n connect(port, host, connectListener) {\n var path, connection = this.#socket, _checkServerIdentity = @undefined;\n if (typeof port === \"string\") {\n if (path = port, port = @undefined, typeof host === \"function\")\n connectListener = host, host = @undefined;\n } else if (typeof host == \"function\") {\n if (typeof port === \"string\")\n path = port, port = @undefined;\n connectListener = host, host = @undefined;\n }\n if (typeof port == \"object\") {\n var {\n port,\n host,\n path,\n socket,\n localAddress,\n localPort,\n family,\n hints,\n lookup,\n noDelay,\n keepAlive,\n keepAliveInitialDelay,\n requestCert,\n rejectUnauthorized,\n pauseOnConnect,\n servername,\n checkServerIdentity,\n session\n } = port;\n if (_checkServerIdentity = checkServerIdentity, this.servername = servername, socket)\n connection = socket;\n }\n if (!pauseOnConnect)\n this.resume();\n this.connecting = !0, this.remotePort = port;\n const bunTLS = this[bunTlsSymbol];\n var tls = @undefined;\n if (typeof bunTLS === \"function\") {\n if (tls = bunTLS.call(this, port, host, !0), this._requestCert = !0, this._rejectUnauthorized = rejectUnauthorized, tls) {\n if (tls.rejectUnauthorized = rejectUnauthorized, tls.requestCert = !0, tls.session = session || tls.session, this.servername = tls.servername, tls.checkServerIdentity = _checkServerIdentity || tls.checkServerIdentity, this[bunTLSConnectOptions] = tls, !connection && tls.socket)\n connection = tls.socket;\n }\n if (connection) {\n if (typeof connection !== \"object\" || !(connection instanceof Socket2) || typeof connection[bunTlsSymbol] === \"function\")\n @throwTypeError(\"socket must be an instance of net.Socket\");\n }\n if (this.authorized = !1, this.secureConnecting = !0, this._secureEstablished = !1, this._securePending = !0, connectListener)\n this.on(\"secureConnect\", connectListener);\n } else if (connectListener)\n this.on(\"connect\", connectListener);\n try {\n if (connection) {\n const socket2 = connection[bunSocketInternal];\n if (socket2) {\n this.connecting = !0, this.#upgraded = !0;\n const result = socket2.upgradeTLS({\n data: this,\n tls,\n socket: Socket2.#Handlers\n });\n if (result) {\n const [raw, tls2] = result;\n connection[bunSocketInternal] = raw, raw.timeout(raw.timeout), raw.connecting = !1, this[bunSocketInternal] = tls2;\n } else\n throw this[bunSocketInternal] = null, new Error(\"Invalid socket\");\n } else\n connection.once(\"connect\", () => {\n const socket3 = connection[bunSocketInternal];\n if (!socket3)\n return;\n this.connecting = !0, this.#upgraded = !0;\n const result = socket3.upgradeTLS({\n data: this,\n tls,\n socket: Socket2.#Handlers\n });\n if (result) {\n const [raw, tls2] = result;\n connection[bunSocketInternal] = raw, raw.timeout(raw.timeout), raw.connecting = !1, this[bunSocketInternal] = tls2;\n } else\n throw this[bunSocketInternal] = null, new Error(\"Invalid socket\");\n });\n } else if (path)\n bunConnect({\n data: this,\n unix: path,\n socket: Socket2.#Handlers,\n tls\n }).catch((error) => {\n this.emit(\"error\", error), this.emit(\"close\");\n });\n else\n bunConnect({\n data: this,\n hostname: host || \"localhost\",\n port,\n socket: Socket2.#Handlers,\n tls\n }).catch((error) => {\n this.emit(\"error\", error), this.emit(\"close\");\n });\n } catch (error) {\n process.nextTick(emitErrorAndCloseNextTick, this, error);\n }\n return this;\n }\n _destroy(err, callback) {\n const socket = this[bunSocketInternal];\n socket && process.nextTick(endNT, socket, callback, err);\n }\n _final(callback) {\n this[bunSocketInternal]\?.end(), callback();\n }\n get localAddress() {\n return \"127.0.0.1\";\n }\n get localFamily() {\n return \"IPv4\";\n }\n get localPort() {\n return this[bunSocketInternal]\?.localPort;\n }\n get pending() {\n return this.connecting;\n }\n _read(size) {\n const queue = this.#readQueue;\n let chunk;\n while (chunk = queue.peek()) {\n if (!this.push(chunk))\n return;\n queue.shift();\n }\n }\n get readyState() {\n if (this.connecting)\n return \"opening\";\n if (this.readable)\n return this.writable \? \"open\" : \"readOnly\";\n else\n return this.writable \? \"writeOnly\" : \"closed\";\n }\n ref() {\n this[bunSocketInternal]\?.ref();\n }\n get remoteAddress() {\n return this[bunSocketInternal]\?.remoteAddress;\n }\n get remoteFamily() {\n return \"IPv4\";\n }\n resetAndDestroy() {\n this[bunSocketInternal]\?.end();\n }\n setKeepAlive(enable = !1, initialDelay = 0) {\n return this;\n }\n setNoDelay(noDelay = !0) {\n return this;\n }\n setTimeout(timeout, callback) {\n if (this[bunSocketInternal]\?.timeout(timeout), this.timeout = timeout, callback)\n this.once(\"timeout\", callback);\n return this;\n }\n unref() {\n this[bunSocketInternal]\?.unref();\n }\n _write(chunk, encoding, callback) {\n if (typeof chunk == \"string\" && encoding !== \"ascii\")\n chunk = @Buffer.from(chunk, encoding);\n var written = this[bunSocketInternal]\?.write(chunk);\n if (written == chunk.length)\n callback();\n else if (this.#writeCallback)\n callback(new Error(\"overlapping _write()\"));\n else {\n if (written > 0)\n if (typeof chunk == \"string\")\n chunk = chunk.slice(written);\n else\n chunk = chunk.subarray(written);\n this.#writeCallback = callback, this.#writeChunk = chunk;\n }\n }\n}), connect = createConnection;\n\nclass Server extends EventEmitter {\n #server;\n #listening = !1;\n [bunSocketServerConnections] = 0;\n [bunSocketServerOptions];\n maxConnections = 0;\n constructor(options, connectionListener) {\n super();\n if (typeof options === \"function\")\n connectionListener = options, options = {};\n else if (options == null || typeof options === \"object\")\n options = { ...options };\n else\n throw new Error(\"bun-net-polyfill: invalid arguments\");\n const { maxConnections } = options;\n this.maxConnections = Number.isSafeInteger(maxConnections) && maxConnections > 0 \? maxConnections : 0, options.connectionListener = connectionListener, this[bunSocketServerOptions] = options;\n }\n ref() {\n return this.#server\?.ref(), this;\n }\n unref() {\n return this.#server\?.unref(), this;\n }\n close(callback) {\n if (this.#server) {\n if (this.#server.stop(!0), this.#server = null, this.#listening = !1, this[bunSocketServerConnections] = 0, this.emit(\"close\"), typeof callback === \"function\")\n callback();\n return this;\n }\n if (typeof callback === \"function\") {\n const error = new Error(\"Server is not running\");\n error.code = \"ERR_SERVER_NOT_RUNNING\", callback(error);\n }\n return this;\n }\n address() {\n const server = this.#server;\n if (server) {\n const unix = server.unix;\n if (unix)\n return unix;\n let address = server.hostname;\n const type = isIP(address), port = server.port;\n if (typeof port === \"number\")\n return {\n port,\n address,\n family: type \? `IPv${type}` : @undefined\n };\n if (type)\n return {\n address,\n family: type \? `IPv${type}` : @undefined\n };\n return address;\n }\n return null;\n }\n getConnections(callback) {\n if (typeof callback === \"function\")\n callback(null, this.#server \? this[bunSocketServerConnections] : 0);\n return this;\n }\n listen(port, hostname, onListen) {\n let backlog, path, exclusive = !1;\n if (typeof port === \"string\") {\n if (Number.isSafeInteger(hostname)) {\n if (hostname > 0)\n backlog = hostname;\n } else if (typeof hostname === \"function\")\n onListen = hostname;\n path = port, hostname = @undefined, port = @undefined;\n } else {\n if (typeof hostname === \"function\")\n onListen = hostname, hostname = @undefined;\n if (typeof port === \"function\")\n onListen = port, port = 0;\n else if (typeof port === \"object\") {\n const options = port;\n options.signal\?.addEventListener(\"abort\", () => this.close()), hostname = options.host, exclusive = options.exclusive === !0;\n const path2 = options.path;\n if (port = options.port, !Number.isSafeInteger(port) || port < 0)\n if (path2)\n hostname = path2, port = @undefined;\n else {\n let message = 'The argument \\'options\\' must have the property \"port\" or \"path\"';\n try {\n message = `${message}. Received ${JSON.stringify(options)}`;\n } catch {\n }\n const error = @makeTypeError(message);\n throw error.code = \"ERR_INVALID_ARG_VALUE\", error;\n }\n else if (!Number.isSafeInteger(port) || port < 0)\n port = 0;\n if (typeof port.callback === \"function\")\n onListen = port\?.callback;\n } else if (!Number.isSafeInteger(port) || port < 0)\n port = 0;\n hostname = hostname || \"::\";\n }\n try {\n var tls = @undefined, TLSSocketClass = @undefined;\n const bunTLS = this[bunTlsSymbol], options = this[bunSocketServerOptions];\n if (typeof bunTLS === \"function\")\n [tls, TLSSocketClass] = bunTLS.call(this, port, hostname, !1), options.servername = tls.serverName, options.InternalSocketClass = TLSSocketClass;\n else\n options.InternalSocketClass = SocketClass;\n this.#server = Bun.listen(path \? {\n exclusive,\n unix: path,\n tls,\n socket: SocketClass[bunSocketServerHandlers]\n } : {\n exclusive,\n port,\n hostname,\n tls,\n socket: SocketClass[bunSocketServerHandlers]\n }), this.#server.data = this, this.#listening = !0, setTimeout(emitListeningNextTick, 1, this, onListen);\n } catch (err) {\n this.#listening = !1, setTimeout(emitErrorNextTick, 1, this, err);\n }\n return this;\n }\n}\n$ = {\n createServer,\n Server,\n createConnection,\n connect,\n isIP,\n isIPv4,\n isIPv6,\n Socket,\n [Symbol.for(\"::bunternal::\")]: SocketClass\n};\nreturn $})\n"_s;
+static constexpr ASCIILiteral NodeNetCode = "(function (){\"use strict\";// src/js/out/tmp/node/net.ts\nvar isIPv4 = function(s) {\n return IPv4Reg.test(s);\n}, isIPv6 = function(s) {\n return IPv6Reg.test(s);\n}, isIP = function(s) {\n if (isIPv4(s))\n return 4;\n if (isIPv6(s))\n return 6;\n return 0;\n}, closeNT = function(self) {\n self.emit(\"close\");\n}, endNT = function(socket, callback, err) {\n socket.end(), callback(err);\n}, createConnection = function(port, host, connectListener) {\n if (typeof port === \"object\")\n return new Socket(port).connect(port, host, connectListener);\n return new Socket().connect(port, host, connectListener);\n}, emitErrorNextTick = function(self, error) {\n self.emit(\"error\", error);\n}, emitErrorAndCloseNextTick = function(self, error) {\n self.emit(\"error\", error), self.emit(\"close\");\n}, emitListeningNextTick = function(self, onListen) {\n if (typeof onListen === \"function\")\n try {\n onListen();\n } catch (err) {\n self.emit(\"error\", err);\n }\n self.emit(\"listening\");\n}, createServer = function(options, connectionListener) {\n return new Server(options, connectionListener);\n}, $, { Duplex } = @getInternalField(@internalModuleRegistry, 39) || @createInternalModuleById(39), EventEmitter = @getInternalField(@internalModuleRegistry, 20) || @createInternalModuleById(20);\nvar IPv4Reg = new @RegExp(\"^((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$\");\nvar IPv6Reg = new @RegExp(\"^((\?:(\?:[0-9a-fA-F]{1,4}):){7}(\?:(\?:[0-9a-fA-F]{1,4})|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){6}(\?:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|:(\?:[0-9a-fA-F]{1,4})|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){5}(\?::((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,2}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){4}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,1}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,3}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){3}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,2}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,4}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){2}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,3}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,5}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){1}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,4}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,6}|:)|(\?::((\?::(\?:[0-9a-fA-F]{1,4})){0,5}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(\?::(\?:[0-9a-fA-F]{1,4})){1,7}|:)))(%[0-9a-zA-Z-.:]{1,})\?$\"), { connect: bunConnect } = Bun, { setTimeout } = globalThis, bunTlsSymbol = Symbol.for(\"::buntls::\"), bunSocketServerHandlers = Symbol.for(\"::bunsocket_serverhandlers::\"), bunSocketServerConnections = Symbol.for(\"::bunnetserverconnections::\"), bunSocketServerOptions = Symbol.for(\"::bunnetserveroptions::\"), bunSocketInternal = Symbol.for(\"::bunnetsocketinternal::\"), bunTLSConnectOptions = Symbol.for(\"::buntlsconnectoptions::\"), SocketClass, Socket = function(InternalSocket) {\n SocketClass = InternalSocket, Object.defineProperty(SocketClass.prototype, Symbol.toStringTag, {\n value: \"Socket\",\n enumerable: !1\n });\n function Socket3(options) {\n return new InternalSocket(options);\n }\n return Socket3.prototype = InternalSocket.prototype, Object.defineProperty(Socket3, Symbol.hasInstance, {\n value(instance) {\n return instance instanceof InternalSocket;\n }\n });\n}(class Socket2 extends Duplex {\n static #Handlers = {\n close: Socket2.#Close,\n data({ data: self }, buffer) {\n self.bytesRead += buffer.length;\n const queue = self.#readQueue;\n if (queue.isEmpty()) {\n if (self.push(buffer))\n return;\n }\n queue.push(buffer);\n },\n drain: Socket2.#Drain,\n end: Socket2.#Close,\n error(socket, error) {\n const self = socket.data, callback = self.#writeCallback;\n if (callback)\n self.#writeCallback = null, callback(error);\n self.emit(\"error\", error);\n },\n open(socket) {\n const self = socket.data;\n socket.timeout(self.timeout), socket.ref(), self[bunSocketInternal] = socket, self.connecting = !1;\n const options = self[bunTLSConnectOptions];\n if (options) {\n const { session } = options;\n if (session)\n self.setSession(session);\n }\n if (!self.#upgraded)\n self.emit(\"connect\", self);\n Socket2.#Drain(socket);\n },\n handshake(socket, success, verifyError) {\n const { data: self } = socket;\n self._securePending = !1, self.secureConnecting = !1, self._secureEstablished = !!success, self.emit(\"secure\", self);\n const { checkServerIdentity } = self[bunTLSConnectOptions];\n if (!verifyError && typeof checkServerIdentity === \"function\" && self.servername) {\n const cert = self.getPeerCertificate(!0);\n verifyError = checkServerIdentity(self.servername, cert);\n }\n if (self._requestCert || self._rejectUnauthorized) {\n if (verifyError) {\n if (self.authorized = !1, self.authorizationError = verifyError.code || verifyError.message, self._rejectUnauthorized) {\n self.destroy(verifyError);\n return;\n }\n }\n } else\n self.authorized = !0;\n self.emit(\"secureConnect\", verifyError);\n },\n timeout(socket) {\n const self = socket.data;\n self.emit(\"timeout\", self);\n },\n binaryType: \"buffer\"\n };\n static #Close(socket) {\n const self = socket.data;\n if (self.#closed)\n return;\n self.#closed = !0, self[bunSocketInternal] = null;\n const queue = self.#readQueue;\n if (queue.isEmpty()) {\n if (self.push(null))\n return;\n }\n queue.push(null);\n }\n static #Drain(socket) {\n const self = socket.data, callback = self.#writeCallback;\n if (callback) {\n const chunk = self.#writeChunk, written = socket.write(chunk);\n if (self.bytesWritten += written, written < chunk.length)\n self.#writeChunk = chunk.slice(written);\n else\n self.#writeCallback = null, self.#writeChunk = null, callback(null);\n }\n }\n static [bunSocketServerHandlers] = {\n data: Socket2.#Handlers.data,\n close(socket) {\n Socket2.#Handlers.close(socket), this.data[bunSocketServerConnections]--;\n },\n end(socket) {\n Socket2.#Handlers.end(socket), this.data[bunSocketServerConnections]--;\n },\n open(socket) {\n const self = this.data, options = self[bunSocketServerOptions], { pauseOnConnect, connectionListener, InternalSocketClass, requestCert, rejectUnauthorized } = options, _socket = new InternalSocketClass({});\n if (_socket.isServer = !0, _socket._requestCert = requestCert, _socket._rejectUnauthorized = rejectUnauthorized, _socket.#attach(this.localPort, socket), self.maxConnections && self[bunSocketServerConnections] >= self.maxConnections) {\n const data = {\n localAddress: _socket.localAddress,\n localPort: _socket.localPort,\n localFamily: _socket.localFamily,\n remoteAddress: _socket.remoteAddress,\n remotePort: _socket.remotePort,\n remoteFamily: _socket.remoteFamily || \"IPv4\"\n };\n socket.end(), self.emit(\"drop\", data);\n return;\n }\n if (!pauseOnConnect)\n _socket.resume();\n if (self[bunSocketServerConnections]++, typeof connectionListener == \"function\")\n if (InternalSocketClass.name === \"TLSSocket\")\n self.once(\"secureConnection\", () => connectionListener(_socket));\n else\n connectionListener(_socket);\n self.emit(\"connection\", _socket);\n },\n handshake(socket, success, verifyError) {\n const { data: self } = socket;\n if (self.emit(\"secure\", self), self._securePending = !1, self.secureConnecting = !1, self._secureEstablished = !!success, self._requestCert || self._rejectUnauthorized) {\n if (verifyError) {\n if (self.authorized = !1, self.authorizationError = verifyError.code || verifyError.message, self._rejectUnauthorized) {\n self.destroy(verifyError);\n return;\n }\n }\n } else\n self.authorized = !0;\n self.emit(\"secureConnection\", verifyError);\n },\n error(socket, error) {\n Socket2.#Handlers.error(socket, error), this.data.emit(\"error\", error);\n },\n timeout: Socket2.#Handlers.timeout,\n connectError: Socket2.#Handlers.connectError,\n drain: Socket2.#Handlers.drain,\n binaryType: \"buffer\"\n };\n bytesRead = 0;\n bytesWritten = 0;\n #closed = !1;\n connecting = !1;\n localAddress = \"127.0.0.1\";\n #readQueue = @createFIFO();\n remotePort;\n [bunSocketInternal] = null;\n [bunTLSConnectOptions] = null;\n timeout = 0;\n #writeCallback;\n #writeChunk;\n #pendingRead;\n isServer = !1;\n _handle;\n _parent;\n _parentWrap;\n #socket;\n #upgraded;\n constructor(options) {\n const { socket, signal, write, read, allowHalfOpen = !1, ...opts } = options || {};\n super({\n ...opts,\n allowHalfOpen,\n readable: !0,\n writable: !0\n });\n if (this._handle = this, this._parent = this, this._parentWrap = this, this.#pendingRead = @undefined, this.#upgraded = null, socket instanceof Socket2)\n this.#socket = socket;\n signal\?.once(\"abort\", () => this.destroy()), this.once(\"connect\", () => this.emit(\"ready\"));\n }\n address() {\n return {\n address: this.localAddress,\n family: this.localFamily,\n port: this.localPort\n };\n }\n get bufferSize() {\n return this.writableLength;\n }\n #attach(port, socket) {\n if (this.remotePort = port, socket.data = this, socket.timeout(this.timeout), socket.ref(), this[bunSocketInternal] = socket, this.connecting = !1, !this.#upgraded)\n this.emit(\"connect\", this);\n Socket2.#Drain(socket);\n }\n #closeRawConnection() {\n const connection = this.#upgraded;\n connection[bunSocketInternal] = null, connection.unref(), connection.destroy(), process.nextTick(closeNT, connection);\n }\n connect(port, host, connectListener) {\n var path, connection = this.#socket, _checkServerIdentity = @undefined;\n if (typeof port === \"string\") {\n if (path = port, port = @undefined, typeof host === \"function\")\n connectListener = host, host = @undefined;\n } else if (typeof host == \"function\") {\n if (typeof port === \"string\")\n path = port, port = @undefined;\n connectListener = host, host = @undefined;\n }\n if (typeof port == \"object\") {\n var {\n port,\n host,\n path,\n socket,\n localAddress,\n localPort,\n family,\n hints,\n lookup,\n noDelay,\n keepAlive,\n keepAliveInitialDelay,\n requestCert,\n rejectUnauthorized,\n pauseOnConnect,\n servername,\n checkServerIdentity,\n session\n } = port;\n if (_checkServerIdentity = checkServerIdentity, this.servername = servername, socket)\n connection = socket;\n }\n if (!pauseOnConnect)\n this.resume();\n this.connecting = !0, this.remotePort = port;\n const bunTLS = this[bunTlsSymbol];\n var tls = @undefined;\n if (typeof bunTLS === \"function\") {\n if (tls = bunTLS.call(this, port, host, !0), this._requestCert = !0, this._rejectUnauthorized = rejectUnauthorized, tls) {\n if (tls.rejectUnauthorized = rejectUnauthorized, tls.requestCert = !0, tls.session = session || tls.session, this.servername = tls.servername, tls.checkServerIdentity = _checkServerIdentity || tls.checkServerIdentity, this[bunTLSConnectOptions] = tls, !connection && tls.socket)\n connection = tls.socket;\n }\n if (connection) {\n if (typeof connection !== \"object\" || !(connection instanceof Socket2) || typeof connection[bunTlsSymbol] === \"function\")\n @throwTypeError(\"socket must be an instance of net.Socket\");\n }\n if (this.authorized = !1, this.secureConnecting = !0, this._secureEstablished = !1, this._securePending = !0, connectListener)\n this.on(\"secureConnect\", connectListener);\n } else if (connectListener)\n this.on(\"connect\", connectListener);\n try {\n if (connection) {\n const socket2 = connection[bunSocketInternal];\n if (socket2) {\n this.connecting = !0, this.#upgraded = connection;\n const result = socket2.upgradeTLS({\n data: this,\n tls,\n socket: Socket2.#Handlers\n });\n if (result) {\n const [raw, tls2] = result;\n connection[bunSocketInternal] = raw, raw.timeout(raw.timeout), this.once(\"end\", this.#closeRawConnection), raw.connecting = !1, this[bunSocketInternal] = tls2;\n } else\n throw this[bunSocketInternal] = null, new Error(\"Invalid socket\");\n } else\n connection.once(\"connect\", () => {\n const socket3 = connection[bunSocketInternal];\n if (!socket3)\n return;\n this.connecting = !0, this.#upgraded = connection;\n const result = socket3.upgradeTLS({\n data: this,\n tls,\n socket: Socket2.#Handlers\n });\n if (result) {\n const [raw, tls2] = result;\n connection[bunSocketInternal] = raw, raw.timeout(raw.timeout), this.once(\"end\", this.#closeRawConnection), raw.connecting = !1, this[bunSocketInternal] = tls2;\n } else\n throw this[bunSocketInternal] = null, new Error(\"Invalid socket\");\n });\n } else if (path)\n bunConnect({\n data: this,\n unix: path,\n socket: Socket2.#Handlers,\n tls\n }).catch((error) => {\n this.emit(\"error\", error), this.emit(\"close\");\n });\n else\n bunConnect({\n data: this,\n hostname: host || \"localhost\",\n port,\n socket: Socket2.#Handlers,\n tls\n }).catch((error) => {\n this.emit(\"error\", error), this.emit(\"close\");\n });\n } catch (error) {\n process.nextTick(emitErrorAndCloseNextTick, this, error);\n }\n return this;\n }\n _destroy(err, callback) {\n const socket = this[bunSocketInternal];\n socket && process.nextTick(endNT, socket, callback, err);\n }\n _final(callback) {\n this[bunSocketInternal]\?.end(), callback(), process.nextTick(closeNT, this);\n }\n get localAddress() {\n return \"127.0.0.1\";\n }\n get localFamily() {\n return \"IPv4\";\n }\n get localPort() {\n return this[bunSocketInternal]\?.localPort;\n }\n get pending() {\n return this.connecting;\n }\n _read(size) {\n const queue = this.#readQueue;\n let chunk;\n while (chunk = queue.peek()) {\n const success = !this.push(chunk);\n if (queue.shift(), !success)\n break;\n }\n }\n get readyState() {\n if (this.connecting)\n return \"opening\";\n if (this.readable)\n return this.writable \? \"open\" : \"readOnly\";\n else\n return this.writable \? \"writeOnly\" : \"closed\";\n }\n ref() {\n this[bunSocketInternal]\?.ref();\n }\n get remoteAddress() {\n return this[bunSocketInternal]\?.remoteAddress;\n }\n get remoteFamily() {\n return \"IPv4\";\n }\n resetAndDestroy() {\n this[bunSocketInternal]\?.end();\n }\n setKeepAlive(enable = !1, initialDelay = 0) {\n return this;\n }\n setNoDelay(noDelay = !0) {\n return this;\n }\n setTimeout(timeout, callback) {\n if (this[bunSocketInternal]\?.timeout(timeout), this.timeout = timeout, callback)\n this.once(\"timeout\", callback);\n return this;\n }\n unref() {\n this[bunSocketInternal]\?.unref();\n }\n _write(chunk, encoding, callback) {\n if (typeof chunk == \"string\" && encoding !== \"ascii\")\n chunk = @Buffer.from(chunk, encoding);\n var written = this[bunSocketInternal]\?.write(chunk);\n if (written == chunk.length)\n callback();\n else if (this.#writeCallback)\n callback(new Error(\"overlapping _write()\"));\n else {\n if (written > 0)\n if (typeof chunk == \"string\")\n chunk = chunk.slice(written);\n else\n chunk = chunk.subarray(written);\n this.#writeCallback = callback, this.#writeChunk = chunk;\n }\n }\n}), connect = createConnection;\n\nclass Server extends EventEmitter {\n #server;\n #listening = !1;\n [bunSocketServerConnections] = 0;\n [bunSocketServerOptions];\n maxConnections = 0;\n constructor(options, connectionListener) {\n super();\n if (typeof options === \"function\")\n connectionListener = options, options = {};\n else if (options == null || typeof options === \"object\")\n options = { ...options };\n else\n throw new Error(\"bun-net-polyfill: invalid arguments\");\n const { maxConnections } = options;\n this.maxConnections = Number.isSafeInteger(maxConnections) && maxConnections > 0 \? maxConnections : 0, options.connectionListener = connectionListener, this[bunSocketServerOptions] = options;\n }\n ref() {\n return this.#server\?.ref(), this;\n }\n unref() {\n return this.#server\?.unref(), this;\n }\n close(callback) {\n if (this.#server) {\n if (this.#server.stop(!0), this.#server = null, this.#listening = !1, this[bunSocketServerConnections] = 0, this.emit(\"close\"), typeof callback === \"function\")\n callback();\n return this;\n }\n if (typeof callback === \"function\") {\n const error = new Error(\"Server is not running\");\n error.code = \"ERR_SERVER_NOT_RUNNING\", callback(error);\n }\n return this;\n }\n address() {\n const server = this.#server;\n if (server) {\n const unix = server.unix;\n if (unix)\n return unix;\n let address = server.hostname;\n const type = isIP(address), port = server.port;\n if (typeof port === \"number\")\n return {\n port,\n address,\n family: type \? `IPv${type}` : @undefined\n };\n if (type)\n return {\n address,\n family: type \? `IPv${type}` : @undefined\n };\n return address;\n }\n return null;\n }\n getConnections(callback) {\n if (typeof callback === \"function\")\n callback(null, this.#server \? this[bunSocketServerConnections] : 0);\n return this;\n }\n listen(port, hostname, onListen) {\n let backlog, path, exclusive = !1;\n if (typeof port === \"string\") {\n if (Number.isSafeInteger(hostname)) {\n if (hostname > 0)\n backlog = hostname;\n } else if (typeof hostname === \"function\")\n onListen = hostname;\n path = port, hostname = @undefined, port = @undefined;\n } else {\n if (typeof hostname === \"function\")\n onListen = hostname, hostname = @undefined;\n if (typeof port === \"function\")\n onListen = port, port = 0;\n else if (typeof port === \"object\") {\n const options = port;\n options.signal\?.addEventListener(\"abort\", () => this.close()), hostname = options.host, exclusive = options.exclusive === !0;\n const path2 = options.path;\n if (port = options.port, !Number.isSafeInteger(port) || port < 0)\n if (path2)\n hostname = path2, port = @undefined;\n else {\n let message = 'The argument \\'options\\' must have the property \"port\" or \"path\"';\n try {\n message = `${message}. Received ${JSON.stringify(options)}`;\n } catch {\n }\n const error = @makeTypeError(message);\n throw error.code = \"ERR_INVALID_ARG_VALUE\", error;\n }\n else if (!Number.isSafeInteger(port) || port < 0)\n port = 0;\n if (typeof port.callback === \"function\")\n onListen = port\?.callback;\n } else if (!Number.isSafeInteger(port) || port < 0)\n port = 0;\n hostname = hostname || \"::\";\n }\n try {\n var tls = @undefined, TLSSocketClass = @undefined;\n const bunTLS = this[bunTlsSymbol], options = this[bunSocketServerOptions];\n if (typeof bunTLS === \"function\")\n [tls, TLSSocketClass] = bunTLS.call(this, port, hostname, !1), options.servername = tls.serverName, options.InternalSocketClass = TLSSocketClass;\n else\n options.InternalSocketClass = SocketClass;\n this.#server = Bun.listen(path \? {\n exclusive,\n unix: path,\n tls,\n socket: SocketClass[bunSocketServerHandlers]\n } : {\n exclusive,\n port,\n hostname,\n tls,\n socket: SocketClass[bunSocketServerHandlers]\n }), this.#server.data = this, this.#listening = !0, setTimeout(emitListeningNextTick, 1, this, onListen);\n } catch (err) {\n this.#listening = !1, setTimeout(emitErrorNextTick, 1, this, err);\n }\n return this;\n }\n}\n$ = {\n createServer,\n Server,\n createConnection,\n connect,\n isIP,\n isIPv4,\n isIPv6,\n Socket,\n [Symbol.for(\"::bunternal::\")]: SocketClass\n};\nreturn $})\n"_s;
//
//
@@ -613,7 +613,7 @@ static constexpr ASCIILiteral NodeInspectorCode = "(function (){\"use strict\";/
//
//
-static constexpr ASCIILiteral NodeNetCode = "(function (){\"use strict\";// src/js/out/tmp/node/net.ts\nvar isIPv4 = function(s) {\n return IPv4Reg.test(s);\n}, isIPv6 = function(s) {\n return IPv6Reg.test(s);\n}, isIP = function(s) {\n if (isIPv4(s))\n return 4;\n if (isIPv6(s))\n return 6;\n return 0;\n}, endNT = function(socket, callback, err) {\n socket.end(), callback(err);\n}, createConnection = function(port, host, connectListener) {\n if (typeof port === \"object\")\n return new Socket(port).connect(port, host, connectListener);\n return new Socket().connect(port, host, connectListener);\n}, emitErrorNextTick = function(self, error) {\n self.emit(\"error\", error);\n}, emitErrorAndCloseNextTick = function(self, error) {\n self.emit(\"error\", error), self.emit(\"close\");\n}, emitListeningNextTick = function(self, onListen) {\n if (typeof onListen === \"function\")\n try {\n onListen();\n } catch (err) {\n self.emit(\"error\", err);\n }\n self.emit(\"listening\");\n}, createServer = function(options, connectionListener) {\n return new Server(options, connectionListener);\n}, $, { Duplex } = @getInternalField(@internalModuleRegistry, 39) || @createInternalModuleById(39), EventEmitter = @getInternalField(@internalModuleRegistry, 20) || @createInternalModuleById(20);\nvar IPv4Reg = new @RegExp(\"^((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$\");\nvar IPv6Reg = new @RegExp(\"^((\?:(\?:[0-9a-fA-F]{1,4}):){7}(\?:(\?:[0-9a-fA-F]{1,4})|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){6}(\?:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|:(\?:[0-9a-fA-F]{1,4})|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){5}(\?::((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,2}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){4}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,1}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,3}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){3}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,2}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,4}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){2}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,3}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,5}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){1}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,4}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,6}|:)|(\?::((\?::(\?:[0-9a-fA-F]{1,4})){0,5}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(\?::(\?:[0-9a-fA-F]{1,4})){1,7}|:)))(%[0-9a-zA-Z-.:]{1,})\?$\"), { connect: bunConnect } = Bun, { setTimeout } = globalThis, bunTlsSymbol = Symbol.for(\"::buntls::\"), bunSocketServerHandlers = Symbol.for(\"::bunsocket_serverhandlers::\"), bunSocketServerConnections = Symbol.for(\"::bunnetserverconnections::\"), bunSocketServerOptions = Symbol.for(\"::bunnetserveroptions::\"), bunSocketInternal = Symbol.for(\"::bunnetsocketinternal::\"), bunTLSConnectOptions = Symbol.for(\"::buntlsconnectoptions::\"), SocketClass, Socket = function(InternalSocket) {\n SocketClass = InternalSocket, Object.defineProperty(SocketClass.prototype, Symbol.toStringTag, {\n value: \"Socket\",\n enumerable: !1\n });\n function Socket3(options) {\n return new InternalSocket(options);\n }\n return Socket3.prototype = InternalSocket.prototype, Object.defineProperty(Socket3, Symbol.hasInstance, {\n value(instance) {\n return instance instanceof InternalSocket;\n }\n });\n}(class Socket2 extends Duplex {\n static #Handlers = {\n close: Socket2.#Close,\n data({ data: self }, buffer) {\n self.bytesRead += buffer.length;\n const queue = self.#readQueue;\n if (queue.isEmpty()) {\n if (self.push(buffer))\n return;\n }\n queue.push(buffer);\n },\n drain: Socket2.#Drain,\n end: Socket2.#Close,\n error(socket, error) {\n const self = socket.data, callback = self.#writeCallback;\n if (callback)\n self.#writeCallback = null, callback(error);\n self.emit(\"error\", error);\n },\n open(socket) {\n const self = socket.data;\n socket.timeout(self.timeout), socket.ref(), self[bunSocketInternal] = socket, self.connecting = !1;\n const options = self[bunTLSConnectOptions];\n if (options) {\n const { session } = options;\n if (session)\n self.setSession(session);\n }\n if (!self.#upgraded)\n self.emit(\"connect\", self);\n Socket2.#Drain(socket);\n },\n handshake(socket, success, verifyError) {\n const { data: self } = socket;\n self._securePending = !1, self.secureConnecting = !1, self._secureEstablished = !!success, self.emit(\"secure\", self);\n const { checkServerIdentity } = self[bunTLSConnectOptions];\n if (!verifyError && typeof checkServerIdentity === \"function\" && self.servername) {\n const cert = self.getPeerCertificate(!0);\n verifyError = checkServerIdentity(self.servername, cert);\n }\n if (self._requestCert || self._rejectUnauthorized) {\n if (verifyError) {\n if (self.authorized = !1, self.authorizationError = verifyError.code || verifyError.message, self._rejectUnauthorized) {\n self.destroy(verifyError);\n return;\n }\n }\n } else\n self.authorized = !0;\n self.emit(\"secureConnect\", verifyError);\n },\n timeout(socket) {\n const self = socket.data;\n self.emit(\"timeout\", self);\n },\n binaryType: \"buffer\"\n };\n static #Close(socket) {\n const self = socket.data;\n if (self.#closed)\n return;\n self.#closed = !0, self[bunSocketInternal] = null;\n const queue = self.#readQueue;\n if (queue.isEmpty()) {\n if (self.push(null))\n return;\n }\n queue.push(null);\n }\n static #Drain(socket) {\n const self = socket.data, callback = self.#writeCallback;\n if (callback) {\n const chunk = self.#writeChunk, written = socket.write(chunk);\n if (self.bytesWritten += written, written < chunk.length)\n self.#writeChunk = chunk.slice(written);\n else\n self.#writeCallback = null, self.#writeChunk = null, callback(null);\n }\n }\n static [bunSocketServerHandlers] = {\n data: Socket2.#Handlers.data,\n close(socket) {\n Socket2.#Handlers.close(socket), this.data[bunSocketServerConnections]--;\n },\n end(socket) {\n Socket2.#Handlers.end(socket), this.data[bunSocketServerConnections]--;\n },\n open(socket) {\n const self = this.data, options = self[bunSocketServerOptions], { pauseOnConnect, connectionListener, InternalSocketClass, requestCert, rejectUnauthorized } = options, _socket = new InternalSocketClass({});\n if (_socket.isServer = !0, _socket._requestCert = requestCert, _socket._rejectUnauthorized = rejectUnauthorized, _socket.#attach(this.localPort, socket), self.maxConnections && self[bunSocketServerConnections] >= self.maxConnections) {\n const data = {\n localAddress: _socket.localAddress,\n localPort: _socket.localPort,\n localFamily: _socket.localFamily,\n remoteAddress: _socket.remoteAddress,\n remotePort: _socket.remotePort,\n remoteFamily: _socket.remoteFamily || \"IPv4\"\n };\n socket.end(), self.emit(\"drop\", data);\n return;\n }\n if (!pauseOnConnect)\n _socket.resume();\n if (self[bunSocketServerConnections]++, typeof connectionListener == \"function\")\n if (InternalSocketClass.name === \"TLSSocket\")\n self.once(\"secureConnection\", () => connectionListener(_socket));\n else\n connectionListener(_socket);\n self.emit(\"connection\", _socket);\n },\n handshake(socket, success, verifyError) {\n const { data: self } = socket;\n if (self.emit(\"secure\", self), self._securePending = !1, self.secureConnecting = !1, self._secureEstablished = !!success, self._requestCert || self._rejectUnauthorized) {\n if (verifyError) {\n if (self.authorized = !1, self.authorizationError = verifyError.code || verifyError.message, self._rejectUnauthorized) {\n self.destroy(verifyError);\n return;\n }\n }\n } else\n self.authorized = !0;\n self.emit(\"secureConnection\", verifyError);\n },\n error(socket, error) {\n Socket2.#Handlers.error(socket, error), this.data.emit(\"error\", error);\n },\n timeout: Socket2.#Handlers.timeout,\n connectError: Socket2.#Handlers.connectError,\n drain: Socket2.#Handlers.drain,\n binaryType: \"buffer\"\n };\n bytesRead = 0;\n bytesWritten = 0;\n #closed = !1;\n connecting = !1;\n localAddress = \"127.0.0.1\";\n #readQueue = @createFIFO();\n remotePort;\n [bunSocketInternal] = null;\n [bunTLSConnectOptions] = null;\n timeout = 0;\n #writeCallback;\n #writeChunk;\n #pendingRead;\n isServer = !1;\n _handle;\n _parent;\n _parentWrap;\n #socket;\n #upgraded;\n constructor(options) {\n const { socket, signal, write, read, allowHalfOpen = !1, ...opts } = options || {};\n super({\n ...opts,\n allowHalfOpen,\n readable: !0,\n writable: !0\n });\n if (this._handle = this, this._parent = this, this._parentWrap = this, this.#pendingRead = @undefined, this.#upgraded = !1, socket instanceof Socket2)\n this.#socket = socket;\n signal\?.once(\"abort\", () => this.destroy()), this.once(\"connect\", () => this.emit(\"ready\"));\n }\n address() {\n return {\n address: this.localAddress,\n family: this.localFamily,\n port: this.localPort\n };\n }\n get bufferSize() {\n return this.writableLength;\n }\n #attach(port, socket) {\n if (this.remotePort = port, socket.data = this, socket.timeout(this.timeout), socket.ref(), this[bunSocketInternal] = socket, this.connecting = !1, !this.#upgraded)\n this.emit(\"connect\", this);\n Socket2.#Drain(socket);\n }\n connect(port, host, connectListener) {\n var path, connection = this.#socket, _checkServerIdentity = @undefined;\n if (typeof port === \"string\") {\n if (path = port, port = @undefined, typeof host === \"function\")\n connectListener = host, host = @undefined;\n } else if (typeof host == \"function\") {\n if (typeof port === \"string\")\n path = port, port = @undefined;\n connectListener = host, host = @undefined;\n }\n if (typeof port == \"object\") {\n var {\n port,\n host,\n path,\n socket,\n localAddress,\n localPort,\n family,\n hints,\n lookup,\n noDelay,\n keepAlive,\n keepAliveInitialDelay,\n requestCert,\n rejectUnauthorized,\n pauseOnConnect,\n servername,\n checkServerIdentity,\n session\n } = port;\n if (_checkServerIdentity = checkServerIdentity, this.servername = servername, socket)\n connection = socket;\n }\n if (!pauseOnConnect)\n this.resume();\n this.connecting = !0, this.remotePort = port;\n const bunTLS = this[bunTlsSymbol];\n var tls = @undefined;\n if (typeof bunTLS === \"function\") {\n if (tls = bunTLS.call(this, port, host, !0), this._requestCert = !0, this._rejectUnauthorized = rejectUnauthorized, tls) {\n if (tls.rejectUnauthorized = rejectUnauthorized, tls.requestCert = !0, tls.session = session || tls.session, this.servername = tls.servername, tls.checkServerIdentity = _checkServerIdentity || tls.checkServerIdentity, this[bunTLSConnectOptions] = tls, !connection && tls.socket)\n connection = tls.socket;\n }\n if (connection) {\n if (typeof connection !== \"object\" || !(connection instanceof Socket2) || typeof connection[bunTlsSymbol] === \"function\")\n @throwTypeError(\"socket must be an instance of net.Socket\");\n }\n if (this.authorized = !1, this.secureConnecting = !0, this._secureEstablished = !1, this._securePending = !0, connectListener)\n this.on(\"secureConnect\", connectListener);\n } else if (connectListener)\n this.on(\"connect\", connectListener);\n try {\n if (connection) {\n const socket2 = connection[bunSocketInternal];\n if (socket2) {\n this.connecting = !0, this.#upgraded = !0;\n const result = socket2.upgradeTLS({\n data: this,\n tls,\n socket: Socket2.#Handlers\n });\n if (result) {\n const [raw, tls2] = result;\n connection[bunSocketInternal] = raw, raw.timeout(raw.timeout), raw.connecting = !1, this[bunSocketInternal] = tls2;\n } else\n throw this[bunSocketInternal] = null, new Error(\"Invalid socket\");\n } else\n connection.once(\"connect\", () => {\n const socket3 = connection[bunSocketInternal];\n if (!socket3)\n return;\n this.connecting = !0, this.#upgraded = !0;\n const result = socket3.upgradeTLS({\n data: this,\n tls,\n socket: Socket2.#Handlers\n });\n if (result) {\n const [raw, tls2] = result;\n connection[bunSocketInternal] = raw, raw.timeout(raw.timeout), raw.connecting = !1, this[bunSocketInternal] = tls2;\n } else\n throw this[bunSocketInternal] = null, new Error(\"Invalid socket\");\n });\n } else if (path)\n bunConnect({\n data: this,\n unix: path,\n socket: Socket2.#Handlers,\n tls\n }).catch((error) => {\n this.emit(\"error\", error), this.emit(\"close\");\n });\n else\n bunConnect({\n data: this,\n hostname: host || \"localhost\",\n port,\n socket: Socket2.#Handlers,\n tls\n }).catch((error) => {\n this.emit(\"error\", error), this.emit(\"close\");\n });\n } catch (error) {\n process.nextTick(emitErrorAndCloseNextTick, this, error);\n }\n return this;\n }\n _destroy(err, callback) {\n const socket = this[bunSocketInternal];\n socket && process.nextTick(endNT, socket, callback, err);\n }\n _final(callback) {\n this[bunSocketInternal]\?.end(), callback();\n }\n get localAddress() {\n return \"127.0.0.1\";\n }\n get localFamily() {\n return \"IPv4\";\n }\n get localPort() {\n return this[bunSocketInternal]\?.localPort;\n }\n get pending() {\n return this.connecting;\n }\n _read(size) {\n const queue = this.#readQueue;\n let chunk;\n while (chunk = queue.peek()) {\n if (!this.push(chunk))\n return;\n queue.shift();\n }\n }\n get readyState() {\n if (this.connecting)\n return \"opening\";\n if (this.readable)\n return this.writable \? \"open\" : \"readOnly\";\n else\n return this.writable \? \"writeOnly\" : \"closed\";\n }\n ref() {\n this[bunSocketInternal]\?.ref();\n }\n get remoteAddress() {\n return this[bunSocketInternal]\?.remoteAddress;\n }\n get remoteFamily() {\n return \"IPv4\";\n }\n resetAndDestroy() {\n this[bunSocketInternal]\?.end();\n }\n setKeepAlive(enable = !1, initialDelay = 0) {\n return this;\n }\n setNoDelay(noDelay = !0) {\n return this;\n }\n setTimeout(timeout, callback) {\n if (this[bunSocketInternal]\?.timeout(timeout), this.timeout = timeout, callback)\n this.once(\"timeout\", callback);\n return this;\n }\n unref() {\n this[bunSocketInternal]\?.unref();\n }\n _write(chunk, encoding, callback) {\n if (typeof chunk == \"string\" && encoding !== \"ascii\")\n chunk = @Buffer.from(chunk, encoding);\n var written = this[bunSocketInternal]\?.write(chunk);\n if (written == chunk.length)\n callback();\n else if (this.#writeCallback)\n callback(new Error(\"overlapping _write()\"));\n else {\n if (written > 0)\n if (typeof chunk == \"string\")\n chunk = chunk.slice(written);\n else\n chunk = chunk.subarray(written);\n this.#writeCallback = callback, this.#writeChunk = chunk;\n }\n }\n}), connect = createConnection;\n\nclass Server extends EventEmitter {\n #server;\n #listening = !1;\n [bunSocketServerConnections] = 0;\n [bunSocketServerOptions];\n maxConnections = 0;\n constructor(options, connectionListener) {\n super();\n if (typeof options === \"function\")\n connectionListener = options, options = {};\n else if (options == null || typeof options === \"object\")\n options = { ...options };\n else\n throw new Error(\"bun-net-polyfill: invalid arguments\");\n const { maxConnections } = options;\n this.maxConnections = Number.isSafeInteger(maxConnections) && maxConnections > 0 \? maxConnections : 0, options.connectionListener = connectionListener, this[bunSocketServerOptions] = options;\n }\n ref() {\n return this.#server\?.ref(), this;\n }\n unref() {\n return this.#server\?.unref(), this;\n }\n close(callback) {\n if (this.#server) {\n if (this.#server.stop(!0), this.#server = null, this.#listening = !1, this[bunSocketServerConnections] = 0, this.emit(\"close\"), typeof callback === \"function\")\n callback();\n return this;\n }\n if (typeof callback === \"function\") {\n const error = new Error(\"Server is not running\");\n error.code = \"ERR_SERVER_NOT_RUNNING\", callback(error);\n }\n return this;\n }\n address() {\n const server = this.#server;\n if (server) {\n const unix = server.unix;\n if (unix)\n return unix;\n let address = server.hostname;\n const type = isIP(address), port = server.port;\n if (typeof port === \"number\")\n return {\n port,\n address,\n family: type \? `IPv${type}` : @undefined\n };\n if (type)\n return {\n address,\n family: type \? `IPv${type}` : @undefined\n };\n return address;\n }\n return null;\n }\n getConnections(callback) {\n if (typeof callback === \"function\")\n callback(null, this.#server \? this[bunSocketServerConnections] : 0);\n return this;\n }\n listen(port, hostname, onListen) {\n let backlog, path, exclusive = !1;\n if (typeof port === \"string\") {\n if (Number.isSafeInteger(hostname)) {\n if (hostname > 0)\n backlog = hostname;\n } else if (typeof hostname === \"function\")\n onListen = hostname;\n path = port, hostname = @undefined, port = @undefined;\n } else {\n if (typeof hostname === \"function\")\n onListen = hostname, hostname = @undefined;\n if (typeof port === \"function\")\n onListen = port, port = 0;\n else if (typeof port === \"object\") {\n const options = port;\n options.signal\?.addEventListener(\"abort\", () => this.close()), hostname = options.host, exclusive = options.exclusive === !0;\n const path2 = options.path;\n if (port = options.port, !Number.isSafeInteger(port) || port < 0)\n if (path2)\n hostname = path2, port = @undefined;\n else {\n let message = 'The argument \\'options\\' must have the property \"port\" or \"path\"';\n try {\n message = `${message}. Received ${JSON.stringify(options)}`;\n } catch {\n }\n const error = @makeTypeError(message);\n throw error.code = \"ERR_INVALID_ARG_VALUE\", error;\n }\n else if (!Number.isSafeInteger(port) || port < 0)\n port = 0;\n if (typeof port.callback === \"function\")\n onListen = port\?.callback;\n } else if (!Number.isSafeInteger(port) || port < 0)\n port = 0;\n hostname = hostname || \"::\";\n }\n try {\n var tls = @undefined, TLSSocketClass = @undefined;\n const bunTLS = this[bunTlsSymbol], options = this[bunSocketServerOptions];\n if (typeof bunTLS === \"function\")\n [tls, TLSSocketClass] = bunTLS.call(this, port, hostname, !1), options.servername = tls.serverName, options.InternalSocketClass = TLSSocketClass;\n else\n options.InternalSocketClass = SocketClass;\n this.#server = Bun.listen(path \? {\n exclusive,\n unix: path,\n tls,\n socket: SocketClass[bunSocketServerHandlers]\n } : {\n exclusive,\n port,\n hostname,\n tls,\n socket: SocketClass[bunSocketServerHandlers]\n }), this.#server.data = this, this.#listening = !0, setTimeout(emitListeningNextTick, 1, this, onListen);\n } catch (err) {\n this.#listening = !1, setTimeout(emitErrorNextTick, 1, this, err);\n }\n return this;\n }\n}\n$ = {\n createServer,\n Server,\n createConnection,\n connect,\n isIP,\n isIPv4,\n isIPv6,\n Socket,\n [Symbol.for(\"::bunternal::\")]: SocketClass\n};\nreturn $})\n"_s;
+static constexpr ASCIILiteral NodeNetCode = "(function (){\"use strict\";// src/js/out/tmp/node/net.ts\nvar isIPv4 = function(s) {\n return IPv4Reg.test(s);\n}, isIPv6 = function(s) {\n return IPv6Reg.test(s);\n}, isIP = function(s) {\n if (isIPv4(s))\n return 4;\n if (isIPv6(s))\n return 6;\n return 0;\n}, closeNT = function(self) {\n self.emit(\"close\");\n}, endNT = function(socket, callback, err) {\n socket.end(), callback(err);\n}, createConnection = function(port, host, connectListener) {\n if (typeof port === \"object\")\n return new Socket(port).connect(port, host, connectListener);\n return new Socket().connect(port, host, connectListener);\n}, emitErrorNextTick = function(self, error) {\n self.emit(\"error\", error);\n}, emitErrorAndCloseNextTick = function(self, error) {\n self.emit(\"error\", error), self.emit(\"close\");\n}, emitListeningNextTick = function(self, onListen) {\n if (typeof onListen === \"function\")\n try {\n onListen();\n } catch (err) {\n self.emit(\"error\", err);\n }\n self.emit(\"listening\");\n}, createServer = function(options, connectionListener) {\n return new Server(options, connectionListener);\n}, $, { Duplex } = @getInternalField(@internalModuleRegistry, 39) || @createInternalModuleById(39), EventEmitter = @getInternalField(@internalModuleRegistry, 20) || @createInternalModuleById(20);\nvar IPv4Reg = new @RegExp(\"^((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$\");\nvar IPv6Reg = new @RegExp(\"^((\?:(\?:[0-9a-fA-F]{1,4}):){7}(\?:(\?:[0-9a-fA-F]{1,4})|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){6}(\?:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|:(\?:[0-9a-fA-F]{1,4})|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){5}(\?::((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,2}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){4}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,1}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,3}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){3}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,2}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,4}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){2}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,3}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,5}|:)|(\?:(\?:[0-9a-fA-F]{1,4}):){1}(\?:(:(\?:[0-9a-fA-F]{1,4})){0,4}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(:(\?:[0-9a-fA-F]{1,4})){1,6}|:)|(\?::((\?::(\?:[0-9a-fA-F]{1,4})){0,5}:((\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])[.]){3}(\?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])|(\?::(\?:[0-9a-fA-F]{1,4})){1,7}|:)))(%[0-9a-zA-Z-.:]{1,})\?$\"), { connect: bunConnect } = Bun, { setTimeout } = globalThis, bunTlsSymbol = Symbol.for(\"::buntls::\"), bunSocketServerHandlers = Symbol.for(\"::bunsocket_serverhandlers::\"), bunSocketServerConnections = Symbol.for(\"::bunnetserverconnections::\"), bunSocketServerOptions = Symbol.for(\"::bunnetserveroptions::\"), bunSocketInternal = Symbol.for(\"::bunnetsocketinternal::\"), bunTLSConnectOptions = Symbol.for(\"::buntlsconnectoptions::\"), SocketClass, Socket = function(InternalSocket) {\n SocketClass = InternalSocket, Object.defineProperty(SocketClass.prototype, Symbol.toStringTag, {\n value: \"Socket\",\n enumerable: !1\n });\n function Socket3(options) {\n return new InternalSocket(options);\n }\n return Socket3.prototype = InternalSocket.prototype, Object.defineProperty(Socket3, Symbol.hasInstance, {\n value(instance) {\n return instance instanceof InternalSocket;\n }\n });\n}(class Socket2 extends Duplex {\n static #Handlers = {\n close: Socket2.#Close,\n data({ data: self }, buffer) {\n self.bytesRead += buffer.length;\n const queue = self.#readQueue;\n if (queue.isEmpty()) {\n if (self.push(buffer))\n return;\n }\n queue.push(buffer);\n },\n drain: Socket2.#Drain,\n end: Socket2.#Close,\n error(socket, error) {\n const self = socket.data, callback = self.#writeCallback;\n if (callback)\n self.#writeCallback = null, callback(error);\n self.emit(\"error\", error);\n },\n open(socket) {\n const self = socket.data;\n socket.timeout(self.timeout), socket.ref(), self[bunSocketInternal] = socket, self.connecting = !1;\n const options = self[bunTLSConnectOptions];\n if (options) {\n const { session } = options;\n if (session)\n self.setSession(session);\n }\n if (!self.#upgraded)\n self.emit(\"connect\", self);\n Socket2.#Drain(socket);\n },\n handshake(socket, success, verifyError) {\n const { data: self } = socket;\n self._securePending = !1, self.secureConnecting = !1, self._secureEstablished = !!success, self.emit(\"secure\", self);\n const { checkServerIdentity } = self[bunTLSConnectOptions];\n if (!verifyError && typeof checkServerIdentity === \"function\" && self.servername) {\n const cert = self.getPeerCertificate(!0);\n verifyError = checkServerIdentity(self.servername, cert);\n }\n if (self._requestCert || self._rejectUnauthorized) {\n if (verifyError) {\n if (self.authorized = !1, self.authorizationError = verifyError.code || verifyError.message, self._rejectUnauthorized) {\n self.destroy(verifyError);\n return;\n }\n }\n } else\n self.authorized = !0;\n self.emit(\"secureConnect\", verifyError);\n },\n timeout(socket) {\n const self = socket.data;\n self.emit(\"timeout\", self);\n },\n binaryType: \"buffer\"\n };\n static #Close(socket) {\n const self = socket.data;\n if (self.#closed)\n return;\n self.#closed = !0, self[bunSocketInternal] = null;\n const queue = self.#readQueue;\n if (queue.isEmpty()) {\n if (self.push(null))\n return;\n }\n queue.push(null);\n }\n static #Drain(socket) {\n const self = socket.data, callback = self.#writeCallback;\n if (callback) {\n const chunk = self.#writeChunk, written = socket.write(chunk);\n if (self.bytesWritten += written, written < chunk.length)\n self.#writeChunk = chunk.slice(written);\n else\n self.#writeCallback = null, self.#writeChunk = null, callback(null);\n }\n }\n static [bunSocketServerHandlers] = {\n data: Socket2.#Handlers.data,\n close(socket) {\n Socket2.#Handlers.close(socket), this.data[bunSocketServerConnections]--;\n },\n end(socket) {\n Socket2.#Handlers.end(socket), this.data[bunSocketServerConnections]--;\n },\n open(socket) {\n const self = this.data, options = self[bunSocketServerOptions], { pauseOnConnect, connectionListener, InternalSocketClass, requestCert, rejectUnauthorized } = options, _socket = new InternalSocketClass({});\n if (_socket.isServer = !0, _socket._requestCert = requestCert, _socket._rejectUnauthorized = rejectUnauthorized, _socket.#attach(this.localPort, socket), self.maxConnections && self[bunSocketServerConnections] >= self.maxConnections) {\n const data = {\n localAddress: _socket.localAddress,\n localPort: _socket.localPort,\n localFamily: _socket.localFamily,\n remoteAddress: _socket.remoteAddress,\n remotePort: _socket.remotePort,\n remoteFamily: _socket.remoteFamily || \"IPv4\"\n };\n socket.end(), self.emit(\"drop\", data);\n return;\n }\n if (!pauseOnConnect)\n _socket.resume();\n if (self[bunSocketServerConnections]++, typeof connectionListener == \"function\")\n if (InternalSocketClass.name === \"TLSSocket\")\n self.once(\"secureConnection\", () => connectionListener(_socket));\n else\n connectionListener(_socket);\n self.emit(\"connection\", _socket);\n },\n handshake(socket, success, verifyError) {\n const { data: self } = socket;\n if (self.emit(\"secure\", self), self._securePending = !1, self.secureConnecting = !1, self._secureEstablished = !!success, self._requestCert || self._rejectUnauthorized) {\n if (verifyError) {\n if (self.authorized = !1, self.authorizationError = verifyError.code || verifyError.message, self._rejectUnauthorized) {\n self.destroy(verifyError);\n return;\n }\n }\n } else\n self.authorized = !0;\n self.emit(\"secureConnection\", verifyError);\n },\n error(socket, error) {\n Socket2.#Handlers.error(socket, error), this.data.emit(\"error\", error);\n },\n timeout: Socket2.#Handlers.timeout,\n connectError: Socket2.#Handlers.connectError,\n drain: Socket2.#Handlers.drain,\n binaryType: \"buffer\"\n };\n bytesRead = 0;\n bytesWritten = 0;\n #closed = !1;\n connecting = !1;\n localAddress = \"127.0.0.1\";\n #readQueue = @createFIFO();\n remotePort;\n [bunSocketInternal] = null;\n [bunTLSConnectOptions] = null;\n timeout = 0;\n #writeCallback;\n #writeChunk;\n #pendingRead;\n isServer = !1;\n _handle;\n _parent;\n _parentWrap;\n #socket;\n #upgraded;\n constructor(options) {\n const { socket, signal, write, read, allowHalfOpen = !1, ...opts } = options || {};\n super({\n ...opts,\n allowHalfOpen,\n readable: !0,\n writable: !0\n });\n if (this._handle = this, this._parent = this, this._parentWrap = this, this.#pendingRead = @undefined, this.#upgraded = null, socket instanceof Socket2)\n this.#socket = socket;\n signal\?.once(\"abort\", () => this.destroy()), this.once(\"connect\", () => this.emit(\"ready\"));\n }\n address() {\n return {\n address: this.localAddress,\n family: this.localFamily,\n port: this.localPort\n };\n }\n get bufferSize() {\n return this.writableLength;\n }\n #attach(port, socket) {\n if (this.remotePort = port, socket.data = this, socket.timeout(this.timeout), socket.ref(), this[bunSocketInternal] = socket, this.connecting = !1, !this.#upgraded)\n this.emit(\"connect\", this);\n Socket2.#Drain(socket);\n }\n #closeRawConnection() {\n const connection = this.#upgraded;\n connection[bunSocketInternal] = null, connection.unref(), connection.destroy(), process.nextTick(closeNT, connection);\n }\n connect(port, host, connectListener) {\n var path, connection = this.#socket, _checkServerIdentity = @undefined;\n if (typeof port === \"string\") {\n if (path = port, port = @undefined, typeof host === \"function\")\n connectListener = host, host = @undefined;\n } else if (typeof host == \"function\") {\n if (typeof port === \"string\")\n path = port, port = @undefined;\n connectListener = host, host = @undefined;\n }\n if (typeof port == \"object\") {\n var {\n port,\n host,\n path,\n socket,\n localAddress,\n localPort,\n family,\n hints,\n lookup,\n noDelay,\n keepAlive,\n keepAliveInitialDelay,\n requestCert,\n rejectUnauthorized,\n pauseOnConnect,\n servername,\n checkServerIdentity,\n session\n } = port;\n if (_checkServerIdentity = checkServerIdentity, this.servername = servername, socket)\n connection = socket;\n }\n if (!pauseOnConnect)\n this.resume();\n this.connecting = !0, this.remotePort = port;\n const bunTLS = this[bunTlsSymbol];\n var tls = @undefined;\n if (typeof bunTLS === \"function\") {\n if (tls = bunTLS.call(this, port, host, !0), this._requestCert = !0, this._rejectUnauthorized = rejectUnauthorized, tls) {\n if (tls.rejectUnauthorized = rejectUnauthorized, tls.requestCert = !0, tls.session = session || tls.session, this.servername = tls.servername, tls.checkServerIdentity = _checkServerIdentity || tls.checkServerIdentity, this[bunTLSConnectOptions] = tls, !connection && tls.socket)\n connection = tls.socket;\n }\n if (connection) {\n if (typeof connection !== \"object\" || !(connection instanceof Socket2) || typeof connection[bunTlsSymbol] === \"function\")\n @throwTypeError(\"socket must be an instance of net.Socket\");\n }\n if (this.authorized = !1, this.secureConnecting = !0, this._secureEstablished = !1, this._securePending = !0, connectListener)\n this.on(\"secureConnect\", connectListener);\n } else if (connectListener)\n this.on(\"connect\", connectListener);\n try {\n if (connection) {\n const socket2 = connection[bunSocketInternal];\n if (socket2) {\n this.connecting = !0, this.#upgraded = connection;\n const result = socket2.upgradeTLS({\n data: this,\n tls,\n socket: Socket2.#Handlers\n });\n if (result) {\n const [raw, tls2] = result;\n connection[bunSocketInternal] = raw, raw.timeout(raw.timeout), this.once(\"end\", this.#closeRawConnection), raw.connecting = !1, this[bunSocketInternal] = tls2;\n } else\n throw this[bunSocketInternal] = null, new Error(\"Invalid socket\");\n } else\n connection.once(\"connect\", () => {\n const socket3 = connection[bunSocketInternal];\n if (!socket3)\n return;\n this.connecting = !0, this.#upgraded = connection;\n const result = socket3.upgradeTLS({\n data: this,\n tls,\n socket: Socket2.#Handlers\n });\n if (result) {\n const [raw, tls2] = result;\n connection[bunSocketInternal] = raw, raw.timeout(raw.timeout), this.once(\"end\", this.#closeRawConnection), raw.connecting = !1, this[bunSocketInternal] = tls2;\n } else\n throw this[bunSocketInternal] = null, new Error(\"Invalid socket\");\n });\n } else if (path)\n bunConnect({\n data: this,\n unix: path,\n socket: Socket2.#Handlers,\n tls\n }).catch((error) => {\n this.emit(\"error\", error), this.emit(\"close\");\n });\n else\n bunConnect({\n data: this,\n hostname: host || \"localhost\",\n port,\n socket: Socket2.#Handlers,\n tls\n }).catch((error) => {\n this.emit(\"error\", error), this.emit(\"close\");\n });\n } catch (error) {\n process.nextTick(emitErrorAndCloseNextTick, this, error);\n }\n return this;\n }\n _destroy(err, callback) {\n const socket = this[bunSocketInternal];\n socket && process.nextTick(endNT, socket, callback, err);\n }\n _final(callback) {\n this[bunSocketInternal]\?.end(), callback(), process.nextTick(closeNT, this);\n }\n get localAddress() {\n return \"127.0.0.1\";\n }\n get localFamily() {\n return \"IPv4\";\n }\n get localPort() {\n return this[bunSocketInternal]\?.localPort;\n }\n get pending() {\n return this.connecting;\n }\n _read(size) {\n const queue = this.#readQueue;\n let chunk;\n while (chunk = queue.peek()) {\n const success = !this.push(chunk);\n if (queue.shift(), !success)\n break;\n }\n }\n get readyState() {\n if (this.connecting)\n return \"opening\";\n if (this.readable)\n return this.writable \? \"open\" : \"readOnly\";\n else\n return this.writable \? \"writeOnly\" : \"closed\";\n }\n ref() {\n this[bunSocketInternal]\?.ref();\n }\n get remoteAddress() {\n return this[bunSocketInternal]\?.remoteAddress;\n }\n get remoteFamily() {\n return \"IPv4\";\n }\n resetAndDestroy() {\n this[bunSocketInternal]\?.end();\n }\n setKeepAlive(enable = !1, initialDelay = 0) {\n return this;\n }\n setNoDelay(noDelay = !0) {\n return this;\n }\n setTimeout(timeout, callback) {\n if (this[bunSocketInternal]\?.timeout(timeout), this.timeout = timeout, callback)\n this.once(\"timeout\", callback);\n return this;\n }\n unref() {\n this[bunSocketInternal]\?.unref();\n }\n _write(chunk, encoding, callback) {\n if (typeof chunk == \"string\" && encoding !== \"ascii\")\n chunk = @Buffer.from(chunk, encoding);\n var written = this[bunSocketInternal]\?.write(chunk);\n if (written == chunk.length)\n callback();\n else if (this.#writeCallback)\n callback(new Error(\"overlapping _write()\"));\n else {\n if (written > 0)\n if (typeof chunk == \"string\")\n chunk = chunk.slice(written);\n else\n chunk = chunk.subarray(written);\n this.#writeCallback = callback, this.#writeChunk = chunk;\n }\n }\n}), connect = createConnection;\n\nclass Server extends EventEmitter {\n #server;\n #listening = !1;\n [bunSocketServerConnections] = 0;\n [bunSocketServerOptions];\n maxConnections = 0;\n constructor(options, connectionListener) {\n super();\n if (typeof options === \"function\")\n connectionListener = options, options = {};\n else if (options == null || typeof options === \"object\")\n options = { ...options };\n else\n throw new Error(\"bun-net-polyfill: invalid arguments\");\n const { maxConnections } = options;\n this.maxConnections = Number.isSafeInteger(maxConnections) && maxConnections > 0 \? maxConnections : 0, options.connectionListener = connectionListener, this[bunSocketServerOptions] = options;\n }\n ref() {\n return this.#server\?.ref(), this;\n }\n unref() {\n return this.#server\?.unref(), this;\n }\n close(callback) {\n if (this.#server) {\n if (this.#server.stop(!0), this.#server = null, this.#listening = !1, this[bunSocketServerConnections] = 0, this.emit(\"close\"), typeof callback === \"function\")\n callback();\n return this;\n }\n if (typeof callback === \"function\") {\n const error = new Error(\"Server is not running\");\n error.code = \"ERR_SERVER_NOT_RUNNING\", callback(error);\n }\n return this;\n }\n address() {\n const server = this.#server;\n if (server) {\n const unix = server.unix;\n if (unix)\n return unix;\n let address = server.hostname;\n const type = isIP(address), port = server.port;\n if (typeof port === \"number\")\n return {\n port,\n address,\n family: type \? `IPv${type}` : @undefined\n };\n if (type)\n return {\n address,\n family: type \? `IPv${type}` : @undefined\n };\n return address;\n }\n return null;\n }\n getConnections(callback) {\n if (typeof callback === \"function\")\n callback(null, this.#server \? this[bunSocketServerConnections] : 0);\n return this;\n }\n listen(port, hostname, onListen) {\n let backlog, path, exclusive = !1;\n if (typeof port === \"string\") {\n if (Number.isSafeInteger(hostname)) {\n if (hostname > 0)\n backlog = hostname;\n } else if (typeof hostname === \"function\")\n onListen = hostname;\n path = port, hostname = @undefined, port = @undefined;\n } else {\n if (typeof hostname === \"function\")\n onListen = hostname, hostname = @undefined;\n if (typeof port === \"function\")\n onListen = port, port = 0;\n else if (typeof port === \"object\") {\n const options = port;\n options.signal\?.addEventListener(\"abort\", () => this.close()), hostname = options.host, exclusive = options.exclusive === !0;\n const path2 = options.path;\n if (port = options.port, !Number.isSafeInteger(port) || port < 0)\n if (path2)\n hostname = path2, port = @undefined;\n else {\n let message = 'The argument \\'options\\' must have the property \"port\" or \"path\"';\n try {\n message = `${message}. Received ${JSON.stringify(options)}`;\n } catch {\n }\n const error = @makeTypeError(message);\n throw error.code = \"ERR_INVALID_ARG_VALUE\", error;\n }\n else if (!Number.isSafeInteger(port) || port < 0)\n port = 0;\n if (typeof port.callback === \"function\")\n onListen = port\?.callback;\n } else if (!Number.isSafeInteger(port) || port < 0)\n port = 0;\n hostname = hostname || \"::\";\n }\n try {\n var tls = @undefined, TLSSocketClass = @undefined;\n const bunTLS = this[bunTlsSymbol], options = this[bunSocketServerOptions];\n if (typeof bunTLS === \"function\")\n [tls, TLSSocketClass] = bunTLS.call(this, port, hostname, !1), options.servername = tls.serverName, options.InternalSocketClass = TLSSocketClass;\n else\n options.InternalSocketClass = SocketClass;\n this.#server = Bun.listen(path \? {\n exclusive,\n unix: path,\n tls,\n socket: SocketClass[bunSocketServerHandlers]\n } : {\n exclusive,\n port,\n hostname,\n tls,\n socket: SocketClass[bunSocketServerHandlers]\n }), this.#server.data = this, this.#listening = !0, setTimeout(emitListeningNextTick, 1, this, onListen);\n } catch (err) {\n this.#listening = !1, setTimeout(emitErrorNextTick, 1, this, err);\n }\n return this;\n }\n}\n$ = {\n createServer,\n Server,\n createConnection,\n connect,\n isIP,\n isIPv4,\n isIPv6,\n Socket,\n [Symbol.for(\"::bunternal::\")]: SocketClass\n};\nreturn $})\n"_s;
//
//
diff --git a/test/js/third_party/postgres/postgres.test.ts b/test/js/third_party/postgres/postgres.test.ts
index 758fee778..991c85d88 100644
--- a/test/js/third_party/postgres/postgres.test.ts
+++ b/test/js/third_party/postgres/postgres.test.ts
@@ -1,5 +1,5 @@
import { test, expect, describe } from "bun:test";
-import { Pool } from "pg";
+import { Pool, Client } from "pg";
import { parse } from "pg-connection-string";
import postgres from "postgres";
@@ -19,6 +19,18 @@ describe("pg", () => {
pool.end();
}
});
+
+ it("should execute big query and end connection", async () => {
+ const client = new Client({
+ connectionString: CONNECTION_STRING,
+ ssl: { rejectUnauthorized: false },
+ });
+
+ await client.connect();
+ const res = await client.query(`SELECT * FROM users LIMIT 1000`);
+ expect(res.rows.length).toBeGreaterThanOrEqual(300);
+ await client.end();
+ }, 5000);
});
describe("postgres", () => {