wasm-ast-types 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- package/main/{wasm.js → client/client.js} +54 -40
- package/main/client/index.js +18 -0
- package/main/client/test/ts-client.arrays.spec.js +25 -0
- package/main/client/test/ts-client.cw-named-groups.test.js +25 -0
- package/main/client/test/ts-client.cw-proposal-single.test.js +30 -0
- package/main/client/test/ts-client.empty-enums.spec.js +19 -0
- package/main/client/test/ts-client.sg721.spec.js +25 -0
- package/main/client/test/ts-client.spec.js +106 -0
- package/main/client/test/ts-client.vectis.spec.js +56 -0
- package/main/context/context.js +48 -0
- package/main/context/index.js +18 -0
- package/main/{messages.js → from-partial/from-partial.js} +17 -60
- package/main/from-partial/from-partial.spec.js +20 -0
- package/main/from-partial/index.js +18 -0
- package/main/index.js +34 -8
- package/main/react-query/index.js +18 -0
- package/main/{react-query.js → react-query/react-query.js} +39 -64
- package/main/{react-query.spec.js → react-query/react-query.spec.js} +33 -43
- package/main/recoil/index.js +18 -0
- package/main/{recoil.js → recoil/recoil.js} +7 -26
- package/main/{recoil.spec.js → recoil/recoil.spec.js} +9 -14
- package/main/utils/babel.spec.js +7 -15
- package/main/utils/index.js +13 -0
- package/main/utils/types.js +34 -32
- package/module/{wasm.js → client/client.js} +43 -33
- package/module/client/index.js +1 -0
- package/module/client/test/ts-client.arrays.spec.js +17 -0
- package/module/client/test/ts-client.cw-named-groups.test.js +17 -0
- package/module/client/test/ts-client.cw-proposal-single.test.js +21 -0
- package/module/client/test/ts-client.empty-enums.spec.js +11 -0
- package/module/client/test/ts-client.sg721.spec.js +17 -0
- package/module/client/test/ts-client.spec.js +85 -0
- package/module/client/test/ts-client.vectis.spec.js +44 -0
- package/module/context/context.js +25 -0
- package/module/context/index.js +1 -0
- package/module/{messages.js → from-partial/from-partial.js} +16 -57
- package/module/from-partial/from-partial.spec.js +12 -0
- package/module/from-partial/index.js +1 -0
- package/module/index.js +5 -3
- package/module/react-query/index.js +1 -0
- package/module/{react-query.js → react-query/react-query.js} +30 -49
- package/module/react-query/react-query.spec.js +53 -0
- package/module/recoil/index.js +1 -0
- package/module/{recoil.js → recoil/recoil.js} +6 -20
- package/module/recoil/recoil.spec.js +15 -0
- package/module/utils/babel.spec.js +1 -10
- package/module/utils/index.js +2 -1
- package/module/utils/types.js +32 -30
- package/package.json +4 -3
- package/types/src/client/client.d.ts +17 -0
- package/types/src/client/index.d.ts +1 -0
- package/types/src/client/test/ts-client.cw-named-groups.test.d.ts +1 -0
- package/types/src/client/test/ts-client.cw-proposal-single.test.d.ts +1 -0
- package/types/src/context/context.d.ts +20 -0
- package/types/src/context/index.d.ts +1 -0
- package/types/src/from-partial/from-partial.d.ts +4 -0
- package/types/src/from-partial/index.d.ts +1 -0
- package/types/src/index.d.ts +7 -0
- package/types/src/react-query/index.d.ts +1 -0
- package/types/src/react-query/react-query.d.ts +81 -0
- package/types/src/recoil/index.d.ts +1 -0
- package/types/{recoil.d.ts → src/recoil/recoil.d.ts} +5 -5
- package/types/{types.d.ts → src/types.d.ts} +17 -0
- package/types/{utils.d.ts → src/utils/babel.d.ts} +21 -1
- package/types/src/utils/index.d.ts +2 -0
- package/types/src/utils/types.d.ts +18 -0
- package/types/test-utils/index.d.ts +2 -0
- package/main/messages.spec.js +0 -24
- package/main/wasm.arrays.spec.js +0 -30
- package/main/wasm.cw-named-groups.test.js +0 -30
- package/main/wasm.cw-proposal-single.test.js +0 -32
- package/main/wasm.empty-enums.spec.js +0 -24
- package/main/wasm.sg721.spec.js +0 -30
- package/main/wasm.spec.js +0 -95
- package/main/wasm.vectis.spec.js +0 -53
- package/module/messages.spec.js +0 -18
- package/module/react-query.spec.js +0 -65
- package/module/recoil.spec.js +0 -22
- package/module/wasm.arrays.spec.js +0 -24
- package/module/wasm.cw-named-groups.test.js +0 -24
- package/module/wasm.cw-proposal-single.test.js +0 -25
- package/module/wasm.empty-enums.spec.js +0 -18
- package/module/wasm.sg721.spec.js +0 -24
- package/module/wasm.spec.js +0 -76
- package/module/wasm.vectis.spec.js +0 -43
- package/types/amino/amino-interfaces.d.ts +0 -6
- package/types/amino/from-amino.d.ts +0 -13
- package/types/amino/index.d.ts +0 -3
- package/types/amino/to-amino.d.ts +0 -11
- package/types/index.d.ts +0 -5
- package/types/messages.d.ts +0 -4
- package/types/react-query.d.ts +0 -70
- package/types/wasm.d.ts +0 -24
@@ -15,56 +15,30 @@ var t = _interopRequireWildcard(require("@babel/types"));
|
|
15
15
|
|
16
16
|
var _case = require("case");
|
17
17
|
|
18
|
-
var _utils = require("
|
18
|
+
var _utils = require("../utils");
|
19
19
|
|
20
|
-
var _types2 = require("
|
20
|
+
var _types2 = require("../utils/types");
|
21
21
|
|
22
|
-
var _babel = require("
|
22
|
+
var _babel = require("../utils/babel");
|
23
|
+
|
24
|
+
var _client = require("../client/client");
|
23
25
|
|
24
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); }
|
25
27
|
|
26
28
|
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
29
|
|
28
|
-
var createWasmExecMethodPartial = function createWasmExecMethodPartial(jsonschema) {
|
29
|
-
var _jsonschema$propertie;
|
30
|
-
|
30
|
+
var createWasmExecMethodPartial = function createWasmExecMethodPartial(context, jsonschema) {
|
31
31
|
var underscoreName = Object.keys(jsonschema.properties)[0];
|
32
32
|
var methodName = (0, _case.camel)(underscoreName);
|
33
|
-
var
|
34
|
-
var
|
35
|
-
var
|
36
|
-
return t.objectProperty(t.identifier(prop), t.identifier((0, _case.camel)(prop)), false, prop === (0, _case.camel)(prop));
|
37
|
-
});
|
38
|
-
var constantParams = [// t.assignmentPattern(
|
39
|
-
// identifier(
|
40
|
-
// 'fee',
|
41
|
-
// t.tsTypeAnnotation(
|
42
|
-
// t.tsUnionType(
|
43
|
-
// [
|
44
|
-
// t.tSNumberKeyword(),
|
45
|
-
// t.tsTypeReference(
|
46
|
-
// t.identifier('StdFee')
|
47
|
-
// ),
|
48
|
-
// t.tsLiteralType(
|
49
|
-
// t.stringLiteral('auto')
|
50
|
-
// )
|
51
|
-
// ]
|
52
|
-
// )
|
53
|
-
// ),
|
54
|
-
// false
|
55
|
-
// ),
|
56
|
-
// t.stringLiteral('auto')
|
57
|
-
// ),
|
58
|
-
// identifier('memo', t.tsTypeAnnotation(
|
59
|
-
// t.tsStringKeyword()
|
60
|
-
// ), true),
|
61
|
-
(0, _babel.identifier)('funds', t.tsTypeAnnotation((0, _babel.tsTypeOperator)(t.tsArrayType(t.tsTypeReference(t.identifier('Coin'))), 'readonly')), true)];
|
33
|
+
var obj = (0, _types2.createTypedObjectParams)(context, jsonschema.properties[underscoreName]);
|
34
|
+
var args = (0, _client.getWasmMethodArgs)(context, jsonschema.properties[underscoreName]);
|
35
|
+
var constantParams = [(0, _babel.identifier)('funds', t.tsTypeAnnotation(t.tsArrayType(t.tsTypeReference(t.identifier('Coin')))), true)];
|
62
36
|
return t.classProperty(t.identifier(methodName), (0, _utils.arrowFunctionExpression)(obj ? [// props
|
63
37
|
obj].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), t.objectExpression(args))])])])), t.objectProperty(t.identifier('funds'), t.identifier('funds'), false, true)])]))]))]), // return type
|
64
38
|
t.tsTypeAnnotation(t.tsTypeReference(t.identifier('MsgExecuteContractEncodeObject'))), false));
|
65
39
|
};
|
66
40
|
|
67
|
-
var createFromPartialClass = function createFromPartialClass(className, implementsClassName, execMsg) {
|
41
|
+
var createFromPartialClass = function createFromPartialClass(context, className, implementsClassName, execMsg) {
|
68
42
|
var propertyNames = (0, _utils.getMessageProperties)(execMsg).map(function (method) {
|
69
43
|
var _Object$keys;
|
70
44
|
|
@@ -72,7 +46,7 @@ var createFromPartialClass = function createFromPartialClass(className, implemen
|
|
72
46
|
}).filter(Boolean);
|
73
47
|
var bindings = propertyNames.map(_case.camel).map(_utils.bindMethod);
|
74
48
|
var methods = (0, _utils.getMessageProperties)(execMsg).map(function (schema) {
|
75
|
-
return createWasmExecMethodPartial(schema);
|
49
|
+
return createWasmExecMethodPartial(context, schema);
|
76
50
|
});
|
77
51
|
var blockStmt = [];
|
78
52
|
[].push.apply(blockStmt, [t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier('sender')), t.identifier('sender'))), t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier('contractAddress')), t.identifier('contractAddress')))].concat((0, _toConsumableArray2["default"])(bindings)));
|
@@ -84,40 +58,23 @@ var createFromPartialClass = function createFromPartialClass(className, implemen
|
|
84
58
|
|
85
59
|
exports.createFromPartialClass = createFromPartialClass;
|
86
60
|
|
87
|
-
var createFromPartialInterface = function createFromPartialInterface(className, execMsg) {
|
61
|
+
var createFromPartialInterface = function createFromPartialInterface(context, className, execMsg) {
|
88
62
|
var methods = (0, _utils.getMessageProperties)(execMsg).map(function (jsonschema) {
|
89
63
|
var underscoreName = Object.keys(jsonschema.properties)[0];
|
90
64
|
var methodName = (0, _case.camel)(underscoreName);
|
91
|
-
return createPropertyFunctionWithObjectParamsForPartial(methodName, 'MsgExecuteContractEncodeObject', jsonschema.properties[underscoreName]);
|
65
|
+
return createPropertyFunctionWithObjectParamsForPartial(context, methodName, 'MsgExecuteContractEncodeObject', jsonschema.properties[underscoreName]);
|
92
66
|
});
|
93
67
|
var extendsAst = [];
|
94
68
|
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(className), null, extendsAst, t.tSInterfaceBody([// contract address
|
95
69
|
t.tSPropertySignature(t.identifier('contractAddress'), t.tsTypeAnnotation(t.tsStringKeyword())), // contract address
|
96
70
|
t.tSPropertySignature(t.identifier('sender'), t.tsTypeAnnotation(t.tsStringKeyword()))].concat((0, _toConsumableArray2["default"])(methods)))));
|
97
|
-
};
|
98
|
-
|
71
|
+
};
|
99
72
|
|
100
73
|
exports.createFromPartialInterface = createFromPartialInterface;
|
101
74
|
|
102
|
-
var createPropertyFunctionWithObjectParamsForPartial = function createPropertyFunctionWithObjectParamsForPartial(methodName, responseType, jsonschema) {
|
103
|
-
var obj = (0, _types2.createTypedObjectParams)(jsonschema);
|
104
|
-
var fixedParams = [
|
105
|
-
// t.tsUnionType(
|
106
|
-
// [
|
107
|
-
// t.tsNumberKeyword(),
|
108
|
-
// t.tsTypeReference(
|
109
|
-
// t.identifier('StdFee')
|
110
|
-
// ),
|
111
|
-
// t.tsLiteralType(
|
112
|
-
// t.stringLiteral('auto')
|
113
|
-
// )
|
114
|
-
// ]
|
115
|
-
// )
|
116
|
-
// ), true),
|
117
|
-
// identifier('memo', t.tsTypeAnnotation(
|
118
|
-
// t.tsStringKeyword()
|
119
|
-
// ), true),
|
120
|
-
(0, _babel.identifier)('funds', t.tsTypeAnnotation((0, _babel.tsTypeOperator)(t.tsArrayType(t.tsTypeReference(t.identifier('Coin'))), 'readonly')), true)];
|
75
|
+
var createPropertyFunctionWithObjectParamsForPartial = function createPropertyFunctionWithObjectParamsForPartial(context, methodName, responseType, jsonschema) {
|
76
|
+
var obj = (0, _types2.createTypedObjectParams)(context, jsonschema);
|
77
|
+
var fixedParams = [(0, _babel.identifier)('funds', t.tsTypeAnnotation(t.tsArrayType(t.tsTypeReference(t.identifier('Coin')))), true)];
|
121
78
|
var func = {
|
122
79
|
type: 'TSFunctionType',
|
123
80
|
typeAnnotation: t.tsTypeAnnotation(t.tsTypeReference(t.identifier(responseType))),
|
@@ -0,0 +1,20 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
var _execute_msg_for__empty = _interopRequireDefault(require("../../../../__fixtures__/basic/execute_msg_for__empty.json"));
|
6
|
+
|
7
|
+
var _fromPartial = require("./from-partial");
|
8
|
+
|
9
|
+
var _context = require("../context");
|
10
|
+
|
11
|
+
var _testUtils = require("../../test-utils");
|
12
|
+
|
13
|
+
it('execute classes', function () {
|
14
|
+
var ctx = new _context.RenderContext(_execute_msg_for__empty["default"]);
|
15
|
+
(0, _testUtils.expectCode)((0, _fromPartial.createFromPartialClass)(ctx, 'SG721MessageComposer', 'SG721Message', _execute_msg_for__empty["default"]));
|
16
|
+
});
|
17
|
+
it('createFromPartialInterface', function () {
|
18
|
+
var ctx = new _context.RenderContext(_execute_msg_for__empty["default"]);
|
19
|
+
(0, _testUtils.expectCode)((0, _fromPartial.createFromPartialInterface)(ctx, 'SG721Message', _execute_msg_for__empty["default"]));
|
20
|
+
});
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
|
7
|
+
var _fromPartial = require("./from-partial");
|
8
|
+
|
9
|
+
Object.keys(_fromPartial).forEach(function (key) {
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
11
|
+
if (key in exports && exports[key] === _fromPartial[key]) return;
|
12
|
+
Object.defineProperty(exports, key, {
|
13
|
+
enumerable: true,
|
14
|
+
get: function get() {
|
15
|
+
return _fromPartial[key];
|
16
|
+
}
|
17
|
+
});
|
18
|
+
});
|
package/main/index.js
CHANGED
@@ -17,15 +17,28 @@ Object.keys(_utils).forEach(function (key) {
|
|
17
17
|
});
|
18
18
|
});
|
19
19
|
|
20
|
-
var
|
20
|
+
var _client = require("./client");
|
21
21
|
|
22
|
-
Object.keys(
|
22
|
+
Object.keys(_client).forEach(function (key) {
|
23
23
|
if (key === "default" || key === "__esModule") return;
|
24
|
-
if (key in exports && exports[key] ===
|
24
|
+
if (key in exports && exports[key] === _client[key]) return;
|
25
25
|
Object.defineProperty(exports, key, {
|
26
26
|
enumerable: true,
|
27
27
|
get: function get() {
|
28
|
-
return
|
28
|
+
return _client[key];
|
29
|
+
}
|
30
|
+
});
|
31
|
+
});
|
32
|
+
|
33
|
+
var _context = require("./context");
|
34
|
+
|
35
|
+
Object.keys(_context).forEach(function (key) {
|
36
|
+
if (key === "default" || key === "__esModule") return;
|
37
|
+
if (key in exports && exports[key] === _context[key]) return;
|
38
|
+
Object.defineProperty(exports, key, {
|
39
|
+
enumerable: true,
|
40
|
+
get: function get() {
|
41
|
+
return _context[key];
|
29
42
|
}
|
30
43
|
});
|
31
44
|
});
|
@@ -43,15 +56,15 @@ Object.keys(_recoil).forEach(function (key) {
|
|
43
56
|
});
|
44
57
|
});
|
45
58
|
|
46
|
-
var
|
59
|
+
var _fromPartial = require("./from-partial");
|
47
60
|
|
48
|
-
Object.keys(
|
61
|
+
Object.keys(_fromPartial).forEach(function (key) {
|
49
62
|
if (key === "default" || key === "__esModule") return;
|
50
|
-
if (key in exports && exports[key] ===
|
63
|
+
if (key in exports && exports[key] === _fromPartial[key]) return;
|
51
64
|
Object.defineProperty(exports, key, {
|
52
65
|
enumerable: true,
|
53
66
|
get: function get() {
|
54
|
-
return
|
67
|
+
return _fromPartial[key];
|
55
68
|
}
|
56
69
|
});
|
57
70
|
});
|
@@ -67,4 +80,17 @@ Object.keys(_reactQuery).forEach(function (key) {
|
|
67
80
|
return _reactQuery[key];
|
68
81
|
}
|
69
82
|
});
|
83
|
+
});
|
84
|
+
|
85
|
+
var _types = require("./types");
|
86
|
+
|
87
|
+
Object.keys(_types).forEach(function (key) {
|
88
|
+
if (key === "default" || key === "__esModule") return;
|
89
|
+
if (key in exports && exports[key] === _types[key]) return;
|
90
|
+
Object.defineProperty(exports, key, {
|
91
|
+
enumerable: true,
|
92
|
+
get: function get() {
|
93
|
+
return _types[key];
|
94
|
+
}
|
95
|
+
});
|
70
96
|
});
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
|
7
|
+
var _reactQuery = require("./react-query");
|
8
|
+
|
9
|
+
Object.keys(_reactQuery).forEach(function (key) {
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
11
|
+
if (key in exports && exports[key] === _reactQuery[key]) return;
|
12
|
+
Object.defineProperty(exports, key, {
|
13
|
+
enumerable: true,
|
14
|
+
get: function get() {
|
15
|
+
return _reactQuery[key];
|
16
|
+
}
|
17
|
+
});
|
18
|
+
});
|
@@ -11,42 +11,28 @@ exports.createReactQueryMutationHooks = exports.createReactQueryMutationHook = e
|
|
11
11
|
|
12
12
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
13
13
|
|
14
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
15
|
-
|
16
14
|
var t = _interopRequireWildcard(require("@babel/types"));
|
17
15
|
|
18
16
|
var _case = require("case");
|
19
17
|
|
20
|
-
var _utils = require("
|
18
|
+
var _utils = require("../utils");
|
21
19
|
|
22
|
-
var _babel = require("
|
20
|
+
var _babel = require("../utils/babel");
|
23
21
|
|
24
|
-
var _types2 = require("
|
22
|
+
var _types2 = require("../utils/types");
|
25
23
|
|
26
|
-
var
|
24
|
+
var _client = require("../client");
|
27
25
|
|
28
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); }
|
29
27
|
|
30
28
|
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; }
|
31
29
|
|
32
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
33
|
-
|
34
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
35
|
-
|
36
|
-
var DEFAULT_OPTIONS = {
|
37
|
-
optionalClient: false,
|
38
|
-
v4: false,
|
39
|
-
mutations: false
|
40
|
-
};
|
41
|
-
|
42
30
|
var createReactQueryHooks = function createReactQueryHooks(_ref) {
|
43
|
-
var
|
31
|
+
var context = _ref.context,
|
32
|
+
queryMsg = _ref.queryMsg,
|
44
33
|
contractName = _ref.contractName,
|
45
|
-
QueryClient = _ref.QueryClient
|
46
|
-
|
47
|
-
options = _ref$options === void 0 ? {} : _ref$options;
|
48
|
-
// merge the user options with the defaults
|
49
|
-
options = _objectSpread(_objectSpread({}, DEFAULT_OPTIONS), options);
|
34
|
+
QueryClient = _ref.QueryClient;
|
35
|
+
var options = context.options.reactQuery;
|
50
36
|
return (0, _utils.getMessageProperties)(queryMsg).reduce(function (m, schema) {
|
51
37
|
var underscoreName = Object.keys(schema.properties)[0];
|
52
38
|
var methodName = (0, _case.camel)(underscoreName);
|
@@ -56,19 +42,20 @@ var createReactQueryHooks = function createReactQueryHooks(_ref) {
|
|
56
42
|
var getterKey = (0, _case.camel)("".concat(contractName).concat((0, _case.pascal)(methodName)));
|
57
43
|
var jsonschema = schema.properties[underscoreName];
|
58
44
|
return [createReactQueryHookInterface({
|
45
|
+
context: context,
|
59
46
|
hookParamsTypeName: hookParamsTypeName,
|
60
47
|
responseType: responseType,
|
61
48
|
QueryClient: QueryClient,
|
62
49
|
jsonschema: jsonschema,
|
63
50
|
options: options
|
64
51
|
}), createReactQueryHook({
|
52
|
+
context: context,
|
65
53
|
methodName: methodName,
|
66
54
|
hookName: hookName,
|
67
55
|
hookParamsTypeName: hookParamsTypeName,
|
68
56
|
responseType: responseType,
|
69
57
|
hookKeyName: getterKey,
|
70
|
-
jsonschema: jsonschema
|
71
|
-
options: options
|
58
|
+
jsonschema: jsonschema
|
72
59
|
})].concat((0, _toConsumableArray2["default"])(m));
|
73
60
|
}, []);
|
74
61
|
};
|
@@ -78,16 +65,14 @@ exports.createReactQueryHooks = createReactQueryHooks;
|
|
78
65
|
var createReactQueryHook = function createReactQueryHook(_ref2) {
|
79
66
|
var _jsonschema$propertie;
|
80
67
|
|
81
|
-
var
|
68
|
+
var context = _ref2.context,
|
69
|
+
hookName = _ref2.hookName,
|
82
70
|
hookParamsTypeName = _ref2.hookParamsTypeName,
|
83
71
|
responseType = _ref2.responseType,
|
84
72
|
hookKeyName = _ref2.hookKeyName,
|
85
73
|
methodName = _ref2.methodName,
|
86
|
-
jsonschema = _ref2.jsonschema
|
87
|
-
|
88
|
-
options = _ref2$options === void 0 ? {} : _ref2$options;
|
89
|
-
// merge the user options with the defaults
|
90
|
-
options = _objectSpread(_objectSpread({}, DEFAULT_OPTIONS), options);
|
74
|
+
jsonschema = _ref2.jsonschema;
|
75
|
+
var options = context.options.reactQuery;
|
91
76
|
var keys = Object.keys((_jsonschema$propertie = jsonschema.properties) !== null && _jsonschema$propertie !== void 0 ? _jsonschema$propertie : {});
|
92
77
|
var args = [];
|
93
78
|
|
@@ -128,32 +113,21 @@ export interface Cw4UpdateMembersMutation {
|
|
128
113
|
```
|
129
114
|
*/
|
130
115
|
var createReactQueryMutationArgsInterface = function createReactQueryMutationArgsInterface(_ref3) {
|
131
|
-
var
|
132
|
-
|
133
|
-
var ExecuteClient = _ref3.ExecuteClient,
|
116
|
+
var context = _ref3.context,
|
117
|
+
ExecuteClient = _ref3.ExecuteClient,
|
134
118
|
mutationHookParamsTypeName = _ref3.mutationHookParamsTypeName,
|
135
119
|
useMutationTypeParameter = _ref3.useMutationTypeParameter,
|
136
120
|
jsonschema = _ref3.jsonschema;
|
137
121
|
var typedUseMutationOptions = t.tsTypeReference(t.identifier('UseMutationOptions'), useMutationTypeParameter);
|
138
122
|
var body = [(0, _utils.tsPropertySignature)(t.identifier('client'), t.tsTypeAnnotation(t.tsTypeReference(t.identifier(ExecuteClient))), false)];
|
139
|
-
var msgType = (0, _types2.getParamsTypeAnnotation)(jsonschema);
|
140
|
-
|
141
|
-
if (!msgType && jsonschema !== null && jsonschema !== void 0 && (_jsonschema$$ref = jsonschema.$ref) !== null && _jsonschema$$ref !== void 0 && _jsonschema$$ref.startsWith('#/definitions/')) {
|
142
|
-
var refName = jsonschema === null || jsonschema === void 0 ? void 0 : jsonschema.$ref;
|
143
|
-
|
144
|
-
if (/_for_[A-Z]/.test(refName)) {
|
145
|
-
refName = refName.replace(/_for_/, 'For');
|
146
|
-
}
|
147
|
-
|
148
|
-
msgType = t.tsTypeAnnotation((0, _types2.getTypeFromRef)(refName));
|
149
|
-
}
|
123
|
+
var msgType = (0, _types2.getParamsTypeAnnotation)(context, jsonschema);
|
150
124
|
|
151
125
|
if (msgType) {
|
152
126
|
body.push(t.tsPropertySignature(t.identifier('msg'), msgType));
|
153
|
-
} // fee: number | StdFee | "auto" = "auto", memo?: string, funds?:
|
127
|
+
} // fee: number | StdFee | "auto" = "auto", memo?: string, funds?: Coin[]
|
154
128
|
|
155
129
|
|
156
|
-
var optionalArgs = t.tsPropertySignature(t.identifier('args'), t.tsTypeAnnotation(t.tsTypeLiteral(
|
130
|
+
var optionalArgs = t.tsPropertySignature(t.identifier('args'), t.tsTypeAnnotation(t.tsTypeLiteral(_client.FIXED_EXECUTE_PARAMS.map(function (param) {
|
157
131
|
return (0, _babel.propertySignature)(param.name, param.typeAnnotation, param.optional);
|
158
132
|
}))));
|
159
133
|
optionalArgs.optional = true;
|
@@ -164,11 +138,10 @@ var createReactQueryMutationArgsInterface = function createReactQueryMutationArg
|
|
164
138
|
exports.createReactQueryMutationArgsInterface = createReactQueryMutationArgsInterface;
|
165
139
|
|
166
140
|
var createReactQueryMutationHooks = function createReactQueryMutationHooks(_ref4) {
|
167
|
-
var
|
141
|
+
var context = _ref4.context,
|
142
|
+
execMsg = _ref4.execMsg,
|
168
143
|
contractName = _ref4.contractName,
|
169
|
-
ExecuteClient = _ref4.ExecuteClient
|
170
|
-
_ref4$options = _ref4.options,
|
171
|
-
options = _ref4$options === void 0 ? {} : _ref4$options;
|
144
|
+
ExecuteClient = _ref4.ExecuteClient;
|
172
145
|
// merge the user options with the defaults
|
173
146
|
return (0, _utils.getMessageProperties)(execMsg).reduce(function (m, schema) {
|
174
147
|
var _jsonschema$propertie2, _Object$keys;
|
@@ -188,11 +161,13 @@ var createReactQueryMutationHooks = function createReactQueryMutationHooks(_ref4
|
|
188
161
|
|
189
162
|
var useMutationTypeParameter = generateMutationTypeParameter(mutationHookParamsTypeName, hasMsg);
|
190
163
|
return [createReactQueryMutationArgsInterface({
|
164
|
+
context: context,
|
191
165
|
mutationHookParamsTypeName: mutationHookParamsTypeName,
|
192
166
|
ExecuteClient: ExecuteClient,
|
193
167
|
jsonschema: jsonschema,
|
194
168
|
useMutationTypeParameter: useMutationTypeParameter
|
195
169
|
}), createReactQueryMutationHook({
|
170
|
+
context: context,
|
196
171
|
execMethodName: execMethodName,
|
197
172
|
mutationHookName: mutationHookName,
|
198
173
|
mutationHookParamsTypeName: mutationHookParamsTypeName,
|
@@ -227,17 +202,18 @@ export const useCw4UpdateMembersMutation = ({ client, options }: Omit<Cw4UpdateM
|
|
227
202
|
```
|
228
203
|
*/
|
229
204
|
var createReactQueryMutationHook = function createReactQueryMutationHook(_ref5) {
|
230
|
-
var
|
205
|
+
var context = _ref5.context,
|
206
|
+
mutationHookName = _ref5.mutationHookName,
|
231
207
|
mutationHookParamsTypeName = _ref5.mutationHookParamsTypeName,
|
232
208
|
execMethodName = _ref5.execMethodName,
|
233
209
|
useMutationTypeParameter = _ref5.useMutationTypeParameter,
|
234
210
|
hasMsg = _ref5.hasMsg;
|
235
211
|
var useMutationFunctionArgs = [(0, _babel.shorthandProperty)('client')];
|
236
212
|
if (hasMsg) useMutationFunctionArgs.push((0, _babel.shorthandProperty)('msg'));
|
237
|
-
useMutationFunctionArgs.push(t.objectProperty(t.identifier('args'), t.assignmentPattern(t.objectPattern(
|
213
|
+
useMutationFunctionArgs.push(t.objectProperty(t.identifier('args'), t.assignmentPattern(t.objectPattern(_client.FIXED_EXECUTE_PARAMS.map(function (param) {
|
238
214
|
return (0, _babel.shorthandProperty)(param.name);
|
239
215
|
})), t.objectExpression([]))));
|
240
|
-
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(
|
216
|
+
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) {
|
241
217
|
return t.identifier(param.name);
|
242
218
|
}))), false // not async
|
243
219
|
), t.identifier('options')], useMutationTypeParameter))])));
|
@@ -246,17 +222,16 @@ var createReactQueryMutationHook = function createReactQueryMutationHook(_ref5)
|
|
246
222
|
exports.createReactQueryMutationHook = createReactQueryMutationHook;
|
247
223
|
|
248
224
|
var createReactQueryHookInterface = function createReactQueryHookInterface(_ref6) {
|
249
|
-
var
|
225
|
+
var context = _ref6.context,
|
226
|
+
QueryClient = _ref6.QueryClient,
|
250
227
|
hookParamsTypeName = _ref6.hookParamsTypeName,
|
251
228
|
responseType = _ref6.responseType,
|
252
|
-
jsonschema = _ref6.jsonschema
|
253
|
-
_ref6$options = _ref6.options,
|
254
|
-
options = _ref6$options === void 0 ? {} : _ref6$options;
|
229
|
+
jsonschema = _ref6.jsonschema;
|
255
230
|
// merge the user options with the defaults
|
256
|
-
options =
|
231
|
+
var options = context.options.reactQuery;
|
257
232
|
var typedUseQueryOptions = t.tsTypeReference(t.identifier('UseQueryOptions'), t.tsTypeParameterInstantiation([(0, _babel.typeRefOrOptionalUnion)(t.identifier(responseType), options.optionalClient), t.tsTypeReference(t.identifier('Error')), t.tsTypeReference(t.identifier(responseType)), t.tsArrayType(t.tsParenthesizedType(t.tsUnionType([t.tsStringKeyword(), t.tsUndefinedKeyword()])))]));
|
258
233
|
var body = [(0, _utils.tsPropertySignature)(t.identifier('client'), t.tsTypeAnnotation(t.tsTypeReference(t.identifier(QueryClient))), options.optionalClient), (0, _utils.tsPropertySignature)(t.identifier('options'), t.tsTypeAnnotation(options.v4 ? t.tSIntersectionType([(0, _babel.omitTypeReference)(typedUseQueryOptions, "'queryKey' | 'queryFn' | 'initialData'"), t.tSTypeLiteral([t.tsPropertySignature(t.identifier('initialData?'), t.tsTypeAnnotation(t.tsUndefinedKeyword()))])]) : typedUseQueryOptions), true)];
|
259
|
-
var props = getProps(
|
234
|
+
var props = getProps(context, jsonschema);
|
260
235
|
|
261
236
|
if (props.length) {
|
262
237
|
body.push(t.tsPropertySignature(t.identifier('args'), t.tsTypeAnnotation(t.tsTypeLiteral(props))));
|
@@ -267,21 +242,21 @@ var createReactQueryHookInterface = function createReactQueryHookInterface(_ref6
|
|
267
242
|
|
268
243
|
exports.createReactQueryHookInterface = createReactQueryHookInterface;
|
269
244
|
|
270
|
-
var getProps = function getProps(
|
245
|
+
var getProps = function getProps(context, jsonschema) {
|
271
246
|
var _jsonschema$propertie3;
|
272
247
|
|
273
248
|
var keys = Object.keys((_jsonschema$propertie3 = jsonschema.properties) !== null && _jsonschema$propertie3 !== void 0 ? _jsonschema$propertie3 : {});
|
274
249
|
if (!keys.length) return [];
|
275
250
|
return keys.map(function (prop) {
|
276
|
-
var _getPropertyType = (0, _types2.getPropertyType)(jsonschema, prop),
|
251
|
+
var _getPropertyType = (0, _types2.getPropertyType)(context, jsonschema, prop),
|
277
252
|
type = _getPropertyType.type,
|
278
253
|
optional = _getPropertyType.optional;
|
279
254
|
|
280
|
-
return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(type), optional);
|
255
|
+
return (0, _babel.propertySignature)(context.options.reactQuery.camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(type), optional);
|
281
256
|
});
|
282
257
|
};
|
283
258
|
|
284
|
-
function generateUseQueryQueryKey(hookKeyName, props, optionalClient) {
|
259
|
+
var generateUseQueryQueryKey = function generateUseQueryQueryKey(hookKeyName, props, optionalClient) {
|
285
260
|
var queryKey = [t.stringLiteral(hookKeyName), t.optionalMemberExpression(t.identifier('client'), t.identifier('contractAddress'), false, optionalClient)];
|
286
261
|
|
287
262
|
if (props.includes('args')) {
|
@@ -289,4 +264,4 @@ function generateUseQueryQueryKey(hookKeyName, props, optionalClient) {
|
|
289
264
|
}
|
290
265
|
|
291
266
|
return queryKey;
|
292
|
-
}
|
267
|
+
};
|
@@ -4,74 +4,64 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
4
4
|
|
5
5
|
var _typeof = require("@babel/runtime/helpers/typeof");
|
6
6
|
|
7
|
-
var _generator = _interopRequireDefault(require("@babel/generator"));
|
8
|
-
|
9
7
|
var t = _interopRequireWildcard(require("@babel/types"));
|
10
8
|
|
11
|
-
var _query_msg = _interopRequireDefault(require("
|
9
|
+
var _query_msg = _interopRequireDefault(require("../../../../__fixtures__/basic/query_msg.json"));
|
10
|
+
|
11
|
+
var _execute_msg_for__empty = _interopRequireDefault(require("../../../../__fixtures__/basic/execute_msg_for__empty.json"));
|
12
12
|
|
13
|
-
var
|
13
|
+
var _context = require("../context");
|
14
14
|
|
15
15
|
var _reactQuery = require("./react-query");
|
16
16
|
|
17
|
+
var _testUtils = require("../../test-utils");
|
18
|
+
|
17
19
|
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); }
|
18
20
|
|
19
21
|
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; }
|
20
22
|
|
21
|
-
var
|
22
|
-
|
23
|
-
};
|
24
|
-
|
25
|
-
var printCode = function printCode(ast) {
|
26
|
-
console.log((0, _generator["default"])(ast).code);
|
27
|
-
}; // it('createReactQueryHook', () => {
|
28
|
-
// printCode(createReactQueryHook({
|
29
|
-
// methodName: 'allNftInfo',
|
30
|
-
// hookName: 'useSg721AllNftInfoQuery',
|
31
|
-
// hookParamsTypeName: 'Sg721CollectionInfoQuery',
|
32
|
-
// responseType: 'AllNftInfoResponse',
|
33
|
-
// hookKeyName: 'Sg721AllNftInfo'
|
34
|
-
// }))
|
35
|
-
// });
|
36
|
-
|
37
|
-
|
23
|
+
var execCtx = new _context.RenderContext(_execute_msg_for__empty["default"]);
|
24
|
+
var queryCtx = new _context.RenderContext(_query_msg["default"]);
|
38
25
|
it('createReactQueryHooks', function () {
|
39
|
-
expectCode(t.program((0, _reactQuery.createReactQueryHooks)({
|
26
|
+
(0, _testUtils.expectCode)(t.program((0, _reactQuery.createReactQueryHooks)({
|
27
|
+
context: queryCtx,
|
40
28
|
queryMsg: _query_msg["default"],
|
41
29
|
contractName: 'Sg721',
|
42
30
|
QueryClient: 'Sg721QueryClient'
|
43
31
|
})));
|
44
|
-
expectCode(t.program((0, _reactQuery.createReactQueryHooks)({
|
32
|
+
(0, _testUtils.expectCode)(t.program((0, _reactQuery.createReactQueryHooks)({
|
33
|
+
context: new _context.RenderContext(_query_msg["default"], {
|
34
|
+
reactQuery: {
|
35
|
+
optionalClient: true
|
36
|
+
}
|
37
|
+
}),
|
45
38
|
queryMsg: _query_msg["default"],
|
46
39
|
contractName: 'Sg721',
|
47
40
|
QueryClient: 'Sg721QueryClient'
|
48
41
|
})));
|
49
|
-
expectCode(t.program((0, _reactQuery.createReactQueryHooks)({
|
42
|
+
(0, _testUtils.expectCode)(t.program((0, _reactQuery.createReactQueryHooks)({
|
43
|
+
context: new _context.RenderContext(_query_msg["default"], {
|
44
|
+
reactQuery: {
|
45
|
+
v4: true
|
46
|
+
}
|
47
|
+
}),
|
50
48
|
queryMsg: _query_msg["default"],
|
51
49
|
contractName: 'Sg721',
|
52
|
-
QueryClient: 'Sg721QueryClient'
|
53
|
-
options: {
|
54
|
-
optionalClient: true
|
55
|
-
}
|
56
|
-
})));
|
57
|
-
expectCode(t.program((0, _reactQuery.createReactQueryHooks)({
|
58
|
-
queryMsg: _query_msg["default"],
|
59
|
-
contractName: 'Sg721',
|
60
|
-
QueryClient: 'Sg721QueryClient',
|
61
|
-
options: {
|
62
|
-
v4: true
|
63
|
-
}
|
50
|
+
QueryClient: 'Sg721QueryClient'
|
64
51
|
})));
|
65
|
-
expectCode(t.program((0, _reactQuery.createReactQueryHooks)({
|
52
|
+
(0, _testUtils.expectCode)(t.program((0, _reactQuery.createReactQueryHooks)({
|
53
|
+
context: new _context.RenderContext(_query_msg["default"], {
|
54
|
+
reactQuery: {
|
55
|
+
optionalClient: true,
|
56
|
+
v4: true
|
57
|
+
}
|
58
|
+
}),
|
66
59
|
queryMsg: _query_msg["default"],
|
67
60
|
contractName: 'Sg721',
|
68
|
-
QueryClient: 'Sg721QueryClient'
|
69
|
-
options: {
|
70
|
-
optionalClient: true,
|
71
|
-
v4: true
|
72
|
-
}
|
61
|
+
QueryClient: 'Sg721QueryClient'
|
73
62
|
})));
|
74
|
-
expectCode(t.program((0, _reactQuery.createReactQueryMutationHooks)({
|
63
|
+
(0, _testUtils.expectCode)(t.program((0, _reactQuery.createReactQueryMutationHooks)({
|
64
|
+
context: execCtx,
|
75
65
|
execMsg: _execute_msg_for__empty["default"],
|
76
66
|
contractName: 'Sg721',
|
77
67
|
ExecuteClient: 'Sg721Client'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
|
7
|
+
var _recoil = require("./recoil");
|
8
|
+
|
9
|
+
Object.keys(_recoil).forEach(function (key) {
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
11
|
+
if (key in exports && exports[key] === _recoil[key]) return;
|
12
|
+
Object.defineProperty(exports, key, {
|
13
|
+
enumerable: true,
|
14
|
+
get: function get() {
|
15
|
+
return _recoil[key];
|
16
|
+
}
|
17
|
+
});
|
18
|
+
});
|