dexie-cloud-addon 4.1.0-beta.49 → 4.2.0-alpha.3
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/modern/define-ydoc-trigger.d.ts +2 -1
- package/dist/modern/dexie-cloud-addon.js +167 -2478
- package/dist/modern/dexie-cloud-addon.js.map +1 -1
- package/dist/modern/dexie-cloud-addon.min.js +1 -1
- package/dist/modern/dexie-cloud-addon.min.js.gz +0 -0
- package/dist/modern/dexie-cloud-addon.min.js.map +1 -1
- package/dist/modern/service-worker.js +36 -2347
- package/dist/modern/service-worker.js.map +1 -1
- package/dist/modern/service-worker.min.js +1 -1
- package/dist/modern/service-worker.min.js.map +1 -1
- package/dist/modern/yjs/YDexieCloudSyncState.d.ts +1 -1
- package/dist/modern/yjs/YTable.d.ts +2 -1
- package/dist/modern/yjs/createYHandler.d.ts +1 -4
- package/dist/modern/yjs/listUpdatesSince.d.ts +2 -1
- package/dist/modern/yjs/reopenDocSignal.d.ts +2 -2
- package/dist/umd/define-ydoc-trigger.d.ts +2 -1
- package/dist/umd/dexie-cloud-addon.js +12795 -3510
- package/dist/umd/dexie-cloud-addon.js.gz +0 -0
- package/dist/umd/dexie-cloud-addon.js.map +1 -1
- package/dist/umd/dexie-cloud-addon.min.js +1 -1
- package/dist/umd/dexie-cloud-addon.min.js.gz +0 -0
- package/dist/umd/dexie-cloud-addon.min.js.map +1 -1
- package/dist/umd/service-worker.js +12268 -2983
- package/dist/umd/service-worker.js.map +1 -1
- package/dist/umd/service-worker.min.js +1 -1
- package/dist/umd/service-worker.min.js.map +1 -1
- package/dist/umd/yjs/YDexieCloudSyncState.d.ts +1 -1
- package/dist/umd/yjs/YTable.d.ts +2 -1
- package/dist/umd/yjs/createYHandler.d.ts +1 -4
- package/dist/umd/yjs/listUpdatesSince.d.ts +2 -1
- package/dist/umd/yjs/reopenDocSignal.d.ts +2 -2
- package/package.json +8 -4
- package/dist/modern/helpers/dbOnClosed.d.ts +0 -2
- package/dist/modern/yjs/Y.d.ts +0 -3
- package/dist/umd/helpers/dbOnClosed.d.ts +0 -2
- package/dist/umd/yjs/Y.d.ts +0 -3
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* ==========================================================================
|
|
10
10
|
*
|
|
11
|
-
* Version 4.
|
|
11
|
+
* Version 4.2.0-alpha.3, Fri Aug 01 2025
|
|
12
12
|
*
|
|
13
13
|
* https://dexie.org
|
|
14
14
|
*
|
|
@@ -16,8 +16,13 @@
|
|
|
16
16
|
*
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
import Dexie, { PropModification, cmp,
|
|
20
|
-
import {
|
|
19
|
+
import Dexie, { PropModification, cmp, RangeSet, liveQuery } from 'dexie';
|
|
20
|
+
import { Encoder, writeVarString, writeAny, writeVarUint8Array, writeBigUint64, toUint8Array } from 'lib0/encoding';
|
|
21
|
+
import { Decoder, readVarString, readAny, readVarUint8Array, readBigUint64, hasContent, readUint8 } from 'lib0/decoding';
|
|
22
|
+
import { firstValueFrom, from, filter, Observable, BehaviorSubject, Subject, of, fromEvent, merge, switchMap as switchMap$1, tap as tap$1, mergeMap, Subscription, throwError, combineLatest, map as map$1, share, timer, startWith as startWith$1 } from 'rxjs';
|
|
23
|
+
import { filter as filter$1, switchMap, delay, distinctUntilChanged, map, tap, take, catchError, debounceTime, startWith, skip } from 'rxjs/operators';
|
|
24
|
+
import * as Y from 'yjs';
|
|
25
|
+
import { DexieYProvider } from 'y-dexie';
|
|
21
26
|
|
|
22
27
|
/******************************************************************************
|
|
23
28
|
Copyright (c) Microsoft Corporation.
|
|
@@ -35,20 +40,6 @@ PERFORMANCE OF THIS SOFTWARE.
|
|
|
35
40
|
***************************************************************************** */
|
|
36
41
|
/* global Reflect, Promise */
|
|
37
42
|
|
|
38
|
-
var extendStatics = function(d, b) {
|
|
39
|
-
extendStatics = Object.setPrototypeOf ||
|
|
40
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
41
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
42
|
-
return extendStatics(d, b);
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
function __extends(d, b) {
|
|
46
|
-
if (typeof b !== "function" && b !== null)
|
|
47
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
48
|
-
extendStatics(d, b);
|
|
49
|
-
function __() { this.constructor = d; }
|
|
50
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
51
|
-
}
|
|
52
43
|
|
|
53
44
|
function __rest(s, e) {
|
|
54
45
|
var t = {};
|
|
@@ -72,34 +63,6 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
72
63
|
});
|
|
73
64
|
}
|
|
74
65
|
|
|
75
|
-
function __generator(thisArg, body) {
|
|
76
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
77
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
78
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
79
|
-
function step(op) {
|
|
80
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
81
|
-
while (_) try {
|
|
82
|
-
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;
|
|
83
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
84
|
-
switch (op[0]) {
|
|
85
|
-
case 0: case 1: t = op; break;
|
|
86
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
87
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
88
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
89
|
-
default:
|
|
90
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
91
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
92
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
93
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
94
|
-
if (t[2]) _.ops.pop();
|
|
95
|
-
_.trys.pop(); continue;
|
|
96
|
-
}
|
|
97
|
-
op = body.call(thisArg, _);
|
|
98
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
99
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
66
|
function __values(o) {
|
|
104
67
|
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
105
68
|
if (m) return m.call(o);
|
|
@@ -112,33 +75,6 @@ function __values(o) {
|
|
|
112
75
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
113
76
|
}
|
|
114
77
|
|
|
115
|
-
function __read(o, n) {
|
|
116
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
117
|
-
if (!m) return o;
|
|
118
|
-
var i = m.call(o), r, ar = [], e;
|
|
119
|
-
try {
|
|
120
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
121
|
-
}
|
|
122
|
-
catch (error) { e = { error: error }; }
|
|
123
|
-
finally {
|
|
124
|
-
try {
|
|
125
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
126
|
-
}
|
|
127
|
-
finally { if (e) throw e.error; }
|
|
128
|
-
}
|
|
129
|
-
return ar;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function __spreadArray(to, from, pack) {
|
|
133
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
134
|
-
if (ar || !(i in from)) {
|
|
135
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
136
|
-
ar[i] = from[i];
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
140
|
-
}
|
|
141
|
-
|
|
142
78
|
function __await(v) {
|
|
143
79
|
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
144
80
|
}
|
|
@@ -467,515 +403,6 @@ function getDbNameFromDbUrl(dbUrl) {
|
|
|
467
403
|
: url.pathname.split('/')[1];
|
|
468
404
|
}
|
|
469
405
|
|
|
470
|
-
/**
|
|
471
|
-
* Common Math expressions.
|
|
472
|
-
*
|
|
473
|
-
* @module math
|
|
474
|
-
*/
|
|
475
|
-
|
|
476
|
-
const floor = Math.floor;
|
|
477
|
-
const abs = Math.abs;
|
|
478
|
-
|
|
479
|
-
/**
|
|
480
|
-
* @function
|
|
481
|
-
* @param {number} a
|
|
482
|
-
* @param {number} b
|
|
483
|
-
* @return {number} The smaller element of a and b
|
|
484
|
-
*/
|
|
485
|
-
const min = (a, b) => a < b ? a : b;
|
|
486
|
-
|
|
487
|
-
/**
|
|
488
|
-
* @function
|
|
489
|
-
* @param {number} a
|
|
490
|
-
* @param {number} b
|
|
491
|
-
* @return {number} The bigger element of a and b
|
|
492
|
-
*/
|
|
493
|
-
const max = (a, b) => a > b ? a : b;
|
|
494
|
-
|
|
495
|
-
/**
|
|
496
|
-
* @param {number} n
|
|
497
|
-
* @return {boolean} Wether n is negative. This function also differentiates between -0 and +0
|
|
498
|
-
*/
|
|
499
|
-
const isNegativeZero = n => n !== 0 ? n < 0 : 1 / n < 0;
|
|
500
|
-
|
|
501
|
-
/* eslint-env browser */
|
|
502
|
-
|
|
503
|
-
const BIT7 = 64;
|
|
504
|
-
const BIT8 = 128;
|
|
505
|
-
const BITS6 = 63;
|
|
506
|
-
const BITS7 = 127;
|
|
507
|
-
/**
|
|
508
|
-
* @type {number}
|
|
509
|
-
*/
|
|
510
|
-
const BITS31 = 0x7FFFFFFF;
|
|
511
|
-
|
|
512
|
-
/**
|
|
513
|
-
* Utility helpers for working with numbers.
|
|
514
|
-
*
|
|
515
|
-
* @module number
|
|
516
|
-
*/
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER;
|
|
520
|
-
|
|
521
|
-
/* c8 ignore next */
|
|
522
|
-
const isInteger = Number.isInteger || (num => typeof num === 'number' && isFinite(num) && floor(num) === num);
|
|
523
|
-
|
|
524
|
-
/**
|
|
525
|
-
* Utility module to work with Arrays.
|
|
526
|
-
*
|
|
527
|
-
* @module array
|
|
528
|
-
*/
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
const isArray = Array.isArray;
|
|
532
|
-
|
|
533
|
-
/**
|
|
534
|
-
* @param {string} str
|
|
535
|
-
* @return {Uint8Array}
|
|
536
|
-
*/
|
|
537
|
-
const _encodeUtf8Polyfill = str => {
|
|
538
|
-
const encodedString = unescape(encodeURIComponent(str));
|
|
539
|
-
const len = encodedString.length;
|
|
540
|
-
const buf = new Uint8Array(len);
|
|
541
|
-
for (let i = 0; i < len; i++) {
|
|
542
|
-
buf[i] = /** @type {number} */ (encodedString.codePointAt(i));
|
|
543
|
-
}
|
|
544
|
-
return buf
|
|
545
|
-
};
|
|
546
|
-
|
|
547
|
-
/* c8 ignore next */
|
|
548
|
-
const utf8TextEncoder = /** @type {TextEncoder} */ (typeof TextEncoder !== 'undefined' ? new TextEncoder() : null);
|
|
549
|
-
|
|
550
|
-
/**
|
|
551
|
-
* @param {string} str
|
|
552
|
-
* @return {Uint8Array}
|
|
553
|
-
*/
|
|
554
|
-
const _encodeUtf8Native = str => utf8TextEncoder.encode(str);
|
|
555
|
-
|
|
556
|
-
/**
|
|
557
|
-
* @param {string} str
|
|
558
|
-
* @return {Uint8Array}
|
|
559
|
-
*/
|
|
560
|
-
/* c8 ignore next */
|
|
561
|
-
const encodeUtf8 = utf8TextEncoder ? _encodeUtf8Native : _encodeUtf8Polyfill;
|
|
562
|
-
|
|
563
|
-
/* c8 ignore next */
|
|
564
|
-
let utf8TextDecoder = typeof TextDecoder === 'undefined' ? null : new TextDecoder('utf-8', { fatal: true, ignoreBOM: true });
|
|
565
|
-
|
|
566
|
-
/* c8 ignore start */
|
|
567
|
-
if (utf8TextDecoder && utf8TextDecoder.decode(new Uint8Array()).length === 1) {
|
|
568
|
-
// Safari doesn't handle BOM correctly.
|
|
569
|
-
// This fixes a bug in Safari 13.0.5 where it produces a BOM the first time it is called.
|
|
570
|
-
// utf8TextDecoder.decode(new Uint8Array()).length === 1 on the first call and
|
|
571
|
-
// utf8TextDecoder.decode(new Uint8Array()).length === 1 on the second call
|
|
572
|
-
// Another issue is that from then on no BOM chars are recognized anymore
|
|
573
|
-
/* c8 ignore next */
|
|
574
|
-
utf8TextDecoder = null;
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
/**
|
|
578
|
-
* Efficient schema-less binary encoding with support for variable length encoding.
|
|
579
|
-
*
|
|
580
|
-
* Use [lib0/encoding] with [lib0/decoding]. Every encoding function has a corresponding decoding function.
|
|
581
|
-
*
|
|
582
|
-
* Encodes numbers in little-endian order (least to most significant byte order)
|
|
583
|
-
* and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/)
|
|
584
|
-
* which is also used in Protocol Buffers.
|
|
585
|
-
*
|
|
586
|
-
* ```js
|
|
587
|
-
* // encoding step
|
|
588
|
-
* const encoder = encoding.createEncoder()
|
|
589
|
-
* encoding.writeVarUint(encoder, 256)
|
|
590
|
-
* encoding.writeVarString(encoder, 'Hello world!')
|
|
591
|
-
* const buf = encoding.toUint8Array(encoder)
|
|
592
|
-
* ```
|
|
593
|
-
*
|
|
594
|
-
* ```js
|
|
595
|
-
* // decoding step
|
|
596
|
-
* const decoder = decoding.createDecoder(buf)
|
|
597
|
-
* decoding.readVarUint(decoder) // => 256
|
|
598
|
-
* decoding.readVarString(decoder) // => 'Hello world!'
|
|
599
|
-
* decoding.hasContent(decoder) // => false - all data is read
|
|
600
|
-
* ```
|
|
601
|
-
*
|
|
602
|
-
* @module encoding
|
|
603
|
-
*/
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
/**
|
|
607
|
-
* A BinaryEncoder handles the encoding to an Uint8Array.
|
|
608
|
-
*/
|
|
609
|
-
class Encoder {
|
|
610
|
-
constructor () {
|
|
611
|
-
this.cpos = 0;
|
|
612
|
-
this.cbuf = new Uint8Array(100);
|
|
613
|
-
/**
|
|
614
|
-
* @type {Array<Uint8Array>}
|
|
615
|
-
*/
|
|
616
|
-
this.bufs = [];
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
/**
|
|
621
|
-
* The current length of the encoded data.
|
|
622
|
-
*
|
|
623
|
-
* @function
|
|
624
|
-
* @param {Encoder} encoder
|
|
625
|
-
* @return {number}
|
|
626
|
-
*/
|
|
627
|
-
const length = encoder => {
|
|
628
|
-
let len = encoder.cpos;
|
|
629
|
-
for (let i = 0; i < encoder.bufs.length; i++) {
|
|
630
|
-
len += encoder.bufs[i].length;
|
|
631
|
-
}
|
|
632
|
-
return len
|
|
633
|
-
};
|
|
634
|
-
|
|
635
|
-
/**
|
|
636
|
-
* Transform to Uint8Array.
|
|
637
|
-
*
|
|
638
|
-
* @function
|
|
639
|
-
* @param {Encoder} encoder
|
|
640
|
-
* @return {Uint8Array} The created ArrayBuffer.
|
|
641
|
-
*/
|
|
642
|
-
const toUint8Array = encoder => {
|
|
643
|
-
const uint8arr = new Uint8Array(length(encoder));
|
|
644
|
-
let curPos = 0;
|
|
645
|
-
for (let i = 0; i < encoder.bufs.length; i++) {
|
|
646
|
-
const d = encoder.bufs[i];
|
|
647
|
-
uint8arr.set(d, curPos);
|
|
648
|
-
curPos += d.length;
|
|
649
|
-
}
|
|
650
|
-
uint8arr.set(new Uint8Array(encoder.cbuf.buffer, 0, encoder.cpos), curPos);
|
|
651
|
-
return uint8arr
|
|
652
|
-
};
|
|
653
|
-
|
|
654
|
-
/**
|
|
655
|
-
* Verify that it is possible to write `len` bytes wtihout checking. If
|
|
656
|
-
* necessary, a new Buffer with the required length is attached.
|
|
657
|
-
*
|
|
658
|
-
* @param {Encoder} encoder
|
|
659
|
-
* @param {number} len
|
|
660
|
-
*/
|
|
661
|
-
const verifyLen = (encoder, len) => {
|
|
662
|
-
const bufferLen = encoder.cbuf.length;
|
|
663
|
-
if (bufferLen - encoder.cpos < len) {
|
|
664
|
-
encoder.bufs.push(new Uint8Array(encoder.cbuf.buffer, 0, encoder.cpos));
|
|
665
|
-
encoder.cbuf = new Uint8Array(max(bufferLen, len) * 2);
|
|
666
|
-
encoder.cpos = 0;
|
|
667
|
-
}
|
|
668
|
-
};
|
|
669
|
-
|
|
670
|
-
/**
|
|
671
|
-
* Write one byte to the encoder.
|
|
672
|
-
*
|
|
673
|
-
* @function
|
|
674
|
-
* @param {Encoder} encoder
|
|
675
|
-
* @param {number} num The byte that is to be encoded.
|
|
676
|
-
*/
|
|
677
|
-
const write = (encoder, num) => {
|
|
678
|
-
const bufferLen = encoder.cbuf.length;
|
|
679
|
-
if (encoder.cpos === bufferLen) {
|
|
680
|
-
encoder.bufs.push(encoder.cbuf);
|
|
681
|
-
encoder.cbuf = new Uint8Array(bufferLen * 2);
|
|
682
|
-
encoder.cpos = 0;
|
|
683
|
-
}
|
|
684
|
-
encoder.cbuf[encoder.cpos++] = num;
|
|
685
|
-
};
|
|
686
|
-
|
|
687
|
-
/**
|
|
688
|
-
* Write a variable length unsigned integer. Max encodable integer is 2^53.
|
|
689
|
-
*
|
|
690
|
-
* @function
|
|
691
|
-
* @param {Encoder} encoder
|
|
692
|
-
* @param {number} num The number that is to be encoded.
|
|
693
|
-
*/
|
|
694
|
-
const writeVarUint = (encoder, num) => {
|
|
695
|
-
while (num > BITS7) {
|
|
696
|
-
write(encoder, BIT8 | (BITS7 & num));
|
|
697
|
-
num = floor(num / 128); // shift >>> 7
|
|
698
|
-
}
|
|
699
|
-
write(encoder, BITS7 & num);
|
|
700
|
-
};
|
|
701
|
-
|
|
702
|
-
/**
|
|
703
|
-
* Write a variable length integer.
|
|
704
|
-
*
|
|
705
|
-
* We use the 7th bit instead for signaling that this is a negative number.
|
|
706
|
-
*
|
|
707
|
-
* @function
|
|
708
|
-
* @param {Encoder} encoder
|
|
709
|
-
* @param {number} num The number that is to be encoded.
|
|
710
|
-
*/
|
|
711
|
-
const writeVarInt = (encoder, num) => {
|
|
712
|
-
const isNegative = isNegativeZero(num);
|
|
713
|
-
if (isNegative) {
|
|
714
|
-
num = -num;
|
|
715
|
-
}
|
|
716
|
-
// |- whether to continue reading |- whether is negative |- number
|
|
717
|
-
write(encoder, (num > BITS6 ? BIT8 : 0) | (isNegative ? BIT7 : 0) | (BITS6 & num));
|
|
718
|
-
num = floor(num / 64); // shift >>> 6
|
|
719
|
-
// We don't need to consider the case of num === 0 so we can use a different
|
|
720
|
-
// pattern here than above.
|
|
721
|
-
while (num > 0) {
|
|
722
|
-
write(encoder, (num > BITS7 ? BIT8 : 0) | (BITS7 & num));
|
|
723
|
-
num = floor(num / 128); // shift >>> 7
|
|
724
|
-
}
|
|
725
|
-
};
|
|
726
|
-
|
|
727
|
-
/**
|
|
728
|
-
* A cache to store strings temporarily
|
|
729
|
-
*/
|
|
730
|
-
const _strBuffer = new Uint8Array(30000);
|
|
731
|
-
const _maxStrBSize = _strBuffer.length / 3;
|
|
732
|
-
|
|
733
|
-
/**
|
|
734
|
-
* Write a variable length string.
|
|
735
|
-
*
|
|
736
|
-
* @function
|
|
737
|
-
* @param {Encoder} encoder
|
|
738
|
-
* @param {String} str The string that is to be encoded.
|
|
739
|
-
*/
|
|
740
|
-
const _writeVarStringNative = (encoder, str) => {
|
|
741
|
-
if (str.length < _maxStrBSize) {
|
|
742
|
-
// We can encode the string into the existing buffer
|
|
743
|
-
/* c8 ignore next */
|
|
744
|
-
const written = utf8TextEncoder.encodeInto(str, _strBuffer).written || 0;
|
|
745
|
-
writeVarUint(encoder, written);
|
|
746
|
-
for (let i = 0; i < written; i++) {
|
|
747
|
-
write(encoder, _strBuffer[i]);
|
|
748
|
-
}
|
|
749
|
-
} else {
|
|
750
|
-
writeVarUint8Array(encoder, encodeUtf8(str));
|
|
751
|
-
}
|
|
752
|
-
};
|
|
753
|
-
|
|
754
|
-
/**
|
|
755
|
-
* Write a variable length string.
|
|
756
|
-
*
|
|
757
|
-
* @function
|
|
758
|
-
* @param {Encoder} encoder
|
|
759
|
-
* @param {String} str The string that is to be encoded.
|
|
760
|
-
*/
|
|
761
|
-
const _writeVarStringPolyfill = (encoder, str) => {
|
|
762
|
-
const encodedString = unescape(encodeURIComponent(str));
|
|
763
|
-
const len = encodedString.length;
|
|
764
|
-
writeVarUint(encoder, len);
|
|
765
|
-
for (let i = 0; i < len; i++) {
|
|
766
|
-
write(encoder, /** @type {number} */ (encodedString.codePointAt(i)));
|
|
767
|
-
}
|
|
768
|
-
};
|
|
769
|
-
|
|
770
|
-
/**
|
|
771
|
-
* Write a variable length string.
|
|
772
|
-
*
|
|
773
|
-
* @function
|
|
774
|
-
* @param {Encoder} encoder
|
|
775
|
-
* @param {String} str The string that is to be encoded.
|
|
776
|
-
*/
|
|
777
|
-
/* c8 ignore next */
|
|
778
|
-
const writeVarString = (utf8TextEncoder && /** @type {any} */ (utf8TextEncoder).encodeInto) ? _writeVarStringNative : _writeVarStringPolyfill;
|
|
779
|
-
|
|
780
|
-
/**
|
|
781
|
-
* Append fixed-length Uint8Array to the encoder.
|
|
782
|
-
*
|
|
783
|
-
* @function
|
|
784
|
-
* @param {Encoder} encoder
|
|
785
|
-
* @param {Uint8Array} uint8Array
|
|
786
|
-
*/
|
|
787
|
-
const writeUint8Array = (encoder, uint8Array) => {
|
|
788
|
-
const bufferLen = encoder.cbuf.length;
|
|
789
|
-
const cpos = encoder.cpos;
|
|
790
|
-
const leftCopyLen = min(bufferLen - cpos, uint8Array.length);
|
|
791
|
-
const rightCopyLen = uint8Array.length - leftCopyLen;
|
|
792
|
-
encoder.cbuf.set(uint8Array.subarray(0, leftCopyLen), cpos);
|
|
793
|
-
encoder.cpos += leftCopyLen;
|
|
794
|
-
if (rightCopyLen > 0) {
|
|
795
|
-
// Still something to write, write right half..
|
|
796
|
-
// Append new buffer
|
|
797
|
-
encoder.bufs.push(encoder.cbuf);
|
|
798
|
-
// must have at least size of remaining buffer
|
|
799
|
-
encoder.cbuf = new Uint8Array(max(bufferLen * 2, rightCopyLen));
|
|
800
|
-
// copy array
|
|
801
|
-
encoder.cbuf.set(uint8Array.subarray(leftCopyLen));
|
|
802
|
-
encoder.cpos = rightCopyLen;
|
|
803
|
-
}
|
|
804
|
-
};
|
|
805
|
-
|
|
806
|
-
/**
|
|
807
|
-
* Append an Uint8Array to Encoder.
|
|
808
|
-
*
|
|
809
|
-
* @function
|
|
810
|
-
* @param {Encoder} encoder
|
|
811
|
-
* @param {Uint8Array} uint8Array
|
|
812
|
-
*/
|
|
813
|
-
const writeVarUint8Array = (encoder, uint8Array) => {
|
|
814
|
-
writeVarUint(encoder, uint8Array.byteLength);
|
|
815
|
-
writeUint8Array(encoder, uint8Array);
|
|
816
|
-
};
|
|
817
|
-
|
|
818
|
-
/**
|
|
819
|
-
* Create an DataView of the next `len` bytes. Use it to write data after
|
|
820
|
-
* calling this function.
|
|
821
|
-
*
|
|
822
|
-
* ```js
|
|
823
|
-
* // write float32 using DataView
|
|
824
|
-
* const dv = writeOnDataView(encoder, 4)
|
|
825
|
-
* dv.setFloat32(0, 1.1)
|
|
826
|
-
* // read float32 using DataView
|
|
827
|
-
* const dv = readFromDataView(encoder, 4)
|
|
828
|
-
* dv.getFloat32(0) // => 1.100000023841858 (leaving it to the reader to find out why this is the correct result)
|
|
829
|
-
* ```
|
|
830
|
-
*
|
|
831
|
-
* @param {Encoder} encoder
|
|
832
|
-
* @param {number} len
|
|
833
|
-
* @return {DataView}
|
|
834
|
-
*/
|
|
835
|
-
const writeOnDataView = (encoder, len) => {
|
|
836
|
-
verifyLen(encoder, len);
|
|
837
|
-
const dview = new DataView(encoder.cbuf.buffer, encoder.cpos, len);
|
|
838
|
-
encoder.cpos += len;
|
|
839
|
-
return dview
|
|
840
|
-
};
|
|
841
|
-
|
|
842
|
-
/**
|
|
843
|
-
* @param {Encoder} encoder
|
|
844
|
-
* @param {number} num
|
|
845
|
-
*/
|
|
846
|
-
const writeFloat32 = (encoder, num) => writeOnDataView(encoder, 4).setFloat32(0, num, false);
|
|
847
|
-
|
|
848
|
-
/**
|
|
849
|
-
* @param {Encoder} encoder
|
|
850
|
-
* @param {number} num
|
|
851
|
-
*/
|
|
852
|
-
const writeFloat64 = (encoder, num) => writeOnDataView(encoder, 8).setFloat64(0, num, false);
|
|
853
|
-
|
|
854
|
-
/**
|
|
855
|
-
* @param {Encoder} encoder
|
|
856
|
-
* @param {bigint} num
|
|
857
|
-
*/
|
|
858
|
-
const writeBigInt64 = (encoder, num) => /** @type {any} */ (writeOnDataView(encoder, 8)).setBigInt64(0, num, false);
|
|
859
|
-
|
|
860
|
-
/**
|
|
861
|
-
* @param {Encoder} encoder
|
|
862
|
-
* @param {bigint} num
|
|
863
|
-
*/
|
|
864
|
-
const writeBigUint64 = (encoder, num) => /** @type {any} */ (writeOnDataView(encoder, 8)).setBigUint64(0, num, false);
|
|
865
|
-
|
|
866
|
-
const floatTestBed = new DataView(new ArrayBuffer(4));
|
|
867
|
-
/**
|
|
868
|
-
* Check if a number can be encoded as a 32 bit float.
|
|
869
|
-
*
|
|
870
|
-
* @param {number} num
|
|
871
|
-
* @return {boolean}
|
|
872
|
-
*/
|
|
873
|
-
const isFloat32 = num => {
|
|
874
|
-
floatTestBed.setFloat32(0, num);
|
|
875
|
-
return floatTestBed.getFloat32(0) === num
|
|
876
|
-
};
|
|
877
|
-
|
|
878
|
-
/**
|
|
879
|
-
* Encode data with efficient binary format.
|
|
880
|
-
*
|
|
881
|
-
* Differences to JSON:
|
|
882
|
-
* • Transforms data to a binary format (not to a string)
|
|
883
|
-
* • Encodes undefined, NaN, and ArrayBuffer (these can't be represented in JSON)
|
|
884
|
-
* • Numbers are efficiently encoded either as a variable length integer, as a
|
|
885
|
-
* 32 bit float, as a 64 bit float, or as a 64 bit bigint.
|
|
886
|
-
*
|
|
887
|
-
* Encoding table:
|
|
888
|
-
*
|
|
889
|
-
* | Data Type | Prefix | Encoding Method | Comment |
|
|
890
|
-
* | ------------------- | -------- | ------------------ | ------- |
|
|
891
|
-
* | undefined | 127 | | Functions, symbol, and everything that cannot be identified is encoded as undefined |
|
|
892
|
-
* | null | 126 | | |
|
|
893
|
-
* | integer | 125 | writeVarInt | Only encodes 32 bit signed integers |
|
|
894
|
-
* | float32 | 124 | writeFloat32 | |
|
|
895
|
-
* | float64 | 123 | writeFloat64 | |
|
|
896
|
-
* | bigint | 122 | writeBigInt64 | |
|
|
897
|
-
* | boolean (false) | 121 | | True and false are different data types so we save the following byte |
|
|
898
|
-
* | boolean (true) | 120 | | - 0b01111000 so the last bit determines whether true or false |
|
|
899
|
-
* | string | 119 | writeVarString | |
|
|
900
|
-
* | object<string,any> | 118 | custom | Writes {length} then {length} key-value pairs |
|
|
901
|
-
* | array<any> | 117 | custom | Writes {length} then {length} json values |
|
|
902
|
-
* | Uint8Array | 116 | writeVarUint8Array | We use Uint8Array for any kind of binary data |
|
|
903
|
-
*
|
|
904
|
-
* Reasons for the decreasing prefix:
|
|
905
|
-
* We need the first bit for extendability (later we may want to encode the
|
|
906
|
-
* prefix with writeVarUint). The remaining 7 bits are divided as follows:
|
|
907
|
-
* [0-30] the beginning of the data range is used for custom purposes
|
|
908
|
-
* (defined by the function that uses this library)
|
|
909
|
-
* [31-127] the end of the data range is used for data encoding by
|
|
910
|
-
* lib0/encoding.js
|
|
911
|
-
*
|
|
912
|
-
* @param {Encoder} encoder
|
|
913
|
-
* @param {undefined|null|number|bigint|boolean|string|Object<string,any>|Array<any>|Uint8Array} data
|
|
914
|
-
*/
|
|
915
|
-
const writeAny = (encoder, data) => {
|
|
916
|
-
switch (typeof data) {
|
|
917
|
-
case 'string':
|
|
918
|
-
// TYPE 119: STRING
|
|
919
|
-
write(encoder, 119);
|
|
920
|
-
writeVarString(encoder, data);
|
|
921
|
-
break
|
|
922
|
-
case 'number':
|
|
923
|
-
if (isInteger(data) && abs(data) <= BITS31) {
|
|
924
|
-
// TYPE 125: INTEGER
|
|
925
|
-
write(encoder, 125);
|
|
926
|
-
writeVarInt(encoder, data);
|
|
927
|
-
} else if (isFloat32(data)) {
|
|
928
|
-
// TYPE 124: FLOAT32
|
|
929
|
-
write(encoder, 124);
|
|
930
|
-
writeFloat32(encoder, data);
|
|
931
|
-
} else {
|
|
932
|
-
// TYPE 123: FLOAT64
|
|
933
|
-
write(encoder, 123);
|
|
934
|
-
writeFloat64(encoder, data);
|
|
935
|
-
}
|
|
936
|
-
break
|
|
937
|
-
case 'bigint':
|
|
938
|
-
// TYPE 122: BigInt
|
|
939
|
-
write(encoder, 122);
|
|
940
|
-
writeBigInt64(encoder, data);
|
|
941
|
-
break
|
|
942
|
-
case 'object':
|
|
943
|
-
if (data === null) {
|
|
944
|
-
// TYPE 126: null
|
|
945
|
-
write(encoder, 126);
|
|
946
|
-
} else if (isArray(data)) {
|
|
947
|
-
// TYPE 117: Array
|
|
948
|
-
write(encoder, 117);
|
|
949
|
-
writeVarUint(encoder, data.length);
|
|
950
|
-
for (let i = 0; i < data.length; i++) {
|
|
951
|
-
writeAny(encoder, data[i]);
|
|
952
|
-
}
|
|
953
|
-
} else if (data instanceof Uint8Array) {
|
|
954
|
-
// TYPE 116: ArrayBuffer
|
|
955
|
-
write(encoder, 116);
|
|
956
|
-
writeVarUint8Array(encoder, data);
|
|
957
|
-
} else {
|
|
958
|
-
// TYPE 118: Object
|
|
959
|
-
write(encoder, 118);
|
|
960
|
-
const keys = Object.keys(data);
|
|
961
|
-
writeVarUint(encoder, keys.length);
|
|
962
|
-
for (let i = 0; i < keys.length; i++) {
|
|
963
|
-
const key = keys[i];
|
|
964
|
-
writeVarString(encoder, key);
|
|
965
|
-
writeAny(encoder, data[key]);
|
|
966
|
-
}
|
|
967
|
-
}
|
|
968
|
-
break
|
|
969
|
-
case 'boolean':
|
|
970
|
-
// TYPE 120/121: boolean (true/false)
|
|
971
|
-
write(encoder, data ? 120 : 121);
|
|
972
|
-
break
|
|
973
|
-
default:
|
|
974
|
-
// TYPE 127: undefined
|
|
975
|
-
write(encoder, 127);
|
|
976
|
-
}
|
|
977
|
-
};
|
|
978
|
-
|
|
979
406
|
function encodeYMessage(msg) {
|
|
980
407
|
const encoder = new Encoder();
|
|
981
408
|
writeVarString(encoder, msg.type);
|
|
@@ -1021,319 +448,6 @@ function encodeYMessage(msg) {
|
|
|
1021
448
|
return toUint8Array(encoder);
|
|
1022
449
|
}
|
|
1023
450
|
|
|
1024
|
-
/**
|
|
1025
|
-
* Error helpers.
|
|
1026
|
-
*
|
|
1027
|
-
* @module error
|
|
1028
|
-
*/
|
|
1029
|
-
|
|
1030
|
-
/**
|
|
1031
|
-
* @param {string} s
|
|
1032
|
-
* @return {Error}
|
|
1033
|
-
*/
|
|
1034
|
-
/* c8 ignore next */
|
|
1035
|
-
const create = s => new Error(s);
|
|
1036
|
-
|
|
1037
|
-
/**
|
|
1038
|
-
* Efficient schema-less binary decoding with support for variable length encoding.
|
|
1039
|
-
*
|
|
1040
|
-
* Use [lib0/decoding] with [lib0/encoding]. Every encoding function has a corresponding decoding function.
|
|
1041
|
-
*
|
|
1042
|
-
* Encodes numbers in little-endian order (least to most significant byte order)
|
|
1043
|
-
* and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/)
|
|
1044
|
-
* which is also used in Protocol Buffers.
|
|
1045
|
-
*
|
|
1046
|
-
* ```js
|
|
1047
|
-
* // encoding step
|
|
1048
|
-
* const encoder = encoding.createEncoder()
|
|
1049
|
-
* encoding.writeVarUint(encoder, 256)
|
|
1050
|
-
* encoding.writeVarString(encoder, 'Hello world!')
|
|
1051
|
-
* const buf = encoding.toUint8Array(encoder)
|
|
1052
|
-
* ```
|
|
1053
|
-
*
|
|
1054
|
-
* ```js
|
|
1055
|
-
* // decoding step
|
|
1056
|
-
* const decoder = decoding.createDecoder(buf)
|
|
1057
|
-
* decoding.readVarUint(decoder) // => 256
|
|
1058
|
-
* decoding.readVarString(decoder) // => 'Hello world!'
|
|
1059
|
-
* decoding.hasContent(decoder) // => false - all data is read
|
|
1060
|
-
* ```
|
|
1061
|
-
*
|
|
1062
|
-
* @module decoding
|
|
1063
|
-
*/
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
const errorUnexpectedEndOfArray = create('Unexpected end of array');
|
|
1067
|
-
const errorIntegerOutOfRange = create('Integer out of Range');
|
|
1068
|
-
|
|
1069
|
-
/**
|
|
1070
|
-
* A Decoder handles the decoding of an Uint8Array.
|
|
1071
|
-
*/
|
|
1072
|
-
class Decoder {
|
|
1073
|
-
/**
|
|
1074
|
-
* @param {Uint8Array} uint8Array Binary data to decode
|
|
1075
|
-
*/
|
|
1076
|
-
constructor (uint8Array) {
|
|
1077
|
-
/**
|
|
1078
|
-
* Decoding target.
|
|
1079
|
-
*
|
|
1080
|
-
* @type {Uint8Array}
|
|
1081
|
-
*/
|
|
1082
|
-
this.arr = uint8Array;
|
|
1083
|
-
/**
|
|
1084
|
-
* Current decoding position.
|
|
1085
|
-
*
|
|
1086
|
-
* @type {number}
|
|
1087
|
-
*/
|
|
1088
|
-
this.pos = 0;
|
|
1089
|
-
}
|
|
1090
|
-
}
|
|
1091
|
-
|
|
1092
|
-
/**
|
|
1093
|
-
* @function
|
|
1094
|
-
* @param {Decoder} decoder
|
|
1095
|
-
* @return {boolean}
|
|
1096
|
-
*/
|
|
1097
|
-
const hasContent = decoder => decoder.pos !== decoder.arr.length;
|
|
1098
|
-
|
|
1099
|
-
/**
|
|
1100
|
-
* Create an Uint8Array view of the next `len` bytes and advance the position by `len`.
|
|
1101
|
-
*
|
|
1102
|
-
* Important: The Uint8Array still points to the underlying ArrayBuffer. Make sure to discard the result as soon as possible to prevent any memory leaks.
|
|
1103
|
-
* Use `buffer.copyUint8Array` to copy the result into a new Uint8Array.
|
|
1104
|
-
*
|
|
1105
|
-
* @function
|
|
1106
|
-
* @param {Decoder} decoder The decoder instance
|
|
1107
|
-
* @param {number} len The length of bytes to read
|
|
1108
|
-
* @return {Uint8Array}
|
|
1109
|
-
*/
|
|
1110
|
-
const readUint8Array = (decoder, len) => {
|
|
1111
|
-
const view = new Uint8Array(decoder.arr.buffer, decoder.pos + decoder.arr.byteOffset, len);
|
|
1112
|
-
decoder.pos += len;
|
|
1113
|
-
return view
|
|
1114
|
-
};
|
|
1115
|
-
|
|
1116
|
-
/**
|
|
1117
|
-
* Read variable length Uint8Array.
|
|
1118
|
-
*
|
|
1119
|
-
* Important: The Uint8Array still points to the underlying ArrayBuffer. Make sure to discard the result as soon as possible to prevent any memory leaks.
|
|
1120
|
-
* Use `buffer.copyUint8Array` to copy the result into a new Uint8Array.
|
|
1121
|
-
*
|
|
1122
|
-
* @function
|
|
1123
|
-
* @param {Decoder} decoder
|
|
1124
|
-
* @return {Uint8Array}
|
|
1125
|
-
*/
|
|
1126
|
-
const readVarUint8Array = decoder => readUint8Array(decoder, readVarUint(decoder));
|
|
1127
|
-
|
|
1128
|
-
/**
|
|
1129
|
-
* Read one byte as unsigned integer.
|
|
1130
|
-
* @function
|
|
1131
|
-
* @param {Decoder} decoder The decoder instance
|
|
1132
|
-
* @return {number} Unsigned 8-bit integer
|
|
1133
|
-
*/
|
|
1134
|
-
const readUint8 = decoder => decoder.arr[decoder.pos++];
|
|
1135
|
-
|
|
1136
|
-
/**
|
|
1137
|
-
* Read unsigned integer (32bit) with variable length.
|
|
1138
|
-
* 1/8th of the storage is used as encoding overhead.
|
|
1139
|
-
* * numbers < 2^7 is stored in one bytlength
|
|
1140
|
-
* * numbers < 2^14 is stored in two bylength
|
|
1141
|
-
*
|
|
1142
|
-
* @function
|
|
1143
|
-
* @param {Decoder} decoder
|
|
1144
|
-
* @return {number} An unsigned integer.length
|
|
1145
|
-
*/
|
|
1146
|
-
const readVarUint = decoder => {
|
|
1147
|
-
let num = 0;
|
|
1148
|
-
let mult = 1;
|
|
1149
|
-
const len = decoder.arr.length;
|
|
1150
|
-
while (decoder.pos < len) {
|
|
1151
|
-
const r = decoder.arr[decoder.pos++];
|
|
1152
|
-
// num = num | ((r & binary.BITS7) << len)
|
|
1153
|
-
num = num + (r & BITS7) * mult; // shift $r << (7*#iterations) and add it to num
|
|
1154
|
-
mult *= 128; // next iteration, shift 7 "more" to the left
|
|
1155
|
-
if (r < BIT8) {
|
|
1156
|
-
return num
|
|
1157
|
-
}
|
|
1158
|
-
/* c8 ignore start */
|
|
1159
|
-
if (num > MAX_SAFE_INTEGER) {
|
|
1160
|
-
throw errorIntegerOutOfRange
|
|
1161
|
-
}
|
|
1162
|
-
/* c8 ignore stop */
|
|
1163
|
-
}
|
|
1164
|
-
throw errorUnexpectedEndOfArray
|
|
1165
|
-
};
|
|
1166
|
-
|
|
1167
|
-
/**
|
|
1168
|
-
* Read signed integer (32bit) with variable length.
|
|
1169
|
-
* 1/8th of the storage is used as encoding overhead.
|
|
1170
|
-
* * numbers < 2^7 is stored in one bytlength
|
|
1171
|
-
* * numbers < 2^14 is stored in two bylength
|
|
1172
|
-
* @todo This should probably create the inverse ~num if number is negative - but this would be a breaking change.
|
|
1173
|
-
*
|
|
1174
|
-
* @function
|
|
1175
|
-
* @param {Decoder} decoder
|
|
1176
|
-
* @return {number} An unsigned integer.length
|
|
1177
|
-
*/
|
|
1178
|
-
const readVarInt = decoder => {
|
|
1179
|
-
let r = decoder.arr[decoder.pos++];
|
|
1180
|
-
let num = r & BITS6;
|
|
1181
|
-
let mult = 64;
|
|
1182
|
-
const sign = (r & BIT7) > 0 ? -1 : 1;
|
|
1183
|
-
if ((r & BIT8) === 0) {
|
|
1184
|
-
// don't continue reading
|
|
1185
|
-
return sign * num
|
|
1186
|
-
}
|
|
1187
|
-
const len = decoder.arr.length;
|
|
1188
|
-
while (decoder.pos < len) {
|
|
1189
|
-
r = decoder.arr[decoder.pos++];
|
|
1190
|
-
// num = num | ((r & binary.BITS7) << len)
|
|
1191
|
-
num = num + (r & BITS7) * mult;
|
|
1192
|
-
mult *= 128;
|
|
1193
|
-
if (r < BIT8) {
|
|
1194
|
-
return sign * num
|
|
1195
|
-
}
|
|
1196
|
-
/* c8 ignore start */
|
|
1197
|
-
if (num > MAX_SAFE_INTEGER) {
|
|
1198
|
-
throw errorIntegerOutOfRange
|
|
1199
|
-
}
|
|
1200
|
-
/* c8 ignore stop */
|
|
1201
|
-
}
|
|
1202
|
-
throw errorUnexpectedEndOfArray
|
|
1203
|
-
};
|
|
1204
|
-
|
|
1205
|
-
/**
|
|
1206
|
-
* We don't test this function anymore as we use native decoding/encoding by default now.
|
|
1207
|
-
* Better not modify this anymore..
|
|
1208
|
-
*
|
|
1209
|
-
* Transforming utf8 to a string is pretty expensive. The code performs 10x better
|
|
1210
|
-
* when String.fromCodePoint is fed with all characters as arguments.
|
|
1211
|
-
* But most environments have a maximum number of arguments per functions.
|
|
1212
|
-
* For effiency reasons we apply a maximum of 10000 characters at once.
|
|
1213
|
-
*
|
|
1214
|
-
* @function
|
|
1215
|
-
* @param {Decoder} decoder
|
|
1216
|
-
* @return {String} The read String.
|
|
1217
|
-
*/
|
|
1218
|
-
/* c8 ignore start */
|
|
1219
|
-
const _readVarStringPolyfill = decoder => {
|
|
1220
|
-
let remainingLen = readVarUint(decoder);
|
|
1221
|
-
if (remainingLen === 0) {
|
|
1222
|
-
return ''
|
|
1223
|
-
} else {
|
|
1224
|
-
let encodedString = String.fromCodePoint(readUint8(decoder)); // remember to decrease remainingLen
|
|
1225
|
-
if (--remainingLen < 100) { // do not create a Uint8Array for small strings
|
|
1226
|
-
while (remainingLen--) {
|
|
1227
|
-
encodedString += String.fromCodePoint(readUint8(decoder));
|
|
1228
|
-
}
|
|
1229
|
-
} else {
|
|
1230
|
-
while (remainingLen > 0) {
|
|
1231
|
-
const nextLen = remainingLen < 10000 ? remainingLen : 10000;
|
|
1232
|
-
// this is dangerous, we create a fresh array view from the existing buffer
|
|
1233
|
-
const bytes = decoder.arr.subarray(decoder.pos, decoder.pos + nextLen);
|
|
1234
|
-
decoder.pos += nextLen;
|
|
1235
|
-
// Starting with ES5.1 we can supply a generic array-like object as arguments
|
|
1236
|
-
encodedString += String.fromCodePoint.apply(null, /** @type {any} */ (bytes));
|
|
1237
|
-
remainingLen -= nextLen;
|
|
1238
|
-
}
|
|
1239
|
-
}
|
|
1240
|
-
return decodeURIComponent(escape(encodedString))
|
|
1241
|
-
}
|
|
1242
|
-
};
|
|
1243
|
-
/* c8 ignore stop */
|
|
1244
|
-
|
|
1245
|
-
/**
|
|
1246
|
-
* @function
|
|
1247
|
-
* @param {Decoder} decoder
|
|
1248
|
-
* @return {String} The read String
|
|
1249
|
-
*/
|
|
1250
|
-
const _readVarStringNative = decoder =>
|
|
1251
|
-
/** @type any */ (utf8TextDecoder).decode(readVarUint8Array(decoder));
|
|
1252
|
-
|
|
1253
|
-
/**
|
|
1254
|
-
* Read string of variable length
|
|
1255
|
-
* * varUint is used to store the length of the string
|
|
1256
|
-
*
|
|
1257
|
-
* @function
|
|
1258
|
-
* @param {Decoder} decoder
|
|
1259
|
-
* @return {String} The read String
|
|
1260
|
-
*
|
|
1261
|
-
*/
|
|
1262
|
-
/* c8 ignore next */
|
|
1263
|
-
const readVarString = utf8TextDecoder ? _readVarStringNative : _readVarStringPolyfill;
|
|
1264
|
-
|
|
1265
|
-
/**
|
|
1266
|
-
* @param {Decoder} decoder
|
|
1267
|
-
* @param {number} len
|
|
1268
|
-
* @return {DataView}
|
|
1269
|
-
*/
|
|
1270
|
-
const readFromDataView = (decoder, len) => {
|
|
1271
|
-
const dv = new DataView(decoder.arr.buffer, decoder.arr.byteOffset + decoder.pos, len);
|
|
1272
|
-
decoder.pos += len;
|
|
1273
|
-
return dv
|
|
1274
|
-
};
|
|
1275
|
-
|
|
1276
|
-
/**
|
|
1277
|
-
* @param {Decoder} decoder
|
|
1278
|
-
*/
|
|
1279
|
-
const readFloat32 = decoder => readFromDataView(decoder, 4).getFloat32(0, false);
|
|
1280
|
-
|
|
1281
|
-
/**
|
|
1282
|
-
* @param {Decoder} decoder
|
|
1283
|
-
*/
|
|
1284
|
-
const readFloat64 = decoder => readFromDataView(decoder, 8).getFloat64(0, false);
|
|
1285
|
-
|
|
1286
|
-
/**
|
|
1287
|
-
* @param {Decoder} decoder
|
|
1288
|
-
*/
|
|
1289
|
-
const readBigInt64 = decoder => /** @type {any} */ (readFromDataView(decoder, 8)).getBigInt64(0, false);
|
|
1290
|
-
|
|
1291
|
-
/**
|
|
1292
|
-
* @param {Decoder} decoder
|
|
1293
|
-
*/
|
|
1294
|
-
const readBigUint64 = decoder => /** @type {any} */ (readFromDataView(decoder, 8)).getBigUint64(0, false);
|
|
1295
|
-
|
|
1296
|
-
/**
|
|
1297
|
-
* @type {Array<function(Decoder):any>}
|
|
1298
|
-
*/
|
|
1299
|
-
const readAnyLookupTable = [
|
|
1300
|
-
decoder => undefined, // CASE 127: undefined
|
|
1301
|
-
decoder => null, // CASE 126: null
|
|
1302
|
-
readVarInt, // CASE 125: integer
|
|
1303
|
-
readFloat32, // CASE 124: float32
|
|
1304
|
-
readFloat64, // CASE 123: float64
|
|
1305
|
-
readBigInt64, // CASE 122: bigint
|
|
1306
|
-
decoder => false, // CASE 121: boolean (false)
|
|
1307
|
-
decoder => true, // CASE 120: boolean (true)
|
|
1308
|
-
readVarString, // CASE 119: string
|
|
1309
|
-
decoder => { // CASE 118: object<string,any>
|
|
1310
|
-
const len = readVarUint(decoder);
|
|
1311
|
-
/**
|
|
1312
|
-
* @type {Object<string,any>}
|
|
1313
|
-
*/
|
|
1314
|
-
const obj = {};
|
|
1315
|
-
for (let i = 0; i < len; i++) {
|
|
1316
|
-
const key = readVarString(decoder);
|
|
1317
|
-
obj[key] = readAny(decoder);
|
|
1318
|
-
}
|
|
1319
|
-
return obj
|
|
1320
|
-
},
|
|
1321
|
-
decoder => { // CASE 117: array<any>
|
|
1322
|
-
const len = readVarUint(decoder);
|
|
1323
|
-
const arr = [];
|
|
1324
|
-
for (let i = 0; i < len; i++) {
|
|
1325
|
-
arr.push(readAny(decoder));
|
|
1326
|
-
}
|
|
1327
|
-
return arr
|
|
1328
|
-
},
|
|
1329
|
-
readVarUint8Array // CASE 116: Uint8Array
|
|
1330
|
-
];
|
|
1331
|
-
|
|
1332
|
-
/**
|
|
1333
|
-
* @param {Decoder} decoder
|
|
1334
|
-
*/
|
|
1335
|
-
const readAny = decoder => readAnyLookupTable[127 - readUint8(decoder)](decoder);
|
|
1336
|
-
|
|
1337
451
|
function decodeYMessage(a) {
|
|
1338
452
|
const decoder = new Decoder(a);
|
|
1339
453
|
const type = readVarString(decoder);
|
|
@@ -1401,1572 +515,154 @@ function decodeYMessage(a) {
|
|
|
1401
515
|
table,
|
|
1402
516
|
prop,
|
|
1403
517
|
k,
|
|
1404
|
-
u: readVarUint8Array(decoder),
|
|
1405
|
-
r: (decoder.pos < decoder.arr.length && readVarString(decoder)) || undefined,
|
|
1406
|
-
};
|
|
1407
|
-
default:
|
|
1408
|
-
throw new TypeError(`Unknown message type: ${type}`);
|
|
1409
|
-
}
|
|
1410
|
-
}
|
|
1411
|
-
}
|
|
1412
|
-
}
|
|
1413
|
-
|
|
1414
|
-
async function asyncIterablePipeline(source, ...stages) {
|
|
1415
|
-
var _a, e_1, _b, _c;
|
|
1416
|
-
// Chain generators by sending outdata from one to another
|
|
1417
|
-
let result = source(); // Start with the source generator
|
|
1418
|
-
for (let i = 0; i < stages.length; i++) {
|
|
1419
|
-
result = stages[i](result); // Pass on the result to next generator
|
|
1420
|
-
}
|
|
1421
|
-
try {
|
|
1422
|
-
// Start running the machine. If the last stage is a sink, it will consume the data and never emit anything
|
|
1423
|
-
// to us here...
|
|
1424
|
-
for (var _d = true, result_1 = __asyncValues(result), result_1_1; result_1_1 = await result_1.next(), _a = result_1_1.done, !_a; _d = true) {
|
|
1425
|
-
_c = result_1_1.value;
|
|
1426
|
-
_d = false;
|
|
1427
|
-
const chunk = _c;
|
|
1428
|
-
}
|
|
1429
|
-
}
|
|
1430
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1431
|
-
finally {
|
|
1432
|
-
try {
|
|
1433
|
-
if (!_d && !_a && (_b = result_1.return)) await _b.call(result_1);
|
|
1434
|
-
}
|
|
1435
|
-
finally { if (e_1) throw e_1.error; }
|
|
1436
|
-
}
|
|
1437
|
-
}
|
|
1438
|
-
|
|
1439
|
-
function consumeChunkedBinaryStream(source) {
|
|
1440
|
-
return __asyncGenerator(this, arguments, function* consumeChunkedBinaryStream_1() {
|
|
1441
|
-
var _a, e_1, _b, _c;
|
|
1442
|
-
let state = 0;
|
|
1443
|
-
let sizeBuf = new Uint8Array(4);
|
|
1444
|
-
let sizeBufPos = 0;
|
|
1445
|
-
let bufs = [];
|
|
1446
|
-
let len = 0;
|
|
1447
|
-
try {
|
|
1448
|
-
for (var _d = true, source_1 = __asyncValues(source), source_1_1; source_1_1 = yield __await(source_1.next()), _a = source_1_1.done, !_a; _d = true) {
|
|
1449
|
-
_c = source_1_1.value;
|
|
1450
|
-
_d = false;
|
|
1451
|
-
const chunk = _c;
|
|
1452
|
-
const dw = new DataView(chunk.buffer, chunk.byteOffset, chunk.byteLength);
|
|
1453
|
-
let pos = 0;
|
|
1454
|
-
while (pos < chunk.byteLength) {
|
|
1455
|
-
switch (state) {
|
|
1456
|
-
case 0:
|
|
1457
|
-
// Beginning of a size header
|
|
1458
|
-
if (pos + 4 > chunk.byteLength) {
|
|
1459
|
-
for (const b of chunk.slice(pos)) {
|
|
1460
|
-
if (sizeBufPos === 4)
|
|
1461
|
-
break;
|
|
1462
|
-
sizeBuf[sizeBufPos++] = b;
|
|
1463
|
-
++pos;
|
|
1464
|
-
}
|
|
1465
|
-
if (sizeBufPos < 4) {
|
|
1466
|
-
// Need more bytes in order to read length.
|
|
1467
|
-
// Will go out from while loop as well because pos is defenitely = chunk.byteLength here.
|
|
1468
|
-
break;
|
|
1469
|
-
}
|
|
1470
|
-
}
|
|
1471
|
-
else if (sizeBufPos > 0 && sizeBufPos < 4) {
|
|
1472
|
-
for (const b of chunk.slice(pos, pos + 4 - sizeBufPos)) {
|
|
1473
|
-
sizeBuf[sizeBufPos++] = b;
|
|
1474
|
-
++pos;
|
|
1475
|
-
}
|
|
1476
|
-
}
|
|
1477
|
-
// Intentional fall-through...
|
|
1478
|
-
case 1:
|
|
1479
|
-
len =
|
|
1480
|
-
sizeBufPos === 4
|
|
1481
|
-
? new DataView(sizeBuf.buffer, 0, 4).getUint32(0, false)
|
|
1482
|
-
: dw.getUint32(pos, false);
|
|
1483
|
-
if (sizeBufPos)
|
|
1484
|
-
sizeBufPos = 0; // in this case pos is already forwarded
|
|
1485
|
-
else
|
|
1486
|
-
pos += 4; // else pos is not yet forwarded - that's why we do it now
|
|
1487
|
-
// Intentional fall-through...
|
|
1488
|
-
case 2:
|
|
1489
|
-
// Eat the chunk
|
|
1490
|
-
if (pos >= chunk.byteLength) {
|
|
1491
|
-
state = 2;
|
|
1492
|
-
break;
|
|
1493
|
-
}
|
|
1494
|
-
if (pos + len > chunk.byteLength) {
|
|
1495
|
-
bufs.push(chunk.slice(pos));
|
|
1496
|
-
len -= (chunk.byteLength - pos);
|
|
1497
|
-
state = 2;
|
|
1498
|
-
pos = chunk.byteLength; // will break while loop.
|
|
1499
|
-
}
|
|
1500
|
-
else {
|
|
1501
|
-
if (bufs.length > 0) {
|
|
1502
|
-
const concats = new Uint8Array(bufs.reduce((p, c) => p + c.byteLength, len));
|
|
1503
|
-
let p = 0;
|
|
1504
|
-
for (const buf of bufs) {
|
|
1505
|
-
concats.set(buf, p);
|
|
1506
|
-
p += buf.byteLength;
|
|
1507
|
-
}
|
|
1508
|
-
concats.set(chunk.slice(pos, pos + len), p);
|
|
1509
|
-
bufs = [];
|
|
1510
|
-
yield yield __await(concats);
|
|
1511
|
-
}
|
|
1512
|
-
else {
|
|
1513
|
-
yield yield __await(chunk.slice(pos, pos + len));
|
|
1514
|
-
}
|
|
1515
|
-
pos += len;
|
|
1516
|
-
state = 0;
|
|
1517
|
-
}
|
|
1518
|
-
break;
|
|
1519
|
-
}
|
|
1520
|
-
}
|
|
1521
|
-
}
|
|
1522
|
-
}
|
|
1523
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1524
|
-
finally {
|
|
1525
|
-
try {
|
|
1526
|
-
if (!_d && !_a && (_b = source_1.return)) yield __await(_b.call(source_1));
|
|
1527
|
-
}
|
|
1528
|
-
finally { if (e_1) throw e_1.error; }
|
|
1529
|
-
}
|
|
1530
|
-
});
|
|
1531
|
-
}
|
|
1532
|
-
|
|
1533
|
-
function getFetchResponseBodyGenerator(res) {
|
|
1534
|
-
return function () {
|
|
1535
|
-
return __asyncGenerator(this, arguments, function* () {
|
|
1536
|
-
if (!res.body)
|
|
1537
|
-
throw new Error("Response body is not readable");
|
|
1538
|
-
const reader = res.body.getReader();
|
|
1539
|
-
try {
|
|
1540
|
-
while (true) {
|
|
1541
|
-
const { done, value } = yield __await(reader.read());
|
|
1542
|
-
if (done)
|
|
1543
|
-
return yield __await(void 0);
|
|
1544
|
-
yield yield __await(value);
|
|
1545
|
-
}
|
|
1546
|
-
}
|
|
1547
|
-
finally {
|
|
1548
|
-
reader.releaseLock();
|
|
1549
|
-
}
|
|
1550
|
-
});
|
|
1551
|
-
};
|
|
1552
|
-
}
|
|
1553
|
-
|
|
1554
|
-
function isFunction(value) {
|
|
1555
|
-
return typeof value === 'function';
|
|
1556
|
-
}
|
|
1557
|
-
|
|
1558
|
-
function hasLift(source) {
|
|
1559
|
-
return isFunction(source === null || source === void 0 ? void 0 : source.lift);
|
|
1560
|
-
}
|
|
1561
|
-
function operate(init) {
|
|
1562
|
-
return function (source) {
|
|
1563
|
-
if (hasLift(source)) {
|
|
1564
|
-
return source.lift(function (liftedSource) {
|
|
1565
|
-
try {
|
|
1566
|
-
return init(liftedSource, this);
|
|
1567
|
-
}
|
|
1568
|
-
catch (err) {
|
|
1569
|
-
this.error(err);
|
|
1570
|
-
}
|
|
1571
|
-
});
|
|
1572
|
-
}
|
|
1573
|
-
throw new TypeError('Unable to lift unknown Observable type');
|
|
1574
|
-
};
|
|
1575
|
-
}
|
|
1576
|
-
|
|
1577
|
-
var isArrayLike = (function (x) { return x && typeof x.length === 'number' && typeof x !== 'function'; });
|
|
1578
|
-
|
|
1579
|
-
function isPromise(value) {
|
|
1580
|
-
return isFunction(value === null || value === void 0 ? void 0 : value.then);
|
|
1581
|
-
}
|
|
1582
|
-
|
|
1583
|
-
function createErrorClass(createImpl) {
|
|
1584
|
-
var _super = function (instance) {
|
|
1585
|
-
Error.call(instance);
|
|
1586
|
-
instance.stack = new Error().stack;
|
|
1587
|
-
};
|
|
1588
|
-
var ctorFunc = createImpl(_super);
|
|
1589
|
-
ctorFunc.prototype = Object.create(Error.prototype);
|
|
1590
|
-
ctorFunc.prototype.constructor = ctorFunc;
|
|
1591
|
-
return ctorFunc;
|
|
1592
|
-
}
|
|
1593
|
-
|
|
1594
|
-
var UnsubscriptionError = createErrorClass(function (_super) {
|
|
1595
|
-
return function UnsubscriptionErrorImpl(errors) {
|
|
1596
|
-
_super(this);
|
|
1597
|
-
this.message = errors
|
|
1598
|
-
? errors.length + " errors occurred during unsubscription:\n" + errors.map(function (err, i) { return i + 1 + ") " + err.toString(); }).join('\n ')
|
|
1599
|
-
: '';
|
|
1600
|
-
this.name = 'UnsubscriptionError';
|
|
1601
|
-
this.errors = errors;
|
|
1602
|
-
};
|
|
1603
|
-
});
|
|
1604
|
-
|
|
1605
|
-
function arrRemove(arr, item) {
|
|
1606
|
-
if (arr) {
|
|
1607
|
-
var index = arr.indexOf(item);
|
|
1608
|
-
0 <= index && arr.splice(index, 1);
|
|
1609
|
-
}
|
|
1610
|
-
}
|
|
1611
|
-
|
|
1612
|
-
var Subscription = (function () {
|
|
1613
|
-
function Subscription(initialTeardown) {
|
|
1614
|
-
this.initialTeardown = initialTeardown;
|
|
1615
|
-
this.closed = false;
|
|
1616
|
-
this._parentage = null;
|
|
1617
|
-
this._finalizers = null;
|
|
1618
|
-
}
|
|
1619
|
-
Subscription.prototype.unsubscribe = function () {
|
|
1620
|
-
var e_1, _a, e_2, _b;
|
|
1621
|
-
var errors;
|
|
1622
|
-
if (!this.closed) {
|
|
1623
|
-
this.closed = true;
|
|
1624
|
-
var _parentage = this._parentage;
|
|
1625
|
-
if (_parentage) {
|
|
1626
|
-
this._parentage = null;
|
|
1627
|
-
if (Array.isArray(_parentage)) {
|
|
1628
|
-
try {
|
|
1629
|
-
for (var _parentage_1 = __values(_parentage), _parentage_1_1 = _parentage_1.next(); !_parentage_1_1.done; _parentage_1_1 = _parentage_1.next()) {
|
|
1630
|
-
var parent_1 = _parentage_1_1.value;
|
|
1631
|
-
parent_1.remove(this);
|
|
1632
|
-
}
|
|
1633
|
-
}
|
|
1634
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1635
|
-
finally {
|
|
1636
|
-
try {
|
|
1637
|
-
if (_parentage_1_1 && !_parentage_1_1.done && (_a = _parentage_1.return)) _a.call(_parentage_1);
|
|
1638
|
-
}
|
|
1639
|
-
finally { if (e_1) throw e_1.error; }
|
|
1640
|
-
}
|
|
1641
|
-
}
|
|
1642
|
-
else {
|
|
1643
|
-
_parentage.remove(this);
|
|
1644
|
-
}
|
|
1645
|
-
}
|
|
1646
|
-
var initialFinalizer = this.initialTeardown;
|
|
1647
|
-
if (isFunction(initialFinalizer)) {
|
|
1648
|
-
try {
|
|
1649
|
-
initialFinalizer();
|
|
1650
|
-
}
|
|
1651
|
-
catch (e) {
|
|
1652
|
-
errors = e instanceof UnsubscriptionError ? e.errors : [e];
|
|
1653
|
-
}
|
|
1654
|
-
}
|
|
1655
|
-
var _finalizers = this._finalizers;
|
|
1656
|
-
if (_finalizers) {
|
|
1657
|
-
this._finalizers = null;
|
|
1658
|
-
try {
|
|
1659
|
-
for (var _finalizers_1 = __values(_finalizers), _finalizers_1_1 = _finalizers_1.next(); !_finalizers_1_1.done; _finalizers_1_1 = _finalizers_1.next()) {
|
|
1660
|
-
var finalizer = _finalizers_1_1.value;
|
|
1661
|
-
try {
|
|
1662
|
-
execFinalizer(finalizer);
|
|
1663
|
-
}
|
|
1664
|
-
catch (err) {
|
|
1665
|
-
errors = errors !== null && errors !== void 0 ? errors : [];
|
|
1666
|
-
if (err instanceof UnsubscriptionError) {
|
|
1667
|
-
errors = __spreadArray(__spreadArray([], __read(errors)), __read(err.errors));
|
|
1668
|
-
}
|
|
1669
|
-
else {
|
|
1670
|
-
errors.push(err);
|
|
1671
|
-
}
|
|
1672
|
-
}
|
|
1673
|
-
}
|
|
1674
|
-
}
|
|
1675
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
1676
|
-
finally {
|
|
1677
|
-
try {
|
|
1678
|
-
if (_finalizers_1_1 && !_finalizers_1_1.done && (_b = _finalizers_1.return)) _b.call(_finalizers_1);
|
|
1679
|
-
}
|
|
1680
|
-
finally { if (e_2) throw e_2.error; }
|
|
1681
|
-
}
|
|
1682
|
-
}
|
|
1683
|
-
if (errors) {
|
|
1684
|
-
throw new UnsubscriptionError(errors);
|
|
1685
|
-
}
|
|
1686
|
-
}
|
|
1687
|
-
};
|
|
1688
|
-
Subscription.prototype.add = function (teardown) {
|
|
1689
|
-
var _a;
|
|
1690
|
-
if (teardown && teardown !== this) {
|
|
1691
|
-
if (this.closed) {
|
|
1692
|
-
execFinalizer(teardown);
|
|
1693
|
-
}
|
|
1694
|
-
else {
|
|
1695
|
-
if (teardown instanceof Subscription) {
|
|
1696
|
-
if (teardown.closed || teardown._hasParent(this)) {
|
|
1697
|
-
return;
|
|
1698
|
-
}
|
|
1699
|
-
teardown._addParent(this);
|
|
1700
|
-
}
|
|
1701
|
-
(this._finalizers = (_a = this._finalizers) !== null && _a !== void 0 ? _a : []).push(teardown);
|
|
1702
|
-
}
|
|
1703
|
-
}
|
|
1704
|
-
};
|
|
1705
|
-
Subscription.prototype._hasParent = function (parent) {
|
|
1706
|
-
var _parentage = this._parentage;
|
|
1707
|
-
return _parentage === parent || (Array.isArray(_parentage) && _parentage.includes(parent));
|
|
1708
|
-
};
|
|
1709
|
-
Subscription.prototype._addParent = function (parent) {
|
|
1710
|
-
var _parentage = this._parentage;
|
|
1711
|
-
this._parentage = Array.isArray(_parentage) ? (_parentage.push(parent), _parentage) : _parentage ? [_parentage, parent] : parent;
|
|
1712
|
-
};
|
|
1713
|
-
Subscription.prototype._removeParent = function (parent) {
|
|
1714
|
-
var _parentage = this._parentage;
|
|
1715
|
-
if (_parentage === parent) {
|
|
1716
|
-
this._parentage = null;
|
|
1717
|
-
}
|
|
1718
|
-
else if (Array.isArray(_parentage)) {
|
|
1719
|
-
arrRemove(_parentage, parent);
|
|
1720
|
-
}
|
|
1721
|
-
};
|
|
1722
|
-
Subscription.prototype.remove = function (teardown) {
|
|
1723
|
-
var _finalizers = this._finalizers;
|
|
1724
|
-
_finalizers && arrRemove(_finalizers, teardown);
|
|
1725
|
-
if (teardown instanceof Subscription) {
|
|
1726
|
-
teardown._removeParent(this);
|
|
1727
|
-
}
|
|
1728
|
-
};
|
|
1729
|
-
Subscription.EMPTY = (function () {
|
|
1730
|
-
var empty = new Subscription();
|
|
1731
|
-
empty.closed = true;
|
|
1732
|
-
return empty;
|
|
1733
|
-
})();
|
|
1734
|
-
return Subscription;
|
|
1735
|
-
}());
|
|
1736
|
-
Subscription.EMPTY;
|
|
1737
|
-
function isSubscription(value) {
|
|
1738
|
-
return (value instanceof Subscription ||
|
|
1739
|
-
(value && 'closed' in value && isFunction(value.remove) && isFunction(value.add) && isFunction(value.unsubscribe)));
|
|
1740
|
-
}
|
|
1741
|
-
function execFinalizer(finalizer) {
|
|
1742
|
-
if (isFunction(finalizer)) {
|
|
1743
|
-
finalizer();
|
|
1744
|
-
}
|
|
1745
|
-
else {
|
|
1746
|
-
finalizer.unsubscribe();
|
|
1747
|
-
}
|
|
1748
|
-
}
|
|
1749
|
-
|
|
1750
|
-
var config = {
|
|
1751
|
-
onUnhandledError: null,
|
|
1752
|
-
onStoppedNotification: null,
|
|
1753
|
-
Promise: undefined,
|
|
1754
|
-
useDeprecatedSynchronousErrorHandling: false,
|
|
1755
|
-
useDeprecatedNextContext: false,
|
|
1756
|
-
};
|
|
1757
|
-
|
|
1758
|
-
var timeoutProvider = {
|
|
1759
|
-
setTimeout: function (handler, timeout) {
|
|
1760
|
-
var args = [];
|
|
1761
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
1762
|
-
args[_i - 2] = arguments[_i];
|
|
1763
|
-
}
|
|
1764
|
-
var delegate = timeoutProvider.delegate;
|
|
1765
|
-
if (delegate === null || delegate === void 0 ? void 0 : delegate.setTimeout) {
|
|
1766
|
-
return delegate.setTimeout.apply(delegate, __spreadArray([handler, timeout], __read(args)));
|
|
1767
|
-
}
|
|
1768
|
-
return setTimeout.apply(void 0, __spreadArray([handler, timeout], __read(args)));
|
|
1769
|
-
},
|
|
1770
|
-
clearTimeout: function (handle) {
|
|
1771
|
-
var delegate = timeoutProvider.delegate;
|
|
1772
|
-
return ((delegate === null || delegate === void 0 ? void 0 : delegate.clearTimeout) || clearTimeout)(handle);
|
|
1773
|
-
},
|
|
1774
|
-
delegate: undefined,
|
|
1775
|
-
};
|
|
1776
|
-
|
|
1777
|
-
function reportUnhandledError(err) {
|
|
1778
|
-
timeoutProvider.setTimeout(function () {
|
|
1779
|
-
{
|
|
1780
|
-
throw err;
|
|
1781
|
-
}
|
|
1782
|
-
});
|
|
1783
|
-
}
|
|
1784
|
-
|
|
1785
|
-
function noop() { }
|
|
1786
|
-
|
|
1787
|
-
function errorContext(cb) {
|
|
1788
|
-
{
|
|
1789
|
-
cb();
|
|
1790
|
-
}
|
|
1791
|
-
}
|
|
1792
|
-
|
|
1793
|
-
var Subscriber = (function (_super) {
|
|
1794
|
-
__extends(Subscriber, _super);
|
|
1795
|
-
function Subscriber(destination) {
|
|
1796
|
-
var _this = _super.call(this) || this;
|
|
1797
|
-
_this.isStopped = false;
|
|
1798
|
-
if (destination) {
|
|
1799
|
-
_this.destination = destination;
|
|
1800
|
-
if (isSubscription(destination)) {
|
|
1801
|
-
destination.add(_this);
|
|
1802
|
-
}
|
|
1803
|
-
}
|
|
1804
|
-
else {
|
|
1805
|
-
_this.destination = EMPTY_OBSERVER;
|
|
1806
|
-
}
|
|
1807
|
-
return _this;
|
|
1808
|
-
}
|
|
1809
|
-
Subscriber.create = function (next, error, complete) {
|
|
1810
|
-
return new SafeSubscriber(next, error, complete);
|
|
1811
|
-
};
|
|
1812
|
-
Subscriber.prototype.next = function (value) {
|
|
1813
|
-
if (this.isStopped) ;
|
|
1814
|
-
else {
|
|
1815
|
-
this._next(value);
|
|
1816
|
-
}
|
|
1817
|
-
};
|
|
1818
|
-
Subscriber.prototype.error = function (err) {
|
|
1819
|
-
if (this.isStopped) ;
|
|
1820
|
-
else {
|
|
1821
|
-
this.isStopped = true;
|
|
1822
|
-
this._error(err);
|
|
1823
|
-
}
|
|
1824
|
-
};
|
|
1825
|
-
Subscriber.prototype.complete = function () {
|
|
1826
|
-
if (this.isStopped) ;
|
|
1827
|
-
else {
|
|
1828
|
-
this.isStopped = true;
|
|
1829
|
-
this._complete();
|
|
1830
|
-
}
|
|
1831
|
-
};
|
|
1832
|
-
Subscriber.prototype.unsubscribe = function () {
|
|
1833
|
-
if (!this.closed) {
|
|
1834
|
-
this.isStopped = true;
|
|
1835
|
-
_super.prototype.unsubscribe.call(this);
|
|
1836
|
-
this.destination = null;
|
|
1837
|
-
}
|
|
1838
|
-
};
|
|
1839
|
-
Subscriber.prototype._next = function (value) {
|
|
1840
|
-
this.destination.next(value);
|
|
1841
|
-
};
|
|
1842
|
-
Subscriber.prototype._error = function (err) {
|
|
1843
|
-
try {
|
|
1844
|
-
this.destination.error(err);
|
|
1845
|
-
}
|
|
1846
|
-
finally {
|
|
1847
|
-
this.unsubscribe();
|
|
1848
|
-
}
|
|
1849
|
-
};
|
|
1850
|
-
Subscriber.prototype._complete = function () {
|
|
1851
|
-
try {
|
|
1852
|
-
this.destination.complete();
|
|
1853
|
-
}
|
|
1854
|
-
finally {
|
|
1855
|
-
this.unsubscribe();
|
|
1856
|
-
}
|
|
1857
|
-
};
|
|
1858
|
-
return Subscriber;
|
|
1859
|
-
}(Subscription));
|
|
1860
|
-
var _bind = Function.prototype.bind;
|
|
1861
|
-
function bind(fn, thisArg) {
|
|
1862
|
-
return _bind.call(fn, thisArg);
|
|
1863
|
-
}
|
|
1864
|
-
var ConsumerObserver = (function () {
|
|
1865
|
-
function ConsumerObserver(partialObserver) {
|
|
1866
|
-
this.partialObserver = partialObserver;
|
|
1867
|
-
}
|
|
1868
|
-
ConsumerObserver.prototype.next = function (value) {
|
|
1869
|
-
var partialObserver = this.partialObserver;
|
|
1870
|
-
if (partialObserver.next) {
|
|
1871
|
-
try {
|
|
1872
|
-
partialObserver.next(value);
|
|
1873
|
-
}
|
|
1874
|
-
catch (error) {
|
|
1875
|
-
handleUnhandledError(error);
|
|
1876
|
-
}
|
|
1877
|
-
}
|
|
1878
|
-
};
|
|
1879
|
-
ConsumerObserver.prototype.error = function (err) {
|
|
1880
|
-
var partialObserver = this.partialObserver;
|
|
1881
|
-
if (partialObserver.error) {
|
|
1882
|
-
try {
|
|
1883
|
-
partialObserver.error(err);
|
|
1884
|
-
}
|
|
1885
|
-
catch (error) {
|
|
1886
|
-
handleUnhandledError(error);
|
|
1887
|
-
}
|
|
1888
|
-
}
|
|
1889
|
-
else {
|
|
1890
|
-
handleUnhandledError(err);
|
|
1891
|
-
}
|
|
1892
|
-
};
|
|
1893
|
-
ConsumerObserver.prototype.complete = function () {
|
|
1894
|
-
var partialObserver = this.partialObserver;
|
|
1895
|
-
if (partialObserver.complete) {
|
|
1896
|
-
try {
|
|
1897
|
-
partialObserver.complete();
|
|
1898
|
-
}
|
|
1899
|
-
catch (error) {
|
|
1900
|
-
handleUnhandledError(error);
|
|
1901
|
-
}
|
|
1902
|
-
}
|
|
1903
|
-
};
|
|
1904
|
-
return ConsumerObserver;
|
|
1905
|
-
}());
|
|
1906
|
-
var SafeSubscriber = (function (_super) {
|
|
1907
|
-
__extends(SafeSubscriber, _super);
|
|
1908
|
-
function SafeSubscriber(observerOrNext, error, complete) {
|
|
1909
|
-
var _this = _super.call(this) || this;
|
|
1910
|
-
var partialObserver;
|
|
1911
|
-
if (isFunction(observerOrNext) || !observerOrNext) {
|
|
1912
|
-
partialObserver = {
|
|
1913
|
-
next: (observerOrNext !== null && observerOrNext !== void 0 ? observerOrNext : undefined),
|
|
1914
|
-
error: error !== null && error !== void 0 ? error : undefined,
|
|
1915
|
-
complete: complete !== null && complete !== void 0 ? complete : undefined,
|
|
1916
|
-
};
|
|
1917
|
-
}
|
|
1918
|
-
else {
|
|
1919
|
-
var context_1;
|
|
1920
|
-
if (_this && config.useDeprecatedNextContext) {
|
|
1921
|
-
context_1 = Object.create(observerOrNext);
|
|
1922
|
-
context_1.unsubscribe = function () { return _this.unsubscribe(); };
|
|
1923
|
-
partialObserver = {
|
|
1924
|
-
next: observerOrNext.next && bind(observerOrNext.next, context_1),
|
|
1925
|
-
error: observerOrNext.error && bind(observerOrNext.error, context_1),
|
|
1926
|
-
complete: observerOrNext.complete && bind(observerOrNext.complete, context_1),
|
|
1927
|
-
};
|
|
1928
|
-
}
|
|
1929
|
-
else {
|
|
1930
|
-
partialObserver = observerOrNext;
|
|
1931
|
-
}
|
|
1932
|
-
}
|
|
1933
|
-
_this.destination = new ConsumerObserver(partialObserver);
|
|
1934
|
-
return _this;
|
|
1935
|
-
}
|
|
1936
|
-
return SafeSubscriber;
|
|
1937
|
-
}(Subscriber));
|
|
1938
|
-
function handleUnhandledError(error) {
|
|
1939
|
-
{
|
|
1940
|
-
reportUnhandledError(error);
|
|
1941
|
-
}
|
|
1942
|
-
}
|
|
1943
|
-
function defaultErrorHandler(err) {
|
|
1944
|
-
throw err;
|
|
1945
|
-
}
|
|
1946
|
-
var EMPTY_OBSERVER = {
|
|
1947
|
-
closed: true,
|
|
1948
|
-
next: noop,
|
|
1949
|
-
error: defaultErrorHandler,
|
|
1950
|
-
complete: noop,
|
|
1951
|
-
};
|
|
1952
|
-
|
|
1953
|
-
var observable = (function () { return (typeof Symbol === 'function' && Symbol.observable) || '@@observable'; })();
|
|
1954
|
-
|
|
1955
|
-
function identity(x) {
|
|
1956
|
-
return x;
|
|
1957
|
-
}
|
|
1958
|
-
|
|
1959
|
-
function pipeFromArray(fns) {
|
|
1960
|
-
if (fns.length === 0) {
|
|
1961
|
-
return identity;
|
|
1962
|
-
}
|
|
1963
|
-
if (fns.length === 1) {
|
|
1964
|
-
return fns[0];
|
|
1965
|
-
}
|
|
1966
|
-
return function piped(input) {
|
|
1967
|
-
return fns.reduce(function (prev, fn) { return fn(prev); }, input);
|
|
1968
|
-
};
|
|
1969
|
-
}
|
|
1970
|
-
|
|
1971
|
-
var Observable = (function () {
|
|
1972
|
-
function Observable(subscribe) {
|
|
1973
|
-
if (subscribe) {
|
|
1974
|
-
this._subscribe = subscribe;
|
|
1975
|
-
}
|
|
1976
|
-
}
|
|
1977
|
-
Observable.prototype.lift = function (operator) {
|
|
1978
|
-
var observable = new Observable();
|
|
1979
|
-
observable.source = this;
|
|
1980
|
-
observable.operator = operator;
|
|
1981
|
-
return observable;
|
|
1982
|
-
};
|
|
1983
|
-
Observable.prototype.subscribe = function (observerOrNext, error, complete) {
|
|
1984
|
-
var _this = this;
|
|
1985
|
-
var subscriber = isSubscriber(observerOrNext) ? observerOrNext : new SafeSubscriber(observerOrNext, error, complete);
|
|
1986
|
-
errorContext(function () {
|
|
1987
|
-
var _a = _this, operator = _a.operator, source = _a.source;
|
|
1988
|
-
subscriber.add(operator
|
|
1989
|
-
?
|
|
1990
|
-
operator.call(subscriber, source)
|
|
1991
|
-
: source
|
|
1992
|
-
?
|
|
1993
|
-
_this._subscribe(subscriber)
|
|
1994
|
-
:
|
|
1995
|
-
_this._trySubscribe(subscriber));
|
|
1996
|
-
});
|
|
1997
|
-
return subscriber;
|
|
1998
|
-
};
|
|
1999
|
-
Observable.prototype._trySubscribe = function (sink) {
|
|
2000
|
-
try {
|
|
2001
|
-
return this._subscribe(sink);
|
|
2002
|
-
}
|
|
2003
|
-
catch (err) {
|
|
2004
|
-
sink.error(err);
|
|
2005
|
-
}
|
|
2006
|
-
};
|
|
2007
|
-
Observable.prototype.forEach = function (next, promiseCtor) {
|
|
2008
|
-
var _this = this;
|
|
2009
|
-
promiseCtor = getPromiseCtor(promiseCtor);
|
|
2010
|
-
return new promiseCtor(function (resolve, reject) {
|
|
2011
|
-
var subscriber = new SafeSubscriber({
|
|
2012
|
-
next: function (value) {
|
|
2013
|
-
try {
|
|
2014
|
-
next(value);
|
|
2015
|
-
}
|
|
2016
|
-
catch (err) {
|
|
2017
|
-
reject(err);
|
|
2018
|
-
subscriber.unsubscribe();
|
|
2019
|
-
}
|
|
2020
|
-
},
|
|
2021
|
-
error: reject,
|
|
2022
|
-
complete: resolve,
|
|
2023
|
-
});
|
|
2024
|
-
_this.subscribe(subscriber);
|
|
2025
|
-
});
|
|
2026
|
-
};
|
|
2027
|
-
Observable.prototype._subscribe = function (subscriber) {
|
|
2028
|
-
var _a;
|
|
2029
|
-
return (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber);
|
|
2030
|
-
};
|
|
2031
|
-
Observable.prototype[observable] = function () {
|
|
2032
|
-
return this;
|
|
2033
|
-
};
|
|
2034
|
-
Observable.prototype.pipe = function () {
|
|
2035
|
-
var operations = [];
|
|
2036
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2037
|
-
operations[_i] = arguments[_i];
|
|
2038
|
-
}
|
|
2039
|
-
return pipeFromArray(operations)(this);
|
|
2040
|
-
};
|
|
2041
|
-
Observable.prototype.toPromise = function (promiseCtor) {
|
|
2042
|
-
var _this = this;
|
|
2043
|
-
promiseCtor = getPromiseCtor(promiseCtor);
|
|
2044
|
-
return new promiseCtor(function (resolve, reject) {
|
|
2045
|
-
var value;
|
|
2046
|
-
_this.subscribe(function (x) { return (value = x); }, function (err) { return reject(err); }, function () { return resolve(value); });
|
|
2047
|
-
});
|
|
2048
|
-
};
|
|
2049
|
-
Observable.create = function (subscribe) {
|
|
2050
|
-
return new Observable(subscribe);
|
|
2051
|
-
};
|
|
2052
|
-
return Observable;
|
|
2053
|
-
}());
|
|
2054
|
-
function getPromiseCtor(promiseCtor) {
|
|
2055
|
-
var _a;
|
|
2056
|
-
return (_a = promiseCtor !== null && promiseCtor !== void 0 ? promiseCtor : config.Promise) !== null && _a !== void 0 ? _a : Promise;
|
|
2057
|
-
}
|
|
2058
|
-
function isObserver(value) {
|
|
2059
|
-
return value && isFunction(value.next) && isFunction(value.error) && isFunction(value.complete);
|
|
2060
|
-
}
|
|
2061
|
-
function isSubscriber(value) {
|
|
2062
|
-
return (value && value instanceof Subscriber) || (isObserver(value) && isSubscription(value));
|
|
2063
|
-
}
|
|
2064
|
-
|
|
2065
|
-
function isInteropObservable(input) {
|
|
2066
|
-
return isFunction(input[observable]);
|
|
2067
|
-
}
|
|
2068
|
-
|
|
2069
|
-
function isAsyncIterable(obj) {
|
|
2070
|
-
return Symbol.asyncIterator && isFunction(obj === null || obj === void 0 ? void 0 : obj[Symbol.asyncIterator]);
|
|
2071
|
-
}
|
|
2072
|
-
|
|
2073
|
-
function createInvalidObservableTypeError(input) {
|
|
2074
|
-
return new TypeError("You provided " + (input !== null && typeof input === 'object' ? 'an invalid object' : "'" + input + "'") + " where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.");
|
|
2075
|
-
}
|
|
2076
|
-
|
|
2077
|
-
function getSymbolIterator() {
|
|
2078
|
-
if (typeof Symbol !== 'function' || !Symbol.iterator) {
|
|
2079
|
-
return '@@iterator';
|
|
2080
|
-
}
|
|
2081
|
-
return Symbol.iterator;
|
|
2082
|
-
}
|
|
2083
|
-
var iterator = getSymbolIterator();
|
|
2084
|
-
|
|
2085
|
-
function isIterable(input) {
|
|
2086
|
-
return isFunction(input === null || input === void 0 ? void 0 : input[iterator]);
|
|
2087
|
-
}
|
|
2088
|
-
|
|
2089
|
-
function readableStreamLikeToAsyncGenerator(readableStream) {
|
|
2090
|
-
return __asyncGenerator(this, arguments, function readableStreamLikeToAsyncGenerator_1() {
|
|
2091
|
-
var reader, _a, value, done;
|
|
2092
|
-
return __generator(this, function (_b) {
|
|
2093
|
-
switch (_b.label) {
|
|
2094
|
-
case 0:
|
|
2095
|
-
reader = readableStream.getReader();
|
|
2096
|
-
_b.label = 1;
|
|
2097
|
-
case 1:
|
|
2098
|
-
_b.trys.push([1, , 9, 10]);
|
|
2099
|
-
_b.label = 2;
|
|
2100
|
-
case 2:
|
|
2101
|
-
return [4, __await(reader.read())];
|
|
2102
|
-
case 3:
|
|
2103
|
-
_a = _b.sent(), value = _a.value, done = _a.done;
|
|
2104
|
-
if (!done) return [3, 5];
|
|
2105
|
-
return [4, __await(void 0)];
|
|
2106
|
-
case 4: return [2, _b.sent()];
|
|
2107
|
-
case 5: return [4, __await(value)];
|
|
2108
|
-
case 6: return [4, _b.sent()];
|
|
2109
|
-
case 7:
|
|
2110
|
-
_b.sent();
|
|
2111
|
-
return [3, 2];
|
|
2112
|
-
case 8: return [3, 10];
|
|
2113
|
-
case 9:
|
|
2114
|
-
reader.releaseLock();
|
|
2115
|
-
return [7];
|
|
2116
|
-
case 10: return [2];
|
|
2117
|
-
}
|
|
2118
|
-
});
|
|
2119
|
-
});
|
|
2120
|
-
}
|
|
2121
|
-
function isReadableStreamLike(obj) {
|
|
2122
|
-
return isFunction(obj === null || obj === void 0 ? void 0 : obj.getReader);
|
|
2123
|
-
}
|
|
2124
|
-
|
|
2125
|
-
function innerFrom(input) {
|
|
2126
|
-
if (input instanceof Observable) {
|
|
2127
|
-
return input;
|
|
2128
|
-
}
|
|
2129
|
-
if (input != null) {
|
|
2130
|
-
if (isInteropObservable(input)) {
|
|
2131
|
-
return fromInteropObservable(input);
|
|
2132
|
-
}
|
|
2133
|
-
if (isArrayLike(input)) {
|
|
2134
|
-
return fromArrayLike(input);
|
|
2135
|
-
}
|
|
2136
|
-
if (isPromise(input)) {
|
|
2137
|
-
return fromPromise(input);
|
|
2138
|
-
}
|
|
2139
|
-
if (isAsyncIterable(input)) {
|
|
2140
|
-
return fromAsyncIterable(input);
|
|
2141
|
-
}
|
|
2142
|
-
if (isIterable(input)) {
|
|
2143
|
-
return fromIterable(input);
|
|
2144
|
-
}
|
|
2145
|
-
if (isReadableStreamLike(input)) {
|
|
2146
|
-
return fromReadableStreamLike(input);
|
|
2147
|
-
}
|
|
2148
|
-
}
|
|
2149
|
-
throw createInvalidObservableTypeError(input);
|
|
2150
|
-
}
|
|
2151
|
-
function fromInteropObservable(obj) {
|
|
2152
|
-
return new Observable(function (subscriber) {
|
|
2153
|
-
var obs = obj[observable]();
|
|
2154
|
-
if (isFunction(obs.subscribe)) {
|
|
2155
|
-
return obs.subscribe(subscriber);
|
|
2156
|
-
}
|
|
2157
|
-
throw new TypeError('Provided object does not correctly implement Symbol.observable');
|
|
2158
|
-
});
|
|
2159
|
-
}
|
|
2160
|
-
function fromArrayLike(array) {
|
|
2161
|
-
return new Observable(function (subscriber) {
|
|
2162
|
-
for (var i = 0; i < array.length && !subscriber.closed; i++) {
|
|
2163
|
-
subscriber.next(array[i]);
|
|
2164
|
-
}
|
|
2165
|
-
subscriber.complete();
|
|
2166
|
-
});
|
|
2167
|
-
}
|
|
2168
|
-
function fromPromise(promise) {
|
|
2169
|
-
return new Observable(function (subscriber) {
|
|
2170
|
-
promise
|
|
2171
|
-
.then(function (value) {
|
|
2172
|
-
if (!subscriber.closed) {
|
|
2173
|
-
subscriber.next(value);
|
|
2174
|
-
subscriber.complete();
|
|
2175
|
-
}
|
|
2176
|
-
}, function (err) { return subscriber.error(err); })
|
|
2177
|
-
.then(null, reportUnhandledError);
|
|
2178
|
-
});
|
|
2179
|
-
}
|
|
2180
|
-
function fromIterable(iterable) {
|
|
2181
|
-
return new Observable(function (subscriber) {
|
|
2182
|
-
var e_1, _a;
|
|
2183
|
-
try {
|
|
2184
|
-
for (var iterable_1 = __values(iterable), iterable_1_1 = iterable_1.next(); !iterable_1_1.done; iterable_1_1 = iterable_1.next()) {
|
|
2185
|
-
var value = iterable_1_1.value;
|
|
2186
|
-
subscriber.next(value);
|
|
2187
|
-
if (subscriber.closed) {
|
|
2188
|
-
return;
|
|
2189
|
-
}
|
|
2190
|
-
}
|
|
2191
|
-
}
|
|
2192
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2193
|
-
finally {
|
|
2194
|
-
try {
|
|
2195
|
-
if (iterable_1_1 && !iterable_1_1.done && (_a = iterable_1.return)) _a.call(iterable_1);
|
|
2196
|
-
}
|
|
2197
|
-
finally { if (e_1) throw e_1.error; }
|
|
2198
|
-
}
|
|
2199
|
-
subscriber.complete();
|
|
2200
|
-
});
|
|
2201
|
-
}
|
|
2202
|
-
function fromAsyncIterable(asyncIterable) {
|
|
2203
|
-
return new Observable(function (subscriber) {
|
|
2204
|
-
process(asyncIterable, subscriber).catch(function (err) { return subscriber.error(err); });
|
|
2205
|
-
});
|
|
2206
|
-
}
|
|
2207
|
-
function fromReadableStreamLike(readableStream) {
|
|
2208
|
-
return fromAsyncIterable(readableStreamLikeToAsyncGenerator(readableStream));
|
|
2209
|
-
}
|
|
2210
|
-
function process(asyncIterable, subscriber) {
|
|
2211
|
-
var asyncIterable_1, asyncIterable_1_1;
|
|
2212
|
-
var e_2, _a;
|
|
2213
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
2214
|
-
var value, e_2_1;
|
|
2215
|
-
return __generator(this, function (_b) {
|
|
2216
|
-
switch (_b.label) {
|
|
2217
|
-
case 0:
|
|
2218
|
-
_b.trys.push([0, 5, 6, 11]);
|
|
2219
|
-
asyncIterable_1 = __asyncValues(asyncIterable);
|
|
2220
|
-
_b.label = 1;
|
|
2221
|
-
case 1: return [4, asyncIterable_1.next()];
|
|
2222
|
-
case 2:
|
|
2223
|
-
if (!(asyncIterable_1_1 = _b.sent(), !asyncIterable_1_1.done)) return [3, 4];
|
|
2224
|
-
value = asyncIterable_1_1.value;
|
|
2225
|
-
subscriber.next(value);
|
|
2226
|
-
if (subscriber.closed) {
|
|
2227
|
-
return [2];
|
|
2228
|
-
}
|
|
2229
|
-
_b.label = 3;
|
|
2230
|
-
case 3: return [3, 1];
|
|
2231
|
-
case 4: return [3, 11];
|
|
2232
|
-
case 5:
|
|
2233
|
-
e_2_1 = _b.sent();
|
|
2234
|
-
e_2 = { error: e_2_1 };
|
|
2235
|
-
return [3, 11];
|
|
2236
|
-
case 6:
|
|
2237
|
-
_b.trys.push([6, , 9, 10]);
|
|
2238
|
-
if (!(asyncIterable_1_1 && !asyncIterable_1_1.done && (_a = asyncIterable_1.return))) return [3, 8];
|
|
2239
|
-
return [4, _a.call(asyncIterable_1)];
|
|
2240
|
-
case 7:
|
|
2241
|
-
_b.sent();
|
|
2242
|
-
_b.label = 8;
|
|
2243
|
-
case 8: return [3, 10];
|
|
2244
|
-
case 9:
|
|
2245
|
-
if (e_2) throw e_2.error;
|
|
2246
|
-
return [7];
|
|
2247
|
-
case 10: return [7];
|
|
2248
|
-
case 11:
|
|
2249
|
-
subscriber.complete();
|
|
2250
|
-
return [2];
|
|
2251
|
-
}
|
|
2252
|
-
});
|
|
2253
|
-
});
|
|
2254
|
-
}
|
|
2255
|
-
|
|
2256
|
-
function createOperatorSubscriber(destination, onNext, onComplete, onError, onFinalize) {
|
|
2257
|
-
return new OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize);
|
|
2258
|
-
}
|
|
2259
|
-
var OperatorSubscriber = (function (_super) {
|
|
2260
|
-
__extends(OperatorSubscriber, _super);
|
|
2261
|
-
function OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize, shouldUnsubscribe) {
|
|
2262
|
-
var _this = _super.call(this, destination) || this;
|
|
2263
|
-
_this.onFinalize = onFinalize;
|
|
2264
|
-
_this.shouldUnsubscribe = shouldUnsubscribe;
|
|
2265
|
-
_this._next = onNext
|
|
2266
|
-
? function (value) {
|
|
2267
|
-
try {
|
|
2268
|
-
onNext(value);
|
|
2269
|
-
}
|
|
2270
|
-
catch (err) {
|
|
2271
|
-
destination.error(err);
|
|
2272
|
-
}
|
|
2273
|
-
}
|
|
2274
|
-
: _super.prototype._next;
|
|
2275
|
-
_this._error = onError
|
|
2276
|
-
? function (err) {
|
|
2277
|
-
try {
|
|
2278
|
-
onError(err);
|
|
2279
|
-
}
|
|
2280
|
-
catch (err) {
|
|
2281
|
-
destination.error(err);
|
|
2282
|
-
}
|
|
2283
|
-
finally {
|
|
2284
|
-
this.unsubscribe();
|
|
2285
|
-
}
|
|
2286
|
-
}
|
|
2287
|
-
: _super.prototype._error;
|
|
2288
|
-
_this._complete = onComplete
|
|
2289
|
-
? function () {
|
|
2290
|
-
try {
|
|
2291
|
-
onComplete();
|
|
2292
|
-
}
|
|
2293
|
-
catch (err) {
|
|
2294
|
-
destination.error(err);
|
|
2295
|
-
}
|
|
2296
|
-
finally {
|
|
2297
|
-
this.unsubscribe();
|
|
2298
|
-
}
|
|
2299
|
-
}
|
|
2300
|
-
: _super.prototype._complete;
|
|
2301
|
-
return _this;
|
|
2302
|
-
}
|
|
2303
|
-
OperatorSubscriber.prototype.unsubscribe = function () {
|
|
2304
|
-
var _a;
|
|
2305
|
-
if (!this.shouldUnsubscribe || this.shouldUnsubscribe()) {
|
|
2306
|
-
var closed_1 = this.closed;
|
|
2307
|
-
_super.prototype.unsubscribe.call(this);
|
|
2308
|
-
!closed_1 && ((_a = this.onFinalize) === null || _a === void 0 ? void 0 : _a.call(this));
|
|
2309
|
-
}
|
|
2310
|
-
};
|
|
2311
|
-
return OperatorSubscriber;
|
|
2312
|
-
}(Subscriber));
|
|
2313
|
-
|
|
2314
|
-
var Action = (function (_super) {
|
|
2315
|
-
__extends(Action, _super);
|
|
2316
|
-
function Action(scheduler, work) {
|
|
2317
|
-
return _super.call(this) || this;
|
|
2318
|
-
}
|
|
2319
|
-
Action.prototype.schedule = function (state, delay) {
|
|
2320
|
-
return this;
|
|
2321
|
-
};
|
|
2322
|
-
return Action;
|
|
2323
|
-
}(Subscription));
|
|
2324
|
-
|
|
2325
|
-
var intervalProvider = {
|
|
2326
|
-
setInterval: function (handler, timeout) {
|
|
2327
|
-
var args = [];
|
|
2328
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
2329
|
-
args[_i - 2] = arguments[_i];
|
|
2330
|
-
}
|
|
2331
|
-
var delegate = intervalProvider.delegate;
|
|
2332
|
-
if (delegate === null || delegate === void 0 ? void 0 : delegate.setInterval) {
|
|
2333
|
-
return delegate.setInterval.apply(delegate, __spreadArray([handler, timeout], __read(args)));
|
|
2334
|
-
}
|
|
2335
|
-
return setInterval.apply(void 0, __spreadArray([handler, timeout], __read(args)));
|
|
2336
|
-
},
|
|
2337
|
-
clearInterval: function (handle) {
|
|
2338
|
-
var delegate = intervalProvider.delegate;
|
|
2339
|
-
return ((delegate === null || delegate === void 0 ? void 0 : delegate.clearInterval) || clearInterval)(handle);
|
|
2340
|
-
},
|
|
2341
|
-
delegate: undefined,
|
|
2342
|
-
};
|
|
2343
|
-
|
|
2344
|
-
var AsyncAction = (function (_super) {
|
|
2345
|
-
__extends(AsyncAction, _super);
|
|
2346
|
-
function AsyncAction(scheduler, work) {
|
|
2347
|
-
var _this = _super.call(this, scheduler, work) || this;
|
|
2348
|
-
_this.scheduler = scheduler;
|
|
2349
|
-
_this.work = work;
|
|
2350
|
-
_this.pending = false;
|
|
2351
|
-
return _this;
|
|
2352
|
-
}
|
|
2353
|
-
AsyncAction.prototype.schedule = function (state, delay) {
|
|
2354
|
-
if (delay === void 0) { delay = 0; }
|
|
2355
|
-
if (this.closed) {
|
|
2356
|
-
return this;
|
|
2357
|
-
}
|
|
2358
|
-
this.state = state;
|
|
2359
|
-
var id = this.id;
|
|
2360
|
-
var scheduler = this.scheduler;
|
|
2361
|
-
if (id != null) {
|
|
2362
|
-
this.id = this.recycleAsyncId(scheduler, id, delay);
|
|
2363
|
-
}
|
|
2364
|
-
this.pending = true;
|
|
2365
|
-
this.delay = delay;
|
|
2366
|
-
this.id = this.id || this.requestAsyncId(scheduler, this.id, delay);
|
|
2367
|
-
return this;
|
|
2368
|
-
};
|
|
2369
|
-
AsyncAction.prototype.requestAsyncId = function (scheduler, _id, delay) {
|
|
2370
|
-
if (delay === void 0) { delay = 0; }
|
|
2371
|
-
return intervalProvider.setInterval(scheduler.flush.bind(scheduler, this), delay);
|
|
2372
|
-
};
|
|
2373
|
-
AsyncAction.prototype.recycleAsyncId = function (_scheduler, id, delay) {
|
|
2374
|
-
if (delay === void 0) { delay = 0; }
|
|
2375
|
-
if (delay != null && this.delay === delay && this.pending === false) {
|
|
2376
|
-
return id;
|
|
2377
|
-
}
|
|
2378
|
-
intervalProvider.clearInterval(id);
|
|
2379
|
-
return undefined;
|
|
2380
|
-
};
|
|
2381
|
-
AsyncAction.prototype.execute = function (state, delay) {
|
|
2382
|
-
if (this.closed) {
|
|
2383
|
-
return new Error('executing a cancelled action');
|
|
2384
|
-
}
|
|
2385
|
-
this.pending = false;
|
|
2386
|
-
var error = this._execute(state, delay);
|
|
2387
|
-
if (error) {
|
|
2388
|
-
return error;
|
|
2389
|
-
}
|
|
2390
|
-
else if (this.pending === false && this.id != null) {
|
|
2391
|
-
this.id = this.recycleAsyncId(this.scheduler, this.id, null);
|
|
2392
|
-
}
|
|
2393
|
-
};
|
|
2394
|
-
AsyncAction.prototype._execute = function (state, _delay) {
|
|
2395
|
-
var errored = false;
|
|
2396
|
-
var errorValue;
|
|
2397
|
-
try {
|
|
2398
|
-
this.work(state);
|
|
2399
|
-
}
|
|
2400
|
-
catch (e) {
|
|
2401
|
-
errored = true;
|
|
2402
|
-
errorValue = e ? e : new Error('Scheduled action threw falsy error');
|
|
2403
|
-
}
|
|
2404
|
-
if (errored) {
|
|
2405
|
-
this.unsubscribe();
|
|
2406
|
-
return errorValue;
|
|
2407
|
-
}
|
|
2408
|
-
};
|
|
2409
|
-
AsyncAction.prototype.unsubscribe = function () {
|
|
2410
|
-
if (!this.closed) {
|
|
2411
|
-
var _a = this, id = _a.id, scheduler = _a.scheduler;
|
|
2412
|
-
var actions = scheduler.actions;
|
|
2413
|
-
this.work = this.state = this.scheduler = null;
|
|
2414
|
-
this.pending = false;
|
|
2415
|
-
arrRemove(actions, this);
|
|
2416
|
-
if (id != null) {
|
|
2417
|
-
this.id = this.recycleAsyncId(scheduler, id, null);
|
|
2418
|
-
}
|
|
2419
|
-
this.delay = null;
|
|
2420
|
-
_super.prototype.unsubscribe.call(this);
|
|
2421
|
-
}
|
|
2422
|
-
};
|
|
2423
|
-
return AsyncAction;
|
|
2424
|
-
}(Action));
|
|
2425
|
-
|
|
2426
|
-
var dateTimestampProvider = {
|
|
2427
|
-
now: function () {
|
|
2428
|
-
return (dateTimestampProvider.delegate || Date).now();
|
|
2429
|
-
},
|
|
2430
|
-
delegate: undefined,
|
|
2431
|
-
};
|
|
2432
|
-
|
|
2433
|
-
var Scheduler = (function () {
|
|
2434
|
-
function Scheduler(schedulerActionCtor, now) {
|
|
2435
|
-
if (now === void 0) { now = Scheduler.now; }
|
|
2436
|
-
this.schedulerActionCtor = schedulerActionCtor;
|
|
2437
|
-
this.now = now;
|
|
2438
|
-
}
|
|
2439
|
-
Scheduler.prototype.schedule = function (work, delay, state) {
|
|
2440
|
-
if (delay === void 0) { delay = 0; }
|
|
2441
|
-
return new this.schedulerActionCtor(this, work).schedule(state, delay);
|
|
2442
|
-
};
|
|
2443
|
-
Scheduler.now = dateTimestampProvider.now;
|
|
2444
|
-
return Scheduler;
|
|
2445
|
-
}());
|
|
2446
|
-
|
|
2447
|
-
var AsyncScheduler = (function (_super) {
|
|
2448
|
-
__extends(AsyncScheduler, _super);
|
|
2449
|
-
function AsyncScheduler(SchedulerAction, now) {
|
|
2450
|
-
if (now === void 0) { now = Scheduler.now; }
|
|
2451
|
-
var _this = _super.call(this, SchedulerAction, now) || this;
|
|
2452
|
-
_this.actions = [];
|
|
2453
|
-
_this._active = false;
|
|
2454
|
-
_this._scheduled = undefined;
|
|
2455
|
-
return _this;
|
|
2456
|
-
}
|
|
2457
|
-
AsyncScheduler.prototype.flush = function (action) {
|
|
2458
|
-
var actions = this.actions;
|
|
2459
|
-
if (this._active) {
|
|
2460
|
-
actions.push(action);
|
|
2461
|
-
return;
|
|
2462
|
-
}
|
|
2463
|
-
var error;
|
|
2464
|
-
this._active = true;
|
|
2465
|
-
do {
|
|
2466
|
-
if ((error = action.execute(action.state, action.delay))) {
|
|
2467
|
-
break;
|
|
2468
|
-
}
|
|
2469
|
-
} while ((action = actions.shift()));
|
|
2470
|
-
this._active = false;
|
|
2471
|
-
if (error) {
|
|
2472
|
-
while ((action = actions.shift())) {
|
|
2473
|
-
action.unsubscribe();
|
|
2474
|
-
}
|
|
2475
|
-
throw error;
|
|
2476
|
-
}
|
|
2477
|
-
};
|
|
2478
|
-
return AsyncScheduler;
|
|
2479
|
-
}(Scheduler));
|
|
2480
|
-
|
|
2481
|
-
var asyncScheduler = new AsyncScheduler(AsyncAction);
|
|
2482
|
-
var async = asyncScheduler;
|
|
2483
|
-
|
|
2484
|
-
function isScheduler(value) {
|
|
2485
|
-
return value && isFunction(value.schedule);
|
|
2486
|
-
}
|
|
2487
|
-
|
|
2488
|
-
function isValidDate(value) {
|
|
2489
|
-
return value instanceof Date && !isNaN(value);
|
|
2490
|
-
}
|
|
2491
|
-
|
|
2492
|
-
function timer(dueTime, intervalOrScheduler, scheduler) {
|
|
2493
|
-
if (dueTime === void 0) { dueTime = 0; }
|
|
2494
|
-
if (scheduler === void 0) { scheduler = async; }
|
|
2495
|
-
var intervalDuration = -1;
|
|
2496
|
-
if (intervalOrScheduler != null) {
|
|
2497
|
-
if (isScheduler(intervalOrScheduler)) {
|
|
2498
|
-
scheduler = intervalOrScheduler;
|
|
2499
|
-
}
|
|
2500
|
-
else {
|
|
2501
|
-
intervalDuration = intervalOrScheduler;
|
|
2502
|
-
}
|
|
2503
|
-
}
|
|
2504
|
-
return new Observable(function (subscriber) {
|
|
2505
|
-
var due = isValidDate(dueTime) ? +dueTime - scheduler.now() : dueTime;
|
|
2506
|
-
if (due < 0) {
|
|
2507
|
-
due = 0;
|
|
2508
|
-
}
|
|
2509
|
-
var n = 0;
|
|
2510
|
-
return scheduler.schedule(function () {
|
|
2511
|
-
if (!subscriber.closed) {
|
|
2512
|
-
subscriber.next(n++);
|
|
2513
|
-
if (0 <= intervalDuration) {
|
|
2514
|
-
this.schedule(undefined, intervalDuration);
|
|
2515
|
-
}
|
|
2516
|
-
else {
|
|
2517
|
-
subscriber.complete();
|
|
2518
|
-
}
|
|
2519
|
-
}
|
|
2520
|
-
}, due);
|
|
2521
|
-
});
|
|
2522
|
-
}
|
|
2523
|
-
|
|
2524
|
-
function last(arr) {
|
|
2525
|
-
return arr[arr.length - 1];
|
|
2526
|
-
}
|
|
2527
|
-
function popScheduler(args) {
|
|
2528
|
-
return isScheduler(last(args)) ? args.pop() : undefined;
|
|
2529
|
-
}
|
|
2530
|
-
|
|
2531
|
-
function executeSchedule(parentSubscription, scheduler, work, delay, repeat) {
|
|
2532
|
-
if (delay === void 0) { delay = 0; }
|
|
2533
|
-
if (repeat === void 0) { repeat = false; }
|
|
2534
|
-
var scheduleSubscription = scheduler.schedule(function () {
|
|
2535
|
-
work();
|
|
2536
|
-
if (repeat) {
|
|
2537
|
-
parentSubscription.add(this.schedule(null, delay));
|
|
2538
|
-
}
|
|
2539
|
-
else {
|
|
2540
|
-
this.unsubscribe();
|
|
2541
|
-
}
|
|
2542
|
-
}, delay);
|
|
2543
|
-
parentSubscription.add(scheduleSubscription);
|
|
2544
|
-
if (!repeat) {
|
|
2545
|
-
return scheduleSubscription;
|
|
2546
|
-
}
|
|
2547
|
-
}
|
|
2548
|
-
|
|
2549
|
-
function catchError(selector) {
|
|
2550
|
-
return operate(function (source, subscriber) {
|
|
2551
|
-
var innerSub = null;
|
|
2552
|
-
var syncUnsub = false;
|
|
2553
|
-
var handledResult;
|
|
2554
|
-
innerSub = source.subscribe(createOperatorSubscriber(subscriber, undefined, undefined, function (err) {
|
|
2555
|
-
handledResult = innerFrom(selector(err, catchError(selector)(source)));
|
|
2556
|
-
if (innerSub) {
|
|
2557
|
-
innerSub.unsubscribe();
|
|
2558
|
-
innerSub = null;
|
|
2559
|
-
handledResult.subscribe(subscriber);
|
|
2560
|
-
}
|
|
2561
|
-
else {
|
|
2562
|
-
syncUnsub = true;
|
|
518
|
+
u: readVarUint8Array(decoder),
|
|
519
|
+
r: (decoder.pos < decoder.arr.length && readVarString(decoder)) || undefined,
|
|
520
|
+
};
|
|
521
|
+
default:
|
|
522
|
+
throw new TypeError(`Unknown message type: ${type}`);
|
|
2563
523
|
}
|
|
2564
|
-
}));
|
|
2565
|
-
if (syncUnsub) {
|
|
2566
|
-
innerSub.unsubscribe();
|
|
2567
|
-
innerSub = null;
|
|
2568
|
-
handledResult.subscribe(subscriber);
|
|
2569
524
|
}
|
|
2570
|
-
});
|
|
2571
|
-
}
|
|
2572
|
-
|
|
2573
|
-
function observeOn(scheduler, delay) {
|
|
2574
|
-
if (delay === void 0) { delay = 0; }
|
|
2575
|
-
return operate(function (source, subscriber) {
|
|
2576
|
-
source.subscribe(createOperatorSubscriber(subscriber, function (value) { return executeSchedule(subscriber, scheduler, function () { return subscriber.next(value); }, delay); }, function () { return executeSchedule(subscriber, scheduler, function () { return subscriber.complete(); }, delay); }, function (err) { return executeSchedule(subscriber, scheduler, function () { return subscriber.error(err); }, delay); }));
|
|
2577
|
-
});
|
|
2578
|
-
}
|
|
2579
|
-
|
|
2580
|
-
function subscribeOn(scheduler, delay) {
|
|
2581
|
-
if (delay === void 0) { delay = 0; }
|
|
2582
|
-
return operate(function (source, subscriber) {
|
|
2583
|
-
subscriber.add(scheduler.schedule(function () { return source.subscribe(subscriber); }, delay));
|
|
2584
|
-
});
|
|
2585
|
-
}
|
|
2586
|
-
|
|
2587
|
-
function scheduleObservable(input, scheduler) {
|
|
2588
|
-
return innerFrom(input).pipe(subscribeOn(scheduler), observeOn(scheduler));
|
|
2589
|
-
}
|
|
2590
|
-
|
|
2591
|
-
function schedulePromise(input, scheduler) {
|
|
2592
|
-
return innerFrom(input).pipe(subscribeOn(scheduler), observeOn(scheduler));
|
|
2593
|
-
}
|
|
2594
|
-
|
|
2595
|
-
function scheduleArray(input, scheduler) {
|
|
2596
|
-
return new Observable(function (subscriber) {
|
|
2597
|
-
var i = 0;
|
|
2598
|
-
return scheduler.schedule(function () {
|
|
2599
|
-
if (i === input.length) {
|
|
2600
|
-
subscriber.complete();
|
|
2601
|
-
}
|
|
2602
|
-
else {
|
|
2603
|
-
subscriber.next(input[i++]);
|
|
2604
|
-
if (!subscriber.closed) {
|
|
2605
|
-
this.schedule();
|
|
2606
|
-
}
|
|
2607
|
-
}
|
|
2608
|
-
});
|
|
2609
|
-
});
|
|
2610
|
-
}
|
|
2611
|
-
|
|
2612
|
-
function scheduleIterable(input, scheduler) {
|
|
2613
|
-
return new Observable(function (subscriber) {
|
|
2614
|
-
var iterator$1;
|
|
2615
|
-
executeSchedule(subscriber, scheduler, function () {
|
|
2616
|
-
iterator$1 = input[iterator]();
|
|
2617
|
-
executeSchedule(subscriber, scheduler, function () {
|
|
2618
|
-
var _a;
|
|
2619
|
-
var value;
|
|
2620
|
-
var done;
|
|
2621
|
-
try {
|
|
2622
|
-
(_a = iterator$1.next(), value = _a.value, done = _a.done);
|
|
2623
|
-
}
|
|
2624
|
-
catch (err) {
|
|
2625
|
-
subscriber.error(err);
|
|
2626
|
-
return;
|
|
2627
|
-
}
|
|
2628
|
-
if (done) {
|
|
2629
|
-
subscriber.complete();
|
|
2630
|
-
}
|
|
2631
|
-
else {
|
|
2632
|
-
subscriber.next(value);
|
|
2633
|
-
}
|
|
2634
|
-
}, 0, true);
|
|
2635
|
-
});
|
|
2636
|
-
return function () { return isFunction(iterator$1 === null || iterator$1 === void 0 ? void 0 : iterator$1.return) && iterator$1.return(); };
|
|
2637
|
-
});
|
|
2638
|
-
}
|
|
2639
|
-
|
|
2640
|
-
function scheduleAsyncIterable(input, scheduler) {
|
|
2641
|
-
if (!input) {
|
|
2642
|
-
throw new Error('Iterable cannot be null');
|
|
2643
525
|
}
|
|
2644
|
-
return new Observable(function (subscriber) {
|
|
2645
|
-
executeSchedule(subscriber, scheduler, function () {
|
|
2646
|
-
var iterator = input[Symbol.asyncIterator]();
|
|
2647
|
-
executeSchedule(subscriber, scheduler, function () {
|
|
2648
|
-
iterator.next().then(function (result) {
|
|
2649
|
-
if (result.done) {
|
|
2650
|
-
subscriber.complete();
|
|
2651
|
-
}
|
|
2652
|
-
else {
|
|
2653
|
-
subscriber.next(result.value);
|
|
2654
|
-
}
|
|
2655
|
-
});
|
|
2656
|
-
}, 0, true);
|
|
2657
|
-
});
|
|
2658
|
-
});
|
|
2659
|
-
}
|
|
2660
|
-
|
|
2661
|
-
function scheduleReadableStreamLike(input, scheduler) {
|
|
2662
|
-
return scheduleAsyncIterable(readableStreamLikeToAsyncGenerator(input), scheduler);
|
|
2663
526
|
}
|
|
2664
527
|
|
|
2665
|
-
function
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
if (isIterable(input)) {
|
|
2680
|
-
return scheduleIterable(input, scheduler);
|
|
528
|
+
async function asyncIterablePipeline(source, ...stages) {
|
|
529
|
+
var _a, e_1, _b, _c;
|
|
530
|
+
// Chain generators by sending outdata from one to another
|
|
531
|
+
let result = source(); // Start with the source generator
|
|
532
|
+
for (let i = 0; i < stages.length; i++) {
|
|
533
|
+
result = stages[i](result); // Pass on the result to next generator
|
|
534
|
+
}
|
|
535
|
+
try {
|
|
536
|
+
// Start running the machine. If the last stage is a sink, it will consume the data and never emit anything
|
|
537
|
+
// to us here...
|
|
538
|
+
for (var _d = true, result_1 = __asyncValues(result), result_1_1; result_1_1 = await result_1.next(), _a = result_1_1.done, !_a; _d = true) {
|
|
539
|
+
_c = result_1_1.value;
|
|
540
|
+
_d = false;
|
|
541
|
+
const chunk = _c;
|
|
2681
542
|
}
|
|
2682
|
-
|
|
2683
|
-
|
|
543
|
+
}
|
|
544
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
545
|
+
finally {
|
|
546
|
+
try {
|
|
547
|
+
if (!_d && !_a && (_b = result_1.return)) await _b.call(result_1);
|
|
2684
548
|
}
|
|
549
|
+
finally { if (e_1) throw e_1.error; }
|
|
2685
550
|
}
|
|
2686
|
-
throw createInvalidObservableTypeError(input);
|
|
2687
|
-
}
|
|
2688
|
-
|
|
2689
|
-
function from(input, scheduler) {
|
|
2690
|
-
return scheduler ? scheduled(input, scheduler) : innerFrom(input);
|
|
2691
|
-
}
|
|
2692
|
-
|
|
2693
|
-
function map(project, thisArg) {
|
|
2694
|
-
return operate(function (source, subscriber) {
|
|
2695
|
-
var index = 0;
|
|
2696
|
-
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
2697
|
-
subscriber.next(project.call(thisArg, value, index++));
|
|
2698
|
-
}));
|
|
2699
|
-
});
|
|
2700
551
|
}
|
|
2701
552
|
|
|
2702
|
-
function
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
553
|
+
function consumeChunkedBinaryStream(source) {
|
|
554
|
+
return __asyncGenerator(this, arguments, function* consumeChunkedBinaryStream_1() {
|
|
555
|
+
var _a, e_1, _b, _c;
|
|
556
|
+
let state = 0;
|
|
557
|
+
let sizeBuf = new Uint8Array(4);
|
|
558
|
+
let sizeBufPos = 0;
|
|
559
|
+
let bufs = [];
|
|
560
|
+
let len = 0;
|
|
561
|
+
try {
|
|
562
|
+
for (var _d = true, source_1 = __asyncValues(source), source_1_1; source_1_1 = yield __await(source_1.next()), _a = source_1_1.done, !_a; _d = true) {
|
|
563
|
+
_c = source_1_1.value;
|
|
564
|
+
_d = false;
|
|
565
|
+
const chunk = _c;
|
|
566
|
+
const dw = new DataView(chunk.buffer, chunk.byteOffset, chunk.byteLength);
|
|
567
|
+
let pos = 0;
|
|
568
|
+
while (pos < chunk.byteLength) {
|
|
569
|
+
switch (state) {
|
|
570
|
+
case 0:
|
|
571
|
+
// Beginning of a size header
|
|
572
|
+
if (pos + 4 > chunk.byteLength) {
|
|
573
|
+
for (const b of chunk.slice(pos)) {
|
|
574
|
+
if (sizeBufPos === 4)
|
|
575
|
+
break;
|
|
576
|
+
sizeBuf[sizeBufPos++] = b;
|
|
577
|
+
++pos;
|
|
578
|
+
}
|
|
579
|
+
if (sizeBufPos < 4) {
|
|
580
|
+
// Need more bytes in order to read length.
|
|
581
|
+
// Will go out from while loop as well because pos is defenitely = chunk.byteLength here.
|
|
582
|
+
break;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
else if (sizeBufPos > 0 && sizeBufPos < 4) {
|
|
586
|
+
for (const b of chunk.slice(pos, pos + 4 - sizeBufPos)) {
|
|
587
|
+
sizeBuf[sizeBufPos++] = b;
|
|
588
|
+
++pos;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
// Intentional fall-through...
|
|
592
|
+
case 1:
|
|
593
|
+
len =
|
|
594
|
+
sizeBufPos === 4
|
|
595
|
+
? new DataView(sizeBuf.buffer, 0, 4).getUint32(0, false)
|
|
596
|
+
: dw.getUint32(pos, false);
|
|
597
|
+
if (sizeBufPos)
|
|
598
|
+
sizeBufPos = 0; // in this case pos is already forwarded
|
|
599
|
+
else
|
|
600
|
+
pos += 4; // else pos is not yet forwarded - that's why we do it now
|
|
601
|
+
// Intentional fall-through...
|
|
602
|
+
case 2:
|
|
603
|
+
// Eat the chunk
|
|
604
|
+
if (pos >= chunk.byteLength) {
|
|
605
|
+
state = 2;
|
|
606
|
+
break;
|
|
607
|
+
}
|
|
608
|
+
if (pos + len > chunk.byteLength) {
|
|
609
|
+
bufs.push(chunk.slice(pos));
|
|
610
|
+
len -= (chunk.byteLength - pos);
|
|
611
|
+
state = 2;
|
|
612
|
+
pos = chunk.byteLength; // will break while loop.
|
|
613
|
+
}
|
|
614
|
+
else {
|
|
615
|
+
if (bufs.length > 0) {
|
|
616
|
+
const concats = new Uint8Array(bufs.reduce((p, c) => p + c.byteLength, len));
|
|
617
|
+
let p = 0;
|
|
618
|
+
for (const buf of bufs) {
|
|
619
|
+
concats.set(buf, p);
|
|
620
|
+
p += buf.byteLength;
|
|
621
|
+
}
|
|
622
|
+
concats.set(chunk.slice(pos, pos + len), p);
|
|
623
|
+
bufs = [];
|
|
624
|
+
yield yield __await(concats);
|
|
625
|
+
}
|
|
626
|
+
else {
|
|
627
|
+
yield yield __await(chunk.slice(pos, pos + len));
|
|
628
|
+
}
|
|
629
|
+
pos += len;
|
|
630
|
+
state = 0;
|
|
631
|
+
}
|
|
632
|
+
break;
|
|
2742
633
|
}
|
|
2743
|
-
checkComplete();
|
|
2744
|
-
}
|
|
2745
|
-
catch (err) {
|
|
2746
|
-
subscriber.error(err);
|
|
2747
634
|
}
|
|
2748
635
|
}
|
|
2749
|
-
}
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
}));
|
|
2755
|
-
return function () {
|
|
2756
|
-
additionalFinalizer === null || additionalFinalizer === void 0 ? void 0 : additionalFinalizer();
|
|
2757
|
-
};
|
|
2758
|
-
}
|
|
2759
|
-
|
|
2760
|
-
function mergeMap(project, resultSelector, concurrent) {
|
|
2761
|
-
if (concurrent === void 0) { concurrent = Infinity; }
|
|
2762
|
-
if (isFunction(resultSelector)) {
|
|
2763
|
-
return mergeMap(function (a, i) { return map(function (b, ii) { return resultSelector(a, b, i, ii); })(innerFrom(project(a, i))); }, concurrent);
|
|
2764
|
-
}
|
|
2765
|
-
else if (typeof resultSelector === 'number') {
|
|
2766
|
-
concurrent = resultSelector;
|
|
2767
|
-
}
|
|
2768
|
-
return operate(function (source, subscriber) { return mergeInternals(source, subscriber, project, concurrent); });
|
|
2769
|
-
}
|
|
2770
|
-
|
|
2771
|
-
function mergeAll(concurrent) {
|
|
2772
|
-
if (concurrent === void 0) { concurrent = Infinity; }
|
|
2773
|
-
return mergeMap(identity, concurrent);
|
|
2774
|
-
}
|
|
2775
|
-
|
|
2776
|
-
function concatAll() {
|
|
2777
|
-
return mergeAll(1);
|
|
2778
|
-
}
|
|
2779
|
-
|
|
2780
|
-
function debounceTime(dueTime, scheduler) {
|
|
2781
|
-
if (scheduler === void 0) { scheduler = asyncScheduler; }
|
|
2782
|
-
return operate(function (source, subscriber) {
|
|
2783
|
-
var activeTask = null;
|
|
2784
|
-
var lastValue = null;
|
|
2785
|
-
var lastTime = null;
|
|
2786
|
-
var emit = function () {
|
|
2787
|
-
if (activeTask) {
|
|
2788
|
-
activeTask.unsubscribe();
|
|
2789
|
-
activeTask = null;
|
|
2790
|
-
var value = lastValue;
|
|
2791
|
-
lastValue = null;
|
|
2792
|
-
subscriber.next(value);
|
|
2793
|
-
}
|
|
2794
|
-
};
|
|
2795
|
-
function emitWhenIdle() {
|
|
2796
|
-
var targetTime = lastTime + dueTime;
|
|
2797
|
-
var now = scheduler.now();
|
|
2798
|
-
if (now < targetTime) {
|
|
2799
|
-
activeTask = this.schedule(undefined, targetTime - now);
|
|
2800
|
-
subscriber.add(activeTask);
|
|
2801
|
-
return;
|
|
636
|
+
}
|
|
637
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
638
|
+
finally {
|
|
639
|
+
try {
|
|
640
|
+
if (!_d && !_a && (_b = source_1.return)) yield __await(_b.call(source_1));
|
|
2802
641
|
}
|
|
2803
|
-
|
|
642
|
+
finally { if (e_1) throw e_1.error; }
|
|
2804
643
|
}
|
|
2805
|
-
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
2806
|
-
lastValue = value;
|
|
2807
|
-
lastTime = scheduler.now();
|
|
2808
|
-
if (!activeTask) {
|
|
2809
|
-
activeTask = scheduler.schedule(emitWhenIdle, dueTime);
|
|
2810
|
-
subscriber.add(activeTask);
|
|
2811
|
-
}
|
|
2812
|
-
}, function () {
|
|
2813
|
-
emit();
|
|
2814
|
-
subscriber.complete();
|
|
2815
|
-
}, undefined, function () {
|
|
2816
|
-
lastValue = activeTask = null;
|
|
2817
|
-
}));
|
|
2818
644
|
});
|
|
2819
645
|
}
|
|
2820
646
|
|
|
2821
|
-
function
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
?
|
|
2834
|
-
function () { return EMPTY; }
|
|
2835
|
-
: operate(function (source, subscriber) {
|
|
2836
|
-
var seen = 0;
|
|
2837
|
-
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
2838
|
-
if (++seen <= count) {
|
|
2839
|
-
subscriber.next(value);
|
|
2840
|
-
if (count <= seen) {
|
|
2841
|
-
subscriber.complete();
|
|
2842
|
-
}
|
|
647
|
+
function getFetchResponseBodyGenerator(res) {
|
|
648
|
+
return function () {
|
|
649
|
+
return __asyncGenerator(this, arguments, function* () {
|
|
650
|
+
if (!res.body)
|
|
651
|
+
throw new Error("Response body is not readable");
|
|
652
|
+
const reader = res.body.getReader();
|
|
653
|
+
try {
|
|
654
|
+
while (true) {
|
|
655
|
+
const { done, value } = yield __await(reader.read());
|
|
656
|
+
if (done)
|
|
657
|
+
return yield __await(void 0);
|
|
658
|
+
yield yield __await(value);
|
|
2843
659
|
}
|
|
2844
|
-
}));
|
|
2845
|
-
});
|
|
2846
|
-
}
|
|
2847
|
-
|
|
2848
|
-
function ignoreElements() {
|
|
2849
|
-
return operate(function (source, subscriber) {
|
|
2850
|
-
source.subscribe(createOperatorSubscriber(subscriber, noop));
|
|
2851
|
-
});
|
|
2852
|
-
}
|
|
2853
|
-
|
|
2854
|
-
function mapTo(value) {
|
|
2855
|
-
return map(function () { return value; });
|
|
2856
|
-
}
|
|
2857
|
-
|
|
2858
|
-
function delayWhen(delayDurationSelector, subscriptionDelay) {
|
|
2859
|
-
if (subscriptionDelay) {
|
|
2860
|
-
return function (source) {
|
|
2861
|
-
return concat$1(subscriptionDelay.pipe(take(1), ignoreElements()), source.pipe(delayWhen(delayDurationSelector)));
|
|
2862
|
-
};
|
|
2863
|
-
}
|
|
2864
|
-
return mergeMap(function (value, index) { return delayDurationSelector(value, index).pipe(take(1), mapTo(value)); });
|
|
2865
|
-
}
|
|
2866
|
-
|
|
2867
|
-
function delay(due, scheduler) {
|
|
2868
|
-
if (scheduler === void 0) { scheduler = asyncScheduler; }
|
|
2869
|
-
var duration = timer(due, scheduler);
|
|
2870
|
-
return delayWhen(function () { return duration; });
|
|
2871
|
-
}
|
|
2872
|
-
|
|
2873
|
-
function distinctUntilChanged(comparator, keySelector) {
|
|
2874
|
-
if (keySelector === void 0) { keySelector = identity; }
|
|
2875
|
-
comparator = comparator !== null && comparator !== void 0 ? comparator : defaultCompare;
|
|
2876
|
-
return operate(function (source, subscriber) {
|
|
2877
|
-
var previousKey;
|
|
2878
|
-
var first = true;
|
|
2879
|
-
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
2880
|
-
var currentKey = keySelector(value);
|
|
2881
|
-
if (first || !comparator(previousKey, currentKey)) {
|
|
2882
|
-
first = false;
|
|
2883
|
-
previousKey = currentKey;
|
|
2884
|
-
subscriber.next(value);
|
|
2885
660
|
}
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
}
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
}
|
|
2892
|
-
|
|
2893
|
-
function filter(predicate, thisArg) {
|
|
2894
|
-
return operate(function (source, subscriber) {
|
|
2895
|
-
var index = 0;
|
|
2896
|
-
source.subscribe(createOperatorSubscriber(subscriber, function (value) { return predicate.call(thisArg, value, index++) && subscriber.next(value); }));
|
|
2897
|
-
});
|
|
2898
|
-
}
|
|
2899
|
-
|
|
2900
|
-
function skip(count) {
|
|
2901
|
-
return filter(function (_, index) { return count <= index; });
|
|
2902
|
-
}
|
|
2903
|
-
|
|
2904
|
-
function startWith() {
|
|
2905
|
-
var values = [];
|
|
2906
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2907
|
-
values[_i] = arguments[_i];
|
|
2908
|
-
}
|
|
2909
|
-
var scheduler = popScheduler(values);
|
|
2910
|
-
return operate(function (source, subscriber) {
|
|
2911
|
-
(scheduler ? concat$1(values, source, scheduler) : concat$1(values, source)).subscribe(subscriber);
|
|
2912
|
-
});
|
|
2913
|
-
}
|
|
2914
|
-
|
|
2915
|
-
function switchMap(project, resultSelector) {
|
|
2916
|
-
return operate(function (source, subscriber) {
|
|
2917
|
-
var innerSubscriber = null;
|
|
2918
|
-
var index = 0;
|
|
2919
|
-
var isComplete = false;
|
|
2920
|
-
var checkComplete = function () { return isComplete && !innerSubscriber && subscriber.complete(); };
|
|
2921
|
-
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
2922
|
-
innerSubscriber === null || innerSubscriber === void 0 ? void 0 : innerSubscriber.unsubscribe();
|
|
2923
|
-
var innerIndex = 0;
|
|
2924
|
-
var outerIndex = index++;
|
|
2925
|
-
innerFrom(project(value, outerIndex)).subscribe((innerSubscriber = createOperatorSubscriber(subscriber, function (innerValue) { return subscriber.next(resultSelector ? resultSelector(value, innerValue, outerIndex, innerIndex++) : innerValue); }, function () {
|
|
2926
|
-
innerSubscriber = null;
|
|
2927
|
-
checkComplete();
|
|
2928
|
-
})));
|
|
2929
|
-
}, function () {
|
|
2930
|
-
isComplete = true;
|
|
2931
|
-
checkComplete();
|
|
2932
|
-
}));
|
|
2933
|
-
});
|
|
2934
|
-
}
|
|
2935
|
-
|
|
2936
|
-
function tap(observerOrNext, error, complete) {
|
|
2937
|
-
var tapObserver = isFunction(observerOrNext) || error || complete
|
|
2938
|
-
?
|
|
2939
|
-
{ next: observerOrNext, error: error, complete: complete }
|
|
2940
|
-
: observerOrNext;
|
|
2941
|
-
return tapObserver
|
|
2942
|
-
? operate(function (source, subscriber) {
|
|
2943
|
-
var _a;
|
|
2944
|
-
(_a = tapObserver.subscribe) === null || _a === void 0 ? void 0 : _a.call(tapObserver);
|
|
2945
|
-
var isUnsub = true;
|
|
2946
|
-
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
2947
|
-
var _a;
|
|
2948
|
-
(_a = tapObserver.next) === null || _a === void 0 ? void 0 : _a.call(tapObserver, value);
|
|
2949
|
-
subscriber.next(value);
|
|
2950
|
-
}, function () {
|
|
2951
|
-
var _a;
|
|
2952
|
-
isUnsub = false;
|
|
2953
|
-
(_a = tapObserver.complete) === null || _a === void 0 ? void 0 : _a.call(tapObserver);
|
|
2954
|
-
subscriber.complete();
|
|
2955
|
-
}, function (err) {
|
|
2956
|
-
var _a;
|
|
2957
|
-
isUnsub = false;
|
|
2958
|
-
(_a = tapObserver.error) === null || _a === void 0 ? void 0 : _a.call(tapObserver, err);
|
|
2959
|
-
subscriber.error(err);
|
|
2960
|
-
}, function () {
|
|
2961
|
-
var _a, _b;
|
|
2962
|
-
if (isUnsub) {
|
|
2963
|
-
(_a = tapObserver.unsubscribe) === null || _a === void 0 ? void 0 : _a.call(tapObserver);
|
|
2964
|
-
}
|
|
2965
|
-
(_b = tapObserver.finalize) === null || _b === void 0 ? void 0 : _b.call(tapObserver);
|
|
2966
|
-
}));
|
|
2967
|
-
})
|
|
2968
|
-
:
|
|
2969
|
-
identity;
|
|
661
|
+
finally {
|
|
662
|
+
reader.releaseLock();
|
|
663
|
+
}
|
|
664
|
+
});
|
|
665
|
+
};
|
|
2970
666
|
}
|
|
2971
667
|
|
|
2972
668
|
//const hasSW = 'serviceWorker' in navigator;
|
|
@@ -3487,7 +1183,7 @@ catch (_a) { }
|
|
|
3487
1183
|
|
|
3488
1184
|
function waitUntil(o, // Works with Dexie's liveQuery observables if we'd need that
|
|
3489
1185
|
predicate) {
|
|
3490
|
-
return firstValueFrom(from
|
|
1186
|
+
return firstValueFrom(from(o).pipe(filter(predicate)));
|
|
3491
1187
|
}
|
|
3492
1188
|
|
|
3493
1189
|
function logout(db) {
|
|
@@ -3858,7 +1554,7 @@ function dispatch(ev) {
|
|
|
3858
1554
|
});
|
|
3859
1555
|
}
|
|
3860
1556
|
}
|
|
3861
|
-
class BroadcastedAndLocalEvent extends Observable
|
|
1557
|
+
class BroadcastedAndLocalEvent extends Observable {
|
|
3862
1558
|
constructor(name) {
|
|
3863
1559
|
const bc = typeof BroadcastChannel === "undefined"
|
|
3864
1560
|
? new SWBroadcastChannel(name) : new BroadcastChannel(name);
|
|
@@ -5003,13 +2699,6 @@ function listUpdatesSince(yTable, sinceIncluding) {
|
|
|
5003
2699
|
.toArray();
|
|
5004
2700
|
}
|
|
5005
2701
|
|
|
5006
|
-
function $Y(db) {
|
|
5007
|
-
const $Y = db.dx._options.Y;
|
|
5008
|
-
if (!$Y)
|
|
5009
|
-
throw new Error('Y library not supplied to Dexie constructor');
|
|
5010
|
-
return $Y;
|
|
5011
|
-
}
|
|
5012
|
-
|
|
5013
2702
|
/** Queries the local database for YMessages to send to server.
|
|
5014
2703
|
*
|
|
5015
2704
|
* There are 2 messages that this function can provide:
|
|
@@ -5033,7 +2722,6 @@ function listYClientMessagesAndStateVector(db, tablesToSync) {
|
|
|
5033
2722
|
for (const table of tablesToSync) {
|
|
5034
2723
|
if (table.schema.yProps) {
|
|
5035
2724
|
for (const yProp of table.schema.yProps) {
|
|
5036
|
-
const Y = $Y(db); // This is how we retrieve the user-provided Y library
|
|
5037
2725
|
const yTable = db.table(yProp.updatesTable); // the updates-table for this combo of table+propName
|
|
5038
2726
|
const syncState = (yield yTable.get(DEXIE_CLOUD_SYNCER_ID));
|
|
5039
2727
|
// unsentFrom = the `i` value of updates that aren't yet sent to server (or at least not acked by the server yet)
|
|
@@ -5193,7 +2881,7 @@ function applyYServerMessages(yMessages, db) {
|
|
|
5193
2881
|
case 'in-sync': {
|
|
5194
2882
|
const doc = DexieYProvider.getDocCache(db.dx).find(m.table, m.k, m.prop);
|
|
5195
2883
|
if (doc && !doc.isSynced) {
|
|
5196
|
-
doc.emit('sync', [true]);
|
|
2884
|
+
doc.emit('sync', [true, doc]);
|
|
5197
2885
|
}
|
|
5198
2886
|
break;
|
|
5199
2887
|
}
|
|
@@ -5773,7 +3461,7 @@ function MessagesFromServerConsumer(db) {
|
|
|
5773
3461
|
// If the sync worker or service worker is syncing, wait 'til thei're done.
|
|
5774
3462
|
// It's no need to have two channels at the same time - even though it wouldnt
|
|
5775
3463
|
// be a problem - this is an optimization.
|
|
5776
|
-
yield firstValueFrom(db.cloud.syncState.pipe(filter(({ phase }) => phase === 'in-sync' || phase === 'error')));
|
|
3464
|
+
yield firstValueFrom(db.cloud.syncState.pipe(filter$1(({ phase }) => phase === 'in-sync' || phase === 'error')));
|
|
5777
3465
|
console.debug('processing msg', msg);
|
|
5778
3466
|
const persistedSyncState = db.cloud.persistedSyncState.value;
|
|
5779
3467
|
//syncState.
|
|
@@ -6812,9 +4500,9 @@ const visibilityStateIsChanged = typeof document !== 'undefined'
|
|
|
6812
4500
|
? fromEvent(document, 'visibilitychange')
|
|
6813
4501
|
: of({});
|
|
6814
4502
|
// document.onvisibilitychange makes document hidden:
|
|
6815
|
-
const documentBecomesHidden = visibilityStateIsChanged.pipe(filter(() => document.visibilityState === 'hidden'));
|
|
4503
|
+
const documentBecomesHidden = visibilityStateIsChanged.pipe(filter$1(() => document.visibilityState === 'hidden'));
|
|
6816
4504
|
// document.onvisibilitychange makes document visible
|
|
6817
|
-
const documentBecomesVisible = visibilityStateIsChanged.pipe(filter(() => document.visibilityState === 'visible'));
|
|
4505
|
+
const documentBecomesVisible = visibilityStateIsChanged.pipe(filter$1(() => document.visibilityState === 'visible'));
|
|
6818
4506
|
// Any of various user-activity-related events happen:
|
|
6819
4507
|
const userDoesSomething = typeof window !== 'undefined'
|
|
6820
4508
|
? merge(documentBecomesVisible, fromEvent(window, 'mousedown'), fromEvent(window, 'mousemove'), fromEvent(window, 'keydown'), fromEvent(window, 'wheel'), fromEvent(window, 'touchmove'))
|
|
@@ -6867,9 +4555,9 @@ function createYClientUpdateObservable(db) {
|
|
|
6867
4555
|
// Per updates table (table+prop combo), we first read syncer.unsentFrom,
|
|
6868
4556
|
// and then start listening for updates since that number.
|
|
6869
4557
|
const yTbl = db.table(updatesTable);
|
|
6870
|
-
return from
|
|
4558
|
+
return from(yTbl.get(DEXIE_CLOUD_SYNCER_ID)).pipe(switchMap$1((syncer) => {
|
|
6871
4559
|
let currentUnsentFrom = (syncer === null || syncer === void 0 ? void 0 : syncer.unsentFrom) || 1;
|
|
6872
|
-
return from
|
|
4560
|
+
return from(liveQuery(() => __awaiter(this, void 0, void 0, function* () {
|
|
6873
4561
|
const addedUpdates = yield listUpdatesSince(yTbl, currentUnsentFrom);
|
|
6874
4562
|
return addedUpdates
|
|
6875
4563
|
.filter((update) => update.f && update.f & 1) // Only include local updates
|
|
@@ -6899,7 +4587,7 @@ function createYClientUpdateObservable(db) {
|
|
|
6899
4587
|
// If messageProducer emits empty array, nothing is emitted
|
|
6900
4588
|
// but if messageProducer emits array of messages, they are
|
|
6901
4589
|
// emitted one by one.
|
|
6902
|
-
mergeMap
|
|
4590
|
+
mergeMap((messages) => messages));
|
|
6903
4591
|
}
|
|
6904
4592
|
|
|
6905
4593
|
function getAwarenessLibrary(db) {
|
|
@@ -6932,13 +4620,13 @@ function getOpenDocSignal(doc) {
|
|
|
6932
4620
|
const SERVER_PING_TIMEOUT = 20000;
|
|
6933
4621
|
const CLIENT_PING_INTERVAL = 30000;
|
|
6934
4622
|
const FAIL_RETRY_WAIT_TIME = 60000;
|
|
6935
|
-
class WSObservable extends Observable
|
|
4623
|
+
class WSObservable extends Observable {
|
|
6936
4624
|
constructor(db, rev, yrev, realmSetHash, clientIdentity, messageProducer, webSocketStatus, user) {
|
|
6937
4625
|
super((subscriber) => new WSConnection(db, rev, yrev, realmSetHash, clientIdentity, user, subscriber, messageProducer, webSocketStatus));
|
|
6938
4626
|
}
|
|
6939
4627
|
}
|
|
6940
4628
|
let counter = 0;
|
|
6941
|
-
class WSConnection extends Subscription
|
|
4629
|
+
class WSConnection extends Subscription {
|
|
6942
4630
|
constructor(db, rev, yrev, realmSetHash, clientIdentity, user, subscriber, messageProducer, webSocketStatus) {
|
|
6943
4631
|
super(() => this.teardown());
|
|
6944
4632
|
this.id = ++counter;
|
|
@@ -7236,9 +4924,9 @@ function connectWebSocket(db) {
|
|
|
7236
4924
|
if (!((_a = db.cloud.options) === null || _a === void 0 ? void 0 : _a.databaseUrl)) {
|
|
7237
4925
|
throw new Error(`No database URL to connect WebSocket to`);
|
|
7238
4926
|
}
|
|
7239
|
-
const readyForChangesMessage = db.messageConsumer.readyToServe.pipe(filter((isReady) => isReady), // When consumer is ready for new messages, produce such a message to inform server about it
|
|
4927
|
+
const readyForChangesMessage = db.messageConsumer.readyToServe.pipe(filter$1((isReady) => isReady), // When consumer is ready for new messages, produce such a message to inform server about it
|
|
7240
4928
|
switchMap(() => db.getPersistedSyncState()), // We need the info on which server revision we are at:
|
|
7241
|
-
filter((syncState) => syncState && syncState.serverRevision), // We wont send anything to server before inital sync has taken place
|
|
4929
|
+
filter$1((syncState) => syncState && syncState.serverRevision), // We wont send anything to server before inital sync has taken place
|
|
7242
4930
|
switchMap((syncState) => __awaiter(this, void 0, void 0, function* () {
|
|
7243
4931
|
return ({
|
|
7244
4932
|
// Produce the message to trigger server to send us new messages to consume:
|
|
@@ -7249,7 +4937,7 @@ function connectWebSocket(db) {
|
|
|
7249
4937
|
})));
|
|
7250
4938
|
const messageProducer = merge(readyForChangesMessage, db.messageProducer);
|
|
7251
4939
|
function createObservable() {
|
|
7252
|
-
return db.cloud.persistedSyncState.pipe(filter((syncState) => syncState === null || syncState === void 0 ? void 0 : syncState.serverRevision), // Don't connect before there's no initial sync performed.
|
|
4940
|
+
return db.cloud.persistedSyncState.pipe(filter$1((syncState) => syncState === null || syncState === void 0 ? void 0 : syncState.serverRevision), // Don't connect before there's no initial sync performed.
|
|
7253
4941
|
take(1), // Don't continue waking up whenever syncState change
|
|
7254
4942
|
switchMap((syncState) => db.cloud.currentUser.pipe(map((userLogin) => [userLogin, syncState]))), switchMap(([userLogin, syncState]) => {
|
|
7255
4943
|
/*if (userLogin.license?.status && userLogin.license.status !== 'ok') {
|
|
@@ -7261,7 +4949,7 @@ function connectWebSocket(db) {
|
|
|
7261
4949
|
// We're in an in-between state when user is logged in but the user's realms are not yet synced.
|
|
7262
4950
|
// Don't make this change reconnect the websocket just yet. Wait till syncState is updated
|
|
7263
4951
|
// to iclude the user's realm.
|
|
7264
|
-
return db.cloud.persistedSyncState.pipe(filter((syncState) => (syncState === null || syncState === void 0 ? void 0 : syncState.realms.includes(userLogin.userId)) || false), take(1), map((syncState) => [userLogin, syncState]));
|
|
4952
|
+
return db.cloud.persistedSyncState.pipe(filter$1((syncState) => (syncState === null || syncState === void 0 ? void 0 : syncState.realms.includes(userLogin.userId)) || false), take(1), map((syncState) => [userLogin, syncState]));
|
|
7265
4953
|
}
|
|
7266
4954
|
return new BehaviorSubject([userLogin, syncState]);
|
|
7267
4955
|
}), switchMap((_a) => __awaiter(this, [_a], void 0, function* ([userLogin, syncState]) { return [userLogin, yield computeRealmSetHash(syncState)]; })), distinctUntilChanged(([prevUser, prevHash], [currUser, currHash]) => prevUser === currUser && prevHash === currHash), switchMap(([userLogin, realmSetHash]) => {
|
|
@@ -7277,7 +4965,7 @@ function connectWebSocket(db) {
|
|
|
7277
4965
|
return new WSObservable(db, db.cloud.persistedSyncState.value.serverRevision, db.cloud.persistedSyncState.value.yServerRevision, realmSetHash, db.cloud.persistedSyncState.value.clientIdentity, messageProducer, db.cloud.webSocketStatus, userLogin);
|
|
7278
4966
|
}
|
|
7279
4967
|
else {
|
|
7280
|
-
return from
|
|
4968
|
+
return from([]);
|
|
7281
4969
|
}
|
|
7282
4970
|
}), catchError((error) => {
|
|
7283
4971
|
if ((error === null || error === void 0 ? void 0 : error.name) === 'TokenExpiredError') {
|
|
@@ -7305,7 +4993,7 @@ function connectWebSocket(db) {
|
|
|
7305
4993
|
// Don't retry. Just throw and don't try connect again.
|
|
7306
4994
|
return throwError(() => error);
|
|
7307
4995
|
}
|
|
7308
|
-
return from
|
|
4996
|
+
return from(waitAndReconnectWhenUserDoesSomething(error)).pipe(switchMap(() => createObservable()));
|
|
7309
4997
|
}));
|
|
7310
4998
|
}
|
|
7311
4999
|
return createObservable().subscribe({
|
|
@@ -7675,7 +5363,7 @@ class LoginGui extends d$1 {
|
|
|
7675
5363
|
this.state = { userInteraction: undefined };
|
|
7676
5364
|
}
|
|
7677
5365
|
componentDidMount() {
|
|
7678
|
-
this.subscription = from
|
|
5366
|
+
this.subscription = from(this.props.db.cloud.userInteraction).subscribe(this.observer);
|
|
7679
5367
|
}
|
|
7680
5368
|
componentWillUnmount() {
|
|
7681
5369
|
if (this.subscription) {
|
|
@@ -7810,8 +5498,8 @@ function computeSyncState(db) {
|
|
|
7810
5498
|
|
|
7811
5499
|
function createSharedValueObservable(o, defaultValue) {
|
|
7812
5500
|
let currentValue = defaultValue;
|
|
7813
|
-
let shared = from
|
|
7814
|
-
const rv = new Observable
|
|
5501
|
+
let shared = from(o).pipe(map$1((x) => (currentValue = x)), share({ resetOnRefCountZero: () => timer(1000) }));
|
|
5502
|
+
const rv = new Observable((observer) => {
|
|
7815
5503
|
let didEmit = false;
|
|
7816
5504
|
const subscription = shared.subscribe({
|
|
7817
5505
|
next(value) {
|
|
@@ -8098,6 +5786,9 @@ function createYHandler(db) {
|
|
|
8098
5786
|
return (provider) => {
|
|
8099
5787
|
var _a;
|
|
8100
5788
|
const doc = provider.doc;
|
|
5789
|
+
if (!doc) {
|
|
5790
|
+
throw new Error('Internal error: DexieYProvider.createYHandler called without a doc. This is unexpected.');
|
|
5791
|
+
}
|
|
8101
5792
|
const { parentTable } = doc.meta || {};
|
|
8102
5793
|
if (!((_a = db.cloud.schema) === null || _a === void 0 ? void 0 : _a[parentTable].markedForSync)) {
|
|
8103
5794
|
return; // The table that holds the doc is not marked for sync - leave it to dexie. No syncing, no awareness.
|
|
@@ -8232,7 +5923,6 @@ function createAwareness(db, doc, provider) {
|
|
|
8232
5923
|
if (provider.destroyed || currentFlowId !== myFlow || !connected)
|
|
8233
5924
|
return;
|
|
8234
5925
|
if (serverUpdatesSinceLastSync.length > 0) {
|
|
8235
|
-
const Y = $Y(db); // Get the Yjs library from Dexie constructor options
|
|
8236
5926
|
const mergedUpdate = Y.mergeUpdatesV2(serverUpdatesSinceLastSync.map((update) => update.u));
|
|
8237
5927
|
const stateVector = Y.encodeStateVectorFromUpdateV2(mergedUpdate);
|
|
8238
5928
|
docOpenMsg.sv = stateVector;
|
|
@@ -8455,7 +6145,7 @@ function dexieCloud(dexie) {
|
|
|
8455
6145
|
const syncComplete = new Subject();
|
|
8456
6146
|
dexie.cloud = {
|
|
8457
6147
|
// @ts-ignore
|
|
8458
|
-
version: "4.
|
|
6148
|
+
version: "4.2.0-alpha.3",
|
|
8459
6149
|
options: Object.assign({}, DEFAULT_OPTIONS),
|
|
8460
6150
|
schema: null,
|
|
8461
6151
|
get currentUserId() {
|
|
@@ -8513,7 +6203,7 @@ function dexieCloud(dexie) {
|
|
|
8513
6203
|
const syncState = db.cloud.persistedSyncState.value;
|
|
8514
6204
|
triggerSync(db, purpose);
|
|
8515
6205
|
if (wait) {
|
|
8516
|
-
const newSyncState = yield firstValueFrom(db.cloud.persistedSyncState.pipe(filter((newSyncState) => (newSyncState === null || newSyncState === void 0 ? void 0 : newSyncState.timestamp) != null &&
|
|
6206
|
+
const newSyncState = yield firstValueFrom(db.cloud.persistedSyncState.pipe(filter$1((newSyncState) => (newSyncState === null || newSyncState === void 0 ? void 0 : newSyncState.timestamp) != null &&
|
|
8517
6207
|
(!syncState || newSyncState.timestamp > syncState.timestamp))));
|
|
8518
6208
|
if (newSyncState === null || newSyncState === void 0 ? void 0 : newSyncState.error) {
|
|
8519
6209
|
throw new Error(`Sync error: ` + newSyncState.error);
|
|
@@ -8525,14 +6215,14 @@ function dexieCloud(dexie) {
|
|
|
8525
6215
|
triggerSync(db, purpose);
|
|
8526
6216
|
if (wait) {
|
|
8527
6217
|
console.debug('db.cloud.login() is waiting for sync completion...');
|
|
8528
|
-
yield firstValueFrom(from
|
|
6218
|
+
yield firstValueFrom(from(liveQuery(() => __awaiter(this, void 0, void 0, function* () {
|
|
8529
6219
|
const syncNeeded = yield isSyncNeeded(db);
|
|
8530
6220
|
const newSyncState = yield db.getPersistedSyncState();
|
|
8531
6221
|
if ((newSyncState === null || newSyncState === void 0 ? void 0 : newSyncState.timestamp) !== (syncState === null || syncState === void 0 ? void 0 : syncState.timestamp) &&
|
|
8532
6222
|
(newSyncState === null || newSyncState === void 0 ? void 0 : newSyncState.error))
|
|
8533
6223
|
throw new Error(`Sync error: ` + newSyncState.error);
|
|
8534
6224
|
return syncNeeded;
|
|
8535
|
-
}))).pipe(filter((isNeeded) => !isNeeded)));
|
|
6225
|
+
}))).pipe(filter$1((isNeeded) => !isNeeded)));
|
|
8536
6226
|
console.debug('Done waiting for sync completion because we have nothing to push anymore');
|
|
8537
6227
|
}
|
|
8538
6228
|
}
|
|
@@ -8676,10 +6366,9 @@ function dexieCloud(dexie) {
|
|
|
8676
6366
|
db.cloud.persistedSyncState.pipe(skip(1), take(1)),
|
|
8677
6367
|
]));
|
|
8678
6368
|
const yHandler = createYHandler(db);
|
|
8679
|
-
|
|
6369
|
+
DexieYProvider.on.new.subscribe(yHandler);
|
|
8680
6370
|
db.dx.once('close', () => {
|
|
8681
|
-
|
|
8682
|
-
(_a = db.dx.on.y) === null || _a === void 0 ? void 0 : _a.unsubscribe(yHandler);
|
|
6371
|
+
DexieYProvider.on.new.unsubscribe(yHandler);
|
|
8683
6372
|
});
|
|
8684
6373
|
}
|
|
8685
6374
|
// HERE: If requireAuth, do athentication now.
|
|
@@ -8691,7 +6380,7 @@ function dexieCloud(dexie) {
|
|
|
8691
6380
|
// If this is a service worker DB, we can't do authentication here,
|
|
8692
6381
|
// we just wait until the application has done it.
|
|
8693
6382
|
console.debug('Dexie Cloud Service worker. Waiting for application to authenticate.');
|
|
8694
|
-
yield firstValueFrom(currentUserEmitter.pipe(filter((user) => !!user.isLoggedIn), take(1)));
|
|
6383
|
+
yield firstValueFrom(currentUserEmitter.pipe(filter$1((user) => !!user.isLoggedIn), take(1)));
|
|
8695
6384
|
console.debug('Dexie Cloud Service worker. Application has authenticated.');
|
|
8696
6385
|
}
|
|
8697
6386
|
else {
|
|
@@ -8773,7 +6462,7 @@ function dexieCloud(dexie) {
|
|
|
8773
6462
|
}
|
|
8774
6463
|
}
|
|
8775
6464
|
// @ts-ignore
|
|
8776
|
-
dexieCloud.version = "4.
|
|
6465
|
+
dexieCloud.version = "4.2.0-alpha.3";
|
|
8777
6466
|
Dexie.Cloud = dexieCloud;
|
|
8778
6467
|
|
|
8779
6468
|
export { dexieCloud as default, defineYDocTrigger, dexieCloud, getTiedObjectId, getTiedRealmId, resolveText };
|