wasm-ast-types 0.26.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE-Apache +201 -0
- package/LICENSE-MIT +21 -0
- package/README.md +24 -1
- package/{types/client → client}/client.d.ts +2 -2
- package/client/client.js +275 -0
- package/client/index.js +17 -0
- package/{types/context → context}/context.d.ts +9 -22
- package/context/context.js +114 -0
- package/{types/context → context}/imports.d.ts +9 -8
- package/context/imports.js +166 -0
- package/context/index.js +18 -0
- package/esm/client/client.js +238 -0
- package/esm/client/index.js +1 -0
- package/esm/context/context.js +104 -0
- package/esm/context/imports.js +136 -0
- package/{module → esm}/context/index.js +1 -1
- package/{src/index.ts → esm/index.js} +0 -1
- package/esm/message-builder/message-builder.js +64 -0
- package/esm/message-composer/message-composer.js +105 -0
- package/esm/provider/provider.js +97 -0
- package/esm/react-query/react-query.js +458 -0
- package/esm/recoil/recoil.js +110 -0
- package/esm/utils/babel.js +231 -0
- package/esm/utils/constants.js +20 -0
- package/esm/utils/ref.js +4 -0
- package/esm/utils/types.js +343 -0
- package/{types/index.d.ts → index.d.ts} +0 -1
- package/index.js +24 -0
- package/message-builder/index.js +17 -0
- package/{types/message-builder → message-builder}/message-builder.d.ts +1 -1
- package/message-builder/message-builder.js +91 -0
- package/message-composer/index.d.ts +1 -0
- package/message-composer/index.js +17 -0
- package/{types/message-composer → message-composer}/message-composer.d.ts +1 -1
- package/message-composer/message-composer.js +133 -0
- package/package.json +19 -68
- package/provider/index.d.ts +1 -0
- package/provider/index.js +17 -0
- package/provider/provider.js +127 -0
- package/react-query/index.d.ts +1 -0
- package/react-query/index.js +17 -0
- package/{types/react-query → react-query}/react-query.d.ts +2 -3
- package/react-query/react-query.js +490 -0
- package/recoil/index.d.ts +1 -0
- package/recoil/index.js +17 -0
- package/{types/recoil → recoil}/recoil.d.ts +1 -1
- package/recoil/recoil.js +140 -0
- package/{types/utils → utils}/babel.d.ts +9 -8
- package/utils/babel.js +285 -0
- package/utils/constants.js +46 -0
- package/utils/index.js +26 -0
- package/{types/utils → utils}/ref.d.ts +1 -1
- package/utils/ref.js +8 -0
- package/{types/utils → utils}/types.d.ts +8 -8
- package/utils/types.js +379 -0
- package/main/client/client.js +0 -196
- package/main/client/index.js +0 -16
- package/main/client/test/ts-client.account-nfts.spec.js +0 -28
- package/main/client/test/ts-client.arrays-ref.spec.js +0 -19
- package/main/client/test/ts-client.arrays.spec.js +0 -26
- package/main/client/test/ts-client.cw-named-groups.test.js +0 -19
- package/main/client/test/ts-client.cw-proposal-single.test.js +0 -23
- package/main/client/test/ts-client.empty-enums.spec.js +0 -13
- package/main/client/test/ts-client.issue-101.spec.js +0 -23
- package/main/client/test/ts-client.issue-103.test.js +0 -44
- package/main/client/test/ts-client.issue-71.test.js +0 -81
- package/main/client/test/ts-client.issue-98.test.js +0 -28
- package/main/client/test/ts-client.issues.test.js +0 -81
- package/main/client/test/ts-client.overrides.spec.js +0 -33
- package/main/client/test/ts-client.sg721.spec.js +0 -19
- package/main/client/test/ts-client.spec.js +0 -87
- package/main/client/test/ts-client.vectis.spec.js +0 -46
- package/main/client/test/ts-client.wager.spec.js +0 -39
- package/main/context/context.js +0 -162
- package/main/context/imports.js +0 -159
- package/main/context/index.js +0 -27
- package/main/index.js +0 -104
- package/main/message-builder/index.js +0 -16
- package/main/message-builder/message-builder.js +0 -62
- package/main/message-builder/message-builder.spec.js +0 -20
- package/main/message-composer/index.js +0 -16
- package/main/message-composer/message-composer.js +0 -86
- package/main/message-composer/message-composer.spec.js +0 -23
- package/main/provider/index.js +0 -16
- package/main/provider/provider.js +0 -71
- package/main/provider/provider.spec.js +0 -60
- package/main/react-query/index.js +0 -16
- package/main/react-query/react-query.js +0 -413
- package/main/react-query/react-query.spec.js +0 -91
- package/main/recoil/index.js +0 -16
- package/main/recoil/recoil.js +0 -61
- package/main/recoil/recoil.spec.js +0 -20
- package/main/types.js +0 -4
- package/main/utils/babel.js +0 -282
- package/main/utils/babel.spec.js +0 -109
- package/main/utils/constants.js +0 -26
- package/main/utils/index.js +0 -65
- package/main/utils/ref.js +0 -12
- package/main/utils/types.js +0 -343
- package/module/client/client.js +0 -166
- package/module/client/index.js +0 -1
- package/module/client/test/ts-client.account-nfts.spec.js +0 -25
- package/module/client/test/ts-client.arrays-ref.spec.js +0 -16
- package/module/client/test/ts-client.arrays.spec.js +0 -23
- package/module/client/test/ts-client.cw-named-groups.test.js +0 -16
- package/module/client/test/ts-client.cw-proposal-single.test.js +0 -20
- package/module/client/test/ts-client.empty-enums.spec.js +0 -10
- package/module/client/test/ts-client.issue-101.spec.js +0 -22
- package/module/client/test/ts-client.issue-103.test.js +0 -41
- package/module/client/test/ts-client.issue-71.test.js +0 -21
- package/module/client/test/ts-client.issue-98.test.js +0 -25
- package/module/client/test/ts-client.issues.test.js +0 -21
- package/module/client/test/ts-client.overrides.spec.js +0 -30
- package/module/client/test/ts-client.sg721.spec.js +0 -16
- package/module/client/test/ts-client.spec.js +0 -84
- package/module/client/test/ts-client.vectis.spec.js +0 -43
- package/module/client/test/ts-client.wager.spec.js +0 -36
- package/module/context/context.js +0 -116
- package/module/context/imports.js +0 -127
- package/module/index.js +0 -9
- package/module/message-builder/index.js +0 -1
- package/module/message-builder/message-builder.js +0 -52
- package/module/message-builder/message-builder.spec.js +0 -17
- package/module/message-composer/index.js +0 -1
- package/module/message-composer/message-composer.js +0 -70
- package/module/message-composer/message-composer.spec.js +0 -20
- package/module/provider/index.js +0 -1
- package/module/provider/provider.js +0 -45
- package/module/provider/provider.spec.js +0 -58
- package/module/react-query/index.js +0 -1
- package/module/react-query/react-query.js +0 -403
- package/module/react-query/react-query.spec.js +0 -85
- package/module/recoil/index.js +0 -1
- package/module/recoil/recoil.js +0 -46
- package/module/recoil/recoil.spec.js +0 -14
- package/module/types.js +0 -3
- package/module/utils/babel.js +0 -203
- package/module/utils/babel.spec.js +0 -70
- package/module/utils/constants.js +0 -12
- package/module/utils/index.js +0 -6
- package/module/utils/ref.js +0 -4
- package/module/utils/types.js +0 -301
- package/src/client/client.ts +0 -584
- package/src/client/index.ts +0 -1
- package/src/client/test/__snapshots__/ts-client.account-nfts.spec.ts.snap +0 -497
- package/src/client/test/__snapshots__/ts-client.arrays-ref.spec.ts.snap +0 -452
- package/src/client/test/__snapshots__/ts-client.arrays.spec.ts.snap +0 -101
- package/src/client/test/__snapshots__/ts-client.cw-named-groups.test.ts.snap +0 -141
- package/src/client/test/__snapshots__/ts-client.cw-proposal-single.test.ts.snap +0 -341
- package/src/client/test/__snapshots__/ts-client.empty-enums.spec.ts.snap +0 -20
- package/src/client/test/__snapshots__/ts-client.issue-101.spec.ts.snap +0 -47
- package/src/client/test/__snapshots__/ts-client.issue-103.test.ts.snap +0 -79
- package/src/client/test/__snapshots__/ts-client.issue-71.test.ts.snap +0 -432
- package/src/client/test/__snapshots__/ts-client.issue-98.test.ts.snap +0 -117
- package/src/client/test/__snapshots__/ts-client.issues.test.ts.snap +0 -984
- package/src/client/test/__snapshots__/ts-client.overrides.spec.ts.snap +0 -709
- package/src/client/test/__snapshots__/ts-client.sg721.spec.ts.snap +0 -350
- package/src/client/test/__snapshots__/ts-client.spec.ts.snap +0 -723
- package/src/client/test/__snapshots__/ts-client.vectis.spec.ts.snap +0 -337
- package/src/client/test/__snapshots__/ts-client.wager.spec.ts.snap +0 -132
- package/src/client/test/ts-client.account-nfts.spec.ts +0 -55
- package/src/client/test/ts-client.arrays-ref.spec.ts +0 -48
- package/src/client/test/ts-client.arrays.spec.ts +0 -58
- package/src/client/test/ts-client.cw-named-groups.test.ts +0 -48
- package/src/client/test/ts-client.cw-proposal-single.test.ts +0 -50
- package/src/client/test/ts-client.empty-enums.spec.ts +0 -28
- package/src/client/test/ts-client.issue-101.spec.ts +0 -37
- package/src/client/test/ts-client.issue-103.test.ts +0 -106
- package/src/client/test/ts-client.issue-71.test.ts +0 -51
- package/src/client/test/ts-client.issue-98.test.ts +0 -55
- package/src/client/test/ts-client.issues.test.ts +0 -52
- package/src/client/test/ts-client.overrides.spec.ts +0 -74
- package/src/client/test/ts-client.sg721.spec.ts +0 -46
- package/src/client/test/ts-client.spec.ts +0 -166
- package/src/client/test/ts-client.vectis.spec.ts +0 -97
- package/src/client/test/ts-client.wager.spec.ts +0 -63
- package/src/context/context.ts +0 -229
- package/src/context/imports.ts +0 -195
- package/src/context/index.ts +0 -2
- package/src/message-builder/__snapshots__/message-builder.spec.ts.snap +0 -270
- package/src/message-builder/message-builder.spec.ts +0 -24
- package/src/message-builder/message-builder.ts +0 -119
- package/src/message-composer/__snapshots__/message-composer.spec.ts.snap +0 -331
- package/src/message-composer/index.ts +0 -1
- package/src/message-composer/message-composer.spec.ts +0 -46
- package/src/message-composer/message-composer.ts +0 -262
- package/src/provider/__snapshots__/provider.spec.ts.snap +0 -49
- package/src/provider/index.ts +0 -1
- package/src/provider/provider.spec.ts +0 -81
- package/src/provider/provider.ts +0 -237
- package/src/react-query/__snapshots__/react-query.spec.ts.snap +0 -1359
- package/src/react-query/index.ts +0 -1
- package/src/react-query/react-query.spec.ts +0 -116
- package/src/react-query/react-query.ts +0 -1072
- package/src/recoil/__snapshots__/recoil.spec.ts.snap +0 -203
- package/src/recoil/index.ts +0 -1
- package/src/recoil/recoil.spec.ts +0 -38
- package/src/recoil/recoil.ts +0 -307
- package/src/types.ts +0 -44
- package/src/utils/__snapshots__/babel.spec.ts.snap +0 -75
- package/src/utils/babel.spec.ts +0 -511
- package/src/utils/babel.ts +0 -352
- package/src/utils/constants.ts +0 -37
- package/src/utils/ref.ts +0 -6
- package/src/utils/types.ts +0 -478
- package/types/types.d.ts +0 -41
- /package/{types/client → client}/index.d.ts +0 -0
- /package/{types/context → context}/index.d.ts +0 -0
- /package/{src/message-builder/index.ts → esm/message-builder/index.js} +0 -0
- /package/{types/message-composer/index.d.ts → esm/message-composer/index.js} +0 -0
- /package/{types/provider/index.d.ts → esm/provider/index.js} +0 -0
- /package/{types/react-query/index.d.ts → esm/react-query/index.js} +0 -0
- /package/{types/recoil/index.d.ts → esm/recoil/index.js} +0 -0
- /package/{src/utils/index.ts → esm/utils/index.js} +0 -0
- /package/{types/message-builder → message-builder}/index.d.ts +0 -0
- /package/{types/provider → provider}/provider.d.ts +0 -0
- /package/{types/utils → utils}/constants.d.ts +0 -0
- /package/{types/utils → utils}/index.d.ts +0 -0
@@ -0,0 +1,490 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
+
exports.createReactQueryHookInterface = exports.createReactQueryMutationHook = exports.createReactQueryMutationHooks = exports.createReactQueryMutationArgsInterface = exports.createReactQueryHook = exports.createReactQueryHooks = void 0;
|
27
|
+
const t = __importStar(require("@babel/types"));
|
28
|
+
const case_1 = require("case");
|
29
|
+
const utils_1 = require("../utils");
|
30
|
+
const babel_1 = require("../utils/babel");
|
31
|
+
const types_1 = require("../utils/types");
|
32
|
+
const constants_1 = require("../utils/constants");
|
33
|
+
const createReactQueryHooks = ({ context, queryMsg, contractName, QueryClient }) => {
|
34
|
+
const options = context.options.reactQuery;
|
35
|
+
const genericQueryInterfaceName = `${(0, case_1.pascal)(contractName)}ReactQuery`;
|
36
|
+
const underscoreNames = (0, utils_1.getMessageProperties)(queryMsg).map((schema) => Object.keys(schema.properties)[0]);
|
37
|
+
const body = [];
|
38
|
+
const queryKeysName = `${(0, case_1.camel)(contractName)}QueryKeys`;
|
39
|
+
if (options.queryKeys) {
|
40
|
+
body.push(createReactQueryKeys({
|
41
|
+
context,
|
42
|
+
queryKeysName,
|
43
|
+
camelContractName: (0, case_1.camel)(contractName),
|
44
|
+
underscoreNames
|
45
|
+
}));
|
46
|
+
}
|
47
|
+
const queryMsgs = (0, utils_1.getMessageProperties)(queryMsg).map((schema) => {
|
48
|
+
// list_voters
|
49
|
+
const underscoreName = Object.keys(schema.properties)[0];
|
50
|
+
// listVoters
|
51
|
+
const methodName = (0, case_1.camel)(underscoreName);
|
52
|
+
// Cw3FlexMultisigListVotersQuery
|
53
|
+
const hookParamsTypeName = `${(0, case_1.pascal)(contractName)}${(0, case_1.pascal)(methodName)}Query`;
|
54
|
+
// useCw3FlexMultisigListVotersQuery
|
55
|
+
const hookName = `use${hookParamsTypeName}`;
|
56
|
+
// listVotersResponse
|
57
|
+
const responseType = (0, types_1.getResponseType)(context, underscoreName);
|
58
|
+
// cw3FlexMultisigListVoters
|
59
|
+
const getterKey = (0, case_1.camel)(`${contractName}${(0, case_1.pascal)(methodName)}`);
|
60
|
+
const jsonschema = schema.properties[underscoreName];
|
61
|
+
return {
|
62
|
+
underscoreName,
|
63
|
+
methodName,
|
64
|
+
hookParamsTypeName,
|
65
|
+
hookName,
|
66
|
+
responseType,
|
67
|
+
getterKey,
|
68
|
+
jsonschema
|
69
|
+
};
|
70
|
+
});
|
71
|
+
const queryFactoryName = `${(0, case_1.camel)(contractName)}Queries`;
|
72
|
+
if (options.queryFactory) {
|
73
|
+
body.push(createReactQueryFactory({
|
74
|
+
context,
|
75
|
+
queryFactoryName,
|
76
|
+
queryKeysName,
|
77
|
+
queryMsgs
|
78
|
+
}));
|
79
|
+
}
|
80
|
+
body.push(createReactQueryHookGenericInterface({
|
81
|
+
context,
|
82
|
+
QueryClient,
|
83
|
+
genericQueryInterfaceName
|
84
|
+
}));
|
85
|
+
body.push(...queryMsgs.reduce((m, { methodName, hookParamsTypeName, hookName, responseType, getterKey, jsonschema }) => {
|
86
|
+
return [
|
87
|
+
(0, exports.createReactQueryHookInterface)({
|
88
|
+
context,
|
89
|
+
hookParamsTypeName,
|
90
|
+
responseType,
|
91
|
+
queryInterfaceName: genericQueryInterfaceName,
|
92
|
+
QueryClient,
|
93
|
+
jsonschema
|
94
|
+
}),
|
95
|
+
(0, exports.createReactQueryHook)({
|
96
|
+
context,
|
97
|
+
methodName,
|
98
|
+
hookName,
|
99
|
+
hookParamsTypeName,
|
100
|
+
queryKeysName,
|
101
|
+
responseType,
|
102
|
+
hookKeyName: getterKey,
|
103
|
+
jsonschema
|
104
|
+
}),
|
105
|
+
...m
|
106
|
+
];
|
107
|
+
}, []));
|
108
|
+
return body;
|
109
|
+
};
|
110
|
+
exports.createReactQueryHooks = createReactQueryHooks;
|
111
|
+
function buildQueryFn(methodName, jsonschema, options) {
|
112
|
+
const keys = Object.keys(jsonschema.properties ?? {});
|
113
|
+
let args = [];
|
114
|
+
if (keys.length) {
|
115
|
+
args = [
|
116
|
+
t.objectExpression([
|
117
|
+
...keys.map((prop) => {
|
118
|
+
return t.objectProperty(t.identifier((0, case_1.camel)(prop)), t.memberExpression(t.identifier('args'), t.identifier((0, case_1.camel)(prop))));
|
119
|
+
})
|
120
|
+
])
|
121
|
+
];
|
122
|
+
}
|
123
|
+
const rejectInvalidClient = t.callExpression(t.memberExpression(t.identifier('Promise'), t.identifier('reject')), [
|
124
|
+
t.newExpression(t.identifier('Error'), [
|
125
|
+
t.stringLiteral('Invalid client')
|
126
|
+
])
|
127
|
+
]);
|
128
|
+
return t.arrowFunctionExpression([], (0, babel_1.optionalConditionalExpression)(t.identifier('client'), t.callExpression(t.memberExpression(t.identifier('client'), t.identifier(methodName)), args), rejectInvalidClient, options.optionalClient), false);
|
129
|
+
}
|
130
|
+
const ENABLED_QUERY_OPTION = t.objectProperty(t.identifier('enabled'), t.logicalExpression('&&', t.unaryExpression('!', t.unaryExpression('!', t.identifier('client'))), t.conditionalExpression(
|
131
|
+
// explicitly check for undefined
|
132
|
+
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))));
|
133
|
+
function buildQueryOptions(options) {
|
134
|
+
return options.optionalClient
|
135
|
+
? t.objectExpression([
|
136
|
+
t.spreadElement(t.identifier('options')),
|
137
|
+
t.objectProperty(t.identifier('enabled'), t.logicalExpression('&&', t.unaryExpression('!', t.unaryExpression('!', t.identifier('client'))), t.conditionalExpression(
|
138
|
+
// explicitly check for undefined
|
139
|
+
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))))
|
140
|
+
])
|
141
|
+
: t.identifier('options');
|
142
|
+
}
|
143
|
+
const createReactQueryHook = ({ context, hookName, hookParamsTypeName, responseType, hookKeyName, queryKeysName, methodName, jsonschema }) => {
|
144
|
+
context.addUtil('useQuery');
|
145
|
+
context.addUtil('UseQueryOptions');
|
146
|
+
const options = context.options.reactQuery;
|
147
|
+
const keys = Object.keys(jsonschema.properties ?? {});
|
148
|
+
let props = ['client', 'options'];
|
149
|
+
if (keys.length) {
|
150
|
+
props = ['client', 'args', 'options'];
|
151
|
+
}
|
152
|
+
const selectResponseGenericTypeName = GENERIC_SELECT_RESPONSE_NAME;
|
153
|
+
const queryFunctionDeclaration = t.functionDeclaration(t.identifier(hookName), [
|
154
|
+
(0, utils_1.tsObjectPattern)([
|
155
|
+
...props.map((prop) => {
|
156
|
+
return t.objectProperty(t.identifier(prop), t.identifier(prop), false, true);
|
157
|
+
})
|
158
|
+
], t.tsTypeAnnotation(t.tsTypeReference(t.identifier(hookParamsTypeName), t.tsTypeParameterInstantiation([
|
159
|
+
t.tsTypeReference(t.identifier(selectResponseGenericTypeName))
|
160
|
+
]))))
|
161
|
+
], t.blockStatement([
|
162
|
+
t.returnStatement((0, utils_1.callExpression)(t.identifier('useQuery'), [
|
163
|
+
generateUseQueryQueryKey({
|
164
|
+
hookKeyName,
|
165
|
+
queryKeysName,
|
166
|
+
methodName,
|
167
|
+
props,
|
168
|
+
options
|
169
|
+
}),
|
170
|
+
buildQueryFn(methodName, jsonschema, options),
|
171
|
+
buildQueryOptions(options)
|
172
|
+
], t.tsTypeParameterInstantiation([
|
173
|
+
t.tsTypeReference(t.identifier(responseType)),
|
174
|
+
t.tsTypeReference(t.identifier('Error')),
|
175
|
+
t.tsTypeReference(t.identifier(selectResponseGenericTypeName))
|
176
|
+
])))
|
177
|
+
]));
|
178
|
+
// Add the TData type parameters
|
179
|
+
queryFunctionDeclaration.typeParameters = t.tsTypeParameterDeclaration([
|
180
|
+
t.tsTypeParameter(undefined, t.tSTypeReference(t.identifier(responseType)), selectResponseGenericTypeName)
|
181
|
+
]);
|
182
|
+
return t.exportNamedDeclaration(queryFunctionDeclaration);
|
183
|
+
};
|
184
|
+
exports.createReactQueryHook = createReactQueryHook;
|
185
|
+
/**
|
186
|
+
* Example:
|
187
|
+
```
|
188
|
+
export interface Cw721RevokeMutation {
|
189
|
+
client: Cw721Client;
|
190
|
+
msg: {
|
191
|
+
spender: string;
|
192
|
+
tokenId: string;
|
193
|
+
};
|
194
|
+
args?: {
|
195
|
+
fee?: number | StdFee | "auto";
|
196
|
+
memo?: string;
|
197
|
+
funds?: Coin[];
|
198
|
+
};
|
199
|
+
}
|
200
|
+
```
|
201
|
+
*/
|
202
|
+
const createReactQueryMutationArgsInterface = ({ context, ExecuteClient, mutationHookParamsTypeName, useMutationTypeParameter, jsonschema }) => {
|
203
|
+
const typedUseMutationOptions = t.tsTypeReference(t.identifier('UseMutationOptions'), useMutationTypeParameter);
|
204
|
+
const body = [
|
205
|
+
(0, utils_1.tsPropertySignature)(t.identifier('client'), t.tsTypeAnnotation(t.tsTypeReference(t.identifier(ExecuteClient))), false)
|
206
|
+
];
|
207
|
+
const msgType = (0, utils_1.createTypedObjectParams)(context, jsonschema)?.typeAnnotation;
|
208
|
+
if (msgType) {
|
209
|
+
body.push(t.tsPropertySignature(t.identifier('msg'),
|
210
|
+
// @ts-ignore
|
211
|
+
msgType));
|
212
|
+
}
|
213
|
+
context.addUtil('StdFee');
|
214
|
+
context.addUtil('Coin');
|
215
|
+
const optionalArgs = t.tsPropertySignature(t.identifier('args'), t.tsTypeAnnotation(
|
216
|
+
// @ts-ignore:next-line
|
217
|
+
t.tsTypeLiteral([
|
218
|
+
(0, babel_1.propertySignature)('fee', constants_1.OPTIONAL_FEE_PARAM.typeAnnotation, true),
|
219
|
+
(0, babel_1.propertySignature)('memo', constants_1.OPTIONAL_MEMO_PARAM.typeAnnotation, true),
|
220
|
+
(0, babel_1.propertySignature)('funds', utils_1.OPTIONAL_FUNDS_PARAM.typeAnnotation, true)
|
221
|
+
])));
|
222
|
+
optionalArgs.optional = true;
|
223
|
+
body.push(optionalArgs);
|
224
|
+
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(mutationHookParamsTypeName), null, [], t.tsInterfaceBody(body)));
|
225
|
+
};
|
226
|
+
exports.createReactQueryMutationArgsInterface = createReactQueryMutationArgsInterface;
|
227
|
+
const createReactQueryMutationHooks = ({ context, execMsg, contractName, ExecuteClient }) => {
|
228
|
+
// merge the user options with the defaults
|
229
|
+
return (0, utils_1.getMessageProperties)(execMsg).reduce((m, schema) => {
|
230
|
+
// update_members
|
231
|
+
const execMethodUnderscoreName = Object.keys(schema.properties)[0];
|
232
|
+
// updateMembers
|
233
|
+
const execMethodName = (0, case_1.camel)(execMethodUnderscoreName);
|
234
|
+
// Cw20UpdateMembersMutation
|
235
|
+
const mutationHookParamsTypeName = `${(0, case_1.pascal)(contractName)}${(0, case_1.pascal)(execMethodName)}Mutation`;
|
236
|
+
// useCw20UpdateMembersMutation
|
237
|
+
const mutationHookName = `use${mutationHookParamsTypeName}`;
|
238
|
+
const jsonschema = schema.properties[execMethodUnderscoreName];
|
239
|
+
const properties = jsonschema.properties ?? {};
|
240
|
+
// TODO: there should be a better way to do this
|
241
|
+
const hasMsg = !!(Object.keys(properties)?.length || jsonschema?.$ref);
|
242
|
+
// <ExecuteResult, Error, Cw4UpdateMembersMutation>
|
243
|
+
const useMutationTypeParameter = generateMutationTypeParameter(context, mutationHookParamsTypeName);
|
244
|
+
return [
|
245
|
+
(0, exports.createReactQueryMutationArgsInterface)({
|
246
|
+
context,
|
247
|
+
mutationHookParamsTypeName,
|
248
|
+
ExecuteClient,
|
249
|
+
jsonschema,
|
250
|
+
useMutationTypeParameter
|
251
|
+
}),
|
252
|
+
(0, exports.createReactQueryMutationHook)({
|
253
|
+
context,
|
254
|
+
execMethodName,
|
255
|
+
mutationHookName,
|
256
|
+
mutationHookParamsTypeName,
|
257
|
+
hasMsg,
|
258
|
+
useMutationTypeParameter
|
259
|
+
}),
|
260
|
+
...m
|
261
|
+
];
|
262
|
+
}, []);
|
263
|
+
};
|
264
|
+
exports.createReactQueryMutationHooks = createReactQueryMutationHooks;
|
265
|
+
/**
|
266
|
+
* Generates the mutation type parameter. If args exist, we use a pick. If not, we just return the params type.
|
267
|
+
*/
|
268
|
+
const generateMutationTypeParameter = (context, mutationHookParamsTypeName) => {
|
269
|
+
context.addUtil('ExecuteResult');
|
270
|
+
return t.tsTypeParameterInstantiation([
|
271
|
+
// Data
|
272
|
+
t.tSTypeReference(t.identifier('ExecuteResult')),
|
273
|
+
// Error
|
274
|
+
t.tsTypeReference(t.identifier('Error')),
|
275
|
+
// Variables
|
276
|
+
t.tsTypeReference(t.identifier(mutationHookParamsTypeName))
|
277
|
+
]);
|
278
|
+
};
|
279
|
+
/**
|
280
|
+
*
|
281
|
+
* Example:
|
282
|
+
```
|
283
|
+
export const useCw4UpdateMembersMutation = ({ client, options }: Omit<Cw4UpdateMembersMutation, 'args'>) =>
|
284
|
+
useMutation<ExecuteResult, Error, Pick<Cw4UpdateMembersMutation, 'args'>>(
|
285
|
+
({ args }) => client.updateMembers(args),
|
286
|
+
options
|
287
|
+
)
|
288
|
+
```
|
289
|
+
*/
|
290
|
+
const createReactQueryMutationHook = ({ context, mutationHookName, mutationHookParamsTypeName, execMethodName, useMutationTypeParameter, hasMsg }) => {
|
291
|
+
context.addUtil('useMutation');
|
292
|
+
context.addUtil('UseMutationOptions');
|
293
|
+
const useMutationFunctionArgs = [(0, babel_1.shorthandProperty)('client')];
|
294
|
+
if (hasMsg)
|
295
|
+
useMutationFunctionArgs.push((0, babel_1.shorthandProperty)('msg'));
|
296
|
+
useMutationFunctionArgs.push(t.objectProperty(t.identifier('args'), t.assignmentPattern(t.objectPattern([
|
297
|
+
(0, babel_1.shorthandProperty)('fee'),
|
298
|
+
(0, babel_1.shorthandProperty)('memo'),
|
299
|
+
(0, babel_1.shorthandProperty)('funds')
|
300
|
+
]), t.objectExpression([]))));
|
301
|
+
return t.exportNamedDeclaration(t.functionDeclaration(t.identifier(mutationHookName), [
|
302
|
+
(0, utils_1.identifier)('options', t.tsTypeAnnotation((0, babel_1.omitTypeReference)(t.tsTypeReference(t.identifier('UseMutationOptions'), useMutationTypeParameter), 'mutationFn')), true)
|
303
|
+
], t.blockStatement([
|
304
|
+
t.returnStatement((0, utils_1.callExpression)(t.identifier('useMutation'), [
|
305
|
+
t.arrowFunctionExpression([t.objectPattern(useMutationFunctionArgs)], t.callExpression(t.memberExpression(t.identifier('client'), t.identifier(execMethodName)), (hasMsg ? [t.identifier('msg')] : []).concat([
|
306
|
+
t.identifier('fee'),
|
307
|
+
t.identifier('memo'),
|
308
|
+
t.identifier('funds')
|
309
|
+
])), false // not async
|
310
|
+
),
|
311
|
+
t.identifier('options')
|
312
|
+
], useMutationTypeParameter))
|
313
|
+
])));
|
314
|
+
};
|
315
|
+
exports.createReactQueryMutationHook = createReactQueryMutationHook;
|
316
|
+
function createReactQueryKeys({ context, queryKeysName, camelContractName, underscoreNames }) {
|
317
|
+
const options = context.options.reactQuery;
|
318
|
+
const contractAddressTypeAnnotation = t.tsTypeAnnotation(options.optionalClient
|
319
|
+
? t.tsUnionType([t.tsStringKeyword(), t.tsUndefinedKeyword()])
|
320
|
+
: t.tSStringKeyword());
|
321
|
+
return t.exportNamedDeclaration(t.variableDeclaration('const', [
|
322
|
+
t.variableDeclarator(t.identifier(queryKeysName), t.objectExpression([
|
323
|
+
// 1: contract
|
324
|
+
t.objectProperty(t.identifier('contract'), t.tSAsExpression(t.arrayExpression([
|
325
|
+
t.objectExpression([
|
326
|
+
t.objectProperty(t.identifier('contract'), t.stringLiteral(camelContractName))
|
327
|
+
])
|
328
|
+
]), t.tSTypeReference(t.identifier('const')))),
|
329
|
+
// 2: address
|
330
|
+
t.objectProperty(t.identifier('address'), t.arrowFunctionExpression([(0, utils_1.identifier)('contractAddress', contractAddressTypeAnnotation)], t.tSAsExpression(t.arrayExpression([
|
331
|
+
t.objectExpression([
|
332
|
+
// 1
|
333
|
+
t.spreadElement(t.memberExpression(t.memberExpression(t.identifier(queryKeysName), t.identifier('contract')), t.numericLiteral(0), true // computed
|
334
|
+
)),
|
335
|
+
t.objectProperty(t.identifier('address'), t.identifier('contractAddress'))
|
336
|
+
])
|
337
|
+
]), t.tSTypeReference(t.identifier('const'))))),
|
338
|
+
// 3: methods
|
339
|
+
...underscoreNames.map((underscoreMethodName) => t.objectProperty(
|
340
|
+
// key id is the camel method name
|
341
|
+
t.identifier((0, case_1.camel)(underscoreMethodName)), t.arrowFunctionExpression([
|
342
|
+
(0, utils_1.identifier)('contractAddress', contractAddressTypeAnnotation),
|
343
|
+
(0, utils_1.identifier)('args',
|
344
|
+
// Record<string, unknown>
|
345
|
+
t.tSTypeAnnotation(t.tsTypeReference(t.identifier('Record'), t.tsTypeParameterInstantiation([
|
346
|
+
t.tsStringKeyword(),
|
347
|
+
t.tsUnknownKeyword()
|
348
|
+
]))), true // optional
|
349
|
+
)
|
350
|
+
], t.tSAsExpression(t.arrayExpression([
|
351
|
+
t.objectExpression([
|
352
|
+
//...cw3FlexMultisigQueryKeys.address(contractAddress)[0]
|
353
|
+
t.spreadElement(t.memberExpression(t.callExpression(t.memberExpression(t.identifier(queryKeysName), t.identifier('address')), [t.identifier('contractAddress')]), t.numericLiteral(0), true // computed
|
354
|
+
)),
|
355
|
+
// method: list_voters
|
356
|
+
t.objectProperty(t.identifier('method'), t.stringLiteral(underscoreMethodName)),
|
357
|
+
// args
|
358
|
+
(0, babel_1.shorthandProperty)('args')
|
359
|
+
])
|
360
|
+
]), t.tSTypeReference(t.identifier('const'))))))
|
361
|
+
]))
|
362
|
+
]));
|
363
|
+
}
|
364
|
+
function createReactQueryFactory({ context, queryFactoryName, queryKeysName, queryMsgs }) {
|
365
|
+
const options = context.options.reactQuery;
|
366
|
+
return t.exportNamedDeclaration(t.variableDeclaration('const', [
|
367
|
+
t.variableDeclarator(t.identifier(queryFactoryName), t.objectExpression([
|
368
|
+
...queryMsgs.map(({ methodName, hookParamsTypeName, responseType, jsonschema }) => {
|
369
|
+
const hasArgs = Object.keys(jsonschema.properties ?? {}).length > 0;
|
370
|
+
const methodQueryOptionsFn = t.arrowFunctionExpression([
|
371
|
+
(0, utils_1.tsObjectPattern)([
|
372
|
+
(0, babel_1.shorthandProperty)('client'),
|
373
|
+
...(hasArgs ? [(0, babel_1.shorthandProperty)('args')] : []),
|
374
|
+
(0, babel_1.shorthandProperty)('options')
|
375
|
+
], t.tsTypeAnnotation(t.tsTypeReference(t.identifier(hookParamsTypeName), t.tsTypeParameterInstantiation([
|
376
|
+
t.tsTypeReference(t.identifier(GENERIC_SELECT_RESPONSE_NAME))
|
377
|
+
]))))
|
378
|
+
], t.objectExpression([
|
379
|
+
// 1: queryKey
|
380
|
+
t.objectProperty(t.identifier('queryKey'), t.callExpression(t.memberExpression(t.identifier(queryKeysName), t.identifier(methodName)), [
|
381
|
+
t.optionalMemberExpression(t.identifier('client'), t.identifier('contractAddress'), false, true),
|
382
|
+
...(hasArgs ? [t.identifier('args')] : [])
|
383
|
+
])),
|
384
|
+
// 2: queryFn
|
385
|
+
t.objectProperty(t.identifier('queryFn'), buildQueryFn(methodName, jsonschema, options)),
|
386
|
+
// 3: spread options
|
387
|
+
t.spreadElement(t.identifier('options')),
|
388
|
+
// 4. enabled
|
389
|
+
ENABLED_QUERY_OPTION
|
390
|
+
]));
|
391
|
+
methodQueryOptionsFn.typeParameters =
|
392
|
+
t.tsTypeParameterDeclaration([
|
393
|
+
t.tsTypeParameter(undefined, t.tsTypeReference(t.identifier(responseType)), GENERIC_SELECT_RESPONSE_NAME)
|
394
|
+
]);
|
395
|
+
methodQueryOptionsFn.returnType = t.tsTypeAnnotation(t.tsTypeReference(t.identifier('UseQueryOptions'), t.tsTypeParameterInstantiation([
|
396
|
+
t.tsTypeReference(t.identifier(responseType)),
|
397
|
+
t.tsTypeReference(t.identifier('Error')),
|
398
|
+
t.tsTypeReference(t.identifier(GENERIC_SELECT_RESPONSE_NAME))
|
399
|
+
])));
|
400
|
+
return t.objectProperty(
|
401
|
+
// key id is the camel method name
|
402
|
+
t.identifier((0, case_1.camel)(methodName)), methodQueryOptionsFn);
|
403
|
+
})
|
404
|
+
]))
|
405
|
+
]));
|
406
|
+
}
|
407
|
+
const GENERIC_SELECT_RESPONSE_NAME = 'TData';
|
408
|
+
function createReactQueryHookGenericInterface({ context, QueryClient, genericQueryInterfaceName }) {
|
409
|
+
const options = context.options.reactQuery;
|
410
|
+
const genericResponseTypeName = 'TResponse';
|
411
|
+
context.addUtil('UseQueryOptions');
|
412
|
+
// UseQueryOptions<TResponse, Error, TData>,
|
413
|
+
const typedUseQueryOptions = t.tsTypeReference(t.identifier('UseQueryOptions'), t.tsTypeParameterInstantiation([
|
414
|
+
t.tsTypeReference(t.identifier(genericResponseTypeName)),
|
415
|
+
t.tsTypeReference(t.identifier('Error')),
|
416
|
+
t.tsTypeReference(t.identifier(GENERIC_SELECT_RESPONSE_NAME))
|
417
|
+
]));
|
418
|
+
const body = [
|
419
|
+
(0, utils_1.tsPropertySignature)(t.identifier('client'), t.tsTypeAnnotation(options.optionalClient
|
420
|
+
? t.tsUnionType([
|
421
|
+
t.tsTypeReference(t.identifier(QueryClient)),
|
422
|
+
t.tsUndefinedKeyword()
|
423
|
+
])
|
424
|
+
: t.tsTypeReference(t.identifier(QueryClient))), false),
|
425
|
+
(0, utils_1.tsPropertySignature)(t.identifier('options'), t.tsTypeAnnotation(options.version === 'v4'
|
426
|
+
? t.tSIntersectionType([
|
427
|
+
(0, babel_1.omitTypeReference)(typedUseQueryOptions, "'queryKey' | 'queryFn' | 'initialData'"),
|
428
|
+
t.tSTypeLiteral([
|
429
|
+
t.tsPropertySignature(t.identifier('initialData?'), t.tsTypeAnnotation(t.tsUndefinedKeyword()))
|
430
|
+
])
|
431
|
+
])
|
432
|
+
: typedUseQueryOptions), true)
|
433
|
+
];
|
434
|
+
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(genericQueryInterfaceName), t.tsTypeParameterDeclaration([
|
435
|
+
// 1: TResponse
|
436
|
+
t.tsTypeParameter(undefined, undefined, genericResponseTypeName),
|
437
|
+
// 2: TData
|
438
|
+
t.tsTypeParameter(undefined, t.tSTypeReference(t.identifier(genericResponseTypeName)), GENERIC_SELECT_RESPONSE_NAME)
|
439
|
+
]), [], t.tSInterfaceBody(body)));
|
440
|
+
}
|
441
|
+
const createReactQueryHookInterface = ({ context, QueryClient, hookParamsTypeName, queryInterfaceName, responseType, jsonschema }) => {
|
442
|
+
// merge the user options with the defaults
|
443
|
+
const options = context.options.reactQuery;
|
444
|
+
const body = [];
|
445
|
+
const props = getProps(context, jsonschema);
|
446
|
+
if (props.length) {
|
447
|
+
body.push(t.tsPropertySignature(t.identifier('args'), t.tsTypeAnnotation(
|
448
|
+
// @ts-ignore:next-line
|
449
|
+
t.tsTypeLiteral(props))));
|
450
|
+
}
|
451
|
+
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(hookParamsTypeName), t.tsTypeParameterDeclaration([
|
452
|
+
t.tSTypeParameter(undefined, undefined, GENERIC_SELECT_RESPONSE_NAME)
|
453
|
+
]), [
|
454
|
+
t.tSExpressionWithTypeArguments(t.identifier(queryInterfaceName), t.tsTypeParameterInstantiation([
|
455
|
+
// 1: response
|
456
|
+
t.tsTypeReference(t.identifier(responseType)),
|
457
|
+
// 2: select generic
|
458
|
+
t.tSTypeReference(t.identifier(GENERIC_SELECT_RESPONSE_NAME))
|
459
|
+
]))
|
460
|
+
], t.tsInterfaceBody(body)));
|
461
|
+
};
|
462
|
+
exports.createReactQueryHookInterface = createReactQueryHookInterface;
|
463
|
+
const getProps = (context, jsonschema) => {
|
464
|
+
const keys = Object.keys(jsonschema.properties ?? {});
|
465
|
+
if (!keys.length)
|
466
|
+
return [];
|
467
|
+
return keys.map((prop) => {
|
468
|
+
const { type, optional } = (0, types_1.getPropertyType)(context, jsonschema, prop);
|
469
|
+
return (0, babel_1.propertySignature)(context.options.reactQuery.camelize ? (0, case_1.camel)(prop) : prop, t.tsTypeAnnotation(type), optional);
|
470
|
+
});
|
471
|
+
};
|
472
|
+
const generateUseQueryQueryKey = ({ hookKeyName, queryKeysName, methodName, props, options }) => {
|
473
|
+
const { optionalClient, queryKeys } = options;
|
474
|
+
const hasArgs = props.includes('args');
|
475
|
+
const contractAddressExpression = t.optionalMemberExpression(t.identifier('client'), t.identifier('contractAddress'), false, optionalClient);
|
476
|
+
if (queryKeys) {
|
477
|
+
const callArgs = [contractAddressExpression];
|
478
|
+
if (hasArgs)
|
479
|
+
callArgs.push(t.identifier('args'));
|
480
|
+
return t.callExpression(t.memberExpression(t.identifier(queryKeysName), t.identifier((0, case_1.camel)(methodName))), callArgs);
|
481
|
+
}
|
482
|
+
const queryKey = [
|
483
|
+
t.stringLiteral(hookKeyName),
|
484
|
+
contractAddressExpression
|
485
|
+
];
|
486
|
+
if (hasArgs) {
|
487
|
+
queryKey.push(t.callExpression(t.memberExpression(t.identifier('JSON'), t.identifier('stringify')), [t.identifier('args')]));
|
488
|
+
}
|
489
|
+
return t.arrayExpression(queryKey);
|
490
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './recoil';
|
package/recoil/index.js
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./recoil"), exports);
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import * as t from '@babel/types';
|
2
|
-
import { QueryMsg } from '
|
2
|
+
import { QueryMsg } from '@cosmology/ts-codegen-types';
|
3
3
|
import { RenderContext } from '../context';
|
4
4
|
export declare const createRecoilSelector: (context: RenderContext, keyPrefix: string, QueryClient: string, methodName: string, responseType: string) => t.ExportNamedDeclaration;
|
5
5
|
export declare const createRecoilSelectors: (context: RenderContext, keyPrefix: string, QueryClient: string, queryMsg: QueryMsg) => t.ExportNamedDeclaration[];
|
package/recoil/recoil.js
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
+
exports.createRecoilQueryClient = exports.createRecoilQueryClientType = exports.createRecoilSelectors = exports.createRecoilSelector = void 0;
|
27
|
+
const t = __importStar(require("@babel/types"));
|
28
|
+
const case_1 = require("case");
|
29
|
+
const utils_1 = require("../utils");
|
30
|
+
const createRecoilSelector = (context, keyPrefix, QueryClient, methodName, responseType) => {
|
31
|
+
context.addUtil('selectorFamily');
|
32
|
+
const selectorName = (0, case_1.camel)(`${methodName}Selector`);
|
33
|
+
const getterKey = (0, case_1.camel)(`${keyPrefix}${(0, case_1.pascal)(methodName)}`);
|
34
|
+
return t.exportNamedDeclaration(t.variableDeclaration('const', [t.variableDeclarator(t.identifier(selectorName), (0, utils_1.callExpression)(t.identifier('selectorFamily'), [
|
35
|
+
t.objectExpression([
|
36
|
+
t.objectProperty(t.identifier('key'), t.stringLiteral(getterKey)),
|
37
|
+
t.objectProperty(t.identifier('get'), t.arrowFunctionExpression([
|
38
|
+
t.objectPattern([
|
39
|
+
t.objectProperty(t.identifier('params'), t.identifier('params'), false, true),
|
40
|
+
t.restElement(t.identifier('queryClientParams'))
|
41
|
+
])
|
42
|
+
], t.arrowFunctionExpression([
|
43
|
+
t.objectPattern([
|
44
|
+
t.objectProperty(t.identifier('get'), t.identifier('get'), false, true)
|
45
|
+
])
|
46
|
+
], t.blockStatement([
|
47
|
+
t.variableDeclaration('const', [
|
48
|
+
t.variableDeclarator(t.identifier('client'), t.callExpression(t.identifier('get'), [
|
49
|
+
t.callExpression(t.identifier('queryClient'), [
|
50
|
+
t.identifier('queryClientParams')
|
51
|
+
])
|
52
|
+
]))
|
53
|
+
]),
|
54
|
+
t.returnStatement(t.awaitExpression(t.callExpression(t.memberExpression(t.identifier('client'), t.identifier(methodName)), [
|
55
|
+
t.spreadElement(t.identifier('params'))
|
56
|
+
])))
|
57
|
+
]), true)))
|
58
|
+
])
|
59
|
+
], t.tsTypeParameterInstantiation([
|
60
|
+
t.tsTypeReference(t.identifier(responseType)),
|
61
|
+
t.tsIntersectionType([
|
62
|
+
t.tsTypeReference(t.identifier('QueryClientParams')),
|
63
|
+
t.tsTypeLiteral([
|
64
|
+
t.tsPropertySignature(t.identifier('params'), t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Parameters'), t.tsTypeParameterInstantiation([
|
65
|
+
t.tsIndexedAccessType(t.tsTypeReference(t.identifier(QueryClient)), t.tsLiteralType(t.stringLiteral(methodName)))
|
66
|
+
]))))
|
67
|
+
])
|
68
|
+
])
|
69
|
+
])))]));
|
70
|
+
};
|
71
|
+
exports.createRecoilSelector = createRecoilSelector;
|
72
|
+
const createRecoilSelectors = (context, keyPrefix, QueryClient, queryMsg) => {
|
73
|
+
return (0, utils_1.getMessageProperties)(queryMsg)
|
74
|
+
.map((schema) => {
|
75
|
+
const underscoreName = Object.keys(schema.properties)[0];
|
76
|
+
const methodName = (0, case_1.camel)(underscoreName);
|
77
|
+
const responseType = (0, utils_1.getResponseType)(context, underscoreName);
|
78
|
+
return (0, exports.createRecoilSelector)(context, keyPrefix, QueryClient, methodName, responseType);
|
79
|
+
});
|
80
|
+
};
|
81
|
+
exports.createRecoilSelectors = createRecoilSelectors;
|
82
|
+
const createRecoilQueryClientType = () => ({
|
83
|
+
"type": "TSTypeAliasDeclaration",
|
84
|
+
"id": {
|
85
|
+
"type": "Identifier",
|
86
|
+
"name": "QueryClientParams"
|
87
|
+
},
|
88
|
+
"typeAnnotation": {
|
89
|
+
"type": "TSTypeLiteral",
|
90
|
+
"members": [
|
91
|
+
{
|
92
|
+
"type": "TSPropertySignature",
|
93
|
+
"key": {
|
94
|
+
"type": "Identifier",
|
95
|
+
"name": "contractAddress"
|
96
|
+
},
|
97
|
+
"computed": false,
|
98
|
+
"typeAnnotation": {
|
99
|
+
"type": "TSTypeAnnotation",
|
100
|
+
"typeAnnotation": {
|
101
|
+
"type": "TSStringKeyword"
|
102
|
+
}
|
103
|
+
}
|
104
|
+
}
|
105
|
+
]
|
106
|
+
}
|
107
|
+
});
|
108
|
+
exports.createRecoilQueryClientType = createRecoilQueryClientType;
|
109
|
+
const createRecoilQueryClient = (context, keyPrefix, QueryClient) => {
|
110
|
+
context.addUtil('selectorFamily');
|
111
|
+
const getterKey = (0, case_1.camel)(`${keyPrefix}${'QueryClient'}`);
|
112
|
+
return t.exportNamedDeclaration(t.variableDeclaration('const', [t.variableDeclarator(t.identifier('queryClient'), (0, utils_1.callExpression)(t.identifier('selectorFamily'), [
|
113
|
+
t.objectExpression([
|
114
|
+
t.objectProperty(t.identifier('key'), t.stringLiteral(getterKey)),
|
115
|
+
t.objectProperty(t.identifier('get'), t.arrowFunctionExpression([
|
116
|
+
t.objectPattern([
|
117
|
+
t.objectProperty(t.identifier('contractAddress'), t.identifier('contractAddress'), false, true)
|
118
|
+
])
|
119
|
+
], t.arrowFunctionExpression([
|
120
|
+
t.objectPattern([
|
121
|
+
t.objectProperty(t.identifier('get'), t.identifier('get'), false, true)
|
122
|
+
])
|
123
|
+
], t.blockStatement([
|
124
|
+
t.variableDeclaration('const', [
|
125
|
+
t.variableDeclarator(t.identifier('client'), t.callExpression(t.identifier('get'), [
|
126
|
+
t.identifier('cosmWasmClient')
|
127
|
+
]))
|
128
|
+
]),
|
129
|
+
t.returnStatement(t.newExpression(t.identifier(QueryClient), [
|
130
|
+
t.identifier('client'),
|
131
|
+
t.identifier('contractAddress')
|
132
|
+
]))
|
133
|
+
]), false)))
|
134
|
+
])
|
135
|
+
], t.tsTypeParameterInstantiation([
|
136
|
+
t.tsTypeReference(t.identifier(QueryClient)),
|
137
|
+
t.tsTypeReference(t.identifier('QueryClientParams'))
|
138
|
+
])))]));
|
139
|
+
};
|
140
|
+
exports.createRecoilQueryClient = createRecoilQueryClient;
|