@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
@@ -0,0 +1,42 @@
1
+ import * as t from "@babel/types";
2
+ import { parse } from "@babel/parser";
3
+ import { sync as mkdirp } from "mkdirp";
4
+ import { writeFileSync } from "fs";
5
+ import { dirname } from "path";
6
+ import generate from "@babel/generator";
7
+ import { unused } from "./unused";
8
+ import traverse from "@babel/traverse";
9
+ export const writeAstToFile = (outPath, program, filename, removeUnusedImports = false, isTsDisable = false, isEslintDisable = false) => {
10
+ const ast = t.program(program);
11
+ const content = generate(ast).code;
12
+ if (removeUnusedImports) {
13
+ const plugins = ["typescript"];
14
+ const newAst = parse(content, {
15
+ sourceType: "module",
16
+ plugins,
17
+ });
18
+ traverse(newAst, unused);
19
+ const content2 = generate(newAst).code;
20
+ writeContentToFile(outPath, content2, filename, isTsDisable, isEslintDisable);
21
+ }
22
+ else {
23
+ writeContentToFile(outPath, content, filename, isTsDisable, isEslintDisable);
24
+ }
25
+ };
26
+ export const writeContentToFile = (outPath, content, filename, isTsDisable = false, isEslintDisable = false) => {
27
+ let esLintPrefix = "";
28
+ let tsLintPrefix = "";
29
+ let nameWithoutPath = filename.replace(outPath, "");
30
+ // strip off leading slash
31
+ if (nameWithoutPath.startsWith("/"))
32
+ nameWithoutPath = nameWithoutPath.replace(/^\//, "");
33
+ if (isTsDisable) {
34
+ tsLintPrefix = `//@ts-nocheck\n`;
35
+ }
36
+ if (isEslintDisable) {
37
+ esLintPrefix = `/* eslint-disable */\n`;
38
+ }
39
+ const text = tsLintPrefix + esLintPrefix + content;
40
+ mkdirp(dirname(filename));
41
+ writeFileSync(filename, text);
42
+ };
@@ -1,32 +1,24 @@
1
1
  import babelTraverse from '@babel/traverse';
2
- import { parse, ParserPlugin } from '@babel/parser';
3
-
2
+ import { parse } from '@babel/parser';
4
3
  export const parser = (codes) => {
5
-
6
4
  const hash = {};
7
5
  codes.forEach(code => {
8
-
9
- const plugins: ParserPlugin[] = [
6
+ const plugins = [
10
7
  'typescript',
11
8
  ];
12
-
13
9
  const ast = parse(code, {
14
10
  sourceType: 'module',
15
11
  plugins
16
12
  });
17
-
18
13
  const visitor = visitorFn({
19
14
  addType(key, node) {
20
15
  hash[key] = node;
21
16
  }
22
- })
17
+ });
23
18
  babelTraverse(ast, visitor);
24
19
  });
25
-
26
20
  return hash;
27
-
28
- }
29
-
21
+ };
30
22
  const visitorFn = (parser) => ({
31
23
  TSTypeAliasDeclaration(path) {
32
24
  parser.addType(path.node.id.name, path.parentPath.node);
@@ -42,4 +34,3 @@ const visitorFn = (parser) => ({
42
34
  parser.addType(path.node.id.name, path.parentPath.node);
43
35
  }
44
36
  });
45
-
@@ -0,0 +1,59 @@
1
+ // @ts-nocheck
2
+ import { filter } from 'fuzzy';
3
+ import { prompt as inquirerer } from 'inquirerer';
4
+ export const getFuzzySearch = (list) => {
5
+ return (answers, input) => {
6
+ input = input || '';
7
+ return new Promise(function (resolve) {
8
+ setTimeout(function () {
9
+ const fuzzyResult = filter(input, list);
10
+ resolve(fuzzyResult.map(function (el) {
11
+ return el.original;
12
+ }));
13
+ }, 25);
14
+ });
15
+ };
16
+ };
17
+ export const getFuzzySearchNames = (nameValueItemList) => {
18
+ const list = nameValueItemList.map(({ name, value }) => name);
19
+ return (answers, input) => {
20
+ input = input || '';
21
+ return new Promise(function (resolve) {
22
+ setTimeout(function () {
23
+ const fuzzyResult = filter(input, list);
24
+ resolve(fuzzyResult.map(function (el) {
25
+ return nameValueItemList.find(({ name, value }) => el.original == name);
26
+ }));
27
+ }, 25);
28
+ });
29
+ };
30
+ };
31
+ const transform = (questions) => {
32
+ return questions.map((q) => {
33
+ if (q.type === 'fuzzy') {
34
+ const choices = q.choices;
35
+ delete q.choices;
36
+ return {
37
+ ...q,
38
+ type: 'autocomplete',
39
+ source: getFuzzySearch(choices)
40
+ };
41
+ }
42
+ else if (q.type === 'fuzzy:objects') {
43
+ const choices = q.choices;
44
+ delete q.choices;
45
+ return {
46
+ ...q,
47
+ type: 'autocomplete',
48
+ source: getFuzzySearchNames(choices)
49
+ };
50
+ }
51
+ else {
52
+ return q;
53
+ }
54
+ });
55
+ };
56
+ export const prompt = async (questions = [], argv = {}) => {
57
+ questions = transform(questions);
58
+ return await inquirerer(questions, argv);
59
+ };
@@ -3,22 +3,13 @@ import { readFileSync } from 'fs';
3
3
  import { cleanse } from './cleanse';
4
4
  import { compile } from '@pyramation/json-schema-to-typescript';
5
5
  import { parser } from './parse';
6
- import { ContractInfo, JSONSchema } from 'wasm-ast-types';
7
- interface ReadSchemaOpts {
8
- schemaDir: string;
9
- clean?: boolean;
10
- };
11
-
12
- export const readSchemas = async ({
13
- schemaDir, clean = true
14
- }: ReadSchemaOpts): Promise<ContractInfo> => {
15
- const fn = clean ? cleanse : (str) => str;
6
+ ;
7
+ export const readSchemas = async ({ schemaDir, clean = true }) => {
8
+ const fn = clean ? cleanse : (schema) => schema;
16
9
  const files = glob(schemaDir + '/**/*.json')
17
10
  .filter(file => !file.match(/\/raw\//));
18
-
19
11
  const schemas = files
20
12
  .map(file => JSON.parse(readFileSync(file, 'utf-8')));
21
-
22
13
  if (schemas.length > 1) {
23
14
  // legacy
24
15
  // TODO add console.warn here
@@ -26,64 +17,45 @@ export const readSchemas = async ({
26
17
  schemas: fn(schemas)
27
18
  };
28
19
  }
29
-
30
20
  if (schemas.length === 0) {
31
21
  throw new Error('Error [too few files]: requires one schema file per contract');
32
22
  }
33
-
34
23
  if (schemas.length !== 1) {
35
24
  throw new Error('Error [too many files]: CosmWasm v1.1 schemas supports one file');
36
25
  }
37
-
38
26
  const idlObject = schemas[0];
39
- const {
40
- contract_name,
41
- contract_version,
42
- idl_version,
43
- responses,
44
- instantiate,
45
- execute,
46
- query,
47
- migrate,
48
- sudo
49
- } = idlObject;
50
-
27
+ const { contract_name, contract_version, idl_version, responses, instantiate, execute, query, migrate, sudo } = idlObject;
51
28
  if (typeof idl_version !== 'string') {
52
29
  // legacy
53
30
  return {
54
31
  schemas: fn(schemas)
55
32
  };
56
33
  }
57
-
58
34
  // TODO use contract_name, etc.
35
+ const idl = {
36
+ instantiate,
37
+ execute,
38
+ query,
39
+ migrate,
40
+ sudo
41
+ };
59
42
  return {
60
43
  schemas: [
61
- ...Object.values(fn({
62
- instantiate,
63
- execute,
64
- query,
65
- migrate,
66
- sudo
67
- })).filter(Boolean),
44
+ ...Object.values(fn(idl)).filter(Boolean),
68
45
  ...Object.values(fn({ ...responses })).filter(Boolean)
69
46
  ],
70
47
  responses,
71
48
  idlObject
72
49
  };
73
50
  };
74
-
75
51
  export const findQueryMsg = (schemas) => {
76
- const QueryMsg = schemas.find(schema => schema.title === 'QueryMsg');
77
- return QueryMsg;
52
+ const queryMsg = schemas.find(schema => schema.title === 'QueryMsg');
53
+ return queryMsg;
78
54
  };
79
-
80
55
  export const findExecuteMsg = (schemas) => {
81
- const ExecuteMsg = schemas.find(schema =>
82
- schema.title.startsWith('ExecuteMsg')
83
- );
84
- return ExecuteMsg;
56
+ const executeMsg = schemas.find(schema => schema.title.startsWith('ExecuteMsg'));
57
+ return executeMsg;
85
58
  };
86
-
87
59
  export const findAndParseTypes = async (schemas) => {
88
60
  const Types = schemas;
89
61
  const allTypes = [];
@@ -0,0 +1,47 @@
1
+ //@ts-nocheck
2
+ import * as t from '@babel/types';
3
+ // https://github.com/chuyik/babel-plugin-danger-remove-unused-import
4
+ // https://github.com/chuyik/babel-plugin-danger-remove-unused-import/blob/c5454c21e94698a2464a12baa5590761932a71a8/License#L1
5
+ export const unused = {
6
+ Program: {
7
+ exit: (path) => {
8
+ const UnRefBindings = new Map();
9
+ for (const [name, binding] of Object.entries(path.scope.bindings)) {
10
+ if (!binding.path.parentPath || binding.kind !== 'module')
11
+ continue;
12
+ const source = binding.path.parentPath.get('source');
13
+ const importName = source.node.value;
14
+ if (!t.isStringLiteral(source))
15
+ continue;
16
+ const key = `${importName}(${source.node.loc &&
17
+ source.node.loc.start.line})`;
18
+ if (!UnRefBindings.has(key)) {
19
+ UnRefBindings.set(key, binding);
20
+ }
21
+ if (binding.referenced) {
22
+ UnRefBindings.set(key, null);
23
+ }
24
+ else {
25
+ const nodeType = binding.path.node.type;
26
+ if (nodeType === 'ImportSpecifier') {
27
+ binding.path.remove();
28
+ }
29
+ else if (nodeType === 'ImportDefaultSpecifier') {
30
+ binding.path.remove();
31
+ }
32
+ else if (nodeType === 'ImportNamespaceSpecifier') {
33
+ binding.path.remove();
34
+ }
35
+ else if (binding.path.parentPath) {
36
+ binding.path.parentPath.remove();
37
+ }
38
+ }
39
+ }
40
+ UnRefBindings.forEach((binding, key) => {
41
+ if (binding && binding.path.parentPath) {
42
+ binding.path.parentPath.remove();
43
+ }
44
+ });
45
+ }
46
+ }
47
+ };
package/file.js ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const prompt_1 = require("./utils/prompt");
5
+ const cli_1 = require("./cli");
6
+ const fs_1 = require("fs");
7
+ const argv = require('minimist')(process.argv.slice(2));
8
+ const question = [
9
+ {
10
+ _: true,
11
+ type: 'string',
12
+ name: 'file',
13
+ message: 'file'
14
+ }
15
+ ];
16
+ (async () => {
17
+ const { file } = await (0, prompt_1.prompt)(question, argv);
18
+ const argvv = JSON.parse((0, fs_1.readFileSync)(file, 'utf-8'));
19
+ await (0, cli_1.cli)(argvv);
20
+ })();
@@ -0,0 +1,95 @@
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
+ const case_1 = require("case");
30
+ const header_1 = require("../utils/header");
31
+ const path_1 = require("path");
32
+ const mkdirp_1 = require("mkdirp");
33
+ const w = __importStar(require("wasm-ast-types"));
34
+ const t = __importStar(require("@babel/types"));
35
+ const fs_1 = require("fs");
36
+ const generator_1 = __importDefault(require("@babel/generator"));
37
+ const wasm_ast_types_1 = require("wasm-ast-types");
38
+ const utils_1 = require("../utils");
39
+ const wasm_ast_types_2 = require("wasm-ast-types");
40
+ exports.default = async (name, contractInfo, outPath, tsClientOptions) => {
41
+ const { schemas } = contractInfo;
42
+ const context = new wasm_ast_types_2.RenderContext(contractInfo, {
43
+ client: tsClientOptions ?? {}
44
+ });
45
+ // const options = context.options.client;
46
+ const localname = (0, case_1.pascal)(name) + '.client.ts';
47
+ const TypesFile = (0, case_1.pascal)(name) + '.types';
48
+ const QueryMsg = (0, utils_1.findQueryMsg)(schemas);
49
+ const ExecuteMsg = (0, utils_1.findExecuteMsg)(schemas);
50
+ const typeHash = await (0, utils_1.findAndParseTypes)(schemas);
51
+ let Client = null;
52
+ let Instance = null;
53
+ let QueryClient = null;
54
+ let ReadOnlyInstance = null;
55
+ const body = [];
56
+ body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
57
+ // query messages
58
+ if (QueryMsg) {
59
+ QueryClient = (0, case_1.pascal)(`${name}QueryClient`);
60
+ ReadOnlyInstance = (0, case_1.pascal)(`${name}ReadOnlyInterface`);
61
+ body.push(w.createQueryInterface(context, ReadOnlyInstance, QueryMsg));
62
+ body.push(w.createQueryClass(context, QueryClient, ReadOnlyInstance, QueryMsg));
63
+ }
64
+ // execute messages
65
+ if (ExecuteMsg) {
66
+ const children = (0, wasm_ast_types_1.getMessageProperties)(ExecuteMsg);
67
+ if (children.length > 0) {
68
+ Client = (0, case_1.pascal)(`${name}Client`);
69
+ Instance = (0, case_1.pascal)(`${name}Interface`);
70
+ body.push(w.createExecuteInterface(context, Instance, context.options.client.execExtendsQuery ? ReadOnlyInstance : null, ExecuteMsg));
71
+ body.push(w.createExecuteClass(context, Client, Instance, context.options.client.execExtendsQuery ? QueryClient : null, ExecuteMsg));
72
+ }
73
+ }
74
+ if (typeHash.hasOwnProperty('Coin')) {
75
+ // @ts-ignore
76
+ delete context.utils.Coin;
77
+ }
78
+ const imports = context.getImports();
79
+ const code = header_1.header + (0, generator_1.default)(
80
+ // @ts-ignore
81
+ t.program([
82
+ ...imports,
83
+ ...body
84
+ ])).code;
85
+ (0, mkdirp_1.sync)(outPath);
86
+ (0, fs_1.writeFileSync)((0, path_1.join)(outPath, localname), code);
87
+ return [
88
+ {
89
+ type: 'client',
90
+ contract: name,
91
+ localname,
92
+ filename: (0, path_1.join)(outPath, localname),
93
+ }
94
+ ];
95
+ };
@@ -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.createHelpers = void 0;
7
+ const path_1 = require("path");
8
+ const mkdirp_1 = require("mkdirp");
9
+ const package_json_1 = __importDefault(require("../../package.json"));
10
+ const files_1 = require("../utils/files");
11
+ const helpers_1 = require("../helpers");
12
+ const version = process.env.NODE_ENV === "test" ? "latest" : package_json_1.default.version;
13
+ const header = `/**
14
+ * This file and any referenced files were automatically generated by ${package_json_1.default.name}@${version}
15
+ * DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain
16
+ * and run the transpile command or yarn proto command to regenerate this bundle.
17
+ */
18
+ \n`;
19
+ const write = (outPath, file, content, varname) => {
20
+ const outFile = (0, path_1.join)(outPath, file);
21
+ (0, mkdirp_1.sync)((0, path_1.dirname)(outFile));
22
+ (0, files_1.writeContentToFile)(outPath, header + content, outFile);
23
+ return {
24
+ type: "plugin",
25
+ pluginType: "helper",
26
+ contract: varname ?? (0, path_1.basename)(file, (0, path_1.extname)(file)),
27
+ localname: file,
28
+ filename: outFile,
29
+ };
30
+ };
31
+ const createHelpers = (input, builderContext) => {
32
+ const files = [];
33
+ if (input.options?.useContractsHooks?.enabled &&
34
+ Object.keys(builderContext.providers)?.length) {
35
+ const useShorthandCtor = input.options?.useShorthandCtor;
36
+ files.push(write(input.outPath, "contractContextBase.ts", useShorthandCtor
37
+ ? helpers_1.contractContextBaseShortHandCtor
38
+ : helpers_1.contractContextBase));
39
+ files.push(write(input.outPath, "contracts-context.tsx", helpers_1.contractsContextTSX, "contractsContext"));
40
+ }
41
+ return files;
42
+ };
43
+ exports.createHelpers = createHelpers;
@@ -0,0 +1,86 @@
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
+ const case_1 = require("case");
30
+ const header_1 = require("../utils/header");
31
+ const path_1 = require("path");
32
+ const mkdirp_1 = require("mkdirp");
33
+ const w = __importStar(require("wasm-ast-types"));
34
+ const t = __importStar(require("@babel/types"));
35
+ const fs_1 = require("fs");
36
+ const generator_1 = __importDefault(require("@babel/generator"));
37
+ const wasm_ast_types_1 = require("wasm-ast-types");
38
+ const utils_1 = require("../utils");
39
+ const wasm_ast_types_2 = require("wasm-ast-types");
40
+ exports.default = async (name, contractInfo, outPath, messageBuilderOptions) => {
41
+ const { schemas } = contractInfo;
42
+ const context = new wasm_ast_types_2.RenderContext(contractInfo, {
43
+ messageBuilder: messageBuilderOptions ?? {},
44
+ });
45
+ const localname = (0, case_1.pascal)(name) + ".message-builder.ts";
46
+ const TypesFile = (0, case_1.pascal)(name) + ".types";
47
+ const ExecuteMsg = (0, utils_1.findExecuteMsg)(schemas);
48
+ const typeHash = await (0, utils_1.findAndParseTypes)(schemas);
49
+ const body = [];
50
+ body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
51
+ body.push(w.importStmt(["CamelCasedProperties"], "type-fest"));
52
+ // execute messages
53
+ if (ExecuteMsg) {
54
+ const children = (0, wasm_ast_types_1.getMessageProperties)(ExecuteMsg);
55
+ if (children.length > 0) {
56
+ const className = (0, case_1.pascal)(`${name}ExecuteMsgBuilder`);
57
+ body.push(w.createMessageBuilderClass(context, className, ExecuteMsg));
58
+ }
59
+ }
60
+ const QueryMsg = (0, utils_1.findQueryMsg)(schemas);
61
+ // query messages
62
+ if (QueryMsg) {
63
+ const children = (0, wasm_ast_types_1.getMessageProperties)(QueryMsg);
64
+ if (children.length > 0) {
65
+ const className = (0, case_1.pascal)(`${name}QueryMsgBuilder`);
66
+ body.push(w.createMessageBuilderClass(context, className, QueryMsg));
67
+ }
68
+ }
69
+ if (typeHash.hasOwnProperty("Coin")) {
70
+ // @ts-ignore
71
+ delete context.utils.Coin;
72
+ }
73
+ const imports = context.getImports();
74
+ // @ts-ignore
75
+ const code = header_1.header + (0, generator_1.default)(t.program([...imports, ...body])).code;
76
+ (0, mkdirp_1.sync)(outPath);
77
+ (0, fs_1.writeFileSync)((0, path_1.join)(outPath, localname), code);
78
+ return [
79
+ {
80
+ type: "message-builder",
81
+ contract: name,
82
+ localname,
83
+ filename: (0, path_1.join)(outPath, localname),
84
+ },
85
+ ];
86
+ };
@@ -0,0 +1,83 @@
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
+ const case_1 = require("case");
30
+ const header_1 = require("../utils/header");
31
+ const path_1 = require("path");
32
+ const mkdirp_1 = require("mkdirp");
33
+ const w = __importStar(require("wasm-ast-types"));
34
+ const t = __importStar(require("@babel/types"));
35
+ const fs_1 = require("fs");
36
+ const generator_1 = __importDefault(require("@babel/generator"));
37
+ const wasm_ast_types_1 = require("wasm-ast-types");
38
+ const utils_1 = require("../utils");
39
+ const wasm_ast_types_2 = require("wasm-ast-types");
40
+ exports.default = async (name, contractInfo, outPath, messageComposerOptions) => {
41
+ const { schemas } = contractInfo;
42
+ const context = new wasm_ast_types_2.RenderContext(contractInfo, {
43
+ messageComposer: messageComposerOptions ?? {}
44
+ });
45
+ // const options = context.options.messageComposer;
46
+ const localname = (0, case_1.pascal)(name) + '.message-composer.ts';
47
+ const TypesFile = (0, case_1.pascal)(name) + '.types';
48
+ const ExecuteMsg = (0, utils_1.findExecuteMsg)(schemas);
49
+ const typeHash = await (0, utils_1.findAndParseTypes)(schemas);
50
+ const body = [];
51
+ body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
52
+ // execute messages
53
+ if (ExecuteMsg) {
54
+ const children = (0, wasm_ast_types_1.getMessageProperties)(ExecuteMsg);
55
+ if (children.length > 0) {
56
+ const TheClass = (0, case_1.pascal)(`${name}MessageComposer`);
57
+ const Interface = (0, case_1.pascal)(`${name}Message`);
58
+ body.push(w.createMessageComposerInterface(context, Interface, ExecuteMsg));
59
+ body.push(w.createMessageComposerClass(context, TheClass, Interface, ExecuteMsg));
60
+ }
61
+ }
62
+ if (typeHash.hasOwnProperty('Coin')) {
63
+ // @ts-ignore
64
+ delete context.utils.Coin;
65
+ }
66
+ const imports = context.getImports();
67
+ const code = header_1.header + (0, generator_1.default)(
68
+ // @ts-ignore
69
+ t.program([
70
+ ...imports,
71
+ ...body
72
+ ])).code;
73
+ (0, mkdirp_1.sync)(outPath);
74
+ (0, fs_1.writeFileSync)((0, path_1.join)(outPath, localname), code);
75
+ return [
76
+ {
77
+ type: 'message-composer',
78
+ contract: name,
79
+ localname,
80
+ filename: (0, path_1.join)(outPath, localname),
81
+ }
82
+ ];
83
+ };