@zoralabs/protocol-deployments 0.3.5-COMMENTS.1 → 0.3.5-COMMENTS.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/.turbo/turbo-build.log +48 -48
  2. package/CHANGELOG.md +12 -0
  3. package/dist/_esm-JXHAY2EM.js +4030 -0
  4. package/dist/_esm-JXHAY2EM.js.map +1 -0
  5. package/dist/ccip-MZCNL5YG.js +15 -0
  6. package/dist/chunk-FJ2PMLO3.js +132 -0
  7. package/dist/chunk-FJ2PMLO3.js.map +1 -0
  8. package/dist/chunk-MCOK75CU.js +3837 -0
  9. package/dist/chunk-MCOK75CU.js.map +1 -0
  10. package/dist/generated/wagmi.d.ts +259 -139
  11. package/dist/generated/wagmi.d.ts.map +1 -1
  12. package/dist/index.cjs +203 -219
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.js +65 -27
  15. package/dist/index.js.map +1 -1
  16. package/dist/secp256k1-NJATWSDZ.js +2395 -0
  17. package/dist/secp256k1-NJATWSDZ.js.map +1 -0
  18. package/dist/typedData.d.ts +12 -3
  19. package/dist/typedData.d.ts.map +1 -1
  20. package/json/1155.json +212 -0
  21. package/json/mints.json +46 -0
  22. package/package/.turbo/turbo-build.log +48 -0
  23. package/{dist/ccip-TLVKUNHE.js → package/dist/ccip-42FQPB7J.js} +2 -2
  24. package/package/dist/ccip-42FQPB7J.js.map +1 -0
  25. package/package/dist/chunk-3EJPJMEH.js +44 -0
  26. package/package/dist/chunk-3EJPJMEH.js.map +1 -0
  27. package/{dist/chunk-IB365BT5.js → package/dist/chunk-YMRS2KON.js} +2 -3
  28. package/package/dist/encoding.d.ts +15 -0
  29. package/package/dist/encoding.d.ts.map +1 -0
  30. package/package/dist/generated/1155.d.ts +232 -0
  31. package/package/dist/generated/1155.d.ts.map +1 -0
  32. package/package/dist/generated/sparks.d.ts +85 -0
  33. package/package/dist/generated/sparks.d.ts.map +1 -0
  34. package/package/dist/generated/wagmi.d.ts +27548 -0
  35. package/package/dist/generated/wagmi.d.ts.map +1 -0
  36. package/package/dist/index.cjs +12957 -0
  37. package/package/dist/index.cjs.map +1 -0
  38. package/package/dist/index.d.ts +7 -0
  39. package/package/dist/index.d.ts.map +1 -0
  40. package/package/dist/index.js +11268 -0
  41. package/package/dist/index.js.map +1 -0
  42. package/package/dist/typedData.d.ts +234 -0
  43. package/package/dist/typedData.d.ts.map +1 -0
  44. package/package/dist/types.d.ts +45 -0
  45. package/package/dist/types.d.ts.map +1 -0
  46. package/package/package/.turbo/turbo-build.log +48 -0
  47. package/package/package/dist/_esm-KB2T7G46.js +3923 -0
  48. package/package/package/dist/_esm-KB2T7G46.js.map +1 -0
  49. package/package/package/dist/ccip-42FQPB7J.js +15 -0
  50. package/package/package/dist/ccip-42FQPB7J.js.map +1 -0
  51. package/package/package/dist/chunk-3EJPJMEH.js +44 -0
  52. package/package/package/dist/chunk-3EJPJMEH.js.map +1 -0
  53. package/package/package/dist/chunk-5JV63AHR.js +129 -0
  54. package/package/package/dist/chunk-5JV63AHR.js.map +1 -0
  55. package/package/package/dist/chunk-YMRS2KON.js +3956 -0
  56. package/package/package/dist/chunk-YMRS2KON.js.map +1 -0
  57. package/package/package/dist/encoding.d.ts +15 -0
  58. package/package/package/dist/encoding.d.ts.map +1 -0
  59. package/package/package/dist/generated/1155.d.ts +232 -0
  60. package/package/package/dist/generated/1155.d.ts.map +1 -0
  61. package/package/package/dist/generated/sparks.d.ts +85 -0
  62. package/package/package/dist/generated/sparks.d.ts.map +1 -0
  63. package/package/package/dist/generated/wagmi.d.ts +27548 -0
  64. package/package/package/dist/generated/wagmi.d.ts.map +1 -0
  65. package/package/package/dist/index.cjs +12957 -0
  66. package/package/package/dist/index.cjs.map +1 -0
  67. package/package/package/dist/index.d.ts +7 -0
  68. package/package/package/dist/index.d.ts.map +1 -0
  69. package/package/package/dist/index.js +11268 -0
  70. package/package/package/dist/index.js.map +1 -0
  71. package/package/package/dist/secp256k1-5CEPNAX3.js +2244 -0
  72. package/package/package/dist/secp256k1-5CEPNAX3.js.map +1 -0
  73. package/package/package/dist/typedData.d.ts +234 -0
  74. package/package/package/dist/typedData.d.ts.map +1 -0
  75. package/package/package/dist/types.d.ts +45 -0
  76. package/package/package/dist/types.d.ts.map +1 -0
  77. package/package.json +4 -5
  78. package/src/generated/wagmi.ts +177 -92
  79. package/src/typedData.ts +12 -3
  80. /package/dist/{ccip-TLVKUNHE.js.map → ccip-MZCNL5YG.js.map} +0 -0
  81. /package/{dist → package/dist}/_esm-KB2T7G46.js +0 -0
  82. /package/{dist → package/dist}/_esm-KB2T7G46.js.map +0 -0
  83. /package/{dist → package/dist}/chunk-5JV63AHR.js +0 -0
  84. /package/{dist → package/dist}/chunk-5JV63AHR.js.map +0 -0
  85. /package/{dist/chunk-IB365BT5.js.map → package/dist/chunk-YMRS2KON.js.map} +0 -0
  86. /package/{dist → package/dist}/secp256k1-5CEPNAX3.js +0 -0
  87. /package/{dist → package/dist}/secp256k1-5CEPNAX3.js.map +0 -0
@@ -0,0 +1,4030 @@
1
+ import {
2
+ __commonJS,
3
+ __export,
4
+ __require,
5
+ __toESM
6
+ } from "./chunk-3EJPJMEH.js";
7
+
8
+ // ../../node_modules/.pnpm/ws@8.18.0_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/stream.js
9
+ var require_stream = __commonJS({
10
+ "../../node_modules/.pnpm/ws@8.18.0_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/stream.js"(exports, module) {
11
+ "use strict";
12
+ var { Duplex } = __require("stream");
13
+ function emitClose(stream) {
14
+ stream.emit("close");
15
+ }
16
+ function duplexOnEnd() {
17
+ if (!this.destroyed && this._writableState.finished) {
18
+ this.destroy();
19
+ }
20
+ }
21
+ function duplexOnError(err) {
22
+ this.removeListener("error", duplexOnError);
23
+ this.destroy();
24
+ if (this.listenerCount("error") === 0) {
25
+ this.emit("error", err);
26
+ }
27
+ }
28
+ function createWebSocketStream2(ws, options) {
29
+ let terminateOnDestroy = true;
30
+ const duplex = new Duplex({
31
+ ...options,
32
+ autoDestroy: false,
33
+ emitClose: false,
34
+ objectMode: false,
35
+ writableObjectMode: false
36
+ });
37
+ ws.on("message", function message(msg, isBinary) {
38
+ const data = !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
39
+ if (!duplex.push(data))
40
+ ws.pause();
41
+ });
42
+ ws.once("error", function error(err) {
43
+ if (duplex.destroyed)
44
+ return;
45
+ terminateOnDestroy = false;
46
+ duplex.destroy(err);
47
+ });
48
+ ws.once("close", function close() {
49
+ if (duplex.destroyed)
50
+ return;
51
+ duplex.push(null);
52
+ });
53
+ duplex._destroy = function(err, callback) {
54
+ if (ws.readyState === ws.CLOSED) {
55
+ callback(err);
56
+ process.nextTick(emitClose, duplex);
57
+ return;
58
+ }
59
+ let called = false;
60
+ ws.once("error", function error(err2) {
61
+ called = true;
62
+ callback(err2);
63
+ });
64
+ ws.once("close", function close() {
65
+ if (!called)
66
+ callback(err);
67
+ process.nextTick(emitClose, duplex);
68
+ });
69
+ if (terminateOnDestroy)
70
+ ws.terminate();
71
+ };
72
+ duplex._final = function(callback) {
73
+ if (ws.readyState === ws.CONNECTING) {
74
+ ws.once("open", function open() {
75
+ duplex._final(callback);
76
+ });
77
+ return;
78
+ }
79
+ if (ws._socket === null)
80
+ return;
81
+ if (ws._socket._writableState.finished) {
82
+ callback();
83
+ if (duplex._readableState.endEmitted)
84
+ duplex.destroy();
85
+ } else {
86
+ ws._socket.once("finish", function finish() {
87
+ callback();
88
+ });
89
+ ws.close();
90
+ }
91
+ };
92
+ duplex._read = function() {
93
+ if (ws.isPaused)
94
+ ws.resume();
95
+ };
96
+ duplex._write = function(chunk, encoding, callback) {
97
+ if (ws.readyState === ws.CONNECTING) {
98
+ ws.once("open", function open() {
99
+ duplex._write(chunk, encoding, callback);
100
+ });
101
+ return;
102
+ }
103
+ ws.send(chunk, callback);
104
+ };
105
+ duplex.on("end", duplexOnEnd);
106
+ duplex.on("error", duplexOnError);
107
+ return duplex;
108
+ }
109
+ module.exports = createWebSocketStream2;
110
+ }
111
+ });
112
+
113
+ // ../../node_modules/.pnpm/ws@8.18.0_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/constants.js
114
+ var require_constants = __commonJS({
115
+ "../../node_modules/.pnpm/ws@8.18.0_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/constants.js"(exports, module) {
116
+ "use strict";
117
+ var BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
118
+ var hasBlob = typeof Blob !== "undefined";
119
+ if (hasBlob)
120
+ BINARY_TYPES.push("blob");
121
+ module.exports = {
122
+ BINARY_TYPES,
123
+ EMPTY_BUFFER: Buffer.alloc(0),
124
+ GUID: "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
125
+ hasBlob,
126
+ kForOnEventAttribute: Symbol("kIsForOnEventAttribute"),
127
+ kListener: Symbol("kListener"),
128
+ kStatusCode: Symbol("status-code"),
129
+ kWebSocket: Symbol("websocket"),
130
+ NOOP: () => {
131
+ }
132
+ };
133
+ }
134
+ });
135
+
136
+ // ../../node_modules/.pnpm/node-gyp-build@4.8.1/node_modules/node-gyp-build/node-gyp-build.js
137
+ var require_node_gyp_build = __commonJS({
138
+ "../../node_modules/.pnpm/node-gyp-build@4.8.1/node_modules/node-gyp-build/node-gyp-build.js"(exports, module) {
139
+ "use strict";
140
+ var fs = __require("fs");
141
+ var path = __require("path");
142
+ var os = __require("os");
143
+ var runtimeRequire = typeof __webpack_require__ === "function" ? __non_webpack_require__ : __require;
144
+ var vars = process.config && process.config.variables || {};
145
+ var prebuildsOnly = !!process.env.PREBUILDS_ONLY;
146
+ var abi = process.versions.modules;
147
+ var runtime = isElectron() ? "electron" : isNwjs() ? "node-webkit" : "node";
148
+ var arch = process.env.npm_config_arch || os.arch();
149
+ var platform = process.env.npm_config_platform || os.platform();
150
+ var libc = process.env.LIBC || (isAlpine(platform) ? "musl" : "glibc");
151
+ var armv = process.env.ARM_VERSION || (arch === "arm64" ? "8" : vars.arm_version) || "";
152
+ var uv = (process.versions.uv || "").split(".")[0];
153
+ module.exports = load;
154
+ function load(dir) {
155
+ return runtimeRequire(load.resolve(dir));
156
+ }
157
+ load.resolve = load.path = function(dir) {
158
+ dir = path.resolve(dir || ".");
159
+ try {
160
+ var name = runtimeRequire(path.join(dir, "package.json")).name.toUpperCase().replace(/-/g, "_");
161
+ if (process.env[name + "_PREBUILD"])
162
+ dir = process.env[name + "_PREBUILD"];
163
+ } catch (err) {
164
+ }
165
+ if (!prebuildsOnly) {
166
+ var release = getFirst(path.join(dir, "build/Release"), matchBuild);
167
+ if (release)
168
+ return release;
169
+ var debug = getFirst(path.join(dir, "build/Debug"), matchBuild);
170
+ if (debug)
171
+ return debug;
172
+ }
173
+ var prebuild = resolve(dir);
174
+ if (prebuild)
175
+ return prebuild;
176
+ var nearby = resolve(path.dirname(process.execPath));
177
+ if (nearby)
178
+ return nearby;
179
+ var target = [
180
+ "platform=" + platform,
181
+ "arch=" + arch,
182
+ "runtime=" + runtime,
183
+ "abi=" + abi,
184
+ "uv=" + uv,
185
+ armv ? "armv=" + armv : "",
186
+ "libc=" + libc,
187
+ "node=" + process.versions.node,
188
+ process.versions.electron ? "electron=" + process.versions.electron : "",
189
+ typeof __webpack_require__ === "function" ? "webpack=true" : ""
190
+ // eslint-disable-line
191
+ ].filter(Boolean).join(" ");
192
+ throw new Error("No native build was found for " + target + "\n loaded from: " + dir + "\n");
193
+ function resolve(dir2) {
194
+ var tuples = readdirSync(path.join(dir2, "prebuilds")).map(parseTuple);
195
+ var tuple = tuples.filter(matchTuple(platform, arch)).sort(compareTuples)[0];
196
+ if (!tuple)
197
+ return;
198
+ var prebuilds = path.join(dir2, "prebuilds", tuple.name);
199
+ var parsed = readdirSync(prebuilds).map(parseTags);
200
+ var candidates = parsed.filter(matchTags(runtime, abi));
201
+ var winner = candidates.sort(compareTags(runtime))[0];
202
+ if (winner)
203
+ return path.join(prebuilds, winner.file);
204
+ }
205
+ };
206
+ function readdirSync(dir) {
207
+ try {
208
+ return fs.readdirSync(dir);
209
+ } catch (err) {
210
+ return [];
211
+ }
212
+ }
213
+ function getFirst(dir, filter) {
214
+ var files = readdirSync(dir).filter(filter);
215
+ return files[0] && path.join(dir, files[0]);
216
+ }
217
+ function matchBuild(name) {
218
+ return /\.node$/.test(name);
219
+ }
220
+ function parseTuple(name) {
221
+ var arr = name.split("-");
222
+ if (arr.length !== 2)
223
+ return;
224
+ var platform2 = arr[0];
225
+ var architectures = arr[1].split("+");
226
+ if (!platform2)
227
+ return;
228
+ if (!architectures.length)
229
+ return;
230
+ if (!architectures.every(Boolean))
231
+ return;
232
+ return { name, platform: platform2, architectures };
233
+ }
234
+ function matchTuple(platform2, arch2) {
235
+ return function(tuple) {
236
+ if (tuple == null)
237
+ return false;
238
+ if (tuple.platform !== platform2)
239
+ return false;
240
+ return tuple.architectures.includes(arch2);
241
+ };
242
+ }
243
+ function compareTuples(a, b) {
244
+ return a.architectures.length - b.architectures.length;
245
+ }
246
+ function parseTags(file) {
247
+ var arr = file.split(".");
248
+ var extension = arr.pop();
249
+ var tags = { file, specificity: 0 };
250
+ if (extension !== "node")
251
+ return;
252
+ for (var i = 0; i < arr.length; i++) {
253
+ var tag = arr[i];
254
+ if (tag === "node" || tag === "electron" || tag === "node-webkit") {
255
+ tags.runtime = tag;
256
+ } else if (tag === "napi") {
257
+ tags.napi = true;
258
+ } else if (tag.slice(0, 3) === "abi") {
259
+ tags.abi = tag.slice(3);
260
+ } else if (tag.slice(0, 2) === "uv") {
261
+ tags.uv = tag.slice(2);
262
+ } else if (tag.slice(0, 4) === "armv") {
263
+ tags.armv = tag.slice(4);
264
+ } else if (tag === "glibc" || tag === "musl") {
265
+ tags.libc = tag;
266
+ } else {
267
+ continue;
268
+ }
269
+ tags.specificity++;
270
+ }
271
+ return tags;
272
+ }
273
+ function matchTags(runtime2, abi2) {
274
+ return function(tags) {
275
+ if (tags == null)
276
+ return false;
277
+ if (tags.runtime && tags.runtime !== runtime2 && !runtimeAgnostic(tags))
278
+ return false;
279
+ if (tags.abi && tags.abi !== abi2 && !tags.napi)
280
+ return false;
281
+ if (tags.uv && tags.uv !== uv)
282
+ return false;
283
+ if (tags.armv && tags.armv !== armv)
284
+ return false;
285
+ if (tags.libc && tags.libc !== libc)
286
+ return false;
287
+ return true;
288
+ };
289
+ }
290
+ function runtimeAgnostic(tags) {
291
+ return tags.runtime === "node" && tags.napi;
292
+ }
293
+ function compareTags(runtime2) {
294
+ return function(a, b) {
295
+ if (a.runtime !== b.runtime) {
296
+ return a.runtime === runtime2 ? -1 : 1;
297
+ } else if (a.abi !== b.abi) {
298
+ return a.abi ? -1 : 1;
299
+ } else if (a.specificity !== b.specificity) {
300
+ return a.specificity > b.specificity ? -1 : 1;
301
+ } else {
302
+ return 0;
303
+ }
304
+ };
305
+ }
306
+ function isNwjs() {
307
+ return !!(process.versions && process.versions.nw);
308
+ }
309
+ function isElectron() {
310
+ if (process.versions && process.versions.electron)
311
+ return true;
312
+ if (process.env.ELECTRON_RUN_AS_NODE)
313
+ return true;
314
+ return typeof window !== "undefined" && window.process && window.process.type === "renderer";
315
+ }
316
+ function isAlpine(platform2) {
317
+ return platform2 === "linux" && fs.existsSync("/etc/alpine-release");
318
+ }
319
+ load.parseTags = parseTags;
320
+ load.matchTags = matchTags;
321
+ load.compareTags = compareTags;
322
+ load.parseTuple = parseTuple;
323
+ load.matchTuple = matchTuple;
324
+ load.compareTuples = compareTuples;
325
+ }
326
+ });
327
+
328
+ // ../../node_modules/.pnpm/node-gyp-build@4.8.1/node_modules/node-gyp-build/index.js
329
+ var require_node_gyp_build2 = __commonJS({
330
+ "../../node_modules/.pnpm/node-gyp-build@4.8.1/node_modules/node-gyp-build/index.js"(exports, module) {
331
+ "use strict";
332
+ var runtimeRequire = typeof __webpack_require__ === "function" ? __non_webpack_require__ : __require;
333
+ if (typeof runtimeRequire.addon === "function") {
334
+ module.exports = runtimeRequire.addon.bind(runtimeRequire);
335
+ } else {
336
+ module.exports = require_node_gyp_build();
337
+ }
338
+ }
339
+ });
340
+
341
+ // ../../node_modules/.pnpm/bufferutil@4.0.8/node_modules/bufferutil/fallback.js
342
+ var require_fallback = __commonJS({
343
+ "../../node_modules/.pnpm/bufferutil@4.0.8/node_modules/bufferutil/fallback.js"(exports, module) {
344
+ "use strict";
345
+ var mask = (source, mask2, output, offset, length) => {
346
+ for (var i = 0; i < length; i++) {
347
+ output[offset + i] = source[i] ^ mask2[i & 3];
348
+ }
349
+ };
350
+ var unmask = (buffer, mask2) => {
351
+ const length = buffer.length;
352
+ for (var i = 0; i < length; i++) {
353
+ buffer[i] ^= mask2[i & 3];
354
+ }
355
+ };
356
+ module.exports = { mask, unmask };
357
+ }
358
+ });
359
+
360
+ // ../../node_modules/.pnpm/bufferutil@4.0.8/node_modules/bufferutil/index.js
361
+ var require_bufferutil = __commonJS({
362
+ "../../node_modules/.pnpm/bufferutil@4.0.8/node_modules/bufferutil/index.js"(exports, module) {
363
+ "use strict";
364
+ try {
365
+ module.exports = require_node_gyp_build2()(__dirname);
366
+ } catch (e) {
367
+ module.exports = require_fallback();
368
+ }
369
+ }
370
+ });
371
+
372
+ // ../../node_modules/.pnpm/ws@8.18.0_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/buffer-util.js
373
+ var require_buffer_util = __commonJS({
374
+ "../../node_modules/.pnpm/ws@8.18.0_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/buffer-util.js"(exports, module) {
375
+ "use strict";
376
+ var { EMPTY_BUFFER } = require_constants();
377
+ var FastBuffer = Buffer[Symbol.species];
378
+ function concat(list, totalLength) {
379
+ if (list.length === 0)
380
+ return EMPTY_BUFFER;
381
+ if (list.length === 1)
382
+ return list[0];
383
+ const target = Buffer.allocUnsafe(totalLength);
384
+ let offset = 0;
385
+ for (let i = 0; i < list.length; i++) {
386
+ const buf = list[i];
387
+ target.set(buf, offset);
388
+ offset += buf.length;
389
+ }
390
+ if (offset < totalLength) {
391
+ return new FastBuffer(target.buffer, target.byteOffset, offset);
392
+ }
393
+ return target;
394
+ }
395
+ function _mask(source, mask, output, offset, length) {
396
+ for (let i = 0; i < length; i++) {
397
+ output[offset + i] = source[i] ^ mask[i & 3];
398
+ }
399
+ }
400
+ function _unmask(buffer, mask) {
401
+ for (let i = 0; i < buffer.length; i++) {
402
+ buffer[i] ^= mask[i & 3];
403
+ }
404
+ }
405
+ function toArrayBuffer(buf) {
406
+ if (buf.length === buf.buffer.byteLength) {
407
+ return buf.buffer;
408
+ }
409
+ return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length);
410
+ }
411
+ function toBuffer(data) {
412
+ toBuffer.readOnly = true;
413
+ if (Buffer.isBuffer(data))
414
+ return data;
415
+ let buf;
416
+ if (data instanceof ArrayBuffer) {
417
+ buf = new FastBuffer(data);
418
+ } else if (ArrayBuffer.isView(data)) {
419
+ buf = new FastBuffer(data.buffer, data.byteOffset, data.byteLength);
420
+ } else {
421
+ buf = Buffer.from(data);
422
+ toBuffer.readOnly = false;
423
+ }
424
+ return buf;
425
+ }
426
+ module.exports = {
427
+ concat,
428
+ mask: _mask,
429
+ toArrayBuffer,
430
+ toBuffer,
431
+ unmask: _unmask
432
+ };
433
+ if (!process.env.WS_NO_BUFFER_UTIL) {
434
+ try {
435
+ const bufferUtil = require_bufferutil();
436
+ module.exports.mask = function(source, mask, output, offset, length) {
437
+ if (length < 48)
438
+ _mask(source, mask, output, offset, length);
439
+ else
440
+ bufferUtil.mask(source, mask, output, offset, length);
441
+ };
442
+ module.exports.unmask = function(buffer, mask) {
443
+ if (buffer.length < 32)
444
+ _unmask(buffer, mask);
445
+ else
446
+ bufferUtil.unmask(buffer, mask);
447
+ };
448
+ } catch (e) {
449
+ }
450
+ }
451
+ }
452
+ });
453
+
454
+ // ../../node_modules/.pnpm/ws@8.18.0_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/limiter.js
455
+ var require_limiter = __commonJS({
456
+ "../../node_modules/.pnpm/ws@8.18.0_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/limiter.js"(exports, module) {
457
+ "use strict";
458
+ var kDone = Symbol("kDone");
459
+ var kRun = Symbol("kRun");
460
+ var Limiter = class {
461
+ /**
462
+ * Creates a new `Limiter`.
463
+ *
464
+ * @param {Number} [concurrency=Infinity] The maximum number of jobs allowed
465
+ * to run concurrently
466
+ */
467
+ constructor(concurrency) {
468
+ this[kDone] = () => {
469
+ this.pending--;
470
+ this[kRun]();
471
+ };
472
+ this.concurrency = concurrency || Infinity;
473
+ this.jobs = [];
474
+ this.pending = 0;
475
+ }
476
+ /**
477
+ * Adds a job to the queue.
478
+ *
479
+ * @param {Function} job The job to run
480
+ * @public
481
+ */
482
+ add(job) {
483
+ this.jobs.push(job);
484
+ this[kRun]();
485
+ }
486
+ /**
487
+ * Removes a job from the queue and runs it if possible.
488
+ *
489
+ * @private
490
+ */
491
+ [kRun]() {
492
+ if (this.pending === this.concurrency)
493
+ return;
494
+ if (this.jobs.length) {
495
+ const job = this.jobs.shift();
496
+ this.pending++;
497
+ job(this[kDone]);
498
+ }
499
+ }
500
+ };
501
+ module.exports = Limiter;
502
+ }
503
+ });
504
+
505
+ // ../../node_modules/.pnpm/ws@8.18.0_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/permessage-deflate.js
506
+ var require_permessage_deflate = __commonJS({
507
+ "../../node_modules/.pnpm/ws@8.18.0_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/permessage-deflate.js"(exports, module) {
508
+ "use strict";
509
+ var zlib = __require("zlib");
510
+ var bufferUtil = require_buffer_util();
511
+ var Limiter = require_limiter();
512
+ var { kStatusCode } = require_constants();
513
+ var FastBuffer = Buffer[Symbol.species];
514
+ var TRAILER = Buffer.from([0, 0, 255, 255]);
515
+ var kPerMessageDeflate = Symbol("permessage-deflate");
516
+ var kTotalLength = Symbol("total-length");
517
+ var kCallback = Symbol("callback");
518
+ var kBuffers = Symbol("buffers");
519
+ var kError = Symbol("error");
520
+ var zlibLimiter;
521
+ var PerMessageDeflate = class {
522
+ /**
523
+ * Creates a PerMessageDeflate instance.
524
+ *
525
+ * @param {Object} [options] Configuration options
526
+ * @param {(Boolean|Number)} [options.clientMaxWindowBits] Advertise support
527
+ * for, or request, a custom client window size
528
+ * @param {Boolean} [options.clientNoContextTakeover=false] Advertise/
529
+ * acknowledge disabling of client context takeover
530
+ * @param {Number} [options.concurrencyLimit=10] The number of concurrent
531
+ * calls to zlib
532
+ * @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
533
+ * use of a custom server window size
534
+ * @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
535
+ * disabling of server context takeover
536
+ * @param {Number} [options.threshold=1024] Size (in bytes) below which
537
+ * messages should not be compressed if context takeover is disabled
538
+ * @param {Object} [options.zlibDeflateOptions] Options to pass to zlib on
539
+ * deflate
540
+ * @param {Object} [options.zlibInflateOptions] Options to pass to zlib on
541
+ * inflate
542
+ * @param {Boolean} [isServer=false] Create the instance in either server or
543
+ * client mode
544
+ * @param {Number} [maxPayload=0] The maximum allowed message length
545
+ */
546
+ constructor(options, isServer, maxPayload) {
547
+ this._maxPayload = maxPayload | 0;
548
+ this._options = options || {};
549
+ this._threshold = this._options.threshold !== void 0 ? this._options.threshold : 1024;
550
+ this._isServer = !!isServer;
551
+ this._deflate = null;
552
+ this._inflate = null;
553
+ this.params = null;
554
+ if (!zlibLimiter) {
555
+ const concurrency = this._options.concurrencyLimit !== void 0 ? this._options.concurrencyLimit : 10;
556
+ zlibLimiter = new Limiter(concurrency);
557
+ }
558
+ }
559
+ /**
560
+ * @type {String}
561
+ */
562
+ static get extensionName() {
563
+ return "permessage-deflate";
564
+ }
565
+ /**
566
+ * Create an extension negotiation offer.
567
+ *
568
+ * @return {Object} Extension parameters
569
+ * @public
570
+ */
571
+ offer() {
572
+ const params = {};
573
+ if (this._options.serverNoContextTakeover) {
574
+ params.server_no_context_takeover = true;
575
+ }
576
+ if (this._options.clientNoContextTakeover) {
577
+ params.client_no_context_takeover = true;
578
+ }
579
+ if (this._options.serverMaxWindowBits) {
580
+ params.server_max_window_bits = this._options.serverMaxWindowBits;
581
+ }
582
+ if (this._options.clientMaxWindowBits) {
583
+ params.client_max_window_bits = this._options.clientMaxWindowBits;
584
+ } else if (this._options.clientMaxWindowBits == null) {
585
+ params.client_max_window_bits = true;
586
+ }
587
+ return params;
588
+ }
589
+ /**
590
+ * Accept an extension negotiation offer/response.
591
+ *
592
+ * @param {Array} configurations The extension negotiation offers/reponse
593
+ * @return {Object} Accepted configuration
594
+ * @public
595
+ */
596
+ accept(configurations) {
597
+ configurations = this.normalizeParams(configurations);
598
+ this.params = this._isServer ? this.acceptAsServer(configurations) : this.acceptAsClient(configurations);
599
+ return this.params;
600
+ }
601
+ /**
602
+ * Releases all resources used by the extension.
603
+ *
604
+ * @public
605
+ */
606
+ cleanup() {
607
+ if (this._inflate) {
608
+ this._inflate.close();
609
+ this._inflate = null;
610
+ }
611
+ if (this._deflate) {
612
+ const callback = this._deflate[kCallback];
613
+ this._deflate.close();
614
+ this._deflate = null;
615
+ if (callback) {
616
+ callback(
617
+ new Error(
618
+ "The deflate stream was closed while data was being processed"
619
+ )
620
+ );
621
+ }
622
+ }
623
+ }
624
+ /**
625
+ * Accept an extension negotiation offer.
626
+ *
627
+ * @param {Array} offers The extension negotiation offers
628
+ * @return {Object} Accepted configuration
629
+ * @private
630
+ */
631
+ acceptAsServer(offers) {
632
+ const opts = this._options;
633
+ const accepted = offers.find((params) => {
634
+ if (opts.serverNoContextTakeover === false && params.server_no_context_takeover || params.server_max_window_bits && (opts.serverMaxWindowBits === false || typeof opts.serverMaxWindowBits === "number" && opts.serverMaxWindowBits > params.server_max_window_bits) || typeof opts.clientMaxWindowBits === "number" && !params.client_max_window_bits) {
635
+ return false;
636
+ }
637
+ return true;
638
+ });
639
+ if (!accepted) {
640
+ throw new Error("None of the extension offers can be accepted");
641
+ }
642
+ if (opts.serverNoContextTakeover) {
643
+ accepted.server_no_context_takeover = true;
644
+ }
645
+ if (opts.clientNoContextTakeover) {
646
+ accepted.client_no_context_takeover = true;
647
+ }
648
+ if (typeof opts.serverMaxWindowBits === "number") {
649
+ accepted.server_max_window_bits = opts.serverMaxWindowBits;
650
+ }
651
+ if (typeof opts.clientMaxWindowBits === "number") {
652
+ accepted.client_max_window_bits = opts.clientMaxWindowBits;
653
+ } else if (accepted.client_max_window_bits === true || opts.clientMaxWindowBits === false) {
654
+ delete accepted.client_max_window_bits;
655
+ }
656
+ return accepted;
657
+ }
658
+ /**
659
+ * Accept the extension negotiation response.
660
+ *
661
+ * @param {Array} response The extension negotiation response
662
+ * @return {Object} Accepted configuration
663
+ * @private
664
+ */
665
+ acceptAsClient(response) {
666
+ const params = response[0];
667
+ if (this._options.clientNoContextTakeover === false && params.client_no_context_takeover) {
668
+ throw new Error('Unexpected parameter "client_no_context_takeover"');
669
+ }
670
+ if (!params.client_max_window_bits) {
671
+ if (typeof this._options.clientMaxWindowBits === "number") {
672
+ params.client_max_window_bits = this._options.clientMaxWindowBits;
673
+ }
674
+ } else if (this._options.clientMaxWindowBits === false || typeof this._options.clientMaxWindowBits === "number" && params.client_max_window_bits > this._options.clientMaxWindowBits) {
675
+ throw new Error(
676
+ 'Unexpected or invalid parameter "client_max_window_bits"'
677
+ );
678
+ }
679
+ return params;
680
+ }
681
+ /**
682
+ * Normalize parameters.
683
+ *
684
+ * @param {Array} configurations The extension negotiation offers/reponse
685
+ * @return {Array} The offers/response with normalized parameters
686
+ * @private
687
+ */
688
+ normalizeParams(configurations) {
689
+ configurations.forEach((params) => {
690
+ Object.keys(params).forEach((key) => {
691
+ let value = params[key];
692
+ if (value.length > 1) {
693
+ throw new Error(`Parameter "${key}" must have only a single value`);
694
+ }
695
+ value = value[0];
696
+ if (key === "client_max_window_bits") {
697
+ if (value !== true) {
698
+ const num = +value;
699
+ if (!Number.isInteger(num) || num < 8 || num > 15) {
700
+ throw new TypeError(
701
+ `Invalid value for parameter "${key}": ${value}`
702
+ );
703
+ }
704
+ value = num;
705
+ } else if (!this._isServer) {
706
+ throw new TypeError(
707
+ `Invalid value for parameter "${key}": ${value}`
708
+ );
709
+ }
710
+ } else if (key === "server_max_window_bits") {
711
+ const num = +value;
712
+ if (!Number.isInteger(num) || num < 8 || num > 15) {
713
+ throw new TypeError(
714
+ `Invalid value for parameter "${key}": ${value}`
715
+ );
716
+ }
717
+ value = num;
718
+ } else if (key === "client_no_context_takeover" || key === "server_no_context_takeover") {
719
+ if (value !== true) {
720
+ throw new TypeError(
721
+ `Invalid value for parameter "${key}": ${value}`
722
+ );
723
+ }
724
+ } else {
725
+ throw new Error(`Unknown parameter "${key}"`);
726
+ }
727
+ params[key] = value;
728
+ });
729
+ });
730
+ return configurations;
731
+ }
732
+ /**
733
+ * Decompress data. Concurrency limited.
734
+ *
735
+ * @param {Buffer} data Compressed data
736
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
737
+ * @param {Function} callback Callback
738
+ * @public
739
+ */
740
+ decompress(data, fin, callback) {
741
+ zlibLimiter.add((done) => {
742
+ this._decompress(data, fin, (err, result) => {
743
+ done();
744
+ callback(err, result);
745
+ });
746
+ });
747
+ }
748
+ /**
749
+ * Compress data. Concurrency limited.
750
+ *
751
+ * @param {(Buffer|String)} data Data to compress
752
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
753
+ * @param {Function} callback Callback
754
+ * @public
755
+ */
756
+ compress(data, fin, callback) {
757
+ zlibLimiter.add((done) => {
758
+ this._compress(data, fin, (err, result) => {
759
+ done();
760
+ callback(err, result);
761
+ });
762
+ });
763
+ }
764
+ /**
765
+ * Decompress data.
766
+ *
767
+ * @param {Buffer} data Compressed data
768
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
769
+ * @param {Function} callback Callback
770
+ * @private
771
+ */
772
+ _decompress(data, fin, callback) {
773
+ const endpoint = this._isServer ? "client" : "server";
774
+ if (!this._inflate) {
775
+ const key = `${endpoint}_max_window_bits`;
776
+ const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
777
+ this._inflate = zlib.createInflateRaw({
778
+ ...this._options.zlibInflateOptions,
779
+ windowBits
780
+ });
781
+ this._inflate[kPerMessageDeflate] = this;
782
+ this._inflate[kTotalLength] = 0;
783
+ this._inflate[kBuffers] = [];
784
+ this._inflate.on("error", inflateOnError);
785
+ this._inflate.on("data", inflateOnData);
786
+ }
787
+ this._inflate[kCallback] = callback;
788
+ this._inflate.write(data);
789
+ if (fin)
790
+ this._inflate.write(TRAILER);
791
+ this._inflate.flush(() => {
792
+ const err = this._inflate[kError];
793
+ if (err) {
794
+ this._inflate.close();
795
+ this._inflate = null;
796
+ callback(err);
797
+ return;
798
+ }
799
+ const data2 = bufferUtil.concat(
800
+ this._inflate[kBuffers],
801
+ this._inflate[kTotalLength]
802
+ );
803
+ if (this._inflate._readableState.endEmitted) {
804
+ this._inflate.close();
805
+ this._inflate = null;
806
+ } else {
807
+ this._inflate[kTotalLength] = 0;
808
+ this._inflate[kBuffers] = [];
809
+ if (fin && this.params[`${endpoint}_no_context_takeover`]) {
810
+ this._inflate.reset();
811
+ }
812
+ }
813
+ callback(null, data2);
814
+ });
815
+ }
816
+ /**
817
+ * Compress data.
818
+ *
819
+ * @param {(Buffer|String)} data Data to compress
820
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
821
+ * @param {Function} callback Callback
822
+ * @private
823
+ */
824
+ _compress(data, fin, callback) {
825
+ const endpoint = this._isServer ? "server" : "client";
826
+ if (!this._deflate) {
827
+ const key = `${endpoint}_max_window_bits`;
828
+ const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
829
+ this._deflate = zlib.createDeflateRaw({
830
+ ...this._options.zlibDeflateOptions,
831
+ windowBits
832
+ });
833
+ this._deflate[kTotalLength] = 0;
834
+ this._deflate[kBuffers] = [];
835
+ this._deflate.on("data", deflateOnData);
836
+ }
837
+ this._deflate[kCallback] = callback;
838
+ this._deflate.write(data);
839
+ this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
840
+ if (!this._deflate) {
841
+ return;
842
+ }
843
+ let data2 = bufferUtil.concat(
844
+ this._deflate[kBuffers],
845
+ this._deflate[kTotalLength]
846
+ );
847
+ if (fin) {
848
+ data2 = new FastBuffer(data2.buffer, data2.byteOffset, data2.length - 4);
849
+ }
850
+ this._deflate[kCallback] = null;
851
+ this._deflate[kTotalLength] = 0;
852
+ this._deflate[kBuffers] = [];
853
+ if (fin && this.params[`${endpoint}_no_context_takeover`]) {
854
+ this._deflate.reset();
855
+ }
856
+ callback(null, data2);
857
+ });
858
+ }
859
+ };
860
+ module.exports = PerMessageDeflate;
861
+ function deflateOnData(chunk) {
862
+ this[kBuffers].push(chunk);
863
+ this[kTotalLength] += chunk.length;
864
+ }
865
+ function inflateOnData(chunk) {
866
+ this[kTotalLength] += chunk.length;
867
+ if (this[kPerMessageDeflate]._maxPayload < 1 || this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload) {
868
+ this[kBuffers].push(chunk);
869
+ return;
870
+ }
871
+ this[kError] = new RangeError("Max payload size exceeded");
872
+ this[kError].code = "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH";
873
+ this[kError][kStatusCode] = 1009;
874
+ this.removeListener("data", inflateOnData);
875
+ this.reset();
876
+ }
877
+ function inflateOnError(err) {
878
+ this[kPerMessageDeflate]._inflate = null;
879
+ err[kStatusCode] = 1007;
880
+ this[kCallback](err);
881
+ }
882
+ }
883
+ });
884
+
885
+ // ../../node_modules/.pnpm/utf-8-validate@5.0.10/node_modules/utf-8-validate/fallback.js
886
+ var require_fallback2 = __commonJS({
887
+ "../../node_modules/.pnpm/utf-8-validate@5.0.10/node_modules/utf-8-validate/fallback.js"(exports, module) {
888
+ "use strict";
889
+ function isValidUTF8(buf) {
890
+ const len = buf.length;
891
+ let i = 0;
892
+ while (i < len) {
893
+ if ((buf[i] & 128) === 0) {
894
+ i++;
895
+ } else if ((buf[i] & 224) === 192) {
896
+ if (i + 1 === len || (buf[i + 1] & 192) !== 128 || (buf[i] & 254) === 192) {
897
+ return false;
898
+ }
899
+ i += 2;
900
+ } else if ((buf[i] & 240) === 224) {
901
+ if (i + 2 >= len || (buf[i + 1] & 192) !== 128 || (buf[i + 2] & 192) !== 128 || buf[i] === 224 && (buf[i + 1] & 224) === 128 || // overlong
902
+ buf[i] === 237 && (buf[i + 1] & 224) === 160) {
903
+ return false;
904
+ }
905
+ i += 3;
906
+ } else if ((buf[i] & 248) === 240) {
907
+ if (i + 3 >= len || (buf[i + 1] & 192) !== 128 || (buf[i + 2] & 192) !== 128 || (buf[i + 3] & 192) !== 128 || buf[i] === 240 && (buf[i + 1] & 240) === 128 || // overlong
908
+ buf[i] === 244 && buf[i + 1] > 143 || buf[i] > 244) {
909
+ return false;
910
+ }
911
+ i += 4;
912
+ } else {
913
+ return false;
914
+ }
915
+ }
916
+ return true;
917
+ }
918
+ module.exports = isValidUTF8;
919
+ }
920
+ });
921
+
922
+ // ../../node_modules/.pnpm/utf-8-validate@5.0.10/node_modules/utf-8-validate/index.js
923
+ var require_utf_8_validate = __commonJS({
924
+ "../../node_modules/.pnpm/utf-8-validate@5.0.10/node_modules/utf-8-validate/index.js"(exports, module) {
925
+ "use strict";
926
+ try {
927
+ module.exports = require_node_gyp_build2()(__dirname);
928
+ } catch (e) {
929
+ module.exports = require_fallback2();
930
+ }
931
+ }
932
+ });
933
+
934
+ // ../../node_modules/.pnpm/ws@8.18.0_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/validation.js
935
+ var require_validation = __commonJS({
936
+ "../../node_modules/.pnpm/ws@8.18.0_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/validation.js"(exports, module) {
937
+ "use strict";
938
+ var { isUtf8 } = __require("buffer");
939
+ var { hasBlob } = require_constants();
940
+ var tokenChars = [
941
+ 0,
942
+ 0,
943
+ 0,
944
+ 0,
945
+ 0,
946
+ 0,
947
+ 0,
948
+ 0,
949
+ 0,
950
+ 0,
951
+ 0,
952
+ 0,
953
+ 0,
954
+ 0,
955
+ 0,
956
+ 0,
957
+ // 0 - 15
958
+ 0,
959
+ 0,
960
+ 0,
961
+ 0,
962
+ 0,
963
+ 0,
964
+ 0,
965
+ 0,
966
+ 0,
967
+ 0,
968
+ 0,
969
+ 0,
970
+ 0,
971
+ 0,
972
+ 0,
973
+ 0,
974
+ // 16 - 31
975
+ 0,
976
+ 1,
977
+ 0,
978
+ 1,
979
+ 1,
980
+ 1,
981
+ 1,
982
+ 1,
983
+ 0,
984
+ 0,
985
+ 1,
986
+ 1,
987
+ 0,
988
+ 1,
989
+ 1,
990
+ 0,
991
+ // 32 - 47
992
+ 1,
993
+ 1,
994
+ 1,
995
+ 1,
996
+ 1,
997
+ 1,
998
+ 1,
999
+ 1,
1000
+ 1,
1001
+ 1,
1002
+ 0,
1003
+ 0,
1004
+ 0,
1005
+ 0,
1006
+ 0,
1007
+ 0,
1008
+ // 48 - 63
1009
+ 0,
1010
+ 1,
1011
+ 1,
1012
+ 1,
1013
+ 1,
1014
+ 1,
1015
+ 1,
1016
+ 1,
1017
+ 1,
1018
+ 1,
1019
+ 1,
1020
+ 1,
1021
+ 1,
1022
+ 1,
1023
+ 1,
1024
+ 1,
1025
+ // 64 - 79
1026
+ 1,
1027
+ 1,
1028
+ 1,
1029
+ 1,
1030
+ 1,
1031
+ 1,
1032
+ 1,
1033
+ 1,
1034
+ 1,
1035
+ 1,
1036
+ 1,
1037
+ 0,
1038
+ 0,
1039
+ 0,
1040
+ 1,
1041
+ 1,
1042
+ // 80 - 95
1043
+ 1,
1044
+ 1,
1045
+ 1,
1046
+ 1,
1047
+ 1,
1048
+ 1,
1049
+ 1,
1050
+ 1,
1051
+ 1,
1052
+ 1,
1053
+ 1,
1054
+ 1,
1055
+ 1,
1056
+ 1,
1057
+ 1,
1058
+ 1,
1059
+ // 96 - 111
1060
+ 1,
1061
+ 1,
1062
+ 1,
1063
+ 1,
1064
+ 1,
1065
+ 1,
1066
+ 1,
1067
+ 1,
1068
+ 1,
1069
+ 1,
1070
+ 1,
1071
+ 0,
1072
+ 1,
1073
+ 0,
1074
+ 1,
1075
+ 0
1076
+ // 112 - 127
1077
+ ];
1078
+ function isValidStatusCode(code) {
1079
+ return code >= 1e3 && code <= 1014 && code !== 1004 && code !== 1005 && code !== 1006 || code >= 3e3 && code <= 4999;
1080
+ }
1081
+ function _isValidUTF8(buf) {
1082
+ const len = buf.length;
1083
+ let i = 0;
1084
+ while (i < len) {
1085
+ if ((buf[i] & 128) === 0) {
1086
+ i++;
1087
+ } else if ((buf[i] & 224) === 192) {
1088
+ if (i + 1 === len || (buf[i + 1] & 192) !== 128 || (buf[i] & 254) === 192) {
1089
+ return false;
1090
+ }
1091
+ i += 2;
1092
+ } else if ((buf[i] & 240) === 224) {
1093
+ if (i + 2 >= len || (buf[i + 1] & 192) !== 128 || (buf[i + 2] & 192) !== 128 || buf[i] === 224 && (buf[i + 1] & 224) === 128 || // Overlong
1094
+ buf[i] === 237 && (buf[i + 1] & 224) === 160) {
1095
+ return false;
1096
+ }
1097
+ i += 3;
1098
+ } else if ((buf[i] & 248) === 240) {
1099
+ if (i + 3 >= len || (buf[i + 1] & 192) !== 128 || (buf[i + 2] & 192) !== 128 || (buf[i + 3] & 192) !== 128 || buf[i] === 240 && (buf[i + 1] & 240) === 128 || // Overlong
1100
+ buf[i] === 244 && buf[i + 1] > 143 || buf[i] > 244) {
1101
+ return false;
1102
+ }
1103
+ i += 4;
1104
+ } else {
1105
+ return false;
1106
+ }
1107
+ }
1108
+ return true;
1109
+ }
1110
+ function isBlob(value) {
1111
+ return hasBlob && typeof value === "object" && typeof value.arrayBuffer === "function" && typeof value.type === "string" && typeof value.stream === "function" && (value[Symbol.toStringTag] === "Blob" || value[Symbol.toStringTag] === "File");
1112
+ }
1113
+ module.exports = {
1114
+ isBlob,
1115
+ isValidStatusCode,
1116
+ isValidUTF8: _isValidUTF8,
1117
+ tokenChars
1118
+ };
1119
+ if (isUtf8) {
1120
+ module.exports.isValidUTF8 = function(buf) {
1121
+ return buf.length < 24 ? _isValidUTF8(buf) : isUtf8(buf);
1122
+ };
1123
+ } else if (!process.env.WS_NO_UTF_8_VALIDATE) {
1124
+ try {
1125
+ const isValidUTF8 = require_utf_8_validate();
1126
+ module.exports.isValidUTF8 = function(buf) {
1127
+ return buf.length < 32 ? _isValidUTF8(buf) : isValidUTF8(buf);
1128
+ };
1129
+ } catch (e) {
1130
+ }
1131
+ }
1132
+ }
1133
+ });
1134
+
1135
+ // ../../node_modules/.pnpm/ws@8.18.0_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/receiver.js
1136
+ var require_receiver = __commonJS({
1137
+ "../../node_modules/.pnpm/ws@8.18.0_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/receiver.js"(exports, module) {
1138
+ "use strict";
1139
+ var { Writable } = __require("stream");
1140
+ var PerMessageDeflate = require_permessage_deflate();
1141
+ var {
1142
+ BINARY_TYPES,
1143
+ EMPTY_BUFFER,
1144
+ kStatusCode,
1145
+ kWebSocket
1146
+ } = require_constants();
1147
+ var { concat, toArrayBuffer, unmask } = require_buffer_util();
1148
+ var { isValidStatusCode, isValidUTF8 } = require_validation();
1149
+ var FastBuffer = Buffer[Symbol.species];
1150
+ var GET_INFO = 0;
1151
+ var GET_PAYLOAD_LENGTH_16 = 1;
1152
+ var GET_PAYLOAD_LENGTH_64 = 2;
1153
+ var GET_MASK = 3;
1154
+ var GET_DATA = 4;
1155
+ var INFLATING = 5;
1156
+ var DEFER_EVENT = 6;
1157
+ var Receiver2 = class extends Writable {
1158
+ /**
1159
+ * Creates a Receiver instance.
1160
+ *
1161
+ * @param {Object} [options] Options object
1162
+ * @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether
1163
+ * any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
1164
+ * multiple times in the same tick
1165
+ * @param {String} [options.binaryType=nodebuffer] The type for binary data
1166
+ * @param {Object} [options.extensions] An object containing the negotiated
1167
+ * extensions
1168
+ * @param {Boolean} [options.isServer=false] Specifies whether to operate in
1169
+ * client or server mode
1170
+ * @param {Number} [options.maxPayload=0] The maximum allowed message length
1171
+ * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
1172
+ * not to skip UTF-8 validation for text and close messages
1173
+ */
1174
+ constructor(options = {}) {
1175
+ super();
1176
+ this._allowSynchronousEvents = options.allowSynchronousEvents !== void 0 ? options.allowSynchronousEvents : true;
1177
+ this._binaryType = options.binaryType || BINARY_TYPES[0];
1178
+ this._extensions = options.extensions || {};
1179
+ this._isServer = !!options.isServer;
1180
+ this._maxPayload = options.maxPayload | 0;
1181
+ this._skipUTF8Validation = !!options.skipUTF8Validation;
1182
+ this[kWebSocket] = void 0;
1183
+ this._bufferedBytes = 0;
1184
+ this._buffers = [];
1185
+ this._compressed = false;
1186
+ this._payloadLength = 0;
1187
+ this._mask = void 0;
1188
+ this._fragmented = 0;
1189
+ this._masked = false;
1190
+ this._fin = false;
1191
+ this._opcode = 0;
1192
+ this._totalPayloadLength = 0;
1193
+ this._messageLength = 0;
1194
+ this._fragments = [];
1195
+ this._errored = false;
1196
+ this._loop = false;
1197
+ this._state = GET_INFO;
1198
+ }
1199
+ /**
1200
+ * Implements `Writable.prototype._write()`.
1201
+ *
1202
+ * @param {Buffer} chunk The chunk of data to write
1203
+ * @param {String} encoding The character encoding of `chunk`
1204
+ * @param {Function} cb Callback
1205
+ * @private
1206
+ */
1207
+ _write(chunk, encoding, cb) {
1208
+ if (this._opcode === 8 && this._state == GET_INFO)
1209
+ return cb();
1210
+ this._bufferedBytes += chunk.length;
1211
+ this._buffers.push(chunk);
1212
+ this.startLoop(cb);
1213
+ }
1214
+ /**
1215
+ * Consumes `n` bytes from the buffered data.
1216
+ *
1217
+ * @param {Number} n The number of bytes to consume
1218
+ * @return {Buffer} The consumed bytes
1219
+ * @private
1220
+ */
1221
+ consume(n) {
1222
+ this._bufferedBytes -= n;
1223
+ if (n === this._buffers[0].length)
1224
+ return this._buffers.shift();
1225
+ if (n < this._buffers[0].length) {
1226
+ const buf = this._buffers[0];
1227
+ this._buffers[0] = new FastBuffer(
1228
+ buf.buffer,
1229
+ buf.byteOffset + n,
1230
+ buf.length - n
1231
+ );
1232
+ return new FastBuffer(buf.buffer, buf.byteOffset, n);
1233
+ }
1234
+ const dst = Buffer.allocUnsafe(n);
1235
+ do {
1236
+ const buf = this._buffers[0];
1237
+ const offset = dst.length - n;
1238
+ if (n >= buf.length) {
1239
+ dst.set(this._buffers.shift(), offset);
1240
+ } else {
1241
+ dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset);
1242
+ this._buffers[0] = new FastBuffer(
1243
+ buf.buffer,
1244
+ buf.byteOffset + n,
1245
+ buf.length - n
1246
+ );
1247
+ }
1248
+ n -= buf.length;
1249
+ } while (n > 0);
1250
+ return dst;
1251
+ }
1252
+ /**
1253
+ * Starts the parsing loop.
1254
+ *
1255
+ * @param {Function} cb Callback
1256
+ * @private
1257
+ */
1258
+ startLoop(cb) {
1259
+ this._loop = true;
1260
+ do {
1261
+ switch (this._state) {
1262
+ case GET_INFO:
1263
+ this.getInfo(cb);
1264
+ break;
1265
+ case GET_PAYLOAD_LENGTH_16:
1266
+ this.getPayloadLength16(cb);
1267
+ break;
1268
+ case GET_PAYLOAD_LENGTH_64:
1269
+ this.getPayloadLength64(cb);
1270
+ break;
1271
+ case GET_MASK:
1272
+ this.getMask();
1273
+ break;
1274
+ case GET_DATA:
1275
+ this.getData(cb);
1276
+ break;
1277
+ case INFLATING:
1278
+ case DEFER_EVENT:
1279
+ this._loop = false;
1280
+ return;
1281
+ }
1282
+ } while (this._loop);
1283
+ if (!this._errored)
1284
+ cb();
1285
+ }
1286
+ /**
1287
+ * Reads the first two bytes of a frame.
1288
+ *
1289
+ * @param {Function} cb Callback
1290
+ * @private
1291
+ */
1292
+ getInfo(cb) {
1293
+ if (this._bufferedBytes < 2) {
1294
+ this._loop = false;
1295
+ return;
1296
+ }
1297
+ const buf = this.consume(2);
1298
+ if ((buf[0] & 48) !== 0) {
1299
+ const error = this.createError(
1300
+ RangeError,
1301
+ "RSV2 and RSV3 must be clear",
1302
+ true,
1303
+ 1002,
1304
+ "WS_ERR_UNEXPECTED_RSV_2_3"
1305
+ );
1306
+ cb(error);
1307
+ return;
1308
+ }
1309
+ const compressed = (buf[0] & 64) === 64;
1310
+ if (compressed && !this._extensions[PerMessageDeflate.extensionName]) {
1311
+ const error = this.createError(
1312
+ RangeError,
1313
+ "RSV1 must be clear",
1314
+ true,
1315
+ 1002,
1316
+ "WS_ERR_UNEXPECTED_RSV_1"
1317
+ );
1318
+ cb(error);
1319
+ return;
1320
+ }
1321
+ this._fin = (buf[0] & 128) === 128;
1322
+ this._opcode = buf[0] & 15;
1323
+ this._payloadLength = buf[1] & 127;
1324
+ if (this._opcode === 0) {
1325
+ if (compressed) {
1326
+ const error = this.createError(
1327
+ RangeError,
1328
+ "RSV1 must be clear",
1329
+ true,
1330
+ 1002,
1331
+ "WS_ERR_UNEXPECTED_RSV_1"
1332
+ );
1333
+ cb(error);
1334
+ return;
1335
+ }
1336
+ if (!this._fragmented) {
1337
+ const error = this.createError(
1338
+ RangeError,
1339
+ "invalid opcode 0",
1340
+ true,
1341
+ 1002,
1342
+ "WS_ERR_INVALID_OPCODE"
1343
+ );
1344
+ cb(error);
1345
+ return;
1346
+ }
1347
+ this._opcode = this._fragmented;
1348
+ } else if (this._opcode === 1 || this._opcode === 2) {
1349
+ if (this._fragmented) {
1350
+ const error = this.createError(
1351
+ RangeError,
1352
+ `invalid opcode ${this._opcode}`,
1353
+ true,
1354
+ 1002,
1355
+ "WS_ERR_INVALID_OPCODE"
1356
+ );
1357
+ cb(error);
1358
+ return;
1359
+ }
1360
+ this._compressed = compressed;
1361
+ } else if (this._opcode > 7 && this._opcode < 11) {
1362
+ if (!this._fin) {
1363
+ const error = this.createError(
1364
+ RangeError,
1365
+ "FIN must be set",
1366
+ true,
1367
+ 1002,
1368
+ "WS_ERR_EXPECTED_FIN"
1369
+ );
1370
+ cb(error);
1371
+ return;
1372
+ }
1373
+ if (compressed) {
1374
+ const error = this.createError(
1375
+ RangeError,
1376
+ "RSV1 must be clear",
1377
+ true,
1378
+ 1002,
1379
+ "WS_ERR_UNEXPECTED_RSV_1"
1380
+ );
1381
+ cb(error);
1382
+ return;
1383
+ }
1384
+ if (this._payloadLength > 125 || this._opcode === 8 && this._payloadLength === 1) {
1385
+ const error = this.createError(
1386
+ RangeError,
1387
+ `invalid payload length ${this._payloadLength}`,
1388
+ true,
1389
+ 1002,
1390
+ "WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH"
1391
+ );
1392
+ cb(error);
1393
+ return;
1394
+ }
1395
+ } else {
1396
+ const error = this.createError(
1397
+ RangeError,
1398
+ `invalid opcode ${this._opcode}`,
1399
+ true,
1400
+ 1002,
1401
+ "WS_ERR_INVALID_OPCODE"
1402
+ );
1403
+ cb(error);
1404
+ return;
1405
+ }
1406
+ if (!this._fin && !this._fragmented)
1407
+ this._fragmented = this._opcode;
1408
+ this._masked = (buf[1] & 128) === 128;
1409
+ if (this._isServer) {
1410
+ if (!this._masked) {
1411
+ const error = this.createError(
1412
+ RangeError,
1413
+ "MASK must be set",
1414
+ true,
1415
+ 1002,
1416
+ "WS_ERR_EXPECTED_MASK"
1417
+ );
1418
+ cb(error);
1419
+ return;
1420
+ }
1421
+ } else if (this._masked) {
1422
+ const error = this.createError(
1423
+ RangeError,
1424
+ "MASK must be clear",
1425
+ true,
1426
+ 1002,
1427
+ "WS_ERR_UNEXPECTED_MASK"
1428
+ );
1429
+ cb(error);
1430
+ return;
1431
+ }
1432
+ if (this._payloadLength === 126)
1433
+ this._state = GET_PAYLOAD_LENGTH_16;
1434
+ else if (this._payloadLength === 127)
1435
+ this._state = GET_PAYLOAD_LENGTH_64;
1436
+ else
1437
+ this.haveLength(cb);
1438
+ }
1439
+ /**
1440
+ * Gets extended payload length (7+16).
1441
+ *
1442
+ * @param {Function} cb Callback
1443
+ * @private
1444
+ */
1445
+ getPayloadLength16(cb) {
1446
+ if (this._bufferedBytes < 2) {
1447
+ this._loop = false;
1448
+ return;
1449
+ }
1450
+ this._payloadLength = this.consume(2).readUInt16BE(0);
1451
+ this.haveLength(cb);
1452
+ }
1453
+ /**
1454
+ * Gets extended payload length (7+64).
1455
+ *
1456
+ * @param {Function} cb Callback
1457
+ * @private
1458
+ */
1459
+ getPayloadLength64(cb) {
1460
+ if (this._bufferedBytes < 8) {
1461
+ this._loop = false;
1462
+ return;
1463
+ }
1464
+ const buf = this.consume(8);
1465
+ const num = buf.readUInt32BE(0);
1466
+ if (num > Math.pow(2, 53 - 32) - 1) {
1467
+ const error = this.createError(
1468
+ RangeError,
1469
+ "Unsupported WebSocket frame: payload length > 2^53 - 1",
1470
+ false,
1471
+ 1009,
1472
+ "WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH"
1473
+ );
1474
+ cb(error);
1475
+ return;
1476
+ }
1477
+ this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
1478
+ this.haveLength(cb);
1479
+ }
1480
+ /**
1481
+ * Payload length has been read.
1482
+ *
1483
+ * @param {Function} cb Callback
1484
+ * @private
1485
+ */
1486
+ haveLength(cb) {
1487
+ if (this._payloadLength && this._opcode < 8) {
1488
+ this._totalPayloadLength += this._payloadLength;
1489
+ if (this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) {
1490
+ const error = this.createError(
1491
+ RangeError,
1492
+ "Max payload size exceeded",
1493
+ false,
1494
+ 1009,
1495
+ "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"
1496
+ );
1497
+ cb(error);
1498
+ return;
1499
+ }
1500
+ }
1501
+ if (this._masked)
1502
+ this._state = GET_MASK;
1503
+ else
1504
+ this._state = GET_DATA;
1505
+ }
1506
+ /**
1507
+ * Reads mask bytes.
1508
+ *
1509
+ * @private
1510
+ */
1511
+ getMask() {
1512
+ if (this._bufferedBytes < 4) {
1513
+ this._loop = false;
1514
+ return;
1515
+ }
1516
+ this._mask = this.consume(4);
1517
+ this._state = GET_DATA;
1518
+ }
1519
+ /**
1520
+ * Reads data bytes.
1521
+ *
1522
+ * @param {Function} cb Callback
1523
+ * @private
1524
+ */
1525
+ getData(cb) {
1526
+ let data = EMPTY_BUFFER;
1527
+ if (this._payloadLength) {
1528
+ if (this._bufferedBytes < this._payloadLength) {
1529
+ this._loop = false;
1530
+ return;
1531
+ }
1532
+ data = this.consume(this._payloadLength);
1533
+ if (this._masked && (this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3]) !== 0) {
1534
+ unmask(data, this._mask);
1535
+ }
1536
+ }
1537
+ if (this._opcode > 7) {
1538
+ this.controlMessage(data, cb);
1539
+ return;
1540
+ }
1541
+ if (this._compressed) {
1542
+ this._state = INFLATING;
1543
+ this.decompress(data, cb);
1544
+ return;
1545
+ }
1546
+ if (data.length) {
1547
+ this._messageLength = this._totalPayloadLength;
1548
+ this._fragments.push(data);
1549
+ }
1550
+ this.dataMessage(cb);
1551
+ }
1552
+ /**
1553
+ * Decompresses data.
1554
+ *
1555
+ * @param {Buffer} data Compressed data
1556
+ * @param {Function} cb Callback
1557
+ * @private
1558
+ */
1559
+ decompress(data, cb) {
1560
+ const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
1561
+ perMessageDeflate.decompress(data, this._fin, (err, buf) => {
1562
+ if (err)
1563
+ return cb(err);
1564
+ if (buf.length) {
1565
+ this._messageLength += buf.length;
1566
+ if (this._messageLength > this._maxPayload && this._maxPayload > 0) {
1567
+ const error = this.createError(
1568
+ RangeError,
1569
+ "Max payload size exceeded",
1570
+ false,
1571
+ 1009,
1572
+ "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"
1573
+ );
1574
+ cb(error);
1575
+ return;
1576
+ }
1577
+ this._fragments.push(buf);
1578
+ }
1579
+ this.dataMessage(cb);
1580
+ if (this._state === GET_INFO)
1581
+ this.startLoop(cb);
1582
+ });
1583
+ }
1584
+ /**
1585
+ * Handles a data message.
1586
+ *
1587
+ * @param {Function} cb Callback
1588
+ * @private
1589
+ */
1590
+ dataMessage(cb) {
1591
+ if (!this._fin) {
1592
+ this._state = GET_INFO;
1593
+ return;
1594
+ }
1595
+ const messageLength = this._messageLength;
1596
+ const fragments = this._fragments;
1597
+ this._totalPayloadLength = 0;
1598
+ this._messageLength = 0;
1599
+ this._fragmented = 0;
1600
+ this._fragments = [];
1601
+ if (this._opcode === 2) {
1602
+ let data;
1603
+ if (this._binaryType === "nodebuffer") {
1604
+ data = concat(fragments, messageLength);
1605
+ } else if (this._binaryType === "arraybuffer") {
1606
+ data = toArrayBuffer(concat(fragments, messageLength));
1607
+ } else if (this._binaryType === "blob") {
1608
+ data = new Blob(fragments);
1609
+ } else {
1610
+ data = fragments;
1611
+ }
1612
+ if (this._allowSynchronousEvents) {
1613
+ this.emit("message", data, true);
1614
+ this._state = GET_INFO;
1615
+ } else {
1616
+ this._state = DEFER_EVENT;
1617
+ setImmediate(() => {
1618
+ this.emit("message", data, true);
1619
+ this._state = GET_INFO;
1620
+ this.startLoop(cb);
1621
+ });
1622
+ }
1623
+ } else {
1624
+ const buf = concat(fragments, messageLength);
1625
+ if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
1626
+ const error = this.createError(
1627
+ Error,
1628
+ "invalid UTF-8 sequence",
1629
+ true,
1630
+ 1007,
1631
+ "WS_ERR_INVALID_UTF8"
1632
+ );
1633
+ cb(error);
1634
+ return;
1635
+ }
1636
+ if (this._state === INFLATING || this._allowSynchronousEvents) {
1637
+ this.emit("message", buf, false);
1638
+ this._state = GET_INFO;
1639
+ } else {
1640
+ this._state = DEFER_EVENT;
1641
+ setImmediate(() => {
1642
+ this.emit("message", buf, false);
1643
+ this._state = GET_INFO;
1644
+ this.startLoop(cb);
1645
+ });
1646
+ }
1647
+ }
1648
+ }
1649
+ /**
1650
+ * Handles a control message.
1651
+ *
1652
+ * @param {Buffer} data Data to handle
1653
+ * @return {(Error|RangeError|undefined)} A possible error
1654
+ * @private
1655
+ */
1656
+ controlMessage(data, cb) {
1657
+ if (this._opcode === 8) {
1658
+ if (data.length === 0) {
1659
+ this._loop = false;
1660
+ this.emit("conclude", 1005, EMPTY_BUFFER);
1661
+ this.end();
1662
+ } else {
1663
+ const code = data.readUInt16BE(0);
1664
+ if (!isValidStatusCode(code)) {
1665
+ const error = this.createError(
1666
+ RangeError,
1667
+ `invalid status code ${code}`,
1668
+ true,
1669
+ 1002,
1670
+ "WS_ERR_INVALID_CLOSE_CODE"
1671
+ );
1672
+ cb(error);
1673
+ return;
1674
+ }
1675
+ const buf = new FastBuffer(
1676
+ data.buffer,
1677
+ data.byteOffset + 2,
1678
+ data.length - 2
1679
+ );
1680
+ if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
1681
+ const error = this.createError(
1682
+ Error,
1683
+ "invalid UTF-8 sequence",
1684
+ true,
1685
+ 1007,
1686
+ "WS_ERR_INVALID_UTF8"
1687
+ );
1688
+ cb(error);
1689
+ return;
1690
+ }
1691
+ this._loop = false;
1692
+ this.emit("conclude", code, buf);
1693
+ this.end();
1694
+ }
1695
+ this._state = GET_INFO;
1696
+ return;
1697
+ }
1698
+ if (this._allowSynchronousEvents) {
1699
+ this.emit(this._opcode === 9 ? "ping" : "pong", data);
1700
+ this._state = GET_INFO;
1701
+ } else {
1702
+ this._state = DEFER_EVENT;
1703
+ setImmediate(() => {
1704
+ this.emit(this._opcode === 9 ? "ping" : "pong", data);
1705
+ this._state = GET_INFO;
1706
+ this.startLoop(cb);
1707
+ });
1708
+ }
1709
+ }
1710
+ /**
1711
+ * Builds an error object.
1712
+ *
1713
+ * @param {function(new:Error|RangeError)} ErrorCtor The error constructor
1714
+ * @param {String} message The error message
1715
+ * @param {Boolean} prefix Specifies whether or not to add a default prefix to
1716
+ * `message`
1717
+ * @param {Number} statusCode The status code
1718
+ * @param {String} errorCode The exposed error code
1719
+ * @return {(Error|RangeError)} The error
1720
+ * @private
1721
+ */
1722
+ createError(ErrorCtor, message, prefix, statusCode, errorCode) {
1723
+ this._loop = false;
1724
+ this._errored = true;
1725
+ const err = new ErrorCtor(
1726
+ prefix ? `Invalid WebSocket frame: ${message}` : message
1727
+ );
1728
+ Error.captureStackTrace(err, this.createError);
1729
+ err.code = errorCode;
1730
+ err[kStatusCode] = statusCode;
1731
+ return err;
1732
+ }
1733
+ };
1734
+ module.exports = Receiver2;
1735
+ }
1736
+ });
1737
+
1738
+ // ../../node_modules/.pnpm/ws@8.18.0_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/sender.js
1739
+ var require_sender = __commonJS({
1740
+ "../../node_modules/.pnpm/ws@8.18.0_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/sender.js"(exports, module) {
1741
+ "use strict";
1742
+ var { Duplex } = __require("stream");
1743
+ var { randomFillSync } = __require("crypto");
1744
+ var PerMessageDeflate = require_permessage_deflate();
1745
+ var { EMPTY_BUFFER, kWebSocket, NOOP } = require_constants();
1746
+ var { isBlob, isValidStatusCode } = require_validation();
1747
+ var { mask: applyMask, toBuffer } = require_buffer_util();
1748
+ var kByteLength = Symbol("kByteLength");
1749
+ var maskBuffer = Buffer.alloc(4);
1750
+ var RANDOM_POOL_SIZE = 8 * 1024;
1751
+ var randomPool;
1752
+ var randomPoolPointer = RANDOM_POOL_SIZE;
1753
+ var DEFAULT = 0;
1754
+ var DEFLATING = 1;
1755
+ var GET_BLOB_DATA = 2;
1756
+ var Sender2 = class _Sender {
1757
+ /**
1758
+ * Creates a Sender instance.
1759
+ *
1760
+ * @param {Duplex} socket The connection socket
1761
+ * @param {Object} [extensions] An object containing the negotiated extensions
1762
+ * @param {Function} [generateMask] The function used to generate the masking
1763
+ * key
1764
+ */
1765
+ constructor(socket, extensions, generateMask) {
1766
+ this._extensions = extensions || {};
1767
+ if (generateMask) {
1768
+ this._generateMask = generateMask;
1769
+ this._maskBuffer = Buffer.alloc(4);
1770
+ }
1771
+ this._socket = socket;
1772
+ this._firstFragment = true;
1773
+ this._compress = false;
1774
+ this._bufferedBytes = 0;
1775
+ this._queue = [];
1776
+ this._state = DEFAULT;
1777
+ this.onerror = NOOP;
1778
+ this[kWebSocket] = void 0;
1779
+ }
1780
+ /**
1781
+ * Frames a piece of data according to the HyBi WebSocket protocol.
1782
+ *
1783
+ * @param {(Buffer|String)} data The data to frame
1784
+ * @param {Object} options Options object
1785
+ * @param {Boolean} [options.fin=false] Specifies whether or not to set the
1786
+ * FIN bit
1787
+ * @param {Function} [options.generateMask] The function used to generate the
1788
+ * masking key
1789
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1790
+ * `data`
1791
+ * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
1792
+ * key
1793
+ * @param {Number} options.opcode The opcode
1794
+ * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
1795
+ * modified
1796
+ * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
1797
+ * RSV1 bit
1798
+ * @return {(Buffer|String)[]} The framed data
1799
+ * @public
1800
+ */
1801
+ static frame(data, options) {
1802
+ let mask;
1803
+ let merge = false;
1804
+ let offset = 2;
1805
+ let skipMasking = false;
1806
+ if (options.mask) {
1807
+ mask = options.maskBuffer || maskBuffer;
1808
+ if (options.generateMask) {
1809
+ options.generateMask(mask);
1810
+ } else {
1811
+ if (randomPoolPointer === RANDOM_POOL_SIZE) {
1812
+ if (randomPool === void 0) {
1813
+ randomPool = Buffer.alloc(RANDOM_POOL_SIZE);
1814
+ }
1815
+ randomFillSync(randomPool, 0, RANDOM_POOL_SIZE);
1816
+ randomPoolPointer = 0;
1817
+ }
1818
+ mask[0] = randomPool[randomPoolPointer++];
1819
+ mask[1] = randomPool[randomPoolPointer++];
1820
+ mask[2] = randomPool[randomPoolPointer++];
1821
+ mask[3] = randomPool[randomPoolPointer++];
1822
+ }
1823
+ skipMasking = (mask[0] | mask[1] | mask[2] | mask[3]) === 0;
1824
+ offset = 6;
1825
+ }
1826
+ let dataLength;
1827
+ if (typeof data === "string") {
1828
+ if ((!options.mask || skipMasking) && options[kByteLength] !== void 0) {
1829
+ dataLength = options[kByteLength];
1830
+ } else {
1831
+ data = Buffer.from(data);
1832
+ dataLength = data.length;
1833
+ }
1834
+ } else {
1835
+ dataLength = data.length;
1836
+ merge = options.mask && options.readOnly && !skipMasking;
1837
+ }
1838
+ let payloadLength = dataLength;
1839
+ if (dataLength >= 65536) {
1840
+ offset += 8;
1841
+ payloadLength = 127;
1842
+ } else if (dataLength > 125) {
1843
+ offset += 2;
1844
+ payloadLength = 126;
1845
+ }
1846
+ const target = Buffer.allocUnsafe(merge ? dataLength + offset : offset);
1847
+ target[0] = options.fin ? options.opcode | 128 : options.opcode;
1848
+ if (options.rsv1)
1849
+ target[0] |= 64;
1850
+ target[1] = payloadLength;
1851
+ if (payloadLength === 126) {
1852
+ target.writeUInt16BE(dataLength, 2);
1853
+ } else if (payloadLength === 127) {
1854
+ target[2] = target[3] = 0;
1855
+ target.writeUIntBE(dataLength, 4, 6);
1856
+ }
1857
+ if (!options.mask)
1858
+ return [target, data];
1859
+ target[1] |= 128;
1860
+ target[offset - 4] = mask[0];
1861
+ target[offset - 3] = mask[1];
1862
+ target[offset - 2] = mask[2];
1863
+ target[offset - 1] = mask[3];
1864
+ if (skipMasking)
1865
+ return [target, data];
1866
+ if (merge) {
1867
+ applyMask(data, mask, target, offset, dataLength);
1868
+ return [target];
1869
+ }
1870
+ applyMask(data, mask, data, 0, dataLength);
1871
+ return [target, data];
1872
+ }
1873
+ /**
1874
+ * Sends a close message to the other peer.
1875
+ *
1876
+ * @param {Number} [code] The status code component of the body
1877
+ * @param {(String|Buffer)} [data] The message component of the body
1878
+ * @param {Boolean} [mask=false] Specifies whether or not to mask the message
1879
+ * @param {Function} [cb] Callback
1880
+ * @public
1881
+ */
1882
+ close(code, data, mask, cb) {
1883
+ let buf;
1884
+ if (code === void 0) {
1885
+ buf = EMPTY_BUFFER;
1886
+ } else if (typeof code !== "number" || !isValidStatusCode(code)) {
1887
+ throw new TypeError("First argument must be a valid error code number");
1888
+ } else if (data === void 0 || !data.length) {
1889
+ buf = Buffer.allocUnsafe(2);
1890
+ buf.writeUInt16BE(code, 0);
1891
+ } else {
1892
+ const length = Buffer.byteLength(data);
1893
+ if (length > 123) {
1894
+ throw new RangeError("The message must not be greater than 123 bytes");
1895
+ }
1896
+ buf = Buffer.allocUnsafe(2 + length);
1897
+ buf.writeUInt16BE(code, 0);
1898
+ if (typeof data === "string") {
1899
+ buf.write(data, 2);
1900
+ } else {
1901
+ buf.set(data, 2);
1902
+ }
1903
+ }
1904
+ const options = {
1905
+ [kByteLength]: buf.length,
1906
+ fin: true,
1907
+ generateMask: this._generateMask,
1908
+ mask,
1909
+ maskBuffer: this._maskBuffer,
1910
+ opcode: 8,
1911
+ readOnly: false,
1912
+ rsv1: false
1913
+ };
1914
+ if (this._state !== DEFAULT) {
1915
+ this.enqueue([this.dispatch, buf, false, options, cb]);
1916
+ } else {
1917
+ this.sendFrame(_Sender.frame(buf, options), cb);
1918
+ }
1919
+ }
1920
+ /**
1921
+ * Sends a ping message to the other peer.
1922
+ *
1923
+ * @param {*} data The message to send
1924
+ * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
1925
+ * @param {Function} [cb] Callback
1926
+ * @public
1927
+ */
1928
+ ping(data, mask, cb) {
1929
+ let byteLength;
1930
+ let readOnly;
1931
+ if (typeof data === "string") {
1932
+ byteLength = Buffer.byteLength(data);
1933
+ readOnly = false;
1934
+ } else if (isBlob(data)) {
1935
+ byteLength = data.size;
1936
+ readOnly = false;
1937
+ } else {
1938
+ data = toBuffer(data);
1939
+ byteLength = data.length;
1940
+ readOnly = toBuffer.readOnly;
1941
+ }
1942
+ if (byteLength > 125) {
1943
+ throw new RangeError("The data size must not be greater than 125 bytes");
1944
+ }
1945
+ const options = {
1946
+ [kByteLength]: byteLength,
1947
+ fin: true,
1948
+ generateMask: this._generateMask,
1949
+ mask,
1950
+ maskBuffer: this._maskBuffer,
1951
+ opcode: 9,
1952
+ readOnly,
1953
+ rsv1: false
1954
+ };
1955
+ if (isBlob(data)) {
1956
+ if (this._state !== DEFAULT) {
1957
+ this.enqueue([this.getBlobData, data, false, options, cb]);
1958
+ } else {
1959
+ this.getBlobData(data, false, options, cb);
1960
+ }
1961
+ } else if (this._state !== DEFAULT) {
1962
+ this.enqueue([this.dispatch, data, false, options, cb]);
1963
+ } else {
1964
+ this.sendFrame(_Sender.frame(data, options), cb);
1965
+ }
1966
+ }
1967
+ /**
1968
+ * Sends a pong message to the other peer.
1969
+ *
1970
+ * @param {*} data The message to send
1971
+ * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
1972
+ * @param {Function} [cb] Callback
1973
+ * @public
1974
+ */
1975
+ pong(data, mask, cb) {
1976
+ let byteLength;
1977
+ let readOnly;
1978
+ if (typeof data === "string") {
1979
+ byteLength = Buffer.byteLength(data);
1980
+ readOnly = false;
1981
+ } else if (isBlob(data)) {
1982
+ byteLength = data.size;
1983
+ readOnly = false;
1984
+ } else {
1985
+ data = toBuffer(data);
1986
+ byteLength = data.length;
1987
+ readOnly = toBuffer.readOnly;
1988
+ }
1989
+ if (byteLength > 125) {
1990
+ throw new RangeError("The data size must not be greater than 125 bytes");
1991
+ }
1992
+ const options = {
1993
+ [kByteLength]: byteLength,
1994
+ fin: true,
1995
+ generateMask: this._generateMask,
1996
+ mask,
1997
+ maskBuffer: this._maskBuffer,
1998
+ opcode: 10,
1999
+ readOnly,
2000
+ rsv1: false
2001
+ };
2002
+ if (isBlob(data)) {
2003
+ if (this._state !== DEFAULT) {
2004
+ this.enqueue([this.getBlobData, data, false, options, cb]);
2005
+ } else {
2006
+ this.getBlobData(data, false, options, cb);
2007
+ }
2008
+ } else if (this._state !== DEFAULT) {
2009
+ this.enqueue([this.dispatch, data, false, options, cb]);
2010
+ } else {
2011
+ this.sendFrame(_Sender.frame(data, options), cb);
2012
+ }
2013
+ }
2014
+ /**
2015
+ * Sends a data message to the other peer.
2016
+ *
2017
+ * @param {*} data The message to send
2018
+ * @param {Object} options Options object
2019
+ * @param {Boolean} [options.binary=false] Specifies whether `data` is binary
2020
+ * or text
2021
+ * @param {Boolean} [options.compress=false] Specifies whether or not to
2022
+ * compress `data`
2023
+ * @param {Boolean} [options.fin=false] Specifies whether the fragment is the
2024
+ * last one
2025
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
2026
+ * `data`
2027
+ * @param {Function} [cb] Callback
2028
+ * @public
2029
+ */
2030
+ send(data, options, cb) {
2031
+ const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
2032
+ let opcode = options.binary ? 2 : 1;
2033
+ let rsv1 = options.compress;
2034
+ let byteLength;
2035
+ let readOnly;
2036
+ if (typeof data === "string") {
2037
+ byteLength = Buffer.byteLength(data);
2038
+ readOnly = false;
2039
+ } else if (isBlob(data)) {
2040
+ byteLength = data.size;
2041
+ readOnly = false;
2042
+ } else {
2043
+ data = toBuffer(data);
2044
+ byteLength = data.length;
2045
+ readOnly = toBuffer.readOnly;
2046
+ }
2047
+ if (this._firstFragment) {
2048
+ this._firstFragment = false;
2049
+ if (rsv1 && perMessageDeflate && perMessageDeflate.params[perMessageDeflate._isServer ? "server_no_context_takeover" : "client_no_context_takeover"]) {
2050
+ rsv1 = byteLength >= perMessageDeflate._threshold;
2051
+ }
2052
+ this._compress = rsv1;
2053
+ } else {
2054
+ rsv1 = false;
2055
+ opcode = 0;
2056
+ }
2057
+ if (options.fin)
2058
+ this._firstFragment = true;
2059
+ const opts = {
2060
+ [kByteLength]: byteLength,
2061
+ fin: options.fin,
2062
+ generateMask: this._generateMask,
2063
+ mask: options.mask,
2064
+ maskBuffer: this._maskBuffer,
2065
+ opcode,
2066
+ readOnly,
2067
+ rsv1
2068
+ };
2069
+ if (isBlob(data)) {
2070
+ if (this._state !== DEFAULT) {
2071
+ this.enqueue([this.getBlobData, data, this._compress, opts, cb]);
2072
+ } else {
2073
+ this.getBlobData(data, this._compress, opts, cb);
2074
+ }
2075
+ } else if (this._state !== DEFAULT) {
2076
+ this.enqueue([this.dispatch, data, this._compress, opts, cb]);
2077
+ } else {
2078
+ this.dispatch(data, this._compress, opts, cb);
2079
+ }
2080
+ }
2081
+ /**
2082
+ * Gets the contents of a blob as binary data.
2083
+ *
2084
+ * @param {Blob} blob The blob
2085
+ * @param {Boolean} [compress=false] Specifies whether or not to compress
2086
+ * the data
2087
+ * @param {Object} options Options object
2088
+ * @param {Boolean} [options.fin=false] Specifies whether or not to set the
2089
+ * FIN bit
2090
+ * @param {Function} [options.generateMask] The function used to generate the
2091
+ * masking key
2092
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
2093
+ * `data`
2094
+ * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
2095
+ * key
2096
+ * @param {Number} options.opcode The opcode
2097
+ * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
2098
+ * modified
2099
+ * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
2100
+ * RSV1 bit
2101
+ * @param {Function} [cb] Callback
2102
+ * @private
2103
+ */
2104
+ getBlobData(blob, compress, options, cb) {
2105
+ this._bufferedBytes += options[kByteLength];
2106
+ this._state = GET_BLOB_DATA;
2107
+ blob.arrayBuffer().then((arrayBuffer) => {
2108
+ if (this._socket.destroyed) {
2109
+ const err = new Error(
2110
+ "The socket was closed while the blob was being read"
2111
+ );
2112
+ process.nextTick(callCallbacks, this, err, cb);
2113
+ return;
2114
+ }
2115
+ this._bufferedBytes -= options[kByteLength];
2116
+ const data = toBuffer(arrayBuffer);
2117
+ if (!compress) {
2118
+ this._state = DEFAULT;
2119
+ this.sendFrame(_Sender.frame(data, options), cb);
2120
+ this.dequeue();
2121
+ } else {
2122
+ this.dispatch(data, compress, options, cb);
2123
+ }
2124
+ }).catch((err) => {
2125
+ process.nextTick(onError, this, err, cb);
2126
+ });
2127
+ }
2128
+ /**
2129
+ * Dispatches a message.
2130
+ *
2131
+ * @param {(Buffer|String)} data The message to send
2132
+ * @param {Boolean} [compress=false] Specifies whether or not to compress
2133
+ * `data`
2134
+ * @param {Object} options Options object
2135
+ * @param {Boolean} [options.fin=false] Specifies whether or not to set the
2136
+ * FIN bit
2137
+ * @param {Function} [options.generateMask] The function used to generate the
2138
+ * masking key
2139
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
2140
+ * `data`
2141
+ * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
2142
+ * key
2143
+ * @param {Number} options.opcode The opcode
2144
+ * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
2145
+ * modified
2146
+ * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
2147
+ * RSV1 bit
2148
+ * @param {Function} [cb] Callback
2149
+ * @private
2150
+ */
2151
+ dispatch(data, compress, options, cb) {
2152
+ if (!compress) {
2153
+ this.sendFrame(_Sender.frame(data, options), cb);
2154
+ return;
2155
+ }
2156
+ const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
2157
+ this._bufferedBytes += options[kByteLength];
2158
+ this._state = DEFLATING;
2159
+ perMessageDeflate.compress(data, options.fin, (_, buf) => {
2160
+ if (this._socket.destroyed) {
2161
+ const err = new Error(
2162
+ "The socket was closed while data was being compressed"
2163
+ );
2164
+ callCallbacks(this, err, cb);
2165
+ return;
2166
+ }
2167
+ this._bufferedBytes -= options[kByteLength];
2168
+ this._state = DEFAULT;
2169
+ options.readOnly = false;
2170
+ this.sendFrame(_Sender.frame(buf, options), cb);
2171
+ this.dequeue();
2172
+ });
2173
+ }
2174
+ /**
2175
+ * Executes queued send operations.
2176
+ *
2177
+ * @private
2178
+ */
2179
+ dequeue() {
2180
+ while (this._state === DEFAULT && this._queue.length) {
2181
+ const params = this._queue.shift();
2182
+ this._bufferedBytes -= params[3][kByteLength];
2183
+ Reflect.apply(params[0], this, params.slice(1));
2184
+ }
2185
+ }
2186
+ /**
2187
+ * Enqueues a send operation.
2188
+ *
2189
+ * @param {Array} params Send operation parameters.
2190
+ * @private
2191
+ */
2192
+ enqueue(params) {
2193
+ this._bufferedBytes += params[3][kByteLength];
2194
+ this._queue.push(params);
2195
+ }
2196
+ /**
2197
+ * Sends a frame.
2198
+ *
2199
+ * @param {Buffer[]} list The frame to send
2200
+ * @param {Function} [cb] Callback
2201
+ * @private
2202
+ */
2203
+ sendFrame(list, cb) {
2204
+ if (list.length === 2) {
2205
+ this._socket.cork();
2206
+ this._socket.write(list[0]);
2207
+ this._socket.write(list[1], cb);
2208
+ this._socket.uncork();
2209
+ } else {
2210
+ this._socket.write(list[0], cb);
2211
+ }
2212
+ }
2213
+ };
2214
+ module.exports = Sender2;
2215
+ function callCallbacks(sender, err, cb) {
2216
+ if (typeof cb === "function")
2217
+ cb(err);
2218
+ for (let i = 0; i < sender._queue.length; i++) {
2219
+ const params = sender._queue[i];
2220
+ const callback = params[params.length - 1];
2221
+ if (typeof callback === "function")
2222
+ callback(err);
2223
+ }
2224
+ }
2225
+ function onError(sender, err, cb) {
2226
+ callCallbacks(sender, err, cb);
2227
+ sender.onerror(err);
2228
+ }
2229
+ }
2230
+ });
2231
+
2232
+ // ../../node_modules/.pnpm/ws@8.18.0_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/event-target.js
2233
+ var require_event_target = __commonJS({
2234
+ "../../node_modules/.pnpm/ws@8.18.0_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/event-target.js"(exports, module) {
2235
+ "use strict";
2236
+ var { kForOnEventAttribute, kListener } = require_constants();
2237
+ var kCode = Symbol("kCode");
2238
+ var kData = Symbol("kData");
2239
+ var kError = Symbol("kError");
2240
+ var kMessage = Symbol("kMessage");
2241
+ var kReason = Symbol("kReason");
2242
+ var kTarget = Symbol("kTarget");
2243
+ var kType = Symbol("kType");
2244
+ var kWasClean = Symbol("kWasClean");
2245
+ var Event = class {
2246
+ /**
2247
+ * Create a new `Event`.
2248
+ *
2249
+ * @param {String} type The name of the event
2250
+ * @throws {TypeError} If the `type` argument is not specified
2251
+ */
2252
+ constructor(type) {
2253
+ this[kTarget] = null;
2254
+ this[kType] = type;
2255
+ }
2256
+ /**
2257
+ * @type {*}
2258
+ */
2259
+ get target() {
2260
+ return this[kTarget];
2261
+ }
2262
+ /**
2263
+ * @type {String}
2264
+ */
2265
+ get type() {
2266
+ return this[kType];
2267
+ }
2268
+ };
2269
+ Object.defineProperty(Event.prototype, "target", { enumerable: true });
2270
+ Object.defineProperty(Event.prototype, "type", { enumerable: true });
2271
+ var CloseEvent = class extends Event {
2272
+ /**
2273
+ * Create a new `CloseEvent`.
2274
+ *
2275
+ * @param {String} type The name of the event
2276
+ * @param {Object} [options] A dictionary object that allows for setting
2277
+ * attributes via object members of the same name
2278
+ * @param {Number} [options.code=0] The status code explaining why the
2279
+ * connection was closed
2280
+ * @param {String} [options.reason=''] A human-readable string explaining why
2281
+ * the connection was closed
2282
+ * @param {Boolean} [options.wasClean=false] Indicates whether or not the
2283
+ * connection was cleanly closed
2284
+ */
2285
+ constructor(type, options = {}) {
2286
+ super(type);
2287
+ this[kCode] = options.code === void 0 ? 0 : options.code;
2288
+ this[kReason] = options.reason === void 0 ? "" : options.reason;
2289
+ this[kWasClean] = options.wasClean === void 0 ? false : options.wasClean;
2290
+ }
2291
+ /**
2292
+ * @type {Number}
2293
+ */
2294
+ get code() {
2295
+ return this[kCode];
2296
+ }
2297
+ /**
2298
+ * @type {String}
2299
+ */
2300
+ get reason() {
2301
+ return this[kReason];
2302
+ }
2303
+ /**
2304
+ * @type {Boolean}
2305
+ */
2306
+ get wasClean() {
2307
+ return this[kWasClean];
2308
+ }
2309
+ };
2310
+ Object.defineProperty(CloseEvent.prototype, "code", { enumerable: true });
2311
+ Object.defineProperty(CloseEvent.prototype, "reason", { enumerable: true });
2312
+ Object.defineProperty(CloseEvent.prototype, "wasClean", { enumerable: true });
2313
+ var ErrorEvent = class extends Event {
2314
+ /**
2315
+ * Create a new `ErrorEvent`.
2316
+ *
2317
+ * @param {String} type The name of the event
2318
+ * @param {Object} [options] A dictionary object that allows for setting
2319
+ * attributes via object members of the same name
2320
+ * @param {*} [options.error=null] The error that generated this event
2321
+ * @param {String} [options.message=''] The error message
2322
+ */
2323
+ constructor(type, options = {}) {
2324
+ super(type);
2325
+ this[kError] = options.error === void 0 ? null : options.error;
2326
+ this[kMessage] = options.message === void 0 ? "" : options.message;
2327
+ }
2328
+ /**
2329
+ * @type {*}
2330
+ */
2331
+ get error() {
2332
+ return this[kError];
2333
+ }
2334
+ /**
2335
+ * @type {String}
2336
+ */
2337
+ get message() {
2338
+ return this[kMessage];
2339
+ }
2340
+ };
2341
+ Object.defineProperty(ErrorEvent.prototype, "error", { enumerable: true });
2342
+ Object.defineProperty(ErrorEvent.prototype, "message", { enumerable: true });
2343
+ var MessageEvent = class extends Event {
2344
+ /**
2345
+ * Create a new `MessageEvent`.
2346
+ *
2347
+ * @param {String} type The name of the event
2348
+ * @param {Object} [options] A dictionary object that allows for setting
2349
+ * attributes via object members of the same name
2350
+ * @param {*} [options.data=null] The message content
2351
+ */
2352
+ constructor(type, options = {}) {
2353
+ super(type);
2354
+ this[kData] = options.data === void 0 ? null : options.data;
2355
+ }
2356
+ /**
2357
+ * @type {*}
2358
+ */
2359
+ get data() {
2360
+ return this[kData];
2361
+ }
2362
+ };
2363
+ Object.defineProperty(MessageEvent.prototype, "data", { enumerable: true });
2364
+ var EventTarget = {
2365
+ /**
2366
+ * Register an event listener.
2367
+ *
2368
+ * @param {String} type A string representing the event type to listen for
2369
+ * @param {(Function|Object)} handler The listener to add
2370
+ * @param {Object} [options] An options object specifies characteristics about
2371
+ * the event listener
2372
+ * @param {Boolean} [options.once=false] A `Boolean` indicating that the
2373
+ * listener should be invoked at most once after being added. If `true`,
2374
+ * the listener would be automatically removed when invoked.
2375
+ * @public
2376
+ */
2377
+ addEventListener(type, handler, options = {}) {
2378
+ for (const listener of this.listeners(type)) {
2379
+ if (!options[kForOnEventAttribute] && listener[kListener] === handler && !listener[kForOnEventAttribute]) {
2380
+ return;
2381
+ }
2382
+ }
2383
+ let wrapper;
2384
+ if (type === "message") {
2385
+ wrapper = function onMessage(data, isBinary) {
2386
+ const event = new MessageEvent("message", {
2387
+ data: isBinary ? data : data.toString()
2388
+ });
2389
+ event[kTarget] = this;
2390
+ callListener(handler, this, event);
2391
+ };
2392
+ } else if (type === "close") {
2393
+ wrapper = function onClose(code, message) {
2394
+ const event = new CloseEvent("close", {
2395
+ code,
2396
+ reason: message.toString(),
2397
+ wasClean: this._closeFrameReceived && this._closeFrameSent
2398
+ });
2399
+ event[kTarget] = this;
2400
+ callListener(handler, this, event);
2401
+ };
2402
+ } else if (type === "error") {
2403
+ wrapper = function onError(error) {
2404
+ const event = new ErrorEvent("error", {
2405
+ error,
2406
+ message: error.message
2407
+ });
2408
+ event[kTarget] = this;
2409
+ callListener(handler, this, event);
2410
+ };
2411
+ } else if (type === "open") {
2412
+ wrapper = function onOpen() {
2413
+ const event = new Event("open");
2414
+ event[kTarget] = this;
2415
+ callListener(handler, this, event);
2416
+ };
2417
+ } else {
2418
+ return;
2419
+ }
2420
+ wrapper[kForOnEventAttribute] = !!options[kForOnEventAttribute];
2421
+ wrapper[kListener] = handler;
2422
+ if (options.once) {
2423
+ this.once(type, wrapper);
2424
+ } else {
2425
+ this.on(type, wrapper);
2426
+ }
2427
+ },
2428
+ /**
2429
+ * Remove an event listener.
2430
+ *
2431
+ * @param {String} type A string representing the event type to remove
2432
+ * @param {(Function|Object)} handler The listener to remove
2433
+ * @public
2434
+ */
2435
+ removeEventListener(type, handler) {
2436
+ for (const listener of this.listeners(type)) {
2437
+ if (listener[kListener] === handler && !listener[kForOnEventAttribute]) {
2438
+ this.removeListener(type, listener);
2439
+ break;
2440
+ }
2441
+ }
2442
+ }
2443
+ };
2444
+ module.exports = {
2445
+ CloseEvent,
2446
+ ErrorEvent,
2447
+ Event,
2448
+ EventTarget,
2449
+ MessageEvent
2450
+ };
2451
+ function callListener(listener, thisArg, event) {
2452
+ if (typeof listener === "object" && listener.handleEvent) {
2453
+ listener.handleEvent.call(listener, event);
2454
+ } else {
2455
+ listener.call(thisArg, event);
2456
+ }
2457
+ }
2458
+ }
2459
+ });
2460
+
2461
+ // ../../node_modules/.pnpm/ws@8.18.0_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/extension.js
2462
+ var require_extension = __commonJS({
2463
+ "../../node_modules/.pnpm/ws@8.18.0_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/extension.js"(exports, module) {
2464
+ "use strict";
2465
+ var { tokenChars } = require_validation();
2466
+ function push(dest, name, elem) {
2467
+ if (dest[name] === void 0)
2468
+ dest[name] = [elem];
2469
+ else
2470
+ dest[name].push(elem);
2471
+ }
2472
+ function parse(header) {
2473
+ const offers = /* @__PURE__ */ Object.create(null);
2474
+ let params = /* @__PURE__ */ Object.create(null);
2475
+ let mustUnescape = false;
2476
+ let isEscaping = false;
2477
+ let inQuotes = false;
2478
+ let extensionName;
2479
+ let paramName;
2480
+ let start = -1;
2481
+ let code = -1;
2482
+ let end = -1;
2483
+ let i = 0;
2484
+ for (; i < header.length; i++) {
2485
+ code = header.charCodeAt(i);
2486
+ if (extensionName === void 0) {
2487
+ if (end === -1 && tokenChars[code] === 1) {
2488
+ if (start === -1)
2489
+ start = i;
2490
+ } else if (i !== 0 && (code === 32 || code === 9)) {
2491
+ if (end === -1 && start !== -1)
2492
+ end = i;
2493
+ } else if (code === 59 || code === 44) {
2494
+ if (start === -1) {
2495
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2496
+ }
2497
+ if (end === -1)
2498
+ end = i;
2499
+ const name = header.slice(start, end);
2500
+ if (code === 44) {
2501
+ push(offers, name, params);
2502
+ params = /* @__PURE__ */ Object.create(null);
2503
+ } else {
2504
+ extensionName = name;
2505
+ }
2506
+ start = end = -1;
2507
+ } else {
2508
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2509
+ }
2510
+ } else if (paramName === void 0) {
2511
+ if (end === -1 && tokenChars[code] === 1) {
2512
+ if (start === -1)
2513
+ start = i;
2514
+ } else if (code === 32 || code === 9) {
2515
+ if (end === -1 && start !== -1)
2516
+ end = i;
2517
+ } else if (code === 59 || code === 44) {
2518
+ if (start === -1) {
2519
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2520
+ }
2521
+ if (end === -1)
2522
+ end = i;
2523
+ push(params, header.slice(start, end), true);
2524
+ if (code === 44) {
2525
+ push(offers, extensionName, params);
2526
+ params = /* @__PURE__ */ Object.create(null);
2527
+ extensionName = void 0;
2528
+ }
2529
+ start = end = -1;
2530
+ } else if (code === 61 && start !== -1 && end === -1) {
2531
+ paramName = header.slice(start, i);
2532
+ start = end = -1;
2533
+ } else {
2534
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2535
+ }
2536
+ } else {
2537
+ if (isEscaping) {
2538
+ if (tokenChars[code] !== 1) {
2539
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2540
+ }
2541
+ if (start === -1)
2542
+ start = i;
2543
+ else if (!mustUnescape)
2544
+ mustUnescape = true;
2545
+ isEscaping = false;
2546
+ } else if (inQuotes) {
2547
+ if (tokenChars[code] === 1) {
2548
+ if (start === -1)
2549
+ start = i;
2550
+ } else if (code === 34 && start !== -1) {
2551
+ inQuotes = false;
2552
+ end = i;
2553
+ } else if (code === 92) {
2554
+ isEscaping = true;
2555
+ } else {
2556
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2557
+ }
2558
+ } else if (code === 34 && header.charCodeAt(i - 1) === 61) {
2559
+ inQuotes = true;
2560
+ } else if (end === -1 && tokenChars[code] === 1) {
2561
+ if (start === -1)
2562
+ start = i;
2563
+ } else if (start !== -1 && (code === 32 || code === 9)) {
2564
+ if (end === -1)
2565
+ end = i;
2566
+ } else if (code === 59 || code === 44) {
2567
+ if (start === -1) {
2568
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2569
+ }
2570
+ if (end === -1)
2571
+ end = i;
2572
+ let value = header.slice(start, end);
2573
+ if (mustUnescape) {
2574
+ value = value.replace(/\\/g, "");
2575
+ mustUnescape = false;
2576
+ }
2577
+ push(params, paramName, value);
2578
+ if (code === 44) {
2579
+ push(offers, extensionName, params);
2580
+ params = /* @__PURE__ */ Object.create(null);
2581
+ extensionName = void 0;
2582
+ }
2583
+ paramName = void 0;
2584
+ start = end = -1;
2585
+ } else {
2586
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2587
+ }
2588
+ }
2589
+ }
2590
+ if (start === -1 || inQuotes || code === 32 || code === 9) {
2591
+ throw new SyntaxError("Unexpected end of input");
2592
+ }
2593
+ if (end === -1)
2594
+ end = i;
2595
+ const token = header.slice(start, end);
2596
+ if (extensionName === void 0) {
2597
+ push(offers, token, params);
2598
+ } else {
2599
+ if (paramName === void 0) {
2600
+ push(params, token, true);
2601
+ } else if (mustUnescape) {
2602
+ push(params, paramName, token.replace(/\\/g, ""));
2603
+ } else {
2604
+ push(params, paramName, token);
2605
+ }
2606
+ push(offers, extensionName, params);
2607
+ }
2608
+ return offers;
2609
+ }
2610
+ function format(extensions) {
2611
+ return Object.keys(extensions).map((extension) => {
2612
+ let configurations = extensions[extension];
2613
+ if (!Array.isArray(configurations))
2614
+ configurations = [configurations];
2615
+ return configurations.map((params) => {
2616
+ return [extension].concat(
2617
+ Object.keys(params).map((k) => {
2618
+ let values = params[k];
2619
+ if (!Array.isArray(values))
2620
+ values = [values];
2621
+ return values.map((v) => v === true ? k : `${k}=${v}`).join("; ");
2622
+ })
2623
+ ).join("; ");
2624
+ }).join(", ");
2625
+ }).join(", ");
2626
+ }
2627
+ module.exports = { format, parse };
2628
+ }
2629
+ });
2630
+
2631
+ // ../../node_modules/.pnpm/ws@8.18.0_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/websocket.js
2632
+ var require_websocket = __commonJS({
2633
+ "../../node_modules/.pnpm/ws@8.18.0_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/websocket.js"(exports, module) {
2634
+ "use strict";
2635
+ var EventEmitter = __require("events");
2636
+ var https = __require("https");
2637
+ var http = __require("http");
2638
+ var net = __require("net");
2639
+ var tls = __require("tls");
2640
+ var { randomBytes, createHash } = __require("crypto");
2641
+ var { Duplex, Readable } = __require("stream");
2642
+ var { URL } = __require("url");
2643
+ var PerMessageDeflate = require_permessage_deflate();
2644
+ var Receiver2 = require_receiver();
2645
+ var Sender2 = require_sender();
2646
+ var { isBlob } = require_validation();
2647
+ var {
2648
+ BINARY_TYPES,
2649
+ EMPTY_BUFFER,
2650
+ GUID,
2651
+ kForOnEventAttribute,
2652
+ kListener,
2653
+ kStatusCode,
2654
+ kWebSocket,
2655
+ NOOP
2656
+ } = require_constants();
2657
+ var {
2658
+ EventTarget: { addEventListener, removeEventListener }
2659
+ } = require_event_target();
2660
+ var { format, parse } = require_extension();
2661
+ var { toBuffer } = require_buffer_util();
2662
+ var closeTimeout = 30 * 1e3;
2663
+ var kAborted = Symbol("kAborted");
2664
+ var protocolVersions = [8, 13];
2665
+ var readyStates = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"];
2666
+ var subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
2667
+ var WebSocket4 = class _WebSocket extends EventEmitter {
2668
+ /**
2669
+ * Create a new `WebSocket`.
2670
+ *
2671
+ * @param {(String|URL)} address The URL to which to connect
2672
+ * @param {(String|String[])} [protocols] The subprotocols
2673
+ * @param {Object} [options] Connection options
2674
+ */
2675
+ constructor(address, protocols, options) {
2676
+ super();
2677
+ this._binaryType = BINARY_TYPES[0];
2678
+ this._closeCode = 1006;
2679
+ this._closeFrameReceived = false;
2680
+ this._closeFrameSent = false;
2681
+ this._closeMessage = EMPTY_BUFFER;
2682
+ this._closeTimer = null;
2683
+ this._errorEmitted = false;
2684
+ this._extensions = {};
2685
+ this._paused = false;
2686
+ this._protocol = "";
2687
+ this._readyState = _WebSocket.CONNECTING;
2688
+ this._receiver = null;
2689
+ this._sender = null;
2690
+ this._socket = null;
2691
+ if (address !== null) {
2692
+ this._bufferedAmount = 0;
2693
+ this._isServer = false;
2694
+ this._redirects = 0;
2695
+ if (protocols === void 0) {
2696
+ protocols = [];
2697
+ } else if (!Array.isArray(protocols)) {
2698
+ if (typeof protocols === "object" && protocols !== null) {
2699
+ options = protocols;
2700
+ protocols = [];
2701
+ } else {
2702
+ protocols = [protocols];
2703
+ }
2704
+ }
2705
+ initAsClient(this, address, protocols, options);
2706
+ } else {
2707
+ this._autoPong = options.autoPong;
2708
+ this._isServer = true;
2709
+ }
2710
+ }
2711
+ /**
2712
+ * For historical reasons, the custom "nodebuffer" type is used by the default
2713
+ * instead of "blob".
2714
+ *
2715
+ * @type {String}
2716
+ */
2717
+ get binaryType() {
2718
+ return this._binaryType;
2719
+ }
2720
+ set binaryType(type) {
2721
+ if (!BINARY_TYPES.includes(type))
2722
+ return;
2723
+ this._binaryType = type;
2724
+ if (this._receiver)
2725
+ this._receiver._binaryType = type;
2726
+ }
2727
+ /**
2728
+ * @type {Number}
2729
+ */
2730
+ get bufferedAmount() {
2731
+ if (!this._socket)
2732
+ return this._bufferedAmount;
2733
+ return this._socket._writableState.length + this._sender._bufferedBytes;
2734
+ }
2735
+ /**
2736
+ * @type {String}
2737
+ */
2738
+ get extensions() {
2739
+ return Object.keys(this._extensions).join();
2740
+ }
2741
+ /**
2742
+ * @type {Boolean}
2743
+ */
2744
+ get isPaused() {
2745
+ return this._paused;
2746
+ }
2747
+ /**
2748
+ * @type {Function}
2749
+ */
2750
+ /* istanbul ignore next */
2751
+ get onclose() {
2752
+ return null;
2753
+ }
2754
+ /**
2755
+ * @type {Function}
2756
+ */
2757
+ /* istanbul ignore next */
2758
+ get onerror() {
2759
+ return null;
2760
+ }
2761
+ /**
2762
+ * @type {Function}
2763
+ */
2764
+ /* istanbul ignore next */
2765
+ get onopen() {
2766
+ return null;
2767
+ }
2768
+ /**
2769
+ * @type {Function}
2770
+ */
2771
+ /* istanbul ignore next */
2772
+ get onmessage() {
2773
+ return null;
2774
+ }
2775
+ /**
2776
+ * @type {String}
2777
+ */
2778
+ get protocol() {
2779
+ return this._protocol;
2780
+ }
2781
+ /**
2782
+ * @type {Number}
2783
+ */
2784
+ get readyState() {
2785
+ return this._readyState;
2786
+ }
2787
+ /**
2788
+ * @type {String}
2789
+ */
2790
+ get url() {
2791
+ return this._url;
2792
+ }
2793
+ /**
2794
+ * Set up the socket and the internal resources.
2795
+ *
2796
+ * @param {Duplex} socket The network socket between the server and client
2797
+ * @param {Buffer} head The first packet of the upgraded stream
2798
+ * @param {Object} options Options object
2799
+ * @param {Boolean} [options.allowSynchronousEvents=false] Specifies whether
2800
+ * any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
2801
+ * multiple times in the same tick
2802
+ * @param {Function} [options.generateMask] The function used to generate the
2803
+ * masking key
2804
+ * @param {Number} [options.maxPayload=0] The maximum allowed message size
2805
+ * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
2806
+ * not to skip UTF-8 validation for text and close messages
2807
+ * @private
2808
+ */
2809
+ setSocket(socket, head, options) {
2810
+ const receiver = new Receiver2({
2811
+ allowSynchronousEvents: options.allowSynchronousEvents,
2812
+ binaryType: this.binaryType,
2813
+ extensions: this._extensions,
2814
+ isServer: this._isServer,
2815
+ maxPayload: options.maxPayload,
2816
+ skipUTF8Validation: options.skipUTF8Validation
2817
+ });
2818
+ const sender = new Sender2(socket, this._extensions, options.generateMask);
2819
+ this._receiver = receiver;
2820
+ this._sender = sender;
2821
+ this._socket = socket;
2822
+ receiver[kWebSocket] = this;
2823
+ sender[kWebSocket] = this;
2824
+ socket[kWebSocket] = this;
2825
+ receiver.on("conclude", receiverOnConclude);
2826
+ receiver.on("drain", receiverOnDrain);
2827
+ receiver.on("error", receiverOnError);
2828
+ receiver.on("message", receiverOnMessage);
2829
+ receiver.on("ping", receiverOnPing);
2830
+ receiver.on("pong", receiverOnPong);
2831
+ sender.onerror = senderOnError;
2832
+ if (socket.setTimeout)
2833
+ socket.setTimeout(0);
2834
+ if (socket.setNoDelay)
2835
+ socket.setNoDelay();
2836
+ if (head.length > 0)
2837
+ socket.unshift(head);
2838
+ socket.on("close", socketOnClose);
2839
+ socket.on("data", socketOnData);
2840
+ socket.on("end", socketOnEnd);
2841
+ socket.on("error", socketOnError);
2842
+ this._readyState = _WebSocket.OPEN;
2843
+ this.emit("open");
2844
+ }
2845
+ /**
2846
+ * Emit the `'close'` event.
2847
+ *
2848
+ * @private
2849
+ */
2850
+ emitClose() {
2851
+ if (!this._socket) {
2852
+ this._readyState = _WebSocket.CLOSED;
2853
+ this.emit("close", this._closeCode, this._closeMessage);
2854
+ return;
2855
+ }
2856
+ if (this._extensions[PerMessageDeflate.extensionName]) {
2857
+ this._extensions[PerMessageDeflate.extensionName].cleanup();
2858
+ }
2859
+ this._receiver.removeAllListeners();
2860
+ this._readyState = _WebSocket.CLOSED;
2861
+ this.emit("close", this._closeCode, this._closeMessage);
2862
+ }
2863
+ /**
2864
+ * Start a closing handshake.
2865
+ *
2866
+ * +----------+ +-----------+ +----------+
2867
+ * - - -|ws.close()|-->|close frame|-->|ws.close()|- - -
2868
+ * | +----------+ +-----------+ +----------+ |
2869
+ * +----------+ +-----------+ |
2870
+ * CLOSING |ws.close()|<--|close frame|<--+-----+ CLOSING
2871
+ * +----------+ +-----------+ |
2872
+ * | | | +---+ |
2873
+ * +------------------------+-->|fin| - - - -
2874
+ * | +---+ | +---+
2875
+ * - - - - -|fin|<---------------------+
2876
+ * +---+
2877
+ *
2878
+ * @param {Number} [code] Status code explaining why the connection is closing
2879
+ * @param {(String|Buffer)} [data] The reason why the connection is
2880
+ * closing
2881
+ * @public
2882
+ */
2883
+ close(code, data) {
2884
+ if (this.readyState === _WebSocket.CLOSED)
2885
+ return;
2886
+ if (this.readyState === _WebSocket.CONNECTING) {
2887
+ const msg = "WebSocket was closed before the connection was established";
2888
+ abortHandshake(this, this._req, msg);
2889
+ return;
2890
+ }
2891
+ if (this.readyState === _WebSocket.CLOSING) {
2892
+ if (this._closeFrameSent && (this._closeFrameReceived || this._receiver._writableState.errorEmitted)) {
2893
+ this._socket.end();
2894
+ }
2895
+ return;
2896
+ }
2897
+ this._readyState = _WebSocket.CLOSING;
2898
+ this._sender.close(code, data, !this._isServer, (err) => {
2899
+ if (err)
2900
+ return;
2901
+ this._closeFrameSent = true;
2902
+ if (this._closeFrameReceived || this._receiver._writableState.errorEmitted) {
2903
+ this._socket.end();
2904
+ }
2905
+ });
2906
+ setCloseTimer(this);
2907
+ }
2908
+ /**
2909
+ * Pause the socket.
2910
+ *
2911
+ * @public
2912
+ */
2913
+ pause() {
2914
+ if (this.readyState === _WebSocket.CONNECTING || this.readyState === _WebSocket.CLOSED) {
2915
+ return;
2916
+ }
2917
+ this._paused = true;
2918
+ this._socket.pause();
2919
+ }
2920
+ /**
2921
+ * Send a ping.
2922
+ *
2923
+ * @param {*} [data] The data to send
2924
+ * @param {Boolean} [mask] Indicates whether or not to mask `data`
2925
+ * @param {Function} [cb] Callback which is executed when the ping is sent
2926
+ * @public
2927
+ */
2928
+ ping(data, mask, cb) {
2929
+ if (this.readyState === _WebSocket.CONNECTING) {
2930
+ throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
2931
+ }
2932
+ if (typeof data === "function") {
2933
+ cb = data;
2934
+ data = mask = void 0;
2935
+ } else if (typeof mask === "function") {
2936
+ cb = mask;
2937
+ mask = void 0;
2938
+ }
2939
+ if (typeof data === "number")
2940
+ data = data.toString();
2941
+ if (this.readyState !== _WebSocket.OPEN) {
2942
+ sendAfterClose(this, data, cb);
2943
+ return;
2944
+ }
2945
+ if (mask === void 0)
2946
+ mask = !this._isServer;
2947
+ this._sender.ping(data || EMPTY_BUFFER, mask, cb);
2948
+ }
2949
+ /**
2950
+ * Send a pong.
2951
+ *
2952
+ * @param {*} [data] The data to send
2953
+ * @param {Boolean} [mask] Indicates whether or not to mask `data`
2954
+ * @param {Function} [cb] Callback which is executed when the pong is sent
2955
+ * @public
2956
+ */
2957
+ pong(data, mask, cb) {
2958
+ if (this.readyState === _WebSocket.CONNECTING) {
2959
+ throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
2960
+ }
2961
+ if (typeof data === "function") {
2962
+ cb = data;
2963
+ data = mask = void 0;
2964
+ } else if (typeof mask === "function") {
2965
+ cb = mask;
2966
+ mask = void 0;
2967
+ }
2968
+ if (typeof data === "number")
2969
+ data = data.toString();
2970
+ if (this.readyState !== _WebSocket.OPEN) {
2971
+ sendAfterClose(this, data, cb);
2972
+ return;
2973
+ }
2974
+ if (mask === void 0)
2975
+ mask = !this._isServer;
2976
+ this._sender.pong(data || EMPTY_BUFFER, mask, cb);
2977
+ }
2978
+ /**
2979
+ * Resume the socket.
2980
+ *
2981
+ * @public
2982
+ */
2983
+ resume() {
2984
+ if (this.readyState === _WebSocket.CONNECTING || this.readyState === _WebSocket.CLOSED) {
2985
+ return;
2986
+ }
2987
+ this._paused = false;
2988
+ if (!this._receiver._writableState.needDrain)
2989
+ this._socket.resume();
2990
+ }
2991
+ /**
2992
+ * Send a data message.
2993
+ *
2994
+ * @param {*} data The message to send
2995
+ * @param {Object} [options] Options object
2996
+ * @param {Boolean} [options.binary] Specifies whether `data` is binary or
2997
+ * text
2998
+ * @param {Boolean} [options.compress] Specifies whether or not to compress
2999
+ * `data`
3000
+ * @param {Boolean} [options.fin=true] Specifies whether the fragment is the
3001
+ * last one
3002
+ * @param {Boolean} [options.mask] Specifies whether or not to mask `data`
3003
+ * @param {Function} [cb] Callback which is executed when data is written out
3004
+ * @public
3005
+ */
3006
+ send(data, options, cb) {
3007
+ if (this.readyState === _WebSocket.CONNECTING) {
3008
+ throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
3009
+ }
3010
+ if (typeof options === "function") {
3011
+ cb = options;
3012
+ options = {};
3013
+ }
3014
+ if (typeof data === "number")
3015
+ data = data.toString();
3016
+ if (this.readyState !== _WebSocket.OPEN) {
3017
+ sendAfterClose(this, data, cb);
3018
+ return;
3019
+ }
3020
+ const opts = {
3021
+ binary: typeof data !== "string",
3022
+ mask: !this._isServer,
3023
+ compress: true,
3024
+ fin: true,
3025
+ ...options
3026
+ };
3027
+ if (!this._extensions[PerMessageDeflate.extensionName]) {
3028
+ opts.compress = false;
3029
+ }
3030
+ this._sender.send(data || EMPTY_BUFFER, opts, cb);
3031
+ }
3032
+ /**
3033
+ * Forcibly close the connection.
3034
+ *
3035
+ * @public
3036
+ */
3037
+ terminate() {
3038
+ if (this.readyState === _WebSocket.CLOSED)
3039
+ return;
3040
+ if (this.readyState === _WebSocket.CONNECTING) {
3041
+ const msg = "WebSocket was closed before the connection was established";
3042
+ abortHandshake(this, this._req, msg);
3043
+ return;
3044
+ }
3045
+ if (this._socket) {
3046
+ this._readyState = _WebSocket.CLOSING;
3047
+ this._socket.destroy();
3048
+ }
3049
+ }
3050
+ };
3051
+ Object.defineProperty(WebSocket4, "CONNECTING", {
3052
+ enumerable: true,
3053
+ value: readyStates.indexOf("CONNECTING")
3054
+ });
3055
+ Object.defineProperty(WebSocket4.prototype, "CONNECTING", {
3056
+ enumerable: true,
3057
+ value: readyStates.indexOf("CONNECTING")
3058
+ });
3059
+ Object.defineProperty(WebSocket4, "OPEN", {
3060
+ enumerable: true,
3061
+ value: readyStates.indexOf("OPEN")
3062
+ });
3063
+ Object.defineProperty(WebSocket4.prototype, "OPEN", {
3064
+ enumerable: true,
3065
+ value: readyStates.indexOf("OPEN")
3066
+ });
3067
+ Object.defineProperty(WebSocket4, "CLOSING", {
3068
+ enumerable: true,
3069
+ value: readyStates.indexOf("CLOSING")
3070
+ });
3071
+ Object.defineProperty(WebSocket4.prototype, "CLOSING", {
3072
+ enumerable: true,
3073
+ value: readyStates.indexOf("CLOSING")
3074
+ });
3075
+ Object.defineProperty(WebSocket4, "CLOSED", {
3076
+ enumerable: true,
3077
+ value: readyStates.indexOf("CLOSED")
3078
+ });
3079
+ Object.defineProperty(WebSocket4.prototype, "CLOSED", {
3080
+ enumerable: true,
3081
+ value: readyStates.indexOf("CLOSED")
3082
+ });
3083
+ [
3084
+ "binaryType",
3085
+ "bufferedAmount",
3086
+ "extensions",
3087
+ "isPaused",
3088
+ "protocol",
3089
+ "readyState",
3090
+ "url"
3091
+ ].forEach((property) => {
3092
+ Object.defineProperty(WebSocket4.prototype, property, { enumerable: true });
3093
+ });
3094
+ ["open", "error", "close", "message"].forEach((method) => {
3095
+ Object.defineProperty(WebSocket4.prototype, `on${method}`, {
3096
+ enumerable: true,
3097
+ get() {
3098
+ for (const listener of this.listeners(method)) {
3099
+ if (listener[kForOnEventAttribute])
3100
+ return listener[kListener];
3101
+ }
3102
+ return null;
3103
+ },
3104
+ set(handler) {
3105
+ for (const listener of this.listeners(method)) {
3106
+ if (listener[kForOnEventAttribute]) {
3107
+ this.removeListener(method, listener);
3108
+ break;
3109
+ }
3110
+ }
3111
+ if (typeof handler !== "function")
3112
+ return;
3113
+ this.addEventListener(method, handler, {
3114
+ [kForOnEventAttribute]: true
3115
+ });
3116
+ }
3117
+ });
3118
+ });
3119
+ WebSocket4.prototype.addEventListener = addEventListener;
3120
+ WebSocket4.prototype.removeEventListener = removeEventListener;
3121
+ module.exports = WebSocket4;
3122
+ function initAsClient(websocket, address, protocols, options) {
3123
+ const opts = {
3124
+ allowSynchronousEvents: true,
3125
+ autoPong: true,
3126
+ protocolVersion: protocolVersions[1],
3127
+ maxPayload: 100 * 1024 * 1024,
3128
+ skipUTF8Validation: false,
3129
+ perMessageDeflate: true,
3130
+ followRedirects: false,
3131
+ maxRedirects: 10,
3132
+ ...options,
3133
+ socketPath: void 0,
3134
+ hostname: void 0,
3135
+ protocol: void 0,
3136
+ timeout: void 0,
3137
+ method: "GET",
3138
+ host: void 0,
3139
+ path: void 0,
3140
+ port: void 0
3141
+ };
3142
+ websocket._autoPong = opts.autoPong;
3143
+ if (!protocolVersions.includes(opts.protocolVersion)) {
3144
+ throw new RangeError(
3145
+ `Unsupported protocol version: ${opts.protocolVersion} (supported versions: ${protocolVersions.join(", ")})`
3146
+ );
3147
+ }
3148
+ let parsedUrl;
3149
+ if (address instanceof URL) {
3150
+ parsedUrl = address;
3151
+ } else {
3152
+ try {
3153
+ parsedUrl = new URL(address);
3154
+ } catch (e) {
3155
+ throw new SyntaxError(`Invalid URL: ${address}`);
3156
+ }
3157
+ }
3158
+ if (parsedUrl.protocol === "http:") {
3159
+ parsedUrl.protocol = "ws:";
3160
+ } else if (parsedUrl.protocol === "https:") {
3161
+ parsedUrl.protocol = "wss:";
3162
+ }
3163
+ websocket._url = parsedUrl.href;
3164
+ const isSecure = parsedUrl.protocol === "wss:";
3165
+ const isIpcUrl = parsedUrl.protocol === "ws+unix:";
3166
+ let invalidUrlMessage;
3167
+ if (parsedUrl.protocol !== "ws:" && !isSecure && !isIpcUrl) {
3168
+ invalidUrlMessage = `The URL's protocol must be one of "ws:", "wss:", "http:", "https", or "ws+unix:"`;
3169
+ } else if (isIpcUrl && !parsedUrl.pathname) {
3170
+ invalidUrlMessage = "The URL's pathname is empty";
3171
+ } else if (parsedUrl.hash) {
3172
+ invalidUrlMessage = "The URL contains a fragment identifier";
3173
+ }
3174
+ if (invalidUrlMessage) {
3175
+ const err = new SyntaxError(invalidUrlMessage);
3176
+ if (websocket._redirects === 0) {
3177
+ throw err;
3178
+ } else {
3179
+ emitErrorAndClose(websocket, err);
3180
+ return;
3181
+ }
3182
+ }
3183
+ const defaultPort = isSecure ? 443 : 80;
3184
+ const key = randomBytes(16).toString("base64");
3185
+ const request = isSecure ? https.request : http.request;
3186
+ const protocolSet = /* @__PURE__ */ new Set();
3187
+ let perMessageDeflate;
3188
+ opts.createConnection = opts.createConnection || (isSecure ? tlsConnect : netConnect);
3189
+ opts.defaultPort = opts.defaultPort || defaultPort;
3190
+ opts.port = parsedUrl.port || defaultPort;
3191
+ opts.host = parsedUrl.hostname.startsWith("[") ? parsedUrl.hostname.slice(1, -1) : parsedUrl.hostname;
3192
+ opts.headers = {
3193
+ ...opts.headers,
3194
+ "Sec-WebSocket-Version": opts.protocolVersion,
3195
+ "Sec-WebSocket-Key": key,
3196
+ Connection: "Upgrade",
3197
+ Upgrade: "websocket"
3198
+ };
3199
+ opts.path = parsedUrl.pathname + parsedUrl.search;
3200
+ opts.timeout = opts.handshakeTimeout;
3201
+ if (opts.perMessageDeflate) {
3202
+ perMessageDeflate = new PerMessageDeflate(
3203
+ opts.perMessageDeflate !== true ? opts.perMessageDeflate : {},
3204
+ false,
3205
+ opts.maxPayload
3206
+ );
3207
+ opts.headers["Sec-WebSocket-Extensions"] = format({
3208
+ [PerMessageDeflate.extensionName]: perMessageDeflate.offer()
3209
+ });
3210
+ }
3211
+ if (protocols.length) {
3212
+ for (const protocol of protocols) {
3213
+ if (typeof protocol !== "string" || !subprotocolRegex.test(protocol) || protocolSet.has(protocol)) {
3214
+ throw new SyntaxError(
3215
+ "An invalid or duplicated subprotocol was specified"
3216
+ );
3217
+ }
3218
+ protocolSet.add(protocol);
3219
+ }
3220
+ opts.headers["Sec-WebSocket-Protocol"] = protocols.join(",");
3221
+ }
3222
+ if (opts.origin) {
3223
+ if (opts.protocolVersion < 13) {
3224
+ opts.headers["Sec-WebSocket-Origin"] = opts.origin;
3225
+ } else {
3226
+ opts.headers.Origin = opts.origin;
3227
+ }
3228
+ }
3229
+ if (parsedUrl.username || parsedUrl.password) {
3230
+ opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
3231
+ }
3232
+ if (isIpcUrl) {
3233
+ const parts = opts.path.split(":");
3234
+ opts.socketPath = parts[0];
3235
+ opts.path = parts[1];
3236
+ }
3237
+ let req;
3238
+ if (opts.followRedirects) {
3239
+ if (websocket._redirects === 0) {
3240
+ websocket._originalIpc = isIpcUrl;
3241
+ websocket._originalSecure = isSecure;
3242
+ websocket._originalHostOrSocketPath = isIpcUrl ? opts.socketPath : parsedUrl.host;
3243
+ const headers = options && options.headers;
3244
+ options = { ...options, headers: {} };
3245
+ if (headers) {
3246
+ for (const [key2, value] of Object.entries(headers)) {
3247
+ options.headers[key2.toLowerCase()] = value;
3248
+ }
3249
+ }
3250
+ } else if (websocket.listenerCount("redirect") === 0) {
3251
+ const isSameHost = isIpcUrl ? websocket._originalIpc ? opts.socketPath === websocket._originalHostOrSocketPath : false : websocket._originalIpc ? false : parsedUrl.host === websocket._originalHostOrSocketPath;
3252
+ if (!isSameHost || websocket._originalSecure && !isSecure) {
3253
+ delete opts.headers.authorization;
3254
+ delete opts.headers.cookie;
3255
+ if (!isSameHost)
3256
+ delete opts.headers.host;
3257
+ opts.auth = void 0;
3258
+ }
3259
+ }
3260
+ if (opts.auth && !options.headers.authorization) {
3261
+ options.headers.authorization = "Basic " + Buffer.from(opts.auth).toString("base64");
3262
+ }
3263
+ req = websocket._req = request(opts);
3264
+ if (websocket._redirects) {
3265
+ websocket.emit("redirect", websocket.url, req);
3266
+ }
3267
+ } else {
3268
+ req = websocket._req = request(opts);
3269
+ }
3270
+ if (opts.timeout) {
3271
+ req.on("timeout", () => {
3272
+ abortHandshake(websocket, req, "Opening handshake has timed out");
3273
+ });
3274
+ }
3275
+ req.on("error", (err) => {
3276
+ if (req === null || req[kAborted])
3277
+ return;
3278
+ req = websocket._req = null;
3279
+ emitErrorAndClose(websocket, err);
3280
+ });
3281
+ req.on("response", (res) => {
3282
+ const location = res.headers.location;
3283
+ const statusCode = res.statusCode;
3284
+ if (location && opts.followRedirects && statusCode >= 300 && statusCode < 400) {
3285
+ if (++websocket._redirects > opts.maxRedirects) {
3286
+ abortHandshake(websocket, req, "Maximum redirects exceeded");
3287
+ return;
3288
+ }
3289
+ req.abort();
3290
+ let addr;
3291
+ try {
3292
+ addr = new URL(location, address);
3293
+ } catch (e) {
3294
+ const err = new SyntaxError(`Invalid URL: ${location}`);
3295
+ emitErrorAndClose(websocket, err);
3296
+ return;
3297
+ }
3298
+ initAsClient(websocket, addr, protocols, options);
3299
+ } else if (!websocket.emit("unexpected-response", req, res)) {
3300
+ abortHandshake(
3301
+ websocket,
3302
+ req,
3303
+ `Unexpected server response: ${res.statusCode}`
3304
+ );
3305
+ }
3306
+ });
3307
+ req.on("upgrade", (res, socket, head) => {
3308
+ websocket.emit("upgrade", res);
3309
+ if (websocket.readyState !== WebSocket4.CONNECTING)
3310
+ return;
3311
+ req = websocket._req = null;
3312
+ const upgrade = res.headers.upgrade;
3313
+ if (upgrade === void 0 || upgrade.toLowerCase() !== "websocket") {
3314
+ abortHandshake(websocket, socket, "Invalid Upgrade header");
3315
+ return;
3316
+ }
3317
+ const digest = createHash("sha1").update(key + GUID).digest("base64");
3318
+ if (res.headers["sec-websocket-accept"] !== digest) {
3319
+ abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
3320
+ return;
3321
+ }
3322
+ const serverProt = res.headers["sec-websocket-protocol"];
3323
+ let protError;
3324
+ if (serverProt !== void 0) {
3325
+ if (!protocolSet.size) {
3326
+ protError = "Server sent a subprotocol but none was requested";
3327
+ } else if (!protocolSet.has(serverProt)) {
3328
+ protError = "Server sent an invalid subprotocol";
3329
+ }
3330
+ } else if (protocolSet.size) {
3331
+ protError = "Server sent no subprotocol";
3332
+ }
3333
+ if (protError) {
3334
+ abortHandshake(websocket, socket, protError);
3335
+ return;
3336
+ }
3337
+ if (serverProt)
3338
+ websocket._protocol = serverProt;
3339
+ const secWebSocketExtensions = res.headers["sec-websocket-extensions"];
3340
+ if (secWebSocketExtensions !== void 0) {
3341
+ if (!perMessageDeflate) {
3342
+ const message = "Server sent a Sec-WebSocket-Extensions header but no extension was requested";
3343
+ abortHandshake(websocket, socket, message);
3344
+ return;
3345
+ }
3346
+ let extensions;
3347
+ try {
3348
+ extensions = parse(secWebSocketExtensions);
3349
+ } catch (err) {
3350
+ const message = "Invalid Sec-WebSocket-Extensions header";
3351
+ abortHandshake(websocket, socket, message);
3352
+ return;
3353
+ }
3354
+ const extensionNames = Object.keys(extensions);
3355
+ if (extensionNames.length !== 1 || extensionNames[0] !== PerMessageDeflate.extensionName) {
3356
+ const message = "Server indicated an extension that was not requested";
3357
+ abortHandshake(websocket, socket, message);
3358
+ return;
3359
+ }
3360
+ try {
3361
+ perMessageDeflate.accept(extensions[PerMessageDeflate.extensionName]);
3362
+ } catch (err) {
3363
+ const message = "Invalid Sec-WebSocket-Extensions header";
3364
+ abortHandshake(websocket, socket, message);
3365
+ return;
3366
+ }
3367
+ websocket._extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
3368
+ }
3369
+ websocket.setSocket(socket, head, {
3370
+ allowSynchronousEvents: opts.allowSynchronousEvents,
3371
+ generateMask: opts.generateMask,
3372
+ maxPayload: opts.maxPayload,
3373
+ skipUTF8Validation: opts.skipUTF8Validation
3374
+ });
3375
+ });
3376
+ if (opts.finishRequest) {
3377
+ opts.finishRequest(req, websocket);
3378
+ } else {
3379
+ req.end();
3380
+ }
3381
+ }
3382
+ function emitErrorAndClose(websocket, err) {
3383
+ websocket._readyState = WebSocket4.CLOSING;
3384
+ websocket._errorEmitted = true;
3385
+ websocket.emit("error", err);
3386
+ websocket.emitClose();
3387
+ }
3388
+ function netConnect(options) {
3389
+ options.path = options.socketPath;
3390
+ return net.connect(options);
3391
+ }
3392
+ function tlsConnect(options) {
3393
+ options.path = void 0;
3394
+ if (!options.servername && options.servername !== "") {
3395
+ options.servername = net.isIP(options.host) ? "" : options.host;
3396
+ }
3397
+ return tls.connect(options);
3398
+ }
3399
+ function abortHandshake(websocket, stream, message) {
3400
+ websocket._readyState = WebSocket4.CLOSING;
3401
+ const err = new Error(message);
3402
+ Error.captureStackTrace(err, abortHandshake);
3403
+ if (stream.setHeader) {
3404
+ stream[kAborted] = true;
3405
+ stream.abort();
3406
+ if (stream.socket && !stream.socket.destroyed) {
3407
+ stream.socket.destroy();
3408
+ }
3409
+ process.nextTick(emitErrorAndClose, websocket, err);
3410
+ } else {
3411
+ stream.destroy(err);
3412
+ stream.once("error", websocket.emit.bind(websocket, "error"));
3413
+ stream.once("close", websocket.emitClose.bind(websocket));
3414
+ }
3415
+ }
3416
+ function sendAfterClose(websocket, data, cb) {
3417
+ if (data) {
3418
+ const length = isBlob(data) ? data.size : toBuffer(data).length;
3419
+ if (websocket._socket)
3420
+ websocket._sender._bufferedBytes += length;
3421
+ else
3422
+ websocket._bufferedAmount += length;
3423
+ }
3424
+ if (cb) {
3425
+ const err = new Error(
3426
+ `WebSocket is not open: readyState ${websocket.readyState} (${readyStates[websocket.readyState]})`
3427
+ );
3428
+ process.nextTick(cb, err);
3429
+ }
3430
+ }
3431
+ function receiverOnConclude(code, reason) {
3432
+ const websocket = this[kWebSocket];
3433
+ websocket._closeFrameReceived = true;
3434
+ websocket._closeMessage = reason;
3435
+ websocket._closeCode = code;
3436
+ if (websocket._socket[kWebSocket] === void 0)
3437
+ return;
3438
+ websocket._socket.removeListener("data", socketOnData);
3439
+ process.nextTick(resume, websocket._socket);
3440
+ if (code === 1005)
3441
+ websocket.close();
3442
+ else
3443
+ websocket.close(code, reason);
3444
+ }
3445
+ function receiverOnDrain() {
3446
+ const websocket = this[kWebSocket];
3447
+ if (!websocket.isPaused)
3448
+ websocket._socket.resume();
3449
+ }
3450
+ function receiverOnError(err) {
3451
+ const websocket = this[kWebSocket];
3452
+ if (websocket._socket[kWebSocket] !== void 0) {
3453
+ websocket._socket.removeListener("data", socketOnData);
3454
+ process.nextTick(resume, websocket._socket);
3455
+ websocket.close(err[kStatusCode]);
3456
+ }
3457
+ if (!websocket._errorEmitted) {
3458
+ websocket._errorEmitted = true;
3459
+ websocket.emit("error", err);
3460
+ }
3461
+ }
3462
+ function receiverOnFinish() {
3463
+ this[kWebSocket].emitClose();
3464
+ }
3465
+ function receiverOnMessage(data, isBinary) {
3466
+ this[kWebSocket].emit("message", data, isBinary);
3467
+ }
3468
+ function receiverOnPing(data) {
3469
+ const websocket = this[kWebSocket];
3470
+ if (websocket._autoPong)
3471
+ websocket.pong(data, !this._isServer, NOOP);
3472
+ websocket.emit("ping", data);
3473
+ }
3474
+ function receiverOnPong(data) {
3475
+ this[kWebSocket].emit("pong", data);
3476
+ }
3477
+ function resume(stream) {
3478
+ stream.resume();
3479
+ }
3480
+ function senderOnError(err) {
3481
+ const websocket = this[kWebSocket];
3482
+ if (websocket.readyState === WebSocket4.CLOSED)
3483
+ return;
3484
+ if (websocket.readyState === WebSocket4.OPEN) {
3485
+ websocket._readyState = WebSocket4.CLOSING;
3486
+ setCloseTimer(websocket);
3487
+ }
3488
+ this._socket.end();
3489
+ if (!websocket._errorEmitted) {
3490
+ websocket._errorEmitted = true;
3491
+ websocket.emit("error", err);
3492
+ }
3493
+ }
3494
+ function setCloseTimer(websocket) {
3495
+ websocket._closeTimer = setTimeout(
3496
+ websocket._socket.destroy.bind(websocket._socket),
3497
+ closeTimeout
3498
+ );
3499
+ }
3500
+ function socketOnClose() {
3501
+ const websocket = this[kWebSocket];
3502
+ this.removeListener("close", socketOnClose);
3503
+ this.removeListener("data", socketOnData);
3504
+ this.removeListener("end", socketOnEnd);
3505
+ websocket._readyState = WebSocket4.CLOSING;
3506
+ let chunk;
3507
+ if (!this._readableState.endEmitted && !websocket._closeFrameReceived && !websocket._receiver._writableState.errorEmitted && (chunk = websocket._socket.read()) !== null) {
3508
+ websocket._receiver.write(chunk);
3509
+ }
3510
+ websocket._receiver.end();
3511
+ this[kWebSocket] = void 0;
3512
+ clearTimeout(websocket._closeTimer);
3513
+ if (websocket._receiver._writableState.finished || websocket._receiver._writableState.errorEmitted) {
3514
+ websocket.emitClose();
3515
+ } else {
3516
+ websocket._receiver.on("error", receiverOnFinish);
3517
+ websocket._receiver.on("finish", receiverOnFinish);
3518
+ }
3519
+ }
3520
+ function socketOnData(chunk) {
3521
+ if (!this[kWebSocket]._receiver.write(chunk)) {
3522
+ this.pause();
3523
+ }
3524
+ }
3525
+ function socketOnEnd() {
3526
+ const websocket = this[kWebSocket];
3527
+ websocket._readyState = WebSocket4.CLOSING;
3528
+ websocket._receiver.end();
3529
+ this.end();
3530
+ }
3531
+ function socketOnError() {
3532
+ const websocket = this[kWebSocket];
3533
+ this.removeListener("error", socketOnError);
3534
+ this.on("error", NOOP);
3535
+ if (websocket) {
3536
+ websocket._readyState = WebSocket4.CLOSING;
3537
+ this.destroy();
3538
+ }
3539
+ }
3540
+ }
3541
+ });
3542
+
3543
+ // ../../node_modules/.pnpm/ws@8.18.0_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/subprotocol.js
3544
+ var require_subprotocol = __commonJS({
3545
+ "../../node_modules/.pnpm/ws@8.18.0_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/subprotocol.js"(exports, module) {
3546
+ "use strict";
3547
+ var { tokenChars } = require_validation();
3548
+ function parse(header) {
3549
+ const protocols = /* @__PURE__ */ new Set();
3550
+ let start = -1;
3551
+ let end = -1;
3552
+ let i = 0;
3553
+ for (i; i < header.length; i++) {
3554
+ const code = header.charCodeAt(i);
3555
+ if (end === -1 && tokenChars[code] === 1) {
3556
+ if (start === -1)
3557
+ start = i;
3558
+ } else if (i !== 0 && (code === 32 || code === 9)) {
3559
+ if (end === -1 && start !== -1)
3560
+ end = i;
3561
+ } else if (code === 44) {
3562
+ if (start === -1) {
3563
+ throw new SyntaxError(`Unexpected character at index ${i}`);
3564
+ }
3565
+ if (end === -1)
3566
+ end = i;
3567
+ const protocol2 = header.slice(start, end);
3568
+ if (protocols.has(protocol2)) {
3569
+ throw new SyntaxError(`The "${protocol2}" subprotocol is duplicated`);
3570
+ }
3571
+ protocols.add(protocol2);
3572
+ start = end = -1;
3573
+ } else {
3574
+ throw new SyntaxError(`Unexpected character at index ${i}`);
3575
+ }
3576
+ }
3577
+ if (start === -1 || end !== -1) {
3578
+ throw new SyntaxError("Unexpected end of input");
3579
+ }
3580
+ const protocol = header.slice(start, i);
3581
+ if (protocols.has(protocol)) {
3582
+ throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
3583
+ }
3584
+ protocols.add(protocol);
3585
+ return protocols;
3586
+ }
3587
+ module.exports = { parse };
3588
+ }
3589
+ });
3590
+
3591
+ // ../../node_modules/.pnpm/ws@8.18.0_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/websocket-server.js
3592
+ var require_websocket_server = __commonJS({
3593
+ "../../node_modules/.pnpm/ws@8.18.0_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/websocket-server.js"(exports, module) {
3594
+ "use strict";
3595
+ var EventEmitter = __require("events");
3596
+ var http = __require("http");
3597
+ var { Duplex } = __require("stream");
3598
+ var { createHash } = __require("crypto");
3599
+ var extension = require_extension();
3600
+ var PerMessageDeflate = require_permessage_deflate();
3601
+ var subprotocol = require_subprotocol();
3602
+ var WebSocket4 = require_websocket();
3603
+ var { GUID, kWebSocket } = require_constants();
3604
+ var keyRegex = /^[+/0-9A-Za-z]{22}==$/;
3605
+ var RUNNING = 0;
3606
+ var CLOSING = 1;
3607
+ var CLOSED = 2;
3608
+ var WebSocketServer2 = class extends EventEmitter {
3609
+ /**
3610
+ * Create a `WebSocketServer` instance.
3611
+ *
3612
+ * @param {Object} options Configuration options
3613
+ * @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether
3614
+ * any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
3615
+ * multiple times in the same tick
3616
+ * @param {Boolean} [options.autoPong=true] Specifies whether or not to
3617
+ * automatically send a pong in response to a ping
3618
+ * @param {Number} [options.backlog=511] The maximum length of the queue of
3619
+ * pending connections
3620
+ * @param {Boolean} [options.clientTracking=true] Specifies whether or not to
3621
+ * track clients
3622
+ * @param {Function} [options.handleProtocols] A hook to handle protocols
3623
+ * @param {String} [options.host] The hostname where to bind the server
3624
+ * @param {Number} [options.maxPayload=104857600] The maximum allowed message
3625
+ * size
3626
+ * @param {Boolean} [options.noServer=false] Enable no server mode
3627
+ * @param {String} [options.path] Accept only connections matching this path
3628
+ * @param {(Boolean|Object)} [options.perMessageDeflate=false] Enable/disable
3629
+ * permessage-deflate
3630
+ * @param {Number} [options.port] The port where to bind the server
3631
+ * @param {(http.Server|https.Server)} [options.server] A pre-created HTTP/S
3632
+ * server to use
3633
+ * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
3634
+ * not to skip UTF-8 validation for text and close messages
3635
+ * @param {Function} [options.verifyClient] A hook to reject connections
3636
+ * @param {Function} [options.WebSocket=WebSocket] Specifies the `WebSocket`
3637
+ * class to use. It must be the `WebSocket` class or class that extends it
3638
+ * @param {Function} [callback] A listener for the `listening` event
3639
+ */
3640
+ constructor(options, callback) {
3641
+ super();
3642
+ options = {
3643
+ allowSynchronousEvents: true,
3644
+ autoPong: true,
3645
+ maxPayload: 100 * 1024 * 1024,
3646
+ skipUTF8Validation: false,
3647
+ perMessageDeflate: false,
3648
+ handleProtocols: null,
3649
+ clientTracking: true,
3650
+ verifyClient: null,
3651
+ noServer: false,
3652
+ backlog: null,
3653
+ // use default (511 as implemented in net.js)
3654
+ server: null,
3655
+ host: null,
3656
+ path: null,
3657
+ port: null,
3658
+ WebSocket: WebSocket4,
3659
+ ...options
3660
+ };
3661
+ if (options.port == null && !options.server && !options.noServer || options.port != null && (options.server || options.noServer) || options.server && options.noServer) {
3662
+ throw new TypeError(
3663
+ 'One and only one of the "port", "server", or "noServer" options must be specified'
3664
+ );
3665
+ }
3666
+ if (options.port != null) {
3667
+ this._server = http.createServer((req, res) => {
3668
+ const body = http.STATUS_CODES[426];
3669
+ res.writeHead(426, {
3670
+ "Content-Length": body.length,
3671
+ "Content-Type": "text/plain"
3672
+ });
3673
+ res.end(body);
3674
+ });
3675
+ this._server.listen(
3676
+ options.port,
3677
+ options.host,
3678
+ options.backlog,
3679
+ callback
3680
+ );
3681
+ } else if (options.server) {
3682
+ this._server = options.server;
3683
+ }
3684
+ if (this._server) {
3685
+ const emitConnection = this.emit.bind(this, "connection");
3686
+ this._removeListeners = addListeners(this._server, {
3687
+ listening: this.emit.bind(this, "listening"),
3688
+ error: this.emit.bind(this, "error"),
3689
+ upgrade: (req, socket, head) => {
3690
+ this.handleUpgrade(req, socket, head, emitConnection);
3691
+ }
3692
+ });
3693
+ }
3694
+ if (options.perMessageDeflate === true)
3695
+ options.perMessageDeflate = {};
3696
+ if (options.clientTracking) {
3697
+ this.clients = /* @__PURE__ */ new Set();
3698
+ this._shouldEmitClose = false;
3699
+ }
3700
+ this.options = options;
3701
+ this._state = RUNNING;
3702
+ }
3703
+ /**
3704
+ * Returns the bound address, the address family name, and port of the server
3705
+ * as reported by the operating system if listening on an IP socket.
3706
+ * If the server is listening on a pipe or UNIX domain socket, the name is
3707
+ * returned as a string.
3708
+ *
3709
+ * @return {(Object|String|null)} The address of the server
3710
+ * @public
3711
+ */
3712
+ address() {
3713
+ if (this.options.noServer) {
3714
+ throw new Error('The server is operating in "noServer" mode');
3715
+ }
3716
+ if (!this._server)
3717
+ return null;
3718
+ return this._server.address();
3719
+ }
3720
+ /**
3721
+ * Stop the server from accepting new connections and emit the `'close'` event
3722
+ * when all existing connections are closed.
3723
+ *
3724
+ * @param {Function} [cb] A one-time listener for the `'close'` event
3725
+ * @public
3726
+ */
3727
+ close(cb) {
3728
+ if (this._state === CLOSED) {
3729
+ if (cb) {
3730
+ this.once("close", () => {
3731
+ cb(new Error("The server is not running"));
3732
+ });
3733
+ }
3734
+ process.nextTick(emitClose, this);
3735
+ return;
3736
+ }
3737
+ if (cb)
3738
+ this.once("close", cb);
3739
+ if (this._state === CLOSING)
3740
+ return;
3741
+ this._state = CLOSING;
3742
+ if (this.options.noServer || this.options.server) {
3743
+ if (this._server) {
3744
+ this._removeListeners();
3745
+ this._removeListeners = this._server = null;
3746
+ }
3747
+ if (this.clients) {
3748
+ if (!this.clients.size) {
3749
+ process.nextTick(emitClose, this);
3750
+ } else {
3751
+ this._shouldEmitClose = true;
3752
+ }
3753
+ } else {
3754
+ process.nextTick(emitClose, this);
3755
+ }
3756
+ } else {
3757
+ const server = this._server;
3758
+ this._removeListeners();
3759
+ this._removeListeners = this._server = null;
3760
+ server.close(() => {
3761
+ emitClose(this);
3762
+ });
3763
+ }
3764
+ }
3765
+ /**
3766
+ * See if a given request should be handled by this server instance.
3767
+ *
3768
+ * @param {http.IncomingMessage} req Request object to inspect
3769
+ * @return {Boolean} `true` if the request is valid, else `false`
3770
+ * @public
3771
+ */
3772
+ shouldHandle(req) {
3773
+ if (this.options.path) {
3774
+ const index = req.url.indexOf("?");
3775
+ const pathname = index !== -1 ? req.url.slice(0, index) : req.url;
3776
+ if (pathname !== this.options.path)
3777
+ return false;
3778
+ }
3779
+ return true;
3780
+ }
3781
+ /**
3782
+ * Handle a HTTP Upgrade request.
3783
+ *
3784
+ * @param {http.IncomingMessage} req The request object
3785
+ * @param {Duplex} socket The network socket between the server and client
3786
+ * @param {Buffer} head The first packet of the upgraded stream
3787
+ * @param {Function} cb Callback
3788
+ * @public
3789
+ */
3790
+ handleUpgrade(req, socket, head, cb) {
3791
+ socket.on("error", socketOnError);
3792
+ const key = req.headers["sec-websocket-key"];
3793
+ const upgrade = req.headers.upgrade;
3794
+ const version = +req.headers["sec-websocket-version"];
3795
+ if (req.method !== "GET") {
3796
+ const message = "Invalid HTTP method";
3797
+ abortHandshakeOrEmitwsClientError(this, req, socket, 405, message);
3798
+ return;
3799
+ }
3800
+ if (upgrade === void 0 || upgrade.toLowerCase() !== "websocket") {
3801
+ const message = "Invalid Upgrade header";
3802
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3803
+ return;
3804
+ }
3805
+ if (key === void 0 || !keyRegex.test(key)) {
3806
+ const message = "Missing or invalid Sec-WebSocket-Key header";
3807
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3808
+ return;
3809
+ }
3810
+ if (version !== 8 && version !== 13) {
3811
+ const message = "Missing or invalid Sec-WebSocket-Version header";
3812
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3813
+ return;
3814
+ }
3815
+ if (!this.shouldHandle(req)) {
3816
+ abortHandshake(socket, 400);
3817
+ return;
3818
+ }
3819
+ const secWebSocketProtocol = req.headers["sec-websocket-protocol"];
3820
+ let protocols = /* @__PURE__ */ new Set();
3821
+ if (secWebSocketProtocol !== void 0) {
3822
+ try {
3823
+ protocols = subprotocol.parse(secWebSocketProtocol);
3824
+ } catch (err) {
3825
+ const message = "Invalid Sec-WebSocket-Protocol header";
3826
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3827
+ return;
3828
+ }
3829
+ }
3830
+ const secWebSocketExtensions = req.headers["sec-websocket-extensions"];
3831
+ const extensions = {};
3832
+ if (this.options.perMessageDeflate && secWebSocketExtensions !== void 0) {
3833
+ const perMessageDeflate = new PerMessageDeflate(
3834
+ this.options.perMessageDeflate,
3835
+ true,
3836
+ this.options.maxPayload
3837
+ );
3838
+ try {
3839
+ const offers = extension.parse(secWebSocketExtensions);
3840
+ if (offers[PerMessageDeflate.extensionName]) {
3841
+ perMessageDeflate.accept(offers[PerMessageDeflate.extensionName]);
3842
+ extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
3843
+ }
3844
+ } catch (err) {
3845
+ const message = "Invalid or unacceptable Sec-WebSocket-Extensions header";
3846
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3847
+ return;
3848
+ }
3849
+ }
3850
+ if (this.options.verifyClient) {
3851
+ const info = {
3852
+ origin: req.headers[`${version === 8 ? "sec-websocket-origin" : "origin"}`],
3853
+ secure: !!(req.socket.authorized || req.socket.encrypted),
3854
+ req
3855
+ };
3856
+ if (this.options.verifyClient.length === 2) {
3857
+ this.options.verifyClient(info, (verified, code, message, headers) => {
3858
+ if (!verified) {
3859
+ return abortHandshake(socket, code || 401, message, headers);
3860
+ }
3861
+ this.completeUpgrade(
3862
+ extensions,
3863
+ key,
3864
+ protocols,
3865
+ req,
3866
+ socket,
3867
+ head,
3868
+ cb
3869
+ );
3870
+ });
3871
+ return;
3872
+ }
3873
+ if (!this.options.verifyClient(info))
3874
+ return abortHandshake(socket, 401);
3875
+ }
3876
+ this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
3877
+ }
3878
+ /**
3879
+ * Upgrade the connection to WebSocket.
3880
+ *
3881
+ * @param {Object} extensions The accepted extensions
3882
+ * @param {String} key The value of the `Sec-WebSocket-Key` header
3883
+ * @param {Set} protocols The subprotocols
3884
+ * @param {http.IncomingMessage} req The request object
3885
+ * @param {Duplex} socket The network socket between the server and client
3886
+ * @param {Buffer} head The first packet of the upgraded stream
3887
+ * @param {Function} cb Callback
3888
+ * @throws {Error} If called more than once with the same socket
3889
+ * @private
3890
+ */
3891
+ completeUpgrade(extensions, key, protocols, req, socket, head, cb) {
3892
+ if (!socket.readable || !socket.writable)
3893
+ return socket.destroy();
3894
+ if (socket[kWebSocket]) {
3895
+ throw new Error(
3896
+ "server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration"
3897
+ );
3898
+ }
3899
+ if (this._state > RUNNING)
3900
+ return abortHandshake(socket, 503);
3901
+ const digest = createHash("sha1").update(key + GUID).digest("base64");
3902
+ const headers = [
3903
+ "HTTP/1.1 101 Switching Protocols",
3904
+ "Upgrade: websocket",
3905
+ "Connection: Upgrade",
3906
+ `Sec-WebSocket-Accept: ${digest}`
3907
+ ];
3908
+ const ws = new this.options.WebSocket(null, void 0, this.options);
3909
+ if (protocols.size) {
3910
+ const protocol = this.options.handleProtocols ? this.options.handleProtocols(protocols, req) : protocols.values().next().value;
3911
+ if (protocol) {
3912
+ headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
3913
+ ws._protocol = protocol;
3914
+ }
3915
+ }
3916
+ if (extensions[PerMessageDeflate.extensionName]) {
3917
+ const params = extensions[PerMessageDeflate.extensionName].params;
3918
+ const value = extension.format({
3919
+ [PerMessageDeflate.extensionName]: [params]
3920
+ });
3921
+ headers.push(`Sec-WebSocket-Extensions: ${value}`);
3922
+ ws._extensions = extensions;
3923
+ }
3924
+ this.emit("headers", headers, req);
3925
+ socket.write(headers.concat("\r\n").join("\r\n"));
3926
+ socket.removeListener("error", socketOnError);
3927
+ ws.setSocket(socket, head, {
3928
+ allowSynchronousEvents: this.options.allowSynchronousEvents,
3929
+ maxPayload: this.options.maxPayload,
3930
+ skipUTF8Validation: this.options.skipUTF8Validation
3931
+ });
3932
+ if (this.clients) {
3933
+ this.clients.add(ws);
3934
+ ws.on("close", () => {
3935
+ this.clients.delete(ws);
3936
+ if (this._shouldEmitClose && !this.clients.size) {
3937
+ process.nextTick(emitClose, this);
3938
+ }
3939
+ });
3940
+ }
3941
+ cb(ws, req);
3942
+ }
3943
+ };
3944
+ module.exports = WebSocketServer2;
3945
+ function addListeners(server, map) {
3946
+ for (const event of Object.keys(map))
3947
+ server.on(event, map[event]);
3948
+ return function removeListeners() {
3949
+ for (const event of Object.keys(map)) {
3950
+ server.removeListener(event, map[event]);
3951
+ }
3952
+ };
3953
+ }
3954
+ function emitClose(server) {
3955
+ server._state = CLOSED;
3956
+ server.emit("close");
3957
+ }
3958
+ function socketOnError() {
3959
+ this.destroy();
3960
+ }
3961
+ function abortHandshake(socket, code, message, headers) {
3962
+ message = message || http.STATUS_CODES[code];
3963
+ headers = {
3964
+ Connection: "close",
3965
+ "Content-Type": "text/html",
3966
+ "Content-Length": Buffer.byteLength(message),
3967
+ ...headers
3968
+ };
3969
+ socket.once("finish", socket.destroy);
3970
+ socket.end(
3971
+ `HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r
3972
+ ` + Object.keys(headers).map((h) => `${h}: ${headers[h]}`).join("\r\n") + "\r\n\r\n" + message
3973
+ );
3974
+ }
3975
+ function abortHandshakeOrEmitwsClientError(server, req, socket, code, message) {
3976
+ if (server.listenerCount("wsClientError")) {
3977
+ const err = new Error(message);
3978
+ Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError);
3979
+ server.emit("wsClientError", err, socket, req);
3980
+ } else {
3981
+ abortHandshake(socket, code, message);
3982
+ }
3983
+ }
3984
+ }
3985
+ });
3986
+
3987
+ // ../../node_modules/.pnpm/ws@8.18.0_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/wrapper.mjs
3988
+ var wrapper_exports = {};
3989
+ __export(wrapper_exports, {
3990
+ Receiver: () => import_receiver.default,
3991
+ Sender: () => import_sender.default,
3992
+ WebSocket: () => import_websocket.default,
3993
+ WebSocketServer: () => import_websocket_server.default,
3994
+ createWebSocketStream: () => import_stream.default,
3995
+ default: () => wrapper_default
3996
+ });
3997
+ var import_stream = __toESM(require_stream(), 1);
3998
+ var import_receiver = __toESM(require_receiver(), 1);
3999
+ var import_sender = __toESM(require_sender(), 1);
4000
+ var import_websocket = __toESM(require_websocket(), 1);
4001
+ var import_websocket_server = __toESM(require_websocket_server(), 1);
4002
+ var wrapper_default = import_websocket.default;
4003
+
4004
+ // ../../node_modules/.pnpm/isows@1.0.6_ws@8.18.0_bufferutil@4.0.8_utf-8-validate@5.0.10_/node_modules/isows/_esm/utils.js
4005
+ function getNativeWebSocket() {
4006
+ if (typeof WebSocket !== "undefined")
4007
+ return WebSocket;
4008
+ if (typeof global.WebSocket !== "undefined")
4009
+ return global.WebSocket;
4010
+ if (typeof window.WebSocket !== "undefined")
4011
+ return window.WebSocket;
4012
+ if (typeof self.WebSocket !== "undefined")
4013
+ return self.WebSocket;
4014
+ throw new Error("`WebSocket` is not supported in this environment");
4015
+ }
4016
+
4017
+ // ../../node_modules/.pnpm/isows@1.0.6_ws@8.18.0_bufferutil@4.0.8_utf-8-validate@5.0.10_/node_modules/isows/_esm/index.js
4018
+ var WebSocket3 = (() => {
4019
+ try {
4020
+ return getNativeWebSocket();
4021
+ } catch {
4022
+ if (import_websocket.default)
4023
+ return import_websocket.default;
4024
+ return wrapper_exports;
4025
+ }
4026
+ })();
4027
+ export {
4028
+ WebSocket3 as WebSocket
4029
+ };
4030
+ //# sourceMappingURL=_esm-JXHAY2EM.js.map