wasm-ast-types 0.4.3 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +129 -0
- package/main/{wasm.js → client/client.js} +56 -40
- package/main/client/index.js +18 -0
- package/main/client/test/ts-client.arrays.spec.js +25 -0
- package/main/client/test/ts-client.cw-named-groups.test.js +25 -0
- package/main/client/test/ts-client.cw-proposal-single.test.js +30 -0
- package/main/client/test/ts-client.empty-enums.spec.js +19 -0
- package/main/client/test/ts-client.sg721.spec.js +25 -0
- package/main/client/test/ts-client.spec.js +106 -0
- package/main/client/test/ts-client.vectis.spec.js +56 -0
- package/main/context/context.js +48 -0
- package/main/context/index.js +18 -0
- package/main/{messages.js → from-partial/from-partial.js} +17 -60
- package/main/from-partial/from-partial.spec.js +20 -0
- package/main/from-partial/index.js +18 -0
- package/main/index.js +34 -8
- package/main/react-query/index.js +18 -0
- package/main/react-query/react-query.js +267 -0
- package/main/{react-query.spec.js → react-query/react-query.spec.js} +36 -39
- package/main/recoil/index.js +18 -0
- package/main/{recoil.js → recoil/recoil.js} +7 -26
- package/main/{recoil.spec.js → recoil/recoil.spec.js} +9 -14
- package/main/utils/babel.js +28 -2
- package/main/utils/babel.spec.js +7 -15
- package/main/utils/index.js +13 -0
- package/main/utils/types.js +100 -78
- package/module/{wasm.js → client/client.js} +45 -35
- package/module/client/index.js +1 -0
- package/module/client/test/ts-client.arrays.spec.js +17 -0
- package/module/client/test/ts-client.cw-named-groups.test.js +17 -0
- package/module/client/test/ts-client.cw-proposal-single.test.js +21 -0
- package/module/client/test/ts-client.empty-enums.spec.js +11 -0
- package/module/client/test/ts-client.sg721.spec.js +17 -0
- package/module/client/test/ts-client.spec.js +85 -0
- package/module/client/test/ts-client.vectis.spec.js +44 -0
- package/module/context/context.js +25 -0
- package/module/context/index.js +1 -0
- package/module/{messages.js → from-partial/from-partial.js} +16 -57
- package/module/from-partial/from-partial.spec.js +12 -0
- package/module/from-partial/index.js +1 -0
- package/module/index.js +5 -3
- package/module/react-query/index.js +1 -0
- package/module/react-query/react-query.js +222 -0
- package/module/react-query/react-query.spec.js +53 -0
- package/module/recoil/index.js +1 -0
- package/module/{recoil.js → recoil/recoil.js} +6 -20
- package/module/recoil/recoil.spec.js +15 -0
- package/module/utils/babel.js +15 -0
- package/module/utils/babel.spec.js +1 -10
- package/module/utils/index.js +2 -1
- package/module/utils/types.js +83 -74
- package/package.json +26 -24
- package/types/src/client/client.d.ts +17 -0
- package/types/src/client/index.d.ts +1 -0
- package/types/src/client/test/ts-client.cw-named-groups.test.d.ts +1 -0
- package/types/src/client/test/ts-client.cw-proposal-single.test.d.ts +1 -0
- package/types/src/context/context.d.ts +20 -0
- package/types/src/context/index.d.ts +1 -0
- package/types/src/from-partial/from-partial.d.ts +4 -0
- package/types/src/from-partial/index.d.ts +1 -0
- package/types/src/index.d.ts +7 -0
- package/types/src/react-query/index.d.ts +1 -0
- package/types/src/react-query/react-query.d.ts +81 -0
- package/types/src/recoil/index.d.ts +1 -0
- package/types/{recoil.d.ts → src/recoil/recoil.d.ts} +5 -5
- package/types/{types.d.ts → src/types.d.ts} +17 -0
- package/types/{utils.d.ts → src/utils/babel.d.ts} +21 -1
- package/types/src/utils/index.d.ts +2 -0
- package/types/src/utils/types.d.ts +18 -0
- package/types/test-utils/index.d.ts +2 -0
- package/main/messages.spec.js +0 -24
- package/main/react-query.js +0 -155
- package/main/wasm.arrays.spec.js +0 -30
- package/main/wasm.cw-named-groups.test.js +0 -30
- package/main/wasm.cw-proposal-single.test.js +0 -32
- package/main/wasm.empty-enums.spec.js +0 -24
- package/main/wasm.sg721.spec.js +0 -30
- package/main/wasm.spec.js +0 -95
- package/main/wasm.vectis.spec.js +0 -53
- package/module/messages.spec.js +0 -18
- package/module/react-query.js +0 -120
- package/module/react-query.spec.js +0 -59
- package/module/recoil.spec.js +0 -22
- package/module/wasm.arrays.spec.js +0 -24
- package/module/wasm.cw-named-groups.test.js +0 -24
- package/module/wasm.cw-proposal-single.test.js +0 -25
- package/module/wasm.empty-enums.spec.js +0 -18
- package/module/wasm.sg721.spec.js +0 -24
- package/module/wasm.spec.js +0 -76
- package/module/wasm.vectis.spec.js +0 -43
- package/types/amino/amino-interfaces.d.ts +0 -6
- package/types/amino/from-amino.d.ts +0 -13
- package/types/amino/index.d.ts +0 -3
- package/types/amino/to-amino.d.ts +0 -11
- package/types/index.d.ts +0 -5
- package/types/messages.d.ts +0 -4
- package/types/react-query.d.ts +0 -32
- package/types/wasm.d.ts +0 -24
@@ -1,25 +1,24 @@
|
|
1
1
|
import * as t from '@babel/types';
|
2
2
|
import { camel, pascal } from 'case';
|
3
|
-
import { bindMethod, typedIdentifier, promiseTypeAnnotation, classDeclaration, classProperty, arrowFunctionExpression, getMessageProperties } from '
|
4
|
-
import { getPropertyType, getType, createTypedObjectParams } from '
|
5
|
-
import { identifier,
|
6
|
-
export const
|
3
|
+
import { bindMethod, typedIdentifier, promiseTypeAnnotation, classDeclaration, classProperty, arrowFunctionExpression, getMessageProperties } from '../utils';
|
4
|
+
import { getPropertyType, getType, createTypedObjectParams } from '../utils/types';
|
5
|
+
import { identifier, propertySignature } from '../utils/babel';
|
6
|
+
export const CONSTANT_EXEC_PARAMS = [t.assignmentPattern(identifier('fee', t.tsTypeAnnotation(t.tsUnionType([t.tSNumberKeyword(), t.tsTypeReference(t.identifier('StdFee')), t.tsLiteralType(t.stringLiteral('auto'))])), false), t.stringLiteral('auto')), identifier('memo', t.tsTypeAnnotation(t.tsStringKeyword()), true), identifier('funds', t.tsTypeAnnotation(t.tsArrayType(t.tsTypeReference(t.identifier('Coin')))), true)];
|
7
|
+
export const FIXED_EXECUTE_PARAMS = [identifier('fee', t.tsTypeAnnotation(t.tsUnionType([t.tsNumberKeyword(), t.tsTypeReference(t.identifier('StdFee')), t.tsLiteralType(t.stringLiteral('auto'))])), true), identifier('memo', t.tsTypeAnnotation(t.tsStringKeyword()), true), identifier('funds', t.tsTypeAnnotation(t.tsArrayType(t.tsTypeReference(t.identifier('Coin')))), true)];
|
8
|
+
export const createWasmQueryMethod = (context, jsonschema) => {
|
7
9
|
const underscoreName = Object.keys(jsonschema.properties)[0];
|
8
10
|
const methodName = camel(underscoreName);
|
9
11
|
const responseType = pascal(`${methodName}Response`);
|
10
|
-
const
|
11
|
-
const
|
12
|
-
const args = Object.keys(properties).map(prop => {
|
13
|
-
return t.objectProperty(t.identifier(prop), t.identifier(camel(prop)), false, true);
|
14
|
-
});
|
12
|
+
const obj = createTypedObjectParams(context, jsonschema.properties[underscoreName]);
|
13
|
+
const args = getWasmMethodArgs(context, jsonschema.properties[underscoreName]);
|
15
14
|
const actionArg = t.objectProperty(t.identifier(underscoreName), t.objectExpression(args));
|
16
15
|
return t.classProperty(t.identifier(methodName), arrowFunctionExpression(obj ? [obj] : [], t.blockStatement([t.returnStatement(t.callExpression(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier('client')), t.identifier('queryContractSmart')), [t.memberExpression(t.thisExpression(), t.identifier('contractAddress')), t.objectExpression([actionArg])]))]), t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Promise'), t.tsTypeParameterInstantiation([t.tSTypeReference(t.identifier(responseType))]))), true));
|
17
16
|
};
|
18
|
-
export const createQueryClass = (className, implementsClassName, queryMsg) => {
|
17
|
+
export const createQueryClass = (context, className, implementsClassName, queryMsg) => {
|
19
18
|
const propertyNames = getMessageProperties(queryMsg).map(method => Object.keys(method.properties)?.[0]).filter(Boolean);
|
20
19
|
const bindings = propertyNames.map(camel).map(bindMethod);
|
21
20
|
const methods = getMessageProperties(queryMsg).map(schema => {
|
22
|
-
return createWasmQueryMethod(schema);
|
21
|
+
return createWasmQueryMethod(context, schema);
|
23
22
|
});
|
24
23
|
return t.exportNamedDeclaration(classDeclaration(className, [// client
|
25
24
|
classProperty('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CosmWasmClient')))), // contractAddress
|
@@ -27,24 +26,36 @@ export const createQueryClass = (className, implementsClassName, queryMsg) => {
|
|
27
26
|
t.classMethod('constructor', t.identifier('constructor'), [typedIdentifier('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CosmWasmClient')))), typedIdentifier('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword()))], t.blockStatement([// client/contract set
|
28
27
|
t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier('client')), t.identifier('client'))), t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier('contractAddress')), t.identifier('contractAddress'))), ...bindings])), ...methods], [t.tSExpressionWithTypeArguments(t.identifier(implementsClassName))]));
|
29
28
|
};
|
30
|
-
export const
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
29
|
+
export const getWasmMethodArgs = (context, jsonschema) => {
|
30
|
+
let keys = Object.keys(jsonschema.properties ?? {}); // only 1 degree $ref-lookup
|
31
|
+
|
32
|
+
if (!keys.length && jsonschema.$ref) {
|
33
|
+
const obj = context.refLookup(jsonschema.$ref);
|
34
|
+
|
35
|
+
if (obj) {
|
36
|
+
keys = Object.keys(obj.properties ?? {});
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
const args = keys.map(prop => {
|
36
41
|
return t.objectProperty(t.identifier(prop), t.identifier(camel(prop)), false, prop === camel(prop));
|
37
42
|
});
|
38
|
-
|
43
|
+
return args;
|
44
|
+
};
|
45
|
+
export const createWasmExecMethod = (context, jsonschema) => {
|
46
|
+
const underscoreName = Object.keys(jsonschema.properties)[0];
|
47
|
+
const methodName = camel(underscoreName);
|
48
|
+
const obj = createTypedObjectParams(context, jsonschema.properties[underscoreName]);
|
49
|
+
const args = getWasmMethodArgs(context, jsonschema.properties[underscoreName]);
|
39
50
|
return t.classProperty(t.identifier(methodName), arrowFunctionExpression(obj ? [// props
|
40
|
-
obj, ...
|
51
|
+
obj, ...CONSTANT_EXEC_PARAMS] : CONSTANT_EXEC_PARAMS, t.blockStatement([t.returnStatement(t.awaitExpression(t.callExpression(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier('client')), t.identifier('execute')), [t.memberExpression(t.thisExpression(), t.identifier('sender')), t.memberExpression(t.thisExpression(), t.identifier('contractAddress')), t.objectExpression([t.objectProperty(t.identifier(underscoreName), t.objectExpression([...args]))]), t.identifier('fee'), t.identifier('memo'), t.identifier('funds')])))]), // return type
|
41
52
|
t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Promise'), t.tsTypeParameterInstantiation([t.tSTypeReference(t.identifier('ExecuteResult'))]))), true));
|
42
53
|
};
|
43
|
-
export const createExecuteClass = (className, implementsClassName, extendsClassName, execMsg) => {
|
54
|
+
export const createExecuteClass = (context, className, implementsClassName, extendsClassName, execMsg) => {
|
44
55
|
const propertyNames = getMessageProperties(execMsg).map(method => Object.keys(method.properties)?.[0]).filter(Boolean);
|
45
56
|
const bindings = propertyNames.map(camel).map(bindMethod);
|
46
57
|
const methods = getMessageProperties(execMsg).map(schema => {
|
47
|
-
return createWasmExecMethod(schema);
|
58
|
+
return createWasmExecMethod(context, schema);
|
48
59
|
});
|
49
60
|
const blockStmt = [];
|
50
61
|
|
@@ -61,19 +72,19 @@ export const createExecuteClass = (className, implementsClassName, extendsClassN
|
|
61
72
|
classProperty('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword())), // constructor
|
62
73
|
t.classMethod('constructor', t.identifier('constructor'), [typedIdentifier('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('SigningCosmWasmClient')))), typedIdentifier('sender', t.tsTypeAnnotation(t.tsStringKeyword())), typedIdentifier('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword()))], t.blockStatement(blockStmt)), ...methods], [t.tSExpressionWithTypeArguments(t.identifier(implementsClassName))], extendsClassName ? t.identifier(extendsClassName) : null));
|
63
74
|
};
|
64
|
-
export const createExecuteInterface = (className, extendsClassName, execMsg) => {
|
75
|
+
export const createExecuteInterface = (context, className, extendsClassName, execMsg) => {
|
65
76
|
const methods = getMessageProperties(execMsg).map(jsonschema => {
|
66
77
|
const underscoreName = Object.keys(jsonschema.properties)[0];
|
67
78
|
const methodName = camel(underscoreName);
|
68
|
-
return createPropertyFunctionWithObjectParamsForExec(methodName, 'ExecuteResult', jsonschema.properties[underscoreName]);
|
79
|
+
return createPropertyFunctionWithObjectParamsForExec(context, methodName, 'ExecuteResult', jsonschema.properties[underscoreName]);
|
69
80
|
});
|
70
81
|
const extendsAst = extendsClassName ? [t.tSExpressionWithTypeArguments(t.identifier(extendsClassName))] : [];
|
71
82
|
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(className), null, extendsAst, t.tSInterfaceBody([// contract address
|
72
83
|
t.tSPropertySignature(t.identifier('contractAddress'), t.tsTypeAnnotation(t.tsStringKeyword())), // contract address
|
73
84
|
t.tSPropertySignature(t.identifier('sender'), t.tsTypeAnnotation(t.tsStringKeyword())), ...methods])));
|
74
85
|
};
|
75
|
-
export const createPropertyFunctionWithObjectParams = (methodName, responseType, jsonschema) => {
|
76
|
-
const obj = createTypedObjectParams(jsonschema);
|
86
|
+
export const createPropertyFunctionWithObjectParams = (context, methodName, responseType, jsonschema) => {
|
87
|
+
const obj = createTypedObjectParams(context, jsonschema);
|
77
88
|
const func = {
|
78
89
|
type: 'TSFunctionType',
|
79
90
|
typeAnnotation: promiseTypeAnnotation(responseType),
|
@@ -81,26 +92,25 @@ export const createPropertyFunctionWithObjectParams = (methodName, responseType,
|
|
81
92
|
};
|
82
93
|
return t.tSPropertySignature(t.identifier(methodName), t.tsTypeAnnotation(func));
|
83
94
|
};
|
84
|
-
export const createPropertyFunctionWithObjectParamsForExec = (methodName, responseType, jsonschema) => {
|
85
|
-
const obj = createTypedObjectParams(jsonschema);
|
86
|
-
const fixedParams = [identifier('fee', t.tsTypeAnnotation(t.tsUnionType([t.tsNumberKeyword(), t.tsTypeReference(t.identifier('StdFee')), t.tsLiteralType(t.stringLiteral('auto'))])), true), identifier('memo', t.tsTypeAnnotation(t.tsStringKeyword()), true), identifier('funds', t.tsTypeAnnotation(tsTypeOperator(t.tsArrayType(t.tsTypeReference(t.identifier('Coin'))), 'readonly')), true)];
|
95
|
+
export const createPropertyFunctionWithObjectParamsForExec = (context, methodName, responseType, jsonschema) => {
|
96
|
+
const obj = createTypedObjectParams(context, jsonschema);
|
87
97
|
const func = {
|
88
98
|
type: 'TSFunctionType',
|
89
99
|
typeAnnotation: promiseTypeAnnotation(responseType),
|
90
|
-
parameters: obj ? [obj, ...
|
100
|
+
parameters: obj ? [obj, ...FIXED_EXECUTE_PARAMS] : FIXED_EXECUTE_PARAMS
|
91
101
|
};
|
92
102
|
return t.tSPropertySignature(t.identifier(methodName), t.tsTypeAnnotation(func));
|
93
103
|
};
|
94
|
-
export const createQueryInterface = (className, queryMsg) => {
|
104
|
+
export const createQueryInterface = (context, className, queryMsg) => {
|
95
105
|
const methods = getMessageProperties(queryMsg).map(jsonschema => {
|
96
106
|
const underscoreName = Object.keys(jsonschema.properties)[0];
|
97
107
|
const methodName = camel(underscoreName);
|
98
108
|
const responseType = pascal(`${methodName}Response`);
|
99
|
-
return createPropertyFunctionWithObjectParams(methodName, responseType, jsonschema.properties[underscoreName]);
|
109
|
+
return createPropertyFunctionWithObjectParams(context, methodName, responseType, jsonschema.properties[underscoreName]);
|
100
110
|
});
|
101
111
|
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(className), null, [], t.tSInterfaceBody([t.tSPropertySignature(t.identifier('contractAddress'), t.tsTypeAnnotation(t.tsStringKeyword())), ...methods])));
|
102
112
|
};
|
103
|
-
export const createTypeOrInterface = (Type, jsonschema) => {
|
113
|
+
export const createTypeOrInterface = (context, Type, jsonschema) => {
|
104
114
|
if (jsonschema.type !== 'object') {
|
105
115
|
if (!jsonschema.type) {
|
106
116
|
return t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(Type), null, t.tsTypeReference(t.identifier(jsonschema.title))));
|
@@ -113,12 +123,12 @@ export const createTypeOrInterface = (Type, jsonschema) => {
|
|
113
123
|
const {
|
114
124
|
type,
|
115
125
|
optional
|
116
|
-
} = getPropertyType(jsonschema, prop);
|
126
|
+
} = getPropertyType(context, jsonschema, prop);
|
117
127
|
return propertySignature(camel(prop), t.tsTypeAnnotation(type), optional);
|
118
128
|
});
|
119
129
|
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(Type), null, [], t.tsInterfaceBody([...props])));
|
120
130
|
};
|
121
|
-
export const createTypeInterface = jsonschema => {
|
131
|
+
export const createTypeInterface = (context, jsonschema) => {
|
122
132
|
const Type = jsonschema.title;
|
123
|
-
return createTypeOrInterface(Type, jsonschema);
|
133
|
+
return createTypeOrInterface(context, Type, jsonschema);
|
124
134
|
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './client';
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import message from '../../../../../__fixtures__/misc/schema/arrays.json';
|
2
|
+
import { createQueryClass, createExecuteClass, createExecuteInterface, createTypeInterface } from '../client';
|
3
|
+
import { RenderContext } from '../../context';
|
4
|
+
import { expectCode } from '../../../test-utils';
|
5
|
+
const ctx = new RenderContext(message);
|
6
|
+
it('execute_msg_for__empty', () => {
|
7
|
+
expectCode(createTypeInterface(ctx, message));
|
8
|
+
});
|
9
|
+
it('query classes', () => {
|
10
|
+
expectCode(createQueryClass(ctx, 'SG721QueryClient', 'SG721ReadOnlyInstance', message));
|
11
|
+
});
|
12
|
+
it('execute classes array types', () => {
|
13
|
+
expectCode(createExecuteClass(ctx, 'SG721Client', 'SG721Instance', null, message));
|
14
|
+
});
|
15
|
+
it('execute interfaces no extends', () => {
|
16
|
+
expectCode(createExecuteInterface(ctx, 'SG721Instance', null, message));
|
17
|
+
});
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import execute_msg from '../../../../../__fixtures__/daodao/cw-named-groups/execute_msg.json';
|
2
|
+
import { createQueryClass, createExecuteClass, createExecuteInterface, createTypeInterface } from '../client';
|
3
|
+
import { RenderContext } from '../../context';
|
4
|
+
import { expectCode } from '../../../test-utils';
|
5
|
+
const ctx = new RenderContext(execute_msg);
|
6
|
+
it('execute_msg', () => {
|
7
|
+
expectCode(createTypeInterface(ctx, execute_msg));
|
8
|
+
});
|
9
|
+
it('query classes', () => {
|
10
|
+
expectCode(createQueryClass(ctx, 'SG721QueryClient', 'SG721ReadOnlyInstance', execute_msg));
|
11
|
+
});
|
12
|
+
it('execute classes array types', () => {
|
13
|
+
expectCode(createExecuteClass(ctx, 'SG721Client', 'SG721Instance', null, execute_msg));
|
14
|
+
});
|
15
|
+
it('execute interfaces no extends', () => {
|
16
|
+
expectCode(createExecuteInterface(ctx, 'SG721Instance', null, execute_msg));
|
17
|
+
});
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import execute_msg from '../../../../../__fixtures__/daodao/cw-proposal-single/execute_msg.json';
|
2
|
+
import query_msg from '../../../../../__fixtures__/daodao/cw-proposal-single/query_msg.json';
|
3
|
+
import { createQueryClass, createExecuteClass, createExecuteInterface, createTypeInterface } from '../client';
|
4
|
+
import { RenderContext } from '../../context';
|
5
|
+
import { expectCode } from '../../../test-utils';
|
6
|
+
it('execute_msg_for', () => {
|
7
|
+
const ctx = new RenderContext(execute_msg);
|
8
|
+
expectCode(createTypeInterface(ctx, execute_msg));
|
9
|
+
});
|
10
|
+
it('query classes', () => {
|
11
|
+
const ctx = new RenderContext(query_msg);
|
12
|
+
expectCode(createQueryClass(ctx, 'SG721QueryClient', 'SG721ReadOnlyInstance', query_msg));
|
13
|
+
});
|
14
|
+
it('execute classes array types', () => {
|
15
|
+
const ctx = new RenderContext(execute_msg);
|
16
|
+
expectCode(createExecuteClass(ctx, 'SG721Client', 'SG721Instance', null, execute_msg));
|
17
|
+
});
|
18
|
+
it('execute interfaces no extends', () => {
|
19
|
+
const ctx = new RenderContext(execute_msg);
|
20
|
+
expectCode(createExecuteInterface(ctx, 'SG721Instance', null, execute_msg));
|
21
|
+
});
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import query_msg from '../../../../../__fixtures__/daodao/cw-admin-factory/query_msg.json';
|
2
|
+
import { createQueryClass, createQueryInterface } from '../client';
|
3
|
+
import { RenderContext } from '../../context';
|
4
|
+
import { expectCode } from '../../../test-utils';
|
5
|
+
const ctx = new RenderContext(query_msg);
|
6
|
+
it('query classes', () => {
|
7
|
+
expectCode(createQueryClass(ctx, 'SG721QueryClient', 'SG721ReadOnlyInstance', query_msg));
|
8
|
+
});
|
9
|
+
it('query interface', () => {
|
10
|
+
expectCode(createQueryInterface(ctx, 'ReadOnlyInstance', query_msg));
|
11
|
+
});
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import execute_msg_for__empty from '../../../../../__fixtures__/sg721/execute_msg_for__empty.json';
|
2
|
+
import { createQueryClass, createExecuteClass, createExecuteInterface, createTypeInterface } from '../client';
|
3
|
+
import { RenderContext } from '../../context';
|
4
|
+
import { expectCode } from '../../../test-utils';
|
5
|
+
const ctx = new RenderContext(execute_msg_for__empty);
|
6
|
+
it('execute_msg_for__empty', () => {
|
7
|
+
expectCode(createTypeInterface(ctx, execute_msg_for__empty));
|
8
|
+
});
|
9
|
+
it('query classes', () => {
|
10
|
+
expectCode(createQueryClass(ctx, 'SG721QueryClient', 'SG721ReadOnlyInstance', execute_msg_for__empty));
|
11
|
+
});
|
12
|
+
it('execute classes array types', () => {
|
13
|
+
expectCode(createExecuteClass(ctx, 'SG721Client', 'SG721Instance', null, execute_msg_for__empty));
|
14
|
+
});
|
15
|
+
it('execute interfaces no extends', () => {
|
16
|
+
expectCode(createExecuteInterface(ctx, 'SG721Instance', null, execute_msg_for__empty));
|
17
|
+
});
|
@@ -0,0 +1,85 @@
|
|
1
|
+
import execute_msg_named_groups from '../../../../../__fixtures__/daodao/cw-named-groups/execute_msg.json';
|
2
|
+
import query_msg from '../../../../../__fixtures__/basic/query_msg.json';
|
3
|
+
import execute_msg from '../../../../../__fixtures__/basic/execute_msg_for__empty.json';
|
4
|
+
import approval_response from '../../../../../__fixtures__/basic/approval_response.json';
|
5
|
+
import all_nft_info_response from '../../../../../__fixtures__/basic/all_nft_info_response.json';
|
6
|
+
import approvals_response from '../../../../../__fixtures__/basic/approvals_response.json';
|
7
|
+
import collection_info_response from '../../../../../__fixtures__/basic/collection_info_response.json';
|
8
|
+
import contract_info_response from '../../../../../__fixtures__/basic/contract_info_response.json';
|
9
|
+
import instantiate_msg from '../../../../../__fixtures__/basic/instantiate_msg.json';
|
10
|
+
import nft_info_response from '../../../../../__fixtures__/basic/nft_info_response.json';
|
11
|
+
import num_tokens_response from '../../../../../__fixtures__/basic/num_tokens_response.json';
|
12
|
+
import operators_response from '../../../../../__fixtures__/basic/operators_response.json';
|
13
|
+
import owner_of_response from '../../../../../__fixtures__/basic/owner_of_response.json';
|
14
|
+
import tokens_response from '../../../../../__fixtures__/basic/tokens_response.json';
|
15
|
+
import { createQueryClass, createQueryInterface, createExecuteClass, createExecuteInterface, createTypeInterface } from '../client';
|
16
|
+
import { RenderContext } from '../../context';
|
17
|
+
import { expectCode } from '../../../test-utils';
|
18
|
+
it('approval_response', () => {
|
19
|
+
const ctx = new RenderContext(approval_response);
|
20
|
+
expectCode(createTypeInterface(ctx, approval_response));
|
21
|
+
});
|
22
|
+
it('all_nft_info_response', () => {
|
23
|
+
const ctx = new RenderContext(all_nft_info_response);
|
24
|
+
expectCode(createTypeInterface(ctx, all_nft_info_response));
|
25
|
+
});
|
26
|
+
it('approvals_response', () => {
|
27
|
+
const ctx = new RenderContext(approvals_response);
|
28
|
+
expectCode(createTypeInterface(ctx, approvals_response));
|
29
|
+
});
|
30
|
+
it('collection_info_response', () => {
|
31
|
+
const ctx = new RenderContext(collection_info_response);
|
32
|
+
expectCode(createTypeInterface(ctx, collection_info_response));
|
33
|
+
});
|
34
|
+
it('contract_info_response', () => {
|
35
|
+
const ctx = new RenderContext(contract_info_response);
|
36
|
+
expectCode(createTypeInterface(ctx, contract_info_response));
|
37
|
+
});
|
38
|
+
it('instantiate_msg', () => {
|
39
|
+
const ctx = new RenderContext(instantiate_msg);
|
40
|
+
expectCode(createTypeInterface(ctx, instantiate_msg));
|
41
|
+
});
|
42
|
+
it('nft_info_response', () => {
|
43
|
+
const ctx = new RenderContext(nft_info_response);
|
44
|
+
expectCode(createTypeInterface(ctx, nft_info_response));
|
45
|
+
});
|
46
|
+
it('num_tokens_response', () => {
|
47
|
+
const ctx = new RenderContext(num_tokens_response);
|
48
|
+
expectCode(createTypeInterface(ctx, num_tokens_response));
|
49
|
+
});
|
50
|
+
it('operators_response', () => {
|
51
|
+
const ctx = new RenderContext(operators_response);
|
52
|
+
expectCode(createTypeInterface(ctx, operators_response));
|
53
|
+
});
|
54
|
+
it('owner_of_response', () => {
|
55
|
+
const ctx = new RenderContext(owner_of_response);
|
56
|
+
expectCode(createTypeInterface(ctx, owner_of_response));
|
57
|
+
});
|
58
|
+
it('tokens_response', () => {
|
59
|
+
const ctx = new RenderContext(tokens_response);
|
60
|
+
expectCode(createTypeInterface(ctx, tokens_response));
|
61
|
+
});
|
62
|
+
it('query classes', () => {
|
63
|
+
const ctx = new RenderContext(query_msg);
|
64
|
+
expectCode(createQueryClass(ctx, 'SG721QueryClient', 'SG721ReadOnlyInstance', query_msg));
|
65
|
+
});
|
66
|
+
it('execute classes', () => {
|
67
|
+
const ctx = new RenderContext(execute_msg);
|
68
|
+
expectCode(createExecuteClass(ctx, 'SG721Client', 'SG721Instance', 'SG721QueryClient', execute_msg));
|
69
|
+
});
|
70
|
+
it('execute classes no extends', () => {
|
71
|
+
const ctx = new RenderContext(execute_msg);
|
72
|
+
expectCode(createExecuteClass(ctx, 'SG721Client', 'SG721Instance', null, execute_msg));
|
73
|
+
});
|
74
|
+
it('execute classes array types', () => {
|
75
|
+
const ctx = new RenderContext(execute_msg_named_groups);
|
76
|
+
expectCode(createExecuteClass(ctx, 'SG721Client', 'SG721Instance', null, execute_msg_named_groups));
|
77
|
+
});
|
78
|
+
it('execute interfaces no extends', () => {
|
79
|
+
const ctx = new RenderContext(execute_msg);
|
80
|
+
expectCode(createExecuteInterface(ctx, 'SG721Instance', null, execute_msg));
|
81
|
+
});
|
82
|
+
it('query interfaces', () => {
|
83
|
+
const ctx = new RenderContext(query_msg);
|
84
|
+
expectCode(createQueryInterface(ctx, 'SG721ReadOnlyInstance', query_msg));
|
85
|
+
});
|
@@ -0,0 +1,44 @@
|
|
1
|
+
import cosmos_msg_for__empty from '../../../../../__fixtures__/vectis/govec/cosmos_msg_for__empty.json';
|
2
|
+
import execute_msg_for__empty from '../../../../../__fixtures__/vectis/govec/execute_msg_for__empty.json';
|
3
|
+
import can_execute_relay_response from '../../../../../__fixtures__/vectis/govec/can_execute_relay_response.json';
|
4
|
+
import info_response from '../../../../../__fixtures__/vectis/govec/info_response.json';
|
5
|
+
import relay_transaction from '../../../../../__fixtures__/vectis/govec/relay_transaction.json';
|
6
|
+
import { createQueryClass, createExecuteClass, createExecuteInterface, createTypeInterface } from '../client';
|
7
|
+
import { RenderContext } from '../../context';
|
8
|
+
import { expectCode } from '../../../test-utils';
|
9
|
+
it('cosmos_msg_for__empty', () => {
|
10
|
+
const ctx = new RenderContext(cosmos_msg_for__empty);
|
11
|
+
expectCode(createTypeInterface(ctx, cosmos_msg_for__empty));
|
12
|
+
});
|
13
|
+
it('execute_msg_for__empty', () => {
|
14
|
+
const ctx = new RenderContext(execute_msg_for__empty);
|
15
|
+
expectCode(createTypeInterface(ctx, execute_msg_for__empty));
|
16
|
+
});
|
17
|
+
it('can_execute_relay_response', () => {
|
18
|
+
const ctx = new RenderContext(can_execute_relay_response);
|
19
|
+
expectCode(createTypeInterface(ctx, can_execute_relay_response));
|
20
|
+
});
|
21
|
+
it('info_response', () => {
|
22
|
+
const ctx = new RenderContext(info_response);
|
23
|
+
expectCode(createTypeInterface(ctx, info_response));
|
24
|
+
});
|
25
|
+
it('relay_transaction', () => {
|
26
|
+
const ctx = new RenderContext(relay_transaction);
|
27
|
+
expectCode(createTypeInterface(ctx, relay_transaction));
|
28
|
+
});
|
29
|
+
it('query classes', () => {
|
30
|
+
const ctx = new RenderContext(cosmos_msg_for__empty);
|
31
|
+
expectCode(createQueryClass(ctx, 'SG721QueryClient', 'SG721ReadOnlyInstance', cosmos_msg_for__empty));
|
32
|
+
});
|
33
|
+
it('query classes', () => {
|
34
|
+
const ctx = new RenderContext(execute_msg_for__empty);
|
35
|
+
expectCode(createQueryClass(ctx, 'SG721QueryClient', 'SG721ReadOnlyInstance', execute_msg_for__empty));
|
36
|
+
});
|
37
|
+
it('execute classes array types', () => {
|
38
|
+
const ctx = new RenderContext(execute_msg_for__empty);
|
39
|
+
expectCode(createExecuteClass(ctx, 'SG721Client', 'SG721Instance', null, execute_msg_for__empty));
|
40
|
+
});
|
41
|
+
it('execute interfaces no extends', () => {
|
42
|
+
const ctx = new RenderContext(execute_msg_for__empty);
|
43
|
+
expectCode(createExecuteInterface(ctx, 'SG721Instance', null, execute_msg_for__empty));
|
44
|
+
});
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
2
|
+
import deepmerge from "deepmerge"; /// Plugin Types
|
3
|
+
|
4
|
+
export const defaultOptions = {
|
5
|
+
reactQuery: {
|
6
|
+
optionalClient: false,
|
7
|
+
v4: false,
|
8
|
+
mutations: false,
|
9
|
+
camelize: true
|
10
|
+
}
|
11
|
+
};
|
12
|
+
export class RenderContext {
|
13
|
+
constructor(schema, options) {
|
14
|
+
_defineProperty(this, "schema", void 0);
|
15
|
+
|
16
|
+
this.schema = schema;
|
17
|
+
this.options = deepmerge(defaultOptions, options ?? {});
|
18
|
+
}
|
19
|
+
|
20
|
+
refLookup($ref) {
|
21
|
+
const refName = $ref.replace('#/definitions/', '');
|
22
|
+
return this.schema.definitions?.[refName];
|
23
|
+
}
|
24
|
+
|
25
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './context';
|
@@ -1,51 +1,26 @@
|
|
1
1
|
import * as t from '@babel/types';
|
2
2
|
import { camel } from 'case';
|
3
|
-
import { bindMethod, typedIdentifier, classDeclaration, classProperty, arrowFunctionExpression, getMessageProperties } from '
|
4
|
-
import { createTypedObjectParams } from '
|
5
|
-
import { identifier
|
3
|
+
import { bindMethod, typedIdentifier, classDeclaration, classProperty, arrowFunctionExpression, getMessageProperties } from '../utils';
|
4
|
+
import { createTypedObjectParams } from '../utils/types';
|
5
|
+
import { identifier } from '../utils/babel';
|
6
|
+
import { getWasmMethodArgs } from '../client/client';
|
6
7
|
|
7
|
-
const createWasmExecMethodPartial = jsonschema => {
|
8
|
+
const createWasmExecMethodPartial = (context, jsonschema) => {
|
8
9
|
const underscoreName = Object.keys(jsonschema.properties)[0];
|
9
10
|
const methodName = camel(underscoreName);
|
10
|
-
const
|
11
|
-
const
|
12
|
-
const
|
13
|
-
return t.objectProperty(t.identifier(prop), t.identifier(camel(prop)), false, prop === camel(prop));
|
14
|
-
});
|
15
|
-
const constantParams = [// t.assignmentPattern(
|
16
|
-
// identifier(
|
17
|
-
// 'fee',
|
18
|
-
// t.tsTypeAnnotation(
|
19
|
-
// t.tsUnionType(
|
20
|
-
// [
|
21
|
-
// t.tSNumberKeyword(),
|
22
|
-
// t.tsTypeReference(
|
23
|
-
// t.identifier('StdFee')
|
24
|
-
// ),
|
25
|
-
// t.tsLiteralType(
|
26
|
-
// t.stringLiteral('auto')
|
27
|
-
// )
|
28
|
-
// ]
|
29
|
-
// )
|
30
|
-
// ),
|
31
|
-
// false
|
32
|
-
// ),
|
33
|
-
// t.stringLiteral('auto')
|
34
|
-
// ),
|
35
|
-
// identifier('memo', t.tsTypeAnnotation(
|
36
|
-
// t.tsStringKeyword()
|
37
|
-
// ), true),
|
38
|
-
identifier('funds', t.tsTypeAnnotation(tsTypeOperator(t.tsArrayType(t.tsTypeReference(t.identifier('Coin'))), 'readonly')), true)];
|
11
|
+
const obj = createTypedObjectParams(context, jsonschema.properties[underscoreName]);
|
12
|
+
const args = getWasmMethodArgs(context, jsonschema.properties[underscoreName]);
|
13
|
+
const constantParams = [identifier('funds', t.tsTypeAnnotation(t.tsArrayType(t.tsTypeReference(t.identifier('Coin')))), true)];
|
39
14
|
return t.classProperty(t.identifier(methodName), arrowFunctionExpression(obj ? [// props
|
40
15
|
obj, ...constantParams] : constantParams, t.blockStatement([t.returnStatement(t.objectExpression([t.objectProperty(t.identifier('typeUrl'), t.stringLiteral('/cosmwasm.wasm.v1.MsgExecuteContract')), t.objectProperty(t.identifier('value'), t.callExpression(t.memberExpression(t.identifier('MsgExecuteContract'), t.identifier('fromPartial')), [t.objectExpression([t.objectProperty(t.identifier('sender'), t.memberExpression(t.thisExpression(), t.identifier('sender'))), t.objectProperty(t.identifier('contract'), t.memberExpression(t.thisExpression(), t.identifier('contractAddress'))), t.objectProperty(t.identifier('msg'), t.callExpression(t.identifier('toUtf8'), [t.callExpression(t.memberExpression(t.identifier('JSON'), t.identifier('stringify')), [t.objectExpression([t.objectProperty(t.identifier(underscoreName), t.objectExpression(args))])])])), t.objectProperty(t.identifier('funds'), t.identifier('funds'), false, true)])]))]))]), // return type
|
41
16
|
t.tsTypeAnnotation(t.tsTypeReference(t.identifier('MsgExecuteContractEncodeObject'))), false));
|
42
17
|
};
|
43
18
|
|
44
|
-
export const createFromPartialClass = (className, implementsClassName, execMsg) => {
|
19
|
+
export const createFromPartialClass = (context, className, implementsClassName, execMsg) => {
|
45
20
|
const propertyNames = getMessageProperties(execMsg).map(method => Object.keys(method.properties)?.[0]).filter(Boolean);
|
46
21
|
const bindings = propertyNames.map(camel).map(bindMethod);
|
47
22
|
const methods = getMessageProperties(execMsg).map(schema => {
|
48
|
-
return createWasmExecMethodPartial(schema);
|
23
|
+
return createWasmExecMethodPartial(context, schema);
|
49
24
|
});
|
50
25
|
const blockStmt = [];
|
51
26
|
[].push.apply(blockStmt, [t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier('sender')), t.identifier('sender'))), t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier('contractAddress')), t.identifier('contractAddress'))), ...bindings]);
|
@@ -54,37 +29,21 @@ export const createFromPartialClass = (className, implementsClassName, execMsg)
|
|
54
29
|
classProperty('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword())), // constructor
|
55
30
|
t.classMethod('constructor', t.identifier('constructor'), [typedIdentifier('sender', t.tsTypeAnnotation(t.tsStringKeyword())), typedIdentifier('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword()))], t.blockStatement(blockStmt)), ...methods], [t.tSExpressionWithTypeArguments(t.identifier(implementsClassName))], null));
|
56
31
|
};
|
57
|
-
export const createFromPartialInterface = (className, execMsg) => {
|
32
|
+
export const createFromPartialInterface = (context, className, execMsg) => {
|
58
33
|
const methods = getMessageProperties(execMsg).map(jsonschema => {
|
59
34
|
const underscoreName = Object.keys(jsonschema.properties)[0];
|
60
35
|
const methodName = camel(underscoreName);
|
61
|
-
return createPropertyFunctionWithObjectParamsForPartial(methodName, 'MsgExecuteContractEncodeObject', jsonschema.properties[underscoreName]);
|
36
|
+
return createPropertyFunctionWithObjectParamsForPartial(context, methodName, 'MsgExecuteContractEncodeObject', jsonschema.properties[underscoreName]);
|
62
37
|
});
|
63
38
|
const extendsAst = [];
|
64
39
|
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(className), null, extendsAst, t.tSInterfaceBody([// contract address
|
65
40
|
t.tSPropertySignature(t.identifier('contractAddress'), t.tsTypeAnnotation(t.tsStringKeyword())), // contract address
|
66
41
|
t.tSPropertySignature(t.identifier('sender'), t.tsTypeAnnotation(t.tsStringKeyword())), ...methods])));
|
67
|
-
};
|
42
|
+
};
|
68
43
|
|
69
|
-
const createPropertyFunctionWithObjectParamsForPartial = (methodName, responseType, jsonschema) => {
|
70
|
-
const obj = createTypedObjectParams(jsonschema);
|
71
|
-
const fixedParams = [
|
72
|
-
// t.tsUnionType(
|
73
|
-
// [
|
74
|
-
// t.tsNumberKeyword(),
|
75
|
-
// t.tsTypeReference(
|
76
|
-
// t.identifier('StdFee')
|
77
|
-
// ),
|
78
|
-
// t.tsLiteralType(
|
79
|
-
// t.stringLiteral('auto')
|
80
|
-
// )
|
81
|
-
// ]
|
82
|
-
// )
|
83
|
-
// ), true),
|
84
|
-
// identifier('memo', t.tsTypeAnnotation(
|
85
|
-
// t.tsStringKeyword()
|
86
|
-
// ), true),
|
87
|
-
identifier('funds', t.tsTypeAnnotation(tsTypeOperator(t.tsArrayType(t.tsTypeReference(t.identifier('Coin'))), 'readonly')), true)];
|
44
|
+
const createPropertyFunctionWithObjectParamsForPartial = (context, methodName, responseType, jsonschema) => {
|
45
|
+
const obj = createTypedObjectParams(context, jsonschema);
|
46
|
+
const fixedParams = [identifier('funds', t.tsTypeAnnotation(t.tsArrayType(t.tsTypeReference(t.identifier('Coin')))), true)];
|
88
47
|
const func = {
|
89
48
|
type: 'TSFunctionType',
|
90
49
|
typeAnnotation: t.tsTypeAnnotation(t.tsTypeReference(t.identifier(responseType))),
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import execute_msg from '../../../../__fixtures__/basic/execute_msg_for__empty.json';
|
2
|
+
import { createFromPartialClass, createFromPartialInterface } from './from-partial';
|
3
|
+
import { RenderContext } from '../context';
|
4
|
+
import { expectCode } from '../../test-utils';
|
5
|
+
it('execute classes', () => {
|
6
|
+
const ctx = new RenderContext(execute_msg);
|
7
|
+
expectCode(createFromPartialClass(ctx, 'SG721MessageComposer', 'SG721Message', execute_msg));
|
8
|
+
});
|
9
|
+
it('createFromPartialInterface', () => {
|
10
|
+
const ctx = new RenderContext(execute_msg);
|
11
|
+
expectCode(createFromPartialInterface(ctx, 'SG721Message', execute_msg));
|
12
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './from-partial';
|
package/module/index.js
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
export * from './utils';
|
2
|
-
export * from './
|
2
|
+
export * from './client';
|
3
|
+
export * from './context';
|
3
4
|
export * from './recoil';
|
4
|
-
export * from './
|
5
|
-
export * from './react-query';
|
5
|
+
export * from './from-partial';
|
6
|
+
export * from './react-query';
|
7
|
+
export * from './types';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './react-query';
|