tinybase 2.2.6 → 3.0.0-beta.1
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/bin/cli.js +1 -1
- package/lib/checkpoints.d.ts +18 -3
- package/lib/checkpoints.js +1 -1
- package/lib/checkpoints.js.gz +0 -0
- package/lib/debug/checkpoints.d.ts +18 -3
- package/lib/debug/checkpoints.js +97 -49
- package/lib/debug/indexes.js +31 -16
- package/lib/debug/metrics.js +31 -16
- package/lib/debug/persisters.d.ts +33 -23
- package/lib/debug/persisters.js +10 -5
- package/lib/debug/queries.js +2 -2
- package/lib/debug/relationships.js +31 -16
- package/lib/debug/store.d.ts +2022 -383
- package/lib/debug/store.js +440 -108
- package/lib/debug/tinybase.js +508 -140
- package/lib/debug/tools.d.ts +89 -38
- package/lib/debug/tools.js +757 -453
- package/lib/debug/ui-react.d.ts +1525 -381
- package/lib/debug/ui-react.js +163 -12
- package/lib/es6/checkpoints.d.ts +18 -3
- package/lib/es6/checkpoints.js +1 -1
- package/lib/es6/checkpoints.js.gz +0 -0
- package/lib/es6/indexes.js +1 -1
- package/lib/es6/indexes.js.gz +0 -0
- package/lib/es6/metrics.js +1 -1
- package/lib/es6/metrics.js.gz +0 -0
- package/lib/es6/persisters.d.ts +33 -23
- package/lib/es6/persisters.js +1 -1
- package/lib/es6/persisters.js.gz +0 -0
- package/lib/es6/relationships.js +1 -1
- package/lib/es6/relationships.js.gz +0 -0
- package/lib/es6/store.d.ts +2022 -383
- package/lib/es6/store.js +1 -1
- package/lib/es6/store.js.gz +0 -0
- package/lib/es6/tinybase.js +1 -1
- package/lib/es6/tinybase.js.gz +0 -0
- package/lib/es6/tools.d.ts +89 -38
- package/lib/es6/tools.js +1 -1
- package/lib/es6/tools.js.gz +0 -0
- package/lib/es6/ui-react.d.ts +1525 -381
- package/lib/es6/ui-react.js +1 -1
- package/lib/es6/ui-react.js.gz +0 -0
- package/lib/indexes.js +1 -1
- package/lib/indexes.js.gz +0 -0
- package/lib/metrics.js +1 -1
- package/lib/metrics.js.gz +0 -0
- package/lib/persisters.d.ts +33 -23
- package/lib/persisters.js +1 -1
- package/lib/persisters.js.gz +0 -0
- package/lib/relationships.js +1 -1
- package/lib/relationships.js.gz +0 -0
- package/lib/store.d.ts +2022 -383
- package/lib/store.js +1 -1
- package/lib/store.js.gz +0 -0
- package/lib/tinybase.js +1 -1
- package/lib/tinybase.js.gz +0 -0
- package/lib/tools.d.ts +89 -38
- package/lib/tools.js +1 -1
- package/lib/tools.js.gz +0 -0
- package/lib/ui-react.d.ts +1525 -381
- package/lib/ui-react.js +1 -1
- package/lib/ui-react.js.gz +0 -0
- package/lib/umd/checkpoints.d.ts +18 -3
- package/lib/umd/checkpoints.js +1 -1
- package/lib/umd/checkpoints.js.gz +0 -0
- package/lib/umd/indexes.js +1 -1
- package/lib/umd/indexes.js.gz +0 -0
- package/lib/umd/metrics.js +1 -1
- package/lib/umd/metrics.js.gz +0 -0
- package/lib/umd/persisters.d.ts +33 -23
- package/lib/umd/persisters.js +1 -1
- package/lib/umd/persisters.js.gz +0 -0
- package/lib/umd/relationships.js +1 -1
- package/lib/umd/relationships.js.gz +0 -0
- package/lib/umd/store.d.ts +2022 -383
- package/lib/umd/store.js +1 -1
- package/lib/umd/store.js.gz +0 -0
- package/lib/umd/tinybase.js +1 -1
- package/lib/umd/tinybase.js.gz +0 -0
- package/lib/umd/tools.d.ts +89 -38
- package/lib/umd/tools.js +1 -1
- package/lib/umd/tools.js.gz +0 -0
- package/lib/umd/ui-react.d.ts +1525 -381
- package/lib/umd/ui-react.js +1 -1
- package/lib/umd/ui-react.js.gz +0 -0
- package/lib/umd-es6/checkpoints.d.ts +18 -3
- package/lib/umd-es6/checkpoints.js +1 -1
- package/lib/umd-es6/checkpoints.js.gz +0 -0
- package/lib/umd-es6/indexes.js +1 -1
- package/lib/umd-es6/indexes.js.gz +0 -0
- package/lib/umd-es6/metrics.js +1 -1
- package/lib/umd-es6/metrics.js.gz +0 -0
- package/lib/umd-es6/persisters.d.ts +33 -23
- package/lib/umd-es6/persisters.js +1 -1
- package/lib/umd-es6/persisters.js.gz +0 -0
- package/lib/umd-es6/relationships.js +1 -1
- package/lib/umd-es6/relationships.js.gz +0 -0
- package/lib/umd-es6/store.d.ts +2022 -383
- package/lib/umd-es6/store.js +1 -1
- package/lib/umd-es6/store.js.gz +0 -0
- package/lib/umd-es6/tinybase.js +1 -1
- package/lib/umd-es6/tinybase.js.gz +0 -0
- package/lib/umd-es6/tools.d.ts +89 -38
- package/lib/umd-es6/tools.js +1 -1
- package/lib/umd-es6/tools.js.gz +0 -0
- package/lib/umd-es6/ui-react.d.ts +1525 -381
- package/lib/umd-es6/ui-react.js +1 -1
- package/lib/umd-es6/ui-react.js.gz +0 -0
- package/package.json +26 -26
- package/readme.md +20 -19
package/lib/debug/tools.d.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* @since v2.2.0
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {
|
|
13
|
+
import {Store, TablesSchema, ValuesSchema} from './store.d';
|
|
14
14
|
import {Id} from './common.d';
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -36,6 +36,10 @@ export type StoreStats = {
|
|
|
36
36
|
* Table objects.
|
|
37
37
|
*/
|
|
38
38
|
totalCells: number;
|
|
39
|
+
/**
|
|
40
|
+
* The number of Value objects in the Store, since v3.0.0.
|
|
41
|
+
*/
|
|
42
|
+
totalValues: number;
|
|
39
43
|
/**
|
|
40
44
|
* The string length of the Store when serialized to JSON.
|
|
41
45
|
*/
|
|
@@ -106,6 +110,7 @@ export type StoreStatsRowDetail = {
|
|
|
106
110
|
* @since v2.2.0
|
|
107
111
|
*/
|
|
108
112
|
export interface Tools {
|
|
113
|
+
/* eslint-disable max-len */
|
|
109
114
|
/**
|
|
110
115
|
* The getStoreStats method provides a set of statistics about the Store, and
|
|
111
116
|
* is used for debugging purposes.
|
|
@@ -125,10 +130,11 @@ export interface Tools {
|
|
|
125
130
|
* .setTable('species', {
|
|
126
131
|
* dog: {price: 5},
|
|
127
132
|
* cat: {price: 4},
|
|
128
|
-
* })
|
|
133
|
+
* })
|
|
134
|
+
* .setValues({open: true, employees: 3});
|
|
129
135
|
* const tools = createTools(store);
|
|
130
136
|
* console.log(tools.getStoreStats());
|
|
131
|
-
* // -> {totalTables: 2, totalRows: 5, totalCells: 8, jsonLength:
|
|
137
|
+
* // -> {totalTables: 2, totalRows: 5, totalCells: 8, totalValues: 2, jsonLength: 212}
|
|
132
138
|
* ```
|
|
133
139
|
* @example
|
|
134
140
|
* This example creates a Tools object and gets detailed statistics about it.
|
|
@@ -162,24 +168,27 @@ export interface Tools {
|
|
|
162
168
|
* @since v2.2.0
|
|
163
169
|
*/
|
|
164
170
|
getStoreStats(detail?: boolean): StoreStats;
|
|
171
|
+
/* eslint-enable max-len */
|
|
165
172
|
|
|
166
173
|
/**
|
|
167
|
-
* The
|
|
174
|
+
* The getStoreTablesSchema method returns the TablesSchema of the Store as an
|
|
175
|
+
* object.
|
|
168
176
|
*
|
|
169
|
-
* If the Store does not already have an explicit
|
|
170
|
-
* the data in the Store will be scanned to attempt to infer a new
|
|
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.
|
|
171
180
|
*
|
|
172
181
|
* To be successful, this requires all the values of a given Cell across a
|
|
173
|
-
* Table object's
|
|
182
|
+
* Table object's Row objects to have a consistent type. If a given Cell Id
|
|
174
183
|
* appears in every Row, then a `default` for that Cell is specified in the
|
|
175
|
-
*
|
|
184
|
+
* TablesSchema, based on the most common value found.
|
|
176
185
|
*
|
|
177
|
-
* @returns A
|
|
186
|
+
* @returns A TablesSchema object for the Store.
|
|
178
187
|
* @example
|
|
179
|
-
* This example creates a Tools object and gets
|
|
180
|
-
*
|
|
188
|
+
* This example creates a Tools object and gets the schema of a Store that
|
|
189
|
+
* already has a TablesSchema.
|
|
181
190
|
* ```js
|
|
182
|
-
* const store = createStore().
|
|
191
|
+
* const store = createStore().setTablesSchema({
|
|
183
192
|
* pets: {
|
|
184
193
|
* species: {type: 'string'},
|
|
185
194
|
* color: {type: 'string'},
|
|
@@ -188,13 +197,13 @@ export interface Tools {
|
|
|
188
197
|
* price: {type: 'number'},
|
|
189
198
|
* },
|
|
190
199
|
* });
|
|
191
|
-
* const schema = createTools(store).
|
|
200
|
+
* const schema = createTools(store).getStoreTablesSchema();
|
|
192
201
|
* console.log(schema.pets);
|
|
193
202
|
* // -> {species: {type: 'string'}, color: {type: 'string'}}
|
|
194
203
|
* ```
|
|
195
204
|
* @example
|
|
196
|
-
* This example creates a Tools object and
|
|
197
|
-
*
|
|
205
|
+
* This example creates a Tools object and infers the schema of a Store that
|
|
206
|
+
* doesn't already have a TablesSchema.
|
|
198
207
|
* ```js
|
|
199
208
|
* const store = createStore()
|
|
200
209
|
* .setTable('pets', {
|
|
@@ -206,7 +215,7 @@ export interface Tools {
|
|
|
206
215
|
* dog: {price: 5, barks: true},
|
|
207
216
|
* cat: {price: 4, purrs: true},
|
|
208
217
|
* });
|
|
209
|
-
* const schema = createTools(store).
|
|
218
|
+
* const schema = createTools(store).getStoreTablesSchema();
|
|
210
219
|
* console.log(schema.pets.species);
|
|
211
220
|
* // -> {type: 'string', default: 'dog'}
|
|
212
221
|
* console.log(schema.pets.color);
|
|
@@ -219,18 +228,57 @@ export interface Tools {
|
|
|
219
228
|
* // -> {type: 'boolean'}
|
|
220
229
|
* ```
|
|
221
230
|
* @category Modelling
|
|
222
|
-
* @since
|
|
231
|
+
* @since v3.0.0
|
|
223
232
|
*/
|
|
224
|
-
|
|
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;
|
|
225
273
|
|
|
226
274
|
/**
|
|
227
275
|
* The getStoreApi method returns a code-generated .d.ts file and a .ts file
|
|
228
276
|
* that describe the schema of a Store in an ORM style.
|
|
229
277
|
*
|
|
230
|
-
* If the Store does not already have an explicit
|
|
231
|
-
* the data in the Store will be scanned to attempt to infer a new
|
|
232
|
-
* method returns two strings (which should be saved as
|
|
233
|
-
* schema can be inferred, the strings will be empty.
|
|
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.
|
|
234
282
|
*
|
|
235
283
|
* The method takes a single argument which represents the name you want the
|
|
236
284
|
* generated store object to have in code. You are expected to save the files
|
|
@@ -278,9 +326,9 @@ export interface Tools {
|
|
|
278
326
|
* `.ts` files.
|
|
279
327
|
* @example
|
|
280
328
|
* This example creates a Tools object and generates code for a Store that
|
|
281
|
-
* already has a
|
|
329
|
+
* already has a TablesSchema.
|
|
282
330
|
* ```js
|
|
283
|
-
* const store = createStore().
|
|
331
|
+
* const store = createStore().setTablesSchema({
|
|
284
332
|
* pets: {
|
|
285
333
|
* price: {type: 'number'},
|
|
286
334
|
* },
|
|
@@ -294,12 +342,12 @@ export interface Tools {
|
|
|
294
342
|
* // -> 'export type PetsRow = {\'price\'?: number;};'
|
|
295
343
|
*
|
|
296
344
|
* const tsLines = ts.split('\n');
|
|
297
|
-
* console.log(tsLines[
|
|
345
|
+
* console.log(tsLines[41]);
|
|
298
346
|
* // -> 'getPetsTable: (): PetsTable => store.getTable(PETS) as PetsTable,'
|
|
299
347
|
* ```
|
|
300
348
|
* @example
|
|
301
349
|
* This example creates a Tools object and generates code for a Store that
|
|
302
|
-
* doesn't already have a
|
|
350
|
+
* doesn't already have a TablesSchema.
|
|
303
351
|
* ```js
|
|
304
352
|
* const store = createStore().setTable('pets', {
|
|
305
353
|
* fido: {price: 5},
|
|
@@ -314,7 +362,7 @@ export interface Tools {
|
|
|
314
362
|
* // -> 'export type PetsRow = {\'price\': number;};'
|
|
315
363
|
*
|
|
316
364
|
* const tsLines = ts.split('\n');
|
|
317
|
-
* console.log(tsLines[
|
|
365
|
+
* console.log(tsLines[43]);
|
|
318
366
|
* // -> 'getPetsTable: (): PetsTable => store.getTable(PETS) as PetsTable,'
|
|
319
367
|
* ```
|
|
320
368
|
* @category Modelling
|
|
@@ -349,9 +397,9 @@ export interface Tools {
|
|
|
349
397
|
* `.ts` files.
|
|
350
398
|
* @example
|
|
351
399
|
* This example creates a Tools object and generates code for a Store that
|
|
352
|
-
* already has a
|
|
400
|
+
* already has a TablesSchema.
|
|
353
401
|
* ```js
|
|
354
|
-
* const store = createStore().
|
|
402
|
+
* const store = createStore().setTablesSchema({
|
|
355
403
|
* pets: {
|
|
356
404
|
* price: {type: 'number'},
|
|
357
405
|
* },
|
|
@@ -360,18 +408,18 @@ export interface Tools {
|
|
|
360
408
|
* const [dTs, ts] = await tools.getPrettyStoreApi('shop');
|
|
361
409
|
*
|
|
362
410
|
* const dTsLines = dTs.split('\n');
|
|
363
|
-
* console.log(dTsLines[
|
|
411
|
+
* console.log(dTsLines[5]);
|
|
364
412
|
* // -> 'export type PetsTable = {[rowId: Id]: PetsRow};'
|
|
365
|
-
* console.log(dTsLines[
|
|
413
|
+
* console.log(dTsLines[10]);
|
|
366
414
|
* // -> 'export type PetsRow = {price?: number};'
|
|
367
415
|
*
|
|
368
416
|
* const tsLines = ts.split('\n');
|
|
369
|
-
* console.log(tsLines[
|
|
417
|
+
* console.log(tsLines[72]);
|
|
370
418
|
* // -> ' hasPetsTable: (): boolean => store.hasTable(PETS),'
|
|
371
419
|
* ```
|
|
372
420
|
* @example
|
|
373
421
|
* This example creates a Tools object and generates code for a Store that
|
|
374
|
-
* doesn't already have a
|
|
422
|
+
* doesn't already have a TablesSchema.
|
|
375
423
|
* ```js
|
|
376
424
|
* const store = createStore().setTable('pets', {
|
|
377
425
|
* fido: {price: 5},
|
|
@@ -381,13 +429,13 @@ export interface Tools {
|
|
|
381
429
|
* const [dTs, ts] = await tools.getPrettyStoreApi('shop');
|
|
382
430
|
*
|
|
383
431
|
* const dTsLines = dTs.split('\n');
|
|
384
|
-
* console.log(dTsLines[
|
|
432
|
+
* console.log(dTsLines[5]);
|
|
385
433
|
* // -> 'export type PetsTable = {[rowId: Id]: PetsRow};'
|
|
386
|
-
* console.log(dTsLines[
|
|
434
|
+
* console.log(dTsLines[10]);
|
|
387
435
|
* // -> 'export type PetsRow = {price: number};'
|
|
388
436
|
*
|
|
389
437
|
* const tsLines = ts.split('\n');
|
|
390
|
-
* console.log(tsLines[
|
|
438
|
+
* console.log(tsLines[74]);
|
|
391
439
|
* // -> ' hasPetsTable: (): boolean => store.hasTable(PETS),'
|
|
392
440
|
* ```
|
|
393
441
|
* @category Modelling
|
|
@@ -396,6 +444,7 @@ export interface Tools {
|
|
|
396
444
|
getPrettyStoreApi(storeName: string): Promise<[string, string]>;
|
|
397
445
|
}
|
|
398
446
|
|
|
447
|
+
/* eslint-disable max-len */
|
|
399
448
|
/**
|
|
400
449
|
* The createTools function creates a Tools object, and is the main entry point
|
|
401
450
|
* into the tools module.
|
|
@@ -419,10 +468,11 @@ export interface Tools {
|
|
|
419
468
|
* .setTable('species', {
|
|
420
469
|
* dog: {price: 5},
|
|
421
470
|
* cat: {price: 4},
|
|
422
|
-
* })
|
|
471
|
+
* })
|
|
472
|
+
* .setValues({open: true, employees: 3});
|
|
423
473
|
* const tools = createTools(store);
|
|
424
474
|
* console.log(tools.getStoreStats());
|
|
425
|
-
* // -> {totalTables: 2, totalRows: 5, totalCells: 8, jsonLength:
|
|
475
|
+
* // -> {totalTables: 2, totalRows: 5, totalCells: 8, totalValues: 2, jsonLength: 212}
|
|
426
476
|
* ```
|
|
427
477
|
* @example
|
|
428
478
|
* This example creates a Tools object, and calls the method a second time
|
|
@@ -439,3 +489,4 @@ export interface Tools {
|
|
|
439
489
|
* @since v2.2.0
|
|
440
490
|
*/
|
|
441
491
|
export function createTools(store: Store): Tools;
|
|
492
|
+
/* eslint-enable max-len */
|