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,315 @@
1
+ import * as t from '@babel/types';
2
+ import { snake } from "case";
3
+ import { Field, QueryMsg, ExecuteMsg } from '../types';
4
+ import { TSTypeAnnotation, TSExpressionWithTypeArguments } from '@babel/types';
5
+
6
+ // t.TSPropertySignature - kind?
7
+ export const propertySignature = (
8
+ name: string,
9
+ typeAnnotation: t.TSTypeAnnotation,
10
+ optional: boolean = false
11
+ ) => {
12
+ return {
13
+ type: 'TSPropertySignature',
14
+ key: t.identifier(name),
15
+ typeAnnotation,
16
+ optional
17
+ }
18
+ };
19
+
20
+ export const identifier = (name: string, typeAnnotation: t.TSTypeAnnotation, optional: boolean = false): t.Identifier => {
21
+ const type = t.identifier(name);
22
+ type.typeAnnotation = typeAnnotation;
23
+ type.optional = optional;
24
+ return type;
25
+ };
26
+
27
+ export const tsTypeOperator = (typeAnnotation: t.TSType, operator: string) => {
28
+ const obj = t.tsTypeOperator(typeAnnotation);
29
+ obj.operator = operator;
30
+ return obj;
31
+ };
32
+
33
+ export const getMessageProperties = (msg: QueryMsg | ExecuteMsg) => {
34
+ if (msg.anyOf) return msg.anyOf;
35
+ if (msg.oneOf) return msg.oneOf;
36
+ if (msg.allOf) return msg.allOf;
37
+ return [];
38
+ }
39
+
40
+ export const tsPropertySignature = (
41
+ key: t.Expression,
42
+ typeAnnotation: t.TSTypeAnnotation,
43
+ optional: boolean
44
+ ) => {
45
+ const obj = t.tsPropertySignature(key, typeAnnotation);
46
+ obj.optional = optional;
47
+ return obj
48
+ };
49
+
50
+
51
+
52
+ export const tsObjectPattern = (
53
+ properties: (t.RestElement | t.ObjectProperty)[],
54
+ typeAnnotation: t.TSTypeAnnotation
55
+ ) => {
56
+ const obj = t.objectPattern(
57
+ properties
58
+ );
59
+ obj.typeAnnotation = typeAnnotation;
60
+ return obj;
61
+ }
62
+
63
+ export const callExpression = (
64
+ callee: t.Expression | t.V8IntrinsicIdentifier,
65
+ _arguments: (t.Expression | t.SpreadElement | t.ArgumentPlaceholder)[],
66
+ typeParameters: t.TSTypeParameterInstantiation
67
+ ) => {
68
+ const callExpr = t.callExpression(callee, _arguments);
69
+ callExpr.typeParameters = typeParameters;
70
+ return callExpr;
71
+ };
72
+
73
+ export const bindMethod = (name: string) => {
74
+ return t.expressionStatement(
75
+ t.assignmentExpression('=', t.memberExpression(
76
+ t.thisExpression(),
77
+ t.identifier(name)
78
+ ),
79
+ t.callExpression(
80
+ t.memberExpression(
81
+ t.memberExpression(
82
+ t.thisExpression(),
83
+ t.identifier(name)
84
+ ),
85
+ t.identifier('bind')
86
+ ),
87
+ [
88
+ t.thisExpression()
89
+ ]
90
+ )
91
+ )
92
+ )
93
+ }
94
+
95
+ export const typedIdentifier = (name: string, typeAnnotation: TSTypeAnnotation, optional: boolean = false) => {
96
+ const type = t.identifier(name);
97
+ type.typeAnnotation = typeAnnotation;
98
+ type.optional = optional;
99
+ return type;
100
+ }
101
+
102
+ export const promiseTypeAnnotation = (name) => {
103
+ return t.tsTypeAnnotation(
104
+ t.tsTypeReference(
105
+ t.identifier('Promise'),
106
+ t.tsTypeParameterInstantiation(
107
+ [
108
+ t.tsTypeReference(t.identifier(name))
109
+ ]
110
+ )
111
+ )
112
+ );
113
+ }
114
+
115
+ export const classDeclaration = (name: string, body: any[], implementsExressions: TSExpressionWithTypeArguments[] = [], superClass: t.Identifier = null) => {
116
+ const declaration = t.classDeclaration(
117
+ t.identifier(name),
118
+ superClass,
119
+ t.classBody(body)
120
+ );
121
+ if (implementsExressions.length) {
122
+ declaration.implements = implementsExressions;
123
+ }
124
+ return declaration;
125
+ };
126
+
127
+
128
+ export const classProperty = (name: string, typeAnnotation: TSTypeAnnotation = null, isReadonly: boolean = false, isStatic: boolean = false) => {
129
+ const prop = t.classProperty(t.identifier(name));
130
+ if (isReadonly) prop.readonly = true;
131
+ if (isStatic) prop.static = true;
132
+ if (typeAnnotation) prop.typeAnnotation = typeAnnotation;
133
+ return prop;
134
+ };
135
+
136
+ export const arrowFunctionExpression = (
137
+ params: (t.Identifier | t.Pattern | t.RestElement)[],
138
+ body: t.BlockStatement,
139
+ returnType: t.TSTypeAnnotation,
140
+ isAsync: boolean = false
141
+ ) => {
142
+ const func = t.arrowFunctionExpression(params, body, isAsync);
143
+ if (returnType) func.returnType = returnType;
144
+ return func;
145
+ };
146
+
147
+
148
+ export const recursiveNamespace = (names, moduleBlockBody) => {
149
+ if (!names || !names.length) return moduleBlockBody;
150
+ const name = names.pop();
151
+ const body = [
152
+ t.exportNamedDeclaration(
153
+ t.tsModuleDeclaration(
154
+ t.identifier(name),
155
+ t.tsModuleBlock(recursiveNamespace(names, moduleBlockBody))
156
+ )
157
+ )
158
+ ];
159
+ return body;
160
+ };
161
+
162
+ export const arrayTypeNDimensions = (body, n) => {
163
+ if (!n) return t.tsArrayType(body);
164
+ return t.tsArrayType(
165
+ arrayTypeNDimensions(body, n - 1)
166
+ );
167
+ };
168
+
169
+ export const FieldTypeAsts = {
170
+ string: () => {
171
+ return t.tsStringKeyword()
172
+ },
173
+ array: (type) => {
174
+ return t.tsArrayType(FieldTypeAsts[type]())
175
+ },
176
+ Duration: () => {
177
+ return t.tsTypeReference(t.identifier('Duration'))
178
+ },
179
+ Height: () => {
180
+ return t.tsTypeReference(t.identifier('Height'))
181
+ },
182
+ Coin: () => {
183
+ return t.tsTypeReference(t.identifier('Coin'))
184
+ },
185
+ Long: () => {
186
+ return t.tsTypeReference(t.identifier('Long'))
187
+ }
188
+ };
189
+
190
+ export const shorthandProperty = (prop: string) => {
191
+ return t.objectProperty(t.identifier(prop), t.identifier(prop), false, true);
192
+ };
193
+
194
+ export const importStmt = (names: string[], path: string) => {
195
+ return t.importDeclaration(
196
+ names.map(name => t.importSpecifier(t.identifier(name), t.identifier(name))),
197
+ t.stringLiteral(path));
198
+ };
199
+
200
+ export const importAs = (name: string, importAs: string, importPath: string) => {
201
+ return t.importDeclaration(
202
+ [
203
+ t.importSpecifier(
204
+ t.identifier(importAs),
205
+ t.identifier(name)
206
+ )
207
+ ],
208
+ t.stringLiteral(importPath)
209
+ )
210
+ };
211
+
212
+ export const importAminoMsg = () => {
213
+ return importStmt(['AminoMsg'], '@cosmjs/amino');
214
+ };
215
+
216
+ export const getFieldDimensionality = (field: Field) => {
217
+ let typeName = field.type;
218
+ const isArray = typeName.endsWith('[]');
219
+ let dimensions = 0;
220
+ if (isArray) {
221
+ dimensions = typeName.match(/\[\]/g).length - 1;
222
+ typeName = typeName.replace(/\[\]/g, '');
223
+ }
224
+ return {
225
+ typeName,
226
+ dimensions,
227
+ isArray
228
+ };
229
+ }
230
+
231
+ export const memberExpressionOrIdentifier = (names) => {
232
+ if (names.length === 1) {
233
+ return t.identifier(names[0])
234
+ }
235
+ if (names.length === 2) {
236
+ const [b, a] = names;
237
+ return t.memberExpression(
238
+ t.identifier(a),
239
+ t.identifier(b)
240
+ );
241
+ }
242
+ const [name, ...rest] = names;
243
+
244
+ return t.memberExpression(
245
+ memberExpressionOrIdentifier(rest),
246
+ t.identifier(name)
247
+ )
248
+ };
249
+
250
+ export const memberExpressionOrIdentifierSnake = (names) => {
251
+ if (names.length === 1) {
252
+ return t.identifier(snake(names[0]))
253
+ }
254
+ if (names.length === 2) {
255
+ const [b, a] = names;
256
+ return t.memberExpression(
257
+ t.identifier(snake(a)),
258
+ t.identifier(snake(b))
259
+ );
260
+ }
261
+ const [name, ...rest] = names;
262
+
263
+ return t.memberExpression(
264
+ memberExpressionOrIdentifierSnake(rest),
265
+ t.identifier(snake(name))
266
+ )
267
+ };
268
+
269
+ /**
270
+ * If optional, return a conditional, otherwise just the expression
271
+ */
272
+ export const optionalConditionalExpression = (test: t.Expression, expression: t.Expression, alternate: t.Expression, optional: boolean = false): t.Expression => {
273
+ return optional
274
+ ? t.conditionalExpression(
275
+ test,
276
+ expression,
277
+ alternate
278
+ )
279
+ : expression
280
+ }
281
+
282
+ export const typeRefOrUnionWithUndefined = (identifier: t.Identifier, optional: boolean = false): t.TSType => {
283
+ const typeReference = t.tsTypeReference(identifier)
284
+ return optional
285
+ ? t.tsUnionType([
286
+ typeReference,
287
+ t.tsUndefinedKeyword()
288
+ ])
289
+ : typeReference
290
+ }
291
+
292
+ export const parameterizedTypeReference = (identifier: string, from: t.TSType, omit: string | Array<string>) => {
293
+ return t.tsTypeReference(
294
+ t.identifier(identifier),
295
+ t.tsTypeParameterInstantiation([
296
+ from,
297
+ typeof omit === 'string'
298
+ ? t.tsLiteralType(t.stringLiteral(omit))
299
+ : t.tsUnionType(omit.map(o => t.tsLiteralType(t.stringLiteral(o))))
300
+ ])
301
+ )
302
+ }
303
+
304
+ /**
305
+ * omitTypeReference(t.tsTypeReference(t.identifier('Cw4UpdateMembersMutation'),),'args').....
306
+ * Omit<Cw4UpdateMembersMutation, 'args'>
307
+ */
308
+ export const omitTypeReference = (from: t.TSType, omit: string | Array<string>) => {
309
+ return parameterizedTypeReference('Omit', from, omit)
310
+ }
311
+
312
+
313
+ export const pickTypeReference = (from: t.TSType, pick: string | Array<string>) => {
314
+ return parameterizedTypeReference('Pick', from, pick)
315
+ }
@@ -0,0 +1,2 @@
1
+ export * from './babel';
2
+ export * from './types';