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 { Observable
|
|
19
|
+
import Dexie, { PropModification, cmp, RangeSet, liveQuery } from 'dexie';
|
|
20
|
+
import { Observable, BehaviorSubject, firstValueFrom, Subject, from, filter as filter$1, 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';
|
|
21
|
+
import { filter, switchMap, delay, distinctUntilChanged, map, tap, take, catchError, debounceTime, startWith, skip } from 'rxjs/operators';
|
|
22
|
+
import { Encoder, writeVarString, writeAny, writeVarUint8Array, writeBigUint64, toUint8Array } from 'lib0/encoding';
|
|
23
|
+
import { Decoder, readVarString, readAny, readVarUint8Array, readBigUint64, hasContent, readUint8 } from 'lib0/decoding';
|
|
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
|
}
|
|
@@ -263,7 +199,7 @@ function dispatch(ev) {
|
|
|
263
199
|
});
|
|
264
200
|
}
|
|
265
201
|
}
|
|
266
|
-
class BroadcastedAndLocalEvent extends Observable
|
|
202
|
+
class BroadcastedAndLocalEvent extends Observable {
|
|
267
203
|
constructor(name) {
|
|
268
204
|
const bc = typeof BroadcastChannel === "undefined"
|
|
269
205
|
? new SWBroadcastChannel(name) : new BroadcastChannel(name);
|
|
@@ -305,1431 +241,13 @@ class BroadcastedAndLocalEvent extends Observable$1 {
|
|
|
305
241
|
this.name = name;
|
|
306
242
|
this.bc = bc;
|
|
307
243
|
}
|
|
308
|
-
next(message) {
|
|
309
|
-
console.debug("BroadcastedAndLocalEvent: bc.postMessage()", Object.assign({}, message), "bc is a", this.bc);
|
|
310
|
-
this.bc.postMessage(message);
|
|
311
|
-
const ev = new CustomEvent(`lbc-${this.name}`, { detail: message });
|
|
312
|
-
//self.dispatchEvent(ev);
|
|
313
|
-
dispatch(ev);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
function isFunction(value) {
|
|
318
|
-
return typeof value === 'function';
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
function hasLift(source) {
|
|
322
|
-
return isFunction(source === null || source === void 0 ? void 0 : source.lift);
|
|
323
|
-
}
|
|
324
|
-
function operate(init) {
|
|
325
|
-
return function (source) {
|
|
326
|
-
if (hasLift(source)) {
|
|
327
|
-
return source.lift(function (liftedSource) {
|
|
328
|
-
try {
|
|
329
|
-
return init(liftedSource, this);
|
|
330
|
-
}
|
|
331
|
-
catch (err) {
|
|
332
|
-
this.error(err);
|
|
333
|
-
}
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
throw new TypeError('Unable to lift unknown Observable type');
|
|
337
|
-
};
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
var isArrayLike = (function (x) { return x && typeof x.length === 'number' && typeof x !== 'function'; });
|
|
341
|
-
|
|
342
|
-
function isPromise(value) {
|
|
343
|
-
return isFunction(value === null || value === void 0 ? void 0 : value.then);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
function createErrorClass(createImpl) {
|
|
347
|
-
var _super = function (instance) {
|
|
348
|
-
Error.call(instance);
|
|
349
|
-
instance.stack = new Error().stack;
|
|
350
|
-
};
|
|
351
|
-
var ctorFunc = createImpl(_super);
|
|
352
|
-
ctorFunc.prototype = Object.create(Error.prototype);
|
|
353
|
-
ctorFunc.prototype.constructor = ctorFunc;
|
|
354
|
-
return ctorFunc;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
var UnsubscriptionError = createErrorClass(function (_super) {
|
|
358
|
-
return function UnsubscriptionErrorImpl(errors) {
|
|
359
|
-
_super(this);
|
|
360
|
-
this.message = errors
|
|
361
|
-
? errors.length + " errors occurred during unsubscription:\n" + errors.map(function (err, i) { return i + 1 + ") " + err.toString(); }).join('\n ')
|
|
362
|
-
: '';
|
|
363
|
-
this.name = 'UnsubscriptionError';
|
|
364
|
-
this.errors = errors;
|
|
365
|
-
};
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
function arrRemove(arr, item) {
|
|
369
|
-
if (arr) {
|
|
370
|
-
var index = arr.indexOf(item);
|
|
371
|
-
0 <= index && arr.splice(index, 1);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
var Subscription = (function () {
|
|
376
|
-
function Subscription(initialTeardown) {
|
|
377
|
-
this.initialTeardown = initialTeardown;
|
|
378
|
-
this.closed = false;
|
|
379
|
-
this._parentage = null;
|
|
380
|
-
this._finalizers = null;
|
|
381
|
-
}
|
|
382
|
-
Subscription.prototype.unsubscribe = function () {
|
|
383
|
-
var e_1, _a, e_2, _b;
|
|
384
|
-
var errors;
|
|
385
|
-
if (!this.closed) {
|
|
386
|
-
this.closed = true;
|
|
387
|
-
var _parentage = this._parentage;
|
|
388
|
-
if (_parentage) {
|
|
389
|
-
this._parentage = null;
|
|
390
|
-
if (Array.isArray(_parentage)) {
|
|
391
|
-
try {
|
|
392
|
-
for (var _parentage_1 = __values(_parentage), _parentage_1_1 = _parentage_1.next(); !_parentage_1_1.done; _parentage_1_1 = _parentage_1.next()) {
|
|
393
|
-
var parent_1 = _parentage_1_1.value;
|
|
394
|
-
parent_1.remove(this);
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
398
|
-
finally {
|
|
399
|
-
try {
|
|
400
|
-
if (_parentage_1_1 && !_parentage_1_1.done && (_a = _parentage_1.return)) _a.call(_parentage_1);
|
|
401
|
-
}
|
|
402
|
-
finally { if (e_1) throw e_1.error; }
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
else {
|
|
406
|
-
_parentage.remove(this);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
var initialFinalizer = this.initialTeardown;
|
|
410
|
-
if (isFunction(initialFinalizer)) {
|
|
411
|
-
try {
|
|
412
|
-
initialFinalizer();
|
|
413
|
-
}
|
|
414
|
-
catch (e) {
|
|
415
|
-
errors = e instanceof UnsubscriptionError ? e.errors : [e];
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
var _finalizers = this._finalizers;
|
|
419
|
-
if (_finalizers) {
|
|
420
|
-
this._finalizers = null;
|
|
421
|
-
try {
|
|
422
|
-
for (var _finalizers_1 = __values(_finalizers), _finalizers_1_1 = _finalizers_1.next(); !_finalizers_1_1.done; _finalizers_1_1 = _finalizers_1.next()) {
|
|
423
|
-
var finalizer = _finalizers_1_1.value;
|
|
424
|
-
try {
|
|
425
|
-
execFinalizer(finalizer);
|
|
426
|
-
}
|
|
427
|
-
catch (err) {
|
|
428
|
-
errors = errors !== null && errors !== void 0 ? errors : [];
|
|
429
|
-
if (err instanceof UnsubscriptionError) {
|
|
430
|
-
errors = __spreadArray(__spreadArray([], __read(errors)), __read(err.errors));
|
|
431
|
-
}
|
|
432
|
-
else {
|
|
433
|
-
errors.push(err);
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
439
|
-
finally {
|
|
440
|
-
try {
|
|
441
|
-
if (_finalizers_1_1 && !_finalizers_1_1.done && (_b = _finalizers_1.return)) _b.call(_finalizers_1);
|
|
442
|
-
}
|
|
443
|
-
finally { if (e_2) throw e_2.error; }
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
if (errors) {
|
|
447
|
-
throw new UnsubscriptionError(errors);
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
};
|
|
451
|
-
Subscription.prototype.add = function (teardown) {
|
|
452
|
-
var _a;
|
|
453
|
-
if (teardown && teardown !== this) {
|
|
454
|
-
if (this.closed) {
|
|
455
|
-
execFinalizer(teardown);
|
|
456
|
-
}
|
|
457
|
-
else {
|
|
458
|
-
if (teardown instanceof Subscription) {
|
|
459
|
-
if (teardown.closed || teardown._hasParent(this)) {
|
|
460
|
-
return;
|
|
461
|
-
}
|
|
462
|
-
teardown._addParent(this);
|
|
463
|
-
}
|
|
464
|
-
(this._finalizers = (_a = this._finalizers) !== null && _a !== void 0 ? _a : []).push(teardown);
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
};
|
|
468
|
-
Subscription.prototype._hasParent = function (parent) {
|
|
469
|
-
var _parentage = this._parentage;
|
|
470
|
-
return _parentage === parent || (Array.isArray(_parentage) && _parentage.includes(parent));
|
|
471
|
-
};
|
|
472
|
-
Subscription.prototype._addParent = function (parent) {
|
|
473
|
-
var _parentage = this._parentage;
|
|
474
|
-
this._parentage = Array.isArray(_parentage) ? (_parentage.push(parent), _parentage) : _parentage ? [_parentage, parent] : parent;
|
|
475
|
-
};
|
|
476
|
-
Subscription.prototype._removeParent = function (parent) {
|
|
477
|
-
var _parentage = this._parentage;
|
|
478
|
-
if (_parentage === parent) {
|
|
479
|
-
this._parentage = null;
|
|
480
|
-
}
|
|
481
|
-
else if (Array.isArray(_parentage)) {
|
|
482
|
-
arrRemove(_parentage, parent);
|
|
483
|
-
}
|
|
484
|
-
};
|
|
485
|
-
Subscription.prototype.remove = function (teardown) {
|
|
486
|
-
var _finalizers = this._finalizers;
|
|
487
|
-
_finalizers && arrRemove(_finalizers, teardown);
|
|
488
|
-
if (teardown instanceof Subscription) {
|
|
489
|
-
teardown._removeParent(this);
|
|
490
|
-
}
|
|
491
|
-
};
|
|
492
|
-
Subscription.EMPTY = (function () {
|
|
493
|
-
var empty = new Subscription();
|
|
494
|
-
empty.closed = true;
|
|
495
|
-
return empty;
|
|
496
|
-
})();
|
|
497
|
-
return Subscription;
|
|
498
|
-
}());
|
|
499
|
-
Subscription.EMPTY;
|
|
500
|
-
function isSubscription(value) {
|
|
501
|
-
return (value instanceof Subscription ||
|
|
502
|
-
(value && 'closed' in value && isFunction(value.remove) && isFunction(value.add) && isFunction(value.unsubscribe)));
|
|
503
|
-
}
|
|
504
|
-
function execFinalizer(finalizer) {
|
|
505
|
-
if (isFunction(finalizer)) {
|
|
506
|
-
finalizer();
|
|
507
|
-
}
|
|
508
|
-
else {
|
|
509
|
-
finalizer.unsubscribe();
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
var config = {
|
|
514
|
-
onUnhandledError: null,
|
|
515
|
-
onStoppedNotification: null,
|
|
516
|
-
Promise: undefined,
|
|
517
|
-
useDeprecatedSynchronousErrorHandling: false,
|
|
518
|
-
useDeprecatedNextContext: false,
|
|
519
|
-
};
|
|
520
|
-
|
|
521
|
-
var timeoutProvider = {
|
|
522
|
-
setTimeout: function (handler, timeout) {
|
|
523
|
-
var args = [];
|
|
524
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
525
|
-
args[_i - 2] = arguments[_i];
|
|
526
|
-
}
|
|
527
|
-
var delegate = timeoutProvider.delegate;
|
|
528
|
-
if (delegate === null || delegate === void 0 ? void 0 : delegate.setTimeout) {
|
|
529
|
-
return delegate.setTimeout.apply(delegate, __spreadArray([handler, timeout], __read(args)));
|
|
530
|
-
}
|
|
531
|
-
return setTimeout.apply(void 0, __spreadArray([handler, timeout], __read(args)));
|
|
532
|
-
},
|
|
533
|
-
clearTimeout: function (handle) {
|
|
534
|
-
var delegate = timeoutProvider.delegate;
|
|
535
|
-
return ((delegate === null || delegate === void 0 ? void 0 : delegate.clearTimeout) || clearTimeout)(handle);
|
|
536
|
-
},
|
|
537
|
-
delegate: undefined,
|
|
538
|
-
};
|
|
539
|
-
|
|
540
|
-
function reportUnhandledError(err) {
|
|
541
|
-
timeoutProvider.setTimeout(function () {
|
|
542
|
-
{
|
|
543
|
-
throw err;
|
|
544
|
-
}
|
|
545
|
-
});
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
function noop() { }
|
|
549
|
-
|
|
550
|
-
function errorContext(cb) {
|
|
551
|
-
{
|
|
552
|
-
cb();
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
var Subscriber = (function (_super) {
|
|
557
|
-
__extends(Subscriber, _super);
|
|
558
|
-
function Subscriber(destination) {
|
|
559
|
-
var _this = _super.call(this) || this;
|
|
560
|
-
_this.isStopped = false;
|
|
561
|
-
if (destination) {
|
|
562
|
-
_this.destination = destination;
|
|
563
|
-
if (isSubscription(destination)) {
|
|
564
|
-
destination.add(_this);
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
else {
|
|
568
|
-
_this.destination = EMPTY_OBSERVER;
|
|
569
|
-
}
|
|
570
|
-
return _this;
|
|
571
|
-
}
|
|
572
|
-
Subscriber.create = function (next, error, complete) {
|
|
573
|
-
return new SafeSubscriber(next, error, complete);
|
|
574
|
-
};
|
|
575
|
-
Subscriber.prototype.next = function (value) {
|
|
576
|
-
if (this.isStopped) ;
|
|
577
|
-
else {
|
|
578
|
-
this._next(value);
|
|
579
|
-
}
|
|
580
|
-
};
|
|
581
|
-
Subscriber.prototype.error = function (err) {
|
|
582
|
-
if (this.isStopped) ;
|
|
583
|
-
else {
|
|
584
|
-
this.isStopped = true;
|
|
585
|
-
this._error(err);
|
|
586
|
-
}
|
|
587
|
-
};
|
|
588
|
-
Subscriber.prototype.complete = function () {
|
|
589
|
-
if (this.isStopped) ;
|
|
590
|
-
else {
|
|
591
|
-
this.isStopped = true;
|
|
592
|
-
this._complete();
|
|
593
|
-
}
|
|
594
|
-
};
|
|
595
|
-
Subscriber.prototype.unsubscribe = function () {
|
|
596
|
-
if (!this.closed) {
|
|
597
|
-
this.isStopped = true;
|
|
598
|
-
_super.prototype.unsubscribe.call(this);
|
|
599
|
-
this.destination = null;
|
|
600
|
-
}
|
|
601
|
-
};
|
|
602
|
-
Subscriber.prototype._next = function (value) {
|
|
603
|
-
this.destination.next(value);
|
|
604
|
-
};
|
|
605
|
-
Subscriber.prototype._error = function (err) {
|
|
606
|
-
try {
|
|
607
|
-
this.destination.error(err);
|
|
608
|
-
}
|
|
609
|
-
finally {
|
|
610
|
-
this.unsubscribe();
|
|
611
|
-
}
|
|
612
|
-
};
|
|
613
|
-
Subscriber.prototype._complete = function () {
|
|
614
|
-
try {
|
|
615
|
-
this.destination.complete();
|
|
616
|
-
}
|
|
617
|
-
finally {
|
|
618
|
-
this.unsubscribe();
|
|
619
|
-
}
|
|
620
|
-
};
|
|
621
|
-
return Subscriber;
|
|
622
|
-
}(Subscription));
|
|
623
|
-
var _bind = Function.prototype.bind;
|
|
624
|
-
function bind(fn, thisArg) {
|
|
625
|
-
return _bind.call(fn, thisArg);
|
|
626
|
-
}
|
|
627
|
-
var ConsumerObserver = (function () {
|
|
628
|
-
function ConsumerObserver(partialObserver) {
|
|
629
|
-
this.partialObserver = partialObserver;
|
|
630
|
-
}
|
|
631
|
-
ConsumerObserver.prototype.next = function (value) {
|
|
632
|
-
var partialObserver = this.partialObserver;
|
|
633
|
-
if (partialObserver.next) {
|
|
634
|
-
try {
|
|
635
|
-
partialObserver.next(value);
|
|
636
|
-
}
|
|
637
|
-
catch (error) {
|
|
638
|
-
handleUnhandledError(error);
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
};
|
|
642
|
-
ConsumerObserver.prototype.error = function (err) {
|
|
643
|
-
var partialObserver = this.partialObserver;
|
|
644
|
-
if (partialObserver.error) {
|
|
645
|
-
try {
|
|
646
|
-
partialObserver.error(err);
|
|
647
|
-
}
|
|
648
|
-
catch (error) {
|
|
649
|
-
handleUnhandledError(error);
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
else {
|
|
653
|
-
handleUnhandledError(err);
|
|
654
|
-
}
|
|
655
|
-
};
|
|
656
|
-
ConsumerObserver.prototype.complete = function () {
|
|
657
|
-
var partialObserver = this.partialObserver;
|
|
658
|
-
if (partialObserver.complete) {
|
|
659
|
-
try {
|
|
660
|
-
partialObserver.complete();
|
|
661
|
-
}
|
|
662
|
-
catch (error) {
|
|
663
|
-
handleUnhandledError(error);
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
};
|
|
667
|
-
return ConsumerObserver;
|
|
668
|
-
}());
|
|
669
|
-
var SafeSubscriber = (function (_super) {
|
|
670
|
-
__extends(SafeSubscriber, _super);
|
|
671
|
-
function SafeSubscriber(observerOrNext, error, complete) {
|
|
672
|
-
var _this = _super.call(this) || this;
|
|
673
|
-
var partialObserver;
|
|
674
|
-
if (isFunction(observerOrNext) || !observerOrNext) {
|
|
675
|
-
partialObserver = {
|
|
676
|
-
next: (observerOrNext !== null && observerOrNext !== void 0 ? observerOrNext : undefined),
|
|
677
|
-
error: error !== null && error !== void 0 ? error : undefined,
|
|
678
|
-
complete: complete !== null && complete !== void 0 ? complete : undefined,
|
|
679
|
-
};
|
|
680
|
-
}
|
|
681
|
-
else {
|
|
682
|
-
var context_1;
|
|
683
|
-
if (_this && config.useDeprecatedNextContext) {
|
|
684
|
-
context_1 = Object.create(observerOrNext);
|
|
685
|
-
context_1.unsubscribe = function () { return _this.unsubscribe(); };
|
|
686
|
-
partialObserver = {
|
|
687
|
-
next: observerOrNext.next && bind(observerOrNext.next, context_1),
|
|
688
|
-
error: observerOrNext.error && bind(observerOrNext.error, context_1),
|
|
689
|
-
complete: observerOrNext.complete && bind(observerOrNext.complete, context_1),
|
|
690
|
-
};
|
|
691
|
-
}
|
|
692
|
-
else {
|
|
693
|
-
partialObserver = observerOrNext;
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
_this.destination = new ConsumerObserver(partialObserver);
|
|
697
|
-
return _this;
|
|
698
|
-
}
|
|
699
|
-
return SafeSubscriber;
|
|
700
|
-
}(Subscriber));
|
|
701
|
-
function handleUnhandledError(error) {
|
|
702
|
-
{
|
|
703
|
-
reportUnhandledError(error);
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
function defaultErrorHandler(err) {
|
|
707
|
-
throw err;
|
|
708
|
-
}
|
|
709
|
-
var EMPTY_OBSERVER = {
|
|
710
|
-
closed: true,
|
|
711
|
-
next: noop,
|
|
712
|
-
error: defaultErrorHandler,
|
|
713
|
-
complete: noop,
|
|
714
|
-
};
|
|
715
|
-
|
|
716
|
-
var observable = (function () { return (typeof Symbol === 'function' && Symbol.observable) || '@@observable'; })();
|
|
717
|
-
|
|
718
|
-
function identity(x) {
|
|
719
|
-
return x;
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
function pipeFromArray(fns) {
|
|
723
|
-
if (fns.length === 0) {
|
|
724
|
-
return identity;
|
|
725
|
-
}
|
|
726
|
-
if (fns.length === 1) {
|
|
727
|
-
return fns[0];
|
|
728
|
-
}
|
|
729
|
-
return function piped(input) {
|
|
730
|
-
return fns.reduce(function (prev, fn) { return fn(prev); }, input);
|
|
731
|
-
};
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
var Observable = (function () {
|
|
735
|
-
function Observable(subscribe) {
|
|
736
|
-
if (subscribe) {
|
|
737
|
-
this._subscribe = subscribe;
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
Observable.prototype.lift = function (operator) {
|
|
741
|
-
var observable = new Observable();
|
|
742
|
-
observable.source = this;
|
|
743
|
-
observable.operator = operator;
|
|
744
|
-
return observable;
|
|
745
|
-
};
|
|
746
|
-
Observable.prototype.subscribe = function (observerOrNext, error, complete) {
|
|
747
|
-
var _this = this;
|
|
748
|
-
var subscriber = isSubscriber(observerOrNext) ? observerOrNext : new SafeSubscriber(observerOrNext, error, complete);
|
|
749
|
-
errorContext(function () {
|
|
750
|
-
var _a = _this, operator = _a.operator, source = _a.source;
|
|
751
|
-
subscriber.add(operator
|
|
752
|
-
?
|
|
753
|
-
operator.call(subscriber, source)
|
|
754
|
-
: source
|
|
755
|
-
?
|
|
756
|
-
_this._subscribe(subscriber)
|
|
757
|
-
:
|
|
758
|
-
_this._trySubscribe(subscriber));
|
|
759
|
-
});
|
|
760
|
-
return subscriber;
|
|
761
|
-
};
|
|
762
|
-
Observable.prototype._trySubscribe = function (sink) {
|
|
763
|
-
try {
|
|
764
|
-
return this._subscribe(sink);
|
|
765
|
-
}
|
|
766
|
-
catch (err) {
|
|
767
|
-
sink.error(err);
|
|
768
|
-
}
|
|
769
|
-
};
|
|
770
|
-
Observable.prototype.forEach = function (next, promiseCtor) {
|
|
771
|
-
var _this = this;
|
|
772
|
-
promiseCtor = getPromiseCtor(promiseCtor);
|
|
773
|
-
return new promiseCtor(function (resolve, reject) {
|
|
774
|
-
var subscriber = new SafeSubscriber({
|
|
775
|
-
next: function (value) {
|
|
776
|
-
try {
|
|
777
|
-
next(value);
|
|
778
|
-
}
|
|
779
|
-
catch (err) {
|
|
780
|
-
reject(err);
|
|
781
|
-
subscriber.unsubscribe();
|
|
782
|
-
}
|
|
783
|
-
},
|
|
784
|
-
error: reject,
|
|
785
|
-
complete: resolve,
|
|
786
|
-
});
|
|
787
|
-
_this.subscribe(subscriber);
|
|
788
|
-
});
|
|
789
|
-
};
|
|
790
|
-
Observable.prototype._subscribe = function (subscriber) {
|
|
791
|
-
var _a;
|
|
792
|
-
return (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber);
|
|
793
|
-
};
|
|
794
|
-
Observable.prototype[observable] = function () {
|
|
795
|
-
return this;
|
|
796
|
-
};
|
|
797
|
-
Observable.prototype.pipe = function () {
|
|
798
|
-
var operations = [];
|
|
799
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
800
|
-
operations[_i] = arguments[_i];
|
|
801
|
-
}
|
|
802
|
-
return pipeFromArray(operations)(this);
|
|
803
|
-
};
|
|
804
|
-
Observable.prototype.toPromise = function (promiseCtor) {
|
|
805
|
-
var _this = this;
|
|
806
|
-
promiseCtor = getPromiseCtor(promiseCtor);
|
|
807
|
-
return new promiseCtor(function (resolve, reject) {
|
|
808
|
-
var value;
|
|
809
|
-
_this.subscribe(function (x) { return (value = x); }, function (err) { return reject(err); }, function () { return resolve(value); });
|
|
810
|
-
});
|
|
811
|
-
};
|
|
812
|
-
Observable.create = function (subscribe) {
|
|
813
|
-
return new Observable(subscribe);
|
|
814
|
-
};
|
|
815
|
-
return Observable;
|
|
816
|
-
}());
|
|
817
|
-
function getPromiseCtor(promiseCtor) {
|
|
818
|
-
var _a;
|
|
819
|
-
return (_a = promiseCtor !== null && promiseCtor !== void 0 ? promiseCtor : config.Promise) !== null && _a !== void 0 ? _a : Promise;
|
|
820
|
-
}
|
|
821
|
-
function isObserver(value) {
|
|
822
|
-
return value && isFunction(value.next) && isFunction(value.error) && isFunction(value.complete);
|
|
823
|
-
}
|
|
824
|
-
function isSubscriber(value) {
|
|
825
|
-
return (value && value instanceof Subscriber) || (isObserver(value) && isSubscription(value));
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
function isInteropObservable(input) {
|
|
829
|
-
return isFunction(input[observable]);
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
function isAsyncIterable(obj) {
|
|
833
|
-
return Symbol.asyncIterator && isFunction(obj === null || obj === void 0 ? void 0 : obj[Symbol.asyncIterator]);
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
function createInvalidObservableTypeError(input) {
|
|
837
|
-
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.");
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
function getSymbolIterator() {
|
|
841
|
-
if (typeof Symbol !== 'function' || !Symbol.iterator) {
|
|
842
|
-
return '@@iterator';
|
|
843
|
-
}
|
|
844
|
-
return Symbol.iterator;
|
|
845
|
-
}
|
|
846
|
-
var iterator = getSymbolIterator();
|
|
847
|
-
|
|
848
|
-
function isIterable(input) {
|
|
849
|
-
return isFunction(input === null || input === void 0 ? void 0 : input[iterator]);
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
function readableStreamLikeToAsyncGenerator(readableStream) {
|
|
853
|
-
return __asyncGenerator(this, arguments, function readableStreamLikeToAsyncGenerator_1() {
|
|
854
|
-
var reader, _a, value, done;
|
|
855
|
-
return __generator(this, function (_b) {
|
|
856
|
-
switch (_b.label) {
|
|
857
|
-
case 0:
|
|
858
|
-
reader = readableStream.getReader();
|
|
859
|
-
_b.label = 1;
|
|
860
|
-
case 1:
|
|
861
|
-
_b.trys.push([1, , 9, 10]);
|
|
862
|
-
_b.label = 2;
|
|
863
|
-
case 2:
|
|
864
|
-
return [4, __await(reader.read())];
|
|
865
|
-
case 3:
|
|
866
|
-
_a = _b.sent(), value = _a.value, done = _a.done;
|
|
867
|
-
if (!done) return [3, 5];
|
|
868
|
-
return [4, __await(void 0)];
|
|
869
|
-
case 4: return [2, _b.sent()];
|
|
870
|
-
case 5: return [4, __await(value)];
|
|
871
|
-
case 6: return [4, _b.sent()];
|
|
872
|
-
case 7:
|
|
873
|
-
_b.sent();
|
|
874
|
-
return [3, 2];
|
|
875
|
-
case 8: return [3, 10];
|
|
876
|
-
case 9:
|
|
877
|
-
reader.releaseLock();
|
|
878
|
-
return [7];
|
|
879
|
-
case 10: return [2];
|
|
880
|
-
}
|
|
881
|
-
});
|
|
882
|
-
});
|
|
883
|
-
}
|
|
884
|
-
function isReadableStreamLike(obj) {
|
|
885
|
-
return isFunction(obj === null || obj === void 0 ? void 0 : obj.getReader);
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
function innerFrom(input) {
|
|
889
|
-
if (input instanceof Observable) {
|
|
890
|
-
return input;
|
|
891
|
-
}
|
|
892
|
-
if (input != null) {
|
|
893
|
-
if (isInteropObservable(input)) {
|
|
894
|
-
return fromInteropObservable(input);
|
|
895
|
-
}
|
|
896
|
-
if (isArrayLike(input)) {
|
|
897
|
-
return fromArrayLike(input);
|
|
898
|
-
}
|
|
899
|
-
if (isPromise(input)) {
|
|
900
|
-
return fromPromise(input);
|
|
901
|
-
}
|
|
902
|
-
if (isAsyncIterable(input)) {
|
|
903
|
-
return fromAsyncIterable(input);
|
|
904
|
-
}
|
|
905
|
-
if (isIterable(input)) {
|
|
906
|
-
return fromIterable(input);
|
|
907
|
-
}
|
|
908
|
-
if (isReadableStreamLike(input)) {
|
|
909
|
-
return fromReadableStreamLike(input);
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
|
-
throw createInvalidObservableTypeError(input);
|
|
913
|
-
}
|
|
914
|
-
function fromInteropObservable(obj) {
|
|
915
|
-
return new Observable(function (subscriber) {
|
|
916
|
-
var obs = obj[observable]();
|
|
917
|
-
if (isFunction(obs.subscribe)) {
|
|
918
|
-
return obs.subscribe(subscriber);
|
|
919
|
-
}
|
|
920
|
-
throw new TypeError('Provided object does not correctly implement Symbol.observable');
|
|
921
|
-
});
|
|
922
|
-
}
|
|
923
|
-
function fromArrayLike(array) {
|
|
924
|
-
return new Observable(function (subscriber) {
|
|
925
|
-
for (var i = 0; i < array.length && !subscriber.closed; i++) {
|
|
926
|
-
subscriber.next(array[i]);
|
|
927
|
-
}
|
|
928
|
-
subscriber.complete();
|
|
929
|
-
});
|
|
930
|
-
}
|
|
931
|
-
function fromPromise(promise) {
|
|
932
|
-
return new Observable(function (subscriber) {
|
|
933
|
-
promise
|
|
934
|
-
.then(function (value) {
|
|
935
|
-
if (!subscriber.closed) {
|
|
936
|
-
subscriber.next(value);
|
|
937
|
-
subscriber.complete();
|
|
938
|
-
}
|
|
939
|
-
}, function (err) { return subscriber.error(err); })
|
|
940
|
-
.then(null, reportUnhandledError);
|
|
941
|
-
});
|
|
942
|
-
}
|
|
943
|
-
function fromIterable(iterable) {
|
|
944
|
-
return new Observable(function (subscriber) {
|
|
945
|
-
var e_1, _a;
|
|
946
|
-
try {
|
|
947
|
-
for (var iterable_1 = __values(iterable), iterable_1_1 = iterable_1.next(); !iterable_1_1.done; iterable_1_1 = iterable_1.next()) {
|
|
948
|
-
var value = iterable_1_1.value;
|
|
949
|
-
subscriber.next(value);
|
|
950
|
-
if (subscriber.closed) {
|
|
951
|
-
return;
|
|
952
|
-
}
|
|
953
|
-
}
|
|
954
|
-
}
|
|
955
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
956
|
-
finally {
|
|
957
|
-
try {
|
|
958
|
-
if (iterable_1_1 && !iterable_1_1.done && (_a = iterable_1.return)) _a.call(iterable_1);
|
|
959
|
-
}
|
|
960
|
-
finally { if (e_1) throw e_1.error; }
|
|
961
|
-
}
|
|
962
|
-
subscriber.complete();
|
|
963
|
-
});
|
|
964
|
-
}
|
|
965
|
-
function fromAsyncIterable(asyncIterable) {
|
|
966
|
-
return new Observable(function (subscriber) {
|
|
967
|
-
process(asyncIterable, subscriber).catch(function (err) { return subscriber.error(err); });
|
|
968
|
-
});
|
|
969
|
-
}
|
|
970
|
-
function fromReadableStreamLike(readableStream) {
|
|
971
|
-
return fromAsyncIterable(readableStreamLikeToAsyncGenerator(readableStream));
|
|
972
|
-
}
|
|
973
|
-
function process(asyncIterable, subscriber) {
|
|
974
|
-
var asyncIterable_1, asyncIterable_1_1;
|
|
975
|
-
var e_2, _a;
|
|
976
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
977
|
-
var value, e_2_1;
|
|
978
|
-
return __generator(this, function (_b) {
|
|
979
|
-
switch (_b.label) {
|
|
980
|
-
case 0:
|
|
981
|
-
_b.trys.push([0, 5, 6, 11]);
|
|
982
|
-
asyncIterable_1 = __asyncValues(asyncIterable);
|
|
983
|
-
_b.label = 1;
|
|
984
|
-
case 1: return [4, asyncIterable_1.next()];
|
|
985
|
-
case 2:
|
|
986
|
-
if (!(asyncIterable_1_1 = _b.sent(), !asyncIterable_1_1.done)) return [3, 4];
|
|
987
|
-
value = asyncIterable_1_1.value;
|
|
988
|
-
subscriber.next(value);
|
|
989
|
-
if (subscriber.closed) {
|
|
990
|
-
return [2];
|
|
991
|
-
}
|
|
992
|
-
_b.label = 3;
|
|
993
|
-
case 3: return [3, 1];
|
|
994
|
-
case 4: return [3, 11];
|
|
995
|
-
case 5:
|
|
996
|
-
e_2_1 = _b.sent();
|
|
997
|
-
e_2 = { error: e_2_1 };
|
|
998
|
-
return [3, 11];
|
|
999
|
-
case 6:
|
|
1000
|
-
_b.trys.push([6, , 9, 10]);
|
|
1001
|
-
if (!(asyncIterable_1_1 && !asyncIterable_1_1.done && (_a = asyncIterable_1.return))) return [3, 8];
|
|
1002
|
-
return [4, _a.call(asyncIterable_1)];
|
|
1003
|
-
case 7:
|
|
1004
|
-
_b.sent();
|
|
1005
|
-
_b.label = 8;
|
|
1006
|
-
case 8: return [3, 10];
|
|
1007
|
-
case 9:
|
|
1008
|
-
if (e_2) throw e_2.error;
|
|
1009
|
-
return [7];
|
|
1010
|
-
case 10: return [7];
|
|
1011
|
-
case 11:
|
|
1012
|
-
subscriber.complete();
|
|
1013
|
-
return [2];
|
|
1014
|
-
}
|
|
1015
|
-
});
|
|
1016
|
-
});
|
|
1017
|
-
}
|
|
1018
|
-
|
|
1019
|
-
function createOperatorSubscriber(destination, onNext, onComplete, onError, onFinalize) {
|
|
1020
|
-
return new OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize);
|
|
1021
|
-
}
|
|
1022
|
-
var OperatorSubscriber = (function (_super) {
|
|
1023
|
-
__extends(OperatorSubscriber, _super);
|
|
1024
|
-
function OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize, shouldUnsubscribe) {
|
|
1025
|
-
var _this = _super.call(this, destination) || this;
|
|
1026
|
-
_this.onFinalize = onFinalize;
|
|
1027
|
-
_this.shouldUnsubscribe = shouldUnsubscribe;
|
|
1028
|
-
_this._next = onNext
|
|
1029
|
-
? function (value) {
|
|
1030
|
-
try {
|
|
1031
|
-
onNext(value);
|
|
1032
|
-
}
|
|
1033
|
-
catch (err) {
|
|
1034
|
-
destination.error(err);
|
|
1035
|
-
}
|
|
1036
|
-
}
|
|
1037
|
-
: _super.prototype._next;
|
|
1038
|
-
_this._error = onError
|
|
1039
|
-
? function (err) {
|
|
1040
|
-
try {
|
|
1041
|
-
onError(err);
|
|
1042
|
-
}
|
|
1043
|
-
catch (err) {
|
|
1044
|
-
destination.error(err);
|
|
1045
|
-
}
|
|
1046
|
-
finally {
|
|
1047
|
-
this.unsubscribe();
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
: _super.prototype._error;
|
|
1051
|
-
_this._complete = onComplete
|
|
1052
|
-
? function () {
|
|
1053
|
-
try {
|
|
1054
|
-
onComplete();
|
|
1055
|
-
}
|
|
1056
|
-
catch (err) {
|
|
1057
|
-
destination.error(err);
|
|
1058
|
-
}
|
|
1059
|
-
finally {
|
|
1060
|
-
this.unsubscribe();
|
|
1061
|
-
}
|
|
1062
|
-
}
|
|
1063
|
-
: _super.prototype._complete;
|
|
1064
|
-
return _this;
|
|
1065
|
-
}
|
|
1066
|
-
OperatorSubscriber.prototype.unsubscribe = function () {
|
|
1067
|
-
var _a;
|
|
1068
|
-
if (!this.shouldUnsubscribe || this.shouldUnsubscribe()) {
|
|
1069
|
-
var closed_1 = this.closed;
|
|
1070
|
-
_super.prototype.unsubscribe.call(this);
|
|
1071
|
-
!closed_1 && ((_a = this.onFinalize) === null || _a === void 0 ? void 0 : _a.call(this));
|
|
1072
|
-
}
|
|
1073
|
-
};
|
|
1074
|
-
return OperatorSubscriber;
|
|
1075
|
-
}(Subscriber));
|
|
1076
|
-
|
|
1077
|
-
var Action = (function (_super) {
|
|
1078
|
-
__extends(Action, _super);
|
|
1079
|
-
function Action(scheduler, work) {
|
|
1080
|
-
return _super.call(this) || this;
|
|
1081
|
-
}
|
|
1082
|
-
Action.prototype.schedule = function (state, delay) {
|
|
1083
|
-
return this;
|
|
1084
|
-
};
|
|
1085
|
-
return Action;
|
|
1086
|
-
}(Subscription));
|
|
1087
|
-
|
|
1088
|
-
var intervalProvider = {
|
|
1089
|
-
setInterval: function (handler, timeout) {
|
|
1090
|
-
var args = [];
|
|
1091
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
1092
|
-
args[_i - 2] = arguments[_i];
|
|
1093
|
-
}
|
|
1094
|
-
var delegate = intervalProvider.delegate;
|
|
1095
|
-
if (delegate === null || delegate === void 0 ? void 0 : delegate.setInterval) {
|
|
1096
|
-
return delegate.setInterval.apply(delegate, __spreadArray([handler, timeout], __read(args)));
|
|
1097
|
-
}
|
|
1098
|
-
return setInterval.apply(void 0, __spreadArray([handler, timeout], __read(args)));
|
|
1099
|
-
},
|
|
1100
|
-
clearInterval: function (handle) {
|
|
1101
|
-
var delegate = intervalProvider.delegate;
|
|
1102
|
-
return ((delegate === null || delegate === void 0 ? void 0 : delegate.clearInterval) || clearInterval)(handle);
|
|
1103
|
-
},
|
|
1104
|
-
delegate: undefined,
|
|
1105
|
-
};
|
|
1106
|
-
|
|
1107
|
-
var AsyncAction = (function (_super) {
|
|
1108
|
-
__extends(AsyncAction, _super);
|
|
1109
|
-
function AsyncAction(scheduler, work) {
|
|
1110
|
-
var _this = _super.call(this, scheduler, work) || this;
|
|
1111
|
-
_this.scheduler = scheduler;
|
|
1112
|
-
_this.work = work;
|
|
1113
|
-
_this.pending = false;
|
|
1114
|
-
return _this;
|
|
1115
|
-
}
|
|
1116
|
-
AsyncAction.prototype.schedule = function (state, delay) {
|
|
1117
|
-
if (delay === void 0) { delay = 0; }
|
|
1118
|
-
if (this.closed) {
|
|
1119
|
-
return this;
|
|
1120
|
-
}
|
|
1121
|
-
this.state = state;
|
|
1122
|
-
var id = this.id;
|
|
1123
|
-
var scheduler = this.scheduler;
|
|
1124
|
-
if (id != null) {
|
|
1125
|
-
this.id = this.recycleAsyncId(scheduler, id, delay);
|
|
1126
|
-
}
|
|
1127
|
-
this.pending = true;
|
|
1128
|
-
this.delay = delay;
|
|
1129
|
-
this.id = this.id || this.requestAsyncId(scheduler, this.id, delay);
|
|
1130
|
-
return this;
|
|
1131
|
-
};
|
|
1132
|
-
AsyncAction.prototype.requestAsyncId = function (scheduler, _id, delay) {
|
|
1133
|
-
if (delay === void 0) { delay = 0; }
|
|
1134
|
-
return intervalProvider.setInterval(scheduler.flush.bind(scheduler, this), delay);
|
|
1135
|
-
};
|
|
1136
|
-
AsyncAction.prototype.recycleAsyncId = function (_scheduler, id, delay) {
|
|
1137
|
-
if (delay === void 0) { delay = 0; }
|
|
1138
|
-
if (delay != null && this.delay === delay && this.pending === false) {
|
|
1139
|
-
return id;
|
|
1140
|
-
}
|
|
1141
|
-
intervalProvider.clearInterval(id);
|
|
1142
|
-
return undefined;
|
|
1143
|
-
};
|
|
1144
|
-
AsyncAction.prototype.execute = function (state, delay) {
|
|
1145
|
-
if (this.closed) {
|
|
1146
|
-
return new Error('executing a cancelled action');
|
|
1147
|
-
}
|
|
1148
|
-
this.pending = false;
|
|
1149
|
-
var error = this._execute(state, delay);
|
|
1150
|
-
if (error) {
|
|
1151
|
-
return error;
|
|
1152
|
-
}
|
|
1153
|
-
else if (this.pending === false && this.id != null) {
|
|
1154
|
-
this.id = this.recycleAsyncId(this.scheduler, this.id, null);
|
|
1155
|
-
}
|
|
1156
|
-
};
|
|
1157
|
-
AsyncAction.prototype._execute = function (state, _delay) {
|
|
1158
|
-
var errored = false;
|
|
1159
|
-
var errorValue;
|
|
1160
|
-
try {
|
|
1161
|
-
this.work(state);
|
|
1162
|
-
}
|
|
1163
|
-
catch (e) {
|
|
1164
|
-
errored = true;
|
|
1165
|
-
errorValue = e ? e : new Error('Scheduled action threw falsy error');
|
|
1166
|
-
}
|
|
1167
|
-
if (errored) {
|
|
1168
|
-
this.unsubscribe();
|
|
1169
|
-
return errorValue;
|
|
1170
|
-
}
|
|
1171
|
-
};
|
|
1172
|
-
AsyncAction.prototype.unsubscribe = function () {
|
|
1173
|
-
if (!this.closed) {
|
|
1174
|
-
var _a = this, id = _a.id, scheduler = _a.scheduler;
|
|
1175
|
-
var actions = scheduler.actions;
|
|
1176
|
-
this.work = this.state = this.scheduler = null;
|
|
1177
|
-
this.pending = false;
|
|
1178
|
-
arrRemove(actions, this);
|
|
1179
|
-
if (id != null) {
|
|
1180
|
-
this.id = this.recycleAsyncId(scheduler, id, null);
|
|
1181
|
-
}
|
|
1182
|
-
this.delay = null;
|
|
1183
|
-
_super.prototype.unsubscribe.call(this);
|
|
1184
|
-
}
|
|
1185
|
-
};
|
|
1186
|
-
return AsyncAction;
|
|
1187
|
-
}(Action));
|
|
1188
|
-
|
|
1189
|
-
var dateTimestampProvider = {
|
|
1190
|
-
now: function () {
|
|
1191
|
-
return (dateTimestampProvider.delegate || Date).now();
|
|
1192
|
-
},
|
|
1193
|
-
delegate: undefined,
|
|
1194
|
-
};
|
|
1195
|
-
|
|
1196
|
-
var Scheduler = (function () {
|
|
1197
|
-
function Scheduler(schedulerActionCtor, now) {
|
|
1198
|
-
if (now === void 0) { now = Scheduler.now; }
|
|
1199
|
-
this.schedulerActionCtor = schedulerActionCtor;
|
|
1200
|
-
this.now = now;
|
|
1201
|
-
}
|
|
1202
|
-
Scheduler.prototype.schedule = function (work, delay, state) {
|
|
1203
|
-
if (delay === void 0) { delay = 0; }
|
|
1204
|
-
return new this.schedulerActionCtor(this, work).schedule(state, delay);
|
|
1205
|
-
};
|
|
1206
|
-
Scheduler.now = dateTimestampProvider.now;
|
|
1207
|
-
return Scheduler;
|
|
1208
|
-
}());
|
|
1209
|
-
|
|
1210
|
-
var AsyncScheduler = (function (_super) {
|
|
1211
|
-
__extends(AsyncScheduler, _super);
|
|
1212
|
-
function AsyncScheduler(SchedulerAction, now) {
|
|
1213
|
-
if (now === void 0) { now = Scheduler.now; }
|
|
1214
|
-
var _this = _super.call(this, SchedulerAction, now) || this;
|
|
1215
|
-
_this.actions = [];
|
|
1216
|
-
_this._active = false;
|
|
1217
|
-
_this._scheduled = undefined;
|
|
1218
|
-
return _this;
|
|
1219
|
-
}
|
|
1220
|
-
AsyncScheduler.prototype.flush = function (action) {
|
|
1221
|
-
var actions = this.actions;
|
|
1222
|
-
if (this._active) {
|
|
1223
|
-
actions.push(action);
|
|
1224
|
-
return;
|
|
1225
|
-
}
|
|
1226
|
-
var error;
|
|
1227
|
-
this._active = true;
|
|
1228
|
-
do {
|
|
1229
|
-
if ((error = action.execute(action.state, action.delay))) {
|
|
1230
|
-
break;
|
|
1231
|
-
}
|
|
1232
|
-
} while ((action = actions.shift()));
|
|
1233
|
-
this._active = false;
|
|
1234
|
-
if (error) {
|
|
1235
|
-
while ((action = actions.shift())) {
|
|
1236
|
-
action.unsubscribe();
|
|
1237
|
-
}
|
|
1238
|
-
throw error;
|
|
1239
|
-
}
|
|
1240
|
-
};
|
|
1241
|
-
return AsyncScheduler;
|
|
1242
|
-
}(Scheduler));
|
|
1243
|
-
|
|
1244
|
-
var asyncScheduler = new AsyncScheduler(AsyncAction);
|
|
1245
|
-
var async = asyncScheduler;
|
|
1246
|
-
|
|
1247
|
-
function isScheduler(value) {
|
|
1248
|
-
return value && isFunction(value.schedule);
|
|
1249
|
-
}
|
|
1250
|
-
|
|
1251
|
-
function isValidDate(value) {
|
|
1252
|
-
return value instanceof Date && !isNaN(value);
|
|
1253
|
-
}
|
|
1254
|
-
|
|
1255
|
-
function timer(dueTime, intervalOrScheduler, scheduler) {
|
|
1256
|
-
if (dueTime === void 0) { dueTime = 0; }
|
|
1257
|
-
if (scheduler === void 0) { scheduler = async; }
|
|
1258
|
-
var intervalDuration = -1;
|
|
1259
|
-
if (intervalOrScheduler != null) {
|
|
1260
|
-
if (isScheduler(intervalOrScheduler)) {
|
|
1261
|
-
scheduler = intervalOrScheduler;
|
|
1262
|
-
}
|
|
1263
|
-
else {
|
|
1264
|
-
intervalDuration = intervalOrScheduler;
|
|
1265
|
-
}
|
|
1266
|
-
}
|
|
1267
|
-
return new Observable(function (subscriber) {
|
|
1268
|
-
var due = isValidDate(dueTime) ? +dueTime - scheduler.now() : dueTime;
|
|
1269
|
-
if (due < 0) {
|
|
1270
|
-
due = 0;
|
|
1271
|
-
}
|
|
1272
|
-
var n = 0;
|
|
1273
|
-
return scheduler.schedule(function () {
|
|
1274
|
-
if (!subscriber.closed) {
|
|
1275
|
-
subscriber.next(n++);
|
|
1276
|
-
if (0 <= intervalDuration) {
|
|
1277
|
-
this.schedule(undefined, intervalDuration);
|
|
1278
|
-
}
|
|
1279
|
-
else {
|
|
1280
|
-
subscriber.complete();
|
|
1281
|
-
}
|
|
1282
|
-
}
|
|
1283
|
-
}, due);
|
|
1284
|
-
});
|
|
1285
|
-
}
|
|
1286
|
-
|
|
1287
|
-
function last(arr) {
|
|
1288
|
-
return arr[arr.length - 1];
|
|
1289
|
-
}
|
|
1290
|
-
function popScheduler(args) {
|
|
1291
|
-
return isScheduler(last(args)) ? args.pop() : undefined;
|
|
1292
|
-
}
|
|
1293
|
-
|
|
1294
|
-
function executeSchedule(parentSubscription, scheduler, work, delay, repeat) {
|
|
1295
|
-
if (delay === void 0) { delay = 0; }
|
|
1296
|
-
if (repeat === void 0) { repeat = false; }
|
|
1297
|
-
var scheduleSubscription = scheduler.schedule(function () {
|
|
1298
|
-
work();
|
|
1299
|
-
if (repeat) {
|
|
1300
|
-
parentSubscription.add(this.schedule(null, delay));
|
|
1301
|
-
}
|
|
1302
|
-
else {
|
|
1303
|
-
this.unsubscribe();
|
|
1304
|
-
}
|
|
1305
|
-
}, delay);
|
|
1306
|
-
parentSubscription.add(scheduleSubscription);
|
|
1307
|
-
if (!repeat) {
|
|
1308
|
-
return scheduleSubscription;
|
|
1309
|
-
}
|
|
1310
|
-
}
|
|
1311
|
-
|
|
1312
|
-
function catchError(selector) {
|
|
1313
|
-
return operate(function (source, subscriber) {
|
|
1314
|
-
var innerSub = null;
|
|
1315
|
-
var syncUnsub = false;
|
|
1316
|
-
var handledResult;
|
|
1317
|
-
innerSub = source.subscribe(createOperatorSubscriber(subscriber, undefined, undefined, function (err) {
|
|
1318
|
-
handledResult = innerFrom(selector(err, catchError(selector)(source)));
|
|
1319
|
-
if (innerSub) {
|
|
1320
|
-
innerSub.unsubscribe();
|
|
1321
|
-
innerSub = null;
|
|
1322
|
-
handledResult.subscribe(subscriber);
|
|
1323
|
-
}
|
|
1324
|
-
else {
|
|
1325
|
-
syncUnsub = true;
|
|
1326
|
-
}
|
|
1327
|
-
}));
|
|
1328
|
-
if (syncUnsub) {
|
|
1329
|
-
innerSub.unsubscribe();
|
|
1330
|
-
innerSub = null;
|
|
1331
|
-
handledResult.subscribe(subscriber);
|
|
1332
|
-
}
|
|
1333
|
-
});
|
|
1334
|
-
}
|
|
1335
|
-
|
|
1336
|
-
function observeOn(scheduler, delay) {
|
|
1337
|
-
if (delay === void 0) { delay = 0; }
|
|
1338
|
-
return operate(function (source, subscriber) {
|
|
1339
|
-
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); }));
|
|
1340
|
-
});
|
|
1341
|
-
}
|
|
1342
|
-
|
|
1343
|
-
function subscribeOn(scheduler, delay) {
|
|
1344
|
-
if (delay === void 0) { delay = 0; }
|
|
1345
|
-
return operate(function (source, subscriber) {
|
|
1346
|
-
subscriber.add(scheduler.schedule(function () { return source.subscribe(subscriber); }, delay));
|
|
1347
|
-
});
|
|
1348
|
-
}
|
|
1349
|
-
|
|
1350
|
-
function scheduleObservable(input, scheduler) {
|
|
1351
|
-
return innerFrom(input).pipe(subscribeOn(scheduler), observeOn(scheduler));
|
|
1352
|
-
}
|
|
1353
|
-
|
|
1354
|
-
function schedulePromise(input, scheduler) {
|
|
1355
|
-
return innerFrom(input).pipe(subscribeOn(scheduler), observeOn(scheduler));
|
|
1356
|
-
}
|
|
1357
|
-
|
|
1358
|
-
function scheduleArray(input, scheduler) {
|
|
1359
|
-
return new Observable(function (subscriber) {
|
|
1360
|
-
var i = 0;
|
|
1361
|
-
return scheduler.schedule(function () {
|
|
1362
|
-
if (i === input.length) {
|
|
1363
|
-
subscriber.complete();
|
|
1364
|
-
}
|
|
1365
|
-
else {
|
|
1366
|
-
subscriber.next(input[i++]);
|
|
1367
|
-
if (!subscriber.closed) {
|
|
1368
|
-
this.schedule();
|
|
1369
|
-
}
|
|
1370
|
-
}
|
|
1371
|
-
});
|
|
1372
|
-
});
|
|
1373
|
-
}
|
|
1374
|
-
|
|
1375
|
-
function scheduleIterable(input, scheduler) {
|
|
1376
|
-
return new Observable(function (subscriber) {
|
|
1377
|
-
var iterator$1;
|
|
1378
|
-
executeSchedule(subscriber, scheduler, function () {
|
|
1379
|
-
iterator$1 = input[iterator]();
|
|
1380
|
-
executeSchedule(subscriber, scheduler, function () {
|
|
1381
|
-
var _a;
|
|
1382
|
-
var value;
|
|
1383
|
-
var done;
|
|
1384
|
-
try {
|
|
1385
|
-
(_a = iterator$1.next(), value = _a.value, done = _a.done);
|
|
1386
|
-
}
|
|
1387
|
-
catch (err) {
|
|
1388
|
-
subscriber.error(err);
|
|
1389
|
-
return;
|
|
1390
|
-
}
|
|
1391
|
-
if (done) {
|
|
1392
|
-
subscriber.complete();
|
|
1393
|
-
}
|
|
1394
|
-
else {
|
|
1395
|
-
subscriber.next(value);
|
|
1396
|
-
}
|
|
1397
|
-
}, 0, true);
|
|
1398
|
-
});
|
|
1399
|
-
return function () { return isFunction(iterator$1 === null || iterator$1 === void 0 ? void 0 : iterator$1.return) && iterator$1.return(); };
|
|
1400
|
-
});
|
|
1401
|
-
}
|
|
1402
|
-
|
|
1403
|
-
function scheduleAsyncIterable(input, scheduler) {
|
|
1404
|
-
if (!input) {
|
|
1405
|
-
throw new Error('Iterable cannot be null');
|
|
1406
|
-
}
|
|
1407
|
-
return new Observable(function (subscriber) {
|
|
1408
|
-
executeSchedule(subscriber, scheduler, function () {
|
|
1409
|
-
var iterator = input[Symbol.asyncIterator]();
|
|
1410
|
-
executeSchedule(subscriber, scheduler, function () {
|
|
1411
|
-
iterator.next().then(function (result) {
|
|
1412
|
-
if (result.done) {
|
|
1413
|
-
subscriber.complete();
|
|
1414
|
-
}
|
|
1415
|
-
else {
|
|
1416
|
-
subscriber.next(result.value);
|
|
1417
|
-
}
|
|
1418
|
-
});
|
|
1419
|
-
}, 0, true);
|
|
1420
|
-
});
|
|
1421
|
-
});
|
|
1422
|
-
}
|
|
1423
|
-
|
|
1424
|
-
function scheduleReadableStreamLike(input, scheduler) {
|
|
1425
|
-
return scheduleAsyncIterable(readableStreamLikeToAsyncGenerator(input), scheduler);
|
|
1426
|
-
}
|
|
1427
|
-
|
|
1428
|
-
function scheduled(input, scheduler) {
|
|
1429
|
-
if (input != null) {
|
|
1430
|
-
if (isInteropObservable(input)) {
|
|
1431
|
-
return scheduleObservable(input, scheduler);
|
|
1432
|
-
}
|
|
1433
|
-
if (isArrayLike(input)) {
|
|
1434
|
-
return scheduleArray(input, scheduler);
|
|
1435
|
-
}
|
|
1436
|
-
if (isPromise(input)) {
|
|
1437
|
-
return schedulePromise(input, scheduler);
|
|
1438
|
-
}
|
|
1439
|
-
if (isAsyncIterable(input)) {
|
|
1440
|
-
return scheduleAsyncIterable(input, scheduler);
|
|
1441
|
-
}
|
|
1442
|
-
if (isIterable(input)) {
|
|
1443
|
-
return scheduleIterable(input, scheduler);
|
|
1444
|
-
}
|
|
1445
|
-
if (isReadableStreamLike(input)) {
|
|
1446
|
-
return scheduleReadableStreamLike(input, scheduler);
|
|
1447
|
-
}
|
|
1448
|
-
}
|
|
1449
|
-
throw createInvalidObservableTypeError(input);
|
|
1450
|
-
}
|
|
1451
|
-
|
|
1452
|
-
function from(input, scheduler) {
|
|
1453
|
-
return scheduler ? scheduled(input, scheduler) : innerFrom(input);
|
|
1454
|
-
}
|
|
1455
|
-
|
|
1456
|
-
function map(project, thisArg) {
|
|
1457
|
-
return operate(function (source, subscriber) {
|
|
1458
|
-
var index = 0;
|
|
1459
|
-
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
1460
|
-
subscriber.next(project.call(thisArg, value, index++));
|
|
1461
|
-
}));
|
|
1462
|
-
});
|
|
1463
|
-
}
|
|
1464
|
-
|
|
1465
|
-
function mergeInternals(source, subscriber, project, concurrent, onBeforeNext, expand, innerSubScheduler, additionalFinalizer) {
|
|
1466
|
-
var buffer = [];
|
|
1467
|
-
var active = 0;
|
|
1468
|
-
var index = 0;
|
|
1469
|
-
var isComplete = false;
|
|
1470
|
-
var checkComplete = function () {
|
|
1471
|
-
if (isComplete && !buffer.length && !active) {
|
|
1472
|
-
subscriber.complete();
|
|
1473
|
-
}
|
|
1474
|
-
};
|
|
1475
|
-
var outerNext = function (value) { return (active < concurrent ? doInnerSub(value) : buffer.push(value)); };
|
|
1476
|
-
var doInnerSub = function (value) {
|
|
1477
|
-
expand && subscriber.next(value);
|
|
1478
|
-
active++;
|
|
1479
|
-
var innerComplete = false;
|
|
1480
|
-
innerFrom(project(value, index++)).subscribe(createOperatorSubscriber(subscriber, function (innerValue) {
|
|
1481
|
-
onBeforeNext === null || onBeforeNext === void 0 ? void 0 : onBeforeNext(innerValue);
|
|
1482
|
-
if (expand) {
|
|
1483
|
-
outerNext(innerValue);
|
|
1484
|
-
}
|
|
1485
|
-
else {
|
|
1486
|
-
subscriber.next(innerValue);
|
|
1487
|
-
}
|
|
1488
|
-
}, function () {
|
|
1489
|
-
innerComplete = true;
|
|
1490
|
-
}, undefined, function () {
|
|
1491
|
-
if (innerComplete) {
|
|
1492
|
-
try {
|
|
1493
|
-
active--;
|
|
1494
|
-
var _loop_1 = function () {
|
|
1495
|
-
var bufferedValue = buffer.shift();
|
|
1496
|
-
if (innerSubScheduler) {
|
|
1497
|
-
executeSchedule(subscriber, innerSubScheduler, function () { return doInnerSub(bufferedValue); });
|
|
1498
|
-
}
|
|
1499
|
-
else {
|
|
1500
|
-
doInnerSub(bufferedValue);
|
|
1501
|
-
}
|
|
1502
|
-
};
|
|
1503
|
-
while (buffer.length && active < concurrent) {
|
|
1504
|
-
_loop_1();
|
|
1505
|
-
}
|
|
1506
|
-
checkComplete();
|
|
1507
|
-
}
|
|
1508
|
-
catch (err) {
|
|
1509
|
-
subscriber.error(err);
|
|
1510
|
-
}
|
|
1511
|
-
}
|
|
1512
|
-
}));
|
|
1513
|
-
};
|
|
1514
|
-
source.subscribe(createOperatorSubscriber(subscriber, outerNext, function () {
|
|
1515
|
-
isComplete = true;
|
|
1516
|
-
checkComplete();
|
|
1517
|
-
}));
|
|
1518
|
-
return function () {
|
|
1519
|
-
additionalFinalizer === null || additionalFinalizer === void 0 ? void 0 : additionalFinalizer();
|
|
1520
|
-
};
|
|
1521
|
-
}
|
|
1522
|
-
|
|
1523
|
-
function mergeMap(project, resultSelector, concurrent) {
|
|
1524
|
-
if (concurrent === void 0) { concurrent = Infinity; }
|
|
1525
|
-
if (isFunction(resultSelector)) {
|
|
1526
|
-
return mergeMap(function (a, i) { return map(function (b, ii) { return resultSelector(a, b, i, ii); })(innerFrom(project(a, i))); }, concurrent);
|
|
1527
|
-
}
|
|
1528
|
-
else if (typeof resultSelector === 'number') {
|
|
1529
|
-
concurrent = resultSelector;
|
|
1530
|
-
}
|
|
1531
|
-
return operate(function (source, subscriber) { return mergeInternals(source, subscriber, project, concurrent); });
|
|
1532
|
-
}
|
|
1533
|
-
|
|
1534
|
-
function mergeAll(concurrent) {
|
|
1535
|
-
if (concurrent === void 0) { concurrent = Infinity; }
|
|
1536
|
-
return mergeMap(identity, concurrent);
|
|
1537
|
-
}
|
|
1538
|
-
|
|
1539
|
-
function concatAll() {
|
|
1540
|
-
return mergeAll(1);
|
|
1541
|
-
}
|
|
1542
|
-
|
|
1543
|
-
function debounceTime(dueTime, scheduler) {
|
|
1544
|
-
if (scheduler === void 0) { scheduler = asyncScheduler; }
|
|
1545
|
-
return operate(function (source, subscriber) {
|
|
1546
|
-
var activeTask = null;
|
|
1547
|
-
var lastValue = null;
|
|
1548
|
-
var lastTime = null;
|
|
1549
|
-
var emit = function () {
|
|
1550
|
-
if (activeTask) {
|
|
1551
|
-
activeTask.unsubscribe();
|
|
1552
|
-
activeTask = null;
|
|
1553
|
-
var value = lastValue;
|
|
1554
|
-
lastValue = null;
|
|
1555
|
-
subscriber.next(value);
|
|
1556
|
-
}
|
|
1557
|
-
};
|
|
1558
|
-
function emitWhenIdle() {
|
|
1559
|
-
var targetTime = lastTime + dueTime;
|
|
1560
|
-
var now = scheduler.now();
|
|
1561
|
-
if (now < targetTime) {
|
|
1562
|
-
activeTask = this.schedule(undefined, targetTime - now);
|
|
1563
|
-
subscriber.add(activeTask);
|
|
1564
|
-
return;
|
|
1565
|
-
}
|
|
1566
|
-
emit();
|
|
1567
|
-
}
|
|
1568
|
-
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
1569
|
-
lastValue = value;
|
|
1570
|
-
lastTime = scheduler.now();
|
|
1571
|
-
if (!activeTask) {
|
|
1572
|
-
activeTask = scheduler.schedule(emitWhenIdle, dueTime);
|
|
1573
|
-
subscriber.add(activeTask);
|
|
1574
|
-
}
|
|
1575
|
-
}, function () {
|
|
1576
|
-
emit();
|
|
1577
|
-
subscriber.complete();
|
|
1578
|
-
}, undefined, function () {
|
|
1579
|
-
lastValue = activeTask = null;
|
|
1580
|
-
}));
|
|
1581
|
-
});
|
|
1582
|
-
}
|
|
1583
|
-
|
|
1584
|
-
function concat$1() {
|
|
1585
|
-
var args = [];
|
|
1586
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1587
|
-
args[_i] = arguments[_i];
|
|
1588
|
-
}
|
|
1589
|
-
return concatAll()(from(args, popScheduler(args)));
|
|
1590
|
-
}
|
|
1591
|
-
|
|
1592
|
-
var EMPTY = new Observable(function (subscriber) { return subscriber.complete(); });
|
|
1593
|
-
|
|
1594
|
-
function take(count) {
|
|
1595
|
-
return count <= 0
|
|
1596
|
-
?
|
|
1597
|
-
function () { return EMPTY; }
|
|
1598
|
-
: operate(function (source, subscriber) {
|
|
1599
|
-
var seen = 0;
|
|
1600
|
-
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
1601
|
-
if (++seen <= count) {
|
|
1602
|
-
subscriber.next(value);
|
|
1603
|
-
if (count <= seen) {
|
|
1604
|
-
subscriber.complete();
|
|
1605
|
-
}
|
|
1606
|
-
}
|
|
1607
|
-
}));
|
|
1608
|
-
});
|
|
1609
|
-
}
|
|
1610
|
-
|
|
1611
|
-
function ignoreElements() {
|
|
1612
|
-
return operate(function (source, subscriber) {
|
|
1613
|
-
source.subscribe(createOperatorSubscriber(subscriber, noop));
|
|
1614
|
-
});
|
|
1615
|
-
}
|
|
1616
|
-
|
|
1617
|
-
function mapTo(value) {
|
|
1618
|
-
return map(function () { return value; });
|
|
1619
|
-
}
|
|
1620
|
-
|
|
1621
|
-
function delayWhen(delayDurationSelector, subscriptionDelay) {
|
|
1622
|
-
if (subscriptionDelay) {
|
|
1623
|
-
return function (source) {
|
|
1624
|
-
return concat$1(subscriptionDelay.pipe(take(1), ignoreElements()), source.pipe(delayWhen(delayDurationSelector)));
|
|
1625
|
-
};
|
|
1626
|
-
}
|
|
1627
|
-
return mergeMap(function (value, index) { return delayDurationSelector(value, index).pipe(take(1), mapTo(value)); });
|
|
1628
|
-
}
|
|
1629
|
-
|
|
1630
|
-
function delay(due, scheduler) {
|
|
1631
|
-
if (scheduler === void 0) { scheduler = asyncScheduler; }
|
|
1632
|
-
var duration = timer(due, scheduler);
|
|
1633
|
-
return delayWhen(function () { return duration; });
|
|
1634
|
-
}
|
|
1635
|
-
|
|
1636
|
-
function distinctUntilChanged(comparator, keySelector) {
|
|
1637
|
-
if (keySelector === void 0) { keySelector = identity; }
|
|
1638
|
-
comparator = comparator !== null && comparator !== void 0 ? comparator : defaultCompare;
|
|
1639
|
-
return operate(function (source, subscriber) {
|
|
1640
|
-
var previousKey;
|
|
1641
|
-
var first = true;
|
|
1642
|
-
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
1643
|
-
var currentKey = keySelector(value);
|
|
1644
|
-
if (first || !comparator(previousKey, currentKey)) {
|
|
1645
|
-
first = false;
|
|
1646
|
-
previousKey = currentKey;
|
|
1647
|
-
subscriber.next(value);
|
|
1648
|
-
}
|
|
1649
|
-
}));
|
|
1650
|
-
});
|
|
1651
|
-
}
|
|
1652
|
-
function defaultCompare(a, b) {
|
|
1653
|
-
return a === b;
|
|
1654
|
-
}
|
|
1655
|
-
|
|
1656
|
-
function filter(predicate, thisArg) {
|
|
1657
|
-
return operate(function (source, subscriber) {
|
|
1658
|
-
var index = 0;
|
|
1659
|
-
source.subscribe(createOperatorSubscriber(subscriber, function (value) { return predicate.call(thisArg, value, index++) && subscriber.next(value); }));
|
|
1660
|
-
});
|
|
1661
|
-
}
|
|
1662
|
-
|
|
1663
|
-
function skip(count) {
|
|
1664
|
-
return filter(function (_, index) { return count <= index; });
|
|
1665
|
-
}
|
|
1666
|
-
|
|
1667
|
-
function startWith() {
|
|
1668
|
-
var values = [];
|
|
1669
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1670
|
-
values[_i] = arguments[_i];
|
|
1671
|
-
}
|
|
1672
|
-
var scheduler = popScheduler(values);
|
|
1673
|
-
return operate(function (source, subscriber) {
|
|
1674
|
-
(scheduler ? concat$1(values, source, scheduler) : concat$1(values, source)).subscribe(subscriber);
|
|
1675
|
-
});
|
|
1676
|
-
}
|
|
1677
|
-
|
|
1678
|
-
function switchMap(project, resultSelector) {
|
|
1679
|
-
return operate(function (source, subscriber) {
|
|
1680
|
-
var innerSubscriber = null;
|
|
1681
|
-
var index = 0;
|
|
1682
|
-
var isComplete = false;
|
|
1683
|
-
var checkComplete = function () { return isComplete && !innerSubscriber && subscriber.complete(); };
|
|
1684
|
-
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
1685
|
-
innerSubscriber === null || innerSubscriber === void 0 ? void 0 : innerSubscriber.unsubscribe();
|
|
1686
|
-
var innerIndex = 0;
|
|
1687
|
-
var outerIndex = index++;
|
|
1688
|
-
innerFrom(project(value, outerIndex)).subscribe((innerSubscriber = createOperatorSubscriber(subscriber, function (innerValue) { return subscriber.next(resultSelector ? resultSelector(value, innerValue, outerIndex, innerIndex++) : innerValue); }, function () {
|
|
1689
|
-
innerSubscriber = null;
|
|
1690
|
-
checkComplete();
|
|
1691
|
-
})));
|
|
1692
|
-
}, function () {
|
|
1693
|
-
isComplete = true;
|
|
1694
|
-
checkComplete();
|
|
1695
|
-
}));
|
|
1696
|
-
});
|
|
1697
|
-
}
|
|
1698
|
-
|
|
1699
|
-
function tap(observerOrNext, error, complete) {
|
|
1700
|
-
var tapObserver = isFunction(observerOrNext) || error || complete
|
|
1701
|
-
?
|
|
1702
|
-
{ next: observerOrNext, error: error, complete: complete }
|
|
1703
|
-
: observerOrNext;
|
|
1704
|
-
return tapObserver
|
|
1705
|
-
? operate(function (source, subscriber) {
|
|
1706
|
-
var _a;
|
|
1707
|
-
(_a = tapObserver.subscribe) === null || _a === void 0 ? void 0 : _a.call(tapObserver);
|
|
1708
|
-
var isUnsub = true;
|
|
1709
|
-
source.subscribe(createOperatorSubscriber(subscriber, function (value) {
|
|
1710
|
-
var _a;
|
|
1711
|
-
(_a = tapObserver.next) === null || _a === void 0 ? void 0 : _a.call(tapObserver, value);
|
|
1712
|
-
subscriber.next(value);
|
|
1713
|
-
}, function () {
|
|
1714
|
-
var _a;
|
|
1715
|
-
isUnsub = false;
|
|
1716
|
-
(_a = tapObserver.complete) === null || _a === void 0 ? void 0 : _a.call(tapObserver);
|
|
1717
|
-
subscriber.complete();
|
|
1718
|
-
}, function (err) {
|
|
1719
|
-
var _a;
|
|
1720
|
-
isUnsub = false;
|
|
1721
|
-
(_a = tapObserver.error) === null || _a === void 0 ? void 0 : _a.call(tapObserver, err);
|
|
1722
|
-
subscriber.error(err);
|
|
1723
|
-
}, function () {
|
|
1724
|
-
var _a, _b;
|
|
1725
|
-
if (isUnsub) {
|
|
1726
|
-
(_a = tapObserver.unsubscribe) === null || _a === void 0 ? void 0 : _a.call(tapObserver);
|
|
1727
|
-
}
|
|
1728
|
-
(_b = tapObserver.finalize) === null || _b === void 0 ? void 0 : _b.call(tapObserver);
|
|
1729
|
-
}));
|
|
1730
|
-
})
|
|
1731
|
-
:
|
|
1732
|
-
identity;
|
|
244
|
+
next(message) {
|
|
245
|
+
console.debug("BroadcastedAndLocalEvent: bc.postMessage()", Object.assign({}, message), "bc is a", this.bc);
|
|
246
|
+
this.bc.postMessage(message);
|
|
247
|
+
const ev = new CustomEvent(`lbc-${this.name}`, { detail: message });
|
|
248
|
+
//self.dispatchEvent(ev);
|
|
249
|
+
dispatch(ev);
|
|
250
|
+
}
|
|
1733
251
|
}
|
|
1734
252
|
|
|
1735
253
|
//const hasSW = 'serviceWorker' in navigator;
|
|
@@ -2257,515 +775,6 @@ function getDbNameFromDbUrl(dbUrl) {
|
|
|
2257
775
|
: url.pathname.split('/')[1];
|
|
2258
776
|
}
|
|
2259
777
|
|
|
2260
|
-
/**
|
|
2261
|
-
* Common Math expressions.
|
|
2262
|
-
*
|
|
2263
|
-
* @module math
|
|
2264
|
-
*/
|
|
2265
|
-
|
|
2266
|
-
const floor = Math.floor;
|
|
2267
|
-
const abs = Math.abs;
|
|
2268
|
-
|
|
2269
|
-
/**
|
|
2270
|
-
* @function
|
|
2271
|
-
* @param {number} a
|
|
2272
|
-
* @param {number} b
|
|
2273
|
-
* @return {number} The smaller element of a and b
|
|
2274
|
-
*/
|
|
2275
|
-
const min = (a, b) => a < b ? a : b;
|
|
2276
|
-
|
|
2277
|
-
/**
|
|
2278
|
-
* @function
|
|
2279
|
-
* @param {number} a
|
|
2280
|
-
* @param {number} b
|
|
2281
|
-
* @return {number} The bigger element of a and b
|
|
2282
|
-
*/
|
|
2283
|
-
const max = (a, b) => a > b ? a : b;
|
|
2284
|
-
|
|
2285
|
-
/**
|
|
2286
|
-
* @param {number} n
|
|
2287
|
-
* @return {boolean} Wether n is negative. This function also differentiates between -0 and +0
|
|
2288
|
-
*/
|
|
2289
|
-
const isNegativeZero = n => n !== 0 ? n < 0 : 1 / n < 0;
|
|
2290
|
-
|
|
2291
|
-
/* eslint-env browser */
|
|
2292
|
-
|
|
2293
|
-
const BIT7 = 64;
|
|
2294
|
-
const BIT8 = 128;
|
|
2295
|
-
const BITS6 = 63;
|
|
2296
|
-
const BITS7 = 127;
|
|
2297
|
-
/**
|
|
2298
|
-
* @type {number}
|
|
2299
|
-
*/
|
|
2300
|
-
const BITS31 = 0x7FFFFFFF;
|
|
2301
|
-
|
|
2302
|
-
/**
|
|
2303
|
-
* Utility helpers for working with numbers.
|
|
2304
|
-
*
|
|
2305
|
-
* @module number
|
|
2306
|
-
*/
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER;
|
|
2310
|
-
|
|
2311
|
-
/* c8 ignore next */
|
|
2312
|
-
const isInteger = Number.isInteger || (num => typeof num === 'number' && isFinite(num) && floor(num) === num);
|
|
2313
|
-
|
|
2314
|
-
/**
|
|
2315
|
-
* Utility module to work with Arrays.
|
|
2316
|
-
*
|
|
2317
|
-
* @module array
|
|
2318
|
-
*/
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
const isArray = Array.isArray;
|
|
2322
|
-
|
|
2323
|
-
/**
|
|
2324
|
-
* @param {string} str
|
|
2325
|
-
* @return {Uint8Array}
|
|
2326
|
-
*/
|
|
2327
|
-
const _encodeUtf8Polyfill = str => {
|
|
2328
|
-
const encodedString = unescape(encodeURIComponent(str));
|
|
2329
|
-
const len = encodedString.length;
|
|
2330
|
-
const buf = new Uint8Array(len);
|
|
2331
|
-
for (let i = 0; i < len; i++) {
|
|
2332
|
-
buf[i] = /** @type {number} */ (encodedString.codePointAt(i));
|
|
2333
|
-
}
|
|
2334
|
-
return buf
|
|
2335
|
-
};
|
|
2336
|
-
|
|
2337
|
-
/* c8 ignore next */
|
|
2338
|
-
const utf8TextEncoder = /** @type {TextEncoder} */ (typeof TextEncoder !== 'undefined' ? new TextEncoder() : null);
|
|
2339
|
-
|
|
2340
|
-
/**
|
|
2341
|
-
* @param {string} str
|
|
2342
|
-
* @return {Uint8Array}
|
|
2343
|
-
*/
|
|
2344
|
-
const _encodeUtf8Native = str => utf8TextEncoder.encode(str);
|
|
2345
|
-
|
|
2346
|
-
/**
|
|
2347
|
-
* @param {string} str
|
|
2348
|
-
* @return {Uint8Array}
|
|
2349
|
-
*/
|
|
2350
|
-
/* c8 ignore next */
|
|
2351
|
-
const encodeUtf8 = utf8TextEncoder ? _encodeUtf8Native : _encodeUtf8Polyfill;
|
|
2352
|
-
|
|
2353
|
-
/* c8 ignore next */
|
|
2354
|
-
let utf8TextDecoder = typeof TextDecoder === 'undefined' ? null : new TextDecoder('utf-8', { fatal: true, ignoreBOM: true });
|
|
2355
|
-
|
|
2356
|
-
/* c8 ignore start */
|
|
2357
|
-
if (utf8TextDecoder && utf8TextDecoder.decode(new Uint8Array()).length === 1) {
|
|
2358
|
-
// Safari doesn't handle BOM correctly.
|
|
2359
|
-
// This fixes a bug in Safari 13.0.5 where it produces a BOM the first time it is called.
|
|
2360
|
-
// utf8TextDecoder.decode(new Uint8Array()).length === 1 on the first call and
|
|
2361
|
-
// utf8TextDecoder.decode(new Uint8Array()).length === 1 on the second call
|
|
2362
|
-
// Another issue is that from then on no BOM chars are recognized anymore
|
|
2363
|
-
/* c8 ignore next */
|
|
2364
|
-
utf8TextDecoder = null;
|
|
2365
|
-
}
|
|
2366
|
-
|
|
2367
|
-
/**
|
|
2368
|
-
* Efficient schema-less binary encoding with support for variable length encoding.
|
|
2369
|
-
*
|
|
2370
|
-
* Use [lib0/encoding] with [lib0/decoding]. Every encoding function has a corresponding decoding function.
|
|
2371
|
-
*
|
|
2372
|
-
* Encodes numbers in little-endian order (least to most significant byte order)
|
|
2373
|
-
* and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/)
|
|
2374
|
-
* which is also used in Protocol Buffers.
|
|
2375
|
-
*
|
|
2376
|
-
* ```js
|
|
2377
|
-
* // encoding step
|
|
2378
|
-
* const encoder = encoding.createEncoder()
|
|
2379
|
-
* encoding.writeVarUint(encoder, 256)
|
|
2380
|
-
* encoding.writeVarString(encoder, 'Hello world!')
|
|
2381
|
-
* const buf = encoding.toUint8Array(encoder)
|
|
2382
|
-
* ```
|
|
2383
|
-
*
|
|
2384
|
-
* ```js
|
|
2385
|
-
* // decoding step
|
|
2386
|
-
* const decoder = decoding.createDecoder(buf)
|
|
2387
|
-
* decoding.readVarUint(decoder) // => 256
|
|
2388
|
-
* decoding.readVarString(decoder) // => 'Hello world!'
|
|
2389
|
-
* decoding.hasContent(decoder) // => false - all data is read
|
|
2390
|
-
* ```
|
|
2391
|
-
*
|
|
2392
|
-
* @module encoding
|
|
2393
|
-
*/
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
/**
|
|
2397
|
-
* A BinaryEncoder handles the encoding to an Uint8Array.
|
|
2398
|
-
*/
|
|
2399
|
-
class Encoder {
|
|
2400
|
-
constructor () {
|
|
2401
|
-
this.cpos = 0;
|
|
2402
|
-
this.cbuf = new Uint8Array(100);
|
|
2403
|
-
/**
|
|
2404
|
-
* @type {Array<Uint8Array>}
|
|
2405
|
-
*/
|
|
2406
|
-
this.bufs = [];
|
|
2407
|
-
}
|
|
2408
|
-
}
|
|
2409
|
-
|
|
2410
|
-
/**
|
|
2411
|
-
* The current length of the encoded data.
|
|
2412
|
-
*
|
|
2413
|
-
* @function
|
|
2414
|
-
* @param {Encoder} encoder
|
|
2415
|
-
* @return {number}
|
|
2416
|
-
*/
|
|
2417
|
-
const length = encoder => {
|
|
2418
|
-
let len = encoder.cpos;
|
|
2419
|
-
for (let i = 0; i < encoder.bufs.length; i++) {
|
|
2420
|
-
len += encoder.bufs[i].length;
|
|
2421
|
-
}
|
|
2422
|
-
return len
|
|
2423
|
-
};
|
|
2424
|
-
|
|
2425
|
-
/**
|
|
2426
|
-
* Transform to Uint8Array.
|
|
2427
|
-
*
|
|
2428
|
-
* @function
|
|
2429
|
-
* @param {Encoder} encoder
|
|
2430
|
-
* @return {Uint8Array} The created ArrayBuffer.
|
|
2431
|
-
*/
|
|
2432
|
-
const toUint8Array = encoder => {
|
|
2433
|
-
const uint8arr = new Uint8Array(length(encoder));
|
|
2434
|
-
let curPos = 0;
|
|
2435
|
-
for (let i = 0; i < encoder.bufs.length; i++) {
|
|
2436
|
-
const d = encoder.bufs[i];
|
|
2437
|
-
uint8arr.set(d, curPos);
|
|
2438
|
-
curPos += d.length;
|
|
2439
|
-
}
|
|
2440
|
-
uint8arr.set(new Uint8Array(encoder.cbuf.buffer, 0, encoder.cpos), curPos);
|
|
2441
|
-
return uint8arr
|
|
2442
|
-
};
|
|
2443
|
-
|
|
2444
|
-
/**
|
|
2445
|
-
* Verify that it is possible to write `len` bytes wtihout checking. If
|
|
2446
|
-
* necessary, a new Buffer with the required length is attached.
|
|
2447
|
-
*
|
|
2448
|
-
* @param {Encoder} encoder
|
|
2449
|
-
* @param {number} len
|
|
2450
|
-
*/
|
|
2451
|
-
const verifyLen = (encoder, len) => {
|
|
2452
|
-
const bufferLen = encoder.cbuf.length;
|
|
2453
|
-
if (bufferLen - encoder.cpos < len) {
|
|
2454
|
-
encoder.bufs.push(new Uint8Array(encoder.cbuf.buffer, 0, encoder.cpos));
|
|
2455
|
-
encoder.cbuf = new Uint8Array(max(bufferLen, len) * 2);
|
|
2456
|
-
encoder.cpos = 0;
|
|
2457
|
-
}
|
|
2458
|
-
};
|
|
2459
|
-
|
|
2460
|
-
/**
|
|
2461
|
-
* Write one byte to the encoder.
|
|
2462
|
-
*
|
|
2463
|
-
* @function
|
|
2464
|
-
* @param {Encoder} encoder
|
|
2465
|
-
* @param {number} num The byte that is to be encoded.
|
|
2466
|
-
*/
|
|
2467
|
-
const write = (encoder, num) => {
|
|
2468
|
-
const bufferLen = encoder.cbuf.length;
|
|
2469
|
-
if (encoder.cpos === bufferLen) {
|
|
2470
|
-
encoder.bufs.push(encoder.cbuf);
|
|
2471
|
-
encoder.cbuf = new Uint8Array(bufferLen * 2);
|
|
2472
|
-
encoder.cpos = 0;
|
|
2473
|
-
}
|
|
2474
|
-
encoder.cbuf[encoder.cpos++] = num;
|
|
2475
|
-
};
|
|
2476
|
-
|
|
2477
|
-
/**
|
|
2478
|
-
* Write a variable length unsigned integer. Max encodable integer is 2^53.
|
|
2479
|
-
*
|
|
2480
|
-
* @function
|
|
2481
|
-
* @param {Encoder} encoder
|
|
2482
|
-
* @param {number} num The number that is to be encoded.
|
|
2483
|
-
*/
|
|
2484
|
-
const writeVarUint = (encoder, num) => {
|
|
2485
|
-
while (num > BITS7) {
|
|
2486
|
-
write(encoder, BIT8 | (BITS7 & num));
|
|
2487
|
-
num = floor(num / 128); // shift >>> 7
|
|
2488
|
-
}
|
|
2489
|
-
write(encoder, BITS7 & num);
|
|
2490
|
-
};
|
|
2491
|
-
|
|
2492
|
-
/**
|
|
2493
|
-
* Write a variable length integer.
|
|
2494
|
-
*
|
|
2495
|
-
* We use the 7th bit instead for signaling that this is a negative number.
|
|
2496
|
-
*
|
|
2497
|
-
* @function
|
|
2498
|
-
* @param {Encoder} encoder
|
|
2499
|
-
* @param {number} num The number that is to be encoded.
|
|
2500
|
-
*/
|
|
2501
|
-
const writeVarInt = (encoder, num) => {
|
|
2502
|
-
const isNegative = isNegativeZero(num);
|
|
2503
|
-
if (isNegative) {
|
|
2504
|
-
num = -num;
|
|
2505
|
-
}
|
|
2506
|
-
// |- whether to continue reading |- whether is negative |- number
|
|
2507
|
-
write(encoder, (num > BITS6 ? BIT8 : 0) | (isNegative ? BIT7 : 0) | (BITS6 & num));
|
|
2508
|
-
num = floor(num / 64); // shift >>> 6
|
|
2509
|
-
// We don't need to consider the case of num === 0 so we can use a different
|
|
2510
|
-
// pattern here than above.
|
|
2511
|
-
while (num > 0) {
|
|
2512
|
-
write(encoder, (num > BITS7 ? BIT8 : 0) | (BITS7 & num));
|
|
2513
|
-
num = floor(num / 128); // shift >>> 7
|
|
2514
|
-
}
|
|
2515
|
-
};
|
|
2516
|
-
|
|
2517
|
-
/**
|
|
2518
|
-
* A cache to store strings temporarily
|
|
2519
|
-
*/
|
|
2520
|
-
const _strBuffer = new Uint8Array(30000);
|
|
2521
|
-
const _maxStrBSize = _strBuffer.length / 3;
|
|
2522
|
-
|
|
2523
|
-
/**
|
|
2524
|
-
* Write a variable length string.
|
|
2525
|
-
*
|
|
2526
|
-
* @function
|
|
2527
|
-
* @param {Encoder} encoder
|
|
2528
|
-
* @param {String} str The string that is to be encoded.
|
|
2529
|
-
*/
|
|
2530
|
-
const _writeVarStringNative = (encoder, str) => {
|
|
2531
|
-
if (str.length < _maxStrBSize) {
|
|
2532
|
-
// We can encode the string into the existing buffer
|
|
2533
|
-
/* c8 ignore next */
|
|
2534
|
-
const written = utf8TextEncoder.encodeInto(str, _strBuffer).written || 0;
|
|
2535
|
-
writeVarUint(encoder, written);
|
|
2536
|
-
for (let i = 0; i < written; i++) {
|
|
2537
|
-
write(encoder, _strBuffer[i]);
|
|
2538
|
-
}
|
|
2539
|
-
} else {
|
|
2540
|
-
writeVarUint8Array(encoder, encodeUtf8(str));
|
|
2541
|
-
}
|
|
2542
|
-
};
|
|
2543
|
-
|
|
2544
|
-
/**
|
|
2545
|
-
* Write a variable length string.
|
|
2546
|
-
*
|
|
2547
|
-
* @function
|
|
2548
|
-
* @param {Encoder} encoder
|
|
2549
|
-
* @param {String} str The string that is to be encoded.
|
|
2550
|
-
*/
|
|
2551
|
-
const _writeVarStringPolyfill = (encoder, str) => {
|
|
2552
|
-
const encodedString = unescape(encodeURIComponent(str));
|
|
2553
|
-
const len = encodedString.length;
|
|
2554
|
-
writeVarUint(encoder, len);
|
|
2555
|
-
for (let i = 0; i < len; i++) {
|
|
2556
|
-
write(encoder, /** @type {number} */ (encodedString.codePointAt(i)));
|
|
2557
|
-
}
|
|
2558
|
-
};
|
|
2559
|
-
|
|
2560
|
-
/**
|
|
2561
|
-
* Write a variable length string.
|
|
2562
|
-
*
|
|
2563
|
-
* @function
|
|
2564
|
-
* @param {Encoder} encoder
|
|
2565
|
-
* @param {String} str The string that is to be encoded.
|
|
2566
|
-
*/
|
|
2567
|
-
/* c8 ignore next */
|
|
2568
|
-
const writeVarString = (utf8TextEncoder && /** @type {any} */ (utf8TextEncoder).encodeInto) ? _writeVarStringNative : _writeVarStringPolyfill;
|
|
2569
|
-
|
|
2570
|
-
/**
|
|
2571
|
-
* Append fixed-length Uint8Array to the encoder.
|
|
2572
|
-
*
|
|
2573
|
-
* @function
|
|
2574
|
-
* @param {Encoder} encoder
|
|
2575
|
-
* @param {Uint8Array} uint8Array
|
|
2576
|
-
*/
|
|
2577
|
-
const writeUint8Array = (encoder, uint8Array) => {
|
|
2578
|
-
const bufferLen = encoder.cbuf.length;
|
|
2579
|
-
const cpos = encoder.cpos;
|
|
2580
|
-
const leftCopyLen = min(bufferLen - cpos, uint8Array.length);
|
|
2581
|
-
const rightCopyLen = uint8Array.length - leftCopyLen;
|
|
2582
|
-
encoder.cbuf.set(uint8Array.subarray(0, leftCopyLen), cpos);
|
|
2583
|
-
encoder.cpos += leftCopyLen;
|
|
2584
|
-
if (rightCopyLen > 0) {
|
|
2585
|
-
// Still something to write, write right half..
|
|
2586
|
-
// Append new buffer
|
|
2587
|
-
encoder.bufs.push(encoder.cbuf);
|
|
2588
|
-
// must have at least size of remaining buffer
|
|
2589
|
-
encoder.cbuf = new Uint8Array(max(bufferLen * 2, rightCopyLen));
|
|
2590
|
-
// copy array
|
|
2591
|
-
encoder.cbuf.set(uint8Array.subarray(leftCopyLen));
|
|
2592
|
-
encoder.cpos = rightCopyLen;
|
|
2593
|
-
}
|
|
2594
|
-
};
|
|
2595
|
-
|
|
2596
|
-
/**
|
|
2597
|
-
* Append an Uint8Array to Encoder.
|
|
2598
|
-
*
|
|
2599
|
-
* @function
|
|
2600
|
-
* @param {Encoder} encoder
|
|
2601
|
-
* @param {Uint8Array} uint8Array
|
|
2602
|
-
*/
|
|
2603
|
-
const writeVarUint8Array = (encoder, uint8Array) => {
|
|
2604
|
-
writeVarUint(encoder, uint8Array.byteLength);
|
|
2605
|
-
writeUint8Array(encoder, uint8Array);
|
|
2606
|
-
};
|
|
2607
|
-
|
|
2608
|
-
/**
|
|
2609
|
-
* Create an DataView of the next `len` bytes. Use it to write data after
|
|
2610
|
-
* calling this function.
|
|
2611
|
-
*
|
|
2612
|
-
* ```js
|
|
2613
|
-
* // write float32 using DataView
|
|
2614
|
-
* const dv = writeOnDataView(encoder, 4)
|
|
2615
|
-
* dv.setFloat32(0, 1.1)
|
|
2616
|
-
* // read float32 using DataView
|
|
2617
|
-
* const dv = readFromDataView(encoder, 4)
|
|
2618
|
-
* dv.getFloat32(0) // => 1.100000023841858 (leaving it to the reader to find out why this is the correct result)
|
|
2619
|
-
* ```
|
|
2620
|
-
*
|
|
2621
|
-
* @param {Encoder} encoder
|
|
2622
|
-
* @param {number} len
|
|
2623
|
-
* @return {DataView}
|
|
2624
|
-
*/
|
|
2625
|
-
const writeOnDataView = (encoder, len) => {
|
|
2626
|
-
verifyLen(encoder, len);
|
|
2627
|
-
const dview = new DataView(encoder.cbuf.buffer, encoder.cpos, len);
|
|
2628
|
-
encoder.cpos += len;
|
|
2629
|
-
return dview
|
|
2630
|
-
};
|
|
2631
|
-
|
|
2632
|
-
/**
|
|
2633
|
-
* @param {Encoder} encoder
|
|
2634
|
-
* @param {number} num
|
|
2635
|
-
*/
|
|
2636
|
-
const writeFloat32 = (encoder, num) => writeOnDataView(encoder, 4).setFloat32(0, num, false);
|
|
2637
|
-
|
|
2638
|
-
/**
|
|
2639
|
-
* @param {Encoder} encoder
|
|
2640
|
-
* @param {number} num
|
|
2641
|
-
*/
|
|
2642
|
-
const writeFloat64 = (encoder, num) => writeOnDataView(encoder, 8).setFloat64(0, num, false);
|
|
2643
|
-
|
|
2644
|
-
/**
|
|
2645
|
-
* @param {Encoder} encoder
|
|
2646
|
-
* @param {bigint} num
|
|
2647
|
-
*/
|
|
2648
|
-
const writeBigInt64 = (encoder, num) => /** @type {any} */ (writeOnDataView(encoder, 8)).setBigInt64(0, num, false);
|
|
2649
|
-
|
|
2650
|
-
/**
|
|
2651
|
-
* @param {Encoder} encoder
|
|
2652
|
-
* @param {bigint} num
|
|
2653
|
-
*/
|
|
2654
|
-
const writeBigUint64 = (encoder, num) => /** @type {any} */ (writeOnDataView(encoder, 8)).setBigUint64(0, num, false);
|
|
2655
|
-
|
|
2656
|
-
const floatTestBed = new DataView(new ArrayBuffer(4));
|
|
2657
|
-
/**
|
|
2658
|
-
* Check if a number can be encoded as a 32 bit float.
|
|
2659
|
-
*
|
|
2660
|
-
* @param {number} num
|
|
2661
|
-
* @return {boolean}
|
|
2662
|
-
*/
|
|
2663
|
-
const isFloat32 = num => {
|
|
2664
|
-
floatTestBed.setFloat32(0, num);
|
|
2665
|
-
return floatTestBed.getFloat32(0) === num
|
|
2666
|
-
};
|
|
2667
|
-
|
|
2668
|
-
/**
|
|
2669
|
-
* Encode data with efficient binary format.
|
|
2670
|
-
*
|
|
2671
|
-
* Differences to JSON:
|
|
2672
|
-
* • Transforms data to a binary format (not to a string)
|
|
2673
|
-
* • Encodes undefined, NaN, and ArrayBuffer (these can't be represented in JSON)
|
|
2674
|
-
* • Numbers are efficiently encoded either as a variable length integer, as a
|
|
2675
|
-
* 32 bit float, as a 64 bit float, or as a 64 bit bigint.
|
|
2676
|
-
*
|
|
2677
|
-
* Encoding table:
|
|
2678
|
-
*
|
|
2679
|
-
* | Data Type | Prefix | Encoding Method | Comment |
|
|
2680
|
-
* | ------------------- | -------- | ------------------ | ------- |
|
|
2681
|
-
* | undefined | 127 | | Functions, symbol, and everything that cannot be identified is encoded as undefined |
|
|
2682
|
-
* | null | 126 | | |
|
|
2683
|
-
* | integer | 125 | writeVarInt | Only encodes 32 bit signed integers |
|
|
2684
|
-
* | float32 | 124 | writeFloat32 | |
|
|
2685
|
-
* | float64 | 123 | writeFloat64 | |
|
|
2686
|
-
* | bigint | 122 | writeBigInt64 | |
|
|
2687
|
-
* | boolean (false) | 121 | | True and false are different data types so we save the following byte |
|
|
2688
|
-
* | boolean (true) | 120 | | - 0b01111000 so the last bit determines whether true or false |
|
|
2689
|
-
* | string | 119 | writeVarString | |
|
|
2690
|
-
* | object<string,any> | 118 | custom | Writes {length} then {length} key-value pairs |
|
|
2691
|
-
* | array<any> | 117 | custom | Writes {length} then {length} json values |
|
|
2692
|
-
* | Uint8Array | 116 | writeVarUint8Array | We use Uint8Array for any kind of binary data |
|
|
2693
|
-
*
|
|
2694
|
-
* Reasons for the decreasing prefix:
|
|
2695
|
-
* We need the first bit for extendability (later we may want to encode the
|
|
2696
|
-
* prefix with writeVarUint). The remaining 7 bits are divided as follows:
|
|
2697
|
-
* [0-30] the beginning of the data range is used for custom purposes
|
|
2698
|
-
* (defined by the function that uses this library)
|
|
2699
|
-
* [31-127] the end of the data range is used for data encoding by
|
|
2700
|
-
* lib0/encoding.js
|
|
2701
|
-
*
|
|
2702
|
-
* @param {Encoder} encoder
|
|
2703
|
-
* @param {undefined|null|number|bigint|boolean|string|Object<string,any>|Array<any>|Uint8Array} data
|
|
2704
|
-
*/
|
|
2705
|
-
const writeAny = (encoder, data) => {
|
|
2706
|
-
switch (typeof data) {
|
|
2707
|
-
case 'string':
|
|
2708
|
-
// TYPE 119: STRING
|
|
2709
|
-
write(encoder, 119);
|
|
2710
|
-
writeVarString(encoder, data);
|
|
2711
|
-
break
|
|
2712
|
-
case 'number':
|
|
2713
|
-
if (isInteger(data) && abs(data) <= BITS31) {
|
|
2714
|
-
// TYPE 125: INTEGER
|
|
2715
|
-
write(encoder, 125);
|
|
2716
|
-
writeVarInt(encoder, data);
|
|
2717
|
-
} else if (isFloat32(data)) {
|
|
2718
|
-
// TYPE 124: FLOAT32
|
|
2719
|
-
write(encoder, 124);
|
|
2720
|
-
writeFloat32(encoder, data);
|
|
2721
|
-
} else {
|
|
2722
|
-
// TYPE 123: FLOAT64
|
|
2723
|
-
write(encoder, 123);
|
|
2724
|
-
writeFloat64(encoder, data);
|
|
2725
|
-
}
|
|
2726
|
-
break
|
|
2727
|
-
case 'bigint':
|
|
2728
|
-
// TYPE 122: BigInt
|
|
2729
|
-
write(encoder, 122);
|
|
2730
|
-
writeBigInt64(encoder, data);
|
|
2731
|
-
break
|
|
2732
|
-
case 'object':
|
|
2733
|
-
if (data === null) {
|
|
2734
|
-
// TYPE 126: null
|
|
2735
|
-
write(encoder, 126);
|
|
2736
|
-
} else if (isArray(data)) {
|
|
2737
|
-
// TYPE 117: Array
|
|
2738
|
-
write(encoder, 117);
|
|
2739
|
-
writeVarUint(encoder, data.length);
|
|
2740
|
-
for (let i = 0; i < data.length; i++) {
|
|
2741
|
-
writeAny(encoder, data[i]);
|
|
2742
|
-
}
|
|
2743
|
-
} else if (data instanceof Uint8Array) {
|
|
2744
|
-
// TYPE 116: ArrayBuffer
|
|
2745
|
-
write(encoder, 116);
|
|
2746
|
-
writeVarUint8Array(encoder, data);
|
|
2747
|
-
} else {
|
|
2748
|
-
// TYPE 118: Object
|
|
2749
|
-
write(encoder, 118);
|
|
2750
|
-
const keys = Object.keys(data);
|
|
2751
|
-
writeVarUint(encoder, keys.length);
|
|
2752
|
-
for (let i = 0; i < keys.length; i++) {
|
|
2753
|
-
const key = keys[i];
|
|
2754
|
-
writeVarString(encoder, key);
|
|
2755
|
-
writeAny(encoder, data[key]);
|
|
2756
|
-
}
|
|
2757
|
-
}
|
|
2758
|
-
break
|
|
2759
|
-
case 'boolean':
|
|
2760
|
-
// TYPE 120/121: boolean (true/false)
|
|
2761
|
-
write(encoder, data ? 120 : 121);
|
|
2762
|
-
break
|
|
2763
|
-
default:
|
|
2764
|
-
// TYPE 127: undefined
|
|
2765
|
-
write(encoder, 127);
|
|
2766
|
-
}
|
|
2767
|
-
};
|
|
2768
|
-
|
|
2769
778
|
function encodeYMessage(msg) {
|
|
2770
779
|
const encoder = new Encoder();
|
|
2771
780
|
writeVarString(encoder, msg.type);
|
|
@@ -2811,319 +820,6 @@ function encodeYMessage(msg) {
|
|
|
2811
820
|
return toUint8Array(encoder);
|
|
2812
821
|
}
|
|
2813
822
|
|
|
2814
|
-
/**
|
|
2815
|
-
* Error helpers.
|
|
2816
|
-
*
|
|
2817
|
-
* @module error
|
|
2818
|
-
*/
|
|
2819
|
-
|
|
2820
|
-
/**
|
|
2821
|
-
* @param {string} s
|
|
2822
|
-
* @return {Error}
|
|
2823
|
-
*/
|
|
2824
|
-
/* c8 ignore next */
|
|
2825
|
-
const create = s => new Error(s);
|
|
2826
|
-
|
|
2827
|
-
/**
|
|
2828
|
-
* Efficient schema-less binary decoding with support for variable length encoding.
|
|
2829
|
-
*
|
|
2830
|
-
* Use [lib0/decoding] with [lib0/encoding]. Every encoding function has a corresponding decoding function.
|
|
2831
|
-
*
|
|
2832
|
-
* Encodes numbers in little-endian order (least to most significant byte order)
|
|
2833
|
-
* and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/)
|
|
2834
|
-
* which is also used in Protocol Buffers.
|
|
2835
|
-
*
|
|
2836
|
-
* ```js
|
|
2837
|
-
* // encoding step
|
|
2838
|
-
* const encoder = encoding.createEncoder()
|
|
2839
|
-
* encoding.writeVarUint(encoder, 256)
|
|
2840
|
-
* encoding.writeVarString(encoder, 'Hello world!')
|
|
2841
|
-
* const buf = encoding.toUint8Array(encoder)
|
|
2842
|
-
* ```
|
|
2843
|
-
*
|
|
2844
|
-
* ```js
|
|
2845
|
-
* // decoding step
|
|
2846
|
-
* const decoder = decoding.createDecoder(buf)
|
|
2847
|
-
* decoding.readVarUint(decoder) // => 256
|
|
2848
|
-
* decoding.readVarString(decoder) // => 'Hello world!'
|
|
2849
|
-
* decoding.hasContent(decoder) // => false - all data is read
|
|
2850
|
-
* ```
|
|
2851
|
-
*
|
|
2852
|
-
* @module decoding
|
|
2853
|
-
*/
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
const errorUnexpectedEndOfArray = create('Unexpected end of array');
|
|
2857
|
-
const errorIntegerOutOfRange = create('Integer out of Range');
|
|
2858
|
-
|
|
2859
|
-
/**
|
|
2860
|
-
* A Decoder handles the decoding of an Uint8Array.
|
|
2861
|
-
*/
|
|
2862
|
-
class Decoder {
|
|
2863
|
-
/**
|
|
2864
|
-
* @param {Uint8Array} uint8Array Binary data to decode
|
|
2865
|
-
*/
|
|
2866
|
-
constructor (uint8Array) {
|
|
2867
|
-
/**
|
|
2868
|
-
* Decoding target.
|
|
2869
|
-
*
|
|
2870
|
-
* @type {Uint8Array}
|
|
2871
|
-
*/
|
|
2872
|
-
this.arr = uint8Array;
|
|
2873
|
-
/**
|
|
2874
|
-
* Current decoding position.
|
|
2875
|
-
*
|
|
2876
|
-
* @type {number}
|
|
2877
|
-
*/
|
|
2878
|
-
this.pos = 0;
|
|
2879
|
-
}
|
|
2880
|
-
}
|
|
2881
|
-
|
|
2882
|
-
/**
|
|
2883
|
-
* @function
|
|
2884
|
-
* @param {Decoder} decoder
|
|
2885
|
-
* @return {boolean}
|
|
2886
|
-
*/
|
|
2887
|
-
const hasContent = decoder => decoder.pos !== decoder.arr.length;
|
|
2888
|
-
|
|
2889
|
-
/**
|
|
2890
|
-
* Create an Uint8Array view of the next `len` bytes and advance the position by `len`.
|
|
2891
|
-
*
|
|
2892
|
-
* Important: The Uint8Array still points to the underlying ArrayBuffer. Make sure to discard the result as soon as possible to prevent any memory leaks.
|
|
2893
|
-
* Use `buffer.copyUint8Array` to copy the result into a new Uint8Array.
|
|
2894
|
-
*
|
|
2895
|
-
* @function
|
|
2896
|
-
* @param {Decoder} decoder The decoder instance
|
|
2897
|
-
* @param {number} len The length of bytes to read
|
|
2898
|
-
* @return {Uint8Array}
|
|
2899
|
-
*/
|
|
2900
|
-
const readUint8Array = (decoder, len) => {
|
|
2901
|
-
const view = new Uint8Array(decoder.arr.buffer, decoder.pos + decoder.arr.byteOffset, len);
|
|
2902
|
-
decoder.pos += len;
|
|
2903
|
-
return view
|
|
2904
|
-
};
|
|
2905
|
-
|
|
2906
|
-
/**
|
|
2907
|
-
* Read variable length Uint8Array.
|
|
2908
|
-
*
|
|
2909
|
-
* Important: The Uint8Array still points to the underlying ArrayBuffer. Make sure to discard the result as soon as possible to prevent any memory leaks.
|
|
2910
|
-
* Use `buffer.copyUint8Array` to copy the result into a new Uint8Array.
|
|
2911
|
-
*
|
|
2912
|
-
* @function
|
|
2913
|
-
* @param {Decoder} decoder
|
|
2914
|
-
* @return {Uint8Array}
|
|
2915
|
-
*/
|
|
2916
|
-
const readVarUint8Array = decoder => readUint8Array(decoder, readVarUint(decoder));
|
|
2917
|
-
|
|
2918
|
-
/**
|
|
2919
|
-
* Read one byte as unsigned integer.
|
|
2920
|
-
* @function
|
|
2921
|
-
* @param {Decoder} decoder The decoder instance
|
|
2922
|
-
* @return {number} Unsigned 8-bit integer
|
|
2923
|
-
*/
|
|
2924
|
-
const readUint8 = decoder => decoder.arr[decoder.pos++];
|
|
2925
|
-
|
|
2926
|
-
/**
|
|
2927
|
-
* Read unsigned integer (32bit) with variable length.
|
|
2928
|
-
* 1/8th of the storage is used as encoding overhead.
|
|
2929
|
-
* * numbers < 2^7 is stored in one bytlength
|
|
2930
|
-
* * numbers < 2^14 is stored in two bylength
|
|
2931
|
-
*
|
|
2932
|
-
* @function
|
|
2933
|
-
* @param {Decoder} decoder
|
|
2934
|
-
* @return {number} An unsigned integer.length
|
|
2935
|
-
*/
|
|
2936
|
-
const readVarUint = decoder => {
|
|
2937
|
-
let num = 0;
|
|
2938
|
-
let mult = 1;
|
|
2939
|
-
const len = decoder.arr.length;
|
|
2940
|
-
while (decoder.pos < len) {
|
|
2941
|
-
const r = decoder.arr[decoder.pos++];
|
|
2942
|
-
// num = num | ((r & binary.BITS7) << len)
|
|
2943
|
-
num = num + (r & BITS7) * mult; // shift $r << (7*#iterations) and add it to num
|
|
2944
|
-
mult *= 128; // next iteration, shift 7 "more" to the left
|
|
2945
|
-
if (r < BIT8) {
|
|
2946
|
-
return num
|
|
2947
|
-
}
|
|
2948
|
-
/* c8 ignore start */
|
|
2949
|
-
if (num > MAX_SAFE_INTEGER) {
|
|
2950
|
-
throw errorIntegerOutOfRange
|
|
2951
|
-
}
|
|
2952
|
-
/* c8 ignore stop */
|
|
2953
|
-
}
|
|
2954
|
-
throw errorUnexpectedEndOfArray
|
|
2955
|
-
};
|
|
2956
|
-
|
|
2957
|
-
/**
|
|
2958
|
-
* Read signed integer (32bit) with variable length.
|
|
2959
|
-
* 1/8th of the storage is used as encoding overhead.
|
|
2960
|
-
* * numbers < 2^7 is stored in one bytlength
|
|
2961
|
-
* * numbers < 2^14 is stored in two bylength
|
|
2962
|
-
* @todo This should probably create the inverse ~num if number is negative - but this would be a breaking change.
|
|
2963
|
-
*
|
|
2964
|
-
* @function
|
|
2965
|
-
* @param {Decoder} decoder
|
|
2966
|
-
* @return {number} An unsigned integer.length
|
|
2967
|
-
*/
|
|
2968
|
-
const readVarInt = decoder => {
|
|
2969
|
-
let r = decoder.arr[decoder.pos++];
|
|
2970
|
-
let num = r & BITS6;
|
|
2971
|
-
let mult = 64;
|
|
2972
|
-
const sign = (r & BIT7) > 0 ? -1 : 1;
|
|
2973
|
-
if ((r & BIT8) === 0) {
|
|
2974
|
-
// don't continue reading
|
|
2975
|
-
return sign * num
|
|
2976
|
-
}
|
|
2977
|
-
const len = decoder.arr.length;
|
|
2978
|
-
while (decoder.pos < len) {
|
|
2979
|
-
r = decoder.arr[decoder.pos++];
|
|
2980
|
-
// num = num | ((r & binary.BITS7) << len)
|
|
2981
|
-
num = num + (r & BITS7) * mult;
|
|
2982
|
-
mult *= 128;
|
|
2983
|
-
if (r < BIT8) {
|
|
2984
|
-
return sign * num
|
|
2985
|
-
}
|
|
2986
|
-
/* c8 ignore start */
|
|
2987
|
-
if (num > MAX_SAFE_INTEGER) {
|
|
2988
|
-
throw errorIntegerOutOfRange
|
|
2989
|
-
}
|
|
2990
|
-
/* c8 ignore stop */
|
|
2991
|
-
}
|
|
2992
|
-
throw errorUnexpectedEndOfArray
|
|
2993
|
-
};
|
|
2994
|
-
|
|
2995
|
-
/**
|
|
2996
|
-
* We don't test this function anymore as we use native decoding/encoding by default now.
|
|
2997
|
-
* Better not modify this anymore..
|
|
2998
|
-
*
|
|
2999
|
-
* Transforming utf8 to a string is pretty expensive. The code performs 10x better
|
|
3000
|
-
* when String.fromCodePoint is fed with all characters as arguments.
|
|
3001
|
-
* But most environments have a maximum number of arguments per functions.
|
|
3002
|
-
* For effiency reasons we apply a maximum of 10000 characters at once.
|
|
3003
|
-
*
|
|
3004
|
-
* @function
|
|
3005
|
-
* @param {Decoder} decoder
|
|
3006
|
-
* @return {String} The read String.
|
|
3007
|
-
*/
|
|
3008
|
-
/* c8 ignore start */
|
|
3009
|
-
const _readVarStringPolyfill = decoder => {
|
|
3010
|
-
let remainingLen = readVarUint(decoder);
|
|
3011
|
-
if (remainingLen === 0) {
|
|
3012
|
-
return ''
|
|
3013
|
-
} else {
|
|
3014
|
-
let encodedString = String.fromCodePoint(readUint8(decoder)); // remember to decrease remainingLen
|
|
3015
|
-
if (--remainingLen < 100) { // do not create a Uint8Array for small strings
|
|
3016
|
-
while (remainingLen--) {
|
|
3017
|
-
encodedString += String.fromCodePoint(readUint8(decoder));
|
|
3018
|
-
}
|
|
3019
|
-
} else {
|
|
3020
|
-
while (remainingLen > 0) {
|
|
3021
|
-
const nextLen = remainingLen < 10000 ? remainingLen : 10000;
|
|
3022
|
-
// this is dangerous, we create a fresh array view from the existing buffer
|
|
3023
|
-
const bytes = decoder.arr.subarray(decoder.pos, decoder.pos + nextLen);
|
|
3024
|
-
decoder.pos += nextLen;
|
|
3025
|
-
// Starting with ES5.1 we can supply a generic array-like object as arguments
|
|
3026
|
-
encodedString += String.fromCodePoint.apply(null, /** @type {any} */ (bytes));
|
|
3027
|
-
remainingLen -= nextLen;
|
|
3028
|
-
}
|
|
3029
|
-
}
|
|
3030
|
-
return decodeURIComponent(escape(encodedString))
|
|
3031
|
-
}
|
|
3032
|
-
};
|
|
3033
|
-
/* c8 ignore stop */
|
|
3034
|
-
|
|
3035
|
-
/**
|
|
3036
|
-
* @function
|
|
3037
|
-
* @param {Decoder} decoder
|
|
3038
|
-
* @return {String} The read String
|
|
3039
|
-
*/
|
|
3040
|
-
const _readVarStringNative = decoder =>
|
|
3041
|
-
/** @type any */ (utf8TextDecoder).decode(readVarUint8Array(decoder));
|
|
3042
|
-
|
|
3043
|
-
/**
|
|
3044
|
-
* Read string of variable length
|
|
3045
|
-
* * varUint is used to store the length of the string
|
|
3046
|
-
*
|
|
3047
|
-
* @function
|
|
3048
|
-
* @param {Decoder} decoder
|
|
3049
|
-
* @return {String} The read String
|
|
3050
|
-
*
|
|
3051
|
-
*/
|
|
3052
|
-
/* c8 ignore next */
|
|
3053
|
-
const readVarString = utf8TextDecoder ? _readVarStringNative : _readVarStringPolyfill;
|
|
3054
|
-
|
|
3055
|
-
/**
|
|
3056
|
-
* @param {Decoder} decoder
|
|
3057
|
-
* @param {number} len
|
|
3058
|
-
* @return {DataView}
|
|
3059
|
-
*/
|
|
3060
|
-
const readFromDataView = (decoder, len) => {
|
|
3061
|
-
const dv = new DataView(decoder.arr.buffer, decoder.arr.byteOffset + decoder.pos, len);
|
|
3062
|
-
decoder.pos += len;
|
|
3063
|
-
return dv
|
|
3064
|
-
};
|
|
3065
|
-
|
|
3066
|
-
/**
|
|
3067
|
-
* @param {Decoder} decoder
|
|
3068
|
-
*/
|
|
3069
|
-
const readFloat32 = decoder => readFromDataView(decoder, 4).getFloat32(0, false);
|
|
3070
|
-
|
|
3071
|
-
/**
|
|
3072
|
-
* @param {Decoder} decoder
|
|
3073
|
-
*/
|
|
3074
|
-
const readFloat64 = decoder => readFromDataView(decoder, 8).getFloat64(0, false);
|
|
3075
|
-
|
|
3076
|
-
/**
|
|
3077
|
-
* @param {Decoder} decoder
|
|
3078
|
-
*/
|
|
3079
|
-
const readBigInt64 = decoder => /** @type {any} */ (readFromDataView(decoder, 8)).getBigInt64(0, false);
|
|
3080
|
-
|
|
3081
|
-
/**
|
|
3082
|
-
* @param {Decoder} decoder
|
|
3083
|
-
*/
|
|
3084
|
-
const readBigUint64 = decoder => /** @type {any} */ (readFromDataView(decoder, 8)).getBigUint64(0, false);
|
|
3085
|
-
|
|
3086
|
-
/**
|
|
3087
|
-
* @type {Array<function(Decoder):any>}
|
|
3088
|
-
*/
|
|
3089
|
-
const readAnyLookupTable = [
|
|
3090
|
-
decoder => undefined, // CASE 127: undefined
|
|
3091
|
-
decoder => null, // CASE 126: null
|
|
3092
|
-
readVarInt, // CASE 125: integer
|
|
3093
|
-
readFloat32, // CASE 124: float32
|
|
3094
|
-
readFloat64, // CASE 123: float64
|
|
3095
|
-
readBigInt64, // CASE 122: bigint
|
|
3096
|
-
decoder => false, // CASE 121: boolean (false)
|
|
3097
|
-
decoder => true, // CASE 120: boolean (true)
|
|
3098
|
-
readVarString, // CASE 119: string
|
|
3099
|
-
decoder => { // CASE 118: object<string,any>
|
|
3100
|
-
const len = readVarUint(decoder);
|
|
3101
|
-
/**
|
|
3102
|
-
* @type {Object<string,any>}
|
|
3103
|
-
*/
|
|
3104
|
-
const obj = {};
|
|
3105
|
-
for (let i = 0; i < len; i++) {
|
|
3106
|
-
const key = readVarString(decoder);
|
|
3107
|
-
obj[key] = readAny(decoder);
|
|
3108
|
-
}
|
|
3109
|
-
return obj
|
|
3110
|
-
},
|
|
3111
|
-
decoder => { // CASE 117: array<any>
|
|
3112
|
-
const len = readVarUint(decoder);
|
|
3113
|
-
const arr = [];
|
|
3114
|
-
for (let i = 0; i < len; i++) {
|
|
3115
|
-
arr.push(readAny(decoder));
|
|
3116
|
-
}
|
|
3117
|
-
return arr
|
|
3118
|
-
},
|
|
3119
|
-
readVarUint8Array // CASE 116: Uint8Array
|
|
3120
|
-
];
|
|
3121
|
-
|
|
3122
|
-
/**
|
|
3123
|
-
* @param {Decoder} decoder
|
|
3124
|
-
*/
|
|
3125
|
-
const readAny = decoder => readAnyLookupTable[127 - readUint8(decoder)](decoder);
|
|
3126
|
-
|
|
3127
823
|
function decodeYMessage(a) {
|
|
3128
824
|
const decoder = new Decoder(a);
|
|
3129
825
|
const type = readVarString(decoder);
|
|
@@ -4699,13 +2395,6 @@ function listUpdatesSince(yTable, sinceIncluding) {
|
|
|
4699
2395
|
.toArray();
|
|
4700
2396
|
}
|
|
4701
2397
|
|
|
4702
|
-
function $Y(db) {
|
|
4703
|
-
const $Y = db.dx._options.Y;
|
|
4704
|
-
if (!$Y)
|
|
4705
|
-
throw new Error('Y library not supplied to Dexie constructor');
|
|
4706
|
-
return $Y;
|
|
4707
|
-
}
|
|
4708
|
-
|
|
4709
2398
|
/** Queries the local database for YMessages to send to server.
|
|
4710
2399
|
*
|
|
4711
2400
|
* There are 2 messages that this function can provide:
|
|
@@ -4729,7 +2418,6 @@ function listYClientMessagesAndStateVector(db, tablesToSync) {
|
|
|
4729
2418
|
for (const table of tablesToSync) {
|
|
4730
2419
|
if (table.schema.yProps) {
|
|
4731
2420
|
for (const yProp of table.schema.yProps) {
|
|
4732
|
-
const Y = $Y(db); // This is how we retrieve the user-provided Y library
|
|
4733
2421
|
const yTable = db.table(yProp.updatesTable); // the updates-table for this combo of table+propName
|
|
4734
2422
|
const syncState = (yield yTable.get(DEXIE_CLOUD_SYNCER_ID));
|
|
4735
2423
|
// unsentFrom = the `i` value of updates that aren't yet sent to server (or at least not acked by the server yet)
|
|
@@ -4889,7 +2577,7 @@ function applyYServerMessages(yMessages, db) {
|
|
|
4889
2577
|
case 'in-sync': {
|
|
4890
2578
|
const doc = DexieYProvider.getDocCache(db.dx).find(m.table, m.k, m.prop);
|
|
4891
2579
|
if (doc && !doc.isSynced) {
|
|
4892
|
-
doc.emit('sync', [true]);
|
|
2580
|
+
doc.emit('sync', [true, doc]);
|
|
4893
2581
|
}
|
|
4894
2582
|
break;
|
|
4895
2583
|
}
|
|
@@ -5761,7 +3449,7 @@ class AuthPersistedContext {
|
|
|
5761
3449
|
|
|
5762
3450
|
function waitUntil(o, // Works with Dexie's liveQuery observables if we'd need that
|
|
5763
3451
|
predicate) {
|
|
5764
|
-
return firstValueFrom(from
|
|
3452
|
+
return firstValueFrom(from(o).pipe(filter$1(predicate)));
|
|
5765
3453
|
}
|
|
5766
3454
|
|
|
5767
3455
|
function logout(db) {
|
|
@@ -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;
|
|
@@ -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;
|
|
@@ -8284,7 +5974,7 @@ function dexieCloud(dexie) {
|
|
|
8284
5974
|
const syncComplete = new Subject();
|
|
8285
5975
|
dexie.cloud = {
|
|
8286
5976
|
// @ts-ignore
|
|
8287
|
-
version: "4.
|
|
5977
|
+
version: "4.2.0-alpha.3",
|
|
8288
5978
|
options: Object.assign({}, DEFAULT_OPTIONS),
|
|
8289
5979
|
schema: null,
|
|
8290
5980
|
get currentUserId() {
|
|
@@ -8354,7 +6044,7 @@ function dexieCloud(dexie) {
|
|
|
8354
6044
|
triggerSync(db, purpose);
|
|
8355
6045
|
if (wait) {
|
|
8356
6046
|
console.debug('db.cloud.login() is waiting for sync completion...');
|
|
8357
|
-
yield firstValueFrom(from
|
|
6047
|
+
yield firstValueFrom(from(liveQuery(() => __awaiter(this, void 0, void 0, function* () {
|
|
8358
6048
|
const syncNeeded = yield isSyncNeeded(db);
|
|
8359
6049
|
const newSyncState = yield db.getPersistedSyncState();
|
|
8360
6050
|
if ((newSyncState === null || newSyncState === void 0 ? void 0 : newSyncState.timestamp) !== (syncState === null || syncState === void 0 ? void 0 : syncState.timestamp) &&
|
|
@@ -8505,10 +6195,9 @@ function dexieCloud(dexie) {
|
|
|
8505
6195
|
db.cloud.persistedSyncState.pipe(skip(1), take(1)),
|
|
8506
6196
|
]));
|
|
8507
6197
|
const yHandler = createYHandler(db);
|
|
8508
|
-
|
|
6198
|
+
DexieYProvider.on.new.subscribe(yHandler);
|
|
8509
6199
|
db.dx.once('close', () => {
|
|
8510
|
-
|
|
8511
|
-
(_a = db.dx.on.y) === null || _a === void 0 ? void 0 : _a.unsubscribe(yHandler);
|
|
6200
|
+
DexieYProvider.on.new.unsubscribe(yHandler);
|
|
8512
6201
|
});
|
|
8513
6202
|
}
|
|
8514
6203
|
// HERE: If requireAuth, do athentication now.
|
|
@@ -8602,7 +6291,7 @@ function dexieCloud(dexie) {
|
|
|
8602
6291
|
}
|
|
8603
6292
|
}
|
|
8604
6293
|
// @ts-ignore
|
|
8605
|
-
dexieCloud.version = "4.
|
|
6294
|
+
dexieCloud.version = "4.2.0-alpha.3";
|
|
8606
6295
|
Dexie.Cloud = dexieCloud;
|
|
8607
6296
|
|
|
8608
6297
|
// In case the SW lives for a while, let it reuse already opened connections:
|