@cosmwasm/ts-codegen 0.35.7 → 1.1.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/LICENSE-Apache +201 -0
- package/LICENSE-MIT +21 -0
- package/README.md +106 -101
- package/{types/src/builder → builder}/builder.d.ts +2 -2
- package/builder/builder.js +172 -0
- package/builder/index.js +17 -0
- package/bundler/bundler.d.ts +8 -0
- package/bundler/bundler.js +79 -0
- package/bundler/index.js +17 -0
- package/cli.d.ts +2 -0
- package/cli.js +24 -0
- package/cmds.d.ts +2 -0
- package/cmds.js +14 -0
- package/commands/create-boilerplate.d.ts +3 -0
- package/commands/create-boilerplate.js +132 -0
- package/commands/generate.d.ts +3 -0
- package/commands/generate.js +175 -0
- package/commands/install.d.ts +3 -0
- package/commands/install.js +107 -0
- package/{src/builder/builder.ts → esm/builder/builder.js} +39 -139
- package/esm/builder/index.js +1 -0
- package/esm/bundler/bundler.js +47 -0
- package/esm/bundler/index.js +1 -0
- package/esm/cli.js +20 -0
- package/{src → esm}/cmds.js +0 -1
- package/{src/commands/create-boilerplate.ts → esm/commands/create-boilerplate.js} +35 -70
- package/{src/commands/generate.ts → esm/commands/generate.js} +19 -24
- package/{src/commands/install.ts → esm/commands/install.js} +22 -35
- package/esm/file.js +18 -0
- package/esm/generators/client.js +67 -0
- package/esm/generators/create-helpers.js +36 -0
- package/esm/generators/message-builder.js +58 -0
- package/esm/generators/message-composer.js +55 -0
- package/esm/generators/react-query.js +76 -0
- package/esm/generators/recoil.js +58 -0
- package/esm/generators/types.js +58 -0
- package/{src/index.ts → esm/index.js} +4 -6
- package/esm/plugins/client.js +59 -0
- package/esm/plugins/message-builder.js +52 -0
- package/esm/plugins/message-composer.js +46 -0
- package/esm/plugins/plugin-base.js +47 -0
- package/esm/plugins/provider-bundle.js +58 -0
- package/esm/plugins/provider.js +73 -0
- package/esm/plugins/react-query.js +69 -0
- package/esm/plugins/recoil.js +51 -0
- package/esm/plugins/types.js +38 -0
- package/{src → esm}/ts-codegen.js +1 -2
- package/{src/utils/clean.ts → esm/utils/clean.js} +7 -7
- package/{src/utils/cleanse.ts → esm/utils/cleanse.js} +18 -22
- package/esm/utils/files.js +42 -0
- package/{src/utils/parse.ts → esm/utils/parse.js} +4 -13
- package/esm/utils/prompt.js +59 -0
- package/{src/utils/schemas.ts → esm/utils/schemas.js} +16 -44
- package/esm/utils/unused.js +47 -0
- package/file.js +20 -0
- package/generators/client.js +95 -0
- package/generators/create-helpers.js +43 -0
- package/generators/message-builder.js +86 -0
- package/generators/message-composer.js +83 -0
- package/generators/react-query.js +104 -0
- package/generators/recoil.js +86 -0
- package/generators/types.js +86 -0
- package/{module/helpers → helpers}/contractContextBase.js +5 -2
- package/{module/helpers → helpers}/contractContextBaseShortHandCtor.js +5 -2
- package/{module/helpers → helpers}/contractsContextTSX.js +5 -2
- package/{module/helpers/index.js → helpers/index.d.ts} +1 -1
- package/helpers/index.js +19 -0
- package/{types/src/index.d.ts → index.d.ts} +1 -0
- package/index.js +41 -0
- package/package.json +28 -63
- package/plugins/client.js +86 -0
- package/plugins/index.d.ts +1 -0
- package/plugins/index.js +17 -0
- package/plugins/message-builder.js +79 -0
- package/plugins/message-composer.js +73 -0
- package/{types/src/plugins → plugins}/plugin-base.d.ts +1 -1
- package/plugins/plugin-base.js +77 -0
- package/plugins/provider-bundle.js +85 -0
- package/{types/src/plugins → plugins}/provider.d.ts +2 -2
- package/plugins/provider.js +102 -0
- package/plugins/react-query.js +96 -0
- package/plugins/recoil.js +78 -0
- package/plugins/types.js +65 -0
- package/ts-codegen.js +8 -0
- package/utils/clean.js +49 -0
- package/utils/cleanse.js +89 -0
- package/utils/files.js +73 -0
- package/utils/header.js +14 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +17 -0
- package/utils/parse.d.ts +1 -0
- package/utils/parse.js +43 -0
- package/utils/prompt.d.ts +3 -0
- package/utils/prompt.js +65 -0
- package/utils/schemas.d.ts +11 -0
- package/utils/schemas.js +81 -0
- package/utils/unused.js +73 -0
- package/main/builder/builder.js +0 -308
- package/main/builder/index.js +0 -16
- package/main/bundler/bundler.js +0 -61
- package/main/bundler/index.js +0 -16
- package/main/cli.js +0 -51
- package/main/cmds.js +0 -15
- package/main/commands/create-boilerplate.js +0 -166
- package/main/commands/generate.js +0 -196
- package/main/commands/install.js +0 -138
- package/main/file.js +0 -35
- package/main/generators/client.js +0 -90
- package/main/generators/create-helpers.js +0 -38
- package/main/generators/message-composer.js +0 -77
- package/main/generators/msg-builder.js +0 -84
- package/main/generators/react-query.js +0 -102
- package/main/generators/recoil.js +0 -81
- package/main/generators/types.js +0 -82
- package/main/helpers/contractContextBase.js +0 -8
- package/main/helpers/contractContextBaseShortHandCtor.js +0 -8
- package/main/helpers/contractsContextTSX.js +0 -8
- package/main/helpers/index.js +0 -38
- package/main/index.js +0 -119
- package/main/plugins/client.js +0 -112
- package/main/plugins/index.js +0 -16
- package/main/plugins/message-builder.js +0 -102
- package/main/plugins/message-composer.js +0 -98
- package/main/plugins/plugin-base.js +0 -103
- package/main/plugins/provider-bundle.js +0 -108
- package/main/plugins/provider.js +0 -126
- package/main/plugins/react-query.js +0 -120
- package/main/plugins/recoil.js +0 -108
- package/main/plugins/types.js +0 -89
- package/main/ts-codegen.js +0 -20
- package/main/utils/clean.js +0 -53
- package/main/utils/cleanse.js +0 -87
- package/main/utils/files.js +0 -57
- package/main/utils/header.js +0 -11
- package/main/utils/index.js +0 -16
- package/main/utils/parse.js +0 -44
- package/main/utils/prompt.js +0 -98
- package/main/utils/schemas.js +0 -144
- package/main/utils/unused.js +0 -57
- package/module/builder/builder.js +0 -143
- package/module/builder/index.js +0 -1
- package/module/bundler/bundler.js +0 -36
- package/module/bundler/index.js +0 -1
- package/module/cli.js +0 -19
- package/module/cmds.js +0 -8
- package/module/commands/create-boilerplate.js +0 -102
- package/module/commands/generate.js +0 -163
- package/module/commands/install.js +0 -98
- package/module/file.js +0 -18
- package/module/generators/client.js +0 -65
- package/module/generators/create-helpers.js +0 -33
- package/module/generators/message-composer.js +0 -52
- package/module/generators/msg-builder.js +0 -58
- package/module/generators/react-query.js +0 -75
- package/module/generators/recoil.js +0 -53
- package/module/generators/types.js +0 -55
- package/module/index.js +0 -14
- package/module/plugins/client.js +0 -63
- package/module/plugins/index.js +0 -1
- package/module/plugins/message-builder.js +0 -55
- package/module/plugins/message-composer.js +0 -49
- package/module/plugins/plugin-base.js +0 -66
- package/module/plugins/provider-bundle.js +0 -56
- package/module/plugins/provider.js +0 -68
- package/module/plugins/react-query.js +0 -72
- package/module/plugins/recoil.js +0 -57
- package/module/plugins/types.js +0 -42
- package/module/ts-codegen.js +0 -6
- package/module/utils/clean.js +0 -44
- package/module/utils/cleanse.js +0 -78
- package/module/utils/files.js +0 -40
- package/module/utils/header.js +0 -8
- package/module/utils/index.js +0 -1
- package/module/utils/parse.js +0 -35
- package/module/utils/prompt.js +0 -63
- package/module/utils/schemas.js +0 -85
- package/module/utils/unused.js +0 -43
- package/src/builder/index.ts +0 -1
- package/src/bundler/bundler.ts +0 -67
- package/src/bundler/index.ts +0 -1
- package/src/cli.js +0 -21
- package/src/file.js +0 -20
- package/src/generators/client.ts +0 -109
- package/src/generators/create-helpers.ts +0 -71
- package/src/generators/message-composer.ts +0 -86
- package/src/generators/msg-builder.ts +0 -78
- package/src/generators/react-query.ts +0 -102
- package/src/generators/recoil.ts +0 -92
- package/src/generators/types.ts +0 -94
- package/src/helpers/index.ts +0 -3
- package/src/plugins/client.ts +0 -124
- package/src/plugins/index.ts +0 -1
- package/src/plugins/message-builder.ts +0 -85
- package/src/plugins/message-composer.ts +0 -89
- package/src/plugins/plugin-base.ts +0 -122
- package/src/plugins/provider-bundle.ts +0 -98
- package/src/plugins/provider.ts +0 -115
- package/src/plugins/react-query.ts +0 -115
- package/src/plugins/recoil.ts +0 -89
- package/src/plugins/types.ts +0 -74
- package/src/utils/files.ts +0 -73
- package/src/utils/index.ts +0 -1
- package/src/utils/prompt.js +0 -65
- package/src/utils/unused.ts +0 -52
- package/types/src/bundler/bundler.d.ts +0 -4
- package/types/src/cli.d.ts +0 -1
- package/types/src/cmds.d.ts +0 -1
- package/types/src/commands/create-boilerplate.d.ts +0 -2
- package/types/src/commands/generate.d.ts +0 -2
- package/types/src/commands/install.d.ts +0 -2
- package/types/src/generators/msg-builder.ts +0 -5
- package/types/src/plugins/msg-builder.d.ts +0 -12
- package/types/src/plugins/use-contracts.d.ts +0 -12
- package/types/src/types.d.ts +0 -16
- package/types/src/utils/parse.d.ts +0 -1
- package/types/src/utils/prompt.d.ts +0 -3
- package/types/src/utils/schemas.d.ts +0 -10
- /package/{types/src/builder → builder}/index.d.ts +0 -0
- /package/{types/src/bundler → bundler}/index.d.ts +0 -0
- /package/{src/helpers/contractContextBase.ts → esm/helpers/contractContextBase.js} +0 -0
- /package/{src/helpers/contractContextBaseShortHandCtor.ts → esm/helpers/contractContextBaseShortHandCtor.js} +0 -0
- /package/{src/helpers/contractsContextTSX.ts → esm/helpers/contractsContextTSX.js} +0 -0
- /package/{types/src/helpers/index.d.ts → esm/helpers/index.js} +0 -0
- /package/{types/src/plugins/index.d.ts → esm/plugins/index.js} +0 -0
- /package/{src/utils/header.ts → esm/utils/header.js} +0 -0
- /package/{types/src/utils/index.d.ts → esm/utils/index.js} +0 -0
- /package/{types/src/file.d.ts → file.d.ts} +0 -0
- /package/{types/src/generators → generators}/client.d.ts +0 -0
- /package/{types/src/generators → generators}/create-helpers.d.ts +0 -0
- /package/{types/src/generators/msg-builder.d.ts → generators/message-builder.d.ts} +0 -0
- /package/{types/src/generators → generators}/message-composer.d.ts +0 -0
- /package/{types/src/generators → generators}/react-query.d.ts +0 -0
- /package/{types/src/generators → generators}/recoil.d.ts +0 -0
- /package/{types/src/generators → generators}/types.d.ts +0 -0
- /package/{types/src/helpers → helpers}/contractContextBase.d.ts +0 -0
- /package/{types/src/helpers → helpers}/contractContextBaseShortHandCtor.d.ts +0 -0
- /package/{types/src/helpers → helpers}/contractsContextTSX.d.ts +0 -0
- /package/{types/src/plugins → plugins}/client.d.ts +0 -0
- /package/{types/src/plugins → plugins}/message-builder.d.ts +0 -0
- /package/{types/src/plugins → plugins}/message-composer.d.ts +0 -0
- /package/{types/src/plugins → plugins}/provider-bundle.d.ts +0 -0
- /package/{types/src/plugins → plugins}/react-query.d.ts +0 -0
- /package/{types/src/plugins → plugins}/recoil.d.ts +0 -0
- /package/{types/src/plugins → plugins}/types.d.ts +0 -0
- /package/{types/src/ts-codegen.d.ts → ts-codegen.d.ts} +0 -0
- /package/{types/src/utils → utils}/clean.d.ts +0 -0
- /package/{types/src/utils → utils}/cleanse.d.ts +0 -0
- /package/{types/src/utils → utils}/files.d.ts +0 -0
- /package/{types/src/utils → utils}/header.d.ts +0 -0
- /package/{types/src/utils → utils}/unused.d.ts +0 -0
@@ -1,7 +1,6 @@
|
|
1
|
+
// @ts-nocheck
|
1
2
|
import { prompt } from '../utils/prompt';
|
2
3
|
import codegen from '../index';
|
3
|
-
import { TSBuilderOptions } from '../builder';
|
4
|
-
|
5
4
|
export default async (argv) => {
|
6
5
|
const questions = [
|
7
6
|
{
|
@@ -42,17 +41,16 @@ export default async (argv) => {
|
|
42
41
|
default: true
|
43
42
|
}
|
44
43
|
];
|
45
|
-
|
46
44
|
if (argv.typesOnly) {
|
47
45
|
argv.plugin = 'types';
|
48
46
|
}
|
49
|
-
|
50
47
|
let { schema, out, name, plugin, bundle } = await prompt(questions, argv);
|
51
|
-
if (!Array.isArray(plugin))
|
52
|
-
|
48
|
+
if (!Array.isArray(plugin))
|
49
|
+
plugin = [plugin];
|
53
50
|
///////// REACT QUERY
|
54
51
|
const questions2 = [];
|
55
52
|
if (plugin.includes('react-query')) {
|
53
|
+
// @ts-ignore
|
56
54
|
[].push.apply(questions2, [
|
57
55
|
{
|
58
56
|
type: 'confirm',
|
@@ -73,8 +71,9 @@ export default async (argv) => {
|
|
73
71
|
message: 'queryKeys?',
|
74
72
|
default: false
|
75
73
|
},
|
76
|
-
])
|
77
|
-
}
|
74
|
+
]);
|
75
|
+
}
|
76
|
+
;
|
78
77
|
const { optionalClient, version, queryKeys } = await prompt(questions2, argv);
|
79
78
|
const questions3 = [];
|
80
79
|
if (version === 'v4') {
|
@@ -86,11 +85,10 @@ export default async (argv) => {
|
|
86
85
|
message: 'Generate useMutation hooks?',
|
87
86
|
default: false
|
88
87
|
}
|
89
|
-
|
90
|
-
|
91
|
-
|
88
|
+
]);
|
89
|
+
}
|
90
|
+
;
|
92
91
|
const { mutations } = await prompt(questions3, argv);
|
93
|
-
|
94
92
|
const queryFactoryQuestions = [];
|
95
93
|
if (queryKeys) {
|
96
94
|
[].push.apply(queryFactoryQuestions, [
|
@@ -101,11 +99,11 @@ export default async (argv) => {
|
|
101
99
|
message: 'queryFactory? ',
|
102
100
|
default: false
|
103
101
|
}
|
104
|
-
])
|
105
|
-
}
|
102
|
+
]);
|
103
|
+
}
|
104
|
+
;
|
106
105
|
const { queryFactory } = await prompt(queryFactoryQuestions, argv);
|
107
106
|
///////// END REACT QUERY
|
108
|
-
|
109
107
|
///////// BUNDLE
|
110
108
|
const questions4 = [];
|
111
109
|
if (bundle) {
|
@@ -122,18 +120,17 @@ export default async (argv) => {
|
|
122
120
|
message: 'bundleScope?',
|
123
121
|
default: 'contracts'
|
124
122
|
}
|
125
|
-
])
|
126
|
-
}
|
123
|
+
]);
|
124
|
+
}
|
125
|
+
;
|
127
126
|
const { bundleFile, bundleScope } = await prompt(questions4, argv);
|
128
127
|
///////// END BUNDLE
|
129
|
-
|
130
|
-
const options: TSBuilderOptions = {
|
128
|
+
const options = {
|
131
129
|
types: {
|
132
130
|
enabled: true
|
133
131
|
},
|
134
132
|
client: {
|
135
|
-
enabled:
|
136
|
-
plugin.includes('client') ||
|
133
|
+
enabled: plugin.includes('client') ||
|
137
134
|
plugin.includes('recoil') ||
|
138
135
|
plugin.includes('react-query')
|
139
136
|
},
|
@@ -152,7 +149,6 @@ export default async (argv) => {
|
|
152
149
|
enabled: plugin.includes('message-composer')
|
153
150
|
},
|
154
151
|
messageBuilder: {
|
155
|
-
|
156
152
|
enabled: plugin.includes('message-builder')
|
157
153
|
},
|
158
154
|
bundle: {
|
@@ -161,7 +157,6 @@ export default async (argv) => {
|
|
161
157
|
bundleFile
|
162
158
|
}
|
163
159
|
};
|
164
|
-
|
165
160
|
await codegen({
|
166
161
|
contracts: [
|
167
162
|
{
|
@@ -171,5 +166,5 @@ export default async (argv) => {
|
|
171
166
|
],
|
172
167
|
outPath: out,
|
173
168
|
options
|
174
|
-
})
|
169
|
+
});
|
175
170
|
};
|
@@ -7,42 +7,35 @@ import { prompt } from '../utils/prompt';
|
|
7
7
|
import { parse } from 'parse-package-name';
|
8
8
|
import { tmpdir } from 'os';
|
9
9
|
import { readFileSync, writeFileSync } from 'fs';
|
10
|
-
|
11
10
|
const TMPDIR = tmpdir();
|
12
|
-
const rnd = () =>
|
13
|
-
Math.random().toString(36).substring(2, 15) +
|
11
|
+
const rnd = () => Math.random().toString(36).substring(2, 15) +
|
14
12
|
Math.random().toString(36).substring(2, 15);
|
15
|
-
|
16
13
|
const getPackages = (names) => {
|
17
14
|
return names.map(pkg => {
|
18
15
|
const { name, version } = parse(pkg);
|
19
|
-
return `${name}@${version}
|
16
|
+
return `${name}@${version}`;
|
20
17
|
}).join(' ');
|
21
18
|
};
|
22
|
-
|
23
19
|
export default async (argv) => {
|
24
|
-
|
25
20
|
// don't prompt if we got this...
|
26
21
|
if (argv._.length) {
|
27
22
|
argv.pkg = argv._;
|
28
23
|
}
|
29
|
-
|
30
24
|
// current dir/package
|
31
25
|
const cur = process.cwd();
|
32
26
|
let thisPackage;
|
33
27
|
try {
|
34
28
|
thisPackage = JSON.parse(readFileSync(join(cur, 'package.json'), 'utf-8'));
|
35
|
-
}
|
29
|
+
}
|
30
|
+
catch (e) {
|
36
31
|
throw new Error('make sure you are inside of a telescope package!');
|
37
32
|
}
|
38
|
-
|
39
33
|
// what are we installing?
|
40
34
|
let { pkg } = await prompt([
|
41
35
|
{
|
42
36
|
type: 'checkbox',
|
43
37
|
name: 'pkg',
|
44
|
-
message:
|
45
|
-
'which chain contracts do you want to support?',
|
38
|
+
message: 'which chain contracts do you want to support?',
|
46
39
|
choices: [
|
47
40
|
'stargaze-base-factory',
|
48
41
|
'stargaze-base-minter',
|
@@ -58,39 +51,37 @@ export default async (argv) => {
|
|
58
51
|
return {
|
59
52
|
name,
|
60
53
|
value: `@cosmjson/${name}`
|
61
|
-
}
|
54
|
+
};
|
62
55
|
})
|
63
56
|
}
|
64
57
|
], argv);
|
65
|
-
|
66
58
|
// install
|
67
|
-
if (!Array.isArray(pkg))
|
59
|
+
if (!Array.isArray(pkg))
|
60
|
+
pkg = [pkg];
|
68
61
|
const tmp = join(TMPDIR, rnd());
|
69
62
|
mkdirp(tmp);
|
70
63
|
process.chdir(tmp);
|
71
64
|
exec(`npm install ${getPackages(pkg)} --production --prefix ./smart-contracts`);
|
72
|
-
|
73
65
|
// protos
|
74
66
|
const pkgs = glob('./smart-contracts/**/package.json');
|
75
67
|
const cmds = pkgs
|
76
|
-
.filter((f) => { return f !== './smart-contracts/package.json' })
|
68
|
+
.filter((f) => { return f !== './smart-contracts/package.json'; })
|
77
69
|
.map((f) => resolve(join(tmp, f)))
|
78
70
|
.map((conf) => {
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
});
|
91
|
-
return [extDir, resolve(join(cur, 'contracts', dst)), dir];
|
71
|
+
const extDir = dirname(conf);
|
72
|
+
const dir = extDir.split('node_modules/')[1];
|
73
|
+
const dst = basename(dir);
|
74
|
+
const files = glob(`${extDir}/**/*`, { nodir: true });
|
75
|
+
files.forEach(f => {
|
76
|
+
if (extname(f) === '.json'
|
77
|
+
|| f === 'package.json'
|
78
|
+
|| /license/i.test(f)
|
79
|
+
|| /readme/i.test(f))
|
80
|
+
return;
|
81
|
+
rimraf(f);
|
92
82
|
});
|
93
|
-
|
83
|
+
return [extDir, resolve(join(cur, 'contracts', dst)), dir];
|
84
|
+
});
|
94
85
|
// move protos
|
95
86
|
for (const [src, dst, pkg] of cmds) {
|
96
87
|
rimraf(dst);
|
@@ -98,7 +89,6 @@ export default async (argv) => {
|
|
98
89
|
mkdirp(dirname(dst));
|
99
90
|
exec(`mv ${src} ${dst}`);
|
100
91
|
}
|
101
|
-
|
102
92
|
// package
|
103
93
|
const packageInfo = JSON.parse(readFileSync('./smart-contracts/package.json', 'utf-8'));
|
104
94
|
const deps = packageInfo.dependencies ?? {};
|
@@ -107,11 +97,8 @@ export default async (argv) => {
|
|
107
97
|
...thisPackage.devDependencies,
|
108
98
|
...deps
|
109
99
|
};
|
110
|
-
|
111
100
|
thisPackage.devDependencies = Object.fromEntries(Object.entries(thisPackage.devDependencies).sort());
|
112
|
-
|
113
101
|
writeFileSync(join(cur, 'package.json'), JSON.stringify(thisPackage, null, 2));
|
114
|
-
|
115
102
|
// cleanup
|
116
103
|
rimraf(tmp);
|
117
104
|
process.chdir(cur);
|
package/esm/file.js
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
import { prompt } from './utils/prompt';
|
3
|
+
import { cli } from './cli';
|
4
|
+
import { readFileSync } from 'fs';
|
5
|
+
const argv = require('minimist')(process.argv.slice(2));
|
6
|
+
const question = [
|
7
|
+
{
|
8
|
+
_: true,
|
9
|
+
type: 'string',
|
10
|
+
name: 'file',
|
11
|
+
message: 'file'
|
12
|
+
}
|
13
|
+
];
|
14
|
+
(async () => {
|
15
|
+
const { file } = await prompt(question, argv);
|
16
|
+
const argvv = JSON.parse(readFileSync(file, 'utf-8'));
|
17
|
+
await cli(argvv);
|
18
|
+
})();
|
@@ -0,0 +1,67 @@
|
|
1
|
+
import { pascal } from "case";
|
2
|
+
import { header } from '../utils/header';
|
3
|
+
import { join } from "path";
|
4
|
+
import { sync as mkdirp } from "mkdirp";
|
5
|
+
import * as w from 'wasm-ast-types';
|
6
|
+
import * as t from '@babel/types';
|
7
|
+
import { writeFileSync } from 'fs';
|
8
|
+
import generate from "@babel/generator";
|
9
|
+
import { getMessageProperties } from "wasm-ast-types";
|
10
|
+
import { findAndParseTypes, findExecuteMsg, findQueryMsg } from '../utils';
|
11
|
+
import { RenderContext } from "wasm-ast-types";
|
12
|
+
export default async (name, contractInfo, outPath, tsClientOptions) => {
|
13
|
+
const { schemas } = contractInfo;
|
14
|
+
const context = new RenderContext(contractInfo, {
|
15
|
+
client: tsClientOptions ?? {}
|
16
|
+
});
|
17
|
+
// const options = context.options.client;
|
18
|
+
const localname = pascal(name) + '.client.ts';
|
19
|
+
const TypesFile = pascal(name) + '.types';
|
20
|
+
const QueryMsg = findQueryMsg(schemas);
|
21
|
+
const ExecuteMsg = findExecuteMsg(schemas);
|
22
|
+
const typeHash = await findAndParseTypes(schemas);
|
23
|
+
let Client = null;
|
24
|
+
let Instance = null;
|
25
|
+
let QueryClient = null;
|
26
|
+
let ReadOnlyInstance = null;
|
27
|
+
const body = [];
|
28
|
+
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
29
|
+
// query messages
|
30
|
+
if (QueryMsg) {
|
31
|
+
QueryClient = pascal(`${name}QueryClient`);
|
32
|
+
ReadOnlyInstance = pascal(`${name}ReadOnlyInterface`);
|
33
|
+
body.push(w.createQueryInterface(context, ReadOnlyInstance, QueryMsg));
|
34
|
+
body.push(w.createQueryClass(context, QueryClient, ReadOnlyInstance, QueryMsg));
|
35
|
+
}
|
36
|
+
// execute messages
|
37
|
+
if (ExecuteMsg) {
|
38
|
+
const children = getMessageProperties(ExecuteMsg);
|
39
|
+
if (children.length > 0) {
|
40
|
+
Client = pascal(`${name}Client`);
|
41
|
+
Instance = pascal(`${name}Interface`);
|
42
|
+
body.push(w.createExecuteInterface(context, Instance, context.options.client.execExtendsQuery ? ReadOnlyInstance : null, ExecuteMsg));
|
43
|
+
body.push(w.createExecuteClass(context, Client, Instance, context.options.client.execExtendsQuery ? QueryClient : null, ExecuteMsg));
|
44
|
+
}
|
45
|
+
}
|
46
|
+
if (typeHash.hasOwnProperty('Coin')) {
|
47
|
+
// @ts-ignore
|
48
|
+
delete context.utils.Coin;
|
49
|
+
}
|
50
|
+
const imports = context.getImports();
|
51
|
+
const code = header + generate(
|
52
|
+
// @ts-ignore
|
53
|
+
t.program([
|
54
|
+
...imports,
|
55
|
+
...body
|
56
|
+
])).code;
|
57
|
+
mkdirp(outPath);
|
58
|
+
writeFileSync(join(outPath, localname), code);
|
59
|
+
return [
|
60
|
+
{
|
61
|
+
type: 'client',
|
62
|
+
contract: name,
|
63
|
+
localname,
|
64
|
+
filename: join(outPath, localname),
|
65
|
+
}
|
66
|
+
];
|
67
|
+
};
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import { join, dirname, basename, extname } from "path";
|
2
|
+
import { sync as mkdirp } from "mkdirp";
|
3
|
+
import pkg from "../../package.json";
|
4
|
+
import { writeContentToFile } from "../utils/files";
|
5
|
+
import { contractContextBase, contractContextBaseShortHandCtor, contractsContextTSX, } from "../helpers";
|
6
|
+
const version = process.env.NODE_ENV === "test" ? "latest" : pkg.version;
|
7
|
+
const header = `/**
|
8
|
+
* This file and any referenced files were automatically generated by ${pkg.name}@${version}
|
9
|
+
* DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain
|
10
|
+
* and run the transpile command or yarn proto command to regenerate this bundle.
|
11
|
+
*/
|
12
|
+
\n`;
|
13
|
+
const write = (outPath, file, content, varname) => {
|
14
|
+
const outFile = join(outPath, file);
|
15
|
+
mkdirp(dirname(outFile));
|
16
|
+
writeContentToFile(outPath, header + content, outFile);
|
17
|
+
return {
|
18
|
+
type: "plugin",
|
19
|
+
pluginType: "helper",
|
20
|
+
contract: varname ?? basename(file, extname(file)),
|
21
|
+
localname: file,
|
22
|
+
filename: outFile,
|
23
|
+
};
|
24
|
+
};
|
25
|
+
export const createHelpers = (input, builderContext) => {
|
26
|
+
const files = [];
|
27
|
+
if (input.options?.useContractsHooks?.enabled &&
|
28
|
+
Object.keys(builderContext.providers)?.length) {
|
29
|
+
const useShorthandCtor = input.options?.useShorthandCtor;
|
30
|
+
files.push(write(input.outPath, "contractContextBase.ts", useShorthandCtor
|
31
|
+
? contractContextBaseShortHandCtor
|
32
|
+
: contractContextBase));
|
33
|
+
files.push(write(input.outPath, "contracts-context.tsx", contractsContextTSX, "contractsContext"));
|
34
|
+
}
|
35
|
+
return files;
|
36
|
+
};
|
@@ -0,0 +1,58 @@
|
|
1
|
+
import { pascal } from "case";
|
2
|
+
import { header } from "../utils/header";
|
3
|
+
import { join } from "path";
|
4
|
+
import { sync as mkdirp } from "mkdirp";
|
5
|
+
import * as w from "wasm-ast-types";
|
6
|
+
import * as t from "@babel/types";
|
7
|
+
import { writeFileSync } from "fs";
|
8
|
+
import generate from "@babel/generator";
|
9
|
+
import { getMessageProperties } from "wasm-ast-types";
|
10
|
+
import { findAndParseTypes, findExecuteMsg, findQueryMsg } from '../utils';
|
11
|
+
import { RenderContext } from 'wasm-ast-types';
|
12
|
+
export default async (name, contractInfo, outPath, messageBuilderOptions) => {
|
13
|
+
const { schemas } = contractInfo;
|
14
|
+
const context = new RenderContext(contractInfo, {
|
15
|
+
messageBuilder: messageBuilderOptions ?? {},
|
16
|
+
});
|
17
|
+
const localname = pascal(name) + ".message-builder.ts";
|
18
|
+
const TypesFile = pascal(name) + ".types";
|
19
|
+
const ExecuteMsg = findExecuteMsg(schemas);
|
20
|
+
const typeHash = await findAndParseTypes(schemas);
|
21
|
+
const body = [];
|
22
|
+
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
23
|
+
body.push(w.importStmt(["CamelCasedProperties"], "type-fest"));
|
24
|
+
// execute messages
|
25
|
+
if (ExecuteMsg) {
|
26
|
+
const children = getMessageProperties(ExecuteMsg);
|
27
|
+
if (children.length > 0) {
|
28
|
+
const className = pascal(`${name}ExecuteMsgBuilder`);
|
29
|
+
body.push(w.createMessageBuilderClass(context, className, ExecuteMsg));
|
30
|
+
}
|
31
|
+
}
|
32
|
+
const QueryMsg = findQueryMsg(schemas);
|
33
|
+
// query messages
|
34
|
+
if (QueryMsg) {
|
35
|
+
const children = getMessageProperties(QueryMsg);
|
36
|
+
if (children.length > 0) {
|
37
|
+
const className = pascal(`${name}QueryMsgBuilder`);
|
38
|
+
body.push(w.createMessageBuilderClass(context, className, QueryMsg));
|
39
|
+
}
|
40
|
+
}
|
41
|
+
if (typeHash.hasOwnProperty("Coin")) {
|
42
|
+
// @ts-ignore
|
43
|
+
delete context.utils.Coin;
|
44
|
+
}
|
45
|
+
const imports = context.getImports();
|
46
|
+
// @ts-ignore
|
47
|
+
const code = header + generate(t.program([...imports, ...body])).code;
|
48
|
+
mkdirp(outPath);
|
49
|
+
writeFileSync(join(outPath, localname), code);
|
50
|
+
return [
|
51
|
+
{
|
52
|
+
type: "message-builder",
|
53
|
+
contract: name,
|
54
|
+
localname,
|
55
|
+
filename: join(outPath, localname),
|
56
|
+
},
|
57
|
+
];
|
58
|
+
};
|
@@ -0,0 +1,55 @@
|
|
1
|
+
import { pascal } from "case";
|
2
|
+
import { header } from '../utils/header';
|
3
|
+
import { join } from "path";
|
4
|
+
import { sync as mkdirp } from "mkdirp";
|
5
|
+
import * as w from 'wasm-ast-types';
|
6
|
+
import * as t from '@babel/types';
|
7
|
+
import { writeFileSync } from 'fs';
|
8
|
+
import generate from "@babel/generator";
|
9
|
+
import { getMessageProperties } from "wasm-ast-types";
|
10
|
+
import { findAndParseTypes, findExecuteMsg } from "../utils";
|
11
|
+
import { RenderContext } from "wasm-ast-types";
|
12
|
+
export default async (name, contractInfo, outPath, messageComposerOptions) => {
|
13
|
+
const { schemas } = contractInfo;
|
14
|
+
const context = new RenderContext(contractInfo, {
|
15
|
+
messageComposer: messageComposerOptions ?? {}
|
16
|
+
});
|
17
|
+
// const options = context.options.messageComposer;
|
18
|
+
const localname = pascal(name) + '.message-composer.ts';
|
19
|
+
const TypesFile = pascal(name) + '.types';
|
20
|
+
const ExecuteMsg = findExecuteMsg(schemas);
|
21
|
+
const typeHash = await findAndParseTypes(schemas);
|
22
|
+
const body = [];
|
23
|
+
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
24
|
+
// execute messages
|
25
|
+
if (ExecuteMsg) {
|
26
|
+
const children = getMessageProperties(ExecuteMsg);
|
27
|
+
if (children.length > 0) {
|
28
|
+
const TheClass = pascal(`${name}MessageComposer`);
|
29
|
+
const Interface = pascal(`${name}Message`);
|
30
|
+
body.push(w.createMessageComposerInterface(context, Interface, ExecuteMsg));
|
31
|
+
body.push(w.createMessageComposerClass(context, TheClass, Interface, ExecuteMsg));
|
32
|
+
}
|
33
|
+
}
|
34
|
+
if (typeHash.hasOwnProperty('Coin')) {
|
35
|
+
// @ts-ignore
|
36
|
+
delete context.utils.Coin;
|
37
|
+
}
|
38
|
+
const imports = context.getImports();
|
39
|
+
const code = header + generate(
|
40
|
+
// @ts-ignore
|
41
|
+
t.program([
|
42
|
+
...imports,
|
43
|
+
...body
|
44
|
+
])).code;
|
45
|
+
mkdirp(outPath);
|
46
|
+
writeFileSync(join(outPath, localname), code);
|
47
|
+
return [
|
48
|
+
{
|
49
|
+
type: 'message-composer',
|
50
|
+
contract: name,
|
51
|
+
localname,
|
52
|
+
filename: join(outPath, localname),
|
53
|
+
}
|
54
|
+
];
|
55
|
+
};
|
@@ -0,0 +1,76 @@
|
|
1
|
+
import { pascal } from "case";
|
2
|
+
import { header } from '../utils/header';
|
3
|
+
import { join } from "path";
|
4
|
+
import { sync as mkdirp } from "mkdirp";
|
5
|
+
import * as w from 'wasm-ast-types';
|
6
|
+
import { RenderContext } from 'wasm-ast-types';
|
7
|
+
import * as t from '@babel/types';
|
8
|
+
import { writeFileSync } from 'fs';
|
9
|
+
import generate from "@babel/generator";
|
10
|
+
import { findAndParseTypes, findExecuteMsg, findQueryMsg } from '../utils';
|
11
|
+
import { getMessageProperties } from "wasm-ast-types";
|
12
|
+
export default async (contractName, contractInfo, outPath, reactQueryOptions) => {
|
13
|
+
const { schemas } = contractInfo;
|
14
|
+
const context = new RenderContext(contractInfo, {
|
15
|
+
reactQuery: reactQueryOptions ?? {}
|
16
|
+
});
|
17
|
+
const options = context.options.reactQuery;
|
18
|
+
const localname = pascal(`${contractName}`) + '.react-query.ts';
|
19
|
+
const ContractFile = pascal(`${contractName}`) + '.client';
|
20
|
+
const TypesFile = pascal(`${contractName}`) + '.types';
|
21
|
+
const QueryMsg = findQueryMsg(schemas);
|
22
|
+
const ExecuteMsg = findExecuteMsg(schemas);
|
23
|
+
const typeHash = await findAndParseTypes(schemas);
|
24
|
+
const ExecuteClient = pascal(`${contractName}Client`);
|
25
|
+
const QueryClient = pascal(`${contractName}QueryClient`);
|
26
|
+
const body = [];
|
27
|
+
const clientImports = [];
|
28
|
+
QueryMsg && clientImports.push(QueryClient);
|
29
|
+
// check that there are commands within the exec msg
|
30
|
+
const shouldGenerateMutationHooks = ExecuteMsg && options?.version === 'v4' && options?.mutations && getMessageProperties(ExecuteMsg).length > 0;
|
31
|
+
if (shouldGenerateMutationHooks) {
|
32
|
+
clientImports.push(ExecuteClient);
|
33
|
+
}
|
34
|
+
// general contract imports
|
35
|
+
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
36
|
+
// client imports
|
37
|
+
body.push(w.importStmt(clientImports, `./${ContractFile}`));
|
38
|
+
// query messages
|
39
|
+
if (QueryMsg) {
|
40
|
+
[].push.apply(body, w.createReactQueryHooks({
|
41
|
+
context,
|
42
|
+
queryMsg: QueryMsg,
|
43
|
+
contractName: contractName,
|
44
|
+
QueryClient
|
45
|
+
}));
|
46
|
+
}
|
47
|
+
if (shouldGenerateMutationHooks) {
|
48
|
+
[].push.apply(body, w.createReactQueryMutationHooks({
|
49
|
+
context,
|
50
|
+
execMsg: ExecuteMsg,
|
51
|
+
contractName: contractName,
|
52
|
+
ExecuteClient
|
53
|
+
}));
|
54
|
+
}
|
55
|
+
if (typeHash.hasOwnProperty('Coin')) {
|
56
|
+
// @ts-ignore
|
57
|
+
delete context.utils.Coin;
|
58
|
+
}
|
59
|
+
const imports = context.getImports();
|
60
|
+
const code = header + generate(
|
61
|
+
// @ts-ignore
|
62
|
+
t.program([
|
63
|
+
...imports,
|
64
|
+
...body
|
65
|
+
])).code;
|
66
|
+
mkdirp(outPath);
|
67
|
+
writeFileSync(join(outPath, localname), code);
|
68
|
+
return [
|
69
|
+
{
|
70
|
+
type: 'react-query',
|
71
|
+
contract: contractName,
|
72
|
+
localname,
|
73
|
+
filename: join(outPath, localname),
|
74
|
+
}
|
75
|
+
];
|
76
|
+
};
|
@@ -0,0 +1,58 @@
|
|
1
|
+
import { pascal } from "case";
|
2
|
+
import { header } from '../utils/header';
|
3
|
+
import { join } from "path";
|
4
|
+
import { sync as mkdirp } from "mkdirp";
|
5
|
+
import * as w from 'wasm-ast-types';
|
6
|
+
import * as t from '@babel/types';
|
7
|
+
import { writeFileSync } from 'fs';
|
8
|
+
import generate from "@babel/generator";
|
9
|
+
import { findAndParseTypes, findQueryMsg } from "../utils";
|
10
|
+
import { RenderContext } from "wasm-ast-types";
|
11
|
+
export default async (name, contractInfo, outPath, recoilOptions) => {
|
12
|
+
const { schemas } = contractInfo;
|
13
|
+
const context = new RenderContext(contractInfo, {
|
14
|
+
recoil: recoilOptions ?? {}
|
15
|
+
});
|
16
|
+
const options = context.options.recoil;
|
17
|
+
const localname = pascal(name) + '.recoil.ts';
|
18
|
+
const ContractFile = pascal(name) + '.client';
|
19
|
+
const TypesFile = pascal(name) + '.types';
|
20
|
+
const QueryMsg = findQueryMsg(schemas);
|
21
|
+
const typeHash = await findAndParseTypes(schemas);
|
22
|
+
let QueryClient = null;
|
23
|
+
let ReadOnlyInstance = null;
|
24
|
+
const body = [];
|
25
|
+
body.push(w.importStmt(['cosmWasmClient'], './chain'));
|
26
|
+
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
27
|
+
// query messages
|
28
|
+
if (QueryMsg) {
|
29
|
+
QueryClient = pascal(`${name}QueryClient`);
|
30
|
+
ReadOnlyInstance = pascal(`${name}ReadOnlyInterface`);
|
31
|
+
body.push(w.importStmt([QueryClient], `./${ContractFile}`));
|
32
|
+
body.push(w.createRecoilQueryClientType());
|
33
|
+
body.push(w.createRecoilQueryClient(context, name, QueryClient));
|
34
|
+
const selectors = w.createRecoilSelectors(context, name, QueryClient, QueryMsg);
|
35
|
+
body.push(...selectors);
|
36
|
+
}
|
37
|
+
if (typeHash.hasOwnProperty('Coin')) {
|
38
|
+
// @ts-ignore
|
39
|
+
delete context.utils.Coin;
|
40
|
+
}
|
41
|
+
const imports = context.getImports();
|
42
|
+
const code = header + generate(
|
43
|
+
// @ts-ignore
|
44
|
+
t.program([
|
45
|
+
...imports,
|
46
|
+
...body
|
47
|
+
])).code;
|
48
|
+
mkdirp(outPath);
|
49
|
+
writeFileSync(join(outPath, localname), code);
|
50
|
+
return [
|
51
|
+
{
|
52
|
+
type: 'recoil',
|
53
|
+
contract: name,
|
54
|
+
localname,
|
55
|
+
filename: join(outPath, localname),
|
56
|
+
}
|
57
|
+
];
|
58
|
+
};
|
@@ -0,0 +1,58 @@
|
|
1
|
+
import { pascal } from "case";
|
2
|
+
import { header } from '../utils/header';
|
3
|
+
import { join } from "path";
|
4
|
+
import { sync as mkdirp } from "mkdirp";
|
5
|
+
import * as t from '@babel/types';
|
6
|
+
import { writeFileSync } from 'fs';
|
7
|
+
import generate from "@babel/generator";
|
8
|
+
import { clean } from "../utils/clean";
|
9
|
+
import { findAndParseTypes, findExecuteMsg, findQueryMsg } from '../utils';
|
10
|
+
import { RenderContext } from "wasm-ast-types";
|
11
|
+
export default async (name, contractInfo, outPath, tsTypesOptions) => {
|
12
|
+
const { schemas } = contractInfo;
|
13
|
+
const context = new RenderContext(contractInfo, {
|
14
|
+
types: tsTypesOptions ?? {}
|
15
|
+
});
|
16
|
+
const options = context.options.types;
|
17
|
+
const localname = pascal(name) + '.types.ts';
|
18
|
+
const ExecuteMsg = findExecuteMsg(schemas);
|
19
|
+
const typeHash = await findAndParseTypes(schemas);
|
20
|
+
const body = [];
|
21
|
+
// TYPES
|
22
|
+
Object.values(typeHash).forEach((type) => {
|
23
|
+
body.push(clean(type));
|
24
|
+
});
|
25
|
+
// alias the ExecuteMsg (deprecated option)
|
26
|
+
if (options.aliasExecuteMsg && ExecuteMsg) {
|
27
|
+
body.push(t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(`${name}ExecuteMsg`), null, t.tsTypeReference(t.identifier('ExecuteMsg')))));
|
28
|
+
}
|
29
|
+
function addEntryPointAlias(msgName) {
|
30
|
+
body.push(t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(`${name}${msgName}`), null, t.tsTypeReference(t.identifier(msgName)))));
|
31
|
+
}
|
32
|
+
if (options.aliasEntryPoints) {
|
33
|
+
if (ExecuteMsg) {
|
34
|
+
addEntryPointAlias('ExecuteMsg');
|
35
|
+
}
|
36
|
+
if (findQueryMsg(schemas)) {
|
37
|
+
addEntryPointAlias('QueryMsg');
|
38
|
+
}
|
39
|
+
}
|
40
|
+
const imports = context.getImports();
|
41
|
+
const code = header + generate(
|
42
|
+
// @ts-ignore
|
43
|
+
t.program([
|
44
|
+
...imports,
|
45
|
+
...body
|
46
|
+
])).code;
|
47
|
+
mkdirp(outPath);
|
48
|
+
const filename = join(outPath, localname);
|
49
|
+
writeFileSync(filename, code);
|
50
|
+
return [
|
51
|
+
{
|
52
|
+
type: 'type',
|
53
|
+
contract: name,
|
54
|
+
localname,
|
55
|
+
filename,
|
56
|
+
}
|
57
|
+
];
|
58
|
+
};
|