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