tinybase 0.0.0 → 0.9.0

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