wasm-ast-types 0.26.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE-Apache +201 -0
- package/LICENSE-MIT +21 -0
- package/README.md +1 -1
- package/{types/client → client}/client.d.ts +2 -2
- package/client/client.js +275 -0
- package/client/index.js +17 -0
- package/{types/context → context}/context.d.ts +9 -22
- package/context/context.js +114 -0
- package/{types/context → context}/imports.d.ts +9 -8
- package/context/imports.js +166 -0
- package/context/index.js +18 -0
- package/esm/client/client.js +238 -0
- package/esm/client/index.js +1 -0
- package/esm/context/context.js +104 -0
- package/esm/context/imports.js +136 -0
- package/{module → esm}/context/index.js +1 -1
- package/{src/index.ts → esm/index.js} +0 -1
- package/esm/message-builder/message-builder.js +64 -0
- package/esm/message-composer/message-composer.js +105 -0
- package/esm/provider/provider.js +97 -0
- package/esm/react-query/react-query.js +458 -0
- package/esm/recoil/recoil.js +110 -0
- package/esm/utils/babel.js +231 -0
- package/esm/utils/constants.js +20 -0
- package/esm/utils/ref.js +4 -0
- package/esm/utils/types.js +343 -0
- package/{types/index.d.ts → index.d.ts} +0 -1
- package/index.js +24 -0
- package/message-builder/index.js +17 -0
- package/{types/message-builder → message-builder}/message-builder.d.ts +1 -1
- package/message-builder/message-builder.js +91 -0
- package/message-composer/index.d.ts +1 -0
- package/message-composer/index.js +17 -0
- package/{types/message-composer → message-composer}/message-composer.d.ts +1 -1
- package/message-composer/message-composer.js +133 -0
- package/package.json +19 -68
- package/provider/index.d.ts +1 -0
- package/provider/index.js +17 -0
- package/provider/provider.js +127 -0
- package/react-query/index.d.ts +1 -0
- package/react-query/index.js +17 -0
- package/{types/react-query → react-query}/react-query.d.ts +2 -3
- package/react-query/react-query.js +490 -0
- package/recoil/index.d.ts +1 -0
- package/recoil/index.js +17 -0
- package/{types/recoil → recoil}/recoil.d.ts +1 -1
- package/recoil/recoil.js +140 -0
- package/{types/utils → utils}/babel.d.ts +9 -8
- package/utils/babel.js +285 -0
- package/utils/constants.js +46 -0
- package/utils/index.js +26 -0
- package/{types/utils → utils}/ref.d.ts +1 -1
- package/utils/ref.js +8 -0
- package/{types/utils → utils}/types.d.ts +8 -8
- package/utils/types.js +379 -0
- package/main/client/client.js +0 -196
- package/main/client/index.js +0 -16
- package/main/client/test/ts-client.account-nfts.spec.js +0 -28
- package/main/client/test/ts-client.arrays-ref.spec.js +0 -19
- package/main/client/test/ts-client.arrays.spec.js +0 -26
- package/main/client/test/ts-client.cw-named-groups.test.js +0 -19
- package/main/client/test/ts-client.cw-proposal-single.test.js +0 -23
- package/main/client/test/ts-client.empty-enums.spec.js +0 -13
- package/main/client/test/ts-client.issue-101.spec.js +0 -23
- package/main/client/test/ts-client.issue-103.test.js +0 -44
- package/main/client/test/ts-client.issue-71.test.js +0 -81
- package/main/client/test/ts-client.issue-98.test.js +0 -28
- package/main/client/test/ts-client.issues.test.js +0 -81
- package/main/client/test/ts-client.overrides.spec.js +0 -33
- package/main/client/test/ts-client.sg721.spec.js +0 -19
- package/main/client/test/ts-client.spec.js +0 -87
- package/main/client/test/ts-client.vectis.spec.js +0 -46
- package/main/client/test/ts-client.wager.spec.js +0 -39
- package/main/context/context.js +0 -162
- package/main/context/imports.js +0 -159
- package/main/context/index.js +0 -27
- package/main/index.js +0 -104
- package/main/message-builder/index.js +0 -16
- package/main/message-builder/message-builder.js +0 -62
- package/main/message-builder/message-builder.spec.js +0 -20
- package/main/message-composer/index.js +0 -16
- package/main/message-composer/message-composer.js +0 -86
- package/main/message-composer/message-composer.spec.js +0 -23
- package/main/provider/index.js +0 -16
- package/main/provider/provider.js +0 -71
- package/main/provider/provider.spec.js +0 -60
- package/main/react-query/index.js +0 -16
- package/main/react-query/react-query.js +0 -413
- package/main/react-query/react-query.spec.js +0 -91
- package/main/recoil/index.js +0 -16
- package/main/recoil/recoil.js +0 -61
- package/main/recoil/recoil.spec.js +0 -20
- package/main/types.js +0 -4
- package/main/utils/babel.js +0 -282
- package/main/utils/babel.spec.js +0 -109
- package/main/utils/constants.js +0 -26
- package/main/utils/index.js +0 -65
- package/main/utils/ref.js +0 -12
- package/main/utils/types.js +0 -343
- package/module/client/client.js +0 -166
- package/module/client/index.js +0 -1
- package/module/client/test/ts-client.account-nfts.spec.js +0 -25
- package/module/client/test/ts-client.arrays-ref.spec.js +0 -16
- package/module/client/test/ts-client.arrays.spec.js +0 -23
- package/module/client/test/ts-client.cw-named-groups.test.js +0 -16
- package/module/client/test/ts-client.cw-proposal-single.test.js +0 -20
- package/module/client/test/ts-client.empty-enums.spec.js +0 -10
- package/module/client/test/ts-client.issue-101.spec.js +0 -22
- package/module/client/test/ts-client.issue-103.test.js +0 -41
- package/module/client/test/ts-client.issue-71.test.js +0 -21
- package/module/client/test/ts-client.issue-98.test.js +0 -25
- package/module/client/test/ts-client.issues.test.js +0 -21
- package/module/client/test/ts-client.overrides.spec.js +0 -30
- package/module/client/test/ts-client.sg721.spec.js +0 -16
- package/module/client/test/ts-client.spec.js +0 -84
- package/module/client/test/ts-client.vectis.spec.js +0 -43
- package/module/client/test/ts-client.wager.spec.js +0 -36
- package/module/context/context.js +0 -116
- package/module/context/imports.js +0 -127
- package/module/index.js +0 -9
- package/module/message-builder/index.js +0 -1
- package/module/message-builder/message-builder.js +0 -52
- package/module/message-builder/message-builder.spec.js +0 -17
- package/module/message-composer/index.js +0 -1
- package/module/message-composer/message-composer.js +0 -70
- package/module/message-composer/message-composer.spec.js +0 -20
- package/module/provider/index.js +0 -1
- package/module/provider/provider.js +0 -45
- package/module/provider/provider.spec.js +0 -58
- package/module/react-query/index.js +0 -1
- package/module/react-query/react-query.js +0 -403
- package/module/react-query/react-query.spec.js +0 -85
- package/module/recoil/index.js +0 -1
- package/module/recoil/recoil.js +0 -46
- package/module/recoil/recoil.spec.js +0 -14
- package/module/types.js +0 -3
- package/module/utils/babel.js +0 -203
- package/module/utils/babel.spec.js +0 -70
- package/module/utils/constants.js +0 -12
- package/module/utils/index.js +0 -6
- package/module/utils/ref.js +0 -4
- package/module/utils/types.js +0 -301
- package/src/client/client.ts +0 -584
- package/src/client/index.ts +0 -1
- package/src/client/test/__snapshots__/ts-client.account-nfts.spec.ts.snap +0 -497
- package/src/client/test/__snapshots__/ts-client.arrays-ref.spec.ts.snap +0 -452
- package/src/client/test/__snapshots__/ts-client.arrays.spec.ts.snap +0 -101
- package/src/client/test/__snapshots__/ts-client.cw-named-groups.test.ts.snap +0 -141
- package/src/client/test/__snapshots__/ts-client.cw-proposal-single.test.ts.snap +0 -341
- package/src/client/test/__snapshots__/ts-client.empty-enums.spec.ts.snap +0 -20
- package/src/client/test/__snapshots__/ts-client.issue-101.spec.ts.snap +0 -47
- package/src/client/test/__snapshots__/ts-client.issue-103.test.ts.snap +0 -79
- package/src/client/test/__snapshots__/ts-client.issue-71.test.ts.snap +0 -432
- package/src/client/test/__snapshots__/ts-client.issue-98.test.ts.snap +0 -117
- package/src/client/test/__snapshots__/ts-client.issues.test.ts.snap +0 -984
- package/src/client/test/__snapshots__/ts-client.overrides.spec.ts.snap +0 -709
- package/src/client/test/__snapshots__/ts-client.sg721.spec.ts.snap +0 -350
- package/src/client/test/__snapshots__/ts-client.spec.ts.snap +0 -723
- package/src/client/test/__snapshots__/ts-client.vectis.spec.ts.snap +0 -337
- package/src/client/test/__snapshots__/ts-client.wager.spec.ts.snap +0 -132
- package/src/client/test/ts-client.account-nfts.spec.ts +0 -55
- package/src/client/test/ts-client.arrays-ref.spec.ts +0 -48
- package/src/client/test/ts-client.arrays.spec.ts +0 -58
- package/src/client/test/ts-client.cw-named-groups.test.ts +0 -48
- package/src/client/test/ts-client.cw-proposal-single.test.ts +0 -50
- package/src/client/test/ts-client.empty-enums.spec.ts +0 -28
- package/src/client/test/ts-client.issue-101.spec.ts +0 -37
- package/src/client/test/ts-client.issue-103.test.ts +0 -106
- package/src/client/test/ts-client.issue-71.test.ts +0 -51
- package/src/client/test/ts-client.issue-98.test.ts +0 -55
- package/src/client/test/ts-client.issues.test.ts +0 -52
- package/src/client/test/ts-client.overrides.spec.ts +0 -74
- package/src/client/test/ts-client.sg721.spec.ts +0 -46
- package/src/client/test/ts-client.spec.ts +0 -166
- package/src/client/test/ts-client.vectis.spec.ts +0 -97
- package/src/client/test/ts-client.wager.spec.ts +0 -63
- package/src/context/context.ts +0 -229
- package/src/context/imports.ts +0 -195
- package/src/context/index.ts +0 -2
- package/src/message-builder/__snapshots__/message-builder.spec.ts.snap +0 -270
- package/src/message-builder/message-builder.spec.ts +0 -24
- package/src/message-builder/message-builder.ts +0 -119
- package/src/message-composer/__snapshots__/message-composer.spec.ts.snap +0 -331
- package/src/message-composer/index.ts +0 -1
- package/src/message-composer/message-composer.spec.ts +0 -46
- package/src/message-composer/message-composer.ts +0 -262
- package/src/provider/__snapshots__/provider.spec.ts.snap +0 -49
- package/src/provider/index.ts +0 -1
- package/src/provider/provider.spec.ts +0 -81
- package/src/provider/provider.ts +0 -237
- package/src/react-query/__snapshots__/react-query.spec.ts.snap +0 -1359
- package/src/react-query/index.ts +0 -1
- package/src/react-query/react-query.spec.ts +0 -116
- package/src/react-query/react-query.ts +0 -1072
- package/src/recoil/__snapshots__/recoil.spec.ts.snap +0 -203
- package/src/recoil/index.ts +0 -1
- package/src/recoil/recoil.spec.ts +0 -38
- package/src/recoil/recoil.ts +0 -307
- package/src/types.ts +0 -44
- package/src/utils/__snapshots__/babel.spec.ts.snap +0 -75
- package/src/utils/babel.spec.ts +0 -511
- package/src/utils/babel.ts +0 -352
- package/src/utils/constants.ts +0 -37
- package/src/utils/ref.ts +0 -6
- package/src/utils/types.ts +0 -478
- package/types/types.d.ts +0 -41
- /package/{types/client → client}/index.d.ts +0 -0
- /package/{types/context → context}/index.d.ts +0 -0
- /package/{src/message-builder/index.ts → esm/message-builder/index.js} +0 -0
- /package/{types/message-composer/index.d.ts → esm/message-composer/index.js} +0 -0
- /package/{types/provider/index.d.ts → esm/provider/index.js} +0 -0
- /package/{types/react-query/index.d.ts → esm/react-query/index.js} +0 -0
- /package/{types/recoil/index.d.ts → esm/recoil/index.js} +0 -0
- /package/{src/utils/index.ts → esm/utils/index.js} +0 -0
- /package/{types/message-builder → message-builder}/index.d.ts +0 -0
- /package/{types/provider → provider}/provider.d.ts +0 -0
- /package/{types/utils → utils}/constants.d.ts +0 -0
- /package/{types/utils → utils}/index.d.ts +0 -0
@@ -1,52 +0,0 @@
|
|
1
|
-
import * as t from '@babel/types';
|
2
|
-
import { camel } from 'case';
|
3
|
-
import { abstractClassDeclaration, arrowFunctionExpression, getMessageProperties } from '../utils';
|
4
|
-
import { createTypedObjectParams } from '../utils/types';
|
5
|
-
import { getWasmMethodArgs } from '../client/client';
|
6
|
-
export const createMessageBuilderClass = (context, className, msg) => {
|
7
|
-
const staticMethods = getMessageProperties(msg).map(schema => {
|
8
|
-
return createStaticExecMethodMessageBuilder(context, schema, msg.title);
|
9
|
-
});
|
10
|
-
|
11
|
-
// const blockStmt = bindings;
|
12
|
-
|
13
|
-
return t.exportNamedDeclaration(abstractClassDeclaration(className, staticMethods, [], null));
|
14
|
-
};
|
15
|
-
|
16
|
-
/**
|
17
|
-
* CamelCasedProperties<Extract<ExecuteMsg, { exec_on_module: unknown }>['exec_on_module']>
|
18
|
-
*/
|
19
|
-
function createExtractTypeAnnotation(underscoreName, msgTitle) {
|
20
|
-
return t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CamelCasedProperties'), t.tsTypeParameterInstantiation([t.tsIndexedAccessType(t.tsTypeReference(t.identifier('Extract'), t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier(msgTitle)), t.tsTypeLiteral([t.tsPropertySignature(t.identifier(underscoreName), t.tsTypeAnnotation(t.tsUnknownKeyword()))])])), t.tsLiteralType(t.stringLiteral(underscoreName)))])));
|
21
|
-
}
|
22
|
-
const createStaticExecMethodMessageBuilder = (context, jsonschema, msgTitle) => {
|
23
|
-
const underscoreName = Object.keys(jsonschema.properties)[0];
|
24
|
-
const methodName = camel(underscoreName);
|
25
|
-
const param = createTypedObjectParams(context, jsonschema.properties[underscoreName]);
|
26
|
-
const args = getWasmMethodArgs(context, jsonschema.properties[underscoreName]);
|
27
|
-
|
28
|
-
// what the underscore named property in the message is assigned to
|
29
|
-
let actionValue;
|
30
|
-
if (param?.type === 'Identifier') {
|
31
|
-
actionValue = t.identifier(param.name);
|
32
|
-
} else {
|
33
|
-
actionValue = t.tsAsExpression(t.objectExpression(args), t.tsTypeReference(t.identifier('const')));
|
34
|
-
}
|
35
|
-
|
36
|
-
// TODO: this is a hack to get the type annotation to work
|
37
|
-
// all type annotations in the future should be the extracted and camelized type
|
38
|
-
if (param && param.typeAnnotation.type === 'TSTypeAnnotation' && param.typeAnnotation.typeAnnotation.type === 'TSTypeLiteral') {
|
39
|
-
param.typeAnnotation = createExtractTypeAnnotation(underscoreName, msgTitle);
|
40
|
-
}
|
41
|
-
return t.classProperty(t.identifier(methodName), arrowFunctionExpression(
|
42
|
-
// params
|
43
|
-
param ? [
|
44
|
-
// props
|
45
|
-
param] : [],
|
46
|
-
// body
|
47
|
-
t.blockStatement([t.returnStatement(t.objectExpression([t.objectProperty(t.identifier(underscoreName), actionValue)]))]),
|
48
|
-
// return type
|
49
|
-
t.tsTypeAnnotation(t.tsTypeReference(t.identifier(msgTitle))), false), null, null, false,
|
50
|
-
// static
|
51
|
-
true);
|
52
|
-
};
|
@@ -1,17 +0,0 @@
|
|
1
|
-
import execute_msg from '../../../../__fixtures__/basic/execute_msg_for__empty.json';
|
2
|
-
import query_msg from '../../../../__fixtures__/basic/query_msg.json';
|
3
|
-
import ownership from '../../../../__fixtures__/basic/ownership.json';
|
4
|
-
import { createMessageBuilderClass } from './message-builder';
|
5
|
-
import { expectCode, makeContext } from '../../test-utils';
|
6
|
-
it('execute class', () => {
|
7
|
-
const ctx = makeContext(execute_msg);
|
8
|
-
expectCode(createMessageBuilderClass(ctx, 'SG721MessageBuilder', execute_msg));
|
9
|
-
});
|
10
|
-
it('query class', () => {
|
11
|
-
const ctx = makeContext(query_msg);
|
12
|
-
expectCode(createMessageBuilderClass(ctx, 'SG721MessageBuilder', query_msg));
|
13
|
-
});
|
14
|
-
it('ownership', () => {
|
15
|
-
const ctx = makeContext(ownership);
|
16
|
-
expectCode(createMessageBuilderClass(ctx, 'Ownership', ownership));
|
17
|
-
});
|
@@ -1 +0,0 @@
|
|
1
|
-
export * from './message-composer';
|
@@ -1,70 +0,0 @@
|
|
1
|
-
import * as t from '@babel/types';
|
2
|
-
import { camel } from 'case';
|
3
|
-
import { arrowFunctionExpression, bindMethod, classDeclaration, classProperty, getMessageProperties, OPTIONAL_FUNDS_PARAM, typedIdentifier } from '../utils';
|
4
|
-
import { createTypedObjectParams } from '../utils/types';
|
5
|
-
import { getWasmMethodArgs } from '../client/client';
|
6
|
-
const createWasmExecMethodMessageComposer = (context, jsonschema) => {
|
7
|
-
context.addUtil('Coin');
|
8
|
-
context.addUtil('MsgExecuteContractEncodeObject');
|
9
|
-
context.addUtil('MsgExecuteContract');
|
10
|
-
context.addUtil('toUtf8');
|
11
|
-
const underscoreName = Object.keys(jsonschema.properties)[0];
|
12
|
-
const methodName = camel(underscoreName);
|
13
|
-
const param = createTypedObjectParams(context, jsonschema.properties[underscoreName]);
|
14
|
-
const args = getWasmMethodArgs(context, jsonschema.properties[underscoreName]);
|
15
|
-
|
16
|
-
// what the underscore named property in the message is assigned to
|
17
|
-
let actionValue;
|
18
|
-
if (param?.type === 'Identifier') {
|
19
|
-
actionValue = t.identifier(param.name);
|
20
|
-
} else {
|
21
|
-
actionValue = t.objectExpression(args);
|
22
|
-
}
|
23
|
-
const constantParams = [OPTIONAL_FUNDS_PARAM];
|
24
|
-
return t.classProperty(t.identifier(methodName), arrowFunctionExpression(param ? [
|
25
|
-
// props
|
26
|
-
param, ...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), actionValue)])])])), t.objectProperty(t.identifier('funds'), t.identifier('_funds'))])]))]))]),
|
27
|
-
// return type
|
28
|
-
t.tsTypeAnnotation(t.tsTypeReference(t.identifier('MsgExecuteContractEncodeObject'))), false));
|
29
|
-
};
|
30
|
-
export const createMessageComposerClass = (context, className, implementsClassName, execMsg) => {
|
31
|
-
const propertyNames = getMessageProperties(execMsg).map(method => Object.keys(method.properties)?.[0]).filter(Boolean);
|
32
|
-
const bindings = propertyNames.map(camel).map(bindMethod);
|
33
|
-
const methods = getMessageProperties(execMsg).map(schema => {
|
34
|
-
return createWasmExecMethodMessageComposer(context, schema);
|
35
|
-
});
|
36
|
-
const blockStmt = [];
|
37
|
-
[].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]);
|
38
|
-
return t.exportNamedDeclaration(classDeclaration(className, [
|
39
|
-
// sender
|
40
|
-
classProperty('sender', t.tsTypeAnnotation(t.tsStringKeyword())),
|
41
|
-
// contractAddress
|
42
|
-
classProperty('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword())),
|
43
|
-
// constructor
|
44
|
-
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));
|
45
|
-
};
|
46
|
-
export const createMessageComposerInterface = (context, className, execMsg) => {
|
47
|
-
const methods = getMessageProperties(execMsg).map(jsonschema => {
|
48
|
-
const underscoreName = Object.keys(jsonschema.properties)[0];
|
49
|
-
const methodName = camel(underscoreName);
|
50
|
-
return createPropertyFunctionWithObjectParamsForMessageComposer(context, methodName, 'MsgExecuteContractEncodeObject', jsonschema.properties[underscoreName]);
|
51
|
-
});
|
52
|
-
const extendsAst = [];
|
53
|
-
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(className), null, extendsAst, t.tSInterfaceBody([
|
54
|
-
// contract address
|
55
|
-
t.tSPropertySignature(t.identifier('contractAddress'), t.tsTypeAnnotation(t.tsStringKeyword())),
|
56
|
-
// contract address
|
57
|
-
t.tSPropertySignature(t.identifier('sender'), t.tsTypeAnnotation(t.tsStringKeyword())), ...methods])));
|
58
|
-
};
|
59
|
-
const createPropertyFunctionWithObjectParamsForMessageComposer = (context, methodName, responseType, jsonschema) => {
|
60
|
-
const obj = createTypedObjectParams(context, jsonschema);
|
61
|
-
const fixedParams = [OPTIONAL_FUNDS_PARAM];
|
62
|
-
const func = {
|
63
|
-
type: 'TSFunctionType',
|
64
|
-
typeAnnotation: t.tsTypeAnnotation(t.tsTypeReference(t.identifier(responseType))),
|
65
|
-
parameters: obj ? [obj, ...fixedParams] : fixedParams
|
66
|
-
};
|
67
|
-
return t.tSPropertySignature(t.identifier(methodName), t.tsTypeAnnotation(
|
68
|
-
// @ts-ignore:next-line
|
69
|
-
func));
|
70
|
-
};
|
@@ -1,20 +0,0 @@
|
|
1
|
-
import execute_msg from "../../../../__fixtures__/basic/execute_msg_for__empty.json";
|
2
|
-
import ownership from "../../../../__fixtures__/basic/ownership.json";
|
3
|
-
import { createMessageComposerClass, createMessageComposerInterface } from "./message-composer";
|
4
|
-
import { expectCode, makeContext } from "../../test-utils";
|
5
|
-
it("execute classes", () => {
|
6
|
-
const ctx = makeContext(execute_msg);
|
7
|
-
expectCode(createMessageComposerClass(ctx, "SG721MessageComposer", "SG721Message", execute_msg));
|
8
|
-
});
|
9
|
-
it("createMessageComposerInterface", () => {
|
10
|
-
const ctx = makeContext(execute_msg);
|
11
|
-
expectCode(createMessageComposerInterface(ctx, "SG721Message", execute_msg));
|
12
|
-
});
|
13
|
-
it("ownershipClass", () => {
|
14
|
-
const ctx = makeContext(ownership);
|
15
|
-
expectCode(createMessageComposerClass(ctx, "OwnershipMessageComposer", "OwnershipMessage", ownership));
|
16
|
-
});
|
17
|
-
it("ownershipInterface", () => {
|
18
|
-
const ownershipCtx = makeContext(ownership);
|
19
|
-
expectCode(createMessageComposerInterface(ownershipCtx, "OwnershipMessage", ownership));
|
20
|
-
});
|
package/module/provider/index.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export * from './provider';
|
@@ -1,45 +0,0 @@
|
|
1
|
-
import * as t from "@babel/types";
|
2
|
-
import { camel, pascal } from "case";
|
3
|
-
import { PROVIDER_TYPES } from "../utils/constants";
|
4
|
-
import { identifier, tsObjectPattern } from "../utils";
|
5
|
-
export const createProvider = (name, providerInfos) => {
|
6
|
-
const classDeclaration = t.classDeclaration(t.identifier(name), t.identifier("ContractBase"), t.classBody([t.classMethod("constructor", t.identifier("constructor"), [tsObjectPattern([t.objectProperty(t.identifier("address"), t.identifier("address"), false, true), t.objectProperty(t.identifier("cosmWasmClient"), t.identifier("cosmWasmClient"), false, true), t.objectProperty(t.identifier("signingCosmWasmClient"), t.identifier("signingCosmWasmClient"), false, true)], t.tsTypeAnnotation(t.tsTypeReference(t.identifier("IContractConstructor"))))], t.blockStatement([t.expressionStatement(t.callExpression(t.super(), [t.identifier("address"), t.identifier("cosmWasmClient"), t.identifier("signingCosmWasmClient"), t.identifier(providerInfos[PROVIDER_TYPES.SIGNING_CLIENT_TYPE] ? providerInfos[PROVIDER_TYPES.SIGNING_CLIENT_TYPE].classname : "undefined"), t.identifier(providerInfos[PROVIDER_TYPES.QUERY_CLIENT_TYPE] ? providerInfos[PROVIDER_TYPES.QUERY_CLIENT_TYPE].classname : "undefined"), t.identifier(providerInfos[PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE] ? providerInfos[PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE].classname : "undefined")]))]))]));
|
7
|
-
classDeclaration.superTypeParameters = t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier(providerInfos[PROVIDER_TYPES.SIGNING_CLIENT_TYPE] ? providerInfos[PROVIDER_TYPES.SIGNING_CLIENT_TYPE].classname : "IEmptyClient")), t.tsTypeReference(t.identifier(providerInfos[PROVIDER_TYPES.QUERY_CLIENT_TYPE] ? providerInfos[PROVIDER_TYPES.QUERY_CLIENT_TYPE].classname : "IEmptyClient")), t.tsTypeReference(t.identifier(providerInfos[PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE] ? providerInfos[PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE].classname : "IEmptyClient"))]);
|
8
|
-
return t.exportNamedDeclaration(classDeclaration);
|
9
|
-
};
|
10
|
-
export const createIContractsContext = providerInfos => {
|
11
|
-
const properties = [];
|
12
|
-
for (const key in providerInfos) {
|
13
|
-
if (Object.prototype.hasOwnProperty.call(providerInfos, key)) {
|
14
|
-
const contractProviderInfo = providerInfos[key];
|
15
|
-
properties.push(createProperty(key, contractProviderInfo));
|
16
|
-
}
|
17
|
-
}
|
18
|
-
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier("IContractsContext"), null, null, t.tsInterfaceBody(properties)));
|
19
|
-
};
|
20
|
-
let PROVIDER_MAPPING = {};
|
21
|
-
PROVIDER_MAPPING[PROVIDER_TYPES.SIGNING_CLIENT_TYPE] = "ISigningClientProvider";
|
22
|
-
PROVIDER_MAPPING[PROVIDER_TYPES.QUERY_CLIENT_TYPE] = "IQueryClientProvider";
|
23
|
-
PROVIDER_MAPPING[PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE] = "IMessageComposerProvider";
|
24
|
-
export const createProperty = (name, providerInfos) => {
|
25
|
-
let typeAnnotation = null;
|
26
|
-
const keys = Object.keys(providerInfos);
|
27
|
-
if (keys?.length == 1) {
|
28
|
-
const key = keys[0];
|
29
|
-
typeAnnotation = t.tsTypeAnnotation(t.tsTypeReference(t.identifier(PROVIDER_MAPPING[key]), t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier(providerInfos[key].classname))])));
|
30
|
-
} else {
|
31
|
-
const typeRefs = [];
|
32
|
-
for (const key of keys) {
|
33
|
-
typeRefs.push(t.tsTypeReference(t.identifier(PROVIDER_MAPPING[key]), t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier(providerInfos[key].classname))])));
|
34
|
-
}
|
35
|
-
typeAnnotation = t.tsTypeAnnotation(t.tsIntersectionType(typeRefs));
|
36
|
-
}
|
37
|
-
return t.tsPropertySignature(t.identifier(camel(name)), typeAnnotation);
|
38
|
-
};
|
39
|
-
export const createGettingProviders = providerInfos => {
|
40
|
-
const properties = [];
|
41
|
-
for (const key of Object.keys(providerInfos)) {
|
42
|
-
properties.push(t.objectProperty(t.identifier(camel(key)), t.newExpression(t.identifier(pascal(key)), [t.objectExpression([t.objectProperty(t.identifier("address"), t.identifier("address"), false, true), t.objectProperty(t.identifier("cosmWasmClient"), t.identifier("cosmWasmClient"), false, true), t.objectProperty(t.identifier("signingCosmWasmClient"), t.identifier("signingCosmWasmClient"), false, true)])])));
|
43
|
-
}
|
44
|
-
return t.exportNamedDeclaration(t.variableDeclaration("const", [t.variableDeclarator(t.identifier("getProviders"), t.arrowFunctionExpression([identifier("address?", t.tsTypeAnnotation(t.tsTypeReference(t.identifier("string")))), identifier("cosmWasmClient?", t.tsTypeAnnotation(t.tsTypeReference(t.identifier("CosmWasmClient")))), identifier("signingCosmWasmClient?", t.tsTypeAnnotation(t.tsTypeReference(t.identifier("SigningCosmWasmClient"))))], t.objectExpression(properties)))]));
|
45
|
-
};
|
@@ -1,58 +0,0 @@
|
|
1
|
-
import { createGettingProviders, createIContractsContext, createProvider } from "./provider";
|
2
|
-
import { expectCode } from "../../test-utils";
|
3
|
-
import { PROVIDER_TYPES } from "../utils/constants";
|
4
|
-
it("execute class", () => {
|
5
|
-
let info = {};
|
6
|
-
info[PROVIDER_TYPES.SIGNING_CLIENT_TYPE] = {
|
7
|
-
classname: "WhitelistClient"
|
8
|
-
};
|
9
|
-
info[PROVIDER_TYPES.QUERY_CLIENT_TYPE] = {
|
10
|
-
classname: "WhitelistQueryClient"
|
11
|
-
};
|
12
|
-
info[PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE] = {
|
13
|
-
classname: "WhitelistMessageComposer"
|
14
|
-
};
|
15
|
-
expectCode(createProvider("Whitelist", info));
|
16
|
-
});
|
17
|
-
it("execute class without message composer", () => {
|
18
|
-
let info = {};
|
19
|
-
info[PROVIDER_TYPES.SIGNING_CLIENT_TYPE] = {
|
20
|
-
classname: "WhitelistClient"
|
21
|
-
};
|
22
|
-
info[PROVIDER_TYPES.QUERY_CLIENT_TYPE] = {
|
23
|
-
classname: "WhitelistQueryClient"
|
24
|
-
};
|
25
|
-
expectCode(createProvider("Whitelist", info));
|
26
|
-
});
|
27
|
-
it("create IContractsContext", () => {
|
28
|
-
let info = {
|
29
|
-
Whitelist: {},
|
30
|
-
Marketplace: {}
|
31
|
-
};
|
32
|
-
info["Whitelist"][PROVIDER_TYPES.SIGNING_CLIENT_TYPE] = {
|
33
|
-
classname: "WhitelistClient"
|
34
|
-
};
|
35
|
-
info["Whitelist"][PROVIDER_TYPES.QUERY_CLIENT_TYPE] = {
|
36
|
-
classname: "WhitelistQueryClient"
|
37
|
-
};
|
38
|
-
info["Marketplace"][PROVIDER_TYPES.SIGNING_CLIENT_TYPE] = {
|
39
|
-
classname: "MarketplaceClient"
|
40
|
-
};
|
41
|
-
expectCode(createIContractsContext(info));
|
42
|
-
});
|
43
|
-
it("create getProviders", () => {
|
44
|
-
let info = {
|
45
|
-
Whitelist: {},
|
46
|
-
Marketplace: {}
|
47
|
-
};
|
48
|
-
info["Whitelist"][PROVIDER_TYPES.SIGNING_CLIENT_TYPE] = {
|
49
|
-
classname: "WhitelistClient"
|
50
|
-
};
|
51
|
-
info["Whitelist"][PROVIDER_TYPES.QUERY_CLIENT_TYPE] = {
|
52
|
-
classname: "WhitelistQueryClient"
|
53
|
-
};
|
54
|
-
info["Marketplace"][PROVIDER_TYPES.SIGNING_CLIENT_TYPE] = {
|
55
|
-
classname: "MarketplaceClient"
|
56
|
-
};
|
57
|
-
expectCode(createGettingProviders(info));
|
58
|
-
});
|
@@ -1 +0,0 @@
|
|
1
|
-
export * from './react-query';
|