wasm-ast-types 0.16.0 → 0.18.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.
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ var _cwWager = _interopRequireDefault(require("../../../../../__fixtures__/wager/cw-wager.json"));
6
+
7
+ var _client = require("../client");
8
+
9
+ var _testUtils = require("../../../test-utils");
10
+
11
+ var queryCtx = (0, _testUtils.makeContext)(_cwWager["default"].query);
12
+ var executeCtx = (0, _testUtils.makeContext)(_cwWager["default"].execute);
13
+ it('query', function () {
14
+ (0, _testUtils.expectCode)((0, _client.createTypeInterface)(queryCtx, _cwWager["default"].query));
15
+ });
16
+ it('execute', function () {
17
+ (0, _testUtils.expectCode)((0, _client.createTypeInterface)(executeCtx, _cwWager["default"].execute));
18
+ });
19
+ it('query classes', function () {
20
+ (0, _testUtils.expectCode)((0, _client.createQueryClass)(queryCtx, 'WagerQueryClient', 'WagerReadOnlyInstance', _cwWager["default"].query));
21
+ }); // it('execute classes array types', () => {
22
+ // expectCode(createExecuteClass(
23
+ // ctx,
24
+ // 'SG721Client',
25
+ // 'SG721Instance',
26
+ // null,
27
+ // wagerJson
28
+ // ))
29
+ // });
30
+ // it('execute interfaces no extends', () => {
31
+ // expectCode(createExecuteInterface(
32
+ // ctx,
33
+ // 'SG721Instance',
34
+ // null,
35
+ // wagerJson
36
+ // ))
37
+ // });
@@ -199,6 +199,8 @@ exports.createReactQueryHook = createReactQueryHook;
199
199
  ```
200
200
  */
201
201
  var createReactQueryMutationArgsInterface = function createReactQueryMutationArgsInterface(_ref4) {
202
+ var _createTypedObjectPar;
203
+
202
204
  var context = _ref4.context,
203
205
  ExecuteClient = _ref4.ExecuteClient,
204
206
  mutationHookParamsTypeName = _ref4.mutationHookParamsTypeName,
@@ -206,12 +208,15 @@ var createReactQueryMutationArgsInterface = function createReactQueryMutationArg
206
208
  jsonschema = _ref4.jsonschema;
207
209
  var typedUseMutationOptions = t.tsTypeReference(t.identifier('UseMutationOptions'), useMutationTypeParameter);
208
210
  var body = [(0, _utils.tsPropertySignature)(t.identifier('client'), t.tsTypeAnnotation(t.tsTypeReference(t.identifier(ExecuteClient))), false)];
209
- var msgType = (0, _utils.createTypedObjectParams)(context, jsonschema).typeAnnotation;
211
+ var msgType = (_createTypedObjectPar = (0, _utils.createTypedObjectParams)(context, jsonschema)) === null || _createTypedObjectPar === void 0 ? void 0 : _createTypedObjectPar.typeAnnotation;
210
212
 
211
213
  if (msgType) {
212
- body.push(t.tsPropertySignature(t.identifier('msg'), msgType));
214
+ body.push(t.tsPropertySignature(t.identifier('msg'), // @ts-ignore
215
+ msgType));
213
216
  }
214
217
 
218
+ context.addUtil('StdFee');
219
+ context.addUtil('Coin');
215
220
  var optionalArgs = t.tsPropertySignature(t.identifier('args'), t.tsTypeAnnotation( // @ts-ignore:next-line
216
221
  t.tsTypeLiteral(_client.FIXED_EXECUTE_PARAMS.map(function (param) {
217
222
  return (0, _babel.propertySignature)(param.name, // @ts-ignore:next-line
@@ -164,7 +164,13 @@ var getTypeInfo = function getTypeInfo(info) {
164
164
  throw new Error('[info.items] case not handled by transpiler. contact maintainers.');
165
165
  }
166
166
  } else {
167
- throw new Error('[info.items] case not handled by transpiler. contact maintainers.');
167
+ if (Array.isArray(info.items)) {
168
+ type = getArrayTypeFromItems(info.items); // console.log(typeof info.items === 'object');
169
+ // console.log(Array.isArray(info.items));
170
+ // console.log(info);
171
+ } else {
172
+ throw new Error('[info.items] case not handled by transpiler. contact maintainers.');
173
+ }
168
174
  }
169
175
  } else {
170
176
  var detect = detectType(info.type);
@@ -0,0 +1,30 @@
1
+ import wagerJson from '../../../../../__fixtures__/wager/cw-wager.json';
2
+ import { createQueryClass, createTypeInterface } from '../client';
3
+ import { expectCode, makeContext } from '../../../test-utils';
4
+ const queryCtx = makeContext(wagerJson.query);
5
+ const executeCtx = makeContext(wagerJson.execute);
6
+ it('query', () => {
7
+ expectCode(createTypeInterface(queryCtx, wagerJson.query));
8
+ });
9
+ it('execute', () => {
10
+ expectCode(createTypeInterface(executeCtx, wagerJson.execute));
11
+ });
12
+ it('query classes', () => {
13
+ expectCode(createQueryClass(queryCtx, 'WagerQueryClient', 'WagerReadOnlyInstance', wagerJson.query));
14
+ }); // it('execute classes array types', () => {
15
+ // expectCode(createExecuteClass(
16
+ // ctx,
17
+ // 'SG721Client',
18
+ // 'SG721Instance',
19
+ // null,
20
+ // wagerJson
21
+ // ))
22
+ // });
23
+ // it('execute interfaces no extends', () => {
24
+ // expectCode(createExecuteInterface(
25
+ // ctx,
26
+ // 'SG721Instance',
27
+ // null,
28
+ // wagerJson
29
+ // ))
30
+ // });
@@ -177,12 +177,15 @@ export const createReactQueryMutationArgsInterface = ({
177
177
  }) => {
178
178
  const typedUseMutationOptions = t.tsTypeReference(t.identifier('UseMutationOptions'), useMutationTypeParameter);
179
179
  const body = [tsPropertySignature(t.identifier('client'), t.tsTypeAnnotation(t.tsTypeReference(t.identifier(ExecuteClient))), false)];
180
- const msgType = createTypedObjectParams(context, jsonschema).typeAnnotation;
180
+ const msgType = createTypedObjectParams(context, jsonschema)?.typeAnnotation;
181
181
 
182
182
  if (msgType) {
183
- body.push(t.tsPropertySignature(t.identifier('msg'), msgType));
183
+ body.push(t.tsPropertySignature(t.identifier('msg'), // @ts-ignore
184
+ msgType));
184
185
  }
185
186
 
187
+ context.addUtil('StdFee');
188
+ context.addUtil('Coin');
186
189
  const optionalArgs = t.tsPropertySignature(t.identifier('args'), t.tsTypeAnnotation( // @ts-ignore:next-line
187
190
  t.tsTypeLiteral(FIXED_EXECUTE_PARAMS.map(param => propertySignature(param.name, // @ts-ignore:next-line
188
191
  param.typeAnnotation, param.optional)))));
@@ -124,7 +124,13 @@ export const getTypeInfo = info => {
124
124
  throw new Error('[info.items] case not handled by transpiler. contact maintainers.');
125
125
  }
126
126
  } else {
127
- throw new Error('[info.items] case not handled by transpiler. contact maintainers.');
127
+ if (Array.isArray(info.items)) {
128
+ type = getArrayTypeFromItems(info.items); // console.log(typeof info.items === 'object');
129
+ // console.log(Array.isArray(info.items));
130
+ // console.log(info);
131
+ } else {
132
+ throw new Error('[info.items] case not handled by transpiler. contact maintainers.');
133
+ }
128
134
  }
129
135
  } else {
130
136
  const detect = detectType(info.type);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wasm-ast-types",
3
- "version": "0.16.0",
3
+ "version": "0.18.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": "9724a2787e6427b62e874ece3b733b5bfa5be2af"
91
+ "gitHead": "857ca4b9661677f7c1a72d0327fb327b0a318e33"
92
92
  }
@@ -0,0 +1,54 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`execute 1`] = `"export type ExecuteMsg = ExecuteMsg;"`;
4
+
5
+ exports[`query 1`] = `"export type QueryMsg = QueryMsg;"`;
6
+
7
+ exports[`query classes 1`] = `
8
+ "export class WagerQueryClient implements WagerReadOnlyInstance {
9
+ client: CosmWasmClient;
10
+ contractAddress: string;
11
+
12
+ constructor(client: CosmWasmClient, contractAddress: string) {
13
+ this.client = client;
14
+ this.contractAddress = contractAddress;
15
+ this.wagers = this.wagers.bind(this);
16
+ this.wager = this.wager.bind(this);
17
+ this.tokenStatus = this.tokenStatus.bind(this);
18
+ this.config = this.config.bind(this);
19
+ }
20
+
21
+ wagers = async (): Promise<WagersResponse> => {
22
+ return this.client.queryContractSmart(this.contractAddress, {
23
+ wagers: {}
24
+ });
25
+ };
26
+ wager = async ({
27
+ token
28
+ }: {
29
+ token: Addr[][];
30
+ }): Promise<WagerResponse> => {
31
+ return this.client.queryContractSmart(this.contractAddress, {
32
+ wager: {
33
+ token
34
+ }
35
+ });
36
+ };
37
+ tokenStatus = async ({
38
+ token
39
+ }: {
40
+ token: Addr[][];
41
+ }): Promise<TokenStatusResponse> => {
42
+ return this.client.queryContractSmart(this.contractAddress, {
43
+ token_status: {
44
+ token
45
+ }
46
+ });
47
+ };
48
+ config = async (): Promise<ConfigResponse> => {
49
+ return this.client.queryContractSmart(this.contractAddress, {
50
+ config: {}
51
+ });
52
+ };
53
+ }"
54
+ `;
@@ -0,0 +1,53 @@
1
+ import wagerJson from '../../../../../__fixtures__/wager/cw-wager.json';
2
+ import {
3
+ createQueryClass,
4
+ createExecuteClass,
5
+ createExecuteInterface,
6
+ createTypeInterface
7
+ } from '../client'
8
+ import { expectCode, makeContext } from '../../../test-utils';
9
+
10
+ const queryCtx = makeContext(wagerJson.query);
11
+ const executeCtx = makeContext(wagerJson.execute);
12
+
13
+ it('query', () => {
14
+ expectCode(createTypeInterface(
15
+ queryCtx,
16
+ wagerJson.query
17
+ ))
18
+ })
19
+
20
+ it('execute', () => {
21
+ expectCode(createTypeInterface(
22
+ executeCtx,
23
+ wagerJson.execute
24
+ ))
25
+ })
26
+
27
+ it('query classes', () => {
28
+ expectCode(createQueryClass(
29
+ queryCtx,
30
+ 'WagerQueryClient',
31
+ 'WagerReadOnlyInstance',
32
+ wagerJson.query
33
+ ))
34
+ });
35
+
36
+ // it('execute classes array types', () => {
37
+ // expectCode(createExecuteClass(
38
+ // ctx,
39
+ // 'SG721Client',
40
+ // 'SG721Instance',
41
+ // null,
42
+ // wagerJson
43
+ // ))
44
+ // });
45
+
46
+ // it('execute interfaces no extends', () => {
47
+ // expectCode(createExecuteInterface(
48
+ // ctx,
49
+ // 'SG721Instance',
50
+ // null,
51
+ // wagerJson
52
+ // ))
53
+ // });
@@ -407,16 +407,20 @@ export const createReactQueryMutationArgsInterface = ({
407
407
  )
408
408
  ];
409
409
 
410
- const msgType = createTypedObjectParams(context, jsonschema).typeAnnotation as unknown as t.TSTypeAnnotation
410
+ const msgType = createTypedObjectParams(context, jsonschema)?.typeAnnotation
411
411
 
412
412
  if (msgType) {
413
413
  body.push(
414
414
  t.tsPropertySignature(
415
415
  t.identifier('msg'),
416
+ // @ts-ignore
416
417
  msgType
417
418
  ));
418
419
  }
419
420
 
421
+ context.addUtil('StdFee');
422
+ context.addUtil('Coin');
423
+
420
424
  const optionalArgs = t.tsPropertySignature(
421
425
  t.identifier('args'),
422
426
  t.tsTypeAnnotation(
@@ -147,7 +147,14 @@ export const getTypeInfo = (info: JSONSchema) => {
147
147
  throw new Error('[info.items] case not handled by transpiler. contact maintainers.')
148
148
  }
149
149
  } else {
150
- throw new Error('[info.items] case not handled by transpiler. contact maintainers.')
150
+ if (Array.isArray(info.items)) {
151
+ type = getArrayTypeFromItems(info.items);
152
+ // console.log(typeof info.items === 'object');
153
+ // console.log(Array.isArray(info.items));
154
+ // console.log(info);
155
+ } else {
156
+ throw new Error('[info.items] case not handled by transpiler. contact maintainers.')
157
+ }
151
158
  }
152
159
  } else {
153
160
  const detect = detectType(info.type);