wasm-ast-types 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -1 +1,130 @@
1
1
  # wasm-ast-types
2
+
3
+ ## working with ASTs
4
+
5
+ ### 1 edit the fixture
6
+
7
+ edit `./scripts/fixture.ts`, for example:
8
+
9
+ ```js
10
+ // ./scripts/fixture.ts
11
+ export interface InstantiateMsg {
12
+ admin?: string | null;
13
+ members: Member[];
14
+ }
15
+ ```
16
+
17
+ ### 2 run AST generator
18
+
19
+ ```
20
+ yarn test:ast
21
+ ```
22
+
23
+ ### 3 look at the JSON produced
24
+
25
+ ```
26
+ code ./scripts/test-output.json
27
+ ```
28
+
29
+ We use the npm module `ast-stringify` to strip out unneccesary props, and generate a JSON for reference.
30
+
31
+ You will see a `File` and `Program`... only concern yourself with the `body[]`:
32
+
33
+ ```json
34
+ {
35
+ "type": "File",
36
+ "errors": [],
37
+ "program": {
38
+ "type": "Program",
39
+ "sourceType": "module",
40
+ "interpreter": null,
41
+ "body": [
42
+ {
43
+ "type": "ExportNamedDeclaration",
44
+ "exportKind": "type",
45
+ "specifiers": [],
46
+ "source": null,
47
+ "declaration": {
48
+ "type": "TSInterfaceDeclaration",
49
+ "id": {
50
+ "type": "Identifier",
51
+ "name": "InstantiateMsg"
52
+ },
53
+ "body": {
54
+ "type": "TSInterfaceBody",
55
+ "body": [
56
+ {
57
+ "type": "TSPropertySignature",
58
+ "key": {
59
+ "type": "Identifier",
60
+ "name": "admin"
61
+ },
62
+ "computed": false,
63
+ "optional": true,
64
+ "typeAnnotation": {
65
+ "type": "TSTypeAnnotation",
66
+ "typeAnnotation": {
67
+ "type": "TSUnionType",
68
+ "types": [
69
+ {
70
+ "type": "TSStringKeyword"
71
+ },
72
+ {
73
+ "type": "TSNullKeyword"
74
+ }
75
+ ]
76
+ }
77
+ }
78
+ },
79
+ {
80
+ "type": "TSPropertySignature",
81
+ "key": {
82
+ "type": "Identifier",
83
+ "name": "members"
84
+ },
85
+ "computed": false,
86
+ "typeAnnotation": {
87
+ "type": "TSTypeAnnotation",
88
+ "typeAnnotation": {
89
+ "type": "TSArrayType",
90
+ "elementType": {
91
+ "type": "TSTypeReference",
92
+ "typeName": {
93
+ "type": "Identifier",
94
+ "name": "Member"
95
+ }
96
+ }
97
+ }
98
+ }
99
+ }
100
+ ]
101
+ }
102
+ }
103
+ }
104
+ ],
105
+ "directives": []
106
+ },
107
+ "comments": []
108
+ }
109
+ ```
110
+
111
+ ### 4 code with `@babel/types` using the JSON as a reference
112
+
113
+ NOTE: 4 continued ideally you should be writing a test with your generator!
114
+
115
+ ```js
116
+ import * as t from '@babel/types';
117
+
118
+ export const createNewGenerator = () => {
119
+ return t.exportNamedDeclaration(
120
+ t.tsInterfaceDeclaration(
121
+ t.identifier('InstantiateMsg'),
122
+ null,
123
+ [],
124
+ t.tsInterfaceBody([
125
+ // ... more code ...
126
+ ])
127
+ )
128
+ );
129
+ };
130
+ ```
@@ -7,10 +7,12 @@ var _typeof = require("@babel/runtime/helpers/typeof");
7
7
  Object.defineProperty(exports, "__esModule", {
8
8
  value: true
9
9
  });
10
- exports.createReactQueryHooks = exports.createReactQueryHookInterface = exports.createReactQueryHook = void 0;
10
+ exports.createReactQueryMutationHooks = exports.createReactQueryMutationHook = exports.createReactQueryMutationArgsInterface = exports.createReactQueryHooks = exports.createReactQueryHookInterface = exports.createReactQueryHook = void 0;
11
11
 
12
12
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
13
13
 
14
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
15
+
14
16
  var t = _interopRequireWildcard(require("@babel/types"));
15
17
 
16
18
  var _case = require("case");
@@ -21,12 +23,20 @@ var _babel = require("./utils/babel");
21
23
 
22
24
  var _types2 = require("./utils/types");
23
25
 
26
+ var _wasm = require("./wasm");
27
+
24
28
  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
29
 
26
30
  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
31
 
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
+
28
36
  var DEFAULT_OPTIONS = {
29
- optionalClient: false
37
+ optionalClient: false,
38
+ v4: false,
39
+ mutations: false
30
40
  };
31
41
 
32
42
  var createReactQueryHooks = function createReactQueryHooks(_ref) {
@@ -34,7 +44,9 @@ var createReactQueryHooks = function createReactQueryHooks(_ref) {
34
44
  contractName = _ref.contractName,
35
45
  QueryClient = _ref.QueryClient,
36
46
  _ref$options = _ref.options,
37
- options = _ref$options === void 0 ? DEFAULT_OPTIONS : _ref$options;
47
+ options = _ref$options === void 0 ? {} : _ref$options;
48
+ // merge the user options with the defaults
49
+ options = _objectSpread(_objectSpread({}, DEFAULT_OPTIONS), options);
38
50
  return (0, _utils.getMessageProperties)(queryMsg).reduce(function (m, schema) {
39
51
  var underscoreName = Object.keys(schema.properties)[0];
40
52
  var methodName = (0, _case.camel)(underscoreName);
@@ -73,7 +85,9 @@ var createReactQueryHook = function createReactQueryHook(_ref2) {
73
85
  methodName = _ref2.methodName,
74
86
  jsonschema = _ref2.jsonschema,
75
87
  _ref2$options = _ref2.options,
76
- options = _ref2$options === void 0 ? DEFAULT_OPTIONS : _ref2$options;
88
+ options = _ref2$options === void 0 ? {} : _ref2$options;
89
+ // merge the user options with the defaults
90
+ options = _objectSpread(_objectSpread({}, DEFAULT_OPTIONS), options);
77
91
  var keys = Object.keys((_jsonschema$propertie = jsonschema.properties) !== null && _jsonschema$propertie !== void 0 ? _jsonschema$propertie : {});
78
92
  var args = [];
79
93
 
@@ -91,19 +105,157 @@ var createReactQueryHook = function createReactQueryHook(_ref2) {
91
105
 
92
106
  return t.exportNamedDeclaration(t.functionDeclaration(t.identifier(hookName), [(0, _utils.tsObjectPattern)((0, _toConsumableArray2["default"])(props.map(function (prop) {
93
107
  return t.objectProperty(t.identifier(prop), t.identifier(prop), false, true);
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()])))])))])));
108
+ })), t.tsTypeAnnotation(t.tsTypeReference(t.identifier(hookParamsTypeName))))], t.blockStatement([t.returnStatement((0, _utils.callExpression)(t.identifier('useQuery'), [t.arrayExpression(generateUseQueryQueryKey(hookKeyName, props, 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.conditionalExpression( // explicitly check for undefined
109
+ t.binaryExpression('!=', t.optionalMemberExpression(t.identifier('options'), t.identifier('enabled'), false, true), t.identifier('undefined')), t.memberExpression(t.identifier('options'), t.identifier('enabled')), t.booleanLiteral(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()])))])))])));
95
110
  };
96
111
 
97
112
  exports.createReactQueryHook = createReactQueryHook;
98
113
 
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)];
114
+ /**
115
+ * Example:
116
+ ```
117
+ export interface Cw4UpdateMembersMutation {
118
+ client: Cw4GroupClient
119
+ args: {
120
+ tokenId: string
121
+ remove: string[]
122
+ }
123
+ options?: Omit<
124
+ UseMutationOptions<ExecuteResult, Error, Pick<Cw4UpdateMembersMutation, 'args'>>,
125
+ 'mutationFn'
126
+ >
127
+ }
128
+ ```
129
+ */
130
+ var createReactQueryMutationArgsInterface = function createReactQueryMutationArgsInterface(_ref3) {
131
+ var _jsonschema$$ref;
132
+
133
+ var ExecuteClient = _ref3.ExecuteClient,
134
+ mutationHookParamsTypeName = _ref3.mutationHookParamsTypeName,
135
+ useMutationTypeParameter = _ref3.useMutationTypeParameter,
136
+ jsonschema = _ref3.jsonschema;
137
+ var typedUseMutationOptions = t.tsTypeReference(t.identifier('UseMutationOptions'), useMutationTypeParameter);
138
+ var body = [(0, _utils.tsPropertySignature)(t.identifier('client'), t.tsTypeAnnotation(t.tsTypeReference(t.identifier(ExecuteClient))), false)];
139
+ var msgType = (0, _types2.getParamsTypeAnnotation)(jsonschema); // TODO: this should not have to be done manually.
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
+ }
150
+
151
+ if (msgType) {
152
+ body.push(t.tsPropertySignature(t.identifier('msg'), msgType));
153
+ } // fee: number | StdFee | "auto" = "auto", memo?: string, funds?: readonly Coin[]
154
+
155
+
156
+ var optionalArgs = t.tsPropertySignature(t.identifier('args'), t.tsTypeAnnotation(t.tsTypeLiteral(_wasm.FIXED_EXECUTE_PARAMS.map(function (param) {
157
+ return (0, _babel.propertySignature)(param.name, param.typeAnnotation, param.optional);
158
+ }))));
159
+ optionalArgs.optional = true;
160
+ body.push(optionalArgs);
161
+ return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(mutationHookParamsTypeName), null, [], t.tsInterfaceBody(body)));
162
+ };
163
+
164
+ exports.createReactQueryMutationArgsInterface = createReactQueryMutationArgsInterface;
165
+
166
+ var createReactQueryMutationHooks = function createReactQueryMutationHooks(_ref4) {
167
+ var execMsg = _ref4.execMsg,
168
+ contractName = _ref4.contractName,
169
+ ExecuteClient = _ref4.ExecuteClient,
170
+ _ref4$options = _ref4.options,
171
+ options = _ref4$options === void 0 ? {} : _ref4$options;
172
+ // merge the user options with the defaults
173
+ return (0, _utils.getMessageProperties)(execMsg).reduce(function (m, schema) {
174
+ var _jsonschema$propertie2, _Object$keys;
175
+
176
+ // update_members
177
+ var execMethodUnderscoreName = Object.keys(schema.properties)[0]; // updateMembers
178
+
179
+ var execMethodName = (0, _case.camel)(execMethodUnderscoreName); // Cw20UpdateMembersMutation
180
+
181
+ var mutationHookParamsTypeName = "".concat((0, _case.pascal)(contractName)).concat((0, _case.pascal)(execMethodName), "Mutation"); // useCw20UpdateMembersMutation
182
+
183
+ var mutationHookName = "use".concat(mutationHookParamsTypeName);
184
+ var jsonschema = schema.properties[execMethodUnderscoreName];
185
+ var properties = (_jsonschema$propertie2 = jsonschema.properties) !== null && _jsonschema$propertie2 !== void 0 ? _jsonschema$propertie2 : {}; // TODO: there should be a better way to do this
186
+
187
+ var hasMsg = !!((_Object$keys = Object.keys(properties)) !== null && _Object$keys !== void 0 && _Object$keys.length || jsonschema !== null && jsonschema !== void 0 && jsonschema.$ref); // <ExecuteResult, Error, Cw4UpdateMembersMutation>
188
+
189
+ var useMutationTypeParameter = generateMutationTypeParameter(mutationHookParamsTypeName, hasMsg);
190
+ return [createReactQueryMutationArgsInterface({
191
+ mutationHookParamsTypeName: mutationHookParamsTypeName,
192
+ ExecuteClient: ExecuteClient,
193
+ jsonschema: jsonschema,
194
+ useMutationTypeParameter: useMutationTypeParameter
195
+ }), createReactQueryMutationHook({
196
+ execMethodName: execMethodName,
197
+ mutationHookName: mutationHookName,
198
+ mutationHookParamsTypeName: mutationHookParamsTypeName,
199
+ hasMsg: hasMsg,
200
+ useMutationTypeParameter: useMutationTypeParameter
201
+ })].concat((0, _toConsumableArray2["default"])(m));
202
+ }, []);
203
+ };
204
+ /**
205
+ * Generates the mutation type parameter. If args exist, we use a pick. If not, we just return the params type.
206
+ */
207
+
208
+
209
+ exports.createReactQueryMutationHooks = createReactQueryMutationHooks;
210
+
211
+ function generateMutationTypeParameter(mutationHookParamsTypeName, hasArgs) {
212
+ return t.tsTypeParameterInstantiation([// Data
213
+ t.tSTypeReference(t.identifier('ExecuteResult')), // Error
214
+ t.tsTypeReference(t.identifier('Error')), // Variables
215
+ t.tsTypeReference(t.identifier(mutationHookParamsTypeName))]);
216
+ }
217
+
218
+ /**
219
+ *
220
+ * Example:
221
+ ```
222
+ export const useCw4UpdateMembersMutation = ({ client, options }: Omit<Cw4UpdateMembersMutation, 'args'>) =>
223
+ useMutation<ExecuteResult, Error, Pick<Cw4UpdateMembersMutation, 'args'>>(
224
+ ({ args }) => client.updateMembers(args),
225
+ options
226
+ )
227
+ ```
228
+ */
229
+ var createReactQueryMutationHook = function createReactQueryMutationHook(_ref5) {
230
+ var mutationHookName = _ref5.mutationHookName,
231
+ mutationHookParamsTypeName = _ref5.mutationHookParamsTypeName,
232
+ execMethodName = _ref5.execMethodName,
233
+ useMutationTypeParameter = _ref5.useMutationTypeParameter,
234
+ hasMsg = _ref5.hasMsg;
235
+ var useMutationFunctionArgs = [(0, _babel.shorthandProperty)('client')];
236
+ if (hasMsg) useMutationFunctionArgs.push((0, _babel.shorthandProperty)('msg'));
237
+ useMutationFunctionArgs.push(t.objectProperty(t.identifier('args'), t.assignmentPattern(t.objectPattern(_wasm.FIXED_EXECUTE_PARAMS.map(function (param) {
238
+ return (0, _babel.shorthandProperty)(param.name);
239
+ })), 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(_wasm.FIXED_EXECUTE_PARAMS.map(function (param) {
241
+ return t.identifier(param.name);
242
+ }))), false // not async
243
+ ), t.identifier('options')], useMutationTypeParameter))])));
244
+ };
245
+
246
+ exports.createReactQueryMutationHook = createReactQueryMutationHook;
247
+
248
+ var createReactQueryHookInterface = function createReactQueryHookInterface(_ref6) {
249
+ var QueryClient = _ref6.QueryClient,
250
+ hookParamsTypeName = _ref6.hookParamsTypeName,
251
+ responseType = _ref6.responseType,
252
+ jsonschema = _ref6.jsonschema,
253
+ _ref6$options = _ref6.options,
254
+ options = _ref6$options === void 0 ? {} : _ref6$options;
255
+ // merge the user options with the defaults
256
+ options = _objectSpread(_objectSpread({}, DEFAULT_OPTIONS), options);
257
+ 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
+ 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)];
107
259
  var props = getProps(jsonschema, true);
108
260
 
109
261
  if (props.length) {
@@ -116,9 +268,9 @@ var createReactQueryHookInterface = function createReactQueryHookInterface(_ref3
116
268
  exports.createReactQueryHookInterface = createReactQueryHookInterface;
117
269
 
118
270
  var getProps = function getProps(jsonschema, camelize) {
119
- var _jsonschema$propertie2;
271
+ var _jsonschema$propertie3;
120
272
 
121
- var keys = Object.keys((_jsonschema$propertie2 = jsonschema.properties) !== null && _jsonschema$propertie2 !== void 0 ? _jsonschema$propertie2 : {});
273
+ var keys = Object.keys((_jsonschema$propertie3 = jsonschema.properties) !== null && _jsonschema$propertie3 !== void 0 ? _jsonschema$propertie3 : {});
122
274
  if (!keys.length) return [];
123
275
  return keys.map(function (prop) {
124
276
  var _getPropertyType = (0, _types2.getPropertyType)(jsonschema, prop),
@@ -127,4 +279,14 @@ var getProps = function getProps(jsonschema, camelize) {
127
279
 
128
280
  return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(type), optional);
129
281
  });
130
- };
282
+ };
283
+
284
+ function generateUseQueryQueryKey(hookKeyName, props, optionalClient) {
285
+ var queryKey = [t.stringLiteral(hookKeyName), t.optionalMemberExpression(t.identifier('client'), t.identifier('contractAddress'), false, optionalClient)];
286
+
287
+ if (props.includes('args')) {
288
+ queryKey.push(t.callExpression(t.memberExpression(t.identifier('JSON'), t.identifier('stringify')), [t.identifier('args')]));
289
+ }
290
+
291
+ return queryKey;
292
+ }
@@ -10,6 +10,8 @@ var t = _interopRequireWildcard(require("@babel/types"));
10
10
 
11
11
  var _query_msg = _interopRequireDefault(require("./../../../__fixtures__/basic/query_msg.json"));
12
12
 
13
+ var _execute_msg_for__empty = _interopRequireDefault(require("./../../../__fixtures__/basic/execute_msg_for__empty.json"));
14
+
13
15
  var _reactQuery = require("./react-query");
14
16
 
15
17
  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); }
@@ -52,4 +54,26 @@ it('createReactQueryHooks', function () {
52
54
  optionalClient: true
53
55
  }
54
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
+ }
64
+ })));
65
+ expectCode(t.program((0, _reactQuery.createReactQueryHooks)({
66
+ queryMsg: _query_msg["default"],
67
+ contractName: 'Sg721',
68
+ QueryClient: 'Sg721QueryClient',
69
+ options: {
70
+ optionalClient: true,
71
+ v4: true
72
+ }
73
+ })));
74
+ expectCode(t.program((0, _reactQuery.createReactQueryMutationHooks)({
75
+ execMsg: _execute_msg_for__empty["default"],
76
+ contractName: 'Sg721',
77
+ ExecuteClient: 'Sg721Client'
78
+ })));
55
79
  });
@@ -31,5 +31,5 @@ it('selectors', function () {
31
31
  expectCode(t.program((0, _recoil.createRecoilSelectors)('SG721', 'SG721QueryClient', _query_msg["default"])));
32
32
  });
33
33
  it('client', function () {
34
- printCode((0, _recoil.createRecoilQueryClient)('SG721', 'SG721QueryClient'));
34
+ expectCode((0, _recoil.createRecoilQueryClient)('SG721', 'SG721QueryClient'));
35
35
  });
@@ -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.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;
10
+ exports.typedIdentifier = exports.typeRefOrOptionalUnion = exports.tsTypeOperator = exports.tsPropertySignature = exports.tsObjectPattern = exports.shorthandProperty = exports.recursiveNamespace = exports.propertySignature = exports.promiseTypeAnnotation = exports.pickTypeReference = exports.parameterizedTypeReference = exports.optionalConditionalExpression = exports.omitTypeReference = 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
 
@@ -21,6 +21,7 @@ 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
+ // t.TSPropertySignature - kind?
24
25
  var propertySignature = function propertySignature(name, typeAnnotation) {
25
26
  var optional = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
26
27
  return {
@@ -279,4 +280,29 @@ var typeRefOrOptionalUnion = function typeRefOrOptionalUnion(identifier) {
279
280
  return optional ? t.tsUnionType([typeReference, t.tsUndefinedKeyword()]) : typeReference;
280
281
  };
281
282
 
282
- exports.typeRefOrOptionalUnion = typeRefOrOptionalUnion;
283
+ exports.typeRefOrOptionalUnion = typeRefOrOptionalUnion;
284
+
285
+ var parameterizedTypeReference = function parameterizedTypeReference(identifier, from, omit) {
286
+ return t.tsTypeReference(t.identifier(identifier), t.tsTypeParameterInstantiation([from, typeof omit === 'string' ? t.tsLiteralType(t.stringLiteral(omit)) : t.tsUnionType(omit.map(function (o) {
287
+ return t.tsLiteralType(t.stringLiteral(o));
288
+ }))]));
289
+ };
290
+ /**
291
+ * omitTypeReference(t.tsTypeReference(t.identifier('Cw4UpdateMembersMutation'),),'args').....
292
+ * Omit<Cw4UpdateMembersMutation, 'args'>
293
+ */
294
+
295
+
296
+ exports.parameterizedTypeReference = parameterizedTypeReference;
297
+
298
+ var omitTypeReference = function omitTypeReference(from, omit) {
299
+ return parameterizedTypeReference('Omit', from, omit);
300
+ };
301
+
302
+ exports.omitTypeReference = omitTypeReference;
303
+
304
+ var pickTypeReference = function pickTypeReference(from, pick) {
305
+ return parameterizedTypeReference('Pick', from, pick);
306
+ };
307
+
308
+ exports.pickTypeReference = pickTypeReference;