wasm-ast-types 0.0.6 → 0.0.9

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/index.js CHANGED
@@ -4,19 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
 
7
- var _types = require("./types");
8
-
9
- Object.keys(_types).forEach(function (key) {
10
- if (key === "default" || key === "__esModule") return;
11
- if (key in exports && exports[key] === _types[key]) return;
12
- Object.defineProperty(exports, key, {
13
- enumerable: true,
14
- get: function get() {
15
- return _types[key];
16
- }
17
- });
18
- });
19
-
20
7
  var _utils = require("./utils");
21
8
 
22
9
  Object.keys(_utils).forEach(function (key) {
@@ -103,4 +103,10 @@ it('mutation classes', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PUR
103
103
  }
104
104
  }
105
105
  }, _callee4);
106
- })));
106
+ })));
107
+ it('object parms', function () {
108
+ var obj = t.objectPattern([t.objectProperty(t.identifier('includeExpired'), t.identifier('includeExpired'), false, true), t.objectProperty(t.identifier('tokenId'), t.identifier('tokenId'), false, true)]);
109
+ obj.typeAnnotation = t.tsTypeAnnotation(t.tsTypeLiteral([t.tsPropertySignature(t.identifier('includeExpired'), t.tsTypeAnnotation(t.tsBooleanKeyword())), t.tsPropertySignature(t.identifier('tokenId'), t.tsTypeAnnotation(t.tsStringKeyword()))]));
110
+ expectCode(t.program([t.expressionStatement(t.assignmentExpression('=', t.identifier('ownerOf'), (0, _utils.arrowFunctionExpression)([obj], t.blockStatement([// body
111
+ ], []), t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Promise'), t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier('OwnerOfResponse'))]))))))]));
112
+ });
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.createTypeOrInterface = exports.createTypeInterface = exports.createQueryInterface = exports.createQueryClass = exports.createExecuteInterface = exports.createExecuteClass = void 0;
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;
11
11
 
12
12
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
13
13
 
@@ -152,16 +152,13 @@ var createWasmQueryMethod = function createWasmQueryMethod(jsonschema) {
152
152
  var underscoreName = Object.keys(jsonschema.properties)[0];
153
153
  var methodName = (0, _case.camel)(underscoreName);
154
154
  var responseType = (0, _case.pascal)("".concat(methodName, "Response"));
155
- var properties = (_jsonschema$propertie = jsonschema.properties[underscoreName].properties) !== null && _jsonschema$propertie !== void 0 ? _jsonschema$propertie : {}; // console.log({ jsonschema, methodName, underscoreName, properties });
156
-
157
- var params = Object.keys(properties).map(function (prop) {
158
- return getProperty(jsonschema.properties[underscoreName], prop);
159
- });
155
+ var properties = (_jsonschema$propertie = jsonschema.properties[underscoreName].properties) !== null && _jsonschema$propertie !== void 0 ? _jsonschema$propertie : {};
156
+ var obj = createTypedObjectParams(jsonschema.properties[underscoreName]);
160
157
  var args = Object.keys(properties).map(function (prop) {
161
158
  return t.objectProperty(t.identifier(prop), t.identifier((0, _case.camel)(prop)), false, true);
162
159
  });
163
160
  var actionArg = t.objectProperty(t.identifier(underscoreName), t.objectExpression(args));
164
- return t.classProperty(t.identifier(methodName), (0, _utils.arrowFunctionExpression)(params, 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));
161
+ return t.classProperty(t.identifier(methodName), (0, _utils.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));
165
162
  };
166
163
 
167
164
  exports.createWasmQueryMethod = createWasmQueryMethod;
@@ -191,13 +188,12 @@ var createWasmExecMethod = function createWasmExecMethod(jsonschema) {
191
188
  var underscoreName = Object.keys(jsonschema.properties)[0];
192
189
  var methodName = (0, _case.camel)(underscoreName);
193
190
  var properties = (_jsonschema$propertie2 = jsonschema.properties[underscoreName].properties) !== null && _jsonschema$propertie2 !== void 0 ? _jsonschema$propertie2 : {};
194
- var params = Object.keys(properties).map(function (prop) {
195
- return getProperty(jsonschema.properties[underscoreName], prop);
196
- });
191
+ var obj = createTypedObjectParams(jsonschema.properties[underscoreName]);
197
192
  var args = Object.keys(properties).map(function (prop) {
198
193
  return t.objectProperty(t.identifier(prop), t.identifier((0, _case.camel)(prop)), false, prop === (0, _case.camel)(prop));
199
194
  });
200
- return t.classProperty(t.identifier(methodName), (0, _utils.arrowFunctionExpression)((0, _toConsumableArray2["default"])(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(t.identifier(underscoreName), t.objectExpression((0, _toConsumableArray2["default"])(args)))]), t.stringLiteral('auto')])))]), // return type
195
+ return t.classProperty(t.identifier(methodName), (0, _utils.arrowFunctionExpression)(obj ? [// props
196
+ obj] : [], 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(t.identifier(underscoreName), t.objectExpression((0, _toConsumableArray2["default"])(args)))]), t.stringLiteral('auto')])))]), // return type
201
197
  t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Promise'), t.tsTypeParameterInstantiation([t.tSTypeReference(t.identifier('ExecuteResult'))]))), true));
202
198
  };
203
199
 
@@ -221,7 +217,7 @@ var createExecuteClass = function createExecuteClass(className, implementsClassN
221
217
  }
222
218
 
223
219
  [].push.apply(blockStmt, [// client/contract set
224
- 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')))].concat((0, _toConsumableArray2["default"])(bindings)));
220
+ 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')))].concat((0, _toConsumableArray2["default"])(bindings)));
225
221
  return t.exportNamedDeclaration((0, _utils.classDeclaration)(className, [// client
226
222
  (0, _utils.classProperty)('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('SigningCosmWasmClient')))), // sender
227
223
  (0, _utils.classProperty)('sender', t.tsTypeAnnotation(t.tsStringKeyword())), // contractAddress
@@ -233,15 +229,9 @@ exports.createExecuteClass = createExecuteClass;
233
229
 
234
230
  var createExecuteInterface = function createExecuteInterface(className, extendsClassName, execMsg) {
235
231
  var methods = execMsg.oneOf.map(function (jsonschema) {
236
- var _jsonschema$propertie3;
237
-
238
232
  var underscoreName = Object.keys(jsonschema.properties)[0];
239
233
  var methodName = (0, _case.camel)(underscoreName);
240
- var properties = (_jsonschema$propertie3 = jsonschema.properties[underscoreName].properties) !== null && _jsonschema$propertie3 !== void 0 ? _jsonschema$propertie3 : {};
241
- var params = Object.keys(properties).map(function (prop) {
242
- return getProperty(jsonschema.properties[underscoreName], prop);
243
- });
244
- return t.tSPropertySignature(t.identifier(methodName), t.tsTypeAnnotation(t.tsFunctionType(null, (0, _toConsumableArray2["default"])(params), (0, _utils.promiseTypeAnnotation)('ExecuteResult'))));
234
+ return createPropertyFunctionWithObjectParams(methodName, 'ExecuteResult', jsonschema.properties[underscoreName]);
245
235
  });
246
236
  var extendsAst = extendsClassName ? [t.tSExpressionWithTypeArguments(t.identifier(extendsClassName))] : [];
247
237
  return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(className), null, extendsAst, t.tSInterfaceBody([// contract address
@@ -251,18 +241,47 @@ var createExecuteInterface = function createExecuteInterface(className, extendsC
251
241
 
252
242
  exports.createExecuteInterface = createExecuteInterface;
253
243
 
244
+ var createTypedObjectParams = function createTypedObjectParams(jsonschema) {
245
+ var _jsonschema$propertie3;
246
+
247
+ var keys = Object.keys((_jsonschema$propertie3 = jsonschema.properties) !== null && _jsonschema$propertie3 !== void 0 ? _jsonschema$propertie3 : {});
248
+ if (!keys.length) return;
249
+ var typedParams = keys.map(function (prop) {
250
+ var _getPropertyType2 = getPropertyType(jsonschema, prop),
251
+ type = _getPropertyType2.type,
252
+ optional = _getPropertyType2.optional;
253
+
254
+ return t.tsPropertySignature(t.identifier(prop), t.tsTypeAnnotation(type));
255
+ });
256
+ var params = keys.map(function (prop) {
257
+ return t.objectProperty(t.identifier(prop), t.identifier(prop), false, true);
258
+ });
259
+ var obj = t.objectPattern((0, _toConsumableArray2["default"])(params));
260
+ obj.typeAnnotation = t.tsTypeAnnotation(t.tsTypeLiteral((0, _toConsumableArray2["default"])(typedParams)));
261
+ return obj;
262
+ };
263
+
264
+ exports.createTypedObjectParams = createTypedObjectParams;
265
+
266
+ var createPropertyFunctionWithObjectParams = function createPropertyFunctionWithObjectParams(methodName, responseType, jsonschema) {
267
+ var obj = createTypedObjectParams(jsonschema);
268
+ var func = {
269
+ type: 'TSFunctionType',
270
+ typeAnnotation: (0, _utils.promiseTypeAnnotation)(responseType),
271
+ parameters: obj ? [obj] : []
272
+ };
273
+ return t.tSPropertySignature(t.identifier(methodName), t.tsTypeAnnotation(func));
274
+ };
275
+
276
+ exports.createPropertyFunctionWithObjectParams = createPropertyFunctionWithObjectParams;
277
+
254
278
  var createQueryInterface = function createQueryInterface(className, queryMsg) {
255
279
  var methods = queryMsg.oneOf.map(function (jsonschema) {
256
- var _jsonschema$propertie4;
257
-
258
280
  var underscoreName = Object.keys(jsonschema.properties)[0];
259
281
  var methodName = (0, _case.camel)(underscoreName);
260
282
  var responseType = (0, _case.pascal)("".concat(methodName, "Response"));
261
- var properties = (_jsonschema$propertie4 = jsonschema.properties[underscoreName].properties) !== null && _jsonschema$propertie4 !== void 0 ? _jsonschema$propertie4 : {};
262
- var params = Object.keys(properties).map(function (prop) {
263
- return getProperty(jsonschema.properties[underscoreName], prop);
264
- });
265
- return t.tSPropertySignature(t.identifier(methodName), t.tsTypeAnnotation(t.tsFunctionType(null, (0, _toConsumableArray2["default"])(params), (0, _utils.promiseTypeAnnotation)(responseType))));
283
+ var obj = createTypedObjectParams(jsonschema.properties[underscoreName]);
284
+ return createPropertyFunctionWithObjectParams(methodName, responseType, jsonschema.properties[underscoreName]);
266
285
  });
267
286
  return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(className), null, [], t.tSInterfaceBody([t.tSPropertySignature(t.identifier('contractAddress'), t.tsTypeAnnotation(t.tsStringKeyword()))].concat((0, _toConsumableArray2["default"])(methods)))));
268
287
  };
@@ -286,16 +305,16 @@ var propertySignature = function propertySignature(name, typeAnnotation) {
286
305
  exports.propertySignature = propertySignature;
287
306
 
288
307
  var createTypeOrInterface = function createTypeOrInterface(Type, jsonschema) {
289
- var _jsonschema$propertie5;
308
+ var _jsonschema$propertie4;
290
309
 
291
310
  if (jsonschema.type !== 'object') {
292
311
  return t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(Type), null, getType(jsonschema.type)));
293
312
  }
294
313
 
295
- var props = Object.keys((_jsonschema$propertie5 = jsonschema.properties) !== null && _jsonschema$propertie5 !== void 0 ? _jsonschema$propertie5 : {}).map(function (prop) {
296
- var _getPropertyType2 = getPropertyType(jsonschema, prop),
297
- type = _getPropertyType2.type,
298
- optional = _getPropertyType2.optional;
314
+ var props = Object.keys((_jsonschema$propertie4 = jsonschema.properties) !== null && _jsonschema$propertie4 !== void 0 ? _jsonschema$propertie4 : {}).map(function (prop) {
315
+ var _getPropertyType3 = getPropertyType(jsonschema, prop),
316
+ type = _getPropertyType3.type,
317
+ optional = _getPropertyType3.optional;
299
318
 
300
319
  return propertySignature((0, _case.camel)(prop), t.tsTypeAnnotation(type), optional);
301
320
  });
package/main/wasm.spec.js CHANGED
@@ -77,7 +77,7 @@ it('query classes', function () {
77
77
  expectCode((0, _wasm.createQueryClass)('SG721QueryClient', 'SG721ReadOnlyInstance', _query_msg["default"]));
78
78
  });
79
79
  it('execute classes', function () {
80
- expectCode((0, _wasm.createExecuteClass)('SG721Client', 'SG721Instance', 'SG721QueryClient', _execute_msg_for__empty["default"]));
80
+ printCode((0, _wasm.createExecuteClass)('SG721Client', 'SG721Instance', 'SG721QueryClient', _execute_msg_for__empty["default"]));
81
81
  });
82
82
  it('execute classes no extends', function () {
83
83
  expectCode((0, _wasm.createExecuteClass)('SG721Client', 'SG721Instance', null, _execute_msg_for__empty["default"]));
package/module/index.js CHANGED
@@ -1,3 +1,2 @@
1
- export * from './types';
2
1
  export * from './utils';
3
2
  export * from './wasm';
@@ -44,4 +44,10 @@ it('mutation classes', async () => {
44
44
  t.classProperty(t.identifier('mint'), arrowFunctionExpression([// props
45
45
  typedIdentifier('sender', t.tsTypeAnnotation(t.tsStringKeyword())), typedIdentifier('tokenId', t.tsTypeAnnotation(t.tsStringKeyword())), typedIdentifier('owner', t.tsTypeAnnotation(t.tsStringKeyword())), typedIdentifier('token_uri', t.tsTypeAnnotation(t.tsStringKeyword()))], t.blockStatement([t.returnStatement(t.awaitExpression(t.callExpression(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier('client')), t.identifier('execute')), [t.identifier('sender'), t.memberExpression(t.thisExpression(), t.identifier('contractAddress')), t.objectExpression([t.objectProperty(t.identifier('mint'), t.objectExpression([t.objectProperty(t.identifier('token_id'), t.identifier('tokenId')), t.objectProperty(t.identifier('owner'), t.identifier('owner')), t.objectProperty(t.identifier('token_uri'), t.identifier('token_uri')), t.objectProperty(t.identifier('expression'), t.objectExpression([]))]))]), t.stringLiteral('auto')])))]), // return type
46
46
  t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Promise'), t.tsTypeParameterInstantiation([t.tSTypeReference(t.identifier('ExecuteResult'))]))), true))], [t.tSExpressionWithTypeArguments(t.identifier('SG721ReadOnlyInstance'))], t.identifier('SG721QueryClient')))]));
47
+ });
48
+ it('object parms', () => {
49
+ const obj = t.objectPattern([t.objectProperty(t.identifier('includeExpired'), t.identifier('includeExpired'), false, true), t.objectProperty(t.identifier('tokenId'), t.identifier('tokenId'), false, true)]);
50
+ obj.typeAnnotation = t.tsTypeAnnotation(t.tsTypeLiteral([t.tsPropertySignature(t.identifier('includeExpired'), t.tsTypeAnnotation(t.tsBooleanKeyword())), t.tsPropertySignature(t.identifier('tokenId'), t.tsTypeAnnotation(t.tsStringKeyword()))]));
51
+ expectCode(t.program([t.expressionStatement(t.assignmentExpression('=', t.identifier('ownerOf'), arrowFunctionExpression([obj], t.blockStatement([// body
52
+ ], []), t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Promise'), t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier('OwnerOfResponse'))]))))))]));
47
53
  });
package/module/wasm.js CHANGED
@@ -123,16 +123,13 @@ export const createWasmQueryMethod = jsonschema => {
123
123
  const underscoreName = Object.keys(jsonschema.properties)[0];
124
124
  const methodName = camel(underscoreName);
125
125
  const responseType = pascal(`${methodName}Response`);
126
- const properties = jsonschema.properties[underscoreName].properties ?? {}; // console.log({ jsonschema, methodName, underscoreName, properties });
127
-
128
- const params = Object.keys(properties).map(prop => {
129
- return getProperty(jsonschema.properties[underscoreName], prop);
130
- });
126
+ const properties = jsonschema.properties[underscoreName].properties ?? {};
127
+ const obj = createTypedObjectParams(jsonschema.properties[underscoreName]);
131
128
  const args = Object.keys(properties).map(prop => {
132
129
  return t.objectProperty(t.identifier(prop), t.identifier(camel(prop)), false, true);
133
130
  });
134
131
  const actionArg = t.objectProperty(t.identifier(underscoreName), t.objectExpression(args));
135
- return t.classProperty(t.identifier(methodName), arrowFunctionExpression(params, 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));
132
+ 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));
136
133
  };
137
134
  export const createQueryClass = (className, implementsClassName, queryMsg) => {
138
135
  const propertyNames = queryMsg.oneOf.map(method => Object.keys(method.properties)?.[0]).filter(Boolean);
@@ -150,14 +147,12 @@ export const createWasmExecMethod = jsonschema => {
150
147
  const underscoreName = Object.keys(jsonschema.properties)[0];
151
148
  const methodName = camel(underscoreName);
152
149
  const properties = jsonschema.properties[underscoreName].properties ?? {};
153
- const params = Object.keys(properties).map(prop => {
154
- return getProperty(jsonschema.properties[underscoreName], prop);
155
- });
150
+ const obj = createTypedObjectParams(jsonschema.properties[underscoreName]);
156
151
  const args = Object.keys(properties).map(prop => {
157
152
  return t.objectProperty(t.identifier(prop), t.identifier(camel(prop)), false, prop === camel(prop));
158
153
  });
159
- return t.classProperty(t.identifier(methodName), arrowFunctionExpression([// props
160
- ...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(t.identifier(underscoreName), t.objectExpression([...args]))]), t.stringLiteral('auto')])))]), // return type
154
+ return t.classProperty(t.identifier(methodName), arrowFunctionExpression(obj ? [// props
155
+ obj] : [], 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(t.identifier(underscoreName), t.objectExpression([...args]))]), t.stringLiteral('auto')])))]), // return type
161
156
  t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Promise'), t.tsTypeParameterInstantiation([t.tSTypeReference(t.identifier('ExecuteResult'))]))), true));
162
157
  };
163
158
  export const createExecuteClass = (className, implementsClassName, extendsClassName, execMsg) => {
@@ -174,7 +169,7 @@ export const createExecuteClass = (className, implementsClassName, extendsClassN
174
169
  }
175
170
 
176
171
  [].push.apply(blockStmt, [// client/contract set
177
- 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]);
172
+ 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]);
178
173
  return t.exportNamedDeclaration(classDeclaration(className, [// client
179
174
  classProperty('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('SigningCosmWasmClient')))), // sender
180
175
  classProperty('sender', t.tsTypeAnnotation(t.tsStringKeyword())), // contractAddress
@@ -185,27 +180,46 @@ export const createExecuteInterface = (className, extendsClassName, execMsg) =>
185
180
  const methods = execMsg.oneOf.map(jsonschema => {
186
181
  const underscoreName = Object.keys(jsonschema.properties)[0];
187
182
  const methodName = camel(underscoreName);
188
- const properties = jsonschema.properties[underscoreName].properties ?? {};
189
- const params = Object.keys(properties).map(prop => {
190
- return getProperty(jsonschema.properties[underscoreName], prop);
191
- });
192
- return t.tSPropertySignature(t.identifier(methodName), t.tsTypeAnnotation(t.tsFunctionType(null, [...params], promiseTypeAnnotation('ExecuteResult'))));
183
+ return createPropertyFunctionWithObjectParams(methodName, 'ExecuteResult', jsonschema.properties[underscoreName]);
193
184
  });
194
185
  const extendsAst = extendsClassName ? [t.tSExpressionWithTypeArguments(t.identifier(extendsClassName))] : [];
195
186
  return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(className), null, extendsAst, t.tSInterfaceBody([// contract address
196
187
  t.tSPropertySignature(t.identifier('contractAddress'), t.tsTypeAnnotation(t.tsStringKeyword())), // contract address
197
188
  t.tSPropertySignature(t.identifier('sender'), t.tsTypeAnnotation(t.tsStringKeyword())), ...methods])));
198
189
  };
190
+ export const createTypedObjectParams = jsonschema => {
191
+ const keys = Object.keys(jsonschema.properties ?? {});
192
+ if (!keys.length) return;
193
+ const typedParams = keys.map(prop => {
194
+ const {
195
+ type,
196
+ optional
197
+ } = getPropertyType(jsonschema, prop);
198
+ return t.tsPropertySignature(t.identifier(prop), t.tsTypeAnnotation(type));
199
+ });
200
+ const params = keys.map(prop => {
201
+ return t.objectProperty(t.identifier(prop), t.identifier(prop), false, true);
202
+ });
203
+ const obj = t.objectPattern([...params]);
204
+ obj.typeAnnotation = t.tsTypeAnnotation(t.tsTypeLiteral([...typedParams]));
205
+ return obj;
206
+ };
207
+ export const createPropertyFunctionWithObjectParams = (methodName, responseType, jsonschema) => {
208
+ const obj = createTypedObjectParams(jsonschema);
209
+ const func = {
210
+ type: 'TSFunctionType',
211
+ typeAnnotation: promiseTypeAnnotation(responseType),
212
+ parameters: obj ? [obj] : []
213
+ };
214
+ return t.tSPropertySignature(t.identifier(methodName), t.tsTypeAnnotation(func));
215
+ };
199
216
  export const createQueryInterface = (className, queryMsg) => {
200
217
  const methods = queryMsg.oneOf.map(jsonschema => {
201
218
  const underscoreName = Object.keys(jsonschema.properties)[0];
202
219
  const methodName = camel(underscoreName);
203
220
  const responseType = pascal(`${methodName}Response`);
204
- const properties = jsonschema.properties[underscoreName].properties ?? {};
205
- const params = Object.keys(properties).map(prop => {
206
- return getProperty(jsonschema.properties[underscoreName], prop);
207
- });
208
- return t.tSPropertySignature(t.identifier(methodName), t.tsTypeAnnotation(t.tsFunctionType(null, [...params], promiseTypeAnnotation(responseType))));
221
+ const obj = createTypedObjectParams(jsonschema.properties[underscoreName]);
222
+ return createPropertyFunctionWithObjectParams(methodName, responseType, jsonschema.properties[underscoreName]);
209
223
  });
210
224
  return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(className), null, [], t.tSInterfaceBody([t.tSPropertySignature(t.identifier('contractAddress'), t.tsTypeAnnotation(t.tsStringKeyword())), ...methods])));
211
225
  };
@@ -59,7 +59,7 @@ it('query classes', () => {
59
59
  expectCode(createQueryClass('SG721QueryClient', 'SG721ReadOnlyInstance', query_msg));
60
60
  });
61
61
  it('execute classes', () => {
62
- expectCode(createExecuteClass('SG721Client', 'SG721Instance', 'SG721QueryClient', execute_msg));
62
+ printCode(createExecuteClass('SG721Client', 'SG721Instance', 'SG721QueryClient', execute_msg));
63
63
  });
64
64
  it('execute classes no extends', () => {
65
65
  expectCode(createExecuteClass('SG721Client', 'SG721Instance', null, execute_msg));
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "wasm-ast-types",
3
- "version": "0.0.6",
3
+ "version": "0.0.9",
4
4
  "description": "CosmWasm TypeScript AST generation",
5
5
  "author": "Dan Lynch <pyramation@gmail.com>",
6
- "homepage": "https://github.com/pyramation/cosmscript/tree/master/packages/wasm-ast-types#readme",
6
+ "homepage": "https://github.com/pyramation/cosmwasm-typescript-gen/tree/master/packages/wasm-ast-types#readme",
7
7
  "license": "SEE LICENSE IN LICENSE",
8
8
  "main": "main/index.js",
9
9
  "module": "module/index.js",
@@ -42,11 +42,11 @@
42
42
  },
43
43
  "repository": {
44
44
  "type": "git",
45
- "url": "https://github.com/pyramation/cosmscript/tree/master/packages/wasm-ast-types"
45
+ "url": "https://github.com/pyramation/cosmwasm-typescript-gen/tree/master/packages/wasm-ast-types"
46
46
  },
47
47
  "keywords": [],
48
48
  "bugs": {
49
- "url": "https://github.com/pyramation/cosmscript/tree/master/packages/wasm-ast-types/issues"
49
+ "url": "https://github.com/pyramation/cosmwasm-typescript-gen/tree/master/packages/wasm-ast-types/issues"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@babel/cli": "7.17.6",
@@ -85,5 +85,5 @@
85
85
  "ast-stringify": "0.1.0",
86
86
  "case": "1.6.3"
87
87
  },
88
- "gitHead": "bedb5d4d98b2779746909450960862ce4b7aa7f4"
88
+ "gitHead": "1d8886f8c415d2123010166ee491f88935c8ec1b"
89
89
  }
package/main/types.js DELETED
@@ -1,4 +0,0 @@
1
- "use strict";
2
-
3
- ;
4
- ;
package/module/types.js DELETED
@@ -1,3 +0,0 @@
1
- ;
2
- ;
3
- export {};