@cosmwasm/ts-codegen 0.34.2 → 0.35.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.
- package/README.md +83 -20
- package/main/builder/builder.js +145 -247
- package/main/builder/index.js +0 -2
- package/main/bundler/bundler.js +3 -16
- package/main/bundler/index.js +0 -2
- package/main/cli.js +20 -38
- package/main/cmds.js +0 -5
- package/main/commands/create-boilerplate.js +132 -160
- package/main/commands/generate.js +168 -192
- package/main/commands/install.js +89 -123
- package/main/file.js +13 -25
- package/main/generators/client.js +55 -81
- package/main/generators/create-helpers.js +0 -14
- package/main/generators/message-composer.js +42 -68
- package/main/generators/msg-builder.js +49 -78
- package/main/generators/react-query.js +68 -92
- package/main/generators/recoil.js +47 -71
- package/main/generators/types.js +45 -73
- package/main/helpers/index.js +0 -6
- package/main/index.js +8 -30
- package/main/plugins/client.js +56 -90
- package/main/plugins/index.js +0 -2
- package/main/plugins/{msg-builder.js → message-builder.js} +56 -93
- package/main/plugins/message-composer.js +42 -76
- package/main/plugins/plugin-base.js +40 -70
- package/main/plugins/provider-bundle.js +42 -81
- package/main/plugins/provider.js +58 -103
- package/main/plugins/react-query.js +67 -99
- package/main/plugins/recoil.js +45 -82
- package/main/plugins/types.js +34 -68
- package/main/ts-codegen.js +7 -15
- package/main/utils/clean.js +8 -17
- package/main/utils/cleanse.js +10 -25
- package/main/utils/files.js +2 -22
- package/main/utils/header.js +0 -3
- package/main/utils/index.js +0 -2
- package/main/utils/parse.js +2 -7
- package/main/utils/prompt.js +16 -36
- package/main/utils/schemas.js +86 -133
- package/main/utils/unused.js +4 -15
- package/module/builder/builder.js +12 -33
- package/module/bundler/bundler.js +3 -3
- package/module/cli.js +0 -1
- package/module/commands/create-boilerplate.js +6 -19
- package/module/commands/generate.js +13 -18
- package/module/commands/install.js +14 -17
- package/module/file.js +0 -3
- package/module/generators/client.js +6 -7
- package/module/generators/create-helpers.js +0 -4
- package/module/generators/message-composer.js +4 -5
- package/module/generators/msg-builder.js +10 -14
- package/module/generators/react-query.js +8 -9
- package/module/generators/recoil.js +2 -3
- package/module/generators/types.js +4 -6
- package/module/plugins/client.js +4 -10
- package/module/plugins/{msg-builder.js → message-builder.js} +10 -18
- package/module/plugins/message-composer.js +4 -10
- package/module/plugins/plugin-base.js +10 -10
- package/module/plugins/provider-bundle.js +0 -10
- package/module/plugins/provider.js +0 -14
- package/module/plugins/react-query.js +8 -13
- package/module/plugins/recoil.js +2 -9
- package/module/plugins/types.js +4 -7
- package/module/ts-codegen.js +0 -2
- package/module/utils/clean.js +8 -13
- package/module/utils/cleanse.js +10 -21
- package/module/utils/files.js +2 -6
- package/module/utils/parse.js +2 -4
- package/module/utils/prompt.js +0 -5
- package/module/utils/schemas.js +2 -13
- package/module/utils/unused.js +4 -6
- package/package.json +3 -3
- package/src/builder/builder.ts +7 -6
- package/src/commands/generate.ts +13 -12
- package/src/generators/msg-builder.ts +7 -9
- package/src/plugins/{msg-builder.ts → message-builder.ts} +6 -6
- package/src/plugins/message-composer.ts +2 -2
- package/types/src/builder/builder.d.ts +3 -2
- package/types/src/generators/msg-builder.d.ts +2 -2
- package/types/src/generators/msg-builder.ts +2 -2
- package/types/src/plugins/message-builder.d.ts +12 -0
- package/types/src/plugins/msg-builder.d.ts +1 -1
package/module/utils/unused.js
CHANGED
@@ -1,28 +1,27 @@
|
|
1
1
|
//@ts-nocheck
|
2
|
-
|
2
|
+
|
3
|
+
import * as t from '@babel/types';
|
4
|
+
|
5
|
+
// https://github.com/chuyik/babel-plugin-danger-remove-unused-import
|
3
6
|
// https://github.com/chuyik/babel-plugin-danger-remove-unused-import/blob/c5454c21e94698a2464a12baa5590761932a71a8/License#L1
|
4
7
|
|
5
8
|
export const unused = {
|
6
9
|
Program: {
|
7
10
|
exit: path => {
|
8
11
|
const UnRefBindings = new Map();
|
9
|
-
|
10
12
|
for (const [name, binding] of Object.entries(path.scope.bindings)) {
|
11
13
|
if (!binding.path.parentPath || binding.kind !== 'module') continue;
|
12
14
|
const source = binding.path.parentPath.get('source');
|
13
15
|
const importName = source.node.value;
|
14
16
|
if (!t.isStringLiteral(source)) continue;
|
15
17
|
const key = `${importName}(${source.node.loc && source.node.loc.start.line})`;
|
16
|
-
|
17
18
|
if (!UnRefBindings.has(key)) {
|
18
19
|
UnRefBindings.set(key, binding);
|
19
20
|
}
|
20
|
-
|
21
21
|
if (binding.referenced) {
|
22
22
|
UnRefBindings.set(key, null);
|
23
23
|
} else {
|
24
24
|
const nodeType = binding.path.node.type;
|
25
|
-
|
26
25
|
if (nodeType === 'ImportSpecifier') {
|
27
26
|
binding.path.remove();
|
28
27
|
} else if (nodeType === 'ImportDefaultSpecifier') {
|
@@ -34,7 +33,6 @@ export const unused = {
|
|
34
33
|
}
|
35
34
|
}
|
36
35
|
}
|
37
|
-
|
38
36
|
UnRefBindings.forEach((binding, key) => {
|
39
37
|
if (binding && binding.path.parentPath) {
|
40
38
|
binding.path.parentPath.remove();
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@cosmwasm/ts-codegen",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.35.0",
|
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",
|
@@ -96,7 +96,7 @@
|
|
96
96
|
"parse-package-name": "1.0.0",
|
97
97
|
"rimraf": "3.0.2",
|
98
98
|
"shelljs": "0.8.5",
|
99
|
-
"wasm-ast-types": "^0.
|
99
|
+
"wasm-ast-types": "^0.26.0"
|
100
100
|
},
|
101
|
-
"gitHead": "
|
101
|
+
"gitHead": "fa5aea0a8de61f713a8dad85c5f7965e82c3b5c0"
|
102
102
|
}
|
package/src/builder/builder.ts
CHANGED
@@ -17,7 +17,7 @@ import generate from '@babel/generator';
|
|
17
17
|
import * as t from '@babel/types';
|
18
18
|
import { ReactQueryPlugin } from "../plugins/react-query";
|
19
19
|
import { RecoilPlugin } from "../plugins/recoil";
|
20
|
-
import {
|
20
|
+
import { MessageBuilderPlugin } from "../plugins/message-builder";
|
21
21
|
import { MessageComposerPlugin } from "../plugins/message-composer";
|
22
22
|
import { ClientPlugin } from "../plugins/client";
|
23
23
|
import { TypesPlugin } from "../plugins/types";
|
@@ -30,7 +30,8 @@ const defaultOpts: TSBuilderOptions = {
|
|
30
30
|
enabled: true,
|
31
31
|
scope: 'contracts',
|
32
32
|
bundleFile: 'bundle.ts'
|
33
|
-
}
|
33
|
+
},
|
34
|
+
useShorthandCtor: true
|
34
35
|
}
|
35
36
|
|
36
37
|
export interface TSBuilderInput {
|
@@ -55,13 +56,13 @@ export type TSBuilderOptions = {
|
|
55
56
|
bundle?: BundleOptions;
|
56
57
|
/**
|
57
58
|
* Enable using shorthand constructor.
|
58
|
-
* Default:
|
59
|
+
* Default: true
|
59
60
|
*/
|
60
61
|
useShorthandCtor?: boolean;
|
61
62
|
useContractsHooks?: UseContractsOptions;
|
62
63
|
} & RenderOptions;
|
63
64
|
|
64
|
-
export type BuilderFileType = 'type' | 'client' | 'recoil' | 'react-query' | 'message-composer' | '
|
65
|
+
export type BuilderFileType = 'type' | 'client' | 'recoil' | 'react-query' | 'message-composer' | 'message-builder' | 'plugin';
|
65
66
|
|
66
67
|
export interface BuilderFile {
|
67
68
|
type: BuilderFileType;
|
@@ -109,7 +110,7 @@ export class TSBuilder {
|
|
109
110
|
new MessageComposerPlugin(this.options),
|
110
111
|
new ReactQueryPlugin(this.options),
|
111
112
|
new RecoilPlugin(this.options),
|
112
|
-
new
|
113
|
+
new MessageBuilderPlugin(this.options),
|
113
114
|
new ContractsContextProviderPlugin(this.options),
|
114
115
|
]);
|
115
116
|
}
|
@@ -189,7 +190,7 @@ export class TSBuilder {
|
|
189
190
|
}, this.builderContext);
|
190
191
|
|
191
192
|
if (helpers && helpers.length) {
|
192
|
-
|
193
|
+
[].push.apply(this.files, helpers);
|
193
194
|
}
|
194
195
|
|
195
196
|
if (this.options.bundle.enabled) {
|
package/src/commands/generate.ts
CHANGED
@@ -91,17 +91,17 @@ export default async (argv) => {
|
|
91
91
|
};
|
92
92
|
const { mutations } = await prompt(questions3, argv);
|
93
93
|
|
94
|
-
const queryFactoryQuestions
|
94
|
+
const queryFactoryQuestions = [];
|
95
95
|
if (queryKeys) {
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
96
|
+
[].push.apply(queryFactoryQuestions, [
|
97
|
+
// Only can use queryFactory if queryKeys is enabled
|
98
|
+
{
|
99
|
+
type: 'confirm',
|
100
|
+
name: 'queryFactory',
|
101
|
+
message: 'queryFactory? ',
|
102
|
+
default: false
|
103
|
+
}
|
104
|
+
])
|
105
105
|
};
|
106
106
|
const { queryFactory } = await prompt(queryFactoryQuestions, argv);
|
107
107
|
///////// END REACT QUERY
|
@@ -151,8 +151,9 @@ export default async (argv) => {
|
|
151
151
|
messageComposer: {
|
152
152
|
enabled: plugin.includes('message-composer')
|
153
153
|
},
|
154
|
-
|
155
|
-
|
154
|
+
messageBuilder: {
|
155
|
+
|
156
|
+
enabled: plugin.includes('message-builder')
|
156
157
|
},
|
157
158
|
bundle: {
|
158
159
|
enabled: bundle,
|
@@ -8,23 +8,21 @@ import { writeFileSync } from "fs";
|
|
8
8
|
import generate from "@babel/generator";
|
9
9
|
import { ContractInfo, getMessageProperties } from "wasm-ast-types";
|
10
10
|
import { findAndParseTypes, findExecuteMsg, findQueryMsg } from '../utils';
|
11
|
-
import { RenderContext,
|
11
|
+
import { RenderContext, MessageBuilderOptions } from 'wasm-ast-types';
|
12
12
|
import { BuilderFile } from "../builder";
|
13
|
-
import babelTraverse from '@babel/traverse';
|
14
|
-
import { parse as babelParse } from '@babel/parser'
|
15
13
|
|
16
14
|
export default async (
|
17
15
|
name: string,
|
18
16
|
contractInfo: ContractInfo,
|
19
17
|
outPath: string,
|
20
|
-
|
18
|
+
messageBuilderOptions?: MessageBuilderOptions
|
21
19
|
): Promise<BuilderFile[]> => {
|
22
20
|
const { schemas } = contractInfo;
|
23
21
|
const context = new RenderContext(contractInfo, {
|
24
|
-
|
22
|
+
messageBuilder: messageBuilderOptions ?? {},
|
25
23
|
});
|
26
24
|
|
27
|
-
const localname = pascal(name) + ".
|
25
|
+
const localname = pascal(name) + ".message-builder.ts";
|
28
26
|
const TypesFile = pascal(name) + ".types";
|
29
27
|
const ExecuteMsg = findExecuteMsg(schemas);
|
30
28
|
const typeHash = await findAndParseTypes(schemas);
|
@@ -41,7 +39,7 @@ export default async (
|
|
41
39
|
const className = pascal(`${name}ExecuteMsgBuilder`);
|
42
40
|
|
43
41
|
body.push(
|
44
|
-
w.
|
42
|
+
w.createMessageBuilderClass(context, className, ExecuteMsg)
|
45
43
|
);
|
46
44
|
}
|
47
45
|
}
|
@@ -54,7 +52,7 @@ export default async (
|
|
54
52
|
const className = pascal(`${name}QueryMsgBuilder`);
|
55
53
|
|
56
54
|
body.push(
|
57
|
-
w.
|
55
|
+
w.createMessageBuilderClass(context, className, QueryMsg)
|
58
56
|
);
|
59
57
|
}
|
60
58
|
}
|
@@ -71,7 +69,7 @@ export default async (
|
|
71
69
|
|
72
70
|
return [
|
73
71
|
{
|
74
|
-
type: "
|
72
|
+
type: "message-builder",
|
75
73
|
contract: name,
|
76
74
|
localname,
|
77
75
|
filename: join(outPath, localname),
|
@@ -11,7 +11,7 @@ import {
|
|
11
11
|
import { BuilderFileType } from '../builder';
|
12
12
|
import { BuilderPluginBase } from './plugin-base';
|
13
13
|
|
14
|
-
export class
|
14
|
+
export class MessageBuilderPlugin extends BuilderPluginBase<RenderOptions> {
|
15
15
|
initContext(
|
16
16
|
contract: ContractInfo,
|
17
17
|
options?: RenderOptions
|
@@ -30,7 +30,7 @@ export class MsgBuilderPlugin extends BuilderPluginBase<RenderOptions> {
|
|
30
30
|
body: any[];
|
31
31
|
}[]
|
32
32
|
> {
|
33
|
-
const { enabled } = this.option.
|
33
|
+
const { enabled } = this.option.messageBuilder;
|
34
34
|
|
35
35
|
if (!enabled) {
|
36
36
|
return;
|
@@ -38,7 +38,7 @@ export class MsgBuilderPlugin extends BuilderPluginBase<RenderOptions> {
|
|
38
38
|
|
39
39
|
const { schemas } = context.contract;
|
40
40
|
|
41
|
-
const localname = pascal(name) + '.
|
41
|
+
const localname = pascal(name) + '.message-builder.ts';
|
42
42
|
const TypesFile = pascal(name) + '.types';
|
43
43
|
const ExecuteMsg = findExecuteMsg(schemas);
|
44
44
|
const typeHash = await findAndParseTypes(schemas);
|
@@ -54,7 +54,7 @@ export class MsgBuilderPlugin extends BuilderPluginBase<RenderOptions> {
|
|
54
54
|
if (children.length > 0) {
|
55
55
|
const className = pascal(`${name}ExecuteMsgBuilder`);
|
56
56
|
|
57
|
-
body.push(w.
|
57
|
+
body.push(w.createMessageBuilderClass(context, className, ExecuteMsg));
|
58
58
|
}
|
59
59
|
}
|
60
60
|
|
@@ -65,7 +65,7 @@ export class MsgBuilderPlugin extends BuilderPluginBase<RenderOptions> {
|
|
65
65
|
if (children.length > 0) {
|
66
66
|
const className = pascal(`${name}QueryMsgBuilder`);
|
67
67
|
|
68
|
-
body.push(w.
|
68
|
+
body.push(w.createMessageBuilderClass(context, className, QueryMsg));
|
69
69
|
}
|
70
70
|
}
|
71
71
|
|
@@ -76,7 +76,7 @@ export class MsgBuilderPlugin extends BuilderPluginBase<RenderOptions> {
|
|
76
76
|
|
77
77
|
return [
|
78
78
|
{
|
79
|
-
type: '
|
79
|
+
type: 'message-builder',
|
80
80
|
localname,
|
81
81
|
body
|
82
82
|
}
|
@@ -54,8 +54,8 @@ export class MessageComposerPlugin extends BuilderPluginBase<RenderOptions> {
|
|
54
54
|
if (ExecuteMsg) {
|
55
55
|
const children = getMessageProperties(ExecuteMsg);
|
56
56
|
if (children.length > 0) {
|
57
|
-
const TheClass = pascal(`${name}
|
58
|
-
const Interface = pascal(`${name}
|
57
|
+
const TheClass = pascal(`${name}MsgComposer`);
|
58
|
+
const Interface = pascal(`${name}Msg`);
|
59
59
|
|
60
60
|
body.push(
|
61
61
|
w.createMessageComposerInterface(context, Interface, ExecuteMsg)
|
@@ -15,15 +15,16 @@ export interface BundleOptions {
|
|
15
15
|
export interface UseContractsOptions {
|
16
16
|
enabled?: boolean;
|
17
17
|
}
|
18
|
-
export
|
18
|
+
export type TSBuilderOptions = {
|
19
19
|
bundle?: BundleOptions;
|
20
20
|
/**
|
21
21
|
* Enable using shorthand constructor.
|
22
|
+
* Default: true
|
22
23
|
*/
|
23
24
|
useShorthandCtor?: boolean;
|
24
25
|
useContractsHooks?: UseContractsOptions;
|
25
26
|
} & RenderOptions;
|
26
|
-
export
|
27
|
+
export type BuilderFileType = 'type' | 'client' | 'recoil' | 'react-query' | 'message-composer' | 'message-builder' | 'plugin';
|
27
28
|
export interface BuilderFile {
|
28
29
|
type: BuilderFileType;
|
29
30
|
pluginType?: string;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { ContractInfo } from "wasm-ast-types";
|
2
|
-
import {
|
2
|
+
import { MessageBuilderOptions } from 'wasm-ast-types';
|
3
3
|
import { BuilderFile } from "../builder";
|
4
|
-
declare const _default: (name: string, contractInfo: ContractInfo, outPath: string,
|
4
|
+
declare const _default: (name: string, contractInfo: ContractInfo, outPath: string, messageBuilderOptions?: MessageBuilderOptions) => Promise<BuilderFile[]>;
|
5
5
|
export default _default;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { ContractInfo } from "wasm-ast-types";
|
2
|
-
import {
|
2
|
+
import { MessageBuilderOptions } from "wasm-ast-types";
|
3
3
|
import { BuilderFile } from "../builder";
|
4
|
-
declare const _default: (name: string, contractInfo: ContractInfo, outPath: string,
|
4
|
+
declare const _default: (name: string, contractInfo: ContractInfo, outPath: string, messageBuilderOptions?: MessageBuilderOptions) => Promise<BuilderFile[]>;
|
5
5
|
export default _default;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { RenderContext, RenderContextBase, ContractInfo, RenderOptions } from 'wasm-ast-types';
|
2
|
+
import { BuilderFileType } from '../builder';
|
3
|
+
import { BuilderPluginBase } from './plugin-base';
|
4
|
+
export declare class MessageBuilderPlugin extends BuilderPluginBase<RenderOptions> {
|
5
|
+
initContext(contract: ContractInfo, options?: RenderOptions): RenderContextBase<RenderOptions>;
|
6
|
+
doRender(name: string, context: RenderContext): Promise<{
|
7
|
+
type: BuilderFileType;
|
8
|
+
pluginType?: string;
|
9
|
+
localname: string;
|
10
|
+
body: any[];
|
11
|
+
}[]>;
|
12
|
+
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { RenderContext, RenderContextBase, ContractInfo, RenderOptions } from 'wasm-ast-types';
|
2
2
|
import { BuilderFileType } from '../builder';
|
3
3
|
import { BuilderPluginBase } from './plugin-base';
|
4
|
-
export declare class
|
4
|
+
export declare class MessageBuilderPlugin extends BuilderPluginBase<RenderOptions> {
|
5
5
|
initContext(contract: ContractInfo, options?: RenderOptions): RenderContextBase<RenderOptions>;
|
6
6
|
doRender(name: string, context: RenderContext): Promise<{
|
7
7
|
type: BuilderFileType;
|