anycodex 0.0.12 → 0.0.13

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