wasm-ast-types 0.8.2 → 0.9.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/context/context.js
CHANGED
@@ -34,17 +34,38 @@ var createReactQueryHooks = function createReactQueryHooks(_ref) {
|
|
34
34
|
QueryClient = _ref.QueryClient;
|
35
35
|
var options = context.options.reactQuery;
|
36
36
|
var genericQueryInterfaceName = "".concat((0, _case.pascal)(contractName), "ReactQuery");
|
37
|
-
var
|
37
|
+
var underscoreNames = (0, _utils.getMessageProperties)(queryMsg).map(function (schema) {
|
38
|
+
return Object.keys(schema.properties)[0];
|
39
|
+
});
|
40
|
+
var body = [];
|
41
|
+
var queryKeysName = "".concat((0, _case.camel)(contractName), "QueryKeys");
|
42
|
+
|
43
|
+
if (options.queryKeys) {
|
44
|
+
body.push(createReactQueryKeys({
|
45
|
+
context: context,
|
46
|
+
queryKeysName: queryKeysName,
|
47
|
+
camelContractName: (0, _case.camel)(contractName),
|
48
|
+
underscoreNames: underscoreNames
|
49
|
+
}));
|
50
|
+
}
|
51
|
+
|
52
|
+
body.push(createReactQueryHookGenericInterface({
|
38
53
|
context: context,
|
39
54
|
QueryClient: QueryClient,
|
40
55
|
genericQueryInterfaceName: genericQueryInterfaceName
|
41
|
-
})
|
56
|
+
}));
|
42
57
|
body.push.apply(body, (0, _toConsumableArray2["default"])((0, _utils.getMessageProperties)(queryMsg).reduce(function (m, schema) {
|
43
|
-
|
44
|
-
var
|
45
|
-
|
46
|
-
var
|
47
|
-
|
58
|
+
// list_voters
|
59
|
+
var underscoreName = Object.keys(schema.properties)[0]; // listVoters
|
60
|
+
|
61
|
+
var methodName = (0, _case.camel)(underscoreName); // Cw3FlexMultisigListVotersQuery
|
62
|
+
|
63
|
+
var hookParamsTypeName = "".concat((0, _case.pascal)(contractName)).concat((0, _case.pascal)(methodName), "Query"); // useCw3FlexMultisigListVotersQuery
|
64
|
+
|
65
|
+
var hookName = "use".concat(hookParamsTypeName); // listVotersResponse
|
66
|
+
|
67
|
+
var responseType = (0, _case.pascal)("".concat(methodName, "Response")); // cw3FlexMultisigListVoters
|
68
|
+
|
48
69
|
var getterKey = (0, _case.camel)("".concat(contractName).concat((0, _case.pascal)(methodName)));
|
49
70
|
var jsonschema = schema.properties[underscoreName];
|
50
71
|
return [createReactQueryHookInterface({
|
@@ -59,6 +80,7 @@ var createReactQueryHooks = function createReactQueryHooks(_ref) {
|
|
59
80
|
methodName: methodName,
|
60
81
|
hookName: hookName,
|
61
82
|
hookParamsTypeName: hookParamsTypeName,
|
83
|
+
queryKeysName: queryKeysName,
|
62
84
|
responseType: responseType,
|
63
85
|
hookKeyName: getterKey,
|
64
86
|
jsonschema: jsonschema
|
@@ -77,6 +99,7 @@ var createReactQueryHook = function createReactQueryHook(_ref2) {
|
|
77
99
|
hookParamsTypeName = _ref2.hookParamsTypeName,
|
78
100
|
responseType = _ref2.responseType,
|
79
101
|
hookKeyName = _ref2.hookKeyName,
|
102
|
+
queryKeysName = _ref2.queryKeysName,
|
80
103
|
methodName = _ref2.methodName,
|
81
104
|
jsonschema = _ref2.jsonschema;
|
82
105
|
context.addUtil('useQuery');
|
@@ -97,10 +120,20 @@ var createReactQueryHook = function createReactQueryHook(_ref2) {
|
|
97
120
|
props = ['client', 'args', 'options'];
|
98
121
|
}
|
99
122
|
|
100
|
-
|
123
|
+
var selectResponseGenericTypeName = 'TData';
|
124
|
+
var queryFunctionDeclaration = t.functionDeclaration(t.identifier(hookName), [(0, _utils.tsObjectPattern)((0, _toConsumableArray2["default"])(props.map(function (prop) {
|
101
125
|
return t.objectProperty(t.identifier(prop), t.identifier(prop), false, true);
|
102
|
-
})), t.tsTypeAnnotation(t.tsTypeReference(t.identifier(hookParamsTypeName)
|
103
|
-
|
126
|
+
})), t.tsTypeAnnotation(t.tsTypeReference(t.identifier(hookParamsTypeName), t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier(selectResponseGenericTypeName))]))))], t.blockStatement([t.returnStatement((0, _utils.callExpression)(t.identifier('useQuery'), [generateUseQueryQueryKey({
|
127
|
+
hookKeyName: hookKeyName,
|
128
|
+
queryKeysName: queryKeysName,
|
129
|
+
methodName: methodName,
|
130
|
+
props: props,
|
131
|
+
options: options
|
132
|
+
}), t.arrowFunctionExpression([], (0, _babel.optionalConditionalExpression)(t.identifier('client'), t.callExpression(t.memberExpression(t.identifier('client'), t.identifier(methodName)), args), t.callExpression(t.memberExpression(t.identifier('Promise'), t.identifier('reject')), [t.newExpression(t.identifier('Error'), [t.stringLiteral('Invalid client')])]), 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
|
133
|
+
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([t.tsTypeReference(t.identifier(responseType)), t.tsTypeReference(t.identifier('Error')), t.tsTypeReference(t.identifier(selectResponseGenericTypeName))])))])); // Add the TData type parameters
|
134
|
+
|
135
|
+
queryFunctionDeclaration.typeParameters = t.tsTypeParameterDeclaration([t.tsTypeParameter(undefined, t.tSTypeReference(t.identifier(responseType)), selectResponseGenericTypeName)]);
|
136
|
+
return t.exportNamedDeclaration(queryFunctionDeclaration);
|
104
137
|
};
|
105
138
|
|
106
139
|
exports.createReactQueryHook = createReactQueryHook;
|
@@ -237,25 +270,52 @@ var createReactQueryMutationHook = function createReactQueryMutationHook(_ref5)
|
|
237
270
|
|
238
271
|
exports.createReactQueryMutationHook = createReactQueryMutationHook;
|
239
272
|
|
240
|
-
function
|
273
|
+
function createReactQueryKeys(_ref6) {
|
241
274
|
var context = _ref6.context,
|
242
|
-
|
243
|
-
|
275
|
+
queryKeysName = _ref6.queryKeysName,
|
276
|
+
camelContractName = _ref6.camelContractName,
|
277
|
+
underscoreNames = _ref6.underscoreNames;
|
244
278
|
var options = context.options.reactQuery;
|
245
|
-
var
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
279
|
+
var contractAddressTypeAnnotation = t.tsTypeAnnotation(options.optionalClient ? t.tsUnionType([t.tsStringKeyword(), t.tsUndefinedKeyword()]) : t.tSStringKeyword());
|
280
|
+
return t.exportNamedDeclaration(t.variableDeclaration('const', [t.variableDeclarator(t.identifier(queryKeysName), t.objectExpression([// 1: contract
|
281
|
+
t.objectProperty(t.identifier('contract'), t.tSAsExpression(t.arrayExpression([t.objectExpression([t.objectProperty(t.identifier('contract'), t.stringLiteral(camelContractName))])]), t.tSTypeReference(t.identifier('const')))), // 2: address
|
282
|
+
t.objectProperty(t.identifier('address'), t.arrowFunctionExpression([(0, _utils.identifier)('contractAddress', contractAddressTypeAnnotation)], t.tSAsExpression(t.arrayExpression([t.objectExpression([// 1
|
283
|
+
t.spreadElement(t.memberExpression(t.memberExpression(t.identifier(queryKeysName), t.identifier('contract')), t.numericLiteral(0), true // computed
|
284
|
+
)), t.objectProperty(t.identifier('address'), t.identifier('contractAddress'))])]), t.tSTypeReference(t.identifier('const')))))].concat((0, _toConsumableArray2["default"])(underscoreNames.map(function (underscoreMethodName) {
|
285
|
+
return t.objectProperty( // key id is the camel method name
|
286
|
+
t.identifier((0, _case.camel)(underscoreMethodName)), t.arrowFunctionExpression([(0, _utils.identifier)('contractAddress', contractAddressTypeAnnotation), (0, _utils.identifier)('args', // Record<string, unknown>
|
287
|
+
t.tSTypeAnnotation(t.tsTypeReference(t.identifier('Record'), t.tsTypeParameterInstantiation([t.tsStringKeyword(), t.tsUnknownKeyword()]))), true // optional
|
288
|
+
)], t.tSAsExpression(t.arrayExpression([t.objectExpression([//...cw3FlexMultisigQueryKeys.address(contractAddress)[0]
|
289
|
+
t.spreadElement(t.memberExpression(t.callExpression(t.memberExpression(t.identifier(queryKeysName), t.identifier('address')), [t.identifier('contractAddress')]), t.numericLiteral(0), true // computed
|
290
|
+
)), // method: list_voters
|
291
|
+
t.objectProperty(t.identifier('method'), t.stringLiteral(underscoreMethodName)), // args
|
292
|
+
(0, _babel.shorthandProperty)('args')])]), t.tSTypeReference(t.identifier('const')))));
|
293
|
+
})))))]));
|
250
294
|
}
|
251
295
|
|
252
|
-
|
296
|
+
function createReactQueryHookGenericInterface(_ref7) {
|
253
297
|
var context = _ref7.context,
|
254
298
|
QueryClient = _ref7.QueryClient,
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
299
|
+
genericQueryInterfaceName = _ref7.genericQueryInterfaceName;
|
300
|
+
var options = context.options.reactQuery;
|
301
|
+
var genericResponseTypeName = 'TResponse';
|
302
|
+
var genericSelectResponseTypeName = 'TData';
|
303
|
+
context.addUtil('UseQueryOptions'); // UseQueryOptions<TResponse, Error, TData>,
|
304
|
+
|
305
|
+
var typedUseQueryOptions = t.tsTypeReference(t.identifier('UseQueryOptions'), t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier(genericResponseTypeName)), t.tsTypeReference(t.identifier('Error')), t.tsTypeReference(t.identifier(genericSelectResponseTypeName))]));
|
306
|
+
var body = [(0, _utils.tsPropertySignature)(t.identifier('client'), t.tsTypeAnnotation(options.optionalClient ? t.tsUnionType([t.tsTypeReference(t.identifier(QueryClient)), t.tsUndefinedKeyword()]) : t.tsTypeReference(t.identifier(QueryClient))), false), (0, _utils.tsPropertySignature)(t.identifier('options'), t.tsTypeAnnotation(options.version === 'v4' ? t.tSIntersectionType([(0, _babel.omitTypeReference)(typedUseQueryOptions, "'queryKey' | 'queryFn' | 'initialData'"), t.tSTypeLiteral([t.tsPropertySignature(t.identifier('initialData?'), t.tsTypeAnnotation(t.tsUndefinedKeyword()))])]) : typedUseQueryOptions), true)];
|
307
|
+
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(genericQueryInterfaceName), t.tsTypeParameterDeclaration([// 1: TResponse
|
308
|
+
t.tsTypeParameter(undefined, undefined, genericResponseTypeName), // 2: TData
|
309
|
+
t.tsTypeParameter(undefined, t.tSTypeReference(t.identifier(genericResponseTypeName)), genericSelectResponseTypeName)]), [], t.tSInterfaceBody(body)));
|
310
|
+
}
|
311
|
+
|
312
|
+
var createReactQueryHookInterface = function createReactQueryHookInterface(_ref8) {
|
313
|
+
var context = _ref8.context,
|
314
|
+
QueryClient = _ref8.QueryClient,
|
315
|
+
hookParamsTypeName = _ref8.hookParamsTypeName,
|
316
|
+
queryInterfaceName = _ref8.queryInterfaceName,
|
317
|
+
responseType = _ref8.responseType,
|
318
|
+
jsonschema = _ref8.jsonschema;
|
259
319
|
// merge the user options with the defaults
|
260
320
|
var options = context.options.reactQuery;
|
261
321
|
var body = [];
|
@@ -266,7 +326,9 @@ var createReactQueryHookInterface = function createReactQueryHookInterface(_ref7
|
|
266
326
|
t.tsTypeLiteral(props))));
|
267
327
|
}
|
268
328
|
|
269
|
-
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(hookParamsTypeName),
|
329
|
+
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(hookParamsTypeName), t.tsTypeParameterDeclaration([t.tSTypeParameter(undefined, undefined, 'TData')]), [t.tSExpressionWithTypeArguments(t.identifier(queryInterfaceName), t.tsTypeParameterInstantiation([// 1: response
|
330
|
+
t.tsTypeReference(t.identifier(responseType)), // 2: select generic
|
331
|
+
t.tSTypeReference(t.identifier('TData'))]))], t.tsInterfaceBody(body)));
|
270
332
|
};
|
271
333
|
|
272
334
|
exports.createReactQueryHookInterface = createReactQueryHookInterface;
|
@@ -285,12 +347,28 @@ var getProps = function getProps(context, jsonschema) {
|
|
285
347
|
});
|
286
348
|
};
|
287
349
|
|
288
|
-
var generateUseQueryQueryKey = function generateUseQueryQueryKey(
|
289
|
-
var
|
350
|
+
var generateUseQueryQueryKey = function generateUseQueryQueryKey(_ref9) {
|
351
|
+
var hookKeyName = _ref9.hookKeyName,
|
352
|
+
queryKeysName = _ref9.queryKeysName,
|
353
|
+
methodName = _ref9.methodName,
|
354
|
+
props = _ref9.props,
|
355
|
+
options = _ref9.options;
|
356
|
+
var optionalClient = options.optionalClient,
|
357
|
+
queryKeys = options.queryKeys;
|
358
|
+
var hasArgs = props.includes('args');
|
359
|
+
var contractAddressExpression = t.optionalMemberExpression(t.identifier('client'), t.identifier('contractAddress'), false, optionalClient);
|
360
|
+
|
361
|
+
if (queryKeys) {
|
362
|
+
var callArgs = [contractAddressExpression];
|
363
|
+
if (hasArgs) callArgs.push(t.identifier('args'));
|
364
|
+
return t.callExpression(t.memberExpression(t.identifier(queryKeysName), t.identifier((0, _case.camel)(methodName))), callArgs);
|
365
|
+
}
|
366
|
+
|
367
|
+
var queryKey = [t.stringLiteral(hookKeyName), contractAddressExpression];
|
290
368
|
|
291
|
-
if (
|
369
|
+
if (hasArgs) {
|
292
370
|
queryKey.push(t.callExpression(t.memberExpression(t.identifier('JSON'), t.identifier('stringify')), [t.identifier('args')]));
|
293
371
|
}
|
294
372
|
|
295
|
-
return queryKey;
|
373
|
+
return t.arrayExpression(queryKey);
|
296
374
|
};
|
@@ -12,17 +12,36 @@ export const createReactQueryHooks = ({
|
|
12
12
|
}) => {
|
13
13
|
const options = context.options.reactQuery;
|
14
14
|
const genericQueryInterfaceName = `${pascal(contractName)}ReactQuery`;
|
15
|
-
const
|
15
|
+
const underscoreNames = getMessageProperties(queryMsg).map(schema => Object.keys(schema.properties)[0]);
|
16
|
+
const body = [];
|
17
|
+
const queryKeysName = `${camel(contractName)}QueryKeys`;
|
18
|
+
|
19
|
+
if (options.queryKeys) {
|
20
|
+
body.push(createReactQueryKeys({
|
21
|
+
context,
|
22
|
+
queryKeysName,
|
23
|
+
camelContractName: camel(contractName),
|
24
|
+
underscoreNames
|
25
|
+
}));
|
26
|
+
}
|
27
|
+
|
28
|
+
body.push(createReactQueryHookGenericInterface({
|
16
29
|
context,
|
17
30
|
QueryClient,
|
18
31
|
genericQueryInterfaceName
|
19
|
-
})
|
32
|
+
}));
|
20
33
|
body.push(...getMessageProperties(queryMsg).reduce((m, schema) => {
|
21
|
-
|
22
|
-
const
|
23
|
-
|
24
|
-
const
|
25
|
-
|
34
|
+
// list_voters
|
35
|
+
const underscoreName = Object.keys(schema.properties)[0]; // listVoters
|
36
|
+
|
37
|
+
const methodName = camel(underscoreName); // Cw3FlexMultisigListVotersQuery
|
38
|
+
|
39
|
+
const hookParamsTypeName = `${pascal(contractName)}${pascal(methodName)}Query`; // useCw3FlexMultisigListVotersQuery
|
40
|
+
|
41
|
+
const hookName = `use${hookParamsTypeName}`; // listVotersResponse
|
42
|
+
|
43
|
+
const responseType = pascal(`${methodName}Response`); // cw3FlexMultisigListVoters
|
44
|
+
|
26
45
|
const getterKey = camel(`${contractName}${pascal(methodName)}`);
|
27
46
|
const jsonschema = schema.properties[underscoreName];
|
28
47
|
return [createReactQueryHookInterface({
|
@@ -37,6 +56,7 @@ export const createReactQueryHooks = ({
|
|
37
56
|
methodName,
|
38
57
|
hookName,
|
39
58
|
hookParamsTypeName,
|
59
|
+
queryKeysName,
|
40
60
|
responseType,
|
41
61
|
hookKeyName: getterKey,
|
42
62
|
jsonschema
|
@@ -50,6 +70,7 @@ export const createReactQueryHook = ({
|
|
50
70
|
hookParamsTypeName,
|
51
71
|
responseType,
|
52
72
|
hookKeyName,
|
73
|
+
queryKeysName,
|
53
74
|
methodName,
|
54
75
|
jsonschema
|
55
76
|
}) => {
|
@@ -71,10 +92,20 @@ export const createReactQueryHook = ({
|
|
71
92
|
props = ['client', 'args', 'options'];
|
72
93
|
}
|
73
94
|
|
74
|
-
|
95
|
+
const selectResponseGenericTypeName = 'TData';
|
96
|
+
const queryFunctionDeclaration = t.functionDeclaration(t.identifier(hookName), [tsObjectPattern([...props.map(prop => {
|
75
97
|
return t.objectProperty(t.identifier(prop), t.identifier(prop), false, true);
|
76
|
-
})], t.tsTypeAnnotation(t.tsTypeReference(t.identifier(hookParamsTypeName)
|
77
|
-
|
98
|
+
})], t.tsTypeAnnotation(t.tsTypeReference(t.identifier(hookParamsTypeName), t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier(selectResponseGenericTypeName))]))))], t.blockStatement([t.returnStatement(callExpression(t.identifier('useQuery'), [generateUseQueryQueryKey({
|
99
|
+
hookKeyName,
|
100
|
+
queryKeysName,
|
101
|
+
methodName,
|
102
|
+
props,
|
103
|
+
options
|
104
|
+
}), t.arrowFunctionExpression([], optionalConditionalExpression(t.identifier('client'), t.callExpression(t.memberExpression(t.identifier('client'), t.identifier(methodName)), args), t.callExpression(t.memberExpression(t.identifier('Promise'), t.identifier('reject')), [t.newExpression(t.identifier('Error'), [t.stringLiteral('Invalid client')])]), 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
|
105
|
+
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([t.tsTypeReference(t.identifier(responseType)), t.tsTypeReference(t.identifier('Error')), t.tsTypeReference(t.identifier(selectResponseGenericTypeName))])))])); // Add the TData type parameters
|
106
|
+
|
107
|
+
queryFunctionDeclaration.typeParameters = t.tsTypeParameterDeclaration([t.tsTypeParameter(undefined, t.tSTypeReference(t.identifier(responseType)), selectResponseGenericTypeName)]);
|
108
|
+
return t.exportNamedDeclaration(queryFunctionDeclaration);
|
78
109
|
};
|
79
110
|
|
80
111
|
/**
|
@@ -196,17 +227,44 @@ export const createReactQueryMutationHook = ({
|
|
196
227
|
), t.identifier('options')], useMutationTypeParameter))])));
|
197
228
|
};
|
198
229
|
|
230
|
+
function createReactQueryKeys({
|
231
|
+
context,
|
232
|
+
queryKeysName,
|
233
|
+
camelContractName,
|
234
|
+
underscoreNames
|
235
|
+
}) {
|
236
|
+
const options = context.options.reactQuery;
|
237
|
+
const contractAddressTypeAnnotation = t.tsTypeAnnotation(options.optionalClient ? t.tsUnionType([t.tsStringKeyword(), t.tsUndefinedKeyword()]) : t.tSStringKeyword());
|
238
|
+
return t.exportNamedDeclaration(t.variableDeclaration('const', [t.variableDeclarator(t.identifier(queryKeysName), t.objectExpression([// 1: contract
|
239
|
+
t.objectProperty(t.identifier('contract'), t.tSAsExpression(t.arrayExpression([t.objectExpression([t.objectProperty(t.identifier('contract'), t.stringLiteral(camelContractName))])]), t.tSTypeReference(t.identifier('const')))), // 2: address
|
240
|
+
t.objectProperty(t.identifier('address'), t.arrowFunctionExpression([identifier('contractAddress', contractAddressTypeAnnotation)], t.tSAsExpression(t.arrayExpression([t.objectExpression([// 1
|
241
|
+
t.spreadElement(t.memberExpression(t.memberExpression(t.identifier(queryKeysName), t.identifier('contract')), t.numericLiteral(0), true // computed
|
242
|
+
)), t.objectProperty(t.identifier('address'), t.identifier('contractAddress'))])]), t.tSTypeReference(t.identifier('const'))))), // 3: methods
|
243
|
+
...underscoreNames.map(underscoreMethodName => t.objectProperty( // key id is the camel method name
|
244
|
+
t.identifier(camel(underscoreMethodName)), t.arrowFunctionExpression([identifier('contractAddress', contractAddressTypeAnnotation), identifier('args', // Record<string, unknown>
|
245
|
+
t.tSTypeAnnotation(t.tsTypeReference(t.identifier('Record'), t.tsTypeParameterInstantiation([t.tsStringKeyword(), t.tsUnknownKeyword()]))), true // optional
|
246
|
+
)], t.tSAsExpression(t.arrayExpression([t.objectExpression([//...cw3FlexMultisigQueryKeys.address(contractAddress)[0]
|
247
|
+
t.spreadElement(t.memberExpression(t.callExpression(t.memberExpression(t.identifier(queryKeysName), t.identifier('address')), [t.identifier('contractAddress')]), t.numericLiteral(0), true // computed
|
248
|
+
)), // method: list_voters
|
249
|
+
t.objectProperty(t.identifier('method'), t.stringLiteral(underscoreMethodName)), // args
|
250
|
+
shorthandProperty('args')])]), t.tSTypeReference(t.identifier('const'))))))]))]));
|
251
|
+
}
|
252
|
+
|
199
253
|
function createReactQueryHookGenericInterface({
|
200
254
|
context,
|
201
255
|
QueryClient,
|
202
256
|
genericQueryInterfaceName
|
203
257
|
}) {
|
204
258
|
const options = context.options.reactQuery;
|
205
|
-
const
|
206
|
-
|
207
|
-
|
259
|
+
const genericResponseTypeName = 'TResponse';
|
260
|
+
const genericSelectResponseTypeName = 'TData';
|
261
|
+
context.addUtil('UseQueryOptions'); // UseQueryOptions<TResponse, Error, TData>,
|
262
|
+
|
263
|
+
const typedUseQueryOptions = t.tsTypeReference(t.identifier('UseQueryOptions'), t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier(genericResponseTypeName)), t.tsTypeReference(t.identifier('Error')), t.tsTypeReference(t.identifier(genericSelectResponseTypeName))]));
|
208
264
|
const body = [tsPropertySignature(t.identifier('client'), t.tsTypeAnnotation(options.optionalClient ? t.tsUnionType([t.tsTypeReference(t.identifier(QueryClient)), t.tsUndefinedKeyword()]) : t.tsTypeReference(t.identifier(QueryClient))), false), tsPropertySignature(t.identifier('options'), t.tsTypeAnnotation(options.version === 'v4' ? t.tSIntersectionType([omitTypeReference(typedUseQueryOptions, "'queryKey' | 'queryFn' | 'initialData'"), t.tSTypeLiteral([t.tsPropertySignature(t.identifier('initialData?'), t.tsTypeAnnotation(t.tsUndefinedKeyword()))])]) : typedUseQueryOptions), true)];
|
209
|
-
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(genericQueryInterfaceName), t.tsTypeParameterDeclaration([
|
265
|
+
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(genericQueryInterfaceName), t.tsTypeParameterDeclaration([// 1: TResponse
|
266
|
+
t.tsTypeParameter(undefined, undefined, genericResponseTypeName), // 2: TData
|
267
|
+
t.tsTypeParameter(undefined, t.tSTypeReference(t.identifier(genericResponseTypeName)), genericSelectResponseTypeName)]), [], t.tSInterfaceBody(body)));
|
210
268
|
}
|
211
269
|
|
212
270
|
export const createReactQueryHookInterface = ({
|
@@ -227,7 +285,9 @@ export const createReactQueryHookInterface = ({
|
|
227
285
|
t.tsTypeLiteral(props))));
|
228
286
|
}
|
229
287
|
|
230
|
-
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(hookParamsTypeName),
|
288
|
+
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(hookParamsTypeName), t.tsTypeParameterDeclaration([t.tSTypeParameter(undefined, undefined, 'TData')]), [t.tSExpressionWithTypeArguments(t.identifier(queryInterfaceName), t.tsTypeParameterInstantiation([// 1: response
|
289
|
+
t.tsTypeReference(t.identifier(responseType)), // 2: select generic
|
290
|
+
t.tSTypeReference(t.identifier('TData'))]))], t.tsInterfaceBody(body)));
|
231
291
|
};
|
232
292
|
|
233
293
|
const getProps = (context, jsonschema) => {
|
@@ -242,12 +302,31 @@ const getProps = (context, jsonschema) => {
|
|
242
302
|
});
|
243
303
|
};
|
244
304
|
|
245
|
-
const generateUseQueryQueryKey = (
|
246
|
-
|
305
|
+
const generateUseQueryQueryKey = ({
|
306
|
+
hookKeyName,
|
307
|
+
queryKeysName,
|
308
|
+
methodName,
|
309
|
+
props,
|
310
|
+
options
|
311
|
+
}) => {
|
312
|
+
const {
|
313
|
+
optionalClient,
|
314
|
+
queryKeys
|
315
|
+
} = options;
|
316
|
+
const hasArgs = props.includes('args');
|
317
|
+
const contractAddressExpression = t.optionalMemberExpression(t.identifier('client'), t.identifier('contractAddress'), false, optionalClient);
|
318
|
+
|
319
|
+
if (queryKeys) {
|
320
|
+
const callArgs = [contractAddressExpression];
|
321
|
+
if (hasArgs) callArgs.push(t.identifier('args'));
|
322
|
+
return t.callExpression(t.memberExpression(t.identifier(queryKeysName), t.identifier(camel(methodName))), callArgs);
|
323
|
+
}
|
324
|
+
|
325
|
+
const queryKey = [t.stringLiteral(hookKeyName), contractAddressExpression];
|
247
326
|
|
248
|
-
if (
|
327
|
+
if (hasArgs) {
|
249
328
|
queryKey.push(t.callExpression(t.memberExpression(t.identifier('JSON'), t.identifier('stringify')), [t.identifier('args')]));
|
250
329
|
}
|
251
330
|
|
252
|
-
return queryKey;
|
331
|
+
return t.arrayExpression(queryKey);
|
253
332
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "wasm-ast-types",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.9.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",
|
@@ -86,5 +86,5 @@
|
|
86
86
|
"case": "1.6.3",
|
87
87
|
"deepmerge": "4.2.2"
|
88
88
|
},
|
89
|
-
"gitHead": "
|
89
|
+
"gitHead": "3b7ca02c9283c346a365d8426d3034af355afcac"
|
90
90
|
}
|