wasm-ast-types 0.1.2 → 0.2.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/index.js CHANGED
@@ -28,4 +28,30 @@ Object.keys(_wasm).forEach(function (key) {
28
28
  return _wasm[key];
29
29
  }
30
30
  });
31
+ });
32
+
33
+ var _recoil = require("./recoil");
34
+
35
+ Object.keys(_recoil).forEach(function (key) {
36
+ if (key === "default" || key === "__esModule") return;
37
+ if (key in exports && exports[key] === _recoil[key]) return;
38
+ Object.defineProperty(exports, key, {
39
+ enumerable: true,
40
+ get: function get() {
41
+ return _recoil[key];
42
+ }
43
+ });
44
+ });
45
+
46
+ var _reactQuery = require("./react-query");
47
+
48
+ Object.keys(_reactQuery).forEach(function (key) {
49
+ if (key === "default" || key === "__esModule") return;
50
+ if (key in exports && exports[key] === _reactQuery[key]) return;
51
+ Object.defineProperty(exports, key, {
52
+ enumerable: true,
53
+ get: function get() {
54
+ return _reactQuery[key];
55
+ }
56
+ });
31
57
  });
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports.createReactQueryHooks = exports.createReactQueryHookInterface = exports.createReactQueryHook = void 0;
11
+
12
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
13
+
14
+ var t = _interopRequireWildcard(require("@babel/types"));
15
+
16
+ var _case = require("case");
17
+
18
+ var _utils = require("./utils");
19
+
20
+ var _wasm = require("./wasm");
21
+
22
+ 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); }
23
+
24
+ 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; }
25
+
26
+ var createReactQueryHooks = function createReactQueryHooks(queryMsg, contractName, QueryClient) {
27
+ return (0, _utils.getMessageProperties)(queryMsg).reduce(function (m, schema) {
28
+ var underscoreName = Object.keys(schema.properties)[0];
29
+ var methodName = (0, _case.camel)(underscoreName);
30
+ var hookName = "use".concat((0, _case.pascal)(contractName)).concat((0, _case.pascal)(methodName), "Query");
31
+ var hookParamsTypeName = "".concat((0, _case.pascal)(contractName)).concat((0, _case.pascal)(methodName), "Query");
32
+ var responseType = (0, _case.pascal)("".concat(methodName, "Response"));
33
+ var getterKey = (0, _case.camel)("".concat(contractName).concat((0, _case.pascal)(methodName)));
34
+ var jsonschema = schema.properties[underscoreName];
35
+ return [createReactQueryHookInterface({
36
+ hookParamsTypeName: hookParamsTypeName,
37
+ responseType: responseType,
38
+ QueryClient: QueryClient,
39
+ jsonschema: jsonschema
40
+ }), createReactQueryHook({
41
+ methodName: methodName,
42
+ hookName: hookName,
43
+ hookParamsTypeName: hookParamsTypeName,
44
+ responseType: responseType,
45
+ hookKeyName: getterKey,
46
+ jsonschema: jsonschema
47
+ })].concat((0, _toConsumableArray2["default"])(m));
48
+ }, []);
49
+ };
50
+
51
+ exports.createReactQueryHooks = createReactQueryHooks;
52
+
53
+ var createReactQueryHook = function createReactQueryHook(_ref) {
54
+ var _jsonschema$propertie;
55
+
56
+ var hookName = _ref.hookName,
57
+ hookParamsTypeName = _ref.hookParamsTypeName,
58
+ responseType = _ref.responseType,
59
+ hookKeyName = _ref.hookKeyName,
60
+ methodName = _ref.methodName,
61
+ jsonschema = _ref.jsonschema;
62
+ var keys = Object.keys((_jsonschema$propertie = jsonschema.properties) !== null && _jsonschema$propertie !== void 0 ? _jsonschema$propertie : {});
63
+ var args = [];
64
+
65
+ if (keys.length) {
66
+ args = [t.objectExpression((0, _toConsumableArray2["default"])(keys.map(function (prop) {
67
+ return t.objectProperty(t.identifier((0, _case.camel)(prop)), t.memberExpression(t.identifier('args'), t.identifier((0, _case.camel)(prop))));
68
+ })))];
69
+ }
70
+
71
+ var props = ['client', 'options'];
72
+
73
+ if (keys.length) {
74
+ props = ['client', 'args', 'options'];
75
+ }
76
+
77
+ return t.exportNamedDeclaration(t.functionDeclaration(t.identifier(hookName), [(0, _utils.tsObjectPattern)((0, _toConsumableArray2["default"])(props.map(function (prop) {
78
+ return t.objectProperty(t.identifier(prop), t.identifier(prop), false, true);
79
+ })), t.tsTypeAnnotation(t.tsTypeReference(t.identifier(hookParamsTypeName))))], t.blockStatement([t.returnStatement((0, _utils.callExpression)(t.identifier('useQuery'), [t.arrayExpression([t.stringLiteral(hookKeyName), t.memberExpression(t.identifier('client'), t.identifier('contractAddress'))]), t.arrowFunctionExpression([], t.callExpression(t.memberExpression(t.identifier('client'), t.identifier(methodName)), args), false), t.identifier('options')], t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier(responseType)), t.tsTypeReference(t.identifier('Error')), t.tsTypeReference(t.identifier(responseType)), t.tsArrayType(t.tsParenthesizedType(t.tsUnionType([t.tsStringKeyword(), t.tsUndefinedKeyword()])))])))])));
80
+ };
81
+
82
+ exports.createReactQueryHook = createReactQueryHook;
83
+
84
+ var createReactQueryHookInterface = function createReactQueryHookInterface(_ref2) {
85
+ var QueryClient = _ref2.QueryClient,
86
+ hookParamsTypeName = _ref2.hookParamsTypeName,
87
+ responseType = _ref2.responseType,
88
+ jsonschema = _ref2.jsonschema;
89
+ var body = [t.tsPropertySignature(t.identifier('client'), t.tsTypeAnnotation(t.tsTypeReference(t.identifier(QueryClient)))), (0, _utils.tsPropertySignature)(t.identifier('options'), t.tsTypeAnnotation(t.tsTypeReference(t.identifier('UseQueryOptions'), t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier(responseType)), t.tsTypeReference(t.identifier('Error')), t.tsTypeReference(t.identifier(responseType)), t.tsArrayType(t.tsParenthesizedType(t.tsUnionType([t.tsStringKeyword(), t.tsUndefinedKeyword()])))]))), true)];
90
+ var props = getProps(jsonschema, true);
91
+
92
+ if (props.length) {
93
+ body.push(t.tsPropertySignature(t.identifier('args'), t.tsTypeAnnotation(t.tsTypeLiteral(props))));
94
+ }
95
+
96
+ return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(hookParamsTypeName), null, [], t.tsInterfaceBody(body)));
97
+ };
98
+
99
+ exports.createReactQueryHookInterface = createReactQueryHookInterface;
100
+
101
+ var getProps = function getProps(jsonschema, camelize) {
102
+ var _jsonschema$propertie2;
103
+
104
+ var keys = Object.keys((_jsonschema$propertie2 = jsonschema.properties) !== null && _jsonschema$propertie2 !== void 0 ? _jsonschema$propertie2 : {});
105
+ if (!keys.length) return [];
106
+ return keys.map(function (prop) {
107
+ var _getPropertyType = (0, _wasm.getPropertyType)(jsonschema, prop),
108
+ type = _getPropertyType.type,
109
+ optional = _getPropertyType.optional;
110
+
111
+ return (0, _wasm.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(type), optional);
112
+ });
113
+ };
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+
7
+ var _generator = _interopRequireDefault(require("@babel/generator"));
8
+
9
+ var t = _interopRequireWildcard(require("@babel/types"));
10
+
11
+ var _query_msg = _interopRequireDefault(require("./__fixtures__/schema/query_msg.json"));
12
+
13
+ var _reactQuery = require("./react-query");
14
+
15
+ 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); }
16
+
17
+ 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; }
18
+
19
+ var expectCode = function expectCode(ast) {
20
+ expect((0, _generator["default"])(ast).code).toMatchSnapshot();
21
+ };
22
+
23
+ var printCode = function printCode(ast) {
24
+ console.log((0, _generator["default"])(ast).code);
25
+ }; // it('createReactQueryHook', () => {
26
+ // printCode(createReactQueryHook({
27
+ // methodName: 'allNftInfo',
28
+ // hookName: 'useSg721AllNftInfoQuery',
29
+ // hookParamsTypeName: 'Sg721CollectionInfoQuery',
30
+ // responseType: 'AllNftInfoResponse',
31
+ // hookKeyName: 'Sg721AllNftInfo'
32
+ // }))
33
+ // });
34
+
35
+
36
+ it('createReactQueryHooks', function () {
37
+ printCode(t.program((0, _reactQuery.createReactQueryHooks)(_query_msg["default"], 'Sg721', 'Sg721QueryClient')));
38
+ expectCode(t.program((0, _reactQuery.createReactQueryHooks)(_query_msg["default"], 'Sg721', 'Sg721QueryClient')));
39
+ });
package/main/recoil.js ADDED
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+
3
+ var _typeof = require("@babel/runtime/helpers/typeof");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.createWasmRecoilMethod = exports.createRecoilSelectors = exports.createRecoilSelector = exports.createRecoilQueryClientType = exports.createRecoilQueryClient = void 0;
9
+
10
+ var t = _interopRequireWildcard(require("@babel/types"));
11
+
12
+ var _case = require("case");
13
+
14
+ var _utils = require("./utils");
15
+
16
+ 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); }
17
+
18
+ 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; }
19
+
20
+ var createWasmRecoilMethod = function createWasmRecoilMethod(jsonschema) {
21
+ var _jsonschema$propertie;
22
+
23
+ var underscoreName = Object.keys(jsonschema.properties)[0];
24
+ var methodName = (0, _case.camel)(underscoreName);
25
+ var responseType = (0, _case.pascal)("".concat(methodName, "Response"));
26
+ var properties = (_jsonschema$propertie = jsonschema.properties[underscoreName].properties) !== null && _jsonschema$propertie !== void 0 ? _jsonschema$propertie : {};
27
+
28
+ if (Object.keys(properties).length > 0) {} else {}
29
+ };
30
+
31
+ exports.createWasmRecoilMethod = createWasmRecoilMethod;
32
+
33
+ var createRecoilSelector = function createRecoilSelector(keyPrefix, QueryClient, methodName) {
34
+ // const propertyNames = getMessageProperties(queryMsg)
35
+ // .map(method => Object.keys(method.properties)?.[0])
36
+ // .filter(Boolean);
37
+ // const methods = getMessageProperties(queryMsg)
38
+ // .map(schema => createWasmRecoilMethod(schema))
39
+ var selectorName = (0, _case.camel)("".concat(methodName, "Selector"));
40
+ var responseType = (0, _case.pascal)("".concat(methodName, "Response"));
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.ifStatement(t.unaryExpression('!', t.identifier('client')), t.returnStatement(null), null), 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.tsUnionType([t.tsTypeReference(t.identifier(responseType)), t.tsUndefinedKeyword()]), 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
+ };
45
+
46
+ exports.createRecoilSelector = createRecoilSelector;
47
+
48
+ var createRecoilSelectors = function createRecoilSelectors(keyPrefix, QueryClient, queryMsg) {
49
+ return (0, _utils.getMessageProperties)(queryMsg).map(function (schema) {
50
+ var underscoreName = Object.keys(schema.properties)[0];
51
+ var methodName = (0, _case.camel)(underscoreName);
52
+ return createRecoilSelector(keyPrefix, QueryClient, methodName);
53
+ });
54
+ };
55
+
56
+ exports.createRecoilSelectors = createRecoilSelectors;
57
+
58
+ var createRecoilQueryClientType = function createRecoilQueryClientType() {
59
+ return {
60
+ "type": "TSTypeAliasDeclaration",
61
+ "id": {
62
+ "type": "Identifier",
63
+ "name": "QueryClientParams"
64
+ },
65
+ "typeAnnotation": {
66
+ "type": "TSTypeLiteral",
67
+ "members": [{
68
+ "type": "TSPropertySignature",
69
+ "key": {
70
+ "type": "Identifier",
71
+ "name": "contractAddress"
72
+ },
73
+ "computed": false,
74
+ "typeAnnotation": {
75
+ "type": "TSTypeAnnotation",
76
+ "typeAnnotation": {
77
+ "type": "TSStringKeyword"
78
+ }
79
+ }
80
+ }]
81
+ }
82
+ };
83
+ };
84
+
85
+ exports.createRecoilQueryClientType = createRecoilQueryClientType;
86
+
87
+ var createRecoilQueryClient = function createRecoilQueryClient(keyPrefix, QueryClient) {
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.ifStatement(t.unaryExpression('!', t.identifier('client')), t.returnStatement(null), null), t.returnStatement(t.newExpression(t.identifier(QueryClient), [t.identifier('client'), t.identifier('contractAddress')]))]), false)))])], t.tsTypeParameterInstantiation([t.tsUnionType([t.tsTypeReference(t.identifier(QueryClient)), t.tsUndefinedKeyword()]), t.tsTypeReference(t.identifier('QueryClientParams'))])))]));
90
+ };
91
+
92
+ exports.createRecoilQueryClient = createRecoilQueryClient;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+
7
+ var _generator = _interopRequireDefault(require("@babel/generator"));
8
+
9
+ var t = _interopRequireWildcard(require("@babel/types"));
10
+
11
+ var _query_msg = _interopRequireDefault(require("./__fixtures__/schema/query_msg.json"));
12
+
13
+ var _recoil = require("./recoil");
14
+
15
+ 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); }
16
+
17
+ 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; }
18
+
19
+ var expectCode = function expectCode(ast) {
20
+ expect((0, _generator["default"])(ast).code).toMatchSnapshot();
21
+ };
22
+
23
+ var printCode = function printCode(ast) {
24
+ console.log((0, _generator["default"])(ast).code);
25
+ };
26
+
27
+ it('selector', function () {
28
+ expectCode((0, _recoil.createRecoilSelector)('SG721', 'SG721QueryClient', 'governanceModules'));
29
+ });
30
+ it('selectors', function () {
31
+ expectCode(t.program((0, _recoil.createRecoilSelectors)('SG721', 'SG721QueryClient', _query_msg["default"])));
32
+ });
33
+ it('client', function () {
34
+ printCode((0, _recoil.createRecoilQueryClient)('SG721', 'SG721QueryClient'));
35
+ });
package/main/types.js ADDED
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ ;
4
+ ;
package/main/utils.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.shorthandProperty = exports.recursiveNamespace = exports.promiseTypeAnnotation = exports.memberExpressionOrIdentifierSnake = exports.memberExpressionOrIdentifier = exports.importStmt = exports.importAminoMsg = exports.getFieldDimensionality = exports.classProperty = exports.classDeclaration = exports.bindMethod = exports.arrowFunctionExpression = exports.arrayTypeNDimensions = exports.FieldTypeAsts = void 0;
10
+ exports.typedIdentifier = exports.tsPropertySignature = exports.tsObjectPattern = exports.shorthandProperty = exports.recursiveNamespace = exports.promiseTypeAnnotation = exports.memberExpressionOrIdentifierSnake = exports.memberExpressionOrIdentifier = exports.importStmt = exports.importAminoMsg = 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
 
@@ -21,6 +21,39 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
21
21
 
22
22
  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; }
23
23
 
24
+ var getMessageProperties = function getMessageProperties(msg) {
25
+ if (msg.anyOf) return msg.anyOf;
26
+ if (msg.oneOf) return msg.oneOf;
27
+ if (msg.allOf) return msg.allOf;
28
+ return [];
29
+ };
30
+
31
+ exports.getMessageProperties = getMessageProperties;
32
+
33
+ var tsPropertySignature = function tsPropertySignature(key, typeAnnotation, optional) {
34
+ var obj = t.tsPropertySignature(key, typeAnnotation);
35
+ obj.optional = optional;
36
+ return obj;
37
+ };
38
+
39
+ exports.tsPropertySignature = tsPropertySignature;
40
+
41
+ var tsObjectPattern = function tsObjectPattern(properties, typeAnnotation) {
42
+ var obj = t.objectPattern(properties);
43
+ obj.typeAnnotation = typeAnnotation;
44
+ return obj;
45
+ };
46
+
47
+ exports.tsObjectPattern = tsObjectPattern;
48
+
49
+ var callExpression = function callExpression(callee, _arguments, typeParameters) {
50
+ var callExpr = t.callExpression(callee, _arguments);
51
+ callExpr.typeParameters = typeParameters;
52
+ return callExpr;
53
+ };
54
+
55
+ exports.callExpression = callExpression;
56
+
24
57
  var bindMethod = function bindMethod(name) {
25
58
  return t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier(name)), t.callExpression(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier(name)), t.identifier('bind')), [t.thisExpression()])));
26
59
  };
package/main/wasm.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.propertySignature = exports.createWasmQueryMethod = exports.createWasmExecMethod = exports.createTypedObjectParams = exports.createTypeOrInterface = exports.createTypeInterface = exports.createQueryInterface = exports.createQueryClass = exports.createPropertyFunctionWithObjectParams = exports.createExecuteInterface = exports.createExecuteClass = void 0;
10
+ exports.propertySignature = exports.getPropertyType = exports.createWasmQueryMethod = exports.createWasmExecMethod = exports.createTypedObjectParams = exports.createTypeOrInterface = exports.createTypeInterface = exports.createQueryInterface = exports.createQueryClass = exports.createPropertyFunctionWithObjectParams = exports.createExecuteInterface = exports.createExecuteClass = void 0;
11
11
 
12
12
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
13
13
 
@@ -23,17 +23,10 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
23
23
 
24
24
  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; }
25
25
 
26
- var getMessageProperties = function getMessageProperties(msg) {
27
- if (msg.anyOf) return msg.anyOf;
28
- if (msg.oneOf) return msg.oneOf;
29
- if (msg.allOf) return msg.allOf;
30
- return [];
31
- };
32
-
33
26
  var getTypeFromRef = function getTypeFromRef($ref) {
34
27
  switch ($ref) {
35
28
  case '#/definitions/Binary':
36
- return t.tsTypeReference(t.identifier('BinaryType'));
29
+ return t.tsTypeReference(t.identifier('Binary'));
37
30
 
38
31
  case '#/definitions/Expiration':
39
32
  return t.tsTypeReference(t.identifier('Expiration'));
@@ -149,6 +142,8 @@ var getPropertyType = function getPropertyType(schema, prop) {
149
142
  };
150
143
  };
151
144
 
145
+ exports.getPropertyType = getPropertyType;
146
+
152
147
  var createWasmQueryMethod = function createWasmQueryMethod(jsonschema) {
153
148
  var _jsonschema$propertie;
154
149
 
@@ -167,13 +162,13 @@ var createWasmQueryMethod = function createWasmQueryMethod(jsonschema) {
167
162
  exports.createWasmQueryMethod = createWasmQueryMethod;
168
163
 
169
164
  var createQueryClass = function createQueryClass(className, implementsClassName, queryMsg) {
170
- var propertyNames = getMessageProperties(queryMsg).map(function (method) {
165
+ var propertyNames = (0, _utils.getMessageProperties)(queryMsg).map(function (method) {
171
166
  var _Object$keys;
172
167
 
173
168
  return (_Object$keys = Object.keys(method.properties)) === null || _Object$keys === void 0 ? void 0 : _Object$keys[0];
174
169
  }).filter(Boolean);
175
170
  var bindings = propertyNames.map(_case.camel).map(_utils.bindMethod);
176
- var methods = getMessageProperties(queryMsg).map(function (schema) {
171
+ var methods = (0, _utils.getMessageProperties)(queryMsg).map(function (schema) {
177
172
  return createWasmQueryMethod(schema);
178
173
  });
179
174
  return t.exportNamedDeclaration((0, _utils.classDeclaration)(className, [// client
@@ -203,13 +198,13 @@ var createWasmExecMethod = function createWasmExecMethod(jsonschema) {
203
198
  exports.createWasmExecMethod = createWasmExecMethod;
204
199
 
205
200
  var createExecuteClass = function createExecuteClass(className, implementsClassName, extendsClassName, execMsg) {
206
- var propertyNames = getMessageProperties(execMsg).map(function (method) {
201
+ var propertyNames = (0, _utils.getMessageProperties)(execMsg).map(function (method) {
207
202
  var _Object$keys2;
208
203
 
209
204
  return (_Object$keys2 = Object.keys(method.properties)) === null || _Object$keys2 === void 0 ? void 0 : _Object$keys2[0];
210
205
  }).filter(Boolean);
211
206
  var bindings = propertyNames.map(_case.camel).map(_utils.bindMethod);
212
- var methods = getMessageProperties(execMsg).map(function (schema) {
207
+ var methods = (0, _utils.getMessageProperties)(execMsg).map(function (schema) {
213
208
  return createWasmExecMethod(schema);
214
209
  });
215
210
  var blockStmt = [];
@@ -231,7 +226,7 @@ var createExecuteClass = function createExecuteClass(className, implementsClassN
231
226
  exports.createExecuteClass = createExecuteClass;
232
227
 
233
228
  var createExecuteInterface = function createExecuteInterface(className, extendsClassName, execMsg) {
234
- var methods = getMessageProperties(execMsg).map(function (jsonschema) {
229
+ var methods = (0, _utils.getMessageProperties)(execMsg).map(function (jsonschema) {
235
230
  var underscoreName = Object.keys(jsonschema.properties)[0];
236
231
  var methodName = (0, _case.camel)(underscoreName);
237
232
  return createPropertyFunctionWithObjectParams(methodName, 'ExecuteResult', jsonschema.properties[underscoreName]);
@@ -300,7 +295,7 @@ var createPropertyFunctionWithObjectParams = function createPropertyFunctionWith
300
295
  exports.createPropertyFunctionWithObjectParams = createPropertyFunctionWithObjectParams;
301
296
 
302
297
  var createQueryInterface = function createQueryInterface(className, queryMsg) {
303
- var methods = getMessageProperties(queryMsg).map(function (jsonschema) {
298
+ var methods = (0, _utils.getMessageProperties)(queryMsg).map(function (jsonschema) {
304
299
  var underscoreName = Object.keys(jsonschema.properties)[0];
305
300
  var methodName = (0, _case.camel)(underscoreName);
306
301
  var responseType = (0, _case.pascal)("".concat(methodName, "Response"));
package/module/index.js CHANGED
@@ -1,2 +1,4 @@
1
1
  export * from './utils';
2
- export * from './wasm';
2
+ export * from './wasm';
3
+ export * from './recoil';
4
+ export * from './react-query';
@@ -0,0 +1,82 @@
1
+ import * as t from '@babel/types';
2
+ import { camel, pascal } from 'case';
3
+ import { tsPropertySignature, tsObjectPattern, callExpression, getMessageProperties } from './utils';
4
+ import { propertySignature, getPropertyType } from './wasm';
5
+ export const createReactQueryHooks = (queryMsg, contractName, QueryClient) => {
6
+ return getMessageProperties(queryMsg).reduce((m, schema) => {
7
+ const underscoreName = Object.keys(schema.properties)[0];
8
+ const methodName = camel(underscoreName);
9
+ const hookName = `use${pascal(contractName)}${pascal(methodName)}Query`;
10
+ const hookParamsTypeName = `${pascal(contractName)}${pascal(methodName)}Query`;
11
+ const responseType = pascal(`${methodName}Response`);
12
+ const getterKey = camel(`${contractName}${pascal(methodName)}`);
13
+ const jsonschema = schema.properties[underscoreName];
14
+ return [createReactQueryHookInterface({
15
+ hookParamsTypeName,
16
+ responseType,
17
+ QueryClient,
18
+ jsonschema
19
+ }), createReactQueryHook({
20
+ methodName,
21
+ hookName,
22
+ hookParamsTypeName,
23
+ responseType,
24
+ hookKeyName: getterKey,
25
+ jsonschema
26
+ }), ...m];
27
+ }, []);
28
+ };
29
+ export const createReactQueryHook = ({
30
+ hookName,
31
+ hookParamsTypeName,
32
+ responseType,
33
+ hookKeyName,
34
+ methodName,
35
+ jsonschema
36
+ }) => {
37
+ const keys = Object.keys(jsonschema.properties ?? {});
38
+ let args = [];
39
+
40
+ if (keys.length) {
41
+ args = [t.objectExpression([...keys.map(prop => {
42
+ return t.objectProperty(t.identifier(camel(prop)), t.memberExpression(t.identifier('args'), t.identifier(camel(prop))));
43
+ })])];
44
+ }
45
+
46
+ let props = ['client', 'options'];
47
+
48
+ if (keys.length) {
49
+ props = ['client', 'args', 'options'];
50
+ }
51
+
52
+ return t.exportNamedDeclaration(t.functionDeclaration(t.identifier(hookName), [tsObjectPattern([...props.map(prop => {
53
+ return t.objectProperty(t.identifier(prop), t.identifier(prop), false, true);
54
+ })], t.tsTypeAnnotation(t.tsTypeReference(t.identifier(hookParamsTypeName))))], t.blockStatement([t.returnStatement(callExpression(t.identifier('useQuery'), [t.arrayExpression([t.stringLiteral(hookKeyName), t.memberExpression(t.identifier('client'), t.identifier('contractAddress'))]), t.arrowFunctionExpression([], t.callExpression(t.memberExpression(t.identifier('client'), t.identifier(methodName)), args), false), t.identifier('options')], t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier(responseType)), t.tsTypeReference(t.identifier('Error')), t.tsTypeReference(t.identifier(responseType)), t.tsArrayType(t.tsParenthesizedType(t.tsUnionType([t.tsStringKeyword(), t.tsUndefinedKeyword()])))])))])));
55
+ };
56
+ export const createReactQueryHookInterface = ({
57
+ QueryClient,
58
+ hookParamsTypeName,
59
+ responseType,
60
+ jsonschema
61
+ }) => {
62
+ const body = [t.tsPropertySignature(t.identifier('client'), t.tsTypeAnnotation(t.tsTypeReference(t.identifier(QueryClient)))), tsPropertySignature(t.identifier('options'), t.tsTypeAnnotation(t.tsTypeReference(t.identifier('UseQueryOptions'), t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier(responseType)), t.tsTypeReference(t.identifier('Error')), t.tsTypeReference(t.identifier(responseType)), t.tsArrayType(t.tsParenthesizedType(t.tsUnionType([t.tsStringKeyword(), t.tsUndefinedKeyword()])))]))), true)];
63
+ const props = getProps(jsonschema, true);
64
+
65
+ if (props.length) {
66
+ body.push(t.tsPropertySignature(t.identifier('args'), t.tsTypeAnnotation(t.tsTypeLiteral(props))));
67
+ }
68
+
69
+ return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(hookParamsTypeName), null, [], t.tsInterfaceBody(body)));
70
+ };
71
+
72
+ const getProps = (jsonschema, camelize) => {
73
+ const keys = Object.keys(jsonschema.properties ?? {});
74
+ if (!keys.length) return [];
75
+ return keys.map(prop => {
76
+ const {
77
+ type,
78
+ optional
79
+ } = getPropertyType(jsonschema, prop);
80
+ return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(type), optional);
81
+ });
82
+ };
@@ -0,0 +1,26 @@
1
+ import generate from '@babel/generator';
2
+ import * as t from '@babel/types';
3
+ import query_msg from './__fixtures__/schema/query_msg.json';
4
+ import { createReactQueryHooks } from './react-query';
5
+
6
+ const expectCode = ast => {
7
+ expect(generate(ast).code).toMatchSnapshot();
8
+ };
9
+
10
+ const printCode = ast => {
11
+ console.log(generate(ast).code);
12
+ }; // it('createReactQueryHook', () => {
13
+ // printCode(createReactQueryHook({
14
+ // methodName: 'allNftInfo',
15
+ // hookName: 'useSg721AllNftInfoQuery',
16
+ // hookParamsTypeName: 'Sg721CollectionInfoQuery',
17
+ // responseType: 'AllNftInfoResponse',
18
+ // hookKeyName: 'Sg721AllNftInfo'
19
+ // }))
20
+ // });
21
+
22
+
23
+ it('createReactQueryHooks', () => {
24
+ printCode(t.program(createReactQueryHooks(query_msg, 'Sg721', 'Sg721QueryClient')));
25
+ expectCode(t.program(createReactQueryHooks(query_msg, 'Sg721', 'Sg721QueryClient')));
26
+ });
@@ -0,0 +1,58 @@
1
+ import * as t from '@babel/types';
2
+ import { camel, pascal } from 'case';
3
+ import { callExpression, getMessageProperties } from './utils';
4
+ export const createWasmRecoilMethod = jsonschema => {
5
+ const underscoreName = Object.keys(jsonschema.properties)[0];
6
+ const methodName = camel(underscoreName);
7
+ const responseType = pascal(`${methodName}Response`);
8
+ const properties = jsonschema.properties[underscoreName].properties ?? {};
9
+
10
+ if (Object.keys(properties).length > 0) {} else {}
11
+ };
12
+ export const createRecoilSelector = (keyPrefix, QueryClient, methodName) => {
13
+ // const propertyNames = getMessageProperties(queryMsg)
14
+ // .map(method => Object.keys(method.properties)?.[0])
15
+ // .filter(Boolean);
16
+ // const methods = getMessageProperties(queryMsg)
17
+ // .map(schema => createWasmRecoilMethod(schema))
18
+ const selectorName = camel(`${methodName}Selector`);
19
+ const responseType = pascal(`${methodName}Response`);
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.ifStatement(t.unaryExpression('!', t.identifier('client')), t.returnStatement(null), null), 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.tsUnionType([t.tsTypeReference(t.identifier(responseType)), t.tsUndefinedKeyword()]), 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
+ };
24
+ export const createRecoilSelectors = (keyPrefix, QueryClient, queryMsg) => {
25
+ return getMessageProperties(queryMsg).map(schema => {
26
+ const underscoreName = Object.keys(schema.properties)[0];
27
+ const methodName = camel(underscoreName);
28
+ return createRecoilSelector(keyPrefix, QueryClient, methodName);
29
+ });
30
+ };
31
+ export const createRecoilQueryClientType = () => ({
32
+ "type": "TSTypeAliasDeclaration",
33
+ "id": {
34
+ "type": "Identifier",
35
+ "name": "QueryClientParams"
36
+ },
37
+ "typeAnnotation": {
38
+ "type": "TSTypeLiteral",
39
+ "members": [{
40
+ "type": "TSPropertySignature",
41
+ "key": {
42
+ "type": "Identifier",
43
+ "name": "contractAddress"
44
+ },
45
+ "computed": false,
46
+ "typeAnnotation": {
47
+ "type": "TSTypeAnnotation",
48
+ "typeAnnotation": {
49
+ "type": "TSStringKeyword"
50
+ }
51
+ }
52
+ }]
53
+ }
54
+ });
55
+ export const createRecoilQueryClient = (keyPrefix, QueryClient) => {
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.ifStatement(t.unaryExpression('!', t.identifier('client')), t.returnStatement(null), null), t.returnStatement(t.newExpression(t.identifier(QueryClient), [t.identifier('client'), t.identifier('contractAddress')]))]), false)))])], t.tsTypeParameterInstantiation([t.tsUnionType([t.tsTypeReference(t.identifier(QueryClient)), t.tsUndefinedKeyword()]), t.tsTypeReference(t.identifier('QueryClientParams'))])))]));
58
+ };
@@ -0,0 +1,22 @@
1
+ import generate from '@babel/generator';
2
+ import * as t from '@babel/types';
3
+ import query_msg from './__fixtures__/schema/query_msg.json';
4
+ import { createRecoilSelector, createRecoilSelectors, createRecoilQueryClient } from './recoil';
5
+
6
+ const expectCode = ast => {
7
+ expect(generate(ast).code).toMatchSnapshot();
8
+ };
9
+
10
+ const printCode = ast => {
11
+ console.log(generate(ast).code);
12
+ };
13
+
14
+ it('selector', () => {
15
+ expectCode(createRecoilSelector('SG721', 'SG721QueryClient', 'governanceModules'));
16
+ });
17
+ it('selectors', () => {
18
+ expectCode(t.program(createRecoilSelectors('SG721', 'SG721QueryClient', query_msg)));
19
+ });
20
+ it('client', () => {
21
+ printCode(createRecoilQueryClient('SG721', 'SG721QueryClient'));
22
+ });
@@ -0,0 +1,3 @@
1
+ ;
2
+ ;
3
+ export {};
package/module/utils.js CHANGED
@@ -1,5 +1,26 @@
1
1
  import * as t from '@babel/types';
2
2
  import { snake } from "case";
3
+ export const getMessageProperties = msg => {
4
+ if (msg.anyOf) return msg.anyOf;
5
+ if (msg.oneOf) return msg.oneOf;
6
+ if (msg.allOf) return msg.allOf;
7
+ return [];
8
+ };
9
+ export const tsPropertySignature = (key, typeAnnotation, optional) => {
10
+ const obj = t.tsPropertySignature(key, typeAnnotation);
11
+ obj.optional = optional;
12
+ return obj;
13
+ };
14
+ export const tsObjectPattern = (properties, typeAnnotation) => {
15
+ const obj = t.objectPattern(properties);
16
+ obj.typeAnnotation = typeAnnotation;
17
+ return obj;
18
+ };
19
+ export const callExpression = (callee, _arguments, typeParameters) => {
20
+ const callExpr = t.callExpression(callee, _arguments);
21
+ callExpr.typeParameters = typeParameters;
22
+ return callExpr;
23
+ };
3
24
  export const bindMethod = name => {
4
25
  return t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier(name)), t.callExpression(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier(name)), t.identifier('bind')), [t.thisExpression()])));
5
26
  };
package/module/wasm.js CHANGED
@@ -1,18 +1,11 @@
1
1
  import * as t from '@babel/types';
2
2
  import { camel, pascal } from 'case';
3
- import { bindMethod, typedIdentifier, promiseTypeAnnotation, classDeclaration, classProperty, arrowFunctionExpression } from './utils';
4
-
5
- const getMessageProperties = msg => {
6
- if (msg.anyOf) return msg.anyOf;
7
- if (msg.oneOf) return msg.oneOf;
8
- if (msg.allOf) return msg.allOf;
9
- return [];
10
- };
3
+ import { bindMethod, typedIdentifier, promiseTypeAnnotation, classDeclaration, classProperty, arrowFunctionExpression, getMessageProperties } from './utils';
11
4
 
12
5
  const getTypeFromRef = $ref => {
13
6
  switch ($ref) {
14
7
  case '#/definitions/Binary':
15
- return t.tsTypeReference(t.identifier('BinaryType'));
8
+ return t.tsTypeReference(t.identifier('Binary'));
16
9
 
17
10
  case '#/definitions/Expiration':
18
11
  return t.tsTypeReference(t.identifier('Expiration'));
@@ -50,7 +43,7 @@ const getType = type => {
50
43
  }
51
44
  };
52
45
 
53
- const getPropertyType = (schema, prop) => {
46
+ export const getPropertyType = (schema, prop) => {
54
47
  const props = schema.properties ?? {};
55
48
  let info = props[prop];
56
49
  let type = null;
@@ -121,7 +114,6 @@ const getPropertyType = (schema, prop) => {
121
114
  optional
122
115
  };
123
116
  };
124
-
125
117
  export const createWasmQueryMethod = jsonschema => {
126
118
  const underscoreName = Object.keys(jsonschema.properties)[0];
127
119
  const methodName = camel(underscoreName);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wasm-ast-types",
3
- "version": "0.1.2",
3
+ "version": "0.2.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",
@@ -85,5 +85,5 @@
85
85
  "ast-stringify": "0.1.0",
86
86
  "case": "1.6.3"
87
87
  },
88
- "gitHead": "7d83e56b361314f823c9b903b267156036377457"
88
+ "gitHead": "93a3bca65ba5aec086efeb3ae85950a346ddf0ff"
89
89
  }
package/types/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- export * from './types';
2
1
  export * from './utils';
3
2
  export * from './wasm';
3
+ export * from './recoil';
4
+ export * from './react-query';
@@ -0,0 +1,20 @@
1
+ import * as t from '@babel/types';
2
+ import { QueryMsg } from './types';
3
+ interface ReactQueryHookQuery {
4
+ hookName: string;
5
+ hookParamsTypeName: string;
6
+ hookKeyName: string;
7
+ responseType: string;
8
+ methodName: string;
9
+ jsonschema: any;
10
+ }
11
+ export declare const createReactQueryHooks: (queryMsg: QueryMsg, contractName: string, QueryClient: string) => any;
12
+ export declare const createReactQueryHook: ({ hookName, hookParamsTypeName, responseType, hookKeyName, methodName, jsonschema }: ReactQueryHookQuery) => t.ExportNamedDeclaration;
13
+ interface ReactQueryHookQueryInterface {
14
+ QueryClient: string;
15
+ hookParamsTypeName: string;
16
+ responseType: string;
17
+ jsonschema: any;
18
+ }
19
+ export declare const createReactQueryHookInterface: ({ QueryClient, hookParamsTypeName, responseType, jsonschema }: ReactQueryHookQueryInterface) => t.ExportNamedDeclaration;
20
+ export {};
@@ -0,0 +1,30 @@
1
+ import * as t from '@babel/types';
2
+ import { QueryMsg } from './types';
3
+ export declare const createWasmRecoilMethod: (jsonschema: any) => void;
4
+ export declare const createRecoilSelector: (keyPrefix: string, QueryClient: string, methodName: string) => t.ExportNamedDeclaration;
5
+ export declare const createRecoilSelectors: (keyPrefix: string, QueryClient: string, queryMsg: QueryMsg) => any;
6
+ export declare const createRecoilQueryClientType: () => {
7
+ type: string;
8
+ id: {
9
+ type: string;
10
+ name: string;
11
+ };
12
+ typeAnnotation: {
13
+ type: string;
14
+ members: {
15
+ type: string;
16
+ key: {
17
+ type: string;
18
+ name: string;
19
+ };
20
+ computed: boolean;
21
+ typeAnnotation: {
22
+ type: string;
23
+ typeAnnotation: {
24
+ type: string;
25
+ };
26
+ };
27
+ }[];
28
+ };
29
+ };
30
+ export declare const createRecoilQueryClient: (keyPrefix: string, QueryClient: string) => t.ExportNamedDeclaration;
package/types/types.d.ts CHANGED
@@ -8,3 +8,17 @@ export interface Interface {
8
8
  name: string;
9
9
  fields: Field[];
10
10
  }
11
+ export interface QueryMsg {
12
+ $schema: string;
13
+ title: "QueryMsg";
14
+ oneOf?: any;
15
+ allOf?: any;
16
+ anyOf?: any;
17
+ }
18
+ export interface ExecuteMsg {
19
+ $schema: string;
20
+ title: "ExecuteMsg" | "ExecuteMsg_for_Empty";
21
+ oneOf?: any;
22
+ allOf?: any;
23
+ anyOf?: any;
24
+ }
package/types/utils.d.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  import * as t from '@babel/types';
2
- import { Field } from './types';
2
+ import { Field, QueryMsg } from './types';
3
3
  import { TSTypeAnnotation, TSExpressionWithTypeArguments } from '@babel/types';
4
+ export declare const getMessageProperties: (msg: QueryMsg | ExecuteMsg) => any;
5
+ export declare const tsPropertySignature: (key: t.Expression, typeAnnotation: t.TSTypeAnnotation, optional: boolean) => t.TSPropertySignature;
6
+ export declare const tsObjectPattern: (properties: (t.RestElement | t.ObjectProperty)[], typeAnnotation: t.TSTypeAnnotation) => t.ObjectPattern;
7
+ export declare const callExpression: (callee: t.Expression | t.V8IntrinsicIdentifier, _arguments: (t.Expression | t.SpreadElement | t.ArgumentPlaceholder)[], typeParameters: t.TSTypeParameterInstantiation) => t.CallExpression;
4
8
  export declare const bindMethod: (name: string) => t.ExpressionStatement;
5
9
  export declare const typedIdentifier: (name: string, typeAnnotation: TSTypeAnnotation, optional?: boolean) => t.Identifier;
6
10
  export declare const promiseTypeAnnotation: (name: any) => t.TSTypeAnnotation;
package/types/wasm.d.ts CHANGED
@@ -1,21 +1,22 @@
1
1
  import * as t from '@babel/types';
2
- interface QueryMsg {
3
- $schema: string;
4
- title: "QueryMsg";
5
- oneOf: any;
6
- }
7
- interface ExecuteMsg {
8
- $schema: string;
9
- title: "ExecuteMsg" | "ExecuteMsg_for_Empty";
10
- oneOf: any;
11
- }
2
+ import { QueryMsg, ExecuteMsg } from './types';
3
+ export declare const getPropertyType: (schema: any, prop: any) => {
4
+ type: any;
5
+ optional: any;
6
+ };
12
7
  export declare const createWasmQueryMethod: (jsonschema: any) => t.ClassProperty;
13
8
  export declare const createQueryClass: (className: string, implementsClassName: string, queryMsg: QueryMsg) => t.ExportNamedDeclaration;
14
9
  export declare const createWasmExecMethod: (jsonschema: any) => t.ClassProperty;
15
10
  export declare const createExecuteClass: (className: string, implementsClassName: string, extendsClassName: string, execMsg: ExecuteMsg) => t.ExportNamedDeclaration;
16
- export declare const createExecuteInterface: (className: string, extendsClassName: string, execMsg: ExecuteMsg) => t.ExportNamedDeclaration;
11
+ export declare const createExecuteInterface: (className: string, extendsClassName: string | null, execMsg: ExecuteMsg) => t.ExportNamedDeclaration;
12
+ export declare const propertySignature: (name: string, typeAnnotation: t.TSTypeAnnotation, optional?: boolean) => {
13
+ type: string;
14
+ key: t.Identifier;
15
+ typeAnnotation: t.TSTypeAnnotation;
16
+ optional: boolean;
17
+ };
18
+ export declare const createTypedObjectParams: (jsonschema: any, camelize?: boolean) => t.ObjectPattern;
19
+ export declare const createPropertyFunctionWithObjectParams: (methodName: string, responseType: string, jsonschema: any) => t.TSPropertySignature;
17
20
  export declare const createQueryInterface: (className: string, queryMsg: QueryMsg) => t.ExportNamedDeclaration;
18
- export declare const propertySignature: (name: string, typeAnnotation: t.TSTypeAnnotation, optional?: boolean) => t.TSPropertySignature;
19
21
  export declare const createTypeOrInterface: (Type: string, jsonschema: any) => t.ExportNamedDeclaration;
20
22
  export declare const createTypeInterface: (jsonschema: any) => t.ExportNamedDeclaration;
21
- export {};