tinybase 6.1.0-beta.1 → 6.1.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@types/common/index.d.ts +4 -4
- package/@types/common/with-schemas/index.d.ts +4 -4
- package/@types/mergeable-store/index.d.ts +45 -20
- package/@types/mergeable-store/with-schemas/index.d.ts +49 -21
- package/@types/persisters/index.d.ts +1 -1
- package/@types/persisters/with-schemas/index.d.ts +1 -1
- package/index.js +19 -11
- package/indexes/index.js +15 -3
- package/indexes/with-schemas/index.js +15 -3
- package/mergeable-store/index.js +4 -8
- package/mergeable-store/with-schemas/index.js +4 -8
- package/min/index.js +1 -1
- package/min/index.js.gz +0 -0
- package/min/indexes/index.js +1 -1
- package/min/indexes/index.js.gz +0 -0
- package/min/indexes/with-schemas/index.js +1 -1
- package/min/indexes/with-schemas/index.js.gz +0 -0
- package/min/mergeable-store/index.js +1 -1
- package/min/mergeable-store/index.js.gz +0 -0
- package/min/mergeable-store/with-schemas/index.js +1 -1
- package/min/mergeable-store/with-schemas/index.js.gz +0 -0
- package/min/with-schemas/index.js +1 -1
- package/min/with-schemas/index.js.gz +0 -0
- package/package.json +9 -9
- package/readme.md +2 -2
- package/with-schemas/index.js +19 -11
- package/@types/_internal/queries/index.d.cts +0 -0
- package/@types/_internal/queries/with-schemas/index.d.cts +0 -22
- package/@types/_internal/store/index.d.cts +0 -3
- package/@types/_internal/store/with-schemas/index.d.cts +0 -106
- package/@types/_internal/ui-react/index.d.cts +0 -0
- package/@types/_internal/ui-react/with-schemas/index.d.cts +0 -1130
- package/@types/checkpoints/index.d.cts +0 -1059
- package/@types/checkpoints/with-schemas/index.d.cts +0 -1151
- package/@types/common/index.d.cts +0 -158
- package/@types/common/with-schemas/index.d.cts +0 -158
- package/@types/index.d.cts +0 -17
- package/@types/indexes/index.d.cts +0 -1064
- package/@types/indexes/with-schemas/index.d.cts +0 -1210
- package/@types/mergeable-store/index.d.cts +0 -1139
- package/@types/mergeable-store/with-schemas/index.d.cts +0 -1628
- package/@types/metrics/index.d.cts +0 -917
- package/@types/metrics/with-schemas/index.d.cts +0 -1004
- package/@types/persisters/index.d.cts +0 -1877
- package/@types/persisters/persister-automerge/index.d.cts +0 -165
- package/@types/persisters/persister-automerge/with-schemas/index.d.cts +0 -180
- package/@types/persisters/persister-browser/index.d.cts +0 -185
- package/@types/persisters/persister-browser/with-schemas/index.d.cts +0 -208
- package/@types/persisters/persister-cr-sqlite-wasm/index.d.cts +0 -159
- package/@types/persisters/persister-cr-sqlite-wasm/with-schemas/index.d.cts +0 -178
- package/@types/persisters/persister-durable-object-storage/index.d.cts +0 -122
- package/@types/persisters/persister-durable-object-storage/with-schemas/index.d.cts +0 -136
- package/@types/persisters/persister-electric-sql/index.d.cts +0 -185
- package/@types/persisters/persister-electric-sql/with-schemas/index.d.cts +0 -204
- package/@types/persisters/persister-expo-sqlite/index.d.cts +0 -186
- package/@types/persisters/persister-expo-sqlite/with-schemas/index.d.cts +0 -205
- package/@types/persisters/persister-file/index.d.cts +0 -94
- package/@types/persisters/persister-file/with-schemas/index.d.cts +0 -107
- package/@types/persisters/persister-indexed-db/index.d.cts +0 -120
- package/@types/persisters/persister-indexed-db/with-schemas/index.d.cts +0 -135
- package/@types/persisters/persister-libsql/index.d.cts +0 -158
- package/@types/persisters/persister-libsql/with-schemas/index.d.cts +0 -177
- package/@types/persisters/persister-partykit-client/index.d.cts +0 -195
- package/@types/persisters/persister-partykit-client/with-schemas/index.d.cts +0 -210
- package/@types/persisters/persister-partykit-server/index.d.cts +0 -650
- package/@types/persisters/persister-partykit-server/with-schemas/index.d.cts +0 -695
- package/@types/persisters/persister-pglite/index.d.cts +0 -177
- package/@types/persisters/persister-pglite/with-schemas/index.d.cts +0 -196
- package/@types/persisters/persister-postgres/index.d.cts +0 -166
- package/@types/persisters/persister-postgres/with-schemas/index.d.cts +0 -185
- package/@types/persisters/persister-powersync/index.d.cts +0 -174
- package/@types/persisters/persister-powersync/with-schemas/index.d.cts +0 -193
- package/@types/persisters/persister-remote/index.d.cts +0 -117
- package/@types/persisters/persister-remote/with-schemas/index.d.cts +0 -133
- package/@types/persisters/persister-sqlite-wasm/index.d.cts +0 -175
- package/@types/persisters/persister-sqlite-wasm/with-schemas/index.d.cts +0 -195
- package/@types/persisters/persister-sqlite3/index.d.cts +0 -176
- package/@types/persisters/persister-sqlite3/with-schemas/index.d.cts +0 -195
- package/@types/persisters/persister-yjs/index.d.cts +0 -161
- package/@types/persisters/persister-yjs/with-schemas/index.d.cts +0 -176
- package/@types/persisters/with-schemas/index.d.cts +0 -2054
- package/@types/queries/index.d.cts +0 -3695
- package/@types/queries/with-schemas/index.d.cts +0 -4016
- package/@types/relationships/index.d.cts +0 -1320
- package/@types/relationships/with-schemas/index.d.cts +0 -1474
- package/@types/store/index.d.cts +0 -7598
- package/@types/store/with-schemas/index.d.cts +0 -9278
- package/@types/synchronizers/index.d.cts +0 -485
- package/@types/synchronizers/synchronizer-broadcast-channel/index.d.cts +0 -121
- package/@types/synchronizers/synchronizer-broadcast-channel/with-schemas/index.d.cts +0 -137
- package/@types/synchronizers/synchronizer-local/index.d.cts +0 -95
- package/@types/synchronizers/synchronizer-local/with-schemas/index.d.cts +0 -114
- package/@types/synchronizers/synchronizer-ws-client/index.d.cts +0 -160
- package/@types/synchronizers/synchronizer-ws-client/with-schemas/index.d.cts +0 -179
- package/@types/synchronizers/synchronizer-ws-server/index.d.cts +0 -736
- package/@types/synchronizers/synchronizer-ws-server/with-schemas/index.d.cts +0 -765
- package/@types/synchronizers/synchronizer-ws-server-durable-object/index.d.cts +0 -311
- package/@types/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.d.cts +0 -349
- package/@types/synchronizers/synchronizer-ws-server-simple/index.d.cts +0 -144
- package/@types/synchronizers/synchronizer-ws-server-simple/with-schemas/index.d.cts +0 -144
- package/@types/synchronizers/with-schemas/index.d.cts +0 -503
- package/@types/ui-react/index.d.cts +0 -16640
- package/@types/ui-react/with-schemas/index.d.cts +0 -17281
- package/@types/ui-react-dom/index.d.cts +0 -1862
- package/@types/ui-react-dom/with-schemas/index.d.cts +0 -1994
- package/@types/ui-react-inspector/index.d.cts +0 -79
- package/@types/ui-react-inspector/with-schemas/index.d.cts +0 -1985
- package/@types/with-schemas/index.d.cts +0 -17
|
@@ -1,1139 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The mergeable-store module contains the types, interfaces, and functions to
|
|
3
|
-
* work with MergeableStore objects, which provide merge and synchronization
|
|
4
|
-
* functionality.
|
|
5
|
-
*
|
|
6
|
-
* The main entry point to this module is the createMergeableStore function,
|
|
7
|
-
* which returns a new MergeableStore, a subtype of Store that can be merged
|
|
8
|
-
* with another with deterministic results.
|
|
9
|
-
*
|
|
10
|
-
* Please be aware that a lot of the types and methods exposed by this module
|
|
11
|
-
* are used internally within TinyBase itself (in particular the Synchronizer
|
|
12
|
-
* framework). They're documented here, but mostly for interest, and it is
|
|
13
|
-
* generally assumed that they won't be called directly by applications.
|
|
14
|
-
*
|
|
15
|
-
* As an application developer, it's more likely that you will continue to use
|
|
16
|
-
* the main Store methods for reading, writing, and listening to data, and rely
|
|
17
|
-
* on Synchronizer instances to keep the data in step with other places.
|
|
18
|
-
* @packageDocumentation
|
|
19
|
-
* @module mergeable-store
|
|
20
|
-
* @since v5.0.0
|
|
21
|
-
*/
|
|
22
|
-
import type {Id} from '../common/index.d.cts';
|
|
23
|
-
import type {
|
|
24
|
-
CellOrUndefined,
|
|
25
|
-
Content,
|
|
26
|
-
Store,
|
|
27
|
-
ValueOrUndefined,
|
|
28
|
-
} from '../store/index.d.cts';
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* The Hash type is used within the mergeable-store module to quickly compare
|
|
32
|
-
* the content of two objects.
|
|
33
|
-
*
|
|
34
|
-
* This is simply an alias for a JavaScript `number`.
|
|
35
|
-
*
|
|
36
|
-
* This type is mostly utilized internally within TinyBase itself and is
|
|
37
|
-
* generally assumed to be opaque to applications that use it.
|
|
38
|
-
* @category Stamps
|
|
39
|
-
* @since v5.0.0
|
|
40
|
-
*/
|
|
41
|
-
export type Hash = number;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* The Time type is used within the mergeable-store module to store the value of
|
|
45
|
-
* a hybrid logical clock (HLC).
|
|
46
|
-
*
|
|
47
|
-
* It is simply an alias for a JavaScript `string`, but it comprises three HLC
|
|
48
|
-
* parts: a logical timestamp, a sequence counter, and a client Id. It is
|
|
49
|
-
* designed to be string-sortable and unique across all of the systems involved
|
|
50
|
-
* in synchronizing a MergeableStore.
|
|
51
|
-
*
|
|
52
|
-
* This type is mostly utilized internally within TinyBase itself and is
|
|
53
|
-
* generally assumed to be opaque to applications that use it.
|
|
54
|
-
* @category Stamps
|
|
55
|
-
* @since v5.0.0
|
|
56
|
-
*/
|
|
57
|
-
export type Time = string;
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* The Stamp type is used as metadata to decide how to merge two different
|
|
61
|
-
* MergeableStore objects together.
|
|
62
|
-
*
|
|
63
|
-
* It describes a combination of a value (or object), a Time, and optionally a
|
|
64
|
-
* Hash, all in an array.
|
|
65
|
-
*
|
|
66
|
-
* This type is mostly utilized internally within TinyBase itself and is
|
|
67
|
-
* generally assumed to be opaque to applications that use it.
|
|
68
|
-
* @category Stamps
|
|
69
|
-
* @since v5.0.0
|
|
70
|
-
*/
|
|
71
|
-
export type Stamp<Thing, Hashed extends boolean = false> = Hashed extends true
|
|
72
|
-
? [thing: Thing, time: Time, hash: Hash]
|
|
73
|
-
: [thing: Thing, time?: Time];
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* The ContentHashes type is used to quickly compare the content of two
|
|
77
|
-
* MergeableStore objects.
|
|
78
|
-
*
|
|
79
|
-
* It is simply an array of two Hash types, one for the MergeableStore's Tables
|
|
80
|
-
* and one for its Values.
|
|
81
|
-
*
|
|
82
|
-
* This type is mostly utilized internally within TinyBase itself and is
|
|
83
|
-
* generally assumed to be opaque to applications that use it.
|
|
84
|
-
* @category Syncing
|
|
85
|
-
* @since v5.0.0
|
|
86
|
-
*/
|
|
87
|
-
export type ContentHashes = [tablesHash: Hash, valuesHash: Hash];
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* The TablesStamp type is used as metadata to decide how to merge two different
|
|
91
|
-
* sets of Tables together.
|
|
92
|
-
*
|
|
93
|
-
* This type is mostly utilized internally within TinyBase itself and is
|
|
94
|
-
* generally assumed to be opaque to applications that use it.
|
|
95
|
-
* @category Stamps
|
|
96
|
-
* @since v5.0.0
|
|
97
|
-
*/
|
|
98
|
-
export type TablesStamp<Hashed extends boolean = false> = Stamp<
|
|
99
|
-
{[tableId: Id]: TableStamp<Hashed>},
|
|
100
|
-
Hashed
|
|
101
|
-
>;
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* The TableHashes type is used to quickly compare the content of two sets of
|
|
105
|
-
* Table objects.
|
|
106
|
-
*
|
|
107
|
-
* It is simply an object of Hash types, one for each Table Id in the
|
|
108
|
-
* MergeableStore.
|
|
109
|
-
*
|
|
110
|
-
* This type is mostly utilized internally within TinyBase itself and is
|
|
111
|
-
* generally assumed to be opaque to applications that use it.
|
|
112
|
-
* @category Syncing
|
|
113
|
-
* @since v5.0.0
|
|
114
|
-
*/
|
|
115
|
-
export type TableHashes = {[tableId: Id]: Hash};
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* The TableStamp type is used as metadata to decide how to merge two different
|
|
119
|
-
* Table objects together.
|
|
120
|
-
*
|
|
121
|
-
* This type is mostly utilized internally within TinyBase itself and is
|
|
122
|
-
* generally assumed to be opaque to applications that use it.
|
|
123
|
-
* @category Stamps
|
|
124
|
-
* @since v5.0.0
|
|
125
|
-
*/
|
|
126
|
-
export type TableStamp<Hashed extends boolean = false> = Stamp<
|
|
127
|
-
{[rowId: Id]: RowStamp<Hashed>},
|
|
128
|
-
Hashed
|
|
129
|
-
>;
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* The RowHashes type is used to quickly compare the content of two sets of Row
|
|
133
|
-
* objects.
|
|
134
|
-
*
|
|
135
|
-
* It is simply a nested object of Hash types, one for each Row Id, for each
|
|
136
|
-
* TableId, in the MergeableStore.
|
|
137
|
-
*
|
|
138
|
-
* This type is mostly utilized internally within TinyBase itself and is
|
|
139
|
-
* generally assumed to be opaque to applications that use it.
|
|
140
|
-
* @category Syncing
|
|
141
|
-
* @since v5.0.0
|
|
142
|
-
*/
|
|
143
|
-
export type RowHashes = {[tableId: Id]: {[rowId: Id]: Hash}};
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* The RowStamp type is used as metadata to decide how to merge two different
|
|
147
|
-
* Row objects together.
|
|
148
|
-
*
|
|
149
|
-
* This type is mostly utilized internally within TinyBase itself and is
|
|
150
|
-
* generally assumed to be opaque to applications that use it.
|
|
151
|
-
* @category Stamps
|
|
152
|
-
* @since v5.0.0
|
|
153
|
-
*/
|
|
154
|
-
export type RowStamp<Hashed extends boolean = false> = Stamp<
|
|
155
|
-
{[cellId: Id]: CellStamp<Hashed>},
|
|
156
|
-
Hashed
|
|
157
|
-
>;
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* The CellHashes type is used to quickly compare the content of two sets of
|
|
161
|
-
* Cell objects.
|
|
162
|
-
*
|
|
163
|
-
* It is simply a nested object of Hash types, one for each Cell Id, for each
|
|
164
|
-
* Row Id, for each TableId, in the MergeableStore.
|
|
165
|
-
*
|
|
166
|
-
* This type is mostly utilized internally within TinyBase itself and is
|
|
167
|
-
* generally assumed to be opaque to applications that use it.
|
|
168
|
-
* @category Syncing
|
|
169
|
-
* @since v5.0.0
|
|
170
|
-
*/
|
|
171
|
-
export type CellHashes = {[tableId: Id]: {[rowId: Id]: {[cellId: Id]: Hash}}};
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* The CellStamp type is used as metadata to decide how to merge two different
|
|
175
|
-
* Cell objects together.
|
|
176
|
-
*
|
|
177
|
-
* This type is mostly utilized internally within TinyBase itself and is
|
|
178
|
-
* generally assumed to be opaque to applications that use it.
|
|
179
|
-
* @category Stamps
|
|
180
|
-
* @since v5.0.0
|
|
181
|
-
*/
|
|
182
|
-
export type CellStamp<Hashed extends boolean = false> = Stamp<
|
|
183
|
-
CellOrUndefined,
|
|
184
|
-
Hashed
|
|
185
|
-
>;
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* The ValuesStamp type is used as metadata to decide how to merge two different
|
|
189
|
-
* sets of Values together.
|
|
190
|
-
*
|
|
191
|
-
* This type is mostly utilized internally within TinyBase itself and is
|
|
192
|
-
* generally assumed to be opaque to applications that use it.
|
|
193
|
-
* @category Stamps
|
|
194
|
-
* @since v5.0.0
|
|
195
|
-
*/
|
|
196
|
-
export type ValuesStamp<Hashed extends boolean = false> = Stamp<
|
|
197
|
-
{[valueId: Id]: ValueStamp<Hashed>},
|
|
198
|
-
Hashed
|
|
199
|
-
>;
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* The ValueHashes type is used to quickly compare the content of two sets of
|
|
203
|
-
* Value objects.
|
|
204
|
-
*
|
|
205
|
-
* It is simply an object of Hash types, one for each Value Id in the
|
|
206
|
-
* MergeableStore.
|
|
207
|
-
*
|
|
208
|
-
* This type is mostly utilized internally within TinyBase itself and is
|
|
209
|
-
* generally assumed to be opaque to applications that use it.
|
|
210
|
-
* @category Syncing
|
|
211
|
-
* @since v5.0.0
|
|
212
|
-
*/
|
|
213
|
-
export type ValueHashes = {[valueId: Id]: Hash};
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* The ValueStamp type is used as metadata to decide how to merge two different
|
|
217
|
-
* Value objects together.
|
|
218
|
-
*
|
|
219
|
-
* This type is mostly utilized internally within TinyBase itself and is
|
|
220
|
-
* generally assumed to be opaque to applications that use it.
|
|
221
|
-
* @category Stamps
|
|
222
|
-
* @since v5.0.0
|
|
223
|
-
*/
|
|
224
|
-
export type ValueStamp<Hashed extends boolean = false> = Stamp<
|
|
225
|
-
ValueOrUndefined,
|
|
226
|
-
Hashed
|
|
227
|
-
>;
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* The MergeableContent type represents the content of a MergeableStore and the
|
|
231
|
-
* metadata about that content) required to merge it with another.
|
|
232
|
-
*
|
|
233
|
-
* It is simply an array of two Stamp types, one for the MergeableStore's Tables
|
|
234
|
-
* and one for its Values.
|
|
235
|
-
*
|
|
236
|
-
* This type is mostly utilized internally within TinyBase itself and is
|
|
237
|
-
* generally assumed to be opaque to applications that use it.
|
|
238
|
-
* @category Mergeable
|
|
239
|
-
* @since v5.0.0
|
|
240
|
-
*/
|
|
241
|
-
export type MergeableContent = [
|
|
242
|
-
mergeableTables: TablesStamp<true>,
|
|
243
|
-
mergeableValues: ValuesStamp<true>,
|
|
244
|
-
];
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* The MergeableChanges type represents changes to the content of a
|
|
248
|
-
* MergeableStore and the metadata about that content) required to merge it with
|
|
249
|
-
* another.
|
|
250
|
-
*
|
|
251
|
-
* It is simply an array of two Stamp types, one for changes to the
|
|
252
|
-
* MergeableStore's Tables and one for changes to its Values. A final `1` is
|
|
253
|
-
* used to distinguish it from a full MergeableContent object.
|
|
254
|
-
*
|
|
255
|
-
* This type is mostly utilized internally within TinyBase itself and is
|
|
256
|
-
* generally assumed to be opaque to applications that use it.
|
|
257
|
-
* @category Mergeable
|
|
258
|
-
* @since v5.0.0
|
|
259
|
-
*/
|
|
260
|
-
export type MergeableChanges<Hashed extends boolean = false> = [
|
|
261
|
-
mergeableTables: TablesStamp<Hashed>,
|
|
262
|
-
mergeableValues: ValuesStamp<Hashed>,
|
|
263
|
-
isChanges: 1,
|
|
264
|
-
];
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* The MergeableStore type represents a Store that carries with it sufficient
|
|
268
|
-
* metadata to be able to be merged with another MergeableStore with
|
|
269
|
-
* deterministic results.
|
|
270
|
-
*
|
|
271
|
-
* This is the key data type used when you need TinyBase data to be cleanly
|
|
272
|
-
* synchronized or merged with data elsewhere on the system, or on another
|
|
273
|
-
* system. It acts as a Conflict-Free Replicated Data Type (CRDT) which allows
|
|
274
|
-
* deterministic disambiguation of how changes to different instances should be
|
|
275
|
-
* merged.
|
|
276
|
-
*
|
|
277
|
-
* Please be aware that a lot of the methods exposed by this interface are used
|
|
278
|
-
* internally within TinyBase itself (in particular the Synchronizer framework).
|
|
279
|
-
* They're documented here, but mostly for interest, and it is generally assumed
|
|
280
|
-
* that they won't be called directly by applications.
|
|
281
|
-
*
|
|
282
|
-
* As an application developer, it's more likely that you will continue to use
|
|
283
|
-
* the main Store methods for reading, writing, and listening to data, and rely
|
|
284
|
-
* on Synchronizer instances to keep the data in step with other places.
|
|
285
|
-
*
|
|
286
|
-
* One possible exceptions is the merge method, which can be used to simply
|
|
287
|
-
* merge two co-located MergeableStore instances together.
|
|
288
|
-
* @example
|
|
289
|
-
* This example shows very simple usage of the MergeableStore: whereby two are
|
|
290
|
-
* created, updated with different data, and then merged with one another.
|
|
291
|
-
*
|
|
292
|
-
* ```js
|
|
293
|
-
* import {createMergeableStore} from 'tinybase';
|
|
294
|
-
*
|
|
295
|
-
* const localStore1 = createMergeableStore();
|
|
296
|
-
* const localStore2 = createMergeableStore();
|
|
297
|
-
*
|
|
298
|
-
* localStore1.setCell('pets', 'fido', 'color', 'brown');
|
|
299
|
-
* localStore2.setCell('pets', 'felix', 'color', 'black');
|
|
300
|
-
*
|
|
301
|
-
* localStore1.merge(localStore2);
|
|
302
|
-
*
|
|
303
|
-
* console.log(localStore1.getContent());
|
|
304
|
-
* // -> [{pets: {felix: {color: 'black'}, fido: {color: 'brown'}}}, {}]
|
|
305
|
-
*
|
|
306
|
-
* console.log(localStore2.getContent());
|
|
307
|
-
* // -> [{pets: {felix: {color: 'black'}, fido: {color: 'brown'}}}, {}]
|
|
308
|
-
*```
|
|
309
|
-
* @category Mergeable
|
|
310
|
-
* @since v5.0.0
|
|
311
|
-
*/
|
|
312
|
-
export interface MergeableStore extends Store {
|
|
313
|
-
//
|
|
314
|
-
/**
|
|
315
|
-
* The getMergeableContent method returns the full content of a
|
|
316
|
-
* MergeableStore, together with the metadata required to make it mergeable
|
|
317
|
-
* with another.
|
|
318
|
-
*
|
|
319
|
-
* The method is generally intended to be used internally within TinyBase
|
|
320
|
-
* itself and the return type is assumed to be opaque to applications that use
|
|
321
|
-
* it.
|
|
322
|
-
* @returns A MergeableContent object for the full content of the
|
|
323
|
-
* MergeableStore.
|
|
324
|
-
* @example
|
|
325
|
-
* This example creates a MergeableStore, sets some data, and then accesses
|
|
326
|
-
* the content and metadata required to make it mergeable.
|
|
327
|
-
*
|
|
328
|
-
* ```js
|
|
329
|
-
* import {createMergeableStore} from 'tinybase';
|
|
330
|
-
*
|
|
331
|
-
* const store = createMergeableStore('store1'); // !resetHlc
|
|
332
|
-
*
|
|
333
|
-
* store.setCell('pets', 'fido', 'color', 'brown');
|
|
334
|
-
*
|
|
335
|
-
* console.log(store.getMergeableContent());
|
|
336
|
-
* // ->
|
|
337
|
-
* [
|
|
338
|
-
* [
|
|
339
|
-
* {
|
|
340
|
-
* pets: [
|
|
341
|
-
* {
|
|
342
|
-
* fido: [
|
|
343
|
-
* {color: ['brown', 'Nn1JUF-----FnHIC', 923684530]},
|
|
344
|
-
* '',
|
|
345
|
-
* 851131566,
|
|
346
|
-
* ],
|
|
347
|
-
* },
|
|
348
|
-
* '',
|
|
349
|
-
* 518810247,
|
|
350
|
-
* ],
|
|
351
|
-
* },
|
|
352
|
-
* '',
|
|
353
|
-
* 784336119,
|
|
354
|
-
* ],
|
|
355
|
-
* [{}, '', 0],
|
|
356
|
-
* ];
|
|
357
|
-
* ```
|
|
358
|
-
* @category Getter
|
|
359
|
-
* @since v5.0.0
|
|
360
|
-
*/
|
|
361
|
-
getMergeableContent(): MergeableContent;
|
|
362
|
-
|
|
363
|
-
/**
|
|
364
|
-
* The getMergeableContentHashes method returns hashes for the full content of
|
|
365
|
-
* a MergeableStore.
|
|
366
|
-
*
|
|
367
|
-
* If two MergeableStore instances have different hashes, that indicates that
|
|
368
|
-
* the mergeable Tables or Values within them are different and should be
|
|
369
|
-
* synchronized.
|
|
370
|
-
*
|
|
371
|
-
* The method is generally intended to be used internally within TinyBase
|
|
372
|
-
* itself and the return type is assumed to be opaque to applications that use
|
|
373
|
-
* it.
|
|
374
|
-
* @returns A ContentHashes array for the hashes of the full content of the
|
|
375
|
-
* MergeableStore.
|
|
376
|
-
* @example
|
|
377
|
-
* This example creates a MergeableStore, sets some data, and then accesses
|
|
378
|
-
* the content hashes.
|
|
379
|
-
*
|
|
380
|
-
* ```js
|
|
381
|
-
* import {createMergeableStore} from 'tinybase';
|
|
382
|
-
*
|
|
383
|
-
* const store = createMergeableStore('store1'); // !resetHlc
|
|
384
|
-
*
|
|
385
|
-
* store.setCell('pets', 'fido', 'color', 'brown');
|
|
386
|
-
* console.log(store.getMergeableContentHashes());
|
|
387
|
-
* // -> [784336119, 0]
|
|
388
|
-
*
|
|
389
|
-
* store.setValue('open', true);
|
|
390
|
-
* console.log(store.getMergeableContentHashes());
|
|
391
|
-
* // -> [784336119, 2829789038]
|
|
392
|
-
* ```
|
|
393
|
-
* @category Syncing
|
|
394
|
-
* @since v5.0.0
|
|
395
|
-
*/
|
|
396
|
-
getMergeableContentHashes(): ContentHashes;
|
|
397
|
-
|
|
398
|
-
/**
|
|
399
|
-
* The getMergeableTableHashes method returns hashes for the Table objects in
|
|
400
|
-
* a MergeableStore.
|
|
401
|
-
*
|
|
402
|
-
* If two Table Ids have different hashes, that indicates that the content
|
|
403
|
-
* within them is different and should be synchronized.
|
|
404
|
-
*
|
|
405
|
-
* The method is generally intended to be used internally within TinyBase
|
|
406
|
-
* itself and the return type is assumed to be opaque to applications that use
|
|
407
|
-
* it.
|
|
408
|
-
* @returns A TableHashes object with the hashes of each Table in the
|
|
409
|
-
* MergeableStore.
|
|
410
|
-
* @example
|
|
411
|
-
* This example creates a MergeableStore, sets some data, and then accesses
|
|
412
|
-
* the Table hashes.
|
|
413
|
-
*
|
|
414
|
-
* ```js
|
|
415
|
-
* import {createMergeableStore} from 'tinybase';
|
|
416
|
-
*
|
|
417
|
-
* const store = createMergeableStore('store1'); // !resetHlc
|
|
418
|
-
*
|
|
419
|
-
* store.setCell('pets', 'fido', 'color', 'brown');
|
|
420
|
-
* console.log(store.getMergeableTableHashes());
|
|
421
|
-
* // -> {pets: 518810247}
|
|
422
|
-
*
|
|
423
|
-
* store.setCell('species', 'dog', 'price', 5);
|
|
424
|
-
* console.log(store.getMergeableTableHashes());
|
|
425
|
-
* // -> {pets: 518810247, species: 2324343240}
|
|
426
|
-
* ```
|
|
427
|
-
* @category Syncing
|
|
428
|
-
* @since v5.0.0
|
|
429
|
-
*/
|
|
430
|
-
getMergeableTableHashes(): TableHashes;
|
|
431
|
-
|
|
432
|
-
/**
|
|
433
|
-
* The getMergeableTableDiff method returns information about new and
|
|
434
|
-
* differing Table objects of a MergeableStore relative to another.
|
|
435
|
-
*
|
|
436
|
-
* The method is generally intended to be used internally within TinyBase
|
|
437
|
-
* itself and the return type is assumed to be opaque to applications that use
|
|
438
|
-
* it.
|
|
439
|
-
* @param otherTableHashes The TableHashes of another MergeableStore.
|
|
440
|
-
* @returns A pair of objects describing the new and differing Table objects
|
|
441
|
-
* of this MergeableStore relative to the other.
|
|
442
|
-
* @example
|
|
443
|
-
* This example creates two MergeableStores, sets some differing data, and
|
|
444
|
-
* then identifies the differences in the Table objects of one versus the
|
|
445
|
-
* other. Once they have been merged, the differences are empty.
|
|
446
|
-
*
|
|
447
|
-
* ```js
|
|
448
|
-
* import {createMergeableStore} from 'tinybase';
|
|
449
|
-
*
|
|
450
|
-
* const store1 = createMergeableStore('store1'); // !resetHlc
|
|
451
|
-
* store1.setTables({pets: {fido: {color: 'brown'}}});
|
|
452
|
-
*
|
|
453
|
-
* const store2 = createMergeableStore('store2');
|
|
454
|
-
* store2.setTables({
|
|
455
|
-
* pets: {fido: {species: 'dog'}},
|
|
456
|
-
* species: {dog: {price: 5}},
|
|
457
|
-
* });
|
|
458
|
-
*
|
|
459
|
-
* console.log(
|
|
460
|
-
* store2.getMergeableTableDiff(store1.getMergeableTableHashes()),
|
|
461
|
-
* );
|
|
462
|
-
* // ->
|
|
463
|
-
* [
|
|
464
|
-
* [{species: [{dog: [{price: [5, 'Nn1JUF----0CnH-J']}]}]}],
|
|
465
|
-
* {pets: 1212600658},
|
|
466
|
-
* ];
|
|
467
|
-
*
|
|
468
|
-
* store1.merge(store2);
|
|
469
|
-
*
|
|
470
|
-
* console.log(
|
|
471
|
-
* store2.getMergeableTableDiff(store1.getMergeableTableHashes()),
|
|
472
|
-
* );
|
|
473
|
-
* // -> [[{}], {}]
|
|
474
|
-
* ```
|
|
475
|
-
* @category Syncing
|
|
476
|
-
* @since v5.0.0
|
|
477
|
-
*/
|
|
478
|
-
getMergeableTableDiff(
|
|
479
|
-
otherTableHashes: TableHashes,
|
|
480
|
-
): [newTables: TablesStamp, differingTableHashes: TableHashes];
|
|
481
|
-
|
|
482
|
-
/**
|
|
483
|
-
* The getMergeableRowHashes method returns hashes for Row objects in a
|
|
484
|
-
* MergeableStore.
|
|
485
|
-
*
|
|
486
|
-
* If two Row Ids have different hashes, that indicates that the content
|
|
487
|
-
* within them is different and should be synchronized.
|
|
488
|
-
*
|
|
489
|
-
* The method is generally intended to be used internally within TinyBase
|
|
490
|
-
* itself and the return type is assumed to be opaque to applications that use
|
|
491
|
-
* it.
|
|
492
|
-
* @param otherTableHashes The TableHashes from the other MergeableStore so
|
|
493
|
-
* that the differences can be efficiently identified.
|
|
494
|
-
* @returns A RowHashes object with the hashes of each Row in the relevant
|
|
495
|
-
* Table objects of the MergeableStore.
|
|
496
|
-
* @example
|
|
497
|
-
* This example creates a MergeableStore, sets some data, and then accesses
|
|
498
|
-
* the Row hashes for the differing Table Ids.
|
|
499
|
-
*
|
|
500
|
-
* ```js
|
|
501
|
-
* import {createMergeableStore} from 'tinybase';
|
|
502
|
-
*
|
|
503
|
-
* const store1 = createMergeableStore('store1'); // !resetHlc
|
|
504
|
-
* store1.setTables({pets: {fido: {color: 'brown'}, felix: {color: 'tan'}}});
|
|
505
|
-
*
|
|
506
|
-
* const store2 = createMergeableStore('store2');
|
|
507
|
-
* store2.setTables({pets: {fido: {color: 'black'}, felix: {color: 'tan'}}});
|
|
508
|
-
*
|
|
509
|
-
* console.log(
|
|
510
|
-
* store1.getMergeableRowHashes(
|
|
511
|
-
* store2.getMergeableTableDiff(store1.getMergeableTableHashes())[1],
|
|
512
|
-
* ),
|
|
513
|
-
* );
|
|
514
|
-
* // -> {pets: {felix: 1683761402, fido: 851131566}}
|
|
515
|
-
* ```
|
|
516
|
-
* @category Syncing
|
|
517
|
-
* @since v5.0.0
|
|
518
|
-
*/
|
|
519
|
-
getMergeableRowHashes(otherTableHashes: TableHashes): RowHashes;
|
|
520
|
-
|
|
521
|
-
/**
|
|
522
|
-
* The getMergeableRowDiff method returns information about new and differing
|
|
523
|
-
* Row objects of a MergeableStore relative to another.
|
|
524
|
-
*
|
|
525
|
-
* The method is generally intended to be used internally within TinyBase
|
|
526
|
-
* itself and the return type is assumed to be opaque to applications that use
|
|
527
|
-
* it.
|
|
528
|
-
* @param otherTableRowHashes The RowHashes of another MergeableStore.
|
|
529
|
-
* @returns A pair of objects describing the new and differing Row objects of
|
|
530
|
-
* this MergeableStore relative to the other.
|
|
531
|
-
* @example
|
|
532
|
-
* This example creates two MergeableStores, sets some differing data, and
|
|
533
|
-
* then identifies the differences in the Row objects of one versus the other.
|
|
534
|
-
* Once they have been merged, the differences are empty.
|
|
535
|
-
*
|
|
536
|
-
* ```js
|
|
537
|
-
* import {createMergeableStore} from 'tinybase';
|
|
538
|
-
*
|
|
539
|
-
* const store1 = createMergeableStore('store1'); // !resetHlc
|
|
540
|
-
* store1.setTables({pets: {fido: {color: 'brown'}}});
|
|
541
|
-
*
|
|
542
|
-
* const store2 = createMergeableStore('store2');
|
|
543
|
-
* store2.setTables({pets: {fido: {color: 'black'}, felix: {color: 'tan'}}});
|
|
544
|
-
*
|
|
545
|
-
* console.log(
|
|
546
|
-
* store2.getMergeableRowDiff(
|
|
547
|
-
* store1.getMergeableRowHashes(
|
|
548
|
-
* store2.getMergeableTableDiff(store1.getMergeableTableHashes())[1],
|
|
549
|
-
* ),
|
|
550
|
-
* ),
|
|
551
|
-
* );
|
|
552
|
-
* // ->
|
|
553
|
-
* [
|
|
554
|
-
* [{pets: [{felix: [{color: ['tan', 'Nn1JUF----0CnH-J']}]}]}],
|
|
555
|
-
* {pets: {fido: 1038491054}},
|
|
556
|
-
* ];
|
|
557
|
-
*
|
|
558
|
-
* store1.merge(store2);
|
|
559
|
-
*
|
|
560
|
-
* console.log(
|
|
561
|
-
* store2.getMergeableRowDiff(
|
|
562
|
-
* store1.getMergeableRowHashes(
|
|
563
|
-
* store2.getMergeableTableDiff(store1.getMergeableTableHashes())[1],
|
|
564
|
-
* ),
|
|
565
|
-
* ),
|
|
566
|
-
* );
|
|
567
|
-
* // -> [[{}], {}]
|
|
568
|
-
* ```
|
|
569
|
-
* @category Syncing
|
|
570
|
-
* @since v5.0.0
|
|
571
|
-
*/
|
|
572
|
-
getMergeableRowDiff(
|
|
573
|
-
otherTableRowHashes: RowHashes,
|
|
574
|
-
): [newRows: TablesStamp, differingRowHashes: RowHashes];
|
|
575
|
-
|
|
576
|
-
/**
|
|
577
|
-
* The getMergeableCellHashes method returns hashes for Cell objects in a
|
|
578
|
-
* MergeableStore.
|
|
579
|
-
*
|
|
580
|
-
* If two Cell Ids have different hashes, that indicates that the content
|
|
581
|
-
* within them is different and should be synchronized.
|
|
582
|
-
*
|
|
583
|
-
* The method is generally intended to be used internally within TinyBase
|
|
584
|
-
* itself and the return type is assumed to be opaque to applications that use
|
|
585
|
-
* it.
|
|
586
|
-
* @param otherTableRowHashes The RowHashes from the other MergeableStore so
|
|
587
|
-
* that the differences can be efficiently identified.
|
|
588
|
-
* @returns A CellHashes object with the hashes of each Cell in the relevant
|
|
589
|
-
* Row objects of the MergeableStore.
|
|
590
|
-
* @example
|
|
591
|
-
* This example creates a MergeableStore, sets some data, and then accesses
|
|
592
|
-
* the Cell hashes for the differing Table Ids.
|
|
593
|
-
*
|
|
594
|
-
* ```js
|
|
595
|
-
* import {createMergeableStore} from 'tinybase';
|
|
596
|
-
*
|
|
597
|
-
* const store1 = createMergeableStore('store1'); // !resetHlc
|
|
598
|
-
* store1.setTables({pets: {fido: {color: 'brown', species: 'dog'}}});
|
|
599
|
-
*
|
|
600
|
-
* const store2 = createMergeableStore('store2');
|
|
601
|
-
* store2.setTables({pets: {fido: {color: 'black', species: 'dog'}}});
|
|
602
|
-
*
|
|
603
|
-
* console.log(
|
|
604
|
-
* store1.getMergeableCellHashes(
|
|
605
|
-
* store2.getMergeableRowDiff(
|
|
606
|
-
* store1.getMergeableRowHashes(
|
|
607
|
-
* store2.getMergeableTableDiff(store1.getMergeableTableHashes())[1],
|
|
608
|
-
* ),
|
|
609
|
-
* )[1],
|
|
610
|
-
* ),
|
|
611
|
-
* );
|
|
612
|
-
* // -> {pets: {fido: {color: 923684530, species: 227729753}}}
|
|
613
|
-
* ```
|
|
614
|
-
* @category Syncing
|
|
615
|
-
* @since v5.0.0
|
|
616
|
-
*/
|
|
617
|
-
getMergeableCellHashes(otherTableRowHashes: RowHashes): CellHashes;
|
|
618
|
-
|
|
619
|
-
/**
|
|
620
|
-
* The getMergeableCellDiff method returns information about new and differing
|
|
621
|
-
* Cell objects of a MergeableStore relative to another.
|
|
622
|
-
*
|
|
623
|
-
* The method is generally intended to be used internally within TinyBase
|
|
624
|
-
* itself and the return type is assumed to be opaque to applications that use
|
|
625
|
-
* it.
|
|
626
|
-
* @param otherTableRowCellHashes The CellHashes of another MergeableStore.
|
|
627
|
-
* @returns The new and differing Cell objects of this MergeableStore relative
|
|
628
|
-
* to the other.
|
|
629
|
-
* @example
|
|
630
|
-
* This example creates two MergeableStores, sets some differing data, and
|
|
631
|
-
* then identifies the differences in the Cell objects of one versus the
|
|
632
|
-
* other. Once they have been merged, the differences are empty.
|
|
633
|
-
*
|
|
634
|
-
* ```js
|
|
635
|
-
* import {createMergeableStore} from 'tinybase';
|
|
636
|
-
*
|
|
637
|
-
* const store1 = createMergeableStore('store1'); // !resetHlc
|
|
638
|
-
* store1.setTables({pets: {fido: {color: 'brown'}}});
|
|
639
|
-
*
|
|
640
|
-
* const store2 = createMergeableStore('store2');
|
|
641
|
-
* store2.setTables({pets: {fido: {color: 'black', species: 'dog'}}});
|
|
642
|
-
*
|
|
643
|
-
* console.log(
|
|
644
|
-
* store2.getMergeableCellDiff(
|
|
645
|
-
* store1.getMergeableCellHashes(
|
|
646
|
-
* store2.getMergeableRowDiff(
|
|
647
|
-
* store1.getMergeableRowHashes(
|
|
648
|
-
* store2.getMergeableTableDiff(
|
|
649
|
-
* store1.getMergeableTableHashes(),
|
|
650
|
-
* )[1],
|
|
651
|
-
* ),
|
|
652
|
-
* )[1],
|
|
653
|
-
* ),
|
|
654
|
-
* ),
|
|
655
|
-
* );
|
|
656
|
-
* // ->
|
|
657
|
-
* [
|
|
658
|
-
* {
|
|
659
|
-
* pets: [
|
|
660
|
-
* {
|
|
661
|
-
* fido: [
|
|
662
|
-
* {
|
|
663
|
-
* color: ['black', 'Nn1JUF-----CnH-J'],
|
|
664
|
-
* species: ['dog', 'Nn1JUF----0CnH-J'],
|
|
665
|
-
* },
|
|
666
|
-
* ],
|
|
667
|
-
* },
|
|
668
|
-
* ],
|
|
669
|
-
* },
|
|
670
|
-
* ];
|
|
671
|
-
*
|
|
672
|
-
* store1.merge(store2);
|
|
673
|
-
*
|
|
674
|
-
* console.log(
|
|
675
|
-
* store2.getMergeableCellDiff(
|
|
676
|
-
* store1.getMergeableCellHashes(
|
|
677
|
-
* store2.getMergeableRowDiff(
|
|
678
|
-
* store1.getMergeableRowHashes(
|
|
679
|
-
* store2.getMergeableTableDiff(
|
|
680
|
-
* store1.getMergeableTableHashes(),
|
|
681
|
-
* )[1],
|
|
682
|
-
* ),
|
|
683
|
-
* )[1],
|
|
684
|
-
* ),
|
|
685
|
-
* ),
|
|
686
|
-
* );
|
|
687
|
-
* // -> [{}]
|
|
688
|
-
* ```
|
|
689
|
-
* @category Syncing
|
|
690
|
-
* @since v5.0.0
|
|
691
|
-
*/
|
|
692
|
-
getMergeableCellDiff(otherTableRowCellHashes: CellHashes): TablesStamp;
|
|
693
|
-
|
|
694
|
-
/**
|
|
695
|
-
* The getMergeableValueHashes method returns hashes for the Value objects in
|
|
696
|
-
* a MergeableStore.
|
|
697
|
-
*
|
|
698
|
-
* If two Value Ids have different hashes, that indicates that the content
|
|
699
|
-
* within them is different and should be synchronized.
|
|
700
|
-
*
|
|
701
|
-
* The method is generally intended to be used internally within TinyBase
|
|
702
|
-
* itself and the return type is assumed to be opaque to applications that use
|
|
703
|
-
* it.
|
|
704
|
-
* @returns A ValueHashes object with the hashes of each Value in the
|
|
705
|
-
* MergeableStore.
|
|
706
|
-
* @example
|
|
707
|
-
* This example creates a MergeableStore, sets some data, and then accesses
|
|
708
|
-
* the Value hashes.
|
|
709
|
-
*
|
|
710
|
-
* ```js
|
|
711
|
-
* import {createMergeableStore} from 'tinybase';
|
|
712
|
-
*
|
|
713
|
-
* const store = createMergeableStore('store1'); // !resetHlc
|
|
714
|
-
*
|
|
715
|
-
* store.setValue('employees', 3);
|
|
716
|
-
* console.log(store.getMergeableValueHashes());
|
|
717
|
-
* // -> {employees: 1940815977}
|
|
718
|
-
*
|
|
719
|
-
* store.setValue('open', true);
|
|
720
|
-
* console.log(store.getMergeableValueHashes());
|
|
721
|
-
* // -> {employees: 1940815977, open: 3860530645}
|
|
722
|
-
* ```
|
|
723
|
-
* @category Syncing
|
|
724
|
-
* @since v5.0.0
|
|
725
|
-
*/
|
|
726
|
-
getMergeableValueHashes(): ValueHashes;
|
|
727
|
-
|
|
728
|
-
/**
|
|
729
|
-
* The getMergeableValueDiff method returns information about new and
|
|
730
|
-
* differing Value objects of a MergeableStore relative to another.
|
|
731
|
-
*
|
|
732
|
-
* The method is generally intended to be used internally within TinyBase
|
|
733
|
-
* itself and the return type is assumed to be opaque to applications that use
|
|
734
|
-
* it.
|
|
735
|
-
* @param otherValueHashes The ValueHashes of another MergeableStore.
|
|
736
|
-
* @returns The new and differing Value objects of this MergeableStore
|
|
737
|
-
* relative to the other.
|
|
738
|
-
* @example
|
|
739
|
-
* This example creates two MergeableStores, sets some differing data, and
|
|
740
|
-
* then identifies the differences in the Value objects of one versus the
|
|
741
|
-
* other. Once they have been merged, the differences are empty.
|
|
742
|
-
*
|
|
743
|
-
* ```js
|
|
744
|
-
* import {createMergeableStore} from 'tinybase';
|
|
745
|
-
*
|
|
746
|
-
* const store1 = createMergeableStore('store1'); // !resetHlc
|
|
747
|
-
* store1.setValues({employees: 3});
|
|
748
|
-
*
|
|
749
|
-
* const store2 = createMergeableStore('store2');
|
|
750
|
-
* store2.setValues({employees: 4, open: true});
|
|
751
|
-
*
|
|
752
|
-
* console.log(
|
|
753
|
-
* store2.getMergeableValueDiff(store1.getMergeableValueHashes()),
|
|
754
|
-
* );
|
|
755
|
-
* // ->
|
|
756
|
-
* [
|
|
757
|
-
* {
|
|
758
|
-
* employees: [4, 'Nn1JUF-----CnH-J'],
|
|
759
|
-
* open: [true, 'Nn1JUF----0CnH-J'],
|
|
760
|
-
* },
|
|
761
|
-
* ];
|
|
762
|
-
*
|
|
763
|
-
* store1.merge(store2);
|
|
764
|
-
*
|
|
765
|
-
* console.log(
|
|
766
|
-
* store2.getMergeableValueDiff(store1.getMergeableValueHashes()),
|
|
767
|
-
* );
|
|
768
|
-
* // -> [{}]
|
|
769
|
-
* ```
|
|
770
|
-
* @category Syncing
|
|
771
|
-
* @since v5.0.0
|
|
772
|
-
*/
|
|
773
|
-
getMergeableValueDiff(otherValueHashes: ValueHashes): ValuesStamp;
|
|
774
|
-
|
|
775
|
-
/**
|
|
776
|
-
* The setMergeableContent method sets the full content of a MergeableStore,
|
|
777
|
-
* together with the metadata required to make it mergeable with another.
|
|
778
|
-
*
|
|
779
|
-
* The method is generally intended to be used internally within TinyBase
|
|
780
|
-
* itself and the return type is assumed to be opaque to applications that use
|
|
781
|
-
* it.
|
|
782
|
-
* @param mergeableContent The full content and metadata of a MergeableStore.
|
|
783
|
-
* @returns A reference to the MergeableStore.
|
|
784
|
-
* @example
|
|
785
|
-
* This example creates a new MergeableStore and initializes it with
|
|
786
|
-
* the content and metadata from another.
|
|
787
|
-
*
|
|
788
|
-
* ```js
|
|
789
|
-
* import {createMergeableStore} from 'tinybase';
|
|
790
|
-
*
|
|
791
|
-
* const store1 = createMergeableStore('store1'); // !resetHlc
|
|
792
|
-
* store1.setValues({employees: 3});
|
|
793
|
-
* console.log(store1.getMergeableContent());
|
|
794
|
-
* // ->
|
|
795
|
-
* [
|
|
796
|
-
* [{}, '', 0],
|
|
797
|
-
* [{employees: [3, 'Nn1JUF-----FnHIC', 1940815977]}, '', 1260895905],
|
|
798
|
-
* ];
|
|
799
|
-
*
|
|
800
|
-
* const store2 = createMergeableStore('store2');
|
|
801
|
-
* store2.setMergeableContent(store1.getMergeableContent());
|
|
802
|
-
* console.log(store2.getMergeableContent());
|
|
803
|
-
* // ->
|
|
804
|
-
* [
|
|
805
|
-
* [{}, '', 0],
|
|
806
|
-
* [{employees: [3, 'Nn1JUF-----FnHIC', 1940815977]}, '', 1260895905],
|
|
807
|
-
* ];
|
|
808
|
-
* ```
|
|
809
|
-
* @category Setter
|
|
810
|
-
* @since v5.0.0
|
|
811
|
-
*/
|
|
812
|
-
setMergeableContent(mergeableContent: MergeableContent): MergeableStore;
|
|
813
|
-
|
|
814
|
-
/**
|
|
815
|
-
* The setDefaultContent method sets initial content of a MergeableStore.
|
|
816
|
-
*
|
|
817
|
-
* This differs from the setMergeableContent method in that all of the
|
|
818
|
-
* metadata is initialized with a empty HLC timestamp - meaning that any
|
|
819
|
-
* changes applied to it will 'win', yet ensuring that at least default,
|
|
820
|
-
* initial data exists.
|
|
821
|
-
*
|
|
822
|
-
* The method is generally intended to be used internally within TinyBase
|
|
823
|
-
* itself and the return type is assumed to be opaque to applications that use
|
|
824
|
-
* it.
|
|
825
|
-
*
|
|
826
|
-
* Since v5.4.2, this method can also take a function that returns the
|
|
827
|
-
* content.
|
|
828
|
-
* @param content An array containing the tabular and keyed-value data to be
|
|
829
|
-
* set, or a function that returns the array.
|
|
830
|
-
* @returns A reference to the MergeableStore.
|
|
831
|
-
* @example
|
|
832
|
-
* This example creates a new MergeableStore with default data, and
|
|
833
|
-
* demonstrates that it is overwritten with another MergeableStore's data on
|
|
834
|
-
* merge, even if the other MergeableStore was provisioned earlier.
|
|
835
|
-
*
|
|
836
|
-
* ```js
|
|
837
|
-
* import {createMergeableStore} from 'tinybase';
|
|
838
|
-
*
|
|
839
|
-
* const store1 = createMergeableStore('store1'); // !resetHlc
|
|
840
|
-
* store1.setValues({employees: 3});
|
|
841
|
-
*
|
|
842
|
-
* const store2 = createMergeableStore('store2');
|
|
843
|
-
* store2.setDefaultContent([{}, {employees: 4}]);
|
|
844
|
-
* console.log(store2.getMergeableContent());
|
|
845
|
-
* // -> [[{}, "", 0], [{"employees": [4, "", 2414055963]}, "", 3035768673]]
|
|
846
|
-
*
|
|
847
|
-
* store2.merge(store1);
|
|
848
|
-
* console.log(store2.getContent());
|
|
849
|
-
* // -> [{}, {employees: 3}]
|
|
850
|
-
* ```
|
|
851
|
-
* @category Setter
|
|
852
|
-
* @since v5.0.0
|
|
853
|
-
*/
|
|
854
|
-
setDefaultContent(content: Content | (() => Content)): MergeableStore;
|
|
855
|
-
|
|
856
|
-
/**
|
|
857
|
-
* The getTransactionMergeableChanges method returns the net meaningful
|
|
858
|
-
* changes that have been made to a MergeableStore during a transaction.
|
|
859
|
-
*
|
|
860
|
-
* The method is generally intended to be used internally within TinyBase
|
|
861
|
-
* itself and the return type is assumed to be opaque to applications that use
|
|
862
|
-
* it.
|
|
863
|
-
* @param withHashes Whether to include hashes in the output, defaulting to
|
|
864
|
-
* false.
|
|
865
|
-
* @returns A MergeableChanges object representing the changes, with hashes.
|
|
866
|
-
* @example
|
|
867
|
-
* This example makes changes to the MergeableStore. At the end of the
|
|
868
|
-
* transaction, detail about what changed is enumerated.
|
|
869
|
-
*
|
|
870
|
-
* ```js
|
|
871
|
-
* import {createMergeableStore} from 'tinybase';
|
|
872
|
-
*
|
|
873
|
-
* const store = createMergeableStore('store1'); // !resetHlc
|
|
874
|
-
* store.setTables({pets: {fido: {species: 'dog', color: 'brown'}}});
|
|
875
|
-
* store.setValues({open: true});
|
|
876
|
-
*
|
|
877
|
-
* store
|
|
878
|
-
* .startTransaction()
|
|
879
|
-
* .setCell('pets', 'fido', 'color', 'black')
|
|
880
|
-
* .setValue('open', false)
|
|
881
|
-
* .finishTransaction(() => {
|
|
882
|
-
* console.log(store.getTransactionMergeableChanges());
|
|
883
|
-
* });
|
|
884
|
-
* // ->
|
|
885
|
-
* [
|
|
886
|
-
* [{pets: [{fido: [{color: ['black', 'Nn1JUF----2FnHIC']}]}]}],
|
|
887
|
-
* [{open: [false, 'Nn1JUF----3FnHIC']}],
|
|
888
|
-
* 1,
|
|
889
|
-
* ];
|
|
890
|
-
* ```
|
|
891
|
-
* @category Transaction
|
|
892
|
-
* @since v5.0.0
|
|
893
|
-
*/
|
|
894
|
-
getTransactionMergeableChanges(withHashes?: boolean): MergeableChanges<true>;
|
|
895
|
-
|
|
896
|
-
/**
|
|
897
|
-
* The applyMergeableChanges method applies a set of mergeable changes or
|
|
898
|
-
* content to the MergeableStore.
|
|
899
|
-
*
|
|
900
|
-
* The method is generally intended to be used internally within TinyBase
|
|
901
|
-
* itself and the return type is assumed to be opaque to applications that use
|
|
902
|
-
* it.
|
|
903
|
-
* @param mergeableChanges The MergeableChanges or MergeableContent to apply
|
|
904
|
-
* to the MergeableStore.
|
|
905
|
-
* @returns A reference to the MergeableStore.
|
|
906
|
-
* @example
|
|
907
|
-
* This example applies a MergeableChanges object that sets a Cell and removes
|
|
908
|
-
* a Value.
|
|
909
|
-
*
|
|
910
|
-
* ```js
|
|
911
|
-
* import {createMergeableStore} from 'tinybase';
|
|
912
|
-
*
|
|
913
|
-
* const store = createMergeableStore('store1')
|
|
914
|
-
* .setTables({pets: {fido: {species: 'dog', color: 'brown'}}})
|
|
915
|
-
* .setValues({open: true});
|
|
916
|
-
*
|
|
917
|
-
* store.applyMergeableChanges([
|
|
918
|
-
* [{pets: [{fido: [{color: ['black', 'Nn1JUF----2FnHIC']}]}]}],
|
|
919
|
-
* [{open: [null, 'Nn1JUF----3FnHIC']}],
|
|
920
|
-
* 1,
|
|
921
|
-
* ]);
|
|
922
|
-
* console.log(store.getTables());
|
|
923
|
-
* // -> {pets: {fido: {species: 'dog', color: 'black'}}}
|
|
924
|
-
* console.log(store.getValues());
|
|
925
|
-
* // -> {}
|
|
926
|
-
* ```
|
|
927
|
-
* @category Setter
|
|
928
|
-
* @since v5.0.0
|
|
929
|
-
*/
|
|
930
|
-
applyMergeableChanges(
|
|
931
|
-
mergeableChanges: MergeableChanges | MergeableContent,
|
|
932
|
-
): MergeableStore;
|
|
933
|
-
|
|
934
|
-
/**
|
|
935
|
-
* The merge method is a convenience method that applies the mergeable content
|
|
936
|
-
* from two MergeableStores to each other in order to bring them to the same
|
|
937
|
-
* state.
|
|
938
|
-
*
|
|
939
|
-
* This method is symmetrical: applying `store1` to `store2` will have exactly
|
|
940
|
-
* the same effect as applying `store2` to `store1`.
|
|
941
|
-
* @param mergeableStore A reference to the other MergeableStore to merge with
|
|
942
|
-
* this one.
|
|
943
|
-
* @returns A reference to this MergeableStore.
|
|
944
|
-
* @example
|
|
945
|
-
* This example merges two MergeableStore objects together. Note how the final
|
|
946
|
-
* part of the timestamps on each Cell give you a clue that the data comes
|
|
947
|
-
* from changes made to different MergeableStore objects.
|
|
948
|
-
*
|
|
949
|
-
* ```js
|
|
950
|
-
* import {createMergeableStore} from 'tinybase';
|
|
951
|
-
*
|
|
952
|
-
* const store1 = createMergeableStore('store1');
|
|
953
|
-
* store1.setTables({pets: {fido: {species: 'dog', color: 'brown'}}});
|
|
954
|
-
*
|
|
955
|
-
* const store2 = createMergeableStore('store2');
|
|
956
|
-
* store2.setTables({pets: {felix: {species: 'cat', color: 'tan'}}});
|
|
957
|
-
*
|
|
958
|
-
* store1.merge(store2);
|
|
959
|
-
*
|
|
960
|
-
* console.log(store1.getContent());
|
|
961
|
-
* // ->
|
|
962
|
-
* [
|
|
963
|
-
* {
|
|
964
|
-
* pets: {
|
|
965
|
-
* felix: {color: 'tan', species: 'cat'},
|
|
966
|
-
* fido: {color: 'brown', species: 'dog'},
|
|
967
|
-
* },
|
|
968
|
-
* },
|
|
969
|
-
* {},
|
|
970
|
-
* ];
|
|
971
|
-
*
|
|
972
|
-
* console.log(store2.getContent());
|
|
973
|
-
* // ->
|
|
974
|
-
* [
|
|
975
|
-
* {
|
|
976
|
-
* pets: {
|
|
977
|
-
* felix: {color: 'tan', species: 'cat'},
|
|
978
|
-
* fido: {color: 'brown', species: 'dog'},
|
|
979
|
-
* },
|
|
980
|
-
* },
|
|
981
|
-
* {},
|
|
982
|
-
* ];
|
|
983
|
-
* console.log(store2.getMergeableContent());
|
|
984
|
-
* // ->
|
|
985
|
-
* [
|
|
986
|
-
* [
|
|
987
|
-
* {
|
|
988
|
-
* pets: [
|
|
989
|
-
* {
|
|
990
|
-
* felix: [
|
|
991
|
-
* {
|
|
992
|
-
* color: ['tan', 'Nn1JUF----0CnH-J', 2576658292],
|
|
993
|
-
* species: ['cat', 'Nn1JUF-----CnH-J', 3409607562],
|
|
994
|
-
* },
|
|
995
|
-
* '',
|
|
996
|
-
* 4146239216,
|
|
997
|
-
* ],
|
|
998
|
-
* fido: [
|
|
999
|
-
* {
|
|
1000
|
-
* color: ['brown', 'Nn1JUF----0FnHIC', 1240535355],
|
|
1001
|
-
* species: ['dog', 'Nn1JUF-----FnHIC', 290599168],
|
|
1002
|
-
* },
|
|
1003
|
-
* '',
|
|
1004
|
-
* 3989065420,
|
|
1005
|
-
* ],
|
|
1006
|
-
* },
|
|
1007
|
-
* '',
|
|
1008
|
-
* 4155188296,
|
|
1009
|
-
* ],
|
|
1010
|
-
* },
|
|
1011
|
-
* '',
|
|
1012
|
-
* 972931118,
|
|
1013
|
-
* ],
|
|
1014
|
-
* [{}, '', 0],
|
|
1015
|
-
* ];
|
|
1016
|
-
* ```
|
|
1017
|
-
* @category Setter
|
|
1018
|
-
* @since v5.0.0
|
|
1019
|
-
*/
|
|
1020
|
-
merge(mergeableStore: MergeableStore): MergeableStore;
|
|
1021
|
-
|
|
1022
|
-
/**
|
|
1023
|
-
* The isMergeable method lets you know if the Store is mergeable.
|
|
1024
|
-
*
|
|
1025
|
-
* This will always return false for a Store, and true for a MergeableStore.
|
|
1026
|
-
* @returns Whether the Store is mergeable.
|
|
1027
|
-
* @category Getter
|
|
1028
|
-
* @since v5.0.0
|
|
1029
|
-
*/
|
|
1030
|
-
isMergeable(): boolean;
|
|
1031
|
-
}
|
|
1032
|
-
|
|
1033
|
-
/**
|
|
1034
|
-
* The createMergeableStore function creates a MergeableStore, and is the main
|
|
1035
|
-
* entry point into the mergeable-store module.
|
|
1036
|
-
*
|
|
1037
|
-
* There is one optional parameter which is a uniqueId for the MergeableStore.
|
|
1038
|
-
* This is used to distinguish conflicting changes made in the same millisecond
|
|
1039
|
-
* by two different MergeableStore objects as its hash is added to the end of
|
|
1040
|
-
* the HLC timestamps. Generally this can be omitted unless you have a need for
|
|
1041
|
-
* deterministic HLCs, such as in a testing scenario. Otherwise, TinyBase will
|
|
1042
|
-
* assign a unique Id to the Store at the time of creation.
|
|
1043
|
-
* @returns A reference to the new MergeableStore.
|
|
1044
|
-
* @example
|
|
1045
|
-
* This example creates a MergeableStore.
|
|
1046
|
-
*
|
|
1047
|
-
* ```js
|
|
1048
|
-
* import {createMergeableStore} from 'tinybase';
|
|
1049
|
-
*
|
|
1050
|
-
* const store = createMergeableStore('store1');
|
|
1051
|
-
*
|
|
1052
|
-
* console.log(store.getContent());
|
|
1053
|
-
* // -> [{}, {}]
|
|
1054
|
-
* console.log(store.getMergeableContent());
|
|
1055
|
-
* // -> [[{}, '', 0], [{}, '', 0]]
|
|
1056
|
-
* ```
|
|
1057
|
-
* @example
|
|
1058
|
-
* This example creates a MergeableStore with some initial data:
|
|
1059
|
-
*
|
|
1060
|
-
* ```js
|
|
1061
|
-
* import {createMergeableStore} from 'tinybase';
|
|
1062
|
-
*
|
|
1063
|
-
* const store = createMergeableStore('store1').setTables({
|
|
1064
|
-
* pets: {fido: {species: 'dog'}},
|
|
1065
|
-
* });
|
|
1066
|
-
*
|
|
1067
|
-
* console.log(store.getContent());
|
|
1068
|
-
* // -> [{pets: {fido: {species: 'dog'}}}, {}]
|
|
1069
|
-
* console.log(store.getMergeableContent());
|
|
1070
|
-
* // ->
|
|
1071
|
-
* [
|
|
1072
|
-
* [
|
|
1073
|
-
* {
|
|
1074
|
-
* pets: [
|
|
1075
|
-
* {
|
|
1076
|
-
* fido: [
|
|
1077
|
-
* {species: ['dog', 'Nn1JUF-----FnHIC', 290599168]},
|
|
1078
|
-
* '',
|
|
1079
|
-
* 2682656941,
|
|
1080
|
-
* ],
|
|
1081
|
-
* },
|
|
1082
|
-
* '',
|
|
1083
|
-
* 2102515304,
|
|
1084
|
-
* ],
|
|
1085
|
-
* },
|
|
1086
|
-
* '',
|
|
1087
|
-
* 3506229770,
|
|
1088
|
-
* ],
|
|
1089
|
-
* [{}, '', 0],
|
|
1090
|
-
* ];
|
|
1091
|
-
* ```
|
|
1092
|
-
* @example
|
|
1093
|
-
* This example creates a MergeableStore with some initial data and a
|
|
1094
|
-
* TablesSchema:
|
|
1095
|
-
*
|
|
1096
|
-
* ```js
|
|
1097
|
-
* import {createMergeableStore} from 'tinybase';
|
|
1098
|
-
*
|
|
1099
|
-
* const store = createMergeableStore('store1')
|
|
1100
|
-
* .setTables({pets: {fido: {species: 'dog'}}})
|
|
1101
|
-
* .setTablesSchema({
|
|
1102
|
-
* pets: {
|
|
1103
|
-
* species: {type: 'string'},
|
|
1104
|
-
* sold: {type: 'boolean', default: false},
|
|
1105
|
-
* },
|
|
1106
|
-
* });
|
|
1107
|
-
*
|
|
1108
|
-
* console.log(store.getContent());
|
|
1109
|
-
* // -> [{pets: {fido: {sold: false, species: 'dog'}}}, {}]
|
|
1110
|
-
* console.log(store.getMergeableContent());
|
|
1111
|
-
* // ->
|
|
1112
|
-
* [
|
|
1113
|
-
* [
|
|
1114
|
-
* {
|
|
1115
|
-
* pets: [
|
|
1116
|
-
* {
|
|
1117
|
-
* fido: [
|
|
1118
|
-
* {
|
|
1119
|
-
* sold: [false, 'Nn1JUF----2FnHIC', 2603026204],
|
|
1120
|
-
* species: ['dog', 'Nn1JUF----1FnHIC', 2817056260],
|
|
1121
|
-
* },
|
|
1122
|
-
* '',
|
|
1123
|
-
* 2859424112,
|
|
1124
|
-
* ],
|
|
1125
|
-
* },
|
|
1126
|
-
* '',
|
|
1127
|
-
* 1640515891,
|
|
1128
|
-
* ],
|
|
1129
|
-
* },
|
|
1130
|
-
* '',
|
|
1131
|
-
* 2077041985,
|
|
1132
|
-
* ],
|
|
1133
|
-
* [{}, '', 0],
|
|
1134
|
-
* ];
|
|
1135
|
-
* ```
|
|
1136
|
-
* @category Creation
|
|
1137
|
-
* @since v5.0.0
|
|
1138
|
-
*/
|
|
1139
|
-
export function createMergeableStore(uniqueId?: Id): MergeableStore;
|