tinybase 6.1.0-beta.1 → 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 (98) hide show
  1. package/@types/common/index.d.ts +4 -4
  2. package/@types/common/with-schemas/index.d.ts +4 -4
  3. package/index.js +15 -3
  4. package/indexes/index.js +15 -3
  5. package/indexes/with-schemas/index.js +15 -3
  6. package/min/index.js +1 -1
  7. package/min/index.js.gz +0 -0
  8. package/min/indexes/index.js +1 -1
  9. package/min/indexes/index.js.gz +0 -0
  10. package/min/indexes/with-schemas/index.js +1 -1
  11. package/min/indexes/with-schemas/index.js.gz +0 -0
  12. package/min/with-schemas/index.js +1 -1
  13. package/min/with-schemas/index.js.gz +0 -0
  14. package/package.json +7 -7
  15. package/readme.md +1 -1
  16. package/with-schemas/index.js +15 -3
  17. package/@types/_internal/queries/index.d.cts +0 -0
  18. package/@types/_internal/queries/with-schemas/index.d.cts +0 -22
  19. package/@types/_internal/store/index.d.cts +0 -3
  20. package/@types/_internal/store/with-schemas/index.d.cts +0 -106
  21. package/@types/_internal/ui-react/index.d.cts +0 -0
  22. package/@types/_internal/ui-react/with-schemas/index.d.cts +0 -1130
  23. package/@types/checkpoints/index.d.cts +0 -1059
  24. package/@types/checkpoints/with-schemas/index.d.cts +0 -1151
  25. package/@types/common/index.d.cts +0 -158
  26. package/@types/common/with-schemas/index.d.cts +0 -158
  27. package/@types/index.d.cts +0 -17
  28. package/@types/indexes/index.d.cts +0 -1064
  29. package/@types/indexes/with-schemas/index.d.cts +0 -1210
  30. package/@types/mergeable-store/index.d.cts +0 -1139
  31. package/@types/mergeable-store/with-schemas/index.d.cts +0 -1628
  32. package/@types/metrics/index.d.cts +0 -917
  33. package/@types/metrics/with-schemas/index.d.cts +0 -1004
  34. package/@types/persisters/index.d.cts +0 -1877
  35. package/@types/persisters/persister-automerge/index.d.cts +0 -165
  36. package/@types/persisters/persister-automerge/with-schemas/index.d.cts +0 -180
  37. package/@types/persisters/persister-browser/index.d.cts +0 -185
  38. package/@types/persisters/persister-browser/with-schemas/index.d.cts +0 -208
  39. package/@types/persisters/persister-cr-sqlite-wasm/index.d.cts +0 -159
  40. package/@types/persisters/persister-cr-sqlite-wasm/with-schemas/index.d.cts +0 -178
  41. package/@types/persisters/persister-durable-object-storage/index.d.cts +0 -122
  42. package/@types/persisters/persister-durable-object-storage/with-schemas/index.d.cts +0 -136
  43. package/@types/persisters/persister-electric-sql/index.d.cts +0 -185
  44. package/@types/persisters/persister-electric-sql/with-schemas/index.d.cts +0 -204
  45. package/@types/persisters/persister-expo-sqlite/index.d.cts +0 -186
  46. package/@types/persisters/persister-expo-sqlite/with-schemas/index.d.cts +0 -205
  47. package/@types/persisters/persister-file/index.d.cts +0 -94
  48. package/@types/persisters/persister-file/with-schemas/index.d.cts +0 -107
  49. package/@types/persisters/persister-indexed-db/index.d.cts +0 -120
  50. package/@types/persisters/persister-indexed-db/with-schemas/index.d.cts +0 -135
  51. package/@types/persisters/persister-libsql/index.d.cts +0 -158
  52. package/@types/persisters/persister-libsql/with-schemas/index.d.cts +0 -177
  53. package/@types/persisters/persister-partykit-client/index.d.cts +0 -195
  54. package/@types/persisters/persister-partykit-client/with-schemas/index.d.cts +0 -210
  55. package/@types/persisters/persister-partykit-server/index.d.cts +0 -650
  56. package/@types/persisters/persister-partykit-server/with-schemas/index.d.cts +0 -695
  57. package/@types/persisters/persister-pglite/index.d.cts +0 -177
  58. package/@types/persisters/persister-pglite/with-schemas/index.d.cts +0 -196
  59. package/@types/persisters/persister-postgres/index.d.cts +0 -166
  60. package/@types/persisters/persister-postgres/with-schemas/index.d.cts +0 -185
  61. package/@types/persisters/persister-powersync/index.d.cts +0 -174
  62. package/@types/persisters/persister-powersync/with-schemas/index.d.cts +0 -193
  63. package/@types/persisters/persister-remote/index.d.cts +0 -117
  64. package/@types/persisters/persister-remote/with-schemas/index.d.cts +0 -133
  65. package/@types/persisters/persister-sqlite-wasm/index.d.cts +0 -175
  66. package/@types/persisters/persister-sqlite-wasm/with-schemas/index.d.cts +0 -195
  67. package/@types/persisters/persister-sqlite3/index.d.cts +0 -176
  68. package/@types/persisters/persister-sqlite3/with-schemas/index.d.cts +0 -195
  69. package/@types/persisters/persister-yjs/index.d.cts +0 -161
  70. package/@types/persisters/persister-yjs/with-schemas/index.d.cts +0 -176
  71. package/@types/persisters/with-schemas/index.d.cts +0 -2054
  72. package/@types/queries/index.d.cts +0 -3695
  73. package/@types/queries/with-schemas/index.d.cts +0 -4016
  74. package/@types/relationships/index.d.cts +0 -1320
  75. package/@types/relationships/with-schemas/index.d.cts +0 -1474
  76. package/@types/store/index.d.cts +0 -7598
  77. package/@types/store/with-schemas/index.d.cts +0 -9278
  78. package/@types/synchronizers/index.d.cts +0 -485
  79. package/@types/synchronizers/synchronizer-broadcast-channel/index.d.cts +0 -121
  80. package/@types/synchronizers/synchronizer-broadcast-channel/with-schemas/index.d.cts +0 -137
  81. package/@types/synchronizers/synchronizer-local/index.d.cts +0 -95
  82. package/@types/synchronizers/synchronizer-local/with-schemas/index.d.cts +0 -114
  83. package/@types/synchronizers/synchronizer-ws-client/index.d.cts +0 -160
  84. package/@types/synchronizers/synchronizer-ws-client/with-schemas/index.d.cts +0 -179
  85. package/@types/synchronizers/synchronizer-ws-server/index.d.cts +0 -736
  86. package/@types/synchronizers/synchronizer-ws-server/with-schemas/index.d.cts +0 -765
  87. package/@types/synchronizers/synchronizer-ws-server-durable-object/index.d.cts +0 -311
  88. package/@types/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.d.cts +0 -349
  89. package/@types/synchronizers/synchronizer-ws-server-simple/index.d.cts +0 -144
  90. package/@types/synchronizers/synchronizer-ws-server-simple/with-schemas/index.d.cts +0 -144
  91. package/@types/synchronizers/with-schemas/index.d.cts +0 -503
  92. package/@types/ui-react/index.d.cts +0 -16640
  93. package/@types/ui-react/with-schemas/index.d.cts +0 -17281
  94. package/@types/ui-react-dom/index.d.cts +0 -1862
  95. package/@types/ui-react-dom/with-schemas/index.d.cts +0 -1994
  96. package/@types/ui-react-inspector/index.d.cts +0 -79
  97. package/@types/ui-react-inspector/with-schemas/index.d.cts +0 -1985
  98. package/@types/with-schemas/index.d.cts +0 -17
@@ -1,1628 +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 {
23
- CellIdFromSchema,
24
- TableIdFromSchema,
25
- ValueIdFromSchema,
26
- } from '../../_internal/store/with-schemas/index.d.cts';
27
- import type {Id} from '../../common/with-schemas/index.d.cts';
28
- import type {
29
- CellOrUndefined,
30
- Content,
31
- NoSchemas,
32
- NoTablesSchema,
33
- NoValuesSchema,
34
- OptionalSchemas,
35
- OptionalTablesSchema,
36
- OptionalValuesSchema,
37
- Store,
38
- TablesSchema,
39
- ValueOrUndefined,
40
- ValuesSchema,
41
- } from '../../store/with-schemas/index.d.cts';
42
-
43
- /**
44
- * The Hash type is used within the mergeable-store module to quickly compare
45
- * the content of two objects.
46
- *
47
- * This is simply an alias for a JavaScript `number`.
48
- *
49
- * This type is mostly utilized internally within TinyBase itself and is
50
- * generally assumed to be opaque to applications that use it.
51
- * @category Stamps
52
- * @since v5.0.0
53
- */
54
- export type Hash = number;
55
-
56
- /**
57
- * The Time type is used within the mergeable-store module to store the value of
58
- * a hybrid logical clock (HLC).
59
- *
60
- * It is simply an alias for a JavaScript `string`, but it comprises three HLC
61
- * parts: a logical timestamp, a sequence counter, and a client Id. It is
62
- * designed to be string-sortable and unique across all of the systems involved
63
- * in synchronizing a MergeableStore.
64
- *
65
- * This type is mostly utilized internally within TinyBase itself and is
66
- * generally assumed to be opaque to applications that use it.
67
- * @category Stamps
68
- * @since v5.0.0
69
- */
70
- export type Time = string;
71
-
72
- /**
73
- * The Stamp type is used as metadata to decide how to merge two different
74
- * MergeableStore objects together.
75
- *
76
- * It describes a combination of a value (or object), a Time, and optionally a
77
- * Hash, all in an array.
78
- *
79
- * This type is mostly utilized internally within TinyBase itself and is
80
- * generally assumed to be opaque to applications that use it.
81
- * @category Stamps
82
- * @since v5.0.0
83
- */
84
- export type Stamp<Thing, Hashed extends boolean = false> = Hashed extends true
85
- ? [thing: Thing, time: Time, hash: Hash]
86
- : [thing: Thing, time?: Time];
87
-
88
- /**
89
- * The ContentHashes type is used to quickly compare the content of two
90
- * MergeableStore objects.
91
- *
92
- * It is simply an array of two Hash types, one for the MergeableStore's Tables
93
- * and one for its Values.
94
- *
95
- * This type is mostly utilized internally within TinyBase itself and is
96
- * generally assumed to be opaque to applications that use it.
97
- * @category Syncing
98
- * @since v5.0.0
99
- */
100
- export type ContentHashes = [tablesHash: Hash, valuesHash: Hash];
101
-
102
- /**
103
- * The TablesStamp type is used as metadata to decide how to merge two different
104
- * sets of Tables together.
105
- *
106
- * This has schema-based typing. The following is a simplified representation:
107
- *
108
- * ```ts override
109
- * export type TablesStamp<Hashed extends boolean = false> = Stamp<
110
- * {[tableId: Id]: TableStamp<Hashed>},
111
- * Hashed
112
- * >;
113
- * ```
114
- *
115
- * This type is mostly utilized internally within TinyBase itself and is
116
- * generally assumed to be opaque to applications that use it.
117
- * @category Stamps
118
- * @since v5.0.0
119
- */
120
- export type TablesStamp<
121
- Schema extends OptionalTablesSchema,
122
- Hashed extends boolean = false,
123
- > = Stamp<
124
- {
125
- [TableId in TableIdFromSchema<Schema>]?: TableStamp<
126
- Schema,
127
- TableId,
128
- Hashed
129
- >;
130
- },
131
- Hashed
132
- >;
133
-
134
- /**
135
- * The TableHashes type is used to quickly compare the content of two sets of
136
- * Table objects.
137
- *
138
- * This has schema-based typing. The following is a simplified representation:
139
- *
140
- * ```ts override
141
- * {[tableId: Id]: Hash};
142
- * ```
143
- *
144
- * It is simply an object of Hash types, one for each Table Id in the
145
- * MergeableStore.
146
- *
147
- * This type is mostly utilized internally within TinyBase itself and is
148
- * generally assumed to be opaque to applications that use it.
149
- * @category Syncing
150
- * @since v5.0.0
151
- */
152
- export type TableHashes<Schema extends OptionalTablesSchema> = {
153
- [TableId in TableIdFromSchema<Schema>]?: Hash;
154
- };
155
-
156
- /**
157
- * The TableStamp type is used as metadata to decide how to merge two different
158
- * Table objects together.
159
- *
160
- * This has schema-based typing. The following is a simplified representation:
161
- *
162
- * ```ts override
163
- * export type TableStamp<Hashed extends boolean = false> = Stamp<
164
- * {[rowId: Id]: RowStamp<Hashed>},
165
- * Hashed
166
- * >;
167
- * ```
168
- *
169
- * This type is mostly utilized internally within TinyBase itself and is
170
- * generally assumed to be opaque to applications that use it.
171
- * @category Stamps
172
- * @since v5.0.0
173
- */
174
- export type TableStamp<
175
- Schema extends OptionalTablesSchema,
176
- TableId extends TableIdFromSchema<Schema>,
177
- Hashed extends boolean = false,
178
- > = Stamp<{[rowId: Id]: RowStamp<Schema, TableId, Hashed>}, Hashed>;
179
-
180
- /**
181
- * The RowHashes type is used to quickly compare the content of two sets of Row
182
- * objects.
183
- *
184
- * This has schema-based typing. The following is a simplified representation:
185
- *
186
- * ```ts override
187
- * {[tableId: Id]: {[rowId: Id]: Hash}};
188
- * ```
189
- *
190
- * It is simply a nested object of Hash types, one for each Row Id, for each
191
- * TableId, in the MergeableStore.
192
- *
193
- * This type is mostly utilized internally within TinyBase itself and is
194
- * generally assumed to be opaque to applications that use it.
195
- * @category Syncing
196
- * @since v5.0.0
197
- */
198
- export type RowHashes<Schema extends OptionalTablesSchema> = {
199
- [TableId in TableIdFromSchema<Schema>]?: {[rowId: Id]: Hash};
200
- };
201
-
202
- /**
203
- * The RowStamp type is used as metadata to decide how to merge two different
204
- * Row objects together.
205
- *
206
- * This has schema-based typing. The following is a simplified representation:
207
- *
208
- * ```ts override
209
- * export type RowStamp<Hashed extends boolean = false> = Stamp<
210
- * {[cellId: Id]: CellStamp<Hashed>},
211
- * Hashed
212
- * >;
213
- * ```
214
- *
215
- * This type is mostly utilized internally within TinyBase itself and is
216
- * generally assumed to be opaque to applications that use it.
217
- * @category Stamps
218
- * @since v5.0.0
219
- */
220
- export type RowStamp<
221
- Schema extends OptionalTablesSchema,
222
- TableId extends TableIdFromSchema<Schema>,
223
- Hashed extends boolean = false,
224
- > = Stamp<
225
- {
226
- [CellId in CellIdFromSchema<Schema, TableId>]?: CellStamp<
227
- Schema,
228
- TableId,
229
- CellId,
230
- Hashed
231
- >;
232
- },
233
- Hashed
234
- >;
235
-
236
- /**
237
- * The CellHashes type is used to quickly compare the content of two sets of
238
- * Cell objects.
239
- *
240
- * This has schema-based typing. The following is a simplified representation:
241
- *
242
- * ```ts override
243
- * {[tableId: Id]: {[rowId: Id]: {[cellId: Id]: Hash}}};
244
- * ```
245
- *
246
- * It is simply a nested object of Hash types, one for each Cell Id, for each
247
- * Row Id, for each TableId, in the MergeableStore.
248
- *
249
- * This type is mostly utilized internally within TinyBase itself and is
250
- * generally assumed to be opaque to applications that use it.
251
- * @category Syncing
252
- * @since v5.0.0
253
- */
254
- export type CellHashes<Schema extends OptionalTablesSchema> = {
255
- [TableId in TableIdFromSchema<Schema>]?: {
256
- [rowId: Id]: {[CellId in CellIdFromSchema<Schema, TableId>]?: Hash};
257
- };
258
- };
259
-
260
- /**
261
- * The CellStamp type is used as metadata to decide how to merge two different
262
- * Cell objects together.
263
- *
264
- * This has schema-based typing. The following is a simplified representation:
265
- *
266
- * ```ts override
267
- * export type CellStamp<Hashed extends boolean = false> = Stamp<
268
- * CellOrUndefined,
269
- * Hashed
270
- * >;
271
- * ```
272
- *
273
- * This type is mostly utilized internally within TinyBase itself and is
274
- * generally assumed to be opaque to applications that use it.
275
- * @category Stamps
276
- * @since v5.0.0
277
- */
278
- export type CellStamp<
279
- Schema extends OptionalTablesSchema,
280
- TableId extends TableIdFromSchema<Schema>,
281
- CellId extends CellIdFromSchema<Schema, TableId>,
282
- Hashed extends boolean = false,
283
- > = Stamp<CellOrUndefined<Schema, TableId, CellId>, Hashed>;
284
-
285
- /**
286
- * The ValuesStamp type is used as metadata to decide how to merge two different
287
- * sets of Values together.
288
- *
289
- * This has schema-based typing. The following is a simplified representation:
290
- *
291
- * ```ts override
292
- * export type ValuesStamp<Hashed extends boolean = false> = Stamp<
293
- * {[valueId: Id]: ValueStamp<Hashed>},
294
- * Hashed
295
- * >;
296
- * ```
297
- *
298
- * This type is mostly utilized internally within TinyBase itself and is
299
- * generally assumed to be opaque to applications that use it.
300
- * @category Stamps
301
- * @since v5.0.0
302
- */
303
- export type ValuesStamp<
304
- Schema extends OptionalValuesSchema,
305
- Hashed extends boolean = false,
306
- > = Stamp<
307
- {
308
- [ValueId in ValueIdFromSchema<Schema>]?: ValueStamp<
309
- Schema,
310
- ValueId,
311
- Hashed
312
- >;
313
- },
314
- Hashed
315
- >;
316
-
317
- /**
318
- * The ValueHashes type is used to quickly compare the content of two sets of
319
- * Value objects.
320
- *
321
- * This has schema-based typing. The following is a simplified representation:
322
- *
323
- * ```ts override
324
- * {[valueId: Id]: Hash};
325
- * ```
326
- *
327
- * It is simply an object of Hash types, one for each Value Id in the
328
- * MergeableStore.
329
- *
330
- * This type is mostly utilized internally within TinyBase itself and is
331
- * generally assumed to be opaque to applications that use it.
332
- * @category Syncing
333
- * @since v5.0.0
334
- */
335
- export type ValueHashes<Schema extends OptionalValuesSchema> = {
336
- [ValueId in ValueIdFromSchema<Schema>]?: Hash;
337
- };
338
-
339
- /**
340
- * The ValueStamp type is used as metadata to decide how to merge two different
341
- * Value objects together.
342
- *
343
- * This has schema-based typing. The following is a simplified representation:
344
- *
345
- * ```ts override
346
- * export type ValueStamp<Hashed extends boolean = false> = Stamp<
347
- * ValueOrUndefined,
348
- * Hashed
349
- * >;
350
- * ```
351
- *
352
- * This type is mostly utilized internally within TinyBase itself and is
353
- * generally assumed to be opaque to applications that use it.
354
- * @category Stamps
355
- * @since v5.0.0
356
- */
357
- export type ValueStamp<
358
- Schema extends OptionalValuesSchema,
359
- ValueId extends ValueIdFromSchema<Schema>,
360
- Hashed extends boolean = false,
361
- > = Stamp<ValueOrUndefined<Schema, ValueId>, Hashed>;
362
-
363
- /**
364
- * The MergeableContent type represents the content of a MergeableStore and the
365
- * metadata about that content) required to merge it with another.
366
- *
367
- * This has schema-based typing. The following is a simplified representation:
368
- *
369
- * ```ts override
370
- * [
371
- * mergeableTables: TablesStamp<true>,
372
- * mergeableValues: ValuesStamp<true>,
373
- * ];
374
- * ```
375
- *
376
- * It is simply an array of two Stamp types, one for the MergeableStore's Tables
377
- * and one for its Values.
378
- *
379
- * This type is mostly utilized internally within TinyBase itself and is
380
- * generally assumed to be opaque to applications that use it.
381
- * @category Mergeable
382
- * @since v5.0.0
383
- */
384
- export type MergeableContent<Schemas extends OptionalSchemas> = [
385
- mergeableTables: TablesStamp<Schemas[0], true>,
386
- mergeableValues: ValuesStamp<Schemas[1], true>,
387
- ];
388
-
389
- /**
390
- * The MergeableChanges type represents changes to the content of a
391
- * MergeableStore and the metadata about that content) required to merge it with
392
- * another.
393
- *
394
- * This has schema-based typing. The following is a simplified representation:
395
- *
396
- * ```ts override
397
- * export type MergeableChanges<Hashed extends boolean = false> = [
398
- * mergeableTables: TablesStamp<Hashed>,
399
- * mergeableValues: ValuesStamp<Hashed>,
400
- * isChanges: 1,
401
- * ];
402
- * ```
403
- *
404
- * It is simply an array of two Stamp types, one for changes to the
405
- * MergeableStore's Tables and one for changes to its Values. A final `1` is
406
- * used to distinguish it from a full MergeableContent object.
407
- *
408
- * This type is mostly utilized internally within TinyBase itself and is
409
- * generally assumed to be opaque to applications that use it.
410
- * @category Mergeable
411
- * @since v5.0.0
412
- */
413
- export type MergeableChanges<
414
- Schemas extends OptionalSchemas,
415
- Hashed extends boolean = false,
416
- > = [
417
- mergeableTables: TablesStamp<Schemas[0], Hashed>,
418
- mergeableValues: ValuesStamp<Schemas[1], Hashed>,
419
- isChanges: 1,
420
- ];
421
-
422
- /**
423
- * The MergeableStore type represents a Store that carries with it sufficient
424
- * metadata to be able to be merged with another MergeableStore with
425
- * deterministic results.
426
- *
427
- * This is the key data type used when you need TinyBase data to be cleanly
428
- * synchronized or merged with data elsewhere on the system, or on another
429
- * system. It acts as a Conflict-Free Replicated Data Type (CRDT) which allows
430
- * deterministic disambiguation of how changes to different instances should be
431
- * merged.
432
- *
433
- * Please be aware that a lot of the methods exposed by this interface are used
434
- * internally within TinyBase itself (in particular the Synchronizer framework).
435
- * They're documented here, but mostly for interest, and it is generally assumed
436
- * that they won't be called directly by applications.
437
- *
438
- * As an application developer, it's more likely that you will continue to use
439
- * the main Store methods for reading, writing, and listening to data, and rely
440
- * on Synchronizer instances to keep the data in step with other places.
441
- *
442
- * One possible exceptions is the merge method, which can be used to simply
443
- * merge two co-located MergeableStore instances together.
444
- * @example
445
- * This example shows very simple usage of the MergeableStore: whereby two are
446
- * created, updated with different data, and then merged with one another.
447
- *
448
- * ```js
449
- * import {createMergeableStore} from 'tinybase';
450
- *
451
- * const localStore1 = createMergeableStore();
452
- * const localStore2 = createMergeableStore();
453
- *
454
- * localStore1.setCell('pets', 'fido', 'color', 'brown');
455
- * localStore2.setCell('pets', 'felix', 'color', 'black');
456
- *
457
- * localStore1.merge(localStore2);
458
- *
459
- * console.log(localStore1.getContent());
460
- * // -> [{pets: {felix: {color: 'black'}, fido: {color: 'brown'}}}, {}]
461
- *
462
- * console.log(localStore2.getContent());
463
- * // -> [{pets: {felix: {color: 'black'}, fido: {color: 'brown'}}}, {}]
464
- *```
465
- * @category Mergeable
466
- * @since v5.0.0
467
- */
468
- export interface MergeableStore<Schemas extends OptionalSchemas>
469
- extends Store<Schemas> {
470
- //
471
- /**
472
- * The getMergeableContent method returns the full content of a
473
- * MergeableStore, together with the metadata required to make it mergeable
474
- * with another.
475
- *
476
- * This has schema-based typing. The following is a simplified representation:
477
- *
478
- * ```ts override
479
- * getMergeableContent(): MergeableContent;
480
- * ```
481
- *
482
- * The method is generally intended to be used internally within TinyBase
483
- * itself and the return type is assumed to be opaque to applications that use
484
- * it.
485
- * @returns A MergeableContent object for the full content of the
486
- * MergeableStore.
487
- * @example
488
- * This example creates a MergeableStore, sets some data, and then accesses
489
- * the content and metadata required to make it mergeable.
490
- *
491
- * ```js
492
- * import {createMergeableStore} from 'tinybase';
493
- *
494
- * const store = createMergeableStore('store1'); // !resetHlc
495
- *
496
- * store.setCell('pets', 'fido', 'color', 'brown');
497
- *
498
- * console.log(store.getMergeableContent());
499
- * // ->
500
- * [
501
- * [
502
- * {
503
- * pets: [
504
- * {
505
- * fido: [
506
- * {color: ['brown', 'Nn1JUF-----FnHIC', 923684530]},
507
- * '',
508
- * 851131566,
509
- * ],
510
- * },
511
- * '',
512
- * 518810247,
513
- * ],
514
- * },
515
- * '',
516
- * 784336119,
517
- * ],
518
- * [{}, '', 0],
519
- * ];
520
- * ```
521
- * @category Getter
522
- * @since v5.0.0
523
- */
524
- getMergeableContent(): MergeableContent<Schemas>;
525
-
526
- /**
527
- * The getMergeableContentHashes method returns hashes for the full content of
528
- * a MergeableStore.
529
- *
530
- * If two MergeableStore instances have different hashes, that indicates that
531
- * the mergeable Tables or Values within them are different and should be
532
- * synchronized.
533
- *
534
- * The method is generally intended to be used internally within TinyBase
535
- * itself and the return type is assumed to be opaque to applications that use
536
- * it.
537
- * @returns A ContentHashes array for the hashes of the full content of the
538
- * MergeableStore.
539
- * @example
540
- * This example creates a MergeableStore, sets some data, and then accesses
541
- * the content hashes.
542
- *
543
- * ```js
544
- * import {createMergeableStore} from 'tinybase';
545
- *
546
- * const store = createMergeableStore('store1'); // !resetHlc
547
- *
548
- * store.setCell('pets', 'fido', 'color', 'brown');
549
- * console.log(store.getMergeableContentHashes());
550
- * // -> [784336119, 0]
551
- *
552
- * store.setValue('open', true);
553
- * console.log(store.getMergeableContentHashes());
554
- * // -> [784336119, 2829789038]
555
- * ```
556
- * @category Syncing
557
- * @since v5.0.0
558
- */
559
- getMergeableContentHashes(): ContentHashes;
560
-
561
- /**
562
- * The getMergeableTableHashes method returns hashes for the Table objects in
563
- * a MergeableStore.
564
- *
565
- * This has schema-based typing. The following is a simplified representation:
566
- *
567
- * ```ts override
568
- * getMergeableTableHashes(): TableHashes;
569
- * ```
570
- *
571
- * If two Table Ids have different hashes, that indicates that the content
572
- * within them is different and should be synchronized.
573
- *
574
- * The method is generally intended to be used internally within TinyBase
575
- * itself and the return type is assumed to be opaque to applications that use
576
- * it.
577
- * @returns A TableHashes object with the hashes of each Table in the
578
- * MergeableStore.
579
- * @example
580
- * This example creates a MergeableStore, sets some data, and then accesses
581
- * the Table hashes.
582
- *
583
- * ```js
584
- * import {createMergeableStore} from 'tinybase';
585
- *
586
- * const store = createMergeableStore('store1'); // !resetHlc
587
- *
588
- * store.setCell('pets', 'fido', 'color', 'brown');
589
- * console.log(store.getMergeableTableHashes());
590
- * // -> {pets: 518810247}
591
- *
592
- * store.setCell('species', 'dog', 'price', 5);
593
- * console.log(store.getMergeableTableHashes());
594
- * // -> {pets: 518810247, species: 2324343240}
595
- * ```
596
- * @category Syncing
597
- * @since v5.0.0
598
- */
599
- getMergeableTableHashes(): TableHashes<Schemas[0]>;
600
-
601
- /**
602
- * The getMergeableTableDiff method returns information about new and
603
- * differing Table objects of a MergeableStore relative to another.
604
- *
605
- * This has schema-based typing. The following is a simplified representation:
606
- *
607
- * ```ts override
608
- * getMergeableTableDiff(
609
- * otherTableHashes: TableHashes,
610
- * ): [newTables: TablesStamp, differingTableHashes: TableHashes];
611
- * ```
612
- *
613
- * The method is generally intended to be used internally within TinyBase
614
- * itself and the return type is assumed to be opaque to applications that use
615
- * it.
616
- * @param otherTableHashes The TableHashes of another MergeableStore.
617
- * @returns A pair of objects describing the new and differing Table objects
618
- * of this MergeableStore relative to the other.
619
- * @example
620
- * This example creates two MergeableStores, sets some differing data, and
621
- * then identifies the differences in the Table objects of one versus the
622
- * other. Once they have been merged, the differences are empty.
623
- *
624
- * ```js
625
- * import {createMergeableStore} from 'tinybase';
626
- *
627
- * const store1 = createMergeableStore('store1'); // !resetHlc
628
- * store1.setTables({pets: {fido: {color: 'brown'}}});
629
- *
630
- * const store2 = createMergeableStore('store2');
631
- * store2.setTables({
632
- * pets: {fido: {species: 'dog'}},
633
- * species: {dog: {price: 5}},
634
- * });
635
- *
636
- * console.log(
637
- * store2.getMergeableTableDiff(store1.getMergeableTableHashes()),
638
- * );
639
- * // ->
640
- * [
641
- * [{species: [{dog: [{price: [5, 'Nn1JUF----0CnH-J']}]}]}],
642
- * {pets: 1212600658},
643
- * ];
644
- *
645
- * store1.merge(store2);
646
- *
647
- * console.log(
648
- * store2.getMergeableTableDiff(store1.getMergeableTableHashes()),
649
- * );
650
- * // -> [[{}], {}]
651
- * ```
652
- * @category Syncing
653
- * @since v5.0.0
654
- */
655
- getMergeableTableDiff(
656
- otherTableHashes: TableHashes<Schemas[0]>,
657
- ): [
658
- newTables: TablesStamp<Schemas[0]>,
659
- differingTableHashes: TableHashes<Schemas[0]>,
660
- ];
661
-
662
- /**
663
- * The getMergeableRowHashes method returns hashes for Row objects in a
664
- * MergeableStore.
665
- *
666
- * This has schema-based typing. The following is a simplified representation:
667
- *
668
- * ```ts override
669
- * getMergeableRowHashes(otherTableHashes: TableHashes): RowHashes;
670
- * ```
671
- *
672
- * If two Row Ids have different hashes, that indicates that the content
673
- * within them is different and should be synchronized.
674
- *
675
- * The method is generally intended to be used internally within TinyBase
676
- * itself and the return type is assumed to be opaque to applications that use
677
- * it.
678
- * @param otherTableHashes The TableHashes from the other MergeableStore so
679
- * that the differences can be efficiently identified.
680
- * @returns A RowHashes object with the hashes of each Row in the relevant
681
- * Table objects of the MergeableStore.
682
- * @example
683
- * This example creates a MergeableStore, sets some data, and then accesses
684
- * the Row hashes for the differing Table Ids.
685
- *
686
- * ```js
687
- * import {createMergeableStore} from 'tinybase';
688
- *
689
- * const store1 = createMergeableStore('store1'); // !resetHlc
690
- * store1.setTables({pets: {fido: {color: 'brown'}, felix: {color: 'tan'}}});
691
- *
692
- * const store2 = createMergeableStore('store2');
693
- * store2.setTables({pets: {fido: {color: 'black'}, felix: {color: 'tan'}}});
694
- *
695
- * console.log(
696
- * store1.getMergeableRowHashes(
697
- * store2.getMergeableTableDiff(store1.getMergeableTableHashes())[1],
698
- * ),
699
- * );
700
- * // -> {pets: {felix: 1683761402, fido: 851131566}}
701
- * ```
702
- * @category Syncing
703
- * @since v5.0.0
704
- */
705
- getMergeableRowHashes(
706
- otherTableHashes: TableHashes<Schemas[0]>,
707
- ): RowHashes<Schemas[0]>;
708
-
709
- /**
710
- * The getMergeableRowDiff method returns information about new and differing
711
- * Row objects of a MergeableStore relative to another.
712
- *
713
- * This has schema-based typing. The following is a simplified representation:
714
- *
715
- * ```ts override
716
- * getMergeableRowDiff(
717
- * otherTableRowHashes: RowHashes,
718
- * ): [newRows: TablesStamp, differingRowHashes: RowHashes];
719
- * ```
720
- *
721
- * The method is generally intended to be used internally within TinyBase
722
- * itself and the return type is assumed to be opaque to applications that use
723
- * it.
724
- * @param otherTableRowHashes The RowHashes of another MergeableStore.
725
- * @returns A pair of objects describing the new and differing Row objects of
726
- * this MergeableStore relative to the other.
727
- * @example
728
- * This example creates two MergeableStores, sets some differing data, and
729
- * then identifies the differences in the Row objects of one versus the other.
730
- * Once they have been merged, the differences are empty.
731
- *
732
- * ```js
733
- * import {createMergeableStore} from 'tinybase';
734
- *
735
- * const store1 = createMergeableStore('store1'); // !resetHlc
736
- * store1.setTables({pets: {fido: {color: 'brown'}}});
737
- *
738
- * const store2 = createMergeableStore('store2');
739
- * store2.setTables({pets: {fido: {color: 'black'}, felix: {color: 'tan'}}});
740
- *
741
- * console.log(
742
- * store2.getMergeableRowDiff(
743
- * store1.getMergeableRowHashes(
744
- * store2.getMergeableTableDiff(store1.getMergeableTableHashes())[1],
745
- * ),
746
- * ),
747
- * );
748
- * // ->
749
- * [
750
- * [{pets: [{felix: [{color: ['tan', 'Nn1JUF----0CnH-J']}]}]}],
751
- * {pets: {fido: 1038491054}},
752
- * ];
753
- *
754
- * store1.merge(store2);
755
- *
756
- * console.log(
757
- * store2.getMergeableRowDiff(
758
- * store1.getMergeableRowHashes(
759
- * store2.getMergeableTableDiff(store1.getMergeableTableHashes())[1],
760
- * ),
761
- * ),
762
- * );
763
- * // -> [[{}], {}]
764
- * ```
765
- * @category Syncing
766
- * @since v5.0.0
767
- */
768
- getMergeableRowDiff(
769
- otherTableRowHashes: RowHashes<Schemas[0]>,
770
- ): [
771
- newRows: TablesStamp<Schemas[0]>,
772
- differingRowHashes: RowHashes<Schemas[0]>,
773
- ];
774
-
775
- /**
776
- * The getMergeableCellHashes method returns hashes for Cell objects in a
777
- * MergeableStore.
778
- *
779
- * This has schema-based typing. The following is a simplified representation:
780
- *
781
- * ```ts override
782
- * getMergeableCellHashes(otherTableRowHashes: RowHashes): CellHashes;
783
- * ```
784
- *
785
- * If two Cell Ids have different hashes, that indicates that the content
786
- * within them is different and should be synchronized.
787
- *
788
- * The method is generally intended to be used internally within TinyBase
789
- * itself and the return type is assumed to be opaque to applications that use
790
- * it.
791
- * @param otherTableRowHashes The RowHashes from the other MergeableStore so
792
- * that the differences can be efficiently identified.
793
- * @returns A CellHashes object with the hashes of each Cell in the relevant
794
- * Row objects of the MergeableStore.
795
- * @example
796
- * This example creates a MergeableStore, sets some data, and then accesses
797
- * the Cell hashes for the differing Table Ids.
798
- *
799
- * ```js
800
- * import {createMergeableStore} from 'tinybase';
801
- *
802
- * const store1 = createMergeableStore('store1'); // !resetHlc
803
- * store1.setTables({pets: {fido: {color: 'brown', species: 'dog'}}});
804
- *
805
- * const store2 = createMergeableStore('store2');
806
- * store2.setTables({pets: {fido: {color: 'black', species: 'dog'}}});
807
- *
808
- * console.log(
809
- * store1.getMergeableCellHashes(
810
- * store2.getMergeableRowDiff(
811
- * store1.getMergeableRowHashes(
812
- * store2.getMergeableTableDiff(store1.getMergeableTableHashes())[1],
813
- * ),
814
- * )[1],
815
- * ),
816
- * );
817
- * // -> {pets: {fido: {color: 923684530, species: 227729753}}}
818
- * ```
819
- * @category Syncing
820
- * @since v5.0.0
821
- */
822
- getMergeableCellHashes(
823
- otherTableRowHashes: RowHashes<Schemas[0]>,
824
- ): CellHashes<Schemas[0]>;
825
-
826
- /**
827
- * The getMergeableCellDiff method returns information about new and differing
828
- * Cell objects of a MergeableStore relative to another.
829
- *
830
- * This has schema-based typing. The following is a simplified representation:
831
- *
832
- * ```ts override
833
- * getMergeableCellDiff(otherTableRowCellHashes: CellHashes): TablesStamp;
834
- * ```
835
- *
836
- * The method is generally intended to be used internally within TinyBase
837
- * itself and the return type is assumed to be opaque to applications that use
838
- * it.
839
- * @param otherTableRowCellHashes The CellHashes of another MergeableStore.
840
- * @returns The new and differing Cell objects of this MergeableStore relative
841
- * to the other.
842
- * @example
843
- * This example creates two MergeableStores, sets some differing data, and
844
- * then identifies the differences in the Cell objects of one versus the
845
- * other. Once they have been merged, the differences are empty.
846
- *
847
- * ```js
848
- * import {createMergeableStore} from 'tinybase';
849
- *
850
- * const store1 = createMergeableStore('store1'); // !resetHlc
851
- * store1.setTables({pets: {fido: {color: 'brown'}}});
852
- *
853
- * const store2 = createMergeableStore('store2');
854
- * store2.setTables({pets: {fido: {color: 'black', species: 'dog'}}});
855
- *
856
- * console.log(
857
- * store2.getMergeableCellDiff(
858
- * store1.getMergeableCellHashes(
859
- * store2.getMergeableRowDiff(
860
- * store1.getMergeableRowHashes(
861
- * store2.getMergeableTableDiff(
862
- * store1.getMergeableTableHashes(),
863
- * )[1],
864
- * ),
865
- * )[1],
866
- * ),
867
- * ),
868
- * );
869
- * // ->
870
- * [
871
- * {
872
- * pets: [
873
- * {
874
- * fido: [
875
- * {
876
- * color: ['black', 'Nn1JUF-----CnH-J'],
877
- * species: ['dog', 'Nn1JUF----0CnH-J'],
878
- * },
879
- * ],
880
- * },
881
- * ],
882
- * },
883
- * ];
884
- *
885
- * store1.merge(store2);
886
- *
887
- * console.log(
888
- * store2.getMergeableCellDiff(
889
- * store1.getMergeableCellHashes(
890
- * store2.getMergeableRowDiff(
891
- * store1.getMergeableRowHashes(
892
- * store2.getMergeableTableDiff(
893
- * store1.getMergeableTableHashes(),
894
- * )[1],
895
- * ),
896
- * )[1],
897
- * ),
898
- * ),
899
- * );
900
- * // -> [{}]
901
- * ```
902
- * @category Syncing
903
- * @since v5.0.0
904
- */
905
- getMergeableCellDiff(
906
- otherTableRowCellHashes: CellHashes<Schemas[0]>,
907
- ): TablesStamp<Schemas[0]>;
908
-
909
- /**
910
- * The getMergeableValueHashes method returns hashes for the Value objects in
911
- * a MergeableStore.
912
- *
913
- * This has schema-based typing. The following is a simplified representation:
914
- *
915
- * ```ts override
916
- * getMergeableValueHashes(): ValueHashes;
917
- * ```
918
- *
919
- * If two Value Ids have different hashes, that indicates that the content
920
- * within them is different and should be synchronized.
921
- *
922
- * The method is generally intended to be used internally within TinyBase
923
- * itself and the return type is assumed to be opaque to applications that use
924
- * it.
925
- * @returns A ValueHashes object with the hashes of each Value in the
926
- * MergeableStore.
927
- * @example
928
- * This example creates a MergeableStore, sets some data, and then accesses
929
- * the Value hashes.
930
- *
931
- * ```js
932
- * import {createMergeableStore} from 'tinybase';
933
- *
934
- * const store = createMergeableStore('store1'); // !resetHlc
935
- *
936
- * store.setValue('employees', 3);
937
- * console.log(store.getMergeableValueHashes());
938
- * // -> {employees: 1940815977}
939
- *
940
- * store.setValue('open', true);
941
- * console.log(store.getMergeableValueHashes());
942
- * // -> {employees: 1940815977, open: 3860530645}
943
- * ```
944
- * @category Syncing
945
- * @since v5.0.0
946
- */
947
- getMergeableValueHashes(): ValueHashes<Schemas[1]>;
948
-
949
- /**
950
- * The getMergeableValueDiff method returns information about new and
951
- * differing Value objects of a MergeableStore relative to another.
952
- *
953
- * This has schema-based typing. The following is a simplified representation:
954
- *
955
- * ```ts override
956
- * getMergeableValueDiff(otherValueHashes: ValueHashes): ValuesStamp;
957
- * ```
958
- *
959
- * The method is generally intended to be used internally within TinyBase
960
- * itself and the return type is assumed to be opaque to applications that use
961
- * it.
962
- * @param otherValueHashes The ValueHashes of another MergeableStore.
963
- * @returns The new and differing Value objects of this MergeableStore
964
- * relative to the other.
965
- * @example
966
- * This example creates two MergeableStores, sets some differing data, and
967
- * then identifies the differences in the Value objects of one versus the
968
- * other. Once they have been merged, the differences are empty.
969
- *
970
- * ```js
971
- * import {createMergeableStore} from 'tinybase';
972
- *
973
- * const store1 = createMergeableStore('store1'); // !resetHlc
974
- * store1.setValues({employees: 3});
975
- *
976
- * const store2 = createMergeableStore('store2');
977
- * store2.setValues({employees: 4, open: true});
978
- *
979
- * console.log(
980
- * store2.getMergeableValueDiff(store1.getMergeableValueHashes()),
981
- * );
982
- * // ->
983
- * [
984
- * {
985
- * employees: [4, 'Nn1JUF-----CnH-J'],
986
- * open: [true, 'Nn1JUF----0CnH-J'],
987
- * },
988
- * ];
989
- *
990
- * store1.merge(store2);
991
- *
992
- * console.log(
993
- * store2.getMergeableValueDiff(store1.getMergeableValueHashes()),
994
- * );
995
- * // -> [{}]
996
- * ```
997
- * @category Syncing
998
- * @since v5.0.0
999
- */
1000
- getMergeableValueDiff(
1001
- otherValueHashes: ValueHashes<Schemas[1]>,
1002
- ): ValuesStamp<Schemas[1]>;
1003
-
1004
- /**
1005
- * The setMergeableContent method sets the full content of a MergeableStore,
1006
- * together with the metadata required to make it mergeable with another.
1007
- *
1008
- * This has schema-based typing. The following is a simplified representation:
1009
- *
1010
- * ```ts override
1011
- * setMergeableContent(mergeableContent: MergeableContent): MergeableStore;
1012
- * ```
1013
- *
1014
- * The method is generally intended to be used internally within TinyBase
1015
- * itself and the return type is assumed to be opaque to applications that use
1016
- * it.
1017
- * @param mergeableContent The full content and metadata of a MergeableStore.
1018
- * @returns A reference to the MergeableStore.
1019
- * @example
1020
- * This example creates a new MergeableStore and initializes it with
1021
- * the content and metadata from another.
1022
- *
1023
- * ```js
1024
- * import {createMergeableStore} from 'tinybase';
1025
- *
1026
- * const store1 = createMergeableStore('store1'); // !resetHlc
1027
- * store1.setValues({employees: 3});
1028
- * console.log(store1.getMergeableContent());
1029
- * // ->
1030
- * [
1031
- * [{}, '', 0],
1032
- * [{employees: [3, 'Nn1JUF-----FnHIC', 1940815977]}, '', 1260895905],
1033
- * ];
1034
- *
1035
- * const store2 = createMergeableStore('store2');
1036
- * store2.setMergeableContent(store1.getMergeableContent());
1037
- * console.log(store2.getMergeableContent());
1038
- * // ->
1039
- * [
1040
- * [{}, '', 0],
1041
- * [{employees: [3, 'Nn1JUF-----FnHIC', 1940815977]}, '', 1260895905],
1042
- * ];
1043
- * ```
1044
- * @category Setter
1045
- * @since v5.0.0
1046
- */
1047
- setMergeableContent(
1048
- mergeableContent: MergeableContent<Schemas>,
1049
- ): MergeableStore<Schemas>;
1050
-
1051
- /**
1052
- * The setDefaultContent method sets initial content of a MergeableStore.
1053
- *
1054
- * This has schema-based typing. The following is a simplified representation:
1055
- *
1056
- * ```ts override
1057
- * setDefaultContent(content: Content | (() => Content)): MergeableStore;
1058
- * ```
1059
- *
1060
- * This differs from the setMergeableContent method in that all of the
1061
- * metadata is initialized with a empty HLC timestamp - meaning that any
1062
- * changes applied to it will 'win', yet ensuring that at least default,
1063
- * initial data exists.
1064
- *
1065
- * The method is generally intended to be used internally within TinyBase
1066
- * itself and the return type is assumed to be opaque to applications that use
1067
- * it.
1068
- *
1069
- * Since v5.4.2, this method can also take a function that returns the
1070
- * content.
1071
- * @param content An array containing the tabular and keyed-value data to be
1072
- * set, or a function that returns the array.
1073
- * @returns A reference to the MergeableStore.
1074
- * @example
1075
- * This example creates a new MergeableStore with default data, and
1076
- * demonstrates that it is overwritten with another MergeableStore's data on
1077
- * merge, even if the other MergeableStore was provisioned earlier.
1078
- *
1079
- * ```js
1080
- * import {createMergeableStore} from 'tinybase';
1081
- *
1082
- * const store1 = createMergeableStore('store1'); // !resetHlc
1083
- * store1.setValues({employees: 3});
1084
- *
1085
- * const store2 = createMergeableStore('store2');
1086
- * store2.setDefaultContent([{}, {employees: 4}]);
1087
- * console.log(store2.getMergeableContent());
1088
- * // -> [[{}, "", 0], [{"employees": [4, "", 2414055963]}, "", 3035768673]]
1089
- *
1090
- * store2.merge(store1);
1091
- * console.log(store2.getContent());
1092
- * // -> [{}, {employees: 3}]
1093
- * ```
1094
- * @category Setter
1095
- * @since v5.0.0
1096
- */
1097
- setDefaultContent(
1098
- content: Content<Schemas> | (() => Content<Schemas>),
1099
- ): MergeableStore<Schemas>;
1100
-
1101
- /**
1102
- * The getTransactionMergeableChanges method returns the net meaningful
1103
- * changes that have been made to a MergeableStore during a transaction.
1104
- *
1105
- * This has schema-based typing. The following is a simplified representation:
1106
- *
1107
- * ```ts override
1108
- * getTransactionMergeableChanges(withHashes?: boolean): MergeableChanges<true>;
1109
- * ```
1110
- *
1111
- * The method is generally intended to be used internally within TinyBase
1112
- * itself and the return type is assumed to be opaque to applications that use
1113
- * it.
1114
- * @param withHashes Whether to include hashes in the output, defaulting to
1115
- * false.
1116
- * @returns A MergeableChanges object representing the changes, with hashes.
1117
- * @example
1118
- * This example makes changes to the MergeableStore. At the end of the
1119
- * transaction, detail about what changed is enumerated.
1120
- *
1121
- * ```js
1122
- * import {createMergeableStore} from 'tinybase';
1123
- *
1124
- * const store = createMergeableStore('store1'); // !resetHlc
1125
- * store.setTables({pets: {fido: {species: 'dog', color: 'brown'}}});
1126
- * store.setValues({open: true});
1127
- *
1128
- * store
1129
- * .startTransaction()
1130
- * .setCell('pets', 'fido', 'color', 'black')
1131
- * .setValue('open', false)
1132
- * .finishTransaction(() => {
1133
- * console.log(store.getTransactionMergeableChanges());
1134
- * });
1135
- * // ->
1136
- * [
1137
- * [{pets: [{fido: [{color: ['black', 'Nn1JUF----2FnHIC']}]}]}],
1138
- * [{open: [false, 'Nn1JUF----3FnHIC']}],
1139
- * 1,
1140
- * ];
1141
- * ```
1142
- * @category Transaction
1143
- * @since v5.0.0
1144
- */
1145
- getTransactionMergeableChanges(
1146
- withHashes?: boolean,
1147
- ): MergeableChanges<Schemas, true>;
1148
-
1149
- /**
1150
- * The applyMergeableChanges method applies a set of mergeable changes or
1151
- * content to the MergeableStore.
1152
- *
1153
- * This has schema-based typing. The following is a simplified representation:
1154
- *
1155
- * ```ts override
1156
- * applyMergeableChanges(
1157
- * mergeableChanges: MergeableChanges | MergeableContent,
1158
- * ): MergeableStore;
1159
- * ```
1160
- *
1161
- * The method is generally intended to be used internally within TinyBase
1162
- * itself and the return type is assumed to be opaque to applications that use
1163
- * it.
1164
- * @param mergeableChanges The MergeableChanges or MergeableContent to apply
1165
- * to the MergeableStore.
1166
- * @returns A reference to the MergeableStore.
1167
- * @example
1168
- * This example applies a MergeableChanges object that sets a Cell and removes
1169
- * a Value.
1170
- *
1171
- * ```js
1172
- * import {createMergeableStore} from 'tinybase';
1173
- *
1174
- * const store = createMergeableStore('store1')
1175
- * .setTables({pets: {fido: {species: 'dog', color: 'brown'}}})
1176
- * .setValues({open: true});
1177
- *
1178
- * store.applyMergeableChanges([
1179
- * [{pets: [{fido: [{color: ['black', 'Nn1JUF----2FnHIC']}]}]}],
1180
- * [{open: [null, 'Nn1JUF----3FnHIC']}],
1181
- * 1,
1182
- * ]);
1183
- * console.log(store.getTables());
1184
- * // -> {pets: {fido: {species: 'dog', color: 'black'}}}
1185
- * console.log(store.getValues());
1186
- * // -> {}
1187
- * ```
1188
- * @category Setter
1189
- * @since v5.0.0
1190
- */
1191
- applyMergeableChanges(
1192
- mergeableChanges: MergeableChanges<Schemas> | MergeableContent<Schemas>,
1193
- ): MergeableStore<Schemas>;
1194
-
1195
- /**
1196
- * The merge method is a convenience method that applies the mergeable content
1197
- * from two MergeableStores to each other in order to bring them to the same
1198
- * state.
1199
- *
1200
- * This has schema-based typing. The following is a simplified representation:
1201
- *
1202
- * ```ts override
1203
- * merge(mergeableStore: MergeableStore): MergeableStore;
1204
- * ```
1205
- *
1206
- * This method is symmetrical: applying `store1` to `store2` will have exactly
1207
- * the same effect as applying `store2` to `store1`.
1208
- * @param mergeableStore A reference to the other MergeableStore to merge with
1209
- * this one.
1210
- * @returns A reference to this MergeableStore.
1211
- * @example
1212
- * This example merges two MergeableStore objects together. Note how the final
1213
- * part of the timestamps on each Cell give you a clue that the data comes
1214
- * from changes made to different MergeableStore objects.
1215
- *
1216
- * ```js
1217
- * import {createMergeableStore} from 'tinybase';
1218
- *
1219
- * const store1 = createMergeableStore('store1');
1220
- * store1.setTables({pets: {fido: {species: 'dog', color: 'brown'}}});
1221
- *
1222
- * const store2 = createMergeableStore('store2');
1223
- * store2.setTables({pets: {felix: {species: 'cat', color: 'tan'}}});
1224
- *
1225
- * store1.merge(store2);
1226
- *
1227
- * console.log(store1.getContent());
1228
- * // ->
1229
- * [
1230
- * {
1231
- * pets: {
1232
- * felix: {color: 'tan', species: 'cat'},
1233
- * fido: {color: 'brown', species: 'dog'},
1234
- * },
1235
- * },
1236
- * {},
1237
- * ];
1238
- *
1239
- * console.log(store2.getContent());
1240
- * // ->
1241
- * [
1242
- * {
1243
- * pets: {
1244
- * felix: {color: 'tan', species: 'cat'},
1245
- * fido: {color: 'brown', species: 'dog'},
1246
- * },
1247
- * },
1248
- * {},
1249
- * ];
1250
- * console.log(store2.getMergeableContent());
1251
- * // ->
1252
- * [
1253
- * [
1254
- * {
1255
- * pets: [
1256
- * {
1257
- * felix: [
1258
- * {
1259
- * color: ['tan', 'Nn1JUF----0CnH-J', 2576658292],
1260
- * species: ['cat', 'Nn1JUF-----CnH-J', 3409607562],
1261
- * },
1262
- * '',
1263
- * 4146239216,
1264
- * ],
1265
- * fido: [
1266
- * {
1267
- * color: ['brown', 'Nn1JUF----0FnHIC', 1240535355],
1268
- * species: ['dog', 'Nn1JUF-----FnHIC', 290599168],
1269
- * },
1270
- * '',
1271
- * 3989065420,
1272
- * ],
1273
- * },
1274
- * '',
1275
- * 4155188296,
1276
- * ],
1277
- * },
1278
- * '',
1279
- * 972931118,
1280
- * ],
1281
- * [{}, '', 0],
1282
- * ];
1283
- * ```
1284
- * @category Setter
1285
- * @since v5.0.0
1286
- */
1287
- merge(mergeableStore: MergeableStore<Schemas>): MergeableStore<Schemas>;
1288
-
1289
- /**
1290
- * The isMergeable method lets you know if the Store is mergeable.
1291
- *
1292
- * This will always return false for a Store, and true for a MergeableStore.
1293
- * @returns Whether the Store is mergeable.
1294
- * @category Getter
1295
- * @since v5.0.0
1296
- */
1297
- isMergeable(): boolean;
1298
-
1299
- /**
1300
- * The setTablesSchema method lets you specify the TablesSchema of the tabular
1301
- * part of the Store.
1302
- *
1303
- * Note that this may result in a change to data in the Store, as defaults are
1304
- * applied or as invalid Table, Row, or Cell objects are removed. These
1305
- * changes will fire any listeners to that data, as expected.
1306
- *
1307
- * When no longer needed, you can also completely remove an existing
1308
- * TablesSchema with the delTablesSchema method.
1309
- * @param tablesSchema The TablesSchema to be set for the Store.
1310
- * @returns A reference to the Store.
1311
- * @example
1312
- * This example sets the TablesSchema of a Store after it has been created.
1313
- *
1314
- * ```js
1315
- * import {createStore} from 'tinybase';
1316
- *
1317
- * const store = createStore().setTablesSchema({
1318
- * pets: {
1319
- * species: {type: 'string'},
1320
- * sold: {type: 'boolean', default: false},
1321
- * },
1322
- * });
1323
- * store.addRow('pets', {species: 'dog', color: 'brown', sold: 'maybe'});
1324
- *
1325
- * console.log(store.getTables());
1326
- * // -> {pets: {0: {species: 'dog', sold: false}}}
1327
- * ```
1328
- * @category Setter
1329
- * @since v3.0.0
1330
- */
1331
- setTablesSchema<TS extends TablesSchema>(
1332
- tablesSchema: TS,
1333
- ): MergeableStore<[typeof tablesSchema, Schemas[1]]>;
1334
-
1335
- /**
1336
- * The setValuesSchema method lets you specify the ValuesSchema of the keyed
1337
- * Values part of the Store.
1338
- *
1339
- * Note that this may result in a change to data in the Store, as defaults are
1340
- * applied or as invalid Values are removed. These changes will fire any
1341
- * listeners to that data, as expected.
1342
- *
1343
- * When no longer needed, you can also completely remove an existing
1344
- * ValuesSchema with the delValuesSchema method.
1345
- * @param valuesSchema The ValuesSchema to be set for the Store.
1346
- * @returns A reference to the Store.
1347
- * @example
1348
- * This example sets the ValuesSchema of a Store after it has been created.
1349
- *
1350
- * ```js
1351
- * import {createStore} from 'tinybase';
1352
- *
1353
- * const store = createStore().setValuesSchema({
1354
- * open: {type: 'boolean', default: false},
1355
- * });
1356
- * store.setValue('open', 'maybe');
1357
- *
1358
- * console.log(store.getValues());
1359
- * // -> {open: false}
1360
- * ```
1361
- * @category Setter
1362
- * @since v3.0.0
1363
- */
1364
- setValuesSchema<VS extends ValuesSchema>(
1365
- valuesSchema: VS,
1366
- ): MergeableStore<[Schemas[0], typeof valuesSchema]>;
1367
-
1368
- /**
1369
- * The setSchema method lets you specify the TablesSchema and ValuesSchema of
1370
- * the Store.
1371
- *
1372
- * Note that this may result in a change to data in the Store, as defaults are
1373
- * applied or as invalid Table, Row, Cell, or Value objects are removed. These
1374
- * changes will fire any listeners to that data, as expected.
1375
- *
1376
- * From v3.0 onwards, this method takes two arguments. The first is the
1377
- * TablesSchema object, the second the ValuesSchema. In previous versions
1378
- * (before the existence of the ValuesSchema data structure), only the first
1379
- * was present. For backwards compatibility the new second parameter is
1380
- * optional.
1381
- * @param tablesSchema The TablesSchema to be set for the Store.
1382
- * @param valuesSchema The ValuesSchema to be set for the Store.
1383
- * @returns A reference to the Store.
1384
- * @example
1385
- * This example sets the TablesSchema and ValuesSchema of a Store after it has
1386
- * been created.
1387
- *
1388
- * ```js
1389
- * import {createStore} from 'tinybase';
1390
- *
1391
- * const store = createStore().setSchema(
1392
- * {
1393
- * pets: {
1394
- * species: {type: 'string'},
1395
- * sold: {type: 'boolean', default: false},
1396
- * },
1397
- * },
1398
- * {open: {type: 'boolean', default: false}},
1399
- * );
1400
- * store.addRow('pets', {species: 'dog', color: 'brown', sold: 'maybe'});
1401
- * store.setValue('open', 'maybe');
1402
- *
1403
- * console.log(store.getTables());
1404
- * // -> {pets: {0: {species: 'dog', sold: false}}}
1405
- * console.log(store.getValues());
1406
- * // -> {open: false}
1407
- * ```
1408
- * @example
1409
- * This example sets just the TablesSchema of a Store after it has been
1410
- * created.
1411
- *
1412
- * ```js
1413
- * import {createStore} from 'tinybase';
1414
- *
1415
- * const store = createStore().setSchema({
1416
- * pets: {
1417
- * species: {type: 'string'},
1418
- * sold: {type: 'boolean', default: false},
1419
- * },
1420
- * });
1421
- * store.addRow('pets', {species: 'dog', color: 'brown', sold: 'maybe'});
1422
- *
1423
- * console.log(store.getTables());
1424
- * // -> {pets: {0: {species: 'dog', sold: false}}}
1425
- * ```
1426
- * @category Setter
1427
- * @since v1.0.0
1428
- */
1429
- setSchema<TS extends TablesSchema, VS extends ValuesSchema>(
1430
- tablesSchema: TS,
1431
- valuesSchema?: VS,
1432
- ): MergeableStore<
1433
- [
1434
- typeof tablesSchema,
1435
- Exclude<ValuesSchema, typeof valuesSchema> extends never
1436
- ? NoValuesSchema
1437
- : NonNullable<typeof valuesSchema>,
1438
- ]
1439
- >;
1440
-
1441
- /**
1442
- * The delTablesSchema method lets you remove the TablesSchema of the Store.
1443
- * @returns A reference to the Store.
1444
- * @example
1445
- * This example removes the TablesSchema of a Store.
1446
- *
1447
- * ```js
1448
- * import {createStore} from 'tinybase';
1449
- *
1450
- * const store = createStore().setTablesSchema({
1451
- * pets: {species: {type: 'string'}},
1452
- * });
1453
- * store.delTablesSchema();
1454
- * console.log(store.getTablesSchemaJson());
1455
- * // -> '{}'
1456
- * ```
1457
- * @category Deleter
1458
- * @since v1.0.0
1459
- */
1460
- delTablesSchema<
1461
- ValuesSchema extends OptionalValuesSchema = Schemas[1],
1462
- >(): MergeableStore<[NoTablesSchema, ValuesSchema]>;
1463
-
1464
- /**
1465
- * The delValuesSchema method lets you remove the ValuesSchema of the Store.
1466
- * @returns A reference to the Store.
1467
- * @example
1468
- * This example removes the ValuesSchema of a Store.
1469
- *
1470
- * ```js
1471
- * import {createStore} from 'tinybase';
1472
- *
1473
- * const store = createStore().setValuesSchema({
1474
- * sold: {type: 'boolean', default: false},
1475
- * });
1476
- * store.delValuesSchema();
1477
- * console.log(store.getValuesSchemaJson());
1478
- * // -> '{}'
1479
- * ```
1480
- * @category Deleter
1481
- * @since v3.0.0
1482
- */
1483
- delValuesSchema<
1484
- TablesSchema extends OptionalTablesSchema = Schemas[0],
1485
- >(): MergeableStore<[TablesSchema, NoValuesSchema]>;
1486
-
1487
- /**
1488
- * The delSchema method lets you remove both the TablesSchema and ValuesSchema
1489
- * of the Store.
1490
- *
1491
- * Prior to v3.0, this method removed the TablesSchema only.
1492
- * @returns A reference to the Store.
1493
- * @example
1494
- * This example removes the TablesSchema and ValuesSchema of a Store.
1495
- *
1496
- * ```js
1497
- * import {createStore} from 'tinybase';
1498
- *
1499
- * const store = createStore()
1500
- * .setTablesSchema({
1501
- * pets: {species: {type: 'string'}},
1502
- * })
1503
- * .setValuesSchema({
1504
- * sold: {type: 'boolean', default: false},
1505
- * });
1506
- * store.delSchema();
1507
- * console.log(store.getSchemaJson());
1508
- * // -> '[{},{}]'
1509
- * ```
1510
- * @category Deleter
1511
- * @since v3.0.0
1512
- */
1513
- delSchema(): MergeableStore<NoSchemas>;
1514
- }
1515
-
1516
- /**
1517
- * The createMergeableStore function creates a MergeableStore, and is the main
1518
- * entry point into the mergeable-store module.
1519
- *
1520
- * This has schema-based typing. The following is a simplified representation:
1521
- *
1522
- * ```ts override
1523
- * createMergeableStore(uniqueId?: Id): MergeableStore;
1524
- * ```
1525
- *
1526
- * There is one optional parameter which is a uniqueId for the MergeableStore.
1527
- * This is used to distinguish conflicting changes made in the same millisecond
1528
- * by two different MergeableStore objects as its hash is added to the end of
1529
- * the HLC timestamps. Generally this can be omitted unless you have a need for
1530
- * deterministic HLCs, such as in a testing scenario. Otherwise, TinyBase will
1531
- * assign a unique Id to the Store at the time of creation.
1532
- * @returns A reference to the new MergeableStore.
1533
- * @example
1534
- * This example creates a MergeableStore.
1535
- *
1536
- * ```js
1537
- * import {createMergeableStore} from 'tinybase';
1538
- *
1539
- * const store = createMergeableStore('store1');
1540
- *
1541
- * console.log(store.getContent());
1542
- * // -> [{}, {}]
1543
- * console.log(store.getMergeableContent());
1544
- * // -> [[{}, '', 0], [{}, '', 0]]
1545
- * ```
1546
- * @example
1547
- * This example creates a MergeableStore with some initial data:
1548
- *
1549
- * ```js
1550
- * import {createMergeableStore} from 'tinybase';
1551
- *
1552
- * const store = createMergeableStore('store1').setTables({
1553
- * pets: {fido: {species: 'dog'}},
1554
- * });
1555
- *
1556
- * console.log(store.getContent());
1557
- * // -> [{pets: {fido: {species: 'dog'}}}, {}]
1558
- * console.log(store.getMergeableContent());
1559
- * // ->
1560
- * [
1561
- * [
1562
- * {
1563
- * pets: [
1564
- * {
1565
- * fido: [
1566
- * {species: ['dog', 'Nn1JUF-----FnHIC', 290599168]},
1567
- * '',
1568
- * 2682656941,
1569
- * ],
1570
- * },
1571
- * '',
1572
- * 2102515304,
1573
- * ],
1574
- * },
1575
- * '',
1576
- * 3506229770,
1577
- * ],
1578
- * [{}, '', 0],
1579
- * ];
1580
- * ```
1581
- * @example
1582
- * This example creates a MergeableStore with some initial data and a
1583
- * TablesSchema:
1584
- *
1585
- * ```js
1586
- * import {createMergeableStore} from 'tinybase';
1587
- *
1588
- * const store = createMergeableStore('store1')
1589
- * .setTables({pets: {fido: {species: 'dog'}}})
1590
- * .setTablesSchema({
1591
- * pets: {
1592
- * species: {type: 'string'},
1593
- * sold: {type: 'boolean', default: false},
1594
- * },
1595
- * });
1596
- *
1597
- * console.log(store.getContent());
1598
- * // -> [{pets: {fido: {sold: false, species: 'dog'}}}, {}]
1599
- * console.log(store.getMergeableContent());
1600
- * // ->
1601
- * [
1602
- * [
1603
- * {
1604
- * pets: [
1605
- * {
1606
- * fido: [
1607
- * {
1608
- * sold: [false, 'Nn1JUF----2FnHIC', 2603026204],
1609
- * species: ['dog', 'Nn1JUF----1FnHIC', 2817056260],
1610
- * },
1611
- * '',
1612
- * 2859424112,
1613
- * ],
1614
- * },
1615
- * '',
1616
- * 1640515891,
1617
- * ],
1618
- * },
1619
- * '',
1620
- * 2077041985,
1621
- * ],
1622
- * [{}, '', 0],
1623
- * ];
1624
- * ```
1625
- * @category Creation
1626
- * @since v5.0.0
1627
- */
1628
- export function createMergeableStore(uniqueId?: Id): MergeableStore<NoSchemas>;