tinybase 3.0.4 → 3.0.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.
- package/package.json +21 -20
- package/readme.md +2 -2
- package/lib/cjs/checkpoints.d.ts +0 -959
- package/lib/cjs/common.d.ts +0 -115
- package/lib/cjs/indexes.d.ts +0 -966
- package/lib/cjs/metrics.d.ts +0 -827
- package/lib/cjs/persisters.d.ts +0 -727
- package/lib/cjs/queries.d.ts +0 -3024
- package/lib/cjs/relationships.d.ts +0 -1201
- package/lib/cjs/store.d.ts +0 -5244
- package/lib/cjs/tinybase.d.ts +0 -14
- package/lib/cjs/tools.d.ts +0 -512
- package/lib/cjs/ui-react.d.ts +0 -10921
- package/lib/cjs-es6/checkpoints.d.ts +0 -959
- package/lib/common.d.ts +0 -115
- package/lib/debug/checkpoints.d.ts +0 -959
- package/lib/debug/common.d.ts +0 -115
- package/lib/debug/indexes.d.ts +0 -966
- package/lib/debug/metrics.d.ts +0 -827
- package/lib/debug/persisters.d.ts +0 -727
- package/lib/debug/queries.d.ts +0 -3024
- package/lib/debug/relationships.d.ts +0 -1201
- package/lib/debug/store.d.ts +0 -5244
- package/lib/debug/tinybase.d.ts +0 -14
- package/lib/debug/tools.d.ts +0 -512
- package/lib/debug/ui-react.d.ts +0 -10921
- package/lib/es6/checkpoints.d.ts +0 -959
- package/lib/es6/common.d.ts +0 -115
- package/lib/es6/indexes.d.ts +0 -966
- package/lib/es6/metrics.d.ts +0 -827
- package/lib/es6/persisters.d.ts +0 -727
- package/lib/es6/queries.d.ts +0 -3024
- package/lib/es6/relationships.d.ts +0 -1201
- package/lib/es6/store.d.ts +0 -5244
- package/lib/es6/tinybase.d.ts +0 -14
- package/lib/es6/tools.d.ts +0 -512
- package/lib/es6/ui-react.d.ts +0 -10921
- package/lib/indexes.d.ts +0 -966
- package/lib/metrics.d.ts +0 -827
- package/lib/persisters.d.ts +0 -727
- package/lib/queries.d.ts +0 -3024
- package/lib/relationships.d.ts +0 -1201
- package/lib/store.d.ts +0 -5244
- package/lib/tinybase.d.ts +0 -14
- package/lib/tools.d.ts +0 -512
- package/lib/ui-react.d.ts +0 -10921
- package/lib/umd/checkpoints.d.ts +0 -959
- package/lib/umd/common.d.ts +0 -115
- package/lib/umd/indexes.d.ts +0 -966
- package/lib/umd/metrics.d.ts +0 -827
- package/lib/umd/persisters.d.ts +0 -727
- package/lib/umd/queries.d.ts +0 -3024
- package/lib/umd/relationships.d.ts +0 -1201
- package/lib/umd/store.d.ts +0 -5244
- package/lib/umd/tinybase.d.ts +0 -14
- package/lib/umd/tools.d.ts +0 -512
- package/lib/umd/ui-react.d.ts +0 -10921
- package/lib/umd-es6/checkpoints.d.ts +0 -959
- package/lib/umd-es6/common.d.ts +0 -115
- package/lib/umd-es6/indexes.d.ts +0 -966
- package/lib/umd-es6/metrics.d.ts +0 -827
- package/lib/umd-es6/persisters.d.ts +0 -727
- package/lib/umd-es6/queries.d.ts +0 -3024
- package/lib/umd-es6/relationships.d.ts +0 -1201
- package/lib/umd-es6/store.d.ts +0 -5244
- package/lib/umd-es6/tinybase.d.ts +0 -14
- package/lib/umd-es6/tools.d.ts +0 -512
- package/lib/umd-es6/ui-react.d.ts +0 -10921
- /package/lib/{checkpoints.d.ts → types/checkpoints.d.ts} +0 -0
- /package/lib/{cjs-es6 → types}/common.d.ts +0 -0
- /package/lib/{cjs-es6 → types}/indexes.d.ts +0 -0
- /package/lib/{cjs-es6 → types}/metrics.d.ts +0 -0
- /package/lib/{cjs-es6 → types}/persisters.d.ts +0 -0
- /package/lib/{cjs-es6 → types}/queries.d.ts +0 -0
- /package/lib/{cjs-es6 → types}/relationships.d.ts +0 -0
- /package/lib/{cjs-es6 → types}/store.d.ts +0 -0
- /package/lib/{cjs-es6 → types}/tinybase.d.ts +0 -0
- /package/lib/{cjs-es6 → types}/tools.d.ts +0 -0
- /package/lib/{cjs-es6 → types}/ui-react.d.ts +0 -0
package/lib/es6/tinybase.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This is everything.
|
|
3
|
-
*
|
|
4
|
-
* @packageDocumentation
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
export * from './checkpoints';
|
|
8
|
-
export * from './common';
|
|
9
|
-
export * from './indexes';
|
|
10
|
-
export * from './metrics';
|
|
11
|
-
export * from './persisters';
|
|
12
|
-
export * from './queries';
|
|
13
|
-
export * from './relationships';
|
|
14
|
-
export * from './store';
|
package/lib/es6/tools.d.ts
DELETED
|
@@ -1,512 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The tools module of the TinyBase project provides utilities for working with
|
|
3
|
-
* TinyBase during development.
|
|
4
|
-
*
|
|
5
|
-
* This module is not intended to be directly used at runtime in a production
|
|
6
|
-
* environment.
|
|
7
|
-
*
|
|
8
|
-
* @packageDocumentation
|
|
9
|
-
* @module tools
|
|
10
|
-
* @since v2.2.0
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {Store, TablesSchema, ValuesSchema} from './store.d';
|
|
14
|
-
import {Id} from './common.d';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* The StoreStats type describes a set of statistics about the Store, and
|
|
18
|
-
* is used for debugging purposes.
|
|
19
|
-
*
|
|
20
|
-
* A StoreStats object is returned from the getStoreStats method.
|
|
21
|
-
*
|
|
22
|
-
* @category Statistics
|
|
23
|
-
* @since v2.2.0
|
|
24
|
-
*/
|
|
25
|
-
export type StoreStats = {
|
|
26
|
-
/**
|
|
27
|
-
* The number of Table objects in the Store.
|
|
28
|
-
*/
|
|
29
|
-
totalTables: number;
|
|
30
|
-
/**
|
|
31
|
-
* The number of Row objects in the Store, across all Table objects.
|
|
32
|
-
*/
|
|
33
|
-
totalRows: number;
|
|
34
|
-
/**
|
|
35
|
-
* The number of Cell objects in the Store, across all Row objects, across all
|
|
36
|
-
* Table objects.
|
|
37
|
-
*/
|
|
38
|
-
totalCells: number;
|
|
39
|
-
/**
|
|
40
|
-
* The number of Value objects in the Store, since v3.0.0.
|
|
41
|
-
*/
|
|
42
|
-
totalValues: number;
|
|
43
|
-
/**
|
|
44
|
-
* The string length of the Store when serialized to JSON.
|
|
45
|
-
*/
|
|
46
|
-
jsonLength: number;
|
|
47
|
-
/**
|
|
48
|
-
* Additional detailed statistics about the Store if the `detail` flag is
|
|
49
|
-
* specified in the getStoreStats method.
|
|
50
|
-
*/
|
|
51
|
-
detail?: StoreStatsDetail;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* The StoreStatsDetail type describes a more detailed set of statistics about
|
|
56
|
-
* the Store, and is used for debugging purposes.
|
|
57
|
-
*
|
|
58
|
-
* A StoreStatsDetail object is added to the StoreStats object (returned from
|
|
59
|
-
* the getStoreStats method) when the `detail` flag is specified.
|
|
60
|
-
*
|
|
61
|
-
* @category Statistics
|
|
62
|
-
* @since v2.2.0
|
|
63
|
-
*/
|
|
64
|
-
export type StoreStatsDetail = {
|
|
65
|
-
/**
|
|
66
|
-
* Information about each Table in the Store.
|
|
67
|
-
*/
|
|
68
|
-
tables: {[tableId: Id]: StoreStatsTableDetail};
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* The StoreStatsTableDetail type describes a detailed set of statistics about a
|
|
73
|
-
* single Table in the Store, and is used for debugging purposes.
|
|
74
|
-
*
|
|
75
|
-
* @category Statistics
|
|
76
|
-
* @since v2.2.0
|
|
77
|
-
*/
|
|
78
|
-
export type StoreStatsTableDetail = {
|
|
79
|
-
/**
|
|
80
|
-
* The number of Row objects in the Table.
|
|
81
|
-
*/
|
|
82
|
-
tableRows: number;
|
|
83
|
-
/**
|
|
84
|
-
* The number of Cell objects in the Table, across all Row objects.
|
|
85
|
-
*/
|
|
86
|
-
tableCells: number;
|
|
87
|
-
rows: {[rowId: Id]: StoreStatsRowDetail};
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* The StoreStatsRowDetail type describes statistics about a single Row in the
|
|
92
|
-
* Store, and is used for debugging purposes.
|
|
93
|
-
*
|
|
94
|
-
* @category Statistics
|
|
95
|
-
* @since v2.2.0
|
|
96
|
-
*/
|
|
97
|
-
export type StoreStatsRowDetail = {
|
|
98
|
-
/**
|
|
99
|
-
* The number of Cell objects in the Row.
|
|
100
|
-
*/
|
|
101
|
-
rowCells: number;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* A Tools object lets you run various utilities on, and get certain information
|
|
106
|
-
* about, Store objects in development.
|
|
107
|
-
*
|
|
108
|
-
* @see Developer Tools guides
|
|
109
|
-
* @category Tools
|
|
110
|
-
* @since v2.2.0
|
|
111
|
-
*/
|
|
112
|
-
export interface Tools {
|
|
113
|
-
/* eslint-disable max-len */
|
|
114
|
-
/**
|
|
115
|
-
* The getStoreStats method provides a set of statistics about the Store, and
|
|
116
|
-
* is used for debugging purposes.
|
|
117
|
-
*
|
|
118
|
-
* @param detail An optional boolean that indicates more detailed stats about
|
|
119
|
-
* the inner structure of the Store should be returned.
|
|
120
|
-
* @returns A StoreStats object containing statistics about the Store.
|
|
121
|
-
* @example
|
|
122
|
-
* This example creates a Tools object and gets basic statistics about it.
|
|
123
|
-
* ```js
|
|
124
|
-
* const store = createStore()
|
|
125
|
-
* .setTable('pets', {
|
|
126
|
-
* fido: {species: 'dog', color: 'brown'},
|
|
127
|
-
* felix: {species: 'cat', color: 'black'},
|
|
128
|
-
* cujo: {species: 'dog', color: 'black'},
|
|
129
|
-
* })
|
|
130
|
-
* .setTable('species', {
|
|
131
|
-
* dog: {price: 5},
|
|
132
|
-
* cat: {price: 4},
|
|
133
|
-
* })
|
|
134
|
-
* .setValues({open: true, employees: 3});
|
|
135
|
-
* const tools = createTools(store);
|
|
136
|
-
* console.log(tools.getStoreStats());
|
|
137
|
-
* // -> {totalTables: 2, totalRows: 5, totalCells: 8, totalValues: 2, jsonLength: 212}
|
|
138
|
-
* ```
|
|
139
|
-
* @example
|
|
140
|
-
* This example creates a Tools object and gets detailed statistics about it.
|
|
141
|
-
* ```js
|
|
142
|
-
* const store = createStore()
|
|
143
|
-
* .setTable('pets', {
|
|
144
|
-
* fido: {species: 'dog', color: 'brown'},
|
|
145
|
-
* felix: {species: 'cat', color: 'black'},
|
|
146
|
-
* cujo: {species: 'dog', color: 'black'},
|
|
147
|
-
* })
|
|
148
|
-
* .setTable('species', {
|
|
149
|
-
* dog: {price: 5},
|
|
150
|
-
* cat: {price: 4},
|
|
151
|
-
* });
|
|
152
|
-
* const stats = createTools(store).getStoreStats(true);
|
|
153
|
-
*
|
|
154
|
-
* console.log(stats.totalTables);
|
|
155
|
-
* // -> 2
|
|
156
|
-
* console.log(stats.totalRows);
|
|
157
|
-
* // -> 5
|
|
158
|
-
* console.log(stats.totalCells);
|
|
159
|
-
* // -> 8
|
|
160
|
-
* console.log(stats.detail.tables.pets.tableRows);
|
|
161
|
-
* // -> 3
|
|
162
|
-
* console.log(stats.detail.tables.pets.tableCells);
|
|
163
|
-
* // -> 6
|
|
164
|
-
* console.log(stats.detail.tables.pets.rows);
|
|
165
|
-
* // -> {fido: {rowCells: 2}, felix: {rowCells: 2}, cujo: {rowCells: 2}}
|
|
166
|
-
* ```
|
|
167
|
-
* @category Statistics
|
|
168
|
-
* @since v2.2.0
|
|
169
|
-
*/
|
|
170
|
-
getStoreStats(detail?: boolean): StoreStats;
|
|
171
|
-
/* eslint-enable max-len */
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* The getStoreTablesSchema method returns the TablesSchema of the Store as an
|
|
175
|
-
* object.
|
|
176
|
-
*
|
|
177
|
-
* If the Store does not already have an explicit TablesSchema associated with
|
|
178
|
-
* it, the data in the Store will be scanned to attempt to infer a new
|
|
179
|
-
* TablesSchema.
|
|
180
|
-
*
|
|
181
|
-
* To be successful, this requires all the values of a given Cell across a
|
|
182
|
-
* Table object's Row objects to have a consistent type. If a given Cell Id
|
|
183
|
-
* appears in every Row, then a `default` for that Cell is specified in the
|
|
184
|
-
* TablesSchema, based on the most common value found.
|
|
185
|
-
*
|
|
186
|
-
* @returns A TablesSchema object for the Store.
|
|
187
|
-
* @example
|
|
188
|
-
* This example creates a Tools object and gets the schema of a Store that
|
|
189
|
-
* already has a TablesSchema.
|
|
190
|
-
* ```js
|
|
191
|
-
* const store = createStore().setTablesSchema({
|
|
192
|
-
* pets: {
|
|
193
|
-
* species: {type: 'string'},
|
|
194
|
-
* color: {type: 'string'},
|
|
195
|
-
* },
|
|
196
|
-
* species: {
|
|
197
|
-
* price: {type: 'number'},
|
|
198
|
-
* },
|
|
199
|
-
* });
|
|
200
|
-
* const schema = createTools(store).getStoreTablesSchema();
|
|
201
|
-
* console.log(schema.pets);
|
|
202
|
-
* // -> {species: {type: 'string'}, color: {type: 'string'}}
|
|
203
|
-
* ```
|
|
204
|
-
* @example
|
|
205
|
-
* This example creates a Tools object and infers the schema of a Store that
|
|
206
|
-
* doesn't already have a TablesSchema.
|
|
207
|
-
* ```js
|
|
208
|
-
* const store = createStore()
|
|
209
|
-
* .setTable('pets', {
|
|
210
|
-
* fido: {species: 'dog', color: 'brown'},
|
|
211
|
-
* felix: {species: 'cat', color: 'black'},
|
|
212
|
-
* cujo: {species: 'dog', color: 'black'},
|
|
213
|
-
* })
|
|
214
|
-
* .setTable('species', {
|
|
215
|
-
* dog: {price: 5, barks: true},
|
|
216
|
-
* cat: {price: 4, purrs: true},
|
|
217
|
-
* });
|
|
218
|
-
* const schema = createTools(store).getStoreTablesSchema();
|
|
219
|
-
* console.log(schema.pets.species);
|
|
220
|
-
* // -> {type: 'string', default: 'dog'}
|
|
221
|
-
* console.log(schema.pets.color);
|
|
222
|
-
* // -> {type: 'string', default: 'black'}
|
|
223
|
-
* console.log(schema.species.price);
|
|
224
|
-
* // -> {type: 'number', default: 5}
|
|
225
|
-
* console.log(schema.species.barks);
|
|
226
|
-
* // -> {type: 'boolean'}
|
|
227
|
-
* console.log(schema.species.purrs);
|
|
228
|
-
* // -> {type: 'boolean'}
|
|
229
|
-
* ```
|
|
230
|
-
* @category Modelling
|
|
231
|
-
* @since v3.0.0
|
|
232
|
-
*/
|
|
233
|
-
getStoreTablesSchema(): TablesSchema;
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* The getStoreValuesSchema method returns the ValuesSchema of the Store as an
|
|
237
|
-
* object.
|
|
238
|
-
*
|
|
239
|
-
* If the Store does not already have an explicit ValuesSchema associated with
|
|
240
|
-
* it, the data in the Store will be scanned to infer a new ValuesSchema,
|
|
241
|
-
* based on the types of the Values present. Note that, unlike the inference
|
|
242
|
-
* of Cell values in the TablesSchema, it is not able to determine whether a
|
|
243
|
-
* Value should have a default or not.
|
|
244
|
-
*
|
|
245
|
-
* @returns A ValuesSchema object for the Store.
|
|
246
|
-
* @example
|
|
247
|
-
* This example creates a Tools object and gets the schema of a Store that
|
|
248
|
-
* already has a ValuesSchema.
|
|
249
|
-
* ```js
|
|
250
|
-
* const store = createStore().setValuesSchema({
|
|
251
|
-
* open: {type: 'boolean', default: true},
|
|
252
|
-
* employees: {type: 'number'},
|
|
253
|
-
* });
|
|
254
|
-
*
|
|
255
|
-
* const schema = createTools(store).getStoreValuesSchema();
|
|
256
|
-
* console.log(schema);
|
|
257
|
-
* // -> {open: {type: 'boolean', default: true}, employees: {type: 'number'}}
|
|
258
|
-
* ```
|
|
259
|
-
* @example
|
|
260
|
-
* This example creates a Tools object and infers the schema of a Store that
|
|
261
|
-
* doesn't already have a ValuesSchema.
|
|
262
|
-
* ```js
|
|
263
|
-
* const store = createStore().setValues({open: true, employees: 3});
|
|
264
|
-
* const schema = createTools(store).getStoreValuesSchema();
|
|
265
|
-
*
|
|
266
|
-
* console.log(schema);
|
|
267
|
-
* // -> {open: {type: 'boolean'}, employees: {type: 'number'}}
|
|
268
|
-
* ```
|
|
269
|
-
* @category Modelling
|
|
270
|
-
* @since v3.0.0
|
|
271
|
-
*/
|
|
272
|
-
getStoreValuesSchema(): ValuesSchema;
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* The getStoreApi method returns a code-generated .d.ts file and a .ts file
|
|
276
|
-
* that describe the schema of a Store in an ORM style.
|
|
277
|
-
*
|
|
278
|
-
* If the Store does not already have an explicit TablesSchema associated with
|
|
279
|
-
* it, the data in the Store will be scanned to attempt to infer a new
|
|
280
|
-
* TablesSchema. The method returns two strings (which should be saved as
|
|
281
|
-
* files) though if no schema can be inferred, the strings will be empty.
|
|
282
|
-
*
|
|
283
|
-
* The method takes a single argument which represents the name you want the
|
|
284
|
-
* generated store object to have in code. You are expected to save the files
|
|
285
|
-
* as `[storeName].d.ts` and `[storeName].ts`, and alongside each other so
|
|
286
|
-
* that the latter can import types from the former.
|
|
287
|
-
*
|
|
288
|
-
* The .d.ts and .ts files that are generated are designed to resemble the
|
|
289
|
-
* main TinyBase `store.d.ts` and `store.ts` files, but provide named types
|
|
290
|
-
* and methods that describe the domain of the schema in the store.
|
|
291
|
-
*
|
|
292
|
-
* For example, from a Store that has a `pets` Table, you will get methods
|
|
293
|
-
* like `getPetsTable`, and types like `PetsRow`, that are more specific
|
|
294
|
-
* versions of the underlying getTable method or the Row type. For example:
|
|
295
|
-
*
|
|
296
|
-
* |Store type|Equivalent generated type|
|
|
297
|
-
* |-|-|
|
|
298
|
-
* |Table|[Table]Table|
|
|
299
|
-
* |Row|[Table]Row|
|
|
300
|
-
* |(Cell) Id|[Table]CellId|
|
|
301
|
-
* |CellCallback|[Table]CellCallback|
|
|
302
|
-
* |...|...|
|
|
303
|
-
*
|
|
304
|
-
* |Store method|Equivalent generated method|
|
|
305
|
-
* |-|-|
|
|
306
|
-
* |setTable|set[Table]Table|
|
|
307
|
-
* |hasRow|has[Table]Row|
|
|
308
|
-
* |getCell|get[Table][Cell]Cell|
|
|
309
|
-
* |...|...|
|
|
310
|
-
*
|
|
311
|
-
* Equivalent to the TinyBase createStore function, a `create[StoreName]`
|
|
312
|
-
* function will also be created. This acts as the main entry point to the
|
|
313
|
-
* generated implementation.
|
|
314
|
-
*
|
|
315
|
-
* Each method is refined correctly to take, or return, the types specified by
|
|
316
|
-
* the schema. For example, if the `pets` Table has a numeric `price` Cell in
|
|
317
|
-
* the schema, the `getPetsPriceCell` method will be typed to return a number.
|
|
318
|
-
*
|
|
319
|
-
* The tables above include just a sample of the generated output. For the
|
|
320
|
-
* full set of methods and types generated by this method, inspect the output
|
|
321
|
-
* directly.
|
|
322
|
-
*
|
|
323
|
-
* @param storeName The name you want to provide to the generated Store, which
|
|
324
|
-
* should also be used to save the `.d.ts` and `.ts` files.
|
|
325
|
-
* @returns A pair of strings representing the contents of the `.d.ts` and
|
|
326
|
-
* `.ts` files.
|
|
327
|
-
* @example
|
|
328
|
-
* This example creates a Tools object and generates code for a Store that
|
|
329
|
-
* already has a TablesSchema.
|
|
330
|
-
* ```js
|
|
331
|
-
* const store = createStore().setTablesSchema({
|
|
332
|
-
* pets: {
|
|
333
|
-
* price: {type: 'number'},
|
|
334
|
-
* },
|
|
335
|
-
* });
|
|
336
|
-
* const [dTs, ts] = createTools(store).getStoreApi('shop');
|
|
337
|
-
*
|
|
338
|
-
* const dTsLines = dTs.split('\n');
|
|
339
|
-
* console.log(dTsLines[3]);
|
|
340
|
-
* // -> 'export type PetsTable = {[rowId: Id]: PetsRow};'
|
|
341
|
-
* console.log(dTsLines[6]);
|
|
342
|
-
* // -> 'export type PetsRow = {\'price\'?: number;};'
|
|
343
|
-
*
|
|
344
|
-
* const tsLines = ts.split('\n');
|
|
345
|
-
* console.log(tsLines[41]);
|
|
346
|
-
* // -> 'getPetsTable: (): PetsTable => store.getTable(PETS) as PetsTable,'
|
|
347
|
-
* ```
|
|
348
|
-
* @example
|
|
349
|
-
* This example creates a Tools object and generates code for a Store that
|
|
350
|
-
* doesn't already have a TablesSchema.
|
|
351
|
-
* ```js
|
|
352
|
-
* const store = createStore().setTable('pets', {
|
|
353
|
-
* fido: {price: 5},
|
|
354
|
-
* felix: {price: 4},
|
|
355
|
-
* });
|
|
356
|
-
* const [dTs, ts] = createTools(store).getStoreApi('shop');
|
|
357
|
-
*
|
|
358
|
-
* const dTsLines = dTs.split('\n');
|
|
359
|
-
* console.log(dTsLines[3]);
|
|
360
|
-
* // -> 'export type PetsTable = {[rowId: Id]: PetsRow};'
|
|
361
|
-
* console.log(dTsLines[6]);
|
|
362
|
-
* // -> 'export type PetsRow = {\'price\': number;};'
|
|
363
|
-
*
|
|
364
|
-
* const tsLines = ts.split('\n');
|
|
365
|
-
* console.log(tsLines[43]);
|
|
366
|
-
* // -> 'getPetsTable: (): PetsTable => store.getTable(PETS) as PetsTable,'
|
|
367
|
-
* ```
|
|
368
|
-
* @category Modelling
|
|
369
|
-
* @since v2.2.0
|
|
370
|
-
*/
|
|
371
|
-
getStoreApi(storeName: string): [string, string];
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
* The getPrettyStoreApi method attempts to returns a prettified
|
|
375
|
-
* code-generated .d.ts file and a .ts file that describe the schema of a
|
|
376
|
-
* Store in an ORM style.
|
|
377
|
-
*
|
|
378
|
-
* This is simply a wrapper around the getStoreApi method that attempts to
|
|
379
|
-
* invoke the `prettier` module (which it hopes you have installed) to format
|
|
380
|
-
* the generated code. If `prettier` is not present, the output will resemble
|
|
381
|
-
* that of the underlying getStoreApi method.
|
|
382
|
-
*
|
|
383
|
-
* The method is asynchronous, so you should use the `await` keyword or handle
|
|
384
|
-
* the results as a promise.
|
|
385
|
-
*
|
|
386
|
-
* The method takes a single argument which represents the name you want the
|
|
387
|
-
* generated store object to have in code. You are expected to save the files
|
|
388
|
-
* as `[storeName].d.ts` and `[storeName].ts`, and alongside each other so
|
|
389
|
-
* that the latter can import types from the former.
|
|
390
|
-
*
|
|
391
|
-
* See the documentation for the getStoreApi method for details of the content
|
|
392
|
-
* of the generated files.
|
|
393
|
-
*
|
|
394
|
-
* @param storeName The name you want to provide to the generated Store, which
|
|
395
|
-
* should also be used to save the `.d.ts` and `.ts` files.
|
|
396
|
-
* @returns A pair of strings representing the contents of the `.d.ts` and
|
|
397
|
-
* `.ts` files.
|
|
398
|
-
* @example
|
|
399
|
-
* This example creates a Tools object and generates code for a Store that
|
|
400
|
-
* already has a TablesSchema.
|
|
401
|
-
* ```js
|
|
402
|
-
* const store = createStore().setTablesSchema({
|
|
403
|
-
* pets: {
|
|
404
|
-
* price: {type: 'number'},
|
|
405
|
-
* },
|
|
406
|
-
* });
|
|
407
|
-
* const tools = createTools(store);
|
|
408
|
-
* const [dTs, ts] = await tools.getPrettyStoreApi('shop');
|
|
409
|
-
*
|
|
410
|
-
* const dTsLines = dTs.split('\n');
|
|
411
|
-
* console.log(dTsLines[5]);
|
|
412
|
-
* // -> 'export type PetsTable = {[rowId: Id]: PetsRow};'
|
|
413
|
-
* console.log(dTsLines[10]);
|
|
414
|
-
* // -> 'export type PetsRow = {price?: number};'
|
|
415
|
-
*
|
|
416
|
-
* const tsLines = ts.split('\n');
|
|
417
|
-
* console.log(tsLines[72]);
|
|
418
|
-
* // -> ' hasPetsTable: (): boolean => store.hasTable(PETS),'
|
|
419
|
-
* ```
|
|
420
|
-
* @example
|
|
421
|
-
* This example creates a Tools object and generates code for a Store that
|
|
422
|
-
* doesn't already have a TablesSchema.
|
|
423
|
-
* ```js
|
|
424
|
-
* const store = createStore().setTable('pets', {
|
|
425
|
-
* fido: {price: 5},
|
|
426
|
-
* felix: {price: 4},
|
|
427
|
-
* });
|
|
428
|
-
* const tools = createTools(store);
|
|
429
|
-
* const [dTs, ts] = await tools.getPrettyStoreApi('shop');
|
|
430
|
-
*
|
|
431
|
-
* const dTsLines = dTs.split('\n');
|
|
432
|
-
* console.log(dTsLines[5]);
|
|
433
|
-
* // -> 'export type PetsTable = {[rowId: Id]: PetsRow};'
|
|
434
|
-
* console.log(dTsLines[10]);
|
|
435
|
-
* // -> 'export type PetsRow = {price: number};'
|
|
436
|
-
*
|
|
437
|
-
* const tsLines = ts.split('\n');
|
|
438
|
-
* console.log(tsLines[74]);
|
|
439
|
-
* // -> ' hasPetsTable: (): boolean => store.hasTable(PETS),'
|
|
440
|
-
* ```
|
|
441
|
-
* @category Modelling
|
|
442
|
-
* @since v2.2.0
|
|
443
|
-
*/
|
|
444
|
-
getPrettyStoreApi(storeName: string): Promise<[string, string]>;
|
|
445
|
-
|
|
446
|
-
/**
|
|
447
|
-
* The getStore method returns a reference to the underlying Store that is
|
|
448
|
-
* backing this Tools object.
|
|
449
|
-
*
|
|
450
|
-
* @returns A reference to the Store.
|
|
451
|
-
* @example
|
|
452
|
-
* This example creates a Tools object against a newly-created Store and
|
|
453
|
-
* then gets its reference in order to update its data.
|
|
454
|
-
*
|
|
455
|
-
* ```js
|
|
456
|
-
* const tools = createTools(createStore());
|
|
457
|
-
* tools.getStore().setCell('species', 'dog', 'price', 5);
|
|
458
|
-
* console.log(tools.getStoreStats().totalCells);
|
|
459
|
-
* // -> 1
|
|
460
|
-
* ```
|
|
461
|
-
* @category Getter
|
|
462
|
-
* @since v3.0.0
|
|
463
|
-
*/
|
|
464
|
-
getStore(): Store;
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
/* eslint-disable max-len */
|
|
468
|
-
/**
|
|
469
|
-
* The createTools function creates a Tools object, and is the main entry point
|
|
470
|
-
* into the tools module.
|
|
471
|
-
*
|
|
472
|
-
* A given Store can only have one Tools object associated with it. If you call
|
|
473
|
-
* this function twice on the same Store, your second call will return a
|
|
474
|
-
* reference to the Tools object created by the first.
|
|
475
|
-
*
|
|
476
|
-
* @param store The Store for which to register tools.
|
|
477
|
-
* @returns A reference to the new Tools object.
|
|
478
|
-
* @example
|
|
479
|
-
* This example creates a Tools object.
|
|
480
|
-
*
|
|
481
|
-
* ```js
|
|
482
|
-
* const store = createStore()
|
|
483
|
-
* .setTable('pets', {
|
|
484
|
-
* fido: {species: 'dog', color: 'brown'},
|
|
485
|
-
* felix: {species: 'cat', color: 'black'},
|
|
486
|
-
* cujo: {species: 'dog', color: 'black'},
|
|
487
|
-
* })
|
|
488
|
-
* .setTable('species', {
|
|
489
|
-
* dog: {price: 5},
|
|
490
|
-
* cat: {price: 4},
|
|
491
|
-
* })
|
|
492
|
-
* .setValues({open: true, employees: 3});
|
|
493
|
-
* const tools = createTools(store);
|
|
494
|
-
* console.log(tools.getStoreStats());
|
|
495
|
-
* // -> {totalTables: 2, totalRows: 5, totalCells: 8, totalValues: 2, jsonLength: 212}
|
|
496
|
-
* ```
|
|
497
|
-
* @example
|
|
498
|
-
* This example creates a Tools object, and calls the method a second time
|
|
499
|
-
* for the same Store to return the same object.
|
|
500
|
-
*
|
|
501
|
-
* ```js
|
|
502
|
-
* const store = createStore();
|
|
503
|
-
* const tools1 = createTools(store);
|
|
504
|
-
* const tools2 = createTools(store);
|
|
505
|
-
* console.log(tools1 === tools2);
|
|
506
|
-
* // -> true
|
|
507
|
-
* ```
|
|
508
|
-
* @category Creation
|
|
509
|
-
* @since v2.2.0
|
|
510
|
-
*/
|
|
511
|
-
export function createTools(store: Store): Tools;
|
|
512
|
-
/* eslint-enable max-len */
|