wasm-ast-types 0.1.0 → 0.1.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/wasm.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.propertySignature = exports.createWasmQueryMethod = exports.createWasmExecMethod = exports.createTypedObjectParams = exports.createTypeOrInterface = exports.createTypeInterface = exports.createQueryInterface = exports.createQueryClass = exports.createPropertyFunctionWithObjectParams = exports.createExecuteInterface = exports.createExecuteClass = void 0;
10
+ exports.propertySignature = exports.getMessageProperties = exports.createWasmQueryMethod = exports.createWasmExecMethod = exports.createTypedObjectParams = exports.createTypeOrInterface = exports.createTypeInterface = exports.createQueryInterface = exports.createQueryClass = exports.createPropertyFunctionWithObjectParams = exports.createExecuteInterface = exports.createExecuteClass = void 0;
11
11
 
12
12
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
13
13
 
@@ -23,6 +23,15 @@ 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
+
33
+ exports.getMessageProperties = getMessageProperties;
34
+
26
35
  var getTypeFromRef = function getTypeFromRef($ref) {
27
36
  switch ($ref) {
28
37
  case '#/definitions/Binary':
@@ -142,14 +151,6 @@ var getPropertyType = function getPropertyType(schema, prop) {
142
151
  };
143
152
  };
144
153
 
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
154
  var createWasmQueryMethod = function createWasmQueryMethod(jsonschema) {
154
155
  var _jsonschema$propertie;
155
156
 
@@ -168,13 +169,13 @@ var createWasmQueryMethod = function createWasmQueryMethod(jsonschema) {
168
169
  exports.createWasmQueryMethod = createWasmQueryMethod;
169
170
 
170
171
  var createQueryClass = function createQueryClass(className, implementsClassName, queryMsg) {
171
- var propertyNames = queryMsg.oneOf.map(function (method) {
172
+ var propertyNames = getMessageProperties(queryMsg).map(function (method) {
172
173
  var _Object$keys;
173
174
 
174
175
  return (_Object$keys = Object.keys(method.properties)) === null || _Object$keys === void 0 ? void 0 : _Object$keys[0];
175
176
  }).filter(Boolean);
176
177
  var bindings = propertyNames.map(_case.camel).map(_utils.bindMethod);
177
- var methods = queryMsg.oneOf.map(function (schema) {
178
+ var methods = getMessageProperties(queryMsg).map(function (schema) {
178
179
  return createWasmQueryMethod(schema);
179
180
  });
180
181
  return t.exportNamedDeclaration((0, _utils.classDeclaration)(className, [// client
@@ -204,13 +205,13 @@ var createWasmExecMethod = function createWasmExecMethod(jsonschema) {
204
205
  exports.createWasmExecMethod = createWasmExecMethod;
205
206
 
206
207
  var createExecuteClass = function createExecuteClass(className, implementsClassName, extendsClassName, execMsg) {
207
- var propertyNames = execMsg.oneOf.map(function (method) {
208
+ var propertyNames = getMessageProperties(execMsg).map(function (method) {
208
209
  var _Object$keys2;
209
210
 
210
211
  return (_Object$keys2 = Object.keys(method.properties)) === null || _Object$keys2 === void 0 ? void 0 : _Object$keys2[0];
211
212
  }).filter(Boolean);
212
213
  var bindings = propertyNames.map(_case.camel).map(_utils.bindMethod);
213
- var methods = execMsg.oneOf.map(function (schema) {
214
+ var methods = getMessageProperties(execMsg).map(function (schema) {
214
215
  return createWasmExecMethod(schema);
215
216
  });
216
217
  var blockStmt = [];
@@ -232,7 +233,7 @@ var createExecuteClass = function createExecuteClass(className, implementsClassN
232
233
  exports.createExecuteClass = createExecuteClass;
233
234
 
234
235
  var createExecuteInterface = function createExecuteInterface(className, extendsClassName, execMsg) {
235
- var methods = execMsg.oneOf.map(function (jsonschema) {
236
+ var methods = getMessageProperties(execMsg).map(function (jsonschema) {
236
237
  var underscoreName = Object.keys(jsonschema.properties)[0];
237
238
  var methodName = (0, _case.camel)(underscoreName);
238
239
  return createPropertyFunctionWithObjectParams(methodName, 'ExecuteResult', jsonschema.properties[underscoreName]);
@@ -272,9 +273,9 @@ var createTypedObjectParams = function createTypedObjectParams(jsonschema) {
272
273
  var keys = Object.keys((_jsonschema$propertie3 = jsonschema.properties) !== null && _jsonschema$propertie3 !== void 0 ? _jsonschema$propertie3 : {});
273
274
  if (!keys.length) return;
274
275
  var typedParams = keys.map(function (prop) {
275
- var _getPropertyType2 = getPropertyType(jsonschema, prop),
276
- type = _getPropertyType2.type,
277
- optional = _getPropertyType2.optional;
276
+ var _getPropertyType = getPropertyType(jsonschema, prop),
277
+ type = _getPropertyType.type,
278
+ optional = _getPropertyType.optional;
278
279
 
279
280
  return propertySignature(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(type), optional);
280
281
  });
@@ -301,7 +302,7 @@ var createPropertyFunctionWithObjectParams = function createPropertyFunctionWith
301
302
  exports.createPropertyFunctionWithObjectParams = createPropertyFunctionWithObjectParams;
302
303
 
303
304
  var createQueryInterface = function createQueryInterface(className, queryMsg) {
304
- var methods = queryMsg.oneOf.map(function (jsonschema) {
305
+ var methods = getMessageProperties(queryMsg).map(function (jsonschema) {
305
306
  var underscoreName = Object.keys(jsonschema.properties)[0];
306
307
  var methodName = (0, _case.camel)(underscoreName);
307
308
  var responseType = (0, _case.pascal)("".concat(methodName, "Response"));
@@ -321,9 +322,9 @@ var createTypeOrInterface = function createTypeOrInterface(Type, jsonschema) {
321
322
  }
322
323
 
323
324
  var props = Object.keys((_jsonschema$propertie4 = jsonschema.properties) !== null && _jsonschema$propertie4 !== void 0 ? _jsonschema$propertie4 : {}).map(function (prop) {
324
- var _getPropertyType3 = getPropertyType(jsonschema, prop),
325
- type = _getPropertyType3.type,
326
- optional = _getPropertyType3.optional;
325
+ var _getPropertyType2 = getPropertyType(jsonschema, prop),
326
+ type = _getPropertyType2.type,
327
+ optional = _getPropertyType2.optional;
327
328
 
328
329
  return propertySignature((0, _case.camel)(prop), t.tsTypeAnnotation(type), optional);
329
330
  });
package/module/wasm.js CHANGED
@@ -1,6 +1,12 @@
1
1
  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
+ export const getMessageProperties = msg => {
5
+ if (msg.anyOf) return msg.anyOf;
6
+ if (msg.oneOf) return msg.oneOf;
7
+ if (msg.allOf) return msg.allOf;
8
+ return [];
9
+ };
4
10
 
5
11
  const getTypeFromRef = $ref => {
6
12
  switch ($ref) {
@@ -115,14 +121,6 @@ const getPropertyType = (schema, prop) => {
115
121
  };
116
122
  };
117
123
 
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
124
  export const createWasmQueryMethod = jsonschema => {
127
125
  const underscoreName = Object.keys(jsonschema.properties)[0];
128
126
  const methodName = camel(underscoreName);
@@ -136,9 +134,9 @@ export const createWasmQueryMethod = jsonschema => {
136
134
  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
135
  };
138
136
  export const createQueryClass = (className, implementsClassName, queryMsg) => {
139
- const propertyNames = queryMsg.oneOf.map(method => Object.keys(method.properties)?.[0]).filter(Boolean);
137
+ const propertyNames = getMessageProperties(queryMsg).map(method => Object.keys(method.properties)?.[0]).filter(Boolean);
140
138
  const bindings = propertyNames.map(camel).map(bindMethod);
141
- const methods = queryMsg.oneOf.map(schema => {
139
+ const methods = getMessageProperties(queryMsg).map(schema => {
142
140
  return createWasmQueryMethod(schema);
143
141
  });
144
142
  return t.exportNamedDeclaration(classDeclaration(className, [// client
@@ -160,9 +158,9 @@ export const createWasmExecMethod = jsonschema => {
160
158
  t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Promise'), t.tsTypeParameterInstantiation([t.tSTypeReference(t.identifier('ExecuteResult'))]))), true));
161
159
  };
162
160
  export const createExecuteClass = (className, implementsClassName, extendsClassName, execMsg) => {
163
- const propertyNames = execMsg.oneOf.map(method => Object.keys(method.properties)?.[0]).filter(Boolean);
161
+ const propertyNames = getMessageProperties(execMsg).map(method => Object.keys(method.properties)?.[0]).filter(Boolean);
164
162
  const bindings = propertyNames.map(camel).map(bindMethod);
165
- const methods = execMsg.oneOf.map(schema => {
163
+ const methods = getMessageProperties(execMsg).map(schema => {
166
164
  return createWasmExecMethod(schema);
167
165
  });
168
166
  const blockStmt = [];
@@ -181,7 +179,7 @@ export const createExecuteClass = (className, implementsClassName, extendsClassN
181
179
  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
180
  };
183
181
  export const createExecuteInterface = (className, extendsClassName, execMsg) => {
184
- const methods = execMsg.oneOf.map(jsonschema => {
182
+ const methods = getMessageProperties(execMsg).map(jsonschema => {
185
183
  const underscoreName = Object.keys(jsonschema.properties)[0];
186
184
  const methodName = camel(underscoreName);
187
185
  return createPropertyFunctionWithObjectParams(methodName, 'ExecuteResult', jsonschema.properties[underscoreName]);
@@ -234,7 +232,7 @@ export const createPropertyFunctionWithObjectParams = (methodName, responseType,
234
232
  return t.tSPropertySignature(t.identifier(methodName), t.tsTypeAnnotation(func));
235
233
  };
236
234
  export const createQueryInterface = (className, queryMsg) => {
237
- const methods = queryMsg.oneOf.map(jsonschema => {
235
+ const methods = getMessageProperties(queryMsg).map(jsonschema => {
238
236
  const underscoreName = Object.keys(jsonschema.properties)[0];
239
237
  const methodName = camel(underscoreName);
240
238
  const responseType = pascal(`${methodName}Response`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wasm-ast-types",
3
- "version": "0.1.0",
3
+ "version": "0.1.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",
@@ -85,5 +85,5 @@
85
85
  "ast-stringify": "0.1.0",
86
86
  "case": "1.6.3"
87
87
  },
88
- "gitHead": "3073018a9061dbbabb5c7c417b5de5a1c754cc0d"
88
+ "gitHead": "6820d1185529bc0a4f67743d69a0cfe087c57eb7"
89
89
  }
package/types/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
- export * from './types';
2
1
  export * from './utils';
3
2
  export * from './wasm';
package/types/utils.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import * as t from '@babel/types';
2
- import { Field } from './types';
3
2
  import { TSTypeAnnotation, TSExpressionWithTypeArguments } from '@babel/types';
4
3
  export declare const bindMethod: (name: string) => t.ExpressionStatement;
5
4
  export declare const typedIdentifier: (name: string, typeAnnotation: TSTypeAnnotation, optional?: boolean) => t.Identifier;
@@ -21,9 +20,9 @@ export declare const shorthandProperty: (prop: string) => t.ObjectProperty;
21
20
  export declare const importStmt: (names: string[], path: string) => t.ImportDeclaration;
22
21
  export declare const importAminoMsg: () => t.ImportDeclaration;
23
22
  export declare const getFieldDimensionality: (field: Field) => {
24
- typeName: string;
23
+ typeName: any;
25
24
  dimensions: number;
26
- isArray: boolean;
25
+ isArray: any;
27
26
  };
28
27
  export declare const memberExpressionOrIdentifier: (names: any) => any;
29
28
  export declare const memberExpressionOrIdentifierSnake: (names: any) => any;
package/types/wasm.d.ts CHANGED
@@ -2,20 +2,32 @@ import * as t from '@babel/types';
2
2
  interface QueryMsg {
3
3
  $schema: string;
4
4
  title: "QueryMsg";
5
- oneOf: any;
5
+ oneOf?: any;
6
+ allOf?: any;
7
+ anyOf?: any;
6
8
  }
7
9
  interface ExecuteMsg {
8
10
  $schema: string;
9
11
  title: "ExecuteMsg" | "ExecuteMsg_for_Empty";
10
- oneOf: any;
12
+ oneOf?: any;
13
+ allOf?: any;
14
+ anyOf?: any;
11
15
  }
16
+ export declare const getMessageProperties: (msg: QueryMsg | ExecuteMsg) => any;
12
17
  export declare const createWasmQueryMethod: (jsonschema: any) => t.ClassProperty;
13
18
  export declare const createQueryClass: (className: string, implementsClassName: string, queryMsg: QueryMsg) => t.ExportNamedDeclaration;
14
19
  export declare const createWasmExecMethod: (jsonschema: any) => t.ClassProperty;
15
20
  export declare const createExecuteClass: (className: string, implementsClassName: string, extendsClassName: string, execMsg: ExecuteMsg) => t.ExportNamedDeclaration;
16
- export declare const createExecuteInterface: (className: string, extendsClassName: string, execMsg: ExecuteMsg) => t.ExportNamedDeclaration;
21
+ export declare const createExecuteInterface: (className: string, extendsClassName: string | null, execMsg: ExecuteMsg) => t.ExportNamedDeclaration;
22
+ export declare const propertySignature: (name: string, typeAnnotation: t.TSTypeAnnotation, optional?: boolean) => {
23
+ type: string;
24
+ key: t.Identifier;
25
+ typeAnnotation: t.TSTypeAnnotation;
26
+ optional: boolean;
27
+ };
28
+ export declare const createTypedObjectParams: (jsonschema: any, camelize?: boolean) => t.ObjectPattern;
29
+ export declare const createPropertyFunctionWithObjectParams: (methodName: string, responseType: string, jsonschema: any) => t.TSPropertySignature;
17
30
  export declare const createQueryInterface: (className: string, queryMsg: QueryMsg) => t.ExportNamedDeclaration;
18
- export declare const propertySignature: (name: string, typeAnnotation: t.TSTypeAnnotation, optional?: boolean) => t.TSPropertySignature;
19
31
  export declare const createTypeOrInterface: (Type: string, jsonschema: any) => t.ExportNamedDeclaration;
20
32
  export declare const createTypeInterface: (jsonschema: any) => t.ExportNamedDeclaration;
21
33
  export {};