@cosmwasm/ts-codegen 0.4.1 → 0.5.1

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
@@ -12,7 +12,7 @@ A Transpiler for CosmWasm Smart Contracts
12
12
  </a>
13
13
  <a href="https://github.com/CosmWasm/ts-codegen/blob/main/LICENSE-MIT"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"></a>
14
14
  <a href="https://github.com/CosmWasm/ts-codegen/blob/main/LICENSE-Apache"><img height="20" src="https://img.shields.io/badge/license-Apache-blue.svg"></a>
15
- <a href="https://www.npmjs.com/package/@cosmwasm/ts-codegen"><img height="20" src="https://img.shields.io/github/package-json/v/CosmWasm/ts-codegen?filename=packages%2Fts-codegen%2Fpackage.json"></a>
15
+ <a href="https://www.npmjs.com/package/@cosmwasm/ts-codegen"><img height="20" src="https://img.shields.io/github/package-json/v/CosmWasm/ts-codegen?filename=packages%2Fcosmwasm-typescript-gen%2Fpackage.json"></a>
16
16
  </p>
17
17
 
18
18
  ```
@@ -9,6 +9,8 @@ exports["default"] = void 0;
9
9
 
10
10
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
11
 
12
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
13
+
12
14
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
15
 
14
16
  var _prompt = require("../prompt");
@@ -17,9 +19,11 @@ var _reactQuery = _interopRequireDefault(require("../react-query"));
17
19
 
18
20
  var _utils = require("../utils");
19
21
 
22
+ var _excluded = ["schema", "out", "name"];
23
+
20
24
  var _default = /*#__PURE__*/function () {
21
25
  var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(argv) {
22
- var questions, _yield$prompt, schema, out, name, schemas;
26
+ var questions, _yield$prompt, schema, out, name, options, schemas;
23
27
 
24
28
  return _regenerator["default"].wrap(function _callee$(_context) {
25
29
  while (1) {
@@ -42,6 +46,11 @@ var _default = /*#__PURE__*/function () {
42
46
  type: 'string',
43
47
  name: 'name',
44
48
  message: 'contract name?'
49
+ }, {
50
+ type: 'confirm',
51
+ name: 'optionalClient',
52
+ message: 'optionalClient?',
53
+ "default": false
45
54
  }];
46
55
  _context.next = 3;
47
56
  return (0, _prompt.prompt)(questions, argv);
@@ -51,14 +60,15 @@ var _default = /*#__PURE__*/function () {
51
60
  schema = _yield$prompt.schema;
52
61
  out = _yield$prompt.out;
53
62
  name = _yield$prompt.name;
63
+ options = (0, _objectWithoutProperties2["default"])(_yield$prompt, _excluded);
54
64
  schemas = (0, _utils.readSchemas)({
55
65
  schemaDir: schema,
56
66
  argv: argv
57
67
  });
58
- _context.next = 10;
59
- return (0, _reactQuery["default"])(name, schemas, out);
68
+ _context.next = 11;
69
+ return (0, _reactQuery["default"])(name, schemas, out, options);
60
70
 
61
- case 10:
71
+ case 11:
62
72
  case "end":
63
73
  return _context.stop();
64
74
  }
@@ -36,14 +36,14 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
36
36
  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; }
37
37
 
38
38
  var _default = /*#__PURE__*/function () {
39
- var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(name, schemas, outPath) {
40
- var RecoilFile, Contract, QueryMsg, typeHash, QueryClient, ReadOnlyInstance, body, code;
39
+ var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(name, schemas, outPath, options) {
40
+ var ReactQueryFile, Contract, QueryMsg, typeHash, QueryClient, ReadOnlyInstance, body, code;
41
41
  return _regenerator["default"].wrap(function _callee$(_context) {
42
42
  while (1) {
43
43
  switch (_context.prev = _context.next) {
44
44
  case 0:
45
- RecoilFile = (0, _case.pascal)("".concat(name, "Contract")) + '.react-query.ts';
46
- Contract = (0, _case.pascal)("".concat(name, "Contract")) + '.ts';
45
+ ReactQueryFile = (0, _case.pascal)("".concat(name, "Contract")) + '.react-query.ts';
46
+ Contract = (0, _case.pascal)("".concat(name, "Contract"));
47
47
  QueryMsg = (0, _utils.findQueryMsg)(schemas);
48
48
  _context.next = 5;
49
49
  return (0, _utils.findAndParseTypes)(schemas);
@@ -54,18 +54,23 @@ var _default = /*#__PURE__*/function () {
54
54
  ReadOnlyInstance = null;
55
55
  body = [];
56
56
  body.push(w.importStmt(['useQuery', 'UseQueryOptions'], 'react-query'));
57
- body.push(w.importStmt(Object.keys(typeHash), "./".concat(Contract).replace(/\.ts$/, ''))); // query messages
57
+ body.push(w.importStmt(Object.keys(typeHash), "./".concat(Contract))); // query messages
58
58
 
59
59
  if (QueryMsg) {
60
60
  QueryClient = (0, _case.pascal)("".concat(name, "QueryClient"));
61
61
  ReadOnlyInstance = (0, _case.pascal)("".concat(name, "ReadOnlyInterface"));
62
62
  body.push(w.importStmt([QueryClient], "./".concat(Contract)));
63
- [].push.apply(body, w.createReactQueryHooks(QueryMsg, name, QueryClient));
63
+ [].push.apply(body, w.createReactQueryHooks({
64
+ queryMsg: QueryMsg,
65
+ contractName: name,
66
+ QueryClient: QueryClient,
67
+ options: options
68
+ }));
64
69
  }
65
70
 
66
71
  code = _header.header + (0, _generator["default"])(t.program(body)).code;
67
72
  (0, _mkdirp.sync)(outPath);
68
- (0, _fs.writeFileSync)((0, _path.join)(outPath, RecoilFile), code);
73
+ (0, _fs.writeFileSync)((0, _path.join)(outPath, ReactQueryFile), code);
69
74
 
70
75
  case 15:
71
76
  case "end":
@@ -75,7 +80,7 @@ var _default = /*#__PURE__*/function () {
75
80
  }, _callee);
76
81
  }));
77
82
 
78
- return function (_x, _x2, _x3) {
83
+ return function (_x, _x2, _x3, _x4) {
79
84
  return _ref.apply(this, arguments);
80
85
  };
81
86
  }();
@@ -1,3 +1,5 @@
1
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
+ const _excluded = ["schema", "out", "name"];
1
3
  import { prompt } from '../prompt';
2
4
  import reactQuery from '../react-query';
3
5
  import { readSchemas } from '../utils';
@@ -19,15 +21,24 @@ export default (async argv => {
19
21
  type: 'string',
20
22
  name: 'name',
21
23
  message: 'contract name?'
24
+ }, {
25
+ type: 'confirm',
26
+ name: 'optionalClient',
27
+ message: 'optionalClient?',
28
+ default: false
22
29
  }];
23
- const {
30
+
31
+ const _await$prompt = await prompt(questions, argv),
32
+ {
24
33
  schema,
25
34
  out,
26
35
  name
27
- } = await prompt(questions, argv);
36
+ } = _await$prompt,
37
+ options = _objectWithoutProperties(_await$prompt, _excluded);
38
+
28
39
  const schemas = readSchemas({
29
40
  schemaDir: schema,
30
41
  argv
31
42
  });
32
- await reactQuery(name, schemas, out);
43
+ await reactQuery(name, schemas, out, options);
33
44
  });
@@ -7,25 +7,30 @@ import * as t from '@babel/types';
7
7
  import { writeFileSync } from 'fs';
8
8
  import generate from "@babel/generator";
9
9
  import { findAndParseTypes, findQueryMsg } from "./utils";
10
- export default (async (name, schemas, outPath) => {
11
- const RecoilFile = pascal(`${name}Contract`) + '.react-query.ts';
12
- const Contract = pascal(`${name}Contract`) + '.ts';
10
+ export default (async (name, schemas, outPath, options) => {
11
+ const ReactQueryFile = pascal(`${name}Contract`) + '.react-query.ts';
12
+ const Contract = pascal(`${name}Contract`);
13
13
  const QueryMsg = findQueryMsg(schemas);
14
14
  const typeHash = await findAndParseTypes(schemas);
15
15
  let QueryClient = null;
16
16
  let ReadOnlyInstance = null;
17
17
  const body = [];
18
18
  body.push(w.importStmt(['useQuery', 'UseQueryOptions'], 'react-query'));
19
- body.push(w.importStmt(Object.keys(typeHash), `./${Contract}`.replace(/\.ts$/, ''))); // query messages
19
+ body.push(w.importStmt(Object.keys(typeHash), `./${Contract}`)); // query messages
20
20
 
21
21
  if (QueryMsg) {
22
22
  QueryClient = pascal(`${name}QueryClient`);
23
23
  ReadOnlyInstance = pascal(`${name}ReadOnlyInterface`);
24
24
  body.push(w.importStmt([QueryClient], `./${Contract}`));
25
- [].push.apply(body, w.createReactQueryHooks(QueryMsg, name, QueryClient));
25
+ [].push.apply(body, w.createReactQueryHooks({
26
+ queryMsg: QueryMsg,
27
+ contractName: name,
28
+ QueryClient,
29
+ options
30
+ }));
26
31
  }
27
32
 
28
33
  const code = header + generate(t.program(body)).code;
29
34
  mkdirp(outPath);
30
- writeFileSync(join(outPath, RecoilFile), code);
35
+ writeFileSync(join(outPath, ReactQueryFile), code);
31
36
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmwasm/ts-codegen",
3
- "version": "0.4.1",
3
+ "version": "0.5.1",
4
4
  "description": "A TypeScript Transpiler for CosmWasm Smart Contracts",
5
5
  "author": "Dan Lynch <pyramation@gmail.com>",
6
6
  "homepage": "https://github.com/pyramation/cosmwasm-typescript-gen",
@@ -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.3.7"
93
+ "wasm-ast-types": "^0.4.1"
94
94
  },
95
- "gitHead": "4c5521454e8165736421b3ebdab1be002d0bdf41"
95
+ "gitHead": "b0312f7e16b8fd1c4892da6d91d3f7cf6c1bd49e"
96
96
  }
package/types/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+
1
2
  export { default as generate } from './generate';
2
3
  export { default as fromPartial } from './from-partial';
3
4
  export { default as reactQuery } from './react-query';
@@ -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, options?: { optionalClient?: boolean }) => Promise<void>;
2
2
  export default _default;