tinybase 2.0.0-beta.0 → 2.0.0-beta.3
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 +4 -3
- package/lib/checkpoints.js +1 -1
- package/lib/checkpoints.js.gz +0 -0
- package/lib/common.js +1 -1
- package/lib/common.js.gz +0 -0
- package/lib/debug/checkpoints.d.ts +4 -3
- package/lib/debug/checkpoints.js +13 -16
- package/lib/debug/common.js +4 -1
- package/lib/debug/indexes.d.ts +4 -2
- package/lib/debug/indexes.js +13 -15
- package/lib/debug/metrics.d.ts +1 -1
- package/lib/debug/metrics.js +13 -16
- package/lib/debug/persisters.d.ts +6 -0
- package/lib/debug/queries.d.ts +249 -299
- package/lib/debug/queries.js +67 -192
- package/lib/debug/relationships.d.ts +6 -5
- package/lib/debug/relationships.js +13 -16
- package/lib/debug/store.d.ts +386 -86
- package/lib/debug/store.js +278 -216
- package/lib/debug/tinybase.js +318 -390
- package/lib/debug/ui-react.d.ts +4320 -1796
- package/lib/debug/ui-react.js +380 -98
- package/lib/indexes.d.ts +4 -2
- package/lib/indexes.js +1 -1
- package/lib/indexes.js.gz +0 -0
- package/lib/metrics.d.ts +1 -1
- package/lib/metrics.js +1 -1
- package/lib/metrics.js.gz +0 -0
- package/lib/persisters.d.ts +6 -0
- package/lib/queries.d.ts +249 -299
- package/lib/queries.js +1 -1
- 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 +386 -86
- 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 +4320 -1796
- 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/common.js +1 -1
- package/lib/umd/common.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/lib/umd/ui-react.js +1 -1
- package/lib/umd/ui-react.js.gz +0 -0
- package/package.json +26 -26
- package/readme.md +2 -2
package/lib/debug/queries.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
Table,
|
|
25
25
|
TableCallback,
|
|
26
26
|
} from './store.d';
|
|
27
|
-
import {Id, IdOrNull, Ids
|
|
27
|
+
import {Id, IdOrNull, Ids} from './common.d';
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* The Aggregate type describes a custom function that takes an array of Cell
|
|
@@ -194,6 +194,41 @@ export type ResultTableListener = (
|
|
|
194
194
|
*/
|
|
195
195
|
export type ResultRowIdsListener = (queries: Queries, tableId: Id) => void;
|
|
196
196
|
|
|
197
|
+
/**
|
|
198
|
+
* The ResultSortedRowIdsListener type describes a function that is used to
|
|
199
|
+
* listen to changes to the sorted Row Ids in a query's result Table.
|
|
200
|
+
*
|
|
201
|
+
* A ResultSortedRowIdsListener is provided when using the
|
|
202
|
+
* addResultSortedRowIdsListener method. See that method for specific examples.
|
|
203
|
+
*
|
|
204
|
+
* When called, a ResultSortedRowIdsListener is given a reference to the Queries
|
|
205
|
+
* object, the Id of the Table whose Row Ids changed (which is the same as the
|
|
206
|
+
* query Id), the Cell Id being used to sort them, whether descending or not,
|
|
207
|
+
* and the offset and limit of the number of Ids returned, for pagination
|
|
208
|
+
* purposes. It also receives the sorted array of Ids itself, so that you can
|
|
209
|
+
* use them in the listener without the additional cost of an explicit call to
|
|
210
|
+
* getResultSortedRowIds.
|
|
211
|
+
*
|
|
212
|
+
* @param queries A reference to the Queries object that changed.
|
|
213
|
+
* @param tableId The Id of the Table that changed, which is also the query Id.
|
|
214
|
+
* @param cellId The Id of the Cell whose values were used for the sorting.
|
|
215
|
+
* @param descending Whether the sorting was in descending order.
|
|
216
|
+
* @param offset The number of Row Ids skipped.
|
|
217
|
+
* @param limit The maximum number of Row Ids returned.
|
|
218
|
+
* @param sortedRowIds The sorted Row Ids themselves.
|
|
219
|
+
* @category Listener
|
|
220
|
+
* @since v2.0.0-beta
|
|
221
|
+
*/
|
|
222
|
+
export type ResultSortedRowIdsListener = (
|
|
223
|
+
queries: Queries,
|
|
224
|
+
tableId: Id,
|
|
225
|
+
cellId: Id | undefined,
|
|
226
|
+
descending: boolean,
|
|
227
|
+
offset: number,
|
|
228
|
+
limit: number | undefined,
|
|
229
|
+
sortedRowIds: Ids,
|
|
230
|
+
) => void;
|
|
231
|
+
|
|
197
232
|
/**
|
|
198
233
|
* The ResultRowListener type describes a function that is used to listen to
|
|
199
234
|
* changes to a Row in a query's result Table.
|
|
@@ -290,23 +325,23 @@ export type ResultCellListener = (
|
|
|
290
325
|
*/
|
|
291
326
|
export type QueriesListenerStats = {
|
|
292
327
|
/**
|
|
293
|
-
* The number of
|
|
328
|
+
* The number of ResultTableListener functions registered with the Store.
|
|
294
329
|
*/
|
|
295
330
|
table?: number;
|
|
296
331
|
/**
|
|
297
|
-
* The number of
|
|
332
|
+
* The number of ResultRowIdsListener functions registered with the Store.
|
|
298
333
|
*/
|
|
299
334
|
rowIds?: number;
|
|
300
335
|
/**
|
|
301
|
-
* The number of
|
|
336
|
+
* The number of ResultRowListener functions registered with the Store.
|
|
302
337
|
*/
|
|
303
338
|
row?: number;
|
|
304
339
|
/**
|
|
305
|
-
* The number of
|
|
340
|
+
* The number of ResultCellIdsListener functions registered with the Store.
|
|
306
341
|
*/
|
|
307
342
|
cellIds?: number;
|
|
308
343
|
/**
|
|
309
|
-
* The number of
|
|
344
|
+
* The number of ResultCellListener functions registered with the Store.
|
|
310
345
|
*/
|
|
311
346
|
cell?: number;
|
|
312
347
|
};
|
|
@@ -1293,214 +1328,6 @@ export type Having = {
|
|
|
1293
1328
|
(condition: (getSelectedOrGroupedCell: GetCell) => boolean): void;
|
|
1294
1329
|
};
|
|
1295
1330
|
|
|
1296
|
-
/**
|
|
1297
|
-
* The Order type describes a function that lets you specify how you want the
|
|
1298
|
-
* Rows in the result Table to be ordered, based on values within.
|
|
1299
|
-
*
|
|
1300
|
-
* The Order function is provided as an parameter in the `build` parameter of
|
|
1301
|
-
* the setQueryDefinition method.
|
|
1302
|
-
*
|
|
1303
|
-
* An Order clause can either order alphanumerically by the value of a single
|
|
1304
|
-
* Cell or by a 'sort key' calculated from Cell values. The alphanumeric sorting
|
|
1305
|
-
* will be ascending by default, or descending if the second parameter is set to
|
|
1306
|
-
* `true`.
|
|
1307
|
-
*
|
|
1308
|
-
* This is applied after any grouping.
|
|
1309
|
-
*
|
|
1310
|
-
* It is possible to provide multiple Order clauses, and a later clause will be
|
|
1311
|
-
* used to establish the order of pairs of Rows if the earlier clauses have not
|
|
1312
|
-
* been able to.
|
|
1313
|
-
*
|
|
1314
|
-
* Note that the Order clause does not work by changing the Row Ids of the
|
|
1315
|
-
* result Table, but by changing their insert order. Therefore the Ids array
|
|
1316
|
-
* returned from the getResultRowIds method will be correctly ordered, even if
|
|
1317
|
-
* the Ids themselves might seem out of order based on their values. If you _do_
|
|
1318
|
-
* want to sort Rows by their Id, that is provided as a second parameter to the
|
|
1319
|
-
* getSortKey callback.
|
|
1320
|
-
*
|
|
1321
|
-
* Importantly, if you are using the addResultRowIdsListener method to listen to
|
|
1322
|
-
* changes to the order of Rows due to this clause, you will need to set the
|
|
1323
|
-
* optional `trackReorder` parameter to `true` to track when the set of Ids has
|
|
1324
|
-
* not changed, but the order has.
|
|
1325
|
-
*
|
|
1326
|
-
* trackReorder
|
|
1327
|
-
*
|
|
1328
|
-
* @example
|
|
1329
|
-
* This example shows a query that orders a Table by a numeric Cell, in a
|
|
1330
|
-
* descending fashion.
|
|
1331
|
-
*
|
|
1332
|
-
* ```js
|
|
1333
|
-
* const store = createStore().setTable('pets', {
|
|
1334
|
-
* cujo: {price: 4},
|
|
1335
|
-
* fido: {price: 5},
|
|
1336
|
-
* tom: {price: 3},
|
|
1337
|
-
* carnaby: {price: 3},
|
|
1338
|
-
* felix: {price: 4},
|
|
1339
|
-
* polly: {price: 3},
|
|
1340
|
-
* });
|
|
1341
|
-
*
|
|
1342
|
-
* const queries = createQueries(store);
|
|
1343
|
-
* queries.setQueryDefinition('query', 'pets', ({select, order}) => {
|
|
1344
|
-
* select('pets', 'price');
|
|
1345
|
-
* order('price', true);
|
|
1346
|
-
* });
|
|
1347
|
-
*
|
|
1348
|
-
* queries.forEachResultRow('query', (rowId) => {
|
|
1349
|
-
* console.log({[rowId]: queries.getResultRow('query', rowId)});
|
|
1350
|
-
* });
|
|
1351
|
-
* // -> {fido: {price: 5}}
|
|
1352
|
-
* // -> {cujo: {price: 4}}
|
|
1353
|
-
* // -> {felix: {price: 4}}
|
|
1354
|
-
* // -> {tom: {price: 3}}
|
|
1355
|
-
* // -> {carnaby: {price: 3}}
|
|
1356
|
-
* // -> {polly: {price: 3}}
|
|
1357
|
-
* ```
|
|
1358
|
-
* @example
|
|
1359
|
-
* This example shows a query that orders a Table by a string Cell, and then a
|
|
1360
|
-
* calculated sort key based on the Row Id.
|
|
1361
|
-
*
|
|
1362
|
-
* ```js
|
|
1363
|
-
* const store = createStore().setTable('pets', {
|
|
1364
|
-
* cujo: {species: 'dog'},
|
|
1365
|
-
* fido: {species: 'dog'},
|
|
1366
|
-
* tom: {species: 'cat'},
|
|
1367
|
-
* carnaby: {species: 'parrot'},
|
|
1368
|
-
* felix: {species: 'cat'},
|
|
1369
|
-
* polly: {species: 'parrot'},
|
|
1370
|
-
* });
|
|
1371
|
-
*
|
|
1372
|
-
* const queries = createQueries(store);
|
|
1373
|
-
* queries.setQueryDefinition('query', 'pets', ({select, order}) => {
|
|
1374
|
-
* select('pets', 'species');
|
|
1375
|
-
* order('species');
|
|
1376
|
-
* order((getSelectedOrGroupedCell, rowId) => rowId);
|
|
1377
|
-
* });
|
|
1378
|
-
*
|
|
1379
|
-
* queries.forEachResultRow('query', (rowId) => {
|
|
1380
|
-
* console.log({[rowId]: queries.getResultRow('query', rowId)});
|
|
1381
|
-
* });
|
|
1382
|
-
* // -> {felix: {species: 'cat'}}
|
|
1383
|
-
* // -> {tom: {species: 'cat'}}
|
|
1384
|
-
* // -> {cujo: {species: 'dog'}}
|
|
1385
|
-
* // -> {fido: {species: 'dog'}}
|
|
1386
|
-
* // -> {carnaby: {species: 'parrot'}}
|
|
1387
|
-
* // -> {polly: {species: 'parrot'}}
|
|
1388
|
-
* ```
|
|
1389
|
-
* @category Definition
|
|
1390
|
-
* @since v2.0.0-beta
|
|
1391
|
-
*/
|
|
1392
|
-
export type Order = {
|
|
1393
|
-
/**
|
|
1394
|
-
* Calling this function with the first parameter as an Id is used to sort the
|
|
1395
|
-
* Rows by the value in that Cell.
|
|
1396
|
-
*
|
|
1397
|
-
* @param selectedOrGroupedCellId The Id of the Cell in the query to sort by.
|
|
1398
|
-
* @param descending Set to `true` to have the Rows sorted in descending
|
|
1399
|
-
* order.
|
|
1400
|
-
*/
|
|
1401
|
-
(selectedOrGroupedCellId: Id, descending?: boolean): void;
|
|
1402
|
-
/**
|
|
1403
|
-
* Calling this function with the first parameter as a function is used to
|
|
1404
|
-
* sort the Rows by a value calculate from their Cells or Id.
|
|
1405
|
-
*
|
|
1406
|
-
* @param getSortKey A callback that takes a GetCell function and that should
|
|
1407
|
-
* return a 'sort key' to be used for ordering the Rows.
|
|
1408
|
-
* @param descending Set to `true` to have the Rows sorted in descending
|
|
1409
|
-
* order.
|
|
1410
|
-
*/
|
|
1411
|
-
(
|
|
1412
|
-
getSortKey: (getSelectedOrGroupedCell: GetCell, rowId: Id) => SortKey,
|
|
1413
|
-
descending?: boolean,
|
|
1414
|
-
): void;
|
|
1415
|
-
};
|
|
1416
|
-
|
|
1417
|
-
/**
|
|
1418
|
-
* The Limit type describes a function that lets you specify how many Rows you
|
|
1419
|
-
* want in the result Table, and how they should be offset.
|
|
1420
|
-
*
|
|
1421
|
-
* The Limit function is provided as an parameter in the `build` parameter of
|
|
1422
|
-
* the setQueryDefinition method.
|
|
1423
|
-
*
|
|
1424
|
-
* A Limit clause can either provide an 'page' offset and size limit, or just
|
|
1425
|
-
* the limit. The offset is zero-based, so if you specify `2`, say, the results
|
|
1426
|
-
* will skip the first two Rows and start with the third.
|
|
1427
|
-
*
|
|
1428
|
-
* This is applied after any grouping and sorting.
|
|
1429
|
-
*
|
|
1430
|
-
* @example
|
|
1431
|
-
* This example shows a query that limits a Table to four Rows from its first.
|
|
1432
|
-
*
|
|
1433
|
-
* ```js
|
|
1434
|
-
* const store = createStore().setTable('pets', {
|
|
1435
|
-
* cujo: {price: 4},
|
|
1436
|
-
* fido: {price: 5},
|
|
1437
|
-
* tom: {price: 3},
|
|
1438
|
-
* carnaby: {price: 3},
|
|
1439
|
-
* felix: {price: 4},
|
|
1440
|
-
* polly: {price: 3},
|
|
1441
|
-
* });
|
|
1442
|
-
*
|
|
1443
|
-
* const queries = createQueries(store);
|
|
1444
|
-
* queries.setQueryDefinition('query', 'pets', ({select, limit}) => {
|
|
1445
|
-
* select('pets', 'price');
|
|
1446
|
-
* limit(4);
|
|
1447
|
-
* });
|
|
1448
|
-
*
|
|
1449
|
-
* queries.forEachResultRow('query', (rowId) => {
|
|
1450
|
-
* console.log({[rowId]: queries.getResultRow('query', rowId)});
|
|
1451
|
-
* });
|
|
1452
|
-
* // -> {cujo: {price: 4}}
|
|
1453
|
-
* // -> {fido: {price: 5}}
|
|
1454
|
-
* // -> {tom: {price: 3}}
|
|
1455
|
-
* // -> {carnaby: {price: 3}}
|
|
1456
|
-
* ```
|
|
1457
|
-
* @example
|
|
1458
|
-
* This example shows a query that limits a Table to three Rows, offset by two.
|
|
1459
|
-
*
|
|
1460
|
-
* ```js
|
|
1461
|
-
* const store = createStore().setTable('pets', {
|
|
1462
|
-
* cujo: {price: 4},
|
|
1463
|
-
* fido: {price: 5},
|
|
1464
|
-
* tom: {price: 3},
|
|
1465
|
-
* carnaby: {price: 3},
|
|
1466
|
-
* felix: {price: 4},
|
|
1467
|
-
* polly: {price: 3},
|
|
1468
|
-
* });
|
|
1469
|
-
*
|
|
1470
|
-
* const queries = createQueries(store);
|
|
1471
|
-
* queries.setQueryDefinition('query', 'pets', ({select, limit}) => {
|
|
1472
|
-
* select('pets', 'price');
|
|
1473
|
-
* limit(2, 3);
|
|
1474
|
-
* });
|
|
1475
|
-
*
|
|
1476
|
-
* queries.forEachResultRow('query', (rowId) => {
|
|
1477
|
-
* console.log({[rowId]: queries.getResultRow('query', rowId)});
|
|
1478
|
-
* });
|
|
1479
|
-
* // -> {tom: {price: 3}}
|
|
1480
|
-
* // -> {carnaby: {price: 3}}
|
|
1481
|
-
* // -> {felix: {price: 4}}
|
|
1482
|
-
* ```
|
|
1483
|
-
* @category Definition
|
|
1484
|
-
* @since v2.0.0-beta
|
|
1485
|
-
*/
|
|
1486
|
-
export type Limit = {
|
|
1487
|
-
/**
|
|
1488
|
-
* Calling this function with one numeric parameter is used to limit the Rows
|
|
1489
|
-
* returned, starting from the first.
|
|
1490
|
-
*
|
|
1491
|
-
* @param limit The number of Rows to return.
|
|
1492
|
-
*/
|
|
1493
|
-
(limit: number): void;
|
|
1494
|
-
/**
|
|
1495
|
-
* Calling this function with two numeric parameters is used to offset the
|
|
1496
|
-
* start of the results, and then limit the Rows returned.
|
|
1497
|
-
*
|
|
1498
|
-
* @param offset The number of Rows to skip.
|
|
1499
|
-
* @param limit The number of Rows to return.
|
|
1500
|
-
*/
|
|
1501
|
-
(offset: number, limit: number): void;
|
|
1502
|
-
};
|
|
1503
|
-
|
|
1504
1331
|
/**
|
|
1505
1332
|
* A Queries object lets you create and track queries of the data in Store
|
|
1506
1333
|
* objects.
|
|
@@ -1562,33 +1389,32 @@ export type Limit = {
|
|
|
1562
1389
|
* console.log(queries.getResultTable('petOwners'));
|
|
1563
1390
|
* // -> {fido: {owner: 'Alice'}, felix: {owner: 'Bob'}, cujo: {owner: 'Carol'}}
|
|
1564
1391
|
*
|
|
1565
|
-
* // A grouped
|
|
1392
|
+
* // A grouped query:
|
|
1566
1393
|
* queries.setQueryDefinition(
|
|
1567
1394
|
* 'colorPrice',
|
|
1568
1395
|
* 'pets',
|
|
1569
|
-
* ({select, join, group
|
|
1396
|
+
* ({select, join, group}) => {
|
|
1570
1397
|
* select('color');
|
|
1571
1398
|
* select('species', 'price');
|
|
1572
1399
|
* join('species', 'species');
|
|
1573
1400
|
* group('price', 'avg');
|
|
1574
|
-
* order('price');
|
|
1575
1401
|
* },
|
|
1576
1402
|
* );
|
|
1577
1403
|
* console.log(queries.getResultTable('colorPrice'));
|
|
1578
1404
|
* // -> {"1": {color: 'black', price: 4.5}, "0": {color: 'brown', price: 5}}
|
|
1579
|
-
* console.log(queries.
|
|
1580
|
-
* // -> ["
|
|
1405
|
+
* console.log(queries.getResultSortedRowIds('colorPrice', 'price', true));
|
|
1406
|
+
* // -> ["0", "1"]
|
|
1581
1407
|
*
|
|
1582
1408
|
* const listenerId = queries.addResultTableListener('colorPrice', () => {
|
|
1583
1409
|
* console.log('Average prices per color changed');
|
|
1584
1410
|
* console.log(queries.getResultTable('colorPrice'));
|
|
1585
|
-
* console.log(queries.
|
|
1411
|
+
* console.log(queries.getResultSortedRowIds('colorPrice', 'price', true));
|
|
1586
1412
|
* });
|
|
1587
1413
|
*
|
|
1588
1414
|
* store.setRow('pets', 'lowly', {species: 'worm', color: 'brown'});
|
|
1589
1415
|
* // -> 'Average prices per color changed'
|
|
1590
1416
|
* // -> {"0": {color: 'brown', price: 3}, "1": {color: 'black', price: 4.5}}
|
|
1591
|
-
* // -> ["
|
|
1417
|
+
* // -> ["1", "0"]
|
|
1592
1418
|
*
|
|
1593
1419
|
* queries.delListener(listenerId);
|
|
1594
1420
|
* queries.destroy();
|
|
@@ -1611,7 +1437,7 @@ export interface Queries {
|
|
|
1611
1437
|
* The third `build` parameter is a callback that you provide to define the
|
|
1612
1438
|
* query. That callback is provided with a `builders` object that contains the
|
|
1613
1439
|
* named 'keywords' for the query, like `select`, `join`, and so on. You can
|
|
1614
|
-
* see how that is used in the simple example below. The following
|
|
1440
|
+
* see how that is used in the simple example below. The following five
|
|
1615
1441
|
* clause types are supported:
|
|
1616
1442
|
*
|
|
1617
1443
|
* - The Select type describes a function that lets you specify a Cell or
|
|
@@ -1625,13 +1451,12 @@ export interface Queries {
|
|
|
1625
1451
|
* of a Cell in multiple result Rows should be aggregated together.
|
|
1626
1452
|
* - The Having type describes a function that lets you specify conditions to
|
|
1627
1453
|
* filter results, based on the grouped Cells resulting from a Group clause.
|
|
1628
|
-
* - The Order type describes a function that lets you specify how you want
|
|
1629
|
-
* the Rows in the result Table to be ordered, based on values within.
|
|
1630
|
-
* - The Limit type describes a function that lets you specify how many Rows
|
|
1631
|
-
* you want in the result Table, and how they should be offset.
|
|
1632
1454
|
*
|
|
1633
1455
|
* Full documentation and examples are provided in the sections for each of
|
|
1634
1456
|
* those clause types.
|
|
1457
|
+
*
|
|
1458
|
+
* Additionally, you can use the getResultSortedRowIds method and
|
|
1459
|
+
* addResultSortedRowIdsListener method to sort and paginate the results.
|
|
1635
1460
|
*
|
|
1636
1461
|
* @param queryId The Id of the query to define.
|
|
1637
1462
|
* @param tableId The Id of the main Table the query will be based on.
|
|
@@ -1671,8 +1496,6 @@ export interface Queries {
|
|
|
1671
1496
|
where: Where;
|
|
1672
1497
|
group: Group;
|
|
1673
1498
|
having: Having;
|
|
1674
|
-
order: Order;
|
|
1675
|
-
limit: Limit;
|
|
1676
1499
|
}) => void,
|
|
1677
1500
|
): Queries;
|
|
1678
1501
|
|
|
@@ -1914,9 +1737,6 @@ export interface Queries {
|
|
|
1914
1737
|
* returns a copy of, rather than a reference to the list of Ids, so changes
|
|
1915
1738
|
* made to the list object are not made to the query results themselves.
|
|
1916
1739
|
*
|
|
1917
|
-
* An Order clause in the query explicitly affects the order of entries in
|
|
1918
|
-
* this array.
|
|
1919
|
-
*
|
|
1920
1740
|
* @param queryId The Id of a query.
|
|
1921
1741
|
* @returns An array of the Ids of every Row in the result of the query.
|
|
1922
1742
|
* @example
|
|
@@ -1951,6 +1771,72 @@ export interface Queries {
|
|
|
1951
1771
|
*/
|
|
1952
1772
|
getResultRowIds(queryId: Id): Ids;
|
|
1953
1773
|
|
|
1774
|
+
/**
|
|
1775
|
+
* The getResultSortedRowIds method returns the Ids of every Row in the result
|
|
1776
|
+
* Table of the given query, sorted according to the values in a specified
|
|
1777
|
+
* Cell.
|
|
1778
|
+
*
|
|
1779
|
+
* This has the same behavior as a Store's getSortedRowIds method. For
|
|
1780
|
+
* example, if the query Id is invalid, the method returns an empty array.
|
|
1781
|
+
* Similarly, the sorting of the rows is alphanumeric, and you can indicate
|
|
1782
|
+
* whether it should be in descending order. The `offset` and `limit`
|
|
1783
|
+
* parameters are used to paginate results, but default to `0` and `undefined`
|
|
1784
|
+
* to return all available Row Ids if not specified.
|
|
1785
|
+
*
|
|
1786
|
+
* Note that every call to this method will perform the sorting afresh - there
|
|
1787
|
+
* is no caching of the results - and so you are advised to memoize the
|
|
1788
|
+
* results yourself, especially when the result Table is large. For a
|
|
1789
|
+
* performant approach to tracking the sorted Row Ids when they change, use
|
|
1790
|
+
* the addResultSortedRowIdsListener method.
|
|
1791
|
+
*
|
|
1792
|
+
* @param queryId The Id of a query.
|
|
1793
|
+
* @param cellId The Id of the Cell whose values are used for the sorting, or
|
|
1794
|
+
* `undefined` to by sort the Row Id itself.
|
|
1795
|
+
* @param descending Whether the sorting should be in descending order.
|
|
1796
|
+
* @param offset The number of Row Ids to skip for pagination purposes, if
|
|
1797
|
+
* any.
|
|
1798
|
+
* @param limit The maximum number of Row Ids to return, or `undefined` for
|
|
1799
|
+
* all.
|
|
1800
|
+
* @returns An array of the sorted Ids of every Row in the result of the
|
|
1801
|
+
* query.
|
|
1802
|
+
* @example
|
|
1803
|
+
* This example creates a Queries object, a single query definition, and then
|
|
1804
|
+
* calls this method on it (as well as a non-existent definition) to get the
|
|
1805
|
+
* result Row Ids.
|
|
1806
|
+
*
|
|
1807
|
+
* ```js
|
|
1808
|
+
* const store = createStore().setTable('pets', {
|
|
1809
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
1810
|
+
* felix: {species: 'cat', color: 'black'},
|
|
1811
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
1812
|
+
* });
|
|
1813
|
+
*
|
|
1814
|
+
* const queries = createQueries(store).setQueryDefinition(
|
|
1815
|
+
* 'dogColors',
|
|
1816
|
+
* 'pets',
|
|
1817
|
+
* ({select, where}) => {
|
|
1818
|
+
* select('color');
|
|
1819
|
+
* where('species', 'dog');
|
|
1820
|
+
* },
|
|
1821
|
+
* );
|
|
1822
|
+
*
|
|
1823
|
+
* console.log(queries.getResultSortedRowIds('dogColors', 'color'));
|
|
1824
|
+
* // -> ['cujo', 'fido']
|
|
1825
|
+
*
|
|
1826
|
+
* console.log(queries.getResultSortedRowIds('catColors', 'color'));
|
|
1827
|
+
* // -> []
|
|
1828
|
+
* ```
|
|
1829
|
+
* @category Result
|
|
1830
|
+
* @since v2.0.0-beta
|
|
1831
|
+
*/
|
|
1832
|
+
getResultSortedRowIds(
|
|
1833
|
+
queryId: Id,
|
|
1834
|
+
cellId?: Id,
|
|
1835
|
+
descending?: boolean,
|
|
1836
|
+
offset?: number,
|
|
1837
|
+
limit?: number,
|
|
1838
|
+
): Ids;
|
|
1839
|
+
|
|
1954
1840
|
/**
|
|
1955
1841
|
* The getResultRow method returns an object containing the entire data of a
|
|
1956
1842
|
* single Row in the result Table of the given query.
|
|
@@ -2122,8 +2008,8 @@ export interface Queries {
|
|
|
2122
2008
|
hasResultTable(queryId: Id): boolean;
|
|
2123
2009
|
|
|
2124
2010
|
/**
|
|
2125
|
-
* The hasResultRow method returns a boolean indicating whether a given
|
|
2126
|
-
*
|
|
2011
|
+
* The hasResultRow method returns a boolean indicating whether a given result
|
|
2012
|
+
* Row exists.
|
|
2127
2013
|
*
|
|
2128
2014
|
* @param queryId The Id of a possible query.
|
|
2129
2015
|
* @param rowId The Id of a possible Row.
|
|
@@ -2437,22 +2323,13 @@ export interface Queries {
|
|
|
2437
2323
|
* the method's first parameter) or changes to any result Table (by providing
|
|
2438
2324
|
* a `null` wildcard).
|
|
2439
2325
|
*
|
|
2440
|
-
* Use the optional `trackReorder` parameter to additionally track when the
|
|
2441
|
-
* set of Ids has not changed, but the order has - for example when the Order
|
|
2442
|
-
* clause of the query causes the Row Ids to be re-sorted. This behavior is
|
|
2443
|
-
* disabled by default due to the potential performance cost of detecting such
|
|
2444
|
-
* changes.
|
|
2445
|
-
*
|
|
2446
2326
|
* @param queryId The Id of the query to listen to, or `null` as a wildcard.
|
|
2447
2327
|
* @param listener The function that will be called whenever the Row Ids in
|
|
2448
2328
|
* the result Table change.
|
|
2449
|
-
* @param trackReorder An optional boolean that indicates that the listener
|
|
2450
|
-
* should be called if the set of Ids remains the same but their order
|
|
2451
|
-
* changes.
|
|
2452
2329
|
* @returns A unique Id for the listener that can later be used to remove it.
|
|
2453
2330
|
* @example
|
|
2454
2331
|
* This example registers a listener that responds to any change to the Row
|
|
2455
|
-
* Ids of a specific result Table
|
|
2332
|
+
* Ids of a specific result Table.
|
|
2456
2333
|
*
|
|
2457
2334
|
* ```js
|
|
2458
2335
|
* const store = createStore().setTable('pets', {
|
|
@@ -2464,16 +2341,15 @@ export interface Queries {
|
|
|
2464
2341
|
* const queries = createQueries(store).setQueryDefinition(
|
|
2465
2342
|
* 'dogColors',
|
|
2466
2343
|
* 'pets',
|
|
2467
|
-
* ({select, where
|
|
2344
|
+
* ({select, where}) => {
|
|
2468
2345
|
* select('color');
|
|
2469
2346
|
* where('species', 'dog');
|
|
2470
|
-
* order('color');
|
|
2471
2347
|
* },
|
|
2472
2348
|
* );
|
|
2473
2349
|
*
|
|
2474
2350
|
* const listenerId = queries.addResultRowIdsListener(
|
|
2475
2351
|
* 'dogColors',
|
|
2476
|
-
* (
|
|
2352
|
+
* (queries, tableId) => {
|
|
2477
2353
|
* console.log(`Row Ids for dogColors result table changed`);
|
|
2478
2354
|
* console.log(queries.getResultRowIds('dogColors'));
|
|
2479
2355
|
* },
|
|
@@ -2481,18 +2357,93 @@ export interface Queries {
|
|
|
2481
2357
|
*
|
|
2482
2358
|
* store.setRow('pets', 'rex', {species: 'dog', color: 'tan'});
|
|
2483
2359
|
* // -> 'Row Ids for dogColors result table changed'
|
|
2484
|
-
* // -> ['
|
|
2360
|
+
* // -> ['fido', 'cujo', 'rex']
|
|
2485
2361
|
*
|
|
2486
|
-
* store.
|
|
2487
|
-
*
|
|
2488
|
-
*
|
|
2362
|
+
* store.delListener(listenerId);
|
|
2363
|
+
* ```
|
|
2364
|
+
* @example
|
|
2365
|
+
* This example registers a listener that responds to any change to the Row
|
|
2366
|
+
* Ids of any result Table.
|
|
2367
|
+
*
|
|
2368
|
+
* ```js
|
|
2369
|
+
* const store = createStore().setTable('pets', {
|
|
2370
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
2371
|
+
* felix: {species: 'cat', color: 'black'},
|
|
2372
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
2373
|
+
* });
|
|
2374
|
+
*
|
|
2375
|
+
* const queries = createQueries(store)
|
|
2376
|
+
* .setQueryDefinition('dogColors', 'pets', ({select, where}) => {
|
|
2377
|
+
* select('color');
|
|
2378
|
+
* where('species', 'dog');
|
|
2379
|
+
* })
|
|
2380
|
+
* .setQueryDefinition('catColors', 'pets', ({select, where}) => {
|
|
2381
|
+
* select('color');
|
|
2382
|
+
* where('species', 'cat');
|
|
2383
|
+
* });
|
|
2384
|
+
*
|
|
2385
|
+
* const listenerId = queries.addResultRowIdsListener(
|
|
2386
|
+
* null,
|
|
2387
|
+
* (queries, tableId) => {
|
|
2388
|
+
* console.log(`Row Ids for ${tableId} result table changed`);
|
|
2389
|
+
* },
|
|
2390
|
+
* );
|
|
2391
|
+
*
|
|
2392
|
+
* store.setRow('pets', 'rex', {species: 'dog', color: 'tan'});
|
|
2393
|
+
* // -> 'Row Ids for dogColors result table changed'
|
|
2394
|
+
* store.setRow('pets', 'tom', {species: 'cat', color: 'gray'});
|
|
2395
|
+
* // -> 'Row Ids for catColors result table changed'
|
|
2489
2396
|
*
|
|
2490
2397
|
* store.delListener(listenerId);
|
|
2491
2398
|
* ```
|
|
2399
|
+
* @category Listener
|
|
2400
|
+
*/
|
|
2401
|
+
addResultRowIdsListener(
|
|
2402
|
+
queryId: IdOrNull,
|
|
2403
|
+
listener: ResultRowIdsListener,
|
|
2404
|
+
): Id;
|
|
2405
|
+
|
|
2406
|
+
/**
|
|
2407
|
+
* The addResultSortedRowIdsListener method registers a listener function with
|
|
2408
|
+
* the Queries object that will be called whenever sorted (and optionally,
|
|
2409
|
+
* paginated) Row Ids in a result Table change.
|
|
2410
|
+
*
|
|
2411
|
+
* The provided listener is a ResultSortedRowIdsListener function, and will be
|
|
2412
|
+
* called with a reference to the Queries object, the Id of the result Table
|
|
2413
|
+
* whose Row Ids sorting changed (which is also the query Id), the Cell Id
|
|
2414
|
+
* being used to sort them, whether descending or not, and the offset and
|
|
2415
|
+
* limit of the number of Ids returned, for pagination purposes. It also
|
|
2416
|
+
* receives the sorted array of Ids itself, so that you can use them in the
|
|
2417
|
+
* listener without the additional cost of an explicit call to
|
|
2418
|
+
* getResultSortedRowIds
|
|
2419
|
+
*
|
|
2420
|
+
* Such a listener is called when a Row is added or removed, but also when a
|
|
2421
|
+
* value in the specified Cell (somewhere in the result Table) has changed
|
|
2422
|
+
* enough to change the sorting of the Row Ids.
|
|
2423
|
+
*
|
|
2424
|
+
* Unlike most other listeners, you cannot provide wildcards (due to the cost
|
|
2425
|
+
* of detecting changes to the sorting). You can only listen to a single
|
|
2426
|
+
* specified result Table, sorted by a single specified Cell.
|
|
2427
|
+
*
|
|
2428
|
+
* The sorting of the rows is alphanumeric, and you can indicate whether it
|
|
2429
|
+
* should be in descending order. The `offset` and `limit` parameters are used
|
|
2430
|
+
* to paginate results, but default to `0` and `undefined` to return all
|
|
2431
|
+
* available Row Ids if not specified.
|
|
2432
|
+
*
|
|
2433
|
+
* @param queryId The Id of the query to listen to.
|
|
2434
|
+
* @param cellId The Id of the Cell whose values are used for the sorting, or
|
|
2435
|
+
* `undefined` to by sort the result Row Id itself.
|
|
2436
|
+
* @param descending Whether the sorting should be in descending order.
|
|
2437
|
+
* @param offset The number of Row Ids to skip for pagination purposes, if
|
|
2438
|
+
* any.
|
|
2439
|
+
* @param limit The maximum number of Row Ids to return, or `undefined` for
|
|
2440
|
+
* all.
|
|
2441
|
+
* @param listener The function that will be called whenever the sorted Row
|
|
2442
|
+
* Ids in the result Table change.
|
|
2443
|
+
* @returns A unique Id for the listener that can later be used to remove it.
|
|
2492
2444
|
* @example
|
|
2493
|
-
* This example registers a listener that responds to
|
|
2494
|
-
*
|
|
2495
|
-
* not changed.
|
|
2445
|
+
* This example registers a listener that responds to any change to the sorted
|
|
2446
|
+
* Row Ids of a specific result Table.
|
|
2496
2447
|
*
|
|
2497
2448
|
* ```js
|
|
2498
2449
|
* const store = createStore().setTable('pets', {
|
|
@@ -2504,35 +2455,35 @@ export interface Queries {
|
|
|
2504
2455
|
* const queries = createQueries(store).setQueryDefinition(
|
|
2505
2456
|
* 'dogColors',
|
|
2506
2457
|
* 'pets',
|
|
2507
|
-
* ({select, where
|
|
2458
|
+
* ({select, where}) => {
|
|
2508
2459
|
* select('color');
|
|
2509
2460
|
* where('species', 'dog');
|
|
2510
|
-
* order('color');
|
|
2511
2461
|
* },
|
|
2512
2462
|
* );
|
|
2513
2463
|
*
|
|
2514
|
-
* const listenerId = queries.
|
|
2464
|
+
* const listenerId = queries.addResultSortedRowIdsListener(
|
|
2515
2465
|
* 'dogColors',
|
|
2516
|
-
*
|
|
2517
|
-
*
|
|
2518
|
-
*
|
|
2466
|
+
* 'color',
|
|
2467
|
+
* false,
|
|
2468
|
+
* 0,
|
|
2469
|
+
* undefined,
|
|
2470
|
+
* (queries, tableId, cellId, descending, offset, limit, sortedRowIds) => {
|
|
2471
|
+
* console.log(`Sorted Row Ids for dogColors result table changed`);
|
|
2472
|
+
* console.log(sortedRowIds);
|
|
2473
|
+
* // ^ cheaper than calling getResultSortedRowIds again
|
|
2519
2474
|
* },
|
|
2520
|
-
* true, // track reorder
|
|
2521
2475
|
* );
|
|
2522
2476
|
*
|
|
2523
2477
|
* store.setRow('pets', 'rex', {species: 'dog', color: 'tan'});
|
|
2524
|
-
* // -> 'Row Ids for dogColors result table changed'
|
|
2478
|
+
* // -> 'Sorted Row Ids for dogColors result table changed'
|
|
2525
2479
|
* // -> ['cujo', 'fido', 'rex']
|
|
2526
2480
|
*
|
|
2527
|
-
* store.setCell('pets', 'fido', 'color', 'walnut');
|
|
2528
|
-
* // -> 'Row Ids for dogColors result table changed'
|
|
2529
|
-
* // -> ['cujo', 'rex', 'fido']
|
|
2530
|
-
*
|
|
2531
2481
|
* store.delListener(listenerId);
|
|
2532
2482
|
* ```
|
|
2533
2483
|
* @example
|
|
2534
|
-
* This example registers a listener that responds to any change to the
|
|
2535
|
-
* Ids of
|
|
2484
|
+
* This example registers a listener that responds to any change to the sorted
|
|
2485
|
+
* Row Ids of a specific Table. The Row Ids are sorted by their own value,
|
|
2486
|
+
* since the `cellId` parameter is explicitly undefined.
|
|
2536
2487
|
*
|
|
2537
2488
|
* ```js
|
|
2538
2489
|
* const store = createStore().setTable('pets', {
|
|
@@ -2541,36 +2492,45 @@ export interface Queries {
|
|
|
2541
2492
|
* cujo: {species: 'dog', color: 'black'},
|
|
2542
2493
|
* });
|
|
2543
2494
|
*
|
|
2544
|
-
* const queries = createQueries(store)
|
|
2545
|
-
*
|
|
2495
|
+
* const queries = createQueries(store).setQueryDefinition(
|
|
2496
|
+
* 'dogColors',
|
|
2497
|
+
* 'pets',
|
|
2498
|
+
* ({select, where}) => {
|
|
2546
2499
|
* select('color');
|
|
2547
2500
|
* where('species', 'dog');
|
|
2548
|
-
* }
|
|
2549
|
-
*
|
|
2550
|
-
*
|
|
2551
|
-
*
|
|
2552
|
-
* });
|
|
2501
|
+
* },
|
|
2502
|
+
* );
|
|
2503
|
+
* console.log(queries.getResultSortedRowIds('dogColors', undefined));
|
|
2504
|
+
* // -> ['cujo', 'fido']
|
|
2553
2505
|
*
|
|
2554
|
-
* const listenerId = queries.
|
|
2555
|
-
*
|
|
2556
|
-
*
|
|
2557
|
-
*
|
|
2506
|
+
* const listenerId = queries.addResultSortedRowIdsListener(
|
|
2507
|
+
* 'dogColors',
|
|
2508
|
+
* undefined,
|
|
2509
|
+
* false,
|
|
2510
|
+
* 0,
|
|
2511
|
+
* undefined,
|
|
2512
|
+
* (queries, tableId, cellId, descending, offset, limit, sortedRowIds) => {
|
|
2513
|
+
* console.log(`Sorted Row Ids for dogColors result table changed`);
|
|
2514
|
+
* console.log(sortedRowIds);
|
|
2515
|
+
* // ^ cheaper than calling getSortedRowIds again
|
|
2558
2516
|
* },
|
|
2559
2517
|
* );
|
|
2560
2518
|
*
|
|
2561
2519
|
* store.setRow('pets', 'rex', {species: 'dog', color: 'tan'});
|
|
2562
|
-
* // -> 'Row Ids for dogColors result table changed'
|
|
2563
|
-
*
|
|
2564
|
-
* // -> 'Row Ids for catColors result table changed'
|
|
2520
|
+
* // -> 'Sorted Row Ids for dogColors result table changed'
|
|
2521
|
+
* // -> ['cujo', 'fido', 'rex']
|
|
2565
2522
|
*
|
|
2566
2523
|
* store.delListener(listenerId);
|
|
2567
2524
|
* ```
|
|
2568
2525
|
* @category Listener
|
|
2569
2526
|
*/
|
|
2570
|
-
|
|
2571
|
-
queryId:
|
|
2572
|
-
|
|
2573
|
-
|
|
2527
|
+
addResultSortedRowIdsListener(
|
|
2528
|
+
queryId: Id,
|
|
2529
|
+
cellId: Id | undefined,
|
|
2530
|
+
descending: boolean,
|
|
2531
|
+
offset: number,
|
|
2532
|
+
limit: number | undefined,
|
|
2533
|
+
listener: ResultSortedRowIdsListener,
|
|
2574
2534
|
): Id;
|
|
2575
2535
|
|
|
2576
2536
|
/**
|
|
@@ -2685,33 +2645,24 @@ export interface Queries {
|
|
|
2685
2645
|
* called with a reference to the Queries object, the Id of the Table (which
|
|
2686
2646
|
* is also the query Id), and the Id of the result Row that changed.
|
|
2687
2647
|
*
|
|
2688
|
-
*
|
|
2689
|
-
*
|
|
2690
|
-
*
|
|
2648
|
+
* Such a listener is only called when a Cell is added to, or removed from,
|
|
2649
|
+
* the result Row. To listen to all changes in the result Row, use the
|
|
2650
|
+
* addResultRowListener method.
|
|
2691
2651
|
*
|
|
2692
2652
|
* You can either listen to a single result Row (by specifying the query Id
|
|
2693
2653
|
* and Row Id as the method's first two parameters) or changes to any Row (by
|
|
2694
|
-
* providing `null`).
|
|
2654
|
+
* providing `null` wildcards).
|
|
2695
2655
|
*
|
|
2696
2656
|
* Both, either, or neither of the `queryId` and `rowId` parameters can be
|
|
2697
2657
|
* wildcarded with `null`. You can listen to a specific result Row in a
|
|
2698
2658
|
* specific query, any result Row in a specific query, a specific result Row
|
|
2699
2659
|
* in any query, or any result Row in any query.
|
|
2700
2660
|
*
|
|
2701
|
-
* Use the optional `trackReorder` parameter to additionally track when the
|
|
2702
|
-
* set of Ids has not changed, but the order has - for example when a Cell
|
|
2703
|
-
* from the middle of the Row is removed and then added back within the same
|
|
2704
|
-
* transaction. This behavior is disabled by default due to the potential
|
|
2705
|
-
* performance cost of detecting such changes.
|
|
2706
|
-
*
|
|
2707
2661
|
* @param queryId The Id of the query to listen to, or `null` as a wildcard.
|
|
2708
2662
|
* @param rowId The Id of the result Row to listen to, or `null` as a
|
|
2709
2663
|
* wildcard.
|
|
2710
2664
|
* @param listener The function that will be called whenever the Cell Ids in
|
|
2711
2665
|
* the result Row change.
|
|
2712
|
-
* @param trackReorder An optional boolean that indicates that the listener
|
|
2713
|
-
* should be called if the set of Ids remains the same but their order
|
|
2714
|
-
* changes.
|
|
2715
2666
|
* @returns A unique Id for the listener that can later be used to remove it.
|
|
2716
2667
|
* @example
|
|
2717
2668
|
* This example registers a listener that responds to any change to the Cell
|
|
@@ -2795,7 +2746,6 @@ export interface Queries {
|
|
|
2795
2746
|
queryId: IdOrNull,
|
|
2796
2747
|
rowId: IdOrNull,
|
|
2797
2748
|
listener: ResultCellIdsListener,
|
|
2798
|
-
trackReorder?: boolean,
|
|
2799
2749
|
): Id;
|
|
2800
2750
|
|
|
2801
2751
|
/**
|