tinybase 8.3.0-beta.0 → 8.3.0-beta.1
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/@types/queries/index.d.ts +141 -0
- package/@types/queries/with-schemas/index.d.ts +184 -0
- package/index.js +594 -418
- package/indexes/index.js +8 -22
- package/indexes/with-schemas/index.js +8 -22
- package/metrics/index.js +8 -22
- package/metrics/with-schemas/index.js +8 -22
- package/min/index.js +1 -1
- package/min/index.js.gz +0 -0
- package/min/indexes/index.js +1 -1
- package/min/indexes/index.js.gz +0 -0
- package/min/indexes/with-schemas/index.js +1 -1
- package/min/indexes/with-schemas/index.js.gz +0 -0
- package/min/metrics/index.js +1 -1
- package/min/metrics/index.js.gz +0 -0
- package/min/metrics/with-schemas/index.js +1 -1
- package/min/metrics/with-schemas/index.js.gz +0 -0
- package/min/omni/index.js +1 -1
- package/min/omni/index.js.gz +0 -0
- package/min/omni/with-schemas/index.js +1 -1
- package/min/omni/with-schemas/index.js.gz +0 -0
- package/min/queries/index.js +1 -1
- package/min/queries/index.js.gz +0 -0
- package/min/queries/with-schemas/index.js +1 -1
- package/min/queries/with-schemas/index.js.gz +0 -0
- package/min/relationships/index.js +1 -1
- package/min/relationships/index.js.gz +0 -0
- package/min/relationships/with-schemas/index.js +1 -1
- package/min/relationships/with-schemas/index.js.gz +0 -0
- package/min/with-schemas/index.js +1 -1
- package/min/with-schemas/index.js.gz +0 -0
- package/omni/index.js +594 -418
- package/omni/with-schemas/index.js +594 -418
- package/package.json +10 -10
- package/queries/index.js +596 -454
- package/queries/with-schemas/index.js +596 -454
- package/readme.md +14 -14
- package/relationships/index.js +8 -22
- package/relationships/with-schemas/index.js +8 -22
- package/releases.md +51 -51
- package/ui-svelte/index.js +1 -1
- package/ui-svelte/with-schemas/index.js +1 -1
- package/ui-svelte-dom/index.js +2 -2
- package/ui-svelte-dom/with-schemas/index.js +2 -2
- package/ui-svelte-inspector/index.js +2 -2
- package/ui-svelte-inspector/with-schemas/index.js +2 -2
- package/with-schemas/index.js +594 -418
package/index.js
CHANGED
|
@@ -85,10 +85,6 @@ const arrayEvery = (array, cb) => array.every(cb);
|
|
|
85
85
|
const arrayIsEqual = (array1, array2) =>
|
|
86
86
|
size(array1) === size(array2) &&
|
|
87
87
|
arrayEvery(array1, (value1, index) => array2[index] === value1);
|
|
88
|
-
const arrayOrValueEqual = (value1, value2) =>
|
|
89
|
-
isArray(value1) && isArray(value2)
|
|
90
|
-
? arrayIsEqual(value1, value2)
|
|
91
|
-
: value1 === value2;
|
|
92
88
|
const arrayIsSorted = (array, sorter) =>
|
|
93
89
|
arrayEvery(
|
|
94
90
|
array,
|
|
@@ -143,7 +139,6 @@ const objDel = (obj, id) => {
|
|
|
143
139
|
delete obj[id];
|
|
144
140
|
return obj;
|
|
145
141
|
};
|
|
146
|
-
const objToMap = (obj) => new Map(objEntries(obj));
|
|
147
142
|
const objForEach = (obj, cb) =>
|
|
148
143
|
arrayForEach(objEntries(obj), ([id, value]) => cb(value, id));
|
|
149
144
|
const objToArray = (obj, cb) =>
|
|
@@ -303,27 +298,17 @@ const getDefinableFunctions = (
|
|
|
303
298
|
const getTableId = (id) => mapGet(tableIds, id);
|
|
304
299
|
const getThing = (id) => mapGet(things, id);
|
|
305
300
|
const setThing = (id, thing) => mapSet(things, id, thing);
|
|
306
|
-
const addStoreListeners = (id,
|
|
301
|
+
const addStoreListeners = (id, ...listenerIds) => {
|
|
307
302
|
const set = mapEnsure(storeListenerIds, id, setNew);
|
|
308
|
-
arrayForEach(
|
|
309
|
-
listenerIds,
|
|
310
|
-
(listenerId) =>
|
|
311
|
-
setAdd(set, listenerId) && andCall && store.callListener(listenerId),
|
|
312
|
-
);
|
|
313
|
-
return listenerIds;
|
|
303
|
+
arrayForEach(listenerIds, (listenerId) => setAdd(set, listenerId));
|
|
314
304
|
};
|
|
315
|
-
const delStoreListeners = (id
|
|
305
|
+
const delStoreListeners = (id) =>
|
|
316
306
|
ifNotUndefined(mapGet(storeListenerIds, id), (allListenerIds) => {
|
|
317
|
-
arrayForEach(
|
|
318
|
-
|
|
319
|
-
(listenerId)
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
},
|
|
323
|
-
);
|
|
324
|
-
if (collIsEmpty(allListenerIds)) {
|
|
325
|
-
mapSet(storeListenerIds, id);
|
|
326
|
-
}
|
|
307
|
+
arrayForEach(collValues(allListenerIds), (listenerId) => {
|
|
308
|
+
store.delListener(listenerId);
|
|
309
|
+
collDel(allListenerIds, listenerId);
|
|
310
|
+
});
|
|
311
|
+
mapSet(storeListenerIds, id);
|
|
327
312
|
});
|
|
328
313
|
const setDefinition = (id, tableId) => {
|
|
329
314
|
mapSet(tableIds, id, tableId);
|
|
@@ -403,7 +388,6 @@ const getDefinableFunctions = (
|
|
|
403
388
|
delStoreListeners(id);
|
|
404
389
|
addStoreListeners(
|
|
405
390
|
id,
|
|
406
|
-
0,
|
|
407
391
|
store.addRowListener(tableId, null, (_store, _tableId, rowId) =>
|
|
408
392
|
processRow(rowId),
|
|
409
393
|
),
|
|
@@ -434,8 +418,6 @@ const getDefinableFunctions = (
|
|
|
434
418
|
delDefinition,
|
|
435
419
|
addThingIdsListener,
|
|
436
420
|
destroy,
|
|
437
|
-
addStoreListeners,
|
|
438
|
-
delStoreListeners,
|
|
439
421
|
];
|
|
440
422
|
};
|
|
441
423
|
const getRowCellFunction = (getRowCell, defaultCellValue) =>
|
|
@@ -3764,13 +3746,29 @@ const createMiddleware = getCreateFunction((store) => {
|
|
|
3764
3746
|
return middleware;
|
|
3765
3747
|
});
|
|
3766
3748
|
|
|
3749
|
+
const PARAMS_TABLE = '_';
|
|
3750
|
+
const PARAM_LISTENER_PREFIX = 'p';
|
|
3767
3751
|
const createQueries = getCreateFunction((store) => {
|
|
3768
3752
|
const createStore = store._[0];
|
|
3769
3753
|
const preStore = createStore();
|
|
3754
|
+
const paramStore = createStore();
|
|
3770
3755
|
const resultStore = createStore();
|
|
3756
|
+
const resultStores = mapNew();
|
|
3757
|
+
const redefiningQueryIds = setNew();
|
|
3758
|
+
const routedResultListeners = mapNew();
|
|
3759
|
+
const routedResultListenerIds = mapNew();
|
|
3760
|
+
const resultListenerStats = {
|
|
3761
|
+
table: 0,
|
|
3762
|
+
tableCellIds: 0,
|
|
3763
|
+
rowCount: 0,
|
|
3764
|
+
rowIds: 0,
|
|
3765
|
+
sortedRowIds: 0,
|
|
3766
|
+
row: 0,
|
|
3767
|
+
cellIds: 0,
|
|
3768
|
+
cell: 0,
|
|
3769
|
+
};
|
|
3771
3770
|
const preStoreListenerIds = mapNew();
|
|
3772
|
-
const
|
|
3773
|
-
const paramValueListeners = mapNew();
|
|
3771
|
+
const sourceStoreListenerIds = mapNew();
|
|
3774
3772
|
const {
|
|
3775
3773
|
_: [, addListener, callListeners],
|
|
3776
3774
|
delListener: delListenerImpl,
|
|
@@ -3787,9 +3785,7 @@ const createQueries = getCreateFunction((store) => {
|
|
|
3787
3785
|
,
|
|
3788
3786
|
delDefinition,
|
|
3789
3787
|
addQueryIdsListenerImpl,
|
|
3790
|
-
|
|
3791
|
-
addStoreListeners,
|
|
3792
|
-
delStoreListeners,
|
|
3788
|
+
destroyImpl,
|
|
3793
3789
|
] = getDefinableFunctions(
|
|
3794
3790
|
store,
|
|
3795
3791
|
() => [],
|
|
@@ -3797,6 +3793,8 @@ const createQueries = getCreateFunction((store) => {
|
|
|
3797
3793
|
addListener,
|
|
3798
3794
|
callListeners,
|
|
3799
3795
|
);
|
|
3796
|
+
const getResultStore = (queryId) =>
|
|
3797
|
+
mapEnsure(resultStores, queryId, createStore);
|
|
3800
3798
|
const addPreStoreListener = (preStore2, queryId, ...listenerIds) =>
|
|
3801
3799
|
arrayForEach(listenerIds, (listenerId) =>
|
|
3802
3800
|
setAdd(
|
|
@@ -3820,8 +3818,49 @@ const createQueries = getCreateFunction((store) => {
|
|
|
3820
3818
|
collClear(queryPreStoreListenerIds);
|
|
3821
3819
|
},
|
|
3822
3820
|
);
|
|
3823
|
-
arrayForEach([
|
|
3821
|
+
arrayForEach([getResultStore(queryId), preStore], (store2) =>
|
|
3822
|
+
store2.delTable(queryId),
|
|
3823
|
+
);
|
|
3824
|
+
};
|
|
3825
|
+
const addSourceStoreListeners = (
|
|
3826
|
+
sourceStore,
|
|
3827
|
+
queryId,
|
|
3828
|
+
andCall,
|
|
3829
|
+
...listenerIds
|
|
3830
|
+
) => {
|
|
3831
|
+
const listenerIdSet = mapEnsure(
|
|
3832
|
+
mapEnsure(sourceStoreListenerIds, queryId, mapNew),
|
|
3833
|
+
sourceStore,
|
|
3834
|
+
setNew,
|
|
3835
|
+
);
|
|
3836
|
+
arrayForEach(listenerIds, (listenerId) => {
|
|
3837
|
+
setAdd(listenerIdSet, listenerId);
|
|
3838
|
+
if (andCall) {
|
|
3839
|
+
sourceStore.callListener(listenerId);
|
|
3840
|
+
}
|
|
3841
|
+
});
|
|
3842
|
+
return listenerIds;
|
|
3824
3843
|
};
|
|
3844
|
+
const delSourceStoreListeners = (queryId, sourceStore, listenerId) =>
|
|
3845
|
+
ifNotUndefined(
|
|
3846
|
+
mapGet(mapGet(sourceStoreListenerIds, queryId), sourceStore),
|
|
3847
|
+
(allListenerIds) => {
|
|
3848
|
+
sourceStore.delListener(listenerId);
|
|
3849
|
+
collDel(allListenerIds, listenerId);
|
|
3850
|
+
if (collIsEmpty(allListenerIds)) {
|
|
3851
|
+
mapSet(mapGet(sourceStoreListenerIds, queryId), sourceStore);
|
|
3852
|
+
}
|
|
3853
|
+
},
|
|
3854
|
+
);
|
|
3855
|
+
const resetSourceStores = (queryId) =>
|
|
3856
|
+
ifNotUndefined(mapGet(sourceStoreListenerIds, queryId), (queryStoreIds) => {
|
|
3857
|
+
mapForEach(queryStoreIds, (sourceStore, listenerIds) =>
|
|
3858
|
+
collForEach(listenerIds, (listenerId) =>
|
|
3859
|
+
sourceStore.delListener(listenerId),
|
|
3860
|
+
),
|
|
3861
|
+
);
|
|
3862
|
+
collClear(queryStoreIds);
|
|
3863
|
+
});
|
|
3825
3864
|
const synchronizeTransactions = (queryId, fromStore, toStore) =>
|
|
3826
3865
|
addPreStoreListener(
|
|
3827
3866
|
fromStore,
|
|
@@ -3831,424 +3870,549 @@ const createQueries = getCreateFunction((store) => {
|
|
|
3831
3870
|
toStore.finishTransaction(),
|
|
3832
3871
|
),
|
|
3833
3872
|
);
|
|
3834
|
-
const
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
resetPreStores(queryId);
|
|
3840
|
-
const [, paramsMap] = getQueryArgs(queryId);
|
|
3841
|
-
const selectEntries = [];
|
|
3842
|
-
const joinEntries = [[void 0, [tableId, void 0, void 0, [], mapNew()]]];
|
|
3843
|
-
const wheres = [];
|
|
3844
|
-
const groupEntries = [];
|
|
3845
|
-
const havings = [];
|
|
3846
|
-
const param = (paramId) => mapGet(paramsMap, paramId);
|
|
3847
|
-
const select = (arg1, arg2) => {
|
|
3848
|
-
const selectEntry = isFunction(arg1)
|
|
3849
|
-
? [size(selectEntries) + EMPTY_STRING, arg1]
|
|
3850
|
-
: [
|
|
3851
|
-
isUndefined(arg2) ? arg1 : arg2,
|
|
3852
|
-
(getTableCell) => getTableCell(arg1, arg2),
|
|
3853
|
-
];
|
|
3854
|
-
arrayPush(selectEntries, selectEntry);
|
|
3855
|
-
return {as: (selectedCellId) => (selectEntry[0] = selectedCellId)};
|
|
3856
|
-
};
|
|
3857
|
-
const join = (joinedTableId, arg1, arg2) => {
|
|
3858
|
-
const fromIntermediateJoinedTableId =
|
|
3859
|
-
isUndefined(arg2) || isFunction(arg1) ? void 0 : arg1;
|
|
3860
|
-
const onArg = isUndefined(fromIntermediateJoinedTableId) ? arg1 : arg2;
|
|
3861
|
-
const joinEntry = [
|
|
3862
|
-
joinedTableId,
|
|
3863
|
-
[
|
|
3864
|
-
joinedTableId,
|
|
3865
|
-
fromIntermediateJoinedTableId,
|
|
3866
|
-
isFunction(onArg) ? onArg : (getCell) => getCell(onArg),
|
|
3867
|
-
[],
|
|
3868
|
-
mapNew(),
|
|
3869
|
-
],
|
|
3870
|
-
];
|
|
3871
|
-
arrayPush(joinEntries, joinEntry);
|
|
3872
|
-
return {as: (joinedTableId2) => (joinEntry[0] = joinedTableId2)};
|
|
3873
|
-
};
|
|
3874
|
-
const where = (arg1, arg2, arg3) =>
|
|
3875
|
-
arrayPush(
|
|
3876
|
-
wheres,
|
|
3877
|
-
isFunction(arg1)
|
|
3878
|
-
? arg1
|
|
3879
|
-
: isUndefined(arg3)
|
|
3880
|
-
? (getTableCell) => getTableCell(arg1) === arg2
|
|
3881
|
-
: (getTableCell) => getTableCell(arg1, arg2) === arg3,
|
|
3882
|
-
);
|
|
3883
|
-
const group = (
|
|
3884
|
-
selectedCellId,
|
|
3885
|
-
aggregate,
|
|
3886
|
-
aggregateAdd,
|
|
3887
|
-
aggregateRemove,
|
|
3888
|
-
aggregateReplace,
|
|
3889
|
-
) => {
|
|
3890
|
-
const groupEntry = [
|
|
3891
|
-
selectedCellId,
|
|
3892
|
-
[
|
|
3893
|
-
selectedCellId,
|
|
3894
|
-
isFunction(aggregate)
|
|
3895
|
-
? [aggregate, aggregateAdd, aggregateRemove, aggregateReplace]
|
|
3896
|
-
: (mapGet(numericAggregators, aggregate) ?? [
|
|
3897
|
-
(_cells, length) => length,
|
|
3898
|
-
]),
|
|
3899
|
-
],
|
|
3900
|
-
];
|
|
3901
|
-
arrayPush(groupEntries, groupEntry);
|
|
3902
|
-
return {as: (groupedCellId) => (groupEntry[0] = groupedCellId)};
|
|
3903
|
-
};
|
|
3904
|
-
const having = (arg1, arg2) =>
|
|
3905
|
-
arrayPush(
|
|
3906
|
-
havings,
|
|
3907
|
-
isFunction(arg1)
|
|
3908
|
-
? arg1
|
|
3909
|
-
: (getSelectedOrGroupedCell) =>
|
|
3910
|
-
getSelectedOrGroupedCell(arg1) === arg2,
|
|
3911
|
-
);
|
|
3912
|
-
build({select, join, where, group, having, param});
|
|
3913
|
-
const selects = mapNew(selectEntries);
|
|
3914
|
-
if (collIsEmpty(selects)) {
|
|
3915
|
-
return queries;
|
|
3916
|
-
}
|
|
3917
|
-
const joins = mapNew(joinEntries);
|
|
3918
|
-
mapForEach(joins, (asTableId, [, fromAsTableId]) =>
|
|
3919
|
-
ifNotUndefined(mapGet(joins, fromAsTableId), ({3: toAsTableIds}) =>
|
|
3920
|
-
isUndefined(asTableId) ? 0 : arrayPush(toAsTableIds, asTableId),
|
|
3921
|
-
),
|
|
3873
|
+
const setOrDelParamValues = (queryId, paramValues) =>
|
|
3874
|
+
(objIsEmpty(paramValues) ? paramStore.delRow : paramStore.setRow)(
|
|
3875
|
+
PARAMS_TABLE,
|
|
3876
|
+
queryId,
|
|
3877
|
+
{...paramValues},
|
|
3922
3878
|
);
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3879
|
+
const addRoutedResultListener = (stat, queryId, addStoreListener) => {
|
|
3880
|
+
const listenerId = addListener(getUndefined, routedResultListenerIds);
|
|
3881
|
+
const storeListenerIds = mapNew();
|
|
3882
|
+
const syncStoreListeners = () => {
|
|
3883
|
+
const queryIds = queryId == null ? getQueryIds() : [queryId];
|
|
3884
|
+
arrayForEach(queryIds, (queryId2) =>
|
|
3885
|
+
collHas(storeListenerIds, queryId2)
|
|
3886
|
+
? 0
|
|
3887
|
+
: mapSet(storeListenerIds, queryId2, [
|
|
3888
|
+
getResultStore(queryId2),
|
|
3889
|
+
addStoreListener(getResultStore(queryId2), queryId2),
|
|
3890
|
+
]),
|
|
3935
3891
|
);
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
collHas(groupedSelectedCellIds, selectedCellId)
|
|
3892
|
+
mapForEach(storeListenerIds, (storeQueryId, [store2, storeListenerId]) =>
|
|
3893
|
+
(queryId == null && hasQuery(storeQueryId)) || storeQueryId == queryId
|
|
3939
3894
|
? 0
|
|
3940
|
-
:
|
|
3895
|
+
: (() => {
|
|
3896
|
+
store2.delListener(storeListenerId);
|
|
3897
|
+
mapSet(storeListenerIds, storeQueryId);
|
|
3898
|
+
})(),
|
|
3941
3899
|
);
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3900
|
+
};
|
|
3901
|
+
syncStoreListeners();
|
|
3902
|
+
mapSet(routedResultListeners, listenerId, [
|
|
3903
|
+
stat,
|
|
3904
|
+
storeListenerIds,
|
|
3905
|
+
queryId == null ? addQueryIdsListenerImpl(syncStoreListeners) : void 0,
|
|
3906
|
+
]);
|
|
3907
|
+
resultListenerStats[stat]++;
|
|
3908
|
+
return listenerId;
|
|
3909
|
+
};
|
|
3910
|
+
const setQueryDefinition = (
|
|
3911
|
+
queryId,
|
|
3912
|
+
tableIdOrAsQuery,
|
|
3913
|
+
tableIdOrBuild,
|
|
3914
|
+
buildOrParamValues,
|
|
3915
|
+
paramValuesIfSourceIsQuery = {},
|
|
3916
|
+
) => {
|
|
3917
|
+
const [tableId, build, sourceIsQuery, paramValues] = isTrue(
|
|
3918
|
+
tableIdOrAsQuery,
|
|
3919
|
+
)
|
|
3920
|
+
? [tableIdOrBuild, buildOrParamValues, 1, paramValuesIfSourceIsQuery]
|
|
3921
|
+
: [tableIdOrAsQuery, tableIdOrBuild, 0, buildOrParamValues ?? {}];
|
|
3922
|
+
ifNotUndefined(getQueryArgs(queryId), ([, listenerId]) =>
|
|
3923
|
+
paramStore.delListener(listenerId),
|
|
3924
|
+
);
|
|
3925
|
+
setDefinition(queryId, tableId);
|
|
3926
|
+
setQueryArgs(queryId, [
|
|
3927
|
+
build,
|
|
3928
|
+
paramStore.addRowListener(PARAMS_TABLE, queryId, () =>
|
|
3929
|
+
setQueryDefinitionImpl(queryId),
|
|
3930
|
+
),
|
|
3931
|
+
sourceIsQuery,
|
|
3932
|
+
]);
|
|
3933
|
+
setOrDelParamValues(queryId, paramValues);
|
|
3934
|
+
setQueryDefinitionImpl(queryId);
|
|
3935
|
+
return queries;
|
|
3936
|
+
};
|
|
3937
|
+
const setQueryDefinitionImpl = (queryId) =>
|
|
3938
|
+
getResultStore(queryId).transaction(() =>
|
|
3939
|
+
ifNotUndefined(getQueryArgs(queryId), ([build, , sourceIsQuery]) => {
|
|
3940
|
+
const tableId = getTableId(queryId);
|
|
3941
|
+
const rootStore = sourceIsQuery ? getResultStore(tableId) : store;
|
|
3942
|
+
const resultStore2 = getResultStore(queryId);
|
|
3943
|
+
const paramValues = getParamValues(queryId);
|
|
3944
|
+
setAdd(redefiningQueryIds, queryId);
|
|
3945
|
+
resetPreStores(queryId);
|
|
3946
|
+
resetSourceStores(queryId);
|
|
3947
|
+
const selectEntries = [];
|
|
3948
|
+
const joinEntries = [
|
|
3949
|
+
[void 0, [tableId, void 0, void 0, [], mapNew(), rootStore]],
|
|
3950
|
+
];
|
|
3951
|
+
const wheres = [];
|
|
3952
|
+
const groupEntries = [];
|
|
3953
|
+
const havings = [];
|
|
3954
|
+
const param = (paramId) => objGet(paramValues, paramId);
|
|
3955
|
+
const select = (arg1, arg2, arg3) => {
|
|
3956
|
+
const joinedTableId = isTrue(arg1) ? arg2 : arg1;
|
|
3957
|
+
const joinedCellId = isTrue(arg1) ? arg3 : arg2;
|
|
3958
|
+
const selectEntry = isFunction(arg1)
|
|
3959
|
+
? [size(selectEntries) + EMPTY_STRING, arg1]
|
|
3960
|
+
: isUndefined(joinedCellId)
|
|
3961
|
+
? [arg1, (getTableCell) => getTableCell(arg1)]
|
|
3962
|
+
: [
|
|
3963
|
+
joinedCellId,
|
|
3964
|
+
(getTableCell) =>
|
|
3965
|
+
isTrue(arg1)
|
|
3966
|
+
? getTableCell(true, joinedTableId, joinedCellId)
|
|
3967
|
+
: getTableCell(joinedTableId, joinedCellId),
|
|
3968
|
+
];
|
|
3969
|
+
arrayPush(selectEntries, selectEntry);
|
|
3970
|
+
return {
|
|
3971
|
+
as: (selectedCellId) => (selectEntry[0] = selectedCellId),
|
|
3972
|
+
};
|
|
3973
|
+
};
|
|
3974
|
+
const join = (arg1, arg2, arg3, arg4) => {
|
|
3975
|
+
const joinedTableId = isTrue(arg1) ? arg2 : arg1;
|
|
3976
|
+
const [fromJoinAlias, onArg] = isTrue(arg1)
|
|
3977
|
+
? isUndefined(arg4) || isFunction(arg3)
|
|
3978
|
+
? [void 0, arg3]
|
|
3979
|
+
: [arg3, arg4]
|
|
3980
|
+
: isUndefined(arg3) || isFunction(arg2)
|
|
3981
|
+
? [void 0, arg2]
|
|
3982
|
+
: [arg2, arg3];
|
|
3983
|
+
const joinEntry = [
|
|
3984
|
+
joinedTableId,
|
|
3985
|
+
[
|
|
3986
|
+
joinedTableId,
|
|
3987
|
+
fromJoinAlias,
|
|
3988
|
+
isFunction(onArg) ? onArg : (getCell) => getCell(onArg),
|
|
3989
|
+
[],
|
|
3990
|
+
mapNew(),
|
|
3991
|
+
isTrue(arg1) ? getResultStore(joinedTableId) : store,
|
|
3992
|
+
],
|
|
3993
|
+
];
|
|
3994
|
+
arrayPush(joinEntries, joinEntry);
|
|
3995
|
+
return {as: (joinedTableId2) => (joinEntry[0] = joinedTableId2)};
|
|
3996
|
+
};
|
|
3997
|
+
const where = (arg1, arg2, arg3, arg4) =>
|
|
3998
|
+
arrayPush(
|
|
3999
|
+
wheres,
|
|
4000
|
+
isFunction(arg1)
|
|
4001
|
+
? arg1
|
|
4002
|
+
: isTrue(arg1)
|
|
4003
|
+
? (getTableCell) => getTableCell(true, arg2, arg3) === arg4
|
|
4004
|
+
: isUndefined(arg3)
|
|
4005
|
+
? (getTableCell) => getTableCell(arg1) === arg2
|
|
4006
|
+
: (getTableCell) => getTableCell(arg1, arg2) === arg3,
|
|
4007
|
+
);
|
|
4008
|
+
const group = (
|
|
4009
|
+
selectedCellId,
|
|
4010
|
+
aggregate,
|
|
4011
|
+
aggregateAdd,
|
|
4012
|
+
aggregateRemove,
|
|
4013
|
+
aggregateReplace,
|
|
4014
|
+
) => {
|
|
4015
|
+
const groupEntry = [
|
|
4016
|
+
selectedCellId,
|
|
4017
|
+
[
|
|
4018
|
+
selectedCellId,
|
|
4019
|
+
isFunction(aggregate)
|
|
4020
|
+
? [aggregate, aggregateAdd, aggregateRemove, aggregateReplace]
|
|
4021
|
+
: (mapGet(numericAggregators, aggregate) ?? [
|
|
4022
|
+
(_cells, length) => length,
|
|
4023
|
+
]),
|
|
4024
|
+
],
|
|
4025
|
+
];
|
|
4026
|
+
arrayPush(groupEntries, groupEntry);
|
|
4027
|
+
return {as: (groupedCellId) => (groupEntry[0] = groupedCellId)};
|
|
4028
|
+
};
|
|
4029
|
+
const having = (arg1, arg2) =>
|
|
4030
|
+
arrayPush(
|
|
4031
|
+
havings,
|
|
4032
|
+
isFunction(arg1)
|
|
4033
|
+
? arg1
|
|
4034
|
+
: (getSelectedOrGroupedCell) =>
|
|
4035
|
+
getSelectedOrGroupedCell(arg1) === arg2,
|
|
4036
|
+
);
|
|
4037
|
+
build({select, join, where, group, having, param});
|
|
4038
|
+
const selects = mapNew(selectEntries);
|
|
4039
|
+
if (collIsEmpty(selects)) {
|
|
4040
|
+
collDel(redefiningQueryIds, queryId);
|
|
4041
|
+
return queries;
|
|
4042
|
+
}
|
|
4043
|
+
const joins = mapNew(joinEntries);
|
|
4044
|
+
mapForEach(joins, (joinAlias, [, fromJoinAlias]) =>
|
|
4045
|
+
ifNotUndefined(mapGet(joins, fromJoinAlias), ({3: toJoinAliases2}) =>
|
|
4046
|
+
isUndefined(joinAlias) ? 0 : arrayPush(toJoinAliases2, joinAlias),
|
|
4047
|
+
),
|
|
4048
|
+
);
|
|
4049
|
+
const groups = mapNew(groupEntries);
|
|
4050
|
+
let selectJoinWhereStore = preStore;
|
|
4051
|
+
if (collIsEmpty(groups) && arrayIsEmpty(havings)) {
|
|
4052
|
+
selectJoinWhereStore = resultStore2;
|
|
4053
|
+
} else {
|
|
4054
|
+
synchronizeTransactions(queryId, selectJoinWhereStore, resultStore2);
|
|
4055
|
+
const groupedSelectedCellIds = mapNew();
|
|
4056
|
+
mapForEach(groups, (groupedCellId, [selectedCellId, aggregators]) =>
|
|
4057
|
+
setAdd(mapEnsure(groupedSelectedCellIds, selectedCellId, setNew), [
|
|
4058
|
+
groupedCellId,
|
|
4059
|
+
aggregators,
|
|
4060
|
+
]),
|
|
4061
|
+
);
|
|
4062
|
+
const groupBySelectedCellIds = setNew();
|
|
4063
|
+
mapForEach(selects, (selectedCellId) =>
|
|
4064
|
+
collHas(groupedSelectedCellIds, selectedCellId)
|
|
4065
|
+
? 0
|
|
4066
|
+
: setAdd(groupBySelectedCellIds, selectedCellId),
|
|
4067
|
+
);
|
|
4068
|
+
const tree = mapNew();
|
|
4069
|
+
const writeGroupRow = (
|
|
4070
|
+
leaf,
|
|
4071
|
+
changedGroupedSelectedCells,
|
|
4072
|
+
selectedRowId,
|
|
4073
|
+
forceRemove,
|
|
4074
|
+
) =>
|
|
4075
|
+
ifNotUndefined(
|
|
4076
|
+
leaf,
|
|
4077
|
+
([selectedCells, selectedRowIds, groupRowId, groupRow]) => {
|
|
4078
|
+
mapForEach(
|
|
4079
|
+
changedGroupedSelectedCells,
|
|
4080
|
+
(selectedCellId, [newCell]) => {
|
|
4081
|
+
const selectedCell = mapEnsure(
|
|
4082
|
+
selectedCells,
|
|
4083
|
+
selectedCellId,
|
|
4084
|
+
mapNew,
|
|
4085
|
+
);
|
|
4086
|
+
const oldLeafCell = mapGet(selectedCell, selectedRowId);
|
|
4087
|
+
const newLeafCell = forceRemove ? void 0 : newCell;
|
|
4088
|
+
if (oldLeafCell !== newLeafCell) {
|
|
4089
|
+
const oldNewSet = setNew([[oldLeafCell, newLeafCell]]);
|
|
4090
|
+
const oldLength = collSize(selectedCell);
|
|
4091
|
+
mapSet(selectedCell, selectedRowId, newLeafCell);
|
|
4092
|
+
collForEach(
|
|
4093
|
+
mapGet(groupedSelectedCellIds, selectedCellId),
|
|
4094
|
+
([groupedCellId, aggregators]) => {
|
|
4095
|
+
const aggregateValue = getAggregateValue(
|
|
4096
|
+
groupRow[groupedCellId],
|
|
4097
|
+
oldLength,
|
|
4098
|
+
selectedCell,
|
|
4099
|
+
oldNewSet,
|
|
4100
|
+
aggregators,
|
|
4101
|
+
);
|
|
4102
|
+
groupRow[groupedCellId] = isUndefined(
|
|
4103
|
+
getCellOrValueType(aggregateValue),
|
|
4104
|
+
)
|
|
4105
|
+
? void 0
|
|
4106
|
+
: aggregateValue;
|
|
4107
|
+
},
|
|
3975
4108
|
);
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
4109
|
+
}
|
|
4110
|
+
},
|
|
4111
|
+
);
|
|
4112
|
+
if (
|
|
4113
|
+
collIsEmpty(selectedRowIds) ||
|
|
4114
|
+
!arrayEvery(havings, (having2) =>
|
|
4115
|
+
having2((cellId) => groupRow[cellId]),
|
|
4116
|
+
)
|
|
4117
|
+
) {
|
|
4118
|
+
resultStore2.delRow(queryId, groupRowId);
|
|
4119
|
+
} else if (isUndefined(groupRowId)) {
|
|
4120
|
+
leaf[2] = resultStore2.addRow(queryId, groupRow);
|
|
4121
|
+
} else {
|
|
4122
|
+
resultStore2.setRow(queryId, groupRowId, groupRow);
|
|
3983
4123
|
}
|
|
3984
4124
|
},
|
|
3985
4125
|
);
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
)
|
|
3991
|
-
) {
|
|
3992
|
-
resultStore.delRow(queryId, groupRowId);
|
|
3993
|
-
} else if (isUndefined(groupRowId)) {
|
|
3994
|
-
leaf[2] = resultStore.addRow(queryId, groupRow);
|
|
3995
|
-
} else {
|
|
3996
|
-
resultStore.setRow(queryId, groupRowId, groupRow);
|
|
3997
|
-
}
|
|
3998
|
-
},
|
|
3999
|
-
);
|
|
4000
|
-
addPreStoreListener(
|
|
4001
|
-
selectJoinWhereStore,
|
|
4002
|
-
queryId,
|
|
4003
|
-
selectJoinWhereStore.addRowListener(
|
|
4004
|
-
queryId,
|
|
4005
|
-
null,
|
|
4006
|
-
(_store, _tableId, selectedRowId, getCellChange) => {
|
|
4007
|
-
const oldPath = [];
|
|
4008
|
-
const newPath = [];
|
|
4009
|
-
const changedGroupedSelectedCells = mapNew();
|
|
4010
|
-
const rowExists = selectJoinWhereStore.hasRow(
|
|
4126
|
+
addPreStoreListener(
|
|
4127
|
+
selectJoinWhereStore,
|
|
4128
|
+
queryId,
|
|
4129
|
+
selectJoinWhereStore.addRowListener(
|
|
4011
4130
|
queryId,
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
|
|
4131
|
+
null,
|
|
4132
|
+
(_store, _tableId, selectedRowId, getCellChange) => {
|
|
4133
|
+
const oldPath = [];
|
|
4134
|
+
const newPath = [];
|
|
4135
|
+
const changedGroupedSelectedCells = mapNew();
|
|
4136
|
+
const rowExists = selectJoinWhereStore.hasRow(
|
|
4137
|
+
queryId,
|
|
4138
|
+
selectedRowId,
|
|
4139
|
+
);
|
|
4140
|
+
let changedLeaf = !rowExists;
|
|
4141
|
+
collForEach(groupBySelectedCellIds, (selectedCellId) => {
|
|
4142
|
+
const [changed, oldCell, newCell] = getCellChange(
|
|
4143
|
+
queryId,
|
|
4144
|
+
selectedRowId,
|
|
4145
|
+
selectedCellId,
|
|
4146
|
+
);
|
|
4147
|
+
arrayPush(oldPath, oldCell);
|
|
4148
|
+
arrayPush(newPath, newCell);
|
|
4149
|
+
changedLeaf ||= changed;
|
|
4150
|
+
});
|
|
4151
|
+
mapForEach(groupedSelectedCellIds, (selectedCellId) => {
|
|
4152
|
+
const [changed, , newCell] = getCellChange(
|
|
4153
|
+
queryId,
|
|
4154
|
+
selectedRowId,
|
|
4155
|
+
selectedCellId,
|
|
4156
|
+
);
|
|
4157
|
+
if (changedLeaf || changed) {
|
|
4158
|
+
mapSet(changedGroupedSelectedCells, selectedCellId, [
|
|
4159
|
+
newCell,
|
|
4160
|
+
]);
|
|
4161
|
+
}
|
|
4162
|
+
});
|
|
4163
|
+
if (changedLeaf) {
|
|
4164
|
+
writeGroupRow(
|
|
4165
|
+
visitTree(tree, oldPath, void 0, ([, selectedRowIds]) => {
|
|
4166
|
+
collDel(selectedRowIds, selectedRowId);
|
|
4167
|
+
return collIsEmpty(selectedRowIds);
|
|
4168
|
+
}),
|
|
4169
|
+
changedGroupedSelectedCells,
|
|
4170
|
+
selectedRowId,
|
|
4171
|
+
1,
|
|
4172
|
+
);
|
|
4173
|
+
}
|
|
4174
|
+
if (rowExists) {
|
|
4175
|
+
writeGroupRow(
|
|
4176
|
+
visitTree(
|
|
4177
|
+
tree,
|
|
4178
|
+
newPath,
|
|
4179
|
+
() => {
|
|
4180
|
+
const groupRow = {};
|
|
4181
|
+
collForEach(
|
|
4182
|
+
groupBySelectedCellIds,
|
|
4183
|
+
(selectedCellId) =>
|
|
4184
|
+
(groupRow[selectedCellId] =
|
|
4185
|
+
selectJoinWhereStore.getCell(
|
|
4186
|
+
queryId,
|
|
4187
|
+
selectedRowId,
|
|
4188
|
+
selectedCellId,
|
|
4189
|
+
)),
|
|
4190
|
+
);
|
|
4191
|
+
return [mapNew(), setNew(), void 0, groupRow];
|
|
4192
|
+
},
|
|
4193
|
+
([, selectedRowIds]) => {
|
|
4194
|
+
setAdd(selectedRowIds, selectedRowId);
|
|
4195
|
+
},
|
|
4196
|
+
),
|
|
4197
|
+
changedGroupedSelectedCells,
|
|
4198
|
+
selectedRowId,
|
|
4199
|
+
);
|
|
4200
|
+
}
|
|
4201
|
+
},
|
|
4202
|
+
),
|
|
4203
|
+
);
|
|
4204
|
+
}
|
|
4205
|
+
synchronizeTransactions(queryId, rootStore, selectJoinWhereStore);
|
|
4206
|
+
const writeSelectRow = (rootRowId) => {
|
|
4207
|
+
const getJoinCell = (arg1, arg2, arg3) => {
|
|
4208
|
+
const joinedTableId = isTrue(arg1) ? arg2 : arg1;
|
|
4209
|
+
const joinedCellId = isTrue(arg1) ? arg3 : arg2;
|
|
4210
|
+
if (isUndefined(joinedCellId)) {
|
|
4211
|
+
return rootStore.getCell(tableId, rootRowId, arg1);
|
|
4045
4212
|
}
|
|
4046
|
-
if (
|
|
4047
|
-
|
|
4048
|
-
visitTree(
|
|
4049
|
-
tree,
|
|
4050
|
-
newPath,
|
|
4051
|
-
() => {
|
|
4052
|
-
const groupRow = {};
|
|
4053
|
-
collForEach(
|
|
4054
|
-
groupBySelectedCellIds,
|
|
4055
|
-
(selectedCellId) =>
|
|
4056
|
-
(groupRow[selectedCellId] =
|
|
4057
|
-
selectJoinWhereStore.getCell(
|
|
4058
|
-
queryId,
|
|
4059
|
-
selectedRowId,
|
|
4060
|
-
selectedCellId,
|
|
4061
|
-
)),
|
|
4062
|
-
);
|
|
4063
|
-
return [mapNew(), setNew(), void 0, groupRow];
|
|
4064
|
-
},
|
|
4065
|
-
([, selectedRowIds]) => {
|
|
4066
|
-
setAdd(selectedRowIds, selectedRowId);
|
|
4067
|
-
},
|
|
4068
|
-
),
|
|
4069
|
-
changedGroupedSelectedCells,
|
|
4070
|
-
selectedRowId,
|
|
4071
|
-
);
|
|
4213
|
+
if (joinedTableId === tableId && !isTrue(arg1)) {
|
|
4214
|
+
return rootStore.getCell(tableId, rootRowId, joinedCellId);
|
|
4072
4215
|
}
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
);
|
|
4076
|
-
}
|
|
4077
|
-
synchronizeTransactions(queryId, store, selectJoinWhereStore);
|
|
4078
|
-
const writeSelectRow = (rootRowId) => {
|
|
4079
|
-
const getTableCell = (arg1, arg2) =>
|
|
4080
|
-
store.getCell(
|
|
4081
|
-
...(isUndefined(arg2)
|
|
4082
|
-
? [tableId, rootRowId, arg1]
|
|
4083
|
-
: arg1 === tableId
|
|
4084
|
-
? [tableId, rootRowId, arg2]
|
|
4085
|
-
: [
|
|
4086
|
-
mapGet(joins, arg1)?.[0],
|
|
4087
|
-
mapGet(mapGet(joins, arg1)?.[4], rootRowId)?.[0],
|
|
4088
|
-
arg2,
|
|
4089
|
-
]),
|
|
4090
|
-
);
|
|
4091
|
-
selectJoinWhereStore.transaction(() =>
|
|
4092
|
-
arrayEvery(wheres, (where2) => where2(getTableCell))
|
|
4093
|
-
? mapForEach(selects, (asCellId, tableCellGetter) =>
|
|
4094
|
-
selectJoinWhereStore._[5](
|
|
4095
|
-
queryId,
|
|
4096
|
-
rootRowId,
|
|
4097
|
-
asCellId,
|
|
4098
|
-
tableCellGetter(getTableCell, rootRowId),
|
|
4099
|
-
),
|
|
4100
|
-
)
|
|
4101
|
-
: selectJoinWhereStore.delRow(queryId, rootRowId),
|
|
4102
|
-
);
|
|
4103
|
-
};
|
|
4104
|
-
const listenToTable = (rootRowId, tableId2, rowId, joinedTableIds2) => {
|
|
4105
|
-
const getCell = (cellId) => store.getCell(tableId2, rowId, cellId);
|
|
4106
|
-
arrayForEach(joinedTableIds2, (remoteAsTableId) => {
|
|
4107
|
-
const [realJoinedTableId, , on, nextJoinedTableIds, remoteIdPairs] =
|
|
4108
|
-
mapGet(joins, remoteAsTableId);
|
|
4109
|
-
const remoteRowId = on?.(getCell, rootRowId);
|
|
4110
|
-
const [previousRemoteRowId, previousRemoteListenerId] =
|
|
4111
|
-
mapGet(remoteIdPairs, rootRowId) ?? [];
|
|
4112
|
-
if (remoteRowId != previousRemoteRowId) {
|
|
4113
|
-
if (!isUndefined(previousRemoteListenerId)) {
|
|
4114
|
-
delStoreListeners(queryId, previousRemoteListenerId);
|
|
4115
|
-
}
|
|
4116
|
-
mapSet(
|
|
4117
|
-
remoteIdPairs,
|
|
4118
|
-
rootRowId,
|
|
4119
|
-
isUndefined(remoteRowId)
|
|
4216
|
+
const join2 = mapGet(joins, joinedTableId);
|
|
4217
|
+
return isUndefined(join2)
|
|
4120
4218
|
? void 0
|
|
4121
|
-
: [
|
|
4122
|
-
|
|
4123
|
-
|
|
4219
|
+
: join2[5].getCell(
|
|
4220
|
+
join2[0],
|
|
4221
|
+
mapGet(join2[4], rootRowId)?.[0],
|
|
4222
|
+
joinedCellId,
|
|
4223
|
+
);
|
|
4224
|
+
};
|
|
4225
|
+
selectJoinWhereStore.transaction(() =>
|
|
4226
|
+
arrayEvery(wheres, (where2) => where2(getJoinCell))
|
|
4227
|
+
? mapForEach(selects, (asCellId, tableCellGetter) =>
|
|
4228
|
+
selectJoinWhereStore._[5](
|
|
4124
4229
|
queryId,
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
rootRowId,
|
|
4129
|
-
realJoinedTableId,
|
|
4130
|
-
remoteRowId,
|
|
4131
|
-
nextJoinedTableIds,
|
|
4132
|
-
),
|
|
4133
|
-
),
|
|
4230
|
+
rootRowId,
|
|
4231
|
+
asCellId,
|
|
4232
|
+
tableCellGetter(getJoinCell, rootRowId),
|
|
4134
4233
|
),
|
|
4135
|
-
|
|
4234
|
+
)
|
|
4235
|
+
: selectJoinWhereStore.delRow(queryId, rootRowId),
|
|
4136
4236
|
);
|
|
4137
|
-
}
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
4237
|
+
};
|
|
4238
|
+
const listenToTable = (
|
|
4239
|
+
rootRowId,
|
|
4240
|
+
sourceStore,
|
|
4241
|
+
tableId2,
|
|
4242
|
+
rowId,
|
|
4243
|
+
toJoinAliases2,
|
|
4244
|
+
) => {
|
|
4245
|
+
const getCell = (cellId) =>
|
|
4246
|
+
sourceStore.getCell(tableId2, rowId, cellId);
|
|
4247
|
+
arrayForEach(toJoinAliases2, (joinAlias) => {
|
|
4248
|
+
const [
|
|
4249
|
+
realJoinedTableId,
|
|
4250
|
+
,
|
|
4251
|
+
on,
|
|
4252
|
+
nextJoinAliases,
|
|
4253
|
+
remoteIdPairs,
|
|
4254
|
+
remoteSourceStore,
|
|
4255
|
+
] = mapGet(joins, joinAlias);
|
|
4256
|
+
const remoteRowId = on?.(getCell, rootRowId);
|
|
4257
|
+
const previousRemote = mapGet(remoteIdPairs, rootRowId);
|
|
4258
|
+
const previousRemoteRowId = previousRemote?.[0];
|
|
4259
|
+
if (remoteRowId != previousRemoteRowId) {
|
|
4260
|
+
ifNotUndefined(
|
|
4261
|
+
previousRemote,
|
|
4262
|
+
([, previousRemoteSourceStore, previousRemoteListenerId]) =>
|
|
4263
|
+
delSourceStoreListeners(
|
|
4264
|
+
queryId,
|
|
4265
|
+
previousRemoteSourceStore,
|
|
4266
|
+
previousRemoteListenerId,
|
|
4267
|
+
),
|
|
4268
|
+
);
|
|
4269
|
+
mapSet(
|
|
4270
|
+
remoteIdPairs,
|
|
4271
|
+
rootRowId,
|
|
4272
|
+
isUndefined(remoteRowId)
|
|
4273
|
+
? void 0
|
|
4274
|
+
: [
|
|
4275
|
+
remoteRowId,
|
|
4276
|
+
remoteSourceStore,
|
|
4277
|
+
...addSourceStoreListeners(
|
|
4278
|
+
remoteSourceStore,
|
|
4279
|
+
queryId,
|
|
4280
|
+
1,
|
|
4281
|
+
remoteSourceStore.addRowListener(
|
|
4282
|
+
realJoinedTableId,
|
|
4283
|
+
remoteRowId,
|
|
4284
|
+
() =>
|
|
4285
|
+
listenToTable(
|
|
4286
|
+
rootRowId,
|
|
4287
|
+
remoteSourceStore,
|
|
4288
|
+
realJoinedTableId,
|
|
4289
|
+
remoteRowId,
|
|
4290
|
+
nextJoinAliases,
|
|
4291
|
+
),
|
|
4292
|
+
),
|
|
4293
|
+
),
|
|
4294
|
+
],
|
|
4295
|
+
);
|
|
4296
|
+
}
|
|
4297
|
+
});
|
|
4298
|
+
writeSelectRow(rootRowId);
|
|
4299
|
+
};
|
|
4300
|
+
const {3: toJoinAliases} = mapGet(joins, void 0);
|
|
4301
|
+
const rootRowChanged = (sourceStore, _tableId, rootRowId) => {
|
|
4302
|
+
if (rootStore.hasRow(tableId, rootRowId)) {
|
|
4303
|
+
listenToTable(
|
|
4304
|
+
rootRowId,
|
|
4305
|
+
rootStore,
|
|
4306
|
+
tableId,
|
|
4307
|
+
rootRowId,
|
|
4308
|
+
toJoinAliases,
|
|
4309
|
+
);
|
|
4149
4310
|
} else {
|
|
4150
4311
|
selectJoinWhereStore.delRow(queryId, rootRowId);
|
|
4151
4312
|
collForEach(joins, ({4: idsByRootRowId}) =>
|
|
4152
4313
|
ifNotUndefined(
|
|
4153
4314
|
mapGet(idsByRootRowId, rootRowId),
|
|
4154
|
-
([, listenerId]) => {
|
|
4155
|
-
|
|
4315
|
+
([, sourceStore2, listenerId]) => {
|
|
4316
|
+
delSourceStoreListeners(queryId, sourceStore2, listenerId);
|
|
4156
4317
|
mapSet(idsByRootRowId, rootRowId);
|
|
4157
4318
|
},
|
|
4158
4319
|
),
|
|
4159
4320
|
);
|
|
4160
4321
|
}
|
|
4161
|
-
}
|
|
4162
|
-
|
|
4322
|
+
};
|
|
4323
|
+
selectJoinWhereStore.transaction(() => {
|
|
4324
|
+
arrayForEach(rootStore.getRowIds(tableId), (rootRowId) =>
|
|
4325
|
+
rootRowChanged(rootStore, tableId, rootRowId),
|
|
4326
|
+
);
|
|
4327
|
+
addSourceStoreListeners(
|
|
4328
|
+
rootStore,
|
|
4329
|
+
queryId,
|
|
4330
|
+
0,
|
|
4331
|
+
rootStore.addRowListener(tableId, null, rootRowChanged),
|
|
4332
|
+
);
|
|
4333
|
+
});
|
|
4334
|
+
collDel(redefiningQueryIds, queryId);
|
|
4335
|
+
return queries;
|
|
4336
|
+
}),
|
|
4163
4337
|
);
|
|
4164
|
-
return queries;
|
|
4165
|
-
};
|
|
4166
|
-
const callParamListeners = (queryId, oldParamValues, newParamValues) => {
|
|
4167
|
-
const allParamIds = setNew([
|
|
4168
|
-
...objIds(oldParamValues),
|
|
4169
|
-
...objIds(newParamValues),
|
|
4170
|
-
]);
|
|
4171
|
-
let changed = 0;
|
|
4172
|
-
collForEach(allParamIds, (paramId) => {
|
|
4173
|
-
const newParamValue = objGet(newParamValues, paramId);
|
|
4174
|
-
if (!arrayOrValueEqual(objGet(oldParamValues, paramId), newParamValue)) {
|
|
4175
|
-
changed = 1;
|
|
4176
|
-
callListeners(paramValueListeners, [queryId, paramId], newParamValue);
|
|
4177
|
-
}
|
|
4178
|
-
});
|
|
4179
|
-
if (changed) {
|
|
4180
|
-
callListeners(paramValuesListeners, [queryId], newParamValues);
|
|
4181
|
-
}
|
|
4182
|
-
};
|
|
4183
4338
|
const delQueryDefinition = (queryId) => {
|
|
4184
|
-
|
|
4339
|
+
ifNotUndefined(getQueryArgs(queryId), ([, listenerId]) =>
|
|
4340
|
+
paramStore.delListener(listenerId),
|
|
4341
|
+
);
|
|
4342
|
+
paramStore.delRow(PARAMS_TABLE, queryId);
|
|
4185
4343
|
resetPreStores(queryId);
|
|
4344
|
+
resetSourceStores(queryId);
|
|
4186
4345
|
delDefinition(queryId);
|
|
4187
|
-
callParamListeners(queryId, oldParamValues, {});
|
|
4188
4346
|
return queries;
|
|
4189
4347
|
};
|
|
4190
|
-
const setParamValues = (queryId, paramValues
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
!objIsEqual(mapToObj(oldParamValues), paramValues, arrayOrValueEqual)
|
|
4195
|
-
) {
|
|
4196
|
-
resultStore.transaction(() =>
|
|
4197
|
-
setQueryDefinition(
|
|
4198
|
-
queryId,
|
|
4199
|
-
getTableId(queryId),
|
|
4200
|
-
definition,
|
|
4201
|
-
paramValues,
|
|
4202
|
-
),
|
|
4203
|
-
);
|
|
4204
|
-
}
|
|
4205
|
-
});
|
|
4348
|
+
const setParamValues = (queryId, paramValues) => {
|
|
4349
|
+
if (hasQuery(queryId)) {
|
|
4350
|
+
setOrDelParamValues(queryId, paramValues);
|
|
4351
|
+
}
|
|
4206
4352
|
return queries;
|
|
4207
4353
|
};
|
|
4208
4354
|
const setParamValue = (queryId, paramId, value) => {
|
|
4209
|
-
if (
|
|
4210
|
-
|
|
4211
|
-
queryId,
|
|
4212
|
-
{...getParamValues(queryId), [paramId]: value},
|
|
4213
|
-
1,
|
|
4214
|
-
);
|
|
4355
|
+
if (hasQuery(queryId)) {
|
|
4356
|
+
paramStore.setCell(PARAMS_TABLE, queryId, paramId, value);
|
|
4215
4357
|
}
|
|
4216
4358
|
return queries;
|
|
4217
4359
|
};
|
|
4218
|
-
const getParamValues = (queryId) =>
|
|
4360
|
+
const getParamValues = (queryId) => paramStore.getRow(PARAMS_TABLE, queryId);
|
|
4219
4361
|
const getParamValue = (queryId, paramId) =>
|
|
4220
|
-
|
|
4362
|
+
paramStore.getCell(PARAMS_TABLE, queryId, paramId);
|
|
4221
4363
|
const addQueryIdsListener = (listener) =>
|
|
4222
4364
|
addQueryIdsListenerImpl(() => listener(queries));
|
|
4365
|
+
const forEachResultTable = (tableCallback) =>
|
|
4366
|
+
forEachQuery((queryId) =>
|
|
4367
|
+
getResultStore(queryId).hasTable(queryId)
|
|
4368
|
+
? tableCallback(queryId, (rowCallback) =>
|
|
4369
|
+
queries.forEachResultRow(queryId, rowCallback),
|
|
4370
|
+
)
|
|
4371
|
+
: 0,
|
|
4372
|
+
);
|
|
4223
4373
|
const addParamValuesListener = (queryId, listener) =>
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4374
|
+
PARAM_LISTENER_PREFIX +
|
|
4375
|
+
paramStore.addRowListener(
|
|
4376
|
+
PARAMS_TABLE,
|
|
4377
|
+
queryId,
|
|
4378
|
+
(_store, _tableId, queryId2) =>
|
|
4379
|
+
listener(queries, queryId2, getParamValues(queryId2)),
|
|
4228
4380
|
);
|
|
4229
4381
|
const addParamValueListener = (queryId, paramId, listener) =>
|
|
4230
|
-
|
|
4231
|
-
|
|
4382
|
+
PARAM_LISTENER_PREFIX +
|
|
4383
|
+
paramStore.addCellListener(
|
|
4384
|
+
PARAMS_TABLE,
|
|
4385
|
+
queryId,
|
|
4386
|
+
paramId,
|
|
4387
|
+
(_store, _tableId, queryId2, paramId2, paramValue) =>
|
|
4232
4388
|
listener(queries, queryId2, paramId2, paramValue),
|
|
4233
|
-
paramValueListeners,
|
|
4234
|
-
[queryId, paramId],
|
|
4235
4389
|
);
|
|
4236
4390
|
const delListener = (listenerId) => {
|
|
4237
|
-
|
|
4391
|
+
const routedResultListener = mapGet(routedResultListeners, listenerId);
|
|
4392
|
+
if (listenerId[0] == PARAM_LISTENER_PREFIX) {
|
|
4393
|
+
paramStore.delListener(slice(listenerId, 1));
|
|
4394
|
+
} else if (!isUndefined(routedResultListener)) {
|
|
4395
|
+
const [stat, storeListenerIds, queryIdsListenerId] = routedResultListener;
|
|
4396
|
+
mapForEach(storeListenerIds, (_queryId, [store2, storeListenerId]) =>
|
|
4397
|
+
store2.delListener(storeListenerId),
|
|
4398
|
+
);
|
|
4399
|
+
ifNotUndefined(queryIdsListenerId, delListenerImpl);
|
|
4400
|
+
mapSet(routedResultListeners, listenerId);
|
|
4401
|
+
delListenerImpl(listenerId);
|
|
4402
|
+
resultListenerStats[stat]--;
|
|
4403
|
+
} else {
|
|
4404
|
+
delListenerImpl(listenerId);
|
|
4405
|
+
}
|
|
4238
4406
|
return queries;
|
|
4239
4407
|
};
|
|
4240
|
-
const getListenerStats = () => {
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
...stats,
|
|
4249
|
-
paramValues: collSize2(paramValuesListeners),
|
|
4250
|
-
paramValue: collSize3(paramValueListeners),
|
|
4251
|
-
};
|
|
4408
|
+
const getListenerStats = () => ({
|
|
4409
|
+
...resultListenerStats,
|
|
4410
|
+
paramValues: paramStore.getListenerStats().row - size(getQueryIds()),
|
|
4411
|
+
paramValue: paramStore.getListenerStats().cell,
|
|
4412
|
+
});
|
|
4413
|
+
const destroy = () => {
|
|
4414
|
+
arrayForEach(getQueryIds(), delQueryDefinition);
|
|
4415
|
+
destroyImpl();
|
|
4252
4416
|
};
|
|
4253
4417
|
const queries = {
|
|
4254
4418
|
setQueryDefinition,
|
|
@@ -4262,6 +4426,7 @@ const createQueries = getCreateFunction((store) => {
|
|
|
4262
4426
|
forEachQuery,
|
|
4263
4427
|
hasQuery,
|
|
4264
4428
|
getTableId,
|
|
4429
|
+
forEachResultTable,
|
|
4265
4430
|
addQueryIdsListener,
|
|
4266
4431
|
addParamValuesListener,
|
|
4267
4432
|
addParamValueListener,
|
|
@@ -4269,30 +4434,41 @@ const createQueries = getCreateFunction((store) => {
|
|
|
4269
4434
|
destroy,
|
|
4270
4435
|
getListenerStats,
|
|
4271
4436
|
};
|
|
4437
|
+
const getListenerArgs = (args, argumentCount) =>
|
|
4438
|
+
argumentCount == 5
|
|
4439
|
+
? [args[0], args[1] ?? void 0, args[2], args[3], args[4]]
|
|
4440
|
+
: slice(args, 0, argumentCount);
|
|
4441
|
+
const getResultListenerStat = (gettable) =>
|
|
4442
|
+
gettable[0].toLowerCase() + slice(gettable, 1);
|
|
4272
4443
|
objMap(
|
|
4273
4444
|
{
|
|
4274
|
-
[TABLE]: [
|
|
4275
|
-
[TABLE + CELL_IDS]: [
|
|
4276
|
-
[ROW_COUNT]: [
|
|
4277
|
-
[ROW_IDS]: [
|
|
4278
|
-
[SORTED_ROW_IDS]: [
|
|
4279
|
-
[ROW]: [
|
|
4280
|
-
[CELL_IDS]: [
|
|
4281
|
-
[CELL]: [
|
|
4445
|
+
[TABLE]: [2, 1],
|
|
4446
|
+
[TABLE + CELL_IDS]: [1, 1],
|
|
4447
|
+
[ROW_COUNT]: [1, 1],
|
|
4448
|
+
[ROW_IDS]: [1, 1],
|
|
4449
|
+
[SORTED_ROW_IDS]: [1, 5],
|
|
4450
|
+
[ROW]: [3, 2],
|
|
4451
|
+
[CELL_IDS]: [1, 2],
|
|
4452
|
+
[CELL]: [3, 3],
|
|
4282
4453
|
},
|
|
4283
|
-
([
|
|
4454
|
+
([prefixCount, argumentCount], gettable) => {
|
|
4284
4455
|
arrayForEach(
|
|
4285
|
-
|
|
4456
|
+
slice([GET, 'has', 'forEach'], 0, prefixCount),
|
|
4286
4457
|
(prefix) =>
|
|
4287
4458
|
(queries[prefix + RESULT + gettable] = (...args) =>
|
|
4288
|
-
|
|
4459
|
+
getResultStore(args[0])[prefix + gettable](...args)),
|
|
4289
4460
|
);
|
|
4290
4461
|
queries[ADD + RESULT + gettable + LISTENER] = (...args) =>
|
|
4291
|
-
|
|
4292
|
-
|
|
4293
|
-
|
|
4294
|
-
|
|
4295
|
-
|
|
4462
|
+
addRoutedResultListener(
|
|
4463
|
+
getResultListenerStat(gettable),
|
|
4464
|
+
args[0],
|
|
4465
|
+
(store2) =>
|
|
4466
|
+
store2[ADD + gettable + LISTENER](
|
|
4467
|
+
...getListenerArgs(args, argumentCount),
|
|
4468
|
+
(_store, ...listenerArgs) =>
|
|
4469
|
+
args[argumentCount](queries, ...listenerArgs),
|
|
4470
|
+
true,
|
|
4471
|
+
),
|
|
4296
4472
|
);
|
|
4297
4473
|
},
|
|
4298
4474
|
);
|