wasm-ast-types 0.24.0 → 0.26.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 (77) hide show
  1. package/main/client/client.js +46 -72
  2. package/main/client/index.js +0 -2
  3. package/main/client/test/ts-client.account-nfts.spec.js +3 -5
  4. package/main/client/test/ts-client.arrays-ref.spec.js +0 -4
  5. package/main/client/test/ts-client.arrays.spec.js +3 -6
  6. package/main/client/test/ts-client.cw-named-groups.test.js +0 -4
  7. package/main/client/test/ts-client.cw-proposal-single.test.js +0 -5
  8. package/main/client/test/ts-client.empty-enums.spec.js +0 -4
  9. package/main/client/test/ts-client.issue-101.spec.js +0 -4
  10. package/main/client/test/ts-client.issue-103.test.js +0 -4
  11. package/main/client/test/ts-client.issue-71.test.js +28 -50
  12. package/main/client/test/ts-client.issue-98.test.js +3 -5
  13. package/main/client/test/ts-client.issues.test.js +28 -50
  14. package/main/client/test/ts-client.overrides.spec.js +0 -4
  15. package/main/client/test/ts-client.sg721.spec.js +0 -4
  16. package/main/client/test/ts-client.spec.js +0 -17
  17. package/main/client/test/ts-client.vectis.spec.js +0 -8
  18. package/main/client/test/ts-client.wager.spec.js +4 -5
  19. package/main/context/context.js +6 -33
  20. package/main/context/imports.js +7 -43
  21. package/main/context/index.js +0 -4
  22. package/main/index.js +4 -22
  23. package/main/{msg-builder → message-builder}/index.js +4 -6
  24. package/main/{msg-builder/msg-builder.js → message-builder/message-builder.js} +24 -30
  25. package/main/{msg-builder/msg-builder.spec.js → message-builder/message-builder.spec.js} +4 -10
  26. package/main/message-composer/index.js +0 -2
  27. package/main/message-composer/message-composer.js +18 -28
  28. package/main/message-composer/message-composer.spec.js +0 -5
  29. package/main/provider/index.js +0 -2
  30. package/main/provider/provider.js +2 -29
  31. package/main/provider/provider.spec.js +0 -3
  32. package/main/react-query/index.js +0 -2
  33. package/main/react-query/react-query.js +125 -152
  34. package/main/react-query/react-query.spec.js +0 -10
  35. package/main/recoil/index.js +0 -2
  36. package/main/recoil/recoil.js +0 -14
  37. package/main/recoil/recoil.spec.js +0 -8
  38. package/main/utils/babel.js +12 -98
  39. package/main/utils/babel.spec.js +72 -67
  40. package/main/utils/constants.js +0 -6
  41. package/main/utils/index.js +0 -7
  42. package/main/utils/ref.js +0 -3
  43. package/main/utils/types.js +22 -109
  44. package/module/client/client.js +46 -32
  45. package/module/client/test/ts-client.account-nfts.spec.js +3 -1
  46. package/module/client/test/ts-client.arrays.spec.js +3 -1
  47. package/module/client/test/ts-client.issue-101.spec.js +3 -1
  48. package/module/client/test/ts-client.issue-98.test.js +3 -1
  49. package/module/client/test/ts-client.wager.spec.js +4 -1
  50. package/module/context/context.js +9 -23
  51. package/module/context/imports.js +5 -24
  52. package/module/index.js +1 -1
  53. package/module/message-builder/index.js +1 -0
  54. package/module/{msg-builder/msg-builder.js → message-builder/message-builder.js} +22 -17
  55. package/module/{msg-builder/msg-builder.spec.js → message-builder/message-builder.spec.js} +4 -4
  56. package/module/message-composer/message-composer.js +18 -14
  57. package/module/provider/provider.js +0 -8
  58. package/module/react-query/react-query.js +77 -76
  59. package/module/utils/babel.js +4 -14
  60. package/module/utils/babel.spec.js +49 -23
  61. package/module/utils/types.js +18 -66
  62. package/package.json +2 -2
  63. package/src/context/context.ts +158 -158
  64. package/src/index.ts +1 -1
  65. package/src/{msg-builder/__snapshots__/msg-builder.spec.ts.snap → message-builder/__snapshots__/message-builder.spec.ts.snap} +2 -2
  66. package/src/message-builder/index.ts +1 -0
  67. package/src/{msg-builder/msg-builder.spec.ts → message-builder/message-builder.spec.ts} +6 -7
  68. package/src/{msg-builder/msg-builder.ts → message-builder/message-builder.ts} +5 -5
  69. package/src/react-query/react-query.spec.ts +1 -1
  70. package/types/context/context.d.ts +2 -2
  71. package/types/index.d.ts +1 -1
  72. package/types/message-builder/index.d.ts +1 -0
  73. package/types/message-builder/message-builder.d.ts +4 -0
  74. package/module/msg-builder/index.js +0 -1
  75. package/src/msg-builder/index.ts +0 -1
  76. package/types/msg-builder/index.d.ts +0 -1
  77. package/types/msg-builder/msg-builder.d.ts +0 -4
@@ -3,52 +3,43 @@ import { camel, pascal } from 'case';
3
3
  import { propertySignature } from './babel';
4
4
  export function getResponseType(context, underscoreName) {
5
5
  const methodName = camel(underscoreName);
6
- return pascal(context.contract?.responses?.[underscoreName]?.title ?? // after v1.1 is adopted, we can deprecate this and require the above response
6
+ return pascal(context.contract?.responses?.[underscoreName]?.title ??
7
+ // after v1.1 is adopted, we can deprecate this and require the above response
7
8
  `${methodName}Response`);
8
9
  }
9
10
  ;
10
-
11
11
  const getTypeStrFromRef = $ref => {
12
12
  if ($ref?.startsWith('#/definitions/')) {
13
13
  return $ref.replace('#/definitions/', '');
14
14
  }
15
-
16
15
  throw new Error('what is $ref: ' + $ref);
17
16
  };
18
-
19
17
  export const getTypeFromRef = $ref => {
20
18
  return t.tsTypeReference(t.identifier(getTypeStrFromRef($ref)));
21
19
  };
22
-
23
20
  const getArrayTypeFromRef = $ref => {
24
21
  return t.tsArrayType(getTypeFromRef($ref));
25
22
  };
26
-
27
23
  const getTypeOrRef = obj => {
28
24
  if (obj.type) {
29
25
  return getType(obj.type);
30
26
  }
31
-
32
27
  if (obj.$ref) {
33
28
  return getTypeFromRef(obj.$ref);
34
29
  }
35
-
36
30
  throw new Error('contact maintainers cannot find type for ' + obj);
37
31
  };
38
-
39
32
  const getArrayTypeFromItems = items => {
40
33
  // passing in [{"type":"string"}]
41
34
  if (Array.isArray(items)) {
42
35
  if (items[0]?.type === 'array') {
43
36
  return getArrayTypeFromItems(items[0]);
44
37
  }
45
-
46
38
  return t.tsArrayType(t.tsArrayType(getTypeOrRef(items[0])));
47
- } // passing in {"items": [{"type":"string"}]}
48
-
39
+ }
49
40
 
41
+ // passing in {"items": [{"type":"string"}]}
50
42
  const detect = detectType(items.type);
51
-
52
43
  if (detect.type === 'array') {
53
44
  if (Array.isArray(items.items)) {
54
45
  return t.tsArrayType(t.tsArrayType(getTypeOrRef(items.items[0])));
@@ -56,31 +47,24 @@ const getArrayTypeFromItems = items => {
56
47
  return t.tsArrayType(getArrayTypeFromItems(items.items));
57
48
  }
58
49
  }
59
-
60
50
  return t.tsArrayType(getType(detect.type));
61
51
  };
62
-
63
52
  export const detectType = type => {
64
53
  let optional = false;
65
54
  let theType = '';
66
-
67
55
  if (Array.isArray(type)) {
68
56
  if (type.length !== 2) {
69
57
  throw new Error('[getType(array length)] case not handled by transpiler. contact maintainers.');
70
58
  }
71
-
72
59
  const [nullableType, nullType] = type;
73
-
74
60
  if (nullType !== 'null') {
75
61
  throw new Error('[getType(null)] case not handled by transpiler. contact maintainers.');
76
62
  }
77
-
78
63
  theType = nullableType;
79
64
  optional = true;
80
65
  } else {
81
66
  theType = type;
82
67
  }
83
-
84
68
  return {
85
69
  type: theType,
86
70
  optional
@@ -89,19 +73,15 @@ export const detectType = type => {
89
73
  export const getTypeInfo = info => {
90
74
  let type = undefined;
91
75
  let optional = undefined;
92
-
93
76
  if (Array.isArray(info.anyOf)) {
94
77
  // assuming 2nd is null, but let's check to ensure
95
78
  if (info.anyOf.length !== 2) {
96
79
  throw new Error('case not handled by transpiler. contact maintainers.');
97
80
  }
98
-
99
81
  const [nullableType, nullType] = info.anyOf;
100
-
101
82
  if (nullType?.type !== 'null') {
102
83
  throw new Error('[nullableType.type]: case not handled by transpiler. contact maintainers.');
103
84
  }
104
-
105
85
  if (!nullableType?.$ref) {
106
86
  if (nullableType.title) {
107
87
  type = t.tsTypeReference(t.identifier(nullableType.title));
@@ -111,10 +91,8 @@ export const getTypeInfo = info => {
111
91
  } else {
112
92
  type = getTypeFromRef(nullableType?.$ref);
113
93
  }
114
-
115
94
  optional = true;
116
95
  }
117
-
118
96
  if (typeof info.type === 'string') {
119
97
  if (info.type === 'array') {
120
98
  if (typeof info.items === 'object' && !Array.isArray(info.items)) {
@@ -129,7 +107,8 @@ export const getTypeInfo = info => {
129
107
  }
130
108
  } else {
131
109
  if (Array.isArray(info.items)) {
132
- type = getArrayTypeFromItems(info.items); // console.log(typeof info.items === 'object');
110
+ type = getArrayTypeFromItems(info.items);
111
+ // console.log(typeof info.items === 'object');
133
112
  // console.log(Array.isArray(info.items));
134
113
  // console.log(info);
135
114
  } else {
@@ -142,33 +121,28 @@ export const getTypeInfo = info => {
142
121
  optional = detect.optional;
143
122
  }
144
123
  }
145
-
146
124
  if (Array.isArray(info.type)) {
147
125
  // assuming 2nd is null, but let's check to ensure
148
126
  if (info.type.length !== 2) {
149
127
  throw new Error('please report this to maintainers (field type): ' + JSON.stringify(info, null, 2));
150
128
  }
151
-
152
129
  const [nullableType, nullType] = info.type;
153
-
154
130
  if (nullType !== 'null') {
155
131
  throw new Error('please report this to maintainers (field type): ' + JSON.stringify(info, null, 2));
156
132
  }
157
-
158
133
  if (nullableType === 'array' && typeof info.items === 'object' && !Array.isArray(info.items)) {
159
134
  if (info.items.type) {
160
135
  const detect = detectType(info.items.type);
161
-
162
136
  if (detect.type === 'array') {
163
137
  // wen recursion?
164
138
  type = t.tsArrayType(getArrayTypeFromItems(info.items));
165
139
  } else {
166
140
  type = t.tsArrayType(getType(detect.type));
167
141
  }
168
-
169
142
  optional = detect.optional;
170
143
  } else if (info.items.$ref) {
171
- type = getArrayTypeFromRef(info.items.$ref); // } else if (info.items.title) {
144
+ type = getArrayTypeFromRef(info.items.$ref);
145
+ // } else if (info.items.title) {
172
146
  // type = t.tsArrayType(
173
147
  // t.tsTypeReference(
174
148
  // t.identifier(info.items.title)
@@ -182,17 +156,14 @@ export const getTypeInfo = info => {
182
156
  } else {
183
157
  const detect = detectType(nullableType);
184
158
  optional = detect.optional;
185
-
186
159
  if (detect.type === 'array') {
187
160
  type = getArrayTypeFromItems(info.items);
188
161
  } else {
189
162
  type = getType(detect.type);
190
163
  }
191
164
  }
192
-
193
165
  optional = true;
194
166
  }
195
-
196
167
  return {
197
168
  type,
198
169
  optional
@@ -202,13 +173,10 @@ export const getType = type => {
202
173
  switch (type) {
203
174
  case 'string':
204
175
  return t.tsStringKeyword();
205
-
206
176
  case 'boolean':
207
177
  return t.tSBooleanKeyword();
208
-
209
178
  case 'integer':
210
179
  return t.tsNumberKeyword();
211
-
212
180
  default:
213
181
  throw new Error('contact maintainers [unknown type]: ' + type);
214
182
  }
@@ -218,33 +186,25 @@ export const getPropertyType = (context, schema, prop) => {
218
186
  let info = props[prop];
219
187
  let type = null;
220
188
  let optional = !schema.required?.includes(prop);
221
-
222
189
  if (info.allOf && info.allOf.length === 1) {
223
190
  info = info.allOf[0];
224
191
  }
225
-
226
192
  if (typeof info.$ref === 'string') {
227
193
  type = getTypeFromRef(info.$ref);
228
194
  }
229
-
230
195
  const typeInfo = getTypeInfo(info);
231
-
232
196
  if (typeof typeInfo.optional !== 'undefined') {
233
197
  optional = typeInfo.optional;
234
198
  }
235
-
236
199
  if (typeof typeInfo.type !== 'undefined') {
237
200
  type = typeInfo.type;
238
201
  }
239
-
240
202
  if (!type) {
241
203
  throw new Error('cannot find type for ' + JSON.stringify(info));
242
204
  }
243
-
244
205
  if (schema.required?.includes(prop)) {
245
206
  optional = false;
246
207
  }
247
-
248
208
  return {
249
209
  type,
250
210
  optional
@@ -258,17 +218,15 @@ export function getPropertySignatureFromProp(context, jsonschema, prop, camelize
258
218
  throw new Error('getPropertySignatureFromProp() contact maintainer');
259
219
  }
260
220
  }
261
-
262
221
  if (Array.isArray(jsonschema.properties[prop].allOf)) {
263
222
  const isOptional = !jsonschema.required?.includes(prop);
264
223
  const unionTypes = jsonschema.properties[prop].allOf.map(el => {
265
224
  if (el.title) return el.title;
266
225
  if (el.$ref) return getTypeStrFromRef(el.$ref);
267
226
  return el.type;
268
- }); // @ts-ignore:next-line
269
-
227
+ });
228
+ // @ts-ignore:next-line
270
229
  const uniqUnionTypes = [...new Set(unionTypes)];
271
-
272
230
  if (uniqUnionTypes.length === 1) {
273
231
  return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(uniqUnionTypes[0]))), isOptional);
274
232
  } else {
@@ -280,24 +238,21 @@ export function getPropertySignatureFromProp(context, jsonschema, prop, camelize
280
238
  if (el.title) return el.title;
281
239
  if (el.$ref) return getTypeStrFromRef(el.$ref);
282
240
  return el.type;
283
- }); // @ts-ignore:next-line
284
-
241
+ });
242
+ // @ts-ignore:next-line
285
243
  const uniqUnionTypes = [...new Set(unionTypes)];
286
-
287
244
  if (uniqUnionTypes.length === 1) {
288
245
  return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(uniqUnionTypes[0]))), isOptional);
289
246
  } else {
290
247
  return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(t.tsUnionType(uniqUnionTypes.map(typ => t.tsTypeReference(t.identifier(typ))))), isOptional);
291
248
  }
292
249
  }
293
-
294
250
  try {
295
251
  getPropertyType(context, jsonschema, prop);
296
252
  } catch (e) {
297
253
  console.log(e);
298
254
  console.log(JSON.stringify(jsonschema, null, 2), prop);
299
255
  }
300
-
301
256
  const {
302
257
  type,
303
258
  optional
@@ -306,24 +261,22 @@ export function getPropertySignatureFromProp(context, jsonschema, prop, camelize
306
261
  }
307
262
  export const getParamsTypeAnnotation = (context, jsonschema, camelize = true) => {
308
263
  const keys = Object.keys(jsonschema.properties ?? {});
309
-
310
264
  if (!keys.length && jsonschema.$ref) {
311
265
  return t.tsTypeAnnotation(getTypeFromRef(jsonschema.$ref));
312
266
  }
313
-
314
267
  if (!keys.length) return undefined;
315
268
  const typedParams = keys.map(prop => getPropertySignatureFromProp(context, jsonschema, prop, camelize));
316
- return t.tsTypeAnnotation(t.tsTypeLiteral( // @ts-ignore:next-line
269
+ return t.tsTypeAnnotation(t.tsTypeLiteral(
270
+ // @ts-ignore:next-line
317
271
  [...typedParams]));
318
272
  };
319
273
  export const createTypedObjectParams = (context, jsonschema, camelize = true) => {
320
274
  const keys = Object.keys(jsonschema.properties ?? {});
321
-
322
275
  if (!keys.length) {
323
276
  // is there a ref?
324
277
  if (jsonschema.$ref) {
325
- const obj = context.refLookup(jsonschema.$ref); // If there is a oneOf, then we need to create a type for it
326
-
278
+ const obj = context.refLookup(jsonschema.$ref);
279
+ // If there is a oneOf, then we need to create a type for it
327
280
  if (obj?.oneOf) {
328
281
  // the actual type of the ref
329
282
  const refType = jsonschema.$ref.split('/').pop();
@@ -334,12 +287,11 @@ export const createTypedObjectParams = (context, jsonschema, camelize = true) =>
334
287
  } else if (obj) {
335
288
  return createTypedObjectParams(context, obj, camelize);
336
289
  }
337
- } // no results...
338
-
290
+ }
339
291
 
292
+ // no results...
340
293
  return;
341
294
  }
342
-
343
295
  const params = keys.map(prop => {
344
296
  return t.objectProperty(camelize ? t.identifier(camel(prop)) : t.identifier(prop), camelize ? t.identifier(camel(prop)) : t.identifier(prop), false, true);
345
297
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wasm-ast-types",
3
- "version": "0.24.0",
3
+ "version": "0.26.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",
@@ -88,5 +88,5 @@
88
88
  "case": "1.6.3",
89
89
  "deepmerge": "4.2.2"
90
90
  },
91
- "gitHead": "4553eb80cd89969583df6164d1c764ab5b289c63"
91
+ "gitHead": "fa5aea0a8de61f713a8dad85c5f7965e82c3b5c0"
92
92
  }