tinybase 3.1.0-beta.3 → 3.1.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.
Files changed (99) hide show
  1. package/bin/cli.js +1 -1
  2. package/lib/cjs/tools.cjs +1 -1
  3. package/lib/cjs/tools.cjs.gz +0 -0
  4. package/lib/cjs-es6/tools.cjs +1 -1
  5. package/lib/cjs-es6/tools.cjs.gz +0 -0
  6. package/lib/debug/tools.js +14 -621
  7. package/lib/debug/ui-react.js +2 -2
  8. package/lib/es6/tools.js +1 -1
  9. package/lib/es6/tools.js.gz +0 -0
  10. package/lib/tools.js +1 -1
  11. package/lib/tools.js.gz +0 -0
  12. package/lib/{debug → types}/indexes.d.ts +1 -1
  13. package/lib/{debug → types}/metrics.d.ts +40 -41
  14. package/lib/{cjs-es6 → types}/queries.d.ts +466 -299
  15. package/lib/{debug → types}/relationships.d.ts +2 -2
  16. package/lib/{debug → types}/store.d.ts +115 -124
  17. package/lib/types/tinybase.d.ts +14 -0
  18. package/lib/{debug → types}/tools.d.ts +3 -174
  19. package/lib/{cjs-es6 → types}/ui-react.d.ts +11 -5
  20. package/lib/{cjs-es6 → types/with-schemas}/checkpoints.d.ts +20 -16
  21. package/lib/{cjs → types/with-schemas}/indexes.d.ts +44 -23
  22. package/lib/types/with-schemas/internal/queries.d.ts +15 -0
  23. package/lib/types/with-schemas/internal/store.d.ts +101 -0
  24. package/lib/types/with-schemas/internal/ui-react.d.ts +776 -0
  25. package/lib/{cjs → types/with-schemas}/metrics.d.ts +61 -55
  26. package/lib/{debug → types/with-schemas}/persisters.d.ts +31 -25
  27. package/lib/{debug → types/with-schemas}/queries.d.ts +615 -350
  28. package/lib/{cjs → types/with-schemas}/relationships.d.ts +42 -25
  29. package/lib/{cjs-es6 → types/with-schemas}/store.d.ts +758 -302
  30. package/lib/types/with-schemas/tinybase.d.ts +14 -0
  31. package/lib/{cjs-es6 → types/with-schemas}/tools.d.ts +11 -180
  32. package/lib/{cjs → types/with-schemas}/ui-react.d.ts +817 -1314
  33. package/lib/umd/tools.js +1 -1
  34. package/lib/umd/tools.js.gz +0 -0
  35. package/lib/umd-es6/tools.js +1 -1
  36. package/lib/umd-es6/tools.js.gz +0 -0
  37. package/package.json +149 -33
  38. package/readme.md +3 -3
  39. package/lib/cjs/checkpoints.d.ts +0 -959
  40. package/lib/cjs/persisters.d.ts +0 -727
  41. package/lib/cjs/queries.d.ts +0 -3024
  42. package/lib/cjs/store.d.ts +0 -5244
  43. package/lib/cjs/tinybase.d.ts +0 -14
  44. package/lib/cjs/tools.d.ts +0 -702
  45. package/lib/cjs-es6/indexes.d.ts +0 -966
  46. package/lib/cjs-es6/metrics.d.ts +0 -827
  47. package/lib/cjs-es6/relationships.d.ts +0 -1201
  48. package/lib/cjs-es6/tinybase.d.ts +0 -14
  49. package/lib/common.d.ts +0 -115
  50. package/lib/debug/checkpoints.d.ts +0 -959
  51. package/lib/debug/common.d.ts +0 -115
  52. package/lib/debug/tinybase.d.ts +0 -14
  53. package/lib/debug/ui-react.d.ts +0 -10921
  54. package/lib/es6/checkpoints.d.ts +0 -959
  55. package/lib/es6/common.d.ts +0 -115
  56. package/lib/es6/indexes.d.ts +0 -966
  57. package/lib/es6/metrics.d.ts +0 -827
  58. package/lib/es6/persisters.d.ts +0 -727
  59. package/lib/es6/queries.d.ts +0 -3024
  60. package/lib/es6/relationships.d.ts +0 -1201
  61. package/lib/es6/store.d.ts +0 -5244
  62. package/lib/es6/tinybase.d.ts +0 -14
  63. package/lib/es6/tools.d.ts +0 -702
  64. package/lib/es6/ui-react.d.ts +0 -10921
  65. package/lib/indexes.d.ts +0 -966
  66. package/lib/metrics.d.ts +0 -827
  67. package/lib/persisters.d.ts +0 -727
  68. package/lib/queries.d.ts +0 -3024
  69. package/lib/relationships.d.ts +0 -1201
  70. package/lib/store.d.ts +0 -5244
  71. package/lib/tinybase.d.ts +0 -14
  72. package/lib/tools.d.ts +0 -702
  73. package/lib/ui-react.d.ts +0 -10921
  74. package/lib/umd/checkpoints.d.ts +0 -959
  75. package/lib/umd/common.d.ts +0 -115
  76. package/lib/umd/indexes.d.ts +0 -966
  77. package/lib/umd/metrics.d.ts +0 -827
  78. package/lib/umd/persisters.d.ts +0 -727
  79. package/lib/umd/queries.d.ts +0 -3024
  80. package/lib/umd/relationships.d.ts +0 -1201
  81. package/lib/umd/store.d.ts +0 -5244
  82. package/lib/umd/tinybase.d.ts +0 -14
  83. package/lib/umd/tools.d.ts +0 -702
  84. package/lib/umd/ui-react.d.ts +0 -10921
  85. package/lib/umd-es6/checkpoints.d.ts +0 -959
  86. package/lib/umd-es6/common.d.ts +0 -115
  87. package/lib/umd-es6/indexes.d.ts +0 -966
  88. package/lib/umd-es6/metrics.d.ts +0 -827
  89. package/lib/umd-es6/persisters.d.ts +0 -727
  90. package/lib/umd-es6/queries.d.ts +0 -3024
  91. package/lib/umd-es6/relationships.d.ts +0 -1201
  92. package/lib/umd-es6/store.d.ts +0 -5244
  93. package/lib/umd-es6/tinybase.d.ts +0 -14
  94. package/lib/umd-es6/tools.d.ts +0 -702
  95. package/lib/umd-es6/ui-react.d.ts +0 -10921
  96. /package/lib/{checkpoints.d.ts → types/checkpoints.d.ts} +0 -0
  97. /package/lib/{cjs-es6 → types}/common.d.ts +0 -0
  98. /package/lib/{cjs-es6 → types}/persisters.d.ts +0 -0
  99. /package/lib/{cjs → types/with-schemas}/common.d.ts +0 -0
@@ -14,18 +14,79 @@
14
14
 
15
15
  import {
16
16
  Cell,
17
- CellCallback,
18
17
  CellOrUndefined,
19
18
  GetCell,
20
- GetCellChange,
21
- Row,
22
- RowCallback,
19
+ NoTablesSchema,
20
+ OptionalSchemas,
21
+ OptionalTablesSchema,
23
22
  Store,
24
- Table,
25
- TableCallback,
26
23
  } from './store.d';
24
+ import {CellIdFromSchema, TableIdFromSchema} from './internal/store';
25
+ import {GetResultCell, JoinedCellIdOrId} from './internal/queries';
27
26
  import {Id, IdOrNull, Ids} from './common.d';
28
27
 
28
+ /**
29
+ * The ResultTable type is the data structure representing the results of a
30
+ * query.
31
+ *
32
+ * A ResultTable is typically accessed with the getResultTable method or
33
+ * addResultTableListener method. It is similar to the Table type in the store
34
+ * module, but without schema-specific typing, and is a regular JavaScript
35
+ * object containing individual ResultRow objects, keyed by their Id.
36
+ *
37
+ * @example
38
+ * ```js
39
+ * const resultTable: ResultTable = {
40
+ * fido: {species: 'dog', color: 'brown'},
41
+ * felix: {species: 'cat'},
42
+ * };
43
+ * ```
44
+ * @category Result
45
+ */
46
+ export type ResultTable = {[rowId: Id]: ResultRow};
47
+
48
+ /**
49
+ * The ResultRow type is the data structure representing a single row in the
50
+ * results of a query.
51
+ *
52
+ * A ResultRow is typically accessed with the getResultRow method or
53
+ * addResultRowListener method. It is similar to the Row type in the store
54
+ * module, but without schema-specific typing, and is a regular JavaScript
55
+ * object containing individual ResultCell objects, keyed by their Id.
56
+ *
57
+ * @example
58
+ * ```js
59
+ * const resultRow: ResultRow = {species: 'dog', color: 'brown'};
60
+ * ```
61
+ * @category Result
62
+ */
63
+ export type ResultRow = {[cellId: Id]: ResultCell};
64
+
65
+ /**
66
+ * The ResultCell type is the data structure representing a single cell in the
67
+ * results of a query.
68
+ *
69
+ * A ResultCell is typically accessed with the getResultCell method or
70
+ * addResultCellListener method. It is similar to the Cell type in the store
71
+ * module, but without schema-specific typing, and is a JavaScript string,
72
+ * number, or boolean.
73
+ *
74
+ * @example
75
+ * ```js
76
+ * const resultCell: ResultCell = 'dog';
77
+ * ```
78
+ * @category Result
79
+ */
80
+ export type ResultCell = string | number | boolean;
81
+
82
+ /**
83
+ * The ResultCellOrUndefined type is the data structure representing a single
84
+ * cell in the results of a query, or the value `undefined`.
85
+ *
86
+ * @category Result
87
+ */
88
+ export type ResultCellOrUndefined = ResultCell | undefined;
89
+
29
90
  /**
30
91
  * The Aggregate type describes a custom function that takes an array of Cell
31
92
  * values and returns an aggregate of them.
@@ -40,7 +101,7 @@ import {Id, IdOrNull, Ids} from './common.d';
40
101
  * @category Aggregators
41
102
  * @since v2.0.0
42
103
  */
43
- export type Aggregate = (cells: Cell[], length: number) => Cell;
104
+ export type Aggregate = (cells: ResultCell[], length: number) => ResultCell;
44
105
 
45
106
  /**
46
107
  * The AggregateAdd type describes a function that can be used to optimize a
@@ -67,10 +128,10 @@ export type Aggregate = (cells: Cell[], length: number) => Cell;
67
128
  * @since v2.0.0
68
129
  */
69
130
  export type AggregateAdd = (
70
- current: Cell,
71
- add: Cell,
131
+ current: ResultCell,
132
+ add: ResultCell,
72
133
  length: number,
73
- ) => Cell | undefined;
134
+ ) => ResultCellOrUndefined;
74
135
 
75
136
  /**
76
137
  * The AggregateRemove type describes a function that can be used to optimize a
@@ -100,10 +161,10 @@ export type AggregateAdd = (
100
161
  * @since v2.0.0
101
162
  */
102
163
  export type AggregateRemove = (
103
- current: Cell,
104
- remove: Cell,
164
+ current: ResultCell,
165
+ remove: ResultCell,
105
166
  length: number,
106
- ) => Cell | undefined;
167
+ ) => ResultCellOrUndefined;
107
168
 
108
169
  /**
109
170
  * The AggregateReplace type describes a function that can be used to optimize a
@@ -132,11 +193,11 @@ export type AggregateRemove = (
132
193
  * @since v2.0.0
133
194
  */
134
195
  export type AggregateReplace = (
135
- current: Cell,
136
- add: Cell,
137
- remove: Cell,
196
+ current: ResultCell,
197
+ add: ResultCell,
198
+ remove: ResultCell,
138
199
  length: number,
139
- ) => Cell | undefined;
200
+ ) => ResultCellOrUndefined;
140
201
 
141
202
  /**
142
203
  * The QueryCallback type describes a function that takes a query's Id.
@@ -151,76 +212,133 @@ export type AggregateReplace = (
151
212
  */
152
213
  export type QueryCallback = (queryId: Id) => void;
153
214
 
215
+ /**
216
+ * The ResultTableCallback type describes a function that takes a ResultTable's
217
+ * Id and a callback to loop over each ResultRow within it.
218
+ *
219
+ * A ResultTableCallback is provided when using the forEachResultTable method,
220
+ * so that you can do something based on every ResultTable in the Queries
221
+ * object. See that method for specific examples.
222
+ *
223
+ * @param tableId The Id of the ResultTable that the callback can operate on.
224
+ * @param forEachRow A function that will let you iterate over the ResultRow
225
+ * objects in this ResultTable.
226
+ * @category Callback
227
+ */
228
+ export type ResultTableCallback = (
229
+ tableId: Id,
230
+ forEachRow: (rowCallback: ResultRowCallback) => void,
231
+ ) => void;
232
+
233
+ /**
234
+ * The ResultRowCallback type describes a function that takes a ResultRow's Id
235
+ * and a callback to loop over each ResultCell within it.
236
+ *
237
+ * A ResultRowCallback is provided when using the forEachResultRow method, so
238
+ * that you can do something based on every ResultRow in a ResultTable. See that
239
+ * method for specific examples.
240
+ *
241
+ * @param rowId The Id of the ResultRow that the callback can operate on.
242
+ * @param forEachRow A function that will let you iterate over the ResultCell
243
+ * values in this ResultRow.
244
+ * @category Callback
245
+ */
246
+ export type ResultRowCallback = (
247
+ rowId: Id,
248
+ forEachCell: (cellCallback: ResultCellCallback) => void,
249
+ ) => void;
250
+
251
+ /**
252
+ * The ResultCellCallback type describes a function that takes a ResultCell's Id
253
+ * and its value.
254
+ *
255
+ * A ResultCellCallback is provided when using the forEachResultCell method, so
256
+ * that you can do something based on every ResultCell in a ResultRow. See that
257
+ * method for specific examples.
258
+ *
259
+ * @param cellId The Id of the ResultCell that the callback can operate on.
260
+ * @param cell The value of the ResultCell.
261
+ * @category Callback
262
+ */
263
+ export type ResultCellCallback = (cellId: Id, cell: ResultCell) => void;
264
+
154
265
  /**
155
266
  * The ResultTableListener type describes a function that is used to listen to
156
- * changes to a query's result Table.
267
+ * changes to a query's ResultTable.
157
268
  *
158
269
  * A ResultTableListener is provided when using the addResultTableListener
159
270
  * method. See that method for specific examples.
160
271
  *
161
272
  * When called, a ResultTableListener is given a reference to the Queries
162
- * object, the Id of the Table that changed (which is the same as the query Id),
163
- * and a GetCellChange function that can be used to query Cell values before and
164
- * after the change.
273
+ * object, the Id of the ResultTable that changed (which is the same as the
274
+ * query Id), and a GetCellResultChange function that can be used to query
275
+ * ResultCell values before and after the change.
165
276
  *
166
277
  * @param queries A reference to the Queries object that changed.
167
- * @param tableId The Id of the Table that changed, which is also the query Id.
168
- * @param getCellChange A function that returns information about any Cell's
169
- * changes.
278
+ * @param tableId The Id of the ResultTable that changed, which is also the
279
+ * query Id.
280
+ * @param getCellChange A function that returns information about any
281
+ * ResultCell's changes.
170
282
  * @category Listener
171
283
  * @since v2.0.0
172
284
  */
173
- export type ResultTableListener = (
174
- queries: Queries,
285
+ export type ResultTableListener<Schemas extends OptionalSchemas> = (
286
+ queries: Queries<Schemas>,
175
287
  tableId: Id,
176
- getCellChange: GetCellChange | undefined,
288
+ getCellChange: GetCellResultChange,
177
289
  ) => void;
178
290
 
179
291
  /**
180
292
  * The ResultRowIdsListener type describes a function that is used to listen to
181
- * changes to the Row Ids in a query's result Table.
293
+ * changes to the ResultRow Ids in a query's ResultTable.
182
294
  *
183
295
  * A ResultRowIdsListener is provided when using the addResultRowIdsListener
184
296
  * method. See that method for specific examples.
185
297
  *
186
298
  * When called, a ResultRowIdsListener is given a reference to the Queries
187
- * object, and the Id of the Table whose Row Ids changed (which is the same as
188
- * the query Id).
299
+ * object, and the Id of the ResultTable whose ResultRow Ids changed (which is
300
+ * the same as the query Id).
189
301
  *
190
302
  * @param queries A reference to the Queries object that changed.
191
- * @param tableId The Id of the Table that changed, which is also the query Id.
303
+ * @param tableId The Id of the ResultTable that changed, which is also the
304
+ * query Id.
192
305
  * @category Listener
193
306
  * @since v2.0.0
194
307
  */
195
- export type ResultRowIdsListener = (queries: Queries, tableId: Id) => void;
308
+ export type ResultRowIdsListener<Schemas extends OptionalSchemas> = (
309
+ queries: Queries<Schemas>,
310
+ tableId: Id,
311
+ ) => void;
196
312
 
197
313
  /**
198
314
  * 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.
315
+ * listen to changes to the sorted ResultRow Ids in a query's ResultTable.
200
316
  *
201
317
  * A ResultSortedRowIdsListener is provided when using the
202
318
  * addResultSortedRowIdsListener method. See that method for specific examples.
203
319
  *
204
320
  * 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.
321
+ * object, the Id of the ResultTable whose ResultRow Ids changed (which is the
322
+ * same as the query Id), the ResultCell Id being used to sort them, whether
323
+ * descending or not, and the offset and limit of the number of Ids returned,
324
+ * for pagination purposes. It also receives the sorted array of Ids itself, so
325
+ * that you can use them in the listener without the additional cost of an
326
+ * explicit call to getResultSortedRowIds.
211
327
  *
212
328
  * @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.
329
+ * @param tableId The Id of the ResultTable that changed, which is also the
330
+ * query Id.
331
+ * @param cellId The Id of the ResultCell whose values were used for the
332
+ * sorting.
215
333
  * @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.
334
+ * @param offset The number of ResultRow Ids skipped.
335
+ * @param limit The maximum number of ResultRow Ids returned.
336
+ * @param sortedRowIds The sorted ResultRow Ids themselves.
219
337
  * @category Listener
220
338
  * @since v2.0.0
221
339
  */
222
- export type ResultSortedRowIdsListener = (
223
- queries: Queries,
340
+ export type ResultSortedRowIdsListener<Schemas extends OptionalSchemas> = (
341
+ queries: Queries<Schemas>,
224
342
  tableId: Id,
225
343
  cellId: Id | undefined,
226
344
  descending: boolean,
@@ -231,88 +349,131 @@ export type ResultSortedRowIdsListener = (
231
349
 
232
350
  /**
233
351
  * The ResultRowListener type describes a function that is used to listen to
234
- * changes to a Row in a query's result Table.
352
+ * changes to a ResultRow in a query's ResultTable.
235
353
  *
236
354
  * A ResultRowListener is provided when using the addResultRowListener method.
237
355
  * See that method for specific examples.
238
356
  *
239
357
  * When called, a ResultRowListener is given a reference to the Queries object,
240
- * the Id of the Table that changed (which is the same as the query Id), the Id
241
- * of the Row that changed, and a GetCellChange function that can be used to
242
- * query Cell values before and after the change.
358
+ * the Id of the ResultTable that changed (which is the same as the query Id),
359
+ * the Id of the ResultRow that changed, and a GetCellResultChange function that
360
+ * can be used to query ResultCell values before and after the change.
243
361
  *
244
362
  * @param queries A reference to the Queries object that changed.
245
- * @param tableId The Id of the Table that changed, which is also the query Id.
246
- * @param rowId The Id of the Row that changed.
247
- * @param getCellChange A function that returns information about any Cell's
248
- * changes.
363
+ * @param tableId The Id of the ResultTable that changed, which is also the
364
+ * query Id.
365
+ * @param rowId The Id of the ResultRow that changed.
366
+ * @param getCellChange A function that returns information about any
367
+ * ResultCell's changes.
249
368
  * @category Listener
250
369
  * @since v2.0.0
251
370
  */
252
- export type ResultRowListener = (
253
- queries: Queries,
371
+ export type ResultRowListener<Schemas extends OptionalSchemas> = (
372
+ queries: Queries<Schemas>,
254
373
  tableId: Id,
255
374
  rowId: Id,
256
- getCellChange: GetCellChange | undefined,
375
+ getCellChange: GetCellResultChange,
257
376
  ) => void;
258
377
 
259
378
  /**
260
379
  * The ResultCellIdsListener type describes a function that is used to listen to
261
- * changes to the Cell Ids in a Row in a query's result Table.
380
+ * changes to the ResultCell Ids in a ResultRow in a query's ResultTable.
262
381
  *
263
382
  * A ResultCellIdsListener is provided when using the addResultCellIdsListener
264
383
  * method. See that method for specific examples.
265
384
  *
266
385
  * When called, a ResultCellIdsListener is given a reference to the Queries
267
- * object, the Id of the Table that changed (which is the same as the query Id),
268
- * and the Id of the Row whose Cell Ids changed.
386
+ * object, the Id of the ResultTable that changed (which is the same as the
387
+ * query Id), and the Id of the ResultRow whose ResultCell Ids changed.
269
388
  *
270
389
  * @param queries A reference to the Queries object that changed.
271
- * @param tableId The Id of the Table that changed, which is also the query Id.
272
- * @param rowId The Id of the Row that changed.
390
+ * @param tableId The Id of the ResultTable that changed, which is also the
391
+ * query Id.
392
+ * @param rowId The Id of the ResultRow that changed.
273
393
  * @category Listener
274
394
  * @since v2.0.0
275
395
  */
276
- export type ResultCellIdsListener = (
277
- queries: Queries,
396
+ export type ResultCellIdsListener<Schemas extends OptionalSchemas> = (
397
+ queries: Queries<Schemas>,
278
398
  tableId: Id,
279
399
  rowId: Id,
280
400
  ) => void;
281
401
 
282
402
  /**
283
403
  * The ResultCellListener type describes a function that is used to listen to
284
- * changes to a Cell in a query's result Table.
404
+ * changes to a ResultCell in a query's ResultTable.
285
405
  *
286
406
  * A ResultCellListener is provided when using the addResultCellListener method.
287
407
  * See that method for specific examples.
288
408
  *
289
409
  * When called, a ResultCellListener is given a reference to the Queries object,
290
- * the Id of the Table that changed (which is the same as the query Id), the Id
291
- * of the Row that changed, and the Id of Cell that changed. It is also given
292
- * the new value of the Cell, the old value of the Cell, and a GetCellChange
293
- * function that can be used to query Cell values before and after the change.
410
+ * the Id of the ResultTable that changed (which is the same as the query Id),
411
+ * the Id of the ResultRow that changed, and the Id of ResultCell that changed.
412
+ * It is also given the new value of the ResultCell, the old value of the
413
+ * ResultCell, and a GetCellResultChange function that can be used to query
414
+ * ResultCell values before and after the change.
294
415
  *
295
416
  * @param queries A reference to the Queries object that changed.
296
- * @param tableId The Id of the Table that changed, which is also the query Id.
297
- * @param rowId The Id of the Row that changed.
298
- * @param cellId The Id of the Cell that changed.
299
- * @param newCell The new value of the Cell that changed.
300
- * @param oldCell The old value of the Cell that changed.
301
- * @param getCellChange A function that returns information about any Cell's
302
- * changes.
417
+ * @param tableId The Id of the ResultTable that changed, which is also the
418
+ * query Id.
419
+ * @param rowId The Id of the ResultRow that changed.
420
+ * @param cellId The Id of the ResultCell that changed.
421
+ * @param newCell The new value of the ResultCell that changed.
422
+ * @param oldCell The old value of the ResultCell that changed.
423
+ * @param getCellChange A function that returns information about any
424
+ * ResultCell's changes.
303
425
  * @category Listener
304
426
  * @since v2.0.0
305
427
  */
306
- export type ResultCellListener = (
307
- queries: Queries,
428
+ export type ResultCellListener<Schemas extends OptionalSchemas> = (
429
+ queries: Queries<Schemas>,
308
430
  tableId: Id,
309
431
  rowId: Id,
310
432
  cellId: Id,
311
- newCell: Cell,
312
- oldCell: Cell,
313
- getCellChange: GetCellChange | undefined,
433
+ newCell: ResultCell,
434
+ oldCell: ResultCell,
435
+ getCellChange: GetCellResultChange,
314
436
  ) => void;
315
437
 
438
+ /**
439
+ * The GetCellResultChange type describes a function that returns information
440
+ * about any ResultCell's changes during a transaction.
441
+ *
442
+ * A GetCellResultChange function is provided to every listener when called due
443
+ * the Store changing. The listener can then fetch the previous value of a
444
+ * ResultCell before the current transaction, the new value after it, and a
445
+ * convenience flag that indicates that the value has changed.
446
+ *
447
+ * @param tableId The Id of the ResultTable to inspect.
448
+ * @param rowId The Id of the ResultRow to inspect.
449
+ * @param cellId The Id of the ResultCell to inspect.
450
+ * @returns A ResultCellChange array containing information about the
451
+ * ResultCell's changes.
452
+ * @category Listener
453
+ */
454
+ export type GetCellResultChange = (
455
+ tableId: Id,
456
+ rowId: Id,
457
+ cellId: Id,
458
+ ) => ResultCellChange;
459
+
460
+ /**
461
+ * The ResultCellChange type describes a ResultCell's changes during a
462
+ * transaction.
463
+ *
464
+ * This is returned by the GetResultCellChange function that is provided to
465
+ * every listener when called. This array contains the previous value of a
466
+ * ResultCell before the current transaction, the new value after it, and a
467
+ * convenience flag that indicates that the value has changed.
468
+ *
469
+ * @category Listener
470
+ */
471
+ export type ResultCellChange = [
472
+ changed: boolean,
473
+ oldCell: ResultCellOrUndefined,
474
+ newCell: ResultCellOrUndefined,
475
+ ];
476
+
316
477
  /**
317
478
  * The QueriesListenerStats type describes the number of listeners registered
318
479
  * with the Queries object, and can be used for debugging purposes.
@@ -357,20 +518,25 @@ export type QueriesListenerStats = {
357
518
  * @category Callback
358
519
  * @since v2.0.0
359
520
  */
360
- export type GetTableCell = {
521
+ export type GetTableCell<
522
+ Schema extends OptionalTablesSchema,
523
+ RootTableId extends TableIdFromSchema<Schema>,
524
+ > = {
361
525
  /**
362
- * When called with one parameter, this function will return the value of the
363
- * specified Cell from the query's main Table for the Row being selected or
364
- * filtered.
526
+ * When called with one parameter, this function will return the value of
527
+ * the specified Cell from the query's root Table for the Row being selected
528
+ * or filtered.
365
529
  *
366
530
  * @param cellId The Id of the Cell to fetch the value for.
367
531
  * @returns A Cell value or `undefined`.
368
532
  */
369
- (cellId: Id): CellOrUndefined;
533
+ <RootCellId extends CellIdFromSchema<Schema, RootTableId>>(
534
+ cellId: RootCellId,
535
+ ): CellOrUndefined<Schema, RootTableId, RootCellId>;
370
536
  /**
371
- * When called with two parameters, this function will return the value of the
372
- * specified Cell from a Table that has been joined in the query, for the Row
373
- * being selected or filtered.
537
+ * When called with two parameters, this function will return the value of
538
+ * the specified Cell from a Table that has been joined in the query, for
539
+ * the Row being selected or filtered.
374
540
  *
375
541
  * @param joinedTableId The Id of the Table to fetch the value from. If the
376
542
  * underlying Table was joined 'as' a different Id, that should instead be
@@ -378,7 +544,20 @@ export type GetTableCell = {
378
544
  * @param joinedCellId The Id of the Cell to fetch the value for.
379
545
  * @returns A Cell value or `undefined`.
380
546
  */
381
- (joinedTableId: Id, joinedCellId: Id): CellOrUndefined;
547
+ <
548
+ JoinedTableId extends TableIdFromSchema<Schema> | Id,
549
+ JoinedCellId extends JoinedCellIdOrId<
550
+ Schema,
551
+ JoinedTableId
552
+ > = JoinedCellIdOrId<Schema, JoinedTableId>,
553
+ >(
554
+ joinedTableId: JoinedTableId,
555
+ joinedCellId: JoinedCellId,
556
+ ):
557
+ | (JoinedTableId extends TableIdFromSchema<Schema>
558
+ ? Cell<Schema, JoinedTableId, JoinedCellId>
559
+ : Cell<any, any, any>)
560
+ | undefined;
382
561
  };
383
562
 
384
563
  /**
@@ -478,16 +657,21 @@ export type GetTableCell = {
478
657
  * @category Definition
479
658
  * @since v2.0.0
480
659
  */
481
- export type Select = {
660
+ export type Select<
661
+ Schema extends OptionalTablesSchema,
662
+ RootTableId extends TableIdFromSchema<Schema>,
663
+ > = {
482
664
  /**
483
665
  * Calling this function with one Id parameter will indicate that the query
484
- * should select the value of the specified Cell from the query's main Table.
666
+ * should select the value of the specified Cell from the query's root Table.
485
667
  *
486
668
  * @param cellId The Id of the Cell to fetch the value for.
487
669
  * @returns A SelectedAs object so that the selected Cell Id can be optionally
488
670
  * aliased.
489
671
  */
490
- (cellId: Id): SelectedAs;
672
+ <RootCellId extends CellIdFromSchema<Schema, RootTableId>>(
673
+ cellId: RootCellId,
674
+ ): SelectedAs;
491
675
  /**
492
676
  * Calling this function with two parameters will indicate that the query
493
677
  * should select the value of the specified Cell from a Table that has been
@@ -500,11 +684,14 @@ export type Select = {
500
684
  * @returns A SelectedAs object so that the selected Cell Id can be optionally
501
685
  * aliased.
502
686
  */
503
- (joinedTableId: Id, joinedCellId: Id): SelectedAs;
687
+ <JoinedTableId extends TableIdFromSchema<Schema> | Id>(
688
+ joinedTableId: JoinedTableId,
689
+ joinedCellId: JoinedCellIdOrId<Schema, JoinedTableId>,
690
+ ): SelectedAs;
504
691
  /**
505
692
  * Calling this function with one callback parameter will indicate that the
506
693
  * query should select a calculated value, based on one or more Cell values in
507
- * the main Table or a joined Table, or on the main Table's Row Id.
694
+ * the root Table or a joined Table, or on the root Table's Row Id.
508
695
  *
509
696
  * @param getCell A callback that takes a GetTableCell function and the main
510
697
  * Table's Row Id. These can be used to programmatically create a calculated
@@ -513,9 +700,13 @@ export type Select = {
513
700
  * aliased.
514
701
  */
515
702
  (
516
- getCell: (getTableCell: GetTableCell, rowId: Id) => CellOrUndefined,
703
+ getCell: (
704
+ getTableCell: GetTableCell<Schema, RootTableId>,
705
+ rowId: Id,
706
+ ) => ResultCellOrUndefined,
517
707
  ): SelectedAs;
518
708
  };
709
+
519
710
  /**
520
711
  * The SelectedAs type describes an object returned from calling a Select
521
712
  * function so that the selected Cell Id can be optionally aliased.
@@ -586,11 +777,11 @@ export type SelectedAs = {
586
777
  * distant join Table.
587
778
  *
588
779
  * Because a Join clause is used to identify which unique Row Id of the joined
589
- * Table will be joined to each Row of the main Table, queries follow the 'left
780
+ * Table will be joined to each Row of the root Table, queries follow the 'left
590
781
  * join' semantics you may be familiar with from SQL. This means that an
591
782
  * unfiltered query will only ever return the same number of Rows as the main
592
783
  * Table being queried, and indeed the resulting table (assuming it has not been
593
- * aggregated) will even preserve the main Table's original Row Ids.
784
+ * aggregated) will even preserve the root Table's original Row Ids.
594
785
  *
595
786
  * @example
596
787
  * This example shows a query that joins a single Table by using an Id present
@@ -628,7 +819,7 @@ export type SelectedAs = {
628
819
  * This example shows a query that joins the same underlying Table twice, and
629
820
  * aliases them (and the selected Cell Ids). Note the left-join semantics: Felix
630
821
  * the cat was bought, but the seller was unknown. The record still exists in
631
- * the result Table.
822
+ * the ResultTable.
632
823
  *
633
824
  * ```js
634
825
  * const store = createStore()
@@ -661,7 +852,7 @@ export type SelectedAs = {
661
852
  * ```
662
853
  * @example
663
854
  * This example shows a query that calculates the Id of the joined Table based
664
- * from multiple values in the main Table rather than a single Cell.
855
+ * from multiple values in the root Table rather than a single Cell.
665
856
  *
666
857
  * ```js
667
858
  * const store = createStore()
@@ -736,34 +927,40 @@ export type SelectedAs = {
736
927
  * @category Definition
737
928
  * @since v2.0.0
738
929
  */
739
- export type Join = {
930
+ export type Join<
931
+ Schema extends OptionalTablesSchema,
932
+ RootTableId extends TableIdFromSchema<Schema>,
933
+ > = {
740
934
  /**
741
935
  * Calling this function with two Id parameters will indicate that the join to
742
936
  * a Row in an adjacent Table is made by finding its Id in a Cell of the
743
- * query's main Table.
937
+ * query's root Table.
744
938
  *
745
939
  * @param joinedTableId The Id of the Table to join to.
746
- * @param on The Id of the Cell in the main Table that contains the joined
940
+ * @param on The Id of the Cell in the root Table that contains the joined
747
941
  * Table's Row Id.
748
942
  * @returns A JoinedAs object so that the joined Table Id can be optionally
749
943
  * aliased.
750
944
  */
751
- (joinedTableId: Id, on: Id): JoinedAs;
945
+ (
946
+ joinedTableId: TableIdFromSchema<Schema>,
947
+ on: CellIdFromSchema<Schema, RootTableId>,
948
+ ): JoinedAs;
752
949
  /**
753
950
  * Calling this function with two parameters (where the second is a function)
754
951
  * will indicate that the join to a Row in an adjacent Table is made by
755
- * calculating its Id from the Cells and the Row Id of the query's main Table.
952
+ * calculating its Id from the Cells and the Row Id of the query's root Table.
756
953
  *
757
954
  * @param joinedTableId The Id of the Table to join to.
758
- * @param on A callback that takes a GetCell function and the main Table's Row
955
+ * @param on A callback that takes a GetCell function and the root Table's Row
759
956
  * Id. These can be used to programmatically calculate the joined Table's Row
760
957
  * Id.
761
958
  * @returns A JoinedAs object so that the joined Table Id can be optionally
762
959
  * aliased.
763
960
  */
764
961
  (
765
- joinedTableId: Id,
766
- on: (getCell: GetCell, rowId: Id) => Id | undefined,
962
+ joinedTableId: TableIdFromSchema<Schema>,
963
+ on: (getCell: GetCell<Schema, RootTableId>, rowId: Id) => Id | undefined,
767
964
  ): JoinedAs;
768
965
  /**
769
966
  * Calling this function with three Id parameters will indicate that the join
@@ -779,7 +976,19 @@ export type Join = {
779
976
  * @returns A JoinedAs object so that the joined Table Id can be optionally
780
977
  * aliased.
781
978
  */
782
- (joinedTableId: Id, fromIntermediateJoinedTableId: Id, on: Id): JoinedAs;
979
+ <
980
+ IntermediateJoinedTableId extends TableIdFromSchema<Schema> | Id =
981
+ | TableIdFromSchema<Schema>
982
+ | Id,
983
+ IntermediateJoinedCellId extends JoinedCellIdOrId<
984
+ Schema,
985
+ IntermediateJoinedTableId
986
+ > = JoinedCellIdOrId<Schema, IntermediateJoinedTableId>,
987
+ >(
988
+ joinedTableId: TableIdFromSchema<Schema>,
989
+ fromIntermediateJoinedTableId: IntermediateJoinedTableId,
990
+ on: IntermediateJoinedCellId,
991
+ ): JoinedAs;
783
992
  /**
784
993
  * Calling this function with three parameters (where the third is a function)
785
994
  * will indicate that the join to a Row in distant Table is made by
@@ -796,15 +1005,24 @@ export type Join = {
796
1005
  * @returns A JoinedAs object so that the joined Table Id can be optionally
797
1006
  * aliased.
798
1007
  */
799
- (
800
- joinedTableId: Id,
801
- fromIntermediateJoinedTableId: Id,
1008
+ <
1009
+ IntermediateJoinedTableId extends TableIdFromSchema<Schema> | Id =
1010
+ | TableIdFromSchema<Schema>
1011
+ | Id,
1012
+ >(
1013
+ joinedTableId: TableIdFromSchema<Schema>,
1014
+ fromIntermediateJoinedTableId: IntermediateJoinedTableId,
802
1015
  on: (
803
- getIntermediateJoinedCell: GetCell,
804
- intermediateJoinedTableRowId: Id,
1016
+ // prettier-ignore
1017
+ getIntermediateJoinedCell:
1018
+ IntermediateJoinedTableId extends TableIdFromSchema<Schema>
1019
+ ? GetCell<Schema, IntermediateJoinedTableId>
1020
+ : GetCell<NoTablesSchema, Id>,
1021
+ intermediateJoinedRowId: Id,
805
1022
  ) => Id | undefined,
806
1023
  ): JoinedAs;
807
1024
  };
1025
+
808
1026
  /**
809
1027
  * The JoinedAs type describes an object returned from calling a Join function
810
1028
  * so that the joined Table Id can be optionally aliased.
@@ -813,6 +1031,9 @@ export type Join = {
813
1031
  * create two joins to the same underlying Table, both _without_ aliases), only
814
1032
  * the latter of two will be used in the query.
815
1033
  *
1034
+ * For the purposes of clarity, it's recommended to use an alias that does not
1035
+ * collide with a real underlying Table (whether included in the query or not).
1036
+ *
816
1037
  * @example
817
1038
  * This example shows a query that joins the same underlying Table twice, for
818
1039
  * different purposes. Both joins are aliased with the 'as' function to
@@ -850,17 +1071,22 @@ export type Join = {
850
1071
  * @category Definition
851
1072
  * @since v2.0.0
852
1073
  */
853
- export type JoinedAs = {as: (joinedTableId: Id) => void};
1074
+ export type JoinedAs = {
1075
+ /**
1076
+ * A function that lets you specify an alias for the joined Table Id.
1077
+ */
1078
+ as: (joinedTableId: Id) => void;
1079
+ };
854
1080
 
855
1081
  /**
856
1082
  * The Where type describes a function that lets you specify conditions to
857
- * filter results, based on the underlying Cells of the main or joined Tables.
1083
+ * filter results, based on the underlying Cells of the root or joined Tables.
858
1084
  *
859
1085
  * The Where function is provided to the third `query` parameter of the
860
1086
  * setQueryDefinition method.
861
1087
  *
862
1088
  * If you do not specify a Where clause, you should expect every non-empty Row
863
- * of the main Table to appear in the query's results.
1089
+ * of the root Table to appear in the query's results.
864
1090
  *
865
1091
  * A Where condition has to be true for a Row to be included in the results.
866
1092
  * Each Where class is additive, as though combined with a logical 'and'. If you
@@ -968,17 +1194,23 @@ export type JoinedAs = {as: (joinedTableId: Id) => void};
968
1194
  * @category Definition
969
1195
  * @since v2.0.0
970
1196
  */
971
- export type Where = {
1197
+ export type Where<
1198
+ Schema extends OptionalTablesSchema,
1199
+ RootTableId extends TableIdFromSchema<Schema>,
1200
+ > = {
972
1201
  /**
973
1202
  * Calling this function with two parameters is used to include only those
974
- * Rows for which a specified Cell in the query's main Table has a specified
1203
+ * Rows for which a specified Cell in the query's root Table has a specified
975
1204
  * value.
976
1205
  *
977
- * @param cellId The Id of the Cell in the query's main Table to test.
1206
+ * @param cellId The Id of the Cell in the query's root Table to test.
978
1207
  * @param equals The value that the Cell has to have for the Row to be
979
1208
  * included in the result.
980
1209
  */
981
- (cellId: Id, equals: Cell): void;
1210
+ <RootCellId extends CellIdFromSchema<Schema, RootTableId>>(
1211
+ cellId: RootCellId,
1212
+ equals: Cell<Schema, RootTableId, RootCellId>,
1213
+ ): void;
982
1214
  /**
983
1215
  * Calling this function with three parameters is used to include only those
984
1216
  * Rows for which a specified Cell in a joined Table has a specified value.
@@ -990,7 +1222,22 @@ export type Where = {
990
1222
  * @param equals The value that the Cell has to have for the Row to be
991
1223
  * included in the result.
992
1224
  */
993
- (joinedTableId: Id, joinedCellId: Id, equals: Cell): void;
1225
+ <
1226
+ JoinedTableId extends TableIdFromSchema<Schema> | Id,
1227
+ JoinedCellId extends JoinedCellIdOrId<
1228
+ Schema,
1229
+ JoinedTableId
1230
+ > = JoinedCellIdOrId<Schema, JoinedTableId>,
1231
+ JoinedCell extends Cell<Schema, JoinedTableId, JoinedCellId> = Cell<
1232
+ Schema,
1233
+ JoinedTableId,
1234
+ JoinedCellId
1235
+ >,
1236
+ >(
1237
+ joinedTableId: JoinedTableId,
1238
+ joinedCellId: JoinedCellId,
1239
+ equals: JoinedCell,
1240
+ ): void;
994
1241
  /**
995
1242
  * Calling this function with one callback parameter is used to include only
996
1243
  * those Rows which meet a calculated boolean condition, based on values in
@@ -999,12 +1246,14 @@ export type Where = {
999
1246
  * @param condition A callback that takes a GetTableCell function and that
1000
1247
  * should return `true` for the Row to be included in the result.
1001
1248
  */
1002
- (condition: (getTableCell: GetTableCell) => boolean): void;
1249
+ (
1250
+ condition: (getTableCell: GetTableCell<Schema, RootTableId>) => boolean,
1251
+ ): void;
1003
1252
  };
1004
1253
 
1005
1254
  /**
1006
1255
  * The Group type describes a function that lets you specify that the values of
1007
- * a Cell in multiple result Rows should be aggregated together.
1256
+ * a Cell in multiple ResultRows should be aggregated together.
1008
1257
  *
1009
1258
  * The Group function is provided to the third `query` parameter of the
1010
1259
  * setQueryDefinition method. When called, it should refer to a Cell Id (or
@@ -1044,7 +1293,7 @@ export type Where = {
1044
1293
  * input values - for example, when a Row is added to the Table.
1045
1294
  * @param aggregateRemove A function that can be used to optimize a custom
1046
1295
  * Aggregate by providing a shortcut for when a single value is removed from the
1047
- * input values - for example ,when a Row is removed from the Table.
1296
+ * input values - for example, when a Row is removed from the Table.
1048
1297
  * @param aggregateReplace A function that can be used to optimize a custom
1049
1298
  * Aggregate by providing a shortcut for when a single value in the input values
1050
1299
  * is replaced with another - for example, when a Row is updated.
@@ -1181,6 +1430,7 @@ export type Group = (
1181
1430
  aggregateRemove?: AggregateRemove,
1182
1431
  aggregateReplace?: AggregateReplace,
1183
1432
  ) => GroupedAs;
1433
+
1184
1434
  /**
1185
1435
  * The GroupedAs type describes an object returned from calling a Group function
1186
1436
  * so that the grouped Cell Id can be optionally aliased.
@@ -1219,7 +1469,12 @@ export type Group = (
1219
1469
  * @category Definition
1220
1470
  * @since v2.0.0
1221
1471
  */
1222
- export type GroupedAs = {as: (groupedCellId: Id) => void};
1472
+ export type GroupedAs = {
1473
+ /**
1474
+ * A function that lets you specify an alias for the grouped Cell Id.
1475
+ */
1476
+ as: (groupedCellId: Id) => void;
1477
+ };
1223
1478
 
1224
1479
  /**
1225
1480
  * The Having type describes a function that lets you specify conditions to
@@ -1312,14 +1567,14 @@ export type GroupedAs = {as: (groupedCellId: Id) => void};
1312
1567
  export type Having = {
1313
1568
  /**
1314
1569
  * Calling this function with two parameters is used to include only those
1315
- * Rows for which a specified Cell in the query's main Table has a specified
1570
+ * Rows for which a specified Cell in the query's root Table has a specified
1316
1571
  * value.
1317
1572
  *
1318
1573
  * @param selectedOrGroupedCellId The Id of the Cell in the query to test.
1319
1574
  * @param equals The value that the Cell has to have for the Row to be
1320
1575
  * included in the result.
1321
1576
  */
1322
- (selectedOrGroupedCellId: Id, equals: Cell): void;
1577
+ (selectedOrGroupedCellId: Id, equals: ResultCell): void;
1323
1578
  /**
1324
1579
  * Calling this function with one callback parameter is used to include only
1325
1580
  * those Rows which meet a calculated boolean condition.
@@ -1327,7 +1582,7 @@ export type Having = {
1327
1582
  * @param condition A callback that takes a GetCell function and that should
1328
1583
  * return `true` for the Row to be included in the result.
1329
1584
  */
1330
- (condition: (getSelectedOrGroupedCell: GetCell) => boolean): void;
1585
+ (condition: (getSelectedOrGroupedCell: GetResultCell) => boolean): void;
1331
1586
  };
1332
1587
 
1333
1588
  /**
@@ -1427,16 +1682,16 @@ export type Having = {
1427
1682
  * @category Queries
1428
1683
  * @since v2.0.0
1429
1684
  */
1430
- export interface Queries {
1685
+ export interface Queries<in out Schemas extends OptionalSchemas> {
1431
1686
  /**
1432
1687
  * The setQueryDefinition method lets you set the definition of a query.
1433
1688
  *
1434
1689
  * Every query definition is identified by a unique Id, and if you re-use an
1435
1690
  * existing Id with this method, the previous definition is overwritten.
1436
1691
  *
1437
- * A query provides a tabular result formed from each Row within a main Table.
1438
- * The definition must specify this 'main' Table (by its Id) to be aggregated.
1439
- * Other Tables can be joined to that using Join clauses.
1692
+ * A query provides a tabular result formed from each Row within a root Table.
1693
+ * The definition must specify this Table (by its Id) to be aggregated. Other
1694
+ * Tables can be joined to that using Join clauses.
1440
1695
  *
1441
1696
  * The third `query` parameter is a callback that you provide to define the
1442
1697
  * query. That callback is provided with a `keywords` object that contains the
@@ -1452,7 +1707,7 @@ export interface Queries {
1452
1707
  * filter results, based on the underlying Cells of the main or joined
1453
1708
  * Tables.
1454
1709
  * - The Group type describes a function that lets you specify that the values
1455
- * of a Cell in multiple result Rows should be aggregated together.
1710
+ * of a Cell in multiple ResultRows should be aggregated together.
1456
1711
  * - The Having type describes a function that lets you specify conditions to
1457
1712
  * filter results, based on the grouped Cells resulting from a Group clause.
1458
1713
  *
@@ -1463,7 +1718,7 @@ export interface Queries {
1463
1718
  * addResultSortedRowIdsListener method to sort and paginate the results.
1464
1719
  *
1465
1720
  * @param queryId The Id of the query to define.
1466
- * @param tableId The Id of the main Table the query will be based on.
1721
+ * @param tableId The Id of the root Table the query will be based on.
1467
1722
  * @param query A callback which can take a `keywords` object and which uses
1468
1723
  the functions it contains to define the query.
1469
1724
  * @returns A reference to the Queries object.
@@ -1491,17 +1746,17 @@ export interface Queries {
1491
1746
  * @category Configuration
1492
1747
  * @since v2.0.0
1493
1748
  */
1494
- setQueryDefinition(
1749
+ setQueryDefinition<RootTableId extends TableIdFromSchema<Schemas[0]>>(
1495
1750
  queryId: Id,
1496
- tableId: Id,
1751
+ tableId: RootTableId,
1497
1752
  query: (keywords: {
1498
- select: Select;
1499
- join: Join;
1500
- where: Where;
1753
+ select: Select<Schemas[0], RootTableId>;
1754
+ join: Join<Schemas[0], RootTableId>;
1755
+ where: Where<Schemas[0], RootTableId>;
1501
1756
  group: Group;
1502
1757
  having: Having;
1503
1758
  }) => void,
1504
- ): Queries;
1759
+ ): Queries<Schemas>;
1505
1760
 
1506
1761
  /**
1507
1762
  * The delQueryDefinition method removes an existing query definition.
@@ -1534,7 +1789,7 @@ export interface Queries {
1534
1789
  * @category Configuration
1535
1790
  * @since v2.0.0
1536
1791
  */
1537
- delQueryDefinition(queryId: Id): Queries;
1792
+ delQueryDefinition(queryId: Id): Queries<Schemas>;
1538
1793
 
1539
1794
  /**
1540
1795
  * The getStore method returns a reference to the underlying Store that is
@@ -1560,7 +1815,7 @@ export interface Queries {
1560
1815
  * @category Getter
1561
1816
  * @since v2.0.0
1562
1817
  */
1563
- getStore(): Store;
1818
+ getStore(): Store<Schemas>;
1564
1819
 
1565
1820
  /**
1566
1821
  * The getQueryIds method returns an array of the query Ids registered with
@@ -1684,11 +1939,13 @@ export interface Queries {
1684
1939
  * @category Getter
1685
1940
  * @since v2.0.0
1686
1941
  */
1687
- getTableId(queryId: Id): Id | undefined;
1942
+ getTableId<TableId extends TableIdFromSchema<Schemas[0]>>(
1943
+ queryId: Id,
1944
+ ): TableId | undefined;
1688
1945
 
1689
1946
  /**
1690
1947
  * The getResultTable method returns an object containing the entire data of
1691
- * the result Table of the given query.
1948
+ * the ResultTable of the given query.
1692
1949
  *
1693
1950
  * This has the same behavior as a Store's getTable method. For example, if
1694
1951
  * the query Id is invalid, the method returns an empty object. Similarly, it
@@ -1697,13 +1954,13 @@ export interface Queries {
1697
1954
  * themselves.
1698
1955
  *
1699
1956
  * @param queryId The Id of a query.
1700
- * @returns An object containing the entire data of the result Table of the
1957
+ * @returns An object containing the entire data of the ResultTable of the
1701
1958
  * query.
1702
- * @returns The result of the query, structured as a Table.
1959
+ * @returns The result of the query, structured as a ResultTable.
1703
1960
  * @example
1704
1961
  * This example creates a Queries object, a single query definition, and then
1705
1962
  * calls this method on it (as well as a non-existent definition) to get the
1706
- * result Table.
1963
+ * ResultTable.
1707
1964
  *
1708
1965
  * ```js
1709
1966
  * const store = createStore().setTable('pets', {
@@ -1730,11 +1987,11 @@ export interface Queries {
1730
1987
  * @category Result
1731
1988
  * @since v2.0.0
1732
1989
  */
1733
- getResultTable(queryId: Id): Table;
1990
+ getResultTable(queryId: Id): ResultTable;
1734
1991
 
1735
1992
  /**
1736
- * The getResultRowIds method returns the Ids of every Row in the result Table
1737
- * of the given query.
1993
+ * The getResultRowIds method returns the Ids of every ResultRow in the
1994
+ * ResultTable of the given query.
1738
1995
  *
1739
1996
  * This has the same behavior as a Store's getRowIds method. For example, if
1740
1997
  * the query Id is invalid, the method returns an empty array. Similarly, it
@@ -1742,11 +1999,11 @@ export interface Queries {
1742
1999
  * made to the list object are not made to the query results themselves.
1743
2000
  *
1744
2001
  * @param queryId The Id of a query.
1745
- * @returns An array of the Ids of every Row in the result of the query.
2002
+ * @returns An array of the Ids of every ResultRow in the result of the query.
1746
2003
  * @example
1747
2004
  * This example creates a Queries object, a single query definition, and then
1748
2005
  * calls this method on it (as well as a non-existent definition) to get the
1749
- * result Row Ids.
2006
+ * ResultRow Ids.
1750
2007
  *
1751
2008
  * ```js
1752
2009
  * const store = createStore().setTable('pets', {
@@ -1776,37 +2033,37 @@ export interface Queries {
1776
2033
  getResultRowIds(queryId: Id): Ids;
1777
2034
 
1778
2035
  /**
1779
- * The getResultSortedRowIds method returns the Ids of every Row in the result
1780
- * Table of the given query, sorted according to the values in a specified
1781
- * Cell.
2036
+ * The getResultSortedRowIds method returns the Ids of every ResultRow in the
2037
+ * ResultTable of the given query, sorted according to the values in a
2038
+ * specified ResultCell.
1782
2039
  *
1783
2040
  * This has the same behavior as a Store's getSortedRowIds method. For
1784
2041
  * example, if the query Id is invalid, the method returns an empty array.
1785
2042
  * Similarly, the sorting of the rows is alphanumeric, and you can indicate
1786
2043
  * whether it should be in descending order. The `offset` and `limit`
1787
2044
  * parameters are used to paginate results, but default to `0` and `undefined`
1788
- * to return all available Row Ids if not specified.
2045
+ * to return all available ResultRow Ids if not specified.
1789
2046
  *
1790
2047
  * Note that every call to this method will perform the sorting afresh - there
1791
2048
  * is no caching of the results - and so you are advised to memoize the
1792
- * results yourself, especially when the result Table is large. For a
1793
- * performant approach to tracking the sorted Row Ids when they change, use
1794
- * the addResultSortedRowIdsListener method.
2049
+ * results yourself, especially when the ResultTable is large. For a
2050
+ * performant approach to tracking the sorted ResultRow Ids when they change,
2051
+ * use the addResultSortedRowIdsListener method.
1795
2052
  *
1796
2053
  * @param queryId The Id of a query.
1797
- * @param cellId The Id of the Cell whose values are used for the sorting, or
1798
- * `undefined` to by sort the Row Id itself.
2054
+ * @param cellId The Id of the ResultCell whose values are used for the
2055
+ * sorting, or `undefined` to by sort the ResultRow Id itself.
1799
2056
  * @param descending Whether the sorting should be in descending order.
1800
- * @param offset The number of Row Ids to skip for pagination purposes, if
1801
- * any.
1802
- * @param limit The maximum number of Row Ids to return, or `undefined` for
1803
- * all.
1804
- * @returns An array of the sorted Ids of every Row in the result of the
2057
+ * @param offset The number of ResultRow Ids to skip for pagination purposes,
2058
+ * if any.
2059
+ * @param limit The maximum number of ResultRow Ids to return, or `undefined`
2060
+ * for all.
2061
+ * @returns An array of the sorted Ids of every ResultRow in the result of the
1805
2062
  * query.
1806
2063
  * @example
1807
2064
  * This example creates a Queries object, a single query definition, and then
1808
2065
  * calls this method on it (as well as a non-existent definition) to get the
1809
- * result Row Ids.
2066
+ * ResultRow Ids.
1810
2067
  *
1811
2068
  * ```js
1812
2069
  * const store = createStore().setTable('pets', {
@@ -1843,22 +2100,22 @@ export interface Queries {
1843
2100
 
1844
2101
  /**
1845
2102
  * The getResultRow method returns an object containing the entire data of a
1846
- * single Row in the result Table of the given query.
2103
+ * single ResultRow in the ResultTable of the given query.
1847
2104
  *
1848
2105
  * This has the same behavior as a Store's getRow method. For example, if the
1849
- * query or Row Id is invalid, the method returns an empty object. Similarly,
1850
- * it returns a copy of, rather than a reference to the underlying data, so
1851
- * changes made to the returned object are not made to the query results
1852
- * themselves.
2106
+ * query or ResultRow Id is invalid, the method returns an empty object.
2107
+ * Similarly, it returns a copy of, rather than a reference to the underlying
2108
+ * data, so changes made to the returned object are not made to the query
2109
+ * results themselves.
1853
2110
  *
1854
2111
  * @param queryId The Id of a query.
1855
- * @param rowId The Id of the Row in the result Table.
1856
- * @returns An object containing the entire data of the Row in the result
1857
- * Table of the query.
2112
+ * @param rowId The Id of the ResultRow in the ResultTable.
2113
+ * @returns An object containing the entire data of the ResultRow in the
2114
+ * ResultTable of the query.
1858
2115
  * @example
1859
2116
  * This example creates a Queries object, a single query definition, and then
1860
- * calls this method on it (as well as a non-existent Row Id) to get the
1861
- * result Row.
2117
+ * calls this method on it (as well as a non-existent ResultRow Id) to get
2118
+ * the ResultRow.
1862
2119
  *
1863
2120
  * ```js
1864
2121
  * const store = createStore().setTable('pets', {
@@ -1885,26 +2142,26 @@ export interface Queries {
1885
2142
  * @category Result
1886
2143
  * @since v2.0.0
1887
2144
  */
1888
- getResultRow(queryId: Id, rowId: Id): Row;
2145
+ getResultRow(queryId: Id, rowId: Id): ResultRow;
1889
2146
 
1890
2147
  /**
1891
- * The getResultCellIds method returns the Ids of every Cell in a given Row,
1892
- * in the result Table of the given query.
2148
+ * The getResultCellIds method returns the Ids of every ResultCell in a given
2149
+ * ResultRow, in the ResultTable of the given query.
1893
2150
  *
1894
2151
  * This has the same behavior as a Store's getCellIds method. For example, if
1895
- * the query Id or Row Id is invalid, the method returns an empty array.
2152
+ * the query Id or ResultRow Id is invalid, the method returns an empty array.
1896
2153
  * Similarly, it returns a copy of, rather than a reference to the list of
1897
2154
  * Ids, so changes made to the list object are not made to the query results
1898
2155
  * themselves.
1899
2156
  *
1900
2157
  * @param queryId The Id of a query.
1901
- * @param rowId The Id of the Row in the result Table.
1902
- * @returns An array of the Ids of every Cell in the Row in the result of the
1903
- * query.
2158
+ * @param rowId The Id of the ResultRow in the ResultTable.
2159
+ * @returns An array of the Ids of every ResultCell in the ResultRow in the
2160
+ * result of the query.
1904
2161
  * @example
1905
2162
  * This example creates a Queries object, a single query definition, and then
1906
- * calls this method on it (as well as a non-existent Row Id) to get the
1907
- * result Cell Ids.
2163
+ * calls this method on it (as well as a non-existent ResultRow Id) to get the
2164
+ * ResultCell Ids.
1908
2165
  *
1909
2166
  * ```js
1910
2167
  * const store = createStore().setTable('pets', {
@@ -1934,20 +2191,21 @@ export interface Queries {
1934
2191
  getResultCellIds(queryId: Id, rowId: Id): Ids;
1935
2192
 
1936
2193
  /**
1937
- * The getResultCell method returns the value of a single Cell in a given Row,
1938
- * in the result Table of the given query.
2194
+ * The getResultCell method returns the value of a single ResultCell in a
2195
+ * given ResultRow, in the ResultTable of the given query.
1939
2196
  *
1940
2197
  * This has the same behavior as a Store's getCell method. For example, if the
1941
- * query, or Row, or Cell Id is invalid, the method returns `undefined`.
2198
+ * query, or ResultRow, or ResultCell Id is invalid, the method returns
2199
+ * `undefined`.
1942
2200
  *
1943
2201
  * @param queryId The Id of a query.
1944
- * @param rowId The Id of the Row in the result Table.
1945
- * @param cellId The Id of the Cell in the Row.
1946
- * @returns The value of the Cell, or `undefined`.
2202
+ * @param rowId The Id of the ResultRow in the ResultTable.
2203
+ * @param cellId The Id of the ResultCell in the ResultRow.
2204
+ * @returns The value of the ResultCell, or `undefined`.
1947
2205
  * @example
1948
2206
  * This example creates a Queries object, a single query definition, and then
1949
- * calls this method on it (as well as a non-existent Cell Id) to get the
1950
- * result Cell.
2207
+ * calls this method on it (as well as a non-existent ResultCell Id) to get
2208
+ * the ResultCell.
1951
2209
  *
1952
2210
  * ```js
1953
2211
  * const store = createStore().setTable('pets', {
@@ -1974,16 +2232,16 @@ export interface Queries {
1974
2232
  * @category Result
1975
2233
  * @since v2.0.0
1976
2234
  */
1977
- getResultCell(queryId: Id, rowId: Id, cellId: Id): CellOrUndefined;
2235
+ getResultCell(queryId: Id, rowId: Id, cellId: Id): ResultCellOrUndefined;
1978
2236
 
1979
2237
  /**
1980
2238
  * The hasResultTable method returns a boolean indicating whether a given
1981
- * result Table exists.
2239
+ * ResultTable exists.
1982
2240
  *
1983
2241
  * @param queryId The Id of a possible query.
1984
- * @returns Whether a result Table for that query Id exists.
2242
+ * @returns Whether a ResultTable for that query Id exists.
1985
2243
  * @example
1986
- * This example shows two simple result Table existence checks.
2244
+ * This example shows two simple ResultTable existence checks.
1987
2245
  *
1988
2246
  * ```js
1989
2247
  * const store = createStore().setTable('pets', {
@@ -2012,14 +2270,14 @@ export interface Queries {
2012
2270
  hasResultTable(queryId: Id): boolean;
2013
2271
 
2014
2272
  /**
2015
- * The hasResultRow method returns a boolean indicating whether a given result
2016
- * Row exists.
2273
+ * The hasResultRow method returns a boolean indicating whether a given
2274
+ * ResultRow exists.
2017
2275
  *
2018
2276
  * @param queryId The Id of a possible query.
2019
- * @param rowId The Id of a possible Row.
2020
- * @returns Whether a result Row for that Id exists.
2277
+ * @param rowId The Id of a possible ResultRow.
2278
+ * @returns Whether a ResultRow for that Id exists.
2021
2279
  * @example
2022
- * This example shows two simple result Row existence checks.
2280
+ * This example shows two simple ResultRow existence checks.
2023
2281
  *
2024
2282
  * ```js
2025
2283
  * const store = createStore().setTable('pets', {
@@ -2049,14 +2307,14 @@ export interface Queries {
2049
2307
 
2050
2308
  /**
2051
2309
  * The hasResultCell method returns a boolean indicating whether a given
2052
- * result Cell exists.
2310
+ * ResultCell exists.
2053
2311
  *
2054
2312
  * @param queryId The Id of a possible query.
2055
- * @param rowId The Id of a possible Row.
2056
- * @param cellId The Id of a possible Cell.
2057
- * @returns Whether a result Cell for that Id exists.
2313
+ * @param rowId The Id of a possible ResultRow.
2314
+ * @param cellId The Id of a possible ResultCell.
2315
+ * @returns Whether a ResultCell for that Id exists.
2058
2316
  * @example
2059
- * This example shows two simple result Row existence checks.
2317
+ * This example shows two simple ResultRow existence checks.
2060
2318
  *
2061
2319
  * ```js
2062
2320
  * const store = createStore().setTable('pets', {
@@ -2086,18 +2344,18 @@ export interface Queries {
2086
2344
 
2087
2345
  /**
2088
2346
  * The forEachResultTable method takes a function that it will then call for
2089
- * each result Table in the Queries object.
2347
+ * each ResultTable in the Queries object.
2090
2348
  *
2091
- * This method is useful for iterating over all the result Tables of the
2349
+ * This method is useful for iterating over all the ResultTables of the
2092
2350
  * queries in a functional style. The `tableCallback` parameter is a
2093
- * TableCallback function that will be called with the Id of each result
2094
- * Table, and with a function that can then be used to iterate over each Row
2095
- * of the result Table, should you wish.
2351
+ * ResultTableCallback function that will be called with the Id of each
2352
+ * ResultTable, and with a function that can then be used to iterate over each
2353
+ * ResultRow of the ResultTable, should you wish.
2096
2354
  *
2097
2355
  * @param tableCallback The function that should be called for every query's
2098
- * result Table.
2356
+ * ResultTable.
2099
2357
  * @example
2100
- * This example iterates over each query's result Table in a Queries object.
2358
+ * This example iterates over each query's ResultTable in a Queries object.
2101
2359
  *
2102
2360
  * ```js
2103
2361
  * const store = createStore().setTable('pets', {
@@ -2129,23 +2387,23 @@ export interface Queries {
2129
2387
  * @category Iterator
2130
2388
  * @since v2.0.0
2131
2389
  */
2132
- forEachResultTable(tableCallback: TableCallback): void;
2390
+ forEachResultTable(tableCallback: ResultTableCallback): void;
2133
2391
 
2134
2392
  /**
2135
2393
  * The forEachResultRow method takes a function that it will then call for
2136
- * each Row in the result Table of a query.
2394
+ * each ResultRow in the ResultTable of a query.
2137
2395
  *
2138
- * This method is useful for iterating over each Row of the result Table of
2139
- * the query in a functional style. The `rowCallback` parameter is a
2140
- * RowCallback function that will be called with the Id of each result Row,
2141
- * and with a function that can then be used to iterate over each Cell of the
2142
- * result Row, should you wish.
2396
+ * This method is useful for iterating over each ResultRow of the ResultTable
2397
+ * of the query in a functional style. The `rowCallback` parameter is a
2398
+ * ResultRowCallback function that will be called with the Id of each
2399
+ * ResultRow, and with a function that can then be used to iterate over each
2400
+ * ResultCell of the ResultRow, should you wish.
2143
2401
  *
2144
2402
  * @param queryId The Id of a query.
2145
- * @param rowCallback The function that should be called for every Row of the
2146
- * query's result Table.
2403
+ * @param rowCallback The function that should be called for every ResultRow
2404
+ * of the query's ResultTable.
2147
2405
  * @example
2148
- * This example iterates over each Row in a query's result Table.
2406
+ * This example iterates over each ResultRow in a query's ResultTable.
2149
2407
  *
2150
2408
  * ```js
2151
2409
  * const store = createStore().setTable('pets', {
@@ -2175,22 +2433,23 @@ export interface Queries {
2175
2433
  * @category Iterator
2176
2434
  * @since v2.0.0
2177
2435
  */
2178
- forEachResultRow(queryId: Id, rowCallback: RowCallback): void;
2436
+ forEachResultRow(queryId: Id, rowCallback: ResultRowCallback): void;
2179
2437
 
2180
2438
  /**
2181
2439
  * The forEachResultCell method takes a function that it will then call for
2182
- * each Cell in the result Row of a query.
2440
+ * each ResultCell in the ResultRow of a query.
2183
2441
  *
2184
- * This method is useful for iterating over each Cell of the result Row of the
2185
- * query in a functional style. The `cellCallback` parameter is a CellCallback
2186
- * function that will be called with the Id and value of each result Cell.
2442
+ * This method is useful for iterating over each ResultCell of the ResultRow
2443
+ * of the query in a functional style. The `cellCallback` parameter is a
2444
+ * ResultCellCallback function that will be called with the Id and value of
2445
+ * each ResultCell.
2187
2446
  *
2188
2447
  * @param queryId The Id of a query.
2189
- * @param rowId The Id of a Row in the query's result Table.
2190
- * @param cellCallback The function that should be called for every Cell of
2191
- * the query's result Row.
2448
+ * @param rowId The Id of a ResultRow in the query's ResultTable.
2449
+ * @param cellCallback The function that should be called for every ResultCell
2450
+ * of the query's ResultRow.
2192
2451
  * @example
2193
- * This example iterates over each Cell in a query's result Row.
2452
+ * This example iterates over each ResultCell in a query's ResultRow.
2194
2453
  *
2195
2454
  * ```js
2196
2455
  * const store = createStore().setTable('pets', {
@@ -2218,28 +2477,32 @@ export interface Queries {
2218
2477
  * @category Iterator
2219
2478
  * @since v2.0.0
2220
2479
  */
2221
- forEachResultCell(queryId: Id, rowId: Id, cellCallback: CellCallback): void;
2480
+ forEachResultCell(
2481
+ queryId: Id,
2482
+ rowId: Id,
2483
+ cellCallback: ResultCellCallback,
2484
+ ): void;
2222
2485
 
2223
2486
  /**
2224
2487
  * The addResultTableListener method registers a listener function with the
2225
- * Queries object that will be called whenever data in a result Table changes.
2488
+ * Queries object that will be called whenever data in a ResultTable changes.
2226
2489
  *
2227
2490
  * The provided listener is a ResultTableListener function, and will be called
2228
- * with a reference to the Queries object, the Id of the Table that changed
2229
- * (which is also the query Id), and a GetCellChange function in case you need
2230
- * to inspect any changes that occurred.
2491
+ * with a reference to the Queries object, the Id of the ResultTable that
2492
+ * changed (which is also the query Id), and a GetCellResultChange function in
2493
+ * case you need to inspect any changes that occurred.
2231
2494
  *
2232
- * You can either listen to a single result Table (by specifying a query Id as
2233
- * the method's first parameter) or changes to any result Table (by providing
2234
- * a `null` wildcard).
2495
+ * You can either listen to a single ResultTable (by specifying a query Id as
2496
+ * the method's first parameter) or changes to any ResultTable (by providing a
2497
+ * `null` wildcard).
2235
2498
  *
2236
2499
  * @param queryId The Id of the query to listen to, or `null` as a wildcard.
2237
2500
  * @param listener The function that will be called whenever data in the
2238
- * matching result Table changes.
2501
+ * matching ResultTable changes.
2239
2502
  * @returns A unique Id for the listener that can later be used to remove it.
2240
2503
  * @example
2241
2504
  * This example registers a listener that responds to any changes to a
2242
- * specific result Table.
2505
+ * specific ResultTable.
2243
2506
  *
2244
2507
  * ```js
2245
2508
  * const store = createStore().setTable('pets', {
@@ -2273,7 +2536,7 @@ export interface Queries {
2273
2536
  * ```
2274
2537
  * @example
2275
2538
  * This example registers a listener that responds to any changes to any
2276
- * result Table.
2539
+ * ResultTable.
2277
2540
  *
2278
2541
  * ```js
2279
2542
  * const store = createStore().setTable('pets', {
@@ -2309,32 +2572,35 @@ export interface Queries {
2309
2572
  * @category Listener
2310
2573
  * @since v2.0.0
2311
2574
  */
2312
- addResultTableListener(queryId: IdOrNull, listener: ResultTableListener): Id;
2575
+ addResultTableListener(
2576
+ queryId: IdOrNull,
2577
+ listener: ResultTableListener<Schemas>,
2578
+ ): Id;
2313
2579
 
2314
2580
  /**
2315
2581
  * The addResultRowIdsListener method registers a listener function with the
2316
- * Queries object that will be called whenever the Row Ids in a result Table
2317
- * change.
2582
+ * Queries object that will be called whenever the ResultRow Ids in a
2583
+ * ResultTable change.
2318
2584
  *
2319
2585
  * The provided listener is a ResultRowIdsListener function, and will be
2320
- * called with a reference to the Queries object and the Id of the Table that
2321
- * changed (which is also the query Id).
2586
+ * called with a reference to the Queries object and the Id of the ResultTable
2587
+ * that changed (which is also the query Id).
2322
2588
  *
2323
- * By default, such a listener is only called when a Row is added to, or
2324
- * removed from, the result Table. To listen to all changes in the result
2325
- * Table, use the addResultTableListener method.
2589
+ * By default, such a listener is only called when a ResultRow is added to, or
2590
+ * removed from, the ResultTable. To listen to all changes in the ResultTable,
2591
+ * use the addResultTableListener method.
2326
2592
  *
2327
- * You can either listen to a single result Table (by specifying a query Id as
2328
- * the method's first parameter) or changes to any result Table (by providing
2329
- * a `null` wildcard).
2593
+ * You can either listen to a single ResultTable (by specifying a query Id as
2594
+ * the method's first parameter) or changes to any ResultTable (by providing a
2595
+ * `null` wildcard).
2330
2596
  *
2331
2597
  * @param queryId The Id of the query to listen to, or `null` as a wildcard.
2332
- * @param listener The function that will be called whenever the Row Ids in
2333
- * the result Table change.
2598
+ * @param listener The function that will be called whenever the ResultRow Ids
2599
+ * in the ResultTable change.
2334
2600
  * @returns A unique Id for the listener that can later be used to remove it.
2335
2601
  * @example
2336
- * This example registers a listener that responds to any change to the Row
2337
- * Ids of a specific result Table.
2602
+ * This example registers a listener that responds to any change to the
2603
+ * ResultRow Ids of a specific ResultTable.
2338
2604
  *
2339
2605
  * ```js
2340
2606
  * const store = createStore().setTable('pets', {
@@ -2367,8 +2633,8 @@ export interface Queries {
2367
2633
  * store.delListener(listenerId);
2368
2634
  * ```
2369
2635
  * @example
2370
- * This example registers a listener that responds to any change to the Row
2371
- * Ids of any result Table.
2636
+ * This example registers a listener that responds to any change to the
2637
+ * ResultRow Ids of any ResultTable.
2372
2638
  *
2373
2639
  * ```js
2374
2640
  * const store = createStore().setTable('pets', {
@@ -2406,50 +2672,50 @@ export interface Queries {
2406
2672
  */
2407
2673
  addResultRowIdsListener(
2408
2674
  queryId: IdOrNull,
2409
- listener: ResultRowIdsListener,
2675
+ listener: ResultRowIdsListener<Schemas>,
2410
2676
  ): Id;
2411
2677
 
2412
2678
  /**
2413
2679
  * The addResultSortedRowIdsListener method registers a listener function with
2414
2680
  * the Queries object that will be called whenever sorted (and optionally,
2415
- * paginated) Row Ids in a result Table change.
2681
+ * paginated) ResultRow Ids in a ResultTable change.
2416
2682
  *
2417
2683
  * The provided listener is a ResultSortedRowIdsListener function, and will be
2418
- * called with a reference to the Queries object, the Id of the result Table
2419
- * whose Row Ids sorting changed (which is also the query Id), the Cell Id
2420
- * being used to sort them, whether descending or not, and the offset and
2421
- * limit of the number of Ids returned, for pagination purposes. It also
2422
- * receives the sorted array of Ids itself, so that you can use them in the
2423
- * listener without the additional cost of an explicit call to
2684
+ * called with a reference to the Queries object, the Id of the ResultTable
2685
+ * whose ResultRow Ids sorting changed (which is also the query Id), the
2686
+ * ResultCell Id being used to sort them, whether descending or not, and the
2687
+ * offset and limit of the number of Ids returned, for pagination purposes. It
2688
+ * also receives the sorted array of Ids itself, so that you can use them in
2689
+ * the listener without the additional cost of an explicit call to
2424
2690
  * getResultSortedRowIds
2425
2691
  *
2426
- * Such a listener is called when a Row is added or removed, but also when a
2427
- * value in the specified Cell (somewhere in the result Table) has changed
2428
- * enough to change the sorting of the Row Ids.
2692
+ * Such a listener is called when a ResultRow is added or removed, but also
2693
+ * when a value in the specified ResultCell (somewhere in the ResultTable) has
2694
+ * changed enough to change the sorting of the ResultRow Ids.
2429
2695
  *
2430
2696
  * Unlike most other listeners, you cannot provide wildcards (due to the cost
2431
2697
  * of detecting changes to the sorting). You can only listen to a single
2432
- * specified result Table, sorted by a single specified Cell.
2698
+ * specified ResultTable, sorted by a single specified ResultCell.
2433
2699
  *
2434
2700
  * The sorting of the rows is alphanumeric, and you can indicate whether it
2435
2701
  * should be in descending order. The `offset` and `limit` parameters are used
2436
2702
  * to paginate results, but default to `0` and `undefined` to return all
2437
- * available Row Ids if not specified.
2703
+ * available ResultRow Ids if not specified.
2438
2704
  *
2439
2705
  * @param queryId The Id of the query to listen to.
2440
- * @param cellId The Id of the Cell whose values are used for the sorting, or
2441
- * `undefined` to by sort the result Row Id itself.
2706
+ * @param cellId The Id of the ResultCell whose values are used for the
2707
+ * sorting, or `undefined` to by sort the ResultRow Id itself.
2442
2708
  * @param descending Whether the sorting should be in descending order.
2443
- * @param offset The number of Row Ids to skip for pagination purposes, if
2444
- * any.
2445
- * @param limit The maximum number of Row Ids to return, or `undefined` for
2446
- * all.
2447
- * @param listener The function that will be called whenever the sorted Row
2448
- * Ids in the result Table change.
2709
+ * @param offset The number of ResultRow Ids to skip for pagination purposes,
2710
+ * if any.
2711
+ * @param limit The maximum number of ResultRow Ids to return, or `undefined`
2712
+ * for all.
2713
+ * @param listener The function that will be called whenever the sorted
2714
+ * ResultRow Ids in the ResultTable change.
2449
2715
  * @returns A unique Id for the listener that can later be used to remove it.
2450
2716
  * @example
2451
2717
  * This example registers a listener that responds to any change to the sorted
2452
- * Row Ids of a specific result Table.
2718
+ * ResultRow Ids of a specific ResultTable.
2453
2719
  *
2454
2720
  * ```js
2455
2721
  * const store = createStore().setTable('pets', {
@@ -2474,22 +2740,22 @@ export interface Queries {
2474
2740
  * 0,
2475
2741
  * undefined,
2476
2742
  * (queries, tableId, cellId, descending, offset, limit, sortedRowIds) => {
2477
- * console.log(`Sorted Row Ids for dogColors result table changed`);
2743
+ * console.log(`Sorted row Ids for dogColors result table changed`);
2478
2744
  * console.log(sortedRowIds);
2479
2745
  * // ^ cheaper than calling getResultSortedRowIds again
2480
2746
  * },
2481
2747
  * );
2482
2748
  *
2483
2749
  * store.setRow('pets', 'rex', {species: 'dog', color: 'tan'});
2484
- * // -> 'Sorted Row Ids for dogColors result table changed'
2750
+ * // -> 'Sorted row Ids for dogColors result table changed'
2485
2751
  * // -> ['cujo', 'fido', 'rex']
2486
2752
  *
2487
2753
  * store.delListener(listenerId);
2488
2754
  * ```
2489
2755
  * @example
2490
2756
  * This example registers a listener that responds to any change to the sorted
2491
- * Row Ids of a specific Table. The Row Ids are sorted by their own value,
2492
- * since the `cellId` parameter is explicitly undefined.
2757
+ * ResultRow Ids of a specific ResultTable. The ResultRow Ids are sorted by
2758
+ * their own value, since the `cellId` parameter is explicitly undefined.
2493
2759
  *
2494
2760
  * ```js
2495
2761
  * const store = createStore().setTable('pets', {
@@ -2516,14 +2782,14 @@ export interface Queries {
2516
2782
  * 0,
2517
2783
  * undefined,
2518
2784
  * (queries, tableId, cellId, descending, offset, limit, sortedRowIds) => {
2519
- * console.log(`Sorted Row Ids for dogColors result table changed`);
2785
+ * console.log(`Sorted row Ids for dogColors result table changed`);
2520
2786
  * console.log(sortedRowIds);
2521
2787
  * // ^ cheaper than calling getSortedRowIds again
2522
2788
  * },
2523
2789
  * );
2524
2790
  *
2525
2791
  * store.setRow('pets', 'rex', {species: 'dog', color: 'tan'});
2526
- * // -> 'Sorted Row Ids for dogColors result table changed'
2792
+ * // -> 'Sorted row Ids for dogColors result table changed'
2527
2793
  * // -> ['cujo', 'fido', 'rex']
2528
2794
  *
2529
2795
  * store.delListener(listenerId);
@@ -2537,36 +2803,35 @@ export interface Queries {
2537
2803
  descending: boolean,
2538
2804
  offset: number,
2539
2805
  limit: number | undefined,
2540
- listener: ResultSortedRowIdsListener,
2806
+ listener: ResultSortedRowIdsListener<Schemas>,
2541
2807
  ): Id;
2542
2808
 
2543
2809
  /**
2544
2810
  * The addResultRowListener method registers a listener function with the
2545
- * Queries object that will be called whenever data in a result Row changes.
2811
+ * Queries object that will be called whenever data in a ResultRow changes.
2546
2812
  *
2547
2813
  * The provided listener is a ResultRowListener function, and will be called
2548
- * with a reference to the Queries object, the Id of the Table that changed
2549
- * (which is also the query Id), and a GetCellChange function in case you need
2550
- * to inspect any changes that occurred.
2814
+ * with a reference to the Queries object, the Id of the ResultTable that
2815
+ * changed (which is also the query Id), and a GetCellResultChange function in
2816
+ * case you need to inspect any changes that occurred.
2551
2817
  *
2552
- * You can either listen to a single result Row (by specifying a query Id and
2553
- * Row Id as the method's first two parameters) or changes to any result Row
2554
- * (by providing `null` wildcards).
2818
+ * You can either listen to a single ResultRow (by specifying a query Id and
2819
+ * ResultRow Id as the method's first two parameters) or changes to any
2820
+ * ResultRow (by providing `null` wildcards).
2555
2821
  *
2556
2822
  * Both, either, or neither of the `queryId` and `rowId` parameters can be
2557
- * wildcarded with `null`. You can listen to a specific result Row in a
2558
- * specific query, any result Row in a specific query, a specific result Row
2559
- * in any query, or any result Row in any query.
2823
+ * wildcarded with `null`. You can listen to a specific ResultRow in a
2824
+ * specific query, any ResultRow in a specific query, a specific ResultRow in
2825
+ * any query, or any ResultRow in any query.
2560
2826
  *
2561
2827
  * @param queryId The Id of the query to listen to, or `null` as a wildcard.
2562
- * @param rowId The Id of the result Row to listen to, or `null` as a
2563
- * wildcard.
2828
+ * @param rowId The Id of the ResultRow to listen to, or `null` as a wildcard.
2564
2829
  * @param listener The function that will be called whenever data in the
2565
- * matching result Row changes.
2830
+ * matching ResultRow changes.
2566
2831
  * @returns A unique Id for the listener that can later be used to remove it.
2567
2832
  * @example
2568
2833
  * This example registers a listener that responds to any changes to a
2569
- * specific result Row.
2834
+ * specific ResultRow.
2570
2835
  *
2571
2836
  * ```js
2572
2837
  * const store = createStore().setTable('pets', {
@@ -2601,7 +2866,7 @@ export interface Queries {
2601
2866
  * ```
2602
2867
  * @example
2603
2868
  * This example registers a listener that responds to any changes to any
2604
- * result Row.
2869
+ * ResultRow.
2605
2870
  *
2606
2871
  * ```js
2607
2872
  * const store = createStore().setTable('pets', {
@@ -2641,40 +2906,39 @@ export interface Queries {
2641
2906
  addResultRowListener(
2642
2907
  queryId: IdOrNull,
2643
2908
  rowId: IdOrNull,
2644
- listener: ResultRowListener,
2909
+ listener: ResultRowListener<Schemas>,
2645
2910
  ): Id;
2646
2911
 
2647
2912
  /**
2648
2913
  * The addResultCellIdsListener method registers a listener function with the
2649
- * Queries object that will be called whenever the Cell Ids in a result Row
2650
- * change.
2914
+ * Queries object that will be called whenever the ResultCell Ids in a
2915
+ * ResultRow change.
2651
2916
  *
2652
2917
  * The provided listener is a ResultCellIdsListener function, and will be
2653
- * called with a reference to the Queries object, the Id of the Table (which
2654
- * is also the query Id), and the Id of the result Row that changed.
2918
+ * called with a reference to the Queries object, the Id of the ResultTable
2919
+ * (which is also the query Id), and the Id of the ResultRow that changed.
2655
2920
  *
2656
- * Such a listener is only called when a Cell is added to, or removed from,
2657
- * the result Row. To listen to all changes in the result Row, use the
2921
+ * Such a listener is only called when a ResultCell is added to, or removed
2922
+ * from, the ResultRow. To listen to all changes in the ResultRow, use the
2658
2923
  * addResultRowListener method.
2659
2924
  *
2660
- * You can either listen to a single result Row (by specifying the query Id
2661
- * and Row Id as the method's first two parameters) or changes to any Row (by
2662
- * providing `null` wildcards).
2925
+ * You can either listen to a single ResultRow (by specifying the query Id and
2926
+ * ResultRow Id as the method's first two parameters) or changes to any
2927
+ * ResultRow (by providing `null` wildcards).
2663
2928
  *
2664
2929
  * Both, either, or neither of the `queryId` and `rowId` parameters can be
2665
- * wildcarded with `null`. You can listen to a specific result Row in a
2666
- * specific query, any result Row in a specific query, a specific result Row
2667
- * in any query, or any result Row in any query.
2930
+ * wildcarded with `null`. You can listen to a specific ResultRow in a
2931
+ * specific query, any ResultRow in a specific query, a specific ResultRow in
2932
+ * any query, or any ResultRow in any query.
2668
2933
  *
2669
2934
  * @param queryId The Id of the query to listen to, or `null` as a wildcard.
2670
- * @param rowId The Id of the result Row to listen to, or `null` as a
2671
- * wildcard.
2672
- * @param listener The function that will be called whenever the Cell Ids in
2673
- * the result Row change.
2935
+ * @param rowId The Id of the ResultRow to listen to, or `null` as a wildcard.
2936
+ * @param listener The function that will be called whenever the ResultCell
2937
+ * Ids in the ResultRow change.
2674
2938
  * @returns A unique Id for the listener that can later be used to remove it.
2675
2939
  * @example
2676
- * This example registers a listener that responds to any change to the Cell
2677
- * Ids of a specific result Row.
2940
+ * This example registers a listener that responds to any change to the
2941
+ * ResultCell Ids of a specific ResultRow.
2678
2942
  *
2679
2943
  * ```js
2680
2944
  * const store = createStore().setTable('pets', {
@@ -2709,8 +2973,8 @@ export interface Queries {
2709
2973
  * store.delListener(listenerId);
2710
2974
  * ```
2711
2975
  * @example
2712
- * This example registers a listener that responds to any change to the Cell
2713
- * Ids of any result Row.
2976
+ * This example registers a listener that responds to any change to the
2977
+ * ResultCell Ids of any ResultRow.
2714
2978
  *
2715
2979
  * ```js
2716
2980
  * const store = createStore().setTable('pets', {
@@ -2754,40 +3018,39 @@ export interface Queries {
2754
3018
  addResultCellIdsListener(
2755
3019
  queryId: IdOrNull,
2756
3020
  rowId: IdOrNull,
2757
- listener: ResultCellIdsListener,
3021
+ listener: ResultCellIdsListener<Schemas>,
2758
3022
  ): Id;
2759
3023
 
2760
3024
  /**
2761
3025
  * The addResultCellListener method registers a listener function with the
2762
- * Queries object that will be called whenever data in a result Cell changes.
3026
+ * Queries object that will be called whenever data in a ResultCell changes.
2763
3027
  *
2764
3028
  * The provided listener is a ResultCellListener function, and will be called
2765
- * with a reference to the Queries object, the Id of the Table that changed
2766
- * (which is also the query Id), the Id of the Row that changed, the Id of the
2767
- * Cell that changed, the new Cell value, the old Cell value, and a
2768
- * GetCellChange function in case you need to inspect any changes that
2769
- * occurred.
3029
+ * with a reference to the Queries object, the Id of the ResultTable that
3030
+ * changed (which is also the query Id), the Id of the ResultRow that changed,
3031
+ * the Id of the ResultCell that changed, the new ResultCell value, the old
3032
+ * ResultCell value, and a GetCellResultChange function in case you need to
3033
+ * inspect any changes that occurred.
2770
3034
  *
2771
- * You can either listen to a single result Row (by specifying a query Id, Row
2772
- * Id, and Cell Id as the method's first three parameters) or changes to any
2773
- * result Cell (by providing `null` wildcards).
3035
+ * You can either listen to a single ResultRow (by specifying a query Id,
3036
+ * ResultRow Id, and ResultCell Id as the method's first three parameters) or
3037
+ * changes to any ResultCell (by providing `null` wildcards).
2774
3038
  *
2775
3039
  * All, some, or none of the `queryId`, `rowId`, and `cellId` parameters can
2776
- * be wildcarded with `null`. You can listen to a specific Cell in a specific
2777
- * result Row in a specific query, any Cell in any result Row in any query,
2778
- * for example - or every other combination of wildcards.
3040
+ * be wildcarded with `null`. You can listen to a specific ResultCell in a
3041
+ * specific ResultRow in a specific query, any ResultCell in any ResultRow in
3042
+ * any query, for example - or every other combination of wildcards.
2779
3043
  *
2780
3044
  * @param queryId The Id of the query to listen to, or `null` as a wildcard.
2781
- * @param rowId The Id of the result Row to listen to, or `null` as a
2782
- * wildcard.
2783
- * @param cellId The Id of the result Cell to listen to, or `null` as a
3045
+ * @param rowId The Id of the ResultRow to listen to, or `null` as a wildcard.
3046
+ * @param cellId The Id of the ResultCell to listen to, or `null` as a
2784
3047
  * wildcard.
2785
3048
  * @param listener The function that will be called whenever data in the
2786
- * matching result Cell changes.
3049
+ * matching ResultCell changes.
2787
3050
  * @returns A unique Id for the listener that can later be used to remove it.
2788
3051
  * @example
2789
3052
  * This example registers a listener that responds to any changes to a
2790
- * specific result Cell.
3053
+ * specific ResultCell.
2791
3054
  *
2792
3055
  * ```js
2793
3056
  * const store = createStore().setTable('pets', {
@@ -2827,7 +3090,7 @@ export interface Queries {
2827
3090
  * ```
2828
3091
  * @example
2829
3092
  * This example registers a listener that responds to any changes to any
2830
- * result Cell.
3093
+ * ResultCell.
2831
3094
  *
2832
3095
  * ```js
2833
3096
  * const store = createStore().setTable('pets', {
@@ -2872,7 +3135,7 @@ export interface Queries {
2872
3135
  queryId: IdOrNull,
2873
3136
  rowId: IdOrNull,
2874
3137
  cellId: IdOrNull,
2875
- listener: ResultCellListener,
3138
+ listener: ResultCellListener<Schemas>,
2876
3139
  ): Id;
2877
3140
 
2878
3141
  /**
@@ -2919,7 +3182,7 @@ export interface Queries {
2919
3182
  * @category Listener
2920
3183
  * @since v2.0.0
2921
3184
  */
2922
- delListener(listenerId: Id): Queries;
3185
+ delListener(listenerId: Id): Queries<Schemas>;
2923
3186
 
2924
3187
  /**
2925
3188
  * The destroy method should be called when this Queries object is no longer
@@ -3021,4 +3284,6 @@ export interface Queries {
3021
3284
  * @category Creation
3022
3285
  * @since v2.0.0
3023
3286
  */
3024
- export function createQueries(store: Store): Queries;
3287
+ export function createQueries<Schemas extends OptionalSchemas>(
3288
+ store: Store<Schemas>,
3289
+ ): Queries<Schemas>;