tinybase 3.1.0-beta.3 → 3.1.0-beta.4
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 +13 -11
- package/lib/cjs/checkpoints.d.ts +13 -11
- package/lib/cjs/indexes.d.ts +15 -7
- package/lib/cjs/metrics.d.ts +9 -7
- package/lib/cjs/persisters.d.ts +30 -24
- package/lib/cjs/queries.d.ts +10 -6
- package/lib/cjs/relationships.d.ts +15 -7
- package/lib/cjs/store.d.ts +1190 -291
- package/lib/cjs/tools.cjs +1 -1
- package/lib/cjs/tools.cjs.gz +0 -0
- package/lib/cjs/tools.d.ts +12 -178
- package/lib/cjs-es6/checkpoints.d.ts +13 -11
- package/lib/cjs-es6/indexes.d.ts +15 -7
- package/lib/cjs-es6/metrics.d.ts +9 -7
- package/lib/cjs-es6/persisters.d.ts +30 -24
- package/lib/cjs-es6/queries.d.ts +10 -6
- package/lib/cjs-es6/relationships.d.ts +15 -7
- package/lib/cjs-es6/store.d.ts +1190 -291
- package/lib/cjs-es6/tools.cjs +1 -1
- package/lib/cjs-es6/tools.cjs.gz +0 -0
- package/lib/cjs-es6/tools.d.ts +12 -178
- package/lib/debug/checkpoints.d.ts +13 -11
- package/lib/debug/indexes.d.ts +15 -7
- package/lib/debug/metrics.d.ts +9 -7
- package/lib/debug/persisters.d.ts +30 -24
- package/lib/debug/queries.d.ts +10 -6
- package/lib/debug/relationships.d.ts +15 -7
- package/lib/debug/store.d.ts +1190 -291
- package/lib/debug/tools.d.ts +12 -178
- package/lib/debug/tools.js +14 -621
- package/lib/es6/checkpoints.d.ts +13 -11
- package/lib/es6/indexes.d.ts +15 -7
- package/lib/es6/metrics.d.ts +9 -7
- package/lib/es6/persisters.d.ts +30 -24
- package/lib/es6/queries.d.ts +10 -6
- package/lib/es6/relationships.d.ts +15 -7
- package/lib/es6/store.d.ts +1190 -291
- package/lib/es6/tools.d.ts +12 -178
- package/lib/es6/tools.js +1 -1
- package/lib/es6/tools.js.gz +0 -0
- package/lib/indexes.d.ts +15 -7
- package/lib/metrics.d.ts +9 -7
- package/lib/persisters.d.ts +30 -24
- package/lib/queries.d.ts +10 -6
- package/lib/relationships.d.ts +15 -7
- package/lib/store.d.ts +1190 -291
- package/lib/tools.d.ts +12 -178
- package/lib/tools.js +1 -1
- package/lib/tools.js.gz +0 -0
- package/lib/umd/checkpoints.d.ts +13 -11
- package/lib/umd/indexes.d.ts +15 -7
- package/lib/umd/metrics.d.ts +9 -7
- package/lib/umd/persisters.d.ts +30 -24
- package/lib/umd/queries.d.ts +10 -6
- package/lib/umd/relationships.d.ts +15 -7
- package/lib/umd/store.d.ts +1190 -291
- package/lib/umd/tools.d.ts +12 -178
- package/lib/umd/tools.js +1 -1
- package/lib/umd/tools.js.gz +0 -0
- package/lib/umd-es6/checkpoints.d.ts +13 -11
- package/lib/umd-es6/indexes.d.ts +15 -7
- package/lib/umd-es6/metrics.d.ts +9 -7
- package/lib/umd-es6/persisters.d.ts +30 -24
- package/lib/umd-es6/queries.d.ts +10 -6
- package/lib/umd-es6/relationships.d.ts +15 -7
- package/lib/umd-es6/store.d.ts +1190 -291
- package/lib/umd-es6/tools.d.ts +12 -178
- package/lib/umd-es6/tools.js +1 -1
- package/lib/umd-es6/tools.js.gz +0 -0
- package/package.json +20 -20
- package/readme.md +1 -1
package/lib/debug/tools.d.ts
CHANGED
|
@@ -10,7 +10,13 @@
|
|
|
10
10
|
* @since v2.2.0
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
NoSchemas,
|
|
15
|
+
OptionalSchemas,
|
|
16
|
+
Store,
|
|
17
|
+
TablesSchema,
|
|
18
|
+
ValuesSchema,
|
|
19
|
+
} from './store.d';
|
|
14
20
|
import {Id} from './common.d';
|
|
15
21
|
|
|
16
22
|
/**
|
|
@@ -109,7 +115,7 @@ export type StoreStatsRowDetail = {
|
|
|
109
115
|
* @category Tools
|
|
110
116
|
* @since v2.2.0
|
|
111
117
|
*/
|
|
112
|
-
export interface Tools {
|
|
118
|
+
export interface Tools<Schemas extends OptionalSchemas = NoSchemas> {
|
|
113
119
|
/* eslint-disable max-len */
|
|
114
120
|
/**
|
|
115
121
|
* The getStoreStats method provides a set of statistics about the Store, and
|
|
@@ -459,180 +465,6 @@ export interface Tools {
|
|
|
459
465
|
storeName: string,
|
|
460
466
|
): Promise<[string, string, string, string]>;
|
|
461
467
|
|
|
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
|
-
|
|
636
468
|
/**
|
|
637
469
|
* The getStore method returns a reference to the underlying Store that is
|
|
638
470
|
* backing this Tools object.
|
|
@@ -651,7 +483,7 @@ export interface Tools {
|
|
|
651
483
|
* @category Getter
|
|
652
484
|
* @since v3.0.0
|
|
653
485
|
*/
|
|
654
|
-
getStore(): Store
|
|
486
|
+
getStore(): Store<Schemas>;
|
|
655
487
|
}
|
|
656
488
|
|
|
657
489
|
/* eslint-disable max-len */
|
|
@@ -698,5 +530,7 @@ export interface Tools {
|
|
|
698
530
|
* @category Creation
|
|
699
531
|
* @since v2.2.0
|
|
700
532
|
*/
|
|
701
|
-
export function createTools
|
|
533
|
+
export function createTools<Schemas extends OptionalSchemas>(
|
|
534
|
+
store: Store<Schemas>,
|
|
535
|
+
): Tools<Schemas>;
|
|
702
536
|
/* eslint-enable max-len */
|