wasm-ast-types 0.24.0 → 0.26.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 +46 -72
- package/main/client/index.js +0 -2
- package/main/client/test/ts-client.account-nfts.spec.js +3 -5
- package/main/client/test/ts-client.arrays-ref.spec.js +0 -4
- package/main/client/test/ts-client.arrays.spec.js +3 -6
- package/main/client/test/ts-client.cw-named-groups.test.js +0 -4
- package/main/client/test/ts-client.cw-proposal-single.test.js +0 -5
- package/main/client/test/ts-client.empty-enums.spec.js +0 -4
- package/main/client/test/ts-client.issue-101.spec.js +0 -4
- package/main/client/test/ts-client.issue-103.test.js +0 -4
- package/main/client/test/ts-client.issue-71.test.js +28 -50
- package/main/client/test/ts-client.issue-98.test.js +3 -5
- package/main/client/test/ts-client.issues.test.js +28 -50
- package/main/client/test/ts-client.overrides.spec.js +0 -4
- package/main/client/test/ts-client.sg721.spec.js +0 -4
- package/main/client/test/ts-client.spec.js +0 -17
- package/main/client/test/ts-client.vectis.spec.js +0 -8
- package/main/client/test/ts-client.wager.spec.js +4 -5
- package/main/context/context.js +6 -33
- package/main/context/imports.js +7 -43
- package/main/context/index.js +0 -4
- package/main/index.js +4 -22
- package/main/{msg-builder → message-builder}/index.js +4 -6
- package/main/{msg-builder/msg-builder.js → message-builder/message-builder.js} +24 -30
- package/main/{msg-builder/msg-builder.spec.js → message-builder/message-builder.spec.js} +4 -10
- package/main/message-composer/index.js +0 -2
- package/main/message-composer/message-composer.js +18 -28
- package/main/message-composer/message-composer.spec.js +0 -5
- package/main/provider/index.js +0 -2
- package/main/provider/provider.js +2 -29
- package/main/provider/provider.spec.js +0 -3
- package/main/react-query/index.js +0 -2
- package/main/react-query/react-query.js +125 -152
- package/main/react-query/react-query.spec.js +0 -10
- package/main/recoil/index.js +0 -2
- package/main/recoil/recoil.js +0 -14
- package/main/recoil/recoil.spec.js +0 -8
- package/main/utils/babel.js +12 -98
- package/main/utils/babel.spec.js +72 -67
- package/main/utils/constants.js +0 -6
- package/main/utils/index.js +0 -7
- package/main/utils/ref.js +0 -3
- package/main/utils/types.js +22 -109
- package/module/client/client.js +46 -32
- package/module/client/test/ts-client.account-nfts.spec.js +3 -1
- package/module/client/test/ts-client.arrays.spec.js +3 -1
- package/module/client/test/ts-client.issue-101.spec.js +3 -1
- package/module/client/test/ts-client.issue-98.test.js +3 -1
- package/module/client/test/ts-client.wager.spec.js +4 -1
- package/module/context/context.js +9 -23
- package/module/context/imports.js +5 -24
- package/module/index.js +1 -1
- package/module/message-builder/index.js +1 -0
- package/module/{msg-builder/msg-builder.js → message-builder/message-builder.js} +22 -17
- package/module/{msg-builder/msg-builder.spec.js → message-builder/message-builder.spec.js} +4 -4
- package/module/message-composer/message-composer.js +18 -14
- package/module/provider/provider.js +0 -8
- package/module/react-query/react-query.js +77 -76
- package/module/utils/babel.js +4 -14
- package/module/utils/babel.spec.js +49 -23
- package/module/utils/types.js +18 -66
- package/package.json +2 -2
- package/src/context/context.ts +158 -158
- package/src/index.ts +1 -1
- package/src/{msg-builder/__snapshots__/msg-builder.spec.ts.snap → message-builder/__snapshots__/message-builder.spec.ts.snap} +2 -2
- package/src/message-builder/index.ts +1 -0
- package/src/{msg-builder/msg-builder.spec.ts → message-builder/message-builder.spec.ts} +6 -7
- package/src/{msg-builder/msg-builder.ts → message-builder/message-builder.ts} +5 -5
- package/src/react-query/react-query.spec.ts +1 -1
- package/types/context/context.d.ts +2 -2
- package/types/index.d.ts +1 -1
- package/types/message-builder/index.d.ts +1 -0
- package/types/message-builder/message-builder.d.ts +4 -0
- package/module/msg-builder/index.js +0 -1
- package/src/msg-builder/index.ts +0 -1
- package/types/msg-builder/index.d.ts +0 -1
- package/types/msg-builder/msg-builder.d.ts +0 -4
package/main/utils/types.js
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
-
|
5
4
|
var _typeof3 = require("@babel/runtime/helpers/typeof");
|
6
|
-
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
8
6
|
value: true
|
9
7
|
});
|
@@ -12,78 +10,55 @@ exports.getPropertySignatureFromProp = getPropertySignatureFromProp;
|
|
12
10
|
exports.getPropertyType = void 0;
|
13
11
|
exports.getResponseType = getResponseType;
|
14
12
|
exports.getTypeInfo = exports.getTypeFromRef = exports.getType = void 0;
|
15
|
-
|
16
13
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
17
|
-
|
18
14
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
19
|
-
|
20
15
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
21
|
-
|
22
16
|
var t = _interopRequireWildcard(require("@babel/types"));
|
23
|
-
|
24
17
|
var _case = require("case");
|
25
|
-
|
26
18
|
var _babel = require("./babel");
|
27
|
-
|
28
19
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
29
|
-
|
30
20
|
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; }
|
31
|
-
|
32
21
|
function getResponseType(context, underscoreName) {
|
33
22
|
var _context$contract$res, _context$contract, _context$contract$res2, _context$contract$res3;
|
34
|
-
|
35
23
|
var methodName = (0, _case.camel)(underscoreName);
|
36
24
|
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
25
|
"".concat(methodName, "Response"));
|
38
26
|
}
|
39
|
-
|
40
27
|
;
|
41
|
-
|
42
28
|
var getTypeStrFromRef = function getTypeStrFromRef($ref) {
|
43
29
|
if ($ref !== null && $ref !== void 0 && $ref.startsWith('#/definitions/')) {
|
44
30
|
return $ref.replace('#/definitions/', '');
|
45
31
|
}
|
46
|
-
|
47
32
|
throw new Error('what is $ref: ' + $ref);
|
48
33
|
};
|
49
|
-
|
50
34
|
var getTypeFromRef = function getTypeFromRef($ref) {
|
51
35
|
return t.tsTypeReference(t.identifier(getTypeStrFromRef($ref)));
|
52
36
|
};
|
53
|
-
|
54
37
|
exports.getTypeFromRef = getTypeFromRef;
|
55
|
-
|
56
38
|
var getArrayTypeFromRef = function getArrayTypeFromRef($ref) {
|
57
39
|
return t.tsArrayType(getTypeFromRef($ref));
|
58
40
|
};
|
59
|
-
|
60
41
|
var getTypeOrRef = function getTypeOrRef(obj) {
|
61
42
|
if (obj.type) {
|
62
43
|
return getType(obj.type);
|
63
44
|
}
|
64
|
-
|
65
45
|
if (obj.$ref) {
|
66
46
|
return getTypeFromRef(obj.$ref);
|
67
47
|
}
|
68
|
-
|
69
48
|
throw new Error('contact maintainers cannot find type for ' + obj);
|
70
49
|
};
|
71
|
-
|
72
50
|
var getArrayTypeFromItems = function getArrayTypeFromItems(items) {
|
73
51
|
// passing in [{"type":"string"}]
|
74
52
|
if (Array.isArray(items)) {
|
75
53
|
var _items$;
|
76
|
-
|
77
54
|
if (((_items$ = items[0]) === null || _items$ === void 0 ? void 0 : _items$.type) === 'array') {
|
78
55
|
return getArrayTypeFromItems(items[0]);
|
79
56
|
}
|
80
|
-
|
81
57
|
return t.tsArrayType(t.tsArrayType(getTypeOrRef(items[0])));
|
82
|
-
}
|
83
|
-
|
58
|
+
}
|
84
59
|
|
60
|
+
// passing in {"items": [{"type":"string"}]}
|
85
61
|
var detect = detectType(items.type);
|
86
|
-
|
87
62
|
if (detect.type === 'array') {
|
88
63
|
if (Array.isArray(items.items)) {
|
89
64
|
return t.tsArrayType(t.tsArrayType(getTypeOrRef(items.items[0])));
|
@@ -91,59 +66,46 @@ var getArrayTypeFromItems = function getArrayTypeFromItems(items) {
|
|
91
66
|
return t.tsArrayType(getArrayTypeFromItems(items.items));
|
92
67
|
}
|
93
68
|
}
|
94
|
-
|
95
69
|
return t.tsArrayType(getType(detect.type));
|
96
70
|
};
|
97
|
-
|
98
71
|
var detectType = function detectType(type) {
|
99
72
|
var optional = false;
|
100
73
|
var theType = '';
|
101
|
-
|
102
74
|
if (Array.isArray(type)) {
|
103
75
|
if (type.length !== 2) {
|
104
76
|
throw new Error('[getType(array length)] case not handled by transpiler. contact maintainers.');
|
105
77
|
}
|
106
|
-
|
107
78
|
var _type = (0, _slicedToArray2["default"])(type, 2),
|
108
|
-
|
109
|
-
|
110
|
-
|
79
|
+
nullableType = _type[0],
|
80
|
+
nullType = _type[1];
|
111
81
|
if (nullType !== 'null') {
|
112
82
|
throw new Error('[getType(null)] case not handled by transpiler. contact maintainers.');
|
113
83
|
}
|
114
|
-
|
115
84
|
theType = nullableType;
|
116
85
|
optional = true;
|
117
86
|
} else {
|
118
87
|
theType = type;
|
119
88
|
}
|
120
|
-
|
121
89
|
return {
|
122
90
|
type: theType,
|
123
91
|
optional: optional
|
124
92
|
};
|
125
93
|
};
|
126
|
-
|
127
94
|
exports.detectType = detectType;
|
128
|
-
|
129
95
|
var getTypeInfo = function getTypeInfo(info) {
|
130
96
|
var type = undefined;
|
131
97
|
var optional = undefined;
|
132
|
-
|
133
98
|
if (Array.isArray(info.anyOf)) {
|
134
99
|
// assuming 2nd is null, but let's check to ensure
|
135
100
|
if (info.anyOf.length !== 2) {
|
136
101
|
throw new Error('case not handled by transpiler. contact maintainers.');
|
137
102
|
}
|
138
|
-
|
139
103
|
var _info$anyOf = (0, _slicedToArray2["default"])(info.anyOf, 2),
|
140
|
-
|
141
|
-
|
142
|
-
|
104
|
+
nullableType = _info$anyOf[0],
|
105
|
+
nullType = _info$anyOf[1];
|
143
106
|
if ((nullType === null || nullType === void 0 ? void 0 : nullType.type) !== 'null') {
|
144
107
|
throw new Error('[nullableType.type]: case not handled by transpiler. contact maintainers.');
|
145
108
|
}
|
146
|
-
|
147
109
|
if (!(nullableType !== null && nullableType !== void 0 && nullableType.$ref)) {
|
148
110
|
if (nullableType.title) {
|
149
111
|
type = t.tsTypeReference(t.identifier(nullableType.title));
|
@@ -153,10 +115,8 @@ var getTypeInfo = function getTypeInfo(info) {
|
|
153
115
|
} else {
|
154
116
|
type = getTypeFromRef(nullableType === null || nullableType === void 0 ? void 0 : nullableType.$ref);
|
155
117
|
}
|
156
|
-
|
157
118
|
optional = true;
|
158
119
|
}
|
159
|
-
|
160
120
|
if (typeof info.type === 'string') {
|
161
121
|
if (info.type === 'array') {
|
162
122
|
if ((0, _typeof2["default"])(info.items) === 'object' && !Array.isArray(info.items)) {
|
@@ -171,7 +131,8 @@ var getTypeInfo = function getTypeInfo(info) {
|
|
171
131
|
}
|
172
132
|
} else {
|
173
133
|
if (Array.isArray(info.items)) {
|
174
|
-
type = getArrayTypeFromItems(info.items);
|
134
|
+
type = getArrayTypeFromItems(info.items);
|
135
|
+
// console.log(typeof info.items === 'object');
|
175
136
|
// console.log(Array.isArray(info.items));
|
176
137
|
// console.log(info);
|
177
138
|
} else {
|
@@ -184,35 +145,30 @@ var getTypeInfo = function getTypeInfo(info) {
|
|
184
145
|
optional = detect.optional;
|
185
146
|
}
|
186
147
|
}
|
187
|
-
|
188
148
|
if (Array.isArray(info.type)) {
|
189
149
|
// assuming 2nd is null, but let's check to ensure
|
190
150
|
if (info.type.length !== 2) {
|
191
151
|
throw new Error('please report this to maintainers (field type): ' + JSON.stringify(info, null, 2));
|
192
152
|
}
|
193
|
-
|
194
153
|
var _info$type = (0, _slicedToArray2["default"])(info.type, 2),
|
195
|
-
|
196
|
-
|
197
|
-
|
154
|
+
_nullableType = _info$type[0],
|
155
|
+
_nullType = _info$type[1];
|
198
156
|
if (_nullType !== 'null') {
|
199
157
|
throw new Error('please report this to maintainers (field type): ' + JSON.stringify(info, null, 2));
|
200
158
|
}
|
201
|
-
|
202
159
|
if (_nullableType === 'array' && (0, _typeof2["default"])(info.items) === 'object' && !Array.isArray(info.items)) {
|
203
160
|
if (info.items.type) {
|
204
161
|
var _detect = detectType(info.items.type);
|
205
|
-
|
206
162
|
if (_detect.type === 'array') {
|
207
163
|
// wen recursion?
|
208
164
|
type = t.tsArrayType(getArrayTypeFromItems(info.items));
|
209
165
|
} else {
|
210
166
|
type = t.tsArrayType(getType(_detect.type));
|
211
167
|
}
|
212
|
-
|
213
168
|
optional = _detect.optional;
|
214
169
|
} else if (info.items.$ref) {
|
215
|
-
type = getArrayTypeFromRef(info.items.$ref);
|
170
|
+
type = getArrayTypeFromRef(info.items.$ref);
|
171
|
+
// } else if (info.items.title) {
|
216
172
|
// type = t.tsArrayType(
|
217
173
|
// t.tsTypeReference(
|
218
174
|
// t.identifier(info.items.title)
|
@@ -225,87 +181,65 @@ var getTypeInfo = function getTypeInfo(info) {
|
|
225
181
|
}
|
226
182
|
} else {
|
227
183
|
var _detect2 = detectType(_nullableType);
|
228
|
-
|
229
184
|
optional = _detect2.optional;
|
230
|
-
|
231
185
|
if (_detect2.type === 'array') {
|
232
186
|
type = getArrayTypeFromItems(info.items);
|
233
187
|
} else {
|
234
188
|
type = getType(_detect2.type);
|
235
189
|
}
|
236
190
|
}
|
237
|
-
|
238
191
|
optional = true;
|
239
192
|
}
|
240
|
-
|
241
193
|
return {
|
242
194
|
type: type,
|
243
195
|
optional: optional
|
244
196
|
};
|
245
197
|
};
|
246
|
-
|
247
198
|
exports.getTypeInfo = getTypeInfo;
|
248
|
-
|
249
199
|
var getType = function getType(type) {
|
250
200
|
switch (type) {
|
251
201
|
case 'string':
|
252
202
|
return t.tsStringKeyword();
|
253
|
-
|
254
203
|
case 'boolean':
|
255
204
|
return t.tSBooleanKeyword();
|
256
|
-
|
257
205
|
case 'integer':
|
258
206
|
return t.tsNumberKeyword();
|
259
|
-
|
260
207
|
default:
|
261
208
|
throw new Error('contact maintainers [unknown type]: ' + type);
|
262
209
|
}
|
263
210
|
};
|
264
|
-
|
265
211
|
exports.getType = getType;
|
266
|
-
|
267
212
|
var getPropertyType = function getPropertyType(context, schema, prop) {
|
268
213
|
var _schema$properties, _schema$required, _schema$required2;
|
269
|
-
|
270
214
|
var props = (_schema$properties = schema.properties) !== null && _schema$properties !== void 0 ? _schema$properties : {};
|
271
215
|
var info = props[prop];
|
272
216
|
var type = null;
|
273
217
|
var optional = !((_schema$required = schema.required) !== null && _schema$required !== void 0 && _schema$required.includes(prop));
|
274
|
-
|
275
218
|
if (info.allOf && info.allOf.length === 1) {
|
276
219
|
info = info.allOf[0];
|
277
220
|
}
|
278
|
-
|
279
221
|
if (typeof info.$ref === 'string') {
|
280
222
|
type = getTypeFromRef(info.$ref);
|
281
223
|
}
|
282
|
-
|
283
224
|
var typeInfo = getTypeInfo(info);
|
284
|
-
|
285
225
|
if (typeof typeInfo.optional !== 'undefined') {
|
286
226
|
optional = typeInfo.optional;
|
287
227
|
}
|
288
|
-
|
289
228
|
if (typeof typeInfo.type !== 'undefined') {
|
290
229
|
type = typeInfo.type;
|
291
230
|
}
|
292
|
-
|
293
231
|
if (!type) {
|
294
232
|
throw new Error('cannot find type for ' + JSON.stringify(info));
|
295
233
|
}
|
296
|
-
|
297
234
|
if ((_schema$required2 = schema.required) !== null && _schema$required2 !== void 0 && _schema$required2.includes(prop)) {
|
298
235
|
optional = false;
|
299
236
|
}
|
300
|
-
|
301
237
|
return {
|
302
238
|
type: type,
|
303
239
|
optional: optional
|
304
240
|
};
|
305
241
|
};
|
306
|
-
|
307
242
|
exports.getPropertyType = getPropertyType;
|
308
|
-
|
309
243
|
function getPropertySignatureFromProp(context, jsonschema, prop, camelize) {
|
310
244
|
if (jsonschema.properties[prop].type === 'object') {
|
311
245
|
if (jsonschema.properties[prop].title) {
|
@@ -314,19 +248,16 @@ function getPropertySignatureFromProp(context, jsonschema, prop, camelize) {
|
|
314
248
|
throw new Error('getPropertySignatureFromProp() contact maintainer');
|
315
249
|
}
|
316
250
|
}
|
317
|
-
|
318
251
|
if (Array.isArray(jsonschema.properties[prop].allOf)) {
|
319
252
|
var _jsonschema$required;
|
320
|
-
|
321
253
|
var isOptional = !((_jsonschema$required = jsonschema.required) !== null && _jsonschema$required !== void 0 && _jsonschema$required.includes(prop));
|
322
254
|
var unionTypes = jsonschema.properties[prop].allOf.map(function (el) {
|
323
255
|
if (el.title) return el.title;
|
324
256
|
if (el.$ref) return getTypeStrFromRef(el.$ref);
|
325
257
|
return el.type;
|
326
|
-
});
|
327
|
-
|
258
|
+
});
|
259
|
+
// @ts-ignore:next-line
|
328
260
|
var uniqUnionTypes = (0, _toConsumableArray2["default"])(new Set(unionTypes));
|
329
|
-
|
330
261
|
if (uniqUnionTypes.length === 1) {
|
331
262
|
return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(uniqUnionTypes[0]))), isOptional);
|
332
263
|
} else {
|
@@ -336,18 +267,14 @@ function getPropertySignatureFromProp(context, jsonschema, prop, camelize) {
|
|
336
267
|
}
|
337
268
|
} else if (Array.isArray(jsonschema.properties[prop].oneOf)) {
|
338
269
|
var _jsonschema$required2;
|
339
|
-
|
340
270
|
var _isOptional = !((_jsonschema$required2 = jsonschema.required) !== null && _jsonschema$required2 !== void 0 && _jsonschema$required2.includes(prop));
|
341
|
-
|
342
271
|
var _unionTypes = jsonschema.properties[prop].oneOf.map(function (el) {
|
343
272
|
if (el.title) return el.title;
|
344
273
|
if (el.$ref) return getTypeStrFromRef(el.$ref);
|
345
274
|
return el.type;
|
346
|
-
});
|
347
|
-
|
348
|
-
|
275
|
+
});
|
276
|
+
// @ts-ignore:next-line
|
349
277
|
var _uniqUnionTypes = (0, _toConsumableArray2["default"])(new Set(_unionTypes));
|
350
|
-
|
351
278
|
if (_uniqUnionTypes.length === 1) {
|
352
279
|
return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(_uniqUnionTypes[0]))), _isOptional);
|
353
280
|
} else {
|
@@ -356,31 +283,24 @@ function getPropertySignatureFromProp(context, jsonschema, prop, camelize) {
|
|
356
283
|
}))), _isOptional);
|
357
284
|
}
|
358
285
|
}
|
359
|
-
|
360
286
|
try {
|
361
287
|
getPropertyType(context, jsonschema, prop);
|
362
288
|
} catch (e) {
|
363
289
|
console.log(e);
|
364
290
|
console.log(JSON.stringify(jsonschema, null, 2), prop);
|
365
291
|
}
|
366
|
-
|
367
292
|
var _getPropertyType = getPropertyType(context, jsonschema, prop),
|
368
|
-
|
369
|
-
|
370
|
-
|
293
|
+
type = _getPropertyType.type,
|
294
|
+
optional = _getPropertyType.optional;
|
371
295
|
return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(type), optional);
|
372
296
|
}
|
373
|
-
|
374
297
|
var getParamsTypeAnnotation = function getParamsTypeAnnotation(context, jsonschema) {
|
375
298
|
var _jsonschema$propertie;
|
376
|
-
|
377
299
|
var camelize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
378
300
|
var keys = Object.keys((_jsonschema$propertie = jsonschema.properties) !== null && _jsonschema$propertie !== void 0 ? _jsonschema$propertie : {});
|
379
|
-
|
380
301
|
if (!keys.length && jsonschema.$ref) {
|
381
302
|
return t.tsTypeAnnotation(getTypeFromRef(jsonschema.$ref));
|
382
303
|
}
|
383
|
-
|
384
304
|
if (!keys.length) return undefined;
|
385
305
|
var typedParams = keys.map(function (prop) {
|
386
306
|
return getPropertySignatureFromProp(context, jsonschema, prop, camelize);
|
@@ -388,21 +308,16 @@ var getParamsTypeAnnotation = function getParamsTypeAnnotation(context, jsonsche
|
|
388
308
|
return t.tsTypeAnnotation(t.tsTypeLiteral( // @ts-ignore:next-line
|
389
309
|
(0, _toConsumableArray2["default"])(typedParams)));
|
390
310
|
};
|
391
|
-
|
392
311
|
exports.getParamsTypeAnnotation = getParamsTypeAnnotation;
|
393
|
-
|
394
312
|
var createTypedObjectParams = function createTypedObjectParams(context, jsonschema) {
|
395
313
|
var _jsonschema$propertie2;
|
396
|
-
|
397
314
|
var camelize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
398
315
|
var keys = Object.keys((_jsonschema$propertie2 = jsonschema.properties) !== null && _jsonschema$propertie2 !== void 0 ? _jsonschema$propertie2 : {});
|
399
|
-
|
400
316
|
if (!keys.length) {
|
401
317
|
// is there a ref?
|
402
318
|
if (jsonschema.$ref) {
|
403
|
-
var _obj = context.refLookup(jsonschema.$ref);
|
404
|
-
|
405
|
-
|
319
|
+
var _obj = context.refLookup(jsonschema.$ref);
|
320
|
+
// If there is a oneOf, then we need to create a type for it
|
406
321
|
if (_obj !== null && _obj !== void 0 && _obj.oneOf) {
|
407
322
|
// the actual type of the ref
|
408
323
|
var refType = jsonschema.$ref.split('/').pop();
|
@@ -413,12 +328,11 @@ var createTypedObjectParams = function createTypedObjectParams(context, jsonsche
|
|
413
328
|
} else if (_obj) {
|
414
329
|
return createTypedObjectParams(context, _obj, camelize);
|
415
330
|
}
|
416
|
-
}
|
417
|
-
|
331
|
+
}
|
418
332
|
|
333
|
+
// no results...
|
419
334
|
return;
|
420
335
|
}
|
421
|
-
|
422
336
|
var params = keys.map(function (prop) {
|
423
337
|
return t.objectProperty(camelize ? t.identifier((0, _case.camel)(prop)) : t.identifier(prop), camelize ? t.identifier((0, _case.camel)(prop)) : t.identifier(prop), false, true);
|
424
338
|
});
|
@@ -426,5 +340,4 @@ var createTypedObjectParams = function createTypedObjectParams(context, jsonsche
|
|
426
340
|
obj.typeAnnotation = getParamsTypeAnnotation(context, jsonschema, camelize);
|
427
341
|
return obj;
|
428
342
|
};
|
429
|
-
|
430
343
|
exports.createTypedObjectParams = createTypedObjectParams;
|
package/module/client/client.js
CHANGED
@@ -10,8 +10,8 @@ export const createWasmQueryMethod = (context, jsonschema) => {
|
|
10
10
|
const responseType = getResponseType(context, underscoreName);
|
11
11
|
const param = createTypedObjectParams(context, jsonschema.properties[underscoreName]);
|
12
12
|
const args = getWasmMethodArgs(context, jsonschema.properties[underscoreName]);
|
13
|
-
const msgAction = t.identifier(underscoreName);
|
14
|
-
|
13
|
+
const msgAction = t.identifier(underscoreName);
|
14
|
+
// If the param is an identifier, we can just use it as is
|
15
15
|
const msgActionValue = param?.type === 'Identifier' ? t.identifier(param.name) : t.objectExpression(args);
|
16
16
|
return t.classProperty(t.identifier(methodName), arrowFunctionExpression(param ? [param] : [], t.blockStatement([t.returnStatement(t.callExpression(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier('client')), t.identifier('queryContractSmart')), [t.memberExpression(t.thisExpression(), t.identifier('contractAddress')), t.objectExpression([t.objectProperty(msgAction, msgActionValue)])]))]), t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Promise'), t.tsTypeParameterInstantiation([t.tSTypeReference(t.identifier(responseType))]))), true));
|
17
17
|
};
|
@@ -22,27 +22,32 @@ export const createQueryClass = (context, className, implementsClassName, queryM
|
|
22
22
|
const methods = getMessageProperties(queryMsg).map(schema => {
|
23
23
|
return createWasmQueryMethod(context, schema);
|
24
24
|
});
|
25
|
-
return t.exportNamedDeclaration(classDeclaration(className, [
|
26
|
-
|
27
|
-
classProperty('
|
28
|
-
|
25
|
+
return t.exportNamedDeclaration(classDeclaration(className, [
|
26
|
+
// client
|
27
|
+
classProperty('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CosmWasmClient')))),
|
28
|
+
// contractAddress
|
29
|
+
classProperty('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword())),
|
30
|
+
// constructor
|
31
|
+
t.classMethod('constructor', t.identifier('constructor'), [typedIdentifier('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CosmWasmClient')))), typedIdentifier('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword()))], t.blockStatement([
|
32
|
+
// client/contract set
|
29
33
|
t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier('client')), t.identifier('client'))), t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier('contractAddress')), t.identifier('contractAddress'))), ...bindings])), ...methods], [t.tSExpressionWithTypeArguments(t.identifier(implementsClassName))]));
|
30
34
|
};
|
31
35
|
export const getWasmMethodArgs = (context, jsonschema) => {
|
32
|
-
let keys = Object.keys(jsonschema.properties ?? {});
|
36
|
+
let keys = Object.keys(jsonschema.properties ?? {});
|
33
37
|
|
38
|
+
// only 1 degree $ref-lookup
|
34
39
|
if (!keys.length && jsonschema.$ref) {
|
35
|
-
const obj = context.refLookup(jsonschema.$ref);
|
36
|
-
|
40
|
+
const obj = context.refLookup(jsonschema.$ref);
|
41
|
+
// properties
|
37
42
|
if (obj) {
|
38
43
|
keys = Object.keys(obj.properties ?? {});
|
39
|
-
}
|
40
|
-
|
44
|
+
}
|
41
45
|
|
42
|
-
|
46
|
+
// tuple struct or otherwise, use the name of the reference
|
47
|
+
if (!keys.length && obj?.oneOf) {
|
48
|
+
// TODO????? ADAIR
|
43
49
|
}
|
44
50
|
}
|
45
|
-
|
46
51
|
const args = keys.map(prop => {
|
47
52
|
return t.objectProperty(t.identifier(prop), t.identifier(camel(prop)), false, prop === camel(prop));
|
48
53
|
});
|
@@ -56,11 +61,13 @@ export const createWasmExecMethod = (context, jsonschema) => {
|
|
56
61
|
const methodName = camel(underscoreName);
|
57
62
|
const param = createTypedObjectParams(context, jsonschema.properties[underscoreName]);
|
58
63
|
const args = getWasmMethodArgs(context, jsonschema.properties[underscoreName]);
|
59
|
-
const msgAction = t.identifier(underscoreName);
|
60
|
-
|
64
|
+
const msgAction = t.identifier(underscoreName);
|
65
|
+
// If the param is an identifier, we can just use it as is
|
61
66
|
const msgActionValue = param?.type === 'Identifier' ? t.identifier(param.name) : t.objectExpression(args);
|
62
|
-
return t.classProperty(t.identifier(methodName), arrowFunctionExpression(param ? [
|
63
|
-
|
67
|
+
return t.classProperty(t.identifier(methodName), arrowFunctionExpression(param ? [
|
68
|
+
// props
|
69
|
+
param, ...CONSTANT_EXEC_PARAMS] : CONSTANT_EXEC_PARAMS, t.blockStatement([t.returnStatement(t.awaitExpression(t.callExpression(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier('client')), t.identifier('execute')), [t.memberExpression(t.thisExpression(), t.identifier('sender')), t.memberExpression(t.thisExpression(), t.identifier('contractAddress')), t.objectExpression([t.objectProperty(msgAction, msgActionValue)]), t.identifier('fee'), t.identifier('memo'), t.identifier('_funds')])))]),
|
70
|
+
// return type
|
64
71
|
t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Promise'), t.tsTypeParameterInstantiation([t.tSTypeReference(t.identifier('ExecuteResult'))]))), true));
|
65
72
|
};
|
66
73
|
export const createExecuteClass = (context, className, implementsClassName, extendsClassName, execMsg) => {
|
@@ -71,19 +78,23 @@ export const createExecuteClass = (context, className, implementsClassName, exte
|
|
71
78
|
return createWasmExecMethod(context, schema);
|
72
79
|
});
|
73
80
|
const blockStmt = [];
|
74
|
-
|
75
81
|
if (extendsClassName) {
|
76
|
-
blockStmt.push(
|
82
|
+
blockStmt.push(
|
83
|
+
// super()
|
77
84
|
t.expressionStatement(t.callExpression(t.super(), [t.identifier('client'), t.identifier('contractAddress')])));
|
78
85
|
}
|
79
|
-
|
80
|
-
|
86
|
+
[].push.apply(blockStmt, [
|
87
|
+
// client/contract set
|
81
88
|
t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier('client')), t.identifier('client'))), t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier('sender')), t.identifier('sender'))), t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier('contractAddress')), t.identifier('contractAddress'))), ...bindings]);
|
82
89
|
const noImplicitOverride = context.options.client.noImplicitOverride && extendsClassName && context.options.client.execExtendsQuery;
|
83
|
-
return t.exportNamedDeclaration(classDeclaration(className, [
|
84
|
-
|
85
|
-
classProperty('
|
86
|
-
|
90
|
+
return t.exportNamedDeclaration(classDeclaration(className, [
|
91
|
+
// client
|
92
|
+
classProperty('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('SigningCosmWasmClient'))), false, false, noImplicitOverride),
|
93
|
+
// sender
|
94
|
+
classProperty('sender', t.tsTypeAnnotation(t.tsStringKeyword())),
|
95
|
+
// contractAddress
|
96
|
+
classProperty('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword()), false, false, noImplicitOverride),
|
97
|
+
// constructor
|
87
98
|
t.classMethod('constructor', t.identifier('constructor'), [typedIdentifier('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('SigningCosmWasmClient')))), typedIdentifier('sender', t.tsTypeAnnotation(t.tsStringKeyword())), typedIdentifier('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword()))], t.blockStatement(blockStmt)), ...methods], [t.tSExpressionWithTypeArguments(t.identifier(implementsClassName))], extendsClassName ? t.identifier(extendsClassName) : null));
|
88
99
|
};
|
89
100
|
export const createExecuteInterface = (context, className, extendsClassName, execMsg) => {
|
@@ -93,8 +104,10 @@ export const createExecuteInterface = (context, className, extendsClassName, exe
|
|
93
104
|
return createPropertyFunctionWithObjectParamsForExec(context, methodName, 'ExecuteResult', jsonschema.properties[underscoreName]);
|
94
105
|
});
|
95
106
|
const extendsAst = extendsClassName ? [t.tSExpressionWithTypeArguments(t.identifier(extendsClassName))] : [];
|
96
|
-
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(className), null, extendsAst, t.tSInterfaceBody([
|
97
|
-
|
107
|
+
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(className), null, extendsAst, t.tSInterfaceBody([
|
108
|
+
// contract address
|
109
|
+
t.tSPropertySignature(t.identifier('contractAddress'), t.tsTypeAnnotation(t.tsStringKeyword())),
|
110
|
+
// contract address
|
98
111
|
t.tSPropertySignature(t.identifier('sender'), t.tsTypeAnnotation(t.tsStringKeyword())), ...methods])));
|
99
112
|
};
|
100
113
|
export const createPropertyFunctionWithObjectParams = (context, methodName, responseType, jsonschema) => {
|
@@ -104,7 +117,8 @@ export const createPropertyFunctionWithObjectParams = (context, methodName, resp
|
|
104
117
|
typeAnnotation: promiseTypeAnnotation(responseType),
|
105
118
|
parameters: obj ? [obj] : []
|
106
119
|
};
|
107
|
-
return t.tSPropertySignature(t.identifier(methodName), t.tsTypeAnnotation(
|
120
|
+
return t.tSPropertySignature(t.identifier(methodName), t.tsTypeAnnotation(
|
121
|
+
// @ts-ignore:next-line
|
108
122
|
func));
|
109
123
|
};
|
110
124
|
export const createPropertyFunctionWithObjectParamsForExec = (context, methodName, responseType, jsonschema) => {
|
@@ -115,7 +129,8 @@ export const createPropertyFunctionWithObjectParamsForExec = (context, methodNam
|
|
115
129
|
typeAnnotation: promiseTypeAnnotation(responseType),
|
116
130
|
parameters: obj ? [obj, ...FIXED_EXECUTE_PARAMS] : FIXED_EXECUTE_PARAMS
|
117
131
|
};
|
118
|
-
return t.tSPropertySignature(t.identifier(methodName), t.tsTypeAnnotation(
|
132
|
+
return t.tSPropertySignature(t.identifier(methodName), t.tsTypeAnnotation(
|
133
|
+
// @ts-ignore:next-line
|
119
134
|
func));
|
120
135
|
};
|
121
136
|
export const createQueryInterface = (context, className, queryMsg) => {
|
@@ -132,10 +147,8 @@ export const createTypeOrInterface = (context, Type, jsonschema) => {
|
|
132
147
|
if (!jsonschema.type) {
|
133
148
|
return t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(Type), null, t.tsTypeReference(t.identifier(jsonschema.title))));
|
134
149
|
}
|
135
|
-
|
136
150
|
return t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(Type), null, getType(jsonschema.type)));
|
137
151
|
}
|
138
|
-
|
139
152
|
const props = Object.keys(jsonschema.properties ?? {}).map(prop => {
|
140
153
|
const {
|
141
154
|
type,
|
@@ -143,7 +156,8 @@ export const createTypeOrInterface = (context, Type, jsonschema) => {
|
|
143
156
|
} = getPropertyType(context, jsonschema, prop);
|
144
157
|
return propertySignature(camel(prop), t.tsTypeAnnotation(type), optional);
|
145
158
|
});
|
146
|
-
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(Type), null, [], t.tsInterfaceBody(
|
159
|
+
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(Type), null, [], t.tsInterfaceBody(
|
160
|
+
// @ts-ignore:next-line
|
147
161
|
[...props])));
|
148
162
|
};
|
149
163
|
export const createTypeInterface = (context, jsonschema) => {
|
@@ -8,7 +8,9 @@ it('execute_msg_for__empty', () => {
|
|
8
8
|
});
|
9
9
|
it('query classes', () => {
|
10
10
|
expectCode(createQueryClass(ctx, 'SG721QueryClient', 'SG721ReadOnlyInstance', message));
|
11
|
-
});
|
11
|
+
});
|
12
|
+
|
13
|
+
// it('query classes response', () => {
|
12
14
|
// expectCode(createTypeInterface(
|
13
15
|
// ctx,
|
14
16
|
// contract.responses.all_debt_shares
|
@@ -5,8 +5,10 @@ import { getPropertyType } from '../../utils';
|
|
5
5
|
const ctx = makeContext(message);
|
6
6
|
it('getPropertyType', () => {
|
7
7
|
const ast = getPropertyType(ctx, message.oneOf[0].properties.update_edges, 'edges3');
|
8
|
-
expectCode(ast.type);
|
8
|
+
expectCode(ast.type);
|
9
|
+
// printCode(ast.type)
|
9
10
|
});
|
11
|
+
|
10
12
|
it('execute_msg_for__empty', () => {
|
11
13
|
expectCode(createTypeInterface(ctx, message));
|
12
14
|
});
|
@@ -1,6 +1,8 @@
|
|
1
1
|
import { createExecuteClass, createExecuteInterface } from '../client';
|
2
2
|
import { expectCode, makeContext } from '../../../test-utils';
|
3
|
-
import ownership from '../../../../../__fixtures__/basic/ownership.json';
|
3
|
+
import ownership from '../../../../../__fixtures__/basic/ownership.json';
|
4
|
+
|
5
|
+
// it('query classes', () => {
|
4
6
|
// const ctx = makeContext(cosmos_msg_for__empty);
|
5
7
|
// expectCode(createQueryClass(
|
6
8
|
// ctx,
|
@@ -8,7 +8,9 @@ it('execute_msg_for__empty', () => {
|
|
8
8
|
});
|
9
9
|
it('query classes', () => {
|
10
10
|
expectCode(createQueryClass(ctx, 'SG721QueryClient', 'SG721ReadOnlyInstance', message));
|
11
|
-
});
|
11
|
+
});
|
12
|
+
|
13
|
+
// it('query classes response', () => {
|
12
14
|
// expectCode(createTypeInterface(
|
13
15
|
// ctx,
|
14
16
|
// contract.responses.all_debt_shares
|
@@ -14,7 +14,9 @@ it('query classes', () => {
|
|
14
14
|
});
|
15
15
|
it('execute classes', () => {
|
16
16
|
expectCode(createExecuteClass(executeCtx, 'WagerClient', 'WagerInstance', null, wagerJson.execute));
|
17
|
-
});
|
17
|
+
});
|
18
|
+
|
19
|
+
// it('execute classes array types', () => {
|
18
20
|
// expectCode(createExecuteClass(
|
19
21
|
// ctx,
|
20
22
|
// 'SG721Client',
|
@@ -23,6 +25,7 @@ it('execute classes', () => {
|
|
23
25
|
// wagerJson
|
24
26
|
// ))
|
25
27
|
// });
|
28
|
+
|
26
29
|
// it('execute interfaces no extends', () => {
|
27
30
|
// expectCode(createExecuteInterface(
|
28
31
|
// ctx,
|