@cosmwasm/ts-codegen 0.7.3 → 0.7.4

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
@@ -81,8 +81,13 @@ for programmatic usage, you can use the `tsClient` function:
81
81
 
82
82
  ```ts
83
83
  import { tsClient } from '@cosmwasm/ts-codegen';
84
- declare const tsClient = (name: string, schemas: any[], outPath: string) => Promise<void>;
84
+ declare const tsClient = (name: string, schemas: any[], outPath: string, tsClientOptions: TSClientOptions) => Promise<void>;
85
85
  ```
86
+ #### TS Client Options
87
+
88
+ | option | description |
89
+ | ----------------------------- | --------------------------------------------------- |
90
+ | `tsClient.aliasExecuteMsg` | generate a type alias based on the contract name |
86
91
 
87
92
  ### react query
88
93
 
@@ -40,19 +40,23 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
40
40
  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; }
41
41
 
42
42
  var _default = /*#__PURE__*/function () {
43
- var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(name, schemas, outPath) {
44
- var Contract, QueryMsg, ExecuteMsg, typeHash, Client, Instance, QueryClient, ReadOnlyInstance, body, context, children, code;
43
+ var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(name, schemas, outPath, tsClientOptions) {
44
+ var context, options, Contract, QueryMsg, ExecuteMsg, typeHash, Client, Instance, QueryClient, ReadOnlyInstance, body, children, code;
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
+ context = new w.RenderContext((0, _utils.getDefinitionSchema)(schemas), {
50
+ tsClient: tsClientOptions !== null && tsClientOptions !== void 0 ? tsClientOptions : {}
51
+ });
52
+ options = context.options.reactQuery;
49
53
  Contract = (0, _case.pascal)("".concat(name, "Contract")) + '.ts';
50
54
  QueryMsg = (0, _utils.findQueryMsg)(schemas);
51
55
  ExecuteMsg = (0, _utils.findExecuteMsg)(schemas);
52
- _context.next = 5;
56
+ _context.next = 7;
53
57
  return (0, _utils.findAndParseTypes)(schemas);
54
58
 
55
- case 5:
59
+ case 7:
56
60
  typeHash = _context.sent;
57
61
  Client = null;
58
62
  Instance = null;
@@ -66,8 +70,10 @@ var _default = /*#__PURE__*/function () {
66
70
  body.push((0, _clean.clean)(type));
67
71
  }); // alias the ExecuteMsg
68
72
 
69
- ExecuteMsg && body.push(t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier("".concat(name, "ExecuteMsg")), null, t.tsTypeReference(t.identifier('ExecuteMsg')))));
70
- context = new w.RenderContext((0, _utils.getDefinitionSchema)(schemas)); // query messages
73
+ if (options.aliasExecuteMsg && ExecuteMsg) {
74
+ body.push(t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier("".concat(name, "ExecuteMsg")), null, t.tsTypeReference(t.identifier('ExecuteMsg')))));
75
+ } // query messages
76
+
71
77
 
72
78
  if (QueryMsg) {
73
79
  QueryClient = (0, _case.pascal)("".concat(name, "QueryClient"));
@@ -92,7 +98,7 @@ var _default = /*#__PURE__*/function () {
92
98
  (0, _mkdirp.sync)(outPath);
93
99
  (0, _fs.writeFileSync)((0, _path.join)(outPath, Contract), code);
94
100
 
95
- case 21:
101
+ case 22:
96
102
  case "end":
97
103
  return _context.stop();
98
104
  }
@@ -100,7 +106,7 @@ var _default = /*#__PURE__*/function () {
100
106
  }, _callee);
101
107
  }));
102
108
 
103
- return function (_x, _x2, _x3) {
109
+ return function (_x, _x2, _x3, _x4) {
104
110
  return _ref.apply(this, arguments);
105
111
  };
106
112
  }();
@@ -11,7 +11,11 @@ import { getMessageProperties } from "wasm-ast-types";
11
11
  import { findAndParseTypes, findExecuteMsg, findQueryMsg, getDefinitionSchema } from '../utils';
12
12
  import { cosmjsAminoImportStatements } from '../utils/imports';
13
13
  import { RenderContext } from "wasm-ast-types";
14
- export default (async (name, schemas, outPath) => {
14
+ export default (async (name, schemas, outPath, tsClientOptions) => {
15
+ const context = new RenderContext(getDefinitionSchema(schemas), {
16
+ tsClient: tsClientOptions ?? {}
17
+ });
18
+ const options = context.options.reactQuery;
15
19
  const Contract = pascal(`${name}Contract`) + '.ts';
16
20
  const QueryMsg = findQueryMsg(schemas);
17
21
  const ExecuteMsg = findExecuteMsg(schemas);
@@ -28,8 +32,10 @@ export default (async (name, schemas, outPath) => {
28
32
  body.push(clean(type));
29
33
  }); // alias the ExecuteMsg
30
34
 
31
- ExecuteMsg && body.push(t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(`${name}ExecuteMsg`), null, t.tsTypeReference(t.identifier('ExecuteMsg')))));
32
- const context = new RenderContext(getDefinitionSchema(schemas)); // query messages
35
+ if (options.aliasExecuteMsg && ExecuteMsg) {
36
+ body.push(t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(`${name}ExecuteMsg`), null, t.tsTypeReference(t.identifier('ExecuteMsg')))));
37
+ } // query messages
38
+
33
39
 
34
40
  if (QueryMsg) {
35
41
  QueryClient = pascal(`${name}QueryClient`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmwasm/ts-codegen",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
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",
@@ -90,7 +90,7 @@
90
90
  "minimist": "1.2.6",
91
91
  "mkdirp": "1.0.4",
92
92
  "shelljs": "0.8.5",
93
- "wasm-ast-types": "^0.6.1"
93
+ "wasm-ast-types": "^0.6.2"
94
94
  },
95
- "gitHead": "6a9da6ddd47a5c9cebebf5fb05f5c1edea2868e2"
95
+ "gitHead": "a737503b0e3a69a25cb8f6e9c1950c92de9b1c74"
96
96
  }
@@ -1,2 +1,2 @@
1
- declare const _default: (name: string, schemas: any[], outPath: string) => Promise<void>;
1
+ declare const _default: (name: string, schemas: any[], outPath: string, tsClientOptions: TsClientOptions) => Promise<void>;
2
2
  export default _default;