tinybase 3.0.0-beta.0 → 3.0.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 (110) hide show
  1. package/bin/cli.js +1 -1
  2. package/lib/checkpoints.d.ts +18 -3
  3. package/lib/checkpoints.js +1 -1
  4. package/lib/checkpoints.js.gz +0 -0
  5. package/lib/debug/checkpoints.d.ts +18 -3
  6. package/lib/debug/checkpoints.js +97 -49
  7. package/lib/debug/indexes.js +31 -16
  8. package/lib/debug/metrics.js +31 -16
  9. package/lib/debug/persisters.d.ts +33 -23
  10. package/lib/debug/persisters.js +10 -5
  11. package/lib/debug/queries.js +2 -2
  12. package/lib/debug/relationships.js +31 -16
  13. package/lib/debug/store.d.ts +2053 -381
  14. package/lib/debug/store.js +444 -106
  15. package/lib/debug/tinybase.js +512 -138
  16. package/lib/debug/tools.d.ts +109 -38
  17. package/lib/debug/tools.js +759 -453
  18. package/lib/debug/ui-react.d.ts +1218 -138
  19. package/lib/debug/ui-react.js +163 -12
  20. package/lib/es6/checkpoints.d.ts +18 -3
  21. package/lib/es6/checkpoints.js +1 -1
  22. package/lib/es6/checkpoints.js.gz +0 -0
  23. package/lib/es6/indexes.js +1 -1
  24. package/lib/es6/indexes.js.gz +0 -0
  25. package/lib/es6/metrics.js +1 -1
  26. package/lib/es6/metrics.js.gz +0 -0
  27. package/lib/es6/persisters.d.ts +33 -23
  28. package/lib/es6/persisters.js +1 -1
  29. package/lib/es6/persisters.js.gz +0 -0
  30. package/lib/es6/relationships.js +1 -1
  31. package/lib/es6/relationships.js.gz +0 -0
  32. package/lib/es6/store.d.ts +2053 -381
  33. package/lib/es6/store.js +1 -1
  34. package/lib/es6/store.js.gz +0 -0
  35. package/lib/es6/tinybase.js +1 -1
  36. package/lib/es6/tinybase.js.gz +0 -0
  37. package/lib/es6/tools.d.ts +109 -38
  38. package/lib/es6/tools.js +1 -1
  39. package/lib/es6/tools.js.gz +0 -0
  40. package/lib/es6/ui-react.d.ts +1218 -138
  41. package/lib/es6/ui-react.js +1 -1
  42. package/lib/es6/ui-react.js.gz +0 -0
  43. package/lib/indexes.js +1 -1
  44. package/lib/indexes.js.gz +0 -0
  45. package/lib/metrics.js +1 -1
  46. package/lib/metrics.js.gz +0 -0
  47. package/lib/persisters.d.ts +33 -23
  48. package/lib/persisters.js +1 -1
  49. package/lib/persisters.js.gz +0 -0
  50. package/lib/relationships.js +1 -1
  51. package/lib/relationships.js.gz +0 -0
  52. package/lib/store.d.ts +2053 -381
  53. package/lib/store.js +1 -1
  54. package/lib/store.js.gz +0 -0
  55. package/lib/tinybase.js +1 -1
  56. package/lib/tinybase.js.gz +0 -0
  57. package/lib/tools.d.ts +109 -38
  58. package/lib/tools.js +1 -1
  59. package/lib/tools.js.gz +0 -0
  60. package/lib/ui-react.d.ts +1218 -138
  61. package/lib/ui-react.js +1 -1
  62. package/lib/ui-react.js.gz +0 -0
  63. package/lib/umd/checkpoints.d.ts +18 -3
  64. package/lib/umd/checkpoints.js +1 -1
  65. package/lib/umd/checkpoints.js.gz +0 -0
  66. package/lib/umd/indexes.js +1 -1
  67. package/lib/umd/indexes.js.gz +0 -0
  68. package/lib/umd/metrics.js +1 -1
  69. package/lib/umd/metrics.js.gz +0 -0
  70. package/lib/umd/persisters.d.ts +33 -23
  71. package/lib/umd/persisters.js +1 -1
  72. package/lib/umd/persisters.js.gz +0 -0
  73. package/lib/umd/relationships.js +1 -1
  74. package/lib/umd/relationships.js.gz +0 -0
  75. package/lib/umd/store.d.ts +2053 -381
  76. package/lib/umd/store.js +1 -1
  77. package/lib/umd/store.js.gz +0 -0
  78. package/lib/umd/tinybase.js +1 -1
  79. package/lib/umd/tinybase.js.gz +0 -0
  80. package/lib/umd/tools.d.ts +109 -38
  81. package/lib/umd/tools.js +1 -1
  82. package/lib/umd/tools.js.gz +0 -0
  83. package/lib/umd/ui-react.d.ts +1218 -138
  84. package/lib/umd/ui-react.js +1 -1
  85. package/lib/umd/ui-react.js.gz +0 -0
  86. package/lib/umd-es6/checkpoints.d.ts +18 -3
  87. package/lib/umd-es6/checkpoints.js +1 -1
  88. package/lib/umd-es6/checkpoints.js.gz +0 -0
  89. package/lib/umd-es6/indexes.js +1 -1
  90. package/lib/umd-es6/indexes.js.gz +0 -0
  91. package/lib/umd-es6/metrics.js +1 -1
  92. package/lib/umd-es6/metrics.js.gz +0 -0
  93. package/lib/umd-es6/persisters.d.ts +33 -23
  94. package/lib/umd-es6/persisters.js +1 -1
  95. package/lib/umd-es6/persisters.js.gz +0 -0
  96. package/lib/umd-es6/relationships.js +1 -1
  97. package/lib/umd-es6/relationships.js.gz +0 -0
  98. package/lib/umd-es6/store.d.ts +2053 -381
  99. package/lib/umd-es6/store.js +1 -1
  100. package/lib/umd-es6/store.js.gz +0 -0
  101. package/lib/umd-es6/tinybase.js +1 -1
  102. package/lib/umd-es6/tinybase.js.gz +0 -0
  103. package/lib/umd-es6/tools.d.ts +109 -38
  104. package/lib/umd-es6/tools.js +1 -1
  105. package/lib/umd-es6/tools.js.gz +0 -0
  106. package/lib/umd-es6/ui-react.d.ts +1218 -138
  107. package/lib/umd-es6/ui-react.js +1 -1
  108. package/lib/umd-es6/ui-react.js.gz +0 -0
  109. package/package.json +20 -20
  110. package/readme.md +27 -16
@@ -10,7 +10,7 @@
10
10
  * @since v2.2.0
11
11
  */
12
12
 
13
- import {Schema, Store} from './store.d';
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: 182}
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 getStoreSchema method returns the Schema of the Store as an object.
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 Schema associated with it,
170
- * the data in the Store will be scanned to attempt to infer a new Schema.
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 Row objects to have a consistent type. If a given Cell Id
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
- * Schema, based on the most common value found.
184
+ * TablesSchema, based on the most common value found.
176
185
  *
177
- * @returns A Schema object for the Store.
186
+ * @returns A TablesSchema object for the Store.
178
187
  * @example
179
- * This example creates a Tools object and gets basic statistics about a Store
180
- * that already has a Schema.
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().setSchema({
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).getStoreSchema();
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 gets basic statistics about a Store
197
- * that doesn't already have a Schema.
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).getStoreSchema();
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 v2.2.0
231
+ * @since v3.0.0
223
232
  */
224
- getStoreSchema(): Schema;
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 Schema associated with it,
231
- * the data in the Store will be scanned to attempt to infer a new Schema. The
232
- * method returns two strings (which should be saved as files) though if no
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 Schema.
329
+ * already has a TablesSchema.
282
330
  * ```js
283
- * const store = createStore().setSchema({
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[40]);
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 Schema.
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[42]);
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 Schema.
400
+ * already has a TablesSchema.
353
401
  * ```js
354
- * const store = createStore().setSchema({
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[14]);
411
+ * console.log(dTsLines[5]);
364
412
  * // -> 'export type PetsTable = {[rowId: Id]: PetsRow};'
365
- * console.log(dTsLines[19]);
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[73]);
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 Schema.
422
+ * doesn't already have a TablesSchema.
375
423
  * ```js
376
424
  * const store = createStore().setTable('pets', {
377
425
  * fido: {price: 5},
@@ -381,21 +429,42 @@ 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[14]);
432
+ * console.log(dTsLines[5]);
385
433
  * // -> 'export type PetsTable = {[rowId: Id]: PetsRow};'
386
- * console.log(dTsLines[19]);
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[75]);
438
+ * console.log(tsLines[74]);
391
439
  * // -> ' hasPetsTable: (): boolean => store.hasTable(PETS),'
392
440
  * ```
393
441
  * @category Modelling
394
442
  * @since v2.2.0
395
443
  */
396
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;
397
465
  }
398
466
 
467
+ /* eslint-disable max-len */
399
468
  /**
400
469
  * The createTools function creates a Tools object, and is the main entry point
401
470
  * into the tools module.
@@ -419,10 +488,11 @@ export interface Tools {
419
488
  * .setTable('species', {
420
489
  * dog: {price: 5},
421
490
  * cat: {price: 4},
422
- * });
491
+ * })
492
+ * .setValues({open: true, employees: 3});
423
493
  * const tools = createTools(store);
424
494
  * console.log(tools.getStoreStats());
425
- * // -> {totalTables: 2, totalRows: 5, totalCells: 8, jsonLength: 182}
495
+ * // -> {totalTables: 2, totalRows: 5, totalCells: 8, totalValues: 2, jsonLength: 212}
426
496
  * ```
427
497
  * @example
428
498
  * This example creates a Tools object, and calls the method a second time
@@ -439,3 +509,4 @@ export interface Tools {
439
509
  * @since v2.2.0
440
510
  */
441
511
  export function createTools(store: Store): Tools;
512
+ /* eslint-enable max-len */