wasm-ast-types 0.3.0 → 0.3.3
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 +23 -15
- package/main/wasm.js +1 -1
- package/main/wasm.vectis.spec.js +17 -2
- package/module/utils/types.js +16 -11
- package/module/wasm.js +2 -2
- package/module/wasm.vectis.spec.js +14 -2
- package/package.json +27 -27
package/main/utils/types.js
CHANGED
@@ -7,7 +7,7 @@ var _typeof = require("@babel/runtime/helpers/typeof");
|
|
7
7
|
Object.defineProperty(exports, "__esModule", {
|
8
8
|
value: true
|
9
9
|
});
|
10
|
-
exports.getType = exports.getPropertyType = exports.
|
10
|
+
exports.getType = exports.getPropertyType = exports.createTypedObjectParams = void 0;
|
11
11
|
|
12
12
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
13
13
|
|
@@ -23,16 +23,6 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
23
23
|
|
24
24
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(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; }
|
25
25
|
|
26
|
-
var forEmptyNameFix = function forEmptyNameFix(name) {
|
27
|
-
if (name.endsWith('For_Empty')) {
|
28
|
-
return name.replace(/For_Empty$/, '_for_Empty');
|
29
|
-
}
|
30
|
-
|
31
|
-
return name;
|
32
|
-
};
|
33
|
-
|
34
|
-
exports.forEmptyNameFix = forEmptyNameFix;
|
35
|
-
|
36
26
|
var getTypeFromRef = function getTypeFromRef($ref) {
|
37
27
|
switch ($ref) {
|
38
28
|
case '#/definitions/Binary':
|
@@ -182,7 +172,7 @@ var createTypedObjectParams = function createTypedObjectParams(jsonschema) {
|
|
182
172
|
var typedParams = keys.map(function (prop) {
|
183
173
|
if (jsonschema.properties[prop].type === 'object') {
|
184
174
|
if (jsonschema.properties[prop].title) {
|
185
|
-
return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(
|
175
|
+
return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(jsonschema.properties[prop].title))));
|
186
176
|
} else {
|
187
177
|
throw new Error('createTypedObjectParams() contact maintainer');
|
188
178
|
}
|
@@ -191,7 +181,6 @@ var createTypedObjectParams = function createTypedObjectParams(jsonschema) {
|
|
191
181
|
if (Array.isArray(jsonschema.properties[prop].allOf)) {
|
192
182
|
var _jsonschema$required;
|
193
183
|
|
194
|
-
var allOf = JSON.stringify(jsonschema.properties[prop].allOf, null, 2);
|
195
184
|
var isOptional = !((_jsonschema$required = jsonschema.required) !== null && _jsonschema$required !== void 0 && _jsonschema$required.includes(prop));
|
196
185
|
var unionTypes = jsonschema.properties[prop].allOf.map(function (el) {
|
197
186
|
if (el.title) return el.title;
|
@@ -200,12 +189,31 @@ var createTypedObjectParams = function createTypedObjectParams(jsonschema) {
|
|
200
189
|
var uniqUnionTypes = (0, _toConsumableArray2["default"])(new Set(unionTypes));
|
201
190
|
|
202
191
|
if (uniqUnionTypes.length === 1) {
|
203
|
-
return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(
|
192
|
+
return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(uniqUnionTypes[0]))), isOptional);
|
204
193
|
} else {
|
205
194
|
return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(t.tsUnionType(uniqUnionTypes.map(function (typ) {
|
206
|
-
return t.tsTypeReference(t.identifier(
|
195
|
+
return t.tsTypeReference(t.identifier(typ));
|
207
196
|
}))), isOptional);
|
208
197
|
}
|
198
|
+
} else if (Array.isArray(jsonschema.properties[prop].oneOf)) {
|
199
|
+
var _jsonschema$required2;
|
200
|
+
|
201
|
+
var _isOptional = !((_jsonschema$required2 = jsonschema.required) !== null && _jsonschema$required2 !== void 0 && _jsonschema$required2.includes(prop));
|
202
|
+
|
203
|
+
var _unionTypes = jsonschema.properties[prop].oneOf.map(function (el) {
|
204
|
+
if (el.title) return el.title;
|
205
|
+
return el.type;
|
206
|
+
});
|
207
|
+
|
208
|
+
var _uniqUnionTypes = (0, _toConsumableArray2["default"])(new Set(_unionTypes));
|
209
|
+
|
210
|
+
if (_uniqUnionTypes.length === 1) {
|
211
|
+
return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(_uniqUnionTypes[0]))), _isOptional);
|
212
|
+
} else {
|
213
|
+
return (0, _babel.propertySignature)(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(t.tsUnionType(_uniqUnionTypes.map(function (typ) {
|
214
|
+
return t.tsTypeReference(t.identifier(typ));
|
215
|
+
}))), _isOptional);
|
216
|
+
}
|
209
217
|
}
|
210
218
|
|
211
219
|
try {
|
package/main/wasm.js
CHANGED
@@ -163,7 +163,7 @@ var createTypeOrInterface = function createTypeOrInterface(Type, jsonschema) {
|
|
163
163
|
|
164
164
|
if (jsonschema.type !== 'object') {
|
165
165
|
if (!jsonschema.type) {
|
166
|
-
return t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(Type), null, t.tsTypeReference(t.identifier(
|
166
|
+
return t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(Type), null, t.tsTypeReference(t.identifier(jsonschema.title))));
|
167
167
|
}
|
168
168
|
|
169
169
|
return t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(Type), null, (0, _types2.getType)(jsonschema.type)));
|
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
@@ -1,13 +1,6 @@
|
|
1
1
|
import * as t from '@babel/types';
|
2
2
|
import { camel } from 'case';
|
3
3
|
import { propertySignature } from './babel';
|
4
|
-
export const forEmptyNameFix = name => {
|
5
|
-
if (name.endsWith('For_Empty')) {
|
6
|
-
return name.replace(/For_Empty$/, '_for_Empty');
|
7
|
-
}
|
8
|
-
|
9
|
-
return name;
|
10
|
-
};
|
11
4
|
|
12
5
|
const getTypeFromRef = $ref => {
|
13
6
|
switch ($ref) {
|
@@ -143,14 +136,13 @@ export const createTypedObjectParams = (jsonschema, camelize = true) => {
|
|
143
136
|
const typedParams = keys.map(prop => {
|
144
137
|
if (jsonschema.properties[prop].type === 'object') {
|
145
138
|
if (jsonschema.properties[prop].title) {
|
146
|
-
return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(
|
139
|
+
return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(jsonschema.properties[prop].title))));
|
147
140
|
} else {
|
148
141
|
throw new Error('createTypedObjectParams() contact maintainer');
|
149
142
|
}
|
150
143
|
}
|
151
144
|
|
152
145
|
if (Array.isArray(jsonschema.properties[prop].allOf)) {
|
153
|
-
const allOf = JSON.stringify(jsonschema.properties[prop].allOf, null, 2);
|
154
146
|
const isOptional = !jsonschema.required?.includes(prop);
|
155
147
|
const unionTypes = jsonschema.properties[prop].allOf.map(el => {
|
156
148
|
if (el.title) return el.title;
|
@@ -159,9 +151,22 @@ export const createTypedObjectParams = (jsonschema, camelize = true) => {
|
|
159
151
|
const uniqUnionTypes = [...new Set(unionTypes)];
|
160
152
|
|
161
153
|
if (uniqUnionTypes.length === 1) {
|
162
|
-
return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(
|
154
|
+
return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(uniqUnionTypes[0]))), isOptional);
|
155
|
+
} else {
|
156
|
+
return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(t.tsUnionType(uniqUnionTypes.map(typ => t.tsTypeReference(t.identifier(typ))))), isOptional);
|
157
|
+
}
|
158
|
+
} else if (Array.isArray(jsonschema.properties[prop].oneOf)) {
|
159
|
+
const isOptional = !jsonschema.required?.includes(prop);
|
160
|
+
const unionTypes = jsonschema.properties[prop].oneOf.map(el => {
|
161
|
+
if (el.title) return el.title;
|
162
|
+
return el.type;
|
163
|
+
});
|
164
|
+
const uniqUnionTypes = [...new Set(unionTypes)];
|
165
|
+
|
166
|
+
if (uniqUnionTypes.length === 1) {
|
167
|
+
return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(uniqUnionTypes[0]))), isOptional);
|
163
168
|
} else {
|
164
|
-
return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(t.tsUnionType(uniqUnionTypes.map(typ => t.tsTypeReference(t.identifier(
|
169
|
+
return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(t.tsUnionType(uniqUnionTypes.map(typ => t.tsTypeReference(t.identifier(typ))))), isOptional);
|
165
170
|
}
|
166
171
|
}
|
167
172
|
|
package/module/wasm.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import * as t from '@babel/types';
|
2
2
|
import { camel, pascal } from 'case';
|
3
3
|
import { bindMethod, typedIdentifier, promiseTypeAnnotation, classDeclaration, classProperty, arrowFunctionExpression, getMessageProperties } from './utils';
|
4
|
-
import { getPropertyType, getType, createTypedObjectParams
|
4
|
+
import { getPropertyType, getType, createTypedObjectParams } from './utils/types';
|
5
5
|
import { identifier, tsTypeOperator, propertySignature } from './utils/babel';
|
6
6
|
export const createWasmQueryMethod = jsonschema => {
|
7
7
|
const underscoreName = Object.keys(jsonschema.properties)[0];
|
@@ -103,7 +103,7 @@ export const createQueryInterface = (className, queryMsg) => {
|
|
103
103
|
export const createTypeOrInterface = (Type, jsonschema) => {
|
104
104
|
if (jsonschema.type !== 'object') {
|
105
105
|
if (!jsonschema.type) {
|
106
|
-
return t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(Type), null, t.tsTypeReference(t.identifier(
|
106
|
+
return t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(Type), null, t.tsTypeReference(t.identifier(jsonschema.title))));
|
107
107
|
}
|
108
108
|
|
109
109
|
return t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(Type), null, getType(jsonschema.type)));
|
@@ -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.3",
|
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",
|
@@ -42,48 +42,48 @@
|
|
42
42
|
},
|
43
43
|
"repository": {
|
44
44
|
"type": "git",
|
45
|
-
"url": "https://github.com/pyramation/cosmwasm-typescript-gen
|
45
|
+
"url": "https://github.com/pyramation/cosmwasm-typescript-gen"
|
46
46
|
},
|
47
47
|
"keywords": [],
|
48
48
|
"bugs": {
|
49
|
-
"url": "https://github.com/pyramation/cosmwasm-typescript-gen/
|
49
|
+
"url": "https://github.com/pyramation/cosmwasm-typescript-gen/issues"
|
50
50
|
},
|
51
51
|
"devDependencies": {
|
52
|
-
"@babel/cli": "7.17.
|
53
|
-
"@babel/core": "7.
|
54
|
-
"@babel/eslint-parser": "^7.
|
55
|
-
"@babel/generator": "7.
|
56
|
-
"@babel/node": "^7.
|
57
|
-
"@babel/parser": "^7.
|
58
|
-
"@babel/plugin-proposal-class-properties": "7.
|
59
|
-
"@babel/plugin-proposal-export-default-from": "7.
|
60
|
-
"@babel/plugin-proposal-object-rest-spread": "7.
|
61
|
-
"@babel/plugin-transform-runtime": "7.
|
62
|
-
"@babel/preset-env": "7.
|
63
|
-
"@babel/preset-typescript": "^7.
|
64
|
-
"@babel/traverse": "7.
|
65
|
-
"@types/jest": "^
|
52
|
+
"@babel/cli": "7.17.10",
|
53
|
+
"@babel/core": "7.18.5",
|
54
|
+
"@babel/eslint-parser": "^7.18.2",
|
55
|
+
"@babel/generator": "7.18.2",
|
56
|
+
"@babel/node": "^7.18.5",
|
57
|
+
"@babel/parser": "^7.18.5",
|
58
|
+
"@babel/plugin-proposal-class-properties": "7.17.12",
|
59
|
+
"@babel/plugin-proposal-export-default-from": "7.17.12",
|
60
|
+
"@babel/plugin-proposal-object-rest-spread": "7.18.0",
|
61
|
+
"@babel/plugin-transform-runtime": "7.18.5",
|
62
|
+
"@babel/preset-env": "7.18.2",
|
63
|
+
"@babel/preset-typescript": "^7.17.12",
|
64
|
+
"@babel/traverse": "7.18.5",
|
65
|
+
"@types/jest": "^28.1.2",
|
66
66
|
"babel-core": "7.0.0-bridge.0",
|
67
|
-
"babel-jest": "
|
67
|
+
"babel-jest": "28.1.1",
|
68
68
|
"babel-watch": "^7.0.0",
|
69
69
|
"cross-env": "^7.0.2",
|
70
|
-
"eslint": "8.
|
70
|
+
"eslint": "8.17.0",
|
71
71
|
"eslint-config-prettier": "^8.5.0",
|
72
72
|
"eslint-plugin-prettier": "^4.0.0",
|
73
|
-
"glob": "
|
74
|
-
"jest": "^
|
73
|
+
"glob": "8.0.3",
|
74
|
+
"jest": "^28.1.1",
|
75
75
|
"jest-in-case": "^1.0.2",
|
76
76
|
"mkdirp": "1.0.4",
|
77
|
-
"prettier": "^2.
|
77
|
+
"prettier": "^2.7.1",
|
78
78
|
"regenerator-runtime": "^0.13.7",
|
79
|
-
"ts-jest": "^
|
80
|
-
"typescript": "^4.
|
79
|
+
"ts-jest": "^28.0.5",
|
80
|
+
"typescript": "^4.7.4"
|
81
81
|
},
|
82
82
|
"dependencies": {
|
83
|
-
"@babel/runtime": "^7.
|
84
|
-
"@babel/types": "7.
|
83
|
+
"@babel/runtime": "^7.18.3",
|
84
|
+
"@babel/types": "7.18.4",
|
85
85
|
"ast-stringify": "0.1.0",
|
86
86
|
"case": "1.6.3"
|
87
87
|
},
|
88
|
-
"gitHead": "
|
88
|
+
"gitHead": "9d21c3edc37a05d3c4329ee286b92e59f9383b28"
|
89
89
|
}
|