tinybase 3.0.4 → 3.0.5

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 (79) hide show
  1. package/package.json +21 -20
  2. package/readme.md +2 -2
  3. package/lib/cjs/checkpoints.d.ts +0 -959
  4. package/lib/cjs/common.d.ts +0 -115
  5. package/lib/cjs/indexes.d.ts +0 -966
  6. package/lib/cjs/metrics.d.ts +0 -827
  7. package/lib/cjs/persisters.d.ts +0 -727
  8. package/lib/cjs/queries.d.ts +0 -3024
  9. package/lib/cjs/relationships.d.ts +0 -1201
  10. package/lib/cjs/store.d.ts +0 -5244
  11. package/lib/cjs/tinybase.d.ts +0 -14
  12. package/lib/cjs/tools.d.ts +0 -512
  13. package/lib/cjs/ui-react.d.ts +0 -10921
  14. package/lib/cjs-es6/checkpoints.d.ts +0 -959
  15. package/lib/common.d.ts +0 -115
  16. package/lib/debug/checkpoints.d.ts +0 -959
  17. package/lib/debug/common.d.ts +0 -115
  18. package/lib/debug/indexes.d.ts +0 -966
  19. package/lib/debug/metrics.d.ts +0 -827
  20. package/lib/debug/persisters.d.ts +0 -727
  21. package/lib/debug/queries.d.ts +0 -3024
  22. package/lib/debug/relationships.d.ts +0 -1201
  23. package/lib/debug/store.d.ts +0 -5244
  24. package/lib/debug/tinybase.d.ts +0 -14
  25. package/lib/debug/tools.d.ts +0 -512
  26. package/lib/debug/ui-react.d.ts +0 -10921
  27. package/lib/es6/checkpoints.d.ts +0 -959
  28. package/lib/es6/common.d.ts +0 -115
  29. package/lib/es6/indexes.d.ts +0 -966
  30. package/lib/es6/metrics.d.ts +0 -827
  31. package/lib/es6/persisters.d.ts +0 -727
  32. package/lib/es6/queries.d.ts +0 -3024
  33. package/lib/es6/relationships.d.ts +0 -1201
  34. package/lib/es6/store.d.ts +0 -5244
  35. package/lib/es6/tinybase.d.ts +0 -14
  36. package/lib/es6/tools.d.ts +0 -512
  37. package/lib/es6/ui-react.d.ts +0 -10921
  38. package/lib/indexes.d.ts +0 -966
  39. package/lib/metrics.d.ts +0 -827
  40. package/lib/persisters.d.ts +0 -727
  41. package/lib/queries.d.ts +0 -3024
  42. package/lib/relationships.d.ts +0 -1201
  43. package/lib/store.d.ts +0 -5244
  44. package/lib/tinybase.d.ts +0 -14
  45. package/lib/tools.d.ts +0 -512
  46. package/lib/ui-react.d.ts +0 -10921
  47. package/lib/umd/checkpoints.d.ts +0 -959
  48. package/lib/umd/common.d.ts +0 -115
  49. package/lib/umd/indexes.d.ts +0 -966
  50. package/lib/umd/metrics.d.ts +0 -827
  51. package/lib/umd/persisters.d.ts +0 -727
  52. package/lib/umd/queries.d.ts +0 -3024
  53. package/lib/umd/relationships.d.ts +0 -1201
  54. package/lib/umd/store.d.ts +0 -5244
  55. package/lib/umd/tinybase.d.ts +0 -14
  56. package/lib/umd/tools.d.ts +0 -512
  57. package/lib/umd/ui-react.d.ts +0 -10921
  58. package/lib/umd-es6/checkpoints.d.ts +0 -959
  59. package/lib/umd-es6/common.d.ts +0 -115
  60. package/lib/umd-es6/indexes.d.ts +0 -966
  61. package/lib/umd-es6/metrics.d.ts +0 -827
  62. package/lib/umd-es6/persisters.d.ts +0 -727
  63. package/lib/umd-es6/queries.d.ts +0 -3024
  64. package/lib/umd-es6/relationships.d.ts +0 -1201
  65. package/lib/umd-es6/store.d.ts +0 -5244
  66. package/lib/umd-es6/tinybase.d.ts +0 -14
  67. package/lib/umd-es6/tools.d.ts +0 -512
  68. package/lib/umd-es6/ui-react.d.ts +0 -10921
  69. /package/lib/{checkpoints.d.ts → types/checkpoints.d.ts} +0 -0
  70. /package/lib/{cjs-es6 → types}/common.d.ts +0 -0
  71. /package/lib/{cjs-es6 → types}/indexes.d.ts +0 -0
  72. /package/lib/{cjs-es6 → types}/metrics.d.ts +0 -0
  73. /package/lib/{cjs-es6 → types}/persisters.d.ts +0 -0
  74. /package/lib/{cjs-es6 → types}/queries.d.ts +0 -0
  75. /package/lib/{cjs-es6 → types}/relationships.d.ts +0 -0
  76. /package/lib/{cjs-es6 → types}/store.d.ts +0 -0
  77. /package/lib/{cjs-es6 → types}/tinybase.d.ts +0 -0
  78. /package/lib/{cjs-es6 → types}/tools.d.ts +0 -0
  79. /package/lib/{cjs-es6 → types}/ui-react.d.ts +0 -0
@@ -1,966 +0,0 @@
1
- /**
2
- * The indexes module of the TinyBase project provides the ability to create and
3
- * track indexes of the data in Store objects.
4
- *
5
- * The main entry point to this module is the createIndexes function, which
6
- * returns a new Indexes object. From there, you can create new Index
7
- * definitions, access the contents of those Indexes directly, and register
8
- * listeners for when they change.
9
- *
10
- * @packageDocumentation
11
- * @module indexes
12
- */
13
-
14
- import {GetCell, RowCallback, Store} from './store.d';
15
- import {Id, IdOrNull, Ids, SortKey} from './common.d';
16
-
17
- /**
18
- * The Index type represents the concept of a map of Slice objects, keyed by Id.
19
- *
20
- * The Ids in a Slice represent Row objects from a Table that all have a derived
21
- * string value in common, as described by the setIndexDefinition method. Those
22
- * values are used as the key for each Slice in the overall Index object.
23
- *
24
- * Note that the Index type is not actually used in the API, and you instead
25
- * enumerate and access its structure with the getSliceIds method and
26
- * getSliceRowIds method.
27
- *
28
- * @category Concept
29
- */
30
- export type Index = {[sliceId: Id]: Slice};
31
-
32
- /**
33
- * The Slice type represents the concept of a set of Row objects that comprise
34
- * part of an Index.
35
- *
36
- * The Ids in a Slice represent Row objects from a Table that all have a derived
37
- * string value in common, as described by the setIndexDefinition method.
38
- *
39
- * Note that the Slice type is not actually used in the API, and you instead get
40
- * Row Ids directly with the getSliceRowIds method.
41
- *
42
- * @category Concept
43
- */
44
- export type Slice = Ids;
45
-
46
- /**
47
- * The IndexCallback type describes a function that takes an Index's Id and a
48
- * callback to loop over each Slice within it.
49
- *
50
- * A IndexCallback is provided when using the forEachIndex method, so that you
51
- * can do something based on every Index in the Indexes object. See that method
52
- * for specific examples.
53
- *
54
- * @param indexId The Id of the Index that the callback can operate on.
55
- * @param forEachRow A function that will let you iterate over the Slice objects
56
- * in this Index.
57
- * @category Callback
58
- */
59
- export type IndexCallback = (
60
- indexId: Id,
61
- forEachSlice: (sliceCallback: SliceCallback) => void,
62
- ) => void;
63
-
64
- /**
65
- * The SliceCallback type describes a function that takes a Slice's Id and a
66
- * callback to loop over each Row within it.
67
- *
68
- * A SliceCallback is provided when using the forEachSlice method, so that you
69
- * can do something based on every Slice in an Index. See that method for
70
- * specific examples.
71
- *
72
- * @param sliceId The Id of the Slice that the callback can operate on.
73
- * @param forEachRow A function that will let you iterate over the Row objects
74
- * in this Slice.
75
- * @category Callback
76
- */
77
- export type SliceCallback = (
78
- sliceId: Id,
79
- forEachRow: (rowCallback: RowCallback) => void,
80
- ) => void;
81
-
82
- /**
83
- * The SliceIdsListener type describes a function that is used to listen to
84
- * changes to the Slice Ids in an Index.
85
- *
86
- * A SliceIdsListener is provided when using the addSliceIdsListener method. See
87
- * that method for specific examples.
88
- *
89
- * When called, a SliceIdsListener is given a reference to the Indexes object,
90
- * and the Id of the Index that changed.
91
- *
92
- * @param indexes A reference to the Indexes object that changed.
93
- * @param indexId The Id of the Index that changed.
94
- * @category Listener
95
- */
96
- export type SliceIdsListener = (indexes: Indexes, indexId: Id) => void;
97
-
98
- /**
99
- * The SliceRowIdsListener type describes a function that is used to listen to
100
- * changes to the Row Ids in a Slice.
101
- *
102
- * A SliceRowIdsListener is provided when using the addSliceRowIdsListener
103
- * method. See that method for specific examples.
104
- *
105
- * When called, a SliceRowIdsListener is given a reference to the Indexes
106
- * object, the Id of the Index that changed, and the Id of the Slice whose Row
107
- * Ids changed.
108
- *
109
- * @param indexes A reference to the Indexes object that changed.
110
- * @param indexId The Id of the Index that changed.
111
- * @param sliceId The Id of the Slice that changed.
112
- * @category Listener
113
- */
114
- export type SliceRowIdsListener = (
115
- indexes: Indexes,
116
- indexId: Id,
117
- sliceId: Id,
118
- ) => void;
119
-
120
- /**
121
- * The IndexesListenerStats type describes the number of listeners registered
122
- * with the Indexes object, and can be used for debugging purposes.
123
- *
124
- * A IndexesListenerStats object is returned from the getListenerStats method,
125
- * and is only populated in a debug build.
126
- *
127
- * @category Development
128
- */
129
- export type IndexesListenerStats = {
130
- /**
131
- * The number of SlideIdsListener functions registered with the Indexes
132
- * object.
133
- */
134
- sliceIds?: number;
135
- /**
136
- * The number of SliceRowIdsListener functions registered with the Indexes
137
- * object.
138
- */
139
- sliceRowIds?: number;
140
- };
141
-
142
- /**
143
- * An Indexes object lets you look up all the Row objects in a Table that have a
144
- * certain Cell value.
145
- *
146
- * This is useful for creating filtered views of a Table, or simple search
147
- * functionality.
148
- *
149
- * Create an Indexes object easily with the createIndexes function. From there,
150
- * you can add new Index definitions (with the setIndexDefinition method), query
151
- * their contents (with the getSliceIds method and getSliceRowIds method), and
152
- * add listeners for when they change (with the addSliceIdsListener method and
153
- * addSliceRowIdsListener method).
154
- *
155
- * This module defaults to indexing Row objects by one of their Cell values.
156
- * However, far more complex indexes can be configured with a custom function.
157
- *
158
- * @example
159
- * This example shows a very simple lifecycle of an Indexes object: from
160
- * creation, to adding a definition, getting its contents, and then registering
161
- * and removing a listener for it.
162
- *
163
- * ```js
164
- * const store = createStore().setTable('pets', {
165
- * fido: {species: 'dog'},
166
- * felix: {species: 'cat'},
167
- * cujo: {species: 'dog'},
168
- * });
169
- *
170
- * const indexes = createIndexes(store);
171
- * indexes.setIndexDefinition(
172
- * 'bySpecies', // indexId
173
- * 'pets', // tableId to index
174
- * 'species', // cellId to index
175
- * );
176
- *
177
- * console.log(indexes.getSliceIds('bySpecies'));
178
- * // -> ['dog', 'cat']
179
- * console.log(indexes.getSliceRowIds('bySpecies', 'dog'));
180
- * // -> ['fido', 'cujo']
181
- *
182
- * const listenerId = indexes.addSliceIdsListener('bySpecies', () => {
183
- * console.log(indexes.getSliceIds('bySpecies'));
184
- * });
185
- * store.setRow('pets', 'lowly', {species: 'worm'});
186
- * // -> ['dog', 'cat', 'worm']
187
- *
188
- * indexes.delListener(listenerId);
189
- * indexes.destroy();
190
- * ```
191
- * @see Metrics And Indexes guides
192
- * @see Rolling Dice demos
193
- * @see Country demo
194
- * @see Todo App demos
195
- * @see Word Frequencies demo
196
- * @category Indexes
197
- */
198
- export interface Indexes {
199
- /**
200
- * The setIndexDefinition method lets you set the definition of an Index.
201
- *
202
- * Every Index definition is identified by a unique Id, and if you re-use an
203
- * existing Id with this method, the previous definition is overwritten.
204
- *
205
- * An Index is a keyed map of Slice objects, each of which is a list of Row
206
- * Ids from a given Table. Therefore the definition must specify the Table (by
207
- * its Id) to be indexed.
208
- *
209
- * The Ids in a Slice represent Row objects from a Table that all have a
210
- * derived string value in common, as described by this method. Those values
211
- * are used as the key for each Slice in the overall Index object.
212
- *
213
- * Without the third `getSliceIdOrIds` parameter, the Index will simply have a
214
- * single Slice, keyed by an empty string. But more often you will specify a
215
- * Cell value containing the Slice Id that the Row should belong to.
216
- * Alternatively, a custom function can be provided that produces your own
217
- * Slice Id from the local Row as a whole. Since v2.1, the custom function can
218
- * return an array of Slice Ids, each of which the Row will then belong to.
219
- *
220
- * The fourth `getSortKey` parameter specifies a Cell Id to get a value (or a
221
- * function that processes a whole Row to get a value) that is used to sort
222
- * the Row Ids within each Slice in the Index.
223
- *
224
- * The fifth parameter, `sliceIdSorter`, lets you specify a way to sort the
225
- * Slice Ids when you access the Index, which may be useful if you are trying
226
- * to create an alphabetic Index of Row entries. If not specified, the order
227
- * of the Slice Ids will match the order of Row insertion.
228
- *
229
- * The final parameter, `rowIdSorter`, lets you specify a way to sort the Row
230
- * Ids within each Slice, based on the `getSortKey` parameter. This may be
231
- * useful if you are trying to keep Rows in a determined order relative to
232
- * each other in the Index. If omitted, the Row Ids are sorted alphabetically,
233
- * based on the `getSortKey` parameter.
234
- *
235
- * The two 'sorter' parameters, `sliceIdSorter` and `rowIdSorter`, are
236
- * functions that take two values and return a positive or negative number for
237
- * when they are in the wrong or right order, respectively. This is exactly
238
- * the same as the 'compareFunction' that is used in the standard JavaScript
239
- * array `sort` method, with the addition that `rowIdSorter` also takes the
240
- * Slice Id parameter, in case you want to sort Row Ids differently in each
241
- * Slice. You can use the convenient defaultSorter function to default this to
242
- * be alphanumeric.
243
- *
244
- * @param indexId The Id of the Index to define.
245
- * @param tableId The Id of the Table the Index will be generated from.
246
- * @param getSliceIdOrIds Either the Id of the Cell containing, or a function
247
- * that produces, the Id that is used to indicate which Slice in the Index the
248
- * Row Id should be in. Defaults to a function that returns `''` (meaning that
249
- * if this `getSliceIdOrIds` parameter is omitted, the Index will simply
250
- * contain a single Slice containing all the Row Ids in the Table). Since
251
- * v2.1, this can return an array of Slice Ids, each of which the Row will
252
- * then belong to.
253
- * @param getSortKey Either the Id of the Cell containing, or a function that
254
- * produces, the value that is used to sort the Row Ids in each Slice.
255
- * @param sliceIdSorter A function that takes two Slice Id values and returns
256
- * a positive or negative number to indicate how they should be sorted.
257
- * @param rowIdSorter A function that takes two Row Id values (and a slice Id)
258
- * and returns a positive or negative number to indicate how they should be
259
- * sorted.
260
- * @returns A reference to the Indexes object.
261
- * @example
262
- * This example creates a Store, creates an Indexes object, and defines a
263
- * simple Index based on the values in the `species` Cell.
264
- *
265
- * ```js
266
- * const store = createStore().setTable('pets', {
267
- * fido: {species: 'dog'},
268
- * felix: {species: 'cat'},
269
- * cujo: {species: 'dog'},
270
- * });
271
- *
272
- * const indexes = createIndexes(store);
273
- * indexes.setIndexDefinition('bySpecies', 'pets', 'species');
274
- *
275
- * console.log(indexes.getSliceIds('bySpecies'));
276
- * // -> ['dog', 'cat']
277
- * console.log(indexes.getSliceRowIds('bySpecies', 'dog'));
278
- * // -> ['fido', 'cujo']
279
- * ```
280
- * @example
281
- * This example creates a Store, creates an Indexes object, and defines an
282
- * Index based on the first letter of the pets' names.
283
- *
284
- * ```js
285
- * const store = createStore().setTable('pets', {
286
- * fido: {species: 'dog'},
287
- * felix: {species: 'cat'},
288
- * cujo: {species: 'dog'},
289
- * });
290
- *
291
- * const indexes = createIndexes(store);
292
- * indexes.setIndexDefinition('byFirst', 'pets', (_, rowId) => rowId[0]);
293
- *
294
- * console.log(indexes.getSliceIds('byFirst'));
295
- * // -> ['f', 'c']
296
- * console.log(indexes.getSliceRowIds('byFirst', 'f'));
297
- * // -> ['fido', 'felix']
298
- * ```
299
- * @example
300
- * This example creates a Store, creates an Indexes object, and defines an
301
- * Index based on each of the letters present in the pets' names.
302
- *
303
- * ```js
304
- * const store = createStore().setTable('pets', {
305
- * fido: {species: 'dog'},
306
- * felix: {species: 'cat'},
307
- * rex: {species: 'dog'},
308
- * });
309
- *
310
- * const indexes = createIndexes(store);
311
- * indexes.setIndexDefinition('containsLetter', 'pets', (_, rowId) =>
312
- * rowId.split(''),
313
- * );
314
- *
315
- * console.log(indexes.getSliceIds('containsLetter'));
316
- * // -> ['f', 'i', 'd', 'o', 'e', 'l', 'x', 'r']
317
- * console.log(indexes.getSliceRowIds('containsLetter', 'i'));
318
- * // -> ['fido', 'felix']
319
- * console.log(indexes.getSliceRowIds('containsLetter', 'x'));
320
- * // -> ['felix', 'rex']
321
- * ```
322
- * @example
323
- * This example creates a Store, creates an Indexes object, and defines an
324
- * Index based on the first letter of the pets' names. The Slice Ids (and Row
325
- * Ids within them) are alphabetically sorted.
326
- *
327
- * ```js
328
- * const store = createStore().setTable('pets', {
329
- * fido: {species: 'dog'},
330
- * felix: {species: 'cat'},
331
- * cujo: {species: 'dog'},
332
- * });
333
- *
334
- * const indexes = createIndexes(store);
335
- * indexes.setIndexDefinition(
336
- * 'byFirst', // indexId
337
- * 'pets', // tableId
338
- * (_, rowId) => rowId[0], // each Row's sliceId
339
- * (_, rowId) => rowId, // each Row's sort key
340
- * defaultSorter, // sort Slice Ids
341
- * defaultSorter, // sort Row Ids
342
- * );
343
- *
344
- * console.log(indexes.getSliceIds('byFirst'));
345
- * // -> ['c', 'f']
346
- * console.log(indexes.getSliceRowIds('byFirst', 'f'));
347
- * // -> ['felix', 'fido']
348
- * ```
349
- * @category Configuration
350
- */
351
- setIndexDefinition(
352
- indexId: Id,
353
- tableId: Id,
354
- getSliceIdOrIds?: Id | ((getCell: GetCell, rowId: Id) => Id | Ids),
355
- getSortKey?: Id | ((getCell: GetCell, rowId: Id) => SortKey),
356
- sliceIdSorter?: (sliceId1: Id, sliceId2: Id) => number,
357
- rowIdSorter?: (sortKey1: SortKey, sortKey2: SortKey, sliceId: Id) => number,
358
- ): Indexes;
359
-
360
- /**
361
- * The delIndexDefinition method removes an existing Index definition.
362
- *
363
- * @param indexId The Id of the Index to remove.
364
- * @returns A reference to the Indexes object.
365
- * @example
366
- * This example creates a Store, creates an Indexes object, defines a simple
367
- * Index, and then removes it.
368
- *
369
- * ```js
370
- * const store = createStore().setTable('pets', {
371
- * fido: {species: 'dog'},
372
- * felix: {species: 'cat'},
373
- * cujo: {species: 'dog'},
374
- * });
375
- *
376
- * const indexes = createIndexes(store);
377
- * indexes.setIndexDefinition('bySpecies', 'pets', 'species');
378
- * console.log(indexes.getIndexIds());
379
- * // -> ['bySpecies']
380
- *
381
- * indexes.delIndexDefinition('bySpecies');
382
- * console.log(indexes.getIndexIds());
383
- * // -> []
384
- * ```
385
- * @category Configuration
386
- */
387
- delIndexDefinition(indexId: Id): Indexes;
388
-
389
- /**
390
- * The getStore method returns a reference to the underlying Store that is
391
- * backing this Indexes object.
392
- *
393
- * @returns A reference to the Store.
394
- * @example
395
- * This example creates an Indexes object against a newly-created Store and
396
- * then gets its reference in order to update its data.
397
- *
398
- * ```js
399
- * const indexes = createIndexes(createStore());
400
- * indexes.setIndexDefinition('bySpecies', 'pets', 'species');
401
- * indexes.getStore().setCell('pets', 'fido', 'species', 'dog');
402
- * console.log(indexes.getSliceIds('bySpecies'));
403
- * // -> ['dog']
404
- * ```
405
- * @category Getter
406
- */
407
- getStore(): Store;
408
-
409
- /**
410
- * The getIndexIds method returns an array of the Index Ids registered with
411
- * this Indexes object.
412
- *
413
- * @returns An array of Ids.
414
- * @example
415
- * This example creates an Indexes object with two definitions, and then gets
416
- * the Ids of the definitions.
417
- *
418
- * ```js
419
- * const indexes = createIndexes(createStore())
420
- * .setIndexDefinition('bySpecies', 'pets', 'species')
421
- * .setIndexDefinition('byColor', 'pets', 'color');
422
- *
423
- * console.log(indexes.getIndexIds());
424
- * // -> ['bySpecies', 'byColor']
425
- * ```
426
- * @category Getter
427
- */
428
- getIndexIds(): Ids;
429
-
430
- /**
431
- * The forEachIndex method takes a function that it will then call for each
432
- * Index in a specified Indexes object.
433
- *
434
- * This method is useful for iterating over the structure of the Indexes
435
- * object in a functional style. The `indexCallback` parameter is a
436
- * IndexCallback function that will be called with the Id of each Index, and
437
- * with a function that can then be used to iterate over each Slice of the
438
- * Index, should you wish.
439
- *
440
- * @param indexCallback The function that should be called for every Index.
441
- * @example
442
- * This example iterates over each Index in an Indexes object, and lists each
443
- * Slice Id within them.
444
- *
445
- * ```js
446
- * const store = createStore().setTable('pets', {
447
- * fido: {species: 'dog', color: 'brown'},
448
- * felix: {species: 'cat', color: 'black'},
449
- * cujo: {species: 'dog', color: 'black'},
450
- * });
451
- * const indexes = createIndexes(store)
452
- * .setIndexDefinition('bySpecies', 'pets', 'species')
453
- * .setIndexDefinition('byColor', 'pets', 'color');
454
- *
455
- * indexes.forEachIndex((indexId, forEachSlice) => {
456
- * console.log(indexId);
457
- * forEachSlice((sliceId) => console.log(`- ${sliceId}`));
458
- * });
459
- * // -> 'bySpecies'
460
- * // -> '- dog'
461
- * // -> '- cat'
462
- * // -> 'byColor'
463
- * // -> '- brown'
464
- * // -> '- black'
465
- * ```
466
- * @category Iterator
467
- */
468
- forEachIndex(indexCallback: IndexCallback): void;
469
-
470
- /**
471
- * The forEachSlice method takes a function that it will then call for each
472
- * Slice in a specified Index.
473
- *
474
- * This method is useful for iterating over the Slice structure of the Index
475
- * in a functional style. The `rowCallback` parameter is a RowCallback
476
- * function that will be called with the Id and value of each Row in the
477
- * Slice.
478
- *
479
- * @param indexId The Id of the Index to iterate over.
480
- * @param sliceCallback The function that should be called for every Slice.
481
- * @example
482
- * This example iterates over each Row in a Slice, and lists its Id.
483
- *
484
- * ```js
485
- * const store = createStore().setTable('pets', {
486
- * fido: {species: 'dog'},
487
- * felix: {species: 'cat'},
488
- * cujo: {species: 'dog'},
489
- * });
490
- * const indexes = createIndexes(store);
491
- * indexes.setIndexDefinition('bySpecies', 'pets', 'species');
492
- *
493
- * indexes.forEachSlice('bySpecies', (sliceId, forEachRow) => {
494
- * console.log(sliceId);
495
- * forEachRow((rowId) => console.log(`- ${rowId}`));
496
- * });
497
- * // -> 'dog'
498
- * // -> '- fido'
499
- * // -> '- cujo'
500
- * // -> 'cat'
501
- * // -> '- felix'
502
- * ```
503
- * @category Iterator
504
- */
505
- forEachSlice(indexId: Id, sliceCallback: SliceCallback): void;
506
-
507
- /**
508
- * The hasIndex method returns a boolean indicating whether a given Index
509
- * exists in the Indexes object.
510
- *
511
- * @param indexId The Id of a possible Index in the Indexes object.
512
- * @returns Whether an Index with that Id exists.
513
- * @example
514
- * This example shows two simple Index existence checks.
515
- *
516
- * ```js
517
- * const indexes = createIndexes(createStore());
518
- * indexes.setIndexDefinition('bySpecies', 'pets', 'species');
519
- * console.log(indexes.hasIndex('bySpecies'));
520
- * // -> true
521
- * console.log(indexes.hasIndex('byColor'));
522
- * // -> false
523
- * ```
524
- * @category Getter
525
- */
526
- hasIndex(indexId: Id): boolean;
527
-
528
- /**
529
- * The hasSlice method returns a boolean indicating whether a given Slice
530
- * exists in the Indexes object.
531
- *
532
- * @param indexId The Id of a possible Index in the Indexes object.
533
- * @param sliceId The Id of a possible Slice in the Index.
534
- * @returns Whether a Slice with that Id exists.
535
- * @example
536
- * This example shows two simple Index existence checks.
537
- *
538
- * ```js
539
- * const store = createStore().setTable('pets', {
540
- * fido: {species: 'dog'},
541
- * felix: {species: 'cat'},
542
- * cujo: {species: 'dog'},
543
- * });
544
- * const indexes = createIndexes(store);
545
- * indexes.setIndexDefinition('bySpecies', 'pets', 'species');
546
- * console.log(indexes.hasSlice('bySpecies', 'dog'));
547
- * // -> true
548
- * console.log(indexes.hasSlice('bySpecies', 'worm'));
549
- * // -> false
550
- * ```
551
- * @category Getter
552
- */
553
- hasSlice(indexId: Id, sliceId: Id): boolean;
554
-
555
- /**
556
- * The getTableId method returns the Id of the underlying Table that is
557
- * backing an Index.
558
- *
559
- * If the Index Id is invalid, the method returns `undefined`.
560
- *
561
- * @param indexId The Id of an Index.
562
- * @returns The Id of the Table backing the Index, or `undefined`.
563
- * @example
564
- * This example creates an Indexes object, a single Index definition, and then
565
- * queries it (and a non-existent definition) to get the underlying Table Id.
566
- *
567
- * ```js
568
- * const indexes = createIndexes(createStore());
569
- * indexes.setIndexDefinition('bySpecies', 'pets', 'species');
570
- *
571
- * console.log(indexes.getTableId('bySpecies'));
572
- * // -> 'pets'
573
- * console.log(indexes.getTableId('byColor'));
574
- * // -> undefined
575
- * ```
576
- * @category Getter
577
- */
578
- getTableId(indexId: Id): Id;
579
-
580
- /**
581
- * The getSliceIds method gets the list of Slice Ids in an Index.
582
- *
583
- * If the identified Index does not exist (or if the definition references a
584
- * Table that does not exist) then an empty array is returned.
585
- *
586
- * @param indexId The Id of the Index.
587
- * @returns The Slice Ids in the Index, or an empty array.
588
- * @example
589
- * This example creates a Store, creates an Indexes object, and defines a
590
- * simple Index. It then uses getSliceIds to see the available Slice Ids in
591
- * the Index (and also the Slice Ids in an Index that has not been defined).
592
- *
593
- * ```js
594
- * const store = createStore().setTable('pets', {
595
- * fido: {species: 'dog'},
596
- * felix: {species: 'cat'},
597
- * cujo: {species: 'dog'},
598
- * });
599
- *
600
- * const indexes = createIndexes(store);
601
- * indexes.setIndexDefinition('bySpecies', 'pets', 'species');
602
- *
603
- * console.log(indexes.getSliceIds('bySpecies'));
604
- * // -> ['dog', 'cat']
605
- * console.log(indexes.getSliceIds('byColor'));
606
- * // -> []
607
- * ```
608
- * @category Getter
609
- */
610
- getSliceIds(indexId: Id): Ids;
611
-
612
- /**
613
- * The getSliceRowIds method gets the list of Row Ids in a given Slice, within
614
- * a given Index.
615
- *
616
- * If the identified Index or Slice do not exist (or if the definition
617
- * references a Table that does not exist) then an empty array is returned.
618
- *
619
- * @param indexId The Id of the Index.
620
- * @param sliceId The Id of the Slice in the Index.
621
- * @returns The Row Ids in the Slice, or an empty array.
622
- * @example
623
- * This example creates a Store, creates an Indexes object, and defines a
624
- * simple Index. It then uses getSliceRowIds to see the Row Ids in the Slice
625
- * (and also the Row Ids in Slices that do not exist).
626
- *
627
- * ```js
628
- * const store = createStore().setTable('pets', {
629
- * fido: {species: 'dog'},
630
- * felix: {species: 'cat'},
631
- * cujo: {species: 'dog'},
632
- * });
633
- *
634
- * const indexes = createIndexes(store);
635
- * indexes.setIndexDefinition('bySpecies', 'pets', 'species');
636
- *
637
- * console.log(indexes.getSliceRowIds('bySpecies', 'dog'));
638
- * // -> ['fido', 'cujo']
639
- * console.log(indexes.getSliceRowIds('bySpecies', 'worm'));
640
- * // -> []
641
- * console.log(indexes.getSliceRowIds('byColor', 'brown'));
642
- * // -> []
643
- * ```
644
- * @category Getter
645
- */
646
- getSliceRowIds(indexId: Id, sliceId: Id): Ids;
647
-
648
- /**
649
- * The addSliceIdsListener method registers a listener function with the
650
- * Indexes object that will be called whenever the Slice Ids in an Index
651
- * change.
652
- *
653
- * You can either listen to a single Index (by specifying the Index Id as the
654
- * method's first parameter), or changes to any Index (by providing a `null`
655
- * wildcard).
656
- *
657
- * The provided listener is a SliceIdsListener function, and will be called
658
- * with a reference to the Indexes object, and the Id of the Index that
659
- * changed.
660
- *
661
- * @param indexId The Id of the Index to listen to, or `null` as a wildcard.
662
- * @param listener The function that will be called whenever the Slice Ids in
663
- * the Index change.
664
- * @returns A unique Id for the listener that can later be used to remove it.
665
- * @example
666
- * This example creates a Store, an Indexes object, and then registers a
667
- * listener that responds to any changes to a specific Index.
668
- *
669
- * ```js
670
- * const store = createStore().setTable('pets', {
671
- * fido: {species: 'dog'},
672
- * felix: {species: 'cat'},
673
- * cujo: {species: 'dog'},
674
- * });
675
- *
676
- * const indexes = createIndexes(store);
677
- * indexes.setIndexDefinition('bySpecies', 'pets', 'species');
678
- *
679
- * const listenerId = indexes.addSliceIdsListener(
680
- * 'bySpecies',
681
- * (indexes, indexId) => {
682
- * console.log('Slice Ids for bySpecies index changed');
683
- * console.log(indexes.getSliceIds('bySpecies'));
684
- * },
685
- * );
686
- *
687
- * store.setRow('pets', 'lowly', {species: 'worm'});
688
- * // -> 'Slice Ids for bySpecies index changed'
689
- * // -> ['dog', 'cat', 'worm']
690
- *
691
- * indexes.delListener(listenerId);
692
- * ```
693
- * @example
694
- * This example creates a Store, an Indexes object, and then registers a
695
- * listener that responds to any changes to any Index.
696
- *
697
- * ```js
698
- * const store = createStore().setTable('pets', {
699
- * fido: {species: 'dog', color: 'brown'},
700
- * felix: {species: 'cat', color: 'black'},
701
- * cujo: {species: 'dog', color: 'brown'},
702
- * });
703
- *
704
- * const indexes = createIndexes(store)
705
- * .setIndexDefinition('bySpecies', 'pets', 'species')
706
- * .setIndexDefinition('byColor', 'pets', 'color');
707
- *
708
- * const listenerId = indexes.addSliceIdsListener(
709
- * null,
710
- * (indexes, indexId) => {
711
- * console.log(`Slice Ids for ${indexId} index changed`);
712
- * console.log(indexes.getSliceIds(indexId));
713
- * },
714
- * );
715
- *
716
- * store.setRow('pets', 'lowly', {species: 'worm', color: 'pink'});
717
- * // -> 'Slice Ids for bySpecies index changed'
718
- * // -> ['dog', 'cat', 'worm']
719
- * // -> 'Slice Ids for byColor index changed'
720
- * // -> ['brown', 'black', 'pink']
721
- *
722
- * indexes.delListener(listenerId);
723
- * ```
724
- * @category Listener
725
- */
726
- addSliceIdsListener(indexId: IdOrNull, listener: SliceIdsListener): Id;
727
-
728
- /**
729
- * The addSliceRowIdsListener method registers a listener function with the
730
- * Indexes object that will be called whenever the Row Ids in a Slice change.
731
- *
732
- * You can either listen to a single Slice (by specifying the Index Id and
733
- * Slice Id as the method's first two parameters), or changes to any Slice (by
734
- * providing `null` wildcards).
735
- *
736
- * Both, either, or neither of the `indexId` and `sliceId` parameters can be
737
- * wildcarded with `null`. You can listen to a specific Slice in a specific
738
- * Index, any Slice in a specific Index, a specific Slice in any Index, or any
739
- * Slice in any Index.
740
- *
741
- * The provided listener is a SliceRowIdsListener function, and will be called
742
- * with a reference to the Indexes object, the Id of the Index, and the Id of
743
- * the Slice that changed.
744
- *
745
- * @param indexId The Id of the Index to listen to, or `null` as a wildcard.
746
- * @param sliceId The Id of the Slice to listen to, or `null` as a wildcard.
747
- * @param listener The function that will be called whenever the Row Ids in
748
- * the Slice change.
749
- * @returns A unique Id for the listener that can later be used to remove it.
750
- * @example
751
- * This example creates a Store, an Indexes object, and then registers a
752
- * listener that responds to any changes to a specific Slice.
753
- *
754
- * ```js
755
- * const store = createStore().setTable('pets', {
756
- * fido: {species: 'dog'},
757
- * felix: {species: 'cat'},
758
- * cujo: {species: 'dog'},
759
- * });
760
- *
761
- * const indexes = createIndexes(store);
762
- * indexes.setIndexDefinition('bySpecies', 'pets', 'species');
763
- *
764
- * const listenerId = indexes.addSliceRowIdsListener(
765
- * 'bySpecies',
766
- * 'dog',
767
- * (indexes, indexId, sliceId) => {
768
- * console.log('Row Ids for dog slice in bySpecies index changed');
769
- * console.log(indexes.getSliceRowIds('bySpecies', 'dog'));
770
- * },
771
- * );
772
- *
773
- * store.setRow('pets', 'toto', {species: 'dog'});
774
- * // -> 'Row Ids for dog slice in bySpecies index changed'
775
- * // -> ['fido', 'cujo', 'toto']
776
- *
777
- * indexes.delListener(listenerId);
778
- * ```
779
- * @example
780
- * This example creates a Store, an Indexes object, and then registers a
781
- * listener that responds to any changes to any Slice.
782
- *
783
- * ```js
784
- * const store = createStore().setTable('pets', {
785
- * fido: {species: 'dog', color: 'brown'},
786
- * felix: {species: 'cat', color: 'black'},
787
- * cujo: {species: 'dog', color: 'black'},
788
- * });
789
- *
790
- * const indexes = createIndexes(store)
791
- * .setIndexDefinition('bySpecies', 'pets', 'species')
792
- * .setIndexDefinition('byColor', 'pets', 'color');
793
- *
794
- * const listenerId = indexes.addSliceRowIdsListener(
795
- * null,
796
- * null,
797
- * (indexes, indexId, sliceId) => {
798
- * console.log(
799
- * `Row Ids for ${sliceId} slice in ${indexId} index changed`,
800
- * );
801
- * console.log(indexes.getSliceRowIds(indexId, sliceId));
802
- * },
803
- * );
804
- *
805
- * store.setRow('pets', 'toto', {species: 'dog', color: 'brown'});
806
- * // -> 'Row Ids for dog slice in bySpecies index changed'
807
- * // -> ['fido', 'cujo', 'toto']
808
- * // -> 'Row Ids for brown slice in byColor index changed'
809
- * // -> ['fido', 'toto']
810
- *
811
- * indexes.delListener(listenerId);
812
- * ```
813
- * @category Listener
814
- */
815
- addSliceRowIdsListener(
816
- indexId: IdOrNull,
817
- sliceId: IdOrNull,
818
- listener: SliceRowIdsListener,
819
- ): Id;
820
-
821
- /**
822
- * The delListener method removes a listener that was previously added to the
823
- * Indexes object.
824
- *
825
- * Use the Id returned by whichever method was used to add the listener. Note
826
- * that the Indexes object may re-use this Id for future listeners added to
827
- * it.
828
- *
829
- * @param listenerId The Id of the listener to remove.
830
- * @returns A reference to the Indexes object.
831
- * @example
832
- * This example creates a Store, an Indexes object, registers a listener, and
833
- * then removes it.
834
- *
835
- * ```js
836
- * const store = createStore().setTable('pets', {
837
- * fido: {species: 'dog'},
838
- * felix: {species: 'cat'},
839
- * cujo: {species: 'dog'},
840
- * });
841
- *
842
- * const indexes = createIndexes(store);
843
- * indexes.setIndexDefinition('bySpecies', 'pets', 'species');
844
- *
845
- * const listenerId = indexes.addSliceIdsListener(
846
- * 'bySpecies',
847
- * (indexes, indexId) => {
848
- * console.log('Slice Ids for bySpecies index changed');
849
- * },
850
- * );
851
- *
852
- * store.setRow('pets', 'lowly', {species: 'worm'});
853
- * // -> 'Slice Ids for bySpecies index changed'
854
- *
855
- * indexes.delListener(listenerId);
856
- *
857
- * store.setRow('pets', 'toto', {species: 'dog'});
858
- * // -> undefined
859
- * // The listener is not called.
860
- * ```
861
- * @category Listener
862
- */
863
- delListener(listenerId: Id): Indexes;
864
-
865
- /**
866
- * The destroy method should be called when this Indexes object is no longer
867
- * used.
868
- *
869
- * This guarantees that all of the listeners that the object registered with
870
- * the underlying Store are removed and it can be correctly garbage collected.
871
- *
872
- * @example
873
- * This example creates a Store, adds an Indexes object with a
874
- * definition (that registers a RowListener with the underlying Store),
875
- * and then destroys it again, removing the listener.
876
- *
877
- * ```js
878
- * const store = createStore().setTable('pets', {
879
- * fido: {species: 'dog'},
880
- * felix: {species: 'cat'},
881
- * cujo: {species: 'dog'},
882
- * });
883
- *
884
- * const indexes = createIndexes(store);
885
- * indexes.setIndexDefinition('bySpecies', 'pets', 'species');
886
- * console.log(store.getListenerStats().row);
887
- * // -> 1
888
- *
889
- * indexes.destroy();
890
- *
891
- * console.log(store.getListenerStats().row);
892
- * // -> 0
893
- * ```
894
- * @category Lifecycle
895
- */
896
- destroy(): void;
897
-
898
- /**
899
- * The getListenerStats method provides a set of statistics about the
900
- * listeners registered with the Indexes object, and is used for debugging
901
- * purposes.
902
- *
903
- * The IndexesListenerStats object contains a breakdown of the different types
904
- * of listener.
905
- *
906
- * The statistics are only populated in a debug build: production builds
907
- * return an empty object. The method is intended to be used during
908
- * development to ensure your application is not leaking listener
909
- * registrations, for example.
910
- *
911
- * @returns A IndexesListenerStats object containing Indexes listener
912
- * statistics.
913
- * @example
914
- * This example gets the listener statistics of an Indexes object.
915
- *
916
- * ```js
917
- * const store = createStore();
918
- * const indexes = createIndexes(store);
919
- * indexes.addSliceIdsListener(null, () => {
920
- * console.log('Slice Ids changed');
921
- * });
922
- * indexes.addSliceRowIdsListener(null, null, () => {
923
- * console.log('Slice Row Ids changed');
924
- * });
925
- *
926
- * console.log(indexes.getListenerStats());
927
- * // -> {sliceIds: 1, sliceRowIds: 1}
928
- * ```
929
- * @category Development
930
- */
931
- getListenerStats(): IndexesListenerStats;
932
- }
933
-
934
- /**
935
- * The createIndexes function creates an Indexes object, and is the main entry
936
- * point into the indexes module.
937
- *
938
- * A given Store can only have one Indexes object associated with it. If you
939
- * call this function twice on the same Store, your second call will return a
940
- * reference to the Indexes object created by the first.
941
- *
942
- * @param store The Store for which to register Index definitions.
943
- * @returns A reference to the new Indexes object.
944
- * @example
945
- * This example creates an Indexes object.
946
- *
947
- * ```js
948
- * const store = createStore();
949
- * const indexes = createIndexes(store);
950
- * console.log(indexes.getIndexIds());
951
- * // -> []
952
- * ```
953
- * @example
954
- * This example creates an Indexes object, and calls the method a second time
955
- * for the same Store to return the same object.
956
- *
957
- * ```js
958
- * const store = createStore();
959
- * const indexes1 = createIndexes(store);
960
- * const indexes2 = createIndexes(store);
961
- * console.log(indexes1 === indexes2);
962
- * // -> true
963
- * ```
964
- * @category Creation
965
- */
966
- export function createIndexes(store: Store): Indexes;