tinybase 3.1.0-beta.4 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/debug/ui-react.js +2 -2
- package/lib/{checkpoints.d.ts → types/checkpoints.d.ts} +13 -13
- package/lib/{debug → types}/indexes.d.ts +10 -16
- package/lib/{debug → types}/metrics.d.ts +49 -50
- package/lib/{debug → types}/persisters.d.ts +26 -30
- package/lib/{cjs-es6 → types}/queries.d.ts +474 -309
- package/lib/{debug → types}/relationships.d.ts +11 -17
- package/lib/{debug → types}/store.d.ts +180 -1038
- package/lib/types/tinybase.d.ts +14 -0
- package/lib/{debug → types}/tools.d.ts +12 -12
- package/lib/{debug → types}/ui-react.d.ts +11 -5
- package/lib/{cjs-es6 → types/with-schemas}/checkpoints.d.ts +93 -7
- package/lib/{cjs → types/with-schemas}/indexes.d.ts +136 -18
- package/lib/types/with-schemas/internal/queries.d.ts +15 -0
- package/lib/types/with-schemas/internal/store.d.ts +101 -0
- package/lib/types/with-schemas/internal/ui-react.d.ts +776 -0
- package/lib/{cjs → types/with-schemas}/metrics.d.ts +115 -50
- package/lib/{cjs → types/with-schemas}/persisters.d.ts +102 -4
- package/lib/{debug → types/with-schemas}/queries.d.ts +865 -346
- package/lib/{cjs → types/with-schemas}/relationships.d.ts +151 -20
- package/lib/{cjs-es6 → types/with-schemas}/store.d.ts +1082 -801
- package/lib/types/with-schemas/tinybase.d.ts +14 -0
- package/lib/{cjs-es6 → types/with-schemas}/tools.d.ts +21 -10
- package/lib/{cjs-es6 → types/with-schemas}/ui-react.d.ts +1871 -1314
- package/package.json +145 -29
- package/readme.md +14 -14
- package/lib/cjs/checkpoints.d.ts +0 -961
- package/lib/cjs/queries.d.ts +0 -3028
- package/lib/cjs/store.d.ts +0 -6143
- package/lib/cjs/tinybase.d.ts +0 -14
- package/lib/cjs/tools.d.ts +0 -536
- package/lib/cjs/ui-react.d.ts +0 -10921
- package/lib/cjs-es6/indexes.d.ts +0 -974
- package/lib/cjs-es6/metrics.d.ts +0 -829
- package/lib/cjs-es6/persisters.d.ts +0 -733
- package/lib/cjs-es6/relationships.d.ts +0 -1209
- package/lib/cjs-es6/tinybase.d.ts +0 -14
- package/lib/common.d.ts +0 -115
- package/lib/debug/checkpoints.d.ts +0 -961
- package/lib/debug/common.d.ts +0 -115
- package/lib/debug/tinybase.d.ts +0 -14
- package/lib/es6/checkpoints.d.ts +0 -961
- package/lib/es6/common.d.ts +0 -115
- package/lib/es6/indexes.d.ts +0 -974
- package/lib/es6/metrics.d.ts +0 -829
- package/lib/es6/persisters.d.ts +0 -733
- package/lib/es6/queries.d.ts +0 -3028
- package/lib/es6/relationships.d.ts +0 -1209
- package/lib/es6/store.d.ts +0 -6143
- package/lib/es6/tinybase.d.ts +0 -14
- package/lib/es6/tools.d.ts +0 -536
- package/lib/es6/ui-react.d.ts +0 -10921
- package/lib/indexes.d.ts +0 -974
- package/lib/metrics.d.ts +0 -829
- package/lib/persisters.d.ts +0 -733
- package/lib/queries.d.ts +0 -3028
- package/lib/relationships.d.ts +0 -1209
- package/lib/store.d.ts +0 -6143
- package/lib/tinybase.d.ts +0 -14
- package/lib/tools.d.ts +0 -536
- package/lib/ui-react.d.ts +0 -10921
- package/lib/umd/checkpoints.d.ts +0 -961
- package/lib/umd/common.d.ts +0 -115
- package/lib/umd/indexes.d.ts +0 -974
- package/lib/umd/metrics.d.ts +0 -829
- package/lib/umd/persisters.d.ts +0 -733
- package/lib/umd/queries.d.ts +0 -3028
- package/lib/umd/relationships.d.ts +0 -1209
- package/lib/umd/store.d.ts +0 -6143
- package/lib/umd/tinybase.d.ts +0 -14
- package/lib/umd/tools.d.ts +0 -536
- package/lib/umd/ui-react.d.ts +0 -10921
- package/lib/umd-es6/checkpoints.d.ts +0 -961
- package/lib/umd-es6/common.d.ts +0 -115
- package/lib/umd-es6/indexes.d.ts +0 -974
- package/lib/umd-es6/metrics.d.ts +0 -829
- package/lib/umd-es6/persisters.d.ts +0 -733
- package/lib/umd-es6/queries.d.ts +0 -3028
- package/lib/umd-es6/relationships.d.ts +0 -1209
- package/lib/umd-es6/store.d.ts +0 -6143
- package/lib/umd-es6/tinybase.d.ts +0 -14
- package/lib/umd-es6/tools.d.ts +0 -536
- package/lib/umd-es6/ui-react.d.ts +0 -10921
- /package/lib/{cjs-es6 → types}/common.d.ts +0 -0
- /package/lib/{cjs → types/with-schemas}/common.d.ts +0 -0
|
@@ -14,20 +14,79 @@
|
|
|
14
14
|
|
|
15
15
|
import {
|
|
16
16
|
Cell,
|
|
17
|
-
CellCallback,
|
|
18
17
|
CellOrUndefined,
|
|
19
18
|
GetCell,
|
|
20
|
-
|
|
21
|
-
NoSchemas,
|
|
19
|
+
NoTablesSchema,
|
|
22
20
|
OptionalSchemas,
|
|
23
|
-
|
|
24
|
-
RowCallback,
|
|
21
|
+
OptionalTablesSchema,
|
|
25
22
|
Store,
|
|
26
|
-
Table,
|
|
27
|
-
TableCallback,
|
|
28
23
|
} from './store.d';
|
|
24
|
+
import {CellIdFromSchema, TableIdFromSchema} from './internal/store';
|
|
25
|
+
import {GetResultCell, JoinedCellIdOrId} from './internal/queries';
|
|
29
26
|
import {Id, IdOrNull, Ids} from './common.d';
|
|
30
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
|
+
|
|
31
90
|
/**
|
|
32
91
|
* The Aggregate type describes a custom function that takes an array of Cell
|
|
33
92
|
* values and returns an aggregate of them.
|
|
@@ -42,7 +101,7 @@ import {Id, IdOrNull, Ids} from './common.d';
|
|
|
42
101
|
* @category Aggregators
|
|
43
102
|
* @since v2.0.0
|
|
44
103
|
*/
|
|
45
|
-
export type Aggregate = (cells:
|
|
104
|
+
export type Aggregate = (cells: ResultCell[], length: number) => ResultCell;
|
|
46
105
|
|
|
47
106
|
/**
|
|
48
107
|
* The AggregateAdd type describes a function that can be used to optimize a
|
|
@@ -69,10 +128,10 @@ export type Aggregate = (cells: Cell[], length: number) => Cell;
|
|
|
69
128
|
* @since v2.0.0
|
|
70
129
|
*/
|
|
71
130
|
export type AggregateAdd = (
|
|
72
|
-
current:
|
|
73
|
-
add:
|
|
131
|
+
current: ResultCell,
|
|
132
|
+
add: ResultCell,
|
|
74
133
|
length: number,
|
|
75
|
-
) =>
|
|
134
|
+
) => ResultCellOrUndefined;
|
|
76
135
|
|
|
77
136
|
/**
|
|
78
137
|
* The AggregateRemove type describes a function that can be used to optimize a
|
|
@@ -102,10 +161,10 @@ export type AggregateAdd = (
|
|
|
102
161
|
* @since v2.0.0
|
|
103
162
|
*/
|
|
104
163
|
export type AggregateRemove = (
|
|
105
|
-
current:
|
|
106
|
-
remove:
|
|
164
|
+
current: ResultCell,
|
|
165
|
+
remove: ResultCell,
|
|
107
166
|
length: number,
|
|
108
|
-
) =>
|
|
167
|
+
) => ResultCellOrUndefined;
|
|
109
168
|
|
|
110
169
|
/**
|
|
111
170
|
* The AggregateReplace type describes a function that can be used to optimize a
|
|
@@ -134,11 +193,11 @@ export type AggregateRemove = (
|
|
|
134
193
|
* @since v2.0.0
|
|
135
194
|
*/
|
|
136
195
|
export type AggregateReplace = (
|
|
137
|
-
current:
|
|
138
|
-
add:
|
|
139
|
-
remove:
|
|
196
|
+
current: ResultCell,
|
|
197
|
+
add: ResultCell,
|
|
198
|
+
remove: ResultCell,
|
|
140
199
|
length: number,
|
|
141
|
-
) =>
|
|
200
|
+
) => ResultCellOrUndefined;
|
|
142
201
|
|
|
143
202
|
/**
|
|
144
203
|
* The QueryCallback type describes a function that takes a query's Id.
|
|
@@ -153,76 +212,163 @@ export type AggregateReplace = (
|
|
|
153
212
|
*/
|
|
154
213
|
export type QueryCallback = (queryId: Id) => void;
|
|
155
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
|
+
|
|
156
265
|
/**
|
|
157
266
|
* The ResultTableListener type describes a function that is used to listen to
|
|
158
|
-
* changes to a query's
|
|
267
|
+
* changes to a query's ResultTable.
|
|
268
|
+
*
|
|
269
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
270
|
+
*
|
|
271
|
+
* ```ts override
|
|
272
|
+
* (
|
|
273
|
+
* queries: Queries,
|
|
274
|
+
* tableId: Id,
|
|
275
|
+
* getCellChange: GetCellResultChange,
|
|
276
|
+
* ) => void;
|
|
277
|
+
* ```
|
|
159
278
|
*
|
|
160
279
|
* A ResultTableListener is provided when using the addResultTableListener
|
|
161
280
|
* method. See that method for specific examples.
|
|
162
281
|
*
|
|
163
282
|
* When called, a ResultTableListener is given a reference to the Queries
|
|
164
|
-
* object, the Id of the
|
|
165
|
-
* and a
|
|
166
|
-
* after the change.
|
|
283
|
+
* object, the Id of the ResultTable that changed (which is the same as the
|
|
284
|
+
* query Id), and a GetCellResultChange function that can be used to query
|
|
285
|
+
* ResultCell values before and after the change.
|
|
167
286
|
*
|
|
168
287
|
* @param queries A reference to the Queries object that changed.
|
|
169
|
-
* @param tableId The Id of the
|
|
170
|
-
*
|
|
171
|
-
*
|
|
288
|
+
* @param tableId The Id of the ResultTable that changed, which is also the
|
|
289
|
+
* query Id.
|
|
290
|
+
* @param getCellChange A function that returns information about any
|
|
291
|
+
* ResultCell's changes.
|
|
172
292
|
* @category Listener
|
|
173
293
|
* @since v2.0.0
|
|
174
294
|
*/
|
|
175
|
-
export type ResultTableListener = (
|
|
176
|
-
queries: Queries
|
|
295
|
+
export type ResultTableListener<Schemas extends OptionalSchemas> = (
|
|
296
|
+
queries: Queries<Schemas>,
|
|
177
297
|
tableId: Id,
|
|
178
|
-
getCellChange:
|
|
298
|
+
getCellChange: GetCellResultChange,
|
|
179
299
|
) => void;
|
|
180
300
|
|
|
181
301
|
/**
|
|
182
302
|
* The ResultRowIdsListener type describes a function that is used to listen to
|
|
183
|
-
* changes to the
|
|
303
|
+
* changes to the ResultRow Ids in a query's ResultTable.
|
|
304
|
+
*
|
|
305
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
306
|
+
*
|
|
307
|
+
* ```ts override
|
|
308
|
+
* (queries: Queries, tableId: Id) => void;
|
|
309
|
+
* ```
|
|
184
310
|
*
|
|
185
311
|
* A ResultRowIdsListener is provided when using the addResultRowIdsListener
|
|
186
312
|
* method. See that method for specific examples.
|
|
187
313
|
*
|
|
188
314
|
* When called, a ResultRowIdsListener is given a reference to the Queries
|
|
189
|
-
* object, and the Id of the
|
|
190
|
-
* the query Id).
|
|
315
|
+
* object, and the Id of the ResultTable whose ResultRow Ids changed (which is
|
|
316
|
+
* the same as the query Id).
|
|
191
317
|
*
|
|
192
318
|
* @param queries A reference to the Queries object that changed.
|
|
193
|
-
* @param tableId The Id of the
|
|
319
|
+
* @param tableId The Id of the ResultTable that changed, which is also the
|
|
320
|
+
* query Id.
|
|
194
321
|
* @category Listener
|
|
195
322
|
* @since v2.0.0
|
|
196
323
|
*/
|
|
197
|
-
export type ResultRowIdsListener = (
|
|
324
|
+
export type ResultRowIdsListener<Schemas extends OptionalSchemas> = (
|
|
325
|
+
queries: Queries<Schemas>,
|
|
326
|
+
tableId: Id,
|
|
327
|
+
) => void;
|
|
198
328
|
|
|
199
329
|
/**
|
|
200
330
|
* The ResultSortedRowIdsListener type describes a function that is used to
|
|
201
|
-
* listen to changes to the sorted
|
|
331
|
+
* listen to changes to the sorted ResultRow Ids in a query's ResultTable.
|
|
332
|
+
*
|
|
333
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
334
|
+
*
|
|
335
|
+
* ```ts override
|
|
336
|
+
* (
|
|
337
|
+
* queries: Queries,
|
|
338
|
+
* tableId: Id,
|
|
339
|
+
* cellId: Id | undefined,
|
|
340
|
+
* descending: boolean,
|
|
341
|
+
* offset: number,
|
|
342
|
+
* limit: number | undefined,
|
|
343
|
+
* sortedRowIds: Ids,
|
|
344
|
+
* ) => void;
|
|
345
|
+
* ```
|
|
202
346
|
*
|
|
203
347
|
* A ResultSortedRowIdsListener is provided when using the
|
|
204
348
|
* addResultSortedRowIdsListener method. See that method for specific examples.
|
|
205
349
|
*
|
|
206
350
|
* When called, a ResultSortedRowIdsListener is given a reference to the Queries
|
|
207
|
-
* object, the Id of the
|
|
208
|
-
* query Id), the
|
|
209
|
-
* and the offset and limit of the number of Ids returned,
|
|
210
|
-
* purposes. It also receives the sorted array of Ids itself, so
|
|
211
|
-
* use them in the listener without the additional cost of an
|
|
212
|
-
* getResultSortedRowIds.
|
|
351
|
+
* object, the Id of the ResultTable whose ResultRow Ids changed (which is the
|
|
352
|
+
* same as the query Id), the ResultCell Id being used to sort them, whether
|
|
353
|
+
* descending or not, and the offset and limit of the number of Ids returned,
|
|
354
|
+
* for pagination purposes. It also receives the sorted array of Ids itself, so
|
|
355
|
+
* that you can use them in the listener without the additional cost of an
|
|
356
|
+
* explicit call to getResultSortedRowIds.
|
|
213
357
|
*
|
|
214
358
|
* @param queries A reference to the Queries object that changed.
|
|
215
|
-
* @param tableId The Id of the
|
|
216
|
-
*
|
|
359
|
+
* @param tableId The Id of the ResultTable that changed, which is also the
|
|
360
|
+
* query Id.
|
|
361
|
+
* @param cellId The Id of the ResultCell whose values were used for the
|
|
362
|
+
* sorting.
|
|
217
363
|
* @param descending Whether the sorting was in descending order.
|
|
218
|
-
* @param offset The number of
|
|
219
|
-
* @param limit The maximum number of
|
|
220
|
-
* @param sortedRowIds The sorted
|
|
364
|
+
* @param offset The number of ResultRow Ids skipped.
|
|
365
|
+
* @param limit The maximum number of ResultRow Ids returned.
|
|
366
|
+
* @param sortedRowIds The sorted ResultRow Ids themselves.
|
|
221
367
|
* @category Listener
|
|
222
368
|
* @since v2.0.0
|
|
223
369
|
*/
|
|
224
|
-
export type ResultSortedRowIdsListener = (
|
|
225
|
-
queries: Queries
|
|
370
|
+
export type ResultSortedRowIdsListener<Schemas extends OptionalSchemas> = (
|
|
371
|
+
queries: Queries<Schemas>,
|
|
226
372
|
tableId: Id,
|
|
227
373
|
cellId: Id | undefined,
|
|
228
374
|
descending: boolean,
|
|
@@ -233,88 +379,166 @@ export type ResultSortedRowIdsListener = (
|
|
|
233
379
|
|
|
234
380
|
/**
|
|
235
381
|
* The ResultRowListener type describes a function that is used to listen to
|
|
236
|
-
* changes to a
|
|
382
|
+
* changes to a ResultRow in a query's ResultTable.
|
|
383
|
+
*
|
|
384
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
385
|
+
*
|
|
386
|
+
* ```ts override
|
|
387
|
+
* (
|
|
388
|
+
* queries: Queries,
|
|
389
|
+
* tableId: Id,
|
|
390
|
+
* rowId: Id,
|
|
391
|
+
* getCellChange: GetCellResultChange,
|
|
392
|
+
* ) => void;
|
|
393
|
+
* ```
|
|
237
394
|
*
|
|
238
395
|
* A ResultRowListener is provided when using the addResultRowListener method.
|
|
239
396
|
* See that method for specific examples.
|
|
240
397
|
*
|
|
241
398
|
* When called, a ResultRowListener is given a reference to the Queries object,
|
|
242
|
-
* the Id of the
|
|
243
|
-
* of the
|
|
244
|
-
* query
|
|
399
|
+
* the Id of the ResultTable that changed (which is the same as the query Id),
|
|
400
|
+
* the Id of the ResultRow that changed, and a GetCellResultChange function that
|
|
401
|
+
* can be used to query ResultCell values before and after the change.
|
|
245
402
|
*
|
|
246
403
|
* @param queries A reference to the Queries object that changed.
|
|
247
|
-
* @param tableId The Id of the
|
|
248
|
-
*
|
|
249
|
-
* @param
|
|
250
|
-
*
|
|
404
|
+
* @param tableId The Id of the ResultTable that changed, which is also the
|
|
405
|
+
* query Id.
|
|
406
|
+
* @param rowId The Id of the ResultRow that changed.
|
|
407
|
+
* @param getCellChange A function that returns information about any
|
|
408
|
+
* ResultCell's changes.
|
|
251
409
|
* @category Listener
|
|
252
410
|
* @since v2.0.0
|
|
253
411
|
*/
|
|
254
|
-
export type ResultRowListener = (
|
|
255
|
-
queries: Queries
|
|
412
|
+
export type ResultRowListener<Schemas extends OptionalSchemas> = (
|
|
413
|
+
queries: Queries<Schemas>,
|
|
256
414
|
tableId: Id,
|
|
257
415
|
rowId: Id,
|
|
258
|
-
getCellChange:
|
|
416
|
+
getCellChange: GetCellResultChange,
|
|
259
417
|
) => void;
|
|
260
418
|
|
|
261
419
|
/**
|
|
262
420
|
* The ResultCellIdsListener type describes a function that is used to listen to
|
|
263
|
-
* changes to the
|
|
421
|
+
* changes to the ResultCell Ids in a ResultRow in a query's ResultTable.
|
|
422
|
+
*
|
|
423
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
424
|
+
*
|
|
425
|
+
* ```ts override
|
|
426
|
+
* (
|
|
427
|
+
* queries: Queries,
|
|
428
|
+
* tableId: Id,
|
|
429
|
+
* rowId: Id,
|
|
430
|
+
* ) => void;
|
|
431
|
+
* ```
|
|
264
432
|
*
|
|
265
433
|
* A ResultCellIdsListener is provided when using the addResultCellIdsListener
|
|
266
434
|
* method. See that method for specific examples.
|
|
267
435
|
*
|
|
268
436
|
* When called, a ResultCellIdsListener is given a reference to the Queries
|
|
269
|
-
* object, the Id of the
|
|
270
|
-
* and the Id of the
|
|
437
|
+
* object, the Id of the ResultTable that changed (which is the same as the
|
|
438
|
+
* query Id), and the Id of the ResultRow whose ResultCell Ids changed.
|
|
271
439
|
*
|
|
272
440
|
* @param queries A reference to the Queries object that changed.
|
|
273
|
-
* @param tableId The Id of the
|
|
274
|
-
*
|
|
441
|
+
* @param tableId The Id of the ResultTable that changed, which is also the
|
|
442
|
+
* query Id.
|
|
443
|
+
* @param rowId The Id of the ResultRow that changed.
|
|
275
444
|
* @category Listener
|
|
276
445
|
* @since v2.0.0
|
|
277
446
|
*/
|
|
278
|
-
export type ResultCellIdsListener = (
|
|
279
|
-
queries: Queries
|
|
447
|
+
export type ResultCellIdsListener<Schemas extends OptionalSchemas> = (
|
|
448
|
+
queries: Queries<Schemas>,
|
|
280
449
|
tableId: Id,
|
|
281
450
|
rowId: Id,
|
|
282
451
|
) => void;
|
|
283
452
|
|
|
284
453
|
/**
|
|
285
454
|
* The ResultCellListener type describes a function that is used to listen to
|
|
286
|
-
* changes to a
|
|
455
|
+
* changes to a ResultCell in a query's ResultTable.
|
|
456
|
+
*
|
|
457
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
458
|
+
*
|
|
459
|
+
* ```ts override
|
|
460
|
+
* (
|
|
461
|
+
* queries: Queries,
|
|
462
|
+
* tableId: Id,
|
|
463
|
+
* rowId: Id,
|
|
464
|
+
* cellId: Id,
|
|
465
|
+
* newCell: ResultCell,
|
|
466
|
+
* oldCell: ResultCell,
|
|
467
|
+
* getCellChange: GetCellResultChange,
|
|
468
|
+
* ) => void;
|
|
469
|
+
* ```
|
|
287
470
|
*
|
|
288
471
|
* A ResultCellListener is provided when using the addResultCellListener method.
|
|
289
472
|
* See that method for specific examples.
|
|
290
473
|
*
|
|
291
474
|
* When called, a ResultCellListener is given a reference to the Queries object,
|
|
292
|
-
* the Id of the
|
|
293
|
-
* of the
|
|
294
|
-
* the new value of the
|
|
295
|
-
* function that can be used to query
|
|
475
|
+
* the Id of the ResultTable that changed (which is the same as the query Id),
|
|
476
|
+
* the Id of the ResultRow that changed, and the Id of ResultCell that changed.
|
|
477
|
+
* It is also given the new value of the ResultCell, the old value of the
|
|
478
|
+
* ResultCell, and a GetCellResultChange function that can be used to query
|
|
479
|
+
* ResultCell values before and after the change.
|
|
296
480
|
*
|
|
297
481
|
* @param queries A reference to the Queries object that changed.
|
|
298
|
-
* @param tableId The Id of the
|
|
299
|
-
*
|
|
300
|
-
* @param
|
|
301
|
-
* @param
|
|
302
|
-
* @param
|
|
303
|
-
* @param
|
|
304
|
-
*
|
|
482
|
+
* @param tableId The Id of the ResultTable that changed, which is also the
|
|
483
|
+
* query Id.
|
|
484
|
+
* @param rowId The Id of the ResultRow that changed.
|
|
485
|
+
* @param cellId The Id of the ResultCell that changed.
|
|
486
|
+
* @param newCell The new value of the ResultCell that changed.
|
|
487
|
+
* @param oldCell The old value of the ResultCell that changed.
|
|
488
|
+
* @param getCellChange A function that returns information about any
|
|
489
|
+
* ResultCell's changes.
|
|
305
490
|
* @category Listener
|
|
306
491
|
* @since v2.0.0
|
|
307
492
|
*/
|
|
308
|
-
export type ResultCellListener = (
|
|
309
|
-
queries: Queries
|
|
493
|
+
export type ResultCellListener<Schemas extends OptionalSchemas> = (
|
|
494
|
+
queries: Queries<Schemas>,
|
|
310
495
|
tableId: Id,
|
|
311
496
|
rowId: Id,
|
|
312
497
|
cellId: Id,
|
|
313
|
-
newCell:
|
|
314
|
-
oldCell:
|
|
315
|
-
getCellChange:
|
|
498
|
+
newCell: ResultCell,
|
|
499
|
+
oldCell: ResultCell,
|
|
500
|
+
getCellChange: GetCellResultChange,
|
|
316
501
|
) => void;
|
|
317
502
|
|
|
503
|
+
/**
|
|
504
|
+
* The GetCellResultChange type describes a function that returns information
|
|
505
|
+
* about any ResultCell's changes during a transaction.
|
|
506
|
+
*
|
|
507
|
+
* A GetCellResultChange function is provided to every listener when called due
|
|
508
|
+
* the Store changing. The listener can then fetch the previous value of a
|
|
509
|
+
* ResultCell before the current transaction, the new value after it, and a
|
|
510
|
+
* convenience flag that indicates that the value has changed.
|
|
511
|
+
*
|
|
512
|
+
* @param tableId The Id of the ResultTable to inspect.
|
|
513
|
+
* @param rowId The Id of the ResultRow to inspect.
|
|
514
|
+
* @param cellId The Id of the ResultCell to inspect.
|
|
515
|
+
* @returns A ResultCellChange array containing information about the
|
|
516
|
+
* ResultCell's changes.
|
|
517
|
+
* @category Listener
|
|
518
|
+
*/
|
|
519
|
+
export type GetCellResultChange = (
|
|
520
|
+
tableId: Id,
|
|
521
|
+
rowId: Id,
|
|
522
|
+
cellId: Id,
|
|
523
|
+
) => ResultCellChange;
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* The ResultCellChange type describes a ResultCell's changes during a
|
|
527
|
+
* transaction.
|
|
528
|
+
*
|
|
529
|
+
* This is returned by the GetResultCellChange function that is provided to
|
|
530
|
+
* every listener when called. This array contains the previous value of a
|
|
531
|
+
* ResultCell before the current transaction, the new value after it, and a
|
|
532
|
+
* convenience flag that indicates that the value has changed.
|
|
533
|
+
*
|
|
534
|
+
* @category Listener
|
|
535
|
+
*/
|
|
536
|
+
export type ResultCellChange = [
|
|
537
|
+
changed: boolean,
|
|
538
|
+
oldCell: ResultCellOrUndefined,
|
|
539
|
+
newCell: ResultCellOrUndefined,
|
|
540
|
+
];
|
|
541
|
+
|
|
318
542
|
/**
|
|
319
543
|
* The QueriesListenerStats type describes the number of listeners registered
|
|
320
544
|
* with the Queries object, and can be used for debugging purposes.
|
|
@@ -359,20 +583,38 @@ export type QueriesListenerStats = {
|
|
|
359
583
|
* @category Callback
|
|
360
584
|
* @since v2.0.0
|
|
361
585
|
*/
|
|
362
|
-
export type GetTableCell
|
|
586
|
+
export type GetTableCell<
|
|
587
|
+
Schema extends OptionalTablesSchema,
|
|
588
|
+
RootTableId extends TableIdFromSchema<Schema>,
|
|
589
|
+
> = {
|
|
363
590
|
/**
|
|
364
|
-
* When called with one parameter, this function will return the value of
|
|
365
|
-
* specified Cell from the query's
|
|
366
|
-
* filtered.
|
|
591
|
+
* When called with one parameter, this function will return the value of
|
|
592
|
+
* the specified Cell from the query's root Table for the Row being selected
|
|
593
|
+
* or filtered.
|
|
594
|
+
*
|
|
595
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
596
|
+
*
|
|
597
|
+
* ```ts override
|
|
598
|
+
* (cellId: Id): CellOrUndefined;
|
|
599
|
+
* ```
|
|
367
600
|
*
|
|
368
601
|
* @param cellId The Id of the Cell to fetch the value for.
|
|
369
602
|
* @returns A Cell value or `undefined`.
|
|
370
603
|
*/
|
|
371
|
-
|
|
604
|
+
<RootCellId extends CellIdFromSchema<Schema, RootTableId>>(
|
|
605
|
+
cellId: RootCellId,
|
|
606
|
+
): CellOrUndefined<Schema, RootTableId, RootCellId>;
|
|
372
607
|
/**
|
|
373
|
-
* When called with two parameters, this function will return the value of
|
|
374
|
-
* specified Cell from a Table that has been joined in the query, for
|
|
375
|
-
* being selected or filtered.
|
|
608
|
+
* When called with two parameters, this function will return the value of
|
|
609
|
+
* the specified Cell from a Table that has been joined in the query, for
|
|
610
|
+
* the Row being selected or filtered.
|
|
611
|
+
*
|
|
612
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
613
|
+
*
|
|
614
|
+
* ```ts override
|
|
615
|
+
* (joinedTableId: Id, joinedCellId: Id): CellOrUndefined;
|
|
616
|
+
};
|
|
617
|
+
* ```
|
|
376
618
|
*
|
|
377
619
|
* @param joinedTableId The Id of the Table to fetch the value from. If the
|
|
378
620
|
* underlying Table was joined 'as' a different Id, that should instead be
|
|
@@ -380,7 +622,20 @@ export type GetTableCell = {
|
|
|
380
622
|
* @param joinedCellId The Id of the Cell to fetch the value for.
|
|
381
623
|
* @returns A Cell value or `undefined`.
|
|
382
624
|
*/
|
|
383
|
-
|
|
625
|
+
<
|
|
626
|
+
JoinedTableId extends TableIdFromSchema<Schema> | Id,
|
|
627
|
+
JoinedCellId extends JoinedCellIdOrId<
|
|
628
|
+
Schema,
|
|
629
|
+
JoinedTableId
|
|
630
|
+
> = JoinedCellIdOrId<Schema, JoinedTableId>,
|
|
631
|
+
>(
|
|
632
|
+
joinedTableId: JoinedTableId,
|
|
633
|
+
joinedCellId: JoinedCellId,
|
|
634
|
+
):
|
|
635
|
+
| (JoinedTableId extends TableIdFromSchema<Schema>
|
|
636
|
+
? Cell<Schema, JoinedTableId, JoinedCellId>
|
|
637
|
+
: Cell<any, any, any>)
|
|
638
|
+
| undefined;
|
|
384
639
|
};
|
|
385
640
|
|
|
386
641
|
/**
|
|
@@ -480,21 +735,38 @@ export type GetTableCell = {
|
|
|
480
735
|
* @category Definition
|
|
481
736
|
* @since v2.0.0
|
|
482
737
|
*/
|
|
483
|
-
export type Select
|
|
738
|
+
export type Select<
|
|
739
|
+
Schema extends OptionalTablesSchema,
|
|
740
|
+
RootTableId extends TableIdFromSchema<Schema>,
|
|
741
|
+
> = {
|
|
484
742
|
/**
|
|
485
743
|
* Calling this function with one Id parameter will indicate that the query
|
|
486
|
-
* should select the value of the specified Cell from the query's
|
|
744
|
+
* should select the value of the specified Cell from the query's root Table.
|
|
745
|
+
*
|
|
746
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
747
|
+
*
|
|
748
|
+
* ```ts override
|
|
749
|
+
* (cellId: Id): SelectedAs;
|
|
750
|
+
* ```
|
|
487
751
|
*
|
|
488
752
|
* @param cellId The Id of the Cell to fetch the value for.
|
|
489
753
|
* @returns A SelectedAs object so that the selected Cell Id can be optionally
|
|
490
754
|
* aliased.
|
|
491
755
|
*/
|
|
492
|
-
|
|
756
|
+
<RootCellId extends CellIdFromSchema<Schema, RootTableId>>(
|
|
757
|
+
cellId: RootCellId,
|
|
758
|
+
): SelectedAs;
|
|
493
759
|
/**
|
|
494
760
|
* Calling this function with two parameters will indicate that the query
|
|
495
761
|
* should select the value of the specified Cell from a Table that has been
|
|
496
762
|
* joined in the query.
|
|
497
763
|
*
|
|
764
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
765
|
+
*
|
|
766
|
+
* ```ts override
|
|
767
|
+
* (joinedTableId: Id, joinedCellId: Id): SelectedAs;
|
|
768
|
+
* ```
|
|
769
|
+
*
|
|
498
770
|
* @param joinedTableId The Id of the Table to fetch the value from. If the
|
|
499
771
|
* underlying Table was joined 'as' a different Id, that should instead be
|
|
500
772
|
* used.
|
|
@@ -502,11 +774,23 @@ export type Select = {
|
|
|
502
774
|
* @returns A SelectedAs object so that the selected Cell Id can be optionally
|
|
503
775
|
* aliased.
|
|
504
776
|
*/
|
|
505
|
-
|
|
777
|
+
<JoinedTableId extends TableIdFromSchema<Schema> | Id>(
|
|
778
|
+
joinedTableId: JoinedTableId,
|
|
779
|
+
joinedCellId: JoinedCellIdOrId<Schema, JoinedTableId>,
|
|
780
|
+
): SelectedAs;
|
|
506
781
|
/**
|
|
507
782
|
* Calling this function with one callback parameter will indicate that the
|
|
508
783
|
* query should select a calculated value, based on one or more Cell values in
|
|
509
|
-
* the
|
|
784
|
+
* the root Table or a joined Table, or on the root Table's Row Id.
|
|
785
|
+
*
|
|
786
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
787
|
+
*
|
|
788
|
+
* ```ts override
|
|
789
|
+
* (
|
|
790
|
+
* getCell: (getTableCell: GetTableCell, rowId: Id) => ResultCellOrUndefined,
|
|
791
|
+
* ): SelectedAs;
|
|
792
|
+
};
|
|
793
|
+
* ```
|
|
510
794
|
*
|
|
511
795
|
* @param getCell A callback that takes a GetTableCell function and the main
|
|
512
796
|
* Table's Row Id. These can be used to programmatically create a calculated
|
|
@@ -515,9 +799,13 @@ export type Select = {
|
|
|
515
799
|
* aliased.
|
|
516
800
|
*/
|
|
517
801
|
(
|
|
518
|
-
getCell: (
|
|
802
|
+
getCell: (
|
|
803
|
+
getTableCell: GetTableCell<Schema, RootTableId>,
|
|
804
|
+
rowId: Id,
|
|
805
|
+
) => ResultCellOrUndefined,
|
|
519
806
|
): SelectedAs;
|
|
520
807
|
};
|
|
808
|
+
|
|
521
809
|
/**
|
|
522
810
|
* The SelectedAs type describes an object returned from calling a Select
|
|
523
811
|
* function so that the selected Cell Id can be optionally aliased.
|
|
@@ -588,11 +876,11 @@ export type SelectedAs = {
|
|
|
588
876
|
* distant join Table.
|
|
589
877
|
*
|
|
590
878
|
* Because a Join clause is used to identify which unique Row Id of the joined
|
|
591
|
-
* Table will be joined to each Row of the
|
|
879
|
+
* Table will be joined to each Row of the root Table, queries follow the 'left
|
|
592
880
|
* join' semantics you may be familiar with from SQL. This means that an
|
|
593
881
|
* unfiltered query will only ever return the same number of Rows as the main
|
|
594
882
|
* Table being queried, and indeed the resulting table (assuming it has not been
|
|
595
|
-
* aggregated) will even preserve the
|
|
883
|
+
* aggregated) will even preserve the root Table's original Row Ids.
|
|
596
884
|
*
|
|
597
885
|
* @example
|
|
598
886
|
* This example shows a query that joins a single Table by using an Id present
|
|
@@ -630,7 +918,7 @@ export type SelectedAs = {
|
|
|
630
918
|
* This example shows a query that joins the same underlying Table twice, and
|
|
631
919
|
* aliases them (and the selected Cell Ids). Note the left-join semantics: Felix
|
|
632
920
|
* the cat was bought, but the seller was unknown. The record still exists in
|
|
633
|
-
* the
|
|
921
|
+
* the ResultTable.
|
|
634
922
|
*
|
|
635
923
|
* ```js
|
|
636
924
|
* const store = createStore()
|
|
@@ -663,7 +951,7 @@ export type SelectedAs = {
|
|
|
663
951
|
* ```
|
|
664
952
|
* @example
|
|
665
953
|
* This example shows a query that calculates the Id of the joined Table based
|
|
666
|
-
* from multiple values in the
|
|
954
|
+
* from multiple values in the root Table rather than a single Cell.
|
|
667
955
|
*
|
|
668
956
|
* ```js
|
|
669
957
|
* const store = createStore()
|
|
@@ -738,40 +1026,67 @@ export type SelectedAs = {
|
|
|
738
1026
|
* @category Definition
|
|
739
1027
|
* @since v2.0.0
|
|
740
1028
|
*/
|
|
741
|
-
export type Join
|
|
1029
|
+
export type Join<
|
|
1030
|
+
Schema extends OptionalTablesSchema,
|
|
1031
|
+
RootTableId extends TableIdFromSchema<Schema>,
|
|
1032
|
+
> = {
|
|
742
1033
|
/**
|
|
743
1034
|
* Calling this function with two Id parameters will indicate that the join to
|
|
744
1035
|
* a Row in an adjacent Table is made by finding its Id in a Cell of the
|
|
745
|
-
* query's
|
|
1036
|
+
* query's root Table.
|
|
1037
|
+
*
|
|
1038
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
1039
|
+
*
|
|
1040
|
+
* ```ts override
|
|
1041
|
+
* (joinedTableId: Id, on: Id): JoinedAs;
|
|
1042
|
+
* ```
|
|
746
1043
|
*
|
|
747
1044
|
* @param joinedTableId The Id of the Table to join to.
|
|
748
|
-
* @param on The Id of the Cell in the
|
|
1045
|
+
* @param on The Id of the Cell in the root Table that contains the joined
|
|
749
1046
|
* Table's Row Id.
|
|
750
1047
|
* @returns A JoinedAs object so that the joined Table Id can be optionally
|
|
751
1048
|
* aliased.
|
|
752
1049
|
*/
|
|
753
|
-
(
|
|
1050
|
+
(
|
|
1051
|
+
joinedTableId: TableIdFromSchema<Schema>,
|
|
1052
|
+
on: CellIdFromSchema<Schema, RootTableId>,
|
|
1053
|
+
): JoinedAs;
|
|
754
1054
|
/**
|
|
755
1055
|
* Calling this function with two parameters (where the second is a function)
|
|
756
1056
|
* will indicate that the join to a Row in an adjacent Table is made by
|
|
757
|
-
* calculating its Id from the Cells and the Row Id of the query's
|
|
1057
|
+
* calculating its Id from the Cells and the Row Id of the query's root Table.
|
|
1058
|
+
*
|
|
1059
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
1060
|
+
*
|
|
1061
|
+
* ```ts override
|
|
1062
|
+
* (
|
|
1063
|
+
* joinedTableId: Id,
|
|
1064
|
+
* on: (getCell: GetCell, rowId: Id) => Id | undefined,
|
|
1065
|
+
* ): JoinedAs;
|
|
1066
|
+
* ```
|
|
758
1067
|
*
|
|
759
1068
|
* @param joinedTableId The Id of the Table to join to.
|
|
760
|
-
* @param on A callback that takes a GetCell function and the
|
|
1069
|
+
* @param on A callback that takes a GetCell function and the root Table's Row
|
|
761
1070
|
* Id. These can be used to programmatically calculate the joined Table's Row
|
|
762
1071
|
* Id.
|
|
763
1072
|
* @returns A JoinedAs object so that the joined Table Id can be optionally
|
|
764
1073
|
* aliased.
|
|
765
1074
|
*/
|
|
766
1075
|
(
|
|
767
|
-
joinedTableId:
|
|
768
|
-
on: (getCell: GetCell, rowId: Id) => Id | undefined,
|
|
1076
|
+
joinedTableId: TableIdFromSchema<Schema>,
|
|
1077
|
+
on: (getCell: GetCell<Schema, RootTableId>, rowId: Id) => Id | undefined,
|
|
769
1078
|
): JoinedAs;
|
|
770
1079
|
/**
|
|
771
1080
|
* Calling this function with three Id parameters will indicate that the join
|
|
772
1081
|
* to a Row in distant Table is made by finding its Id in a Cell of an
|
|
773
1082
|
* intermediately joined Table.
|
|
774
1083
|
*
|
|
1084
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
1085
|
+
*
|
|
1086
|
+
* ```ts override
|
|
1087
|
+
* (joinedTableId: Id, fromIntermediateJoinedTableId: Id, on: Id): JoinedAs;
|
|
1088
|
+
* ```
|
|
1089
|
+
*
|
|
775
1090
|
* @param joinedTableId The Id of the distant Table to join to.
|
|
776
1091
|
* @param fromIntermediateJoinedTableId The Id of an intermediate Table (which
|
|
777
1092
|
* should have been in turn joined to the main query table via other Join
|
|
@@ -781,13 +1096,39 @@ export type Join = {
|
|
|
781
1096
|
* @returns A JoinedAs object so that the joined Table Id can be optionally
|
|
782
1097
|
* aliased.
|
|
783
1098
|
*/
|
|
784
|
-
|
|
1099
|
+
<
|
|
1100
|
+
IntermediateJoinedTableId extends TableIdFromSchema<Schema> | Id =
|
|
1101
|
+
| TableIdFromSchema<Schema>
|
|
1102
|
+
| Id,
|
|
1103
|
+
IntermediateJoinedCellId extends JoinedCellIdOrId<
|
|
1104
|
+
Schema,
|
|
1105
|
+
IntermediateJoinedTableId
|
|
1106
|
+
> = JoinedCellIdOrId<Schema, IntermediateJoinedTableId>,
|
|
1107
|
+
>(
|
|
1108
|
+
joinedTableId: TableIdFromSchema<Schema>,
|
|
1109
|
+
fromIntermediateJoinedTableId: IntermediateJoinedTableId,
|
|
1110
|
+
on: IntermediateJoinedCellId,
|
|
1111
|
+
): JoinedAs;
|
|
785
1112
|
/**
|
|
786
1113
|
* Calling this function with three parameters (where the third is a function)
|
|
787
1114
|
* will indicate that the join to a Row in distant Table is made by
|
|
788
1115
|
* calculating its Id from the Cells and the Row Id of an intermediately
|
|
789
1116
|
* joined Table.
|
|
790
1117
|
*
|
|
1118
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
1119
|
+
*
|
|
1120
|
+
* ```ts override
|
|
1121
|
+
* (
|
|
1122
|
+
* joinedTableId: Id,
|
|
1123
|
+
* fromIntermediateJoinedTableId: Id,
|
|
1124
|
+
* on: (
|
|
1125
|
+
* getIntermediateJoinedCell: GetCell,
|
|
1126
|
+
* intermediateJoinedRowId: Id,
|
|
1127
|
+
* ) => Id | undefined,
|
|
1128
|
+
* ): JoinedAs;
|
|
1129
|
+
};
|
|
1130
|
+
* ```
|
|
1131
|
+
*
|
|
791
1132
|
* @param joinedTableId The Id of the Table to join to.
|
|
792
1133
|
* @param fromIntermediateJoinedTableId The Id of an intermediate Table (which
|
|
793
1134
|
* should have been in turn joined to the main query table via other Join
|
|
@@ -798,15 +1139,24 @@ export type Join = {
|
|
|
798
1139
|
* @returns A JoinedAs object so that the joined Table Id can be optionally
|
|
799
1140
|
* aliased.
|
|
800
1141
|
*/
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
1142
|
+
<
|
|
1143
|
+
IntermediateJoinedTableId extends TableIdFromSchema<Schema> | Id =
|
|
1144
|
+
| TableIdFromSchema<Schema>
|
|
1145
|
+
| Id,
|
|
1146
|
+
>(
|
|
1147
|
+
joinedTableId: TableIdFromSchema<Schema>,
|
|
1148
|
+
fromIntermediateJoinedTableId: IntermediateJoinedTableId,
|
|
804
1149
|
on: (
|
|
805
|
-
|
|
806
|
-
|
|
1150
|
+
// prettier-ignore
|
|
1151
|
+
getIntermediateJoinedCell:
|
|
1152
|
+
IntermediateJoinedTableId extends TableIdFromSchema<Schema>
|
|
1153
|
+
? GetCell<Schema, IntermediateJoinedTableId>
|
|
1154
|
+
: GetCell<NoTablesSchema, Id>,
|
|
1155
|
+
intermediateJoinedRowId: Id,
|
|
807
1156
|
) => Id | undefined,
|
|
808
1157
|
): JoinedAs;
|
|
809
1158
|
};
|
|
1159
|
+
|
|
810
1160
|
/**
|
|
811
1161
|
* The JoinedAs type describes an object returned from calling a Join function
|
|
812
1162
|
* so that the joined Table Id can be optionally aliased.
|
|
@@ -815,6 +1165,9 @@ export type Join = {
|
|
|
815
1165
|
* create two joins to the same underlying Table, both _without_ aliases), only
|
|
816
1166
|
* the latter of two will be used in the query.
|
|
817
1167
|
*
|
|
1168
|
+
* For the purposes of clarity, it's recommended to use an alias that does not
|
|
1169
|
+
* collide with a real underlying Table (whether included in the query or not).
|
|
1170
|
+
*
|
|
818
1171
|
* @example
|
|
819
1172
|
* This example shows a query that joins the same underlying Table twice, for
|
|
820
1173
|
* different purposes. Both joins are aliased with the 'as' function to
|
|
@@ -852,17 +1205,22 @@ export type Join = {
|
|
|
852
1205
|
* @category Definition
|
|
853
1206
|
* @since v2.0.0
|
|
854
1207
|
*/
|
|
855
|
-
export type JoinedAs = {
|
|
1208
|
+
export type JoinedAs = {
|
|
1209
|
+
/**
|
|
1210
|
+
* A function that lets you specify an alias for the joined Table Id.
|
|
1211
|
+
*/
|
|
1212
|
+
as: (joinedTableId: Id) => void;
|
|
1213
|
+
};
|
|
856
1214
|
|
|
857
1215
|
/**
|
|
858
1216
|
* The Where type describes a function that lets you specify conditions to
|
|
859
|
-
* filter results, based on the underlying Cells of the
|
|
1217
|
+
* filter results, based on the underlying Cells of the root or joined Tables.
|
|
860
1218
|
*
|
|
861
1219
|
* The Where function is provided to the third `query` parameter of the
|
|
862
1220
|
* setQueryDefinition method.
|
|
863
1221
|
*
|
|
864
1222
|
* If you do not specify a Where clause, you should expect every non-empty Row
|
|
865
|
-
* of the
|
|
1223
|
+
* of the root Table to appear in the query's results.
|
|
866
1224
|
*
|
|
867
1225
|
* A Where condition has to be true for a Row to be included in the results.
|
|
868
1226
|
* Each Where class is additive, as though combined with a logical 'and'. If you
|
|
@@ -970,21 +1328,39 @@ export type JoinedAs = {as: (joinedTableId: Id) => void};
|
|
|
970
1328
|
* @category Definition
|
|
971
1329
|
* @since v2.0.0
|
|
972
1330
|
*/
|
|
973
|
-
export type Where
|
|
1331
|
+
export type Where<
|
|
1332
|
+
Schema extends OptionalTablesSchema,
|
|
1333
|
+
RootTableId extends TableIdFromSchema<Schema>,
|
|
1334
|
+
> = {
|
|
974
1335
|
/**
|
|
975
1336
|
* Calling this function with two parameters is used to include only those
|
|
976
|
-
* Rows for which a specified Cell in the query's
|
|
1337
|
+
* Rows for which a specified Cell in the query's root Table has a specified
|
|
977
1338
|
* value.
|
|
978
1339
|
*
|
|
979
|
-
*
|
|
1340
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
1341
|
+
*
|
|
1342
|
+
* ```ts override
|
|
1343
|
+
* (cellId: Id, equals: Cell): void;
|
|
1344
|
+
* ```
|
|
1345
|
+
*
|
|
1346
|
+
* @param cellId The Id of the Cell in the query's root Table to test.
|
|
980
1347
|
* @param equals The value that the Cell has to have for the Row to be
|
|
981
1348
|
* included in the result.
|
|
982
1349
|
*/
|
|
983
|
-
|
|
1350
|
+
<RootCellId extends CellIdFromSchema<Schema, RootTableId>>(
|
|
1351
|
+
cellId: RootCellId,
|
|
1352
|
+
equals: Cell<Schema, RootTableId, RootCellId>,
|
|
1353
|
+
): void;
|
|
984
1354
|
/**
|
|
985
1355
|
* Calling this function with three parameters is used to include only those
|
|
986
1356
|
* Rows for which a specified Cell in a joined Table has a specified value.
|
|
987
1357
|
*
|
|
1358
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
1359
|
+
*
|
|
1360
|
+
* ```ts override
|
|
1361
|
+
* (joinedTableId: Id, joinedCellId: Id, equals: Cell): void;
|
|
1362
|
+
* ```
|
|
1363
|
+
*
|
|
988
1364
|
* @param joinedTableId The Id of the joined Table to test a value in. If the
|
|
989
1365
|
* underlying Table was joined 'as' a different Id, that should instead be
|
|
990
1366
|
* used.
|
|
@@ -992,21 +1368,45 @@ export type Where = {
|
|
|
992
1368
|
* @param equals The value that the Cell has to have for the Row to be
|
|
993
1369
|
* included in the result.
|
|
994
1370
|
*/
|
|
995
|
-
|
|
1371
|
+
<
|
|
1372
|
+
JoinedTableId extends TableIdFromSchema<Schema> | Id,
|
|
1373
|
+
JoinedCellId extends JoinedCellIdOrId<
|
|
1374
|
+
Schema,
|
|
1375
|
+
JoinedTableId
|
|
1376
|
+
> = JoinedCellIdOrId<Schema, JoinedTableId>,
|
|
1377
|
+
JoinedCell extends Cell<Schema, JoinedTableId, JoinedCellId> = Cell<
|
|
1378
|
+
Schema,
|
|
1379
|
+
JoinedTableId,
|
|
1380
|
+
JoinedCellId
|
|
1381
|
+
>,
|
|
1382
|
+
>(
|
|
1383
|
+
joinedTableId: JoinedTableId,
|
|
1384
|
+
joinedCellId: JoinedCellId,
|
|
1385
|
+
equals: JoinedCell,
|
|
1386
|
+
): void;
|
|
996
1387
|
/**
|
|
997
1388
|
* Calling this function with one callback parameter is used to include only
|
|
998
1389
|
* those Rows which meet a calculated boolean condition, based on values in
|
|
999
1390
|
* the main and (optionally) joined Tables.
|
|
1000
1391
|
*
|
|
1392
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
1393
|
+
*
|
|
1394
|
+
* ```ts override
|
|
1395
|
+
* (condition: (getTableCell: GetTableCell) => boolean): void;
|
|
1396
|
+
};
|
|
1397
|
+
* ```
|
|
1398
|
+
*
|
|
1001
1399
|
* @param condition A callback that takes a GetTableCell function and that
|
|
1002
1400
|
* should return `true` for the Row to be included in the result.
|
|
1003
1401
|
*/
|
|
1004
|
-
(
|
|
1402
|
+
(
|
|
1403
|
+
condition: (getTableCell: GetTableCell<Schema, RootTableId>) => boolean,
|
|
1404
|
+
): void;
|
|
1005
1405
|
};
|
|
1006
1406
|
|
|
1007
1407
|
/**
|
|
1008
1408
|
* The Group type describes a function that lets you specify that the values of
|
|
1009
|
-
* a Cell in multiple
|
|
1409
|
+
* a Cell in multiple ResultRows should be aggregated together.
|
|
1010
1410
|
*
|
|
1011
1411
|
* The Group function is provided to the third `query` parameter of the
|
|
1012
1412
|
* setQueryDefinition method. When called, it should refer to a Cell Id (or
|
|
@@ -1046,7 +1446,7 @@ export type Where = {
|
|
|
1046
1446
|
* input values - for example, when a Row is added to the Table.
|
|
1047
1447
|
* @param aggregateRemove A function that can be used to optimize a custom
|
|
1048
1448
|
* Aggregate by providing a shortcut for when a single value is removed from the
|
|
1049
|
-
* input values - for example
|
|
1449
|
+
* input values - for example, when a Row is removed from the Table.
|
|
1050
1450
|
* @param aggregateReplace A function that can be used to optimize a custom
|
|
1051
1451
|
* Aggregate by providing a shortcut for when a single value in the input values
|
|
1052
1452
|
* is replaced with another - for example, when a Row is updated.
|
|
@@ -1183,6 +1583,7 @@ export type Group = (
|
|
|
1183
1583
|
aggregateRemove?: AggregateRemove,
|
|
1184
1584
|
aggregateReplace?: AggregateReplace,
|
|
1185
1585
|
) => GroupedAs;
|
|
1586
|
+
|
|
1186
1587
|
/**
|
|
1187
1588
|
* The GroupedAs type describes an object returned from calling a Group function
|
|
1188
1589
|
* so that the grouped Cell Id can be optionally aliased.
|
|
@@ -1221,7 +1622,12 @@ export type Group = (
|
|
|
1221
1622
|
* @category Definition
|
|
1222
1623
|
* @since v2.0.0
|
|
1223
1624
|
*/
|
|
1224
|
-
export type GroupedAs = {
|
|
1625
|
+
export type GroupedAs = {
|
|
1626
|
+
/**
|
|
1627
|
+
* A function that lets you specify an alias for the grouped Cell Id.
|
|
1628
|
+
*/
|
|
1629
|
+
as: (groupedCellId: Id) => void;
|
|
1630
|
+
};
|
|
1225
1631
|
|
|
1226
1632
|
/**
|
|
1227
1633
|
* The Having type describes a function that lets you specify conditions to
|
|
@@ -1314,14 +1720,14 @@ export type GroupedAs = {as: (groupedCellId: Id) => void};
|
|
|
1314
1720
|
export type Having = {
|
|
1315
1721
|
/**
|
|
1316
1722
|
* Calling this function with two parameters is used to include only those
|
|
1317
|
-
* Rows for which a specified Cell in the query's
|
|
1723
|
+
* Rows for which a specified Cell in the query's root Table has a specified
|
|
1318
1724
|
* value.
|
|
1319
1725
|
*
|
|
1320
1726
|
* @param selectedOrGroupedCellId The Id of the Cell in the query to test.
|
|
1321
1727
|
* @param equals The value that the Cell has to have for the Row to be
|
|
1322
1728
|
* included in the result.
|
|
1323
1729
|
*/
|
|
1324
|
-
(selectedOrGroupedCellId: Id, equals:
|
|
1730
|
+
(selectedOrGroupedCellId: Id, equals: ResultCell): void;
|
|
1325
1731
|
/**
|
|
1326
1732
|
* Calling this function with one callback parameter is used to include only
|
|
1327
1733
|
* those Rows which meet a calculated boolean condition.
|
|
@@ -1329,7 +1735,7 @@ export type Having = {
|
|
|
1329
1735
|
* @param condition A callback that takes a GetCell function and that should
|
|
1330
1736
|
* return `true` for the Row to be included in the result.
|
|
1331
1737
|
*/
|
|
1332
|
-
(condition: (getSelectedOrGroupedCell:
|
|
1738
|
+
(condition: (getSelectedOrGroupedCell: GetResultCell) => boolean): void;
|
|
1333
1739
|
};
|
|
1334
1740
|
|
|
1335
1741
|
/**
|
|
@@ -1429,16 +1835,32 @@ export type Having = {
|
|
|
1429
1835
|
* @category Queries
|
|
1430
1836
|
* @since v2.0.0
|
|
1431
1837
|
*/
|
|
1432
|
-
export interface Queries<Schemas extends OptionalSchemas
|
|
1838
|
+
export interface Queries<in out Schemas extends OptionalSchemas> {
|
|
1433
1839
|
/**
|
|
1434
1840
|
* The setQueryDefinition method lets you set the definition of a query.
|
|
1435
1841
|
*
|
|
1842
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
1843
|
+
*
|
|
1844
|
+
* ```ts override
|
|
1845
|
+
* setQueryDefinition(
|
|
1846
|
+
* queryId: Id,
|
|
1847
|
+
* tableId: Id,
|
|
1848
|
+
* query: (keywords: {
|
|
1849
|
+
* select: Select;
|
|
1850
|
+
* join: Join;
|
|
1851
|
+
* where: Where;
|
|
1852
|
+
* group: Group;
|
|
1853
|
+
* having: Having;
|
|
1854
|
+
* }) => void,
|
|
1855
|
+
* ): Queries;
|
|
1856
|
+
* ```
|
|
1857
|
+
*
|
|
1436
1858
|
* Every query definition is identified by a unique Id, and if you re-use an
|
|
1437
1859
|
* existing Id with this method, the previous definition is overwritten.
|
|
1438
1860
|
*
|
|
1439
|
-
* A query provides a tabular result formed from each Row within a
|
|
1440
|
-
* The definition must specify this
|
|
1441
|
-
*
|
|
1861
|
+
* A query provides a tabular result formed from each Row within a root Table.
|
|
1862
|
+
* The definition must specify this Table (by its Id) to be aggregated. Other
|
|
1863
|
+
* Tables can be joined to that using Join clauses.
|
|
1442
1864
|
*
|
|
1443
1865
|
* The third `query` parameter is a callback that you provide to define the
|
|
1444
1866
|
* query. That callback is provided with a `keywords` object that contains the
|
|
@@ -1454,7 +1876,7 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
1454
1876
|
* filter results, based on the underlying Cells of the main or joined
|
|
1455
1877
|
* Tables.
|
|
1456
1878
|
* - The Group type describes a function that lets you specify that the values
|
|
1457
|
-
* of a Cell in multiple
|
|
1879
|
+
* of a Cell in multiple ResultRows should be aggregated together.
|
|
1458
1880
|
* - The Having type describes a function that lets you specify conditions to
|
|
1459
1881
|
* filter results, based on the grouped Cells resulting from a Group clause.
|
|
1460
1882
|
*
|
|
@@ -1465,7 +1887,7 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
1465
1887
|
* addResultSortedRowIdsListener method to sort and paginate the results.
|
|
1466
1888
|
*
|
|
1467
1889
|
* @param queryId The Id of the query to define.
|
|
1468
|
-
* @param tableId The Id of the
|
|
1890
|
+
* @param tableId The Id of the root Table the query will be based on.
|
|
1469
1891
|
* @param query A callback which can take a `keywords` object and which uses
|
|
1470
1892
|
the functions it contains to define the query.
|
|
1471
1893
|
* @returns A reference to the Queries object.
|
|
@@ -1493,13 +1915,13 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
1493
1915
|
* @category Configuration
|
|
1494
1916
|
* @since v2.0.0
|
|
1495
1917
|
*/
|
|
1496
|
-
setQueryDefinition(
|
|
1918
|
+
setQueryDefinition<RootTableId extends TableIdFromSchema<Schemas[0]>>(
|
|
1497
1919
|
queryId: Id,
|
|
1498
|
-
tableId:
|
|
1920
|
+
tableId: RootTableId,
|
|
1499
1921
|
query: (keywords: {
|
|
1500
|
-
select: Select
|
|
1501
|
-
join: Join
|
|
1502
|
-
where: Where
|
|
1922
|
+
select: Select<Schemas[0], RootTableId>;
|
|
1923
|
+
join: Join<Schemas[0], RootTableId>;
|
|
1924
|
+
where: Where<Schemas[0], RootTableId>;
|
|
1503
1925
|
group: Group;
|
|
1504
1926
|
having: Having;
|
|
1505
1927
|
}) => void,
|
|
@@ -1508,6 +1930,12 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
1508
1930
|
/**
|
|
1509
1931
|
* The delQueryDefinition method removes an existing query definition.
|
|
1510
1932
|
*
|
|
1933
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
1934
|
+
*
|
|
1935
|
+
* ```ts override
|
|
1936
|
+
* delQueryDefinition(queryId: Id): Queries;
|
|
1937
|
+
* ```
|
|
1938
|
+
*
|
|
1511
1939
|
* @param queryId The Id of the query to remove.
|
|
1512
1940
|
* @returns A reference to the Queries object.
|
|
1513
1941
|
* @example
|
|
@@ -1542,6 +1970,12 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
1542
1970
|
* The getStore method returns a reference to the underlying Store that is
|
|
1543
1971
|
* backing this Queries object.
|
|
1544
1972
|
*
|
|
1973
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
1974
|
+
*
|
|
1975
|
+
* ```ts override
|
|
1976
|
+
* getStore(): Store;
|
|
1977
|
+
* ```
|
|
1978
|
+
*
|
|
1545
1979
|
* @returns A reference to the Store.
|
|
1546
1980
|
* @example
|
|
1547
1981
|
* This example creates a Queries object against a newly-created Store and
|
|
@@ -1659,6 +2093,12 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
1659
2093
|
* The getTableId method returns the Id of the underlying Table that is
|
|
1660
2094
|
* backing a query.
|
|
1661
2095
|
*
|
|
2096
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
2097
|
+
*
|
|
2098
|
+
* ```ts override
|
|
2099
|
+
* getTableId(queryId: Id): Id | undefined;
|
|
2100
|
+
* ```
|
|
2101
|
+
*
|
|
1662
2102
|
* If the query Id is invalid, the method returns `undefined`.
|
|
1663
2103
|
*
|
|
1664
2104
|
* @param queryId The Id of a query.
|
|
@@ -1686,11 +2126,13 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
1686
2126
|
* @category Getter
|
|
1687
2127
|
* @since v2.0.0
|
|
1688
2128
|
*/
|
|
1689
|
-
getTableId
|
|
2129
|
+
getTableId<TableId extends TableIdFromSchema<Schemas[0]>>(
|
|
2130
|
+
queryId: Id,
|
|
2131
|
+
): TableId | undefined;
|
|
1690
2132
|
|
|
1691
2133
|
/**
|
|
1692
2134
|
* The getResultTable method returns an object containing the entire data of
|
|
1693
|
-
* the
|
|
2135
|
+
* the ResultTable of the given query.
|
|
1694
2136
|
*
|
|
1695
2137
|
* This has the same behavior as a Store's getTable method. For example, if
|
|
1696
2138
|
* the query Id is invalid, the method returns an empty object. Similarly, it
|
|
@@ -1699,13 +2141,13 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
1699
2141
|
* themselves.
|
|
1700
2142
|
*
|
|
1701
2143
|
* @param queryId The Id of a query.
|
|
1702
|
-
* @returns An object containing the entire data of the
|
|
2144
|
+
* @returns An object containing the entire data of the ResultTable of the
|
|
1703
2145
|
* query.
|
|
1704
|
-
* @returns The result of the query, structured as a
|
|
2146
|
+
* @returns The result of the query, structured as a ResultTable.
|
|
1705
2147
|
* @example
|
|
1706
2148
|
* This example creates a Queries object, a single query definition, and then
|
|
1707
2149
|
* calls this method on it (as well as a non-existent definition) to get the
|
|
1708
|
-
*
|
|
2150
|
+
* ResultTable.
|
|
1709
2151
|
*
|
|
1710
2152
|
* ```js
|
|
1711
2153
|
* const store = createStore().setTable('pets', {
|
|
@@ -1732,11 +2174,11 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
1732
2174
|
* @category Result
|
|
1733
2175
|
* @since v2.0.0
|
|
1734
2176
|
*/
|
|
1735
|
-
getResultTable(queryId: Id):
|
|
2177
|
+
getResultTable(queryId: Id): ResultTable;
|
|
1736
2178
|
|
|
1737
2179
|
/**
|
|
1738
|
-
* The getResultRowIds method returns the Ids of every
|
|
1739
|
-
* of the given query.
|
|
2180
|
+
* The getResultRowIds method returns the Ids of every ResultRow in the
|
|
2181
|
+
* ResultTable of the given query.
|
|
1740
2182
|
*
|
|
1741
2183
|
* This has the same behavior as a Store's getRowIds method. For example, if
|
|
1742
2184
|
* the query Id is invalid, the method returns an empty array. Similarly, it
|
|
@@ -1744,11 +2186,11 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
1744
2186
|
* made to the list object are not made to the query results themselves.
|
|
1745
2187
|
*
|
|
1746
2188
|
* @param queryId The Id of a query.
|
|
1747
|
-
* @returns An array of the Ids of every
|
|
2189
|
+
* @returns An array of the Ids of every ResultRow in the result of the query.
|
|
1748
2190
|
* @example
|
|
1749
2191
|
* This example creates a Queries object, a single query definition, and then
|
|
1750
2192
|
* calls this method on it (as well as a non-existent definition) to get the
|
|
1751
|
-
*
|
|
2193
|
+
* ResultRow Ids.
|
|
1752
2194
|
*
|
|
1753
2195
|
* ```js
|
|
1754
2196
|
* const store = createStore().setTable('pets', {
|
|
@@ -1778,37 +2220,37 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
1778
2220
|
getResultRowIds(queryId: Id): Ids;
|
|
1779
2221
|
|
|
1780
2222
|
/**
|
|
1781
|
-
* The getResultSortedRowIds method returns the Ids of every
|
|
1782
|
-
*
|
|
1783
|
-
*
|
|
2223
|
+
* The getResultSortedRowIds method returns the Ids of every ResultRow in the
|
|
2224
|
+
* ResultTable of the given query, sorted according to the values in a
|
|
2225
|
+
* specified ResultCell.
|
|
1784
2226
|
*
|
|
1785
2227
|
* This has the same behavior as a Store's getSortedRowIds method. For
|
|
1786
2228
|
* example, if the query Id is invalid, the method returns an empty array.
|
|
1787
2229
|
* Similarly, the sorting of the rows is alphanumeric, and you can indicate
|
|
1788
2230
|
* whether it should be in descending order. The `offset` and `limit`
|
|
1789
2231
|
* parameters are used to paginate results, but default to `0` and `undefined`
|
|
1790
|
-
* to return all available
|
|
2232
|
+
* to return all available ResultRow Ids if not specified.
|
|
1791
2233
|
*
|
|
1792
2234
|
* Note that every call to this method will perform the sorting afresh - there
|
|
1793
2235
|
* is no caching of the results - and so you are advised to memoize the
|
|
1794
|
-
* results yourself, especially when the
|
|
1795
|
-
* performant approach to tracking the sorted
|
|
1796
|
-
* the addResultSortedRowIdsListener method.
|
|
2236
|
+
* results yourself, especially when the ResultTable is large. For a
|
|
2237
|
+
* performant approach to tracking the sorted ResultRow Ids when they change,
|
|
2238
|
+
* use the addResultSortedRowIdsListener method.
|
|
1797
2239
|
*
|
|
1798
2240
|
* @param queryId The Id of a query.
|
|
1799
|
-
* @param cellId The Id of the
|
|
1800
|
-
* `undefined` to by sort the
|
|
2241
|
+
* @param cellId The Id of the ResultCell whose values are used for the
|
|
2242
|
+
* sorting, or `undefined` to by sort the ResultRow Id itself.
|
|
1801
2243
|
* @param descending Whether the sorting should be in descending order.
|
|
1802
|
-
* @param offset The number of
|
|
1803
|
-
* any.
|
|
1804
|
-
* @param limit The maximum number of
|
|
1805
|
-
* all.
|
|
1806
|
-
* @returns An array of the sorted Ids of every
|
|
2244
|
+
* @param offset The number of ResultRow Ids to skip for pagination purposes,
|
|
2245
|
+
* if any.
|
|
2246
|
+
* @param limit The maximum number of ResultRow Ids to return, or `undefined`
|
|
2247
|
+
* for all.
|
|
2248
|
+
* @returns An array of the sorted Ids of every ResultRow in the result of the
|
|
1807
2249
|
* query.
|
|
1808
2250
|
* @example
|
|
1809
2251
|
* This example creates a Queries object, a single query definition, and then
|
|
1810
2252
|
* calls this method on it (as well as a non-existent definition) to get the
|
|
1811
|
-
*
|
|
2253
|
+
* ResultRow Ids.
|
|
1812
2254
|
*
|
|
1813
2255
|
* ```js
|
|
1814
2256
|
* const store = createStore().setTable('pets', {
|
|
@@ -1845,22 +2287,22 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
1845
2287
|
|
|
1846
2288
|
/**
|
|
1847
2289
|
* The getResultRow method returns an object containing the entire data of a
|
|
1848
|
-
* single
|
|
2290
|
+
* single ResultRow in the ResultTable of the given query.
|
|
1849
2291
|
*
|
|
1850
2292
|
* This has the same behavior as a Store's getRow method. For example, if the
|
|
1851
|
-
* query or
|
|
1852
|
-
* it returns a copy of, rather than a reference to the underlying
|
|
1853
|
-
* changes made to the returned object are not made to the query
|
|
1854
|
-
* themselves.
|
|
2293
|
+
* query or ResultRow Id is invalid, the method returns an empty object.
|
|
2294
|
+
* Similarly, it returns a copy of, rather than a reference to the underlying
|
|
2295
|
+
* data, so changes made to the returned object are not made to the query
|
|
2296
|
+
* results themselves.
|
|
1855
2297
|
*
|
|
1856
2298
|
* @param queryId The Id of a query.
|
|
1857
|
-
* @param rowId The Id of the
|
|
1858
|
-
* @returns An object containing the entire data of the
|
|
1859
|
-
*
|
|
2299
|
+
* @param rowId The Id of the ResultRow in the ResultTable.
|
|
2300
|
+
* @returns An object containing the entire data of the ResultRow in the
|
|
2301
|
+
* ResultTable of the query.
|
|
1860
2302
|
* @example
|
|
1861
2303
|
* This example creates a Queries object, a single query definition, and then
|
|
1862
|
-
* calls this method on it (as well as a non-existent
|
|
1863
|
-
*
|
|
2304
|
+
* calls this method on it (as well as a non-existent ResultRow Id) to get
|
|
2305
|
+
* the ResultRow.
|
|
1864
2306
|
*
|
|
1865
2307
|
* ```js
|
|
1866
2308
|
* const store = createStore().setTable('pets', {
|
|
@@ -1887,26 +2329,26 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
1887
2329
|
* @category Result
|
|
1888
2330
|
* @since v2.0.0
|
|
1889
2331
|
*/
|
|
1890
|
-
getResultRow(queryId: Id, rowId: Id):
|
|
2332
|
+
getResultRow(queryId: Id, rowId: Id): ResultRow;
|
|
1891
2333
|
|
|
1892
2334
|
/**
|
|
1893
|
-
* The getResultCellIds method returns the Ids of every
|
|
1894
|
-
* in the
|
|
2335
|
+
* The getResultCellIds method returns the Ids of every ResultCell in a given
|
|
2336
|
+
* ResultRow, in the ResultTable of the given query.
|
|
1895
2337
|
*
|
|
1896
2338
|
* This has the same behavior as a Store's getCellIds method. For example, if
|
|
1897
|
-
* the query Id or
|
|
2339
|
+
* the query Id or ResultRow Id is invalid, the method returns an empty array.
|
|
1898
2340
|
* Similarly, it returns a copy of, rather than a reference to the list of
|
|
1899
2341
|
* Ids, so changes made to the list object are not made to the query results
|
|
1900
2342
|
* themselves.
|
|
1901
2343
|
*
|
|
1902
2344
|
* @param queryId The Id of a query.
|
|
1903
|
-
* @param rowId The Id of the
|
|
1904
|
-
* @returns An array of the Ids of every
|
|
1905
|
-
* query.
|
|
2345
|
+
* @param rowId The Id of the ResultRow in the ResultTable.
|
|
2346
|
+
* @returns An array of the Ids of every ResultCell in the ResultRow in the
|
|
2347
|
+
* result of the query.
|
|
1906
2348
|
* @example
|
|
1907
2349
|
* This example creates a Queries object, a single query definition, and then
|
|
1908
|
-
* calls this method on it (as well as a non-existent
|
|
1909
|
-
*
|
|
2350
|
+
* calls this method on it (as well as a non-existent ResultRow Id) to get the
|
|
2351
|
+
* ResultCell Ids.
|
|
1910
2352
|
*
|
|
1911
2353
|
* ```js
|
|
1912
2354
|
* const store = createStore().setTable('pets', {
|
|
@@ -1936,20 +2378,21 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
1936
2378
|
getResultCellIds(queryId: Id, rowId: Id): Ids;
|
|
1937
2379
|
|
|
1938
2380
|
/**
|
|
1939
|
-
* The getResultCell method returns the value of a single
|
|
1940
|
-
* in the
|
|
2381
|
+
* The getResultCell method returns the value of a single ResultCell in a
|
|
2382
|
+
* given ResultRow, in the ResultTable of the given query.
|
|
1941
2383
|
*
|
|
1942
2384
|
* This has the same behavior as a Store's getCell method. For example, if the
|
|
1943
|
-
* query, or
|
|
2385
|
+
* query, or ResultRow, or ResultCell Id is invalid, the method returns
|
|
2386
|
+
* `undefined`.
|
|
1944
2387
|
*
|
|
1945
2388
|
* @param queryId The Id of a query.
|
|
1946
|
-
* @param rowId The Id of the
|
|
1947
|
-
* @param cellId The Id of the
|
|
1948
|
-
* @returns The value of the
|
|
2389
|
+
* @param rowId The Id of the ResultRow in the ResultTable.
|
|
2390
|
+
* @param cellId The Id of the ResultCell in the ResultRow.
|
|
2391
|
+
* @returns The value of the ResultCell, or `undefined`.
|
|
1949
2392
|
* @example
|
|
1950
2393
|
* This example creates a Queries object, a single query definition, and then
|
|
1951
|
-
* calls this method on it (as well as a non-existent
|
|
1952
|
-
*
|
|
2394
|
+
* calls this method on it (as well as a non-existent ResultCell Id) to get
|
|
2395
|
+
* the ResultCell.
|
|
1953
2396
|
*
|
|
1954
2397
|
* ```js
|
|
1955
2398
|
* const store = createStore().setTable('pets', {
|
|
@@ -1976,16 +2419,16 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
1976
2419
|
* @category Result
|
|
1977
2420
|
* @since v2.0.0
|
|
1978
2421
|
*/
|
|
1979
|
-
getResultCell(queryId: Id, rowId: Id, cellId: Id):
|
|
2422
|
+
getResultCell(queryId: Id, rowId: Id, cellId: Id): ResultCellOrUndefined;
|
|
1980
2423
|
|
|
1981
2424
|
/**
|
|
1982
2425
|
* The hasResultTable method returns a boolean indicating whether a given
|
|
1983
|
-
*
|
|
2426
|
+
* ResultTable exists.
|
|
1984
2427
|
*
|
|
1985
2428
|
* @param queryId The Id of a possible query.
|
|
1986
|
-
* @returns Whether a
|
|
2429
|
+
* @returns Whether a ResultTable for that query Id exists.
|
|
1987
2430
|
* @example
|
|
1988
|
-
* This example shows two simple
|
|
2431
|
+
* This example shows two simple ResultTable existence checks.
|
|
1989
2432
|
*
|
|
1990
2433
|
* ```js
|
|
1991
2434
|
* const store = createStore().setTable('pets', {
|
|
@@ -2014,14 +2457,14 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
2014
2457
|
hasResultTable(queryId: Id): boolean;
|
|
2015
2458
|
|
|
2016
2459
|
/**
|
|
2017
|
-
* The hasResultRow method returns a boolean indicating whether a given
|
|
2018
|
-
*
|
|
2460
|
+
* The hasResultRow method returns a boolean indicating whether a given
|
|
2461
|
+
* ResultRow exists.
|
|
2019
2462
|
*
|
|
2020
2463
|
* @param queryId The Id of a possible query.
|
|
2021
|
-
* @param rowId The Id of a possible
|
|
2022
|
-
* @returns Whether a
|
|
2464
|
+
* @param rowId The Id of a possible ResultRow.
|
|
2465
|
+
* @returns Whether a ResultRow for that Id exists.
|
|
2023
2466
|
* @example
|
|
2024
|
-
* This example shows two simple
|
|
2467
|
+
* This example shows two simple ResultRow existence checks.
|
|
2025
2468
|
*
|
|
2026
2469
|
* ```js
|
|
2027
2470
|
* const store = createStore().setTable('pets', {
|
|
@@ -2051,14 +2494,14 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
2051
2494
|
|
|
2052
2495
|
/**
|
|
2053
2496
|
* The hasResultCell method returns a boolean indicating whether a given
|
|
2054
|
-
*
|
|
2497
|
+
* ResultCell exists.
|
|
2055
2498
|
*
|
|
2056
2499
|
* @param queryId The Id of a possible query.
|
|
2057
|
-
* @param rowId The Id of a possible
|
|
2058
|
-
* @param cellId The Id of a possible
|
|
2059
|
-
* @returns Whether a
|
|
2500
|
+
* @param rowId The Id of a possible ResultRow.
|
|
2501
|
+
* @param cellId The Id of a possible ResultCell.
|
|
2502
|
+
* @returns Whether a ResultCell for that Id exists.
|
|
2060
2503
|
* @example
|
|
2061
|
-
* This example shows two simple
|
|
2504
|
+
* This example shows two simple ResultRow existence checks.
|
|
2062
2505
|
*
|
|
2063
2506
|
* ```js
|
|
2064
2507
|
* const store = createStore().setTable('pets', {
|
|
@@ -2088,18 +2531,18 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
2088
2531
|
|
|
2089
2532
|
/**
|
|
2090
2533
|
* The forEachResultTable method takes a function that it will then call for
|
|
2091
|
-
* each
|
|
2534
|
+
* each ResultTable in the Queries object.
|
|
2092
2535
|
*
|
|
2093
|
-
* This method is useful for iterating over all the
|
|
2536
|
+
* This method is useful for iterating over all the ResultTables of the
|
|
2094
2537
|
* queries in a functional style. The `tableCallback` parameter is a
|
|
2095
|
-
*
|
|
2096
|
-
*
|
|
2097
|
-
* of the
|
|
2538
|
+
* ResultTableCallback function that will be called with the Id of each
|
|
2539
|
+
* ResultTable, and with a function that can then be used to iterate over each
|
|
2540
|
+
* ResultRow of the ResultTable, should you wish.
|
|
2098
2541
|
*
|
|
2099
2542
|
* @param tableCallback The function that should be called for every query's
|
|
2100
|
-
*
|
|
2543
|
+
* ResultTable.
|
|
2101
2544
|
* @example
|
|
2102
|
-
* This example iterates over each query's
|
|
2545
|
+
* This example iterates over each query's ResultTable in a Queries object.
|
|
2103
2546
|
*
|
|
2104
2547
|
* ```js
|
|
2105
2548
|
* const store = createStore().setTable('pets', {
|
|
@@ -2131,23 +2574,23 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
2131
2574
|
* @category Iterator
|
|
2132
2575
|
* @since v2.0.0
|
|
2133
2576
|
*/
|
|
2134
|
-
forEachResultTable(tableCallback:
|
|
2577
|
+
forEachResultTable(tableCallback: ResultTableCallback): void;
|
|
2135
2578
|
|
|
2136
2579
|
/**
|
|
2137
2580
|
* The forEachResultRow method takes a function that it will then call for
|
|
2138
|
-
* each
|
|
2581
|
+
* each ResultRow in the ResultTable of a query.
|
|
2139
2582
|
*
|
|
2140
|
-
* This method is useful for iterating over each
|
|
2141
|
-
* the query in a functional style. The `rowCallback` parameter is a
|
|
2142
|
-
*
|
|
2143
|
-
* and with a function that can then be used to iterate over each
|
|
2144
|
-
*
|
|
2583
|
+
* This method is useful for iterating over each ResultRow of the ResultTable
|
|
2584
|
+
* of the query in a functional style. The `rowCallback` parameter is a
|
|
2585
|
+
* ResultRowCallback function that will be called with the Id of each
|
|
2586
|
+
* ResultRow, and with a function that can then be used to iterate over each
|
|
2587
|
+
* ResultCell of the ResultRow, should you wish.
|
|
2145
2588
|
*
|
|
2146
2589
|
* @param queryId The Id of a query.
|
|
2147
|
-
* @param rowCallback The function that should be called for every
|
|
2148
|
-
* query's
|
|
2590
|
+
* @param rowCallback The function that should be called for every ResultRow
|
|
2591
|
+
* of the query's ResultTable.
|
|
2149
2592
|
* @example
|
|
2150
|
-
* This example iterates over each
|
|
2593
|
+
* This example iterates over each ResultRow in a query's ResultTable.
|
|
2151
2594
|
*
|
|
2152
2595
|
* ```js
|
|
2153
2596
|
* const store = createStore().setTable('pets', {
|
|
@@ -2177,22 +2620,23 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
2177
2620
|
* @category Iterator
|
|
2178
2621
|
* @since v2.0.0
|
|
2179
2622
|
*/
|
|
2180
|
-
forEachResultRow(queryId: Id, rowCallback:
|
|
2623
|
+
forEachResultRow(queryId: Id, rowCallback: ResultRowCallback): void;
|
|
2181
2624
|
|
|
2182
2625
|
/**
|
|
2183
2626
|
* The forEachResultCell method takes a function that it will then call for
|
|
2184
|
-
* each
|
|
2627
|
+
* each ResultCell in the ResultRow of a query.
|
|
2185
2628
|
*
|
|
2186
|
-
* This method is useful for iterating over each
|
|
2187
|
-
* query in a functional style. The `cellCallback` parameter is a
|
|
2188
|
-
* function that will be called with the Id and value of
|
|
2629
|
+
* This method is useful for iterating over each ResultCell of the ResultRow
|
|
2630
|
+
* of the query in a functional style. The `cellCallback` parameter is a
|
|
2631
|
+
* ResultCellCallback function that will be called with the Id and value of
|
|
2632
|
+
* each ResultCell.
|
|
2189
2633
|
*
|
|
2190
2634
|
* @param queryId The Id of a query.
|
|
2191
|
-
* @param rowId The Id of a
|
|
2192
|
-
* @param cellCallback The function that should be called for every
|
|
2193
|
-
* the query's
|
|
2635
|
+
* @param rowId The Id of a ResultRow in the query's ResultTable.
|
|
2636
|
+
* @param cellCallback The function that should be called for every ResultCell
|
|
2637
|
+
* of the query's ResultRow.
|
|
2194
2638
|
* @example
|
|
2195
|
-
* This example iterates over each
|
|
2639
|
+
* This example iterates over each ResultCell in a query's ResultRow.
|
|
2196
2640
|
*
|
|
2197
2641
|
* ```js
|
|
2198
2642
|
* const store = createStore().setTable('pets', {
|
|
@@ -2220,28 +2664,38 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
2220
2664
|
* @category Iterator
|
|
2221
2665
|
* @since v2.0.0
|
|
2222
2666
|
*/
|
|
2223
|
-
forEachResultCell(
|
|
2667
|
+
forEachResultCell(
|
|
2668
|
+
queryId: Id,
|
|
2669
|
+
rowId: Id,
|
|
2670
|
+
cellCallback: ResultCellCallback,
|
|
2671
|
+
): void;
|
|
2224
2672
|
|
|
2225
2673
|
/**
|
|
2226
2674
|
* The addResultTableListener method registers a listener function with the
|
|
2227
|
-
* Queries object that will be called whenever data in a
|
|
2675
|
+
* Queries object that will be called whenever data in a ResultTable changes.
|
|
2676
|
+
*
|
|
2677
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
2678
|
+
*
|
|
2679
|
+
* ```ts override
|
|
2680
|
+
* addResultTableListener(queryId: IdOrNull, listener: ResultTableListener): Id;
|
|
2681
|
+
* ```
|
|
2228
2682
|
*
|
|
2229
2683
|
* The provided listener is a ResultTableListener function, and will be called
|
|
2230
|
-
* with a reference to the Queries object, the Id of the
|
|
2231
|
-
* (which is also the query Id), and a
|
|
2232
|
-
* to inspect any changes that occurred.
|
|
2684
|
+
* with a reference to the Queries object, the Id of the ResultTable that
|
|
2685
|
+
* changed (which is also the query Id), and a GetCellResultChange function in
|
|
2686
|
+
* case you need to inspect any changes that occurred.
|
|
2233
2687
|
*
|
|
2234
|
-
* You can either listen to a single
|
|
2235
|
-
* the method's first parameter) or changes to any
|
|
2236
|
-
*
|
|
2688
|
+
* You can either listen to a single ResultTable (by specifying a query Id as
|
|
2689
|
+
* the method's first parameter) or changes to any ResultTable (by providing a
|
|
2690
|
+
* `null` wildcard).
|
|
2237
2691
|
*
|
|
2238
2692
|
* @param queryId The Id of the query to listen to, or `null` as a wildcard.
|
|
2239
2693
|
* @param listener The function that will be called whenever data in the
|
|
2240
|
-
* matching
|
|
2694
|
+
* matching ResultTable changes.
|
|
2241
2695
|
* @returns A unique Id for the listener that can later be used to remove it.
|
|
2242
2696
|
* @example
|
|
2243
2697
|
* This example registers a listener that responds to any changes to a
|
|
2244
|
-
* specific
|
|
2698
|
+
* specific ResultTable.
|
|
2245
2699
|
*
|
|
2246
2700
|
* ```js
|
|
2247
2701
|
* const store = createStore().setTable('pets', {
|
|
@@ -2275,7 +2729,7 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
2275
2729
|
* ```
|
|
2276
2730
|
* @example
|
|
2277
2731
|
* This example registers a listener that responds to any changes to any
|
|
2278
|
-
*
|
|
2732
|
+
* ResultTable.
|
|
2279
2733
|
*
|
|
2280
2734
|
* ```js
|
|
2281
2735
|
* const store = createStore().setTable('pets', {
|
|
@@ -2311,32 +2765,44 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
2311
2765
|
* @category Listener
|
|
2312
2766
|
* @since v2.0.0
|
|
2313
2767
|
*/
|
|
2314
|
-
addResultTableListener(
|
|
2768
|
+
addResultTableListener(
|
|
2769
|
+
queryId: IdOrNull,
|
|
2770
|
+
listener: ResultTableListener<Schemas>,
|
|
2771
|
+
): Id;
|
|
2315
2772
|
|
|
2316
2773
|
/**
|
|
2317
2774
|
* The addResultRowIdsListener method registers a listener function with the
|
|
2318
|
-
* Queries object that will be called whenever the
|
|
2319
|
-
* change.
|
|
2775
|
+
* Queries object that will be called whenever the ResultRow Ids in a
|
|
2776
|
+
* ResultTable change.
|
|
2777
|
+
*
|
|
2778
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
2779
|
+
*
|
|
2780
|
+
* ```ts override
|
|
2781
|
+
* addResultRowIdsListener(
|
|
2782
|
+
* queryId: IdOrNull,
|
|
2783
|
+
* listener: ResultRowIdsListener,
|
|
2784
|
+
* ): Id;
|
|
2785
|
+
* ```
|
|
2320
2786
|
*
|
|
2321
2787
|
* The provided listener is a ResultRowIdsListener function, and will be
|
|
2322
|
-
* called with a reference to the Queries object and the Id of the
|
|
2323
|
-
* changed (which is also the query Id).
|
|
2788
|
+
* called with a reference to the Queries object and the Id of the ResultTable
|
|
2789
|
+
* that changed (which is also the query Id).
|
|
2324
2790
|
*
|
|
2325
|
-
* By default, such a listener is only called when a
|
|
2326
|
-
* removed from, the
|
|
2327
|
-
*
|
|
2791
|
+
* By default, such a listener is only called when a ResultRow is added to, or
|
|
2792
|
+
* removed from, the ResultTable. To listen to all changes in the ResultTable,
|
|
2793
|
+
* use the addResultTableListener method.
|
|
2328
2794
|
*
|
|
2329
|
-
* You can either listen to a single
|
|
2330
|
-
* the method's first parameter) or changes to any
|
|
2331
|
-
*
|
|
2795
|
+
* You can either listen to a single ResultTable (by specifying a query Id as
|
|
2796
|
+
* the method's first parameter) or changes to any ResultTable (by providing a
|
|
2797
|
+
* `null` wildcard).
|
|
2332
2798
|
*
|
|
2333
2799
|
* @param queryId The Id of the query to listen to, or `null` as a wildcard.
|
|
2334
|
-
* @param listener The function that will be called whenever the
|
|
2335
|
-
* the
|
|
2800
|
+
* @param listener The function that will be called whenever the ResultRow Ids
|
|
2801
|
+
* in the ResultTable change.
|
|
2336
2802
|
* @returns A unique Id for the listener that can later be used to remove it.
|
|
2337
2803
|
* @example
|
|
2338
|
-
* This example registers a listener that responds to any change to the
|
|
2339
|
-
* Ids of a specific
|
|
2804
|
+
* This example registers a listener that responds to any change to the
|
|
2805
|
+
* ResultRow Ids of a specific ResultTable.
|
|
2340
2806
|
*
|
|
2341
2807
|
* ```js
|
|
2342
2808
|
* const store = createStore().setTable('pets', {
|
|
@@ -2369,8 +2835,8 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
2369
2835
|
* store.delListener(listenerId);
|
|
2370
2836
|
* ```
|
|
2371
2837
|
* @example
|
|
2372
|
-
* This example registers a listener that responds to any change to the
|
|
2373
|
-
* Ids of any
|
|
2838
|
+
* This example registers a listener that responds to any change to the
|
|
2839
|
+
* ResultRow Ids of any ResultTable.
|
|
2374
2840
|
*
|
|
2375
2841
|
* ```js
|
|
2376
2842
|
* const store = createStore().setTable('pets', {
|
|
@@ -2408,50 +2874,63 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
2408
2874
|
*/
|
|
2409
2875
|
addResultRowIdsListener(
|
|
2410
2876
|
queryId: IdOrNull,
|
|
2411
|
-
listener: ResultRowIdsListener
|
|
2877
|
+
listener: ResultRowIdsListener<Schemas>,
|
|
2412
2878
|
): Id;
|
|
2413
2879
|
|
|
2414
2880
|
/**
|
|
2415
2881
|
* The addResultSortedRowIdsListener method registers a listener function with
|
|
2416
2882
|
* the Queries object that will be called whenever sorted (and optionally,
|
|
2417
|
-
* paginated)
|
|
2883
|
+
* paginated) ResultRow Ids in a ResultTable change.
|
|
2884
|
+
*
|
|
2885
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
2886
|
+
*
|
|
2887
|
+
* ```ts override
|
|
2888
|
+
* addResultSortedRowIdsListener(
|
|
2889
|
+
* queryId: Id,
|
|
2890
|
+
* cellId: Id | undefined,
|
|
2891
|
+
* descending: boolean,
|
|
2892
|
+
* offset: number,
|
|
2893
|
+
* limit: number | undefined,
|
|
2894
|
+
* listener: ResultSortedRowIdsListener,
|
|
2895
|
+
* ): Id;
|
|
2896
|
+
* ```
|
|
2418
2897
|
*
|
|
2419
2898
|
* The provided listener is a ResultSortedRowIdsListener function, and will be
|
|
2420
|
-
* called with a reference to the Queries object, the Id of the
|
|
2421
|
-
* whose
|
|
2422
|
-
* being used to sort them, whether descending or not, and the
|
|
2423
|
-
* limit of the number of Ids returned, for pagination purposes. It
|
|
2424
|
-
* receives the sorted array of Ids itself, so that you can use them in
|
|
2425
|
-
* listener without the additional cost of an explicit call to
|
|
2899
|
+
* called with a reference to the Queries object, the Id of the ResultTable
|
|
2900
|
+
* whose ResultRow Ids sorting changed (which is also the query Id), the
|
|
2901
|
+
* ResultCell Id being used to sort them, whether descending or not, and the
|
|
2902
|
+
* offset and limit of the number of Ids returned, for pagination purposes. It
|
|
2903
|
+
* also receives the sorted array of Ids itself, so that you can use them in
|
|
2904
|
+
* the listener without the additional cost of an explicit call to
|
|
2426
2905
|
* getResultSortedRowIds
|
|
2427
2906
|
*
|
|
2428
|
-
* Such a listener is called when a
|
|
2429
|
-
* value in the specified
|
|
2430
|
-
* enough to change the sorting of the
|
|
2907
|
+
* Such a listener is called when a ResultRow is added or removed, but also
|
|
2908
|
+
* when a value in the specified ResultCell (somewhere in the ResultTable) has
|
|
2909
|
+
* changed enough to change the sorting of the ResultRow Ids.
|
|
2431
2910
|
*
|
|
2432
2911
|
* Unlike most other listeners, you cannot provide wildcards (due to the cost
|
|
2433
2912
|
* of detecting changes to the sorting). You can only listen to a single
|
|
2434
|
-
* specified
|
|
2913
|
+
* specified ResultTable, sorted by a single specified ResultCell.
|
|
2435
2914
|
*
|
|
2436
2915
|
* The sorting of the rows is alphanumeric, and you can indicate whether it
|
|
2437
2916
|
* should be in descending order. The `offset` and `limit` parameters are used
|
|
2438
2917
|
* to paginate results, but default to `0` and `undefined` to return all
|
|
2439
|
-
* available
|
|
2918
|
+
* available ResultRow Ids if not specified.
|
|
2440
2919
|
*
|
|
2441
2920
|
* @param queryId The Id of the query to listen to.
|
|
2442
|
-
* @param cellId The Id of the
|
|
2443
|
-
* `undefined` to by sort the
|
|
2921
|
+
* @param cellId The Id of the ResultCell whose values are used for the
|
|
2922
|
+
* sorting, or `undefined` to by sort the ResultRow Id itself.
|
|
2444
2923
|
* @param descending Whether the sorting should be in descending order.
|
|
2445
|
-
* @param offset The number of
|
|
2446
|
-
* any.
|
|
2447
|
-
* @param limit The maximum number of
|
|
2448
|
-
* all.
|
|
2449
|
-
* @param listener The function that will be called whenever the sorted
|
|
2450
|
-
* Ids in the
|
|
2924
|
+
* @param offset The number of ResultRow Ids to skip for pagination purposes,
|
|
2925
|
+
* if any.
|
|
2926
|
+
* @param limit The maximum number of ResultRow Ids to return, or `undefined`
|
|
2927
|
+
* for all.
|
|
2928
|
+
* @param listener The function that will be called whenever the sorted
|
|
2929
|
+
* ResultRow Ids in the ResultTable change.
|
|
2451
2930
|
* @returns A unique Id for the listener that can later be used to remove it.
|
|
2452
2931
|
* @example
|
|
2453
2932
|
* This example registers a listener that responds to any change to the sorted
|
|
2454
|
-
*
|
|
2933
|
+
* ResultRow Ids of a specific ResultTable.
|
|
2455
2934
|
*
|
|
2456
2935
|
* ```js
|
|
2457
2936
|
* const store = createStore().setTable('pets', {
|
|
@@ -2476,22 +2955,22 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
2476
2955
|
* 0,
|
|
2477
2956
|
* undefined,
|
|
2478
2957
|
* (queries, tableId, cellId, descending, offset, limit, sortedRowIds) => {
|
|
2479
|
-
* console.log(`Sorted
|
|
2958
|
+
* console.log(`Sorted row Ids for dogColors result table changed`);
|
|
2480
2959
|
* console.log(sortedRowIds);
|
|
2481
2960
|
* // ^ cheaper than calling getResultSortedRowIds again
|
|
2482
2961
|
* },
|
|
2483
2962
|
* );
|
|
2484
2963
|
*
|
|
2485
2964
|
* store.setRow('pets', 'rex', {species: 'dog', color: 'tan'});
|
|
2486
|
-
* // -> 'Sorted
|
|
2965
|
+
* // -> 'Sorted row Ids for dogColors result table changed'
|
|
2487
2966
|
* // -> ['cujo', 'fido', 'rex']
|
|
2488
2967
|
*
|
|
2489
2968
|
* store.delListener(listenerId);
|
|
2490
2969
|
* ```
|
|
2491
2970
|
* @example
|
|
2492
2971
|
* This example registers a listener that responds to any change to the sorted
|
|
2493
|
-
*
|
|
2494
|
-
* since the `cellId` parameter is explicitly undefined.
|
|
2972
|
+
* ResultRow Ids of a specific ResultTable. The ResultRow Ids are sorted by
|
|
2973
|
+
* their own value, since the `cellId` parameter is explicitly undefined.
|
|
2495
2974
|
*
|
|
2496
2975
|
* ```js
|
|
2497
2976
|
* const store = createStore().setTable('pets', {
|
|
@@ -2518,14 +2997,14 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
2518
2997
|
* 0,
|
|
2519
2998
|
* undefined,
|
|
2520
2999
|
* (queries, tableId, cellId, descending, offset, limit, sortedRowIds) => {
|
|
2521
|
-
* console.log(`Sorted
|
|
3000
|
+
* console.log(`Sorted row Ids for dogColors result table changed`);
|
|
2522
3001
|
* console.log(sortedRowIds);
|
|
2523
3002
|
* // ^ cheaper than calling getSortedRowIds again
|
|
2524
3003
|
* },
|
|
2525
3004
|
* );
|
|
2526
3005
|
*
|
|
2527
3006
|
* store.setRow('pets', 'rex', {species: 'dog', color: 'tan'});
|
|
2528
|
-
* // -> 'Sorted
|
|
3007
|
+
* // -> 'Sorted row Ids for dogColors result table changed'
|
|
2529
3008
|
* // -> ['cujo', 'fido', 'rex']
|
|
2530
3009
|
*
|
|
2531
3010
|
* store.delListener(listenerId);
|
|
@@ -2539,36 +3018,45 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
2539
3018
|
descending: boolean,
|
|
2540
3019
|
offset: number,
|
|
2541
3020
|
limit: number | undefined,
|
|
2542
|
-
listener: ResultSortedRowIdsListener
|
|
3021
|
+
listener: ResultSortedRowIdsListener<Schemas>,
|
|
2543
3022
|
): Id;
|
|
2544
3023
|
|
|
2545
3024
|
/**
|
|
2546
3025
|
* The addResultRowListener method registers a listener function with the
|
|
2547
|
-
* Queries object that will be called whenever data in a
|
|
3026
|
+
* Queries object that will be called whenever data in a ResultRow changes.
|
|
3027
|
+
*
|
|
3028
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
3029
|
+
*
|
|
3030
|
+
* ```ts override
|
|
3031
|
+
* addResultRowListener(
|
|
3032
|
+
* queryId: IdOrNull,
|
|
3033
|
+
* rowId: IdOrNull,
|
|
3034
|
+
* listener: ResultRowListener,
|
|
3035
|
+
* ): Id;
|
|
3036
|
+
* ```
|
|
2548
3037
|
*
|
|
2549
3038
|
* The provided listener is a ResultRowListener function, and will be called
|
|
2550
|
-
* with a reference to the Queries object, the Id of the
|
|
2551
|
-
* (which is also the query Id), and a
|
|
2552
|
-
* to inspect any changes that occurred.
|
|
3039
|
+
* with a reference to the Queries object, the Id of the ResultTable that
|
|
3040
|
+
* changed (which is also the query Id), and a GetCellResultChange function in
|
|
3041
|
+
* case you need to inspect any changes that occurred.
|
|
2553
3042
|
*
|
|
2554
|
-
* You can either listen to a single
|
|
2555
|
-
*
|
|
2556
|
-
* (by providing `null` wildcards).
|
|
3043
|
+
* You can either listen to a single ResultRow (by specifying a query Id and
|
|
3044
|
+
* ResultRow Id as the method's first two parameters) or changes to any
|
|
3045
|
+
* ResultRow (by providing `null` wildcards).
|
|
2557
3046
|
*
|
|
2558
3047
|
* Both, either, or neither of the `queryId` and `rowId` parameters can be
|
|
2559
|
-
* wildcarded with `null`. You can listen to a specific
|
|
2560
|
-
* specific query, any
|
|
2561
|
-
*
|
|
3048
|
+
* wildcarded with `null`. You can listen to a specific ResultRow in a
|
|
3049
|
+
* specific query, any ResultRow in a specific query, a specific ResultRow in
|
|
3050
|
+
* any query, or any ResultRow in any query.
|
|
2562
3051
|
*
|
|
2563
3052
|
* @param queryId The Id of the query to listen to, or `null` as a wildcard.
|
|
2564
|
-
* @param rowId The Id of the
|
|
2565
|
-
* wildcard.
|
|
3053
|
+
* @param rowId The Id of the ResultRow to listen to, or `null` as a wildcard.
|
|
2566
3054
|
* @param listener The function that will be called whenever data in the
|
|
2567
|
-
* matching
|
|
3055
|
+
* matching ResultRow changes.
|
|
2568
3056
|
* @returns A unique Id for the listener that can later be used to remove it.
|
|
2569
3057
|
* @example
|
|
2570
3058
|
* This example registers a listener that responds to any changes to a
|
|
2571
|
-
* specific
|
|
3059
|
+
* specific ResultRow.
|
|
2572
3060
|
*
|
|
2573
3061
|
* ```js
|
|
2574
3062
|
* const store = createStore().setTable('pets', {
|
|
@@ -2603,7 +3091,7 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
2603
3091
|
* ```
|
|
2604
3092
|
* @example
|
|
2605
3093
|
* This example registers a listener that responds to any changes to any
|
|
2606
|
-
*
|
|
3094
|
+
* ResultRow.
|
|
2607
3095
|
*
|
|
2608
3096
|
* ```js
|
|
2609
3097
|
* const store = createStore().setTable('pets', {
|
|
@@ -2643,40 +3131,49 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
2643
3131
|
addResultRowListener(
|
|
2644
3132
|
queryId: IdOrNull,
|
|
2645
3133
|
rowId: IdOrNull,
|
|
2646
|
-
listener: ResultRowListener
|
|
3134
|
+
listener: ResultRowListener<Schemas>,
|
|
2647
3135
|
): Id;
|
|
2648
3136
|
|
|
2649
3137
|
/**
|
|
2650
3138
|
* The addResultCellIdsListener method registers a listener function with the
|
|
2651
|
-
* Queries object that will be called whenever the
|
|
2652
|
-
* change.
|
|
3139
|
+
* Queries object that will be called whenever the ResultCell Ids in a
|
|
3140
|
+
* ResultRow change.
|
|
3141
|
+
*
|
|
3142
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
3143
|
+
*
|
|
3144
|
+
* ```ts override
|
|
3145
|
+
* addResultCellIdsListener(
|
|
3146
|
+
* queryId: IdOrNull,
|
|
3147
|
+
* rowId: IdOrNull,
|
|
3148
|
+
* listener: ResultCellIdsListener,
|
|
3149
|
+
* ): Id;
|
|
3150
|
+
* ```
|
|
2653
3151
|
*
|
|
2654
3152
|
* The provided listener is a ResultCellIdsListener function, and will be
|
|
2655
|
-
* called with a reference to the Queries object, the Id of the
|
|
2656
|
-
* is also the query Id), and the Id of the
|
|
3153
|
+
* called with a reference to the Queries object, the Id of the ResultTable
|
|
3154
|
+
* (which is also the query Id), and the Id of the ResultRow that changed.
|
|
2657
3155
|
*
|
|
2658
|
-
* Such a listener is only called when a
|
|
2659
|
-
* the
|
|
3156
|
+
* Such a listener is only called when a ResultCell is added to, or removed
|
|
3157
|
+
* from, the ResultRow. To listen to all changes in the ResultRow, use the
|
|
2660
3158
|
* addResultRowListener method.
|
|
2661
3159
|
*
|
|
2662
|
-
* You can either listen to a single
|
|
2663
|
-
*
|
|
2664
|
-
* providing `null` wildcards).
|
|
3160
|
+
* You can either listen to a single ResultRow (by specifying the query Id and
|
|
3161
|
+
* ResultRow Id as the method's first two parameters) or changes to any
|
|
3162
|
+
* ResultRow (by providing `null` wildcards).
|
|
2665
3163
|
*
|
|
2666
3164
|
* Both, either, or neither of the `queryId` and `rowId` parameters can be
|
|
2667
|
-
* wildcarded with `null`. You can listen to a specific
|
|
2668
|
-
* specific query, any
|
|
2669
|
-
*
|
|
3165
|
+
* wildcarded with `null`. You can listen to a specific ResultRow in a
|
|
3166
|
+
* specific query, any ResultRow in a specific query, a specific ResultRow in
|
|
3167
|
+
* any query, or any ResultRow in any query.
|
|
2670
3168
|
*
|
|
2671
3169
|
* @param queryId The Id of the query to listen to, or `null` as a wildcard.
|
|
2672
|
-
* @param rowId The Id of the
|
|
2673
|
-
*
|
|
2674
|
-
*
|
|
2675
|
-
* the result Row change.
|
|
3170
|
+
* @param rowId The Id of the ResultRow to listen to, or `null` as a wildcard.
|
|
3171
|
+
* @param listener The function that will be called whenever the ResultCell
|
|
3172
|
+
* Ids in the ResultRow change.
|
|
2676
3173
|
* @returns A unique Id for the listener that can later be used to remove it.
|
|
2677
3174
|
* @example
|
|
2678
|
-
* This example registers a listener that responds to any change to the
|
|
2679
|
-
* Ids of a specific
|
|
3175
|
+
* This example registers a listener that responds to any change to the
|
|
3176
|
+
* ResultCell Ids of a specific ResultRow.
|
|
2680
3177
|
*
|
|
2681
3178
|
* ```js
|
|
2682
3179
|
* const store = createStore().setTable('pets', {
|
|
@@ -2711,8 +3208,8 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
2711
3208
|
* store.delListener(listenerId);
|
|
2712
3209
|
* ```
|
|
2713
3210
|
* @example
|
|
2714
|
-
* This example registers a listener that responds to any change to the
|
|
2715
|
-
* Ids of any
|
|
3211
|
+
* This example registers a listener that responds to any change to the
|
|
3212
|
+
* ResultCell Ids of any ResultRow.
|
|
2716
3213
|
*
|
|
2717
3214
|
* ```js
|
|
2718
3215
|
* const store = createStore().setTable('pets', {
|
|
@@ -2756,40 +3253,50 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
2756
3253
|
addResultCellIdsListener(
|
|
2757
3254
|
queryId: IdOrNull,
|
|
2758
3255
|
rowId: IdOrNull,
|
|
2759
|
-
listener: ResultCellIdsListener
|
|
3256
|
+
listener: ResultCellIdsListener<Schemas>,
|
|
2760
3257
|
): Id;
|
|
2761
3258
|
|
|
2762
3259
|
/**
|
|
2763
3260
|
* The addResultCellListener method registers a listener function with the
|
|
2764
|
-
* Queries object that will be called whenever data in a
|
|
3261
|
+
* Queries object that will be called whenever data in a ResultCell changes.
|
|
3262
|
+
*
|
|
3263
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
3264
|
+
*
|
|
3265
|
+
* ```ts override
|
|
3266
|
+
* addResultCellListener(
|
|
3267
|
+
* queryId: IdOrNull,
|
|
3268
|
+
* rowId: IdOrNull,
|
|
3269
|
+
* cellId: IdOrNull,
|
|
3270
|
+
* listener: ResultCellListener,
|
|
3271
|
+
* ): Id;
|
|
3272
|
+
* ```
|
|
2765
3273
|
*
|
|
2766
3274
|
* The provided listener is a ResultCellListener function, and will be called
|
|
2767
|
-
* with a reference to the Queries object, the Id of the
|
|
2768
|
-
* (which is also the query Id), the Id of the
|
|
2769
|
-
*
|
|
2770
|
-
*
|
|
2771
|
-
* occurred.
|
|
3275
|
+
* with a reference to the Queries object, the Id of the ResultTable that
|
|
3276
|
+
* changed (which is also the query Id), the Id of the ResultRow that changed,
|
|
3277
|
+
* the Id of the ResultCell that changed, the new ResultCell value, the old
|
|
3278
|
+
* ResultCell value, and a GetCellResultChange function in case you need to
|
|
3279
|
+
* inspect any changes that occurred.
|
|
2772
3280
|
*
|
|
2773
|
-
* You can either listen to a single
|
|
2774
|
-
* Id, and
|
|
2775
|
-
*
|
|
3281
|
+
* You can either listen to a single ResultRow (by specifying a query Id,
|
|
3282
|
+
* ResultRow Id, and ResultCell Id as the method's first three parameters) or
|
|
3283
|
+
* changes to any ResultCell (by providing `null` wildcards).
|
|
2776
3284
|
*
|
|
2777
3285
|
* All, some, or none of the `queryId`, `rowId`, and `cellId` parameters can
|
|
2778
|
-
* be wildcarded with `null`. You can listen to a specific
|
|
2779
|
-
*
|
|
2780
|
-
* for example - or every other combination of wildcards.
|
|
3286
|
+
* be wildcarded with `null`. You can listen to a specific ResultCell in a
|
|
3287
|
+
* specific ResultRow in a specific query, any ResultCell in any ResultRow in
|
|
3288
|
+
* any query, for example - or every other combination of wildcards.
|
|
2781
3289
|
*
|
|
2782
3290
|
* @param queryId The Id of the query to listen to, or `null` as a wildcard.
|
|
2783
|
-
* @param rowId The Id of the
|
|
2784
|
-
*
|
|
2785
|
-
* @param cellId The Id of the result Cell to listen to, or `null` as a
|
|
3291
|
+
* @param rowId The Id of the ResultRow to listen to, or `null` as a wildcard.
|
|
3292
|
+
* @param cellId The Id of the ResultCell to listen to, or `null` as a
|
|
2786
3293
|
* wildcard.
|
|
2787
3294
|
* @param listener The function that will be called whenever data in the
|
|
2788
|
-
* matching
|
|
3295
|
+
* matching ResultCell changes.
|
|
2789
3296
|
* @returns A unique Id for the listener that can later be used to remove it.
|
|
2790
3297
|
* @example
|
|
2791
3298
|
* This example registers a listener that responds to any changes to a
|
|
2792
|
-
* specific
|
|
3299
|
+
* specific ResultCell.
|
|
2793
3300
|
*
|
|
2794
3301
|
* ```js
|
|
2795
3302
|
* const store = createStore().setTable('pets', {
|
|
@@ -2829,7 +3336,7 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
2829
3336
|
* ```
|
|
2830
3337
|
* @example
|
|
2831
3338
|
* This example registers a listener that responds to any changes to any
|
|
2832
|
-
*
|
|
3339
|
+
* ResultCell.
|
|
2833
3340
|
*
|
|
2834
3341
|
* ```js
|
|
2835
3342
|
* const store = createStore().setTable('pets', {
|
|
@@ -2874,13 +3381,19 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
2874
3381
|
queryId: IdOrNull,
|
|
2875
3382
|
rowId: IdOrNull,
|
|
2876
3383
|
cellId: IdOrNull,
|
|
2877
|
-
listener: ResultCellListener
|
|
3384
|
+
listener: ResultCellListener<Schemas>,
|
|
2878
3385
|
): Id;
|
|
2879
3386
|
|
|
2880
3387
|
/**
|
|
2881
3388
|
* The delListener method removes a listener that was previously added to the
|
|
2882
3389
|
* Queries object.
|
|
2883
3390
|
*
|
|
3391
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
3392
|
+
*
|
|
3393
|
+
* ```ts override
|
|
3394
|
+
* delListener(listenerId: Id): Queries;
|
|
3395
|
+
* ```
|
|
3396
|
+
*
|
|
2884
3397
|
* Use the Id returned by the addMetricListener method. Note that the Queries
|
|
2885
3398
|
* object may re-use this Id for future listeners added to it.
|
|
2886
3399
|
*
|
|
@@ -2994,6 +3507,12 @@ export interface Queries<Schemas extends OptionalSchemas = NoSchemas> {
|
|
|
2994
3507
|
* The createQueries function creates a Queries object, and is the main entry
|
|
2995
3508
|
* point into the queries module.
|
|
2996
3509
|
*
|
|
3510
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
3511
|
+
*
|
|
3512
|
+
* ```ts override
|
|
3513
|
+
* createQueries(store: Store): Queries;
|
|
3514
|
+
* ```
|
|
3515
|
+
*
|
|
2997
3516
|
* A given Store can only have one Queries object associated with it. If you
|
|
2998
3517
|
* call this function twice on the same Store, your second call will return a
|
|
2999
3518
|
* reference to the Queries object created by the first.
|