wasm-ast-types 0.21.0 → 0.23.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/main/client/client.js +4 -6
- package/main/context/imports.js +1 -1
- package/main/message-composer/message-composer.js +3 -5
- package/main/react-query/react-query.js +4 -11
- package/main/utils/babel.js +1 -0
- package/main/utils/constants.js +25 -0
- package/main/utils/index.js +22 -1
- package/module/client/client.js +3 -4
- package/module/context/imports.js +1 -1
- package/module/message-composer/message-composer.js +4 -5
- package/module/react-query/react-query.js +5 -6
- package/module/utils/babel.js +1 -0
- package/module/utils/constants.js +6 -0
- package/module/utils/index.js +3 -1
- package/package.json +2 -2
- package/src/client/client.ts +235 -323
- package/src/client/test/__snapshots__/ts-client.account-nfts.spec.ts.snap +45 -45
- package/src/client/test/__snapshots__/ts-client.arrays-ref.spec.ts.snap +42 -42
- package/src/client/test/__snapshots__/ts-client.arrays.spec.ts.snap +3 -3
- package/src/client/test/__snapshots__/ts-client.cw-named-groups.test.ts.snap +9 -9
- package/src/client/test/__snapshots__/ts-client.cw-proposal-single.test.ts.snap +27 -27
- package/src/client/test/__snapshots__/ts-client.issue-101.spec.ts.snap +6 -6
- package/src/client/test/__snapshots__/ts-client.issue-71.test.ts.snap +30 -30
- package/src/client/test/__snapshots__/ts-client.issue-98.test.ts.snap +9 -9
- package/src/client/test/__snapshots__/ts-client.issues.test.ts.snap +78 -78
- package/src/client/test/__snapshots__/ts-client.overrides.spec.ts.snap +80 -80
- package/src/client/test/__snapshots__/ts-client.sg721.spec.ts.snap +24 -24
- package/src/client/test/__snapshots__/ts-client.spec.ts.snap +46 -46
- package/src/client/test/__snapshots__/ts-client.vectis.spec.ts.snap +24 -24
- package/src/client/test/__snapshots__/ts-client.wager.spec.ts.snap +8 -8
- package/src/context/context.ts +2 -0
- package/src/context/imports.ts +1 -1
- package/src/message-composer/__snapshots__/message-composer.spec.ts.snap +30 -30
- package/src/message-composer/message-composer.ts +216 -267
- package/src/react-query/react-query.ts +28 -25
- package/src/utils/babel.ts +4 -3
- package/src/utils/constants.ts +30 -0
- package/src/utils/index.ts +2 -0
- package/types/context/context.d.ts +2 -0
package/main/client/client.js
CHANGED
@@ -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.
|
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),
|
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('
|
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));
|
package/main/context/imports.js
CHANGED
@@ -43,7 +43,7 @@ var makeReactQuerySwitch = function makeReactQuerySwitch(varName) {
|
|
43
43
|
var UTILS = {
|
44
44
|
selectorFamily: 'recoil',
|
45
45
|
MsgExecuteContract: 'cosmjs-types/cosmwasm/wasm/v1/tx',
|
46
|
-
MsgExecuteContractEncodeObject: 'cosmwasm',
|
46
|
+
MsgExecuteContractEncodeObject: '@cosmjs/cosmwasm-stargate',
|
47
47
|
Coin: '@cosmjs/amino',
|
48
48
|
toUtf8: '@cosmjs/encoding',
|
49
49
|
StdFee: '@cosmjs/amino',
|
@@ -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 = [
|
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('
|
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 = [
|
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
|
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(
|
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(
|
309
|
-
|
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
|
|
package/main/utils/babel.js
CHANGED
@@ -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;
|
package/main/utils/index.js
CHANGED
@@ -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");
|
package/module/client/client.js
CHANGED
@@ -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),
|
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('
|
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) => {
|
@@ -25,7 +25,7 @@ const makeReactQuerySwitch = varName => {
|
|
25
25
|
export const UTILS = {
|
26
26
|
selectorFamily: 'recoil',
|
27
27
|
MsgExecuteContract: 'cosmjs-types/cosmwasm/wasm/v1/tx',
|
28
|
-
MsgExecuteContractEncodeObject: 'cosmwasm',
|
28
|
+
MsgExecuteContractEncodeObject: '@cosmjs/cosmwasm-stargate',
|
29
29
|
Coin: '@cosmjs/amino',
|
30
30
|
toUtf8: '@cosmjs/encoding',
|
31
31
|
StdFee: '@cosmjs/amino',
|
@@ -1,8 +1,7 @@
|
|
1
1
|
import * as t from '@babel/types';
|
2
2
|
import { camel } from 'case';
|
3
|
-
import {
|
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 = [
|
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('
|
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 = [
|
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 {
|
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(
|
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(
|
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(
|
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
|
|
package/module/utils/babel.js
CHANGED
@@ -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];
|
package/module/utils/index.js
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "wasm-ast-types",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.23.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": "
|
91
|
+
"gitHead": "9979ae4b7209f920fe1b822ede2ba80ee0f2eade"
|
92
92
|
}
|