tinybase 1.0.2 → 1.1.0-beta.0

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 (60) hide show
  1. package/lib/checkpoints.d.ts +945 -0
  2. package/lib/checkpoints.js +1 -0
  3. package/lib/checkpoints.js.gz +0 -0
  4. package/lib/common.d.ts +115 -0
  5. package/lib/common.js +1 -0
  6. package/lib/common.js.gz +0 -0
  7. package/lib/debug/checkpoints.d.ts +66 -0
  8. package/lib/debug/checkpoints.js +332 -0
  9. package/lib/debug/common.js +3 -0
  10. package/lib/debug/indexes.d.ts +167 -6
  11. package/lib/debug/indexes.js +431 -0
  12. package/lib/debug/metrics.d.ts +72 -0
  13. package/lib/debug/metrics.js +401 -0
  14. package/lib/debug/persisters.js +191 -0
  15. package/lib/debug/relationships.d.ts +86 -1
  16. package/lib/debug/relationships.js +434 -0
  17. package/lib/debug/store.d.ts +187 -5
  18. package/lib/debug/store.js +783 -0
  19. package/lib/debug/tinybase.js +144 -39
  20. package/lib/indexes.d.ts +939 -0
  21. package/lib/indexes.js +1 -0
  22. package/lib/indexes.js.gz +0 -0
  23. package/lib/metrics.d.ts +829 -0
  24. package/lib/metrics.js +1 -0
  25. package/lib/metrics.js.gz +0 -0
  26. package/lib/persisters.d.ts +711 -0
  27. package/lib/persisters.js +1 -0
  28. package/lib/persisters.js.gz +0 -0
  29. package/lib/relationships.d.ts +1201 -0
  30. package/lib/relationships.js +1 -0
  31. package/lib/relationships.js.gz +0 -0
  32. package/lib/store.d.ts +2688 -0
  33. package/lib/store.js +1 -0
  34. package/lib/store.js.gz +0 -0
  35. package/lib/tinybase.d.ts +13 -0
  36. package/lib/tinybase.js +1 -0
  37. package/lib/tinybase.js.gz +0 -0
  38. package/lib/ui-react.d.ts +7185 -0
  39. package/lib/ui-react.js +1 -0
  40. package/lib/ui-react.js.gz +0 -0
  41. package/lib/umd/checkpoints.js +1 -0
  42. package/lib/umd/checkpoints.js.gz +0 -0
  43. package/lib/umd/common.js +1 -0
  44. package/lib/umd/common.js.gz +0 -0
  45. package/lib/umd/indexes.js +1 -0
  46. package/lib/umd/indexes.js.gz +0 -0
  47. package/lib/umd/metrics.js +1 -0
  48. package/lib/umd/metrics.js.gz +0 -0
  49. package/lib/umd/persisters.js +1 -0
  50. package/lib/umd/persisters.js.gz +0 -0
  51. package/lib/umd/relationships.js +1 -0
  52. package/lib/umd/relationships.js.gz +0 -0
  53. package/lib/umd/store.js +1 -0
  54. package/lib/umd/store.js.gz +0 -0
  55. package/lib/umd/tinybase.js +1 -0
  56. package/lib/umd/tinybase.js.gz +0 -0
  57. package/lib/umd/ui-react.js +1 -0
  58. package/lib/umd/ui-react.js.gz +0 -0
  59. package/package.json +14 -14
  60. package/readme.md +2 -2
@@ -0,0 +1,1201 @@
1
+ /**
2
+ * The relationships module of the TinyBase project provides the ability to
3
+ * create and track relationships between the data in Store objects.
4
+ *
5
+ * The main entry point to this module is the createRelationships function,
6
+ * which returns a new Relationships object. From there, you can create new
7
+ * Relationship definitions, access the associations within those Relationships
8
+ * directly, and register listeners for when they change.
9
+ *
10
+ * @packageDocumentation
11
+ * @module relationships
12
+ */
13
+
14
+ import {GetCell, RowCallback, Store} from './store.d';
15
+ import {Id, IdOrNull, Ids} from './common.d';
16
+
17
+ /**
18
+ * The Relationship type represents the concept of a map that connects one Row
19
+ * object to another, often in another Table.
20
+ *
21
+ * The Relationship has a one-to-many nature. One local Row Id is linked to one
22
+ * remote Row Id (in the remote Table), as described by the
23
+ * setRelationshipDefinition method - and one remote Row Id may map back to
24
+ * multiple local Row Ids (in the local Table).
25
+ *
26
+ * A Relationship where the local Table is the same as the remote Table can be
27
+ * used to model a 'linked list', where Row A references Row B, Row B references
28
+ * Row C, and so on.
29
+ *
30
+ * Note that the Relationship type is not actually used in the API, and you
31
+ * instead enumerate and access its structure with the getRemoteRowId method,
32
+ * the getLocalRowIds method, and the getLinkedRowIds method.
33
+ *
34
+ * @category Concept
35
+ */
36
+ export type Relationship = {
37
+ remoteRowId: {[localRowId: Id]: Id};
38
+ localRowIds: {[remoteRowId: Id]: Ids};
39
+ linkedRowIds: {[firstRowId: Id]: Ids};
40
+ };
41
+
42
+ /**
43
+ * The RelationshipCallback type describes a function that takes a
44
+ * Relationship's Id and a callback to loop over each local Row within it.
45
+ *
46
+ * A RelationshipCallback is provided when using the forEachRelationship method,
47
+ * so that you can do something based on every Relationship in the Relationships
48
+ * object. See that method for specific examples.
49
+ *
50
+ * @param relationshipId The Id of the Relationship that the callback can
51
+ * operate on.
52
+ * @param forEachRow A function that will let you iterate over the local Row
53
+ * objects in this Relationship.
54
+ * @category Callback
55
+ */
56
+ export type RelationshipCallback = (
57
+ relationshipId: Id,
58
+ forEachRow: (rowCallback: RowCallback) => void,
59
+ ) => void;
60
+
61
+ /**
62
+ * The RemoteRowIdListener type describes a function that is used to listen to
63
+ * changes to the remote Row Id end of a Relationship.
64
+ *
65
+ * A RemoteRowIdListener is provided when using the addRemoteRowIdListener
66
+ * method. See that method for specific examples.
67
+ *
68
+ * When called, a RemoteRowIdListener is given a reference to the Relationships
69
+ * object, the Id of the Relationship that changed, and the Id of the local Row
70
+ * whose remote Row Id changed.
71
+ *
72
+ * @param relationships A reference to the Relationships object that changed.
73
+ * @param relationshipId The Id of the Relationship that changed.
74
+ * @param localRowId The Id of the local Row whose remote Row Id changed.
75
+ * @category Listener
76
+ */
77
+ export type RemoteRowIdListener = (
78
+ relationships: Relationships,
79
+ relationshipId: Id,
80
+ localRowId: Id,
81
+ ) => void;
82
+
83
+ /**
84
+ * The LocalRowIdsListener type describes a function that is used to listen to
85
+ * changes to the local Row Id ends of a Relationship.
86
+ *
87
+ * A LocalRowIdsListener is provided when using the addLocalRowIdsListener
88
+ * method. See that method for specific examples.
89
+ *
90
+ * When called, a LocalRowIdsListener is given a reference to the Relationships
91
+ * object, the Id of the Relationship that changed, and the Id of the remote Row
92
+ * whose local Row Ids changed.
93
+ *
94
+ * @param relationships A reference to the Relationships object that changed.
95
+ * @param relationshipId The Id of the Relationship that changed.
96
+ * @param remoteRowId The Id of the remote Row whose local Row Ids changed.
97
+ * @category Listener
98
+ */
99
+ export type LocalRowIdsListener = (
100
+ relationships: Relationships,
101
+ relationshipId: Id,
102
+ remoteRowId: Id,
103
+ ) => void;
104
+
105
+ /**
106
+ * The LinkedRowIdsListener type describes a function that is used to listen to
107
+ * changes to the local Row Id ends of a Relationship.
108
+ *
109
+ * A LinkedRowIdsListener is provided when using the addLinkedRowIdsListener
110
+ * method. See that method for specific examples.
111
+ *
112
+ * When called, a LinkedRowIdsListener is given a reference to the Relationships
113
+ * object, the Id of the Relationship that changed, and the Id of the first Row
114
+ * of the the linked list whose members changed.
115
+ *
116
+ * @param relationships A reference to the Relationships object that changed.
117
+ * @param relationshipId The Id of the Relationship that changed.
118
+ * @param firstRowId The Id of the first Row of the the linked list whose
119
+ * members changed.
120
+ * @category Listener
121
+ */
122
+ export type LinkedRowIdsListener = (
123
+ relationships: Relationships,
124
+ relationshipId: Id,
125
+ firstRowId: Id,
126
+ ) => void;
127
+
128
+ /**
129
+ * The RelationshipsListenerStats type describes the number of listeners
130
+ * registered with the Relationships object, and can be used for debugging
131
+ * purposes.
132
+ *
133
+ * A RelationshipsListenerStats object is returned from the getListenerStats
134
+ * method, and is only populated in a debug build.
135
+ *
136
+ * @category Development
137
+ */
138
+ export type RelationshipsListenerStats = {
139
+ /**
140
+ * The number of RemoteRowIdListeners registered with the Relationships
141
+ * object.
142
+ */
143
+ remoteRowId?: number;
144
+ /**
145
+ * The number of LocalRowIdsListeners registered with the Relationships
146
+ * object.
147
+ */
148
+ localRowIds?: number;
149
+ /**
150
+ * The number of LinkedRowIds registered with the Relationships object.
151
+ */
152
+ linkedRowIds?: number;
153
+ };
154
+
155
+ /**
156
+ * A Relationships object lets you associate a Row in a one Table with the Id of
157
+ * a Row in another Table.
158
+ *
159
+ * This is useful for creating parent-child relationships between the data in
160
+ * different Table objects, but it can also be used to model a linked list of
161
+ * Row objects in the same Table.
162
+ *
163
+ * Create a Relationships object easily with the createRelationships function.
164
+ * From there, you can add new Relationship definitions (with the
165
+ * setRelationshipDefinition method), query their contents (with the
166
+ * getRemoteRowId method, the getLocalRowIds method, and the getLinkedRowIds
167
+ * method), and add listeners for when they change (with the
168
+ * addRemoteRowIdListener method, the addLocalRowIdsListener method, and the
169
+ * addLinkedRowIdsListener method).
170
+ *
171
+ * This module defaults to creating relationships between Row objects by using
172
+ * one of their Cell values. However, far more complex relationships can be
173
+ * configured with a custom function.
174
+ *
175
+ * @example
176
+ * This example shows a very simple lifecycle of a Relationships object: from
177
+ * creation, to adding definitions (both local/remote table and linked list),
178
+ * getting their contents, and then registering and removing listeners for them.
179
+ *
180
+ * ```js
181
+ * const store = createStore()
182
+ * .setTable('pets', {
183
+ * fido: {species: 'dog', next: 'felix'},
184
+ * felix: {species: 'cat', next: 'cujo'},
185
+ * cujo: {species: 'dog'},
186
+ * })
187
+ * .setTable('species', {
188
+ * dog: {price: 5},
189
+ * cat: {price: 4},
190
+ * });
191
+ *
192
+ * const relationships = createRelationships(store);
193
+ * // A local/remote table relationship:
194
+ * relationships.setRelationshipDefinition(
195
+ * 'petSpecies', // relationshipId
196
+ * 'pets', // localTableId to link from
197
+ * 'species', // remoteTableId to link to
198
+ * 'species', // cellId containing remote key
199
+ * );
200
+ * // A linked list relationship:
201
+ * relationships.setRelationshipDefinition(
202
+ * 'petSequence', // relationshipId
203
+ * 'pets', // localTableId to link from
204
+ * 'pets', // the same remoteTableId to link within
205
+ * 'next', // cellId containing link key
206
+ * );
207
+ *
208
+ * console.log(relationships.getRemoteRowId('petSpecies', 'fido'));
209
+ * // -> 'dog'
210
+ * console.log(relationships.getLocalRowIds('petSpecies', 'dog'));
211
+ * // -> ['fido', 'cujo']
212
+ * console.log(relationships.getLinkedRowIds('petSequence', 'fido'));
213
+ * // -> ['fido', 'felix', 'cujo']
214
+ *
215
+ * const listenerId1 = relationships.addLocalRowIdsListener(
216
+ * 'petSpecies',
217
+ * 'dog',
218
+ * () => {
219
+ * console.log('petSpecies relationship (to dog) changed');
220
+ * console.log(relationships.getLocalRowIds('petSpecies', 'dog'));
221
+ * },
222
+ * );
223
+ * const listenerId2 = relationships.addLinkedRowIdsListener(
224
+ * 'petSequence',
225
+ * 'fido',
226
+ * () => {
227
+ * console.log('petSequence linked list (from fido) changed');
228
+ * console.log(relationships.getLinkedRowIds('petSequence', 'fido'));
229
+ * },
230
+ * );
231
+ *
232
+ * store.setRow('pets', 'toto', {species: 'dog'});
233
+ * // -> 'petSpecies relationship (to dog) changed'
234
+ * // -> ['fido', 'cujo', 'toto']
235
+ *
236
+ * store.setCell('pets', 'cujo', 'next', 'toto');
237
+ * // -> 'petSequence linked list (from fido) changed'
238
+ * // -> ['fido', 'felix', 'cujo', 'toto']
239
+ *
240
+ * relationships.delListener(listenerId1);
241
+ * relationships.delListener(listenerId2);
242
+ * relationships.destroy();
243
+ * ```
244
+ * @see Relationships And Checkpoints guides
245
+ * @see TinyDraw demo
246
+ * @category Relationships
247
+ */
248
+ export interface Relationships {
249
+ /**
250
+ * The setRelationshipDefinition method lets you set the definition of a
251
+ * Relationship.
252
+ *
253
+ * Every Relationship definition is identified by a unique Id, and if you
254
+ * re-use an existing Id with this method, the previous definition is
255
+ * overwritten.
256
+ *
257
+ * An Relationship is based on connections between Row objects, often in two
258
+ * different Table objects. Therefore the definition requires the
259
+ * `localTableId` parameter to specify the 'local' Table to create the
260
+ * Relationship from, and the `remoteTableId` parameter to specify the
261
+ * 'remote' Table to create Relationship to.
262
+ *
263
+ * A linked list Relationship is one that has the same Table specified as both
264
+ * local Table Id and remote Table Id, allowing you to create a sequence of
265
+ * Row objects within that one Table.
266
+ *
267
+ * A local Row is related to a remote Row by specifying which of its (local)
268
+ * Cell values contains the (remote) Row Id, using the `getRemoteRowId`
269
+ * parameter. Alternatively, a custom function can be provided that produces
270
+ * your own remote Row Id from the local Row as a whole.
271
+ *
272
+ * @param relationshipId The Id of the Relationship to define.
273
+ * @param localTableId The Id of the local Table for the Relationship.
274
+ * @param remoteTableId The Id of the remote Table for the Relationship (or
275
+ * the same as the `localTableId` in the case of a linked list).
276
+ * @param getRemoteRowId Either the Id of the Cell containing, or a function
277
+ * that produces, the Id that is used to indicate which Row in the remote
278
+ * Table a local Row is related to.
279
+ * @returns A reference to the Relationships object.
280
+ * @example
281
+ * This example creates a Store, creates a Relationships object, and defines
282
+ * a simple Relationship based on the values in the `species` Cell of the
283
+ * `pets` Table that relates a Row to another in the `species` Table.
284
+ *
285
+ * ```js
286
+ * const store = createStore()
287
+ * .setTable('pets', {
288
+ * fido: {species: 'dog'},
289
+ * felix: {species: 'cat'},
290
+ * cujo: {species: 'dog'},
291
+ * })
292
+ * .setTable('species', {
293
+ * dog: {price: 5},
294
+ * cat: {price: 4},
295
+ * });
296
+ *
297
+ * const relationships = createRelationships(store);
298
+ * relationships.setRelationshipDefinition(
299
+ * 'petSpecies', // relationshipId
300
+ * 'pets', // localTableId to link from
301
+ * 'species', // remoteTableId to link to
302
+ * 'species', // cellId containing remote key
303
+ * );
304
+ *
305
+ * console.log(relationships.getRemoteRowId('petSpecies', 'fido'));
306
+ * // -> 'dog'
307
+ * console.log(relationships.getLocalRowIds('petSpecies', 'dog'));
308
+ * // -> ['fido', 'cujo']
309
+ * ```
310
+ * @example
311
+ * This example creates a Store, creates a Relationships object, and defines
312
+ * a linked list Relationship based on the values in the `next` Cell of the
313
+ * `pets` Table that relates a Row to another in the same Table.
314
+ *
315
+ * ```js
316
+ * const store = createStore().setTable('pets', {
317
+ * fido: {species: 'dog', next: 'felix'},
318
+ * felix: {species: 'cat', next: 'cujo'},
319
+ * cujo: {species: 'dog'},
320
+ * });
321
+ *
322
+ * const relationships = createRelationships(store);
323
+ * relationships.setRelationshipDefinition(
324
+ * 'petSequence', // relationshipId
325
+ * 'pets', // localTableId to link from
326
+ * 'pets', // the same remoteTableId to link within
327
+ * 'next', // cellId containing link key
328
+ * );
329
+ *
330
+ * console.log(relationships.getLinkedRowIds('petSequence', 'fido'));
331
+ * // -> ['fido', 'felix', 'cujo']
332
+ * ```
333
+ * @category Configuration
334
+ */
335
+ setRelationshipDefinition(
336
+ relationshipId: Id,
337
+ localTableId: Id,
338
+ remoteTableId: Id,
339
+ getRemoteRowId: Id | ((getCell: GetCell, localRowId: Id) => Id),
340
+ ): Relationships;
341
+
342
+ /**
343
+ * The delRelationshipDefinition method removes an existing Relationship
344
+ * definition.
345
+ *
346
+ * @param relationshipId The Id of the Relationship to remove.
347
+ * @returns A reference to the Relationships object.
348
+ * @example
349
+ * This example creates a Store, creates a Relationships object, defines a
350
+ * simple Relationship, and then removes it.
351
+ *
352
+ * ```js
353
+ * const store = createStore()
354
+ * .setTable('pets', {
355
+ * fido: {species: 'dog'},
356
+ * felix: {species: 'cat'},
357
+ * cujo: {species: 'dog'},
358
+ * })
359
+ * .setTable('species', {
360
+ * dog: {price: 5},
361
+ * cat: {price: 4},
362
+ * });
363
+ *
364
+ * const relationships = createRelationships(store);
365
+ * relationships.setRelationshipDefinition(
366
+ * 'petSpecies',
367
+ * 'pets',
368
+ * 'species',
369
+ * 'species',
370
+ * );
371
+ * console.log(relationships.getRelationshipIds());
372
+ * // -> ['petSpecies']
373
+ *
374
+ * relationships.delRelationshipDefinition('petSpecies');
375
+ * console.log(relationships.getRelationshipIds());
376
+ * // -> []
377
+ * ```
378
+ * @category Configuration
379
+ */
380
+ delRelationshipDefinition(relationshipId: Id): Relationships;
381
+
382
+ /**
383
+ * The getStore method returns a reference to the underlying Store that is
384
+ * backing this Relationships object.
385
+ *
386
+ * @returns A reference to the Store.
387
+ * @example
388
+ * This example creates a Relationships object against a newly-created Store
389
+ * and then gets its reference in order to update its data.
390
+ *
391
+ * ```js
392
+ * const relationships = createRelationships(createStore());
393
+ * relationships.setRelationshipDefinition(
394
+ * 'petSpecies',
395
+ * 'pets',
396
+ * 'species',
397
+ * 'species',
398
+ * );
399
+ * relationships.getStore().setCell('pets', 'fido', 'species', 'dog');
400
+ * console.log(relationships.getRemoteRowId('petSpecies', 'fido'));
401
+ * // -> 'dog'
402
+ * ```
403
+ * @category Getter
404
+ */
405
+ getStore(): Store;
406
+
407
+ /**
408
+ * The getRelationshipIds method returns an array of the Relationship Ids
409
+ * registered with this Relationships object.
410
+ *
411
+ * @returns An array of Ids.
412
+ * @example
413
+ * This example creates a Relationships object with two definitions, and then
414
+ * gets the Ids of the definitions.
415
+ *
416
+ * ```js
417
+ * const relationships = createRelationships(createStore())
418
+ * .setRelationshipDefinition('petSpecies', 'pets', 'species', 'species')
419
+ * .setRelationshipDefinition('petSequence', 'pets', 'pets', 'next');
420
+ * console.log(relationships.getRelationshipIds());
421
+ * // -> ['petSpecies', 'petSequence']
422
+ * ```
423
+ * @category Getter
424
+ */
425
+ getRelationshipIds(): Ids;
426
+
427
+ /**
428
+ * The forEachRelationship method takes a function that it will then call for
429
+ * each Relationship in a specified Relationships object.
430
+ *
431
+ * This method is useful for iterating over the structure of the Relationships
432
+ * object in a functional style. The `relationshipCallback` parameter is a
433
+ * RelationshipCallback function that will be called with the Id of each
434
+ * Relationship, and with a function that can then be used to iterate over
435
+ * each local Row involved in the Relationship.
436
+ *
437
+ * @param relationshipCallback The function that should be called for every
438
+ * Relationship.
439
+ * @example
440
+ * This example iterates over each Relationship in a Relationships object, and
441
+ * lists each Row Id within them.
442
+ *
443
+ * ```js
444
+ * const store = createStore().setTable('pets', {
445
+ * fido: {species: 'dog', next: 'felix'},
446
+ * felix: {species: 'cat', next: 'cujo'},
447
+ * cujo: {species: 'dog'},
448
+ * });
449
+ * const relationships = createRelationships(store)
450
+ * .setRelationshipDefinition('petSpecies', 'pets', 'species', 'species')
451
+ * .setRelationshipDefinition('petSequence', 'pets', 'pets', 'next');
452
+ *
453
+ * relationships.forEachRelationship((relationshipId, forEachRow) => {
454
+ * console.log(relationshipId);
455
+ * forEachRow((rowId) => console.log(`- ${rowId}`));
456
+ * });
457
+ * // -> 'petSpecies'
458
+ * // -> '- fido'
459
+ * // -> '- felix'
460
+ * // -> '- cujo'
461
+ * // -> 'petSequence'
462
+ * // -> '- fido'
463
+ * // -> '- felix'
464
+ * // -> '- cujo'
465
+ * ```
466
+ * @category Iterator
467
+ */
468
+ forEachRelationship(relationshipCallback: RelationshipCallback): void;
469
+
470
+ /**
471
+ * The hasRelationship method returns a boolean indicating whether a given
472
+ * Relationship exists in the Relationships object.
473
+ *
474
+ * @param relationshipId The Id of a possible Relationship in the
475
+ * Relationships object.
476
+ * @returns Whether a Relationship with that Id exists.
477
+ * @example
478
+ * This example shows two simple Relationship existence checks.
479
+ *
480
+ * ```js
481
+ * const relationships = createRelationships(
482
+ * createStore(),
483
+ * ).setRelationshipDefinition('petSpecies', 'pets', 'species', 'species');
484
+ * console.log(relationships.hasRelationship('petSpecies'));
485
+ * // -> true
486
+ * console.log(relationships.hasRelationship('petColor'));
487
+ * // -> false
488
+ * ```
489
+ * @category Getter
490
+ */
491
+ hasRelationship(indexId: Id): boolean;
492
+
493
+ /**
494
+ * The getLocalTableId method returns the Id of the underlying local Table
495
+ * that is used in the Relationship.
496
+ *
497
+ * If the Relationship Id is invalid, the method returns `undefined`.
498
+ *
499
+ * @param relationshipId The Id of a Relationship.
500
+ * @returns The Id of the local Table backing the Relationship, or
501
+ * `undefined`.
502
+ * @example
503
+ * This example creates a Relationship object, a single Relationship
504
+ * definition, and then queries it (and a non-existent definition) to get the
505
+ * underlying local Table Id.
506
+ *
507
+ * ```js
508
+ * const relationships = createRelationships(createStore());
509
+ * relationships.setRelationshipDefinition(
510
+ * 'petSpecies',
511
+ * 'pets',
512
+ * 'species',
513
+ * 'species',
514
+ * );
515
+ *
516
+ * console.log(relationships.getLocalTableId('petSpecies'));
517
+ * // -> 'pets'
518
+ * console.log(relationships.getLocalTableId('petColor'));
519
+ * // -> undefined
520
+ * ```
521
+ * @category Getter
522
+ */
523
+ getLocalTableId(relationshipId: Id): Id;
524
+
525
+ /**
526
+ * The getRemoteTableId method returns the Id of the underlying remote Table
527
+ * that is used in the Relationship.
528
+ *
529
+ * If the Relationship Id is invalid, the method returns `undefined`.
530
+ *
531
+ * @param relationshipId The Id of a Relationship.
532
+ * @returns The Id of the remote Table backing the Relationship, or
533
+ * `undefined`.
534
+ * @example
535
+ * This example creates a Relationship object, a single Relationship
536
+ * definition, and then queries it (and a non-existent definition) to get the
537
+ * underlying remote Table Id.
538
+ *
539
+ * ```js
540
+ * const relationships = createRelationships(createStore());
541
+ * relationships.setRelationshipDefinition(
542
+ * 'petSpecies',
543
+ * 'pets',
544
+ * 'species',
545
+ * 'species',
546
+ * );
547
+ *
548
+ * console.log(relationships.getRemoteTableId('petSpecies'));
549
+ * // -> 'species'
550
+ * console.log(relationships.getRemoteTableId('petColor'));
551
+ * // -> undefined
552
+ * ```
553
+ * @category Getter
554
+ */
555
+ getRemoteTableId(relationshipId: Id): Id;
556
+
557
+ /**
558
+ * The getRemoteRowId method gets the remote Row Id for a given local Row in a
559
+ * Relationship.
560
+ *
561
+ * If the identified Relationship or Row does not exist (or if the definition
562
+ * references a Table that does not exist) then `undefined` is returned.
563
+ *
564
+ * @param relationshipId The Id of the Relationship.
565
+ * @param localRowId The Id of the local Row in the Relationship.
566
+ * @returns The remote Row Id in the Relationship, or `undefined`.
567
+ * @example
568
+ * This example creates a Store, creates a Relationships object, and defines
569
+ * a simple Relationship. It then uses getRemoteRowId to see the remote Row Id
570
+ * in the Relationship (and also the remote Row Ids for a local Row that does
571
+ * not exist, and for a Relationship that has not been defined).
572
+ *
573
+ * ```js
574
+ * const store = createStore()
575
+ * .setTable('pets', {
576
+ * fido: {species: 'dog'},
577
+ * felix: {species: 'cat'},
578
+ * cujo: {species: 'dog'},
579
+ * })
580
+ * .setTable('species', {
581
+ * dog: {price: 5},
582
+ * cat: {price: 4},
583
+ * });
584
+ *
585
+ * const relationships = createRelationships(store);
586
+ * relationships.setRelationshipDefinition(
587
+ * 'petSpecies',
588
+ * 'pets',
589
+ * 'species',
590
+ * 'species',
591
+ * );
592
+ *
593
+ * console.log(relationships.getRemoteRowId('petSpecies', 'fido'));
594
+ * // -> 'dog'
595
+ * console.log(relationships.getRemoteRowId('petSpecies', 'toto'));
596
+ * // -> undefined
597
+ * console.log(relationships.getRemoteRowId('petColor', 'fido'));
598
+ * // -> undefined
599
+ * ```
600
+ * @category Getter
601
+ */
602
+ getRemoteRowId(relationshipId: Id, localRowId: Id): Id | undefined;
603
+
604
+ /**
605
+ * The getLocalRowIds method gets the local Row Ids for a given remote Row in
606
+ * a Relationship.
607
+ *
608
+ * If the identified Relationship or Row does not exist (or if the definition
609
+ * references a Table that does not exist) then an empty array is returned.
610
+ *
611
+ * @param relationshipId The Id of the Relationship.
612
+ * @param remoteRowId The Id of the remote Row in the Relationship.
613
+ * @returns The local Row Ids in the Relationship, or an empty array.
614
+ * @example
615
+ * This example creates a Store, creates a Relationships object, and defines
616
+ * a simple Relationship. It then uses getLocalRowIds to see the local Row Ids
617
+ * in the Relationship (and also the local Row Ids for a remote Row that does
618
+ * not exist, and for a Relationship that has not been defined).
619
+ *
620
+ * ```js
621
+ * const store = createStore()
622
+ * .setTable('pets', {
623
+ * fido: {species: 'dog'},
624
+ * felix: {species: 'cat'},
625
+ * cujo: {species: 'dog'},
626
+ * })
627
+ * .setTable('species', {
628
+ * dog: {price: 5},
629
+ * cat: {price: 4},
630
+ * });
631
+ *
632
+ * const relationships = createRelationships(store);
633
+ * relationships.setRelationshipDefinition(
634
+ * 'petSpecies',
635
+ * 'pets',
636
+ * 'species',
637
+ * 'species',
638
+ * );
639
+ *
640
+ * console.log(relationships.getLocalRowIds('petSpecies', 'dog'));
641
+ * // -> ['fido', 'cujo']
642
+ * console.log(relationships.getLocalRowIds('petSpecies', 'worm'));
643
+ * // -> []
644
+ * console.log(relationships.getLocalRowIds('petColor', 'brown'));
645
+ * // -> []
646
+ * ```
647
+ * @category Getter
648
+ */
649
+ getLocalRowIds(relationshipId: Id, remoteRowId: Id): Ids;
650
+
651
+ /**
652
+ * The getLinkedRowIds method gets the linked Row Ids for a given Row in a
653
+ * linked list Relationship.
654
+ *
655
+ * A linked list Relationship is one that has the same Table specified as both
656
+ * local Table Id and remote Table Id, allowing you to create a sequence of
657
+ * Row objects within that one Table.
658
+ *
659
+ * If the identified Relationship or Row does not exist (or if the definition
660
+ * references a Table that does not exist) then an array containing just the
661
+ * first Row Id is returned.
662
+ *
663
+ * @param relationshipId The Id of the Relationship.
664
+ * @param firstRowId The Id of the first Row in the linked list Relationship.
665
+ * @returns The linked Row Ids in the Relationship.
666
+ * @example
667
+ * This example creates a Store, creates a Relationships object, and defines
668
+ * a simple linked list Relationship. It then uses getLinkedRowIds to see the
669
+ * linked Row Ids in the Relationship (and also the linked Row Ids for a Row
670
+ * that does not exist, and for a Relationship that has not been defined).
671
+ *
672
+ * ```js
673
+ * const store = createStore().setTable('pets', {
674
+ * fido: {species: 'dog', next: 'felix'},
675
+ * felix: {species: 'cat', next: 'cujo'},
676
+ * cujo: {species: 'dog'},
677
+ * });
678
+ *
679
+ * const relationships = createRelationships(store);
680
+ * relationships.setRelationshipDefinition(
681
+ * 'petSequence',
682
+ * 'pets',
683
+ * 'pets',
684
+ * 'next',
685
+ * );
686
+ *
687
+ * console.log(relationships.getLinkedRowIds('petSequence', 'fido'));
688
+ * // -> ['fido', 'felix', 'cujo']
689
+ * console.log(relationships.getLinkedRowIds('petSequence', 'felix'));
690
+ * // -> ['felix', 'cujo']
691
+ * console.log(relationships.getLinkedRowIds('petSequence', 'toto'));
692
+ * // -> ['toto']
693
+ * console.log(relationships.getLinkedRowIds('petFriendships', 'fido'));
694
+ * // -> ['fido']
695
+ * ```
696
+ * @category Getter
697
+ */
698
+ getLinkedRowIds(relationshipId: Id, firstRowId: Id): Ids;
699
+
700
+ /**
701
+ * The addRemoteRowIdListener method registers a listener function with the
702
+ * Relationships object that will be called whenever a remote Row Id in a
703
+ * Relationship changes.
704
+ *
705
+ * You can either listen to a single local Row (by specifying the Relationship
706
+ * Id and local Row Id as the method's first two parameters), or changes to
707
+ * any local Row (by providing a `null` wildcards).
708
+ *
709
+ * Both, either, or neither of the `relationshipId` and `localRowId`
710
+ * parameters can be wildcarded with `null`. You can listen to a specific
711
+ * local Row in a specific Relationship, any local Row in a specific
712
+ * Relationship, a specific local Row in any Relationship, or any local Row in
713
+ * any Relationship.
714
+ *
715
+ * The provided listener is a RemoteRowIdListener function, and will be called
716
+ * with a reference to the Relationships object, the Id of the Relationship,
717
+ * and the Id of the local Row that had its remote Row change.
718
+ *
719
+ * @param relationshipId The Id of the Relationship to listen to, or `null` as
720
+ * a wildcard.
721
+ * @param localRowId The Id of the local Row to listen to, or `null` as a
722
+ * wildcard.
723
+ * @param listener The function that will be called whenever the remote Row Id
724
+ * changes.
725
+ * @returns A unique Id for the listener that can later be used to remove it.
726
+ * @example
727
+ * This example creates a Store, a Relationships object, and then registers a
728
+ * listener that responds to any changes to a specific local Row's remote Row.
729
+ *
730
+ * ```js
731
+ * const store = createStore()
732
+ * .setTable('pets', {
733
+ * fido: {species: 'dog'},
734
+ * felix: {species: 'cat'},
735
+ * cujo: {species: 'dog'},
736
+ * })
737
+ * .setTable('species', {
738
+ * wolf: {price: 10},
739
+ * dog: {price: 5},
740
+ * cat: {price: 4},
741
+ * });
742
+ *
743
+ * const relationships = createRelationships(store);
744
+ * relationships.setRelationshipDefinition(
745
+ * 'petSpecies',
746
+ * 'pets',
747
+ * 'species',
748
+ * 'species',
749
+ * );
750
+ *
751
+ * const listenerId = relationships.addRemoteRowIdListener(
752
+ * 'petSpecies',
753
+ * 'cujo',
754
+ * (relationships, relationshipId, localRowId) => {
755
+ * console.log('petSpecies relationship (from cujo) changed');
756
+ * console.log(relationships.getRemoteRowId('petSpecies', 'cujo'));
757
+ * },
758
+ * );
759
+ *
760
+ * store.setCell('pets', 'cujo', 'species', 'wolf');
761
+ * // -> 'petSpecies relationship (from cujo) changed'
762
+ * // -> 'wolf'
763
+ *
764
+ * relationships.delListener(listenerId);
765
+ * ```
766
+ * @example
767
+ * This example creates a Store, a Relationships object, and then registers a
768
+ * listener that responds to any changes to any local Row's remote Row. It
769
+ * also illustrates how you can use the getStore method and the getRemoteRowId
770
+ * method to resolve the remote Row as a whole.
771
+ *
772
+ * ```js
773
+ * const store = createStore()
774
+ * .setTable('pets', {
775
+ * fido: {species: 'dog', color: 'brown'},
776
+ * felix: {species: 'cat', color: 'black'},
777
+ * cujo: {species: 'dog', color: 'brown'},
778
+ * })
779
+ * .setTable('species', {
780
+ * wolf: {price: 10},
781
+ * dog: {price: 5},
782
+ * cat: {price: 4},
783
+ * })
784
+ * .setTable('color', {
785
+ * brown: {discount: 0.1},
786
+ * black: {discount: 0},
787
+ * grey: {discount: 0.2},
788
+ * });
789
+ *
790
+ * const relationships = createRelationships(store)
791
+ * .setRelationshipDefinition('petSpecies', 'pets', 'species', 'species')
792
+ * .setRelationshipDefinition('petColor', 'pets', 'color', 'color');
793
+ *
794
+ * const listenerId = relationships.addRemoteRowIdListener(
795
+ * null,
796
+ * null,
797
+ * (relationships, relationshipId, localRowId) => {
798
+ * console.log(
799
+ * `${relationshipId} relationship (from ${localRowId}) changed`,
800
+ * );
801
+ * console.log(relationships.getRemoteRowId(relationshipId, localRowId));
802
+ * console.log(
803
+ * relationships
804
+ * .getStore()
805
+ * .getRow(
806
+ * relationships.getRemoteTableId(relationshipId),
807
+ * relationships.getRemoteRowId(relationshipId, localRowId),
808
+ * ),
809
+ * );
810
+ * },
811
+ * );
812
+ *
813
+ * store.setRow('pets', 'cujo', {species: 'wolf', color: 'grey'});
814
+ * // -> 'petSpecies relationship (from cujo) changed'
815
+ * // -> 'wolf'
816
+ * // -> {price: 10}
817
+ * // -> 'petColor relationship (from cujo) changed'
818
+ * // -> 'grey'
819
+ * // -> {discount: 0.2}
820
+ *
821
+ * relationships.delListener(listenerId);
822
+ * ```
823
+ * @category Listener
824
+ */
825
+ addRemoteRowIdListener(
826
+ relationshipId: IdOrNull,
827
+ localRowId: IdOrNull,
828
+ listener: RemoteRowIdListener,
829
+ ): Id;
830
+
831
+ /**
832
+ * The addLocalRowIdsListener method registers a listener function with the
833
+ * Relationships object that will be called whenever the local Row Ids in
834
+ * a Relationship change.
835
+ *
836
+ * You can either listen to a single local Row (by specifying the Relationship
837
+ * Id and local Row Id as the method's first two parameters), or changes to
838
+ * any local Row (by providing a `null` wildcards).
839
+ *
840
+ * Both, either, or neither of the `relationshipId` and `remoteRowId`
841
+ * parameters can be wildcarded with `null`. You can listen to a specific
842
+ * remote Row in a specific Relationship, any remote Row in a specific
843
+ * Relationship, a specific remote Row in any Relationship, or any remote Row
844
+ * in any Relationship.
845
+ *
846
+ * The provided listener is a LocalRowIdsListener function, and will be called
847
+ * with a reference to the Relationships object, the Id of the Relationship,
848
+ * and the Id of the remote Row that had its local Row objects change.
849
+ *
850
+ * @param relationshipId The Id of the Relationship to listen to, or `null` as
851
+ * a wildcard.
852
+ * @param remoteRowId The Id of the remote Row to listen to, or `null` as a
853
+ * wildcard.
854
+ * @param listener The function that will be called whenever the local Row Ids
855
+ * change.
856
+ * @returns A unique Id for the listener that can later be used to remove it.
857
+ * @example
858
+ * This example creates a Store, a Relationships object, and then registers a
859
+ * listener that responds to any changes to a specific remote Row's local Row
860
+ * objects.
861
+ *
862
+ * ```js
863
+ * const store = createStore()
864
+ * .setTable('pets', {
865
+ * fido: {species: 'dog'},
866
+ * felix: {species: 'cat'},
867
+ * cujo: {species: 'dog'},
868
+ * })
869
+ * .setTable('species', {
870
+ * wolf: {price: 10},
871
+ * dog: {price: 5},
872
+ * cat: {price: 4},
873
+ * });
874
+ *
875
+ * const relationships = createRelationships(store);
876
+ * relationships.setRelationshipDefinition(
877
+ * 'petSpecies',
878
+ * 'pets',
879
+ * 'species',
880
+ * 'species',
881
+ * );
882
+ *
883
+ * const listenerId = relationships.addLocalRowIdsListener(
884
+ * 'petSpecies',
885
+ * 'dog',
886
+ * (relationships, relationshipId, remoteRowId) => {
887
+ * console.log('petSpecies relationship (to dog) changed');
888
+ * console.log(relationships.getLocalRowIds('petSpecies', 'dog'));
889
+ * },
890
+ * );
891
+ *
892
+ * store.setRow('pets', 'toto', {species: 'dog'});
893
+ * // -> 'petSpecies relationship (to dog) changed'
894
+ * // -> ['fido', 'cujo', 'toto']
895
+ *
896
+ * relationships.delListener(listenerId);
897
+ * ```
898
+ * @example
899
+ * This example creates a Store, a Relationships object, and then registers a
900
+ * listener that responds to any changes to any remote Row's local Row
901
+ * objects.
902
+ *
903
+ * ```js
904
+ * const store = createStore()
905
+ * .setTable('pets', {
906
+ * fido: {species: 'dog', color: 'brown'},
907
+ * felix: {species: 'cat', color: 'black'},
908
+ * cujo: {species: 'dog', color: 'brown'},
909
+ * toto: {species: 'dog', color: 'grey'},
910
+ * })
911
+ * .setTable('species', {
912
+ * wolf: {price: 10},
913
+ * dog: {price: 5},
914
+ * cat: {price: 4},
915
+ * })
916
+ * .setTable('color', {
917
+ * brown: {discount: 0.1},
918
+ * black: {discount: 0},
919
+ * grey: {discount: 0.2},
920
+ * });
921
+ *
922
+ * const relationships = createRelationships(store)
923
+ * .setRelationshipDefinition('petSpecies', 'pets', 'species', 'species')
924
+ * .setRelationshipDefinition('petColor', 'pets', 'color', 'color');
925
+ *
926
+ * const listenerId = relationships.addLocalRowIdsListener(
927
+ * null,
928
+ * null,
929
+ * (relationships, relationshipId, remoteRowId) => {
930
+ * console.log(
931
+ * `${relationshipId} relationship (to ${remoteRowId}) changed`,
932
+ * );
933
+ * console.log(relationships.getLocalRowIds(relationshipId, remoteRowId));
934
+ * },
935
+ * );
936
+ *
937
+ * store.setRow('pets', 'cujo', {species: 'wolf', color: 'grey'});
938
+ * // -> 'petSpecies relationship (to dog) changed'
939
+ * // -> ['fido', 'toto']
940
+ * // -> 'petSpecies relationship (to wolf) changed'
941
+ * // -> ['cujo']
942
+ * // -> 'petColor relationship (to brown) changed'
943
+ * // -> ['fido']
944
+ * // -> 'petColor relationship (to grey) changed'
945
+ * // -> ['toto', 'cujo']
946
+ *
947
+ * relationships.delListener(listenerId);
948
+ * ```
949
+ * @category Listener
950
+ */
951
+ addLocalRowIdsListener(
952
+ relationshipId: IdOrNull,
953
+ remoteRowId: IdOrNull,
954
+ listener: LocalRowIdsListener,
955
+ ): Id;
956
+
957
+ /**
958
+ * The addLinkedRowIdsListener method registers a listener function with the
959
+ * Relationships object that will be called whenever the linked Row Ids in a
960
+ * linked list Relationship change.
961
+ *
962
+ * A linked list Relationship is one that has the same Table specified as both
963
+ * local Table Id and remote Table Id, allowing you to create a sequence of
964
+ * Row objects within that one Table.
965
+ *
966
+ * You listen to changes to a linked list starting from a single first Row by
967
+ * specifying the Relationship Id and local Row Id as the method's first two
968
+ * parameters.
969
+ *
970
+ * Unlike other listener registration methods, you cannot provide `null`
971
+ * wildcards for the first two parameters of the addLinkedRowIdsListener
972
+ * method. This prevents the prohibitive expense of tracking all the possible
973
+ * linked lists (and partial linked lists within them) in a Store.
974
+ *
975
+ * The provided listener is a LinkedRowIdsListener function, and will be
976
+ * called with a reference to the Relationships object, the Id of the
977
+ * Relationship, and the Id of the first Row that had its linked list change.
978
+ *
979
+ * @param relationshipId The Id of the Relationship to listen to.
980
+ * @param firstRowId The Id of the first Row of the linked list to listen to.
981
+ * @param listener The function that will be called whenever the linked Row
982
+ * Ids change.
983
+ * @returns A unique Id for the listener that can later be used to remove it.
984
+ * @example
985
+ * This example creates a Store, a Relationships object, and then registers a
986
+ * listener that responds to any changes to a specific first Row's linked Row
987
+ * objects.
988
+ *
989
+ * ```js
990
+ * const store = createStore().setTable('pets', {
991
+ * fido: {species: 'dog', next: 'felix'},
992
+ * felix: {species: 'cat', next: 'cujo'},
993
+ * cujo: {species: 'dog'},
994
+ * });
995
+ *
996
+ * const relationships = createRelationships(store);
997
+ * relationships.setRelationshipDefinition(
998
+ * 'petSequence',
999
+ * 'pets',
1000
+ * 'pets',
1001
+ * 'next',
1002
+ * );
1003
+ *
1004
+ * const listenerId = relationships.addLinkedRowIdsListener(
1005
+ * 'petSequence',
1006
+ * 'fido',
1007
+ * (relationships, relationshipId, firstRowId) => {
1008
+ * console.log('petSequence linked list (from fido) changed');
1009
+ * console.log(relationships.getLinkedRowIds('petSequence', 'fido'));
1010
+ * },
1011
+ * );
1012
+ *
1013
+ * store.setRow('pets', 'toto', {species: 'dog'});
1014
+ * store.setCell('pets', 'cujo', 'next', 'toto');
1015
+ * // -> 'petSequence linked list (from fido) changed'
1016
+ * // -> ['fido', 'felix', 'cujo', 'toto']
1017
+ *
1018
+ * relationships.delListener(listenerId);
1019
+ * ```
1020
+ * @category Listener
1021
+ */
1022
+ addLinkedRowIdsListener(
1023
+ relationshipId: Id,
1024
+ firstRowId: Id,
1025
+ listener: LinkedRowIdsListener,
1026
+ ): Id;
1027
+
1028
+ /**
1029
+ * The delListener method removes a listener that was previously added to the
1030
+ * Relationships object.
1031
+ *
1032
+ * Use the Id returned by whichever method was used to add the listener. Note
1033
+ * that the Relationships object may re-use this Id for future listeners added
1034
+ * to it.
1035
+ *
1036
+ * @param listenerId The Id of the listener to remove.
1037
+ * @returns A reference to the Relationships object.
1038
+ * @example
1039
+ * This example creates a Store, a Relationships object, registers a listener,
1040
+ * and then removes it.
1041
+ *
1042
+ * ```js
1043
+ * const store = createStore()
1044
+ * .setTable('pets', {
1045
+ * fido: {species: 'dog'},
1046
+ * felix: {species: 'cat'},
1047
+ * cujo: {species: 'dog'},
1048
+ * })
1049
+ * .setTable('species', {
1050
+ * wolf: {price: 10},
1051
+ * dog: {price: 5},
1052
+ * cat: {price: 4},
1053
+ * });
1054
+ *
1055
+ * const relationships = createRelationships(store);
1056
+ * relationships.setRelationshipDefinition(
1057
+ * 'petSpecies',
1058
+ * 'pets',
1059
+ * 'species',
1060
+ * 'species',
1061
+ * );
1062
+ *
1063
+ * const listenerId = relationships.addLocalRowIdsListener(
1064
+ * 'petSpecies',
1065
+ * 'dog',
1066
+ * (relationships, relationshipId, remoteRowId) => {
1067
+ * console.log('petSpecies relationship (to dog) changed');
1068
+ * },
1069
+ * );
1070
+ *
1071
+ * store.setRow('pets', 'toto', {species: 'dog'});
1072
+ * // -> 'petSpecies relationship (to dog) changed'
1073
+ *
1074
+ * relationships.delListener(listenerId);
1075
+ *
1076
+ * store.setRow('pets', 'toto', {species: 'dog'});
1077
+ * // -> undefined
1078
+ * // The listener is not called.
1079
+ * ```
1080
+ * @category Listener
1081
+ */
1082
+ delListener(listenerId: Id): Relationships;
1083
+
1084
+ /**
1085
+ * The destroy method should be called when this Relationships object is no
1086
+ * longer used.
1087
+ *
1088
+ * This guarantees that all of the listeners that the object registered with
1089
+ * the underlying Store are removed and it can be correctly garbage collected.
1090
+ *
1091
+ * @example
1092
+ * This example creates a Store, adds an Relationships object with a
1093
+ * definition (that registers a RowListener with the underlying Store),
1094
+ * and then destroys it again, removing the listener.
1095
+ *
1096
+ * ```js
1097
+ * const store = createStore()
1098
+ * .setTable('pets', {
1099
+ * fido: {species: 'dog'},
1100
+ * felix: {species: 'cat'},
1101
+ * cujo: {species: 'dog'},
1102
+ * })
1103
+ * .setTable('species', {
1104
+ * wolf: {price: 10},
1105
+ * dog: {price: 5},
1106
+ * cat: {price: 4},
1107
+ * });
1108
+ *
1109
+ * const relationships = createRelationships(store);
1110
+ * relationships.setRelationshipDefinition(
1111
+ * 'petSpecies',
1112
+ * 'pets',
1113
+ * 'species',
1114
+ * 'species',
1115
+ * );
1116
+ * console.log(store.getListenerStats().row);
1117
+ * // -> 1
1118
+ *
1119
+ * relationships.destroy();
1120
+ *
1121
+ * console.log(store.getListenerStats().row);
1122
+ * // -> 0
1123
+ * ```
1124
+ * @category Lifecycle
1125
+ */
1126
+ destroy(): void;
1127
+
1128
+ /**
1129
+ * The getListenerStats method provides a set of statistics about the
1130
+ * listeners registered with the Relationships object, and is used for
1131
+ * debugging purposes.
1132
+ *
1133
+ * The RelationshipsListenerStats object contains a breakdown of the different
1134
+ * types of listener.
1135
+ *
1136
+ * The statistics are only populated in a debug build: production builds
1137
+ * return an empty object. The method is intended to be used during
1138
+ * development to ensure your application is not leaking listener
1139
+ * registrations, for example.
1140
+ *
1141
+ * @returns A RelationshipsListenerStats object containing Relationships
1142
+ * listener statistics.
1143
+ * @example
1144
+ * This example gets the listener statistics of a Relationships object.
1145
+ *
1146
+ * ```js
1147
+ * const store = createStore();
1148
+ * const relationships = createRelationships(store);
1149
+ * relationships.addRemoteRowIdListener(null, null, () => {
1150
+ * console.log('Remote Row Id changed');
1151
+ * });
1152
+ * relationships.addLocalRowIdsListener(null, null, () => {
1153
+ * console.log('Local Row Id changed');
1154
+ * });
1155
+ *
1156
+ * const listenerStats = relationships.getListenerStats();
1157
+ * console.log(listenerStats.remoteRowId);
1158
+ * // -> 1
1159
+ * console.log(listenerStats.localRowIds);
1160
+ * // -> 1
1161
+ * ```
1162
+ * @category Development
1163
+ */
1164
+ getListenerStats(): RelationshipsListenerStats;
1165
+ }
1166
+
1167
+ /**
1168
+ * The createRelationships function creates an Relationships object, and is the
1169
+ * main entry point into the relationships module.
1170
+ *
1171
+ * It is trivially simple.
1172
+ *
1173
+ * A given Store can only have one Relationships object associated with it. If
1174
+ * you call this function twice on the same Store, your second call will return
1175
+ * a reference to the Relationships object created by the first.
1176
+ *
1177
+ * @param store The Store for which to register Relationships.
1178
+ * @returns A reference to the new Relationships object.
1179
+ * @example
1180
+ * This example creates an Relationships object.
1181
+ *
1182
+ * ```js
1183
+ * const store = createStore();
1184
+ * const relationships = createRelationships(store);
1185
+ * console.log(relationships.getRelationshipIds());
1186
+ * // -> []
1187
+ * ```
1188
+ * @example
1189
+ * This example creates a Relationships object, and calls the method a second
1190
+ * time for the same Store to return the same object.
1191
+ *
1192
+ * ```js
1193
+ * const store = createStore();
1194
+ * const relationships1 = createRelationships(store);
1195
+ * const relationships2 = createRelationships(store);
1196
+ * console.log(relationships1 === relationships2);
1197
+ * // -> true
1198
+ * ```
1199
+ * @category Creation
1200
+ */
1201
+ export function createRelationships(store: Store): Relationships;