aboutsummaryrefslogtreecommitdiff
path: root/src/js/out/InternalModuleRegistryConstants.h
diff options
context:
space:
mode:
authorGravatar Dylan Conway <35280289+dylan-conway@users.noreply.github.com> 2023-09-22 19:48:36 -0700
committerGravatar GitHub <noreply@github.com> 2023-09-22 19:48:36 -0700
commit966b636e5d2026bf535a85860895fab2c004dac1 (patch)
treecbc2e1e4ea7acbb17706addeacfc8db7c5f1f41f /src/js/out/InternalModuleRegistryConstants.h
parentee93f1b88c141f1cc5d917a60ddb4a3e2706f1ff (diff)
downloadbun-966b636e5d2026bf535a85860895fab2c004dac1.tar.gz
bun-966b636e5d2026bf535a85860895fab2c004dac1.tar.zst
bun-966b636e5d2026bf535a85860895fab2c004dac1.zip
isBinary (#5944)
Diffstat (limited to 'src/js/out/InternalModuleRegistryConstants.h')
-rw-r--r--src/js/out/InternalModuleRegistryConstants.h6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/js/out/InternalModuleRegistryConstants.h b/src/js/out/InternalModuleRegistryConstants.h
index b868f16e9..d2e750c83 100644
--- a/src/js/out/InternalModuleRegistryConstants.h
+++ b/src/js/out/InternalModuleRegistryConstants.h
@@ -242,7 +242,7 @@ static constexpr ASCIILiteral ThirdpartyVercelFetchCode = "(function (){\"use st
//
//
-static constexpr ASCIILiteral ThirdpartyWSCode = "(function (){\"use strict\";// src/js/out/tmp/thirdparty/ws.ts\nvar emitWarning = function(type, message) {\n if (emittedWarnings.has(type))\n return;\n emittedWarnings.add(type), console.warn(\"[bun] Warning:\", message);\n}, subprotocolParse = function(header) {\n const protocols = new Set;\n let start = -1, end = -1, i = 0;\n for (i;i < header.length; i++) {\n const code = header.charCodeAt(i);\n if (end === -1 && wsTokenChars[code] === 1) {\n if (start === -1)\n start = i;\n } else if (i !== 0 && (code === 32 || code === 9)) {\n if (end === -1 && start !== -1)\n end = i;\n } else if (code === 44) {\n if (start === -1)\n throw new SyntaxError(`Unexpected character at index ${i}`);\n if (end === -1)\n end = i;\n const protocol2 = header.slice(start, end);\n if (protocols.has(protocol2))\n throw new SyntaxError(`The \"${protocol2}\" subprotocol is duplicated`);\n protocols.add(protocol2), start = end = -1;\n } else\n throw new SyntaxError(`Unexpected character at index ${i}`);\n }\n if (start === -1 || end !== -1)\n throw new SyntaxError(\"Unexpected end of input\");\n const protocol = header.slice(start, i);\n if (protocols.has(protocol))\n throw new SyntaxError(`The \"${protocol}\" subprotocol is duplicated`);\n return protocols.add(protocol), protocols;\n}, wsEmitClose = function(server) {\n server._state = CLOSED, server.emit(\"close\");\n}, abortHandshake = function(response, code, message, headers) {\n message = message || http.STATUS_CODES[code], headers = {\n Connection: \"close\",\n \"Content-Type\": \"text/html\",\n \"Content-Length\": @Buffer.byteLength(message),\n ...headers\n }, response.writeHead(code, headers), response.write(message), response.end();\n}, abortHandshakeOrEmitwsClientError = function(server, req, response, socket, code, message) {\n if (server.listenerCount(\"wsClientError\")) {\n const err = new Error(message);\n Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError), server.emit(\"wsClientError\", err, socket, req);\n } else\n abortHandshake(response, code, message);\n}, $, EventEmitter = @getInternalField(@internalModuleRegistry, 18) || @createInternalModuleById(18), http = @getInternalField(@internalModuleRegistry, 21) || @createInternalModuleById(21), kBunInternals = Symbol.for(\"::bunternal::\"), readyStates = [\"CONNECTING\", \"OPEN\", \"CLOSING\", \"CLOSED\"], encoder = new TextEncoder, eventIds = {\n open: 1,\n close: 2,\n message: 3,\n error: 4,\n ping: 5,\n pong: 6\n}, emittedWarnings = new Set;\n\nclass BunWebSocket extends EventEmitter {\n static CONNECTING = 0;\n static OPEN = 1;\n static CLOSING = 2;\n static CLOSED = 3;\n #ws;\n #paused = !1;\n #fragments = !1;\n #binaryType = \"nodebuffer\";\n #eventId = 0;\n constructor(url, protocols, options) {\n super();\n let ws = this.#ws = new WebSocket(url, protocols);\n ws.binaryType = \"nodebuffer\";\n }\n on(event, listener) {\n if (event === \"unexpected-response\" || event === \"upgrade\" || event === \"redirect\")\n emitWarning(event, \"ws.WebSocket '\" + event + \"' event is not implemented in bun\");\n const mask = 1 << eventIds[event];\n if (mask && (this.#eventId & mask) !== mask) {\n if (this.#eventId |= mask, event === \"open\")\n this.#ws.addEventListener(\"open\", () => {\n this.emit(\"open\");\n });\n else if (event === \"close\")\n this.#ws.addEventListener(\"close\", ({ code, reason, wasClean }) => {\n this.emit(\"close\", code, reason, wasClean);\n });\n else if (event === \"message\")\n this.#ws.addEventListener(\"message\", ({ data }) => {\n const isBinary = typeof data !== \"string\";\n if (isBinary)\n this.emit(\"message\", this.#fragments \? [data] : data, isBinary);\n else {\n let encoded = encoder.encode(data);\n if (this.#binaryType !== \"arraybuffer\")\n encoded = @Buffer.from(encoded.buffer, encoded.byteOffset, encoded.byteLength);\n this.emit(\"message\", this.#fragments \? [encoded] : encoded, isBinary);\n }\n });\n else if (event === \"error\")\n this.#ws.addEventListener(\"error\", (err) => {\n this.emit(\"error\", err);\n });\n else if (event === \"ping\")\n this.#ws.addEventListener(\"ping\", ({ data }) => {\n this.emit(\"ping\", data);\n });\n else if (event === \"pong\")\n this.#ws.addEventListener(\"pong\", ({ data }) => {\n this.emit(\"pong\", data);\n });\n }\n return super.on(event, listener);\n }\n send(data, opts, cb) {\n try {\n this.#ws.send(data, opts\?.compress);\n } catch (error) {\n typeof cb === \"function\" && cb(error);\n return;\n }\n typeof cb === \"function\" && cb();\n }\n close(code, reason) {\n this.#ws.close(code, reason);\n }\n terminate() {\n this.#ws.terminate();\n }\n get url() {\n return this.#ws.url;\n }\n get readyState() {\n return this.#ws.readyState;\n }\n get binaryType() {\n return this.#binaryType;\n }\n set binaryType(value) {\n if (value === \"nodebuffer\" || value === \"arraybuffer\")\n this.#ws.binaryType = this.#binaryType = value, this.#fragments = !1;\n else if (value === \"fragments\")\n this.#ws.binaryType = \"nodebuffer\", this.#binaryType = \"fragments\", this.#fragments = !0;\n else\n throw new Error(`Invalid binaryType: ${value}`);\n }\n get protocol() {\n return this.#ws.protocol;\n }\n get extensions() {\n return this.#ws.extensions;\n }\n addEventListener(type, listener, options) {\n this.#ws.addEventListener(type, listener, options);\n }\n removeEventListener(type, listener) {\n this.#ws.removeEventListener(type, listener);\n }\n get onopen() {\n return this.#ws.onopen;\n }\n set onopen(value) {\n this.#ws.onopen = value;\n }\n get onerror() {\n return this.#ws.onerror;\n }\n set onerror(value) {\n this.#ws.onerror = value;\n }\n get onclose() {\n return this.#ws.onclose;\n }\n set onclose(value) {\n this.#ws.onclose = value;\n }\n get onmessage() {\n return this.#ws.onmessage;\n }\n set onmessage(value) {\n this.#ws.onmessage = value;\n }\n get bufferedAmount() {\n return this.#ws.bufferedAmount;\n }\n get isPaused() {\n return this.#paused;\n }\n ping(data, mask, cb) {\n if (typeof data === \"function\")\n cb = data, data = mask = @undefined;\n else if (typeof mask === \"function\")\n cb = mask, mask = @undefined;\n if (typeof data === \"number\")\n data = data.toString();\n try {\n this.#ws.ping(data);\n } catch (error) {\n typeof cb === \"function\" && cb(error);\n return;\n }\n typeof cb === \"function\" && cb();\n }\n pong(data, mask, cb) {\n if (typeof data === \"function\")\n cb = data, data = mask = @undefined;\n else if (typeof mask === \"function\")\n cb = mask, mask = @undefined;\n if (typeof data === \"number\")\n data = data.toString();\n try {\n this.#ws.pong(data);\n } catch (error) {\n typeof cb === \"function\" && cb(error);\n return;\n }\n typeof cb === \"function\" && cb();\n }\n pause() {\n switch (this.readyState) {\n case WebSocket.CONNECTING:\n case WebSocket.CLOSED:\n return;\n }\n this.#paused = !0, emitWarning(\"pause()\", \"ws.WebSocket.pause() is not implemented in bun\");\n }\n resume() {\n switch (this.readyState) {\n case WebSocket.CONNECTING:\n case WebSocket.CLOSED:\n return;\n }\n this.#paused = !1, emitWarning(\"resume()\", \"ws.WebSocket.resume() is not implemented in bun\");\n }\n}\nObject.defineProperty(BunWebSocket, \"name\", { value: \"WebSocket\" });\nvar wsKeyRegex = /^[+/0-9A-Za-z]{22}==$/, wsTokenChars = [\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 1,\n 0,\n 1,\n 1,\n 1,\n 1,\n 1,\n 0,\n 0,\n 1,\n 1,\n 0,\n 1,\n 1,\n 0,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 0,\n 0,\n 0,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 0,\n 1,\n 0,\n 1,\n 0\n], RUNNING = 0, CLOSING = 1, CLOSED = 2;\n\nclass BunWebSocketMocked extends EventEmitter {\n #ws;\n #state;\n #enquedMessages = [];\n #url;\n #protocol;\n #extensions;\n #bufferedAmount = 0;\n #binaryType = \"arraybuffer\";\n #onclose;\n #onerror;\n #onmessage;\n #onopen;\n constructor(url, protocol, extensions, binaryType) {\n super();\n if (this.#ws = null, this.#state = 0, this.#url = url, this.#bufferedAmount = 0, binaryType = binaryType || \"arraybuffer\", binaryType !== \"nodebuffer\" && binaryType !== \"blob\" && binaryType !== \"arraybuffer\")\n @throwTypeError(\"binaryType must be either 'blob', 'arraybuffer' or 'nodebuffer'\");\n this.#binaryType = binaryType, this.#protocol = protocol, this.#extensions = extensions;\n const message = this.#message.bind(this), open = this.#open.bind(this), close = this.#close.bind(this), drain = this.#drain.bind(this);\n this[kBunInternals] = {\n message,\n open,\n close,\n drain\n };\n }\n #message(ws, message) {\n if (this.#ws = ws, typeof message === \"string\")\n if (this.#binaryType === \"arraybuffer\")\n message = encoder.encode(message).buffer;\n else if (this.#binaryType === \"blob\")\n message = new Blob([message], { type: \"text/plain\" });\n else\n message = @Buffer.from(message);\n else if (this.#binaryType !== \"nodebuffer\") {\n if (this.#binaryType === \"arraybuffer\")\n message = new @Uint8Array(message);\n else if (this.#binaryType === \"blob\")\n message = new Blob([message]);\n }\n this.emit(\"message\", message);\n }\n #open(ws) {\n this.#ws = ws, this.#state = 1, this.emit(\"open\", this), this.#drain(ws);\n }\n #close(ws, code, reason) {\n this.#state = 3, this.#ws = null, this.emit(\"close\", code, reason);\n }\n #drain(ws) {\n const chunk = this.#enquedMessages[0];\n if (chunk) {\n const [data, compress, cb] = chunk;\n if (ws.send(data, compress) == -1)\n return;\n typeof cb === \"function\" && cb(), this.#bufferedAmount -= chunk.length, this.#enquedMessages.shift();\n }\n }\n send(data, opts, cb) {\n if (this.#state === 1) {\n const compress = opts\?.compress;\n if (this.#ws.send(data, compress) == -1) {\n this.#enquedMessages.push([data, compress, cb]), this.#bufferedAmount += data.length;\n return;\n }\n typeof cb === \"function\" && cb();\n } else if (this.#state === 0)\n this.#enquedMessages.push([data, opts\?.compress, cb]), this.#bufferedAmount += data.length;\n }\n close(code, reason) {\n if (this.#state === 1)\n this.#state = 2, this.#ws.close(code, reason);\n }\n get binaryType() {\n return this.#binaryType;\n }\n set binaryType(type) {\n if (type !== \"nodebuffer\" && type !== \"blob\" && type !== \"arraybuffer\")\n @throwTypeError(\"binaryType must be either 'blob', 'arraybuffer' or 'nodebuffer'\");\n this.#binaryType = type;\n }\n get readyState() {\n return this.#state;\n }\n get url() {\n return this.#url;\n }\n get protocol() {\n return this.#protocol;\n }\n get extensions() {\n return this.#extensions;\n }\n get bufferedAmount() {\n return this.#bufferedAmount \?\? 0;\n }\n setSocket(socket, head, options) {\n throw new Error(\"Not implemented\");\n }\n set onclose(cb) {\n if (this.#onclose)\n this.removeListener(\"close\", this.#onclose);\n this.on(\"close\", cb), this.#onclose = cb;\n }\n set onerror(cb) {\n if (this.#onerror)\n this.removeListener(\"error\", this.#onerror);\n this.on(\"error\", cb), this.#onerror = cb;\n }\n set onmessage(cb) {\n if (this.#onmessage)\n this.removeListener(\"message\", this.#onmessage);\n this.on(\"message\", cb), this.#onmessage = cb;\n }\n set onopen(cb) {\n if (this.#onopen)\n this.removeListener(\"open\", this.#onopen);\n this.on(\"open\", cb), this.#onopen = cb;\n }\n get onclose() {\n return this.#onclose;\n }\n get onerror() {\n return this.#onerror;\n }\n get onmessage() {\n return this.#onmessage;\n }\n get onopen() {\n return this.#onopen;\n }\n addEventListener(type, listener, options) {\n if (type === \"message\") {\n const l = (data) => listener({ data });\n l.listener = listener, this.on(type, l);\n return;\n }\n this.on(type, listener);\n }\n removeEventListener(type, listener) {\n this.off(type, listener);\n }\n}\n\nclass WebSocketServer extends EventEmitter {\n _server;\n options;\n clients;\n _shouldEmitClose;\n _state;\n _removeListeners;\n constructor(options, callback) {\n super();\n if (options = {\n maxPayload: 104857600,\n skipUTF8Validation: !1,\n perMessageDeflate: !1,\n handleProtocols: null,\n clientTracking: !0,\n verifyClient: null,\n noServer: !1,\n backlog: null,\n server: null,\n host: null,\n path: null,\n port: null,\n ...options\n }, options.port == null && !options.server && !options.noServer || options.port != null && (options.server || options.noServer) || options.server && options.noServer)\n @throwTypeError('One and only one of the \"port\", \"server\", or \"noServer\" options must be specified');\n if (options.port != null)\n this._server = http.createServer((req, res) => {\n const body = http.STATUS_CODES[426];\n res.writeHead(426, {\n \"Content-Length\": body.length,\n \"Content-Type\": \"text/plain\"\n }), res.end(body);\n }), this._server.listen(options.port, options.host, options.backlog, callback);\n else if (options.server)\n this._server = options.server;\n if (this._server) {\n const emitConnection = this.emit.bind(this, \"connection\"), emitListening = this.emit.bind(this, \"listening\"), emitError = this.emit.bind(this, \"error\"), doUpgrade = (req, socket, head) => {\n this.handleUpgrade(req, socket, head, emitConnection);\n };\n this._server.on(\"listening\", emitListening), this._server.on(\"error\", emitError), this._server.on(\"upgrade\", doUpgrade), this._removeListeners = () => {\n this._server.removeListener(\"upgrade\", doUpgrade), this._server.removeListener(\"listening\", emitListening), this._server.removeListener(\"error\", emitError);\n };\n }\n if (options.perMessageDeflate === !0)\n options.perMessageDeflate = {};\n if (options.clientTracking)\n this.clients = new Set, this._shouldEmitClose = !1;\n this.options = options, this._state = RUNNING;\n }\n address() {\n if (this.options.noServer)\n throw new Error('The server is operating in \"noServer\" mode');\n if (!this._server)\n return null;\n return this._server.address();\n }\n close(cb) {\n if (this._state === CLOSED) {\n if (cb)\n this.once(\"close\", () => {\n cb(new Error(\"The server is not running\"));\n });\n process.nextTick((server) => {\n server._state = CLOSED, server.emit(\"close\");\n }, this);\n return;\n }\n if (cb)\n this.once(\"close\", cb);\n if (this._state === CLOSING)\n return;\n if (this._state = CLOSING, this.options.noServer || this.options.server) {\n if (this._server)\n this._removeListeners(), this._removeListeners = this._server = null;\n if (this.clients)\n if (!this.clients.size)\n process.nextTick((server) => {\n server._state = CLOSED, server.emit(\"close\");\n }, this);\n else\n this._shouldEmitClose = !0;\n else\n process.nextTick((server) => {\n server._state = CLOSED, server.emit(\"close\");\n }, this);\n } else {\n const server = this._server;\n this._removeListeners(), this._removeListeners = this._server = null, server.close(() => {\n this._state = CLOSED, this.emit(\"close\");\n });\n }\n }\n shouldHandle(req) {\n if (this.options.path) {\n const index = req.url.indexOf(\"\?\");\n if ((index !== -1 \? req.url.slice(0, index) : req.url) !== this.options.path)\n return !1;\n }\n return !0;\n }\n completeUpgrade(extensions, key, protocols, request, socket, head, cb) {\n const [server, response, req] = socket[kBunInternals];\n if (this._state > RUNNING)\n return abortHandshake(response, 503);\n let protocol = \"\";\n if (protocols.size)\n protocol = this.options.handleProtocols \? this.options.handleProtocols(protocols, request) : protocols.values().next().value;\n const ws = new BunWebSocketMocked(request.url, protocol, extensions, \"nodebuffer\"), headers = [\"HTTP/1.1 101 Switching Protocols\", \"Upgrade: websocket\", \"Connection: Upgrade\"];\n if (this.emit(\"headers\", headers, request), server.upgrade(req, {\n data: ws[kBunInternals]\n })) {\n if (response._reply(@undefined), this.clients)\n this.clients.add(ws), ws.on(\"close\", () => {\n if (this.clients.delete(ws), this._shouldEmitClose && !this.clients.size)\n process.nextTick(wsEmitClose, this);\n });\n cb(ws, request);\n } else\n abortHandshake(response, 500);\n }\n handleUpgrade(req, socket, head, cb) {\n const [_, response] = socket[kBunInternals], key = req.headers[\"sec-websocket-key\"], version = +req.headers[\"sec-websocket-version\"];\n if (req.method !== \"GET\") {\n abortHandshakeOrEmitwsClientError(this, req, response, socket, 405, \"Invalid HTTP method\");\n return;\n }\n if (req.headers.upgrade.toLowerCase() !== \"websocket\") {\n abortHandshakeOrEmitwsClientError(this, req, response, socket, 400, \"Invalid Upgrade header\");\n return;\n }\n if (!key || !wsKeyRegex.test(key)) {\n abortHandshakeOrEmitwsClientError(this, req, response, socket, 400, \"Missing or invalid Sec-WebSocket-Key header\");\n return;\n }\n if (version !== 8 && version !== 13) {\n abortHandshakeOrEmitwsClientError(this, req, response, socket, 400, \"Missing or invalid Sec-WebSocket-Version header\");\n return;\n }\n if (!this.shouldHandle(req)) {\n abortHandshake(response, 400);\n return;\n }\n const secWebSocketProtocol = req.headers[\"sec-websocket-protocol\"];\n let protocols = new Set;\n if (secWebSocketProtocol !== @undefined)\n try {\n protocols = subprotocolParse(secWebSocketProtocol);\n } catch (err) {\n abortHandshakeOrEmitwsClientError(this, req, response, socket, 400, \"Invalid Sec-WebSocket-Protocol header\");\n return;\n }\n const extensions = {};\n if (this.options.verifyClient) {\n const info = {\n origin: req.headers[`${version === 8 \? \"sec-websocket-origin\" : \"origin\"}`],\n secure: !!(req.socket.authorized || req.socket.encrypted),\n req\n };\n if (this.options.verifyClient.length === 2) {\n this.options.verifyClient(info, (verified, code, message, headers) => {\n if (!verified)\n return abortHandshake(response, code || 401, message, headers);\n this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);\n });\n return;\n }\n if (!this.options.verifyClient(info))\n return abortHandshake(response, 401);\n }\n this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);\n }\n}\nObject.defineProperty(BunWebSocket, \"CONNECTING\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CONNECTING\")\n});\nObject.defineProperty(BunWebSocket.prototype, \"CONNECTING\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CONNECTING\")\n});\nObject.defineProperty(BunWebSocket, \"OPEN\", {\n enumerable: !0,\n value: readyStates.indexOf(\"OPEN\")\n});\nObject.defineProperty(BunWebSocket.prototype, \"OPEN\", {\n enumerable: !0,\n value: readyStates.indexOf(\"OPEN\")\n});\nObject.defineProperty(BunWebSocket, \"CLOSING\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CLOSING\")\n});\nObject.defineProperty(BunWebSocket.prototype, \"CLOSING\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CLOSING\")\n});\nObject.defineProperty(BunWebSocket, \"CLOSED\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CLOSED\")\n});\nObject.defineProperty(BunWebSocket.prototype, \"CLOSED\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CLOSED\")\n});\n\nclass Sender {\n constructor() {\n throw new Error(\"Not supported yet in Bun\");\n }\n}\n\nclass Receiver {\n constructor() {\n throw new Error(\"Not supported yet in Bun\");\n }\n}\nvar createWebSocketStream = (ws) => {\n throw new Error(\"Not supported yet in Bun\");\n};\n$ = Object.assign(BunWebSocket, {\n createWebSocketStream,\n Receiver,\n Sender,\n WebSocket: BunWebSocket,\n Server: WebSocketServer,\n WebSocketServer\n});\nreturn $})\n"_s;
+static constexpr ASCIILiteral ThirdpartyWSCode = "(function (){\"use strict\";// src/js/out/tmp/thirdparty/ws.ts\nvar emitWarning = function(type, message) {\n if (emittedWarnings.has(type))\n return;\n emittedWarnings.add(type), console.warn(\"[bun] Warning:\", message);\n}, subprotocolParse = function(header) {\n const protocols = new Set;\n let start = -1, end = -1, i = 0;\n for (i;i < header.length; i++) {\n const code = header.charCodeAt(i);\n if (end === -1 && wsTokenChars[code] === 1) {\n if (start === -1)\n start = i;\n } else if (i !== 0 && (code === 32 || code === 9)) {\n if (end === -1 && start !== -1)\n end = i;\n } else if (code === 44) {\n if (start === -1)\n throw new SyntaxError(`Unexpected character at index ${i}`);\n if (end === -1)\n end = i;\n const protocol2 = header.slice(start, end);\n if (protocols.has(protocol2))\n throw new SyntaxError(`The \"${protocol2}\" subprotocol is duplicated`);\n protocols.add(protocol2), start = end = -1;\n } else\n throw new SyntaxError(`Unexpected character at index ${i}`);\n }\n if (start === -1 || end !== -1)\n throw new SyntaxError(\"Unexpected end of input\");\n const protocol = header.slice(start, i);\n if (protocols.has(protocol))\n throw new SyntaxError(`The \"${protocol}\" subprotocol is duplicated`);\n return protocols.add(protocol), protocols;\n}, wsEmitClose = function(server) {\n server._state = CLOSED, server.emit(\"close\");\n}, abortHandshake = function(response, code, message, headers) {\n message = message || http.STATUS_CODES[code], headers = {\n Connection: \"close\",\n \"Content-Type\": \"text/html\",\n \"Content-Length\": @Buffer.byteLength(message),\n ...headers\n }, response.writeHead(code, headers), response.write(message), response.end();\n}, abortHandshakeOrEmitwsClientError = function(server, req, response, socket, code, message) {\n if (server.listenerCount(\"wsClientError\")) {\n const err = new Error(message);\n Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError), server.emit(\"wsClientError\", err, socket, req);\n } else\n abortHandshake(response, code, message);\n}, $, EventEmitter = @getInternalField(@internalModuleRegistry, 18) || @createInternalModuleById(18), http = @getInternalField(@internalModuleRegistry, 21) || @createInternalModuleById(21), kBunInternals = Symbol.for(\"::bunternal::\"), readyStates = [\"CONNECTING\", \"OPEN\", \"CLOSING\", \"CLOSED\"], encoder = new TextEncoder, eventIds = {\n open: 1,\n close: 2,\n message: 3,\n error: 4,\n ping: 5,\n pong: 6\n}, emittedWarnings = new Set;\n\nclass BunWebSocket extends EventEmitter {\n static CONNECTING = 0;\n static OPEN = 1;\n static CLOSING = 2;\n static CLOSED = 3;\n #ws;\n #paused = !1;\n #fragments = !1;\n #binaryType = \"nodebuffer\";\n #eventId = 0;\n constructor(url, protocols, options) {\n super();\n let ws = this.#ws = new WebSocket(url, protocols);\n ws.binaryType = \"nodebuffer\";\n }\n on(event, listener) {\n if (event === \"unexpected-response\" || event === \"upgrade\" || event === \"redirect\")\n emitWarning(event, \"ws.WebSocket '\" + event + \"' event is not implemented in bun\");\n const mask = 1 << eventIds[event];\n if (mask && (this.#eventId & mask) !== mask) {\n if (this.#eventId |= mask, event === \"open\")\n this.#ws.addEventListener(\"open\", () => {\n this.emit(\"open\");\n });\n else if (event === \"close\")\n this.#ws.addEventListener(\"close\", ({ code, reason, wasClean }) => {\n this.emit(\"close\", code, reason, wasClean);\n });\n else if (event === \"message\")\n this.#ws.addEventListener(\"message\", ({ data }) => {\n const isBinary = typeof data !== \"string\";\n if (isBinary)\n this.emit(\"message\", this.#fragments \? [data] : data, isBinary);\n else {\n let encoded = encoder.encode(data);\n if (this.#binaryType !== \"arraybuffer\")\n encoded = @Buffer.from(encoded.buffer, encoded.byteOffset, encoded.byteLength);\n this.emit(\"message\", this.#fragments \? [encoded] : encoded, isBinary);\n }\n });\n else if (event === \"error\")\n this.#ws.addEventListener(\"error\", (err) => {\n this.emit(\"error\", err);\n });\n else if (event === \"ping\")\n this.#ws.addEventListener(\"ping\", ({ data }) => {\n this.emit(\"ping\", data);\n });\n else if (event === \"pong\")\n this.#ws.addEventListener(\"pong\", ({ data }) => {\n this.emit(\"pong\", data);\n });\n }\n return super.on(event, listener);\n }\n send(data, opts, cb) {\n try {\n this.#ws.send(data, opts\?.compress);\n } catch (error) {\n typeof cb === \"function\" && cb(error);\n return;\n }\n typeof cb === \"function\" && cb();\n }\n close(code, reason) {\n this.#ws.close(code, reason);\n }\n terminate() {\n this.#ws.terminate();\n }\n get url() {\n return this.#ws.url;\n }\n get readyState() {\n return this.#ws.readyState;\n }\n get binaryType() {\n return this.#binaryType;\n }\n set binaryType(value) {\n if (value === \"nodebuffer\" || value === \"arraybuffer\")\n this.#ws.binaryType = this.#binaryType = value, this.#fragments = !1;\n else if (value === \"fragments\")\n this.#ws.binaryType = \"nodebuffer\", this.#binaryType = \"fragments\", this.#fragments = !0;\n else\n throw new Error(`Invalid binaryType: ${value}`);\n }\n get protocol() {\n return this.#ws.protocol;\n }\n get extensions() {\n return this.#ws.extensions;\n }\n addEventListener(type, listener, options) {\n this.#ws.addEventListener(type, listener, options);\n }\n removeEventListener(type, listener) {\n this.#ws.removeEventListener(type, listener);\n }\n get onopen() {\n return this.#ws.onopen;\n }\n set onopen(value) {\n this.#ws.onopen = value;\n }\n get onerror() {\n return this.#ws.onerror;\n }\n set onerror(value) {\n this.#ws.onerror = value;\n }\n get onclose() {\n return this.#ws.onclose;\n }\n set onclose(value) {\n this.#ws.onclose = value;\n }\n get onmessage() {\n return this.#ws.onmessage;\n }\n set onmessage(value) {\n this.#ws.onmessage = value;\n }\n get bufferedAmount() {\n return this.#ws.bufferedAmount;\n }\n get isPaused() {\n return this.#paused;\n }\n ping(data, mask, cb) {\n if (typeof data === \"function\")\n cb = data, data = mask = @undefined;\n else if (typeof mask === \"function\")\n cb = mask, mask = @undefined;\n if (typeof data === \"number\")\n data = data.toString();\n try {\n this.#ws.ping(data);\n } catch (error) {\n typeof cb === \"function\" && cb(error);\n return;\n }\n typeof cb === \"function\" && cb();\n }\n pong(data, mask, cb) {\n if (typeof data === \"function\")\n cb = data, data = mask = @undefined;\n else if (typeof mask === \"function\")\n cb = mask, mask = @undefined;\n if (typeof data === \"number\")\n data = data.toString();\n try {\n this.#ws.pong(data);\n } catch (error) {\n typeof cb === \"function\" && cb(error);\n return;\n }\n typeof cb === \"function\" && cb();\n }\n pause() {\n switch (this.readyState) {\n case WebSocket.CONNECTING:\n case WebSocket.CLOSED:\n return;\n }\n this.#paused = !0, emitWarning(\"pause()\", \"ws.WebSocket.pause() is not implemented in bun\");\n }\n resume() {\n switch (this.readyState) {\n case WebSocket.CONNECTING:\n case WebSocket.CLOSED:\n return;\n }\n this.#paused = !1, emitWarning(\"resume()\", \"ws.WebSocket.resume() is not implemented in bun\");\n }\n}\nObject.defineProperty(BunWebSocket, \"name\", { value: \"WebSocket\" });\nvar wsKeyRegex = /^[+/0-9A-Za-z]{22}==$/, wsTokenChars = [\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 1,\n 0,\n 1,\n 1,\n 1,\n 1,\n 1,\n 0,\n 0,\n 1,\n 1,\n 0,\n 1,\n 1,\n 0,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 0,\n 0,\n 0,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 0,\n 1,\n 0,\n 1,\n 0\n], RUNNING = 0, CLOSING = 1, CLOSED = 2;\n\nclass BunWebSocketMocked extends EventEmitter {\n #ws;\n #state;\n #enquedMessages = [];\n #url;\n #protocol;\n #extensions;\n #bufferedAmount = 0;\n #binaryType = \"arraybuffer\";\n #onclose;\n #onerror;\n #onmessage;\n #onopen;\n constructor(url, protocol, extensions, binaryType) {\n super();\n if (this.#ws = null, this.#state = 0, this.#url = url, this.#bufferedAmount = 0, binaryType = binaryType || \"arraybuffer\", binaryType !== \"nodebuffer\" && binaryType !== \"blob\" && binaryType !== \"arraybuffer\")\n @throwTypeError(\"binaryType must be either 'blob', 'arraybuffer' or 'nodebuffer'\");\n this.#binaryType = binaryType, this.#protocol = protocol, this.#extensions = extensions;\n const message = this.#message.bind(this), open = this.#open.bind(this), close = this.#close.bind(this), drain = this.#drain.bind(this);\n this[kBunInternals] = {\n message,\n open,\n close,\n drain\n };\n }\n #message(ws, message) {\n this.#ws = ws;\n let isBinary = !1;\n if (typeof message === \"string\")\n if (this.#binaryType === \"arraybuffer\")\n message = encoder.encode(message).buffer;\n else if (this.#binaryType === \"blob\")\n message = new Blob([message], { type: \"text/plain\" });\n else\n message = @Buffer.from(message);\n else if (isBinary = !0, this.#binaryType !== \"nodebuffer\") {\n if (this.#binaryType === \"arraybuffer\")\n message = new @Uint8Array(message);\n else if (this.#binaryType === \"blob\")\n message = new Blob([message]);\n }\n this.emit(\"message\", message, isBinary);\n }\n #open(ws) {\n this.#ws = ws, this.#state = 1, this.emit(\"open\", this), this.#drain(ws);\n }\n #close(ws, code, reason) {\n this.#state = 3, this.#ws = null, this.emit(\"close\", code, reason);\n }\n #drain(ws) {\n const chunk = this.#enquedMessages[0];\n if (chunk) {\n const [data, compress, cb] = chunk;\n if (ws.send(data, compress) == -1)\n return;\n typeof cb === \"function\" && cb(), this.#bufferedAmount -= chunk.length, this.#enquedMessages.shift();\n }\n }\n send(data, opts, cb) {\n if (this.#state === 1) {\n const compress = opts\?.compress;\n if (this.#ws.send(data, compress) == -1) {\n this.#enquedMessages.push([data, compress, cb]), this.#bufferedAmount += data.length;\n return;\n }\n typeof cb === \"function\" && cb();\n } else if (this.#state === 0)\n this.#enquedMessages.push([data, opts\?.compress, cb]), this.#bufferedAmount += data.length;\n }\n close(code, reason) {\n if (this.#state === 1)\n this.#state = 2, this.#ws.close(code, reason);\n }\n get binaryType() {\n return this.#binaryType;\n }\n set binaryType(type) {\n if (type !== \"nodebuffer\" && type !== \"blob\" && type !== \"arraybuffer\")\n @throwTypeError(\"binaryType must be either 'blob', 'arraybuffer' or 'nodebuffer'\");\n this.#binaryType = type;\n }\n get readyState() {\n return this.#state;\n }\n get url() {\n return this.#url;\n }\n get protocol() {\n return this.#protocol;\n }\n get extensions() {\n return this.#extensions;\n }\n get bufferedAmount() {\n return this.#bufferedAmount \?\? 0;\n }\n setSocket(socket, head, options) {\n throw new Error(\"Not implemented\");\n }\n set onclose(cb) {\n if (this.#onclose)\n this.removeListener(\"close\", this.#onclose);\n this.on(\"close\", cb), this.#onclose = cb;\n }\n set onerror(cb) {\n if (this.#onerror)\n this.removeListener(\"error\", this.#onerror);\n this.on(\"error\", cb), this.#onerror = cb;\n }\n set onmessage(cb) {\n if (this.#onmessage)\n this.removeListener(\"message\", this.#onmessage);\n this.on(\"message\", cb), this.#onmessage = cb;\n }\n set onopen(cb) {\n if (this.#onopen)\n this.removeListener(\"open\", this.#onopen);\n this.on(\"open\", cb), this.#onopen = cb;\n }\n get onclose() {\n return this.#onclose;\n }\n get onerror() {\n return this.#onerror;\n }\n get onmessage() {\n return this.#onmessage;\n }\n get onopen() {\n return this.#onopen;\n }\n addEventListener(type, listener, options) {\n if (type === \"message\") {\n const l = (data) => listener({ data });\n l.listener = listener, this.on(type, l);\n return;\n }\n this.on(type, listener);\n }\n removeEventListener(type, listener) {\n this.off(type, listener);\n }\n}\n\nclass WebSocketServer extends EventEmitter {\n _server;\n options;\n clients;\n _shouldEmitClose;\n _state;\n _removeListeners;\n constructor(options, callback) {\n super();\n if (options = {\n maxPayload: 104857600,\n skipUTF8Validation: !1,\n perMessageDeflate: !1,\n handleProtocols: null,\n clientTracking: !0,\n verifyClient: null,\n noServer: !1,\n backlog: null,\n server: null,\n host: null,\n path: null,\n port: null,\n ...options\n }, options.port == null && !options.server && !options.noServer || options.port != null && (options.server || options.noServer) || options.server && options.noServer)\n @throwTypeError('One and only one of the \"port\", \"server\", or \"noServer\" options must be specified');\n if (options.port != null)\n this._server = http.createServer((req, res) => {\n const body = http.STATUS_CODES[426];\n res.writeHead(426, {\n \"Content-Length\": body.length,\n \"Content-Type\": \"text/plain\"\n }), res.end(body);\n }), this._server.listen(options.port, options.host, options.backlog, callback);\n else if (options.server)\n this._server = options.server;\n if (this._server) {\n const emitConnection = this.emit.bind(this, \"connection\"), emitListening = this.emit.bind(this, \"listening\"), emitError = this.emit.bind(this, \"error\"), doUpgrade = (req, socket, head) => {\n this.handleUpgrade(req, socket, head, emitConnection);\n };\n this._server.on(\"listening\", emitListening), this._server.on(\"error\", emitError), this._server.on(\"upgrade\", doUpgrade), this._removeListeners = () => {\n this._server.removeListener(\"upgrade\", doUpgrade), this._server.removeListener(\"listening\", emitListening), this._server.removeListener(\"error\", emitError);\n };\n }\n if (options.perMessageDeflate === !0)\n options.perMessageDeflate = {};\n if (options.clientTracking)\n this.clients = new Set, this._shouldEmitClose = !1;\n this.options = options, this._state = RUNNING;\n }\n address() {\n if (this.options.noServer)\n throw new Error('The server is operating in \"noServer\" mode');\n if (!this._server)\n return null;\n return this._server.address();\n }\n close(cb) {\n if (this._state === CLOSED) {\n if (cb)\n this.once(\"close\", () => {\n cb(new Error(\"The server is not running\"));\n });\n process.nextTick((server) => {\n server._state = CLOSED, server.emit(\"close\");\n }, this);\n return;\n }\n if (cb)\n this.once(\"close\", cb);\n if (this._state === CLOSING)\n return;\n if (this._state = CLOSING, this.options.noServer || this.options.server) {\n if (this._server)\n this._removeListeners(), this._removeListeners = this._server = null;\n if (this.clients)\n if (!this.clients.size)\n process.nextTick((server) => {\n server._state = CLOSED, server.emit(\"close\");\n }, this);\n else\n this._shouldEmitClose = !0;\n else\n process.nextTick((server) => {\n server._state = CLOSED, server.emit(\"close\");\n }, this);\n } else {\n const server = this._server;\n this._removeListeners(), this._removeListeners = this._server = null, server.close(() => {\n this._state = CLOSED, this.emit(\"close\");\n });\n }\n }\n shouldHandle(req) {\n if (this.options.path) {\n const index = req.url.indexOf(\"\?\");\n if ((index !== -1 \? req.url.slice(0, index) : req.url) !== this.options.path)\n return !1;\n }\n return !0;\n }\n completeUpgrade(extensions, key, protocols, request, socket, head, cb) {\n const [server, response, req] = socket[kBunInternals];\n if (this._state > RUNNING)\n return abortHandshake(response, 503);\n let protocol = \"\";\n if (protocols.size)\n protocol = this.options.handleProtocols \? this.options.handleProtocols(protocols, request) : protocols.values().next().value;\n const ws = new BunWebSocketMocked(request.url, protocol, extensions, \"nodebuffer\"), headers = [\"HTTP/1.1 101 Switching Protocols\", \"Upgrade: websocket\", \"Connection: Upgrade\"];\n if (this.emit(\"headers\", headers, request), server.upgrade(req, {\n data: ws[kBunInternals]\n })) {\n if (response._reply(@undefined), this.clients)\n this.clients.add(ws), ws.on(\"close\", () => {\n if (this.clients.delete(ws), this._shouldEmitClose && !this.clients.size)\n process.nextTick(wsEmitClose, this);\n });\n cb(ws, request);\n } else\n abortHandshake(response, 500);\n }\n handleUpgrade(req, socket, head, cb) {\n const [_, response] = socket[kBunInternals], key = req.headers[\"sec-websocket-key\"], version = +req.headers[\"sec-websocket-version\"];\n if (req.method !== \"GET\") {\n abortHandshakeOrEmitwsClientError(this, req, response, socket, 405, \"Invalid HTTP method\");\n return;\n }\n if (req.headers.upgrade.toLowerCase() !== \"websocket\") {\n abortHandshakeOrEmitwsClientError(this, req, response, socket, 400, \"Invalid Upgrade header\");\n return;\n }\n if (!key || !wsKeyRegex.test(key)) {\n abortHandshakeOrEmitwsClientError(this, req, response, socket, 400, \"Missing or invalid Sec-WebSocket-Key header\");\n return;\n }\n if (version !== 8 && version !== 13) {\n abortHandshakeOrEmitwsClientError(this, req, response, socket, 400, \"Missing or invalid Sec-WebSocket-Version header\");\n return;\n }\n if (!this.shouldHandle(req)) {\n abortHandshake(response, 400);\n return;\n }\n const secWebSocketProtocol = req.headers[\"sec-websocket-protocol\"];\n let protocols = new Set;\n if (secWebSocketProtocol !== @undefined)\n try {\n protocols = subprotocolParse(secWebSocketProtocol);\n } catch (err) {\n abortHandshakeOrEmitwsClientError(this, req, response, socket, 400, \"Invalid Sec-WebSocket-Protocol header\");\n return;\n }\n const extensions = {};\n if (this.options.verifyClient) {\n const info = {\n origin: req.headers[`${version === 8 \? \"sec-websocket-origin\" : \"origin\"}`],\n secure: !!(req.socket.authorized || req.socket.encrypted),\n req\n };\n if (this.options.verifyClient.length === 2) {\n this.options.verifyClient(info, (verified, code, message, headers) => {\n if (!verified)\n return abortHandshake(response, code || 401, message, headers);\n this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);\n });\n return;\n }\n if (!this.options.verifyClient(info))\n return abortHandshake(response, 401);\n }\n this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);\n }\n}\nObject.defineProperty(BunWebSocket, \"CONNECTING\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CONNECTING\")\n});\nObject.defineProperty(BunWebSocket.prototype, \"CONNECTING\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CONNECTING\")\n});\nObject.defineProperty(BunWebSocket, \"OPEN\", {\n enumerable: !0,\n value: readyStates.indexOf(\"OPEN\")\n});\nObject.defineProperty(BunWebSocket.prototype, \"OPEN\", {\n enumerable: !0,\n value: readyStates.indexOf(\"OPEN\")\n});\nObject.defineProperty(BunWebSocket, \"CLOSING\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CLOSING\")\n});\nObject.defineProperty(BunWebSocket.prototype, \"CLOSING\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CLOSING\")\n});\nObject.defineProperty(BunWebSocket, \"CLOSED\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CLOSED\")\n});\nObject.defineProperty(BunWebSocket.prototype, \"CLOSED\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CLOSED\")\n});\n\nclass Sender {\n constructor() {\n throw new Error(\"Not supported yet in Bun\");\n }\n}\n\nclass Receiver {\n constructor() {\n throw new Error(\"Not supported yet in Bun\");\n }\n}\nvar createWebSocketStream = (ws) => {\n throw new Error(\"Not supported yet in Bun\");\n};\n$ = Object.assign(BunWebSocket, {\n createWebSocketStream,\n Receiver,\n Sender,\n WebSocket: BunWebSocket,\n Server: WebSocketServer,\n WebSocketServer\n});\nreturn $})\n"_s;
//
#elif _WIN32
@@ -483,7 +483,7 @@ static constexpr ASCIILiteral ThirdpartyVercelFetchCode = "(function (){\"use st
//
//
-static constexpr ASCIILiteral ThirdpartyWSCode = "(function (){\"use strict\";// src/js/out/tmp/thirdparty/ws.ts\nvar emitWarning = function(type, message) {\n if (emittedWarnings.has(type))\n return;\n emittedWarnings.add(type), console.warn(\"[bun] Warning:\", message);\n}, subprotocolParse = function(header) {\n const protocols = new Set;\n let start = -1, end = -1, i = 0;\n for (i;i < header.length; i++) {\n const code = header.charCodeAt(i);\n if (end === -1 && wsTokenChars[code] === 1) {\n if (start === -1)\n start = i;\n } else if (i !== 0 && (code === 32 || code === 9)) {\n if (end === -1 && start !== -1)\n end = i;\n } else if (code === 44) {\n if (start === -1)\n throw new SyntaxError(`Unexpected character at index ${i}`);\n if (end === -1)\n end = i;\n const protocol2 = header.slice(start, end);\n if (protocols.has(protocol2))\n throw new SyntaxError(`The \"${protocol2}\" subprotocol is duplicated`);\n protocols.add(protocol2), start = end = -1;\n } else\n throw new SyntaxError(`Unexpected character at index ${i}`);\n }\n if (start === -1 || end !== -1)\n throw new SyntaxError(\"Unexpected end of input\");\n const protocol = header.slice(start, i);\n if (protocols.has(protocol))\n throw new SyntaxError(`The \"${protocol}\" subprotocol is duplicated`);\n return protocols.add(protocol), protocols;\n}, wsEmitClose = function(server) {\n server._state = CLOSED, server.emit(\"close\");\n}, abortHandshake = function(response, code, message, headers) {\n message = message || http.STATUS_CODES[code], headers = {\n Connection: \"close\",\n \"Content-Type\": \"text/html\",\n \"Content-Length\": @Buffer.byteLength(message),\n ...headers\n }, response.writeHead(code, headers), response.write(message), response.end();\n}, abortHandshakeOrEmitwsClientError = function(server, req, response, socket, code, message) {\n if (server.listenerCount(\"wsClientError\")) {\n const err = new Error(message);\n Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError), server.emit(\"wsClientError\", err, socket, req);\n } else\n abortHandshake(response, code, message);\n}, $, EventEmitter = @getInternalField(@internalModuleRegistry, 18) || @createInternalModuleById(18), http = @getInternalField(@internalModuleRegistry, 21) || @createInternalModuleById(21), kBunInternals = Symbol.for(\"::bunternal::\"), readyStates = [\"CONNECTING\", \"OPEN\", \"CLOSING\", \"CLOSED\"], encoder = new TextEncoder, eventIds = {\n open: 1,\n close: 2,\n message: 3,\n error: 4,\n ping: 5,\n pong: 6\n}, emittedWarnings = new Set;\n\nclass BunWebSocket extends EventEmitter {\n static CONNECTING = 0;\n static OPEN = 1;\n static CLOSING = 2;\n static CLOSED = 3;\n #ws;\n #paused = !1;\n #fragments = !1;\n #binaryType = \"nodebuffer\";\n #eventId = 0;\n constructor(url, protocols, options) {\n super();\n let ws = this.#ws = new WebSocket(url, protocols);\n ws.binaryType = \"nodebuffer\";\n }\n on(event, listener) {\n if (event === \"unexpected-response\" || event === \"upgrade\" || event === \"redirect\")\n emitWarning(event, \"ws.WebSocket '\" + event + \"' event is not implemented in bun\");\n const mask = 1 << eventIds[event];\n if (mask && (this.#eventId & mask) !== mask) {\n if (this.#eventId |= mask, event === \"open\")\n this.#ws.addEventListener(\"open\", () => {\n this.emit(\"open\");\n });\n else if (event === \"close\")\n this.#ws.addEventListener(\"close\", ({ code, reason, wasClean }) => {\n this.emit(\"close\", code, reason, wasClean);\n });\n else if (event === \"message\")\n this.#ws.addEventListener(\"message\", ({ data }) => {\n const isBinary = typeof data !== \"string\";\n if (isBinary)\n this.emit(\"message\", this.#fragments \? [data] : data, isBinary);\n else {\n let encoded = encoder.encode(data);\n if (this.#binaryType !== \"arraybuffer\")\n encoded = @Buffer.from(encoded.buffer, encoded.byteOffset, encoded.byteLength);\n this.emit(\"message\", this.#fragments \? [encoded] : encoded, isBinary);\n }\n });\n else if (event === \"error\")\n this.#ws.addEventListener(\"error\", (err) => {\n this.emit(\"error\", err);\n });\n else if (event === \"ping\")\n this.#ws.addEventListener(\"ping\", ({ data }) => {\n this.emit(\"ping\", data);\n });\n else if (event === \"pong\")\n this.#ws.addEventListener(\"pong\", ({ data }) => {\n this.emit(\"pong\", data);\n });\n }\n return super.on(event, listener);\n }\n send(data, opts, cb) {\n try {\n this.#ws.send(data, opts\?.compress);\n } catch (error) {\n typeof cb === \"function\" && cb(error);\n return;\n }\n typeof cb === \"function\" && cb();\n }\n close(code, reason) {\n this.#ws.close(code, reason);\n }\n terminate() {\n this.#ws.terminate();\n }\n get url() {\n return this.#ws.url;\n }\n get readyState() {\n return this.#ws.readyState;\n }\n get binaryType() {\n return this.#binaryType;\n }\n set binaryType(value) {\n if (value === \"nodebuffer\" || value === \"arraybuffer\")\n this.#ws.binaryType = this.#binaryType = value, this.#fragments = !1;\n else if (value === \"fragments\")\n this.#ws.binaryType = \"nodebuffer\", this.#binaryType = \"fragments\", this.#fragments = !0;\n else\n throw new Error(`Invalid binaryType: ${value}`);\n }\n get protocol() {\n return this.#ws.protocol;\n }\n get extensions() {\n return this.#ws.extensions;\n }\n addEventListener(type, listener, options) {\n this.#ws.addEventListener(type, listener, options);\n }\n removeEventListener(type, listener) {\n this.#ws.removeEventListener(type, listener);\n }\n get onopen() {\n return this.#ws.onopen;\n }\n set onopen(value) {\n this.#ws.onopen = value;\n }\n get onerror() {\n return this.#ws.onerror;\n }\n set onerror(value) {\n this.#ws.onerror = value;\n }\n get onclose() {\n return this.#ws.onclose;\n }\n set onclose(value) {\n this.#ws.onclose = value;\n }\n get onmessage() {\n return this.#ws.onmessage;\n }\n set onmessage(value) {\n this.#ws.onmessage = value;\n }\n get bufferedAmount() {\n return this.#ws.bufferedAmount;\n }\n get isPaused() {\n return this.#paused;\n }\n ping(data, mask, cb) {\n if (typeof data === \"function\")\n cb = data, data = mask = @undefined;\n else if (typeof mask === \"function\")\n cb = mask, mask = @undefined;\n if (typeof data === \"number\")\n data = data.toString();\n try {\n this.#ws.ping(data);\n } catch (error) {\n typeof cb === \"function\" && cb(error);\n return;\n }\n typeof cb === \"function\" && cb();\n }\n pong(data, mask, cb) {\n if (typeof data === \"function\")\n cb = data, data = mask = @undefined;\n else if (typeof mask === \"function\")\n cb = mask, mask = @undefined;\n if (typeof data === \"number\")\n data = data.toString();\n try {\n this.#ws.pong(data);\n } catch (error) {\n typeof cb === \"function\" && cb(error);\n return;\n }\n typeof cb === \"function\" && cb();\n }\n pause() {\n switch (this.readyState) {\n case WebSocket.CONNECTING:\n case WebSocket.CLOSED:\n return;\n }\n this.#paused = !0, emitWarning(\"pause()\", \"ws.WebSocket.pause() is not implemented in bun\");\n }\n resume() {\n switch (this.readyState) {\n case WebSocket.CONNECTING:\n case WebSocket.CLOSED:\n return;\n }\n this.#paused = !1, emitWarning(\"resume()\", \"ws.WebSocket.resume() is not implemented in bun\");\n }\n}\nObject.defineProperty(BunWebSocket, \"name\", { value: \"WebSocket\" });\nvar wsKeyRegex = /^[+/0-9A-Za-z]{22}==$/, wsTokenChars = [\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 1,\n 0,\n 1,\n 1,\n 1,\n 1,\n 1,\n 0,\n 0,\n 1,\n 1,\n 0,\n 1,\n 1,\n 0,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 0,\n 0,\n 0,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 0,\n 1,\n 0,\n 1,\n 0\n], RUNNING = 0, CLOSING = 1, CLOSED = 2;\n\nclass BunWebSocketMocked extends EventEmitter {\n #ws;\n #state;\n #enquedMessages = [];\n #url;\n #protocol;\n #extensions;\n #bufferedAmount = 0;\n #binaryType = \"arraybuffer\";\n #onclose;\n #onerror;\n #onmessage;\n #onopen;\n constructor(url, protocol, extensions, binaryType) {\n super();\n if (this.#ws = null, this.#state = 0, this.#url = url, this.#bufferedAmount = 0, binaryType = binaryType || \"arraybuffer\", binaryType !== \"nodebuffer\" && binaryType !== \"blob\" && binaryType !== \"arraybuffer\")\n @throwTypeError(\"binaryType must be either 'blob', 'arraybuffer' or 'nodebuffer'\");\n this.#binaryType = binaryType, this.#protocol = protocol, this.#extensions = extensions;\n const message = this.#message.bind(this), open = this.#open.bind(this), close = this.#close.bind(this), drain = this.#drain.bind(this);\n this[kBunInternals] = {\n message,\n open,\n close,\n drain\n };\n }\n #message(ws, message) {\n if (this.#ws = ws, typeof message === \"string\")\n if (this.#binaryType === \"arraybuffer\")\n message = encoder.encode(message).buffer;\n else if (this.#binaryType === \"blob\")\n message = new Blob([message], { type: \"text/plain\" });\n else\n message = @Buffer.from(message);\n else if (this.#binaryType !== \"nodebuffer\") {\n if (this.#binaryType === \"arraybuffer\")\n message = new @Uint8Array(message);\n else if (this.#binaryType === \"blob\")\n message = new Blob([message]);\n }\n this.emit(\"message\", message);\n }\n #open(ws) {\n this.#ws = ws, this.#state = 1, this.emit(\"open\", this), this.#drain(ws);\n }\n #close(ws, code, reason) {\n this.#state = 3, this.#ws = null, this.emit(\"close\", code, reason);\n }\n #drain(ws) {\n const chunk = this.#enquedMessages[0];\n if (chunk) {\n const [data, compress, cb] = chunk;\n if (ws.send(data, compress) == -1)\n return;\n typeof cb === \"function\" && cb(), this.#bufferedAmount -= chunk.length, this.#enquedMessages.shift();\n }\n }\n send(data, opts, cb) {\n if (this.#state === 1) {\n const compress = opts\?.compress;\n if (this.#ws.send(data, compress) == -1) {\n this.#enquedMessages.push([data, compress, cb]), this.#bufferedAmount += data.length;\n return;\n }\n typeof cb === \"function\" && cb();\n } else if (this.#state === 0)\n this.#enquedMessages.push([data, opts\?.compress, cb]), this.#bufferedAmount += data.length;\n }\n close(code, reason) {\n if (this.#state === 1)\n this.#state = 2, this.#ws.close(code, reason);\n }\n get binaryType() {\n return this.#binaryType;\n }\n set binaryType(type) {\n if (type !== \"nodebuffer\" && type !== \"blob\" && type !== \"arraybuffer\")\n @throwTypeError(\"binaryType must be either 'blob', 'arraybuffer' or 'nodebuffer'\");\n this.#binaryType = type;\n }\n get readyState() {\n return this.#state;\n }\n get url() {\n return this.#url;\n }\n get protocol() {\n return this.#protocol;\n }\n get extensions() {\n return this.#extensions;\n }\n get bufferedAmount() {\n return this.#bufferedAmount \?\? 0;\n }\n setSocket(socket, head, options) {\n throw new Error(\"Not implemented\");\n }\n set onclose(cb) {\n if (this.#onclose)\n this.removeListener(\"close\", this.#onclose);\n this.on(\"close\", cb), this.#onclose = cb;\n }\n set onerror(cb) {\n if (this.#onerror)\n this.removeListener(\"error\", this.#onerror);\n this.on(\"error\", cb), this.#onerror = cb;\n }\n set onmessage(cb) {\n if (this.#onmessage)\n this.removeListener(\"message\", this.#onmessage);\n this.on(\"message\", cb), this.#onmessage = cb;\n }\n set onopen(cb) {\n if (this.#onopen)\n this.removeListener(\"open\", this.#onopen);\n this.on(\"open\", cb), this.#onopen = cb;\n }\n get onclose() {\n return this.#onclose;\n }\n get onerror() {\n return this.#onerror;\n }\n get onmessage() {\n return this.#onmessage;\n }\n get onopen() {\n return this.#onopen;\n }\n addEventListener(type, listener, options) {\n if (type === \"message\") {\n const l = (data) => listener({ data });\n l.listener = listener, this.on(type, l);\n return;\n }\n this.on(type, listener);\n }\n removeEventListener(type, listener) {\n this.off(type, listener);\n }\n}\n\nclass WebSocketServer extends EventEmitter {\n _server;\n options;\n clients;\n _shouldEmitClose;\n _state;\n _removeListeners;\n constructor(options, callback) {\n super();\n if (options = {\n maxPayload: 104857600,\n skipUTF8Validation: !1,\n perMessageDeflate: !1,\n handleProtocols: null,\n clientTracking: !0,\n verifyClient: null,\n noServer: !1,\n backlog: null,\n server: null,\n host: null,\n path: null,\n port: null,\n ...options\n }, options.port == null && !options.server && !options.noServer || options.port != null && (options.server || options.noServer) || options.server && options.noServer)\n @throwTypeError('One and only one of the \"port\", \"server\", or \"noServer\" options must be specified');\n if (options.port != null)\n this._server = http.createServer((req, res) => {\n const body = http.STATUS_CODES[426];\n res.writeHead(426, {\n \"Content-Length\": body.length,\n \"Content-Type\": \"text/plain\"\n }), res.end(body);\n }), this._server.listen(options.port, options.host, options.backlog, callback);\n else if (options.server)\n this._server = options.server;\n if (this._server) {\n const emitConnection = this.emit.bind(this, \"connection\"), emitListening = this.emit.bind(this, \"listening\"), emitError = this.emit.bind(this, \"error\"), doUpgrade = (req, socket, head) => {\n this.handleUpgrade(req, socket, head, emitConnection);\n };\n this._server.on(\"listening\", emitListening), this._server.on(\"error\", emitError), this._server.on(\"upgrade\", doUpgrade), this._removeListeners = () => {\n this._server.removeListener(\"upgrade\", doUpgrade), this._server.removeListener(\"listening\", emitListening), this._server.removeListener(\"error\", emitError);\n };\n }\n if (options.perMessageDeflate === !0)\n options.perMessageDeflate = {};\n if (options.clientTracking)\n this.clients = new Set, this._shouldEmitClose = !1;\n this.options = options, this._state = RUNNING;\n }\n address() {\n if (this.options.noServer)\n throw new Error('The server is operating in \"noServer\" mode');\n if (!this._server)\n return null;\n return this._server.address();\n }\n close(cb) {\n if (this._state === CLOSED) {\n if (cb)\n this.once(\"close\", () => {\n cb(new Error(\"The server is not running\"));\n });\n process.nextTick((server) => {\n server._state = CLOSED, server.emit(\"close\");\n }, this);\n return;\n }\n if (cb)\n this.once(\"close\", cb);\n if (this._state === CLOSING)\n return;\n if (this._state = CLOSING, this.options.noServer || this.options.server) {\n if (this._server)\n this._removeListeners(), this._removeListeners = this._server = null;\n if (this.clients)\n if (!this.clients.size)\n process.nextTick((server) => {\n server._state = CLOSED, server.emit(\"close\");\n }, this);\n else\n this._shouldEmitClose = !0;\n else\n process.nextTick((server) => {\n server._state = CLOSED, server.emit(\"close\");\n }, this);\n } else {\n const server = this._server;\n this._removeListeners(), this._removeListeners = this._server = null, server.close(() => {\n this._state = CLOSED, this.emit(\"close\");\n });\n }\n }\n shouldHandle(req) {\n if (this.options.path) {\n const index = req.url.indexOf(\"\?\");\n if ((index !== -1 \? req.url.slice(0, index) : req.url) !== this.options.path)\n return !1;\n }\n return !0;\n }\n completeUpgrade(extensions, key, protocols, request, socket, head, cb) {\n const [server, response, req] = socket[kBunInternals];\n if (this._state > RUNNING)\n return abortHandshake(response, 503);\n let protocol = \"\";\n if (protocols.size)\n protocol = this.options.handleProtocols \? this.options.handleProtocols(protocols, request) : protocols.values().next().value;\n const ws = new BunWebSocketMocked(request.url, protocol, extensions, \"nodebuffer\"), headers = [\"HTTP/1.1 101 Switching Protocols\", \"Upgrade: websocket\", \"Connection: Upgrade\"];\n if (this.emit(\"headers\", headers, request), server.upgrade(req, {\n data: ws[kBunInternals]\n })) {\n if (response._reply(@undefined), this.clients)\n this.clients.add(ws), ws.on(\"close\", () => {\n if (this.clients.delete(ws), this._shouldEmitClose && !this.clients.size)\n process.nextTick(wsEmitClose, this);\n });\n cb(ws, request);\n } else\n abortHandshake(response, 500);\n }\n handleUpgrade(req, socket, head, cb) {\n const [_, response] = socket[kBunInternals], key = req.headers[\"sec-websocket-key\"], version = +req.headers[\"sec-websocket-version\"];\n if (req.method !== \"GET\") {\n abortHandshakeOrEmitwsClientError(this, req, response, socket, 405, \"Invalid HTTP method\");\n return;\n }\n if (req.headers.upgrade.toLowerCase() !== \"websocket\") {\n abortHandshakeOrEmitwsClientError(this, req, response, socket, 400, \"Invalid Upgrade header\");\n return;\n }\n if (!key || !wsKeyRegex.test(key)) {\n abortHandshakeOrEmitwsClientError(this, req, response, socket, 400, \"Missing or invalid Sec-WebSocket-Key header\");\n return;\n }\n if (version !== 8 && version !== 13) {\n abortHandshakeOrEmitwsClientError(this, req, response, socket, 400, \"Missing or invalid Sec-WebSocket-Version header\");\n return;\n }\n if (!this.shouldHandle(req)) {\n abortHandshake(response, 400);\n return;\n }\n const secWebSocketProtocol = req.headers[\"sec-websocket-protocol\"];\n let protocols = new Set;\n if (secWebSocketProtocol !== @undefined)\n try {\n protocols = subprotocolParse(secWebSocketProtocol);\n } catch (err) {\n abortHandshakeOrEmitwsClientError(this, req, response, socket, 400, \"Invalid Sec-WebSocket-Protocol header\");\n return;\n }\n const extensions = {};\n if (this.options.verifyClient) {\n const info = {\n origin: req.headers[`${version === 8 \? \"sec-websocket-origin\" : \"origin\"}`],\n secure: !!(req.socket.authorized || req.socket.encrypted),\n req\n };\n if (this.options.verifyClient.length === 2) {\n this.options.verifyClient(info, (verified, code, message, headers) => {\n if (!verified)\n return abortHandshake(response, code || 401, message, headers);\n this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);\n });\n return;\n }\n if (!this.options.verifyClient(info))\n return abortHandshake(response, 401);\n }\n this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);\n }\n}\nObject.defineProperty(BunWebSocket, \"CONNECTING\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CONNECTING\")\n});\nObject.defineProperty(BunWebSocket.prototype, \"CONNECTING\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CONNECTING\")\n});\nObject.defineProperty(BunWebSocket, \"OPEN\", {\n enumerable: !0,\n value: readyStates.indexOf(\"OPEN\")\n});\nObject.defineProperty(BunWebSocket.prototype, \"OPEN\", {\n enumerable: !0,\n value: readyStates.indexOf(\"OPEN\")\n});\nObject.defineProperty(BunWebSocket, \"CLOSING\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CLOSING\")\n});\nObject.defineProperty(BunWebSocket.prototype, \"CLOSING\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CLOSING\")\n});\nObject.defineProperty(BunWebSocket, \"CLOSED\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CLOSED\")\n});\nObject.defineProperty(BunWebSocket.prototype, \"CLOSED\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CLOSED\")\n});\n\nclass Sender {\n constructor() {\n throw new Error(\"Not supported yet in Bun\");\n }\n}\n\nclass Receiver {\n constructor() {\n throw new Error(\"Not supported yet in Bun\");\n }\n}\nvar createWebSocketStream = (ws) => {\n throw new Error(\"Not supported yet in Bun\");\n};\n$ = Object.assign(BunWebSocket, {\n createWebSocketStream,\n Receiver,\n Sender,\n WebSocket: BunWebSocket,\n Server: WebSocketServer,\n WebSocketServer\n});\nreturn $})\n"_s;
+static constexpr ASCIILiteral ThirdpartyWSCode = "(function (){\"use strict\";// src/js/out/tmp/thirdparty/ws.ts\nvar emitWarning = function(type, message) {\n if (emittedWarnings.has(type))\n return;\n emittedWarnings.add(type), console.warn(\"[bun] Warning:\", message);\n}, subprotocolParse = function(header) {\n const protocols = new Set;\n let start = -1, end = -1, i = 0;\n for (i;i < header.length; i++) {\n const code = header.charCodeAt(i);\n if (end === -1 && wsTokenChars[code] === 1) {\n if (start === -1)\n start = i;\n } else if (i !== 0 && (code === 32 || code === 9)) {\n if (end === -1 && start !== -1)\n end = i;\n } else if (code === 44) {\n if (start === -1)\n throw new SyntaxError(`Unexpected character at index ${i}`);\n if (end === -1)\n end = i;\n const protocol2 = header.slice(start, end);\n if (protocols.has(protocol2))\n throw new SyntaxError(`The \"${protocol2}\" subprotocol is duplicated`);\n protocols.add(protocol2), start = end = -1;\n } else\n throw new SyntaxError(`Unexpected character at index ${i}`);\n }\n if (start === -1 || end !== -1)\n throw new SyntaxError(\"Unexpected end of input\");\n const protocol = header.slice(start, i);\n if (protocols.has(protocol))\n throw new SyntaxError(`The \"${protocol}\" subprotocol is duplicated`);\n return protocols.add(protocol), protocols;\n}, wsEmitClose = function(server) {\n server._state = CLOSED, server.emit(\"close\");\n}, abortHandshake = function(response, code, message, headers) {\n message = message || http.STATUS_CODES[code], headers = {\n Connection: \"close\",\n \"Content-Type\": \"text/html\",\n \"Content-Length\": @Buffer.byteLength(message),\n ...headers\n }, response.writeHead(code, headers), response.write(message), response.end();\n}, abortHandshakeOrEmitwsClientError = function(server, req, response, socket, code, message) {\n if (server.listenerCount(\"wsClientError\")) {\n const err = new Error(message);\n Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError), server.emit(\"wsClientError\", err, socket, req);\n } else\n abortHandshake(response, code, message);\n}, $, EventEmitter = @getInternalField(@internalModuleRegistry, 18) || @createInternalModuleById(18), http = @getInternalField(@internalModuleRegistry, 21) || @createInternalModuleById(21), kBunInternals = Symbol.for(\"::bunternal::\"), readyStates = [\"CONNECTING\", \"OPEN\", \"CLOSING\", \"CLOSED\"], encoder = new TextEncoder, eventIds = {\n open: 1,\n close: 2,\n message: 3,\n error: 4,\n ping: 5,\n pong: 6\n}, emittedWarnings = new Set;\n\nclass BunWebSocket extends EventEmitter {\n static CONNECTING = 0;\n static OPEN = 1;\n static CLOSING = 2;\n static CLOSED = 3;\n #ws;\n #paused = !1;\n #fragments = !1;\n #binaryType = \"nodebuffer\";\n #eventId = 0;\n constructor(url, protocols, options) {\n super();\n let ws = this.#ws = new WebSocket(url, protocols);\n ws.binaryType = \"nodebuffer\";\n }\n on(event, listener) {\n if (event === \"unexpected-response\" || event === \"upgrade\" || event === \"redirect\")\n emitWarning(event, \"ws.WebSocket '\" + event + \"' event is not implemented in bun\");\n const mask = 1 << eventIds[event];\n if (mask && (this.#eventId & mask) !== mask) {\n if (this.#eventId |= mask, event === \"open\")\n this.#ws.addEventListener(\"open\", () => {\n this.emit(\"open\");\n });\n else if (event === \"close\")\n this.#ws.addEventListener(\"close\", ({ code, reason, wasClean }) => {\n this.emit(\"close\", code, reason, wasClean);\n });\n else if (event === \"message\")\n this.#ws.addEventListener(\"message\", ({ data }) => {\n const isBinary = typeof data !== \"string\";\n if (isBinary)\n this.emit(\"message\", this.#fragments \? [data] : data, isBinary);\n else {\n let encoded = encoder.encode(data);\n if (this.#binaryType !== \"arraybuffer\")\n encoded = @Buffer.from(encoded.buffer, encoded.byteOffset, encoded.byteLength);\n this.emit(\"message\", this.#fragments \? [encoded] : encoded, isBinary);\n }\n });\n else if (event === \"error\")\n this.#ws.addEventListener(\"error\", (err) => {\n this.emit(\"error\", err);\n });\n else if (event === \"ping\")\n this.#ws.addEventListener(\"ping\", ({ data }) => {\n this.emit(\"ping\", data);\n });\n else if (event === \"pong\")\n this.#ws.addEventListener(\"pong\", ({ data }) => {\n this.emit(\"pong\", data);\n });\n }\n return super.on(event, listener);\n }\n send(data, opts, cb) {\n try {\n this.#ws.send(data, opts\?.compress);\n } catch (error) {\n typeof cb === \"function\" && cb(error);\n return;\n }\n typeof cb === \"function\" && cb();\n }\n close(code, reason) {\n this.#ws.close(code, reason);\n }\n terminate() {\n this.#ws.terminate();\n }\n get url() {\n return this.#ws.url;\n }\n get readyState() {\n return this.#ws.readyState;\n }\n get binaryType() {\n return this.#binaryType;\n }\n set binaryType(value) {\n if (value === \"nodebuffer\" || value === \"arraybuffer\")\n this.#ws.binaryType = this.#binaryType = value, this.#fragments = !1;\n else if (value === \"fragments\")\n this.#ws.binaryType = \"nodebuffer\", this.#binaryType = \"fragments\", this.#fragments = !0;\n else\n throw new Error(`Invalid binaryType: ${value}`);\n }\n get protocol() {\n return this.#ws.protocol;\n }\n get extensions() {\n return this.#ws.extensions;\n }\n addEventListener(type, listener, options) {\n this.#ws.addEventListener(type, listener, options);\n }\n removeEventListener(type, listener) {\n this.#ws.removeEventListener(type, listener);\n }\n get onopen() {\n return this.#ws.onopen;\n }\n set onopen(value) {\n this.#ws.onopen = value;\n }\n get onerror() {\n return this.#ws.onerror;\n }\n set onerror(value) {\n this.#ws.onerror = value;\n }\n get onclose() {\n return this.#ws.onclose;\n }\n set onclose(value) {\n this.#ws.onclose = value;\n }\n get onmessage() {\n return this.#ws.onmessage;\n }\n set onmessage(value) {\n this.#ws.onmessage = value;\n }\n get bufferedAmount() {\n return this.#ws.bufferedAmount;\n }\n get isPaused() {\n return this.#paused;\n }\n ping(data, mask, cb) {\n if (typeof data === \"function\")\n cb = data, data = mask = @undefined;\n else if (typeof mask === \"function\")\n cb = mask, mask = @undefined;\n if (typeof data === \"number\")\n data = data.toString();\n try {\n this.#ws.ping(data);\n } catch (error) {\n typeof cb === \"function\" && cb(error);\n return;\n }\n typeof cb === \"function\" && cb();\n }\n pong(data, mask, cb) {\n if (typeof data === \"function\")\n cb = data, data = mask = @undefined;\n else if (typeof mask === \"function\")\n cb = mask, mask = @undefined;\n if (typeof data === \"number\")\n data = data.toString();\n try {\n this.#ws.pong(data);\n } catch (error) {\n typeof cb === \"function\" && cb(error);\n return;\n }\n typeof cb === \"function\" && cb();\n }\n pause() {\n switch (this.readyState) {\n case WebSocket.CONNECTING:\n case WebSocket.CLOSED:\n return;\n }\n this.#paused = !0, emitWarning(\"pause()\", \"ws.WebSocket.pause() is not implemented in bun\");\n }\n resume() {\n switch (this.readyState) {\n case WebSocket.CONNECTING:\n case WebSocket.CLOSED:\n return;\n }\n this.#paused = !1, emitWarning(\"resume()\", \"ws.WebSocket.resume() is not implemented in bun\");\n }\n}\nObject.defineProperty(BunWebSocket, \"name\", { value: \"WebSocket\" });\nvar wsKeyRegex = /^[+/0-9A-Za-z]{22}==$/, wsTokenChars = [\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 1,\n 0,\n 1,\n 1,\n 1,\n 1,\n 1,\n 0,\n 0,\n 1,\n 1,\n 0,\n 1,\n 1,\n 0,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 0,\n 0,\n 0,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 0,\n 1,\n 0,\n 1,\n 0\n], RUNNING = 0, CLOSING = 1, CLOSED = 2;\n\nclass BunWebSocketMocked extends EventEmitter {\n #ws;\n #state;\n #enquedMessages = [];\n #url;\n #protocol;\n #extensions;\n #bufferedAmount = 0;\n #binaryType = \"arraybuffer\";\n #onclose;\n #onerror;\n #onmessage;\n #onopen;\n constructor(url, protocol, extensions, binaryType) {\n super();\n if (this.#ws = null, this.#state = 0, this.#url = url, this.#bufferedAmount = 0, binaryType = binaryType || \"arraybuffer\", binaryType !== \"nodebuffer\" && binaryType !== \"blob\" && binaryType !== \"arraybuffer\")\n @throwTypeError(\"binaryType must be either 'blob', 'arraybuffer' or 'nodebuffer'\");\n this.#binaryType = binaryType, this.#protocol = protocol, this.#extensions = extensions;\n const message = this.#message.bind(this), open = this.#open.bind(this), close = this.#close.bind(this), drain = this.#drain.bind(this);\n this[kBunInternals] = {\n message,\n open,\n close,\n drain\n };\n }\n #message(ws, message) {\n this.#ws = ws;\n let isBinary = !1;\n if (typeof message === \"string\")\n if (this.#binaryType === \"arraybuffer\")\n message = encoder.encode(message).buffer;\n else if (this.#binaryType === \"blob\")\n message = new Blob([message], { type: \"text/plain\" });\n else\n message = @Buffer.from(message);\n else if (isBinary = !0, this.#binaryType !== \"nodebuffer\") {\n if (this.#binaryType === \"arraybuffer\")\n message = new @Uint8Array(message);\n else if (this.#binaryType === \"blob\")\n message = new Blob([message]);\n }\n this.emit(\"message\", message, isBinary);\n }\n #open(ws) {\n this.#ws = ws, this.#state = 1, this.emit(\"open\", this), this.#drain(ws);\n }\n #close(ws, code, reason) {\n this.#state = 3, this.#ws = null, this.emit(\"close\", code, reason);\n }\n #drain(ws) {\n const chunk = this.#enquedMessages[0];\n if (chunk) {\n const [data, compress, cb] = chunk;\n if (ws.send(data, compress) == -1)\n return;\n typeof cb === \"function\" && cb(), this.#bufferedAmount -= chunk.length, this.#enquedMessages.shift();\n }\n }\n send(data, opts, cb) {\n if (this.#state === 1) {\n const compress = opts\?.compress;\n if (this.#ws.send(data, compress) == -1) {\n this.#enquedMessages.push([data, compress, cb]), this.#bufferedAmount += data.length;\n return;\n }\n typeof cb === \"function\" && cb();\n } else if (this.#state === 0)\n this.#enquedMessages.push([data, opts\?.compress, cb]), this.#bufferedAmount += data.length;\n }\n close(code, reason) {\n if (this.#state === 1)\n this.#state = 2, this.#ws.close(code, reason);\n }\n get binaryType() {\n return this.#binaryType;\n }\n set binaryType(type) {\n if (type !== \"nodebuffer\" && type !== \"blob\" && type !== \"arraybuffer\")\n @throwTypeError(\"binaryType must be either 'blob', 'arraybuffer' or 'nodebuffer'\");\n this.#binaryType = type;\n }\n get readyState() {\n return this.#state;\n }\n get url() {\n return this.#url;\n }\n get protocol() {\n return this.#protocol;\n }\n get extensions() {\n return this.#extensions;\n }\n get bufferedAmount() {\n return this.#bufferedAmount \?\? 0;\n }\n setSocket(socket, head, options) {\n throw new Error(\"Not implemented\");\n }\n set onclose(cb) {\n if (this.#onclose)\n this.removeListener(\"close\", this.#onclose);\n this.on(\"close\", cb), this.#onclose = cb;\n }\n set onerror(cb) {\n if (this.#onerror)\n this.removeListener(\"error\", this.#onerror);\n this.on(\"error\", cb), this.#onerror = cb;\n }\n set onmessage(cb) {\n if (this.#onmessage)\n this.removeListener(\"message\", this.#onmessage);\n this.on(\"message\", cb), this.#onmessage = cb;\n }\n set onopen(cb) {\n if (this.#onopen)\n this.removeListener(\"open\", this.#onopen);\n this.on(\"open\", cb), this.#onopen = cb;\n }\n get onclose() {\n return this.#onclose;\n }\n get onerror() {\n return this.#onerror;\n }\n get onmessage() {\n return this.#onmessage;\n }\n get onopen() {\n return this.#onopen;\n }\n addEventListener(type, listener, options) {\n if (type === \"message\") {\n const l = (data) => listener({ data });\n l.listener = listener, this.on(type, l);\n return;\n }\n this.on(type, listener);\n }\n removeEventListener(type, listener) {\n this.off(type, listener);\n }\n}\n\nclass WebSocketServer extends EventEmitter {\n _server;\n options;\n clients;\n _shouldEmitClose;\n _state;\n _removeListeners;\n constructor(options, callback) {\n super();\n if (options = {\n maxPayload: 104857600,\n skipUTF8Validation: !1,\n perMessageDeflate: !1,\n handleProtocols: null,\n clientTracking: !0,\n verifyClient: null,\n noServer: !1,\n backlog: null,\n server: null,\n host: null,\n path: null,\n port: null,\n ...options\n }, options.port == null && !options.server && !options.noServer || options.port != null && (options.server || options.noServer) || options.server && options.noServer)\n @throwTypeError('One and only one of the \"port\", \"server\", or \"noServer\" options must be specified');\n if (options.port != null)\n this._server = http.createServer((req, res) => {\n const body = http.STATUS_CODES[426];\n res.writeHead(426, {\n \"Content-Length\": body.length,\n \"Content-Type\": \"text/plain\"\n }), res.end(body);\n }), this._server.listen(options.port, options.host, options.backlog, callback);\n else if (options.server)\n this._server = options.server;\n if (this._server) {\n const emitConnection = this.emit.bind(this, \"connection\"), emitListening = this.emit.bind(this, \"listening\"), emitError = this.emit.bind(this, \"error\"), doUpgrade = (req, socket, head) => {\n this.handleUpgrade(req, socket, head, emitConnection);\n };\n this._server.on(\"listening\", emitListening), this._server.on(\"error\", emitError), this._server.on(\"upgrade\", doUpgrade), this._removeListeners = () => {\n this._server.removeListener(\"upgrade\", doUpgrade), this._server.removeListener(\"listening\", emitListening), this._server.removeListener(\"error\", emitError);\n };\n }\n if (options.perMessageDeflate === !0)\n options.perMessageDeflate = {};\n if (options.clientTracking)\n this.clients = new Set, this._shouldEmitClose = !1;\n this.options = options, this._state = RUNNING;\n }\n address() {\n if (this.options.noServer)\n throw new Error('The server is operating in \"noServer\" mode');\n if (!this._server)\n return null;\n return this._server.address();\n }\n close(cb) {\n if (this._state === CLOSED) {\n if (cb)\n this.once(\"close\", () => {\n cb(new Error(\"The server is not running\"));\n });\n process.nextTick((server) => {\n server._state = CLOSED, server.emit(\"close\");\n }, this);\n return;\n }\n if (cb)\n this.once(\"close\", cb);\n if (this._state === CLOSING)\n return;\n if (this._state = CLOSING, this.options.noServer || this.options.server) {\n if (this._server)\n this._removeListeners(), this._removeListeners = this._server = null;\n if (this.clients)\n if (!this.clients.size)\n process.nextTick((server) => {\n server._state = CLOSED, server.emit(\"close\");\n }, this);\n else\n this._shouldEmitClose = !0;\n else\n process.nextTick((server) => {\n server._state = CLOSED, server.emit(\"close\");\n }, this);\n } else {\n const server = this._server;\n this._removeListeners(), this._removeListeners = this._server = null, server.close(() => {\n this._state = CLOSED, this.emit(\"close\");\n });\n }\n }\n shouldHandle(req) {\n if (this.options.path) {\n const index = req.url.indexOf(\"\?\");\n if ((index !== -1 \? req.url.slice(0, index) : req.url) !== this.options.path)\n return !1;\n }\n return !0;\n }\n completeUpgrade(extensions, key, protocols, request, socket, head, cb) {\n const [server, response, req] = socket[kBunInternals];\n if (this._state > RUNNING)\n return abortHandshake(response, 503);\n let protocol = \"\";\n if (protocols.size)\n protocol = this.options.handleProtocols \? this.options.handleProtocols(protocols, request) : protocols.values().next().value;\n const ws = new BunWebSocketMocked(request.url, protocol, extensions, \"nodebuffer\"), headers = [\"HTTP/1.1 101 Switching Protocols\", \"Upgrade: websocket\", \"Connection: Upgrade\"];\n if (this.emit(\"headers\", headers, request), server.upgrade(req, {\n data: ws[kBunInternals]\n })) {\n if (response._reply(@undefined), this.clients)\n this.clients.add(ws), ws.on(\"close\", () => {\n if (this.clients.delete(ws), this._shouldEmitClose && !this.clients.size)\n process.nextTick(wsEmitClose, this);\n });\n cb(ws, request);\n } else\n abortHandshake(response, 500);\n }\n handleUpgrade(req, socket, head, cb) {\n const [_, response] = socket[kBunInternals], key = req.headers[\"sec-websocket-key\"], version = +req.headers[\"sec-websocket-version\"];\n if (req.method !== \"GET\") {\n abortHandshakeOrEmitwsClientError(this, req, response, socket, 405, \"Invalid HTTP method\");\n return;\n }\n if (req.headers.upgrade.toLowerCase() !== \"websocket\") {\n abortHandshakeOrEmitwsClientError(this, req, response, socket, 400, \"Invalid Upgrade header\");\n return;\n }\n if (!key || !wsKeyRegex.test(key)) {\n abortHandshakeOrEmitwsClientError(this, req, response, socket, 400, \"Missing or invalid Sec-WebSocket-Key header\");\n return;\n }\n if (version !== 8 && version !== 13) {\n abortHandshakeOrEmitwsClientError(this, req, response, socket, 400, \"Missing or invalid Sec-WebSocket-Version header\");\n return;\n }\n if (!this.shouldHandle(req)) {\n abortHandshake(response, 400);\n return;\n }\n const secWebSocketProtocol = req.headers[\"sec-websocket-protocol\"];\n let protocols = new Set;\n if (secWebSocketProtocol !== @undefined)\n try {\n protocols = subprotocolParse(secWebSocketProtocol);\n } catch (err) {\n abortHandshakeOrEmitwsClientError(this, req, response, socket, 400, \"Invalid Sec-WebSocket-Protocol header\");\n return;\n }\n const extensions = {};\n if (this.options.verifyClient) {\n const info = {\n origin: req.headers[`${version === 8 \? \"sec-websocket-origin\" : \"origin\"}`],\n secure: !!(req.socket.authorized || req.socket.encrypted),\n req\n };\n if (this.options.verifyClient.length === 2) {\n this.options.verifyClient(info, (verified, code, message, headers) => {\n if (!verified)\n return abortHandshake(response, code || 401, message, headers);\n this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);\n });\n return;\n }\n if (!this.options.verifyClient(info))\n return abortHandshake(response, 401);\n }\n this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);\n }\n}\nObject.defineProperty(BunWebSocket, \"CONNECTING\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CONNECTING\")\n});\nObject.defineProperty(BunWebSocket.prototype, \"CONNECTING\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CONNECTING\")\n});\nObject.defineProperty(BunWebSocket, \"OPEN\", {\n enumerable: !0,\n value: readyStates.indexOf(\"OPEN\")\n});\nObject.defineProperty(BunWebSocket.prototype, \"OPEN\", {\n enumerable: !0,\n value: readyStates.indexOf(\"OPEN\")\n});\nObject.defineProperty(BunWebSocket, \"CLOSING\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CLOSING\")\n});\nObject.defineProperty(BunWebSocket.prototype, \"CLOSING\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CLOSING\")\n});\nObject.defineProperty(BunWebSocket, \"CLOSED\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CLOSED\")\n});\nObject.defineProperty(BunWebSocket.prototype, \"CLOSED\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CLOSED\")\n});\n\nclass Sender {\n constructor() {\n throw new Error(\"Not supported yet in Bun\");\n }\n}\n\nclass Receiver {\n constructor() {\n throw new Error(\"Not supported yet in Bun\");\n }\n}\nvar createWebSocketStream = (ws) => {\n throw new Error(\"Not supported yet in Bun\");\n};\n$ = Object.assign(BunWebSocket, {\n createWebSocketStream,\n Receiver,\n Sender,\n WebSocket: BunWebSocket,\n Server: WebSocketServer,\n WebSocketServer\n});\nreturn $})\n"_s;
//
#else
@@ -725,7 +725,7 @@ static constexpr ASCIILiteral ThirdpartyVercelFetchCode = "(function (){\"use st
//
//
-static constexpr ASCIILiteral ThirdpartyWSCode = "(function (){\"use strict\";// src/js/out/tmp/thirdparty/ws.ts\nvar emitWarning = function(type, message) {\n if (emittedWarnings.has(type))\n return;\n emittedWarnings.add(type), console.warn(\"[bun] Warning:\", message);\n}, subprotocolParse = function(header) {\n const protocols = new Set;\n let start = -1, end = -1, i = 0;\n for (i;i < header.length; i++) {\n const code = header.charCodeAt(i);\n if (end === -1 && wsTokenChars[code] === 1) {\n if (start === -1)\n start = i;\n } else if (i !== 0 && (code === 32 || code === 9)) {\n if (end === -1 && start !== -1)\n end = i;\n } else if (code === 44) {\n if (start === -1)\n throw new SyntaxError(`Unexpected character at index ${i}`);\n if (end === -1)\n end = i;\n const protocol2 = header.slice(start, end);\n if (protocols.has(protocol2))\n throw new SyntaxError(`The \"${protocol2}\" subprotocol is duplicated`);\n protocols.add(protocol2), start = end = -1;\n } else\n throw new SyntaxError(`Unexpected character at index ${i}`);\n }\n if (start === -1 || end !== -1)\n throw new SyntaxError(\"Unexpected end of input\");\n const protocol = header.slice(start, i);\n if (protocols.has(protocol))\n throw new SyntaxError(`The \"${protocol}\" subprotocol is duplicated`);\n return protocols.add(protocol), protocols;\n}, wsEmitClose = function(server) {\n server._state = CLOSED, server.emit(\"close\");\n}, abortHandshake = function(response, code, message, headers) {\n message = message || http.STATUS_CODES[code], headers = {\n Connection: \"close\",\n \"Content-Type\": \"text/html\",\n \"Content-Length\": @Buffer.byteLength(message),\n ...headers\n }, response.writeHead(code, headers), response.write(message), response.end();\n}, abortHandshakeOrEmitwsClientError = function(server, req, response, socket, code, message) {\n if (server.listenerCount(\"wsClientError\")) {\n const err = new Error(message);\n Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError), server.emit(\"wsClientError\", err, socket, req);\n } else\n abortHandshake(response, code, message);\n}, $, EventEmitter = @getInternalField(@internalModuleRegistry, 18) || @createInternalModuleById(18), http = @getInternalField(@internalModuleRegistry, 21) || @createInternalModuleById(21), kBunInternals = Symbol.for(\"::bunternal::\"), readyStates = [\"CONNECTING\", \"OPEN\", \"CLOSING\", \"CLOSED\"], encoder = new TextEncoder, eventIds = {\n open: 1,\n close: 2,\n message: 3,\n error: 4,\n ping: 5,\n pong: 6\n}, emittedWarnings = new Set;\n\nclass BunWebSocket extends EventEmitter {\n static CONNECTING = 0;\n static OPEN = 1;\n static CLOSING = 2;\n static CLOSED = 3;\n #ws;\n #paused = !1;\n #fragments = !1;\n #binaryType = \"nodebuffer\";\n #eventId = 0;\n constructor(url, protocols, options) {\n super();\n let ws = this.#ws = new WebSocket(url, protocols);\n ws.binaryType = \"nodebuffer\";\n }\n on(event, listener) {\n if (event === \"unexpected-response\" || event === \"upgrade\" || event === \"redirect\")\n emitWarning(event, \"ws.WebSocket '\" + event + \"' event is not implemented in bun\");\n const mask = 1 << eventIds[event];\n if (mask && (this.#eventId & mask) !== mask) {\n if (this.#eventId |= mask, event === \"open\")\n this.#ws.addEventListener(\"open\", () => {\n this.emit(\"open\");\n });\n else if (event === \"close\")\n this.#ws.addEventListener(\"close\", ({ code, reason, wasClean }) => {\n this.emit(\"close\", code, reason, wasClean);\n });\n else if (event === \"message\")\n this.#ws.addEventListener(\"message\", ({ data }) => {\n const isBinary = typeof data !== \"string\";\n if (isBinary)\n this.emit(\"message\", this.#fragments \? [data] : data, isBinary);\n else {\n let encoded = encoder.encode(data);\n if (this.#binaryType !== \"arraybuffer\")\n encoded = @Buffer.from(encoded.buffer, encoded.byteOffset, encoded.byteLength);\n this.emit(\"message\", this.#fragments \? [encoded] : encoded, isBinary);\n }\n });\n else if (event === \"error\")\n this.#ws.addEventListener(\"error\", (err) => {\n this.emit(\"error\", err);\n });\n else if (event === \"ping\")\n this.#ws.addEventListener(\"ping\", ({ data }) => {\n this.emit(\"ping\", data);\n });\n else if (event === \"pong\")\n this.#ws.addEventListener(\"pong\", ({ data }) => {\n this.emit(\"pong\", data);\n });\n }\n return super.on(event, listener);\n }\n send(data, opts, cb) {\n try {\n this.#ws.send(data, opts\?.compress);\n } catch (error) {\n typeof cb === \"function\" && cb(error);\n return;\n }\n typeof cb === \"function\" && cb();\n }\n close(code, reason) {\n this.#ws.close(code, reason);\n }\n terminate() {\n this.#ws.terminate();\n }\n get url() {\n return this.#ws.url;\n }\n get readyState() {\n return this.#ws.readyState;\n }\n get binaryType() {\n return this.#binaryType;\n }\n set binaryType(value) {\n if (value === \"nodebuffer\" || value === \"arraybuffer\")\n this.#ws.binaryType = this.#binaryType = value, this.#fragments = !1;\n else if (value === \"fragments\")\n this.#ws.binaryType = \"nodebuffer\", this.#binaryType = \"fragments\", this.#fragments = !0;\n else\n throw new Error(`Invalid binaryType: ${value}`);\n }\n get protocol() {\n return this.#ws.protocol;\n }\n get extensions() {\n return this.#ws.extensions;\n }\n addEventListener(type, listener, options) {\n this.#ws.addEventListener(type, listener, options);\n }\n removeEventListener(type, listener) {\n this.#ws.removeEventListener(type, listener);\n }\n get onopen() {\n return this.#ws.onopen;\n }\n set onopen(value) {\n this.#ws.onopen = value;\n }\n get onerror() {\n return this.#ws.onerror;\n }\n set onerror(value) {\n this.#ws.onerror = value;\n }\n get onclose() {\n return this.#ws.onclose;\n }\n set onclose(value) {\n this.#ws.onclose = value;\n }\n get onmessage() {\n return this.#ws.onmessage;\n }\n set onmessage(value) {\n this.#ws.onmessage = value;\n }\n get bufferedAmount() {\n return this.#ws.bufferedAmount;\n }\n get isPaused() {\n return this.#paused;\n }\n ping(data, mask, cb) {\n if (typeof data === \"function\")\n cb = data, data = mask = @undefined;\n else if (typeof mask === \"function\")\n cb = mask, mask = @undefined;\n if (typeof data === \"number\")\n data = data.toString();\n try {\n this.#ws.ping(data);\n } catch (error) {\n typeof cb === \"function\" && cb(error);\n return;\n }\n typeof cb === \"function\" && cb();\n }\n pong(data, mask, cb) {\n if (typeof data === \"function\")\n cb = data, data = mask = @undefined;\n else if (typeof mask === \"function\")\n cb = mask, mask = @undefined;\n if (typeof data === \"number\")\n data = data.toString();\n try {\n this.#ws.pong(data);\n } catch (error) {\n typeof cb === \"function\" && cb(error);\n return;\n }\n typeof cb === \"function\" && cb();\n }\n pause() {\n switch (this.readyState) {\n case WebSocket.CONNECTING:\n case WebSocket.CLOSED:\n return;\n }\n this.#paused = !0, emitWarning(\"pause()\", \"ws.WebSocket.pause() is not implemented in bun\");\n }\n resume() {\n switch (this.readyState) {\n case WebSocket.CONNECTING:\n case WebSocket.CLOSED:\n return;\n }\n this.#paused = !1, emitWarning(\"resume()\", \"ws.WebSocket.resume() is not implemented in bun\");\n }\n}\nObject.defineProperty(BunWebSocket, \"name\", { value: \"WebSocket\" });\nvar wsKeyRegex = /^[+/0-9A-Za-z]{22}==$/, wsTokenChars = [\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 1,\n 0,\n 1,\n 1,\n 1,\n 1,\n 1,\n 0,\n 0,\n 1,\n 1,\n 0,\n 1,\n 1,\n 0,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 0,\n 0,\n 0,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 0,\n 1,\n 0,\n 1,\n 0\n], RUNNING = 0, CLOSING = 1, CLOSED = 2;\n\nclass BunWebSocketMocked extends EventEmitter {\n #ws;\n #state;\n #enquedMessages = [];\n #url;\n #protocol;\n #extensions;\n #bufferedAmount = 0;\n #binaryType = \"arraybuffer\";\n #onclose;\n #onerror;\n #onmessage;\n #onopen;\n constructor(url, protocol, extensions, binaryType) {\n super();\n if (this.#ws = null, this.#state = 0, this.#url = url, this.#bufferedAmount = 0, binaryType = binaryType || \"arraybuffer\", binaryType !== \"nodebuffer\" && binaryType !== \"blob\" && binaryType !== \"arraybuffer\")\n @throwTypeError(\"binaryType must be either 'blob', 'arraybuffer' or 'nodebuffer'\");\n this.#binaryType = binaryType, this.#protocol = protocol, this.#extensions = extensions;\n const message = this.#message.bind(this), open = this.#open.bind(this), close = this.#close.bind(this), drain = this.#drain.bind(this);\n this[kBunInternals] = {\n message,\n open,\n close,\n drain\n };\n }\n #message(ws, message) {\n if (this.#ws = ws, typeof message === \"string\")\n if (this.#binaryType === \"arraybuffer\")\n message = encoder.encode(message).buffer;\n else if (this.#binaryType === \"blob\")\n message = new Blob([message], { type: \"text/plain\" });\n else\n message = @Buffer.from(message);\n else if (this.#binaryType !== \"nodebuffer\") {\n if (this.#binaryType === \"arraybuffer\")\n message = new @Uint8Array(message);\n else if (this.#binaryType === \"blob\")\n message = new Blob([message]);\n }\n this.emit(\"message\", message);\n }\n #open(ws) {\n this.#ws = ws, this.#state = 1, this.emit(\"open\", this), this.#drain(ws);\n }\n #close(ws, code, reason) {\n this.#state = 3, this.#ws = null, this.emit(\"close\", code, reason);\n }\n #drain(ws) {\n const chunk = this.#enquedMessages[0];\n if (chunk) {\n const [data, compress, cb] = chunk;\n if (ws.send(data, compress) == -1)\n return;\n typeof cb === \"function\" && cb(), this.#bufferedAmount -= chunk.length, this.#enquedMessages.shift();\n }\n }\n send(data, opts, cb) {\n if (this.#state === 1) {\n const compress = opts\?.compress;\n if (this.#ws.send(data, compress) == -1) {\n this.#enquedMessages.push([data, compress, cb]), this.#bufferedAmount += data.length;\n return;\n }\n typeof cb === \"function\" && cb();\n } else if (this.#state === 0)\n this.#enquedMessages.push([data, opts\?.compress, cb]), this.#bufferedAmount += data.length;\n }\n close(code, reason) {\n if (this.#state === 1)\n this.#state = 2, this.#ws.close(code, reason);\n }\n get binaryType() {\n return this.#binaryType;\n }\n set binaryType(type) {\n if (type !== \"nodebuffer\" && type !== \"blob\" && type !== \"arraybuffer\")\n @throwTypeError(\"binaryType must be either 'blob', 'arraybuffer' or 'nodebuffer'\");\n this.#binaryType = type;\n }\n get readyState() {\n return this.#state;\n }\n get url() {\n return this.#url;\n }\n get protocol() {\n return this.#protocol;\n }\n get extensions() {\n return this.#extensions;\n }\n get bufferedAmount() {\n return this.#bufferedAmount \?\? 0;\n }\n setSocket(socket, head, options) {\n throw new Error(\"Not implemented\");\n }\n set onclose(cb) {\n if (this.#onclose)\n this.removeListener(\"close\", this.#onclose);\n this.on(\"close\", cb), this.#onclose = cb;\n }\n set onerror(cb) {\n if (this.#onerror)\n this.removeListener(\"error\", this.#onerror);\n this.on(\"error\", cb), this.#onerror = cb;\n }\n set onmessage(cb) {\n if (this.#onmessage)\n this.removeListener(\"message\", this.#onmessage);\n this.on(\"message\", cb), this.#onmessage = cb;\n }\n set onopen(cb) {\n if (this.#onopen)\n this.removeListener(\"open\", this.#onopen);\n this.on(\"open\", cb), this.#onopen = cb;\n }\n get onclose() {\n return this.#onclose;\n }\n get onerror() {\n return this.#onerror;\n }\n get onmessage() {\n return this.#onmessage;\n }\n get onopen() {\n return this.#onopen;\n }\n addEventListener(type, listener, options) {\n if (type === \"message\") {\n const l = (data) => listener({ data });\n l.listener = listener, this.on(type, l);\n return;\n }\n this.on(type, listener);\n }\n removeEventListener(type, listener) {\n this.off(type, listener);\n }\n}\n\nclass WebSocketServer extends EventEmitter {\n _server;\n options;\n clients;\n _shouldEmitClose;\n _state;\n _removeListeners;\n constructor(options, callback) {\n super();\n if (options = {\n maxPayload: 104857600,\n skipUTF8Validation: !1,\n perMessageDeflate: !1,\n handleProtocols: null,\n clientTracking: !0,\n verifyClient: null,\n noServer: !1,\n backlog: null,\n server: null,\n host: null,\n path: null,\n port: null,\n ...options\n }, options.port == null && !options.server && !options.noServer || options.port != null && (options.server || options.noServer) || options.server && options.noServer)\n @throwTypeError('One and only one of the \"port\", \"server\", or \"noServer\" options must be specified');\n if (options.port != null)\n this._server = http.createServer((req, res) => {\n const body = http.STATUS_CODES[426];\n res.writeHead(426, {\n \"Content-Length\": body.length,\n \"Content-Type\": \"text/plain\"\n }), res.end(body);\n }), this._server.listen(options.port, options.host, options.backlog, callback);\n else if (options.server)\n this._server = options.server;\n if (this._server) {\n const emitConnection = this.emit.bind(this, \"connection\"), emitListening = this.emit.bind(this, \"listening\"), emitError = this.emit.bind(this, \"error\"), doUpgrade = (req, socket, head) => {\n this.handleUpgrade(req, socket, head, emitConnection);\n };\n this._server.on(\"listening\", emitListening), this._server.on(\"error\", emitError), this._server.on(\"upgrade\", doUpgrade), this._removeListeners = () => {\n this._server.removeListener(\"upgrade\", doUpgrade), this._server.removeListener(\"listening\", emitListening), this._server.removeListener(\"error\", emitError);\n };\n }\n if (options.perMessageDeflate === !0)\n options.perMessageDeflate = {};\n if (options.clientTracking)\n this.clients = new Set, this._shouldEmitClose = !1;\n this.options = options, this._state = RUNNING;\n }\n address() {\n if (this.options.noServer)\n throw new Error('The server is operating in \"noServer\" mode');\n if (!this._server)\n return null;\n return this._server.address();\n }\n close(cb) {\n if (this._state === CLOSED) {\n if (cb)\n this.once(\"close\", () => {\n cb(new Error(\"The server is not running\"));\n });\n process.nextTick((server) => {\n server._state = CLOSED, server.emit(\"close\");\n }, this);\n return;\n }\n if (cb)\n this.once(\"close\", cb);\n if (this._state === CLOSING)\n return;\n if (this._state = CLOSING, this.options.noServer || this.options.server) {\n if (this._server)\n this._removeListeners(), this._removeListeners = this._server = null;\n if (this.clients)\n if (!this.clients.size)\n process.nextTick((server) => {\n server._state = CLOSED, server.emit(\"close\");\n }, this);\n else\n this._shouldEmitClose = !0;\n else\n process.nextTick((server) => {\n server._state = CLOSED, server.emit(\"close\");\n }, this);\n } else {\n const server = this._server;\n this._removeListeners(), this._removeListeners = this._server = null, server.close(() => {\n this._state = CLOSED, this.emit(\"close\");\n });\n }\n }\n shouldHandle(req) {\n if (this.options.path) {\n const index = req.url.indexOf(\"\?\");\n if ((index !== -1 \? req.url.slice(0, index) : req.url) !== this.options.path)\n return !1;\n }\n return !0;\n }\n completeUpgrade(extensions, key, protocols, request, socket, head, cb) {\n const [server, response, req] = socket[kBunInternals];\n if (this._state > RUNNING)\n return abortHandshake(response, 503);\n let protocol = \"\";\n if (protocols.size)\n protocol = this.options.handleProtocols \? this.options.handleProtocols(protocols, request) : protocols.values().next().value;\n const ws = new BunWebSocketMocked(request.url, protocol, extensions, \"nodebuffer\"), headers = [\"HTTP/1.1 101 Switching Protocols\", \"Upgrade: websocket\", \"Connection: Upgrade\"];\n if (this.emit(\"headers\", headers, request), server.upgrade(req, {\n data: ws[kBunInternals]\n })) {\n if (response._reply(@undefined), this.clients)\n this.clients.add(ws), ws.on(\"close\", () => {\n if (this.clients.delete(ws), this._shouldEmitClose && !this.clients.size)\n process.nextTick(wsEmitClose, this);\n });\n cb(ws, request);\n } else\n abortHandshake(response, 500);\n }\n handleUpgrade(req, socket, head, cb) {\n const [_, response] = socket[kBunInternals], key = req.headers[\"sec-websocket-key\"], version = +req.headers[\"sec-websocket-version\"];\n if (req.method !== \"GET\") {\n abortHandshakeOrEmitwsClientError(this, req, response, socket, 405, \"Invalid HTTP method\");\n return;\n }\n if (req.headers.upgrade.toLowerCase() !== \"websocket\") {\n abortHandshakeOrEmitwsClientError(this, req, response, socket, 400, \"Invalid Upgrade header\");\n return;\n }\n if (!key || !wsKeyRegex.test(key)) {\n abortHandshakeOrEmitwsClientError(this, req, response, socket, 400, \"Missing or invalid Sec-WebSocket-Key header\");\n return;\n }\n if (version !== 8 && version !== 13) {\n abortHandshakeOrEmitwsClientError(this, req, response, socket, 400, \"Missing or invalid Sec-WebSocket-Version header\");\n return;\n }\n if (!this.shouldHandle(req)) {\n abortHandshake(response, 400);\n return;\n }\n const secWebSocketProtocol = req.headers[\"sec-websocket-protocol\"];\n let protocols = new Set;\n if (secWebSocketProtocol !== @undefined)\n try {\n protocols = subprotocolParse(secWebSocketProtocol);\n } catch (err) {\n abortHandshakeOrEmitwsClientError(this, req, response, socket, 400, \"Invalid Sec-WebSocket-Protocol header\");\n return;\n }\n const extensions = {};\n if (this.options.verifyClient) {\n const info = {\n origin: req.headers[`${version === 8 \? \"sec-websocket-origin\" : \"origin\"}`],\n secure: !!(req.socket.authorized || req.socket.encrypted),\n req\n };\n if (this.options.verifyClient.length === 2) {\n this.options.verifyClient(info, (verified, code, message, headers) => {\n if (!verified)\n return abortHandshake(response, code || 401, message, headers);\n this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);\n });\n return;\n }\n if (!this.options.verifyClient(info))\n return abortHandshake(response, 401);\n }\n this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);\n }\n}\nObject.defineProperty(BunWebSocket, \"CONNECTING\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CONNECTING\")\n});\nObject.defineProperty(BunWebSocket.prototype, \"CONNECTING\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CONNECTING\")\n});\nObject.defineProperty(BunWebSocket, \"OPEN\", {\n enumerable: !0,\n value: readyStates.indexOf(\"OPEN\")\n});\nObject.defineProperty(BunWebSocket.prototype, \"OPEN\", {\n enumerable: !0,\n value: readyStates.indexOf(\"OPEN\")\n});\nObject.defineProperty(BunWebSocket, \"CLOSING\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CLOSING\")\n});\nObject.defineProperty(BunWebSocket.prototype, \"CLOSING\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CLOSING\")\n});\nObject.defineProperty(BunWebSocket, \"CLOSED\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CLOSED\")\n});\nObject.defineProperty(BunWebSocket.prototype, \"CLOSED\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CLOSED\")\n});\n\nclass Sender {\n constructor() {\n throw new Error(\"Not supported yet in Bun\");\n }\n}\n\nclass Receiver {\n constructor() {\n throw new Error(\"Not supported yet in Bun\");\n }\n}\nvar createWebSocketStream = (ws) => {\n throw new Error(\"Not supported yet in Bun\");\n};\n$ = Object.assign(BunWebSocket, {\n createWebSocketStream,\n Receiver,\n Sender,\n WebSocket: BunWebSocket,\n Server: WebSocketServer,\n WebSocketServer\n});\nreturn $})\n"_s;
+static constexpr ASCIILiteral ThirdpartyWSCode = "(function (){\"use strict\";// src/js/out/tmp/thirdparty/ws.ts\nvar emitWarning = function(type, message) {\n if (emittedWarnings.has(type))\n return;\n emittedWarnings.add(type), console.warn(\"[bun] Warning:\", message);\n}, subprotocolParse = function(header) {\n const protocols = new Set;\n let start = -1, end = -1, i = 0;\n for (i;i < header.length; i++) {\n const code = header.charCodeAt(i);\n if (end === -1 && wsTokenChars[code] === 1) {\n if (start === -1)\n start = i;\n } else if (i !== 0 && (code === 32 || code === 9)) {\n if (end === -1 && start !== -1)\n end = i;\n } else if (code === 44) {\n if (start === -1)\n throw new SyntaxError(`Unexpected character at index ${i}`);\n if (end === -1)\n end = i;\n const protocol2 = header.slice(start, end);\n if (protocols.has(protocol2))\n throw new SyntaxError(`The \"${protocol2}\" subprotocol is duplicated`);\n protocols.add(protocol2), start = end = -1;\n } else\n throw new SyntaxError(`Unexpected character at index ${i}`);\n }\n if (start === -1 || end !== -1)\n throw new SyntaxError(\"Unexpected end of input\");\n const protocol = header.slice(start, i);\n if (protocols.has(protocol))\n throw new SyntaxError(`The \"${protocol}\" subprotocol is duplicated`);\n return protocols.add(protocol), protocols;\n}, wsEmitClose = function(server) {\n server._state = CLOSED, server.emit(\"close\");\n}, abortHandshake = function(response, code, message, headers) {\n message = message || http.STATUS_CODES[code], headers = {\n Connection: \"close\",\n \"Content-Type\": \"text/html\",\n \"Content-Length\": @Buffer.byteLength(message),\n ...headers\n }, response.writeHead(code, headers), response.write(message), response.end();\n}, abortHandshakeOrEmitwsClientError = function(server, req, response, socket, code, message) {\n if (server.listenerCount(\"wsClientError\")) {\n const err = new Error(message);\n Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError), server.emit(\"wsClientError\", err, socket, req);\n } else\n abortHandshake(response, code, message);\n}, $, EventEmitter = @getInternalField(@internalModuleRegistry, 18) || @createInternalModuleById(18), http = @getInternalField(@internalModuleRegistry, 21) || @createInternalModuleById(21), kBunInternals = Symbol.for(\"::bunternal::\"), readyStates = [\"CONNECTING\", \"OPEN\", \"CLOSING\", \"CLOSED\"], encoder = new TextEncoder, eventIds = {\n open: 1,\n close: 2,\n message: 3,\n error: 4,\n ping: 5,\n pong: 6\n}, emittedWarnings = new Set;\n\nclass BunWebSocket extends EventEmitter {\n static CONNECTING = 0;\n static OPEN = 1;\n static CLOSING = 2;\n static CLOSED = 3;\n #ws;\n #paused = !1;\n #fragments = !1;\n #binaryType = \"nodebuffer\";\n #eventId = 0;\n constructor(url, protocols, options) {\n super();\n let ws = this.#ws = new WebSocket(url, protocols);\n ws.binaryType = \"nodebuffer\";\n }\n on(event, listener) {\n if (event === \"unexpected-response\" || event === \"upgrade\" || event === \"redirect\")\n emitWarning(event, \"ws.WebSocket '\" + event + \"' event is not implemented in bun\");\n const mask = 1 << eventIds[event];\n if (mask && (this.#eventId & mask) !== mask) {\n if (this.#eventId |= mask, event === \"open\")\n this.#ws.addEventListener(\"open\", () => {\n this.emit(\"open\");\n });\n else if (event === \"close\")\n this.#ws.addEventListener(\"close\", ({ code, reason, wasClean }) => {\n this.emit(\"close\", code, reason, wasClean);\n });\n else if (event === \"message\")\n this.#ws.addEventListener(\"message\", ({ data }) => {\n const isBinary = typeof data !== \"string\";\n if (isBinary)\n this.emit(\"message\", this.#fragments \? [data] : data, isBinary);\n else {\n let encoded = encoder.encode(data);\n if (this.#binaryType !== \"arraybuffer\")\n encoded = @Buffer.from(encoded.buffer, encoded.byteOffset, encoded.byteLength);\n this.emit(\"message\", this.#fragments \? [encoded] : encoded, isBinary);\n }\n });\n else if (event === \"error\")\n this.#ws.addEventListener(\"error\", (err) => {\n this.emit(\"error\", err);\n });\n else if (event === \"ping\")\n this.#ws.addEventListener(\"ping\", ({ data }) => {\n this.emit(\"ping\", data);\n });\n else if (event === \"pong\")\n this.#ws.addEventListener(\"pong\", ({ data }) => {\n this.emit(\"pong\", data);\n });\n }\n return super.on(event, listener);\n }\n send(data, opts, cb) {\n try {\n this.#ws.send(data, opts\?.compress);\n } catch (error) {\n typeof cb === \"function\" && cb(error);\n return;\n }\n typeof cb === \"function\" && cb();\n }\n close(code, reason) {\n this.#ws.close(code, reason);\n }\n terminate() {\n this.#ws.terminate();\n }\n get url() {\n return this.#ws.url;\n }\n get readyState() {\n return this.#ws.readyState;\n }\n get binaryType() {\n return this.#binaryType;\n }\n set binaryType(value) {\n if (value === \"nodebuffer\" || value === \"arraybuffer\")\n this.#ws.binaryType = this.#binaryType = value, this.#fragments = !1;\n else if (value === \"fragments\")\n this.#ws.binaryType = \"nodebuffer\", this.#binaryType = \"fragments\", this.#fragments = !0;\n else\n throw new Error(`Invalid binaryType: ${value}`);\n }\n get protocol() {\n return this.#ws.protocol;\n }\n get extensions() {\n return this.#ws.extensions;\n }\n addEventListener(type, listener, options) {\n this.#ws.addEventListener(type, listener, options);\n }\n removeEventListener(type, listener) {\n this.#ws.removeEventListener(type, listener);\n }\n get onopen() {\n return this.#ws.onopen;\n }\n set onopen(value) {\n this.#ws.onopen = value;\n }\n get onerror() {\n return this.#ws.onerror;\n }\n set onerror(value) {\n this.#ws.onerror = value;\n }\n get onclose() {\n return this.#ws.onclose;\n }\n set onclose(value) {\n this.#ws.onclose = value;\n }\n get onmessage() {\n return this.#ws.onmessage;\n }\n set onmessage(value) {\n this.#ws.onmessage = value;\n }\n get bufferedAmount() {\n return this.#ws.bufferedAmount;\n }\n get isPaused() {\n return this.#paused;\n }\n ping(data, mask, cb) {\n if (typeof data === \"function\")\n cb = data, data = mask = @undefined;\n else if (typeof mask === \"function\")\n cb = mask, mask = @undefined;\n if (typeof data === \"number\")\n data = data.toString();\n try {\n this.#ws.ping(data);\n } catch (error) {\n typeof cb === \"function\" && cb(error);\n return;\n }\n typeof cb === \"function\" && cb();\n }\n pong(data, mask, cb) {\n if (typeof data === \"function\")\n cb = data, data = mask = @undefined;\n else if (typeof mask === \"function\")\n cb = mask, mask = @undefined;\n if (typeof data === \"number\")\n data = data.toString();\n try {\n this.#ws.pong(data);\n } catch (error) {\n typeof cb === \"function\" && cb(error);\n return;\n }\n typeof cb === \"function\" && cb();\n }\n pause() {\n switch (this.readyState) {\n case WebSocket.CONNECTING:\n case WebSocket.CLOSED:\n return;\n }\n this.#paused = !0, emitWarning(\"pause()\", \"ws.WebSocket.pause() is not implemented in bun\");\n }\n resume() {\n switch (this.readyState) {\n case WebSocket.CONNECTING:\n case WebSocket.CLOSED:\n return;\n }\n this.#paused = !1, emitWarning(\"resume()\", \"ws.WebSocket.resume() is not implemented in bun\");\n }\n}\nObject.defineProperty(BunWebSocket, \"name\", { value: \"WebSocket\" });\nvar wsKeyRegex = /^[+/0-9A-Za-z]{22}==$/, wsTokenChars = [\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 1,\n 0,\n 1,\n 1,\n 1,\n 1,\n 1,\n 0,\n 0,\n 1,\n 1,\n 0,\n 1,\n 1,\n 0,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 0,\n 0,\n 0,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 1,\n 0,\n 1,\n 0,\n 1,\n 0\n], RUNNING = 0, CLOSING = 1, CLOSED = 2;\n\nclass BunWebSocketMocked extends EventEmitter {\n #ws;\n #state;\n #enquedMessages = [];\n #url;\n #protocol;\n #extensions;\n #bufferedAmount = 0;\n #binaryType = \"arraybuffer\";\n #onclose;\n #onerror;\n #onmessage;\n #onopen;\n constructor(url, protocol, extensions, binaryType) {\n super();\n if (this.#ws = null, this.#state = 0, this.#url = url, this.#bufferedAmount = 0, binaryType = binaryType || \"arraybuffer\", binaryType !== \"nodebuffer\" && binaryType !== \"blob\" && binaryType !== \"arraybuffer\")\n @throwTypeError(\"binaryType must be either 'blob', 'arraybuffer' or 'nodebuffer'\");\n this.#binaryType = binaryType, this.#protocol = protocol, this.#extensions = extensions;\n const message = this.#message.bind(this), open = this.#open.bind(this), close = this.#close.bind(this), drain = this.#drain.bind(this);\n this[kBunInternals] = {\n message,\n open,\n close,\n drain\n };\n }\n #message(ws, message) {\n this.#ws = ws;\n let isBinary = !1;\n if (typeof message === \"string\")\n if (this.#binaryType === \"arraybuffer\")\n message = encoder.encode(message).buffer;\n else if (this.#binaryType === \"blob\")\n message = new Blob([message], { type: \"text/plain\" });\n else\n message = @Buffer.from(message);\n else if (isBinary = !0, this.#binaryType !== \"nodebuffer\") {\n if (this.#binaryType === \"arraybuffer\")\n message = new @Uint8Array(message);\n else if (this.#binaryType === \"blob\")\n message = new Blob([message]);\n }\n this.emit(\"message\", message, isBinary);\n }\n #open(ws) {\n this.#ws = ws, this.#state = 1, this.emit(\"open\", this), this.#drain(ws);\n }\n #close(ws, code, reason) {\n this.#state = 3, this.#ws = null, this.emit(\"close\", code, reason);\n }\n #drain(ws) {\n const chunk = this.#enquedMessages[0];\n if (chunk) {\n const [data, compress, cb] = chunk;\n if (ws.send(data, compress) == -1)\n return;\n typeof cb === \"function\" && cb(), this.#bufferedAmount -= chunk.length, this.#enquedMessages.shift();\n }\n }\n send(data, opts, cb) {\n if (this.#state === 1) {\n const compress = opts\?.compress;\n if (this.#ws.send(data, compress) == -1) {\n this.#enquedMessages.push([data, compress, cb]), this.#bufferedAmount += data.length;\n return;\n }\n typeof cb === \"function\" && cb();\n } else if (this.#state === 0)\n this.#enquedMessages.push([data, opts\?.compress, cb]), this.#bufferedAmount += data.length;\n }\n close(code, reason) {\n if (this.#state === 1)\n this.#state = 2, this.#ws.close(code, reason);\n }\n get binaryType() {\n return this.#binaryType;\n }\n set binaryType(type) {\n if (type !== \"nodebuffer\" && type !== \"blob\" && type !== \"arraybuffer\")\n @throwTypeError(\"binaryType must be either 'blob', 'arraybuffer' or 'nodebuffer'\");\n this.#binaryType = type;\n }\n get readyState() {\n return this.#state;\n }\n get url() {\n return this.#url;\n }\n get protocol() {\n return this.#protocol;\n }\n get extensions() {\n return this.#extensions;\n }\n get bufferedAmount() {\n return this.#bufferedAmount \?\? 0;\n }\n setSocket(socket, head, options) {\n throw new Error(\"Not implemented\");\n }\n set onclose(cb) {\n if (this.#onclose)\n this.removeListener(\"close\", this.#onclose);\n this.on(\"close\", cb), this.#onclose = cb;\n }\n set onerror(cb) {\n if (this.#onerror)\n this.removeListener(\"error\", this.#onerror);\n this.on(\"error\", cb), this.#onerror = cb;\n }\n set onmessage(cb) {\n if (this.#onmessage)\n this.removeListener(\"message\", this.#onmessage);\n this.on(\"message\", cb), this.#onmessage = cb;\n }\n set onopen(cb) {\n if (this.#onopen)\n this.removeListener(\"open\", this.#onopen);\n this.on(\"open\", cb), this.#onopen = cb;\n }\n get onclose() {\n return this.#onclose;\n }\n get onerror() {\n return this.#onerror;\n }\n get onmessage() {\n return this.#onmessage;\n }\n get onopen() {\n return this.#onopen;\n }\n addEventListener(type, listener, options) {\n if (type === \"message\") {\n const l = (data) => listener({ data });\n l.listener = listener, this.on(type, l);\n return;\n }\n this.on(type, listener);\n }\n removeEventListener(type, listener) {\n this.off(type, listener);\n }\n}\n\nclass WebSocketServer extends EventEmitter {\n _server;\n options;\n clients;\n _shouldEmitClose;\n _state;\n _removeListeners;\n constructor(options, callback) {\n super();\n if (options = {\n maxPayload: 104857600,\n skipUTF8Validation: !1,\n perMessageDeflate: !1,\n handleProtocols: null,\n clientTracking: !0,\n verifyClient: null,\n noServer: !1,\n backlog: null,\n server: null,\n host: null,\n path: null,\n port: null,\n ...options\n }, options.port == null && !options.server && !options.noServer || options.port != null && (options.server || options.noServer) || options.server && options.noServer)\n @throwTypeError('One and only one of the \"port\", \"server\", or \"noServer\" options must be specified');\n if (options.port != null)\n this._server = http.createServer((req, res) => {\n const body = http.STATUS_CODES[426];\n res.writeHead(426, {\n \"Content-Length\": body.length,\n \"Content-Type\": \"text/plain\"\n }), res.end(body);\n }), this._server.listen(options.port, options.host, options.backlog, callback);\n else if (options.server)\n this._server = options.server;\n if (this._server) {\n const emitConnection = this.emit.bind(this, \"connection\"), emitListening = this.emit.bind(this, \"listening\"), emitError = this.emit.bind(this, \"error\"), doUpgrade = (req, socket, head) => {\n this.handleUpgrade(req, socket, head, emitConnection);\n };\n this._server.on(\"listening\", emitListening), this._server.on(\"error\", emitError), this._server.on(\"upgrade\", doUpgrade), this._removeListeners = () => {\n this._server.removeListener(\"upgrade\", doUpgrade), this._server.removeListener(\"listening\", emitListening), this._server.removeListener(\"error\", emitError);\n };\n }\n if (options.perMessageDeflate === !0)\n options.perMessageDeflate = {};\n if (options.clientTracking)\n this.clients = new Set, this._shouldEmitClose = !1;\n this.options = options, this._state = RUNNING;\n }\n address() {\n if (this.options.noServer)\n throw new Error('The server is operating in \"noServer\" mode');\n if (!this._server)\n return null;\n return this._server.address();\n }\n close(cb) {\n if (this._state === CLOSED) {\n if (cb)\n this.once(\"close\", () => {\n cb(new Error(\"The server is not running\"));\n });\n process.nextTick((server) => {\n server._state = CLOSED, server.emit(\"close\");\n }, this);\n return;\n }\n if (cb)\n this.once(\"close\", cb);\n if (this._state === CLOSING)\n return;\n if (this._state = CLOSING, this.options.noServer || this.options.server) {\n if (this._server)\n this._removeListeners(), this._removeListeners = this._server = null;\n if (this.clients)\n if (!this.clients.size)\n process.nextTick((server) => {\n server._state = CLOSED, server.emit(\"close\");\n }, this);\n else\n this._shouldEmitClose = !0;\n else\n process.nextTick((server) => {\n server._state = CLOSED, server.emit(\"close\");\n }, this);\n } else {\n const server = this._server;\n this._removeListeners(), this._removeListeners = this._server = null, server.close(() => {\n this._state = CLOSED, this.emit(\"close\");\n });\n }\n }\n shouldHandle(req) {\n if (this.options.path) {\n const index = req.url.indexOf(\"\?\");\n if ((index !== -1 \? req.url.slice(0, index) : req.url) !== this.options.path)\n return !1;\n }\n return !0;\n }\n completeUpgrade(extensions, key, protocols, request, socket, head, cb) {\n const [server, response, req] = socket[kBunInternals];\n if (this._state > RUNNING)\n return abortHandshake(response, 503);\n let protocol = \"\";\n if (protocols.size)\n protocol = this.options.handleProtocols \? this.options.handleProtocols(protocols, request) : protocols.values().next().value;\n const ws = new BunWebSocketMocked(request.url, protocol, extensions, \"nodebuffer\"), headers = [\"HTTP/1.1 101 Switching Protocols\", \"Upgrade: websocket\", \"Connection: Upgrade\"];\n if (this.emit(\"headers\", headers, request), server.upgrade(req, {\n data: ws[kBunInternals]\n })) {\n if (response._reply(@undefined), this.clients)\n this.clients.add(ws), ws.on(\"close\", () => {\n if (this.clients.delete(ws), this._shouldEmitClose && !this.clients.size)\n process.nextTick(wsEmitClose, this);\n });\n cb(ws, request);\n } else\n abortHandshake(response, 500);\n }\n handleUpgrade(req, socket, head, cb) {\n const [_, response] = socket[kBunInternals], key = req.headers[\"sec-websocket-key\"], version = +req.headers[\"sec-websocket-version\"];\n if (req.method !== \"GET\") {\n abortHandshakeOrEmitwsClientError(this, req, response, socket, 405, \"Invalid HTTP method\");\n return;\n }\n if (req.headers.upgrade.toLowerCase() !== \"websocket\") {\n abortHandshakeOrEmitwsClientError(this, req, response, socket, 400, \"Invalid Upgrade header\");\n return;\n }\n if (!key || !wsKeyRegex.test(key)) {\n abortHandshakeOrEmitwsClientError(this, req, response, socket, 400, \"Missing or invalid Sec-WebSocket-Key header\");\n return;\n }\n if (version !== 8 && version !== 13) {\n abortHandshakeOrEmitwsClientError(this, req, response, socket, 400, \"Missing or invalid Sec-WebSocket-Version header\");\n return;\n }\n if (!this.shouldHandle(req)) {\n abortHandshake(response, 400);\n return;\n }\n const secWebSocketProtocol = req.headers[\"sec-websocket-protocol\"];\n let protocols = new Set;\n if (secWebSocketProtocol !== @undefined)\n try {\n protocols = subprotocolParse(secWebSocketProtocol);\n } catch (err) {\n abortHandshakeOrEmitwsClientError(this, req, response, socket, 400, \"Invalid Sec-WebSocket-Protocol header\");\n return;\n }\n const extensions = {};\n if (this.options.verifyClient) {\n const info = {\n origin: req.headers[`${version === 8 \? \"sec-websocket-origin\" : \"origin\"}`],\n secure: !!(req.socket.authorized || req.socket.encrypted),\n req\n };\n if (this.options.verifyClient.length === 2) {\n this.options.verifyClient(info, (verified, code, message, headers) => {\n if (!verified)\n return abortHandshake(response, code || 401, message, headers);\n this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);\n });\n return;\n }\n if (!this.options.verifyClient(info))\n return abortHandshake(response, 401);\n }\n this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);\n }\n}\nObject.defineProperty(BunWebSocket, \"CONNECTING\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CONNECTING\")\n});\nObject.defineProperty(BunWebSocket.prototype, \"CONNECTING\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CONNECTING\")\n});\nObject.defineProperty(BunWebSocket, \"OPEN\", {\n enumerable: !0,\n value: readyStates.indexOf(\"OPEN\")\n});\nObject.defineProperty(BunWebSocket.prototype, \"OPEN\", {\n enumerable: !0,\n value: readyStates.indexOf(\"OPEN\")\n});\nObject.defineProperty(BunWebSocket, \"CLOSING\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CLOSING\")\n});\nObject.defineProperty(BunWebSocket.prototype, \"CLOSING\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CLOSING\")\n});\nObject.defineProperty(BunWebSocket, \"CLOSED\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CLOSED\")\n});\nObject.defineProperty(BunWebSocket.prototype, \"CLOSED\", {\n enumerable: !0,\n value: readyStates.indexOf(\"CLOSED\")\n});\n\nclass Sender {\n constructor() {\n throw new Error(\"Not supported yet in Bun\");\n }\n}\n\nclass Receiver {\n constructor() {\n throw new Error(\"Not supported yet in Bun\");\n }\n}\nvar createWebSocketStream = (ws) => {\n throw new Error(\"Not supported yet in Bun\");\n};\n$ = Object.assign(BunWebSocket, {\n createWebSocketStream,\n Receiver,\n Sender,\n WebSocket: BunWebSocket,\n Server: WebSocketServer,\n WebSocketServer\n});\nreturn $})\n"_s;
//
#endif