@cosmwasm/ts-codegen 0.25.2 → 0.27.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 +26 -0
- package/main/builder/builder.js +165 -254
- package/main/commands/generate.js +3 -0
- package/main/generators/msg-builder.js +113 -0
- package/main/index.js +14 -0
- package/main/plugins/client.js +141 -0
- package/main/plugins/index.js +18 -0
- package/main/plugins/message-composer.js +128 -0
- package/main/plugins/msg-builder.js +139 -0
- package/main/plugins/plugin-base.js +126 -0
- package/main/plugins/react-query.js +152 -0
- package/main/plugins/recoil.js +145 -0
- package/main/plugins/types.js +123 -0
- package/module/builder/builder.js +63 -109
- package/module/commands/generate.js +3 -0
- package/module/generators/msg-builder.js +62 -0
- package/module/index.js +1 -0
- package/module/plugins/client.js +66 -0
- package/module/plugins/index.js +1 -0
- package/module/plugins/message-composer.js +53 -0
- package/module/plugins/msg-builder.js +63 -0
- package/module/plugins/plugin-base.js +59 -0
- package/module/plugins/react-query.js +77 -0
- package/module/plugins/recoil.js +64 -0
- package/module/plugins/types.js +45 -0
- package/package.json +3 -3
- package/src/builder/builder.ts +82 -82
- package/src/commands/generate.ts +3 -0
- package/src/generators/msg-builder.ts +80 -0
- package/src/index.ts +1 -0
- package/src/plugins/client.ts +108 -0
- package/src/plugins/index.ts +1 -0
- package/src/plugins/message-composer.ts +80 -0
- package/src/plugins/msg-builder.ts +85 -0
- package/src/plugins/plugin-base.ts +112 -0
- package/src/plugins/react-query.ts +115 -0
- package/src/plugins/recoil.ts +89 -0
- package/src/plugins/types.ts +74 -0
- package/types/src/builder/builder.d.ts +13 -9
- package/types/src/generators/msg-builder.d.ts +5 -0
- package/types/src/generators/msg-builder.ts +5 -0
- package/types/src/index.d.ts +1 -0
- package/types/src/plugins/client.d.ts +12 -0
- package/types/src/plugins/index.d.ts +1 -0
- package/types/src/plugins/message-composer.d.ts +12 -0
- package/types/src/plugins/msg-builder.d.ts +12 -0
- package/types/src/plugins/plugin-base.d.ts +47 -0
- package/types/src/plugins/react-query.d.ts +12 -0
- package/types/src/plugins/recoil.d.ts +13 -0
- package/types/src/plugins/types.d.ts +12 -0
@@ -0,0 +1,85 @@
|
|
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 MsgBuilderPlugin extends BuilderPluginBase<RenderOptions> {
|
15
|
+
initContext(
|
16
|
+
contract: ContractInfo,
|
17
|
+
options?: RenderOptions
|
18
|
+
): RenderContextBase<RenderOptions> {
|
19
|
+
return new RenderContext(contract, options);
|
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.msgBuilder;
|
34
|
+
|
35
|
+
if (!enabled) {
|
36
|
+
return;
|
37
|
+
}
|
38
|
+
|
39
|
+
const { schemas } = context.contract;
|
40
|
+
|
41
|
+
const localname = pascal(name) + '.msg-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.createMsgBuilderClass(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.createMsgBuilderClass(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: 'msg-builder',
|
80
|
+
localname,
|
81
|
+
body
|
82
|
+
}
|
83
|
+
];
|
84
|
+
}
|
85
|
+
}
|
@@ -0,0 +1,112 @@
|
|
1
|
+
import { sync as mkdirp } from 'mkdirp';
|
2
|
+
import { join } from 'path';
|
3
|
+
import { writeFileSync } from 'fs';
|
4
|
+
import { header } from '../utils/header';
|
5
|
+
import {
|
6
|
+
ContractInfo,
|
7
|
+
UtilMapping,
|
8
|
+
IContext
|
9
|
+
} from 'wasm-ast-types';
|
10
|
+
import generate from '@babel/generator';
|
11
|
+
import * as t from '@babel/types';
|
12
|
+
import { BuilderFile, BuilderFileType, TSBuilderOptions } from '../builder';
|
13
|
+
|
14
|
+
/**
|
15
|
+
* IBuilderPlugin is a common plugin that render generated code.
|
16
|
+
*/
|
17
|
+
export interface IBuilderPlugin {
|
18
|
+
/**
|
19
|
+
* a mapping of utils will be used in generated code.
|
20
|
+
*/
|
21
|
+
utils: UtilMapping;
|
22
|
+
|
23
|
+
/**
|
24
|
+
* render generated cdoe.
|
25
|
+
* @param name the name of contract
|
26
|
+
* @param contractInfo contract
|
27
|
+
* @param outPath the path of generated code.
|
28
|
+
* @returns info of generated files.
|
29
|
+
*/
|
30
|
+
render(
|
31
|
+
name: string,
|
32
|
+
contractInfo: ContractInfo,
|
33
|
+
outPath: string,
|
34
|
+
): Promise<BuilderFile[]>;
|
35
|
+
}
|
36
|
+
|
37
|
+
/**
|
38
|
+
* BuilderPluginBase enable ts-codegen users implement their own plugins by only implement a few functions.
|
39
|
+
*/
|
40
|
+
export abstract class BuilderPluginBase<TOpt extends { enabled?: boolean }> implements IBuilderPlugin {
|
41
|
+
option: TOpt;
|
42
|
+
utils: UtilMapping;
|
43
|
+
|
44
|
+
constructor(opt: TOpt) {
|
45
|
+
this.option = opt;
|
46
|
+
}
|
47
|
+
|
48
|
+
async render(
|
49
|
+
name: string,
|
50
|
+
contractInfo: ContractInfo,
|
51
|
+
outPath: string
|
52
|
+
): Promise<BuilderFile[]> {
|
53
|
+
const { enabled } = this.option;
|
54
|
+
|
55
|
+
if (!enabled) {
|
56
|
+
return;
|
57
|
+
}
|
58
|
+
|
59
|
+
const context = this.initContext(contractInfo, this.option);
|
60
|
+
|
61
|
+
const results = await this.doRender(name, context);
|
62
|
+
|
63
|
+
if (!results || !results.length) {
|
64
|
+
return [];
|
65
|
+
}
|
66
|
+
|
67
|
+
return results.map((result) => {
|
68
|
+
const imports = context.getImports(this.utils);
|
69
|
+
const code =
|
70
|
+
header + generate(t.program([...imports, ...result.body])).code;
|
71
|
+
|
72
|
+
mkdirp(outPath);
|
73
|
+
const filename = join(outPath, result.localname);
|
74
|
+
writeFileSync(filename, code);
|
75
|
+
|
76
|
+
return {
|
77
|
+
type: result.type,
|
78
|
+
pluginType: result.pluginType,
|
79
|
+
contract: name,
|
80
|
+
localname: result.localname,
|
81
|
+
filename
|
82
|
+
};
|
83
|
+
});
|
84
|
+
}
|
85
|
+
|
86
|
+
/**
|
87
|
+
* init context here
|
88
|
+
* @param contract
|
89
|
+
* @param options
|
90
|
+
*/
|
91
|
+
abstract initContext(
|
92
|
+
contract: ContractInfo,
|
93
|
+
options?: TOpt
|
94
|
+
): IContext;
|
95
|
+
|
96
|
+
/**
|
97
|
+
* render generated code here.
|
98
|
+
* @param name
|
99
|
+
* @param context
|
100
|
+
*/
|
101
|
+
abstract doRender(
|
102
|
+
name: string,
|
103
|
+
context: IContext
|
104
|
+
): Promise<
|
105
|
+
{
|
106
|
+
type: BuilderFileType;
|
107
|
+
pluginType?: string;
|
108
|
+
localname: string;
|
109
|
+
body: any[];
|
110
|
+
}[]
|
111
|
+
>;
|
112
|
+
}
|
@@ -0,0 +1,115 @@
|
|
1
|
+
import { pascal } from 'case';
|
2
|
+
import * as w from 'wasm-ast-types';
|
3
|
+
import { findAndParseTypes, findExecuteMsg, findQueryMsg } from '../utils';
|
4
|
+
import {
|
5
|
+
getMessageProperties,
|
6
|
+
ContractInfo,
|
7
|
+
RenderOptions,
|
8
|
+
RenderContextBase,
|
9
|
+
RenderContext
|
10
|
+
} from 'wasm-ast-types';
|
11
|
+
import { BuilderFileType } from '../builder';
|
12
|
+
import { BuilderPluginBase } from './plugin-base';
|
13
|
+
|
14
|
+
export class ReactQueryPlugin extends BuilderPluginBase<RenderOptions> {
|
15
|
+
initContext(
|
16
|
+
contract: ContractInfo,
|
17
|
+
options?: RenderOptions
|
18
|
+
): RenderContextBase<RenderOptions> {
|
19
|
+
return new RenderContext(contract, options);
|
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 options = this.option.reactQuery;
|
34
|
+
|
35
|
+
const { enabled } = options;
|
36
|
+
|
37
|
+
if (!enabled) {
|
38
|
+
return;
|
39
|
+
}
|
40
|
+
|
41
|
+
const { schemas } = context.contract;
|
42
|
+
|
43
|
+
const localname = pascal(`${name}`) + '.react-query.ts';
|
44
|
+
const ContractFile = pascal(`${name}`) + '.client';
|
45
|
+
const TypesFile = pascal(`${name}`) + '.types';
|
46
|
+
|
47
|
+
const QueryMsg = findQueryMsg(schemas);
|
48
|
+
const ExecuteMsg = findExecuteMsg(schemas);
|
49
|
+
const typeHash = await findAndParseTypes(schemas);
|
50
|
+
|
51
|
+
const ExecuteClient = pascal(`${name}Client`);
|
52
|
+
const QueryClient = pascal(`${name}QueryClient`);
|
53
|
+
|
54
|
+
const body = [];
|
55
|
+
|
56
|
+
const clientImports = [];
|
57
|
+
|
58
|
+
QueryMsg && clientImports.push(QueryClient);
|
59
|
+
|
60
|
+
// check that there are commands within the exec msg
|
61
|
+
const shouldGenerateMutationHooks =
|
62
|
+
ExecuteMsg &&
|
63
|
+
options?.version === 'v4' &&
|
64
|
+
options?.mutations &&
|
65
|
+
getMessageProperties(ExecuteMsg).length > 0;
|
66
|
+
|
67
|
+
if (shouldGenerateMutationHooks) {
|
68
|
+
clientImports.push(ExecuteClient);
|
69
|
+
}
|
70
|
+
|
71
|
+
// general contract imports
|
72
|
+
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
73
|
+
|
74
|
+
// client imports
|
75
|
+
body.push(w.importStmt(clientImports, `./${ContractFile}`));
|
76
|
+
|
77
|
+
// query messages
|
78
|
+
if (QueryMsg) {
|
79
|
+
[].push.apply(
|
80
|
+
body,
|
81
|
+
w.createReactQueryHooks({
|
82
|
+
context,
|
83
|
+
queryMsg: QueryMsg,
|
84
|
+
contractName: name,
|
85
|
+
QueryClient
|
86
|
+
})
|
87
|
+
);
|
88
|
+
}
|
89
|
+
|
90
|
+
if (shouldGenerateMutationHooks) {
|
91
|
+
[].push.apply(
|
92
|
+
body,
|
93
|
+
w.createReactQueryMutationHooks({
|
94
|
+
context,
|
95
|
+
execMsg: ExecuteMsg,
|
96
|
+
contractName: name,
|
97
|
+
ExecuteClient
|
98
|
+
})
|
99
|
+
);
|
100
|
+
}
|
101
|
+
|
102
|
+
if (typeHash.hasOwnProperty('Coin')) {
|
103
|
+
// @ts-ignore
|
104
|
+
delete context.utils.Coin;
|
105
|
+
}
|
106
|
+
|
107
|
+
return [
|
108
|
+
{
|
109
|
+
type: 'react-query',
|
110
|
+
localname,
|
111
|
+
body
|
112
|
+
}
|
113
|
+
];
|
114
|
+
}
|
115
|
+
}
|
@@ -0,0 +1,89 @@
|
|
1
|
+
import { pascal } from 'case';
|
2
|
+
import * as w from 'wasm-ast-types';
|
3
|
+
import { findAndParseTypes, findQueryMsg } from '../utils';
|
4
|
+
import {
|
5
|
+
ContractInfo,
|
6
|
+
RenderContext,
|
7
|
+
RenderContextBase,
|
8
|
+
UtilMapping,
|
9
|
+
RenderOptions
|
10
|
+
} from 'wasm-ast-types';
|
11
|
+
import { BuilderFileType } from '../builder';
|
12
|
+
import { BuilderPluginBase } from './plugin-base';
|
13
|
+
|
14
|
+
export class RecoilPlugin extends BuilderPluginBase<RenderOptions> {
|
15
|
+
utils: UtilMapping = {
|
16
|
+
selectorFamily: 'recoil',
|
17
|
+
};
|
18
|
+
initContext(
|
19
|
+
contract: ContractInfo,
|
20
|
+
options?: RenderOptions
|
21
|
+
): RenderContextBase<RenderOptions> {
|
22
|
+
return new RenderContext(contract, options);
|
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.recoil;
|
37
|
+
|
38
|
+
if (!enabled) {
|
39
|
+
return;
|
40
|
+
}
|
41
|
+
|
42
|
+
const { schemas } = context.contract;
|
43
|
+
|
44
|
+
const localname = pascal(name) + '.recoil.ts';
|
45
|
+
const ContractFile = pascal(name) + '.client';
|
46
|
+
const TypesFile = pascal(name) + '.types';
|
47
|
+
|
48
|
+
const QueryMsg = findQueryMsg(schemas);
|
49
|
+
const typeHash = await findAndParseTypes(schemas);
|
50
|
+
|
51
|
+
let QueryClient = null;
|
52
|
+
let ReadOnlyInstance = null;
|
53
|
+
|
54
|
+
const body = [];
|
55
|
+
|
56
|
+
body.push(w.importStmt(['cosmWasmClient'], './chain'));
|
57
|
+
|
58
|
+
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
59
|
+
|
60
|
+
// query messages
|
61
|
+
if (QueryMsg) {
|
62
|
+
QueryClient = pascal(`${name}QueryClient`);
|
63
|
+
ReadOnlyInstance = pascal(`${name}ReadOnlyInterface`);
|
64
|
+
|
65
|
+
body.push(w.importStmt([QueryClient], `./${ContractFile}`));
|
66
|
+
|
67
|
+
body.push(w.createRecoilQueryClientType());
|
68
|
+
body.push(w.createRecoilQueryClient(context, name, QueryClient));
|
69
|
+
|
70
|
+
[].push.apply(
|
71
|
+
body,
|
72
|
+
w.createRecoilSelectors(context, name, QueryClient, QueryMsg)
|
73
|
+
);
|
74
|
+
}
|
75
|
+
|
76
|
+
if (typeHash.hasOwnProperty('Coin')) {
|
77
|
+
// @ts-ignore
|
78
|
+
delete context.utils.Coin;
|
79
|
+
}
|
80
|
+
|
81
|
+
return [
|
82
|
+
{
|
83
|
+
type: 'recoil',
|
84
|
+
localname,
|
85
|
+
body
|
86
|
+
}
|
87
|
+
];
|
88
|
+
}
|
89
|
+
}
|
@@ -0,0 +1,74 @@
|
|
1
|
+
import * as t from '@babel/types';
|
2
|
+
import { clean } from '../utils/clean';
|
3
|
+
import { pascal } from 'case';
|
4
|
+
import { findExecuteMsg, findAndParseTypes, findQueryMsg } from '../utils';
|
5
|
+
import {
|
6
|
+
ContractInfo,
|
7
|
+
RenderContext,
|
8
|
+
RenderContextBase,
|
9
|
+
RenderOptions
|
10
|
+
} from 'wasm-ast-types';
|
11
|
+
import { BuilderFileType } from '../builder';
|
12
|
+
import { BuilderPluginBase } from './plugin-base';
|
13
|
+
|
14
|
+
export class TypesPlugin extends BuilderPluginBase<RenderOptions> {
|
15
|
+
initContext(
|
16
|
+
contract: ContractInfo,
|
17
|
+
options?: RenderOptions
|
18
|
+
): RenderContextBase<RenderOptions> {
|
19
|
+
return new RenderContext(contract, options);
|
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.types;
|
34
|
+
|
35
|
+
if (!enabled) {
|
36
|
+
return;
|
37
|
+
}
|
38
|
+
|
39
|
+
const { schemas } = context.contract;
|
40
|
+
const options = this.option.types;
|
41
|
+
|
42
|
+
const localname = pascal(name) + '.types.ts';
|
43
|
+
const ExecuteMsg = findExecuteMsg(schemas);
|
44
|
+
const typeHash = await findAndParseTypes(schemas);
|
45
|
+
|
46
|
+
const body = [];
|
47
|
+
|
48
|
+
// TYPES
|
49
|
+
Object.values(typeHash).forEach((type: t.Node) => {
|
50
|
+
body.push(clean(type));
|
51
|
+
});
|
52
|
+
|
53
|
+
// alias the ExecuteMsg
|
54
|
+
if (options.aliasExecuteMsg && ExecuteMsg) {
|
55
|
+
body.push(
|
56
|
+
t.exportNamedDeclaration(
|
57
|
+
t.tsTypeAliasDeclaration(
|
58
|
+
t.identifier(`${name}ExecuteMsg`),
|
59
|
+
null,
|
60
|
+
t.tsTypeReference(t.identifier('ExecuteMsg'))
|
61
|
+
)
|
62
|
+
)
|
63
|
+
);
|
64
|
+
}
|
65
|
+
|
66
|
+
return [
|
67
|
+
{
|
68
|
+
type: 'type',
|
69
|
+
localname,
|
70
|
+
body
|
71
|
+
}
|
72
|
+
];
|
73
|
+
}
|
74
|
+
}
|
@@ -1,19 +1,24 @@
|
|
1
1
|
import { RenderOptions } from "wasm-ast-types";
|
2
|
+
import { IBuilderPlugin } from '../plugins';
|
2
3
|
export interface TSBuilderInput {
|
3
4
|
contracts: Array<ContractFile | string>;
|
4
5
|
outPath: string;
|
5
6
|
options?: TSBuilderOptions;
|
7
|
+
plugins?: IBuilderPlugin[];
|
6
8
|
}
|
7
9
|
export interface BundleOptions {
|
8
10
|
enabled?: boolean;
|
9
11
|
scope?: string;
|
10
12
|
bundleFile?: string;
|
13
|
+
bundlePath?: string;
|
11
14
|
}
|
12
|
-
export
|
15
|
+
export type TSBuilderOptions = {
|
13
16
|
bundle?: BundleOptions;
|
14
17
|
} & RenderOptions;
|
18
|
+
export type BuilderFileType = 'type' | 'client' | 'recoil' | 'react-query' | 'message-composer' | 'msg-builder' | 'plugin';
|
15
19
|
export interface BuilderFile {
|
16
|
-
type:
|
20
|
+
type: BuilderFileType;
|
21
|
+
pluginType?: string;
|
17
22
|
contract: string;
|
18
23
|
localname: string;
|
19
24
|
filename: string;
|
@@ -26,14 +31,13 @@ export declare class TSBuilder {
|
|
26
31
|
contracts: Array<ContractFile | string>;
|
27
32
|
outPath: string;
|
28
33
|
options?: TSBuilderOptions;
|
34
|
+
plugins: IBuilderPlugin[];
|
29
35
|
protected files: BuilderFile[];
|
30
|
-
|
31
|
-
|
32
|
-
renderTypes(contract: ContractFile): Promise<void>;
|
33
|
-
renderClient(contract: ContractFile): Promise<void>;
|
34
|
-
renderRecoil(contract: ContractFile): Promise<void>;
|
35
|
-
renderReactQuery(contract: ContractFile): Promise<void>;
|
36
|
-
renderMessageComposer(contract: ContractFile): Promise<void>;
|
36
|
+
loadDefaultPlugins(): void;
|
37
|
+
constructor({ contracts, outPath, options, plugins }: TSBuilderInput);
|
37
38
|
build(): Promise<void>;
|
39
|
+
private process;
|
40
|
+
private render;
|
41
|
+
private after;
|
38
42
|
bundle(): Promise<void>;
|
39
43
|
}
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import { ContractInfo } from "wasm-ast-types";
|
2
|
+
import { MsgBuilderOptions } from 'wasm-ast-types';
|
3
|
+
import { BuilderFile } from "../builder";
|
4
|
+
declare const _default: (name: string, contractInfo: ContractInfo, outPath: string, msgBuilderOptions?: MsgBuilderOptions) => Promise<BuilderFile[]>;
|
5
|
+
export default _default;
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import { ContractInfo } from "wasm-ast-types";
|
2
|
+
import { MsgBuilderOptions } from "wasm-ast-types";
|
3
|
+
import { BuilderFile } from "../builder";
|
4
|
+
declare const _default: (name: string, contractInfo: ContractInfo, outPath: string, msgBuilderOptions?: MsgBuilderOptions) => Promise<BuilderFile[]>;
|
5
|
+
export default _default;
|
package/types/src/index.d.ts
CHANGED
@@ -7,5 +7,6 @@ export { default as generateRecoil } from './generators/recoil';
|
|
7
7
|
export * from './utils';
|
8
8
|
export * from './builder';
|
9
9
|
export * from './bundler';
|
10
|
+
export * from './plugins';
|
10
11
|
declare const _default: (input: TSBuilderInput) => Promise<void>;
|
11
12
|
export default _default;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { RenderContext, ContractInfo, RenderContextBase, RenderOptions } from 'wasm-ast-types';
|
2
|
+
import { BuilderFileType } from '../builder';
|
3
|
+
import { BuilderPluginBase } from './plugin-base';
|
4
|
+
export declare class ClientPlugin extends BuilderPluginBase<RenderOptions> {
|
5
|
+
initContext(contract: ContractInfo, options?: RenderOptions): RenderContextBase<RenderOptions>;
|
6
|
+
doRender(name: string, context: RenderContext): Promise<{
|
7
|
+
type: BuilderFileType;
|
8
|
+
pluginType?: string;
|
9
|
+
localname: string;
|
10
|
+
body: any[];
|
11
|
+
}[]>;
|
12
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from "./plugin-base";
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { ContractInfo, RenderContextBase, RenderContext, RenderOptions } from 'wasm-ast-types';
|
2
|
+
import { BuilderFileType } from '../builder';
|
3
|
+
import { BuilderPluginBase } from './plugin-base';
|
4
|
+
export declare class MessageComposerPlugin extends BuilderPluginBase<RenderOptions> {
|
5
|
+
initContext(contract: ContractInfo, options?: RenderOptions): RenderContextBase<RenderOptions>;
|
6
|
+
doRender(name: string, context: RenderContext): Promise<{
|
7
|
+
type: BuilderFileType;
|
8
|
+
pluginType?: string;
|
9
|
+
localname: string;
|
10
|
+
body: any[];
|
11
|
+
}[]>;
|
12
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { RenderContext, RenderContextBase, ContractInfo, RenderOptions } from 'wasm-ast-types';
|
2
|
+
import { BuilderFileType } from '../builder';
|
3
|
+
import { BuilderPluginBase } from './plugin-base';
|
4
|
+
export declare class MsgBuilderPlugin extends BuilderPluginBase<RenderOptions> {
|
5
|
+
initContext(contract: ContractInfo, options?: RenderOptions): RenderContextBase<RenderOptions>;
|
6
|
+
doRender(name: string, context: RenderContext): Promise<{
|
7
|
+
type: BuilderFileType;
|
8
|
+
pluginType?: string;
|
9
|
+
localname: string;
|
10
|
+
body: any[];
|
11
|
+
}[]>;
|
12
|
+
}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
import { ContractInfo, UtilMapping, IContext } from 'wasm-ast-types';
|
2
|
+
import { BuilderFile, BuilderFileType } from '../builder';
|
3
|
+
/**
|
4
|
+
* IBuilderPlugin is a common plugin that render generated code.
|
5
|
+
*/
|
6
|
+
export interface IBuilderPlugin {
|
7
|
+
/**
|
8
|
+
* a mapping of utils will be used in generated code.
|
9
|
+
*/
|
10
|
+
utils: UtilMapping;
|
11
|
+
/**
|
12
|
+
* render generated cdoe.
|
13
|
+
* @param name the name of contract
|
14
|
+
* @param contractInfo contract
|
15
|
+
* @param outPath the path of generated code.
|
16
|
+
* @returns info of generated files.
|
17
|
+
*/
|
18
|
+
render(name: string, contractInfo: ContractInfo, outPath: string): Promise<BuilderFile[]>;
|
19
|
+
}
|
20
|
+
/**
|
21
|
+
* BuilderPluginBase enable ts-codegen users implement their own plugins by only implement a few functions.
|
22
|
+
*/
|
23
|
+
export declare abstract class BuilderPluginBase<TOpt extends {
|
24
|
+
enabled?: boolean;
|
25
|
+
}> implements IBuilderPlugin {
|
26
|
+
option: TOpt;
|
27
|
+
utils: UtilMapping;
|
28
|
+
constructor(opt: TOpt);
|
29
|
+
render(name: string, contractInfo: ContractInfo, outPath: string): Promise<BuilderFile[]>;
|
30
|
+
/**
|
31
|
+
* init context here
|
32
|
+
* @param contract
|
33
|
+
* @param options
|
34
|
+
*/
|
35
|
+
abstract initContext(contract: ContractInfo, options?: TOpt): IContext;
|
36
|
+
/**
|
37
|
+
* render generated code here.
|
38
|
+
* @param name
|
39
|
+
* @param context
|
40
|
+
*/
|
41
|
+
abstract doRender(name: string, context: IContext): Promise<{
|
42
|
+
type: BuilderFileType;
|
43
|
+
pluginType?: string;
|
44
|
+
localname: string;
|
45
|
+
body: any[];
|
46
|
+
}[]>;
|
47
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { ContractInfo, RenderOptions, RenderContextBase, RenderContext } from 'wasm-ast-types';
|
2
|
+
import { BuilderFileType } from '../builder';
|
3
|
+
import { BuilderPluginBase } from './plugin-base';
|
4
|
+
export declare class ReactQueryPlugin extends BuilderPluginBase<RenderOptions> {
|
5
|
+
initContext(contract: ContractInfo, options?: RenderOptions): RenderContextBase<RenderOptions>;
|
6
|
+
doRender(name: string, context: RenderContext): Promise<{
|
7
|
+
type: BuilderFileType;
|
8
|
+
pluginType?: string;
|
9
|
+
localname: string;
|
10
|
+
body: any[];
|
11
|
+
}[]>;
|
12
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { ContractInfo, RenderContext, RenderContextBase, UtilMapping, RenderOptions } from 'wasm-ast-types';
|
2
|
+
import { BuilderFileType } from '../builder';
|
3
|
+
import { BuilderPluginBase } from './plugin-base';
|
4
|
+
export declare class RecoilPlugin extends BuilderPluginBase<RenderOptions> {
|
5
|
+
utils: UtilMapping;
|
6
|
+
initContext(contract: ContractInfo, options?: RenderOptions): RenderContextBase<RenderOptions>;
|
7
|
+
doRender(name: string, context: RenderContext): Promise<{
|
8
|
+
type: BuilderFileType;
|
9
|
+
pluginType?: string;
|
10
|
+
localname: string;
|
11
|
+
body: any[];
|
12
|
+
}[]>;
|
13
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { ContractInfo, RenderContext, RenderContextBase, RenderOptions } from 'wasm-ast-types';
|
2
|
+
import { BuilderFileType } from '../builder';
|
3
|
+
import { BuilderPluginBase } from './plugin-base';
|
4
|
+
export declare class TypesPlugin extends BuilderPluginBase<RenderOptions> {
|
5
|
+
initContext(contract: ContractInfo, options?: RenderOptions): RenderContextBase<RenderOptions>;
|
6
|
+
doRender(name: string, context: RenderContext): Promise<{
|
7
|
+
type: BuilderFileType;
|
8
|
+
pluginType?: string;
|
9
|
+
localname: string;
|
10
|
+
body: any[];
|
11
|
+
}[]>;
|
12
|
+
}
|