@livequery/core 2.0.86 → 2.0.87
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/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 +591 -309
- 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,10 +2478,7 @@ 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) => {
|
|
2241
2484
|
event.summary && this.summary.next(event.summary);
|
|
@@ -2290,7 +2533,7 @@ class LivequeryCollection {
|
|
|
2290
2533
|
const target = index != null && index >= 0 ? p[index] : null;
|
|
2291
2534
|
target && target.next({ ...target.value, ...data });
|
|
2292
2535
|
return p;
|
|
2293
|
-
}, this
|
|
2536
|
+
}, this.items.value);
|
|
2294
2537
|
const new_items = events.added.filter((a) => a.data).reduce((p, c) => {
|
|
2295
2538
|
if (!p.indexes.has(c.id)) {
|
|
2296
2539
|
const doc = new LivequeryDocument(this, { id: c.id, ...c.data });
|
|
@@ -2313,31 +2556,20 @@ class LivequeryCollection {
|
|
|
2313
2556
|
...new_items.list
|
|
2314
2557
|
]);
|
|
2315
2558
|
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
|
-
}
|
|
2559
|
+
chaos && this.#commit(items);
|
|
2321
2560
|
event.from == "query" && this.loading.next(null);
|
|
2322
2561
|
event.paging && this.paging.next(event.paging);
|
|
2323
2562
|
event.from == "query" && this.loading.next(null);
|
|
2324
2563
|
}))).subscribe();
|
|
2325
2564
|
return this.#subscription;
|
|
2326
2565
|
}
|
|
2327
|
-
#show$ = new Subject;
|
|
2328
|
-
async show(visible) {
|
|
2329
|
-
this.#show$.next(visible);
|
|
2330
|
-
}
|
|
2331
2566
|
async#query(filters, flush) {
|
|
2332
2567
|
if (!this.#core)
|
|
2333
2568
|
return;
|
|
2334
2569
|
if (!this.ref)
|
|
2335
2570
|
return;
|
|
2336
2571
|
this.error.next(null);
|
|
2337
|
-
|
|
2338
|
-
this.#items = [];
|
|
2339
|
-
this.items.next([]);
|
|
2340
|
-
}
|
|
2572
|
+
flush && this.#commit([]);
|
|
2341
2573
|
this.#keys = Object.entries(filters).reduce((p, [k, v]) => {
|
|
2342
2574
|
if (k.endsWith(":sort")) {
|
|
2343
2575
|
const field = k.split(":")[0];
|
|
@@ -2355,9 +2587,8 @@ class LivequeryCollection {
|
|
|
2355
2587
|
filters,
|
|
2356
2588
|
collection_id: this.id
|
|
2357
2589
|
});
|
|
2358
|
-
if (
|
|
2359
|
-
this.#
|
|
2360
|
-
this.items.next(this.#items);
|
|
2590
|
+
if (items && flush && Object.keys(filters || {}).length == 0) {
|
|
2591
|
+
this.#commit(items.documents.map((i) => new LivequeryDocument(this, i)));
|
|
2361
2592
|
this.loading.next(null);
|
|
2362
2593
|
}
|
|
2363
2594
|
}
|
|
@@ -2450,6 +2681,92 @@ var tryCatch = async (fn) => {
|
|
|
2450
2681
|
}
|
|
2451
2682
|
};
|
|
2452
2683
|
|
|
2684
|
+
// src/helpers/whenCompleted.ts
|
|
2685
|
+
function whenCompleted(stream) {
|
|
2686
|
+
return stream.pipe(materialize(), filter((n) => n.kind === "C" || n.kind === "E"), map(() => {
|
|
2687
|
+
return;
|
|
2688
|
+
}), shareReplay(1));
|
|
2689
|
+
}
|
|
2690
|
+
|
|
2691
|
+
// src/helpers/filterDocs.ts
|
|
2692
|
+
function filterDocs(documents, filters) {
|
|
2693
|
+
if (!filters)
|
|
2694
|
+
return documents;
|
|
2695
|
+
const normalized = filters;
|
|
2696
|
+
return documents.filter((doc) => matchesAllFilters(doc, normalized));
|
|
2697
|
+
}
|
|
2698
|
+
function matchesAllFilters(doc, filters) {
|
|
2699
|
+
for (const [key, expected] of Object.entries(filters)) {
|
|
2700
|
+
if (key.startsWith(":") || key.endsWith(":sort"))
|
|
2701
|
+
continue;
|
|
2702
|
+
const split = key.split(":");
|
|
2703
|
+
const fieldPath = split[0];
|
|
2704
|
+
if (!fieldPath)
|
|
2705
|
+
continue;
|
|
2706
|
+
const op = split[1] || "eq";
|
|
2707
|
+
const actual = getByPath(doc, fieldPath);
|
|
2708
|
+
if (!matchByOperator(actual, op, expected)) {
|
|
2709
|
+
return false;
|
|
2710
|
+
}
|
|
2711
|
+
}
|
|
2712
|
+
return true;
|
|
2713
|
+
}
|
|
2714
|
+
function matchByOperator(actual, op, expected) {
|
|
2715
|
+
switch (op) {
|
|
2716
|
+
case "gt":
|
|
2717
|
+
return asNumber(actual) > asNumber(expected);
|
|
2718
|
+
case "gte":
|
|
2719
|
+
return asNumber(actual) >= asNumber(expected);
|
|
2720
|
+
case "lt":
|
|
2721
|
+
return asNumber(actual) < asNumber(expected);
|
|
2722
|
+
case "lte":
|
|
2723
|
+
return asNumber(actual) <= asNumber(expected);
|
|
2724
|
+
case "eq-number":
|
|
2725
|
+
return asNumber(actual) === asNumber(expected);
|
|
2726
|
+
case "in":
|
|
2727
|
+
return Array.isArray(expected) ? expected.includes(actual) : false;
|
|
2728
|
+
case "nin":
|
|
2729
|
+
return Array.isArray(expected) ? !expected.includes(actual) : true;
|
|
2730
|
+
case "include":
|
|
2731
|
+
return Array.isArray(actual) ? actual.includes(expected) : false;
|
|
2732
|
+
case "boolean":
|
|
2733
|
+
return matchBoolean(actual, expected);
|
|
2734
|
+
case "like":
|
|
2735
|
+
return String(actual || "").toLowerCase().includes(String(expected || "").toLowerCase());
|
|
2736
|
+
case "null":
|
|
2737
|
+
return expected === "null-only" ? actual === null || typeof actual === "undefined" : actual !== null && typeof actual !== "undefined";
|
|
2738
|
+
case "eq":
|
|
2739
|
+
default:
|
|
2740
|
+
return actual === expected;
|
|
2741
|
+
}
|
|
2742
|
+
}
|
|
2743
|
+
function matchBoolean(actual, expected) {
|
|
2744
|
+
switch (expected) {
|
|
2745
|
+
case "true":
|
|
2746
|
+
return actual === true;
|
|
2747
|
+
case "false":
|
|
2748
|
+
return actual === false;
|
|
2749
|
+
case "not-true":
|
|
2750
|
+
return actual !== true;
|
|
2751
|
+
case "not-false":
|
|
2752
|
+
return actual !== false;
|
|
2753
|
+
default:
|
|
2754
|
+
return false;
|
|
2755
|
+
}
|
|
2756
|
+
}
|
|
2757
|
+
function getByPath(obj, path) {
|
|
2758
|
+
if (!path.includes("."))
|
|
2759
|
+
return obj[path];
|
|
2760
|
+
return path.split(".").reduce((acc, key) => {
|
|
2761
|
+
if (!acc || typeof acc !== "object")
|
|
2762
|
+
return;
|
|
2763
|
+
return acc[key];
|
|
2764
|
+
}, obj);
|
|
2765
|
+
}
|
|
2766
|
+
function asNumber(value) {
|
|
2767
|
+
return Number(value);
|
|
2768
|
+
}
|
|
2769
|
+
|
|
2453
2770
|
// src/LivequeryCore.ts
|
|
2454
2771
|
class LivequeryCore {
|
|
2455
2772
|
config;
|
|
@@ -2461,79 +2778,80 @@ class LivequeryCore {
|
|
|
2461
2778
|
this.config = config3;
|
|
2462
2779
|
this.#start();
|
|
2463
2780
|
}
|
|
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
|
-
}
|
|
2781
|
+
#cache = new Map;
|
|
2782
|
+
#query(e, deduplicate_key) {
|
|
2783
|
+
const clear = () => deduplicate_key && this.#cache.delete(deduplicate_key);
|
|
2784
|
+
const cached = deduplicate_key && this.#cache.get(deduplicate_key);
|
|
2785
|
+
if (cached)
|
|
2786
|
+
return Object.assign(cached, { clear });
|
|
2787
|
+
const $ = from(Object.values(this.config.transporters)).pipe(mergeMap((transporter) => transporter.query(e).pipe(tap((result) => {
|
|
2788
|
+
for (const change of result.changes || []) {
|
|
2789
|
+
change.type == "added" && change.data && this.config.storage.add(change.collection_ref, {
|
|
2790
|
+
id: change.data.id,
|
|
2791
|
+
...change.data
|
|
2792
|
+
});
|
|
2793
|
+
change.type == "modified" && change.data && this.config.storage.update(change.collection_ref, change.id, change.data);
|
|
2794
|
+
change.type == "removed" && this.config.storage.delete(change.collection_ref, change.id);
|
|
2486
2795
|
}
|
|
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
|
-
}), filter(Boolean), shareReplay());
|
|
2512
|
-
cache.set(key, query);
|
|
2513
|
-
return query;
|
|
2514
|
-
}), mergeMap(($) => $), map(({ result }, index) => {
|
|
2515
|
-
collection.o.next({
|
|
2796
|
+
}), map((result, index) => ({ result, index })), mergeMap(({ result, index }) => {
|
|
2797
|
+
if (index == 0)
|
|
2798
|
+
return of(result);
|
|
2799
|
+
const changes = result.changes || [];
|
|
2800
|
+
if (changes.length === 0)
|
|
2801
|
+
return EMPTY;
|
|
2802
|
+
const lock$ = this.#adding.get(e.collection.collection_ref);
|
|
2803
|
+
if (!lock$) {
|
|
2804
|
+
this.#broadcast(e.collection.collection_ref, "realtime", changes);
|
|
2805
|
+
return EMPTY;
|
|
2806
|
+
}
|
|
2807
|
+
const ok_changes = changes.filter((c) => c.type != "added");
|
|
2808
|
+
const delay_changes = changes.filter((c) => c.type == "added");
|
|
2809
|
+
this.#broadcast(e.collection.collection_ref, "realtime", ok_changes);
|
|
2810
|
+
return lock$.pipe(tap(() => this.#broadcast(e.collection.collection_ref, "realtime", delay_changes)), switchMap(() => EMPTY));
|
|
2811
|
+
}))), finalize(clear), shareReplay());
|
|
2812
|
+
deduplicate_key && this.#cache.set(deduplicate_key, $);
|
|
2813
|
+
return Object.assign($, { clear });
|
|
2814
|
+
}
|
|
2815
|
+
#start() {
|
|
2816
|
+
lastValueFrom(merge(this.#queries$.pipe(filter((req) => req.collection.mode == "server-first" || req.collection.mode == "cache-first"), mergeMap((e) => {
|
|
2817
|
+
const deduplicate_key = `${e.collection.collection_id}:${JSON.stringify(e.filters)}`;
|
|
2818
|
+
return this.#query(e, deduplicate_key).pipe(takeUntil(whenCompleted(e.collection.data$)), tap((result) => {
|
|
2819
|
+
e.collection.data$.next({
|
|
2516
2820
|
...result,
|
|
2517
|
-
from:
|
|
2821
|
+
from: "query"
|
|
2518
2822
|
});
|
|
2519
2823
|
}));
|
|
2520
|
-
}), mergeMap(($) =>
|
|
2824
|
+
})), 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) => merge(of(e), index > 0 ? EMPTY : defer(() => {
|
|
2825
|
+
return this.#query(e).pipe(expand((res) => {
|
|
2826
|
+
const next = res.paging?.next;
|
|
2827
|
+
if (!next)
|
|
2828
|
+
return EMPTY;
|
|
2829
|
+
return this.#query({
|
|
2830
|
+
...e,
|
|
2831
|
+
filters: { ":after": next.cursor }
|
|
2832
|
+
});
|
|
2833
|
+
}), tap((result) => {
|
|
2834
|
+
this.#broadcast(e.collection.collection_ref, "query", result.changes || []);
|
|
2835
|
+
}));
|
|
2836
|
+
}).pipe(switchMap(() => EMPTY)))), 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
2837
|
}
|
|
2522
|
-
watch(ref, collection_id) {
|
|
2838
|
+
watch(ref, collection_id, mode) {
|
|
2523
2839
|
const refs = ref.split("/");
|
|
2524
2840
|
const document_id = refs.length % 2 == 0 ? refs[refs.length - 1] : undefined;
|
|
2525
2841
|
const collection_ref = refs.length % 2 == 0 ? refs.slice(0, -1).join("/") : ref;
|
|
2526
2842
|
const collections = this.#refs.get(collection_ref) || new Set;
|
|
2527
2843
|
collections.add(collection_id);
|
|
2528
2844
|
this.#refs.set(collection_ref, collections);
|
|
2529
|
-
const
|
|
2845
|
+
const data$ = new Subject;
|
|
2530
2846
|
this.#collections.set(collection_id, {
|
|
2531
|
-
|
|
2847
|
+
data$,
|
|
2532
2848
|
document_id,
|
|
2533
2849
|
collection_id,
|
|
2534
|
-
collection_ref
|
|
2850
|
+
collection_ref,
|
|
2851
|
+
mode,
|
|
2852
|
+
filters: {}
|
|
2535
2853
|
});
|
|
2536
|
-
return
|
|
2854
|
+
return data$.pipe(finalize(() => {
|
|
2537
2855
|
this.#collections.delete(collection_id);
|
|
2538
2856
|
collections.delete(collection_id);
|
|
2539
2857
|
if (collections.size === 0) {
|
|
@@ -2543,27 +2861,70 @@ class LivequeryCore {
|
|
|
2543
2861
|
}
|
|
2544
2862
|
async query(req) {
|
|
2545
2863
|
const collection = this.#collections.get(req.collection_id);
|
|
2546
|
-
|
|
2547
|
-
|
|
2864
|
+
if (!collection)
|
|
2865
|
+
throw new Error(`Collection with id ${req.collection_id} not found`);
|
|
2866
|
+
setTimeout(() => this.#queries$.next({
|
|
2867
|
+
...req,
|
|
2868
|
+
filters: collection.mode == "local-first" ? {} : req.filters,
|
|
2869
|
+
collection
|
|
2870
|
+
}));
|
|
2871
|
+
if (collection.document_id) {
|
|
2872
|
+
const doc = await this.config.storage.get(collection.collection_ref, collection.document_id);
|
|
2873
|
+
return {
|
|
2874
|
+
documents: doc ? [doc] : []
|
|
2875
|
+
};
|
|
2876
|
+
}
|
|
2877
|
+
collection.filters = req.filters || {};
|
|
2878
|
+
if (collection.mode == "local-first") {
|
|
2879
|
+
return await this.config.storage.query(req.ref, req.filters);
|
|
2880
|
+
}
|
|
2881
|
+
if (collection.mode == "cache-first") {
|
|
2882
|
+
const before = req.filters?.[":before"];
|
|
2883
|
+
const after = req.filters?.[":after"];
|
|
2884
|
+
const is_first_query = !before && !after;
|
|
2885
|
+
if (is_first_query) {
|
|
2886
|
+
return await this.config.storage.query(req.ref, req.filters);
|
|
2887
|
+
}
|
|
2888
|
+
}
|
|
2548
2889
|
}
|
|
2549
|
-
#
|
|
2550
|
-
const collections = this.#refs.get(
|
|
2890
|
+
#broadcast(collection_ref, from2, events) {
|
|
2891
|
+
const collections = this.#refs.get(collection_ref) || new Set;
|
|
2551
2892
|
for (const collection_id of collections) {
|
|
2552
|
-
const
|
|
2553
|
-
if (!
|
|
2893
|
+
const collection = this.#collections.get(collection_id);
|
|
2894
|
+
if (!collection)
|
|
2554
2895
|
continue;
|
|
2555
|
-
if (
|
|
2556
|
-
|
|
2896
|
+
if (collection.document_id) {
|
|
2897
|
+
const change = events.find((c) => c.id == collection.document_id);
|
|
2898
|
+
change && collection.data$.next({
|
|
2557
2899
|
changes: [change],
|
|
2558
|
-
from:
|
|
2900
|
+
from: from2
|
|
2559
2901
|
});
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2902
|
+
continue;
|
|
2903
|
+
}
|
|
2904
|
+
if (collection.mode == "local-first") {
|
|
2905
|
+
const changes = events.filter((e) => {
|
|
2906
|
+
if (e.type == "added")
|
|
2907
|
+
return e.data && matchesAllFilters(e.data, collection.filters);
|
|
2908
|
+
if (e.type == "modified") {
|
|
2909
|
+
if (!e.data)
|
|
2910
|
+
return false;
|
|
2911
|
+
if (!matchesAllFilters(e.data, collection.filters)) {
|
|
2912
|
+
e.type = "removed";
|
|
2913
|
+
}
|
|
2914
|
+
}
|
|
2915
|
+
return true;
|
|
2916
|
+
});
|
|
2917
|
+
changes.length > 0 && collection.data$.next({
|
|
2918
|
+
changes,
|
|
2919
|
+
from: from2
|
|
2920
|
+
});
|
|
2921
|
+
continue;
|
|
2564
2922
|
}
|
|
2923
|
+
collection.data$.next({
|
|
2924
|
+
changes: events,
|
|
2925
|
+
from: from2
|
|
2926
|
+
});
|
|
2565
2927
|
}
|
|
2566
|
-
return change.data;
|
|
2567
2928
|
}
|
|
2568
2929
|
#push(collection_ref, id, doc) {
|
|
2569
2930
|
const cleanDoc = Object.entries(doc).reduce((p, [k, v]) => {
|
|
@@ -2583,12 +2944,12 @@ class LivequeryCore {
|
|
|
2583
2944
|
...e ? { _adding_error: e } : {}
|
|
2584
2945
|
};
|
|
2585
2946
|
await this.config.storage.update(collection_ref, id, fnd);
|
|
2586
|
-
this.#
|
|
2947
|
+
this.#broadcast(collection_ref, "action", [{
|
|
2587
2948
|
collection_ref,
|
|
2588
2949
|
type: "modified",
|
|
2589
2950
|
id,
|
|
2590
2951
|
data: fnd
|
|
2591
|
-
});
|
|
2952
|
+
}]);
|
|
2592
2953
|
}
|
|
2593
2954
|
o.next();
|
|
2594
2955
|
o.complete();
|
|
@@ -2602,19 +2963,19 @@ class LivequeryCore {
|
|
|
2602
2963
|
_deleting_error: e
|
|
2603
2964
|
};
|
|
2604
2965
|
await this.config.storage.update(collection_ref, id, fnd);
|
|
2605
|
-
this.#
|
|
2966
|
+
this.#broadcast(collection_ref, "action", [{
|
|
2606
2967
|
collection_ref,
|
|
2607
2968
|
type: "modified",
|
|
2608
2969
|
id,
|
|
2609
2970
|
data: fnd
|
|
2610
|
-
});
|
|
2971
|
+
}]);
|
|
2611
2972
|
} else {
|
|
2612
2973
|
await this.config.storage.delete(collection_ref, id);
|
|
2613
|
-
this.#
|
|
2974
|
+
this.#broadcast(collection_ref, "action", [{
|
|
2614
2975
|
collection_ref,
|
|
2615
2976
|
type: "removed",
|
|
2616
2977
|
id
|
|
2617
|
-
});
|
|
2978
|
+
}]);
|
|
2618
2979
|
}
|
|
2619
2980
|
}
|
|
2620
2981
|
if (doc._prev && Object.keys(doc._prev).length > 0) {
|
|
@@ -2629,24 +2990,24 @@ class LivequeryCore {
|
|
|
2629
2990
|
_updating_error: e
|
|
2630
2991
|
};
|
|
2631
2992
|
await this.config.storage.update(collection_ref, id, fnd);
|
|
2632
|
-
this.#
|
|
2993
|
+
this.#broadcast(collection_ref, "action", [{
|
|
2633
2994
|
collection_ref,
|
|
2634
2995
|
type: "modified",
|
|
2635
2996
|
id,
|
|
2636
2997
|
data: fnd
|
|
2637
|
-
});
|
|
2998
|
+
}]);
|
|
2638
2999
|
}
|
|
2639
3000
|
return EMPTY;
|
|
2640
3001
|
})), { defaultValue: undefined });
|
|
2641
3002
|
}
|
|
2642
3003
|
async add(collection_ref, doc) {
|
|
2643
3004
|
const data = await this.config.storage.add(collection_ref, { ...doc, _adding: true });
|
|
2644
|
-
this.#
|
|
3005
|
+
this.#broadcast(collection_ref, "action", [{
|
|
3006
|
+
collection_ref,
|
|
2645
3007
|
id: data.id,
|
|
2646
3008
|
type: "added",
|
|
2647
|
-
data
|
|
2648
|
-
|
|
2649
|
-
});
|
|
3009
|
+
data
|
|
3010
|
+
}]);
|
|
2650
3011
|
await this.#push(collection_ref, data.id, data);
|
|
2651
3012
|
return data;
|
|
2652
3013
|
}
|
|
@@ -2663,7 +3024,7 @@ class LivequeryCore {
|
|
|
2663
3024
|
};
|
|
2664
3025
|
}, old._prev || {});
|
|
2665
3026
|
await this.config.storage.update(collection_ref, id, { _prev, _updating: true, ...data });
|
|
2666
|
-
const doc = await this.#
|
|
3027
|
+
const doc = await this.#broadcast(collection_ref, "action", [{
|
|
2667
3028
|
collection_ref,
|
|
2668
3029
|
id,
|
|
2669
3030
|
type: "modified",
|
|
@@ -2672,7 +3033,7 @@ class LivequeryCore {
|
|
|
2672
3033
|
_updating: true,
|
|
2673
3034
|
...data
|
|
2674
3035
|
}
|
|
2675
|
-
});
|
|
3036
|
+
}]);
|
|
2676
3037
|
await this.#push(collection_ref, id, { ...data, _prev, _updating: true });
|
|
2677
3038
|
return doc;
|
|
2678
3039
|
}
|
|
@@ -2681,108 +3042,29 @@ class LivequeryCore {
|
|
|
2681
3042
|
const is_local_doc = id.startsWith("local:");
|
|
2682
3043
|
if (!soft || is_local_doc) {
|
|
2683
3044
|
await this.config.storage.delete(collection_ref, id);
|
|
2684
|
-
await this.#
|
|
3045
|
+
await this.#broadcast(collection_ref, "action", [{
|
|
2685
3046
|
collection_ref,
|
|
2686
3047
|
id,
|
|
2687
3048
|
type: "removed"
|
|
2688
|
-
});
|
|
3049
|
+
}]);
|
|
2689
3050
|
return;
|
|
2690
3051
|
}
|
|
2691
3052
|
await this.config.storage.update(collection_ref, id, { _deleting: true });
|
|
2692
|
-
const doc = await this.#
|
|
3053
|
+
const doc = await this.#broadcast(collection_ref, "action", [{
|
|
2693
3054
|
collection_ref,
|
|
2694
3055
|
id,
|
|
2695
3056
|
type: "modified",
|
|
2696
3057
|
data: {
|
|
2697
3058
|
_deleting: true
|
|
2698
3059
|
}
|
|
2699
|
-
});
|
|
2700
|
-
await this.#push(collection_ref, id, {
|
|
3060
|
+
}]);
|
|
3061
|
+
await this.#push(collection_ref, id, { _deleting: true });
|
|
2701
3062
|
return doc;
|
|
2702
3063
|
}
|
|
2703
3064
|
trigger(action) {
|
|
2704
3065
|
return from(Object.values(this.config.transporters)).pipe(mergeMap((transporter) => transporter.trigger(action)));
|
|
2705
3066
|
}
|
|
2706
3067
|
}
|
|
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
3068
|
// src/LivequeryMemoryStorage.ts
|
|
2787
3069
|
class LivequeryMemoryStorage {
|
|
2788
3070
|
#collections = new Map;
|
|
@@ -2879,5 +3161,5 @@ export {
|
|
|
2879
3161
|
LivequeryCollection
|
|
2880
3162
|
};
|
|
2881
3163
|
|
|
2882
|
-
//# debugId=
|
|
3164
|
+
//# debugId=067B8FB03B47D24664756E2164756E21
|
|
2883
3165
|
//# sourceMappingURL=index.js.map
|