@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/ts-codegen.js
ADDED
package/utils/clean.js
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.clean = void 0;
|
4
|
+
const clean = (obj) => {
|
5
|
+
var copy;
|
6
|
+
// Handle the 3 simple types, and null or undefined
|
7
|
+
if (null == obj || 'object' != typeof obj)
|
8
|
+
return obj;
|
9
|
+
// Handle Date
|
10
|
+
if (obj instanceof Date) {
|
11
|
+
copy = new Date();
|
12
|
+
copy.setTime(obj.getTime());
|
13
|
+
return copy;
|
14
|
+
}
|
15
|
+
// Handle Array
|
16
|
+
if (obj instanceof Array) {
|
17
|
+
copy = [];
|
18
|
+
for (var i = 0, len = obj.length; i < len; i++) {
|
19
|
+
copy[i] = (0, exports.clean)(obj[i]);
|
20
|
+
}
|
21
|
+
return copy;
|
22
|
+
}
|
23
|
+
// Handle Object
|
24
|
+
if (obj instanceof Object || typeof obj === 'object') {
|
25
|
+
copy = {};
|
26
|
+
for (var attr in obj) {
|
27
|
+
if (obj.hasOwnProperty(attr)) {
|
28
|
+
switch (attr) {
|
29
|
+
case 'leadingComments':
|
30
|
+
case 'trailingComments':
|
31
|
+
case 'loc':
|
32
|
+
case 'start':
|
33
|
+
case 'end':
|
34
|
+
break;
|
35
|
+
default:
|
36
|
+
// @ts-ignore
|
37
|
+
copy[attr] = (0, exports.clean)(obj[attr]);
|
38
|
+
}
|
39
|
+
}
|
40
|
+
else {
|
41
|
+
// @ts-ignore
|
42
|
+
copy[attr] = (0, exports.clean)(obj[attr]);
|
43
|
+
}
|
44
|
+
}
|
45
|
+
return copy;
|
46
|
+
}
|
47
|
+
throw new Error("Unable to copy obj! Its type isn't supported.");
|
48
|
+
};
|
49
|
+
exports.clean = clean;
|
package/utils/cleanse.js
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.cleanse = void 0;
|
4
|
+
const case_1 = require("case");
|
5
|
+
const cleanFor = (str) => {
|
6
|
+
/*
|
7
|
+
1. look at first char after _for_
|
8
|
+
2. ONLY if you find capitals after, modify it
|
9
|
+
*/
|
10
|
+
while (/_[a-z]+_[A-Z]/.test(str)) {
|
11
|
+
const m = str.match(/(_[a-z]+_)[A-Z]/);
|
12
|
+
str = str.replace(m[1], (0, case_1.pascal)(m[1]));
|
13
|
+
}
|
14
|
+
return str;
|
15
|
+
};
|
16
|
+
const cleanNullable = (str) => {
|
17
|
+
if (/^Nullable_/.test(str)) {
|
18
|
+
str = str.replace(/^Nullable_/, 'Nullable');
|
19
|
+
}
|
20
|
+
return str;
|
21
|
+
};
|
22
|
+
const cleanse = (obj) => {
|
23
|
+
var copy;
|
24
|
+
// Handle the 3 simple types, and null or undefined
|
25
|
+
if (null == obj || 'object' != typeof obj)
|
26
|
+
return obj;
|
27
|
+
// Handle Date
|
28
|
+
if (obj instanceof Date) {
|
29
|
+
copy = new Date();
|
30
|
+
copy.setTime(obj.getTime());
|
31
|
+
return copy;
|
32
|
+
}
|
33
|
+
// Handle Array
|
34
|
+
if (obj instanceof Array) {
|
35
|
+
copy = [];
|
36
|
+
for (var i = 0, len = obj.length; i < len; i++) {
|
37
|
+
copy[i] = (0, exports.cleanse)(obj[i]);
|
38
|
+
}
|
39
|
+
return copy;
|
40
|
+
}
|
41
|
+
// Handle Object
|
42
|
+
if (obj instanceof Object || typeof obj === 'object') {
|
43
|
+
copy = {};
|
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
|
+
// @ts-ignore
|
55
|
+
copy[cleanFor(attr)] = (0, exports.cleanse)(obj[attr]);
|
56
|
+
}
|
57
|
+
else if (/^Nullable_/.test(attr)) {
|
58
|
+
// @ts-ignore
|
59
|
+
copy[cleanNullable(attr)] = (0, exports.cleanse)(obj[attr]);
|
60
|
+
}
|
61
|
+
else {
|
62
|
+
switch (attr) {
|
63
|
+
case 'title':
|
64
|
+
case '$ref':
|
65
|
+
if (typeof obj[attr] === 'string') {
|
66
|
+
// @ts-ignore
|
67
|
+
copy[attr] = (0, exports.cleanse)(cleanNullable(cleanFor(obj[attr])));
|
68
|
+
}
|
69
|
+
else {
|
70
|
+
// @ts-ignore
|
71
|
+
copy[attr] = (0, exports.cleanse)(obj[attr]);
|
72
|
+
}
|
73
|
+
break;
|
74
|
+
default:
|
75
|
+
// @ts-ignore
|
76
|
+
copy[attr] = (0, exports.cleanse)(obj[attr]);
|
77
|
+
}
|
78
|
+
}
|
79
|
+
}
|
80
|
+
else {
|
81
|
+
// @ts-ignore
|
82
|
+
copy[attr] = (0, exports.cleanse)(obj[attr]);
|
83
|
+
}
|
84
|
+
}
|
85
|
+
return copy;
|
86
|
+
}
|
87
|
+
throw new Error("Unable to copy obj! Its type isn't supported.");
|
88
|
+
};
|
89
|
+
exports.cleanse = cleanse;
|
package/utils/files.js
ADDED
@@ -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
|
+
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.writeContentToFile = exports.writeAstToFile = void 0;
|
30
|
+
const t = __importStar(require("@babel/types"));
|
31
|
+
const parser_1 = require("@babel/parser");
|
32
|
+
const mkdirp_1 = require("mkdirp");
|
33
|
+
const fs_1 = require("fs");
|
34
|
+
const path_1 = require("path");
|
35
|
+
const generator_1 = __importDefault(require("@babel/generator"));
|
36
|
+
const unused_1 = require("./unused");
|
37
|
+
const traverse_1 = __importDefault(require("@babel/traverse"));
|
38
|
+
const writeAstToFile = (outPath, program, filename, removeUnusedImports = false, isTsDisable = false, isEslintDisable = false) => {
|
39
|
+
const ast = t.program(program);
|
40
|
+
const content = (0, generator_1.default)(ast).code;
|
41
|
+
if (removeUnusedImports) {
|
42
|
+
const plugins = ["typescript"];
|
43
|
+
const newAst = (0, parser_1.parse)(content, {
|
44
|
+
sourceType: "module",
|
45
|
+
plugins,
|
46
|
+
});
|
47
|
+
(0, traverse_1.default)(newAst, unused_1.unused);
|
48
|
+
const content2 = (0, generator_1.default)(newAst).code;
|
49
|
+
(0, exports.writeContentToFile)(outPath, content2, filename, isTsDisable, isEslintDisable);
|
50
|
+
}
|
51
|
+
else {
|
52
|
+
(0, exports.writeContentToFile)(outPath, content, filename, isTsDisable, isEslintDisable);
|
53
|
+
}
|
54
|
+
};
|
55
|
+
exports.writeAstToFile = writeAstToFile;
|
56
|
+
const writeContentToFile = (outPath, content, filename, isTsDisable = false, isEslintDisable = false) => {
|
57
|
+
let esLintPrefix = "";
|
58
|
+
let tsLintPrefix = "";
|
59
|
+
let nameWithoutPath = filename.replace(outPath, "");
|
60
|
+
// strip off leading slash
|
61
|
+
if (nameWithoutPath.startsWith("/"))
|
62
|
+
nameWithoutPath = nameWithoutPath.replace(/^\//, "");
|
63
|
+
if (isTsDisable) {
|
64
|
+
tsLintPrefix = `//@ts-nocheck\n`;
|
65
|
+
}
|
66
|
+
if (isEslintDisable) {
|
67
|
+
esLintPrefix = `/* eslint-disable */\n`;
|
68
|
+
}
|
69
|
+
const text = tsLintPrefix + esLintPrefix + content;
|
70
|
+
(0, mkdirp_1.sync)((0, path_1.dirname)(filename));
|
71
|
+
(0, fs_1.writeFileSync)(filename, text);
|
72
|
+
};
|
73
|
+
exports.writeContentToFile = writeContentToFile;
|
package/utils/header.js
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.header = void 0;
|
7
|
+
const package_json_1 = __importDefault(require("../../package.json"));
|
8
|
+
const version = process.env.NODE_ENV === 'test' ? 'latest' : package_json_1.default.version;
|
9
|
+
exports.header = `/**
|
10
|
+
* This file was automatically generated by ${package_json_1.default.name}@${version}.
|
11
|
+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
12
|
+
* and run the ${package_json_1.default.name} generate command to regenerate this file.
|
13
|
+
*/
|
14
|
+
\n`;
|
package/utils/index.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export * from './schemas';
|
package/utils/index.js
ADDED
@@ -0,0 +1,17 @@
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./schemas"), exports);
|
package/utils/parse.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export declare const parser: (codes: string[]) => Record<string, any>;
|
package/utils/parse.js
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.parser = void 0;
|
7
|
+
const traverse_1 = __importDefault(require("@babel/traverse"));
|
8
|
+
const parser_1 = require("@babel/parser");
|
9
|
+
const parser = (codes) => {
|
10
|
+
const hash = {};
|
11
|
+
codes.forEach(code => {
|
12
|
+
const plugins = [
|
13
|
+
'typescript',
|
14
|
+
];
|
15
|
+
const ast = (0, parser_1.parse)(code, {
|
16
|
+
sourceType: 'module',
|
17
|
+
plugins
|
18
|
+
});
|
19
|
+
const visitor = visitorFn({
|
20
|
+
addType(key, node) {
|
21
|
+
hash[key] = node;
|
22
|
+
}
|
23
|
+
});
|
24
|
+
(0, traverse_1.default)(ast, visitor);
|
25
|
+
});
|
26
|
+
return hash;
|
27
|
+
};
|
28
|
+
exports.parser = parser;
|
29
|
+
const visitorFn = (parser) => ({
|
30
|
+
TSTypeAliasDeclaration(path) {
|
31
|
+
parser.addType(path.node.id.name, path.parentPath.node);
|
32
|
+
// if (path.node.id.name.endsWith('For_Empty')) {
|
33
|
+
// const newName = path.node.id.name.replace(/For_Empty$/, '_for_Empty');
|
34
|
+
// path.parentPath.node.declaration.id.name = newName;
|
35
|
+
// parser.addType(newName, path.parentPath.node);
|
36
|
+
// } else {
|
37
|
+
// parser.addType(path.node.id.name, path.parentPath.node);
|
38
|
+
// }
|
39
|
+
},
|
40
|
+
TSInterfaceDeclaration(path) {
|
41
|
+
parser.addType(path.node.id.name, path.parentPath.node);
|
42
|
+
}
|
43
|
+
});
|
@@ -0,0 +1,3 @@
|
|
1
|
+
export declare const getFuzzySearch: (list: any) => (answers: any, input: any) => Promise<unknown>;
|
2
|
+
export declare const getFuzzySearchNames: (nameValueItemList: any) => (answers: any, input: any) => Promise<unknown>;
|
3
|
+
export declare const prompt: (questions?: any[], argv?: {}) => Promise<any>;
|
package/utils/prompt.js
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.prompt = exports.getFuzzySearchNames = exports.getFuzzySearch = void 0;
|
4
|
+
// @ts-nocheck
|
5
|
+
const fuzzy_1 = require("fuzzy");
|
6
|
+
const inquirerer_1 = require("inquirerer");
|
7
|
+
const getFuzzySearch = (list) => {
|
8
|
+
return (answers, input) => {
|
9
|
+
input = input || '';
|
10
|
+
return new Promise(function (resolve) {
|
11
|
+
setTimeout(function () {
|
12
|
+
const fuzzyResult = (0, fuzzy_1.filter)(input, list);
|
13
|
+
resolve(fuzzyResult.map(function (el) {
|
14
|
+
return el.original;
|
15
|
+
}));
|
16
|
+
}, 25);
|
17
|
+
});
|
18
|
+
};
|
19
|
+
};
|
20
|
+
exports.getFuzzySearch = getFuzzySearch;
|
21
|
+
const getFuzzySearchNames = (nameValueItemList) => {
|
22
|
+
const list = nameValueItemList.map(({ name, value }) => name);
|
23
|
+
return (answers, input) => {
|
24
|
+
input = input || '';
|
25
|
+
return new Promise(function (resolve) {
|
26
|
+
setTimeout(function () {
|
27
|
+
const fuzzyResult = (0, fuzzy_1.filter)(input, list);
|
28
|
+
resolve(fuzzyResult.map(function (el) {
|
29
|
+
return nameValueItemList.find(({ name, value }) => el.original == name);
|
30
|
+
}));
|
31
|
+
}, 25);
|
32
|
+
});
|
33
|
+
};
|
34
|
+
};
|
35
|
+
exports.getFuzzySearchNames = getFuzzySearchNames;
|
36
|
+
const transform = (questions) => {
|
37
|
+
return questions.map((q) => {
|
38
|
+
if (q.type === 'fuzzy') {
|
39
|
+
const choices = q.choices;
|
40
|
+
delete q.choices;
|
41
|
+
return {
|
42
|
+
...q,
|
43
|
+
type: 'autocomplete',
|
44
|
+
source: (0, exports.getFuzzySearch)(choices)
|
45
|
+
};
|
46
|
+
}
|
47
|
+
else if (q.type === 'fuzzy:objects') {
|
48
|
+
const choices = q.choices;
|
49
|
+
delete q.choices;
|
50
|
+
return {
|
51
|
+
...q,
|
52
|
+
type: 'autocomplete',
|
53
|
+
source: (0, exports.getFuzzySearchNames)(choices)
|
54
|
+
};
|
55
|
+
}
|
56
|
+
else {
|
57
|
+
return q;
|
58
|
+
}
|
59
|
+
});
|
60
|
+
};
|
61
|
+
const prompt = async (questions = [], argv = {}) => {
|
62
|
+
questions = transform(questions);
|
63
|
+
return await (0, inquirerer_1.prompt)(questions, argv);
|
64
|
+
};
|
65
|
+
exports.prompt = prompt;
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { ContractInfo } from 'wasm-ast-types';
|
2
|
+
import { ExecuteMsg, JSONSchema, QueryMsg } from '@cosmology/ts-codegen-types';
|
3
|
+
interface ReadSchemaOpts {
|
4
|
+
schemaDir: string;
|
5
|
+
clean?: boolean;
|
6
|
+
}
|
7
|
+
export declare const readSchemas: ({ schemaDir, clean }: ReadSchemaOpts) => Promise<ContractInfo>;
|
8
|
+
export declare const findQueryMsg: (schemas: JSONSchema[]) => QueryMsg;
|
9
|
+
export declare const findExecuteMsg: (schemas: JSONSchema[]) => ExecuteMsg;
|
10
|
+
export declare const findAndParseTypes: (schemas: JSONSchema[]) => Promise<Record<string, any>>;
|
11
|
+
export {};
|
package/utils/schemas.js
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.findAndParseTypes = exports.findExecuteMsg = exports.findQueryMsg = exports.readSchemas = void 0;
|
4
|
+
const glob_1 = require("glob");
|
5
|
+
const fs_1 = require("fs");
|
6
|
+
const cleanse_1 = require("./cleanse");
|
7
|
+
const json_schema_to_typescript_1 = require("@pyramation/json-schema-to-typescript");
|
8
|
+
const parse_1 = require("./parse");
|
9
|
+
;
|
10
|
+
const readSchemas = async ({ schemaDir, clean = true }) => {
|
11
|
+
const fn = clean ? cleanse_1.cleanse : (schema) => schema;
|
12
|
+
const files = (0, glob_1.sync)(schemaDir + '/**/*.json')
|
13
|
+
.filter(file => !file.match(/\/raw\//));
|
14
|
+
const schemas = files
|
15
|
+
.map(file => JSON.parse((0, fs_1.readFileSync)(file, 'utf-8')));
|
16
|
+
if (schemas.length > 1) {
|
17
|
+
// legacy
|
18
|
+
// TODO add console.warn here
|
19
|
+
return {
|
20
|
+
schemas: fn(schemas)
|
21
|
+
};
|
22
|
+
}
|
23
|
+
if (schemas.length === 0) {
|
24
|
+
throw new Error('Error [too few files]: requires one schema file per contract');
|
25
|
+
}
|
26
|
+
if (schemas.length !== 1) {
|
27
|
+
throw new Error('Error [too many files]: CosmWasm v1.1 schemas supports one file');
|
28
|
+
}
|
29
|
+
const idlObject = schemas[0];
|
30
|
+
const { contract_name, contract_version, idl_version, responses, instantiate, execute, query, migrate, sudo } = idlObject;
|
31
|
+
if (typeof idl_version !== 'string') {
|
32
|
+
// legacy
|
33
|
+
return {
|
34
|
+
schemas: fn(schemas)
|
35
|
+
};
|
36
|
+
}
|
37
|
+
// TODO use contract_name, etc.
|
38
|
+
const idl = {
|
39
|
+
instantiate,
|
40
|
+
execute,
|
41
|
+
query,
|
42
|
+
migrate,
|
43
|
+
sudo
|
44
|
+
};
|
45
|
+
return {
|
46
|
+
schemas: [
|
47
|
+
...Object.values(fn(idl)).filter(Boolean),
|
48
|
+
...Object.values(fn({ ...responses })).filter(Boolean)
|
49
|
+
],
|
50
|
+
responses,
|
51
|
+
idlObject
|
52
|
+
};
|
53
|
+
};
|
54
|
+
exports.readSchemas = readSchemas;
|
55
|
+
const findQueryMsg = (schemas) => {
|
56
|
+
const queryMsg = schemas.find(schema => schema.title === 'QueryMsg');
|
57
|
+
return queryMsg;
|
58
|
+
};
|
59
|
+
exports.findQueryMsg = findQueryMsg;
|
60
|
+
const findExecuteMsg = (schemas) => {
|
61
|
+
const executeMsg = schemas.find(schema => schema.title.startsWith('ExecuteMsg'));
|
62
|
+
return executeMsg;
|
63
|
+
};
|
64
|
+
exports.findExecuteMsg = findExecuteMsg;
|
65
|
+
const findAndParseTypes = async (schemas) => {
|
66
|
+
const Types = schemas;
|
67
|
+
const allTypes = [];
|
68
|
+
for (const typ in Types) {
|
69
|
+
if (Types[typ].definitions) {
|
70
|
+
for (const key of Object.keys(Types[typ].definitions)) {
|
71
|
+
// set title
|
72
|
+
Types[typ].definitions[key].title = key;
|
73
|
+
}
|
74
|
+
}
|
75
|
+
const result = await (0, json_schema_to_typescript_1.compile)(Types[typ], Types[typ].title);
|
76
|
+
allTypes.push(result);
|
77
|
+
}
|
78
|
+
const typeHash = (0, parse_1.parser)(allTypes);
|
79
|
+
return typeHash;
|
80
|
+
};
|
81
|
+
exports.findAndParseTypes = findAndParseTypes;
|
package/utils/unused.js
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
"use strict";
|
2
|
+
//@ts-nocheck
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
4
|
+
if (k2 === undefined) k2 = k;
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
8
|
+
}
|
9
|
+
Object.defineProperty(o, k2, desc);
|
10
|
+
}) : (function(o, m, k, k2) {
|
11
|
+
if (k2 === undefined) k2 = k;
|
12
|
+
o[k2] = m[k];
|
13
|
+
}));
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
16
|
+
}) : function(o, v) {
|
17
|
+
o["default"] = v;
|
18
|
+
});
|
19
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
20
|
+
if (mod && mod.__esModule) return mod;
|
21
|
+
var result = {};
|
22
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
23
|
+
__setModuleDefault(result, mod);
|
24
|
+
return result;
|
25
|
+
};
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
27
|
+
exports.unused = void 0;
|
28
|
+
const t = __importStar(require("@babel/types"));
|
29
|
+
// https://github.com/chuyik/babel-plugin-danger-remove-unused-import
|
30
|
+
// https://github.com/chuyik/babel-plugin-danger-remove-unused-import/blob/c5454c21e94698a2464a12baa5590761932a71a8/License#L1
|
31
|
+
exports.unused = {
|
32
|
+
Program: {
|
33
|
+
exit: (path) => {
|
34
|
+
const UnRefBindings = new Map();
|
35
|
+
for (const [name, binding] of Object.entries(path.scope.bindings)) {
|
36
|
+
if (!binding.path.parentPath || binding.kind !== 'module')
|
37
|
+
continue;
|
38
|
+
const source = binding.path.parentPath.get('source');
|
39
|
+
const importName = source.node.value;
|
40
|
+
if (!t.isStringLiteral(source))
|
41
|
+
continue;
|
42
|
+
const key = `${importName}(${source.node.loc &&
|
43
|
+
source.node.loc.start.line})`;
|
44
|
+
if (!UnRefBindings.has(key)) {
|
45
|
+
UnRefBindings.set(key, binding);
|
46
|
+
}
|
47
|
+
if (binding.referenced) {
|
48
|
+
UnRefBindings.set(key, null);
|
49
|
+
}
|
50
|
+
else {
|
51
|
+
const nodeType = binding.path.node.type;
|
52
|
+
if (nodeType === 'ImportSpecifier') {
|
53
|
+
binding.path.remove();
|
54
|
+
}
|
55
|
+
else if (nodeType === 'ImportDefaultSpecifier') {
|
56
|
+
binding.path.remove();
|
57
|
+
}
|
58
|
+
else if (nodeType === 'ImportNamespaceSpecifier') {
|
59
|
+
binding.path.remove();
|
60
|
+
}
|
61
|
+
else if (binding.path.parentPath) {
|
62
|
+
binding.path.parentPath.remove();
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}
|
66
|
+
UnRefBindings.forEach((binding, key) => {
|
67
|
+
if (binding && binding.path.parentPath) {
|
68
|
+
binding.path.parentPath.remove();
|
69
|
+
}
|
70
|
+
});
|
71
|
+
}
|
72
|
+
}
|
73
|
+
};
|