@cosmwasm/ts-codegen 0.35.7 → 1.0.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 +2 -2
  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-composer.js +55 -0
  33. package/esm/generators/msg-builder.js +58 -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} +3 -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-composer.js +83 -0
  59. package/generators/msg-builder.js +86 -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/index.js +39 -0
  69. package/package.json +27 -51
  70. package/plugins/client.js +86 -0
  71. package/plugins/index.d.ts +1 -0
  72. package/plugins/index.js +17 -0
  73. package/plugins/message-builder.js +79 -0
  74. package/plugins/message-composer.js +73 -0
  75. package/{types/src/plugins → plugins}/plugin-base.d.ts +1 -1
  76. package/plugins/plugin-base.js +77 -0
  77. package/plugins/provider-bundle.js +85 -0
  78. package/{types/src/plugins → plugins}/provider.d.ts +2 -2
  79. package/plugins/provider.js +102 -0
  80. package/plugins/react-query.js +96 -0
  81. package/plugins/recoil.js +78 -0
  82. package/plugins/types.js +65 -0
  83. package/ts-codegen.js +8 -0
  84. package/utils/clean.js +49 -0
  85. package/utils/cleanse.js +89 -0
  86. package/utils/files.js +73 -0
  87. package/utils/header.js +14 -0
  88. package/utils/index.d.ts +1 -0
  89. package/utils/index.js +17 -0
  90. package/utils/parse.d.ts +1 -0
  91. package/utils/parse.js +43 -0
  92. package/utils/prompt.d.ts +3 -0
  93. package/utils/prompt.js +65 -0
  94. package/utils/schemas.d.ts +11 -0
  95. package/utils/schemas.js +81 -0
  96. package/utils/unused.js +73 -0
  97. package/main/builder/builder.js +0 -308
  98. package/main/builder/index.js +0 -16
  99. package/main/bundler/bundler.js +0 -61
  100. package/main/bundler/index.js +0 -16
  101. package/main/cli.js +0 -51
  102. package/main/cmds.js +0 -15
  103. package/main/commands/create-boilerplate.js +0 -166
  104. package/main/commands/generate.js +0 -196
  105. package/main/commands/install.js +0 -138
  106. package/main/file.js +0 -35
  107. package/main/generators/client.js +0 -90
  108. package/main/generators/create-helpers.js +0 -38
  109. package/main/generators/message-composer.js +0 -77
  110. package/main/generators/msg-builder.js +0 -84
  111. package/main/generators/react-query.js +0 -102
  112. package/main/generators/recoil.js +0 -81
  113. package/main/generators/types.js +0 -82
  114. package/main/helpers/contractContextBase.js +0 -8
  115. package/main/helpers/contractContextBaseShortHandCtor.js +0 -8
  116. package/main/helpers/contractsContextTSX.js +0 -8
  117. package/main/helpers/index.js +0 -38
  118. package/main/index.js +0 -119
  119. package/main/plugins/client.js +0 -112
  120. package/main/plugins/index.js +0 -16
  121. package/main/plugins/message-builder.js +0 -102
  122. package/main/plugins/message-composer.js +0 -98
  123. package/main/plugins/plugin-base.js +0 -103
  124. package/main/plugins/provider-bundle.js +0 -108
  125. package/main/plugins/provider.js +0 -126
  126. package/main/plugins/react-query.js +0 -120
  127. package/main/plugins/recoil.js +0 -108
  128. package/main/plugins/types.js +0 -89
  129. package/main/ts-codegen.js +0 -20
  130. package/main/utils/clean.js +0 -53
  131. package/main/utils/cleanse.js +0 -87
  132. package/main/utils/files.js +0 -57
  133. package/main/utils/header.js +0 -11
  134. package/main/utils/index.js +0 -16
  135. package/main/utils/parse.js +0 -44
  136. package/main/utils/prompt.js +0 -98
  137. package/main/utils/schemas.js +0 -144
  138. package/main/utils/unused.js +0 -57
  139. package/module/builder/builder.js +0 -143
  140. package/module/builder/index.js +0 -1
  141. package/module/bundler/bundler.js +0 -36
  142. package/module/bundler/index.js +0 -1
  143. package/module/cli.js +0 -19
  144. package/module/cmds.js +0 -8
  145. package/module/commands/create-boilerplate.js +0 -102
  146. package/module/commands/generate.js +0 -163
  147. package/module/commands/install.js +0 -98
  148. package/module/file.js +0 -18
  149. package/module/generators/client.js +0 -65
  150. package/module/generators/create-helpers.js +0 -33
  151. package/module/generators/message-composer.js +0 -52
  152. package/module/generators/msg-builder.js +0 -58
  153. package/module/generators/react-query.js +0 -75
  154. package/module/generators/recoil.js +0 -53
  155. package/module/generators/types.js +0 -55
  156. package/module/index.js +0 -14
  157. package/module/plugins/client.js +0 -63
  158. package/module/plugins/index.js +0 -1
  159. package/module/plugins/message-builder.js +0 -55
  160. package/module/plugins/message-composer.js +0 -49
  161. package/module/plugins/plugin-base.js +0 -66
  162. package/module/plugins/provider-bundle.js +0 -56
  163. package/module/plugins/provider.js +0 -68
  164. package/module/plugins/react-query.js +0 -72
  165. package/module/plugins/recoil.js +0 -57
  166. package/module/plugins/types.js +0 -42
  167. package/module/ts-codegen.js +0 -6
  168. package/module/utils/clean.js +0 -44
  169. package/module/utils/cleanse.js +0 -78
  170. package/module/utils/files.js +0 -40
  171. package/module/utils/header.js +0 -8
  172. package/module/utils/index.js +0 -1
  173. package/module/utils/parse.js +0 -35
  174. package/module/utils/prompt.js +0 -63
  175. package/module/utils/schemas.js +0 -85
  176. package/module/utils/unused.js +0 -43
  177. package/src/builder/index.ts +0 -1
  178. package/src/bundler/bundler.ts +0 -67
  179. package/src/bundler/index.ts +0 -1
  180. package/src/cli.js +0 -21
  181. package/src/file.js +0 -20
  182. package/src/generators/client.ts +0 -109
  183. package/src/generators/create-helpers.ts +0 -71
  184. package/src/generators/message-composer.ts +0 -86
  185. package/src/generators/msg-builder.ts +0 -78
  186. package/src/generators/react-query.ts +0 -102
  187. package/src/generators/recoil.ts +0 -92
  188. package/src/generators/types.ts +0 -94
  189. package/src/helpers/index.ts +0 -3
  190. package/src/plugins/client.ts +0 -124
  191. package/src/plugins/index.ts +0 -1
  192. package/src/plugins/message-builder.ts +0 -85
  193. package/src/plugins/message-composer.ts +0 -89
  194. package/src/plugins/plugin-base.ts +0 -122
  195. package/src/plugins/provider-bundle.ts +0 -98
  196. package/src/plugins/provider.ts +0 -115
  197. package/src/plugins/react-query.ts +0 -115
  198. package/src/plugins/recoil.ts +0 -89
  199. package/src/plugins/types.ts +0 -74
  200. package/src/utils/files.ts +0 -73
  201. package/src/utils/index.ts +0 -1
  202. package/src/utils/prompt.js +0 -65
  203. package/src/utils/unused.ts +0 -52
  204. package/types/src/bundler/bundler.d.ts +0 -4
  205. package/types/src/cli.d.ts +0 -1
  206. package/types/src/cmds.d.ts +0 -1
  207. package/types/src/commands/create-boilerplate.d.ts +0 -2
  208. package/types/src/commands/generate.d.ts +0 -2
  209. package/types/src/commands/install.d.ts +0 -2
  210. package/types/src/generators/msg-builder.ts +0 -5
  211. package/types/src/plugins/msg-builder.d.ts +0 -12
  212. package/types/src/plugins/use-contracts.d.ts +0 -12
  213. package/types/src/types.d.ts +0 -16
  214. package/types/src/utils/parse.d.ts +0 -1
  215. package/types/src/utils/prompt.d.ts +0 -3
  216. package/types/src/utils/schemas.d.ts +0 -10
  217. /package/{types/src/builder → builder}/index.d.ts +0 -0
  218. /package/{types/src/bundler → bundler}/index.d.ts +0 -0
  219. /package/{src/helpers/contractContextBase.ts → esm/helpers/contractContextBase.js} +0 -0
  220. /package/{src/helpers/contractContextBaseShortHandCtor.ts → esm/helpers/contractContextBaseShortHandCtor.js} +0 -0
  221. /package/{src/helpers/contractsContextTSX.ts → esm/helpers/contractsContextTSX.js} +0 -0
  222. /package/{types/src/helpers/index.d.ts → esm/helpers/index.js} +0 -0
  223. /package/{types/src/plugins/index.d.ts → esm/plugins/index.js} +0 -0
  224. /package/{src/utils/header.ts → esm/utils/header.js} +0 -0
  225. /package/{types/src/utils/index.d.ts → esm/utils/index.js} +0 -0
  226. /package/{types/src/file.d.ts → file.d.ts} +0 -0
  227. /package/{types/src/generators → generators}/client.d.ts +0 -0
  228. /package/{types/src/generators → generators}/create-helpers.d.ts +0 -0
  229. /package/{types/src/generators → generators}/message-composer.d.ts +0 -0
  230. /package/{types/src/generators → generators}/msg-builder.d.ts +0 -0
  231. /package/{types/src/generators → generators}/react-query.d.ts +0 -0
  232. /package/{types/src/generators → generators}/recoil.d.ts +0 -0
  233. /package/{types/src/generators → generators}/types.d.ts +0 -0
  234. /package/{types/src/helpers → helpers}/contractContextBase.d.ts +0 -0
  235. /package/{types/src/helpers → helpers}/contractContextBaseShortHandCtor.d.ts +0 -0
  236. /package/{types/src/helpers → helpers}/contractsContextTSX.d.ts +0 -0
  237. /package/{types/src/index.d.ts → index.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,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 utils_1 = require("../utils");
38
+ const wasm_ast_types_1 = require("wasm-ast-types");
39
+ exports.default = async (name, contractInfo, outPath, recoilOptions) => {
40
+ const { schemas } = contractInfo;
41
+ const context = new wasm_ast_types_1.RenderContext(contractInfo, {
42
+ recoil: recoilOptions ?? {}
43
+ });
44
+ const options = context.options.recoil;
45
+ const localname = (0, case_1.pascal)(name) + '.recoil.ts';
46
+ const ContractFile = (0, case_1.pascal)(name) + '.client';
47
+ const TypesFile = (0, case_1.pascal)(name) + '.types';
48
+ const QueryMsg = (0, utils_1.findQueryMsg)(schemas);
49
+ const typeHash = await (0, utils_1.findAndParseTypes)(schemas);
50
+ let QueryClient = null;
51
+ let ReadOnlyInstance = null;
52
+ const body = [];
53
+ body.push(w.importStmt(['cosmWasmClient'], './chain'));
54
+ body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
55
+ // query messages
56
+ if (QueryMsg) {
57
+ QueryClient = (0, case_1.pascal)(`${name}QueryClient`);
58
+ ReadOnlyInstance = (0, case_1.pascal)(`${name}ReadOnlyInterface`);
59
+ body.push(w.importStmt([QueryClient], `./${ContractFile}`));
60
+ body.push(w.createRecoilQueryClientType());
61
+ body.push(w.createRecoilQueryClient(context, name, QueryClient));
62
+ const selectors = w.createRecoilSelectors(context, name, QueryClient, QueryMsg);
63
+ body.push(...selectors);
64
+ }
65
+ if (typeHash.hasOwnProperty('Coin')) {
66
+ // @ts-ignore
67
+ delete context.utils.Coin;
68
+ }
69
+ const imports = context.getImports();
70
+ const code = header_1.header + (0, generator_1.default)(
71
+ // @ts-ignore
72
+ t.program([
73
+ ...imports,
74
+ ...body
75
+ ])).code;
76
+ (0, mkdirp_1.sync)(outPath);
77
+ (0, fs_1.writeFileSync)((0, path_1.join)(outPath, localname), code);
78
+ return [
79
+ {
80
+ type: 'recoil',
81
+ contract: name,
82
+ localname,
83
+ filename: (0, path_1.join)(outPath, localname),
84
+ }
85
+ ];
86
+ };
@@ -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 t = __importStar(require("@babel/types"));
34
+ const fs_1 = require("fs");
35
+ const generator_1 = __importDefault(require("@babel/generator"));
36
+ const clean_1 = require("../utils/clean");
37
+ const utils_1 = require("../utils");
38
+ const wasm_ast_types_1 = require("wasm-ast-types");
39
+ exports.default = async (name, contractInfo, outPath, tsTypesOptions) => {
40
+ const { schemas } = contractInfo;
41
+ const context = new wasm_ast_types_1.RenderContext(contractInfo, {
42
+ types: tsTypesOptions ?? {}
43
+ });
44
+ const options = context.options.types;
45
+ const localname = (0, case_1.pascal)(name) + '.types.ts';
46
+ const ExecuteMsg = (0, utils_1.findExecuteMsg)(schemas);
47
+ const typeHash = await (0, utils_1.findAndParseTypes)(schemas);
48
+ const body = [];
49
+ // TYPES
50
+ Object.values(typeHash).forEach((type) => {
51
+ body.push((0, clean_1.clean)(type));
52
+ });
53
+ // alias the ExecuteMsg (deprecated option)
54
+ if (options.aliasExecuteMsg && ExecuteMsg) {
55
+ body.push(t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(`${name}ExecuteMsg`), null, t.tsTypeReference(t.identifier('ExecuteMsg')))));
56
+ }
57
+ function addEntryPointAlias(msgName) {
58
+ body.push(t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(`${name}${msgName}`), null, t.tsTypeReference(t.identifier(msgName)))));
59
+ }
60
+ if (options.aliasEntryPoints) {
61
+ if (ExecuteMsg) {
62
+ addEntryPointAlias('ExecuteMsg');
63
+ }
64
+ if ((0, utils_1.findQueryMsg)(schemas)) {
65
+ addEntryPointAlias('QueryMsg');
66
+ }
67
+ }
68
+ const imports = context.getImports();
69
+ const code = header_1.header + (0, generator_1.default)(
70
+ // @ts-ignore
71
+ t.program([
72
+ ...imports,
73
+ ...body
74
+ ])).code;
75
+ (0, mkdirp_1.sync)(outPath);
76
+ const filename = (0, path_1.join)(outPath, localname);
77
+ (0, fs_1.writeFileSync)(filename, code);
78
+ return [
79
+ {
80
+ type: 'type',
81
+ contract: name,
82
+ localname,
83
+ filename,
84
+ }
85
+ ];
86
+ };
@@ -1,4 +1,7 @@
1
- export const contractContextBase = `
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.contractContextBase = void 0;
4
+ exports.contractContextBase = `
2
5
  import {
3
6
  CosmWasmClient,
4
7
  SigningCosmWasmClient,
@@ -114,4 +117,4 @@ export class ContractBase<
114
117
  return new this.TMsgComposer(this.address, contractAddr);
115
118
  }
116
119
  }
117
- `;
120
+ `;
@@ -1,4 +1,7 @@
1
- export const contractContextBaseShortHandCtor = `
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.contractContextBaseShortHandCtor = void 0;
4
+ exports.contractContextBaseShortHandCtor = `
2
5
  import {
3
6
  CosmWasmClient,
4
7
  SigningCosmWasmClient,
@@ -89,4 +92,4 @@ export class ContractBase<
89
92
  return new this.TMsgComposer(this.address, contractAddr);
90
93
  }
91
94
  }
92
- `;
95
+ `;
@@ -1,4 +1,7 @@
1
- export const contractsContextTSX = `
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.contractsContextTSX = void 0;
4
+ exports.contractsContextTSX = `
2
5
  import React, { useEffect, useMemo, useRef, useState, useContext } from 'react';
3
6
  import {
4
7
  CosmWasmClient,
@@ -70,4 +73,4 @@ export const useContracts = () => {
70
73
  }
71
74
  return contracts;
72
75
  };
73
- `;
76
+ `;
@@ -1,3 +1,3 @@
1
1
  export * from './contractContextBase';
2
2
  export * from './contractContextBaseShortHandCtor';
3
- export * from './contractsContextTSX';
3
+ export * from './contractsContextTSX';
@@ -0,0 +1,19 @@
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("./contractContextBase"), exports);
18
+ __exportStar(require("./contractContextBaseShortHandCtor"), exports);
19
+ __exportStar(require("./contractsContextTSX"), exports);
package/index.js ADDED
@@ -0,0 +1,39 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.generateRecoil = exports.generateReactQuery = exports.generateMessageComposer = exports.generateClient = exports.generateTypes = void 0;
21
+ const builder_1 = require("./builder");
22
+ var types_1 = require("./generators/types");
23
+ Object.defineProperty(exports, "generateTypes", { enumerable: true, get: function () { return __importDefault(types_1).default; } });
24
+ var client_1 = require("./generators/client");
25
+ Object.defineProperty(exports, "generateClient", { enumerable: true, get: function () { return __importDefault(client_1).default; } });
26
+ var message_composer_1 = require("./generators/message-composer");
27
+ Object.defineProperty(exports, "generateMessageComposer", { enumerable: true, get: function () { return __importDefault(message_composer_1).default; } });
28
+ var react_query_1 = require("./generators/react-query");
29
+ Object.defineProperty(exports, "generateReactQuery", { enumerable: true, get: function () { return __importDefault(react_query_1).default; } });
30
+ var recoil_1 = require("./generators/recoil");
31
+ Object.defineProperty(exports, "generateRecoil", { enumerable: true, get: function () { return __importDefault(recoil_1).default; } });
32
+ __exportStar(require("./utils"), exports);
33
+ __exportStar(require("./builder"), exports);
34
+ __exportStar(require("./bundler"), exports);
35
+ __exportStar(require("./plugins"), exports);
36
+ exports.default = async (input) => {
37
+ const builder = new builder_1.TSBuilder(input);
38
+ await builder.build();
39
+ };
package/package.json CHANGED
@@ -1,73 +1,41 @@
1
1
  {
2
2
  "name": "@cosmwasm/ts-codegen",
3
- "version": "0.35.7",
3
+ "version": "1.0.0",
4
4
  "description": "@cosmwasm/ts-codegen converts your CosmWasm smart contracts into dev-friendly TypeScript classes so you can focus on shipping code.",
5
5
  "author": "Dan Lynch <pyramation@gmail.com>",
6
6
  "homepage": "https://github.com/cosmwasm/ts-codegen",
7
7
  "license": "SEE LICENSE IN LICENSE",
8
- "main": "main/index.js",
9
- "module": "module/index.js",
10
- "typings": "types/src/index.d.ts",
8
+ "main": "index.js",
9
+ "module": "esm/index.js",
10
+ "types": "index.d.ts",
11
+ "publishConfig": {
12
+ "access": "public",
13
+ "directory": "dist"
14
+ },
11
15
  "bin": {
12
16
  "cosmwasm-ts-codegen": "main/ts-codegen.js"
13
17
  },
14
- "directories": {
15
- "lib": "src",
16
- "test": "__tests__"
17
- },
18
- "files": [
19
- "types",
20
- "main",
21
- "src",
22
- "module"
23
- ],
24
18
  "scripts": {
25
- "build:main": "cross-env BABEL_ENV=production babel src --out-dir main --delete-dir-on-start --extensions \".tsx,.ts,.js\"",
26
- "build:module": "cross-env MODULE=true babel src --out-dir module --delete-dir-on-start --extensions \".tsx,.ts,.js\"",
27
- "build:ts": "tsc --project ./tsconfig.json",
28
- "build": "npm run build:module && npm run build:main",
29
- "buidl": "npm run build && npm run build:ts",
19
+ "copy": "copyfiles -f LICENSE-Apache LICENSE-MIT README.md package.json dist",
20
+ "clean": "del dist/**",
30
21
  "prepare": "npm run build",
31
- "dev": "cross-env NODE_ENV=development babel-node src/ts-codegen --extensions \".tsx,.ts,.js\"",
32
- "watch": "cross-env NODE_ENV=development babel-watch src/ts-codegen --extensions \".tsx,.ts,.js\"",
33
- "file": "cross-env NODE_ENV=development babel-watch src/file --extensions \".tsx,.ts,.js\"",
34
- "lint": "eslint .",
35
- "format": "eslint . --fix",
22
+ "cmds": "ts-node ./scripts/cmds.ts",
23
+ "build": "npm run clean; tsc; tsc -p tsconfig.esm.json; npm run copy",
36
24
  "test": "jest",
37
25
  "test:watch": "jest --watch",
38
- "test:debug": "node --inspect node_modules/.bin/jest --runInBand"
39
- },
40
- "publishConfig": {
41
- "access": "public"
26
+ "dev": "ts-node src/ts-codegen",
27
+ "file": "ts-node src/file"
42
28
  },
43
29
  "repository": {
44
30
  "type": "git",
45
31
  "url": "https://github.com/cosmwasm/ts-codegen"
46
32
  },
47
- "keywords": [],
48
33
  "bugs": {
49
34
  "url": "https://github.com/cosmwasm/ts-codegen/issues"
50
35
  },
51
36
  "devDependencies": {
52
- "@babel/cli": "7.18.10",
53
- "@babel/eslint-parser": "^7.18.9",
54
- "@babel/node": "^7.18.10",
55
37
  "@cosmjs/cosmwasm-stargate": "0.30.1",
56
- "@types/jest": "^28.1.6",
57
- "ast-stringify": "0.1.0",
58
- "babel-core": "7.0.0-bridge.0",
59
- "babel-jest": "28.1.3",
60
- "babel-watch": "^7.0.0",
61
- "cross-env": "^7.0.2",
62
- "eslint": "8.21.0",
63
- "eslint-config-prettier": "^8.5.0",
64
- "eslint-plugin-prettier": "^4.2.1",
65
- "jest": "^28.1.3",
66
- "jest-in-case": "^1.0.2",
67
- "prettier": "^2.7.1",
68
- "regenerator-runtime": "^0.13.7",
69
- "ts-jest": "^28.0.7",
70
- "typescript": "^4.7.4"
38
+ "ast-stringify": "0.1.0"
71
39
  },
72
40
  "dependencies": {
73
41
  "@babel/core": "7.18.10",
@@ -82,21 +50,29 @@
82
50
  "@babel/runtime": "^7.18.9",
83
51
  "@babel/traverse": "7.18.11",
84
52
  "@babel/types": "7.18.10",
53
+ "@cosmology/ts-codegen-types": "^1.0.0",
85
54
  "@pyramation/json-schema-to-typescript": " 11.0.4",
55
+ "@types/rimraf": "3.0.2",
56
+ "@types/shelljs": "0.8.15",
86
57
  "case": "1.6.3",
87
58
  "dargs": "7.0.0",
88
59
  "deepmerge": "4.2.2",
89
- "dotty": "0.1.2",
90
60
  "fuzzy": "0.1.3",
91
61
  "glob": "8.0.3",
92
62
  "inquirerer": "0.1.3",
93
- "long": "^5.2.0",
94
63
  "minimist": "1.2.6",
95
64
  "mkdirp": "1.0.4",
65
+ "nested-obj": "0.0.1",
96
66
  "parse-package-name": "1.0.0",
97
67
  "rimraf": "3.0.2",
98
68
  "shelljs": "0.8.5",
99
- "wasm-ast-types": "^0.26.4"
69
+ "wasm-ast-types": "^1.0.0"
100
70
  },
101
- "gitHead": "eeba0cf1e0cbadfb6cfc103412108e763fdb9f6a"
71
+ "keywords": [
72
+ "cosmwasm",
73
+ "interchain",
74
+ "smart contracts",
75
+ "codegen"
76
+ ],
77
+ "gitHead": "7d55265f8f7cb567b921b78b9df5ca996bf9c8b6"
102
78
  }
@@ -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
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.ClientPlugin = exports.TYPE = void 0;
27
+ const case_1 = require("case");
28
+ const w = __importStar(require("wasm-ast-types"));
29
+ const utils_1 = require("../utils");
30
+ const wasm_ast_types_1 = require("wasm-ast-types");
31
+ const plugin_base_1 = require("./plugin-base");
32
+ exports.TYPE = "client";
33
+ class ClientPlugin extends plugin_base_1.BuilderPluginBase {
34
+ initContext(contract, options) {
35
+ return new wasm_ast_types_1.RenderContext(contract, options, this.builder.builderContext);
36
+ }
37
+ async doRender(name, context) {
38
+ const { enabled } = this.option.client;
39
+ if (!enabled) {
40
+ return;
41
+ }
42
+ const { schemas } = context.contract;
43
+ const localname = (0, case_1.pascal)(name) + ".client.ts";
44
+ const TypesFile = (0, case_1.pascal)(name) + ".types";
45
+ const QueryMsg = (0, utils_1.findQueryMsg)(schemas);
46
+ const ExecuteMsg = (0, utils_1.findExecuteMsg)(schemas);
47
+ const typeHash = await (0, utils_1.findAndParseTypes)(schemas);
48
+ let Client = null;
49
+ let Instance = null;
50
+ let QueryClient = null;
51
+ let ReadOnlyInstance = null;
52
+ const body = [];
53
+ body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
54
+ // query messages
55
+ if (QueryMsg) {
56
+ QueryClient = (0, case_1.pascal)(`${name}QueryClient`);
57
+ ReadOnlyInstance = (0, case_1.pascal)(`${name}ReadOnlyInterface`);
58
+ body.push(w.createQueryInterface(context, ReadOnlyInstance, QueryMsg));
59
+ body.push(w.createQueryClass(context, QueryClient, ReadOnlyInstance, QueryMsg));
60
+ context.addProviderInfo(name, w.PROVIDER_TYPES.QUERY_CLIENT_TYPE, QueryClient, localname);
61
+ }
62
+ // execute messages
63
+ if (ExecuteMsg) {
64
+ const children = (0, wasm_ast_types_1.getMessageProperties)(ExecuteMsg);
65
+ if (children.length > 0) {
66
+ Client = (0, case_1.pascal)(`${name}Client`);
67
+ Instance = (0, case_1.pascal)(`${name}Interface`);
68
+ body.push(w.createExecuteInterface(context, Instance, this.option.client.execExtendsQuery ? ReadOnlyInstance : null, ExecuteMsg));
69
+ body.push(w.createExecuteClass(context, Client, Instance, this.option.client.execExtendsQuery ? QueryClient : null, ExecuteMsg));
70
+ context.addProviderInfo(name, w.PROVIDER_TYPES.SIGNING_CLIENT_TYPE, Client, localname);
71
+ }
72
+ }
73
+ if (typeHash.hasOwnProperty("Coin")) {
74
+ // @ts-ignore
75
+ delete context.utils.Coin;
76
+ }
77
+ return [
78
+ {
79
+ type: exports.TYPE,
80
+ localname,
81
+ body,
82
+ },
83
+ ];
84
+ }
85
+ }
86
+ exports.ClientPlugin = ClientPlugin;
@@ -0,0 +1 @@
1
+ export * from "./plugin-base";
@@ -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("./plugin-base"), exports);
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.MessageBuilderPlugin = void 0;
27
+ const case_1 = require("case");
28
+ const w = __importStar(require("wasm-ast-types"));
29
+ const utils_1 = require("../utils");
30
+ const wasm_ast_types_1 = require("wasm-ast-types");
31
+ const plugin_base_1 = require("./plugin-base");
32
+ class MessageBuilderPlugin extends plugin_base_1.BuilderPluginBase {
33
+ initContext(contract, options) {
34
+ return new wasm_ast_types_1.RenderContext(contract, options, this.builder.builderContext);
35
+ }
36
+ async doRender(name, context) {
37
+ const { enabled } = this.option.messageBuilder;
38
+ if (!enabled) {
39
+ return;
40
+ }
41
+ const { schemas } = context.contract;
42
+ const localname = (0, case_1.pascal)(name) + '.message-builder.ts';
43
+ const TypesFile = (0, case_1.pascal)(name) + '.types';
44
+ const ExecuteMsg = (0, utils_1.findExecuteMsg)(schemas);
45
+ const typeHash = await (0, utils_1.findAndParseTypes)(schemas);
46
+ const body = [];
47
+ body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
48
+ body.push(w.importStmt(['CamelCasedProperties'], 'type-fest'));
49
+ // execute messages
50
+ if (ExecuteMsg) {
51
+ const children = (0, wasm_ast_types_1.getMessageProperties)(ExecuteMsg);
52
+ if (children.length > 0) {
53
+ const className = (0, case_1.pascal)(`${name}ExecuteMsgBuilder`);
54
+ body.push(w.createMessageBuilderClass(context, className, ExecuteMsg));
55
+ }
56
+ }
57
+ const QueryMsg = (0, utils_1.findQueryMsg)(schemas);
58
+ // query messages
59
+ if (QueryMsg) {
60
+ const children = (0, wasm_ast_types_1.getMessageProperties)(QueryMsg);
61
+ if (children.length > 0) {
62
+ const className = (0, case_1.pascal)(`${name}QueryMsgBuilder`);
63
+ body.push(w.createMessageBuilderClass(context, className, QueryMsg));
64
+ }
65
+ }
66
+ if (typeHash.hasOwnProperty('Coin')) {
67
+ // @ts-ignore
68
+ delete context.utils.Coin;
69
+ }
70
+ return [
71
+ {
72
+ type: 'message-builder',
73
+ localname,
74
+ body
75
+ }
76
+ ];
77
+ }
78
+ }
79
+ exports.MessageBuilderPlugin = MessageBuilderPlugin;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.MessageComposerPlugin = exports.TYPE = void 0;
27
+ const case_1 = require("case");
28
+ const w = __importStar(require("wasm-ast-types"));
29
+ const utils_1 = require("../utils");
30
+ const wasm_ast_types_1 = require("wasm-ast-types");
31
+ const plugin_base_1 = require("./plugin-base");
32
+ exports.TYPE = "message-composer";
33
+ class MessageComposerPlugin extends plugin_base_1.BuilderPluginBase {
34
+ initContext(contract, options) {
35
+ return new wasm_ast_types_1.RenderContext(contract, options, this.builder.builderContext);
36
+ }
37
+ async doRender(name, context) {
38
+ const { enabled } = this.option.messageComposer;
39
+ if (!enabled) {
40
+ return;
41
+ }
42
+ const { schemas } = context.contract;
43
+ const localname = (0, case_1.pascal)(name) + ".message-composer.ts";
44
+ const TypesFile = (0, case_1.pascal)(name) + ".types";
45
+ const ExecuteMsg = (0, utils_1.findExecuteMsg)(schemas);
46
+ const typeHash = await (0, utils_1.findAndParseTypes)(schemas);
47
+ const body = [];
48
+ body.push(w.importStmt(Object.keys(typeHash), `./${TypesFile}`));
49
+ // execute messages
50
+ if (ExecuteMsg) {
51
+ const children = (0, wasm_ast_types_1.getMessageProperties)(ExecuteMsg);
52
+ if (children.length > 0) {
53
+ const TheClass = (0, case_1.pascal)(`${name}MsgComposer`);
54
+ const Interface = (0, case_1.pascal)(`${name}Msg`);
55
+ body.push(w.createMessageComposerInterface(context, Interface, ExecuteMsg));
56
+ body.push(w.createMessageComposerClass(context, TheClass, Interface, ExecuteMsg));
57
+ context.addProviderInfo(name, w.PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE, TheClass, localname);
58
+ }
59
+ }
60
+ if (typeHash.hasOwnProperty("Coin")) {
61
+ // @ts-ignore
62
+ delete context.utils.Coin;
63
+ }
64
+ return [
65
+ {
66
+ type: exports.TYPE,
67
+ localname,
68
+ body,
69
+ },
70
+ ];
71
+ }
72
+ }
73
+ exports.MessageComposerPlugin = MessageComposerPlugin;