wasm-ast-types 0.0.3

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/module/wasm.js ADDED
@@ -0,0 +1,233 @@
1
+ import * as t from '@babel/types';
2
+ import { camel, pascal } from 'case';
3
+ import { bindMethod, typedIdentifier, promiseTypeAnnotation, classDeclaration, classProperty, arrowFunctionExpression } from './utils';
4
+
5
+ const getTypeFromRef = $ref => {
6
+ switch ($ref) {
7
+ case '#/definitions/Binary':
8
+ return t.tsTypeReference(t.identifier('BinaryType'));
9
+
10
+ case '#/definitions/Expiration':
11
+ return t.tsTypeReference(t.identifier('Expiration'));
12
+
13
+ default:
14
+ if ($ref.startsWith('#/definitions/')) {
15
+ return t.tsTypeReference(t.identifier($ref.replace('#/definitions/', '')));
16
+ }
17
+
18
+ throw new Error('what is $ref: ' + $ref);
19
+ }
20
+ };
21
+
22
+ const getArrayTypeFromRef = $ref => {
23
+ return t.tsArrayType(getTypeFromRef($ref));
24
+ };
25
+
26
+ const getArrayTypeFromType = type => {
27
+ return t.tsArrayType(getType(type));
28
+ };
29
+
30
+ const getType = type => {
31
+ switch (type) {
32
+ case 'string':
33
+ return t.tsStringKeyword();
34
+
35
+ case 'boolean':
36
+ return t.tSBooleanKeyword();
37
+
38
+ case 'integer':
39
+ return t.tsNumberKeyword();
40
+
41
+ default:
42
+ throw new Error('what is type: ' + type);
43
+ }
44
+ };
45
+
46
+ const getPropertyType = (schema, prop) => {
47
+ const props = schema.properties ?? {};
48
+ let info = props[prop];
49
+ let type = null;
50
+ let optional = schema.required?.includes(prop);
51
+
52
+ if (info.allOf && info.allOf.length === 1) {
53
+ info = info.allOf[0];
54
+ }
55
+
56
+ if (typeof info.$ref === 'string') {
57
+ type = getTypeFromRef(info.$ref);
58
+ }
59
+
60
+ if (Array.isArray(info.anyOf)) {
61
+ // assuming 2nd is null, but let's check to ensure
62
+ if (info.anyOf.length !== 2) {
63
+ throw new Error('case not handled by transpiler. contact maintainers.');
64
+ }
65
+
66
+ const [nullableType, nullType] = info.anyOf;
67
+
68
+ if (nullType?.type !== 'null') {
69
+ throw new Error('case not handled by transpiler. contact maintainers.');
70
+ }
71
+
72
+ type = getTypeFromRef(nullableType?.$ref);
73
+ optional = true;
74
+ }
75
+
76
+ if (typeof info.type === 'string') {
77
+ if (info.type === 'array') {
78
+ if (info.items.$ref) {
79
+ type = getArrayTypeFromRef(info.items.$ref);
80
+ } else {
81
+ type = getArrayTypeFromType(info.items.type);
82
+ }
83
+ } else {
84
+ type = getType(info.type);
85
+ }
86
+ }
87
+
88
+ if (Array.isArray(info.type)) {
89
+ // assuming 2nd is null, but let's check to ensure
90
+ if (info.type.length !== 2) {
91
+ throw new Error('case not handled by transpiler. contact maintainers.');
92
+ }
93
+
94
+ const [nullableType, nullType] = info.type;
95
+
96
+ if (nullType !== 'null') {
97
+ throw new Error('case not handled by transpiler. contact maintainers.');
98
+ }
99
+
100
+ type = getType(nullableType);
101
+ optional = true;
102
+ }
103
+
104
+ if (!type) {
105
+ throw new Error('cannot find type for ' + JSON.stringify(info));
106
+ }
107
+
108
+ return {
109
+ type,
110
+ optional
111
+ };
112
+ };
113
+
114
+ const getProperty = (schema, prop) => {
115
+ const {
116
+ type,
117
+ optional
118
+ } = getPropertyType(schema, prop);
119
+ return typedIdentifier(camel(prop), t.tsTypeAnnotation(type), optional);
120
+ };
121
+
122
+ export const createWasmQueryMethod = jsonschema => {
123
+ const underscoreName = Object.keys(jsonschema.properties)[0];
124
+ const methodName = camel(underscoreName);
125
+ const responseType = pascal(`${methodName}Response`);
126
+ const properties = jsonschema.properties[underscoreName].properties ?? {}; // console.log({ jsonschema, methodName, underscoreName, properties });
127
+
128
+ const params = Object.keys(properties).map(prop => {
129
+ return getProperty(jsonschema.properties[underscoreName], prop);
130
+ });
131
+ const args = Object.keys(properties).map(prop => {
132
+ return t.objectProperty(t.identifier(prop), t.identifier(camel(prop)), false, true);
133
+ });
134
+ const actionArg = t.objectProperty(t.identifier(underscoreName), t.objectExpression(args));
135
+ return t.classProperty(t.identifier(methodName), arrowFunctionExpression(params, t.blockStatement([t.returnStatement(t.callExpression(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier('client')), t.identifier('queryContractSmart')), [t.memberExpression(t.thisExpression(), t.identifier('contractAddress')), t.objectExpression([actionArg])]))]), t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Promise'), t.tsTypeParameterInstantiation([t.tSTypeReference(t.identifier(responseType))]))), true));
136
+ };
137
+ export const createQueryClass = (className, implementsClassName, queryMsg) => {
138
+ const propertyNames = queryMsg.oneOf.map(method => Object.keys(method.properties)?.[0]).filter(Boolean);
139
+ const bindings = propertyNames.map(camel).map(bindMethod);
140
+ const methods = queryMsg.oneOf.map(schema => {
141
+ return createWasmQueryMethod(schema);
142
+ });
143
+ return t.exportNamedDeclaration(classDeclaration(className, [// client
144
+ classProperty('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CosmWasmClient')))), // contractAddress
145
+ classProperty('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword())), // constructor
146
+ t.classMethod('constructor', t.identifier('constructor'), [typedIdentifier('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CosmWasmClient')))), typedIdentifier('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword()))], t.blockStatement([// client/contract set
147
+ t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier('client')), t.identifier('client'))), t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier('contractAddress')), t.identifier('contractAddress'))), ...bindings])), ...methods], [t.tSExpressionWithTypeArguments(t.identifier(implementsClassName))]));
148
+ };
149
+ export const createWasmExecMethod = jsonschema => {
150
+ const underscoreName = Object.keys(jsonschema.properties)[0];
151
+ const methodName = camel(underscoreName);
152
+ const properties = jsonschema.properties[underscoreName].properties ?? {};
153
+ const params = Object.keys(properties).map(prop => {
154
+ return getProperty(jsonschema.properties[underscoreName], prop);
155
+ });
156
+ const args = Object.keys(properties).map(prop => {
157
+ return t.objectProperty(t.identifier(prop), t.identifier(camel(prop)), false, prop === camel(prop));
158
+ });
159
+ return t.classProperty(t.identifier(methodName), arrowFunctionExpression([// props
160
+ ...params], t.blockStatement([t.returnStatement(t.awaitExpression(t.callExpression(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier('client')), t.identifier('execute')), [t.memberExpression(t.thisExpression(), t.identifier('sender')), t.memberExpression(t.thisExpression(), t.identifier('contractAddress')), t.objectExpression([t.objectProperty(t.identifier(underscoreName), t.objectExpression([...args]))]), t.stringLiteral('auto')])))]), // return type
161
+ t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Promise'), t.tsTypeParameterInstantiation([t.tSTypeReference(t.identifier('ExecuteResult'))]))), true));
162
+ };
163
+ export const createExecuteClass = (className, implementsClassName, extendsClassName, execMsg) => {
164
+ const propertyNames = execMsg.oneOf.map(method => Object.keys(method.properties)?.[0]).filter(Boolean);
165
+ const bindings = propertyNames.map(camel).map(bindMethod);
166
+ const methods = execMsg.oneOf.map(schema => {
167
+ return createWasmExecMethod(schema);
168
+ });
169
+ return t.exportNamedDeclaration(classDeclaration(className, [// client
170
+ classProperty('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('SigningCosmWasmClient')))), // sender
171
+ classProperty('sender', t.tsTypeAnnotation(t.tsStringKeyword())), // contractAddress
172
+ classProperty('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword())), // constructor
173
+ t.classMethod('constructor', t.identifier('constructor'), [typedIdentifier('client', t.tsTypeAnnotation(t.tsTypeReference(t.identifier('SigningCosmWasmClient')))), typedIdentifier('sender', t.tsTypeAnnotation(t.tsStringKeyword())), typedIdentifier('contractAddress', t.tsTypeAnnotation(t.tsStringKeyword()))], t.blockStatement([// super()
174
+ t.expressionStatement(t.callExpression(t.super(), [t.identifier('client'), t.identifier('contractAddress')])), // client/contract set
175
+ t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier('client')), t.identifier('client'))), t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier('contractAddress')), t.identifier('contractAddress'))), ...bindings])), ...methods], [t.tSExpressionWithTypeArguments(t.identifier(implementsClassName))], t.identifier(extendsClassName)));
176
+ };
177
+ export const createExecuteInterface = (className, extendsClassName, execMsg) => {
178
+ const methods = execMsg.oneOf.map(jsonschema => {
179
+ const underscoreName = Object.keys(jsonschema.properties)[0];
180
+ const methodName = camel(underscoreName);
181
+ const properties = jsonschema.properties[underscoreName].properties ?? {};
182
+ const params = Object.keys(properties).map(prop => {
183
+ return getProperty(jsonschema.properties[underscoreName], prop);
184
+ });
185
+ return t.tSPropertySignature(t.identifier(methodName), t.tsTypeAnnotation(t.tsFunctionType(null, [...params], promiseTypeAnnotation('ExecuteResult'))));
186
+ });
187
+ return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(className), null, [t.tSExpressionWithTypeArguments(t.identifier(extendsClassName))], t.tSInterfaceBody([// contract address
188
+ t.tSPropertySignature(t.identifier('contractAddress'), t.tsTypeAnnotation(t.tsStringKeyword())), // contract address
189
+ t.tSPropertySignature(t.identifier('sender'), t.tsTypeAnnotation(t.tsStringKeyword())), ...methods])));
190
+ };
191
+ export const createQueryInterface = (className, queryMsg) => {
192
+ const methods = queryMsg.oneOf.map(jsonschema => {
193
+ const underscoreName = Object.keys(jsonschema.properties)[0];
194
+ const methodName = camel(underscoreName);
195
+ const responseType = pascal(`${methodName}Response`);
196
+ const properties = jsonschema.properties[underscoreName].properties ?? {};
197
+ const params = Object.keys(properties).map(prop => {
198
+ return getProperty(jsonschema.properties[underscoreName], prop);
199
+ });
200
+ return t.tSPropertySignature(t.identifier(methodName), t.tsTypeAnnotation(t.tsFunctionType(null, [...params], promiseTypeAnnotation(responseType))));
201
+ });
202
+ return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(className), null, [], t.tSInterfaceBody([t.tSPropertySignature(t.identifier('contractAddress'), t.tsTypeAnnotation(t.tsStringKeyword())), ...methods])));
203
+ };
204
+ export const propertySignature = (name, typeAnnotation, optional = false) => {
205
+ const prop = t.tsPropertySignature(t.identifier(name), typeAnnotation); // prop.leadingComments = [{
206
+ // type: 'Comment',
207
+ // value: ' Data on the token itself'
208
+ // }];
209
+ // prop.leadingComments = [{
210
+ // type: 'CommentBlock',
211
+ // value: '* Data on the token itself'
212
+ // }];
213
+
214
+ return prop;
215
+ };
216
+ export const createTypeOrInterface = (Type, jsonschema) => {
217
+ if (jsonschema.type !== 'object') {
218
+ return t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier(Type), null, getType(jsonschema.type)));
219
+ }
220
+
221
+ const props = Object.keys(jsonschema.properties ?? {}).map(prop => {
222
+ const {
223
+ type,
224
+ optional
225
+ } = getPropertyType(jsonschema, prop);
226
+ return propertySignature(camel(prop), t.tsTypeAnnotation(type), optional);
227
+ });
228
+ return t.exportNamedDeclaration(t.tsInterfaceDeclaration(t.identifier(Type), null, [], t.tsInterfaceBody([...props])));
229
+ };
230
+ export const createTypeInterface = jsonschema => {
231
+ const Type = jsonschema.title;
232
+ return createTypeOrInterface(Type, jsonschema);
233
+ };
@@ -0,0 +1,69 @@
1
+ import generate from '@babel/generator';
2
+ import query_msg from './__fixtures__/schema/query_msg.json';
3
+ import execute_msg from './__fixtures__/schema/execute_msg_for__empty.json';
4
+ import approval_response from './__fixtures__/schema/approval_response.json';
5
+ import all_nft_info_response from './__fixtures__/schema/all_nft_info_response.json';
6
+ import approvals_response from './__fixtures__/schema/approvals_response.json';
7
+ import collection_info_response from './__fixtures__/schema/collection_info_response.json';
8
+ import contract_info_response from './__fixtures__/schema/contract_info_response.json';
9
+ import instantiate_msg from './__fixtures__/schema/instantiate_msg.json';
10
+ import nft_info_response from './__fixtures__/schema/nft_info_response.json';
11
+ import num_tokens_response from './__fixtures__/schema/num_tokens_response.json';
12
+ import operators_response from './__fixtures__/schema/operators_response.json';
13
+ import owner_of_response from './__fixtures__/schema/owner_of_response.json';
14
+ import tokens_response from './__fixtures__/schema/tokens_response.json';
15
+ import { createQueryClass, createQueryInterface, createExecuteClass, createExecuteInterface, createTypeInterface } from './wasm';
16
+
17
+ const expectCode = ast => {
18
+ expect(generate(ast).code).toMatchSnapshot();
19
+ };
20
+
21
+ const printCode = ast => {
22
+ console.log(generate(ast).code);
23
+ };
24
+
25
+ it('approval_response', () => {
26
+ expectCode(createTypeInterface(approval_response));
27
+ });
28
+ it('all_nft_info_response', () => {
29
+ expectCode(createTypeInterface(all_nft_info_response));
30
+ });
31
+ it('approvals_response', () => {
32
+ expectCode(createTypeInterface(approvals_response));
33
+ });
34
+ it('collection_info_response', () => {
35
+ expectCode(createTypeInterface(collection_info_response));
36
+ });
37
+ it('contract_info_response', () => {
38
+ expectCode(createTypeInterface(contract_info_response));
39
+ });
40
+ it('instantiate_msg', () => {
41
+ expectCode(createTypeInterface(instantiate_msg));
42
+ });
43
+ it('nft_info_response', () => {
44
+ expectCode(createTypeInterface(nft_info_response));
45
+ });
46
+ it('num_tokens_response', () => {
47
+ expectCode(createTypeInterface(num_tokens_response));
48
+ });
49
+ it('operators_response', () => {
50
+ expectCode(createTypeInterface(operators_response));
51
+ });
52
+ it('owner_of_response', () => {
53
+ expectCode(createTypeInterface(owner_of_response));
54
+ });
55
+ it('tokens_response', () => {
56
+ expectCode(createTypeInterface(tokens_response));
57
+ });
58
+ it('query classes', () => {
59
+ expectCode(createQueryClass('SG721QueryClient', 'SG721ReadOnlyInstance', query_msg));
60
+ });
61
+ it('execute classes', () => {
62
+ expectCode(createExecuteClass('SG721Client', 'SG721Instance', 'SG721QueryClient', execute_msg));
63
+ });
64
+ it('execute interfaces', () => {
65
+ expectCode(createExecuteInterface('SG721Instance', 'SG721ReadOnlyInstance', execute_msg));
66
+ });
67
+ it('query interfaces', () => {
68
+ expectCode(createQueryInterface('SG721ReadOnlyInstance', query_msg));
69
+ });
package/package.json ADDED
@@ -0,0 +1,89 @@
1
+ {
2
+ "name": "wasm-ast-types",
3
+ "version": "0.0.3",
4
+ "description": "CosmWasm TypeScript AST generation",
5
+ "author": "Dan Lynch <pyramation@gmail.com>",
6
+ "homepage": "https://github.com/pyramation/cosmscript/tree/master/packages/wasm-ast-types#readme",
7
+ "license": "SEE LICENSE IN LICENSE",
8
+ "main": "main/index.js",
9
+ "module": "module/index.js",
10
+ "typings": "types/index.d.ts",
11
+ "directories": {
12
+ "lib": "src",
13
+ "test": "__tests__"
14
+ },
15
+ "files": [
16
+ "types",
17
+ "main",
18
+ "module"
19
+ ],
20
+ "scripts": {
21
+ "build:main": "cross-env BABEL_ENV=production babel src --out-dir main --delete-dir-on-start --extensions \".tsx,.ts,.js\"",
22
+ "build:module": "cross-env MODULE=true babel src --out-dir module --delete-dir-on-start --extensions \".tsx,.ts,.js\"",
23
+ "build": "npm run build:module && npm run build:main",
24
+ "build:ts": "tsc --project ./tsconfig.json",
25
+ "prepare": "npm run build",
26
+ "dev": "cross-env NODE_ENV=development babel-node src/index",
27
+ "watch": "cross-env NODE_ENV=development babel-watch src/index",
28
+ "lint": "eslint src --fix",
29
+ "test": "jest",
30
+ "test:ast": "cross-env NODE_ENV=development babel-node scripts/test-ast.js",
31
+ "test:watch": "jest --watch",
32
+ "test:debug": "node --inspect node_modules/.bin/jest --runInBand"
33
+ },
34
+ "jest": {
35
+ "testPathIgnorePatterns": [
36
+ "main/",
37
+ "module/"
38
+ ]
39
+ },
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "https://github.com/pyramation/cosmscript/tree/master/packages/wasm-ast-types"
46
+ },
47
+ "keywords": [],
48
+ "bugs": {
49
+ "url": "https://github.com/pyramation/cosmscript/tree/master/packages/wasm-ast-types/issues"
50
+ },
51
+ "devDependencies": {
52
+ "@babel/cli": "7.17.6",
53
+ "@babel/core": "7.17.8",
54
+ "@babel/eslint-parser": "^7.5.4",
55
+ "@babel/generator": "7.17.7",
56
+ "@babel/node": "^7.10.5",
57
+ "@babel/parser": "^7.17.8",
58
+ "@babel/plugin-proposal-class-properties": "7.16.7",
59
+ "@babel/plugin-proposal-export-default-from": "7.16.7",
60
+ "@babel/plugin-proposal-object-rest-spread": "7.17.3",
61
+ "@babel/plugin-transform-runtime": "7.17.0",
62
+ "@babel/preset-env": "7.16.11",
63
+ "@babel/preset-typescript": "^7.16.7",
64
+ "@babel/traverse": "7.17.3",
65
+ "@types/jest": "^27.4.1",
66
+ "babel-core": "7.0.0-bridge.0",
67
+ "babel-jest": "27.5.1",
68
+ "babel-watch": "^7.0.0",
69
+ "cross-env": "^7.0.2",
70
+ "eslint": "8.12.0",
71
+ "eslint-config-prettier": "^8.5.0",
72
+ "eslint-plugin-prettier": "^4.0.0",
73
+ "glob": "7.2.0",
74
+ "jest": "^27.5.1",
75
+ "jest-in-case": "^1.0.2",
76
+ "mkdirp": "1.0.4",
77
+ "prettier": "^2.6.2",
78
+ "regenerator-runtime": "^0.13.7",
79
+ "ts-jest": "^27.1.4",
80
+ "typescript": "^4.6.2"
81
+ },
82
+ "dependencies": {
83
+ "@babel/runtime": "^7.11.2",
84
+ "@babel/types": "7.17.0",
85
+ "ast-stringify": "0.1.0",
86
+ "case": "1.6.3"
87
+ },
88
+ "gitHead": "bb157d67d9adbf04328fdcfcfb37aab0bc336c4e"
89
+ }
@@ -0,0 +1,6 @@
1
+ import * as t from '@babel/types';
2
+ import { Enum, Field, Interface, MessageSchema } from '../types';
3
+ export declare const makeAminoConverterItem: (schema: MessageSchema, enums: Enum[], interfaces: Interface[]) => t.ObjectProperty;
4
+ export declare const aminoConverter: (schemas: MessageSchema[], enums: Enum[], interfaces: Interface[]) => t.ExportNamedDeclaration;
5
+ export declare const renderAminoField: (field: Field, enums: Enum[], interfaces?: any[], imports?: any[]) => any;
6
+ export declare const makeAminoTypeInterface: (schema: MessageSchema, enums: Enum[], interfaces?: any[], imports?: any[]) => t.ExportNamedDeclaration;
@@ -0,0 +1,13 @@
1
+ import * as t from '@babel/types';
2
+ import { Enum, Field, Interface, MessageSchema } from '../types';
3
+ export declare const fromAminoStringToLong: (prop: string, scope: string[]) => t.ObjectProperty;
4
+ export declare const fromAminoFromArrayCall: (prop: string, scope: string[]) => t.ObjectProperty;
5
+ export declare const fromAminoSnakeToCamel: (prop: string, scope: string[]) => t.ObjectProperty;
6
+ export declare const fromAminoHeight: (prop: string, scope: string[]) => t.ObjectProperty;
7
+ export declare const fromAminoDuration: (prop: string, scope: string[]) => t.ObjectProperty;
8
+ export declare const fromAminoEnum: (val: Enum, field: Field, scope: string[]) => t.ObjectProperty;
9
+ export declare const fromAminoEnumArray: (val: Enum, field: Field, scope: string[]) => t.ObjectProperty;
10
+ export declare const fromAminoInterface: (field: Field, ival: Interface, enums: Enum[], interfaces: Interface[], scope: string[], nested: number) => any;
11
+ export declare const fromAminoInterfaceArray: (field: Field, ival: Interface, enums: Enum[], interfaces: Interface[], scope: string[], nested: number) => t.ObjectProperty;
12
+ export declare const fromAminoParseField: (field: Field, enums: Enum[], interfaces: Interface[], scope?: any[], nested?: number) => any;
13
+ export declare const fromAmino: (schema: MessageSchema, enums: Enum[], interfaces: Interface[]) => t.ArrowFunctionExpression;
@@ -0,0 +1,3 @@
1
+ export * from './from-amino';
2
+ export * from './to-amino';
3
+ export * from './amino-interfaces';
@@ -0,0 +1,11 @@
1
+ import * as t from '@babel/types';
2
+ import { Enum, Field, Interface, MessageSchema } from '../types';
3
+ export declare const toAminoDuration: (prop: string, scope: string[]) => t.ObjectProperty;
4
+ export declare const toAminoSnakeToCamel: (prop: string, scope: string[]) => t.ObjectProperty;
5
+ export declare const toAminoInterface: (field: Field, ival: Interface, enums: Enum[], interfaces: Interface[], scope: string[], nested: number) => any;
6
+ export declare const toAminoInterfaceArray: (field: Field, ival: Interface, enums: Enum[], interfaces: Interface[], scope: string[], nested: number) => t.ObjectProperty;
7
+ export declare const toAminoLongToString: (prop: string, scope: string[]) => t.ObjectProperty;
8
+ export declare const toAminoCoin: (prop: string, scope: string[]) => t.ObjectProperty;
9
+ export declare const toAminoHeight: (prop: string, scope: string[]) => t.ObjectProperty;
10
+ export declare const toAminoParseField: (field: Field, enums: Enum[], interfaces: Interface[], scope?: any[], nested?: number) => any;
11
+ export declare const toAmino: (schema: MessageSchema, enums: Enum[], interfaces: Interface[]) => t.ArrowFunctionExpression;
@@ -0,0 +1,3 @@
1
+ export * from './types';
2
+ export * from './utils';
3
+ export * from './wasm';
@@ -0,0 +1,35 @@
1
+ import * as t from '@babel/types';
2
+ import { Mutation } from './types';
3
+ export declare const addMsgMethod: ({ methodName, typeUrl, TypeName, methodToCall }: {
4
+ methodName: any;
5
+ typeUrl: any;
6
+ TypeName: any;
7
+ methodToCall: any;
8
+ }) => t.ObjectMethod;
9
+ export declare const addFromJSONMethod: ({ methodName, typeUrl, TypeName }: {
10
+ methodName: any;
11
+ typeUrl: any;
12
+ TypeName: any;
13
+ }) => t.ObjectMethod;
14
+ export declare const addFromPartialMethod: ({ methodName, typeUrl, TypeName }: {
15
+ methodName: any;
16
+ typeUrl: any;
17
+ TypeName: any;
18
+ }) => t.ObjectMethod;
19
+ export declare const addToJSONMethod: ({ methodName, typeUrl, TypeName }: {
20
+ methodName: any;
21
+ typeUrl: any;
22
+ TypeName: any;
23
+ }) => t.ObjectMethod;
24
+ export declare const addJsonMethod: ({ methodName, typeUrl, TypeName }: {
25
+ methodName: any;
26
+ typeUrl: any;
27
+ TypeName: any;
28
+ }) => t.ObjectMethod;
29
+ export declare const addEncodedMethod: ({ methodName, typeUrl, TypeName }: {
30
+ methodName: any;
31
+ typeUrl: any;
32
+ TypeName: any;
33
+ }) => t.ObjectMethod;
34
+ export declare const messages: (mutations: Mutation[]) => t.ExportNamedDeclaration;
35
+ export declare const encoded: (mutations: Mutation[]) => t.ExportNamedDeclaration;
@@ -0,0 +1,10 @@
1
+ export declare type fieldType = 'Long' | 'Coin' | 'Duration' | 'Height' | string;
2
+ export interface Field {
3
+ name: string;
4
+ type: fieldType;
5
+ node: any;
6
+ }
7
+ export interface Interface {
8
+ name: string;
9
+ fields: Field[];
10
+ }
@@ -0,0 +1,29 @@
1
+ import * as t from '@babel/types';
2
+ import { Field } from './types';
3
+ import { TSTypeAnnotation, TSExpressionWithTypeArguments } from '@babel/types';
4
+ export declare const bindMethod: (name: string) => t.ExpressionStatement;
5
+ export declare const typedIdentifier: (name: string, typeAnnotation: TSTypeAnnotation, optional?: boolean) => t.Identifier;
6
+ export declare const promiseTypeAnnotation: (name: any) => t.TSTypeAnnotation;
7
+ export declare const classDeclaration: (name: string, body: any[], implementsExressions?: TSExpressionWithTypeArguments[], superClass?: t.Identifier) => t.ClassDeclaration;
8
+ export declare const classProperty: (name: string, typeAnnotation?: TSTypeAnnotation, isReadonly?: boolean, isStatic?: boolean) => t.ClassProperty;
9
+ export declare const arrowFunctionExpression: (params: (t.Identifier | t.Pattern | t.RestElement)[], body: t.BlockStatement, returnType: t.TSTypeAnnotation, isAsync?: boolean) => t.ArrowFunctionExpression;
10
+ export declare const recursiveNamespace: (names: any, moduleBlockBody: any) => any;
11
+ export declare const arrayTypeNDimensions: (body: any, n: any) => any;
12
+ export declare const FieldTypeAsts: {
13
+ string: () => t.TSStringKeyword;
14
+ array: (type: any) => t.TSArrayType;
15
+ Duration: () => t.TSTypeReference;
16
+ Height: () => t.TSTypeReference;
17
+ Coin: () => t.TSTypeReference;
18
+ Long: () => t.TSTypeReference;
19
+ };
20
+ export declare const shorthandProperty: (prop: string) => t.ObjectProperty;
21
+ export declare const importStmt: (names: string[], path: string) => t.ImportDeclaration;
22
+ export declare const importAminoMsg: () => t.ImportDeclaration;
23
+ export declare const getFieldDimensionality: (field: Field) => {
24
+ typeName: string;
25
+ dimensions: number;
26
+ isArray: boolean;
27
+ };
28
+ export declare const memberExpressionOrIdentifier: (names: any) => any;
29
+ export declare const memberExpressionOrIdentifierSnake: (names: any) => any;
@@ -0,0 +1,21 @@
1
+ import * as t from '@babel/types';
2
+ interface QueryMsg {
3
+ $schema: string;
4
+ title: "QueryMsg";
5
+ oneOf: any;
6
+ }
7
+ interface ExecuteMsg {
8
+ $schema: string;
9
+ title: "ExecuteMsg" | "ExecuteMsg_for_Empty";
10
+ oneOf: any;
11
+ }
12
+ export declare const createWasmQueryMethod: (jsonschema: any) => t.ClassProperty;
13
+ export declare const createQueryClass: (className: string, implementsClassName: string, queryMsg: QueryMsg) => t.ExportNamedDeclaration;
14
+ export declare const createWasmExecMethod: (jsonschema: any) => t.ClassProperty;
15
+ export declare const createExecuteClass: (className: string, implementsClassName: string, extendsClassName: string, execMsg: ExecuteMsg) => t.ExportNamedDeclaration;
16
+ export declare const createExecuteInterface: (className: string, extendsClassName: string, execMsg: ExecuteMsg) => t.ExportNamedDeclaration;
17
+ export declare const createQueryInterface: (className: string, queryMsg: QueryMsg) => t.ExportNamedDeclaration;
18
+ export declare const propertySignature: (name: string, typeAnnotation: t.TSTypeAnnotation, optional?: boolean) => t.TSPropertySignature;
19
+ export declare const createTypeOrInterface: (Type: string, jsonschema: any) => t.ExportNamedDeclaration;
20
+ export declare const createTypeInterface: (jsonschema: any) => t.ExportNamedDeclaration;
21
+ export {};