tinybase 9.1.0-beta.1 → 9.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.
- package/@types/_internal/store/with-schemas/index.d.ts +133 -2
- package/@types/indexes/index.d.ts +97 -0
- package/@types/indexes/with-schemas/index.d.ts +137 -0
- package/@types/store/index.d.ts +96 -18
- package/@types/store/with-schemas/index.d.ts +107 -44
- package/@types/ui-react/index.d.ts +42 -0
- package/@types/ui-react/with-schemas/index.d.ts +101 -32
- package/@types/ui-react-dom/index.d.ts +10 -10
- package/@types/ui-react-dom/with-schemas/index.d.ts +10 -10
- package/@types/ui-react-dom-charts/index.d.ts +7 -7
- package/@types/ui-react-dom-charts/with-schemas/index.d.ts +7 -7
- package/@types/ui-react-inspector/index.d.ts +1 -1
- package/@types/ui-react-inspector/with-schemas/index.d.ts +1 -1
- package/@types/ui-solid/index.d.ts +42 -0
- package/@types/ui-solid/with-schemas/index.d.ts +101 -32
- package/@types/ui-solid-dom/index.d.ts +10 -10
- package/@types/ui-solid-dom/with-schemas/index.d.ts +10 -10
- package/@types/ui-solid-inspector/index.d.ts +1 -1
- package/@types/ui-solid-inspector/with-schemas/index.d.ts +1 -1
- package/@types/ui-svelte/index.d.ts +34 -0
- package/@types/ui-svelte/with-schemas/index.d.ts +34 -0
- package/@types/ui-svelte-dom/index.d.ts +10 -10
- package/@types/ui-svelte-dom/with-schemas/index.d.ts +10 -10
- package/@types/ui-svelte-inspector/index.d.ts +1 -1
- package/@types/ui-svelte-inspector/with-schemas/index.d.ts +1 -1
- package/index.js +121 -32
- package/indexes/index.js +39 -0
- package/indexes/with-schemas/index.js +39 -0
- package/mergeable-store/index.js +82 -32
- package/mergeable-store/with-schemas/index.js +82 -32
- package/min/index.js +1 -1
- package/min/index.js.gz +0 -0
- package/min/indexes/index.js +1 -1
- package/min/indexes/index.js.gz +0 -0
- package/min/indexes/with-schemas/index.js +1 -1
- package/min/indexes/with-schemas/index.js.gz +0 -0
- package/min/mergeable-store/index.js +1 -1
- package/min/mergeable-store/index.js.gz +0 -0
- package/min/mergeable-store/with-schemas/index.js +1 -1
- package/min/mergeable-store/with-schemas/index.js.gz +0 -0
- package/min/omni/index.js +1 -1
- package/min/omni/index.js.gz +0 -0
- package/min/omni/with-schemas/index.js +1 -1
- package/min/omni/with-schemas/index.js.gz +0 -0
- package/min/store/index.js +1 -1
- package/min/store/index.js.gz +0 -0
- package/min/store/with-schemas/index.js +1 -1
- package/min/store/with-schemas/index.js.gz +0 -0
- package/min/ui-react/index.js +1 -1
- package/min/ui-react/index.js.gz +0 -0
- package/min/ui-react/with-schemas/index.js +1 -1
- package/min/ui-react/with-schemas/index.js.gz +0 -0
- package/min/ui-react-inspector/index.js +1 -1
- package/min/ui-react-inspector/index.js.gz +0 -0
- package/min/ui-react-inspector/with-schemas/index.js +1 -1
- package/min/ui-react-inspector/with-schemas/index.js.gz +0 -0
- package/min/ui-solid/index.js +1 -1
- package/min/ui-solid/index.js.gz +0 -0
- package/min/ui-solid/with-schemas/index.js +1 -1
- package/min/ui-solid/with-schemas/index.js.gz +0 -0
- package/min/ui-solid-inspector/index.js +1 -1
- package/min/ui-solid-inspector/index.js.gz +0 -0
- package/min/ui-solid-inspector/with-schemas/index.js +1 -1
- package/min/ui-solid-inspector/with-schemas/index.js.gz +0 -0
- package/min/ui-svelte/index.js +1 -1
- package/min/ui-svelte/index.js.gz +0 -0
- package/min/ui-svelte/with-schemas/index.js +1 -1
- package/min/ui-svelte/with-schemas/index.js.gz +0 -0
- package/min/ui-svelte-inspector/index.js +1 -1
- package/min/ui-svelte-inspector/index.js.gz +0 -0
- package/min/ui-svelte-inspector/with-schemas/index.js +1 -1
- package/min/ui-svelte-inspector/with-schemas/index.js.gz +0 -0
- package/min/with-schemas/index.js +1 -1
- package/min/with-schemas/index.js.gz +0 -0
- package/omni/index.js +121 -32
- package/omni/with-schemas/index.js +121 -32
- package/package.json +5 -5
- package/readme.md +14 -14
- package/releases.md +101 -60
- package/store/index.js +82 -32
- package/store/with-schemas/index.js +82 -32
- package/ui-react/index.js +16 -0
- package/ui-react/with-schemas/index.js +16 -0
- package/ui-react-inspector/index.js +82 -32
- package/ui-react-inspector/with-schemas/index.js +82 -32
- package/ui-solid/index.js +16 -0
- package/ui-solid/with-schemas/index.js +16 -0
- package/ui-solid-inspector/index.js +82 -32
- package/ui-solid-inspector/with-schemas/index.js +82 -32
- package/ui-svelte/index.js +18 -0
- package/ui-svelte/with-schemas/index.js +18 -0
- package/ui-svelte-inspector/index.js +82 -32
- package/ui-svelte-inspector/with-schemas/index.js +82 -32
- package/with-schemas/index.js +121 -32
|
@@ -33,6 +33,53 @@ export type DefaultCellIdFromSchema<
|
|
|
33
33
|
}[CellIdFromSchema<Schema, TableId>]
|
|
34
34
|
>;
|
|
35
35
|
|
|
36
|
+
export type RequiredCellIdFromSchema<
|
|
37
|
+
Schema extends OptionalTablesSchema,
|
|
38
|
+
TableId extends TableIdFromSchema<Schema>,
|
|
39
|
+
IsRequired extends boolean = true,
|
|
40
|
+
> = AsId<
|
|
41
|
+
{
|
|
42
|
+
[CellId in CellIdFromSchema<Schema, TableId>]: CellIsRequiredFromSchema<
|
|
43
|
+
Schema,
|
|
44
|
+
TableId,
|
|
45
|
+
CellId,
|
|
46
|
+
IsRequired extends true ? CellId : never,
|
|
47
|
+
IsRequired extends true ? never : CellId
|
|
48
|
+
>;
|
|
49
|
+
}[CellIdFromSchema<Schema, TableId>]
|
|
50
|
+
>;
|
|
51
|
+
|
|
52
|
+
export type PresentCellIdFromSchema<
|
|
53
|
+
Schema extends OptionalTablesSchema,
|
|
54
|
+
TableId extends TableIdFromSchema<Schema>,
|
|
55
|
+
IsPresent extends boolean = true,
|
|
56
|
+
> = AsId<
|
|
57
|
+
{
|
|
58
|
+
[CellId in CellIdFromSchema<Schema, TableId>]: CellIsPresentFromSchema<
|
|
59
|
+
Schema,
|
|
60
|
+
TableId,
|
|
61
|
+
CellId,
|
|
62
|
+
IsPresent extends true ? CellId : never,
|
|
63
|
+
IsPresent extends true ? never : CellId
|
|
64
|
+
>;
|
|
65
|
+
}[CellIdFromSchema<Schema, TableId>]
|
|
66
|
+
>;
|
|
67
|
+
|
|
68
|
+
export type RequiredNonDefaultCellIdFromSchema<
|
|
69
|
+
Schema extends OptionalTablesSchema,
|
|
70
|
+
TableId extends TableIdFromSchema<Schema>,
|
|
71
|
+
> = AsId<
|
|
72
|
+
{
|
|
73
|
+
[CellId in CellIdFromSchema<Schema, TableId>]: CellIsRequiredFromSchema<
|
|
74
|
+
Schema,
|
|
75
|
+
TableId,
|
|
76
|
+
CellId,
|
|
77
|
+
CellIsDefaultedFromSchema<Schema, TableId, CellId, never, CellId>,
|
|
78
|
+
never
|
|
79
|
+
>;
|
|
80
|
+
}[CellIdFromSchema<Schema, TableId>]
|
|
81
|
+
>;
|
|
82
|
+
|
|
36
83
|
export type AllCellIdFromSchema<
|
|
37
84
|
Schema extends OptionalTablesSchema,
|
|
38
85
|
TableId extends TableIdFromSchema<Schema> = TableIdFromSchema<Schema>,
|
|
@@ -53,13 +100,39 @@ export type CellIsDefaultedFromSchema<
|
|
|
53
100
|
? Then
|
|
54
101
|
: Else;
|
|
55
102
|
|
|
103
|
+
export type CellIsRequiredFromSchema<
|
|
104
|
+
Schema extends OptionalTablesSchema,
|
|
105
|
+
TableId extends TableIdFromSchema<Schema>,
|
|
106
|
+
CellId extends CellIdFromSchema<Schema, TableId>,
|
|
107
|
+
Then,
|
|
108
|
+
Else,
|
|
109
|
+
> = Schema[TableId][CellId] extends {
|
|
110
|
+
required: true;
|
|
111
|
+
}
|
|
112
|
+
? Then
|
|
113
|
+
: Else;
|
|
114
|
+
|
|
115
|
+
export type CellIsPresentFromSchema<
|
|
116
|
+
Schema extends OptionalTablesSchema,
|
|
117
|
+
TableId extends TableIdFromSchema<Schema>,
|
|
118
|
+
CellId extends CellIdFromSchema<Schema, TableId>,
|
|
119
|
+
Then,
|
|
120
|
+
Else,
|
|
121
|
+
> = CellIsDefaultedFromSchema<
|
|
122
|
+
Schema,
|
|
123
|
+
TableId,
|
|
124
|
+
CellId,
|
|
125
|
+
Then,
|
|
126
|
+
CellIsRequiredFromSchema<Schema, TableId, CellId, Then, Else>
|
|
127
|
+
>;
|
|
128
|
+
|
|
56
129
|
export type DefaultedCellFromSchema<
|
|
57
130
|
Schema extends OptionalTablesSchema,
|
|
58
131
|
TableId extends TableIdFromSchema<Schema>,
|
|
59
132
|
CellId extends CellIdFromSchema<Schema, TableId>,
|
|
60
133
|
> =
|
|
61
134
|
| Cell<Schema, TableId, CellId>
|
|
62
|
-
|
|
|
135
|
+
| CellIsPresentFromSchema<Schema, TableId, CellId, never, undefined>;
|
|
63
136
|
|
|
64
137
|
export type ValueIdFromSchema<Schema extends OptionalValuesSchema> = AsId<
|
|
65
138
|
keyof Schema
|
|
@@ -77,6 +150,41 @@ export type DefaultValueIdFromSchema<
|
|
|
77
150
|
>;
|
|
78
151
|
}[ValueIdFromSchema<Schema>];
|
|
79
152
|
|
|
153
|
+
export type RequiredValueIdFromSchema<
|
|
154
|
+
Schema extends OptionalValuesSchema,
|
|
155
|
+
IsRequired extends boolean = true,
|
|
156
|
+
> = {
|
|
157
|
+
[ValueId in ValueIdFromSchema<Schema>]: ValueIsRequiredFromSchema<
|
|
158
|
+
Schema,
|
|
159
|
+
ValueId,
|
|
160
|
+
IsRequired extends true ? ValueId : never,
|
|
161
|
+
IsRequired extends true ? never : ValueId
|
|
162
|
+
>;
|
|
163
|
+
}[ValueIdFromSchema<Schema>];
|
|
164
|
+
|
|
165
|
+
export type PresentValueIdFromSchema<
|
|
166
|
+
Schema extends OptionalValuesSchema,
|
|
167
|
+
IsPresent extends boolean = true,
|
|
168
|
+
> = {
|
|
169
|
+
[ValueId in ValueIdFromSchema<Schema>]: ValueIsPresentFromSchema<
|
|
170
|
+
Schema,
|
|
171
|
+
ValueId,
|
|
172
|
+
IsPresent extends true ? ValueId : never,
|
|
173
|
+
IsPresent extends true ? never : ValueId
|
|
174
|
+
>;
|
|
175
|
+
}[ValueIdFromSchema<Schema>];
|
|
176
|
+
|
|
177
|
+
export type RequiredNonDefaultValueIdFromSchema<
|
|
178
|
+
Schema extends OptionalValuesSchema,
|
|
179
|
+
> = {
|
|
180
|
+
[ValueId in ValueIdFromSchema<Schema>]: ValueIsRequiredFromSchema<
|
|
181
|
+
Schema,
|
|
182
|
+
ValueId,
|
|
183
|
+
ValueIsDefaultedFromSchema<Schema, ValueId, never, ValueId>,
|
|
184
|
+
never
|
|
185
|
+
>;
|
|
186
|
+
}[ValueIdFromSchema<Schema>];
|
|
187
|
+
|
|
80
188
|
export type ValueIsDefaultedFromSchema<
|
|
81
189
|
Schema extends OptionalValuesSchema,
|
|
82
190
|
ValueId extends ValueIdFromSchema<Schema>,
|
|
@@ -88,12 +196,35 @@ export type ValueIsDefaultedFromSchema<
|
|
|
88
196
|
? Then
|
|
89
197
|
: Else;
|
|
90
198
|
|
|
199
|
+
export type ValueIsRequiredFromSchema<
|
|
200
|
+
Schema extends OptionalValuesSchema,
|
|
201
|
+
ValueId extends ValueIdFromSchema<Schema>,
|
|
202
|
+
Then,
|
|
203
|
+
Else,
|
|
204
|
+
> = Schema[ValueId] extends {
|
|
205
|
+
required: true;
|
|
206
|
+
}
|
|
207
|
+
? Then
|
|
208
|
+
: Else;
|
|
209
|
+
|
|
210
|
+
export type ValueIsPresentFromSchema<
|
|
211
|
+
Schema extends OptionalValuesSchema,
|
|
212
|
+
ValueId extends ValueIdFromSchema<Schema>,
|
|
213
|
+
Then,
|
|
214
|
+
Else,
|
|
215
|
+
> = ValueIsDefaultedFromSchema<
|
|
216
|
+
Schema,
|
|
217
|
+
ValueId,
|
|
218
|
+
Then,
|
|
219
|
+
ValueIsRequiredFromSchema<Schema, ValueId, Then, Else>
|
|
220
|
+
>;
|
|
221
|
+
|
|
91
222
|
export type DefaultedValueFromSchema<
|
|
92
223
|
Schema extends OptionalValuesSchema,
|
|
93
224
|
ValueId extends ValueIdFromSchema<Schema>,
|
|
94
225
|
> =
|
|
95
226
|
| Value<Schema, ValueId>
|
|
96
|
-
|
|
|
227
|
+
| ValueIsPresentFromSchema<Schema, ValueId, never, undefined>;
|
|
97
228
|
|
|
98
229
|
export type AsId<Key> = Exclude<Key & Id, number>;
|
|
99
230
|
|
|
@@ -92,6 +92,27 @@ export type SliceCallback = (
|
|
|
92
92
|
*/
|
|
93
93
|
export type IndexIdsListener = (indexes: Indexes) => void;
|
|
94
94
|
|
|
95
|
+
/**
|
|
96
|
+
* The HasIndexListener type describes a function that is used to listen to
|
|
97
|
+
* Index definitions being added or removed.
|
|
98
|
+
*
|
|
99
|
+
* A HasIndexListener is provided when using the addHasIndexListener method.
|
|
100
|
+
* See that method for specific examples.
|
|
101
|
+
*
|
|
102
|
+
* When called, a HasIndexListener is given a reference to the Indexes object,
|
|
103
|
+
* the Id of the Index that changed, and whether it now exists.
|
|
104
|
+
* @param indexes A reference to the Indexes object that changed.
|
|
105
|
+
* @param indexId The Id of the Index that changed.
|
|
106
|
+
* @param hasIndex Whether the Index now exists.
|
|
107
|
+
* @category Listener
|
|
108
|
+
* @since v9.1.0
|
|
109
|
+
*/
|
|
110
|
+
export type HasIndexListener = (
|
|
111
|
+
indexes: Indexes,
|
|
112
|
+
indexId: Id,
|
|
113
|
+
hasIndex: boolean,
|
|
114
|
+
) => void;
|
|
115
|
+
|
|
95
116
|
/**
|
|
96
117
|
* The SliceIdsListener type describes a function that is used to listen to
|
|
97
118
|
* changes to the Slice Ids in an Index.
|
|
@@ -108,6 +129,30 @@ export type IndexIdsListener = (indexes: Indexes) => void;
|
|
|
108
129
|
*/
|
|
109
130
|
export type SliceIdsListener = (indexes: Indexes, indexId: Id) => void;
|
|
110
131
|
|
|
132
|
+
/**
|
|
133
|
+
* The HasSliceListener type describes a function that is used to listen to
|
|
134
|
+
* Slices being added to or removed from an Index.
|
|
135
|
+
*
|
|
136
|
+
* A HasSliceListener is provided when using the addHasSliceListener method. See
|
|
137
|
+
* that method for specific examples.
|
|
138
|
+
*
|
|
139
|
+
* When called, a HasSliceListener is given a reference to the Indexes object,
|
|
140
|
+
* the Id of the Index that changed, the Id of the Slice that changed, and
|
|
141
|
+
* whether it now exists.
|
|
142
|
+
* @param indexes A reference to the Indexes object that changed.
|
|
143
|
+
* @param indexId The Id of the Index that changed.
|
|
144
|
+
* @param sliceId The Id of the Slice that changed.
|
|
145
|
+
* @param hasSlice Whether the Slice now exists.
|
|
146
|
+
* @category Listener
|
|
147
|
+
* @since v9.1.0
|
|
148
|
+
*/
|
|
149
|
+
export type HasSliceListener = (
|
|
150
|
+
indexes: Indexes,
|
|
151
|
+
indexId: Id,
|
|
152
|
+
sliceId: Id,
|
|
153
|
+
hasSlice: boolean,
|
|
154
|
+
) => void;
|
|
155
|
+
|
|
111
156
|
/**
|
|
112
157
|
* The SliceRowIdsListener type describes a function that is used to listen to
|
|
113
158
|
* changes to the Row Ids in a Slice.
|
|
@@ -812,6 +857,27 @@ export interface Indexes {
|
|
|
812
857
|
*/
|
|
813
858
|
addIndexIdsListener(listener: IndexIdsListener): Id;
|
|
814
859
|
|
|
860
|
+
/**
|
|
861
|
+
* The addHasIndexListener method registers a listener function with the
|
|
862
|
+
* Indexes object that will be called whenever an Index definition is added or
|
|
863
|
+
* removed.
|
|
864
|
+
*
|
|
865
|
+
* You can either listen to a single Index (by specifying the Index Id as the
|
|
866
|
+
* method's first parameter), or changes to any Index (by providing a `null`
|
|
867
|
+
* wildcard).
|
|
868
|
+
*
|
|
869
|
+
* The provided listener is a HasIndexListener function, and will be called
|
|
870
|
+
* with a reference to the Indexes object, the Id of the Index that changed,
|
|
871
|
+
* and whether it now exists.
|
|
872
|
+
* @param indexId The Id of the Index to listen to, or `null` as a wildcard.
|
|
873
|
+
* @param listener The function that will be called whenever the Index is
|
|
874
|
+
* added or removed.
|
|
875
|
+
* @returns A unique Id for the listener that can later be used to remove it.
|
|
876
|
+
* @category Listener
|
|
877
|
+
* @since v9.1.0
|
|
878
|
+
*/
|
|
879
|
+
addHasIndexListener(indexId: IdOrNull, listener: HasIndexListener): Id;
|
|
880
|
+
|
|
815
881
|
/**
|
|
816
882
|
* The addSliceRowIdsListener method registers a listener function with the
|
|
817
883
|
* Indexes object that will be called whenever the Row Ids in a Slice change.
|
|
@@ -909,6 +975,37 @@ export interface Indexes {
|
|
|
909
975
|
listener: SliceRowIdsListener,
|
|
910
976
|
): Id;
|
|
911
977
|
|
|
978
|
+
/**
|
|
979
|
+
* The addHasSliceListener method registers a listener function with the
|
|
980
|
+
* Indexes object that will be called whenever a Slice is added to or removed
|
|
981
|
+
* from an Index.
|
|
982
|
+
*
|
|
983
|
+
* You can either listen to a single Slice (by specifying the Index Id and
|
|
984
|
+
* Slice Id as the method's first two parameters), or changes to any Slice (by
|
|
985
|
+
* providing `null` wildcards).
|
|
986
|
+
*
|
|
987
|
+
* Both, either, or neither of the `indexId` and `sliceId` parameters can be
|
|
988
|
+
* wildcarded with `null`. You can listen to a specific Slice in a specific
|
|
989
|
+
* Index, any Slice in a specific Index, a specific Slice in any Index, or any
|
|
990
|
+
* Slice in any Index.
|
|
991
|
+
*
|
|
992
|
+
* The provided listener is a HasSliceListener function, and will be called
|
|
993
|
+
* with a reference to the Indexes object, the Id of the Index, the Id of the
|
|
994
|
+
* Slice that changed, and whether it now exists.
|
|
995
|
+
* @param indexId The Id of the Index to listen to, or `null` as a wildcard.
|
|
996
|
+
* @param sliceId The Id of the Slice to listen to, or `null` as a wildcard.
|
|
997
|
+
* @param listener The function that will be called whenever the Slice is
|
|
998
|
+
* added or removed.
|
|
999
|
+
* @returns A unique Id for the listener that can later be used to remove it.
|
|
1000
|
+
* @category Listener
|
|
1001
|
+
* @since v9.1.0
|
|
1002
|
+
*/
|
|
1003
|
+
addHasSliceListener(
|
|
1004
|
+
indexId: IdOrNull,
|
|
1005
|
+
sliceId: IdOrNull,
|
|
1006
|
+
listener: HasSliceListener,
|
|
1007
|
+
): Id;
|
|
1008
|
+
|
|
912
1009
|
/**
|
|
913
1010
|
* The delListener method removes a listener that was previously added to the
|
|
914
1011
|
* Indexes object.
|
|
@@ -133,6 +133,37 @@ export type IndexIdsListener<Schemas extends OptionalSchemas> = (
|
|
|
133
133
|
indexes: Indexes<Schemas>,
|
|
134
134
|
) => void;
|
|
135
135
|
|
|
136
|
+
/**
|
|
137
|
+
* The HasIndexListener type describes a function that is used to listen to
|
|
138
|
+
* Index definitions being added or removed.
|
|
139
|
+
*
|
|
140
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
141
|
+
*
|
|
142
|
+
* ```ts override
|
|
143
|
+
* (
|
|
144
|
+
* indexes: Indexes,
|
|
145
|
+
* indexId: Id,
|
|
146
|
+
* hasIndex: boolean,
|
|
147
|
+
* ) => void;
|
|
148
|
+
* ```
|
|
149
|
+
*
|
|
150
|
+
* A HasIndexListener is provided when using the addHasIndexListener method.
|
|
151
|
+
* See that method for specific examples.
|
|
152
|
+
*
|
|
153
|
+
* When called, a HasIndexListener is given a reference to the Indexes object,
|
|
154
|
+
* the Id of the Index that changed, and whether it now exists.
|
|
155
|
+
* @param indexes A reference to the Indexes object that changed.
|
|
156
|
+
* @param indexId The Id of the Index that changed.
|
|
157
|
+
* @param hasIndex Whether the Index now exists.
|
|
158
|
+
* @category Listener
|
|
159
|
+
* @since v9.1.0
|
|
160
|
+
*/
|
|
161
|
+
export type HasIndexListener<Schemas extends OptionalSchemas> = (
|
|
162
|
+
indexes: Indexes<Schemas>,
|
|
163
|
+
indexId: Id,
|
|
164
|
+
hasIndex: boolean,
|
|
165
|
+
) => void;
|
|
166
|
+
|
|
136
167
|
/**
|
|
137
168
|
* The SliceIdsListener type describes a function that is used to listen to
|
|
138
169
|
* changes to the Slice Ids in an Index.
|
|
@@ -158,6 +189,41 @@ export type SliceIdsListener<Schemas extends OptionalSchemas> = (
|
|
|
158
189
|
indexId: Id,
|
|
159
190
|
) => void;
|
|
160
191
|
|
|
192
|
+
/**
|
|
193
|
+
* The HasSliceListener type describes a function that is used to listen to
|
|
194
|
+
* Slices being added to or removed from an Index.
|
|
195
|
+
*
|
|
196
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
197
|
+
*
|
|
198
|
+
* ```ts override
|
|
199
|
+
* (
|
|
200
|
+
* indexes: Indexes,
|
|
201
|
+
* indexId: Id,
|
|
202
|
+
* sliceId: Id,
|
|
203
|
+
* hasSlice: boolean,
|
|
204
|
+
* ) => void;
|
|
205
|
+
* ```
|
|
206
|
+
*
|
|
207
|
+
* A HasSliceListener is provided when using the addHasSliceListener method. See
|
|
208
|
+
* that method for specific examples.
|
|
209
|
+
*
|
|
210
|
+
* When called, a HasSliceListener is given a reference to the Indexes object,
|
|
211
|
+
* the Id of the Index that changed, the Id of the Slice that changed, and
|
|
212
|
+
* whether it now exists.
|
|
213
|
+
* @param indexes A reference to the Indexes object that changed.
|
|
214
|
+
* @param indexId The Id of the Index that changed.
|
|
215
|
+
* @param sliceId The Id of the Slice that changed.
|
|
216
|
+
* @param hasSlice Whether the Slice now exists.
|
|
217
|
+
* @category Listener
|
|
218
|
+
* @since v9.1.0
|
|
219
|
+
*/
|
|
220
|
+
export type HasSliceListener<Schemas extends OptionalSchemas> = (
|
|
221
|
+
indexes: Indexes<Schemas>,
|
|
222
|
+
indexId: Id,
|
|
223
|
+
sliceId: Id,
|
|
224
|
+
hasSlice: boolean,
|
|
225
|
+
) => void;
|
|
226
|
+
|
|
161
227
|
/**
|
|
162
228
|
* The SliceRowIdsListener type describes a function that is used to listen to
|
|
163
229
|
* changes to the Row Ids in a Slice.
|
|
@@ -845,6 +911,36 @@ export interface Indexes<in out Schemas extends OptionalSchemas> {
|
|
|
845
911
|
*/
|
|
846
912
|
addIndexIdsListener(listener: IndexIdsListener<Schemas>): Id;
|
|
847
913
|
|
|
914
|
+
/**
|
|
915
|
+
* The addHasIndexListener method registers a listener function with the
|
|
916
|
+
* Indexes object that will be called whenever an Index definition is added or
|
|
917
|
+
* removed.
|
|
918
|
+
*
|
|
919
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
920
|
+
*
|
|
921
|
+
* ```ts override
|
|
922
|
+
* addHasIndexListener(indexId: IdOrNull, listener: HasIndexListener): Id;
|
|
923
|
+
* ```
|
|
924
|
+
*
|
|
925
|
+
* You can either listen to a single Index (by specifying the Index Id as the
|
|
926
|
+
* method's first parameter), or changes to any Index (by providing a `null`
|
|
927
|
+
* wildcard).
|
|
928
|
+
*
|
|
929
|
+
* The provided listener is a HasIndexListener function, and will be called
|
|
930
|
+
* with a reference to the Indexes object, the Id of the Index that changed,
|
|
931
|
+
* and whether it now exists.
|
|
932
|
+
* @param indexId The Id of the Index to listen to, or `null` as a wildcard.
|
|
933
|
+
* @param listener The function that will be called whenever the Index is
|
|
934
|
+
* added or removed.
|
|
935
|
+
* @returns A unique Id for the listener that can later be used to remove it.
|
|
936
|
+
* @category Listener
|
|
937
|
+
* @since v9.1.0
|
|
938
|
+
*/
|
|
939
|
+
addHasIndexListener(
|
|
940
|
+
indexId: IdOrNull,
|
|
941
|
+
listener: HasIndexListener<Schemas>,
|
|
942
|
+
): Id;
|
|
943
|
+
|
|
848
944
|
/**
|
|
849
945
|
* The addSliceIdsListener method registers a listener function with the
|
|
850
946
|
* Indexes object that will be called whenever the Slice Ids in an Index
|
|
@@ -1042,6 +1138,47 @@ export interface Indexes<in out Schemas extends OptionalSchemas> {
|
|
|
1042
1138
|
listener: SliceRowIdsListener<Schemas>,
|
|
1043
1139
|
): Id;
|
|
1044
1140
|
|
|
1141
|
+
/**
|
|
1142
|
+
* The addHasSliceListener method registers a listener function with the
|
|
1143
|
+
* Indexes object that will be called whenever a Slice is added to or removed
|
|
1144
|
+
* from an Index.
|
|
1145
|
+
*
|
|
1146
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
1147
|
+
*
|
|
1148
|
+
* ```ts override
|
|
1149
|
+
* addHasSliceListener(
|
|
1150
|
+
* indexId: IdOrNull,
|
|
1151
|
+
* sliceId: IdOrNull,
|
|
1152
|
+
* listener: HasSliceListener,
|
|
1153
|
+
* ): Id;
|
|
1154
|
+
* ```
|
|
1155
|
+
*
|
|
1156
|
+
* You can either listen to a single Slice (by specifying the Index Id and
|
|
1157
|
+
* Slice Id as the method's first two parameters), or changes to any Slice (by
|
|
1158
|
+
* providing `null` wildcards).
|
|
1159
|
+
*
|
|
1160
|
+
* Both, either, or neither of the `indexId` and `sliceId` parameters can be
|
|
1161
|
+
* wildcarded with `null`. You can listen to a specific Slice in a specific
|
|
1162
|
+
* Index, any Slice in a specific Index, a specific Slice in any Index, or any
|
|
1163
|
+
* Slice in any Index.
|
|
1164
|
+
*
|
|
1165
|
+
* The provided listener is a HasSliceListener function, and will be called
|
|
1166
|
+
* with a reference to the Indexes object, the Id of the Index, the Id of the
|
|
1167
|
+
* Slice that changed, and whether it now exists.
|
|
1168
|
+
* @param indexId The Id of the Index to listen to, or `null` as a wildcard.
|
|
1169
|
+
* @param sliceId The Id of the Slice to listen to, or `null` as a wildcard.
|
|
1170
|
+
* @param listener The function that will be called whenever the Slice is
|
|
1171
|
+
* added or removed.
|
|
1172
|
+
* @returns A unique Id for the listener that can later be used to remove it.
|
|
1173
|
+
* @category Listener
|
|
1174
|
+
* @since v9.1.0
|
|
1175
|
+
*/
|
|
1176
|
+
addHasSliceListener(
|
|
1177
|
+
indexId: IdOrNull,
|
|
1178
|
+
sliceId: IdOrNull,
|
|
1179
|
+
listener: HasSliceListener<Schemas>,
|
|
1180
|
+
): Id;
|
|
1181
|
+
|
|
1045
1182
|
/**
|
|
1046
1183
|
* The delListener method removes a listener that was previously added to the
|
|
1047
1184
|
* Indexes object.
|
package/@types/store/index.d.ts
CHANGED
|
@@ -61,11 +61,13 @@ export type TablesSchema = {[tableId: Id]: {[cellId: Id]: CellSchema}};
|
|
|
61
61
|
* object or array Cell directly, and get back the same structure.
|
|
62
62
|
*
|
|
63
63
|
* If a default value is provided (and its type is correct), you can be certain
|
|
64
|
-
* that that Cell will always be present in a Row.
|
|
64
|
+
* that that Cell will always be present in a Row. You can also set `required`
|
|
65
|
+
* to `true` to indicate to schema-based typing that the Cell should be present
|
|
66
|
+
* even if it does not have a default.
|
|
65
67
|
*
|
|
66
|
-
* If
|
|
67
|
-
*
|
|
68
|
-
*
|
|
68
|
+
* If neither a default value nor `required: true` is provided, the Cell may be
|
|
69
|
+
* missing from the Row, but when present you can be guaranteed it is of the
|
|
70
|
+
* correct type.
|
|
69
71
|
* @example
|
|
70
72
|
* When applied to a Store, this CellSchema ensures a boolean Cell is always
|
|
71
73
|
* present, and defaults it to `false`.
|
|
@@ -79,6 +81,18 @@ export type TablesSchema = {[tableId: Id]: {[cellId: Id]: CellSchema}};
|
|
|
79
81
|
* };
|
|
80
82
|
* ```
|
|
81
83
|
* @example
|
|
84
|
+
* When applied to a Store, this CellSchema expects a string Cell to be present
|
|
85
|
+
* without providing a default value.
|
|
86
|
+
*
|
|
87
|
+
* ```js
|
|
88
|
+
* import type {CellSchema} from 'tinybase';
|
|
89
|
+
*
|
|
90
|
+
* export const requiredString: CellSchema = {
|
|
91
|
+
* type: 'string',
|
|
92
|
+
* required: true,
|
|
93
|
+
* };
|
|
94
|
+
* ```
|
|
95
|
+
* @example
|
|
82
96
|
* When applied to a Store, this CellSchema allows an object Cell containing
|
|
83
97
|
* arbitrary data, defaulting to an empty object.
|
|
84
98
|
*
|
|
@@ -94,11 +108,36 @@ export type TablesSchema = {[tableId: Id]: {[cellId: Id]: CellSchema}};
|
|
|
94
108
|
* @since v1.0.0
|
|
95
109
|
*/
|
|
96
110
|
export type CellSchema =
|
|
97
|
-
| {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
111
|
+
| {
|
|
112
|
+
type: 'string';
|
|
113
|
+
default?: string | null;
|
|
114
|
+
allowNull?: boolean;
|
|
115
|
+
required?: boolean;
|
|
116
|
+
}
|
|
117
|
+
| {
|
|
118
|
+
type: 'number';
|
|
119
|
+
default?: number | null;
|
|
120
|
+
allowNull?: boolean;
|
|
121
|
+
required?: boolean;
|
|
122
|
+
}
|
|
123
|
+
| {
|
|
124
|
+
type: 'boolean';
|
|
125
|
+
default?: boolean | null;
|
|
126
|
+
allowNull?: boolean;
|
|
127
|
+
required?: boolean;
|
|
128
|
+
}
|
|
129
|
+
| {
|
|
130
|
+
type: 'object';
|
|
131
|
+
default?: AnyObject;
|
|
132
|
+
allowNull?: boolean;
|
|
133
|
+
required?: boolean;
|
|
134
|
+
}
|
|
135
|
+
| {
|
|
136
|
+
type: 'array';
|
|
137
|
+
default?: AnyArray;
|
|
138
|
+
allowNull?: boolean;
|
|
139
|
+
required?: boolean;
|
|
140
|
+
};
|
|
102
141
|
|
|
103
142
|
/**
|
|
104
143
|
* The ValuesSchema type describes the keyed Values that can be set in a Store
|
|
@@ -134,11 +173,13 @@ export type ValuesSchema = {[valueId: Id]: ValueSchema};
|
|
|
134
173
|
* and from JSON when storing and retrieving them.
|
|
135
174
|
*
|
|
136
175
|
* If a default value is provided (and its type is correct), you can be certain
|
|
137
|
-
* that the Value will always be present in a Store.
|
|
176
|
+
* that the Value will always be present in a Store. You can also set `required`
|
|
177
|
+
* to `true` to indicate to schema-based typing that the Value should be
|
|
178
|
+
* present even if it does not have a default.
|
|
138
179
|
*
|
|
139
|
-
* If
|
|
140
|
-
*
|
|
141
|
-
*
|
|
180
|
+
* If neither a default value nor `required: true` is provided, the Value may
|
|
181
|
+
* not be present in the Store, but when present you can be guaranteed it is of
|
|
182
|
+
* the correct type.
|
|
142
183
|
* @example
|
|
143
184
|
* When applied to a Store, this ValueSchema ensures a boolean Value is always
|
|
144
185
|
* present, and defaults it to `false`.
|
|
@@ -152,6 +193,18 @@ export type ValuesSchema = {[valueId: Id]: ValueSchema};
|
|
|
152
193
|
* };
|
|
153
194
|
* ```
|
|
154
195
|
* @example
|
|
196
|
+
* When applied to a Store, this ValueSchema expects a string Value to be
|
|
197
|
+
* present without providing a default value.
|
|
198
|
+
*
|
|
199
|
+
* ```js
|
|
200
|
+
* import type {ValueSchema} from 'tinybase';
|
|
201
|
+
*
|
|
202
|
+
* export const requiredString: ValueSchema = {
|
|
203
|
+
* type: 'string',
|
|
204
|
+
* required: true,
|
|
205
|
+
* };
|
|
206
|
+
* ```
|
|
207
|
+
* @example
|
|
155
208
|
* When applied to a Store, this ValueSchema allows an array Value containing
|
|
156
209
|
* a list of items, defaulting to an empty array.
|
|
157
210
|
*
|
|
@@ -167,11 +220,36 @@ export type ValuesSchema = {[valueId: Id]: ValueSchema};
|
|
|
167
220
|
* @since v3.0.0
|
|
168
221
|
*/
|
|
169
222
|
export type ValueSchema =
|
|
170
|
-
| {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
223
|
+
| {
|
|
224
|
+
type: 'string';
|
|
225
|
+
default?: string | null;
|
|
226
|
+
allowNull?: boolean;
|
|
227
|
+
required?: boolean;
|
|
228
|
+
}
|
|
229
|
+
| {
|
|
230
|
+
type: 'number';
|
|
231
|
+
default?: number | null;
|
|
232
|
+
allowNull?: boolean;
|
|
233
|
+
required?: boolean;
|
|
234
|
+
}
|
|
235
|
+
| {
|
|
236
|
+
type: 'boolean';
|
|
237
|
+
default?: boolean | null;
|
|
238
|
+
allowNull?: boolean;
|
|
239
|
+
required?: boolean;
|
|
240
|
+
}
|
|
241
|
+
| {
|
|
242
|
+
type: 'object';
|
|
243
|
+
default?: AnyObject;
|
|
244
|
+
allowNull?: boolean;
|
|
245
|
+
required?: boolean;
|
|
246
|
+
}
|
|
247
|
+
| {
|
|
248
|
+
type: 'array';
|
|
249
|
+
default?: AnyArray;
|
|
250
|
+
allowNull?: boolean;
|
|
251
|
+
required?: boolean;
|
|
252
|
+
};
|
|
175
253
|
|
|
176
254
|
/**
|
|
177
255
|
* The NoTablesSchema type is a TablesSchema-like type for when one has not been
|