wasm-ast-types 0.0.9 → 0.0.12

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,9 +245,30 @@ 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
 
271
+ var camelize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
247
272
  var keys = Object.keys((_jsonschema$propertie3 = jsonschema.properties) !== null && _jsonschema$propertie3 !== void 0 ? _jsonschema$propertie3 : {});
248
273
  if (!keys.length) return;
249
274
  var typedParams = keys.map(function (prop) {
@@ -251,10 +276,10 @@ var createTypedObjectParams = function createTypedObjectParams(jsonschema) {
251
276
  type = _getPropertyType2.type,
252
277
  optional = _getPropertyType2.optional;
253
278
 
254
- return t.tsPropertySignature(t.identifier(prop), t.tsTypeAnnotation(type));
279
+ return propertySignature(camelize ? (0, _case.camel)(prop) : prop, t.tsTypeAnnotation(type), optional);
255
280
  });
256
281
  var params = keys.map(function (prop) {
257
- return t.objectProperty(t.identifier(prop), t.identifier(prop), false, true);
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);
258
283
  });
259
284
  var obj = t.objectPattern((0, _toConsumableArray2["default"])(params));
260
285
  obj.typeAnnotation = t.tsTypeAnnotation(t.tsTypeLiteral((0, _toConsumableArray2["default"])(typedParams)));
@@ -288,22 +313,6 @@ var createQueryInterface = function createQueryInterface(className, queryMsg) {
288
313
 
289
314
  exports.createQueryInterface = createQueryInterface;
290
315
 
291
- var propertySignature = function propertySignature(name, typeAnnotation) {
292
- var optional = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
293
- var prop = t.tsPropertySignature(t.identifier(name), typeAnnotation); // prop.leadingComments = [{
294
- // type: 'Comment',
295
- // value: ' Data on the token itself'
296
- // }];
297
- // prop.leadingComments = [{
298
- // type: 'CommentBlock',
299
- // value: '* Data on the token itself'
300
- // }];
301
-
302
- return prop;
303
- };
304
-
305
- exports.propertySignature = propertySignature;
306
-
307
316
  var createTypeOrInterface = function createTypeOrInterface(Type, jsonschema) {
308
317
  var _jsonschema$propertie4;
309
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,7 +191,23 @@ 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
  };
190
- export const createTypedObjectParams = jsonschema => {
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
+ };
210
+ export const createTypedObjectParams = (jsonschema, camelize = true) => {
191
211
  const keys = Object.keys(jsonschema.properties ?? {});
192
212
  if (!keys.length) return;
193
213
  const typedParams = keys.map(prop => {
@@ -195,10 +215,10 @@ export const createTypedObjectParams = jsonschema => {
195
215
  type,
196
216
  optional
197
217
  } = getPropertyType(jsonschema, prop);
198
- return t.tsPropertySignature(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
- return t.objectProperty(t.identifier(prop), t.identifier(prop), false, true);
221
+ return t.objectProperty(camelize ? t.identifier(camel(prop)) : t.identifier(prop), camelize ? t.identifier(camel(prop)) : t.identifier(prop), false, true);
202
222
  });
203
223
  const obj = t.objectPattern([...params]);
204
224
  obj.typeAnnotation = t.tsTypeAnnotation(t.tsTypeLiteral([...typedParams]));
@@ -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.9",
3
+ "version": "0.0.12",
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": "1d8886f8c415d2123010166ee491f88935c8ec1b"
88
+ "gitHead": "7b4d5701c31843fc5c49364e658ea6003e080b7e"
89
89
  }