tinybase 2.0.0-beta.0 → 2.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/checkpoints.d.ts +4 -3
- package/lib/checkpoints.js +1 -1
- package/lib/checkpoints.js.gz +0 -0
- package/lib/common.js +1 -1
- package/lib/common.js.gz +0 -0
- package/lib/debug/checkpoints.d.ts +4 -3
- package/lib/debug/checkpoints.js +13 -16
- package/lib/debug/common.js +4 -1
- package/lib/debug/indexes.d.ts +4 -2
- package/lib/debug/indexes.js +13 -15
- package/lib/debug/metrics.d.ts +1 -1
- package/lib/debug/metrics.js +13 -16
- package/lib/debug/persisters.d.ts +6 -0
- package/lib/debug/queries.d.ts +249 -299
- package/lib/debug/queries.js +67 -192
- package/lib/debug/relationships.d.ts +6 -5
- package/lib/debug/relationships.js +13 -16
- package/lib/debug/store.d.ts +386 -86
- package/lib/debug/store.js +278 -216
- package/lib/debug/tinybase.js +318 -390
- package/lib/debug/ui-react.d.ts +4320 -1796
- package/lib/debug/ui-react.js +380 -98
- package/lib/indexes.d.ts +4 -2
- package/lib/indexes.js +1 -1
- package/lib/indexes.js.gz +0 -0
- package/lib/metrics.d.ts +1 -1
- package/lib/metrics.js +1 -1
- package/lib/metrics.js.gz +0 -0
- package/lib/persisters.d.ts +6 -0
- package/lib/queries.d.ts +249 -299
- package/lib/queries.js +1 -1
- package/lib/queries.js.gz +0 -0
- package/lib/relationships.d.ts +6 -5
- package/lib/relationships.js +1 -1
- package/lib/relationships.js.gz +0 -0
- package/lib/store.d.ts +386 -86
- package/lib/store.js +1 -1
- package/lib/store.js.gz +0 -0
- package/lib/tinybase.js +1 -1
- package/lib/tinybase.js.gz +0 -0
- package/lib/ui-react.d.ts +4320 -1796
- package/lib/ui-react.js +1 -1
- package/lib/ui-react.js.gz +0 -0
- package/lib/umd/checkpoints.js +1 -1
- package/lib/umd/checkpoints.js.gz +0 -0
- package/lib/umd/common.js +1 -1
- package/lib/umd/common.js.gz +0 -0
- package/lib/umd/indexes.js +1 -1
- package/lib/umd/indexes.js.gz +0 -0
- package/lib/umd/metrics.js +1 -1
- package/lib/umd/metrics.js.gz +0 -0
- package/lib/umd/queries.js +1 -1
- package/lib/umd/queries.js.gz +0 -0
- package/lib/umd/relationships.js +1 -1
- package/lib/umd/relationships.js.gz +0 -0
- package/lib/umd/store.js +1 -1
- package/lib/umd/store.js.gz +0 -0
- package/lib/umd/tinybase.js +1 -1
- package/lib/umd/tinybase.js.gz +0 -0
- package/lib/umd/ui-react.js +1 -1
- package/lib/umd/ui-react.js.gz +0 -0
- package/package.json +26 -26
- package/readme.md +2 -2
package/lib/debug/queries.js
CHANGED
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
const arrayEvery = (array, cb) => array.every(cb);
|
|
2
|
-
const arrayIsEqual = (array1, array2) =>
|
|
3
|
-
arrayLength(array1) === arrayLength(array2) &&
|
|
4
|
-
arrayEvery(array1, (value1, index) => array2[index] === value1);
|
|
5
|
-
const arraySort = (array, sorter) => array.sort(sorter);
|
|
6
|
-
const arrayForEach = (array, cb) => array.forEach(cb);
|
|
7
|
-
const arrayMap = (array, cb) => array.map(cb);
|
|
8
|
-
const arraySum = (array) => arrayReduce(array, (i, j) => i + j, 0);
|
|
9
|
-
const arrayLength = (array) => array.length;
|
|
10
|
-
const arrayIsEmpty = (array) => arrayLength(array) == 0;
|
|
11
|
-
const arrayReduce = (array, cb, initial) => array.reduce(cb, initial);
|
|
12
|
-
const arraySlice = (array, start, end) => array.slice(start, end);
|
|
13
|
-
const arrayPush = (array, ...values) => array.push(...values);
|
|
14
|
-
|
|
15
1
|
const getTypeOf = (thing) => typeof thing;
|
|
16
2
|
const EMPTY_STRING = '';
|
|
17
3
|
const STRING = getTypeOf(EMPTY_STRING);
|
|
@@ -22,6 +8,25 @@ const SUM = 'sum';
|
|
|
22
8
|
const AVG = 'avg';
|
|
23
9
|
const MIN = 'min';
|
|
24
10
|
const MAX = 'max';
|
|
11
|
+
const LISTENER = 'Listener';
|
|
12
|
+
const RESULT = 'Result';
|
|
13
|
+
const GET = 'get';
|
|
14
|
+
const ADD = 'add';
|
|
15
|
+
const TABLE = 'Table';
|
|
16
|
+
const ROW_IDS = 'RowIds';
|
|
17
|
+
const SORTED_ROW_IDS = 'SortedRowIds';
|
|
18
|
+
const ROW = 'Row';
|
|
19
|
+
const CELL_IDS = 'CellIds';
|
|
20
|
+
const CELL = 'Cell';
|
|
21
|
+
|
|
22
|
+
const arrayEvery = (array, cb) => array.every(cb);
|
|
23
|
+
const arrayForEach = (array, cb) => array.forEach(cb);
|
|
24
|
+
const arraySum = (array) => arrayReduce(array, (i, j) => i + j, 0);
|
|
25
|
+
const arrayLength = (array) => array.length;
|
|
26
|
+
const arrayIsEmpty = (array) => arrayLength(array) == 0;
|
|
27
|
+
const arrayReduce = (array, cb, initial) => array.reduce(cb, initial);
|
|
28
|
+
const arraySlice = (array, start, end) => array.slice(start, end);
|
|
29
|
+
const arrayPush = (array, ...values) => array.push(...values);
|
|
25
30
|
|
|
26
31
|
const mathMax = Math.max;
|
|
27
32
|
const mathMin = Math.min;
|
|
@@ -50,7 +55,7 @@ const mapSet = (map, key, value) =>
|
|
|
50
55
|
isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
|
|
51
56
|
const mapEnsure = (map, key, getDefaultValue) => {
|
|
52
57
|
if (!collHas(map, key)) {
|
|
53
|
-
map
|
|
58
|
+
mapSet(map, key, getDefaultValue());
|
|
54
59
|
}
|
|
55
60
|
return mapGet(map, key);
|
|
56
61
|
};
|
|
@@ -307,12 +312,12 @@ const getCreateFunction = (getFunction) => {
|
|
|
307
312
|
};
|
|
308
313
|
|
|
309
314
|
const object = Object;
|
|
310
|
-
const objIds = object.keys;
|
|
311
315
|
const objFreeze = object.freeze;
|
|
312
|
-
|
|
313
|
-
|
|
316
|
+
const objForEach = (obj, cb) =>
|
|
317
|
+
arrayForEach(object.entries(obj), ([id, value]) => cb(value, id));
|
|
314
318
|
|
|
315
319
|
const createQueries = getCreateFunction((store) => {
|
|
320
|
+
const createStore = store.createStore;
|
|
316
321
|
const [
|
|
317
322
|
getStore,
|
|
318
323
|
getQueryIds,
|
|
@@ -328,25 +333,26 @@ const createQueries = getCreateFunction((store) => {
|
|
|
328
333
|
addStoreListeners,
|
|
329
334
|
delStoreListeners,
|
|
330
335
|
] = getDefinableFunctions(store, () => true, getUndefined);
|
|
331
|
-
const
|
|
332
|
-
const
|
|
333
|
-
const resultStore = store.createStore();
|
|
336
|
+
const preStore = createStore();
|
|
337
|
+
const resultStore = createStore();
|
|
334
338
|
const preStoreListenerIds = mapNew();
|
|
335
|
-
const addPreStoreListener = (
|
|
339
|
+
const addPreStoreListener = (preStore2, queryId, ...listenerIds) =>
|
|
336
340
|
arrayForEach(listenerIds, (listenerId) =>
|
|
337
341
|
setAdd(
|
|
338
342
|
mapEnsure(
|
|
339
343
|
mapEnsure(preStoreListenerIds, queryId, mapNew),
|
|
340
|
-
|
|
344
|
+
preStore2,
|
|
341
345
|
setNew,
|
|
342
346
|
),
|
|
343
347
|
listenerId,
|
|
344
348
|
),
|
|
345
349
|
);
|
|
350
|
+
const cleanPreStores = (queryId) =>
|
|
351
|
+
arrayForEach([resultStore, preStore], (store2) => store2.delTable(queryId));
|
|
346
352
|
const synchronizeTransactions = (queryId, fromStore, toStore) =>
|
|
347
|
-
|
|
353
|
+
addPreStoreListener(
|
|
354
|
+
fromStore,
|
|
348
355
|
queryId,
|
|
349
|
-
0,
|
|
350
356
|
fromStore.addWillFinishTransactionListener(toStore.startTransaction),
|
|
351
357
|
fromStore.addDidFinishTransactionListener(() =>
|
|
352
358
|
toStore.finishTransaction(),
|
|
@@ -354,16 +360,12 @@ const createQueries = getCreateFunction((store) => {
|
|
|
354
360
|
);
|
|
355
361
|
const setQueryDefinition = (queryId, tableId, build) => {
|
|
356
362
|
setDefinition(queryId, tableId);
|
|
357
|
-
|
|
358
|
-
preStore2.delTable(queryId);
|
|
359
|
-
resultStore.delTable(queryId);
|
|
360
|
-
let offsetLimit;
|
|
363
|
+
cleanPreStores(queryId);
|
|
361
364
|
const selectEntries = [];
|
|
362
365
|
const joinEntries = [[null, [tableId, null, null, [], mapNew()]]];
|
|
363
366
|
const wheres = [];
|
|
364
367
|
const groupEntries = [];
|
|
365
368
|
const havings = [];
|
|
366
|
-
const orders = [];
|
|
367
369
|
const select = (arg1, arg2) => {
|
|
368
370
|
const selectEntry = isFunction(arg1)
|
|
369
371
|
? [arrayLength(selectEntries) + EMPTY_STRING, arg1]
|
|
@@ -429,17 +431,7 @@ const createQueries = getCreateFunction((store) => {
|
|
|
429
431
|
: (getSelectedOrGroupedCell) =>
|
|
430
432
|
getSelectedOrGroupedCell(arg1) === arg2,
|
|
431
433
|
);
|
|
432
|
-
|
|
433
|
-
arrayPush(orders, [
|
|
434
|
-
isFunction(arg1)
|
|
435
|
-
? arg1
|
|
436
|
-
: (getSelectedOrGroupedCell) => getSelectedOrGroupedCell(arg1) ?? 0,
|
|
437
|
-
descending,
|
|
438
|
-
]);
|
|
439
|
-
const limit = (arg1, arg2) => {
|
|
440
|
-
offsetLimit = isUndefined(arg2) ? [0, arg1] : [arg1, arg2];
|
|
441
|
-
};
|
|
442
|
-
build({select, join, where, group, having, order, limit});
|
|
434
|
+
build({select, join, where, group, having});
|
|
443
435
|
const selects = mapNew(selectEntries);
|
|
444
436
|
if (collIsEmpty(selects)) {
|
|
445
437
|
return queries;
|
|
@@ -451,95 +443,11 @@ const createQueries = getCreateFunction((store) => {
|
|
|
451
443
|
),
|
|
452
444
|
);
|
|
453
445
|
const groups = mapNew(groupEntries);
|
|
454
|
-
let selectJoinWhereStore =
|
|
455
|
-
let groupHavingStore = preStore2;
|
|
456
|
-
if (arrayIsEmpty(orders) && isUndefined(offsetLimit)) {
|
|
457
|
-
groupHavingStore = resultStore;
|
|
458
|
-
} else {
|
|
459
|
-
synchronizeTransactions(queryId, groupHavingStore, resultStore);
|
|
460
|
-
const groupRowIdSorter = (rowId1, rowId2) => {
|
|
461
|
-
const sortKeys1 = mapGet(sortKeysByGroupRowId, rowId1) ?? [];
|
|
462
|
-
const sortKeys2 = mapGet(sortKeysByGroupRowId, rowId2) ?? [];
|
|
463
|
-
const orderIndex = orders.findIndex(
|
|
464
|
-
(_order, index) => sortKeys1[index] !== sortKeys2[index],
|
|
465
|
-
);
|
|
466
|
-
return orderIndex < 0
|
|
467
|
-
? 0
|
|
468
|
-
: defaultSorter(sortKeys1[orderIndex], sortKeys2[orderIndex]) *
|
|
469
|
-
(orders[orderIndex][1] ? -1 : 1);
|
|
470
|
-
};
|
|
471
|
-
const sortKeysByGroupRowId = mapNew();
|
|
472
|
-
const sortedGroupRowIds = mapNew();
|
|
473
|
-
addPreStoreListener(
|
|
474
|
-
groupHavingStore,
|
|
475
|
-
queryId,
|
|
476
|
-
arrayIsEmpty(orders)
|
|
477
|
-
? groupHavingStore.addRowIdsListener(queryId, () =>
|
|
478
|
-
collClear(sortedGroupRowIds),
|
|
479
|
-
)
|
|
480
|
-
: groupHavingStore.addRowListener(
|
|
481
|
-
queryId,
|
|
482
|
-
null,
|
|
483
|
-
(_store, _tableId, groupRowId) => {
|
|
484
|
-
let newSortKeys = null;
|
|
485
|
-
if (groupHavingStore.hasRow(queryId, groupRowId)) {
|
|
486
|
-
const oldSortKeys =
|
|
487
|
-
mapGet(sortKeysByGroupRowId, groupRowId) ?? [];
|
|
488
|
-
const groupRow = groupHavingStore.getRow(queryId, groupRowId);
|
|
489
|
-
const getCell = (getSelectedOrGroupedCell) =>
|
|
490
|
-
groupRow[getSelectedOrGroupedCell];
|
|
491
|
-
newSortKeys = arrayMap(orders, ([getSortKey]) =>
|
|
492
|
-
getSortKey(getCell, groupRowId),
|
|
493
|
-
);
|
|
494
|
-
if (arrayIsEqual(oldSortKeys, newSortKeys)) {
|
|
495
|
-
if (mapGet(sortedGroupRowIds, groupRowId)) {
|
|
496
|
-
resultStore.setRow(queryId, groupRowId, groupRow);
|
|
497
|
-
}
|
|
498
|
-
return;
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
mapSet(sortKeysByGroupRowId, groupRowId, newSortKeys);
|
|
502
|
-
collClear(sortedGroupRowIds);
|
|
503
|
-
},
|
|
504
|
-
),
|
|
505
|
-
groupHavingStore.addTableListener(queryId, () => {
|
|
506
|
-
if (collIsEmpty(sortedGroupRowIds)) {
|
|
507
|
-
resultStore.delTable(queryId);
|
|
508
|
-
if (groupHavingStore.hasTable(queryId)) {
|
|
509
|
-
const groupTable = groupHavingStore.getTable(queryId);
|
|
510
|
-
arrayForEach(
|
|
511
|
-
arraySort(objIds(groupTable), groupRowIdSorter),
|
|
512
|
-
(id) => mapSet(sortedGroupRowIds, id, 0),
|
|
513
|
-
);
|
|
514
|
-
arrayForEach(
|
|
515
|
-
ifNotUndefined(
|
|
516
|
-
offsetLimit,
|
|
517
|
-
([offset, limit2]) =>
|
|
518
|
-
arraySlice(
|
|
519
|
-
mapKeys(sortedGroupRowIds),
|
|
520
|
-
offset,
|
|
521
|
-
offset + limit2,
|
|
522
|
-
),
|
|
523
|
-
() => mapKeys(sortedGroupRowIds),
|
|
524
|
-
),
|
|
525
|
-
(groupRowId) => {
|
|
526
|
-
resultStore.setRow(
|
|
527
|
-
queryId,
|
|
528
|
-
groupRowId,
|
|
529
|
-
groupTable[groupRowId],
|
|
530
|
-
);
|
|
531
|
-
mapSet(sortedGroupRowIds, groupRowId, 1);
|
|
532
|
-
},
|
|
533
|
-
);
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
}),
|
|
537
|
-
);
|
|
538
|
-
}
|
|
446
|
+
let selectJoinWhereStore = preStore;
|
|
539
447
|
if (collIsEmpty(groups) && arrayIsEmpty(havings)) {
|
|
540
|
-
selectJoinWhereStore =
|
|
448
|
+
selectJoinWhereStore = resultStore;
|
|
541
449
|
} else {
|
|
542
|
-
synchronizeTransactions(queryId, selectJoinWhereStore,
|
|
450
|
+
synchronizeTransactions(queryId, selectJoinWhereStore, resultStore);
|
|
543
451
|
const groupedSelectedCellIds = mapNew();
|
|
544
452
|
mapForEach(groups, (groupedCellId, [selectedCellId, aggregators]) =>
|
|
545
453
|
setAdd(mapEnsure(groupedSelectedCellIds, selectedCellId, setNew), [
|
|
@@ -601,8 +509,8 @@ const createQueries = getCreateFunction((store) => {
|
|
|
601
509
|
!arrayEvery(havings, (having2) =>
|
|
602
510
|
having2((cellId) => groupRow[cellId]),
|
|
603
511
|
)
|
|
604
|
-
?
|
|
605
|
-
:
|
|
512
|
+
? resultStore.delRow
|
|
513
|
+
: resultStore.setRow)(queryId, groupRowId, groupRow);
|
|
606
514
|
},
|
|
607
515
|
);
|
|
608
516
|
addPreStoreListener(
|
|
@@ -649,7 +557,7 @@ const createQueries = getCreateFunction((store) => {
|
|
|
649
557
|
([, selectedRowIds, groupRowId]) => {
|
|
650
558
|
collDel(selectedRowIds, selectedRowId);
|
|
651
559
|
if (collIsEmpty(selectedRowIds)) {
|
|
652
|
-
|
|
560
|
+
resultStore.delRow(queryId, groupRowId);
|
|
653
561
|
return 1;
|
|
654
562
|
}
|
|
655
563
|
},
|
|
@@ -679,7 +587,7 @@ const createQueries = getCreateFunction((store) => {
|
|
|
679
587
|
return [
|
|
680
588
|
mapNew(),
|
|
681
589
|
setNew(),
|
|
682
|
-
|
|
590
|
+
resultStore.addRow(queryId, groupRow, 1),
|
|
683
591
|
groupRow,
|
|
684
592
|
];
|
|
685
593
|
},
|
|
@@ -786,56 +694,15 @@ const createQueries = getCreateFunction((store) => {
|
|
|
786
694
|
return queries;
|
|
787
695
|
};
|
|
788
696
|
const delQueryDefinition = (queryId) => {
|
|
789
|
-
mapForEach(mapGet(preStoreListenerIds, queryId), (
|
|
697
|
+
mapForEach(mapGet(preStoreListenerIds, queryId), (preStore2, listenerIds) =>
|
|
790
698
|
collForEach(listenerIds, (listenerId) =>
|
|
791
|
-
|
|
699
|
+
preStore2.delListener(listenerId),
|
|
792
700
|
),
|
|
793
701
|
);
|
|
702
|
+
cleanPreStores(queryId);
|
|
794
703
|
delDefinition(queryId);
|
|
795
704
|
return queries;
|
|
796
705
|
};
|
|
797
|
-
const getResultTable = (queryId) => resultStore.getTable(queryId);
|
|
798
|
-
const getResultRowIds = (queryId) => resultStore.getRowIds(queryId);
|
|
799
|
-
const getResultRow = (queryId, rowId) => resultStore.getRow(queryId, rowId);
|
|
800
|
-
const getResultCellIds = (queryId, rowId) =>
|
|
801
|
-
resultStore.getCellIds(queryId, rowId);
|
|
802
|
-
const getResultCell = (queryId, rowId, cellId) =>
|
|
803
|
-
resultStore.getCell(queryId, rowId, cellId);
|
|
804
|
-
const hasResultTable = (queryId) => resultStore.hasTable(queryId);
|
|
805
|
-
const hasResultRow = (queryId, rowId) => resultStore.hasRow(queryId, rowId);
|
|
806
|
-
const hasResultCell = (queryId, rowId, cellId) =>
|
|
807
|
-
resultStore.hasCell(queryId, rowId, cellId);
|
|
808
|
-
const forEachResultTable = (tableCallback) =>
|
|
809
|
-
resultStore.forEachTable(tableCallback);
|
|
810
|
-
const forEachResultRow = (queryId, rowCallback) =>
|
|
811
|
-
resultStore.forEachRow(queryId, rowCallback);
|
|
812
|
-
const forEachResultCell = (queryId, rowId, cellCallback) =>
|
|
813
|
-
resultStore.forEachCell(queryId, rowId, cellCallback);
|
|
814
|
-
const addResultTableListener = (queryId, listener) =>
|
|
815
|
-
resultStore.addTableListener(queryId, (_store, ...args) =>
|
|
816
|
-
listener(queries, ...args),
|
|
817
|
-
);
|
|
818
|
-
const addResultRowIdsListener = (queryId, listener, trackReorder) =>
|
|
819
|
-
resultStore.addRowIdsListener(
|
|
820
|
-
queryId,
|
|
821
|
-
(_store, ...args) => listener(queries, ...args),
|
|
822
|
-
trackReorder,
|
|
823
|
-
);
|
|
824
|
-
const addResultRowListener = (queryId, rowId, listener) =>
|
|
825
|
-
resultStore.addRowListener(queryId, rowId, (_store, ...args) =>
|
|
826
|
-
listener(queries, ...args),
|
|
827
|
-
);
|
|
828
|
-
const addResultCellIdsListener = (queryId, rowId, listener, trackReorder) =>
|
|
829
|
-
resultStore.addCellIdsListener(
|
|
830
|
-
queryId,
|
|
831
|
-
rowId,
|
|
832
|
-
(_store, ...args) => listener(queries, ...args),
|
|
833
|
-
trackReorder,
|
|
834
|
-
);
|
|
835
|
-
const addResultCellListener = (queryId, rowId, cellId, listener) =>
|
|
836
|
-
resultStore.addCellListener(queryId, rowId, cellId, (_store, ...args) =>
|
|
837
|
-
listener(queries, ...args),
|
|
838
|
-
);
|
|
839
706
|
const delListener = (listenerId) => {
|
|
840
707
|
resultStore.delListener(listenerId);
|
|
841
708
|
return queries;
|
|
@@ -857,26 +724,34 @@ const createQueries = getCreateFunction((store) => {
|
|
|
857
724
|
forEachQuery,
|
|
858
725
|
hasQuery,
|
|
859
726
|
getTableId,
|
|
860
|
-
getResultTable,
|
|
861
|
-
getResultRowIds,
|
|
862
|
-
getResultRow,
|
|
863
|
-
getResultCellIds,
|
|
864
|
-
getResultCell,
|
|
865
|
-
hasResultTable,
|
|
866
|
-
hasResultRow,
|
|
867
|
-
hasResultCell,
|
|
868
|
-
forEachResultTable,
|
|
869
|
-
forEachResultRow,
|
|
870
|
-
forEachResultCell,
|
|
871
|
-
addResultTableListener,
|
|
872
|
-
addResultRowIdsListener,
|
|
873
|
-
addResultRowListener,
|
|
874
|
-
addResultCellIdsListener,
|
|
875
|
-
addResultCellListener,
|
|
876
727
|
delListener,
|
|
877
728
|
destroy,
|
|
878
729
|
getListenerStats,
|
|
879
730
|
};
|
|
731
|
+
objForEach(
|
|
732
|
+
{
|
|
733
|
+
[TABLE]: [1, 1],
|
|
734
|
+
[ROW_IDS]: [0, 1],
|
|
735
|
+
[SORTED_ROW_IDS]: [0, 5],
|
|
736
|
+
[ROW]: [1, 2],
|
|
737
|
+
[CELL_IDS]: [0, 2],
|
|
738
|
+
[CELL]: [1, 3],
|
|
739
|
+
},
|
|
740
|
+
([hasAndForEach, argumentCount], gettable) => {
|
|
741
|
+
arrayForEach(
|
|
742
|
+
hasAndForEach ? [GET, 'has', 'forEach'] : [GET],
|
|
743
|
+
(prefix) =>
|
|
744
|
+
(queries[prefix + RESULT + gettable] = (...args) =>
|
|
745
|
+
resultStore[prefix + gettable](...args)),
|
|
746
|
+
);
|
|
747
|
+
queries[ADD + RESULT + gettable + LISTENER] = (...args) =>
|
|
748
|
+
resultStore[ADD + gettable + LISTENER](
|
|
749
|
+
...arraySlice(args, 0, argumentCount),
|
|
750
|
+
(_store, ...listenerArgs) =>
|
|
751
|
+
args[argumentCount](queries, ...listenerArgs),
|
|
752
|
+
);
|
|
753
|
+
},
|
|
754
|
+
);
|
|
880
755
|
return objFreeze(queries);
|
|
881
756
|
});
|
|
882
757
|
|
|
@@ -137,17 +137,18 @@ export type LinkedRowIdsListener = (
|
|
|
137
137
|
*/
|
|
138
138
|
export type RelationshipsListenerStats = {
|
|
139
139
|
/**
|
|
140
|
-
* The number of
|
|
141
|
-
* object.
|
|
140
|
+
* The number of RemoteRowIdListener functions registered with the
|
|
141
|
+
* Relationships object.
|
|
142
142
|
*/
|
|
143
143
|
remoteRowId?: number;
|
|
144
144
|
/**
|
|
145
|
-
* The number of
|
|
146
|
-
* object.
|
|
145
|
+
* The number of LocalRowIdsListener functions registered with the
|
|
146
|
+
* Relationships object.
|
|
147
147
|
*/
|
|
148
148
|
localRowIds?: number;
|
|
149
149
|
/**
|
|
150
|
-
* The number of
|
|
150
|
+
* The number of LinkedRowId functions registered with the Relationships
|
|
151
|
+
* object.
|
|
151
152
|
*/
|
|
152
153
|
linkedRowIds?: number;
|
|
153
154
|
};
|
|
@@ -2,7 +2,6 @@ const getTypeOf = (thing) => typeof thing;
|
|
|
2
2
|
const EMPTY_STRING = '';
|
|
3
3
|
const STRING = getTypeOf(EMPTY_STRING);
|
|
4
4
|
|
|
5
|
-
const arrayEvery = (array, cb) => array.every(cb);
|
|
6
5
|
const arrayForEach = (array, cb) => array.forEach(cb);
|
|
7
6
|
const arrayLength = (array) => array.length;
|
|
8
7
|
const arrayIsEmpty = (array) => arrayLength(array) == 0;
|
|
@@ -36,7 +35,7 @@ const mapSet = (map, key, value) =>
|
|
|
36
35
|
isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
|
|
37
36
|
const mapEnsure = (map, key, getDefaultValue) => {
|
|
38
37
|
if (!collHas(map, key)) {
|
|
39
|
-
map
|
|
38
|
+
mapSet(map, key, getDefaultValue());
|
|
40
39
|
}
|
|
41
40
|
return mapGet(map, key);
|
|
42
41
|
};
|
|
@@ -217,32 +216,32 @@ const getCreateFunction = (getFunction) => {
|
|
|
217
216
|
};
|
|
218
217
|
|
|
219
218
|
const getWildcardedLeaves = (deepIdSet, path = [EMPTY_STRING]) => {
|
|
220
|
-
const
|
|
221
|
-
const deep = (
|
|
219
|
+
const leaves = [];
|
|
220
|
+
const deep = (node, p) =>
|
|
222
221
|
p == arrayLength(path)
|
|
223
|
-
? arrayPush(
|
|
224
|
-
:
|
|
222
|
+
? arrayPush(leaves, node)
|
|
223
|
+
: path[p] === null
|
|
224
|
+
? collForEach(node, (node2) => deep(node2, p + 1))
|
|
225
|
+
: arrayForEach([path[p], null], (id) => deep(mapGet(node, id), p + 1));
|
|
225
226
|
deep(deepIdSet, 0);
|
|
226
|
-
return
|
|
227
|
+
return leaves;
|
|
227
228
|
};
|
|
228
229
|
const getListenerFunctions = (getThing) => {
|
|
229
230
|
let thing;
|
|
230
231
|
let nextId = 0;
|
|
231
232
|
const listenerPool = [];
|
|
232
233
|
const allListeners = mapNew();
|
|
233
|
-
const addListener = (listener, idSetNode,
|
|
234
|
+
const addListener = (listener, idSetNode, path) => {
|
|
234
235
|
thing ??= getThing();
|
|
235
236
|
const id = arrayPop(listenerPool) ?? EMPTY_STRING + nextId++;
|
|
236
|
-
mapSet(allListeners, id, [listener, idSetNode,
|
|
237
|
-
setAdd(visitTree(idSetNode,
|
|
237
|
+
mapSet(allListeners, id, [listener, idSetNode, path]);
|
|
238
|
+
setAdd(visitTree(idSetNode, path ?? [EMPTY_STRING], setNew), id);
|
|
238
239
|
return id;
|
|
239
240
|
};
|
|
240
241
|
const callListeners = (idSetNode, ids, ...extraArgs) =>
|
|
241
242
|
arrayForEach(getWildcardedLeaves(idSetNode, ids), (set) =>
|
|
242
243
|
collForEach(set, (id) =>
|
|
243
|
-
|
|
244
|
-
listener(thing, ...(ids ?? []), ...extraArgs),
|
|
245
|
-
),
|
|
244
|
+
mapGet(allListeners, id)[0](thing, ...(ids ?? []), ...extraArgs),
|
|
246
245
|
),
|
|
247
246
|
);
|
|
248
247
|
const delListener = (id) =>
|
|
@@ -257,8 +256,6 @@ const getListenerFunctions = (getThing) => {
|
|
|
257
256
|
}
|
|
258
257
|
return idOrNulls;
|
|
259
258
|
});
|
|
260
|
-
const hasListeners = (idSetNode, ids) =>
|
|
261
|
-
!arrayEvery(getWildcardedLeaves(idSetNode, ids), isUndefined);
|
|
262
259
|
const callListener = (id, idNullGetters, extraArgsGetter) =>
|
|
263
260
|
ifNotUndefined(mapGet(allListeners, id), ([listener, , idOrNulls = []]) => {
|
|
264
261
|
const callWithIds = (...ids) => {
|
|
@@ -273,7 +270,7 @@ const getListenerFunctions = (getThing) => {
|
|
|
273
270
|
};
|
|
274
271
|
callWithIds();
|
|
275
272
|
});
|
|
276
|
-
return [addListener, callListeners, delListener,
|
|
273
|
+
return [addListener, callListeners, delListener, callListener];
|
|
277
274
|
};
|
|
278
275
|
|
|
279
276
|
const object = Object;
|