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.
Files changed (47) hide show
  1. package/@types/queries/index.d.ts +141 -0
  2. package/@types/queries/with-schemas/index.d.ts +184 -0
  3. package/index.js +594 -418
  4. package/indexes/index.js +8 -22
  5. package/indexes/with-schemas/index.js +8 -22
  6. package/metrics/index.js +8 -22
  7. package/metrics/with-schemas/index.js +8 -22
  8. package/min/index.js +1 -1
  9. package/min/index.js.gz +0 -0
  10. package/min/indexes/index.js +1 -1
  11. package/min/indexes/index.js.gz +0 -0
  12. package/min/indexes/with-schemas/index.js +1 -1
  13. package/min/indexes/with-schemas/index.js.gz +0 -0
  14. package/min/metrics/index.js +1 -1
  15. package/min/metrics/index.js.gz +0 -0
  16. package/min/metrics/with-schemas/index.js +1 -1
  17. package/min/metrics/with-schemas/index.js.gz +0 -0
  18. package/min/omni/index.js +1 -1
  19. package/min/omni/index.js.gz +0 -0
  20. package/min/omni/with-schemas/index.js +1 -1
  21. package/min/omni/with-schemas/index.js.gz +0 -0
  22. package/min/queries/index.js +1 -1
  23. package/min/queries/index.js.gz +0 -0
  24. package/min/queries/with-schemas/index.js +1 -1
  25. package/min/queries/with-schemas/index.js.gz +0 -0
  26. package/min/relationships/index.js +1 -1
  27. package/min/relationships/index.js.gz +0 -0
  28. package/min/relationships/with-schemas/index.js +1 -1
  29. package/min/relationships/with-schemas/index.js.gz +0 -0
  30. package/min/with-schemas/index.js +1 -1
  31. package/min/with-schemas/index.js.gz +0 -0
  32. package/omni/index.js +594 -418
  33. package/omni/with-schemas/index.js +594 -418
  34. package/package.json +10 -10
  35. package/queries/index.js +596 -454
  36. package/queries/with-schemas/index.js +596 -454
  37. package/readme.md +14 -14
  38. package/relationships/index.js +8 -22
  39. package/relationships/with-schemas/index.js +8 -22
  40. package/releases.md +51 -51
  41. package/ui-svelte/index.js +1 -1
  42. package/ui-svelte/with-schemas/index.js +1 -1
  43. package/ui-svelte-dom/index.js +2 -2
  44. package/ui-svelte-dom/with-schemas/index.js +2 -2
  45. package/ui-svelte-inspector/index.js +2 -2
  46. package/ui-svelte-inspector/with-schemas/index.js +2 -2
  47. package/with-schemas/index.js +594 -418
@@ -119,10 +119,6 @@ const arrayEvery = (array, cb) => array.every(cb);
119
119
  const arrayIsEqual = (array1, array2) =>
120
120
  size(array1) === size(array2) &&
121
121
  arrayEvery(array1, (value1, index) => array2[index] === value1);
122
- const arrayOrValueEqual = (value1, value2) =>
123
- isArray(value1) && isArray(value2)
124
- ? arrayIsEqual(value1, value2)
125
- : value1 === value2;
126
122
  const arrayIsSorted = (array, sorter) =>
127
123
  arrayEvery(
128
124
  array,
@@ -180,7 +176,6 @@ const objDel = (obj, id) => {
180
176
  delete obj[id];
181
177
  return obj;
182
178
  };
183
- const objToMap = (obj) => new Map(objEntries(obj));
184
179
  const objForEach = (obj, cb) =>
185
180
  arrayForEach(objEntries(obj), ([id, value]) => cb(value, id));
186
181
  const objToArray = (obj, cb) =>
@@ -341,27 +336,17 @@ const getDefinableFunctions = (
341
336
  const getTableId = (id) => mapGet(tableIds, id);
342
337
  const getThing = (id) => mapGet(things, id);
343
338
  const setThing = (id, thing) => mapSet(things, id, thing);
344
- const addStoreListeners = (id, andCall, ...listenerIds) => {
339
+ const addStoreListeners = (id, ...listenerIds) => {
345
340
  const set = mapEnsure(storeListenerIds, id, setNew);
346
- arrayForEach(
347
- listenerIds,
348
- (listenerId) =>
349
- setAdd(set, listenerId) && andCall && store.callListener(listenerId),
350
- );
351
- return listenerIds;
341
+ arrayForEach(listenerIds, (listenerId) => setAdd(set, listenerId));
352
342
  };
353
- const delStoreListeners = (id, ...listenerIds) =>
343
+ const delStoreListeners = (id) =>
354
344
  ifNotUndefined(mapGet(storeListenerIds, id), (allListenerIds) => {
355
- arrayForEach(
356
- arrayIsEmpty(listenerIds) ? collValues(allListenerIds) : listenerIds,
357
- (listenerId) => {
358
- store.delListener(listenerId);
359
- collDel(allListenerIds, listenerId);
360
- },
361
- );
362
- if (collIsEmpty(allListenerIds)) {
363
- mapSet(storeListenerIds, id);
364
- }
345
+ arrayForEach(collValues(allListenerIds), (listenerId) => {
346
+ store.delListener(listenerId);
347
+ collDel(allListenerIds, listenerId);
348
+ });
349
+ mapSet(storeListenerIds, id);
365
350
  });
366
351
  const setDefinition = (id, tableId) => {
367
352
  mapSet(tableIds, id, tableId);
@@ -441,7 +426,6 @@ const getDefinableFunctions = (
441
426
  delStoreListeners(id);
442
427
  addStoreListeners(
443
428
  id,
444
- 0,
445
429
  store.addRowListener(tableId, null, (_store, _tableId, rowId) =>
446
430
  processRow(rowId),
447
431
  ),
@@ -472,8 +456,6 @@ const getDefinableFunctions = (
472
456
  delDefinition,
473
457
  addThingIdsListener,
474
458
  destroy,
475
- addStoreListeners,
476
- delStoreListeners,
477
459
  ];
478
460
  };
479
461
  const getRowCellFunction = (getRowCell, defaultCellValue) =>
@@ -6326,13 +6308,29 @@ const createYjsPersister = (
6326
6308
  );
6327
6309
  };
6328
6310
 
6311
+ const PARAMS_TABLE = '_';
6312
+ const PARAM_LISTENER_PREFIX = 'p';
6329
6313
  const createQueries = getCreateFunction((store) => {
6330
6314
  const createStore = store._[0];
6331
6315
  const preStore = createStore();
6316
+ const paramStore = createStore();
6332
6317
  const resultStore = createStore();
6318
+ const resultStores = mapNew();
6319
+ const redefiningQueryIds = setNew();
6320
+ const routedResultListeners = mapNew();
6321
+ const routedResultListenerIds = mapNew();
6322
+ const resultListenerStats = {
6323
+ table: 0,
6324
+ tableCellIds: 0,
6325
+ rowCount: 0,
6326
+ rowIds: 0,
6327
+ sortedRowIds: 0,
6328
+ row: 0,
6329
+ cellIds: 0,
6330
+ cell: 0,
6331
+ };
6333
6332
  const preStoreListenerIds = mapNew();
6334
- const paramValuesListeners = mapNew();
6335
- const paramValueListeners = mapNew();
6333
+ const sourceStoreListenerIds = mapNew();
6336
6334
  const {
6337
6335
  _: [, addListener, callListeners],
6338
6336
  delListener: delListenerImpl,
@@ -6349,9 +6347,7 @@ const createQueries = getCreateFunction((store) => {
6349
6347
  ,
6350
6348
  delDefinition,
6351
6349
  addQueryIdsListenerImpl,
6352
- destroy,
6353
- addStoreListeners,
6354
- delStoreListeners,
6350
+ destroyImpl,
6355
6351
  ] = getDefinableFunctions(
6356
6352
  store,
6357
6353
  () => [],
@@ -6359,6 +6355,8 @@ const createQueries = getCreateFunction((store) => {
6359
6355
  addListener,
6360
6356
  callListeners,
6361
6357
  );
6358
+ const getResultStore = (queryId) =>
6359
+ mapEnsure(resultStores, queryId, createStore);
6362
6360
  const addPreStoreListener = (preStore2, queryId, ...listenerIds) =>
6363
6361
  arrayForEach(listenerIds, (listenerId) =>
6364
6362
  setAdd(
@@ -6382,8 +6380,49 @@ const createQueries = getCreateFunction((store) => {
6382
6380
  collClear(queryPreStoreListenerIds);
6383
6381
  },
6384
6382
  );
6385
- arrayForEach([resultStore, preStore], (store2) => store2.delTable(queryId));
6383
+ arrayForEach([getResultStore(queryId), preStore], (store2) =>
6384
+ store2.delTable(queryId),
6385
+ );
6386
+ };
6387
+ const addSourceStoreListeners = (
6388
+ sourceStore,
6389
+ queryId,
6390
+ andCall,
6391
+ ...listenerIds
6392
+ ) => {
6393
+ const listenerIdSet = mapEnsure(
6394
+ mapEnsure(sourceStoreListenerIds, queryId, mapNew),
6395
+ sourceStore,
6396
+ setNew,
6397
+ );
6398
+ arrayForEach(listenerIds, (listenerId) => {
6399
+ setAdd(listenerIdSet, listenerId);
6400
+ if (andCall) {
6401
+ sourceStore.callListener(listenerId);
6402
+ }
6403
+ });
6404
+ return listenerIds;
6386
6405
  };
6406
+ const delSourceStoreListeners = (queryId, sourceStore, listenerId) =>
6407
+ ifNotUndefined(
6408
+ mapGet(mapGet(sourceStoreListenerIds, queryId), sourceStore),
6409
+ (allListenerIds) => {
6410
+ sourceStore.delListener(listenerId);
6411
+ collDel(allListenerIds, listenerId);
6412
+ if (collIsEmpty(allListenerIds)) {
6413
+ mapSet(mapGet(sourceStoreListenerIds, queryId), sourceStore);
6414
+ }
6415
+ },
6416
+ );
6417
+ const resetSourceStores = (queryId) =>
6418
+ ifNotUndefined(mapGet(sourceStoreListenerIds, queryId), (queryStoreIds) => {
6419
+ mapForEach(queryStoreIds, (sourceStore, listenerIds) =>
6420
+ collForEach(listenerIds, (listenerId) =>
6421
+ sourceStore.delListener(listenerId),
6422
+ ),
6423
+ );
6424
+ collClear(queryStoreIds);
6425
+ });
6387
6426
  const synchronizeTransactions = (queryId, fromStore, toStore) =>
6388
6427
  addPreStoreListener(
6389
6428
  fromStore,
@@ -6393,424 +6432,549 @@ const createQueries = getCreateFunction((store) => {
6393
6432
  toStore.finishTransaction(),
6394
6433
  ),
6395
6434
  );
6396
- const setQueryDefinition = (queryId, tableId, build, paramValues = {}) => {
6397
- const oldParamValues = getParamValues(queryId);
6398
- setDefinition(queryId, tableId);
6399
- setQueryArgs(queryId, [build, objToMap(paramValues)]);
6400
- callParamListeners(queryId, oldParamValues, paramValues);
6401
- resetPreStores(queryId);
6402
- const [, paramsMap] = getQueryArgs(queryId);
6403
- const selectEntries = [];
6404
- const joinEntries = [[void 0, [tableId, void 0, void 0, [], mapNew()]]];
6405
- const wheres = [];
6406
- const groupEntries = [];
6407
- const havings = [];
6408
- const param = (paramId) => mapGet(paramsMap, paramId);
6409
- const select = (arg1, arg2) => {
6410
- const selectEntry = isFunction(arg1)
6411
- ? [size(selectEntries) + EMPTY_STRING, arg1]
6412
- : [
6413
- isUndefined(arg2) ? arg1 : arg2,
6414
- (getTableCell) => getTableCell(arg1, arg2),
6415
- ];
6416
- arrayPush(selectEntries, selectEntry);
6417
- return {as: (selectedCellId) => (selectEntry[0] = selectedCellId)};
6418
- };
6419
- const join = (joinedTableId, arg1, arg2) => {
6420
- const fromIntermediateJoinedTableId =
6421
- isUndefined(arg2) || isFunction(arg1) ? void 0 : arg1;
6422
- const onArg = isUndefined(fromIntermediateJoinedTableId) ? arg1 : arg2;
6423
- const joinEntry = [
6424
- joinedTableId,
6425
- [
6426
- joinedTableId,
6427
- fromIntermediateJoinedTableId,
6428
- isFunction(onArg) ? onArg : (getCell) => getCell(onArg),
6429
- [],
6430
- mapNew(),
6431
- ],
6432
- ];
6433
- arrayPush(joinEntries, joinEntry);
6434
- return {as: (joinedTableId2) => (joinEntry[0] = joinedTableId2)};
6435
- };
6436
- const where = (arg1, arg2, arg3) =>
6437
- arrayPush(
6438
- wheres,
6439
- isFunction(arg1)
6440
- ? arg1
6441
- : isUndefined(arg3)
6442
- ? (getTableCell) => getTableCell(arg1) === arg2
6443
- : (getTableCell) => getTableCell(arg1, arg2) === arg3,
6444
- );
6445
- const group = (
6446
- selectedCellId,
6447
- aggregate,
6448
- aggregateAdd,
6449
- aggregateRemove,
6450
- aggregateReplace,
6451
- ) => {
6452
- const groupEntry = [
6453
- selectedCellId,
6454
- [
6455
- selectedCellId,
6456
- isFunction(aggregate)
6457
- ? [aggregate, aggregateAdd, aggregateRemove, aggregateReplace]
6458
- : (mapGet(numericAggregators, aggregate) ?? [
6459
- (_cells, length) => length,
6460
- ]),
6461
- ],
6462
- ];
6463
- arrayPush(groupEntries, groupEntry);
6464
- return {as: (groupedCellId) => (groupEntry[0] = groupedCellId)};
6465
- };
6466
- const having = (arg1, arg2) =>
6467
- arrayPush(
6468
- havings,
6469
- isFunction(arg1)
6470
- ? arg1
6471
- : (getSelectedOrGroupedCell) =>
6472
- getSelectedOrGroupedCell(arg1) === arg2,
6473
- );
6474
- build({select, join, where, group, having, param});
6475
- const selects = mapNew(selectEntries);
6476
- if (collIsEmpty(selects)) {
6477
- return queries;
6478
- }
6479
- const joins = mapNew(joinEntries);
6480
- mapForEach(joins, (asTableId, [, fromAsTableId]) =>
6481
- ifNotUndefined(mapGet(joins, fromAsTableId), ({3: toAsTableIds}) =>
6482
- isUndefined(asTableId) ? 0 : arrayPush(toAsTableIds, asTableId),
6483
- ),
6435
+ const setOrDelParamValues = (queryId, paramValues) =>
6436
+ (objIsEmpty(paramValues) ? paramStore.delRow : paramStore.setRow)(
6437
+ PARAMS_TABLE,
6438
+ queryId,
6439
+ {...paramValues},
6484
6440
  );
6485
- const groups = mapNew(groupEntries);
6486
- let selectJoinWhereStore = preStore;
6487
- if (collIsEmpty(groups) && arrayIsEmpty(havings)) {
6488
- selectJoinWhereStore = resultStore;
6489
- } else {
6490
- synchronizeTransactions(queryId, selectJoinWhereStore, resultStore);
6491
- const groupedSelectedCellIds = mapNew();
6492
- mapForEach(groups, (groupedCellId, [selectedCellId, aggregators]) =>
6493
- setAdd(mapEnsure(groupedSelectedCellIds, selectedCellId, setNew), [
6494
- groupedCellId,
6495
- aggregators,
6496
- ]),
6441
+ const addRoutedResultListener = (stat, queryId, addStoreListener) => {
6442
+ const listenerId = addListener(getUndefined, routedResultListenerIds);
6443
+ const storeListenerIds = mapNew();
6444
+ const syncStoreListeners = () => {
6445
+ const queryIds = queryId == null ? getQueryIds() : [queryId];
6446
+ arrayForEach(queryIds, (queryId2) =>
6447
+ collHas(storeListenerIds, queryId2)
6448
+ ? 0
6449
+ : mapSet(storeListenerIds, queryId2, [
6450
+ getResultStore(queryId2),
6451
+ addStoreListener(getResultStore(queryId2), queryId2),
6452
+ ]),
6497
6453
  );
6498
- const groupBySelectedCellIds = setNew();
6499
- mapForEach(selects, (selectedCellId) =>
6500
- collHas(groupedSelectedCellIds, selectedCellId)
6454
+ mapForEach(storeListenerIds, (storeQueryId, [store2, storeListenerId]) =>
6455
+ (queryId == null && hasQuery(storeQueryId)) || storeQueryId == queryId
6501
6456
  ? 0
6502
- : setAdd(groupBySelectedCellIds, selectedCellId),
6457
+ : (() => {
6458
+ store2.delListener(storeListenerId);
6459
+ mapSet(storeListenerIds, storeQueryId);
6460
+ })(),
6503
6461
  );
6504
- const tree = mapNew();
6505
- const writeGroupRow = (
6506
- leaf,
6507
- changedGroupedSelectedCells,
6508
- selectedRowId,
6509
- forceRemove,
6510
- ) =>
6511
- ifNotUndefined(
6512
- leaf,
6513
- ([selectedCells, selectedRowIds, groupRowId, groupRow]) => {
6514
- mapForEach(
6515
- changedGroupedSelectedCells,
6516
- (selectedCellId, [newCell]) => {
6517
- const selectedCell = mapEnsure(
6518
- selectedCells,
6519
- selectedCellId,
6520
- mapNew,
6521
- );
6522
- const oldLeafCell = mapGet(selectedCell, selectedRowId);
6523
- const newLeafCell = forceRemove ? void 0 : newCell;
6524
- if (oldLeafCell !== newLeafCell) {
6525
- const oldNewSet = setNew([[oldLeafCell, newLeafCell]]);
6526
- const oldLength = collSize(selectedCell);
6527
- mapSet(selectedCell, selectedRowId, newLeafCell);
6528
- collForEach(
6529
- mapGet(groupedSelectedCellIds, selectedCellId),
6530
- ([groupedCellId, aggregators]) => {
6531
- const aggregateValue = getAggregateValue(
6532
- groupRow[groupedCellId],
6533
- oldLength,
6534
- selectedCell,
6535
- oldNewSet,
6536
- aggregators,
6462
+ };
6463
+ syncStoreListeners();
6464
+ mapSet(routedResultListeners, listenerId, [
6465
+ stat,
6466
+ storeListenerIds,
6467
+ queryId == null ? addQueryIdsListenerImpl(syncStoreListeners) : void 0,
6468
+ ]);
6469
+ resultListenerStats[stat]++;
6470
+ return listenerId;
6471
+ };
6472
+ const setQueryDefinition = (
6473
+ queryId,
6474
+ tableIdOrAsQuery,
6475
+ tableIdOrBuild,
6476
+ buildOrParamValues,
6477
+ paramValuesIfSourceIsQuery = {},
6478
+ ) => {
6479
+ const [tableId, build, sourceIsQuery, paramValues] = isTrue(
6480
+ tableIdOrAsQuery,
6481
+ )
6482
+ ? [tableIdOrBuild, buildOrParamValues, 1, paramValuesIfSourceIsQuery]
6483
+ : [tableIdOrAsQuery, tableIdOrBuild, 0, buildOrParamValues ?? {}];
6484
+ ifNotUndefined(getQueryArgs(queryId), ([, listenerId]) =>
6485
+ paramStore.delListener(listenerId),
6486
+ );
6487
+ setDefinition(queryId, tableId);
6488
+ setQueryArgs(queryId, [
6489
+ build,
6490
+ paramStore.addRowListener(PARAMS_TABLE, queryId, () =>
6491
+ setQueryDefinitionImpl(queryId),
6492
+ ),
6493
+ sourceIsQuery,
6494
+ ]);
6495
+ setOrDelParamValues(queryId, paramValues);
6496
+ setQueryDefinitionImpl(queryId);
6497
+ return queries;
6498
+ };
6499
+ const setQueryDefinitionImpl = (queryId) =>
6500
+ getResultStore(queryId).transaction(() =>
6501
+ ifNotUndefined(getQueryArgs(queryId), ([build, , sourceIsQuery]) => {
6502
+ const tableId = getTableId(queryId);
6503
+ const rootStore = sourceIsQuery ? getResultStore(tableId) : store;
6504
+ const resultStore2 = getResultStore(queryId);
6505
+ const paramValues = getParamValues(queryId);
6506
+ setAdd(redefiningQueryIds, queryId);
6507
+ resetPreStores(queryId);
6508
+ resetSourceStores(queryId);
6509
+ const selectEntries = [];
6510
+ const joinEntries = [
6511
+ [void 0, [tableId, void 0, void 0, [], mapNew(), rootStore]],
6512
+ ];
6513
+ const wheres = [];
6514
+ const groupEntries = [];
6515
+ const havings = [];
6516
+ const param = (paramId) => objGet(paramValues, paramId);
6517
+ const select = (arg1, arg2, arg3) => {
6518
+ const joinedTableId = isTrue(arg1) ? arg2 : arg1;
6519
+ const joinedCellId = isTrue(arg1) ? arg3 : arg2;
6520
+ const selectEntry = isFunction(arg1)
6521
+ ? [size(selectEntries) + EMPTY_STRING, arg1]
6522
+ : isUndefined(joinedCellId)
6523
+ ? [arg1, (getTableCell) => getTableCell(arg1)]
6524
+ : [
6525
+ joinedCellId,
6526
+ (getTableCell) =>
6527
+ isTrue(arg1)
6528
+ ? getTableCell(true, joinedTableId, joinedCellId)
6529
+ : getTableCell(joinedTableId, joinedCellId),
6530
+ ];
6531
+ arrayPush(selectEntries, selectEntry);
6532
+ return {
6533
+ as: (selectedCellId) => (selectEntry[0] = selectedCellId),
6534
+ };
6535
+ };
6536
+ const join = (arg1, arg2, arg3, arg4) => {
6537
+ const joinedTableId = isTrue(arg1) ? arg2 : arg1;
6538
+ const [fromJoinAlias, onArg] = isTrue(arg1)
6539
+ ? isUndefined(arg4) || isFunction(arg3)
6540
+ ? [void 0, arg3]
6541
+ : [arg3, arg4]
6542
+ : isUndefined(arg3) || isFunction(arg2)
6543
+ ? [void 0, arg2]
6544
+ : [arg2, arg3];
6545
+ const joinEntry = [
6546
+ joinedTableId,
6547
+ [
6548
+ joinedTableId,
6549
+ fromJoinAlias,
6550
+ isFunction(onArg) ? onArg : (getCell) => getCell(onArg),
6551
+ [],
6552
+ mapNew(),
6553
+ isTrue(arg1) ? getResultStore(joinedTableId) : store,
6554
+ ],
6555
+ ];
6556
+ arrayPush(joinEntries, joinEntry);
6557
+ return {as: (joinedTableId2) => (joinEntry[0] = joinedTableId2)};
6558
+ };
6559
+ const where = (arg1, arg2, arg3, arg4) =>
6560
+ arrayPush(
6561
+ wheres,
6562
+ isFunction(arg1)
6563
+ ? arg1
6564
+ : isTrue(arg1)
6565
+ ? (getTableCell) => getTableCell(true, arg2, arg3) === arg4
6566
+ : isUndefined(arg3)
6567
+ ? (getTableCell) => getTableCell(arg1) === arg2
6568
+ : (getTableCell) => getTableCell(arg1, arg2) === arg3,
6569
+ );
6570
+ const group = (
6571
+ selectedCellId,
6572
+ aggregate,
6573
+ aggregateAdd,
6574
+ aggregateRemove,
6575
+ aggregateReplace,
6576
+ ) => {
6577
+ const groupEntry = [
6578
+ selectedCellId,
6579
+ [
6580
+ selectedCellId,
6581
+ isFunction(aggregate)
6582
+ ? [aggregate, aggregateAdd, aggregateRemove, aggregateReplace]
6583
+ : (mapGet(numericAggregators, aggregate) ?? [
6584
+ (_cells, length) => length,
6585
+ ]),
6586
+ ],
6587
+ ];
6588
+ arrayPush(groupEntries, groupEntry);
6589
+ return {as: (groupedCellId) => (groupEntry[0] = groupedCellId)};
6590
+ };
6591
+ const having = (arg1, arg2) =>
6592
+ arrayPush(
6593
+ havings,
6594
+ isFunction(arg1)
6595
+ ? arg1
6596
+ : (getSelectedOrGroupedCell) =>
6597
+ getSelectedOrGroupedCell(arg1) === arg2,
6598
+ );
6599
+ build({select, join, where, group, having, param});
6600
+ const selects = mapNew(selectEntries);
6601
+ if (collIsEmpty(selects)) {
6602
+ collDel(redefiningQueryIds, queryId);
6603
+ return queries;
6604
+ }
6605
+ const joins = mapNew(joinEntries);
6606
+ mapForEach(joins, (joinAlias, [, fromJoinAlias]) =>
6607
+ ifNotUndefined(mapGet(joins, fromJoinAlias), ({3: toJoinAliases2}) =>
6608
+ isUndefined(joinAlias) ? 0 : arrayPush(toJoinAliases2, joinAlias),
6609
+ ),
6610
+ );
6611
+ const groups = mapNew(groupEntries);
6612
+ let selectJoinWhereStore = preStore;
6613
+ if (collIsEmpty(groups) && arrayIsEmpty(havings)) {
6614
+ selectJoinWhereStore = resultStore2;
6615
+ } else {
6616
+ synchronizeTransactions(queryId, selectJoinWhereStore, resultStore2);
6617
+ const groupedSelectedCellIds = mapNew();
6618
+ mapForEach(groups, (groupedCellId, [selectedCellId, aggregators]) =>
6619
+ setAdd(mapEnsure(groupedSelectedCellIds, selectedCellId, setNew), [
6620
+ groupedCellId,
6621
+ aggregators,
6622
+ ]),
6623
+ );
6624
+ const groupBySelectedCellIds = setNew();
6625
+ mapForEach(selects, (selectedCellId) =>
6626
+ collHas(groupedSelectedCellIds, selectedCellId)
6627
+ ? 0
6628
+ : setAdd(groupBySelectedCellIds, selectedCellId),
6629
+ );
6630
+ const tree = mapNew();
6631
+ const writeGroupRow = (
6632
+ leaf,
6633
+ changedGroupedSelectedCells,
6634
+ selectedRowId,
6635
+ forceRemove,
6636
+ ) =>
6637
+ ifNotUndefined(
6638
+ leaf,
6639
+ ([selectedCells, selectedRowIds, groupRowId, groupRow]) => {
6640
+ mapForEach(
6641
+ changedGroupedSelectedCells,
6642
+ (selectedCellId, [newCell]) => {
6643
+ const selectedCell = mapEnsure(
6644
+ selectedCells,
6645
+ selectedCellId,
6646
+ mapNew,
6647
+ );
6648
+ const oldLeafCell = mapGet(selectedCell, selectedRowId);
6649
+ const newLeafCell = forceRemove ? void 0 : newCell;
6650
+ if (oldLeafCell !== newLeafCell) {
6651
+ const oldNewSet = setNew([[oldLeafCell, newLeafCell]]);
6652
+ const oldLength = collSize(selectedCell);
6653
+ mapSet(selectedCell, selectedRowId, newLeafCell);
6654
+ collForEach(
6655
+ mapGet(groupedSelectedCellIds, selectedCellId),
6656
+ ([groupedCellId, aggregators]) => {
6657
+ const aggregateValue = getAggregateValue(
6658
+ groupRow[groupedCellId],
6659
+ oldLength,
6660
+ selectedCell,
6661
+ oldNewSet,
6662
+ aggregators,
6663
+ );
6664
+ groupRow[groupedCellId] = isUndefined(
6665
+ getCellOrValueType(aggregateValue),
6666
+ )
6667
+ ? void 0
6668
+ : aggregateValue;
6669
+ },
6537
6670
  );
6538
- groupRow[groupedCellId] = isUndefined(
6539
- getCellOrValueType(aggregateValue),
6540
- )
6541
- ? void 0
6542
- : aggregateValue;
6543
- },
6544
- );
6671
+ }
6672
+ },
6673
+ );
6674
+ if (
6675
+ collIsEmpty(selectedRowIds) ||
6676
+ !arrayEvery(havings, (having2) =>
6677
+ having2((cellId) => groupRow[cellId]),
6678
+ )
6679
+ ) {
6680
+ resultStore2.delRow(queryId, groupRowId);
6681
+ } else if (isUndefined(groupRowId)) {
6682
+ leaf[2] = resultStore2.addRow(queryId, groupRow);
6683
+ } else {
6684
+ resultStore2.setRow(queryId, groupRowId, groupRow);
6545
6685
  }
6546
6686
  },
6547
6687
  );
6548
- if (
6549
- collIsEmpty(selectedRowIds) ||
6550
- !arrayEvery(havings, (having2) =>
6551
- having2((cellId) => groupRow[cellId]),
6552
- )
6553
- ) {
6554
- resultStore.delRow(queryId, groupRowId);
6555
- } else if (isUndefined(groupRowId)) {
6556
- leaf[2] = resultStore.addRow(queryId, groupRow);
6557
- } else {
6558
- resultStore.setRow(queryId, groupRowId, groupRow);
6559
- }
6560
- },
6561
- );
6562
- addPreStoreListener(
6563
- selectJoinWhereStore,
6564
- queryId,
6565
- selectJoinWhereStore.addRowListener(
6566
- queryId,
6567
- null,
6568
- (_store, _tableId, selectedRowId, getCellChange) => {
6569
- const oldPath = [];
6570
- const newPath = [];
6571
- const changedGroupedSelectedCells = mapNew();
6572
- const rowExists = selectJoinWhereStore.hasRow(
6688
+ addPreStoreListener(
6689
+ selectJoinWhereStore,
6690
+ queryId,
6691
+ selectJoinWhereStore.addRowListener(
6573
6692
  queryId,
6574
- selectedRowId,
6575
- );
6576
- let changedLeaf = !rowExists;
6577
- collForEach(groupBySelectedCellIds, (selectedCellId) => {
6578
- const [changed, oldCell, newCell] = getCellChange(
6579
- queryId,
6580
- selectedRowId,
6581
- selectedCellId,
6582
- );
6583
- arrayPush(oldPath, oldCell);
6584
- arrayPush(newPath, newCell);
6585
- changedLeaf ||= changed;
6586
- });
6587
- mapForEach(groupedSelectedCellIds, (selectedCellId) => {
6588
- const [changed, , newCell] = getCellChange(
6589
- queryId,
6590
- selectedRowId,
6591
- selectedCellId,
6592
- );
6593
- if (changedLeaf || changed) {
6594
- mapSet(changedGroupedSelectedCells, selectedCellId, [newCell]);
6595
- }
6596
- });
6597
- if (changedLeaf) {
6598
- writeGroupRow(
6599
- visitTree(tree, oldPath, void 0, ([, selectedRowIds]) => {
6600
- collDel(selectedRowIds, selectedRowId);
6601
- return collIsEmpty(selectedRowIds);
6602
- }),
6603
- changedGroupedSelectedCells,
6604
- selectedRowId,
6605
- 1,
6606
- );
6693
+ null,
6694
+ (_store, _tableId, selectedRowId, getCellChange) => {
6695
+ const oldPath = [];
6696
+ const newPath = [];
6697
+ const changedGroupedSelectedCells = mapNew();
6698
+ const rowExists = selectJoinWhereStore.hasRow(
6699
+ queryId,
6700
+ selectedRowId,
6701
+ );
6702
+ let changedLeaf = !rowExists;
6703
+ collForEach(groupBySelectedCellIds, (selectedCellId) => {
6704
+ const [changed, oldCell, newCell] = getCellChange(
6705
+ queryId,
6706
+ selectedRowId,
6707
+ selectedCellId,
6708
+ );
6709
+ arrayPush(oldPath, oldCell);
6710
+ arrayPush(newPath, newCell);
6711
+ changedLeaf ||= changed;
6712
+ });
6713
+ mapForEach(groupedSelectedCellIds, (selectedCellId) => {
6714
+ const [changed, , newCell] = getCellChange(
6715
+ queryId,
6716
+ selectedRowId,
6717
+ selectedCellId,
6718
+ );
6719
+ if (changedLeaf || changed) {
6720
+ mapSet(changedGroupedSelectedCells, selectedCellId, [
6721
+ newCell,
6722
+ ]);
6723
+ }
6724
+ });
6725
+ if (changedLeaf) {
6726
+ writeGroupRow(
6727
+ visitTree(tree, oldPath, void 0, ([, selectedRowIds]) => {
6728
+ collDel(selectedRowIds, selectedRowId);
6729
+ return collIsEmpty(selectedRowIds);
6730
+ }),
6731
+ changedGroupedSelectedCells,
6732
+ selectedRowId,
6733
+ 1,
6734
+ );
6735
+ }
6736
+ if (rowExists) {
6737
+ writeGroupRow(
6738
+ visitTree(
6739
+ tree,
6740
+ newPath,
6741
+ () => {
6742
+ const groupRow = {};
6743
+ collForEach(
6744
+ groupBySelectedCellIds,
6745
+ (selectedCellId) =>
6746
+ (groupRow[selectedCellId] =
6747
+ selectJoinWhereStore.getCell(
6748
+ queryId,
6749
+ selectedRowId,
6750
+ selectedCellId,
6751
+ )),
6752
+ );
6753
+ return [mapNew(), setNew(), void 0, groupRow];
6754
+ },
6755
+ ([, selectedRowIds]) => {
6756
+ setAdd(selectedRowIds, selectedRowId);
6757
+ },
6758
+ ),
6759
+ changedGroupedSelectedCells,
6760
+ selectedRowId,
6761
+ );
6762
+ }
6763
+ },
6764
+ ),
6765
+ );
6766
+ }
6767
+ synchronizeTransactions(queryId, rootStore, selectJoinWhereStore);
6768
+ const writeSelectRow = (rootRowId) => {
6769
+ const getJoinCell = (arg1, arg2, arg3) => {
6770
+ const joinedTableId = isTrue(arg1) ? arg2 : arg1;
6771
+ const joinedCellId = isTrue(arg1) ? arg3 : arg2;
6772
+ if (isUndefined(joinedCellId)) {
6773
+ return rootStore.getCell(tableId, rootRowId, arg1);
6607
6774
  }
6608
- if (rowExists) {
6609
- writeGroupRow(
6610
- visitTree(
6611
- tree,
6612
- newPath,
6613
- () => {
6614
- const groupRow = {};
6615
- collForEach(
6616
- groupBySelectedCellIds,
6617
- (selectedCellId) =>
6618
- (groupRow[selectedCellId] =
6619
- selectJoinWhereStore.getCell(
6620
- queryId,
6621
- selectedRowId,
6622
- selectedCellId,
6623
- )),
6624
- );
6625
- return [mapNew(), setNew(), void 0, groupRow];
6626
- },
6627
- ([, selectedRowIds]) => {
6628
- setAdd(selectedRowIds, selectedRowId);
6629
- },
6630
- ),
6631
- changedGroupedSelectedCells,
6632
- selectedRowId,
6633
- );
6775
+ if (joinedTableId === tableId && !isTrue(arg1)) {
6776
+ return rootStore.getCell(tableId, rootRowId, joinedCellId);
6634
6777
  }
6635
- },
6636
- ),
6637
- );
6638
- }
6639
- synchronizeTransactions(queryId, store, selectJoinWhereStore);
6640
- const writeSelectRow = (rootRowId) => {
6641
- const getTableCell = (arg1, arg2) =>
6642
- store.getCell(
6643
- ...(isUndefined(arg2)
6644
- ? [tableId, rootRowId, arg1]
6645
- : arg1 === tableId
6646
- ? [tableId, rootRowId, arg2]
6647
- : [
6648
- mapGet(joins, arg1)?.[0],
6649
- mapGet(mapGet(joins, arg1)?.[4], rootRowId)?.[0],
6650
- arg2,
6651
- ]),
6652
- );
6653
- selectJoinWhereStore.transaction(() =>
6654
- arrayEvery(wheres, (where2) => where2(getTableCell))
6655
- ? mapForEach(selects, (asCellId, tableCellGetter) =>
6656
- selectJoinWhereStore._[5](
6657
- queryId,
6658
- rootRowId,
6659
- asCellId,
6660
- tableCellGetter(getTableCell, rootRowId),
6661
- ),
6662
- )
6663
- : selectJoinWhereStore.delRow(queryId, rootRowId),
6664
- );
6665
- };
6666
- const listenToTable = (rootRowId, tableId2, rowId, joinedTableIds2) => {
6667
- const getCell = (cellId) => store.getCell(tableId2, rowId, cellId);
6668
- arrayForEach(joinedTableIds2, (remoteAsTableId) => {
6669
- const [realJoinedTableId, , on, nextJoinedTableIds, remoteIdPairs] =
6670
- mapGet(joins, remoteAsTableId);
6671
- const remoteRowId = on?.(getCell, rootRowId);
6672
- const [previousRemoteRowId, previousRemoteListenerId] =
6673
- mapGet(remoteIdPairs, rootRowId) ?? [];
6674
- if (remoteRowId != previousRemoteRowId) {
6675
- if (!isUndefined(previousRemoteListenerId)) {
6676
- delStoreListeners(queryId, previousRemoteListenerId);
6677
- }
6678
- mapSet(
6679
- remoteIdPairs,
6680
- rootRowId,
6681
- isUndefined(remoteRowId)
6778
+ const join2 = mapGet(joins, joinedTableId);
6779
+ return isUndefined(join2)
6682
6780
  ? void 0
6683
- : [
6684
- remoteRowId,
6685
- ...addStoreListeners(
6781
+ : join2[5].getCell(
6782
+ join2[0],
6783
+ mapGet(join2[4], rootRowId)?.[0],
6784
+ joinedCellId,
6785
+ );
6786
+ };
6787
+ selectJoinWhereStore.transaction(() =>
6788
+ arrayEvery(wheres, (where2) => where2(getJoinCell))
6789
+ ? mapForEach(selects, (asCellId, tableCellGetter) =>
6790
+ selectJoinWhereStore._[5](
6686
6791
  queryId,
6687
- 1,
6688
- store.addRowListener(realJoinedTableId, remoteRowId, () =>
6689
- listenToTable(
6690
- rootRowId,
6691
- realJoinedTableId,
6692
- remoteRowId,
6693
- nextJoinedTableIds,
6694
- ),
6695
- ),
6792
+ rootRowId,
6793
+ asCellId,
6794
+ tableCellGetter(getJoinCell, rootRowId),
6696
6795
  ),
6697
- ],
6796
+ )
6797
+ : selectJoinWhereStore.delRow(queryId, rootRowId),
6698
6798
  );
6699
- }
6700
- });
6701
- writeSelectRow(rootRowId);
6702
- };
6703
- const {3: joinedTableIds} = mapGet(joins, void 0);
6704
- selectJoinWhereStore.transaction(() =>
6705
- addStoreListeners(
6706
- queryId,
6707
- 1,
6708
- store.addRowListener(tableId, null, (_store, _tableId, rootRowId) => {
6709
- if (store.hasRow(tableId, rootRowId)) {
6710
- listenToTable(rootRowId, tableId, rootRowId, joinedTableIds);
6799
+ };
6800
+ const listenToTable = (
6801
+ rootRowId,
6802
+ sourceStore,
6803
+ tableId2,
6804
+ rowId,
6805
+ toJoinAliases2,
6806
+ ) => {
6807
+ const getCell = (cellId) =>
6808
+ sourceStore.getCell(tableId2, rowId, cellId);
6809
+ arrayForEach(toJoinAliases2, (joinAlias) => {
6810
+ const [
6811
+ realJoinedTableId,
6812
+ ,
6813
+ on,
6814
+ nextJoinAliases,
6815
+ remoteIdPairs,
6816
+ remoteSourceStore,
6817
+ ] = mapGet(joins, joinAlias);
6818
+ const remoteRowId = on?.(getCell, rootRowId);
6819
+ const previousRemote = mapGet(remoteIdPairs, rootRowId);
6820
+ const previousRemoteRowId = previousRemote?.[0];
6821
+ if (remoteRowId != previousRemoteRowId) {
6822
+ ifNotUndefined(
6823
+ previousRemote,
6824
+ ([, previousRemoteSourceStore, previousRemoteListenerId]) =>
6825
+ delSourceStoreListeners(
6826
+ queryId,
6827
+ previousRemoteSourceStore,
6828
+ previousRemoteListenerId,
6829
+ ),
6830
+ );
6831
+ mapSet(
6832
+ remoteIdPairs,
6833
+ rootRowId,
6834
+ isUndefined(remoteRowId)
6835
+ ? void 0
6836
+ : [
6837
+ remoteRowId,
6838
+ remoteSourceStore,
6839
+ ...addSourceStoreListeners(
6840
+ remoteSourceStore,
6841
+ queryId,
6842
+ 1,
6843
+ remoteSourceStore.addRowListener(
6844
+ realJoinedTableId,
6845
+ remoteRowId,
6846
+ () =>
6847
+ listenToTable(
6848
+ rootRowId,
6849
+ remoteSourceStore,
6850
+ realJoinedTableId,
6851
+ remoteRowId,
6852
+ nextJoinAliases,
6853
+ ),
6854
+ ),
6855
+ ),
6856
+ ],
6857
+ );
6858
+ }
6859
+ });
6860
+ writeSelectRow(rootRowId);
6861
+ };
6862
+ const {3: toJoinAliases} = mapGet(joins, void 0);
6863
+ const rootRowChanged = (sourceStore, _tableId, rootRowId) => {
6864
+ if (rootStore.hasRow(tableId, rootRowId)) {
6865
+ listenToTable(
6866
+ rootRowId,
6867
+ rootStore,
6868
+ tableId,
6869
+ rootRowId,
6870
+ toJoinAliases,
6871
+ );
6711
6872
  } else {
6712
6873
  selectJoinWhereStore.delRow(queryId, rootRowId);
6713
6874
  collForEach(joins, ({4: idsByRootRowId}) =>
6714
6875
  ifNotUndefined(
6715
6876
  mapGet(idsByRootRowId, rootRowId),
6716
- ([, listenerId]) => {
6717
- delStoreListeners(queryId, listenerId);
6877
+ ([, sourceStore2, listenerId]) => {
6878
+ delSourceStoreListeners(queryId, sourceStore2, listenerId);
6718
6879
  mapSet(idsByRootRowId, rootRowId);
6719
6880
  },
6720
6881
  ),
6721
6882
  );
6722
6883
  }
6723
- }),
6724
- ),
6884
+ };
6885
+ selectJoinWhereStore.transaction(() => {
6886
+ arrayForEach(rootStore.getRowIds(tableId), (rootRowId) =>
6887
+ rootRowChanged(rootStore, tableId, rootRowId),
6888
+ );
6889
+ addSourceStoreListeners(
6890
+ rootStore,
6891
+ queryId,
6892
+ 0,
6893
+ rootStore.addRowListener(tableId, null, rootRowChanged),
6894
+ );
6895
+ });
6896
+ collDel(redefiningQueryIds, queryId);
6897
+ return queries;
6898
+ }),
6725
6899
  );
6726
- return queries;
6727
- };
6728
- const callParamListeners = (queryId, oldParamValues, newParamValues) => {
6729
- const allParamIds = setNew([
6730
- ...objIds(oldParamValues),
6731
- ...objIds(newParamValues),
6732
- ]);
6733
- let changed = 0;
6734
- collForEach(allParamIds, (paramId) => {
6735
- const newParamValue = objGet(newParamValues, paramId);
6736
- if (!arrayOrValueEqual(objGet(oldParamValues, paramId), newParamValue)) {
6737
- changed = 1;
6738
- callListeners(paramValueListeners, [queryId, paramId], newParamValue);
6739
- }
6740
- });
6741
- if (changed) {
6742
- callListeners(paramValuesListeners, [queryId], newParamValues);
6743
- }
6744
- };
6745
6900
  const delQueryDefinition = (queryId) => {
6746
- const oldParamValues = getParamValues(queryId);
6901
+ ifNotUndefined(getQueryArgs(queryId), ([, listenerId]) =>
6902
+ paramStore.delListener(listenerId),
6903
+ );
6904
+ paramStore.delRow(PARAMS_TABLE, queryId);
6747
6905
  resetPreStores(queryId);
6906
+ resetSourceStores(queryId);
6748
6907
  delDefinition(queryId);
6749
- callParamListeners(queryId, oldParamValues, {});
6750
6908
  return queries;
6751
6909
  };
6752
- const setParamValues = (queryId, paramValues, force = 0) => {
6753
- ifNotUndefined(getQueryArgs(queryId), ([definition, oldParamValues]) => {
6754
- if (
6755
- force ||
6756
- !objIsEqual(mapToObj(oldParamValues), paramValues, arrayOrValueEqual)
6757
- ) {
6758
- resultStore.transaction(() =>
6759
- setQueryDefinition(
6760
- queryId,
6761
- getTableId(queryId),
6762
- definition,
6763
- paramValues,
6764
- ),
6765
- );
6766
- }
6767
- });
6910
+ const setParamValues = (queryId, paramValues) => {
6911
+ if (hasQuery(queryId)) {
6912
+ setOrDelParamValues(queryId, paramValues);
6913
+ }
6768
6914
  return queries;
6769
6915
  };
6770
6916
  const setParamValue = (queryId, paramId, value) => {
6771
- if (!arrayOrValueEqual(getParamValue(queryId, paramId), value)) {
6772
- setParamValues(
6773
- queryId,
6774
- {...getParamValues(queryId), [paramId]: value},
6775
- 1,
6776
- );
6917
+ if (hasQuery(queryId)) {
6918
+ paramStore.setCell(PARAMS_TABLE, queryId, paramId, value);
6777
6919
  }
6778
6920
  return queries;
6779
6921
  };
6780
- const getParamValues = (queryId) => mapToObj(getQueryArgs(queryId)?.[1]);
6922
+ const getParamValues = (queryId) => paramStore.getRow(PARAMS_TABLE, queryId);
6781
6923
  const getParamValue = (queryId, paramId) =>
6782
- mapGet(getQueryArgs(queryId)?.[1], paramId);
6924
+ paramStore.getCell(PARAMS_TABLE, queryId, paramId);
6783
6925
  const addQueryIdsListener = (listener) =>
6784
6926
  addQueryIdsListenerImpl(() => listener(queries));
6927
+ const forEachResultTable = (tableCallback) =>
6928
+ forEachQuery((queryId) =>
6929
+ getResultStore(queryId).hasTable(queryId)
6930
+ ? tableCallback(queryId, (rowCallback) =>
6931
+ queries.forEachResultRow(queryId, rowCallback),
6932
+ )
6933
+ : 0,
6934
+ );
6785
6935
  const addParamValuesListener = (queryId, listener) =>
6786
- addListener(
6787
- (_, queryId2, paramValues) => listener(queries, queryId2, paramValues),
6788
- paramValuesListeners,
6789
- [queryId],
6936
+ PARAM_LISTENER_PREFIX +
6937
+ paramStore.addRowListener(
6938
+ PARAMS_TABLE,
6939
+ queryId,
6940
+ (_store, _tableId, queryId2) =>
6941
+ listener(queries, queryId2, getParamValues(queryId2)),
6790
6942
  );
6791
6943
  const addParamValueListener = (queryId, paramId, listener) =>
6792
- addListener(
6793
- (_, queryId2, paramId2, paramValue) =>
6944
+ PARAM_LISTENER_PREFIX +
6945
+ paramStore.addCellListener(
6946
+ PARAMS_TABLE,
6947
+ queryId,
6948
+ paramId,
6949
+ (_store, _tableId, queryId2, paramId2, paramValue) =>
6794
6950
  listener(queries, queryId2, paramId2, paramValue),
6795
- paramValueListeners,
6796
- [queryId, paramId],
6797
6951
  );
6798
6952
  const delListener = (listenerId) => {
6799
- delListenerImpl(listenerId);
6953
+ const routedResultListener = mapGet(routedResultListeners, listenerId);
6954
+ if (listenerId[0] == PARAM_LISTENER_PREFIX) {
6955
+ paramStore.delListener(slice(listenerId, 1));
6956
+ } else if (!isUndefined(routedResultListener)) {
6957
+ const [stat, storeListenerIds, queryIdsListenerId] = routedResultListener;
6958
+ mapForEach(storeListenerIds, (_queryId, [store2, storeListenerId]) =>
6959
+ store2.delListener(storeListenerId),
6960
+ );
6961
+ ifNotUndefined(queryIdsListenerId, delListenerImpl);
6962
+ mapSet(routedResultListeners, listenerId);
6963
+ delListenerImpl(listenerId);
6964
+ resultListenerStats[stat]--;
6965
+ } else {
6966
+ delListenerImpl(listenerId);
6967
+ }
6800
6968
  return queries;
6801
6969
  };
6802
- const getListenerStats = () => {
6803
- const {
6804
- tables: _1,
6805
- tableIds: _2,
6806
- transaction: _3,
6807
- ...stats
6808
- } = resultStore.getListenerStats();
6809
- return {
6810
- ...stats,
6811
- paramValues: collSize2(paramValuesListeners),
6812
- paramValue: collSize3(paramValueListeners),
6813
- };
6970
+ const getListenerStats = () => ({
6971
+ ...resultListenerStats,
6972
+ paramValues: paramStore.getListenerStats().row - size(getQueryIds()),
6973
+ paramValue: paramStore.getListenerStats().cell,
6974
+ });
6975
+ const destroy = () => {
6976
+ arrayForEach(getQueryIds(), delQueryDefinition);
6977
+ destroyImpl();
6814
6978
  };
6815
6979
  const queries = {
6816
6980
  setQueryDefinition,
@@ -6824,6 +6988,7 @@ const createQueries = getCreateFunction((store) => {
6824
6988
  forEachQuery,
6825
6989
  hasQuery,
6826
6990
  getTableId,
6991
+ forEachResultTable,
6827
6992
  addQueryIdsListener,
6828
6993
  addParamValuesListener,
6829
6994
  addParamValueListener,
@@ -6831,30 +6996,41 @@ const createQueries = getCreateFunction((store) => {
6831
6996
  destroy,
6832
6997
  getListenerStats,
6833
6998
  };
6999
+ const getListenerArgs = (args, argumentCount) =>
7000
+ argumentCount == 5
7001
+ ? [args[0], args[1] ?? void 0, args[2], args[3], args[4]]
7002
+ : slice(args, 0, argumentCount);
7003
+ const getResultListenerStat = (gettable) =>
7004
+ gettable[0].toLowerCase() + slice(gettable, 1);
6834
7005
  objMap(
6835
7006
  {
6836
- [TABLE$1]: [1, 1],
6837
- [TABLE$1 + CELL_IDS]: [0, 1],
6838
- [ROW_COUNT]: [0, 1],
6839
- [ROW_IDS]: [0, 1],
6840
- [SORTED_ROW_IDS]: [0, 5],
6841
- [ROW]: [1, 2],
6842
- [CELL_IDS]: [0, 2],
6843
- [CELL]: [1, 3],
7007
+ [TABLE$1]: [2, 1],
7008
+ [TABLE$1 + CELL_IDS]: [1, 1],
7009
+ [ROW_COUNT]: [1, 1],
7010
+ [ROW_IDS]: [1, 1],
7011
+ [SORTED_ROW_IDS]: [1, 5],
7012
+ [ROW]: [3, 2],
7013
+ [CELL_IDS]: [1, 2],
7014
+ [CELL]: [3, 3],
6844
7015
  },
6845
- ([hasAndForEach, argumentCount], gettable) => {
7016
+ ([prefixCount, argumentCount], gettable) => {
6846
7017
  arrayForEach(
6847
- hasAndForEach ? [GET, 'has', 'forEach'] : [GET],
7018
+ slice([GET, 'has', 'forEach'], 0, prefixCount),
6848
7019
  (prefix) =>
6849
7020
  (queries[prefix + RESULT + gettable] = (...args) =>
6850
- resultStore[prefix + gettable](...args)),
7021
+ getResultStore(args[0])[prefix + gettable](...args)),
6851
7022
  );
6852
7023
  queries[ADD + RESULT + gettable + LISTENER] = (...args) =>
6853
- resultStore[ADD + gettable + LISTENER](
6854
- ...slice(args, 0, argumentCount),
6855
- (_store, ...listenerArgs) =>
6856
- args[argumentCount](queries, ...listenerArgs),
6857
- true,
7024
+ addRoutedResultListener(
7025
+ getResultListenerStat(gettable),
7026
+ args[0],
7027
+ (store2) =>
7028
+ store2[ADD + gettable + LISTENER](
7029
+ ...getListenerArgs(args, argumentCount),
7030
+ (_store, ...listenerArgs) =>
7031
+ args[argumentCount](queries, ...listenerArgs),
7032
+ true,
7033
+ ),
6858
7034
  );
6859
7035
  },
6860
7036
  );