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