tinybase 4.0.0-beta.0 → 4.0.0-beta.2

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 (203) hide show
  1. package/bin/cli.js +1 -1
  2. package/lib/checkpoints.js +1 -1
  3. package/lib/checkpoints.js.gz +0 -0
  4. package/lib/cjs/checkpoints.cjs +1 -1
  5. package/lib/cjs/checkpoints.cjs.gz +0 -0
  6. package/lib/cjs/indexes.cjs +1 -1
  7. package/lib/cjs/indexes.cjs.gz +0 -0
  8. package/lib/cjs/metrics.cjs +1 -1
  9. package/lib/cjs/metrics.cjs.gz +0 -0
  10. package/lib/cjs/persister-browser.cjs +1 -0
  11. package/lib/cjs/persister-browser.cjs.gz +0 -0
  12. package/lib/cjs/persister-file.cjs +1 -0
  13. package/lib/cjs/persister-file.cjs.gz +0 -0
  14. package/lib/cjs/persister-remote.cjs +1 -0
  15. package/lib/cjs/persister-remote.cjs.gz +0 -0
  16. package/lib/cjs/persister-yjs.cjs +1 -1
  17. package/lib/cjs/persister-yjs.cjs.gz +0 -0
  18. package/lib/cjs/persisters.cjs +1 -1
  19. package/lib/cjs/persisters.cjs.gz +0 -0
  20. package/lib/cjs/queries.cjs +1 -1
  21. package/lib/cjs/queries.cjs.gz +0 -0
  22. package/lib/cjs/relationships.cjs +1 -1
  23. package/lib/cjs/relationships.cjs.gz +0 -0
  24. package/lib/cjs/store.cjs +1 -1
  25. package/lib/cjs/store.cjs.gz +0 -0
  26. package/lib/cjs/tinybase.cjs +1 -1
  27. package/lib/cjs/tinybase.cjs.gz +0 -0
  28. package/lib/cjs/tools.cjs +1 -1
  29. package/lib/cjs/tools.cjs.gz +0 -0
  30. package/lib/cjs/ui-react.cjs +1 -1
  31. package/lib/cjs/ui-react.cjs.gz +0 -0
  32. package/lib/cjs-es6/checkpoints.cjs +1 -1
  33. package/lib/cjs-es6/checkpoints.cjs.gz +0 -0
  34. package/lib/cjs-es6/indexes.cjs +1 -1
  35. package/lib/cjs-es6/indexes.cjs.gz +0 -0
  36. package/lib/cjs-es6/metrics.cjs +1 -1
  37. package/lib/cjs-es6/metrics.cjs.gz +0 -0
  38. package/lib/cjs-es6/persister-browser.cjs +1 -0
  39. package/lib/cjs-es6/persister-browser.cjs.gz +0 -0
  40. package/lib/cjs-es6/persister-file.cjs +1 -0
  41. package/lib/cjs-es6/persister-file.cjs.gz +0 -0
  42. package/lib/cjs-es6/persister-remote.cjs +1 -0
  43. package/lib/cjs-es6/persister-remote.cjs.gz +0 -0
  44. package/lib/cjs-es6/persister-yjs.cjs +1 -1
  45. package/lib/cjs-es6/persister-yjs.cjs.gz +0 -0
  46. package/lib/cjs-es6/persisters.cjs +1 -1
  47. package/lib/cjs-es6/persisters.cjs.gz +0 -0
  48. package/lib/cjs-es6/queries.cjs +1 -1
  49. package/lib/cjs-es6/queries.cjs.gz +0 -0
  50. package/lib/cjs-es6/relationships.cjs +1 -1
  51. package/lib/cjs-es6/relationships.cjs.gz +0 -0
  52. package/lib/cjs-es6/store.cjs +1 -1
  53. package/lib/cjs-es6/store.cjs.gz +0 -0
  54. package/lib/cjs-es6/tinybase.cjs +1 -1
  55. package/lib/cjs-es6/tinybase.cjs.gz +0 -0
  56. package/lib/cjs-es6/tools.cjs +1 -1
  57. package/lib/cjs-es6/tools.cjs.gz +0 -0
  58. package/lib/cjs-es6/ui-react.cjs +1 -1
  59. package/lib/cjs-es6/ui-react.cjs.gz +0 -0
  60. package/lib/debug/checkpoints.js +3 -3
  61. package/lib/debug/indexes.js +3 -3
  62. package/lib/debug/metrics.js +3 -3
  63. package/lib/debug/persister-browser.js +147 -0
  64. package/lib/debug/persister-file.js +140 -0
  65. package/lib/debug/persister-remote.js +159 -0
  66. package/lib/debug/persister-yjs.js +234 -40
  67. package/lib/debug/persisters.js +43 -133
  68. package/lib/debug/queries.js +5 -5
  69. package/lib/debug/relationships.js +3 -3
  70. package/lib/debug/store.js +137 -87
  71. package/lib/debug/tinybase.js +179 -215
  72. package/lib/debug/tools.js +9 -9
  73. package/lib/es6/checkpoints.js +1 -1
  74. package/lib/es6/checkpoints.js.gz +0 -0
  75. package/lib/es6/indexes.js +1 -1
  76. package/lib/es6/indexes.js.gz +0 -0
  77. package/lib/es6/metrics.js +1 -1
  78. package/lib/es6/metrics.js.gz +0 -0
  79. package/lib/es6/persister-browser.js +1 -0
  80. package/lib/es6/persister-browser.js.gz +0 -0
  81. package/lib/es6/persister-file.js +1 -0
  82. package/lib/es6/persister-file.js.gz +0 -0
  83. package/lib/es6/persister-remote.js +1 -0
  84. package/lib/es6/persister-remote.js.gz +0 -0
  85. package/lib/es6/persister-yjs.js +1 -1
  86. package/lib/es6/persister-yjs.js.gz +0 -0
  87. package/lib/es6/persisters.js +1 -1
  88. package/lib/es6/persisters.js.gz +0 -0
  89. package/lib/es6/queries.js +1 -1
  90. package/lib/es6/queries.js.gz +0 -0
  91. package/lib/es6/relationships.js +1 -1
  92. package/lib/es6/relationships.js.gz +0 -0
  93. package/lib/es6/store.js +1 -1
  94. package/lib/es6/store.js.gz +0 -0
  95. package/lib/es6/tinybase.js +1 -1
  96. package/lib/es6/tinybase.js.gz +0 -0
  97. package/lib/es6/tools.js +1 -1
  98. package/lib/es6/tools.js.gz +0 -0
  99. package/lib/es6/ui-react.js +1 -1
  100. package/lib/es6/ui-react.js.gz +0 -0
  101. package/lib/indexes.js +1 -1
  102. package/lib/indexes.js.gz +0 -0
  103. package/lib/metrics.js +1 -1
  104. package/lib/metrics.js.gz +0 -0
  105. package/lib/persister-browser.js +1 -0
  106. package/lib/persister-browser.js.gz +0 -0
  107. package/lib/persister-file.js +1 -0
  108. package/lib/persister-file.js.gz +0 -0
  109. package/lib/persister-remote.js +1 -0
  110. package/lib/persister-remote.js.gz +0 -0
  111. package/lib/persister-yjs.js +1 -1
  112. package/lib/persister-yjs.js.gz +0 -0
  113. package/lib/persisters.js +1 -1
  114. package/lib/persisters.js.gz +0 -0
  115. package/lib/queries.js +1 -1
  116. package/lib/queries.js.gz +0 -0
  117. package/lib/relationships.js +1 -1
  118. package/lib/relationships.js.gz +0 -0
  119. package/lib/store.js +1 -1
  120. package/lib/store.js.gz +0 -0
  121. package/lib/tinybase.js +1 -1
  122. package/lib/tinybase.js.gz +0 -0
  123. package/lib/tools.js +1 -1
  124. package/lib/tools.js.gz +0 -0
  125. package/lib/types/persister-browser.d.ts +85 -0
  126. package/lib/types/persister-file.d.ts +41 -0
  127. package/lib/types/persister-remote.d.ts +60 -0
  128. package/lib/types/persister-yjs.d.ts +70 -8
  129. package/lib/types/persisters.d.ts +73 -181
  130. package/lib/types/queries.d.ts +52 -52
  131. package/lib/types/store.d.ts +499 -139
  132. package/lib/types/tools.d.ts +16 -16
  133. package/lib/types/ui-react.d.ts +56 -47
  134. package/lib/types/with-schemas/internal/ui-react.d.ts +2 -2
  135. package/lib/types/with-schemas/persister-browser.d.ts +103 -0
  136. package/lib/types/with-schemas/persister-file.d.ts +50 -0
  137. package/lib/types/with-schemas/persister-remote.d.ts +71 -0
  138. package/lib/types/with-schemas/persister-yjs.d.ts +72 -9
  139. package/lib/types/with-schemas/persisters.d.ts +99 -223
  140. package/lib/types/with-schemas/queries.d.ts +52 -52
  141. package/lib/types/with-schemas/store.d.ts +595 -153
  142. package/lib/types/with-schemas/tools.d.ts +16 -16
  143. package/lib/types/with-schemas/ui-react.d.ts +54 -45
  144. package/lib/ui-react.js +1 -1
  145. package/lib/ui-react.js.gz +0 -0
  146. package/lib/umd/checkpoints.js +1 -1
  147. package/lib/umd/checkpoints.js.gz +0 -0
  148. package/lib/umd/indexes.js +1 -1
  149. package/lib/umd/indexes.js.gz +0 -0
  150. package/lib/umd/metrics.js +1 -1
  151. package/lib/umd/metrics.js.gz +0 -0
  152. package/lib/umd/persister-browser.js +1 -0
  153. package/lib/umd/persister-browser.js.gz +0 -0
  154. package/lib/umd/persister-file.js +1 -0
  155. package/lib/umd/persister-file.js.gz +0 -0
  156. package/lib/umd/persister-remote.js +1 -0
  157. package/lib/umd/persister-remote.js.gz +0 -0
  158. package/lib/umd/persister-yjs.js +1 -1
  159. package/lib/umd/persister-yjs.js.gz +0 -0
  160. package/lib/umd/persisters.js +1 -1
  161. package/lib/umd/persisters.js.gz +0 -0
  162. package/lib/umd/queries.js +1 -1
  163. package/lib/umd/queries.js.gz +0 -0
  164. package/lib/umd/relationships.js +1 -1
  165. package/lib/umd/relationships.js.gz +0 -0
  166. package/lib/umd/store.js +1 -1
  167. package/lib/umd/store.js.gz +0 -0
  168. package/lib/umd/tinybase.js +1 -1
  169. package/lib/umd/tinybase.js.gz +0 -0
  170. package/lib/umd/tools.js +1 -1
  171. package/lib/umd/tools.js.gz +0 -0
  172. package/lib/umd/ui-react.js +1 -1
  173. package/lib/umd/ui-react.js.gz +0 -0
  174. package/lib/umd-es6/checkpoints.js +1 -1
  175. package/lib/umd-es6/checkpoints.js.gz +0 -0
  176. package/lib/umd-es6/indexes.js +1 -1
  177. package/lib/umd-es6/indexes.js.gz +0 -0
  178. package/lib/umd-es6/metrics.js +1 -1
  179. package/lib/umd-es6/metrics.js.gz +0 -0
  180. package/lib/umd-es6/persister-browser.js +1 -0
  181. package/lib/umd-es6/persister-browser.js.gz +0 -0
  182. package/lib/umd-es6/persister-file.js +1 -0
  183. package/lib/umd-es6/persister-file.js.gz +0 -0
  184. package/lib/umd-es6/persister-remote.js +1 -0
  185. package/lib/umd-es6/persister-remote.js.gz +0 -0
  186. package/lib/umd-es6/persister-yjs.js +1 -1
  187. package/lib/umd-es6/persister-yjs.js.gz +0 -0
  188. package/lib/umd-es6/persisters.js +1 -1
  189. package/lib/umd-es6/persisters.js.gz +0 -0
  190. package/lib/umd-es6/queries.js +1 -1
  191. package/lib/umd-es6/queries.js.gz +0 -0
  192. package/lib/umd-es6/relationships.js +1 -1
  193. package/lib/umd-es6/relationships.js.gz +0 -0
  194. package/lib/umd-es6/store.js +1 -1
  195. package/lib/umd-es6/store.js.gz +0 -0
  196. package/lib/umd-es6/tinybase.js +1 -1
  197. package/lib/umd-es6/tinybase.js.gz +0 -0
  198. package/lib/umd-es6/tools.js +1 -1
  199. package/lib/umd-es6/tools.js.gz +0 -0
  200. package/lib/umd-es6/ui-react.js +1 -1
  201. package/lib/umd-es6/ui-react.js.gz +0 -0
  202. package/package.json +15 -15
  203. package/readme.md +2 -2
@@ -3,21 +3,21 @@
3
3
  * saving and loading Store data, to and from different destinations, or
4
4
  * underlying storage types.
5
5
  *
6
- * Several entry points are provided, each of which returns a new Persister
7
- * object that can load and save a Store:
8
- *
9
- * - The createSessionPersister function returns a Persister that uses the
10
- * browser's session storage.
11
- * - The createLocalPersister function returns a Persister that uses the
12
- * browser's local storage.
13
- * - The createRemotePersister function returns a Persister that uses a remote
14
- * server.
15
- * - The createFilePersister function returns a Persister that uses a local file
16
- * (in an appropriate environment).
6
+ * Several entry points are provided (in separately installed modules), each of
7
+ * which returns a new Persister object that can load and save a Store:
8
+ *
9
+ * - The createSessionPersister function (in the persister-browser module)
10
+ * returns a Persister that uses the browser's session storage.
11
+ * - The createLocalPersister function (in the persister-browser module) returns
12
+ * a Persister that uses the browser's local storage.
13
+ * - The createRemotePersister function (in the persister-remote module) returns
14
+ * a Persister that uses a remote server.
15
+ * - The createFilePersister function (in the persister-file module) returns a
16
+ * Persister that uses a local file (in an appropriate environment).
17
17
  *
18
18
  * Since persistence requirements can be different for every app, the
19
- * createCustomPersister function can also be used to easily create a fully
20
- * customized way to save and load Store data.
19
+ * createCustomPersister function in this module can also be used to easily
20
+ * create a fully customized way to save and load Store data.
21
21
  *
22
22
  * @see Persisting Data guide
23
23
  * @see Countries demo
@@ -27,8 +27,7 @@
27
27
  * @module persisters
28
28
  */
29
29
 
30
- import {Store, Tables, Values} from './store.d';
31
- import {Callback} from './common.d';
30
+ import {GetTransactionChanges, Store, Tables, Values} from './store.d';
32
31
 
33
32
  /**
34
33
  * The PersisterStats type describes the number of times a Persister object has
@@ -50,6 +49,27 @@ export type PersisterStats = {
50
49
  saves?: number;
51
50
  };
52
51
 
52
+ /**
53
+ * A PersisterListener is a callback that lets a Persister inform the Store that
54
+ * a change has happened to the underlying data.
55
+ *
56
+ * If the listener has the `getTransactionChanges` parameter, it will be used to
57
+ * make an incremental change to the Store. If not, but the `getContent`
58
+ * function _is_ available, that will be used to make a wholesale change to the
59
+ * Store. If neither are present, the content will be loaded from the
60
+ * Persister's load method.
61
+ *
62
+ * @param getContent An optional function that, if provided, returns an array of
63
+ * Store content and can be used to immediately wholesale update the Store.
64
+ * @param getTransactionChanges An optional function that, if provided, returns
65
+ * a TransactionChanges object and can be used to immediately incrementally
66
+ * update the Store.
67
+ */
68
+ export type PersisterListener = (
69
+ getContent?: () => [Tables, Values],
70
+ getTransactionChanges?: GetTransactionChanges,
71
+ ) => void;
72
+
53
73
  /**
54
74
  * A Persister object lets you save and load Store data to and from different
55
75
  * locations, or underlying storage types.
@@ -165,7 +185,7 @@ export interface Persister {
165
185
  * @param initialTables An optional Tables object used when the underlying
166
186
  * storage has not previously been populated.
167
187
  * @param initialValues An optional Values object used when the underlying
168
- * storage has not previously been populated, since v3.0.0.
188
+ * storage has not previously been populated, since v3.0.
169
189
  * @returns A Promise containing a reference to the Persister object.
170
190
  * @example
171
191
  * This example creates an empty Store, and loads data into it from the
@@ -233,7 +253,7 @@ export interface Persister {
233
253
  * @param initialTables An optional Tables object used when the underlying
234
254
  * storage has not previously been populated.
235
255
  * @param initialValues An optional Values object used when the underlying
236
- * storage has not previously been populated, since v3.0.0.
256
+ * storage has not previously been populated, since v3.0.
237
257
  * @returns A Promise containing a reference to the Persister object.
238
258
  * @example
239
259
  * This example creates an empty Store, and loads data into it from the
@@ -461,12 +481,12 @@ export interface Persister {
461
481
  * const persister = createSessionPersister(store, 'pets');
462
482
  * await persister.startAutoSave();
463
483
  *
464
- * console.log(store.getListenerStats().tables);
484
+ * console.log(store.getListenerStats().transaction);
465
485
  * // -> 1
466
486
  *
467
487
  * persister.destroy();
468
488
  *
469
- * console.log(store.getListenerStats().tables);
489
+ * console.log(store.getListenerStats().transaction);
470
490
  * // -> 0
471
491
  * ```
472
492
  * @category Lifecycle
@@ -520,151 +540,6 @@ export interface Persister {
520
540
  //
521
541
  }
522
542
 
523
- /**
524
- * The createSessionPersister function creates a Persister object that can
525
- * persist the Store to the browser's session storage.
526
- *
527
- * As well as providing a reference to the Store to persist, you must provide a
528
- * `storageName` parameter which is unique to your application. This is the key
529
- * that the browser uses to identify the storage location.
530
- *
531
- * @param store The Store to persist.
532
- * @param storageName The unique key to identify the storage location.
533
- * @returns A reference to the new Persister object.
534
- * @example
535
- * This example creates a Persister object and persists the Store to the
536
- * browser's session storage.
537
- *
538
- * ```js
539
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
540
- * const persister = createSessionPersister(store, 'pets');
541
- *
542
- * await persister.save();
543
- * console.log(sessionStorage.getItem('pets'));
544
- * // -> '[{"pets":{"fido":{"species":"dog"}}},{}]'
545
- *
546
- * persister.destroy();
547
- * sessionStorage.clear();
548
- * ```
549
- * @category Creation
550
- */
551
- export function createSessionPersister(
552
- store: Store,
553
- storageName: string,
554
- ): Persister;
555
-
556
- /**
557
- * The createLocalPersister function creates a Persister object that can
558
- * persist the Store to the browser's local storage.
559
- *
560
- * As well as providing a reference to the Store to persist, you must provide a
561
- * `storageName` parameter which is unique to your application. This is the key
562
- * that the browser uses to identify the storage location.
563
- *
564
- * @param store The Store to persist.
565
- * @param storageName The unique key to identify the storage location.
566
- * @returns A reference to the new Persister object.
567
- * @example
568
- * This example creates a Persister object and persists the Store to the
569
- * browser's local storage.
570
- *
571
- * ```js
572
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
573
- * const persister = createLocalPersister(store, 'pets');
574
- *
575
- * await persister.save();
576
- * console.log(localStorage.getItem('pets'));
577
- * // -> '[{"pets":{"fido":{"species":"dog"}}},{}]'
578
- *
579
- * persister.destroy();
580
- * localStorage.clear();
581
- * ```
582
- * @category Creation
583
- */
584
- export function createLocalPersister(
585
- store: Store,
586
- storageName: string,
587
- ): Persister;
588
-
589
- /**
590
- * The createRemotePersister function creates a Persister object that can
591
- * persist the Store to a remote server.
592
- *
593
- * As well as providing a reference to the Store to persist, you must provide
594
- * `loadUrl` and `saveUrl` parameters. These identify the endpoints of the
595
- * server that support the `GET` method (to fetch the Store JSON to load) and
596
- * the `POST` method (to send the Store JSON to save) respectively.
597
- *
598
- * For when you choose to enable automatic loading for the Persister (with the
599
- * startAutoLoad method), it will poll the loadUrl for changes. The
600
- * `autoLoadIntervalSeconds` method is used to indicate how often to do this.
601
- *
602
- * @param store The Store to persist.
603
- * @param loadUrl The endpoint that supports a `GET` method to load JSON.
604
- * @param saveUrl The endpoint that supports a `POST` method to save JSON.
605
- * @param autoLoadIntervalSeconds How often to poll the `loadUrl` when
606
- * automatically loading changes from the server.
607
- * @returns A reference to the new Persister object.
608
- * @example
609
- * This example creates a Persister object and persists the Store to a remote
610
- * server.
611
- *
612
- * ```js yolo
613
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
614
- * const persister = createRemotePersister(
615
- * store,
616
- * 'https://example.com/load',
617
- * 'https://example.com/save',
618
- * 5,
619
- * );
620
- *
621
- * await persister.save();
622
- * // Store JSON will be sent to server in a POST request.
623
- *
624
- * await persister.load();
625
- * // Store JSON will be fetched from server with a GET request.
626
- *
627
- * persister.destroy();
628
- * ```
629
- * @category Creation
630
- */
631
- export function createRemotePersister(
632
- store: Store,
633
- loadUrl: string,
634
- saveUrl: string,
635
- autoLoadIntervalSeconds: number,
636
- ): Persister;
637
-
638
- /**
639
- * The createFilePersister function creates a Persister object that can persist
640
- * the Store to a local file (in an appropriate environment).
641
- *
642
- * As well as providing a reference to the Store to persist, you must provide
643
- * `filePath` parameter which identifies the file to persist it to.
644
- *
645
- * @param store The Store to persist.
646
- * @param filePath The location of the local file to persist the Store to.
647
- * @returns A reference to the new Persister object.
648
- * @example
649
- * This example creates a Persister object and persists the Store to a local
650
- * file.
651
- *
652
- * ```js yolo
653
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
654
- * const persister = createFilePersister(store, '/app/persisted.json');
655
- *
656
- * await persister.save();
657
- * // Store JSON will be saved to the file.
658
- *
659
- * await persister.load();
660
- * // Store JSON will be loaded from the file.
661
- *
662
- * persister.destroy();
663
- * ```
664
- * @category Creation
665
- */
666
- export function createFilePersister(store: Store, filePath: string): Persister;
667
-
668
543
  /**
669
544
  * The createCustomPersister function creates a Persister object that you can
670
545
  * configure to persist the Store in any way you wish.
@@ -678,18 +553,28 @@ export function createFilePersister(store: Store, filePath: string): Persister;
678
553
  * covers. See those implementations for ideas on how to implement your own
679
554
  * Persister types.
680
555
  *
556
+ * This API changed in v4.0. Any custom persisters created on previous
557
+ * versions should be upgraded. Most notably, the `setPersisted` function
558
+ * parameter is provided with a `getContent` function to get the content from
559
+ * the Store itself, rather than being passed pre-serialized JSON. It also
560
+ * receives information about the changes made during a transaction. The
561
+ * `getPersisted` function must return the content (or nothing) rather than
562
+ * JSON. `addPersisterListener` has been renamed `addPersisterListener`, and
563
+ * `addPersisterListener` has been renamed `delPersisterListener`.
564
+ *
681
565
  * @param store The Store to persist.
682
- * @param getPersisted An asynchronous function which will fetch JSON from the
683
- * persistence layer (or `null` or `undefined` if not present).
684
- * @param setPersisted An asynchronous function which will send JSON to the
685
- * persistence layer.
686
- * @param startListeningToPersisted A function that will register a `didChange`
566
+ * @param getPersisted An asynchronous function which will fetch content from
567
+ * the persistence layer (or `undefined` if not present).
568
+ * @param setPersisted An asynchronous function which will send content to the
569
+ * persistence layer. Since v4.0, it receives functions for getting the Store
570
+ * content and information about the changes made during a transaction.
571
+ * @param addPersisterListener A function that will register a `listener`
687
572
  * listener on underlying changes to the persistence layer. You can return a
688
- * listening handle that will be provided again when `stopListeningToPersisted`
689
- * is called.
690
- * @param stopListeningToPersisted A function that will unregister the listener
691
- * from the underlying changes to the persistence layer. It receives whatever
692
- * was returned from your `startListeningToPersisted` implementation.
573
+ * listening handle that will be provided again when `delPersisterListener` is
574
+ * called.
575
+ * @param delPersisterListener A function that will unregister the listener from
576
+ * the underlying changes to the persistence layer. It receives whatever was
577
+ * returned from your `addPersisterListener` implementation.
693
578
  * @returns A reference to the new Persister object.
694
579
  * @example
695
580
  * This example creates a custom Persister object and persists the Store to a
@@ -702,9 +587,13 @@ export function createFilePersister(store: Store, filePath: string): Persister;
702
587
  *
703
588
  * const persister = createCustomPersister(
704
589
  * store,
705
- * async () => storeJson,
706
- * async (json) => (storeJson = json),
707
- * (didChange) => setInterval(didChange, 1000),
590
+ * async () => {
591
+ * try {
592
+ * return JSON.parse(storeJson);
593
+ * } catch {}
594
+ * },
595
+ * async (getContent) => (storeJson = JSON.stringify(getContent())),
596
+ * (listener) => setInterval(listener, 1000),
708
597
  * (interval) => clearInterval(interval),
709
598
  * );
710
599
  *
@@ -724,8 +613,11 @@ export function createFilePersister(store: Store, filePath: string): Persister;
724
613
  */
725
614
  export function createCustomPersister<ListeningHandle>(
726
615
  store: Store,
727
- getPersisted: () => Promise<string | null | undefined>,
728
- setPersisted: (json: string) => Promise<void>,
729
- startListeningToPersisted: (didChange: Callback) => ListeningHandle,
730
- stopListeningToPersisted: (listeningHandle: ListeningHandle) => void,
616
+ getPersisted: () => Promise<[Tables, Values] | undefined>,
617
+ setPersisted: (
618
+ getContent: () => [Tables, Values],
619
+ getTransactionChanges?: GetTransactionChanges,
620
+ ) => Promise<void>,
621
+ addPersisterListener: (listener: PersisterListener) => ListeningHandle,
622
+ delPersisterListener: (listeningHandle: ListeningHandle) => void,
731
623
  ): Persister;