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.
Files changed (108) hide show
  1. package/@types/common/index.d.ts +4 -4
  2. package/@types/common/with-schemas/index.d.ts +4 -4
  3. package/@types/mergeable-store/index.d.ts +45 -20
  4. package/@types/mergeable-store/with-schemas/index.d.ts +49 -21
  5. package/@types/persisters/index.d.ts +1 -1
  6. package/@types/persisters/with-schemas/index.d.ts +1 -1
  7. package/index.js +19 -11
  8. package/indexes/index.js +15 -3
  9. package/indexes/with-schemas/index.js +15 -3
  10. package/mergeable-store/index.js +4 -8
  11. package/mergeable-store/with-schemas/index.js +4 -8
  12. package/min/index.js +1 -1
  13. package/min/index.js.gz +0 -0
  14. package/min/indexes/index.js +1 -1
  15. package/min/indexes/index.js.gz +0 -0
  16. package/min/indexes/with-schemas/index.js +1 -1
  17. package/min/indexes/with-schemas/index.js.gz +0 -0
  18. package/min/mergeable-store/index.js +1 -1
  19. package/min/mergeable-store/index.js.gz +0 -0
  20. package/min/mergeable-store/with-schemas/index.js +1 -1
  21. package/min/mergeable-store/with-schemas/index.js.gz +0 -0
  22. package/min/with-schemas/index.js +1 -1
  23. package/min/with-schemas/index.js.gz +0 -0
  24. package/package.json +9 -9
  25. package/readme.md +2 -2
  26. package/with-schemas/index.js +19 -11
  27. package/@types/_internal/queries/index.d.cts +0 -0
  28. package/@types/_internal/queries/with-schemas/index.d.cts +0 -22
  29. package/@types/_internal/store/index.d.cts +0 -3
  30. package/@types/_internal/store/with-schemas/index.d.cts +0 -106
  31. package/@types/_internal/ui-react/index.d.cts +0 -0
  32. package/@types/_internal/ui-react/with-schemas/index.d.cts +0 -1130
  33. package/@types/checkpoints/index.d.cts +0 -1059
  34. package/@types/checkpoints/with-schemas/index.d.cts +0 -1151
  35. package/@types/common/index.d.cts +0 -158
  36. package/@types/common/with-schemas/index.d.cts +0 -158
  37. package/@types/index.d.cts +0 -17
  38. package/@types/indexes/index.d.cts +0 -1064
  39. package/@types/indexes/with-schemas/index.d.cts +0 -1210
  40. package/@types/mergeable-store/index.d.cts +0 -1139
  41. package/@types/mergeable-store/with-schemas/index.d.cts +0 -1628
  42. package/@types/metrics/index.d.cts +0 -917
  43. package/@types/metrics/with-schemas/index.d.cts +0 -1004
  44. package/@types/persisters/index.d.cts +0 -1877
  45. package/@types/persisters/persister-automerge/index.d.cts +0 -165
  46. package/@types/persisters/persister-automerge/with-schemas/index.d.cts +0 -180
  47. package/@types/persisters/persister-browser/index.d.cts +0 -185
  48. package/@types/persisters/persister-browser/with-schemas/index.d.cts +0 -208
  49. package/@types/persisters/persister-cr-sqlite-wasm/index.d.cts +0 -159
  50. package/@types/persisters/persister-cr-sqlite-wasm/with-schemas/index.d.cts +0 -178
  51. package/@types/persisters/persister-durable-object-storage/index.d.cts +0 -122
  52. package/@types/persisters/persister-durable-object-storage/with-schemas/index.d.cts +0 -136
  53. package/@types/persisters/persister-electric-sql/index.d.cts +0 -185
  54. package/@types/persisters/persister-electric-sql/with-schemas/index.d.cts +0 -204
  55. package/@types/persisters/persister-expo-sqlite/index.d.cts +0 -186
  56. package/@types/persisters/persister-expo-sqlite/with-schemas/index.d.cts +0 -205
  57. package/@types/persisters/persister-file/index.d.cts +0 -94
  58. package/@types/persisters/persister-file/with-schemas/index.d.cts +0 -107
  59. package/@types/persisters/persister-indexed-db/index.d.cts +0 -120
  60. package/@types/persisters/persister-indexed-db/with-schemas/index.d.cts +0 -135
  61. package/@types/persisters/persister-libsql/index.d.cts +0 -158
  62. package/@types/persisters/persister-libsql/with-schemas/index.d.cts +0 -177
  63. package/@types/persisters/persister-partykit-client/index.d.cts +0 -195
  64. package/@types/persisters/persister-partykit-client/with-schemas/index.d.cts +0 -210
  65. package/@types/persisters/persister-partykit-server/index.d.cts +0 -650
  66. package/@types/persisters/persister-partykit-server/with-schemas/index.d.cts +0 -695
  67. package/@types/persisters/persister-pglite/index.d.cts +0 -177
  68. package/@types/persisters/persister-pglite/with-schemas/index.d.cts +0 -196
  69. package/@types/persisters/persister-postgres/index.d.cts +0 -166
  70. package/@types/persisters/persister-postgres/with-schemas/index.d.cts +0 -185
  71. package/@types/persisters/persister-powersync/index.d.cts +0 -174
  72. package/@types/persisters/persister-powersync/with-schemas/index.d.cts +0 -193
  73. package/@types/persisters/persister-remote/index.d.cts +0 -117
  74. package/@types/persisters/persister-remote/with-schemas/index.d.cts +0 -133
  75. package/@types/persisters/persister-sqlite-wasm/index.d.cts +0 -175
  76. package/@types/persisters/persister-sqlite-wasm/with-schemas/index.d.cts +0 -195
  77. package/@types/persisters/persister-sqlite3/index.d.cts +0 -176
  78. package/@types/persisters/persister-sqlite3/with-schemas/index.d.cts +0 -195
  79. package/@types/persisters/persister-yjs/index.d.cts +0 -161
  80. package/@types/persisters/persister-yjs/with-schemas/index.d.cts +0 -176
  81. package/@types/persisters/with-schemas/index.d.cts +0 -2054
  82. package/@types/queries/index.d.cts +0 -3695
  83. package/@types/queries/with-schemas/index.d.cts +0 -4016
  84. package/@types/relationships/index.d.cts +0 -1320
  85. package/@types/relationships/with-schemas/index.d.cts +0 -1474
  86. package/@types/store/index.d.cts +0 -7598
  87. package/@types/store/with-schemas/index.d.cts +0 -9278
  88. package/@types/synchronizers/index.d.cts +0 -485
  89. package/@types/synchronizers/synchronizer-broadcast-channel/index.d.cts +0 -121
  90. package/@types/synchronizers/synchronizer-broadcast-channel/with-schemas/index.d.cts +0 -137
  91. package/@types/synchronizers/synchronizer-local/index.d.cts +0 -95
  92. package/@types/synchronizers/synchronizer-local/with-schemas/index.d.cts +0 -114
  93. package/@types/synchronizers/synchronizer-ws-client/index.d.cts +0 -160
  94. package/@types/synchronizers/synchronizer-ws-client/with-schemas/index.d.cts +0 -179
  95. package/@types/synchronizers/synchronizer-ws-server/index.d.cts +0 -736
  96. package/@types/synchronizers/synchronizer-ws-server/with-schemas/index.d.cts +0 -765
  97. package/@types/synchronizers/synchronizer-ws-server-durable-object/index.d.cts +0 -311
  98. package/@types/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.d.cts +0 -349
  99. package/@types/synchronizers/synchronizer-ws-server-simple/index.d.cts +0 -144
  100. package/@types/synchronizers/synchronizer-ws-server-simple/with-schemas/index.d.cts +0 -144
  101. package/@types/synchronizers/with-schemas/index.d.cts +0 -503
  102. package/@types/ui-react/index.d.cts +0 -16640
  103. package/@types/ui-react/with-schemas/index.d.cts +0 -17281
  104. package/@types/ui-react-dom/index.d.cts +0 -1862
  105. package/@types/ui-react-dom/with-schemas/index.d.cts +0 -1994
  106. package/@types/ui-react-inspector/index.d.cts +0 -79
  107. package/@types/ui-react-inspector/with-schemas/index.d.cts +0 -1985
  108. package/@types/with-schemas/index.d.cts +0 -17
@@ -1,1151 +0,0 @@
1
- /**
2
- * The checkpoints module of the TinyBase project provides the ability to
3
- * create and track checkpoints made to the data in Store objects.
4
- *
5
- * The main entry point to this module is the createCheckpoints function, which
6
- * returns a new Checkpoints object. From there, you can create new checkpoints,
7
- * go forwards or backwards to others, and register listeners for when the list
8
- * of checkpoints change.
9
- * @packageDocumentation
10
- * @module checkpoints
11
- * @since v1.0.0
12
- */
13
- import type {Id, IdOrNull, Ids} from '../../common/with-schemas/index.d.cts';
14
- import type {OptionalSchemas, Store} from '../../store/with-schemas/index.d.cts';
15
-
16
- /**
17
- * The CheckpointIds type is a representation of the list of checkpoint Ids
18
- * stored in a Checkpoints object.
19
- *
20
- * There are three parts to a CheckpointsIds array:
21
- *
22
- * - The 'backward' checkpoint Ids that can be rolled backward to (in other
23
- * words, the checkpoints in the undo stack for this Store). They are in
24
- * chronological order with the oldest checkpoint at the start of the array.
25
- * - The current checkpoint Id of the Store's state, or `undefined` if the
26
- * current state has not been checkpointed.
27
- * - The 'forward' checkpoint Ids that can be rolled forward to (in other words,
28
- * the checkpoints in the redo stack for this Store). They are in
29
- * chronological order with the newest checkpoint at the end of the array.
30
- * @category Identity
31
- * @since v1.0.0
32
- */
33
- export type CheckpointIds = [Ids, Id | undefined, Ids];
34
-
35
- /**
36
- * The CheckpointCallback type describes a function that takes a Checkpoint's
37
- * Id.
38
- *
39
- * A CheckpointCallback is provided when using the forEachCheckpoint method,
40
- * so that you can do something based on every Checkpoint in the Checkpoints
41
- * object. See that method for specific examples.
42
- * @param checkpointId The Id of the Checkpoint that the callback can operate
43
- * on.
44
- * @category Callback
45
- * @since v1.0.0
46
- */
47
- export type CheckpointCallback = (checkpointId: Id, label?: string) => void;
48
-
49
- /**
50
- * The CheckpointIdsListener type describes a function that is used to listen to
51
- * changes to the checkpoint Ids in a Checkpoints object.
52
- *
53
- * This has schema-based typing. The following is a simplified representation:
54
- *
55
- * ```ts override
56
- * (checkpoints: Checkpoints) => void;
57
- * ```
58
- *
59
- * A CheckpointIdsListener is provided when using the addCheckpointIdsListener
60
- * method. See that method for specific examples.
61
- *
62
- * When called, a CheckpointIdsListener is given a reference to the Checkpoints
63
- * object.
64
- * @param checkpoints A reference to the Checkpoints object that changed.
65
- * @category Listener
66
- * @since v1.0.0
67
- */
68
- export type CheckpointIdsListener<Schemas extends OptionalSchemas> = (
69
- checkpoints: Checkpoints<Schemas>,
70
- ) => void;
71
-
72
- /**
73
- * The CheckpointListener type describes a function that is used to listen to
74
- * changes to a checkpoint's label in a Checkpoints object.
75
- *
76
- * This has schema-based typing. The following is a simplified representation:
77
- *
78
- * ```ts override
79
- * (
80
- * checkpoints: Checkpoints,
81
- * checkpointId: Id,
82
- * ) => void;
83
- * ```
84
- *
85
- * A CheckpointListener is provided when using the addCheckpointListener method.
86
- * See that method for specific examples.
87
- *
88
- * When called, a CheckpointListener is given a reference to the Checkpoints
89
- * object, and the Id of the checkpoint whose label changed.
90
- * @param checkpoints A reference to the Checkpoints object that changed.
91
- * @param checkpointId The Id of the checkpoint that changed.
92
- * @category Listener
93
- * @since v1.0.0
94
- */
95
- export type CheckpointListener<Schemas extends OptionalSchemas> = (
96
- checkpoints: Checkpoints<Schemas>,
97
- checkpointId: Id,
98
- ) => void;
99
-
100
- /**
101
- * The CheckpointsListenerStats type describes the number of listeners
102
- * registered with the Checkpoints object, and can be used for debugging
103
- * purposes.
104
- *
105
- * A CheckpointsListenerStats object is returned from the getListenerStats
106
- * method.
107
- * @category Development
108
- * @since v1.0.0
109
- */
110
- export type CheckpointsListenerStats = {
111
- /**
112
- * The number of CheckpointIdsListener functions registered with the
113
- * Checkpoints object.
114
- * @category Stat
115
- * @since v1.0.0
116
- */
117
- checkpointIds: number;
118
- /**
119
- * The number of CheckpointListener functions registered with the Checkpoints
120
- * object.
121
- * @category Stat
122
- * @since v1.0.0
123
- */
124
- checkpoint: number;
125
- };
126
-
127
- /**
128
- * A Checkpoints object lets you set checkpoints on a Store, and move forward
129
- * and backward through them to create undo and redo functionality.
130
- *
131
- * Create a Checkpoints object easily with the createCheckpoints function. From
132
- * there, you can set checkpoints (with the addCheckpoint method), query the
133
- * checkpoints available (with the getCheckpointIds method), move forward and
134
- * backward through them (with the goBackward method, goForward method, and goTo
135
- * method), and add listeners for when the list checkpoints changes (with the
136
- * addCheckpointIdsListener method).
137
- *
138
- * Checkpoints work for both changes to tabular data and to keyed value data.
139
- *
140
- * Every checkpoint can be given a label which can be used to describe the
141
- * actions that changed the Store before this checkpoint. This can be useful for
142
- * interfaces that let users 'Undo [last action]'.
143
- * @example
144
- * This example shows a simple lifecycle of a Checkpoints object: from creation,
145
- * to adding a checkpoint, getting the list of available checkpoints, and then
146
- * registering and removing a listener for them.
147
- *
148
- * ```js
149
- * import {createCheckpoints, createStore} from 'tinybase';
150
- *
151
- * const store = createStore()
152
- * .setTables({pets: {fido: {sold: false}}})
153
- * .setValue('open', true);
154
- *
155
- * const checkpoints = createCheckpoints(store);
156
- * checkpoints.setSize(200);
157
- * console.log(checkpoints.getCheckpointIds());
158
- * // -> [[], '0', []]
159
- *
160
- * store.setCell('pets', 'fido', 'sold', true);
161
- * checkpoints.addCheckpoint('sale');
162
- * console.log(checkpoints.getCheckpointIds());
163
- * // -> [['0'], '1', []]
164
- *
165
- * checkpoints.goBackward();
166
- * console.log(store.getCell('pets', 'fido', 'sold'));
167
- * // -> false
168
- * console.log(checkpoints.getCheckpointIds());
169
- * // -> [[], '0', ['1']]
170
- *
171
- * store.setValue('open', false);
172
- * checkpoints.addCheckpoint('closed');
173
- * console.log(checkpoints.getCheckpointIds());
174
- * // -> [['0'], '2', []]
175
- *
176
- * checkpoints.goBackward();
177
- * console.log(store.getValue('open'));
178
- * // -> true
179
- * console.log(checkpoints.getCheckpointIds());
180
- * // -> [[], '0', ['2']]
181
- *
182
- * const listenerId = checkpoints.addCheckpointIdsListener(() => {
183
- * console.log(checkpoints.getCheckpointIds());
184
- * });
185
- * store.setCell('pets', 'fido', 'species', 'dog');
186
- * // -> [['0'], undefined, []]
187
- * checkpoints.addCheckpoint();
188
- * // -> [['0'], '3', []]
189
- * // Previous redo of checkpoints '1' and '2' are now not possible.
190
- *
191
- * checkpoints.delListener(listenerId);
192
- * ```
193
- * @see Using Checkpoints guide
194
- * @see Todo App demos
195
- * @see Drawing demo
196
- * @category Checkpoints
197
- * @since v1.0.0
198
- */
199
- export interface Checkpoints<in out Schemas extends OptionalSchemas> {
200
- /**
201
- * The setSize method lets you specify how many checkpoints the Checkpoints
202
- * object will store.
203
- *
204
- * This has schema-based typing. The following is a simplified representation:
205
- *
206
- * ```ts override
207
- * setSize(size: number): Checkpoints;
208
- * ```
209
- *
210
- * If you set more checkpoints than this size, the oldest checkpoints will be
211
- * pruned to make room for more recent ones.
212
- *
213
- * The default size for a newly-created Checkpoints object is 100.
214
- * @param size The number of checkpoints that this Checkpoints object should
215
- * hold.
216
- * @returns A reference to the Checkpoints object.
217
- * @example
218
- * This example creates a Store, adds a Checkpoints object, reduces the size
219
- * of the Checkpoints object dramatically and then creates more than that
220
- * number of checkpoints to demonstrate the oldest being pruned.
221
- *
222
- * ```js
223
- * import {createCheckpoints, createStore} from 'tinybase';
224
- *
225
- * const store = createStore().setTables({pets: {fido: {views: 0}}});
226
- *
227
- * const checkpoints = createCheckpoints(store);
228
- * checkpoints.setSize(2);
229
- * console.log(checkpoints.getCheckpointIds());
230
- * // -> [[], '0', []]
231
- *
232
- * store.setCell('pets', 'fido', 'views', 1);
233
- * checkpoints.addCheckpoint();
234
- * console.log(checkpoints.getCheckpointIds());
235
- * // -> [['0'], '1', []]
236
- *
237
- * store.setCell('pets', 'fido', 'views', 2);
238
- * checkpoints.addCheckpoint();
239
- * console.log(checkpoints.getCheckpointIds());
240
- * // -> [['0', '1'], '2', []]
241
- *
242
- * store.setCell('pets', 'fido', 'views', 3);
243
- * checkpoints.addCheckpoint();
244
- * console.log(checkpoints.getCheckpointIds());
245
- * // -> [['1', '2'], '3', []]
246
- * ```
247
- * @category Configuration
248
- * @since v1.0.0
249
- */
250
- setSize(size: number): Checkpoints<Schemas>;
251
-
252
- /**
253
- * The addCheckpoint method records a checkpoint of the Store into the
254
- * Checkpoints object that can be reverted to in the future.
255
- *
256
- * If no changes have been made to the Store since the last time a checkpoint
257
- * was made, this method will have no effect.
258
- *
259
- * The optional `label` parameter can be used to describe the actions that
260
- * changed the Store before this checkpoint. This can be useful for interfaces
261
- * that let users 'Undo [last action]'.
262
- * @param label An optional label to describe the actions leading up to this
263
- * checkpoint.
264
- * @returns The Id of the newly-created checkpoint.
265
- * @example
266
- * This example creates a Store, adds a Checkpoints object, and adds two
267
- * checkpoints, one with a label.
268
- *
269
- * ```js
270
- * import {createCheckpoints, createStore} from 'tinybase';
271
- *
272
- * const store = createStore().setTables({pets: {fido: {sold: false}}});
273
- *
274
- * const checkpoints = createCheckpoints(store);
275
- * console.log(checkpoints.getCheckpointIds());
276
- * // -> [[], '0', []]
277
- *
278
- * store.setCell('pets', 'fido', 'species', 'dog');
279
- * const checkpointId1 = checkpoints.addCheckpoint();
280
- * console.log(checkpointId1);
281
- * // -> '1'
282
- *
283
- * console.log(checkpoints.getCheckpointIds());
284
- * // -> [['0'], '1', []]
285
- *
286
- * store.setCell('pets', 'fido', 'sold', true);
287
- * checkpoints.addCheckpoint('sale');
288
- * console.log(checkpoints.getCheckpointIds());
289
- * // -> [['0', '1'], '2', []]
290
- *
291
- * console.log(checkpoints.getCheckpoint('2'));
292
- * // -> 'sale'
293
- * ```
294
- * @category Setter
295
- * @since v1.0.0
296
- */
297
- addCheckpoint(label?: string): Id;
298
-
299
- /**
300
- * The setCheckpoint method updates the label for a checkpoint in the
301
- * Checkpoints object after it has been created.
302
- *
303
- * This has schema-based typing. The following is a simplified representation:
304
- *
305
- * ```ts override
306
- * setCheckpoint(checkpointId: Id, label: string): Checkpoints;
307
- * ```
308
- *
309
- * The `label` parameter can be used to describe the actions that changed the
310
- * Store before the given checkpoint. This can be useful for interfaces that
311
- * let users 'Undo [last action]'.
312
- *
313
- * Generally you will provide the `label` parameter when the addCheckpoint
314
- * method is called. Use this setCheckpoint method only when you need to
315
- * change the label at a later point.
316
- *
317
- * You cannot add a label to a checkpoint that does not yet exist.
318
- * @param checkpointId The Id of the checkpoint to set the label for.
319
- * @param label A label to describe the actions leading up to this checkpoint
320
- * or left undefined if you want to clear the current label.
321
- * @returns A reference to the Checkpoints object.
322
- * @example
323
- * This example creates a Store, adds a Checkpoints object, and sets two
324
- * checkpoints, one with a label, which are both then re-labelled.
325
- *
326
- * ```js
327
- * import {createCheckpoints, createStore} from 'tinybase';
328
- *
329
- * const store = createStore().setTables({pets: {fido: {sold: false}}});
330
- *
331
- * const checkpoints = createCheckpoints(store);
332
- * console.log(checkpoints.getCheckpointIds());
333
- * // -> [[], '0', []]
334
- *
335
- * store.setCell('pets', 'fido', 'species', 'dog');
336
- * checkpoints.addCheckpoint();
337
- * store.setCell('pets', 'fido', 'sold', true);
338
- * checkpoints.addCheckpoint('sale');
339
- *
340
- * console.log(checkpoints.getCheckpoint('1'));
341
- * // -> ''
342
- * console.log(checkpoints.getCheckpoint('2'));
343
- * // -> 'sale'
344
- *
345
- * checkpoints.setCheckpoint('1', 'identified');
346
- * checkpoints.setCheckpoint('2', '');
347
- *
348
- * console.log(checkpoints.getCheckpoint('1'));
349
- * // -> 'identified'
350
- * console.log(checkpoints.getCheckpoint('2'));
351
- * // -> ''
352
- *
353
- * checkpoints.setCheckpoint('3', 'unknown');
354
- * console.log(checkpoints.getCheckpoint('3'));
355
- * // -> undefined
356
- * ```
357
- * @category Setter
358
- * @since v1.0.0
359
- */
360
- setCheckpoint(checkpointId: Id, label: string): Checkpoints<Schemas>;
361
-
362
- /**
363
- * The getStore method returns a reference to the underlying Store that is
364
- * backing this Checkpoints object.
365
- * @returns A reference to the Store.
366
- * @example
367
- * This example creates a Checkpoints object against a newly-created Store
368
- * and then gets its reference in order to update its data and set a
369
- * checkpoint.
370
- *
371
- * This has schema-based typing. The following is a simplified representation:
372
- *
373
- * ```ts override
374
- * getStore(): Store;
375
- * ```
376
- *
377
- * ```js
378
- * import {createCheckpoints, createStore} from 'tinybase';
379
- *
380
- * const checkpoints = createCheckpoints(createStore());
381
- * checkpoints.getStore().setCell('pets', 'fido', 'species', 'dog');
382
- * checkpoints.addCheckpoint();
383
- * console.log(checkpoints.getCheckpointIds());
384
- * // -> [['0'], '1', []]
385
- * ```
386
- * @category Getter
387
- * @since v1.0.0
388
- */
389
- getStore(): Store<Schemas>;
390
-
391
- /**
392
- * The getCheckpointIds method returns an array of the checkpoint Ids being
393
- * managed by this Checkpoints object.
394
- *
395
- * The returned CheckpointIds array contains 'backward' checkpoint Ids, the
396
- * current checkpoint Id (if present), and the 'forward' checkpointIds.
397
- * Together, these are sufficient to understand the state of the Checkpoints
398
- * object and what movement is possible backward or forward through the
399
- * checkpoint stack.
400
- * @returns A CheckpointIds array, containing the checkpoint Ids managed by
401
- * this Checkpoints object.
402
- * @example
403
- * This example creates a Store, adds a Checkpoints object, and then gets the
404
- * Ids of the checkpoints as it sets them and moves around the stack.
405
- *
406
- * ```js
407
- * import {createCheckpoints, createStore} from 'tinybase';
408
- *
409
- * const store = createStore().setTables({pets: {fido: {sold: false}}});
410
- *
411
- * const checkpoints = createCheckpoints(store);
412
- * console.log(checkpoints.getCheckpointIds());
413
- * // -> [[], '0', []]
414
- *
415
- * store.setCell('pets', 'fido', 'sold', true);
416
- * checkpoints.addCheckpoint('sale');
417
- * console.log(checkpoints.getCheckpointIds());
418
- * // -> [['0'], '1', []]
419
- *
420
- * checkpoints.goBackward();
421
- * console.log(checkpoints.getCheckpointIds());
422
- * // -> [[], '0', ['1']]
423
- *
424
- * checkpoints.goForward();
425
- * console.log(checkpoints.getCheckpointIds());
426
- * // -> [['0'], '1', []]
427
- * ```
428
- * @category Getter
429
- * @since v1.0.0
430
- */
431
- getCheckpointIds(): CheckpointIds;
432
-
433
- /**
434
- * The forEachCheckpoint method takes a function that it will then call for
435
- * each Checkpoint in a specified Checkpoints object.
436
- *
437
- * This method is useful for iterating over the structure of the Checkpoints
438
- * object in a functional style. The `checkpointCallback` parameter is a
439
- * CheckpointCallback function that will be called with the Id of each
440
- * Checkpoint.
441
- * @param checkpointCallback The function that should be called for every
442
- * Checkpoint.
443
- * @example
444
- * This example iterates over each Checkpoint in a Checkpoints object.
445
- *
446
- * ```js
447
- * import {createCheckpoints, createStore} from 'tinybase';
448
- *
449
- * const store = createStore().setTables({pets: {fido: {sold: false}}});
450
- * const checkpoints = createCheckpoints(store);
451
- * store.setCell('pets', 'fido', 'sold', true);
452
- * checkpoints.addCheckpoint('sale');
453
- *
454
- * checkpoints.forEachCheckpoint((checkpointId, label) => {
455
- * console.log(`${checkpointId}:${label}`);
456
- * });
457
- * // -> '0:'
458
- * // -> '1:sale'
459
- * ```
460
- * @category Iterator
461
- * @since v1.0.0
462
- */
463
- forEachCheckpoint(checkpointCallback: CheckpointCallback): void;
464
-
465
- /**
466
- * The hasCheckpoint method returns a boolean indicating whether a given
467
- * Checkpoint exists in the Checkpoints object.
468
- * @param checkpointId The Id of a possible Checkpoint in the Checkpoints
469
- * object.
470
- * @returns Whether a Checkpoint with that Id exists.
471
- * @example
472
- * This example shows two simple Checkpoint existence checks.
473
- *
474
- * ```js
475
- * import {createCheckpoints, createStore} from 'tinybase';
476
- *
477
- * const store = createStore().setTables({pets: {fido: {sold: false}}});
478
- * const checkpoints = createCheckpoints(store);
479
- * console.log(checkpoints.hasCheckpoint('0'));
480
- * // -> true
481
- * console.log(checkpoints.hasCheckpoint('1'));
482
- * // -> false
483
- * ```
484
- * @category Getter
485
- * @since v1.0.0
486
- */
487
- hasCheckpoint(checkpointId: Id): boolean;
488
-
489
- /**
490
- * The getCheckpoint method fetches the label for a checkpoint, if it had been
491
- * provided at the time of the addCheckpoint method or set subsequently with
492
- * the setCheckpoint method.
493
- *
494
- * If the checkpoint has had no label provided, this method will return an
495
- * empty string.
496
- * @param checkpointId The Id of the checkpoint to get the label for.
497
- * @returns A string label for the requested checkpoint, an empty string if it
498
- * was never set, or `undefined` if the checkpoint does not exist.
499
- * @example
500
- * This example creates a Store, adds a Checkpoints object, and sets a
501
- * checkpoint with a label, before retrieving it again.
502
- *
503
- * ```js
504
- * import {createCheckpoints, createStore} from 'tinybase';
505
- *
506
- * const store = createStore().setTables({pets: {fido: {sold: false}}});
507
- *
508
- * const checkpoints = createCheckpoints(store);
509
- * store.setCell('pets', 'fido', 'sold', true);
510
- * console.log(checkpoints.addCheckpoint('sale'));
511
- * // -> '1'
512
- *
513
- * console.log(checkpoints.getCheckpoint('1'));
514
- * // -> 'sale'
515
- * ```
516
- * @example
517
- * This example creates a Store, adds a Checkpoints object, and sets a
518
- * checkpoint without a label, setting it subsequently. A non-existent
519
- * checkpoint return an `undefined` label.
520
- *
521
- * ```js
522
- * import {createCheckpoints, createStore} from 'tinybase';
523
- *
524
- * const store = createStore().setTables({pets: {fido: {sold: false}}});
525
- *
526
- * const checkpoints = createCheckpoints(store);
527
- * store.setCell('pets', 'fido', 'sold', true);
528
- * checkpoints.addCheckpoint();
529
- * console.log(checkpoints.getCheckpoint('1'));
530
- * // -> ''
531
- *
532
- * checkpoints.setCheckpoint('1', 'sold');
533
- * console.log(checkpoints.getCheckpoint('1'));
534
- * // -> 'sold'
535
- *
536
- * console.log(checkpoints.getCheckpoint('2'));
537
- * // -> undefined
538
- * ```
539
- * @category Getter
540
- * @since v1.0.0
541
- */
542
- getCheckpoint(checkpointId: Id): string | undefined;
543
-
544
- /**
545
- * The addCheckpointIdsListener method registers a listener function with the
546
- * Checkpoints object that will be called whenever its set of checkpoints
547
- * changes.
548
- *
549
- * This has schema-based typing. The following is a simplified representation:
550
- *
551
- * ```ts override
552
- * addCheckpointIdsListener(listener: CheckpointIdsListener): Id;
553
- * ```
554
- *
555
- * The provided listener is a CheckpointIdsListener function, and will be
556
- * called with a reference to the Checkpoints object.
557
- * @param listener The function that will be called whenever the checkpoints
558
- * change.
559
- * @returns A unique Id for the listener that can later be used to remove it.
560
- * @example
561
- * This example creates a Store, a Checkpoints object, and then registers a
562
- * listener that responds to any changes to the checkpoints.
563
- *
564
- * ```js
565
- * import {createCheckpoints, createStore} from 'tinybase';
566
- *
567
- * const store = createStore().setTables({pets: {fido: {sold: false}}});
568
- *
569
- * const checkpoints = createCheckpoints(store);
570
- * console.log(checkpoints.getCheckpointIds());
571
- * // -> [[], '0', []]
572
- *
573
- * const listenerId = checkpoints.addCheckpointIdsListener(() => {
574
- * console.log('Checkpoint Ids changed');
575
- * console.log(checkpoints.getCheckpointIds());
576
- * });
577
- *
578
- * store.setCell('pets', 'fido', 'species', 'dog');
579
- * // -> 'Checkpoint Ids changed'
580
- * // -> [['0'], undefined, []]
581
- *
582
- * checkpoints.addCheckpoint();
583
- * // -> 'Checkpoint Ids changed'
584
- * // -> [['0'], '1', []]
585
- *
586
- * checkpoints.goBackward();
587
- * // -> 'Checkpoint Ids changed'
588
- * // -> [[], '0', ['1']]
589
- *
590
- * checkpoints.goForward();
591
- * // -> 'Checkpoint Ids changed'
592
- * // -> [['0'], '1', []]
593
- *
594
- * checkpoints.delListener(listenerId);
595
- * ```
596
- * @category Listener
597
- * @since v1.0.0
598
- */
599
- addCheckpointIdsListener(listener: CheckpointIdsListener<Schemas>): Id;
600
-
601
- /**
602
- * The addCheckpointListener method registers a listener function with the
603
- * Checkpoints object that will be called whenever the label of a checkpoint
604
- * changes.
605
- *
606
- * This has schema-based typing. The following is a simplified representation:
607
- *
608
- * ```ts override
609
- * addCheckpointListener(
610
- * checkpointId: IdOrNull,
611
- * listener: CheckpointListener,
612
- * ): Id;
613
- * ```
614
- *
615
- * You can either listen to a single checkpoint label (by specifying the
616
- * checkpoint Id as the method's first parameter), or changes to any
617
- * checkpoint label (by providing a `null` wildcard).
618
- *
619
- * The provided listener is a CheckpointListener function, and will be called
620
- * with a reference to the Checkpoints object, and the Id of the checkpoint
621
- * whose label changed.
622
- * @param checkpointId The Id of the checkpoint to listen to, or `null` as a
623
- * wildcard.
624
- * @param listener The function that will be called whenever the checkpoint
625
- * label changes.
626
- * @returns A unique Id for the listener that can later be used to remove it.
627
- * @example
628
- * This example creates a Store, a Checkpoints object, and then registers a
629
- * listener that responds to any changes to a specific checkpoint label,
630
- * including when the checkpoint no longer exists.
631
- *
632
- * ```js
633
- * import {createCheckpoints, createStore} from 'tinybase';
634
- *
635
- * const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
636
- *
637
- * const checkpoints = createCheckpoints(store);
638
- * console.log(checkpoints.getCheckpointIds());
639
- * // -> [[], '0', []]
640
- *
641
- * const listenerId = checkpoints.addCheckpointListener('1', () => {
642
- * console.log('Checkpoint 1 label changed');
643
- * console.log(checkpoints.getCheckpoint('1'));
644
- * });
645
- *
646
- * store.setCell('pets', 'fido', 'sold', true);
647
- * checkpoints.addCheckpoint('sale');
648
- * // -> 'Checkpoint 1 label changed'
649
- * // -> 'sale'
650
- *
651
- * checkpoints.setCheckpoint('1', 'sold');
652
- * // -> 'Checkpoint 1 label changed'
653
- * // -> 'sold'
654
- *
655
- * checkpoints.setCheckpoint('1', 'sold');
656
- * // The listener is not called when the label does not change.
657
- *
658
- * checkpoints.goTo('0');
659
- * store.setCell('pets', 'fido', 'sold', false);
660
- * // -> 'Checkpoint 1 label changed'
661
- * // -> undefined
662
- * // The checkpoint no longer exists.
663
- *
664
- * checkpoints.delListener(listenerId);
665
- * ```
666
- * @category Listener
667
- * @since v1.0.0
668
- */
669
- addCheckpointListener(
670
- checkpointId: IdOrNull,
671
- listener: CheckpointListener<Schemas>,
672
- ): Id;
673
-
674
- /**
675
- * The delListener method removes a listener that was previously added to the
676
- * Checkpoints object.
677
- *
678
- * This has schema-based typing. The following is a simplified representation:
679
- *
680
- * ```ts override
681
- * delListener(listenerId: Id): Checkpoints;
682
- * ```
683
- *
684
- * Use the Id returned by the addCheckpointIdsListener method. Note that the
685
- * Checkpoints object may re-use this Id for future listeners added to it.
686
- * @param listenerId The Id of the listener to remove.
687
- * @returns A reference to the Checkpoints object.
688
- * @example
689
- * This example creates a Store, a Checkpoints object, registers a listener,
690
- * and then removes it.
691
- *
692
- * ```js
693
- * import {createCheckpoints, createStore} from 'tinybase';
694
- *
695
- * const store = createStore().setTables({pets: {fido: {sold: false}}});
696
- *
697
- * const checkpoints = createCheckpoints(store);
698
- * console.log(checkpoints.getCheckpointIds());
699
- * // -> [[], '0', []]
700
- *
701
- * const listenerId = checkpoints.addCheckpointIdsListener(() => {
702
- * console.log('checkpoints changed');
703
- * });
704
- *
705
- * store.setCell('pets', 'fido', 'species', 'dog');
706
- * // -> 'checkpoints changed'
707
- *
708
- * checkpoints.addCheckpoint();
709
- * // -> 'checkpoints changed'
710
- *
711
- * checkpoints.delListener(listenerId);
712
- *
713
- * store.setCell('pets', 'fido', 'sold', 'true');
714
- * // -> undefined
715
- * // The listener is not called.
716
- * ```
717
- * @category Listener
718
- * @since v1.0.0
719
- */
720
- delListener(listenerId: Id): Checkpoints<Schemas>;
721
-
722
- /**
723
- * The goBackward method moves the state of the underlying Store back to the
724
- * previous checkpoint, effectively performing an 'undo' on the Store data.
725
- *
726
- * This has schema-based typing. The following is a simplified representation:
727
- *
728
- * ```ts override
729
- * goBackward(): Checkpoints;
730
- * ```
731
- *
732
- * If there is no previous checkpoint to return to, this method has no effect.
733
- * @returns A reference to the Checkpoints object.
734
- * @example
735
- * This example creates a Store, a Checkpoints object, makes a change and then
736
- * goes backward to the state of the Store before the change.
737
- *
738
- * ```js
739
- * import {createCheckpoints, createStore} from 'tinybase';
740
- *
741
- * const store = createStore().setTables({pets: {fido: {sold: false}}});
742
- *
743
- * const checkpoints = createCheckpoints(store);
744
- * console.log(checkpoints.getCheckpointIds());
745
- * // -> [[], '0', []]
746
- *
747
- * store.setCell('pets', 'fido', 'sold', true);
748
- * checkpoints.addCheckpoint('sale');
749
- * console.log(checkpoints.getCheckpointIds());
750
- * // -> [['0'], '1', []]
751
- *
752
- * checkpoints.goBackward();
753
- * console.log(store.getCell('pets', 'fido', 'sold'));
754
- * // -> false
755
- * console.log(checkpoints.getCheckpointIds());
756
- * // -> [[], '0', ['1']]
757
- * ```
758
- * @category Movement
759
- * @since v1.0.0
760
- */
761
- goBackward(): Checkpoints<Schemas>;
762
-
763
- /**
764
- * The goForward method moves the state of the underlying Store forwards to a
765
- * future checkpoint, effectively performing an 'redo' on the Store data.
766
- *
767
- * This has schema-based typing. The following is a simplified representation:
768
- *
769
- * ```ts override
770
- * goForward(): Checkpoints;
771
- * ```
772
- *
773
- * If there is no future checkpoint to return to, this method has no effect.
774
- *
775
- * Note that if you have previously used the goBackward method to undo
776
- * changes, the forwards 'redo' stack will only exist while you do not make
777
- * changes to the Store. In general the goForward method is expected to be
778
- * used to redo changes that were just undone.
779
- * @returns A reference to the Checkpoints object.
780
- * @example
781
- * This example creates a Store, a Checkpoints object, makes a change and then
782
- * goes backward to the state of the Store before the change. It then goes
783
- * forward again to restore the state with the changes.
784
- *
785
- * ```js
786
- * import {createCheckpoints, createStore} from 'tinybase';
787
- *
788
- * const store = createStore().setTables({pets: {fido: {sold: false}}});
789
- *
790
- * const checkpoints = createCheckpoints(store);
791
- * console.log(checkpoints.getCheckpointIds());
792
- * // -> [[], '0', []]
793
- *
794
- * store.setCell('pets', 'fido', 'sold', true);
795
- * checkpoints.addCheckpoint('sale');
796
- * console.log(checkpoints.getCheckpointIds());
797
- * // -> [['0'], '1', []]
798
- *
799
- * checkpoints.goBackward();
800
- * console.log(store.getCell('pets', 'fido', 'sold'));
801
- * // -> false
802
- * console.log(checkpoints.getCheckpointIds());
803
- * // -> [[], '0', ['1']]
804
- *
805
- * checkpoints.goForward();
806
- * console.log(store.getCell('pets', 'fido', 'sold'));
807
- * // -> true
808
- * console.log(checkpoints.getCheckpointIds());
809
- * // -> [['0'], '1', []]
810
- * ```
811
- * @example
812
- * This example creates a Store, a Checkpoints object, makes a change and then
813
- * goes backward to the state of the Store before the change. It makes a new
814
- * change, the redo stack disappears, and then the attempt to forward again
815
- * has no effect.
816
- *
817
- * ```js
818
- * import {createCheckpoints, createStore} from 'tinybase';
819
- *
820
- * const store = createStore().setTables({pets: {fido: {sold: false}}});
821
- *
822
- * const checkpoints = createCheckpoints(store);
823
- * console.log(checkpoints.getCheckpointIds());
824
- * // -> [[], '0', []]
825
- *
826
- * store.setCell('pets', 'fido', 'sold', true);
827
- * checkpoints.addCheckpoint('sale');
828
- * console.log(checkpoints.getCheckpointIds());
829
- * // -> [['0'], '1', []]
830
- *
831
- * checkpoints.goBackward();
832
- * console.log(store.getCell('pets', 'fido', 'sold'));
833
- * // -> false
834
- * console.log(checkpoints.getCheckpointIds());
835
- * // -> [[], '0', ['1']]
836
- *
837
- * store.setCell('pets', 'fido', 'color', 'brown');
838
- * console.log(checkpoints.getCheckpointIds());
839
- * // -> [['0'], undefined, []]
840
- *
841
- * checkpoints.goForward();
842
- * console.log(store.getCell('pets', 'fido', 'sold'));
843
- * // -> false
844
- * console.log(checkpoints.getCheckpointIds());
845
- * // -> [['0'], undefined, []]
846
- * // The original change cannot be redone.
847
- * ```
848
- * @category Movement
849
- * @since v1.0.0
850
- */
851
- goForward(): Checkpoints<Schemas>;
852
-
853
- /**
854
- * The goTo method moves the state of the underlying Store backwards or
855
- * forwards to a specified checkpoint.
856
- *
857
- * This has schema-based typing. The following is a simplified representation:
858
- *
859
- * ```ts override
860
- * goTo(checkpointId: Id): Checkpoints;
861
- * ```
862
- *
863
- * If there is no checkpoint with the Id specified, this method has no effect.
864
- * @param checkpointId The Id of the checkpoint to move to.
865
- * @returns A reference to the Checkpoints object.
866
- * @example
867
- * This example creates a Store, a Checkpoints object, makes two changes and
868
- * then goes directly to the state of the Store before the two changes. It
869
- * then goes forward again one change, also using the goTo method. Finally it
870
- * tries to go to a checkpoint that does not exist.
871
- *
872
- * ```js
873
- * import {createCheckpoints, createStore} from 'tinybase';
874
- *
875
- * const store = createStore().setTables({pets: {fido: {sold: false}}});
876
- *
877
- * const checkpoints = createCheckpoints(store);
878
- * console.log(checkpoints.getCheckpointIds());
879
- * // -> [[], '0', []]
880
- *
881
- * store.setCell('pets', 'fido', 'color', 'brown');
882
- * checkpoints.addCheckpoint('identification');
883
- * store.setCell('pets', 'fido', 'sold', true);
884
- * checkpoints.addCheckpoint('sale');
885
- * console.log(checkpoints.getCheckpointIds());
886
- * // -> [['0', '1'], '2', []]
887
- *
888
- * checkpoints.goTo('0');
889
- * console.log(store.getTables());
890
- * // -> {pets: {fido: {sold: false}}}
891
- * console.log(checkpoints.getCheckpointIds());
892
- * // -> [[], '0', ['1', '2']]
893
- *
894
- * checkpoints.goTo('1');
895
- * console.log(store.getTables());
896
- * // -> {pets: {fido: {sold: false, color: 'brown'}}}
897
- * console.log(checkpoints.getCheckpointIds());
898
- * // -> [['0'], '1', ['2']]
899
- *
900
- * checkpoints.goTo('3');
901
- * console.log(store.getTables());
902
- * // -> {pets: {fido: {sold: false, color: 'brown'}}}
903
- * console.log(checkpoints.getCheckpointIds());
904
- * // -> [['0'], '1', ['2']]
905
- * ```
906
- * @category Movement
907
- * @since v1.0.0
908
- */
909
- goTo(checkpointId: Id): Checkpoints<Schemas>;
910
-
911
- /**
912
- * The clear method resets this Checkpoints object to its initial state,
913
- * removing all the checkpoints it has been managing.
914
- *
915
- * This has schema-based typing. The following is a simplified representation:
916
- *
917
- * ```ts override
918
- * clear(): Checkpoints;
919
- * ```
920
- *
921
- * Obviously this method should be used with caution as it destroys the
922
- * ability to undo or redo recent changes to the Store (though of course the
923
- * Store itself is not reset by this method).
924
- *
925
- * This method can be useful when a Store is being loaded via a Persister
926
- * asynchronously after the Checkpoints object has been attached, and you
927
- * don't want users to be able to undo the initial load of the data. In this
928
- * case you could call the clear method immediately after the initial load so
929
- * that that is the baseline from which all subsequent changes are tracked.
930
- * @returns A reference to the Checkpoints object.
931
- * @example
932
- * This example creates a Store, a Checkpoints object, adds a listener, makes
933
- * a change and then clears the checkpoints.
934
- *
935
- * ```js
936
- * import {createCheckpoints, createStore} from 'tinybase';
937
- *
938
- * const store = createStore().setTables({pets: {fido: {sold: false}}});
939
- *
940
- * const checkpoints = createCheckpoints(store);
941
- * console.log(checkpoints.getCheckpointIds());
942
- * // -> [[], '0', []]
943
- *
944
- * const listenerId = checkpoints.addCheckpointIdsListener(() => {
945
- * console.log('checkpoints changed');
946
- * });
947
- *
948
- * store.setCell('pets', 'fido', 'color', 'brown');
949
- * // -> 'checkpoints changed'
950
- * checkpoints.addCheckpoint();
951
- * // -> 'checkpoints changed'
952
- * store.setCell('pets', 'fido', 'sold', true);
953
- * // -> 'checkpoints changed'
954
- * checkpoints.addCheckpoint();
955
- * // -> 'checkpoints changed'
956
- *
957
- * console.log(store.getTables());
958
- * // -> {pets: {fido: {sold: true, color: 'brown'}}}
959
- * console.log(checkpoints.getCheckpointIds());
960
- * // -> [['0', '1'], '2', []]
961
- *
962
- * checkpoints.clear();
963
- * // -> 'checkpoints changed'
964
- *
965
- * console.log(store.getTables());
966
- * // -> {pets: {fido: {sold: true, color: 'brown'}}}
967
- * console.log(checkpoints.getCheckpointIds());
968
- * // -> [[], '0', []]
969
- *
970
- * checkpoints.delListener(listenerId);
971
- * ```
972
- * @category Lifecycle
973
- * @since v1.0.0
974
- */
975
- clear(): Checkpoints<Schemas>;
976
-
977
- /**
978
- * The clearForward method resets just the 'redo' checkpoints it has been
979
- * managing.
980
- *
981
- * This has schema-based typing. The following is a simplified representation:
982
- *
983
- * ```ts override
984
- * clearForward(): Checkpoints;
985
- * ```
986
- *
987
- * Obviously this method should be used with caution as it destroys the
988
- * ability to redo recent changes to the Store (though of course the Store
989
- * itself is not reset by this method).
990
- *
991
- * This method can be useful when you want to prohibit a user from redoing
992
- * changes they have undone. The 'backward' redo stack, and current checkpoint
993
- * are not affected.
994
- * @returns A reference to the Checkpoints object.
995
- * @example
996
- * This example creates a Store, a Checkpoints object, adds a listener, makes
997
- * a change and then clears the forward checkpoints.
998
- *
999
- * ```js
1000
- * import {createCheckpoints, createStore} from 'tinybase';
1001
- *
1002
- * const store = createStore().setTables({pets: {fido: {sold: false}}});
1003
- *
1004
- * const checkpoints = createCheckpoints(store);
1005
- * console.log(checkpoints.getCheckpointIds());
1006
- * // -> [[], '0', []]
1007
- *
1008
- * const listenerId = checkpoints.addCheckpointIdsListener(() => {
1009
- * console.log('checkpoints changed');
1010
- * });
1011
- *
1012
- * store.setCell('pets', 'fido', 'color', 'brown');
1013
- * // -> 'checkpoints changed'
1014
- * checkpoints.addCheckpoint();
1015
- * // -> 'checkpoints changed'
1016
- * store.setCell('pets', 'fido', 'sold', true);
1017
- * // -> 'checkpoints changed'
1018
- * checkpoints.addCheckpoint();
1019
- * // -> 'checkpoints changed'
1020
- * checkpoints.goBackward();
1021
- * // -> 'checkpoints changed'
1022
- *
1023
- * console.log(store.getTables());
1024
- * // -> {pets: {fido: {color: 'brown', sold: false}}}
1025
- * console.log(checkpoints.getCheckpointIds());
1026
- * // -> [['0'], '1', ['2']]
1027
- *
1028
- * checkpoints.clearForward();
1029
- * // -> 'checkpoints changed'
1030
- *
1031
- * console.log(checkpoints.getCheckpointIds());
1032
- * // -> [['0'], '1', []]
1033
- *
1034
- * checkpoints.delListener(listenerId);
1035
- * ```
1036
- * @category Lifecycle
1037
- * @since v4.5.3
1038
- */
1039
- clearForward(): Checkpoints<Schemas>;
1040
-
1041
- /**
1042
- * The destroy method should be called when this Checkpoints object is no
1043
- * longer used.
1044
- *
1045
- * This guarantees that all of the listeners that the object registered with
1046
- * the underlying Store are removed and it can be correctly garbage collected.
1047
- * @example
1048
- * This example creates a Store, adds a Checkpoints object (that registers a
1049
- * CellListener with the underlying Store), and then destroys it again,
1050
- * removing the listener.
1051
- *
1052
- * ```js
1053
- * import {createCheckpoints, createStore} from 'tinybase';
1054
- *
1055
- * const store = createStore().setTables({pets: {fido: {sold: false}}});
1056
- *
1057
- * const checkpoints = createCheckpoints(store);
1058
- * console.log(store.getListenerStats().cell);
1059
- * // -> 1
1060
- *
1061
- * checkpoints.destroy();
1062
- *
1063
- * console.log(store.getListenerStats().cell);
1064
- * // -> 0
1065
- * ```
1066
- * @category Lifecycle
1067
- * @since v1.0.0
1068
- */
1069
- destroy(): void;
1070
-
1071
- /**
1072
- * The getListenerStats method provides a set of statistics about the
1073
- * listeners registered with the Checkpoints object, and is used for debugging
1074
- * purposes.
1075
- *
1076
- * The CheckpointsListenerStats object contains a breakdown of the different
1077
- * types of listener.
1078
- *
1079
- * The method is intended to be used during development to ensure your
1080
- * application is not leaking listener registrations, for example.
1081
- * @returns A CheckpointsListenerStats object containing Checkpoints listener
1082
- * statistics.
1083
- * @example
1084
- * This example gets the listener statistics of a Checkpoints object.
1085
- *
1086
- * ```js
1087
- * import {createCheckpoints, createStore} from 'tinybase';
1088
- *
1089
- * const store = createStore();
1090
- * const checkpoints = createCheckpoints(store);
1091
- * checkpoints.addCheckpointIdsListener(() => {
1092
- * console.log('Checkpoint Ids changed');
1093
- * });
1094
- * checkpoints.addCheckpointListener(null, () => {
1095
- * console.log('Checkpoint label changed');
1096
- * });
1097
- *
1098
- * console.log(checkpoints.getListenerStats());
1099
- * // -> {checkpointIds: 1, checkpoint: 1}
1100
- * ```
1101
- * @category Development
1102
- * @since v1.0.0
1103
- */
1104
- getListenerStats(): CheckpointsListenerStats;
1105
- }
1106
-
1107
- /**
1108
- * The createCheckpoints function creates a Checkpoints object, and is the main
1109
- * entry point into the checkpoints module.
1110
- *
1111
- * This has schema-based typing. The following is a simplified representation:
1112
- *
1113
- * ```ts override
1114
- * createCheckpoints(store: Store): Checkpoints;
1115
- * ```
1116
- *
1117
- * A given Store can only have one Checkpoints object associated with it. If you
1118
- * call this function twice on the same Store, your second call will return a
1119
- * reference to the Checkpoints object created by the first.
1120
- * @param store The Store for which to set Checkpoints.
1121
- * @returns A reference to the new Checkpoints object.
1122
- * @example
1123
- * This example creates a Checkpoints object.
1124
- *
1125
- * ```js
1126
- * import {createCheckpoints, createStore} from 'tinybase';
1127
- *
1128
- * const store = createStore();
1129
- * const checkpoints = createCheckpoints(store);
1130
- * console.log(checkpoints.getCheckpointIds());
1131
- * // -> [[], '0', []]
1132
- * ```
1133
- * @example
1134
- * This example creates a Checkpoints object, and calls the method a second
1135
- * time for the same Store to return the same object.
1136
- *
1137
- * ```js
1138
- * import {createCheckpoints, createStore} from 'tinybase';
1139
- *
1140
- * const store = createStore();
1141
- * const checkpoints1 = createCheckpoints(store);
1142
- * const checkpoints2 = createCheckpoints(store);
1143
- * console.log(checkpoints1 === checkpoints2);
1144
- * // -> true
1145
- * ```
1146
- * @category Creation
1147
- * @since v1.0.0
1148
- */
1149
- export function createCheckpoints<Schemas extends OptionalSchemas>(
1150
- store: Store<Schemas>,
1151
- ): Checkpoints<Schemas>;