wasm-ast-types 0.26.4 → 1.1.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
@@ -0,0 +1,91 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
+
exports.createMessageBuilderClass = void 0;
|
27
|
+
const t = __importStar(require("@babel/types"));
|
28
|
+
const case_1 = require("case");
|
29
|
+
const utils_1 = require("../utils");
|
30
|
+
const types_1 = require("../utils/types");
|
31
|
+
const client_1 = require("../client/client");
|
32
|
+
const createMessageBuilderClass = (context, className, msg) => {
|
33
|
+
const staticMethods = (0, utils_1.getMessageProperties)(msg).map((schema) => {
|
34
|
+
return createStaticExecMethodMessageBuilder(context, schema, msg.title);
|
35
|
+
});
|
36
|
+
// const blockStmt = bindings;
|
37
|
+
return t.exportNamedDeclaration((0, utils_1.abstractClassDeclaration)(className, staticMethods, [], null));
|
38
|
+
};
|
39
|
+
exports.createMessageBuilderClass = createMessageBuilderClass;
|
40
|
+
/**
|
41
|
+
* CamelCasedProperties<Extract<ExecuteMsg, { exec_on_module: unknown }>['exec_on_module']>
|
42
|
+
*/
|
43
|
+
function createExtractTypeAnnotation(underscoreName, msgTitle) {
|
44
|
+
return t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CamelCasedProperties'), t.tsTypeParameterInstantiation([
|
45
|
+
t.tsIndexedAccessType(t.tsTypeReference(t.identifier('Extract'), t.tsTypeParameterInstantiation([
|
46
|
+
t.tsTypeReference(t.identifier(msgTitle)),
|
47
|
+
t.tsTypeLiteral([
|
48
|
+
t.tsPropertySignature(t.identifier(underscoreName), t.tsTypeAnnotation(t.tsUnknownKeyword()))
|
49
|
+
])
|
50
|
+
])), t.tsLiteralType(t.stringLiteral(underscoreName)))
|
51
|
+
])));
|
52
|
+
}
|
53
|
+
const createStaticExecMethodMessageBuilder = (context, jsonschema, msgTitle) => {
|
54
|
+
const underscoreName = Object.keys(jsonschema.properties)[0];
|
55
|
+
const methodName = (0, case_1.camel)(underscoreName);
|
56
|
+
const param = (0, types_1.createTypedObjectParams)(context, jsonschema.properties[underscoreName]);
|
57
|
+
const args = (0, client_1.getWasmMethodArgs)(context, jsonschema.properties[underscoreName]);
|
58
|
+
// what the underscore named property in the message is assigned to
|
59
|
+
let actionValue;
|
60
|
+
if (param?.type === 'Identifier') {
|
61
|
+
actionValue = t.identifier(param.name);
|
62
|
+
}
|
63
|
+
else {
|
64
|
+
actionValue = t.tsAsExpression(t.objectExpression(args), t.tsTypeReference(t.identifier('const')));
|
65
|
+
}
|
66
|
+
// TODO: this is a hack to get the type annotation to work
|
67
|
+
// all type annotations in the future should be the extracted and camelized type
|
68
|
+
if (param &&
|
69
|
+
param.typeAnnotation.type === 'TSTypeAnnotation' &&
|
70
|
+
param.typeAnnotation.typeAnnotation.type === 'TSTypeLiteral') {
|
71
|
+
param.typeAnnotation = createExtractTypeAnnotation(underscoreName, msgTitle);
|
72
|
+
}
|
73
|
+
return t.classProperty(t.identifier(methodName), (0, utils_1.arrowFunctionExpression)(
|
74
|
+
// params
|
75
|
+
param
|
76
|
+
? [
|
77
|
+
// props
|
78
|
+
param
|
79
|
+
]
|
80
|
+
: [],
|
81
|
+
// body
|
82
|
+
t.blockStatement([
|
83
|
+
t.returnStatement(t.objectExpression([
|
84
|
+
t.objectProperty(t.identifier(underscoreName), actionValue)
|
85
|
+
]))
|
86
|
+
]),
|
87
|
+
// return type
|
88
|
+
t.tsTypeAnnotation(t.tsTypeReference(t.identifier(msgTitle))), false), null, null, false,
|
89
|
+
// static
|
90
|
+
true);
|
91
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './message-composer';
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./message-composer"), exports);
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import * as t from '@babel/types';
|
2
|
-
import { ExecuteMsg } from '
|
2
|
+
import { ExecuteMsg } from '@cosmology/ts-codegen-types';
|
3
3
|
import { RenderContext } from '../context';
|
4
4
|
export declare const createMessageComposerClass: (context: RenderContext, className: string, implementsClassName: string, execMsg: ExecuteMsg) => t.ExportNamedDeclaration;
|
5
5
|
export declare const createMessageComposerInterface: (context: RenderContext, className: string, execMsg: ExecuteMsg) => t.ExportNamedDeclaration;
|
@@ -0,0 +1,133 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
+
exports.createMessageComposerInterface = exports.createMessageComposerClass = void 0;
|
27
|
+
const t = __importStar(require("@babel/types"));
|
28
|
+
const case_1 = require("case");
|
29
|
+
const utils_1 = require("../utils");
|
30
|
+
const types_1 = require("../utils/types");
|
31
|
+
const client_1 = require("../client/client");
|
32
|
+
const createWasmExecMethodMessageComposer = (context, jsonschema) => {
|
33
|
+
context.addUtil('Coin');
|
34
|
+
context.addUtil('MsgExecuteContractEncodeObject');
|
35
|
+
context.addUtil('MsgExecuteContract');
|
36
|
+
context.addUtil('toUtf8');
|
37
|
+
const underscoreName = Object.keys(jsonschema.properties)[0];
|
38
|
+
const methodName = (0, case_1.camel)(underscoreName);
|
39
|
+
const param = (0, types_1.createTypedObjectParams)(context, jsonschema.properties[underscoreName]);
|
40
|
+
const args = (0, client_1.getWasmMethodArgs)(context, jsonschema.properties[underscoreName]);
|
41
|
+
// what the underscore named property in the message is assigned to
|
42
|
+
let actionValue;
|
43
|
+
if (param?.type === 'Identifier') {
|
44
|
+
actionValue = t.identifier(param.name);
|
45
|
+
}
|
46
|
+
else {
|
47
|
+
actionValue = t.objectExpression(args);
|
48
|
+
}
|
49
|
+
const constantParams = [utils_1.OPTIONAL_FUNDS_PARAM];
|
50
|
+
return t.classProperty(t.identifier(methodName), (0, utils_1.arrowFunctionExpression)(param
|
51
|
+
? [
|
52
|
+
// props
|
53
|
+
param,
|
54
|
+
...constantParams
|
55
|
+
]
|
56
|
+
: constantParams, t.blockStatement([
|
57
|
+
t.returnStatement(t.objectExpression([
|
58
|
+
t.objectProperty(t.identifier('typeUrl'), t.stringLiteral('/cosmwasm.wasm.v1.MsgExecuteContract')),
|
59
|
+
t.objectProperty(t.identifier('value'), t.callExpression(t.memberExpression(t.identifier('MsgExecuteContract'), t.identifier('fromPartial')), [
|
60
|
+
t.objectExpression([
|
61
|
+
t.objectProperty(t.identifier('sender'), t.memberExpression(t.thisExpression(), t.identifier('sender'))),
|
62
|
+
t.objectProperty(t.identifier('contract'), t.memberExpression(t.thisExpression(), t.identifier('contractAddress'))),
|
63
|
+
t.objectProperty(t.identifier('msg'), t.callExpression(t.identifier('toUtf8'), [
|
64
|
+
t.callExpression(t.memberExpression(t.identifier('JSON'), t.identifier('stringify')), [
|
65
|
+
t.objectExpression([
|
66
|
+
t.objectProperty(t.identifier(underscoreName), actionValue)
|
67
|
+
])
|
68
|
+
])
|
69
|
+
])),
|
70
|
+
t.objectProperty(t.identifier('funds'), t.identifier('_funds'))
|
71
|
+
])
|
72
|
+
]))
|
73
|
+
]))
|
74
|
+
]),
|
75
|
+
// return type
|
76
|
+
t.tsTypeAnnotation(t.tsTypeReference(t.identifier('MsgExecuteContractEncodeObject'))), false));
|
77
|
+
};
|
78
|
+
const createMessageComposerClass = (context, className, implementsClassName, execMsg) => {
|
79
|
+
const propertyNames = (0, utils_1.getMessageProperties)(execMsg)
|
80
|
+
.map((method) => Object.keys(method.properties)?.[0])
|
81
|
+
.filter(Boolean);
|
82
|
+
const bindings = propertyNames.map(case_1.camel).map(utils_1.bindMethod);
|
83
|
+
const methods = (0, utils_1.getMessageProperties)(execMsg).map((schema) => {
|
84
|
+
return createWasmExecMethodMessageComposer(context, schema);
|
85
|
+
});
|
86
|
+
const blockStmt = [];
|
87
|
+
blockStmt.push(...[
|
88
|
+
t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier('sender')), t.identifier('sender'))),
|
89
|
+
t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier('contractAddress')), t.identifier('contractAddress'))),
|
90
|
+
...bindings
|
91
|
+
]);
|
92
|
+
return t.exportNamedDeclaration((0, utils_1.classDeclaration)(className, [
|
93
|
+
// sender
|
94
|
+
(0, utils_1.classProperty)('sender', t.tsTypeAnnotation(t.tsStringKeyword())),
|
95
|
+
// contractAddress
|
96
|
+
(0, utils_1.classProperty)('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword())),
|
97
|
+
// constructor
|
98
|
+
t.classMethod('constructor', t.identifier('constructor'), [
|
99
|
+
(0, utils_1.typedIdentifier)('sender', t.tsTypeAnnotation(t.tsStringKeyword())),
|
100
|
+
(0, utils_1.typedIdentifier)('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword()))
|
101
|
+
], t.blockStatement(blockStmt)),
|
102
|
+
...methods
|
103
|
+
], [t.tSExpressionWithTypeArguments(t.identifier(implementsClassName))], null));
|
104
|
+
};
|
105
|
+
exports.createMessageComposerClass = createMessageComposerClass;
|
106
|
+
const createMessageComposerInterface = (context, className, execMsg) => {
|
107
|
+
const methods = (0, utils_1.getMessageProperties)(execMsg).map((jsonschema) => {
|
108
|
+
const underscoreName = Object.keys(jsonschema.properties)[0];
|
109
|
+
const methodName = (0, case_1.camel)(underscoreName);
|
110
|
+
return createPropertyFunctionWithObjectParamsForMessageComposer(context, methodName, 'MsgExecuteContractEncodeObject', jsonschema.properties[underscoreName]);
|
111
|
+
});
|
112
|
+
const extendsAst = [];
|
113
|
+
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(className), null, extendsAst, t.tSInterfaceBody([
|
114
|
+
// contract address
|
115
|
+
t.tSPropertySignature(t.identifier('contractAddress'), t.tsTypeAnnotation(t.tsStringKeyword())),
|
116
|
+
// contract address
|
117
|
+
t.tSPropertySignature(t.identifier('sender'), t.tsTypeAnnotation(t.tsStringKeyword())),
|
118
|
+
...methods
|
119
|
+
])));
|
120
|
+
};
|
121
|
+
exports.createMessageComposerInterface = createMessageComposerInterface;
|
122
|
+
const createPropertyFunctionWithObjectParamsForMessageComposer = (context, methodName, responseType, jsonschema) => {
|
123
|
+
const obj = (0, types_1.createTypedObjectParams)(context, jsonschema);
|
124
|
+
const fixedParams = [utils_1.OPTIONAL_FUNDS_PARAM];
|
125
|
+
const func = {
|
126
|
+
type: 'TSFunctionType',
|
127
|
+
typeAnnotation: t.tsTypeAnnotation(t.tsTypeReference(t.identifier(responseType))),
|
128
|
+
parameters: obj ? [obj, ...fixedParams] : fixedParams
|
129
|
+
};
|
130
|
+
return t.tSPropertySignature(t.identifier(methodName), t.tsTypeAnnotation(
|
131
|
+
// @ts-ignore:next-line
|
132
|
+
func));
|
133
|
+
};
|
package/package.json
CHANGED
@@ -1,92 +1,43 @@
|
|
1
1
|
{
|
2
2
|
"name": "wasm-ast-types",
|
3
|
-
"version": "
|
3
|
+
"version": "1.1.0",
|
4
4
|
"description": "CosmWasm TypeScript AST generation",
|
5
5
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
6
|
-
"homepage": "https://github.com/
|
6
|
+
"homepage": "https://github.com/cosmwasm/ts-codegen/tree/master/packages/ast#readme",
|
7
7
|
"license": "SEE LICENSE IN LICENSE",
|
8
|
-
"main": "
|
9
|
-
"module": "
|
10
|
-
"
|
11
|
-
"
|
12
|
-
"
|
13
|
-
"
|
8
|
+
"main": "index.js",
|
9
|
+
"module": "esm/index.js",
|
10
|
+
"types": "index.d.ts",
|
11
|
+
"publishConfig": {
|
12
|
+
"access": "public",
|
13
|
+
"directory": "dist"
|
14
14
|
},
|
15
|
-
"files": [
|
16
|
-
"types",
|
17
|
-
"main",
|
18
|
-
"src",
|
19
|
-
"module"
|
20
|
-
],
|
21
15
|
"scripts": {
|
22
|
-
"
|
23
|
-
"
|
24
|
-
"build:ts": "tsc --project ./tsconfig.json",
|
25
|
-
"build": "npm run build:module && npm run build:main",
|
26
|
-
"buidl": "npm run build && npm run build:ts",
|
16
|
+
"copy": "copyfiles -f LICENSE-Apache LICENSE-MIT README.md package.json dist",
|
17
|
+
"clean": "del dist/**",
|
27
18
|
"prepare": "npm run build",
|
28
|
-
"
|
29
|
-
"
|
19
|
+
"codegen": "ts-node ./scripts/build.ts",
|
20
|
+
"build": "npm run clean; tsc; tsc -p tsconfig.esm.json; npm run copy",
|
30
21
|
"test": "jest",
|
31
|
-
"test:ast": "cross-env NODE_ENV=development babel-node scripts/test-ast.js",
|
32
22
|
"test:watch": "jest --watch",
|
33
|
-
"test:
|
34
|
-
|
35
|
-
|
36
|
-
"testPathIgnorePatterns": [
|
37
|
-
"main/",
|
38
|
-
"module/"
|
39
|
-
]
|
40
|
-
},
|
41
|
-
"publishConfig": {
|
42
|
-
"access": "public"
|
23
|
+
"test:ast": "ts-node scripts/test-ast.ts",
|
24
|
+
"dev": "ts-node src/ts-codegen",
|
25
|
+
"file": "ts-node src/file"
|
43
26
|
},
|
44
27
|
"repository": {
|
45
28
|
"type": "git",
|
46
|
-
"url": "https://github.com/
|
29
|
+
"url": "https://github.com/cosmwasm/ts-codegen"
|
47
30
|
},
|
48
31
|
"keywords": [],
|
49
32
|
"bugs": {
|
50
|
-
"url": "https://github.com/
|
51
|
-
},
|
52
|
-
"devDependencies": {
|
53
|
-
"@babel/cli": "7.18.10",
|
54
|
-
"@babel/core": "7.18.10",
|
55
|
-
"@babel/eslint-parser": "^7.18.9",
|
56
|
-
"@babel/generator": "7.18.12",
|
57
|
-
"@babel/node": "^7.18.10",
|
58
|
-
"@babel/parser": "^7.18.11",
|
59
|
-
"@babel/plugin-proposal-class-properties": "7.18.6",
|
60
|
-
"@babel/plugin-proposal-export-default-from": "7.18.10",
|
61
|
-
"@babel/plugin-proposal-object-rest-spread": "7.18.9",
|
62
|
-
"@babel/plugin-transform-runtime": "7.18.10",
|
63
|
-
"@babel/preset-env": "7.18.10",
|
64
|
-
"@babel/preset-typescript": "^7.18.6",
|
65
|
-
"@babel/traverse": "7.18.11",
|
66
|
-
"@types/jest": "^28.1.6",
|
67
|
-
"babel-core": "7.0.0-bridge.0",
|
68
|
-
"babel-jest": "^28.1.3",
|
69
|
-
"babel-watch": "^7.0.0",
|
70
|
-
"cross-env": "^7.0.2",
|
71
|
-
"eslint": "8.21.0",
|
72
|
-
"eslint-config-prettier": "^8.5.0",
|
73
|
-
"eslint-plugin-prettier": "^4.2.1",
|
74
|
-
"glob": "8.0.3",
|
75
|
-
"jest": "28.1.3",
|
76
|
-
"jest-in-case": "^1.0.2",
|
77
|
-
"mkdirp": "1.0.4",
|
78
|
-
"prettier": "^2.7.1",
|
79
|
-
"regenerator-runtime": "^0.13.7",
|
80
|
-
"ts-jest": "^28.0.7",
|
81
|
-
"typescript": "^4.7.4"
|
33
|
+
"url": "https://github.com/cosmwasm/ts-codegen/issues"
|
82
34
|
},
|
83
35
|
"dependencies": {
|
84
|
-
"@babel/runtime": "^7.18.9",
|
85
36
|
"@babel/types": "7.18.10",
|
86
|
-
"@
|
37
|
+
"@cosmology/ts-codegen-types": "^1.1.0",
|
87
38
|
"ast-stringify": "0.1.0",
|
88
39
|
"case": "1.6.3",
|
89
40
|
"deepmerge": "4.2.2"
|
90
41
|
},
|
91
|
-
"gitHead": "
|
42
|
+
"gitHead": "f584b91783521be1dd42f0392dfbd73020321862"
|
92
43
|
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './provider';
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./provider"), exports);
|
@@ -0,0 +1,127 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
+
exports.createGettingProviders = exports.createProperty = exports.createIContractsContext = exports.createProvider = void 0;
|
27
|
+
const t = __importStar(require("@babel/types"));
|
28
|
+
const case_1 = require("case");
|
29
|
+
const constants_1 = require("../utils/constants");
|
30
|
+
const utils_1 = require("../utils");
|
31
|
+
const createProvider = (name, providerInfos) => {
|
32
|
+
const classDeclaration = t.classDeclaration(t.identifier(name), t.identifier("ContractBase"), t.classBody([
|
33
|
+
t.classMethod("constructor", t.identifier("constructor"), [
|
34
|
+
(0, utils_1.tsObjectPattern)([
|
35
|
+
t.objectProperty(t.identifier("address"), t.identifier("address"), false, true),
|
36
|
+
t.objectProperty(t.identifier("cosmWasmClient"), t.identifier("cosmWasmClient"), false, true),
|
37
|
+
t.objectProperty(t.identifier("signingCosmWasmClient"), t.identifier("signingCosmWasmClient"), false, true),
|
38
|
+
], t.tsTypeAnnotation(t.tsTypeReference(t.identifier("IContractConstructor")))),
|
39
|
+
], t.blockStatement([
|
40
|
+
t.expressionStatement(t.callExpression(t.super(), [
|
41
|
+
t.identifier("address"),
|
42
|
+
t.identifier("cosmWasmClient"),
|
43
|
+
t.identifier("signingCosmWasmClient"),
|
44
|
+
t.identifier(providerInfos[constants_1.PROVIDER_TYPES.SIGNING_CLIENT_TYPE]
|
45
|
+
? providerInfos[constants_1.PROVIDER_TYPES.SIGNING_CLIENT_TYPE].classname
|
46
|
+
: "undefined"),
|
47
|
+
t.identifier(providerInfos[constants_1.PROVIDER_TYPES.QUERY_CLIENT_TYPE]
|
48
|
+
? providerInfos[constants_1.PROVIDER_TYPES.QUERY_CLIENT_TYPE].classname
|
49
|
+
: "undefined"),
|
50
|
+
t.identifier(providerInfos[constants_1.PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE]
|
51
|
+
? providerInfos[constants_1.PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE]
|
52
|
+
.classname
|
53
|
+
: "undefined"),
|
54
|
+
])),
|
55
|
+
])),
|
56
|
+
]));
|
57
|
+
classDeclaration.superTypeParameters = t.tsTypeParameterInstantiation([
|
58
|
+
t.tsTypeReference(t.identifier(providerInfos[constants_1.PROVIDER_TYPES.SIGNING_CLIENT_TYPE]
|
59
|
+
? providerInfos[constants_1.PROVIDER_TYPES.SIGNING_CLIENT_TYPE].classname
|
60
|
+
: "IEmptyClient")),
|
61
|
+
t.tsTypeReference(t.identifier(providerInfos[constants_1.PROVIDER_TYPES.QUERY_CLIENT_TYPE]
|
62
|
+
? providerInfos[constants_1.PROVIDER_TYPES.QUERY_CLIENT_TYPE].classname
|
63
|
+
: "IEmptyClient")),
|
64
|
+
t.tsTypeReference(t.identifier(providerInfos[constants_1.PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE]
|
65
|
+
? providerInfos[constants_1.PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE].classname
|
66
|
+
: "IEmptyClient")),
|
67
|
+
]);
|
68
|
+
return t.exportNamedDeclaration(classDeclaration);
|
69
|
+
};
|
70
|
+
exports.createProvider = createProvider;
|
71
|
+
const createIContractsContext = (providerInfos) => {
|
72
|
+
const properties = [];
|
73
|
+
for (const key in providerInfos) {
|
74
|
+
if (Object.prototype.hasOwnProperty.call(providerInfos, key)) {
|
75
|
+
const contractProviderInfo = providerInfos[key];
|
76
|
+
properties.push((0, exports.createProperty)(key, contractProviderInfo));
|
77
|
+
}
|
78
|
+
}
|
79
|
+
return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier("IContractsContext"), null, null, t.tsInterfaceBody(properties)));
|
80
|
+
};
|
81
|
+
exports.createIContractsContext = createIContractsContext;
|
82
|
+
let PROVIDER_MAPPING = {};
|
83
|
+
PROVIDER_MAPPING[constants_1.PROVIDER_TYPES.SIGNING_CLIENT_TYPE] = "ISigningClientProvider";
|
84
|
+
PROVIDER_MAPPING[constants_1.PROVIDER_TYPES.QUERY_CLIENT_TYPE] = "IQueryClientProvider";
|
85
|
+
PROVIDER_MAPPING[constants_1.PROVIDER_TYPES.MESSAGE_COMPOSER_TYPE] =
|
86
|
+
"IMessageComposerProvider";
|
87
|
+
const createProperty = (name, providerInfos) => {
|
88
|
+
let typeAnnotation = null;
|
89
|
+
const keys = Object.keys(providerInfos);
|
90
|
+
if (keys?.length == 1) {
|
91
|
+
const key = keys[0];
|
92
|
+
typeAnnotation = t.tsTypeAnnotation(t.tsTypeReference(t.identifier(PROVIDER_MAPPING[key]), t.tsTypeParameterInstantiation([
|
93
|
+
t.tsTypeReference(t.identifier(providerInfos[key].classname)),
|
94
|
+
])));
|
95
|
+
}
|
96
|
+
else {
|
97
|
+
const typeRefs = [];
|
98
|
+
for (const key of keys) {
|
99
|
+
typeRefs.push(t.tsTypeReference(t.identifier(PROVIDER_MAPPING[key]), t.tsTypeParameterInstantiation([
|
100
|
+
t.tsTypeReference(t.identifier(providerInfos[key].classname)),
|
101
|
+
])));
|
102
|
+
}
|
103
|
+
typeAnnotation = t.tsTypeAnnotation(t.tsIntersectionType(typeRefs));
|
104
|
+
}
|
105
|
+
return t.tsPropertySignature(t.identifier((0, case_1.camel)(name)), typeAnnotation);
|
106
|
+
};
|
107
|
+
exports.createProperty = createProperty;
|
108
|
+
const createGettingProviders = (providerInfos) => {
|
109
|
+
const properties = [];
|
110
|
+
for (const key of Object.keys(providerInfos)) {
|
111
|
+
properties.push(t.objectProperty(t.identifier((0, case_1.camel)(key)), t.newExpression(t.identifier((0, case_1.pascal)(key)), [
|
112
|
+
t.objectExpression([
|
113
|
+
t.objectProperty(t.identifier("address"), t.identifier("address"), false, true),
|
114
|
+
t.objectProperty(t.identifier("cosmWasmClient"), t.identifier("cosmWasmClient"), false, true),
|
115
|
+
t.objectProperty(t.identifier("signingCosmWasmClient"), t.identifier("signingCosmWasmClient"), false, true),
|
116
|
+
]),
|
117
|
+
])));
|
118
|
+
}
|
119
|
+
return t.exportNamedDeclaration(t.variableDeclaration("const", [
|
120
|
+
t.variableDeclarator(t.identifier("getProviders"), t.arrowFunctionExpression([
|
121
|
+
(0, utils_1.identifier)("address?", t.tsTypeAnnotation(t.tsTypeReference(t.identifier("string")))),
|
122
|
+
(0, utils_1.identifier)("cosmWasmClient?", t.tsTypeAnnotation(t.tsTypeReference(t.identifier("CosmWasmClient")))),
|
123
|
+
(0, utils_1.identifier)("signingCosmWasmClient?", t.tsTypeAnnotation(t.tsTypeReference(t.identifier("SigningCosmWasmClient")))),
|
124
|
+
], t.objectExpression(properties))),
|
125
|
+
]));
|
126
|
+
};
|
127
|
+
exports.createGettingProviders = createGettingProviders;
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './react-query';
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./react-query"), exports);
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import * as t from '@babel/types';
|
2
|
-
import { ExecuteMsg, QueryMsg } from '
|
2
|
+
import { JSONSchema, ExecuteMsg, QueryMsg } from '@cosmology/ts-codegen-types';
|
3
3
|
import { RenderContext } from '../context';
|
4
|
-
import { JSONSchema } from '../types';
|
5
4
|
interface ReactQueryHookQuery {
|
6
5
|
context: RenderContext;
|
7
6
|
hookName: string;
|
@@ -51,7 +50,7 @@ interface ReactQueryMutationHooks {
|
|
51
50
|
contractName: string;
|
52
51
|
ExecuteClient: string;
|
53
52
|
}
|
54
|
-
export declare const createReactQueryMutationHooks: ({ context, execMsg, contractName, ExecuteClient }: ReactQueryMutationHooks) => any;
|
53
|
+
export declare const createReactQueryMutationHooks: ({ context, execMsg, contractName, ExecuteClient }: ReactQueryMutationHooks) => any[];
|
55
54
|
interface ReactQueryMutationHook {
|
56
55
|
context: RenderContext;
|
57
56
|
mutationHookName: string;
|