wasm-ast-types 0.24.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/main/client/client.js +46 -72
- package/main/client/index.js +0 -2
- package/main/client/test/ts-client.account-nfts.spec.js +3 -5
- package/main/client/test/ts-client.arrays-ref.spec.js +0 -4
- package/main/client/test/ts-client.arrays.spec.js +3 -6
- package/main/client/test/ts-client.cw-named-groups.test.js +0 -4
- package/main/client/test/ts-client.cw-proposal-single.test.js +0 -5
- package/main/client/test/ts-client.empty-enums.spec.js +0 -4
- package/main/client/test/ts-client.issue-101.spec.js +0 -4
- package/main/client/test/ts-client.issue-103.test.js +0 -4
- package/main/client/test/ts-client.issue-71.test.js +28 -50
- package/main/client/test/ts-client.issue-98.test.js +3 -5
- package/main/client/test/ts-client.issues.test.js +28 -50
- package/main/client/test/ts-client.overrides.spec.js +0 -4
- package/main/client/test/ts-client.sg721.spec.js +0 -4
- package/main/client/test/ts-client.spec.js +0 -17
- package/main/client/test/ts-client.vectis.spec.js +0 -8
- package/main/client/test/ts-client.wager.spec.js +4 -5
- package/main/context/context.js +6 -33
- package/main/context/imports.js +7 -43
- package/main/context/index.js +0 -4
- package/main/index.js +4 -22
- package/main/{msg-builder → message-builder}/index.js +4 -6
- package/main/{msg-builder/msg-builder.js → message-builder/message-builder.js} +24 -30
- package/main/{msg-builder/msg-builder.spec.js → message-builder/message-builder.spec.js} +4 -10
- package/main/message-composer/index.js +0 -2
- package/main/message-composer/message-composer.js +18 -28
- package/main/message-composer/message-composer.spec.js +0 -5
- package/main/provider/index.js +0 -2
- package/main/provider/provider.js +2 -29
- package/main/provider/provider.spec.js +0 -3
- package/main/react-query/index.js +0 -2
- package/main/react-query/react-query.js +125 -152
- package/main/react-query/react-query.spec.js +0 -10
- package/main/recoil/index.js +0 -2
- package/main/recoil/recoil.js +0 -14
- package/main/recoil/recoil.spec.js +0 -8
- package/main/utils/babel.js +12 -98
- package/main/utils/babel.spec.js +72 -67
- package/main/utils/constants.js +0 -6
- package/main/utils/index.js +0 -7
- package/main/utils/ref.js +0 -3
- package/main/utils/types.js +22 -109
- package/module/client/client.js +46 -32
- package/module/client/test/ts-client.account-nfts.spec.js +3 -1
- package/module/client/test/ts-client.arrays.spec.js +3 -1
- package/module/client/test/ts-client.issue-101.spec.js +3 -1
- package/module/client/test/ts-client.issue-98.test.js +3 -1
- package/module/client/test/ts-client.wager.spec.js +4 -1
- package/module/context/context.js +9 -23
- package/module/context/imports.js +5 -24
- package/module/index.js +1 -1
- package/module/message-builder/index.js +1 -0
- package/module/{msg-builder/msg-builder.js → message-builder/message-builder.js} +22 -17
- package/module/{msg-builder/msg-builder.spec.js → message-builder/message-builder.spec.js} +4 -4
- package/module/message-composer/message-composer.js +18 -14
- package/module/provider/provider.js +0 -8
- package/module/react-query/react-query.js +77 -76
- package/module/utils/babel.js +4 -14
- package/module/utils/babel.spec.js +49 -23
- package/module/utils/types.js +18 -66
- package/package.json +2 -2
- package/src/context/context.ts +158 -158
- package/src/index.ts +1 -1
- package/src/{msg-builder/__snapshots__/msg-builder.spec.ts.snap → message-builder/__snapshots__/message-builder.spec.ts.snap} +2 -2
- package/src/message-builder/index.ts +1 -0
- package/src/{msg-builder/msg-builder.spec.ts → message-builder/message-builder.spec.ts} +6 -7
- package/src/{msg-builder/msg-builder.ts → message-builder/message-builder.ts} +5 -5
- package/src/react-query/react-query.spec.ts +1 -1
- package/types/context/context.d.ts +2 -2
- package/types/index.d.ts +1 -1
- package/types/message-builder/index.d.ts +1 -0
- package/types/message-builder/message-builder.d.ts +4 -0
- package/module/msg-builder/index.js +0 -1
- package/src/msg-builder/index.ts +0 -1
- package/types/msg-builder/index.d.ts +0 -1
- package/types/msg-builder/msg-builder.d.ts +0 -4
@@ -1,13 +1,14 @@
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
2
|
-
|
3
2
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
4
|
-
|
5
3
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
6
|
-
|
7
4
|
import { refLookup } from "../utils";
|
8
5
|
import { convertUtilsToImportList, getImportStatements } from "./imports";
|
9
6
|
import deepmerge from "deepmerge";
|
10
|
-
import { basename, extname } from 'path';
|
7
|
+
import { basename, extname } from 'path';
|
8
|
+
|
9
|
+
/// Plugin Types
|
10
|
+
|
11
|
+
/// END Plugin Types
|
11
12
|
|
12
13
|
;
|
13
14
|
export const defaultOptions = {
|
@@ -27,7 +28,7 @@ export const defaultOptions = {
|
|
27
28
|
messageComposer: {
|
28
29
|
enabled: false
|
29
30
|
},
|
30
|
-
|
31
|
+
messageBuilder: {
|
31
32
|
enabled: false
|
32
33
|
},
|
33
34
|
reactQuery: {
|
@@ -41,7 +42,8 @@ export const defaultOptions = {
|
|
41
42
|
};
|
42
43
|
export const getDefinitionSchema = schemas => {
|
43
44
|
const aggregateSchema = {
|
44
|
-
definitions: {
|
45
|
+
definitions: {
|
46
|
+
//
|
45
47
|
}
|
46
48
|
};
|
47
49
|
schemas.forEach(schema => {
|
@@ -54,42 +56,33 @@ export class BuilderContext {
|
|
54
56
|
constructor() {
|
55
57
|
_defineProperty(this, "providers", {});
|
56
58
|
}
|
57
|
-
|
58
59
|
addProviderInfo(contractName, type, classname, filename) {
|
59
60
|
if (!this.providers[contractName]) {
|
60
61
|
this.providers[contractName] = {};
|
61
62
|
}
|
62
|
-
|
63
63
|
this.providers[contractName][type] = {
|
64
64
|
classname,
|
65
65
|
filename,
|
66
66
|
basename: basename(filename, extname(filename))
|
67
67
|
};
|
68
68
|
}
|
69
|
-
|
70
69
|
getProviderInfos() {
|
71
70
|
return this.providers;
|
72
71
|
}
|
73
|
-
|
74
72
|
}
|
73
|
+
|
75
74
|
/**
|
76
75
|
* context object for generating code.
|
77
76
|
* only mergeDefaultOpt needs to implementing for combine options and default options.
|
78
77
|
* @param TOpt option type
|
79
78
|
*/
|
80
|
-
|
81
79
|
export class RenderContextBase {
|
82
80
|
constructor(contract, options, builderContext) {
|
83
81
|
_defineProperty(this, "builderContext", void 0);
|
84
|
-
|
85
82
|
_defineProperty(this, "contract", void 0);
|
86
|
-
|
87
83
|
_defineProperty(this, "utils", []);
|
88
|
-
|
89
84
|
_defineProperty(this, "schema", void 0);
|
90
|
-
|
91
85
|
_defineProperty(this, "options", void 0);
|
92
|
-
|
93
86
|
this.contract = contract;
|
94
87
|
this.schema = getDefinitionSchema(contract.schemas);
|
95
88
|
this.options = this.mergeDefaultOpt(options);
|
@@ -100,31 +93,24 @@ export class RenderContextBase {
|
|
100
93
|
* @param options
|
101
94
|
*/
|
102
95
|
|
103
|
-
|
104
96
|
refLookup($ref) {
|
105
97
|
return refLookup($ref, this.schema);
|
106
98
|
}
|
107
|
-
|
108
99
|
addUtil(util) {
|
109
100
|
this.utils[util] = true;
|
110
101
|
}
|
111
|
-
|
112
102
|
addProviderInfo(contractName, type, classname, filename) {
|
113
103
|
this.builderContext.addProviderInfo(contractName, type, classname, filename);
|
114
104
|
}
|
115
|
-
|
116
105
|
getProviderInfos() {
|
117
106
|
return this.builderContext.providers;
|
118
107
|
}
|
119
|
-
|
120
108
|
getImports(registeredUtils, filepath) {
|
121
109
|
return getImportStatements(convertUtilsToImportList(this, Object.keys(this.utils), registeredUtils), filepath);
|
122
110
|
}
|
123
|
-
|
124
111
|
}
|
125
112
|
export class RenderContext extends RenderContextBase {
|
126
113
|
mergeDefaultOpt(options) {
|
127
114
|
return deepmerge(defaultOptions, options ?? {});
|
128
115
|
}
|
129
|
-
|
130
116
|
}
|
@@ -1,13 +1,9 @@
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
2
|
-
|
3
2
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
4
|
-
|
5
3
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
6
|
-
|
7
4
|
import * as t from '@babel/types';
|
8
5
|
import { importAs, importStmt } from "../utils";
|
9
6
|
import { relative, dirname, extname } from 'path';
|
10
|
-
|
11
7
|
const makeReactQuerySwitch = varName => {
|
12
8
|
return context => {
|
13
9
|
switch (context.options.reactQuery.version) {
|
@@ -17,7 +13,6 @@ const makeReactQuerySwitch = varName => {
|
|
17
13
|
path: '@tanstack/react-query',
|
18
14
|
name: varName
|
19
15
|
};
|
20
|
-
|
21
16
|
case 'v3':
|
22
17
|
default:
|
23
18
|
return {
|
@@ -28,7 +23,6 @@ const makeReactQuerySwitch = varName => {
|
|
28
23
|
}
|
29
24
|
};
|
30
25
|
};
|
31
|
-
|
32
26
|
export const UTILS = {
|
33
27
|
selectorFamily: 'recoil',
|
34
28
|
MsgExecuteContract: 'cosmjs-types/cosmwasm/wasm/v1/tx',
|
@@ -49,27 +43,21 @@ export const UTIL_HELPERS = ['__contractContextBase__'];
|
|
49
43
|
export const convertUtilsToImportList = (context, utils, registeredUtils) => {
|
50
44
|
return utils.map(util => {
|
51
45
|
let result = null;
|
52
|
-
|
53
46
|
if (registeredUtils) {
|
54
47
|
result = convertUtil(context, util, registeredUtils);
|
55
|
-
|
56
48
|
if (result) {
|
57
49
|
return result;
|
58
50
|
}
|
59
51
|
}
|
60
|
-
|
61
52
|
result = convertUtil(context, util, UTILS);
|
62
|
-
|
63
53
|
if (result) {
|
64
54
|
return result;
|
65
55
|
}
|
66
|
-
|
67
56
|
throw new Error(`missing Util! ::[${util}]`);
|
68
57
|
});
|
69
58
|
};
|
70
59
|
export const convertUtil = (context, util, registeredUtils) => {
|
71
60
|
if (!registeredUtils.hasOwnProperty(util)) return null;
|
72
|
-
|
73
61
|
if (typeof registeredUtils[util] === 'string') {
|
74
62
|
return {
|
75
63
|
type: 'import',
|
@@ -81,8 +69,9 @@ export const convertUtil = (context, util, registeredUtils) => {
|
|
81
69
|
} else {
|
82
70
|
return registeredUtils[util];
|
83
71
|
}
|
84
|
-
};
|
72
|
+
};
|
85
73
|
|
74
|
+
// __helpers__
|
86
75
|
export const getImportStatements = (list, filepath) => {
|
87
76
|
// swap helpers with helpers file...
|
88
77
|
const modifiedImports = list.map(imp => {
|
@@ -92,49 +81,41 @@ export const getImportStatements = (list, filepath) => {
|
|
92
81
|
path: getRelativePath(filepath, `./${name}`)
|
93
82
|
});
|
94
83
|
}
|
95
|
-
|
96
84
|
return imp;
|
97
85
|
});
|
98
86
|
const imports = modifiedImports.reduce((m, obj) => {
|
99
87
|
m[obj.path] = m[obj.path] || [];
|
100
|
-
const exists = m[obj.path].find(el => el.type === obj.type && el.path === obj.path && el.name === obj.name);
|
101
|
-
// TODO some have google.protobuf.Any shows up... figure out the better way to handle this
|
88
|
+
const exists = m[obj.path].find(el => el.type === obj.type && el.path === obj.path && el.name === obj.name);
|
102
89
|
|
90
|
+
// MARKED AS NOT DRY [google.protobuf names]
|
91
|
+
// TODO some have google.protobuf.Any shows up... figure out the better way to handle this
|
103
92
|
if (/\./.test(obj.name)) {
|
104
93
|
obj.name = obj.name.split('.')[obj.name.split('.').length - 1];
|
105
94
|
}
|
106
|
-
|
107
95
|
if (!exists) {
|
108
96
|
m[obj.path].push(obj);
|
109
97
|
}
|
110
|
-
|
111
98
|
return m;
|
112
99
|
}, {});
|
113
100
|
return Object.entries(imports).reduce((m, [importPath, imports]) => {
|
114
101
|
const defaultImports = imports.filter(a => a.type === 'default');
|
115
|
-
|
116
102
|
if (defaultImports.length) {
|
117
103
|
if (defaultImports.length > 1) throw new Error('more than one default name NOT allowed.');
|
118
104
|
m.push(t.importDeclaration([t.importDefaultSpecifier(t.identifier(defaultImports[0].name))], t.stringLiteral(defaultImports[0].path)));
|
119
105
|
}
|
120
|
-
|
121
106
|
const namedImports = imports.filter(a => a.type === 'import' && (!a.importAs || a.name === a.importAs));
|
122
|
-
|
123
107
|
if (namedImports.length) {
|
124
108
|
m.push(importStmt(namedImports.map(i => i.name), namedImports[0].path));
|
125
109
|
}
|
126
|
-
|
127
110
|
const aliasNamedImports = imports.filter(a => a.type === 'import' && a.importAs && a.name !== a.importAs);
|
128
111
|
aliasNamedImports.forEach(imp => {
|
129
112
|
m.push(importAs(imp.name, imp.importAs, imp.path));
|
130
113
|
});
|
131
114
|
const namespaced = imports.filter(a => a.type === 'namespace');
|
132
|
-
|
133
115
|
if (namespaced.length) {
|
134
116
|
if (namespaced.length > 1) throw new Error('more than one namespaced name NOT allowed.');
|
135
117
|
m.push(t.importDeclaration([t.importNamespaceSpecifier(t.identifier(namespaced[0].name))], t.stringLiteral(namespaced[0].path)));
|
136
118
|
}
|
137
|
-
|
138
119
|
return m;
|
139
120
|
}, []);
|
140
121
|
};
|
package/module/index.js
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
export * from './message-builder';
|
@@ -3,45 +3,50 @@ import { camel } from 'case';
|
|
3
3
|
import { abstractClassDeclaration, arrowFunctionExpression, getMessageProperties } from '../utils';
|
4
4
|
import { createTypedObjectParams } from '../utils/types';
|
5
5
|
import { getWasmMethodArgs } from '../client/client';
|
6
|
-
export const
|
6
|
+
export const createMessageBuilderClass = (context, className, msg) => {
|
7
7
|
const staticMethods = getMessageProperties(msg).map(schema => {
|
8
|
-
return
|
9
|
-
});
|
8
|
+
return createStaticExecMethodMessageBuilder(context, schema, msg.title);
|
9
|
+
});
|
10
|
+
|
11
|
+
// const blockStmt = bindings;
|
10
12
|
|
11
13
|
return t.exportNamedDeclaration(abstractClassDeclaration(className, staticMethods, [], null));
|
12
14
|
};
|
15
|
+
|
13
16
|
/**
|
14
17
|
* CamelCasedProperties<Extract<ExecuteMsg, { exec_on_module: unknown }>['exec_on_module']>
|
15
18
|
*/
|
16
|
-
|
17
19
|
function createExtractTypeAnnotation(underscoreName, msgTitle) {
|
18
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)))])));
|
19
21
|
}
|
20
|
-
|
21
|
-
const createStaticExecMethodMsgBuilder = (context, jsonschema, msgTitle) => {
|
22
|
+
const createStaticExecMethodMessageBuilder = (context, jsonschema, msgTitle) => {
|
22
23
|
const underscoreName = Object.keys(jsonschema.properties)[0];
|
23
24
|
const methodName = camel(underscoreName);
|
24
25
|
const param = createTypedObjectParams(context, jsonschema.properties[underscoreName]);
|
25
|
-
const args = getWasmMethodArgs(context, jsonschema.properties[underscoreName]);
|
26
|
+
const args = getWasmMethodArgs(context, jsonschema.properties[underscoreName]);
|
26
27
|
|
28
|
+
// what the underscore named property in the message is assigned to
|
27
29
|
let actionValue;
|
28
|
-
|
29
30
|
if (param?.type === 'Identifier') {
|
30
31
|
actionValue = t.identifier(param.name);
|
31
32
|
} else {
|
32
33
|
actionValue = t.tsAsExpression(t.objectExpression(args), t.tsTypeReference(t.identifier('const')));
|
33
|
-
}
|
34
|
-
// all type annotations in the future should be the extracted and camelized type
|
35
|
-
|
34
|
+
}
|
36
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
|
37
38
|
if (param && param.typeAnnotation.type === 'TSTypeAnnotation' && param.typeAnnotation.typeAnnotation.type === 'TSTypeLiteral') {
|
38
39
|
param.typeAnnotation = createExtractTypeAnnotation(underscoreName, msgTitle);
|
39
40
|
}
|
40
|
-
|
41
|
-
|
42
|
-
param ? [
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
46
51
|
true);
|
47
52
|
};
|
@@ -1,17 +1,17 @@
|
|
1
1
|
import execute_msg from '../../../../__fixtures__/basic/execute_msg_for__empty.json';
|
2
2
|
import query_msg from '../../../../__fixtures__/basic/query_msg.json';
|
3
3
|
import ownership from '../../../../__fixtures__/basic/ownership.json';
|
4
|
-
import {
|
4
|
+
import { createMessageBuilderClass } from './message-builder';
|
5
5
|
import { expectCode, makeContext } from '../../test-utils';
|
6
6
|
it('execute class', () => {
|
7
7
|
const ctx = makeContext(execute_msg);
|
8
|
-
expectCode(
|
8
|
+
expectCode(createMessageBuilderClass(ctx, 'SG721MessageBuilder', execute_msg));
|
9
9
|
});
|
10
10
|
it('query class', () => {
|
11
11
|
const ctx = makeContext(query_msg);
|
12
|
-
expectCode(
|
12
|
+
expectCode(createMessageBuilderClass(ctx, 'SG721MessageBuilder', query_msg));
|
13
13
|
});
|
14
14
|
it('ownership', () => {
|
15
15
|
const ctx = makeContext(ownership);
|
16
|
-
expectCode(
|
16
|
+
expectCode(createMessageBuilderClass(ctx, 'Ownership', ownership));
|
17
17
|
});
|
@@ -3,7 +3,6 @@ import { camel } from 'case';
|
|
3
3
|
import { arrowFunctionExpression, bindMethod, classDeclaration, classProperty, getMessageProperties, OPTIONAL_FUNDS_PARAM, typedIdentifier } from '../utils';
|
4
4
|
import { createTypedObjectParams } from '../utils/types';
|
5
5
|
import { getWasmMethodArgs } from '../client/client';
|
6
|
-
|
7
6
|
const createWasmExecMethodMessageComposer = (context, jsonschema) => {
|
8
7
|
context.addUtil('Coin');
|
9
8
|
context.addUtil('MsgExecuteContractEncodeObject');
|
@@ -12,22 +11,22 @@ const createWasmExecMethodMessageComposer = (context, jsonschema) => {
|
|
12
11
|
const underscoreName = Object.keys(jsonschema.properties)[0];
|
13
12
|
const methodName = camel(underscoreName);
|
14
13
|
const param = createTypedObjectParams(context, jsonschema.properties[underscoreName]);
|
15
|
-
const args = getWasmMethodArgs(context, jsonschema.properties[underscoreName]);
|
14
|
+
const args = getWasmMethodArgs(context, jsonschema.properties[underscoreName]);
|
16
15
|
|
16
|
+
// what the underscore named property in the message is assigned to
|
17
17
|
let actionValue;
|
18
|
-
|
19
18
|
if (param?.type === 'Identifier') {
|
20
19
|
actionValue = t.identifier(param.name);
|
21
20
|
} else {
|
22
21
|
actionValue = t.objectExpression(args);
|
23
22
|
}
|
24
|
-
|
25
23
|
const constantParams = [OPTIONAL_FUNDS_PARAM];
|
26
|
-
return t.classProperty(t.identifier(methodName), arrowFunctionExpression(param ? [
|
27
|
-
|
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
28
|
t.tsTypeAnnotation(t.tsTypeReference(t.identifier('MsgExecuteContractEncodeObject'))), false));
|
29
29
|
};
|
30
|
-
|
31
30
|
export const createMessageComposerClass = (context, className, implementsClassName, execMsg) => {
|
32
31
|
const propertyNames = getMessageProperties(execMsg).map(method => Object.keys(method.properties)?.[0]).filter(Boolean);
|
33
32
|
const bindings = propertyNames.map(camel).map(bindMethod);
|
@@ -36,9 +35,12 @@ export const createMessageComposerClass = (context, className, implementsClassNa
|
|
36
35
|
});
|
37
36
|
const blockStmt = [];
|
38
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]);
|
39
|
-
return t.exportNamedDeclaration(classDeclaration(className, [
|
40
|
-
|
41
|
-
classProperty('
|
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
|
42
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));
|
43
45
|
};
|
44
46
|
export const createMessageComposerInterface = (context, className, execMsg) => {
|
@@ -48,11 +50,12 @@ export const createMessageComposerInterface = (context, className, execMsg) => {
|
|
48
50
|
return createPropertyFunctionWithObjectParamsForMessageComposer(context, methodName, 'MsgExecuteContractEncodeObject', jsonschema.properties[underscoreName]);
|
49
51
|
});
|
50
52
|
const extendsAst = [];
|
51
|
-
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(className), null, extendsAst, t.tSInterfaceBody([
|
52
|
-
|
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
|
53
57
|
t.tSPropertySignature(t.identifier('sender'), t.tsTypeAnnotation(t.tsStringKeyword())), ...methods])));
|
54
58
|
};
|
55
|
-
|
56
59
|
const createPropertyFunctionWithObjectParamsForMessageComposer = (context, methodName, responseType, jsonschema) => {
|
57
60
|
const obj = createTypedObjectParams(context, jsonschema);
|
58
61
|
const fixedParams = [OPTIONAL_FUNDS_PARAM];
|
@@ -61,6 +64,7 @@ const createPropertyFunctionWithObjectParamsForMessageComposer = (context, metho
|
|
61
64
|
typeAnnotation: t.tsTypeAnnotation(t.tsTypeReference(t.identifier(responseType))),
|
62
65
|
parameters: obj ? [obj, ...fixedParams] : fixedParams
|
63
66
|
};
|
64
|
-
return t.tSPropertySignature(t.identifier(methodName), t.tsTypeAnnotation(
|
67
|
+
return t.tSPropertySignature(t.identifier(methodName), t.tsTypeAnnotation(
|
68
|
+
// @ts-ignore:next-line
|
65
69
|
func));
|
66
70
|
};
|
@@ -9,14 +9,12 @@ export const createProvider = (name, providerInfos) => {
|
|
9
9
|
};
|
10
10
|
export const createIContractsContext = providerInfos => {
|
11
11
|
const properties = [];
|
12
|
-
|
13
12
|
for (const key in providerInfos) {
|
14
13
|
if (Object.prototype.hasOwnProperty.call(providerInfos, key)) {
|
15
14
|
const contractProviderInfo = providerInfos[key];
|
16
15
|
properties.push(createProperty(key, contractProviderInfo));
|
17
16
|
}
|
18
17
|
}
|
19
|
-
|
20
18
|
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier("IContractsContext"), null, null, t.tsInterfaceBody(properties)));
|
21
19
|
};
|
22
20
|
let PROVIDER_MAPPING = {};
|
@@ -26,28 +24,22 @@ PROVIDER_MAPPING[PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE] = "IMessageComposerProvid
|
|
26
24
|
export const createProperty = (name, providerInfos) => {
|
27
25
|
let typeAnnotation = null;
|
28
26
|
const keys = Object.keys(providerInfos);
|
29
|
-
|
30
27
|
if (keys?.length == 1) {
|
31
28
|
const key = keys[0];
|
32
29
|
typeAnnotation = t.tsTypeAnnotation(t.tsTypeReference(t.identifier(PROVIDER_MAPPING[key]), t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier(providerInfos[key].classname))])));
|
33
30
|
} else {
|
34
31
|
const typeRefs = [];
|
35
|
-
|
36
32
|
for (const key of keys) {
|
37
33
|
typeRefs.push(t.tsTypeReference(t.identifier(PROVIDER_MAPPING[key]), t.tsTypeParameterInstantiation([t.tsTypeReference(t.identifier(providerInfos[key].classname))])));
|
38
34
|
}
|
39
|
-
|
40
35
|
typeAnnotation = t.tsTypeAnnotation(t.tsIntersectionType(typeRefs));
|
41
36
|
}
|
42
|
-
|
43
37
|
return t.tsPropertySignature(t.identifier(camel(name)), typeAnnotation);
|
44
38
|
};
|
45
39
|
export const createGettingProviders = providerInfos => {
|
46
40
|
const properties = [];
|
47
|
-
|
48
41
|
for (const key of Object.keys(providerInfos)) {
|
49
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)])])));
|
50
43
|
}
|
51
|
-
|
52
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)))]));
|
53
45
|
};
|