wasm-ast-types 0.9.0 → 0.11.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/client/client.js +2 -2
- package/main/client/test/ts-client.arrays-ref.spec.js +1 -3
- package/main/client/test/ts-client.arrays.spec.js +7 -3
- package/main/client/test/ts-client.cw-named-groups.test.js +1 -3
- package/main/client/test/ts-client.cw-proposal-single.test.js +4 -6
- package/main/client/test/ts-client.empty-enums.spec.js +1 -3
- package/main/client/test/ts-client.issues.test.js +4 -6
- package/main/client/test/ts-client.sg721.spec.js +1 -3
- package/main/client/test/ts-client.spec.js +17 -19
- package/main/client/test/ts-client.vectis.spec.js +9 -11
- package/main/context/context.js +25 -4
- package/main/message-composer/message-composer.spec.js +2 -4
- package/main/react-query/react-query.js +1 -1
- package/main/react-query/react-query.spec.js +5 -7
- package/main/recoil/recoil.js +3 -3
- package/main/recoil/recoil.spec.js +2 -4
- package/main/utils/types.js +110 -32
- package/module/client/client.js +4 -4
- package/module/client/test/ts-client.arrays-ref.spec.js +2 -3
- package/module/client/test/ts-client.arrays.spec.js +7 -3
- package/module/client/test/ts-client.cw-named-groups.test.js +2 -3
- package/module/client/test/ts-client.cw-proposal-single.test.js +5 -6
- package/module/client/test/ts-client.empty-enums.spec.js +2 -3
- package/module/client/test/ts-client.issues.test.js +5 -6
- package/module/client/test/ts-client.sg721.spec.js +2 -3
- package/module/client/test/ts-client.spec.js +18 -19
- package/module/client/test/ts-client.vectis.spec.js +10 -11
- package/module/context/context.js +23 -3
- package/module/message-composer/message-composer.spec.js +3 -4
- package/module/react-query/react-query.js +2 -2
- package/module/react-query/react-query.spec.js +6 -7
- package/module/recoil/recoil.js +4 -4
- package/module/recoil/recoil.spec.js +3 -4
- package/module/utils/types.js +91 -27
- package/package.json +2 -2
- package/types/context/context.d.ts +25 -3
- package/types/react-query/react-query.d.ts +3 -2
- package/types/recoil/recoil.d.ts +1 -1
- package/types/utils/types.d.ts +10 -1
package/main/utils/types.js
CHANGED
@@ -7,9 +7,11 @@ var _typeof3 = require("@babel/runtime/helpers/typeof");
|
|
7
7
|
Object.defineProperty(exports, "__esModule", {
|
8
8
|
value: true
|
9
9
|
});
|
10
|
-
exports.getParamsTypeAnnotation = exports.createTypedObjectParams = void 0;
|
10
|
+
exports.getParamsTypeAnnotation = exports.detectType = exports.createTypedObjectParams = void 0;
|
11
11
|
exports.getPropertySignatureFromProp = getPropertySignatureFromProp;
|
12
|
-
exports.
|
12
|
+
exports.getPropertyType = void 0;
|
13
|
+
exports.getResponseType = getResponseType;
|
14
|
+
exports.getTypeInfo = exports.getTypeFromRef = exports.getType = void 0;
|
13
15
|
|
14
16
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
15
17
|
|
@@ -27,6 +29,16 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
27
29
|
|
28
30
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof3(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; }
|
29
31
|
|
32
|
+
function getResponseType(context, underscoreName) {
|
33
|
+
var _context$contract$res, _context$contract, _context$contract$res2, _context$contract$res3;
|
34
|
+
|
35
|
+
var methodName = (0, _case.camel)(underscoreName);
|
36
|
+
return (0, _case.pascal)((_context$contract$res = (_context$contract = context.contract) === null || _context$contract === void 0 ? void 0 : (_context$contract$res2 = _context$contract.responses) === null || _context$contract$res2 === void 0 ? void 0 : (_context$contract$res3 = _context$contract$res2[underscoreName]) === null || _context$contract$res3 === void 0 ? void 0 : _context$contract$res3.title) !== null && _context$contract$res !== void 0 ? _context$contract$res : // after v1.1 is adopted, we can deprecate this and require the above response
|
37
|
+
"".concat(methodName, "Response"));
|
38
|
+
}
|
39
|
+
|
40
|
+
;
|
41
|
+
|
30
42
|
var getTypeStrFromRef = function getTypeStrFromRef($ref) {
|
31
43
|
if ($ref !== null && $ref !== void 0 && $ref.startsWith('#/definitions/')) {
|
32
44
|
return $ref.replace('#/definitions/', '');
|
@@ -58,7 +70,9 @@ var getTypeOrRef = function getTypeOrRef(obj) {
|
|
58
70
|
};
|
59
71
|
|
60
72
|
var getArrayTypeFromItems = function getArrayTypeFromItems(items) {
|
61
|
-
|
73
|
+
var detect = detectType(items.type);
|
74
|
+
|
75
|
+
if (detect.type === 'array') {
|
62
76
|
if (Array.isArray(items.items)) {
|
63
77
|
return t.tsArrayType(t.tsArrayType(getTypeOrRef(items.items[0])));
|
64
78
|
} else {
|
@@ -66,42 +80,43 @@ var getArrayTypeFromItems = function getArrayTypeFromItems(items) {
|
|
66
80
|
}
|
67
81
|
}
|
68
82
|
|
69
|
-
return t.tsArrayType(getType(
|
83
|
+
return t.tsArrayType(getType(detect.type));
|
70
84
|
};
|
71
85
|
|
72
|
-
var
|
73
|
-
|
74
|
-
|
75
|
-
return t.tsStringKeyword();
|
76
|
-
|
77
|
-
case 'boolean':
|
78
|
-
return t.tSBooleanKeyword();
|
86
|
+
var detectType = function detectType(type) {
|
87
|
+
var optional = false;
|
88
|
+
var theType = '';
|
79
89
|
|
80
|
-
|
81
|
-
|
90
|
+
if (Array.isArray(type)) {
|
91
|
+
if (type.length !== 2) {
|
92
|
+
throw new Error('[getType(array length)] case not handled by transpiler. contact maintainers.');
|
93
|
+
}
|
82
94
|
|
83
|
-
default
|
84
|
-
|
85
|
-
|
86
|
-
};
|
95
|
+
var _type = (0, _slicedToArray2["default"])(type, 2),
|
96
|
+
nullableType = _type[0],
|
97
|
+
nullType = _type[1];
|
87
98
|
|
88
|
-
|
99
|
+
if (nullType !== 'null') {
|
100
|
+
throw new Error('[getType(null)] case not handled by transpiler. contact maintainers.');
|
101
|
+
}
|
89
102
|
|
90
|
-
|
91
|
-
|
103
|
+
theType = nullableType;
|
104
|
+
optional = true;
|
105
|
+
} else {
|
106
|
+
theType = type;
|
107
|
+
}
|
92
108
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
109
|
+
return {
|
110
|
+
type: theType,
|
111
|
+
optional: optional
|
112
|
+
};
|
113
|
+
};
|
97
114
|
|
98
|
-
|
99
|
-
info = info.allOf[0];
|
100
|
-
}
|
115
|
+
exports.detectType = detectType;
|
101
116
|
|
102
|
-
|
103
|
-
|
104
|
-
|
117
|
+
var getTypeInfo = function getTypeInfo(info) {
|
118
|
+
var type = undefined;
|
119
|
+
var optional = undefined;
|
105
120
|
|
106
121
|
if (Array.isArray(info.anyOf)) {
|
107
122
|
// assuming 2nd is null, but let's check to ensure
|
@@ -146,7 +161,9 @@ var getPropertyType = function getPropertyType(context, schema, prop) {
|
|
146
161
|
throw new Error('[info.items] case not handled by transpiler. contact maintainers.');
|
147
162
|
}
|
148
163
|
} else {
|
149
|
-
|
164
|
+
var detect = detectType(info.type);
|
165
|
+
type = getType(detect.type);
|
166
|
+
optional = detect.optional;
|
150
167
|
}
|
151
168
|
}
|
152
169
|
|
@@ -165,7 +182,16 @@ var getPropertyType = function getPropertyType(context, schema, prop) {
|
|
165
182
|
}
|
166
183
|
|
167
184
|
if (_nullableType === 'array' && (0, _typeof2["default"])(info.items) === 'object' && !Array.isArray(info.items)) {
|
168
|
-
|
185
|
+
var _detect = detectType(info.items.type);
|
186
|
+
|
187
|
+
if (_detect.type === 'array') {
|
188
|
+
// wen recursion?
|
189
|
+
type = t.tsArrayType(getArrayTypeFromItems(info.items));
|
190
|
+
} else {
|
191
|
+
type = t.tsArrayType(getType(_detect.type));
|
192
|
+
}
|
193
|
+
|
194
|
+
optional = _detect.optional;
|
169
195
|
} else {
|
170
196
|
type = getType(_nullableType);
|
171
197
|
}
|
@@ -173,6 +199,58 @@ var getPropertyType = function getPropertyType(context, schema, prop) {
|
|
173
199
|
optional = true;
|
174
200
|
}
|
175
201
|
|
202
|
+
return {
|
203
|
+
type: type,
|
204
|
+
optional: optional
|
205
|
+
};
|
206
|
+
};
|
207
|
+
|
208
|
+
exports.getTypeInfo = getTypeInfo;
|
209
|
+
|
210
|
+
var getType = function getType(type) {
|
211
|
+
switch (type) {
|
212
|
+
case 'string':
|
213
|
+
return t.tsStringKeyword();
|
214
|
+
|
215
|
+
case 'boolean':
|
216
|
+
return t.tSBooleanKeyword();
|
217
|
+
|
218
|
+
case 'integer':
|
219
|
+
return t.tsNumberKeyword();
|
220
|
+
|
221
|
+
default:
|
222
|
+
throw new Error('contact maintainers [unknown type]: ' + type);
|
223
|
+
}
|
224
|
+
};
|
225
|
+
|
226
|
+
exports.getType = getType;
|
227
|
+
|
228
|
+
var getPropertyType = function getPropertyType(context, schema, prop) {
|
229
|
+
var _schema$properties, _schema$required, _schema$required2;
|
230
|
+
|
231
|
+
var props = (_schema$properties = schema.properties) !== null && _schema$properties !== void 0 ? _schema$properties : {};
|
232
|
+
var info = props[prop];
|
233
|
+
var type = null;
|
234
|
+
var optional = !((_schema$required = schema.required) !== null && _schema$required !== void 0 && _schema$required.includes(prop));
|
235
|
+
|
236
|
+
if (info.allOf && info.allOf.length === 1) {
|
237
|
+
info = info.allOf[0];
|
238
|
+
}
|
239
|
+
|
240
|
+
if (typeof info.$ref === 'string') {
|
241
|
+
type = getTypeFromRef(info.$ref);
|
242
|
+
}
|
243
|
+
|
244
|
+
var typeInfo = getTypeInfo(info);
|
245
|
+
|
246
|
+
if (typeof typeInfo.optional !== 'undefined') {
|
247
|
+
optional = typeInfo.optional;
|
248
|
+
}
|
249
|
+
|
250
|
+
if (typeof typeInfo.type !== 'undefined') {
|
251
|
+
type = typeInfo.type;
|
252
|
+
}
|
253
|
+
|
176
254
|
if (!type) {
|
177
255
|
throw new Error('cannot find type for ' + JSON.stringify(info));
|
178
256
|
}
|
package/module/client/client.js
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
import * as t from '@babel/types';
|
2
|
-
import { camel
|
2
|
+
import { camel } from 'case';
|
3
3
|
import { bindMethod, typedIdentifier, promiseTypeAnnotation, classDeclaration, classProperty, arrowFunctionExpression, getMessageProperties } from '../utils';
|
4
|
-
import { getPropertyType, getType, createTypedObjectParams } from '../utils/types';
|
4
|
+
import { getPropertyType, getType, createTypedObjectParams, getResponseType } from '../utils/types';
|
5
5
|
import { identifier, propertySignature } from '../utils/babel';
|
6
6
|
export const CONSTANT_EXEC_PARAMS = [t.assignmentPattern(identifier('fee', t.tsTypeAnnotation(t.tsUnionType([t.tSNumberKeyword(), t.tsTypeReference(t.identifier('StdFee')), t.tsLiteralType(t.stringLiteral('auto'))])), false), t.stringLiteral('auto')), identifier('memo', t.tsTypeAnnotation(t.tsStringKeyword()), true), identifier('funds', t.tsTypeAnnotation(t.tsArrayType(t.tsTypeReference(t.identifier('Coin')))), true)];
|
7
7
|
export const FIXED_EXECUTE_PARAMS = [identifier('fee', t.tsTypeAnnotation(t.tsUnionType([t.tsNumberKeyword(), t.tsTypeReference(t.identifier('StdFee')), t.tsLiteralType(t.stringLiteral('auto'))])), true), identifier('memo', t.tsTypeAnnotation(t.tsStringKeyword()), true), identifier('funds', t.tsTypeAnnotation(t.tsArrayType(t.tsTypeReference(t.identifier('Coin')))), true)];
|
8
8
|
export const createWasmQueryMethod = (context, jsonschema) => {
|
9
9
|
const underscoreName = Object.keys(jsonschema.properties)[0];
|
10
10
|
const methodName = camel(underscoreName);
|
11
|
-
const responseType =
|
11
|
+
const responseType = getResponseType(context, underscoreName);
|
12
12
|
const obj = createTypedObjectParams(context, jsonschema.properties[underscoreName]);
|
13
13
|
const args = getWasmMethodArgs(context, jsonschema.properties[underscoreName]);
|
14
14
|
const actionArg = t.objectProperty(t.identifier(underscoreName), t.objectExpression(args));
|
@@ -113,7 +113,7 @@ export const createQueryInterface = (context, className, queryMsg) => {
|
|
113
113
|
const methods = getMessageProperties(queryMsg).map(jsonschema => {
|
114
114
|
const underscoreName = Object.keys(jsonschema.properties)[0];
|
115
115
|
const methodName = camel(underscoreName);
|
116
|
-
const responseType =
|
116
|
+
const responseType = getResponseType(context, underscoreName);
|
117
117
|
return createPropertyFunctionWithObjectParams(context, methodName, responseType, jsonschema.properties[underscoreName]);
|
118
118
|
});
|
119
119
|
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(className), null, [], t.tSInterfaceBody([t.tSPropertySignature(t.identifier('contractAddress'), t.tsTypeAnnotation(t.tsStringKeyword())), ...methods])));
|
@@ -1,8 +1,7 @@
|
|
1
1
|
import message from '../../../../../__fixtures__/misc/schema/arrays-ref.json';
|
2
2
|
import { createQueryClass, createExecuteClass, createExecuteInterface, createTypeInterface } from '../client';
|
3
|
-
import {
|
4
|
-
|
5
|
-
const ctx = new RenderContext(message);
|
3
|
+
import { expectCode, makeContext } from '../../../test-utils';
|
4
|
+
const ctx = makeContext(message);
|
6
5
|
it('execute_msg_for__empty', () => {
|
7
6
|
expectCode(createTypeInterface(ctx, message));
|
8
7
|
});
|
@@ -1,8 +1,12 @@
|
|
1
1
|
import message from '../../../../../__fixtures__/misc/schema/arrays.json';
|
2
2
|
import { createQueryClass, createExecuteClass, createExecuteInterface, createTypeInterface } from '../client';
|
3
|
-
import {
|
4
|
-
import {
|
5
|
-
const ctx =
|
3
|
+
import { expectCode, makeContext } from '../../../test-utils';
|
4
|
+
import { getPropertyType } from '../../utils';
|
5
|
+
const ctx = makeContext(message);
|
6
|
+
it('getPropertyType', () => {
|
7
|
+
const ast = getPropertyType(ctx, message.oneOf[0].properties.update_edges, 'edges3');
|
8
|
+
expectCode(ast.type); // printCode(ast.type)
|
9
|
+
});
|
6
10
|
it('execute_msg_for__empty', () => {
|
7
11
|
expectCode(createTypeInterface(ctx, message));
|
8
12
|
});
|
@@ -1,8 +1,7 @@
|
|
1
1
|
import execute_msg from '../../../../../__fixtures__/daodao/cw-named-groups/execute_msg.json';
|
2
2
|
import { createQueryClass, createExecuteClass, createExecuteInterface, createTypeInterface } from '../client';
|
3
|
-
import {
|
4
|
-
|
5
|
-
const ctx = new RenderContext(execute_msg);
|
3
|
+
import { expectCode, makeContext } from '../../../test-utils';
|
4
|
+
const ctx = makeContext(execute_msg);
|
6
5
|
it('execute_msg', () => {
|
7
6
|
expectCode(createTypeInterface(ctx, execute_msg));
|
8
7
|
});
|
@@ -1,21 +1,20 @@
|
|
1
1
|
import execute_msg from '../../../../../__fixtures__/daodao/cw-proposal-single/execute_msg.json';
|
2
2
|
import query_msg from '../../../../../__fixtures__/daodao/cw-proposal-single/query_msg.json';
|
3
3
|
import { createQueryClass, createExecuteClass, createExecuteInterface, createTypeInterface } from '../client';
|
4
|
-
import {
|
5
|
-
import { expectCode } from '../../../test-utils';
|
4
|
+
import { expectCode, makeContext } from '../../../test-utils';
|
6
5
|
it('execute_msg_for', () => {
|
7
|
-
const ctx =
|
6
|
+
const ctx = makeContext(execute_msg);
|
8
7
|
expectCode(createTypeInterface(ctx, execute_msg));
|
9
8
|
});
|
10
9
|
it('query classes', () => {
|
11
|
-
const ctx =
|
10
|
+
const ctx = makeContext(query_msg);
|
12
11
|
expectCode(createQueryClass(ctx, 'SG721QueryClient', 'SG721ReadOnlyInstance', query_msg));
|
13
12
|
});
|
14
13
|
it('execute classes array types', () => {
|
15
|
-
const ctx =
|
14
|
+
const ctx = makeContext(execute_msg);
|
16
15
|
expectCode(createExecuteClass(ctx, 'SG721Client', 'SG721Instance', null, execute_msg));
|
17
16
|
});
|
18
17
|
it('execute interfaces no extends', () => {
|
19
|
-
const ctx =
|
18
|
+
const ctx = makeContext(execute_msg);
|
20
19
|
expectCode(createExecuteInterface(ctx, 'SG721Instance', null, execute_msg));
|
21
20
|
});
|
@@ -1,8 +1,7 @@
|
|
1
1
|
import query_msg from '../../../../../__fixtures__/daodao/cw-admin-factory/query_msg.json';
|
2
2
|
import { createQueryClass, createQueryInterface } from '../client';
|
3
|
-
import {
|
4
|
-
|
5
|
-
const ctx = new RenderContext(query_msg);
|
3
|
+
import { expectCode, makeContext } from '../../../test-utils';
|
4
|
+
const ctx = makeContext(query_msg);
|
6
5
|
it('query classes', () => {
|
7
6
|
expectCode(createQueryClass(ctx, 'SG721QueryClient', 'SG721ReadOnlyInstance', query_msg));
|
8
7
|
});
|
@@ -1,22 +1,21 @@
|
|
1
|
-
import { globContracts } from '../../../test-utils';
|
1
|
+
import { globContracts, makeContext } from '../../../test-utils';
|
2
2
|
import { createQueryClass, createExecuteClass, createExecuteInterface, createTypeInterface } from '../client';
|
3
|
-
import { RenderContext } from '../../context';
|
4
3
|
import { expectCode } from '../../../test-utils';
|
5
4
|
import cases from 'jest-in-case';
|
6
5
|
const contracts = globContracts('issues/55');
|
7
6
|
cases('execute_msg_for__empty', async opts => {
|
8
|
-
const ctx =
|
7
|
+
const ctx = makeContext(opts.content);
|
9
8
|
expectCode(createTypeInterface(ctx, opts.content));
|
10
9
|
}, contracts);
|
11
10
|
cases('query classes', async opts => {
|
12
|
-
const ctx =
|
11
|
+
const ctx = makeContext(opts.content);
|
13
12
|
expectCode(createQueryClass(ctx, 'SG721QueryClient', 'SG721ReadOnlyInstance', opts.content));
|
14
13
|
}, contracts);
|
15
14
|
cases('execute class', async opts => {
|
16
|
-
const ctx =
|
15
|
+
const ctx = makeContext(opts.content);
|
17
16
|
expectCode(createExecuteClass(ctx, 'SG721Client', 'SG721Instance', null, opts.content));
|
18
17
|
}, contracts);
|
19
18
|
cases('execute interface', async opts => {
|
20
|
-
const ctx =
|
19
|
+
const ctx = makeContext(opts.content);
|
21
20
|
expectCode(createExecuteInterface(ctx, 'SG721Instance', null, opts.content));
|
22
21
|
}, contracts);
|
@@ -1,8 +1,7 @@
|
|
1
1
|
import execute_msg_for__empty from '../../../../../__fixtures__/sg721/execute_msg_for__empty.json';
|
2
2
|
import { createQueryClass, createExecuteClass, createExecuteInterface, createTypeInterface } from '../client';
|
3
|
-
import {
|
4
|
-
|
5
|
-
const ctx = new RenderContext(execute_msg_for__empty);
|
3
|
+
import { expectCode, makeContext } from '../../../test-utils';
|
4
|
+
const ctx = makeContext(execute_msg_for__empty);
|
6
5
|
it('execute_msg_for__empty', () => {
|
7
6
|
expectCode(createTypeInterface(ctx, execute_msg_for__empty));
|
8
7
|
});
|
@@ -13,73 +13,72 @@ import operators_response from '../../../../../__fixtures__/basic/operators_resp
|
|
13
13
|
import owner_of_response from '../../../../../__fixtures__/basic/owner_of_response.json';
|
14
14
|
import tokens_response from '../../../../../__fixtures__/basic/tokens_response.json';
|
15
15
|
import { createQueryClass, createQueryInterface, createExecuteClass, createExecuteInterface, createTypeInterface } from '../client';
|
16
|
-
import {
|
17
|
-
import { expectCode } from '../../../test-utils';
|
16
|
+
import { expectCode, makeContext } from '../../../test-utils';
|
18
17
|
it('approval_response', () => {
|
19
|
-
const ctx =
|
18
|
+
const ctx = makeContext(approval_response);
|
20
19
|
expectCode(createTypeInterface(ctx, approval_response));
|
21
20
|
});
|
22
21
|
it('all_nft_info_response', () => {
|
23
|
-
const ctx =
|
22
|
+
const ctx = makeContext(all_nft_info_response);
|
24
23
|
expectCode(createTypeInterface(ctx, all_nft_info_response));
|
25
24
|
});
|
26
25
|
it('approvals_response', () => {
|
27
|
-
const ctx =
|
26
|
+
const ctx = makeContext(approvals_response);
|
28
27
|
expectCode(createTypeInterface(ctx, approvals_response));
|
29
28
|
});
|
30
29
|
it('collection_info_response', () => {
|
31
|
-
const ctx =
|
30
|
+
const ctx = makeContext(collection_info_response);
|
32
31
|
expectCode(createTypeInterface(ctx, collection_info_response));
|
33
32
|
});
|
34
33
|
it('contract_info_response', () => {
|
35
|
-
const ctx =
|
34
|
+
const ctx = makeContext(contract_info_response);
|
36
35
|
expectCode(createTypeInterface(ctx, contract_info_response));
|
37
36
|
});
|
38
37
|
it('instantiate_msg', () => {
|
39
|
-
const ctx =
|
38
|
+
const ctx = makeContext(instantiate_msg);
|
40
39
|
expectCode(createTypeInterface(ctx, instantiate_msg));
|
41
40
|
});
|
42
41
|
it('nft_info_response', () => {
|
43
|
-
const ctx =
|
42
|
+
const ctx = makeContext(nft_info_response);
|
44
43
|
expectCode(createTypeInterface(ctx, nft_info_response));
|
45
44
|
});
|
46
45
|
it('num_tokens_response', () => {
|
47
|
-
const ctx =
|
46
|
+
const ctx = makeContext(num_tokens_response);
|
48
47
|
expectCode(createTypeInterface(ctx, num_tokens_response));
|
49
48
|
});
|
50
49
|
it('operators_response', () => {
|
51
|
-
const ctx =
|
50
|
+
const ctx = makeContext(operators_response);
|
52
51
|
expectCode(createTypeInterface(ctx, operators_response));
|
53
52
|
});
|
54
53
|
it('owner_of_response', () => {
|
55
|
-
const ctx =
|
54
|
+
const ctx = makeContext(owner_of_response);
|
56
55
|
expectCode(createTypeInterface(ctx, owner_of_response));
|
57
56
|
});
|
58
57
|
it('tokens_response', () => {
|
59
|
-
const ctx =
|
58
|
+
const ctx = makeContext(tokens_response);
|
60
59
|
expectCode(createTypeInterface(ctx, tokens_response));
|
61
60
|
});
|
62
61
|
it('query classes', () => {
|
63
|
-
const ctx =
|
62
|
+
const ctx = makeContext(query_msg);
|
64
63
|
expectCode(createQueryClass(ctx, 'SG721QueryClient', 'SG721ReadOnlyInstance', query_msg));
|
65
64
|
});
|
66
65
|
it('execute classes', () => {
|
67
|
-
const ctx =
|
66
|
+
const ctx = makeContext(execute_msg);
|
68
67
|
expectCode(createExecuteClass(ctx, 'SG721Client', 'SG721Instance', 'SG721QueryClient', execute_msg));
|
69
68
|
});
|
70
69
|
it('execute classes no extends', () => {
|
71
|
-
const ctx =
|
70
|
+
const ctx = makeContext(execute_msg);
|
72
71
|
expectCode(createExecuteClass(ctx, 'SG721Client', 'SG721Instance', null, execute_msg));
|
73
72
|
});
|
74
73
|
it('execute classes array types', () => {
|
75
|
-
const ctx =
|
74
|
+
const ctx = makeContext(execute_msg_named_groups);
|
76
75
|
expectCode(createExecuteClass(ctx, 'SG721Client', 'SG721Instance', null, execute_msg_named_groups));
|
77
76
|
});
|
78
77
|
it('execute interfaces no extends', () => {
|
79
|
-
const ctx =
|
78
|
+
const ctx = makeContext(execute_msg);
|
80
79
|
expectCode(createExecuteInterface(ctx, 'SG721Instance', null, execute_msg));
|
81
80
|
});
|
82
81
|
it('query interfaces', () => {
|
83
|
-
const ctx =
|
82
|
+
const ctx = makeContext(query_msg);
|
84
83
|
expectCode(createQueryInterface(ctx, 'SG721ReadOnlyInstance', query_msg));
|
85
84
|
});
|
@@ -4,41 +4,40 @@ import can_execute_relay_response from '../../../../../__fixtures__/vectis/govec
|
|
4
4
|
import info_response from '../../../../../__fixtures__/vectis/govec/info_response.json';
|
5
5
|
import relay_transaction from '../../../../../__fixtures__/vectis/govec/relay_transaction.json';
|
6
6
|
import { createQueryClass, createExecuteClass, createExecuteInterface, createTypeInterface } from '../client';
|
7
|
-
import {
|
8
|
-
import { expectCode } from '../../../test-utils';
|
7
|
+
import { expectCode, makeContext } from '../../../test-utils';
|
9
8
|
it('cosmos_msg_for__empty', () => {
|
10
|
-
const ctx =
|
9
|
+
const ctx = makeContext(cosmos_msg_for__empty);
|
11
10
|
expectCode(createTypeInterface(ctx, cosmos_msg_for__empty));
|
12
11
|
});
|
13
12
|
it('execute_msg_for__empty', () => {
|
14
|
-
const ctx =
|
13
|
+
const ctx = makeContext(execute_msg_for__empty);
|
15
14
|
expectCode(createTypeInterface(ctx, execute_msg_for__empty));
|
16
15
|
});
|
17
16
|
it('can_execute_relay_response', () => {
|
18
|
-
const ctx =
|
17
|
+
const ctx = makeContext(can_execute_relay_response);
|
19
18
|
expectCode(createTypeInterface(ctx, can_execute_relay_response));
|
20
19
|
});
|
21
20
|
it('info_response', () => {
|
22
|
-
const ctx =
|
21
|
+
const ctx = makeContext(info_response);
|
23
22
|
expectCode(createTypeInterface(ctx, info_response));
|
24
23
|
});
|
25
24
|
it('relay_transaction', () => {
|
26
|
-
const ctx =
|
25
|
+
const ctx = makeContext(relay_transaction);
|
27
26
|
expectCode(createTypeInterface(ctx, relay_transaction));
|
28
27
|
});
|
29
28
|
it('query classes', () => {
|
30
|
-
const ctx =
|
29
|
+
const ctx = makeContext(cosmos_msg_for__empty);
|
31
30
|
expectCode(createQueryClass(ctx, 'SG721QueryClient', 'SG721ReadOnlyInstance', cosmos_msg_for__empty));
|
32
31
|
});
|
33
32
|
it('query classes', () => {
|
34
|
-
const ctx =
|
33
|
+
const ctx = makeContext(execute_msg_for__empty);
|
35
34
|
expectCode(createQueryClass(ctx, 'SG721QueryClient', 'SG721ReadOnlyInstance', execute_msg_for__empty));
|
36
35
|
});
|
37
36
|
it('execute classes array types', () => {
|
38
|
-
const ctx =
|
37
|
+
const ctx = makeContext(execute_msg_for__empty);
|
39
38
|
expectCode(createExecuteClass(ctx, 'SG721Client', 'SG721Instance', null, execute_msg_for__empty));
|
40
39
|
});
|
41
40
|
it('execute interfaces no extends', () => {
|
42
|
-
const ctx =
|
41
|
+
const ctx = makeContext(execute_msg_for__empty);
|
43
42
|
expectCode(createExecuteInterface(ctx, 'SG721Instance', null, execute_msg_for__empty));
|
44
43
|
});
|
@@ -1,7 +1,13 @@
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
2
|
+
|
3
|
+
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; }
|
4
|
+
|
5
|
+
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) { _defineProperty(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; }
|
6
|
+
|
2
7
|
import { convertUtilsToImportList, getImportStatements } from "./imports";
|
3
8
|
import deepmerge from "deepmerge"; /// Plugin Types
|
4
9
|
|
10
|
+
;
|
5
11
|
export const defaultOptions = {
|
6
12
|
types: {
|
7
13
|
enabled: true,
|
@@ -25,13 +31,27 @@ export const defaultOptions = {
|
|
25
31
|
queryKeys: false
|
26
32
|
}
|
27
33
|
};
|
34
|
+
export const getDefinitionSchema = schemas => {
|
35
|
+
const aggregateSchema = {
|
36
|
+
definitions: {//
|
37
|
+
}
|
38
|
+
};
|
39
|
+
schemas.forEach(schema => {
|
40
|
+
schema.definitions = schema.definitions || {};
|
41
|
+
aggregateSchema.definitions = _objectSpread(_objectSpread({}, aggregateSchema.definitions), schema.definitions);
|
42
|
+
});
|
43
|
+
return aggregateSchema;
|
44
|
+
};
|
28
45
|
export class RenderContext {
|
29
|
-
constructor(
|
30
|
-
_defineProperty(this, "
|
46
|
+
constructor(contract, options) {
|
47
|
+
_defineProperty(this, "contract", void 0);
|
31
48
|
|
32
49
|
_defineProperty(this, "utils", []);
|
33
50
|
|
34
|
-
this
|
51
|
+
_defineProperty(this, "schema", void 0);
|
52
|
+
|
53
|
+
this.contract = contract;
|
54
|
+
this.schema = getDefinitionSchema(contract.schemas);
|
35
55
|
this.options = deepmerge(defaultOptions, options ?? {});
|
36
56
|
}
|
37
57
|
|
@@ -1,12 +1,11 @@
|
|
1
1
|
import execute_msg from '../../../../__fixtures__/basic/execute_msg_for__empty.json';
|
2
2
|
import { createMessageComposerClass, createMessageComposerInterface } from './message-composer';
|
3
|
-
import {
|
4
|
-
import { expectCode } from '../../test-utils';
|
3
|
+
import { expectCode, makeContext } from '../../test-utils';
|
5
4
|
it('execute classes', () => {
|
6
|
-
const ctx =
|
5
|
+
const ctx = makeContext(execute_msg);
|
7
6
|
expectCode(createMessageComposerClass(ctx, 'SG721MessageComposer', 'SG721Message', execute_msg));
|
8
7
|
});
|
9
8
|
it('createMessageComposerInterface', () => {
|
10
|
-
const ctx =
|
9
|
+
const ctx = makeContext(execute_msg);
|
11
10
|
expectCode(createMessageComposerInterface(ctx, 'SG721Message', execute_msg));
|
12
11
|
});
|
@@ -2,7 +2,7 @@ import * as t from '@babel/types';
|
|
2
2
|
import { camel, pascal } from 'case';
|
3
3
|
import { callExpression, getMessageProperties, identifier, tsObjectPattern, tsPropertySignature } from '../utils';
|
4
4
|
import { omitTypeReference, optionalConditionalExpression, propertySignature, shorthandProperty } from '../utils/babel';
|
5
|
-
import { getParamsTypeAnnotation, getPropertyType } from '../utils/types';
|
5
|
+
import { getParamsTypeAnnotation, getPropertyType, getResponseType } from '../utils/types';
|
6
6
|
import { FIXED_EXECUTE_PARAMS } from '../client';
|
7
7
|
export const createReactQueryHooks = ({
|
8
8
|
context,
|
@@ -40,7 +40,7 @@ export const createReactQueryHooks = ({
|
|
40
40
|
|
41
41
|
const hookName = `use${hookParamsTypeName}`; // listVotersResponse
|
42
42
|
|
43
|
-
const responseType =
|
43
|
+
const responseType = getResponseType(context, underscoreName); // cw3FlexMultisigListVoters
|
44
44
|
|
45
45
|
const getterKey = camel(`${contractName}${pascal(methodName)}`);
|
46
46
|
const jsonschema = schema.properties[underscoreName];
|
@@ -1,11 +1,10 @@
|
|
1
1
|
import * as t from '@babel/types';
|
2
2
|
import query_msg from '../../../../__fixtures__/basic/query_msg.json';
|
3
3
|
import execute_msg from '../../../../__fixtures__/basic/execute_msg_for__empty.json';
|
4
|
-
import { RenderContext } from '../context';
|
5
4
|
import { createReactQueryHooks, createReactQueryMutationHooks } from './react-query';
|
6
|
-
import { expectCode } from '../../test-utils';
|
7
|
-
const execCtx =
|
8
|
-
const queryCtx =
|
5
|
+
import { expectCode, makeContext } from '../../test-utils';
|
6
|
+
const execCtx = makeContext(execute_msg);
|
7
|
+
const queryCtx = makeContext(query_msg);
|
9
8
|
it('createReactQueryHooks', () => {
|
10
9
|
expectCode(t.program(createReactQueryHooks({
|
11
10
|
context: queryCtx,
|
@@ -14,7 +13,7 @@ it('createReactQueryHooks', () => {
|
|
14
13
|
QueryClient: 'Sg721QueryClient'
|
15
14
|
})));
|
16
15
|
expectCode(t.program(createReactQueryHooks({
|
17
|
-
context:
|
16
|
+
context: makeContext(query_msg, {
|
18
17
|
reactQuery: {
|
19
18
|
optionalClient: true
|
20
19
|
}
|
@@ -24,7 +23,7 @@ it('createReactQueryHooks', () => {
|
|
24
23
|
QueryClient: 'Sg721QueryClient'
|
25
24
|
})));
|
26
25
|
expectCode(t.program(createReactQueryHooks({
|
27
|
-
context:
|
26
|
+
context: makeContext(query_msg, {
|
28
27
|
reactQuery: {
|
29
28
|
version: 'v4'
|
30
29
|
}
|
@@ -34,7 +33,7 @@ it('createReactQueryHooks', () => {
|
|
34
33
|
QueryClient: 'Sg721QueryClient'
|
35
34
|
})));
|
36
35
|
expectCode(t.program(createReactQueryHooks({
|
37
|
-
context:
|
36
|
+
context: makeContext(query_msg, {
|
38
37
|
reactQuery: {
|
39
38
|
optionalClient: true,
|
40
39
|
version: 'v4'
|
package/module/recoil/recoil.js
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
import * as t from '@babel/types';
|
2
2
|
import { camel, pascal } from 'case';
|
3
|
-
import { callExpression, getMessageProperties } from '../utils';
|
4
|
-
export const createRecoilSelector = (context, keyPrefix, QueryClient, methodName) => {
|
3
|
+
import { callExpression, getMessageProperties, getResponseType } from '../utils';
|
4
|
+
export const createRecoilSelector = (context, keyPrefix, QueryClient, methodName, responseType) => {
|
5
5
|
context.addUtil('selectorFamily');
|
6
6
|
const selectorName = camel(`${methodName}Selector`);
|
7
|
-
const responseType = pascal(`${methodName}Response`);
|
8
7
|
const getterKey = camel(`${keyPrefix}${pascal(methodName)}`);
|
9
8
|
return t.exportNamedDeclaration(t.variableDeclaration('const', [t.variableDeclarator(t.identifier(selectorName), callExpression(t.identifier('selectorFamily'), [t.objectExpression([t.objectProperty(t.identifier('key'), t.stringLiteral(getterKey)), t.objectProperty(t.identifier('get'), t.arrowFunctionExpression([t.objectPattern([t.objectProperty(t.identifier('params'), t.identifier('params'), false, true), t.restElement(t.identifier('queryClientParams'))])], t.arrowFunctionExpression([t.objectPattern([t.objectProperty(t.identifier('get'), t.identifier('get'), false, true)])], t.blockStatement([t.variableDeclaration('const', [t.variableDeclarator(t.identifier('client'), t.callExpression(t.identifier('get'), [t.callExpression(t.identifier('queryClient'), [t.identifier('queryClientParams')])]))]), t.returnStatement(t.awaitExpression(t.callExpression(t.memberExpression(t.identifier('client'), t.identifier(methodName)), [t.spreadElement(t.identifier('params'))])))]), true)))])], t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier(responseType)), t.tsIntersectionType([t.tsTypeReference(t.identifier('QueryClientParams')), t.tsTypeLiteral([t.tsPropertySignature(t.identifier('params'), t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Parameters'), t.tsTypeParameterInstantiation([t.tsIndexedAccessType(t.tsTypeReference(t.identifier(QueryClient)), t.tsLiteralType(t.stringLiteral(methodName)))]))))])])])))]));
|
10
9
|
};
|
@@ -12,7 +11,8 @@ export const createRecoilSelectors = (context, keyPrefix, QueryClient, queryMsg)
|
|
12
11
|
return getMessageProperties(queryMsg).map(schema => {
|
13
12
|
const underscoreName = Object.keys(schema.properties)[0];
|
14
13
|
const methodName = camel(underscoreName);
|
15
|
-
|
14
|
+
const responseType = getResponseType(context, underscoreName);
|
15
|
+
return createRecoilSelector(context, keyPrefix, QueryClient, methodName, responseType);
|
16
16
|
});
|
17
17
|
};
|
18
18
|
export const createRecoilQueryClientType = () => ({
|