@latticexyz/world-module-erc20 2.2.18-f0433092876e2ac9b5b12cd0ecae9c120a2d0368 → 2.2.19-900ac35deebfa260bafb1697d15e95eef855cd69

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