wasm-ast-types 0.0.12 → 0.1.2
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/wasm.js +19 -20
- package/module/wasm.js +13 -14
- package/package.json +2 -2
package/main/wasm.js
CHANGED
@@ -23,6 +23,13 @@ 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 getMessageProperties = function getMessageProperties(msg) {
|
27
|
+
if (msg.anyOf) return msg.anyOf;
|
28
|
+
if (msg.oneOf) return msg.oneOf;
|
29
|
+
if (msg.allOf) return msg.allOf;
|
30
|
+
return [];
|
31
|
+
};
|
32
|
+
|
26
33
|
var getTypeFromRef = function getTypeFromRef($ref) {
|
27
34
|
switch ($ref) {
|
28
35
|
case '#/definitions/Binary':
|
@@ -142,14 +149,6 @@ var getPropertyType = function getPropertyType(schema, prop) {
|
|
142
149
|
};
|
143
150
|
};
|
144
151
|
|
145
|
-
var getProperty = function getProperty(schema, prop) {
|
146
|
-
var _getPropertyType = getPropertyType(schema, prop),
|
147
|
-
type = _getPropertyType.type,
|
148
|
-
optional = _getPropertyType.optional;
|
149
|
-
|
150
|
-
return (0, _utils.typedIdentifier)((0, _case.camel)(prop), t.tsTypeAnnotation(type), optional);
|
151
|
-
};
|
152
|
-
|
153
152
|
var createWasmQueryMethod = function createWasmQueryMethod(jsonschema) {
|
154
153
|
var _jsonschema$propertie;
|
155
154
|
|
@@ -168,13 +167,13 @@ var createWasmQueryMethod = function createWasmQueryMethod(jsonschema) {
|
|
168
167
|
exports.createWasmQueryMethod = createWasmQueryMethod;
|
169
168
|
|
170
169
|
var createQueryClass = function createQueryClass(className, implementsClassName, queryMsg) {
|
171
|
-
var propertyNames = queryMsg.
|
170
|
+
var propertyNames = getMessageProperties(queryMsg).map(function (method) {
|
172
171
|
var _Object$keys;
|
173
172
|
|
174
173
|
return (_Object$keys = Object.keys(method.properties)) === null || _Object$keys === void 0 ? void 0 : _Object$keys[0];
|
175
174
|
}).filter(Boolean);
|
176
175
|
var bindings = propertyNames.map(_case.camel).map(_utils.bindMethod);
|
177
|
-
var methods = queryMsg.
|
176
|
+
var methods = getMessageProperties(queryMsg).map(function (schema) {
|
178
177
|
return createWasmQueryMethod(schema);
|
179
178
|
});
|
180
179
|
return t.exportNamedDeclaration((0, _utils.classDeclaration)(className, [// client
|
@@ -204,13 +203,13 @@ var createWasmExecMethod = function createWasmExecMethod(jsonschema) {
|
|
204
203
|
exports.createWasmExecMethod = createWasmExecMethod;
|
205
204
|
|
206
205
|
var createExecuteClass = function createExecuteClass(className, implementsClassName, extendsClassName, execMsg) {
|
207
|
-
var propertyNames = execMsg.
|
206
|
+
var propertyNames = getMessageProperties(execMsg).map(function (method) {
|
208
207
|
var _Object$keys2;
|
209
208
|
|
210
209
|
return (_Object$keys2 = Object.keys(method.properties)) === null || _Object$keys2 === void 0 ? void 0 : _Object$keys2[0];
|
211
210
|
}).filter(Boolean);
|
212
211
|
var bindings = propertyNames.map(_case.camel).map(_utils.bindMethod);
|
213
|
-
var methods = execMsg.
|
212
|
+
var methods = getMessageProperties(execMsg).map(function (schema) {
|
214
213
|
return createWasmExecMethod(schema);
|
215
214
|
});
|
216
215
|
var blockStmt = [];
|
@@ -232,7 +231,7 @@ var createExecuteClass = function createExecuteClass(className, implementsClassN
|
|
232
231
|
exports.createExecuteClass = createExecuteClass;
|
233
232
|
|
234
233
|
var createExecuteInterface = function createExecuteInterface(className, extendsClassName, execMsg) {
|
235
|
-
var methods = execMsg.
|
234
|
+
var methods = getMessageProperties(execMsg).map(function (jsonschema) {
|
236
235
|
var underscoreName = Object.keys(jsonschema.properties)[0];
|
237
236
|
var methodName = (0, _case.camel)(underscoreName);
|
238
237
|
return createPropertyFunctionWithObjectParams(methodName, 'ExecuteResult', jsonschema.properties[underscoreName]);
|
@@ -272,9 +271,9 @@ var createTypedObjectParams = function createTypedObjectParams(jsonschema) {
|
|
272
271
|
var keys = Object.keys((_jsonschema$propertie3 = jsonschema.properties) !== null && _jsonschema$propertie3 !== void 0 ? _jsonschema$propertie3 : {});
|
273
272
|
if (!keys.length) return;
|
274
273
|
var typedParams = keys.map(function (prop) {
|
275
|
-
var
|
276
|
-
type =
|
277
|
-
optional =
|
274
|
+
var _getPropertyType = getPropertyType(jsonschema, prop),
|
275
|
+
type = _getPropertyType.type,
|
276
|
+
optional = _getPropertyType.optional;
|
278
277
|
|
279
278
|
return propertySignature(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(type), optional);
|
280
279
|
});
|
@@ -301,7 +300,7 @@ var createPropertyFunctionWithObjectParams = function createPropertyFunctionWith
|
|
301
300
|
exports.createPropertyFunctionWithObjectParams = createPropertyFunctionWithObjectParams;
|
302
301
|
|
303
302
|
var createQueryInterface = function createQueryInterface(className, queryMsg) {
|
304
|
-
var methods = queryMsg.
|
303
|
+
var methods = getMessageProperties(queryMsg).map(function (jsonschema) {
|
305
304
|
var underscoreName = Object.keys(jsonschema.properties)[0];
|
306
305
|
var methodName = (0, _case.camel)(underscoreName);
|
307
306
|
var responseType = (0, _case.pascal)("".concat(methodName, "Response"));
|
@@ -321,9 +320,9 @@ var createTypeOrInterface = function createTypeOrInterface(Type, jsonschema) {
|
|
321
320
|
}
|
322
321
|
|
323
322
|
var props = Object.keys((_jsonschema$propertie4 = jsonschema.properties) !== null && _jsonschema$propertie4 !== void 0 ? _jsonschema$propertie4 : {}).map(function (prop) {
|
324
|
-
var
|
325
|
-
type =
|
326
|
-
optional =
|
323
|
+
var _getPropertyType2 = getPropertyType(jsonschema, prop),
|
324
|
+
type = _getPropertyType2.type,
|
325
|
+
optional = _getPropertyType2.optional;
|
327
326
|
|
328
327
|
return propertySignature((0, _case.camel)(prop), t.tsTypeAnnotation(type), optional);
|
329
328
|
});
|
package/module/wasm.js
CHANGED
@@ -2,6 +2,13 @@ import * as t from '@babel/types';
|
|
2
2
|
import { camel, pascal } from 'case';
|
3
3
|
import { bindMethod, typedIdentifier, promiseTypeAnnotation, classDeclaration, classProperty, arrowFunctionExpression } from './utils';
|
4
4
|
|
5
|
+
const getMessageProperties = msg => {
|
6
|
+
if (msg.anyOf) return msg.anyOf;
|
7
|
+
if (msg.oneOf) return msg.oneOf;
|
8
|
+
if (msg.allOf) return msg.allOf;
|
9
|
+
return [];
|
10
|
+
};
|
11
|
+
|
5
12
|
const getTypeFromRef = $ref => {
|
6
13
|
switch ($ref) {
|
7
14
|
case '#/definitions/Binary':
|
@@ -115,14 +122,6 @@ const getPropertyType = (schema, prop) => {
|
|
115
122
|
};
|
116
123
|
};
|
117
124
|
|
118
|
-
const getProperty = (schema, prop) => {
|
119
|
-
const {
|
120
|
-
type,
|
121
|
-
optional
|
122
|
-
} = getPropertyType(schema, prop);
|
123
|
-
return typedIdentifier(camel(prop), t.tsTypeAnnotation(type), optional);
|
124
|
-
};
|
125
|
-
|
126
125
|
export const createWasmQueryMethod = jsonschema => {
|
127
126
|
const underscoreName = Object.keys(jsonschema.properties)[0];
|
128
127
|
const methodName = camel(underscoreName);
|
@@ -136,9 +135,9 @@ export const createWasmQueryMethod = jsonschema => {
|
|
136
135
|
return t.classProperty(t.identifier(methodName), arrowFunctionExpression(obj ? [obj] : [], 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([actionArg])]))]), t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Promise'), t.tsTypeParameterInstantiation([t.tSTypeReference(t.identifier(responseType))]))), true));
|
137
136
|
};
|
138
137
|
export const createQueryClass = (className, implementsClassName, queryMsg) => {
|
139
|
-
const propertyNames = queryMsg.
|
138
|
+
const propertyNames = getMessageProperties(queryMsg).map(method => Object.keys(method.properties)?.[0]).filter(Boolean);
|
140
139
|
const bindings = propertyNames.map(camel).map(bindMethod);
|
141
|
-
const methods = queryMsg.
|
140
|
+
const methods = getMessageProperties(queryMsg).map(schema => {
|
142
141
|
return createWasmQueryMethod(schema);
|
143
142
|
});
|
144
143
|
return t.exportNamedDeclaration(classDeclaration(className, [// client
|
@@ -160,9 +159,9 @@ export const createWasmExecMethod = jsonschema => {
|
|
160
159
|
t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Promise'), t.tsTypeParameterInstantiation([t.tSTypeReference(t.identifier('ExecuteResult'))]))), true));
|
161
160
|
};
|
162
161
|
export const createExecuteClass = (className, implementsClassName, extendsClassName, execMsg) => {
|
163
|
-
const propertyNames = execMsg.
|
162
|
+
const propertyNames = getMessageProperties(execMsg).map(method => Object.keys(method.properties)?.[0]).filter(Boolean);
|
164
163
|
const bindings = propertyNames.map(camel).map(bindMethod);
|
165
|
-
const methods = execMsg.
|
164
|
+
const methods = getMessageProperties(execMsg).map(schema => {
|
166
165
|
return createWasmExecMethod(schema);
|
167
166
|
});
|
168
167
|
const blockStmt = [];
|
@@ -181,7 +180,7 @@ export const createExecuteClass = (className, implementsClassName, extendsClassN
|
|
181
180
|
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));
|
182
181
|
};
|
183
182
|
export const createExecuteInterface = (className, extendsClassName, execMsg) => {
|
184
|
-
const methods = execMsg.
|
183
|
+
const methods = getMessageProperties(execMsg).map(jsonschema => {
|
185
184
|
const underscoreName = Object.keys(jsonschema.properties)[0];
|
186
185
|
const methodName = camel(underscoreName);
|
187
186
|
return createPropertyFunctionWithObjectParams(methodName, 'ExecuteResult', jsonschema.properties[underscoreName]);
|
@@ -234,7 +233,7 @@ export const createPropertyFunctionWithObjectParams = (methodName, responseType,
|
|
234
233
|
return t.tSPropertySignature(t.identifier(methodName), t.tsTypeAnnotation(func));
|
235
234
|
};
|
236
235
|
export const createQueryInterface = (className, queryMsg) => {
|
237
|
-
const methods = queryMsg.
|
236
|
+
const methods = getMessageProperties(queryMsg).map(jsonschema => {
|
238
237
|
const underscoreName = Object.keys(jsonschema.properties)[0];
|
239
238
|
const methodName = camel(underscoreName);
|
240
239
|
const responseType = pascal(`${methodName}Response`);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "wasm-ast-types",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.1.2",
|
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": "7d83e56b361314f823c9b903b267156036377457"
|
89
89
|
}
|