@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
@@ -0,0 +1,79 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
+
exports.MessageBuilderPlugin = void 0;
|
27
|
+
const case_1 = require("case");
|
28
|
+
const w = __importStar(require("wasm-ast-types"));
|
29
|
+
const utils_1 = require("../utils");
|
30
|
+
const wasm_ast_types_1 = require("wasm-ast-types");
|
31
|
+
const plugin_base_1 = require("./plugin-base");
|
32
|
+
class MessageBuilderPlugin extends plugin_base_1.BuilderPluginBase {
|
33
|
+
initContext(contract, options) {
|
34
|
+
return new wasm_ast_types_1.RenderContext(contract, options, this.builder.builderContext);
|
35
|
+
}
|
36
|
+
async doRender(name, context) {
|
37
|
+
const { enabled } = this.option.messageBuilder;
|
38
|
+
if (!enabled) {
|
39
|
+
return;
|
40
|
+
}
|
41
|
+
const { schemas } = context.contract;
|
42
|
+
const localname = (0, case_1.pascal)(name) + '.message-builder.ts';
|
43
|
+
const TypesFile = (0, case_1.pascal)(name) + '.types';
|
44
|
+
const ExecuteMsg = (0, utils_1.findExecuteMsg)(schemas);
|
45
|
+
const typeHash = await (0, utils_1.findAndParseTypes)(schemas);
|
46
|
+
const body = [];
|
47
|
+
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
48
|
+
body.push(w.importStmt(['CamelCasedProperties'], 'type-fest'));
|
49
|
+
// execute messages
|
50
|
+
if (ExecuteMsg) {
|
51
|
+
const children = (0, wasm_ast_types_1.getMessageProperties)(ExecuteMsg);
|
52
|
+
if (children.length > 0) {
|
53
|
+
const className = (0, case_1.pascal)(`${name}ExecuteMsgBuilder`);
|
54
|
+
body.push(w.createMessageBuilderClass(context, className, ExecuteMsg));
|
55
|
+
}
|
56
|
+
}
|
57
|
+
const QueryMsg = (0, utils_1.findQueryMsg)(schemas);
|
58
|
+
// query messages
|
59
|
+
if (QueryMsg) {
|
60
|
+
const children = (0, wasm_ast_types_1.getMessageProperties)(QueryMsg);
|
61
|
+
if (children.length > 0) {
|
62
|
+
const className = (0, case_1.pascal)(`${name}QueryMsgBuilder`);
|
63
|
+
body.push(w.createMessageBuilderClass(context, className, QueryMsg));
|
64
|
+
}
|
65
|
+
}
|
66
|
+
if (typeHash.hasOwnProperty('Coin')) {
|
67
|
+
// @ts-ignore
|
68
|
+
delete context.utils.Coin;
|
69
|
+
}
|
70
|
+
return [
|
71
|
+
{
|
72
|
+
type: 'message-builder',
|
73
|
+
localname,
|
74
|
+
body
|
75
|
+
}
|
76
|
+
];
|
77
|
+
}
|
78
|
+
}
|
79
|
+
exports.MessageBuilderPlugin = MessageBuilderPlugin;
|
@@ -0,0 +1,73 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
+
exports.MessageComposerPlugin = exports.TYPE = void 0;
|
27
|
+
const case_1 = require("case");
|
28
|
+
const w = __importStar(require("wasm-ast-types"));
|
29
|
+
const utils_1 = require("../utils");
|
30
|
+
const wasm_ast_types_1 = require("wasm-ast-types");
|
31
|
+
const plugin_base_1 = require("./plugin-base");
|
32
|
+
exports.TYPE = "message-composer";
|
33
|
+
class MessageComposerPlugin extends plugin_base_1.BuilderPluginBase {
|
34
|
+
initContext(contract, options) {
|
35
|
+
return new wasm_ast_types_1.RenderContext(contract, options, this.builder.builderContext);
|
36
|
+
}
|
37
|
+
async doRender(name, context) {
|
38
|
+
const { enabled } = this.option.messageComposer;
|
39
|
+
if (!enabled) {
|
40
|
+
return;
|
41
|
+
}
|
42
|
+
const { schemas } = context.contract;
|
43
|
+
const localname = (0, case_1.pascal)(name) + ".message-composer.ts";
|
44
|
+
const TypesFile = (0, case_1.pascal)(name) + ".types";
|
45
|
+
const ExecuteMsg = (0, utils_1.findExecuteMsg)(schemas);
|
46
|
+
const typeHash = await (0, utils_1.findAndParseTypes)(schemas);
|
47
|
+
const body = [];
|
48
|
+
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
49
|
+
// execute messages
|
50
|
+
if (ExecuteMsg) {
|
51
|
+
const children = (0, wasm_ast_types_1.getMessageProperties)(ExecuteMsg);
|
52
|
+
if (children.length > 0) {
|
53
|
+
const TheClass = (0, case_1.pascal)(`${name}MsgComposer`);
|
54
|
+
const Interface = (0, case_1.pascal)(`${name}Msg`);
|
55
|
+
body.push(w.createMessageComposerInterface(context, Interface, ExecuteMsg));
|
56
|
+
body.push(w.createMessageComposerClass(context, TheClass, Interface, ExecuteMsg));
|
57
|
+
context.addProviderInfo(name, w.PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE, TheClass, localname);
|
58
|
+
}
|
59
|
+
}
|
60
|
+
if (typeHash.hasOwnProperty("Coin")) {
|
61
|
+
// @ts-ignore
|
62
|
+
delete context.utils.Coin;
|
63
|
+
}
|
64
|
+
return [
|
65
|
+
{
|
66
|
+
type: exports.TYPE,
|
67
|
+
localname,
|
68
|
+
body,
|
69
|
+
},
|
70
|
+
];
|
71
|
+
}
|
72
|
+
}
|
73
|
+
exports.MessageComposerPlugin = MessageComposerPlugin;
|
@@ -0,0 +1,77 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
|
+
};
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
+
exports.BuilderPluginBase = void 0;
|
30
|
+
const mkdirp_1 = require("mkdirp");
|
31
|
+
const path_1 = require("path");
|
32
|
+
const fs_1 = require("fs");
|
33
|
+
const header_1 = require("../utils/header");
|
34
|
+
const generator_1 = __importDefault(require("@babel/generator"));
|
35
|
+
const t = __importStar(require("@babel/types"));
|
36
|
+
/**
|
37
|
+
* BuilderPluginBase enable ts-codegen users implement their own plugins by only implement a few functions.
|
38
|
+
*/
|
39
|
+
class BuilderPluginBase {
|
40
|
+
builder;
|
41
|
+
option;
|
42
|
+
utils;
|
43
|
+
constructor(opt, builder) {
|
44
|
+
this.option = opt;
|
45
|
+
this.builder = builder;
|
46
|
+
}
|
47
|
+
setBuilder(builder) {
|
48
|
+
this.builder = builder;
|
49
|
+
}
|
50
|
+
async render(name, contractInfo, outPath) {
|
51
|
+
const { enabled } = this.option;
|
52
|
+
if (!enabled) {
|
53
|
+
return;
|
54
|
+
}
|
55
|
+
const context = this.initContext(contractInfo, this.option);
|
56
|
+
const results = await this.doRender(name, context);
|
57
|
+
if (!results || !results.length) {
|
58
|
+
return [];
|
59
|
+
}
|
60
|
+
return results.map((result) => {
|
61
|
+
const imports = context.getImports(this.utils, result.localname);
|
62
|
+
// @ts-ignore
|
63
|
+
const code = header_1.header + (0, generator_1.default)(t.program([...imports, ...result.body])).code;
|
64
|
+
(0, mkdirp_1.sync)(outPath);
|
65
|
+
const filename = (0, path_1.join)(outPath, result.localname);
|
66
|
+
(0, fs_1.writeFileSync)(filename, code);
|
67
|
+
return {
|
68
|
+
type: result.type,
|
69
|
+
pluginType: result.pluginType,
|
70
|
+
contract: name,
|
71
|
+
localname: result.localname,
|
72
|
+
filename,
|
73
|
+
};
|
74
|
+
});
|
75
|
+
}
|
76
|
+
}
|
77
|
+
exports.BuilderPluginBase = BuilderPluginBase;
|
@@ -0,0 +1,85 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
+
exports.ContractsProviderBundlePlugin = void 0;
|
27
|
+
const case_1 = require("case");
|
28
|
+
const w = __importStar(require("wasm-ast-types"));
|
29
|
+
const wasm_ast_types_1 = require("wasm-ast-types");
|
30
|
+
const plugin_base_1 = require("./plugin-base");
|
31
|
+
const provider_1 = require("./provider");
|
32
|
+
class ContractsProviderBundlePlugin extends plugin_base_1.BuilderPluginBase {
|
33
|
+
constructor(opt) {
|
34
|
+
super(opt);
|
35
|
+
this.utils = {
|
36
|
+
CosmWasmClient: "@cosmjs/cosmwasm-stargate",
|
37
|
+
SigningCosmWasmClient: "@cosmjs/cosmwasm-stargate",
|
38
|
+
IQueryClientProvider: "__contractContextBase__",
|
39
|
+
ISigningClientProvider: "__contractContextBase__",
|
40
|
+
IMessageComposerProvider: "__contractContextBase__",
|
41
|
+
};
|
42
|
+
}
|
43
|
+
initContext(contract, options) {
|
44
|
+
return new wasm_ast_types_1.RenderContext(contract, options, this.builder.builderContext);
|
45
|
+
}
|
46
|
+
async doRender(name, context) {
|
47
|
+
if (!this.option?.useContractsHooks?.enabled) {
|
48
|
+
return;
|
49
|
+
}
|
50
|
+
const providerInfos = context.getProviderInfos();
|
51
|
+
if (!Object.keys(providerInfos || {})?.length) {
|
52
|
+
return;
|
53
|
+
}
|
54
|
+
const localname = "contractContextProviders.ts";
|
55
|
+
const body = [];
|
56
|
+
context.addUtil("CosmWasmClient");
|
57
|
+
context.addUtil("SigningCosmWasmClient");
|
58
|
+
context.addUtil("IQueryClientProvider");
|
59
|
+
context.addUtil("ISigningClientProvider");
|
60
|
+
context.addUtil("IMessageComposerProvider");
|
61
|
+
for (const name in providerInfos) {
|
62
|
+
if (Object.prototype.hasOwnProperty.call(providerInfos, name)) {
|
63
|
+
const providerInfo = providerInfos[name];
|
64
|
+
for (const key in providerInfo) {
|
65
|
+
if (Object.prototype.hasOwnProperty.call(providerInfo, key)) {
|
66
|
+
const info = providerInfo[key];
|
67
|
+
body.push(w.importStmt([info.classname], `./${info.basename}`));
|
68
|
+
}
|
69
|
+
}
|
70
|
+
body.push(w.importStmt([(0, case_1.pascal)(name)], `./${(0, provider_1.GetLocalBaseNameByContractName)(name)}`));
|
71
|
+
}
|
72
|
+
}
|
73
|
+
body.push(w.createIContractsContext(providerInfos));
|
74
|
+
body.push(w.createGettingProviders(providerInfos));
|
75
|
+
return [
|
76
|
+
{
|
77
|
+
type: "plugin",
|
78
|
+
pluginType: "contractContextProviders",
|
79
|
+
localname,
|
80
|
+
body,
|
81
|
+
},
|
82
|
+
];
|
83
|
+
}
|
84
|
+
}
|
85
|
+
exports.ContractsProviderBundlePlugin = ContractsProviderBundlePlugin;
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import { ContractInfo, RenderContextBase, RenderContext } from "wasm-ast-types";
|
2
2
|
import { BuilderFileType, TSBuilderOptions } from "../builder";
|
3
3
|
import { BuilderPluginBase } from "./plugin-base";
|
4
|
-
export declare const GetLocalNameByContractName: (name:
|
5
|
-
export declare const GetLocalBaseNameByContractName: (name:
|
4
|
+
export declare const GetLocalNameByContractName: (name: string) => string;
|
5
|
+
export declare const GetLocalBaseNameByContractName: (name: string) => string;
|
6
6
|
export declare class ContractsContextProviderPlugin extends BuilderPluginBase<TSBuilderOptions> {
|
7
7
|
constructor(opt: TSBuilderOptions);
|
8
8
|
initContext(contract: ContractInfo, options?: TSBuilderOptions): RenderContextBase<TSBuilderOptions>;
|
@@ -0,0 +1,102 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
+
exports.ContractsContextProviderPlugin = exports.GetLocalBaseNameByContractName = exports.GetLocalNameByContractName = void 0;
|
27
|
+
const case_1 = require("case");
|
28
|
+
const w = __importStar(require("wasm-ast-types"));
|
29
|
+
const wasm_ast_types_1 = require("wasm-ast-types");
|
30
|
+
const plugin_base_1 = require("./plugin-base");
|
31
|
+
const GetLocalNameByContractName = (name) => `${(0, case_1.pascal)(name)}.provider.ts`;
|
32
|
+
exports.GetLocalNameByContractName = GetLocalNameByContractName;
|
33
|
+
const GetLocalBaseNameByContractName = (name) => `${(0, case_1.pascal)(name)}.provider`;
|
34
|
+
exports.GetLocalBaseNameByContractName = GetLocalBaseNameByContractName;
|
35
|
+
class ContractsContextProviderPlugin extends plugin_base_1.BuilderPluginBase {
|
36
|
+
constructor(opt) {
|
37
|
+
super(opt);
|
38
|
+
this.utils = {
|
39
|
+
ContractBase: "__contractContextBase__",
|
40
|
+
IContractConstructor: "__contractContextBase__",
|
41
|
+
IEmptyClient: "__contractContextBase__",
|
42
|
+
};
|
43
|
+
}
|
44
|
+
initContext(contract, options) {
|
45
|
+
return new wasm_ast_types_1.RenderContext(contract, options, this.builder.builderContext);
|
46
|
+
}
|
47
|
+
async doRender(name, context) {
|
48
|
+
if (!this.option?.useContractsHooks?.enabled) {
|
49
|
+
return;
|
50
|
+
}
|
51
|
+
const providerInfo = context.getProviderInfos()[name];
|
52
|
+
if (!Object.keys(providerInfo || {})?.length) {
|
53
|
+
return;
|
54
|
+
}
|
55
|
+
context.addUtil("ContractBase");
|
56
|
+
context.addUtil("IContractConstructor");
|
57
|
+
const localname = (0, exports.GetLocalNameByContractName)(name);
|
58
|
+
let needEmptyClientType = false;
|
59
|
+
let clientFile = null;
|
60
|
+
let clientClasses = [];
|
61
|
+
const body = [];
|
62
|
+
const signClientProviderInfo = providerInfo[w.PROVIDER_TYPES.SIGNING_CLIENT_TYPE];
|
63
|
+
if (signClientProviderInfo) {
|
64
|
+
clientFile = `./${signClientProviderInfo.basename}`;
|
65
|
+
clientClasses.push(signClientProviderInfo.classname);
|
66
|
+
}
|
67
|
+
else {
|
68
|
+
needEmptyClientType = true;
|
69
|
+
}
|
70
|
+
const queryClientProviderInfo = providerInfo[w.PROVIDER_TYPES.QUERY_CLIENT_TYPE];
|
71
|
+
if (queryClientProviderInfo) {
|
72
|
+
clientFile = `./${queryClientProviderInfo.basename}`;
|
73
|
+
clientClasses.push(queryClientProviderInfo.classname);
|
74
|
+
}
|
75
|
+
else {
|
76
|
+
needEmptyClientType = true;
|
77
|
+
}
|
78
|
+
if (clientFile) {
|
79
|
+
body.push(w.importStmt(clientClasses, clientFile));
|
80
|
+
}
|
81
|
+
const messageComposerProviderInfo = providerInfo[w.PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE];
|
82
|
+
if (messageComposerProviderInfo) {
|
83
|
+
body.push(w.importStmt([messageComposerProviderInfo.classname], `./${messageComposerProviderInfo.basename}`));
|
84
|
+
}
|
85
|
+
else {
|
86
|
+
needEmptyClientType = true;
|
87
|
+
}
|
88
|
+
if (needEmptyClientType) {
|
89
|
+
context.addUtil("IEmptyClient");
|
90
|
+
}
|
91
|
+
body.push(w.createProvider(name, providerInfo));
|
92
|
+
return [
|
93
|
+
{
|
94
|
+
type: "plugin",
|
95
|
+
pluginType: "provider",
|
96
|
+
localname,
|
97
|
+
body,
|
98
|
+
},
|
99
|
+
];
|
100
|
+
}
|
101
|
+
}
|
102
|
+
exports.ContractsContextProviderPlugin = ContractsContextProviderPlugin;
|
@@ -0,0 +1,96 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
+
exports.ReactQueryPlugin = void 0;
|
27
|
+
const case_1 = require("case");
|
28
|
+
const w = __importStar(require("wasm-ast-types"));
|
29
|
+
const utils_1 = require("../utils");
|
30
|
+
const wasm_ast_types_1 = require("wasm-ast-types");
|
31
|
+
const plugin_base_1 = require("./plugin-base");
|
32
|
+
class ReactQueryPlugin extends plugin_base_1.BuilderPluginBase {
|
33
|
+
initContext(contract, options) {
|
34
|
+
return new wasm_ast_types_1.RenderContext(contract, options, this.builder.builderContext);
|
35
|
+
}
|
36
|
+
async doRender(name, context) {
|
37
|
+
const options = this.option.reactQuery;
|
38
|
+
const { enabled } = options;
|
39
|
+
if (!enabled) {
|
40
|
+
return;
|
41
|
+
}
|
42
|
+
const { schemas } = context.contract;
|
43
|
+
const localname = (0, case_1.pascal)(`${name}`) + '.react-query.ts';
|
44
|
+
const ContractFile = (0, case_1.pascal)(`${name}`) + '.client';
|
45
|
+
const TypesFile = (0, case_1.pascal)(`${name}`) + '.types';
|
46
|
+
const QueryMsg = (0, utils_1.findQueryMsg)(schemas);
|
47
|
+
const ExecuteMsg = (0, utils_1.findExecuteMsg)(schemas);
|
48
|
+
const typeHash = await (0, utils_1.findAndParseTypes)(schemas);
|
49
|
+
const ExecuteClient = (0, case_1.pascal)(`${name}Client`);
|
50
|
+
const QueryClient = (0, case_1.pascal)(`${name}QueryClient`);
|
51
|
+
const body = [];
|
52
|
+
const clientImports = [];
|
53
|
+
QueryMsg && clientImports.push(QueryClient);
|
54
|
+
// check that there are commands within the exec msg
|
55
|
+
const shouldGenerateMutationHooks = ExecuteMsg &&
|
56
|
+
options?.version === 'v4' &&
|
57
|
+
options?.mutations &&
|
58
|
+
(0, wasm_ast_types_1.getMessageProperties)(ExecuteMsg).length > 0;
|
59
|
+
if (shouldGenerateMutationHooks) {
|
60
|
+
clientImports.push(ExecuteClient);
|
61
|
+
}
|
62
|
+
// general contract imports
|
63
|
+
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
64
|
+
// client imports
|
65
|
+
body.push(w.importStmt(clientImports, `./${ContractFile}`));
|
66
|
+
// query messages
|
67
|
+
if (QueryMsg) {
|
68
|
+
[].push.apply(body, w.createReactQueryHooks({
|
69
|
+
context,
|
70
|
+
queryMsg: QueryMsg,
|
71
|
+
contractName: name,
|
72
|
+
QueryClient
|
73
|
+
}));
|
74
|
+
}
|
75
|
+
if (shouldGenerateMutationHooks) {
|
76
|
+
[].push.apply(body, w.createReactQueryMutationHooks({
|
77
|
+
context,
|
78
|
+
execMsg: ExecuteMsg,
|
79
|
+
contractName: name,
|
80
|
+
ExecuteClient
|
81
|
+
}));
|
82
|
+
}
|
83
|
+
if (typeHash.hasOwnProperty('Coin')) {
|
84
|
+
// @ts-ignore
|
85
|
+
delete context.utils.Coin;
|
86
|
+
}
|
87
|
+
return [
|
88
|
+
{
|
89
|
+
type: 'react-query',
|
90
|
+
localname,
|
91
|
+
body
|
92
|
+
}
|
93
|
+
];
|
94
|
+
}
|
95
|
+
}
|
96
|
+
exports.ReactQueryPlugin = ReactQueryPlugin;
|
@@ -0,0 +1,78 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
+
exports.RecoilPlugin = void 0;
|
27
|
+
const case_1 = require("case");
|
28
|
+
const w = __importStar(require("wasm-ast-types"));
|
29
|
+
const utils_1 = require("../utils");
|
30
|
+
const wasm_ast_types_1 = require("wasm-ast-types");
|
31
|
+
const plugin_base_1 = require("./plugin-base");
|
32
|
+
class RecoilPlugin extends plugin_base_1.BuilderPluginBase {
|
33
|
+
utils = {
|
34
|
+
selectorFamily: 'recoil',
|
35
|
+
};
|
36
|
+
initContext(contract, options) {
|
37
|
+
return new wasm_ast_types_1.RenderContext(contract, options, this.builder.builderContext);
|
38
|
+
}
|
39
|
+
async doRender(name, context) {
|
40
|
+
const { enabled } = this.option.recoil;
|
41
|
+
if (!enabled) {
|
42
|
+
return;
|
43
|
+
}
|
44
|
+
const { schemas } = context.contract;
|
45
|
+
const localname = (0, case_1.pascal)(name) + '.recoil.ts';
|
46
|
+
const ContractFile = (0, case_1.pascal)(name) + '.client';
|
47
|
+
const TypesFile = (0, case_1.pascal)(name) + '.types';
|
48
|
+
const QueryMsg = (0, utils_1.findQueryMsg)(schemas);
|
49
|
+
const typeHash = await (0, utils_1.findAndParseTypes)(schemas);
|
50
|
+
let QueryClient = null;
|
51
|
+
let ReadOnlyInstance = null;
|
52
|
+
const body = [];
|
53
|
+
body.push(w.importStmt(['cosmWasmClient'], './chain'));
|
54
|
+
body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
|
55
|
+
// query messages
|
56
|
+
if (QueryMsg) {
|
57
|
+
QueryClient = (0, case_1.pascal)(`${name}QueryClient`);
|
58
|
+
ReadOnlyInstance = (0, case_1.pascal)(`${name}ReadOnlyInterface`);
|
59
|
+
body.push(w.importStmt([QueryClient], `./${ContractFile}`));
|
60
|
+
body.push(w.createRecoilQueryClientType());
|
61
|
+
body.push(w.createRecoilQueryClient(context, name, QueryClient));
|
62
|
+
const selectors = w.createRecoilSelectors(context, name, QueryClient, QueryMsg);
|
63
|
+
body.push(...selectors);
|
64
|
+
}
|
65
|
+
if (typeHash.hasOwnProperty('Coin')) {
|
66
|
+
// @ts-ignore
|
67
|
+
delete context.utils.Coin;
|
68
|
+
}
|
69
|
+
return [
|
70
|
+
{
|
71
|
+
type: 'recoil',
|
72
|
+
localname,
|
73
|
+
body
|
74
|
+
}
|
75
|
+
];
|
76
|
+
}
|
77
|
+
}
|
78
|
+
exports.RecoilPlugin = RecoilPlugin;
|
package/plugins/types.js
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
+
exports.TypesPlugin = void 0;
|
27
|
+
const t = __importStar(require("@babel/types"));
|
28
|
+
const clean_1 = require("../utils/clean");
|
29
|
+
const case_1 = require("case");
|
30
|
+
const utils_1 = require("../utils");
|
31
|
+
const wasm_ast_types_1 = require("wasm-ast-types");
|
32
|
+
const plugin_base_1 = require("./plugin-base");
|
33
|
+
class TypesPlugin extends plugin_base_1.BuilderPluginBase {
|
34
|
+
initContext(contract, options) {
|
35
|
+
return new wasm_ast_types_1.RenderContext(contract, options, this.builder.builderContext);
|
36
|
+
}
|
37
|
+
async doRender(name, context) {
|
38
|
+
const { enabled } = this.option.types;
|
39
|
+
if (!enabled) {
|
40
|
+
return;
|
41
|
+
}
|
42
|
+
const { schemas } = context.contract;
|
43
|
+
const options = this.option.types;
|
44
|
+
const localname = (0, case_1.pascal)(name) + '.types.ts';
|
45
|
+
const ExecuteMsg = (0, utils_1.findExecuteMsg)(schemas);
|
46
|
+
const typeHash = await (0, utils_1.findAndParseTypes)(schemas);
|
47
|
+
const body = [];
|
48
|
+
// TYPES
|
49
|
+
Object.values(typeHash).forEach((type) => {
|
50
|
+
body.push((0, clean_1.clean)(type));
|
51
|
+
});
|
52
|
+
// alias the ExecuteMsg
|
53
|
+
if (options.aliasExecuteMsg && ExecuteMsg) {
|
54
|
+
body.push(t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(`${name}ExecuteMsg`), null, t.tsTypeReference(t.identifier('ExecuteMsg')))));
|
55
|
+
}
|
56
|
+
return [
|
57
|
+
{
|
58
|
+
type: 'type',
|
59
|
+
localname,
|
60
|
+
body
|
61
|
+
}
|
62
|
+
];
|
63
|
+
}
|
64
|
+
}
|
65
|
+
exports.TypesPlugin = TypesPlugin;
|