@afterrealism/dendri-client 2.3.7

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.
package/dist/dendri.js ADDED
@@ -0,0 +1,1907 @@
1
+ import { Dendri, DataConnection, logger_default } from './chunk-MJW5M75V.js';
2
+ export { AckManager, BaseConnectionErrorType, BufferedConnection, ConnectionQuality, ConnectionState, ConnectionType, DataConnectionErrorType, Dendri, DendriError, DendriErrorType, HybridConnection, PollingTransport, PresenceManager, RelayEncryption, Room, RpcError, RpcErrorCode, RpcManager, SSETransport, SerializationType, ServerMessageType, SignalingTransport, SocketEventType, TopicManager, TransportMode, createDendriStore, electNewHost, isRpcRequest, isRpcResponse, isTopicEnvelope, util } from './chunk-MJW5M75V.js';
3
+
4
+ // node_modules/.pnpm/@msgpack+msgpack@2.8.0/node_modules/@msgpack/msgpack/dist.es5+esm/utils/int.mjs
5
+ var UINT32_MAX = 4294967295;
6
+ function setUint64(view, offset, value) {
7
+ var high = value / 4294967296;
8
+ var low = value;
9
+ view.setUint32(offset, high);
10
+ view.setUint32(offset + 4, low);
11
+ }
12
+ function setInt64(view, offset, value) {
13
+ var high = Math.floor(value / 4294967296);
14
+ var low = value;
15
+ view.setUint32(offset, high);
16
+ view.setUint32(offset + 4, low);
17
+ }
18
+ function getInt64(view, offset) {
19
+ var high = view.getInt32(offset);
20
+ var low = view.getUint32(offset + 4);
21
+ return high * 4294967296 + low;
22
+ }
23
+ function getUint64(view, offset) {
24
+ var high = view.getUint32(offset);
25
+ var low = view.getUint32(offset + 4);
26
+ return high * 4294967296 + low;
27
+ }
28
+
29
+ // node_modules/.pnpm/@msgpack+msgpack@2.8.0/node_modules/@msgpack/msgpack/dist.es5+esm/utils/utf8.mjs
30
+ var _a;
31
+ var _b;
32
+ var _c;
33
+ var TEXT_ENCODING_AVAILABLE = (typeof process === "undefined" || ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a["TEXT_ENCODING"]) !== "never") && typeof TextEncoder !== "undefined" && typeof TextDecoder !== "undefined";
34
+ function utf8Count(str) {
35
+ var strLength = str.length;
36
+ var byteLength = 0;
37
+ var pos = 0;
38
+ while (pos < strLength) {
39
+ var value = str.charCodeAt(pos++);
40
+ if ((value & 4294967168) === 0) {
41
+ byteLength++;
42
+ continue;
43
+ } else if ((value & 4294965248) === 0) {
44
+ byteLength += 2;
45
+ } else {
46
+ if (value >= 55296 && value <= 56319) {
47
+ if (pos < strLength) {
48
+ var extra = str.charCodeAt(pos);
49
+ if ((extra & 64512) === 56320) {
50
+ ++pos;
51
+ value = ((value & 1023) << 10) + (extra & 1023) + 65536;
52
+ }
53
+ }
54
+ }
55
+ if ((value & 4294901760) === 0) {
56
+ byteLength += 3;
57
+ } else {
58
+ byteLength += 4;
59
+ }
60
+ }
61
+ }
62
+ return byteLength;
63
+ }
64
+ function utf8EncodeJs(str, output, outputOffset) {
65
+ var strLength = str.length;
66
+ var offset = outputOffset;
67
+ var pos = 0;
68
+ while (pos < strLength) {
69
+ var value = str.charCodeAt(pos++);
70
+ if ((value & 4294967168) === 0) {
71
+ output[offset++] = value;
72
+ continue;
73
+ } else if ((value & 4294965248) === 0) {
74
+ output[offset++] = value >> 6 & 31 | 192;
75
+ } else {
76
+ if (value >= 55296 && value <= 56319) {
77
+ if (pos < strLength) {
78
+ var extra = str.charCodeAt(pos);
79
+ if ((extra & 64512) === 56320) {
80
+ ++pos;
81
+ value = ((value & 1023) << 10) + (extra & 1023) + 65536;
82
+ }
83
+ }
84
+ }
85
+ if ((value & 4294901760) === 0) {
86
+ output[offset++] = value >> 12 & 15 | 224;
87
+ output[offset++] = value >> 6 & 63 | 128;
88
+ } else {
89
+ output[offset++] = value >> 18 & 7 | 240;
90
+ output[offset++] = value >> 12 & 63 | 128;
91
+ output[offset++] = value >> 6 & 63 | 128;
92
+ }
93
+ }
94
+ output[offset++] = value & 63 | 128;
95
+ }
96
+ }
97
+ var sharedTextEncoder = TEXT_ENCODING_AVAILABLE ? new TextEncoder() : void 0;
98
+ var TEXT_ENCODER_THRESHOLD = !TEXT_ENCODING_AVAILABLE ? UINT32_MAX : typeof process !== "undefined" && ((_b = process === null || process === void 0 ? void 0 : process.env) === null || _b === void 0 ? void 0 : _b["TEXT_ENCODING"]) !== "force" ? 200 : 0;
99
+ function utf8EncodeTEencode(str, output, outputOffset) {
100
+ output.set(sharedTextEncoder.encode(str), outputOffset);
101
+ }
102
+ function utf8EncodeTEencodeInto(str, output, outputOffset) {
103
+ sharedTextEncoder.encodeInto(str, output.subarray(outputOffset));
104
+ }
105
+ var utf8EncodeTE = (sharedTextEncoder === null || sharedTextEncoder === void 0 ? void 0 : sharedTextEncoder.encodeInto) ? utf8EncodeTEencodeInto : utf8EncodeTEencode;
106
+ var CHUNK_SIZE = 4096;
107
+ function utf8DecodeJs(bytes, inputOffset, byteLength) {
108
+ var offset = inputOffset;
109
+ var end = offset + byteLength;
110
+ var units = [];
111
+ var result = "";
112
+ while (offset < end) {
113
+ var byte1 = bytes[offset++];
114
+ if ((byte1 & 128) === 0) {
115
+ units.push(byte1);
116
+ } else if ((byte1 & 224) === 192) {
117
+ var byte2 = bytes[offset++] & 63;
118
+ units.push((byte1 & 31) << 6 | byte2);
119
+ } else if ((byte1 & 240) === 224) {
120
+ var byte2 = bytes[offset++] & 63;
121
+ var byte3 = bytes[offset++] & 63;
122
+ units.push((byte1 & 31) << 12 | byte2 << 6 | byte3);
123
+ } else if ((byte1 & 248) === 240) {
124
+ var byte2 = bytes[offset++] & 63;
125
+ var byte3 = bytes[offset++] & 63;
126
+ var byte4 = bytes[offset++] & 63;
127
+ var unit = (byte1 & 7) << 18 | byte2 << 12 | byte3 << 6 | byte4;
128
+ if (unit > 65535) {
129
+ unit -= 65536;
130
+ units.push(unit >>> 10 & 1023 | 55296);
131
+ unit = 56320 | unit & 1023;
132
+ }
133
+ units.push(unit);
134
+ } else {
135
+ units.push(byte1);
136
+ }
137
+ if (units.length >= CHUNK_SIZE) {
138
+ result += String.fromCharCode.apply(String, units);
139
+ units.length = 0;
140
+ }
141
+ }
142
+ if (units.length > 0) {
143
+ result += String.fromCharCode.apply(String, units);
144
+ }
145
+ return result;
146
+ }
147
+ var sharedTextDecoder = TEXT_ENCODING_AVAILABLE ? new TextDecoder() : null;
148
+ var TEXT_DECODER_THRESHOLD = !TEXT_ENCODING_AVAILABLE ? UINT32_MAX : typeof process !== "undefined" && ((_c = process === null || process === void 0 ? void 0 : process.env) === null || _c === void 0 ? void 0 : _c["TEXT_DECODER"]) !== "force" ? 200 : 0;
149
+ function utf8DecodeTD(bytes, inputOffset, byteLength) {
150
+ var stringBytes = bytes.subarray(inputOffset, inputOffset + byteLength);
151
+ return sharedTextDecoder.decode(stringBytes);
152
+ }
153
+
154
+ // node_modules/.pnpm/@msgpack+msgpack@2.8.0/node_modules/@msgpack/msgpack/dist.es5+esm/ExtData.mjs
155
+ var ExtData = (
156
+ /** @class */
157
+ /* @__PURE__ */ (function() {
158
+ function ExtData2(type, data) {
159
+ this.type = type;
160
+ this.data = data;
161
+ }
162
+ return ExtData2;
163
+ })()
164
+ );
165
+
166
+ // node_modules/.pnpm/@msgpack+msgpack@2.8.0/node_modules/@msgpack/msgpack/dist.es5+esm/DecodeError.mjs
167
+ var __extends = /* @__PURE__ */ (function() {
168
+ var extendStatics = function(d, b) {
169
+ extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
170
+ d2.__proto__ = b2;
171
+ } || function(d2, b2) {
172
+ for (var p in b2) if (Object.prototype.hasOwnProperty.call(b2, p)) d2[p] = b2[p];
173
+ };
174
+ return extendStatics(d, b);
175
+ };
176
+ return function(d, b) {
177
+ if (typeof b !== "function" && b !== null)
178
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
179
+ extendStatics(d, b);
180
+ function __() {
181
+ this.constructor = d;
182
+ }
183
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
184
+ };
185
+ })();
186
+ var DecodeError = (
187
+ /** @class */
188
+ (function(_super) {
189
+ __extends(DecodeError2, _super);
190
+ function DecodeError2(message) {
191
+ var _this = _super.call(this, message) || this;
192
+ var proto = Object.create(DecodeError2.prototype);
193
+ Object.setPrototypeOf(_this, proto);
194
+ Object.defineProperty(_this, "name", {
195
+ configurable: true,
196
+ enumerable: false,
197
+ value: DecodeError2.name
198
+ });
199
+ return _this;
200
+ }
201
+ return DecodeError2;
202
+ })(Error)
203
+ );
204
+
205
+ // node_modules/.pnpm/@msgpack+msgpack@2.8.0/node_modules/@msgpack/msgpack/dist.es5+esm/timestamp.mjs
206
+ var EXT_TIMESTAMP = -1;
207
+ var TIMESTAMP32_MAX_SEC = 4294967296 - 1;
208
+ var TIMESTAMP64_MAX_SEC = 17179869184 - 1;
209
+ function encodeTimeSpecToTimestamp(_a2) {
210
+ var sec = _a2.sec, nsec = _a2.nsec;
211
+ if (sec >= 0 && nsec >= 0 && sec <= TIMESTAMP64_MAX_SEC) {
212
+ if (nsec === 0 && sec <= TIMESTAMP32_MAX_SEC) {
213
+ var rv = new Uint8Array(4);
214
+ var view = new DataView(rv.buffer);
215
+ view.setUint32(0, sec);
216
+ return rv;
217
+ } else {
218
+ var secHigh = sec / 4294967296;
219
+ var secLow = sec & 4294967295;
220
+ var rv = new Uint8Array(8);
221
+ var view = new DataView(rv.buffer);
222
+ view.setUint32(0, nsec << 2 | secHigh & 3);
223
+ view.setUint32(4, secLow);
224
+ return rv;
225
+ }
226
+ } else {
227
+ var rv = new Uint8Array(12);
228
+ var view = new DataView(rv.buffer);
229
+ view.setUint32(0, nsec);
230
+ setInt64(view, 4, sec);
231
+ return rv;
232
+ }
233
+ }
234
+ function encodeDateToTimeSpec(date) {
235
+ var msec = date.getTime();
236
+ var sec = Math.floor(msec / 1e3);
237
+ var nsec = (msec - sec * 1e3) * 1e6;
238
+ var nsecInSec = Math.floor(nsec / 1e9);
239
+ return {
240
+ sec: sec + nsecInSec,
241
+ nsec: nsec - nsecInSec * 1e9
242
+ };
243
+ }
244
+ function encodeTimestampExtension(object) {
245
+ if (object instanceof Date) {
246
+ var timeSpec = encodeDateToTimeSpec(object);
247
+ return encodeTimeSpecToTimestamp(timeSpec);
248
+ } else {
249
+ return null;
250
+ }
251
+ }
252
+ function decodeTimestampToTimeSpec(data) {
253
+ var view = new DataView(data.buffer, data.byteOffset, data.byteLength);
254
+ switch (data.byteLength) {
255
+ case 4: {
256
+ var sec = view.getUint32(0);
257
+ var nsec = 0;
258
+ return { sec, nsec };
259
+ }
260
+ case 8: {
261
+ var nsec30AndSecHigh2 = view.getUint32(0);
262
+ var secLow32 = view.getUint32(4);
263
+ var sec = (nsec30AndSecHigh2 & 3) * 4294967296 + secLow32;
264
+ var nsec = nsec30AndSecHigh2 >>> 2;
265
+ return { sec, nsec };
266
+ }
267
+ case 12: {
268
+ var sec = getInt64(view, 4);
269
+ var nsec = view.getUint32(0);
270
+ return { sec, nsec };
271
+ }
272
+ default:
273
+ throw new DecodeError("Unrecognized data size for timestamp (expected 4, 8, or 12): ".concat(data.length));
274
+ }
275
+ }
276
+ function decodeTimestampExtension(data) {
277
+ var timeSpec = decodeTimestampToTimeSpec(data);
278
+ return new Date(timeSpec.sec * 1e3 + timeSpec.nsec / 1e6);
279
+ }
280
+ var timestampExtension = {
281
+ type: EXT_TIMESTAMP,
282
+ encode: encodeTimestampExtension,
283
+ decode: decodeTimestampExtension
284
+ };
285
+
286
+ // node_modules/.pnpm/@msgpack+msgpack@2.8.0/node_modules/@msgpack/msgpack/dist.es5+esm/ExtensionCodec.mjs
287
+ var ExtensionCodec = (
288
+ /** @class */
289
+ (function() {
290
+ function ExtensionCodec2() {
291
+ this.builtInEncoders = [];
292
+ this.builtInDecoders = [];
293
+ this.encoders = [];
294
+ this.decoders = [];
295
+ this.register(timestampExtension);
296
+ }
297
+ ExtensionCodec2.prototype.register = function(_a2) {
298
+ var type = _a2.type, encode = _a2.encode, decode = _a2.decode;
299
+ if (type >= 0) {
300
+ this.encoders[type] = encode;
301
+ this.decoders[type] = decode;
302
+ } else {
303
+ var index = 1 + type;
304
+ this.builtInEncoders[index] = encode;
305
+ this.builtInDecoders[index] = decode;
306
+ }
307
+ };
308
+ ExtensionCodec2.prototype.tryToEncode = function(object, context) {
309
+ for (var i = 0; i < this.builtInEncoders.length; i++) {
310
+ var encodeExt = this.builtInEncoders[i];
311
+ if (encodeExt != null) {
312
+ var data = encodeExt(object, context);
313
+ if (data != null) {
314
+ var type = -1 - i;
315
+ return new ExtData(type, data);
316
+ }
317
+ }
318
+ }
319
+ for (var i = 0; i < this.encoders.length; i++) {
320
+ var encodeExt = this.encoders[i];
321
+ if (encodeExt != null) {
322
+ var data = encodeExt(object, context);
323
+ if (data != null) {
324
+ var type = i;
325
+ return new ExtData(type, data);
326
+ }
327
+ }
328
+ }
329
+ if (object instanceof ExtData) {
330
+ return object;
331
+ }
332
+ return null;
333
+ };
334
+ ExtensionCodec2.prototype.decode = function(data, type, context) {
335
+ var decodeExt = type < 0 ? this.builtInDecoders[-1 - type] : this.decoders[type];
336
+ if (decodeExt) {
337
+ return decodeExt(data, type, context);
338
+ } else {
339
+ return new ExtData(type, data);
340
+ }
341
+ };
342
+ ExtensionCodec2.defaultCodec = new ExtensionCodec2();
343
+ return ExtensionCodec2;
344
+ })()
345
+ );
346
+
347
+ // node_modules/.pnpm/@msgpack+msgpack@2.8.0/node_modules/@msgpack/msgpack/dist.es5+esm/utils/typedArrays.mjs
348
+ function ensureUint8Array(buffer) {
349
+ if (buffer instanceof Uint8Array) {
350
+ return buffer;
351
+ } else if (ArrayBuffer.isView(buffer)) {
352
+ return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
353
+ } else if (buffer instanceof ArrayBuffer) {
354
+ return new Uint8Array(buffer);
355
+ } else {
356
+ return Uint8Array.from(buffer);
357
+ }
358
+ }
359
+ function createDataView(buffer) {
360
+ if (buffer instanceof ArrayBuffer) {
361
+ return new DataView(buffer);
362
+ }
363
+ var bufferView = ensureUint8Array(buffer);
364
+ return new DataView(bufferView.buffer, bufferView.byteOffset, bufferView.byteLength);
365
+ }
366
+
367
+ // node_modules/.pnpm/@msgpack+msgpack@2.8.0/node_modules/@msgpack/msgpack/dist.es5+esm/Encoder.mjs
368
+ var DEFAULT_MAX_DEPTH = 100;
369
+ var DEFAULT_INITIAL_BUFFER_SIZE = 2048;
370
+ var Encoder = (
371
+ /** @class */
372
+ (function() {
373
+ function Encoder2(extensionCodec, context, maxDepth, initialBufferSize, sortKeys, forceFloat32, ignoreUndefined, forceIntegerToFloat) {
374
+ if (extensionCodec === void 0) {
375
+ extensionCodec = ExtensionCodec.defaultCodec;
376
+ }
377
+ if (context === void 0) {
378
+ context = void 0;
379
+ }
380
+ if (maxDepth === void 0) {
381
+ maxDepth = DEFAULT_MAX_DEPTH;
382
+ }
383
+ if (initialBufferSize === void 0) {
384
+ initialBufferSize = DEFAULT_INITIAL_BUFFER_SIZE;
385
+ }
386
+ if (sortKeys === void 0) {
387
+ sortKeys = false;
388
+ }
389
+ if (forceFloat32 === void 0) {
390
+ forceFloat32 = false;
391
+ }
392
+ if (ignoreUndefined === void 0) {
393
+ ignoreUndefined = false;
394
+ }
395
+ if (forceIntegerToFloat === void 0) {
396
+ forceIntegerToFloat = false;
397
+ }
398
+ this.extensionCodec = extensionCodec;
399
+ this.context = context;
400
+ this.maxDepth = maxDepth;
401
+ this.initialBufferSize = initialBufferSize;
402
+ this.sortKeys = sortKeys;
403
+ this.forceFloat32 = forceFloat32;
404
+ this.ignoreUndefined = ignoreUndefined;
405
+ this.forceIntegerToFloat = forceIntegerToFloat;
406
+ this.pos = 0;
407
+ this.view = new DataView(new ArrayBuffer(this.initialBufferSize));
408
+ this.bytes = new Uint8Array(this.view.buffer);
409
+ }
410
+ Encoder2.prototype.reinitializeState = function() {
411
+ this.pos = 0;
412
+ };
413
+ Encoder2.prototype.encodeSharedRef = function(object) {
414
+ this.reinitializeState();
415
+ this.doEncode(object, 1);
416
+ return this.bytes.subarray(0, this.pos);
417
+ };
418
+ Encoder2.prototype.encode = function(object) {
419
+ this.reinitializeState();
420
+ this.doEncode(object, 1);
421
+ return this.bytes.slice(0, this.pos);
422
+ };
423
+ Encoder2.prototype.doEncode = function(object, depth) {
424
+ if (depth > this.maxDepth) {
425
+ throw new Error("Too deep objects in depth ".concat(depth));
426
+ }
427
+ if (object == null) {
428
+ this.encodeNil();
429
+ } else if (typeof object === "boolean") {
430
+ this.encodeBoolean(object);
431
+ } else if (typeof object === "number") {
432
+ this.encodeNumber(object);
433
+ } else if (typeof object === "string") {
434
+ this.encodeString(object);
435
+ } else {
436
+ this.encodeObject(object, depth);
437
+ }
438
+ };
439
+ Encoder2.prototype.ensureBufferSizeToWrite = function(sizeToWrite) {
440
+ var requiredSize = this.pos + sizeToWrite;
441
+ if (this.view.byteLength < requiredSize) {
442
+ this.resizeBuffer(requiredSize * 2);
443
+ }
444
+ };
445
+ Encoder2.prototype.resizeBuffer = function(newSize) {
446
+ var newBuffer = new ArrayBuffer(newSize);
447
+ var newBytes = new Uint8Array(newBuffer);
448
+ var newView = new DataView(newBuffer);
449
+ newBytes.set(this.bytes);
450
+ this.view = newView;
451
+ this.bytes = newBytes;
452
+ };
453
+ Encoder2.prototype.encodeNil = function() {
454
+ this.writeU8(192);
455
+ };
456
+ Encoder2.prototype.encodeBoolean = function(object) {
457
+ if (object === false) {
458
+ this.writeU8(194);
459
+ } else {
460
+ this.writeU8(195);
461
+ }
462
+ };
463
+ Encoder2.prototype.encodeNumber = function(object) {
464
+ if (Number.isSafeInteger(object) && !this.forceIntegerToFloat) {
465
+ if (object >= 0) {
466
+ if (object < 128) {
467
+ this.writeU8(object);
468
+ } else if (object < 256) {
469
+ this.writeU8(204);
470
+ this.writeU8(object);
471
+ } else if (object < 65536) {
472
+ this.writeU8(205);
473
+ this.writeU16(object);
474
+ } else if (object < 4294967296) {
475
+ this.writeU8(206);
476
+ this.writeU32(object);
477
+ } else {
478
+ this.writeU8(207);
479
+ this.writeU64(object);
480
+ }
481
+ } else {
482
+ if (object >= -32) {
483
+ this.writeU8(224 | object + 32);
484
+ } else if (object >= -128) {
485
+ this.writeU8(208);
486
+ this.writeI8(object);
487
+ } else if (object >= -32768) {
488
+ this.writeU8(209);
489
+ this.writeI16(object);
490
+ } else if (object >= -2147483648) {
491
+ this.writeU8(210);
492
+ this.writeI32(object);
493
+ } else {
494
+ this.writeU8(211);
495
+ this.writeI64(object);
496
+ }
497
+ }
498
+ } else {
499
+ if (this.forceFloat32) {
500
+ this.writeU8(202);
501
+ this.writeF32(object);
502
+ } else {
503
+ this.writeU8(203);
504
+ this.writeF64(object);
505
+ }
506
+ }
507
+ };
508
+ Encoder2.prototype.writeStringHeader = function(byteLength) {
509
+ if (byteLength < 32) {
510
+ this.writeU8(160 + byteLength);
511
+ } else if (byteLength < 256) {
512
+ this.writeU8(217);
513
+ this.writeU8(byteLength);
514
+ } else if (byteLength < 65536) {
515
+ this.writeU8(218);
516
+ this.writeU16(byteLength);
517
+ } else if (byteLength < 4294967296) {
518
+ this.writeU8(219);
519
+ this.writeU32(byteLength);
520
+ } else {
521
+ throw new Error("Too long string: ".concat(byteLength, " bytes in UTF-8"));
522
+ }
523
+ };
524
+ Encoder2.prototype.encodeString = function(object) {
525
+ var maxHeaderSize = 1 + 4;
526
+ var strLength = object.length;
527
+ if (strLength > TEXT_ENCODER_THRESHOLD) {
528
+ var byteLength = utf8Count(object);
529
+ this.ensureBufferSizeToWrite(maxHeaderSize + byteLength);
530
+ this.writeStringHeader(byteLength);
531
+ utf8EncodeTE(object, this.bytes, this.pos);
532
+ this.pos += byteLength;
533
+ } else {
534
+ var byteLength = utf8Count(object);
535
+ this.ensureBufferSizeToWrite(maxHeaderSize + byteLength);
536
+ this.writeStringHeader(byteLength);
537
+ utf8EncodeJs(object, this.bytes, this.pos);
538
+ this.pos += byteLength;
539
+ }
540
+ };
541
+ Encoder2.prototype.encodeObject = function(object, depth) {
542
+ var ext = this.extensionCodec.tryToEncode(object, this.context);
543
+ if (ext != null) {
544
+ this.encodeExtension(ext);
545
+ } else if (Array.isArray(object)) {
546
+ this.encodeArray(object, depth);
547
+ } else if (ArrayBuffer.isView(object)) {
548
+ this.encodeBinary(object);
549
+ } else if (typeof object === "object") {
550
+ this.encodeMap(object, depth);
551
+ } else {
552
+ throw new Error("Unrecognized object: ".concat(Object.prototype.toString.apply(object)));
553
+ }
554
+ };
555
+ Encoder2.prototype.encodeBinary = function(object) {
556
+ var size = object.byteLength;
557
+ if (size < 256) {
558
+ this.writeU8(196);
559
+ this.writeU8(size);
560
+ } else if (size < 65536) {
561
+ this.writeU8(197);
562
+ this.writeU16(size);
563
+ } else if (size < 4294967296) {
564
+ this.writeU8(198);
565
+ this.writeU32(size);
566
+ } else {
567
+ throw new Error("Too large binary: ".concat(size));
568
+ }
569
+ var bytes = ensureUint8Array(object);
570
+ this.writeU8a(bytes);
571
+ };
572
+ Encoder2.prototype.encodeArray = function(object, depth) {
573
+ var size = object.length;
574
+ if (size < 16) {
575
+ this.writeU8(144 + size);
576
+ } else if (size < 65536) {
577
+ this.writeU8(220);
578
+ this.writeU16(size);
579
+ } else if (size < 4294967296) {
580
+ this.writeU8(221);
581
+ this.writeU32(size);
582
+ } else {
583
+ throw new Error("Too large array: ".concat(size));
584
+ }
585
+ for (var _i = 0, object_1 = object; _i < object_1.length; _i++) {
586
+ var item = object_1[_i];
587
+ this.doEncode(item, depth + 1);
588
+ }
589
+ };
590
+ Encoder2.prototype.countWithoutUndefined = function(object, keys) {
591
+ var count = 0;
592
+ for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
593
+ var key = keys_1[_i];
594
+ if (object[key] !== void 0) {
595
+ count++;
596
+ }
597
+ }
598
+ return count;
599
+ };
600
+ Encoder2.prototype.encodeMap = function(object, depth) {
601
+ var keys = Object.keys(object);
602
+ if (this.sortKeys) {
603
+ keys.sort();
604
+ }
605
+ var size = this.ignoreUndefined ? this.countWithoutUndefined(object, keys) : keys.length;
606
+ if (size < 16) {
607
+ this.writeU8(128 + size);
608
+ } else if (size < 65536) {
609
+ this.writeU8(222);
610
+ this.writeU16(size);
611
+ } else if (size < 4294967296) {
612
+ this.writeU8(223);
613
+ this.writeU32(size);
614
+ } else {
615
+ throw new Error("Too large map object: ".concat(size));
616
+ }
617
+ for (var _i = 0, keys_2 = keys; _i < keys_2.length; _i++) {
618
+ var key = keys_2[_i];
619
+ var value = object[key];
620
+ if (!(this.ignoreUndefined && value === void 0)) {
621
+ this.encodeString(key);
622
+ this.doEncode(value, depth + 1);
623
+ }
624
+ }
625
+ };
626
+ Encoder2.prototype.encodeExtension = function(ext) {
627
+ var size = ext.data.length;
628
+ if (size === 1) {
629
+ this.writeU8(212);
630
+ } else if (size === 2) {
631
+ this.writeU8(213);
632
+ } else if (size === 4) {
633
+ this.writeU8(214);
634
+ } else if (size === 8) {
635
+ this.writeU8(215);
636
+ } else if (size === 16) {
637
+ this.writeU8(216);
638
+ } else if (size < 256) {
639
+ this.writeU8(199);
640
+ this.writeU8(size);
641
+ } else if (size < 65536) {
642
+ this.writeU8(200);
643
+ this.writeU16(size);
644
+ } else if (size < 4294967296) {
645
+ this.writeU8(201);
646
+ this.writeU32(size);
647
+ } else {
648
+ throw new Error("Too large extension object: ".concat(size));
649
+ }
650
+ this.writeI8(ext.type);
651
+ this.writeU8a(ext.data);
652
+ };
653
+ Encoder2.prototype.writeU8 = function(value) {
654
+ this.ensureBufferSizeToWrite(1);
655
+ this.view.setUint8(this.pos, value);
656
+ this.pos++;
657
+ };
658
+ Encoder2.prototype.writeU8a = function(values) {
659
+ var size = values.length;
660
+ this.ensureBufferSizeToWrite(size);
661
+ this.bytes.set(values, this.pos);
662
+ this.pos += size;
663
+ };
664
+ Encoder2.prototype.writeI8 = function(value) {
665
+ this.ensureBufferSizeToWrite(1);
666
+ this.view.setInt8(this.pos, value);
667
+ this.pos++;
668
+ };
669
+ Encoder2.prototype.writeU16 = function(value) {
670
+ this.ensureBufferSizeToWrite(2);
671
+ this.view.setUint16(this.pos, value);
672
+ this.pos += 2;
673
+ };
674
+ Encoder2.prototype.writeI16 = function(value) {
675
+ this.ensureBufferSizeToWrite(2);
676
+ this.view.setInt16(this.pos, value);
677
+ this.pos += 2;
678
+ };
679
+ Encoder2.prototype.writeU32 = function(value) {
680
+ this.ensureBufferSizeToWrite(4);
681
+ this.view.setUint32(this.pos, value);
682
+ this.pos += 4;
683
+ };
684
+ Encoder2.prototype.writeI32 = function(value) {
685
+ this.ensureBufferSizeToWrite(4);
686
+ this.view.setInt32(this.pos, value);
687
+ this.pos += 4;
688
+ };
689
+ Encoder2.prototype.writeF32 = function(value) {
690
+ this.ensureBufferSizeToWrite(4);
691
+ this.view.setFloat32(this.pos, value);
692
+ this.pos += 4;
693
+ };
694
+ Encoder2.prototype.writeF64 = function(value) {
695
+ this.ensureBufferSizeToWrite(8);
696
+ this.view.setFloat64(this.pos, value);
697
+ this.pos += 8;
698
+ };
699
+ Encoder2.prototype.writeU64 = function(value) {
700
+ this.ensureBufferSizeToWrite(8);
701
+ setUint64(this.view, this.pos, value);
702
+ this.pos += 8;
703
+ };
704
+ Encoder2.prototype.writeI64 = function(value) {
705
+ this.ensureBufferSizeToWrite(8);
706
+ setInt64(this.view, this.pos, value);
707
+ this.pos += 8;
708
+ };
709
+ return Encoder2;
710
+ })()
711
+ );
712
+
713
+ // node_modules/.pnpm/@msgpack+msgpack@2.8.0/node_modules/@msgpack/msgpack/dist.es5+esm/utils/prettyByte.mjs
714
+ function prettyByte(byte) {
715
+ return "".concat(byte < 0 ? "-" : "", "0x").concat(Math.abs(byte).toString(16).padStart(2, "0"));
716
+ }
717
+
718
+ // node_modules/.pnpm/@msgpack+msgpack@2.8.0/node_modules/@msgpack/msgpack/dist.es5+esm/CachedKeyDecoder.mjs
719
+ var DEFAULT_MAX_KEY_LENGTH = 16;
720
+ var DEFAULT_MAX_LENGTH_PER_KEY = 16;
721
+ var CachedKeyDecoder = (
722
+ /** @class */
723
+ (function() {
724
+ function CachedKeyDecoder2(maxKeyLength, maxLengthPerKey) {
725
+ if (maxKeyLength === void 0) {
726
+ maxKeyLength = DEFAULT_MAX_KEY_LENGTH;
727
+ }
728
+ if (maxLengthPerKey === void 0) {
729
+ maxLengthPerKey = DEFAULT_MAX_LENGTH_PER_KEY;
730
+ }
731
+ this.maxKeyLength = maxKeyLength;
732
+ this.maxLengthPerKey = maxLengthPerKey;
733
+ this.hit = 0;
734
+ this.miss = 0;
735
+ this.caches = [];
736
+ for (var i = 0; i < this.maxKeyLength; i++) {
737
+ this.caches.push([]);
738
+ }
739
+ }
740
+ CachedKeyDecoder2.prototype.canBeCached = function(byteLength) {
741
+ return byteLength > 0 && byteLength <= this.maxKeyLength;
742
+ };
743
+ CachedKeyDecoder2.prototype.find = function(bytes, inputOffset, byteLength) {
744
+ var records = this.caches[byteLength - 1];
745
+ FIND_CHUNK: for (var _i = 0, records_1 = records; _i < records_1.length; _i++) {
746
+ var record = records_1[_i];
747
+ var recordBytes = record.bytes;
748
+ for (var j = 0; j < byteLength; j++) {
749
+ if (recordBytes[j] !== bytes[inputOffset + j]) {
750
+ continue FIND_CHUNK;
751
+ }
752
+ }
753
+ return record.str;
754
+ }
755
+ return null;
756
+ };
757
+ CachedKeyDecoder2.prototype.store = function(bytes, value) {
758
+ var records = this.caches[bytes.length - 1];
759
+ var record = { bytes, str: value };
760
+ if (records.length >= this.maxLengthPerKey) {
761
+ records[Math.random() * records.length | 0] = record;
762
+ } else {
763
+ records.push(record);
764
+ }
765
+ };
766
+ CachedKeyDecoder2.prototype.decode = function(bytes, inputOffset, byteLength) {
767
+ var cachedValue = this.find(bytes, inputOffset, byteLength);
768
+ if (cachedValue != null) {
769
+ this.hit++;
770
+ return cachedValue;
771
+ }
772
+ this.miss++;
773
+ var str = utf8DecodeJs(bytes, inputOffset, byteLength);
774
+ var slicedCopyOfBytes = Uint8Array.prototype.slice.call(bytes, inputOffset, inputOffset + byteLength);
775
+ this.store(slicedCopyOfBytes, str);
776
+ return str;
777
+ };
778
+ return CachedKeyDecoder2;
779
+ })()
780
+ );
781
+
782
+ // node_modules/.pnpm/@msgpack+msgpack@2.8.0/node_modules/@msgpack/msgpack/dist.es5+esm/Decoder.mjs
783
+ var __awaiter = function(thisArg, _arguments, P, generator) {
784
+ function adopt(value) {
785
+ return value instanceof P ? value : new P(function(resolve) {
786
+ resolve(value);
787
+ });
788
+ }
789
+ return new (P || (P = Promise))(function(resolve, reject) {
790
+ function fulfilled(value) {
791
+ try {
792
+ step(generator.next(value));
793
+ } catch (e) {
794
+ reject(e);
795
+ }
796
+ }
797
+ function rejected(value) {
798
+ try {
799
+ step(generator["throw"](value));
800
+ } catch (e) {
801
+ reject(e);
802
+ }
803
+ }
804
+ function step(result) {
805
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
806
+ }
807
+ step((generator = generator.apply(thisArg, [])).next());
808
+ });
809
+ };
810
+ var __generator = function(thisArg, body) {
811
+ var _ = { label: 0, sent: function() {
812
+ if (t[0] & 1) throw t[1];
813
+ return t[1];
814
+ }, trys: [], ops: [] }, f, y, t, g;
815
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
816
+ return this;
817
+ }), g;
818
+ function verb(n) {
819
+ return function(v) {
820
+ return step([n, v]);
821
+ };
822
+ }
823
+ function step(op) {
824
+ if (f) throw new TypeError("Generator is already executing.");
825
+ while (_) try {
826
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
827
+ if (y = 0, t) op = [op[0] & 2, t.value];
828
+ switch (op[0]) {
829
+ case 0:
830
+ case 1:
831
+ t = op;
832
+ break;
833
+ case 4:
834
+ _.label++;
835
+ return { value: op[1], done: false };
836
+ case 5:
837
+ _.label++;
838
+ y = op[1];
839
+ op = [0];
840
+ continue;
841
+ case 7:
842
+ op = _.ops.pop();
843
+ _.trys.pop();
844
+ continue;
845
+ default:
846
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
847
+ _ = 0;
848
+ continue;
849
+ }
850
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
851
+ _.label = op[1];
852
+ break;
853
+ }
854
+ if (op[0] === 6 && _.label < t[1]) {
855
+ _.label = t[1];
856
+ t = op;
857
+ break;
858
+ }
859
+ if (t && _.label < t[2]) {
860
+ _.label = t[2];
861
+ _.ops.push(op);
862
+ break;
863
+ }
864
+ if (t[2]) _.ops.pop();
865
+ _.trys.pop();
866
+ continue;
867
+ }
868
+ op = body.call(thisArg, _);
869
+ } catch (e) {
870
+ op = [6, e];
871
+ y = 0;
872
+ } finally {
873
+ f = t = 0;
874
+ }
875
+ if (op[0] & 5) throw op[1];
876
+ return { value: op[0] ? op[1] : void 0, done: true };
877
+ }
878
+ };
879
+ var __asyncValues = function(o) {
880
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
881
+ var m = o[Symbol.asyncIterator], i;
882
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() {
883
+ return this;
884
+ }, i);
885
+ function verb(n) {
886
+ i[n] = o[n] && function(v) {
887
+ return new Promise(function(resolve, reject) {
888
+ v = o[n](v), settle(resolve, reject, v.done, v.value);
889
+ });
890
+ };
891
+ }
892
+ function settle(resolve, reject, d, v) {
893
+ Promise.resolve(v).then(function(v2) {
894
+ resolve({ value: v2, done: d });
895
+ }, reject);
896
+ }
897
+ };
898
+ var __await = function(v) {
899
+ return this instanceof __await ? (this.v = v, this) : new __await(v);
900
+ };
901
+ var __asyncGenerator = function(thisArg, _arguments, generator) {
902
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
903
+ var g = generator.apply(thisArg, _arguments || []), i, q = [];
904
+ return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() {
905
+ return this;
906
+ }, i;
907
+ function verb(n) {
908
+ if (g[n]) i[n] = function(v) {
909
+ return new Promise(function(a, b) {
910
+ q.push([n, v, a, b]) > 1 || resume(n, v);
911
+ });
912
+ };
913
+ }
914
+ function resume(n, v) {
915
+ try {
916
+ step(g[n](v));
917
+ } catch (e) {
918
+ settle(q[0][3], e);
919
+ }
920
+ }
921
+ function step(r) {
922
+ r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
923
+ }
924
+ function fulfill(value) {
925
+ resume("next", value);
926
+ }
927
+ function reject(value) {
928
+ resume("throw", value);
929
+ }
930
+ function settle(f, v) {
931
+ if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]);
932
+ }
933
+ };
934
+ var isValidMapKeyType = function(key) {
935
+ var keyType = typeof key;
936
+ return keyType === "string" || keyType === "number";
937
+ };
938
+ var HEAD_BYTE_REQUIRED = -1;
939
+ var EMPTY_VIEW = new DataView(new ArrayBuffer(0));
940
+ var EMPTY_BYTES = new Uint8Array(EMPTY_VIEW.buffer);
941
+ var DataViewIndexOutOfBoundsError = (function() {
942
+ try {
943
+ EMPTY_VIEW.getInt8(0);
944
+ } catch (e) {
945
+ return e.constructor;
946
+ }
947
+ throw new Error("never reached");
948
+ })();
949
+ var MORE_DATA = new DataViewIndexOutOfBoundsError("Insufficient data");
950
+ var sharedCachedKeyDecoder = new CachedKeyDecoder();
951
+ var Decoder = (
952
+ /** @class */
953
+ (function() {
954
+ function Decoder2(extensionCodec, context, maxStrLength, maxBinLength, maxArrayLength, maxMapLength, maxExtLength, keyDecoder) {
955
+ if (extensionCodec === void 0) {
956
+ extensionCodec = ExtensionCodec.defaultCodec;
957
+ }
958
+ if (context === void 0) {
959
+ context = void 0;
960
+ }
961
+ if (maxStrLength === void 0) {
962
+ maxStrLength = UINT32_MAX;
963
+ }
964
+ if (maxBinLength === void 0) {
965
+ maxBinLength = UINT32_MAX;
966
+ }
967
+ if (maxArrayLength === void 0) {
968
+ maxArrayLength = UINT32_MAX;
969
+ }
970
+ if (maxMapLength === void 0) {
971
+ maxMapLength = UINT32_MAX;
972
+ }
973
+ if (maxExtLength === void 0) {
974
+ maxExtLength = UINT32_MAX;
975
+ }
976
+ if (keyDecoder === void 0) {
977
+ keyDecoder = sharedCachedKeyDecoder;
978
+ }
979
+ this.extensionCodec = extensionCodec;
980
+ this.context = context;
981
+ this.maxStrLength = maxStrLength;
982
+ this.maxBinLength = maxBinLength;
983
+ this.maxArrayLength = maxArrayLength;
984
+ this.maxMapLength = maxMapLength;
985
+ this.maxExtLength = maxExtLength;
986
+ this.keyDecoder = keyDecoder;
987
+ this.totalPos = 0;
988
+ this.pos = 0;
989
+ this.view = EMPTY_VIEW;
990
+ this.bytes = EMPTY_BYTES;
991
+ this.headByte = HEAD_BYTE_REQUIRED;
992
+ this.stack = [];
993
+ }
994
+ Decoder2.prototype.reinitializeState = function() {
995
+ this.totalPos = 0;
996
+ this.headByte = HEAD_BYTE_REQUIRED;
997
+ this.stack.length = 0;
998
+ };
999
+ Decoder2.prototype.setBuffer = function(buffer) {
1000
+ this.bytes = ensureUint8Array(buffer);
1001
+ this.view = createDataView(this.bytes);
1002
+ this.pos = 0;
1003
+ };
1004
+ Decoder2.prototype.appendBuffer = function(buffer) {
1005
+ if (this.headByte === HEAD_BYTE_REQUIRED && !this.hasRemaining(1)) {
1006
+ this.setBuffer(buffer);
1007
+ } else {
1008
+ var remainingData = this.bytes.subarray(this.pos);
1009
+ var newData = ensureUint8Array(buffer);
1010
+ var newBuffer = new Uint8Array(remainingData.length + newData.length);
1011
+ newBuffer.set(remainingData);
1012
+ newBuffer.set(newData, remainingData.length);
1013
+ this.setBuffer(newBuffer);
1014
+ }
1015
+ };
1016
+ Decoder2.prototype.hasRemaining = function(size) {
1017
+ return this.view.byteLength - this.pos >= size;
1018
+ };
1019
+ Decoder2.prototype.createExtraByteError = function(posToShow) {
1020
+ var _a2 = this, view = _a2.view, pos = _a2.pos;
1021
+ return new RangeError("Extra ".concat(view.byteLength - pos, " of ").concat(view.byteLength, " byte(s) found at buffer[").concat(posToShow, "]"));
1022
+ };
1023
+ Decoder2.prototype.decode = function(buffer) {
1024
+ this.reinitializeState();
1025
+ this.setBuffer(buffer);
1026
+ var object = this.doDecodeSync();
1027
+ if (this.hasRemaining(1)) {
1028
+ throw this.createExtraByteError(this.pos);
1029
+ }
1030
+ return object;
1031
+ };
1032
+ Decoder2.prototype.decodeMulti = function(buffer) {
1033
+ return __generator(this, function(_a2) {
1034
+ switch (_a2.label) {
1035
+ case 0:
1036
+ this.reinitializeState();
1037
+ this.setBuffer(buffer);
1038
+ _a2.label = 1;
1039
+ case 1:
1040
+ if (!this.hasRemaining(1)) return [3, 3];
1041
+ return [4, this.doDecodeSync()];
1042
+ case 2:
1043
+ _a2.sent();
1044
+ return [3, 1];
1045
+ case 3:
1046
+ return [
1047
+ 2
1048
+ /*return*/
1049
+ ];
1050
+ }
1051
+ });
1052
+ };
1053
+ Decoder2.prototype.decodeAsync = function(stream) {
1054
+ var stream_1, stream_1_1;
1055
+ var e_1, _a2;
1056
+ return __awaiter(this, void 0, void 0, function() {
1057
+ var decoded, object, buffer, e_1_1, _b2, headByte, pos, totalPos;
1058
+ return __generator(this, function(_c2) {
1059
+ switch (_c2.label) {
1060
+ case 0:
1061
+ decoded = false;
1062
+ _c2.label = 1;
1063
+ case 1:
1064
+ _c2.trys.push([1, 6, 7, 12]);
1065
+ stream_1 = __asyncValues(stream);
1066
+ _c2.label = 2;
1067
+ case 2:
1068
+ return [4, stream_1.next()];
1069
+ case 3:
1070
+ if (!(stream_1_1 = _c2.sent(), !stream_1_1.done)) return [3, 5];
1071
+ buffer = stream_1_1.value;
1072
+ if (decoded) {
1073
+ throw this.createExtraByteError(this.totalPos);
1074
+ }
1075
+ this.appendBuffer(buffer);
1076
+ try {
1077
+ object = this.doDecodeSync();
1078
+ decoded = true;
1079
+ } catch (e) {
1080
+ if (!(e instanceof DataViewIndexOutOfBoundsError)) {
1081
+ throw e;
1082
+ }
1083
+ }
1084
+ this.totalPos += this.pos;
1085
+ _c2.label = 4;
1086
+ case 4:
1087
+ return [3, 2];
1088
+ case 5:
1089
+ return [3, 12];
1090
+ case 6:
1091
+ e_1_1 = _c2.sent();
1092
+ e_1 = { error: e_1_1 };
1093
+ return [3, 12];
1094
+ case 7:
1095
+ _c2.trys.push([7, , 10, 11]);
1096
+ if (!(stream_1_1 && !stream_1_1.done && (_a2 = stream_1.return))) return [3, 9];
1097
+ return [4, _a2.call(stream_1)];
1098
+ case 8:
1099
+ _c2.sent();
1100
+ _c2.label = 9;
1101
+ case 9:
1102
+ return [3, 11];
1103
+ case 10:
1104
+ if (e_1) throw e_1.error;
1105
+ return [
1106
+ 7
1107
+ /*endfinally*/
1108
+ ];
1109
+ case 11:
1110
+ return [
1111
+ 7
1112
+ /*endfinally*/
1113
+ ];
1114
+ case 12:
1115
+ if (decoded) {
1116
+ if (this.hasRemaining(1)) {
1117
+ throw this.createExtraByteError(this.totalPos);
1118
+ }
1119
+ return [2, object];
1120
+ }
1121
+ _b2 = this, headByte = _b2.headByte, pos = _b2.pos, totalPos = _b2.totalPos;
1122
+ throw new RangeError("Insufficient data in parsing ".concat(prettyByte(headByte), " at ").concat(totalPos, " (").concat(pos, " in the current buffer)"));
1123
+ }
1124
+ });
1125
+ });
1126
+ };
1127
+ Decoder2.prototype.decodeArrayStream = function(stream) {
1128
+ return this.decodeMultiAsync(stream, true);
1129
+ };
1130
+ Decoder2.prototype.decodeStream = function(stream) {
1131
+ return this.decodeMultiAsync(stream, false);
1132
+ };
1133
+ Decoder2.prototype.decodeMultiAsync = function(stream, isArray) {
1134
+ return __asyncGenerator(this, arguments, function decodeMultiAsync_1() {
1135
+ var isArrayHeaderRequired, arrayItemsLeft, stream_2, stream_2_1, buffer, e_2, e_3_1;
1136
+ var e_3, _a2;
1137
+ return __generator(this, function(_b2) {
1138
+ switch (_b2.label) {
1139
+ case 0:
1140
+ isArrayHeaderRequired = isArray;
1141
+ arrayItemsLeft = -1;
1142
+ _b2.label = 1;
1143
+ case 1:
1144
+ _b2.trys.push([1, 13, 14, 19]);
1145
+ stream_2 = __asyncValues(stream);
1146
+ _b2.label = 2;
1147
+ case 2:
1148
+ return [4, __await(stream_2.next())];
1149
+ case 3:
1150
+ if (!(stream_2_1 = _b2.sent(), !stream_2_1.done)) return [3, 12];
1151
+ buffer = stream_2_1.value;
1152
+ if (isArray && arrayItemsLeft === 0) {
1153
+ throw this.createExtraByteError(this.totalPos);
1154
+ }
1155
+ this.appendBuffer(buffer);
1156
+ if (isArrayHeaderRequired) {
1157
+ arrayItemsLeft = this.readArraySize();
1158
+ isArrayHeaderRequired = false;
1159
+ this.complete();
1160
+ }
1161
+ _b2.label = 4;
1162
+ case 4:
1163
+ _b2.trys.push([4, 9, , 10]);
1164
+ _b2.label = 5;
1165
+ case 5:
1166
+ return [4, __await(this.doDecodeSync())];
1167
+ case 6:
1168
+ return [4, _b2.sent()];
1169
+ case 7:
1170
+ _b2.sent();
1171
+ if (--arrayItemsLeft === 0) {
1172
+ return [3, 8];
1173
+ }
1174
+ return [3, 5];
1175
+ case 8:
1176
+ return [3, 10];
1177
+ case 9:
1178
+ e_2 = _b2.sent();
1179
+ if (!(e_2 instanceof DataViewIndexOutOfBoundsError)) {
1180
+ throw e_2;
1181
+ }
1182
+ return [3, 10];
1183
+ case 10:
1184
+ this.totalPos += this.pos;
1185
+ _b2.label = 11;
1186
+ case 11:
1187
+ return [3, 2];
1188
+ case 12:
1189
+ return [3, 19];
1190
+ case 13:
1191
+ e_3_1 = _b2.sent();
1192
+ e_3 = { error: e_3_1 };
1193
+ return [3, 19];
1194
+ case 14:
1195
+ _b2.trys.push([14, , 17, 18]);
1196
+ if (!(stream_2_1 && !stream_2_1.done && (_a2 = stream_2.return))) return [3, 16];
1197
+ return [4, __await(_a2.call(stream_2))];
1198
+ case 15:
1199
+ _b2.sent();
1200
+ _b2.label = 16;
1201
+ case 16:
1202
+ return [3, 18];
1203
+ case 17:
1204
+ if (e_3) throw e_3.error;
1205
+ return [
1206
+ 7
1207
+ /*endfinally*/
1208
+ ];
1209
+ case 18:
1210
+ return [
1211
+ 7
1212
+ /*endfinally*/
1213
+ ];
1214
+ case 19:
1215
+ return [
1216
+ 2
1217
+ /*return*/
1218
+ ];
1219
+ }
1220
+ });
1221
+ });
1222
+ };
1223
+ Decoder2.prototype.doDecodeSync = function() {
1224
+ DECODE: while (true) {
1225
+ var headByte = this.readHeadByte();
1226
+ var object = void 0;
1227
+ if (headByte >= 224) {
1228
+ object = headByte - 256;
1229
+ } else if (headByte < 192) {
1230
+ if (headByte < 128) {
1231
+ object = headByte;
1232
+ } else if (headByte < 144) {
1233
+ var size = headByte - 128;
1234
+ if (size !== 0) {
1235
+ this.pushMapState(size);
1236
+ this.complete();
1237
+ continue DECODE;
1238
+ } else {
1239
+ object = {};
1240
+ }
1241
+ } else if (headByte < 160) {
1242
+ var size = headByte - 144;
1243
+ if (size !== 0) {
1244
+ this.pushArrayState(size);
1245
+ this.complete();
1246
+ continue DECODE;
1247
+ } else {
1248
+ object = [];
1249
+ }
1250
+ } else {
1251
+ var byteLength = headByte - 160;
1252
+ object = this.decodeUtf8String(byteLength, 0);
1253
+ }
1254
+ } else if (headByte === 192) {
1255
+ object = null;
1256
+ } else if (headByte === 194) {
1257
+ object = false;
1258
+ } else if (headByte === 195) {
1259
+ object = true;
1260
+ } else if (headByte === 202) {
1261
+ object = this.readF32();
1262
+ } else if (headByte === 203) {
1263
+ object = this.readF64();
1264
+ } else if (headByte === 204) {
1265
+ object = this.readU8();
1266
+ } else if (headByte === 205) {
1267
+ object = this.readU16();
1268
+ } else if (headByte === 206) {
1269
+ object = this.readU32();
1270
+ } else if (headByte === 207) {
1271
+ object = this.readU64();
1272
+ } else if (headByte === 208) {
1273
+ object = this.readI8();
1274
+ } else if (headByte === 209) {
1275
+ object = this.readI16();
1276
+ } else if (headByte === 210) {
1277
+ object = this.readI32();
1278
+ } else if (headByte === 211) {
1279
+ object = this.readI64();
1280
+ } else if (headByte === 217) {
1281
+ var byteLength = this.lookU8();
1282
+ object = this.decodeUtf8String(byteLength, 1);
1283
+ } else if (headByte === 218) {
1284
+ var byteLength = this.lookU16();
1285
+ object = this.decodeUtf8String(byteLength, 2);
1286
+ } else if (headByte === 219) {
1287
+ var byteLength = this.lookU32();
1288
+ object = this.decodeUtf8String(byteLength, 4);
1289
+ } else if (headByte === 220) {
1290
+ var size = this.readU16();
1291
+ if (size !== 0) {
1292
+ this.pushArrayState(size);
1293
+ this.complete();
1294
+ continue DECODE;
1295
+ } else {
1296
+ object = [];
1297
+ }
1298
+ } else if (headByte === 221) {
1299
+ var size = this.readU32();
1300
+ if (size !== 0) {
1301
+ this.pushArrayState(size);
1302
+ this.complete();
1303
+ continue DECODE;
1304
+ } else {
1305
+ object = [];
1306
+ }
1307
+ } else if (headByte === 222) {
1308
+ var size = this.readU16();
1309
+ if (size !== 0) {
1310
+ this.pushMapState(size);
1311
+ this.complete();
1312
+ continue DECODE;
1313
+ } else {
1314
+ object = {};
1315
+ }
1316
+ } else if (headByte === 223) {
1317
+ var size = this.readU32();
1318
+ if (size !== 0) {
1319
+ this.pushMapState(size);
1320
+ this.complete();
1321
+ continue DECODE;
1322
+ } else {
1323
+ object = {};
1324
+ }
1325
+ } else if (headByte === 196) {
1326
+ var size = this.lookU8();
1327
+ object = this.decodeBinary(size, 1);
1328
+ } else if (headByte === 197) {
1329
+ var size = this.lookU16();
1330
+ object = this.decodeBinary(size, 2);
1331
+ } else if (headByte === 198) {
1332
+ var size = this.lookU32();
1333
+ object = this.decodeBinary(size, 4);
1334
+ } else if (headByte === 212) {
1335
+ object = this.decodeExtension(1, 0);
1336
+ } else if (headByte === 213) {
1337
+ object = this.decodeExtension(2, 0);
1338
+ } else if (headByte === 214) {
1339
+ object = this.decodeExtension(4, 0);
1340
+ } else if (headByte === 215) {
1341
+ object = this.decodeExtension(8, 0);
1342
+ } else if (headByte === 216) {
1343
+ object = this.decodeExtension(16, 0);
1344
+ } else if (headByte === 199) {
1345
+ var size = this.lookU8();
1346
+ object = this.decodeExtension(size, 1);
1347
+ } else if (headByte === 200) {
1348
+ var size = this.lookU16();
1349
+ object = this.decodeExtension(size, 2);
1350
+ } else if (headByte === 201) {
1351
+ var size = this.lookU32();
1352
+ object = this.decodeExtension(size, 4);
1353
+ } else {
1354
+ throw new DecodeError("Unrecognized type byte: ".concat(prettyByte(headByte)));
1355
+ }
1356
+ this.complete();
1357
+ var stack = this.stack;
1358
+ while (stack.length > 0) {
1359
+ var state = stack[stack.length - 1];
1360
+ if (state.type === 0) {
1361
+ state.array[state.position] = object;
1362
+ state.position++;
1363
+ if (state.position === state.size) {
1364
+ stack.pop();
1365
+ object = state.array;
1366
+ } else {
1367
+ continue DECODE;
1368
+ }
1369
+ } else if (state.type === 1) {
1370
+ if (!isValidMapKeyType(object)) {
1371
+ throw new DecodeError("The type of key must be string or number but " + typeof object);
1372
+ }
1373
+ if (object === "__proto__") {
1374
+ throw new DecodeError("The key __proto__ is not allowed");
1375
+ }
1376
+ state.key = object;
1377
+ state.type = 2;
1378
+ continue DECODE;
1379
+ } else {
1380
+ state.map[state.key] = object;
1381
+ state.readCount++;
1382
+ if (state.readCount === state.size) {
1383
+ stack.pop();
1384
+ object = state.map;
1385
+ } else {
1386
+ state.key = null;
1387
+ state.type = 1;
1388
+ continue DECODE;
1389
+ }
1390
+ }
1391
+ }
1392
+ return object;
1393
+ }
1394
+ };
1395
+ Decoder2.prototype.readHeadByte = function() {
1396
+ if (this.headByte === HEAD_BYTE_REQUIRED) {
1397
+ this.headByte = this.readU8();
1398
+ }
1399
+ return this.headByte;
1400
+ };
1401
+ Decoder2.prototype.complete = function() {
1402
+ this.headByte = HEAD_BYTE_REQUIRED;
1403
+ };
1404
+ Decoder2.prototype.readArraySize = function() {
1405
+ var headByte = this.readHeadByte();
1406
+ switch (headByte) {
1407
+ case 220:
1408
+ return this.readU16();
1409
+ case 221:
1410
+ return this.readU32();
1411
+ default: {
1412
+ if (headByte < 160) {
1413
+ return headByte - 144;
1414
+ } else {
1415
+ throw new DecodeError("Unrecognized array type byte: ".concat(prettyByte(headByte)));
1416
+ }
1417
+ }
1418
+ }
1419
+ };
1420
+ Decoder2.prototype.pushMapState = function(size) {
1421
+ if (size > this.maxMapLength) {
1422
+ throw new DecodeError("Max length exceeded: map length (".concat(size, ") > maxMapLengthLength (").concat(this.maxMapLength, ")"));
1423
+ }
1424
+ this.stack.push({
1425
+ type: 1,
1426
+ size,
1427
+ key: null,
1428
+ readCount: 0,
1429
+ map: {}
1430
+ });
1431
+ };
1432
+ Decoder2.prototype.pushArrayState = function(size) {
1433
+ if (size > this.maxArrayLength) {
1434
+ throw new DecodeError("Max length exceeded: array length (".concat(size, ") > maxArrayLength (").concat(this.maxArrayLength, ")"));
1435
+ }
1436
+ this.stack.push({
1437
+ type: 0,
1438
+ size,
1439
+ array: new Array(size),
1440
+ position: 0
1441
+ });
1442
+ };
1443
+ Decoder2.prototype.decodeUtf8String = function(byteLength, headerOffset) {
1444
+ var _a2;
1445
+ if (byteLength > this.maxStrLength) {
1446
+ throw new DecodeError("Max length exceeded: UTF-8 byte length (".concat(byteLength, ") > maxStrLength (").concat(this.maxStrLength, ")"));
1447
+ }
1448
+ if (this.bytes.byteLength < this.pos + headerOffset + byteLength) {
1449
+ throw MORE_DATA;
1450
+ }
1451
+ var offset = this.pos + headerOffset;
1452
+ var object;
1453
+ if (this.stateIsMapKey() && ((_a2 = this.keyDecoder) === null || _a2 === void 0 ? void 0 : _a2.canBeCached(byteLength))) {
1454
+ object = this.keyDecoder.decode(this.bytes, offset, byteLength);
1455
+ } else if (byteLength > TEXT_DECODER_THRESHOLD) {
1456
+ object = utf8DecodeTD(this.bytes, offset, byteLength);
1457
+ } else {
1458
+ object = utf8DecodeJs(this.bytes, offset, byteLength);
1459
+ }
1460
+ this.pos += headerOffset + byteLength;
1461
+ return object;
1462
+ };
1463
+ Decoder2.prototype.stateIsMapKey = function() {
1464
+ if (this.stack.length > 0) {
1465
+ var state = this.stack[this.stack.length - 1];
1466
+ return state.type === 1;
1467
+ }
1468
+ return false;
1469
+ };
1470
+ Decoder2.prototype.decodeBinary = function(byteLength, headOffset) {
1471
+ if (byteLength > this.maxBinLength) {
1472
+ throw new DecodeError("Max length exceeded: bin length (".concat(byteLength, ") > maxBinLength (").concat(this.maxBinLength, ")"));
1473
+ }
1474
+ if (!this.hasRemaining(byteLength + headOffset)) {
1475
+ throw MORE_DATA;
1476
+ }
1477
+ var offset = this.pos + headOffset;
1478
+ var object = this.bytes.subarray(offset, offset + byteLength);
1479
+ this.pos += headOffset + byteLength;
1480
+ return object;
1481
+ };
1482
+ Decoder2.prototype.decodeExtension = function(size, headOffset) {
1483
+ if (size > this.maxExtLength) {
1484
+ throw new DecodeError("Max length exceeded: ext length (".concat(size, ") > maxExtLength (").concat(this.maxExtLength, ")"));
1485
+ }
1486
+ var extType = this.view.getInt8(this.pos + headOffset);
1487
+ var data = this.decodeBinary(
1488
+ size,
1489
+ headOffset + 1
1490
+ /* extType */
1491
+ );
1492
+ return this.extensionCodec.decode(data, extType, this.context);
1493
+ };
1494
+ Decoder2.prototype.lookU8 = function() {
1495
+ return this.view.getUint8(this.pos);
1496
+ };
1497
+ Decoder2.prototype.lookU16 = function() {
1498
+ return this.view.getUint16(this.pos);
1499
+ };
1500
+ Decoder2.prototype.lookU32 = function() {
1501
+ return this.view.getUint32(this.pos);
1502
+ };
1503
+ Decoder2.prototype.readU8 = function() {
1504
+ var value = this.view.getUint8(this.pos);
1505
+ this.pos++;
1506
+ return value;
1507
+ };
1508
+ Decoder2.prototype.readI8 = function() {
1509
+ var value = this.view.getInt8(this.pos);
1510
+ this.pos++;
1511
+ return value;
1512
+ };
1513
+ Decoder2.prototype.readU16 = function() {
1514
+ var value = this.view.getUint16(this.pos);
1515
+ this.pos += 2;
1516
+ return value;
1517
+ };
1518
+ Decoder2.prototype.readI16 = function() {
1519
+ var value = this.view.getInt16(this.pos);
1520
+ this.pos += 2;
1521
+ return value;
1522
+ };
1523
+ Decoder2.prototype.readU32 = function() {
1524
+ var value = this.view.getUint32(this.pos);
1525
+ this.pos += 4;
1526
+ return value;
1527
+ };
1528
+ Decoder2.prototype.readI32 = function() {
1529
+ var value = this.view.getInt32(this.pos);
1530
+ this.pos += 4;
1531
+ return value;
1532
+ };
1533
+ Decoder2.prototype.readU64 = function() {
1534
+ var value = getUint64(this.view, this.pos);
1535
+ this.pos += 8;
1536
+ return value;
1537
+ };
1538
+ Decoder2.prototype.readI64 = function() {
1539
+ var value = getInt64(this.view, this.pos);
1540
+ this.pos += 8;
1541
+ return value;
1542
+ };
1543
+ Decoder2.prototype.readF32 = function() {
1544
+ var value = this.view.getFloat32(this.pos);
1545
+ this.pos += 4;
1546
+ return value;
1547
+ };
1548
+ Decoder2.prototype.readF64 = function() {
1549
+ var value = this.view.getFloat64(this.pos);
1550
+ this.pos += 8;
1551
+ return value;
1552
+ };
1553
+ return Decoder2;
1554
+ })()
1555
+ );
1556
+
1557
+ // node_modules/.pnpm/@msgpack+msgpack@2.8.0/node_modules/@msgpack/msgpack/dist.es5+esm/decode.mjs
1558
+ var defaultDecodeOptions = {};
1559
+
1560
+ // node_modules/.pnpm/@msgpack+msgpack@2.8.0/node_modules/@msgpack/msgpack/dist.es5+esm/utils/stream.mjs
1561
+ var __generator2 = function(thisArg, body) {
1562
+ var _ = { label: 0, sent: function() {
1563
+ if (t[0] & 1) throw t[1];
1564
+ return t[1];
1565
+ }, trys: [], ops: [] }, f, y, t, g;
1566
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
1567
+ return this;
1568
+ }), g;
1569
+ function verb(n) {
1570
+ return function(v) {
1571
+ return step([n, v]);
1572
+ };
1573
+ }
1574
+ function step(op) {
1575
+ if (f) throw new TypeError("Generator is already executing.");
1576
+ while (_) try {
1577
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
1578
+ if (y = 0, t) op = [op[0] & 2, t.value];
1579
+ switch (op[0]) {
1580
+ case 0:
1581
+ case 1:
1582
+ t = op;
1583
+ break;
1584
+ case 4:
1585
+ _.label++;
1586
+ return { value: op[1], done: false };
1587
+ case 5:
1588
+ _.label++;
1589
+ y = op[1];
1590
+ op = [0];
1591
+ continue;
1592
+ case 7:
1593
+ op = _.ops.pop();
1594
+ _.trys.pop();
1595
+ continue;
1596
+ default:
1597
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
1598
+ _ = 0;
1599
+ continue;
1600
+ }
1601
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
1602
+ _.label = op[1];
1603
+ break;
1604
+ }
1605
+ if (op[0] === 6 && _.label < t[1]) {
1606
+ _.label = t[1];
1607
+ t = op;
1608
+ break;
1609
+ }
1610
+ if (t && _.label < t[2]) {
1611
+ _.label = t[2];
1612
+ _.ops.push(op);
1613
+ break;
1614
+ }
1615
+ if (t[2]) _.ops.pop();
1616
+ _.trys.pop();
1617
+ continue;
1618
+ }
1619
+ op = body.call(thisArg, _);
1620
+ } catch (e) {
1621
+ op = [6, e];
1622
+ y = 0;
1623
+ } finally {
1624
+ f = t = 0;
1625
+ }
1626
+ if (op[0] & 5) throw op[1];
1627
+ return { value: op[0] ? op[1] : void 0, done: true };
1628
+ }
1629
+ };
1630
+ var __await2 = function(v) {
1631
+ return this instanceof __await2 ? (this.v = v, this) : new __await2(v);
1632
+ };
1633
+ var __asyncGenerator2 = function(thisArg, _arguments, generator) {
1634
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
1635
+ var g = generator.apply(thisArg, _arguments || []), i, q = [];
1636
+ return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() {
1637
+ return this;
1638
+ }, i;
1639
+ function verb(n) {
1640
+ if (g[n]) i[n] = function(v) {
1641
+ return new Promise(function(a, b) {
1642
+ q.push([n, v, a, b]) > 1 || resume(n, v);
1643
+ });
1644
+ };
1645
+ }
1646
+ function resume(n, v) {
1647
+ try {
1648
+ step(g[n](v));
1649
+ } catch (e) {
1650
+ settle(q[0][3], e);
1651
+ }
1652
+ }
1653
+ function step(r) {
1654
+ r.value instanceof __await2 ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
1655
+ }
1656
+ function fulfill(value) {
1657
+ resume("next", value);
1658
+ }
1659
+ function reject(value) {
1660
+ resume("throw", value);
1661
+ }
1662
+ function settle(f, v) {
1663
+ if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]);
1664
+ }
1665
+ };
1666
+ function isAsyncIterable(object) {
1667
+ return object[Symbol.asyncIterator] != null;
1668
+ }
1669
+ function assertNonNull(value) {
1670
+ if (value == null) {
1671
+ throw new Error("Assertion Failure: value must not be null nor undefined");
1672
+ }
1673
+ }
1674
+ function asyncIterableFromStream(stream) {
1675
+ return __asyncGenerator2(this, arguments, function asyncIterableFromStream_1() {
1676
+ var reader, _a2, done, value;
1677
+ return __generator2(this, function(_b2) {
1678
+ switch (_b2.label) {
1679
+ case 0:
1680
+ reader = stream.getReader();
1681
+ _b2.label = 1;
1682
+ case 1:
1683
+ _b2.trys.push([1, , 9, 10]);
1684
+ _b2.label = 2;
1685
+ case 2:
1686
+ return [4, __await2(reader.read())];
1687
+ case 3:
1688
+ _a2 = _b2.sent(), done = _a2.done, value = _a2.value;
1689
+ if (!done) return [3, 5];
1690
+ return [4, __await2(void 0)];
1691
+ case 4:
1692
+ return [2, _b2.sent()];
1693
+ case 5:
1694
+ assertNonNull(value);
1695
+ return [4, __await2(value)];
1696
+ case 6:
1697
+ return [4, _b2.sent()];
1698
+ case 7:
1699
+ _b2.sent();
1700
+ return [3, 2];
1701
+ case 8:
1702
+ return [3, 10];
1703
+ case 9:
1704
+ reader.releaseLock();
1705
+ return [
1706
+ 7
1707
+ /*endfinally*/
1708
+ ];
1709
+ case 10:
1710
+ return [
1711
+ 2
1712
+ /*return*/
1713
+ ];
1714
+ }
1715
+ });
1716
+ });
1717
+ }
1718
+ function ensureAsyncIterable(streamLike) {
1719
+ if (isAsyncIterable(streamLike)) {
1720
+ return streamLike;
1721
+ } else {
1722
+ return asyncIterableFromStream(streamLike);
1723
+ }
1724
+ }
1725
+
1726
+ // node_modules/.pnpm/@msgpack+msgpack@2.8.0/node_modules/@msgpack/msgpack/dist.es5+esm/decodeAsync.mjs
1727
+ function decodeMultiStream(streamLike, options) {
1728
+ if (options === void 0) {
1729
+ options = defaultDecodeOptions;
1730
+ }
1731
+ var stream = ensureAsyncIterable(streamLike);
1732
+ var decoder = new Decoder(options.extensionCodec, options.context, options.maxStrLength, options.maxBinLength, options.maxArrayLength, options.maxMapLength, options.maxExtLength);
1733
+ return decoder.decodeStream(stream);
1734
+ }
1735
+
1736
+ // src/dataconnection/StreamConnection/StreamConnection.ts
1737
+ var StreamConnection = class extends DataConnection {
1738
+ _CHUNK_SIZE = 1024 * 8 * 4;
1739
+ _splitStream = new TransformStream({
1740
+ transform: (chunk, controller) => {
1741
+ for (let split = 0; split < chunk.length; split += this._CHUNK_SIZE) {
1742
+ controller.enqueue(chunk.subarray(split, split + this._CHUNK_SIZE));
1743
+ }
1744
+ }
1745
+ });
1746
+ _rawSendStream = new WritableStream({
1747
+ write: async (chunk, controller) => {
1748
+ if (this.dataChannel && this.dataChannel.bufferedAmount > DataConnection.MAX_BUFFERED_AMOUNT - chunk.byteLength) {
1749
+ await new Promise((resolve, reject) => {
1750
+ const onLow = () => {
1751
+ cleanup();
1752
+ resolve();
1753
+ };
1754
+ const onClose = () => {
1755
+ cleanup();
1756
+ reject(new Error("DataChannel closed while waiting for buffer drain"));
1757
+ };
1758
+ const cleanup = () => {
1759
+ this.dataChannel?.removeEventListener("bufferedamountlow", onLow);
1760
+ this.dataChannel?.removeEventListener("close", onClose);
1761
+ };
1762
+ this.dataChannel?.addEventListener("bufferedamountlow", onLow, {
1763
+ once: true
1764
+ });
1765
+ this.dataChannel?.addEventListener("close", onClose, {
1766
+ once: true
1767
+ });
1768
+ });
1769
+ }
1770
+ if (!this.dataChannel || this.dataChannel.readyState !== "open") {
1771
+ controller.error(new Error("DataChannel is not open"));
1772
+ return;
1773
+ }
1774
+ try {
1775
+ this.dataChannel.send(chunk);
1776
+ } catch (e) {
1777
+ logger_default.error(`DC#:${this.connectionId} Error when sending:`, e);
1778
+ controller.error(e);
1779
+ this.close();
1780
+ }
1781
+ }
1782
+ });
1783
+ writer = this._splitStream.writable.getWriter();
1784
+ _readStreamMessageHandler = null;
1785
+ _readStreamController = null;
1786
+ _rawReadStream = new ReadableStream({
1787
+ start: (controller) => {
1788
+ this._readStreamController = controller;
1789
+ this.once("open", () => {
1790
+ if (!this.dataChannel) return;
1791
+ this._readStreamMessageHandler = (e) => {
1792
+ controller.enqueue(e.data);
1793
+ };
1794
+ this.dataChannel.addEventListener("message", this._readStreamMessageHandler);
1795
+ });
1796
+ }
1797
+ });
1798
+ constructor(peerId, provider, options) {
1799
+ super(peerId, provider, { ...options, reliable: true });
1800
+ void this._splitStream.readable.pipeTo(this._rawSendStream);
1801
+ }
1802
+ _initializeDataChannel(dc) {
1803
+ super._initializeDataChannel(dc);
1804
+ this.dataChannel.binaryType = "arraybuffer";
1805
+ this.dataChannel.bufferedAmountLowThreshold = DataConnection.MAX_BUFFERED_AMOUNT / 2;
1806
+ }
1807
+ close(options) {
1808
+ if (this.dataChannel && this._readStreamMessageHandler) {
1809
+ this.dataChannel.removeEventListener("message", this._readStreamMessageHandler);
1810
+ this._readStreamMessageHandler = null;
1811
+ }
1812
+ super.close(options);
1813
+ try {
1814
+ this.writer.abort();
1815
+ } catch (_) {
1816
+ }
1817
+ if (this._readStreamController) {
1818
+ try {
1819
+ this._readStreamController.close();
1820
+ } catch (_) {
1821
+ }
1822
+ this._readStreamController = null;
1823
+ }
1824
+ }
1825
+ };
1826
+
1827
+ // src/dataconnection/StreamConnection/MsgPack.ts
1828
+ var MsgPack = class extends StreamConnection {
1829
+ serialization = "MsgPack";
1830
+ _encoder = new Encoder();
1831
+ constructor(peerId, provider, options) {
1832
+ super(peerId, provider, options);
1833
+ (async () => {
1834
+ for await (const msg of decodeMultiStream(this._rawReadStream)) {
1835
+ const peerData = msg?.__peerData;
1836
+ if (peerData?.type === "close") {
1837
+ this.close();
1838
+ return;
1839
+ }
1840
+ this.emit("data", msg);
1841
+ }
1842
+ })().catch((err) => {
1843
+ if (this.open) {
1844
+ logger_default.error(`DC#${this.connectionId} MsgPack decode error:`, err);
1845
+ }
1846
+ });
1847
+ }
1848
+ _send(data) {
1849
+ return this.writer.write(this._encoder.encode(data));
1850
+ }
1851
+ };
1852
+
1853
+ // src/msgPackDendri.ts
1854
+ var MsgPackDendri = class extends Dendri {
1855
+ _serializers = {
1856
+ MsgPack,
1857
+ default: MsgPack
1858
+ };
1859
+ };
1860
+
1861
+ // src/server-api.ts
1862
+ var DendriServerAPI = class {
1863
+ _baseUrl;
1864
+ _key;
1865
+ constructor(options) {
1866
+ this._baseUrl = options.url.replace(/\/$/, "");
1867
+ this._key = options.key ?? "dendri";
1868
+ }
1869
+ /** Get server health and stats */
1870
+ async getHealth() {
1871
+ const res = await fetch(`${this._baseUrl}/health`);
1872
+ if (!res.ok) throw new Error(`Health check failed: ${res.status}`);
1873
+ return res.json();
1874
+ }
1875
+ /** List all connected peer IDs */
1876
+ async listPeers(room) {
1877
+ const url = room ? `${this._baseUrl}/${this._key}/peers?room=${encodeURIComponent(room)}` : `${this._baseUrl}/${this._key}/peers`;
1878
+ const res = await fetch(url);
1879
+ if (!res.ok) throw new Error(`List peers failed: ${res.status}`);
1880
+ return res.json();
1881
+ }
1882
+ /** Generate a new peer ID */
1883
+ async generatePeerId() {
1884
+ const res = await fetch(`${this._baseUrl}/${this._key}/id`);
1885
+ if (!res.ok) throw new Error(`Generate ID failed: ${res.status}`);
1886
+ return res.text();
1887
+ }
1888
+ /** Get TURN credentials */
1889
+ async getTurnCredentials() {
1890
+ const res = await fetch(`${this._baseUrl}/turn`);
1891
+ if (!res.ok) throw new Error(`TURN credentials failed: ${res.status}`);
1892
+ return res.json();
1893
+ }
1894
+ /** Get analytics metadata */
1895
+ async getAnalytics() {
1896
+ const res = await fetch(`${this._baseUrl}/analytics`);
1897
+ if (!res.ok) throw new Error(`Analytics failed: ${res.status}`);
1898
+ return res.json();
1899
+ }
1900
+ };
1901
+
1902
+ // src/index.ts
1903
+ var src_default = Dendri;
1904
+
1905
+ export { DendriServerAPI, MsgPack, MsgPackDendri, StreamConnection, src_default as default };
1906
+ //# sourceMappingURL=dendri.js.map
1907
+ //# sourceMappingURL=dendri.js.map