wasm-ast-types 0.0.4 → 0.0.7

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
@@ -213,13 +213,20 @@ var createExecuteClass = function createExecuteClass(className, implementsClassN
213
213
  var methods = execMsg.oneOf.map(function (schema) {
214
214
  return createWasmExecMethod(schema);
215
215
  });
216
+ var blockStmt = [];
217
+
218
+ if (extendsClassName) {
219
+ blockStmt.push( // super()
220
+ t.expressionStatement(t.callExpression(t["super"](), [t.identifier('client'), t.identifier('contractAddress')])));
221
+ }
222
+
223
+ [].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('sender')), t.identifier('sender'))), t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier('contractAddress')), t.identifier('contractAddress')))].concat((0, _toConsumableArray2["default"])(bindings)));
216
225
  return t.exportNamedDeclaration((0, _utils.classDeclaration)(className, [// client
217
226
  (0, _utils.classProperty)('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('SigningCosmWasmClient')))), // sender
218
227
  (0, _utils.classProperty)('sender', t.tsTypeAnnotation(t.tsStringKeyword())), // contractAddress
219
228
  (0, _utils.classProperty)('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword())), // constructor
220
- t.classMethod('constructor', t.identifier('constructor'), [(0, _utils.typedIdentifier)('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('SigningCosmWasmClient')))), (0, _utils.typedIdentifier)('sender', t.tsTypeAnnotation(t.tsStringKeyword())), (0, _utils.typedIdentifier)('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword()))], t.blockStatement([// super()
221
- t.expressionStatement(t.callExpression(t["super"](), [t.identifier('client'), t.identifier('contractAddress')])), // client/contract set
222
- 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))))].concat((0, _toConsumableArray2["default"])(methods)), [t.tSExpressionWithTypeArguments(t.identifier(implementsClassName))], t.identifier(extendsClassName)));
229
+ t.classMethod('constructor', t.identifier('constructor'), [(0, _utils.typedIdentifier)('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('SigningCosmWasmClient')))), (0, _utils.typedIdentifier)('sender', t.tsTypeAnnotation(t.tsStringKeyword())), (0, _utils.typedIdentifier)('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword()))], t.blockStatement(blockStmt))].concat((0, _toConsumableArray2["default"])(methods)), [t.tSExpressionWithTypeArguments(t.identifier(implementsClassName))], extendsClassName ? t.identifier(extendsClassName) : null));
223
230
  };
224
231
 
225
232
  exports.createExecuteClass = createExecuteClass;
@@ -236,7 +243,8 @@ var createExecuteInterface = function createExecuteInterface(className, extendsC
236
243
  });
237
244
  return t.tSPropertySignature(t.identifier(methodName), t.tsTypeAnnotation(t.tsFunctionType(null, (0, _toConsumableArray2["default"])(params), (0, _utils.promiseTypeAnnotation)('ExecuteResult'))));
238
245
  });
239
- return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(className), null, [t.tSExpressionWithTypeArguments(t.identifier(extendsClassName))], t.tSInterfaceBody([// contract address
246
+ var extendsAst = extendsClassName ? [t.tSExpressionWithTypeArguments(t.identifier(extendsClassName))] : [];
247
+ return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(className), null, extendsAst, t.tSInterfaceBody([// contract address
240
248
  t.tSPropertySignature(t.identifier('contractAddress'), t.tsTypeAnnotation(t.tsStringKeyword())), // contract address
241
249
  t.tSPropertySignature(t.identifier('sender'), t.tsTypeAnnotation(t.tsStringKeyword()))].concat((0, _toConsumableArray2["default"])(methods)))));
242
250
  };
package/main/wasm.spec.js CHANGED
@@ -79,8 +79,11 @@ it('query classes', function () {
79
79
  it('execute classes', function () {
80
80
  expectCode((0, _wasm.createExecuteClass)('SG721Client', 'SG721Instance', 'SG721QueryClient', _execute_msg_for__empty["default"]));
81
81
  });
82
- it('execute interfaces', function () {
83
- expectCode((0, _wasm.createExecuteInterface)('SG721Instance', 'SG721ReadOnlyInstance', _execute_msg_for__empty["default"]));
82
+ it('execute classes no extends', function () {
83
+ expectCode((0, _wasm.createExecuteClass)('SG721Client', 'SG721Instance', null, _execute_msg_for__empty["default"]));
84
+ });
85
+ it('execute interfaces no extends', function () {
86
+ expectCode((0, _wasm.createExecuteInterface)('SG721Instance', null, _execute_msg_for__empty["default"]));
84
87
  });
85
88
  it('query interfaces', function () {
86
89
  expectCode((0, _wasm.createQueryInterface)('SG721ReadOnlyInstance', _query_msg["default"]));
package/module/wasm.js CHANGED
@@ -166,13 +166,20 @@ export const createExecuteClass = (className, implementsClassName, extendsClassN
166
166
  const methods = execMsg.oneOf.map(schema => {
167
167
  return createWasmExecMethod(schema);
168
168
  });
169
+ const blockStmt = [];
170
+
171
+ if (extendsClassName) {
172
+ blockStmt.push( // super()
173
+ t.expressionStatement(t.callExpression(t.super(), [t.identifier('client'), t.identifier('contractAddress')])));
174
+ }
175
+
176
+ [].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('sender')), t.identifier('sender'))), t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier('contractAddress')), t.identifier('contractAddress'))), ...bindings]);
169
178
  return t.exportNamedDeclaration(classDeclaration(className, [// client
170
179
  classProperty('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('SigningCosmWasmClient')))), // sender
171
180
  classProperty('sender', t.tsTypeAnnotation(t.tsStringKeyword())), // contractAddress
172
181
  classProperty('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword())), // constructor
173
- 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([// super()
174
- t.expressionStatement(t.callExpression(t.super(), [t.identifier('client'), t.identifier('contractAddress')])), // client/contract set
175
- 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])), ...methods], [t.tSExpressionWithTypeArguments(t.identifier(implementsClassName))], t.identifier(extendsClassName)));
182
+ 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));
176
183
  };
177
184
  export const createExecuteInterface = (className, extendsClassName, execMsg) => {
178
185
  const methods = execMsg.oneOf.map(jsonschema => {
@@ -184,7 +191,8 @@ export const createExecuteInterface = (className, extendsClassName, execMsg) =>
184
191
  });
185
192
  return t.tSPropertySignature(t.identifier(methodName), t.tsTypeAnnotation(t.tsFunctionType(null, [...params], promiseTypeAnnotation('ExecuteResult'))));
186
193
  });
187
- return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(className), null, [t.tSExpressionWithTypeArguments(t.identifier(extendsClassName))], t.tSInterfaceBody([// contract address
194
+ const extendsAst = extendsClassName ? [t.tSExpressionWithTypeArguments(t.identifier(extendsClassName))] : [];
195
+ return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(className), null, extendsAst, t.tSInterfaceBody([// contract address
188
196
  t.tSPropertySignature(t.identifier('contractAddress'), t.tsTypeAnnotation(t.tsStringKeyword())), // contract address
189
197
  t.tSPropertySignature(t.identifier('sender'), t.tsTypeAnnotation(t.tsStringKeyword())), ...methods])));
190
198
  };
@@ -61,8 +61,11 @@ it('query classes', () => {
61
61
  it('execute classes', () => {
62
62
  expectCode(createExecuteClass('SG721Client', 'SG721Instance', 'SG721QueryClient', execute_msg));
63
63
  });
64
- it('execute interfaces', () => {
65
- expectCode(createExecuteInterface('SG721Instance', 'SG721ReadOnlyInstance', execute_msg));
64
+ it('execute classes no extends', () => {
65
+ expectCode(createExecuteClass('SG721Client', 'SG721Instance', null, execute_msg));
66
+ });
67
+ it('execute interfaces no extends', () => {
68
+ expectCode(createExecuteInterface('SG721Instance', null, execute_msg));
66
69
  });
67
70
  it('query interfaces', () => {
68
71
  expectCode(createQueryInterface('SG721ReadOnlyInstance', query_msg));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wasm-ast-types",
3
- "version": "0.0.4",
3
+ "version": "0.0.7",
4
4
  "description": "CosmWasm TypeScript AST generation",
5
5
  "author": "Dan Lynch <pyramation@gmail.com>",
6
6
  "homepage": "https://github.com/pyramation/cosmscript/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": "e2b5cd65b9caf2cc9f916533bc78dded5ea32b40"
88
+ "gitHead": "ef6a879c720522764911a6f5f915aa824b4e3e08"
89
89
  }