tinybase 1.3.3 → 2.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/checkpoints.js +1 -1
- package/lib/checkpoints.js.gz +0 -0
- package/lib/debug/checkpoints.js +67 -54
- package/lib/debug/indexes.js +104 -67
- package/lib/debug/metrics.js +185 -129
- package/lib/debug/persisters.js +2 -1
- package/lib/debug/queries.d.ts +3066 -0
- package/lib/debug/queries.js +883 -0
- package/lib/debug/relationships.d.ts +6 -5
- package/lib/debug/relationships.js +103 -67
- package/lib/debug/store.d.ts +137 -66
- package/lib/debug/store.js +215 -119
- package/lib/debug/tinybase.d.ts +1 -0
- package/lib/debug/tinybase.js +896 -176
- package/lib/debug/ui-react.d.ts +49 -2
- package/lib/debug/ui-react.js +85 -74
- package/lib/indexes.js +1 -1
- package/lib/indexes.js.gz +0 -0
- package/lib/metrics.js +1 -1
- package/lib/metrics.js.gz +0 -0
- package/lib/queries.d.ts +3066 -0
- package/lib/queries.js +1 -0
- package/lib/queries.js.gz +0 -0
- package/lib/relationships.d.ts +6 -5
- package/lib/relationships.js +1 -1
- package/lib/relationships.js.gz +0 -0
- package/lib/store.d.ts +137 -66
- package/lib/store.js +1 -1
- package/lib/store.js.gz +0 -0
- package/lib/tinybase.d.ts +1 -0
- package/lib/tinybase.js +1 -1
- package/lib/tinybase.js.gz +0 -0
- package/lib/ui-react.d.ts +49 -2
- package/lib/ui-react.js +1 -1
- package/lib/ui-react.js.gz +0 -0
- package/lib/umd/checkpoints.js +1 -1
- package/lib/umd/checkpoints.js.gz +0 -0
- package/lib/umd/indexes.js +1 -1
- package/lib/umd/indexes.js.gz +0 -0
- package/lib/umd/metrics.js +1 -1
- package/lib/umd/metrics.js.gz +0 -0
- package/lib/umd/queries.js +1 -0
- package/lib/umd/queries.js.gz +0 -0
- package/lib/umd/relationships.js +1 -1
- package/lib/umd/relationships.js.gz +0 -0
- package/lib/umd/store.js +1 -1
- package/lib/umd/store.js.gz +0 -0
- package/lib/umd/tinybase.js +1 -1
- package/lib/umd/tinybase.js.gz +0 -0
- package/lib/umd/ui-react.js +1 -1
- package/lib/umd/ui-react.js.gz +0 -0
- package/package.json +24 -24
- package/readme.md +2 -2
|
@@ -0,0 +1,883 @@
|
|
|
1
|
+
const arrayEvery = (array, cb) => array.every(cb);
|
|
2
|
+
const arrayIsEqual = (array1, array2) =>
|
|
3
|
+
arrayLength(array1) === arrayLength(array2) &&
|
|
4
|
+
arrayEvery(array1, (value1, index) => array2[index] === value1);
|
|
5
|
+
const arraySort = (array, sorter) => array.sort(sorter);
|
|
6
|
+
const arrayForEach = (array, cb) => array.forEach(cb);
|
|
7
|
+
const arrayMap = (array, cb) => array.map(cb);
|
|
8
|
+
const arraySum = (array) => arrayReduce(array, (i, j) => i + j, 0);
|
|
9
|
+
const arrayLength = (array) => array.length;
|
|
10
|
+
const arrayIsEmpty = (array) => arrayLength(array) == 0;
|
|
11
|
+
const arrayReduce = (array, cb, initial) => array.reduce(cb, initial);
|
|
12
|
+
const arraySlice = (array, start, end) => array.slice(start, end);
|
|
13
|
+
const arrayPush = (array, ...values) => array.push(...values);
|
|
14
|
+
|
|
15
|
+
const getTypeOf = (thing) => typeof thing;
|
|
16
|
+
const EMPTY_STRING = '';
|
|
17
|
+
const STRING = getTypeOf(EMPTY_STRING);
|
|
18
|
+
const BOOLEAN = getTypeOf(true);
|
|
19
|
+
const NUMBER = getTypeOf(0);
|
|
20
|
+
const FUNCTION = getTypeOf(getTypeOf);
|
|
21
|
+
const SUM = 'sum';
|
|
22
|
+
const AVG = 'avg';
|
|
23
|
+
const MIN = 'min';
|
|
24
|
+
const MAX = 'max';
|
|
25
|
+
|
|
26
|
+
const mathMax = Math.max;
|
|
27
|
+
const mathMin = Math.min;
|
|
28
|
+
const isFiniteNumber = isFinite;
|
|
29
|
+
const isUndefined = (thing) => thing == void 0;
|
|
30
|
+
const ifNotUndefined = (value, then, otherwise) =>
|
|
31
|
+
isUndefined(value) ? otherwise?.() : then(value);
|
|
32
|
+
const isTypeStringOrBoolean = (type) => type == STRING || type == BOOLEAN;
|
|
33
|
+
const isFunction = (thing) => getTypeOf(thing) == FUNCTION;
|
|
34
|
+
const getUndefined = () => void 0;
|
|
35
|
+
|
|
36
|
+
const collSize = (coll) => coll.size;
|
|
37
|
+
const collHas = (coll, keyOrValue) => coll?.has(keyOrValue) ?? false;
|
|
38
|
+
const collIsEmpty = (coll) => isUndefined(coll) || collSize(coll) == 0;
|
|
39
|
+
const collValues = (coll) => [...(coll?.values() ?? [])];
|
|
40
|
+
const collClear = (coll) => coll.clear();
|
|
41
|
+
const collForEach = (coll, cb) => coll?.forEach(cb);
|
|
42
|
+
const collDel = (coll, keyOrValue) => coll?.delete(keyOrValue);
|
|
43
|
+
|
|
44
|
+
const mapNew = (entries) => new Map(entries);
|
|
45
|
+
const mapKeys = (map) => [...(map?.keys() ?? [])];
|
|
46
|
+
const mapGet = (map, key) => map?.get(key);
|
|
47
|
+
const mapForEach = (map, cb) =>
|
|
48
|
+
collForEach(map, (value, key) => cb(key, value));
|
|
49
|
+
const mapSet = (map, key, value) =>
|
|
50
|
+
isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
|
|
51
|
+
const mapEnsure = (map, key, getDefaultValue) => {
|
|
52
|
+
if (!collHas(map, key)) {
|
|
53
|
+
map.set(key, getDefaultValue());
|
|
54
|
+
}
|
|
55
|
+
return mapGet(map, key);
|
|
56
|
+
};
|
|
57
|
+
const visitTree = (node, path, ensureLeaf, pruneLeaf, p = 0) =>
|
|
58
|
+
ifNotUndefined(
|
|
59
|
+
(ensureLeaf ? mapEnsure : mapGet)(
|
|
60
|
+
node,
|
|
61
|
+
path[p],
|
|
62
|
+
p > arrayLength(path) - 2 ? ensureLeaf : mapNew,
|
|
63
|
+
),
|
|
64
|
+
(nodeOrLeaf) => {
|
|
65
|
+
if (p > arrayLength(path) - 2) {
|
|
66
|
+
if (pruneLeaf?.(nodeOrLeaf)) {
|
|
67
|
+
mapSet(node, path[p]);
|
|
68
|
+
}
|
|
69
|
+
return nodeOrLeaf;
|
|
70
|
+
}
|
|
71
|
+
const leaf = visitTree(nodeOrLeaf, path, ensureLeaf, pruneLeaf, p + 1);
|
|
72
|
+
if (collIsEmpty(nodeOrLeaf)) {
|
|
73
|
+
mapSet(node, path[p]);
|
|
74
|
+
}
|
|
75
|
+
return leaf;
|
|
76
|
+
},
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const setNew = (entries) => new Set(entries);
|
|
80
|
+
const setAdd = (set, value) => set?.add(value);
|
|
81
|
+
|
|
82
|
+
const numericAggregators = mapNew([
|
|
83
|
+
[
|
|
84
|
+
AVG,
|
|
85
|
+
[
|
|
86
|
+
(numbers, length) => arraySum(numbers) / length,
|
|
87
|
+
(metric, add, length) => metric + (add - metric) / (length + 1),
|
|
88
|
+
(metric, remove, length) => metric + (metric - remove) / (length - 1),
|
|
89
|
+
(metric, add, remove, length) => metric + (add - remove) / length,
|
|
90
|
+
],
|
|
91
|
+
],
|
|
92
|
+
[
|
|
93
|
+
MAX,
|
|
94
|
+
[
|
|
95
|
+
(numbers) => mathMax(...numbers),
|
|
96
|
+
(metric, add) => mathMax(add, metric),
|
|
97
|
+
(metric, remove) => (remove == metric ? void 0 : metric),
|
|
98
|
+
(metric, add, remove) =>
|
|
99
|
+
remove == metric ? void 0 : mathMax(add, metric),
|
|
100
|
+
],
|
|
101
|
+
],
|
|
102
|
+
[
|
|
103
|
+
MIN,
|
|
104
|
+
[
|
|
105
|
+
(numbers) => mathMin(...numbers),
|
|
106
|
+
(metric, add) => mathMin(add, metric),
|
|
107
|
+
(metric, remove) => (remove == metric ? void 0 : metric),
|
|
108
|
+
(metric, add, remove) =>
|
|
109
|
+
remove == metric ? void 0 : mathMin(add, metric),
|
|
110
|
+
],
|
|
111
|
+
],
|
|
112
|
+
[
|
|
113
|
+
SUM,
|
|
114
|
+
[
|
|
115
|
+
(numbers) => arraySum(numbers),
|
|
116
|
+
(metric, add) => metric + add,
|
|
117
|
+
(metric, remove) => metric - remove,
|
|
118
|
+
(metric, add, remove) => metric - remove + add,
|
|
119
|
+
],
|
|
120
|
+
],
|
|
121
|
+
]);
|
|
122
|
+
const getAggregateValue = (
|
|
123
|
+
aggregateValue,
|
|
124
|
+
oldLength,
|
|
125
|
+
newValues,
|
|
126
|
+
changedValues,
|
|
127
|
+
aggregators,
|
|
128
|
+
force = false,
|
|
129
|
+
) => {
|
|
130
|
+
if (collIsEmpty(newValues)) {
|
|
131
|
+
return void 0;
|
|
132
|
+
}
|
|
133
|
+
const [aggregate, aggregateAdd, aggregateRemove, aggregateReplace] =
|
|
134
|
+
aggregators;
|
|
135
|
+
force ||= isUndefined(aggregateValue);
|
|
136
|
+
collForEach(changedValues, ([oldValue, newValue]) => {
|
|
137
|
+
if (!force) {
|
|
138
|
+
aggregateValue = isUndefined(oldValue)
|
|
139
|
+
? aggregateAdd?.(aggregateValue, newValue, oldLength++)
|
|
140
|
+
: isUndefined(newValue)
|
|
141
|
+
? aggregateRemove?.(aggregateValue, oldValue, oldLength--)
|
|
142
|
+
: aggregateReplace?.(aggregateValue, newValue, oldValue, oldLength);
|
|
143
|
+
force ||= isUndefined(aggregateValue);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
return force
|
|
147
|
+
? aggregate(collValues(newValues), collSize(newValues))
|
|
148
|
+
: aggregateValue;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const getCellType = (cell) => {
|
|
152
|
+
const type = getTypeOf(cell);
|
|
153
|
+
return isTypeStringOrBoolean(type) || (type == NUMBER && isFiniteNumber(cell))
|
|
154
|
+
? type
|
|
155
|
+
: void 0;
|
|
156
|
+
};
|
|
157
|
+
const setOrDelCell = (store, tableId, rowId, cellId, cell) =>
|
|
158
|
+
isUndefined(cell)
|
|
159
|
+
? store.delCell(tableId, rowId, cellId, true)
|
|
160
|
+
: store.setCell(tableId, rowId, cellId, cell);
|
|
161
|
+
|
|
162
|
+
const getDefinableFunctions = (store, getDefaultThing, validateRowValue) => {
|
|
163
|
+
const hasRow = store.hasRow;
|
|
164
|
+
const tableIds = mapNew();
|
|
165
|
+
const things = mapNew();
|
|
166
|
+
const allRowValues = mapNew();
|
|
167
|
+
const allSortKeys = mapNew();
|
|
168
|
+
const storeListenerIds = mapNew();
|
|
169
|
+
const getStore = () => store;
|
|
170
|
+
const getThingIds = () => mapKeys(tableIds);
|
|
171
|
+
const forEachThing = (cb) => mapForEach(things, cb);
|
|
172
|
+
const hasThing = (id) => collHas(things, id);
|
|
173
|
+
const getTableId = (id) => mapGet(tableIds, id);
|
|
174
|
+
const getThing = (id) => mapGet(things, id);
|
|
175
|
+
const setThing = (id, thing) => mapSet(things, id, thing);
|
|
176
|
+
const addStoreListeners = (id, andCall, ...listenerIds) => {
|
|
177
|
+
const set = mapEnsure(storeListenerIds, id, setNew);
|
|
178
|
+
arrayForEach(
|
|
179
|
+
listenerIds,
|
|
180
|
+
(listenerId) =>
|
|
181
|
+
setAdd(set, listenerId) && andCall && store.callListener(listenerId),
|
|
182
|
+
);
|
|
183
|
+
return listenerIds;
|
|
184
|
+
};
|
|
185
|
+
const delStoreListeners = (id, ...listenerIds) =>
|
|
186
|
+
ifNotUndefined(mapGet(storeListenerIds, id), (allListenerIds) => {
|
|
187
|
+
arrayForEach(
|
|
188
|
+
arrayIsEmpty(listenerIds) ? collValues(allListenerIds) : listenerIds,
|
|
189
|
+
(listenerId) => {
|
|
190
|
+
store.delListener(listenerId);
|
|
191
|
+
collDel(allListenerIds, listenerId);
|
|
192
|
+
},
|
|
193
|
+
);
|
|
194
|
+
if (collIsEmpty(allListenerIds)) {
|
|
195
|
+
mapSet(storeListenerIds, id);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
const setDefinition = (id, tableId) => {
|
|
199
|
+
mapSet(tableIds, id, tableId);
|
|
200
|
+
if (!collHas(things, id)) {
|
|
201
|
+
mapSet(things, id, getDefaultThing());
|
|
202
|
+
mapSet(allRowValues, id, mapNew());
|
|
203
|
+
mapSet(allSortKeys, id, mapNew());
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
const setDefinitionAndListen = (
|
|
207
|
+
id,
|
|
208
|
+
tableId,
|
|
209
|
+
onChanged,
|
|
210
|
+
getRowValue,
|
|
211
|
+
getSortKey,
|
|
212
|
+
) => {
|
|
213
|
+
setDefinition(id, tableId);
|
|
214
|
+
const changedRowValues = mapNew();
|
|
215
|
+
const changedSortKeys = mapNew();
|
|
216
|
+
const rowValues = mapGet(allRowValues, id);
|
|
217
|
+
const sortKeys = mapGet(allSortKeys, id);
|
|
218
|
+
const processRow = (rowId) => {
|
|
219
|
+
const getCell = (cellId) => store.getCell(tableId, rowId, cellId);
|
|
220
|
+
const oldRowValue = mapGet(rowValues, rowId);
|
|
221
|
+
const newRowValue = hasRow(tableId, rowId)
|
|
222
|
+
? validateRowValue(getRowValue(getCell, rowId))
|
|
223
|
+
: void 0;
|
|
224
|
+
if (oldRowValue != newRowValue) {
|
|
225
|
+
mapSet(changedRowValues, rowId, [oldRowValue, newRowValue]);
|
|
226
|
+
}
|
|
227
|
+
if (!isUndefined(getSortKey)) {
|
|
228
|
+
const oldSortKey = mapGet(sortKeys, rowId);
|
|
229
|
+
const newSortKey = hasRow(tableId, rowId)
|
|
230
|
+
? getSortKey(getCell, rowId)
|
|
231
|
+
: void 0;
|
|
232
|
+
if (oldSortKey != newSortKey) {
|
|
233
|
+
mapSet(changedSortKeys, rowId, newSortKey);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
const processTable = (force) => {
|
|
238
|
+
onChanged(
|
|
239
|
+
() => {
|
|
240
|
+
collForEach(changedRowValues, ([, newRowValue], rowId) =>
|
|
241
|
+
mapSet(rowValues, rowId, newRowValue),
|
|
242
|
+
);
|
|
243
|
+
collForEach(changedSortKeys, (newSortKey, rowId) =>
|
|
244
|
+
mapSet(sortKeys, rowId, newSortKey),
|
|
245
|
+
);
|
|
246
|
+
},
|
|
247
|
+
changedRowValues,
|
|
248
|
+
changedSortKeys,
|
|
249
|
+
rowValues,
|
|
250
|
+
sortKeys,
|
|
251
|
+
force,
|
|
252
|
+
);
|
|
253
|
+
collClear(changedRowValues);
|
|
254
|
+
collClear(changedSortKeys);
|
|
255
|
+
};
|
|
256
|
+
mapForEach(rowValues, processRow);
|
|
257
|
+
if (store.hasTable(tableId)) {
|
|
258
|
+
arrayForEach(store.getRowIds(tableId), (rowId) => {
|
|
259
|
+
if (!collHas(rowValues, rowId)) {
|
|
260
|
+
processRow(rowId);
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
processTable(true);
|
|
265
|
+
delStoreListeners(id);
|
|
266
|
+
addStoreListeners(
|
|
267
|
+
id,
|
|
268
|
+
0,
|
|
269
|
+
store.addRowListener(tableId, null, (_store, _tableId, rowId) =>
|
|
270
|
+
processRow(rowId),
|
|
271
|
+
),
|
|
272
|
+
store.addTableListener(tableId, () => processTable()),
|
|
273
|
+
);
|
|
274
|
+
};
|
|
275
|
+
const delDefinition = (id) => {
|
|
276
|
+
mapSet(tableIds, id);
|
|
277
|
+
mapSet(things, id);
|
|
278
|
+
mapSet(allRowValues, id);
|
|
279
|
+
mapSet(allSortKeys, id);
|
|
280
|
+
delStoreListeners(id);
|
|
281
|
+
};
|
|
282
|
+
const destroy = () => mapForEach(storeListenerIds, delDefinition);
|
|
283
|
+
return [
|
|
284
|
+
getStore,
|
|
285
|
+
getThingIds,
|
|
286
|
+
forEachThing,
|
|
287
|
+
hasThing,
|
|
288
|
+
getTableId,
|
|
289
|
+
getThing,
|
|
290
|
+
setThing,
|
|
291
|
+
setDefinition,
|
|
292
|
+
setDefinitionAndListen,
|
|
293
|
+
delDefinition,
|
|
294
|
+
destroy,
|
|
295
|
+
addStoreListeners,
|
|
296
|
+
delStoreListeners,
|
|
297
|
+
];
|
|
298
|
+
};
|
|
299
|
+
const getCreateFunction = (getFunction) => {
|
|
300
|
+
const getFunctionsByStore = /* @__PURE__ */ new WeakMap();
|
|
301
|
+
return (store) => {
|
|
302
|
+
if (!getFunctionsByStore.has(store)) {
|
|
303
|
+
getFunctionsByStore.set(store, getFunction(store));
|
|
304
|
+
}
|
|
305
|
+
return getFunctionsByStore.get(store);
|
|
306
|
+
};
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
const object = Object;
|
|
310
|
+
const objIds = object.keys;
|
|
311
|
+
const objFreeze = object.freeze;
|
|
312
|
+
|
|
313
|
+
const defaultSorter = (sortKey1, sortKey2) => (sortKey1 < sortKey2 ? -1 : 1);
|
|
314
|
+
|
|
315
|
+
const createQueries = getCreateFunction((store) => {
|
|
316
|
+
const [
|
|
317
|
+
getStore,
|
|
318
|
+
getQueryIds,
|
|
319
|
+
forEachQuery,
|
|
320
|
+
hasQuery,
|
|
321
|
+
getTableId,
|
|
322
|
+
,
|
|
323
|
+
,
|
|
324
|
+
setDefinition,
|
|
325
|
+
,
|
|
326
|
+
delDefinition,
|
|
327
|
+
destroy,
|
|
328
|
+
addStoreListeners,
|
|
329
|
+
delStoreListeners,
|
|
330
|
+
] = getDefinableFunctions(store, () => true, getUndefined);
|
|
331
|
+
const preStore1 = store.createStore();
|
|
332
|
+
const preStore2 = store.createStore();
|
|
333
|
+
const resultStore = store.createStore();
|
|
334
|
+
const preStoreListenerIds = mapNew();
|
|
335
|
+
const addPreStoreListener = (preStore, queryId, ...listenerIds) =>
|
|
336
|
+
arrayForEach(listenerIds, (listenerId) =>
|
|
337
|
+
setAdd(
|
|
338
|
+
mapEnsure(
|
|
339
|
+
mapEnsure(preStoreListenerIds, queryId, mapNew),
|
|
340
|
+
preStore,
|
|
341
|
+
setNew,
|
|
342
|
+
),
|
|
343
|
+
listenerId,
|
|
344
|
+
),
|
|
345
|
+
);
|
|
346
|
+
const synchronizeTransactions = (queryId, fromStore, toStore) =>
|
|
347
|
+
addStoreListeners(
|
|
348
|
+
queryId,
|
|
349
|
+
0,
|
|
350
|
+
fromStore.addWillFinishTransactionListener(toStore.startTransaction),
|
|
351
|
+
fromStore.addDidFinishTransactionListener(() =>
|
|
352
|
+
toStore.finishTransaction(),
|
|
353
|
+
),
|
|
354
|
+
);
|
|
355
|
+
const setQueryDefinition = (queryId, tableId, build) => {
|
|
356
|
+
setDefinition(queryId, tableId);
|
|
357
|
+
preStore1.delTable(queryId);
|
|
358
|
+
preStore2.delTable(queryId);
|
|
359
|
+
resultStore.delTable(queryId);
|
|
360
|
+
let offsetLimit;
|
|
361
|
+
const selectEntries = [];
|
|
362
|
+
const joinEntries = [[null, [tableId, null, null, [], mapNew()]]];
|
|
363
|
+
const wheres = [];
|
|
364
|
+
const groupEntries = [];
|
|
365
|
+
const havings = [];
|
|
366
|
+
const orders = [];
|
|
367
|
+
const select = (arg1, arg2) => {
|
|
368
|
+
const selectEntry = isFunction(arg1)
|
|
369
|
+
? [arrayLength(selectEntries) + EMPTY_STRING, arg1]
|
|
370
|
+
: [
|
|
371
|
+
isUndefined(arg2) ? arg1 : arg2,
|
|
372
|
+
(getTableCell) => getTableCell(arg1, arg2),
|
|
373
|
+
];
|
|
374
|
+
arrayPush(selectEntries, selectEntry);
|
|
375
|
+
return {as: (selectedCellId) => (selectEntry[0] = selectedCellId)};
|
|
376
|
+
};
|
|
377
|
+
const join = (joinedTableId, arg1, arg2) => {
|
|
378
|
+
const fromIntermediateJoinedTableId =
|
|
379
|
+
isUndefined(arg2) || isFunction(arg1) ? null : arg1;
|
|
380
|
+
const onArg = isUndefined(fromIntermediateJoinedTableId) ? arg1 : arg2;
|
|
381
|
+
const joinEntry = [
|
|
382
|
+
joinedTableId,
|
|
383
|
+
[
|
|
384
|
+
joinedTableId,
|
|
385
|
+
fromIntermediateJoinedTableId,
|
|
386
|
+
isFunction(onArg) ? onArg : (getCell) => getCell(onArg),
|
|
387
|
+
[],
|
|
388
|
+
mapNew(),
|
|
389
|
+
],
|
|
390
|
+
];
|
|
391
|
+
arrayPush(joinEntries, joinEntry);
|
|
392
|
+
return {as: (joinedTableId2) => (joinEntry[0] = joinedTableId2)};
|
|
393
|
+
};
|
|
394
|
+
const where = (arg1, arg2, arg3) =>
|
|
395
|
+
arrayPush(
|
|
396
|
+
wheres,
|
|
397
|
+
isFunction(arg1)
|
|
398
|
+
? arg1
|
|
399
|
+
: isUndefined(arg3)
|
|
400
|
+
? (getTableCell) => getTableCell(arg1) === arg2
|
|
401
|
+
: (getTableCell) => getTableCell(arg1, arg2) === arg3,
|
|
402
|
+
);
|
|
403
|
+
const group = (
|
|
404
|
+
selectedCellId,
|
|
405
|
+
aggregate,
|
|
406
|
+
aggregateAdd,
|
|
407
|
+
aggregateRemove,
|
|
408
|
+
aggregateReplace,
|
|
409
|
+
) => {
|
|
410
|
+
const groupEntry = [
|
|
411
|
+
selectedCellId,
|
|
412
|
+
[
|
|
413
|
+
selectedCellId,
|
|
414
|
+
isFunction(aggregate)
|
|
415
|
+
? [aggregate, aggregateAdd, aggregateRemove, aggregateReplace]
|
|
416
|
+
: mapGet(numericAggregators, aggregate) ?? [
|
|
417
|
+
(_cells, length) => length,
|
|
418
|
+
],
|
|
419
|
+
],
|
|
420
|
+
];
|
|
421
|
+
arrayPush(groupEntries, groupEntry);
|
|
422
|
+
return {as: (groupedCellId) => (groupEntry[0] = groupedCellId)};
|
|
423
|
+
};
|
|
424
|
+
const having = (arg1, arg2) =>
|
|
425
|
+
arrayPush(
|
|
426
|
+
havings,
|
|
427
|
+
isFunction(arg1)
|
|
428
|
+
? arg1
|
|
429
|
+
: (getSelectedOrGroupedCell) =>
|
|
430
|
+
getSelectedOrGroupedCell(arg1) === arg2,
|
|
431
|
+
);
|
|
432
|
+
const order = (arg1, descending) =>
|
|
433
|
+
arrayPush(orders, [
|
|
434
|
+
isFunction(arg1)
|
|
435
|
+
? arg1
|
|
436
|
+
: (getSelectedOrGroupedCell) => getSelectedOrGroupedCell(arg1) ?? 0,
|
|
437
|
+
descending,
|
|
438
|
+
]);
|
|
439
|
+
const limit = (arg1, arg2) => {
|
|
440
|
+
offsetLimit = isUndefined(arg2) ? [0, arg1] : [arg1, arg2];
|
|
441
|
+
};
|
|
442
|
+
build({select, join, where, group, having, order, limit});
|
|
443
|
+
const selects = mapNew(selectEntries);
|
|
444
|
+
if (collIsEmpty(selects)) {
|
|
445
|
+
return queries;
|
|
446
|
+
}
|
|
447
|
+
const joins = mapNew(joinEntries);
|
|
448
|
+
mapForEach(joins, (asTableId, [, fromAsTableId]) =>
|
|
449
|
+
ifNotUndefined(mapGet(joins, fromAsTableId), ({3: toAsTableIds}) =>
|
|
450
|
+
isUndefined(asTableId) ? 0 : arrayPush(toAsTableIds, asTableId),
|
|
451
|
+
),
|
|
452
|
+
);
|
|
453
|
+
const groups = mapNew(groupEntries);
|
|
454
|
+
let selectJoinWhereStore = preStore1;
|
|
455
|
+
let groupHavingStore = preStore2;
|
|
456
|
+
if (arrayIsEmpty(orders) && isUndefined(offsetLimit)) {
|
|
457
|
+
groupHavingStore = resultStore;
|
|
458
|
+
} else {
|
|
459
|
+
synchronizeTransactions(queryId, groupHavingStore, resultStore);
|
|
460
|
+
const groupRowIdSorter = (rowId1, rowId2) => {
|
|
461
|
+
const sortKeys1 = mapGet(sortKeysByGroupRowId, rowId1) ?? [];
|
|
462
|
+
const sortKeys2 = mapGet(sortKeysByGroupRowId, rowId2) ?? [];
|
|
463
|
+
const orderIndex = orders.findIndex(
|
|
464
|
+
(_order, index) => sortKeys1[index] !== sortKeys2[index],
|
|
465
|
+
);
|
|
466
|
+
return orderIndex < 0
|
|
467
|
+
? 0
|
|
468
|
+
: defaultSorter(sortKeys1[orderIndex], sortKeys2[orderIndex]) *
|
|
469
|
+
(orders[orderIndex][1] ? -1 : 1);
|
|
470
|
+
};
|
|
471
|
+
const sortKeysByGroupRowId = mapNew();
|
|
472
|
+
const sortedGroupRowIds = mapNew();
|
|
473
|
+
addPreStoreListener(
|
|
474
|
+
groupHavingStore,
|
|
475
|
+
queryId,
|
|
476
|
+
arrayIsEmpty(orders)
|
|
477
|
+
? groupHavingStore.addRowIdsListener(queryId, () =>
|
|
478
|
+
collClear(sortedGroupRowIds),
|
|
479
|
+
)
|
|
480
|
+
: groupHavingStore.addRowListener(
|
|
481
|
+
queryId,
|
|
482
|
+
null,
|
|
483
|
+
(_store, _tableId, groupRowId) => {
|
|
484
|
+
let newSortKeys = null;
|
|
485
|
+
if (groupHavingStore.hasRow(queryId, groupRowId)) {
|
|
486
|
+
const oldSortKeys =
|
|
487
|
+
mapGet(sortKeysByGroupRowId, groupRowId) ?? [];
|
|
488
|
+
const groupRow = groupHavingStore.getRow(queryId, groupRowId);
|
|
489
|
+
const getCell = (getSelectedOrGroupedCell) =>
|
|
490
|
+
groupRow[getSelectedOrGroupedCell];
|
|
491
|
+
newSortKeys = arrayMap(orders, ([getSortKey]) =>
|
|
492
|
+
getSortKey(getCell, groupRowId),
|
|
493
|
+
);
|
|
494
|
+
if (arrayIsEqual(oldSortKeys, newSortKeys)) {
|
|
495
|
+
if (mapGet(sortedGroupRowIds, groupRowId)) {
|
|
496
|
+
resultStore.setRow(queryId, groupRowId, groupRow);
|
|
497
|
+
}
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
mapSet(sortKeysByGroupRowId, groupRowId, newSortKeys);
|
|
502
|
+
collClear(sortedGroupRowIds);
|
|
503
|
+
},
|
|
504
|
+
),
|
|
505
|
+
groupHavingStore.addTableListener(queryId, () => {
|
|
506
|
+
if (collIsEmpty(sortedGroupRowIds)) {
|
|
507
|
+
resultStore.delTable(queryId);
|
|
508
|
+
if (groupHavingStore.hasTable(queryId)) {
|
|
509
|
+
const groupTable = groupHavingStore.getTable(queryId);
|
|
510
|
+
arrayForEach(
|
|
511
|
+
arraySort(objIds(groupTable), groupRowIdSorter),
|
|
512
|
+
(id) => mapSet(sortedGroupRowIds, id, 0),
|
|
513
|
+
);
|
|
514
|
+
arrayForEach(
|
|
515
|
+
ifNotUndefined(
|
|
516
|
+
offsetLimit,
|
|
517
|
+
([offset, limit2]) =>
|
|
518
|
+
arraySlice(
|
|
519
|
+
mapKeys(sortedGroupRowIds),
|
|
520
|
+
offset,
|
|
521
|
+
offset + limit2,
|
|
522
|
+
),
|
|
523
|
+
() => mapKeys(sortedGroupRowIds),
|
|
524
|
+
),
|
|
525
|
+
(groupRowId) => {
|
|
526
|
+
resultStore.setRow(
|
|
527
|
+
queryId,
|
|
528
|
+
groupRowId,
|
|
529
|
+
groupTable[groupRowId],
|
|
530
|
+
);
|
|
531
|
+
mapSet(sortedGroupRowIds, groupRowId, 1);
|
|
532
|
+
},
|
|
533
|
+
);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}),
|
|
537
|
+
);
|
|
538
|
+
}
|
|
539
|
+
if (collIsEmpty(groups) && arrayIsEmpty(havings)) {
|
|
540
|
+
selectJoinWhereStore = groupHavingStore;
|
|
541
|
+
} else {
|
|
542
|
+
synchronizeTransactions(queryId, selectJoinWhereStore, groupHavingStore);
|
|
543
|
+
const groupedSelectedCellIds = mapNew();
|
|
544
|
+
mapForEach(groups, (groupedCellId, [selectedCellId, aggregators]) =>
|
|
545
|
+
setAdd(mapEnsure(groupedSelectedCellIds, selectedCellId, setNew), [
|
|
546
|
+
groupedCellId,
|
|
547
|
+
aggregators,
|
|
548
|
+
]),
|
|
549
|
+
);
|
|
550
|
+
const groupBySelectedCellIds = setNew();
|
|
551
|
+
mapForEach(selects, (selectedCellId) =>
|
|
552
|
+
collHas(groupedSelectedCellIds, selectedCellId)
|
|
553
|
+
? 0
|
|
554
|
+
: setAdd(groupBySelectedCellIds, selectedCellId),
|
|
555
|
+
);
|
|
556
|
+
const tree = mapNew();
|
|
557
|
+
const writeGroupRow = (
|
|
558
|
+
leaf,
|
|
559
|
+
changedGroupedSelectedCells,
|
|
560
|
+
selectedRowId,
|
|
561
|
+
forceRemove,
|
|
562
|
+
) =>
|
|
563
|
+
ifNotUndefined(
|
|
564
|
+
leaf,
|
|
565
|
+
([selectedCells, selectedRowIds, groupRowId, groupRow]) => {
|
|
566
|
+
mapForEach(
|
|
567
|
+
changedGroupedSelectedCells,
|
|
568
|
+
(selectedCellId, [newCell]) => {
|
|
569
|
+
const selectedCell = mapEnsure(
|
|
570
|
+
selectedCells,
|
|
571
|
+
selectedCellId,
|
|
572
|
+
mapNew,
|
|
573
|
+
);
|
|
574
|
+
const oldLeafCell = mapGet(selectedCell, selectedRowId);
|
|
575
|
+
const newLeafCell = forceRemove ? void 0 : newCell;
|
|
576
|
+
if (oldLeafCell !== newLeafCell) {
|
|
577
|
+
const oldNewSet = setNew([[oldLeafCell, newLeafCell]]);
|
|
578
|
+
const oldLength = collSize(selectedCell);
|
|
579
|
+
mapSet(selectedCell, selectedRowId, newLeafCell);
|
|
580
|
+
collForEach(
|
|
581
|
+
mapGet(groupedSelectedCellIds, selectedCellId),
|
|
582
|
+
([groupedCellId, aggregators]) => {
|
|
583
|
+
const aggregateValue = getAggregateValue(
|
|
584
|
+
groupRow[groupedCellId],
|
|
585
|
+
oldLength,
|
|
586
|
+
selectedCell,
|
|
587
|
+
oldNewSet,
|
|
588
|
+
aggregators,
|
|
589
|
+
);
|
|
590
|
+
groupRow[groupedCellId] = isUndefined(
|
|
591
|
+
getCellType(aggregateValue),
|
|
592
|
+
)
|
|
593
|
+
? null
|
|
594
|
+
: aggregateValue;
|
|
595
|
+
},
|
|
596
|
+
);
|
|
597
|
+
}
|
|
598
|
+
},
|
|
599
|
+
);
|
|
600
|
+
(collIsEmpty(selectedRowIds) ||
|
|
601
|
+
!arrayEvery(havings, (having2) =>
|
|
602
|
+
having2((cellId) => groupRow[cellId]),
|
|
603
|
+
)
|
|
604
|
+
? groupHavingStore.delRow
|
|
605
|
+
: groupHavingStore.setRow)(queryId, groupRowId, groupRow);
|
|
606
|
+
},
|
|
607
|
+
);
|
|
608
|
+
addPreStoreListener(
|
|
609
|
+
selectJoinWhereStore,
|
|
610
|
+
queryId,
|
|
611
|
+
selectJoinWhereStore.addRowListener(
|
|
612
|
+
queryId,
|
|
613
|
+
null,
|
|
614
|
+
(_store, _tableId, selectedRowId, getCellChange) => {
|
|
615
|
+
const oldPath = [];
|
|
616
|
+
const newPath = [];
|
|
617
|
+
const changedGroupedSelectedCells = mapNew();
|
|
618
|
+
const rowExists = selectJoinWhereStore.hasRow(
|
|
619
|
+
queryId,
|
|
620
|
+
selectedRowId,
|
|
621
|
+
);
|
|
622
|
+
let changedLeaf = !rowExists;
|
|
623
|
+
collForEach(groupBySelectedCellIds, (selectedCellId) => {
|
|
624
|
+
const [changed, oldCell, newCell] = getCellChange(
|
|
625
|
+
queryId,
|
|
626
|
+
selectedRowId,
|
|
627
|
+
selectedCellId,
|
|
628
|
+
);
|
|
629
|
+
arrayPush(oldPath, oldCell);
|
|
630
|
+
arrayPush(newPath, newCell);
|
|
631
|
+
changedLeaf ||= changed;
|
|
632
|
+
});
|
|
633
|
+
mapForEach(groupedSelectedCellIds, (selectedCellId) => {
|
|
634
|
+
const [changed, , newCell] = getCellChange(
|
|
635
|
+
queryId,
|
|
636
|
+
selectedRowId,
|
|
637
|
+
selectedCellId,
|
|
638
|
+
);
|
|
639
|
+
if (changedLeaf || changed) {
|
|
640
|
+
mapSet(changedGroupedSelectedCells, selectedCellId, [newCell]);
|
|
641
|
+
}
|
|
642
|
+
});
|
|
643
|
+
if (changedLeaf) {
|
|
644
|
+
writeGroupRow(
|
|
645
|
+
visitTree(
|
|
646
|
+
tree,
|
|
647
|
+
oldPath,
|
|
648
|
+
void 0,
|
|
649
|
+
([, selectedRowIds, groupRowId]) => {
|
|
650
|
+
collDel(selectedRowIds, selectedRowId);
|
|
651
|
+
if (collIsEmpty(selectedRowIds)) {
|
|
652
|
+
groupHavingStore.delRow(queryId, groupRowId);
|
|
653
|
+
return 1;
|
|
654
|
+
}
|
|
655
|
+
},
|
|
656
|
+
),
|
|
657
|
+
changedGroupedSelectedCells,
|
|
658
|
+
selectedRowId,
|
|
659
|
+
1,
|
|
660
|
+
);
|
|
661
|
+
}
|
|
662
|
+
if (rowExists) {
|
|
663
|
+
writeGroupRow(
|
|
664
|
+
visitTree(
|
|
665
|
+
tree,
|
|
666
|
+
newPath,
|
|
667
|
+
() => {
|
|
668
|
+
const groupRow = {};
|
|
669
|
+
collForEach(
|
|
670
|
+
groupBySelectedCellIds,
|
|
671
|
+
(selectedCellId) =>
|
|
672
|
+
(groupRow[selectedCellId] =
|
|
673
|
+
selectJoinWhereStore.getCell(
|
|
674
|
+
queryId,
|
|
675
|
+
selectedRowId,
|
|
676
|
+
selectedCellId,
|
|
677
|
+
)),
|
|
678
|
+
);
|
|
679
|
+
return [
|
|
680
|
+
mapNew(),
|
|
681
|
+
setNew(),
|
|
682
|
+
groupHavingStore.addRow(queryId, groupRow, 1),
|
|
683
|
+
groupRow,
|
|
684
|
+
];
|
|
685
|
+
},
|
|
686
|
+
([, selectedRowIds]) => {
|
|
687
|
+
setAdd(selectedRowIds, selectedRowId);
|
|
688
|
+
},
|
|
689
|
+
),
|
|
690
|
+
changedGroupedSelectedCells,
|
|
691
|
+
selectedRowId,
|
|
692
|
+
);
|
|
693
|
+
}
|
|
694
|
+
},
|
|
695
|
+
),
|
|
696
|
+
);
|
|
697
|
+
}
|
|
698
|
+
synchronizeTransactions(queryId, store, selectJoinWhereStore);
|
|
699
|
+
const writeSelectRow = (rootRowId) => {
|
|
700
|
+
const getTableCell = (arg1, arg2) =>
|
|
701
|
+
store.getCell(
|
|
702
|
+
...(isUndefined(arg2)
|
|
703
|
+
? [tableId, rootRowId, arg1]
|
|
704
|
+
: arg1 === tableId
|
|
705
|
+
? [tableId, rootRowId, arg2]
|
|
706
|
+
: [
|
|
707
|
+
mapGet(joins, arg1)?.[0],
|
|
708
|
+
mapGet(mapGet(joins, arg1)?.[4], rootRowId)?.[0],
|
|
709
|
+
arg2,
|
|
710
|
+
]),
|
|
711
|
+
);
|
|
712
|
+
selectJoinWhereStore.transaction(() =>
|
|
713
|
+
arrayEvery(wheres, (where2) => where2(getTableCell))
|
|
714
|
+
? mapForEach(selects, (asCellId, tableCellGetter) =>
|
|
715
|
+
setOrDelCell(
|
|
716
|
+
selectJoinWhereStore,
|
|
717
|
+
queryId,
|
|
718
|
+
rootRowId,
|
|
719
|
+
asCellId,
|
|
720
|
+
tableCellGetter(getTableCell, rootRowId),
|
|
721
|
+
),
|
|
722
|
+
)
|
|
723
|
+
: selectJoinWhereStore.delRow(queryId, rootRowId),
|
|
724
|
+
);
|
|
725
|
+
};
|
|
726
|
+
const listenToTable = (rootRowId, tableId2, rowId, joinedTableIds2) => {
|
|
727
|
+
const getCell = (cellId) => store.getCell(tableId2, rowId, cellId);
|
|
728
|
+
arrayForEach(joinedTableIds2, (remoteAsTableId) => {
|
|
729
|
+
const [realJoinedTableId, , on, nextJoinedTableIds, remoteIdPair] =
|
|
730
|
+
mapGet(joins, remoteAsTableId);
|
|
731
|
+
const remoteRowId = on?.(getCell, rootRowId);
|
|
732
|
+
const [previousRemoteRowId, previousRemoteListenerId] =
|
|
733
|
+
mapGet(remoteIdPair, rootRowId) ?? [];
|
|
734
|
+
if (remoteRowId != previousRemoteRowId) {
|
|
735
|
+
if (!isUndefined(previousRemoteListenerId)) {
|
|
736
|
+
delStoreListeners(queryId, previousRemoteListenerId);
|
|
737
|
+
}
|
|
738
|
+
mapSet(
|
|
739
|
+
remoteIdPair,
|
|
740
|
+
rootRowId,
|
|
741
|
+
isUndefined(remoteRowId)
|
|
742
|
+
? null
|
|
743
|
+
: [
|
|
744
|
+
remoteRowId,
|
|
745
|
+
...addStoreListeners(
|
|
746
|
+
queryId,
|
|
747
|
+
1,
|
|
748
|
+
store.addRowListener(realJoinedTableId, remoteRowId, () =>
|
|
749
|
+
listenToTable(
|
|
750
|
+
rootRowId,
|
|
751
|
+
realJoinedTableId,
|
|
752
|
+
remoteRowId,
|
|
753
|
+
nextJoinedTableIds,
|
|
754
|
+
),
|
|
755
|
+
),
|
|
756
|
+
),
|
|
757
|
+
],
|
|
758
|
+
);
|
|
759
|
+
}
|
|
760
|
+
});
|
|
761
|
+
writeSelectRow(rootRowId);
|
|
762
|
+
};
|
|
763
|
+
const {3: joinedTableIds} = mapGet(joins, null);
|
|
764
|
+
selectJoinWhereStore.transaction(() =>
|
|
765
|
+
addStoreListeners(
|
|
766
|
+
queryId,
|
|
767
|
+
1,
|
|
768
|
+
store.addRowListener(tableId, null, (_store, _tableId, rootRowId) => {
|
|
769
|
+
if (store.hasRow(tableId, rootRowId)) {
|
|
770
|
+
listenToTable(rootRowId, tableId, rootRowId, joinedTableIds);
|
|
771
|
+
} else {
|
|
772
|
+
selectJoinWhereStore.delRow(queryId, rootRowId);
|
|
773
|
+
collForEach(joins, ({4: idsByRootRowId}) =>
|
|
774
|
+
ifNotUndefined(
|
|
775
|
+
mapGet(idsByRootRowId, rootRowId),
|
|
776
|
+
([, listenerId]) => {
|
|
777
|
+
delStoreListeners(queryId, listenerId);
|
|
778
|
+
mapSet(idsByRootRowId, rootRowId);
|
|
779
|
+
},
|
|
780
|
+
),
|
|
781
|
+
);
|
|
782
|
+
}
|
|
783
|
+
}),
|
|
784
|
+
),
|
|
785
|
+
);
|
|
786
|
+
return queries;
|
|
787
|
+
};
|
|
788
|
+
const delQueryDefinition = (queryId) => {
|
|
789
|
+
mapForEach(mapGet(preStoreListenerIds, queryId), (preStore, listenerIds) =>
|
|
790
|
+
collForEach(listenerIds, (listenerId) =>
|
|
791
|
+
preStore.delListener(listenerId),
|
|
792
|
+
),
|
|
793
|
+
);
|
|
794
|
+
delDefinition(queryId);
|
|
795
|
+
return queries;
|
|
796
|
+
};
|
|
797
|
+
const getResultTable = (queryId) => resultStore.getTable(queryId);
|
|
798
|
+
const getResultRowIds = (queryId) => resultStore.getRowIds(queryId);
|
|
799
|
+
const getResultRow = (queryId, rowId) => resultStore.getRow(queryId, rowId);
|
|
800
|
+
const getResultCellIds = (queryId, rowId) =>
|
|
801
|
+
resultStore.getCellIds(queryId, rowId);
|
|
802
|
+
const getResultCell = (queryId, rowId, cellId) =>
|
|
803
|
+
resultStore.getCell(queryId, rowId, cellId);
|
|
804
|
+
const hasResultTable = (queryId) => resultStore.hasTable(queryId);
|
|
805
|
+
const hasResultRow = (queryId, rowId) => resultStore.hasRow(queryId, rowId);
|
|
806
|
+
const hasResultCell = (queryId, rowId, cellId) =>
|
|
807
|
+
resultStore.hasCell(queryId, rowId, cellId);
|
|
808
|
+
const forEachResultTable = (tableCallback) =>
|
|
809
|
+
resultStore.forEachTable(tableCallback);
|
|
810
|
+
const forEachResultRow = (queryId, rowCallback) =>
|
|
811
|
+
resultStore.forEachRow(queryId, rowCallback);
|
|
812
|
+
const forEachResultCell = (queryId, rowId, cellCallback) =>
|
|
813
|
+
resultStore.forEachCell(queryId, rowId, cellCallback);
|
|
814
|
+
const addResultTableListener = (queryId, listener) =>
|
|
815
|
+
resultStore.addTableListener(queryId, (_store, ...args) =>
|
|
816
|
+
listener(queries, ...args),
|
|
817
|
+
);
|
|
818
|
+
const addResultRowIdsListener = (queryId, listener, trackReorder) =>
|
|
819
|
+
resultStore.addRowIdsListener(
|
|
820
|
+
queryId,
|
|
821
|
+
(_store, ...args) => listener(queries, ...args),
|
|
822
|
+
trackReorder,
|
|
823
|
+
);
|
|
824
|
+
const addResultRowListener = (queryId, rowId, listener) =>
|
|
825
|
+
resultStore.addRowListener(queryId, rowId, (_store, ...args) =>
|
|
826
|
+
listener(queries, ...args),
|
|
827
|
+
);
|
|
828
|
+
const addResultCellIdsListener = (queryId, rowId, listener, trackReorder) =>
|
|
829
|
+
resultStore.addCellIdsListener(
|
|
830
|
+
queryId,
|
|
831
|
+
rowId,
|
|
832
|
+
(_store, ...args) => listener(queries, ...args),
|
|
833
|
+
trackReorder,
|
|
834
|
+
);
|
|
835
|
+
const addResultCellListener = (queryId, rowId, cellId, listener) =>
|
|
836
|
+
resultStore.addCellListener(queryId, rowId, cellId, (_store, ...args) =>
|
|
837
|
+
listener(queries, ...args),
|
|
838
|
+
);
|
|
839
|
+
const delListener = (listenerId) => {
|
|
840
|
+
resultStore.delListener(listenerId);
|
|
841
|
+
return queries;
|
|
842
|
+
};
|
|
843
|
+
const getListenerStats = () => {
|
|
844
|
+
const {
|
|
845
|
+
tables: _1,
|
|
846
|
+
tableIds: _2,
|
|
847
|
+
transaction: _3,
|
|
848
|
+
...stats
|
|
849
|
+
} = resultStore.getListenerStats();
|
|
850
|
+
return stats;
|
|
851
|
+
};
|
|
852
|
+
const queries = {
|
|
853
|
+
setQueryDefinition,
|
|
854
|
+
delQueryDefinition,
|
|
855
|
+
getStore,
|
|
856
|
+
getQueryIds,
|
|
857
|
+
forEachQuery,
|
|
858
|
+
hasQuery,
|
|
859
|
+
getTableId,
|
|
860
|
+
getResultTable,
|
|
861
|
+
getResultRowIds,
|
|
862
|
+
getResultRow,
|
|
863
|
+
getResultCellIds,
|
|
864
|
+
getResultCell,
|
|
865
|
+
hasResultTable,
|
|
866
|
+
hasResultRow,
|
|
867
|
+
hasResultCell,
|
|
868
|
+
forEachResultTable,
|
|
869
|
+
forEachResultRow,
|
|
870
|
+
forEachResultCell,
|
|
871
|
+
addResultTableListener,
|
|
872
|
+
addResultRowIdsListener,
|
|
873
|
+
addResultRowListener,
|
|
874
|
+
addResultCellIdsListener,
|
|
875
|
+
addResultCellListener,
|
|
876
|
+
delListener,
|
|
877
|
+
destroy,
|
|
878
|
+
getListenerStats,
|
|
879
|
+
};
|
|
880
|
+
return objFreeze(queries);
|
|
881
|
+
});
|
|
882
|
+
|
|
883
|
+
export {createQueries};
|