wasm-ast-types 0.20.0 → 0.22.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. package/main/client/client.js +4 -6
  2. package/main/client/test/ts-client.issue-103.test.js +48 -0
  3. package/main/message-composer/message-composer.js +3 -5
  4. package/main/react-query/react-query.js +4 -11
  5. package/main/utils/babel.js +1 -0
  6. package/main/utils/constants.js +25 -0
  7. package/main/utils/index.js +22 -1
  8. package/module/client/client.js +3 -4
  9. package/module/client/test/ts-client.issue-103.test.js +41 -0
  10. package/module/message-composer/message-composer.js +4 -5
  11. package/module/react-query/react-query.js +5 -6
  12. package/module/utils/babel.js +1 -0
  13. package/module/utils/constants.js +6 -0
  14. package/module/utils/index.js +3 -1
  15. package/package.json +2 -2
  16. package/src/client/client.ts +235 -323
  17. package/src/client/test/__snapshots__/ts-client.account-nfts.spec.ts.snap +45 -45
  18. package/src/client/test/__snapshots__/ts-client.arrays-ref.spec.ts.snap +42 -42
  19. package/src/client/test/__snapshots__/ts-client.arrays.spec.ts.snap +3 -3
  20. package/src/client/test/__snapshots__/ts-client.cw-named-groups.test.ts.snap +9 -9
  21. package/src/client/test/__snapshots__/ts-client.cw-proposal-single.test.ts.snap +27 -27
  22. package/src/client/test/__snapshots__/ts-client.issue-101.spec.ts.snap +6 -6
  23. package/src/client/test/__snapshots__/ts-client.issue-103.test.ts.snap +79 -0
  24. package/src/client/test/__snapshots__/ts-client.issue-71.test.ts.snap +30 -30
  25. package/src/client/test/__snapshots__/ts-client.issue-98.test.ts.snap +9 -9
  26. package/src/client/test/__snapshots__/ts-client.issues.test.ts.snap +78 -78
  27. package/src/client/test/__snapshots__/ts-client.overrides.spec.ts.snap +80 -80
  28. package/src/client/test/__snapshots__/ts-client.sg721.spec.ts.snap +24 -24
  29. package/src/client/test/__snapshots__/ts-client.spec.ts.snap +46 -46
  30. package/src/client/test/__snapshots__/ts-client.vectis.spec.ts.snap +24 -24
  31. package/src/client/test/__snapshots__/ts-client.wager.spec.ts.snap +8 -8
  32. package/src/client/test/ts-client.issue-103.test.ts +106 -0
  33. package/src/context/context.ts +2 -0
  34. package/src/message-composer/__snapshots__/message-composer.spec.ts.snap +30 -30
  35. package/src/message-composer/message-composer.ts +216 -267
  36. package/src/react-query/react-query.ts +28 -25
  37. package/src/utils/babel.ts +4 -3
  38. package/src/utils/constants.ts +30 -0
  39. package/src/utils/index.ts +2 -0
  40. package/types/context/context.d.ts +2 -0
@@ -7,7 +7,7 @@ var _typeof = require("@babel/runtime/helpers/typeof");
7
7
  Object.defineProperty(exports, "__esModule", {
8
8
  value: true
9
9
  });
10
- exports.getWasmMethodArgs = exports.createWasmQueryMethod = exports.createWasmExecMethod = exports.createTypeOrInterface = exports.createTypeInterface = exports.createQueryInterface = exports.createQueryClass = exports.createPropertyFunctionWithObjectParamsForExec = exports.createPropertyFunctionWithObjectParams = exports.createExecuteInterface = exports.createExecuteClass = exports.FIXED_EXECUTE_PARAMS = exports.CONSTANT_EXEC_PARAMS = void 0;
10
+ exports.getWasmMethodArgs = exports.createWasmQueryMethod = exports.createWasmExecMethod = exports.createTypeOrInterface = exports.createTypeInterface = exports.createQueryInterface = exports.createQueryClass = exports.createPropertyFunctionWithObjectParamsForExec = exports.createPropertyFunctionWithObjectParams = exports.createExecuteInterface = exports.createExecuteClass = exports.CONSTANT_EXEC_PARAMS = void 0;
11
11
 
12
12
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
13
13
 
@@ -25,10 +25,8 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
25
25
 
26
26
  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; }
27
27
 
28
- var CONSTANT_EXEC_PARAMS = [t.assignmentPattern((0, _babel.identifier)('fee', t.tsTypeAnnotation(t.tsUnionType([t.tSNumberKeyword(), t.tsTypeReference(t.identifier('StdFee')), t.tsLiteralType(t.stringLiteral('auto'))])), false), t.stringLiteral('auto')), (0, _babel.identifier)('memo', t.tsTypeAnnotation(t.tsStringKeyword()), true), (0, _babel.identifier)('funds', t.tsTypeAnnotation(t.tsArrayType(t.tsTypeReference(t.identifier('Coin')))), true)];
28
+ var CONSTANT_EXEC_PARAMS = [t.assignmentPattern((0, _babel.identifier)('fee', t.tsTypeAnnotation(t.tsUnionType([t.tSNumberKeyword(), t.tsTypeReference(t.identifier('StdFee')), t.tsLiteralType(t.stringLiteral('auto'))])), false), t.stringLiteral('auto')), (0, _babel.identifier)('memo', t.tsTypeAnnotation(t.tsStringKeyword()), true), _utils.OPTIONAL_FUNDS_PARAM];
29
29
  exports.CONSTANT_EXEC_PARAMS = CONSTANT_EXEC_PARAMS;
30
- var FIXED_EXECUTE_PARAMS = [(0, _babel.identifier)('fee', t.tsTypeAnnotation(t.tsUnionType([t.tsNumberKeyword(), t.tsTypeReference(t.identifier('StdFee')), t.tsLiteralType(t.stringLiteral('auto'))])), true), (0, _babel.identifier)('memo', t.tsTypeAnnotation(t.tsStringKeyword()), true), (0, _babel.identifier)('funds', t.tsTypeAnnotation(t.tsArrayType(t.tsTypeReference(t.identifier('Coin')))), true)];
31
- exports.FIXED_EXECUTE_PARAMS = FIXED_EXECUTE_PARAMS;
32
30
 
33
31
  var createWasmQueryMethod = function createWasmQueryMethod(context, jsonschema) {
34
32
  var underscoreName = Object.keys(jsonschema.properties)[0];
@@ -103,7 +101,7 @@ var createWasmExecMethod = function createWasmExecMethod(context, jsonschema) {
103
101
 
104
102
  var msgActionValue = (param === null || param === void 0 ? void 0 : param.type) === 'Identifier' ? t.identifier(param.name) : t.objectExpression(args);
105
103
  return t.classProperty(t.identifier(methodName), (0, _utils.arrowFunctionExpression)(param ? [// props
106
- param].concat(CONSTANT_EXEC_PARAMS) : CONSTANT_EXEC_PARAMS, t.blockStatement([t.returnStatement(t.awaitExpression(t.callExpression(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier('client')), t.identifier('execute')), [t.memberExpression(t.thisExpression(), t.identifier('sender')), t.memberExpression(t.thisExpression(), t.identifier('contractAddress')), t.objectExpression([t.objectProperty(msgAction, msgActionValue)]), t.identifier('fee'), t.identifier('memo'), t.identifier('funds')])))]), // return type
104
+ param].concat(CONSTANT_EXEC_PARAMS) : CONSTANT_EXEC_PARAMS, t.blockStatement([t.returnStatement(t.awaitExpression(t.callExpression(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier('client')), t.identifier('execute')), [t.memberExpression(t.thisExpression(), t.identifier('sender')), t.memberExpression(t.thisExpression(), t.identifier('contractAddress')), t.objectExpression([t.objectProperty(msgAction, msgActionValue)]), t.identifier('fee'), t.identifier('memo'), t.identifier('_funds')])))]), // return type
107
105
  t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Promise'), t.tsTypeParameterInstantiation([t.tSTypeReference(t.identifier('ExecuteResult'))]))), true));
108
106
  };
109
107
 
@@ -172,7 +170,7 @@ var createPropertyFunctionWithObjectParamsForExec = function createPropertyFunct
172
170
  var func = {
173
171
  type: 'TSFunctionType',
174
172
  typeAnnotation: (0, _utils.promiseTypeAnnotation)(responseType),
175
- parameters: obj ? [obj].concat(FIXED_EXECUTE_PARAMS) : FIXED_EXECUTE_PARAMS
173
+ parameters: obj ? [obj].concat((0, _toConsumableArray2["default"])(_utils.FIXED_EXECUTE_PARAMS)) : _utils.FIXED_EXECUTE_PARAMS
176
174
  };
177
175
  return t.tSPropertySignature(t.identifier(methodName), t.tsTypeAnnotation( // @ts-ignore:next-line
178
176
  func));
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ var _schema = _interopRequireDefault(require("../../../../../__fixtures__/issues/103/schema.json"));
6
+
7
+ var _client = require("../client");
8
+
9
+ var _testUtils = require("../../../test-utils");
10
+
11
+ var queryMessage = _schema["default"].query;
12
+ var executeMessage = _schema["default"].execute;
13
+ var queryCtx = (0, _testUtils.makeContext)(queryMessage);
14
+ var executeCtx = (0, _testUtils.makeContext)(executeMessage);
15
+ describe('query', function () {
16
+ it('execute_msg_for__empty', function () {
17
+ (0, _testUtils.expectCode)((0, _client.createTypeInterface)(queryCtx, queryMessage));
18
+ });
19
+ it('query classes', function () {
20
+ (0, _testUtils.expectCode)((0, _client.createQueryClass)(queryCtx, 'QueryClient', 'ReadOnlyInstance', queryMessage));
21
+ });
22
+ it('query classes response', function () {
23
+ (0, _testUtils.expectCode)((0, _client.createTypeInterface)(queryCtx, _schema["default"].query));
24
+ });
25
+ it('execute classes array types', function () {
26
+ (0, _testUtils.expectCode)((0, _client.createExecuteClass)(queryCtx, 'Client', 'Instance', null, queryMessage));
27
+ });
28
+ it('execute interfaces no extends', function () {
29
+ (0, _testUtils.expectCode)((0, _client.createExecuteInterface)(queryCtx, 'SG721Instance', null, queryMessage));
30
+ });
31
+ });
32
+ describe('execute', function () {
33
+ it('execute_msg_for__empty', function () {
34
+ (0, _testUtils.expectCode)((0, _client.createTypeInterface)(executeCtx, executeMessage));
35
+ });
36
+ it('query classes', function () {
37
+ (0, _testUtils.expectCode)((0, _client.createQueryClass)(executeCtx, 'QueryClient', 'ReadOnlyInstance', executeMessage));
38
+ });
39
+ it('query classes response', function () {
40
+ (0, _testUtils.expectCode)((0, _client.createTypeInterface)(executeCtx, _schema["default"].query));
41
+ });
42
+ it('execute classes array types', function () {
43
+ (0, _testUtils.expectCode)((0, _client.createExecuteClass)(executeCtx, 'Client', 'Instance', null, executeMessage));
44
+ });
45
+ it('execute interfaces no extends', function () {
46
+ (0, _testUtils.expectCode)((0, _client.createExecuteInterface)(executeCtx, 'SG721Instance', null, executeMessage));
47
+ });
48
+ });
@@ -19,8 +19,6 @@ var _utils = require("../utils");
19
19
 
20
20
  var _types2 = require("../utils/types");
21
21
 
22
- var _babel = require("../utils/babel");
23
-
24
22
  var _client = require("../client/client");
25
23
 
26
24
  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); }
@@ -45,9 +43,9 @@ var createWasmExecMethodMessageComposer = function createWasmExecMethodMessageCo
45
43
  actionValue = t.objectExpression(args);
46
44
  }
47
45
 
48
- var constantParams = [(0, _babel.identifier)('funds', t.tsTypeAnnotation(t.tsArrayType(t.tsTypeReference(t.identifier('Coin')))), true)];
46
+ var constantParams = [_utils.OPTIONAL_FUNDS_PARAM];
49
47
  return t.classProperty(t.identifier(methodName), (0, _utils.arrowFunctionExpression)(param ? [// props
50
- param].concat(constantParams) : constantParams, t.blockStatement([t.returnStatement(t.objectExpression([t.objectProperty(t.identifier('typeUrl'), t.stringLiteral('/cosmwasm.wasm.v1.MsgExecuteContract')), t.objectProperty(t.identifier('value'), t.callExpression(t.memberExpression(t.identifier('MsgExecuteContract'), t.identifier('fromPartial')), [t.objectExpression([t.objectProperty(t.identifier('sender'), t.memberExpression(t.thisExpression(), t.identifier('sender'))), t.objectProperty(t.identifier('contract'), t.memberExpression(t.thisExpression(), t.identifier('contractAddress'))), t.objectProperty(t.identifier('msg'), t.callExpression(t.identifier('toUtf8'), [t.callExpression(t.memberExpression(t.identifier('JSON'), t.identifier('stringify')), [t.objectExpression([t.objectProperty(t.identifier(underscoreName), actionValue)])])])), t.objectProperty(t.identifier('funds'), t.identifier('funds'), false, true)])]))]))]), // return type
48
+ param].concat(constantParams) : constantParams, t.blockStatement([t.returnStatement(t.objectExpression([t.objectProperty(t.identifier('typeUrl'), t.stringLiteral('/cosmwasm.wasm.v1.MsgExecuteContract')), t.objectProperty(t.identifier('value'), t.callExpression(t.memberExpression(t.identifier('MsgExecuteContract'), t.identifier('fromPartial')), [t.objectExpression([t.objectProperty(t.identifier('sender'), t.memberExpression(t.thisExpression(), t.identifier('sender'))), t.objectProperty(t.identifier('contract'), t.memberExpression(t.thisExpression(), t.identifier('contractAddress'))), t.objectProperty(t.identifier('msg'), t.callExpression(t.identifier('toUtf8'), [t.callExpression(t.memberExpression(t.identifier('JSON'), t.identifier('stringify')), [t.objectExpression([t.objectProperty(t.identifier(underscoreName), actionValue)])])])), t.objectProperty(t.identifier('funds'), t.identifier('_funds'))])]))]))]), // return type
51
49
  t.tsTypeAnnotation(t.tsTypeReference(t.identifier('MsgExecuteContractEncodeObject'))), false));
52
50
  };
53
51
 
@@ -87,7 +85,7 @@ exports.createMessageComposerInterface = createMessageComposerInterface;
87
85
 
88
86
  var createPropertyFunctionWithObjectParamsForMessageComposer = function createPropertyFunctionWithObjectParamsForMessageComposer(context, methodName, responseType, jsonschema) {
89
87
  var obj = (0, _types2.createTypedObjectParams)(context, jsonschema);
90
- var fixedParams = [(0, _babel.identifier)('funds', t.tsTypeAnnotation(t.tsArrayType(t.tsTypeReference(t.identifier('Coin')))), true)];
88
+ var fixedParams = [_utils.OPTIONAL_FUNDS_PARAM];
91
89
  var func = {
92
90
  type: 'TSFunctionType',
93
91
  typeAnnotation: t.tsTypeAnnotation(t.tsTypeReference(t.identifier(responseType))),
@@ -21,7 +21,7 @@ var _babel = require("../utils/babel");
21
21
 
22
22
  var _types2 = require("../utils/types");
23
23
 
24
- var _client = require("../client");
24
+ var _constants = require("../utils/constants");
25
25
 
26
26
  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); }
27
27
 
@@ -218,10 +218,7 @@ var createReactQueryMutationArgsInterface = function createReactQueryMutationArg
218
218
  context.addUtil('StdFee');
219
219
  context.addUtil('Coin');
220
220
  var optionalArgs = t.tsPropertySignature(t.identifier('args'), t.tsTypeAnnotation( // @ts-ignore:next-line
221
- t.tsTypeLiteral(_client.FIXED_EXECUTE_PARAMS.map(function (param) {
222
- return (0, _babel.propertySignature)(param.name, // @ts-ignore:next-line
223
- param.typeAnnotation, param.optional);
224
- }))));
221
+ t.tsTypeLiteral([(0, _babel.propertySignature)('fee', _constants.OPTIONAL_FEE_PARAM.typeAnnotation, true), (0, _babel.propertySignature)('memo', _constants.OPTIONAL_MEMO_PARAM.typeAnnotation, true), (0, _babel.propertySignature)('funds', _utils.OPTIONAL_FUNDS_PARAM.typeAnnotation, true)])));
225
222
  optionalArgs.optional = true;
226
223
  body.push(optionalArgs);
227
224
  return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(mutationHookParamsTypeName), null, [], t.tsInterfaceBody(body)));
@@ -305,12 +302,8 @@ var createReactQueryMutationHook = function createReactQueryMutationHook(_ref6)
305
302
  context.addUtil('UseMutationOptions');
306
303
  var useMutationFunctionArgs = [(0, _babel.shorthandProperty)('client')];
307
304
  if (hasMsg) useMutationFunctionArgs.push((0, _babel.shorthandProperty)('msg'));
308
- useMutationFunctionArgs.push(t.objectProperty(t.identifier('args'), t.assignmentPattern(t.objectPattern(_client.FIXED_EXECUTE_PARAMS.map(function (param) {
309
- return (0, _babel.shorthandProperty)(param.name);
310
- })), t.objectExpression([]))));
311
- return t.exportNamedDeclaration(t.functionDeclaration(t.identifier(mutationHookName), [(0, _utils.identifier)('options', t.tsTypeAnnotation((0, _babel.omitTypeReference)(t.tsTypeReference(t.identifier('UseMutationOptions'), useMutationTypeParameter), 'mutationFn')), true)], t.blockStatement([t.returnStatement((0, _utils.callExpression)(t.identifier('useMutation'), [t.arrowFunctionExpression([t.objectPattern(useMutationFunctionArgs)], t.callExpression(t.memberExpression(t.identifier('client'), t.identifier(execMethodName)), (hasMsg ? [t.identifier('msg')] : []).concat(_client.FIXED_EXECUTE_PARAMS.map(function (param) {
312
- return t.identifier(param.name);
313
- }))), false // not async
305
+ useMutationFunctionArgs.push(t.objectProperty(t.identifier('args'), t.assignmentPattern(t.objectPattern([(0, _babel.shorthandProperty)('fee'), (0, _babel.shorthandProperty)('memo'), (0, _babel.shorthandProperty)('funds')]), t.objectExpression([]))));
306
+ return t.exportNamedDeclaration(t.functionDeclaration(t.identifier(mutationHookName), [(0, _utils.identifier)('options', t.tsTypeAnnotation((0, _babel.omitTypeReference)(t.tsTypeReference(t.identifier('UseMutationOptions'), useMutationTypeParameter), 'mutationFn')), true)], t.blockStatement([t.returnStatement((0, _utils.callExpression)(t.identifier('useMutation'), [t.arrowFunctionExpression([t.objectPattern(useMutationFunctionArgs)], t.callExpression(t.memberExpression(t.identifier('client'), t.identifier(execMethodName)), (hasMsg ? [t.identifier('msg')] : []).concat([t.identifier('fee'), t.identifier('memo'), t.identifier('funds')])), false // not async
314
307
  ), t.identifier('options')], useMutationTypeParameter))])));
315
308
  };
316
309
 
@@ -37,6 +37,7 @@ var propertySignature = function propertySignature(name, typeAnnotation) {
37
37
  return {
38
38
  type: 'TSPropertySignature',
39
39
  key: t.identifier(name),
40
+ kind: 'get',
40
41
  typeAnnotation: typeAnnotation,
41
42
  optional: optional
42
43
  };
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ var _typeof = require("@babel/runtime/helpers/typeof");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.OPTIONAL_MEMO_PARAM = exports.OPTIONAL_FUNDS_PARAM = exports.OPTIONAL_FEE_PARAM = exports.FIXED_EXECUTE_PARAMS = void 0;
9
+
10
+ var _babel = require("./babel");
11
+
12
+ var t = _interopRequireWildcard(require("@babel/types"));
13
+
14
+ 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); }
15
+
16
+ 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; }
17
+
18
+ var OPTIONAL_FUNDS_PARAM = (0, _babel.identifier)('_funds', t.tsTypeAnnotation(t.tsArrayType(t.tsTypeReference(t.identifier('Coin')))), true);
19
+ exports.OPTIONAL_FUNDS_PARAM = OPTIONAL_FUNDS_PARAM;
20
+ var OPTIONAL_FEE_PARAM = (0, _babel.identifier)('fee', t.tsTypeAnnotation(t.tsUnionType([t.tsNumberKeyword(), t.tsTypeReference(t.identifier('StdFee')), t.tsLiteralType(t.stringLiteral('auto'))])), true);
21
+ exports.OPTIONAL_FEE_PARAM = OPTIONAL_FEE_PARAM;
22
+ var OPTIONAL_MEMO_PARAM = (0, _babel.identifier)('memo', t.tsTypeAnnotation(t.tsStringKeyword()), true);
23
+ exports.OPTIONAL_MEMO_PARAM = OPTIONAL_MEMO_PARAM;
24
+ var FIXED_EXECUTE_PARAMS = [OPTIONAL_FEE_PARAM, OPTIONAL_MEMO_PARAM, OPTIONAL_FUNDS_PARAM];
25
+ exports.FIXED_EXECUTE_PARAMS = FIXED_EXECUTE_PARAMS;
@@ -3,11 +3,28 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ var _exportNames = {
7
+ OPTIONAL_FUNDS_PARAM: true,
8
+ FIXED_EXECUTE_PARAMS: true
9
+ };
10
+ Object.defineProperty(exports, "FIXED_EXECUTE_PARAMS", {
11
+ enumerable: true,
12
+ get: function get() {
13
+ return _constants.FIXED_EXECUTE_PARAMS;
14
+ }
15
+ });
16
+ Object.defineProperty(exports, "OPTIONAL_FUNDS_PARAM", {
17
+ enumerable: true,
18
+ get: function get() {
19
+ return _constants.OPTIONAL_FUNDS_PARAM;
20
+ }
21
+ });
6
22
 
7
23
  var _babel = require("./babel");
8
24
 
9
25
  Object.keys(_babel).forEach(function (key) {
10
26
  if (key === "default" || key === "__esModule") return;
27
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
11
28
  if (key in exports && exports[key] === _babel[key]) return;
12
29
  Object.defineProperty(exports, key, {
13
30
  enumerable: true,
@@ -21,6 +38,7 @@ var _types = require("./types");
21
38
 
22
39
  Object.keys(_types).forEach(function (key) {
23
40
  if (key === "default" || key === "__esModule") return;
41
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
24
42
  if (key in exports && exports[key] === _types[key]) return;
25
43
  Object.defineProperty(exports, key, {
26
44
  enumerable: true,
@@ -34,6 +52,7 @@ var _ref = require("./ref");
34
52
 
35
53
  Object.keys(_ref).forEach(function (key) {
36
54
  if (key === "default" || key === "__esModule") return;
55
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
37
56
  if (key in exports && exports[key] === _ref[key]) return;
38
57
  Object.defineProperty(exports, key, {
39
58
  enumerable: true,
@@ -41,4 +60,6 @@ Object.keys(_ref).forEach(function (key) {
41
60
  return _ref[key];
42
61
  }
43
62
  });
44
- });
63
+ });
64
+
65
+ var _constants = require("./constants");
@@ -1,10 +1,9 @@
1
1
  import * as t from '@babel/types';
2
2
  import { camel } from 'case';
3
- import { arrowFunctionExpression, bindMethod, classDeclaration, classProperty, getMessageProperties, promiseTypeAnnotation, typedIdentifier } from '../utils';
3
+ import { arrowFunctionExpression, bindMethod, classDeclaration, classProperty, FIXED_EXECUTE_PARAMS, getMessageProperties, OPTIONAL_FUNDS_PARAM, promiseTypeAnnotation, typedIdentifier } from '../utils';
4
4
  import { createTypedObjectParams, getPropertyType, getResponseType, getType } from '../utils/types';
5
5
  import { identifier, propertySignature } from '../utils/babel';
6
- export const CONSTANT_EXEC_PARAMS = [t.assignmentPattern(identifier('fee', t.tsTypeAnnotation(t.tsUnionType([t.tSNumberKeyword(), t.tsTypeReference(t.identifier('StdFee')), t.tsLiteralType(t.stringLiteral('auto'))])), false), t.stringLiteral('auto')), identifier('memo', t.tsTypeAnnotation(t.tsStringKeyword()), true), identifier('funds', t.tsTypeAnnotation(t.tsArrayType(t.tsTypeReference(t.identifier('Coin')))), true)];
7
- export const FIXED_EXECUTE_PARAMS = [identifier('fee', t.tsTypeAnnotation(t.tsUnionType([t.tsNumberKeyword(), t.tsTypeReference(t.identifier('StdFee')), t.tsLiteralType(t.stringLiteral('auto'))])), true), identifier('memo', t.tsTypeAnnotation(t.tsStringKeyword()), true), identifier('funds', t.tsTypeAnnotation(t.tsArrayType(t.tsTypeReference(t.identifier('Coin')))), true)];
6
+ export const CONSTANT_EXEC_PARAMS = [t.assignmentPattern(identifier('fee', t.tsTypeAnnotation(t.tsUnionType([t.tSNumberKeyword(), t.tsTypeReference(t.identifier('StdFee')), t.tsLiteralType(t.stringLiteral('auto'))])), false), t.stringLiteral('auto')), identifier('memo', t.tsTypeAnnotation(t.tsStringKeyword()), true), OPTIONAL_FUNDS_PARAM];
8
7
  export const createWasmQueryMethod = (context, jsonschema) => {
9
8
  const underscoreName = Object.keys(jsonschema.properties)[0];
10
9
  const methodName = camel(underscoreName);
@@ -61,7 +60,7 @@ export const createWasmExecMethod = (context, jsonschema) => {
61
60
 
62
61
  const msgActionValue = param?.type === 'Identifier' ? t.identifier(param.name) : t.objectExpression(args);
63
62
  return t.classProperty(t.identifier(methodName), arrowFunctionExpression(param ? [// props
64
- param, ...CONSTANT_EXEC_PARAMS] : CONSTANT_EXEC_PARAMS, t.blockStatement([t.returnStatement(t.awaitExpression(t.callExpression(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier('client')), t.identifier('execute')), [t.memberExpression(t.thisExpression(), t.identifier('sender')), t.memberExpression(t.thisExpression(), t.identifier('contractAddress')), t.objectExpression([t.objectProperty(msgAction, msgActionValue)]), t.identifier('fee'), t.identifier('memo'), t.identifier('funds')])))]), // return type
63
+ param, ...CONSTANT_EXEC_PARAMS] : CONSTANT_EXEC_PARAMS, t.blockStatement([t.returnStatement(t.awaitExpression(t.callExpression(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier('client')), t.identifier('execute')), [t.memberExpression(t.thisExpression(), t.identifier('sender')), t.memberExpression(t.thisExpression(), t.identifier('contractAddress')), t.objectExpression([t.objectProperty(msgAction, msgActionValue)]), t.identifier('fee'), t.identifier('memo'), t.identifier('_funds')])))]), // return type
65
64
  t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Promise'), t.tsTypeParameterInstantiation([t.tSTypeReference(t.identifier('ExecuteResult'))]))), true));
66
65
  };
67
66
  export const createExecuteClass = (context, className, implementsClassName, extendsClassName, execMsg) => {
@@ -0,0 +1,41 @@
1
+ import contract from '../../../../../__fixtures__/issues/103/schema.json';
2
+ import { createQueryClass, createExecuteClass, createExecuteInterface, createTypeInterface } from '../client';
3
+ import { expectCode, makeContext } from '../../../test-utils';
4
+ const queryMessage = contract.query;
5
+ const executeMessage = contract.execute;
6
+ const queryCtx = makeContext(queryMessage);
7
+ const executeCtx = makeContext(executeMessage);
8
+ describe('query', () => {
9
+ it('execute_msg_for__empty', () => {
10
+ expectCode(createTypeInterface(queryCtx, queryMessage));
11
+ });
12
+ it('query classes', () => {
13
+ expectCode(createQueryClass(queryCtx, 'QueryClient', 'ReadOnlyInstance', queryMessage));
14
+ });
15
+ it('query classes response', () => {
16
+ expectCode(createTypeInterface(queryCtx, contract.query));
17
+ });
18
+ it('execute classes array types', () => {
19
+ expectCode(createExecuteClass(queryCtx, 'Client', 'Instance', null, queryMessage));
20
+ });
21
+ it('execute interfaces no extends', () => {
22
+ expectCode(createExecuteInterface(queryCtx, 'SG721Instance', null, queryMessage));
23
+ });
24
+ });
25
+ describe('execute', () => {
26
+ it('execute_msg_for__empty', () => {
27
+ expectCode(createTypeInterface(executeCtx, executeMessage));
28
+ });
29
+ it('query classes', () => {
30
+ expectCode(createQueryClass(executeCtx, 'QueryClient', 'ReadOnlyInstance', executeMessage));
31
+ });
32
+ it('query classes response', () => {
33
+ expectCode(createTypeInterface(executeCtx, contract.query));
34
+ });
35
+ it('execute classes array types', () => {
36
+ expectCode(createExecuteClass(executeCtx, 'Client', 'Instance', null, executeMessage));
37
+ });
38
+ it('execute interfaces no extends', () => {
39
+ expectCode(createExecuteInterface(executeCtx, 'SG721Instance', null, executeMessage));
40
+ });
41
+ });
@@ -1,8 +1,7 @@
1
1
  import * as t from '@babel/types';
2
2
  import { camel } from 'case';
3
- import { bindMethod, typedIdentifier, classDeclaration, classProperty, arrowFunctionExpression, getMessageProperties } from '../utils';
3
+ import { arrowFunctionExpression, bindMethod, classDeclaration, classProperty, getMessageProperties, OPTIONAL_FUNDS_PARAM, typedIdentifier } from '../utils';
4
4
  import { createTypedObjectParams } from '../utils/types';
5
- import { identifier } from '../utils/babel';
6
5
  import { getWasmMethodArgs } from '../client/client';
7
6
 
8
7
  const createWasmExecMethodMessageComposer = (context, jsonschema) => {
@@ -23,9 +22,9 @@ const createWasmExecMethodMessageComposer = (context, jsonschema) => {
23
22
  actionValue = t.objectExpression(args);
24
23
  }
25
24
 
26
- const constantParams = [identifier('funds', t.tsTypeAnnotation(t.tsArrayType(t.tsTypeReference(t.identifier('Coin')))), true)];
25
+ const constantParams = [OPTIONAL_FUNDS_PARAM];
27
26
  return t.classProperty(t.identifier(methodName), arrowFunctionExpression(param ? [// props
28
- param, ...constantParams] : constantParams, t.blockStatement([t.returnStatement(t.objectExpression([t.objectProperty(t.identifier('typeUrl'), t.stringLiteral('/cosmwasm.wasm.v1.MsgExecuteContract')), t.objectProperty(t.identifier('value'), t.callExpression(t.memberExpression(t.identifier('MsgExecuteContract'), t.identifier('fromPartial')), [t.objectExpression([t.objectProperty(t.identifier('sender'), t.memberExpression(t.thisExpression(), t.identifier('sender'))), t.objectProperty(t.identifier('contract'), t.memberExpression(t.thisExpression(), t.identifier('contractAddress'))), t.objectProperty(t.identifier('msg'), t.callExpression(t.identifier('toUtf8'), [t.callExpression(t.memberExpression(t.identifier('JSON'), t.identifier('stringify')), [t.objectExpression([t.objectProperty(t.identifier(underscoreName), actionValue)])])])), t.objectProperty(t.identifier('funds'), t.identifier('funds'), false, true)])]))]))]), // return type
27
+ param, ...constantParams] : constantParams, t.blockStatement([t.returnStatement(t.objectExpression([t.objectProperty(t.identifier('typeUrl'), t.stringLiteral('/cosmwasm.wasm.v1.MsgExecuteContract')), t.objectProperty(t.identifier('value'), t.callExpression(t.memberExpression(t.identifier('MsgExecuteContract'), t.identifier('fromPartial')), [t.objectExpression([t.objectProperty(t.identifier('sender'), t.memberExpression(t.thisExpression(), t.identifier('sender'))), t.objectProperty(t.identifier('contract'), t.memberExpression(t.thisExpression(), t.identifier('contractAddress'))), t.objectProperty(t.identifier('msg'), t.callExpression(t.identifier('toUtf8'), [t.callExpression(t.memberExpression(t.identifier('JSON'), t.identifier('stringify')), [t.objectExpression([t.objectProperty(t.identifier(underscoreName), actionValue)])])])), t.objectProperty(t.identifier('funds'), t.identifier('_funds'))])]))]))]), // return type
29
28
  t.tsTypeAnnotation(t.tsTypeReference(t.identifier('MsgExecuteContractEncodeObject'))), false));
30
29
  };
31
30
 
@@ -56,7 +55,7 @@ export const createMessageComposerInterface = (context, className, execMsg) => {
56
55
 
57
56
  const createPropertyFunctionWithObjectParamsForMessageComposer = (context, methodName, responseType, jsonschema) => {
58
57
  const obj = createTypedObjectParams(context, jsonschema);
59
- const fixedParams = [identifier('funds', t.tsTypeAnnotation(t.tsArrayType(t.tsTypeReference(t.identifier('Coin')))), true)];
58
+ const fixedParams = [OPTIONAL_FUNDS_PARAM];
60
59
  const func = {
61
60
  type: 'TSFunctionType',
62
61
  typeAnnotation: t.tsTypeAnnotation(t.tsTypeReference(t.identifier(responseType))),
@@ -1,9 +1,9 @@
1
1
  import * as t from '@babel/types';
2
2
  import { camel, pascal } from 'case';
3
- import { callExpression, createTypedObjectParams, getMessageProperties, identifier, tsObjectPattern, tsPropertySignature } from '../utils';
3
+ import { callExpression, createTypedObjectParams, getMessageProperties, identifier, OPTIONAL_FUNDS_PARAM, tsObjectPattern, tsPropertySignature } from '../utils';
4
4
  import { omitTypeReference, optionalConditionalExpression, propertySignature, shorthandProperty } from '../utils/babel';
5
5
  import { getPropertyType, getResponseType } from '../utils/types';
6
- import { FIXED_EXECUTE_PARAMS } from '../client';
6
+ import { OPTIONAL_FEE_PARAM, OPTIONAL_MEMO_PARAM } from '../utils/constants';
7
7
  export const createReactQueryHooks = ({
8
8
  context,
9
9
  queryMsg,
@@ -187,8 +187,7 @@ export const createReactQueryMutationArgsInterface = ({
187
187
  context.addUtil('StdFee');
188
188
  context.addUtil('Coin');
189
189
  const optionalArgs = t.tsPropertySignature(t.identifier('args'), t.tsTypeAnnotation( // @ts-ignore:next-line
190
- t.tsTypeLiteral(FIXED_EXECUTE_PARAMS.map(param => propertySignature(param.name, // @ts-ignore:next-line
191
- param.typeAnnotation, param.optional)))));
190
+ t.tsTypeLiteral([propertySignature('fee', OPTIONAL_FEE_PARAM.typeAnnotation, true), propertySignature('memo', OPTIONAL_MEMO_PARAM.typeAnnotation, true), propertySignature('funds', OPTIONAL_FUNDS_PARAM.typeAnnotation, true)])));
192
191
  optionalArgs.optional = true;
193
192
  body.push(optionalArgs);
194
193
  return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(mutationHookParamsTypeName), null, [], t.tsInterfaceBody(body)));
@@ -266,8 +265,8 @@ export const createReactQueryMutationHook = ({
266
265
  context.addUtil('UseMutationOptions');
267
266
  const useMutationFunctionArgs = [shorthandProperty('client')];
268
267
  if (hasMsg) useMutationFunctionArgs.push(shorthandProperty('msg'));
269
- useMutationFunctionArgs.push(t.objectProperty(t.identifier('args'), t.assignmentPattern(t.objectPattern(FIXED_EXECUTE_PARAMS.map(param => shorthandProperty(param.name))), t.objectExpression([]))));
270
- return t.exportNamedDeclaration(t.functionDeclaration(t.identifier(mutationHookName), [identifier('options', t.tsTypeAnnotation(omitTypeReference(t.tsTypeReference(t.identifier('UseMutationOptions'), useMutationTypeParameter), 'mutationFn')), true)], t.blockStatement([t.returnStatement(callExpression(t.identifier('useMutation'), [t.arrowFunctionExpression([t.objectPattern(useMutationFunctionArgs)], t.callExpression(t.memberExpression(t.identifier('client'), t.identifier(execMethodName)), (hasMsg ? [t.identifier('msg')] : []).concat(FIXED_EXECUTE_PARAMS.map(param => t.identifier(param.name)))), false // not async
268
+ useMutationFunctionArgs.push(t.objectProperty(t.identifier('args'), t.assignmentPattern(t.objectPattern([shorthandProperty('fee'), shorthandProperty('memo'), shorthandProperty('funds')]), t.objectExpression([]))));
269
+ return t.exportNamedDeclaration(t.functionDeclaration(t.identifier(mutationHookName), [identifier('options', t.tsTypeAnnotation(omitTypeReference(t.tsTypeReference(t.identifier('UseMutationOptions'), useMutationTypeParameter), 'mutationFn')), true)], t.blockStatement([t.returnStatement(callExpression(t.identifier('useMutation'), [t.arrowFunctionExpression([t.objectPattern(useMutationFunctionArgs)], t.callExpression(t.memberExpression(t.identifier('client'), t.identifier(execMethodName)), (hasMsg ? [t.identifier('msg')] : []).concat([t.identifier('fee'), t.identifier('memo'), t.identifier('funds')])), false // not async
271
270
  ), t.identifier('options')], useMutationTypeParameter))])));
272
271
  };
273
272
 
@@ -6,6 +6,7 @@ export const propertySignature = (name, typeAnnotation, optional = false) => {
6
6
  return {
7
7
  type: 'TSPropertySignature',
8
8
  key: t.identifier(name),
9
+ kind: 'get',
9
10
  typeAnnotation,
10
11
  optional
11
12
  };
@@ -0,0 +1,6 @@
1
+ import { identifier } from './babel';
2
+ import * as t from '@babel/types';
3
+ export const OPTIONAL_FUNDS_PARAM = identifier('_funds', t.tsTypeAnnotation(t.tsArrayType(t.tsTypeReference(t.identifier('Coin')))), true);
4
+ export const OPTIONAL_FEE_PARAM = identifier('fee', t.tsTypeAnnotation(t.tsUnionType([t.tsNumberKeyword(), t.tsTypeReference(t.identifier('StdFee')), t.tsLiteralType(t.stringLiteral('auto'))])), true);
5
+ export const OPTIONAL_MEMO_PARAM = identifier('memo', t.tsTypeAnnotation(t.tsStringKeyword()), true);
6
+ export const FIXED_EXECUTE_PARAMS = [OPTIONAL_FEE_PARAM, OPTIONAL_MEMO_PARAM, OPTIONAL_FUNDS_PARAM];
@@ -1,3 +1,5 @@
1
1
  export * from './babel';
2
2
  export * from './types';
3
- export * from './ref';
3
+ export * from './ref';
4
+ export { OPTIONAL_FUNDS_PARAM } from './constants';
5
+ export { FIXED_EXECUTE_PARAMS } from './constants';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wasm-ast-types",
3
- "version": "0.20.0",
3
+ "version": "0.22.0",
4
4
  "description": "CosmWasm TypeScript AST generation",
5
5
  "author": "Dan Lynch <pyramation@gmail.com>",
6
6
  "homepage": "https://github.com/pyramation/cosmwasm-typescript-gen/tree/master/packages/wasm-ast-types#readme",
@@ -88,5 +88,5 @@
88
88
  "case": "1.6.3",
89
89
  "deepmerge": "4.2.2"
90
90
  },
91
- "gitHead": "d2edba320c63e2db5fe2db0bfb1f4cd5e44f2188"
91
+ "gitHead": "45ac1ece2da95df09f949d692c95c66de0205408"
92
92
  }