tinybase 2.2.6 → 3.0.0-beta.1

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 (110) hide show
  1. package/bin/cli.js +1 -1
  2. package/lib/checkpoints.d.ts +18 -3
  3. package/lib/checkpoints.js +1 -1
  4. package/lib/checkpoints.js.gz +0 -0
  5. package/lib/debug/checkpoints.d.ts +18 -3
  6. package/lib/debug/checkpoints.js +97 -49
  7. package/lib/debug/indexes.js +31 -16
  8. package/lib/debug/metrics.js +31 -16
  9. package/lib/debug/persisters.d.ts +33 -23
  10. package/lib/debug/persisters.js +10 -5
  11. package/lib/debug/queries.js +2 -2
  12. package/lib/debug/relationships.js +31 -16
  13. package/lib/debug/store.d.ts +2022 -383
  14. package/lib/debug/store.js +440 -108
  15. package/lib/debug/tinybase.js +508 -140
  16. package/lib/debug/tools.d.ts +89 -38
  17. package/lib/debug/tools.js +757 -453
  18. package/lib/debug/ui-react.d.ts +1525 -381
  19. package/lib/debug/ui-react.js +163 -12
  20. package/lib/es6/checkpoints.d.ts +18 -3
  21. package/lib/es6/checkpoints.js +1 -1
  22. package/lib/es6/checkpoints.js.gz +0 -0
  23. package/lib/es6/indexes.js +1 -1
  24. package/lib/es6/indexes.js.gz +0 -0
  25. package/lib/es6/metrics.js +1 -1
  26. package/lib/es6/metrics.js.gz +0 -0
  27. package/lib/es6/persisters.d.ts +33 -23
  28. package/lib/es6/persisters.js +1 -1
  29. package/lib/es6/persisters.js.gz +0 -0
  30. package/lib/es6/relationships.js +1 -1
  31. package/lib/es6/relationships.js.gz +0 -0
  32. package/lib/es6/store.d.ts +2022 -383
  33. package/lib/es6/store.js +1 -1
  34. package/lib/es6/store.js.gz +0 -0
  35. package/lib/es6/tinybase.js +1 -1
  36. package/lib/es6/tinybase.js.gz +0 -0
  37. package/lib/es6/tools.d.ts +89 -38
  38. package/lib/es6/tools.js +1 -1
  39. package/lib/es6/tools.js.gz +0 -0
  40. package/lib/es6/ui-react.d.ts +1525 -381
  41. package/lib/es6/ui-react.js +1 -1
  42. package/lib/es6/ui-react.js.gz +0 -0
  43. package/lib/indexes.js +1 -1
  44. package/lib/indexes.js.gz +0 -0
  45. package/lib/metrics.js +1 -1
  46. package/lib/metrics.js.gz +0 -0
  47. package/lib/persisters.d.ts +33 -23
  48. package/lib/persisters.js +1 -1
  49. package/lib/persisters.js.gz +0 -0
  50. package/lib/relationships.js +1 -1
  51. package/lib/relationships.js.gz +0 -0
  52. package/lib/store.d.ts +2022 -383
  53. package/lib/store.js +1 -1
  54. package/lib/store.js.gz +0 -0
  55. package/lib/tinybase.js +1 -1
  56. package/lib/tinybase.js.gz +0 -0
  57. package/lib/tools.d.ts +89 -38
  58. package/lib/tools.js +1 -1
  59. package/lib/tools.js.gz +0 -0
  60. package/lib/ui-react.d.ts +1525 -381
  61. package/lib/ui-react.js +1 -1
  62. package/lib/ui-react.js.gz +0 -0
  63. package/lib/umd/checkpoints.d.ts +18 -3
  64. package/lib/umd/checkpoints.js +1 -1
  65. package/lib/umd/checkpoints.js.gz +0 -0
  66. package/lib/umd/indexes.js +1 -1
  67. package/lib/umd/indexes.js.gz +0 -0
  68. package/lib/umd/metrics.js +1 -1
  69. package/lib/umd/metrics.js.gz +0 -0
  70. package/lib/umd/persisters.d.ts +33 -23
  71. package/lib/umd/persisters.js +1 -1
  72. package/lib/umd/persisters.js.gz +0 -0
  73. package/lib/umd/relationships.js +1 -1
  74. package/lib/umd/relationships.js.gz +0 -0
  75. package/lib/umd/store.d.ts +2022 -383
  76. package/lib/umd/store.js +1 -1
  77. package/lib/umd/store.js.gz +0 -0
  78. package/lib/umd/tinybase.js +1 -1
  79. package/lib/umd/tinybase.js.gz +0 -0
  80. package/lib/umd/tools.d.ts +89 -38
  81. package/lib/umd/tools.js +1 -1
  82. package/lib/umd/tools.js.gz +0 -0
  83. package/lib/umd/ui-react.d.ts +1525 -381
  84. package/lib/umd/ui-react.js +1 -1
  85. package/lib/umd/ui-react.js.gz +0 -0
  86. package/lib/umd-es6/checkpoints.d.ts +18 -3
  87. package/lib/umd-es6/checkpoints.js +1 -1
  88. package/lib/umd-es6/checkpoints.js.gz +0 -0
  89. package/lib/umd-es6/indexes.js +1 -1
  90. package/lib/umd-es6/indexes.js.gz +0 -0
  91. package/lib/umd-es6/metrics.js +1 -1
  92. package/lib/umd-es6/metrics.js.gz +0 -0
  93. package/lib/umd-es6/persisters.d.ts +33 -23
  94. package/lib/umd-es6/persisters.js +1 -1
  95. package/lib/umd-es6/persisters.js.gz +0 -0
  96. package/lib/umd-es6/relationships.js +1 -1
  97. package/lib/umd-es6/relationships.js.gz +0 -0
  98. package/lib/umd-es6/store.d.ts +2022 -383
  99. package/lib/umd-es6/store.js +1 -1
  100. package/lib/umd-es6/store.js.gz +0 -0
  101. package/lib/umd-es6/tinybase.js +1 -1
  102. package/lib/umd-es6/tinybase.js.gz +0 -0
  103. package/lib/umd-es6/tools.d.ts +89 -38
  104. package/lib/umd-es6/tools.js +1 -1
  105. package/lib/umd-es6/tools.js.gz +0 -0
  106. package/lib/umd-es6/ui-react.d.ts +1525 -381
  107. package/lib/umd-es6/ui-react.js +1 -1
  108. package/lib/umd-es6/ui-react.js.gz +0 -0
  109. package/package.json +26 -26
  110. package/readme.md +20 -19
@@ -90,16 +90,61 @@ export type Cell = string | number | boolean;
90
90
 
91
91
  /**
92
92
  * The CellOrUndefined type is a data structure representing the data in a
93
- * single cell or the value `undefined`.
93
+ * single cell, or the value `undefined`.
94
94
  *
95
- * This is used when describing a Cell that is present _or_ that is not present
96
- * - such as when it has been deleted, or when describing a previous state where
95
+ * This is used when describing a Cell that is present _or_ that is not present,
96
+ * such as when it has been deleted, or when describing a previous state where
97
97
  * the Cell value has since been added.
98
98
  *
99
99
  * @category Store
100
100
  */
101
101
  export type CellOrUndefined = Cell | undefined;
102
102
 
103
+ /**
104
+ * The Values type is the data structure representing all the keyed values in a
105
+ * Store.
106
+ *
107
+ * A Values object is used when setting values with the setValues method, and
108
+ * when getting them back out again with the getValues method. A Values object
109
+ * is a regular JavaScript object containing individual Value objects, keyed by
110
+ * their Id.
111
+ *
112
+ * @example
113
+ * ```js
114
+ * const values: Values = {open: true, employees: 4};
115
+ * ```
116
+ * @category Store
117
+ */
118
+ export type Values = {[valueId: Id]: Value};
119
+
120
+ /**
121
+ * The Value type is the data structure representing the data in a single keyed
122
+ * value.
123
+ *
124
+ * A Value is used when setting a value with the setValue method, and when
125
+ * getting it back out again with the getValue method. A Value is a JavaScript
126
+ * string, number, or boolean.
127
+ *
128
+ * @example
129
+ * ```js
130
+ * const value: Value = 'dog';
131
+ * ```
132
+ * @category Store
133
+ */
134
+ export type Value = string | number | boolean;
135
+
136
+ /**
137
+ * The ValueOrUndefined type is a data structure representing the data in a
138
+ * single value, or the value `undefined`.
139
+ *
140
+ * This is used when describing a Value that is present _or_ that is not
141
+ * present, such as when it has been deleted, or when describing a previous
142
+ * state where the Value has since been added.
143
+ *
144
+ * @category Store
145
+ */
146
+ export type ValueOrUndefined = Value | undefined;
147
+
103
148
  /**
104
149
  * The TableCallback type describes a function that takes a Table's Id and a
105
150
  * callback to loop over each Row within it.
@@ -150,6 +195,20 @@ export type RowCallback = (
150
195
  */
151
196
  export type CellCallback = (cellId: Id, cell: Cell) => void;
152
197
 
198
+ /**
199
+ * The ValueCallback type describes a function that takes a Value's Id and its
200
+ * actual value.
201
+ *
202
+ * A ValueCallback is provided when using the forEachValue method, so that you
203
+ * can do something based on every Value in a Store. See that method for
204
+ * specific examples.
205
+ *
206
+ * @param valueId The Id of the Value that the callback can operate on.
207
+ * @param value The Value itself.
208
+ * @category Callback
209
+ */
210
+ export type ValueCallback = (valueId: Id, value: Value) => void;
211
+
153
212
  /**
154
213
  * The MapCell type describes a function that takes an existing Cell value and
155
214
  * returns another.
@@ -163,6 +222,19 @@ export type CellCallback = (cellId: Id, cell: Cell) => void;
163
222
  */
164
223
  export type MapCell = (cell: CellOrUndefined) => Cell;
165
224
 
225
+ /**
226
+ * The MapValue type describes a function that takes an existing Value and
227
+ * returns another.
228
+ *
229
+ * A MapValue can be provided in the setValue method to map an existing Value to
230
+ * a new one, such as when incrementing a number. See that method for specific
231
+ * examples.
232
+ *
233
+ * @param value The current Value to map to a new Value.
234
+ * @category Callback
235
+ */
236
+ export type MapValue = (value: ValueOrUndefined) => Value;
237
+
166
238
  /**
167
239
  * The GetCell type describes a function that takes a Id and returns the Cell
168
240
  * value for a particular Row.
@@ -176,6 +248,32 @@ export type MapCell = (cell: CellOrUndefined) => Cell;
176
248
  */
177
249
  export type GetCell = (cellId: Id) => CellOrUndefined;
178
250
 
251
+ /**
252
+ * The DoRollback type describes a function that you can use to rollback the
253
+ * transaction if it did not complete to your satisfaction.
254
+ *
255
+ * A DoRollback can be provided when calling the transaction method or the
256
+ * finishTransaction method. See those methods for specific examples.
257
+ *
258
+ * It is called with `changedCells`, `invalidCells`, `changedValues`, and
259
+ * `invalidValues` parameters, which inform you of the net changes that have
260
+ * been made during the transaction, and any invalid attempts to do so,
261
+ * respectively.
262
+ *
263
+ * @param changedCells Any Cells that were changed during the transaction.
264
+ * @param invalidCells Any invalid attempts to change Cells.
265
+ * @param changedValues Any Values that were changed during the transaction,
266
+ * since v3.0.0.
267
+ * @param invalidValues Any invalid attempts to change Values, since v3.0.0.
268
+ * @category Callback
269
+ */
270
+ export type DoRollback = (
271
+ changedCells: ChangedCells,
272
+ invalidCells: InvalidCells,
273
+ changedValues: ChangedValues,
274
+ invalidValues: InvalidValues,
275
+ ) => boolean;
276
+
179
277
  /**
180
278
  * The TransactionListener type describes a function that is used to listen to
181
279
  * the completion of a transaction for the Store.
@@ -185,22 +283,28 @@ export type GetCell = (cellId: Id) => CellOrUndefined;
185
283
  * See those methods for specific examples.
186
284
  *
187
285
  * When called, a TransactionListener is simply given a reference to the Store
188
- * and a boolean to indicate whether Cell values have been touched during the
189
- * transaction. The latter flag is intended as a hint about whether non-mutating
190
- * listeners might be being called at the end of the transaction.
286
+ * and booleans to indicate whether Cell or Value data has been touched during
287
+ * the transaction. The two flags are intended as a hint about whether
288
+ * non-mutating listeners might be being called at the end of the transaction.
191
289
  *
192
- * Here, 'touched' means that Cell values have either been changed, or changed
193
- * and then changed back to its original value during the transaction. The
194
- * exception is a transaction that has been rolled back, for which the value of
195
- * `cellsTouched` in the listener will be `false` because all changes have been
196
- * reverted.
290
+ * Here, 'touched' means that Cell or Value data has either been changed, or
291
+ * changed and then changed back to its original value during the transaction.
292
+ * The exception is a transaction that has been rolled back, for which the value
293
+ * of `cellsTouched` and `valuesTouched` in the listener will be `false` because
294
+ * all changes have been reverted.
197
295
  *
198
296
  * @param store A reference to the Store that is completing a transaction.
199
297
  * @param cellsTouched Whether Cell values have been touched during the
200
298
  * transaction.
299
+ * @param valuesTouched Whether Values have been touched during the
300
+ * transaction, since v3.0.0.
201
301
  * @category Listener
202
302
  */
203
- export type TransactionListener = (store: Store, cellsTouched: boolean) => void;
303
+ export type TransactionListener = (
304
+ store: Store,
305
+ cellsTouched: boolean,
306
+ valuesTouched: boolean,
307
+ ) => void;
204
308
 
205
309
  /**
206
310
  * The TablesListener type describes a function that is used to listen to
@@ -403,6 +507,78 @@ export type CellListener = (
403
507
  getCellChange: GetCellChange | undefined,
404
508
  ) => void;
405
509
 
510
+ /**
511
+ * The ValuesListener type describes a function that is used to listen to
512
+ * changes to all the Values in a Store.
513
+ *
514
+ * A ValuesListener is provided when using the addValuesListener method. See
515
+ * that method for specific examples.
516
+ *
517
+ * When called, a ValuesListener is given a reference to the Store and a
518
+ * GetValueChange function that can be used to query Values before and after the
519
+ * current transaction.
520
+ *
521
+ * Note that if the listener was manually forced to be called (with the
522
+ * callListener method rather than due to a real change in the Store), the
523
+ * GetValueChange function will not be present.
524
+ *
525
+ * @param store A reference to the Store that changed.
526
+ * @param getValueChange A function that returns information about any Value's
527
+ * changes.
528
+ * @category Listener
529
+ */
530
+ export type ValuesListener = (
531
+ store: Store,
532
+ getValueChange: GetValueChange | undefined,
533
+ ) => void;
534
+
535
+ /**
536
+ * The ValueIdsListener type describes a function that is used to listen to
537
+ * changes to the Value Ids in a Store.
538
+ *
539
+ * A ValueIdsListener is provided when using the addValueIdsListener method. See
540
+ * that method for specific examples.
541
+ *
542
+ * When called, a ValueIdsListener is given a reference to the Store.
543
+ *
544
+ * @param store A reference to the Store that changed.
545
+ * @category Listener
546
+ */
547
+ export type ValueIdsListener = (store: Store) => void;
548
+
549
+ /**
550
+ * The ValueListener type describes a function that is used to listen to changes
551
+ * to a Value.
552
+ *
553
+ * A ValueListener is provided when using the addValueListener method. See that
554
+ * method for specific examples.
555
+ *
556
+ * When called, a ValueListener is given a reference to the Store and the Id of
557
+ * Value that changed. It is also given the new value of the Value, the old
558
+ * value of the Value, and a GetValueChange function that can be used to query
559
+ * Values before and after the current transaction.
560
+ *
561
+ * Note that if the listener was manually forced to be called (with the
562
+ * callListener method rather than due to a real change in the Store), the
563
+ * GetValueChange function will not be present and the new and old values of the
564
+ * Value will be the same.
565
+ *
566
+ * @param store A reference to the Store that changed.
567
+ * @param valueId The Id of the Value that changed.
568
+ * @param newValue The new value of the Value that changed.
569
+ * @param oldValue The old value of the Value that changed.
570
+ * @param getValueChange A function that returns information about any Value's
571
+ * changes.
572
+ * @category Listener
573
+ */
574
+ export type ValueListener = (
575
+ store: Store,
576
+ valueId: Id,
577
+ newValue: Value,
578
+ oldValue: Value,
579
+ getValueChange: GetValueChange | undefined,
580
+ ) => void;
581
+
406
582
  /**
407
583
  * The InvalidCellListener type describes a function that is used to listen to
408
584
  * attempts to set invalid data to a Cell.
@@ -411,7 +587,7 @@ export type CellListener = (
411
587
  * method. See that method for specific examples.
412
588
  *
413
589
  * When called, a InvalidCellListener is given a reference to the Store, the Id
414
- * of the Table, the Id of the Row, and the Id of Cell that were being attempted
590
+ * of the Table, the Id of the Row, and the Id of Cell that was being attempted
415
591
  * to be changed. It is also given the invalid value of the Cell, which could
416
592
  * have been of absolutely any type. Since there could have been multiple failed
417
593
  * attempts to set the Cell within a single transaction, this is an array
@@ -433,6 +609,32 @@ export type InvalidCellListener = (
433
609
  invalidCells: any[],
434
610
  ) => void;
435
611
 
612
+ /**
613
+ * The InvalidValueListener type describes a function that is used to listen to
614
+ * attempts to set invalid data to a Value.
615
+ *
616
+ * A InvalidValueListener is provided when using the addInvalidValueListener
617
+ * method. See that method for specific examples.
618
+ *
619
+ * When called, a InvalidValueListener is given a reference to the Store and the
620
+ * Id of Value that was being attempted to be changed. It is also given the
621
+ * invalid value of the Value, which could have been of absolutely any type.
622
+ * Since there could have been multiple failed attempts to set the Value within
623
+ * a single transaction, this is an array containing each attempt,
624
+ * chronologically.
625
+ *
626
+ * @param store A reference to the Store that was being changed.
627
+ * @param valueId The Id of the Value that was being changed.
628
+ * @param invalidValues An array of the Values that were invalid.
629
+ * @category Listener
630
+ * @since v3.0.0
631
+ */
632
+ export type InvalidValueListener = (
633
+ store: Store,
634
+ valueId: Id,
635
+ invalidValues: any[],
636
+ ) => void;
637
+
436
638
  /**
437
639
  * The GetCellChange type describes a function that returns information about
438
640
  * any Cell's changes during a transaction.
@@ -467,20 +669,52 @@ export type CellChange = [
467
669
  ];
468
670
 
469
671
  /**
470
- * The Schema type describes the structure of a Store in terms of valid Table
471
- * Ids and the types of Cell that can exist within them.
672
+ * The GetValueChange type describes a function that returns information about
673
+ * any Value's changes during a transaction.
674
+ *
675
+ * A GetValueChange function is provided to every listener when called due the
676
+ * Store changing. The listener can then fetch the previous value of a Value
677
+ * before the current transaction, the new value after it, and a convenience
678
+ * flag that indicates that the value has changed.
679
+ *
680
+ * @param valueId The Id of the Value to inspect.
681
+ * @returns A ValueChange array containing information about the Value's
682
+ * changes.
683
+ * @category Listener
684
+ */
685
+ export type GetValueChange = (valueId: Id) => ValueChange;
686
+
687
+ /**
688
+ * The ValueChange type describes a Value's changes during a transaction.
689
+ *
690
+ * This is returned by the GetValueChange function that is provided to every
691
+ * listener when called. This array contains the previous value of a Value
692
+ * before the current transaction, the new value after it, and a convenience
693
+ * flag that indicates that the value has changed.
694
+ *
695
+ * @category Listener
696
+ */
697
+ export type ValueChange = [
698
+ changed: boolean,
699
+ oldValue: ValueOrUndefined,
700
+ newValue: ValueOrUndefined,
701
+ ];
702
+
703
+ /**
704
+ * The TablesSchema type describes the tabular structure of a Store in terms of
705
+ * valid Table Ids and the types of Cell that can exist within them.
472
706
  *
473
- * A Schema comprises a JavaScript object describing each Table, in turn a
707
+ * A TablesSchema comprises a JavaScript object describing each Table, in turn a
474
708
  * nested JavaScript object containing information about each Cell and its
475
- * CellSchema. It is provided to the setSchema method.
709
+ * CellSchema. It is provided to the setTablesSchema method.
476
710
  *
477
711
  * @example
478
- * When applied to a Store, this Schema only allows one Table called `pets`, in
479
- * which each Row may contain a string `species` Cell, and is guaranteed to
480
- * contain a boolean `sold` Cell that defaults to `false`.
712
+ * When applied to a Store, this TablesSchema only allows one Table called
713
+ * `pets`, in which each Row may contain a string `species` Cell, and is
714
+ * guaranteed to contain a boolean `sold` Cell that defaults to `false`.
481
715
  *
482
716
  *```js
483
- * const schema: Schema = {
717
+ * const tableSchema: TablesSchema = {
484
718
  * pets: {
485
719
  * species: {type: 'string'},
486
720
  * sold: {type: 'boolean', default: false},
@@ -489,7 +723,7 @@ export type CellChange = [
489
723
  * ```
490
724
  * @category Schema
491
725
  */
492
- export type Schema = {
726
+ export type TablesSchema = {
493
727
  [tableId: Id]: {
494
728
  [cellId: Id]: CellSchema;
495
729
  };
@@ -520,18 +754,62 @@ export type Schema = {
520
754
  * @category Schema
521
755
  */
522
756
  export type CellSchema =
523
- | {
524
- type: 'string';
525
- default?: string;
526
- }
527
- | {
528
- type: 'number';
529
- default?: number;
530
- }
531
- | {
532
- type: 'boolean';
533
- default?: boolean;
534
- };
757
+ | {type: 'string'; default?: string}
758
+ | {type: 'number'; default?: number}
759
+ | {type: 'boolean'; default?: boolean};
760
+
761
+ /**
762
+ * The ValuesSchema type describes the keyed Values that can be set in a Store
763
+ * and their types.
764
+ *
765
+ * A ValuesSchema comprises a JavaScript object describing each Value and its
766
+ * ValueSchema. It is provided to the setValuesSchema method.
767
+ *
768
+ * @example
769
+ * When applied to a Store, this ValuesSchema only allows one boolean Value
770
+ * called `open`, that defaults to `false`.
771
+ *
772
+ *```js
773
+ * const valuesSchema: ValuesSchema = {
774
+ * open: {type: 'boolean', default: false},
775
+ * };
776
+ * ```
777
+ * @category Schema
778
+ * @since v3.0.0
779
+ */
780
+ export type ValuesSchema = {
781
+ [valueId: Id]: ValueSchema;
782
+ };
783
+
784
+ /**
785
+ * The ValueSchema type describes what values are allowed for keyed Values in a
786
+ * Store.
787
+ *
788
+ * A ValueSchema specifies the type of the Value (`string`, `boolean`, or
789
+ * `number`), and what the default value can be when an explicit value is not
790
+ * specified.
791
+ *
792
+ * If a default value is provided (and its type is correct), you can be certain
793
+ * that the Value will always be present in a Store.
794
+ *
795
+ * If the default value is _not_ provided (or its type is incorrect), the Value
796
+ * may not be present in the Store, but when present you can be guaranteed it is
797
+ * of the correct type.
798
+ *
799
+ * @example
800
+ * When applied to a Store, this ValueSchema ensures a boolean Value is always
801
+ * present, and defaults it to `false`.
802
+ *
803
+ *```js
804
+ * const requiredBoolean: ValueSchema = {type: 'boolean', default: false};
805
+ * ```
806
+ * @category Schema
807
+ * @since v3.0.0
808
+ */
809
+ export type ValueSchema =
810
+ | {type: 'string'; default?: string}
811
+ | {type: 'number'; default?: number}
812
+ | {type: 'boolean'; default?: boolean};
535
813
 
536
814
  /**
537
815
  * The ChangedCells type describes the Cell values that have been changed during
@@ -539,7 +817,8 @@ export type CellSchema =
539
817
  * transaction should be rolled back.
540
818
  *
541
819
  * A ChangedCells object is provided to the `doRollback` callback when using the
542
- * transaction method. See that method for specific examples.
820
+ * transaction method and the finishTransaction method. See those methods for
821
+ * specific examples.
543
822
  *
544
823
  * This type is a nested structure of Table, Row, and Cell objects, much like
545
824
  * the Tables object, but one which provides both the old and new Cell values in
@@ -564,13 +843,15 @@ export type ChangedCells = {
564
843
  };
565
844
  };
566
845
  };
846
+
567
847
  /**
568
848
  * The InvalidCells type describes the invalid Cell values that have been
569
849
  * attempted during a transaction, primarily used so that you can indicate
570
850
  * whether the transaction should be rolled back.
571
851
  *
572
852
  * An InvalidCells object is provided to the `doRollback` callback when using
573
- * the transaction method. See that method for specific examples.
853
+ * the transaction method and the finishTransaction method. See those methods
854
+ * for specific examples.
574
855
  *
575
856
  * This type is a nested structure of Table, Row, and Cell objects, much like
576
857
  * the Tables object, but one for which Cell values are listed in array (much
@@ -588,6 +869,53 @@ export type InvalidCells = {
588
869
  };
589
870
  };
590
871
 
872
+ /**
873
+ * The ChangedValues type describes the Values that have been changed during a
874
+ * transaction, primarily used so that you can indicate whether the transaction
875
+ * should be rolled back.
876
+ *
877
+ * A ChangedValues object is provided to the `doRollback` callback when using
878
+ * the transaction method and the finishTransaction method. See those methods
879
+ * for specific examples.
880
+ *
881
+ * This type is an object containing the old and new Values in two-part arrays.
882
+ * These are describing the state of each changed Value in Store at the _start_
883
+ * of the transaction, and by the _end_ of the transaction.
884
+ *
885
+ * Hence, an `undefined` value for the first item in the array means that the
886
+ * Value was added during the transaction. An `undefined` value for the second
887
+ * item in the array means that the Value was removed during the transaction. An
888
+ * array with two different Values indicates that it was changed. The two-part
889
+ * array will never contain two items of the same value (including two
890
+ * `undefined` values), even if, during the transaction, a Value was changed to
891
+ * a different value and then changed back.
892
+ *
893
+ * @category Transaction
894
+ * @since v3.0.0
895
+ */
896
+ export type ChangedValues = {
897
+ [valueId: Id]: [ValueOrUndefined, ValueOrUndefined];
898
+ };
899
+ /**
900
+ * The InvalidValues type describes the invalid Values that have been attempted
901
+ * during a transaction, primarily used so that you can indicate whether the
902
+ * transaction should be rolled back.
903
+ *
904
+ * An InvalidValues object is provided to the `doRollback` callback when using
905
+ * the transaction method and the finishTransaction method. See those methods
906
+ * for specific examples.
907
+ *
908
+ * This type is an object containing each invalid Value's attempt listed in
909
+ * array (much like the InvalidValueListener type) so that multiple failed
910
+ * attempts to change a Value during the transaction are described.
911
+ *
912
+ * @category Transaction
913
+ * @since v3.0.0
914
+ */
915
+ export type InvalidValues = {
916
+ [valueId: Id]: any[];
917
+ };
918
+
591
919
  /**
592
920
  * The StoreListenerStats type describes the number of listeners registered with
593
921
  * the Store, and can be used for debugging purposes.
@@ -636,6 +964,26 @@ export type StoreListenerStats = {
636
964
  * The number of InvalidCellListener functions registered with the Store.
637
965
  */
638
966
  invalidCell?: number;
967
+ /**
968
+ * The number of ValuesListener functions registered with the Store, since
969
+ * v3.0.0.
970
+ */
971
+ values?: number;
972
+ /**
973
+ * The number of ValueIdsListener functions registered with the Store, since
974
+ * v3.0.0.
975
+ */
976
+ valueIds?: number;
977
+ /**
978
+ * The number of ValueListener functions registered with the Store, since
979
+ * v3.0.0.
980
+ */
981
+ value?: number;
982
+ /**
983
+ * The number of InvalidValueListener functions registered with the Store,
984
+ * since v3.0.0.
985
+ */
986
+ invalidValue?: number;
639
987
  /**
640
988
  * The number of TransactionListener functions registered with the Store.
641
989
  */
@@ -643,13 +991,39 @@ export type StoreListenerStats = {
643
991
  };
644
992
 
645
993
  /**
646
- * A Store is the main location for keeping structured state and tabular data.
994
+ * A Store is the main location for keeping both tabular data and keyed values.
647
995
  *
648
996
  * Create a Store easily with the createStore function. From there, you can set
649
- * and get data, add listeners for when the data changes, set a Schema, and so
997
+ * and get data, add listeners for when the data changes, set schemas, and so
650
998
  * on.
651
999
  *
652
- * A Store has a simple hierarchical structure:
1000
+ * A Store has two facets. It can contain keyed Values, and independently, it
1001
+ * can contain tabular Tables data. These two facets have similar APIs but can
1002
+ * be used entirely independently: you can use only tables, only keyed Values,
1003
+ * or both tables _and_ keyed Values - all in a single Store.
1004
+ *
1005
+ * # Keyed values
1006
+ *
1007
+ * The keyed value support is best thought of as a flat JavaScript object. The
1008
+ * Store contains a number of Value objects, each with a unique ID, and which is
1009
+ * a string, boolean, or number:
1010
+ *
1011
+ * ```json
1012
+ * { // Store
1013
+ * "value1": "one", // Value (string)
1014
+ * "value2": true, // Value (boolean)
1015
+ * "value3": 3, // Value (number)
1016
+ * ...
1017
+ * }
1018
+ * ```
1019
+ *
1020
+ * In its default form, a Store has no sense of a structured schema for the
1021
+ * Values. However, you _can_ optionally specify a ValuesSchema for a Store,
1022
+ * which then usefully constrains and defaults the Values you can use.
1023
+ *
1024
+ * # Tabular data
1025
+ *
1026
+ * The tabular data exists in a simple hierarchical structure:
653
1027
  *
654
1028
  * - The Store contains a number of Table objects.
655
1029
  * - Each Table contains a number of Row objects.
@@ -676,11 +1050,11 @@ export type StoreListenerStats = {
676
1050
  * }
677
1051
  * ```
678
1052
  *
679
- * In its default form, a Store has no sense of a structured schema, so, as long
680
- * as they are unique within their own parent, the Id keys can each be any
681
- * string you want. However, you _can_ optionally specify a Schema for a Store,
682
- * which then usefully constrains the Table and Cell Ids (and Cell values) you
683
- * can use.
1053
+ * Again, by default Store has no sense of a structured schema. As long as they
1054
+ * are unique within their own parent, the Id keys can each be any string you
1055
+ * want. However, as you _can_ optionally specify a TablesSchema for the tabular
1056
+ * data in a Store, which then usefully constrains the Table and Cell Ids (and
1057
+ * Cell values) you can use.
684
1058
  *
685
1059
  * # Setting and getting data
686
1060
  *
@@ -700,6 +1074,9 @@ export type StoreListenerStats = {
700
1074
  *
701
1075
  * |Type|Get data|Set data|Delete data|Add a listener|
702
1076
  * |-|-|-|-|-|
1077
+ * |Values|getValues|setValues|delValues|addValuesListener|
1078
+ * |Value Ids|getValueIds|-|-|addValueIdsListener|
1079
+ * |Value|getValue|setValue|delValue|addValueListener|
703
1080
  * |Tables|getTables|setTables|delTables|addTablesListener|
704
1081
  * |Table Ids|getTableIds|-|-|addTableIdsListener|
705
1082
  * |Table|getTable|setTable|delTable|addTableListener|
@@ -709,13 +1086,14 @@ export type StoreListenerStats = {
709
1086
  * |Cell Ids|getCellIds|-|-|addCellIdsListener|
710
1087
  * |Cell|getCell|setCell|delCell|addCellListener|
711
1088
  *
712
- * Additionally, there are two extra methods to manipulate Row objects. The
713
- * addRow method is like the setRow method but automatically assigns it a new
714
- * unique Id. And the setPartialRow method lets you update multiple Cell values
715
- * in a Row without affecting the others.
1089
+ * There are two extra methods to manipulate Row objects. The addRow method is
1090
+ * like the setRow method but automatically assigns it a new unique Id. And the
1091
+ * setPartialRow method lets you update multiple Cell values in a Row without
1092
+ * affecting the others. (There is a similar setPartialValues method to do the
1093
+ * same for the Values in a Store.)
716
1094
  *
717
- * You can listen to attempts to write invalid data to a Cell with the
718
- * addInvalidCellListener method.
1095
+ * You can listen to attempts to write invalid data to a Value or Cell with the
1096
+ * addInvalidValueListener method or addInvalidCellListener method.
719
1097
  *
720
1098
  * The transaction method is used to wrap multiple changes to the Store so that
721
1099
  * the relevant listeners only fire once.
@@ -733,17 +1111,17 @@ export type StoreListenerStats = {
733
1111
  * Read more about setting and changing data in The Basics guides, and about
734
1112
  * listeners in the Listening to Stores guide.
735
1113
  *
736
- * # Creating a Schema
1114
+ * # Creating a schema
737
1115
  *
738
- * You can set a Schema on a Store when you create it with createStore function,
739
- * or at a later stage with the setSchema method. A Schema constrains the Table
1116
+ * You can set a ValuesSchema and a TablesSchema with the setValuesSchema method
1117
+ * and setTablesSchema method respectively. A TablesSchema constrains the Table
740
1118
  * Ids the Store can have, and the types of Cell data in each Table. Each Cell
741
1119
  * requires its type to be specified, and can also take a default value for when
742
1120
  * it's not specified.
743
1121
  *
744
- * You can also get a serialization of the Schema out of the Store with the
745
- * getSchemaJson method, and remove the Schema altogether with the delSchema
746
- * method.
1122
+ * You can also get a serialization of the schemas out of the Store with
1123
+ * the getSchemaJson method, and remove the schemas altogether with
1124
+ * the delValuesSchema method and delTablesSchema method.
747
1125
  *
748
1126
  * Read more about schemas in the Using Schemas guide.
749
1127
  *
@@ -755,6 +1133,7 @@ export type StoreListenerStats = {
755
1133
  *
756
1134
  * ||Checking existence|Iterator|
757
1135
  * |-|-|-|
1136
+ * |Value|hasValue|forEachValue|
758
1137
  * |Table|hasTable|forEachTable|
759
1138
  * |Row|hasRow|forEachRow|
760
1139
  * |Cell|hasCell|forEachCell|
@@ -1136,6 +1515,92 @@ export interface Store {
1136
1515
  */
1137
1516
  getCell(tableId: Id, rowId: Id, cellId: Id): CellOrUndefined;
1138
1517
 
1518
+ /**
1519
+ * The getValues method returns an object containing the entire set of keyed
1520
+ * Values in the Store.
1521
+ *
1522
+ * Note that this returns a copy of, rather than a reference to the underlying
1523
+ * data, so changes made to the returned object are not made to the Store
1524
+ * itself.
1525
+ *
1526
+ * @returns An object containing the entire data of the Values.
1527
+ * @example
1528
+ * This example retrieves the keyed Values data in a Store.
1529
+ *
1530
+ * ```js
1531
+ * const store = createStore().setValues({open: true, employees: 3});
1532
+ * console.log(store.getValues());
1533
+ * // -> {open: true, employees: 3}
1534
+ * ```
1535
+ * @example
1536
+ * This example retrieves a Values from a Store that has none, returning an
1537
+ * empty object.
1538
+ *
1539
+ * ```js
1540
+ * const store = createStore();
1541
+ * console.log(store.getValues());
1542
+ * // -> {}
1543
+ * ```
1544
+ * @category Getter
1545
+ * @since v3.0.0
1546
+ */
1547
+ getValues(): Values;
1548
+
1549
+ /**
1550
+ * The getValueIds method returns the Ids of every Value in a Store.
1551
+ *
1552
+ * Note that this returns a copy of, rather than a reference, to the list of
1553
+ * Ids, so changes made to the list are not made to the Store itself.
1554
+ *
1555
+ * @returns An array of the Ids of every Value in the Store.
1556
+ * @example
1557
+ * This example retrieves the Value Ids in a Store.
1558
+ *
1559
+ * ```js
1560
+ * const store = createStore().setValues({open: true, employees: 3});
1561
+ * console.log(store.getValueIds());
1562
+ * // -> ['open', 'employees']
1563
+ * ```
1564
+ * @example
1565
+ * This example retrieves the Value Ids of a Store that has had none set,
1566
+ * returning an empty array.
1567
+ *
1568
+ * ```js
1569
+ * const store = createStore();
1570
+ * console.log(store.getValueIds());
1571
+ * // -> []
1572
+ * ```
1573
+ * @category Getter
1574
+ * @since v3.0.0
1575
+ */
1576
+ getValueIds(): Ids;
1577
+
1578
+ /**
1579
+ * The getValue method returns a single keyed Value in the Store.
1580
+ *
1581
+ * @param valueId The Id of the Value in the Store.
1582
+ * @returns The Value, or `undefined`.
1583
+ * @example
1584
+ * This example retrieves a single Value.
1585
+ *
1586
+ * ```js
1587
+ * const store = createStore().setValues({open: true, employees: 3});
1588
+ * console.log(store.getValue('employees'));
1589
+ * // -> 3
1590
+ * ```
1591
+ * @example
1592
+ * This example retrieves a Value that does not exist, returning `undefined`.
1593
+ *
1594
+ * ```js
1595
+ * const store = createStore().setValues({open: true, employees: 3});
1596
+ * console.log(store.getValue('website'));
1597
+ * // -> undefined
1598
+ * ```
1599
+ * @category Getter
1600
+ * @since v3.0.0
1601
+ */
1602
+ getValue(valueId: Id): ValueOrUndefined;
1603
+
1139
1604
  /**
1140
1605
  * The hasTables method returns a boolean indicating whether any Table objects
1141
1606
  * exist in the Store.
@@ -1220,61 +1685,235 @@ export interface Store {
1220
1685
  hasCell(tableId: Id, rowId: Id, cellId: Id): boolean;
1221
1686
 
1222
1687
  /**
1223
- * The getJson method returns a string serialization of all of the Tables in
1224
- * the Store.
1225
- *
1226
- * @returns A string serialization of all of the Tables in the Store.
1227
- * @example
1228
- * This example serializes the contents of a Store.
1688
+ * The hasTables method returns a boolean indicating whether any Values exist
1689
+ * in the Store.
1229
1690
  *
1230
- * ```js
1231
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1232
- * console.log(store.getJson());
1233
- * // -> '{"pets":{"fido":{"species":"dog"}}}'
1234
- * ```
1691
+ * @returns Whether any Values exist.
1235
1692
  * @example
1236
- * This example serializes the contents of an empty Store.
1693
+ * This example shows simple existence checks.
1237
1694
  *
1238
1695
  * ```js
1239
1696
  * const store = createStore();
1240
- * console.log(store.getJson());
1241
- * // -> '{}'
1697
+ * console.log(store.hasValues());
1698
+ * // -> false
1699
+ * store.setValues({open: true});
1700
+ * console.log(store.hasValues());
1701
+ * // -> true
1702
+ * ```
1703
+ * @category Getter
1704
+ * @since v3.0.0
1705
+ */
1706
+ hasValues(): boolean;
1707
+
1708
+ /**
1709
+ * The hasValue method returns a boolean indicating whether a given Value
1710
+ * exists in the Store.
1711
+ *
1712
+ * @param valueId The Id of a possible Value in the Store.
1713
+ * @returns Whether a Value with that Id exists in the Store.
1714
+ * @example
1715
+ * This example shows two simple Value existence checks.
1716
+ *
1717
+ * ```js
1718
+ * const store = createStore().setValues({open: true});
1719
+ * console.log(store.hasValue('open'));
1720
+ * // -> true
1721
+ * console.log(store.hasValue('employees'));
1722
+ * // -> false
1723
+ * ```
1724
+ * @category Getter
1725
+ * @since v3.0.0
1726
+ */
1727
+ hasValue(valueId: Id): boolean;
1728
+
1729
+ /**
1730
+ * The getTablesJson method returns a string serialization of all of the
1731
+ * Tables in the Store.
1732
+ *
1733
+ * @returns A string serialization of all of the Tables in the Store.
1734
+ * @example
1735
+ * This example serializes the contents of a Store.
1736
+ *
1737
+ * ```js
1738
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1739
+ * console.log(store.getTablesJson());
1740
+ * // -> '{"pets":{"fido":{"species":"dog"}}}'
1741
+ * ```
1742
+ * @example
1743
+ * This example serializes the contents of an empty Store.
1744
+ *
1745
+ * ```js
1746
+ * const store = createStore();
1747
+ * console.log(store.getTablesJson());
1748
+ * // -> '{}'
1749
+ * ```
1750
+ * @category Getter
1751
+ * @since v3.0.0
1752
+ */
1753
+ getTablesJson(): Json;
1754
+
1755
+ /**
1756
+ * The getValuesJson method returns a string serialization of all of the
1757
+ * keyed Values in the Store.
1758
+ *
1759
+ * @returns A string serialization of all of the Values in the Store.
1760
+ * @example
1761
+ * This example serializes the keyed value contents of a Store.
1762
+ *
1763
+ * ```js
1764
+ * const store = createStore().setValues({open: true});
1765
+ * console.log(store.getValuesJson());
1766
+ * // -> '{"open":true}'
1767
+ * ```
1768
+ * @example
1769
+ * This example serializes the contents of an empty Store.
1770
+ *
1771
+ * ```js
1772
+ * const store = createStore();
1773
+ * console.log(store.getValuesJson());
1774
+ * // -> '{}'
1775
+ * ```
1776
+ * @category Getter
1777
+ * @since v3.0.0
1778
+ */
1779
+ getValuesJson(): Json;
1780
+
1781
+ /**
1782
+ * The getJson method returns a string serialization of all the Store content:
1783
+ * both the Tables and the keyed Values.
1784
+ *
1785
+ * From v3.0.0 onwards, the serialization is of an array with two entries. The
1786
+ * first is the Tables object, the second the Values. In previous versions
1787
+ * (before the existence of the Values data structure), it was a sole object
1788
+ * of Tables.
1789
+ *
1790
+ * @returns A string serialization of the Tables and Values in the Store.
1791
+ * @example
1792
+ * This example serializes the tabular and keyed value contents of a Store.
1793
+ *
1794
+ * ```js
1795
+ * const store = createStore()
1796
+ * .setTables({pets: {fido: {species: 'dog'}}})
1797
+ * .setValues({open: true});
1798
+ * console.log(store.getJson());
1799
+ * // -> '[{"pets":{"fido":{"species":"dog"}}},{"open":true}]'
1800
+ * ```
1801
+ * @example
1802
+ * This example serializes the contents of an empty Store.
1803
+ *
1804
+ * ```js
1805
+ * const store = createStore();
1806
+ * console.log(store.getJson());
1807
+ * // -> '[{},{}]'
1242
1808
  * ```
1243
1809
  * @category Getter
1244
1810
  */
1245
1811
  getJson(): Json;
1246
1812
 
1247
1813
  /**
1248
- * The getSchemaJson method returns a string serialization of the Schema of
1249
- * the Store.
1814
+ * The getTablesSchemaJson method returns a string serialization of the
1815
+ * TablesSchema of the Store.
1250
1816
  *
1251
- * If no Schema has been set on the Store (or if it has been removed with the
1252
- * delSchema method), then it will return the serialization of an empty
1253
- * object, `{}`.
1817
+ * If no TablesSchema has been set on the Store (or if it has been removed
1818
+ * with the delTablesSchema method), then it will return the serialization of
1819
+ * an empty object, `{}`.
1254
1820
  *
1255
- * @returns A string serialization of the Schema of the Store.
1821
+ * @returns A string serialization of the TablesSchema of the Store.
1256
1822
  * @example
1257
- * This example serializes the Schema of a Store.
1823
+ * This example serializes the TablesSchema of a Store.
1258
1824
  *
1259
1825
  * ```js
1260
- * const store = createStore().setSchema({
1826
+ * const store = createStore().setTablesSchema({
1261
1827
  * pets: {
1262
1828
  * species: {type: 'string'},
1263
1829
  * sold: {type: 'boolean'},
1264
1830
  * },
1265
1831
  * });
1266
- * console.log(store.getSchemaJson());
1832
+ * console.log(store.getTablesSchemaJson());
1267
1833
  * // -> '{"pets":{"species":{"type":"string"},"sold":{"type":"boolean"}}}'
1268
1834
  * ```
1269
1835
  * @example
1270
- * This example serializes the Schema of an empty Store.
1836
+ * This example serializes the TablesSchema of an empty Store.
1271
1837
  *
1272
1838
  * ```js
1273
1839
  * const store = createStore();
1274
- * console.log(store.getSchemaJson());
1840
+ * console.log(store.getTablesSchemaJson());
1841
+ * // -> '{}'
1842
+ * ```
1843
+ * @category Getter
1844
+ * @since v3.0.0
1845
+ */
1846
+ getTablesSchemaJson(): Json;
1847
+
1848
+ /**
1849
+ * The getValuesSchemaJson method returns a string serialization of the
1850
+ * ValuesSchema of the Store.
1851
+ *
1852
+ * If no ValuesSchema has been set on the Store (or if it has been removed
1853
+ * with the delValuesSchema method), then it will return the serialization of
1854
+ * an empty object, `{}`.
1855
+ *
1856
+ * @returns A string serialization of the ValuesSchema of the Store.
1857
+ * @example
1858
+ * This example serializes the ValuesSchema of a Store.
1859
+ *
1860
+ * ```js
1861
+ * const store = createStore().setValuesSchema({
1862
+ * open: {type: 'boolean', default: false},
1863
+ * });
1864
+ * console.log(store.getValuesSchemaJson());
1865
+ * // -> '{"open":{"type":"boolean","default":false}}'
1866
+ * ```
1867
+ * @example
1868
+ * This example serializes the ValuesSchema of an empty Store.
1869
+ *
1870
+ * ```js
1871
+ * const store = createStore();
1872
+ * console.log(store.getValuesSchemaJson());
1275
1873
  * // -> '{}'
1276
1874
  * ```
1277
1875
  * @category Getter
1876
+ * @since v3.0.0
1877
+ */
1878
+ getValuesSchemaJson(): Json;
1879
+
1880
+ /**
1881
+ * The getSchemaJson method returns a string serialization of both the
1882
+ * TablesSchema and ValuesSchema of the Store.
1883
+ *
1884
+ * From v3.0.0 onwards, the serialization is of an array with two entries. The
1885
+ * first is the TablesSchema object, the second the ValuesSchema. In previous
1886
+ * versions (before the existence of the ValuesSchema data structure), it was
1887
+ * a sole object of TablesSchema.
1888
+ *
1889
+ * @returns A string serialization of the TablesSchema and ValuesSchema of the
1890
+ * Store.
1891
+ * @example
1892
+ * This example serializes the TablesSchema and ValuesSchema of a Store.
1893
+ *
1894
+ * ```js
1895
+ * const store = createStore()
1896
+ * .setTablesSchema({
1897
+ * pets: {
1898
+ * price: {type: 'number'},
1899
+ * },
1900
+ * })
1901
+ * .setValuesSchema({
1902
+ * open: {type: 'boolean'},
1903
+ * });
1904
+ * console.log(store.getSchemaJson());
1905
+ * // -> '[{"pets":{"price":{"type":"number"}}},{"open":{"type":"boolean"}}]'
1906
+ * ```
1907
+ * @example
1908
+ * This example serializes the TablesSchema and ValuesSchema of an empty
1909
+ * Store.
1910
+ *
1911
+ * ```js
1912
+ * const store = createStore();
1913
+ * console.log(store.getSchemaJson());
1914
+ * // -> '[{},{}]'
1915
+ * ```
1916
+ * @category Getter
1278
1917
  */
1279
1918
  getSchemaJson(): Json;
1280
1919
 
@@ -1285,14 +1924,14 @@ export interface Store {
1285
1924
  * Id changes resulting from it.
1286
1925
  *
1287
1926
  * Any part of the provided object that is invalid (either according to the
1288
- * Tables type, or because it does not match a Schema associated with the
1289
- * Store), will be ignored silently.
1927
+ * Tables type, or because it does not match a TablesSchema associated with
1928
+ * the Store), will be ignored silently.
1290
1929
  *
1291
1930
  * Assuming that at least some of the provided Tables object is valid, any
1292
1931
  * data that was already present in the Store will be completely overwritten.
1293
1932
  * If the object is completely invalid, no change will be made to the Store.
1294
1933
  *
1295
- * The method returns a reference to the Store to that subsequent operations
1934
+ * The method returns a reference to the Store so that subsequent operations
1296
1935
  * can be chained in a fluent style.
1297
1936
  *
1298
1937
  * @param tables The data of the Store to be set.
@@ -1334,7 +1973,7 @@ export interface Store {
1334
1973
  * Id changes resulting from it.
1335
1974
  *
1336
1975
  * Any part of the provided object that is invalid (either according to the
1337
- * Table type, or because it does not match a Schema associated with the
1976
+ * Table type, or because it does not match a TablesSchema associated with the
1338
1977
  * Store), will be ignored silently.
1339
1978
  *
1340
1979
  * Assuming that at least some of the provided Table object is valid, any data
@@ -1342,7 +1981,7 @@ export interface Store {
1342
1981
  * overwritten. If the object is completely invalid, no change will be made to
1343
1982
  * the Store.
1344
1983
  *
1345
- * The method returns a reference to the Store to that subsequent operations
1984
+ * The method returns a reference to the Store so that subsequent operations
1346
1985
  * can be chained in a fluent style.
1347
1986
  *
1348
1987
  * @param tableId The Id of the Table in the Store.
@@ -1385,15 +2024,15 @@ export interface Store {
1385
2024
  * Id changes resulting from it.
1386
2025
  *
1387
2026
  * Any part of the provided object that is invalid (either according to the
1388
- * Row type, or because it does not match a Schema associated with the Store),
1389
- * will be ignored silently.
2027
+ * Row type, or because it does not match a TablesSchema associated with the
2028
+ * Store), will be ignored silently.
1390
2029
  *
1391
2030
  * Assuming that at least some of the provided Row object is valid, any data
1392
2031
  * that was already present in the Store for that Row will be completely
1393
2032
  * overwritten. If the object is completely invalid, no change will be made to
1394
2033
  * the Store.
1395
2034
  *
1396
- * The method returns a reference to the Store to that subsequent operations
2035
+ * The method returns a reference to the Store so that subsequent operations
1397
2036
  * can be chained in a fluent style.
1398
2037
  *
1399
2038
  * @param tableId The Id of the Table in the Store.
@@ -1435,8 +2074,8 @@ export interface Store {
1435
2074
  * Id changes resulting from it.
1436
2075
  *
1437
2076
  * Any part of the provided object that is invalid (either according to the
1438
- * Row type, or because it does not match a Schema associated with the Store),
1439
- * will be ignored silently.
2077
+ * Row type, or because it does not match a TablesSchema associated with the
2078
+ * Store), will be ignored silently.
1440
2079
  *
1441
2080
  * Assuming that at least some of the provided Row object is valid, a new Row
1442
2081
  * will be created. If the object is completely invalid, no change will be
@@ -1489,13 +2128,13 @@ export interface Store {
1489
2128
  *
1490
2129
  * Any part of the provided object that is invalid (either according to the
1491
2130
  * Row type, or because, when combined with the current Row data, it does not
1492
- * match a Schema associated with the Store), will be ignored silently.
2131
+ * match a TablesSchema associated with the Store), will be ignored silently.
1493
2132
  *
1494
2133
  * Assuming that at least some of the provided Row object is valid, it will be
1495
2134
  * merged with the data that was already present in the Store. If the object
1496
2135
  * is completely invalid, no change will be made to the Store.
1497
2136
  *
1498
- * The method returns a reference to the Store to that subsequent operations
2137
+ * The method returns a reference to the Store so that subsequent operations
1499
2138
  * can be chained in a fluent style.
1500
2139
  *
1501
2140
  * @param tableId The Id of the Table in the Store.
@@ -1539,7 +2178,7 @@ export interface Store {
1539
2178
  * Id changes resulting from it.
1540
2179
  *
1541
2180
  * If the Cell value is invalid (either because of its type, or because it
1542
- * does not match a Schema associated with the Store), will be ignored
2181
+ * does not match a TablesSchema associated with the Store), will be ignored
1543
2182
  * silently.
1544
2183
  *
1545
2184
  * As well as string, number, or boolean Cell types, this method can also take
@@ -1547,7 +2186,7 @@ export interface Store {
1547
2186
  * maps it. This is useful if you want to efficiently increment a value
1548
2187
  * without fetching it first, for example.
1549
2188
  *
1550
- * The method returns a reference to the Store to that subsequent operations
2189
+ * The method returns a reference to the Store so that subsequent operations
1551
2190
  * can be chained in a fluent style.
1552
2191
  *
1553
2192
  * @param tableId The Id of the Table in the Store.
@@ -1591,53 +2230,391 @@ export interface Store {
1591
2230
  setCell(tableId: Id, rowId: Id, cellId: Id, cell: Cell | MapCell): Store;
1592
2231
 
1593
2232
  /**
1594
- * The setJson method takes a string serialization of all of the Tables in the
1595
- * Store and attempts to update it to that value
2233
+ * The setValues method takes an object and sets all the Values in the Store.
2234
+ *
2235
+ * This method will cause listeners to be called for any Value or Id changes
2236
+ * resulting from it.
2237
+ *
2238
+ * Any part of the provided object that is invalid (either according to the
2239
+ * Values type, or because it does not match a ValuesSchema associated with
2240
+ * the Store), will be ignored silently.
2241
+ *
2242
+ * Assuming that at least some of the provided Values object is valid, any
2243
+ * data that was already present in the Store for that Values will be
2244
+ * completely overwritten. If the object is completely invalid, no change will
2245
+ * be made to the Store.
2246
+ *
2247
+ * The method returns a reference to the Store so that subsequent operations
2248
+ * can be chained in a fluent style.
2249
+ *
2250
+ * @param values The Values object to be set.
2251
+ * @returns A reference to the Store.
2252
+ * @example
2253
+ * This example sets the Values of a Store.
2254
+ *
2255
+ * ```js
2256
+ * const store = createStore().setValues({open: true, employees: 3});
2257
+ * console.log(store.getValues());
2258
+ * // -> {open: true, employees: 3}
2259
+ * ```
2260
+ * @example
2261
+ * This example attempts to set the data of an existing Store with partly
2262
+ * invalid, and then completely invalid, Values objects.
2263
+ *
2264
+ * ```js
2265
+ * const store = createStore().setValues({open: true});
2266
+ *
2267
+ * store.setValues({employees: 3, bug: []});
2268
+ * console.log(store.getValues());
2269
+ * // -> {employees: 3}
2270
+ *
2271
+ * store.setValues(42);
2272
+ * console.log(store.getValues());
2273
+ * // -> {employees: 3}
2274
+ * ```
2275
+ * @category Setter
2276
+ * @since v3.0.0
2277
+ */
2278
+ setValues(values: Values): Store;
2279
+
2280
+ /**
2281
+ * The setPartialValues method takes an object and sets its Values in the
2282
+ * Store, but leaving existing Values unaffected.
2283
+ *
2284
+ * This method will cause listeners to be called for any Values or Id changes
2285
+ * resulting from it.
2286
+ *
2287
+ * Any part of the provided object that is invalid (either according to the
2288
+ * Values type, or because, when combined with the current Values data, it
2289
+ * does not match a ValuesSchema associated with the Store), will be ignored
2290
+ * silently.
2291
+ *
2292
+ * Assuming that at least some of the provided Values object is valid, it will
2293
+ * be merged with the data that was already present in the Store. If the
2294
+ * object is completely invalid, no change will be made to the Store.
2295
+ *
2296
+ * The method returns a reference to the Store so that subsequent operations
2297
+ * can be chained in a fluent style.
2298
+ *
2299
+ * @param partialValues The Values to be set.
2300
+ * @returns A reference to the Store.
2301
+ * @example
2302
+ * This example sets some of the keyed value data in a Store.
2303
+ *
2304
+ * ```js
2305
+ * const store = createStore().setValues({open: true});
2306
+ * store.setPartialValues({employees: 3});
2307
+ * console.log(store.getValues());
2308
+ * // -> {open: true, employees: 3}
2309
+ * ```
2310
+ * @example
2311
+ * This example attempts to set some of the data of an existing Store with
2312
+ * partly invalid, and then completely invalid, Values objects.
2313
+ *
2314
+ * ```js
2315
+ * const store = createStore().setValues({open: true});
2316
+ *
2317
+ * store.setPartialValues({employees: 3, bug: []});
2318
+ * console.log(store.getValues());
2319
+ * // -> {open: true, employees: 3}
2320
+ *
2321
+ * store.setPartialValues(42);
2322
+ * console.log(store.getValues());
2323
+ * // -> {open: true, employees: 3}
2324
+ * ```
2325
+ * @category Setter
2326
+ * @since v3.0.0
2327
+ */
2328
+ setPartialValues(partialValues: Values): Store;
2329
+
2330
+ /**
2331
+ * The setValue method sets a single keyed Value in the Store.
2332
+ *
2333
+ * This method will cause listeners to be called for any Value, or Id changes
2334
+ * resulting from it.
2335
+ *
2336
+ * If the Value is invalid (either because of its type, or because it does not
2337
+ * match a ValuesSchema associated with the Store), will be ignored silently.
2338
+ *
2339
+ * As well as string, number, or boolean Value types, this method can also
2340
+ * take a MapValue function that takes the current Value as a parameter and
2341
+ * maps it. This is useful if you want to efficiently increment a value
2342
+ * without fetching it first, for example.
2343
+ *
2344
+ * The method returns a reference to the Store so that subsequent operations
2345
+ * can be chained in a fluent style.
2346
+ *
2347
+ * @param valueId The Id of the Value in the Store.
2348
+ * @param value The Value to be set, or a MapValue function to update it.
2349
+ * @returns A reference to the Store.
2350
+ * @example
2351
+ * This example sets a single Value.
2352
+ *
2353
+ * ```js
2354
+ * const store = createStore().setValue('open', true);
2355
+ * console.log(store.getValues());
2356
+ * // -> {open: true}
2357
+ * ```
2358
+ * @example
2359
+ * This example sets the data of a single Value by mapping the existing Value.
2360
+ *
2361
+ * ```js
2362
+ * const increment = (value) => value + 1;
2363
+ * const store = createStore().setValues({employees: 3});
2364
+ *
2365
+ * store.setValue('employees', increment);
2366
+ * console.log(store.getValue('employees'));
2367
+ * // -> 4
2368
+ * ```
2369
+ * @example
2370
+ * This example attempts to set an invalid Value.
2371
+ *
2372
+ * ```js
2373
+ * const store = createStore().setValues({employees: 3});
2374
+ *
2375
+ * store.setValue('bug', []);
2376
+ * console.log(store.getValues());
2377
+ * // -> {employees: 3}
2378
+ * ```
2379
+ * @category Setter
2380
+ * @since v3.0.0
2381
+ */
2382
+ setValue(valueId: Id, value: Value | MapValue): Store;
2383
+
2384
+ /**
2385
+ * The setTablesJson method takes a string serialization of all of the Tables
2386
+ * in the Store and attempts to update them to that.
1596
2387
  *
1597
2388
  * If the JSON cannot be parsed, this will fail silently. If it can be parsed,
1598
2389
  * it will then be subject to the same validation rules as the setTables
1599
- * method (according to the Tables type, and matching any Schema associated
1600
- * with the Store).
2390
+ * method (according to the Tables type, and matching any TablesSchema
2391
+ * associated with the Store).
1601
2392
  *
1602
- * @param json A string serialization of all of the Tables in the Store.
2393
+ * @param tablesJson A string serialization of all of the Tables in the Store.
1603
2394
  * @returns A reference to the Store.
1604
2395
  * @example
1605
- * This example sets the contents of a Store from a serialization.
2396
+ * This example sets the tabular contents of a Store from a serialization.
1606
2397
  *
1607
2398
  * ```js
1608
2399
  * const store = createStore();
1609
- * store.setJson('{"pets":{"fido":{"species":"dog"}}}');
2400
+ * store.setTablesJson('{"pets": {"fido": {"species": "dog"}}}');
1610
2401
  * console.log(store.getTables());
1611
2402
  * // -> {pets: {fido: {species: 'dog'}}}
1612
2403
  * ```
1613
2404
  * @example
1614
- * This example attempts to set the contents of a Store from an invalid
2405
+ * This example attempts to set the tabular contents of a Store from an
2406
+ * invalid serialization.
2407
+ *
2408
+ * ```js
2409
+ * const store = createStore();
2410
+ * store.setTablesJson('{"pets": {"fido": {');
2411
+ * console.log(store.getTables());
2412
+ * // -> {}
2413
+ * ```
2414
+ * @category Setter
2415
+ * @since v3.0.0
2416
+ */
2417
+ setTablesJson(tablesJson: Json): Store;
2418
+
2419
+ /**
2420
+ * The setValuesJson method takes a string serialization of all of the Values
2421
+ * in the Store and attempts to update them to those values.
2422
+ *
2423
+ * If the JSON cannot be parsed, this will fail silently. If it can be parsed,
2424
+ * it will then be subject to the same validation rules as the setValues
2425
+ * method (according to the Values type, and matching any ValuesSchema
2426
+ * associated with the Store).
2427
+ *
2428
+ * @param valuesJson A string serialization of all of the Values in the Store.
2429
+ * @returns A reference to the Store.
2430
+ * @example
2431
+ * This example sets the keyed value contents of a Store from a serialization.
2432
+ *
2433
+ * ```js
2434
+ * const store = createStore();
2435
+ * store.setValuesJson('{"open": true}');
2436
+ * console.log(store.getValues());
2437
+ * // -> {open: true}
2438
+ * ```
2439
+ * @example
2440
+ * This example attempts to set the keyed value contents of a Store from an
2441
+ * invalid serialization.
2442
+ *
2443
+ * ```js
2444
+ * const store = createStore();
2445
+ * store.setValuesJson('{"open": false');
2446
+ * console.log(store.getValues());
2447
+ * // -> {}
2448
+ * ```
2449
+ * @category Setter
2450
+ * @since v3.0.0
2451
+ */
2452
+ setValuesJson(valuesJson: Json): Store;
2453
+
2454
+ /**
2455
+ * The setJson method takes a string serialization of all of the Tables and
2456
+ * Values in the Store and attempts to update them to those values.
2457
+ *
2458
+ * From v3.0.0 onwards, the serialization should be of an array with two
2459
+ * entries. The first is the Tables object, the second the Values. In previous
2460
+ * versions (before the existence of the Values data structure), it was a sole
2461
+ * object of Tables. For backwards compatibility, if a serialization of a
2462
+ * single object is provided, it will be treated as the Tables type.
2463
+ *
2464
+ * If the JSON cannot be parsed, this will fail silently. If it can be parsed,
2465
+ * it will then be subject to the same validation rules as the setTables
2466
+ * method (according to the Tables type, and matching any TablesSchema
2467
+ * associated with the Store), and the setValues method (according to the
2468
+ * Values type, and matching any ValuesSchema associated with the Store).
2469
+ *
2470
+ * @param tablesAndValuesJson A string serialization of all of the Tables and
2471
+ * Values in the Store.
2472
+ * @returns A reference to the Store.
2473
+ * @example
2474
+ * This example sets the tabular and keyed value contents of a Store from a
1615
2475
  * serialization.
1616
2476
  *
1617
2477
  * ```js
1618
2478
  * const store = createStore();
1619
- * store.setJson('{"pets":{"fido":{');
2479
+ * store.setJson('[{"pets": {"fido": {"species": "dog"}}}, {"open": true}]');
1620
2480
  * console.log(store.getTables());
2481
+ * // -> {pets: {fido: {species: 'dog'}}}
2482
+ * console.log(store.getValues());
2483
+ * // -> {open: true}
2484
+ * ```
2485
+ * @example
2486
+ * This example sets the tabular contents of a Store from a
2487
+ * legacy single-object serialization (compatible with v2.x and earlier).
2488
+ *
2489
+ * ```js
2490
+ * const store = createStore();
2491
+ * store.setJson('{"pets": {"fido": {"species": "dog"}}}');
2492
+ * console.log(store.getTables());
2493
+ * // -> {pets: {fido: {species: 'dog'}}}
2494
+ * console.log(store.getValues());
2495
+ * // -> {}
2496
+ * ```
2497
+ * @example
2498
+ * This example attempts to set the the tabular and keyed value contents of a
2499
+ * Store from an invalid serialization.
2500
+ *
2501
+ * ```js
2502
+ * const store = createStore();
2503
+ * store.setValuesJson('[{"pets": {"fido": {"species": "do');
2504
+ * console.log(store.getTables());
2505
+ * // -> {}
2506
+ * console.log(store.getValues());
1621
2507
  * // -> {}
1622
2508
  * ```
1623
2509
  * @category Setter
1624
2510
  */
1625
- setJson(json: Json): Store;
2511
+ setJson(tablesAndValuesJson: Json): Store;
1626
2512
 
1627
2513
  /**
1628
- * The setSchema method lets you specify the Schema of the Store.
2514
+ * The setTablesSchema method lets you specify the TablesSchema of the tabular
2515
+ * part of the Store.
1629
2516
  *
1630
2517
  * Note that this may result in a change to data in the Store, as defaults are
1631
2518
  * applied or as invalid Table, Row, or Cell objects are removed. These
1632
2519
  * changes will fire any listeners to that data, as expected.
1633
2520
  *
1634
- * When no longer needed, you can also completely remove an existing Schema
1635
- * with the delSchema method.
2521
+ * When no longer needed, you can also completely remove an existing
2522
+ * TablesSchema with the delTablesSchema method.
1636
2523
  *
1637
- * @param schema The Schema to be set for the Store.
2524
+ * @param tablesSchema The TablesSchema to be set for the Store.
1638
2525
  * @returns A reference to the Store.
1639
2526
  * @example
1640
- * This example sets the Schema of a Store after it has been created.
2527
+ * This example sets the TablesSchema of a Store after it has been created.
2528
+ *
2529
+ * ```js
2530
+ * const store = createStore().setTablesSchema({
2531
+ * pets: {
2532
+ * species: {type: 'string'},
2533
+ * sold: {type: 'boolean', default: false},
2534
+ * },
2535
+ * });
2536
+ * store.addRow('pets', {species: 'dog', color: 'brown', sold: 'maybe'});
2537
+ *
2538
+ * console.log(store.getTables());
2539
+ * // -> {pets: {0: {species: 'dog', sold: false}}}
2540
+ * ```
2541
+ * @category Setter
2542
+ * @since v3.0.0
2543
+ */
2544
+ setTablesSchema(tablesSchema: TablesSchema): Store;
2545
+
2546
+ /**
2547
+ * The setValuesSchema method lets you specify the ValuesSchema of the keyed
2548
+ * Values part of the Store.
2549
+ *
2550
+ * Note that this may result in a change to data in the Store, as defaults are
2551
+ * applied or as invalid Values are removed. These changes will fire any
2552
+ * listeners to that data, as expected.
2553
+ *
2554
+ * When no longer needed, you can also completely remove an existing
2555
+ * ValuesSchema with the delValuesSchema method.
2556
+ *
2557
+ * @param valuesSchema The ValuesSchema to be set for the Store.
2558
+ * @returns A reference to the Store.
2559
+ * @example
2560
+ * This example sets the ValuesSchema of a Store after it has been created.
2561
+ *
2562
+ * ```js
2563
+ * const store = createStore().setValuesSchema({
2564
+ * open: {type: 'boolean', default: false},
2565
+ * });
2566
+ * store.setValue('open', 'maybe');
2567
+ *
2568
+ * console.log(store.getValues());
2569
+ * // -> {open: false}
2570
+ * ```
2571
+ * @category Setter
2572
+ * @since v3.0.0
2573
+ */
2574
+ setValuesSchema(valuesSchema: ValuesSchema): Store;
2575
+
2576
+ /**
2577
+ * The setSchema method lets you specify the TablesSchema and ValuesSchema of
2578
+ * the Store.
2579
+ *
2580
+ * Note that this may result in a change to data in the Store, as defaults are
2581
+ * applied or as invalid Table, Row, Cell, or Value objects are removed. These
2582
+ * changes will fire any listeners to that data, as expected.
2583
+ *
2584
+ * From v3.0.0 onwards, this method takes two arguments. The first is the
2585
+ * TablesSchema object, the second the ValuesSchema. In previous versions
2586
+ * (before the existence of the ValuesSchema data structure), only the first
2587
+ * was present. For backwards compatibility the new second parameter is
2588
+ * optional.
2589
+ *
2590
+ * @param tablesSchema The TablesSchema to be set for the Store.
2591
+ * @param valuesSchema The ValuesSchema to be set for the Store.
2592
+ * @returns A reference to the Store.
2593
+ * @example
2594
+ * This example sets the TablesSchema and ValuesSchema of a Store after it has
2595
+ * been created.
2596
+ *
2597
+ * ```js
2598
+ * const store = createStore().setSchema(
2599
+ * {
2600
+ * pets: {
2601
+ * species: {type: 'string'},
2602
+ * sold: {type: 'boolean', default: false},
2603
+ * },
2604
+ * },
2605
+ * {open: {type: 'boolean', default: false}},
2606
+ * );
2607
+ * store.addRow('pets', {species: 'dog', color: 'brown', sold: 'maybe'});
2608
+ * store.setValue('open', 'maybe');
2609
+ *
2610
+ * console.log(store.getTables());
2611
+ * // -> {pets: {0: {species: 'dog', sold: false}}}
2612
+ * console.log(store.getValues());
2613
+ * // -> {open: false}
2614
+ * ```
2615
+ * @example
2616
+ * This example sets just the TablesSchema of a Store after it has been
2617
+ * created.
1641
2618
  *
1642
2619
  * ```js
1643
2620
  * const store = createStore().setSchema({
@@ -1647,12 +2624,13 @@ export interface Store {
1647
2624
  * },
1648
2625
  * });
1649
2626
  * store.addRow('pets', {species: 'dog', color: 'brown', sold: 'maybe'});
2627
+ *
1650
2628
  * console.log(store.getTables());
1651
2629
  * // -> {pets: {0: {species: 'dog', sold: false}}}
1652
2630
  * ```
1653
2631
  * @category Setter
1654
2632
  */
1655
- setSchema(schema: Schema): Store;
2633
+ setSchema(tablesSchema: TablesSchema, valuesSchema?: ValuesSchema): Store;
1656
2634
 
1657
2635
  /**
1658
2636
  * The delTables method lets you remove all of the data in a Store.
@@ -1721,32 +2699,33 @@ export interface Store {
1721
2699
  /**
1722
2700
  * The delCell method lets you remove a single Cell from a Row.
1723
2701
  *
1724
- * When there is no Schema applied to the Store, then if this is the last Cell
1725
- * in its Row, then that Row will be removed. If, in turn, that is the last
1726
- * Row in its Table, then that Table will be removed.
2702
+ * When there is no TablesSchema applied to the Store, then if this is the
2703
+ * last Cell in its Row, then that Row will be removed. If, in turn, that is
2704
+ * the last Row in its Table, then that Table will be removed.
1727
2705
  *
1728
- * If there is a Schema applied to the Store and it specifies a default value
1729
- * for this Cell, then deletion will result in it being set back to its
2706
+ * If there is a TablesSchema applied to the Store and it specifies a default
2707
+ * value for this Cell, then deletion will result in it being set back to its
1730
2708
  * default value. To override this, use the `forceDel` parameter, as described
1731
2709
  * below.
1732
2710
  *
1733
2711
  * The `forceDel` parameter is an optional flag that is only relevant if a
1734
- * Schema provides a default value for this Cell. Under such circumstances,
1735
- * deleting a Cell value will normally restore it to the default value. If
1736
- * this flag is set to `true`, the complete removal of the Cell is instead
1737
- * guaranteed. But since doing do so would result in an invalid Row (according
1738
- * to the Schema), in fact the whole Row is deleted to retain the integrity of
1739
- * the Table. Therefore, this flag should be used with caution.
2712
+ * TablesSchema provides a default value for this Cell. Under such
2713
+ * circumstances, deleting a Cell value will normally restore it to the
2714
+ * default value. If this flag is set to `true`, the complete removal of the
2715
+ * Cell is instead guaranteed. But since doing do so would result in an
2716
+ * invalid Row (according to the TablesSchema), in fact the whole Row is
2717
+ * deleted to retain the integrity of the Table. Therefore, this flag should
2718
+ * be used with caution.
1740
2719
  *
1741
2720
  * @param tableId The Id of the Table in the Store.
1742
2721
  * @param rowId The Id of the Row in the Table.
1743
2722
  * @param cellId The Id of the Cell in the Row.
1744
2723
  * @param forceDel An optional flag to indicate that the whole Row should be
1745
- * deleted, even if a Schema provides a default value for this Cell. Defaults
1746
- * to `false`.
2724
+ * deleted, even if a TablesSchema provides a default value for this Cell.
2725
+ * Defaults to `false`.
1747
2726
  * @returns A reference to the Store.
1748
2727
  * @example
1749
- * This example removes a Cell from a Row without a Schema.
2728
+ * This example removes a Cell from a Row without a TablesSchema.
1750
2729
  *
1751
2730
  * ```js
1752
2731
  * const store = createStore().setTables({
@@ -1758,15 +2737,15 @@ export interface Store {
1758
2737
  * // -> {pets: {fido: {species: 'dog'}}}
1759
2738
  * ```
1760
2739
  * @example
1761
- * This example removes a Cell from a Row with a Schema that defaults its
1762
- * value.
2740
+ * This example removes a Cell from a Row with a TablesSchema that defaults
2741
+ * its value.
1763
2742
  *
1764
2743
  * ```js
1765
2744
  * const store = createStore()
1766
2745
  * .setTables({
1767
2746
  * pets: {fido: {species: 'dog', sold: true}},
1768
2747
  * })
1769
- * .setSchema({
2748
+ * .setTablesSchema({
1770
2749
  * pets: {
1771
2750
  * species: {type: 'string'},
1772
2751
  * sold: {type: 'boolean', default: false},
@@ -1778,15 +2757,15 @@ export interface Store {
1778
2757
  * // -> {pets: {fido: {species: 'dog', sold: false}}}
1779
2758
  * ```
1780
2759
  * @example
1781
- * This example removes a Cell from a Row with a Schema that defaults its
1782
- * value, but uses the `forceDel` parameter to override it.
2760
+ * This example removes a Cell from a Row with a TablesSchema that defaults
2761
+ * its value, but uses the `forceDel` parameter to override it.
1783
2762
  *
1784
2763
  * ```js
1785
2764
  * const store = createStore()
1786
2765
  * .setTables({
1787
2766
  * pets: {fido: {species: 'dog', sold: true}, felix: {species: 'cat'}},
1788
2767
  * })
1789
- * .setSchema({
2768
+ * .setTablesSchema({
1790
2769
  * pets: {
1791
2770
  * species: {type: 'string'},
1792
2771
  * sold: {type: 'boolean', default: false},
@@ -1802,21 +2781,122 @@ export interface Store {
1802
2781
  delCell(tableId: Id, rowId: Id, cellId: Id, forceDel?: boolean): Store;
1803
2782
 
1804
2783
  /**
1805
- * The delSchema method lets you remove the Schema of the Store.
2784
+ * The delValues method lets you remove all the Values from a Store.
2785
+ *
2786
+ * If there is a ValuesSchema applied to the Store and it specifies a default
2787
+ * value for any Value Id, then deletion will result in it being set back to
2788
+ * its default value.
1806
2789
  *
1807
2790
  * @returns A reference to the Store.
1808
2791
  * @example
1809
- * This example removes the Schema of a Store.
2792
+ * This example removes all Values from a Store without a ValuesSchema.
1810
2793
  *
1811
2794
  * ```js
1812
- * const store = createStore().setSchema({pets: {species: {type: 'string'}}});
1813
- * store.delSchema();
1814
- * console.log(store.getSchemaJson());
2795
+ * const store = createStore().setValues({open: true, employees: 3});
2796
+ * store.delValues();
2797
+ *
2798
+ * console.log(store.getValues());
2799
+ * // -> {}
2800
+ * ```
2801
+ * @example
2802
+ * This example removes all Values from a Store with a ValuesSchema that
2803
+ * defaults one of its values.
2804
+ *
2805
+ * ```js
2806
+ * const store = createStore()
2807
+ * .setValues({open: true, employees: 3})
2808
+ * .setValuesSchema({
2809
+ * open: {type: 'boolean', default: false},
2810
+ * employees: {type: 'number'},
2811
+ * });
2812
+ * store.delValues();
2813
+ *
2814
+ * console.log(store.getValues());
2815
+ * // -> {open: false}
2816
+ * ```
2817
+ * @category Deleter
2818
+ * @since v3.0.0
2819
+ */
2820
+ delValues(): Store;
2821
+
2822
+ /**
2823
+ * The delValue method lets you remove a single Value from a Store.
2824
+ *
2825
+ * If there is a ValuesSchema applied to the Store and it specifies a default
2826
+ * value for this Value Id, then deletion will result in it being set back to
2827
+ * its default value.
2828
+ *
2829
+ * @param valueId The Id of the Value in the Row.
2830
+ * @returns A reference to the Store.
2831
+ * @example
2832
+ * This example removes a Value from a Store without a ValuesSchema.
2833
+ *
2834
+ * ```js
2835
+ * const store = createStore().setValues({open: true, employees: 3});
2836
+ * store.delValue('employees');
2837
+ *
2838
+ * console.log(store.getValues());
2839
+ * // -> {open: true}
2840
+ * ```
2841
+ * @example
2842
+ * This example removes a Value from a Store with a ValuesSchema that defaults
2843
+ * its value.
2844
+ *
2845
+ * ```js
2846
+ * const store = createStore()
2847
+ * .setValues({open: true, employees: 3})
2848
+ * .setValuesSchema({
2849
+ * open: {type: 'boolean', default: false},
2850
+ * employees: {type: 'number'},
2851
+ * });
2852
+ * store.delValue('open');
2853
+ *
2854
+ * console.log(store.getValues());
2855
+ * // -> {open: false, employees: 3}
2856
+ * ```
2857
+ * @category Deleter
2858
+ * @since v3.0.0
2859
+ */
2860
+ delValue(valueId: Id): Store;
2861
+
2862
+ /**
2863
+ * The delTablesSchema method lets you remove the TablesSchema of the Store.
2864
+ *
2865
+ * @returns A reference to the Store.
2866
+ * @example
2867
+ * This example removes the TablesSchema of a Store.
2868
+ *
2869
+ * ```js
2870
+ * const store = createStore().setTablesSchema({
2871
+ * pets: {species: {type: 'string'}},
2872
+ * });
2873
+ * store.delTablesSchema();
2874
+ * console.log(store.getTablesSchemaJson());
1815
2875
  * // -> '{}'
1816
2876
  * ```
1817
2877
  * @category Deleter
1818
2878
  */
1819
- delSchema(): Store;
2879
+ delTablesSchema(): Store;
2880
+
2881
+ /**
2882
+ * The delValuesSchema method lets you remove the ValuesSchema of the Store.
2883
+ *
2884
+ * @returns A reference to the Store.
2885
+ * @example
2886
+ * This example removes the ValuesSchema of a Store.
2887
+ *
2888
+ * ```js
2889
+ * const store = createStore().setValuesSchema({
2890
+ * sold: {type: 'boolean', default: false},
2891
+ * });
2892
+ * store.delValuesSchema();
2893
+ * console.log(store.getValuesSchemaJson());
2894
+ * // -> '{}'
2895
+ * ```
2896
+ * @category Deleter
2897
+ * @since v3.0.0
2898
+ */
2899
+ delValuesSchema(): Store;
1820
2900
 
1821
2901
  /**
1822
2902
  * The transaction method takes a function that makes multiple mutations to
@@ -1840,11 +2920,12 @@ export interface Store {
1840
2920
  * Transactions can be nested. Relevant listeners will be called only when the
1841
2921
  * outermost one completes.
1842
2922
  *
1843
- * The second, optional parameter, `doRollback` is a callback that you can use
1844
- * to rollback the transaction if it did not complete to your satisfaction. It
1845
- * is called with `changedCells` and `invalidCells` parameters, which inform
1846
- * you of the net changes that have been made during the transaction, and any
1847
- * invalid attempts to do so, respectively.
2923
+ * The second, optional parameter, `doRollback` is a DoRollback callback that
2924
+ * you can use to rollback the transaction if it did not complete to your
2925
+ * satisfaction. It is called with `changedCells`, `invalidCells`,
2926
+ * `changedValues`, and `invalidValues` parameters, which inform you of the
2927
+ * net changes that have been made during the transaction, and any invalid
2928
+ * attempts to do so, respectively.
1848
2929
  *
1849
2930
  * @param actions The function to be executed as a transaction.
1850
2931
  * @param doRollback An optional callback that should return `true` if you
@@ -1859,15 +2940,17 @@ export interface Store {
1859
2940
  * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1860
2941
  * store.addRowListener('pets', 'fido', () => console.log('Fido changed'));
1861
2942
  *
1862
- * store.setCell('pets', 'fido', 'color', 'brown');
1863
- * store.setCell('pets', 'fido', 'sold', false);
2943
+ * store
2944
+ * .setCell('pets', 'fido', 'color', 'brown')
2945
+ * .setCell('pets', 'fido', 'sold', false);
1864
2946
  * // -> 'Fido changed'
1865
2947
  * // -> 'Fido changed'
1866
2948
  *
1867
- * store.transaction(() => {
1868
- * store.setCell('pets', 'fido', 'color', 'walnut');
1869
- * store.setCell('pets', 'fido', 'sold', true);
1870
- * });
2949
+ * store.transaction(() =>
2950
+ * store
2951
+ * .setCell('pets', 'fido', 'color', 'walnut')
2952
+ * .setCell('pets', 'fido', 'sold', true),
2953
+ * );
1871
2954
  * // -> 'Fido changed'
1872
2955
  * ```
1873
2956
  * @example
@@ -1884,60 +2967,64 @@ export interface Store {
1884
2967
  * (store, tableId, rowId, cellId, newCell) => console.log(newCell),
1885
2968
  * );
1886
2969
  *
1887
- * store.transaction(() => {
1888
- * store.setCell('pets', 'fido', 'color', 'black');
1889
- * store.setCell('pets', 'fido', 'color', 'brown');
1890
- * store.setCell('pets', 'fido', 'color', 'walnut');
1891
- * });
2970
+ * store.transaction(() =>
2971
+ * store
2972
+ * .setCell('pets', 'fido', 'color', 'black')
2973
+ * .setCell('pets', 'fido', 'color', 'brown')
2974
+ * .setCell('pets', 'fido', 'color', 'walnut'),
2975
+ * );
1892
2976
  * // -> 'walnut'
1893
2977
  *
1894
- * store.transaction(() => {
1895
- * store.setCell('pets', 'fido', 'color', 'black');
1896
- * store.setCell('pets', 'fido', 'color', 'walnut');
1897
- * });
2978
+ * store.transaction(() =>
2979
+ * store
2980
+ * .setCell('pets', 'fido', 'color', 'black')
2981
+ * .setCell('pets', 'fido', 'color', 'walnut'),
2982
+ * );
1898
2983
  * // -> undefined
1899
2984
  * // No net change during the transaction, so the listener is not called.
1900
2985
  * ```
1901
- * @example
1902
- * This example makes multiple changes to the Store, including some attempts
1903
- * to update a Cell with invalid values. The `doRollback` callback receives
1904
- * information about the changes and invalid attempts, and then judges that
1905
- * the transaction should be rolled back to its original state.
2986
+ * @example
2987
+ * This example makes multiple changes to the Store, including some attempts
2988
+ * to update a Cell and Value with invalid values. The `doRollback` callback
2989
+ * receives information about the changes and invalid attempts, and then
2990
+ * judges that the transaction should be rolled back to its original state.
1906
2991
  *
1907
2992
  * ```js
1908
- * const store = createStore().setTables({
1909
- * pets: {fido: {species: 'dog', color: 'brown'}},
1910
- * });
2993
+ * const store = createStore()
2994
+ * .setTables({pets: {fido: {species: 'dog', color: 'brown'}}})
2995
+ * .setValues({open: true});
1911
2996
  *
1912
2997
  * store.transaction(
1913
- * () => {
1914
- * store.setCell('pets', 'fido', 'color', 'black');
1915
- * store.setCell('pets', 'fido', 'eyes', ['left', 'right']);
1916
- * store.setCell('pets', 'fido', 'info', {sold: null});
1917
- * },
1918
- * (changedCells, invalidCells) => {
2998
+ * () =>
2999
+ * store
3000
+ * .setCell('pets', 'fido', 'color', 'black')
3001
+ * .setCell('pets', 'fido', 'eyes', ['left', 'right'])
3002
+ * .setCell('pets', 'fido', 'info', {sold: null})
3003
+ * .setValue('open', false)
3004
+ * .setValue('employees', ['alice', 'bob']),
3005
+ * (changedCells, invalidCells, changedValues, invalidValues) => {
1919
3006
  * console.log(store.getTables());
1920
- * // -> {pets: {fido: {species: 'dog', color: 'black'}}}
1921
3007
  * console.log(changedCells);
1922
- * // -> {pets: {fido: {color: ['brown', 'black']}}}
1923
3008
  * console.log(invalidCells);
1924
- * // -> {pets: {fido: {eyes: [['left', 'right']], info: [{sold: null}]}}}
3009
+ * console.log(changedValues);
3010
+ * console.log(invalidValues);
1925
3011
  * return invalidCells['pets'] != null;
1926
3012
  * },
1927
3013
  * );
3014
+ * // -> {pets: {fido: {species: 'dog', color: 'black'}}}
3015
+ * // -> {pets: {fido: {color: ['brown', 'black']}}}
3016
+ * // -> {pets: {fido: {eyes: [['left', 'right']], info: [{sold: null}]}}}
3017
+ * // -> {open: [true, false]}
3018
+ * // -> {employees: [['alice', 'bob']]}
1928
3019
  *
1929
3020
  * console.log(store.getTables());
1930
3021
  * // -> {pets: {fido: {species: 'dog', color: 'brown'}}}
3022
+ * console.log(store.getValues());
3023
+ * // -> {open: true}
1931
3024
  * ```
1932
3025
  * @category Transaction
1933
3026
  */
1934
- transaction<Return>(
1935
- actions: () => Return,
1936
- doRollback?: (
1937
- changedCells: ChangedCells,
1938
- invalidCells: InvalidCells,
1939
- ) => boolean,
1940
- ): Return;
3027
+ transaction<Return>(actions: () => Return, doRollback?: DoRollback): Return;
1941
3028
 
1942
3029
  /**
1943
3030
  * The startTransaction method allows you to explicitly start a transaction
@@ -1972,15 +3059,17 @@ export interface Store {
1972
3059
  * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
1973
3060
  * store.addRowListener('pets', 'fido', () => console.log('Fido changed'));
1974
3061
  *
1975
- * store.setCell('pets', 'fido', 'color', 'brown');
1976
- * store.setCell('pets', 'fido', 'sold', false);
3062
+ * store
3063
+ * .setCell('pets', 'fido', 'color', 'brown')
3064
+ * .setCell('pets', 'fido', 'sold', false);
1977
3065
  * // -> 'Fido changed'
1978
3066
  * // -> 'Fido changed'
1979
3067
  *
1980
- * store.startTransaction();
1981
- * store.setCell('pets', 'fido', 'color', 'walnut');
1982
- * store.setCell('pets', 'fido', 'sold', true);
1983
- * store.finishTransaction();
3068
+ * store
3069
+ * .startTransaction()
3070
+ * .setCell('pets', 'fido', 'color', 'walnut')
3071
+ * .setCell('pets', 'fido', 'sold', true)
3072
+ * .finishTransaction();
1984
3073
  * // -> 'Fido changed'
1985
3074
  * ```
1986
3075
  * @category Transaction
@@ -2010,6 +3099,13 @@ export interface Store {
2010
3099
  * been a corresponding startTransaction method that this completes, of
2011
3100
  * course, otherwise this function has no effect.
2012
3101
  *
3102
+ * The optional parameter, `doRollback` is a DoRollback callback that
3103
+ * you can use to rollback the transaction if it did not complete to your
3104
+ * satisfaction. It is called with `changedCells`, `invalidCells`,
3105
+ * `changedValues`, and `invalidValues` parameters, which inform you of the
3106
+ * net changes that have been made during the transaction, and any invalid
3107
+ * attempts to do so, respectively.
3108
+ *
2013
3109
  * @param doRollback An optional callback that should return `true` if you
2014
3110
  * want to rollback the transaction at the end.
2015
3111
  * @returns A reference to the Store.
@@ -2022,15 +3118,17 @@ export interface Store {
2022
3118
  * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
2023
3119
  * store.addRowListener('pets', 'fido', () => console.log('Fido changed'));
2024
3120
  *
2025
- * store.setCell('pets', 'fido', 'color', 'brown');
2026
- * store.setCell('pets', 'fido', 'sold', false);
3121
+ * store
3122
+ * .setCell('pets', 'fido', 'color', 'brown')
3123
+ * .setCell('pets', 'fido', 'sold', false);
2027
3124
  * // -> 'Fido changed'
2028
3125
  * // -> 'Fido changed'
2029
3126
  *
2030
- * store.startTransaction();
2031
- * store.setCell('pets', 'fido', 'color', 'walnut');
2032
- * store.setCell('pets', 'fido', 'sold', true);
2033
- * store.finishTransaction();
3127
+ * store
3128
+ * .startTransaction()
3129
+ * .setCell('pets', 'fido', 'color', 'walnut')
3130
+ * .setCell('pets', 'fido', 'sold', true)
3131
+ * .finishTransaction();
2034
3132
  * // -> 'Fido changed'
2035
3133
  * ```
2036
3134
  * @example
@@ -2040,36 +3138,42 @@ export interface Store {
2040
3138
  * the transaction should be rolled back to its original state.
2041
3139
  *
2042
3140
  * ```js
2043
- * const store = createStore().setTables({
2044
- * pets: {fido: {species: 'dog', color: 'brown'}},
2045
- * });
2046
- *
2047
- * store.startTransaction();
2048
- * store.setCell('pets', 'fido', 'color', 'black');
2049
- * store.setCell('pets', 'fido', 'eyes', ['left', 'right']);
2050
- * store.setCell('pets', 'fido', 'info', {sold: null});
2051
- * store.finishTransaction((changedCells, invalidCells) => {
2052
- * console.log(store.getTables());
2053
- * // -> {pets: {fido: {species: 'dog', color: 'black'}}}
2054
- * console.log(changedCells);
2055
- * // -> {pets: {fido: {color: ['brown', 'black']}}}
2056
- * console.log(invalidCells);
2057
- * // -> {pets: {fido: {eyes: [['left', 'right']], info: [{sold: null}]}}}
2058
- * return invalidCells['pets'] != null;
2059
- * });
3141
+ * const store = createStore()
3142
+ * .setTables({pets: {fido: {species: 'dog', color: 'brown'}}})
3143
+ * .setValues({open: true});
3144
+ *
3145
+ * store
3146
+ * .startTransaction()
3147
+ * .setCell('pets', 'fido', 'color', 'black')
3148
+ * .setCell('pets', 'fido', 'eyes', ['left', 'right'])
3149
+ * .setCell('pets', 'fido', 'info', {sold: null})
3150
+ * .setValue('open', false)
3151
+ * .setValue('employees', ['alice', 'bob'])
3152
+ * .finishTransaction(
3153
+ * (changedCells, invalidCells, changedValues, invalidValues) => {
3154
+ * console.log(store.getTables());
3155
+ * console.log(changedCells);
3156
+ * console.log(invalidCells);
3157
+ * console.log(changedValues);
3158
+ * console.log(invalidValues);
3159
+ * return invalidCells['pets'] != null;
3160
+ * },
3161
+ * );
3162
+ * // -> {pets: {fido: {species: 'dog', color: 'black'}}}
3163
+ * // -> {pets: {fido: {color: ['brown', 'black']}}}
3164
+ * // -> {pets: {fido: {eyes: [['left', 'right']], info: [{sold: null}]}}}
3165
+ * // -> {open: [true, false]}
3166
+ * // -> {employees: [['alice', 'bob']]}
2060
3167
  *
2061
3168
  * console.log(store.getTables());
2062
3169
  * // -> {pets: {fido: {species: 'dog', color: 'brown'}}}
3170
+ * console.log(store.getValues());
3171
+ * // -> {open: true}
2063
3172
  * ```
2064
3173
  * @category Transaction
2065
3174
  * @since v1.3.0
2066
3175
  */
2067
- finishTransaction(
2068
- doRollback?: (
2069
- changedCells: ChangedCells,
2070
- invalidCells: InvalidCells,
2071
- ) => boolean,
2072
- ): Store;
3176
+ finishTransaction(doRollback?: DoRollback): Store;
2073
3177
 
2074
3178
  /**
2075
3179
  * The forEachTable method takes a function that it will then call for each
@@ -2167,6 +3271,31 @@ export interface Store {
2167
3271
  */
2168
3272
  forEachCell(tableId: Id, rowId: Id, cellCallback: CellCallback): void;
2169
3273
 
3274
+ /**
3275
+ * The forEachValue method takes a function that it will then call for each
3276
+ * Value in a Store.
3277
+ *
3278
+ * This method is useful for iterating over the Value structure of the Store
3279
+ * in a functional style. The `valueCallback` parameter is a ValueCallback
3280
+ * function that will be called with the Id and value of each Value.
3281
+ *
3282
+ * @param valueCallback The function that should be called for every Value.
3283
+ * @example
3284
+ * This example iterates over each Value in a Store, and lists its value.
3285
+ *
3286
+ * ```js
3287
+ * const store = createStore().setValues({open: true, employees: 3});
3288
+ * store.forEachValue((valueId, value) => {
3289
+ * console.log(`${valueId}: ${value}`);
3290
+ * });
3291
+ * // -> 'open: true'
3292
+ * // -> 'employees: 3'
3293
+ * ```
3294
+ * @category Iterator
3295
+ * @since v3.0.0
3296
+ */
3297
+ forEachValue(valueCallback: ValueCallback): void;
3298
+
2170
3299
  /**
2171
3300
  * The addTablesListener method registers a listener function with the Store
2172
3301
  * that will be called whenever data in the Store changes.
@@ -2873,76 +4002,314 @@ export interface Store {
2873
4002
  * store.delListener(listenerId);
2874
4003
  * ```
2875
4004
  * @example
2876
- * This example registers a listener that responds to any change to the Cell
2877
- * Ids of any Row.
4005
+ * This example registers a listener that responds to any change to the Cell
4006
+ * Ids of any Row.
4007
+ *
4008
+ * ```js
4009
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
4010
+ * const listenerId = store.addCellIdsListener(
4011
+ * null,
4012
+ * null,
4013
+ * (store, tableId, rowId) => {
4014
+ * console.log(`Cell Ids for ${rowId} row in ${tableId} table changed`);
4015
+ * console.log(store.getCellIds(tableId, rowId));
4016
+ * },
4017
+ * );
4018
+ *
4019
+ * store.setCell('pets', 'fido', 'color', 'brown');
4020
+ * // -> 'Cell Ids for fido row in pets table changed'
4021
+ * // -> ['species', 'color']
4022
+ * store.setCell('species', 'dog', 'price', 5);
4023
+ * // -> 'Cell Ids for dog row in species table changed'
4024
+ * // -> ['price']
4025
+ *
4026
+ * store.delListener(listenerId);
4027
+ * ```
4028
+ * @example
4029
+ * This example registers a listener that responds to any change to the Cell
4030
+ * Ids of a specific Row, and which also mutates the Store itself.
4031
+ *
4032
+ * ```js
4033
+ * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
4034
+ * const listenerId = store.addCellIdsListener(
4035
+ * 'pets',
4036
+ * 'fido',
4037
+ * (store, tableId, rowId) =>
4038
+ * store.setCell('meta', 'update', `${tableId}_${rowId}`, true),
4039
+ * true, // mutator
4040
+ * );
4041
+ *
4042
+ * store.setCell('pets', 'fido', 'color', 'brown');
4043
+ * console.log(store.getTable('meta'));
4044
+ * // -> {update: {pets_fido: true}}
4045
+ *
4046
+ * store.delListener(listenerId);
4047
+ * ```
4048
+ * @category Listener
4049
+ */
4050
+ addCellIdsListener(
4051
+ tableId: IdOrNull,
4052
+ rowId: IdOrNull,
4053
+ listener: CellIdsListener,
4054
+ mutator?: boolean,
4055
+ ): Id;
4056
+
4057
+ /**
4058
+ * The addCellListener method registers a listener function with the Store
4059
+ * that will be called whenever data in a Cell changes.
4060
+ *
4061
+ * The provided listener is a CellListener function, and will be called with a
4062
+ * reference to the Store, the Id of the Table that changed, the Id of the Row
4063
+ * that changed, the Id of the Cell that changed, the new Cell value, the old
4064
+ * Cell value, and a GetCellChange function in case you need to inspect any
4065
+ * changes that occurred.
4066
+ *
4067
+ * You can either listen to a single Cell (by specifying the Table Id, Row Id,
4068
+ * and Cell Id as the method's first three parameters) or changes to any Cell
4069
+ * (by providing `null` wildcards).
4070
+ *
4071
+ * All, some, or none of the `tableId`, `rowId`, and `cellId` parameters can
4072
+ * be wildcarded with `null`. You can listen to a specific Cell in a specific
4073
+ * Row in a specific Table, any Cell in any Row in any Table, for example - or
4074
+ * every other combination of wildcards.
4075
+ *
4076
+ * Use the optional mutator parameter to indicate that there is code in the
4077
+ * listener that will mutate Store data. If set to `false` (or omitted), such
4078
+ * mutations will be silently ignored. All relevant mutator listeners (with
4079
+ * this flag set to `true`) are called _before_ any non-mutator listeners
4080
+ * (since the latter may become relevant due to changes made in the former).
4081
+ * The changes made by mutator listeners do not fire other mutating listeners,
4082
+ * though they will fire non-mutator listeners.
4083
+ *
4084
+ * @param tableId The Id of the Table to listen to, or `null` as a wildcard.
4085
+ * @param rowId The Id of the Row to listen to, or `null` as a wildcard.
4086
+ * @param cellId The Id of the Cell to listen to, or `null` as a wildcard.
4087
+ * @param listener The function that will be called whenever data in the
4088
+ * matching Cell changes.
4089
+ * @param mutator An optional boolean that indicates that the listener mutates
4090
+ * Store data.
4091
+ * @returns A unique Id for the listener that can later be used to call it
4092
+ * explicitly, or to remove it.
4093
+ * @example
4094
+ * This example registers a listener that responds to any changes to a
4095
+ * specific Cell.
4096
+ *
4097
+ * ```js
4098
+ * const store = createStore().setTables({
4099
+ * pets: {fido: {species: 'dog', color: 'brown'}},
4100
+ * });
4101
+ * const listenerId = store.addCellListener(
4102
+ * 'pets',
4103
+ * 'fido',
4104
+ * 'color',
4105
+ * (store, tableId, rowId, cellId, newCell, oldCell, getCellChange) => {
4106
+ * console.log('color cell in fido row in pets table changed');
4107
+ * console.log([oldCell, newCell]);
4108
+ * console.log(getCellChange('pets', 'fido', 'color'));
4109
+ * },
4110
+ * );
4111
+ *
4112
+ * store.setCell('pets', 'fido', 'color', 'walnut');
4113
+ * // -> 'color cell in fido row in pets table changed'
4114
+ * // -> ['brown', 'walnut']
4115
+ * // -> [true, 'brown', 'walnut']
4116
+ *
4117
+ * store.delListener(listenerId);
4118
+ * ```
4119
+ * @example
4120
+ * This example registers a listener that responds to any changes to any Cell.
4121
+ *
4122
+ * ```js
4123
+ * const store = createStore().setTables({
4124
+ * pets: {fido: {species: 'dog', color: 'brown'}},
4125
+ * });
4126
+ * const listenerId = store.addCellListener(
4127
+ * null,
4128
+ * null,
4129
+ * null,
4130
+ * (store, tableId, rowId, cellId) => {
4131
+ * console.log(
4132
+ * `${cellId} cell in ${rowId} row in ${tableId} table changed`,
4133
+ * );
4134
+ * },
4135
+ * );
4136
+ *
4137
+ * store.setCell('pets', 'fido', 'color', 'walnut');
4138
+ * // -> 'color cell in fido row in pets table changed'
4139
+ * store.setTable('species', {dog: {price: 5}});
4140
+ * // -> 'price cell in dog row in species table changed'
4141
+ *
4142
+ * store.delListener(listenerId);
4143
+ * ```
4144
+ * @example
4145
+ * This example registers a listener that responds to any changes to a
4146
+ * specific Cell, and which also mutates the Store itself.
4147
+ *
4148
+ * ```js
4149
+ * const store = createStore().setTables({
4150
+ * pets: {fido: {species: 'dog', color: 'brown'}},
4151
+ * });
4152
+ * const listenerId = store.addCellListener(
4153
+ * 'pets',
4154
+ * 'fido',
4155
+ * 'color',
4156
+ * (store, tableId, rowId, cellId) =>
4157
+ * store.setCell('meta', 'update', `${tableId}_${rowId}_${cellId}`, true),
4158
+ * true,
4159
+ * );
4160
+ *
4161
+ * store.delCell('pets', 'fido', 'color');
4162
+ * console.log(store.getTable('meta'));
4163
+ * // -> {update: {pets_fido_color: true}}
4164
+ *
4165
+ * store.delListener(listenerId);
4166
+ * ```
4167
+ * @category Listener
4168
+ */
4169
+ addCellListener(
4170
+ tableId: IdOrNull,
4171
+ rowId: IdOrNull,
4172
+ cellId: IdOrNull,
4173
+ listener: CellListener,
4174
+ mutator?: boolean,
4175
+ ): Id;
4176
+
4177
+ /**
4178
+ * The addValuesListener method registers a listener function with the Store
4179
+ * that will be called whenever the Values change.
4180
+ *
4181
+ * The provided listener is a ValuesListener function, and will be called with
4182
+ * a reference to the Store and a GetValueChange function in case you need to
4183
+ * inspect any changes that occurred.
4184
+ *
4185
+ * Use the optional mutator parameter to indicate that there is code in the
4186
+ * listener that will mutate Store data. If set to `false` (or omitted), such
4187
+ * mutations will be silently ignored. All relevant mutator listeners (with
4188
+ * this flag set to `true`) are called _before_ any non-mutator listeners
4189
+ * (since the latter may become relevant due to changes made in the former).
4190
+ * The changes made by mutator listeners do not fire other mutating listeners,
4191
+ * though they will fire non-mutator listeners.
4192
+ *
4193
+ * @param listener The function that will be called whenever data in the
4194
+ * Values changes.
4195
+ * @param mutator An optional boolean that indicates that the listener mutates
4196
+ * Store data.
4197
+ * @returns A unique Id for the listener that can later be used to call it
4198
+ * explicitly, or to remove it.
4199
+ * @example
4200
+ * This example registers a listener that responds to any changes to the
4201
+ * Store's Values.
4202
+ *
4203
+ * ```js
4204
+ * const store = createStore().setValues({open: true, employees: 3});
4205
+ * const listenerId = store.addValuesListener((store, getValueChange) => {
4206
+ * console.log('values changed');
4207
+ * console.log(getValueChange('employees'));
4208
+ * });
4209
+ *
4210
+ * store.setValue('employees', 4);
4211
+ * // -> 'values changed'
4212
+ * // -> [true, 3, 4]
4213
+ *
4214
+ * store.delListener(listenerId);
4215
+ * ```
4216
+ * @example
4217
+ * This example registers a listener that responds to any changes to the
4218
+ * Store's Values, and which also mutates the Store itself.
4219
+ *
4220
+ * ```js
4221
+ * const store = createStore().setValues({open: true, employees: 3});
4222
+ * const listenerId = store.addValuesListener(
4223
+ * (store, getValueChange) => store.setValue('updated', true),
4224
+ * true,
4225
+ * );
4226
+ *
4227
+ * store.setValue('employees', 4);
4228
+ * console.log(store.getValues());
4229
+ * // -> {open: true, employees: 4, updated: true}
4230
+ *
4231
+ * store.delListener(listenerId);
4232
+ * ```
4233
+ * @category Listener
4234
+ * @since v3.0.0
4235
+ */
4236
+ addValuesListener(listener: ValuesListener, mutator?: boolean): Id;
4237
+
4238
+ /**
4239
+ * The addValueIdsListener method registers a listener function with the Store
4240
+ * that will be called whenever the Value Ids in a Store change.
4241
+ *
4242
+ * The provided listener is a ValueIdsListener function, and will be called
4243
+ * with a reference to the Store.
4244
+ *
4245
+ * By default, such a listener is only called when a Value is added or
4246
+ * removed. To listen to all changes in the Values, use the addValuesListener
4247
+ * method.
4248
+ *
4249
+ * Use the optional mutator parameter to indicate that there is code in the
4250
+ * listener that will mutate Store data. If set to `false` (or omitted), such
4251
+ * mutations will be silently ignored. All relevant mutator listeners (with
4252
+ * this flag set to `true`) are called _before_ any non-mutator listeners
4253
+ * (since the latter may become relevant due to changes made in the former).
4254
+ * The changes made by mutator listeners do not fire other mutating listeners,
4255
+ * though they will fire non-mutator listeners.
4256
+ *
4257
+ * @param listener The function that will be called whenever the Value Ids in
4258
+ * the Store change.
4259
+ * @param mutator An optional boolean that indicates that the listener mutates
4260
+ * Store data.
4261
+ * @returns A unique Id for the listener that can later be used to call it
4262
+ * explicitly, or to remove it.
4263
+ * @example
4264
+ * This example registers a listener that responds to any change to the Value
4265
+ * Ids.
2878
4266
  *
2879
4267
  * ```js
2880
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
2881
- * const listenerId = store.addCellIdsListener(
2882
- * null,
2883
- * null,
2884
- * (store, tableId, rowId) => {
2885
- * console.log(`Cell Ids for ${rowId} row in ${tableId} table changed`);
2886
- * console.log(store.getCellIds(tableId, rowId));
2887
- * },
2888
- * );
4268
+ * const store = createStore().setValues({open: true});
4269
+ * const listenerId = store.addValueIdsListener((store) => {
4270
+ * console.log('Value Ids changed');
4271
+ * console.log(store.getValueIds());
4272
+ * });
2889
4273
  *
2890
- * store.setCell('pets', 'fido', 'color', 'brown');
2891
- * // -> 'Cell Ids for fido row in pets table changed'
2892
- * // -> ['species', 'color']
2893
- * store.setCell('species', 'dog', 'price', 5);
2894
- * // -> 'Cell Ids for dog row in species table changed'
2895
- * // -> ['price']
4274
+ * store.setValue('employees', 3);
4275
+ * // -> 'Value Ids changed'
4276
+ * // -> ['open', 'employees']
2896
4277
  *
2897
4278
  * store.delListener(listenerId);
2898
4279
  * ```
2899
4280
  * @example
2900
- * This example registers a listener that responds to any change to the Cell
2901
- * Ids of a specific Row, and which also mutates the Store itself.
4281
+ * This example registers a listener that responds to any change to the Value
4282
+ * Ids, and which also mutates the Store itself.
2902
4283
  *
2903
4284
  * ```js
2904
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
2905
- * const listenerId = store.addCellIdsListener(
2906
- * 'pets',
2907
- * 'fido',
2908
- * (store, tableId, rowId) =>
2909
- * store.setCell('meta', 'update', `${tableId}_${rowId}`, true),
4285
+ * const store = createStore().setValues({open: true});
4286
+ * const listenerId = store.addValueIdsListener(
4287
+ * (store) => store.setValue('updated', true),
2910
4288
  * true, // mutator
2911
4289
  * );
2912
4290
  *
2913
- * store.setCell('pets', 'fido', 'color', 'brown');
2914
- * console.log(store.getTable('meta'));
2915
- * // -> {update: {pets_fido: true}}
4291
+ * store.setValue('employees', 3);
4292
+ * console.log(store.getValues());
4293
+ * // -> {open: true, employees: 3, updated: true}
2916
4294
  *
2917
4295
  * store.delListener(listenerId);
2918
4296
  * ```
2919
4297
  * @category Listener
4298
+ * @since v3.0.0
2920
4299
  */
2921
- addCellIdsListener(
2922
- tableId: IdOrNull,
2923
- rowId: IdOrNull,
2924
- listener: CellIdsListener,
2925
- mutator?: boolean,
2926
- ): Id;
4300
+ addValueIdsListener(listener: ValueIdsListener, mutator?: boolean): Id;
2927
4301
 
2928
4302
  /**
2929
- * The addCellListener method registers a listener function with the Store
2930
- * that will be called whenever data in a Cell changes.
2931
- *
2932
- * The provided listener is a CellListener function, and will be called with a
2933
- * reference to the Store, the Id of the Table that changed, the Id of the Row
2934
- * that changed, the Id of the Cell that changed, the new Cell value, the old
2935
- * Cell value, and a GetCellChange function in case you need to inspect any
2936
- * changes that occurred.
4303
+ * The addValueListener method registers a listener function with the Store
4304
+ * that will be called whenever data in a Value changes.
2937
4305
  *
2938
- * You can either listen to a single Cell (by specifying the Table Id, Row Id,
2939
- * and Cell Id as the method's first three parameters) or changes to any Cell
2940
- * (by providing `null` wildcards).
4306
+ * The provided listener is a ValueListener function, and will be called with
4307
+ * a reference to the Store, the Id of the Value that changed, the new Value
4308
+ * value, the old Value, and a GetValueChange function in case you need to
4309
+ * inspect any changes that occurred.
2941
4310
  *
2942
- * All, some, or none of the `tableId`, `rowId`, and `cellId` parameters can
2943
- * be wildcarded with `null`. You can listen to a specific Cell in a specific
2944
- * Row in a specific Table, any Cell in any Row in any Table, for example - or
2945
- * every other combination of wildcards.
4311
+ * You can either listen to a single Value (by specifying the Value Id) or
4312
+ * changes to any Value (by providing a `null` wildcard).
2946
4313
  *
2947
4314
  * Use the optional mutator parameter to indicate that there is code in the
2948
4315
  * listener that will mutate Store data. If set to `false` (or omitted), such
@@ -2952,95 +4319,75 @@ export interface Store {
2952
4319
  * The changes made by mutator listeners do not fire other mutating listeners,
2953
4320
  * though they will fire non-mutator listeners.
2954
4321
  *
2955
- * @param tableId The Id of the Table to listen to, or `null` as a wildcard.
2956
- * @param rowId The Id of the Row to listen to, or `null` as a wildcard.
2957
- * @param cellId The Id of the Cell to listen to, or `null` as a wildcard.
4322
+ * @param valueId The Id of the Value to listen to, or `null` as a wildcard.
2958
4323
  * @param listener The function that will be called whenever data in the
2959
- * matching Cell changes.
4324
+ * matching Value changes.
2960
4325
  * @param mutator An optional boolean that indicates that the listener mutates
2961
4326
  * Store data.
2962
4327
  * @returns A unique Id for the listener that can later be used to call it
2963
4328
  * explicitly, or to remove it.
2964
4329
  * @example
2965
4330
  * This example registers a listener that responds to any changes to a
2966
- * specific Cell.
4331
+ * specific Value.
2967
4332
  *
2968
4333
  * ```js
2969
- * const store = createStore().setTables({
2970
- * pets: {fido: {species: 'dog', color: 'brown'}},
2971
- * });
2972
- * const listenerId = store.addCellListener(
2973
- * 'pets',
2974
- * 'fido',
2975
- * 'color',
2976
- * (store, tableId, rowId, cellId, newCell, oldCell, getCellChange) => {
2977
- * console.log('color cell in fido row in pets table changed');
2978
- * console.log([oldCell, newCell]);
2979
- * console.log(getCellChange('pets', 'fido', 'color'));
4334
+ * const store = createStore().setValues({open: true, employees: 3});
4335
+ * const listenerId = store.addValueListener(
4336
+ * 'employees',
4337
+ * (store, valueId, newValue, oldValue, getValueChange) => {
4338
+ * console.log('employee value changed');
4339
+ * console.log([oldValue, newValue]);
4340
+ * console.log(getValueChange('employees'));
2980
4341
  * },
2981
4342
  * );
2982
4343
  *
2983
- * store.setCell('pets', 'fido', 'color', 'walnut');
2984
- * // -> 'color cell in fido row in pets table changed'
2985
- * // -> ['brown', 'walnut']
2986
- * // -> [true, 'brown', 'walnut']
4344
+ * store.setValue('employees', 4);
4345
+ * // -> 'employee value changed'
4346
+ * // -> [3, 4]
4347
+ * // -> [true, 3, 4]
2987
4348
  *
2988
4349
  * store.delListener(listenerId);
2989
4350
  * ```
2990
4351
  * @example
2991
- * This example registers a listener that responds to any changes to any Cell.
4352
+ * This example registers a listener that responds to any changes to any
4353
+ * Value.
2992
4354
  *
2993
4355
  * ```js
2994
- * const store = createStore().setTables({
2995
- * pets: {fido: {species: 'dog', color: 'brown'}},
4356
+ * const store = createStore().setValues({open: true, employees: 3});
4357
+ * const listenerId = store.addValueListener(null, (store, valueId) => {
4358
+ * console.log(`${valueId} value changed`);
2996
4359
  * });
2997
- * const listenerId = store.addCellListener(
2998
- * null,
2999
- * null,
3000
- * null,
3001
- * (store, tableId, rowId, cellId) => {
3002
- * console.log(
3003
- * `${cellId} cell in ${rowId} row in ${tableId} table changed`,
3004
- * );
3005
- * },
3006
- * );
3007
4360
  *
3008
- * store.setCell('pets', 'fido', 'color', 'walnut');
3009
- * // -> 'color cell in fido row in pets table changed'
3010
- * store.setTable('species', {dog: {price: 5}});
3011
- * // -> 'price cell in dog row in species table changed'
4361
+ * store.setValue('employees', 4);
4362
+ * // -> 'employees value changed'
4363
+ * store.setValue('open', false);
4364
+ * // -> 'open value changed'
3012
4365
  *
3013
4366
  * store.delListener(listenerId);
3014
4367
  * ```
3015
4368
  * @example
3016
4369
  * This example registers a listener that responds to any changes to a
3017
- * specific Cell, and which also mutates the Store itself.
4370
+ * specific Value, and which also mutates the Store itself.
3018
4371
  *
3019
4372
  * ```js
3020
- * const store = createStore().setTables({
3021
- * pets: {fido: {species: 'dog', color: 'brown'}},
3022
- * });
3023
- * const listenerId = store.addCellListener(
3024
- * 'pets',
3025
- * 'fido',
3026
- * 'color',
3027
- * (store, tableId, rowId, cellId) =>
3028
- * store.setCell('meta', 'update', `${tableId}_${rowId}_${cellId}`, true),
4373
+ * const store = createStore().setValues({open: true, employees: 3});
4374
+ * const listenerId = store.addValueListener(
4375
+ * 'employees',
4376
+ * (store, valueId) => store.setValue('updated', true),
3029
4377
  * true,
3030
4378
  * );
3031
4379
  *
3032
- * store.delCell('pets', 'fido', 'color');
3033
- * console.log(store.getTable('meta'));
3034
- * // -> {update: {pets_fido_color: true}}
4380
+ * store.delValue('employees');
4381
+ * console.log(store.getValues());
4382
+ * // -> {open: true, updated: true}
3035
4383
  *
3036
4384
  * store.delListener(listenerId);
3037
4385
  * ```
3038
4386
  * @category Listener
4387
+ * @since v3.0.0
3039
4388
  */
3040
- addCellListener(
3041
- tableId: IdOrNull,
3042
- rowId: IdOrNull,
3043
- cellId: IdOrNull,
4389
+ addValueListener(
4390
+ valueId: IdOrNull,
3044
4391
  listener: CellListener,
3045
4392
  mutator?: boolean,
3046
4393
  ): Id;
@@ -3052,7 +4399,7 @@ export interface Store {
3052
4399
  *
3053
4400
  * The provided listener is an InvalidCellListener function, and will be
3054
4401
  * called with a reference to the Store, the Id of the Table, the Id of the
3055
- * Row, and the Id of Cell that were being attempted to be changed. It is also
4402
+ * Row, and the Id of Cell that was being attempted to be changed. It is also
3056
4403
  * given the invalid value of the Cell, which could have been of absolutely
3057
4404
  * any type. Since there could have been multiple failed attempts to set the
3058
4405
  * Cell within a single transaction, this is an array containing each attempt,
@@ -3076,19 +4423,20 @@ export interface Store {
3076
4423
  * though they will fire non-mutator listeners.
3077
4424
  *
3078
4425
  * Special note should be made for how the listener will be called when a
3079
- * Schema is present. The listener will be called:
4426
+ * TablesSchema is present. The listener will be called:
3080
4427
  *
3081
- * - if a Table is being updated that is not specified in the Schema
3082
- * - if a Cell is of the wrong type specified in the Schema
3083
- * - if a Cell is omitted and is not defaulted in the Schema
3084
- * - if an empty Row is provided and there are no Cell defaults in the Schema
4428
+ * - if a Table is being updated that is not specified in the TablesSchema
4429
+ * - if a Cell is of the wrong type specified in the TablesSchema
4430
+ * - if a Cell is omitted and is not defaulted in the TablesSchema
4431
+ * - if an empty Row is provided and there are no Cell defaults in the
4432
+ * TablesSchema
3085
4433
  *
3086
- * The listener will not be called if Cell that is defaulted in the Schema is
3087
- * not provided, as long as all of the Cells that are _not_ defaulted _are_
3088
- * provided.
4434
+ * The listener will not be called if a Cell that is defaulted in the
4435
+ * TablesSchema is not provided, as long as all of the Cells that are _not_
4436
+ * defaulted _are_ provided.
3089
4437
  *
3090
4438
  * To help understand all of these schema-based conditions, please see the
3091
- * Schema example below.
4439
+ * TablesSchema example below.
3092
4440
  *
3093
4441
  * @param tableId The Id of the Table to listen to, or `null` as a wildcard.
3094
4442
  * @param rowId The Id of the Row to listen to, or `null` as a wildcard.
@@ -3125,9 +4473,9 @@ export interface Store {
3125
4473
  * ```
3126
4474
  * @example
3127
4475
  * This example registers a listener that responds to any invalid changes to
3128
- * any Cell - in a Store _without_ a Schema. Note also how it then responds to
3129
- * cases where an empty or invalid Row objects, or Table objects, or Tables
3130
- * objects are provided.
4476
+ * any Cell - in a Store _without_ a TablesSchema. Note also how it then
4477
+ * responds to cases where empty or invalid Row objects, or Table objects,
4478
+ * or Tables objects are provided.
3131
4479
  *
3132
4480
  * ```js
3133
4481
  * const store = createStore().setTables({
@@ -3174,12 +4522,12 @@ export interface Store {
3174
4522
  * ```
3175
4523
  * @example
3176
4524
  * This example registers a listener that responds to any invalid changes to
3177
- * any Cell - in a Store _with_ a Schema. Note how it responds to cases where
3178
- * missing parameters are provided for optional, and defaulted Cell values in
3179
- * a Row.
4525
+ * any Cell - in a Store _with_ a TablesSchema. Note how it responds to cases
4526
+ * where missing parameters are provided for optional, and defaulted Cell
4527
+ * values in a Row.
3180
4528
  *
3181
4529
  * ```js
3182
- * const store = createStore().setSchema({
4530
+ * const store = createStore().setTablesSchema({
3183
4531
  * pets: {
3184
4532
  * species: {type: 'string'},
3185
4533
  * color: {type: 'string', default: 'unknown'},
@@ -3220,7 +4568,7 @@ export interface Store {
3220
4568
  * // -> {species: 'dog', color: 'unknown'}
3221
4569
  * // The listener is not called, because color is defaulted
3222
4570
  *
3223
- * store.delTables().setSchema({
4571
+ * store.delTables().setTablesSchema({
3224
4572
  * pets: {
3225
4573
  * species: {type: 'string'},
3226
4574
  * color: {type: 'string'},
@@ -3275,6 +4623,182 @@ export interface Store {
3275
4623
  mutator?: boolean,
3276
4624
  ): Id;
3277
4625
 
4626
+ /**
4627
+ * The addInvalidValueListener method registers a listener function with the
4628
+ * Store that will be called whenever invalid data was attempted to be written
4629
+ * to a Value.
4630
+ *
4631
+ * The provided listener is an InvalidValueListener function, and will be
4632
+ * called with a reference to the Store and the Id of Value that was being
4633
+ * attempted to be changed. It is also given the invalid value of the Value,
4634
+ * which could have been of absolutely any type. Since there could have been
4635
+ * multiple failed attempts to set the Value within a single transaction, this
4636
+ * is an array containing each attempt, chronologically.
4637
+ *
4638
+ * You can either listen to a single Value (by specifying the Value Id as the
4639
+ * method's first parameter) or invalid attempts to change any Value (by
4640
+ * providing a `null` wildcard).
4641
+ *
4642
+ * Use the optional mutator parameter to indicate that there is code in the
4643
+ * listener that will mutate Store data. If set to `false` (or omitted), such
4644
+ * mutations will be silently ignored. All relevant mutator listeners (with
4645
+ * this flag set to `true`) are called _before_ any non-mutator listeners
4646
+ * (since the latter may become relevant due to changes made in the former).
4647
+ * The changes made by mutator listeners do not fire other mutating listeners,
4648
+ * though they will fire non-mutator listeners.
4649
+ *
4650
+ * Special note should be made for how the listener will be called when a
4651
+ * ValuesSchema is present. The listener will be called:
4652
+ *
4653
+ * - if a Value is being updated that is not specified in the ValuesSchema
4654
+ * - if a Value is of the wrong type specified in the ValuesSchema
4655
+ * - if a Value is omitted when using setValues that is not defaulted in the
4656
+ * ValuesSchema
4657
+ *
4658
+ * The listener will not be called if a Value that is defaulted in the
4659
+ * ValuesSchema is not provided, as long as all of the Values that are _not_
4660
+ * defaulted _are_ provided.
4661
+ *
4662
+ * To help understand all of these schema-based conditions, please see the
4663
+ * ValuesSchema example below.
4664
+ *
4665
+ * @param valueId The Id of the Value to listen to, or `null` as a wildcard.
4666
+ * @param listener The function that will be called whenever an attempt to
4667
+ * write invalid data to the matching Value was made.
4668
+ * @param mutator An optional boolean that indicates that the listener mutates
4669
+ * Store data.
4670
+ * @returns A unique Id for the listener that can later be used to call it
4671
+ * explicitly, or to remove it.
4672
+ * @example
4673
+ * This example registers a listener that responds to any invalid changes to a
4674
+ * specific Value.
4675
+ *
4676
+ * ```js
4677
+ * const store = createStore().setValues({open: true});
4678
+ * const listenerId = store.addInvalidValueListener(
4679
+ * 'open',
4680
+ * (store, valueId, invalidValues) => {
4681
+ * console.log('Invalid open value');
4682
+ * console.log(invalidValues);
4683
+ * },
4684
+ * );
4685
+ *
4686
+ * store.setValue('open', {yes: true});
4687
+ * // -> 'Invalid open value'
4688
+ * // -> [{yes: true}]
4689
+ *
4690
+ * store.delListener(listenerId);
4691
+ * ```
4692
+ * @example
4693
+ * This example registers a listener that responds to any invalid changes to
4694
+ * any Value - in a Store _without_ a ValuesSchema. Note also how it then
4695
+ * responds to cases where an empty Values object is provided.
4696
+ *
4697
+ * ```js
4698
+ * const store = createStore().setValues({open: true});
4699
+ * const listenerId = store.addInvalidValueListener(
4700
+ * null,
4701
+ * (store, valueId) => {
4702
+ * console.log(`Invalid ${valueId} value`);
4703
+ * },
4704
+ * );
4705
+ *
4706
+ * store.setValue('open', {yes: true});
4707
+ * // -> 'Invalid open value'
4708
+ * store.setValue('employees', ['alice', 'bob']);
4709
+ * // -> 'Invalid employees value'
4710
+ *
4711
+ * store.setValues('pets', 'felix', {});
4712
+ * // -> 'Invalid undefined value'
4713
+ *
4714
+ * store.delListener(listenerId);
4715
+ * ```
4716
+ * @example
4717
+ * This example registers a listener that responds to any invalid changes to
4718
+ * any Value - in a Store _with_ a ValuesSchema. Note how it responds to cases
4719
+ * where missing parameters are provided for optional, and defaulted Values.
4720
+ *
4721
+ * ```js
4722
+ * const store = createStore().setValuesSchema({
4723
+ * open: {type: 'boolean', default: false},
4724
+ * employees: {type: 'number'},
4725
+ * });
4726
+ *
4727
+ * console.log(store.getValues());
4728
+ * // -> {open: false}
4729
+ *
4730
+ * const listenerId = store.addInvalidValueListener(
4731
+ * null,
4732
+ * (store, valueId) => {
4733
+ * console.log(`Invalid ${valueId} value`);
4734
+ * },
4735
+ * );
4736
+ *
4737
+ * store.setValue('website', true);
4738
+ * // -> 'Invalid website value'
4739
+ * // The listener is called, because the website Value is not in the schema
4740
+ *
4741
+ * store.setValue('open', 'yes');
4742
+ * // -> 'Invalid open value'
4743
+ * // The listener is called, because 'open' is invalid...
4744
+ * console.log(store.getValues());
4745
+ * // -> {open: false}
4746
+ * // ...even though it is still present with the default value
4747
+ *
4748
+ * store.setValues({open: true});
4749
+ * // -> 'Invalid employees value'
4750
+ * // The listener is called because employees is missing and not defaulted...
4751
+ * console.log(store.getValues());
4752
+ * // -> {open: true}
4753
+ * // ...even though the Values were set
4754
+ *
4755
+ * store.setValues({employees: 3});
4756
+ * console.log(store.getValues());
4757
+ * // -> {open: false, employees: 3}
4758
+ * // The listener is not called, because 'open' is defaulted
4759
+ *
4760
+ * store.setValuesSchema({
4761
+ * open: {type: 'boolean'},
4762
+ * employees: {type: 'number'},
4763
+ * });
4764
+ *
4765
+ * store.setValues({});
4766
+ * // -> 'Invalid open value'
4767
+ * // -> 'Invalid employees value'
4768
+ * // -> 'Invalid undefined value'
4769
+ * // The listener is called multiple times, because neither Value is
4770
+ * // defaulted and the Values as a whole were empty
4771
+ *
4772
+ * store.delListener(listenerId);
4773
+ * ```
4774
+ * @example
4775
+ * This example registers a listener that responds to any changes to a
4776
+ * specific Value, and which also mutates the Store itself.
4777
+ *
4778
+ * ```js
4779
+ * const store = createStore().setValues({open: true});
4780
+ * const listenerId = store.addInvalidValueListener(
4781
+ * 'open',
4782
+ * (store, valueId, invalidValues) =>
4783
+ * store.setValue('invalid_updates', JSON.stringify(invalidValues[0])),
4784
+ * true,
4785
+ * );
4786
+ *
4787
+ * store.setValue('open', {yes: true});
4788
+ * console.log(store.getValue('invalid_updates'));
4789
+ * // -> '{"yes":true}'
4790
+ *
4791
+ * store.delListener(listenerId);
4792
+ * ```
4793
+ * @category Listener
4794
+ * @since v3.0.0
4795
+ */
4796
+ addInvalidValueListener(
4797
+ valueId: IdOrNull,
4798
+ listener: InvalidValueListener,
4799
+ mutator?: boolean,
4800
+ ): Id;
4801
+
3278
4802
  /**
3279
4803
  * The addWillFinishTransactionListener method registers a listener function
3280
4804
  * with the Store that will be called just before other non-mutating listeners
@@ -3285,59 +4809,82 @@ export interface Store {
3285
4809
  * together.
3286
4810
  *
3287
4811
  * The provided TransactionListener will receive a reference to the Store and
3288
- * a boolean to indicate whether Cell values have been touched during the
3289
- * transaction. The latter flag is intended as a hint about whether
4812
+ * two booleans to indicate whether Cell or Value data has been touched during
4813
+ * the transaction. The two flags are intended as a hint about whether
3290
4814
  * non-mutating listeners might be being called at the end of the transaction.
3291
4815
  *
3292
- * Here, 'touched' means that Cell values have either been changed, or changed
3293
- * and then changed back to its original value during the transaction. The
3294
- * exception is a transaction that has been rolled back, for which the value
3295
- * of `cellsTouched` in the listener will be `false` because all changes have
3296
- * been reverted.
4816
+ * Here, 'touched' means that Cell or Value data has either been changed, or
4817
+ * changed and then changed back to its original value during the transaction.
4818
+ * The exception is a transaction that has been rolled back, for which the
4819
+ * value of `cellsTouched` and `valuesTouched` in the listener will be `false`
4820
+ * because all changes have been reverted.
3297
4821
  *
3298
4822
  * @returns A unique Id for the listener that can later be used to remove it.
3299
4823
  * @example
3300
4824
  * This example registers a listener that is called at the end of the
3301
4825
  * transaction, just before its listeners will be called. The transactions
3302
4826
  * shown here variously change, touch, and rollback cells, demonstrating how
3303
- * the `cellsTouched` parameter in the listener works.
4827
+ * the `cellsTouched` and `valuesTouched` parameters in the listener work.
3304
4828
  *
3305
4829
  * ```js
3306
- * const store = createStore().setTables({
3307
- * pets: {fido: {species: 'dog', color: 'brown'}},
3308
- * });
4830
+ * const store = createStore()
4831
+ * .setTables({
4832
+ * pets: {fido: {species: 'dog', color: 'brown'}},
4833
+ * })
4834
+ * .setValues({open: true, employees: 3});
3309
4835
  * const listenerId = store.addWillFinishTransactionListener(
3310
- * (store, cellsTouched) => console.log(`Cells touched: ${cellsTouched}`),
4836
+ * (store, cellsTouched, valuesTouched) => {
4837
+ * console.log(`Cells/Values touched: ${cellsTouched}/${valuesTouched}`);
4838
+ * },
3311
4839
  * );
3312
4840
  * const listenerId2 = store.addTablesListener(() =>
3313
4841
  * console.log('Tables changed'),
3314
4842
  * );
4843
+ * const listenerId3 = store.addValuesListener(() =>
4844
+ * console.log('Values changed'),
4845
+ * );
3315
4846
  *
3316
- * store.transaction(() => store.setCell('pets', 'fido', 'color', 'brown'));
3317
- * // -> 'Cells touched: false'
4847
+ * store.transaction(() =>
4848
+ * store.setCell('pets', 'fido', 'color', 'brown').setValue('employees', 3),
4849
+ * );
4850
+ * // -> 'Cells/Values touched: false/false'
3318
4851
  *
3319
4852
  * store.transaction(() => store.setCell('pets', 'fido', 'color', 'walnut'));
3320
- * // -> 'Cells touched: true'
4853
+ * // -> 'Cells/Values touched: true/false'
3321
4854
  * // -> 'Tables changed'
3322
4855
  *
4856
+ * store.transaction(() => store.setValue('employees', 4));
4857
+ * // -> 'Cells/Values touched: false/true'
4858
+ * // -> 'Values changed'
4859
+ *
3323
4860
  * store.transaction(() => {
3324
- * store.setRow('pets', 'felix', {species: 'cat'});
3325
- * store.delRow('pets', 'felix');
4861
+ * store
4862
+ * .setRow('pets', 'felix', {species: 'cat'})
4863
+ * .delRow('pets', 'felix')
4864
+ * .setValue('city', 'London')
4865
+ * .delValue('city');
3326
4866
  * });
3327
- * // -> 'Cells touched: true'
4867
+ * // -> 'Cells/Values touched: true/true'
4868
+ * // But no Tables or Values listeners fired since there are no net changes.
3328
4869
  *
3329
4870
  * store.transaction(
3330
- * () => store.setRow('pets', 'fido', {species: 'dog'}),
4871
+ * () =>
4872
+ * store
4873
+ * .setRow('pets', 'felix', {species: 'cat'})
4874
+ * .setValue('city', 'London'),
3331
4875
  * () => true,
3332
4876
  * );
3333
- * // -> 'Cells touched: false'
4877
+ * // -> 'Cells/Values touched: false/false'
3334
4878
  * // Transaction was rolled back.
3335
4879
  *
3336
4880
  * store.callListener(listenerId);
3337
- * // -> 'Cells touched: undefined'
4881
+ * // -> 'Cells/Values touched: undefined/undefined'
3338
4882
  * // It is meaningless to call this listener directly.
3339
4883
  *
3340
- * store.delListener(listenerId).delListener(listenerId2);
4884
+ * store
4885
+ * .delListener(listenerId)
4886
+ * .delListener(listenerId2)
4887
+ * .delListener(listenerId3);
3341
4888
  * ```
3342
4889
  * @category Listener
3343
4890
  * @since v1.3.0
@@ -3354,60 +4901,83 @@ export interface Store {
3354
4901
  * together.
3355
4902
  *
3356
4903
  * The provided TransactionListener will receive a reference to the Store and
3357
- * a boolean to indicate whether Cell values have been touched during the
3358
- * transaction. The latter flag is intended as a hint about whether
4904
+ * two booleans to indicate whether Cell or Value data has been touched during
4905
+ * the transaction. The two flags is intended as a hint about whether
3359
4906
  * non-mutating listeners might have been called at the end of the
3360
4907
  * transaction.
3361
4908
  *
3362
- * Here, 'touched' means that Cell values have either been changed, or changed
3363
- * and then changed back to its original value during the transaction. The
3364
- * exception is a transaction that has been rolled back, for which the value
3365
- * of `cellsTouched` in the listener will be `false` because all changes have
3366
- * been reverted.
4909
+ * Here, 'touched' means that Cell or Value data has either been changed, or
4910
+ * changed and then changed back to its original value during the transaction.
4911
+ * The exception is a transaction that has been rolled back, for which the
4912
+ * value of `cellsTouched` and `valuesTouched` in the listener will be `false`
4913
+ * because all changes have been reverted.
3367
4914
  *
3368
4915
  * @returns A unique Id for the listener that can later be used to remove it.
3369
4916
  * @example
3370
4917
  * This example registers a listener that is called at the end of the
3371
4918
  * transaction, just after its listeners have been called. The transactions
3372
4919
  * shown here variously change, touch, and rollback cells, demonstrating how
3373
- * the `cellsTouched` parameter in the listener works.
4920
+ * the `cellsTouched` and `valuesTouched` parameters in the listener work.
3374
4921
  *
3375
4922
  * ```js
3376
- * const store = createStore().setTables({
3377
- * pets: {fido: {species: 'dog', color: 'brown'}},
3378
- * });
4923
+ * const store = createStore()
4924
+ * .setTables({
4925
+ * pets: {fido: {species: 'dog', color: 'brown'}},
4926
+ * })
4927
+ * .setValues({open: true, employees: 3});
3379
4928
  * const listenerId = store.addDidFinishTransactionListener(
3380
- * (store, cellsTouched) => console.log(`Cells touched: ${cellsTouched}`),
4929
+ * (store, cellsTouched, valuesTouched) => {
4930
+ * console.log(`Cells/Values touched: ${cellsTouched}/${valuesTouched}`);
4931
+ * },
3381
4932
  * );
3382
4933
  * const listenerId2 = store.addTablesListener(() =>
3383
4934
  * console.log('Tables changed'),
3384
4935
  * );
4936
+ * const listenerId3 = store.addValuesListener(() =>
4937
+ * console.log('Values changed'),
4938
+ * );
3385
4939
  *
3386
- * store.transaction(() => store.setCell('pets', 'fido', 'color', 'brown'));
3387
- * // -> 'Cells touched: false'
4940
+ * store.transaction(() =>
4941
+ * store.setCell('pets', 'fido', 'color', 'brown').setValue('employees', 3),
4942
+ * );
4943
+ * // -> 'Cells/Values touched: false/false'
3388
4944
  *
3389
4945
  * store.transaction(() => store.setCell('pets', 'fido', 'color', 'walnut'));
3390
4946
  * // -> 'Tables changed'
3391
- * // -> 'Cells touched: true'
4947
+ * // -> 'Cells/Values touched: true/false'
4948
+ *
4949
+ * store.transaction(() => store.setValue('employees', 4));
4950
+ * // -> 'Values changed'
4951
+ * // -> 'Cells/Values touched: false/true'
3392
4952
  *
3393
4953
  * store.transaction(() => {
3394
- * store.setRow('pets', 'felix', {species: 'cat'});
3395
- * store.delRow('pets', 'felix');
4954
+ * store
4955
+ * .setRow('pets', 'felix', {species: 'cat'})
4956
+ * .delRow('pets', 'felix')
4957
+ * .setValue('city', 'London')
4958
+ * .delValue('city');
3396
4959
  * });
3397
- * // -> 'Cells touched: true'
4960
+ * // -> 'Cells/Values touched: true/true'
4961
+ * // But no Tables or Values listeners fired since there are no net changes.
3398
4962
  *
3399
4963
  * store.transaction(
3400
- * () => store.setRow('pets', 'fido', {species: 'dog'}),
4964
+ * () =>
4965
+ * store
4966
+ * .setRow('pets', 'felix', {species: 'cat'})
4967
+ * .setValue('city', 'London'),
3401
4968
  * () => true,
3402
4969
  * );
3403
- * // -> 'Cells touched: false'
4970
+ * // -> 'Cells/Values touched: false/false'
3404
4971
  * // Transaction was rolled back.
3405
4972
  *
3406
4973
  * store.callListener(listenerId);
3407
- * // -> 'Cells touched: undefined'
4974
+ * // -> 'Cells/Values touched: undefined/undefined'
3408
4975
  * // It is meaningless to call this listener directly.
3409
4976
  *
3410
- * store.delListener(listenerId).delListener(listenerId2);
4977
+ * store
4978
+ * .delListener(listenerId)
4979
+ * .delListener(listenerId2)
4980
+ * .delListener(listenerId3);
3411
4981
  * ```
3412
4982
  * @category Listener
3413
4983
  * @since v1.3.0
@@ -3458,6 +5028,75 @@ export interface Store {
3458
5028
  *
3459
5029
  * store.delListener(listenerId);
3460
5030
  * ```
5031
+ * @example
5032
+ * This example registers a listener to Row Id changes. It is explicitly
5033
+ * called and fires for two Tables in the Store.
5034
+ *
5035
+ * ```js
5036
+ * const store = createStore().setTables({
5037
+ * pets: {fido: {species: 'dog'}},
5038
+ * species: {dog: {price: 5}},
5039
+ * });
5040
+ *
5041
+ * const listenerId = store.addRowIdsListener(null, (store, tableId) => {
5042
+ * console.log(`Row Ids listener called for ${tableId} table`);
5043
+ * });
5044
+ *
5045
+ * store.callListener(listenerId);
5046
+ * // -> 'Row Ids listener called for pets table'
5047
+ * // -> 'Row Ids listener called for species table'
5048
+ *
5049
+ * store.delListener(listenerId);
5050
+ * ```
5051
+ * @example
5052
+ * This example registers a listener Value changes. It is explicitly called
5053
+ * and fires for two Values in the Store.
5054
+ *
5055
+ * ```js
5056
+ * const store = createStore().setValues({open: true, employees: 3});
5057
+ *
5058
+ * const listenerId = store.addValueListener(
5059
+ * null,
5060
+ * (store, valueId, value) => {
5061
+ * console.log(`Value listener called for ${valueId} value, ${value}`);
5062
+ * },
5063
+ * );
5064
+ *
5065
+ * store.callListener(listenerId);
5066
+ * // -> 'Value listener called for open value, true'
5067
+ * // -> 'Value listener called for employees value, 3'
5068
+ *
5069
+ * store.delListener(listenerId);
5070
+ * ```
5071
+ * @example
5072
+ * This example registers listeners for the end of transactions, and for
5073
+ * invalid Cells. The are explicitly called, meaninglessly. The former
5074
+ * receives empty arguments. The latter is not called at all.
5075
+ *
5076
+ * ```js
5077
+ * const store = createStore();
5078
+ *
5079
+ * const listenerId = store.addWillFinishTransactionListener(
5080
+ * (store, cellsTouched, valuesTouched) => {
5081
+ * console.log(`Transaction finish: ${cellsTouched}/${valuesTouched}`);
5082
+ * },
5083
+ * );
5084
+ * store.callListener(listenerId);
5085
+ * // -> 'Transaction finish: undefined/undefined'
5086
+ * store.delListener(listenerId);
5087
+ *
5088
+ * const listenerId2 = store.addInvalidCellListener(
5089
+ * null,
5090
+ * null,
5091
+ * null,
5092
+ * (store, tableId, rowId, cellId) => {
5093
+ * console.log('Invalid cell', tableId, rowId, cellId);
5094
+ * },
5095
+ * );
5096
+ * store.callListener(listenerId2);
5097
+ * // -> undefined
5098
+ * store.delListener(listenerId2);
5099
+ * ```
3461
5100
  * @category Listener
3462
5101
  */
3463
5102
  callListener(listenerId: Id): Store;
@@ -3552,12 +5191,12 @@ export interface Store {
3552
5191
  * // -> {pets: {fido: {species: 'dog'}}}
3553
5192
  * ```
3554
5193
  * @example
3555
- * This example creates a Store with some initial data and a Schema:
5194
+ * This example creates a Store with some initial data and a TablesSchema:
3556
5195
  *
3557
5196
  * ```js
3558
5197
  * const store = createStore()
3559
5198
  * .setTables({pets: {fido: {species: 'dog'}}})
3560
- * .setSchema({
5199
+ * .setTablesSchema({
3561
5200
  * pets: {
3562
5201
  * species: {type: 'string'},
3563
5202
  * sold: {type: 'boolean', default: false},