@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.
Files changed (250) hide show
  1. package/LICENSE-Apache +201 -0
  2. package/LICENSE-MIT +21 -0
  3. package/README.md +106 -101
  4. package/{types/src/builder → builder}/builder.d.ts +2 -2
  5. package/builder/builder.js +172 -0
  6. package/builder/index.js +17 -0
  7. package/bundler/bundler.d.ts +8 -0
  8. package/bundler/bundler.js +79 -0
  9. package/bundler/index.js +17 -0
  10. package/cli.d.ts +2 -0
  11. package/cli.js +24 -0
  12. package/cmds.d.ts +2 -0
  13. package/cmds.js +14 -0
  14. package/commands/create-boilerplate.d.ts +3 -0
  15. package/commands/create-boilerplate.js +132 -0
  16. package/commands/generate.d.ts +3 -0
  17. package/commands/generate.js +175 -0
  18. package/commands/install.d.ts +3 -0
  19. package/commands/install.js +107 -0
  20. package/{src/builder/builder.ts → esm/builder/builder.js} +39 -139
  21. package/esm/builder/index.js +1 -0
  22. package/esm/bundler/bundler.js +47 -0
  23. package/esm/bundler/index.js +1 -0
  24. package/esm/cli.js +20 -0
  25. package/{src → esm}/cmds.js +0 -1
  26. package/{src/commands/create-boilerplate.ts → esm/commands/create-boilerplate.js} +35 -70
  27. package/{src/commands/generate.ts → esm/commands/generate.js} +19 -24
  28. package/{src/commands/install.ts → esm/commands/install.js} +22 -35
  29. package/esm/file.js +18 -0
  30. package/esm/generators/client.js +67 -0
  31. package/esm/generators/create-helpers.js +36 -0
  32. package/esm/generators/message-builder.js +58 -0
  33. package/esm/generators/message-composer.js +55 -0
  34. package/esm/generators/react-query.js +76 -0
  35. package/esm/generators/recoil.js +58 -0
  36. package/esm/generators/types.js +58 -0
  37. package/{src/index.ts → esm/index.js} +4 -6
  38. package/esm/plugins/client.js +59 -0
  39. package/esm/plugins/message-builder.js +52 -0
  40. package/esm/plugins/message-composer.js +46 -0
  41. package/esm/plugins/plugin-base.js +47 -0
  42. package/esm/plugins/provider-bundle.js +58 -0
  43. package/esm/plugins/provider.js +73 -0
  44. package/esm/plugins/react-query.js +69 -0
  45. package/esm/plugins/recoil.js +51 -0
  46. package/esm/plugins/types.js +38 -0
  47. package/{src → esm}/ts-codegen.js +1 -2
  48. package/{src/utils/clean.ts → esm/utils/clean.js} +7 -7
  49. package/{src/utils/cleanse.ts → esm/utils/cleanse.js} +18 -22
  50. package/esm/utils/files.js +42 -0
  51. package/{src/utils/parse.ts → esm/utils/parse.js} +4 -13
  52. package/esm/utils/prompt.js +59 -0
  53. package/{src/utils/schemas.ts → esm/utils/schemas.js} +16 -44
  54. package/esm/utils/unused.js +47 -0
  55. package/file.js +20 -0
  56. package/generators/client.js +95 -0
  57. package/generators/create-helpers.js +43 -0
  58. package/generators/message-builder.js +86 -0
  59. package/generators/message-composer.js +83 -0
  60. package/generators/react-query.js +104 -0
  61. package/generators/recoil.js +86 -0
  62. package/generators/types.js +86 -0
  63. package/{module/helpers → helpers}/contractContextBase.js +5 -2
  64. package/{module/helpers → helpers}/contractContextBaseShortHandCtor.js +5 -2
  65. package/{module/helpers → helpers}/contractsContextTSX.js +5 -2
  66. package/{module/helpers/index.js → helpers/index.d.ts} +1 -1
  67. package/helpers/index.js +19 -0
  68. package/{types/src/index.d.ts → index.d.ts} +1 -0
  69. package/index.js +41 -0
  70. package/package.json +28 -63
  71. package/plugins/client.js +86 -0
  72. package/plugins/index.d.ts +1 -0
  73. package/plugins/index.js +17 -0
  74. package/plugins/message-builder.js +79 -0
  75. package/plugins/message-composer.js +73 -0
  76. package/{types/src/plugins → plugins}/plugin-base.d.ts +1 -1
  77. package/plugins/plugin-base.js +77 -0
  78. package/plugins/provider-bundle.js +85 -0
  79. package/{types/src/plugins → plugins}/provider.d.ts +2 -2
  80. package/plugins/provider.js +102 -0
  81. package/plugins/react-query.js +96 -0
  82. package/plugins/recoil.js +78 -0
  83. package/plugins/types.js +65 -0
  84. package/ts-codegen.js +8 -0
  85. package/utils/clean.js +49 -0
  86. package/utils/cleanse.js +89 -0
  87. package/utils/files.js +73 -0
  88. package/utils/header.js +14 -0
  89. package/utils/index.d.ts +1 -0
  90. package/utils/index.js +17 -0
  91. package/utils/parse.d.ts +1 -0
  92. package/utils/parse.js +43 -0
  93. package/utils/prompt.d.ts +3 -0
  94. package/utils/prompt.js +65 -0
  95. package/utils/schemas.d.ts +11 -0
  96. package/utils/schemas.js +81 -0
  97. package/utils/unused.js +73 -0
  98. package/main/builder/builder.js +0 -308
  99. package/main/builder/index.js +0 -16
  100. package/main/bundler/bundler.js +0 -61
  101. package/main/bundler/index.js +0 -16
  102. package/main/cli.js +0 -51
  103. package/main/cmds.js +0 -15
  104. package/main/commands/create-boilerplate.js +0 -166
  105. package/main/commands/generate.js +0 -196
  106. package/main/commands/install.js +0 -138
  107. package/main/file.js +0 -35
  108. package/main/generators/client.js +0 -90
  109. package/main/generators/create-helpers.js +0 -38
  110. package/main/generators/message-composer.js +0 -77
  111. package/main/generators/msg-builder.js +0 -84
  112. package/main/generators/react-query.js +0 -102
  113. package/main/generators/recoil.js +0 -81
  114. package/main/generators/types.js +0 -82
  115. package/main/helpers/contractContextBase.js +0 -8
  116. package/main/helpers/contractContextBaseShortHandCtor.js +0 -8
  117. package/main/helpers/contractsContextTSX.js +0 -8
  118. package/main/helpers/index.js +0 -38
  119. package/main/index.js +0 -119
  120. package/main/plugins/client.js +0 -112
  121. package/main/plugins/index.js +0 -16
  122. package/main/plugins/message-builder.js +0 -102
  123. package/main/plugins/message-composer.js +0 -98
  124. package/main/plugins/plugin-base.js +0 -103
  125. package/main/plugins/provider-bundle.js +0 -108
  126. package/main/plugins/provider.js +0 -126
  127. package/main/plugins/react-query.js +0 -120
  128. package/main/plugins/recoil.js +0 -108
  129. package/main/plugins/types.js +0 -89
  130. package/main/ts-codegen.js +0 -20
  131. package/main/utils/clean.js +0 -53
  132. package/main/utils/cleanse.js +0 -87
  133. package/main/utils/files.js +0 -57
  134. package/main/utils/header.js +0 -11
  135. package/main/utils/index.js +0 -16
  136. package/main/utils/parse.js +0 -44
  137. package/main/utils/prompt.js +0 -98
  138. package/main/utils/schemas.js +0 -144
  139. package/main/utils/unused.js +0 -57
  140. package/module/builder/builder.js +0 -143
  141. package/module/builder/index.js +0 -1
  142. package/module/bundler/bundler.js +0 -36
  143. package/module/bundler/index.js +0 -1
  144. package/module/cli.js +0 -19
  145. package/module/cmds.js +0 -8
  146. package/module/commands/create-boilerplate.js +0 -102
  147. package/module/commands/generate.js +0 -163
  148. package/module/commands/install.js +0 -98
  149. package/module/file.js +0 -18
  150. package/module/generators/client.js +0 -65
  151. package/module/generators/create-helpers.js +0 -33
  152. package/module/generators/message-composer.js +0 -52
  153. package/module/generators/msg-builder.js +0 -58
  154. package/module/generators/react-query.js +0 -75
  155. package/module/generators/recoil.js +0 -53
  156. package/module/generators/types.js +0 -55
  157. package/module/index.js +0 -14
  158. package/module/plugins/client.js +0 -63
  159. package/module/plugins/index.js +0 -1
  160. package/module/plugins/message-builder.js +0 -55
  161. package/module/plugins/message-composer.js +0 -49
  162. package/module/plugins/plugin-base.js +0 -66
  163. package/module/plugins/provider-bundle.js +0 -56
  164. package/module/plugins/provider.js +0 -68
  165. package/module/plugins/react-query.js +0 -72
  166. package/module/plugins/recoil.js +0 -57
  167. package/module/plugins/types.js +0 -42
  168. package/module/ts-codegen.js +0 -6
  169. package/module/utils/clean.js +0 -44
  170. package/module/utils/cleanse.js +0 -78
  171. package/module/utils/files.js +0 -40
  172. package/module/utils/header.js +0 -8
  173. package/module/utils/index.js +0 -1
  174. package/module/utils/parse.js +0 -35
  175. package/module/utils/prompt.js +0 -63
  176. package/module/utils/schemas.js +0 -85
  177. package/module/utils/unused.js +0 -43
  178. package/src/builder/index.ts +0 -1
  179. package/src/bundler/bundler.ts +0 -67
  180. package/src/bundler/index.ts +0 -1
  181. package/src/cli.js +0 -21
  182. package/src/file.js +0 -20
  183. package/src/generators/client.ts +0 -109
  184. package/src/generators/create-helpers.ts +0 -71
  185. package/src/generators/message-composer.ts +0 -86
  186. package/src/generators/msg-builder.ts +0 -78
  187. package/src/generators/react-query.ts +0 -102
  188. package/src/generators/recoil.ts +0 -92
  189. package/src/generators/types.ts +0 -94
  190. package/src/helpers/index.ts +0 -3
  191. package/src/plugins/client.ts +0 -124
  192. package/src/plugins/index.ts +0 -1
  193. package/src/plugins/message-builder.ts +0 -85
  194. package/src/plugins/message-composer.ts +0 -89
  195. package/src/plugins/plugin-base.ts +0 -122
  196. package/src/plugins/provider-bundle.ts +0 -98
  197. package/src/plugins/provider.ts +0 -115
  198. package/src/plugins/react-query.ts +0 -115
  199. package/src/plugins/recoil.ts +0 -89
  200. package/src/plugins/types.ts +0 -74
  201. package/src/utils/files.ts +0 -73
  202. package/src/utils/index.ts +0 -1
  203. package/src/utils/prompt.js +0 -65
  204. package/src/utils/unused.ts +0 -52
  205. package/types/src/bundler/bundler.d.ts +0 -4
  206. package/types/src/cli.d.ts +0 -1
  207. package/types/src/cmds.d.ts +0 -1
  208. package/types/src/commands/create-boilerplate.d.ts +0 -2
  209. package/types/src/commands/generate.d.ts +0 -2
  210. package/types/src/commands/install.d.ts +0 -2
  211. package/types/src/generators/msg-builder.ts +0 -5
  212. package/types/src/plugins/msg-builder.d.ts +0 -12
  213. package/types/src/plugins/use-contracts.d.ts +0 -12
  214. package/types/src/types.d.ts +0 -16
  215. package/types/src/utils/parse.d.ts +0 -1
  216. package/types/src/utils/prompt.d.ts +0 -3
  217. package/types/src/utils/schemas.d.ts +0 -10
  218. /package/{types/src/builder → builder}/index.d.ts +0 -0
  219. /package/{types/src/bundler → bundler}/index.d.ts +0 -0
  220. /package/{src/helpers/contractContextBase.ts → esm/helpers/contractContextBase.js} +0 -0
  221. /package/{src/helpers/contractContextBaseShortHandCtor.ts → esm/helpers/contractContextBaseShortHandCtor.js} +0 -0
  222. /package/{src/helpers/contractsContextTSX.ts → esm/helpers/contractsContextTSX.js} +0 -0
  223. /package/{types/src/helpers/index.d.ts → esm/helpers/index.js} +0 -0
  224. /package/{types/src/plugins/index.d.ts → esm/plugins/index.js} +0 -0
  225. /package/{src/utils/header.ts → esm/utils/header.js} +0 -0
  226. /package/{types/src/utils/index.d.ts → esm/utils/index.js} +0 -0
  227. /package/{types/src/file.d.ts → file.d.ts} +0 -0
  228. /package/{types/src/generators → generators}/client.d.ts +0 -0
  229. /package/{types/src/generators → generators}/create-helpers.d.ts +0 -0
  230. /package/{types/src/generators/msg-builder.d.ts → generators/message-builder.d.ts} +0 -0
  231. /package/{types/src/generators → generators}/message-composer.d.ts +0 -0
  232. /package/{types/src/generators → generators}/react-query.d.ts +0 -0
  233. /package/{types/src/generators → generators}/recoil.d.ts +0 -0
  234. /package/{types/src/generators → generators}/types.d.ts +0 -0
  235. /package/{types/src/helpers → helpers}/contractContextBase.d.ts +0 -0
  236. /package/{types/src/helpers → helpers}/contractContextBaseShortHandCtor.d.ts +0 -0
  237. /package/{types/src/helpers → helpers}/contractsContextTSX.d.ts +0 -0
  238. /package/{types/src/plugins → plugins}/client.d.ts +0 -0
  239. /package/{types/src/plugins → plugins}/message-builder.d.ts +0 -0
  240. /package/{types/src/plugins → plugins}/message-composer.d.ts +0 -0
  241. /package/{types/src/plugins → plugins}/provider-bundle.d.ts +0 -0
  242. /package/{types/src/plugins → plugins}/react-query.d.ts +0 -0
  243. /package/{types/src/plugins → plugins}/recoil.d.ts +0 -0
  244. /package/{types/src/plugins → plugins}/types.d.ts +0 -0
  245. /package/{types/src/ts-codegen.d.ts → ts-codegen.d.ts} +0 -0
  246. /package/{types/src/utils → utils}/clean.d.ts +0 -0
  247. /package/{types/src/utils → utils}/cleanse.d.ts +0 -0
  248. /package/{types/src/utils → utils}/files.d.ts +0 -0
  249. /package/{types/src/utils → utils}/header.d.ts +0 -0
  250. /package/{types/src/utils → utils}/unused.d.ts +0 -0
package/ts-codegen.js ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const cli_1 = require("./cli");
5
+ var argv = require('minimist')(process.argv.slice(2));
6
+ (async () => {
7
+ await (0, cli_1.cli)(argv);
8
+ })();
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;
@@ -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;
@@ -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`;
@@ -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);
@@ -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>;
@@ -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 {};
@@ -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;
@@ -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
+ };