tinybase 2.0.0-beta.3 → 2.0.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/checkpoints.d.ts +1 -1
- package/lib/checkpoints.js +1 -1
- package/lib/checkpoints.js.gz +0 -0
- package/lib/debug/checkpoints.d.ts +1 -1
- package/lib/debug/checkpoints.js +19 -7
- package/lib/debug/indexes.js +18 -7
- package/lib/debug/metrics.js +18 -7
- package/lib/debug/persisters.d.ts +1 -1
- package/lib/debug/queries.d.ts +93 -83
- package/lib/debug/queries.js +29 -29
- package/lib/debug/relationships.d.ts +1 -1
- package/lib/debug/relationships.js +18 -7
- package/lib/debug/store.js +42 -22
- package/lib/debug/tinybase.js +72 -51
- package/lib/debug/ui-react.d.ts +30 -9
- 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/persisters.d.ts +1 -1
- package/lib/queries.d.ts +93 -83
- package/lib/queries.js +1 -1
- package/lib/queries.js.gz +0 -0
- package/lib/relationships.d.ts +1 -1
- package/lib/relationships.js +1 -1
- package/lib/relationships.js.gz +0 -0
- package/lib/store.js +1 -1
- package/lib/store.js.gz +0 -0
- package/lib/tinybase.js +1 -1
- package/lib/tinybase.js.gz +0 -0
- package/lib/ui-react.d.ts +30 -9
- 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 -1
- package/lib/umd/queries.js.gz +0 -0
- package/lib/umd/relationships.js +1 -1
- package/lib/umd/relationships.js.gz +0 -0
- package/lib/umd/store.js +1 -1
- package/lib/umd/store.js.gz +0 -0
- package/lib/umd/tinybase.js +1 -1
- package/lib/umd/tinybase.js.gz +0 -0
- package/package.json +20 -19
- package/readme.md +11 -11
package/lib/debug/queries.js
CHANGED
|
@@ -347,8 +347,20 @@ const createQueries = getCreateFunction((store) => {
|
|
|
347
347
|
listenerId,
|
|
348
348
|
),
|
|
349
349
|
);
|
|
350
|
-
const
|
|
350
|
+
const resetPreStores = (queryId) => {
|
|
351
|
+
ifNotUndefined(
|
|
352
|
+
mapGet(preStoreListenerIds, queryId),
|
|
353
|
+
(queryPreStoreListenerIds) => {
|
|
354
|
+
mapForEach(queryPreStoreListenerIds, (preStore2, listenerIds) =>
|
|
355
|
+
collForEach(listenerIds, (listenerId) =>
|
|
356
|
+
preStore2.delListener(listenerId),
|
|
357
|
+
),
|
|
358
|
+
);
|
|
359
|
+
collClear(queryPreStoreListenerIds);
|
|
360
|
+
},
|
|
361
|
+
);
|
|
351
362
|
arrayForEach([resultStore, preStore], (store2) => store2.delTable(queryId));
|
|
363
|
+
};
|
|
352
364
|
const synchronizeTransactions = (queryId, fromStore, toStore) =>
|
|
353
365
|
addPreStoreListener(
|
|
354
366
|
fromStore,
|
|
@@ -360,7 +372,7 @@ const createQueries = getCreateFunction((store) => {
|
|
|
360
372
|
);
|
|
361
373
|
const setQueryDefinition = (queryId, tableId, build) => {
|
|
362
374
|
setDefinition(queryId, tableId);
|
|
363
|
-
|
|
375
|
+
resetPreStores(queryId);
|
|
364
376
|
const selectEntries = [];
|
|
365
377
|
const joinEntries = [[null, [tableId, null, null, [], mapNew()]]];
|
|
366
378
|
const wheres = [];
|
|
@@ -505,12 +517,18 @@ const createQueries = getCreateFunction((store) => {
|
|
|
505
517
|
}
|
|
506
518
|
},
|
|
507
519
|
);
|
|
508
|
-
(
|
|
520
|
+
if (
|
|
521
|
+
collIsEmpty(selectedRowIds) ||
|
|
509
522
|
!arrayEvery(havings, (having2) =>
|
|
510
523
|
having2((cellId) => groupRow[cellId]),
|
|
511
524
|
)
|
|
512
|
-
|
|
513
|
-
|
|
525
|
+
) {
|
|
526
|
+
resultStore.delRow(queryId, groupRowId);
|
|
527
|
+
} else if (isUndefined(groupRowId)) {
|
|
528
|
+
leaf[2] = resultStore.addRow(queryId, groupRow);
|
|
529
|
+
} else {
|
|
530
|
+
resultStore.setRow(queryId, groupRowId, groupRow);
|
|
531
|
+
}
|
|
514
532
|
},
|
|
515
533
|
);
|
|
516
534
|
addPreStoreListener(
|
|
@@ -550,18 +568,10 @@ const createQueries = getCreateFunction((store) => {
|
|
|
550
568
|
});
|
|
551
569
|
if (changedLeaf) {
|
|
552
570
|
writeGroupRow(
|
|
553
|
-
visitTree(
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
([, selectedRowIds, groupRowId]) => {
|
|
558
|
-
collDel(selectedRowIds, selectedRowId);
|
|
559
|
-
if (collIsEmpty(selectedRowIds)) {
|
|
560
|
-
resultStore.delRow(queryId, groupRowId);
|
|
561
|
-
return 1;
|
|
562
|
-
}
|
|
563
|
-
},
|
|
564
|
-
),
|
|
571
|
+
visitTree(tree, oldPath, void 0, ([, selectedRowIds]) => {
|
|
572
|
+
collDel(selectedRowIds, selectedRowId);
|
|
573
|
+
return collIsEmpty(selectedRowIds);
|
|
574
|
+
}),
|
|
565
575
|
changedGroupedSelectedCells,
|
|
566
576
|
selectedRowId,
|
|
567
577
|
1,
|
|
@@ -584,12 +594,7 @@ const createQueries = getCreateFunction((store) => {
|
|
|
584
594
|
selectedCellId,
|
|
585
595
|
)),
|
|
586
596
|
);
|
|
587
|
-
return [
|
|
588
|
-
mapNew(),
|
|
589
|
-
setNew(),
|
|
590
|
-
resultStore.addRow(queryId, groupRow, 1),
|
|
591
|
-
groupRow,
|
|
592
|
-
];
|
|
597
|
+
return [mapNew(), setNew(), void 0, groupRow];
|
|
593
598
|
},
|
|
594
599
|
([, selectedRowIds]) => {
|
|
595
600
|
setAdd(selectedRowIds, selectedRowId);
|
|
@@ -694,12 +699,7 @@ const createQueries = getCreateFunction((store) => {
|
|
|
694
699
|
return queries;
|
|
695
700
|
};
|
|
696
701
|
const delQueryDefinition = (queryId) => {
|
|
697
|
-
|
|
698
|
-
collForEach(listenerIds, (listenerId) =>
|
|
699
|
-
preStore2.delListener(listenerId),
|
|
700
|
-
),
|
|
701
|
-
);
|
|
702
|
-
cleanPreStores(queryId);
|
|
702
|
+
resetPreStores(queryId);
|
|
703
703
|
delDefinition(queryId);
|
|
704
704
|
return queries;
|
|
705
705
|
};
|
|
@@ -244,7 +244,7 @@ export type RelationshipsListenerStats = {
|
|
|
244
244
|
* relationships.destroy();
|
|
245
245
|
* ```
|
|
246
246
|
* @see Relationships And Checkpoints guides
|
|
247
|
-
* @see
|
|
247
|
+
* @see Drawing demo
|
|
248
248
|
* @category Relationships
|
|
249
249
|
*/
|
|
250
250
|
export interface Relationships {
|
|
@@ -7,7 +7,7 @@ const arrayLength = (array) => array.length;
|
|
|
7
7
|
const arrayIsEmpty = (array) => arrayLength(array) == 0;
|
|
8
8
|
const arrayReduce = (array, cb, initial) => array.reduce(cb, initial);
|
|
9
9
|
const arrayPush = (array, ...values) => array.push(...values);
|
|
10
|
-
const
|
|
10
|
+
const arrayShift = (array) => array.shift();
|
|
11
11
|
|
|
12
12
|
const isUndefined = (thing) => thing == void 0;
|
|
13
13
|
const ifNotUndefined = (value, then, otherwise) =>
|
|
@@ -215,6 +215,20 @@ const getCreateFunction = (getFunction) => {
|
|
|
215
215
|
};
|
|
216
216
|
};
|
|
217
217
|
|
|
218
|
+
const INTEGER = /^\d+$/;
|
|
219
|
+
const getPoolFunctions = () => {
|
|
220
|
+
const pool = [];
|
|
221
|
+
let nextId = 0;
|
|
222
|
+
return [
|
|
223
|
+
() => arrayShift(pool) ?? EMPTY_STRING + nextId++,
|
|
224
|
+
(id) => {
|
|
225
|
+
if (INTEGER.test(id) && arrayLength(pool) < 1e3) {
|
|
226
|
+
arrayPush(pool, id);
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
];
|
|
230
|
+
};
|
|
231
|
+
|
|
218
232
|
const getWildcardedLeaves = (deepIdSet, path = [EMPTY_STRING]) => {
|
|
219
233
|
const leaves = [];
|
|
220
234
|
const deep = (node, p) =>
|
|
@@ -228,12 +242,11 @@ const getWildcardedLeaves = (deepIdSet, path = [EMPTY_STRING]) => {
|
|
|
228
242
|
};
|
|
229
243
|
const getListenerFunctions = (getThing) => {
|
|
230
244
|
let thing;
|
|
231
|
-
|
|
232
|
-
const listenerPool = [];
|
|
245
|
+
const [getId, releaseId] = getPoolFunctions();
|
|
233
246
|
const allListeners = mapNew();
|
|
234
247
|
const addListener = (listener, idSetNode, path) => {
|
|
235
248
|
thing ??= getThing();
|
|
236
|
-
const id =
|
|
249
|
+
const id = getId();
|
|
237
250
|
mapSet(allListeners, id, [listener, idSetNode, path]);
|
|
238
251
|
setAdd(visitTree(idSetNode, path ?? [EMPTY_STRING], setNew), id);
|
|
239
252
|
return id;
|
|
@@ -251,9 +264,7 @@ const getListenerFunctions = (getThing) => {
|
|
|
251
264
|
return collIsEmpty(idSet) ? 1 : 0;
|
|
252
265
|
});
|
|
253
266
|
mapSet(allListeners, id);
|
|
254
|
-
|
|
255
|
-
arrayPush(listenerPool, id);
|
|
256
|
-
}
|
|
267
|
+
releaseId(id);
|
|
257
268
|
return idOrNulls;
|
|
258
269
|
});
|
|
259
270
|
const callListener = (id, idNullGetters, extraArgsGetter) =>
|
package/lib/debug/store.js
CHANGED
|
@@ -31,7 +31,7 @@ const arrayReduce = (array, cb, initial) => array.reduce(cb, initial);
|
|
|
31
31
|
const arrayFilter = (array, cb) => array.filter(cb);
|
|
32
32
|
const arraySlice = (array, start, end) => array.slice(start, end);
|
|
33
33
|
const arrayPush = (array, ...values) => array.push(...values);
|
|
34
|
-
const
|
|
34
|
+
const arrayShift = (array) => array.shift();
|
|
35
35
|
|
|
36
36
|
const jsonString = (obj) =>
|
|
37
37
|
JSON.stringify(obj, (_key, value) =>
|
|
@@ -136,6 +136,20 @@ const objIsEmpty = (obj) => arrayIsEmpty(objIds(obj));
|
|
|
136
136
|
const setNew = (entries) => new Set(entries);
|
|
137
137
|
const setAdd = (set, value) => set?.add(value);
|
|
138
138
|
|
|
139
|
+
const INTEGER = /^\d+$/;
|
|
140
|
+
const getPoolFunctions = () => {
|
|
141
|
+
const pool = [];
|
|
142
|
+
let nextId = 0;
|
|
143
|
+
return [
|
|
144
|
+
() => arrayShift(pool) ?? EMPTY_STRING + nextId++,
|
|
145
|
+
(id) => {
|
|
146
|
+
if (INTEGER.test(id) && arrayLength(pool) < 1e3) {
|
|
147
|
+
arrayPush(pool, id);
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
];
|
|
151
|
+
};
|
|
152
|
+
|
|
139
153
|
const getWildcardedLeaves = (deepIdSet, path = [EMPTY_STRING]) => {
|
|
140
154
|
const leaves = [];
|
|
141
155
|
const deep = (node, p) =>
|
|
@@ -149,12 +163,11 @@ const getWildcardedLeaves = (deepIdSet, path = [EMPTY_STRING]) => {
|
|
|
149
163
|
};
|
|
150
164
|
const getListenerFunctions = (getThing) => {
|
|
151
165
|
let thing;
|
|
152
|
-
|
|
153
|
-
const listenerPool = [];
|
|
166
|
+
const [getId, releaseId] = getPoolFunctions();
|
|
154
167
|
const allListeners = mapNew();
|
|
155
168
|
const addListener = (listener, idSetNode, path) => {
|
|
156
169
|
thing ??= getThing();
|
|
157
|
-
const id =
|
|
170
|
+
const id = getId();
|
|
158
171
|
mapSet(allListeners, id, [listener, idSetNode, path]);
|
|
159
172
|
setAdd(visitTree(idSetNode, path ?? [EMPTY_STRING], setNew), id);
|
|
160
173
|
return id;
|
|
@@ -172,9 +185,7 @@ const getListenerFunctions = (getThing) => {
|
|
|
172
185
|
return collIsEmpty(idSet) ? 1 : 0;
|
|
173
186
|
});
|
|
174
187
|
mapSet(allListeners, id);
|
|
175
|
-
|
|
176
|
-
arrayPush(listenerPool, id);
|
|
177
|
-
}
|
|
188
|
+
releaseId(id);
|
|
178
189
|
return idOrNulls;
|
|
179
190
|
});
|
|
180
191
|
const callListener = (id, idNullGetters, extraArgsGetter) =>
|
|
@@ -240,7 +251,6 @@ const idsChanged = (changedIds, id2, added) =>
|
|
|
240
251
|
const createStore = () => {
|
|
241
252
|
let hasSchema;
|
|
242
253
|
let cellsTouched;
|
|
243
|
-
let nextRowId = 0;
|
|
244
254
|
let transactions = 0;
|
|
245
255
|
const changedTableIds = mapNew();
|
|
246
256
|
const changedRowIds = mapNew();
|
|
@@ -249,6 +259,7 @@ const createStore = () => {
|
|
|
249
259
|
const invalidCells = mapNew();
|
|
250
260
|
const schemaMap = mapNew();
|
|
251
261
|
const schemaRowCache = mapNew();
|
|
262
|
+
const tablePoolFunctions = mapNew();
|
|
252
263
|
const tablesMap = mapNew();
|
|
253
264
|
const tablesListeners = pairNewMap();
|
|
254
265
|
const tableIdsListeners = pairNewMap();
|
|
@@ -411,18 +422,26 @@ const createStore = () => {
|
|
|
411
422
|
addDefaultsToRow({[cellId]: validCell}, tableId, rowId),
|
|
412
423
|
),
|
|
413
424
|
);
|
|
414
|
-
const getNewRowId = (
|
|
415
|
-
const
|
|
416
|
-
|
|
425
|
+
const getNewRowId = (tableId) => {
|
|
426
|
+
const [getId] = mapEnsure(tablePoolFunctions, tableId, getPoolFunctions);
|
|
427
|
+
const rowId = getId();
|
|
428
|
+
if (!collHas(mapGet(tablesMap, tableId), rowId)) {
|
|
417
429
|
return rowId;
|
|
418
430
|
}
|
|
419
|
-
return getNewRowId(
|
|
431
|
+
return getNewRowId(tableId);
|
|
420
432
|
};
|
|
421
433
|
const getOrCreateTable = (tableId) =>
|
|
422
434
|
mapGet(tablesMap, tableId) ?? setValidTable(tableId, {});
|
|
423
435
|
const delValidTable = (tableId) => setValidTable(tableId, {});
|
|
424
|
-
const delValidRow = (tableId, tableMap, rowId) =>
|
|
436
|
+
const delValidRow = (tableId, tableMap, rowId) => {
|
|
437
|
+
const [, releaseId] = mapEnsure(
|
|
438
|
+
tablePoolFunctions,
|
|
439
|
+
tableId,
|
|
440
|
+
getPoolFunctions,
|
|
441
|
+
);
|
|
442
|
+
releaseId(rowId);
|
|
425
443
|
setValidRow(tableId, tableMap, rowId, {}, true);
|
|
444
|
+
};
|
|
426
445
|
const delValidCell = (tableId, table, rowId, row, cellId, forceDel) => {
|
|
427
446
|
const defaultCell = mapGet(mapGet(schemaRowCache, tableId)?.[0], cellId);
|
|
428
447
|
if (!isUndefined(defaultCell) && !forceDel) {
|
|
@@ -668,16 +687,17 @@ const createStore = () => {
|
|
|
668
687
|
tableId,
|
|
669
688
|
rowId,
|
|
670
689
|
);
|
|
671
|
-
const addRow = (tableId, row
|
|
690
|
+
const addRow = (tableId, row) =>
|
|
672
691
|
transaction(() => {
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
692
|
+
let rowId = void 0;
|
|
693
|
+
if (validateRow(tableId, rowId, row)) {
|
|
694
|
+
tableId = id(tableId);
|
|
695
|
+
setValidRow(
|
|
696
|
+
tableId,
|
|
697
|
+
getOrCreateTable(tableId),
|
|
698
|
+
(rowId = getNewRowId(tableId)),
|
|
699
|
+
row,
|
|
700
|
+
);
|
|
681
701
|
}
|
|
682
702
|
return rowId;
|
|
683
703
|
});
|
package/lib/debug/tinybase.js
CHANGED
|
@@ -49,6 +49,7 @@ const arraySlice = (array, start, end) => array.slice(start, end);
|
|
|
49
49
|
const arrayClear = (array, to) => array.splice(0, to);
|
|
50
50
|
const arrayPush = (array, ...values) => array.push(...values);
|
|
51
51
|
const arrayPop = (array) => array.pop();
|
|
52
|
+
const arrayShift = (array) => array.shift();
|
|
52
53
|
|
|
53
54
|
const jsonString = (obj) =>
|
|
54
55
|
JSON.stringify(obj, (_key, value) =>
|
|
@@ -295,6 +296,20 @@ const getCreateFunction = (getFunction) => {
|
|
|
295
296
|
};
|
|
296
297
|
};
|
|
297
298
|
|
|
299
|
+
const INTEGER = /^\d+$/;
|
|
300
|
+
const getPoolFunctions = () => {
|
|
301
|
+
const pool = [];
|
|
302
|
+
let nextId = 0;
|
|
303
|
+
return [
|
|
304
|
+
() => arrayShift(pool) ?? EMPTY_STRING + nextId++,
|
|
305
|
+
(id) => {
|
|
306
|
+
if (INTEGER.test(id) && arrayLength(pool) < 1e3) {
|
|
307
|
+
arrayPush(pool, id);
|
|
308
|
+
}
|
|
309
|
+
},
|
|
310
|
+
];
|
|
311
|
+
};
|
|
312
|
+
|
|
298
313
|
const getWildcardedLeaves = (deepIdSet, path = [EMPTY_STRING]) => {
|
|
299
314
|
const leaves = [];
|
|
300
315
|
const deep = (node, p) =>
|
|
@@ -308,12 +323,11 @@ const getWildcardedLeaves = (deepIdSet, path = [EMPTY_STRING]) => {
|
|
|
308
323
|
};
|
|
309
324
|
const getListenerFunctions = (getThing) => {
|
|
310
325
|
let thing;
|
|
311
|
-
|
|
312
|
-
const listenerPool = [];
|
|
326
|
+
const [getId, releaseId] = getPoolFunctions();
|
|
313
327
|
const allListeners = mapNew();
|
|
314
328
|
const addListener = (listener, idSetNode, path) => {
|
|
315
329
|
thing ??= getThing();
|
|
316
|
-
const id =
|
|
330
|
+
const id = getId();
|
|
317
331
|
mapSet(allListeners, id, [listener, idSetNode, path]);
|
|
318
332
|
setAdd(visitTree(idSetNode, path ?? [EMPTY_STRING], setNew), id);
|
|
319
333
|
return id;
|
|
@@ -331,9 +345,7 @@ const getListenerFunctions = (getThing) => {
|
|
|
331
345
|
return collIsEmpty(idSet) ? 1 : 0;
|
|
332
346
|
});
|
|
333
347
|
mapSet(allListeners, id);
|
|
334
|
-
|
|
335
|
-
arrayPush(listenerPool, id);
|
|
336
|
-
}
|
|
348
|
+
releaseId(id);
|
|
337
349
|
return idOrNulls;
|
|
338
350
|
});
|
|
339
351
|
const callListener = (id, idNullGetters, extraArgsGetter) =>
|
|
@@ -470,7 +482,7 @@ const createCheckpoints = getCreateFunction((store) => {
|
|
|
470
482
|
const goForwardImpl = () => {
|
|
471
483
|
if (!arrayIsEmpty(forwardIds)) {
|
|
472
484
|
arrayPush(backwardIds, currentId);
|
|
473
|
-
currentId = forwardIds
|
|
485
|
+
currentId = arrayShift(forwardIds);
|
|
474
486
|
updateStore(1, currentId);
|
|
475
487
|
checkpointsChanged = 1;
|
|
476
488
|
}
|
|
@@ -1122,8 +1134,20 @@ const createQueries = getCreateFunction((store) => {
|
|
|
1122
1134
|
listenerId,
|
|
1123
1135
|
),
|
|
1124
1136
|
);
|
|
1125
|
-
const
|
|
1137
|
+
const resetPreStores = (queryId) => {
|
|
1138
|
+
ifNotUndefined(
|
|
1139
|
+
mapGet(preStoreListenerIds, queryId),
|
|
1140
|
+
(queryPreStoreListenerIds) => {
|
|
1141
|
+
mapForEach(queryPreStoreListenerIds, (preStore2, listenerIds) =>
|
|
1142
|
+
collForEach(listenerIds, (listenerId) =>
|
|
1143
|
+
preStore2.delListener(listenerId),
|
|
1144
|
+
),
|
|
1145
|
+
);
|
|
1146
|
+
collClear(queryPreStoreListenerIds);
|
|
1147
|
+
},
|
|
1148
|
+
);
|
|
1126
1149
|
arrayForEach([resultStore, preStore], (store2) => store2.delTable(queryId));
|
|
1150
|
+
};
|
|
1127
1151
|
const synchronizeTransactions = (queryId, fromStore, toStore) =>
|
|
1128
1152
|
addPreStoreListener(
|
|
1129
1153
|
fromStore,
|
|
@@ -1135,7 +1159,7 @@ const createQueries = getCreateFunction((store) => {
|
|
|
1135
1159
|
);
|
|
1136
1160
|
const setQueryDefinition = (queryId, tableId, build) => {
|
|
1137
1161
|
setDefinition(queryId, tableId);
|
|
1138
|
-
|
|
1162
|
+
resetPreStores(queryId);
|
|
1139
1163
|
const selectEntries = [];
|
|
1140
1164
|
const joinEntries = [[null, [tableId, null, null, [], mapNew()]]];
|
|
1141
1165
|
const wheres = [];
|
|
@@ -1280,12 +1304,18 @@ const createQueries = getCreateFunction((store) => {
|
|
|
1280
1304
|
}
|
|
1281
1305
|
},
|
|
1282
1306
|
);
|
|
1283
|
-
(
|
|
1307
|
+
if (
|
|
1308
|
+
collIsEmpty(selectedRowIds) ||
|
|
1284
1309
|
!arrayEvery(havings, (having2) =>
|
|
1285
1310
|
having2((cellId) => groupRow[cellId]),
|
|
1286
1311
|
)
|
|
1287
|
-
|
|
1288
|
-
|
|
1312
|
+
) {
|
|
1313
|
+
resultStore.delRow(queryId, groupRowId);
|
|
1314
|
+
} else if (isUndefined(groupRowId)) {
|
|
1315
|
+
leaf[2] = resultStore.addRow(queryId, groupRow);
|
|
1316
|
+
} else {
|
|
1317
|
+
resultStore.setRow(queryId, groupRowId, groupRow);
|
|
1318
|
+
}
|
|
1289
1319
|
},
|
|
1290
1320
|
);
|
|
1291
1321
|
addPreStoreListener(
|
|
@@ -1325,18 +1355,10 @@ const createQueries = getCreateFunction((store) => {
|
|
|
1325
1355
|
});
|
|
1326
1356
|
if (changedLeaf) {
|
|
1327
1357
|
writeGroupRow(
|
|
1328
|
-
visitTree(
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
([, selectedRowIds, groupRowId]) => {
|
|
1333
|
-
collDel(selectedRowIds, selectedRowId);
|
|
1334
|
-
if (collIsEmpty(selectedRowIds)) {
|
|
1335
|
-
resultStore.delRow(queryId, groupRowId);
|
|
1336
|
-
return 1;
|
|
1337
|
-
}
|
|
1338
|
-
},
|
|
1339
|
-
),
|
|
1358
|
+
visitTree(tree, oldPath, void 0, ([, selectedRowIds]) => {
|
|
1359
|
+
collDel(selectedRowIds, selectedRowId);
|
|
1360
|
+
return collIsEmpty(selectedRowIds);
|
|
1361
|
+
}),
|
|
1340
1362
|
changedGroupedSelectedCells,
|
|
1341
1363
|
selectedRowId,
|
|
1342
1364
|
1,
|
|
@@ -1359,12 +1381,7 @@ const createQueries = getCreateFunction((store) => {
|
|
|
1359
1381
|
selectedCellId,
|
|
1360
1382
|
)),
|
|
1361
1383
|
);
|
|
1362
|
-
return [
|
|
1363
|
-
mapNew(),
|
|
1364
|
-
setNew(),
|
|
1365
|
-
resultStore.addRow(queryId, groupRow, 1),
|
|
1366
|
-
groupRow,
|
|
1367
|
-
];
|
|
1384
|
+
return [mapNew(), setNew(), void 0, groupRow];
|
|
1368
1385
|
},
|
|
1369
1386
|
([, selectedRowIds]) => {
|
|
1370
1387
|
setAdd(selectedRowIds, selectedRowId);
|
|
@@ -1469,12 +1486,7 @@ const createQueries = getCreateFunction((store) => {
|
|
|
1469
1486
|
return queries;
|
|
1470
1487
|
};
|
|
1471
1488
|
const delQueryDefinition = (queryId) => {
|
|
1472
|
-
|
|
1473
|
-
collForEach(listenerIds, (listenerId) =>
|
|
1474
|
-
preStore2.delListener(listenerId),
|
|
1475
|
-
),
|
|
1476
|
-
);
|
|
1477
|
-
cleanPreStores(queryId);
|
|
1489
|
+
resetPreStores(queryId);
|
|
1478
1490
|
delDefinition(queryId);
|
|
1479
1491
|
return queries;
|
|
1480
1492
|
};
|
|
@@ -1749,7 +1761,6 @@ const idsChanged = (changedIds, id2, added) =>
|
|
|
1749
1761
|
const createStore = () => {
|
|
1750
1762
|
let hasSchema;
|
|
1751
1763
|
let cellsTouched;
|
|
1752
|
-
let nextRowId = 0;
|
|
1753
1764
|
let transactions = 0;
|
|
1754
1765
|
const changedTableIds = mapNew();
|
|
1755
1766
|
const changedRowIds = mapNew();
|
|
@@ -1758,6 +1769,7 @@ const createStore = () => {
|
|
|
1758
1769
|
const invalidCells = mapNew();
|
|
1759
1770
|
const schemaMap = mapNew();
|
|
1760
1771
|
const schemaRowCache = mapNew();
|
|
1772
|
+
const tablePoolFunctions = mapNew();
|
|
1761
1773
|
const tablesMap = mapNew();
|
|
1762
1774
|
const tablesListeners = pairNewMap();
|
|
1763
1775
|
const tableIdsListeners = pairNewMap();
|
|
@@ -1920,18 +1932,26 @@ const createStore = () => {
|
|
|
1920
1932
|
addDefaultsToRow({[cellId]: validCell}, tableId, rowId),
|
|
1921
1933
|
),
|
|
1922
1934
|
);
|
|
1923
|
-
const getNewRowId = (
|
|
1924
|
-
const
|
|
1925
|
-
|
|
1935
|
+
const getNewRowId = (tableId) => {
|
|
1936
|
+
const [getId] = mapEnsure(tablePoolFunctions, tableId, getPoolFunctions);
|
|
1937
|
+
const rowId = getId();
|
|
1938
|
+
if (!collHas(mapGet(tablesMap, tableId), rowId)) {
|
|
1926
1939
|
return rowId;
|
|
1927
1940
|
}
|
|
1928
|
-
return getNewRowId(
|
|
1941
|
+
return getNewRowId(tableId);
|
|
1929
1942
|
};
|
|
1930
1943
|
const getOrCreateTable = (tableId) =>
|
|
1931
1944
|
mapGet(tablesMap, tableId) ?? setValidTable(tableId, {});
|
|
1932
1945
|
const delValidTable = (tableId) => setValidTable(tableId, {});
|
|
1933
|
-
const delValidRow = (tableId, tableMap, rowId) =>
|
|
1946
|
+
const delValidRow = (tableId, tableMap, rowId) => {
|
|
1947
|
+
const [, releaseId] = mapEnsure(
|
|
1948
|
+
tablePoolFunctions,
|
|
1949
|
+
tableId,
|
|
1950
|
+
getPoolFunctions,
|
|
1951
|
+
);
|
|
1952
|
+
releaseId(rowId);
|
|
1934
1953
|
setValidRow(tableId, tableMap, rowId, {}, true);
|
|
1954
|
+
};
|
|
1935
1955
|
const delValidCell = (tableId, table, rowId, row, cellId, forceDel) => {
|
|
1936
1956
|
const defaultCell = mapGet(mapGet(schemaRowCache, tableId)?.[0], cellId);
|
|
1937
1957
|
if (!isUndefined(defaultCell) && !forceDel) {
|
|
@@ -2177,16 +2197,17 @@ const createStore = () => {
|
|
|
2177
2197
|
tableId,
|
|
2178
2198
|
rowId,
|
|
2179
2199
|
);
|
|
2180
|
-
const addRow = (tableId, row
|
|
2200
|
+
const addRow = (tableId, row) =>
|
|
2181
2201
|
transaction(() => {
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2202
|
+
let rowId = void 0;
|
|
2203
|
+
if (validateRow(tableId, rowId, row)) {
|
|
2204
|
+
tableId = id(tableId);
|
|
2205
|
+
setValidRow(
|
|
2206
|
+
tableId,
|
|
2207
|
+
getOrCreateTable(tableId),
|
|
2208
|
+
(rowId = getNewRowId(tableId)),
|
|
2209
|
+
row,
|
|
2210
|
+
);
|
|
2190
2211
|
}
|
|
2191
2212
|
return rowId;
|
|
2192
2213
|
});
|