wasm-ast-types 0.17.0 → 0.18.1
Sign up to get free protection for your applications and to get access to all the features.
- package/main/client/test/ts-client.wager.spec.js +40 -0
- package/main/utils/types.js +13 -1
- package/module/client/test/ts-client.wager.spec.js +33 -0
- package/module/utils/types.js +11 -1
- package/package.json +2 -2
- package/src/client/test/__snapshots__/ts-client.wager.spec.ts.snap +132 -0
- package/src/client/test/ts-client.wager.spec.ts +63 -0
- package/src/utils/types.ts +17 -1
@@ -0,0 +1,40 @@
|
|
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
|
+
});
|
22
|
+
it('execute classes', function () {
|
23
|
+
(0, _testUtils.expectCode)((0, _client.createExecuteClass)(executeCtx, 'WagerClient', 'WagerInstance', null, _cwWager["default"].execute));
|
24
|
+
}); // it('execute classes array types', () => {
|
25
|
+
// expectCode(createExecuteClass(
|
26
|
+
// ctx,
|
27
|
+
// 'SG721Client',
|
28
|
+
// 'SG721Instance',
|
29
|
+
// null,
|
30
|
+
// wagerJson
|
31
|
+
// ))
|
32
|
+
// });
|
33
|
+
// it('execute interfaces no extends', () => {
|
34
|
+
// expectCode(createExecuteInterface(
|
35
|
+
// ctx,
|
36
|
+
// 'SG721Instance',
|
37
|
+
// null,
|
38
|
+
// wagerJson
|
39
|
+
// ))
|
40
|
+
// });
|
package/main/utils/types.js
CHANGED
@@ -72,6 +72,12 @@ var getTypeOrRef = function getTypeOrRef(obj) {
|
|
72
72
|
var getArrayTypeFromItems = function getArrayTypeFromItems(items) {
|
73
73
|
// passing in [{"type":"string"}]
|
74
74
|
if (Array.isArray(items)) {
|
75
|
+
var _items$;
|
76
|
+
|
77
|
+
if (((_items$ = items[0]) === null || _items$ === void 0 ? void 0 : _items$.type) === 'array') {
|
78
|
+
return t.tsArrayType(t.tsArrayType(getArrayTypeFromItems(items[0])));
|
79
|
+
}
|
80
|
+
|
75
81
|
return t.tsArrayType(t.tsArrayType(getTypeOrRef(items[0])));
|
76
82
|
} // passing in {"items": [{"type":"string"}]}
|
77
83
|
|
@@ -164,7 +170,13 @@ var getTypeInfo = function getTypeInfo(info) {
|
|
164
170
|
throw new Error('[info.items] case not handled by transpiler. contact maintainers.');
|
165
171
|
}
|
166
172
|
} else {
|
167
|
-
|
173
|
+
if (Array.isArray(info.items)) {
|
174
|
+
type = getArrayTypeFromItems(info.items); // console.log(typeof info.items === 'object');
|
175
|
+
// console.log(Array.isArray(info.items));
|
176
|
+
// console.log(info);
|
177
|
+
} else {
|
178
|
+
throw new Error('[info.items] case not handled by transpiler. contact maintainers.');
|
179
|
+
}
|
168
180
|
}
|
169
181
|
} else {
|
170
182
|
var detect = detectType(info.type);
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import wagerJson from '../../../../../__fixtures__/wager/cw-wager.json';
|
2
|
+
import { createQueryClass, createExecuteClass, 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
|
+
});
|
15
|
+
it('execute classes', () => {
|
16
|
+
expectCode(createExecuteClass(executeCtx, 'WagerClient', 'WagerInstance', null, wagerJson.execute));
|
17
|
+
}); // it('execute classes array types', () => {
|
18
|
+
// expectCode(createExecuteClass(
|
19
|
+
// ctx,
|
20
|
+
// 'SG721Client',
|
21
|
+
// 'SG721Instance',
|
22
|
+
// null,
|
23
|
+
// wagerJson
|
24
|
+
// ))
|
25
|
+
// });
|
26
|
+
// it('execute interfaces no extends', () => {
|
27
|
+
// expectCode(createExecuteInterface(
|
28
|
+
// ctx,
|
29
|
+
// 'SG721Instance',
|
30
|
+
// null,
|
31
|
+
// wagerJson
|
32
|
+
// ))
|
33
|
+
// });
|
package/module/utils/types.js
CHANGED
@@ -39,6 +39,10 @@ const getTypeOrRef = obj => {
|
|
39
39
|
const getArrayTypeFromItems = items => {
|
40
40
|
// passing in [{"type":"string"}]
|
41
41
|
if (Array.isArray(items)) {
|
42
|
+
if (items[0]?.type === 'array') {
|
43
|
+
return t.tsArrayType(t.tsArrayType(getArrayTypeFromItems(items[0])));
|
44
|
+
}
|
45
|
+
|
42
46
|
return t.tsArrayType(t.tsArrayType(getTypeOrRef(items[0])));
|
43
47
|
} // passing in {"items": [{"type":"string"}]}
|
44
48
|
|
@@ -124,7 +128,13 @@ export const getTypeInfo = info => {
|
|
124
128
|
throw new Error('[info.items] case not handled by transpiler. contact maintainers.');
|
125
129
|
}
|
126
130
|
} else {
|
127
|
-
|
131
|
+
if (Array.isArray(info.items)) {
|
132
|
+
type = getArrayTypeFromItems(info.items); // console.log(typeof info.items === 'object');
|
133
|
+
// console.log(Array.isArray(info.items));
|
134
|
+
// console.log(info);
|
135
|
+
} else {
|
136
|
+
throw new Error('[info.items] case not handled by transpiler. contact maintainers.');
|
137
|
+
}
|
128
138
|
}
|
129
139
|
} else {
|
130
140
|
const detect = detectType(info.type);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "wasm-ast-types",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.18.1",
|
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": "
|
91
|
+
"gitHead": "e6daf701507cad95127613a815fc0fca1a883f8a"
|
92
92
|
}
|
@@ -0,0 +1,132 @@
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
2
|
+
|
3
|
+
exports[`execute 1`] = `"export type ExecuteMsg = ExecuteMsg;"`;
|
4
|
+
|
5
|
+
exports[`execute classes 1`] = `
|
6
|
+
"export class WagerClient implements WagerInstance {
|
7
|
+
client: SigningCosmWasmClient;
|
8
|
+
sender: string;
|
9
|
+
contractAddress: string;
|
10
|
+
|
11
|
+
constructor(client: SigningCosmWasmClient, sender: string, contractAddress: string) {
|
12
|
+
this.client = client;
|
13
|
+
this.sender = sender;
|
14
|
+
this.contractAddress = contractAddress;
|
15
|
+
this.updateConfig = this.updateConfig.bind(this);
|
16
|
+
this.setWinner = this.setWinner.bind(this);
|
17
|
+
this.wager = this.wager.bind(this);
|
18
|
+
this.cancel = this.cancel.bind(this);
|
19
|
+
}
|
20
|
+
|
21
|
+
updateConfig = async ({
|
22
|
+
params
|
23
|
+
}: {
|
24
|
+
params: ParamInfo;
|
25
|
+
}, fee: number | StdFee | \\"auto\\" = \\"auto\\", memo?: string, funds?: Coin[]): Promise<ExecuteResult> => {
|
26
|
+
return await this.client.execute(this.sender, this.contractAddress, {
|
27
|
+
update_config: {
|
28
|
+
params
|
29
|
+
}
|
30
|
+
}, fee, memo, funds);
|
31
|
+
};
|
32
|
+
setWinner = async ({
|
33
|
+
currentPrices,
|
34
|
+
prevPrices,
|
35
|
+
wagerKey
|
36
|
+
}: {
|
37
|
+
currentPrices: number[][];
|
38
|
+
prevPrices: number[][];
|
39
|
+
wagerKey: Addr[][][][];
|
40
|
+
}, fee: number | StdFee | \\"auto\\" = \\"auto\\", memo?: string, funds?: Coin[]): Promise<ExecuteResult> => {
|
41
|
+
return await this.client.execute(this.sender, this.contractAddress, {
|
42
|
+
set_winner: {
|
43
|
+
current_prices: currentPrices,
|
44
|
+
prev_prices: prevPrices,
|
45
|
+
wager_key: wagerKey
|
46
|
+
}
|
47
|
+
}, fee, memo, funds);
|
48
|
+
};
|
49
|
+
wager = async ({
|
50
|
+
againstCurrencies,
|
51
|
+
currency,
|
52
|
+
expiry,
|
53
|
+
token
|
54
|
+
}: {
|
55
|
+
againstCurrencies: Currency[];
|
56
|
+
currency: Currency;
|
57
|
+
expiry: number;
|
58
|
+
token: Addr[][];
|
59
|
+
}, fee: number | StdFee | \\"auto\\" = \\"auto\\", memo?: string, funds?: Coin[]): Promise<ExecuteResult> => {
|
60
|
+
return await this.client.execute(this.sender, this.contractAddress, {
|
61
|
+
wager: {
|
62
|
+
against_currencies: againstCurrencies,
|
63
|
+
currency,
|
64
|
+
expiry,
|
65
|
+
token
|
66
|
+
}
|
67
|
+
}, fee, memo, funds);
|
68
|
+
};
|
69
|
+
cancel = async ({
|
70
|
+
token
|
71
|
+
}: {
|
72
|
+
token: Addr[][];
|
73
|
+
}, fee: number | StdFee | \\"auto\\" = \\"auto\\", memo?: string, funds?: Coin[]): Promise<ExecuteResult> => {
|
74
|
+
return await this.client.execute(this.sender, this.contractAddress, {
|
75
|
+
cancel: {
|
76
|
+
token
|
77
|
+
}
|
78
|
+
}, fee, memo, funds);
|
79
|
+
};
|
80
|
+
}"
|
81
|
+
`;
|
82
|
+
|
83
|
+
exports[`query 1`] = `"export type QueryMsg = QueryMsg;"`;
|
84
|
+
|
85
|
+
exports[`query classes 1`] = `
|
86
|
+
"export class WagerQueryClient implements WagerReadOnlyInstance {
|
87
|
+
client: CosmWasmClient;
|
88
|
+
contractAddress: string;
|
89
|
+
|
90
|
+
constructor(client: CosmWasmClient, contractAddress: string) {
|
91
|
+
this.client = client;
|
92
|
+
this.contractAddress = contractAddress;
|
93
|
+
this.wagers = this.wagers.bind(this);
|
94
|
+
this.wager = this.wager.bind(this);
|
95
|
+
this.tokenStatus = this.tokenStatus.bind(this);
|
96
|
+
this.config = this.config.bind(this);
|
97
|
+
}
|
98
|
+
|
99
|
+
wagers = async (): Promise<WagersResponse> => {
|
100
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
101
|
+
wagers: {}
|
102
|
+
});
|
103
|
+
};
|
104
|
+
wager = async ({
|
105
|
+
token
|
106
|
+
}: {
|
107
|
+
token: Addr[][];
|
108
|
+
}): Promise<WagerResponse> => {
|
109
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
110
|
+
wager: {
|
111
|
+
token
|
112
|
+
}
|
113
|
+
});
|
114
|
+
};
|
115
|
+
tokenStatus = async ({
|
116
|
+
token
|
117
|
+
}: {
|
118
|
+
token: Addr[][];
|
119
|
+
}): Promise<TokenStatusResponse> => {
|
120
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
121
|
+
token_status: {
|
122
|
+
token
|
123
|
+
}
|
124
|
+
});
|
125
|
+
};
|
126
|
+
config = async (): Promise<ConfigResponse> => {
|
127
|
+
return this.client.queryContractSmart(this.contractAddress, {
|
128
|
+
config: {}
|
129
|
+
});
|
130
|
+
};
|
131
|
+
}"
|
132
|
+
`;
|
@@ -0,0 +1,63 @@
|
|
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', () => {
|
37
|
+
expectCode(createExecuteClass(
|
38
|
+
executeCtx,
|
39
|
+
'WagerClient',
|
40
|
+
'WagerInstance',
|
41
|
+
null,
|
42
|
+
wagerJson.execute
|
43
|
+
))
|
44
|
+
});
|
45
|
+
|
46
|
+
// it('execute classes array types', () => {
|
47
|
+
// expectCode(createExecuteClass(
|
48
|
+
// ctx,
|
49
|
+
// 'SG721Client',
|
50
|
+
// 'SG721Instance',
|
51
|
+
// null,
|
52
|
+
// wagerJson
|
53
|
+
// ))
|
54
|
+
// });
|
55
|
+
|
56
|
+
// it('execute interfaces no extends', () => {
|
57
|
+
// expectCode(createExecuteInterface(
|
58
|
+
// ctx,
|
59
|
+
// 'SG721Instance',
|
60
|
+
// null,
|
61
|
+
// wagerJson
|
62
|
+
// ))
|
63
|
+
// });
|
package/src/utils/types.ts
CHANGED
@@ -48,6 +48,15 @@ const getTypeOrRef = (obj) => {
|
|
48
48
|
const getArrayTypeFromItems = (items) => {
|
49
49
|
// passing in [{"type":"string"}]
|
50
50
|
if (Array.isArray(items)) {
|
51
|
+
if (items[0]?.type === 'array') {
|
52
|
+
return t.tsArrayType(
|
53
|
+
t.tsArrayType(
|
54
|
+
getArrayTypeFromItems(
|
55
|
+
items[0]
|
56
|
+
)
|
57
|
+
)
|
58
|
+
);
|
59
|
+
}
|
51
60
|
return t.tsArrayType(
|
52
61
|
t.tsArrayType(
|
53
62
|
getTypeOrRef(items[0])
|
@@ -147,7 +156,14 @@ export const getTypeInfo = (info: JSONSchema) => {
|
|
147
156
|
throw new Error('[info.items] case not handled by transpiler. contact maintainers.')
|
148
157
|
}
|
149
158
|
} else {
|
150
|
-
|
159
|
+
if (Array.isArray(info.items)) {
|
160
|
+
type = getArrayTypeFromItems(info.items);
|
161
|
+
// console.log(typeof info.items === 'object');
|
162
|
+
// console.log(Array.isArray(info.items));
|
163
|
+
// console.log(info);
|
164
|
+
} else {
|
165
|
+
throw new Error('[info.items] case not handled by transpiler. contact maintainers.')
|
166
|
+
}
|
151
167
|
}
|
152
168
|
} else {
|
153
169
|
const detect = detectType(info.type);
|