wasm-ast-types 0.21.0 → 0.23.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. package/main/client/client.js +4 -6
  2. package/main/context/imports.js +1 -1
  3. package/main/message-composer/message-composer.js +3 -5
  4. package/main/react-query/react-query.js +4 -11
  5. package/main/utils/babel.js +1 -0
  6. package/main/utils/constants.js +25 -0
  7. package/main/utils/index.js +22 -1
  8. package/module/client/client.js +3 -4
  9. package/module/context/imports.js +1 -1
  10. package/module/message-composer/message-composer.js +4 -5
  11. package/module/react-query/react-query.js +5 -6
  12. package/module/utils/babel.js +1 -0
  13. package/module/utils/constants.js +6 -0
  14. package/module/utils/index.js +3 -1
  15. package/package.json +2 -2
  16. package/src/client/client.ts +235 -323
  17. package/src/client/test/__snapshots__/ts-client.account-nfts.spec.ts.snap +45 -45
  18. package/src/client/test/__snapshots__/ts-client.arrays-ref.spec.ts.snap +42 -42
  19. package/src/client/test/__snapshots__/ts-client.arrays.spec.ts.snap +3 -3
  20. package/src/client/test/__snapshots__/ts-client.cw-named-groups.test.ts.snap +9 -9
  21. package/src/client/test/__snapshots__/ts-client.cw-proposal-single.test.ts.snap +27 -27
  22. package/src/client/test/__snapshots__/ts-client.issue-101.spec.ts.snap +6 -6
  23. package/src/client/test/__snapshots__/ts-client.issue-71.test.ts.snap +30 -30
  24. package/src/client/test/__snapshots__/ts-client.issue-98.test.ts.snap +9 -9
  25. package/src/client/test/__snapshots__/ts-client.issues.test.ts.snap +78 -78
  26. package/src/client/test/__snapshots__/ts-client.overrides.spec.ts.snap +80 -80
  27. package/src/client/test/__snapshots__/ts-client.sg721.spec.ts.snap +24 -24
  28. package/src/client/test/__snapshots__/ts-client.spec.ts.snap +46 -46
  29. package/src/client/test/__snapshots__/ts-client.vectis.spec.ts.snap +24 -24
  30. package/src/client/test/__snapshots__/ts-client.wager.spec.ts.snap +8 -8
  31. package/src/context/context.ts +2 -0
  32. package/src/context/imports.ts +1 -1
  33. package/src/message-composer/__snapshots__/message-composer.spec.ts.snap +30 -30
  34. package/src/message-composer/message-composer.ts +216 -267
  35. package/src/react-query/react-query.ts +28 -25
  36. package/src/utils/babel.ts +4 -3
  37. package/src/utils/constants.ts +30 -0
  38. package/src/utils/index.ts +2 -0
  39. package/types/context/context.d.ts +2 -0
@@ -5,14 +5,21 @@ import {
5
5
  bindMethod,
6
6
  classDeclaration,
7
7
  classProperty,
8
+ FIXED_EXECUTE_PARAMS,
8
9
  getMessageProperties,
10
+ OPTIONAL_FUNDS_PARAM,
9
11
  promiseTypeAnnotation,
10
12
  typedIdentifier
11
13
  } from '../utils';
12
14
 
13
15
  import { ExecuteMsg, JSONSchema, QueryMsg } from '../types';
14
16
 
15
- import { createTypedObjectParams, getPropertyType, getResponseType, getType } from '../utils/types';
17
+ import {
18
+ createTypedObjectParams,
19
+ getPropertyType,
20
+ getResponseType,
21
+ getType
22
+ } from '../utils/types';
16
23
  import { RenderContext } from '../context';
17
24
  import { identifier, propertySignature } from '../utils/babel';
18
25
 
@@ -21,66 +28,24 @@ export const CONSTANT_EXEC_PARAMS = [
21
28
  identifier(
22
29
  'fee',
23
30
  t.tsTypeAnnotation(
24
- t.tsUnionType(
25
- [
26
- t.tSNumberKeyword(),
27
- t.tsTypeReference(
28
- t.identifier('StdFee')
29
- ),
30
- t.tsLiteralType(
31
- t.stringLiteral('auto')
32
- )
33
- ]
34
- )
31
+ t.tsUnionType([
32
+ t.tSNumberKeyword(),
33
+ t.tsTypeReference(t.identifier('StdFee')),
34
+ t.tsLiteralType(t.stringLiteral('auto'))
35
+ ])
35
36
  ),
36
37
  false
37
38
  ),
38
39
  t.stringLiteral('auto')
39
40
  ),
40
- identifier('memo', t.tsTypeAnnotation(
41
- t.tsStringKeyword()
42
- ), true),
43
- identifier('funds', t.tsTypeAnnotation(
44
- t.tsArrayType(
45
- t.tsTypeReference(
46
- t.identifier('Coin')
47
- )
48
- )
49
- ), true)
50
- ];
51
-
52
- export const FIXED_EXECUTE_PARAMS = [
53
- identifier('fee', t.tsTypeAnnotation(
54
- t.tsUnionType(
55
- [
56
- t.tsNumberKeyword(),
57
- t.tsTypeReference(
58
- t.identifier('StdFee')
59
- ),
60
- t.tsLiteralType(
61
- t.stringLiteral('auto')
62
- )
63
- ]
64
- )
65
- ), true),
66
- identifier('memo', t.tsTypeAnnotation(
67
- t.tsStringKeyword()
68
- ), true),
69
- identifier('funds', t.tsTypeAnnotation(
70
- t.tsArrayType(
71
- t.tsTypeReference(
72
- t.identifier('Coin')
73
- )
74
- )
75
- ), true)
41
+ identifier('memo', t.tsTypeAnnotation(t.tsStringKeyword()), true),
42
+ OPTIONAL_FUNDS_PARAM
76
43
  ];
77
44
 
78
-
79
45
  export const createWasmQueryMethod = (
80
46
  context: RenderContext,
81
47
  jsonschema: any
82
48
  ) => {
83
-
84
49
  const underscoreName = Object.keys(jsonschema.properties)[0];
85
50
  const methodName = camel(underscoreName);
86
51
  const responseType = getResponseType(context, underscoreName);
@@ -97,49 +62,44 @@ export const createWasmQueryMethod = (
97
62
 
98
63
  const msgAction = t.identifier(underscoreName);
99
64
  // If the param is an identifier, we can just use it as is
100
- const msgActionValue = param?.type === 'Identifier' ? t.identifier(param.name) : t.objectExpression(args)
65
+ const msgActionValue =
66
+ param?.type === 'Identifier'
67
+ ? t.identifier(param.name)
68
+ : t.objectExpression(args);
101
69
 
102
70
  return t.classProperty(
103
71
  t.identifier(methodName),
104
72
  arrowFunctionExpression(
105
73
  param ? [param] : [],
106
- t.blockStatement(
107
- [
108
- t.returnStatement(
109
- t.callExpression(
74
+ t.blockStatement([
75
+ t.returnStatement(
76
+ t.callExpression(
77
+ t.memberExpression(
78
+ t.memberExpression(t.thisExpression(), t.identifier('client')),
79
+ t.identifier('queryContractSmart')
80
+ ),
81
+ [
110
82
  t.memberExpression(
111
- t.memberExpression(
112
- t.thisExpression(),
113
- t.identifier('client')
114
- ),
115
- t.identifier('queryContractSmart')
83
+ t.thisExpression(),
84
+ t.identifier('contractAddress')
116
85
  ),
117
- [
118
- t.memberExpression(t.thisExpression(), t.identifier('contractAddress')),
119
- t.objectExpression([
120
- t.objectProperty(msgAction, msgActionValue)
121
- ])
122
- ]
123
- )
86
+ t.objectExpression([t.objectProperty(msgAction, msgActionValue)])
87
+ ]
124
88
  )
125
- ]
126
- ),
89
+ )
90
+ ]),
127
91
  t.tsTypeAnnotation(
128
92
  t.tsTypeReference(
129
93
  t.identifier('Promise'),
130
- t.tsTypeParameterInstantiation(
131
- [
132
- t.tSTypeReference(
133
- t.identifier(responseType)
134
- )
135
- ]
136
- )
94
+ t.tsTypeParameterInstantiation([
95
+ t.tSTypeReference(t.identifier(responseType))
96
+ ])
137
97
  )
138
98
  ),
139
99
  true
140
100
  )
141
101
  );
142
- }
102
+ };
143
103
 
144
104
  export const createQueryClass = (
145
105
  context: RenderContext,
@@ -147,81 +107,78 @@ export const createQueryClass = (
147
107
  implementsClassName: string,
148
108
  queryMsg: QueryMsg
149
109
  ) => {
150
-
151
110
  context.addUtil('CosmWasmClient');
152
111
 
153
112
  const propertyNames = getMessageProperties(queryMsg)
154
- .map(method => Object.keys(method.properties)?.[0])
113
+ .map((method) => Object.keys(method.properties)?.[0])
155
114
  .filter(Boolean);
156
115
 
157
- const bindings = propertyNames
158
- .map(camel)
159
- .map(bindMethod);
116
+ const bindings = propertyNames.map(camel).map(bindMethod);
160
117
 
161
- const methods = getMessageProperties(queryMsg)
162
- .map(schema => {
163
- return createWasmQueryMethod(context, schema)
164
- });
118
+ const methods = getMessageProperties(queryMsg).map((schema) => {
119
+ return createWasmQueryMethod(context, schema);
120
+ });
165
121
 
166
122
  return t.exportNamedDeclaration(
167
- classDeclaration(className,
123
+ classDeclaration(
124
+ className,
168
125
  [
169
126
  // client
170
- classProperty('client', t.tsTypeAnnotation(
171
- t.tsTypeReference(t.identifier('CosmWasmClient'))
172
- )),
127
+ classProperty(
128
+ 'client',
129
+ t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CosmWasmClient')))
130
+ ),
173
131
 
174
132
  // contractAddress
175
- classProperty('contractAddress', t.tsTypeAnnotation(
176
- t.tsStringKeyword()
177
- )),
133
+ classProperty(
134
+ 'contractAddress',
135
+ t.tsTypeAnnotation(t.tsStringKeyword())
136
+ ),
178
137
 
179
138
  // constructor
180
- t.classMethod('constructor',
139
+ t.classMethod(
140
+ 'constructor',
181
141
  t.identifier('constructor'),
182
142
  [
183
- typedIdentifier('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CosmWasmClient')))),
184
- typedIdentifier('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword()))
185
-
143
+ typedIdentifier(
144
+ 'client',
145
+ t.tsTypeAnnotation(
146
+ t.tsTypeReference(t.identifier('CosmWasmClient'))
147
+ )
148
+ ),
149
+ typedIdentifier(
150
+ 'contractAddress',
151
+ t.tsTypeAnnotation(t.tsStringKeyword())
152
+ )
186
153
  ],
187
- t.blockStatement(
188
- [
189
-
190
- // client/contract set
191
- t.expressionStatement(
192
- t.assignmentExpression(
193
- '=',
194
- t.memberExpression(
195
- t.thisExpression(),
196
- t.identifier('client')
197
- ),
198
- t.identifier('client')
199
- )
200
- ),
201
- t.expressionStatement(
202
- t.assignmentExpression(
203
- '=',
204
- t.memberExpression(
205
- t.thisExpression(),
206
- t.identifier('contractAddress')
207
- ),
154
+ t.blockStatement([
155
+ // client/contract set
156
+ t.expressionStatement(
157
+ t.assignmentExpression(
158
+ '=',
159
+ t.memberExpression(t.thisExpression(), t.identifier('client')),
160
+ t.identifier('client')
161
+ )
162
+ ),
163
+ t.expressionStatement(
164
+ t.assignmentExpression(
165
+ '=',
166
+ t.memberExpression(
167
+ t.thisExpression(),
208
168
  t.identifier('contractAddress')
209
- )
210
- ),
211
-
212
- ...bindings
169
+ ),
170
+ t.identifier('contractAddress')
171
+ )
172
+ ),
213
173
 
214
- ]
215
- )),
174
+ ...bindings
175
+ ])
176
+ ),
216
177
 
217
178
  ...methods
218
-
219
179
  ],
220
- [
221
- t.tSExpressionWithTypeArguments(
222
- t.identifier(implementsClassName)
223
- )
224
- ])
180
+ [t.tSExpressionWithTypeArguments(t.identifier(implementsClassName))]
181
+ )
225
182
  );
226
183
  };
227
184
 
@@ -236,16 +193,16 @@ export const getWasmMethodArgs = (
236
193
  const obj = context.refLookup(jsonschema.$ref);
237
194
  // properties
238
195
  if (obj) {
239
- keys = Object.keys(obj.properties ?? {})
196
+ keys = Object.keys(obj.properties ?? {});
240
197
  }
241
198
 
242
199
  // tuple struct or otherwise, use the name of the reference
243
200
  if (!keys.length && obj?.oneOf) {
244
- // TODO????? ADAIR
201
+ // TODO????? ADAIR
245
202
  }
246
203
  }
247
204
 
248
- const args = keys.map(prop => {
205
+ const args = keys.map((prop) => {
249
206
  return t.objectProperty(
250
207
  t.identifier(prop),
251
208
  t.identifier(camel(prop)),
@@ -261,7 +218,6 @@ export const createWasmExecMethod = (
261
218
  context: RenderContext,
262
219
  jsonschema: JSONSchema
263
220
  ) => {
264
-
265
221
  context.addUtil('ExecuteResult');
266
222
  context.addUtil('StdFee');
267
223
  context.addUtil('Coin');
@@ -279,73 +235,59 @@ export const createWasmExecMethod = (
279
235
 
280
236
  const msgAction = t.identifier(underscoreName);
281
237
  // If the param is an identifier, we can just use it as is
282
- const msgActionValue = param?.type === 'Identifier' ? t.identifier(param.name) : t.objectExpression(args)
238
+ const msgActionValue =
239
+ param?.type === 'Identifier'
240
+ ? t.identifier(param.name)
241
+ : t.objectExpression(args);
283
242
 
284
243
  return t.classProperty(
285
244
  t.identifier(methodName),
286
245
  arrowFunctionExpression(
287
- param ? [
288
- // props
289
- param,
290
- ...CONSTANT_EXEC_PARAMS
291
- ] : CONSTANT_EXEC_PARAMS,
292
- t.blockStatement(
293
- [
294
- t.returnStatement(
295
- t.awaitExpression(
296
- t.callExpression(
246
+ param
247
+ ? [
248
+ // props
249
+ param,
250
+ ...CONSTANT_EXEC_PARAMS
251
+ ]
252
+ : CONSTANT_EXEC_PARAMS,
253
+ t.blockStatement([
254
+ t.returnStatement(
255
+ t.awaitExpression(
256
+ t.callExpression(
257
+ t.memberExpression(
258
+ t.memberExpression(t.thisExpression(), t.identifier('client')),
259
+ t.identifier('execute')
260
+ ),
261
+ [
262
+ t.memberExpression(t.thisExpression(), t.identifier('sender')),
297
263
  t.memberExpression(
298
- t.memberExpression(
299
- t.thisExpression(),
300
- t.identifier('client')
301
- ),
302
- t.identifier('execute')
264
+ t.thisExpression(),
265
+ t.identifier('contractAddress')
303
266
  ),
304
- [
305
- t.memberExpression(
306
- t.thisExpression(),
307
- t.identifier('sender')
308
- ),
309
- t.memberExpression(
310
- t.thisExpression(),
311
- t.identifier('contractAddress')
312
- ),
313
- t.objectExpression(
314
- [
315
- t.objectProperty(
316
- msgAction,
317
- msgActionValue
318
- )
319
-
320
- ]
321
- ),
322
- t.identifier('fee'),
323
- t.identifier('memo'),
324
- t.identifier('funds')
325
- ]
326
- )
267
+ t.objectExpression([
268
+ t.objectProperty(msgAction, msgActionValue)
269
+ ]),
270
+ t.identifier('fee'),
271
+ t.identifier('memo'),
272
+ t.identifier('_funds')
273
+ ]
327
274
  )
328
275
  )
329
- ]
330
- ),
276
+ )
277
+ ]),
331
278
  // return type
332
279
  t.tsTypeAnnotation(
333
280
  t.tsTypeReference(
334
281
  t.identifier('Promise'),
335
- t.tsTypeParameterInstantiation(
336
- [
337
- t.tSTypeReference(
338
- t.identifier('ExecuteResult')
339
- )
340
- ]
341
- )
282
+ t.tsTypeParameterInstantiation([
283
+ t.tSTypeReference(t.identifier('ExecuteResult'))
284
+ ])
342
285
  )
343
286
  ),
344
287
  true
345
288
  )
346
289
  );
347
-
348
- }
290
+ };
349
291
 
350
292
  export const createExecuteClass = (
351
293
  context: RenderContext,
@@ -354,33 +296,29 @@ export const createExecuteClass = (
354
296
  extendsClassName: string | null,
355
297
  execMsg: ExecuteMsg
356
298
  ) => {
357
-
358
299
  context.addUtil('SigningCosmWasmClient');
359
300
 
360
301
  const propertyNames = getMessageProperties(execMsg)
361
- .map(method => Object.keys(method.properties)?.[0])
302
+ .map((method) => Object.keys(method.properties)?.[0])
362
303
  .filter(Boolean);
363
304
 
364
- const bindings = propertyNames
365
- .map(camel)
366
- .map(bindMethod);
305
+ const bindings = propertyNames.map(camel).map(bindMethod);
367
306
 
368
- const methods = getMessageProperties(execMsg)
369
- .map(schema => {
370
- return createWasmExecMethod(context, schema)
371
- });
307
+ const methods = getMessageProperties(execMsg).map((schema) => {
308
+ return createWasmExecMethod(context, schema);
309
+ });
372
310
 
373
311
  const blockStmt = [];
374
312
 
375
313
  if (extendsClassName) {
376
- blockStmt.push( // super()
377
- t.expressionStatement(t.callExpression(
378
- t.super(),
379
- [
314
+ blockStmt.push(
315
+ // super()
316
+ t.expressionStatement(
317
+ t.callExpression(t.super(), [
380
318
  t.identifier('client'),
381
319
  t.identifier('contractAddress')
382
- ]
383
- ))
320
+ ])
321
+ )
384
322
  );
385
323
  }
386
324
 
@@ -389,78 +327,85 @@ export const createExecuteClass = (
389
327
  t.expressionStatement(
390
328
  t.assignmentExpression(
391
329
  '=',
392
- t.memberExpression(
393
- t.thisExpression(),
394
- t.identifier('client')
395
- ),
330
+ t.memberExpression(t.thisExpression(), t.identifier('client')),
396
331
  t.identifier('client')
397
332
  )
398
333
  ),
399
334
  t.expressionStatement(
400
335
  t.assignmentExpression(
401
336
  '=',
402
- t.memberExpression(
403
- t.thisExpression(),
404
- t.identifier('sender')
405
- ),
337
+ t.memberExpression(t.thisExpression(), t.identifier('sender')),
406
338
  t.identifier('sender')
407
339
  )
408
340
  ),
409
341
  t.expressionStatement(
410
342
  t.assignmentExpression(
411
343
  '=',
412
- t.memberExpression(
413
- t.thisExpression(),
414
- t.identifier('contractAddress')
415
- ),
344
+ t.memberExpression(t.thisExpression(), t.identifier('contractAddress')),
416
345
  t.identifier('contractAddress')
417
346
  )
418
347
  ),
419
348
  ...bindings
420
349
  ]);
421
350
 
422
- const noImplicitOverride = context.options.client.noImplicitOverride && extendsClassName && context.options.client.execExtendsQuery;
351
+ const noImplicitOverride =
352
+ context.options.client.noImplicitOverride &&
353
+ extendsClassName &&
354
+ context.options.client.execExtendsQuery;
423
355
 
424
356
  return t.exportNamedDeclaration(
425
- classDeclaration(className,
357
+ classDeclaration(
358
+ className,
426
359
  [
427
360
  // client
428
- classProperty('client', t.tsTypeAnnotation(
429
- t.tsTypeReference(t.identifier('SigningCosmWasmClient'))
430
- ), false, false, noImplicitOverride),
361
+ classProperty(
362
+ 'client',
363
+ t.tsTypeAnnotation(
364
+ t.tsTypeReference(t.identifier('SigningCosmWasmClient'))
365
+ ),
366
+ false,
367
+ false,
368
+ noImplicitOverride
369
+ ),
431
370
 
432
371
  // sender
433
- classProperty('sender', t.tsTypeAnnotation(
434
- t.tsStringKeyword()
435
- )),
372
+ classProperty('sender', t.tsTypeAnnotation(t.tsStringKeyword())),
436
373
 
437
374
  // contractAddress
438
- classProperty('contractAddress', t.tsTypeAnnotation(
439
- t.tsStringKeyword()
440
- ), false, false, noImplicitOverride),
375
+ classProperty(
376
+ 'contractAddress',
377
+ t.tsTypeAnnotation(t.tsStringKeyword()),
378
+ false,
379
+ false,
380
+ noImplicitOverride
381
+ ),
441
382
 
442
383
  // constructor
443
- t.classMethod('constructor',
384
+ t.classMethod(
385
+ 'constructor',
444
386
  t.identifier('constructor'),
445
387
  [
446
- typedIdentifier('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('SigningCosmWasmClient')))),
388
+ typedIdentifier(
389
+ 'client',
390
+ t.tsTypeAnnotation(
391
+ t.tsTypeReference(t.identifier('SigningCosmWasmClient'))
392
+ )
393
+ ),
447
394
  typedIdentifier('sender', t.tsTypeAnnotation(t.tsStringKeyword())),
448
- typedIdentifier('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword()))
395
+ typedIdentifier(
396
+ 'contractAddress',
397
+ t.tsTypeAnnotation(t.tsStringKeyword())
398
+ )
449
399
  ],
450
- t.blockStatement(
451
- blockStmt
452
- )),
400
+ t.blockStatement(blockStmt)
401
+ ),
453
402
  ...methods
454
403
  ],
455
- [
456
- t.tSExpressionWithTypeArguments(
457
- t.identifier(implementsClassName)
458
- )
459
- ],
404
+ [t.tSExpressionWithTypeArguments(t.identifier(implementsClassName))],
460
405
  extendsClassName ? t.identifier(extendsClassName) : null
461
406
  )
462
407
  );
463
- }
408
+ };
464
409
 
465
410
  export const createExecuteInterface = (
466
411
  context: RenderContext,
@@ -468,50 +413,41 @@ export const createExecuteInterface = (
468
413
  extendsClassName: string | null,
469
414
  execMsg: ExecuteMsg
470
415
  ) => {
416
+ const methods = getMessageProperties(execMsg).map((jsonschema) => {
417
+ const underscoreName = Object.keys(jsonschema.properties)[0];
418
+ const methodName = camel(underscoreName);
419
+ return createPropertyFunctionWithObjectParamsForExec(
420
+ context,
421
+ methodName,
422
+ 'ExecuteResult',
423
+ jsonschema.properties[underscoreName]
424
+ );
425
+ });
471
426
 
472
- const methods = getMessageProperties(execMsg)
473
- .map(jsonschema => {
474
- const underscoreName = Object.keys(jsonschema.properties)[0];
475
- const methodName = camel(underscoreName);
476
- return createPropertyFunctionWithObjectParamsForExec(
477
- context,
478
- methodName,
479
- 'ExecuteResult',
480
- jsonschema.properties[underscoreName]
481
- );
482
- });
483
-
484
- const extendsAst = extendsClassName ? [t.tSExpressionWithTypeArguments(
485
- t.identifier(extendsClassName)
486
- )] : []
427
+ const extendsAst = extendsClassName
428
+ ? [t.tSExpressionWithTypeArguments(t.identifier(extendsClassName))]
429
+ : [];
487
430
 
488
431
  return t.exportNamedDeclaration(
489
432
  t.tsInterfaceDeclaration(
490
433
  t.identifier(className),
491
434
  null,
492
435
  extendsAst,
493
- t.tSInterfaceBody(
494
- [
495
-
496
- // contract address
497
- t.tSPropertySignature(
498
- t.identifier('contractAddress'),
499
- t.tsTypeAnnotation(
500
- t.tsStringKeyword()
501
- )
502
- ),
436
+ t.tSInterfaceBody([
437
+ // contract address
438
+ t.tSPropertySignature(
439
+ t.identifier('contractAddress'),
440
+ t.tsTypeAnnotation(t.tsStringKeyword())
441
+ ),
503
442
 
504
- // contract address
505
- t.tSPropertySignature(
506
- t.identifier('sender'),
507
- t.tsTypeAnnotation(
508
- t.tsStringKeyword()
509
- )
510
- ),
443
+ // contract address
444
+ t.tSPropertySignature(
445
+ t.identifier('sender'),
446
+ t.tsTypeAnnotation(t.tsStringKeyword())
447
+ ),
511
448
 
512
- ...methods,
513
- ]
514
- )
449
+ ...methods
450
+ ])
515
451
  )
516
452
  );
517
453
  };
@@ -527,10 +463,8 @@ export const createPropertyFunctionWithObjectParams = (
527
463
  const func = {
528
464
  type: 'TSFunctionType',
529
465
  typeAnnotation: promiseTypeAnnotation(responseType),
530
- parameters: obj ? [
531
- obj
532
- ] : []
533
- }
466
+ parameters: obj ? [obj] : []
467
+ };
534
468
 
535
469
  return t.tSPropertySignature(
536
470
  t.identifier(methodName),
@@ -547,7 +481,6 @@ export const createPropertyFunctionWithObjectParamsForExec = (
547
481
  responseType: string,
548
482
  jsonschema: JSONSchema
549
483
  ) => {
550
-
551
484
  context.addUtil('Coin');
552
485
 
553
486
  const obj = createTypedObjectParams(context, jsonschema);
@@ -555,12 +488,8 @@ export const createPropertyFunctionWithObjectParamsForExec = (
555
488
  const func = {
556
489
  type: 'TSFunctionType',
557
490
  typeAnnotation: promiseTypeAnnotation(responseType),
558
- parameters: obj ? [
559
- obj,
560
- ...FIXED_EXECUTE_PARAMS
561
-
562
- ] : FIXED_EXECUTE_PARAMS
563
- }
491
+ parameters: obj ? [obj, ...FIXED_EXECUTE_PARAMS] : FIXED_EXECUTE_PARAMS
492
+ };
564
493
 
565
494
  return t.tSPropertySignature(
566
495
  t.identifier(methodName),
@@ -576,47 +505,40 @@ export const createQueryInterface = (
576
505
  className: string,
577
506
  queryMsg: QueryMsg
578
507
  ) => {
579
- const methods = getMessageProperties(queryMsg)
580
- .map(jsonschema => {
581
- const underscoreName = Object.keys(jsonschema.properties)[0];
582
- const methodName = camel(underscoreName);
583
- const responseType = getResponseType(context, underscoreName);
584
- return createPropertyFunctionWithObjectParams(
585
- context,
586
- methodName,
587
- responseType,
588
- jsonschema.properties[underscoreName]
589
- );
590
- });
508
+ const methods = getMessageProperties(queryMsg).map((jsonschema) => {
509
+ const underscoreName = Object.keys(jsonschema.properties)[0];
510
+ const methodName = camel(underscoreName);
511
+ const responseType = getResponseType(context, underscoreName);
512
+ return createPropertyFunctionWithObjectParams(
513
+ context,
514
+ methodName,
515
+ responseType,
516
+ jsonschema.properties[underscoreName]
517
+ );
518
+ });
591
519
 
592
520
  return t.exportNamedDeclaration(
593
521
  t.tsInterfaceDeclaration(
594
522
  t.identifier(className),
595
523
  null,
596
524
  [],
597
- t.tSInterfaceBody(
598
- [
599
- t.tSPropertySignature(
600
- t.identifier('contractAddress'),
601
- t.tsTypeAnnotation(
602
- t.tsStringKeyword()
603
- )
604
- ),
605
- ...methods
606
- ]
607
- )
525
+ t.tSInterfaceBody([
526
+ t.tSPropertySignature(
527
+ t.identifier('contractAddress'),
528
+ t.tsTypeAnnotation(t.tsStringKeyword())
529
+ ),
530
+ ...methods
531
+ ])
608
532
  )
609
533
  );
610
534
  };
611
535
 
612
-
613
536
  export const createTypeOrInterface = (
614
537
  context: RenderContext,
615
538
  Type: string,
616
539
  jsonschema: JSONSchema
617
540
  ) => {
618
541
  if (jsonschema.type !== 'object') {
619
-
620
542
  if (!jsonschema.type) {
621
543
  return t.exportNamedDeclaration(
622
544
  t.tsTypeAliasDeclaration(
@@ -624,7 +546,7 @@ export const createTypeOrInterface = (
624
546
  null,
625
547
  t.tsTypeReference(t.identifier(jsonschema.title))
626
548
  )
627
- )
549
+ );
628
550
  }
629
551
 
630
552
  return t.exportNamedDeclaration(
@@ -635,14 +557,10 @@ export const createTypeOrInterface = (
635
557
  )
636
558
  );
637
559
  }
638
- const props = Object.keys(jsonschema.properties ?? {})
639
- .map(prop => {
640
- const { type, optional } = getPropertyType(context, jsonschema, prop);
641
- return propertySignature(camel(prop), t.tsTypeAnnotation(
642
- type
643
- ), optional);
644
- });
645
-
560
+ const props = Object.keys(jsonschema.properties ?? {}).map((prop) => {
561
+ const { type, optional } = getPropertyType(context, jsonschema, prop);
562
+ return propertySignature(camel(prop), t.tsTypeAnnotation(type), optional);
563
+ });
646
564
 
647
565
  return t.exportNamedDeclaration(
648
566
  t.tsInterfaceDeclaration(
@@ -651,12 +569,10 @@ export const createTypeOrInterface = (
651
569
  [],
652
570
  t.tsInterfaceBody(
653
571
  // @ts-ignore:next-line
654
- [
655
- ...props
656
- ]
572
+ [...props]
657
573
  )
658
574
  )
659
- )
575
+ );
660
576
  };
661
577
 
662
578
  export const createTypeInterface = (
@@ -664,9 +580,5 @@ export const createTypeInterface = (
664
580
  jsonschema: JSONSchema
665
581
  ) => {
666
582
  const Type = jsonschema.title;
667
- return createTypeOrInterface(
668
- context,
669
- Type,
670
- jsonschema
671
- );
583
+ return createTypeOrInterface(context, Type, jsonschema);
672
584
  };