@taqueria/plugin-contract-types 0.3.1 → 0.4.0-rc3

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/README.md ADDED
@@ -0,0 +1,125 @@
1
+ # Taqueria Contract Types Plugin
2
+
3
+ This plugin provides a `taq generate types` command which will generate and export TypeScript types from compiled Michelson smart contracts. These generated types then work with your IDE and Taquito, providing type safety and an improved code authoring experience
4
+
5
+ Benefits of using generated types:
6
+ - Static types used to call smart contract methods are checked at compile time, improving code reliability
7
+ - Generated types enable auto-completion and syntax highlighting in your IDE
8
+ - Developing apps with Taquito is faster and more reliable
9
+ - The VS Code Extension provides tooltip hints for parameter types used to call a smart contract method
10
+ - Calling smart contract methods with types is done directly, removing the need for utility methods
11
+ - Simplifies your code and improves readability
12
+
13
+ ## Requirements
14
+
15
+ - Node JS v16 or later
16
+ - Taquito v11.2 or later (optional)
17
+
18
+ ## Installation
19
+
20
+ To install the Contract Types plugin on a Taqueria project, navigate to the project folder and run:
21
+ ```shell
22
+ taq install @taqueria/plugin-contract-types
23
+ ```
24
+
25
+ ## Configuration
26
+
27
+ This plugin will look for Michelson files according to the `artifactsDir` configured in `./.taq/config.json`. By default, this value is `/artifacts` but can be changed as needed
28
+
29
+ ## Usage
30
+
31
+ The plugin provides a single command to Taqueria: `taq generate types`
32
+
33
+ This will look for `.tz` files in the `/artifacts` directory and will generate a series of related `.ts` files in the `/types` directory. These files export type definitions for each method which can then be used by Taquito and your IDE
34
+
35
+ ### The `generate types` Command
36
+
37
+ #### Syntax
38
+ ```shell
39
+ taq generate types [typeOutputDir]
40
+ ```
41
+
42
+ #### Parameters
43
+
44
+ | parameter | required | description |
45
+ |:-------------:|:-----------|----------------------------------------------------|
46
+ | typeOutputDir | no | The output directory for the `.ts` files generated |
47
+
48
+ #### CLI Aliases
49
+
50
+ The following aliases are interchangable with `generate types`
51
+ - `gen`
52
+ - `gentypes`
53
+
54
+ #### Options
55
+
56
+ The `generate types` command will accept the following optional parameters:
57
+
58
+ | flag | name | description |
59
+ |:-----:|:--------------|----------------------------------------------|
60
+ | -t | typeAliasMode | Use type aliases in the generated types |
61
+
62
+
63
+ ## Taquito Workflow Improvements
64
+
65
+ The generated TS types can be used in a Taquito project which provides an improved developing experience, and simplifies the way types are provided to Taquito method calls. Some examples of how these changes are put into use are detailed below
66
+
67
+ > ### :page_with_curl: Note
68
+ > You can view the full example in the `example-usage.ts` file on Github: [taqueria/taqueria-plugin-contract-types/example](https://github.com/ecadlabs/taqueria/blob/main/taqueria-plugin-contract-types/example/example-usage.ts)
69
+
70
+ ### Calling the `.at` Method of a Contract
71
+
72
+ Traditionally, calling the `.at` method of a contract with Taquito required the developer to pass the parameter's type via a utility method:
73
+ ```ts Utility Method
74
+ const contract = await Tezos.contract.at(`KT123...`, contractAbstractionComposer<TestContractType>());
75
+ ```
76
+ or a cast:
77
+ ```ts Cast
78
+ const contract = await Tezos.contract.at(`KT123...`) as ContractProviderFromContractType<TestContractType>;
79
+ ```
80
+
81
+ When using generated types, the developer can now directly use the type in the call to `.at`:
82
+ ```ts
83
+ const contract = await Tezos.contract.at<TestContract>(`KT123...`);
84
+ ```
85
+
86
+ ### Using a Wallet
87
+
88
+ Using a wallet is simplified in a similar way:
89
+ ```ts
90
+ const contract = await Tezos.wallet.at(`KT123...`, walletAbstractionComposer<TestContractType>());
91
+ ```
92
+
93
+ Becomes:
94
+ ```ts
95
+ const contract = await Tezos.wallet.at<TestWalletContract>(`KT123...`);
96
+ ```
97
+
98
+ ### Contract Origination
99
+
100
+ The Taquito contract origination did not have any way to provide a type, so this used to require a cast:
101
+ ```ts
102
+ const originationResult = await Tezos.contract.originate({...});
103
+ const contract = await originationResult.contract(5) as ContractProviderFromContractType<TestContractType2>;
104
+ ```
105
+
106
+ Now, it can directly accept a type:
107
+ ```ts
108
+ const originationResult = await Tezos.contract.originate({...});
109
+ const contract = await originationResult.contract<TestContract2>(5);
110
+ ```
111
+
112
+
113
+ ### Storage
114
+
115
+ When accessing storage, there was no way to pass the type through the contract class. This required providing the type a second time:
116
+ ```ts
117
+ const contract = await Tezos.contract.at(`KT123...`) as ContractProviderFromContractType<TestContractType>;
118
+ const storage = await contract.storage<StorageFromContractType<TestContractType>>();
119
+ ```
120
+
121
+ Now, the contract type provides the default storage type:
122
+ ```ts
123
+ const contract = await Tezos.contract.at<TestContract>(`KT123...`);
124
+ const storage = await contract.storage();
125
+ ```
package/_readme.eta ADDED
@@ -0,0 +1,128 @@
1
+ <% if (it.output == "github") { %>
2
+ # Taqueria Contract Types Plugin
3
+ <% } %>
4
+
5
+ This plugin provides a `taq generate types` command which will generate and export TypeScript types from compiled Michelson smart contracts. These generated types then work with your IDE and Taquito, providing type safety and an improved code authoring experience
6
+
7
+ Benefits of using generated types:
8
+ - Static types used to call smart contract methods are checked at compile time, improving code reliability
9
+ - Generated types enable auto-completion and syntax highlighting in your IDE
10
+ - Developing apps with Taquito is faster and more reliable
11
+ - The VS Code Extension provides tooltip hints for parameter types used to call a smart contract method
12
+ - Calling smart contract methods with types is done directly, removing the need for utility methods
13
+ - Simplifies your code and improves readability
14
+
15
+ ## Requirements
16
+
17
+ - Node JS v16 or later
18
+ - Taquito v11.2 or later (optional)
19
+
20
+ ## Installation
21
+
22
+ To install the Contract Types plugin on a Taqueria project, navigate to the project folder and run:
23
+ ```shell
24
+ taq install @taqueria/plugin-contract-types
25
+ ```
26
+
27
+ ## Configuration
28
+
29
+ This plugin will look for Michelson files according to the `artifactsDir` configured in `./.taq/config.json`. By default, this value is `/artifacts` but can be changed as needed
30
+
31
+ ## Usage
32
+
33
+ The plugin provides a single command to Taqueria: `taq generate types`
34
+
35
+ This will look for `.tz` files in the `/artifacts` directory and will generate a series of related `.ts` files in the `/types` directory. These files export type definitions for each method which can then be used by Taquito and your IDE
36
+
37
+ ### The `generate types` Command
38
+
39
+ #### Syntax
40
+ ```shell
41
+ taq generate types [typeOutputDir]
42
+ ```
43
+
44
+ #### Parameters
45
+
46
+ | parameter | required | description |
47
+ |:-------------:|:-----------|----------------------------------------------------|
48
+ | typeOutputDir | no | The output directory for the `.ts` files generated |
49
+
50
+ #### CLI Aliases
51
+
52
+ The following aliases are interchangable with `generate types`
53
+ - `gen`
54
+ - `gentypes`
55
+
56
+ #### Options
57
+
58
+ The `generate types` command will accept the following optional parameters:
59
+
60
+ | flag | name | description |
61
+ |:-----:|:--------------|----------------------------------------------|
62
+ | -t | typeAliasMode | Use type aliases in the generated types |
63
+
64
+
65
+ ## Taquito Workflow Improvements
66
+
67
+ The generated TS types can be used in a Taquito project which provides an improved developing experience, and simplifies the way types are provided to Taquito method calls. Some examples of how these changes are put into use are detailed below
68
+
69
+ <%~ it.noteOpenAdmonition %>
70
+ You can view the full example in the `example-usage.ts` file on Github: [taqueria/taqueria-plugin-contract-types/example](https://github.com/ecadlabs/taqueria/blob/main/taqueria-plugin-contract-types/example/example-usage.ts)
71
+ <%= it.closeAdmonition %>
72
+
73
+ ### Calling the `.at` Method of a Contract
74
+
75
+ Traditionally, calling the `.at` method of a contract with Taquito required the developer to pass the parameter's type via a utility method:
76
+ ```ts Utility Method
77
+ const contract = await Tezos.contract.at(`KT123...`, contractAbstractionComposer<TestContractType>());
78
+ ```
79
+ or a cast:
80
+ ```ts Cast
81
+ const contract = await Tezos.contract.at(`KT123...`) as ContractProviderFromContractType<TestContractType>;
82
+ ```
83
+
84
+ When using generated types, the developer can now directly use the type in the call to `.at`:
85
+ ```ts
86
+ const contract = await Tezos.contract.at<TestContract>(`KT123...`);
87
+ ```
88
+
89
+ ### Using a Wallet
90
+
91
+ Using a wallet is simplified in a similar way:
92
+ ```ts
93
+ const contract = await Tezos.wallet.at(`KT123...`, walletAbstractionComposer<TestContractType>());
94
+ ```
95
+
96
+ Becomes:
97
+ ```ts
98
+ const contract = await Tezos.wallet.at<TestWalletContract>(`KT123...`);
99
+ ```
100
+
101
+ ### Contract Origination
102
+
103
+ The Taquito contract origination did not have any way to provide a type, so this used to require a cast:
104
+ ```ts
105
+ const originationResult = await Tezos.contract.originate({...});
106
+ const contract = await originationResult.contract(5) as ContractProviderFromContractType<TestContractType2>;
107
+ ```
108
+
109
+ Now, it can directly accept a type:
110
+ ```ts
111
+ const originationResult = await Tezos.contract.originate({...});
112
+ const contract = await originationResult.contract<TestContract2>(5);
113
+ ```
114
+
115
+
116
+ ### Storage
117
+
118
+ When accessing storage, there was no way to pass the type through the contract class. This required providing the type a second time:
119
+ ```ts
120
+ const contract = await Tezos.contract.at(`KT123...`) as ContractProviderFromContractType<TestContractType>;
121
+ const storage = await contract.storage<StorageFromContractType<TestContractType>>();
122
+ ```
123
+
124
+ Now, the contract type provides the default storage type:
125
+ ```ts
126
+ const contract = await Tezos.contract.at<TestContract>(`KT123...`);
127
+ const storage = await contract.storage();
128
+ ```
@@ -54,12 +54,12 @@ export const exampleTypedMethods_existingWallet = async () => {
54
54
 
55
55
  const contract = await Tezos.wallet.at<TestWallet>(`tz123`);
56
56
 
57
- // SendParams are not stictly typed yet
57
+ // SendParams are not strictly typed yet
58
58
  // const bidSendResult = await contract.methods.bid(tas.nat(0)).send({ amount: tas.mutez(1000000) });
59
59
  const bidSendResult = await contract.methods.bid(tas.nat(0)).send({ amount: tas.number(tas.mutez(1000000)) });
60
60
 
61
61
  // Receipt only exists on wallet
62
- const bidReciptResult = await bidSendResult.receipt();
62
+ const bidReceiptResult = await bidSendResult.receipt();
63
63
  const bidConfirmationResult = await bidSendResult.confirmation(10);
64
64
 
65
65
  contract.methods.configure(