tinybase 6.1.0-beta.0 → 6.1.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 (155) hide show
  1. package/@types/_internal/ui-react/with-schemas/index.d.ts +1 -1
  2. package/@types/common/index.d.ts +4 -4
  3. package/@types/common/with-schemas/index.d.ts +4 -4
  4. package/@types/index.d.ts +1 -1
  5. package/@types/persisters/persister-automerge/index.d.ts +1 -1
  6. package/@types/persisters/persister-automerge/with-schemas/index.d.ts +1 -1
  7. package/@types/persisters/persister-cr-sqlite-wasm/index.d.ts +1 -1
  8. package/@types/persisters/persister-cr-sqlite-wasm/with-schemas/index.d.ts +1 -1
  9. package/@types/persisters/persister-electric-sql/index.d.ts +4 -4
  10. package/@types/persisters/persister-electric-sql/with-schemas/index.d.ts +4 -4
  11. package/@types/persisters/persister-expo-sqlite/index.d.ts +1 -1
  12. package/@types/persisters/persister-expo-sqlite/with-schemas/index.d.ts +1 -1
  13. package/@types/persisters/persister-libsql/index.d.ts +1 -1
  14. package/@types/persisters/persister-libsql/with-schemas/index.d.ts +1 -1
  15. package/@types/persisters/persister-partykit-client/index.d.ts +1 -1
  16. package/@types/persisters/persister-partykit-client/with-schemas/index.d.ts +1 -1
  17. package/@types/persisters/persister-partykit-server/index.d.ts +7 -7
  18. package/@types/persisters/persister-partykit-server/with-schemas/index.d.ts +1 -1
  19. package/@types/persisters/persister-pglite/index.d.ts +1 -1
  20. package/@types/persisters/persister-pglite/with-schemas/index.d.ts +1 -1
  21. package/@types/persisters/persister-postgres/index.d.ts +1 -1
  22. package/@types/persisters/persister-postgres/with-schemas/index.d.ts +1 -1
  23. package/@types/persisters/persister-powersync/index.d.ts +1 -1
  24. package/@types/persisters/persister-powersync/with-schemas/index.d.ts +1 -1
  25. package/@types/persisters/persister-sqlite3/index.d.ts +1 -1
  26. package/@types/persisters/persister-sqlite3/with-schemas/index.d.ts +1 -1
  27. package/@types/persisters/persister-yjs/index.d.ts +1 -1
  28. package/@types/persisters/persister-yjs/with-schemas/index.d.ts +1 -1
  29. package/@types/synchronizers/synchronizer-ws-client/index.d.ts +1 -1
  30. package/@types/synchronizers/synchronizer-ws-client/with-schemas/index.d.ts +1 -1
  31. package/@types/synchronizers/synchronizer-ws-server/index.d.ts +1 -1
  32. package/@types/synchronizers/synchronizer-ws-server/with-schemas/index.d.ts +1 -1
  33. package/@types/synchronizers/synchronizer-ws-server-durable-object/index.d.ts +1 -1
  34. package/@types/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.d.ts +1 -1
  35. package/@types/ui-react/index.d.ts +3 -3
  36. package/@types/ui-react/with-schemas/index.d.ts +1 -1
  37. package/@types/ui-react-dom/index.d.ts +1 -1
  38. package/@types/ui-react-dom/with-schemas/index.d.ts +1 -1
  39. package/@types/ui-react-inspector/with-schemas/index.d.ts +1 -1
  40. package/@types/with-schemas/index.d.ts +1 -1
  41. package/index.js +1579 -1567
  42. package/indexes/index.js +15 -3
  43. package/indexes/with-schemas/index.js +15 -3
  44. package/min/index.js +1 -1
  45. package/min/index.js.gz +0 -0
  46. package/min/indexes/index.js +1 -1
  47. package/min/indexes/index.js.gz +0 -0
  48. package/min/indexes/with-schemas/index.js +1 -1
  49. package/min/indexes/with-schemas/index.js.gz +0 -0
  50. package/min/persisters/index.js +1 -1
  51. package/min/persisters/index.js.gz +0 -0
  52. package/min/persisters/with-schemas/index.js +1 -1
  53. package/min/persisters/with-schemas/index.js.gz +0 -0
  54. package/min/ui-react/index.js +1 -1
  55. package/min/ui-react/index.js.gz +0 -0
  56. package/min/ui-react/with-schemas/index.js +1 -1
  57. package/min/ui-react/with-schemas/index.js.gz +0 -0
  58. package/min/with-schemas/index.js +1 -1
  59. package/min/with-schemas/index.js.gz +0 -0
  60. package/package.json +7 -10
  61. package/persisters/index.js +95 -95
  62. package/persisters/with-schemas/index.js +95 -95
  63. package/readme.md +13 -13
  64. package/releases.md +25 -25
  65. package/synchronizers/synchronizer-ws-server-durable-object/index.js +1 -1
  66. package/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +1 -1
  67. package/ui-react/index.js +64 -53
  68. package/ui-react/with-schemas/index.js +64 -53
  69. package/ui-react-dom/index.js +3 -3
  70. package/ui-react-dom/with-schemas/index.js +3 -3
  71. package/ui-react-inspector/index.js +4 -4
  72. package/ui-react-inspector/with-schemas/index.js +4 -4
  73. package/with-schemas/index.js +1579 -1567
  74. package/@types/_internal/queries/index.d.cts +0 -0
  75. package/@types/_internal/queries/with-schemas/index.d.cts +0 -22
  76. package/@types/_internal/store/index.d.cts +0 -3
  77. package/@types/_internal/store/with-schemas/index.d.cts +0 -106
  78. package/@types/_internal/ui-react/index.d.cts +0 -0
  79. package/@types/_internal/ui-react/with-schemas/index.d.cts +0 -1130
  80. package/@types/checkpoints/index.d.cts +0 -1059
  81. package/@types/checkpoints/with-schemas/index.d.cts +0 -1151
  82. package/@types/common/index.d.cts +0 -158
  83. package/@types/common/with-schemas/index.d.cts +0 -158
  84. package/@types/index.d.cts +0 -17
  85. package/@types/indexes/index.d.cts +0 -1064
  86. package/@types/indexes/with-schemas/index.d.cts +0 -1210
  87. package/@types/mergeable-store/index.d.cts +0 -1139
  88. package/@types/mergeable-store/with-schemas/index.d.cts +0 -1628
  89. package/@types/metrics/index.d.cts +0 -917
  90. package/@types/metrics/with-schemas/index.d.cts +0 -1004
  91. package/@types/persisters/index.d.cts +0 -1877
  92. package/@types/persisters/persister-automerge/index.d.cts +0 -165
  93. package/@types/persisters/persister-automerge/with-schemas/index.d.cts +0 -180
  94. package/@types/persisters/persister-browser/index.d.cts +0 -185
  95. package/@types/persisters/persister-browser/with-schemas/index.d.cts +0 -208
  96. package/@types/persisters/persister-cr-sqlite-wasm/index.d.cts +0 -159
  97. package/@types/persisters/persister-cr-sqlite-wasm/with-schemas/index.d.cts +0 -178
  98. package/@types/persisters/persister-durable-object-storage/index.d.cts +0 -122
  99. package/@types/persisters/persister-durable-object-storage/with-schemas/index.d.cts +0 -136
  100. package/@types/persisters/persister-electric-sql/index.d.cts +0 -185
  101. package/@types/persisters/persister-electric-sql/with-schemas/index.d.cts +0 -204
  102. package/@types/persisters/persister-expo-sqlite/index.d.cts +0 -186
  103. package/@types/persisters/persister-expo-sqlite/with-schemas/index.d.cts +0 -205
  104. package/@types/persisters/persister-file/index.d.cts +0 -94
  105. package/@types/persisters/persister-file/with-schemas/index.d.cts +0 -107
  106. package/@types/persisters/persister-indexed-db/index.d.cts +0 -120
  107. package/@types/persisters/persister-indexed-db/with-schemas/index.d.cts +0 -135
  108. package/@types/persisters/persister-libsql/index.d.cts +0 -158
  109. package/@types/persisters/persister-libsql/with-schemas/index.d.cts +0 -177
  110. package/@types/persisters/persister-partykit-client/index.d.cts +0 -195
  111. package/@types/persisters/persister-partykit-client/with-schemas/index.d.cts +0 -210
  112. package/@types/persisters/persister-partykit-server/index.d.cts +0 -650
  113. package/@types/persisters/persister-partykit-server/with-schemas/index.d.cts +0 -695
  114. package/@types/persisters/persister-pglite/index.d.cts +0 -177
  115. package/@types/persisters/persister-pglite/with-schemas/index.d.cts +0 -196
  116. package/@types/persisters/persister-postgres/index.d.cts +0 -166
  117. package/@types/persisters/persister-postgres/with-schemas/index.d.cts +0 -185
  118. package/@types/persisters/persister-powersync/index.d.cts +0 -174
  119. package/@types/persisters/persister-powersync/with-schemas/index.d.cts +0 -193
  120. package/@types/persisters/persister-remote/index.d.cts +0 -117
  121. package/@types/persisters/persister-remote/with-schemas/index.d.cts +0 -133
  122. package/@types/persisters/persister-sqlite-wasm/index.d.cts +0 -175
  123. package/@types/persisters/persister-sqlite-wasm/with-schemas/index.d.cts +0 -195
  124. package/@types/persisters/persister-sqlite3/index.d.cts +0 -176
  125. package/@types/persisters/persister-sqlite3/with-schemas/index.d.cts +0 -195
  126. package/@types/persisters/persister-yjs/index.d.cts +0 -161
  127. package/@types/persisters/persister-yjs/with-schemas/index.d.cts +0 -176
  128. package/@types/persisters/with-schemas/index.d.cts +0 -2054
  129. package/@types/queries/index.d.cts +0 -3695
  130. package/@types/queries/with-schemas/index.d.cts +0 -4016
  131. package/@types/relationships/index.d.cts +0 -1320
  132. package/@types/relationships/with-schemas/index.d.cts +0 -1474
  133. package/@types/store/index.d.cts +0 -7598
  134. package/@types/store/with-schemas/index.d.cts +0 -9278
  135. package/@types/synchronizers/index.d.cts +0 -485
  136. package/@types/synchronizers/synchronizer-broadcast-channel/index.d.cts +0 -121
  137. package/@types/synchronizers/synchronizer-broadcast-channel/with-schemas/index.d.cts +0 -137
  138. package/@types/synchronizers/synchronizer-local/index.d.cts +0 -95
  139. package/@types/synchronizers/synchronizer-local/with-schemas/index.d.cts +0 -114
  140. package/@types/synchronizers/synchronizer-ws-client/index.d.cts +0 -160
  141. package/@types/synchronizers/synchronizer-ws-client/with-schemas/index.d.cts +0 -179
  142. package/@types/synchronizers/synchronizer-ws-server/index.d.cts +0 -736
  143. package/@types/synchronizers/synchronizer-ws-server/with-schemas/index.d.cts +0 -765
  144. package/@types/synchronizers/synchronizer-ws-server-durable-object/index.d.cts +0 -311
  145. package/@types/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.d.cts +0 -349
  146. package/@types/synchronizers/synchronizer-ws-server-simple/index.d.cts +0 -144
  147. package/@types/synchronizers/synchronizer-ws-server-simple/with-schemas/index.d.cts +0 -144
  148. package/@types/synchronizers/with-schemas/index.d.cts +0 -503
  149. package/@types/ui-react/index.d.cts +0 -16640
  150. package/@types/ui-react/with-schemas/index.d.cts +0 -17281
  151. package/@types/ui-react-dom/index.d.cts +0 -1862
  152. package/@types/ui-react-dom/with-schemas/index.d.cts +0 -1994
  153. package/@types/ui-react-inspector/index.d.cts +0 -79
  154. package/@types/ui-react-inspector/with-schemas/index.d.cts +0 -1985
  155. package/@types/with-schemas/index.d.cts +0 -17
@@ -1,165 +0,0 @@
1
- /**
2
- * The persister-automerge module of the TinyBase project provides a way to save
3
- * and load Store data to and from an Automerge document.
4
- *
5
- * A single entry point, the createAutomergePersister function, is provided,
6
- * which returns a new Persister object that can bind a Store to a provided
7
- * Automerge document handle (and in turn, its document).
8
- * @see Third-Party CRDT Persistence guide
9
- * @packageDocumentation
10
- * @module persister-automerge
11
- * @since v4.0.0
12
- */
13
- import type {Store} from '../../store/index.d.cts';
14
- import type {Persister} from '../index.d.cts';
15
- import type {DocHandle} from '@automerge/automerge-repo';
16
-
17
- /**
18
- * The AutomergePersister interface represents a Persister that lets you save
19
- * and load Store data to and from an Automerge document.
20
- *
21
- * You should use the createAutomergePersister function to create an
22
- * AutomergePersister object.
23
- *
24
- * It is a minor extension to the Persister interface and simply provides an
25
- * extra getDocHandle method for accessing the Automerge document handler the
26
- * Store is being persisted to.
27
- * @category Persister
28
- * @since v4.3.14
29
- */
30
- export interface AutomergePersister extends Persister {
31
- /**
32
- * The getDocHandle method returns the Automerge document handler the Store is
33
- * being persisted to.
34
- * @returns The Automerge document handler.
35
- * @example
36
- * This example creates a Persister object against a newly-created Store and
37
- * then gets the Automerge document handler back out again.
38
- *
39
- * ```js
40
- * import {Repo} from '@automerge/automerge-repo';
41
- * import {createStore} from 'tinybase';
42
- * import {createAutomergePersister} from 'tinybase/persisters/persister-automerge';
43
- *
44
- * const docHandler = new Repo({network: []}).create();
45
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
46
- * const persister = createAutomergePersister(store, docHandler);
47
- *
48
- * console.log(persister.getDocHandle() == docHandler);
49
- * // -> true
50
- *
51
- * persister.destroy();
52
- * ```
53
- * @category Getter
54
- * @since v4.3.14
55
- */
56
- getDocHandle(): DocHandle<any>;
57
- }
58
-
59
- /**
60
- * The createAutomergePersister function creates an AutomergePersister object
61
- * that can persist the Store to an Automerge document.
62
- *
63
- * An AutomergePersister only supports regular Store objects, and cannot be used
64
- * to persist the metadata of a MergeableStore.
65
- *
66
- * As well as providing a reference to the Store to persist, you must provide
67
- * the Automerge document handler to persist it with.
68
- * @param store The Store to persist.
69
- * @param docHandle The Automerge document handler to persist the Store with.
70
- * @param docMapName The name of the map used inside the Automerge document to
71
- * sync the Store to (which otherwise will default to 'tinybase').
72
- * @param onIgnoredError An optional handler for the errors that the Persister
73
- * would otherwise ignore when trying to save or load data. This is suitable for
74
- * debugging persistence issues in a development environment, since v4.0.4.
75
- * @returns A reference to the new AutomergePersister object.
76
- * @example
77
- * This example creates a AutomergePersister object and persists the Store to an
78
- * Automerge document.
79
- *
80
- * ```js
81
- * import {Repo} from '@automerge/automerge-repo';
82
- * import {createStore} from 'tinybase';
83
- * import {createAutomergePersister} from 'tinybase/persisters/persister-automerge';
84
- *
85
- * const docHandler = new Repo({network: []}).create();
86
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
87
- * const persister = createAutomergePersister(store, docHandler);
88
- *
89
- * await persister.save();
90
- * // Store will be saved to the document.
91
- *
92
- * console.log(await docHandler.doc());
93
- * // -> {tinybase: {t: {pets: {fido: {species: 'dog'}}}, v: {}}}
94
- *
95
- * persister.destroy();
96
- * ```
97
- * @example
98
- * This more complex example uses Automerge networking to keep two Store objects
99
- * (each with their own Persister objects and Automerge documents) in sync with
100
- * each other using a network.
101
- *
102
- * ```js
103
- * import {Repo} from '@automerge/automerge-repo';
104
- * import {BroadcastChannelNetworkAdapter} from '@automerge/automerge-repo-network-broadcastchannel';
105
- * import {createStore} from 'tinybase';
106
- * import {createAutomergePersister} from 'tinybase/persisters/persister-automerge';
107
- *
108
- * // Bind the first Store to a network-enabled automerge-repo
109
- * const repo1 = new Repo({
110
- * network: [new BroadcastChannelNetworkAdapter()],
111
- * });
112
- * const docHandler1 = repo1.create();
113
- * await docHandler1.doc();
114
- * const store1 = createStore();
115
- * const persister1 = createAutomergePersister(store1, docHandler1);
116
- * await persister1.startAutoLoad();
117
- * await persister1.startAutoSave();
118
- *
119
- * // Bind the second Store to a different network-enabled automerge-repo
120
- * const repo2 = new Repo({
121
- * network: [new BroadcastChannelNetworkAdapter()],
122
- * });
123
- * const docHandler2 = repo2.find(docHandler1.documentId);
124
- * await docHandler2.doc();
125
- * const store2 = createStore();
126
- * const persister2 = createAutomergePersister(store2, docHandler2);
127
- * await persister2.startAutoLoad();
128
- * await persister2.startAutoSave();
129
- *
130
- * // A function that waits briefly and then for the documents to synchronize
131
- * // with each other, merely for the purposes of sequentiality in this example.
132
- * const syncDocsWait = async () => {
133
- * await new Promise((resolve) => setTimeout(() => resolve(0), 100));
134
- * await docHandler1.doc();
135
- * await docHandler2.doc();
136
- * };
137
- *
138
- * // Wait for the documents to synchronize in their initial state.
139
- * await syncDocsWait();
140
- *
141
- * // Make a change to each of the two Stores.
142
- * store1.setTables({pets: {fido: {species: 'dog'}}});
143
- * store2.setValues({open: true});
144
- *
145
- * // Wait for the documents to synchronize in their new state.
146
- * await syncDocsWait();
147
- *
148
- * // Ensure the Stores are in sync.
149
- * console.log(store1.getContent());
150
- * // -> [{pets: {fido: {species: 'dog'}}}, {open: true}]
151
- * console.log(store2.getContent());
152
- * // -> [{pets: {fido: {species: 'dog'}}}, {open: true}]
153
- *
154
- * persister1.destroy();
155
- * persister2.destroy();
156
- * ```
157
- * @category Creation
158
- * @since v4.0.0
159
- */
160
- export function createAutomergePersister(
161
- store: Store,
162
- docHandle: DocHandle<any>,
163
- docMapName?: string,
164
- onIgnoredError?: (error: any) => void,
165
- ): AutomergePersister;
@@ -1,180 +0,0 @@
1
- /**
2
- * The persister-automerge module of the TinyBase project provides a way to save
3
- * and load Store data to and from an Automerge document.
4
- *
5
- * A single entry point, the createAutomergePersister function, is provided,
6
- * which returns a new Persister object that can bind a Store to a provided
7
- * Automerge document handle (and in turn, its document).
8
- * @see Third-Party CRDT Persistence guide
9
- * @packageDocumentation
10
- * @module persister-automerge
11
- * @since v4.0.0
12
- */
13
- import type {
14
- OptionalSchemas,
15
- Store,
16
- } from '../../../store/with-schemas/index.d.cts';
17
- import type {Persister} from '../../with-schemas/index.d.cts';
18
- import type {DocHandle} from '@automerge/automerge-repo';
19
-
20
- /**
21
- * The AutomergePersister interface represents a Persister that lets you save
22
- * and load Store data to and from an Automerge document.
23
- *
24
- * You should use the createAutomergePersister function to create an
25
- * AutomergePersister object.
26
- *
27
- * It is a minor extension to the Persister interface and simply provides an
28
- * extra getDocHandle method for accessing the Automerge document handler the
29
- * Store is being persisted to.
30
- * @category Persister
31
- * @since v4.3.14
32
- */
33
- export interface AutomergePersister<Schemas extends OptionalSchemas>
34
- extends Persister<Schemas> {
35
- /**
36
- * The getDocHandle method returns the Automerge document handler the Store is
37
- * being persisted to.
38
- * @returns The Automerge document handler.
39
- * @example
40
- * This example creates a Persister object against a newly-created Store and
41
- * then gets the Automerge document handler back out again.
42
- *
43
- * ```js
44
- * import {Repo} from '@automerge/automerge-repo';
45
- * import {createStore} from 'tinybase';
46
- * import {createAutomergePersister} from 'tinybase/persisters/persister-automerge';
47
- *
48
- * const docHandler = new Repo({network: []}).create();
49
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
50
- * const persister = createAutomergePersister(store, docHandler);
51
- *
52
- * console.log(persister.getDocHandle() == docHandler);
53
- * // -> true
54
- *
55
- * persister.destroy();
56
- * ```
57
- * @category Getter
58
- * @since v4.3.14
59
- */
60
- getDocHandle(): DocHandle<any>;
61
- }
62
-
63
- /**
64
- * The createAutomergePersister function creates an AutomergePersister object
65
- * that can persist the Store to an Automerge document.
66
- *
67
- * This has schema-based typing. The following is a simplified representation:
68
- *
69
- * ```ts override
70
- * createAutomergePersister(
71
- * store: Store,
72
- * docHandle: DocHandle<any>,
73
- * docMapName?: string,
74
- * onIgnoredError?: (error: any) => void,
75
- * ): AutomergePersister;
76
- * ```
77
- *
78
- * An AutomergePersister only supports regular Store objects, and cannot be used
79
- * to persist the metadata of a MergeableStore.
80
- *
81
- * As well as providing a reference to the Store to persist, you must provide
82
- * the Automerge document handler to persist it with.
83
- * @param store The Store to persist.
84
- * @param docHandle The Automerge document handler to persist the Store with.
85
- * @param docMapName The name of the map used inside the Automerge document to
86
- * sync the Store to (which otherwise will default to 'tinybase').
87
- * @param onIgnoredError An optional handler for the errors that the Persister
88
- * would otherwise ignore when trying to save or load data. This is suitable for
89
- * debugging persistence issues in a development environment, since v4.0.4.
90
- * @returns A reference to the new AutomergePersister object.
91
- * @example
92
- * This example creates a AutomergePersister object and persists the Store to an
93
- * Automerge document.
94
- *
95
- * ```js
96
- * import {Repo} from '@automerge/automerge-repo';
97
- * import {createStore} from 'tinybase';
98
- * import {createAutomergePersister} from 'tinybase/persisters/persister-automerge';
99
- *
100
- * const docHandler = new Repo({network: []}).create();
101
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
102
- * const persister = createAutomergePersister(store, docHandler);
103
- *
104
- * await persister.save();
105
- * // Store will be saved to the document.
106
- *
107
- * console.log(await docHandler.doc());
108
- * // -> {tinybase: {t: {pets: {fido: {species: 'dog'}}}, v: {}}}
109
- *
110
- * persister.destroy();
111
- * ```
112
- * @example
113
- * This more complex example uses Automerge networking to keep two Store objects
114
- * (each with their own Persister objects and Automerge documents) in sync with
115
- * each other using a network.
116
- *
117
- * ```js
118
- * import {Repo} from '@automerge/automerge-repo';
119
- * import {BroadcastChannelNetworkAdapter} from '@automerge/automerge-repo-network-broadcastchannel';
120
- * import {createStore} from 'tinybase';
121
- * import {createAutomergePersister} from 'tinybase/persisters/persister-automerge';
122
- *
123
- * // Bind the first Store to a network-enabled automerge-repo
124
- * const repo1 = new Repo({
125
- * network: [new BroadcastChannelNetworkAdapter()],
126
- * });
127
- * const docHandler1 = repo1.create();
128
- * await docHandler1.doc();
129
- * const store1 = createStore();
130
- * const persister1 = createAutomergePersister(store1, docHandler1);
131
- * await persister1.startAutoLoad();
132
- * await persister1.startAutoSave();
133
- *
134
- * // Bind the second Store to a different network-enabled automerge-repo
135
- * const repo2 = new Repo({
136
- * network: [new BroadcastChannelNetworkAdapter()],
137
- * });
138
- * const docHandler2 = repo2.find(docHandler1.documentId);
139
- * await docHandler2.doc();
140
- * const store2 = createStore();
141
- * const persister2 = createAutomergePersister(store2, docHandler2);
142
- * await persister2.startAutoLoad();
143
- * await persister2.startAutoSave();
144
- *
145
- * // A function that waits briefly and then for the documents to synchronize
146
- * // with each other, merely for the purposes of sequentiality in this example.
147
- * const syncDocsWait = async () => {
148
- * await new Promise((resolve) => setTimeout(() => resolve(0), 100));
149
- * await docHandler1.doc();
150
- * await docHandler2.doc();
151
- * };
152
- *
153
- * // Wait for the documents to synchronize in their initial state.
154
- * await syncDocsWait();
155
- *
156
- * // Make a change to each of the two Stores.
157
- * store1.setTables({pets: {fido: {species: 'dog'}}});
158
- * store2.setValues({open: true});
159
- *
160
- * // Wait for the documents to synchronize in their new state.
161
- * await syncDocsWait();
162
- *
163
- * // Ensure the Stores are in sync.
164
- * console.log(store1.getContent());
165
- * // -> [{pets: {fido: {species: 'dog'}}}, {open: true}]
166
- * console.log(store2.getContent());
167
- * // -> [{pets: {fido: {species: 'dog'}}}, {open: true}]
168
- *
169
- * persister1.destroy();
170
- * persister2.destroy();
171
- * ```
172
- * @category Creation
173
- * @since v4.0.0
174
- */
175
- export function createAutomergePersister<Schemas extends OptionalSchemas>(
176
- store: Store<Schemas>,
177
- docHandle: DocHandle<any>,
178
- docMapName?: string,
179
- onIgnoredError?: (error: any) => void,
180
- ): AutomergePersister<Schemas>;
@@ -1,185 +0,0 @@
1
- /**
2
- * The persister-browser module of the TinyBase project lets you save and load
3
- * Store data to and from browser storage.
4
- *
5
- * Two entry points are provided, each of which returns a new Persister object
6
- * that can load and save a Store:
7
- *
8
- * - The createSessionPersister function returns a Persister that uses the
9
- * browser's session storage.
10
- * - The createLocalPersister function returns a Persister that uses the
11
- * browser's local storage.
12
- * @see Persistence guides
13
- * @packageDocumentation
14
- * @module persister-browser
15
- * @since v1.0.0
16
- */
17
- import type {MergeableStore} from '../../mergeable-store/index.d.cts';
18
- import type {Store} from '../../store/index.d.cts';
19
- import type {Persister, Persists} from '../index.d.cts';
20
-
21
- /**
22
- * The SessionPersister interface represents a Persister that lets you save and
23
- * load Store data to and from the browser's session storage.
24
- *
25
- * You should use the createSessionPersister function to create a
26
- * SessionPersister object.
27
- *
28
- * It is a minor extension to the Persister interface and simply provides an
29
- * extra getStorageName method for accessing the unique key of the storage
30
- * location the Store is being persisted to.
31
- * @category Persister
32
- * @since v4.3.14
33
- */
34
- export interface SessionPersister
35
- extends Persister<Persists.StoreOrMergeableStore> {
36
- /**
37
- * The getStorageName method returns the unique key of the storage location
38
- * the Store is being persisted to.
39
- * @returns The unique key of the storage location.
40
- * @example
41
- * This example creates a Persister object against a newly-created Store and
42
- * then gets the unique key of the storage location back out again.
43
- *
44
- * ```js
45
- * import {createStore} from 'tinybase';
46
- * import {createSessionPersister} from 'tinybase/persisters/persister-browser';
47
- *
48
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
49
- * const persister = createSessionPersister(store, 'pets');
50
- *
51
- * console.log(persister.getStorageName());
52
- * // -> 'pets'
53
- *
54
- * persister.destroy();
55
- * ```
56
- * @category Getter
57
- * @since v4.3.14
58
- */
59
- getStorageName(): string;
60
- }
61
-
62
- /**
63
- * The LocalPersister interface represents a Persister that lets you save and
64
- * load Store data to and from the browser's local storage.
65
- *
66
- * It is a minor extension to the Persister interface and simply provides an
67
- * extra getStorageName method for accessing the unique key of the storage
68
- * location the Store is being persisted to.
69
- *
70
- * You should use the createLocalPersister function to create a LocalPersister
71
- * object.
72
- * @category Persister
73
- * @since v4.3.14
74
- */
75
- export interface LocalPersister
76
- extends Persister<Persists.StoreOrMergeableStore> {
77
- /**
78
- * The getStorageName method returns the unique key of the storage location
79
- * the Store is being persisted to.
80
- * @returns The unique key of the storage location.
81
- * @example
82
- * This example creates a Persister object against a newly-created Store and
83
- * then gets the unique key of the storage location back out again.
84
- *
85
- * ```js
86
- * import {createStore} from 'tinybase';
87
- * import {createLocalPersister} from 'tinybase/persisters/persister-browser';
88
- *
89
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
90
- * const persister = createLocalPersister(store, 'pets');
91
- *
92
- * console.log(persister.getStorageName());
93
- * // -> 'pets'
94
- *
95
- * persister.destroy();
96
- * ```
97
- * @category Getter
98
- * @since v4.3.14
99
- */
100
- getStorageName(): string;
101
- }
102
-
103
- /**
104
- * The createSessionPersister function creates a SessionPersister object that
105
- * can persist the Store to the browser's session storage.
106
- *
107
- * A SessionPersister supports both regular Store and MergeableStore objects.
108
- *
109
- * As well as providing a reference to the Store to persist, you must provide a
110
- * `storageName` parameter which is unique to your application. This is the key
111
- * that the browser uses to identify the storage location.
112
- * @param store The Store or MergeableStore to persist.
113
- * @param storageName The unique key to identify the storage location.
114
- * @param onIgnoredError An optional handler for the errors that the Persister
115
- * would otherwise ignore when trying to save or load data. This is suitable for
116
- * debugging persistence issues in a development environment, since v4.0.4.
117
- * @returns A reference to the new SessionPersister object.
118
- * @example
119
- * This example creates a SessionPersister object and persists the Store to the
120
- * browser's session storage.
121
- *
122
- * ```js
123
- * import {createStore} from 'tinybase';
124
- * import {createSessionPersister} from 'tinybase/persisters/persister-browser';
125
- *
126
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
127
- * const persister = createSessionPersister(store, 'pets');
128
- *
129
- * await persister.save();
130
- * console.log(sessionStorage.getItem('pets'));
131
- * // -> '[{"pets":{"fido":{"species":"dog"}}},{}]'
132
- *
133
- * persister.destroy();
134
- * sessionStorage.clear();
135
- * ```
136
- * @category Creation
137
- * @since v1.0.0
138
- */
139
- export function createSessionPersister(
140
- store: Store | MergeableStore,
141
- storageName: string,
142
- onIgnoredError?: (error: any) => void,
143
- ): SessionPersister;
144
-
145
- /**
146
- * The createLocalPersister function creates a LocalPersister object that can
147
- * persist the Store to the browser's local storage.
148
- *
149
- * A LocalPersister supports both regular Store and MergeableStore objects.
150
- *
151
- * As well as providing a reference to the Store to persist, you must provide a
152
- * `storageName` parameter which is unique to your application. This is the key
153
- * that the browser uses to identify the storage location.
154
- * @param store The Store or MergeableStore to persist.
155
- * @param storageName The unique key to identify the storage location.
156
- * @param onIgnoredError An optional handler for the errors that the Persister
157
- * would otherwise ignore when trying to save or load data. This is suitable for
158
- * debugging persistence issues in a development environment, since v4.0.4.
159
- * @returns A reference to the new LocalPersister object.
160
- * @example
161
- * This example creates a LocalPersister object and persists the Store to the
162
- * browser's local storage.
163
- *
164
- * ```js
165
- * import {createStore} from 'tinybase';
166
- * import {createLocalPersister} from 'tinybase/persisters/persister-browser';
167
- *
168
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
169
- * const persister = createLocalPersister(store, 'pets');
170
- *
171
- * await persister.save();
172
- * console.log(localStorage.getItem('pets'));
173
- * // -> '[{"pets":{"fido":{"species":"dog"}}},{}]'
174
- *
175
- * persister.destroy();
176
- * localStorage.clear();
177
- * ```
178
- * @category Creation
179
- * @since v1.0.0
180
- */
181
- export function createLocalPersister(
182
- store: Store | MergeableStore,
183
- storageName: string,
184
- onIgnoredError?: (error: any) => void,
185
- ): LocalPersister;