tinybase 3.1.0-beta.2 → 3.1.0-beta.3
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/cjs/tools.cjs +1 -1
- package/lib/cjs/tools.cjs.gz +0 -0
- package/lib/cjs/tools.d.ts +193 -27
- package/lib/cjs-es6/tools.cjs +1 -1
- package/lib/cjs-es6/tools.cjs.gz +0 -0
- package/lib/cjs-es6/tools.d.ts +193 -27
- package/lib/debug/tools.d.ts +193 -27
- package/lib/debug/tools.js +1266 -451
- package/lib/es6/tools.d.ts +193 -27
- package/lib/es6/tools.js +1 -1
- package/lib/es6/tools.js.gz +0 -0
- package/lib/tools.d.ts +193 -27
- package/lib/tools.js +1 -1
- package/lib/tools.js.gz +0 -0
- package/lib/umd/tools.d.ts +193 -27
- package/lib/umd/tools.js +1 -1
- package/lib/umd/tools.js.gz +0 -0
- package/lib/umd-es6/tools.d.ts +193 -27
- package/lib/umd-es6/tools.js +1 -1
- package/lib/umd-es6/tools.js.gz +0 -0
- package/package.json +17 -17
- package/readme.md +1 -1
package/lib/cjs-es6/tools.d.ts
CHANGED
|
@@ -272,9 +272,9 @@ export interface Tools {
|
|
|
272
272
|
getStoreValuesSchema(): ValuesSchema;
|
|
273
273
|
|
|
274
274
|
/**
|
|
275
|
-
* The getStoreApi method returns code-generated
|
|
276
|
-
* describe the schema of a Store and React bindings (since v3.1.0) in an
|
|
277
|
-
* style.
|
|
275
|
+
* The getStoreApi method returns code-generated `.d.ts` and `.ts(x)` files
|
|
276
|
+
* that describe the schema of a Store and React bindings (since v3.1.0) in an
|
|
277
|
+
* ORM style.
|
|
278
278
|
*
|
|
279
279
|
* If the Store does not already have an explicit TablesSchema or ValuesSchema
|
|
280
280
|
* associated with it, the data in the Store will be scanned to attempt to
|
|
@@ -290,12 +290,12 @@ export interface Tools {
|
|
|
290
290
|
* - `[storeName]-ui-react.d.ts`
|
|
291
291
|
* - `[storeName]-ui-react.tsx`
|
|
292
292
|
*
|
|
293
|
-
* Also you should save these alongside each other so that the
|
|
294
|
-
* can import types from the
|
|
293
|
+
* Also you should save these alongside each other so that the `.ts(x)` files
|
|
294
|
+
* can import types from the `.d.ts` files.
|
|
295
295
|
*
|
|
296
|
-
* The
|
|
297
|
-
* main TinyBase Store and React binding files, but provide named types
|
|
298
|
-
* methods that describe the domain of the schema in the
|
|
296
|
+
* The `.d.ts` and `.ts(x)` files that are generated are designed to resemble
|
|
297
|
+
* the main TinyBase Store and React binding files, but provide named types
|
|
298
|
+
* and methods that describe the domain of the schema in the Store.
|
|
299
299
|
*
|
|
300
300
|
* For example, from a Store that has a `pets` Table, you will get methods
|
|
301
301
|
* like `getPetsTable`, types like `PetsRow`, and hooks and components that
|
|
@@ -347,9 +347,7 @@ export interface Tools {
|
|
|
347
347
|
*
|
|
348
348
|
* const dTsLines = dTs.split('\n');
|
|
349
349
|
* console.log(dTsLines[3]);
|
|
350
|
-
* // ->
|
|
351
|
-
* console.log(dTsLines[6]);
|
|
352
|
-
* // -> 'export type PetsRow = {\'price\'?: number;};'
|
|
350
|
+
* // -> `export type Tables = {'pets'?: {[rowId: Id]: {'price'?: number}}};`
|
|
353
351
|
*
|
|
354
352
|
* const tsLines = ts.split('\n');
|
|
355
353
|
* console.log(tsLines[39]);
|
|
@@ -368,9 +366,7 @@ export interface Tools {
|
|
|
368
366
|
*
|
|
369
367
|
* const dTsLines = dTs.split('\n');
|
|
370
368
|
* console.log(dTsLines[3]);
|
|
371
|
-
* // ->
|
|
372
|
-
* console.log(dTsLines[6]);
|
|
373
|
-
* // -> 'export type PetsRow = {\'price\': number;};'
|
|
369
|
+
* // -> `export type Tables = {'pets'?: {[rowId: Id]: {'price': number}}};`
|
|
374
370
|
*
|
|
375
371
|
* const tsLines = ts.split('\n');
|
|
376
372
|
* console.log(tsLines[41]);
|
|
@@ -382,9 +378,9 @@ export interface Tools {
|
|
|
382
378
|
getStoreApi(storeName: string): [string, string, string, string];
|
|
383
379
|
|
|
384
380
|
/**
|
|
385
|
-
* The getPrettyStoreApi method attempts to
|
|
386
|
-
*
|
|
387
|
-
*
|
|
381
|
+
* The getPrettyStoreApi method attempts to return prettified code-generated
|
|
382
|
+
* `.d.ts` and `.ts(x)` files that describe the schema of a Store and React
|
|
383
|
+
* bindings (since v3.1.0) in an ORM style.
|
|
388
384
|
*
|
|
389
385
|
* This is simply a wrapper around the getStoreApi method that attempts to
|
|
390
386
|
* invoke the `prettier` module (which it hopes you have installed) to format
|
|
@@ -403,8 +399,8 @@ export interface Tools {
|
|
|
403
399
|
* - `[storeName]-ui-react.d.ts`
|
|
404
400
|
* - `[storeName]-ui-react.tsx`
|
|
405
401
|
*
|
|
406
|
-
* Also you should save these alongside each other so that the
|
|
407
|
-
* can import types from the
|
|
402
|
+
* Also you should save these alongside each other so that the `.ts(x)` files
|
|
403
|
+
* can import types from the `.d.ts` files.
|
|
408
404
|
*
|
|
409
405
|
* See the documentation for the getStoreApi method for details of the content
|
|
410
406
|
* of the generated files.
|
|
@@ -429,12 +425,10 @@ export interface Tools {
|
|
|
429
425
|
*
|
|
430
426
|
* const dTsLines = dTs.split('\n');
|
|
431
427
|
* console.log(dTsLines[5]);
|
|
432
|
-
* // ->
|
|
433
|
-
* console.log(dTsLines[10]);
|
|
434
|
-
* // -> 'export type PetsRow = {price?: number};'
|
|
428
|
+
* // -> `export type Tables = {pets?: {[rowId: Id]: {price?: number}}};`
|
|
435
429
|
*
|
|
436
430
|
* const tsLines = ts.split('\n');
|
|
437
|
-
* console.log(tsLines[
|
|
431
|
+
* console.log(tsLines[79]);
|
|
438
432
|
* // -> ' hasPetsTable: (): boolean => store.hasTable(PETS),'
|
|
439
433
|
* ```
|
|
440
434
|
* @example
|
|
@@ -452,12 +446,10 @@ export interface Tools {
|
|
|
452
446
|
*
|
|
453
447
|
* const dTsLines = dTs.split('\n');
|
|
454
448
|
* console.log(dTsLines[5]);
|
|
455
|
-
* // -> 'export type
|
|
456
|
-
* console.log(dTsLines[10]);
|
|
457
|
-
* // -> 'export type PetsRow = {price: number};'
|
|
449
|
+
* // -> 'export type Tables = {pets?: {[rowId: Id]: {price: number}}};'
|
|
458
450
|
*
|
|
459
451
|
* const tsLines = ts.split('\n');
|
|
460
|
-
* console.log(tsLines[
|
|
452
|
+
* console.log(tsLines[81]);
|
|
461
453
|
* // -> ' hasPetsTable: (): boolean => store.hasTable(PETS),'
|
|
462
454
|
* ```
|
|
463
455
|
* @category Modelling
|
|
@@ -467,6 +459,180 @@ export interface Tools {
|
|
|
467
459
|
storeName: string,
|
|
468
460
|
): Promise<[string, string, string, string]>;
|
|
469
461
|
|
|
462
|
+
/**
|
|
463
|
+
* The getStoreRefinement method returns code-generated `.d.ts` files that
|
|
464
|
+
* refine the Store and React bindings to have schema-specific methods and
|
|
465
|
+
* types.
|
|
466
|
+
*
|
|
467
|
+
* If the Store does not already have an explicit TablesSchema or ValuesSchema
|
|
468
|
+
* associated with it, the data in the Store will be scanned to attempt to
|
|
469
|
+
* infer new schemas. The method returns two strings (which should be saved as
|
|
470
|
+
* files) though if no schema can be inferred, the strings will be empty.
|
|
471
|
+
*
|
|
472
|
+
* The method takes a single argument which represents the name you want the
|
|
473
|
+
* generated store object to have in code. You are expected to save the two
|
|
474
|
+
* files yourself, as, respectively:
|
|
475
|
+
*
|
|
476
|
+
* - `[storeName]-refinement.d.ts`
|
|
477
|
+
* - `[storeName]-ui-react-refinement.d.ts`
|
|
478
|
+
*
|
|
479
|
+
* You should save these alongside each other.
|
|
480
|
+
*
|
|
481
|
+
* The `.d.ts` files that are generated are designed to resemble the main
|
|
482
|
+
* TinyBase Store and React binding files. In your application you will need
|
|
483
|
+
* to coerce the Store to the refined interface to benefit from the type
|
|
484
|
+
* safety. One easy way to do this is to cast the TinyBase module to the
|
|
485
|
+
* refined module in bulk, and then destructure to get the refined imports:
|
|
486
|
+
*
|
|
487
|
+
* ```js yolo
|
|
488
|
+
* import * as tinybase from 'tinybase';
|
|
489
|
+
* import shopRefinement from './shop-refinement.d';
|
|
490
|
+
*
|
|
491
|
+
* const {createStore} = tinybase as typeof shopRefinement;
|
|
492
|
+
*
|
|
493
|
+
* const shop = createStore(); // shop is a refined Store
|
|
494
|
+
* // ...
|
|
495
|
+
* ```
|
|
496
|
+
*
|
|
497
|
+
* This is a particularly good approach for the React module which has many
|
|
498
|
+
* top-level hook and component functions. You don't need to refine them one
|
|
499
|
+
* by one:
|
|
500
|
+
*
|
|
501
|
+
* ```js yolo
|
|
502
|
+
* import * as tinybaseUiReact from 'tinybase/ui-react';
|
|
503
|
+
* import shopUiReactRefinement from './shop-ui-react-refinement.d';
|
|
504
|
+
*
|
|
505
|
+
* const {
|
|
506
|
+
* useTables, // a refined hook
|
|
507
|
+
* RowView, // a refined component
|
|
508
|
+
* // ...
|
|
509
|
+
* } = tinybaseUiReact as typeof shopUiReactRefinement;
|
|
510
|
+
*
|
|
511
|
+
* // ...
|
|
512
|
+
* ```
|
|
513
|
+
*
|
|
514
|
+
* If you need access to refined types from the generated module definition,
|
|
515
|
+
* you can access them as normal, in a separate import:
|
|
516
|
+
*
|
|
517
|
+
* ```js yolo
|
|
518
|
+
* import {Tables} from './shop-refinement.d';
|
|
519
|
+
* ```
|
|
520
|
+
*
|
|
521
|
+
* @param storeName The name you want to provide to the generated Store, which
|
|
522
|
+
* should also be used to save the `.d.ts` files.
|
|
523
|
+
* @returns A pair of strings representing the contents of the `.d.ts` files
|
|
524
|
+
* for the generated Store and React modules.
|
|
525
|
+
* @example
|
|
526
|
+
* This example creates a Tools object and generates type refinements for a
|
|
527
|
+
* Store that already has a TablesSchema.
|
|
528
|
+
* ```js
|
|
529
|
+
* const store = createStore().setTablesSchema({
|
|
530
|
+
* pets: {
|
|
531
|
+
* price: {type: 'number'},
|
|
532
|
+
* },
|
|
533
|
+
* });
|
|
534
|
+
* const [refinementDTs, uiReactRefinementDTs] =
|
|
535
|
+
* createTools(store).getStoreRefinement('shop');
|
|
536
|
+
*
|
|
537
|
+
* const dTsLines = refinementDTs.split('\n');
|
|
538
|
+
* // console.log(dTsLines[3]);
|
|
539
|
+
* // // -> ''
|
|
540
|
+
* // console.log(dTsLines[6]);
|
|
541
|
+
* // // -> ''
|
|
542
|
+
* ```
|
|
543
|
+
* @example
|
|
544
|
+
* This example creates a Tools object and generates code for a Store that
|
|
545
|
+
* doesn't already have a TablesSchema.
|
|
546
|
+
* ```js
|
|
547
|
+
* const store = createStore().setTable('pets', {
|
|
548
|
+
* fido: {price: 5},
|
|
549
|
+
* felix: {price: 4},
|
|
550
|
+
* });
|
|
551
|
+
* const [refinementDTs, uiReactRefinementDTs] =
|
|
552
|
+
* createTools(store).getStoreRefinement('shop');
|
|
553
|
+
*
|
|
554
|
+
* const dTsLines = refinementDTs.split('\n');
|
|
555
|
+
* // console.log(dTsLines[3]);
|
|
556
|
+
* // // -> ''
|
|
557
|
+
* // console.log(dTsLines[6]);
|
|
558
|
+
* // // -> ''
|
|
559
|
+
* ```
|
|
560
|
+
* @category Modelling
|
|
561
|
+
* @since v3.1.0
|
|
562
|
+
*/
|
|
563
|
+
getStoreRefinement(storeName: string): [string, string];
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* The getPrettyStoreRefinement method attempts to return prettified
|
|
567
|
+
* code-generated `.d.ts` files that refine the Store and React bindings to
|
|
568
|
+
* have schema-specific methods and types.
|
|
569
|
+
*
|
|
570
|
+
* This is simply a wrapper around the getStoreRefinement method that attempts
|
|
571
|
+
* to invoke the `prettier` module (which it hopes you have installed) to
|
|
572
|
+
* format the generated code. If `prettier` is not present, the output will
|
|
573
|
+
* resemble that of the underlying getStoreRefinement method.
|
|
574
|
+
*
|
|
575
|
+
* The method is asynchronous, so you should use the `await` keyword or handle
|
|
576
|
+
* the results as a promise.
|
|
577
|
+
*
|
|
578
|
+
* The method takes a single argument which represents the name you want the
|
|
579
|
+
* generated store object to have in code. You are expected to save the two
|
|
580
|
+
* files yourself, as, respectively:
|
|
581
|
+
*
|
|
582
|
+
* - `[storeName]-refinement.d.ts`
|
|
583
|
+
* - `[storeName]-ui-react-refinement.d.ts`
|
|
584
|
+
*
|
|
585
|
+
* You should save these alongside each other.
|
|
586
|
+
*
|
|
587
|
+
* See the documentation for the getStoreRefinement method for details of the
|
|
588
|
+
* content of the generated files.
|
|
589
|
+
*
|
|
590
|
+
* @param storeName The name you want to provide to the generated Store, which
|
|
591
|
+
* should also be used to save the `.d.ts` files.
|
|
592
|
+
* @returns A pair of strings representing the contents of the `.d.ts` files
|
|
593
|
+
* for the generated Store and React modules.
|
|
594
|
+
* @example
|
|
595
|
+
* This example creates a Tools object and generates type refinements for a
|
|
596
|
+
* Store that already has a TablesSchema.
|
|
597
|
+
* ```js
|
|
598
|
+
* const store = createStore().setTablesSchema({
|
|
599
|
+
* pets: {
|
|
600
|
+
* price: {type: 'number'},
|
|
601
|
+
* },
|
|
602
|
+
* });
|
|
603
|
+
* const [refinementDTs, uiReactRefinementDTs] = await createTools(
|
|
604
|
+
* store,
|
|
605
|
+
* ).getPrettyStoreRefinement('shop');
|
|
606
|
+
*
|
|
607
|
+
* const dTsLines = refinementDTs.split('\n');
|
|
608
|
+
* // console.log(dTsLines[3]);
|
|
609
|
+
* // // -> ''
|
|
610
|
+
* // console.log(dTsLines[6]);
|
|
611
|
+
* // // -> ''
|
|
612
|
+
* ```
|
|
613
|
+
* @example
|
|
614
|
+
* This example creates a Tools object and generates code for a Store that
|
|
615
|
+
* doesn't already have a TablesSchema.
|
|
616
|
+
* ```js
|
|
617
|
+
* const store = createStore().setTable('pets', {
|
|
618
|
+
* fido: {price: 5},
|
|
619
|
+
* felix: {price: 4},
|
|
620
|
+
* });
|
|
621
|
+
* const [refinementDTs, uiReactRefinementDTs] = await createTools(
|
|
622
|
+
* store,
|
|
623
|
+
* ).getPrettyStoreRefinement('shop');
|
|
624
|
+
*
|
|
625
|
+
* const dTsLines = refinementDTs.split('\n');
|
|
626
|
+
* // console.log(dTsLines[3]);
|
|
627
|
+
* // // -> ''
|
|
628
|
+
* // console.log(dTsLines[6]);
|
|
629
|
+
* // // -> ''
|
|
630
|
+
* ```
|
|
631
|
+
* @category Modelling
|
|
632
|
+
* @since v3.1.0
|
|
633
|
+
*/
|
|
634
|
+
getPrettyStoreRefinement(storeName: string): Promise<[string, string]>;
|
|
635
|
+
|
|
470
636
|
/**
|
|
471
637
|
* The getStore method returns a reference to the underlying Store that is
|
|
472
638
|
* backing this Tools object.
|
package/lib/debug/tools.d.ts
CHANGED
|
@@ -272,9 +272,9 @@ export interface Tools {
|
|
|
272
272
|
getStoreValuesSchema(): ValuesSchema;
|
|
273
273
|
|
|
274
274
|
/**
|
|
275
|
-
* The getStoreApi method returns code-generated
|
|
276
|
-
* describe the schema of a Store and React bindings (since v3.1.0) in an
|
|
277
|
-
* style.
|
|
275
|
+
* The getStoreApi method returns code-generated `.d.ts` and `.ts(x)` files
|
|
276
|
+
* that describe the schema of a Store and React bindings (since v3.1.0) in an
|
|
277
|
+
* ORM style.
|
|
278
278
|
*
|
|
279
279
|
* If the Store does not already have an explicit TablesSchema or ValuesSchema
|
|
280
280
|
* associated with it, the data in the Store will be scanned to attempt to
|
|
@@ -290,12 +290,12 @@ export interface Tools {
|
|
|
290
290
|
* - `[storeName]-ui-react.d.ts`
|
|
291
291
|
* - `[storeName]-ui-react.tsx`
|
|
292
292
|
*
|
|
293
|
-
* Also you should save these alongside each other so that the
|
|
294
|
-
* can import types from the
|
|
293
|
+
* Also you should save these alongside each other so that the `.ts(x)` files
|
|
294
|
+
* can import types from the `.d.ts` files.
|
|
295
295
|
*
|
|
296
|
-
* The
|
|
297
|
-
* main TinyBase Store and React binding files, but provide named types
|
|
298
|
-
* methods that describe the domain of the schema in the
|
|
296
|
+
* The `.d.ts` and `.ts(x)` files that are generated are designed to resemble
|
|
297
|
+
* the main TinyBase Store and React binding files, but provide named types
|
|
298
|
+
* and methods that describe the domain of the schema in the Store.
|
|
299
299
|
*
|
|
300
300
|
* For example, from a Store that has a `pets` Table, you will get methods
|
|
301
301
|
* like `getPetsTable`, types like `PetsRow`, and hooks and components that
|
|
@@ -347,9 +347,7 @@ export interface Tools {
|
|
|
347
347
|
*
|
|
348
348
|
* const dTsLines = dTs.split('\n');
|
|
349
349
|
* console.log(dTsLines[3]);
|
|
350
|
-
* // ->
|
|
351
|
-
* console.log(dTsLines[6]);
|
|
352
|
-
* // -> 'export type PetsRow = {\'price\'?: number;};'
|
|
350
|
+
* // -> `export type Tables = {'pets'?: {[rowId: Id]: {'price'?: number}}};`
|
|
353
351
|
*
|
|
354
352
|
* const tsLines = ts.split('\n');
|
|
355
353
|
* console.log(tsLines[39]);
|
|
@@ -368,9 +366,7 @@ export interface Tools {
|
|
|
368
366
|
*
|
|
369
367
|
* const dTsLines = dTs.split('\n');
|
|
370
368
|
* console.log(dTsLines[3]);
|
|
371
|
-
* // ->
|
|
372
|
-
* console.log(dTsLines[6]);
|
|
373
|
-
* // -> 'export type PetsRow = {\'price\': number;};'
|
|
369
|
+
* // -> `export type Tables = {'pets'?: {[rowId: Id]: {'price': number}}};`
|
|
374
370
|
*
|
|
375
371
|
* const tsLines = ts.split('\n');
|
|
376
372
|
* console.log(tsLines[41]);
|
|
@@ -382,9 +378,9 @@ export interface Tools {
|
|
|
382
378
|
getStoreApi(storeName: string): [string, string, string, string];
|
|
383
379
|
|
|
384
380
|
/**
|
|
385
|
-
* The getPrettyStoreApi method attempts to
|
|
386
|
-
*
|
|
387
|
-
*
|
|
381
|
+
* The getPrettyStoreApi method attempts to return prettified code-generated
|
|
382
|
+
* `.d.ts` and `.ts(x)` files that describe the schema of a Store and React
|
|
383
|
+
* bindings (since v3.1.0) in an ORM style.
|
|
388
384
|
*
|
|
389
385
|
* This is simply a wrapper around the getStoreApi method that attempts to
|
|
390
386
|
* invoke the `prettier` module (which it hopes you have installed) to format
|
|
@@ -403,8 +399,8 @@ export interface Tools {
|
|
|
403
399
|
* - `[storeName]-ui-react.d.ts`
|
|
404
400
|
* - `[storeName]-ui-react.tsx`
|
|
405
401
|
*
|
|
406
|
-
* Also you should save these alongside each other so that the
|
|
407
|
-
* can import types from the
|
|
402
|
+
* Also you should save these alongside each other so that the `.ts(x)` files
|
|
403
|
+
* can import types from the `.d.ts` files.
|
|
408
404
|
*
|
|
409
405
|
* See the documentation for the getStoreApi method for details of the content
|
|
410
406
|
* of the generated files.
|
|
@@ -429,12 +425,10 @@ export interface Tools {
|
|
|
429
425
|
*
|
|
430
426
|
* const dTsLines = dTs.split('\n');
|
|
431
427
|
* console.log(dTsLines[5]);
|
|
432
|
-
* // ->
|
|
433
|
-
* console.log(dTsLines[10]);
|
|
434
|
-
* // -> 'export type PetsRow = {price?: number};'
|
|
428
|
+
* // -> `export type Tables = {pets?: {[rowId: Id]: {price?: number}}};`
|
|
435
429
|
*
|
|
436
430
|
* const tsLines = ts.split('\n');
|
|
437
|
-
* console.log(tsLines[
|
|
431
|
+
* console.log(tsLines[79]);
|
|
438
432
|
* // -> ' hasPetsTable: (): boolean => store.hasTable(PETS),'
|
|
439
433
|
* ```
|
|
440
434
|
* @example
|
|
@@ -452,12 +446,10 @@ export interface Tools {
|
|
|
452
446
|
*
|
|
453
447
|
* const dTsLines = dTs.split('\n');
|
|
454
448
|
* console.log(dTsLines[5]);
|
|
455
|
-
* // -> 'export type
|
|
456
|
-
* console.log(dTsLines[10]);
|
|
457
|
-
* // -> 'export type PetsRow = {price: number};'
|
|
449
|
+
* // -> 'export type Tables = {pets?: {[rowId: Id]: {price: number}}};'
|
|
458
450
|
*
|
|
459
451
|
* const tsLines = ts.split('\n');
|
|
460
|
-
* console.log(tsLines[
|
|
452
|
+
* console.log(tsLines[81]);
|
|
461
453
|
* // -> ' hasPetsTable: (): boolean => store.hasTable(PETS),'
|
|
462
454
|
* ```
|
|
463
455
|
* @category Modelling
|
|
@@ -467,6 +459,180 @@ export interface Tools {
|
|
|
467
459
|
storeName: string,
|
|
468
460
|
): Promise<[string, string, string, string]>;
|
|
469
461
|
|
|
462
|
+
/**
|
|
463
|
+
* The getStoreRefinement method returns code-generated `.d.ts` files that
|
|
464
|
+
* refine the Store and React bindings to have schema-specific methods and
|
|
465
|
+
* types.
|
|
466
|
+
*
|
|
467
|
+
* If the Store does not already have an explicit TablesSchema or ValuesSchema
|
|
468
|
+
* associated with it, the data in the Store will be scanned to attempt to
|
|
469
|
+
* infer new schemas. The method returns two strings (which should be saved as
|
|
470
|
+
* files) though if no schema can be inferred, the strings will be empty.
|
|
471
|
+
*
|
|
472
|
+
* The method takes a single argument which represents the name you want the
|
|
473
|
+
* generated store object to have in code. You are expected to save the two
|
|
474
|
+
* files yourself, as, respectively:
|
|
475
|
+
*
|
|
476
|
+
* - `[storeName]-refinement.d.ts`
|
|
477
|
+
* - `[storeName]-ui-react-refinement.d.ts`
|
|
478
|
+
*
|
|
479
|
+
* You should save these alongside each other.
|
|
480
|
+
*
|
|
481
|
+
* The `.d.ts` files that are generated are designed to resemble the main
|
|
482
|
+
* TinyBase Store and React binding files. In your application you will need
|
|
483
|
+
* to coerce the Store to the refined interface to benefit from the type
|
|
484
|
+
* safety. One easy way to do this is to cast the TinyBase module to the
|
|
485
|
+
* refined module in bulk, and then destructure to get the refined imports:
|
|
486
|
+
*
|
|
487
|
+
* ```js yolo
|
|
488
|
+
* import * as tinybase from 'tinybase';
|
|
489
|
+
* import shopRefinement from './shop-refinement.d';
|
|
490
|
+
*
|
|
491
|
+
* const {createStore} = tinybase as typeof shopRefinement;
|
|
492
|
+
*
|
|
493
|
+
* const shop = createStore(); // shop is a refined Store
|
|
494
|
+
* // ...
|
|
495
|
+
* ```
|
|
496
|
+
*
|
|
497
|
+
* This is a particularly good approach for the React module which has many
|
|
498
|
+
* top-level hook and component functions. You don't need to refine them one
|
|
499
|
+
* by one:
|
|
500
|
+
*
|
|
501
|
+
* ```js yolo
|
|
502
|
+
* import * as tinybaseUiReact from 'tinybase/ui-react';
|
|
503
|
+
* import shopUiReactRefinement from './shop-ui-react-refinement.d';
|
|
504
|
+
*
|
|
505
|
+
* const {
|
|
506
|
+
* useTables, // a refined hook
|
|
507
|
+
* RowView, // a refined component
|
|
508
|
+
* // ...
|
|
509
|
+
* } = tinybaseUiReact as typeof shopUiReactRefinement;
|
|
510
|
+
*
|
|
511
|
+
* // ...
|
|
512
|
+
* ```
|
|
513
|
+
*
|
|
514
|
+
* If you need access to refined types from the generated module definition,
|
|
515
|
+
* you can access them as normal, in a separate import:
|
|
516
|
+
*
|
|
517
|
+
* ```js yolo
|
|
518
|
+
* import {Tables} from './shop-refinement.d';
|
|
519
|
+
* ```
|
|
520
|
+
*
|
|
521
|
+
* @param storeName The name you want to provide to the generated Store, which
|
|
522
|
+
* should also be used to save the `.d.ts` files.
|
|
523
|
+
* @returns A pair of strings representing the contents of the `.d.ts` files
|
|
524
|
+
* for the generated Store and React modules.
|
|
525
|
+
* @example
|
|
526
|
+
* This example creates a Tools object and generates type refinements for a
|
|
527
|
+
* Store that already has a TablesSchema.
|
|
528
|
+
* ```js
|
|
529
|
+
* const store = createStore().setTablesSchema({
|
|
530
|
+
* pets: {
|
|
531
|
+
* price: {type: 'number'},
|
|
532
|
+
* },
|
|
533
|
+
* });
|
|
534
|
+
* const [refinementDTs, uiReactRefinementDTs] =
|
|
535
|
+
* createTools(store).getStoreRefinement('shop');
|
|
536
|
+
*
|
|
537
|
+
* const dTsLines = refinementDTs.split('\n');
|
|
538
|
+
* // console.log(dTsLines[3]);
|
|
539
|
+
* // // -> ''
|
|
540
|
+
* // console.log(dTsLines[6]);
|
|
541
|
+
* // // -> ''
|
|
542
|
+
* ```
|
|
543
|
+
* @example
|
|
544
|
+
* This example creates a Tools object and generates code for a Store that
|
|
545
|
+
* doesn't already have a TablesSchema.
|
|
546
|
+
* ```js
|
|
547
|
+
* const store = createStore().setTable('pets', {
|
|
548
|
+
* fido: {price: 5},
|
|
549
|
+
* felix: {price: 4},
|
|
550
|
+
* });
|
|
551
|
+
* const [refinementDTs, uiReactRefinementDTs] =
|
|
552
|
+
* createTools(store).getStoreRefinement('shop');
|
|
553
|
+
*
|
|
554
|
+
* const dTsLines = refinementDTs.split('\n');
|
|
555
|
+
* // console.log(dTsLines[3]);
|
|
556
|
+
* // // -> ''
|
|
557
|
+
* // console.log(dTsLines[6]);
|
|
558
|
+
* // // -> ''
|
|
559
|
+
* ```
|
|
560
|
+
* @category Modelling
|
|
561
|
+
* @since v3.1.0
|
|
562
|
+
*/
|
|
563
|
+
getStoreRefinement(storeName: string): [string, string];
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* The getPrettyStoreRefinement method attempts to return prettified
|
|
567
|
+
* code-generated `.d.ts` files that refine the Store and React bindings to
|
|
568
|
+
* have schema-specific methods and types.
|
|
569
|
+
*
|
|
570
|
+
* This is simply a wrapper around the getStoreRefinement method that attempts
|
|
571
|
+
* to invoke the `prettier` module (which it hopes you have installed) to
|
|
572
|
+
* format the generated code. If `prettier` is not present, the output will
|
|
573
|
+
* resemble that of the underlying getStoreRefinement method.
|
|
574
|
+
*
|
|
575
|
+
* The method is asynchronous, so you should use the `await` keyword or handle
|
|
576
|
+
* the results as a promise.
|
|
577
|
+
*
|
|
578
|
+
* The method takes a single argument which represents the name you want the
|
|
579
|
+
* generated store object to have in code. You are expected to save the two
|
|
580
|
+
* files yourself, as, respectively:
|
|
581
|
+
*
|
|
582
|
+
* - `[storeName]-refinement.d.ts`
|
|
583
|
+
* - `[storeName]-ui-react-refinement.d.ts`
|
|
584
|
+
*
|
|
585
|
+
* You should save these alongside each other.
|
|
586
|
+
*
|
|
587
|
+
* See the documentation for the getStoreRefinement method for details of the
|
|
588
|
+
* content of the generated files.
|
|
589
|
+
*
|
|
590
|
+
* @param storeName The name you want to provide to the generated Store, which
|
|
591
|
+
* should also be used to save the `.d.ts` files.
|
|
592
|
+
* @returns A pair of strings representing the contents of the `.d.ts` files
|
|
593
|
+
* for the generated Store and React modules.
|
|
594
|
+
* @example
|
|
595
|
+
* This example creates a Tools object and generates type refinements for a
|
|
596
|
+
* Store that already has a TablesSchema.
|
|
597
|
+
* ```js
|
|
598
|
+
* const store = createStore().setTablesSchema({
|
|
599
|
+
* pets: {
|
|
600
|
+
* price: {type: 'number'},
|
|
601
|
+
* },
|
|
602
|
+
* });
|
|
603
|
+
* const [refinementDTs, uiReactRefinementDTs] = await createTools(
|
|
604
|
+
* store,
|
|
605
|
+
* ).getPrettyStoreRefinement('shop');
|
|
606
|
+
*
|
|
607
|
+
* const dTsLines = refinementDTs.split('\n');
|
|
608
|
+
* // console.log(dTsLines[3]);
|
|
609
|
+
* // // -> ''
|
|
610
|
+
* // console.log(dTsLines[6]);
|
|
611
|
+
* // // -> ''
|
|
612
|
+
* ```
|
|
613
|
+
* @example
|
|
614
|
+
* This example creates a Tools object and generates code for a Store that
|
|
615
|
+
* doesn't already have a TablesSchema.
|
|
616
|
+
* ```js
|
|
617
|
+
* const store = createStore().setTable('pets', {
|
|
618
|
+
* fido: {price: 5},
|
|
619
|
+
* felix: {price: 4},
|
|
620
|
+
* });
|
|
621
|
+
* const [refinementDTs, uiReactRefinementDTs] = await createTools(
|
|
622
|
+
* store,
|
|
623
|
+
* ).getPrettyStoreRefinement('shop');
|
|
624
|
+
*
|
|
625
|
+
* const dTsLines = refinementDTs.split('\n');
|
|
626
|
+
* // console.log(dTsLines[3]);
|
|
627
|
+
* // // -> ''
|
|
628
|
+
* // console.log(dTsLines[6]);
|
|
629
|
+
* // // -> ''
|
|
630
|
+
* ```
|
|
631
|
+
* @category Modelling
|
|
632
|
+
* @since v3.1.0
|
|
633
|
+
*/
|
|
634
|
+
getPrettyStoreRefinement(storeName: string): Promise<[string, string]>;
|
|
635
|
+
|
|
470
636
|
/**
|
|
471
637
|
* The getStore method returns a reference to the underlying Store that is
|
|
472
638
|
* backing this Tools object.
|