tinybase 9.3.0 → 9.4.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 -7
- package/@types/queries/with-schemas/index.d.ts +153 -7
- package/@types/ui-react-dom/index.d.ts +10 -10
- package/@types/ui-react-dom/with-schemas/index.d.ts +10 -10
- package/@types/ui-react-dom-charts/index.d.ts +7 -7
- package/@types/ui-react-dom-charts/with-schemas/index.d.ts +7 -7
- package/@types/ui-react-inspector/index.d.ts +1 -1
- package/@types/ui-react-inspector/with-schemas/index.d.ts +1 -1
- package/@types/ui-solid-dom/index.d.ts +10 -10
- package/@types/ui-solid-dom/with-schemas/index.d.ts +10 -10
- package/@types/ui-solid-inspector/index.d.ts +1 -1
- package/@types/ui-solid-inspector/with-schemas/index.d.ts +1 -1
- package/@types/ui-svelte-dom/index.d.ts +10 -10
- package/@types/ui-svelte-dom/with-schemas/index.d.ts +10 -10
- package/@types/ui-svelte-inspector/index.d.ts +1 -1
- package/@types/ui-svelte-inspector/with-schemas/index.d.ts +1 -1
- package/index.js +200 -24
- package/min/index.js +1 -1
- package/min/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/with-schemas/index.js +1 -1
- package/min/with-schemas/index.js.gz +0 -0
- package/omni/index.js +200 -24
- package/omni/with-schemas/index.js +200 -24
- package/package.json +1 -1
- package/queries/index.js +205 -24
- package/queries/with-schemas/index.js +205 -24
- package/readme.md +1 -1
- package/releases.md +1 -1
- package/with-schemas/index.js +200 -24
|
@@ -8230,6 +8230,8 @@ const createQueries = getCreateFunction((store) => {
|
|
|
8230
8230
|
};
|
|
8231
8231
|
const preStoreListenerIds = mapNew();
|
|
8232
8232
|
const sourceStoreListenerIds = mapNew();
|
|
8233
|
+
const selectAllListenerIds = mapNew();
|
|
8234
|
+
const referencedQueryIds = mapNew();
|
|
8233
8235
|
const {
|
|
8234
8236
|
_: [, addListener, callListeners],
|
|
8235
8237
|
delListener: delListenerImpl,
|
|
@@ -8303,11 +8305,42 @@ const createQueries = getCreateFunction((store) => {
|
|
|
8303
8305
|
resetStoreListeners(mapGet(sourceStoreListenerIds, queryId));
|
|
8304
8306
|
mapSet(sourceStoreListenerIds, queryId);
|
|
8305
8307
|
};
|
|
8306
|
-
const
|
|
8308
|
+
const syncSelectAllListeners = (queryId, nextSources = mapNew()) => {
|
|
8309
|
+
const listenerIds = mapEnsure(selectAllListenerIds, queryId, mapNew);
|
|
8310
|
+
mapForEach(listenerIds, (sourceStore, listenerIdsByTableId) => {
|
|
8311
|
+
mapForEach(listenerIdsByTableId, (sourceTableId, listenerId) =>
|
|
8312
|
+
collHas(mapGet(nextSources, sourceStore), sourceTableId)
|
|
8313
|
+
? 0
|
|
8314
|
+
: (sourceStore.delListener(listenerId),
|
|
8315
|
+
mapSet(listenerIdsByTableId, sourceTableId)),
|
|
8316
|
+
);
|
|
8317
|
+
if (collIsEmpty(listenerIdsByTableId)) {
|
|
8318
|
+
mapSet(listenerIds, sourceStore);
|
|
8319
|
+
}
|
|
8320
|
+
});
|
|
8321
|
+
mapForEach(nextSources, (sourceStore, tableIds) => {
|
|
8322
|
+
const listenerIdsByTableId = mapEnsure(listenerIds, sourceStore, mapNew);
|
|
8323
|
+
collForEach(tableIds, (sourceTableId) =>
|
|
8324
|
+
mapEnsure(listenerIdsByTableId, sourceTableId, () =>
|
|
8325
|
+
sourceStore.addTableCellIdsListener(sourceTableId, () =>
|
|
8326
|
+
setQueryDefinitionImpl(queryId),
|
|
8327
|
+
),
|
|
8328
|
+
),
|
|
8329
|
+
);
|
|
8330
|
+
});
|
|
8331
|
+
if (collIsEmpty(listenerIds)) {
|
|
8332
|
+
mapSet(selectAllListenerIds, queryId);
|
|
8333
|
+
}
|
|
8334
|
+
};
|
|
8335
|
+
const isResultStoreReferenced = (queryId, resultStore2) =>
|
|
8307
8336
|
!(
|
|
8308
8337
|
collEvery(routedResultListeners, ([, storeListenerIds]) =>
|
|
8309
8338
|
collEvery(storeListenerIds, ([store2]) => store2 !== resultStore2),
|
|
8310
8339
|
) &&
|
|
8340
|
+
collEvery(
|
|
8341
|
+
referencedQueryIds,
|
|
8342
|
+
(queryIds) => !collHas(queryIds, queryId),
|
|
8343
|
+
) &&
|
|
8311
8344
|
arrayEvery(
|
|
8312
8345
|
[preStoreListenerIds, sourceStoreListenerIds],
|
|
8313
8346
|
(storeListenerIds) =>
|
|
@@ -8322,7 +8355,7 @@ const createQueries = getCreateFunction((store) => {
|
|
|
8322
8355
|
hasQuery(queryId) ? 0 : mapSet(preStores, queryId),
|
|
8323
8356
|
);
|
|
8324
8357
|
mapForEach(resultStores, (queryId, resultStore2) =>
|
|
8325
|
-
hasQuery(queryId) || isResultStoreReferenced(resultStore2)
|
|
8358
|
+
hasQuery(queryId) || isResultStoreReferenced(queryId, resultStore2)
|
|
8326
8359
|
? 0
|
|
8327
8360
|
: mapSet(resultStores, queryId),
|
|
8328
8361
|
);
|
|
@@ -8404,7 +8437,13 @@ const createQueries = getCreateFunction((store) => {
|
|
|
8404
8437
|
const rootStore = asQuery ? getResultStore(tableId) : store;
|
|
8405
8438
|
const resultStore2 = getResultStore(queryId);
|
|
8406
8439
|
const paramValues = definition?.[3] ?? getParamValues(queryId);
|
|
8407
|
-
const
|
|
8440
|
+
const nextReferencedQueryIds = stagedDefinition[4];
|
|
8441
|
+
if (asQuery) {
|
|
8442
|
+
setAdd(nextReferencedQueryIds, tableId);
|
|
8443
|
+
}
|
|
8444
|
+
const selectionEntries = [];
|
|
8445
|
+
let hasSelectAll = false;
|
|
8446
|
+
let selectCount = 0;
|
|
8408
8447
|
const joinEntries = [
|
|
8409
8448
|
[void 0, [tableId, void 0, void 0, [], mapNew(), rootStore]],
|
|
8410
8449
|
];
|
|
@@ -8416,21 +8455,35 @@ const createQueries = getCreateFunction((store) => {
|
|
|
8416
8455
|
const joinedTableId = isTrue(arg1) ? arg2 : arg1;
|
|
8417
8456
|
const joinedCellId = isTrue(arg1) ? arg3 : arg2;
|
|
8418
8457
|
const selectEntry = isFunction(arg1)
|
|
8419
|
-
? [
|
|
8458
|
+
? [0, selectCount + EMPTY_STRING, arg1]
|
|
8420
8459
|
: isUndefined(joinedCellId)
|
|
8421
|
-
? [arg1, (getTableCell) => getTableCell(arg1)]
|
|
8460
|
+
? [0, arg1, (getTableCell) => getTableCell(arg1)]
|
|
8422
8461
|
: [
|
|
8462
|
+
0,
|
|
8423
8463
|
joinedCellId,
|
|
8424
8464
|
(getTableCell) =>
|
|
8425
8465
|
isTrue(arg1)
|
|
8426
8466
|
? getTableCell(true, joinedTableId, joinedCellId)
|
|
8427
8467
|
: getTableCell(joinedTableId, joinedCellId),
|
|
8428
8468
|
];
|
|
8429
|
-
|
|
8469
|
+
selectCount++;
|
|
8470
|
+
arrayPush(selectionEntries, selectEntry);
|
|
8430
8471
|
return {
|
|
8431
|
-
as: (selectedCellId) => (selectEntry[
|
|
8472
|
+
as: (selectedCellId) => (selectEntry[1] = selectedCellId),
|
|
8432
8473
|
};
|
|
8433
8474
|
};
|
|
8475
|
+
const selectAll = (arg1, arg2, arg3) => {
|
|
8476
|
+
hasSelectAll = true;
|
|
8477
|
+
const joinedTableId = isTrue(arg1) ? arg2 : arg1;
|
|
8478
|
+
const prefixOrMapper = isTrue(arg1) ? arg3 : arg2;
|
|
8479
|
+
arrayPush(selectionEntries, [
|
|
8480
|
+
1,
|
|
8481
|
+
joinedTableId,
|
|
8482
|
+
isFunction(prefixOrMapper)
|
|
8483
|
+
? prefixOrMapper
|
|
8484
|
+
: (cellId) => (prefixOrMapper ?? EMPTY_STRING) + cellId,
|
|
8485
|
+
]);
|
|
8486
|
+
};
|
|
8434
8487
|
const join = (arg1, arg2, arg3, arg4) => {
|
|
8435
8488
|
const joinedTableId = isTrue(arg1) ? arg2 : arg1;
|
|
8436
8489
|
const [fromJoinAlias, onArg] = isTrue(arg1)
|
|
@@ -8440,6 +8493,13 @@ const createQueries = getCreateFunction((store) => {
|
|
|
8440
8493
|
: isUndefined(arg3) || isFunction(arg2)
|
|
8441
8494
|
? [void 0, arg2]
|
|
8442
8495
|
: [arg2, arg3];
|
|
8496
|
+
const sourceIsQuery = isTrue(arg1);
|
|
8497
|
+
const sourceStore = sourceIsQuery
|
|
8498
|
+
? getResultStore(joinedTableId)
|
|
8499
|
+
: store;
|
|
8500
|
+
if (sourceIsQuery) {
|
|
8501
|
+
setAdd(nextReferencedQueryIds, joinedTableId);
|
|
8502
|
+
}
|
|
8443
8503
|
const joinEntry = [
|
|
8444
8504
|
joinedTableId,
|
|
8445
8505
|
[
|
|
@@ -8448,7 +8508,7 @@ const createQueries = getCreateFunction((store) => {
|
|
|
8448
8508
|
isFunction(onArg) ? onArg : (getCell) => getCell(onArg),
|
|
8449
8509
|
[],
|
|
8450
8510
|
mapNew(),
|
|
8451
|
-
|
|
8511
|
+
sourceStore,
|
|
8452
8512
|
],
|
|
8453
8513
|
];
|
|
8454
8514
|
arrayPush(joinEntries, joinEntry);
|
|
@@ -8494,10 +8554,9 @@ const createQueries = getCreateFunction((store) => {
|
|
|
8494
8554
|
: (getSelectedOrGroupedCell) =>
|
|
8495
8555
|
getSelectedOrGroupedCell(arg1) === arg2,
|
|
8496
8556
|
);
|
|
8497
|
-
build({select, join, where, group, having, param});
|
|
8557
|
+
build({select, selectAll, join, where, group, having, param});
|
|
8498
8558
|
resultStore2.delTable(queryId);
|
|
8499
|
-
|
|
8500
|
-
if (collIsEmpty(selects)) {
|
|
8559
|
+
if (isEmpty(selectionEntries)) {
|
|
8501
8560
|
commit?.();
|
|
8502
8561
|
return queries;
|
|
8503
8562
|
}
|
|
@@ -8509,6 +8568,55 @@ const createQueries = getCreateFunction((store) => {
|
|
|
8509
8568
|
);
|
|
8510
8569
|
const groups = mapNew(groupEntries);
|
|
8511
8570
|
const hasGroupsOrHavings = !collIsEmpty(groups) || !isEmpty(havings);
|
|
8571
|
+
const selectEntries = [];
|
|
8572
|
+
const selectAllSources = stagedDefinition[3];
|
|
8573
|
+
const getSelectAllJoin = (joinedTableId) =>
|
|
8574
|
+
mapGet(
|
|
8575
|
+
joins,
|
|
8576
|
+
isUndefined(joinedTableId) || joinedTableId === tableId
|
|
8577
|
+
? void 0
|
|
8578
|
+
: joinedTableId,
|
|
8579
|
+
);
|
|
8580
|
+
arrayForEach(
|
|
8581
|
+
selectionEntries,
|
|
8582
|
+
([selectAll2, selectedOrJoinedTableId, clauseOrMapper]) => {
|
|
8583
|
+
if (selectAll2) {
|
|
8584
|
+
if (hasGroupsOrHavings) {
|
|
8585
|
+
ifNotUndefined(
|
|
8586
|
+
getSelectAllJoin(selectedOrJoinedTableId),
|
|
8587
|
+
([realTableId, , , , , sourceStore]) => {
|
|
8588
|
+
setAdd(
|
|
8589
|
+
mapEnsure(selectAllSources, sourceStore, setNew),
|
|
8590
|
+
realTableId,
|
|
8591
|
+
);
|
|
8592
|
+
arrayForEach(
|
|
8593
|
+
arraySort(sourceStore.getTableCellIds(realTableId)),
|
|
8594
|
+
(cellId) =>
|
|
8595
|
+
arrayPush(selectEntries, [
|
|
8596
|
+
clauseOrMapper(cellId),
|
|
8597
|
+
(getTableCell) =>
|
|
8598
|
+
isUndefined(selectedOrJoinedTableId) ||
|
|
8599
|
+
selectedOrJoinedTableId === tableId
|
|
8600
|
+
? getTableCell(cellId)
|
|
8601
|
+
: getTableCell(selectedOrJoinedTableId, cellId),
|
|
8602
|
+
]),
|
|
8603
|
+
);
|
|
8604
|
+
},
|
|
8605
|
+
);
|
|
8606
|
+
}
|
|
8607
|
+
} else {
|
|
8608
|
+
arrayPush(selectEntries, [
|
|
8609
|
+
selectedOrJoinedTableId,
|
|
8610
|
+
clauseOrMapper,
|
|
8611
|
+
]);
|
|
8612
|
+
}
|
|
8613
|
+
},
|
|
8614
|
+
);
|
|
8615
|
+
const selects = mapNew(selectEntries);
|
|
8616
|
+
if (hasGroupsOrHavings && collIsEmpty(selects)) {
|
|
8617
|
+
commit?.();
|
|
8618
|
+
return queries;
|
|
8619
|
+
}
|
|
8512
8620
|
const selectJoinWhereStore = hasGroupsOrHavings
|
|
8513
8621
|
? (stagedDefinition[2] = createStore())
|
|
8514
8622
|
: resultStore2;
|
|
@@ -8687,18 +8795,78 @@ const createQueries = getCreateFunction((store) => {
|
|
|
8687
8795
|
joinedCellId,
|
|
8688
8796
|
);
|
|
8689
8797
|
};
|
|
8690
|
-
selectJoinWhereStore.transaction(() =>
|
|
8691
|
-
arrayEvery(wheres, (where2) => where2(getJoinCell))
|
|
8692
|
-
|
|
8693
|
-
|
|
8694
|
-
|
|
8695
|
-
|
|
8696
|
-
|
|
8697
|
-
|
|
8698
|
-
|
|
8699
|
-
|
|
8700
|
-
|
|
8701
|
-
|
|
8798
|
+
selectJoinWhereStore.transaction(() => {
|
|
8799
|
+
if (!arrayEvery(wheres, (where2) => where2(getJoinCell))) {
|
|
8800
|
+
selectJoinWhereStore.delRow(queryId, rootRowId);
|
|
8801
|
+
} else if (hasGroupsOrHavings) {
|
|
8802
|
+
mapForEach(selects, (asCellId, tableCellGetter) =>
|
|
8803
|
+
selectJoinWhereStore._[5](
|
|
8804
|
+
queryId,
|
|
8805
|
+
rootRowId,
|
|
8806
|
+
asCellId,
|
|
8807
|
+
tableCellGetter(getJoinCell, rootRowId),
|
|
8808
|
+
),
|
|
8809
|
+
);
|
|
8810
|
+
} else if (hasSelectAll) {
|
|
8811
|
+
const resultRow = objNew();
|
|
8812
|
+
arrayForEach(
|
|
8813
|
+
selectionEntries,
|
|
8814
|
+
([selectAll2, selectedOrJoinedTableId, clauseOrMapper]) => {
|
|
8815
|
+
if (selectAll2) {
|
|
8816
|
+
ifNotUndefined(
|
|
8817
|
+
getSelectAllJoin(selectedOrJoinedTableId),
|
|
8818
|
+
([realTableId, , , , remoteIdPairs, sourceStore]) => {
|
|
8819
|
+
const sourceRowId =
|
|
8820
|
+
isUndefined(selectedOrJoinedTableId) ||
|
|
8821
|
+
selectedOrJoinedTableId === tableId
|
|
8822
|
+
? rootRowId
|
|
8823
|
+
: mapGet(remoteIdPairs, rootRowId)?.[0];
|
|
8824
|
+
ifNotUndefined(sourceRowId, (sourceRowId2) =>
|
|
8825
|
+
arrayForEach(
|
|
8826
|
+
arraySort(
|
|
8827
|
+
sourceStore.getCellIds(realTableId, sourceRowId2),
|
|
8828
|
+
),
|
|
8829
|
+
(cellId) =>
|
|
8830
|
+
objSet(
|
|
8831
|
+
resultRow,
|
|
8832
|
+
clauseOrMapper(cellId),
|
|
8833
|
+
sourceStore.getCell(
|
|
8834
|
+
realTableId,
|
|
8835
|
+
sourceRowId2,
|
|
8836
|
+
cellId,
|
|
8837
|
+
),
|
|
8838
|
+
),
|
|
8839
|
+
),
|
|
8840
|
+
);
|
|
8841
|
+
},
|
|
8842
|
+
);
|
|
8843
|
+
} else {
|
|
8844
|
+
const selectedCell = clauseOrMapper(getJoinCell, rootRowId);
|
|
8845
|
+
const selectedCellId = selectedOrJoinedTableId;
|
|
8846
|
+
if (isUndefined(selectedCell)) {
|
|
8847
|
+
objDel(resultRow, selectedCellId);
|
|
8848
|
+
} else {
|
|
8849
|
+
objSet(resultRow, selectedCellId, selectedCell);
|
|
8850
|
+
}
|
|
8851
|
+
}
|
|
8852
|
+
},
|
|
8853
|
+
);
|
|
8854
|
+
if (objIsEmpty(resultRow)) {
|
|
8855
|
+
selectJoinWhereStore.delRow(queryId, rootRowId);
|
|
8856
|
+
} else {
|
|
8857
|
+
selectJoinWhereStore.setRow(queryId, rootRowId, resultRow);
|
|
8858
|
+
}
|
|
8859
|
+
} else {
|
|
8860
|
+
mapForEach(selects, (asCellId, tableCellGetter) =>
|
|
8861
|
+
selectJoinWhereStore._[5](
|
|
8862
|
+
queryId,
|
|
8863
|
+
rootRowId,
|
|
8864
|
+
asCellId,
|
|
8865
|
+
tableCellGetter(getJoinCell, rootRowId),
|
|
8866
|
+
),
|
|
8867
|
+
);
|
|
8868
|
+
}
|
|
8869
|
+
});
|
|
8702
8870
|
};
|
|
8703
8871
|
const listenToTable = (
|
|
8704
8872
|
rootRowId,
|
|
@@ -8817,7 +8985,7 @@ const createQueries = getCreateFunction((store) => {
|
|
|
8817
8985
|
}),
|
|
8818
8986
|
);
|
|
8819
8987
|
const setQueryDefinitionImpl = (queryId, definition) => {
|
|
8820
|
-
const stagedDefinition = [mapNew(), mapNew()];
|
|
8988
|
+
const stagedDefinition = [mapNew(), mapNew(), void 0, mapNew(), setNew()];
|
|
8821
8989
|
let committed = false;
|
|
8822
8990
|
tryCatchSync(
|
|
8823
8991
|
() =>
|
|
@@ -8838,6 +9006,12 @@ const createQueries = getCreateFunction((store) => {
|
|
|
8838
9006
|
collIsEmpty(stagedDefinition[1]) ? void 0 : stagedDefinition[1],
|
|
8839
9007
|
);
|
|
8840
9008
|
mapSet(preStores, queryId, stagedDefinition[2]);
|
|
9009
|
+
syncSelectAllListeners(queryId, stagedDefinition[3]);
|
|
9010
|
+
mapSet(
|
|
9011
|
+
referencedQueryIds,
|
|
9012
|
+
queryId,
|
|
9013
|
+
collIsEmpty(stagedDefinition[4]) ? void 0 : stagedDefinition[4],
|
|
9014
|
+
);
|
|
8841
9015
|
committed = true;
|
|
8842
9016
|
}),
|
|
8843
9017
|
(error) => {
|
|
@@ -8887,6 +9061,8 @@ const createQueries = getCreateFunction((store) => {
|
|
|
8887
9061
|
paramStore.delRow(PARAMS_TABLE, queryId);
|
|
8888
9062
|
resetPreStores(queryId);
|
|
8889
9063
|
resetSourceStores(queryId);
|
|
9064
|
+
syncSelectAllListeners(queryId);
|
|
9065
|
+
mapSet(referencedQueryIds, queryId);
|
|
8890
9066
|
delDefinition(queryId);
|
|
8891
9067
|
cleanStores();
|
|
8892
9068
|
return queries;
|
package/package.json
CHANGED
package/queries/index.js
CHANGED
|
@@ -53,6 +53,7 @@ const arrayEvery = (array, cb) => array.every(cb);
|
|
|
53
53
|
const arrayIsEqual = (array1, array2) =>
|
|
54
54
|
size(array1) === size(array2) &&
|
|
55
55
|
arrayEvery(array1, (value1, index) => array2[index] === value1);
|
|
56
|
+
const arraySort = (array, sorter) => array.sort(sorter);
|
|
56
57
|
const arrayForEach = (array, cb) => array.forEach(cb);
|
|
57
58
|
const arraySum = (array) => arrayReduce(array, (i, j) => i + j, 0);
|
|
58
59
|
const arrayMax = (array) =>
|
|
@@ -111,6 +112,10 @@ const objNew = (entries = []) => {
|
|
|
111
112
|
arrayForEach(entries, ([id, value]) => objSet(obj, id, value));
|
|
112
113
|
return obj;
|
|
113
114
|
};
|
|
115
|
+
const objDel = (obj, id) => {
|
|
116
|
+
delete obj[id];
|
|
117
|
+
return obj;
|
|
118
|
+
};
|
|
114
119
|
const objForEach = (obj, cb) =>
|
|
115
120
|
arrayForEach(objIds(obj), (id) => cb(obj[id], id));
|
|
116
121
|
const objSize = (obj) => size(objIds(obj));
|
|
@@ -464,6 +469,8 @@ const createQueries = getCreateFunction((store) => {
|
|
|
464
469
|
};
|
|
465
470
|
const preStoreListenerIds = mapNew();
|
|
466
471
|
const sourceStoreListenerIds = mapNew();
|
|
472
|
+
const selectAllListenerIds = mapNew();
|
|
473
|
+
const referencedQueryIds = mapNew();
|
|
467
474
|
const {
|
|
468
475
|
_: [, addListener, callListeners],
|
|
469
476
|
delListener: delListenerImpl,
|
|
@@ -537,11 +544,42 @@ const createQueries = getCreateFunction((store) => {
|
|
|
537
544
|
resetStoreListeners(mapGet(sourceStoreListenerIds, queryId));
|
|
538
545
|
mapSet(sourceStoreListenerIds, queryId);
|
|
539
546
|
};
|
|
540
|
-
const
|
|
547
|
+
const syncSelectAllListeners = (queryId, nextSources = mapNew()) => {
|
|
548
|
+
const listenerIds = mapEnsure(selectAllListenerIds, queryId, mapNew);
|
|
549
|
+
mapForEach(listenerIds, (sourceStore, listenerIdsByTableId) => {
|
|
550
|
+
mapForEach(listenerIdsByTableId, (sourceTableId, listenerId) =>
|
|
551
|
+
collHas(mapGet(nextSources, sourceStore), sourceTableId)
|
|
552
|
+
? 0
|
|
553
|
+
: (sourceStore.delListener(listenerId),
|
|
554
|
+
mapSet(listenerIdsByTableId, sourceTableId)),
|
|
555
|
+
);
|
|
556
|
+
if (collIsEmpty(listenerIdsByTableId)) {
|
|
557
|
+
mapSet(listenerIds, sourceStore);
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
mapForEach(nextSources, (sourceStore, tableIds) => {
|
|
561
|
+
const listenerIdsByTableId = mapEnsure(listenerIds, sourceStore, mapNew);
|
|
562
|
+
collForEach(tableIds, (sourceTableId) =>
|
|
563
|
+
mapEnsure(listenerIdsByTableId, sourceTableId, () =>
|
|
564
|
+
sourceStore.addTableCellIdsListener(sourceTableId, () =>
|
|
565
|
+
setQueryDefinitionImpl(queryId),
|
|
566
|
+
),
|
|
567
|
+
),
|
|
568
|
+
);
|
|
569
|
+
});
|
|
570
|
+
if (collIsEmpty(listenerIds)) {
|
|
571
|
+
mapSet(selectAllListenerIds, queryId);
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
const isResultStoreReferenced = (queryId, resultStore2) =>
|
|
541
575
|
!(
|
|
542
576
|
collEvery(routedResultListeners, ([, storeListenerIds]) =>
|
|
543
577
|
collEvery(storeListenerIds, ([store2]) => store2 !== resultStore2),
|
|
544
578
|
) &&
|
|
579
|
+
collEvery(
|
|
580
|
+
referencedQueryIds,
|
|
581
|
+
(queryIds) => !collHas(queryIds, queryId),
|
|
582
|
+
) &&
|
|
545
583
|
arrayEvery(
|
|
546
584
|
[preStoreListenerIds, sourceStoreListenerIds],
|
|
547
585
|
(storeListenerIds) =>
|
|
@@ -556,7 +594,7 @@ const createQueries = getCreateFunction((store) => {
|
|
|
556
594
|
hasQuery(queryId) ? 0 : mapSet(preStores, queryId),
|
|
557
595
|
);
|
|
558
596
|
mapForEach(resultStores, (queryId, resultStore2) =>
|
|
559
|
-
hasQuery(queryId) || isResultStoreReferenced(resultStore2)
|
|
597
|
+
hasQuery(queryId) || isResultStoreReferenced(queryId, resultStore2)
|
|
560
598
|
? 0
|
|
561
599
|
: mapSet(resultStores, queryId),
|
|
562
600
|
);
|
|
@@ -638,7 +676,13 @@ const createQueries = getCreateFunction((store) => {
|
|
|
638
676
|
const rootStore = asQuery ? getResultStore(tableId) : store;
|
|
639
677
|
const resultStore2 = getResultStore(queryId);
|
|
640
678
|
const paramValues = definition?.[3] ?? getParamValues(queryId);
|
|
641
|
-
const
|
|
679
|
+
const nextReferencedQueryIds = stagedDefinition[4];
|
|
680
|
+
if (asQuery) {
|
|
681
|
+
setAdd(nextReferencedQueryIds, tableId);
|
|
682
|
+
}
|
|
683
|
+
const selectionEntries = [];
|
|
684
|
+
let hasSelectAll = false;
|
|
685
|
+
let selectCount = 0;
|
|
642
686
|
const joinEntries = [
|
|
643
687
|
[void 0, [tableId, void 0, void 0, [], mapNew(), rootStore]],
|
|
644
688
|
];
|
|
@@ -650,21 +694,35 @@ const createQueries = getCreateFunction((store) => {
|
|
|
650
694
|
const joinedTableId = isTrue(arg1) ? arg2 : arg1;
|
|
651
695
|
const joinedCellId = isTrue(arg1) ? arg3 : arg2;
|
|
652
696
|
const selectEntry = isFunction(arg1)
|
|
653
|
-
? [
|
|
697
|
+
? [0, selectCount + EMPTY_STRING, arg1]
|
|
654
698
|
: isUndefined(joinedCellId)
|
|
655
|
-
? [arg1, (getTableCell) => getTableCell(arg1)]
|
|
699
|
+
? [0, arg1, (getTableCell) => getTableCell(arg1)]
|
|
656
700
|
: [
|
|
701
|
+
0,
|
|
657
702
|
joinedCellId,
|
|
658
703
|
(getTableCell) =>
|
|
659
704
|
isTrue(arg1)
|
|
660
705
|
? getTableCell(true, joinedTableId, joinedCellId)
|
|
661
706
|
: getTableCell(joinedTableId, joinedCellId),
|
|
662
707
|
];
|
|
663
|
-
|
|
708
|
+
selectCount++;
|
|
709
|
+
arrayPush(selectionEntries, selectEntry);
|
|
664
710
|
return {
|
|
665
|
-
as: (selectedCellId) => (selectEntry[
|
|
711
|
+
as: (selectedCellId) => (selectEntry[1] = selectedCellId),
|
|
666
712
|
};
|
|
667
713
|
};
|
|
714
|
+
const selectAll = (arg1, arg2, arg3) => {
|
|
715
|
+
hasSelectAll = true;
|
|
716
|
+
const joinedTableId = isTrue(arg1) ? arg2 : arg1;
|
|
717
|
+
const prefixOrMapper = isTrue(arg1) ? arg3 : arg2;
|
|
718
|
+
arrayPush(selectionEntries, [
|
|
719
|
+
1,
|
|
720
|
+
joinedTableId,
|
|
721
|
+
isFunction(prefixOrMapper)
|
|
722
|
+
? prefixOrMapper
|
|
723
|
+
: (cellId) => (prefixOrMapper ?? EMPTY_STRING) + cellId,
|
|
724
|
+
]);
|
|
725
|
+
};
|
|
668
726
|
const join = (arg1, arg2, arg3, arg4) => {
|
|
669
727
|
const joinedTableId = isTrue(arg1) ? arg2 : arg1;
|
|
670
728
|
const [fromJoinAlias, onArg] = isTrue(arg1)
|
|
@@ -674,6 +732,13 @@ const createQueries = getCreateFunction((store) => {
|
|
|
674
732
|
: isUndefined(arg3) || isFunction(arg2)
|
|
675
733
|
? [void 0, arg2]
|
|
676
734
|
: [arg2, arg3];
|
|
735
|
+
const sourceIsQuery = isTrue(arg1);
|
|
736
|
+
const sourceStore = sourceIsQuery
|
|
737
|
+
? getResultStore(joinedTableId)
|
|
738
|
+
: store;
|
|
739
|
+
if (sourceIsQuery) {
|
|
740
|
+
setAdd(nextReferencedQueryIds, joinedTableId);
|
|
741
|
+
}
|
|
677
742
|
const joinEntry = [
|
|
678
743
|
joinedTableId,
|
|
679
744
|
[
|
|
@@ -682,7 +747,7 @@ const createQueries = getCreateFunction((store) => {
|
|
|
682
747
|
isFunction(onArg) ? onArg : (getCell) => getCell(onArg),
|
|
683
748
|
[],
|
|
684
749
|
mapNew(),
|
|
685
|
-
|
|
750
|
+
sourceStore,
|
|
686
751
|
],
|
|
687
752
|
];
|
|
688
753
|
arrayPush(joinEntries, joinEntry);
|
|
@@ -728,10 +793,9 @@ const createQueries = getCreateFunction((store) => {
|
|
|
728
793
|
: (getSelectedOrGroupedCell) =>
|
|
729
794
|
getSelectedOrGroupedCell(arg1) === arg2,
|
|
730
795
|
);
|
|
731
|
-
build({select, join, where, group, having, param});
|
|
796
|
+
build({select, selectAll, join, where, group, having, param});
|
|
732
797
|
resultStore2.delTable(queryId);
|
|
733
|
-
|
|
734
|
-
if (collIsEmpty(selects)) {
|
|
798
|
+
if (isEmpty(selectionEntries)) {
|
|
735
799
|
commit?.();
|
|
736
800
|
return queries;
|
|
737
801
|
}
|
|
@@ -743,6 +807,55 @@ const createQueries = getCreateFunction((store) => {
|
|
|
743
807
|
);
|
|
744
808
|
const groups = mapNew(groupEntries);
|
|
745
809
|
const hasGroupsOrHavings = !collIsEmpty(groups) || !isEmpty(havings);
|
|
810
|
+
const selectEntries = [];
|
|
811
|
+
const selectAllSources = stagedDefinition[3];
|
|
812
|
+
const getSelectAllJoin = (joinedTableId) =>
|
|
813
|
+
mapGet(
|
|
814
|
+
joins,
|
|
815
|
+
isUndefined(joinedTableId) || joinedTableId === tableId
|
|
816
|
+
? void 0
|
|
817
|
+
: joinedTableId,
|
|
818
|
+
);
|
|
819
|
+
arrayForEach(
|
|
820
|
+
selectionEntries,
|
|
821
|
+
([selectAll2, selectedOrJoinedTableId, clauseOrMapper]) => {
|
|
822
|
+
if (selectAll2) {
|
|
823
|
+
if (hasGroupsOrHavings) {
|
|
824
|
+
ifNotUndefined(
|
|
825
|
+
getSelectAllJoin(selectedOrJoinedTableId),
|
|
826
|
+
([realTableId, , , , , sourceStore]) => {
|
|
827
|
+
setAdd(
|
|
828
|
+
mapEnsure(selectAllSources, sourceStore, setNew),
|
|
829
|
+
realTableId,
|
|
830
|
+
);
|
|
831
|
+
arrayForEach(
|
|
832
|
+
arraySort(sourceStore.getTableCellIds(realTableId)),
|
|
833
|
+
(cellId) =>
|
|
834
|
+
arrayPush(selectEntries, [
|
|
835
|
+
clauseOrMapper(cellId),
|
|
836
|
+
(getTableCell) =>
|
|
837
|
+
isUndefined(selectedOrJoinedTableId) ||
|
|
838
|
+
selectedOrJoinedTableId === tableId
|
|
839
|
+
? getTableCell(cellId)
|
|
840
|
+
: getTableCell(selectedOrJoinedTableId, cellId),
|
|
841
|
+
]),
|
|
842
|
+
);
|
|
843
|
+
},
|
|
844
|
+
);
|
|
845
|
+
}
|
|
846
|
+
} else {
|
|
847
|
+
arrayPush(selectEntries, [
|
|
848
|
+
selectedOrJoinedTableId,
|
|
849
|
+
clauseOrMapper,
|
|
850
|
+
]);
|
|
851
|
+
}
|
|
852
|
+
},
|
|
853
|
+
);
|
|
854
|
+
const selects = mapNew(selectEntries);
|
|
855
|
+
if (hasGroupsOrHavings && collIsEmpty(selects)) {
|
|
856
|
+
commit?.();
|
|
857
|
+
return queries;
|
|
858
|
+
}
|
|
746
859
|
const selectJoinWhereStore = hasGroupsOrHavings
|
|
747
860
|
? (stagedDefinition[2] = createStore())
|
|
748
861
|
: resultStore2;
|
|
@@ -921,18 +1034,78 @@ const createQueries = getCreateFunction((store) => {
|
|
|
921
1034
|
joinedCellId,
|
|
922
1035
|
);
|
|
923
1036
|
};
|
|
924
|
-
selectJoinWhereStore.transaction(() =>
|
|
925
|
-
arrayEvery(wheres, (where2) => where2(getJoinCell))
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
1037
|
+
selectJoinWhereStore.transaction(() => {
|
|
1038
|
+
if (!arrayEvery(wheres, (where2) => where2(getJoinCell))) {
|
|
1039
|
+
selectJoinWhereStore.delRow(queryId, rootRowId);
|
|
1040
|
+
} else if (hasGroupsOrHavings) {
|
|
1041
|
+
mapForEach(selects, (asCellId, tableCellGetter) =>
|
|
1042
|
+
selectJoinWhereStore._[5](
|
|
1043
|
+
queryId,
|
|
1044
|
+
rootRowId,
|
|
1045
|
+
asCellId,
|
|
1046
|
+
tableCellGetter(getJoinCell, rootRowId),
|
|
1047
|
+
),
|
|
1048
|
+
);
|
|
1049
|
+
} else if (hasSelectAll) {
|
|
1050
|
+
const resultRow = objNew();
|
|
1051
|
+
arrayForEach(
|
|
1052
|
+
selectionEntries,
|
|
1053
|
+
([selectAll2, selectedOrJoinedTableId, clauseOrMapper]) => {
|
|
1054
|
+
if (selectAll2) {
|
|
1055
|
+
ifNotUndefined(
|
|
1056
|
+
getSelectAllJoin(selectedOrJoinedTableId),
|
|
1057
|
+
([realTableId, , , , remoteIdPairs, sourceStore]) => {
|
|
1058
|
+
const sourceRowId =
|
|
1059
|
+
isUndefined(selectedOrJoinedTableId) ||
|
|
1060
|
+
selectedOrJoinedTableId === tableId
|
|
1061
|
+
? rootRowId
|
|
1062
|
+
: mapGet(remoteIdPairs, rootRowId)?.[0];
|
|
1063
|
+
ifNotUndefined(sourceRowId, (sourceRowId2) =>
|
|
1064
|
+
arrayForEach(
|
|
1065
|
+
arraySort(
|
|
1066
|
+
sourceStore.getCellIds(realTableId, sourceRowId2),
|
|
1067
|
+
),
|
|
1068
|
+
(cellId) =>
|
|
1069
|
+
objSet(
|
|
1070
|
+
resultRow,
|
|
1071
|
+
clauseOrMapper(cellId),
|
|
1072
|
+
sourceStore.getCell(
|
|
1073
|
+
realTableId,
|
|
1074
|
+
sourceRowId2,
|
|
1075
|
+
cellId,
|
|
1076
|
+
),
|
|
1077
|
+
),
|
|
1078
|
+
),
|
|
1079
|
+
);
|
|
1080
|
+
},
|
|
1081
|
+
);
|
|
1082
|
+
} else {
|
|
1083
|
+
const selectedCell = clauseOrMapper(getJoinCell, rootRowId);
|
|
1084
|
+
const selectedCellId = selectedOrJoinedTableId;
|
|
1085
|
+
if (isUndefined(selectedCell)) {
|
|
1086
|
+
objDel(resultRow, selectedCellId);
|
|
1087
|
+
} else {
|
|
1088
|
+
objSet(resultRow, selectedCellId, selectedCell);
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
},
|
|
1092
|
+
);
|
|
1093
|
+
if (objIsEmpty(resultRow)) {
|
|
1094
|
+
selectJoinWhereStore.delRow(queryId, rootRowId);
|
|
1095
|
+
} else {
|
|
1096
|
+
selectJoinWhereStore.setRow(queryId, rootRowId, resultRow);
|
|
1097
|
+
}
|
|
1098
|
+
} else {
|
|
1099
|
+
mapForEach(selects, (asCellId, tableCellGetter) =>
|
|
1100
|
+
selectJoinWhereStore._[5](
|
|
1101
|
+
queryId,
|
|
1102
|
+
rootRowId,
|
|
1103
|
+
asCellId,
|
|
1104
|
+
tableCellGetter(getJoinCell, rootRowId),
|
|
1105
|
+
),
|
|
1106
|
+
);
|
|
1107
|
+
}
|
|
1108
|
+
});
|
|
936
1109
|
};
|
|
937
1110
|
const listenToTable = (
|
|
938
1111
|
rootRowId,
|
|
@@ -1051,7 +1224,7 @@ const createQueries = getCreateFunction((store) => {
|
|
|
1051
1224
|
}),
|
|
1052
1225
|
);
|
|
1053
1226
|
const setQueryDefinitionImpl = (queryId, definition) => {
|
|
1054
|
-
const stagedDefinition = [mapNew(), mapNew()];
|
|
1227
|
+
const stagedDefinition = [mapNew(), mapNew(), void 0, mapNew(), setNew()];
|
|
1055
1228
|
let committed = false;
|
|
1056
1229
|
tryCatchSync(
|
|
1057
1230
|
() =>
|
|
@@ -1072,6 +1245,12 @@ const createQueries = getCreateFunction((store) => {
|
|
|
1072
1245
|
collIsEmpty(stagedDefinition[1]) ? void 0 : stagedDefinition[1],
|
|
1073
1246
|
);
|
|
1074
1247
|
mapSet(preStores, queryId, stagedDefinition[2]);
|
|
1248
|
+
syncSelectAllListeners(queryId, stagedDefinition[3]);
|
|
1249
|
+
mapSet(
|
|
1250
|
+
referencedQueryIds,
|
|
1251
|
+
queryId,
|
|
1252
|
+
collIsEmpty(stagedDefinition[4]) ? void 0 : stagedDefinition[4],
|
|
1253
|
+
);
|
|
1075
1254
|
committed = true;
|
|
1076
1255
|
}),
|
|
1077
1256
|
(error) => {
|
|
@@ -1121,6 +1300,8 @@ const createQueries = getCreateFunction((store) => {
|
|
|
1121
1300
|
paramStore.delRow(PARAMS_TABLE, queryId);
|
|
1122
1301
|
resetPreStores(queryId);
|
|
1123
1302
|
resetSourceStores(queryId);
|
|
1303
|
+
syncSelectAllListeners(queryId);
|
|
1304
|
+
mapSet(referencedQueryIds, queryId);
|
|
1124
1305
|
delDefinition(queryId);
|
|
1125
1306
|
cleanStores();
|
|
1126
1307
|
return queries;
|