@cosmwasm/ts-codegen 0.35.6 → 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 +15 -7
  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
@@ -1,98 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.prompt = exports.getFuzzySearchNames = exports.getFuzzySearch = void 0;
8
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
- var _fuzzy = require("fuzzy");
12
- var _inquirerer = require("inquirerer");
13
- 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; }
14
- 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) { (0, _defineProperty2["default"])(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; }
15
- var getFuzzySearch = function getFuzzySearch(list) {
16
- return function (answers, input) {
17
- input = input || '';
18
- return new Promise(function (resolve) {
19
- setTimeout(function () {
20
- var fuzzyResult = (0, _fuzzy.filter)(input, list);
21
- resolve(fuzzyResult.map(function (el) {
22
- return el.original;
23
- }));
24
- }, 25);
25
- });
26
- };
27
- };
28
- exports.getFuzzySearch = getFuzzySearch;
29
- var getFuzzySearchNames = function getFuzzySearchNames(nameValueItemList) {
30
- var list = nameValueItemList.map(function (_ref) {
31
- var name = _ref.name,
32
- value = _ref.value;
33
- return name;
34
- });
35
- return function (answers, input) {
36
- input = input || '';
37
- return new Promise(function (resolve) {
38
- setTimeout(function () {
39
- var fuzzyResult = (0, _fuzzy.filter)(input, list);
40
- resolve(fuzzyResult.map(function (el) {
41
- return nameValueItemList.find(function (_ref2) {
42
- var name = _ref2.name,
43
- value = _ref2.value;
44
- return el.original == name;
45
- });
46
- }));
47
- }, 25);
48
- });
49
- };
50
- };
51
- exports.getFuzzySearchNames = getFuzzySearchNames;
52
- var transform = function transform(questions) {
53
- return questions.map(function (q) {
54
- if (q.type === 'fuzzy') {
55
- var choices = q.choices;
56
- delete q.choices;
57
- return _objectSpread(_objectSpread({}, q), {}, {
58
- type: 'autocomplete',
59
- source: getFuzzySearch(choices)
60
- });
61
- } else if (q.type === 'fuzzy:objects') {
62
- var _choices = q.choices;
63
- delete q.choices;
64
- return _objectSpread(_objectSpread({}, q), {}, {
65
- type: 'autocomplete',
66
- source: getFuzzySearchNames(_choices)
67
- });
68
- } else {
69
- return q;
70
- }
71
- });
72
- };
73
- var prompt = /*#__PURE__*/function () {
74
- var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
75
- var questions,
76
- argv,
77
- _args = arguments;
78
- return _regenerator["default"].wrap(function _callee$(_context) {
79
- while (1) switch (_context.prev = _context.next) {
80
- case 0:
81
- questions = _args.length > 0 && _args[0] !== undefined ? _args[0] : [];
82
- argv = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
83
- questions = transform(questions);
84
- _context.next = 5;
85
- return (0, _inquirerer.prompt)(questions, argv);
86
- case 5:
87
- return _context.abrupt("return", _context.sent);
88
- case 6:
89
- case "end":
90
- return _context.stop();
91
- }
92
- }, _callee);
93
- }));
94
- return function prompt() {
95
- return _ref3.apply(this, arguments);
96
- };
97
- }();
98
- exports.prompt = prompt;
@@ -1,144 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.readSchemas = exports.findQueryMsg = exports.findExecuteMsg = exports.findAndParseTypes = void 0;
8
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
12
- var _glob = require("glob");
13
- var _fs = require("fs");
14
- var _cleanse = require("./cleanse");
15
- var _jsonSchemaToTypescript = require("@pyramation/json-schema-to-typescript");
16
- var _parse = require("./parse");
17
- 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; }
18
- 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) { (0, _defineProperty2["default"])(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; }
19
- ;
20
- var readSchemas = /*#__PURE__*/function () {
21
- var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(_ref) {
22
- var schemaDir, _ref$clean, clean, fn, files, schemas, idlObject, contract_name, contract_version, idl_version, responses, instantiate, execute, query, migrate, sudo;
23
- return _regenerator["default"].wrap(function _callee$(_context) {
24
- while (1) switch (_context.prev = _context.next) {
25
- case 0:
26
- schemaDir = _ref.schemaDir, _ref$clean = _ref.clean, clean = _ref$clean === void 0 ? true : _ref$clean;
27
- fn = clean ? _cleanse.cleanse : function (str) {
28
- return str;
29
- };
30
- files = (0, _glob.sync)(schemaDir + '/**/*.json').filter(function (file) {
31
- return !file.match(/\/raw\//);
32
- });
33
- schemas = files.map(function (file) {
34
- return JSON.parse((0, _fs.readFileSync)(file, 'utf-8'));
35
- });
36
- if (!(schemas.length > 1)) {
37
- _context.next = 6;
38
- break;
39
- }
40
- return _context.abrupt("return", {
41
- schemas: fn(schemas)
42
- });
43
- case 6:
44
- if (!(schemas.length === 0)) {
45
- _context.next = 8;
46
- break;
47
- }
48
- throw new Error('Error [too few files]: requires one schema file per contract');
49
- case 8:
50
- if (!(schemas.length !== 1)) {
51
- _context.next = 10;
52
- break;
53
- }
54
- throw new Error('Error [too many files]: CosmWasm v1.1 schemas supports one file');
55
- case 10:
56
- idlObject = schemas[0];
57
- contract_name = idlObject.contract_name, contract_version = idlObject.contract_version, idl_version = idlObject.idl_version, responses = idlObject.responses, instantiate = idlObject.instantiate, execute = idlObject.execute, query = idlObject.query, migrate = idlObject.migrate, sudo = idlObject.sudo;
58
- if (!(typeof idl_version !== 'string')) {
59
- _context.next = 14;
60
- break;
61
- }
62
- return _context.abrupt("return", {
63
- schemas: fn(schemas)
64
- });
65
- case 14:
66
- return _context.abrupt("return", {
67
- schemas: [].concat((0, _toConsumableArray2["default"])(Object.values(fn({
68
- instantiate: instantiate,
69
- execute: execute,
70
- query: query,
71
- migrate: migrate,
72
- sudo: sudo
73
- })).filter(Boolean)), (0, _toConsumableArray2["default"])(Object.values(fn(_objectSpread({}, responses))).filter(Boolean))),
74
- responses: responses,
75
- idlObject: idlObject
76
- });
77
- case 15:
78
- case "end":
79
- return _context.stop();
80
- }
81
- }, _callee);
82
- }));
83
- return function readSchemas(_x) {
84
- return _ref2.apply(this, arguments);
85
- };
86
- }();
87
- exports.readSchemas = readSchemas;
88
- var findQueryMsg = function findQueryMsg(schemas) {
89
- var QueryMsg = schemas.find(function (schema) {
90
- return schema.title === 'QueryMsg';
91
- });
92
- return QueryMsg;
93
- };
94
- exports.findQueryMsg = findQueryMsg;
95
- var findExecuteMsg = function findExecuteMsg(schemas) {
96
- var ExecuteMsg = schemas.find(function (schema) {
97
- return schema.title.startsWith('ExecuteMsg');
98
- });
99
- return ExecuteMsg;
100
- };
101
- exports.findExecuteMsg = findExecuteMsg;
102
- var findAndParseTypes = /*#__PURE__*/function () {
103
- var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(schemas) {
104
- var Types, allTypes, typ, _i, _Object$keys, key, result, typeHash;
105
- return _regenerator["default"].wrap(function _callee2$(_context2) {
106
- while (1) switch (_context2.prev = _context2.next) {
107
- case 0:
108
- Types = schemas;
109
- allTypes = [];
110
- _context2.t0 = _regenerator["default"].keys(Types);
111
- case 3:
112
- if ((_context2.t1 = _context2.t0()).done) {
113
- _context2.next = 12;
114
- break;
115
- }
116
- typ = _context2.t1.value;
117
- if (Types[typ].definitions) {
118
- for (_i = 0, _Object$keys = Object.keys(Types[typ].definitions); _i < _Object$keys.length; _i++) {
119
- key = _Object$keys[_i];
120
- // set title
121
- Types[typ].definitions[key].title = key;
122
- }
123
- }
124
- _context2.next = 8;
125
- return (0, _jsonSchemaToTypescript.compile)(Types[typ], Types[typ].title);
126
- case 8:
127
- result = _context2.sent;
128
- allTypes.push(result);
129
- _context2.next = 3;
130
- break;
131
- case 12:
132
- typeHash = (0, _parse.parser)(allTypes);
133
- return _context2.abrupt("return", typeHash);
134
- case 14:
135
- case "end":
136
- return _context2.stop();
137
- }
138
- }, _callee2);
139
- }));
140
- return function findAndParseTypes(_x2) {
141
- return _ref3.apply(this, arguments);
142
- };
143
- }();
144
- exports.findAndParseTypes = findAndParseTypes;
@@ -1,57 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- var _typeof = require("@babel/runtime/helpers/typeof");
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.unused = void 0;
9
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
- var t = _interopRequireWildcard(require("@babel/types"));
11
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
12
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
13
- //@ts-nocheck
14
-
15
- // https://github.com/chuyik/babel-plugin-danger-remove-unused-import
16
- // https://github.com/chuyik/babel-plugin-danger-remove-unused-import/blob/c5454c21e94698a2464a12baa5590761932a71a8/License#L1
17
-
18
- var unused = {
19
- Program: {
20
- exit: function exit(path) {
21
- var UnRefBindings = new Map();
22
- for (var _i = 0, _Object$entries = Object.entries(path.scope.bindings); _i < _Object$entries.length; _i++) {
23
- var _Object$entries$_i = (0, _slicedToArray2["default"])(_Object$entries[_i], 2),
24
- name = _Object$entries$_i[0],
25
- binding = _Object$entries$_i[1];
26
- if (!binding.path.parentPath || binding.kind !== 'module') continue;
27
- var source = binding.path.parentPath.get('source');
28
- var importName = source.node.value;
29
- if (!t.isStringLiteral(source)) continue;
30
- var key = "".concat(importName, "(").concat(source.node.loc && source.node.loc.start.line, ")");
31
- if (!UnRefBindings.has(key)) {
32
- UnRefBindings.set(key, binding);
33
- }
34
- if (binding.referenced) {
35
- UnRefBindings.set(key, null);
36
- } else {
37
- var nodeType = binding.path.node.type;
38
- if (nodeType === 'ImportSpecifier') {
39
- binding.path.remove();
40
- } else if (nodeType === 'ImportDefaultSpecifier') {
41
- binding.path.remove();
42
- } else if (nodeType === 'ImportNamespaceSpecifier') {
43
- binding.path.remove();
44
- } else if (binding.path.parentPath) {
45
- binding.path.parentPath.remove();
46
- }
47
- }
48
- }
49
- UnRefBindings.forEach(function (binding, key) {
50
- if (binding && binding.path.parentPath) {
51
- binding.path.parentPath.remove();
52
- }
53
- });
54
- }
55
- }
56
- };
57
- exports.unused = unused;
@@ -1,143 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import { defaultOptions, BuilderContext } from "wasm-ast-types";
3
- import { header } from '../utils/header';
4
- import { join } from "path";
5
- import { writeFileSync } from 'fs';
6
- import { sync as mkdirp } from "mkdirp";
7
- import { basename } from 'path';
8
- import { readSchemas } from '../utils';
9
- import deepmerge from 'deepmerge';
10
- import { pascal } from "case";
11
- import { createFileBundle, recursiveModuleBundle } from "../bundler";
12
- import generate from '@babel/generator';
13
- import * as t from '@babel/types';
14
- import { ReactQueryPlugin } from "../plugins/react-query";
15
- import { RecoilPlugin } from "../plugins/recoil";
16
- import { MessageBuilderPlugin } from "../plugins/message-builder";
17
- import { MessageComposerPlugin } from "../plugins/message-composer";
18
- import { ClientPlugin } from "../plugins/client";
19
- import { TypesPlugin } from "../plugins/types";
20
- import { ContractsContextProviderPlugin } from "../plugins/provider";
21
- import { createHelpers } from "../generators/create-helpers";
22
- import { ContractsProviderBundlePlugin } from "../plugins/provider-bundle";
23
- const defaultOpts = {
24
- bundle: {
25
- enabled: true,
26
- scope: 'contracts',
27
- bundleFile: 'bundle.ts'
28
- },
29
- useShorthandCtor: true
30
- };
31
- ;
32
- ;
33
- ;
34
- ;
35
- function getContract(contractOpt) {
36
- if (typeof contractOpt === 'string') {
37
- const name = basename(contractOpt);
38
- const contractName = pascal(name);
39
- return {
40
- name: contractName,
41
- dir: contractOpt
42
- };
43
- }
44
- return {
45
- name: pascal(contractOpt.name),
46
- dir: contractOpt.dir
47
- };
48
- }
49
- export class TSBuilder {
50
- loadDefaultPlugins() {
51
- [].push.apply(this.plugins, [new TypesPlugin(this.options), new ClientPlugin(this.options), new MessageComposerPlugin(this.options), new ReactQueryPlugin(this.options), new RecoilPlugin(this.options), new MessageBuilderPlugin(this.options), new ContractsContextProviderPlugin(this.options)]);
52
- }
53
- constructor({
54
- contracts,
55
- outPath,
56
- options,
57
- plugins
58
- }) {
59
- _defineProperty(this, "contracts", void 0);
60
- _defineProperty(this, "outPath", void 0);
61
- _defineProperty(this, "options", void 0);
62
- _defineProperty(this, "plugins", []);
63
- _defineProperty(this, "builderContext", new BuilderContext());
64
- _defineProperty(this, "files", []);
65
- this.contracts = contracts;
66
- this.outPath = outPath;
67
- this.options = deepmerge(deepmerge(defaultOptions, defaultOpts), options ?? {});
68
- this.loadDefaultPlugins();
69
- if (plugins && plugins.length) {
70
- [].push.apply(this.plugins, plugins);
71
- }
72
- this.plugins.forEach(plugin => plugin.setBuilder(this));
73
- }
74
- async build() {
75
- await this.process();
76
- await this.after();
77
- }
78
-
79
- // lifecycle functions
80
- async process() {
81
- for (const contractOpt of this.contracts) {
82
- const contract = getContract(contractOpt);
83
- //resolve contract schema.
84
- const contractInfo = await readSchemas({
85
- schemaDir: contract.dir
86
- });
87
-
88
- //lifecycle and plugins.
89
- await this.render(contract.name, contractInfo);
90
- }
91
- }
92
- async render(name, contractInfo) {
93
- for (const plugin of this.plugins) {
94
- let files = await plugin.render(name, contractInfo, this.outPath);
95
- if (files && files.length) {
96
- [].push.apply(this.files, files);
97
- }
98
- }
99
- }
100
- async after() {
101
- //create useContracts bundle file
102
- const contractsProviderBundlePlugin = new ContractsProviderBundlePlugin(this.options);
103
- contractsProviderBundlePlugin.setBuilder(this);
104
-
105
- //contractContextProviders.ts
106
- const files = await contractsProviderBundlePlugin.render("contractContextProviders", {
107
- schemas: []
108
- }, this.outPath);
109
- if (files && files.length) {
110
- [].push.apply(this.files, files);
111
- }
112
- const helpers = createHelpers({
113
- outPath: this.outPath,
114
- contracts: this.contracts,
115
- options: this.options,
116
- plugins: this.plugins
117
- }, this.builderContext);
118
- if (helpers && helpers.length) {
119
- [].push.apply(this.files, helpers);
120
- }
121
- if (this.options.bundle.enabled) {
122
- this.bundle();
123
- }
124
- }
125
- async bundle() {
126
- const allFiles = this.files;
127
- const bundleFile = this.options.bundle.bundleFile;
128
- const bundlePath = join(this.options?.bundle?.bundlePath ?? this.outPath, bundleFile);
129
- const bundleVariables = {};
130
- const importPaths = [];
131
- allFiles.forEach(file => {
132
- createFileBundle(`${this.options.bundle.scope}.${file.contract}`, file.filename, bundlePath, importPaths, bundleVariables);
133
- });
134
- const ast = recursiveModuleBundle(bundleVariables);
135
- let code = generate(t.program([...importPaths, ...ast])).code;
136
- if (this.options?.bundle?.bundlePath) {
137
- mkdirp(this.options?.bundle?.bundlePath);
138
- }
139
- mkdirp(this.outPath);
140
- if (code.trim() === '') code = 'export {};';
141
- writeFileSync(bundlePath, header + code);
142
- }
143
- }
@@ -1 +0,0 @@
1
- export * from './builder';
@@ -1,36 +0,0 @@
1
- import * as t from '@babel/types';
2
- import * as dotty from 'dotty';
3
- import { relative, dirname, extname } from 'path';
4
- export const recursiveModuleBundle = obj => {
5
- return Object.keys(obj).map(key => {
6
- if (obj[key]?.__export) {
7
- // e.g. abci
8
- // 1. create variable for abci
9
- // 2. splat ALL _0, parms into abci
10
- // 3. export that variable
11
-
12
- const nmspc = t.variableDeclaration('const', [t.variableDeclarator(t.identifier(key), t.objectExpression(Object.keys(obj[key]).filter(a => a !== '__export').filter(a => a.startsWith('_')).map(a => t.spreadElement(t.identifier(a)))))]);
13
- const others = Object.keys(obj[key]).filter(a => a !== '__export').filter(a => !a.startsWith('_'));
14
- if (others.length) {
15
- throw new Error('namespace and package not supported, yet.');
16
- }
17
-
18
- // return nmspc;
19
- return t.exportNamedDeclaration(nmspc, []);
20
- } else {
21
- // you can make a namespace for obj[key]
22
- // e.g. libs
23
- return t.exportNamedDeclaration(t.tsModuleDeclaration(t.identifier(key), t.tsModuleBlock(recursiveModuleBundle(obj[key]))));
24
- }
25
- });
26
- };
27
- export const importNamespace = (ident, path) => t.importDeclaration([t.importNamespaceSpecifier(t.identifier(ident))], t.stringLiteral(path.replace(extname(path), '')));
28
- let counter = 0;
29
- export const createFileBundle = (pkg, filename, bundleFile, importPaths, bundleVariables) => {
30
- let rel = relative(dirname(bundleFile), filename);
31
- if (!rel.startsWith('.')) rel = `./${rel}`;
32
- const variable = `_${counter++}`;
33
- importPaths.push(importNamespace(variable, rel));
34
- dotty.put(bundleVariables, pkg + '.__export', true);
35
- dotty.put(bundleVariables, pkg + '.' + variable, true);
36
- };
@@ -1 +0,0 @@
1
- export * from './bundler';
package/module/cli.js DELETED
@@ -1,19 +0,0 @@
1
- import { prompt } from './utils/prompt';
2
- import { Commands as commands } from './cmds';
3
- const question = [{
4
- _: true,
5
- type: 'fuzzy',
6
- name: 'cmd',
7
- message: 'what do you want to do?',
8
- choices: Object.keys(commands)
9
- }];
10
- export const cli = async argv => {
11
- var {
12
- cmd
13
- } = await prompt(question, argv);
14
- if (typeof commands[cmd] === 'function') {
15
- await commands[cmd](argv);
16
- } else {
17
- console.log('command not found.');
18
- }
19
- };
package/module/cmds.js DELETED
@@ -1,8 +0,0 @@
1
- import _create_boilerplate from './commands/create-boilerplate';
2
- import _generate from './commands/generate';
3
- import _install from './commands/install';
4
- const Commands = {};
5
- Commands['create-boilerplate'] = _create_boilerplate;
6
- Commands['generate'] = _generate;
7
- Commands['install'] = _install;
8
- export { Commands };
@@ -1,102 +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 * as shell from 'shelljs';
5
- import { prompt } from '../utils/prompt';
6
- import dargs from 'dargs';
7
- const glob = require('glob').sync;
8
- const fs = require('fs');
9
- const path = require('path');
10
- const repo = 'https://github.com/cosmology-tech/ts-codegen-module-boilerplate';
11
- export default (async argv => {
12
- if (!shell.which('git')) {
13
- shell.echo('Sorry, this script requires git');
14
- return shell.exit(1);
15
- }
16
- const {
17
- name
18
- } = await prompt([{
19
- type: 'string',
20
- name: 'name',
21
- message: 'Enter your new module name'
22
- }], argv);
23
- shell.exec(`git clone ${repo} ${name}`);
24
- shell.cd(name);
25
- const questions = JSON.parse(fs.readFileSync(`.questions.json`));
26
- const fullname = shell.exec('git config --global user.name', {
27
- silent: true
28
- }).trim();
29
- const email = shell.exec('git config --global user.email', {
30
- silent: true
31
- }).trim();
32
-
33
- // @__USERNAME__/__MODULENAME__
34
- // __PACKAGE_IDENTIFIER__
35
- const args = dargs(_objectSpread(_objectSpread({
36
- _: []
37
- }, argv), {}, {
38
- __MODULENAME__: name,
39
- __USERFULLNAME__: fullname,
40
- __USEREMAIL__: email
41
- }), {
42
- allowCamelCase: true
43
- });
44
- const results = await prompt(questions, args);
45
- let scopedResults;
46
- const license = await prompt([{
47
- name: '__LICENSE__',
48
- message: 'Which license?',
49
- choices: ['MIT', 'closed'],
50
- type: 'list',
51
- required: true
52
- }], []);
53
- if (results.__ACCESS__ === 'public') {
54
- scopedResults = await prompt([{
55
- type: 'confirm',
56
- name: 'scoped',
57
- message: 'use npm scopes?',
58
- required: true
59
- }], []);
60
- }
61
- const files = [].concat(glob(process.cwd() + '/**/.*')).concat(glob(process.cwd() + '/**/*'));
62
- for (let i = 0; i < files.length; i++) {
63
- const templateFile = files[i];
64
- if (fs.lstatSync(templateFile).isDirectory()) continue;
65
- let content = fs.readFileSync(templateFile).toString();
66
- if (path.basename(templateFile) === 'LICENSE' && license.__LICENSE__ === 'closed') {
67
- content = `Copyright (c) 2023 __USERFULLNAME__ <__USEREMAIL__> - All Rights Reserved
68
- Unauthorized copying via any medium is strictly prohibited
69
- Proprietary and confidential`;
70
- }
71
- Object.keys(results).forEach(key => {
72
- if (/^__/.test(key)) {
73
- content = content.replace(new RegExp(key, 'g'), results[key]);
74
- }
75
- });
76
- if (results.__ACCESS__ === 'public') {
77
- if (scopedResults.scoped) {
78
- content = content.replace(/__PACKAGE_IDENTIFIER__/g, `@${results.__USERNAME__}/${results.__MODULENAME__}`);
79
- } else {
80
- content = content.replace(/__PACKAGE_IDENTIFIER__/g, `${results.__MODULENAME__}`);
81
- }
82
- } else {
83
- content = content.replace(/__PACKAGE_IDENTIFIER__/g, `@${results.__USERNAME__}/${results.__MODULENAME__}`);
84
- }
85
-
86
- // if (path.basename(templateFile) === 'README.md') {
87
- // content = `# ${results.__MODULENAME__}`;
88
- // }
89
-
90
- fs.writeFileSync(templateFile, content);
91
- }
92
- shell.rm('-rf', '.git');
93
- shell.rm('-rf', '.questions.json');
94
- console.log(`
95
-
96
- |||
97
- (o o)
98
- ooO--(_)--Ooo-
99
-
100
- ✨ Great work!
101
- `);
102
- });