tinybase 3.1.0-beta.4 → 3.1.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/lib/debug/ui-react.js +2 -2
  2. package/lib/{cjs-es6 → types}/checkpoints.d.ts +11 -13
  3. package/lib/{debug → types}/indexes.d.ts +8 -16
  4. package/lib/{debug → types}/metrics.d.ts +47 -50
  5. package/lib/{cjs → types}/persisters.d.ts +24 -30
  6. package/lib/{cjs-es6 → types}/queries.d.ts +472 -309
  7. package/lib/{debug → types}/relationships.d.ts +9 -17
  8. package/lib/{cjs-es6 → types}/store.d.ts +176 -1084
  9. package/lib/types/tinybase.d.ts +14 -0
  10. package/lib/{cjs-es6 → types}/tools.d.ts +7 -12
  11. package/lib/{debug → types}/ui-react.d.ts +11 -5
  12. package/lib/{checkpoints.d.ts → types/with-schemas/checkpoints.d.ts} +9 -7
  13. package/lib/{cjs → types/with-schemas}/indexes.d.ts +31 -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 +54 -50
  18. package/lib/{debug → types/with-schemas}/persisters.d.ts +4 -4
  19. package/lib/{debug → types/with-schemas}/queries.d.ts +607 -346
  20. package/lib/{cjs → types/with-schemas}/relationships.d.ts +29 -20
  21. package/lib/{debug → types/with-schemas}/store.d.ts +386 -829
  22. package/lib/types/with-schemas/tinybase.d.ts +14 -0
  23. package/lib/{debug → types/with-schemas}/tools.d.ts +7 -10
  24. package/lib/{cjs-es6 → types/with-schemas}/ui-react.d.ts +817 -1314
  25. package/package.json +145 -29
  26. package/readme.md +3 -3
  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,6 +1,6 @@
1
1
  /**
2
- * The metrics module of the TinyBase project provides the ability to create
3
- * and track metrics and aggregates of the data in Store objects.
2
+ * The metrics module of the TinyBase project provides the ability to create and
3
+ * track metrics and aggregates of the data in Store objects.
4
4
  *
5
5
  * The main entry point to this module is the createMetrics function, which
6
6
  * returns a new Metrics object. From there, you can create new Metric
@@ -11,7 +11,8 @@
11
11
  * @module metrics
12
12
  */
13
13
 
14
- import {GetCell, NoSchemas, OptionalSchemas, Store} from './store.d';
14
+ import {CellIdFromSchema, TableIdFromSchema} from './internal/store';
15
+ import {GetCell, OptionalSchemas, Store} from './store.d';
15
16
  import {Id, IdOrNull, Ids} from './common.d';
16
17
 
17
18
  /**
@@ -37,8 +38,8 @@ export type Metric = number;
37
38
  export type MetricCallback = (metricId: Id, metric?: Metric) => void;
38
39
 
39
40
  /**
40
- * The Aggregate type describes a custom function that takes an array of numbers
41
- * and returns an aggregate that is used as a Metric.
41
+ * The MetricAggregate type describes a custom function that takes an array of
42
+ * numbers and returns an aggregate that is used as a Metric.
42
43
  *
43
44
  * There are a number of common predefined aggregators, such as for counting,
44
45
  * summing, and averaging values. This type is instead used for when you wish to
@@ -50,12 +51,12 @@ export type MetricCallback = (metricId: Id, metric?: Metric) => void;
50
51
  * @returns The value of the Metric.
51
52
  * @category Aggregators
52
53
  */
53
- export type Aggregate = (numbers: number[], length: number) => Metric;
54
+ export type MetricAggregate = (numbers: number[], length: number) => Metric;
54
55
 
55
56
  /**
56
- * The AggregateAdd type describes a function that can be used to optimize a
57
- * custom Aggregate by providing a shortcut for when a single value is added to
58
- * the input values.
57
+ * The MetricAggregateAdd type describes a function that can be used to optimize
58
+ * a custom MetricAggregate by providing a shortcut for when a single value is
59
+ * added to the input values.
59
60
  *
60
61
  * Some aggregation functions do not need to recalculate the aggregation of the
61
62
  * whole set when one value changes. For example, when adding a new number to a
@@ -65,10 +66,10 @@ export type Aggregate = (numbers: number[], length: number) => Metric;
65
66
  * being added, return `undefined` and the Metric will be completely
66
67
  * recalculated.
67
68
  *
68
- * Where possible, if you are providing a custom Aggregate, seek an
69
- * implementation of an AggregateAdd function that can reduce the complexity
70
- * cost of growing the input data set. See the setMetricDefinition method for
71
- * more examples.
69
+ * Where possible, if you are providing a custom MetricAggregate, seek an
70
+ * implementation of an MetricAggregateAdd function that can reduce the
71
+ * complexity cost of growing the input data set. See the setMetricDefinition
72
+ * method for more examples.
72
73
  *
73
74
  * @param metric The current value of the Metric.
74
75
  * @param add The number being added to the Metric's aggregation.
@@ -76,16 +77,16 @@ export type Aggregate = (numbers: number[], length: number) => Metric;
76
77
  * @returns The new value of the Metric.
77
78
  * @category Aggregators
78
79
  */
79
- export type AggregateAdd = (
80
+ export type MetricAggregateAdd = (
80
81
  metric: Metric,
81
82
  add: number,
82
83
  length: number,
83
84
  ) => Metric | undefined;
84
85
 
85
86
  /**
86
- * The AggregateRemove type describes a function that can be used to optimize a
87
- * custom Aggregate by providing a shortcut for when a single value is removed
88
- * from the input values.
87
+ * The MetricAggregateRemove type describes a function that can be used to
88
+ * optimize a custom MetricAggregate by providing a shortcut for when a single
89
+ * value is removed from the input values.
89
90
  *
90
91
  * Some aggregation functions do not need to recalculate the aggregation of the
91
92
  * whole set when one value changes. For example, when removing a number from a
@@ -98,10 +99,10 @@ export type AggregateAdd = (
98
99
  * values, and the previous minimum is being removed. The whole of the rest of
99
100
  * the list will need to be re-scanned to find a new minimum.
100
101
  *
101
- * Where possible, if you are providing a custom Aggregate, seek an
102
- * implementation of an AggregateRemove function that can reduce the complexity
103
- * cost of shrinking the input data set. See the setMetricDefinition method for
104
- * more examples.
102
+ * Where possible, if you are providing a custom MetricAggregate, seek an
103
+ * implementation of an MetricAggregateRemove function that can reduce the
104
+ * complexity cost of shrinking the input data set. See the setMetricDefinition
105
+ * method for more examples.
105
106
  *
106
107
  * @param metric The current value of the Metric.
107
108
  * @param remove The number being removed from the Metric's aggregation.
@@ -109,16 +110,16 @@ export type AggregateAdd = (
109
110
  * @returns The new value of the Metric.
110
111
  * @category Aggregators
111
112
  */
112
- export type AggregateRemove = (
113
+ export type MetricAggregateRemove = (
113
114
  metric: Metric,
114
115
  remove: number,
115
116
  length: number,
116
117
  ) => Metric | undefined;
117
118
 
118
119
  /**
119
- * The AggregateReplace type describes a function that can be used to optimize a
120
- * custom Aggregate by providing a shortcut for when a single value in the input
121
- * values is replaced with another.
120
+ * The MetricAggregateReplace type describes a function that can be used to
121
+ * optimize a custom MetricAggregate by providing a shortcut for when a single
122
+ * value in the input values is replaced with another.
122
123
  *
123
124
  * Some aggregation functions do not need to recalculate the aggregation of the
124
125
  * whole set when one value changes. For example, when replacing a number in a
@@ -126,13 +127,12 @@ export type AggregateRemove = (
126
127
  * minus the old value.
127
128
  *
128
129
  * If it is not possible to shortcut the aggregation based on just one value
129
- * changing, return `undefined` and the Metric will be completely
130
- * recalculated.
130
+ * changing, return `undefined` and the Metric will be completely recalculated.
131
131
  *
132
- * Where possible, if you are providing a custom Aggregate, seek an
133
- * implementation of an AggregateReplace function that can reduce the complexity
134
- * cost of changing the input data set in place. See the setMetricDefinition
135
- * method for more examples.
132
+ * Where possible, if you are providing a custom MetricAggregate, seek an
133
+ * implementation of an MetricAggregateReplace function that can reduce the
134
+ * complexity cost of changing the input data set in place. See the
135
+ * setMetricDefinition method for more examples.
136
136
  *
137
137
  * @param metric The current value of the Metric.
138
138
  * @param add The number being added to the Metric's aggregation.
@@ -141,7 +141,7 @@ export type AggregateRemove = (
141
141
  * @returns The new value of the Metric.
142
142
  * @category Aggregators
143
143
  */
144
- export type AggregateReplace = (
144
+ export type MetricAggregateReplace = (
145
145
  metric: Metric,
146
146
  add: number,
147
147
  remove: number,
@@ -168,8 +168,8 @@ export type AggregateReplace = (
168
168
  * @param oldMetric The old value of the Metric that changed.
169
169
  * @category Listener
170
170
  */
171
- export type MetricListener = (
172
- metrics: Metrics,
171
+ export type MetricListener<Schemas extends OptionalSchemas> = (
172
+ metrics: Metrics<Schemas>,
173
173
  metricId: Id,
174
174
  newMetric: Metric | undefined,
175
175
  oldMetric: Metric | undefined,
@@ -246,7 +246,7 @@ export type MetricsListenerStats = {
246
246
  * @see Todo App demos
247
247
  * @category Metrics
248
248
  */
249
- export interface Metrics<Schemas extends OptionalSchemas = NoSchemas> {
249
+ export interface Metrics<in out Schemas extends OptionalSchemas> {
250
250
  /**
251
251
  * The setMetricDefinition method lets you set the definition of a Metric.
252
252
  *
@@ -287,14 +287,14 @@ export interface Metrics<Schemas extends OptionalSchemas = NoSchemas> {
287
287
  * that if the `aggregate` and `getNumber` parameters are both omitted, the
288
288
  * Metric will simply be a count of the Row objects in the Table).
289
289
  * @param aggregateAdd A function that can be used to optimize a custom
290
- * Aggregate by providing a shortcut for when a single value is added to the
291
- * input values - for example, when a Row is added to the Table.
290
+ * MetricAggregate by providing a shortcut for when a single value is added to
291
+ * the input values - for example, when a Row is added to the Table.
292
292
  * @param aggregateRemove A function that can be used to optimize a custom
293
- * Aggregate by providing a shortcut for when a single value is removed from
294
- * the input values - for example ,when a Row is removed from the Table.
293
+ * MetricAggregate by providing a shortcut for when a single value is removed
294
+ * from the input values - for example ,when a Row is removed from the Table.
295
295
  * @param aggregateReplace A function that can be used to optimize a custom
296
- * Aggregate by providing a shortcut for when a single value in the input
297
- * values is replaced with another - for example, when a Row is updated.
296
+ * MetricAggregate by providing a shortcut for when a single value in the
297
+ * input values is replaced with another - for example, when a Row is updated.
298
298
  * @returns A reference to the Metrics object.
299
299
  * @example
300
300
  * This example creates a Store, creates a Metrics object, and defines a
@@ -412,14 +412,16 @@ export interface Metrics<Schemas extends OptionalSchemas = NoSchemas> {
412
412
  * ```
413
413
  * @category Configuration
414
414
  */
415
- setMetricDefinition(
415
+ setMetricDefinition<TableId extends TableIdFromSchema<Schemas[0]>>(
416
416
  metricId: Id,
417
- tableId: Id,
418
- aggregate?: 'sum' | 'avg' | 'min' | 'max' | Aggregate,
419
- getNumber?: Id | ((getCell: GetCell, rowId: Id) => number),
420
- aggregateAdd?: AggregateAdd,
421
- aggregateRemove?: AggregateRemove,
422
- aggregateReplace?: AggregateReplace,
417
+ tableId: TableId,
418
+ aggregate?: 'sum' | 'avg' | 'min' | 'max' | MetricAggregate,
419
+ getNumber?:
420
+ | CellIdFromSchema<Schemas[0], TableId>
421
+ | ((getCell: GetCell<Schemas[0], TableId>, rowId: Id) => number),
422
+ aggregateAdd?: MetricAggregateAdd,
423
+ aggregateRemove?: MetricAggregateRemove,
424
+ aggregateReplace?: MetricAggregateReplace,
423
425
  ): Metrics<Schemas>;
424
426
 
425
427
  /**
@@ -573,7 +575,9 @@ export interface Metrics<Schemas extends OptionalSchemas = NoSchemas> {
573
575
  * ```
574
576
  * @category Getter
575
577
  */
576
- getTableId(metricId: Id): Id | undefined;
578
+ getTableId<TableId extends TableIdFromSchema<Schemas[0]>>(
579
+ metricId: Id,
580
+ ): TableId | undefined;
577
581
 
578
582
  /**
579
583
  * The getMetric method gets the current value of a Metric.
@@ -686,7 +690,7 @@ export interface Metrics<Schemas extends OptionalSchemas = NoSchemas> {
686
690
  * ```
687
691
  * @category Listener
688
692
  */
689
- addMetricListener(metricId: IdOrNull, listener: MetricListener): Id;
693
+ addMetricListener(metricId: IdOrNull, listener: MetricListener<Schemas>): Id;
690
694
 
691
695
  /**
692
696
  * The delListener method removes a listener that was previously added to the
@@ -27,7 +27,7 @@
27
27
  * @module persisters
28
28
  */
29
29
 
30
- import {NoSchemas, OptionalSchemas, Store, Tables, Values} from './store.d';
30
+ import {OptionalSchemas, Store, Tables, Values} from './store.d';
31
31
  import {Callback} from './common.d';
32
32
 
33
33
  /**
@@ -145,7 +145,7 @@ export type PersisterStats = {
145
145
  * ```
146
146
  * @category Persister
147
147
  */
148
- export interface Persister<Schemas extends OptionalSchemas = NoSchemas> {
148
+ export interface Persister<in out Schemas extends OptionalSchemas> {
149
149
  /**
150
150
  * The load method gets persisted data from storage, and loads it into the
151
151
  * Store with which the Persister is associated, once.
@@ -208,7 +208,7 @@ export interface Persister<Schemas extends OptionalSchemas = NoSchemas> {
208
208
  */
209
209
  load(
210
210
  initialTables?: Tables<Schemas[0], true>,
211
- initialValues?: Values,
211
+ initialValues?: Values<Schemas[1], true>,
212
212
  ): Promise<Persister<Schemas>>;
213
213
 
214
214
  /**
@@ -267,7 +267,7 @@ export interface Persister<Schemas extends OptionalSchemas = NoSchemas> {
267
267
  */
268
268
  startAutoLoad(
269
269
  initialTables?: Tables<Schemas[0], true>,
270
- initialValues?: Values,
270
+ initialValues?: Values<Schemas[1], true>,
271
271
  ): Promise<Persister<Schemas>>;
272
272
 
273
273
  /**