wasm-ast-types 0.3.0 → 0.3.1
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/utils/types.js +21 -1
- package/main/wasm.vectis.spec.js +17 -2
- package/module/utils/types.js +14 -1
- package/module/wasm.vectis.spec.js +14 -2
- package/package.json +2 -2
package/main/utils/types.js
CHANGED
@@ -191,7 +191,6 @@ var createTypedObjectParams = function createTypedObjectParams(jsonschema) {
|
|
191
191
|
if (Array.isArray(jsonschema.properties[prop].allOf)) {
|
192
192
|
var _jsonschema$required;
|
193
193
|
|
194
|
-
var allOf = JSON.stringify(jsonschema.properties[prop].allOf, null, 2);
|
195
194
|
var isOptional = !((_jsonschema$required = jsonschema.required) !== null && _jsonschema$required !== void 0 && _jsonschema$required.includes(prop));
|
196
195
|
var unionTypes = jsonschema.properties[prop].allOf.map(function (el) {
|
197
196
|
if (el.title) return el.title;
|
@@ -206,6 +205,27 @@ var createTypedObjectParams = function createTypedObjectParams(jsonschema) {
|
|
206
205
|
return t.tsTypeReference(t.identifier(forEmptyNameFix(typ)));
|
207
206
|
}))), isOptional);
|
208
207
|
}
|
208
|
+
} else if (Array.isArray(jsonschema.properties[prop].oneOf)) {
|
209
|
+
var _jsonschema$required2;
|
210
|
+
|
211
|
+
var oneOf = JSON.stringify(jsonschema.properties[prop].oneOf, null, 2);
|
212
|
+
|
213
|
+
var _isOptional = !((_jsonschema$required2 = jsonschema.required) !== null && _jsonschema$required2 !== void 0 && _jsonschema$required2.includes(prop));
|
214
|
+
|
215
|
+
var _unionTypes = jsonschema.properties[prop].oneOf.map(function (el) {
|
216
|
+
if (el.title) return el.title;
|
217
|
+
return el.type;
|
218
|
+
});
|
219
|
+
|
220
|
+
var _uniqUnionTypes = (0, _toConsumableArray2["default"])(new Set(_unionTypes));
|
221
|
+
|
222
|
+
if (_uniqUnionTypes.length === 1) {
|
223
|
+
return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(forEmptyNameFix(_uniqUnionTypes[0])))), _isOptional);
|
224
|
+
} else {
|
225
|
+
return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(t.tsUnionType(_uniqUnionTypes.map(function (typ) {
|
226
|
+
return t.tsTypeReference(t.identifier(forEmptyNameFix(typ)));
|
227
|
+
}))), _isOptional);
|
228
|
+
}
|
209
229
|
}
|
210
230
|
|
211
231
|
try {
|
package/main/wasm.vectis.spec.js
CHANGED
@@ -4,9 +4,15 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
4
4
|
|
5
5
|
var _generator = _interopRequireDefault(require("@babel/generator"));
|
6
6
|
|
7
|
-
var _cosmos_msg_for__empty = _interopRequireDefault(require("./../../../__fixtures__/vectis/cosmos_msg_for__empty.json"));
|
7
|
+
var _cosmos_msg_for__empty = _interopRequireDefault(require("./../../../__fixtures__/vectis/govec/cosmos_msg_for__empty.json"));
|
8
8
|
|
9
|
-
var _execute_msg_for__empty = _interopRequireDefault(require("./../../../__fixtures__/vectis/execute_msg_for__empty.json"));
|
9
|
+
var _execute_msg_for__empty = _interopRequireDefault(require("./../../../__fixtures__/vectis/govec/execute_msg_for__empty.json"));
|
10
|
+
|
11
|
+
var _can_execute_relay_response = _interopRequireDefault(require("./../../../__fixtures__/vectis/govec/can_execute_relay_response.json"));
|
12
|
+
|
13
|
+
var _info_response = _interopRequireDefault(require("./../../../__fixtures__/vectis/govec/info_response.json"));
|
14
|
+
|
15
|
+
var _relay_transaction = _interopRequireDefault(require("./../../../__fixtures__/vectis/govec/relay_transaction.json"));
|
10
16
|
|
11
17
|
var _wasm = require("./wasm");
|
12
18
|
|
@@ -24,6 +30,15 @@ it('cosmos_msg_for__empty', function () {
|
|
24
30
|
it('execute_msg_for__empty', function () {
|
25
31
|
expectCode((0, _wasm.createTypeInterface)(_execute_msg_for__empty["default"]));
|
26
32
|
});
|
33
|
+
it('can_execute_relay_response', function () {
|
34
|
+
expectCode((0, _wasm.createTypeInterface)(_can_execute_relay_response["default"]));
|
35
|
+
});
|
36
|
+
it('info_response', function () {
|
37
|
+
expectCode((0, _wasm.createTypeInterface)(_info_response["default"]));
|
38
|
+
});
|
39
|
+
it('relay_transaction', function () {
|
40
|
+
expectCode((0, _wasm.createTypeInterface)(_relay_transaction["default"]));
|
41
|
+
});
|
27
42
|
it('query classes', function () {
|
28
43
|
expectCode((0, _wasm.createQueryClass)('SG721QueryClient', 'SG721ReadOnlyInstance', _cosmos_msg_for__empty["default"]));
|
29
44
|
});
|
package/module/utils/types.js
CHANGED
@@ -150,7 +150,6 @@ export const createTypedObjectParams = (jsonschema, camelize = true) => {
|
|
150
150
|
}
|
151
151
|
|
152
152
|
if (Array.isArray(jsonschema.properties[prop].allOf)) {
|
153
|
-
const allOf = JSON.stringify(jsonschema.properties[prop].allOf, null, 2);
|
154
153
|
const isOptional = !jsonschema.required?.includes(prop);
|
155
154
|
const unionTypes = jsonschema.properties[prop].allOf.map(el => {
|
156
155
|
if (el.title) return el.title;
|
@@ -158,6 +157,20 @@ export const createTypedObjectParams = (jsonschema, camelize = true) => {
|
|
158
157
|
});
|
159
158
|
const uniqUnionTypes = [...new Set(unionTypes)];
|
160
159
|
|
160
|
+
if (uniqUnionTypes.length === 1) {
|
161
|
+
return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(forEmptyNameFix(uniqUnionTypes[0])))), isOptional);
|
162
|
+
} else {
|
163
|
+
return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(t.tsUnionType(uniqUnionTypes.map(typ => t.tsTypeReference(t.identifier(forEmptyNameFix(typ)))))), isOptional);
|
164
|
+
}
|
165
|
+
} else if (Array.isArray(jsonschema.properties[prop].oneOf)) {
|
166
|
+
const oneOf = JSON.stringify(jsonschema.properties[prop].oneOf, null, 2);
|
167
|
+
const isOptional = !jsonschema.required?.includes(prop);
|
168
|
+
const unionTypes = jsonschema.properties[prop].oneOf.map(el => {
|
169
|
+
if (el.title) return el.title;
|
170
|
+
return el.type;
|
171
|
+
});
|
172
|
+
const uniqUnionTypes = [...new Set(unionTypes)];
|
173
|
+
|
161
174
|
if (uniqUnionTypes.length === 1) {
|
162
175
|
return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(forEmptyNameFix(uniqUnionTypes[0])))), isOptional);
|
163
176
|
} else {
|
@@ -1,6 +1,9 @@
|
|
1
1
|
import generate from '@babel/generator';
|
2
|
-
import cosmos_msg_for__empty from './../../../__fixtures__/vectis/cosmos_msg_for__empty.json';
|
3
|
-
import execute_msg_for__empty from './../../../__fixtures__/vectis/execute_msg_for__empty.json';
|
2
|
+
import cosmos_msg_for__empty from './../../../__fixtures__/vectis/govec/cosmos_msg_for__empty.json';
|
3
|
+
import execute_msg_for__empty from './../../../__fixtures__/vectis/govec/execute_msg_for__empty.json';
|
4
|
+
import can_execute_relay_response from './../../../__fixtures__/vectis/govec/can_execute_relay_response.json';
|
5
|
+
import info_response from './../../../__fixtures__/vectis/govec/info_response.json';
|
6
|
+
import relay_transaction from './../../../__fixtures__/vectis/govec/relay_transaction.json';
|
4
7
|
import { createQueryClass, createExecuteClass, createExecuteInterface, createTypeInterface } from './wasm';
|
5
8
|
|
6
9
|
const expectCode = ast => {
|
@@ -17,6 +20,15 @@ it('cosmos_msg_for__empty', () => {
|
|
17
20
|
it('execute_msg_for__empty', () => {
|
18
21
|
expectCode(createTypeInterface(execute_msg_for__empty));
|
19
22
|
});
|
23
|
+
it('can_execute_relay_response', () => {
|
24
|
+
expectCode(createTypeInterface(can_execute_relay_response));
|
25
|
+
});
|
26
|
+
it('info_response', () => {
|
27
|
+
expectCode(createTypeInterface(info_response));
|
28
|
+
});
|
29
|
+
it('relay_transaction', () => {
|
30
|
+
expectCode(createTypeInterface(relay_transaction));
|
31
|
+
});
|
20
32
|
it('query classes', () => {
|
21
33
|
expectCode(createQueryClass('SG721QueryClient', 'SG721ReadOnlyInstance', cosmos_msg_for__empty));
|
22
34
|
});
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "wasm-ast-types",
|
3
|
-
"version": "0.3.
|
3
|
+
"version": "0.3.1",
|
4
4
|
"description": "CosmWasm TypeScript AST generation",
|
5
5
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
6
6
|
"homepage": "https://github.com/pyramation/cosmwasm-typescript-gen/tree/master/packages/wasm-ast-types#readme",
|
@@ -85,5 +85,5 @@
|
|
85
85
|
"ast-stringify": "0.1.0",
|
86
86
|
"case": "1.6.3"
|
87
87
|
},
|
88
|
-
"gitHead": "
|
88
|
+
"gitHead": "aade6ffc08df51adc9922d4cd813fe8ef5bebfa1"
|
89
89
|
}
|