tinybase 2.0.0 → 2.1.0-beta.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.
Files changed (123) hide show
  1. package/lib/checkpoints.js +1 -1
  2. package/lib/checkpoints.js.gz +0 -0
  3. package/lib/common.js +1 -1
  4. package/lib/common.js.gz +0 -0
  5. package/lib/debug/checkpoints.js +7 -1
  6. package/lib/debug/common.js +1 -4
  7. package/lib/debug/indexes.d.ts +36 -10
  8. package/lib/debug/indexes.js +57 -25
  9. package/lib/debug/metrics.d.ts +1 -1
  10. package/lib/debug/metrics.js +19 -2
  11. package/lib/debug/persisters.d.ts +5 -5
  12. package/lib/debug/queries.js +18 -2
  13. package/lib/debug/relationships.d.ts +3 -3
  14. package/lib/debug/relationships.js +19 -2
  15. package/lib/debug/store.js +8 -2
  16. package/lib/debug/tinybase.js +53 -27
  17. package/lib/debug/ui-react.d.ts +17 -17
  18. package/lib/debug/ui-react.js +2 -1
  19. package/lib/es6/checkpoints.d.ts +946 -0
  20. package/lib/es6/checkpoints.js +1 -0
  21. package/lib/es6/checkpoints.js.gz +0 -0
  22. package/lib/es6/common.d.ts +115 -0
  23. package/lib/es6/common.js +1 -0
  24. package/lib/es6/common.js.gz +0 -0
  25. package/lib/es6/indexes.d.ts +967 -0
  26. package/lib/es6/indexes.js +1 -0
  27. package/lib/es6/indexes.js.gz +0 -0
  28. package/lib/es6/metrics.d.ts +829 -0
  29. package/lib/es6/metrics.js +1 -0
  30. package/lib/es6/metrics.js.gz +0 -0
  31. package/lib/es6/persisters.d.ts +717 -0
  32. package/lib/es6/persisters.js +1 -0
  33. package/lib/es6/persisters.js.gz +0 -0
  34. package/lib/es6/queries.d.ts +3026 -0
  35. package/lib/es6/queries.js +1 -0
  36. package/lib/es6/queries.js.gz +0 -0
  37. package/lib/es6/relationships.d.ts +1203 -0
  38. package/lib/es6/relationships.js +1 -0
  39. package/lib/es6/relationships.js.gz +0 -0
  40. package/lib/es6/store.d.ts +3572 -0
  41. package/lib/es6/store.js +1 -0
  42. package/lib/es6/store.js.gz +0 -0
  43. package/lib/es6/tinybase.d.ts +14 -0
  44. package/lib/es6/tinybase.js +1 -0
  45. package/lib/es6/tinybase.js.gz +0 -0
  46. package/lib/es6/ui-react.d.ts +9777 -0
  47. package/lib/es6/ui-react.js +1 -0
  48. package/lib/es6/ui-react.js.gz +0 -0
  49. package/lib/indexes.d.ts +36 -10
  50. package/lib/indexes.js +1 -1
  51. package/lib/indexes.js.gz +0 -0
  52. package/lib/metrics.d.ts +1 -1
  53. package/lib/metrics.js +1 -1
  54. package/lib/metrics.js.gz +0 -0
  55. package/lib/persisters.d.ts +5 -5
  56. package/lib/queries.js +1 -1
  57. package/lib/queries.js.gz +0 -0
  58. package/lib/relationships.d.ts +3 -3
  59. package/lib/relationships.js +1 -1
  60. package/lib/relationships.js.gz +0 -0
  61. package/lib/store.js +1 -1
  62. package/lib/store.js.gz +0 -0
  63. package/lib/tinybase.js +1 -1
  64. package/lib/tinybase.js.gz +0 -0
  65. package/lib/ui-react.d.ts +17 -17
  66. package/lib/umd/checkpoints.d.ts +946 -0
  67. package/lib/umd/checkpoints.js +1 -1
  68. package/lib/umd/checkpoints.js.gz +0 -0
  69. package/lib/umd/common.d.ts +115 -0
  70. package/lib/umd/common.js +1 -1
  71. package/lib/umd/common.js.gz +0 -0
  72. package/lib/umd/indexes.d.ts +967 -0
  73. package/lib/umd/indexes.js +1 -1
  74. package/lib/umd/indexes.js.gz +0 -0
  75. package/lib/umd/metrics.d.ts +829 -0
  76. package/lib/umd/metrics.js +1 -1
  77. package/lib/umd/metrics.js.gz +0 -0
  78. package/lib/umd/persisters.d.ts +717 -0
  79. package/lib/umd/queries.d.ts +3026 -0
  80. package/lib/umd/queries.js +1 -1
  81. package/lib/umd/queries.js.gz +0 -0
  82. package/lib/umd/relationships.d.ts +1203 -0
  83. package/lib/umd/relationships.js +1 -1
  84. package/lib/umd/relationships.js.gz +0 -0
  85. package/lib/umd/store.d.ts +3572 -0
  86. package/lib/umd/store.js +1 -1
  87. package/lib/umd/store.js.gz +0 -0
  88. package/lib/umd/tinybase.d.ts +14 -0
  89. package/lib/umd/tinybase.js +1 -1
  90. package/lib/umd/tinybase.js.gz +0 -0
  91. package/lib/umd/ui-react.d.ts +9777 -0
  92. package/lib/umd-es6/checkpoints.d.ts +946 -0
  93. package/lib/umd-es6/checkpoints.js +1 -0
  94. package/lib/umd-es6/checkpoints.js.gz +0 -0
  95. package/lib/umd-es6/common.d.ts +115 -0
  96. package/lib/umd-es6/common.js +1 -0
  97. package/lib/umd-es6/common.js.gz +0 -0
  98. package/lib/umd-es6/indexes.d.ts +967 -0
  99. package/lib/umd-es6/indexes.js +1 -0
  100. package/lib/umd-es6/indexes.js.gz +0 -0
  101. package/lib/umd-es6/metrics.d.ts +829 -0
  102. package/lib/umd-es6/metrics.js +1 -0
  103. package/lib/umd-es6/metrics.js.gz +0 -0
  104. package/lib/umd-es6/persisters.d.ts +717 -0
  105. package/lib/umd-es6/persisters.js +1 -0
  106. package/lib/umd-es6/persisters.js.gz +0 -0
  107. package/lib/umd-es6/queries.d.ts +3026 -0
  108. package/lib/umd-es6/queries.js +1 -0
  109. package/lib/umd-es6/queries.js.gz +0 -0
  110. package/lib/umd-es6/relationships.d.ts +1203 -0
  111. package/lib/umd-es6/relationships.js +1 -0
  112. package/lib/umd-es6/relationships.js.gz +0 -0
  113. package/lib/umd-es6/store.d.ts +3572 -0
  114. package/lib/umd-es6/store.js +1 -0
  115. package/lib/umd-es6/store.js.gz +0 -0
  116. package/lib/umd-es6/tinybase.d.ts +14 -0
  117. package/lib/umd-es6/tinybase.js +1 -0
  118. package/lib/umd-es6/tinybase.js.gz +0 -0
  119. package/lib/umd-es6/ui-react.d.ts +9777 -0
  120. package/lib/umd-es6/ui-react.js +1 -0
  121. package/lib/umd-es6/ui-react.js.gz +0 -0
  122. package/package.json +2 -1
  123. package/readme.md +12 -12
@@ -0,0 +1,3572 @@
1
+ /**
2
+ * The store module is the core of the TinyBase project and contains the types,
3
+ * interfaces, and functions to work with Store objects.
4
+ *
5
+ * The main entry point to this module is the createStore function, which
6
+ * returns a new Store. From there, you can set and get data, register
7
+ * listeners, and use other modules to build an entire app around the state and
8
+ * tabular data within.
9
+ *
10
+ * @packageDocumentation
11
+ * @module store
12
+ */
13
+
14
+ import {Id, IdOrNull, Ids, Json} from './common.d';
15
+
16
+ /**
17
+ * The Tables type is the data structure representing all of the data in a
18
+ * Store.
19
+ *
20
+ * A Tables object is used when setting all of the tables together with the
21
+ * setTables method, and when getting them back out again with the getTables
22
+ * method. A Tables object is a regular JavaScript object containing individual
23
+ * Table objects, keyed by their Id.
24
+ *
25
+ * @example
26
+ * ```js
27
+ * const tables: Tables = {
28
+ * pets: {
29
+ * fido: {species: 'dog', color: 'brown'},
30
+ * felix: {species: 'cat'},
31
+ * },
32
+ * species: {
33
+ * dog: {price: 5},
34
+ * cat: {price: 4},
35
+ * },
36
+ * };
37
+ * ```
38
+ * @category Store
39
+ */
40
+ export type Tables = {[tableId: Id]: Table};
41
+
42
+ /**
43
+ * The Table type is the data structure representing the data in a single table.
44
+ *
45
+ * A Table is used when setting a table with the setTable method, and when
46
+ * getting it back out again with the getTable method. A Table object is a
47
+ * regular JavaScript object containing individual Row objects, keyed by their
48
+ * Id.
49
+ *
50
+ * @example
51
+ * ```js
52
+ * const table: Table = {
53
+ * fido: {species: 'dog', color: 'brown'},
54
+ * felix: {species: 'cat'},
55
+ * };
56
+ * ```
57
+ * @category Store
58
+ */
59
+ export type Table = {[rowId: Id]: Row};
60
+
61
+ /**
62
+ * The Row type is the data structure representing the data in a single row.
63
+ *
64
+ * A Row is used when setting a row with the setRow method, and when getting it
65
+ * back out again with the getRow method. A Row object is a regular JavaScript
66
+ * object containing individual Cell objects, keyed by their Id.
67
+ *
68
+ * @example
69
+ * ```js
70
+ * const row: Row = {species: 'dog', color: 'brown'};
71
+ * ```
72
+ * @category Store
73
+ */
74
+ export type Row = {[cellId: Id]: Cell};
75
+
76
+ /**
77
+ * The Cell type is the data structure representing the data in a single cell.
78
+ *
79
+ * A Cell is used when setting a cell with the setCell method, and when getting
80
+ * it back out again with the getCell method. A Cell is a JavaScript string,
81
+ * number, or boolean.
82
+ *
83
+ * @example
84
+ * ```js
85
+ * const cell: Cell = 'dog';
86
+ * ```
87
+ * @category Store
88
+ */
89
+ export type Cell = string | number | boolean;
90
+
91
+ /**
92
+ * The CellOrUndefined type is a data structure representing the data in a
93
+ * single cell or the value `undefined`.
94
+ *
95
+ * This is used when describing a Cell that is present _or_ that is not present
96
+ * - such as when it has been deleted, or when describing a previous state where
97
+ * the Cell value has since been added.
98
+ *
99
+ * @category Store
100
+ */
101
+ export type CellOrUndefined = Cell | undefined;
102
+
103
+ /**
104
+ * The TableCallback type describes a function that takes a Table's Id and a
105
+ * callback to loop over each Row within it.
106
+ *
107
+ * A TableCallback is provided when using the forEachTable method, so that you
108
+ * can do something based on every Table in the Store. See that method for
109
+ * specific examples.
110
+ *
111
+ * @param tableId The Id of the Table that the callback can operate on.
112
+ * @param forEachRow A function that will let you iterate over the Row objects
113
+ * in this Table.
114
+ * @category Callback
115
+ */
116
+ export type TableCallback = (
117
+ tableId: Id,
118
+ forEachRow: (rowCallback: RowCallback) => void,
119
+ ) => void;
120
+
121
+ /**
122
+ * The RowCallback type describes a function that takes a Row's Id and a
123
+ * callback to loop over each Cell within it.
124
+ *
125
+ * A RowCallback is provided when using the forEachRow method, so that you can
126
+ * do something based on every Row in a Table. See that method for specific
127
+ * examples.
128
+ *
129
+ * @param rowId The Id of the Row that the callback can operate on.
130
+ * @param forEachRow A function that will let you iterate over the Cell values
131
+ * in this Row.
132
+ * @category Callback
133
+ */
134
+ export type RowCallback = (
135
+ rowId: Id,
136
+ forEachCell: (cellCallback: CellCallback) => void,
137
+ ) => void;
138
+
139
+ /**
140
+ * The CellCallback type describes a function that takes a Cell's Id and its
141
+ * value.
142
+ *
143
+ * A CellCallback is provided when using the forEachCell method, so that you can
144
+ * do something based on every Cell in a Row. See that method for specific
145
+ * examples.
146
+ *
147
+ * @param cellId The Id of the Cell that the callback can operate on.
148
+ * @param cell The value of the Cell.
149
+ * @category Callback
150
+ */
151
+ export type CellCallback = (cellId: Id, cell: Cell) => void;
152
+
153
+ /**
154
+ * The MapCell type describes a function that takes an existing Cell value and
155
+ * returns another.
156
+ *
157
+ * A MapCell can be provided in the setCell method to map an existing value to a
158
+ * new one, such as when incrementing a number. See that method for specific
159
+ * examples.
160
+ *
161
+ * @param cell The current value of the Cell to map to a new value.
162
+ * @category Callback
163
+ */
164
+ export type MapCell = (cell: CellOrUndefined) => Cell;
165
+
166
+ /**
167
+ * The GetCell type describes a function that takes a Id and returns the Cell
168
+ * value for a particular Row.
169
+ *
170
+ * A GetCell can be provided when setting definitions, as in the
171
+ * setMetricDefinition method of a Metrics object, or the setIndexDefinition
172
+ * method of an Indexes object. See those methods for specific examples.
173
+ *
174
+ * @param cellId The Id of the Cell to fetch the value for.
175
+ * @category Callback
176
+ */
177
+ export type GetCell = (cellId: Id) => CellOrUndefined;
178
+
179
+ /**
180
+ * The TransactionListener type describes a function that is used to listen to
181
+ * the completion of a transaction for the Store.
182
+ *
183
+ * A TransactionListener is provided when using the
184
+ * addWillFinishTransactionListener and addDidFinishTransactionListener methods.
185
+ * See those methods for specific examples.
186
+ *
187
+ * When called, a TransactionListener is simply given a reference to the Store
188
+ * and a boolean to indicate whether Cell values have been touched during the
189
+ * transaction. The latter flag is intended as a hint about whether non-mutating
190
+ * listeners might be being called at the end of the transaction.
191
+ *
192
+ * Here, 'touched' means that Cell values have either been changed, or changed
193
+ * and then changed back to its original value during the transaction. The
194
+ * exception is a transaction that has been rolled back, for which the value of
195
+ * `cellsTouched` in the listener will be `false` because all changes have been
196
+ * reverted.
197
+ *
198
+ * @param store A reference to the Store that is completing a transaction.
199
+ * @param cellsTouched Whether Cell values have been touched during the
200
+ * transaction.
201
+ * @category Listener
202
+ */
203
+ export type TransactionListener = (store: Store, cellsTouched: boolean) => void;
204
+
205
+ /**
206
+ * The TablesListener type describes a function that is used to listen to
207
+ * changes to the whole Store.
208
+ *
209
+ * A TablesListener is provided when using the addTablesListener method. See
210
+ * that method for specific examples.
211
+ *
212
+ * When called, a TablesListener is given a reference to the Store and a
213
+ * GetCellChange function that can be used to query Cell values before and after
214
+ * the current transaction.
215
+ *
216
+ * Note that if the listener was manually forced to be called (with the
217
+ * callListener method rather than due to a real change in the Store), the
218
+ * GetCellChange function will not be present.
219
+ *
220
+ * @param store A reference to the Store that changed.
221
+ * @param getCellChange A function that returns information about any Cell's
222
+ * changes.
223
+ * @category Listener
224
+ */
225
+ export type TablesListener = (
226
+ store: Store,
227
+ getCellChange: GetCellChange | undefined,
228
+ ) => void;
229
+
230
+ /**
231
+ * The TableIdsListener type describes a function that is used to listen to
232
+ * changes to the Table Ids in the Store.
233
+ *
234
+ * A TableIdsListener is provided when using the addTableIdsListener method. See
235
+ * that method for specific examples.
236
+ *
237
+ * When called, a TableIdsListener is given a reference to the Store.
238
+ *
239
+ * @param store A reference to the Store that changed.
240
+ * @category Listener
241
+ */
242
+ export type TableIdsListener = (store: Store) => void;
243
+
244
+ /**
245
+ * The TableListener type describes a function that is used to listen to changes
246
+ * to a Table.
247
+ *
248
+ * A TableListener is provided when using the addTableListener method. See that
249
+ * method for specific examples.
250
+ *
251
+ * When called, a TableListener is given a reference to the Store, the Id of the
252
+ * Table that changed, and a GetCellChange function that can be used to query
253
+ * Cell values before and after the current transaction.
254
+ *
255
+ * Note that if the listener was manually forced to be called (with the
256
+ * callListener method rather than due to a real change in the Store), the
257
+ * GetCellChange function will not be present.
258
+ *
259
+ * @param store A reference to the Store that changed.
260
+ * @param tableId The Id of the Table that changed.
261
+ * @param getCellChange A function that returns information about any Cell's
262
+ * changes.
263
+ * @category Listener
264
+ */
265
+ export type TableListener = (
266
+ store: Store,
267
+ tableId: Id,
268
+ getCellChange: GetCellChange | undefined,
269
+ ) => void;
270
+
271
+ /**
272
+ * The RowIdsListener type describes a function that is used to listen to
273
+ * changes to the Row Ids in a Table.
274
+ *
275
+ * A RowIdsListener is provided when using the addRowIdsListener method. See
276
+ * that method for specific examples.
277
+ *
278
+ * When called, a RowIdsListener is given a reference to the Store, and the Id
279
+ * of the Table whose Row Ids changed.
280
+ *
281
+ * @param store A reference to the Store that changed.
282
+ * @param tableId The Id of the Table that changed.
283
+ * @category Listener
284
+ */
285
+ export type RowIdsListener = (store: Store, tableId: Id) => void;
286
+
287
+ /**
288
+ * The SortedRowIdsListener type describes a function that is used to listen to
289
+ * changes to sorted Row Ids in a Table.
290
+ *
291
+ * A SortedRowIdsListener is provided when using the addSortedRowIdsListener
292
+ * method. See that method for specific examples.
293
+ *
294
+ * When called, a SortedRowIdsListener is given a reference to the Store, the Id
295
+ * of the Table whose Row Ids sorting changed, the Cell Id being used to sort
296
+ * them, whether descending or not, and the offset and limit of the number of
297
+ * Ids returned, for pagination purposes. It also receives the sorted array of
298
+ * Ids itself, so that you can use them in the listener without the additional
299
+ * cost of an explicit call to getSortedRowIds.
300
+ *
301
+ * @param store A reference to the Store that changed.
302
+ * @param tableId The Id of the Table whose sorted Row Ids changed.
303
+ * @param cellId The Id of the Cell whose values were used for the sorting.
304
+ * @param descending Whether the sorting was in descending order.
305
+ * @param offset The number of Row Ids skipped.
306
+ * @param limit The maximum number of Row Ids returned.
307
+ * @param sortedRowIds The sorted Row Ids themselves.
308
+ * @category Listener
309
+ * @since v2.0.0
310
+ */
311
+ export type SortedRowIdsListener = (
312
+ store: Store,
313
+ tableId: Id,
314
+ cellId: Id | undefined,
315
+ descending: boolean,
316
+ offset: number,
317
+ limit: number | undefined,
318
+ sortedRowIds: Ids,
319
+ ) => void;
320
+
321
+ /**
322
+ * The RowListener type describes a function that is used to listen to changes
323
+ * to a Row.
324
+ *
325
+ * A RowListener is provided when using the addRowListener method. See that
326
+ * method for specific examples.
327
+ *
328
+ * When called, a RowListener is given a reference to the Store, the Id of the
329
+ * Table that changed, the Id of the Row that changed, and a GetCellChange
330
+ * function that can be used to query Cell values before and after the current
331
+ * transaction.
332
+ *
333
+ * Note that if the listener was manually forced to be called (with the
334
+ * callListener method rather than due to a real change in the Store), the
335
+ * GetCellChange function will not be present.
336
+ *
337
+ * @param store A reference to the Store that changed.
338
+ * @param tableId The Id of the Table that changed.
339
+ * @param rowId The Id of the Row that changed.
340
+ * @param getCellChange A function that returns information about any Cell's
341
+ * changes.
342
+ * @category Listener
343
+ */
344
+ export type RowListener = (
345
+ store: Store,
346
+ tableId: Id,
347
+ rowId: Id,
348
+ getCellChange: GetCellChange | undefined,
349
+ ) => void;
350
+
351
+ /**
352
+ * The CellIdsListener type describes a function that is used to listen to
353
+ * changes to the Cell Ids in a Row.
354
+ *
355
+ * A CellIdsListener is provided when using the addCellIdsListener method. See
356
+ * that method for specific examples.
357
+ *
358
+ * When called, a CellIdsListener is given a reference to the Store, the Id of
359
+ * the Table that changed, and the Id of the Row whose Cell Ids changed.
360
+ *
361
+ * @param store A reference to the Store that changed.
362
+ * @param tableId The Id of the Table that changed.
363
+ * @param rowId The Id of the Row that changed.
364
+ * @category Listener
365
+ */
366
+ export type CellIdsListener = (store: Store, tableId: Id, rowId: Id) => void;
367
+
368
+ /**
369
+ * The CellListener type describes a function that is used to listen to changes
370
+ * to a Cell.
371
+ *
372
+ * A CellListener is provided when using the addCellListener method. See that
373
+ * method for specific examples.
374
+ *
375
+ * When called, a CellListener is given a reference to the Store, the Id of the
376
+ * Table that changed, the Id of the Row that changed, and the Id of Cell that
377
+ * changed. It is also given the new value of the Cell, the old value of the
378
+ * Cell, and a GetCellChange function that can be used to query Cell values
379
+ * before and after the current transaction.
380
+ *
381
+ * Note that if the listener was manually forced to be called (with the
382
+ * callListener method rather than due to a real change in the Store), the
383
+ * GetCellChange function will not be present and the new and old values of the
384
+ * Cell will be the same.
385
+ *
386
+ * @param store A reference to the Store that changed.
387
+ * @param tableId The Id of the Table that changed.
388
+ * @param rowId The Id of the Row that changed.
389
+ * @param cellId The Id of the Cell that changed.
390
+ * @param newCell The new value of the Cell that changed.
391
+ * @param oldCell The old value of the Cell that changed.
392
+ * @param getCellChange A function that returns information about any Cell's
393
+ * changes.
394
+ * @category Listener
395
+ */
396
+ export type CellListener = (
397
+ store: Store,
398
+ tableId: Id,
399
+ rowId: Id,
400
+ cellId: Id,
401
+ newCell: Cell,
402
+ oldCell: Cell,
403
+ getCellChange: GetCellChange | undefined,
404
+ ) => void;
405
+
406
+ /**
407
+ * The InvalidCellListener type describes a function that is used to listen to
408
+ * attempts to set invalid data to a Cell.
409
+ *
410
+ * A InvalidCellListener is provided when using the addInvalidCellListener
411
+ * method. See that method for specific examples.
412
+ *
413
+ * When called, a InvalidCellListener is given a reference to the Store, the Id
414
+ * of the Table, the Id of the Row, and the Id of Cell that were being attempted
415
+ * to be changed. It is also given the invalid value of the Cell, which could
416
+ * have been of absolutely any type. Since there could have been multiple failed
417
+ * attempts to set the Cell within a single transaction, this is an array
418
+ * containing each attempt, chronologically.
419
+ *
420
+ * @param store A reference to the Store that was being changed.
421
+ * @param tableId The Id of the Table that was being changed.
422
+ * @param rowId The Id of the Row that was being changed.
423
+ * @param cellId The Id of the Cell that was being changed.
424
+ * @param invalidCells An array of the values of the Cell that were invalid.
425
+ * @category Listener
426
+ * @since v1.1.0
427
+ */
428
+ export type InvalidCellListener = (
429
+ store: Store,
430
+ tableId: Id,
431
+ rowId: Id,
432
+ cellId: Id,
433
+ invalidCells: any[],
434
+ ) => void;
435
+
436
+ /**
437
+ * The GetCellChange type describes a function that returns information about
438
+ * any Cell's changes during a transaction.
439
+ *
440
+ * A GetCellChange function is provided to every listener when called due the
441
+ * Store changing. The listener can then fetch the previous value of a Cell
442
+ * before the current transaction, the new value after it, and a convenience
443
+ * flag that indicates that the value has changed.
444
+ *
445
+ * @param tableId The Id of the Table to inspect.
446
+ * @param rowId The Id of the Row to inspect.
447
+ * @param cellId The Id of the Cell to inspect.
448
+ * @returns A CellChange array containing information about the Cell's changes.
449
+ * @category Listener
450
+ */
451
+ export type GetCellChange = (tableId: Id, rowId: Id, cellId: Id) => CellChange;
452
+
453
+ /**
454
+ * The CellChange type describes a Cell's changes during a transaction.
455
+ *
456
+ * This is returned by the GetCellChange function that is provided to every
457
+ * listener when called. This array contains the previous value of a Cell before
458
+ * the current transaction, the new value after it, and a convenience flag that
459
+ * indicates that the value has changed.
460
+ *
461
+ * @category Listener
462
+ */
463
+ export type CellChange = [
464
+ changed: boolean,
465
+ oldCell: CellOrUndefined,
466
+ newCell: CellOrUndefined,
467
+ ];
468
+
469
+ /**
470
+ * The Schema type describes the structure of a Store in terms of valid Table
471
+ * Ids and the types of Cell that can exist within them.
472
+ *
473
+ * A Schema comprises a JavaScript object describing each Table, in turn a
474
+ * nested JavaScript object containing information about each Cell and its
475
+ * CellSchema. It is provided to the setSchema method.
476
+ *
477
+ * @example
478
+ * When applied to a Store, this Schema only allows one Table called `pets`, in
479
+ * which each Row may contain a string `species` Cell, and is guaranteed to
480
+ * contain a boolean `sold` Cell that defaults to `false`.
481
+ *
482
+ *```js
483
+ * const schema: Schema = {
484
+ * pets: {
485
+ * species: {type: 'string'},
486
+ * sold: {type: 'boolean', default: false},
487
+ * },
488
+ * };
489
+ * ```
490
+ * @category Schema
491
+ */
492
+ export type Schema = {
493
+ [tableId: Id]: {
494
+ [cellId: Id]: CellSchema;
495
+ };
496
+ };
497
+
498
+ /**
499
+ * The CellSchema type describes what values are allowed for each Cell in a
500
+ * Table.
501
+ *
502
+ * A CellSchema specifies the type of the Cell (`string`, `boolean`, or
503
+ * `number`), and what the default value can be when an explicit value is not
504
+ * specified.
505
+ *
506
+ * If a default value is provided (and its type is correct), you can be certain
507
+ * that that Cell will always be present in a Row.
508
+ *
509
+ * If the default value is _not_ provided (or its type is incorrect), the Cell
510
+ * may be missing from the Row, but when present you can be guaranteed it is of
511
+ * the correct type.
512
+ *
513
+ * @example
514
+ * When applied to a Store, this CellSchema ensures a boolean Cell is always
515
+ * present, and defaults it to `false`.
516
+ *
517
+ *```js
518
+ * const requiredBoolean: CellSchema = {type: 'boolean', default: false};
519
+ * ```
520
+ * @category Schema
521
+ */
522
+ export type CellSchema =
523
+ | {
524
+ type: 'string';
525
+ default?: string;
526
+ }
527
+ | {
528
+ type: 'number';
529
+ default?: number;
530
+ }
531
+ | {
532
+ type: 'boolean';
533
+ default?: boolean;
534
+ };
535
+
536
+ /**
537
+ * The ChangedCells type describes the Cell values that have been changed during
538
+ * a transaction, primarily used so that you can indicate whether the
539
+ * transaction should be rolled back.
540
+ *
541
+ * A ChangedCells object is provided to the `doRollback` callback when using the
542
+ * transaction method. See that method for specific examples.
543
+ *
544
+ * This type is a nested structure of Table, Row, and Cell objects, much like
545
+ * the Tables object, but one which provides both the old and new Cell values in
546
+ * a two-part array. These are describing the state of each changed Cell in
547
+ * Store at the _start_ of the transaction, and by the _end_ of the transaction.
548
+ *
549
+ * Hence, an `undefined` value for the first item in the array means that the
550
+ * Cell was added during the transaction. An `undefined` value for the second
551
+ * item in the array means that the Cell was removed during the transaction. An
552
+ * array with two different Cell values indicates that it was changed. The
553
+ * two-part array will never contain two items of the same value (including two
554
+ * `undefined` values), even if, during the transaction, a Cell was changed to a
555
+ * different value and then changed back.
556
+ *
557
+ * @category Transaction
558
+ * @since v1.2.0
559
+ */
560
+ export type ChangedCells = {
561
+ [tableId: Id]: {
562
+ [rowId: Id]: {
563
+ [cellId: Id]: [CellOrUndefined, CellOrUndefined];
564
+ };
565
+ };
566
+ };
567
+ /**
568
+ * The InvalidCells type describes the invalid Cell values that have been
569
+ * attempted during a transaction, primarily used so that you can indicate
570
+ * whether the transaction should be rolled back.
571
+ *
572
+ * An InvalidCells object is provided to the `doRollback` callback when using
573
+ * the transaction method. See that method for specific examples.
574
+ *
575
+ * This type is a nested structure of Table, Row, and Cell objects, much like
576
+ * the Tables object, but one for which Cell values are listed in array (much
577
+ * like the InvalidCellListener type) so that multiple failed attempts to change
578
+ * a Cell during the transaction are described.
579
+ *
580
+ * @category Transaction
581
+ * @since v1.2.0
582
+ */
583
+ export type InvalidCells = {
584
+ [tableId: Id]: {
585
+ [rowId: Id]: {
586
+ [cellId: Id]: any[];
587
+ };
588
+ };
589
+ };
590
+
591
+ /**
592
+ * The StoreListenerStats type describes the number of listeners registered with
593
+ * the Store, and can be used for debugging purposes.
594
+ *
595
+ * The StoreListenerStats object contains a breakdown of the different types of
596
+ * listener. Totals include both mutator and non-mutator listeners. A
597
+ * StoreListenerStats object is returned from the getListenerStats method, and
598
+ * is only populated in a debug build.
599
+ *
600
+ * @category Development
601
+ */
602
+ export type StoreListenerStats = {
603
+ /**
604
+ * The number of TablesListener functions registered with the Store.
605
+ */
606
+ tables?: number;
607
+ /**
608
+ * The number of TableIdsListener functions registered with the Store.
609
+ */
610
+ tableIds?: number;
611
+ /**
612
+ * The number of TableListener functions registered with the Store.
613
+ */
614
+ table?: number;
615
+ /**
616
+ * The number of RowIdsListener functions registered with the Store.
617
+ */
618
+ rowIds?: number;
619
+ /**
620
+ * The number of SortedRowIdsListener functions registered with the Store.
621
+ */
622
+ sortedRowIds?: number;
623
+ /**
624
+ * The number of RowListener functions registered with the Store.
625
+ */
626
+ row?: number;
627
+ /**
628
+ * The number of CellIdsListener functions registered with the Store.
629
+ */
630
+ cellIds?: number;
631
+ /**
632
+ * The number of CellListener functions registered with the Store.
633
+ */
634
+ cell?: number;
635
+ /**
636
+ * The number of InvalidCellListener functions registered with the Store.
637
+ */
638
+ invalidCell?: number;
639
+ /**
640
+ * The number of TransactionListener functions registered with the Store.
641
+ */
642
+ transaction?: number;
643
+ };
644
+
645
+ /**
646
+ * A Store is the main location for keeping structured state and tabular data.
647
+ *
648
+ * Create a Store easily with the createStore function. From there, you can set
649
+ * and get data, add listeners for when the data changes, set a Schema, and so
650
+ * on.
651
+ *
652
+ * A Store has a simple hierarchical structure:
653
+ *
654
+ * - The Store contains a number of Table objects.
655
+ * - Each Table contains a number of Row objects.
656
+ * - Each Row contains a number of Cell objects.
657
+ *
658
+ * A Cell is a string, boolean, or number value.
659
+ *
660
+ * The members of each level of this hierarchy are identified with a unique Id
661
+ * (which is a string). In other words you can naively think of a Store as a
662
+ * three-level-deep JavaScript object, keyed with strings:
663
+ *
664
+ * ```json
665
+ * { // Store
666
+ * "table1": { // Table
667
+ * "row1": { // Row
668
+ * "cell1": "one", // Cell (string)
669
+ * "cell2": true, // Cell (boolean)
670
+ * "cell3": 3, // Cell (number)
671
+ * ...
672
+ * },
673
+ * ...
674
+ * },
675
+ * ...
676
+ * }
677
+ * ```
678
+ *
679
+ * In its default form, a Store has no sense of a structured schema, so, as long
680
+ * as they are unique within their own parent, the Id keys can each be any
681
+ * string you want. However, you _can_ optionally specify a Schema for a Store,
682
+ * which then usefully constrains the Table and Cell Ids (and Cell values) you
683
+ * can use.
684
+ *
685
+ * # Setting and getting data
686
+ *
687
+ * Every part of the Store can be accessed with getter methods. When you
688
+ * retrieve data from the Store, you are receiving a copy - rather than a
689
+ * reference - of it. This means that manipulating the data in the Store must be
690
+ * performed with the equivalent setter and deleter methods.
691
+ *
692
+ * To benefit from the reactive behavior of the Store, you can also subscribe to
693
+ * changes on any part of it with 'listeners'. Registering a listener returns a
694
+ * listener Id (that you can use later to remove it with the delListener
695
+ * method), and it will then be called every time there is a change within the
696
+ * part of the hierarchy you're listening to.
697
+ *
698
+ * This table shows the main ways you can set, get, and listen to, different
699
+ * types of data in a Store:
700
+ *
701
+ * |Type|Get data|Set data|Delete data|Add a listener|
702
+ * |-|-|-|-|-|
703
+ * |Tables|getTables|setTables|delTables|addTablesListener|
704
+ * |Table Ids|getTableIds|-|-|addTableIdsListener|
705
+ * |Table|getTable|setTable|delTable|addTableListener|
706
+ * |Row Ids|getRowIds|-|-|addRowIdsListener|
707
+ * |Row Ids (sorted)|getSortedRowIds|-|-|addSortedRowIdsListener|
708
+ * |Row|getRow|setRow|delRow|addRowListener|
709
+ * |Cell Ids|getCellIds|-|-|addCellIdsListener|
710
+ * |Cell|getCell|setCell|delCell|addCellListener|
711
+ *
712
+ * Additionally, there are two extra methods to manipulate Row objects. The
713
+ * addRow method is like the setRow method but automatically assigns it a new
714
+ * unique Id. And the setPartialRow method lets you update multiple Cell values
715
+ * in a Row without affecting the others.
716
+ *
717
+ * You can listen to attempts to write invalid data to a Cell with the
718
+ * addInvalidCellListener method.
719
+ *
720
+ * The transaction method is used to wrap multiple changes to the Store so that
721
+ * the relevant listeners only fire once.
722
+ *
723
+ * The setJson method and the getJson method allow you to work with a
724
+ * JSON-encoded representation of the entire Store, which is useful for
725
+ * persisting it.
726
+ *
727
+ * Finally, the callListener method provides a way for you to manually provoke a
728
+ * listener to be called, even if the underlying data hasn't changed. This is
729
+ * useful when you are using mutator listeners to guarantee that data conforms
730
+ * to programmatic conditions, and those conditions change such that you need to
731
+ * update the Store in bulk.
732
+ *
733
+ * Read more about setting and changing data in The Basics guides, and about
734
+ * listeners in the Listening to Stores guide.
735
+ *
736
+ * # Creating a Schema
737
+ *
738
+ * You can set a Schema on a Store when you create it with createStore function,
739
+ * or at a later stage with the setSchema method. A Schema constrains the Table
740
+ * Ids the Store can have, and the types of Cell data in each Table. Each Cell
741
+ * requires its type to be specified, and can also take a default value for when
742
+ * it's not specified.
743
+ *
744
+ * You can also get a serialization of the Schema out of the Store with the
745
+ * getSchemaJson method, and remove the Schema altogether with the delSchema
746
+ * method.
747
+ *
748
+ * Read more about schemas in the Using Schemas guide.
749
+ *
750
+ * # Convenience methods
751
+ *
752
+ * There are a few additional helper methods to make it easier to work with a
753
+ * Store. There are methods for easily checking the existence of a Table, Row,
754
+ * or Cell, and iterators that let you act on the children of a common parent:
755
+ *
756
+ * ||Checking existence|Iterator|
757
+ * |-|-|-|
758
+ * |Table|hasTable|forEachTable|
759
+ * |Row|hasRow|forEachRow|
760
+ * |Cell|hasCell|forEachCell|
761
+ *
762
+ * Finally, the getListenerStats method describes the current state of the
763
+ * Store's listeners for debugging purposes.
764
+ *
765
+ * @example
766
+ * This example shows a very simple lifecycle of a Store: from creation, to
767
+ * adding and getting some data, and then registering and removing a listener.
768
+ *
769
+ * ```js
770
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
771
+ * console.log(store.getRow('pets', 'fido'));
772
+ * // -> {species: 'dog'}
773
+ *
774
+ * store.setCell('pets', 'fido', 'color', 'brown');
775
+ * console.log(store.getCell('pets', 'fido', 'color'));
776
+ * // -> 'brown'
777
+ *
778
+ * const listenerId = store.addTableListener('pets', () => {
779
+ * console.log('changed');
780
+ * });
781
+ *
782
+ * store.setCell('pets', 'fido', 'sold', false);
783
+ * // -> 'changed'
784
+ *
785
+ * store.delListener(listenerId);
786
+ * ```
787
+ * @see The Basics guides
788
+ * @see Using Schemas guides
789
+ * @see Hello World demos
790
+ * @see Todo App demos
791
+ * @category Store
792
+ */
793
+ export interface Store {
794
+ /**
795
+ * The getTables method returns a Tables object containing the entire data of
796
+ * the Store.
797
+ *
798
+ * Note that this returns a copy of, rather than a reference to the underlying
799
+ * data, so changes made to the returned object are not made to the Store
800
+ * itself.
801
+ *
802
+ * @returns A Tables object containing the entire data of the Store.
803
+ * @example
804
+ * This example retrieves the data in a Store.
805
+ *
806
+ * ```js
807
+ * const store = createStore().setTables({
808
+ * pets: {fido: {species: 'dog'}},
809
+ * species: {dog: {price: 5}},
810
+ * });
811
+ * console.log(store.getTables());
812
+ * // -> {pets: {fido: {species: 'dog'}}, species: {dog: {price: 5}}}
813
+ * ```
814
+ * @example
815
+ * This example retrieves the Tables of an empty Store, returning an empty
816
+ * object.
817
+ *
818
+ * ```js
819
+ * const store = createStore();
820
+ * console.log(store.getTables());
821
+ * // -> {}
822
+ * ```
823
+ * @see
824
+ * # Guides
825
+ * Creating a Store
826
+ * @see Indexes
827
+ * @category Getter
828
+ */
829
+ getTables(): Tables;
830
+
831
+ /**
832
+ * The getTableIds method returns the Ids of every Table in the Store.
833
+ *
834
+ * Note that this returns a copy of, rather than a reference, to the list of
835
+ * Ids, so changes made to the list are not made to the Store itself.
836
+ *
837
+ * @returns An array of the Ids of every Table in the Store.
838
+ * @example
839
+ * This example retrieves the Table Ids in a Store.
840
+ *
841
+ * ```js
842
+ * const store = createStore().setTables({
843
+ * pets: {fido: {species: 'dog'}},
844
+ * species: {dog: {price: 5}},
845
+ * });
846
+ * console.log(store.getTableIds());
847
+ * // -> ['pets', 'species']
848
+ * ```
849
+ * @example
850
+ * This example retrieves the Table Ids of an empty Store, returning an empty
851
+ * array.
852
+ *
853
+ * ```js
854
+ * const store = createStore();
855
+ * console.log(store.getTableIds());
856
+ * // -> []
857
+ * ```
858
+ * @category Getter
859
+ */
860
+ getTableIds(): Ids;
861
+
862
+ /**
863
+ * The getTable method returns an object containing the entire data of a
864
+ * single Table in the Store.
865
+ *
866
+ * Note that this returns a copy of, rather than a reference to the underlying
867
+ * data, so changes made to the returned object are not made to the Store
868
+ * itself.
869
+ *
870
+ * @param tableId The Id of the Table in the Store.
871
+ * @returns An object containing the entire data of the Table.
872
+ * @example
873
+ * This example retrieves the data in a single Table.
874
+ *
875
+ * ```js
876
+ * const store = createStore().setTables({
877
+ * pets: {fido: {species: 'dog'}},
878
+ * species: {dog: {price: 5}},
879
+ * });
880
+ * console.log(store.getTable('pets'));
881
+ * // -> {fido: {species: 'dog'}}
882
+ * ```
883
+ * @example
884
+ * This example retrieves a Table that does not exist, returning an empty
885
+ * object.
886
+ *
887
+ * ```js
888
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
889
+ * console.log(store.getTable('employees'));
890
+ * // -> {}
891
+ * ```
892
+ * @category Getter
893
+ */
894
+ getTable(tableId: Id): Table;
895
+
896
+ /**
897
+ * The getRowIds method returns the Ids of every Row in a given Table.
898
+ *
899
+ * Note that this returns a copy of, rather than a reference, to the list of
900
+ * Ids, so changes made to the list are not made to the Store itself.
901
+ *
902
+ * @param tableId The Id of the Table in the Store.
903
+ * @returns An array of the Ids of every Row in the Table.
904
+ * @example
905
+ * This example retrieves the Row Ids in a Table.
906
+ *
907
+ * ```js
908
+ * const store = createStore().setTables({
909
+ * pets: {
910
+ * fido: {species: 'dog'},
911
+ * felix: {species: 'cat'},
912
+ * },
913
+ * });
914
+ * console.log(store.getRowIds('pets'));
915
+ * // -> ['fido', 'felix']
916
+ * ```
917
+ * @example
918
+ * This example retrieves the Row Ids of a Table that does not exist,
919
+ * returning an empty array.
920
+ *
921
+ * ```js
922
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
923
+ * console.log(store.getRowIds('employees'));
924
+ * // -> []
925
+ * ```
926
+ * @category Getter
927
+ */
928
+ getRowIds(tableId: Id): Ids;
929
+
930
+ /**
931
+ * The getSortedRowIds method returns the Ids of every Row in a given Table,
932
+ * sorted according to the values in a specified Cell.
933
+ *
934
+ * The sorting of the rows is alphanumeric, and you can indicate whether it
935
+ * should be in descending order. The `offset` and `limit` parameters are used
936
+ * to paginate results, but default to `0` and `undefined` to return all
937
+ * available Row Ids if not specified.
938
+ *
939
+ * Note that every call to this method will perform the sorting afresh - there
940
+ * is no caching of the results - and so you are advised to memoize the
941
+ * results yourself, especially when the Table is large. For a performant
942
+ * approach to tracking the sorted Row Ids when they change, use the
943
+ * addSortedRowIdsListener method.
944
+ *
945
+ * If the Table does not exist, an empty array is returned.
946
+ *
947
+ * @param tableId The Id of the Table in the Store.
948
+ * @param cellId The Id of the Cell whose values are used for the sorting, or
949
+ * `undefined` to by sort the Row Id itself.
950
+ * @param descending Whether the sorting should be in descending order.
951
+ * @param offset The number of Row Ids to skip for pagination purposes, if
952
+ * any.
953
+ * @param limit The maximum number of Row Ids to return, or `undefined` for
954
+ * all.
955
+ * @returns An array of the sorted Ids of every Row in the Table.
956
+ * @example
957
+ * This example retrieves sorted Row Ids in a Table.
958
+ *
959
+ * ```js
960
+ * const store = createStore().setTables({
961
+ * pets: {
962
+ * fido: {species: 'dog'},
963
+ * felix: {species: 'cat'},
964
+ * },
965
+ * });
966
+ * console.log(store.getSortedRowIds('pets', 'species'));
967
+ * // -> ['felix', 'fido']
968
+ * ```
969
+ * @example
970
+ * This example retrieves sorted Row Ids in a Table in reverse order.
971
+ *
972
+ * ```js
973
+ * const store = createStore().setTables({
974
+ * pets: {
975
+ * fido: {species: 'dog'},
976
+ * felix: {species: 'cat'},
977
+ * cujo: {species: 'wolf'},
978
+ * },
979
+ * });
980
+ * console.log(store.getSortedRowIds('pets', 'species', true));
981
+ * // -> ['cujo', 'fido', 'felix']
982
+ * ```
983
+ * @example
984
+ * This example retrieves two pages of Row Ids in a Table.
985
+ *
986
+ * ```js
987
+ * const store = createStore().setTables({
988
+ * pets: {
989
+ * fido: {price: 6},
990
+ * felix: {price: 5},
991
+ * mickey: {price: 2},
992
+ * tom: {price: 4},
993
+ * carnaby: {price: 3},
994
+ * lowly: {price: 1},
995
+ * },
996
+ * });
997
+ * console.log(store.getSortedRowIds('pets', 'price', false, 0, 2));
998
+ * // -> ['lowly', 'mickey']
999
+ * console.log(store.getSortedRowIds('pets', 'price', false, 2, 2));
1000
+ * // -> ['carnaby', 'tom']
1001
+ * ```
1002
+ * @example
1003
+ * This example retrieves Row Ids sorted by their own value, since the
1004
+ * `cellId` parameter is undefined.
1005
+ *
1006
+ * ```js
1007
+ * const store = createStore().setTables({
1008
+ * pets: {
1009
+ * fido: {species: 'dog'},
1010
+ * felix: {species: 'cat'},
1011
+ * cujo: {species: 'wolf'},
1012
+ * },
1013
+ * });
1014
+ * console.log(store.getSortedRowIds('pets'));
1015
+ * // -> ['cujo', 'felix', 'fido']
1016
+ * ```
1017
+ * @example
1018
+ * This example retrieves the sorted Row Ids of a Table that does not exist,
1019
+ * returning an empty array.
1020
+ *
1021
+ * ```js
1022
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1023
+ * console.log(store.getSortedRowIds('employees'));
1024
+ * // -> []
1025
+ * ```
1026
+ * @category Getter
1027
+ * @since v2.0.0
1028
+ */
1029
+ getSortedRowIds(
1030
+ tableId: Id,
1031
+ cellId?: Id,
1032
+ descending?: boolean,
1033
+ offset?: number,
1034
+ limit?: number,
1035
+ ): Ids;
1036
+
1037
+ /**
1038
+ * The getRow method returns an object containing the entire data of a single
1039
+ * Row in a given Table.
1040
+ *
1041
+ * Note that this returns a copy of, rather than a reference to the underlying
1042
+ * data, so changes made to the returned object are not made to the Store
1043
+ * itself.
1044
+ *
1045
+ * @param tableId The Id of the Table in the Store.
1046
+ * @param rowId The Id of the Row in the Table.
1047
+ * @returns An object containing the entire data of the Row.
1048
+ * @example
1049
+ * This example retrieves the data in a single Row.
1050
+ *
1051
+ * ```js
1052
+ * const store = createStore().setTables({
1053
+ * pets: {
1054
+ * fido: {species: 'dog'},
1055
+ * felix: {species: 'cat'},
1056
+ * },
1057
+ * });
1058
+ * console.log(store.getRow('pets', 'fido'));
1059
+ * // -> {species: 'dog'}
1060
+ * ```
1061
+ * @example
1062
+ * This example retrieves a Row that does not exist, returning an empty
1063
+ * object.
1064
+ *
1065
+ * ```js
1066
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1067
+ * console.log(store.getRow('pets', 'felix'));
1068
+ * // -> {}
1069
+ * ```
1070
+ * @category Getter
1071
+ */
1072
+ getRow(tableId: Id, rowId: Id): Row;
1073
+
1074
+ /**
1075
+ * The getCellIds method returns the Ids of every Cell in a given Row, in a
1076
+ * given Table.
1077
+ *
1078
+ * Note that this returns a copy of, rather than a reference, to the list of
1079
+ * Ids, so changes made to the list are not made to the Store itself.
1080
+ *
1081
+ * @param tableId The Id of the Table in the Store.
1082
+ * @param rowId The Id of the Row in the Table.
1083
+ * @returns An array of the Ids of every Cell in the Row.
1084
+ * @example
1085
+ * This example retrieves the Cell Ids in a Row.
1086
+ *
1087
+ * ```js
1088
+ * const store = createStore().setTables({
1089
+ * pets: {
1090
+ * fido: {species: 'dog', color: 'brown'},
1091
+ * },
1092
+ * });
1093
+ * console.log(store.getCellIds('pets', 'fido'));
1094
+ * // -> ['species', 'color']
1095
+ * ```
1096
+ * @example
1097
+ * This example retrieves the Cell Ids of a Cell that does not exist,
1098
+ * returning an empty array.
1099
+ *
1100
+ * ```js
1101
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1102
+ * console.log(store.getCellIds('pets', 'felix'));
1103
+ * // -> []
1104
+ * ```
1105
+ * @category Getter
1106
+ */
1107
+ getCellIds(tableId: Id, rowId: Id): Ids;
1108
+
1109
+ /**
1110
+ * The getCell method returns the value of a single Cell in a given Row, in a
1111
+ * given Table.
1112
+ *
1113
+ * @param tableId The Id of the Table in the Store.
1114
+ * @param rowId The Id of the Row in the Table.
1115
+ * @param cellId The Id of the Cell in the Row.
1116
+ * @returns The value of the Cell, or `undefined`.
1117
+ * @example
1118
+ * This example retrieves a single Cell.
1119
+ *
1120
+ * ```js
1121
+ * const store = createStore().setTables({
1122
+ * pets: {fido: {species: 'dog', color: 'brown'}},
1123
+ * });
1124
+ * console.log(store.getCell('pets', 'fido', 'species'));
1125
+ * // -> 'dog'
1126
+ * ```
1127
+ * @example
1128
+ * This example retrieves a Cell that does not exist, returning `undefined`.
1129
+ *
1130
+ * ```js
1131
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1132
+ * console.log(store.getCell('pets', 'fido', 'color'));
1133
+ * // -> undefined
1134
+ * ```
1135
+ * @category Getter
1136
+ */
1137
+ getCell(tableId: Id, rowId: Id, cellId: Id): CellOrUndefined;
1138
+
1139
+ /**
1140
+ * The hasTables method returns a boolean indicating whether any Table objects
1141
+ * exist in the Store.
1142
+ *
1143
+ * @returns Whether any Tables exist.
1144
+ * @example
1145
+ * This example shows simple existence checks.
1146
+ *
1147
+ * ```js
1148
+ * const store = createStore();
1149
+ * console.log(store.hasTables());
1150
+ * // -> false
1151
+ * store.setTables({pets: {fido: {species: 'dog'}}});
1152
+ * console.log(store.hasTables());
1153
+ * // -> true
1154
+ * ```
1155
+ * @category Getter
1156
+ */
1157
+ hasTables(): boolean;
1158
+
1159
+ /**
1160
+ * The hasTable method returns a boolean indicating whether a given Table
1161
+ * exists in the Store.
1162
+ *
1163
+ * @param tableId The Id of a possible Table in the Store.
1164
+ * @returns Whether a Table with that Id exists.
1165
+ * @example
1166
+ * This example shows two simple Table existence checks.
1167
+ *
1168
+ * ```js
1169
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1170
+ * console.log(store.hasTable('pets'));
1171
+ * // -> true
1172
+ * console.log(store.hasTable('employees'));
1173
+ * // -> false
1174
+ * ```
1175
+ * @category Getter
1176
+ */
1177
+ hasTable(tableId: Id): boolean;
1178
+
1179
+ /**
1180
+ * The hasRow method returns a boolean indicating whether a given Row exists
1181
+ * in the Store.
1182
+ *
1183
+ * @param tableId The Id of a possible Table in the Store.
1184
+ * @param rowId The Id of a possible Row in the Table.
1185
+ * @returns Whether a Row with that Id exists in that Table.
1186
+ * @example
1187
+ * This example shows two simple Row existence checks.
1188
+ *
1189
+ * ```js
1190
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1191
+ * console.log(store.hasRow('pets', 'fido'));
1192
+ * // -> true
1193
+ * console.log(store.hasRow('pets', 'felix'));
1194
+ * // -> false
1195
+ * ```
1196
+ * @category Getter
1197
+ */
1198
+ hasRow(tableId: Id, rowId: Id): boolean;
1199
+
1200
+ /**
1201
+ * The hasCell method returns a boolean indicating whether a given Cell exists
1202
+ * in the Store.
1203
+ *
1204
+ * @param tableId The Id of a possible Table in the Store.
1205
+ * @param rowId The Id of a possible Row in the Table.
1206
+ * @param cellId The Id of a possible Cell in the Row.
1207
+ * @returns Whether a Cell with that Id exists in that Row in that Table.
1208
+ * @example
1209
+ * This example shows two simple Cell existence checks.
1210
+ *
1211
+ * ```js
1212
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1213
+ * console.log(store.hasCell('pets', 'fido', 'species'));
1214
+ * // -> true
1215
+ * console.log(store.hasCell('pets', 'fido', 'color'));
1216
+ * // -> false
1217
+ * ```
1218
+ * @category Getter
1219
+ */
1220
+ hasCell(tableId: Id, rowId: Id, cellId: Id): boolean;
1221
+
1222
+ /**
1223
+ * The getJson method returns a string serialization of all of the Tables in
1224
+ * the Store.
1225
+ *
1226
+ * @returns A string serialization of all of the Tables in the Store.
1227
+ * @example
1228
+ * This example serializes the contents of a Store.
1229
+ *
1230
+ * ```js
1231
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1232
+ * console.log(store.getJson());
1233
+ * // -> '{"pets":{"fido":{"species":"dog"}}}'
1234
+ * ```
1235
+ * @example
1236
+ * This example serializes the contents of an empty Store.
1237
+ *
1238
+ * ```js
1239
+ * const store = createStore();
1240
+ * console.log(store.getJson());
1241
+ * // -> '{}'
1242
+ * ```
1243
+ * @category Getter
1244
+ */
1245
+ getJson(): Json;
1246
+
1247
+ /**
1248
+ * The getSchemaJson method returns a string serialization of the Schema of
1249
+ * the Store.
1250
+ *
1251
+ * If no Schema has been set on the Store (or if it has been removed with the
1252
+ * delSchema method), then it will return the serialization of an empty
1253
+ * object, `{}`.
1254
+ *
1255
+ * @returns A string serialization of the Schema of the Store.
1256
+ * @example
1257
+ * This example serializes the Schema of a Store.
1258
+ *
1259
+ * ```js
1260
+ * const store = createStore().setSchema({
1261
+ * pets: {
1262
+ * species: {type: 'string'},
1263
+ * sold: {type: 'boolean'},
1264
+ * },
1265
+ * });
1266
+ * console.log(store.getSchemaJson());
1267
+ * // -> '{"pets":{"species":{"type":"string"},"sold":{"type":"boolean"}}}'
1268
+ * ```
1269
+ * @example
1270
+ * This example serializes the Schema of an empty Store.
1271
+ *
1272
+ * ```js
1273
+ * const store = createStore();
1274
+ * console.log(store.getSchemaJson());
1275
+ * // -> '{}'
1276
+ * ```
1277
+ * @category Getter
1278
+ */
1279
+ getSchemaJson(): Json;
1280
+
1281
+ /**
1282
+ * The setTables method takes an object and sets the entire data of the Store.
1283
+ *
1284
+ * This method will cause listeners to be called for any Table, Row, Cell, or
1285
+ * Id changes resulting from it.
1286
+ *
1287
+ * Any part of the provided object that is invalid (either according to the
1288
+ * Tables type, or because it does not match a Schema associated with the
1289
+ * Store), will be ignored silently.
1290
+ *
1291
+ * Assuming that at least some of the provided Tables object is valid, any
1292
+ * data that was already present in the Store will be completely overwritten.
1293
+ * If the object is completely invalid, no change will be made to the Store.
1294
+ *
1295
+ * The method returns a reference to the Store to that subsequent operations
1296
+ * can be chained in a fluent style.
1297
+ *
1298
+ * @param tables The data of the Store to be set.
1299
+ * @example
1300
+ * This example sets the data of a Store.
1301
+ *
1302
+ * ```js
1303
+ * const store = createStore().setTables({
1304
+ * pets: {fido: {species: 'dog'}},
1305
+ * species: {dog: {price: 5}},
1306
+ * });
1307
+ * console.log(store.getTables());
1308
+ * // -> {pets: {fido: {species: 'dog'}}, species: {dog: {price: 5}}}
1309
+ * ```
1310
+ * @example
1311
+ * This example attempts to set the data of an existing Store with partly
1312
+ * invalid, and then completely invalid, Tables objects.
1313
+ *
1314
+ * ```js
1315
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1316
+ *
1317
+ * store.setTables({pets: {felix: {species: 'cat', bug: []}}});
1318
+ * console.log(store.getTables());
1319
+ * // -> {pets: {felix: {species: 'cat'}}}
1320
+ *
1321
+ * store.setTables({meaning: 42});
1322
+ * console.log(store.getTables());
1323
+ * // -> {pets: {felix: {species: 'cat'}}}
1324
+ * ```
1325
+ * @category Setter
1326
+ */
1327
+ setTables(tables: Tables): Store;
1328
+
1329
+ /**
1330
+ * The setTable method takes an object and sets the entire data of a single
1331
+ * Table in the Store.
1332
+ *
1333
+ * This method will cause listeners to be called for any Table, Row, Cell, or
1334
+ * Id changes resulting from it.
1335
+ *
1336
+ * Any part of the provided object that is invalid (either according to the
1337
+ * Table type, or because it does not match a Schema associated with the
1338
+ * Store), will be ignored silently.
1339
+ *
1340
+ * Assuming that at least some of the provided Table object is valid, any data
1341
+ * that was already present in the Store for that Table will be completely
1342
+ * overwritten. If the object is completely invalid, no change will be made to
1343
+ * the Store.
1344
+ *
1345
+ * The method returns a reference to the Store to that subsequent operations
1346
+ * can be chained in a fluent style.
1347
+ *
1348
+ * @param tableId The Id of the Table in the Store.
1349
+ * @param table The data of a single Table to be set.
1350
+ * @example
1351
+ * This example sets the data of a single Table.
1352
+ *
1353
+ * ```js
1354
+ * const store = createStore().setTable('pets', {
1355
+ * fido: {species: 'dog'},
1356
+ * felix: {species: 'cat'},
1357
+ * });
1358
+ * console.log(store.getTables());
1359
+ * // -> {pets: {fido: {species: 'dog'}, felix: {species: 'cat'}}}
1360
+ * ```
1361
+ * @example
1362
+ * This example attempts to set the data of an existing Store with partly
1363
+ * invalid, and then completely invalid, Table objects.
1364
+ *
1365
+ * ```js
1366
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1367
+ *
1368
+ * store.setTable('pets', {felix: {species: 'cat', bug: []}});
1369
+ * console.log(store.getTables());
1370
+ * // -> {pets: {felix: {species: 'cat'}}}
1371
+ *
1372
+ * store.setTable('pets', {meaning: 42});
1373
+ * console.log(store.getTables());
1374
+ * // -> {pets: {felix: {species: 'cat'}}}
1375
+ * ```
1376
+ * @category Setter
1377
+ */
1378
+ setTable(tableId: Id, table: Table): Store;
1379
+
1380
+ /**
1381
+ * The setRow method takes an object and sets the entire data of a single Row
1382
+ * in the Store.
1383
+ *
1384
+ * This method will cause listeners to be called for any Table, Row, Cell, or
1385
+ * Id changes resulting from it.
1386
+ *
1387
+ * Any part of the provided object that is invalid (either according to the
1388
+ * Row type, or because it does not match a Schema associated with the Store),
1389
+ * will be ignored silently.
1390
+ *
1391
+ * Assuming that at least some of the provided Row object is valid, any data
1392
+ * that was already present in the Store for that Row will be completely
1393
+ * overwritten. If the object is completely invalid, no change will be made to
1394
+ * the Store.
1395
+ *
1396
+ * The method returns a reference to the Store to that subsequent operations
1397
+ * can be chained in a fluent style.
1398
+ *
1399
+ * @param tableId The Id of the Table in the Store.
1400
+ * @param rowId The Id of the Row in the Table.
1401
+ * @param row The data of a single Row to be set.
1402
+ * @returns A reference to the Store.
1403
+ * @example
1404
+ * This example sets the data of a single Row.
1405
+ *
1406
+ * ```js
1407
+ * const store = createStore().setRow('pets', 'fido', {species: 'dog'});
1408
+ * console.log(store.getTables());
1409
+ * // -> {pets: {fido: {species: 'dog'}}}
1410
+ * ```
1411
+ * @example
1412
+ * This example attempts to set the data of an existing Store with partly
1413
+ * invalid, and then completely invalid, Row objects.
1414
+ *
1415
+ * ```js
1416
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1417
+ *
1418
+ * store.setRow('pets', 'fido', {color: 'brown', bug: []});
1419
+ * console.log(store.getTables());
1420
+ * // -> {pets: {fido: {color: 'brown'}}}
1421
+ *
1422
+ * store.setRow('pets', 'fido', 42);
1423
+ * console.log(store.getTables());
1424
+ * // -> {pets: {fido: {color: 'brown'}}}
1425
+ * ```
1426
+ * @category Setter
1427
+ */
1428
+ setRow(tableId: Id, rowId: Id, row: Row): Store;
1429
+
1430
+ /**
1431
+ * The addRow method takes an object and creates a new Row in the Store,
1432
+ * returning the unique Id assigned to it.
1433
+ *
1434
+ * This method will cause listeners to be called for any Table, Row, Cell, or
1435
+ * Id changes resulting from it.
1436
+ *
1437
+ * Any part of the provided object that is invalid (either according to the
1438
+ * Row type, or because it does not match a Schema associated with the Store),
1439
+ * will be ignored silently.
1440
+ *
1441
+ * Assuming that at least some of the provided Row object is valid, a new Row
1442
+ * will be created. If the object is completely invalid, no change will be
1443
+ * made to the Store and the method will return `undefined`
1444
+ *
1445
+ * You should not guarantee the form of the unique Id that is generated when a
1446
+ * Row is added to the Table. However it is likely to be a string
1447
+ * representation of an increasing integer.
1448
+ *
1449
+ * @param tableId The Id of the Table in the Store.
1450
+ * @param row The data of a single Row to be added.
1451
+ * @returns A reference to the Store.
1452
+ * @example
1453
+ * This example adds a single Row.
1454
+ *
1455
+ * ```js
1456
+ * const store = createStore();
1457
+ * console.log(store.addRow('pets', {species: 'dog'}));
1458
+ * // -> '0'
1459
+ * console.log(store.getTables());
1460
+ * // -> {pets: {'0': {species: 'dog'}}}
1461
+ * ```
1462
+ * @example
1463
+ * This example attempts to add Rows to an existing Store with partly invalid,
1464
+ * and then completely invalid, Row objects.
1465
+ *
1466
+ * ```js
1467
+ * const store = createStore().setTables({pets: {'0': {species: 'dog'}}});
1468
+ *
1469
+ * console.log(store.addRow('pets', {species: 'cat', bug: []}));
1470
+ * // -> '1'
1471
+ * console.log(store.getTables());
1472
+ * // -> {pets: {'0': {species: 'dog'}, '1': {species: 'cat'}}}
1473
+ *
1474
+ * console.log(store.addRow('pets', 42));
1475
+ * // -> undefined
1476
+ * console.log(store.getTables());
1477
+ * // -> {pets: {'0': {species: 'dog'}, '1': {species: 'cat'}}}
1478
+ * ```
1479
+ * @category Setter
1480
+ */
1481
+ addRow(tableId: Id, row: Row): Id | undefined;
1482
+
1483
+ /**
1484
+ * The setPartialRow method takes an object and sets partial data of a single
1485
+ * Row in the Store, leaving other Cell values unaffected.
1486
+ *
1487
+ * This method will cause listeners to be called for any Table, Row, Cell, or
1488
+ * Id changes resulting from it.
1489
+ *
1490
+ * Any part of the provided object that is invalid (either according to the
1491
+ * Row type, or because, when combined with the current Row data, it does not
1492
+ * match a Schema associated with the Store), will be ignored silently.
1493
+ *
1494
+ * Assuming that at least some of the provided Row object is valid, it will be
1495
+ * merged with the data that was already present in the Store. If the object
1496
+ * is completely invalid, no change will be made to the Store.
1497
+ *
1498
+ * The method returns a reference to the Store to that subsequent operations
1499
+ * can be chained in a fluent style.
1500
+ *
1501
+ * @param tableId The Id of the Table in the Store.
1502
+ * @param rowId The Id of the Row in the Table.
1503
+ * @param partialRow The partial data of a single Row to be set.
1504
+ * @returns A reference to the Store.
1505
+ * @example
1506
+ * This example sets some of the data of a single Row.
1507
+ *
1508
+ * ```js
1509
+ * const store = createStore().setTables({
1510
+ * pets: {fido: {species: 'dog', color: 'brown'}},
1511
+ * });
1512
+ * store.setPartialRow('pets', 'fido', {color: 'walnut', visits: 1});
1513
+ * console.log(store.getTables());
1514
+ * // -> {pets: {fido: {species: 'dog', color: 'walnut', visits: 1}}}
1515
+ * ```
1516
+ * @example
1517
+ * This example attempts to set some of the data of an existing Store with
1518
+ * partly invalid, and then completely invalid, Row objects.
1519
+ *
1520
+ * ```js
1521
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1522
+ *
1523
+ * store.setPartialRow('pets', 'fido', {color: 'brown', bug: []});
1524
+ * console.log(store.getTables());
1525
+ * // -> {pets: {fido: {species: 'dog', color: 'brown'}}}
1526
+ *
1527
+ * store.setPartialRow('pets', 'fido', 42);
1528
+ * console.log(store.getTables());
1529
+ * // -> {pets: {fido: {species: 'dog', color: 'brown'}}}
1530
+ * ```
1531
+ * @category Setter
1532
+ */
1533
+ setPartialRow(tableId: Id, rowId: Id, partialRow: Row): Store;
1534
+
1535
+ /**
1536
+ * The setCell method sets the value of a single Cell in the Store.
1537
+ *
1538
+ * This method will cause listeners to be called for any Table, Row, Cell, or
1539
+ * Id changes resulting from it.
1540
+ *
1541
+ * If the Cell value is invalid (either because of its type, or because it
1542
+ * does not match a Schema associated with the Store), will be ignored
1543
+ * silently.
1544
+ *
1545
+ * As well as string, number, or boolean Cell types, this method can also take
1546
+ * a MapCell function that takes the current Cell value as a parameter and
1547
+ * maps it. This is useful if you want to efficiently increment a value
1548
+ * without fetching it first, for example.
1549
+ *
1550
+ * The method returns a reference to the Store to that subsequent operations
1551
+ * can be chained in a fluent style.
1552
+ *
1553
+ * @param tableId The Id of the Table in the Store.
1554
+ * @param rowId The Id of the Row in the Table.
1555
+ * @param cellId The Id of the Cell in the Row.
1556
+ * @param cell The value of the Cell to be set, or a MapCell function to
1557
+ * update it.
1558
+ * @returns A reference to the Store.
1559
+ * @example
1560
+ * This example sets the value of a single Cell.
1561
+ *
1562
+ * ```js
1563
+ * const store = createStore().setCell('pets', 'fido', 'species', 'dog');
1564
+ * console.log(store.getTables());
1565
+ * // -> {pets: {fido: {species: 'dog'}}}
1566
+ * ```
1567
+ * @example
1568
+ * This example sets the data of a single Cell by mapping the existing value.
1569
+ *
1570
+ * ```js
1571
+ * const increment = (cell) => cell + 1;
1572
+ * const store = createStore().setTables({pets: {fido: {visits: 1}}});
1573
+ *
1574
+ * store.setCell('pets', 'fido', 'visits', increment);
1575
+ * console.log(store.getCell('pets', 'fido', 'visits'));
1576
+ * // -> 2
1577
+ * ```
1578
+ * @example
1579
+ * This example attempts to set the data of an existing Store with an invalid
1580
+ * Cell value.
1581
+ *
1582
+ * ```js
1583
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1584
+ *
1585
+ * store.setCell('pets', 'fido', 'bug', []);
1586
+ * console.log(store.getTables());
1587
+ * // -> {pets: {fido: {species: 'dog'}}}
1588
+ * ```
1589
+ * @category Setter
1590
+ */
1591
+ setCell(tableId: Id, rowId: Id, cellId: Id, cell: Cell | MapCell): Store;
1592
+
1593
+ /**
1594
+ * The setJson method takes a string serialization of all of the Tables in the
1595
+ * Store and attempts to update it to that value
1596
+ *
1597
+ * If the JSON cannot be parsed, this will fail silently. If it can be parsed,
1598
+ * it will then be subject to the same validation rules as the setTables
1599
+ * method (according to the Tables type, and matching any Schema associated
1600
+ * with the Store).
1601
+ *
1602
+ * @param json A string serialization of all of the Tables in the Store.
1603
+ * @returns A reference to the Store.
1604
+ * @example
1605
+ * This example sets the contents of a Store from a serialization.
1606
+ *
1607
+ * ```js
1608
+ * const store = createStore();
1609
+ * store.setJson('{"pets":{"fido":{"species":"dog"}}}');
1610
+ * console.log(store.getTables());
1611
+ * // -> {pets: {fido: {species: 'dog'}}}
1612
+ * ```
1613
+ * @example
1614
+ * This example attempts to set the contents of a Store from an invalid
1615
+ * serialization.
1616
+ *
1617
+ * ```js
1618
+ * const store = createStore();
1619
+ * store.setJson('{"pets":{"fido":{');
1620
+ * console.log(store.getTables());
1621
+ * // -> {}
1622
+ * ```
1623
+ * @category Setter
1624
+ */
1625
+ setJson(json: Json): Store;
1626
+
1627
+ /**
1628
+ * The setSchema method lets you specify the Schema of the Store.
1629
+ *
1630
+ * Note that this may result in a change to data in the Store, as defaults are
1631
+ * applied or as invalid Table, Row, or Cell objects are removed. These
1632
+ * changes will fire any listeners to that data, as expected.
1633
+ *
1634
+ * When no longer needed, you can also completely remove an existing Schema
1635
+ * with the delSchema method.
1636
+ *
1637
+ * @param schema The Schema to be set for the Store.
1638
+ * @returns A reference to the Store.
1639
+ * @example
1640
+ * This example sets the Schema of a Store after it has been created.
1641
+ *
1642
+ * ```js
1643
+ * const store = createStore().setSchema({
1644
+ * pets: {
1645
+ * species: {type: 'string'},
1646
+ * sold: {type: 'boolean', default: false},
1647
+ * },
1648
+ * });
1649
+ * store.addRow('pets', {species: 'dog', color: 'brown', sold: 'maybe'});
1650
+ * console.log(store.getTables());
1651
+ * // -> {pets: {0: {species: 'dog', sold: false}}}
1652
+ * ```
1653
+ * @category Setter
1654
+ */
1655
+ setSchema(tablesSchema: Schema): Store;
1656
+
1657
+ /**
1658
+ * The delTables method lets you remove all of the data in a Store.
1659
+ *
1660
+ * @returns A reference to the Store.
1661
+ * @example
1662
+ * This example removes the data of a Store.
1663
+ *
1664
+ * ```js
1665
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1666
+ *
1667
+ * store.delTables();
1668
+ * console.log(store.getTables());
1669
+ * // -> {}
1670
+ * ```
1671
+ * @category Deleter
1672
+ */
1673
+ delTables(): Store;
1674
+
1675
+ /**
1676
+ * The delTable method lets you remove a single Table from the Store.
1677
+ *
1678
+ * @param tableId The Id of the Table in the Store.
1679
+ * @returns A reference to the Store.
1680
+ * @example
1681
+ * This example removes a Table from a Store.
1682
+ *
1683
+ * ```js
1684
+ * const store = createStore().setTables({
1685
+ * pets: {fido: {species: 'dog'}},
1686
+ * species: {dog: {price: 5}},
1687
+ * });
1688
+ * store.delTable('pets');
1689
+ *
1690
+ * console.log(store.getTables());
1691
+ * // -> {species: {dog: {price: 5}}}
1692
+ * ```
1693
+ * @category Deleter
1694
+ */
1695
+ delTable(tableId: Id): Store;
1696
+
1697
+ /**
1698
+ * The delRow method lets you remove a single Row from a Table.
1699
+ *
1700
+ * If this is the last Row in its Table, then that Table will be removed.
1701
+ *
1702
+ * @param tableId The Id of the Table in the Store.
1703
+ * @param rowId The Id of the Row in the Table.
1704
+ * @returns A reference to the Store.
1705
+ * @example
1706
+ * This example removes a Row from a Table.
1707
+ *
1708
+ * ```js
1709
+ * const store = createStore().setTables({
1710
+ * pets: {fido: {species: 'dog'}, felix: {species: 'cat'}},
1711
+ * });
1712
+ * store.delRow('pets', 'fido');
1713
+ *
1714
+ * console.log(store.getTables());
1715
+ * // -> {pets: {felix: {species: 'cat'}}}
1716
+ * ```
1717
+ * @category Deleter
1718
+ */
1719
+ delRow(tableId: Id, rowId: Id): Store;
1720
+
1721
+ /**
1722
+ * The delCell method lets you remove a single Cell from a Row.
1723
+ *
1724
+ * When there is no Schema applied to the Store, then if this is the last Cell
1725
+ * in its Row, then that Row will be removed. If, in turn, that is the last
1726
+ * Row in its Table, then that Table will be removed.
1727
+ *
1728
+ * If there is a Schema applied to the Store and it specifies a default value
1729
+ * for this Cell, then deletion will result in it being set back to its
1730
+ * default value. To override this, use the `forceDel` parameter, as described
1731
+ * below.
1732
+ *
1733
+ * The `forceDel` parameter is an optional flag that is only relevant if a
1734
+ * Schema provides a default value for this Cell. Under such circumstances,
1735
+ * deleting a Cell value will normally restore it to the default value. If
1736
+ * this flag is set to `true`, the complete removal of the Cell is instead
1737
+ * guaranteed. But since doing do so would result in an invalid Row (according
1738
+ * to the Schema), in fact the whole Row is deleted to retain the integrity of
1739
+ * the Table. Therefore, this flag should be used with caution.
1740
+ *
1741
+ * @param tableId The Id of the Table in the Store.
1742
+ * @param rowId The Id of the Row in the Table.
1743
+ * @param cellId The Id of the Cell in the Row.
1744
+ * @param forceDel An optional flag to indicate that the whole Row should be
1745
+ * deleted, even if a Schema provides a default value for this Cell. Defaults
1746
+ * to `false`.
1747
+ * @returns A reference to the Store.
1748
+ * @example
1749
+ * This example removes a Cell from a Row without a Schema.
1750
+ *
1751
+ * ```js
1752
+ * const store = createStore().setTables({
1753
+ * pets: {fido: {species: 'dog', sold: true}},
1754
+ * });
1755
+ * store.delCell('pets', 'fido', 'sold');
1756
+ *
1757
+ * console.log(store.getTables());
1758
+ * // -> {pets: {fido: {species: 'dog'}}}
1759
+ * ```
1760
+ * @example
1761
+ * This example removes a Cell from a Row with a Schema that defaults its
1762
+ * value.
1763
+ *
1764
+ * ```js
1765
+ * const store = createStore()
1766
+ * .setTables({
1767
+ * pets: {fido: {species: 'dog', sold: true}},
1768
+ * })
1769
+ * .setSchema({
1770
+ * pets: {
1771
+ * species: {type: 'string'},
1772
+ * sold: {type: 'boolean', default: false},
1773
+ * },
1774
+ * });
1775
+ * store.delCell('pets', 'fido', 'sold');
1776
+ *
1777
+ * console.log(store.getTables());
1778
+ * // -> {pets: {fido: {species: 'dog', sold: false}}}
1779
+ * ```
1780
+ * @example
1781
+ * This example removes a Cell from a Row with a Schema that defaults its
1782
+ * value, but uses the `forceDel` parameter to override it.
1783
+ *
1784
+ * ```js
1785
+ * const store = createStore()
1786
+ * .setTables({
1787
+ * pets: {fido: {species: 'dog', sold: true}, felix: {species: 'cat'}},
1788
+ * })
1789
+ * .setSchema({
1790
+ * pets: {
1791
+ * species: {type: 'string'},
1792
+ * sold: {type: 'boolean', default: false},
1793
+ * },
1794
+ * });
1795
+ * store.delCell('pets', 'fido', 'sold', true);
1796
+ *
1797
+ * console.log(store.getTables());
1798
+ * // -> {pets: {felix: {species: 'cat', sold: false}}}
1799
+ * ```
1800
+ * @category Deleter
1801
+ */
1802
+ delCell(tableId: Id, rowId: Id, cellId: Id, forceDel?: boolean): Store;
1803
+
1804
+ /**
1805
+ * The delSchema method lets you remove the Schema of the Store.
1806
+ *
1807
+ * @returns A reference to the Store.
1808
+ * @example
1809
+ * This example removes the Schema of a Store.
1810
+ *
1811
+ * ```js
1812
+ * const store = createStore().setSchema({pets: {species: {type: 'string'}}});
1813
+ * store.delSchema();
1814
+ * console.log(store.getSchemaJson());
1815
+ * // -> '{}'
1816
+ * ```
1817
+ * @category Deleter
1818
+ */
1819
+ delSchema(): Store;
1820
+
1821
+ /**
1822
+ * The transaction method takes a function that makes multiple mutations to
1823
+ * the Store, buffering all calls to the relevant listeners until it
1824
+ * completes.
1825
+ *
1826
+ * This method is useful for making bulk changes to the data in a Store, and
1827
+ * when you don't want listeners to be called as you make each change. Changes
1828
+ * are made silently during the transaction, and listeners relevant to the
1829
+ * changes you have made will instead only be called when the whole
1830
+ * transaction is complete.
1831
+ *
1832
+ * If multiple changes are made to a piece of Store data throughout the
1833
+ * transaction, a relevant listener will only be called with the final value
1834
+ * (assuming it is different to the value at the start of the transaction),
1835
+ * regardless of the changes that happened in between. For example, if a Cell
1836
+ * had a value `'a'` and then, within a transaction, it was changed to `'b'`
1837
+ * and then `'c'`, any CellListener registered for that cell would be called
1838
+ * once as if there had been a single change from `'a'` to `'c'`.
1839
+ *
1840
+ * Transactions can be nested. Relevant listeners will be called only when the
1841
+ * outermost one completes.
1842
+ *
1843
+ * The second, optional parameter, `doRollback` is a callback that you can use
1844
+ * to rollback the transaction if it did not complete to your satisfaction. It
1845
+ * is called with `changedCells` and `invalidCells` parameters, which inform
1846
+ * you of the net changes that have been made during the transaction, and any
1847
+ * invalid attempts to do so, respectively.
1848
+ *
1849
+ * @param actions The function to be executed as a transaction.
1850
+ * @param doRollback An optional callback that should return `true` if you
1851
+ * want to rollback the transaction at the end. Since v1.2.0.
1852
+ * @returns Whatever value the provided transaction function returns.
1853
+ * @example
1854
+ * This example makes changes to two Cells, first outside, and secondly
1855
+ * within, a transaction. In the second case, the Row listener is only called
1856
+ * once.
1857
+ *
1858
+ * ```js
1859
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1860
+ * store.addRowListener('pets', 'fido', () => console.log('Fido changed'));
1861
+ *
1862
+ * store.setCell('pets', 'fido', 'color', 'brown');
1863
+ * store.setCell('pets', 'fido', 'sold', false);
1864
+ * // -> 'Fido changed'
1865
+ * // -> 'Fido changed'
1866
+ *
1867
+ * store.transaction(() => {
1868
+ * store.setCell('pets', 'fido', 'color', 'walnut');
1869
+ * store.setCell('pets', 'fido', 'sold', true);
1870
+ * });
1871
+ * // -> 'Fido changed'
1872
+ * ```
1873
+ * @example
1874
+ * This example makes multiple changes to one Cell. The Cell listener is
1875
+ * called once - and with the final value - only if there is a net overall
1876
+ * change.
1877
+ *
1878
+ * ```js
1879
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1880
+ * store.addCellListener(
1881
+ * 'pets',
1882
+ * 'fido',
1883
+ * 'color',
1884
+ * (store, tableId, rowId, cellId, newCell) => console.log(newCell),
1885
+ * );
1886
+ *
1887
+ * store.transaction(() => {
1888
+ * store.setCell('pets', 'fido', 'color', 'black');
1889
+ * store.setCell('pets', 'fido', 'color', 'brown');
1890
+ * store.setCell('pets', 'fido', 'color', 'walnut');
1891
+ * });
1892
+ * // -> 'walnut'
1893
+ *
1894
+ * store.transaction(() => {
1895
+ * store.setCell('pets', 'fido', 'color', 'black');
1896
+ * store.setCell('pets', 'fido', 'color', 'walnut');
1897
+ * });
1898
+ * // -> undefined
1899
+ * // No net change during the transaction, so the listener is not called.
1900
+ * ```
1901
+ * @example
1902
+ * This example makes multiple changes to the Store, including some attempts
1903
+ * to update a Cell with invalid values. The `doRollback` callback receives
1904
+ * information about the changes and invalid attempts, and then judges that
1905
+ * the transaction should be rolled back to its original state.
1906
+ *
1907
+ * ```js
1908
+ * const store = createStore().setTables({
1909
+ * pets: {fido: {species: 'dog', color: 'brown'}},
1910
+ * });
1911
+ *
1912
+ * store.transaction(
1913
+ * () => {
1914
+ * store.setCell('pets', 'fido', 'color', 'black');
1915
+ * store.setCell('pets', 'fido', 'eyes', ['left', 'right']);
1916
+ * store.setCell('pets', 'fido', 'info', {sold: null});
1917
+ * },
1918
+ * (changedCells, invalidCells) => {
1919
+ * console.log(store.getTables());
1920
+ * // -> {pets: {fido: {species: 'dog', color: 'black'}}}
1921
+ * console.log(changedCells);
1922
+ * // -> {pets: {fido: {color: ['brown', 'black']}}}
1923
+ * console.log(invalidCells);
1924
+ * // -> {pets: {fido: {eyes: [['left', 'right']], info: [{sold: null}]}}}
1925
+ * return invalidCells['pets'] != null;
1926
+ * },
1927
+ * );
1928
+ *
1929
+ * console.log(store.getTables());
1930
+ * // -> {pets: {fido: {species: 'dog', color: 'brown'}}}
1931
+ * ```
1932
+ * @category Transaction
1933
+ */
1934
+ transaction<Return>(
1935
+ actions: () => Return,
1936
+ doRollback?: (
1937
+ changedCells: ChangedCells,
1938
+ invalidCells: InvalidCells,
1939
+ ) => boolean,
1940
+ ): Return;
1941
+
1942
+ /**
1943
+ * The startTransaction method allows you to explicitly start a transaction
1944
+ * that will make multiple mutations to the Store, buffering all calls to the
1945
+ * relevant listeners until it completes when you call the finishTransaction
1946
+ * method.
1947
+ *
1948
+ * Transactions are useful for making bulk changes to the data in a Store, and
1949
+ * when you don't want listeners to be called as you make each change. Changes
1950
+ * are made silently during the transaction, and listeners relevant to the
1951
+ * changes you have made will instead only be called when the whole
1952
+ * transaction is complete.
1953
+ *
1954
+ * Generally it is preferable to use the transaction method to wrap a block of
1955
+ * code as a transaction. It simply calls both the startTransaction and
1956
+ * finishTransaction methods for you. See that method for several transaction
1957
+ * examples.
1958
+ *
1959
+ * Use this startTransaction method when you have a more 'open-ended'
1960
+ * transaction, such as one containing mutations triggered from other events
1961
+ * that are asynchronous or not occurring inline to your code. You must
1962
+ * remember to also call the finishTransaction method explicitly when it is
1963
+ * done, of course.
1964
+ *
1965
+ * @returns A reference to the Store.
1966
+ * @example
1967
+ * This example makes changes to two Cells, first outside, and secondly
1968
+ * within, a transaction that is explicitly started and finished. In the
1969
+ * second case, the Row listener is only called once.
1970
+ *
1971
+ * ```js
1972
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1973
+ * store.addRowListener('pets', 'fido', () => console.log('Fido changed'));
1974
+ *
1975
+ * store.setCell('pets', 'fido', 'color', 'brown');
1976
+ * store.setCell('pets', 'fido', 'sold', false);
1977
+ * // -> 'Fido changed'
1978
+ * // -> 'Fido changed'
1979
+ *
1980
+ * store.startTransaction();
1981
+ * store.setCell('pets', 'fido', 'color', 'walnut');
1982
+ * store.setCell('pets', 'fido', 'sold', true);
1983
+ * store.finishTransaction();
1984
+ * // -> 'Fido changed'
1985
+ * ```
1986
+ * @category Transaction
1987
+ * @since v1.3.0
1988
+ */
1989
+ startTransaction(): Store;
1990
+
1991
+ /**
1992
+ * The finishTransaction method allows you to explicitly finish a transaction
1993
+ * that has made multiple mutations to the Store, triggering all calls to the
1994
+ * relevant listeners.
1995
+ *
1996
+ * Transactions are useful for making bulk changes to the data in a Store, and
1997
+ * when you don't want listeners to be called as you make each change. Changes
1998
+ * are made silently during the transaction, and listeners relevant to the
1999
+ * changes you have made will instead only be called when the whole
2000
+ * transaction is complete.
2001
+ *
2002
+ * Generally it is preferable to use the transaction method to wrap a block of
2003
+ * code as a transaction. It simply calls both the startTransaction and
2004
+ * finishTransaction methods for you. See that method for several transaction
2005
+ * examples.
2006
+ *
2007
+ * Use this finishTransaction method when you have a more 'open-ended'
2008
+ * transaction, such as one containing mutations triggered from other events
2009
+ * that are asynchronous or not occurring inline to your code. There must have
2010
+ * been a corresponding startTransaction method that this completes, of
2011
+ * course, otherwise this function has no effect.
2012
+ *
2013
+ * @param doRollback An optional callback that should return `true` if you
2014
+ * want to rollback the transaction at the end.
2015
+ * @returns A reference to the Store.
2016
+ * @example
2017
+ * This example makes changes to two Cells, first outside, and secondly
2018
+ * within, a transaction that is explicitly started and finished. In the
2019
+ * second case, the Row listener is only called once.
2020
+ *
2021
+ * ```js
2022
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
2023
+ * store.addRowListener('pets', 'fido', () => console.log('Fido changed'));
2024
+ *
2025
+ * store.setCell('pets', 'fido', 'color', 'brown');
2026
+ * store.setCell('pets', 'fido', 'sold', false);
2027
+ * // -> 'Fido changed'
2028
+ * // -> 'Fido changed'
2029
+ *
2030
+ * store.startTransaction();
2031
+ * store.setCell('pets', 'fido', 'color', 'walnut');
2032
+ * store.setCell('pets', 'fido', 'sold', true);
2033
+ * store.finishTransaction();
2034
+ * // -> 'Fido changed'
2035
+ * ```
2036
+ * @example
2037
+ * This example makes multiple changes to the Store, including some attempts
2038
+ * to update a Cell with invalid values. The `doRollback` callback receives
2039
+ * information about the changes and invalid attempts, and then judges that
2040
+ * the transaction should be rolled back to its original state.
2041
+ *
2042
+ * ```js
2043
+ * const store = createStore().setTables({
2044
+ * pets: {fido: {species: 'dog', color: 'brown'}},
2045
+ * });
2046
+ *
2047
+ * store.startTransaction();
2048
+ * store.setCell('pets', 'fido', 'color', 'black');
2049
+ * store.setCell('pets', 'fido', 'eyes', ['left', 'right']);
2050
+ * store.setCell('pets', 'fido', 'info', {sold: null});
2051
+ * store.finishTransaction((changedCells, invalidCells) => {
2052
+ * console.log(store.getTables());
2053
+ * // -> {pets: {fido: {species: 'dog', color: 'black'}}}
2054
+ * console.log(changedCells);
2055
+ * // -> {pets: {fido: {color: ['brown', 'black']}}}
2056
+ * console.log(invalidCells);
2057
+ * // -> {pets: {fido: {eyes: [['left', 'right']], info: [{sold: null}]}}}
2058
+ * return invalidCells['pets'] != null;
2059
+ * });
2060
+ *
2061
+ * console.log(store.getTables());
2062
+ * // -> {pets: {fido: {species: 'dog', color: 'brown'}}}
2063
+ * ```
2064
+ * @category Transaction
2065
+ * @since v1.3.0
2066
+ */
2067
+ finishTransaction(
2068
+ doRollback?: (
2069
+ changedCells: ChangedCells,
2070
+ invalidCells: InvalidCells,
2071
+ ) => boolean,
2072
+ ): Store;
2073
+
2074
+ /**
2075
+ * The forEachTable method takes a function that it will then call for each
2076
+ * Table in the Store.
2077
+ *
2078
+ * This method is useful for iterating over the Table structure of the Store
2079
+ * in a functional style. The `tableCallback` parameter is a TableCallback
2080
+ * function that will be called with the Id of each Table, and with a function
2081
+ * that can then be used to iterate over each Row of the Table, should you
2082
+ * wish.
2083
+ *
2084
+ * @param tableCallback The function that should be called for every Table.
2085
+ * @example
2086
+ * This example iterates over each Table in a Store, and lists each Row Id
2087
+ * within them.
2088
+ *
2089
+ * ```js
2090
+ * const store = createStore().setTables({
2091
+ * pets: {fido: {species: 'dog'}},
2092
+ * species: {dog: {price: 5}},
2093
+ * });
2094
+ * store.forEachTable((tableId, forEachRow) => {
2095
+ * console.log(tableId);
2096
+ * forEachRow((rowId) => console.log(`- ${rowId}`));
2097
+ * });
2098
+ * // -> 'pets'
2099
+ * // -> '- fido'
2100
+ * // -> 'species'
2101
+ * // -> '- dog'
2102
+ * ```
2103
+ * @category Iterator
2104
+ */
2105
+ forEachTable(tableCallback: TableCallback): void;
2106
+
2107
+ /**
2108
+ * The forEachRow method takes a function that it will then call for each Row
2109
+ * in a specified Table.
2110
+ *
2111
+ * This method is useful for iterating over the Row structure of the Table in
2112
+ * a functional style. The `rowCallback` parameter is a RowCallback function
2113
+ * that will be called with the Id of each Row, and with a function that can
2114
+ * then be used to iterate over each Cell of the Row, should you wish.
2115
+ *
2116
+ * @param tableId The Id of the Table to iterate over.
2117
+ * @param rowCallback The function that should be called for every Row.
2118
+ * @example
2119
+ * This example iterates over each Row in a Table, and lists each Cell Id
2120
+ * within them.
2121
+ *
2122
+ * ```js
2123
+ * const store = createStore().setTables({
2124
+ * pets: {
2125
+ * fido: {species: 'dog'},
2126
+ * felix: {color: 'black'},
2127
+ * },
2128
+ * });
2129
+ * store.forEachRow('pets', (rowId, forEachCell) => {
2130
+ * console.log(rowId);
2131
+ * forEachCell((cellId) => console.log(`- ${cellId}`));
2132
+ * });
2133
+ * // -> 'fido'
2134
+ * // -> '- species'
2135
+ * // -> 'felix'
2136
+ * // -> '- color'
2137
+ * ```
2138
+ * @category Iterator
2139
+ */
2140
+ forEachRow(tableId: Id, rowCallback: RowCallback): void;
2141
+
2142
+ /**
2143
+ * The forEachCell method takes a function that it will then call for each
2144
+ * Cell in a specified Row.
2145
+ *
2146
+ * This method is useful for iterating over the Cell structure of the Row in a
2147
+ * functional style. The `cellCallback` parameter is a CellCallback function
2148
+ * that will be called with the Id and value of each Cell.
2149
+ *
2150
+ * @param tableId The Id of the Table containing the Row to iterate over.
2151
+ * @param rowId The Id of the Row to iterate over.
2152
+ * @param cellCallback The function that should be called for every Cell.
2153
+ * @example
2154
+ * This example iterates over each Cell in a Row, and lists its value.
2155
+ *
2156
+ * ```js
2157
+ * const store = createStore().setTables({
2158
+ * pets: {fido: {species: 'dog', color: 'brown'}},
2159
+ * });
2160
+ * store.forEachCell('pets', 'fido', (cellId, cell) => {
2161
+ * console.log(`${cellId}: ${cell}`);
2162
+ * });
2163
+ * // -> 'species: dog'
2164
+ * // -> 'color: brown'
2165
+ * ```
2166
+ * @category Iterator
2167
+ */
2168
+ forEachCell(tableId: Id, rowId: Id, cellCallback: CellCallback): void;
2169
+
2170
+ /**
2171
+ * The addTablesListener method registers a listener function with the Store
2172
+ * that will be called whenever data in the Store changes.
2173
+ *
2174
+ * The provided listener is a TablesListener function, and will be called with
2175
+ * a reference to the Store and a GetCellChange function in case you need to
2176
+ * inspect any changes that occurred.
2177
+ *
2178
+ * Use the optional mutator parameter to indicate that there is code in the
2179
+ * listener that will mutate Store data. If set to `false` (or omitted), such
2180
+ * mutations will be silently ignored. All relevant mutator listeners (with
2181
+ * this flag set to `true`) are called _before_ any non-mutator listeners
2182
+ * (since the latter may become relevant due to changes made in the former).
2183
+ * The changes made by mutator listeners do not fire other mutating listeners,
2184
+ * though they will fire non-mutator listeners.
2185
+ *
2186
+ * @param listener The function that will be called whenever data in the Store
2187
+ * changes.
2188
+ * @param mutator An optional boolean that indicates that the listener mutates
2189
+ * Store data.
2190
+ * @returns A unique Id for the listener that can later be used to call it
2191
+ * explicitly, or to remove it.
2192
+ * @example
2193
+ * This example registers a listener that responds to any changes to the whole
2194
+ * Store.
2195
+ *
2196
+ * ```js
2197
+ * const store = createStore().setTables({
2198
+ * pets: {fido: {species: 'dog', color: 'brown'}},
2199
+ * });
2200
+ * const listenerId = store.addTablesListener((store, getCellChange) => {
2201
+ * console.log('Tables changed');
2202
+ * console.log(getCellChange('pets', 'fido', 'color'));
2203
+ * });
2204
+ *
2205
+ * store.setCell('pets', 'fido', 'color', 'walnut');
2206
+ * // -> 'Tables changed'
2207
+ * // -> [true, 'brown', 'walnut']
2208
+ *
2209
+ * store.delListener(listenerId);
2210
+ * ```
2211
+ * @example
2212
+ * This example registers a listener that responds to any changes to the whole
2213
+ * Store, and which also mutates the Store itself.
2214
+ *
2215
+ * ```js
2216
+ * const store = createStore().setTables({
2217
+ * pets: {fido: {species: 'dog', color: 'brown'}},
2218
+ * });
2219
+ * const listenerId = store.addTablesListener(
2220
+ * (store) => store.setCell('meta', 'update', 'store', true),
2221
+ * true,
2222
+ * );
2223
+ *
2224
+ * store.delCell('pets', 'fido', 'color');
2225
+ * console.log(store.getTable('meta'));
2226
+ * // -> {update: {store: true}}
2227
+ *
2228
+ * store.delListener(listenerId);
2229
+ * ```
2230
+ * @category Listener
2231
+ */
2232
+ addTablesListener(listener: TablesListener, mutator?: boolean): Id;
2233
+
2234
+ /**
2235
+ * The addTableIdsListener method registers a listener function with the Store
2236
+ * that will be called whenever the Table Ids in the Store change.
2237
+ *
2238
+ * The provided listener is a TableIdsListener function, and will be called
2239
+ * with a reference to the Store.
2240
+ *
2241
+ * By default, such a listener is only called when a Table is added or
2242
+ * removed. To listen to all changes in the Store, use the addTablesListener
2243
+ * method.
2244
+ *
2245
+ * Use the optional mutator parameter to indicate that there is code in the
2246
+ * listener that will mutate Store data. If set to `false` (or omitted), such
2247
+ * mutations will be silently ignored. All relevant mutator listeners (with
2248
+ * this flag set to `true`) are called _before_ any non-mutator listeners
2249
+ * (since the latter may become relevant due to changes made in the former).
2250
+ * The changes made by mutator listeners do not fire other mutating listeners,
2251
+ * though they will fire non-mutator listeners.
2252
+ *
2253
+ * @param listener The function that will be called whenever the Table Ids in
2254
+ * the Store change.
2255
+ * @param mutator An optional boolean that indicates that the listener mutates
2256
+ * Store data.
2257
+ * @returns A unique Id for the listener that can later be used to call it
2258
+ * explicitly, or to remove it.
2259
+ * @example
2260
+ * This example registers a listener that responds to any change to the Table
2261
+ * Ids.
2262
+ *
2263
+ * ```js
2264
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
2265
+ * const listenerId = store.addTableIdsListener((store) => {
2266
+ * console.log('Table Ids changed');
2267
+ * console.log(store.getTableIds());
2268
+ * });
2269
+ *
2270
+ * store.setTable('species', {dog: {price: 5}});
2271
+ * // -> 'Table Ids changed'
2272
+ * // -> ['pets', 'species']
2273
+ *
2274
+ * store.delListener(listenerId);
2275
+ * ```
2276
+ * @example
2277
+ * This example registers a listener that responds to any change to the Table
2278
+ * Ids, and which also mutates the Store itself.
2279
+ *
2280
+ * ```js
2281
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
2282
+ * const listenerId = store.addTableIdsListener(
2283
+ * (store) => store.setCell('meta', 'update', 'store', true),
2284
+ * true, // mutator
2285
+ * );
2286
+ *
2287
+ * store.setTable('species', {dog: {price: 5}});
2288
+ * console.log(store.getTable('meta'));
2289
+ * // -> {update: {store: true}}
2290
+ *
2291
+ * store.delListener(listenerId);
2292
+ * ```
2293
+ * @category Listener
2294
+ */
2295
+ addTableIdsListener(listener: TableIdsListener, mutator?: boolean): Id;
2296
+
2297
+ /**
2298
+ * The addTableListener method registers a listener function with the Store
2299
+ * that will be called whenever data in a Table changes.
2300
+ *
2301
+ * The provided listener is a TableListener function, and will be called with
2302
+ * a reference to the Store, the Id of the Table that changed, and a
2303
+ * GetCellChange function in case you need to inspect any changes that
2304
+ * occurred.
2305
+ *
2306
+ * You can either listen to a single Table (by specifying its Id as the
2307
+ * method's first parameter) or changes to any Table (by providing a `null`
2308
+ * wildcard).
2309
+ *
2310
+ * Use the optional mutator parameter to indicate that there is code in the
2311
+ * listener that will mutate Store data. If set to `false` (or omitted), such
2312
+ * mutations will be silently ignored. All relevant mutator listeners (with
2313
+ * this flag set to `true`) are called _before_ any non-mutator listeners
2314
+ * (since the latter may become relevant due to changes made in the former).
2315
+ * The changes made by mutator listeners do not fire other mutating listeners,
2316
+ * though they will fire non-mutator listeners.
2317
+ *
2318
+ * @param tableId The Id of the Table to listen to, or `null` as a wildcard.
2319
+ * @param listener The function that will be called whenever data in the
2320
+ * matching Table changes.
2321
+ * @param mutator An optional boolean that indicates that the listener mutates
2322
+ * Store data.
2323
+ * @returns A unique Id for the listener that can later be used to call it
2324
+ * explicitly, or to remove it.
2325
+ * @example
2326
+ * This example registers a listener that responds to any changes to a
2327
+ * specific Table.
2328
+ *
2329
+ * ```js
2330
+ * const store = createStore().setTables({
2331
+ * pets: {fido: {species: 'dog', color: 'brown'}},
2332
+ * });
2333
+ * const listenerId = store.addTableListener(
2334
+ * 'pets',
2335
+ * (store, tableId, getCellChange) => {
2336
+ * console.log('pets table changed');
2337
+ * console.log(getCellChange('pets', 'fido', 'color'));
2338
+ * },
2339
+ * );
2340
+ *
2341
+ * store.setCell('pets', 'fido', 'color', 'walnut');
2342
+ * // -> 'pets table changed'
2343
+ * // -> [true, 'brown', 'walnut']
2344
+ *
2345
+ * store.delListener(listenerId);
2346
+ * ```
2347
+ * @example
2348
+ * This example registers a listener that responds to any changes to any
2349
+ * Table.
2350
+ *
2351
+ * ```js
2352
+ * const store = createStore().setTables({
2353
+ * pets: {fido: {species: 'dog', color: 'brown'}},
2354
+ * });
2355
+ * const listenerId = store.addTableListener(null, (store, tableId) => {
2356
+ * console.log(`${tableId} table changed`);
2357
+ * });
2358
+ *
2359
+ * store.setCell('pets', 'fido', 'color', 'walnut');
2360
+ * // -> 'pets table changed'
2361
+ * store.setTable('species', {dog: {price: 5}});
2362
+ * // -> 'species table changed'
2363
+ *
2364
+ * store.delListener(listenerId);
2365
+ * ```
2366
+ * @example
2367
+ * This example registers a listener that responds to any changes to a
2368
+ * specific Table, and which also mutates the Store itself.
2369
+ *
2370
+ * ```js
2371
+ * const store = createStore().setTables({
2372
+ * pets: {fido: {species: 'dog', color: 'brown'}},
2373
+ * });
2374
+ * const listenerId = store.addTableListener(
2375
+ * 'pets',
2376
+ * (store, tableId) => store.setCell('meta', 'update', tableId, true),
2377
+ * true,
2378
+ * );
2379
+ *
2380
+ * store.delCell('pets', 'fido', 'color');
2381
+ * console.log(store.getTable('meta'));
2382
+ * // -> {update: {pets: true}}
2383
+ *
2384
+ * store.delListener(listenerId);
2385
+ * ```
2386
+ * @category Listener
2387
+ */
2388
+ addTableListener(
2389
+ tableId: IdOrNull,
2390
+ listener: TableListener,
2391
+ mutator?: boolean,
2392
+ ): Id;
2393
+
2394
+ /**
2395
+ * The addRowIdsListener method registers a listener function with the Store
2396
+ * that will be called whenever the Row Ids in a Table change.
2397
+ *
2398
+ * The provided listener is a RowIdsListener function, and will be called with
2399
+ * a reference to the Store and the Id of the Table that changed.
2400
+ *
2401
+ * By default, such a listener is only called when a Row is added or removed.
2402
+ * To listen to all changes in the Table, use the addTableListener method.
2403
+ *
2404
+ * You can either listen to a single Table (by specifying its Id as the
2405
+ * method's first parameter) or changes to any Table (by providing a `null`
2406
+ * wildcard).
2407
+ *
2408
+ * Use the optional mutator parameter to indicate that there is code in the
2409
+ * listener that will mutate Store data. If set to `false` (or omitted), such
2410
+ * mutations will be silently ignored. All relevant mutator listeners (with
2411
+ * this flag set to `true`) are called _before_ any non-mutator listeners
2412
+ * (since the latter may become relevant due to changes made in the former).
2413
+ * The changes made by mutator listeners do not fire other mutating listeners,
2414
+ * though they will fire non-mutator listeners.
2415
+ *
2416
+ * @param tableId The Id of the Table to listen to, or `null` as a wildcard.
2417
+ * @param listener The function that will be called whenever the Row Ids in
2418
+ * the Table change.
2419
+ * @param mutator An optional boolean that indicates that the listener mutates
2420
+ * Store data.
2421
+ * @returns A unique Id for the listener that can later be used to call it
2422
+ * explicitly, or to remove it.
2423
+ * @example
2424
+ * This example registers a listener that responds to any change to the Row
2425
+ * Ids of a specific Table.
2426
+ *
2427
+ * ```js
2428
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
2429
+ * const listenerId = store.addRowIdsListener('pets', (store) => {
2430
+ * console.log('Row Ids for pets table changed');
2431
+ * console.log(store.getRowIds('pets'));
2432
+ * });
2433
+ *
2434
+ * store.setRow('pets', 'felix', {species: 'cat'});
2435
+ * // -> 'Row Ids for pets table changed'
2436
+ * // -> ['fido', 'felix']
2437
+ *
2438
+ * store.delListener(listenerId);
2439
+ * ```
2440
+ * @example
2441
+ * This example registers a listener that responds to any change to the Row
2442
+ * Ids of any Table.
2443
+ *
2444
+ * ```js
2445
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
2446
+ * const listenerId = store.addRowIdsListener(null, (store, tableId) => {
2447
+ * console.log(`Row Ids for ${tableId} table changed`);
2448
+ * console.log(store.getRowIds(tableId));
2449
+ * });
2450
+ *
2451
+ * store.setRow('pets', 'felix', {species: 'cat'});
2452
+ * // -> 'Row Ids for pets table changed'
2453
+ * // -> ['fido', 'felix']
2454
+ * store.setRow('species', 'dog', {price: 5});
2455
+ * // -> 'Row Ids for species table changed'
2456
+ * // -> ['dog']
2457
+ *
2458
+ * store.delListener(listenerId);
2459
+ * ```
2460
+ * @example
2461
+ * This example registers a listener that responds to any change to the Row
2462
+ * Ids of a specific Table, and which also mutates the Store itself.
2463
+ *
2464
+ * ```js
2465
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
2466
+ * const listenerId = store.addRowIdsListener(
2467
+ * 'pets',
2468
+ * (store, tableId) => store.setCell('meta', 'update', tableId, true),
2469
+ * true, // mutator
2470
+ * );
2471
+ *
2472
+ * store.setRow('pets', 'felix', {species: 'cat'});
2473
+ * console.log(store.getTable('meta'));
2474
+ * // -> {update: {pets: true}}
2475
+ *
2476
+ * store.delListener(listenerId);
2477
+ * ```
2478
+ * @category Listener
2479
+ */
2480
+ addRowIdsListener(
2481
+ tableId: IdOrNull,
2482
+ listener: RowIdsListener,
2483
+ mutator?: boolean,
2484
+ ): Id;
2485
+
2486
+ /**
2487
+ * The addSortedRowIdsListener method registers a listener function with the
2488
+ * Store that will be called whenever sorted (and optionally, paginated) Row
2489
+ * Ids in a Table change.
2490
+ *
2491
+ * The provided listener is a SortedRowIdsListener function, and will be
2492
+ * called with a reference to the Store, the Id of the Table whose Row Ids
2493
+ * sorting changed, the Cell Id being used to sort them, whether descending or
2494
+ * not, and the offset and limit of the number of Ids returned, for pagination
2495
+ * purposes. It also receives the sorted array of Ids itself, so that you can
2496
+ * use them in the listener without the additional cost of an explicit call to
2497
+ * getSortedRowIds.
2498
+ *
2499
+ * Such a listener is called when a Row is added or removed, but also when a
2500
+ * value in the specified Cell (somewhere in the Table) has changed enough to
2501
+ * change the sorting of the Row Ids.
2502
+ *
2503
+ * Unlike most other listeners, you cannot provide wildcards (due to the cost
2504
+ * of detecting changes to the sorting). You can only listen to a single
2505
+ * specified Table, sorted by a single specified Cell.
2506
+ *
2507
+ * The sorting of the rows is alphanumeric, and you can indicate whether it
2508
+ * should be in descending order. The `offset` and `limit` parameters are used
2509
+ * to paginate results, but default to `0` and `undefined` to return all
2510
+ * available Row Ids if not specified.
2511
+ *
2512
+ * Use the optional mutator parameter to indicate that there is code in the
2513
+ * listener that will mutate Store data. If set to `false` (or omitted), such
2514
+ * mutations will be silently ignored. All relevant mutator listeners (with
2515
+ * this flag set to `true`) are called _before_ any non-mutator listeners
2516
+ * (since the latter may become relevant due to changes made in the former).
2517
+ * The changes made by mutator listeners do not fire other mutating listeners,
2518
+ * though they will fire non-mutator listeners.
2519
+ *
2520
+ * @param tableId The Id of the Table to listen to.
2521
+ * @param cellId The Id of the Cell whose values are used for the sorting, or
2522
+ * `undefined` to by sort the Row Id itself.
2523
+ * @param descending Whether the sorting should be in descending order.
2524
+ * @param offset The number of Row Ids to skip for pagination purposes, if
2525
+ * any.
2526
+ * @param limit The maximum number of Row Ids to return, or `undefined` for
2527
+ * all.
2528
+ * @param listener The function that will be called whenever the sorted Row
2529
+ * Ids in the Table change.
2530
+ * @param mutator An optional boolean that indicates that the listener mutates
2531
+ * Store data.
2532
+ * @returns A unique Id for the listener that can later be used to call it
2533
+ * explicitly, or to remove it.
2534
+ * @example
2535
+ * This example registers a listener that responds to any change to the sorted
2536
+ * Row Ids of a specific Table.
2537
+ *
2538
+ * ```js
2539
+ * const store = createStore().setTables({
2540
+ * pets: {
2541
+ * cujo: {species: 'wolf'},
2542
+ * felix: {species: 'cat'},
2543
+ * },
2544
+ * });
2545
+ * console.log(store.getSortedRowIds('pets', 'species', false));
2546
+ * // -> ['felix', 'cujo']
2547
+ *
2548
+ * const listenerId = store.addSortedRowIdsListener(
2549
+ * 'pets',
2550
+ * 'species',
2551
+ * false,
2552
+ * 0,
2553
+ * undefined,
2554
+ * (store, tableId, cellId, descending, offset, limit, sortedRowIds) => {
2555
+ * console.log(`Sorted Row Ids for ${tableId} table changed`);
2556
+ * console.log(sortedRowIds);
2557
+ * // ^ cheaper than calling getSortedRowIds again
2558
+ * },
2559
+ * );
2560
+ *
2561
+ * store.setRow('pets', 'fido', {species: 'dog'});
2562
+ * // -> 'Sorted Row Ids for pets table changed'
2563
+ * // -> ['felix', 'fido', 'cujo']
2564
+ *
2565
+ * store.delListener(listenerId);
2566
+ * ```
2567
+ * @example
2568
+ * This 111example registers a listener that responds to any change to a
2569
+ * paginated section of the sorted Row Ids of a specific Table.
2570
+ *
2571
+ * ```js
2572
+ * const store = createStore().setTables({
2573
+ * pets: {
2574
+ * fido: {price: 6},
2575
+ * felix: {price: 5},
2576
+ * mickey: {price: 2},
2577
+ * tom: {price: 4},
2578
+ * carnaby: {price: 3},
2579
+ * lowly: {price: 1},
2580
+ * },
2581
+ * });
2582
+ *
2583
+ * const listenerId = store.addSortedRowIdsListener(
2584
+ * 'pets',
2585
+ * 'price',
2586
+ * false,
2587
+ * 0,
2588
+ * 3,
2589
+ * (store, tableId, cellId, descending, offset, limit, sortedRowIds) => {
2590
+ * console.log(`First three sorted Row Ids for ${tableId} table changed`);
2591
+ * console.log(sortedRowIds);
2592
+ * // ^ cheaper than calling getSortedRowIds again
2593
+ * },
2594
+ * );
2595
+ * console.log(store.getSortedRowIds('pets', 'price', false, 0, 3));
2596
+ * // -> ['lowly', 'mickey', 'carnaby']
2597
+ *
2598
+ * store.setCell('pets', 'carnaby', 'price', 4.5);
2599
+ * // -> 'First three sorted Row Ids for pets table changed'
2600
+ * // -> ['lowly', 'mickey', 'tom']
2601
+ *
2602
+ * store.delListener(listenerId);
2603
+ * ```
2604
+ * @example
2605
+ * This example registers a listener that responds to any change to the sorted
2606
+ * Row Ids of a specific Table. The Row Ids are sorted by their own value,
2607
+ * since the `cellId` parameter is explicitly undefined.
2608
+ *
2609
+ * ```js
2610
+ * const store = createStore().setTables({
2611
+ * pets: {
2612
+ * fido: {species: 'dog'},
2613
+ * felix: {species: 'cat'},
2614
+ * },
2615
+ * });
2616
+ * console.log(store.getSortedRowIds('pets', undefined, false));
2617
+ * // -> ['felix', 'fido']
2618
+ *
2619
+ * const listenerId = store.addSortedRowIdsListener(
2620
+ * 'pets',
2621
+ * undefined,
2622
+ * false,
2623
+ * 0,
2624
+ * undefined,
2625
+ * (store, tableId, cellId, descending, offset, limit, sortedRowIds) => {
2626
+ * console.log(`Sorted Row Ids for ${tableId} table changed`);
2627
+ * console.log(sortedRowIds);
2628
+ * // ^ cheaper than calling getSortedRowIds again
2629
+ * },
2630
+ * );
2631
+ *
2632
+ * store.setRow('pets', 'cujo', {species: 'wolf'});
2633
+ * // -> 'Sorted Row Ids for pets table changed'
2634
+ * // -> ['cujo', 'felix', 'fido']
2635
+ *
2636
+ * store.delListener(listenerId);
2637
+ * ```
2638
+ * @example
2639
+ * This example registers a listener that responds to a change in the sorting
2640
+ * of the rows of a specific Table, even though the set of Ids themselves has
2641
+ * not changed.
2642
+ *
2643
+ * ```js
2644
+ * const store = createStore().setTables({
2645
+ * pets: {
2646
+ * fido: {species: 'dog'},
2647
+ * felix: {species: 'cat'},
2648
+ * },
2649
+ * });
2650
+ * console.log(store.getSortedRowIds('pets', 'species', false));
2651
+ * // -> ['felix', 'fido']
2652
+ *
2653
+ * const listenerId = store.addSortedRowIdsListener(
2654
+ * 'pets',
2655
+ * 'species',
2656
+ * false,
2657
+ * 0,
2658
+ * undefined,
2659
+ * (store, tableId, cellId, descending, offset, limit, sortedRowIds) => {
2660
+ * console.log(`Sorted Row Ids for ${tableId} table changed`);
2661
+ * console.log(sortedRowIds);
2662
+ * // ^ cheaper than calling getSortedRowIds again
2663
+ * },
2664
+ * );
2665
+ *
2666
+ * store.setCell('pets', 'felix', 'species', 'tiger');
2667
+ * // -> 'Sorted Row Ids for pets table changed'
2668
+ * // -> ['fido', 'felix']
2669
+ *
2670
+ * store.delListener(listenerId);
2671
+ * ```
2672
+ * @example
2673
+ * This example registers a listener that responds to any change to the sorted
2674
+ * Row Ids of a specific Table, and which also mutates the Store itself.
2675
+ *
2676
+ * ```js
2677
+ * const store = createStore().setTables({
2678
+ * pets: {
2679
+ * cujo: {species: 'wolf'},
2680
+ * felix: {species: 'cat'},
2681
+ * },
2682
+ * });
2683
+ * const listenerId = store.addSortedRowIdsListener(
2684
+ * 'pets',
2685
+ * 'species',
2686
+ * false,
2687
+ * 0,
2688
+ * undefined,
2689
+ * (store, tableId) => store.setCell('meta', 'sorted', tableId, true),
2690
+ * true, // mutator
2691
+ * );
2692
+ *
2693
+ * store.setRow('pets', 'fido', {species: 'dog'});
2694
+ * console.log(store.getTable('meta'));
2695
+ * // -> {sorted: {pets: true}}
2696
+ *
2697
+ * store.delListener(listenerId);
2698
+ * ```
2699
+ * @category Listener
2700
+ * @since v2.0.0
2701
+ */
2702
+ addSortedRowIdsListener(
2703
+ tableId: Id,
2704
+ cellId: Id | undefined,
2705
+ descending: boolean,
2706
+ offset: number,
2707
+ limit: number | undefined,
2708
+ listener: SortedRowIdsListener,
2709
+ mutator?: boolean,
2710
+ ): Id;
2711
+
2712
+ /**
2713
+ * The addRowListener method registers a listener function with the Store that
2714
+ * will be called whenever data in a Row changes.
2715
+ *
2716
+ * The provided listener is a RowListener function, and will be called with a
2717
+ * reference to the Store, the Id of the Table that changed, the Id of the Row
2718
+ * that changed, and a GetCellChange function in case you need to inspect any
2719
+ * changes that occurred.
2720
+ *
2721
+ * You can either listen to a single Row (by specifying the Table Id and Row
2722
+ * Id as the method's first two parameters) or changes to any Row (by
2723
+ * providing `null` wildcards).
2724
+ *
2725
+ * Both, either, or neither of the `tableId` and `rowId` parameters can be
2726
+ * wildcarded with `null`. You can listen to a specific Row in a specific
2727
+ * Table, any Row in a specific Table, a specific Row in any Table, or any Row
2728
+ * in any Table.
2729
+ *
2730
+ * Use the optional mutator parameter to indicate that there is code in the
2731
+ * listener that will mutate Store data. If set to `false` (or omitted), such
2732
+ * mutations will be silently ignored. All relevant mutator listeners (with
2733
+ * this flag set to `true`) are called _before_ any non-mutator listeners
2734
+ * (since the latter may become relevant due to changes made in the former).
2735
+ * The changes made by mutator listeners do not fire other mutating listeners,
2736
+ * though they will fire non-mutator listeners.
2737
+ *
2738
+ * @param tableId The Id of the Table to listen to, or `null` as a wildcard.
2739
+ * @param rowId The Id of the Row to listen to, or `null` as a wildcard.
2740
+ * @param listener The function that will be called whenever data in the
2741
+ * matching Row changes.
2742
+ * @param mutator An optional boolean that indicates that the listener mutates
2743
+ * Store data.
2744
+ * @returns A unique Id for the listener that can later be used to call it
2745
+ * explicitly, or to remove it.
2746
+ * @example
2747
+ * This example registers a listener that responds to any changes to a
2748
+ * specific Row.
2749
+ *
2750
+ * ```js
2751
+ * const store = createStore().setTables({
2752
+ * pets: {fido: {species: 'dog', color: 'brown'}},
2753
+ * });
2754
+ * const listenerId = store.addRowListener(
2755
+ * 'pets',
2756
+ * 'fido',
2757
+ * (store, tableId, rowId, getCellChange) => {
2758
+ * console.log('fido row in pets table changed');
2759
+ * console.log(getCellChange('pets', 'fido', 'color'));
2760
+ * },
2761
+ * );
2762
+ *
2763
+ * store.setCell('pets', 'fido', 'color', 'walnut');
2764
+ * // -> 'fido row in pets table changed'
2765
+ * // -> [true, 'brown', 'walnut']
2766
+ *
2767
+ * store.delListener(listenerId);
2768
+ * ```
2769
+ * @example
2770
+ * This example registers a listener that responds to any changes to any Row.
2771
+ *
2772
+ * ```js
2773
+ * const store = createStore().setTables({
2774
+ * pets: {fido: {species: 'dog', color: 'brown'}},
2775
+ * });
2776
+ * const listenerId = store.addRowListener(
2777
+ * null,
2778
+ * null,
2779
+ * (store, tableId, rowId) => {
2780
+ * console.log(`${rowId} row in ${tableId} table changed`);
2781
+ * },
2782
+ * );
2783
+ *
2784
+ * store.setCell('pets', 'fido', 'color', 'walnut');
2785
+ * // -> 'fido row in pets table changed'
2786
+ * store.setTable('species', {dog: {price: 5}});
2787
+ * // -> 'dog row in species table changed'
2788
+ *
2789
+ * store.delListener(listenerId);
2790
+ * ```
2791
+ * @example
2792
+ * This example registers a listener that responds to any changes to a
2793
+ * specific Row, and which also mutates the Store itself.
2794
+ *
2795
+ * ```js
2796
+ * const store = createStore().setTables({
2797
+ * pets: {fido: {species: 'dog', color: 'brown'}},
2798
+ * });
2799
+ * const listenerId = store.addRowListener(
2800
+ * 'pets',
2801
+ * 'fido',
2802
+ * (store, tableId, rowId) =>
2803
+ * store.setCell('meta', 'update', `${tableId}_${rowId}`, true),
2804
+ * true,
2805
+ * );
2806
+ *
2807
+ * store.delCell('pets', 'fido', 'color');
2808
+ * console.log(store.getTable('meta'));
2809
+ * // -> {update: {pets_fido: true}}
2810
+ *
2811
+ * store.delListener(listenerId);
2812
+ * ```
2813
+ * @category Listener
2814
+ */
2815
+ addRowListener(
2816
+ tableId: IdOrNull,
2817
+ rowId: IdOrNull,
2818
+ listener: RowListener,
2819
+ mutator?: boolean,
2820
+ ): Id;
2821
+
2822
+ /**
2823
+ * The addCellIdsListener method registers a listener function with the Store
2824
+ * that will be called whenever the Cell Ids in a Row change.
2825
+ *
2826
+ * The provided listener is a CellIdsListener function, and will be called
2827
+ * with a reference to the Store, the Id of the Table, and the Id of the Row
2828
+ * that changed.
2829
+ *
2830
+ * By default, such a listener is only called when a Cell is added or removed.
2831
+ * To listen to all changes in the Row, use the addRowListener method.
2832
+ *
2833
+ * You can either listen to a single Row (by specifying the Table Id and Row
2834
+ * Id as the method's first two parameters) or changes to any Row (by
2835
+ * providing a `null` wildcard).
2836
+ *
2837
+ * Both, either, or neither of the `tableId` and `rowId` parameters can be
2838
+ * wildcarded with `null`. You can listen to a specific Row in a specific
2839
+ * Table, any Row in a specific Table, a specific Row in any Table, or any Row
2840
+ * in any Table.
2841
+ *
2842
+ * Use the optional mutator parameter to indicate that there is code in the
2843
+ * listener that will mutate Store data. If set to `false` (or omitted), such
2844
+ * mutations will be silently ignored. All relevant mutator listeners (with
2845
+ * this flag set to `true`) are called _before_ any non-mutator listeners
2846
+ * (since the latter may become relevant due to changes made in the former).
2847
+ * The changes made by mutator listeners do not fire other mutating listeners,
2848
+ * though they will fire non-mutator listeners.
2849
+ *
2850
+ * @param tableId The Id of the Table to listen to, or `null` as a wildcard.
2851
+ * @param rowId The Id of the Row to listen to, or `null` as a wildcard.
2852
+ * @param listener The function that will be called whenever the Cell Ids in
2853
+ * the Row change.
2854
+ * @param mutator An optional boolean that indicates that the listener mutates
2855
+ * Store data.
2856
+ * @returns A unique Id for the listener that can later be used to call it
2857
+ * explicitly, or to remove it.
2858
+ * @example
2859
+ * This example registers a listener that responds to any change to the Cell
2860
+ * Ids of a specific Row.
2861
+ *
2862
+ * ```js
2863
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
2864
+ * const listenerId = store.addCellIdsListener('pets', 'fido', (store) => {
2865
+ * console.log('Cell Ids for fido row in pets table changed');
2866
+ * console.log(store.getCellIds('pets', 'fido'));
2867
+ * });
2868
+ *
2869
+ * store.setCell('pets', 'fido', 'color', 'brown');
2870
+ * // -> 'Cell Ids for fido row in pets table changed'
2871
+ * // -> ['species', 'color']
2872
+ *
2873
+ * store.delListener(listenerId);
2874
+ * ```
2875
+ * @example
2876
+ * This example registers a listener that responds to any change to the Cell
2877
+ * Ids of any Row.
2878
+ *
2879
+ * ```js
2880
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
2881
+ * const listenerId = store.addCellIdsListener(
2882
+ * null,
2883
+ * null,
2884
+ * (store, tableId, rowId) => {
2885
+ * console.log(`Cell Ids for ${rowId} row in ${tableId} table changed`);
2886
+ * console.log(store.getCellIds(tableId, rowId));
2887
+ * },
2888
+ * );
2889
+ *
2890
+ * store.setCell('pets', 'fido', 'color', 'brown');
2891
+ * // -> 'Cell Ids for fido row in pets table changed'
2892
+ * // -> ['species', 'color']
2893
+ * store.setCell('species', 'dog', 'price', 5);
2894
+ * // -> 'Cell Ids for dog row in species table changed'
2895
+ * // -> ['price']
2896
+ *
2897
+ * store.delListener(listenerId);
2898
+ * ```
2899
+ * @example
2900
+ * This example registers a listener that responds to any change to the Cell
2901
+ * Ids of a specific Row, and which also mutates the Store itself.
2902
+ *
2903
+ * ```js
2904
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
2905
+ * const listenerId = store.addCellIdsListener(
2906
+ * 'pets',
2907
+ * 'fido',
2908
+ * (store, tableId, rowId) =>
2909
+ * store.setCell('meta', 'update', `${tableId}_${rowId}`, true),
2910
+ * true, // mutator
2911
+ * );
2912
+ *
2913
+ * store.setCell('pets', 'fido', 'color', 'brown');
2914
+ * console.log(store.getTable('meta'));
2915
+ * // -> {update: {pets_fido: true}}
2916
+ *
2917
+ * store.delListener(listenerId);
2918
+ * ```
2919
+ * @category Listener
2920
+ */
2921
+ addCellIdsListener(
2922
+ tableId: IdOrNull,
2923
+ rowId: IdOrNull,
2924
+ listener: CellIdsListener,
2925
+ mutator?: boolean,
2926
+ ): Id;
2927
+
2928
+ /**
2929
+ * The addCellListener method registers a listener function with the Store
2930
+ * that will be called whenever data in a Cell changes.
2931
+ *
2932
+ * The provided listener is a CellListener function, and will be called with a
2933
+ * reference to the Store, the Id of the Table that changed, the Id of the Row
2934
+ * that changed, the Id of the Cell that changed, the new Cell value, the old
2935
+ * Cell value, and a GetCellChange function in case you need to inspect any
2936
+ * changes that occurred.
2937
+ *
2938
+ * You can either listen to a single Cell (by specifying the Table Id, Row Id,
2939
+ * and Cell Id as the method's first three parameters) or changes to any Cell
2940
+ * (by providing `null` wildcards).
2941
+ *
2942
+ * All, some, or none of the `tableId`, `rowId`, and `cellId` parameters can
2943
+ * be wildcarded with `null`. You can listen to a specific Cell in a specific
2944
+ * Row in a specific Table, any Cell in any Row in any Table, for example - or
2945
+ * every other combination of wildcards.
2946
+ *
2947
+ * Use the optional mutator parameter to indicate that there is code in the
2948
+ * listener that will mutate Store data. If set to `false` (or omitted), such
2949
+ * mutations will be silently ignored. All relevant mutator listeners (with
2950
+ * this flag set to `true`) are called _before_ any non-mutator listeners
2951
+ * (since the latter may become relevant due to changes made in the former).
2952
+ * The changes made by mutator listeners do not fire other mutating listeners,
2953
+ * though they will fire non-mutator listeners.
2954
+ *
2955
+ * @param tableId The Id of the Table to listen to, or `null` as a wildcard.
2956
+ * @param rowId The Id of the Row to listen to, or `null` as a wildcard.
2957
+ * @param cellId The Id of the Cell to listen to, or `null` as a wildcard.
2958
+ * @param listener The function that will be called whenever data in the
2959
+ * matching Cell changes.
2960
+ * @param mutator An optional boolean that indicates that the listener mutates
2961
+ * Store data.
2962
+ * @returns A unique Id for the listener that can later be used to call it
2963
+ * explicitly, or to remove it.
2964
+ * @example
2965
+ * This example registers a listener that responds to any changes to a
2966
+ * specific Cell.
2967
+ *
2968
+ * ```js
2969
+ * const store = createStore().setTables({
2970
+ * pets: {fido: {species: 'dog', color: 'brown'}},
2971
+ * });
2972
+ * const listenerId = store.addCellListener(
2973
+ * 'pets',
2974
+ * 'fido',
2975
+ * 'color',
2976
+ * (store, tableId, rowId, cellId, newCell, oldCell, getCellChange) => {
2977
+ * console.log('color cell in fido row in pets table changed');
2978
+ * console.log([oldCell, newCell]);
2979
+ * console.log(getCellChange('pets', 'fido', 'color'));
2980
+ * },
2981
+ * );
2982
+ *
2983
+ * store.setCell('pets', 'fido', 'color', 'walnut');
2984
+ * // -> 'color cell in fido row in pets table changed'
2985
+ * // -> ['brown', 'walnut']
2986
+ * // -> [true, 'brown', 'walnut']
2987
+ *
2988
+ * store.delListener(listenerId);
2989
+ * ```
2990
+ * @example
2991
+ * This example registers a listener that responds to any changes to any Cell.
2992
+ *
2993
+ * ```js
2994
+ * const store = createStore().setTables({
2995
+ * pets: {fido: {species: 'dog', color: 'brown'}},
2996
+ * });
2997
+ * const listenerId = store.addCellListener(
2998
+ * null,
2999
+ * null,
3000
+ * null,
3001
+ * (store, tableId, rowId, cellId) => {
3002
+ * console.log(
3003
+ * `${cellId} cell in ${rowId} row in ${tableId} table changed`,
3004
+ * );
3005
+ * },
3006
+ * );
3007
+ *
3008
+ * store.setCell('pets', 'fido', 'color', 'walnut');
3009
+ * // -> 'color cell in fido row in pets table changed'
3010
+ * store.setTable('species', {dog: {price: 5}});
3011
+ * // -> 'price cell in dog row in species table changed'
3012
+ *
3013
+ * store.delListener(listenerId);
3014
+ * ```
3015
+ * @example
3016
+ * This example registers a listener that responds to any changes to a
3017
+ * specific Cell, and which also mutates the Store itself.
3018
+ *
3019
+ * ```js
3020
+ * const store = createStore().setTables({
3021
+ * pets: {fido: {species: 'dog', color: 'brown'}},
3022
+ * });
3023
+ * const listenerId = store.addCellListener(
3024
+ * 'pets',
3025
+ * 'fido',
3026
+ * 'color',
3027
+ * (store, tableId, rowId, cellId) =>
3028
+ * store.setCell('meta', 'update', `${tableId}_${rowId}_${cellId}`, true),
3029
+ * true,
3030
+ * );
3031
+ *
3032
+ * store.delCell('pets', 'fido', 'color');
3033
+ * console.log(store.getTable('meta'));
3034
+ * // -> {update: {pets_fido_color: true}}
3035
+ *
3036
+ * store.delListener(listenerId);
3037
+ * ```
3038
+ * @category Listener
3039
+ */
3040
+ addCellListener(
3041
+ tableId: IdOrNull,
3042
+ rowId: IdOrNull,
3043
+ cellId: IdOrNull,
3044
+ listener: CellListener,
3045
+ mutator?: boolean,
3046
+ ): Id;
3047
+
3048
+ /**
3049
+ * The addInvalidCellListener method registers a listener function with the
3050
+ * Store that will be called whenever invalid data was attempted to be written
3051
+ * to a Cell.
3052
+ *
3053
+ * The provided listener is an InvalidCellListener function, and will be
3054
+ * called with a reference to the Store, the Id of the Table, the Id of the
3055
+ * Row, and the Id of Cell that were being attempted to be changed. It is also
3056
+ * given the invalid value of the Cell, which could have been of absolutely
3057
+ * any type. Since there could have been multiple failed attempts to set the
3058
+ * Cell within a single transaction, this is an array containing each attempt,
3059
+ * chronologically.
3060
+ *
3061
+ * You can either listen to a single Cell (by specifying the Table Id, Row Id,
3062
+ * and Cell Id as the method's first three parameters) or invalid attempts to
3063
+ * change any Cell (by providing `null` wildcards).
3064
+ *
3065
+ * All, some, or none of the `tableId`, `rowId`, and `cellId` parameters can
3066
+ * be wildcarded with `null`. You can listen to a specific Cell in a specific
3067
+ * Row in a specific Table, any Cell in any Row in any Table, for example - or
3068
+ * every other combination of wildcards.
3069
+ *
3070
+ * Use the optional mutator parameter to indicate that there is code in the
3071
+ * listener that will mutate Store data. If set to `false` (or omitted), such
3072
+ * mutations will be silently ignored. All relevant mutator listeners (with
3073
+ * this flag set to `true`) are called _before_ any non-mutator listeners
3074
+ * (since the latter may become relevant due to changes made in the former).
3075
+ * The changes made by mutator listeners do not fire other mutating listeners,
3076
+ * though they will fire non-mutator listeners.
3077
+ *
3078
+ * Special note should be made for how the listener will be called when a
3079
+ * Schema is present. The listener will be called:
3080
+ *
3081
+ * - if a Table is being updated that is not specified in the Schema
3082
+ * - if a Cell is of the wrong type specified in the Schema
3083
+ * - if a Cell is omitted and is not defaulted in the Schema
3084
+ * - if an empty Row is provided and there are no Cell defaults in the Schema
3085
+ *
3086
+ * The listener will not be called if Cell that is defaulted in the Schema is
3087
+ * not provided, as long as all of the Cells that are _not_ defaulted _are_
3088
+ * provided.
3089
+ *
3090
+ * To help understand all of these schema-based conditions, please see the
3091
+ * Schema example below.
3092
+ *
3093
+ * @param tableId The Id of the Table to listen to, or `null` as a wildcard.
3094
+ * @param rowId The Id of the Row to listen to, or `null` as a wildcard.
3095
+ * @param cellId The Id of the Cell to listen to, or `null` as a wildcard.
3096
+ * @param listener The function that will be called whenever an attempt to
3097
+ * write invalid data to the matching Cell was made.
3098
+ * @param mutator An optional boolean that indicates that the listener mutates
3099
+ * Store data.
3100
+ * @returns A unique Id for the listener that can later be used to call it
3101
+ * explicitly, or to remove it.
3102
+ * @example
3103
+ * This example registers a listener that responds to any invalid changes to a
3104
+ * specific Cell.
3105
+ *
3106
+ * ```js
3107
+ * const store = createStore().setTables({
3108
+ * pets: {fido: {species: 'dog', color: 'brown'}},
3109
+ * });
3110
+ * const listenerId = store.addInvalidCellListener(
3111
+ * 'pets',
3112
+ * 'fido',
3113
+ * 'color',
3114
+ * (store, tableId, rowId, cellId, invalidCells) => {
3115
+ * console.log('Invalid color cell in fido row in pets table');
3116
+ * console.log(invalidCells);
3117
+ * },
3118
+ * );
3119
+ *
3120
+ * store.setCell('pets', 'fido', 'color', {r: '96', g: '4B', b: '00'});
3121
+ * // -> 'Invalid color cell in fido row in pets table'
3122
+ * // -> [{r: '96', g: '4B', b: '00'}]
3123
+ *
3124
+ * store.delListener(listenerId);
3125
+ * ```
3126
+ * @example
3127
+ * This example registers a listener that responds to any invalid changes to
3128
+ * any Cell - in a Store _without_ a Schema. Note also how it then responds to
3129
+ * cases where an empty or invalid Row objects, or Table objects, or Tables
3130
+ * objects are provided.
3131
+ *
3132
+ * ```js
3133
+ * const store = createStore().setTables({
3134
+ * pets: {fido: {species: 'dog', color: 'brown'}},
3135
+ * });
3136
+ * const listenerId = store.addInvalidCellListener(
3137
+ * null,
3138
+ * null,
3139
+ * null,
3140
+ * (store, tableId, rowId, cellId) => {
3141
+ * console.log(
3142
+ * `Invalid ${cellId} cell in ${rowId} row in ${tableId} table`,
3143
+ * );
3144
+ * },
3145
+ * );
3146
+ *
3147
+ * store.setCell('pets', 'fido', 'color', {r: '96', g: '4B', b: '00'});
3148
+ * // -> 'Invalid color cell in fido row in pets table'
3149
+ * store.setTable('sales', {fido: {date: new Date()}});
3150
+ * // -> 'Invalid date cell in fido row in sales table'
3151
+ *
3152
+ * store.setRow('pets', 'felix', {});
3153
+ * // -> 'Invalid undefined cell in felix row in pets table'
3154
+ *
3155
+ * store.setRow('filter', 'name', /[a-z]?/);
3156
+ * // -> 'Invalid undefined cell in name row in filter table'
3157
+ *
3158
+ * store.setRow('sales', '2021', {forecast: undefined});
3159
+ * // -> 'Invalid forecast cell in 2021 row in sales table'
3160
+ *
3161
+ * store.addRow('filter', /[0-9]?/);
3162
+ * // -> 'Invalid undefined cell in undefined row in filter table'
3163
+ *
3164
+ * store.setTable('raw', {});
3165
+ * // -> 'Invalid undefined cell in undefined row in raw table'
3166
+ *
3167
+ * store.setTable('raw', ['row1', 'row2']);
3168
+ * // -> 'Invalid undefined cell in undefined row in raw table'
3169
+ *
3170
+ * store.setTables(['table1', 'table2']);
3171
+ * // -> 'Invalid undefined cell in undefined row in undefined table'
3172
+ *
3173
+ * store.delListener(listenerId);
3174
+ * ```
3175
+ * @example
3176
+ * This example registers a listener that responds to any invalid changes to
3177
+ * any Cell - in a Store _with_ a Schema. Note how it responds to cases where
3178
+ * missing parameters are provided for optional, and defaulted Cell values in
3179
+ * a Row.
3180
+ *
3181
+ * ```js
3182
+ * const store = createStore().setSchema({
3183
+ * pets: {
3184
+ * species: {type: 'string'},
3185
+ * color: {type: 'string', default: 'unknown'},
3186
+ * },
3187
+ * });
3188
+ *
3189
+ * const listenerId = store.addInvalidCellListener(
3190
+ * null,
3191
+ * null,
3192
+ * null,
3193
+ * (store, tableId, rowId, cellId) => {
3194
+ * console.log(
3195
+ * `Invalid ${cellId} cell in ${rowId} row in ${tableId} table`,
3196
+ * );
3197
+ * },
3198
+ * );
3199
+ *
3200
+ * store.setRow('sales', 'fido', {price: 5});
3201
+ * // -> 'Invalid price cell in fido row in sales table'
3202
+ * // The listener is called, because the sales Table is not in the schema
3203
+ *
3204
+ * store.setRow('pets', 'felix', {species: true});
3205
+ * // -> 'Invalid species cell in felix row in pets table'
3206
+ * // The listener is called, because species is invalid...
3207
+ * console.log(store.getRow('pets', 'felix'));
3208
+ * // -> {color: 'unknown'}
3209
+ * // ...even though a Row was set with the default value
3210
+ *
3211
+ * store.setRow('pets', 'fido', {color: 'brown'});
3212
+ * // -> 'Invalid species cell in fido row in pets table'
3213
+ * // The listener is called, because species is missing and not defaulted...
3214
+ * console.log(store.getRow('pets', 'fido'));
3215
+ * // -> {color: 'brown'}
3216
+ * // ...even though a Row was set
3217
+ *
3218
+ * store.setRow('pets', 'rex', {species: 'dog'});
3219
+ * console.log(store.getRow('pets', 'rex'));
3220
+ * // -> {species: 'dog', color: 'unknown'}
3221
+ * // The listener is not called, because color is defaulted
3222
+ *
3223
+ * store.delTables().setSchema({
3224
+ * pets: {
3225
+ * species: {type: 'string'},
3226
+ * color: {type: 'string'},
3227
+ * },
3228
+ * });
3229
+ *
3230
+ * store.setRow('pets', 'cujo', {});
3231
+ * // -> 'Invalid species cell in cujo row in pets table'
3232
+ * // -> 'Invalid color cell in cujo row in pets table'
3233
+ * // -> 'Invalid undefined cell in cujo row in pets table'
3234
+ * // The listener is called multiple times, because neither Cell is defaulted
3235
+ * // and the Row as a whole is empty
3236
+ *
3237
+ * store.delListener(listenerId);
3238
+ * ```
3239
+ * @example
3240
+ * This example registers a listener that responds to any changes to a
3241
+ * specific Cell, and which also mutates the Store itself.
3242
+ *
3243
+ * ```js
3244
+ * const store = createStore().setTables({
3245
+ * pets: {fido: {species: 'dog', color: 'brown'}},
3246
+ * });
3247
+ * const listenerId = store.addInvalidCellListener(
3248
+ * 'pets',
3249
+ * 'fido',
3250
+ * 'color',
3251
+ * (store, tableId, rowId, cellId, invalidCells) =>
3252
+ * store.setCell(
3253
+ * 'meta',
3254
+ * 'invalid_updates',
3255
+ * `${tableId}_${rowId}_${cellId}`,
3256
+ * JSON.stringify(invalidCells[0]),
3257
+ * ),
3258
+ * true,
3259
+ * );
3260
+ *
3261
+ * store.setCell('pets', 'fido', 'color', {r: '96', g: '4B', b: '00'});
3262
+ * console.log(store.getRow('meta', 'invalid_updates'));
3263
+ * // -> {'pets_fido_color': '{"r":"96","g":"4B","b":"00"}'}
3264
+ *
3265
+ * store.delListener(listenerId);
3266
+ * ```
3267
+ * @category Listener
3268
+ * @since v1.1.0
3269
+ */
3270
+ addInvalidCellListener(
3271
+ tableId: IdOrNull,
3272
+ rowId: IdOrNull,
3273
+ cellId: IdOrNull,
3274
+ listener: InvalidCellListener,
3275
+ mutator?: boolean,
3276
+ ): Id;
3277
+
3278
+ /**
3279
+ * The addWillFinishTransactionListener method registers a listener function
3280
+ * with the Store that will be called just before other non-mutating listeners
3281
+ * are called at the end of the transaction.
3282
+ *
3283
+ * This is useful if you need to know that a set of listeners are about to be
3284
+ * called at the end of a transaction, perhaps to batch _their_ consequences
3285
+ * together.
3286
+ *
3287
+ * The provided TransactionListener will receive a reference to the Store and
3288
+ * a boolean to indicate whether Cell values have been touched during the
3289
+ * transaction. The latter flag is intended as a hint about whether
3290
+ * non-mutating listeners might be being called at the end of the transaction.
3291
+ *
3292
+ * Here, 'touched' means that Cell values have either been changed, or changed
3293
+ * and then changed back to its original value during the transaction. The
3294
+ * exception is a transaction that has been rolled back, for which the value
3295
+ * of `cellsTouched` in the listener will be `false` because all changes have
3296
+ * been reverted.
3297
+ *
3298
+ * @returns A unique Id for the listener that can later be used to remove it.
3299
+ * @example
3300
+ * This example registers a listener that is called at the end of the
3301
+ * transaction, just before its listeners will be called. The transactions
3302
+ * shown here variously change, touch, and rollback cells, demonstrating how
3303
+ * the `cellsTouched` parameter in the listener works.
3304
+ *
3305
+ * ```js
3306
+ * const store = createStore().setTables({
3307
+ * pets: {fido: {species: 'dog', color: 'brown'}},
3308
+ * });
3309
+ * const listenerId = store.addWillFinishTransactionListener(
3310
+ * (store, cellsTouched) => console.log(`Cells touched: ${cellsTouched}`),
3311
+ * );
3312
+ * const listenerId2 = store.addTablesListener(() =>
3313
+ * console.log('Tables changed'),
3314
+ * );
3315
+ *
3316
+ * store.transaction(() => store.setCell('pets', 'fido', 'color', 'brown'));
3317
+ * // -> 'Cells touched: false'
3318
+ *
3319
+ * store.transaction(() => store.setCell('pets', 'fido', 'color', 'walnut'));
3320
+ * // -> 'Cells touched: true'
3321
+ * // -> 'Tables changed'
3322
+ *
3323
+ * store.transaction(() => {
3324
+ * store.setRow('pets', 'felix', {species: 'cat'});
3325
+ * store.delRow('pets', 'felix');
3326
+ * });
3327
+ * // -> 'Cells touched: true'
3328
+ *
3329
+ * store.transaction(
3330
+ * () => store.setRow('pets', 'fido', {species: 'dog'}),
3331
+ * () => true,
3332
+ * );
3333
+ * // -> 'Cells touched: false'
3334
+ * // Transaction was rolled back.
3335
+ *
3336
+ * store.callListener(listenerId);
3337
+ * // -> 'Cells touched: undefined'
3338
+ * // It is meaningless to call this listener directly.
3339
+ *
3340
+ * store.delListener(listenerId).delListener(listenerId2);
3341
+ * ```
3342
+ * @category Listener
3343
+ * @since v1.3.0
3344
+ */
3345
+ addWillFinishTransactionListener(listener: TransactionListener): Id;
3346
+
3347
+ /**
3348
+ * The addDidFinishTransactionListener method registers a listener function
3349
+ * with the Store that will be called just after other non-mutating listeners
3350
+ * are called at the end of the transaction.
3351
+ *
3352
+ * This is useful if you need to know that a set of listeners have just been
3353
+ * called at the end of a transaction, perhaps to batch _their_ consequences
3354
+ * together.
3355
+ *
3356
+ * The provided TransactionListener will receive a reference to the Store and
3357
+ * a boolean to indicate whether Cell values have been touched during the
3358
+ * transaction. The latter flag is intended as a hint about whether
3359
+ * non-mutating listeners might have been called at the end of the
3360
+ * transaction.
3361
+ *
3362
+ * Here, 'touched' means that Cell values have either been changed, or changed
3363
+ * and then changed back to its original value during the transaction. The
3364
+ * exception is a transaction that has been rolled back, for which the value
3365
+ * of `cellsTouched` in the listener will be `false` because all changes have
3366
+ * been reverted.
3367
+ *
3368
+ * @returns A unique Id for the listener that can later be used to remove it.
3369
+ * @example
3370
+ * This example registers a listener that is called at the end of the
3371
+ * transaction, just after its listeners have been called. The transactions
3372
+ * shown here variously change, touch, and rollback cells, demonstrating how
3373
+ * the `cellsTouched` parameter in the listener works.
3374
+ *
3375
+ * ```js
3376
+ * const store = createStore().setTables({
3377
+ * pets: {fido: {species: 'dog', color: 'brown'}},
3378
+ * });
3379
+ * const listenerId = store.addDidFinishTransactionListener(
3380
+ * (store, cellsTouched) => console.log(`Cells touched: ${cellsTouched}`),
3381
+ * );
3382
+ * const listenerId2 = store.addTablesListener(() =>
3383
+ * console.log('Tables changed'),
3384
+ * );
3385
+ *
3386
+ * store.transaction(() => store.setCell('pets', 'fido', 'color', 'brown'));
3387
+ * // -> 'Cells touched: false'
3388
+ *
3389
+ * store.transaction(() => store.setCell('pets', 'fido', 'color', 'walnut'));
3390
+ * // -> 'Tables changed'
3391
+ * // -> 'Cells touched: true'
3392
+ *
3393
+ * store.transaction(() => {
3394
+ * store.setRow('pets', 'felix', {species: 'cat'});
3395
+ * store.delRow('pets', 'felix');
3396
+ * });
3397
+ * // -> 'Cells touched: true'
3398
+ *
3399
+ * store.transaction(
3400
+ * () => store.setRow('pets', 'fido', {species: 'dog'}),
3401
+ * () => true,
3402
+ * );
3403
+ * // -> 'Cells touched: false'
3404
+ * // Transaction was rolled back.
3405
+ *
3406
+ * store.callListener(listenerId);
3407
+ * // -> 'Cells touched: undefined'
3408
+ * // It is meaningless to call this listener directly.
3409
+ *
3410
+ * store.delListener(listenerId).delListener(listenerId2);
3411
+ * ```
3412
+ * @category Listener
3413
+ * @since v1.3.0
3414
+ */
3415
+ addDidFinishTransactionListener(listener: TransactionListener): Id;
3416
+
3417
+ /**
3418
+ * The callListener method provides a way for you to manually provoke a
3419
+ * listener to be called, even if the underlying data hasn't changed.
3420
+ *
3421
+ * This is useful when you are using mutator listeners to guarantee that data
3422
+ * conforms to programmatic conditions, and those conditions change such that
3423
+ * you need to update the Store in bulk.
3424
+ *
3425
+ * @param listenerId The Id of the listener to call.
3426
+ * @returns A reference to the Store.
3427
+ * @example
3428
+ * This example registers a listener that ensures a Cell has one of list of a
3429
+ * valid values. After that list changes, the listener is called to apply the
3430
+ * condition to the existing data.
3431
+ *
3432
+ * ```js
3433
+ * const validColors = ['walnut', 'brown', 'black'];
3434
+ * const store = createStore();
3435
+ * const listenerId = store.addCellListener(
3436
+ * 'pets',
3437
+ * null,
3438
+ * 'color',
3439
+ * (store, tableId, rowId, cellId, color) => {
3440
+ * if (!validColors.includes(color)) {
3441
+ * store.setCell(tableId, rowId, cellId, validColors[0]);
3442
+ * }
3443
+ * },
3444
+ * true,
3445
+ * );
3446
+ *
3447
+ * store.setRow('pets', 'fido', {species: 'dog', color: 'honey'});
3448
+ * console.log(store.getRow('pets', 'fido'));
3449
+ * // -> {species: 'dog', color: 'walnut'}
3450
+ *
3451
+ * validColors.shift();
3452
+ * console.log(validColors);
3453
+ * // -> ['brown', 'black']
3454
+ *
3455
+ * store.callListener(listenerId);
3456
+ * console.log(store.getRow('pets', 'fido'));
3457
+ * // -> {species: 'dog', color: 'brown'}
3458
+ *
3459
+ * store.delListener(listenerId);
3460
+ * ```
3461
+ * @category Listener
3462
+ */
3463
+ callListener(listenerId: Id): Store;
3464
+
3465
+ /**
3466
+ * The delListener method removes a listener that was previously added to the
3467
+ * Store.
3468
+ *
3469
+ * Use the Id returned by whichever method was used to add the listener. Note
3470
+ * that the Store may re-use this Id for future listeners added to it.
3471
+ *
3472
+ * @param listenerId The Id of the listener to remove.
3473
+ * @returns A reference to the Store.
3474
+ * @example
3475
+ * This example registers a listener and then removes it.
3476
+ *
3477
+ * ```js
3478
+ * const store = createStore().setTables({
3479
+ * pets: {fido: {species: 'dog', color: 'brown'}},
3480
+ * });
3481
+ * const listenerId = store.addTablesListener(() => {
3482
+ * console.log('Tables changed');
3483
+ * });
3484
+ *
3485
+ * store.setCell('pets', 'fido', 'color', 'walnut');
3486
+ * // -> 'Tables changed'
3487
+ *
3488
+ * store.delListener(listenerId);
3489
+ *
3490
+ * store.setCell('pets', 'fido', 'color', 'honey');
3491
+ * // -> undefined
3492
+ * // The listener is not called.
3493
+ * ```
3494
+ * @category Listener
3495
+ */
3496
+ delListener(listenerId: Id): Store;
3497
+
3498
+ /**
3499
+ * The getListenerStats method provides a set of statistics about the
3500
+ * listeners registered with the Store, and is used for debugging purposes.
3501
+ *
3502
+ * The StoreListenerStats object contains a breakdown of the different types
3503
+ * of listener. Totals include both mutator and non-mutator listeners.
3504
+ *
3505
+ * The statistics are only populated in a debug build: production builds
3506
+ * return an empty object. The method is intended to be used during
3507
+ * development to ensure your application is not leaking listener
3508
+ * registrations, for example.
3509
+ *
3510
+ * @returns A StoreListenerStats object containing Store listener statistics.
3511
+ * @example
3512
+ * This example gets the listener statistics of a small and simple Store.
3513
+ *
3514
+ * ```js
3515
+ * const store = createStore();
3516
+ * store.addTablesListener(() => console.log('Tables changed'));
3517
+ * store.addRowIdsListener(() => console.log('Row Ids changed'));
3518
+ *
3519
+ * const listenerStats = store.getListenerStats();
3520
+ * console.log(listenerStats.rowIds);
3521
+ * // -> 1
3522
+ * console.log(listenerStats.tables);
3523
+ * // -> 1
3524
+ * ```
3525
+ * @category Development
3526
+ */
3527
+ getListenerStats(): StoreListenerStats;
3528
+ }
3529
+
3530
+ /**
3531
+ * The createStore function creates a Store, and is the main entry point into
3532
+ * the store module.
3533
+ *
3534
+ * Since (or perhaps _because_) it is the most important function in the whole
3535
+ * module, it is trivially simple.
3536
+ *
3537
+ * @returns A reference to the new Store.
3538
+ * @example
3539
+ * This example creates a Store.
3540
+ *
3541
+ * ```js
3542
+ * const store = createStore();
3543
+ * console.log(store.getTables());
3544
+ * // -> {}
3545
+ * ```
3546
+ * @example
3547
+ * This example creates a Store with some initial data:
3548
+ *
3549
+ * ```js
3550
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
3551
+ * console.log(store.getTables());
3552
+ * // -> {pets: {fido: {species: 'dog'}}}
3553
+ * ```
3554
+ * @example
3555
+ * This example creates a Store with some initial data and a Schema:
3556
+ *
3557
+ * ```js
3558
+ * const store = createStore()
3559
+ * .setTables({pets: {fido: {species: 'dog'}}})
3560
+ * .setSchema({
3561
+ * pets: {
3562
+ * species: {type: 'string'},
3563
+ * sold: {type: 'boolean', default: false},
3564
+ * },
3565
+ * });
3566
+ * console.log(store.getTables());
3567
+ * // -> {pets: {fido: {species: 'dog', sold: false}}}
3568
+ * ```
3569
+ * @see The Basics guides
3570
+ * @category Creation
3571
+ */
3572
+ export function createStore(): Store;