@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
package/module/plugins/client.js
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
import { pascal } from "case";
|
2
|
-
import * as w from "wasm-ast-types";
|
3
|
-
import { findExecuteMsg, findAndParseTypes, findQueryMsg } from "../utils";
|
4
|
-
import { RenderContext, getMessageProperties } from "wasm-ast-types";
|
5
|
-
import { BuilderPluginBase } from "./plugin-base";
|
6
|
-
export const TYPE = "client";
|
7
|
-
export class ClientPlugin extends BuilderPluginBase {
|
8
|
-
initContext(contract, options) {
|
9
|
-
return new RenderContext(contract, options, this.builder.builderContext);
|
10
|
-
}
|
11
|
-
async doRender(name, context) {
|
12
|
-
const {
|
13
|
-
enabled
|
14
|
-
} = this.option.client;
|
15
|
-
if (!enabled) {
|
16
|
-
return;
|
17
|
-
}
|
18
|
-
const {
|
19
|
-
schemas
|
20
|
-
} = context.contract;
|
21
|
-
const localname = pascal(name) + ".client.ts";
|
22
|
-
const TypesFile = pascal(name) + ".types";
|
23
|
-
const QueryMsg = findQueryMsg(schemas);
|
24
|
-
const ExecuteMsg = findExecuteMsg(schemas);
|
25
|
-
const typeHash = await findAndParseTypes(schemas);
|
26
|
-
let Client = null;
|
27
|
-
let Instance = null;
|
28
|
-
let QueryClient = null;
|
29
|
-
let ReadOnlyInstance = null;
|
30
|
-
const body = [];
|
31
|
-
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
32
|
-
|
33
|
-
// query messages
|
34
|
-
if (QueryMsg) {
|
35
|
-
QueryClient = pascal(`${name}QueryClient`);
|
36
|
-
ReadOnlyInstance = pascal(`${name}ReadOnlyInterface`);
|
37
|
-
body.push(w.createQueryInterface(context, ReadOnlyInstance, QueryMsg));
|
38
|
-
body.push(w.createQueryClass(context, QueryClient, ReadOnlyInstance, QueryMsg));
|
39
|
-
context.addProviderInfo(name, w.PROVIDER_TYPES.QUERY_CLIENT_TYPE, QueryClient, localname);
|
40
|
-
}
|
41
|
-
|
42
|
-
// execute messages
|
43
|
-
if (ExecuteMsg) {
|
44
|
-
const children = getMessageProperties(ExecuteMsg);
|
45
|
-
if (children.length > 0) {
|
46
|
-
Client = pascal(`${name}Client`);
|
47
|
-
Instance = pascal(`${name}Interface`);
|
48
|
-
body.push(w.createExecuteInterface(context, Instance, this.option.client.execExtendsQuery ? ReadOnlyInstance : null, ExecuteMsg));
|
49
|
-
body.push(w.createExecuteClass(context, Client, Instance, this.option.client.execExtendsQuery ? QueryClient : null, ExecuteMsg));
|
50
|
-
context.addProviderInfo(name, w.PROVIDER_TYPES.SIGNING_CLIENT_TYPE, Client, localname);
|
51
|
-
}
|
52
|
-
}
|
53
|
-
if (typeHash.hasOwnProperty("Coin")) {
|
54
|
-
// @ts-ignore
|
55
|
-
delete context.utils.Coin;
|
56
|
-
}
|
57
|
-
return [{
|
58
|
-
type: TYPE,
|
59
|
-
localname,
|
60
|
-
body
|
61
|
-
}];
|
62
|
-
}
|
63
|
-
}
|
package/module/plugins/index.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export * from "./plugin-base";
|
@@ -1,55 +0,0 @@
|
|
1
|
-
import { pascal } from 'case';
|
2
|
-
import * as w from 'wasm-ast-types';
|
3
|
-
import { findAndParseTypes, findQueryMsg, findExecuteMsg } from '../utils';
|
4
|
-
import { getMessageProperties, RenderContext } from 'wasm-ast-types';
|
5
|
-
import { BuilderPluginBase } from './plugin-base';
|
6
|
-
export class MessageBuilderPlugin extends BuilderPluginBase {
|
7
|
-
initContext(contract, options) {
|
8
|
-
return new RenderContext(contract, options, this.builder.builderContext);
|
9
|
-
}
|
10
|
-
async doRender(name, context) {
|
11
|
-
const {
|
12
|
-
enabled
|
13
|
-
} = this.option.messageBuilder;
|
14
|
-
if (!enabled) {
|
15
|
-
return;
|
16
|
-
}
|
17
|
-
const {
|
18
|
-
schemas
|
19
|
-
} = context.contract;
|
20
|
-
const localname = pascal(name) + '.message-builder.ts';
|
21
|
-
const TypesFile = pascal(name) + '.types';
|
22
|
-
const ExecuteMsg = findExecuteMsg(schemas);
|
23
|
-
const typeHash = await findAndParseTypes(schemas);
|
24
|
-
const body = [];
|
25
|
-
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
26
|
-
body.push(w.importStmt(['CamelCasedProperties'], 'type-fest'));
|
27
|
-
|
28
|
-
// execute messages
|
29
|
-
if (ExecuteMsg) {
|
30
|
-
const children = getMessageProperties(ExecuteMsg);
|
31
|
-
if (children.length > 0) {
|
32
|
-
const className = pascal(`${name}ExecuteMsgBuilder`);
|
33
|
-
body.push(w.createMessageBuilderClass(context, className, ExecuteMsg));
|
34
|
-
}
|
35
|
-
}
|
36
|
-
const QueryMsg = findQueryMsg(schemas);
|
37
|
-
// query messages
|
38
|
-
if (QueryMsg) {
|
39
|
-
const children = getMessageProperties(QueryMsg);
|
40
|
-
if (children.length > 0) {
|
41
|
-
const className = pascal(`${name}QueryMsgBuilder`);
|
42
|
-
body.push(w.createMessageBuilderClass(context, className, QueryMsg));
|
43
|
-
}
|
44
|
-
}
|
45
|
-
if (typeHash.hasOwnProperty('Coin')) {
|
46
|
-
// @ts-ignore
|
47
|
-
delete context.utils.Coin;
|
48
|
-
}
|
49
|
-
return [{
|
50
|
-
type: 'message-builder',
|
51
|
-
localname,
|
52
|
-
body
|
53
|
-
}];
|
54
|
-
}
|
55
|
-
}
|
@@ -1,49 +0,0 @@
|
|
1
|
-
import { pascal } from "case";
|
2
|
-
import * as w from "wasm-ast-types";
|
3
|
-
import { findAndParseTypes, findExecuteMsg } from "../utils";
|
4
|
-
import { getMessageProperties, RenderContext } from "wasm-ast-types";
|
5
|
-
import { BuilderPluginBase } from "./plugin-base";
|
6
|
-
export const TYPE = "message-composer";
|
7
|
-
export class MessageComposerPlugin extends BuilderPluginBase {
|
8
|
-
initContext(contract, options) {
|
9
|
-
return new RenderContext(contract, options, this.builder.builderContext);
|
10
|
-
}
|
11
|
-
async doRender(name, context) {
|
12
|
-
const {
|
13
|
-
enabled
|
14
|
-
} = this.option.messageComposer;
|
15
|
-
if (!enabled) {
|
16
|
-
return;
|
17
|
-
}
|
18
|
-
const {
|
19
|
-
schemas
|
20
|
-
} = context.contract;
|
21
|
-
const localname = pascal(name) + ".message-composer.ts";
|
22
|
-
const TypesFile = pascal(name) + ".types";
|
23
|
-
const ExecuteMsg = findExecuteMsg(schemas);
|
24
|
-
const typeHash = await findAndParseTypes(schemas);
|
25
|
-
const body = [];
|
26
|
-
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
27
|
-
|
28
|
-
// execute messages
|
29
|
-
if (ExecuteMsg) {
|
30
|
-
const children = getMessageProperties(ExecuteMsg);
|
31
|
-
if (children.length > 0) {
|
32
|
-
const TheClass = pascal(`${name}MsgComposer`);
|
33
|
-
const Interface = pascal(`${name}Msg`);
|
34
|
-
body.push(w.createMessageComposerInterface(context, Interface, ExecuteMsg));
|
35
|
-
body.push(w.createMessageComposerClass(context, TheClass, Interface, ExecuteMsg));
|
36
|
-
context.addProviderInfo(name, w.PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE, TheClass, localname);
|
37
|
-
}
|
38
|
-
}
|
39
|
-
if (typeHash.hasOwnProperty("Coin")) {
|
40
|
-
// @ts-ignore
|
41
|
-
delete context.utils.Coin;
|
42
|
-
}
|
43
|
-
return [{
|
44
|
-
type: TYPE,
|
45
|
-
localname,
|
46
|
-
body
|
47
|
-
}];
|
48
|
-
}
|
49
|
-
}
|
@@ -1,66 +0,0 @@
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
2
|
-
import { sync as mkdirp } from "mkdirp";
|
3
|
-
import { join } from "path";
|
4
|
-
import { writeFileSync } from "fs";
|
5
|
-
import { header } from "../utils/header";
|
6
|
-
import generate from "@babel/generator";
|
7
|
-
import * as t from "@babel/types";
|
8
|
-
|
9
|
-
/**
|
10
|
-
* IBuilderPlugin is a common plugin that render generated code.
|
11
|
-
*/
|
12
|
-
|
13
|
-
/**
|
14
|
-
* BuilderPluginBase enable ts-codegen users implement their own plugins by only implement a few functions.
|
15
|
-
*/
|
16
|
-
export class BuilderPluginBase {
|
17
|
-
constructor(opt, builder) {
|
18
|
-
_defineProperty(this, "builder", void 0);
|
19
|
-
_defineProperty(this, "option", void 0);
|
20
|
-
_defineProperty(this, "utils", void 0);
|
21
|
-
this.option = opt;
|
22
|
-
this.builder = builder;
|
23
|
-
}
|
24
|
-
setBuilder(builder) {
|
25
|
-
this.builder = builder;
|
26
|
-
}
|
27
|
-
async render(name, contractInfo, outPath) {
|
28
|
-
const {
|
29
|
-
enabled
|
30
|
-
} = this.option;
|
31
|
-
if (!enabled) {
|
32
|
-
return;
|
33
|
-
}
|
34
|
-
const context = this.initContext(contractInfo, this.option);
|
35
|
-
const results = await this.doRender(name, context);
|
36
|
-
if (!results || !results.length) {
|
37
|
-
return [];
|
38
|
-
}
|
39
|
-
return results.map(result => {
|
40
|
-
const imports = context.getImports(this.utils, result.localname);
|
41
|
-
const code = header + generate(t.program([...imports, ...result.body])).code;
|
42
|
-
mkdirp(outPath);
|
43
|
-
const filename = join(outPath, result.localname);
|
44
|
-
writeFileSync(filename, code);
|
45
|
-
return {
|
46
|
-
type: result.type,
|
47
|
-
pluginType: result.pluginType,
|
48
|
-
contract: name,
|
49
|
-
localname: result.localname,
|
50
|
-
filename
|
51
|
-
};
|
52
|
-
});
|
53
|
-
}
|
54
|
-
|
55
|
-
/**
|
56
|
-
* init context here
|
57
|
-
* @param contract
|
58
|
-
* @param options
|
59
|
-
*/
|
60
|
-
|
61
|
-
/**
|
62
|
-
* render generated code here.
|
63
|
-
* @param name
|
64
|
-
* @param context
|
65
|
-
*/
|
66
|
-
}
|
@@ -1,56 +0,0 @@
|
|
1
|
-
import { pascal } from "case";
|
2
|
-
import * as w from "wasm-ast-types";
|
3
|
-
import { RenderContext } from "wasm-ast-types";
|
4
|
-
import { BuilderPluginBase } from "./plugin-base";
|
5
|
-
import { GetLocalBaseNameByContractName } from "./provider";
|
6
|
-
export class ContractsProviderBundlePlugin extends BuilderPluginBase {
|
7
|
-
constructor(opt) {
|
8
|
-
super(opt);
|
9
|
-
this.utils = {
|
10
|
-
CosmWasmClient: "@cosmjs/cosmwasm-stargate",
|
11
|
-
SigningCosmWasmClient: "@cosmjs/cosmwasm-stargate",
|
12
|
-
IQueryClientProvider: "__contractContextBase__",
|
13
|
-
ISigningClientProvider: "__contractContextBase__",
|
14
|
-
IMessageComposerProvider: "__contractContextBase__"
|
15
|
-
};
|
16
|
-
}
|
17
|
-
initContext(contract, options) {
|
18
|
-
return new RenderContext(contract, options, this.builder.builderContext);
|
19
|
-
}
|
20
|
-
async doRender(name, context) {
|
21
|
-
if (!this.option?.useContractsHooks?.enabled) {
|
22
|
-
return;
|
23
|
-
}
|
24
|
-
const providerInfos = context.getProviderInfos();
|
25
|
-
if (!Object.keys(providerInfos || {})?.length) {
|
26
|
-
return;
|
27
|
-
}
|
28
|
-
const localname = "contractContextProviders.ts";
|
29
|
-
const body = [];
|
30
|
-
context.addUtil("CosmWasmClient");
|
31
|
-
context.addUtil("SigningCosmWasmClient");
|
32
|
-
context.addUtil("IQueryClientProvider");
|
33
|
-
context.addUtil("ISigningClientProvider");
|
34
|
-
context.addUtil("IMessageComposerProvider");
|
35
|
-
for (const name in providerInfos) {
|
36
|
-
if (Object.prototype.hasOwnProperty.call(providerInfos, name)) {
|
37
|
-
const providerInfo = providerInfos[name];
|
38
|
-
for (const key in providerInfo) {
|
39
|
-
if (Object.prototype.hasOwnProperty.call(providerInfo, key)) {
|
40
|
-
const info = providerInfo[key];
|
41
|
-
body.push(w.importStmt([info.classname], `./${info.basename}`));
|
42
|
-
}
|
43
|
-
}
|
44
|
-
body.push(w.importStmt([pascal(name)], `./${GetLocalBaseNameByContractName(name)}`));
|
45
|
-
}
|
46
|
-
}
|
47
|
-
body.push(w.createIContractsContext(providerInfos));
|
48
|
-
body.push(w.createGettingProviders(providerInfos));
|
49
|
-
return [{
|
50
|
-
type: "plugin",
|
51
|
-
pluginType: "contractContextProviders",
|
52
|
-
localname,
|
53
|
-
body
|
54
|
-
}];
|
55
|
-
}
|
56
|
-
}
|
@@ -1,68 +0,0 @@
|
|
1
|
-
import { pascal } from "case";
|
2
|
-
import * as w from "wasm-ast-types";
|
3
|
-
import { RenderContext } from "wasm-ast-types";
|
4
|
-
import { BuilderPluginBase } from "./plugin-base";
|
5
|
-
export const GetLocalNameByContractName = name => `${pascal(name)}.provider.ts`;
|
6
|
-
export const GetLocalBaseNameByContractName = name => `${pascal(name)}.provider`;
|
7
|
-
export class ContractsContextProviderPlugin extends BuilderPluginBase {
|
8
|
-
constructor(opt) {
|
9
|
-
super(opt);
|
10
|
-
this.utils = {
|
11
|
-
ContractBase: "__contractContextBase__",
|
12
|
-
IContractConstructor: "__contractContextBase__",
|
13
|
-
IEmptyClient: "__contractContextBase__"
|
14
|
-
};
|
15
|
-
}
|
16
|
-
initContext(contract, options) {
|
17
|
-
return new RenderContext(contract, options, this.builder.builderContext);
|
18
|
-
}
|
19
|
-
async doRender(name, context) {
|
20
|
-
if (!this.option?.useContractsHooks?.enabled) {
|
21
|
-
return;
|
22
|
-
}
|
23
|
-
const providerInfo = context.getProviderInfos()[name];
|
24
|
-
if (!Object.keys(providerInfo || {})?.length) {
|
25
|
-
return;
|
26
|
-
}
|
27
|
-
context.addUtil("ContractBase");
|
28
|
-
context.addUtil("IContractConstructor");
|
29
|
-
const localname = GetLocalNameByContractName(name);
|
30
|
-
let needEmptyClientType = false;
|
31
|
-
let clientFile = null;
|
32
|
-
let clientClasses = [];
|
33
|
-
const body = [];
|
34
|
-
const signClientProviderInfo = providerInfo[w.PROVIDER_TYPES.SIGNING_CLIENT_TYPE];
|
35
|
-
if (signClientProviderInfo) {
|
36
|
-
clientFile = `./${signClientProviderInfo.basename}`;
|
37
|
-
clientClasses.push(signClientProviderInfo.classname);
|
38
|
-
} else {
|
39
|
-
needEmptyClientType = true;
|
40
|
-
}
|
41
|
-
const queryClientProviderInfo = providerInfo[w.PROVIDER_TYPES.QUERY_CLIENT_TYPE];
|
42
|
-
if (queryClientProviderInfo) {
|
43
|
-
clientFile = `./${queryClientProviderInfo.basename}`;
|
44
|
-
clientClasses.push(queryClientProviderInfo.classname);
|
45
|
-
} else {
|
46
|
-
needEmptyClientType = true;
|
47
|
-
}
|
48
|
-
if (clientFile) {
|
49
|
-
body.push(w.importStmt(clientClasses, clientFile));
|
50
|
-
}
|
51
|
-
const messageComposerProviderInfo = providerInfo[w.PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE];
|
52
|
-
if (messageComposerProviderInfo) {
|
53
|
-
body.push(w.importStmt([messageComposerProviderInfo.classname], `./${messageComposerProviderInfo.basename}`));
|
54
|
-
} else {
|
55
|
-
needEmptyClientType = true;
|
56
|
-
}
|
57
|
-
if (needEmptyClientType) {
|
58
|
-
context.addUtil("IEmptyClient");
|
59
|
-
}
|
60
|
-
body.push(w.createProvider(name, providerInfo));
|
61
|
-
return [{
|
62
|
-
type: "plugin",
|
63
|
-
pluginType: "provider",
|
64
|
-
localname,
|
65
|
-
body
|
66
|
-
}];
|
67
|
-
}
|
68
|
-
}
|
@@ -1,72 +0,0 @@
|
|
1
|
-
import { pascal } from 'case';
|
2
|
-
import * as w from 'wasm-ast-types';
|
3
|
-
import { findAndParseTypes, findExecuteMsg, findQueryMsg } from '../utils';
|
4
|
-
import { getMessageProperties, RenderContext } from 'wasm-ast-types';
|
5
|
-
import { BuilderPluginBase } from './plugin-base';
|
6
|
-
export class ReactQueryPlugin extends BuilderPluginBase {
|
7
|
-
initContext(contract, options) {
|
8
|
-
return new RenderContext(contract, options, this.builder.builderContext);
|
9
|
-
}
|
10
|
-
async doRender(name, context) {
|
11
|
-
const options = this.option.reactQuery;
|
12
|
-
const {
|
13
|
-
enabled
|
14
|
-
} = options;
|
15
|
-
if (!enabled) {
|
16
|
-
return;
|
17
|
-
}
|
18
|
-
const {
|
19
|
-
schemas
|
20
|
-
} = context.contract;
|
21
|
-
const localname = pascal(`${name}`) + '.react-query.ts';
|
22
|
-
const ContractFile = pascal(`${name}`) + '.client';
|
23
|
-
const TypesFile = pascal(`${name}`) + '.types';
|
24
|
-
const QueryMsg = findQueryMsg(schemas);
|
25
|
-
const ExecuteMsg = findExecuteMsg(schemas);
|
26
|
-
const typeHash = await findAndParseTypes(schemas);
|
27
|
-
const ExecuteClient = pascal(`${name}Client`);
|
28
|
-
const QueryClient = pascal(`${name}QueryClient`);
|
29
|
-
const body = [];
|
30
|
-
const clientImports = [];
|
31
|
-
QueryMsg && clientImports.push(QueryClient);
|
32
|
-
|
33
|
-
// check that there are commands within the exec msg
|
34
|
-
const shouldGenerateMutationHooks = ExecuteMsg && options?.version === 'v4' && options?.mutations && getMessageProperties(ExecuteMsg).length > 0;
|
35
|
-
if (shouldGenerateMutationHooks) {
|
36
|
-
clientImports.push(ExecuteClient);
|
37
|
-
}
|
38
|
-
|
39
|
-
// general contract imports
|
40
|
-
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
41
|
-
|
42
|
-
// client imports
|
43
|
-
body.push(w.importStmt(clientImports, `./${ContractFile}`));
|
44
|
-
|
45
|
-
// query messages
|
46
|
-
if (QueryMsg) {
|
47
|
-
[].push.apply(body, w.createReactQueryHooks({
|
48
|
-
context,
|
49
|
-
queryMsg: QueryMsg,
|
50
|
-
contractName: name,
|
51
|
-
QueryClient
|
52
|
-
}));
|
53
|
-
}
|
54
|
-
if (shouldGenerateMutationHooks) {
|
55
|
-
[].push.apply(body, w.createReactQueryMutationHooks({
|
56
|
-
context,
|
57
|
-
execMsg: ExecuteMsg,
|
58
|
-
contractName: name,
|
59
|
-
ExecuteClient
|
60
|
-
}));
|
61
|
-
}
|
62
|
-
if (typeHash.hasOwnProperty('Coin')) {
|
63
|
-
// @ts-ignore
|
64
|
-
delete context.utils.Coin;
|
65
|
-
}
|
66
|
-
return [{
|
67
|
-
type: 'react-query',
|
68
|
-
localname,
|
69
|
-
body
|
70
|
-
}];
|
71
|
-
}
|
72
|
-
}
|
package/module/plugins/recoil.js
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
2
|
-
import { pascal } from 'case';
|
3
|
-
import * as w from 'wasm-ast-types';
|
4
|
-
import { findAndParseTypes, findQueryMsg } from '../utils';
|
5
|
-
import { RenderContext } from 'wasm-ast-types';
|
6
|
-
import { BuilderPluginBase } from './plugin-base';
|
7
|
-
export class RecoilPlugin extends BuilderPluginBase {
|
8
|
-
constructor(...args) {
|
9
|
-
super(...args);
|
10
|
-
_defineProperty(this, "utils", {
|
11
|
-
selectorFamily: 'recoil'
|
12
|
-
});
|
13
|
-
}
|
14
|
-
initContext(contract, options) {
|
15
|
-
return new RenderContext(contract, options, this.builder.builderContext);
|
16
|
-
}
|
17
|
-
async doRender(name, context) {
|
18
|
-
const {
|
19
|
-
enabled
|
20
|
-
} = this.option.recoil;
|
21
|
-
if (!enabled) {
|
22
|
-
return;
|
23
|
-
}
|
24
|
-
const {
|
25
|
-
schemas
|
26
|
-
} = context.contract;
|
27
|
-
const localname = pascal(name) + '.recoil.ts';
|
28
|
-
const ContractFile = pascal(name) + '.client';
|
29
|
-
const TypesFile = pascal(name) + '.types';
|
30
|
-
const QueryMsg = findQueryMsg(schemas);
|
31
|
-
const typeHash = await findAndParseTypes(schemas);
|
32
|
-
let QueryClient = null;
|
33
|
-
let ReadOnlyInstance = null;
|
34
|
-
const body = [];
|
35
|
-
body.push(w.importStmt(['cosmWasmClient'], './chain'));
|
36
|
-
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
37
|
-
|
38
|
-
// query messages
|
39
|
-
if (QueryMsg) {
|
40
|
-
QueryClient = pascal(`${name}QueryClient`);
|
41
|
-
ReadOnlyInstance = pascal(`${name}ReadOnlyInterface`);
|
42
|
-
body.push(w.importStmt([QueryClient], `./${ContractFile}`));
|
43
|
-
body.push(w.createRecoilQueryClientType());
|
44
|
-
body.push(w.createRecoilQueryClient(context, name, QueryClient));
|
45
|
-
[].push.apply(body, w.createRecoilSelectors(context, name, QueryClient, QueryMsg));
|
46
|
-
}
|
47
|
-
if (typeHash.hasOwnProperty('Coin')) {
|
48
|
-
// @ts-ignore
|
49
|
-
delete context.utils.Coin;
|
50
|
-
}
|
51
|
-
return [{
|
52
|
-
type: 'recoil',
|
53
|
-
localname,
|
54
|
-
body
|
55
|
-
}];
|
56
|
-
}
|
57
|
-
}
|
package/module/plugins/types.js
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
import * as t from '@babel/types';
|
2
|
-
import { clean } from '../utils/clean';
|
3
|
-
import { pascal } from 'case';
|
4
|
-
import { findExecuteMsg, findAndParseTypes } from '../utils';
|
5
|
-
import { RenderContext } from 'wasm-ast-types';
|
6
|
-
import { BuilderPluginBase } from './plugin-base';
|
7
|
-
export class TypesPlugin extends BuilderPluginBase {
|
8
|
-
initContext(contract, options) {
|
9
|
-
return new RenderContext(contract, options, this.builder.builderContext);
|
10
|
-
}
|
11
|
-
async doRender(name, context) {
|
12
|
-
const {
|
13
|
-
enabled
|
14
|
-
} = this.option.types;
|
15
|
-
if (!enabled) {
|
16
|
-
return;
|
17
|
-
}
|
18
|
-
const {
|
19
|
-
schemas
|
20
|
-
} = context.contract;
|
21
|
-
const options = this.option.types;
|
22
|
-
const localname = pascal(name) + '.types.ts';
|
23
|
-
const ExecuteMsg = findExecuteMsg(schemas);
|
24
|
-
const typeHash = await findAndParseTypes(schemas);
|
25
|
-
const body = [];
|
26
|
-
|
27
|
-
// TYPES
|
28
|
-
Object.values(typeHash).forEach(type => {
|
29
|
-
body.push(clean(type));
|
30
|
-
});
|
31
|
-
|
32
|
-
// alias the ExecuteMsg
|
33
|
-
if (options.aliasExecuteMsg && ExecuteMsg) {
|
34
|
-
body.push(t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(`${name}ExecuteMsg`), null, t.tsTypeReference(t.identifier('ExecuteMsg')))));
|
35
|
-
}
|
36
|
-
return [{
|
37
|
-
type: 'type',
|
38
|
-
localname,
|
39
|
-
body
|
40
|
-
}];
|
41
|
-
}
|
42
|
-
}
|
package/module/ts-codegen.js
DELETED
package/module/utils/clean.js
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
export const clean = obj => {
|
2
|
-
var copy;
|
3
|
-
// Handle the 3 simple types, and null or undefined
|
4
|
-
if (null == obj || 'object' != typeof obj) return obj;
|
5
|
-
|
6
|
-
// Handle Date
|
7
|
-
if (obj instanceof Date) {
|
8
|
-
copy = new Date();
|
9
|
-
copy.setTime(obj.getTime());
|
10
|
-
return copy;
|
11
|
-
}
|
12
|
-
|
13
|
-
// Handle Array
|
14
|
-
if (obj instanceof Array) {
|
15
|
-
copy = [];
|
16
|
-
for (var i = 0, len = obj.length; i < len; i++) {
|
17
|
-
copy[i] = clean(obj[i]);
|
18
|
-
}
|
19
|
-
return copy;
|
20
|
-
}
|
21
|
-
|
22
|
-
// Handle Object
|
23
|
-
if (obj instanceof Object || typeof obj === 'object') {
|
24
|
-
copy = {};
|
25
|
-
for (var attr in obj) {
|
26
|
-
if (obj.hasOwnProperty(attr)) {
|
27
|
-
switch (attr) {
|
28
|
-
case 'leadingComments':
|
29
|
-
case 'trailingComments':
|
30
|
-
case 'loc':
|
31
|
-
case 'start':
|
32
|
-
case 'end':
|
33
|
-
break;
|
34
|
-
default:
|
35
|
-
copy[attr] = clean(obj[attr]);
|
36
|
-
}
|
37
|
-
} else {
|
38
|
-
copy[attr] = clean(obj[attr]);
|
39
|
-
}
|
40
|
-
}
|
41
|
-
return copy;
|
42
|
-
}
|
43
|
-
throw new Error("Unable to copy obj! Its type isn't supported.");
|
44
|
-
};
|
package/module/utils/cleanse.js
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
import { pascal } from "case";
|
2
|
-
const cleanFor = str => {
|
3
|
-
/*
|
4
|
-
1. look at first char after _for_
|
5
|
-
2. ONLY if you find capitals after, modify it
|
6
|
-
*/
|
7
|
-
while (/_[a-z]+_[A-Z]/.test(str)) {
|
8
|
-
const m = str.match(/(_[a-z]+_)[A-Z]/);
|
9
|
-
str = str.replace(m[1], pascal(m[1]));
|
10
|
-
}
|
11
|
-
return str;
|
12
|
-
};
|
13
|
-
const cleanNullable = str => {
|
14
|
-
if (/^Nullable_/.test(str)) {
|
15
|
-
str = str.replace(/^Nullable_/, 'Nullable');
|
16
|
-
}
|
17
|
-
return str;
|
18
|
-
};
|
19
|
-
export const cleanse = obj => {
|
20
|
-
var copy;
|
21
|
-
// Handle the 3 simple types, and null or undefined
|
22
|
-
if (null == obj || 'object' != typeof obj) return obj;
|
23
|
-
|
24
|
-
// Handle Date
|
25
|
-
if (obj instanceof Date) {
|
26
|
-
copy = new Date();
|
27
|
-
copy.setTime(obj.getTime());
|
28
|
-
return copy;
|
29
|
-
}
|
30
|
-
|
31
|
-
// Handle Array
|
32
|
-
if (obj instanceof Array) {
|
33
|
-
copy = [];
|
34
|
-
for (var i = 0, len = obj.length; i < len; i++) {
|
35
|
-
copy[i] = cleanse(obj[i]);
|
36
|
-
}
|
37
|
-
return copy;
|
38
|
-
}
|
39
|
-
|
40
|
-
// Handle Object
|
41
|
-
if (obj instanceof Object || typeof obj === 'object') {
|
42
|
-
copy = {};
|
43
|
-
|
44
|
-
// https://github.com/CosmWasm/cosmwasm-typescript-gen/issues/27
|
45
|
-
if (Array.isArray(obj.enum) && obj.enum.length === 0) {
|
46
|
-
delete obj.enum;
|
47
|
-
if (!obj.type) {
|
48
|
-
obj.type = 'string';
|
49
|
-
}
|
50
|
-
}
|
51
|
-
for (var attr in obj) {
|
52
|
-
if (obj.hasOwnProperty(attr)) {
|
53
|
-
if (/_for_/.test(attr)) {
|
54
|
-
copy[cleanFor(attr)] = cleanse(obj[attr]);
|
55
|
-
} else if (/^Nullable_/.test(attr)) {
|
56
|
-
copy[cleanNullable(attr)] = cleanse(obj[attr]);
|
57
|
-
} else {
|
58
|
-
switch (attr) {
|
59
|
-
case 'title':
|
60
|
-
case '$ref':
|
61
|
-
if (typeof obj[attr] === 'string') {
|
62
|
-
copy[attr] = cleanse(cleanNullable(cleanFor(obj[attr])));
|
63
|
-
} else {
|
64
|
-
copy[attr] = cleanse(obj[attr]);
|
65
|
-
}
|
66
|
-
break;
|
67
|
-
default:
|
68
|
-
copy[attr] = cleanse(obj[attr]);
|
69
|
-
}
|
70
|
-
}
|
71
|
-
} else {
|
72
|
-
copy[attr] = cleanse(obj[attr]);
|
73
|
-
}
|
74
|
-
}
|
75
|
-
return copy;
|
76
|
-
}
|
77
|
-
throw new Error("Unable to copy obj! Its type isn't supported.");
|
78
|
-
};
|