wasm-ast-types 0.11.3 → 0.13.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.
Files changed (55) hide show
  1. package/main/client/test/ts-client.issue-71.test.js +103 -0
  2. package/main/context/context.js +2 -1
  3. package/main/utils/types.js +20 -7
  4. package/module/client/test/ts-client.issue-71.test.js +21 -0
  5. package/module/context/context.js +2 -1
  6. package/module/utils/types.js +20 -7
  7. package/package.json +5 -3
  8. package/src/client/client.ts +665 -0
  9. package/src/client/index.ts +1 -0
  10. package/src/client/test/__snapshots__/ts-client.account-nfts.spec.ts.snap +497 -0
  11. package/src/client/test/__snapshots__/ts-client.arrays-ref.spec.ts.snap +452 -0
  12. package/src/client/test/__snapshots__/ts-client.arrays.spec.ts.snap +101 -0
  13. package/src/client/test/__snapshots__/ts-client.cw-named-groups.test.ts.snap +141 -0
  14. package/src/client/test/__snapshots__/ts-client.cw-proposal-single.test.ts.snap +341 -0
  15. package/src/client/test/__snapshots__/ts-client.empty-enums.spec.ts.snap +20 -0
  16. package/src/client/test/__snapshots__/ts-client.issue-71.test.ts.snap +432 -0
  17. package/src/client/test/__snapshots__/ts-client.issues.test.ts.snap +984 -0
  18. package/src/client/test/__snapshots__/ts-client.sg721.spec.ts.snap +350 -0
  19. package/src/client/test/__snapshots__/ts-client.spec.ts.snap +723 -0
  20. package/src/client/test/__snapshots__/ts-client.vectis.spec.ts.snap +337 -0
  21. package/src/client/test/ts-client.account-nfts.spec.ts +55 -0
  22. package/src/client/test/ts-client.arrays-ref.spec.ts +48 -0
  23. package/src/client/test/ts-client.arrays.spec.ts +58 -0
  24. package/src/client/test/ts-client.cw-named-groups.test.ts +48 -0
  25. package/src/client/test/ts-client.cw-proposal-single.test.ts +50 -0
  26. package/src/client/test/ts-client.empty-enums.spec.ts +28 -0
  27. package/src/client/test/ts-client.issue-71.test.ts +51 -0
  28. package/src/client/test/ts-client.issues.test.ts +52 -0
  29. package/src/client/test/ts-client.sg721.spec.ts +46 -0
  30. package/src/client/test/ts-client.spec.ts +166 -0
  31. package/src/client/test/ts-client.vectis.spec.ts +97 -0
  32. package/src/context/context.ts +134 -0
  33. package/src/context/imports.ts +126 -0
  34. package/src/context/index.ts +2 -0
  35. package/src/index.ts +7 -0
  36. package/src/message-composer/__snapshots__/message-composer.spec.ts.snap +271 -0
  37. package/src/message-composer/index.ts +1 -0
  38. package/src/message-composer/message-composer.spec.ts +25 -0
  39. package/src/message-composer/message-composer.ts +305 -0
  40. package/src/react-query/__snapshots__/react-query.spec.ts.snap +913 -0
  41. package/src/react-query/index.ts +1 -0
  42. package/src/react-query/react-query.spec.ts +75 -0
  43. package/src/react-query/react-query.ts +913 -0
  44. package/src/recoil/__snapshots__/recoil.spec.ts.snap +203 -0
  45. package/src/recoil/index.ts +1 -0
  46. package/src/recoil/recoil.spec.ts +38 -0
  47. package/src/recoil/recoil.ts +307 -0
  48. package/src/types.ts +44 -0
  49. package/src/utils/__snapshots__/babel.spec.ts.snap +75 -0
  50. package/src/utils/babel.spec.ts +511 -0
  51. package/src/utils/babel.ts +315 -0
  52. package/src/utils/index.ts +2 -0
  53. package/src/utils/types.ts +459 -0
  54. package/types/client/client.d.ts +1 -1
  55. package/types/context/context.d.ts +1 -0
@@ -0,0 +1,511 @@
1
+ import { importStmt } from './babel'
2
+ import * as t from '@babel/types';
3
+
4
+ import {
5
+ bindMethod,
6
+ typedIdentifier,
7
+ promiseTypeAnnotation,
8
+ classDeclaration,
9
+ classProperty,
10
+ arrowFunctionExpression
11
+ } from './babel'
12
+ import { expectCode } from '../../test-utils';
13
+
14
+ it('top import', async () => {
15
+ expectCode(
16
+ importStmt([
17
+ 'CosmWasmClient',
18
+ 'ExecuteResult',
19
+ 'SigningCosmWasmClient'
20
+ ], '@cosmjs/cosmwasm-stargate')
21
+ );
22
+ });
23
+
24
+ it('interfaces', async () => {
25
+ expectCode(
26
+ t.program(
27
+ [
28
+ t.exportNamedDeclaration(
29
+ t.tsInterfaceDeclaration(
30
+ t.identifier('SG721ReadOnlyInstance'),
31
+ null,
32
+ [],
33
+ t.tSInterfaceBody(
34
+ [
35
+ t.tSPropertySignature(
36
+ t.identifier('contractAddress'),
37
+ t.tsTypeAnnotation(
38
+ t.tsStringKeyword()
39
+ )
40
+ ),
41
+ // methods
42
+
43
+ t.tSPropertySignature(
44
+ t.identifier('tokens'),
45
+ t.tsTypeAnnotation(
46
+ t.tsFunctionType(
47
+ null,
48
+ [
49
+ typedIdentifier('owner', t.tsTypeAnnotation(
50
+ t.tsStringKeyword()
51
+ )),
52
+ typedIdentifier('startAfter', t.tsTypeAnnotation(
53
+ t.tsStringKeyword()
54
+ ), true),
55
+ typedIdentifier('limit', t.tsTypeAnnotation(
56
+ t.tsStringKeyword()
57
+ ), true)
58
+ ],
59
+ promiseTypeAnnotation('TokensResponse')
60
+ )
61
+ )
62
+ )
63
+ ]
64
+ )
65
+ )
66
+ ),
67
+
68
+ // extends
69
+
70
+ t.exportNamedDeclaration(
71
+ t.tsInterfaceDeclaration(
72
+ t.identifier('SG721Instance'),
73
+ null,
74
+ [
75
+ t.tSExpressionWithTypeArguments(
76
+ t.identifier('SG721ReadOnlyInstance')
77
+ )
78
+ ],
79
+ t.tSInterfaceBody(
80
+ [
81
+
82
+ // contract address
83
+
84
+ t.tSPropertySignature(
85
+ t.identifier('contractAddress'),
86
+ t.tsTypeAnnotation(
87
+ t.tsStringKeyword()
88
+ )
89
+ ),
90
+
91
+ // METHOD
92
+ t.tSPropertySignature(
93
+ t.identifier('mint'),
94
+ t.tsTypeAnnotation(
95
+ t.tsFunctionType(
96
+ null,
97
+ [
98
+ typedIdentifier('sender', t.tsTypeAnnotation(
99
+ t.tsStringKeyword()
100
+ )),
101
+ typedIdentifier('anotherProp', t.tsTypeAnnotation(
102
+ t.tsStringKeyword()
103
+ )),
104
+ typedIdentifier('prop3', t.tsTypeAnnotation(
105
+ t.tsStringKeyword()
106
+ ))
107
+ ],
108
+ promiseTypeAnnotation('ExecuteResult')
109
+ )
110
+ )
111
+ )
112
+ ]
113
+ )
114
+ )
115
+ )
116
+
117
+ ]
118
+ )
119
+ )
120
+
121
+ });
122
+
123
+
124
+ it('readonly classes', async () => {
125
+ expectCode(
126
+ t.program(
127
+ [
128
+
129
+ t.exportNamedDeclaration(
130
+ classDeclaration('SG721QueryClient',
131
+ [
132
+ // client
133
+ classProperty('client', t.tsTypeAnnotation(
134
+ t.tsTypeReference(t.identifier('CosmWasmClient'))
135
+ )),
136
+
137
+ // contractAddress
138
+ classProperty('contractAddress', t.tsTypeAnnotation(
139
+ t.tsStringKeyword()
140
+ )),
141
+
142
+ // constructor
143
+ t.classMethod('constructor',
144
+ t.identifier('constructor'),
145
+ [
146
+ typedIdentifier('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CosmWasmClient')))),
147
+ typedIdentifier('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword()))
148
+
149
+ ],
150
+ t.blockStatement(
151
+ [
152
+
153
+ // client/contract set
154
+ t.expressionStatement(
155
+ t.assignmentExpression(
156
+ '=',
157
+ t.memberExpression(
158
+ t.thisExpression(),
159
+ t.identifier('client')
160
+ ),
161
+ t.identifier('client')
162
+ )
163
+ ),
164
+ t.expressionStatement(
165
+ t.assignmentExpression(
166
+ '=',
167
+ t.memberExpression(
168
+ t.thisExpression(),
169
+ t.identifier('contractAddress')
170
+ ),
171
+ t.identifier('contractAddress')
172
+ )
173
+ ),
174
+
175
+
176
+ // bindings
177
+ bindMethod('approval'),
178
+ bindMethod('otherProp'),
179
+ bindMethod('hello'),
180
+ bindMethod('mintme')
181
+ ]
182
+ )),
183
+
184
+ // methods:
185
+ t.classProperty(
186
+ t.identifier('approval'),
187
+ arrowFunctionExpression(
188
+ [
189
+ // props
190
+ typedIdentifier('owner', t.tsTypeAnnotation(
191
+ t.tsStringKeyword()
192
+ )),
193
+ //
194
+ typedIdentifier('spender', t.tsTypeAnnotation(
195
+ t.tsStringKeyword()
196
+ ))
197
+ ],
198
+ t.blockStatement(
199
+ [
200
+ t.returnStatement(
201
+ t.callExpression(
202
+ t.memberExpression(
203
+ t.memberExpression(
204
+ t.thisExpression(),
205
+ t.identifier('client')
206
+ ),
207
+ t.identifier('queryContractSmart')
208
+ ),
209
+ [
210
+ t.memberExpression(t.thisExpression(), t.identifier('contractAddress')),
211
+ t.objectExpression([
212
+ // props
213
+ t.objectProperty(
214
+ t.identifier('owner'),
215
+ t.identifier('owner'),
216
+ false,
217
+ true
218
+ ),
219
+
220
+ t.objectProperty(
221
+ t.identifier('spender'),
222
+ t.identifier('spender'),
223
+ false,
224
+ true
225
+ ),
226
+
227
+ ])
228
+ ]
229
+ )
230
+ )
231
+ ]
232
+ ),
233
+ t.tsTypeAnnotation(
234
+ t.tsTypeReference(
235
+ t.identifier('Promise'),
236
+ t.tsTypeParameterInstantiation(
237
+ [
238
+ t.tSTypeReference(
239
+ t.identifier('ApprovalResponse')
240
+ )
241
+ ]
242
+ )
243
+ )
244
+ ),
245
+ true
246
+ )
247
+ )
248
+
249
+ ],
250
+ [
251
+ t.tSExpressionWithTypeArguments(
252
+ t.identifier('SG721ReadOnlyInstance')
253
+ )
254
+ ])
255
+ ),
256
+
257
+
258
+
259
+
260
+
261
+ ]
262
+ )
263
+ )
264
+
265
+ });
266
+
267
+ it('mutation classes', async () => {
268
+ expectCode(
269
+ t.program(
270
+ [
271
+
272
+ t.exportNamedDeclaration(
273
+ classDeclaration('SG721Client',
274
+ [
275
+ // client
276
+ classProperty('client', t.tsTypeAnnotation(
277
+ t.tsTypeReference(t.identifier('SigningCosmWasmClient'))
278
+ )),
279
+
280
+ // contractAddress
281
+ classProperty('contractAddress', t.tsTypeAnnotation(
282
+ t.tsStringKeyword()
283
+ )),
284
+
285
+ // constructor
286
+ t.classMethod('constructor',
287
+ t.identifier('constructor'),
288
+ [
289
+ typedIdentifier('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('SigningCosmWasmClient')))),
290
+ typedIdentifier('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword()))
291
+ ],
292
+ t.blockStatement(
293
+ [
294
+ // super()
295
+ t.expressionStatement(t.callExpression(
296
+ t.super(),
297
+ [
298
+ t.identifier('client'),
299
+ t.identifier('contractAddress')
300
+ ]
301
+ )),
302
+
303
+ // client/contract set
304
+ t.expressionStatement(
305
+ t.assignmentExpression(
306
+ '=',
307
+ t.memberExpression(
308
+ t.thisExpression(),
309
+ t.identifier('client')
310
+ ),
311
+ t.identifier('client')
312
+ )
313
+ ),
314
+ t.expressionStatement(
315
+ t.assignmentExpression(
316
+ '=',
317
+ t.memberExpression(
318
+ t.thisExpression(),
319
+ t.identifier('contractAddress')
320
+ ),
321
+ t.identifier('contractAddress')
322
+ )
323
+ ),
324
+
325
+ // bindings
326
+ bindMethod('approval'),
327
+ bindMethod('otherProp'),
328
+ bindMethod('hello'),
329
+ bindMethod('mintme')
330
+ ]
331
+ )),
332
+
333
+ // methods:
334
+ t.classProperty(
335
+ t.identifier('mint'),
336
+ arrowFunctionExpression(
337
+ [
338
+ // props
339
+ typedIdentifier('sender', t.tsTypeAnnotation(
340
+ t.tsStringKeyword()
341
+ )),
342
+ typedIdentifier('tokenId', t.tsTypeAnnotation(
343
+ t.tsStringKeyword()
344
+ )),
345
+ typedIdentifier('owner', t.tsTypeAnnotation(
346
+ t.tsStringKeyword()
347
+ )),
348
+ typedIdentifier('token_uri', t.tsTypeAnnotation(
349
+ t.tsStringKeyword()
350
+ ))
351
+ ],
352
+ t.blockStatement(
353
+ [
354
+ t.returnStatement(
355
+ t.awaitExpression(
356
+ t.callExpression(
357
+ t.memberExpression(
358
+ t.memberExpression(
359
+ t.thisExpression(),
360
+ t.identifier('client')
361
+ ),
362
+ t.identifier('execute')
363
+ ),
364
+ [
365
+ t.identifier('sender'),
366
+ t.memberExpression(
367
+ t.thisExpression(),
368
+ t.identifier('contractAddress')
369
+ ),
370
+ t.objectExpression(
371
+ [
372
+ t.objectProperty(
373
+ t.identifier('mint'),
374
+ t.objectExpression([
375
+ t.objectProperty(
376
+ t.identifier('token_id'),
377
+ t.identifier('tokenId')
378
+ ),
379
+ t.objectProperty(
380
+ t.identifier('owner'),
381
+ t.identifier('owner')
382
+ ),
383
+ t.objectProperty(
384
+ t.identifier('token_uri'),
385
+ t.identifier('token_uri')
386
+ ),
387
+ t.objectProperty(
388
+ t.identifier('expression'),
389
+ t.objectExpression([])
390
+ )
391
+ ])
392
+ )
393
+
394
+ ]
395
+ ),
396
+ t.stringLiteral('auto')
397
+ ]
398
+ )
399
+ )
400
+ )
401
+ ]
402
+ ),
403
+ // return type
404
+ t.tsTypeAnnotation(
405
+ t.tsTypeReference(
406
+ t.identifier('Promise'),
407
+ t.tsTypeParameterInstantiation(
408
+ [
409
+ t.tSTypeReference(
410
+ t.identifier('ExecuteResult')
411
+ )
412
+ ]
413
+ )
414
+ )
415
+ ),
416
+ true
417
+ )
418
+ )
419
+
420
+ ],
421
+ [
422
+ t.tSExpressionWithTypeArguments(
423
+ t.identifier('SG721ReadOnlyInstance')
424
+ )
425
+ ],
426
+ t.identifier('SG721QueryClient')
427
+ )
428
+ ),
429
+
430
+
431
+
432
+
433
+
434
+ ]
435
+ )
436
+ )
437
+
438
+ });
439
+
440
+ it('object parms', () => {
441
+
442
+ const obj = t.objectPattern(
443
+ [
444
+ t.objectProperty(
445
+ t.identifier('includeExpired'),
446
+ t.identifier('includeExpired'),
447
+ false,
448
+ true
449
+ ),
450
+ t.objectProperty(
451
+ t.identifier('tokenId'),
452
+ t.identifier('tokenId'),
453
+ false,
454
+ true
455
+ )
456
+ ]
457
+ );
458
+ obj.typeAnnotation = t.tsTypeAnnotation(
459
+ t.tsTypeLiteral(
460
+ [
461
+ t.tsPropertySignature(
462
+ t.identifier('includeExpired'),
463
+ t.tsTypeAnnotation(
464
+ t.tsBooleanKeyword()
465
+ )
466
+ ),
467
+ t.tsPropertySignature(
468
+ t.identifier('tokenId'),
469
+ t.tsTypeAnnotation(
470
+ t.tsStringKeyword()
471
+ )
472
+ )
473
+ ]
474
+ )
475
+ )
476
+ expectCode(
477
+ t.program(
478
+ [
479
+ t.expressionStatement(
480
+ t.assignmentExpression(
481
+ '=',
482
+ t.identifier('ownerOf'),
483
+ arrowFunctionExpression(
484
+ [
485
+ obj
486
+ ],
487
+ t.blockStatement(
488
+ [
489
+ // body
490
+ ],
491
+ []
492
+ ),
493
+ t.tsTypeAnnotation(
494
+ t.tsTypeReference(
495
+ t.identifier('Promise'),
496
+ t.tsTypeParameterInstantiation(
497
+ [
498
+ t.tsTypeReference(
499
+ t.identifier('OwnerOfResponse')
500
+ )
501
+ ]
502
+ )
503
+ )
504
+ )
505
+ )
506
+ )
507
+ )
508
+ ]
509
+ )
510
+ );
511
+ })