wasm-ast-types 0.3.6 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/main/react-query.js +32 -17
- package/main/react-query.spec.js +18 -2
- package/main/recoil.js +3 -3
- package/main/utils/babel.js +21 -2
- package/module/react-query.js +20 -8
- package/module/react-query.spec.js +18 -2
- package/module/recoil.js +3 -3
- package/module/utils/babel.js +11 -0
- package/package.json +4 -5
- package/types/react-query.d.ts +13 -2
package/main/react-query.js
CHANGED
|
@@ -25,7 +25,16 @@ 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
|
|
28
|
+
var DEFAULT_OPTIONS = {
|
|
29
|
+
optionalClient: false
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
var createReactQueryHooks = function createReactQueryHooks(_ref) {
|
|
33
|
+
var queryMsg = _ref.queryMsg,
|
|
34
|
+
contractName = _ref.contractName,
|
|
35
|
+
QueryClient = _ref.QueryClient,
|
|
36
|
+
_ref$options = _ref.options,
|
|
37
|
+
options = _ref$options === void 0 ? DEFAULT_OPTIONS : _ref$options;
|
|
29
38
|
return (0, _utils.getMessageProperties)(queryMsg).reduce(function (m, schema) {
|
|
30
39
|
var underscoreName = Object.keys(schema.properties)[0];
|
|
31
40
|
var methodName = (0, _case.camel)(underscoreName);
|
|
@@ -38,29 +47,33 @@ var createReactQueryHooks = function createReactQueryHooks(queryMsg, contractNam
|
|
|
38
47
|
hookParamsTypeName: hookParamsTypeName,
|
|
39
48
|
responseType: responseType,
|
|
40
49
|
QueryClient: QueryClient,
|
|
41
|
-
jsonschema: jsonschema
|
|
50
|
+
jsonschema: jsonschema,
|
|
51
|
+
options: options
|
|
42
52
|
}), createReactQueryHook({
|
|
43
53
|
methodName: methodName,
|
|
44
54
|
hookName: hookName,
|
|
45
55
|
hookParamsTypeName: hookParamsTypeName,
|
|
46
56
|
responseType: responseType,
|
|
47
57
|
hookKeyName: getterKey,
|
|
48
|
-
jsonschema: jsonschema
|
|
58
|
+
jsonschema: jsonschema,
|
|
59
|
+
options: options
|
|
49
60
|
})].concat((0, _toConsumableArray2["default"])(m));
|
|
50
61
|
}, []);
|
|
51
62
|
};
|
|
52
63
|
|
|
53
64
|
exports.createReactQueryHooks = createReactQueryHooks;
|
|
54
65
|
|
|
55
|
-
var createReactQueryHook = function createReactQueryHook(
|
|
66
|
+
var createReactQueryHook = function createReactQueryHook(_ref2) {
|
|
56
67
|
var _jsonschema$propertie;
|
|
57
68
|
|
|
58
|
-
var hookName =
|
|
59
|
-
hookParamsTypeName =
|
|
60
|
-
responseType =
|
|
61
|
-
hookKeyName =
|
|
62
|
-
methodName =
|
|
63
|
-
jsonschema =
|
|
69
|
+
var hookName = _ref2.hookName,
|
|
70
|
+
hookParamsTypeName = _ref2.hookParamsTypeName,
|
|
71
|
+
responseType = _ref2.responseType,
|
|
72
|
+
hookKeyName = _ref2.hookKeyName,
|
|
73
|
+
methodName = _ref2.methodName,
|
|
74
|
+
jsonschema = _ref2.jsonschema,
|
|
75
|
+
_ref2$options = _ref2.options,
|
|
76
|
+
options = _ref2$options === void 0 ? DEFAULT_OPTIONS : _ref2$options;
|
|
64
77
|
var keys = Object.keys((_jsonschema$propertie = jsonschema.properties) !== null && _jsonschema$propertie !== void 0 ? _jsonschema$propertie : {});
|
|
65
78
|
var args = [];
|
|
66
79
|
|
|
@@ -78,17 +91,19 @@ var createReactQueryHook = function createReactQueryHook(_ref) {
|
|
|
78
91
|
|
|
79
92
|
return t.exportNamedDeclaration(t.functionDeclaration(t.identifier(hookName), [(0, _utils.tsObjectPattern)((0, _toConsumableArray2["default"])(props.map(function (prop) {
|
|
80
93
|
return t.objectProperty(t.identifier(prop), t.identifier(prop), false, true);
|
|
81
|
-
})), t.tsTypeAnnotation(t.tsTypeReference(t.identifier(hookParamsTypeName))))], t.blockStatement([t.returnStatement((0, _utils.callExpression)(t.identifier('useQuery'), [t.arrayExpression([t.stringLiteral(hookKeyName), t.
|
|
94
|
+
})), t.tsTypeAnnotation(t.tsTypeReference(t.identifier(hookParamsTypeName))))], t.blockStatement([t.returnStatement((0, _utils.callExpression)(t.identifier('useQuery'), [t.arrayExpression([t.stringLiteral(hookKeyName), t.optionalMemberExpression(t.identifier('client'), t.identifier('contractAddress'), false, options.optionalClient)]), t.arrowFunctionExpression([], (0, _babel.optionalConditionalExpression)(t.identifier('client'), t.callExpression(t.memberExpression(t.identifier('client'), t.identifier(methodName)), args), t.identifier('undefined'), options.optionalClient), false), options.optionalClient ? t.objectExpression([t.spreadElement(t.identifier('options')), t.objectProperty(t.identifier('enabled'), t.logicalExpression('&&', t.unaryExpression('!', t.unaryExpression('!', t.identifier('client'))), t.optionalMemberExpression(t.identifier('options'), t.identifier('enabled'), false, true)))]) : t.identifier('options')], 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()])))])))])));
|
|
82
95
|
};
|
|
83
96
|
|
|
84
97
|
exports.createReactQueryHook = createReactQueryHook;
|
|
85
98
|
|
|
86
|
-
var createReactQueryHookInterface = function createReactQueryHookInterface(
|
|
87
|
-
var QueryClient =
|
|
88
|
-
hookParamsTypeName =
|
|
89
|
-
responseType =
|
|
90
|
-
jsonschema =
|
|
91
|
-
|
|
99
|
+
var createReactQueryHookInterface = function createReactQueryHookInterface(_ref3) {
|
|
100
|
+
var QueryClient = _ref3.QueryClient,
|
|
101
|
+
hookParamsTypeName = _ref3.hookParamsTypeName,
|
|
102
|
+
responseType = _ref3.responseType,
|
|
103
|
+
jsonschema = _ref3.jsonschema,
|
|
104
|
+
_ref3$options = _ref3.options,
|
|
105
|
+
options = _ref3$options === void 0 ? DEFAULT_OPTIONS : _ref3$options;
|
|
106
|
+
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(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()])))]))), true)];
|
|
92
107
|
var props = getProps(jsonschema, true);
|
|
93
108
|
|
|
94
109
|
if (props.length) {
|
package/main/react-query.spec.js
CHANGED
|
@@ -34,6 +34,22 @@ var printCode = function printCode(ast) {
|
|
|
34
34
|
|
|
35
35
|
|
|
36
36
|
it('createReactQueryHooks', function () {
|
|
37
|
-
expectCode(t.program((0, _reactQuery.createReactQueryHooks)(
|
|
38
|
-
|
|
37
|
+
expectCode(t.program((0, _reactQuery.createReactQueryHooks)({
|
|
38
|
+
queryMsg: _query_msg["default"],
|
|
39
|
+
contractName: 'Sg721',
|
|
40
|
+
QueryClient: 'Sg721QueryClient'
|
|
41
|
+
})));
|
|
42
|
+
expectCode(t.program((0, _reactQuery.createReactQueryHooks)({
|
|
43
|
+
queryMsg: _query_msg["default"],
|
|
44
|
+
contractName: 'Sg721',
|
|
45
|
+
QueryClient: 'Sg721QueryClient'
|
|
46
|
+
})));
|
|
47
|
+
expectCode(t.program((0, _reactQuery.createReactQueryHooks)({
|
|
48
|
+
queryMsg: _query_msg["default"],
|
|
49
|
+
contractName: 'Sg721',
|
|
50
|
+
QueryClient: 'Sg721QueryClient',
|
|
51
|
+
options: {
|
|
52
|
+
optionalClient: true
|
|
53
|
+
}
|
|
54
|
+
})));
|
|
39
55
|
});
|
package/main/recoil.js
CHANGED
|
@@ -39,8 +39,8 @@ var createRecoilSelector = function createRecoilSelector(keyPrefix, QueryClient,
|
|
|
39
39
|
var selectorName = (0, _case.camel)("".concat(methodName, "Selector"));
|
|
40
40
|
var responseType = (0, _case.pascal)("".concat(methodName, "Response"));
|
|
41
41
|
var getterKey = (0, _case.camel)("".concat(keyPrefix).concat((0, _case.pascal)(methodName)));
|
|
42
|
-
return t.exportNamedDeclaration(t.variableDeclaration('const', [t.variableDeclarator(t.identifier(selectorName), (0, _utils.callExpression)(t.identifier('selectorFamily'), [t.objectExpression([t.objectProperty(t.identifier('key'), t.stringLiteral(getterKey)), t.objectProperty(t.identifier('get'), t.arrowFunctionExpression([t.objectPattern([t.objectProperty(t.identifier('params'), t.identifier('params'), false, true), t.restElement(t.identifier('queryClientParams'))])], t.arrowFunctionExpression([t.objectPattern([t.objectProperty(t.identifier('get'), t.identifier('get'), false, true)])], t.blockStatement([t.variableDeclaration('const', [t.variableDeclarator(t.identifier('client'), t.callExpression(t.identifier('get'), [t.callExpression(t.identifier('queryClient'), [t.identifier('queryClientParams')])]))]), t.
|
|
43
|
-
t.spreadElement(t.identifier('params'))])))]), true)))])], t.tsTypeParameterInstantiation([t.
|
|
42
|
+
return t.exportNamedDeclaration(t.variableDeclaration('const', [t.variableDeclarator(t.identifier(selectorName), (0, _utils.callExpression)(t.identifier('selectorFamily'), [t.objectExpression([t.objectProperty(t.identifier('key'), t.stringLiteral(getterKey)), t.objectProperty(t.identifier('get'), t.arrowFunctionExpression([t.objectPattern([t.objectProperty(t.identifier('params'), t.identifier('params'), false, true), t.restElement(t.identifier('queryClientParams'))])], t.arrowFunctionExpression([t.objectPattern([t.objectProperty(t.identifier('get'), t.identifier('get'), false, true)])], t.blockStatement([t.variableDeclaration('const', [t.variableDeclarator(t.identifier('client'), t.callExpression(t.identifier('get'), [t.callExpression(t.identifier('queryClient'), [t.identifier('queryClientParams')])]))]), t.returnStatement(t.awaitExpression(t.callExpression(t.memberExpression(t.identifier('client'), t.identifier(methodName)), [// t.identifier('params')
|
|
43
|
+
t.spreadElement(t.identifier('params'))])))]), true)))])], t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier(responseType)), t.tsIntersectionType([t.tsTypeReference(t.identifier('QueryClientParams')), t.tsTypeLiteral([t.tsPropertySignature(t.identifier('params'), t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Parameters'), t.tsTypeParameterInstantiation([t.tsIndexedAccessType(t.tsTypeReference(t.identifier(QueryClient)), t.tsLiteralType(t.stringLiteral(methodName)))]))))])])])))]));
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
exports.createRecoilSelector = createRecoilSelector;
|
|
@@ -86,7 +86,7 @@ exports.createRecoilQueryClientType = createRecoilQueryClientType;
|
|
|
86
86
|
|
|
87
87
|
var createRecoilQueryClient = function createRecoilQueryClient(keyPrefix, QueryClient) {
|
|
88
88
|
var getterKey = (0, _case.camel)("".concat(keyPrefix, 'QueryClient'));
|
|
89
|
-
return t.exportNamedDeclaration(t.variableDeclaration('const', [t.variableDeclarator(t.identifier('queryClient'), (0, _utils.callExpression)(t.identifier('selectorFamily'), [t.objectExpression([t.objectProperty(t.identifier('key'), t.stringLiteral(getterKey)), t.objectProperty(t.identifier('get'), t.arrowFunctionExpression([t.objectPattern([t.objectProperty(t.identifier('contractAddress'), t.identifier('contractAddress'), false, true)])], t.arrowFunctionExpression([t.objectPattern([t.objectProperty(t.identifier('get'), t.identifier('get'), false, true)])], t.blockStatement([t.variableDeclaration('const', [t.variableDeclarator(t.identifier('client'), t.callExpression(t.identifier('get'), [t.identifier('cosmWasmClient')]))]), t.
|
|
89
|
+
return t.exportNamedDeclaration(t.variableDeclaration('const', [t.variableDeclarator(t.identifier('queryClient'), (0, _utils.callExpression)(t.identifier('selectorFamily'), [t.objectExpression([t.objectProperty(t.identifier('key'), t.stringLiteral(getterKey)), t.objectProperty(t.identifier('get'), t.arrowFunctionExpression([t.objectPattern([t.objectProperty(t.identifier('contractAddress'), t.identifier('contractAddress'), false, true)])], t.arrowFunctionExpression([t.objectPattern([t.objectProperty(t.identifier('get'), t.identifier('get'), false, true)])], t.blockStatement([t.variableDeclaration('const', [t.variableDeclarator(t.identifier('client'), t.callExpression(t.identifier('get'), [t.identifier('cosmWasmClient')]))]), t.returnStatement(t.newExpression(t.identifier(QueryClient), [t.identifier('client'), t.identifier('contractAddress')]))]), false)))])], t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier(QueryClient)), t.tsTypeReference(t.identifier('QueryClientParams'))])))]));
|
|
90
90
|
};
|
|
91
91
|
|
|
92
92
|
exports.createRecoilQueryClient = createRecoilQueryClient;
|
package/main/utils/babel.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.typedIdentifier = exports.tsTypeOperator = exports.tsPropertySignature = exports.tsObjectPattern = exports.shorthandProperty = exports.recursiveNamespace = exports.propertySignature = exports.promiseTypeAnnotation = exports.memberExpressionOrIdentifierSnake = exports.memberExpressionOrIdentifier = exports.importStmt = exports.importAminoMsg = exports.identifier = exports.getMessageProperties = exports.getFieldDimensionality = exports.classProperty = exports.classDeclaration = exports.callExpression = exports.bindMethod = exports.arrowFunctionExpression = exports.arrayTypeNDimensions = exports.FieldTypeAsts = void 0;
|
|
10
|
+
exports.typedIdentifier = exports.typeRefOrOptionalUnion = exports.tsTypeOperator = exports.tsPropertySignature = exports.tsObjectPattern = exports.shorthandProperty = exports.recursiveNamespace = exports.propertySignature = exports.promiseTypeAnnotation = exports.optionalConditionalExpression = exports.memberExpressionOrIdentifierSnake = exports.memberExpressionOrIdentifier = exports.importStmt = exports.importAminoMsg = exports.identifier = exports.getMessageProperties = exports.getFieldDimensionality = exports.classProperty = exports.classDeclaration = exports.callExpression = exports.bindMethod = exports.arrowFunctionExpression = exports.arrayTypeNDimensions = exports.FieldTypeAsts = void 0;
|
|
11
11
|
|
|
12
12
|
var _toArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toArray"));
|
|
13
13
|
|
|
@@ -259,5 +259,24 @@ var memberExpressionOrIdentifierSnake = function memberExpressionOrIdentifierSna
|
|
|
259
259
|
|
|
260
260
|
return t.memberExpression(memberExpressionOrIdentifierSnake(rest), t.identifier((0, _case.snake)(name)));
|
|
261
261
|
};
|
|
262
|
+
/**
|
|
263
|
+
* If optional, return a conditional, otherwise just the expression
|
|
264
|
+
*/
|
|
262
265
|
|
|
263
|
-
|
|
266
|
+
|
|
267
|
+
exports.memberExpressionOrIdentifierSnake = memberExpressionOrIdentifierSnake;
|
|
268
|
+
|
|
269
|
+
var optionalConditionalExpression = function optionalConditionalExpression(test, expression, alternate) {
|
|
270
|
+
var optional = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
271
|
+
return optional ? t.conditionalExpression(test, expression, alternate) : expression;
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
exports.optionalConditionalExpression = optionalConditionalExpression;
|
|
275
|
+
|
|
276
|
+
var typeRefOrOptionalUnion = function typeRefOrOptionalUnion(identifier) {
|
|
277
|
+
var optional = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
278
|
+
var typeReference = t.tsTypeReference(identifier);
|
|
279
|
+
return optional ? t.tsUnionType([typeReference, t.tsUndefinedKeyword()]) : typeReference;
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
exports.typeRefOrOptionalUnion = typeRefOrOptionalUnion;
|
package/module/react-query.js
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import * as t from '@babel/types';
|
|
2
2
|
import { camel, pascal } from 'case';
|
|
3
3
|
import { tsPropertySignature, tsObjectPattern, callExpression, getMessageProperties } from './utils';
|
|
4
|
-
import { propertySignature } from './utils/babel';
|
|
4
|
+
import { typeRefOrOptionalUnion, propertySignature, optionalConditionalExpression } from './utils/babel';
|
|
5
5
|
import { getPropertyType } from './utils/types';
|
|
6
|
-
|
|
6
|
+
const DEFAULT_OPTIONS = {
|
|
7
|
+
optionalClient: false
|
|
8
|
+
};
|
|
9
|
+
export const createReactQueryHooks = ({
|
|
10
|
+
queryMsg,
|
|
11
|
+
contractName,
|
|
12
|
+
QueryClient,
|
|
13
|
+
options = DEFAULT_OPTIONS
|
|
14
|
+
}) => {
|
|
7
15
|
return getMessageProperties(queryMsg).reduce((m, schema) => {
|
|
8
16
|
const underscoreName = Object.keys(schema.properties)[0];
|
|
9
17
|
const methodName = camel(underscoreName);
|
|
@@ -16,14 +24,16 @@ export const createReactQueryHooks = (queryMsg, contractName, QueryClient) => {
|
|
|
16
24
|
hookParamsTypeName,
|
|
17
25
|
responseType,
|
|
18
26
|
QueryClient,
|
|
19
|
-
jsonschema
|
|
27
|
+
jsonschema,
|
|
28
|
+
options
|
|
20
29
|
}), createReactQueryHook({
|
|
21
30
|
methodName,
|
|
22
31
|
hookName,
|
|
23
32
|
hookParamsTypeName,
|
|
24
33
|
responseType,
|
|
25
34
|
hookKeyName: getterKey,
|
|
26
|
-
jsonschema
|
|
35
|
+
jsonschema,
|
|
36
|
+
options
|
|
27
37
|
}), ...m];
|
|
28
38
|
}, []);
|
|
29
39
|
};
|
|
@@ -33,7 +43,8 @@ export const createReactQueryHook = ({
|
|
|
33
43
|
responseType,
|
|
34
44
|
hookKeyName,
|
|
35
45
|
methodName,
|
|
36
|
-
jsonschema
|
|
46
|
+
jsonschema,
|
|
47
|
+
options = DEFAULT_OPTIONS
|
|
37
48
|
}) => {
|
|
38
49
|
const keys = Object.keys(jsonschema.properties ?? {});
|
|
39
50
|
let args = [];
|
|
@@ -52,15 +63,16 @@ export const createReactQueryHook = ({
|
|
|
52
63
|
|
|
53
64
|
return t.exportNamedDeclaration(t.functionDeclaration(t.identifier(hookName), [tsObjectPattern([...props.map(prop => {
|
|
54
65
|
return t.objectProperty(t.identifier(prop), t.identifier(prop), false, true);
|
|
55
|
-
})], t.tsTypeAnnotation(t.tsTypeReference(t.identifier(hookParamsTypeName))))], t.blockStatement([t.returnStatement(callExpression(t.identifier('useQuery'), [t.arrayExpression([t.stringLiteral(hookKeyName), t.
|
|
66
|
+
})], t.tsTypeAnnotation(t.tsTypeReference(t.identifier(hookParamsTypeName))))], t.blockStatement([t.returnStatement(callExpression(t.identifier('useQuery'), [t.arrayExpression([t.stringLiteral(hookKeyName), t.optionalMemberExpression(t.identifier('client'), t.identifier('contractAddress'), false, options.optionalClient)]), t.arrowFunctionExpression([], optionalConditionalExpression(t.identifier('client'), t.callExpression(t.memberExpression(t.identifier('client'), t.identifier(methodName)), args), t.identifier('undefined'), options.optionalClient), false), options.optionalClient ? t.objectExpression([t.spreadElement(t.identifier('options')), t.objectProperty(t.identifier('enabled'), t.logicalExpression('&&', t.unaryExpression('!', t.unaryExpression('!', t.identifier('client'))), t.optionalMemberExpression(t.identifier('options'), t.identifier('enabled'), false, true)))]) : t.identifier('options')], t.tsTypeParameterInstantiation([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()])))])))])));
|
|
56
67
|
};
|
|
57
68
|
export const createReactQueryHookInterface = ({
|
|
58
69
|
QueryClient,
|
|
59
70
|
hookParamsTypeName,
|
|
60
71
|
responseType,
|
|
61
|
-
jsonschema
|
|
72
|
+
jsonschema,
|
|
73
|
+
options = DEFAULT_OPTIONS
|
|
62
74
|
}) => {
|
|
63
|
-
const body = [
|
|
75
|
+
const body = [tsPropertySignature(t.identifier('client'), t.tsTypeAnnotation(t.tsTypeReference(t.identifier(QueryClient))), options.optionalClient), tsPropertySignature(t.identifier('options'), t.tsTypeAnnotation(t.tsTypeReference(t.identifier('UseQueryOptions'), t.tsTypeParameterInstantiation([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()])))]))), true)];
|
|
64
76
|
const props = getProps(jsonschema, true);
|
|
65
77
|
|
|
66
78
|
if (props.length) {
|
|
@@ -21,6 +21,22 @@ const printCode = ast => {
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
it('createReactQueryHooks', () => {
|
|
24
|
-
expectCode(t.program(createReactQueryHooks(
|
|
25
|
-
|
|
24
|
+
expectCode(t.program(createReactQueryHooks({
|
|
25
|
+
queryMsg: query_msg,
|
|
26
|
+
contractName: 'Sg721',
|
|
27
|
+
QueryClient: 'Sg721QueryClient'
|
|
28
|
+
})));
|
|
29
|
+
expectCode(t.program(createReactQueryHooks({
|
|
30
|
+
queryMsg: query_msg,
|
|
31
|
+
contractName: 'Sg721',
|
|
32
|
+
QueryClient: 'Sg721QueryClient'
|
|
33
|
+
})));
|
|
34
|
+
expectCode(t.program(createReactQueryHooks({
|
|
35
|
+
queryMsg: query_msg,
|
|
36
|
+
contractName: 'Sg721',
|
|
37
|
+
QueryClient: 'Sg721QueryClient',
|
|
38
|
+
options: {
|
|
39
|
+
optionalClient: true
|
|
40
|
+
}
|
|
41
|
+
})));
|
|
26
42
|
});
|
package/module/recoil.js
CHANGED
|
@@ -18,8 +18,8 @@ export const createRecoilSelector = (keyPrefix, QueryClient, methodName) => {
|
|
|
18
18
|
const selectorName = camel(`${methodName}Selector`);
|
|
19
19
|
const responseType = pascal(`${methodName}Response`);
|
|
20
20
|
const getterKey = camel(`${keyPrefix}${pascal(methodName)}`);
|
|
21
|
-
return t.exportNamedDeclaration(t.variableDeclaration('const', [t.variableDeclarator(t.identifier(selectorName), callExpression(t.identifier('selectorFamily'), [t.objectExpression([t.objectProperty(t.identifier('key'), t.stringLiteral(getterKey)), t.objectProperty(t.identifier('get'), t.arrowFunctionExpression([t.objectPattern([t.objectProperty(t.identifier('params'), t.identifier('params'), false, true), t.restElement(t.identifier('queryClientParams'))])], t.arrowFunctionExpression([t.objectPattern([t.objectProperty(t.identifier('get'), t.identifier('get'), false, true)])], t.blockStatement([t.variableDeclaration('const', [t.variableDeclarator(t.identifier('client'), t.callExpression(t.identifier('get'), [t.callExpression(t.identifier('queryClient'), [t.identifier('queryClientParams')])]))]), t.
|
|
22
|
-
t.spreadElement(t.identifier('params'))])))]), true)))])], t.tsTypeParameterInstantiation([t.
|
|
21
|
+
return t.exportNamedDeclaration(t.variableDeclaration('const', [t.variableDeclarator(t.identifier(selectorName), callExpression(t.identifier('selectorFamily'), [t.objectExpression([t.objectProperty(t.identifier('key'), t.stringLiteral(getterKey)), t.objectProperty(t.identifier('get'), t.arrowFunctionExpression([t.objectPattern([t.objectProperty(t.identifier('params'), t.identifier('params'), false, true), t.restElement(t.identifier('queryClientParams'))])], t.arrowFunctionExpression([t.objectPattern([t.objectProperty(t.identifier('get'), t.identifier('get'), false, true)])], t.blockStatement([t.variableDeclaration('const', [t.variableDeclarator(t.identifier('client'), t.callExpression(t.identifier('get'), [t.callExpression(t.identifier('queryClient'), [t.identifier('queryClientParams')])]))]), t.returnStatement(t.awaitExpression(t.callExpression(t.memberExpression(t.identifier('client'), t.identifier(methodName)), [// t.identifier('params')
|
|
22
|
+
t.spreadElement(t.identifier('params'))])))]), true)))])], t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier(responseType)), t.tsIntersectionType([t.tsTypeReference(t.identifier('QueryClientParams')), t.tsTypeLiteral([t.tsPropertySignature(t.identifier('params'), t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Parameters'), t.tsTypeParameterInstantiation([t.tsIndexedAccessType(t.tsTypeReference(t.identifier(QueryClient)), t.tsLiteralType(t.stringLiteral(methodName)))]))))])])])))]));
|
|
23
23
|
};
|
|
24
24
|
export const createRecoilSelectors = (keyPrefix, QueryClient, queryMsg) => {
|
|
25
25
|
return getMessageProperties(queryMsg).map(schema => {
|
|
@@ -54,5 +54,5 @@ export const createRecoilQueryClientType = () => ({
|
|
|
54
54
|
});
|
|
55
55
|
export const createRecoilQueryClient = (keyPrefix, QueryClient) => {
|
|
56
56
|
const getterKey = camel(`${keyPrefix}${'QueryClient'}`);
|
|
57
|
-
return t.exportNamedDeclaration(t.variableDeclaration('const', [t.variableDeclarator(t.identifier('queryClient'), callExpression(t.identifier('selectorFamily'), [t.objectExpression([t.objectProperty(t.identifier('key'), t.stringLiteral(getterKey)), t.objectProperty(t.identifier('get'), t.arrowFunctionExpression([t.objectPattern([t.objectProperty(t.identifier('contractAddress'), t.identifier('contractAddress'), false, true)])], t.arrowFunctionExpression([t.objectPattern([t.objectProperty(t.identifier('get'), t.identifier('get'), false, true)])], t.blockStatement([t.variableDeclaration('const', [t.variableDeclarator(t.identifier('client'), t.callExpression(t.identifier('get'), [t.identifier('cosmWasmClient')]))]), t.
|
|
57
|
+
return t.exportNamedDeclaration(t.variableDeclaration('const', [t.variableDeclarator(t.identifier('queryClient'), callExpression(t.identifier('selectorFamily'), [t.objectExpression([t.objectProperty(t.identifier('key'), t.stringLiteral(getterKey)), t.objectProperty(t.identifier('get'), t.arrowFunctionExpression([t.objectPattern([t.objectProperty(t.identifier('contractAddress'), t.identifier('contractAddress'), false, true)])], t.arrowFunctionExpression([t.objectPattern([t.objectProperty(t.identifier('get'), t.identifier('get'), false, true)])], t.blockStatement([t.variableDeclaration('const', [t.variableDeclarator(t.identifier('client'), t.callExpression(t.identifier('get'), [t.identifier('cosmWasmClient')]))]), t.returnStatement(t.newExpression(t.identifier(QueryClient), [t.identifier('client'), t.identifier('contractAddress')]))]), false)))])], t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier(QueryClient)), t.tsTypeReference(t.identifier('QueryClientParams'))])))]));
|
|
58
58
|
};
|
package/module/utils/babel.js
CHANGED
|
@@ -153,4 +153,15 @@ export const memberExpressionOrIdentifierSnake = names => {
|
|
|
153
153
|
|
|
154
154
|
const [name, ...rest] = names;
|
|
155
155
|
return t.memberExpression(memberExpressionOrIdentifierSnake(rest), t.identifier(snake(name)));
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* If optional, return a conditional, otherwise just the expression
|
|
159
|
+
*/
|
|
160
|
+
|
|
161
|
+
export const optionalConditionalExpression = (test, expression, alternate, optional = false) => {
|
|
162
|
+
return optional ? t.conditionalExpression(test, expression, alternate) : expression;
|
|
163
|
+
};
|
|
164
|
+
export const typeRefOrOptionalUnion = (identifier, optional = false) => {
|
|
165
|
+
const typeReference = t.tsTypeReference(identifier);
|
|
166
|
+
return optional ? t.tsUnionType([typeReference, t.tsUndefinedKeyword()]) : typeReference;
|
|
156
167
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wasm-ast-types",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
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",
|
|
@@ -23,9 +23,8 @@
|
|
|
23
23
|
"build": "npm run build:module && npm run build:main",
|
|
24
24
|
"build:ts": "tsc --project ./tsconfig.json",
|
|
25
25
|
"prepare": "npm run build",
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"lint": "eslint src --fix",
|
|
26
|
+
"lint": "eslint .",
|
|
27
|
+
"format": "eslint . --fix",
|
|
29
28
|
"test": "jest",
|
|
30
29
|
"test:ast": "cross-env NODE_ENV=development babel-node scripts/test-ast.js",
|
|
31
30
|
"test:watch": "jest --watch",
|
|
@@ -85,5 +84,5 @@
|
|
|
85
84
|
"ast-stringify": "0.1.0",
|
|
86
85
|
"case": "1.6.3"
|
|
87
86
|
},
|
|
88
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "b0312f7e16b8fd1c4892da6d91d3f7cf6c1bd49e"
|
|
89
88
|
}
|
package/types/react-query.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import * as t from '@babel/types';
|
|
2
2
|
import { QueryMsg } from './types';
|
|
3
|
+
|
|
4
|
+
interface ReactQueryHooks {
|
|
5
|
+
queryMsg: QueryMsg
|
|
6
|
+
contractName: string
|
|
7
|
+
QueryClient: string
|
|
8
|
+
options?: ReactQueryOptions
|
|
9
|
+
}
|
|
3
10
|
interface ReactQueryHookQuery {
|
|
4
11
|
hookName: string;
|
|
5
12
|
hookParamsTypeName: string;
|
|
@@ -8,7 +15,11 @@ interface ReactQueryHookQuery {
|
|
|
8
15
|
methodName: string;
|
|
9
16
|
jsonschema: any;
|
|
10
17
|
}
|
|
11
|
-
|
|
18
|
+
|
|
19
|
+
export declare interface ReactQueryOptions {
|
|
20
|
+
optionalClient?: boolean
|
|
21
|
+
}
|
|
22
|
+
export declare const createReactQueryHooks: ({ queryMsg, contractName, QueryClient, options }: ReactQueryHooks) => any;
|
|
12
23
|
export declare const createReactQueryHook: ({ hookName, hookParamsTypeName, responseType, hookKeyName, methodName, jsonschema }: ReactQueryHookQuery) => t.ExportNamedDeclaration;
|
|
13
24
|
interface ReactQueryHookQueryInterface {
|
|
14
25
|
QueryClient: string;
|
|
@@ -17,4 +28,4 @@ interface ReactQueryHookQueryInterface {
|
|
|
17
28
|
jsonschema: any;
|
|
18
29
|
}
|
|
19
30
|
export declare const createReactQueryHookInterface: ({ QueryClient, hookParamsTypeName, responseType, jsonschema }: ReactQueryHookQueryInterface) => t.ExportNamedDeclaration;
|
|
20
|
-
export {};
|
|
31
|
+
export { };
|