@cosmwasm/ts-codegen 0.28.0 → 0.29.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.
package/README.md CHANGED
@@ -141,6 +141,7 @@ Typescript types and interfaces are generated in separate files so they can be i
141
141
  | ----------------------------- | --------------------------------------------------- |
142
142
  | `types.enabled` | enable type generation |
143
143
  | `types.aliasExecuteMsg` | generate a type alias based on the contract name |
144
+ | `types.aliasEntryPoints` | generate type aliases for the entry points based on the contract name |
144
145
 
145
146
  ### Client
146
147
 
@@ -41,11 +41,15 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
41
41
 
42
42
  var _default = /*#__PURE__*/function () {
43
43
  var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(name, contractInfo, outPath, tsTypesOptions) {
44
- var schemas, context, options, localname, ExecuteMsg, typeHash, body, imports, code, filename;
44
+ var schemas, context, options, localname, ExecuteMsg, typeHash, body, addEntryPointAlias, imports, code, filename;
45
45
  return _regenerator["default"].wrap(function _callee$(_context) {
46
46
  while (1) {
47
47
  switch (_context.prev = _context.next) {
48
48
  case 0:
49
+ addEntryPointAlias = function _addEntryPointAlias(msgName) {
50
+ body.push(t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier("".concat(name).concat(msgName)), null, t.tsTypeReference(t.identifier(msgName)))));
51
+ };
52
+
49
53
  schemas = contractInfo.schemas;
50
54
  context = new _wasmAstTypes.RenderContext(contractInfo, {
51
55
  types: tsTypesOptions !== null && tsTypesOptions !== void 0 ? tsTypesOptions : {}
@@ -53,21 +57,31 @@ var _default = /*#__PURE__*/function () {
53
57
  options = context.options.types;
54
58
  localname = (0, _case.pascal)(name) + '.types.ts';
55
59
  ExecuteMsg = (0, _utils.findExecuteMsg)(schemas);
56
- _context.next = 7;
60
+ _context.next = 8;
57
61
  return (0, _utils.findAndParseTypes)(schemas);
58
62
 
59
- case 7:
63
+ case 8:
60
64
  typeHash = _context.sent;
61
65
  body = []; // TYPES
62
66
 
63
67
  Object.values(typeHash).forEach(function (type) {
64
68
  body.push((0, _clean.clean)(type));
65
- }); // alias the ExecuteMsg
69
+ }); // alias the ExecuteMsg (deprecated option)
66
70
 
67
71
  if (options.aliasExecuteMsg && ExecuteMsg) {
68
72
  body.push(t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier("".concat(name, "ExecuteMsg")), null, t.tsTypeReference(t.identifier('ExecuteMsg')))));
69
73
  }
70
74
 
75
+ if (options.aliasEntryPoints) {
76
+ if (ExecuteMsg) {
77
+ addEntryPointAlias('ExecuteMsg');
78
+ }
79
+
80
+ if ((0, _utils.findQueryMsg)(schemas)) {
81
+ addEntryPointAlias('QueryMsg');
82
+ }
83
+ }
84
+
71
85
  imports = context.getImports();
72
86
  code = _header.header + (0, _generator["default"])(t.program([].concat((0, _toConsumableArray2["default"])(imports), body))).code;
73
87
  (0, _mkdirp.sync)(outPath);
@@ -80,7 +94,7 @@ var _default = /*#__PURE__*/function () {
80
94
  filename: filename
81
95
  }]);
82
96
 
83
- case 17:
97
+ case 19:
84
98
  case "end":
85
99
  return _context.stop();
86
100
  }
@@ -6,7 +6,7 @@ import * as t from '@babel/types';
6
6
  import { writeFileSync } from 'fs';
7
7
  import generate from "@babel/generator";
8
8
  import { clean } from "../utils/clean";
9
- import { findAndParseTypes, findExecuteMsg } from '../utils';
9
+ import { findAndParseTypes, findExecuteMsg, findQueryMsg } from '../utils';
10
10
  import { RenderContext } from "wasm-ast-types";
11
11
  export default (async (name, contractInfo, outPath, tsTypesOptions) => {
12
12
  const {
@@ -23,12 +23,26 @@ export default (async (name, contractInfo, outPath, tsTypesOptions) => {
23
23
 
24
24
  Object.values(typeHash).forEach(type => {
25
25
  body.push(clean(type));
26
- }); // alias the ExecuteMsg
26
+ }); // alias the ExecuteMsg (deprecated option)
27
27
 
28
28
  if (options.aliasExecuteMsg && ExecuteMsg) {
29
29
  body.push(t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(`${name}ExecuteMsg`), null, t.tsTypeReference(t.identifier('ExecuteMsg')))));
30
30
  }
31
31
 
32
+ function addEntryPointAlias(msgName) {
33
+ body.push(t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(`${name}${msgName}`), null, t.tsTypeReference(t.identifier(msgName)))));
34
+ }
35
+
36
+ if (options.aliasEntryPoints) {
37
+ if (ExecuteMsg) {
38
+ addEntryPointAlias('ExecuteMsg');
39
+ }
40
+
41
+ if (findQueryMsg(schemas)) {
42
+ addEntryPointAlias('QueryMsg');
43
+ }
44
+ }
45
+
32
46
  const imports = context.getImports();
33
47
  const code = header + generate(t.program([...imports, ...body])).code;
34
48
  mkdirp(outPath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmwasm/ts-codegen",
3
- "version": "0.28.0",
3
+ "version": "0.29.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",
@@ -96,7 +96,7 @@
96
96
  "parse-package-name": "1.0.0",
97
97
  "rimraf": "3.0.2",
98
98
  "shelljs": "0.8.5",
99
- "wasm-ast-types": "^0.21.0"
99
+ "wasm-ast-types": "^0.22.0"
100
100
  },
101
- "gitHead": "90fb688d19f477d246f9021ac91d824c96b8f3fc"
101
+ "gitHead": "45ac1ece2da95df09f949d692c95c66de0205408"
102
102
  }
@@ -6,7 +6,7 @@ import * as t from '@babel/types';
6
6
  import { writeFileSync } from 'fs';
7
7
  import generate from "@babel/generator";
8
8
  import { clean } from "../utils/clean";
9
- import { findAndParseTypes, findExecuteMsg } from '../utils';
9
+ import { findAndParseTypes, findExecuteMsg, findQueryMsg } from '../utils';
10
10
  import { ContractInfo, RenderContext, TSTypesOptions } from "wasm-ast-types";
11
11
  import { BuilderFile } from "../builder";
12
12
 
@@ -36,7 +36,7 @@ export default async (
36
36
  )
37
37
  });
38
38
 
39
- // alias the ExecuteMsg
39
+ // alias the ExecuteMsg (deprecated option)
40
40
  if (options.aliasExecuteMsg && ExecuteMsg) {
41
41
  body.push(
42
42
  t.exportNamedDeclaration(
@@ -49,6 +49,28 @@ export default async (
49
49
  );
50
50
  }
51
51
 
52
+ function addEntryPointAlias(msgName: string) {
53
+ body.push(
54
+ t.exportNamedDeclaration(
55
+ t.tsTypeAliasDeclaration(
56
+ t.identifier(`${name}${msgName}`),
57
+ null,
58
+ t.tsTypeReference(t.identifier(msgName))
59
+ )
60
+ )
61
+ );
62
+ }
63
+
64
+ if (options.aliasEntryPoints) {
65
+ if (ExecuteMsg) {
66
+ addEntryPointAlias('ExecuteMsg');
67
+ }
68
+ if (findQueryMsg(schemas)) {
69
+ addEntryPointAlias('QueryMsg');
70
+ }
71
+ }
72
+
73
+
52
74
  const imports = context.getImports();
53
75
  const code = header + generate(
54
76
  t.program([