taskin 1.0.8 → 1.0.9

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