tinybase 2.0.0-beta.1 → 2.0.0-beta.4
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 +5 -4
- 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 +5 -4
- 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 +7 -1
- package/lib/debug/queries.d.ts +296 -326
- package/lib/debug/queries.js +71 -192
- package/lib/debug/relationships.d.ts +7 -6
- 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 +322 -390
- package/lib/debug/ui-react.d.ts +850 -68
- package/lib/debug/ui-react.js +217 -120
- 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 +7 -1
- package/lib/queries.d.ts +296 -326
- package/lib/queries.js +1 -1
- package/lib/queries.js.gz +0 -0
- package/lib/relationships.d.ts +7 -6
- 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 +850 -68
- 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 +28 -27
- package/readme.md +11 -11
package/lib/debug/queries.d.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*
|
|
10
10
|
* @packageDocumentation
|
|
11
11
|
* @module queries
|
|
12
|
-
* @since v2.0.0
|
|
12
|
+
* @since v2.0.0
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import {
|
|
@@ -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
|
|
@@ -38,7 +38,7 @@ import {Id, IdOrNull, Ids, SortKey} from './common.d';
|
|
|
38
38
|
* @param length The length of the array of Cell values to be aggregated.
|
|
39
39
|
* @returns The value of the aggregation.
|
|
40
40
|
* @category Aggregators
|
|
41
|
-
* @since v2.0.0
|
|
41
|
+
* @since v2.0.0
|
|
42
42
|
*/
|
|
43
43
|
export type Aggregate = (cells: Cell[], length: number) => Cell;
|
|
44
44
|
|
|
@@ -64,7 +64,7 @@ export type Aggregate = (cells: Cell[], length: number) => Cell;
|
|
|
64
64
|
* @param length The length of the array of Cell values in the aggregation.
|
|
65
65
|
* @returns The new value of the aggregation.
|
|
66
66
|
* @category Aggregators
|
|
67
|
-
* @since v2.0.0
|
|
67
|
+
* @since v2.0.0
|
|
68
68
|
*/
|
|
69
69
|
export type AggregateAdd = (
|
|
70
70
|
current: Cell,
|
|
@@ -97,7 +97,7 @@ export type AggregateAdd = (
|
|
|
97
97
|
* @param length The length of the array of Cell values in the aggregation.
|
|
98
98
|
* @returns The new value of the aggregation.
|
|
99
99
|
* @category Aggregators
|
|
100
|
-
* @since v2.0.0
|
|
100
|
+
* @since v2.0.0
|
|
101
101
|
*/
|
|
102
102
|
export type AggregateRemove = (
|
|
103
103
|
current: Cell,
|
|
@@ -129,7 +129,7 @@ export type AggregateRemove = (
|
|
|
129
129
|
* @param length The length of the array of Cell values in the aggregation.
|
|
130
130
|
* @returns The new value of the aggregation.
|
|
131
131
|
* @category Aggregators
|
|
132
|
-
* @since v2.0.0
|
|
132
|
+
* @since v2.0.0
|
|
133
133
|
*/
|
|
134
134
|
export type AggregateReplace = (
|
|
135
135
|
current: Cell,
|
|
@@ -147,7 +147,7 @@ export type AggregateReplace = (
|
|
|
147
147
|
*
|
|
148
148
|
* @param queryId The Id of the query that the callback can operate on.
|
|
149
149
|
* @category Callback
|
|
150
|
-
* @since v2.0.0
|
|
150
|
+
* @since v2.0.0
|
|
151
151
|
*/
|
|
152
152
|
export type QueryCallback = (queryId: Id) => void;
|
|
153
153
|
|
|
@@ -168,7 +168,7 @@ export type QueryCallback = (queryId: Id) => void;
|
|
|
168
168
|
* @param getCellChange A function that returns information about any Cell's
|
|
169
169
|
* changes.
|
|
170
170
|
* @category Listener
|
|
171
|
-
* @since v2.0.0
|
|
171
|
+
* @since v2.0.0
|
|
172
172
|
*/
|
|
173
173
|
export type ResultTableListener = (
|
|
174
174
|
queries: Queries,
|
|
@@ -190,10 +190,45 @@ export type ResultTableListener = (
|
|
|
190
190
|
* @param queries A reference to the Queries object that changed.
|
|
191
191
|
* @param tableId The Id of the Table that changed, which is also the query Id.
|
|
192
192
|
* @category Listener
|
|
193
|
-
* @since v2.0.0
|
|
193
|
+
* @since v2.0.0
|
|
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
|
|
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.
|
|
@@ -212,7 +247,7 @@ export type ResultRowIdsListener = (queries: Queries, tableId: Id) => void;
|
|
|
212
247
|
* @param getCellChange A function that returns information about any Cell's
|
|
213
248
|
* changes.
|
|
214
249
|
* @category Listener
|
|
215
|
-
* @since v2.0.0
|
|
250
|
+
* @since v2.0.0
|
|
216
251
|
*/
|
|
217
252
|
export type ResultRowListener = (
|
|
218
253
|
queries: Queries,
|
|
@@ -236,7 +271,7 @@ export type ResultRowListener = (
|
|
|
236
271
|
* @param tableId The Id of the Table that changed, which is also the query Id.
|
|
237
272
|
* @param rowId The Id of the Row that changed.
|
|
238
273
|
* @category Listener
|
|
239
|
-
* @since v2.0.0
|
|
274
|
+
* @since v2.0.0
|
|
240
275
|
*/
|
|
241
276
|
export type ResultCellIdsListener = (
|
|
242
277
|
queries: Queries,
|
|
@@ -266,7 +301,7 @@ export type ResultCellIdsListener = (
|
|
|
266
301
|
* @param getCellChange A function that returns information about any Cell's
|
|
267
302
|
* changes.
|
|
268
303
|
* @category Listener
|
|
269
|
-
* @since v2.0.0
|
|
304
|
+
* @since v2.0.0
|
|
270
305
|
*/
|
|
271
306
|
export type ResultCellListener = (
|
|
272
307
|
queries: Queries,
|
|
@@ -286,27 +321,27 @@ export type ResultCellListener = (
|
|
|
286
321
|
* and is only populated in a debug build.
|
|
287
322
|
*
|
|
288
323
|
* @category Development
|
|
289
|
-
* @since v2.0.0
|
|
324
|
+
* @since v2.0.0
|
|
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
|
};
|
|
@@ -320,7 +355,7 @@ export type QueriesListenerStats = {
|
|
|
320
355
|
* calculated values. See those methods for specific examples.
|
|
321
356
|
*
|
|
322
357
|
* @category Callback
|
|
323
|
-
* @since v2.0.0
|
|
358
|
+
* @since v2.0.0
|
|
324
359
|
*/
|
|
325
360
|
export type GetTableCell = {
|
|
326
361
|
/**
|
|
@@ -441,7 +476,7 @@ export type GetTableCell = {
|
|
|
441
476
|
* // -> {cujo: {description: 'dog for Carol'}}
|
|
442
477
|
* ```
|
|
443
478
|
* @category Definition
|
|
444
|
-
* @since v2.0.0
|
|
479
|
+
* @since v2.0.0
|
|
445
480
|
*/
|
|
446
481
|
export type Select = {
|
|
447
482
|
/**
|
|
@@ -526,7 +561,7 @@ export type Select = {
|
|
|
526
561
|
* // -> {cujo: {petSpecies: 'dog', ownerName: 'Carol'}}
|
|
527
562
|
* ```
|
|
528
563
|
* @category Definition
|
|
529
|
-
* @since v2.0.0
|
|
564
|
+
* @since v2.0.0
|
|
530
565
|
*/
|
|
531
566
|
export type SelectedAs = {
|
|
532
567
|
/**
|
|
@@ -699,7 +734,7 @@ export type SelectedAs = {
|
|
|
699
734
|
* // -> {cujo: {description: 'dog in Washington'}}
|
|
700
735
|
* ```
|
|
701
736
|
* @category Definition
|
|
702
|
-
* @since v2.0.0
|
|
737
|
+
* @since v2.0.0
|
|
703
738
|
*/
|
|
704
739
|
export type Join = {
|
|
705
740
|
/**
|
|
@@ -813,7 +848,7 @@ export type Join = {
|
|
|
813
848
|
* // -> {cujo: {buyer: 'Carol', seller: 'Alice'}}
|
|
814
849
|
* ```
|
|
815
850
|
* @category Definition
|
|
816
|
-
* @since v2.0.0
|
|
851
|
+
* @since v2.0.0
|
|
817
852
|
*/
|
|
818
853
|
export type JoinedAs = {as: (joinedTableId: Id) => void};
|
|
819
854
|
|
|
@@ -931,7 +966,7 @@ export type JoinedAs = {as: (joinedTableId: Id) => void};
|
|
|
931
966
|
* // -> {cujo: {species: 'dog', state: 'WA'}}
|
|
932
967
|
* ```
|
|
933
968
|
* @category Definition
|
|
934
|
-
* @since v2.0.0
|
|
969
|
+
* @since v2.0.0
|
|
935
970
|
*/
|
|
936
971
|
export type Where = {
|
|
937
972
|
/**
|
|
@@ -1136,6 +1171,8 @@ export type Where = {
|
|
|
1136
1171
|
* // -> {1: {owner: 'bob', lowestPriceOver2: 3}}
|
|
1137
1172
|
* // Both have a parrot at 3. Alice's worm at 1 is excluded from aggregation.
|
|
1138
1173
|
* ```
|
|
1174
|
+
* @category Definition
|
|
1175
|
+
* @since v2.0.0
|
|
1139
1176
|
*/
|
|
1140
1177
|
export type Group = (
|
|
1141
1178
|
selectedCellId: Id,
|
|
@@ -1180,7 +1217,7 @@ export type Group = (
|
|
|
1180
1217
|
* // -> {1: {species: 'cat', minPrice: 3, maxPrice: 4}}
|
|
1181
1218
|
* ```
|
|
1182
1219
|
* @category Definition
|
|
1183
|
-
* @since v2.0.0
|
|
1220
|
+
* @since v2.0.0
|
|
1184
1221
|
*/
|
|
1185
1222
|
export type GroupedAs = {as: (groupedCellId: Id) => void};
|
|
1186
1223
|
|
|
@@ -1270,7 +1307,7 @@ export type GroupedAs = {as: (groupedCellId: Id) => void};
|
|
|
1270
1307
|
* // Parrots are filtered out because they have zero range in price.
|
|
1271
1308
|
* ```
|
|
1272
1309
|
* @category Definition
|
|
1273
|
-
* @since v2.0.0
|
|
1310
|
+
* @since v2.0.0
|
|
1274
1311
|
*/
|
|
1275
1312
|
export type Having = {
|
|
1276
1313
|
/**
|
|
@@ -1293,212 +1330,6 @@ export type Having = {
|
|
|
1293
1330
|
(condition: (getSelectedOrGroupedCell: GetCell) => boolean): void;
|
|
1294
1331
|
};
|
|
1295
1332
|
|
|
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
|
-
* @example
|
|
1327
|
-
* This example shows a query that orders a Table by a numeric Cell, in a
|
|
1328
|
-
* descending fashion.
|
|
1329
|
-
*
|
|
1330
|
-
* ```js
|
|
1331
|
-
* const store = createStore().setTable('pets', {
|
|
1332
|
-
* cujo: {price: 4},
|
|
1333
|
-
* fido: {price: 5},
|
|
1334
|
-
* tom: {price: 3},
|
|
1335
|
-
* carnaby: {price: 3},
|
|
1336
|
-
* felix: {price: 4},
|
|
1337
|
-
* polly: {price: 3},
|
|
1338
|
-
* });
|
|
1339
|
-
*
|
|
1340
|
-
* const queries = createQueries(store);
|
|
1341
|
-
* queries.setQueryDefinition('query', 'pets', ({select, order}) => {
|
|
1342
|
-
* select('pets', 'price');
|
|
1343
|
-
* order('price', true);
|
|
1344
|
-
* });
|
|
1345
|
-
*
|
|
1346
|
-
* queries.forEachResultRow('query', (rowId) => {
|
|
1347
|
-
* console.log({[rowId]: queries.getResultRow('query', rowId)});
|
|
1348
|
-
* });
|
|
1349
|
-
* // -> {fido: {price: 5}}
|
|
1350
|
-
* // -> {cujo: {price: 4}}
|
|
1351
|
-
* // -> {felix: {price: 4}}
|
|
1352
|
-
* // -> {tom: {price: 3}}
|
|
1353
|
-
* // -> {carnaby: {price: 3}}
|
|
1354
|
-
* // -> {polly: {price: 3}}
|
|
1355
|
-
* ```
|
|
1356
|
-
* @example
|
|
1357
|
-
* This example shows a query that orders a Table by a string Cell, and then a
|
|
1358
|
-
* calculated sort key based on the Row Id.
|
|
1359
|
-
*
|
|
1360
|
-
* ```js
|
|
1361
|
-
* const store = createStore().setTable('pets', {
|
|
1362
|
-
* cujo: {species: 'dog'},
|
|
1363
|
-
* fido: {species: 'dog'},
|
|
1364
|
-
* tom: {species: 'cat'},
|
|
1365
|
-
* carnaby: {species: 'parrot'},
|
|
1366
|
-
* felix: {species: 'cat'},
|
|
1367
|
-
* polly: {species: 'parrot'},
|
|
1368
|
-
* });
|
|
1369
|
-
*
|
|
1370
|
-
* const queries = createQueries(store);
|
|
1371
|
-
* queries.setQueryDefinition('query', 'pets', ({select, order}) => {
|
|
1372
|
-
* select('pets', 'species');
|
|
1373
|
-
* order('species');
|
|
1374
|
-
* order((getSelectedOrGroupedCell, rowId) => rowId);
|
|
1375
|
-
* });
|
|
1376
|
-
*
|
|
1377
|
-
* queries.forEachResultRow('query', (rowId) => {
|
|
1378
|
-
* console.log({[rowId]: queries.getResultRow('query', rowId)});
|
|
1379
|
-
* });
|
|
1380
|
-
* // -> {felix: {species: 'cat'}}
|
|
1381
|
-
* // -> {tom: {species: 'cat'}}
|
|
1382
|
-
* // -> {cujo: {species: 'dog'}}
|
|
1383
|
-
* // -> {fido: {species: 'dog'}}
|
|
1384
|
-
* // -> {carnaby: {species: 'parrot'}}
|
|
1385
|
-
* // -> {polly: {species: 'parrot'}}
|
|
1386
|
-
* ```
|
|
1387
|
-
* @category Definition
|
|
1388
|
-
* @since v2.0.0-beta
|
|
1389
|
-
*/
|
|
1390
|
-
export type Order = {
|
|
1391
|
-
/**
|
|
1392
|
-
* Calling this function with the first parameter as an Id is used to sort the
|
|
1393
|
-
* Rows by the value in that Cell.
|
|
1394
|
-
*
|
|
1395
|
-
* @param selectedOrGroupedCellId The Id of the Cell in the query to sort by.
|
|
1396
|
-
* @param descending Set to `true` to have the Rows sorted in descending
|
|
1397
|
-
* order.
|
|
1398
|
-
*/
|
|
1399
|
-
(selectedOrGroupedCellId: Id, descending?: boolean): void;
|
|
1400
|
-
/**
|
|
1401
|
-
* Calling this function with the first parameter as a function is used to
|
|
1402
|
-
* sort the Rows by a value calculate from their Cells or Id.
|
|
1403
|
-
*
|
|
1404
|
-
* @param getSortKey A callback that takes a GetCell function and that should
|
|
1405
|
-
* return a 'sort key' to be used for ordering the Rows.
|
|
1406
|
-
* @param descending Set to `true` to have the Rows sorted in descending
|
|
1407
|
-
* order.
|
|
1408
|
-
*/
|
|
1409
|
-
(
|
|
1410
|
-
getSortKey: (getSelectedOrGroupedCell: GetCell, rowId: Id) => SortKey,
|
|
1411
|
-
descending?: boolean,
|
|
1412
|
-
): void;
|
|
1413
|
-
};
|
|
1414
|
-
|
|
1415
|
-
/**
|
|
1416
|
-
* The Limit type describes a function that lets you specify how many Rows you
|
|
1417
|
-
* want in the result Table, and how they should be offset.
|
|
1418
|
-
*
|
|
1419
|
-
* The Limit function is provided as an parameter in the `build` parameter of
|
|
1420
|
-
* the setQueryDefinition method.
|
|
1421
|
-
*
|
|
1422
|
-
* A Limit clause can either provide an 'page' offset and size limit, or just
|
|
1423
|
-
* the limit. The offset is zero-based, so if you specify `2`, say, the results
|
|
1424
|
-
* will skip the first two Rows and start with the third.
|
|
1425
|
-
*
|
|
1426
|
-
* This is applied after any grouping and sorting.
|
|
1427
|
-
*
|
|
1428
|
-
* @example
|
|
1429
|
-
* This example shows a query that limits a Table to four Rows from its first.
|
|
1430
|
-
*
|
|
1431
|
-
* ```js
|
|
1432
|
-
* const store = createStore().setTable('pets', {
|
|
1433
|
-
* cujo: {price: 4},
|
|
1434
|
-
* fido: {price: 5},
|
|
1435
|
-
* tom: {price: 3},
|
|
1436
|
-
* carnaby: {price: 3},
|
|
1437
|
-
* felix: {price: 4},
|
|
1438
|
-
* polly: {price: 3},
|
|
1439
|
-
* });
|
|
1440
|
-
*
|
|
1441
|
-
* const queries = createQueries(store);
|
|
1442
|
-
* queries.setQueryDefinition('query', 'pets', ({select, limit}) => {
|
|
1443
|
-
* select('pets', 'price');
|
|
1444
|
-
* limit(4);
|
|
1445
|
-
* });
|
|
1446
|
-
*
|
|
1447
|
-
* queries.forEachResultRow('query', (rowId) => {
|
|
1448
|
-
* console.log({[rowId]: queries.getResultRow('query', rowId)});
|
|
1449
|
-
* });
|
|
1450
|
-
* // -> {cujo: {price: 4}}
|
|
1451
|
-
* // -> {fido: {price: 5}}
|
|
1452
|
-
* // -> {tom: {price: 3}}
|
|
1453
|
-
* // -> {carnaby: {price: 3}}
|
|
1454
|
-
* ```
|
|
1455
|
-
* @example
|
|
1456
|
-
* This example shows a query that limits a Table to three Rows, offset by two.
|
|
1457
|
-
*
|
|
1458
|
-
* ```js
|
|
1459
|
-
* const store = createStore().setTable('pets', {
|
|
1460
|
-
* cujo: {price: 4},
|
|
1461
|
-
* fido: {price: 5},
|
|
1462
|
-
* tom: {price: 3},
|
|
1463
|
-
* carnaby: {price: 3},
|
|
1464
|
-
* felix: {price: 4},
|
|
1465
|
-
* polly: {price: 3},
|
|
1466
|
-
* });
|
|
1467
|
-
*
|
|
1468
|
-
* const queries = createQueries(store);
|
|
1469
|
-
* queries.setQueryDefinition('query', 'pets', ({select, limit}) => {
|
|
1470
|
-
* select('pets', 'price');
|
|
1471
|
-
* limit(2, 3);
|
|
1472
|
-
* });
|
|
1473
|
-
*
|
|
1474
|
-
* queries.forEachResultRow('query', (rowId) => {
|
|
1475
|
-
* console.log({[rowId]: queries.getResultRow('query', rowId)});
|
|
1476
|
-
* });
|
|
1477
|
-
* // -> {tom: {price: 3}}
|
|
1478
|
-
* // -> {carnaby: {price: 3}}
|
|
1479
|
-
* // -> {felix: {price: 4}}
|
|
1480
|
-
* ```
|
|
1481
|
-
* @category Definition
|
|
1482
|
-
* @since v2.0.0-beta
|
|
1483
|
-
*/
|
|
1484
|
-
export type Limit = {
|
|
1485
|
-
/**
|
|
1486
|
-
* Calling this function with one numeric parameter is used to limit the Rows
|
|
1487
|
-
* returned, starting from the first.
|
|
1488
|
-
*
|
|
1489
|
-
* @param limit The number of Rows to return.
|
|
1490
|
-
*/
|
|
1491
|
-
(limit: number): void;
|
|
1492
|
-
/**
|
|
1493
|
-
* Calling this function with two numeric parameters is used to offset the
|
|
1494
|
-
* start of the results, and then limit the Rows returned.
|
|
1495
|
-
*
|
|
1496
|
-
* @param offset The number of Rows to skip.
|
|
1497
|
-
* @param limit The number of Rows to return.
|
|
1498
|
-
*/
|
|
1499
|
-
(offset: number, limit: number): void;
|
|
1500
|
-
};
|
|
1501
|
-
|
|
1502
1333
|
/**
|
|
1503
1334
|
* A Queries object lets you create and track queries of the data in Store
|
|
1504
1335
|
* objects.
|
|
@@ -1560,40 +1391,39 @@ export type Limit = {
|
|
|
1560
1391
|
* console.log(queries.getResultTable('petOwners'));
|
|
1561
1392
|
* // -> {fido: {owner: 'Alice'}, felix: {owner: 'Bob'}, cujo: {owner: 'Carol'}}
|
|
1562
1393
|
*
|
|
1563
|
-
* // A grouped
|
|
1394
|
+
* // A grouped query:
|
|
1564
1395
|
* queries.setQueryDefinition(
|
|
1565
1396
|
* 'colorPrice',
|
|
1566
1397
|
* 'pets',
|
|
1567
|
-
* ({select, join, group
|
|
1398
|
+
* ({select, join, group}) => {
|
|
1568
1399
|
* select('color');
|
|
1569
1400
|
* select('species', 'price');
|
|
1570
1401
|
* join('species', 'species');
|
|
1571
1402
|
* group('price', 'avg');
|
|
1572
|
-
* order('price');
|
|
1573
1403
|
* },
|
|
1574
1404
|
* );
|
|
1575
1405
|
* console.log(queries.getResultTable('colorPrice'));
|
|
1576
1406
|
* // -> {"1": {color: 'black', price: 4.5}, "0": {color: 'brown', price: 5}}
|
|
1577
|
-
* console.log(queries.
|
|
1578
|
-
* // -> ["
|
|
1407
|
+
* console.log(queries.getResultSortedRowIds('colorPrice', 'price', true));
|
|
1408
|
+
* // -> ["0", "1"]
|
|
1579
1409
|
*
|
|
1580
1410
|
* const listenerId = queries.addResultTableListener('colorPrice', () => {
|
|
1581
1411
|
* console.log('Average prices per color changed');
|
|
1582
1412
|
* console.log(queries.getResultTable('colorPrice'));
|
|
1583
|
-
* console.log(queries.
|
|
1413
|
+
* console.log(queries.getResultSortedRowIds('colorPrice', 'price', true));
|
|
1584
1414
|
* });
|
|
1585
1415
|
*
|
|
1586
1416
|
* store.setRow('pets', 'lowly', {species: 'worm', color: 'brown'});
|
|
1587
1417
|
* // -> 'Average prices per color changed'
|
|
1588
1418
|
* // -> {"0": {color: 'brown', price: 3}, "1": {color: 'black', price: 4.5}}
|
|
1589
|
-
* // -> ["
|
|
1419
|
+
* // -> ["1", "0"]
|
|
1590
1420
|
*
|
|
1591
1421
|
* queries.delListener(listenerId);
|
|
1592
1422
|
* queries.destroy();
|
|
1593
1423
|
* ```
|
|
1594
1424
|
* @see Queries guides
|
|
1595
1425
|
* @category Queries
|
|
1596
|
-
* @since v2.0.0
|
|
1426
|
+
* @since v2.0.0
|
|
1597
1427
|
*/
|
|
1598
1428
|
export interface Queries {
|
|
1599
1429
|
/**
|
|
@@ -1609,7 +1439,7 @@ export interface Queries {
|
|
|
1609
1439
|
* The third `build` parameter is a callback that you provide to define the
|
|
1610
1440
|
* query. That callback is provided with a `builders` object that contains the
|
|
1611
1441
|
* named 'keywords' for the query, like `select`, `join`, and so on. You can
|
|
1612
|
-
* see how that is used in the simple example below. The following
|
|
1442
|
+
* see how that is used in the simple example below. The following five
|
|
1613
1443
|
* clause types are supported:
|
|
1614
1444
|
*
|
|
1615
1445
|
* - The Select type describes a function that lets you specify a Cell or
|
|
@@ -1623,13 +1453,12 @@ export interface Queries {
|
|
|
1623
1453
|
* of a Cell in multiple result Rows should be aggregated together.
|
|
1624
1454
|
* - The Having type describes a function that lets you specify conditions to
|
|
1625
1455
|
* filter results, based on the grouped Cells resulting from a Group clause.
|
|
1626
|
-
* - The Order type describes a function that lets you specify how you want
|
|
1627
|
-
* the Rows in the result Table to be ordered, based on values within.
|
|
1628
|
-
* - The Limit type describes a function that lets you specify how many Rows
|
|
1629
|
-
* you want in the result Table, and how they should be offset.
|
|
1630
1456
|
*
|
|
1631
1457
|
* Full documentation and examples are provided in the sections for each of
|
|
1632
1458
|
* those clause types.
|
|
1459
|
+
*
|
|
1460
|
+
* Additionally, you can use the getResultSortedRowIds method and
|
|
1461
|
+
* addResultSortedRowIdsListener method to sort and paginate the results.
|
|
1633
1462
|
*
|
|
1634
1463
|
* @param queryId The Id of the query to define.
|
|
1635
1464
|
* @param tableId The Id of the main Table the query will be based on.
|
|
@@ -1658,7 +1487,7 @@ export interface Queries {
|
|
|
1658
1487
|
* // -> {fido: {color: 'brown'}, cujo: {color: 'black'}}
|
|
1659
1488
|
* ```
|
|
1660
1489
|
* @category Configuration
|
|
1661
|
-
* @since v2.0.0
|
|
1490
|
+
* @since v2.0.0
|
|
1662
1491
|
*/
|
|
1663
1492
|
setQueryDefinition(
|
|
1664
1493
|
queryId: Id,
|
|
@@ -1669,8 +1498,6 @@ export interface Queries {
|
|
|
1669
1498
|
where: Where;
|
|
1670
1499
|
group: Group;
|
|
1671
1500
|
having: Having;
|
|
1672
|
-
order: Order;
|
|
1673
|
-
limit: Limit;
|
|
1674
1501
|
}) => void,
|
|
1675
1502
|
): Queries;
|
|
1676
1503
|
|
|
@@ -1703,7 +1530,7 @@ export interface Queries {
|
|
|
1703
1530
|
* // -> []
|
|
1704
1531
|
* ```
|
|
1705
1532
|
* @category Configuration
|
|
1706
|
-
* @since v2.0.0
|
|
1533
|
+
* @since v2.0.0
|
|
1707
1534
|
*/
|
|
1708
1535
|
delQueryDefinition(queryId: Id): Queries;
|
|
1709
1536
|
|
|
@@ -1729,7 +1556,7 @@ export interface Queries {
|
|
|
1729
1556
|
* // -> {fido: {color: 'brown'}}
|
|
1730
1557
|
* ```
|
|
1731
1558
|
* @category Getter
|
|
1732
|
-
* @since v2.0.0
|
|
1559
|
+
* @since v2.0.0
|
|
1733
1560
|
*/
|
|
1734
1561
|
getStore(): Store;
|
|
1735
1562
|
|
|
@@ -1757,7 +1584,7 @@ export interface Queries {
|
|
|
1757
1584
|
* // -> ['dogColors', 'catColors']
|
|
1758
1585
|
* ```
|
|
1759
1586
|
* @category Getter
|
|
1760
|
-
* @since v2.0.0
|
|
1587
|
+
* @since v2.0.0
|
|
1761
1588
|
*/
|
|
1762
1589
|
getQueryIds(): Ids;
|
|
1763
1590
|
|
|
@@ -1791,7 +1618,7 @@ export interface Queries {
|
|
|
1791
1618
|
* // -> 'catColors'
|
|
1792
1619
|
* ```
|
|
1793
1620
|
* @category Iterator
|
|
1794
|
-
* @since v2.0.0
|
|
1621
|
+
* @since v2.0.0
|
|
1795
1622
|
*/
|
|
1796
1623
|
forEachQuery(queryCallback: QueryCallback): void;
|
|
1797
1624
|
|
|
@@ -1820,7 +1647,7 @@ export interface Queries {
|
|
|
1820
1647
|
* // -> false
|
|
1821
1648
|
* ```
|
|
1822
1649
|
* @category Getter
|
|
1823
|
-
* @since v2.0.0
|
|
1650
|
+
* @since v2.0.0
|
|
1824
1651
|
*/
|
|
1825
1652
|
hasQuery(queryId: Id): boolean;
|
|
1826
1653
|
|
|
@@ -1853,7 +1680,7 @@ export interface Queries {
|
|
|
1853
1680
|
* // -> undefined
|
|
1854
1681
|
* ```
|
|
1855
1682
|
* @category Getter
|
|
1856
|
-
* @since v2.0.0
|
|
1683
|
+
* @since v2.0.0
|
|
1857
1684
|
*/
|
|
1858
1685
|
getTableId(queryId: Id): Id | undefined;
|
|
1859
1686
|
|
|
@@ -1899,7 +1726,7 @@ export interface Queries {
|
|
|
1899
1726
|
* // -> {}
|
|
1900
1727
|
* ```
|
|
1901
1728
|
* @category Result
|
|
1902
|
-
* @since v2.0.0
|
|
1729
|
+
* @since v2.0.0
|
|
1903
1730
|
*/
|
|
1904
1731
|
getResultTable(queryId: Id): Table;
|
|
1905
1732
|
|
|
@@ -1912,9 +1739,6 @@ export interface Queries {
|
|
|
1912
1739
|
* returns a copy of, rather than a reference to the list of Ids, so changes
|
|
1913
1740
|
* made to the list object are not made to the query results themselves.
|
|
1914
1741
|
*
|
|
1915
|
-
* An Order clause in the query explicitly affects the order of entries in
|
|
1916
|
-
* this array.
|
|
1917
|
-
*
|
|
1918
1742
|
* @param queryId The Id of a query.
|
|
1919
1743
|
* @returns An array of the Ids of every Row in the result of the query.
|
|
1920
1744
|
* @example
|
|
@@ -1945,10 +1769,76 @@ export interface Queries {
|
|
|
1945
1769
|
* // -> []
|
|
1946
1770
|
* ```
|
|
1947
1771
|
* @category Result
|
|
1948
|
-
* @since v2.0.0
|
|
1772
|
+
* @since v2.0.0
|
|
1949
1773
|
*/
|
|
1950
1774
|
getResultRowIds(queryId: Id): Ids;
|
|
1951
1775
|
|
|
1776
|
+
/**
|
|
1777
|
+
* The getResultSortedRowIds method returns the Ids of every Row in the result
|
|
1778
|
+
* Table of the given query, sorted according to the values in a specified
|
|
1779
|
+
* Cell.
|
|
1780
|
+
*
|
|
1781
|
+
* This has the same behavior as a Store's getSortedRowIds method. For
|
|
1782
|
+
* example, if the query Id is invalid, the method returns an empty array.
|
|
1783
|
+
* Similarly, the sorting of the rows is alphanumeric, and you can indicate
|
|
1784
|
+
* whether it should be in descending order. The `offset` and `limit`
|
|
1785
|
+
* parameters are used to paginate results, but default to `0` and `undefined`
|
|
1786
|
+
* to return all available Row Ids if not specified.
|
|
1787
|
+
*
|
|
1788
|
+
* Note that every call to this method will perform the sorting afresh - there
|
|
1789
|
+
* is no caching of the results - and so you are advised to memoize the
|
|
1790
|
+
* results yourself, especially when the result Table is large. For a
|
|
1791
|
+
* performant approach to tracking the sorted Row Ids when they change, use
|
|
1792
|
+
* the addResultSortedRowIdsListener method.
|
|
1793
|
+
*
|
|
1794
|
+
* @param queryId The Id of a query.
|
|
1795
|
+
* @param cellId The Id of the Cell whose values are used for the sorting, or
|
|
1796
|
+
* `undefined` to by sort the Row Id itself.
|
|
1797
|
+
* @param descending Whether the sorting should be in descending order.
|
|
1798
|
+
* @param offset The number of Row Ids to skip for pagination purposes, if
|
|
1799
|
+
* any.
|
|
1800
|
+
* @param limit The maximum number of Row Ids to return, or `undefined` for
|
|
1801
|
+
* all.
|
|
1802
|
+
* @returns An array of the sorted Ids of every Row in the result of the
|
|
1803
|
+
* query.
|
|
1804
|
+
* @example
|
|
1805
|
+
* This example creates a Queries object, a single query definition, and then
|
|
1806
|
+
* calls this method on it (as well as a non-existent definition) to get the
|
|
1807
|
+
* result Row Ids.
|
|
1808
|
+
*
|
|
1809
|
+
* ```js
|
|
1810
|
+
* const store = createStore().setTable('pets', {
|
|
1811
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
1812
|
+
* felix: {species: 'cat', color: 'black'},
|
|
1813
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
1814
|
+
* });
|
|
1815
|
+
*
|
|
1816
|
+
* const queries = createQueries(store).setQueryDefinition(
|
|
1817
|
+
* 'dogColors',
|
|
1818
|
+
* 'pets',
|
|
1819
|
+
* ({select, where}) => {
|
|
1820
|
+
* select('color');
|
|
1821
|
+
* where('species', 'dog');
|
|
1822
|
+
* },
|
|
1823
|
+
* );
|
|
1824
|
+
*
|
|
1825
|
+
* console.log(queries.getResultSortedRowIds('dogColors', 'color'));
|
|
1826
|
+
* // -> ['cujo', 'fido']
|
|
1827
|
+
*
|
|
1828
|
+
* console.log(queries.getResultSortedRowIds('catColors', 'color'));
|
|
1829
|
+
* // -> []
|
|
1830
|
+
* ```
|
|
1831
|
+
* @category Result
|
|
1832
|
+
* @since v2.0.0
|
|
1833
|
+
*/
|
|
1834
|
+
getResultSortedRowIds(
|
|
1835
|
+
queryId: Id,
|
|
1836
|
+
cellId?: Id,
|
|
1837
|
+
descending?: boolean,
|
|
1838
|
+
offset?: number,
|
|
1839
|
+
limit?: number,
|
|
1840
|
+
): Ids;
|
|
1841
|
+
|
|
1952
1842
|
/**
|
|
1953
1843
|
* The getResultRow method returns an object containing the entire data of a
|
|
1954
1844
|
* single Row in the result Table of the given query.
|
|
@@ -1991,7 +1881,7 @@ export interface Queries {
|
|
|
1991
1881
|
* // -> {}
|
|
1992
1882
|
* ```
|
|
1993
1883
|
* @category Result
|
|
1994
|
-
* @since v2.0.0
|
|
1884
|
+
* @since v2.0.0
|
|
1995
1885
|
*/
|
|
1996
1886
|
getResultRow(queryId: Id, rowId: Id): Row;
|
|
1997
1887
|
|
|
@@ -2037,7 +1927,7 @@ export interface Queries {
|
|
|
2037
1927
|
* // -> []
|
|
2038
1928
|
* ```
|
|
2039
1929
|
* @category Result
|
|
2040
|
-
* @since v2.0.0
|
|
1930
|
+
* @since v2.0.0
|
|
2041
1931
|
*/
|
|
2042
1932
|
getResultCellIds(queryId: Id, rowId: Id): Ids;
|
|
2043
1933
|
|
|
@@ -2080,7 +1970,7 @@ export interface Queries {
|
|
|
2080
1970
|
* // -> undefined
|
|
2081
1971
|
* ```
|
|
2082
1972
|
* @category Result
|
|
2083
|
-
* @since v2.0.0
|
|
1973
|
+
* @since v2.0.0
|
|
2084
1974
|
*/
|
|
2085
1975
|
getResultCell(queryId: Id, rowId: Id, cellId: Id): CellOrUndefined;
|
|
2086
1976
|
|
|
@@ -2115,13 +2005,13 @@ export interface Queries {
|
|
|
2115
2005
|
* // -> false
|
|
2116
2006
|
* ```
|
|
2117
2007
|
* @category Result
|
|
2118
|
-
* @since v2.0.0
|
|
2008
|
+
* @since v2.0.0
|
|
2119
2009
|
*/
|
|
2120
2010
|
hasResultTable(queryId: Id): boolean;
|
|
2121
2011
|
|
|
2122
2012
|
/**
|
|
2123
|
-
* The hasResultRow method returns a boolean indicating whether a given
|
|
2124
|
-
*
|
|
2013
|
+
* The hasResultRow method returns a boolean indicating whether a given result
|
|
2014
|
+
* Row exists.
|
|
2125
2015
|
*
|
|
2126
2016
|
* @param queryId The Id of a possible query.
|
|
2127
2017
|
* @param rowId The Id of a possible Row.
|
|
@@ -2151,7 +2041,7 @@ export interface Queries {
|
|
|
2151
2041
|
* // -> false
|
|
2152
2042
|
* ```
|
|
2153
2043
|
* @category Result
|
|
2154
|
-
* @since v2.0.0
|
|
2044
|
+
* @since v2.0.0
|
|
2155
2045
|
*/
|
|
2156
2046
|
hasResultRow(queryId: Id, rowId: Id): boolean;
|
|
2157
2047
|
|
|
@@ -2188,7 +2078,7 @@ export interface Queries {
|
|
|
2188
2078
|
* // -> false
|
|
2189
2079
|
* ```
|
|
2190
2080
|
* @category Result
|
|
2191
|
-
* @since v2.0.0
|
|
2081
|
+
* @since v2.0.0
|
|
2192
2082
|
*/
|
|
2193
2083
|
hasResultCell(queryId: Id, rowId: Id, cellId: Id): boolean;
|
|
2194
2084
|
|
|
@@ -2235,7 +2125,7 @@ export interface Queries {
|
|
|
2235
2125
|
* // -> '- felix'
|
|
2236
2126
|
* ```
|
|
2237
2127
|
* @category Iterator
|
|
2238
|
-
* @since v2.0.0
|
|
2128
|
+
* @since v2.0.0
|
|
2239
2129
|
*/
|
|
2240
2130
|
forEachResultTable(tableCallback: TableCallback): void;
|
|
2241
2131
|
|
|
@@ -2281,7 +2171,7 @@ export interface Queries {
|
|
|
2281
2171
|
* // -> '- color'
|
|
2282
2172
|
* ```
|
|
2283
2173
|
* @category Iterator
|
|
2284
|
-
* @since v2.0.0
|
|
2174
|
+
* @since v2.0.0
|
|
2285
2175
|
*/
|
|
2286
2176
|
forEachResultRow(queryId: Id, rowCallback: RowCallback): void;
|
|
2287
2177
|
|
|
@@ -2324,7 +2214,7 @@ export interface Queries {
|
|
|
2324
2214
|
* // -> 'color: brown'
|
|
2325
2215
|
* ```
|
|
2326
2216
|
* @category Iterator
|
|
2327
|
-
* @since v2.0.0
|
|
2217
|
+
* @since v2.0.0
|
|
2328
2218
|
*/
|
|
2329
2219
|
forEachResultCell(queryId: Id, rowId: Id, cellCallback: CellCallback): void;
|
|
2330
2220
|
|
|
@@ -2415,6 +2305,7 @@ export interface Queries {
|
|
|
2415
2305
|
* store.delListener(listenerId);
|
|
2416
2306
|
* ```
|
|
2417
2307
|
* @category Listener
|
|
2308
|
+
* @since v2.0.0
|
|
2418
2309
|
*/
|
|
2419
2310
|
addResultTableListener(queryId: IdOrNull, listener: ResultTableListener): Id;
|
|
2420
2311
|
|
|
@@ -2435,22 +2326,13 @@ export interface Queries {
|
|
|
2435
2326
|
* the method's first parameter) or changes to any result Table (by providing
|
|
2436
2327
|
* a `null` wildcard).
|
|
2437
2328
|
*
|
|
2438
|
-
* Use the optional `trackReorder` parameter to additionally track when the
|
|
2439
|
-
* set of Ids has not changed, but the order has - specifically when the Order
|
|
2440
|
-
* clause of the query causes the Row Ids to be re-sorted. This behavior is
|
|
2441
|
-
* disabled by default due to the potential performance cost of detecting such
|
|
2442
|
-
* changes.
|
|
2443
|
-
*
|
|
2444
2329
|
* @param queryId The Id of the query to listen to, or `null` as a wildcard.
|
|
2445
2330
|
* @param listener The function that will be called whenever the Row Ids in
|
|
2446
2331
|
* the result Table change.
|
|
2447
|
-
* @param trackReorder An optional boolean that indicates that the listener
|
|
2448
|
-
* should be called if the set of Ids remains the same but their order
|
|
2449
|
-
* changes.
|
|
2450
2332
|
* @returns A unique Id for the listener that can later be used to remove it.
|
|
2451
2333
|
* @example
|
|
2452
2334
|
* This example registers a listener that responds to any change to the Row
|
|
2453
|
-
* Ids of a specific result Table
|
|
2335
|
+
* Ids of a specific result Table.
|
|
2454
2336
|
*
|
|
2455
2337
|
* ```js
|
|
2456
2338
|
* const store = createStore().setTable('pets', {
|
|
@@ -2462,16 +2344,15 @@ export interface Queries {
|
|
|
2462
2344
|
* const queries = createQueries(store).setQueryDefinition(
|
|
2463
2345
|
* 'dogColors',
|
|
2464
2346
|
* 'pets',
|
|
2465
|
-
* ({select, where
|
|
2347
|
+
* ({select, where}) => {
|
|
2466
2348
|
* select('color');
|
|
2467
2349
|
* where('species', 'dog');
|
|
2468
|
-
* order('color');
|
|
2469
2350
|
* },
|
|
2470
2351
|
* );
|
|
2471
2352
|
*
|
|
2472
2353
|
* const listenerId = queries.addResultRowIdsListener(
|
|
2473
2354
|
* 'dogColors',
|
|
2474
|
-
* (
|
|
2355
|
+
* (queries, tableId) => {
|
|
2475
2356
|
* console.log(`Row Ids for dogColors result table changed`);
|
|
2476
2357
|
* console.log(queries.getResultRowIds('dogColors'));
|
|
2477
2358
|
* },
|
|
@@ -2479,18 +2360,94 @@ export interface Queries {
|
|
|
2479
2360
|
*
|
|
2480
2361
|
* store.setRow('pets', 'rex', {species: 'dog', color: 'tan'});
|
|
2481
2362
|
* // -> 'Row Ids for dogColors result table changed'
|
|
2482
|
-
* // -> ['
|
|
2363
|
+
* // -> ['fido', 'cujo', 'rex']
|
|
2483
2364
|
*
|
|
2484
|
-
* store.
|
|
2485
|
-
*
|
|
2486
|
-
*
|
|
2365
|
+
* store.delListener(listenerId);
|
|
2366
|
+
* ```
|
|
2367
|
+
* @example
|
|
2368
|
+
* This example registers a listener that responds to any change to the Row
|
|
2369
|
+
* Ids of any result Table.
|
|
2370
|
+
*
|
|
2371
|
+
* ```js
|
|
2372
|
+
* const store = createStore().setTable('pets', {
|
|
2373
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
2374
|
+
* felix: {species: 'cat', color: 'black'},
|
|
2375
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
2376
|
+
* });
|
|
2377
|
+
*
|
|
2378
|
+
* const queries = createQueries(store)
|
|
2379
|
+
* .setQueryDefinition('dogColors', 'pets', ({select, where}) => {
|
|
2380
|
+
* select('color');
|
|
2381
|
+
* where('species', 'dog');
|
|
2382
|
+
* })
|
|
2383
|
+
* .setQueryDefinition('catColors', 'pets', ({select, where}) => {
|
|
2384
|
+
* select('color');
|
|
2385
|
+
* where('species', 'cat');
|
|
2386
|
+
* });
|
|
2387
|
+
*
|
|
2388
|
+
* const listenerId = queries.addResultRowIdsListener(
|
|
2389
|
+
* null,
|
|
2390
|
+
* (queries, tableId) => {
|
|
2391
|
+
* console.log(`Row Ids for ${tableId} result table changed`);
|
|
2392
|
+
* },
|
|
2393
|
+
* );
|
|
2394
|
+
*
|
|
2395
|
+
* store.setRow('pets', 'rex', {species: 'dog', color: 'tan'});
|
|
2396
|
+
* // -> 'Row Ids for dogColors result table changed'
|
|
2397
|
+
* store.setRow('pets', 'tom', {species: 'cat', color: 'gray'});
|
|
2398
|
+
* // -> 'Row Ids for catColors result table changed'
|
|
2487
2399
|
*
|
|
2488
2400
|
* store.delListener(listenerId);
|
|
2489
2401
|
* ```
|
|
2402
|
+
* @category Listener
|
|
2403
|
+
* @since v2.0.0
|
|
2404
|
+
*/
|
|
2405
|
+
addResultRowIdsListener(
|
|
2406
|
+
queryId: IdOrNull,
|
|
2407
|
+
listener: ResultRowIdsListener,
|
|
2408
|
+
): Id;
|
|
2409
|
+
|
|
2410
|
+
/**
|
|
2411
|
+
* The addResultSortedRowIdsListener method registers a listener function with
|
|
2412
|
+
* the Queries object that will be called whenever sorted (and optionally,
|
|
2413
|
+
* paginated) Row Ids in a result Table change.
|
|
2414
|
+
*
|
|
2415
|
+
* The provided listener is a ResultSortedRowIdsListener function, and will be
|
|
2416
|
+
* called with a reference to the Queries object, the Id of the result Table
|
|
2417
|
+
* whose Row Ids sorting changed (which is also the query Id), the Cell Id
|
|
2418
|
+
* being used to sort them, whether descending or not, and the offset and
|
|
2419
|
+
* limit of the number of Ids returned, for pagination purposes. It also
|
|
2420
|
+
* receives the sorted array of Ids itself, so that you can use them in the
|
|
2421
|
+
* listener without the additional cost of an explicit call to
|
|
2422
|
+
* getResultSortedRowIds
|
|
2423
|
+
*
|
|
2424
|
+
* Such a listener is called when a Row is added or removed, but also when a
|
|
2425
|
+
* value in the specified Cell (somewhere in the result Table) has changed
|
|
2426
|
+
* enough to change the sorting of the Row Ids.
|
|
2427
|
+
*
|
|
2428
|
+
* Unlike most other listeners, you cannot provide wildcards (due to the cost
|
|
2429
|
+
* of detecting changes to the sorting). You can only listen to a single
|
|
2430
|
+
* specified result Table, sorted by a single specified Cell.
|
|
2431
|
+
*
|
|
2432
|
+
* The sorting of the rows is alphanumeric, and you can indicate whether it
|
|
2433
|
+
* should be in descending order. The `offset` and `limit` parameters are used
|
|
2434
|
+
* to paginate results, but default to `0` and `undefined` to return all
|
|
2435
|
+
* available Row Ids if not specified.
|
|
2436
|
+
*
|
|
2437
|
+
* @param queryId The Id of the query to listen to.
|
|
2438
|
+
* @param cellId The Id of the Cell whose values are used for the sorting, or
|
|
2439
|
+
* `undefined` to by sort the result Row Id itself.
|
|
2440
|
+
* @param descending Whether the sorting should be in descending order.
|
|
2441
|
+
* @param offset The number of Row Ids to skip for pagination purposes, if
|
|
2442
|
+
* any.
|
|
2443
|
+
* @param limit The maximum number of Row Ids to return, or `undefined` for
|
|
2444
|
+
* all.
|
|
2445
|
+
* @param listener The function that will be called whenever the sorted Row
|
|
2446
|
+
* Ids in the result Table change.
|
|
2447
|
+
* @returns A unique Id for the listener that can later be used to remove it.
|
|
2490
2448
|
* @example
|
|
2491
|
-
* This example registers a listener that responds to
|
|
2492
|
-
*
|
|
2493
|
-
* not changed.
|
|
2449
|
+
* This example registers a listener that responds to any change to the sorted
|
|
2450
|
+
* Row Ids of a specific result Table.
|
|
2494
2451
|
*
|
|
2495
2452
|
* ```js
|
|
2496
2453
|
* const store = createStore().setTable('pets', {
|
|
@@ -2502,35 +2459,35 @@ export interface Queries {
|
|
|
2502
2459
|
* const queries = createQueries(store).setQueryDefinition(
|
|
2503
2460
|
* 'dogColors',
|
|
2504
2461
|
* 'pets',
|
|
2505
|
-
* ({select, where
|
|
2462
|
+
* ({select, where}) => {
|
|
2506
2463
|
* select('color');
|
|
2507
2464
|
* where('species', 'dog');
|
|
2508
|
-
* order('color');
|
|
2509
2465
|
* },
|
|
2510
2466
|
* );
|
|
2511
2467
|
*
|
|
2512
|
-
* const listenerId = queries.
|
|
2468
|
+
* const listenerId = queries.addResultSortedRowIdsListener(
|
|
2513
2469
|
* 'dogColors',
|
|
2514
|
-
*
|
|
2515
|
-
*
|
|
2516
|
-
*
|
|
2470
|
+
* 'color',
|
|
2471
|
+
* false,
|
|
2472
|
+
* 0,
|
|
2473
|
+
* undefined,
|
|
2474
|
+
* (queries, tableId, cellId, descending, offset, limit, sortedRowIds) => {
|
|
2475
|
+
* console.log(`Sorted Row Ids for dogColors result table changed`);
|
|
2476
|
+
* console.log(sortedRowIds);
|
|
2477
|
+
* // ^ cheaper than calling getResultSortedRowIds again
|
|
2517
2478
|
* },
|
|
2518
|
-
* true, // track reorder
|
|
2519
2479
|
* );
|
|
2520
2480
|
*
|
|
2521
2481
|
* store.setRow('pets', 'rex', {species: 'dog', color: 'tan'});
|
|
2522
|
-
* // -> 'Row Ids for dogColors result table changed'
|
|
2482
|
+
* // -> 'Sorted Row Ids for dogColors result table changed'
|
|
2523
2483
|
* // -> ['cujo', 'fido', 'rex']
|
|
2524
2484
|
*
|
|
2525
|
-
* store.setCell('pets', 'fido', 'color', 'walnut');
|
|
2526
|
-
* // -> 'Row Ids for dogColors result table changed'
|
|
2527
|
-
* // -> ['cujo', 'rex', 'fido']
|
|
2528
|
-
*
|
|
2529
2485
|
* store.delListener(listenerId);
|
|
2530
2486
|
* ```
|
|
2531
2487
|
* @example
|
|
2532
|
-
* This example registers a listener that responds to any change to the
|
|
2533
|
-
* Ids of
|
|
2488
|
+
* This example registers a listener that responds to any change to the sorted
|
|
2489
|
+
* Row Ids of a specific Table. The Row Ids are sorted by their own value,
|
|
2490
|
+
* since the `cellId` parameter is explicitly undefined.
|
|
2534
2491
|
*
|
|
2535
2492
|
* ```js
|
|
2536
2493
|
* const store = createStore().setTable('pets', {
|
|
@@ -2539,36 +2496,46 @@ export interface Queries {
|
|
|
2539
2496
|
* cujo: {species: 'dog', color: 'black'},
|
|
2540
2497
|
* });
|
|
2541
2498
|
*
|
|
2542
|
-
* const queries = createQueries(store)
|
|
2543
|
-
*
|
|
2499
|
+
* const queries = createQueries(store).setQueryDefinition(
|
|
2500
|
+
* 'dogColors',
|
|
2501
|
+
* 'pets',
|
|
2502
|
+
* ({select, where}) => {
|
|
2544
2503
|
* select('color');
|
|
2545
2504
|
* where('species', 'dog');
|
|
2546
|
-
* }
|
|
2547
|
-
*
|
|
2548
|
-
*
|
|
2549
|
-
*
|
|
2550
|
-
* });
|
|
2505
|
+
* },
|
|
2506
|
+
* );
|
|
2507
|
+
* console.log(queries.getResultSortedRowIds('dogColors', undefined));
|
|
2508
|
+
* // -> ['cujo', 'fido']
|
|
2551
2509
|
*
|
|
2552
|
-
* const listenerId = queries.
|
|
2553
|
-
*
|
|
2554
|
-
*
|
|
2555
|
-
*
|
|
2510
|
+
* const listenerId = queries.addResultSortedRowIdsListener(
|
|
2511
|
+
* 'dogColors',
|
|
2512
|
+
* undefined,
|
|
2513
|
+
* false,
|
|
2514
|
+
* 0,
|
|
2515
|
+
* undefined,
|
|
2516
|
+
* (queries, tableId, cellId, descending, offset, limit, sortedRowIds) => {
|
|
2517
|
+
* console.log(`Sorted Row Ids for dogColors result table changed`);
|
|
2518
|
+
* console.log(sortedRowIds);
|
|
2519
|
+
* // ^ cheaper than calling getSortedRowIds again
|
|
2556
2520
|
* },
|
|
2557
2521
|
* );
|
|
2558
2522
|
*
|
|
2559
2523
|
* store.setRow('pets', 'rex', {species: 'dog', color: 'tan'});
|
|
2560
|
-
* // -> 'Row Ids for dogColors result table changed'
|
|
2561
|
-
*
|
|
2562
|
-
* // -> 'Row Ids for catColors result table changed'
|
|
2524
|
+
* // -> 'Sorted Row Ids for dogColors result table changed'
|
|
2525
|
+
* // -> ['cujo', 'fido', 'rex']
|
|
2563
2526
|
*
|
|
2564
2527
|
* store.delListener(listenerId);
|
|
2565
2528
|
* ```
|
|
2566
2529
|
* @category Listener
|
|
2530
|
+
* @since v2.0.0
|
|
2567
2531
|
*/
|
|
2568
|
-
|
|
2569
|
-
queryId:
|
|
2570
|
-
|
|
2571
|
-
|
|
2532
|
+
addResultSortedRowIdsListener(
|
|
2533
|
+
queryId: Id,
|
|
2534
|
+
cellId: Id | undefined,
|
|
2535
|
+
descending: boolean,
|
|
2536
|
+
offset: number,
|
|
2537
|
+
limit: number | undefined,
|
|
2538
|
+
listener: ResultSortedRowIdsListener,
|
|
2572
2539
|
): Id;
|
|
2573
2540
|
|
|
2574
2541
|
/**
|
|
@@ -2667,6 +2634,7 @@ export interface Queries {
|
|
|
2667
2634
|
* store.delListener(listenerId);
|
|
2668
2635
|
* ```
|
|
2669
2636
|
* @category Listener
|
|
2637
|
+
* @since v2.0.0
|
|
2670
2638
|
*/
|
|
2671
2639
|
addResultRowListener(
|
|
2672
2640
|
queryId: IdOrNull,
|
|
@@ -2779,6 +2747,7 @@ export interface Queries {
|
|
|
2779
2747
|
* store.delListener(listenerId);
|
|
2780
2748
|
* ```
|
|
2781
2749
|
* @category Listener
|
|
2750
|
+
* @since v2.0.0
|
|
2782
2751
|
*/
|
|
2783
2752
|
addResultCellIdsListener(
|
|
2784
2753
|
queryId: IdOrNull,
|
|
@@ -2895,6 +2864,7 @@ export interface Queries {
|
|
|
2895
2864
|
* store.delListener(listenerId);
|
|
2896
2865
|
* ```
|
|
2897
2866
|
* @category Listener
|
|
2867
|
+
* @since v2.0.0
|
|
2898
2868
|
*/
|
|
2899
2869
|
addResultCellListener(
|
|
2900
2870
|
queryId: IdOrNull,
|
|
@@ -2945,7 +2915,7 @@ export interface Queries {
|
|
|
2945
2915
|
* // The listener is not called.
|
|
2946
2916
|
* ```
|
|
2947
2917
|
* @category Listener
|
|
2948
|
-
* @since v2.0.0
|
|
2918
|
+
* @since v2.0.0
|
|
2949
2919
|
*/
|
|
2950
2920
|
delListener(listenerId: Id): Queries;
|
|
2951
2921
|
|
|
@@ -2981,7 +2951,7 @@ export interface Queries {
|
|
|
2981
2951
|
* // -> 0
|
|
2982
2952
|
* ```
|
|
2983
2953
|
* @category Lifecycle
|
|
2984
|
-
* @since v2.0.0
|
|
2954
|
+
* @since v2.0.0
|
|
2985
2955
|
*/
|
|
2986
2956
|
destroy(): void;
|
|
2987
2957
|
|
|
@@ -3011,7 +2981,7 @@ export interface Queries {
|
|
|
3011
2981
|
* // -> 0
|
|
3012
2982
|
* ```
|
|
3013
2983
|
* @category Development
|
|
3014
|
-
* @since v2.0.0
|
|
2984
|
+
* @since v2.0.0
|
|
3015
2985
|
*/
|
|
3016
2986
|
getListenerStats(): QueriesListenerStats;
|
|
3017
2987
|
}
|
|
@@ -3049,6 +3019,6 @@ export interface Queries {
|
|
|
3049
3019
|
* // -> true
|
|
3050
3020
|
* ```
|
|
3051
3021
|
* @category Creation
|
|
3052
|
-
* @since v2.0.0
|
|
3022
|
+
* @since v2.0.0
|
|
3053
3023
|
*/
|
|
3054
3024
|
export function createQueries(store: Store): Queries;
|