@cosmwasm/ts-codegen 0.35.7 → 1.0.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 +2 -2
- 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-composer.js +55 -0
- package/esm/generators/msg-builder.js +58 -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} +3 -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-composer.js +83 -0
- package/generators/msg-builder.js +86 -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/index.js +39 -0
- package/package.json +27 -51
- 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 → generators}/message-composer.d.ts +0 -0
- /package/{types/src/generators → generators}/msg-builder.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/index.d.ts → index.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,78 +0,0 @@
|
|
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 { ContractInfo, getMessageProperties } from "wasm-ast-types";
|
10
|
-
import { findAndParseTypes, findExecuteMsg, findQueryMsg } from '../utils';
|
11
|
-
import { RenderContext, MessageBuilderOptions } from 'wasm-ast-types';
|
12
|
-
import { BuilderFile } from "../builder";
|
13
|
-
|
14
|
-
export default async (
|
15
|
-
name: string,
|
16
|
-
contractInfo: ContractInfo,
|
17
|
-
outPath: string,
|
18
|
-
messageBuilderOptions?: MessageBuilderOptions
|
19
|
-
): Promise<BuilderFile[]> => {
|
20
|
-
const { schemas } = contractInfo;
|
21
|
-
const context = new RenderContext(contractInfo, {
|
22
|
-
messageBuilder: messageBuilderOptions ?? {},
|
23
|
-
});
|
24
|
-
|
25
|
-
const localname = pascal(name) + ".message-builder.ts";
|
26
|
-
const TypesFile = pascal(name) + ".types";
|
27
|
-
const ExecuteMsg = findExecuteMsg(schemas);
|
28
|
-
const typeHash = await findAndParseTypes(schemas);
|
29
|
-
|
30
|
-
const body = [];
|
31
|
-
|
32
|
-
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
33
|
-
body.push(w.importStmt(["CamelCasedProperties"], "type-fest"));
|
34
|
-
|
35
|
-
// execute messages
|
36
|
-
if (ExecuteMsg) {
|
37
|
-
const children = getMessageProperties(ExecuteMsg);
|
38
|
-
if (children.length > 0) {
|
39
|
-
const className = pascal(`${name}ExecuteMsgBuilder`);
|
40
|
-
|
41
|
-
body.push(
|
42
|
-
w.createMessageBuilderClass(context, className, ExecuteMsg)
|
43
|
-
);
|
44
|
-
}
|
45
|
-
}
|
46
|
-
|
47
|
-
const QueryMsg = findQueryMsg(schemas);
|
48
|
-
// query messages
|
49
|
-
if (QueryMsg) {
|
50
|
-
const children = getMessageProperties(QueryMsg);
|
51
|
-
if (children.length > 0) {
|
52
|
-
const className = pascal(`${name}QueryMsgBuilder`);
|
53
|
-
|
54
|
-
body.push(
|
55
|
-
w.createMessageBuilderClass(context, className, QueryMsg)
|
56
|
-
);
|
57
|
-
}
|
58
|
-
}
|
59
|
-
|
60
|
-
if (typeHash.hasOwnProperty("Coin")) {
|
61
|
-
// @ts-ignore
|
62
|
-
delete context.utils.Coin;
|
63
|
-
}
|
64
|
-
const imports = context.getImports();
|
65
|
-
const code = header + generate(t.program([...imports, ...body])).code;
|
66
|
-
|
67
|
-
mkdirp(outPath);
|
68
|
-
writeFileSync(join(outPath, localname), code);
|
69
|
-
|
70
|
-
return [
|
71
|
-
{
|
72
|
-
type: "message-builder",
|
73
|
-
contract: name,
|
74
|
-
localname,
|
75
|
-
filename: join(outPath, localname),
|
76
|
-
},
|
77
|
-
];
|
78
|
-
};
|
@@ -1,102 +0,0 @@
|
|
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, ReactQueryOptions, ContractInfo } from "wasm-ast-types";
|
12
|
-
import { BuilderFile } from "../builder";
|
13
|
-
|
14
|
-
export default async (
|
15
|
-
contractName: string,
|
16
|
-
contractInfo: ContractInfo,
|
17
|
-
outPath: string,
|
18
|
-
reactQueryOptions?: ReactQueryOptions
|
19
|
-
): Promise<BuilderFile[]> => {
|
20
|
-
const { schemas } = contractInfo;
|
21
|
-
const context = new RenderContext(contractInfo, {
|
22
|
-
reactQuery: reactQueryOptions ?? {}
|
23
|
-
});
|
24
|
-
const options = context.options.reactQuery;
|
25
|
-
|
26
|
-
const localname = pascal(`${contractName}`) + '.react-query.ts';
|
27
|
-
const ContractFile = pascal(`${contractName}`) + '.client';
|
28
|
-
const TypesFile = pascal(`${contractName}`) + '.types';
|
29
|
-
|
30
|
-
const QueryMsg = findQueryMsg(schemas);
|
31
|
-
const ExecuteMsg = findExecuteMsg(schemas);
|
32
|
-
const typeHash = await findAndParseTypes(schemas);
|
33
|
-
|
34
|
-
const ExecuteClient = pascal(`${contractName}Client`);
|
35
|
-
const QueryClient = pascal(`${contractName}QueryClient`);
|
36
|
-
|
37
|
-
const body = [];
|
38
|
-
|
39
|
-
const clientImports = []
|
40
|
-
|
41
|
-
QueryMsg && clientImports.push(QueryClient)
|
42
|
-
|
43
|
-
// check that there are commands within the exec msg
|
44
|
-
const shouldGenerateMutationHooks = ExecuteMsg && options?.version === 'v4' && options?.mutations && getMessageProperties(ExecuteMsg).length > 0
|
45
|
-
|
46
|
-
if (shouldGenerateMutationHooks) {
|
47
|
-
clientImports.push(ExecuteClient)
|
48
|
-
}
|
49
|
-
|
50
|
-
// general contract imports
|
51
|
-
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
52
|
-
|
53
|
-
// client imports
|
54
|
-
body.push(w.importStmt(clientImports, `./${ContractFile}`));
|
55
|
-
|
56
|
-
// query messages
|
57
|
-
if (QueryMsg) {
|
58
|
-
[].push.apply(body,
|
59
|
-
w.createReactQueryHooks({
|
60
|
-
context,
|
61
|
-
queryMsg: QueryMsg,
|
62
|
-
contractName: contractName,
|
63
|
-
QueryClient
|
64
|
-
})
|
65
|
-
);
|
66
|
-
}
|
67
|
-
|
68
|
-
if (shouldGenerateMutationHooks) {
|
69
|
-
[].push.apply(body,
|
70
|
-
w.createReactQueryMutationHooks({
|
71
|
-
context,
|
72
|
-
execMsg: ExecuteMsg,
|
73
|
-
contractName: contractName,
|
74
|
-
ExecuteClient
|
75
|
-
})
|
76
|
-
);
|
77
|
-
}
|
78
|
-
|
79
|
-
if (typeHash.hasOwnProperty('Coin')) {
|
80
|
-
// @ts-ignore
|
81
|
-
delete context.utils.Coin;
|
82
|
-
}
|
83
|
-
const imports = context.getImports();
|
84
|
-
const code = header + generate(
|
85
|
-
t.program([
|
86
|
-
...imports,
|
87
|
-
...body
|
88
|
-
])
|
89
|
-
).code;
|
90
|
-
|
91
|
-
mkdirp(outPath);
|
92
|
-
writeFileSync(join(outPath, localname), code);
|
93
|
-
|
94
|
-
return [
|
95
|
-
{
|
96
|
-
type: 'react-query',
|
97
|
-
contract: contractName,
|
98
|
-
localname,
|
99
|
-
filename: join(outPath, localname),
|
100
|
-
}
|
101
|
-
]
|
102
|
-
};
|
package/src/generators/recoil.ts
DELETED
@@ -1,92 +0,0 @@
|
|
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 { ContractInfo, RenderContext, RecoilOptions } from "wasm-ast-types";
|
11
|
-
import { BuilderFile } from "../builder";
|
12
|
-
|
13
|
-
export default async (
|
14
|
-
name: string,
|
15
|
-
contractInfo: ContractInfo,
|
16
|
-
outPath: string,
|
17
|
-
recoilOptions?: RecoilOptions
|
18
|
-
): Promise<BuilderFile[]> => {
|
19
|
-
|
20
|
-
const { schemas } = contractInfo;
|
21
|
-
const context = new RenderContext(contractInfo, {
|
22
|
-
recoil: recoilOptions ?? {}
|
23
|
-
});
|
24
|
-
const options = context.options.recoil;
|
25
|
-
|
26
|
-
const localname = pascal(name) + '.recoil.ts';
|
27
|
-
const ContractFile = pascal(name) + '.client';
|
28
|
-
const TypesFile = pascal(name) + '.types';
|
29
|
-
|
30
|
-
const QueryMsg = findQueryMsg(schemas);
|
31
|
-
const typeHash = await findAndParseTypes(schemas);
|
32
|
-
|
33
|
-
let QueryClient = null;
|
34
|
-
let ReadOnlyInstance = null;
|
35
|
-
|
36
|
-
const body = [];
|
37
|
-
|
38
|
-
body.push(
|
39
|
-
w.importStmt(['cosmWasmClient'], './chain')
|
40
|
-
);
|
41
|
-
|
42
|
-
body.push(
|
43
|
-
w.importStmt(Object.keys(typeHash), `./${TypesFile}`)
|
44
|
-
);
|
45
|
-
|
46
|
-
// query messages
|
47
|
-
if (QueryMsg) {
|
48
|
-
|
49
|
-
QueryClient = pascal(`${name}QueryClient`);
|
50
|
-
ReadOnlyInstance = pascal(`${name}ReadOnlyInterface`);
|
51
|
-
|
52
|
-
body.push(
|
53
|
-
w.importStmt([QueryClient], `./${ContractFile}`)
|
54
|
-
);
|
55
|
-
|
56
|
-
body.push(w.createRecoilQueryClientType());
|
57
|
-
body.push(w.createRecoilQueryClient(
|
58
|
-
context,
|
59
|
-
name,
|
60
|
-
QueryClient
|
61
|
-
));
|
62
|
-
|
63
|
-
[].push.apply(body,
|
64
|
-
w.createRecoilSelectors(context, name, QueryClient, QueryMsg)
|
65
|
-
);
|
66
|
-
|
67
|
-
}
|
68
|
-
|
69
|
-
if (typeHash.hasOwnProperty('Coin')) {
|
70
|
-
// @ts-ignore
|
71
|
-
delete context.utils.Coin;
|
72
|
-
}
|
73
|
-
const imports = context.getImports();
|
74
|
-
const code = header + generate(
|
75
|
-
t.program([
|
76
|
-
...imports,
|
77
|
-
...body
|
78
|
-
])
|
79
|
-
).code;
|
80
|
-
|
81
|
-
mkdirp(outPath);
|
82
|
-
writeFileSync(join(outPath, localname), code);
|
83
|
-
|
84
|
-
return [
|
85
|
-
{
|
86
|
-
type: 'recoil',
|
87
|
-
contract: name,
|
88
|
-
localname,
|
89
|
-
filename: join(outPath, localname),
|
90
|
-
}
|
91
|
-
]
|
92
|
-
};
|
package/src/generators/types.ts
DELETED
@@ -1,94 +0,0 @@
|
|
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 { ContractInfo, RenderContext, TSTypesOptions } from "wasm-ast-types";
|
11
|
-
import { BuilderFile } from "../builder";
|
12
|
-
|
13
|
-
export default async (
|
14
|
-
name: string,
|
15
|
-
contractInfo: ContractInfo,
|
16
|
-
outPath: string,
|
17
|
-
tsTypesOptions?: TSTypesOptions
|
18
|
-
): Promise<BuilderFile[]> => {
|
19
|
-
|
20
|
-
const { schemas } = contractInfo;
|
21
|
-
const context = new RenderContext(contractInfo, {
|
22
|
-
types: tsTypesOptions ?? {}
|
23
|
-
});
|
24
|
-
const options = context.options.types;
|
25
|
-
|
26
|
-
const localname = pascal(name) + '.types.ts';
|
27
|
-
const ExecuteMsg = findExecuteMsg(schemas);
|
28
|
-
const typeHash = await findAndParseTypes(schemas);
|
29
|
-
|
30
|
-
const body = [];
|
31
|
-
|
32
|
-
// TYPES
|
33
|
-
Object.values(typeHash).forEach((type: t.Node) => {
|
34
|
-
body.push(
|
35
|
-
clean(type)
|
36
|
-
)
|
37
|
-
});
|
38
|
-
|
39
|
-
// alias the ExecuteMsg (deprecated option)
|
40
|
-
if (options.aliasExecuteMsg && ExecuteMsg) {
|
41
|
-
body.push(
|
42
|
-
t.exportNamedDeclaration(
|
43
|
-
t.tsTypeAliasDeclaration(
|
44
|
-
t.identifier(`${name}ExecuteMsg`),
|
45
|
-
null,
|
46
|
-
t.tsTypeReference(t.identifier('ExecuteMsg'))
|
47
|
-
)
|
48
|
-
)
|
49
|
-
);
|
50
|
-
}
|
51
|
-
|
52
|
-
function addEntryPointAlias(msgName: string) {
|
53
|
-
body.push(
|
54
|
-
t.exportNamedDeclaration(
|
55
|
-
t.tsTypeAliasDeclaration(
|
56
|
-
t.identifier(`${name}${msgName}`),
|
57
|
-
null,
|
58
|
-
t.tsTypeReference(t.identifier(msgName))
|
59
|
-
)
|
60
|
-
)
|
61
|
-
);
|
62
|
-
}
|
63
|
-
|
64
|
-
if (options.aliasEntryPoints) {
|
65
|
-
if (ExecuteMsg) {
|
66
|
-
addEntryPointAlias('ExecuteMsg');
|
67
|
-
}
|
68
|
-
if (findQueryMsg(schemas)) {
|
69
|
-
addEntryPointAlias('QueryMsg');
|
70
|
-
}
|
71
|
-
}
|
72
|
-
|
73
|
-
|
74
|
-
const imports = context.getImports();
|
75
|
-
const code = header + generate(
|
76
|
-
t.program([
|
77
|
-
...imports,
|
78
|
-
...body
|
79
|
-
])
|
80
|
-
).code;
|
81
|
-
|
82
|
-
mkdirp(outPath);
|
83
|
-
const filename = join(outPath, localname);
|
84
|
-
writeFileSync(filename, code);
|
85
|
-
|
86
|
-
return [
|
87
|
-
{
|
88
|
-
type: 'type',
|
89
|
-
contract: name,
|
90
|
-
localname,
|
91
|
-
filename,
|
92
|
-
}
|
93
|
-
]
|
94
|
-
};
|
package/src/helpers/index.ts
DELETED
package/src/plugins/client.ts
DELETED
@@ -1,124 +0,0 @@
|
|
1
|
-
import { pascal } from "case";
|
2
|
-
import * as w from "wasm-ast-types";
|
3
|
-
import { findExecuteMsg, findAndParseTypes, findQueryMsg } from "../utils";
|
4
|
-
import {
|
5
|
-
RenderContext,
|
6
|
-
ContractInfo,
|
7
|
-
RenderContextBase,
|
8
|
-
getMessageProperties,
|
9
|
-
RenderOptions,
|
10
|
-
} from "wasm-ast-types";
|
11
|
-
import { BuilderFileType } from "../builder";
|
12
|
-
import { BuilderPluginBase } from "./plugin-base";
|
13
|
-
|
14
|
-
export const TYPE = "client";
|
15
|
-
|
16
|
-
export class ClientPlugin extends BuilderPluginBase<RenderOptions> {
|
17
|
-
initContext(
|
18
|
-
contract: ContractInfo,
|
19
|
-
options?: RenderOptions
|
20
|
-
): RenderContextBase<RenderOptions> {
|
21
|
-
return new RenderContext(contract, options, this.builder.builderContext);
|
22
|
-
}
|
23
|
-
|
24
|
-
async doRender(
|
25
|
-
name: string,
|
26
|
-
context: RenderContext
|
27
|
-
): Promise<
|
28
|
-
{
|
29
|
-
type: BuilderFileType;
|
30
|
-
pluginType?: string;
|
31
|
-
localname: string;
|
32
|
-
body: any[];
|
33
|
-
}[]
|
34
|
-
> {
|
35
|
-
const { enabled } = this.option.client;
|
36
|
-
|
37
|
-
if (!enabled) {
|
38
|
-
return;
|
39
|
-
}
|
40
|
-
|
41
|
-
const { schemas } = context.contract;
|
42
|
-
|
43
|
-
const localname = pascal(name) + ".client.ts";
|
44
|
-
const TypesFile = pascal(name) + ".types";
|
45
|
-
const QueryMsg = findQueryMsg(schemas);
|
46
|
-
const ExecuteMsg = findExecuteMsg(schemas);
|
47
|
-
const typeHash = await findAndParseTypes(schemas);
|
48
|
-
|
49
|
-
let Client = null;
|
50
|
-
let Instance = null;
|
51
|
-
let QueryClient = null;
|
52
|
-
let ReadOnlyInstance = null;
|
53
|
-
|
54
|
-
const body = [];
|
55
|
-
|
56
|
-
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
57
|
-
|
58
|
-
// query messages
|
59
|
-
if (QueryMsg) {
|
60
|
-
QueryClient = pascal(`${name}QueryClient`);
|
61
|
-
ReadOnlyInstance = pascal(`${name}ReadOnlyInterface`);
|
62
|
-
|
63
|
-
body.push(w.createQueryInterface(context, ReadOnlyInstance, QueryMsg));
|
64
|
-
body.push(
|
65
|
-
w.createQueryClass(context, QueryClient, ReadOnlyInstance, QueryMsg)
|
66
|
-
);
|
67
|
-
|
68
|
-
context.addProviderInfo(
|
69
|
-
name,
|
70
|
-
w.PROVIDER_TYPES.QUERY_CLIENT_TYPE,
|
71
|
-
QueryClient,
|
72
|
-
localname
|
73
|
-
);
|
74
|
-
}
|
75
|
-
|
76
|
-
// execute messages
|
77
|
-
if (ExecuteMsg) {
|
78
|
-
const children = getMessageProperties(ExecuteMsg);
|
79
|
-
if (children.length > 0) {
|
80
|
-
Client = pascal(`${name}Client`);
|
81
|
-
Instance = pascal(`${name}Interface`);
|
82
|
-
|
83
|
-
body.push(
|
84
|
-
w.createExecuteInterface(
|
85
|
-
context,
|
86
|
-
Instance,
|
87
|
-
this.option.client.execExtendsQuery ? ReadOnlyInstance : null,
|
88
|
-
ExecuteMsg
|
89
|
-
)
|
90
|
-
);
|
91
|
-
|
92
|
-
body.push(
|
93
|
-
w.createExecuteClass(
|
94
|
-
context,
|
95
|
-
Client,
|
96
|
-
Instance,
|
97
|
-
this.option.client.execExtendsQuery ? QueryClient : null,
|
98
|
-
ExecuteMsg
|
99
|
-
)
|
100
|
-
);
|
101
|
-
|
102
|
-
context.addProviderInfo(
|
103
|
-
name,
|
104
|
-
w.PROVIDER_TYPES.SIGNING_CLIENT_TYPE,
|
105
|
-
Client,
|
106
|
-
localname
|
107
|
-
);
|
108
|
-
}
|
109
|
-
}
|
110
|
-
|
111
|
-
if (typeHash.hasOwnProperty("Coin")) {
|
112
|
-
// @ts-ignore
|
113
|
-
delete context.utils.Coin;
|
114
|
-
}
|
115
|
-
|
116
|
-
return [
|
117
|
-
{
|
118
|
-
type: TYPE,
|
119
|
-
localname,
|
120
|
-
body,
|
121
|
-
},
|
122
|
-
];
|
123
|
-
}
|
124
|
-
}
|
package/src/plugins/index.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export * from "./plugin-base"
|
@@ -1,85 +0,0 @@
|
|
1
|
-
import { pascal } from 'case';
|
2
|
-
import * as w from 'wasm-ast-types';
|
3
|
-
import { findAndParseTypes, findQueryMsg, findExecuteMsg } from '../utils';
|
4
|
-
import {
|
5
|
-
getMessageProperties,
|
6
|
-
RenderContext,
|
7
|
-
RenderContextBase,
|
8
|
-
ContractInfo,
|
9
|
-
RenderOptions
|
10
|
-
} from 'wasm-ast-types';
|
11
|
-
import { BuilderFileType } from '../builder';
|
12
|
-
import { BuilderPluginBase } from './plugin-base';
|
13
|
-
|
14
|
-
export class MessageBuilderPlugin extends BuilderPluginBase<RenderOptions> {
|
15
|
-
initContext(
|
16
|
-
contract: ContractInfo,
|
17
|
-
options?: RenderOptions
|
18
|
-
): RenderContextBase<RenderOptions> {
|
19
|
-
return new RenderContext(contract, options, this.builder.builderContext);
|
20
|
-
}
|
21
|
-
|
22
|
-
async doRender(
|
23
|
-
name: string,
|
24
|
-
context: RenderContext
|
25
|
-
): Promise<
|
26
|
-
{
|
27
|
-
type: BuilderFileType;
|
28
|
-
pluginType?: string;
|
29
|
-
localname: string;
|
30
|
-
body: any[];
|
31
|
-
}[]
|
32
|
-
> {
|
33
|
-
const { enabled } = this.option.messageBuilder;
|
34
|
-
|
35
|
-
if (!enabled) {
|
36
|
-
return;
|
37
|
-
}
|
38
|
-
|
39
|
-
const { schemas } = context.contract;
|
40
|
-
|
41
|
-
const localname = pascal(name) + '.message-builder.ts';
|
42
|
-
const TypesFile = pascal(name) + '.types';
|
43
|
-
const ExecuteMsg = findExecuteMsg(schemas);
|
44
|
-
const typeHash = await findAndParseTypes(schemas);
|
45
|
-
|
46
|
-
const body = [];
|
47
|
-
|
48
|
-
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
49
|
-
body.push(w.importStmt(['CamelCasedProperties'], 'type-fest'));
|
50
|
-
|
51
|
-
// execute messages
|
52
|
-
if (ExecuteMsg) {
|
53
|
-
const children = getMessageProperties(ExecuteMsg);
|
54
|
-
if (children.length > 0) {
|
55
|
-
const className = pascal(`${name}ExecuteMsgBuilder`);
|
56
|
-
|
57
|
-
body.push(w.createMessageBuilderClass(context, className, ExecuteMsg));
|
58
|
-
}
|
59
|
-
}
|
60
|
-
|
61
|
-
const QueryMsg = findQueryMsg(schemas);
|
62
|
-
// query messages
|
63
|
-
if (QueryMsg) {
|
64
|
-
const children = getMessageProperties(QueryMsg);
|
65
|
-
if (children.length > 0) {
|
66
|
-
const className = pascal(`${name}QueryMsgBuilder`);
|
67
|
-
|
68
|
-
body.push(w.createMessageBuilderClass(context, className, QueryMsg));
|
69
|
-
}
|
70
|
-
}
|
71
|
-
|
72
|
-
if (typeHash.hasOwnProperty('Coin')) {
|
73
|
-
// @ts-ignore
|
74
|
-
delete context.utils.Coin;
|
75
|
-
}
|
76
|
-
|
77
|
-
return [
|
78
|
-
{
|
79
|
-
type: 'message-builder',
|
80
|
-
localname,
|
81
|
-
body
|
82
|
-
}
|
83
|
-
];
|
84
|
-
}
|
85
|
-
}
|
@@ -1,89 +0,0 @@
|
|
1
|
-
import { pascal } from "case";
|
2
|
-
import * as w from "wasm-ast-types";
|
3
|
-
import { findAndParseTypes, findExecuteMsg } from "../utils";
|
4
|
-
import {
|
5
|
-
MessageComposerOptions,
|
6
|
-
getMessageProperties,
|
7
|
-
ContractInfo,
|
8
|
-
RenderContextBase,
|
9
|
-
RenderContext,
|
10
|
-
RenderOptions,
|
11
|
-
} from "wasm-ast-types";
|
12
|
-
import { BuilderFileType } from "../builder";
|
13
|
-
import { BuilderPluginBase } from "./plugin-base";
|
14
|
-
|
15
|
-
export const TYPE = "message-composer";
|
16
|
-
|
17
|
-
export class MessageComposerPlugin extends BuilderPluginBase<RenderOptions> {
|
18
|
-
initContext(
|
19
|
-
contract: ContractInfo,
|
20
|
-
options?: RenderOptions
|
21
|
-
): RenderContextBase<RenderOptions> {
|
22
|
-
return new RenderContext(contract, options, this.builder.builderContext);
|
23
|
-
}
|
24
|
-
|
25
|
-
async doRender(
|
26
|
-
name: string,
|
27
|
-
context: RenderContext
|
28
|
-
): Promise<
|
29
|
-
{
|
30
|
-
type: BuilderFileType;
|
31
|
-
pluginType?: string;
|
32
|
-
localname: string;
|
33
|
-
body: any[];
|
34
|
-
}[]
|
35
|
-
> {
|
36
|
-
const { enabled } = this.option.messageComposer;
|
37
|
-
|
38
|
-
if (!enabled) {
|
39
|
-
return;
|
40
|
-
}
|
41
|
-
|
42
|
-
const { schemas } = context.contract;
|
43
|
-
|
44
|
-
const localname = pascal(name) + ".message-composer.ts";
|
45
|
-
const TypesFile = pascal(name) + ".types";
|
46
|
-
const ExecuteMsg = findExecuteMsg(schemas);
|
47
|
-
const typeHash = await findAndParseTypes(schemas);
|
48
|
-
|
49
|
-
const body = [];
|
50
|
-
|
51
|
-
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
52
|
-
|
53
|
-
// execute messages
|
54
|
-
if (ExecuteMsg) {
|
55
|
-
const children = getMessageProperties(ExecuteMsg);
|
56
|
-
if (children.length > 0) {
|
57
|
-
const TheClass = pascal(`${name}MsgComposer`);
|
58
|
-
const Interface = pascal(`${name}Msg`);
|
59
|
-
|
60
|
-
body.push(
|
61
|
-
w.createMessageComposerInterface(context, Interface, ExecuteMsg)
|
62
|
-
);
|
63
|
-
body.push(
|
64
|
-
w.createMessageComposerClass(context, TheClass, Interface, ExecuteMsg)
|
65
|
-
);
|
66
|
-
|
67
|
-
context.addProviderInfo(
|
68
|
-
name,
|
69
|
-
w.PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE,
|
70
|
-
TheClass,
|
71
|
-
localname
|
72
|
-
);
|
73
|
-
}
|
74
|
-
}
|
75
|
-
|
76
|
-
if (typeHash.hasOwnProperty("Coin")) {
|
77
|
-
// @ts-ignore
|
78
|
-
delete context.utils.Coin;
|
79
|
-
}
|
80
|
-
|
81
|
-
return [
|
82
|
-
{
|
83
|
-
type: TYPE,
|
84
|
-
localname,
|
85
|
-
body,
|
86
|
-
},
|
87
|
-
];
|
88
|
-
}
|
89
|
-
}
|