@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
@@ -1,40 +0,0 @@
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
- } else {
22
- writeContentToFile(outPath, content, filename, isTsDisable, isEslintDisable);
23
- }
24
- };
25
- export const writeContentToFile = (outPath, content, filename, isTsDisable = false, isEslintDisable = false) => {
26
- let esLintPrefix = "";
27
- let tsLintPrefix = "";
28
- let nameWithoutPath = filename.replace(outPath, "");
29
- // strip off leading slash
30
- if (nameWithoutPath.startsWith("/")) nameWithoutPath = nameWithoutPath.replace(/^\//, "");
31
- if (isTsDisable) {
32
- tsLintPrefix = `//@ts-nocheck\n`;
33
- }
34
- if (isEslintDisable) {
35
- esLintPrefix = `/* eslint-disable */\n`;
36
- }
37
- const text = tsLintPrefix + esLintPrefix + content;
38
- mkdirp(dirname(filename));
39
- writeFileSync(filename, text);
40
- };
@@ -1,8 +0,0 @@
1
- import pkg from '../../package.json';
2
- const version = process.env.NODE_ENV === 'test' ? 'latest' : pkg.version;
3
- export const header = `/**
4
- * This file was automatically generated by ${pkg.name}@${version}.
5
- * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
6
- * and run the ${pkg.name} generate command to regenerate this file.
7
- */
8
- \n`;
@@ -1 +0,0 @@
1
- export * from './schemas';
@@ -1,35 +0,0 @@
1
- import babelTraverse from '@babel/traverse';
2
- import { parse } from '@babel/parser';
3
- export const parser = codes => {
4
- const hash = {};
5
- codes.forEach(code => {
6
- const plugins = ['typescript'];
7
- const ast = parse(code, {
8
- sourceType: 'module',
9
- plugins
10
- });
11
- const visitor = visitorFn({
12
- addType(key, node) {
13
- hash[key] = node;
14
- }
15
- });
16
- babelTraverse(ast, visitor);
17
- });
18
- return hash;
19
- };
20
- const visitorFn = parser => ({
21
- TSTypeAliasDeclaration(path) {
22
- parser.addType(path.node.id.name, path.parentPath.node);
23
- // if (path.node.id.name.endsWith('For_Empty')) {
24
- // const newName = path.node.id.name.replace(/For_Empty$/, '_for_Empty');
25
- // path.parentPath.node.declaration.id.name = newName;
26
- // parser.addType(newName, path.parentPath.node);
27
- // } else {
28
- // parser.addType(path.node.id.name, path.parentPath.node);
29
- // }
30
- },
31
-
32
- TSInterfaceDeclaration(path) {
33
- parser.addType(path.node.id.name, path.parentPath.node);
34
- }
35
- });
@@ -1,63 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
- import { filter } from 'fuzzy';
5
- import { prompt as inquirerer } from 'inquirerer';
6
- export const getFuzzySearch = list => {
7
- return (answers, input) => {
8
- input = input || '';
9
- return new Promise(function (resolve) {
10
- setTimeout(function () {
11
- const fuzzyResult = filter(input, list);
12
- resolve(fuzzyResult.map(function (el) {
13
- return el.original;
14
- }));
15
- }, 25);
16
- });
17
- };
18
- };
19
- export const getFuzzySearchNames = nameValueItemList => {
20
- const list = nameValueItemList.map(({
21
- name,
22
- value
23
- }) => name);
24
- return (answers, input) => {
25
- input = input || '';
26
- return new Promise(function (resolve) {
27
- setTimeout(function () {
28
- const fuzzyResult = filter(input, list);
29
- resolve(fuzzyResult.map(function (el) {
30
- return nameValueItemList.find(({
31
- name,
32
- value
33
- }) => el.original == name);
34
- }));
35
- }, 25);
36
- });
37
- };
38
- };
39
- const transform = questions => {
40
- return questions.map(q => {
41
- if (q.type === 'fuzzy') {
42
- const choices = q.choices;
43
- delete q.choices;
44
- return _objectSpread(_objectSpread({}, q), {}, {
45
- type: 'autocomplete',
46
- source: getFuzzySearch(choices)
47
- });
48
- } else if (q.type === 'fuzzy:objects') {
49
- const choices = q.choices;
50
- delete q.choices;
51
- return _objectSpread(_objectSpread({}, q), {}, {
52
- type: 'autocomplete',
53
- source: getFuzzySearchNames(choices)
54
- });
55
- } else {
56
- return q;
57
- }
58
- });
59
- };
60
- export const prompt = async (questions = [], argv = {}) => {
61
- questions = transform(questions);
62
- return await inquirerer(questions, argv);
63
- };
@@ -1,85 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
- import { sync as glob } from 'glob';
5
- import { readFileSync } from 'fs';
6
- import { cleanse } from './cleanse';
7
- import { compile } from '@pyramation/json-schema-to-typescript';
8
- import { parser } from './parse';
9
- ;
10
- export const readSchemas = async ({
11
- schemaDir,
12
- clean = true
13
- }) => {
14
- const fn = clean ? cleanse : str => str;
15
- const files = glob(schemaDir + '/**/*.json').filter(file => !file.match(/\/raw\//));
16
- const schemas = files.map(file => JSON.parse(readFileSync(file, 'utf-8')));
17
- if (schemas.length > 1) {
18
- // legacy
19
- // TODO add console.warn here
20
- return {
21
- schemas: fn(schemas)
22
- };
23
- }
24
- if (schemas.length === 0) {
25
- throw new Error('Error [too few files]: requires one schema file per contract');
26
- }
27
- if (schemas.length !== 1) {
28
- throw new Error('Error [too many files]: CosmWasm v1.1 schemas supports one file');
29
- }
30
- const idlObject = schemas[0];
31
- const {
32
- contract_name,
33
- contract_version,
34
- idl_version,
35
- responses,
36
- instantiate,
37
- execute,
38
- query,
39
- migrate,
40
- sudo
41
- } = idlObject;
42
- if (typeof idl_version !== 'string') {
43
- // legacy
44
- return {
45
- schemas: fn(schemas)
46
- };
47
- }
48
-
49
- // TODO use contract_name, etc.
50
- return {
51
- schemas: [...Object.values(fn({
52
- instantiate,
53
- execute,
54
- query,
55
- migrate,
56
- sudo
57
- })).filter(Boolean), ...Object.values(fn(_objectSpread({}, responses))).filter(Boolean)],
58
- responses,
59
- idlObject
60
- };
61
- };
62
- export const findQueryMsg = schemas => {
63
- const QueryMsg = schemas.find(schema => schema.title === 'QueryMsg');
64
- return QueryMsg;
65
- };
66
- export const findExecuteMsg = schemas => {
67
- const ExecuteMsg = schemas.find(schema => schema.title.startsWith('ExecuteMsg'));
68
- return ExecuteMsg;
69
- };
70
- export const findAndParseTypes = async schemas => {
71
- const Types = schemas;
72
- const allTypes = [];
73
- for (const typ in Types) {
74
- if (Types[typ].definitions) {
75
- for (const key of Object.keys(Types[typ].definitions)) {
76
- // set title
77
- Types[typ].definitions[key].title = key;
78
- }
79
- }
80
- const result = await compile(Types[typ], Types[typ].title);
81
- allTypes.push(result);
82
- }
83
- const typeHash = parser(allTypes);
84
- return typeHash;
85
- };
@@ -1,43 +0,0 @@
1
- //@ts-nocheck
2
-
3
- import * as t from '@babel/types';
4
-
5
- // https://github.com/chuyik/babel-plugin-danger-remove-unused-import
6
- // https://github.com/chuyik/babel-plugin-danger-remove-unused-import/blob/c5454c21e94698a2464a12baa5590761932a71a8/License#L1
7
-
8
- export const unused = {
9
- Program: {
10
- exit: path => {
11
- const UnRefBindings = new Map();
12
- for (const [name, binding] of Object.entries(path.scope.bindings)) {
13
- if (!binding.path.parentPath || binding.kind !== 'module') continue;
14
- const source = binding.path.parentPath.get('source');
15
- const importName = source.node.value;
16
- if (!t.isStringLiteral(source)) continue;
17
- const key = `${importName}(${source.node.loc && 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
- } else {
24
- const nodeType = binding.path.node.type;
25
- if (nodeType === 'ImportSpecifier') {
26
- binding.path.remove();
27
- } else if (nodeType === 'ImportDefaultSpecifier') {
28
- binding.path.remove();
29
- } else if (nodeType === 'ImportNamespaceSpecifier') {
30
- binding.path.remove();
31
- } else if (binding.path.parentPath) {
32
- binding.path.parentPath.remove();
33
- }
34
- }
35
- }
36
- UnRefBindings.forEach((binding, key) => {
37
- if (binding && binding.path.parentPath) {
38
- binding.path.parentPath.remove();
39
- }
40
- });
41
- }
42
- }
43
- };
@@ -1 +0,0 @@
1
- export * from './builder';
@@ -1,67 +0,0 @@
1
- import * as t from '@babel/types';
2
- import * as dotty from 'dotty';
3
- import {
4
- relative, dirname, extname
5
- } from 'path';
6
-
7
- export const recursiveModuleBundle = (obj) => {
8
- return Object.keys(obj).map(key => {
9
- if (obj[key]?.__export) {
10
- // e.g. abci
11
- // 1. create variable for abci
12
- // 2. splat ALL _0, parms into abci
13
- // 3. export that variable
14
-
15
- const nmspc = t.variableDeclaration('const',
16
- [t.variableDeclarator(
17
- t.identifier(key),
18
- t.objectExpression(
19
- Object.keys(obj[key])
20
- .filter(a => a !== '__export')
21
- .filter(a => a.startsWith('_'))
22
- .map(a => t.spreadElement(t.identifier(a)))
23
- )
24
- )]
25
- );
26
-
27
- const others = Object.keys(obj[key])
28
- .filter(a => a !== '__export')
29
- .filter(a => !a.startsWith('_'));
30
- if (others.length) {
31
- throw new Error('namespace and package not supported, yet.')
32
- }
33
-
34
- // return nmspc;
35
- return t.exportNamedDeclaration(nmspc, []);
36
-
37
-
38
-
39
- } else {
40
- // you can make a namespace for obj[key]
41
- // e.g. libs
42
- return t.exportNamedDeclaration(
43
- t.tsModuleDeclaration(
44
- t.identifier(key),
45
- t.tsModuleBlock(recursiveModuleBundle(obj[key]))
46
- )
47
- )
48
- }
49
- });
50
- };
51
-
52
- export const importNamespace = (ident: string, path: string) => t.importDeclaration(
53
- [
54
- t.importNamespaceSpecifier(t.identifier(ident))
55
- ],
56
- t.stringLiteral(path.replace(extname(path), ''))
57
- );
58
-
59
- let counter = 0;
60
- export const createFileBundle = (pkg, filename, bundleFile, importPaths, bundleVariables) => {
61
- let rel = relative(dirname(bundleFile), filename);
62
- if (!rel.startsWith('.')) rel = `./${rel}`;
63
- const variable = `_${counter++}`;
64
- importPaths.push(importNamespace(variable, rel));
65
- dotty.put(bundleVariables, pkg + '.__export', true);
66
- dotty.put(bundleVariables, pkg + '.' + variable, true);
67
- }
@@ -1 +0,0 @@
1
- export * from './bundler';
package/src/cli.js DELETED
@@ -1,21 +0,0 @@
1
- import { prompt } from './utils/prompt';
2
- import { Commands as commands } from './cmds';
3
-
4
- const question = [
5
- {
6
- _: true,
7
- type: 'fuzzy',
8
- name: 'cmd',
9
- message: 'what do you want to do?',
10
- choices: Object.keys(commands)
11
- }
12
- ];
13
-
14
- export const cli = async (argv) => {
15
- var { cmd } = await prompt(question, argv);
16
- if (typeof commands[cmd] === 'function') {
17
- await commands[cmd](argv);
18
- } else {
19
- console.log('command not found.');
20
- }
21
- };
package/src/file.js DELETED
@@ -1,20 +0,0 @@
1
- #!/usr/bin/env node
2
- import { prompt } from './utils/prompt';
3
- import { cli } from './cli';
4
- import { readFileSync } from 'fs';
5
- const argv = require('minimist')(process.argv.slice(2));
6
-
7
- const question = [
8
- {
9
- _: true,
10
- type: 'string',
11
- name: 'file',
12
- message: 'file'
13
- }
14
- ];
15
-
16
- (async () => {
17
- const { file } = await prompt(question, argv);
18
- const argvv = JSON.parse(readFileSync(file, 'utf-8'));
19
- await cli(argvv);
20
- })();
@@ -1,109 +0,0 @@
1
- import { pascal } from "case";
2
- import { header } from '../utils/header';
3
- import { join } from "path";
4
- import { sync as mkdirp } from "mkdirp";
5
- import * as w from 'wasm-ast-types';
6
- import * as t from '@babel/types';
7
- import { writeFileSync } from 'fs';
8
- import generate from "@babel/generator";
9
- import { ContractInfo, getMessageProperties } from "wasm-ast-types";
10
- import { findAndParseTypes, findExecuteMsg, findQueryMsg } from '../utils';
11
- import { RenderContext, TSClientOptions } from "wasm-ast-types";
12
- import { BuilderFile } from "../builder";
13
-
14
- export default async (
15
- name: string,
16
- contractInfo: ContractInfo,
17
- outPath: string,
18
- tsClientOptions?: TSClientOptions
19
- ): Promise<BuilderFile[]> => {
20
-
21
- const { schemas } = contractInfo;
22
- const context = new RenderContext(contractInfo, {
23
- client: tsClientOptions ?? {}
24
- });
25
- // const options = context.options.client;
26
-
27
- const localname = pascal(name) + '.client.ts';
28
- const TypesFile = pascal(name) + '.types'
29
- const QueryMsg = findQueryMsg(schemas);
30
- const ExecuteMsg = findExecuteMsg(schemas);
31
- const typeHash = await findAndParseTypes(schemas);
32
-
33
- let Client = null;
34
- let Instance = null;
35
- let QueryClient = null;
36
- let ReadOnlyInstance = null;
37
-
38
- const body = [];
39
-
40
- body.push(
41
- w.importStmt(Object.keys(typeHash), `./${TypesFile}`)
42
- );
43
-
44
- // query messages
45
- if (QueryMsg) {
46
-
47
- QueryClient = pascal(`${name}QueryClient`);
48
- ReadOnlyInstance = pascal(`${name}ReadOnlyInterface`);
49
-
50
- body.push(
51
- w.createQueryInterface(context, ReadOnlyInstance, QueryMsg)
52
- );
53
- body.push(
54
- w.createQueryClass(context, QueryClient, ReadOnlyInstance, QueryMsg)
55
- );
56
- }
57
-
58
- // execute messages
59
- if (ExecuteMsg) {
60
- const children = getMessageProperties(ExecuteMsg);
61
- if (children.length > 0) {
62
- Client = pascal(`${name}Client`);
63
- Instance = pascal(`${name}Interface`);
64
-
65
- body.push(
66
- w.createExecuteInterface(
67
- context,
68
- Instance,
69
- context.options.client.execExtendsQuery ? ReadOnlyInstance : null,
70
- ExecuteMsg
71
- )
72
- );
73
-
74
- body.push(
75
- w.createExecuteClass(
76
- context,
77
- Client,
78
- Instance,
79
- context.options.client.execExtendsQuery ? QueryClient : null,
80
- ExecuteMsg
81
- )
82
- );
83
- }
84
- }
85
-
86
- if (typeHash.hasOwnProperty('Coin')) {
87
- // @ts-ignore
88
- delete context.utils.Coin;
89
- }
90
- const imports = context.getImports();
91
- const code = header + generate(
92
- t.program([
93
- ...imports,
94
- ...body
95
- ])
96
- ).code;
97
-
98
- mkdirp(outPath);
99
- writeFileSync(join(outPath, localname), code);
100
-
101
- return [
102
- {
103
- type: 'client',
104
- contract: name,
105
- localname,
106
- filename: join(outPath, localname),
107
- }
108
- ]
109
- };
@@ -1,71 +0,0 @@
1
- import { join, dirname, basename, extname } from "path";
2
- import { sync as mkdirp } from "mkdirp";
3
- import pkg from "../../package.json";
4
- import { writeContentToFile } from "../utils/files";
5
- import { BuilderFile, TSBuilderInput } from "../builder";
6
- import {
7
- contractContextBase,
8
- contractContextBaseShortHandCtor,
9
- contractsContextTSX,
10
- } from "../helpers";
11
- import { BuilderContext } from "wasm-ast-types";
12
-
13
- const version = process.env.NODE_ENV === "test" ? "latest" : pkg.version;
14
- const header = `/**
15
- * This file and any referenced files were automatically generated by ${pkg.name}@${version}
16
- * DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain
17
- * and run the transpile command or yarn proto command to regenerate this bundle.
18
- */
19
- \n`;
20
-
21
- const write = (
22
- outPath: string,
23
- file: string,
24
- content: string,
25
- varname?: string
26
- ): BuilderFile => {
27
- const outFile = join(outPath, file);
28
- mkdirp(dirname(outFile));
29
- writeContentToFile(outPath, header + content, outFile);
30
-
31
- return {
32
- type: "plugin",
33
- pluginType: "helper",
34
- contract: varname ?? basename(file, extname(file)),
35
- localname: file,
36
- filename: outFile,
37
- };
38
- };
39
-
40
- export const createHelpers = (
41
- input: TSBuilderInput,
42
- builderContext: BuilderContext
43
- ): BuilderFile[] => {
44
- const files: BuilderFile[] = [];
45
-
46
- if (
47
- input.options?.useContractsHooks?.enabled &&
48
- Object.keys(builderContext.providers)?.length
49
- ) {
50
- const useShorthandCtor = input.options?.useShorthandCtor;
51
- files.push(
52
- write(
53
- input.outPath,
54
- "contractContextBase.ts",
55
- useShorthandCtor
56
- ? contractContextBaseShortHandCtor
57
- : contractContextBase
58
- )
59
- );
60
- files.push(
61
- write(
62
- input.outPath,
63
- "contracts-context.tsx",
64
- contractsContextTSX,
65
- "contractsContext"
66
- )
67
- );
68
- }
69
-
70
- return files;
71
- };
@@ -1,86 +0,0 @@
1
- import { pascal } from "case";
2
- import { header } from '../utils/header';
3
- import { join } from "path";
4
- import { sync as mkdirp } from "mkdirp";
5
- import * as w from 'wasm-ast-types';
6
- import * as t from '@babel/types';
7
- import { writeFileSync } from 'fs';
8
- import generate from "@babel/generator";
9
- import { ContractInfo, getMessageProperties } from "wasm-ast-types";
10
- import { findAndParseTypes, findExecuteMsg } from "../utils";
11
- import { RenderContext, MessageComposerOptions } from "wasm-ast-types";
12
- import { BuilderFile } from "../builder";
13
-
14
- export default async (
15
- name: string,
16
- contractInfo: ContractInfo,
17
- outPath: string,
18
- messageComposerOptions?: MessageComposerOptions
19
- ): Promise<BuilderFile[]> => {
20
-
21
- const { schemas } = contractInfo;
22
- const context = new RenderContext(contractInfo, {
23
- messageComposer: messageComposerOptions ?? {}
24
- });
25
- // const options = context.options.messageComposer;
26
-
27
- const localname = pascal(name) + '.message-composer.ts';
28
- const TypesFile = pascal(name) + '.types';
29
- const ExecuteMsg = findExecuteMsg(schemas);
30
- const typeHash = await findAndParseTypes(schemas);
31
-
32
- const body = [];
33
-
34
- body.push(
35
- w.importStmt(Object.keys(typeHash), `./${TypesFile}`)
36
- );
37
-
38
- // execute messages
39
- if (ExecuteMsg) {
40
- const children = getMessageProperties(ExecuteMsg);
41
- if (children.length > 0) {
42
- const TheClass = pascal(`${name}MessageComposer`);
43
- const Interface = pascal(`${name}Message`);
44
-
45
- body.push(
46
- w.createMessageComposerInterface(
47
- context,
48
- Interface,
49
- ExecuteMsg
50
- )
51
- );
52
- body.push(
53
- w.createMessageComposerClass(
54
- context,
55
- TheClass,
56
- Interface,
57
- ExecuteMsg
58
- )
59
- );
60
- }
61
- }
62
-
63
- if (typeHash.hasOwnProperty('Coin')) {
64
- // @ts-ignore
65
- delete context.utils.Coin;
66
- }
67
- const imports = context.getImports();
68
- const code = header + generate(
69
- t.program([
70
- ...imports,
71
- ...body
72
- ])
73
- ).code;
74
-
75
- mkdirp(outPath);
76
- writeFileSync(join(outPath, localname), code);
77
-
78
- return [
79
- {
80
- type: 'message-composer',
81
- contract: name,
82
- localname,
83
- filename: join(outPath, localname),
84
- }
85
- ]
86
- };