@livequery/core 2.0.86 → 2.0.89
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/LivequeryCollection.d.ts +9 -12
- package/dist/LivequeryCollection.d.ts.map +1 -1
- package/dist/LivequeryCore.d.ts +13 -9
- package/dist/LivequeryCore.d.ts.map +1 -1
- package/dist/LivequeryDocument.d.ts +2 -2
- package/dist/LivequeryTransporter.d.ts +1 -0
- package/dist/LivequeryTransporter.d.ts.map +1 -1
- package/dist/helpers/filterDocs.d.ts +1 -1
- package/dist/helpers/filterDocs.d.ts.map +1 -1
- package/dist/helpers/whenCompleted.d.ts +3 -0
- package/dist/helpers/whenCompleted.d.ts.map +1 -0
- package/dist/index.js +608 -324
- package/dist/index.js.map +26 -17
- package/dist/types.d.ts +2 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1242,45 +1242,56 @@ function process(asyncIterable, subscriber) {
|
|
|
1242
1242
|
});
|
|
1243
1243
|
}
|
|
1244
1244
|
|
|
1245
|
-
// node_modules/rxjs/dist/esm5/internal/
|
|
1246
|
-
function
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
}
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1245
|
+
// node_modules/rxjs/dist/esm5/internal/observable/defer.js
|
|
1246
|
+
function defer(observableFactory) {
|
|
1247
|
+
return new Observable(function(subscriber) {
|
|
1248
|
+
innerFrom(observableFactory()).subscribe(subscriber);
|
|
1249
|
+
});
|
|
1250
|
+
}
|
|
1251
|
+
// node_modules/rxjs/dist/esm5/internal/util/argsArgArrayOrObject.js
|
|
1252
|
+
var isArray = Array.isArray;
|
|
1253
|
+
var getPrototypeOf = Object.getPrototypeOf;
|
|
1254
|
+
var objectProto = Object.prototype;
|
|
1255
|
+
var getKeys = Object.keys;
|
|
1256
|
+
function argsArgArrayOrObject(args) {
|
|
1257
|
+
if (args.length === 1) {
|
|
1258
|
+
var first_1 = args[0];
|
|
1259
|
+
if (isArray(first_1)) {
|
|
1260
|
+
return { args: first_1, keys: null };
|
|
1261
|
+
}
|
|
1262
|
+
if (isPOJO(first_1)) {
|
|
1263
|
+
var keys = getKeys(first_1);
|
|
1264
|
+
return {
|
|
1265
|
+
args: keys.map(function(key) {
|
|
1266
|
+
return first_1[key];
|
|
1267
|
+
}),
|
|
1268
|
+
keys
|
|
1269
|
+
};
|
|
1259
1270
|
}
|
|
1260
|
-
}, delay);
|
|
1261
|
-
parentSubscription.add(scheduleSubscription);
|
|
1262
|
-
if (!repeat) {
|
|
1263
|
-
return scheduleSubscription;
|
|
1264
1271
|
}
|
|
1272
|
+
return { args, keys: null };
|
|
1273
|
+
}
|
|
1274
|
+
function isPOJO(obj) {
|
|
1275
|
+
return obj && typeof obj === "object" && getPrototypeOf(obj) === objectProto;
|
|
1265
1276
|
}
|
|
1266
1277
|
|
|
1267
|
-
// node_modules/rxjs/dist/esm5/internal/util/
|
|
1268
|
-
function
|
|
1269
|
-
return isFunction(
|
|
1278
|
+
// node_modules/rxjs/dist/esm5/internal/util/isScheduler.js
|
|
1279
|
+
function isScheduler(value) {
|
|
1280
|
+
return value && isFunction(value.schedule);
|
|
1270
1281
|
}
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1282
|
+
|
|
1283
|
+
// node_modules/rxjs/dist/esm5/internal/util/args.js
|
|
1284
|
+
function last(arr) {
|
|
1285
|
+
return arr[arr.length - 1];
|
|
1286
|
+
}
|
|
1287
|
+
function popResultSelector(args) {
|
|
1288
|
+
return isFunction(last(args)) ? args.pop() : undefined;
|
|
1289
|
+
}
|
|
1290
|
+
function popScheduler(args) {
|
|
1291
|
+
return isScheduler(last(args)) ? args.pop() : undefined;
|
|
1292
|
+
}
|
|
1293
|
+
function popNumber(args, defaultValue) {
|
|
1294
|
+
return typeof last(args) === "number" ? args.pop() : defaultValue;
|
|
1284
1295
|
}
|
|
1285
1296
|
|
|
1286
1297
|
// node_modules/rxjs/dist/esm5/internal/operators/OperatorSubscriber.js
|
|
@@ -1331,6 +1342,117 @@ var OperatorSubscriber = function(_super) {
|
|
|
1331
1342
|
return OperatorSubscriber2;
|
|
1332
1343
|
}(Subscriber);
|
|
1333
1344
|
|
|
1345
|
+
// node_modules/rxjs/dist/esm5/internal/util/lift.js
|
|
1346
|
+
function hasLift(source) {
|
|
1347
|
+
return isFunction(source === null || source === undefined ? undefined : source.lift);
|
|
1348
|
+
}
|
|
1349
|
+
function operate(init) {
|
|
1350
|
+
return function(source) {
|
|
1351
|
+
if (hasLift(source)) {
|
|
1352
|
+
return source.lift(function(liftedSource) {
|
|
1353
|
+
try {
|
|
1354
|
+
return init(liftedSource, this);
|
|
1355
|
+
} catch (err) {
|
|
1356
|
+
this.error(err);
|
|
1357
|
+
}
|
|
1358
|
+
});
|
|
1359
|
+
}
|
|
1360
|
+
throw new TypeError("Unable to lift unknown Observable type");
|
|
1361
|
+
};
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
// node_modules/rxjs/dist/esm5/internal/operators/map.js
|
|
1365
|
+
function map(project, thisArg) {
|
|
1366
|
+
return operate(function(source, subscriber) {
|
|
1367
|
+
var index = 0;
|
|
1368
|
+
source.subscribe(createOperatorSubscriber(subscriber, function(value) {
|
|
1369
|
+
subscriber.next(project.call(thisArg, value, index++));
|
|
1370
|
+
}));
|
|
1371
|
+
});
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
// node_modules/rxjs/dist/esm5/internal/util/mapOneOrManyArgs.js
|
|
1375
|
+
var isArray2 = Array.isArray;
|
|
1376
|
+
function callOrApply(fn, args) {
|
|
1377
|
+
return isArray2(args) ? fn.apply(undefined, __spreadArray([], __read(args))) : fn(args);
|
|
1378
|
+
}
|
|
1379
|
+
function mapOneOrManyArgs(fn) {
|
|
1380
|
+
return map(function(args) {
|
|
1381
|
+
return callOrApply(fn, args);
|
|
1382
|
+
});
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
// node_modules/rxjs/dist/esm5/internal/util/createObject.js
|
|
1386
|
+
function createObject(keys, values) {
|
|
1387
|
+
return keys.reduce(function(result, key, i) {
|
|
1388
|
+
return result[key] = values[i], result;
|
|
1389
|
+
}, {});
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
// node_modules/rxjs/dist/esm5/internal/observable/forkJoin.js
|
|
1393
|
+
function forkJoin() {
|
|
1394
|
+
var args = [];
|
|
1395
|
+
for (var _i = 0;_i < arguments.length; _i++) {
|
|
1396
|
+
args[_i] = arguments[_i];
|
|
1397
|
+
}
|
|
1398
|
+
var resultSelector = popResultSelector(args);
|
|
1399
|
+
var _a = argsArgArrayOrObject(args), sources = _a.args, keys = _a.keys;
|
|
1400
|
+
var result = new Observable(function(subscriber) {
|
|
1401
|
+
var length = sources.length;
|
|
1402
|
+
if (!length) {
|
|
1403
|
+
subscriber.complete();
|
|
1404
|
+
return;
|
|
1405
|
+
}
|
|
1406
|
+
var values = new Array(length);
|
|
1407
|
+
var remainingCompletions = length;
|
|
1408
|
+
var remainingEmissions = length;
|
|
1409
|
+
var _loop_1 = function(sourceIndex2) {
|
|
1410
|
+
var hasValue = false;
|
|
1411
|
+
innerFrom(sources[sourceIndex2]).subscribe(createOperatorSubscriber(subscriber, function(value) {
|
|
1412
|
+
if (!hasValue) {
|
|
1413
|
+
hasValue = true;
|
|
1414
|
+
remainingEmissions--;
|
|
1415
|
+
}
|
|
1416
|
+
values[sourceIndex2] = value;
|
|
1417
|
+
}, function() {
|
|
1418
|
+
return remainingCompletions--;
|
|
1419
|
+
}, undefined, function() {
|
|
1420
|
+
if (!remainingCompletions || !hasValue) {
|
|
1421
|
+
if (!remainingEmissions) {
|
|
1422
|
+
subscriber.next(keys ? createObject(keys, values) : values);
|
|
1423
|
+
}
|
|
1424
|
+
subscriber.complete();
|
|
1425
|
+
}
|
|
1426
|
+
}));
|
|
1427
|
+
};
|
|
1428
|
+
for (var sourceIndex = 0;sourceIndex < length; sourceIndex++) {
|
|
1429
|
+
_loop_1(sourceIndex);
|
|
1430
|
+
}
|
|
1431
|
+
});
|
|
1432
|
+
return resultSelector ? result.pipe(mapOneOrManyArgs(resultSelector)) : result;
|
|
1433
|
+
}
|
|
1434
|
+
// node_modules/rxjs/dist/esm5/internal/util/executeSchedule.js
|
|
1435
|
+
function executeSchedule(parentSubscription, scheduler, work, delay, repeat) {
|
|
1436
|
+
if (delay === undefined) {
|
|
1437
|
+
delay = 0;
|
|
1438
|
+
}
|
|
1439
|
+
if (repeat === undefined) {
|
|
1440
|
+
repeat = false;
|
|
1441
|
+
}
|
|
1442
|
+
var scheduleSubscription = scheduler.schedule(function() {
|
|
1443
|
+
work();
|
|
1444
|
+
if (repeat) {
|
|
1445
|
+
parentSubscription.add(this.schedule(null, delay));
|
|
1446
|
+
} else {
|
|
1447
|
+
this.unsubscribe();
|
|
1448
|
+
}
|
|
1449
|
+
}, delay);
|
|
1450
|
+
parentSubscription.add(scheduleSubscription);
|
|
1451
|
+
if (!repeat) {
|
|
1452
|
+
return scheduleSubscription;
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1334
1456
|
// node_modules/rxjs/dist/esm5/internal/operators/observeOn.js
|
|
1335
1457
|
function observeOn(scheduler, delay) {
|
|
1336
1458
|
if (delay === undefined) {
|
|
@@ -1476,16 +1598,6 @@ function scheduled(input, scheduler) {
|
|
|
1476
1598
|
function from(input, scheduler) {
|
|
1477
1599
|
return scheduler ? scheduled(input, scheduler) : innerFrom(input);
|
|
1478
1600
|
}
|
|
1479
|
-
// node_modules/rxjs/dist/esm5/internal/operators/map.js
|
|
1480
|
-
function map(project, thisArg) {
|
|
1481
|
-
return operate(function(source, subscriber) {
|
|
1482
|
-
var index = 0;
|
|
1483
|
-
source.subscribe(createOperatorSubscriber(subscriber, function(value) {
|
|
1484
|
-
subscriber.next(project.call(thisArg, value, index++));
|
|
1485
|
-
}));
|
|
1486
|
-
});
|
|
1487
|
-
}
|
|
1488
|
-
|
|
1489
1601
|
// node_modules/rxjs/dist/esm5/internal/operators/mergeInternals.js
|
|
1490
1602
|
function mergeInternals(source, subscriber, project, concurrent, onBeforeNext, expand, innerSubScheduler, additionalFinalizer) {
|
|
1491
1603
|
var buffer = [];
|
|
@@ -1578,22 +1690,6 @@ var EMPTY = new Observable(function(subscriber) {
|
|
|
1578
1690
|
return subscriber.complete();
|
|
1579
1691
|
});
|
|
1580
1692
|
|
|
1581
|
-
// node_modules/rxjs/dist/esm5/internal/util/isScheduler.js
|
|
1582
|
-
function isScheduler(value) {
|
|
1583
|
-
return value && isFunction(value.schedule);
|
|
1584
|
-
}
|
|
1585
|
-
|
|
1586
|
-
// node_modules/rxjs/dist/esm5/internal/util/args.js
|
|
1587
|
-
function last(arr) {
|
|
1588
|
-
return arr[arr.length - 1];
|
|
1589
|
-
}
|
|
1590
|
-
function popScheduler(args) {
|
|
1591
|
-
return isScheduler(last(args)) ? args.pop() : undefined;
|
|
1592
|
-
}
|
|
1593
|
-
function popNumber(args, defaultValue) {
|
|
1594
|
-
return typeof last(args) === "number" ? args.pop() : defaultValue;
|
|
1595
|
-
}
|
|
1596
|
-
|
|
1597
1693
|
// node_modules/rxjs/dist/esm5/internal/observable/merge.js
|
|
1598
1694
|
function merge() {
|
|
1599
1695
|
var args = [];
|
|
@@ -1852,60 +1948,14 @@ function debounceTime(dueTime, scheduler) {
|
|
|
1852
1948
|
}));
|
|
1853
1949
|
});
|
|
1854
1950
|
}
|
|
1855
|
-
// node_modules/rxjs/dist/esm5/internal/operators/
|
|
1856
|
-
function
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
// node_modules/rxjs/dist/esm5/internal/observable/concat.js
|
|
1861
|
-
function concat() {
|
|
1862
|
-
var args = [];
|
|
1863
|
-
for (var _i = 0;_i < arguments.length; _i++) {
|
|
1864
|
-
args[_i] = arguments[_i];
|
|
1951
|
+
// node_modules/rxjs/dist/esm5/internal/operators/expand.js
|
|
1952
|
+
function expand(project, concurrent, scheduler) {
|
|
1953
|
+
if (concurrent === undefined) {
|
|
1954
|
+
concurrent = Infinity;
|
|
1865
1955
|
}
|
|
1866
|
-
|
|
1867
|
-
}
|
|
1868
|
-
|
|
1869
|
-
// node_modules/rxjs/dist/esm5/internal/operators/take.js
|
|
1870
|
-
function take(count) {
|
|
1871
|
-
return count <= 0 ? function() {
|
|
1872
|
-
return EMPTY;
|
|
1873
|
-
} : operate(function(source, subscriber) {
|
|
1874
|
-
var seen = 0;
|
|
1875
|
-
source.subscribe(createOperatorSubscriber(subscriber, function(value) {
|
|
1876
|
-
if (++seen <= count) {
|
|
1877
|
-
subscriber.next(value);
|
|
1878
|
-
if (count <= seen) {
|
|
1879
|
-
subscriber.complete();
|
|
1880
|
-
}
|
|
1881
|
-
}
|
|
1882
|
-
}));
|
|
1883
|
-
});
|
|
1884
|
-
}
|
|
1885
|
-
|
|
1886
|
-
// node_modules/rxjs/dist/esm5/internal/operators/ignoreElements.js
|
|
1887
|
-
function ignoreElements() {
|
|
1956
|
+
concurrent = (concurrent || 0) < 1 ? Infinity : concurrent;
|
|
1888
1957
|
return operate(function(source, subscriber) {
|
|
1889
|
-
source
|
|
1890
|
-
});
|
|
1891
|
-
}
|
|
1892
|
-
|
|
1893
|
-
// node_modules/rxjs/dist/esm5/internal/operators/mapTo.js
|
|
1894
|
-
function mapTo(value) {
|
|
1895
|
-
return map(function() {
|
|
1896
|
-
return value;
|
|
1897
|
-
});
|
|
1898
|
-
}
|
|
1899
|
-
|
|
1900
|
-
// node_modules/rxjs/dist/esm5/internal/operators/delayWhen.js
|
|
1901
|
-
function delayWhen(delayDurationSelector, subscriptionDelay) {
|
|
1902
|
-
if (subscriptionDelay) {
|
|
1903
|
-
return function(source) {
|
|
1904
|
-
return concat(subscriptionDelay.pipe(take(1), ignoreElements()), source.pipe(delayWhen(delayDurationSelector)));
|
|
1905
|
-
};
|
|
1906
|
-
}
|
|
1907
|
-
return mergeMap(function(value, index) {
|
|
1908
|
-
return innerFrom(delayDurationSelector(value, index)).pipe(take(1), mapTo(value));
|
|
1958
|
+
return mergeInternals(source, subscriber, project, concurrent, undefined, true, scheduler);
|
|
1909
1959
|
});
|
|
1910
1960
|
}
|
|
1911
1961
|
// node_modules/rxjs/dist/esm5/internal/operators/filter.js
|
|
@@ -1927,6 +1977,157 @@ function finalize(callback) {
|
|
|
1927
1977
|
}
|
|
1928
1978
|
});
|
|
1929
1979
|
}
|
|
1980
|
+
// node_modules/rxjs/dist/esm5/internal/operators/groupBy.js
|
|
1981
|
+
function groupBy(keySelector, elementOrOptions, duration, connector) {
|
|
1982
|
+
return operate(function(source, subscriber) {
|
|
1983
|
+
var element;
|
|
1984
|
+
if (!elementOrOptions || typeof elementOrOptions === "function") {
|
|
1985
|
+
element = elementOrOptions;
|
|
1986
|
+
} else {
|
|
1987
|
+
duration = elementOrOptions.duration, element = elementOrOptions.element, connector = elementOrOptions.connector;
|
|
1988
|
+
}
|
|
1989
|
+
var groups = new Map;
|
|
1990
|
+
var notify = function(cb) {
|
|
1991
|
+
groups.forEach(cb);
|
|
1992
|
+
cb(subscriber);
|
|
1993
|
+
};
|
|
1994
|
+
var handleError = function(err) {
|
|
1995
|
+
return notify(function(consumer) {
|
|
1996
|
+
return consumer.error(err);
|
|
1997
|
+
});
|
|
1998
|
+
};
|
|
1999
|
+
var activeGroups = 0;
|
|
2000
|
+
var teardownAttempted = false;
|
|
2001
|
+
var groupBySourceSubscriber = new OperatorSubscriber(subscriber, function(value) {
|
|
2002
|
+
try {
|
|
2003
|
+
var key_1 = keySelector(value);
|
|
2004
|
+
var group_1 = groups.get(key_1);
|
|
2005
|
+
if (!group_1) {
|
|
2006
|
+
groups.set(key_1, group_1 = connector ? connector() : new Subject);
|
|
2007
|
+
var grouped = createGroupedObservable(key_1, group_1);
|
|
2008
|
+
subscriber.next(grouped);
|
|
2009
|
+
if (duration) {
|
|
2010
|
+
var durationSubscriber_1 = createOperatorSubscriber(group_1, function() {
|
|
2011
|
+
group_1.complete();
|
|
2012
|
+
durationSubscriber_1 === null || durationSubscriber_1 === undefined || durationSubscriber_1.unsubscribe();
|
|
2013
|
+
}, undefined, undefined, function() {
|
|
2014
|
+
return groups.delete(key_1);
|
|
2015
|
+
});
|
|
2016
|
+
groupBySourceSubscriber.add(innerFrom(duration(grouped)).subscribe(durationSubscriber_1));
|
|
2017
|
+
}
|
|
2018
|
+
}
|
|
2019
|
+
group_1.next(element ? element(value) : value);
|
|
2020
|
+
} catch (err) {
|
|
2021
|
+
handleError(err);
|
|
2022
|
+
}
|
|
2023
|
+
}, function() {
|
|
2024
|
+
return notify(function(consumer) {
|
|
2025
|
+
return consumer.complete();
|
|
2026
|
+
});
|
|
2027
|
+
}, handleError, function() {
|
|
2028
|
+
return groups.clear();
|
|
2029
|
+
}, function() {
|
|
2030
|
+
teardownAttempted = true;
|
|
2031
|
+
return activeGroups === 0;
|
|
2032
|
+
});
|
|
2033
|
+
source.subscribe(groupBySourceSubscriber);
|
|
2034
|
+
function createGroupedObservable(key, groupSubject) {
|
|
2035
|
+
var result = new Observable(function(groupSubscriber) {
|
|
2036
|
+
activeGroups++;
|
|
2037
|
+
var innerSub = groupSubject.subscribe(groupSubscriber);
|
|
2038
|
+
return function() {
|
|
2039
|
+
innerSub.unsubscribe();
|
|
2040
|
+
--activeGroups === 0 && teardownAttempted && groupBySourceSubscriber.unsubscribe();
|
|
2041
|
+
};
|
|
2042
|
+
});
|
|
2043
|
+
result.key = key;
|
|
2044
|
+
return result;
|
|
2045
|
+
}
|
|
2046
|
+
});
|
|
2047
|
+
}
|
|
2048
|
+
// node_modules/rxjs/dist/esm5/internal/observable/throwError.js
|
|
2049
|
+
function throwError(errorOrErrorFactory, scheduler) {
|
|
2050
|
+
var errorFactory = isFunction(errorOrErrorFactory) ? errorOrErrorFactory : function() {
|
|
2051
|
+
return errorOrErrorFactory;
|
|
2052
|
+
};
|
|
2053
|
+
var init = function(subscriber) {
|
|
2054
|
+
return subscriber.error(errorFactory());
|
|
2055
|
+
};
|
|
2056
|
+
return new Observable(scheduler ? function(subscriber) {
|
|
2057
|
+
return scheduler.schedule(init, 0, subscriber);
|
|
2058
|
+
} : init);
|
|
2059
|
+
}
|
|
2060
|
+
|
|
2061
|
+
// node_modules/rxjs/dist/esm5/internal/Notification.js
|
|
2062
|
+
var NotificationKind;
|
|
2063
|
+
(function(NotificationKind2) {
|
|
2064
|
+
NotificationKind2["NEXT"] = "N";
|
|
2065
|
+
NotificationKind2["ERROR"] = "E";
|
|
2066
|
+
NotificationKind2["COMPLETE"] = "C";
|
|
2067
|
+
})(NotificationKind || (NotificationKind = {}));
|
|
2068
|
+
var Notification = function() {
|
|
2069
|
+
function Notification2(kind, value, error) {
|
|
2070
|
+
this.kind = kind;
|
|
2071
|
+
this.value = value;
|
|
2072
|
+
this.error = error;
|
|
2073
|
+
this.hasValue = kind === "N";
|
|
2074
|
+
}
|
|
2075
|
+
Notification2.prototype.observe = function(observer) {
|
|
2076
|
+
return observeNotification(this, observer);
|
|
2077
|
+
};
|
|
2078
|
+
Notification2.prototype.do = function(nextHandler, errorHandler, completeHandler) {
|
|
2079
|
+
var _a = this, kind = _a.kind, value = _a.value, error = _a.error;
|
|
2080
|
+
return kind === "N" ? nextHandler === null || nextHandler === undefined ? undefined : nextHandler(value) : kind === "E" ? errorHandler === null || errorHandler === undefined ? undefined : errorHandler(error) : completeHandler === null || completeHandler === undefined ? undefined : completeHandler();
|
|
2081
|
+
};
|
|
2082
|
+
Notification2.prototype.accept = function(nextOrObserver, error, complete) {
|
|
2083
|
+
var _a;
|
|
2084
|
+
return isFunction((_a = nextOrObserver) === null || _a === undefined ? undefined : _a.next) ? this.observe(nextOrObserver) : this.do(nextOrObserver, error, complete);
|
|
2085
|
+
};
|
|
2086
|
+
Notification2.prototype.toObservable = function() {
|
|
2087
|
+
var _a = this, kind = _a.kind, value = _a.value, error = _a.error;
|
|
2088
|
+
var result = kind === "N" ? of(value) : kind === "E" ? throwError(function() {
|
|
2089
|
+
return error;
|
|
2090
|
+
}) : kind === "C" ? EMPTY : 0;
|
|
2091
|
+
if (!result) {
|
|
2092
|
+
throw new TypeError("Unexpected notification kind " + kind);
|
|
2093
|
+
}
|
|
2094
|
+
return result;
|
|
2095
|
+
};
|
|
2096
|
+
Notification2.createNext = function(value) {
|
|
2097
|
+
return new Notification2("N", value);
|
|
2098
|
+
};
|
|
2099
|
+
Notification2.createError = function(err) {
|
|
2100
|
+
return new Notification2("E", undefined, err);
|
|
2101
|
+
};
|
|
2102
|
+
Notification2.createComplete = function() {
|
|
2103
|
+
return Notification2.completeNotification;
|
|
2104
|
+
};
|
|
2105
|
+
Notification2.completeNotification = new Notification2("C");
|
|
2106
|
+
return Notification2;
|
|
2107
|
+
}();
|
|
2108
|
+
function observeNotification(notification, observer) {
|
|
2109
|
+
var _a, _b, _c;
|
|
2110
|
+
var _d = notification, kind = _d.kind, value = _d.value, error = _d.error;
|
|
2111
|
+
if (typeof kind !== "string") {
|
|
2112
|
+
throw new TypeError('Invalid notification, missing "kind"');
|
|
2113
|
+
}
|
|
2114
|
+
kind === "N" ? (_a = observer.next) === null || _a === undefined || _a.call(observer, value) : kind === "E" ? (_b = observer.error) === null || _b === undefined || _b.call(observer, error) : (_c = observer.complete) === null || _c === undefined || _c.call(observer);
|
|
2115
|
+
}
|
|
2116
|
+
|
|
2117
|
+
// node_modules/rxjs/dist/esm5/internal/operators/materialize.js
|
|
2118
|
+
function materialize() {
|
|
2119
|
+
return operate(function(source, subscriber) {
|
|
2120
|
+
source.subscribe(createOperatorSubscriber(subscriber, function(value) {
|
|
2121
|
+
subscriber.next(Notification.createNext(value));
|
|
2122
|
+
}, function() {
|
|
2123
|
+
subscriber.next(Notification.createComplete());
|
|
2124
|
+
subscriber.complete();
|
|
2125
|
+
}, function(err) {
|
|
2126
|
+
subscriber.next(Notification.createError(err));
|
|
2127
|
+
subscriber.complete();
|
|
2128
|
+
}));
|
|
2129
|
+
});
|
|
2130
|
+
}
|
|
1930
2131
|
// node_modules/rxjs/dist/esm5/internal/operators/pairwise.js
|
|
1931
2132
|
function pairwise() {
|
|
1932
2133
|
return operate(function(source, subscriber) {
|
|
@@ -1940,6 +2141,27 @@ function pairwise() {
|
|
|
1940
2141
|
}));
|
|
1941
2142
|
});
|
|
1942
2143
|
}
|
|
2144
|
+
// node_modules/rxjs/dist/esm5/internal/operators/scanInternals.js
|
|
2145
|
+
function scanInternals(accumulator, seed, hasSeed, emitOnNext, emitBeforeComplete) {
|
|
2146
|
+
return function(source, subscriber) {
|
|
2147
|
+
var hasState = hasSeed;
|
|
2148
|
+
var state = seed;
|
|
2149
|
+
var index = 0;
|
|
2150
|
+
source.subscribe(createOperatorSubscriber(subscriber, function(value) {
|
|
2151
|
+
var i = index++;
|
|
2152
|
+
state = hasState ? accumulator(state, value, i) : (hasState = true, value);
|
|
2153
|
+
emitOnNext && subscriber.next(state);
|
|
2154
|
+
}, emitBeforeComplete && function() {
|
|
2155
|
+
hasState && subscriber.next(state);
|
|
2156
|
+
subscriber.complete();
|
|
2157
|
+
}));
|
|
2158
|
+
};
|
|
2159
|
+
}
|
|
2160
|
+
|
|
2161
|
+
// node_modules/rxjs/dist/esm5/internal/operators/scan.js
|
|
2162
|
+
function scan(accumulator, seed) {
|
|
2163
|
+
return operate(scanInternals(accumulator, seed, arguments.length >= 2, true));
|
|
2164
|
+
}
|
|
1943
2165
|
// node_modules/rxjs/dist/esm5/internal/ReplaySubject.js
|
|
1944
2166
|
var ReplaySubject = function(_super) {
|
|
1945
2167
|
__extends(ReplaySubject2, _super);
|
|
@@ -2131,6 +2353,29 @@ function switchMap(project, resultSelector) {
|
|
|
2131
2353
|
}));
|
|
2132
2354
|
});
|
|
2133
2355
|
}
|
|
2356
|
+
// node_modules/rxjs/dist/esm5/internal/operators/takeUntil.js
|
|
2357
|
+
function takeUntil(notifier) {
|
|
2358
|
+
return operate(function(source, subscriber) {
|
|
2359
|
+
innerFrom(notifier).subscribe(createOperatorSubscriber(subscriber, function() {
|
|
2360
|
+
return subscriber.complete();
|
|
2361
|
+
}, noop));
|
|
2362
|
+
!subscriber.closed && source.subscribe(subscriber);
|
|
2363
|
+
});
|
|
2364
|
+
}
|
|
2365
|
+
// node_modules/rxjs/dist/esm5/internal/operators/takeWhile.js
|
|
2366
|
+
function takeWhile(predicate, inclusive) {
|
|
2367
|
+
if (inclusive === undefined) {
|
|
2368
|
+
inclusive = false;
|
|
2369
|
+
}
|
|
2370
|
+
return operate(function(source, subscriber) {
|
|
2371
|
+
var index = 0;
|
|
2372
|
+
source.subscribe(createOperatorSubscriber(subscriber, function(value) {
|
|
2373
|
+
var result = predicate(value, index++);
|
|
2374
|
+
(result || inclusive) && subscriber.next(value);
|
|
2375
|
+
!result && subscriber.complete();
|
|
2376
|
+
}));
|
|
2377
|
+
});
|
|
2378
|
+
}
|
|
2134
2379
|
// node_modules/rxjs/dist/esm5/internal/operators/tap.js
|
|
2135
2380
|
function tap(observerOrNext, error, complete) {
|
|
2136
2381
|
var tapObserver = isFunction(observerOrNext) || error || complete ? { next: observerOrNext, error, complete } : observerOrNext;
|
|
@@ -2185,6 +2430,7 @@ class LivequeryDocument extends BehaviorSubject {
|
|
|
2185
2430
|
|
|
2186
2431
|
// src/LivequeryCollection.ts
|
|
2187
2432
|
class LivequeryCollection {
|
|
2433
|
+
options;
|
|
2188
2434
|
id = (Math.random() * 1000000000000000000).toString(36);
|
|
2189
2435
|
#keys = new Map;
|
|
2190
2436
|
#indexes;
|
|
@@ -2192,7 +2438,6 @@ class LivequeryCollection {
|
|
|
2192
2438
|
#filters = new Subject;
|
|
2193
2439
|
ref;
|
|
2194
2440
|
collection_ref;
|
|
2195
|
-
#items = [];
|
|
2196
2441
|
items;
|
|
2197
2442
|
summary;
|
|
2198
2443
|
metadata;
|
|
@@ -2200,8 +2445,8 @@ class LivequeryCollection {
|
|
|
2200
2445
|
filters;
|
|
2201
2446
|
paging;
|
|
2202
2447
|
error;
|
|
2203
|
-
options
|
|
2204
|
-
|
|
2448
|
+
constructor(options = {}) {
|
|
2449
|
+
this.options = options;
|
|
2205
2450
|
this.#indexes = new Map;
|
|
2206
2451
|
this.items = new BehaviorSubject([]);
|
|
2207
2452
|
this.summary = new BehaviorSubject({});
|
|
@@ -2216,8 +2461,9 @@ class LivequeryCollection {
|
|
|
2216
2461
|
this.options = options;
|
|
2217
2462
|
}
|
|
2218
2463
|
}
|
|
2219
|
-
#
|
|
2220
|
-
this
|
|
2464
|
+
#commit(items) {
|
|
2465
|
+
this.items.next(items);
|
|
2466
|
+
this.#indexes = items.reduce((p, c, index) => {
|
|
2221
2467
|
p.set(c.value.id, index);
|
|
2222
2468
|
return p;
|
|
2223
2469
|
}, new Map);
|
|
@@ -2232,20 +2478,16 @@ class LivequeryCollection {
|
|
|
2232
2478
|
this.#core = core;
|
|
2233
2479
|
const timer2 = this.options.lazy !== true && setTimeout(() => this.query(this.filters.value || {}));
|
|
2234
2480
|
this.#subscription?.unsubscribe();
|
|
2235
|
-
this.#subscription = merge(this.options.debounce ? merge(this.#filters.pipe(debounceTime(this.options.debounce), switchMap((filters) => this.query(filters))),
|
|
2236
|
-
this.options.visible = visible;
|
|
2237
|
-
this.items.next(this.options.visible ? this.#items.filter((i) => this.options.visible(i.value)) : this.#items);
|
|
2238
|
-
}))) : EMPTY, core.watch(this.ref, this.id).pipe(finalize(() => {
|
|
2481
|
+
this.#subscription = merge(this.options.debounce ? merge(this.#filters.pipe(debounceTime(this.options.debounce), switchMap((filters) => this.query(filters)))) : EMPTY, core.watch(this.ref, this.id, this.options.mode || "server-first").pipe(finalize(() => {
|
|
2239
2482
|
timer2 && clearTimeout(timer2);
|
|
2240
2483
|
}), tap((event) => {
|
|
2484
|
+
event.loading !== undefined && event.loading !== this.loading.value && this.loading.next(event.loading);
|
|
2241
2485
|
event.summary && this.summary.next(event.summary);
|
|
2242
2486
|
event.metadata && this.metadata.next(event.metadata);
|
|
2243
2487
|
event.paging && this.paging.next(event.paging);
|
|
2244
2488
|
event.error && this.error.next(event.error);
|
|
2245
|
-
if (!event.changes || event.changes.length == 0)
|
|
2246
|
-
event.from == "query" && this.loading.next(null);
|
|
2489
|
+
if (!event.changes || event.changes.length == 0)
|
|
2247
2490
|
return;
|
|
2248
|
-
}
|
|
2249
2491
|
const chaos = event.changes && event.changes.some((change) => {
|
|
2250
2492
|
if (change.type == "added" || change.type == "removed")
|
|
2251
2493
|
return true;
|
|
@@ -2290,7 +2532,7 @@ class LivequeryCollection {
|
|
|
2290
2532
|
const target = index != null && index >= 0 ? p[index] : null;
|
|
2291
2533
|
target && target.next({ ...target.value, ...data });
|
|
2292
2534
|
return p;
|
|
2293
|
-
}, this
|
|
2535
|
+
}, this.items.value);
|
|
2294
2536
|
const new_items = events.added.filter((a) => a.data).reduce((p, c) => {
|
|
2295
2537
|
if (!p.indexes.has(c.id)) {
|
|
2296
2538
|
const doc = new LivequeryDocument(this, { id: c.id, ...c.data });
|
|
@@ -2313,31 +2555,18 @@ class LivequeryCollection {
|
|
|
2313
2555
|
...new_items.list
|
|
2314
2556
|
]);
|
|
2315
2557
|
const items = chaos ? unsort_items.sort(sorter) : unsort_items;
|
|
2316
|
-
|
|
2317
|
-
this.#items = items;
|
|
2318
|
-
this.items.next(this.options.visible ? items.filter((i) => this.options.visible(i.value)) : items);
|
|
2319
|
-
this.#reindex();
|
|
2320
|
-
}
|
|
2321
|
-
event.from == "query" && this.loading.next(null);
|
|
2558
|
+
chaos && this.#commit(items);
|
|
2322
2559
|
event.paging && this.paging.next(event.paging);
|
|
2323
|
-
event.from == "query" && this.loading.next(null);
|
|
2324
2560
|
}))).subscribe();
|
|
2325
2561
|
return this.#subscription;
|
|
2326
2562
|
}
|
|
2327
|
-
#show$ = new Subject;
|
|
2328
|
-
async show(visible) {
|
|
2329
|
-
this.#show$.next(visible);
|
|
2330
|
-
}
|
|
2331
2563
|
async#query(filters, flush) {
|
|
2332
2564
|
if (!this.#core)
|
|
2333
2565
|
return;
|
|
2334
2566
|
if (!this.ref)
|
|
2335
2567
|
return;
|
|
2336
2568
|
this.error.next(null);
|
|
2337
|
-
|
|
2338
|
-
this.#items = [];
|
|
2339
|
-
this.items.next([]);
|
|
2340
|
-
}
|
|
2569
|
+
flush && this.#commit([]);
|
|
2341
2570
|
this.#keys = Object.entries(filters).reduce((p, [k, v]) => {
|
|
2342
2571
|
if (k.endsWith(":sort")) {
|
|
2343
2572
|
const field = k.split(":")[0];
|
|
@@ -2346,23 +2575,16 @@ class LivequeryCollection {
|
|
|
2346
2575
|
return p;
|
|
2347
2576
|
}, new Map);
|
|
2348
2577
|
this.filters.next(filters);
|
|
2349
|
-
const
|
|
2350
|
-
const prev = filters[":before"];
|
|
2351
|
-
const loading = next && prev ? "all" : next ? "next" : prev ? "prev" : "all";
|
|
2352
|
-
this.loading.next(loading);
|
|
2353
|
-
const items = await this.#core.query({
|
|
2578
|
+
const cache = await this.#core.query({
|
|
2354
2579
|
ref: this.ref,
|
|
2355
2580
|
filters,
|
|
2356
2581
|
collection_id: this.id
|
|
2357
2582
|
});
|
|
2358
|
-
if (
|
|
2359
|
-
this.#
|
|
2360
|
-
this.items.next(this.#items);
|
|
2361
|
-
this.loading.next(null);
|
|
2583
|
+
if (cache && cache.documents && flush) {
|
|
2584
|
+
this.#commit(cache.documents.map((i) => new LivequeryDocument(this, i)));
|
|
2362
2585
|
}
|
|
2363
2586
|
}
|
|
2364
2587
|
async query(filters) {
|
|
2365
|
-
this.loading.next("all");
|
|
2366
2588
|
await this.#query(filters, true);
|
|
2367
2589
|
}
|
|
2368
2590
|
async debounceQuery(filters) {
|
|
@@ -2376,7 +2598,6 @@ class LivequeryCollection {
|
|
|
2376
2598
|
...this.filters.value,
|
|
2377
2599
|
":after": next.cursor
|
|
2378
2600
|
};
|
|
2379
|
-
this.loading.next("next");
|
|
2380
2601
|
await this.#query(filters || {}, false);
|
|
2381
2602
|
}
|
|
2382
2603
|
async loadPrev() {
|
|
@@ -2387,7 +2608,6 @@ class LivequeryCollection {
|
|
|
2387
2608
|
...this.filters.value,
|
|
2388
2609
|
":before": prev.cursor
|
|
2389
2610
|
};
|
|
2390
|
-
this.loading.next("prev");
|
|
2391
2611
|
await this.#query(filters || {}, false);
|
|
2392
2612
|
}
|
|
2393
2613
|
async loadAround(cursor) {
|
|
@@ -2396,7 +2616,6 @@ class LivequeryCollection {
|
|
|
2396
2616
|
":after": cursor,
|
|
2397
2617
|
":before": cursor
|
|
2398
2618
|
};
|
|
2399
|
-
this.loading.next("all");
|
|
2400
2619
|
await this.#query(filters || {}, false);
|
|
2401
2620
|
}
|
|
2402
2621
|
add(payload) {
|
|
@@ -2450,6 +2669,92 @@ var tryCatch = async (fn) => {
|
|
|
2450
2669
|
}
|
|
2451
2670
|
};
|
|
2452
2671
|
|
|
2672
|
+
// src/helpers/whenCompleted.ts
|
|
2673
|
+
function whenCompleted(stream) {
|
|
2674
|
+
return stream.pipe(materialize(), filter((n) => n.kind === "C" || n.kind === "E"), map(() => {
|
|
2675
|
+
return;
|
|
2676
|
+
}), shareReplay(1));
|
|
2677
|
+
}
|
|
2678
|
+
|
|
2679
|
+
// src/helpers/filterDocs.ts
|
|
2680
|
+
function filterDocs(documents, filters) {
|
|
2681
|
+
if (!filters)
|
|
2682
|
+
return documents;
|
|
2683
|
+
const normalized = filters;
|
|
2684
|
+
return documents.filter((doc) => matchesAllFilters(doc, normalized));
|
|
2685
|
+
}
|
|
2686
|
+
function matchesAllFilters(doc, filters) {
|
|
2687
|
+
for (const [key, expected] of Object.entries(filters)) {
|
|
2688
|
+
if (key.startsWith(":") || key.endsWith(":sort"))
|
|
2689
|
+
continue;
|
|
2690
|
+
const split = key.split(":");
|
|
2691
|
+
const fieldPath = split[0];
|
|
2692
|
+
if (!fieldPath)
|
|
2693
|
+
continue;
|
|
2694
|
+
const op = split[1] || "eq";
|
|
2695
|
+
const actual = getByPath(doc, fieldPath);
|
|
2696
|
+
if (!matchByOperator(actual, op, expected)) {
|
|
2697
|
+
return false;
|
|
2698
|
+
}
|
|
2699
|
+
}
|
|
2700
|
+
return true;
|
|
2701
|
+
}
|
|
2702
|
+
function matchByOperator(actual, op, expected) {
|
|
2703
|
+
switch (op) {
|
|
2704
|
+
case "gt":
|
|
2705
|
+
return asNumber(actual) > asNumber(expected);
|
|
2706
|
+
case "gte":
|
|
2707
|
+
return asNumber(actual) >= asNumber(expected);
|
|
2708
|
+
case "lt":
|
|
2709
|
+
return asNumber(actual) < asNumber(expected);
|
|
2710
|
+
case "lte":
|
|
2711
|
+
return asNumber(actual) <= asNumber(expected);
|
|
2712
|
+
case "eq-number":
|
|
2713
|
+
return asNumber(actual) === asNumber(expected);
|
|
2714
|
+
case "in":
|
|
2715
|
+
return Array.isArray(expected) ? expected.includes(actual) : false;
|
|
2716
|
+
case "nin":
|
|
2717
|
+
return Array.isArray(expected) ? !expected.includes(actual) : true;
|
|
2718
|
+
case "include":
|
|
2719
|
+
return Array.isArray(actual) ? actual.includes(expected) : false;
|
|
2720
|
+
case "boolean":
|
|
2721
|
+
return matchBoolean(actual, expected);
|
|
2722
|
+
case "like":
|
|
2723
|
+
return String(actual || "").toLowerCase().includes(String(expected || "").toLowerCase());
|
|
2724
|
+
case "null":
|
|
2725
|
+
return expected === "null-only" ? actual === null || typeof actual === "undefined" : actual !== null && typeof actual !== "undefined";
|
|
2726
|
+
case "eq":
|
|
2727
|
+
default:
|
|
2728
|
+
return actual === expected;
|
|
2729
|
+
}
|
|
2730
|
+
}
|
|
2731
|
+
function matchBoolean(actual, expected) {
|
|
2732
|
+
switch (expected) {
|
|
2733
|
+
case "true":
|
|
2734
|
+
return actual === true;
|
|
2735
|
+
case "false":
|
|
2736
|
+
return actual === false;
|
|
2737
|
+
case "not-true":
|
|
2738
|
+
return actual !== true;
|
|
2739
|
+
case "not-false":
|
|
2740
|
+
return actual !== false;
|
|
2741
|
+
default:
|
|
2742
|
+
return false;
|
|
2743
|
+
}
|
|
2744
|
+
}
|
|
2745
|
+
function getByPath(obj, path) {
|
|
2746
|
+
if (!path.includes("."))
|
|
2747
|
+
return obj[path];
|
|
2748
|
+
return path.split(".").reduce((acc, key) => {
|
|
2749
|
+
if (!acc || typeof acc !== "object")
|
|
2750
|
+
return;
|
|
2751
|
+
return acc[key];
|
|
2752
|
+
}, obj);
|
|
2753
|
+
}
|
|
2754
|
+
function asNumber(value) {
|
|
2755
|
+
return Number(value);
|
|
2756
|
+
}
|
|
2757
|
+
|
|
2453
2758
|
// src/LivequeryCore.ts
|
|
2454
2759
|
class LivequeryCore {
|
|
2455
2760
|
config;
|
|
@@ -2461,79 +2766,95 @@ class LivequeryCore {
|
|
|
2461
2766
|
this.config = config3;
|
|
2462
2767
|
this.#start();
|
|
2463
2768
|
}
|
|
2464
|
-
#
|
|
2465
|
-
|
|
2466
|
-
const
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
type: "added",
|
|
2479
|
-
collection_ref: collection.collection_ref,
|
|
2480
|
-
id: doc.id,
|
|
2481
|
-
data: doc
|
|
2482
|
-
}]
|
|
2483
|
-
});
|
|
2484
|
-
return EMPTY;
|
|
2485
|
-
}
|
|
2769
|
+
#cache = new Map;
|
|
2770
|
+
#query(e, deduplicate_key) {
|
|
2771
|
+
const clear = () => deduplicate_key && this.#cache.delete(deduplicate_key);
|
|
2772
|
+
const cached = deduplicate_key && this.#cache.get(deduplicate_key);
|
|
2773
|
+
if (cached)
|
|
2774
|
+
return Object.assign(cached, { clear });
|
|
2775
|
+
const $ = from(Object.values(this.config.transporters)).pipe(mergeMap((transporter) => transporter.query(e).pipe(tap((result) => {
|
|
2776
|
+
for (const change of result.changes || []) {
|
|
2777
|
+
change.type == "added" && change.data && this.config.storage.add(change.collection_ref, {
|
|
2778
|
+
id: change.data.id,
|
|
2779
|
+
...change.data
|
|
2780
|
+
});
|
|
2781
|
+
change.type == "modified" && change.data && this.config.storage.update(change.collection_ref, change.id, change.data);
|
|
2782
|
+
change.type == "removed" && this.config.storage.delete(change.collection_ref, change.id);
|
|
2486
2783
|
}
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
collection.
|
|
2784
|
+
}), map((result, index) => ({ result, index })), mergeMap(({ result, index }) => {
|
|
2785
|
+
if (index == 0)
|
|
2786
|
+
return of(result);
|
|
2787
|
+
const changes = result.changes || [];
|
|
2788
|
+
if (changes.length === 0)
|
|
2789
|
+
return EMPTY;
|
|
2790
|
+
const lock$ = this.#adding.get(e.collection.collection_ref);
|
|
2791
|
+
if (!lock$) {
|
|
2792
|
+
this.#broadcast(e.collection.collection_ref, "realtime", changes);
|
|
2793
|
+
return EMPTY;
|
|
2794
|
+
}
|
|
2795
|
+
const ok_changes = changes.filter((c) => c.type != "added");
|
|
2796
|
+
const delay_changes = changes.filter((c) => c.type == "added");
|
|
2797
|
+
this.#broadcast(e.collection.collection_ref, "realtime", ok_changes);
|
|
2798
|
+
return lock$.pipe(tap(() => this.#broadcast(e.collection.collection_ref, "realtime", delay_changes)), switchMap(() => EMPTY));
|
|
2799
|
+
}))), finalize(clear), shareReplay());
|
|
2800
|
+
deduplicate_key && this.#cache.set(deduplicate_key, $);
|
|
2801
|
+
return Object.assign($, { clear });
|
|
2802
|
+
}
|
|
2803
|
+
#start() {
|
|
2804
|
+
lastValueFrom(merge(this.#queries$.pipe(filter((req) => req.collection.mode == "server-first" || req.collection.mode == "cache-first"), mergeMap((e) => {
|
|
2805
|
+
const deduplicate_key = `${e.collection.collection_id}:${JSON.stringify(e.filters)}`;
|
|
2806
|
+
const before = e.filters?.[":before"];
|
|
2807
|
+
const after = e.filters?.[":after"];
|
|
2808
|
+
const around = e.filters?.[":around"];
|
|
2809
|
+
const loading = !before && !after || before && after || around ? "all" : before ? "prev" : "next";
|
|
2810
|
+
e.collection.data$.next({
|
|
2811
|
+
from: "query",
|
|
2812
|
+
loading: e.collection.document_id ? "all" : loading
|
|
2813
|
+
});
|
|
2814
|
+
return this.#query(e, deduplicate_key).pipe(takeUntil(whenCompleted(e.collection.data$)), tap((result) => {
|
|
2815
|
+
e.collection.data$.next({
|
|
2516
2816
|
...result,
|
|
2517
|
-
from:
|
|
2817
|
+
from: "query",
|
|
2818
|
+
loading: null
|
|
2518
2819
|
});
|
|
2519
2820
|
}));
|
|
2520
|
-
}),
|
|
2821
|
+
})), this.#queries$.pipe(filter((req) => req.collection.mode == "local-first"), groupBy((e) => `${e.collection.collection_ref}/${e.collection.document_id || "::"}`), mergeMap(($) => $.pipe(mergeMap((e, index) => {
|
|
2822
|
+
index == 0 && e.collection.data$.next({
|
|
2823
|
+
from: "query",
|
|
2824
|
+
loading: "all"
|
|
2825
|
+
});
|
|
2826
|
+
return merge(of(e), index > 0 ? EMPTY : defer(() => {
|
|
2827
|
+
return this.#query(e).pipe(expand((res) => {
|
|
2828
|
+
const next = res.paging?.next;
|
|
2829
|
+
if (!next)
|
|
2830
|
+
return EMPTY;
|
|
2831
|
+
return this.#query({
|
|
2832
|
+
...e,
|
|
2833
|
+
filters: { ":after": next.cursor }
|
|
2834
|
+
});
|
|
2835
|
+
}), tap((result) => {
|
|
2836
|
+
this.#broadcast(e.collection.collection_ref, "query", result.changes || []);
|
|
2837
|
+
}));
|
|
2838
|
+
}).pipe(switchMap(() => EMPTY)));
|
|
2839
|
+
}), scan((p, c) => new Set([...p, c.collection.data$].filter(($2) => !$2.closed)), new Set), map((set) => [...set].map(($2) => whenCompleted($2))), switchMap((list) => forkJoin(list)), takeWhile(() => false))))));
|
|
2521
2840
|
}
|
|
2522
|
-
watch(ref, collection_id) {
|
|
2841
|
+
watch(ref, collection_id, mode) {
|
|
2523
2842
|
const refs = ref.split("/");
|
|
2524
2843
|
const document_id = refs.length % 2 == 0 ? refs[refs.length - 1] : undefined;
|
|
2525
2844
|
const collection_ref = refs.length % 2 == 0 ? refs.slice(0, -1).join("/") : ref;
|
|
2526
2845
|
const collections = this.#refs.get(collection_ref) || new Set;
|
|
2527
2846
|
collections.add(collection_id);
|
|
2528
2847
|
this.#refs.set(collection_ref, collections);
|
|
2529
|
-
const
|
|
2848
|
+
const data$ = new Subject;
|
|
2530
2849
|
this.#collections.set(collection_id, {
|
|
2531
|
-
|
|
2850
|
+
data$,
|
|
2532
2851
|
document_id,
|
|
2533
2852
|
collection_id,
|
|
2534
|
-
collection_ref
|
|
2853
|
+
collection_ref,
|
|
2854
|
+
mode,
|
|
2855
|
+
filters: {}
|
|
2535
2856
|
});
|
|
2536
|
-
return
|
|
2857
|
+
return data$.pipe(finalize(() => {
|
|
2537
2858
|
this.#collections.delete(collection_id);
|
|
2538
2859
|
collections.delete(collection_id);
|
|
2539
2860
|
if (collections.size === 0) {
|
|
@@ -2543,27 +2864,69 @@ class LivequeryCore {
|
|
|
2543
2864
|
}
|
|
2544
2865
|
async query(req) {
|
|
2545
2866
|
const collection = this.#collections.get(req.collection_id);
|
|
2546
|
-
|
|
2547
|
-
|
|
2867
|
+
if (!collection)
|
|
2868
|
+
throw new Error(`Collection with id ${req.collection_id} not found`);
|
|
2869
|
+
if (collection.document_id) {
|
|
2870
|
+
const ids = this.#refs.get(collection.collection_ref);
|
|
2871
|
+
const collections = ids ? [...ids].map((id) => this.#collections.get(id)).filter((c) => c && c.document_id) : [];
|
|
2872
|
+
const doc = await this.config.storage.get(collection.collection_ref, collection.document_id);
|
|
2873
|
+
if (collections.length > 0 && doc)
|
|
2874
|
+
return {
|
|
2875
|
+
documents: [doc]
|
|
2876
|
+
};
|
|
2877
|
+
}
|
|
2878
|
+
setTimeout(() => this.#queries$.next({
|
|
2879
|
+
...req,
|
|
2880
|
+
filters: collection.mode == "local-first" ? {} : req.filters,
|
|
2881
|
+
collection
|
|
2882
|
+
}));
|
|
2883
|
+
collection.filters = req.filters || {};
|
|
2884
|
+
if (collection.mode == "local-first") {
|
|
2885
|
+
return await this.config.storage.query(req.ref, req.filters);
|
|
2886
|
+
}
|
|
2887
|
+
if (collection.mode == "cache-first") {
|
|
2888
|
+
const before = req.filters?.[":before"];
|
|
2889
|
+
const after = req.filters?.[":after"];
|
|
2890
|
+
const is_first_query = !before && !after;
|
|
2891
|
+
if (is_first_query) {
|
|
2892
|
+
return await this.config.storage.query(req.ref, req.filters);
|
|
2893
|
+
}
|
|
2894
|
+
}
|
|
2548
2895
|
}
|
|
2549
|
-
#
|
|
2550
|
-
const collections = this.#refs.get(
|
|
2896
|
+
#broadcast(collection_ref, from2, events) {
|
|
2897
|
+
const collections = this.#refs.get(collection_ref) || new Set;
|
|
2551
2898
|
for (const collection_id of collections) {
|
|
2552
|
-
const
|
|
2553
|
-
if (!
|
|
2899
|
+
const collection = this.#collections.get(collection_id);
|
|
2900
|
+
if (!collection)
|
|
2554
2901
|
continue;
|
|
2555
|
-
if (
|
|
2556
|
-
|
|
2902
|
+
if (collection.document_id) {
|
|
2903
|
+
const change = events.find((c) => c.id == collection.document_id);
|
|
2904
|
+
change && collection.data$.next({
|
|
2557
2905
|
changes: [change],
|
|
2558
|
-
from:
|
|
2906
|
+
from: from2,
|
|
2907
|
+
loading: null
|
|
2559
2908
|
});
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2909
|
+
continue;
|
|
2910
|
+
}
|
|
2911
|
+
if (collection.mode == "local-first") {
|
|
2912
|
+
const changes = events.filter((e) => {
|
|
2913
|
+
if (e.type == "added")
|
|
2914
|
+
return e.data && matchesAllFilters(e.data, collection.filters);
|
|
2915
|
+
return true;
|
|
2916
|
+
});
|
|
2917
|
+
changes.length > 0 && collection.data$.next({
|
|
2918
|
+
changes,
|
|
2919
|
+
from: from2,
|
|
2920
|
+
...from2 == "query" ? { loading: null } : {}
|
|
2921
|
+
});
|
|
2922
|
+
continue;
|
|
2564
2923
|
}
|
|
2924
|
+
collection.data$.next({
|
|
2925
|
+
changes: events,
|
|
2926
|
+
from: from2,
|
|
2927
|
+
...from2 == "query" ? { loading: null } : {}
|
|
2928
|
+
});
|
|
2565
2929
|
}
|
|
2566
|
-
return change.data;
|
|
2567
2930
|
}
|
|
2568
2931
|
#push(collection_ref, id, doc) {
|
|
2569
2932
|
const cleanDoc = Object.entries(doc).reduce((p, [k, v]) => {
|
|
@@ -2583,12 +2946,12 @@ class LivequeryCore {
|
|
|
2583
2946
|
...e ? { _adding_error: e } : {}
|
|
2584
2947
|
};
|
|
2585
2948
|
await this.config.storage.update(collection_ref, id, fnd);
|
|
2586
|
-
this.#
|
|
2949
|
+
this.#broadcast(collection_ref, "action", [{
|
|
2587
2950
|
collection_ref,
|
|
2588
2951
|
type: "modified",
|
|
2589
2952
|
id,
|
|
2590
2953
|
data: fnd
|
|
2591
|
-
});
|
|
2954
|
+
}]);
|
|
2592
2955
|
}
|
|
2593
2956
|
o.next();
|
|
2594
2957
|
o.complete();
|
|
@@ -2602,19 +2965,19 @@ class LivequeryCore {
|
|
|
2602
2965
|
_deleting_error: e
|
|
2603
2966
|
};
|
|
2604
2967
|
await this.config.storage.update(collection_ref, id, fnd);
|
|
2605
|
-
this.#
|
|
2968
|
+
this.#broadcast(collection_ref, "action", [{
|
|
2606
2969
|
collection_ref,
|
|
2607
2970
|
type: "modified",
|
|
2608
2971
|
id,
|
|
2609
2972
|
data: fnd
|
|
2610
|
-
});
|
|
2973
|
+
}]);
|
|
2611
2974
|
} else {
|
|
2612
2975
|
await this.config.storage.delete(collection_ref, id);
|
|
2613
|
-
this.#
|
|
2976
|
+
this.#broadcast(collection_ref, "action", [{
|
|
2614
2977
|
collection_ref,
|
|
2615
2978
|
type: "removed",
|
|
2616
2979
|
id
|
|
2617
|
-
});
|
|
2980
|
+
}]);
|
|
2618
2981
|
}
|
|
2619
2982
|
}
|
|
2620
2983
|
if (doc._prev && Object.keys(doc._prev).length > 0) {
|
|
@@ -2629,24 +2992,24 @@ class LivequeryCore {
|
|
|
2629
2992
|
_updating_error: e
|
|
2630
2993
|
};
|
|
2631
2994
|
await this.config.storage.update(collection_ref, id, fnd);
|
|
2632
|
-
this.#
|
|
2995
|
+
this.#broadcast(collection_ref, "action", [{
|
|
2633
2996
|
collection_ref,
|
|
2634
2997
|
type: "modified",
|
|
2635
2998
|
id,
|
|
2636
2999
|
data: fnd
|
|
2637
|
-
});
|
|
3000
|
+
}]);
|
|
2638
3001
|
}
|
|
2639
3002
|
return EMPTY;
|
|
2640
3003
|
})), { defaultValue: undefined });
|
|
2641
3004
|
}
|
|
2642
3005
|
async add(collection_ref, doc) {
|
|
2643
3006
|
const data = await this.config.storage.add(collection_ref, { ...doc, _adding: true });
|
|
2644
|
-
this.#
|
|
3007
|
+
this.#broadcast(collection_ref, "action", [{
|
|
3008
|
+
collection_ref,
|
|
2645
3009
|
id: data.id,
|
|
2646
3010
|
type: "added",
|
|
2647
|
-
data
|
|
2648
|
-
|
|
2649
|
-
});
|
|
3011
|
+
data
|
|
3012
|
+
}]);
|
|
2650
3013
|
await this.#push(collection_ref, data.id, data);
|
|
2651
3014
|
return data;
|
|
2652
3015
|
}
|
|
@@ -2663,7 +3026,7 @@ class LivequeryCore {
|
|
|
2663
3026
|
};
|
|
2664
3027
|
}, old._prev || {});
|
|
2665
3028
|
await this.config.storage.update(collection_ref, id, { _prev, _updating: true, ...data });
|
|
2666
|
-
const doc = await this.#
|
|
3029
|
+
const doc = await this.#broadcast(collection_ref, "action", [{
|
|
2667
3030
|
collection_ref,
|
|
2668
3031
|
id,
|
|
2669
3032
|
type: "modified",
|
|
@@ -2672,7 +3035,7 @@ class LivequeryCore {
|
|
|
2672
3035
|
_updating: true,
|
|
2673
3036
|
...data
|
|
2674
3037
|
}
|
|
2675
|
-
});
|
|
3038
|
+
}]);
|
|
2676
3039
|
await this.#push(collection_ref, id, { ...data, _prev, _updating: true });
|
|
2677
3040
|
return doc;
|
|
2678
3041
|
}
|
|
@@ -2681,108 +3044,29 @@ class LivequeryCore {
|
|
|
2681
3044
|
const is_local_doc = id.startsWith("local:");
|
|
2682
3045
|
if (!soft || is_local_doc) {
|
|
2683
3046
|
await this.config.storage.delete(collection_ref, id);
|
|
2684
|
-
await this.#
|
|
3047
|
+
await this.#broadcast(collection_ref, "action", [{
|
|
2685
3048
|
collection_ref,
|
|
2686
3049
|
id,
|
|
2687
3050
|
type: "removed"
|
|
2688
|
-
});
|
|
3051
|
+
}]);
|
|
2689
3052
|
return;
|
|
2690
3053
|
}
|
|
2691
3054
|
await this.config.storage.update(collection_ref, id, { _deleting: true });
|
|
2692
|
-
const doc = await this.#
|
|
3055
|
+
const doc = await this.#broadcast(collection_ref, "action", [{
|
|
2693
3056
|
collection_ref,
|
|
2694
3057
|
id,
|
|
2695
3058
|
type: "modified",
|
|
2696
3059
|
data: {
|
|
2697
3060
|
_deleting: true
|
|
2698
3061
|
}
|
|
2699
|
-
});
|
|
2700
|
-
await this.#push(collection_ref, id, {
|
|
3062
|
+
}]);
|
|
3063
|
+
await this.#push(collection_ref, id, { _deleting: true });
|
|
2701
3064
|
return doc;
|
|
2702
3065
|
}
|
|
2703
3066
|
trigger(action) {
|
|
2704
3067
|
return from(Object.values(this.config.transporters)).pipe(mergeMap((transporter) => transporter.trigger(action)));
|
|
2705
3068
|
}
|
|
2706
3069
|
}
|
|
2707
|
-
// src/helpers/filterDocs.ts
|
|
2708
|
-
function filterDocs(documents, filters) {
|
|
2709
|
-
if (!filters)
|
|
2710
|
-
return documents;
|
|
2711
|
-
const normalized = filters;
|
|
2712
|
-
return documents.filter((doc) => matchesAllFilters(doc, normalized));
|
|
2713
|
-
}
|
|
2714
|
-
function matchesAllFilters(doc, filters) {
|
|
2715
|
-
for (const [key, expected] of Object.entries(filters)) {
|
|
2716
|
-
if (key.startsWith(":") || key.endsWith(":sort"))
|
|
2717
|
-
continue;
|
|
2718
|
-
const split = key.split(":");
|
|
2719
|
-
const fieldPath = split[0];
|
|
2720
|
-
if (!fieldPath)
|
|
2721
|
-
continue;
|
|
2722
|
-
const op = split[1] || "eq";
|
|
2723
|
-
const actual = getByPath(doc, fieldPath);
|
|
2724
|
-
if (!matchByOperator(actual, op, expected)) {
|
|
2725
|
-
return false;
|
|
2726
|
-
}
|
|
2727
|
-
}
|
|
2728
|
-
return true;
|
|
2729
|
-
}
|
|
2730
|
-
function matchByOperator(actual, op, expected) {
|
|
2731
|
-
switch (op) {
|
|
2732
|
-
case "gt":
|
|
2733
|
-
return asNumber(actual) > asNumber(expected);
|
|
2734
|
-
case "gte":
|
|
2735
|
-
return asNumber(actual) >= asNumber(expected);
|
|
2736
|
-
case "lt":
|
|
2737
|
-
return asNumber(actual) < asNumber(expected);
|
|
2738
|
-
case "lte":
|
|
2739
|
-
return asNumber(actual) <= asNumber(expected);
|
|
2740
|
-
case "eq-number":
|
|
2741
|
-
return asNumber(actual) === asNumber(expected);
|
|
2742
|
-
case "in":
|
|
2743
|
-
return Array.isArray(expected) ? expected.includes(actual) : false;
|
|
2744
|
-
case "nin":
|
|
2745
|
-
return Array.isArray(expected) ? !expected.includes(actual) : true;
|
|
2746
|
-
case "include":
|
|
2747
|
-
return Array.isArray(actual) ? actual.includes(expected) : false;
|
|
2748
|
-
case "boolean":
|
|
2749
|
-
return matchBoolean(actual, expected);
|
|
2750
|
-
case "like":
|
|
2751
|
-
return String(actual || "").toLowerCase().includes(String(expected || "").toLowerCase());
|
|
2752
|
-
case "null":
|
|
2753
|
-
return expected === "null-only" ? actual === null || typeof actual === "undefined" : actual !== null && typeof actual !== "undefined";
|
|
2754
|
-
case "eq":
|
|
2755
|
-
default:
|
|
2756
|
-
return actual === expected;
|
|
2757
|
-
}
|
|
2758
|
-
}
|
|
2759
|
-
function matchBoolean(actual, expected) {
|
|
2760
|
-
switch (expected) {
|
|
2761
|
-
case "true":
|
|
2762
|
-
return actual === true;
|
|
2763
|
-
case "false":
|
|
2764
|
-
return actual === false;
|
|
2765
|
-
case "not-true":
|
|
2766
|
-
return actual !== true;
|
|
2767
|
-
case "not-false":
|
|
2768
|
-
return actual !== false;
|
|
2769
|
-
default:
|
|
2770
|
-
return false;
|
|
2771
|
-
}
|
|
2772
|
-
}
|
|
2773
|
-
function getByPath(obj, path) {
|
|
2774
|
-
if (!path.includes("."))
|
|
2775
|
-
return obj[path];
|
|
2776
|
-
return path.split(".").reduce((acc, key) => {
|
|
2777
|
-
if (!acc || typeof acc !== "object")
|
|
2778
|
-
return;
|
|
2779
|
-
return acc[key];
|
|
2780
|
-
}, obj);
|
|
2781
|
-
}
|
|
2782
|
-
function asNumber(value) {
|
|
2783
|
-
return Number(value);
|
|
2784
|
-
}
|
|
2785
|
-
|
|
2786
3070
|
// src/LivequeryMemoryStorage.ts
|
|
2787
3071
|
class LivequeryMemoryStorage {
|
|
2788
3072
|
#collections = new Map;
|
|
@@ -2879,5 +3163,5 @@ export {
|
|
|
2879
3163
|
LivequeryCollection
|
|
2880
3164
|
};
|
|
2881
3165
|
|
|
2882
|
-
//# debugId=
|
|
3166
|
+
//# debugId=E4687FC651D4981264756E2164756E21
|
|
2883
3167
|
//# sourceMappingURL=index.js.map
|