wasm-ast-types 0.19.0 → 0.21.0
Sign up to get free protection for your applications and to get access to all the features.
- package/main/client/client.js +16 -7
- package/main/client/test/ts-client.issue-101.spec.js +27 -0
- package/main/client/test/ts-client.issue-103.test.js +48 -0
- package/main/message-composer/message-composer.js +13 -4
- package/main/message-composer/message-composer.spec.js +14 -4
- package/main/msg-builder/msg-builder.js +21 -7
- package/main/msg-builder/msg-builder.spec.js +7 -1
- package/main/react-query/react-query.spec.js +11 -0
- package/main/utils/types.js +10 -2
- package/module/client/client.js +18 -9
- package/module/client/test/ts-client.issue-101.spec.js +20 -0
- package/module/client/test/ts-client.issue-103.test.js +41 -0
- package/module/message-composer/message-composer.js +13 -4
- package/module/message-composer/message-composer.spec.js +16 -7
- package/module/msg-builder/msg-builder.js +26 -12
- package/module/msg-builder/msg-builder.spec.js +6 -1
- package/module/react-query/react-query.spec.js +10 -0
- package/module/utils/types.js +10 -3
- package/package.json +2 -2
- package/src/client/client.ts +29 -24
- package/src/client/test/__snapshots__/ts-client.issue-101.spec.ts.snap +47 -0
- package/src/client/test/__snapshots__/ts-client.issue-103.test.ts.snap +79 -0
- package/src/client/test/__snapshots__/ts-client.vectis.spec.ts.snap +8 -8
- package/src/client/test/ts-client.issue-101.spec.ts +37 -0
- package/src/client/test/ts-client.issue-103.test.ts +106 -0
- package/src/message-composer/__snapshots__/message-composer.spec.ts.snap +60 -0
- package/src/message-composer/message-composer.spec.ts +41 -20
- package/src/message-composer/message-composer.ts +13 -5
- package/src/msg-builder/__snapshots__/msg-builder.spec.ts.snap +21 -0
- package/src/msg-builder/msg-builder.spec.ts +9 -1
- package/src/msg-builder/msg-builder.ts +36 -24
- package/src/react-query/__snapshots__/react-query.spec.ts.snap +45 -0
- package/src/react-query/react-query.spec.ts +17 -1
- package/src/utils/types.ts +11 -4
@@ -1,16 +1,11 @@
|
|
1
|
-
import * as t from
|
2
|
-
import { camel } from
|
3
|
-
import {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
} from "../utils";
|
10
|
-
import { ExecuteMsg, QueryMsg } from "../types";
|
11
|
-
import { createTypedObjectParams } from "../utils/types";
|
12
|
-
import { RenderContext } from "../context";
|
13
|
-
import { getWasmMethodArgs } from "../client/client";
|
1
|
+
import * as t from '@babel/types';
|
2
|
+
import { camel } from 'case';
|
3
|
+
import { abstractClassDeclaration, arrowFunctionExpression, getMessageProperties } from '../utils';
|
4
|
+
import { ExecuteMsg, QueryMsg } from '../types';
|
5
|
+
import { createTypedObjectParams } from '../utils/types';
|
6
|
+
import { RenderContext } from '../context';
|
7
|
+
import { getWasmMethodArgs } from '../client/client';
|
8
|
+
import { Expression, Identifier, PatternLike, TSAsExpression } from '@babel/types';
|
14
9
|
|
15
10
|
export const createMsgBuilderClass = (
|
16
11
|
context: RenderContext,
|
@@ -34,10 +29,10 @@ export const createMsgBuilderClass = (
|
|
34
29
|
function createExtractTypeAnnotation(underscoreName: string, msgTitle: string) {
|
35
30
|
return t.tsTypeAnnotation(
|
36
31
|
t.tsTypeReference(
|
37
|
-
t.identifier(
|
32
|
+
t.identifier('CamelCasedProperties'),
|
38
33
|
t.tsTypeParameterInstantiation([
|
39
34
|
t.tsIndexedAccessType(
|
40
|
-
t.tsTypeReference(t.identifier(
|
35
|
+
t.tsTypeReference(t.identifier('Extract'),
|
41
36
|
t.tsTypeParameterInstantiation([
|
42
37
|
t.tsTypeReference(t.identifier(msgTitle)),
|
43
38
|
t.tsTypeLiteral([
|
@@ -62,7 +57,7 @@ const createStaticExecMethodMsgBuilder = (
|
|
62
57
|
) => {
|
63
58
|
const underscoreName = Object.keys(jsonschema.properties)[0];
|
64
59
|
const methodName = camel(underscoreName);
|
65
|
-
const
|
60
|
+
const param = createTypedObjectParams(
|
66
61
|
context,
|
67
62
|
jsonschema.properties[underscoreName]
|
68
63
|
);
|
@@ -71,17 +66,34 @@ const createStaticExecMethodMsgBuilder = (
|
|
71
66
|
jsonschema.properties[underscoreName]
|
72
67
|
);
|
73
68
|
|
74
|
-
|
69
|
+
// what the underscore named property in the message is assigned to
|
70
|
+
let actionValue: Expression
|
71
|
+
if (param?.type === 'Identifier') {
|
72
|
+
actionValue = t.identifier(param.name);
|
73
|
+
} else {
|
74
|
+
actionValue = t.tsAsExpression(t.objectExpression(args), t.tsTypeReference(t.identifier('const')));
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
// TODO: this is a hack to get the type annotation to work
|
79
|
+
// all type annotations in the future should be the extracted and camelized type
|
80
|
+
if (
|
81
|
+
param &&
|
82
|
+
param.typeAnnotation.type === 'TSTypeAnnotation' &&
|
83
|
+
param.typeAnnotation.typeAnnotation.type === 'TSTypeLiteral'
|
84
|
+
) {
|
85
|
+
param.typeAnnotation = createExtractTypeAnnotation(underscoreName, msgTitle);
|
86
|
+
}
|
75
87
|
|
76
88
|
return t.classProperty(
|
77
89
|
t.identifier(methodName),
|
78
90
|
arrowFunctionExpression(
|
79
91
|
// params
|
80
|
-
|
92
|
+
param
|
81
93
|
? [
|
82
|
-
|
83
|
-
|
84
|
-
|
94
|
+
// props
|
95
|
+
param
|
96
|
+
]
|
85
97
|
: [],
|
86
98
|
// body
|
87
99
|
t.blockStatement([
|
@@ -89,10 +101,10 @@ const createStaticExecMethodMsgBuilder = (
|
|
89
101
|
t.objectExpression([
|
90
102
|
t.objectProperty(
|
91
103
|
t.identifier(underscoreName),
|
92
|
-
|
93
|
-
)
|
104
|
+
actionValue
|
105
|
+
)
|
94
106
|
])
|
95
|
-
)
|
107
|
+
)
|
96
108
|
]),
|
97
109
|
// return type
|
98
110
|
t.tsTypeAnnotation(t.tsTypeReference(t.identifier(msgTitle))),
|
@@ -1312,3 +1312,48 @@ export function useSg721TransferNftMutation(options?: Omit<UseMutationOptions<Ex
|
|
1312
1312
|
}) => client.transferNft(msg, fee, memo, funds), options);
|
1313
1313
|
}"
|
1314
1314
|
`;
|
1315
|
+
|
1316
|
+
exports[`ownership 1`] = `
|
1317
|
+
"export interface OwnershipUpdateOwnershipMutation {
|
1318
|
+
client: OwnershipClient;
|
1319
|
+
msg: Action;
|
1320
|
+
args?: {
|
1321
|
+
fee?: number | StdFee | \\"auto\\";
|
1322
|
+
memo?: string;
|
1323
|
+
funds?: Coin[];
|
1324
|
+
};
|
1325
|
+
}
|
1326
|
+
export function useOwnershipUpdateOwnershipMutation(options?: Omit<UseMutationOptions<ExecuteResult, Error, OwnershipUpdateOwnershipMutation>, \\"mutationFn\\">) {
|
1327
|
+
return useMutation<ExecuteResult, Error, OwnershipUpdateOwnershipMutation>(({
|
1328
|
+
client,
|
1329
|
+
msg,
|
1330
|
+
args: {
|
1331
|
+
fee,
|
1332
|
+
memo,
|
1333
|
+
funds
|
1334
|
+
} = {}
|
1335
|
+
}) => client.updateOwnership(msg, fee, memo, funds), options);
|
1336
|
+
}
|
1337
|
+
export interface OwnershipSetFactoryMutation {
|
1338
|
+
client: OwnershipClient;
|
1339
|
+
msg: {
|
1340
|
+
newFactory: string;
|
1341
|
+
};
|
1342
|
+
args?: {
|
1343
|
+
fee?: number | StdFee | \\"auto\\";
|
1344
|
+
memo?: string;
|
1345
|
+
funds?: Coin[];
|
1346
|
+
};
|
1347
|
+
}
|
1348
|
+
export function useOwnershipSetFactoryMutation(options?: Omit<UseMutationOptions<ExecuteResult, Error, OwnershipSetFactoryMutation>, \\"mutationFn\\">) {
|
1349
|
+
return useMutation<ExecuteResult, Error, OwnershipSetFactoryMutation>(({
|
1350
|
+
client,
|
1351
|
+
msg,
|
1352
|
+
args: {
|
1353
|
+
fee,
|
1354
|
+
memo,
|
1355
|
+
funds
|
1356
|
+
} = {}
|
1357
|
+
}) => client.setFactory(msg, fee, memo, funds), options);
|
1358
|
+
}"
|
1359
|
+
`;
|
@@ -1,13 +1,15 @@
|
|
1
1
|
import * as t from '@babel/types';
|
2
2
|
import query_msg from '../../../../__fixtures__/basic/query_msg.json';
|
3
3
|
import execute_msg from '../../../../__fixtures__/basic/execute_msg_for__empty.json';
|
4
|
-
import
|
4
|
+
import ownership from '../../../../__fixtures__/basic/ownership.json';
|
5
|
+
|
5
6
|
|
6
7
|
import {
|
7
8
|
createReactQueryHooks,
|
8
9
|
createReactQueryMutationHooks,
|
9
10
|
} from './react-query'
|
10
11
|
import { expectCode, makeContext } from '../../test-utils';
|
12
|
+
import { createMsgBuilderClass } from '../msg-builder';
|
11
13
|
|
12
14
|
const execCtx = makeContext(execute_msg);
|
13
15
|
const queryCtx = makeContext(query_msg);
|
@@ -90,3 +92,17 @@ it('createReactQueryHooks', () => {
|
|
90
92
|
)))
|
91
93
|
});
|
92
94
|
|
95
|
+
it('ownership', () => {
|
96
|
+
const ownershipCtx = makeContext(ownership);
|
97
|
+
expectCode(t.program(
|
98
|
+
createReactQueryMutationHooks(
|
99
|
+
{
|
100
|
+
context: ownershipCtx,
|
101
|
+
execMsg: ownership,
|
102
|
+
contractName: 'Ownership',
|
103
|
+
ExecuteClient: 'OwnershipClient',
|
104
|
+
}
|
105
|
+
)))
|
106
|
+
});
|
107
|
+
|
108
|
+
|
package/src/utils/types.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import * as t from '@babel/types';
|
2
|
-
import { camel, pascal } from 'case';
|
2
|
+
import { camel, pascal, snake } from 'case';
|
3
3
|
import { propertySignature } from './babel';
|
4
4
|
import { TSTypeAnnotation } from '@babel/types';
|
5
5
|
import { RenderContext } from '../context';
|
@@ -425,15 +425,22 @@ export const createTypedObjectParams = (
|
|
425
425
|
context: RenderContext,
|
426
426
|
jsonschema: JSONSchema,
|
427
427
|
camelize: boolean = true
|
428
|
-
): t.
|
428
|
+
): (t.Identifier | t.Pattern | t.RestElement) => {
|
429
429
|
|
430
430
|
const keys = Object.keys(jsonschema.properties ?? {});
|
431
431
|
if (!keys.length) {
|
432
|
-
|
433
432
|
// is there a ref?
|
434
433
|
if (jsonschema.$ref) {
|
435
434
|
const obj = context.refLookup(jsonschema.$ref);
|
436
|
-
|
435
|
+
// If there is a oneOf, then we need to create a type for it
|
436
|
+
if (obj?.oneOf) {
|
437
|
+
// the actual type of the ref
|
438
|
+
const refType = jsonschema.$ref.split('/').pop();
|
439
|
+
const refName = camel(refType);
|
440
|
+
const id = t.identifier(refName);
|
441
|
+
id.typeAnnotation = t.tsTypeAnnotation(t.tsTypeReference(t.identifier(refType)));
|
442
|
+
return id
|
443
|
+
} else if (obj) {
|
437
444
|
return createTypedObjectParams(
|
438
445
|
context,
|
439
446
|
obj,
|