wasm-ast-types 0.26.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE-Apache +201 -0
- package/LICENSE-MIT +21 -0
- package/README.md +24 -1
- package/{types/client → client}/client.d.ts +2 -2
- package/client/client.js +275 -0
- package/client/index.js +17 -0
- package/{types/context → context}/context.d.ts +9 -22
- package/context/context.js +114 -0
- package/{types/context → context}/imports.d.ts +9 -8
- package/context/imports.js +166 -0
- package/context/index.js +18 -0
- package/esm/client/client.js +238 -0
- package/esm/client/index.js +1 -0
- package/esm/context/context.js +104 -0
- package/esm/context/imports.js +136 -0
- package/{module → esm}/context/index.js +1 -1
- package/{src/index.ts → esm/index.js} +0 -1
- package/esm/message-builder/message-builder.js +64 -0
- package/esm/message-composer/message-composer.js +105 -0
- package/esm/provider/provider.js +97 -0
- package/esm/react-query/react-query.js +458 -0
- package/esm/recoil/recoil.js +110 -0
- package/esm/utils/babel.js +231 -0
- package/esm/utils/constants.js +20 -0
- package/esm/utils/ref.js +4 -0
- package/esm/utils/types.js +343 -0
- package/{types/index.d.ts → index.d.ts} +0 -1
- package/index.js +24 -0
- package/message-builder/index.js +17 -0
- package/{types/message-builder → message-builder}/message-builder.d.ts +1 -1
- package/message-builder/message-builder.js +91 -0
- package/message-composer/index.d.ts +1 -0
- package/message-composer/index.js +17 -0
- package/{types/message-composer → message-composer}/message-composer.d.ts +1 -1
- package/message-composer/message-composer.js +133 -0
- package/package.json +19 -68
- package/provider/index.d.ts +1 -0
- package/provider/index.js +17 -0
- package/provider/provider.js +127 -0
- package/react-query/index.d.ts +1 -0
- package/react-query/index.js +17 -0
- package/{types/react-query → react-query}/react-query.d.ts +2 -3
- package/react-query/react-query.js +490 -0
- package/recoil/index.d.ts +1 -0
- package/recoil/index.js +17 -0
- package/{types/recoil → recoil}/recoil.d.ts +1 -1
- package/recoil/recoil.js +140 -0
- package/{types/utils → utils}/babel.d.ts +9 -8
- package/utils/babel.js +285 -0
- package/utils/constants.js +46 -0
- package/utils/index.js +26 -0
- package/{types/utils → utils}/ref.d.ts +1 -1
- package/utils/ref.js +8 -0
- package/{types/utils → utils}/types.d.ts +8 -8
- package/utils/types.js +379 -0
- package/main/client/client.js +0 -196
- package/main/client/index.js +0 -16
- package/main/client/test/ts-client.account-nfts.spec.js +0 -28
- package/main/client/test/ts-client.arrays-ref.spec.js +0 -19
- package/main/client/test/ts-client.arrays.spec.js +0 -26
- package/main/client/test/ts-client.cw-named-groups.test.js +0 -19
- package/main/client/test/ts-client.cw-proposal-single.test.js +0 -23
- package/main/client/test/ts-client.empty-enums.spec.js +0 -13
- package/main/client/test/ts-client.issue-101.spec.js +0 -23
- package/main/client/test/ts-client.issue-103.test.js +0 -44
- package/main/client/test/ts-client.issue-71.test.js +0 -81
- package/main/client/test/ts-client.issue-98.test.js +0 -28
- package/main/client/test/ts-client.issues.test.js +0 -81
- package/main/client/test/ts-client.overrides.spec.js +0 -33
- package/main/client/test/ts-client.sg721.spec.js +0 -19
- package/main/client/test/ts-client.spec.js +0 -87
- package/main/client/test/ts-client.vectis.spec.js +0 -46
- package/main/client/test/ts-client.wager.spec.js +0 -39
- package/main/context/context.js +0 -162
- package/main/context/imports.js +0 -159
- package/main/context/index.js +0 -27
- package/main/index.js +0 -104
- package/main/message-builder/index.js +0 -16
- package/main/message-builder/message-builder.js +0 -62
- package/main/message-builder/message-builder.spec.js +0 -20
- package/main/message-composer/index.js +0 -16
- package/main/message-composer/message-composer.js +0 -86
- package/main/message-composer/message-composer.spec.js +0 -23
- package/main/provider/index.js +0 -16
- package/main/provider/provider.js +0 -71
- package/main/provider/provider.spec.js +0 -60
- package/main/react-query/index.js +0 -16
- package/main/react-query/react-query.js +0 -413
- package/main/react-query/react-query.spec.js +0 -91
- package/main/recoil/index.js +0 -16
- package/main/recoil/recoil.js +0 -61
- package/main/recoil/recoil.spec.js +0 -20
- package/main/types.js +0 -4
- package/main/utils/babel.js +0 -282
- package/main/utils/babel.spec.js +0 -109
- package/main/utils/constants.js +0 -26
- package/main/utils/index.js +0 -65
- package/main/utils/ref.js +0 -12
- package/main/utils/types.js +0 -343
- package/module/client/client.js +0 -166
- package/module/client/index.js +0 -1
- package/module/client/test/ts-client.account-nfts.spec.js +0 -25
- package/module/client/test/ts-client.arrays-ref.spec.js +0 -16
- package/module/client/test/ts-client.arrays.spec.js +0 -23
- package/module/client/test/ts-client.cw-named-groups.test.js +0 -16
- package/module/client/test/ts-client.cw-proposal-single.test.js +0 -20
- package/module/client/test/ts-client.empty-enums.spec.js +0 -10
- package/module/client/test/ts-client.issue-101.spec.js +0 -22
- package/module/client/test/ts-client.issue-103.test.js +0 -41
- package/module/client/test/ts-client.issue-71.test.js +0 -21
- package/module/client/test/ts-client.issue-98.test.js +0 -25
- package/module/client/test/ts-client.issues.test.js +0 -21
- package/module/client/test/ts-client.overrides.spec.js +0 -30
- package/module/client/test/ts-client.sg721.spec.js +0 -16
- package/module/client/test/ts-client.spec.js +0 -84
- package/module/client/test/ts-client.vectis.spec.js +0 -43
- package/module/client/test/ts-client.wager.spec.js +0 -36
- package/module/context/context.js +0 -116
- package/module/context/imports.js +0 -127
- package/module/index.js +0 -9
- package/module/message-builder/index.js +0 -1
- package/module/message-builder/message-builder.js +0 -52
- package/module/message-builder/message-builder.spec.js +0 -17
- package/module/message-composer/index.js +0 -1
- package/module/message-composer/message-composer.js +0 -70
- package/module/message-composer/message-composer.spec.js +0 -20
- package/module/provider/index.js +0 -1
- package/module/provider/provider.js +0 -45
- package/module/provider/provider.spec.js +0 -58
- package/module/react-query/index.js +0 -1
- package/module/react-query/react-query.js +0 -403
- package/module/react-query/react-query.spec.js +0 -85
- package/module/recoil/index.js +0 -1
- package/module/recoil/recoil.js +0 -46
- package/module/recoil/recoil.spec.js +0 -14
- package/module/types.js +0 -3
- package/module/utils/babel.js +0 -203
- package/module/utils/babel.spec.js +0 -70
- package/module/utils/constants.js +0 -12
- package/module/utils/index.js +0 -6
- package/module/utils/ref.js +0 -4
- package/module/utils/types.js +0 -301
- package/src/client/client.ts +0 -584
- package/src/client/index.ts +0 -1
- package/src/client/test/__snapshots__/ts-client.account-nfts.spec.ts.snap +0 -497
- package/src/client/test/__snapshots__/ts-client.arrays-ref.spec.ts.snap +0 -452
- package/src/client/test/__snapshots__/ts-client.arrays.spec.ts.snap +0 -101
- package/src/client/test/__snapshots__/ts-client.cw-named-groups.test.ts.snap +0 -141
- package/src/client/test/__snapshots__/ts-client.cw-proposal-single.test.ts.snap +0 -341
- package/src/client/test/__snapshots__/ts-client.empty-enums.spec.ts.snap +0 -20
- package/src/client/test/__snapshots__/ts-client.issue-101.spec.ts.snap +0 -47
- package/src/client/test/__snapshots__/ts-client.issue-103.test.ts.snap +0 -79
- package/src/client/test/__snapshots__/ts-client.issue-71.test.ts.snap +0 -432
- package/src/client/test/__snapshots__/ts-client.issue-98.test.ts.snap +0 -117
- package/src/client/test/__snapshots__/ts-client.issues.test.ts.snap +0 -984
- package/src/client/test/__snapshots__/ts-client.overrides.spec.ts.snap +0 -709
- package/src/client/test/__snapshots__/ts-client.sg721.spec.ts.snap +0 -350
- package/src/client/test/__snapshots__/ts-client.spec.ts.snap +0 -723
- package/src/client/test/__snapshots__/ts-client.vectis.spec.ts.snap +0 -337
- package/src/client/test/__snapshots__/ts-client.wager.spec.ts.snap +0 -132
- package/src/client/test/ts-client.account-nfts.spec.ts +0 -55
- package/src/client/test/ts-client.arrays-ref.spec.ts +0 -48
- package/src/client/test/ts-client.arrays.spec.ts +0 -58
- package/src/client/test/ts-client.cw-named-groups.test.ts +0 -48
- package/src/client/test/ts-client.cw-proposal-single.test.ts +0 -50
- package/src/client/test/ts-client.empty-enums.spec.ts +0 -28
- package/src/client/test/ts-client.issue-101.spec.ts +0 -37
- package/src/client/test/ts-client.issue-103.test.ts +0 -106
- package/src/client/test/ts-client.issue-71.test.ts +0 -51
- package/src/client/test/ts-client.issue-98.test.ts +0 -55
- package/src/client/test/ts-client.issues.test.ts +0 -52
- package/src/client/test/ts-client.overrides.spec.ts +0 -74
- package/src/client/test/ts-client.sg721.spec.ts +0 -46
- package/src/client/test/ts-client.spec.ts +0 -166
- package/src/client/test/ts-client.vectis.spec.ts +0 -97
- package/src/client/test/ts-client.wager.spec.ts +0 -63
- package/src/context/context.ts +0 -229
- package/src/context/imports.ts +0 -195
- package/src/context/index.ts +0 -2
- package/src/message-builder/__snapshots__/message-builder.spec.ts.snap +0 -270
- package/src/message-builder/message-builder.spec.ts +0 -24
- package/src/message-builder/message-builder.ts +0 -119
- package/src/message-composer/__snapshots__/message-composer.spec.ts.snap +0 -331
- package/src/message-composer/index.ts +0 -1
- package/src/message-composer/message-composer.spec.ts +0 -46
- package/src/message-composer/message-composer.ts +0 -262
- package/src/provider/__snapshots__/provider.spec.ts.snap +0 -49
- package/src/provider/index.ts +0 -1
- package/src/provider/provider.spec.ts +0 -81
- package/src/provider/provider.ts +0 -237
- package/src/react-query/__snapshots__/react-query.spec.ts.snap +0 -1359
- package/src/react-query/index.ts +0 -1
- package/src/react-query/react-query.spec.ts +0 -116
- package/src/react-query/react-query.ts +0 -1072
- package/src/recoil/__snapshots__/recoil.spec.ts.snap +0 -203
- package/src/recoil/index.ts +0 -1
- package/src/recoil/recoil.spec.ts +0 -38
- package/src/recoil/recoil.ts +0 -307
- package/src/types.ts +0 -44
- package/src/utils/__snapshots__/babel.spec.ts.snap +0 -75
- package/src/utils/babel.spec.ts +0 -511
- package/src/utils/babel.ts +0 -352
- package/src/utils/constants.ts +0 -37
- package/src/utils/ref.ts +0 -6
- package/src/utils/types.ts +0 -478
- package/types/types.d.ts +0 -41
- /package/{types/client → client}/index.d.ts +0 -0
- /package/{types/context → context}/index.d.ts +0 -0
- /package/{src/message-builder/index.ts → esm/message-builder/index.js} +0 -0
- /package/{types/message-composer/index.d.ts → esm/message-composer/index.js} +0 -0
- /package/{types/provider/index.d.ts → esm/provider/index.js} +0 -0
- /package/{types/react-query/index.d.ts → esm/react-query/index.js} +0 -0
- /package/{types/recoil/index.d.ts → esm/recoil/index.js} +0 -0
- /package/{src/utils/index.ts → esm/utils/index.js} +0 -0
- /package/{types/message-builder → message-builder}/index.d.ts +0 -0
- /package/{types/provider → provider}/provider.d.ts +0 -0
- /package/{types/utils → utils}/constants.d.ts +0 -0
- /package/{types/utils → utils}/index.d.ts +0 -0
@@ -1,25 +1,26 @@
|
|
1
1
|
import * as t from '@babel/types';
|
2
|
-
import { Field } from '
|
2
|
+
import { Field } from '@cosmology/ts-codegen-types';
|
3
3
|
import { TSTypeAnnotation, TSExpressionWithTypeArguments } from '@babel/types';
|
4
|
+
import { JSONSchema } from '@cosmology/ts-codegen-types';
|
4
5
|
export declare const propertySignature: (name: string, typeAnnotation: TSTypeAnnotation, optional?: boolean) => t.TSPropertySignature;
|
5
6
|
export declare const identifier: (name: string, typeAnnotation: t.TSTypeAnnotation, optional?: boolean) => t.Identifier;
|
6
7
|
export declare const tsTypeOperator: (typeAnnotation: t.TSType, operator: string) => t.TSTypeOperator;
|
7
|
-
export declare const getMessageProperties: (msg:
|
8
|
+
export declare const getMessageProperties: (msg: JSONSchema) => JSONSchema[];
|
8
9
|
export declare const tsPropertySignature: (key: t.Expression, typeAnnotation: t.TSTypeAnnotation, optional: boolean) => t.TSPropertySignature;
|
9
10
|
export declare const tsObjectPattern: (properties: (t.RestElement | t.ObjectProperty)[], typeAnnotation: t.TSTypeAnnotation) => t.ObjectPattern;
|
10
11
|
export declare const callExpression: (callee: t.Expression | t.V8IntrinsicIdentifier, _arguments: (t.Expression | t.SpreadElement | t.ArgumentPlaceholder)[], typeParameters: t.TSTypeParameterInstantiation) => t.CallExpression;
|
11
12
|
export declare const bindMethod: (name: string) => t.ExpressionStatement;
|
12
13
|
export declare const typedIdentifier: (name: string, typeAnnotation: TSTypeAnnotation, optional?: boolean) => t.Identifier;
|
13
|
-
export declare const promiseTypeAnnotation: (name:
|
14
|
+
export declare const promiseTypeAnnotation: (name: string) => t.TSTypeAnnotation;
|
14
15
|
export declare const abstractClassDeclaration: (name: string, body: any[], implementsExressions?: TSExpressionWithTypeArguments[], superClass?: t.Identifier) => t.ClassDeclaration;
|
15
16
|
export declare const classDeclaration: (name: string, body: any[], implementsExressions?: TSExpressionWithTypeArguments[], superClass?: t.Identifier) => t.ClassDeclaration;
|
16
17
|
export declare const classProperty: (name: string, typeAnnotation?: TSTypeAnnotation, isReadonly?: boolean, isStatic?: boolean, noImplicitOverride?: boolean) => t.ClassProperty;
|
17
18
|
export declare const arrowFunctionExpression: (params: (t.Identifier | t.Pattern | t.RestElement)[], body: t.BlockStatement, returnType: t.TSTypeAnnotation, isAsync?: boolean) => t.ArrowFunctionExpression;
|
18
|
-
export declare const recursiveNamespace: (names:
|
19
|
-
export declare const arrayTypeNDimensions: (body: any, n:
|
19
|
+
export declare const recursiveNamespace: (names: string[], moduleBlockBody: any) => t.ExportNamedDeclaration[];
|
20
|
+
export declare const arrayTypeNDimensions: (body: any, n: number) => t.TSArrayType;
|
20
21
|
export declare const FieldTypeAsts: {
|
21
22
|
string: () => t.TSStringKeyword;
|
22
|
-
array: (type:
|
23
|
+
array: (type: 'string' | 'Duration' | 'Height' | 'Coin' | 'Long') => t.TSArrayType;
|
23
24
|
Duration: () => t.TSTypeReference;
|
24
25
|
Height: () => t.TSTypeReference;
|
25
26
|
Coin: () => t.TSTypeReference;
|
@@ -34,8 +35,8 @@ export declare const getFieldDimensionality: (field: Field) => {
|
|
34
35
|
dimensions: number;
|
35
36
|
isArray: boolean;
|
36
37
|
};
|
37
|
-
export declare const memberExpressionOrIdentifier: (names:
|
38
|
-
export declare const memberExpressionOrIdentifierSnake: (names:
|
38
|
+
export declare const memberExpressionOrIdentifier: (names: string[]) => t.MemberExpression | t.Identifier;
|
39
|
+
export declare const memberExpressionOrIdentifierSnake: (names: string[]) => t.MemberExpression | t.Identifier;
|
39
40
|
/**
|
40
41
|
* If optional, return a conditional, otherwise just the expression
|
41
42
|
*/
|
package/utils/babel.js
ADDED
@@ -0,0 +1,285 @@
|
|
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.pickTypeReference = exports.omitTypeReference = exports.parameterizedTypeReference = exports.typeRefOrUnionWithUndefined = exports.optionalConditionalExpression = exports.memberExpressionOrIdentifierSnake = exports.memberExpressionOrIdentifier = exports.getFieldDimensionality = exports.importAminoMsg = exports.importAs = exports.importStmt = exports.shorthandProperty = exports.FieldTypeAsts = exports.arrayTypeNDimensions = exports.recursiveNamespace = exports.arrowFunctionExpression = exports.classProperty = exports.classDeclaration = exports.abstractClassDeclaration = exports.promiseTypeAnnotation = exports.typedIdentifier = exports.bindMethod = exports.callExpression = exports.tsObjectPattern = exports.tsPropertySignature = exports.getMessageProperties = exports.tsTypeOperator = exports.identifier = exports.propertySignature = void 0;
|
27
|
+
const t = __importStar(require("@babel/types"));
|
28
|
+
const case_1 = require("case");
|
29
|
+
const ref_1 = require("./ref");
|
30
|
+
// t.TSPropertySignature - kind?
|
31
|
+
const propertySignature = (name, typeAnnotation, optional = false) => {
|
32
|
+
return {
|
33
|
+
type: 'TSPropertySignature',
|
34
|
+
key: t.identifier(name),
|
35
|
+
kind: 'get',
|
36
|
+
typeAnnotation,
|
37
|
+
optional
|
38
|
+
};
|
39
|
+
};
|
40
|
+
exports.propertySignature = propertySignature;
|
41
|
+
const identifier = (name, typeAnnotation, optional = false) => {
|
42
|
+
const type = t.identifier(name);
|
43
|
+
type.typeAnnotation = typeAnnotation;
|
44
|
+
type.optional = optional;
|
45
|
+
return type;
|
46
|
+
};
|
47
|
+
exports.identifier = identifier;
|
48
|
+
const tsTypeOperator = (typeAnnotation, operator) => {
|
49
|
+
const obj = t.tsTypeOperator(typeAnnotation);
|
50
|
+
obj.operator = operator;
|
51
|
+
return obj;
|
52
|
+
};
|
53
|
+
exports.tsTypeOperator = tsTypeOperator;
|
54
|
+
const getMessageProperties = (msg) => {
|
55
|
+
let results = [];
|
56
|
+
let objs = [];
|
57
|
+
if (msg.anyOf) {
|
58
|
+
objs = msg.anyOf;
|
59
|
+
}
|
60
|
+
else if (msg.oneOf) {
|
61
|
+
objs = msg.oneOf;
|
62
|
+
}
|
63
|
+
else if (msg.allOf) {
|
64
|
+
objs = msg.allOf;
|
65
|
+
}
|
66
|
+
for (const obj of objs) {
|
67
|
+
if (obj.properties) {
|
68
|
+
results.push(obj);
|
69
|
+
}
|
70
|
+
else {
|
71
|
+
if (obj.$ref) {
|
72
|
+
const ref = (0, ref_1.refLookup)(obj.$ref, msg);
|
73
|
+
const refProps = (0, exports.getMessageProperties)(ref);
|
74
|
+
results = [...results, ...refProps];
|
75
|
+
}
|
76
|
+
}
|
77
|
+
}
|
78
|
+
return results;
|
79
|
+
};
|
80
|
+
exports.getMessageProperties = getMessageProperties;
|
81
|
+
const tsPropertySignature = (key, typeAnnotation, optional) => {
|
82
|
+
const obj = t.tsPropertySignature(key, typeAnnotation);
|
83
|
+
obj.optional = optional;
|
84
|
+
return obj;
|
85
|
+
};
|
86
|
+
exports.tsPropertySignature = tsPropertySignature;
|
87
|
+
const tsObjectPattern = (properties, typeAnnotation) => {
|
88
|
+
const obj = t.objectPattern(properties);
|
89
|
+
obj.typeAnnotation = typeAnnotation;
|
90
|
+
return obj;
|
91
|
+
};
|
92
|
+
exports.tsObjectPattern = tsObjectPattern;
|
93
|
+
const callExpression = (callee, _arguments, typeParameters) => {
|
94
|
+
const callExpr = t.callExpression(callee, _arguments);
|
95
|
+
callExpr.typeParameters = typeParameters;
|
96
|
+
return callExpr;
|
97
|
+
};
|
98
|
+
exports.callExpression = callExpression;
|
99
|
+
const bindMethod = (name) => {
|
100
|
+
return t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.thisExpression(), t.identifier(name)), t.callExpression(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier(name)), t.identifier('bind')), [
|
101
|
+
t.thisExpression()
|
102
|
+
])));
|
103
|
+
};
|
104
|
+
exports.bindMethod = bindMethod;
|
105
|
+
const typedIdentifier = (name, typeAnnotation, optional = false) => {
|
106
|
+
const type = t.identifier(name);
|
107
|
+
type.typeAnnotation = typeAnnotation;
|
108
|
+
type.optional = optional;
|
109
|
+
return type;
|
110
|
+
};
|
111
|
+
exports.typedIdentifier = typedIdentifier;
|
112
|
+
const promiseTypeAnnotation = (name) => {
|
113
|
+
return t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Promise'), t.tsTypeParameterInstantiation([
|
114
|
+
t.tsTypeReference(t.identifier(name))
|
115
|
+
])));
|
116
|
+
};
|
117
|
+
exports.promiseTypeAnnotation = promiseTypeAnnotation;
|
118
|
+
const abstractClassDeclaration = (name, body, implementsExressions = [], superClass = null) => {
|
119
|
+
const declaration = (0, exports.classDeclaration)(name, body, implementsExressions, superClass);
|
120
|
+
declaration.abstract = true;
|
121
|
+
return declaration;
|
122
|
+
};
|
123
|
+
exports.abstractClassDeclaration = abstractClassDeclaration;
|
124
|
+
const classDeclaration = (name, body, implementsExressions = [], superClass = null) => {
|
125
|
+
const declaration = t.classDeclaration(t.identifier(name), superClass, t.classBody(body));
|
126
|
+
if (implementsExressions.length) {
|
127
|
+
declaration.implements = implementsExressions;
|
128
|
+
}
|
129
|
+
return declaration;
|
130
|
+
};
|
131
|
+
exports.classDeclaration = classDeclaration;
|
132
|
+
const classProperty = (name, typeAnnotation = null, isReadonly = false, isStatic = false, noImplicitOverride = false) => {
|
133
|
+
const prop = t.classProperty(t.identifier(name));
|
134
|
+
if (isReadonly)
|
135
|
+
prop.readonly = true;
|
136
|
+
if (isStatic)
|
137
|
+
prop.static = true;
|
138
|
+
if (typeAnnotation)
|
139
|
+
prop.typeAnnotation = typeAnnotation;
|
140
|
+
if (noImplicitOverride)
|
141
|
+
prop.override = true;
|
142
|
+
return prop;
|
143
|
+
};
|
144
|
+
exports.classProperty = classProperty;
|
145
|
+
const arrowFunctionExpression = (params, body, returnType, isAsync = false) => {
|
146
|
+
const func = t.arrowFunctionExpression(params, body, isAsync);
|
147
|
+
if (returnType)
|
148
|
+
func.returnType = returnType;
|
149
|
+
return func;
|
150
|
+
};
|
151
|
+
exports.arrowFunctionExpression = arrowFunctionExpression;
|
152
|
+
const recursiveNamespace = (names, moduleBlockBody) => {
|
153
|
+
if (!names || !names.length)
|
154
|
+
return moduleBlockBody;
|
155
|
+
const name = names.pop();
|
156
|
+
const body = [
|
157
|
+
t.exportNamedDeclaration(t.tsModuleDeclaration(t.identifier(name), t.tsModuleBlock((0, exports.recursiveNamespace)(names, moduleBlockBody))))
|
158
|
+
];
|
159
|
+
return body;
|
160
|
+
};
|
161
|
+
exports.recursiveNamespace = recursiveNamespace;
|
162
|
+
const arrayTypeNDimensions = (body, n) => {
|
163
|
+
if (!n)
|
164
|
+
return t.tsArrayType(body);
|
165
|
+
return t.tsArrayType((0, exports.arrayTypeNDimensions)(body, n - 1));
|
166
|
+
};
|
167
|
+
exports.arrayTypeNDimensions = arrayTypeNDimensions;
|
168
|
+
exports.FieldTypeAsts = {
|
169
|
+
string: () => {
|
170
|
+
return t.tsStringKeyword();
|
171
|
+
},
|
172
|
+
array: (type) => {
|
173
|
+
const result = exports.FieldTypeAsts[type]();
|
174
|
+
return t.tsArrayType(result);
|
175
|
+
},
|
176
|
+
Duration: () => {
|
177
|
+
return t.tsTypeReference(t.identifier('Duration'));
|
178
|
+
},
|
179
|
+
Height: () => {
|
180
|
+
return t.tsTypeReference(t.identifier('Height'));
|
181
|
+
},
|
182
|
+
Coin: () => {
|
183
|
+
return t.tsTypeReference(t.identifier('Coin'));
|
184
|
+
},
|
185
|
+
Long: () => {
|
186
|
+
return t.tsTypeReference(t.identifier('Long'));
|
187
|
+
}
|
188
|
+
};
|
189
|
+
const shorthandProperty = (prop) => {
|
190
|
+
return t.objectProperty(t.identifier(prop), t.identifier(prop), false, true);
|
191
|
+
};
|
192
|
+
exports.shorthandProperty = shorthandProperty;
|
193
|
+
const importStmt = (names, path) => {
|
194
|
+
return t.importDeclaration(names.map(name => t.importSpecifier(t.identifier(name), t.identifier(name))), t.stringLiteral(path));
|
195
|
+
};
|
196
|
+
exports.importStmt = importStmt;
|
197
|
+
const importAs = (name, importAs, importPath) => {
|
198
|
+
return t.importDeclaration([
|
199
|
+
t.importSpecifier(t.identifier(importAs), t.identifier(name))
|
200
|
+
], t.stringLiteral(importPath));
|
201
|
+
};
|
202
|
+
exports.importAs = importAs;
|
203
|
+
const importAminoMsg = () => {
|
204
|
+
return (0, exports.importStmt)(['AminoMsg'], '@cosmjs/amino');
|
205
|
+
};
|
206
|
+
exports.importAminoMsg = importAminoMsg;
|
207
|
+
const getFieldDimensionality = (field) => {
|
208
|
+
let typeName = field.type;
|
209
|
+
const isArray = typeName.endsWith('[]');
|
210
|
+
let dimensions = 0;
|
211
|
+
if (isArray) {
|
212
|
+
dimensions = typeName.match(/\[\]/g).length - 1;
|
213
|
+
typeName = typeName.replace(/\[\]/g, '');
|
214
|
+
}
|
215
|
+
return {
|
216
|
+
typeName,
|
217
|
+
dimensions,
|
218
|
+
isArray
|
219
|
+
};
|
220
|
+
};
|
221
|
+
exports.getFieldDimensionality = getFieldDimensionality;
|
222
|
+
const memberExpressionOrIdentifier = (names) => {
|
223
|
+
if (names.length === 1) {
|
224
|
+
return t.identifier(names[0]);
|
225
|
+
}
|
226
|
+
if (names.length === 2) {
|
227
|
+
const [b, a] = names;
|
228
|
+
return t.memberExpression(t.identifier(a), t.identifier(b));
|
229
|
+
}
|
230
|
+
const [name, ...rest] = names;
|
231
|
+
return t.memberExpression((0, exports.memberExpressionOrIdentifier)(rest), t.identifier(name));
|
232
|
+
};
|
233
|
+
exports.memberExpressionOrIdentifier = memberExpressionOrIdentifier;
|
234
|
+
const memberExpressionOrIdentifierSnake = (names) => {
|
235
|
+
if (names.length === 1) {
|
236
|
+
return t.identifier((0, case_1.snake)(names[0]));
|
237
|
+
}
|
238
|
+
if (names.length === 2) {
|
239
|
+
const [b, a] = names;
|
240
|
+
return t.memberExpression(t.identifier((0, case_1.snake)(a)), t.identifier((0, case_1.snake)(b)));
|
241
|
+
}
|
242
|
+
const [name, ...rest] = names;
|
243
|
+
return t.memberExpression((0, exports.memberExpressionOrIdentifierSnake)(rest), t.identifier((0, case_1.snake)(name)));
|
244
|
+
};
|
245
|
+
exports.memberExpressionOrIdentifierSnake = memberExpressionOrIdentifierSnake;
|
246
|
+
/**
|
247
|
+
* If optional, return a conditional, otherwise just the expression
|
248
|
+
*/
|
249
|
+
const optionalConditionalExpression = (test, expression, alternate, optional = false) => {
|
250
|
+
return optional
|
251
|
+
? t.conditionalExpression(test, expression, alternate)
|
252
|
+
: expression;
|
253
|
+
};
|
254
|
+
exports.optionalConditionalExpression = optionalConditionalExpression;
|
255
|
+
const typeRefOrUnionWithUndefined = (identifier, optional = false) => {
|
256
|
+
const typeReference = t.tsTypeReference(identifier);
|
257
|
+
return optional
|
258
|
+
? t.tsUnionType([
|
259
|
+
typeReference,
|
260
|
+
t.tsUndefinedKeyword()
|
261
|
+
])
|
262
|
+
: typeReference;
|
263
|
+
};
|
264
|
+
exports.typeRefOrUnionWithUndefined = typeRefOrUnionWithUndefined;
|
265
|
+
const parameterizedTypeReference = (identifier, from, omit) => {
|
266
|
+
return t.tsTypeReference(t.identifier(identifier), t.tsTypeParameterInstantiation([
|
267
|
+
from,
|
268
|
+
typeof omit === 'string'
|
269
|
+
? t.tsLiteralType(t.stringLiteral(omit))
|
270
|
+
: t.tsUnionType(omit.map(o => t.tsLiteralType(t.stringLiteral(o))))
|
271
|
+
]));
|
272
|
+
};
|
273
|
+
exports.parameterizedTypeReference = parameterizedTypeReference;
|
274
|
+
/**
|
275
|
+
* omitTypeReference(t.tsTypeReference(t.identifier('Cw4UpdateMembersMutation'),),'args').....
|
276
|
+
* Omit<Cw4UpdateMembersMutation, 'args'>
|
277
|
+
*/
|
278
|
+
const omitTypeReference = (from, omit) => {
|
279
|
+
return (0, exports.parameterizedTypeReference)('Omit', from, omit);
|
280
|
+
};
|
281
|
+
exports.omitTypeReference = omitTypeReference;
|
282
|
+
const pickTypeReference = (from, pick) => {
|
283
|
+
return (0, exports.parameterizedTypeReference)('Pick', from, pick);
|
284
|
+
};
|
285
|
+
exports.pickTypeReference = pickTypeReference;
|
@@ -0,0 +1,46 @@
|
|
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.PROVIDER_TYPES = exports.FIXED_EXECUTE_PARAMS = exports.OPTIONAL_MEMO_PARAM = exports.OPTIONAL_FEE_PARAM = exports.OPTIONAL_FUNDS_PARAM = void 0;
|
27
|
+
const babel_1 = require("./babel");
|
28
|
+
const t = __importStar(require("@babel/types"));
|
29
|
+
exports.OPTIONAL_FUNDS_PARAM = (0, babel_1.identifier)('_funds', t.tsTypeAnnotation(t.tsArrayType(t.tsTypeReference(t.identifier('Coin')))), true);
|
30
|
+
exports.OPTIONAL_FEE_PARAM = (0, babel_1.identifier)('fee', t.tsTypeAnnotation(t.tsUnionType([
|
31
|
+
t.tsNumberKeyword(),
|
32
|
+
t.tsTypeReference(t.identifier('StdFee')),
|
33
|
+
t.tsLiteralType(t.stringLiteral('auto'))
|
34
|
+
])), true);
|
35
|
+
exports.OPTIONAL_MEMO_PARAM = (0, babel_1.identifier)('memo', t.tsTypeAnnotation(t.tsStringKeyword()), true);
|
36
|
+
exports.FIXED_EXECUTE_PARAMS = [
|
37
|
+
exports.OPTIONAL_FEE_PARAM,
|
38
|
+
exports.OPTIONAL_MEMO_PARAM,
|
39
|
+
exports.OPTIONAL_FUNDS_PARAM
|
40
|
+
];
|
41
|
+
exports.PROVIDER_TYPES = {
|
42
|
+
SIGNING_CLIENT_TYPE: "client",
|
43
|
+
QUERY_CLIENT_TYPE: "queryClient",
|
44
|
+
MESSAGE_COMPOSER_TYPE: 'message-composer',
|
45
|
+
PROVIDER_TYPE: 'provider'
|
46
|
+
};
|
package/utils/index.js
ADDED
@@ -0,0 +1,26 @@
|
|
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
|
+
exports.PROVIDER_TYPES = exports.FIXED_EXECUTE_PARAMS = exports.OPTIONAL_FUNDS_PARAM = void 0;
|
18
|
+
__exportStar(require("./babel"), exports);
|
19
|
+
__exportStar(require("./types"), exports);
|
20
|
+
__exportStar(require("./ref"), exports);
|
21
|
+
var constants_1 = require("./constants");
|
22
|
+
Object.defineProperty(exports, "OPTIONAL_FUNDS_PARAM", { enumerable: true, get: function () { return constants_1.OPTIONAL_FUNDS_PARAM; } });
|
23
|
+
var constants_2 = require("./constants");
|
24
|
+
Object.defineProperty(exports, "FIXED_EXECUTE_PARAMS", { enumerable: true, get: function () { return constants_2.FIXED_EXECUTE_PARAMS; } });
|
25
|
+
var constants_3 = require("./constants");
|
26
|
+
Object.defineProperty(exports, "PROVIDER_TYPES", { enumerable: true, get: function () { return constants_3.PROVIDER_TYPES; } });
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import { JSONSchema } from "
|
1
|
+
import { JSONSchema } from "@cosmology/ts-codegen-types";
|
2
2
|
export declare const refLookup: ($ref: string, schema: JSONSchema) => JSONSchema;
|
package/utils/ref.js
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.refLookup = void 0;
|
4
|
+
const refLookup = ($ref, schema) => {
|
5
|
+
const refName = $ref.replace('#/definitions/', '');
|
6
|
+
return schema.definitions?.[refName];
|
7
|
+
};
|
8
|
+
exports.refLookup = refLookup;
|
@@ -1,20 +1,20 @@
|
|
1
1
|
import * as t from '@babel/types';
|
2
|
-
import { TSTypeAnnotation } from '@babel/types';
|
3
2
|
import { RenderContext } from '../context';
|
4
|
-
import { JSONSchema } from '
|
3
|
+
import { JSONSchema } from '@cosmology/ts-codegen-types';
|
5
4
|
export declare function getResponseType(context: RenderContext, underscoreName: string): string;
|
6
|
-
export declare const getTypeFromRef: ($ref:
|
5
|
+
export declare const getTypeFromRef: ($ref: string) => t.TSTypeReference;
|
6
|
+
export declare const getTypeOrRef: (obj: JSONSchema) => t.TSType;
|
7
7
|
export declare const detectType: (type: string | string[]) => {
|
8
8
|
type: string;
|
9
9
|
optional: boolean;
|
10
10
|
};
|
11
|
-
export declare const getTypeInfo: (info: JSONSchema) => {
|
12
|
-
type:
|
13
|
-
optional:
|
11
|
+
export declare const getTypeInfo: (context: RenderContext, info: JSONSchema) => {
|
12
|
+
type: t.TSBooleanKeyword | t.TSNullKeyword | t.TSNumberKeyword | t.TSStringKeyword | t.TSTypeReference | t.TSArrayType;
|
13
|
+
optional: boolean;
|
14
14
|
};
|
15
|
-
export declare const getType: (type: string) => t.TSBooleanKeyword | t.TSNumberKeyword | t.TSStringKeyword;
|
15
|
+
export declare const getType: (type: string) => t.TSBooleanKeyword | t.TSNullKeyword | t.TSNumberKeyword | t.TSStringKeyword;
|
16
16
|
export declare const getPropertyType: (context: RenderContext, schema: JSONSchema, prop: string) => {
|
17
|
-
type:
|
17
|
+
type: t.TSBooleanKeyword | t.TSNullKeyword | t.TSNumberKeyword | t.TSStringKeyword | t.TSTypeReference | t.TSArrayType;
|
18
18
|
optional: boolean;
|
19
19
|
};
|
20
20
|
export declare function getPropertySignatureFromProp(context: RenderContext, jsonschema: JSONSchema, prop: string, camelize: boolean): t.TSPropertySignature;
|