@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
@@ -29,11 +29,9 @@ export default (async argv => {
|
|
29
29
|
message: 'enable bundle?',
|
30
30
|
default: true
|
31
31
|
}];
|
32
|
-
|
33
32
|
if (argv.typesOnly) {
|
34
33
|
argv.plugin = 'types';
|
35
34
|
}
|
36
|
-
|
37
35
|
let {
|
38
36
|
schema,
|
39
37
|
out,
|
@@ -41,10 +39,10 @@ export default (async argv => {
|
|
41
39
|
plugin,
|
42
40
|
bundle
|
43
41
|
} = await prompt(questions, argv);
|
44
|
-
if (!Array.isArray(plugin)) plugin = [plugin];
|
42
|
+
if (!Array.isArray(plugin)) plugin = [plugin];
|
45
43
|
|
44
|
+
///////// REACT QUERY
|
46
45
|
const questions2 = [];
|
47
|
-
|
48
46
|
if (plugin.includes('react-query')) {
|
49
47
|
[].push.apply(questions2, [{
|
50
48
|
type: 'confirm',
|
@@ -64,7 +62,6 @@ export default (async argv => {
|
|
64
62
|
default: false
|
65
63
|
}]);
|
66
64
|
}
|
67
|
-
|
68
65
|
;
|
69
66
|
const {
|
70
67
|
optionalClient,
|
@@ -72,9 +69,9 @@ export default (async argv => {
|
|
72
69
|
queryKeys
|
73
70
|
} = await prompt(questions2, argv);
|
74
71
|
const questions3 = [];
|
75
|
-
|
76
72
|
if (version === 'v4') {
|
77
|
-
[].push.apply(questions3, [
|
73
|
+
[].push.apply(questions3, [
|
74
|
+
// currently we only support v4 for useMutation
|
78
75
|
{
|
79
76
|
type: 'confirm',
|
80
77
|
name: 'mutations',
|
@@ -82,15 +79,14 @@ export default (async argv => {
|
|
82
79
|
default: false
|
83
80
|
}]);
|
84
81
|
}
|
85
|
-
|
86
82
|
;
|
87
83
|
const {
|
88
84
|
mutations
|
89
85
|
} = await prompt(questions3, argv);
|
90
86
|
const queryFactoryQuestions = [];
|
91
|
-
|
92
87
|
if (queryKeys) {
|
93
|
-
[].push.apply(queryFactoryQuestions, [
|
88
|
+
[].push.apply(queryFactoryQuestions, [
|
89
|
+
// Only can use queryFactory if queryKeys is enabled
|
94
90
|
{
|
95
91
|
type: 'confirm',
|
96
92
|
name: 'queryFactory',
|
@@ -98,15 +94,14 @@ export default (async argv => {
|
|
98
94
|
default: false
|
99
95
|
}]);
|
100
96
|
}
|
101
|
-
|
102
97
|
;
|
103
98
|
const {
|
104
99
|
queryFactory
|
105
|
-
} = await prompt(queryFactoryQuestions, argv);
|
106
|
-
/////////
|
100
|
+
} = await prompt(queryFactoryQuestions, argv);
|
101
|
+
///////// END REACT QUERY
|
107
102
|
|
103
|
+
///////// BUNDLE
|
108
104
|
const questions4 = [];
|
109
|
-
|
110
105
|
if (bundle) {
|
111
106
|
[].push.apply(questions4, [{
|
112
107
|
type: 'string',
|
@@ -120,12 +115,12 @@ export default (async argv => {
|
|
120
115
|
default: 'contracts'
|
121
116
|
}]);
|
122
117
|
}
|
123
|
-
|
124
118
|
;
|
125
119
|
const {
|
126
120
|
bundleFile,
|
127
121
|
bundleScope
|
128
|
-
} = await prompt(questions4, argv);
|
122
|
+
} = await prompt(questions4, argv);
|
123
|
+
///////// END BUNDLE
|
129
124
|
|
130
125
|
const options = {
|
131
126
|
types: {
|
@@ -148,8 +143,8 @@ export default (async argv => {
|
|
148
143
|
messageComposer: {
|
149
144
|
enabled: plugin.includes('message-composer')
|
150
145
|
},
|
151
|
-
|
152
|
-
enabled: plugin.includes('
|
146
|
+
messageBuilder: {
|
147
|
+
enabled: plugin.includes('message-builder')
|
153
148
|
},
|
154
149
|
bundle: {
|
155
150
|
enabled: bundle,
|
@@ -1,9 +1,6 @@
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
2
|
-
|
3
2
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
4
|
-
|
5
3
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
6
|
-
|
7
4
|
import { resolve, join, dirname, basename, extname } from 'path';
|
8
5
|
import { sync as mkdirp } from 'mkdirp';
|
9
6
|
import { sync as glob } from 'glob';
|
@@ -14,9 +11,7 @@ import { parse } from 'parse-package-name';
|
|
14
11
|
import { tmpdir } from 'os';
|
15
12
|
import { readFileSync, writeFileSync } from 'fs';
|
16
13
|
const TMPDIR = tmpdir();
|
17
|
-
|
18
14
|
const rnd = () => Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
19
|
-
|
20
15
|
const getPackages = names => {
|
21
16
|
return names.map(pkg => {
|
22
17
|
const {
|
@@ -26,24 +21,22 @@ const getPackages = names => {
|
|
26
21
|
return `${name}@${version}`;
|
27
22
|
}).join(' ');
|
28
23
|
};
|
29
|
-
|
30
24
|
export default (async argv => {
|
31
25
|
// don't prompt if we got this...
|
32
26
|
if (argv._.length) {
|
33
27
|
argv.pkg = argv._;
|
34
|
-
}
|
35
|
-
|
28
|
+
}
|
36
29
|
|
30
|
+
// current dir/package
|
37
31
|
const cur = process.cwd();
|
38
32
|
let thisPackage;
|
39
|
-
|
40
33
|
try {
|
41
34
|
thisPackage = JSON.parse(readFileSync(join(cur, 'package.json'), 'utf-8'));
|
42
35
|
} catch (e) {
|
43
36
|
throw new Error('make sure you are inside of a telescope package!');
|
44
|
-
}
|
45
|
-
|
37
|
+
}
|
46
38
|
|
39
|
+
// what are we installing?
|
47
40
|
let {
|
48
41
|
pkg
|
49
42
|
} = await prompt([{
|
@@ -56,14 +49,16 @@ export default (async argv => {
|
|
56
49
|
value: `@cosmjson/${name}`
|
57
50
|
};
|
58
51
|
})
|
59
|
-
}], argv);
|
52
|
+
}], argv);
|
60
53
|
|
54
|
+
// install
|
61
55
|
if (!Array.isArray(pkg)) pkg = [pkg];
|
62
56
|
const tmp = join(TMPDIR, rnd());
|
63
57
|
mkdirp(tmp);
|
64
58
|
process.chdir(tmp);
|
65
|
-
exec(`npm install ${getPackages(pkg)} --production --prefix ./smart-contracts`);
|
59
|
+
exec(`npm install ${getPackages(pkg)} --production --prefix ./smart-contracts`);
|
66
60
|
|
61
|
+
// protos
|
67
62
|
const pkgs = glob('./smart-contracts/**/package.json');
|
68
63
|
const cmds = pkgs.filter(f => {
|
69
64
|
return f !== './smart-contracts/package.json';
|
@@ -79,23 +74,25 @@ export default (async argv => {
|
|
79
74
|
rimraf(f);
|
80
75
|
});
|
81
76
|
return [extDir, resolve(join(cur, 'contracts', dst)), dir];
|
82
|
-
});
|
77
|
+
});
|
83
78
|
|
79
|
+
// move protos
|
84
80
|
for (const [src, dst, pkg] of cmds) {
|
85
81
|
rimraf(dst);
|
86
82
|
console.log(`installing ${pkg}...`);
|
87
83
|
mkdirp(dirname(dst));
|
88
84
|
exec(`mv ${src} ${dst}`);
|
89
|
-
}
|
90
|
-
|
85
|
+
}
|
91
86
|
|
87
|
+
// package
|
92
88
|
const packageInfo = JSON.parse(readFileSync('./smart-contracts/package.json', 'utf-8'));
|
93
89
|
const deps = packageInfo.dependencies ?? {};
|
94
90
|
thisPackage.devDependencies = thisPackage.devDependencies ?? {};
|
95
91
|
thisPackage.devDependencies = _objectSpread(_objectSpread({}, thisPackage.devDependencies), deps);
|
96
92
|
thisPackage.devDependencies = Object.fromEntries(Object.entries(thisPackage.devDependencies).sort());
|
97
|
-
writeFileSync(join(cur, 'package.json'), JSON.stringify(thisPackage, null, 2));
|
93
|
+
writeFileSync(join(cur, 'package.json'), JSON.stringify(thisPackage, null, 2));
|
98
94
|
|
95
|
+
// cleanup
|
99
96
|
rimraf(tmp);
|
100
97
|
process.chdir(cur);
|
101
98
|
});
|
package/module/file.js
CHANGED
@@ -2,16 +2,13 @@
|
|
2
2
|
import { prompt } from './utils/prompt';
|
3
3
|
import { cli } from './cli';
|
4
4
|
import { readFileSync } from 'fs';
|
5
|
-
|
6
5
|
const argv = require('minimist')(process.argv.slice(2));
|
7
|
-
|
8
6
|
const question = [{
|
9
7
|
_: true,
|
10
8
|
type: 'string',
|
11
9
|
name: 'file',
|
12
10
|
message: 'file'
|
13
11
|
}];
|
14
|
-
|
15
12
|
(async () => {
|
16
13
|
const {
|
17
14
|
file
|
@@ -15,7 +15,8 @@ export default (async (name, contractInfo, outPath, tsClientOptions) => {
|
|
15
15
|
} = contractInfo;
|
16
16
|
const context = new RenderContext(contractInfo, {
|
17
17
|
client: tsClientOptions ?? {}
|
18
|
-
});
|
18
|
+
});
|
19
|
+
// const options = context.options.client;
|
19
20
|
|
20
21
|
const localname = pascal(name) + '.client.ts';
|
21
22
|
const TypesFile = pascal(name) + '.types';
|
@@ -27,19 +28,19 @@ export default (async (name, contractInfo, outPath, tsClientOptions) => {
|
|
27
28
|
let QueryClient = null;
|
28
29
|
let ReadOnlyInstance = null;
|
29
30
|
const body = [];
|
30
|
-
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
31
|
+
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
31
32
|
|
33
|
+
// query messages
|
32
34
|
if (QueryMsg) {
|
33
35
|
QueryClient = pascal(`${name}QueryClient`);
|
34
36
|
ReadOnlyInstance = pascal(`${name}ReadOnlyInterface`);
|
35
37
|
body.push(w.createQueryInterface(context, ReadOnlyInstance, QueryMsg));
|
36
38
|
body.push(w.createQueryClass(context, QueryClient, ReadOnlyInstance, QueryMsg));
|
37
|
-
}
|
38
|
-
|
39
|
+
}
|
39
40
|
|
41
|
+
// execute messages
|
40
42
|
if (ExecuteMsg) {
|
41
43
|
const children = getMessageProperties(ExecuteMsg);
|
42
|
-
|
43
44
|
if (children.length > 0) {
|
44
45
|
Client = pascal(`${name}Client`);
|
45
46
|
Instance = pascal(`${name}Interface`);
|
@@ -47,12 +48,10 @@ export default (async (name, contractInfo, outPath, tsClientOptions) => {
|
|
47
48
|
body.push(w.createExecuteClass(context, Client, Instance, context.options.client.execExtendsQuery ? QueryClient : null, ExecuteMsg));
|
48
49
|
}
|
49
50
|
}
|
50
|
-
|
51
51
|
if (typeHash.hasOwnProperty('Coin')) {
|
52
52
|
// @ts-ignore
|
53
53
|
delete context.utils.Coin;
|
54
54
|
}
|
55
|
-
|
56
55
|
const imports = context.getImports();
|
57
56
|
const code = header + generate(t.program([...imports, ...body])).code;
|
58
57
|
mkdirp(outPath);
|
@@ -10,7 +10,6 @@ const header = `/**
|
|
10
10
|
* and run the transpile command or yarn proto command to regenerate this bundle.
|
11
11
|
*/
|
12
12
|
\n`;
|
13
|
-
|
14
13
|
const write = (outPath, file, content, varname) => {
|
15
14
|
const outFile = join(outPath, file);
|
16
15
|
mkdirp(dirname(outFile));
|
@@ -23,15 +22,12 @@ const write = (outPath, file, content, varname) => {
|
|
23
22
|
filename: outFile
|
24
23
|
};
|
25
24
|
};
|
26
|
-
|
27
25
|
export const createHelpers = (input, builderContext) => {
|
28
26
|
const files = [];
|
29
|
-
|
30
27
|
if (input.options?.useContractsHooks?.enabled && Object.keys(builderContext.providers)?.length) {
|
31
28
|
const useShorthandCtor = input.options?.useShorthandCtor;
|
32
29
|
files.push(write(input.outPath, "contractContextBase.ts", useShorthandCtor ? contractContextBaseShortHandCtor : contractContextBase));
|
33
30
|
files.push(write(input.outPath, "contracts-context.tsx", contractsContextTSX, "contractsContext"));
|
34
31
|
}
|
35
|
-
|
36
32
|
return files;
|
37
33
|
};
|
@@ -15,18 +15,19 @@ export default (async (name, contractInfo, outPath, messageComposerOptions) => {
|
|
15
15
|
} = contractInfo;
|
16
16
|
const context = new RenderContext(contractInfo, {
|
17
17
|
messageComposer: messageComposerOptions ?? {}
|
18
|
-
});
|
18
|
+
});
|
19
|
+
// const options = context.options.messageComposer;
|
19
20
|
|
20
21
|
const localname = pascal(name) + '.message-composer.ts';
|
21
22
|
const TypesFile = pascal(name) + '.types';
|
22
23
|
const ExecuteMsg = findExecuteMsg(schemas);
|
23
24
|
const typeHash = await findAndParseTypes(schemas);
|
24
25
|
const body = [];
|
25
|
-
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
26
|
+
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
26
27
|
|
28
|
+
// execute messages
|
27
29
|
if (ExecuteMsg) {
|
28
30
|
const children = getMessageProperties(ExecuteMsg);
|
29
|
-
|
30
31
|
if (children.length > 0) {
|
31
32
|
const TheClass = pascal(`${name}MessageComposer`);
|
32
33
|
const Interface = pascal(`${name}Message`);
|
@@ -34,12 +35,10 @@ export default (async (name, contractInfo, outPath, messageComposerOptions) => {
|
|
34
35
|
body.push(w.createMessageComposerClass(context, TheClass, Interface, ExecuteMsg));
|
35
36
|
}
|
36
37
|
}
|
37
|
-
|
38
38
|
if (typeHash.hasOwnProperty('Coin')) {
|
39
39
|
// @ts-ignore
|
40
40
|
delete context.utils.Coin;
|
41
41
|
}
|
42
|
-
|
43
42
|
const imports = context.getImports();
|
44
43
|
const code = header + generate(t.program([...imports, ...body])).code;
|
45
44
|
mkdirp(outPath);
|
@@ -9,52 +9,48 @@ import generate from "@babel/generator";
|
|
9
9
|
import { getMessageProperties } from "wasm-ast-types";
|
10
10
|
import { findAndParseTypes, findExecuteMsg, findQueryMsg } from '../utils';
|
11
11
|
import { RenderContext } from 'wasm-ast-types';
|
12
|
-
export default (async (name, contractInfo, outPath,
|
12
|
+
export default (async (name, contractInfo, outPath, messageBuilderOptions) => {
|
13
13
|
const {
|
14
14
|
schemas
|
15
15
|
} = contractInfo;
|
16
16
|
const context = new RenderContext(contractInfo, {
|
17
|
-
|
17
|
+
messageBuilder: messageBuilderOptions ?? {}
|
18
18
|
});
|
19
|
-
const localname = pascal(name) + ".
|
19
|
+
const localname = pascal(name) + ".message-builder.ts";
|
20
20
|
const TypesFile = pascal(name) + ".types";
|
21
21
|
const ExecuteMsg = findExecuteMsg(schemas);
|
22
22
|
const typeHash = await findAndParseTypes(schemas);
|
23
23
|
const body = [];
|
24
24
|
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
25
|
-
body.push(w.importStmt(["CamelCasedProperties"], "type-fest"));
|
25
|
+
body.push(w.importStmt(["CamelCasedProperties"], "type-fest"));
|
26
26
|
|
27
|
+
// execute messages
|
27
28
|
if (ExecuteMsg) {
|
28
29
|
const children = getMessageProperties(ExecuteMsg);
|
29
|
-
|
30
30
|
if (children.length > 0) {
|
31
31
|
const className = pascal(`${name}ExecuteMsgBuilder`);
|
32
|
-
body.push(w.
|
32
|
+
body.push(w.createMessageBuilderClass(context, className, ExecuteMsg));
|
33
33
|
}
|
34
34
|
}
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
const QueryMsg = findQueryMsg(schemas);
|
36
|
+
// query messages
|
38
37
|
if (QueryMsg) {
|
39
38
|
const children = getMessageProperties(QueryMsg);
|
40
|
-
|
41
39
|
if (children.length > 0) {
|
42
40
|
const className = pascal(`${name}QueryMsgBuilder`);
|
43
|
-
body.push(w.
|
41
|
+
body.push(w.createMessageBuilderClass(context, className, QueryMsg));
|
44
42
|
}
|
45
43
|
}
|
46
|
-
|
47
44
|
if (typeHash.hasOwnProperty("Coin")) {
|
48
45
|
// @ts-ignore
|
49
46
|
delete context.utils.Coin;
|
50
47
|
}
|
51
|
-
|
52
48
|
const imports = context.getImports();
|
53
49
|
const code = header + generate(t.program([...imports, ...body])).code;
|
54
50
|
mkdirp(outPath);
|
55
51
|
writeFileSync(join(outPath, localname), code);
|
56
52
|
return [{
|
57
|
-
type: "
|
53
|
+
type: "message-builder",
|
58
54
|
contract: name,
|
59
55
|
localname,
|
60
56
|
filename: join(outPath, localname)
|
@@ -27,19 +27,21 @@ export default (async (contractName, contractInfo, outPath, reactQueryOptions) =
|
|
27
27
|
const QueryClient = pascal(`${contractName}QueryClient`);
|
28
28
|
const body = [];
|
29
29
|
const clientImports = [];
|
30
|
-
QueryMsg && clientImports.push(QueryClient);
|
30
|
+
QueryMsg && clientImports.push(QueryClient);
|
31
31
|
|
32
|
+
// check that there are commands within the exec msg
|
32
33
|
const shouldGenerateMutationHooks = ExecuteMsg && options?.version === 'v4' && options?.mutations && getMessageProperties(ExecuteMsg).length > 0;
|
33
|
-
|
34
34
|
if (shouldGenerateMutationHooks) {
|
35
35
|
clientImports.push(ExecuteClient);
|
36
|
-
}
|
37
|
-
|
36
|
+
}
|
38
37
|
|
39
|
-
|
38
|
+
// general contract imports
|
39
|
+
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
40
40
|
|
41
|
-
|
41
|
+
// client imports
|
42
|
+
body.push(w.importStmt(clientImports, `./${ContractFile}`));
|
42
43
|
|
44
|
+
// query messages
|
43
45
|
if (QueryMsg) {
|
44
46
|
[].push.apply(body, w.createReactQueryHooks({
|
45
47
|
context,
|
@@ -48,7 +50,6 @@ export default (async (contractName, contractInfo, outPath, reactQueryOptions) =
|
|
48
50
|
QueryClient
|
49
51
|
}));
|
50
52
|
}
|
51
|
-
|
52
53
|
if (shouldGenerateMutationHooks) {
|
53
54
|
[].push.apply(body, w.createReactQueryMutationHooks({
|
54
55
|
context,
|
@@ -57,12 +58,10 @@ export default (async (contractName, contractInfo, outPath, reactQueryOptions) =
|
|
57
58
|
ExecuteClient
|
58
59
|
}));
|
59
60
|
}
|
60
|
-
|
61
61
|
if (typeHash.hasOwnProperty('Coin')) {
|
62
62
|
// @ts-ignore
|
63
63
|
delete context.utils.Coin;
|
64
64
|
}
|
65
|
-
|
66
65
|
const imports = context.getImports();
|
67
66
|
const code = header + generate(t.program([...imports, ...body])).code;
|
68
67
|
mkdirp(outPath);
|
@@ -25,8 +25,9 @@ export default (async (name, contractInfo, outPath, recoilOptions) => {
|
|
25
25
|
let ReadOnlyInstance = null;
|
26
26
|
const body = [];
|
27
27
|
body.push(w.importStmt(['cosmWasmClient'], './chain'));
|
28
|
-
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
28
|
+
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
29
29
|
|
30
|
+
// query messages
|
30
31
|
if (QueryMsg) {
|
31
32
|
QueryClient = pascal(`${name}QueryClient`);
|
32
33
|
ReadOnlyInstance = pascal(`${name}ReadOnlyInterface`);
|
@@ -35,12 +36,10 @@ export default (async (name, contractInfo, outPath, recoilOptions) => {
|
|
35
36
|
body.push(w.createRecoilQueryClient(context, name, QueryClient));
|
36
37
|
[].push.apply(body, w.createRecoilSelectors(context, name, QueryClient, QueryMsg));
|
37
38
|
}
|
38
|
-
|
39
39
|
if (typeHash.hasOwnProperty('Coin')) {
|
40
40
|
// @ts-ignore
|
41
41
|
delete context.utils.Coin;
|
42
42
|
}
|
43
|
-
|
44
43
|
const imports = context.getImports();
|
45
44
|
const code = header + generate(t.program([...imports, ...body])).code;
|
46
45
|
mkdirp(outPath);
|
@@ -19,30 +19,28 @@ export default (async (name, contractInfo, outPath, tsTypesOptions) => {
|
|
19
19
|
const localname = pascal(name) + '.types.ts';
|
20
20
|
const ExecuteMsg = findExecuteMsg(schemas);
|
21
21
|
const typeHash = await findAndParseTypes(schemas);
|
22
|
-
const body = [];
|
22
|
+
const body = [];
|
23
23
|
|
24
|
+
// TYPES
|
24
25
|
Object.values(typeHash).forEach(type => {
|
25
26
|
body.push(clean(type));
|
26
|
-
});
|
27
|
+
});
|
27
28
|
|
29
|
+
// alias the ExecuteMsg (deprecated option)
|
28
30
|
if (options.aliasExecuteMsg && ExecuteMsg) {
|
29
31
|
body.push(t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(`${name}ExecuteMsg`), null, t.tsTypeReference(t.identifier('ExecuteMsg')))));
|
30
32
|
}
|
31
|
-
|
32
33
|
function addEntryPointAlias(msgName) {
|
33
34
|
body.push(t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(`${name}${msgName}`), null, t.tsTypeReference(t.identifier(msgName)))));
|
34
35
|
}
|
35
|
-
|
36
36
|
if (options.aliasEntryPoints) {
|
37
37
|
if (ExecuteMsg) {
|
38
38
|
addEntryPointAlias('ExecuteMsg');
|
39
39
|
}
|
40
|
-
|
41
40
|
if (findQueryMsg(schemas)) {
|
42
41
|
addEntryPointAlias('QueryMsg');
|
43
42
|
}
|
44
43
|
}
|
45
|
-
|
46
44
|
const imports = context.getImports();
|
47
45
|
const code = header + generate(t.program([...imports, ...body])).code;
|
48
46
|
mkdirp(outPath);
|
package/module/plugins/client.js
CHANGED
@@ -8,16 +8,13 @@ export class ClientPlugin extends BuilderPluginBase {
|
|
8
8
|
initContext(contract, options) {
|
9
9
|
return new RenderContext(contract, options, this.builder.builderContext);
|
10
10
|
}
|
11
|
-
|
12
11
|
async doRender(name, context) {
|
13
12
|
const {
|
14
13
|
enabled
|
15
14
|
} = this.option.client;
|
16
|
-
|
17
15
|
if (!enabled) {
|
18
16
|
return;
|
19
17
|
}
|
20
|
-
|
21
18
|
const {
|
22
19
|
schemas
|
23
20
|
} = context.contract;
|
@@ -31,20 +28,20 @@ export class ClientPlugin extends BuilderPluginBase {
|
|
31
28
|
let QueryClient = null;
|
32
29
|
let ReadOnlyInstance = null;
|
33
30
|
const body = [];
|
34
|
-
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
31
|
+
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
35
32
|
|
33
|
+
// query messages
|
36
34
|
if (QueryMsg) {
|
37
35
|
QueryClient = pascal(`${name}QueryClient`);
|
38
36
|
ReadOnlyInstance = pascal(`${name}ReadOnlyInterface`);
|
39
37
|
body.push(w.createQueryInterface(context, ReadOnlyInstance, QueryMsg));
|
40
38
|
body.push(w.createQueryClass(context, QueryClient, ReadOnlyInstance, QueryMsg));
|
41
39
|
context.addProviderInfo(name, w.PROVIDER_TYPES.QUERY_CLIENT_TYPE, QueryClient, localname);
|
42
|
-
}
|
43
|
-
|
40
|
+
}
|
44
41
|
|
42
|
+
// execute messages
|
45
43
|
if (ExecuteMsg) {
|
46
44
|
const children = getMessageProperties(ExecuteMsg);
|
47
|
-
|
48
45
|
if (children.length > 0) {
|
49
46
|
Client = pascal(`${name}Client`);
|
50
47
|
Instance = pascal(`${name}Interface`);
|
@@ -53,17 +50,14 @@ export class ClientPlugin extends BuilderPluginBase {
|
|
53
50
|
context.addProviderInfo(name, w.PROVIDER_TYPES.SIGNING_CLIENT_TYPE, Client, localname);
|
54
51
|
}
|
55
52
|
}
|
56
|
-
|
57
53
|
if (typeHash.hasOwnProperty("Coin")) {
|
58
54
|
// @ts-ignore
|
59
55
|
delete context.utils.Coin;
|
60
56
|
}
|
61
|
-
|
62
57
|
return [{
|
63
58
|
type: TYPE,
|
64
59
|
localname,
|
65
60
|
body
|
66
61
|
}];
|
67
62
|
}
|
68
|
-
|
69
63
|
}
|
@@ -3,61 +3,53 @@ import * as w from 'wasm-ast-types';
|
|
3
3
|
import { findAndParseTypes, findQueryMsg, findExecuteMsg } from '../utils';
|
4
4
|
import { getMessageProperties, RenderContext } from 'wasm-ast-types';
|
5
5
|
import { BuilderPluginBase } from './plugin-base';
|
6
|
-
export class
|
6
|
+
export class MessageBuilderPlugin extends BuilderPluginBase {
|
7
7
|
initContext(contract, options) {
|
8
8
|
return new RenderContext(contract, options, this.builder.builderContext);
|
9
9
|
}
|
10
|
-
|
11
10
|
async doRender(name, context) {
|
12
11
|
const {
|
13
12
|
enabled
|
14
|
-
} = this.option.
|
15
|
-
|
13
|
+
} = this.option.messageBuilder;
|
16
14
|
if (!enabled) {
|
17
15
|
return;
|
18
16
|
}
|
19
|
-
|
20
17
|
const {
|
21
18
|
schemas
|
22
19
|
} = context.contract;
|
23
|
-
const localname = pascal(name) + '.
|
20
|
+
const localname = pascal(name) + '.message-builder.ts';
|
24
21
|
const TypesFile = pascal(name) + '.types';
|
25
22
|
const ExecuteMsg = findExecuteMsg(schemas);
|
26
23
|
const typeHash = await findAndParseTypes(schemas);
|
27
24
|
const body = [];
|
28
25
|
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
29
|
-
body.push(w.importStmt(['CamelCasedProperties'], 'type-fest'));
|
26
|
+
body.push(w.importStmt(['CamelCasedProperties'], 'type-fest'));
|
30
27
|
|
28
|
+
// execute messages
|
31
29
|
if (ExecuteMsg) {
|
32
30
|
const children = getMessageProperties(ExecuteMsg);
|
33
|
-
|
34
31
|
if (children.length > 0) {
|
35
32
|
const className = pascal(`${name}ExecuteMsgBuilder`);
|
36
|
-
body.push(w.
|
33
|
+
body.push(w.createMessageBuilderClass(context, className, ExecuteMsg));
|
37
34
|
}
|
38
35
|
}
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
const QueryMsg = findQueryMsg(schemas);
|
37
|
+
// query messages
|
42
38
|
if (QueryMsg) {
|
43
39
|
const children = getMessageProperties(QueryMsg);
|
44
|
-
|
45
40
|
if (children.length > 0) {
|
46
41
|
const className = pascal(`${name}QueryMsgBuilder`);
|
47
|
-
body.push(w.
|
42
|
+
body.push(w.createMessageBuilderClass(context, className, QueryMsg));
|
48
43
|
}
|
49
44
|
}
|
50
|
-
|
51
45
|
if (typeHash.hasOwnProperty('Coin')) {
|
52
46
|
// @ts-ignore
|
53
47
|
delete context.utils.Coin;
|
54
48
|
}
|
55
|
-
|
56
49
|
return [{
|
57
|
-
type: '
|
50
|
+
type: 'message-builder',
|
58
51
|
localname,
|
59
52
|
body
|
60
53
|
}];
|
61
54
|
}
|
62
|
-
|
63
55
|
}
|
@@ -8,16 +8,13 @@ export class MessageComposerPlugin extends BuilderPluginBase {
|
|
8
8
|
initContext(contract, options) {
|
9
9
|
return new RenderContext(contract, options, this.builder.builderContext);
|
10
10
|
}
|
11
|
-
|
12
11
|
async doRender(name, context) {
|
13
12
|
const {
|
14
13
|
enabled
|
15
14
|
} = this.option.messageComposer;
|
16
|
-
|
17
15
|
if (!enabled) {
|
18
16
|
return;
|
19
17
|
}
|
20
|
-
|
21
18
|
const {
|
22
19
|
schemas
|
23
20
|
} = context.contract;
|
@@ -26,30 +23,27 @@ export class MessageComposerPlugin extends BuilderPluginBase {
|
|
26
23
|
const ExecuteMsg = findExecuteMsg(schemas);
|
27
24
|
const typeHash = await findAndParseTypes(schemas);
|
28
25
|
const body = [];
|
29
|
-
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
26
|
+
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
30
27
|
|
28
|
+
// execute messages
|
31
29
|
if (ExecuteMsg) {
|
32
30
|
const children = getMessageProperties(ExecuteMsg);
|
33
|
-
|
34
31
|
if (children.length > 0) {
|
35
|
-
const TheClass = pascal(`${name}
|
36
|
-
const Interface = pascal(`${name}
|
32
|
+
const TheClass = pascal(`${name}MsgComposer`);
|
33
|
+
const Interface = pascal(`${name}Msg`);
|
37
34
|
body.push(w.createMessageComposerInterface(context, Interface, ExecuteMsg));
|
38
35
|
body.push(w.createMessageComposerClass(context, TheClass, Interface, ExecuteMsg));
|
39
36
|
context.addProviderInfo(name, w.PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE, TheClass, localname);
|
40
37
|
}
|
41
38
|
}
|
42
|
-
|
43
39
|
if (typeHash.hasOwnProperty("Coin")) {
|
44
40
|
// @ts-ignore
|
45
41
|
delete context.utils.Coin;
|
46
42
|
}
|
47
|
-
|
48
43
|
return [{
|
49
44
|
type: TYPE,
|
50
45
|
localname,
|
51
46
|
body
|
52
47
|
}];
|
53
48
|
}
|
54
|
-
|
55
49
|
}
|