@kitware/wslink 2.5.0 → 2.5.4

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/wslink.mjs DELETED
@@ -1,1474 +0,0 @@
1
- function R(n) {
2
- return n.charAt(0).toUpperCase() + n.slice(1);
3
- }
4
- function fe(n, e = {}, t = null) {
5
- e.isA || (e.isA = []), t && e.isA.push(t), n.isA || (n.isA = (r) => e.isA.indexOf(r) !== -1);
6
- }
7
- function he(n, e = {}, t = []) {
8
- t.forEach((r) => {
9
- n[`set${R(r)}`] = (s) => {
10
- e[r] = s;
11
- };
12
- });
13
- }
14
- function ue(n, e = {}, t = []) {
15
- t.forEach((r) => {
16
- n[`get${R(r)}`] = () => e[r];
17
- });
18
- }
19
- function de(n, e = {}) {
20
- const t = n.destroy;
21
- e.subscriptions || (e.subscriptions = []), n.destroy = () => {
22
- for (t && t(); e.subscriptions && e.subscriptions.length; )
23
- e.subscriptions.pop().unsubscribe();
24
- Object.keys(e).forEach((r) => {
25
- delete e[r];
26
- }), e.deleted = !0;
27
- };
28
- }
29
- function le(n, e, t, r = !0) {
30
- const s = [], i = n.destroy;
31
- function o(h) {
32
- s[h] = null;
33
- }
34
- function c(h) {
35
- function a() {
36
- o(h);
37
- }
38
- return Object.freeze({ unsubscribe: a });
39
- }
40
- n[`fire${R(t)}`] = (...h) => {
41
- if (e.deleted) {
42
- console.log("instance deleted - can not call any method");
43
- return;
44
- }
45
- function a() {
46
- s.forEach((l) => {
47
- if (l)
48
- try {
49
- l.apply(n, h);
50
- } catch (p) {
51
- console.log("Error event:", t, p);
52
- }
53
- });
54
- }
55
- r ? setTimeout(a, 0) : a();
56
- }, n[`on${R(t)}`] = (h) => {
57
- if (e.deleted)
58
- return console.log("instance deleted - can not call any method"), null;
59
- const a = s.length;
60
- return s.push(h), c(a);
61
- }, n.destroy = () => {
62
- i(), s.forEach((h, a) => o(a));
63
- };
64
- }
65
- function pe(...n) {
66
- return (...e) => n.filter((t) => !!t).forEach((t) => t(...e));
67
- }
68
- function we(n) {
69
- return (e = {}) => {
70
- const t = {}, r = {};
71
- return n(r, t, e), Object.freeze(r);
72
- };
73
- }
74
- const w = {
75
- chain: pe,
76
- destroy: de,
77
- event: le,
78
- get: ue,
79
- isA: fe,
80
- newInstance: we,
81
- set: he
82
- }, X = [];
83
- function ve(n, e) {
84
- n.start = (t) => {
85
- const r = new XMLHttpRequest(), s = e.endPoint;
86
- e._retry || (e._retry = t.launcherRetry || []), r.open("POST", s, !0), t.headers && (e._headers = t.headers, delete t.headers), e._headers && Object.entries(e._headers).forEach(
87
- ([o, c]) => r.setRequestHeader(o, c)
88
- ), r.responseType = "json";
89
- const i = "response" in r && r.responseType === "json";
90
- r.onload = (o) => {
91
- const c = i ? r.response : JSON.parse(r.response);
92
- if (r.status === 200 && c && !c.error) {
93
- X.push(c), n.fireProcessReady(c);
94
- return;
95
- } else if (r.status === 503 && e._retry.length > 0) {
96
- const h = e._retry.shift();
97
- setTimeout(n.start, h, t);
98
- } else
99
- n.fireError(r);
100
- }, r.onerror = (o) => {
101
- n.fireError(r);
102
- }, r.send(JSON.stringify(t));
103
- }, n.fetchConnection = (t) => {
104
- var r = new XMLHttpRequest(), s = [e.endPoint, t].join("/");
105
- r.open("GET", s, !0), r.responseType = "json";
106
- const i = "response" in r && r.responseType === "json";
107
- r.onload = (o) => {
108
- if (this.status === 200) {
109
- n.fireFetch(
110
- i ? r.response : JSON.parse(r.response)
111
- );
112
- return;
113
- }
114
- n.fireError(r);
115
- }, r.onerror = (o) => {
116
- n.fireError(r);
117
- }, r.send();
118
- }, n.stop = (t) => {
119
- var r = new XMLHttpRequest(), s = [e.endPoint, t.id].join("/");
120
- r.open("DELETE", s, !0), r.responseType = "json";
121
- const i = "response" in r && r.responseType === "json";
122
- r.onload = (o) => {
123
- if (this.status === 200) {
124
- const c = i ? r.response : JSON.parse(r.response);
125
- n.fireProcessStopped(c);
126
- return;
127
- }
128
- n.fireError(r);
129
- }, r.onerror = (o) => {
130
- n.fireError(r);
131
- }, r.send();
132
- }, n.listConnections = () => X;
133
- }
134
- const ye = {
135
- endPoint: null
136
- };
137
- function Z(n, e, t = {}) {
138
- Object.assign(e, ye, t), w.destroy(n, e), w.event(n, e, "ProcessReady"), w.event(n, e, "ProcessStopped"), w.event(n, e, "Fetch"), w.event(n, e, "Error"), w.isA(n, e, "ProcessLauncher"), ve(n, e);
139
- }
140
- const xe = w.newInstance(Z), ge = { newInstance: xe, extend: Z }, N = 4, V = 0, Q = N, I = V + Q, b = N, P = I + b, Ee = N, E = Q + b + Ee;
141
- function Ue(n, e, t) {
142
- const r = new ArrayBuffer(E), s = new Uint8Array(r), i = new DataView(r);
143
- return i.setUint32(V, n, !0), i.setUint32(I, e, !0), i.setUint32(P, t, !0), s;
144
- }
145
- function Se(n) {
146
- const e = new DataView(n.buffer), t = e.getUint32(V, !0), r = e.getUint32(I, !0), s = e.getUint32(P, !0);
147
- return { id: t, offset: r, size: s };
148
- }
149
- function* K(n, e) {
150
- const t = n.byteLength;
151
- let r;
152
- e === 0 ? r = t : r = Math.max(e - E, 1);
153
- const s = new Uint32Array(1);
154
- crypto.getRandomValues(s);
155
- let i = 0;
156
- for (; i < t; ) {
157
- const o = Math.min(r, t - i), c = new Uint8Array(new ArrayBuffer(E + o)), h = Ue(s[0], i, t);
158
- c.set(new Uint8Array(h.buffer), 0), c.set(n.subarray(i, i + o), E), yield c, i += o;
159
- }
160
- }
161
- class Te {
162
- pendingMessages;
163
- constructor() {
164
- this.pendingMessages = {};
165
- }
166
- releasePendingMessages() {
167
- this.pendingMessages = {};
168
- }
169
- async processChunk(e, t) {
170
- const r = e.slice(0, E), s = e.slice(E), i = new Uint8Array(await r.arrayBuffer()), { id: o, offset: c, size: h } = Se(i);
171
- let a = this.pendingMessages[o];
172
- if (a || (a = {
173
- receivedSize: 0,
174
- content: new Uint8Array(h),
175
- decoder: t()
176
- }, this.pendingMessages[o] = a), h !== a.content.byteLength)
177
- throw delete this.pendingMessages[o], new Error(
178
- `Total size in chunk header for message ${o} does not match total size declared by previous chunk.`
179
- );
180
- const l = new Uint8Array(await s.arrayBuffer()), p = a.content;
181
- if (p.set(l, c), a.receivedSize += l.byteLength, a.receivedSize >= h) {
182
- delete this.pendingMessages[o];
183
- try {
184
- return a.decoder.decode(p);
185
- } catch {
186
- console.error("Malformed message: ", p.slice(0, 100));
187
- }
188
- }
189
- }
190
- }
191
- var g = 4294967295;
192
- function _e(n, e, t) {
193
- var r = t / 4294967296, s = t;
194
- n.setUint32(e, r), n.setUint32(e + 4, s);
195
- }
196
- function j(n, e, t) {
197
- var r = Math.floor(t / 4294967296), s = t;
198
- n.setUint32(e, r), n.setUint32(e + 4, s);
199
- }
200
- function ee(n, e) {
201
- var t = n.getInt32(e), r = n.getUint32(e + 4);
202
- return t * 4294967296 + r;
203
- }
204
- function Ce(n, e) {
205
- var t = n.getUint32(e), r = n.getUint32(e + 4);
206
- return t * 4294967296 + r;
207
- }
208
- var k, z, F, M = (typeof process > "u" || ((k = process == null ? void 0 : process.env) === null || k === void 0 ? void 0 : k.TEXT_ENCODING) !== "never") && typeof TextEncoder < "u" && typeof TextDecoder < "u";
209
- function J(n) {
210
- for (var e = n.length, t = 0, r = 0; r < e; ) {
211
- var s = n.charCodeAt(r++);
212
- if ((s & 4294967168) === 0) {
213
- t++;
214
- continue;
215
- } else if ((s & 4294965248) === 0)
216
- t += 2;
217
- else {
218
- if (s >= 55296 && s <= 56319 && r < e) {
219
- var i = n.charCodeAt(r);
220
- (i & 64512) === 56320 && (++r, s = ((s & 1023) << 10) + (i & 1023) + 65536);
221
- }
222
- (s & 4294901760) === 0 ? t += 3 : t += 4;
223
- }
224
- }
225
- return t;
226
- }
227
- function De(n, e, t) {
228
- for (var r = n.length, s = t, i = 0; i < r; ) {
229
- var o = n.charCodeAt(i++);
230
- if ((o & 4294967168) === 0) {
231
- e[s++] = o;
232
- continue;
233
- } else if ((o & 4294965248) === 0)
234
- e[s++] = o >> 6 & 31 | 192;
235
- else {
236
- if (o >= 55296 && o <= 56319 && i < r) {
237
- var c = n.charCodeAt(i);
238
- (c & 64512) === 56320 && (++i, o = ((o & 1023) << 10) + (c & 1023) + 65536);
239
- }
240
- (o & 4294901760) === 0 ? (e[s++] = o >> 12 & 15 | 224, e[s++] = o >> 6 & 63 | 128) : (e[s++] = o >> 18 & 7 | 240, e[s++] = o >> 12 & 63 | 128, e[s++] = o >> 6 & 63 | 128);
241
- }
242
- e[s++] = o & 63 | 128;
243
- }
244
- }
245
- var _ = M ? new TextEncoder() : void 0, Re = M ? typeof process < "u" && ((z = process == null ? void 0 : process.env) === null || z === void 0 ? void 0 : z.TEXT_ENCODING) !== "force" ? 200 : 0 : g;
246
- function Le(n, e, t) {
247
- e.set(_.encode(n), t);
248
- }
249
- function Me(n, e, t) {
250
- _.encodeInto(n, e.subarray(t));
251
- }
252
- var Oe = _?.encodeInto ? Me : Le, ke = 4096;
253
- function te(n, e, t) {
254
- for (var r = e, s = r + t, i = [], o = ""; r < s; ) {
255
- var c = n[r++];
256
- if ((c & 128) === 0)
257
- i.push(c);
258
- else if ((c & 224) === 192) {
259
- var h = n[r++] & 63;
260
- i.push((c & 31) << 6 | h);
261
- } else if ((c & 240) === 224) {
262
- var h = n[r++] & 63, a = n[r++] & 63;
263
- i.push((c & 31) << 12 | h << 6 | a);
264
- } else if ((c & 248) === 240) {
265
- var h = n[r++] & 63, a = n[r++] & 63, l = n[r++] & 63, p = (c & 7) << 18 | h << 12 | a << 6 | l;
266
- p > 65535 && (p -= 65536, i.push(p >>> 10 & 1023 | 55296), p = 56320 | p & 1023), i.push(p);
267
- } else
268
- i.push(c);
269
- i.length >= ke && (o += String.fromCharCode.apply(String, i), i.length = 0);
270
- }
271
- return i.length > 0 && (o += String.fromCharCode.apply(String, i)), o;
272
- }
273
- var ze = M ? new TextDecoder() : null, Fe = M ? typeof process < "u" && ((F = process == null ? void 0 : process.env) === null || F === void 0 ? void 0 : F.TEXT_DECODER) !== "force" ? 200 : 0 : g;
274
- function Ae(n, e, t) {
275
- var r = n.subarray(e, e + t);
276
- return ze.decode(r);
277
- }
278
- var C = (
279
- /** @class */
280
- /* @__PURE__ */ (function() {
281
- function n(e, t) {
282
- this.type = e, this.data = t;
283
- }
284
- return n;
285
- })()
286
- ), Be = /* @__PURE__ */ (function() {
287
- var n = function(e, t) {
288
- return n = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(r, s) {
289
- r.__proto__ = s;
290
- } || function(r, s) {
291
- for (var i in s) Object.prototype.hasOwnProperty.call(s, i) && (r[i] = s[i]);
292
- }, n(e, t);
293
- };
294
- return function(e, t) {
295
- if (typeof t != "function" && t !== null)
296
- throw new TypeError("Class extends value " + String(t) + " is not a constructor or null");
297
- n(e, t);
298
- function r() {
299
- this.constructor = e;
300
- }
301
- e.prototype = t === null ? Object.create(t) : (r.prototype = t.prototype, new r());
302
- };
303
- })(), y = (
304
- /** @class */
305
- (function(n) {
306
- Be(e, n);
307
- function e(t) {
308
- var r = n.call(this, t) || this, s = Object.create(e.prototype);
309
- return Object.setPrototypeOf(r, s), Object.defineProperty(r, "name", {
310
- configurable: !0,
311
- enumerable: !1,
312
- value: e.name
313
- }), r;
314
- }
315
- return e;
316
- })(Error)
317
- ), $e = -1, He = 4294967296 - 1, Ne = 17179869184 - 1;
318
- function Ve(n) {
319
- var e = n.sec, t = n.nsec;
320
- if (e >= 0 && t >= 0 && e <= Ne)
321
- if (t === 0 && e <= He) {
322
- var r = new Uint8Array(4), s = new DataView(r.buffer);
323
- return s.setUint32(0, e), r;
324
- } else {
325
- var i = e / 4294967296, o = e & 4294967295, r = new Uint8Array(8), s = new DataView(r.buffer);
326
- return s.setUint32(0, t << 2 | i & 3), s.setUint32(4, o), r;
327
- }
328
- else {
329
- var r = new Uint8Array(12), s = new DataView(r.buffer);
330
- return s.setUint32(0, t), j(s, 4, e), r;
331
- }
332
- }
333
- function Ie(n) {
334
- var e = n.getTime(), t = Math.floor(e / 1e3), r = (e - t * 1e3) * 1e6, s = Math.floor(r / 1e9);
335
- return {
336
- sec: t + s,
337
- nsec: r - s * 1e9
338
- };
339
- }
340
- function We(n) {
341
- if (n instanceof Date) {
342
- var e = Ie(n);
343
- return Ve(e);
344
- } else
345
- return null;
346
- }
347
- function Ge(n) {
348
- var e = new DataView(n.buffer, n.byteOffset, n.byteLength);
349
- switch (n.byteLength) {
350
- case 4: {
351
- var t = e.getUint32(0), r = 0;
352
- return { sec: t, nsec: r };
353
- }
354
- case 8: {
355
- var s = e.getUint32(0), i = e.getUint32(4), t = (s & 3) * 4294967296 + i, r = s >>> 2;
356
- return { sec: t, nsec: r };
357
- }
358
- case 12: {
359
- var t = ee(e, 4), r = e.getUint32(0);
360
- return { sec: t, nsec: r };
361
- }
362
- default:
363
- throw new y("Unrecognized data size for timestamp (expected 4, 8, or 12): ".concat(n.length));
364
- }
365
- }
366
- function Xe(n) {
367
- var e = Ge(n);
368
- return new Date(e.sec * 1e3 + e.nsec / 1e6);
369
- }
370
- var Ke = {
371
- type: $e,
372
- encode: We,
373
- decode: Xe
374
- }, ne = (
375
- /** @class */
376
- (function() {
377
- function n() {
378
- this.builtInEncoders = [], this.builtInDecoders = [], this.encoders = [], this.decoders = [], this.register(Ke);
379
- }
380
- return n.prototype.register = function(e) {
381
- var t = e.type, r = e.encode, s = e.decode;
382
- if (t >= 0)
383
- this.encoders[t] = r, this.decoders[t] = s;
384
- else {
385
- var i = 1 + t;
386
- this.builtInEncoders[i] = r, this.builtInDecoders[i] = s;
387
- }
388
- }, n.prototype.tryToEncode = function(e, t) {
389
- for (var r = 0; r < this.builtInEncoders.length; r++) {
390
- var s = this.builtInEncoders[r];
391
- if (s != null) {
392
- var i = s(e, t);
393
- if (i != null) {
394
- var o = -1 - r;
395
- return new C(o, i);
396
- }
397
- }
398
- }
399
- for (var r = 0; r < this.encoders.length; r++) {
400
- var s = this.encoders[r];
401
- if (s != null) {
402
- var i = s(e, t);
403
- if (i != null) {
404
- var o = r;
405
- return new C(o, i);
406
- }
407
- }
408
- }
409
- return e instanceof C ? e : null;
410
- }, n.prototype.decode = function(e, t, r) {
411
- var s = t < 0 ? this.builtInDecoders[-1 - t] : this.decoders[t];
412
- return s ? s(e, t, r) : new C(t, e);
413
- }, n.defaultCodec = new n(), n;
414
- })()
415
- );
416
- function L(n) {
417
- return n instanceof Uint8Array ? n : ArrayBuffer.isView(n) ? new Uint8Array(n.buffer, n.byteOffset, n.byteLength) : n instanceof ArrayBuffer ? new Uint8Array(n) : Uint8Array.from(n);
418
- }
419
- function Je(n) {
420
- if (n instanceof ArrayBuffer)
421
- return new DataView(n);
422
- var e = L(n);
423
- return new DataView(e.buffer, e.byteOffset, e.byteLength);
424
- }
425
- var me = 100, qe = 2048, Ye = (
426
- /** @class */
427
- (function() {
428
- function n(e, t, r, s, i, o, c, h) {
429
- e === void 0 && (e = ne.defaultCodec), t === void 0 && (t = void 0), r === void 0 && (r = me), s === void 0 && (s = qe), i === void 0 && (i = !1), o === void 0 && (o = !1), c === void 0 && (c = !1), h === void 0 && (h = !1), this.extensionCodec = e, this.context = t, this.maxDepth = r, this.initialBufferSize = s, this.sortKeys = i, this.forceFloat32 = o, this.ignoreUndefined = c, this.forceIntegerToFloat = h, this.pos = 0, this.view = new DataView(new ArrayBuffer(this.initialBufferSize)), this.bytes = new Uint8Array(this.view.buffer);
430
- }
431
- return n.prototype.reinitializeState = function() {
432
- this.pos = 0;
433
- }, n.prototype.encodeSharedRef = function(e) {
434
- return this.reinitializeState(), this.doEncode(e, 1), this.bytes.subarray(0, this.pos);
435
- }, n.prototype.encode = function(e) {
436
- return this.reinitializeState(), this.doEncode(e, 1), this.bytes.slice(0, this.pos);
437
- }, n.prototype.doEncode = function(e, t) {
438
- if (t > this.maxDepth)
439
- throw new Error("Too deep objects in depth ".concat(t));
440
- e == null ? this.encodeNil() : typeof e == "boolean" ? this.encodeBoolean(e) : typeof e == "number" ? this.encodeNumber(e) : typeof e == "string" ? this.encodeString(e) : this.encodeObject(e, t);
441
- }, n.prototype.ensureBufferSizeToWrite = function(e) {
442
- var t = this.pos + e;
443
- this.view.byteLength < t && this.resizeBuffer(t * 2);
444
- }, n.prototype.resizeBuffer = function(e) {
445
- var t = new ArrayBuffer(e), r = new Uint8Array(t), s = new DataView(t);
446
- r.set(this.bytes), this.view = s, this.bytes = r;
447
- }, n.prototype.encodeNil = function() {
448
- this.writeU8(192);
449
- }, n.prototype.encodeBoolean = function(e) {
450
- e === !1 ? this.writeU8(194) : this.writeU8(195);
451
- }, n.prototype.encodeNumber = function(e) {
452
- Number.isSafeInteger(e) && !this.forceIntegerToFloat ? e >= 0 ? e < 128 ? this.writeU8(e) : e < 256 ? (this.writeU8(204), this.writeU8(e)) : e < 65536 ? (this.writeU8(205), this.writeU16(e)) : e < 4294967296 ? (this.writeU8(206), this.writeU32(e)) : (this.writeU8(207), this.writeU64(e)) : e >= -32 ? this.writeU8(224 | e + 32) : e >= -128 ? (this.writeU8(208), this.writeI8(e)) : e >= -32768 ? (this.writeU8(209), this.writeI16(e)) : e >= -2147483648 ? (this.writeU8(210), this.writeI32(e)) : (this.writeU8(211), this.writeI64(e)) : this.forceFloat32 ? (this.writeU8(202), this.writeF32(e)) : (this.writeU8(203), this.writeF64(e));
453
- }, n.prototype.writeStringHeader = function(e) {
454
- if (e < 32)
455
- this.writeU8(160 + e);
456
- else if (e < 256)
457
- this.writeU8(217), this.writeU8(e);
458
- else if (e < 65536)
459
- this.writeU8(218), this.writeU16(e);
460
- else if (e < 4294967296)
461
- this.writeU8(219), this.writeU32(e);
462
- else
463
- throw new Error("Too long string: ".concat(e, " bytes in UTF-8"));
464
- }, n.prototype.encodeString = function(e) {
465
- var t = 5, r = e.length;
466
- if (r > Re) {
467
- var s = J(e);
468
- this.ensureBufferSizeToWrite(t + s), this.writeStringHeader(s), Oe(e, this.bytes, this.pos), this.pos += s;
469
- } else {
470
- var s = J(e);
471
- this.ensureBufferSizeToWrite(t + s), this.writeStringHeader(s), De(e, this.bytes, this.pos), this.pos += s;
472
- }
473
- }, n.prototype.encodeObject = function(e, t) {
474
- var r = this.extensionCodec.tryToEncode(e, this.context);
475
- if (r != null)
476
- this.encodeExtension(r);
477
- else if (Array.isArray(e))
478
- this.encodeArray(e, t);
479
- else if (ArrayBuffer.isView(e))
480
- this.encodeBinary(e);
481
- else if (typeof e == "object")
482
- this.encodeMap(e, t);
483
- else
484
- throw new Error("Unrecognized object: ".concat(Object.prototype.toString.apply(e)));
485
- }, n.prototype.encodeBinary = function(e) {
486
- var t = e.byteLength;
487
- if (t < 256)
488
- this.writeU8(196), this.writeU8(t);
489
- else if (t < 65536)
490
- this.writeU8(197), this.writeU16(t);
491
- else if (t < 4294967296)
492
- this.writeU8(198), this.writeU32(t);
493
- else
494
- throw new Error("Too large binary: ".concat(t));
495
- var r = L(e);
496
- this.writeU8a(r);
497
- }, n.prototype.encodeArray = function(e, t) {
498
- var r = e.length;
499
- if (r < 16)
500
- this.writeU8(144 + r);
501
- else if (r < 65536)
502
- this.writeU8(220), this.writeU16(r);
503
- else if (r < 4294967296)
504
- this.writeU8(221), this.writeU32(r);
505
- else
506
- throw new Error("Too large array: ".concat(r));
507
- for (var s = 0, i = e; s < i.length; s++) {
508
- var o = i[s];
509
- this.doEncode(o, t + 1);
510
- }
511
- }, n.prototype.countWithoutUndefined = function(e, t) {
512
- for (var r = 0, s = 0, i = t; s < i.length; s++) {
513
- var o = i[s];
514
- e[o] !== void 0 && r++;
515
- }
516
- return r;
517
- }, n.prototype.encodeMap = function(e, t) {
518
- var r = Object.keys(e);
519
- this.sortKeys && r.sort();
520
- var s = this.ignoreUndefined ? this.countWithoutUndefined(e, r) : r.length;
521
- if (s < 16)
522
- this.writeU8(128 + s);
523
- else if (s < 65536)
524
- this.writeU8(222), this.writeU16(s);
525
- else if (s < 4294967296)
526
- this.writeU8(223), this.writeU32(s);
527
- else
528
- throw new Error("Too large map object: ".concat(s));
529
- for (var i = 0, o = r; i < o.length; i++) {
530
- var c = o[i], h = e[c];
531
- this.ignoreUndefined && h === void 0 || (this.encodeString(c), this.doEncode(h, t + 1));
532
- }
533
- }, n.prototype.encodeExtension = function(e) {
534
- var t = e.data.length;
535
- if (t === 1)
536
- this.writeU8(212);
537
- else if (t === 2)
538
- this.writeU8(213);
539
- else if (t === 4)
540
- this.writeU8(214);
541
- else if (t === 8)
542
- this.writeU8(215);
543
- else if (t === 16)
544
- this.writeU8(216);
545
- else if (t < 256)
546
- this.writeU8(199), this.writeU8(t);
547
- else if (t < 65536)
548
- this.writeU8(200), this.writeU16(t);
549
- else if (t < 4294967296)
550
- this.writeU8(201), this.writeU32(t);
551
- else
552
- throw new Error("Too large extension object: ".concat(t));
553
- this.writeI8(e.type), this.writeU8a(e.data);
554
- }, n.prototype.writeU8 = function(e) {
555
- this.ensureBufferSizeToWrite(1), this.view.setUint8(this.pos, e), this.pos++;
556
- }, n.prototype.writeU8a = function(e) {
557
- var t = e.length;
558
- this.ensureBufferSizeToWrite(t), this.bytes.set(e, this.pos), this.pos += t;
559
- }, n.prototype.writeI8 = function(e) {
560
- this.ensureBufferSizeToWrite(1), this.view.setInt8(this.pos, e), this.pos++;
561
- }, n.prototype.writeU16 = function(e) {
562
- this.ensureBufferSizeToWrite(2), this.view.setUint16(this.pos, e), this.pos += 2;
563
- }, n.prototype.writeI16 = function(e) {
564
- this.ensureBufferSizeToWrite(2), this.view.setInt16(this.pos, e), this.pos += 2;
565
- }, n.prototype.writeU32 = function(e) {
566
- this.ensureBufferSizeToWrite(4), this.view.setUint32(this.pos, e), this.pos += 4;
567
- }, n.prototype.writeI32 = function(e) {
568
- this.ensureBufferSizeToWrite(4), this.view.setInt32(this.pos, e), this.pos += 4;
569
- }, n.prototype.writeF32 = function(e) {
570
- this.ensureBufferSizeToWrite(4), this.view.setFloat32(this.pos, e), this.pos += 4;
571
- }, n.prototype.writeF64 = function(e) {
572
- this.ensureBufferSizeToWrite(8), this.view.setFloat64(this.pos, e), this.pos += 8;
573
- }, n.prototype.writeU64 = function(e) {
574
- this.ensureBufferSizeToWrite(8), _e(this.view, this.pos, e), this.pos += 8;
575
- }, n.prototype.writeI64 = function(e) {
576
- this.ensureBufferSizeToWrite(8), j(this.view, this.pos, e), this.pos += 8;
577
- }, n;
578
- })()
579
- );
580
- function A(n) {
581
- return "".concat(n < 0 ? "-" : "", "0x").concat(Math.abs(n).toString(16).padStart(2, "0"));
582
- }
583
- var Ze = 16, Qe = 16, be = (
584
- /** @class */
585
- (function() {
586
- function n(e, t) {
587
- e === void 0 && (e = Ze), t === void 0 && (t = Qe), this.maxKeyLength = e, this.maxLengthPerKey = t, this.hit = 0, this.miss = 0, this.caches = [];
588
- for (var r = 0; r < this.maxKeyLength; r++)
589
- this.caches.push([]);
590
- }
591
- return n.prototype.canBeCached = function(e) {
592
- return e > 0 && e <= this.maxKeyLength;
593
- }, n.prototype.find = function(e, t, r) {
594
- var s = this.caches[r - 1];
595
- e: for (var i = 0, o = s; i < o.length; i++) {
596
- for (var c = o[i], h = c.bytes, a = 0; a < r; a++)
597
- if (h[a] !== e[t + a])
598
- continue e;
599
- return c.str;
600
- }
601
- return null;
602
- }, n.prototype.store = function(e, t) {
603
- var r = this.caches[e.length - 1], s = { bytes: e, str: t };
604
- r.length >= this.maxLengthPerKey ? r[Math.random() * r.length | 0] = s : r.push(s);
605
- }, n.prototype.decode = function(e, t, r) {
606
- var s = this.find(e, t, r);
607
- if (s != null)
608
- return this.hit++, s;
609
- this.miss++;
610
- var i = te(e, t, r), o = Uint8Array.prototype.slice.call(e, t, t + r);
611
- return this.store(o, i), i;
612
- }, n;
613
- })()
614
- ), Pe = function(n, e, t, r) {
615
- function s(i) {
616
- return i instanceof t ? i : new t(function(o) {
617
- o(i);
618
- });
619
- }
620
- return new (t || (t = Promise))(function(i, o) {
621
- function c(l) {
622
- try {
623
- a(r.next(l));
624
- } catch (p) {
625
- o(p);
626
- }
627
- }
628
- function h(l) {
629
- try {
630
- a(r.throw(l));
631
- } catch (p) {
632
- o(p);
633
- }
634
- }
635
- function a(l) {
636
- l.done ? i(l.value) : s(l.value).then(c, h);
637
- }
638
- a((r = r.apply(n, e || [])).next());
639
- });
640
- }, B = function(n, e) {
641
- var t = { label: 0, sent: function() {
642
- if (i[0] & 1) throw i[1];
643
- return i[1];
644
- }, trys: [], ops: [] }, r, s, i, o;
645
- return o = { next: c(0), throw: c(1), return: c(2) }, typeof Symbol == "function" && (o[Symbol.iterator] = function() {
646
- return this;
647
- }), o;
648
- function c(a) {
649
- return function(l) {
650
- return h([a, l]);
651
- };
652
- }
653
- function h(a) {
654
- if (r) throw new TypeError("Generator is already executing.");
655
- for (; t; ) try {
656
- if (r = 1, s && (i = a[0] & 2 ? s.return : a[0] ? s.throw || ((i = s.return) && i.call(s), 0) : s.next) && !(i = i.call(s, a[1])).done) return i;
657
- switch (s = 0, i && (a = [a[0] & 2, i.value]), a[0]) {
658
- case 0:
659
- case 1:
660
- i = a;
661
- break;
662
- case 4:
663
- return t.label++, { value: a[1], done: !1 };
664
- case 5:
665
- t.label++, s = a[1], a = [0];
666
- continue;
667
- case 7:
668
- a = t.ops.pop(), t.trys.pop();
669
- continue;
670
- default:
671
- if (i = t.trys, !(i = i.length > 0 && i[i.length - 1]) && (a[0] === 6 || a[0] === 2)) {
672
- t = 0;
673
- continue;
674
- }
675
- if (a[0] === 3 && (!i || a[1] > i[0] && a[1] < i[3])) {
676
- t.label = a[1];
677
- break;
678
- }
679
- if (a[0] === 6 && t.label < i[1]) {
680
- t.label = i[1], i = a;
681
- break;
682
- }
683
- if (i && t.label < i[2]) {
684
- t.label = i[2], t.ops.push(a);
685
- break;
686
- }
687
- i[2] && t.ops.pop(), t.trys.pop();
688
- continue;
689
- }
690
- a = e.call(n, t);
691
- } catch (l) {
692
- a = [6, l], s = 0;
693
- } finally {
694
- r = i = 0;
695
- }
696
- if (a[0] & 5) throw a[1];
697
- return { value: a[0] ? a[1] : void 0, done: !0 };
698
- }
699
- }, m = function(n) {
700
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
701
- var e = n[Symbol.asyncIterator], t;
702
- return e ? e.call(n) : (n = typeof __values == "function" ? __values(n) : n[Symbol.iterator](), t = {}, r("next"), r("throw"), r("return"), t[Symbol.asyncIterator] = function() {
703
- return this;
704
- }, t);
705
- function r(i) {
706
- t[i] = n[i] && function(o) {
707
- return new Promise(function(c, h) {
708
- o = n[i](o), s(c, h, o.done, o.value);
709
- });
710
- };
711
- }
712
- function s(i, o, c, h) {
713
- Promise.resolve(h).then(function(a) {
714
- i({ value: a, done: c });
715
- }, o);
716
- }
717
- }, U = function(n) {
718
- return this instanceof U ? (this.v = n, this) : new U(n);
719
- }, je = function(n, e, t) {
720
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
721
- var r = t.apply(n, e || []), s, i = [];
722
- return s = {}, o("next"), o("throw"), o("return"), s[Symbol.asyncIterator] = function() {
723
- return this;
724
- }, s;
725
- function o(f) {
726
- r[f] && (s[f] = function(u) {
727
- return new Promise(function(d, v) {
728
- i.push([f, u, d, v]) > 1 || c(f, u);
729
- });
730
- });
731
- }
732
- function c(f, u) {
733
- try {
734
- h(r[f](u));
735
- } catch (d) {
736
- p(i[0][3], d);
737
- }
738
- }
739
- function h(f) {
740
- f.value instanceof U ? Promise.resolve(f.value.v).then(a, l) : p(i[0][2], f);
741
- }
742
- function a(f) {
743
- c("next", f);
744
- }
745
- function l(f) {
746
- c("throw", f);
747
- }
748
- function p(f, u) {
749
- f(u), i.shift(), i.length && c(i[0][0], i[0][1]);
750
- }
751
- }, et = function(n) {
752
- var e = typeof n;
753
- return e === "string" || e === "number";
754
- }, S = -1, W = new DataView(new ArrayBuffer(0)), tt = new Uint8Array(W.buffer), H = (function() {
755
- try {
756
- W.getInt8(0);
757
- } catch (n) {
758
- return n.constructor;
759
- }
760
- throw new Error("never reached");
761
- })(), q = new H("Insufficient data"), nt = new be(), rt = (
762
- /** @class */
763
- (function() {
764
- function n(e, t, r, s, i, o, c, h) {
765
- e === void 0 && (e = ne.defaultCodec), t === void 0 && (t = void 0), r === void 0 && (r = g), s === void 0 && (s = g), i === void 0 && (i = g), o === void 0 && (o = g), c === void 0 && (c = g), h === void 0 && (h = nt), this.extensionCodec = e, this.context = t, this.maxStrLength = r, this.maxBinLength = s, this.maxArrayLength = i, this.maxMapLength = o, this.maxExtLength = c, this.keyDecoder = h, this.totalPos = 0, this.pos = 0, this.view = W, this.bytes = tt, this.headByte = S, this.stack = [];
766
- }
767
- return n.prototype.reinitializeState = function() {
768
- this.totalPos = 0, this.headByte = S, this.stack.length = 0;
769
- }, n.prototype.setBuffer = function(e) {
770
- this.bytes = L(e), this.view = Je(this.bytes), this.pos = 0;
771
- }, n.prototype.appendBuffer = function(e) {
772
- if (this.headByte === S && !this.hasRemaining(1))
773
- this.setBuffer(e);
774
- else {
775
- var t = this.bytes.subarray(this.pos), r = L(e), s = new Uint8Array(t.length + r.length);
776
- s.set(t), s.set(r, t.length), this.setBuffer(s);
777
- }
778
- }, n.prototype.hasRemaining = function(e) {
779
- return this.view.byteLength - this.pos >= e;
780
- }, n.prototype.createExtraByteError = function(e) {
781
- var t = this, r = t.view, s = t.pos;
782
- return new RangeError("Extra ".concat(r.byteLength - s, " of ").concat(r.byteLength, " byte(s) found at buffer[").concat(e, "]"));
783
- }, n.prototype.decode = function(e) {
784
- this.reinitializeState(), this.setBuffer(e);
785
- var t = this.doDecodeSync();
786
- if (this.hasRemaining(1))
787
- throw this.createExtraByteError(this.pos);
788
- return t;
789
- }, n.prototype.decodeMulti = function(e) {
790
- return B(this, function(t) {
791
- switch (t.label) {
792
- case 0:
793
- this.reinitializeState(), this.setBuffer(e), t.label = 1;
794
- case 1:
795
- return this.hasRemaining(1) ? [4, this.doDecodeSync()] : [3, 3];
796
- case 2:
797
- return t.sent(), [3, 1];
798
- case 3:
799
- return [
800
- 2
801
- /*return*/
802
- ];
803
- }
804
- });
805
- }, n.prototype.decodeAsync = function(e) {
806
- var t, r, s, i;
807
- return Pe(this, void 0, void 0, function() {
808
- var o, c, h, a, l, p, f, u;
809
- return B(this, function(d) {
810
- switch (d.label) {
811
- case 0:
812
- o = !1, d.label = 1;
813
- case 1:
814
- d.trys.push([1, 6, 7, 12]), t = m(e), d.label = 2;
815
- case 2:
816
- return [4, t.next()];
817
- case 3:
818
- if (r = d.sent(), !!r.done) return [3, 5];
819
- if (h = r.value, o)
820
- throw this.createExtraByteError(this.totalPos);
821
- this.appendBuffer(h);
822
- try {
823
- c = this.doDecodeSync(), o = !0;
824
- } catch (v) {
825
- if (!(v instanceof H))
826
- throw v;
827
- }
828
- this.totalPos += this.pos, d.label = 4;
829
- case 4:
830
- return [3, 2];
831
- case 5:
832
- return [3, 12];
833
- case 6:
834
- return a = d.sent(), s = { error: a }, [3, 12];
835
- case 7:
836
- return d.trys.push([7, , 10, 11]), r && !r.done && (i = t.return) ? [4, i.call(t)] : [3, 9];
837
- case 8:
838
- d.sent(), d.label = 9;
839
- case 9:
840
- return [3, 11];
841
- case 10:
842
- if (s) throw s.error;
843
- return [
844
- 7
845
- /*endfinally*/
846
- ];
847
- case 11:
848
- return [
849
- 7
850
- /*endfinally*/
851
- ];
852
- case 12:
853
- if (o) {
854
- if (this.hasRemaining(1))
855
- throw this.createExtraByteError(this.totalPos);
856
- return [2, c];
857
- }
858
- throw l = this, p = l.headByte, f = l.pos, u = l.totalPos, new RangeError("Insufficient data in parsing ".concat(A(p), " at ").concat(u, " (").concat(f, " in the current buffer)"));
859
- }
860
- });
861
- });
862
- }, n.prototype.decodeArrayStream = function(e) {
863
- return this.decodeMultiAsync(e, !0);
864
- }, n.prototype.decodeStream = function(e) {
865
- return this.decodeMultiAsync(e, !1);
866
- }, n.prototype.decodeMultiAsync = function(e, t) {
867
- return je(this, arguments, function() {
868
- var s, i, o, c, h, a, l, p, f;
869
- return B(this, function(u) {
870
- switch (u.label) {
871
- case 0:
872
- s = t, i = -1, u.label = 1;
873
- case 1:
874
- u.trys.push([1, 13, 14, 19]), o = m(e), u.label = 2;
875
- case 2:
876
- return [4, U(o.next())];
877
- case 3:
878
- if (c = u.sent(), !!c.done) return [3, 12];
879
- if (h = c.value, t && i === 0)
880
- throw this.createExtraByteError(this.totalPos);
881
- this.appendBuffer(h), s && (i = this.readArraySize(), s = !1, this.complete()), u.label = 4;
882
- case 4:
883
- u.trys.push([4, 9, , 10]), u.label = 5;
884
- case 5:
885
- return [4, U(this.doDecodeSync())];
886
- case 6:
887
- return [4, u.sent()];
888
- case 7:
889
- return u.sent(), --i === 0 ? [3, 8] : [3, 5];
890
- case 8:
891
- return [3, 10];
892
- case 9:
893
- if (a = u.sent(), !(a instanceof H))
894
- throw a;
895
- return [3, 10];
896
- case 10:
897
- this.totalPos += this.pos, u.label = 11;
898
- case 11:
899
- return [3, 2];
900
- case 12:
901
- return [3, 19];
902
- case 13:
903
- return l = u.sent(), p = { error: l }, [3, 19];
904
- case 14:
905
- return u.trys.push([14, , 17, 18]), c && !c.done && (f = o.return) ? [4, U(f.call(o))] : [3, 16];
906
- case 15:
907
- u.sent(), u.label = 16;
908
- case 16:
909
- return [3, 18];
910
- case 17:
911
- if (p) throw p.error;
912
- return [
913
- 7
914
- /*endfinally*/
915
- ];
916
- case 18:
917
- return [
918
- 7
919
- /*endfinally*/
920
- ];
921
- case 19:
922
- return [
923
- 2
924
- /*return*/
925
- ];
926
- }
927
- });
928
- });
929
- }, n.prototype.doDecodeSync = function() {
930
- e: for (; ; ) {
931
- var e = this.readHeadByte(), t = void 0;
932
- if (e >= 224)
933
- t = e - 256;
934
- else if (e < 192)
935
- if (e < 128)
936
- t = e;
937
- else if (e < 144) {
938
- var r = e - 128;
939
- if (r !== 0) {
940
- this.pushMapState(r), this.complete();
941
- continue e;
942
- } else
943
- t = {};
944
- } else if (e < 160) {
945
- var r = e - 144;
946
- if (r !== 0) {
947
- this.pushArrayState(r), this.complete();
948
- continue e;
949
- } else
950
- t = [];
951
- } else {
952
- var s = e - 160;
953
- t = this.decodeUtf8String(s, 0);
954
- }
955
- else if (e === 192)
956
- t = null;
957
- else if (e === 194)
958
- t = !1;
959
- else if (e === 195)
960
- t = !0;
961
- else if (e === 202)
962
- t = this.readF32();
963
- else if (e === 203)
964
- t = this.readF64();
965
- else if (e === 204)
966
- t = this.readU8();
967
- else if (e === 205)
968
- t = this.readU16();
969
- else if (e === 206)
970
- t = this.readU32();
971
- else if (e === 207)
972
- t = this.readU64();
973
- else if (e === 208)
974
- t = this.readI8();
975
- else if (e === 209)
976
- t = this.readI16();
977
- else if (e === 210)
978
- t = this.readI32();
979
- else if (e === 211)
980
- t = this.readI64();
981
- else if (e === 217) {
982
- var s = this.lookU8();
983
- t = this.decodeUtf8String(s, 1);
984
- } else if (e === 218) {
985
- var s = this.lookU16();
986
- t = this.decodeUtf8String(s, 2);
987
- } else if (e === 219) {
988
- var s = this.lookU32();
989
- t = this.decodeUtf8String(s, 4);
990
- } else if (e === 220) {
991
- var r = this.readU16();
992
- if (r !== 0) {
993
- this.pushArrayState(r), this.complete();
994
- continue e;
995
- } else
996
- t = [];
997
- } else if (e === 221) {
998
- var r = this.readU32();
999
- if (r !== 0) {
1000
- this.pushArrayState(r), this.complete();
1001
- continue e;
1002
- } else
1003
- t = [];
1004
- } else if (e === 222) {
1005
- var r = this.readU16();
1006
- if (r !== 0) {
1007
- this.pushMapState(r), this.complete();
1008
- continue e;
1009
- } else
1010
- t = {};
1011
- } else if (e === 223) {
1012
- var r = this.readU32();
1013
- if (r !== 0) {
1014
- this.pushMapState(r), this.complete();
1015
- continue e;
1016
- } else
1017
- t = {};
1018
- } else if (e === 196) {
1019
- var r = this.lookU8();
1020
- t = this.decodeBinary(r, 1);
1021
- } else if (e === 197) {
1022
- var r = this.lookU16();
1023
- t = this.decodeBinary(r, 2);
1024
- } else if (e === 198) {
1025
- var r = this.lookU32();
1026
- t = this.decodeBinary(r, 4);
1027
- } else if (e === 212)
1028
- t = this.decodeExtension(1, 0);
1029
- else if (e === 213)
1030
- t = this.decodeExtension(2, 0);
1031
- else if (e === 214)
1032
- t = this.decodeExtension(4, 0);
1033
- else if (e === 215)
1034
- t = this.decodeExtension(8, 0);
1035
- else if (e === 216)
1036
- t = this.decodeExtension(16, 0);
1037
- else if (e === 199) {
1038
- var r = this.lookU8();
1039
- t = this.decodeExtension(r, 1);
1040
- } else if (e === 200) {
1041
- var r = this.lookU16();
1042
- t = this.decodeExtension(r, 2);
1043
- } else if (e === 201) {
1044
- var r = this.lookU32();
1045
- t = this.decodeExtension(r, 4);
1046
- } else
1047
- throw new y("Unrecognized type byte: ".concat(A(e)));
1048
- this.complete();
1049
- for (var i = this.stack; i.length > 0; ) {
1050
- var o = i[i.length - 1];
1051
- if (o.type === 0)
1052
- if (o.array[o.position] = t, o.position++, o.position === o.size)
1053
- i.pop(), t = o.array;
1054
- else
1055
- continue e;
1056
- else if (o.type === 1) {
1057
- if (!et(t))
1058
- throw new y("The type of key must be string or number but " + typeof t);
1059
- if (t === "__proto__")
1060
- throw new y("The key __proto__ is not allowed");
1061
- o.key = t, o.type = 2;
1062
- continue e;
1063
- } else if (o.map[o.key] = t, o.readCount++, o.readCount === o.size)
1064
- i.pop(), t = o.map;
1065
- else {
1066
- o.key = null, o.type = 1;
1067
- continue e;
1068
- }
1069
- }
1070
- return t;
1071
- }
1072
- }, n.prototype.readHeadByte = function() {
1073
- return this.headByte === S && (this.headByte = this.readU8()), this.headByte;
1074
- }, n.prototype.complete = function() {
1075
- this.headByte = S;
1076
- }, n.prototype.readArraySize = function() {
1077
- var e = this.readHeadByte();
1078
- switch (e) {
1079
- case 220:
1080
- return this.readU16();
1081
- case 221:
1082
- return this.readU32();
1083
- default: {
1084
- if (e < 160)
1085
- return e - 144;
1086
- throw new y("Unrecognized array type byte: ".concat(A(e)));
1087
- }
1088
- }
1089
- }, n.prototype.pushMapState = function(e) {
1090
- if (e > this.maxMapLength)
1091
- throw new y("Max length exceeded: map length (".concat(e, ") > maxMapLengthLength (").concat(this.maxMapLength, ")"));
1092
- this.stack.push({
1093
- type: 1,
1094
- size: e,
1095
- key: null,
1096
- readCount: 0,
1097
- map: {}
1098
- });
1099
- }, n.prototype.pushArrayState = function(e) {
1100
- if (e > this.maxArrayLength)
1101
- throw new y("Max length exceeded: array length (".concat(e, ") > maxArrayLength (").concat(this.maxArrayLength, ")"));
1102
- this.stack.push({
1103
- type: 0,
1104
- size: e,
1105
- array: new Array(e),
1106
- position: 0
1107
- });
1108
- }, n.prototype.decodeUtf8String = function(e, t) {
1109
- var r;
1110
- if (e > this.maxStrLength)
1111
- throw new y("Max length exceeded: UTF-8 byte length (".concat(e, ") > maxStrLength (").concat(this.maxStrLength, ")"));
1112
- if (this.bytes.byteLength < this.pos + t + e)
1113
- throw q;
1114
- var s = this.pos + t, i;
1115
- return this.stateIsMapKey() && (!((r = this.keyDecoder) === null || r === void 0) && r.canBeCached(e)) ? i = this.keyDecoder.decode(this.bytes, s, e) : e > Fe ? i = Ae(this.bytes, s, e) : i = te(this.bytes, s, e), this.pos += t + e, i;
1116
- }, n.prototype.stateIsMapKey = function() {
1117
- if (this.stack.length > 0) {
1118
- var e = this.stack[this.stack.length - 1];
1119
- return e.type === 1;
1120
- }
1121
- return !1;
1122
- }, n.prototype.decodeBinary = function(e, t) {
1123
- if (e > this.maxBinLength)
1124
- throw new y("Max length exceeded: bin length (".concat(e, ") > maxBinLength (").concat(this.maxBinLength, ")"));
1125
- if (!this.hasRemaining(e + t))
1126
- throw q;
1127
- var r = this.pos + t, s = this.bytes.subarray(r, r + e);
1128
- return this.pos += t + e, s;
1129
- }, n.prototype.decodeExtension = function(e, t) {
1130
- if (e > this.maxExtLength)
1131
- throw new y("Max length exceeded: ext length (".concat(e, ") > maxExtLength (").concat(this.maxExtLength, ")"));
1132
- var r = this.view.getInt8(this.pos + t), s = this.decodeBinary(
1133
- e,
1134
- t + 1
1135
- /* extType */
1136
- );
1137
- return this.extensionCodec.decode(s, r, this.context);
1138
- }, n.prototype.lookU8 = function() {
1139
- return this.view.getUint8(this.pos);
1140
- }, n.prototype.lookU16 = function() {
1141
- return this.view.getUint16(this.pos);
1142
- }, n.prototype.lookU32 = function() {
1143
- return this.view.getUint32(this.pos);
1144
- }, n.prototype.readU8 = function() {
1145
- var e = this.view.getUint8(this.pos);
1146
- return this.pos++, e;
1147
- }, n.prototype.readI8 = function() {
1148
- var e = this.view.getInt8(this.pos);
1149
- return this.pos++, e;
1150
- }, n.prototype.readU16 = function() {
1151
- var e = this.view.getUint16(this.pos);
1152
- return this.pos += 2, e;
1153
- }, n.prototype.readI16 = function() {
1154
- var e = this.view.getInt16(this.pos);
1155
- return this.pos += 2, e;
1156
- }, n.prototype.readU32 = function() {
1157
- var e = this.view.getUint32(this.pos);
1158
- return this.pos += 4, e;
1159
- }, n.prototype.readI32 = function() {
1160
- var e = this.view.getInt32(this.pos);
1161
- return this.pos += 4, e;
1162
- }, n.prototype.readU64 = function() {
1163
- var e = Ce(this.view, this.pos);
1164
- return this.pos += 8, e;
1165
- }, n.prototype.readI64 = function() {
1166
- var e = ee(this.view, this.pos);
1167
- return this.pos += 8, e;
1168
- }, n.prototype.readF32 = function() {
1169
- var e = this.view.getFloat32(this.pos);
1170
- return this.pos += 4, e;
1171
- }, n.prototype.readF64 = function() {
1172
- var e = this.view.getFloat64(this.pos);
1173
- return this.pos += 8, e;
1174
- }, n;
1175
- })()
1176
- );
1177
- function T() {
1178
- const n = {};
1179
- return n.promise = new Promise(function(e, t) {
1180
- n.resolve = e, n.reject = t;
1181
- }), n;
1182
- }
1183
- function st(n, e) {
1184
- let r = 0;
1185
- const s = {}, i = /^(rpc|publish|system):(\w+(?:\.\w+)*):(?:\d+)$/, o = {};
1186
- let c = null, h = 512 * 1024;
1187
- const a = new Te();
1188
- function l(f) {
1189
- if (f && f.id) {
1190
- if (f.error) {
1191
- const u = s[f.id];
1192
- u ? u.reject(f.error) : console.error("Server error:", f.error);
1193
- } else {
1194
- const u = i.exec(f.id);
1195
- if (u) {
1196
- const d = u[1];
1197
- if (d === "rpc") {
1198
- const v = s[f.id];
1199
- if (!v) {
1200
- console.log(
1201
- "session message id without matching call, dropped",
1202
- f
1203
- );
1204
- return;
1205
- }
1206
- v.resolve(f.result);
1207
- } else if (d == "publish") {
1208
- console.assert(
1209
- s[f.id] === void 0,
1210
- "publish message received matching in-flight rpc call"
1211
- );
1212
- const v = u[2];
1213
- if (!o[v])
1214
- return;
1215
- o[v].forEach(
1216
- (x) => x([f.result])
1217
- );
1218
- } else if (d == "system") {
1219
- const v = s[f.id];
1220
- f.id === "system:c0:0" ? (c = f.result.clientID, h = f.result.maxMsgSize || h, v && v.resolve(c)) : (console.error("Unknown system message", f.id), v && v.reject({
1221
- code: -32099,
1222
- message: `Unknown system message ${f.id}`
1223
- }));
1224
- } else
1225
- console.error("Unknown rpc id format", f.id);
1226
- }
1227
- }
1228
- delete s[f.id];
1229
- }
1230
- }
1231
- n.onconnect = (f) => {
1232
- const u = T(), d = "system:c0:0";
1233
- s[d] = u;
1234
- const v = {
1235
- wslink: "1.0",
1236
- id: d,
1237
- method: "wslink.hello",
1238
- args: [{ secret: e.secret }],
1239
- kwargs: {}
1240
- }, O = new Y().encode(v);
1241
- for (let G of K(O, h))
1242
- e.ws.send(G, { binary: !0 });
1243
- return u.promise;
1244
- }, n.call = (f, u = [], d = {}) => {
1245
- const v = T();
1246
- if (e.ws && c && e.ws.readyState === 1) {
1247
- const x = `rpc:${c}:${r++}`;
1248
- s[x] = v;
1249
- const O = { wslink: "1.0", id: x, method: f, args: u, kwargs: d }, ce = new Y().encode(O);
1250
- for (let ae of K(ce, h))
1251
- e.ws.send(ae, { binary: !0 });
1252
- } else
1253
- v.reject({
1254
- code: -32099,
1255
- message: `RPC call ${f} unsuccessful: connection not open`
1256
- });
1257
- return v.promise;
1258
- }, n.subscribe = (f, u) => {
1259
- const d = T();
1260
- return e.ws && c ? (o[f] || (o[f] = []), o[f].push(u), d.resolve({ topic: f, callback: u })) : d.reject({
1261
- code: -32099,
1262
- message: `Subscribe call ${f} unsuccessful: connection not open`
1263
- }), {
1264
- topic: f,
1265
- callback: u,
1266
- promise: d.promise,
1267
- unsubscribe: () => n.unsubscribe({ topic: f, callback: u })
1268
- };
1269
- }, n.unsubscribe = (f) => {
1270
- const u = T(), { topic: d, callback: v } = f;
1271
- if (!o[d])
1272
- return u.reject({
1273
- code: -32099,
1274
- message: `Unsubscribe call ${d} unsuccessful: not subscribed`
1275
- }), u.promise;
1276
- const x = o[d].indexOf(v);
1277
- return x !== -1 ? (o[d].splice(x, 1), u.resolve()) : u.reject({
1278
- code: -32099,
1279
- message: `Unsubscribe call ${d} unsuccessful: callback not found`
1280
- }), u.promise;
1281
- }, n.close = () => {
1282
- const f = T();
1283
- return e.ws.close(), a.releasePendingMessages(), f.resolve(), f.promise;
1284
- };
1285
- function p() {
1286
- return new rt();
1287
- }
1288
- n.onmessage = async (f) => {
1289
- const u = await a.processChunk(f.data, p);
1290
- u && l(u);
1291
- }, n.addAttachment = (f) => f instanceof ArrayBuffer ? new DataView(f) : f;
1292
- }
1293
- const it = {
1294
- secret: "wslink-secret",
1295
- ws: null
1296
- };
1297
- function re(n, e, t = {}) {
1298
- Object.assign(e, it, t), w.destroy(n, e), w.isA(n, e, "Session"), st(n, e);
1299
- }
1300
- const ot = w.newInstance(re), ct = { newInstance: ot, extend: re };
1301
- class Y extends Ye {
1302
- // Unfortunately @msgpack/msgpack only supports
1303
- // views of an ArrayBuffer (DataView, Uint8Array,..),
1304
- // but not an ArrayBuffer itself.
1305
- // They suggest using custom type extensions to support it,
1306
- // but that would yield a different packed payload
1307
- // (1 byte larger, but most importantly it would require
1308
- // dealing with the custom type when unpacking on the server).
1309
- // Since this type is too trivial to be treated differently,
1310
- // and since I don't want to rely on the users always wrapping
1311
- // their ArrayBuffers in a view, I'm subclassing the encoder.
1312
- encodeObject(e, t) {
1313
- return e instanceof ArrayBuffer && (e = new DataView(e)), super.encodeObject.call(this, e, t);
1314
- }
1315
- }
1316
- const se = "wslink-secret";
1317
- function at(n) {
1318
- var e = n.indexOf(":"), t = n.substring(0, e);
1319
- if (t === "ws" || t === "wss")
1320
- return {
1321
- type: "websocket",
1322
- url: n
1323
- };
1324
- throw new Error(
1325
- `Unknown protocol (${t}) for url (${n}). Unable to create transport object.`
1326
- );
1327
- }
1328
- function ft(n, e) {
1329
- n.connect = () => {
1330
- if (!e.urls) return null;
1331
- var r = [].concat(e.urls), s = [];
1332
- for (let i = 0; i < r.length; i += 1) {
1333
- const o = r[i];
1334
- try {
1335
- const c = at(o);
1336
- s.push(c);
1337
- } catch (c) {
1338
- return console.error(c), n.fireConnectionError(n, c), null;
1339
- }
1340
- }
1341
- if (e.connection) {
1342
- if (e.connection.url !== s[0].url)
1343
- e.connection.close();
1344
- else if (e.connection.readyState === 0 || e.connection.readyState === 1)
1345
- return e.session;
1346
- }
1347
- try {
1348
- e.wsProxy ? e.connection = WSLINK.createWebSocket(s[0].url) : e.connection = new WebSocket(s[0].url);
1349
- } catch (i) {
1350
- return console.error(i), n.fireConnectionError(n, i), null;
1351
- }
1352
- return e.connection.binaryType = "blob", e.secret || (e.secret = se), e.session = ct.newInstance({
1353
- ws: e.connection,
1354
- secret: e.secret
1355
- }), e.connection.onopen = (i) => {
1356
- e.session && e.session.onconnect(i).then(
1357
- () => {
1358
- n.fireConnectionReady(n);
1359
- },
1360
- (o) => {
1361
- console.error("Connection error", o), n.fireConnectionError(n, o);
1362
- }
1363
- );
1364
- }, e.connection.onclose = (i) => {
1365
- n.fireConnectionClose(n, i), e.connection = null;
1366
- }, e.connection.onerror = (i) => {
1367
- n.fireConnectionError(n, i);
1368
- }, e.connection.onmessage = (i) => {
1369
- e.session.onmessage(i);
1370
- }, e.session;
1371
- }, n.getSession = () => e.session, n.getUrl = () => e.connection ? e.connection.url : void 0;
1372
- function t(r = 10) {
1373
- e.connection && e.connection.readyState === 1 && e.session && r > 0 && e.session.call("application.exit.later", [r]), e.connection && e.connection.close(), e.connection = null;
1374
- }
1375
- n.destroy = w.chain(t, n.destroy);
1376
- }
1377
- const ht = {
1378
- secret: se,
1379
- connection: null,
1380
- session: null,
1381
- retry: !1,
1382
- wsProxy: !1
1383
- // Use WSLINK.WebSocket if true else native WebSocket
1384
- };
1385
- function ie(n, e, t = {}) {
1386
- Object.assign(e, ht, t), w.destroy(n, e), w.event(n, e, "ConnectionReady"), w.event(n, e, "ConnectionClose"), w.event(n, e, "ConnectionError"), w.isA(n, e, "WebsocketConnection"), ft(n, e);
1387
- }
1388
- const ut = w.newInstance(ie), dt = { newInstance: ut, extend: ie };
1389
- function $(n) {
1390
- return n.sessionURL && (n.sessionURL = n.sessionURL.replaceAll(
1391
- "USE_HOSTNAME",
1392
- window.location.hostname
1393
- ), n.sessionURL = n.sessionURL.replaceAll(
1394
- "USE_HOST",
1395
- window.location.host
1396
- )), n;
1397
- }
1398
- function lt(n, e = window.location.pathname) {
1399
- if (e.endsWith(".html") || e.endsWith(".htm")) {
1400
- const t = e.split("/");
1401
- t.pop(), e = t.join("/");
1402
- }
1403
- for (; e.length > 0 && e[e.length - 1] === "/"; )
1404
- e = e.substring(0, e.length - 1);
1405
- return e.length === 0 ? n : `${e}${n}`;
1406
- }
1407
- const pt = `${document.baseURI}paraview/`, wt = `${window.location.protocol === "https:" ? "wss:" : "ws:"}//${window.location.hostname}:${window.location.port}${lt(
1408
- "/ws"
1409
- )}`;
1410
- function D(n, e) {
1411
- const t = dt.newInstance({
1412
- urls: e.config.sessionURL,
1413
- secret: e.config.secret,
1414
- retry: e.config.retry,
1415
- wsProxy: e.config.iframe || e.config.wsProxy
1416
- });
1417
- return e.subscriptions.push(
1418
- t.onConnectionReady(n.readyForwarder)
1419
- ), e.subscriptions.push(
1420
- t.onConnectionError(n.errorForwarder)
1421
- ), e.subscriptions.push(
1422
- t.onConnectionClose(n.closeForwarder)
1423
- ), e.gc.push(t), t.connect();
1424
- }
1425
- function vt(n, e) {
1426
- let t = null;
1427
- e.gc = [], n.readyForwarder = (s) => {
1428
- t = s.getSession(), n.fireConnectionReady(s);
1429
- }, n.errorForwarder = (s, i) => {
1430
- n.fireConnectionError(s, i);
1431
- }, n.closeForwarder = (s, i) => {
1432
- n.fireConnectionClose(s, i);
1433
- }, n.connect = () => {
1434
- if (e.configDecorator && (e.config = e.configDecorator(e.config)), e.config = $(e.config), e.config.sessionURL)
1435
- t = D(n, e);
1436
- else if (e.config.wsProxy)
1437
- e.config.sessionURL = e.config.sessionURL || "wss://proxy/", t = D(n, e);
1438
- else {
1439
- const s = ge.newInstance({
1440
- endPoint: e.config.sessionManagerURL || pt
1441
- });
1442
- e.subscriptions.push(
1443
- s.onProcessReady((i) => {
1444
- e.configDecorator ? e.config = e.configDecorator(
1445
- Object.assign({}, e.config, i)
1446
- ) : e.config = Object.assign({}, e.config, i), e.config = $(e.config), t = D(n, e);
1447
- })
1448
- ), e.subscriptions.push(
1449
- s.onError((i) => {
1450
- i && i.response && i.response.error ? n.errorForwarder(i, i.response.error) : (e.config.sessionURL = wt, e.config = $(e.config), t = D(n, e));
1451
- })
1452
- ), s.start(e.config), e.gc.push(s);
1453
- }
1454
- }, n.getSession = () => t;
1455
- function r(s) {
1456
- for (t && (s > 0 && t.call("application.exit.later", [s]), t.close()), t = null; e.gc.length; )
1457
- e.gc.pop().destroy();
1458
- }
1459
- n.destroy = w.chain(r, n.destroy);
1460
- }
1461
- const yt = {
1462
- config: {}
1463
- // configDecorator: null,
1464
- };
1465
- function oe(n, e, t = {}) {
1466
- Object.assign(e, yt, t), w.destroy(n, e), w.event(n, e, "ConnectionReady"), w.event(n, e, "ConnectionClose"), w.event(n, e, "ConnectionError"), w.isA(n, e, "SmartConnect"), w.get(n, e, ["config", "configDecorator"]), w.set(n, e, ["configDecorator"]), vt(n, e);
1467
- }
1468
- const xt = w.newInstance(oe), gt = { newInstance: xt, extend: oe };
1469
- export {
1470
- w as CompositeClosureHelper,
1471
- ge as ProcessLauncher,
1472
- gt as SmartConnect,
1473
- dt as WebsocketConnection
1474
- };