wasm-ast-types 0.0.10 → 0.1.0

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
@@ -65,7 +65,7 @@ var getType = function getType(type) {
65
65
  };
66
66
 
67
67
  var getPropertyType = function getPropertyType(schema, prop) {
68
- var _schema$properties, _schema$required;
68
+ var _schema$properties, _schema$required, _schema$required2;
69
69
 
70
70
  var props = (_schema$properties = schema.properties) !== null && _schema$properties !== void 0 ? _schema$properties : {};
71
71
  var info = props[prop];
@@ -132,6 +132,10 @@ var getPropertyType = function getPropertyType(schema, prop) {
132
132
  throw new Error('cannot find type for ' + JSON.stringify(info));
133
133
  }
134
134
 
135
+ if ((_schema$required2 = schema.required) !== null && _schema$required2 !== void 0 && _schema$required2.includes(prop)) {
136
+ optional = false;
137
+ }
138
+
135
139
  return {
136
140
  type: type,
137
141
  optional: optional
@@ -241,6 +245,26 @@ var createExecuteInterface = function createExecuteInterface(className, extendsC
241
245
 
242
246
  exports.createExecuteInterface = createExecuteInterface;
243
247
 
248
+ var propertySignature = function propertySignature(name, typeAnnotation) {
249
+ var optional = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
250
+ // prop.leadingComments = [{
251
+ // type: 'Comment',
252
+ // value: ' Data on the token itself'
253
+ // }];
254
+ // prop.leadingComments = [{
255
+ // type: 'CommentBlock',
256
+ // value: '* Data on the token itself'
257
+ // }];
258
+ return {
259
+ type: 'TSPropertySignature',
260
+ key: t.identifier(name),
261
+ typeAnnotation: typeAnnotation,
262
+ optional: optional
263
+ };
264
+ };
265
+
266
+ exports.propertySignature = propertySignature;
267
+
244
268
  var createTypedObjectParams = function createTypedObjectParams(jsonschema) {
245
269
  var _jsonschema$propertie3;
246
270
 
@@ -252,7 +276,7 @@ var createTypedObjectParams = function createTypedObjectParams(jsonschema) {
252
276
  type = _getPropertyType2.type,
253
277
  optional = _getPropertyType2.optional;
254
278
 
255
- return t.tsPropertySignature(camelize ? t.identifier((0, _case.camel)(prop)) : t.identifier(prop), t.tsTypeAnnotation(type));
279
+ return propertySignature(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(type), optional);
256
280
  });
257
281
  var params = keys.map(function (prop) {
258
282
  return t.objectProperty(camelize ? t.identifier((0, _case.camel)(prop)) : t.identifier(prop), camelize ? t.identifier((0, _case.camel)(prop)) : t.identifier(prop), false, true);
@@ -289,22 +313,6 @@ var createQueryInterface = function createQueryInterface(className, queryMsg) {
289
313
 
290
314
  exports.createQueryInterface = createQueryInterface;
291
315
 
292
- var propertySignature = function propertySignature(name, typeAnnotation) {
293
- var optional = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
294
- var prop = t.tsPropertySignature(t.identifier(name), typeAnnotation); // prop.leadingComments = [{
295
- // type: 'Comment',
296
- // value: ' Data on the token itself'
297
- // }];
298
- // prop.leadingComments = [{
299
- // type: 'CommentBlock',
300
- // value: '* Data on the token itself'
301
- // }];
302
-
303
- return prop;
304
- };
305
-
306
- exports.propertySignature = propertySignature;
307
-
308
316
  var createTypeOrInterface = function createTypeOrInterface(Type, jsonschema) {
309
317
  var _jsonschema$propertie4;
310
318
 
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
- printCode((0, _wasm.createExecuteClass)('SG721Client', 'SG721Instance', 'SG721QueryClient', _execute_msg_for__empty["default"]));
80
+ expectCode((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/wasm.js CHANGED
@@ -105,6 +105,10 @@ const getPropertyType = (schema, prop) => {
105
105
  throw new Error('cannot find type for ' + JSON.stringify(info));
106
106
  }
107
107
 
108
+ if (schema.required?.includes(prop)) {
109
+ optional = false;
110
+ }
111
+
108
112
  return {
109
113
  type,
110
114
  optional
@@ -187,6 +191,22 @@ export const createExecuteInterface = (className, extendsClassName, execMsg) =>
187
191
  t.tSPropertySignature(t.identifier('contractAddress'), t.tsTypeAnnotation(t.tsStringKeyword())), // contract address
188
192
  t.tSPropertySignature(t.identifier('sender'), t.tsTypeAnnotation(t.tsStringKeyword())), ...methods])));
189
193
  };
194
+ export const propertySignature = (name, typeAnnotation, optional = false) => {
195
+ // prop.leadingComments = [{
196
+ // type: 'Comment',
197
+ // value: ' Data on the token itself'
198
+ // }];
199
+ // prop.leadingComments = [{
200
+ // type: 'CommentBlock',
201
+ // value: '* Data on the token itself'
202
+ // }];
203
+ return {
204
+ type: 'TSPropertySignature',
205
+ key: t.identifier(name),
206
+ typeAnnotation,
207
+ optional
208
+ };
209
+ };
190
210
  export const createTypedObjectParams = (jsonschema, camelize = true) => {
191
211
  const keys = Object.keys(jsonschema.properties ?? {});
192
212
  if (!keys.length) return;
@@ -195,7 +215,7 @@ export const createTypedObjectParams = (jsonschema, camelize = true) => {
195
215
  type,
196
216
  optional
197
217
  } = getPropertyType(jsonschema, prop);
198
- return t.tsPropertySignature(camelize ? t.identifier(camel(prop)) : t.identifier(prop), t.tsTypeAnnotation(type));
218
+ return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(type), optional);
199
219
  });
200
220
  const params = keys.map(prop => {
201
221
  return t.objectProperty(camelize ? t.identifier(camel(prop)) : t.identifier(prop), camelize ? t.identifier(camel(prop)) : t.identifier(prop), false, true);
@@ -223,18 +243,6 @@ export const createQueryInterface = (className, queryMsg) => {
223
243
  });
224
244
  return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(className), null, [], t.tSInterfaceBody([t.tSPropertySignature(t.identifier('contractAddress'), t.tsTypeAnnotation(t.tsStringKeyword())), ...methods])));
225
245
  };
226
- export const propertySignature = (name, typeAnnotation, optional = false) => {
227
- const prop = t.tsPropertySignature(t.identifier(name), typeAnnotation); // prop.leadingComments = [{
228
- // type: 'Comment',
229
- // value: ' Data on the token itself'
230
- // }];
231
- // prop.leadingComments = [{
232
- // type: 'CommentBlock',
233
- // value: '* Data on the token itself'
234
- // }];
235
-
236
- return prop;
237
- };
238
246
  export const createTypeOrInterface = (Type, jsonschema) => {
239
247
  if (jsonschema.type !== 'object') {
240
248
  return t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(Type), null, getType(jsonschema.type)));
@@ -59,7 +59,7 @@ it('query classes', () => {
59
59
  expectCode(createQueryClass('SG721QueryClient', 'SG721ReadOnlyInstance', query_msg));
60
60
  });
61
61
  it('execute classes', () => {
62
- printCode(createExecuteClass('SG721Client', 'SG721Instance', 'SG721QueryClient', execute_msg));
62
+ expectCode(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,6 +1,6 @@
1
1
  {
2
2
  "name": "wasm-ast-types",
3
- "version": "0.0.10",
3
+ "version": "0.1.0",
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": "c68977bec42dfc57a0272965fba25660ebc04498"
88
+ "gitHead": "3073018a9061dbbabb5c7c417b5de5a1c754cc0d"
89
89
  }