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
@@ -11,10 +11,11 @@
11
11
  * @module relationships
12
12
  */
13
13
 
14
+ import {CellIdFromSchema, TableIdFromSchema} from './internal/store';
14
15
  import {
15
16
  GetCell,
16
- NoSchemas,
17
17
  OptionalSchemas,
18
+ OptionalTablesSchema,
18
19
  RowCallback,
19
20
  Store,
20
21
  } from './store.d';
@@ -49,6 +50,15 @@ export type Relationship = {
49
50
  * The RelationshipCallback type describes a function that takes a
50
51
  * Relationship's Id and a callback to loop over each local Row within it.
51
52
  *
53
+ * This has schema-based typing. The following is a simplified representation:
54
+ *
55
+ * ```ts override
56
+ * (
57
+ * relationshipId: Id,
58
+ * forEachRow: (rowCallback: RowCallback) => void,
59
+ * ) => void;
60
+ * ```
61
+ *
52
62
  * A RelationshipCallback is provided when using the forEachRelationship method,
53
63
  * so that you can do something based on every Relationship in the Relationships
54
64
  * object. See that method for specific examples.
@@ -59,15 +69,25 @@ export type Relationship = {
59
69
  * objects in this Relationship.
60
70
  * @category Callback
61
71
  */
62
- export type RelationshipCallback = (
72
+ export type RelationshipCallback<Schema extends OptionalTablesSchema> = (
63
73
  relationshipId: Id,
64
- forEachRow: (rowCallback: RowCallback) => void,
74
+ forEachRow: (rowCallback: RowCallback<Schema>) => void,
65
75
  ) => void;
66
76
 
67
77
  /**
68
78
  * The RemoteRowIdListener type describes a function that is used to listen to
69
79
  * changes to the remote Row Id end of a Relationship.
70
80
  *
81
+ * This has schema-based typing. The following is a simplified representation:
82
+ *
83
+ * ```ts override
84
+ * (
85
+ * relationships: Relationships,
86
+ * relationshipId: Id,
87
+ * localRowId: Id,
88
+ * ) => void;
89
+ * ```
90
+ *
71
91
  * A RemoteRowIdListener is provided when using the addRemoteRowIdListener
72
92
  * method. See that method for specific examples.
73
93
  *
@@ -80,8 +100,8 @@ export type RelationshipCallback = (
80
100
  * @param localRowId The Id of the local Row whose remote Row Id changed.
81
101
  * @category Listener
82
102
  */
83
- export type RemoteRowIdListener = (
84
- relationships: Relationships,
103
+ export type RemoteRowIdListener<Schemas extends OptionalSchemas> = (
104
+ relationships: Relationships<Schemas>,
85
105
  relationshipId: Id,
86
106
  localRowId: Id,
87
107
  ) => void;
@@ -90,6 +110,16 @@ export type RemoteRowIdListener = (
90
110
  * The LocalRowIdsListener type describes a function that is used to listen to
91
111
  * changes to the local Row Id ends of a Relationship.
92
112
  *
113
+ * This has schema-based typing. The following is a simplified representation:
114
+ *
115
+ * ```ts override
116
+ * (
117
+ * relationships: Relationships,
118
+ * relationshipId: Id,
119
+ * remoteRowId: Id,
120
+ * ) => void;
121
+ * ```
122
+ *
93
123
  * A LocalRowIdsListener is provided when using the addLocalRowIdsListener
94
124
  * method. See that method for specific examples.
95
125
  *
@@ -102,8 +132,8 @@ export type RemoteRowIdListener = (
102
132
  * @param remoteRowId The Id of the remote Row whose local Row Ids changed.
103
133
  * @category Listener
104
134
  */
105
- export type LocalRowIdsListener = (
106
- relationships: Relationships,
135
+ export type LocalRowIdsListener<Schemas extends OptionalSchemas> = (
136
+ relationships: Relationships<Schemas>,
107
137
  relationshipId: Id,
108
138
  remoteRowId: Id,
109
139
  ) => void;
@@ -112,6 +142,16 @@ export type LocalRowIdsListener = (
112
142
  * The LinkedRowIdsListener type describes a function that is used to listen to
113
143
  * changes to the local Row Id ends of a Relationship.
114
144
  *
145
+ * This has schema-based typing. The following is a simplified representation:
146
+ *
147
+ * ```ts override
148
+ * (
149
+ * relationships: Relationships,
150
+ * relationshipId: Id,
151
+ * firstRowId: Id,
152
+ * ) => void;
153
+ * ```
154
+ *
115
155
  * A LinkedRowIdsListener is provided when using the addLinkedRowIdsListener
116
156
  * method. See that method for specific examples.
117
157
  *
@@ -125,8 +165,8 @@ export type LocalRowIdsListener = (
125
165
  * members changed.
126
166
  * @category Listener
127
167
  */
128
- export type LinkedRowIdsListener = (
129
- relationships: Relationships,
168
+ export type LinkedRowIdsListener<Schemas extends OptionalSchemas> = (
169
+ relationships: Relationships<Schemas>,
130
170
  relationshipId: Id,
131
171
  firstRowId: Id,
132
172
  ) => void;
@@ -253,11 +293,22 @@ export type RelationshipsListenerStats = {
253
293
  * @see Drawing demo
254
294
  * @category Relationships
255
295
  */
256
- export interface Relationships<Schemas extends OptionalSchemas = NoSchemas> {
296
+ export interface Relationships<in out Schemas extends OptionalSchemas> {
257
297
  /**
258
298
  * The setRelationshipDefinition method lets you set the definition of a
259
299
  * Relationship.
260
300
  *
301
+ * This has schema-based typing. The following is a simplified representation:
302
+ *
303
+ * ```ts override
304
+ * setRelationshipDefinition(
305
+ * relationshipId: Id,
306
+ * localTableId: Id,
307
+ * remoteTableId: Id,
308
+ * getRemoteRowId: Id | ((getCell: GetCell, localRowId: Id) => Id),
309
+ * ): Relationships;
310
+ * ```
311
+ *
261
312
  * Every Relationship definition is identified by a unique Id, and if you
262
313
  * re-use an existing Id with this method, the previous definition is
263
314
  * overwritten.
@@ -340,17 +391,25 @@ export interface Relationships<Schemas extends OptionalSchemas = NoSchemas> {
340
391
  * ```
341
392
  * @category Configuration
342
393
  */
343
- setRelationshipDefinition(
394
+ setRelationshipDefinition<LocalTableId extends TableIdFromSchema<Schemas[0]>>(
344
395
  relationshipId: Id,
345
- localTableId: Id,
346
- remoteTableId: Id,
347
- getRemoteRowId: Id | ((getCell: GetCell, localRowId: Id) => Id),
396
+ localTableId: LocalTableId,
397
+ remoteTableId: TableIdFromSchema<Schemas[0]>,
398
+ getRemoteRowId:
399
+ | CellIdFromSchema<Schemas[0], LocalTableId>
400
+ | ((getCell: GetCell<Schemas[0], LocalTableId>, localRowId: Id) => Id),
348
401
  ): Relationships<Schemas>;
349
402
 
350
403
  /**
351
404
  * The delRelationshipDefinition method removes an existing Relationship
352
405
  * definition.
353
406
  *
407
+ * This has schema-based typing. The following is a simplified representation:
408
+ *
409
+ * ```ts override
410
+ * delRelationshipDefinition(relationshipId: Id): Relationships;
411
+ * ```
412
+ *
354
413
  * @param relationshipId The Id of the Relationship to remove.
355
414
  * @returns A reference to the Relationships object.
356
415
  * @example
@@ -391,6 +450,12 @@ export interface Relationships<Schemas extends OptionalSchemas = NoSchemas> {
391
450
  * The getStore method returns a reference to the underlying Store that is
392
451
  * backing this Relationships object.
393
452
  *
453
+ * This has schema-based typing. The following is a simplified representation:
454
+ *
455
+ * ```ts override
456
+ * getStore(): Store;
457
+ * ```
458
+ *
394
459
  * @returns A reference to the Store.
395
460
  * @example
396
461
  * This example creates a Relationships object against a newly-created Store
@@ -436,6 +501,12 @@ export interface Relationships<Schemas extends OptionalSchemas = NoSchemas> {
436
501
  * The forEachRelationship method takes a function that it will then call for
437
502
  * each Relationship in a specified Relationships object.
438
503
  *
504
+ * This has schema-based typing. The following is a simplified representation:
505
+ *
506
+ * ```ts override
507
+ * forEachRelationship(relationshipCallback: RelationshipCallback): void;
508
+ * ```
509
+ *
439
510
  * This method is useful for iterating over the structure of the Relationships
440
511
  * object in a functional style. The `relationshipCallback` parameter is a
441
512
  * RelationshipCallback function that will be called with the Id of each
@@ -473,7 +544,9 @@ export interface Relationships<Schemas extends OptionalSchemas = NoSchemas> {
473
544
  * ```
474
545
  * @category Iterator
475
546
  */
476
- forEachRelationship(relationshipCallback: RelationshipCallback): void;
547
+ forEachRelationship(
548
+ relationshipCallback: RelationshipCallback<Schemas[0]>,
549
+ ): void;
477
550
 
478
551
  /**
479
552
  * The hasRelationship method returns a boolean indicating whether a given
@@ -502,6 +575,12 @@ export interface Relationships<Schemas extends OptionalSchemas = NoSchemas> {
502
575
  * The getLocalTableId method returns the Id of the underlying local Table
503
576
  * that is used in the Relationship.
504
577
  *
578
+ * This has schema-based typing. The following is a simplified representation:
579
+ *
580
+ * ```ts override
581
+ * getLocalTableId(relationshipId: Id): Id | undefined;
582
+ * ```
583
+ *
505
584
  * If the Relationship Id is invalid, the method returns `undefined`.
506
585
  *
507
586
  * @param relationshipId The Id of a Relationship.
@@ -528,12 +607,20 @@ export interface Relationships<Schemas extends OptionalSchemas = NoSchemas> {
528
607
  * ```
529
608
  * @category Getter
530
609
  */
531
- getLocalTableId(relationshipId: Id): Id;
610
+ getLocalTableId<TableId extends TableIdFromSchema<Schemas[0]>>(
611
+ relationshipId: Id,
612
+ ): TableId | undefined;
532
613
 
533
614
  /**
534
615
  * The getRemoteTableId method returns the Id of the underlying remote Table
535
616
  * that is used in the Relationship.
536
617
  *
618
+ * This has schema-based typing. The following is a simplified representation:
619
+ *
620
+ * ```ts override
621
+ * getRemoteTableId(relationshipId: Id): Id | undefined;
622
+ * ```
623
+ *
537
624
  * If the Relationship Id is invalid, the method returns `undefined`.
538
625
  *
539
626
  * @param relationshipId The Id of a Relationship.
@@ -560,7 +647,9 @@ export interface Relationships<Schemas extends OptionalSchemas = NoSchemas> {
560
647
  * ```
561
648
  * @category Getter
562
649
  */
563
- getRemoteTableId(relationshipId: Id): Id;
650
+ getRemoteTableId<TableId extends TableIdFromSchema<Schemas[0]>>(
651
+ relationshipId: Id,
652
+ ): TableId | undefined;
564
653
 
565
654
  /**
566
655
  * The getRemoteRowId method gets the remote Row Id for a given local Row in a
@@ -710,6 +799,16 @@ export interface Relationships<Schemas extends OptionalSchemas = NoSchemas> {
710
799
  * Relationships object that will be called whenever a remote Row Id in a
711
800
  * Relationship changes.
712
801
  *
802
+ * This has schema-based typing. The following is a simplified representation:
803
+ *
804
+ * ```ts override
805
+ * addRemoteRowIdListener(
806
+ * relationshipId: IdOrNull,
807
+ * localRowId: IdOrNull,
808
+ * listener: RemoteRowIdListener,
809
+ * ): Id;
810
+ * ```
811
+ *
713
812
  * You can either listen to a single local Row (by specifying the Relationship
714
813
  * Id and local Row Id as the method's first two parameters), or changes to
715
814
  * any local Row (by providing a `null` wildcards).
@@ -833,7 +932,7 @@ export interface Relationships<Schemas extends OptionalSchemas = NoSchemas> {
833
932
  addRemoteRowIdListener(
834
933
  relationshipId: IdOrNull,
835
934
  localRowId: IdOrNull,
836
- listener: RemoteRowIdListener,
935
+ listener: RemoteRowIdListener<Schemas>,
837
936
  ): Id;
838
937
 
839
938
  /**
@@ -841,6 +940,16 @@ export interface Relationships<Schemas extends OptionalSchemas = NoSchemas> {
841
940
  * Relationships object that will be called whenever the local Row Ids in
842
941
  * a Relationship change.
843
942
  *
943
+ * This has schema-based typing. The following is a simplified representation:
944
+ *
945
+ * ```ts override
946
+ * addLocalRowIdsListener(
947
+ * relationshipId: IdOrNull,
948
+ * remoteRowId: IdOrNull,
949
+ * listener: LocalRowIdsListener,
950
+ * ): Id;
951
+ * ```
952
+ *
844
953
  * You can either listen to a single local Row (by specifying the Relationship
845
954
  * Id and local Row Id as the method's first two parameters), or changes to
846
955
  * any local Row (by providing a `null` wildcards).
@@ -959,7 +1068,7 @@ export interface Relationships<Schemas extends OptionalSchemas = NoSchemas> {
959
1068
  addLocalRowIdsListener(
960
1069
  relationshipId: IdOrNull,
961
1070
  remoteRowId: IdOrNull,
962
- listener: LocalRowIdsListener,
1071
+ listener: LocalRowIdsListener<Schemas>,
963
1072
  ): Id;
964
1073
 
965
1074
  /**
@@ -967,6 +1076,16 @@ export interface Relationships<Schemas extends OptionalSchemas = NoSchemas> {
967
1076
  * Relationships object that will be called whenever the linked Row Ids in a
968
1077
  * linked list Relationship change.
969
1078
  *
1079
+ * This has schema-based typing. The following is a simplified representation:
1080
+ *
1081
+ * ```ts override
1082
+ * addLinkedRowIdsListener(
1083
+ * relationshipId: Id,
1084
+ * firstRowId: Id,
1085
+ * listener: LinkedRowIdsListener,
1086
+ * ): Id;
1087
+ * ```
1088
+ *
970
1089
  * A linked list Relationship is one that has the same Table specified as both
971
1090
  * local Table Id and remote Table Id, allowing you to create a sequence of
972
1091
  * Row objects within that one Table.
@@ -1030,13 +1149,19 @@ export interface Relationships<Schemas extends OptionalSchemas = NoSchemas> {
1030
1149
  addLinkedRowIdsListener(
1031
1150
  relationshipId: Id,
1032
1151
  firstRowId: Id,
1033
- listener: LinkedRowIdsListener,
1152
+ listener: LinkedRowIdsListener<Schemas>,
1034
1153
  ): Id;
1035
1154
 
1036
1155
  /**
1037
1156
  * The delListener method removes a listener that was previously added to the
1038
1157
  * Relationships object.
1039
1158
  *
1159
+ * This has schema-based typing. The following is a simplified representation:
1160
+ *
1161
+ * ```ts override
1162
+ * delListener(listenerId: Id): Relationships;
1163
+ * ```
1164
+ *
1040
1165
  * Use the Id returned by whichever method was used to add the listener. Note
1041
1166
  * that the Relationships object may re-use this Id for future listeners added
1042
1167
  * to it.
@@ -1176,6 +1301,12 @@ export interface Relationships<Schemas extends OptionalSchemas = NoSchemas> {
1176
1301
  * The createRelationships function creates a Relationships object, and is the
1177
1302
  * main entry point into the relationships module.
1178
1303
  *
1304
+ * This has schema-based typing. The following is a simplified representation:
1305
+ *
1306
+ * ```ts override
1307
+ * createRelationships(store: Store): Relationships;
1308
+ * ```
1309
+ *
1179
1310
  * A given Store can only have one Relationships object associated with it. If
1180
1311
  * you call this function twice on the same Store, your second call will return
1181
1312
  * a reference to the Relationships object created by the first.