tinybase 0.0.0 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/LICENSE +21 -0
  2. package/lib/checkpoints.d.ts +876 -0
  3. package/lib/checkpoints.js +1 -0
  4. package/lib/checkpoints.js.gz +0 -0
  5. package/lib/common.d.ts +59 -0
  6. package/lib/debug/checkpoints.d.ts +876 -0
  7. package/lib/debug/checkpoints.js +326 -0
  8. package/lib/debug/common.d.ts +59 -0
  9. package/lib/debug/indexes.d.ts +829 -0
  10. package/lib/debug/indexes.js +390 -0
  11. package/lib/debug/metrics.d.ts +753 -0
  12. package/lib/debug/metrics.js +391 -0
  13. package/lib/debug/persisters.d.ts +704 -0
  14. package/lib/debug/persisters.js +191 -0
  15. package/lib/debug/relationships.d.ts +1114 -0
  16. package/lib/debug/relationships.js +418 -0
  17. package/lib/debug/store.d.ts +2503 -0
  18. package/lib/debug/store.js +725 -0
  19. package/lib/debug/tinybase.d.ts +13 -0
  20. package/lib/debug/tinybase.js +1708 -0
  21. package/lib/debug/ui-react.d.ts +7158 -0
  22. package/lib/debug/ui-react.js +1040 -0
  23. package/lib/indexes.d.ts +829 -0
  24. package/lib/indexes.js +1 -0
  25. package/lib/indexes.js.gz +0 -0
  26. package/lib/metrics.d.ts +753 -0
  27. package/lib/metrics.js +1 -0
  28. package/lib/metrics.js.gz +0 -0
  29. package/lib/persisters.d.ts +704 -0
  30. package/lib/persisters.js +1 -0
  31. package/lib/persisters.js.gz +0 -0
  32. package/lib/relationships.d.ts +1114 -0
  33. package/lib/relationships.js +1 -0
  34. package/lib/relationships.js.gz +0 -0
  35. package/lib/store.d.ts +2503 -0
  36. package/lib/store.js +1 -0
  37. package/lib/store.js.gz +0 -0
  38. package/lib/tinybase.d.ts +13 -0
  39. package/lib/tinybase.js +1 -0
  40. package/lib/tinybase.js.gz +0 -0
  41. package/lib/ui-react.d.ts +7158 -0
  42. package/lib/ui-react.js +1 -0
  43. package/lib/ui-react.js.gz +0 -0
  44. package/lib/umd/checkpoints.js +1 -0
  45. package/lib/umd/checkpoints.js.gz +0 -0
  46. package/lib/umd/indexes.js +1 -0
  47. package/lib/umd/indexes.js.gz +0 -0
  48. package/lib/umd/metrics.js +1 -0
  49. package/lib/umd/metrics.js.gz +0 -0
  50. package/lib/umd/persisters.js +1 -0
  51. package/lib/umd/persisters.js.gz +0 -0
  52. package/lib/umd/relationships.js +1 -0
  53. package/lib/umd/relationships.js.gz +0 -0
  54. package/lib/umd/store.js +1 -0
  55. package/lib/umd/store.js.gz +0 -0
  56. package/lib/umd/tinybase.js +1 -0
  57. package/lib/umd/tinybase.js.gz +0 -0
  58. package/lib/umd/ui-react.js +1 -0
  59. package/lib/umd/ui-react.js.gz +0 -0
  60. package/package.json +98 -2
  61. package/readme.md +195 -0
package/lib/store.d.ts ADDED
@@ -0,0 +1,2503 @@
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 can be provided to the createStore function when first
21
+ * creating the Store. It is also used when setting all of the tables together
22
+ * with the setTables method, and when getting them back out again with the
23
+ * getTables method. A Tables object is a regular JavaScript object containing
24
+ * individual Table objects, keyed by their Id.
25
+ *
26
+ * @example
27
+ * ```js
28
+ * const tables: Tables = {
29
+ * pets: {
30
+ * fido: {species: 'dog', color: 'brown'},
31
+ * felix: {species: 'cat'},
32
+ * },
33
+ * species: {
34
+ * dog: {price: 5},
35
+ * cat: {price: 4},
36
+ * },
37
+ * };
38
+ * ```
39
+ * @category Store
40
+ */
41
+ export type Tables = {[tableId: Id]: Table};
42
+
43
+ /**
44
+ * The Table type is the data structure representing the data in a single table.
45
+ *
46
+ * A Table is used when setting a table with the setTable method, and when
47
+ * getting it back out again with the getTable method. A Table object is a
48
+ * regular JavaScript object containing individual Row objects, keyed by their
49
+ * Id.
50
+ *
51
+ * @example
52
+ * ```js
53
+ * const table: Table = {
54
+ * fido: {species: 'dog', color: 'brown'},
55
+ * felix: {species: 'cat'},
56
+ * };
57
+ * ```
58
+ * @category Store
59
+ */
60
+ export type Table = {[rowId: Id]: Row};
61
+
62
+ /**
63
+ * The Row type is the data structure representing the data in a single row.
64
+ *
65
+ * A Row is used when setting a row with the setRow method, and when getting it
66
+ * back out again with the getRow method. A Row object is a regular JavaScript
67
+ * object containing individual Cell objects, keyed by their Id.
68
+ *
69
+ * @example
70
+ * ```js
71
+ * const row: Row = {species: 'dog', color: 'brown'};
72
+ * ```
73
+ * @category Store
74
+ */
75
+ export type Row = {[cellId: Id]: Cell};
76
+
77
+ /**
78
+ * The Cell type is the data structure representing the data in a single cell.
79
+ *
80
+ * A Cell is used when setting a cell with the setCell method, and when getting
81
+ * it back out again with the getCell method. A Cell is a JavaScript string,
82
+ * number, or boolean.
83
+ *
84
+ * @example
85
+ * ```js
86
+ * const cell: Cell = 'dog';
87
+ * ```
88
+ * @category Store
89
+ */
90
+ export type Cell = string | number | boolean;
91
+
92
+ /**
93
+ * The TableCallback type describes a function that takes a Tables's Id and a
94
+ * callback to loop over each Row within it.
95
+ *
96
+ * A TableCallback is provided when using the forEachTable method, so that you
97
+ * can do something based on every Table in the Store. See that method for
98
+ * specific examples.
99
+ *
100
+ * @param tableId The Id of the Table that the callback can operate on.
101
+ * @param forEachRow A function that will let you iterate over the Row objects
102
+ * in this Table.
103
+ * @category Callback
104
+ */
105
+ export type TableCallback = (
106
+ tableId: Id,
107
+ forEachRow: (rowCallback: RowCallback) => void,
108
+ ) => void;
109
+
110
+ /**
111
+ * The RowCallback type describes a function that takes a Row's Id and a
112
+ * callback to loop over each Cell within it.
113
+ *
114
+ * A RowCallback is provided when using the forEachRow method, so that you can
115
+ * do something based on every Row in a Table. See that method for specific
116
+ * examples.
117
+ *
118
+ * @param rowId The Id of the Row that the callback can operate on.
119
+ * @param forEachRow A function that will let you iterate over the Cell values
120
+ * in this Row.
121
+ * @category Callback
122
+ */
123
+ export type RowCallback = (
124
+ rowId: Id,
125
+ forEachCell: (cellCallback: CellCallback) => void,
126
+ ) => void;
127
+
128
+ /**
129
+ * The CellCallback type describes a function that takes a Cell's Id and its
130
+ * value.
131
+ *
132
+ * A CellCallback is provided when using the forEachCell method, so that you can
133
+ * do something based on every Cell in a Row. See that method for specific
134
+ * examples.
135
+ *
136
+ * @param cellId The Id of the Cell that the callback can operate on.
137
+ * @param cell The value of the Cell.
138
+ * @category Callback
139
+ */
140
+ export type CellCallback = (cellId: Id, cell: Cell) => void;
141
+
142
+ /**
143
+ * The MapCell type describes a function that takes an existing Cell value and
144
+ * returns another.
145
+ *
146
+ * A MapCell can be provided in the setCell method to map an existing value to a
147
+ * new one, such as when incrementing a number. See that method for specific
148
+ * examples.
149
+ *
150
+ * @param cell The current value of the Cell to map to a new value.
151
+ * @category Callback
152
+ */
153
+ export type MapCell = (cell: Cell | undefined) => Cell;
154
+
155
+ /**
156
+ * The GetCell type describes a function that takes a Id and returns the Cell
157
+ * value for a particular Row.
158
+ *
159
+ * A GetCell can be provided when setting definitions, as in the
160
+ * setMetricDefinition method of a Metrics object, or the setIndexDefinition
161
+ * method of an Indexes object. See those methods for specific examples.
162
+ *
163
+ * @param cellId The Id of the Cell to fetch the value for.
164
+ * @category Callback
165
+ */
166
+ export type GetCell = (cellId: Id) => Cell | undefined;
167
+
168
+ /**
169
+ * The TablesListener type describes a function that is used to listen to
170
+ * changes to the whole Store.
171
+ *
172
+ * A TablesListener is provided when using the addTablesListener method. See
173
+ * that method for specific examples.
174
+ *
175
+ * When called, a TablesListener is given a reference to the Store and a
176
+ * GetCellChange function that can be used to query Cell values before and after
177
+ * the current transaction.
178
+ *
179
+ * Note that if the listener was manually forced to be called (with the
180
+ * callListener method rather than due to a real change in the Store), the
181
+ * GetCellChange function will not be present.
182
+ *
183
+ * @param store A reference to the Store that changed.
184
+ * @param getCellChange A function that returns information about any Cell's
185
+ * changes.
186
+ * @category Listener
187
+ */
188
+ export type TablesListener = (
189
+ store: Store,
190
+ getCellChange: GetCellChange | undefined,
191
+ ) => void;
192
+
193
+ /**
194
+ * The TableIdsListener type describes a function that is used to listen to
195
+ * changes to the Table Ids in the Store.
196
+ *
197
+ * A TableIdsListener is provided when using the addTableIdsListener method. See
198
+ * that method for specific examples.
199
+ *
200
+ * When called, a TableIdsListener is given a reference to the Store.
201
+ *
202
+ * @param store A reference to the Store that changed.
203
+ * @category Listener
204
+ */
205
+ export type TableIdsListener = (store: Store) => void;
206
+
207
+ /**
208
+ * The TableListener type describes a function that is used to listen to changes
209
+ * to a Table.
210
+ *
211
+ * A TableListener is provided when using the addTableListener method. See that
212
+ * method for specific examples.
213
+ *
214
+ * When called, a TableListener is given a reference to the Store, the Id of the
215
+ * Table that changed, and a GetCellChange function that can be used to query
216
+ * Cell values before and after the current transaction.
217
+ *
218
+ * Note that if the listener was manually forced to be called (with the
219
+ * callListener method rather than due to a real change in the Store), the
220
+ * GetCellChange function will not be present.
221
+ *
222
+ * @param store A reference to the Store that changed.
223
+ * @param tableId The Id of the Table that changed.
224
+ * @param getCellChange A function that returns information about any Cell's
225
+ * changes.
226
+ * @category Listener
227
+ */
228
+ export type TableListener = (
229
+ store: Store,
230
+ tableId: Id,
231
+ getCellChange: GetCellChange | undefined,
232
+ ) => void;
233
+
234
+ /**
235
+ * The RowIdsListener type describes a function that is used to listen to
236
+ * changes to the Row Ids in a Table.
237
+ *
238
+ * A RowIdsListener is provided when using the addRowIdsListener method. See
239
+ * that method for specific examples.
240
+ *
241
+ * When called, a RowIdsListener is given a reference to the Store, and the Id
242
+ * of the Table whose Row Ids changed.
243
+ *
244
+ * @param store A reference to the Store that changed.
245
+ * @param tableId The Id of the Table that changed.
246
+ * @category Listener
247
+ */
248
+ export type RowIdsListener = (store: Store, tableId: Id) => void;
249
+
250
+ /**
251
+ * The RowListener type describes a function that is used to listen to changes
252
+ * to a Row.
253
+ *
254
+ * A RowListener is provided when using the addRowListener method. See that
255
+ * method for specific examples.
256
+ *
257
+ * When called, a RowListener is given a reference to the Store, the Id of the
258
+ * Table that changed, the Id of the Row that changed, and a GetCellChange
259
+ * function that can be used to query Cell values before and after the current
260
+ * transaction.
261
+ *
262
+ * Note that if the listener was manually forced to be called (with the
263
+ * callListener method rather than due to a real change in the Store), the
264
+ * GetCellChange function will not be present.
265
+ *
266
+ * @param store A reference to the Store that changed.
267
+ * @param tableId The Id of the Table that changed.
268
+ * @param rowId The Id of the Row that changed.
269
+ * @param getCellChange A function that returns information about any Cell's
270
+ * changes.
271
+ * @category Listener
272
+ */
273
+ export type RowListener = (
274
+ store: Store,
275
+ tableId: Id,
276
+ rowId: Id,
277
+ getCellChange: GetCellChange | undefined,
278
+ ) => void;
279
+
280
+ /**
281
+ * The CellIdsListener type describes a function that is used to listen to
282
+ * changes to the Cell Ids in a Row.
283
+ *
284
+ * A CellIdsListener is provided when using the addCellIdsListener method. See
285
+ * that method for specific examples.
286
+ *
287
+ * When called, a CellIdsListener is given a reference to the Store, the Id of
288
+ * the Table that changed, and the Id of the Row whose Cell Ids changed.
289
+ *
290
+ * @param store A reference to the Store that changed.
291
+ * @param tableId The Id of the Table that changed.
292
+ * @param rowId The Id of the Row that changed.
293
+ * changes.
294
+ * @category Listener
295
+ */
296
+ export type CellIdsListener = (store: Store, tableId: Id, rowId: Id) => void;
297
+
298
+ /**
299
+ * The CellListener type describes a function that is used to listen to changes
300
+ * to a Cell.
301
+ *
302
+ * A CellListener is provided when using the addCellListener method. See that
303
+ * method for specific examples.
304
+ *
305
+ * When called, a CellListener is given a reference to the Store, the Id of the
306
+ * Table that changed, the Id of the Row that changed, and the Id of Cell that
307
+ * changed. It is also given the new value of the Cell, the old value of the
308
+ * Cell, and a GetCellChange function that can be used to query Cell values
309
+ * before and after the current transaction.
310
+ *
311
+ * Note that if the listener was manually forced to be called (with the
312
+ * callListener method rather than due to a real change in the Store), the
313
+ * GetCellChange function will not be present and the new and old values of the
314
+ * Cell will be the same.
315
+ *
316
+ * @param store A reference to the Store that changed.
317
+ * @param tableId The Id of the Table that changed.
318
+ * @param rowId The Id of the Row that changed.
319
+ * @param cellId The Id of the Cell that changed.
320
+ * @param newCell The new value of the Cell that changed.
321
+ * @param oldCell The old value of the Cell that changed.
322
+ * @param getCellChange A function that returns information about any Cell's
323
+ * changes.
324
+ * @category Listener
325
+ */
326
+ export type CellListener = (
327
+ store: Store,
328
+ tableId: Id,
329
+ rowId: Id,
330
+ cellId: Id,
331
+ newCell: Cell,
332
+ oldCell: Cell,
333
+ getCellChange: GetCellChange | undefined,
334
+ ) => void;
335
+
336
+ /**
337
+ * The GetCellChange type describes a function that returns information about
338
+ * any Cell's changes during a transaction.
339
+ *
340
+ * A GetCellChange function is provided to every listener when called due the
341
+ * Store changing. The listener can then fetch the previous value of a Cell
342
+ * before the current transaction, the new value after it, and a convenience
343
+ * flag that indicates that the value has changed.
344
+ *
345
+ * @param tableId The Id of the Table to inspect.
346
+ * @param rowId The Id of the Row to inspect.
347
+ * @param cellId The Id of the Cell to inspect.
348
+ * @returns A CellChange array containing information about the Cell's changes.
349
+ * @category Listener
350
+ */
351
+ export type GetCellChange = (tableId: Id, rowId: Id, cellId: Id) => CellChange;
352
+
353
+ /**
354
+ * The CellChange type describes a Cell's changes during a transaction.
355
+ *
356
+ * This is returned by the GetCellChange function that is provided to every
357
+ * listener when called. This array contains the previous value of a Cell
358
+ * before the current transaction, the new value after it, and a convenience
359
+ * flag that indicates that the value has changed.
360
+ *
361
+ * @category Listener
362
+ */
363
+ export type CellChange = [
364
+ changed: boolean,
365
+ oldCell: Cell | undefined,
366
+ newCell: Cell | undefined,
367
+ ];
368
+
369
+ /**
370
+ * The Schema type describes the structure of a Store in terms of valid Table
371
+ * Ids and the types of Cell that can exist within them.
372
+ *
373
+ * A Schema comprises a JavaScript object describing each Table, in turn a
374
+ * nested JavaScript object containing the each Cell and its CellSchema. It is
375
+ * provided to the createStore function or to the setSchema method.
376
+ *
377
+ * @example
378
+ * When applied to a Store, this Schema only allows one Table called `pets`, in
379
+ * which each Row may contain a string `species` Cell, and is guaranteed to
380
+ * contain a boolean `sold` Cell that defaults to `false`.
381
+ *
382
+ *```js
383
+ * const schema: Schema = {
384
+ * pets: {
385
+ * species: {type: 'string'},
386
+ * sold: {type: 'boolean', default: false},
387
+ * },
388
+ * };
389
+ * ```
390
+ * @category Schema
391
+ */
392
+ export type Schema = {
393
+ [tableId: Id]: {
394
+ [cellId: Id]: CellSchema;
395
+ };
396
+ };
397
+
398
+ /**
399
+ * The CellSchema type describes what values are allowed for each Cell in a
400
+ * Table.
401
+ *
402
+ * A CellSchema specifies the type of the Cell (`string`, `boolean`, or
403
+ * `number`), and what the default value can be when an explicit value is not
404
+ * specified.
405
+ *
406
+ * If a default value is provided (and its type is correct), you can be certain
407
+ * that that Cell will always be present in a Row.
408
+ *
409
+ * If the default value is _not_ provided (or its type is incorrect), the Cell
410
+ * may be missing from the Row, but when present you can be guaranteed it is of
411
+ * the correct type.
412
+ *
413
+ * @example
414
+ * When applied to a Store, this CellSchema ensures a boolean Cell is always
415
+ * present, and defaults it to `false`.
416
+ *
417
+ *```js
418
+ * const requiredBoolean: CellSchema = {type: 'boolean', default: false};
419
+ * ```
420
+ * @category Schema
421
+ */
422
+ export type CellSchema =
423
+ | {
424
+ type: 'string';
425
+ default?: string;
426
+ }
427
+ | {
428
+ type: 'number';
429
+ default?: number;
430
+ }
431
+ | {
432
+ type: 'boolean';
433
+ default?: boolean;
434
+ };
435
+
436
+ /**
437
+ * The StoreListenerStats type describes the number of listeners registered with
438
+ * the Store, and can be used for debugging purposes.
439
+ *
440
+ * The StoreListenerStats object contains a breakdown of the different types of
441
+ * listener. Totals include both mutator and non-mutator listeners. A
442
+ * StoreListenerStats object is returned from the getListenerStats method, and
443
+ * is only populated in a debug build.
444
+ *
445
+ * @category Development
446
+ */
447
+ export type StoreListenerStats = {
448
+ /**
449
+ * The number of TablesListeners registered with the Store.
450
+ */
451
+ tables?: number;
452
+ /**
453
+ * The number of TableIdsListeners registered with the Store.
454
+ */
455
+ tableIds?: number;
456
+ /**
457
+ * The number of TableListeners registered with the Store.
458
+ */
459
+ table?: number;
460
+ /**
461
+ * The number of RowIdsListeners registered with the Store.
462
+ */
463
+ rowIds?: number;
464
+ /**
465
+ * The number of RowListeners registered with the Store.
466
+ */
467
+ row?: number;
468
+ /**
469
+ * The number of CellIdsListeners registered with the Store.
470
+ */
471
+ cellIds?: number;
472
+ /**
473
+ * The number of CellListeners registered with the Store.
474
+ */
475
+ cell?: number;
476
+ };
477
+
478
+ /**
479
+ * A Store is the main location for keeping structured state and tabular data.
480
+ *
481
+ * Create a Store easily with the createStore function. From there, you can set
482
+ * and get data, add listeners for when the data changes, set a Schema, and so
483
+ * on.
484
+ *
485
+ * A Store has a simple hierarchical structure:
486
+ *
487
+ * - The Store contains a number of Table objects.
488
+ * - Each Table contains a number of Row objects.
489
+ * - Each Row contains a number of Cell objects.
490
+ *
491
+ * A Cell is a string, boolean, or number value.
492
+ *
493
+ * The members of each level of this hierarchy are identified with a unique Id
494
+ * (which is a string). In other words you can naively think of a Store as a
495
+ * three-level-deep JavaScript object, keyed with strings:
496
+ *
497
+ * ```json
498
+ * { // Store
499
+ * "table1": { // Table
500
+ * "row1": { // Row
501
+ * "cell1": "one", // Cell (string)
502
+ * "cell2": true, // Cell (boolean)
503
+ * "cell3": 3, // Cell (number)
504
+ * ...
505
+ * },
506
+ * ...
507
+ * },
508
+ * ...
509
+ * }
510
+ * ```
511
+ *
512
+ * In its default form, a Store has no sense of a structured schema, so, as long
513
+ * as they are unique within their own parent, the Id keys can each be any
514
+ * string you want. However, you _can_ optionally specify a Schema for a Store,
515
+ * which then usefully constrains the Table and Cell Ids (and Cell values) you
516
+ * can use.
517
+ *
518
+ * # Setting and getting data
519
+ *
520
+ * Every part of the Store can be accessed with getter methods. When you
521
+ * retrieve data from the Store, you are receiving a copy - rather than a
522
+ * reference - of it. This means that manipulating the data in the Store must be
523
+ * performed with the equivalent setter and deleter methods.
524
+ *
525
+ * To benefit from the reactive behavior of the Store, you can also subscribe to
526
+ * changes on any part of it with 'listeners'. Registering a listener returns a
527
+ * listener Id (that you can use later to remove it with the delListener
528
+ * method), and it will then be called every time there is a change within the
529
+ * part of the hierarchy you're listening to.
530
+ *
531
+ * This table shows the main ways you can set, get, and listen to, different
532
+ * types of data in a Store:
533
+ *
534
+ * |Type|Get data|Set data|Delete data|Add a listener|
535
+ * |-|-|-|-|-|
536
+ * |Tables|getTables|setTables|delTables|addTablesListener|
537
+ * |Table Ids|getTableIds|-|-|addTableIdsListener|
538
+ * |Table|getTable|setTable|delTable|addTableListener|
539
+ * |Row Ids|getRowIds|-|-|addRowIdsListener|
540
+ * |Row|getRow|setRow|delRow|addRowListener|
541
+ * |Cell Ids|getCellIds|-|-|addCellIdsListener|
542
+ * |Cell|getCell|setCell|delCell|addCellListener|
543
+ *
544
+ * Additionally, there are two extra methods to manipulate Row objects. The
545
+ * addRow method is like the setRow method but automatically assigns it a new
546
+ * unique Id. And the setPartialRow method lets you update multiple Cell values
547
+ * in a Row without affecting the others.
548
+ *
549
+ * The transaction method is used to wrap multiple changes to the Store so that
550
+ * the relevant listeners only fire once.
551
+ *
552
+ * The setJson method and the getJson method allow you to work with a
553
+ * JSON-encoded representation of the entire Store, which is useful for
554
+ * persisting it.
555
+ *
556
+ * Finally, the callListener method provides a way for you to manually provoke a
557
+ * listener to be called, even if the underlying data hasn't changed. This is
558
+ * useful when you are using mutator listeners to guarantee that data conforms
559
+ * to programmatic conditions, and those conditions change such that you need to
560
+ * update the Store in bulk.
561
+ *
562
+ * Read more about setting and changing data in The Basics guides, and about
563
+ * listeners in the Listening to Stores guide.
564
+ *
565
+ * # Creating a Schema
566
+ *
567
+ * You can set a Schema on a Store when you create it with createStore function,
568
+ * or at a later stage with the setSchema method. A Schema constrains the Table
569
+ * Ids the Store can have, and the types of Cell data in each Table. Each Cell
570
+ * requires its type to be specified, and can also take a default value for when
571
+ * it's not specified.
572
+ *
573
+ * You can also get a serialization of the Schema out of the Store with the
574
+ * getSchemaJson method, and remove the Schema altogether with the delSchema
575
+ * method.
576
+ *
577
+ * Read more about schemas in the Using Schemas guide.
578
+ *
579
+ * # Convenience methods
580
+ *
581
+ * There are a few additional helper methods to make it easier to work with a
582
+ * Store. There are methods for easily checking the existence of a Table, Row,
583
+ * or Cell, and iterators that let you act on the children of a common parent:
584
+ *
585
+ * ||Checking existence|Iterator|
586
+ * |-|-|-|
587
+ * |Table|hasTable|forEachTable|
588
+ * |Row|hasRow|forEachRow|
589
+ * |Cell|hasCell|forEachCell|
590
+ *
591
+ * Finally, the getListenerStats method describes the current state of the
592
+ * Store's listeners for debugging purposes.
593
+ *
594
+ * @example
595
+ * This example shows a very simple lifecycle of a Store: from creation, to
596
+ * adding and getting some data, and then registering and removing a listener.
597
+ *
598
+ * ```js
599
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
600
+ * console.log(store.getRow('pets', 'fido'));
601
+ * // -> {species: 'dog'}
602
+ *
603
+ * store.setCell('pets', 'fido', 'color', 'brown');
604
+ * console.log(store.getCell('pets', 'fido', 'color'));
605
+ * // -> 'brown'
606
+ *
607
+ * const listenerId = store.addTableListener('pets', () => {
608
+ * console.log('changed');
609
+ * });
610
+ *
611
+ * store.setCell('pets', 'fido', 'sold', false);
612
+ * // -> 'changed'
613
+ *
614
+ * store.delListener(listenerId);
615
+ * ```
616
+ * @category Store
617
+ */
618
+ export interface Store {
619
+ /**
620
+ * The getTables method returns a Tables object containing the entire data of
621
+ * the Store.
622
+ *
623
+ * Note that this returns a copy of, rather than a reference to the underlying
624
+ * data, so changes made to the returned object are not made to the Store
625
+ * itself.
626
+ *
627
+ * @returns A Tables object containing the entire data of the Store.
628
+ * @example
629
+ * This example retrieves the data in a Store.
630
+ *
631
+ * ```js
632
+ * const store = createStore().setTables({
633
+ * pets: {fido: {species: 'dog'}},
634
+ * species: {dog: {price: 5}},
635
+ * });
636
+ * console.log(store.getTables());
637
+ * // -> {pets: {fido: {species: 'dog'}}, species: {dog: {price: 5}}}
638
+ * ```
639
+ * @example
640
+ * This example retrieves the Tables of an empty Store, returning an empty
641
+ * object.
642
+ *
643
+ * ```js
644
+ * const store = createStore();
645
+ * console.log(store.getTables());
646
+ * // -> {}
647
+ * ```
648
+ * @see
649
+ * # Guides
650
+ * Creating a Store
651
+ * @see Indexes
652
+ * @category Getter
653
+ */
654
+ getTables(): Tables;
655
+
656
+ /**
657
+ * The getTableIds method returns the Ids of every Table in the Store.
658
+ *
659
+ * Note that this returns a copy of, rather than a reference, to the list of
660
+ * Ids, so changes made to the list are not made to the Store itself. Although
661
+ * the order of Ids have no meaning, this method is expected to return them in
662
+ * the order in which each Table was added.
663
+ *
664
+ * @returns An array of the Ids of every Table in the Store.
665
+ * @example
666
+ * This example retrieves the Table Ids in a Store.
667
+ *
668
+ * ```js
669
+ * const store = createStore().setTables({
670
+ * pets: {fido: {species: 'dog'}},
671
+ * species: {dog: {price: 5}},
672
+ * });
673
+ * console.log(store.getTableIds());
674
+ * // -> ['pets', 'species']
675
+ * ```
676
+ * @example
677
+ * This example retrieves the Table Ids of an empty Store, returning an empty
678
+ * array.
679
+ *
680
+ * ```js
681
+ * const store = createStore();
682
+ * console.log(store.getTableIds());
683
+ * // -> []
684
+ * ```
685
+ * @category Getter
686
+ */
687
+ getTableIds(): Ids;
688
+
689
+ /**
690
+ * The getTable method returns an object containing the entire data of a
691
+ * single Table in the Store.
692
+ *
693
+ * Note that this returns a copy of, rather than a reference to the underlying
694
+ * data, so changes made to the returned object are not made to the Store
695
+ * itself.
696
+ *
697
+ * @param tableId The Id of the Table in the Store.
698
+ * @returns An object containing the entire data of the Table.
699
+ * @example
700
+ * This example retrieves the data in a single Table.
701
+ *
702
+ * ```js
703
+ * const store = createStore().setTables({
704
+ * pets: {fido: {species: 'dog'}},
705
+ * species: {dog: {price: 5}},
706
+ * });
707
+ * console.log(store.getTable('pets'));
708
+ * // -> {fido: {species: 'dog'}}
709
+ * ```
710
+ * @example
711
+ * This example retrieves a Table that does not exist, returning an empty
712
+ * object.
713
+ *
714
+ * ```js
715
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
716
+ * console.log(store.getTable('employees'));
717
+ * // -> {}
718
+ * ```
719
+ * @category Getter
720
+ */
721
+ getTable(tableId: Id): Table;
722
+
723
+ /**
724
+ * The getRowIds method returns the Ids of every Row in a given Table.
725
+ *
726
+ * Note that this returns a copy of, rather than a reference, to the list of
727
+ * Ids, so changes made to the list are not made to the Store itself. Although
728
+ * the order of Ids have no meaning, this method is expected to return them in
729
+ * the order in which each Row was added.
730
+ *
731
+ * @param tableId The Id of the Table in the Store.
732
+ * @returns An array of the Ids of every Row in the Table.
733
+ * @example
734
+ * This example retrieves the Row Ids in a Table.
735
+ *
736
+ * ```js
737
+ * const store = createStore().setTables({
738
+ * pets: {
739
+ * fido: {species: 'dog'},
740
+ * felix: {species: 'cat'},
741
+ * },
742
+ * });
743
+ * console.log(store.getRowIds('pets'));
744
+ * // -> ['fido', 'felix']
745
+ * ```
746
+ * @example
747
+ * This example retrieves the Row Ids of a Table that does not exist,
748
+ * returning an empty array.
749
+ *
750
+ * ```js
751
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
752
+ * console.log(store.getRowIds('employees'));
753
+ * // -> []
754
+ * ```
755
+ * @category Getter
756
+ */
757
+ getRowIds(tableId: Id): Ids;
758
+
759
+ /**
760
+ * The getRow method returns an object containing the entire data of a single
761
+ * Row in a given Table.
762
+ *
763
+ * Note that this returns a copy of, rather than a reference to the underlying
764
+ * data, so changes made to the returned object are not made to the Store
765
+ * itself.
766
+ *
767
+ * @param tableId The Id of the Table in the Store.
768
+ * @param rowId The Id of the Row in the Table.
769
+ * @returns An object containing the entire data of the Row.
770
+ * @example
771
+ * This example retrieves the data in a single Row.
772
+ *
773
+ * ```js
774
+ * const store = createStore().setTables({
775
+ * pets: {
776
+ * fido: {species: 'dog'},
777
+ * felix: {species: 'cat'},
778
+ * },
779
+ * });
780
+ * console.log(store.getRow('pets', 'fido'));
781
+ * // -> {species: 'dog'}
782
+ * ```
783
+ * @example
784
+ * This example retrieves a Row that does not exist, returning an empty
785
+ * object.
786
+ *
787
+ * ```js
788
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
789
+ * console.log(store.getRow('pets', 'felix'));
790
+ * // -> {}
791
+ * ```
792
+ * @category Getter
793
+ */
794
+ getRow(tableId: Id, rowId: Id): Row;
795
+
796
+ /**
797
+ * The getCellIds method returns the Ids of every Cell in a given Row, in a
798
+ * given Table.
799
+ *
800
+ * Note that this returns a copy of, rather than a reference, to the list of
801
+ * Ids, so changes made to the list are not made to the Store itself. Although
802
+ * the order of Ids have no meaning, this method is expected to return them in
803
+ * the order in which each Row was added.
804
+ *
805
+ * @param tableId The Id of the Table in the Store.
806
+ * @param rowId The Id of the Row in the Table.
807
+ * @returns An array of the Ids of every Cell in the Row.
808
+ * @example
809
+ * This example retrieves the Cell Ids in a Row.
810
+ *
811
+ * ```js
812
+ * const store = createStore().setTables({
813
+ * pets: {
814
+ * fido: {species: 'dog', color: 'brown'},
815
+ * },
816
+ * });
817
+ * console.log(store.getCellIds('pets', 'fido'));
818
+ * // -> ['species', 'color']
819
+ * ```
820
+ * @example
821
+ * This example retrieves the Cell Ids of a Cell that does not exist,
822
+ * returning an empty array.
823
+ *
824
+ * ```js
825
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
826
+ * console.log(store.getCellIds('pets', 'felix'));
827
+ * // -> []
828
+ * ```
829
+ * @category Getter
830
+ */
831
+ getCellIds(tableId: Id, rowId: Id): Ids;
832
+
833
+ /**
834
+ * The getCell method returns an object containing the value of a single Cell
835
+ * in a given Row, in a given Table.
836
+ *
837
+ * Note that this returns a copy of, rather than a reference to the underlying
838
+ * data, so changes made to the returned object are not made to the Store
839
+ * itself.
840
+ *
841
+ * @param tableId The Id of the Table in the Store.
842
+ * @param rowId The Id of the Row in the Table.
843
+ * @param cellId The Id of the Cell in the Row.
844
+ * @returns The value of the Cell.
845
+ * @example
846
+ * This example retrieves a single Cell.
847
+ *
848
+ * ```js
849
+ * const store = createStore().setTables({
850
+ * pets: {fido: {species: 'dog', color: 'brown'}},
851
+ * });
852
+ * console.log(store.getCell('pets', 'fido', 'species'));
853
+ * // -> 'dog'
854
+ * ```
855
+ * @example
856
+ * This example retrieves a Cell that does not exist, returning `undefined`.
857
+ *
858
+ * ```js
859
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
860
+ * console.log(store.getCell('pets', 'fido', 'color'));
861
+ * // -> undefined
862
+ * ```
863
+ * @category Getter
864
+ */
865
+ getCell(tableId: Id, rowId: Id, cellId: Id): Cell | undefined;
866
+
867
+ /**
868
+ * The hasTable method returns a boolean indicating whether a given Table
869
+ * exists in the Store.
870
+ *
871
+ * @param tableId The Id of a possible Table in the Store.
872
+ * @returns Whether a Table with that Id exists.
873
+ * @example
874
+ * This example shows two simple Table existence checks.
875
+ *
876
+ * ```js
877
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
878
+ * console.log(store.hasTable('pets'));
879
+ * // -> true
880
+ * console.log(store.hasTable('employees'));
881
+ * // -> false
882
+ * ```
883
+ * @category Getter
884
+ */
885
+ hasTable(tableId: Id): boolean;
886
+
887
+ /**
888
+ * The hasRow method returns a boolean indicating whether a given Row exists
889
+ * in the Store.
890
+ *
891
+ * @param tableId The Id of a possible Table in the Store.
892
+ * @param rowId The Id of a possible Row in the Table.
893
+ * @returns Whether a Row with that Id exists in that Table.
894
+ * @example
895
+ * This example shows two simple Row existence checks.
896
+ *
897
+ * ```js
898
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
899
+ * console.log(store.hasRow('pets', 'fido'));
900
+ * // -> true
901
+ * console.log(store.hasRow('pets', 'felix'));
902
+ * // -> false
903
+ * ```
904
+ * @category Getter
905
+ */
906
+ hasRow(tableId: Id, rowId: Id): boolean;
907
+
908
+ /**
909
+ * The hasCell method returns a boolean indicating whether a given Cell exists
910
+ * in the Store.
911
+ *
912
+ * @param tableId The Id of a possible Table in the Store.
913
+ * @param rowId The Id of a possible Row in the Table.
914
+ * @param cellId The Id of a possible Cell in the Row.
915
+ * @returns Whether a Cell with that Id exists in that Row in that Table.
916
+ * @example
917
+ * This example shows two simple Cell existence checks.
918
+ *
919
+ * ```js
920
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
921
+ * console.log(store.hasCell('pets', 'fido', 'species'));
922
+ * // -> true
923
+ * console.log(store.hasCell('pets', 'fido', 'color'));
924
+ * // -> false
925
+ * ```
926
+ * @category Getter
927
+ */
928
+ hasCell(tableId: Id, rowId: Id, cellId: Id): boolean;
929
+
930
+ /**
931
+ * The getJson method returns a string serialization of all of the Tables in
932
+ * the Store.
933
+ *
934
+ * @returns A string serialization of all of the Tables in the Store.
935
+ * @example
936
+ * This example serializes the contents of a Store.
937
+ *
938
+ * ```js
939
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
940
+ * console.log(store.getJson());
941
+ * // -> '{"pets":{"fido":{"species":"dog"}}}'
942
+ * ```
943
+ * @example
944
+ * This example serializes the contents of an empty Store.
945
+ *
946
+ * ```js
947
+ * const store = createStore();
948
+ * console.log(store.getJson());
949
+ * // -> '{}'
950
+ * ```
951
+ * @category Getter
952
+ */
953
+ getJson(): Json;
954
+
955
+ /**
956
+ * The getSchemaJson method returns a string serialization of the Schema of
957
+ * the Store.
958
+ *
959
+ * If no Schema has been set on the Store (or if it has been removed with the
960
+ * delSchema method), then it will return the serialization of an empty
961
+ * object, `{}`.
962
+ *
963
+ * @returns A string serialization of the Schema of the Store.
964
+ * @example
965
+ * This example serializes the Schema of a Store.
966
+ *
967
+ * ```js
968
+ * const store = createStore().setSchema({
969
+ * pets: {
970
+ * species: {type: 'string'},
971
+ * sold: {type: 'boolean'},
972
+ * },
973
+ * });
974
+ * console.log(store.getSchemaJson());
975
+ * // -> '{"pets":{"species":{"type":"string"},"sold":{"type":"boolean"}}}'
976
+ * ```
977
+ * @example
978
+ * This example serializes the Schema of an empty Store.
979
+ *
980
+ * ```js
981
+ * const store = createStore();
982
+ * console.log(store.getSchemaJson());
983
+ * // -> '{}'
984
+ * ```
985
+ * @category Getter
986
+ */
987
+ getSchemaJson(): Json;
988
+
989
+ /**
990
+ * The setTables method takes an object and sets the entire data of the Store.
991
+ *
992
+ * This method will cause listeners to be called for any Table, Row, Cell, or
993
+ * Id changes resulting from it.
994
+ *
995
+ * Any part of the provided object that is invalid (either according to the
996
+ * Tables type, or because it does not match a Schema associated with the
997
+ * Store), will be ignored silently.
998
+ *
999
+ * Assuming that at least some of the provided Tables object is valid, any
1000
+ * data that was already present in the Store will be completely overwritten.
1001
+ * If the object is completely invalid, no change will be made to the Store.
1002
+ *
1003
+ * The method returns a reference to the Store to that subsequent operations
1004
+ * can be chained in a fluent style.
1005
+ *
1006
+ * @param tables The data of the Store to be set.
1007
+ * @example
1008
+ * This example sets the data of a Store.
1009
+ *
1010
+ * ```js
1011
+ * const store = createStore().setTables({
1012
+ * pets: {fido: {species: 'dog'}},
1013
+ * species: {dog: {price: 5}},
1014
+ * });
1015
+ * console.log(store.getTables());
1016
+ * // -> {pets: {fido: {species: 'dog'}}, species: {dog: {price: 5}}}
1017
+ * ```
1018
+ * @example
1019
+ * This example attempts to set the data of an existing Store with partly
1020
+ * invalid, and then completely invalid, Tables objects.
1021
+ *
1022
+ * ```js
1023
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1024
+ *
1025
+ * store.setTables({pets: {felix: {species: 'cat', bug: []}}});
1026
+ * console.log(store.getTables());
1027
+ * // -> {pets: {felix: {species: 'cat'}}}
1028
+ *
1029
+ * store.setTables({meaning: 42});
1030
+ * console.log(store.getTables());
1031
+ * // -> {pets: {felix: {species: 'cat'}}}
1032
+ * ```
1033
+ * @category Setter
1034
+ */
1035
+ setTables(tables: Tables): Store;
1036
+
1037
+ /**
1038
+ * The setTable method takes an object and sets the entire data of a single
1039
+ * Table in the Store.
1040
+ *
1041
+ * This method will cause listeners to be called for any Table, Row, Cell, or
1042
+ * Id changes resulting from it.
1043
+ *
1044
+ * Any part of the provided object that is invalid (either according to the
1045
+ * Table type, or because it does not match a Schema associated with the
1046
+ * Store), will be ignored silently.
1047
+ *
1048
+ * Assuming that at least some of the provided Table object is valid, any data
1049
+ * that was already present in the Store for that Table will be completely
1050
+ * overwritten. If the object is completely invalid, no change will be made to
1051
+ * the Store.
1052
+ *
1053
+ * The method returns a reference to the Store to that subsequent operations
1054
+ * can be chained in a fluent style.
1055
+ *
1056
+ * @param tableId The Id of the Table in the Store.
1057
+ * @param table The data of a single Table to be set.
1058
+ * @example
1059
+ * This example sets the data of a single Table.
1060
+ *
1061
+ * ```js
1062
+ * const store = createStore().setTable('pets', {
1063
+ * fido: {species: 'dog'},
1064
+ * felix: {species: 'cat'},
1065
+ * });
1066
+ * console.log(store.getTables());
1067
+ * // -> {pets: {fido: {species: 'dog'}, felix: {species: 'cat'}}}
1068
+ * ```
1069
+ * @example
1070
+ * This example attempts to set the data of an existing Store with partly
1071
+ * invalid, and then completely invalid, Table objects.
1072
+ *
1073
+ * ```js
1074
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1075
+ *
1076
+ * store.setTable('pets', {felix: {species: 'cat', bug: []}});
1077
+ * console.log(store.getTables());
1078
+ * // -> {pets: {felix: {species: 'cat'}}}
1079
+ *
1080
+ * store.setTable('pets', {meaning: 42});
1081
+ * console.log(store.getTables());
1082
+ * // -> {pets: {felix: {species: 'cat'}}}
1083
+ * ```
1084
+ * @category Setter
1085
+ */
1086
+ setTable(tableId: Id, table: Table): Store;
1087
+
1088
+ /**
1089
+ * The setRow method takes an object and sets the entire data of a single Row
1090
+ * in the Store.
1091
+ *
1092
+ * This method will cause listeners to be called for any Table, Row, Cell, or
1093
+ * Id changes resulting from it.
1094
+ *
1095
+ * Any part of the provided object that is invalid (either according to the
1096
+ * Row type, or because it does not match a Schema associated with the Store),
1097
+ * will be ignored silently.
1098
+ *
1099
+ * Assuming that at least some of the provided Row object is valid, any data
1100
+ * that was already present in the Store for that Row will be completely
1101
+ * overwritten. If the object is completely invalid, no change will be made to
1102
+ * the Store.
1103
+ *
1104
+ * The method returns a reference to the Store to that subsequent operations
1105
+ * can be chained in a fluent style.
1106
+ *
1107
+ * @param tableId The Id of the Table in the Store.
1108
+ * @param rowId The Id of the Row in the Table.
1109
+ * @param row The data of a single Row to be set.
1110
+ * @returns A reference to the Store.
1111
+ * @example
1112
+ * This example sets the data of a single Row.
1113
+ *
1114
+ * ```js
1115
+ * const store = createStore().setRow('pets', 'fido', {species: 'dog'});
1116
+ * console.log(store.getTables());
1117
+ * // -> {pets: {fido: {species: 'dog'}}}
1118
+ * ```
1119
+ * @example
1120
+ * This example attempts to set the data of an existing Store with partly
1121
+ * invalid, and then completely invalid, Row objects.
1122
+ *
1123
+ * ```js
1124
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1125
+ *
1126
+ * store.setRow('pets', 'fido', {color: 'brown', bug: []});
1127
+ * console.log(store.getTables());
1128
+ * // -> {pets: {fido: {color: 'brown'}}}
1129
+ *
1130
+ * store.setRow('pets', 'fido', 42);
1131
+ * console.log(store.getTables());
1132
+ * // -> {pets: {fido: {color: 'brown'}}}
1133
+ * ```
1134
+ * @category Setter
1135
+ */
1136
+ setRow(tableId: Id, rowId: Id, row: Row): Store;
1137
+
1138
+ /**
1139
+ * The addRow method takes an object and creates a new Row in the Store,
1140
+ * returning the unique Id assigned to it.
1141
+ *
1142
+ * This method will cause listeners to be called for any Table, Row, Cell, or
1143
+ * Id changes resulting from it.
1144
+ *
1145
+ * Any part of the provided object that is invalid (either according to the
1146
+ * Row type, or because it does not match a Schema associated with the Store),
1147
+ * will be ignored silently.
1148
+ *
1149
+ * Assuming that at least some of the provided Row object is valid, a new Row
1150
+ * will be created. If the object is completely invalid, no change will be
1151
+ * made to the Store and the method will return `undefined`
1152
+ *
1153
+ * You should not guarantee the form of the unique Id that is generated when a
1154
+ * Row is added to the Table. However it is likely to be a string
1155
+ * representation of an increasing integer.
1156
+ *
1157
+ * @param tableId The Id of the Table in the Store.
1158
+ * @param row The data of a single Row to be added.
1159
+ * @returns A reference to the Store.
1160
+ * @example
1161
+ * This example adds a single Row.
1162
+ *
1163
+ * ```js
1164
+ * const store = createStore();
1165
+ * console.log(store.addRow('pets', {species: 'dog'}));
1166
+ * // -> '0'
1167
+ * console.log(store.getTables());
1168
+ * // -> {pets: {'0': {species: 'dog'}}}
1169
+ * ```
1170
+ * @example
1171
+ * This example attempts to add Rows to an existing Store with partly invalid,
1172
+ * and then completely invalid, Row objects.
1173
+ *
1174
+ * ```js
1175
+ * const store = createStore().setTables({pets: {'0': {species: 'dog'}}});
1176
+ *
1177
+ * console.log(store.addRow('pets', {species: 'cat', bug: []}));
1178
+ * // -> '1'
1179
+ * console.log(store.getTables());
1180
+ * // -> {pets: {'0': {species: 'dog'}, '1': {species: 'cat'}}}
1181
+ *
1182
+ * console.log(store.addRow('pets', 42));
1183
+ * // -> undefined
1184
+ * console.log(store.getTables());
1185
+ * // -> {pets: {'0': {species: 'dog'}, '1': {species: 'cat'}}}
1186
+ * ```
1187
+ * @category Setter
1188
+ */
1189
+ addRow(tableId: Id, row: Row): Id | undefined;
1190
+
1191
+ /**
1192
+ * The setPartialRow method takes an object and sets partial data of a single
1193
+ * Row in the Store, leaving other Cell values unaffected.
1194
+ *
1195
+ * This method will cause listeners to be called for any Table, Row, Cell, or
1196
+ * Id changes resulting from it.
1197
+ *
1198
+ * Any part of the provided object that is invalid (either according to the
1199
+ * Row type, or because, when combined with the current Row data, it does not
1200
+ * match a Schema associated with the Store), will be ignored silently.
1201
+ *
1202
+ * Assuming that at least some of the provided Row object is valid, it will be
1203
+ * merged with the data that was already present in the Store. If the object
1204
+ * is completely invalid, no change will be made to the Store.
1205
+ *
1206
+ * The method returns a reference to the Store to that subsequent operations
1207
+ * can be chained in a fluent style.
1208
+ *
1209
+ * @param tableId The Id of the Table in the Store.
1210
+ * @param rowId The Id of the Row in the Table.
1211
+ * @param partialRow The partial data of a single Row to be set.
1212
+ * @returns A reference to the Store.
1213
+ * @example
1214
+ * This example sets some of the data of a single Row.
1215
+ *
1216
+ * ```js
1217
+ * const store = createStore().setTables({
1218
+ * pets: {fido: {species: 'dog', color: 'brown'}},
1219
+ * });
1220
+ * store.setPartialRow('pets', 'fido', {color: 'walnut', visits: 1});
1221
+ * console.log(store.getTables());
1222
+ * // -> {pets: {fido: {species: 'dog', color: 'walnut', visits: 1}}}
1223
+ * ```
1224
+ * @example
1225
+ * This example attempts to set some of the data of an existing Store with
1226
+ * partly invalid, and then completely invalid, Row objects.
1227
+ *
1228
+ * ```js
1229
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1230
+ *
1231
+ * store.setPartialRow('pets', 'fido', {color: 'brown', bug: []});
1232
+ * console.log(store.getTables());
1233
+ * // -> {pets: {fido: {species: 'dog', color: 'brown'}}}
1234
+ *
1235
+ * store.setPartialRow('pets', 'fido', 42);
1236
+ * console.log(store.getTables());
1237
+ * // -> {pets: {fido: {species: 'dog', color: 'brown'}}}
1238
+ * ```
1239
+ * @category Setter
1240
+ */
1241
+ setPartialRow(tableId: Id, rowId: Id, partialRow: Row): Store;
1242
+
1243
+ /**
1244
+ * The setCell method sets the value of a single Cell in the Store.
1245
+ *
1246
+ * This method will cause listeners to be called for any Table, Row, Cell, or
1247
+ * Id changes resulting from it.
1248
+ *
1249
+ * If the Cell value is invalid (either because of its type, or because it
1250
+ * does not match a Schema associated with the Store), will be ignored
1251
+ * silently.
1252
+ *
1253
+ * As well as string, number, or boolean Cell types, this method can also take
1254
+ * a MapCell function that takes the current Cell value as a parameter and
1255
+ * maps it. This is useful if you want to efficiently increment a value
1256
+ * without fetching it first, for example.
1257
+ *
1258
+ * The method returns a reference to the Store to that subsequent operations
1259
+ * can be chained in a fluent style.
1260
+ *
1261
+ * @param tableId The Id of the Table in the Store.
1262
+ * @param rowId The Id of the Row in the Table.
1263
+ * @param cellId The Id of the Cell in the Row.
1264
+ * @param cell The value of the Cell to be set, or a MapCell function to
1265
+ * update it.
1266
+ * @returns A reference to the Store.
1267
+ * @example
1268
+ * This example sets the value of a single Cell.
1269
+ *
1270
+ * ```js
1271
+ * const store = createStore().setCell('pets', 'fido', 'species', 'dog');
1272
+ * console.log(store.getTables());
1273
+ * // -> {pets: {fido: {species: 'dog'}}}
1274
+ * ```
1275
+ * @example
1276
+ * This example sets the data of a single Cell by mapping the existing value.
1277
+ *
1278
+ * ```js
1279
+ * const increment = (cell) => cell + 1;
1280
+ * const store = createStore().setTables({pets: {fido: {visits: 1}}});
1281
+ *
1282
+ * store.setCell('pets', 'fido', 'visits', increment);
1283
+ * console.log(store.getCell('pets', 'fido', 'visits'));
1284
+ * // -> 2
1285
+ * ```
1286
+ * @example
1287
+ * This example attempts to set the data of an existing Store with an invalid
1288
+ * Cell value.
1289
+ *
1290
+ * ```js
1291
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1292
+ *
1293
+ * store.setCell('pets', 'fido', 'bug', []);
1294
+ * console.log(store.getTables());
1295
+ * // -> {pets: {fido: {species: 'dog'}}}
1296
+ * ```
1297
+ * @category Setter
1298
+ */
1299
+ setCell(tableId: Id, rowId: Id, cellId: Id, cell: Cell | MapCell): Store;
1300
+
1301
+ /**
1302
+ * The setJson method takes a string serialization of all of the Tables in the
1303
+ * Store and attempts to update it to that value
1304
+ *
1305
+ * If the JSON cannot be parsed, this will fail silently. If it can be parsed,
1306
+ * it will then be subject to the same validation rules as the setTables
1307
+ * method (according to the Tables type, and matching any Schema associated
1308
+ * with the Store).
1309
+ *
1310
+ * @param json A string serialization of all of the Tables in the Store.
1311
+ * @returns A reference to the Store.
1312
+ * @example
1313
+ * This example sets the contents of a Store from a serialization.
1314
+ *
1315
+ * ```js
1316
+ * const store = createStore();
1317
+ * store.setJson('{"pets":{"fido":{"species":"dog"}}}');
1318
+ * console.log(store.getTables());
1319
+ * // -> {pets: {fido: {species: 'dog'}}}
1320
+ * ```
1321
+ * @example
1322
+ * This example attempts to set the contents of a Store from an invalid
1323
+ * serialization.
1324
+ *
1325
+ * ```js
1326
+ * const store = createStore();
1327
+ * store.setJson('{"pets":{"fido":{');
1328
+ * console.log(store.getTables());
1329
+ * // -> {}
1330
+ * ```
1331
+ * @category Setter
1332
+ */
1333
+ setJson(json: Json): Store;
1334
+
1335
+ /**
1336
+ * The setSchema method lets you specify the Schema of the Store.
1337
+ *
1338
+ * Note that this may result in a change to data in the Store, as defaults are
1339
+ * applied or as invalid Table, Row, or Cell objects are removed. These
1340
+ * changes will fire any listeners to that data, as expected.
1341
+ *
1342
+ * You can also specify the Schema at the time of creation, as the second
1343
+ * parameter of the createStore function. When no longer needed, you can also
1344
+ * completely remove an existing Schema with the delSchema method.
1345
+ *
1346
+ * @param schema The Schema to be set for the Store.
1347
+ * @returns A reference to the Store.
1348
+ * @example
1349
+ * This example sets the Schema of a Store after it has been created.
1350
+ *
1351
+ * ```js
1352
+ * const store = createStore().setSchema({
1353
+ * pets: {
1354
+ * species: {type: 'string'},
1355
+ * sold: {type: 'boolean', default: false},
1356
+ * },
1357
+ * });
1358
+ * store.addRow('pets', {species: 'dog', color: 'brown', sold: 'maybe'});
1359
+ * console.log(store.getTables());
1360
+ * // -> {pets: {0: {species: 'dog', sold: false}}}
1361
+ * ```
1362
+ * @category Setter
1363
+ */
1364
+ setSchema(tablesSchema: Schema): Store;
1365
+
1366
+ /**
1367
+ * The delTables method lets you remove all of the data in a Store.
1368
+ *
1369
+ * @returns A reference to the Store.
1370
+ * @example
1371
+ * This example removes the data of a Store.
1372
+ *
1373
+ * ```js
1374
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1375
+ *
1376
+ * store.delTables();
1377
+ * console.log(store.getTables());
1378
+ * // -> {}
1379
+ * ```
1380
+ * @category Deleter
1381
+ */
1382
+ delTables(): Store;
1383
+
1384
+ /**
1385
+ * The delTable method lets you remove a single Table from the Store.
1386
+ *
1387
+ * @param tableId The Id of the Table in the Store.
1388
+ * @returns A reference to the Store.
1389
+ * @example
1390
+ * This example removes a Table from a Store.
1391
+ *
1392
+ * ```js
1393
+ * const store = createStore().setTables({
1394
+ * pets: {fido: {species: 'dog'}},
1395
+ * species: {dog: {price: 5}},
1396
+ * });
1397
+ * store.delTable('pets');
1398
+ *
1399
+ * console.log(store.getTables());
1400
+ * // -> {species: {dog: {price: 5}}}
1401
+ * ```
1402
+ * @category Deleter
1403
+ */
1404
+ delTable(tableId: Id): Store;
1405
+
1406
+ /**
1407
+ * The delRow method lets you remove a single Row from a Table.
1408
+ *
1409
+ * If this is the last Row in its Table, then that Table will be removed.
1410
+ *
1411
+ * @param tableId The Id of the Table in the Store.
1412
+ * @param rowId The Id of the Row in the Table.
1413
+ * @returns A reference to the Store.
1414
+ * @example
1415
+ * This example removes a Row from a Table.
1416
+ *
1417
+ * ```js
1418
+ * const store = createStore().setTables({
1419
+ * pets: {fido: {species: 'dog'}, felix: {species: 'cat'}},
1420
+ * });
1421
+ * store.delRow('pets', 'fido');
1422
+ *
1423
+ * console.log(store.getTables());
1424
+ * // -> {pets: {felix: {species: 'cat'}}}
1425
+ * ```
1426
+ * @category Deleter
1427
+ */
1428
+ delRow(tableId: Id, rowId: Id): Store;
1429
+
1430
+ /**
1431
+ * The delCell method lets you remove a single Cell from a Row.
1432
+ *
1433
+ * When there is no Schema applied to the Store, then if this is the last Cell
1434
+ * in its Row, then that Row will be removed. If, in turn, that is the last
1435
+ * Row in its Table, then that Table will be removed.
1436
+ *
1437
+ * If there is a Schema applied to the Store and it specifies a default value
1438
+ * for this Cell, then deletion will result in it being set back to its
1439
+ * default value. To override this, use the `forceDel` parameter, as described
1440
+ * below.
1441
+ *
1442
+ * The `forceDel` parameter is an optional flag that is only relevant if a
1443
+ * Schema provides a default value for this Cell. Under such circumstances,
1444
+ * deleting a Cell value will normally restore it to the default value. If
1445
+ * this flag is set to `true`, the complete removal of the Cell is instead
1446
+ * guaranteed. But since doing do so would result in an invalid Row (according
1447
+ * to the Schema), in fact the whole Row is deleted to retain the integrity of
1448
+ * the Table. Therefore, this flag should be used with caution.
1449
+ *
1450
+ * @param tableId The Id of the Table in the Store.
1451
+ * @param rowId The Id of the Row in the Table.
1452
+ * @param cellId The Id of the Cell in the Row.
1453
+ * @param forceDel An optional flag to indicate that the whole Row should be
1454
+ * deleted, even if a Schema provides a default value for this Cell. Defaults
1455
+ * to `false`.
1456
+ * @returns A reference to the Store.
1457
+ * @example
1458
+ * This example removes a Cell from a Row without a Schema.
1459
+ *
1460
+ * ```js
1461
+ * const store = createStore().setTables({
1462
+ * pets: {fido: {species: 'dog', sold: true}},
1463
+ * });
1464
+ * store.delCell('pets', 'fido', 'sold');
1465
+ *
1466
+ * console.log(store.getTables());
1467
+ * // -> {pets: {fido: {species: 'dog'}}}
1468
+ * ```
1469
+ * @example
1470
+ * This example removes a Cell from a Row with a Schema that defaults its
1471
+ * value.
1472
+ *
1473
+ * ```js
1474
+ * const store = createStore()
1475
+ * .setTables({
1476
+ * pets: {fido: {species: 'dog', sold: true}},
1477
+ * })
1478
+ * .setSchema({
1479
+ * pets: {
1480
+ * species: {type: 'string'},
1481
+ * sold: {type: 'boolean', default: false},
1482
+ * },
1483
+ * });
1484
+ * store.delCell('pets', 'fido', 'sold');
1485
+ *
1486
+ * console.log(store.getTables());
1487
+ * // -> {pets: {fido: {species: 'dog', sold: false}}}
1488
+ * ```
1489
+ * @example
1490
+ * This example removes a Cell from a Row with a Schema that defaults its
1491
+ * value, but uses the `forceDel` parameter to override it.
1492
+ *
1493
+ * ```js
1494
+ * const store = createStore()
1495
+ * .setTables({
1496
+ * pets: {fido: {species: 'dog', sold: true}, felix: {species: 'cat'}},
1497
+ * })
1498
+ * .setSchema({
1499
+ * pets: {
1500
+ * species: {type: 'string'},
1501
+ * sold: {type: 'boolean', default: false},
1502
+ * },
1503
+ * });
1504
+ * store.delCell('pets', 'fido', 'sold', true);
1505
+ *
1506
+ * console.log(store.getTables());
1507
+ * // -> {pets: {felix: {species: 'cat', sold: false}}}
1508
+ * ```
1509
+ * @category Deleter
1510
+ */
1511
+ delCell(tableId: Id, rowId: Id, cellId: Id, forceDel?: boolean): Store;
1512
+
1513
+ /**
1514
+ * The delSchema method lets you remove the Schema of the Store.
1515
+ *
1516
+ * @returns A reference to the Store.
1517
+ * @example
1518
+ * This example removes the Schema of a Store.
1519
+ *
1520
+ * ```js
1521
+ * const store = createStore().setSchema({pets: {species: {type: 'string'}}});
1522
+ * store.delSchema();
1523
+ * console.log(store.getSchemaJson());
1524
+ * // -> '{}'
1525
+ * ```
1526
+ * @category Deleter
1527
+ */
1528
+ delSchema(): Store;
1529
+
1530
+ /**
1531
+ * The transaction method takes a function that makes multiple mutations to
1532
+ * the store, buffering all calls to the relevant listeners until it
1533
+ * completes.
1534
+ *
1535
+ * This method is useful for making bulk changes to the data in a Store, and
1536
+ * when you don't want listeners to be called as you make each change. Changes
1537
+ * are made silently during the transaction, and listeners relevant to the
1538
+ * changes you have made will instead only be called when the whole
1539
+ * transaction is complete.
1540
+ *
1541
+ * If multiple changes are made to a piece of Store data throughout the
1542
+ * transaction, a relevant listener will only be called with the final value
1543
+ * (assuming it is different to the value at the start of the transaction),
1544
+ * regardless of the changes that happened in between. For example, if a Cell
1545
+ * had a value `'b'` and then, within a transaction, it was changed to `'b'`
1546
+ * and then `'c'`, any CellListener registered for that cell would be called
1547
+ * once as if there had been a single change from `'a'` to `'c'`.
1548
+ *
1549
+ * Transactions can be nested. Relevant listeners will be called only when the
1550
+ * outermost one completes.
1551
+ *
1552
+ * @param actions The function to be executed as a transaction.
1553
+ * @returns Whatever value the provided transaction function returns.
1554
+ * @example
1555
+ * This example makes changes to two Cells, first outside, and secondly
1556
+ * within, a transaction. In the second case, the Row listener is only called
1557
+ * once.
1558
+ *
1559
+ * ```js
1560
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1561
+ * store.addRowListener('pets', 'fido', () => console.log('Fido changed'));
1562
+ *
1563
+ * store.setCell('pets', 'fido', 'color', 'brown');
1564
+ * store.setCell('pets', 'fido', 'sold', false);
1565
+ * // -> 'Fido changed'
1566
+ * // -> 'Fido changed'
1567
+ *
1568
+ * store.transaction(() => {
1569
+ * store.setCell('pets', 'fido', 'color', 'walnut');
1570
+ * store.setCell('pets', 'fido', 'sold', true);
1571
+ * });
1572
+ * // -> 'Fido changed'
1573
+ * ```
1574
+ * @example
1575
+ * This example makes multiple changes to one Cell. The Cell listener is
1576
+ * called once - and with the final value - only if there is a net overall
1577
+ * change.
1578
+ *
1579
+ * ```js
1580
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1581
+ * store.addCellListener(
1582
+ * 'pets',
1583
+ * 'fido',
1584
+ * 'color',
1585
+ * (store, tableId, rowId, cellId, newCell) => console.log(newCell),
1586
+ * );
1587
+ *
1588
+ * store.transaction(() => {
1589
+ * store.setCell('pets', 'fido', 'color', 'black');
1590
+ * store.setCell('pets', 'fido', 'color', 'brown');
1591
+ * store.setCell('pets', 'fido', 'color', 'walnut');
1592
+ * });
1593
+ * // -> 'walnut'
1594
+ *
1595
+ * store.transaction(() => {
1596
+ * store.setCell('pets', 'fido', 'color', 'black');
1597
+ * store.setCell('pets', 'fido', 'color', 'walnut');
1598
+ * });
1599
+ * // -> undefined
1600
+ * // No net change during the transaction, so the listener is not called.
1601
+ * ```
1602
+ * @category Setter
1603
+ */
1604
+ transaction<Return>(actions: () => Return): Return;
1605
+
1606
+ /**
1607
+ * The forEachTable method takes a function that it will then call for each
1608
+ * Table in the Store.
1609
+ *
1610
+ * This method is useful for iterating over the Table structure of the Store
1611
+ * in a functional style. The `tableCallback` parameter is a TableCallback
1612
+ * function that will called with the Id of each Table, and with a function
1613
+ * that can then be used to iterate over each Row of the Table, should you
1614
+ * wish.
1615
+ *
1616
+ * @param tableCallback The function that should be called for every Table.
1617
+ * @example
1618
+ * This example iterates over each Table in a Store, and lists each Row Id
1619
+ * within them.
1620
+ *
1621
+ * ```js
1622
+ * const store = createStore().setTables({
1623
+ * pets: {fido: {species: 'dog'}},
1624
+ * species: {dog: {price: 5}},
1625
+ * });
1626
+ * store.forEachTable((tableId, forEachRow) => {
1627
+ * console.log(tableId);
1628
+ * forEachRow((rowId) => console.log(`- ${rowId}`));
1629
+ * });
1630
+ * // -> 'pets'
1631
+ * // -> '- fido'
1632
+ * // -> 'species'
1633
+ * // -> '- dog'
1634
+ * ```
1635
+ * @category Iterator
1636
+ */
1637
+ forEachTable(tableCallback: TableCallback): void;
1638
+
1639
+ /**
1640
+ * The forEachRow method takes a function that it will then call for each Row
1641
+ * in a specified Table.
1642
+ *
1643
+ * This method is useful for iterating over the Row structure of the Table in
1644
+ * a functional style. The `rowCallback` parameter is a RowCallback function
1645
+ * that will called with the Id of each Row, and with a function that can then
1646
+ * be used to iterate over each Cell of the Row, should you wish.
1647
+ *
1648
+ * @param rowCallback The function that should be called for every Row.
1649
+ * @example
1650
+ * This example iterates over each Row in a Table, and lists each Cell Id
1651
+ * within them.
1652
+ *
1653
+ * ```js
1654
+ * const store = createStore().setTables({
1655
+ * pets: {
1656
+ * fido: {species: 'dog'},
1657
+ * felix: {color: 'black'},
1658
+ * },
1659
+ * });
1660
+ * store.forEachRow('pets', (rowId, forEachCell) => {
1661
+ * console.log(rowId);
1662
+ * forEachCell((cellId) => console.log(`- ${cellId}`));
1663
+ * });
1664
+ * // -> 'fido'
1665
+ * // -> '- species'
1666
+ * // -> 'felix'
1667
+ * // -> '- color'
1668
+ * ```
1669
+ * @category Iterator
1670
+ */
1671
+ forEachRow(tableId: Id, rowCallback: RowCallback): void;
1672
+
1673
+ /**
1674
+ * The forEachCell method takes a function that it will then call for each
1675
+ * Cell in a specified Row.
1676
+ *
1677
+ * This method is useful for iterating over the Cell structure of the Row in a
1678
+ * functional style. The `cellCallback` parameter is a CellCallback function
1679
+ * that will called with the Id and value of each Cell.
1680
+ *
1681
+ * @param cellCallback The function that should be called for every Cell.
1682
+ * @example
1683
+ * This example iterates over each Cell in a Row, and lists its value.
1684
+ *
1685
+ * ```js
1686
+ * const store = createStore().setTables({
1687
+ * pets: {fido: {species: 'dog', color: 'brown'}},
1688
+ * });
1689
+ * store.forEachCell('pets', 'fido', (cellId, cell) => {
1690
+ * console.log(`${cellId}: ${cell}`);
1691
+ * });
1692
+ * // -> 'species: dog'
1693
+ * // -> 'color: brown'
1694
+ * ```
1695
+ * @category Iterator
1696
+ */
1697
+ forEachCell(tableId: Id, rowId: Id, cellCallback: CellCallback): void;
1698
+
1699
+ /**
1700
+ * The addTablesListener method registers a listener function with the Store
1701
+ * that will be called whenever data in the Store changes.
1702
+ *
1703
+ * The provided listener is a TablesListener function, and will be called with
1704
+ * a reference to the Store and a GetCellChange function in case you need to
1705
+ * inspect any changes that occurred.
1706
+ *
1707
+ * Use the optional mutator parameter to indicate that there is code in the
1708
+ * listener that will mutate Store data. If set to `false` (or omitted), such
1709
+ * mutations will be silently ignored. All relevant mutator listeners (with
1710
+ * this flag set to `true`) are called _before_ any non-mutator listeners
1711
+ * (since the latter may become relevant due to changes made in the former).
1712
+ * The changes made by mutator listeners do not fire other mutating listeners,
1713
+ * though they will fire non-mutator listeners.
1714
+ *
1715
+ * @param listener The function that will be called whenever data in the Store
1716
+ * changes.
1717
+ * @param mutator An optional boolean that indicates that the listener mutates
1718
+ * Store data.
1719
+ * @returns A unique Id for the listener that can later be used to call it
1720
+ * explicitly, or to remove it.
1721
+ * @example
1722
+ * This example registers a listener that responds to any changes to the whole
1723
+ * Store.
1724
+ *
1725
+ * ```js
1726
+ * const store = createStore().setTables({
1727
+ * pets: {fido: {species: 'dog', color: 'brown'}},
1728
+ * });
1729
+ * const listenerId = store.addTablesListener((store, getCellChange) => {
1730
+ * console.log('Tables changed');
1731
+ * console.log(getCellChange('pets', 'fido', 'color'));
1732
+ * });
1733
+ *
1734
+ * store.setCell('pets', 'fido', 'color', 'walnut');
1735
+ * // -> 'Tables changed'
1736
+ * // -> [true, 'brown', 'walnut']
1737
+ *
1738
+ * store.delListener(listenerId);
1739
+ * ```
1740
+ * @example
1741
+ * This example registers a listener that responds to any changes to the whole
1742
+ * Store, and which also mutates the Store itself.
1743
+ *
1744
+ * ```js
1745
+ * const store = createStore().setTables({
1746
+ * pets: {fido: {species: 'dog', color: 'brown'}},
1747
+ * });
1748
+ * const listenerId = store.addTablesListener(
1749
+ * (store) => store.setCell('meta', 'update', 'store', true),
1750
+ * true,
1751
+ * );
1752
+ *
1753
+ * store.delCell('pets', 'fido', 'color');
1754
+ * console.log(store.getTable('meta'));
1755
+ * // -> {update: {store: true}}
1756
+ *
1757
+ * store.delListener(listenerId);
1758
+ * ```
1759
+ * @category Listener
1760
+ */
1761
+ addTablesListener(listener: TablesListener, mutator?: boolean): Id;
1762
+
1763
+ /**
1764
+ * The addTableIdsListener method registers a listener function with the Store
1765
+ * that will be called whenever the Table Ids in the Store change.
1766
+ *
1767
+ * Such a listener is only called when a Table is added or removed. To listen
1768
+ * to all changes in the Store, use the addTablesListener method.
1769
+ *
1770
+ * The provided listener is a TableIdsListener function, and will be called
1771
+ * with a reference to the Store.
1772
+ *
1773
+ * Use the optional mutator parameter to indicate that there is code in the
1774
+ * listener that will mutate Store data. If set to `false` (or omitted), such
1775
+ * mutations will be silently ignored. All relevant mutator listeners (with
1776
+ * this flag set to `true`) are called _before_ any non-mutator listeners
1777
+ * (since the latter may become relevant due to changes made in the former).
1778
+ * The changes made by mutator listeners do not fire other mutating listeners,
1779
+ * though they will fire non-mutator listeners.
1780
+ *
1781
+ * @param listener The function that will be called whenever the Table Ids in
1782
+ * the Store change.
1783
+ * @param mutator An optional boolean that indicates that the listener mutates
1784
+ * Store data.
1785
+ * @returns A unique Id for the listener that can later be used to call it
1786
+ * explicitly, or to remove it.
1787
+ * @example
1788
+ * This example registers a listener that responds to any change to the Table
1789
+ * Ids.
1790
+ *
1791
+ * ```js
1792
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1793
+ * const listenerId = store.addTableIdsListener((store) => {
1794
+ * console.log('Table Ids changed');
1795
+ * console.log(store.getTableIds());
1796
+ * });
1797
+ *
1798
+ * store.setTable('species', {dog: {price: 5}});
1799
+ * // -> 'Table Ids changed'
1800
+ * // -> ['pets', 'species']
1801
+ *
1802
+ * store.delListener(listenerId);
1803
+ * ```
1804
+ * @example
1805
+ * This example registers a listener that responds to any change to the Table
1806
+ * Ids, and which also mutates the Store itself.
1807
+ *
1808
+ * ```js
1809
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1810
+ * const listenerId = store.addTableIdsListener(
1811
+ * (store) => store.setCell('meta', 'update', 'store', true),
1812
+ * true,
1813
+ * );
1814
+ *
1815
+ * store.setTable('species', {dog: {price: 5}});
1816
+ * console.log(store.getTable('meta'));
1817
+ * // -> {update: {store: true}}
1818
+ *
1819
+ * store.delListener(listenerId);
1820
+ * ```
1821
+ * @category Listener
1822
+ */
1823
+ addTableIdsListener(listener: TableIdsListener, mutator?: boolean): Id;
1824
+
1825
+ /**
1826
+ * The addTableListener method registers a listener function with the Store
1827
+ * that will be called whenever data in a Table changes.
1828
+ *
1829
+ * You can either listen to a single Table (by specifying its Id as the
1830
+ * method's first parameter) or changes to any Table (by providing a `null`
1831
+ * wildcard).
1832
+ *
1833
+ * The provided listener is a TableListener function, and will be called with
1834
+ * a reference to the Store, the Id of the Table that changed, and a
1835
+ * GetCellChange function in case you need to inspect any changes that
1836
+ * occurred.
1837
+ *
1838
+ * Use the optional mutator parameter to indicate that there is code in the
1839
+ * listener that will mutate Store data. If set to `false` (or omitted), such
1840
+ * mutations will be silently ignored. All relevant mutator listeners (with
1841
+ * this flag set to `true`) are called _before_ any non-mutator listeners
1842
+ * (since the latter may become relevant due to changes made in the former).
1843
+ * The changes made by mutator listeners do not fire other mutating listeners,
1844
+ * though they will fire non-mutator listeners.
1845
+ *
1846
+ * @param tableId The Id of the Table to listen to, or `null` as a wildcard.
1847
+ * @param listener The function that will be called whenever data in the
1848
+ * matching Table changes.
1849
+ * @param mutator An optional boolean that indicates that the listener mutates
1850
+ * Store data.
1851
+ * @returns A unique Id for the listener that can later be used to call it
1852
+ * explicitly, or to remove it.
1853
+ * @example
1854
+ * This example registers a listener that responds to any changes to a
1855
+ * specific Table.
1856
+ *
1857
+ * ```js
1858
+ * const store = createStore().setTables({
1859
+ * pets: {fido: {species: 'dog', color: 'brown'}},
1860
+ * });
1861
+ * const listenerId = store.addTableListener(
1862
+ * 'pets',
1863
+ * (store, tableId, getCellChange) => {
1864
+ * console.log('pets table changed');
1865
+ * console.log(getCellChange('pets', 'fido', 'color'));
1866
+ * },
1867
+ * );
1868
+ *
1869
+ * store.setCell('pets', 'fido', 'color', 'walnut');
1870
+ * // -> 'pets table changed'
1871
+ * // -> [true, 'brown', 'walnut']
1872
+ *
1873
+ * store.delListener(listenerId);
1874
+ * ```
1875
+ * @example
1876
+ * This example registers a listener that responds to any changes to any
1877
+ * Table.
1878
+ *
1879
+ * ```js
1880
+ * const store = createStore().setTables({
1881
+ * pets: {fido: {species: 'dog', color: 'brown'}},
1882
+ * });
1883
+ * const listenerId = store.addTableListener(null, (store, tableId) => {
1884
+ * console.log(`${tableId} table changed`);
1885
+ * });
1886
+ *
1887
+ * store.setCell('pets', 'fido', 'color', 'walnut');
1888
+ * // -> 'pets table changed'
1889
+ * store.setTable('species', {dog: {price: 5}});
1890
+ * // -> 'species table changed'
1891
+ *
1892
+ * store.delListener(listenerId);
1893
+ * ```
1894
+ * @example
1895
+ * This example registers a listener that responds to any changes to a
1896
+ * specific Table, and which also mutates the Store itself.
1897
+ *
1898
+ * ```js
1899
+ * const store = createStore().setTables({
1900
+ * pets: {fido: {species: 'dog', color: 'brown'}},
1901
+ * });
1902
+ * const listenerId = store.addTableListener(
1903
+ * 'pets',
1904
+ * (store, tableId) => store.setCell('meta', 'update', tableId, true),
1905
+ * true,
1906
+ * );
1907
+ *
1908
+ * store.delCell('pets', 'fido', 'color');
1909
+ * console.log(store.getTable('meta'));
1910
+ * // -> {update: {pets: true}}
1911
+ *
1912
+ * store.delListener(listenerId);
1913
+ * ```
1914
+ * @category Listener
1915
+ */
1916
+ addTableListener(
1917
+ tableId: IdOrNull,
1918
+ listener: TableListener,
1919
+ mutator?: boolean,
1920
+ ): Id;
1921
+
1922
+ /**
1923
+ * The addRowIdsListener method registers a listener function with the Store
1924
+ * that will be called whenever the Row Ids in a Table change.
1925
+ *
1926
+ * Such a listener is only called when a Row is added or removed. To listen to
1927
+ * all changes in the Table, use the addTableListener method.
1928
+ *
1929
+ * You can either listen to a single Table (by specifying its Id as the
1930
+ * method's first parameter) or changes to any Table (by providing `null`).
1931
+ *
1932
+ * The provided listener is a RowIdsListener function, and will be called with
1933
+ * a reference to the Store and the Id of the Table that changed.
1934
+ *
1935
+ * Use the optional mutator parameter to indicate that there is code in the
1936
+ * listener that will mutate Store data. If set to `false` (or omitted), such
1937
+ * mutations will be silently ignored. All relevant mutator listeners (with
1938
+ * this flag set to `true`) are called _before_ any non-mutator listeners
1939
+ * (since the latter may become relevant due to changes made in the former).
1940
+ * The changes made by mutator listeners do not fire other mutating listeners,
1941
+ * though they will fire non-mutator listeners.
1942
+ *
1943
+ * @param tableId The Id of the Table to listen to, or `null` as a wildcard.
1944
+ * @param listener The function that will be called whenever the Row Ids in
1945
+ * the Table change.
1946
+ * @param mutator An optional boolean that indicates that the listener mutates
1947
+ * Store data.
1948
+ * @returns A unique Id for the listener that can later be used to call it
1949
+ * explicitly, or to remove it.
1950
+ * @example
1951
+ * This example registers a listener that responds to any change to the Row
1952
+ * Ids of a specific Table.
1953
+ *
1954
+ * ```js
1955
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1956
+ * const listenerId = store.addRowIdsListener('pets', (store) => {
1957
+ * console.log('Row Ids for pets table changed');
1958
+ * console.log(store.getRowIds('pets'));
1959
+ * });
1960
+ *
1961
+ * store.setRow('pets', 'felix', {species: 'cat'});
1962
+ * // -> 'Row Ids for pets table changed'
1963
+ * // -> ['fido', 'felix']
1964
+ *
1965
+ * store.delListener(listenerId);
1966
+ * ```
1967
+ * @example
1968
+ * This example registers a listener that responds to any change to the Row
1969
+ * Ids of any Table.
1970
+ *
1971
+ * ```js
1972
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1973
+ * const listenerId = store.addRowIdsListener(null, (store, tableId) => {
1974
+ * console.log(`Row Ids for ${tableId} table changed`);
1975
+ * console.log(store.getRowIds(tableId));
1976
+ * });
1977
+ *
1978
+ * store.setRow('pets', 'felix', {species: 'cat'});
1979
+ * // -> 'Row Ids for pets table changed'
1980
+ * // -> ['fido', 'felix']
1981
+ * store.setRow('species', 'dog', {price: 5});
1982
+ * // -> 'Row Ids for species table changed'
1983
+ * // -> ['dog']
1984
+ *
1985
+ * store.delListener(listenerId);
1986
+ * ```
1987
+ * @example
1988
+ * This example registers a listener that responds to any change to the Row
1989
+ * Ids of a specific Table, and which also mutates the Store itself.
1990
+ *
1991
+ * ```js
1992
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1993
+ * const listenerId = store.addRowIdsListener(
1994
+ * 'pets',
1995
+ * (store, tableId) => store.setCell('meta', 'update', tableId, true),
1996
+ * true,
1997
+ * );
1998
+ *
1999
+ * store.setRow('pets', 'felix', {species: 'cat'});
2000
+ * console.log(store.getTable('meta'));
2001
+ * // -> {update: {pets: true}}
2002
+ *
2003
+ * store.delListener(listenerId);
2004
+ * ```
2005
+ * @category Listener
2006
+ */
2007
+ addRowIdsListener(
2008
+ tableId: IdOrNull,
2009
+ listener: RowIdsListener,
2010
+ mutator?: boolean,
2011
+ ): Id;
2012
+
2013
+ /**
2014
+ * The addRowListener method registers a listener function with the Store that
2015
+ * will be called whenever data in a Row changes.
2016
+ *
2017
+ * You can either listen to a single Row (by specifying the Table Id and Row
2018
+ * Id as the method's first two parameters) or changes to any Row (by
2019
+ * providing `null` wildcards).
2020
+ *
2021
+ * Both, either, or neither of the `tableId` and `rowId` parameters can be
2022
+ * wildcarded with `null`. You can listen to a specific Row in a specific
2023
+ * Table, any Row in a specific Table, a specific Row in any Table, or any Row
2024
+ * in any Table.
2025
+ *
2026
+ * The provided listener is a RowListener function, and will be called with a
2027
+ * reference to the Store, the Id of the Table that changed, the Id of the Row
2028
+ * that changed, and a GetCellChange function in case you need to inspect any
2029
+ * changes that occurred.
2030
+ *
2031
+ * Use the optional mutator parameter to indicate that there is code in the
2032
+ * listener that will mutate Store data. If set to `false` (or omitted), such
2033
+ * mutations will be silently ignored. All relevant mutator listeners (with
2034
+ * this flag set to `true`) are called _before_ any non-mutator listeners
2035
+ * (since the latter may become relevant due to changes made in the former).
2036
+ * The changes made by mutator listeners do not fire other mutating listeners,
2037
+ * though they will fire non-mutator listeners.
2038
+ *
2039
+ * @param tableId The Id of the Table to listen to, or `null` as a wildcard.
2040
+ * @param rowId The Id of the Row to listen to, or `null` as a wildcard.
2041
+ * @param listener The function that will be called whenever data in the
2042
+ * matching Row changes.
2043
+ * @param mutator An optional boolean that indicates that the listener mutates
2044
+ * Store data.
2045
+ * @returns A unique Id for the listener that can later be used to call it
2046
+ * explicitly, or to remove it.
2047
+ * @example
2048
+ * This example registers a listener that responds to any changes to a
2049
+ * specific Row.
2050
+ *
2051
+ * ```js
2052
+ * const store = createStore().setTables({
2053
+ * pets: {fido: {species: 'dog', color: 'brown'}},
2054
+ * });
2055
+ * const listenerId = store.addRowListener(
2056
+ * 'pets',
2057
+ * 'fido',
2058
+ * (store, tableId, rowId, getCellChange) => {
2059
+ * console.log('fido row in pets table changed');
2060
+ * console.log(getCellChange('pets', 'fido', 'color'));
2061
+ * },
2062
+ * );
2063
+ *
2064
+ * store.setCell('pets', 'fido', 'color', 'walnut');
2065
+ * // -> 'fido row in pets table changed'
2066
+ * // -> [true, 'brown', 'walnut']
2067
+ *
2068
+ * store.delListener(listenerId);
2069
+ * ```
2070
+ * @example
2071
+ * This example registers a listener that responds to any changes to any Row.
2072
+ *
2073
+ * ```js
2074
+ * const store = createStore().setTables({
2075
+ * pets: {fido: {species: 'dog', color: 'brown'}},
2076
+ * });
2077
+ * const listenerId = store.addRowListener(
2078
+ * null,
2079
+ * null,
2080
+ * (store, tableId, rowId) => {
2081
+ * console.log(`${rowId} row in ${tableId} table changed`);
2082
+ * },
2083
+ * );
2084
+ *
2085
+ * store.setCell('pets', 'fido', 'color', 'walnut');
2086
+ * // -> 'fido row in pets table changed'
2087
+ * store.setTable('species', {dog: {price: 5}});
2088
+ * // -> 'dog row in species table changed'
2089
+ *
2090
+ * store.delListener(listenerId);
2091
+ * ```
2092
+ * @example
2093
+ * This example registers a listener that responds to any changes to a
2094
+ * specific Row, and which also mutates the Store itself.
2095
+ *
2096
+ * ```js
2097
+ * const store = createStore().setTables({
2098
+ * pets: {fido: {species: 'dog', color: 'brown'}},
2099
+ * });
2100
+ * const listenerId = store.addRowListener(
2101
+ * 'pets',
2102
+ * 'fido',
2103
+ * (store, tableId, rowId) =>
2104
+ * store.setCell('meta', 'update', `${tableId}_${rowId}`, true),
2105
+ * true,
2106
+ * );
2107
+ *
2108
+ * store.delCell('pets', 'fido', 'color');
2109
+ * console.log(store.getTable('meta'));
2110
+ * // -> {update: {pets_fido: true}}
2111
+ *
2112
+ * store.delListener(listenerId);
2113
+ * ```
2114
+ * @category Listener
2115
+ */
2116
+ addRowListener(
2117
+ tableId: IdOrNull,
2118
+ rowId: IdOrNull,
2119
+ listener: RowListener,
2120
+ mutator?: boolean,
2121
+ ): Id;
2122
+
2123
+ /**
2124
+ * The addCellIdsListener method registers a listener function with the Store
2125
+ * that will be called whenever the Cell Ids in a Row change.
2126
+ *
2127
+ * Such a listener is only called when a Cell is added or removed. To listen
2128
+ * to all changes in the Row, use the addRowListener method.
2129
+ *
2130
+ * You can either listen to a single Row (by specifying the Table Id and Row
2131
+ * Id as the method's first two parameters) or changes to any Row (by
2132
+ * providing `null`).
2133
+ *
2134
+ * Both, either, or neither of the `tableId` and `rowId` parameters can be
2135
+ * wildcarded with `null`. You can listen to a specific Row in a specific
2136
+ * Table, any Row in a specific Table, a specific Row in any Table, or any Row
2137
+ * in any Table.
2138
+ *
2139
+ * The provided listener is a CellIdsListener function, and will be called
2140
+ * with a reference to the Store, the Id of the Table, and the Id of the Row
2141
+ * that changed.
2142
+ *
2143
+ * Use the optional mutator parameter to indicate that there is code in the
2144
+ * listener that will mutate Store data. If set to `false` (or omitted), such
2145
+ * mutations will be silently ignored. All relevant mutator listeners (with
2146
+ * this flag set to `true`) are called _before_ any non-mutator listeners
2147
+ * (since the latter may become relevant due to changes made in the former).
2148
+ * The changes made by mutator listeners do not fire other mutating listeners,
2149
+ * though they will fire non-mutator listeners.
2150
+ *
2151
+ * @param tableId The Id of the Table to listen to, or `null` as a wildcard.
2152
+ * @param rowId The Id of the Row to listen to, or `null` as a wildcard.
2153
+ * @param listener The function that will be called whenever the Cell Ids in
2154
+ * the Row change.
2155
+ * @param mutator An optional boolean that indicates that the listener mutates
2156
+ * Store data.
2157
+ * @returns A unique Id for the listener that can later be used to call it
2158
+ * explicitly, or to remove it.
2159
+ * @example
2160
+ * This example registers a listener that responds to any change to the Cell
2161
+ * Ids of a specific Row.
2162
+ *
2163
+ * ```js
2164
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
2165
+ * const listenerId = store.addCellIdsListener('pets', 'fido', (store) => {
2166
+ * console.log('Cell Ids for fido row in pets table changed');
2167
+ * console.log(store.getCellIds('pets', 'fido'));
2168
+ * });
2169
+ *
2170
+ * store.setCell('pets', 'fido', 'color', 'brown');
2171
+ * // -> 'Cell Ids for fido row in pets table changed'
2172
+ * // -> ['species', 'color']
2173
+ *
2174
+ * store.delListener(listenerId);
2175
+ * ```
2176
+ * @example
2177
+ * This example registers a listener that responds to any change to the Cell
2178
+ * Ids of any Row.
2179
+ *
2180
+ * ```js
2181
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
2182
+ * const listenerId = store.addCellIdsListener(
2183
+ * null,
2184
+ * null,
2185
+ * (store, tableId, rowId) => {
2186
+ * console.log(`Cell Ids for ${rowId} row in ${tableId} table changed`);
2187
+ * console.log(store.getCellIds(tableId, rowId));
2188
+ * },
2189
+ * );
2190
+ *
2191
+ * store.setCell('pets', 'fido', 'color', 'brown');
2192
+ * // -> 'Cell Ids for fido row in pets table changed'
2193
+ * // -> ['species', 'color']
2194
+ * store.setCell('species', 'dog', 'price', 5);
2195
+ * // -> 'Cell Ids for dog row in species table changed'
2196
+ * // -> ['price']
2197
+ *
2198
+ * store.delListener(listenerId);
2199
+ * ```
2200
+ * @example
2201
+ * This example registers a listener that responds to any change to the Cell
2202
+ * Ids of a specific Row, and which also mutates the Store itself.
2203
+ *
2204
+ * ```js
2205
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
2206
+ * const listenerId = store.addCellIdsListener(
2207
+ * 'pets',
2208
+ * 'fido',
2209
+ * (store, tableId, rowId) =>
2210
+ * store.setCell('meta', 'update', `${tableId}_${rowId}`, true),
2211
+ * true,
2212
+ * );
2213
+ *
2214
+ * store.setCell('pets', 'fido', 'color', 'brown');
2215
+ * console.log(store.getTable('meta'));
2216
+ * // -> {update: {pets_fido: true}}
2217
+ *
2218
+ * store.delListener(listenerId);
2219
+ * ```
2220
+ * @category Listener
2221
+ */
2222
+ addCellIdsListener(
2223
+ tableId: IdOrNull,
2224
+ rowId: IdOrNull,
2225
+ listener: CellIdsListener,
2226
+ mutator?: boolean,
2227
+ ): Id;
2228
+
2229
+ /**
2230
+ * The addCellListener method registers a listener function with the Store
2231
+ * that will be called whenever data in a Cell changes.
2232
+ *
2233
+ * You can either listen to a single Cell (by specifying the Table Id, Row Id,
2234
+ * and Cell Id as the method's first three parameters) or changes to any Cell
2235
+ * (by providing `null` wildcards).
2236
+ *
2237
+ * All, some, or none of the `tableId`, `rowId`, and `cellId` parameters can
2238
+ * be wildcarded with `null`. You can listen to a specific Cell in a specific
2239
+ * Row in a specific Table, any Cell in any Row in any Table, for example - or
2240
+ * every other combination of wildcards.
2241
+ *
2242
+ * The provided listener is a CellListener function, and will be called with a
2243
+ * reference to the Store, the Id of the Table that changed, the Id of the Row
2244
+ * that changed, the Id of the Cell that changed, the new Cell value, the old
2245
+ * Cell value, and a GetCellChange function in case you need to inspect any
2246
+ * changes that occurred.
2247
+ *
2248
+ * Use the optional mutator parameter to indicate that there is code in the
2249
+ * listener that will mutate Store data. If set to `false` (or omitted), such
2250
+ * mutations will be silently ignored. All relevant mutator listeners (with
2251
+ * this flag set to `true`) are called _before_ any non-mutator listeners
2252
+ * (since the latter may become relevant due to changes made in the former).
2253
+ * The changes made by mutator listeners do not fire other mutating listeners,
2254
+ * though they will fire non-mutator listeners.
2255
+ *
2256
+ * @param tableId The Id of the Table to listen to, or `null` as a wildcard.
2257
+ * @param rowId The Id of the Row to listen to, or `null` as a wildcard.
2258
+ * @param cellId The Id of the Cell to listen to, or `null` as a wildcard.
2259
+ * @param listener The function that will be called whenever data in the
2260
+ * matching Cell changes.
2261
+ * @param mutator An optional boolean that indicates that the listener mutates
2262
+ * Store data.
2263
+ * @returns A unique Id for the listener that can later be used to call it
2264
+ * explicitly, or to remove it.
2265
+ * @example
2266
+ * This example registers a listener that responds to any changes to a
2267
+ * specific Cell.
2268
+ *
2269
+ * ```js
2270
+ * const store = createStore().setTables({
2271
+ * pets: {fido: {species: 'dog', color: 'brown'}},
2272
+ * });
2273
+ * const listenerId = store.addCellListener(
2274
+ * 'pets',
2275
+ * 'fido',
2276
+ * 'color',
2277
+ * (store, tableId, rowId, cellId, newCell, oldCell, getCellChange) => {
2278
+ * console.log('color cell in fido row in pets table changed');
2279
+ * console.log([oldCell, newCell]);
2280
+ * console.log(getCellChange('pets', 'fido', 'color'));
2281
+ * },
2282
+ * );
2283
+ *
2284
+ * store.setCell('pets', 'fido', 'color', 'walnut');
2285
+ * // -> 'color cell in fido row in pets table changed'
2286
+ * // -> ['brown', 'walnut']
2287
+ * // -> [true, 'brown', 'walnut']
2288
+ *
2289
+ * store.delListener(listenerId);
2290
+ * ```
2291
+ * @example
2292
+ * This example registers a listener that responds to any changes to any Cell.
2293
+ *
2294
+ * ```js
2295
+ * const store = createStore().setTables({
2296
+ * pets: {fido: {species: 'dog', color: 'brown'}},
2297
+ * });
2298
+ * const listenerId = store.addCellListener(
2299
+ * null,
2300
+ * null,
2301
+ * null,
2302
+ * (store, tableId, rowId, cellId) => {
2303
+ * console.log(
2304
+ * `${cellId} cell in ${rowId} row in ${tableId} table changed`,
2305
+ * );
2306
+ * },
2307
+ * );
2308
+ *
2309
+ * store.setCell('pets', 'fido', 'color', 'walnut');
2310
+ * // -> 'color cell in fido row in pets table changed'
2311
+ * store.setTable('species', {dog: {price: 5}});
2312
+ * // -> 'price cell in dog row in species table changed'
2313
+ *
2314
+ * store.delListener(listenerId);
2315
+ * ```
2316
+ * @example
2317
+ * This example registers a listener that responds to any changes to a
2318
+ * specific Cell, and which also mutates the Store itself.
2319
+ *
2320
+ * ```js
2321
+ * const store = createStore().setTables({
2322
+ * pets: {fido: {species: 'dog', color: 'brown'}},
2323
+ * });
2324
+ * const listenerId = store.addCellListener(
2325
+ * 'pets',
2326
+ * 'fido',
2327
+ * 'color',
2328
+ * (store, tableId, rowId, cellId) =>
2329
+ * store.setCell('meta', 'update', `${tableId}_${rowId}_${cellId}`, true),
2330
+ * true,
2331
+ * );
2332
+ *
2333
+ * store.delCell('pets', 'fido', 'color');
2334
+ * console.log(store.getTable('meta'));
2335
+ * // -> {update: {pets_fido_color: true}}
2336
+ *
2337
+ * store.delListener(listenerId);
2338
+ * ```
2339
+ * @category Listener
2340
+ */
2341
+ addCellListener(
2342
+ tableId: IdOrNull,
2343
+ rowId: IdOrNull,
2344
+ cellId: IdOrNull,
2345
+ listener: CellListener,
2346
+ mutator?: boolean,
2347
+ ): Id;
2348
+
2349
+ /**
2350
+ * The callListener method provides a way for you to manually provoke a
2351
+ * listener to be called, even if the underlying data hasn't changed.
2352
+ *
2353
+ * This is useful when you are using mutator listeners to guarantee that data
2354
+ * conforms to programmatic conditions, and those conditions change such that
2355
+ * you need to update the Store in bulk.
2356
+ *
2357
+ * @param listenerId The Id of the listener to call.
2358
+ * @returns A reference to the Store.
2359
+ * @example
2360
+ * This example registers a listener that ensures a Cell has one of list of a
2361
+ * valid values. After that list changes, the listener is called to apply the
2362
+ * condition to the existing data.
2363
+ *
2364
+ * ```js
2365
+ * const validColors = ['walnut', 'brown', 'black'];
2366
+ * const store = createStore();
2367
+ * const listenerId = store.addCellListener(
2368
+ * 'pets',
2369
+ * null,
2370
+ * 'color',
2371
+ * (store, tableId, rowId, cellId, color) => {
2372
+ * if (!validColors.includes(color)) {
2373
+ * store.setCell(tableId, rowId, cellId, validColors[0]);
2374
+ * }
2375
+ * },
2376
+ * true,
2377
+ * );
2378
+ *
2379
+ * store.setRow('pets', 'fido', {species: 'dog', color: 'honey'});
2380
+ * console.log(store.getRow('pets', 'fido'));
2381
+ * // -> {species: 'dog', color: 'walnut'}
2382
+ *
2383
+ * validColors.shift();
2384
+ * console.log(validColors);
2385
+ * // -> ['brown', 'black']
2386
+ *
2387
+ * store.callListener(listenerId);
2388
+ * console.log(store.getRow('pets', 'fido'));
2389
+ * // -> {species: 'dog', color: 'brown'}
2390
+ *
2391
+ * store.delListener(listenerId);
2392
+ * ```
2393
+ * @category Listener
2394
+ */
2395
+ callListener(listenerId: Id): Store;
2396
+
2397
+ /**
2398
+ * The delListener method removes a listener that was previously added to the
2399
+ * Store.
2400
+ *
2401
+ * Use the Id returned by whichever method was used to add the listener. Note
2402
+ * that the Store may re-use this Id for future listeners added to it.
2403
+ *
2404
+ * @param listenerId The Id of the listener to remove.
2405
+ * @returns A reference to the Store.
2406
+ * @example
2407
+ * This example registers a listener and then removes it.
2408
+ *
2409
+ * ```js
2410
+ * const store = createStore().setTables({
2411
+ * pets: {fido: {species: 'dog', color: 'brown'}},
2412
+ * });
2413
+ * const listenerId = store.addTablesListener(() => {
2414
+ * console.log('Tables changed');
2415
+ * });
2416
+ *
2417
+ * store.setCell('pets', 'fido', 'color', 'walnut');
2418
+ * // -> 'Tables changed'
2419
+ *
2420
+ * store.delListener(listenerId);
2421
+ *
2422
+ * store.setCell('pets', 'fido', 'color', 'honey');
2423
+ * // -> undefined
2424
+ * // The listener is not called.
2425
+ * ```
2426
+ * @category Listener
2427
+ */
2428
+ delListener(listenerId: Id): Store;
2429
+
2430
+ /**
2431
+ * The getListenerStats method provides a set of statistics about the
2432
+ * listeners registered with the Store, and is used for debugging purposes.
2433
+ *
2434
+ * The StoreListenerStats object contains a breakdown of the different types
2435
+ * of listener. Totals include both mutator and non-mutator listeners.
2436
+ *
2437
+ * The statistics are only populated in a debug build: production builds
2438
+ * return an empty object. The method is intended to be used during
2439
+ * development to ensure your application is not leaking listener
2440
+ * registrations, for example.
2441
+ *
2442
+ * @returns A StoreListenerStats object containing Store listener statistics.
2443
+ * @example
2444
+ * This example gets the listener statistics of a small and simple Store.
2445
+ *
2446
+ * ```js
2447
+ * const store = createStore();
2448
+ * store.addTablesListener(() => console.log('Tables changed'));
2449
+ * store.addRowIdsListener(() => console.log('Row Ids changed'));
2450
+ *
2451
+ * const listenerStats = store.getListenerStats();
2452
+ * console.log(listenerStats.rowIds);
2453
+ * // -> 1
2454
+ * console.log(listenerStats.tables);
2455
+ * // -> 1
2456
+ * ```
2457
+ * @category Development
2458
+ */
2459
+ getListenerStats(): StoreListenerStats;
2460
+ }
2461
+
2462
+ /**
2463
+ * The createStore function creates a Store, and is the main entry point into
2464
+ * the store module.
2465
+ *
2466
+ * Since (or perhaps _because_) it is the most important function in the whole
2467
+ * module, it is trivially simple.
2468
+ *
2469
+ * @returns A reference to the new Store.
2470
+ * @example
2471
+ * This example creates a Store.
2472
+ *
2473
+ * ```js
2474
+ * const store = createStore();
2475
+ * console.log(store.getTables());
2476
+ * // -> {}
2477
+ * ```
2478
+ * @example
2479
+ * This example creates a Store with some initial data:
2480
+ *
2481
+ * ```js
2482
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
2483
+ * console.log(store.getTables());
2484
+ * // -> {pets: {fido: {species: 'dog'}}}
2485
+ * ```
2486
+ * @example
2487
+ * This example creates a Store with some initial data and a Schema:
2488
+ *
2489
+ * ```js
2490
+ * const store = createStore()
2491
+ * .setTables({pets: {fido: {species: 'dog'}}})
2492
+ * .setSchema({
2493
+ * pets: {
2494
+ * species: {type: 'string'},
2495
+ * sold: {type: 'boolean', default: false},
2496
+ * },
2497
+ * });
2498
+ * console.log(store.getTables());
2499
+ * // -> {pets: {fido: {species: 'dog', sold: false}}}
2500
+ * ```
2501
+ * @category Creation
2502
+ */
2503
+ export function createStore(): Store;