@cosmwasm/ts-codegen 0.31.1 → 0.31.3
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +22 -14
- package/main/generators/create-helpers.js +1 -1
- package/main/plugins/provider-bundle.js +1 -1
- package/main/plugins/provider.js +1 -1
- package/module/generators/create-helpers.js +1 -1
- package/module/plugins/provider-bundle.js +1 -1
- package/module/plugins/provider.js +1 -1
- package/package.json +2 -2
- package/src/builder/builder.ts +28 -28
- package/src/generators/create-helpers.ts +1 -1
- package/src/plugins/provider-bundle.ts +1 -1
- package/src/plugins/provider.ts +1 -1
- package/types/src/builder/builder.d.ts +1 -1
package/README.md
CHANGED
@@ -36,6 +36,8 @@ The quickest and easiest way to interact with CosmWasm Contracts. `@cosmwasm/ts-
|
|
36
36
|
- [React Query](#react-query)
|
37
37
|
- [Recoil](#recoil)
|
38
38
|
- [Message Composer](#message-composer)
|
39
|
+
- [Message Builder](#message-builder)
|
40
|
+
- [Use Contracts Hooks](#use-contracts-hooks)
|
39
41
|
- [Bundles](#bundles)
|
40
42
|
- [CLI Usage and Examples](#cli-usage-and-examples)
|
41
43
|
- [Advanced Usage](#advanced-usage)
|
@@ -136,11 +138,11 @@ Typescript types and interfaces are generated in separate files so they can be i
|
|
136
138
|
|
137
139
|
#### Types Options
|
138
140
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
141
|
+
| option | description |
|
142
|
+
| ------------------------ | ---------------------------------------------------- |
|
143
|
+
| `types.enabled` | enable type generation |
|
144
|
+
| `types.aliasExecuteMsg` | generate a type alias based on the contract name |
|
145
|
+
| `types.aliasEntryPoints` | generate type aliases for the entry points based on the contract name |
|
144
146
|
|
145
147
|
### Client
|
146
148
|
|
@@ -150,11 +152,11 @@ The `client` plugin will generate TS client classes for your contracts. This opt
|
|
150
152
|
|
151
153
|
#### Client Options
|
152
154
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
155
|
+
| option | description |
|
156
|
+
| --------------------------------------- | --------------------------------------------------- |
|
157
|
+
| `client.enabled` | generate TS client classes for your contracts |
|
158
|
+
| `client.execExtendsQuery` | execute should extend query message clients |
|
159
|
+
| `client.noImplicitOverride` | should match your tsconfig noImplicitOverride option |
|
158
160
|
|
159
161
|
#### Client via CLI
|
160
162
|
|
@@ -256,13 +258,13 @@ cosmwasm-ts-codegen generate \
|
|
256
258
|
| ------------------------------ | ------------------------------------------------------------------- |
|
257
259
|
| `messageComposer.enabled` | enable the messageComposer plugin |
|
258
260
|
|
259
|
-
###
|
261
|
+
### Message Builder
|
260
262
|
|
261
263
|
Generate raw message jsons for use in your application with the `msg-builder` command.
|
262
264
|
|
263
265
|
[see example output code](https://gist.github.com/adairrr/b394e62beb9856b0351883f776650f26)
|
264
266
|
|
265
|
-
####
|
267
|
+
#### Message Builder via CLI
|
266
268
|
|
267
269
|
```sh
|
268
270
|
cosmwasm-ts-codegen generate \
|
@@ -271,12 +273,18 @@ cosmwasm-ts-codegen generate \
|
|
271
273
|
--out ./ts \
|
272
274
|
--name MyContractName
|
273
275
|
```
|
274
|
-
#### Message
|
276
|
+
#### Message Builder Options
|
275
277
|
|
276
278
|
| option | description |
|
277
279
|
|------------ | ------------------------------ | ------------------------------------------------------------------- |
|
278
|
-
| `msgBuilder.enabled` | enable the
|
280
|
+
| `msgBuilder.enabled` | enable the msgBuilder plugin |
|
281
|
+
|
282
|
+
|
283
|
+
### Use Contracts Hooks
|
279
284
|
|
285
|
+
| option | description |
|
286
|
+
| -------------------------------- | --------------------------------------- |
|
287
|
+
| `useContractsHooks.enabled` | enable the `useContracts` plugin |
|
280
288
|
|
281
289
|
### Bundles
|
282
290
|
|
@@ -29,7 +29,7 @@ var write = function write(outPath, file, content) {
|
|
29
29
|
var createHelpers = function createHelpers(input, builderContext) {
|
30
30
|
var _input$options, _input$options$useCon, _Object$keys;
|
31
31
|
|
32
|
-
if ((_input$options = input.options) !== null && _input$options !== void 0 && (_input$options$useCon = _input$options.
|
32
|
+
if ((_input$options = input.options) !== null && _input$options !== void 0 && (_input$options$useCon = _input$options.useContractsHooks) !== null && _input$options$useCon !== void 0 && _input$options$useCon.enabled && (_Object$keys = Object.keys(builderContext.providers)) !== null && _Object$keys !== void 0 && _Object$keys.length) {
|
33
33
|
write(input.outPath, "contractContextBase.ts", _helpers.contractContextBase);
|
34
34
|
write(input.outPath, "contracts-context.tsx", _helpers.contractsContextTSX);
|
35
35
|
}
|
@@ -76,7 +76,7 @@ var ContractsProviderBundlePlugin = /*#__PURE__*/function (_BuilderPluginBase) {
|
|
76
76
|
while (1) {
|
77
77
|
switch (_context.prev = _context.next) {
|
78
78
|
case 0:
|
79
|
-
if ((_this$option = this.option) !== null && _this$option !== void 0 && (_this$option$useContr = _this$option.
|
79
|
+
if ((_this$option = this.option) !== null && _this$option !== void 0 && (_this$option$useContr = _this$option.useContractsHooks) !== null && _this$option$useContr !== void 0 && _this$option$useContr.enabled) {
|
80
80
|
_context.next = 2;
|
81
81
|
break;
|
82
82
|
}
|
package/main/plugins/provider.js
CHANGED
@@ -83,7 +83,7 @@ var ContractsContextProviderPlugin = /*#__PURE__*/function (_BuilderPluginBase)
|
|
83
83
|
while (1) {
|
84
84
|
switch (_context.prev = _context.next) {
|
85
85
|
case 0:
|
86
|
-
if ((_this$option = this.option) !== null && _this$option !== void 0 && (_this$option$useContr = _this$option.
|
86
|
+
if ((_this$option = this.option) !== null && _this$option !== void 0 && (_this$option$useContr = _this$option.useContractsHooks) !== null && _this$option$useContr !== void 0 && _this$option$useContr.enabled) {
|
87
87
|
_context.next = 2;
|
88
88
|
break;
|
89
89
|
}
|
@@ -18,7 +18,7 @@ const write = (outPath, file, content) => {
|
|
18
18
|
};
|
19
19
|
|
20
20
|
export const createHelpers = (input, builderContext) => {
|
21
|
-
if (input.options?.
|
21
|
+
if (input.options?.useContractsHooks?.enabled && Object.keys(builderContext.providers)?.length) {
|
22
22
|
write(input.outPath, "contractContextBase.ts", contractContextBase);
|
23
23
|
write(input.outPath, "contracts-context.tsx", contractsContextTSX);
|
24
24
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@cosmwasm/ts-codegen",
|
3
|
-
"version": "0.31.
|
3
|
+
"version": "0.31.3",
|
4
4
|
"description": "@cosmwasm/ts-codegen converts your CosmWasm smart contracts into dev-friendly TypeScript classes so you can focus on shipping code.",
|
5
5
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
6
6
|
"homepage": "https://github.com/cosmwasm/ts-codegen",
|
@@ -98,5 +98,5 @@
|
|
98
98
|
"shelljs": "0.8.5",
|
99
99
|
"wasm-ast-types": "^0.24.0"
|
100
100
|
},
|
101
|
-
"gitHead": "
|
101
|
+
"gitHead": "7605b218d5823ab79fd61a529790f88b82d367c5"
|
102
102
|
}
|
package/src/builder/builder.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { RenderOptions, defaultOptions, RenderContext, ContractInfo, MessageComposerOptions, BuilderContext} from "wasm-ast-types";
|
1
|
+
import { RenderOptions, defaultOptions, RenderContext, ContractInfo, MessageComposerOptions, BuilderContext } from "wasm-ast-types";
|
2
2
|
|
3
3
|
import { header } from '../utils/header';
|
4
4
|
import { join } from "path";
|
@@ -48,13 +48,13 @@ export interface BundleOptions {
|
|
48
48
|
};
|
49
49
|
|
50
50
|
export interface UseContractsOptions {
|
51
|
-
|
52
|
-
|
51
|
+
enabled?: boolean;
|
52
|
+
filename?: string;
|
53
53
|
};
|
54
54
|
|
55
55
|
export type TSBuilderOptions = {
|
56
56
|
bundle?: BundleOptions;
|
57
|
-
|
57
|
+
useContractsHooks?: UseContractsOptions;
|
58
58
|
} & RenderOptions;
|
59
59
|
|
60
60
|
export type BuilderFileType = 'type' | 'client' | 'recoil' | 'react-query' | 'message-composer' | 'msg-builder' | 'plugin';
|
@@ -125,7 +125,7 @@ export class TSBuilder {
|
|
125
125
|
[].push.apply(this.plugins, plugins);
|
126
126
|
}
|
127
127
|
|
128
|
-
this.plugins.forEach(plugin=> plugin.setBuilder(this))
|
128
|
+
this.plugins.forEach(plugin => plugin.setBuilder(this))
|
129
129
|
}
|
130
130
|
|
131
131
|
async build() {
|
@@ -134,7 +134,7 @@ export class TSBuilder {
|
|
134
134
|
}
|
135
135
|
|
136
136
|
// lifecycle functions
|
137
|
-
private async process(){
|
137
|
+
private async process() {
|
138
138
|
for (const contractOpt of this.contracts) {
|
139
139
|
const contract = getContract(contractOpt);
|
140
140
|
//resolve contract schema.
|
@@ -147,16 +147,16 @@ export class TSBuilder {
|
|
147
147
|
}
|
148
148
|
}
|
149
149
|
|
150
|
-
private async render(name: string, contractInfo: ContractInfo){
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
150
|
+
private async render(name: string, contractInfo: ContractInfo) {
|
151
|
+
for (const plugin of this.plugins) {
|
152
|
+
let files = await plugin.render(name, contractInfo, this.outPath);
|
153
|
+
if (files && files.length) {
|
154
|
+
[].push.apply(this.files, files);
|
155
|
+
}
|
156
|
+
}
|
157
157
|
}
|
158
158
|
|
159
|
-
private async after(){
|
159
|
+
private async after() {
|
160
160
|
if (this.options.bundle.enabled) {
|
161
161
|
this.bundle();
|
162
162
|
}
|
@@ -166,21 +166,21 @@ export class TSBuilder {
|
|
166
166
|
contractsProviderBundlePlugin.setBuilder(this);
|
167
167
|
|
168
168
|
let files = await contractsProviderBundlePlugin.render(
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
169
|
+
"",
|
170
|
+
{
|
171
|
+
schemas: [],
|
172
|
+
},
|
173
|
+
this.outPath
|
174
174
|
);
|
175
|
-
if(files && files.length){
|
176
|
-
|
175
|
+
if (files && files.length) {
|
176
|
+
[].push.apply(this.files, files);
|
177
177
|
}
|
178
178
|
|
179
179
|
createHelpers({
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
180
|
+
outPath: this.outPath,
|
181
|
+
contracts: this.contracts,
|
182
|
+
options: this.options,
|
183
|
+
plugins: this.plugins,
|
184
184
|
}, this.builderContext);
|
185
185
|
}
|
186
186
|
|
@@ -190,8 +190,8 @@ export class TSBuilder {
|
|
190
190
|
|
191
191
|
const bundleFile = this.options.bundle.bundleFile;
|
192
192
|
const bundlePath = join(
|
193
|
-
|
194
|
-
|
193
|
+
this.options?.bundle?.bundlePath ?? this.outPath,
|
194
|
+
bundleFile
|
195
195
|
);
|
196
196
|
const bundleVariables = {};
|
197
197
|
const importPaths = [];
|
@@ -215,7 +215,7 @@ export class TSBuilder {
|
|
215
215
|
]
|
216
216
|
)).code;
|
217
217
|
|
218
|
-
if(this.options?.bundle?.bundlePath){
|
218
|
+
if (this.options?.bundle?.bundlePath) {
|
219
219
|
mkdirp(this.options?.bundle?.bundlePath);
|
220
220
|
}
|
221
221
|
|
@@ -21,7 +21,7 @@ const write = (outPath: string, file: string, content: string) => {
|
|
21
21
|
};
|
22
22
|
|
23
23
|
export const createHelpers = (input: TSBuilderInput, builderContext: BuilderContext) => {
|
24
|
-
if (input.options?.
|
24
|
+
if (input.options?.useContractsHooks?.enabled && Object.keys(builderContext.providers)?.length) {
|
25
25
|
write(input.outPath, "contractContextBase.ts", contractContextBase);
|
26
26
|
write(input.outPath, "contracts-context.tsx", contractsContextTSX);
|
27
27
|
}
|
package/src/plugins/provider.ts
CHANGED
@@ -18,7 +18,7 @@ export interface UseContractsOptions {
|
|
18
18
|
}
|
19
19
|
export type TSBuilderOptions = {
|
20
20
|
bundle?: BundleOptions;
|
21
|
-
|
21
|
+
useContractsHooks?: UseContractsOptions;
|
22
22
|
} & RenderOptions;
|
23
23
|
export type BuilderFileType = 'type' | 'client' | 'recoil' | 'react-query' | 'message-composer' | 'msg-builder' | 'plugin';
|
24
24
|
export interface BuilderFile {
|