wasm-ast-types 0.26.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE-Apache +201 -0
- package/LICENSE-MIT +21 -0
- package/README.md +1 -1
- package/{types/client → client}/client.d.ts +2 -2
- package/client/client.js +275 -0
- package/client/index.js +17 -0
- package/{types/context → context}/context.d.ts +9 -22
- package/context/context.js +114 -0
- package/{types/context → context}/imports.d.ts +9 -8
- package/context/imports.js +166 -0
- package/context/index.js +18 -0
- package/esm/client/client.js +238 -0
- package/esm/client/index.js +1 -0
- package/esm/context/context.js +104 -0
- package/esm/context/imports.js +136 -0
- package/{module → esm}/context/index.js +1 -1
- package/{src/index.ts → esm/index.js} +0 -1
- package/esm/message-builder/message-builder.js +64 -0
- package/esm/message-composer/message-composer.js +105 -0
- package/esm/provider/provider.js +97 -0
- package/esm/react-query/react-query.js +458 -0
- package/esm/recoil/recoil.js +110 -0
- package/esm/utils/babel.js +231 -0
- package/esm/utils/constants.js +20 -0
- package/esm/utils/ref.js +4 -0
- package/esm/utils/types.js +343 -0
- package/{types/index.d.ts → index.d.ts} +0 -1
- package/index.js +24 -0
- package/message-builder/index.js +17 -0
- package/{types/message-builder → message-builder}/message-builder.d.ts +1 -1
- package/message-builder/message-builder.js +91 -0
- package/message-composer/index.d.ts +1 -0
- package/message-composer/index.js +17 -0
- package/{types/message-composer → message-composer}/message-composer.d.ts +1 -1
- package/message-composer/message-composer.js +133 -0
- package/package.json +19 -68
- package/provider/index.d.ts +1 -0
- package/provider/index.js +17 -0
- package/provider/provider.js +127 -0
- package/react-query/index.d.ts +1 -0
- package/react-query/index.js +17 -0
- package/{types/react-query → react-query}/react-query.d.ts +2 -3
- package/react-query/react-query.js +490 -0
- package/recoil/index.d.ts +1 -0
- package/recoil/index.js +17 -0
- package/{types/recoil → recoil}/recoil.d.ts +1 -1
- package/recoil/recoil.js +140 -0
- package/{types/utils → utils}/babel.d.ts +9 -8
- package/utils/babel.js +285 -0
- package/utils/constants.js +46 -0
- package/utils/index.js +26 -0
- package/{types/utils → utils}/ref.d.ts +1 -1
- package/utils/ref.js +8 -0
- package/{types/utils → utils}/types.d.ts +8 -8
- package/utils/types.js +379 -0
- package/main/client/client.js +0 -196
- package/main/client/index.js +0 -16
- package/main/client/test/ts-client.account-nfts.spec.js +0 -28
- package/main/client/test/ts-client.arrays-ref.spec.js +0 -19
- package/main/client/test/ts-client.arrays.spec.js +0 -26
- package/main/client/test/ts-client.cw-named-groups.test.js +0 -19
- package/main/client/test/ts-client.cw-proposal-single.test.js +0 -23
- package/main/client/test/ts-client.empty-enums.spec.js +0 -13
- package/main/client/test/ts-client.issue-101.spec.js +0 -23
- package/main/client/test/ts-client.issue-103.test.js +0 -44
- package/main/client/test/ts-client.issue-71.test.js +0 -81
- package/main/client/test/ts-client.issue-98.test.js +0 -28
- package/main/client/test/ts-client.issues.test.js +0 -81
- package/main/client/test/ts-client.overrides.spec.js +0 -33
- package/main/client/test/ts-client.sg721.spec.js +0 -19
- package/main/client/test/ts-client.spec.js +0 -87
- package/main/client/test/ts-client.vectis.spec.js +0 -46
- package/main/client/test/ts-client.wager.spec.js +0 -39
- package/main/context/context.js +0 -162
- package/main/context/imports.js +0 -159
- package/main/context/index.js +0 -27
- package/main/index.js +0 -104
- package/main/message-builder/index.js +0 -16
- package/main/message-builder/message-builder.js +0 -62
- package/main/message-builder/message-builder.spec.js +0 -20
- package/main/message-composer/index.js +0 -16
- package/main/message-composer/message-composer.js +0 -86
- package/main/message-composer/message-composer.spec.js +0 -23
- package/main/provider/index.js +0 -16
- package/main/provider/provider.js +0 -71
- package/main/provider/provider.spec.js +0 -60
- package/main/react-query/index.js +0 -16
- package/main/react-query/react-query.js +0 -413
- package/main/react-query/react-query.spec.js +0 -91
- package/main/recoil/index.js +0 -16
- package/main/recoil/recoil.js +0 -61
- package/main/recoil/recoil.spec.js +0 -20
- package/main/types.js +0 -4
- package/main/utils/babel.js +0 -282
- package/main/utils/babel.spec.js +0 -109
- package/main/utils/constants.js +0 -26
- package/main/utils/index.js +0 -65
- package/main/utils/ref.js +0 -12
- package/main/utils/types.js +0 -343
- package/module/client/client.js +0 -166
- package/module/client/index.js +0 -1
- package/module/client/test/ts-client.account-nfts.spec.js +0 -25
- package/module/client/test/ts-client.arrays-ref.spec.js +0 -16
- package/module/client/test/ts-client.arrays.spec.js +0 -23
- package/module/client/test/ts-client.cw-named-groups.test.js +0 -16
- package/module/client/test/ts-client.cw-proposal-single.test.js +0 -20
- package/module/client/test/ts-client.empty-enums.spec.js +0 -10
- package/module/client/test/ts-client.issue-101.spec.js +0 -22
- package/module/client/test/ts-client.issue-103.test.js +0 -41
- package/module/client/test/ts-client.issue-71.test.js +0 -21
- package/module/client/test/ts-client.issue-98.test.js +0 -25
- package/module/client/test/ts-client.issues.test.js +0 -21
- package/module/client/test/ts-client.overrides.spec.js +0 -30
- package/module/client/test/ts-client.sg721.spec.js +0 -16
- package/module/client/test/ts-client.spec.js +0 -84
- package/module/client/test/ts-client.vectis.spec.js +0 -43
- package/module/client/test/ts-client.wager.spec.js +0 -36
- package/module/context/context.js +0 -116
- package/module/context/imports.js +0 -127
- package/module/index.js +0 -9
- package/module/message-builder/index.js +0 -1
- package/module/message-builder/message-builder.js +0 -52
- package/module/message-builder/message-builder.spec.js +0 -17
- package/module/message-composer/index.js +0 -1
- package/module/message-composer/message-composer.js +0 -70
- package/module/message-composer/message-composer.spec.js +0 -20
- package/module/provider/index.js +0 -1
- package/module/provider/provider.js +0 -45
- package/module/provider/provider.spec.js +0 -58
- package/module/react-query/index.js +0 -1
- package/module/react-query/react-query.js +0 -403
- package/module/react-query/react-query.spec.js +0 -85
- package/module/recoil/index.js +0 -1
- package/module/recoil/recoil.js +0 -46
- package/module/recoil/recoil.spec.js +0 -14
- package/module/types.js +0 -3
- package/module/utils/babel.js +0 -203
- package/module/utils/babel.spec.js +0 -70
- package/module/utils/constants.js +0 -12
- package/module/utils/index.js +0 -6
- package/module/utils/ref.js +0 -4
- package/module/utils/types.js +0 -301
- package/src/client/client.ts +0 -584
- package/src/client/index.ts +0 -1
- package/src/client/test/__snapshots__/ts-client.account-nfts.spec.ts.snap +0 -497
- package/src/client/test/__snapshots__/ts-client.arrays-ref.spec.ts.snap +0 -452
- package/src/client/test/__snapshots__/ts-client.arrays.spec.ts.snap +0 -101
- package/src/client/test/__snapshots__/ts-client.cw-named-groups.test.ts.snap +0 -141
- package/src/client/test/__snapshots__/ts-client.cw-proposal-single.test.ts.snap +0 -341
- package/src/client/test/__snapshots__/ts-client.empty-enums.spec.ts.snap +0 -20
- package/src/client/test/__snapshots__/ts-client.issue-101.spec.ts.snap +0 -47
- package/src/client/test/__snapshots__/ts-client.issue-103.test.ts.snap +0 -79
- package/src/client/test/__snapshots__/ts-client.issue-71.test.ts.snap +0 -432
- package/src/client/test/__snapshots__/ts-client.issue-98.test.ts.snap +0 -117
- package/src/client/test/__snapshots__/ts-client.issues.test.ts.snap +0 -984
- package/src/client/test/__snapshots__/ts-client.overrides.spec.ts.snap +0 -709
- package/src/client/test/__snapshots__/ts-client.sg721.spec.ts.snap +0 -350
- package/src/client/test/__snapshots__/ts-client.spec.ts.snap +0 -723
- package/src/client/test/__snapshots__/ts-client.vectis.spec.ts.snap +0 -337
- package/src/client/test/__snapshots__/ts-client.wager.spec.ts.snap +0 -132
- package/src/client/test/ts-client.account-nfts.spec.ts +0 -55
- package/src/client/test/ts-client.arrays-ref.spec.ts +0 -48
- package/src/client/test/ts-client.arrays.spec.ts +0 -58
- package/src/client/test/ts-client.cw-named-groups.test.ts +0 -48
- package/src/client/test/ts-client.cw-proposal-single.test.ts +0 -50
- package/src/client/test/ts-client.empty-enums.spec.ts +0 -28
- package/src/client/test/ts-client.issue-101.spec.ts +0 -37
- package/src/client/test/ts-client.issue-103.test.ts +0 -106
- package/src/client/test/ts-client.issue-71.test.ts +0 -51
- package/src/client/test/ts-client.issue-98.test.ts +0 -55
- package/src/client/test/ts-client.issues.test.ts +0 -52
- package/src/client/test/ts-client.overrides.spec.ts +0 -74
- package/src/client/test/ts-client.sg721.spec.ts +0 -46
- package/src/client/test/ts-client.spec.ts +0 -166
- package/src/client/test/ts-client.vectis.spec.ts +0 -97
- package/src/client/test/ts-client.wager.spec.ts +0 -63
- package/src/context/context.ts +0 -229
- package/src/context/imports.ts +0 -195
- package/src/context/index.ts +0 -2
- package/src/message-builder/__snapshots__/message-builder.spec.ts.snap +0 -270
- package/src/message-builder/message-builder.spec.ts +0 -24
- package/src/message-builder/message-builder.ts +0 -119
- package/src/message-composer/__snapshots__/message-composer.spec.ts.snap +0 -331
- package/src/message-composer/index.ts +0 -1
- package/src/message-composer/message-composer.spec.ts +0 -46
- package/src/message-composer/message-composer.ts +0 -262
- package/src/provider/__snapshots__/provider.spec.ts.snap +0 -49
- package/src/provider/index.ts +0 -1
- package/src/provider/provider.spec.ts +0 -81
- package/src/provider/provider.ts +0 -237
- package/src/react-query/__snapshots__/react-query.spec.ts.snap +0 -1359
- package/src/react-query/index.ts +0 -1
- package/src/react-query/react-query.spec.ts +0 -116
- package/src/react-query/react-query.ts +0 -1072
- package/src/recoil/__snapshots__/recoil.spec.ts.snap +0 -203
- package/src/recoil/index.ts +0 -1
- package/src/recoil/recoil.spec.ts +0 -38
- package/src/recoil/recoil.ts +0 -307
- package/src/types.ts +0 -44
- package/src/utils/__snapshots__/babel.spec.ts.snap +0 -75
- package/src/utils/babel.spec.ts +0 -511
- package/src/utils/babel.ts +0 -352
- package/src/utils/constants.ts +0 -37
- package/src/utils/ref.ts +0 -6
- package/src/utils/types.ts +0 -478
- package/types/types.d.ts +0 -41
- /package/{types/client → client}/index.d.ts +0 -0
- /package/{types/context → context}/index.d.ts +0 -0
- /package/{src/message-builder/index.ts → esm/message-builder/index.js} +0 -0
- /package/{types/message-composer/index.d.ts → esm/message-composer/index.js} +0 -0
- /package/{types/provider/index.d.ts → esm/provider/index.js} +0 -0
- /package/{types/react-query/index.d.ts → esm/react-query/index.js} +0 -0
- /package/{types/recoil/index.d.ts → esm/recoil/index.js} +0 -0
- /package/{src/utils/index.ts → esm/utils/index.js} +0 -0
- /package/{types/message-builder → message-builder}/index.d.ts +0 -0
- /package/{types/provider → provider}/provider.d.ts +0 -0
- /package/{types/utils → utils}/constants.d.ts +0 -0
- /package/{types/utils → utils}/index.d.ts +0 -0
@@ -0,0 +1,231 @@
|
|
1
|
+
import * as t from '@babel/types';
|
2
|
+
import { snake } from "case";
|
3
|
+
import { refLookup } from './ref';
|
4
|
+
// t.TSPropertySignature - kind?
|
5
|
+
export const propertySignature = (name, typeAnnotation, optional = false) => {
|
6
|
+
return {
|
7
|
+
type: 'TSPropertySignature',
|
8
|
+
key: t.identifier(name),
|
9
|
+
kind: 'get',
|
10
|
+
typeAnnotation,
|
11
|
+
optional
|
12
|
+
};
|
13
|
+
};
|
14
|
+
export const identifier = (name, typeAnnotation, optional = false) => {
|
15
|
+
const type = t.identifier(name);
|
16
|
+
type.typeAnnotation = typeAnnotation;
|
17
|
+
type.optional = optional;
|
18
|
+
return type;
|
19
|
+
};
|
20
|
+
export const tsTypeOperator = (typeAnnotation, operator) => {
|
21
|
+
const obj = t.tsTypeOperator(typeAnnotation);
|
22
|
+
obj.operator = operator;
|
23
|
+
return obj;
|
24
|
+
};
|
25
|
+
export const getMessageProperties = (msg) => {
|
26
|
+
let results = [];
|
27
|
+
let objs = [];
|
28
|
+
if (msg.anyOf) {
|
29
|
+
objs = msg.anyOf;
|
30
|
+
}
|
31
|
+
else if (msg.oneOf) {
|
32
|
+
objs = msg.oneOf;
|
33
|
+
}
|
34
|
+
else if (msg.allOf) {
|
35
|
+
objs = msg.allOf;
|
36
|
+
}
|
37
|
+
for (const obj of objs) {
|
38
|
+
if (obj.properties) {
|
39
|
+
results.push(obj);
|
40
|
+
}
|
41
|
+
else {
|
42
|
+
if (obj.$ref) {
|
43
|
+
const ref = refLookup(obj.$ref, msg);
|
44
|
+
const refProps = getMessageProperties(ref);
|
45
|
+
results = [...results, ...refProps];
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}
|
49
|
+
return results;
|
50
|
+
};
|
51
|
+
export const tsPropertySignature = (key, typeAnnotation, optional) => {
|
52
|
+
const obj = t.tsPropertySignature(key, typeAnnotation);
|
53
|
+
obj.optional = optional;
|
54
|
+
return obj;
|
55
|
+
};
|
56
|
+
export const tsObjectPattern = (properties, typeAnnotation) => {
|
57
|
+
const obj = t.objectPattern(properties);
|
58
|
+
obj.typeAnnotation = typeAnnotation;
|
59
|
+
return obj;
|
60
|
+
};
|
61
|
+
export const callExpression = (callee, _arguments, typeParameters) => {
|
62
|
+
const callExpr = t.callExpression(callee, _arguments);
|
63
|
+
callExpr.typeParameters = typeParameters;
|
64
|
+
return callExpr;
|
65
|
+
};
|
66
|
+
export const bindMethod = (name) => {
|
67
|
+
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')), [
|
68
|
+
t.thisExpression()
|
69
|
+
])));
|
70
|
+
};
|
71
|
+
export const typedIdentifier = (name, typeAnnotation, optional = false) => {
|
72
|
+
const type = t.identifier(name);
|
73
|
+
type.typeAnnotation = typeAnnotation;
|
74
|
+
type.optional = optional;
|
75
|
+
return type;
|
76
|
+
};
|
77
|
+
export const promiseTypeAnnotation = (name) => {
|
78
|
+
return t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Promise'), t.tsTypeParameterInstantiation([
|
79
|
+
t.tsTypeReference(t.identifier(name))
|
80
|
+
])));
|
81
|
+
};
|
82
|
+
export const abstractClassDeclaration = (name, body, implementsExressions = [], superClass = null) => {
|
83
|
+
const declaration = classDeclaration(name, body, implementsExressions, superClass);
|
84
|
+
declaration.abstract = true;
|
85
|
+
return declaration;
|
86
|
+
};
|
87
|
+
export const classDeclaration = (name, body, implementsExressions = [], superClass = null) => {
|
88
|
+
const declaration = t.classDeclaration(t.identifier(name), superClass, t.classBody(body));
|
89
|
+
if (implementsExressions.length) {
|
90
|
+
declaration.implements = implementsExressions;
|
91
|
+
}
|
92
|
+
return declaration;
|
93
|
+
};
|
94
|
+
export const classProperty = (name, typeAnnotation = null, isReadonly = false, isStatic = false, noImplicitOverride = false) => {
|
95
|
+
const prop = t.classProperty(t.identifier(name));
|
96
|
+
if (isReadonly)
|
97
|
+
prop.readonly = true;
|
98
|
+
if (isStatic)
|
99
|
+
prop.static = true;
|
100
|
+
if (typeAnnotation)
|
101
|
+
prop.typeAnnotation = typeAnnotation;
|
102
|
+
if (noImplicitOverride)
|
103
|
+
prop.override = true;
|
104
|
+
return prop;
|
105
|
+
};
|
106
|
+
export const arrowFunctionExpression = (params, body, returnType, isAsync = false) => {
|
107
|
+
const func = t.arrowFunctionExpression(params, body, isAsync);
|
108
|
+
if (returnType)
|
109
|
+
func.returnType = returnType;
|
110
|
+
return func;
|
111
|
+
};
|
112
|
+
export const recursiveNamespace = (names, moduleBlockBody) => {
|
113
|
+
if (!names || !names.length)
|
114
|
+
return moduleBlockBody;
|
115
|
+
const name = names.pop();
|
116
|
+
const body = [
|
117
|
+
t.exportNamedDeclaration(t.tsModuleDeclaration(t.identifier(name), t.tsModuleBlock(recursiveNamespace(names, moduleBlockBody))))
|
118
|
+
];
|
119
|
+
return body;
|
120
|
+
};
|
121
|
+
export const arrayTypeNDimensions = (body, n) => {
|
122
|
+
if (!n)
|
123
|
+
return t.tsArrayType(body);
|
124
|
+
return t.tsArrayType(arrayTypeNDimensions(body, n - 1));
|
125
|
+
};
|
126
|
+
export const FieldTypeAsts = {
|
127
|
+
string: () => {
|
128
|
+
return t.tsStringKeyword();
|
129
|
+
},
|
130
|
+
array: (type) => {
|
131
|
+
const result = FieldTypeAsts[type]();
|
132
|
+
return t.tsArrayType(result);
|
133
|
+
},
|
134
|
+
Duration: () => {
|
135
|
+
return t.tsTypeReference(t.identifier('Duration'));
|
136
|
+
},
|
137
|
+
Height: () => {
|
138
|
+
return t.tsTypeReference(t.identifier('Height'));
|
139
|
+
},
|
140
|
+
Coin: () => {
|
141
|
+
return t.tsTypeReference(t.identifier('Coin'));
|
142
|
+
},
|
143
|
+
Long: () => {
|
144
|
+
return t.tsTypeReference(t.identifier('Long'));
|
145
|
+
}
|
146
|
+
};
|
147
|
+
export const shorthandProperty = (prop) => {
|
148
|
+
return t.objectProperty(t.identifier(prop), t.identifier(prop), false, true);
|
149
|
+
};
|
150
|
+
export const importStmt = (names, path) => {
|
151
|
+
return t.importDeclaration(names.map(name => t.importSpecifier(t.identifier(name), t.identifier(name))), t.stringLiteral(path));
|
152
|
+
};
|
153
|
+
export const importAs = (name, importAs, importPath) => {
|
154
|
+
return t.importDeclaration([
|
155
|
+
t.importSpecifier(t.identifier(importAs), t.identifier(name))
|
156
|
+
], t.stringLiteral(importPath));
|
157
|
+
};
|
158
|
+
export const importAminoMsg = () => {
|
159
|
+
return importStmt(['AminoMsg'], '@cosmjs/amino');
|
160
|
+
};
|
161
|
+
export const getFieldDimensionality = (field) => {
|
162
|
+
let typeName = field.type;
|
163
|
+
const isArray = typeName.endsWith('[]');
|
164
|
+
let dimensions = 0;
|
165
|
+
if (isArray) {
|
166
|
+
dimensions = typeName.match(/\[\]/g).length - 1;
|
167
|
+
typeName = typeName.replace(/\[\]/g, '');
|
168
|
+
}
|
169
|
+
return {
|
170
|
+
typeName,
|
171
|
+
dimensions,
|
172
|
+
isArray
|
173
|
+
};
|
174
|
+
};
|
175
|
+
export const memberExpressionOrIdentifier = (names) => {
|
176
|
+
if (names.length === 1) {
|
177
|
+
return t.identifier(names[0]);
|
178
|
+
}
|
179
|
+
if (names.length === 2) {
|
180
|
+
const [b, a] = names;
|
181
|
+
return t.memberExpression(t.identifier(a), t.identifier(b));
|
182
|
+
}
|
183
|
+
const [name, ...rest] = names;
|
184
|
+
return t.memberExpression(memberExpressionOrIdentifier(rest), t.identifier(name));
|
185
|
+
};
|
186
|
+
export const memberExpressionOrIdentifierSnake = (names) => {
|
187
|
+
if (names.length === 1) {
|
188
|
+
return t.identifier(snake(names[0]));
|
189
|
+
}
|
190
|
+
if (names.length === 2) {
|
191
|
+
const [b, a] = names;
|
192
|
+
return t.memberExpression(t.identifier(snake(a)), t.identifier(snake(b)));
|
193
|
+
}
|
194
|
+
const [name, ...rest] = names;
|
195
|
+
return t.memberExpression(memberExpressionOrIdentifierSnake(rest), t.identifier(snake(name)));
|
196
|
+
};
|
197
|
+
/**
|
198
|
+
* If optional, return a conditional, otherwise just the expression
|
199
|
+
*/
|
200
|
+
export const optionalConditionalExpression = (test, expression, alternate, optional = false) => {
|
201
|
+
return optional
|
202
|
+
? t.conditionalExpression(test, expression, alternate)
|
203
|
+
: expression;
|
204
|
+
};
|
205
|
+
export const typeRefOrUnionWithUndefined = (identifier, optional = false) => {
|
206
|
+
const typeReference = t.tsTypeReference(identifier);
|
207
|
+
return optional
|
208
|
+
? t.tsUnionType([
|
209
|
+
typeReference,
|
210
|
+
t.tsUndefinedKeyword()
|
211
|
+
])
|
212
|
+
: typeReference;
|
213
|
+
};
|
214
|
+
export const parameterizedTypeReference = (identifier, from, omit) => {
|
215
|
+
return t.tsTypeReference(t.identifier(identifier), t.tsTypeParameterInstantiation([
|
216
|
+
from,
|
217
|
+
typeof omit === 'string'
|
218
|
+
? t.tsLiteralType(t.stringLiteral(omit))
|
219
|
+
: t.tsUnionType(omit.map(o => t.tsLiteralType(t.stringLiteral(o))))
|
220
|
+
]));
|
221
|
+
};
|
222
|
+
/**
|
223
|
+
* omitTypeReference(t.tsTypeReference(t.identifier('Cw4UpdateMembersMutation'),),'args').....
|
224
|
+
* Omit<Cw4UpdateMembersMutation, 'args'>
|
225
|
+
*/
|
226
|
+
export const omitTypeReference = (from, omit) => {
|
227
|
+
return parameterizedTypeReference('Omit', from, omit);
|
228
|
+
};
|
229
|
+
export const pickTypeReference = (from, pick) => {
|
230
|
+
return parameterizedTypeReference('Pick', from, pick);
|
231
|
+
};
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { identifier } from './babel';
|
2
|
+
import * as t from '@babel/types';
|
3
|
+
export const OPTIONAL_FUNDS_PARAM = identifier('_funds', t.tsTypeAnnotation(t.tsArrayType(t.tsTypeReference(t.identifier('Coin')))), true);
|
4
|
+
export const OPTIONAL_FEE_PARAM = identifier('fee', t.tsTypeAnnotation(t.tsUnionType([
|
5
|
+
t.tsNumberKeyword(),
|
6
|
+
t.tsTypeReference(t.identifier('StdFee')),
|
7
|
+
t.tsLiteralType(t.stringLiteral('auto'))
|
8
|
+
])), true);
|
9
|
+
export const OPTIONAL_MEMO_PARAM = identifier('memo', t.tsTypeAnnotation(t.tsStringKeyword()), true);
|
10
|
+
export const FIXED_EXECUTE_PARAMS = [
|
11
|
+
OPTIONAL_FEE_PARAM,
|
12
|
+
OPTIONAL_MEMO_PARAM,
|
13
|
+
OPTIONAL_FUNDS_PARAM
|
14
|
+
];
|
15
|
+
export const PROVIDER_TYPES = {
|
16
|
+
SIGNING_CLIENT_TYPE: "client",
|
17
|
+
QUERY_CLIENT_TYPE: "queryClient",
|
18
|
+
MESSAGE_COMPOSER_TYPE: 'message-composer',
|
19
|
+
PROVIDER_TYPE: 'provider'
|
20
|
+
};
|
package/esm/utils/ref.js
ADDED
@@ -0,0 +1,343 @@
|
|
1
|
+
import * as t from '@babel/types';
|
2
|
+
import { camel, pascal } from 'case';
|
3
|
+
import { propertySignature } from './babel';
|
4
|
+
export function getResponseType(context, underscoreName) {
|
5
|
+
const methodName = camel(underscoreName);
|
6
|
+
return pascal(context.contract?.responses?.[underscoreName]?.title
|
7
|
+
??
|
8
|
+
// after v1.1 is adopted, we can deprecate this and require the above response
|
9
|
+
`${methodName}Response`);
|
10
|
+
}
|
11
|
+
;
|
12
|
+
const getTypeStrFromRef = ($ref) => {
|
13
|
+
if ($ref?.startsWith('#/definitions/')) {
|
14
|
+
return $ref.replace('#/definitions/', '');
|
15
|
+
}
|
16
|
+
throw new Error('what is $ref: ' + $ref);
|
17
|
+
};
|
18
|
+
export const getTypeFromRef = ($ref) => {
|
19
|
+
return t.tsTypeReference(t.identifier(getTypeStrFromRef($ref)));
|
20
|
+
};
|
21
|
+
const getArrayTypeFromRef = ($ref) => {
|
22
|
+
return t.tsArrayType(getTypeFromRef($ref));
|
23
|
+
};
|
24
|
+
export const getTypeOrRef = (obj) => {
|
25
|
+
if (obj.$ref) {
|
26
|
+
return getTypeFromRef(obj.$ref);
|
27
|
+
}
|
28
|
+
else if (typeof obj.type === 'string') {
|
29
|
+
return getType(obj.type);
|
30
|
+
}
|
31
|
+
else if (Array.isArray(obj.type)) {
|
32
|
+
// Handle array of types by creating a union type
|
33
|
+
const types = obj.type.map(t => getType(t));
|
34
|
+
return t.tsUnionType(types);
|
35
|
+
}
|
36
|
+
else {
|
37
|
+
throw new Error('Type definition not supported or missing: ' + JSON.stringify(obj));
|
38
|
+
}
|
39
|
+
};
|
40
|
+
const getArrayTypeFromItems = (context, items) => {
|
41
|
+
if (Array.isArray(items)) {
|
42
|
+
// if (context.options.types.itemsUseTuples === true) {
|
43
|
+
// Using the modified method with tsTupleType
|
44
|
+
// return t.tsArrayType(
|
45
|
+
// t.tsTupleType(items.map(item => getTypeOrRef(item)))
|
46
|
+
// );
|
47
|
+
// } else {
|
48
|
+
// Using the original method with nested arrays
|
49
|
+
if (items.length > 0 && items[0].type === 'array') {
|
50
|
+
return getArrayTypeFromItems(context, items[0]);
|
51
|
+
}
|
52
|
+
return items.length > 0 ? t.tsArrayType(t.tsArrayType(getTypeOrRef(items[0]))) : t.tsArrayType(t.tsArrayType(t.tsAnyKeyword()));
|
53
|
+
// }
|
54
|
+
}
|
55
|
+
else {
|
56
|
+
const detect = detectType(items.type);
|
57
|
+
if (detect.type === 'array') {
|
58
|
+
if (Array.isArray(items.items)) {
|
59
|
+
return t.tsArrayType(t.tsArrayType(getTypeOrRef(items.items[0])));
|
60
|
+
}
|
61
|
+
else if (items.items) {
|
62
|
+
return t.tsArrayType(getArrayTypeFromItems(context, items.items));
|
63
|
+
}
|
64
|
+
else {
|
65
|
+
// Handle the case where items.items is undefined for array types
|
66
|
+
return t.tsArrayType(t.tsAnyKeyword());
|
67
|
+
}
|
68
|
+
}
|
69
|
+
return t.tsArrayType(getType(detect.type));
|
70
|
+
}
|
71
|
+
};
|
72
|
+
export const detectType = (type) => {
|
73
|
+
let optional = false;
|
74
|
+
let theType = '';
|
75
|
+
if (Array.isArray(type)) {
|
76
|
+
if (type.length !== 2) {
|
77
|
+
throw new Error('[getType(array length)] case not handled by transpiler. contact maintainers.');
|
78
|
+
}
|
79
|
+
const [nullableType, nullType] = type;
|
80
|
+
if (nullType !== 'null') {
|
81
|
+
throw new Error('[getType(null)] case not handled by transpiler. contact maintainers.');
|
82
|
+
}
|
83
|
+
theType = nullableType;
|
84
|
+
optional = true;
|
85
|
+
}
|
86
|
+
else {
|
87
|
+
theType = type;
|
88
|
+
}
|
89
|
+
return {
|
90
|
+
type: theType,
|
91
|
+
optional
|
92
|
+
};
|
93
|
+
};
|
94
|
+
export const getTypeInfo = (context, info) => {
|
95
|
+
let type = undefined;
|
96
|
+
let optional = undefined;
|
97
|
+
// Handle nullable types using 'anyOf' schema
|
98
|
+
if (Array.isArray(info.anyOf)) {
|
99
|
+
if (info.anyOf.length !== 2) {
|
100
|
+
throw new Error('case not handled by transpiler. contact maintainers.');
|
101
|
+
}
|
102
|
+
const [nullableType, nullType] = info.anyOf;
|
103
|
+
if (nullType?.type !== 'null') {
|
104
|
+
throw new Error('[nullableType.type]: case not handled by transpiler. contact maintainers.');
|
105
|
+
}
|
106
|
+
if (!nullableType?.$ref) {
|
107
|
+
if (nullableType.title) {
|
108
|
+
type = t.tsTypeReference(t.identifier(nullableType.title));
|
109
|
+
}
|
110
|
+
else {
|
111
|
+
throw new Error('[nullableType.title] case not handled by transpiler. contact maintainers.');
|
112
|
+
}
|
113
|
+
}
|
114
|
+
else {
|
115
|
+
type = getTypeFromRef(nullableType.$ref);
|
116
|
+
}
|
117
|
+
optional = true;
|
118
|
+
}
|
119
|
+
else if (typeof info.type === 'string') {
|
120
|
+
// Process type when it's explicitly defined
|
121
|
+
if (info.type === 'array') {
|
122
|
+
if (typeof info.items === 'object' && !Array.isArray(info.items)) {
|
123
|
+
if (info.items.$ref) {
|
124
|
+
type = getArrayTypeFromRef(info.items.$ref);
|
125
|
+
}
|
126
|
+
else if (info.items.title) {
|
127
|
+
type = t.tsArrayType(t.tsTypeReference(t.identifier(info.items.title)));
|
128
|
+
}
|
129
|
+
else if (info.items.type) {
|
130
|
+
type = getArrayTypeFromItems(context, info.items);
|
131
|
+
}
|
132
|
+
else {
|
133
|
+
throw new Error('[info.items] case not handled by transpiler. contact maintainers.');
|
134
|
+
}
|
135
|
+
// type = getArrayTypeFromItems(context, info.items);
|
136
|
+
}
|
137
|
+
else {
|
138
|
+
if (Array.isArray(info.items)) {
|
139
|
+
type = getArrayTypeFromItems(context, info.items);
|
140
|
+
}
|
141
|
+
else {
|
142
|
+
throw new Error('[info.items] case not handled by transpiler. contact maintainers.');
|
143
|
+
}
|
144
|
+
}
|
145
|
+
}
|
146
|
+
else {
|
147
|
+
const detect = detectType(info.type);
|
148
|
+
type = getType(detect.type);
|
149
|
+
optional = detect.optional;
|
150
|
+
}
|
151
|
+
}
|
152
|
+
else if (Array.isArray(info.type)) {
|
153
|
+
// Handle multiple types, typically nullable types
|
154
|
+
if (info.type.length !== 2) {
|
155
|
+
throw new Error('please report this to maintainers (field type): ' + JSON.stringify(info, null, 2));
|
156
|
+
}
|
157
|
+
const [nullableType, nullType] = info.type;
|
158
|
+
if (nullType !== 'null') {
|
159
|
+
throw new Error('please report this to maintainers (field type): ' + JSON.stringify(info, null, 2));
|
160
|
+
}
|
161
|
+
if (nullableType === 'array' && typeof info.items === 'object' && !Array.isArray(info.items)) {
|
162
|
+
if (info.items.type) {
|
163
|
+
const detect = detectType(info.items.type);
|
164
|
+
if (detect.type === 'array') {
|
165
|
+
type = t.tsArrayType(getArrayTypeFromItems(context, info.items));
|
166
|
+
}
|
167
|
+
else {
|
168
|
+
type = t.tsArrayType(getType(detect.type));
|
169
|
+
}
|
170
|
+
optional = detect.optional;
|
171
|
+
}
|
172
|
+
else if (info.items.$ref) {
|
173
|
+
type = getArrayTypeFromRef(info.items.$ref);
|
174
|
+
}
|
175
|
+
else if (info.items.type) {
|
176
|
+
type = getArrayTypeFromItems(context, info.items);
|
177
|
+
}
|
178
|
+
else {
|
179
|
+
throw new Error('[info.items] case not handled by transpiler. contact maintainers.');
|
180
|
+
}
|
181
|
+
}
|
182
|
+
else {
|
183
|
+
const detect = detectType(nullableType);
|
184
|
+
optional = detect.optional;
|
185
|
+
if (detect.type === 'array') {
|
186
|
+
type = getArrayTypeFromItems(context, info.items);
|
187
|
+
}
|
188
|
+
else {
|
189
|
+
type = getType(detect.type);
|
190
|
+
}
|
191
|
+
}
|
192
|
+
optional = true; // Ensure optional is set for nullable types
|
193
|
+
}
|
194
|
+
return {
|
195
|
+
type,
|
196
|
+
optional
|
197
|
+
};
|
198
|
+
};
|
199
|
+
export const getType = (type) => {
|
200
|
+
switch (type) {
|
201
|
+
case 'string':
|
202
|
+
return t.tsStringKeyword();
|
203
|
+
case 'boolean':
|
204
|
+
return t.tSBooleanKeyword();
|
205
|
+
case 'integer':
|
206
|
+
return t.tsNumberKeyword();
|
207
|
+
case 'null':
|
208
|
+
return t.tsNullKeyword();
|
209
|
+
case 'number':
|
210
|
+
return t.tsNumberKeyword();
|
211
|
+
default:
|
212
|
+
throw new Error('contact maintainers [unknown type]: ' + type);
|
213
|
+
}
|
214
|
+
};
|
215
|
+
export const getPropertyType = (context, schema, prop) => {
|
216
|
+
const props = schema.properties ?? {};
|
217
|
+
let info = props[prop];
|
218
|
+
let type = null;
|
219
|
+
let optional = !schema.required?.includes(prop);
|
220
|
+
if (info.allOf && info.allOf.length === 1) {
|
221
|
+
info = info.allOf[0];
|
222
|
+
}
|
223
|
+
if (typeof info.$ref === 'string') {
|
224
|
+
type = getTypeFromRef(info.$ref);
|
225
|
+
}
|
226
|
+
const typeInfo = getTypeInfo(context, info);
|
227
|
+
if (typeof typeInfo.optional !== 'undefined') {
|
228
|
+
optional = typeInfo.optional;
|
229
|
+
}
|
230
|
+
if (typeof typeInfo.type !== 'undefined') {
|
231
|
+
type = typeInfo.type;
|
232
|
+
}
|
233
|
+
if (!type) {
|
234
|
+
throw new Error('cannot find type for ' + JSON.stringify(info));
|
235
|
+
}
|
236
|
+
if (schema.required?.includes(prop)) {
|
237
|
+
optional = false;
|
238
|
+
}
|
239
|
+
return { type, optional };
|
240
|
+
};
|
241
|
+
export function getPropertySignatureFromProp(context, jsonschema, prop, camelize) {
|
242
|
+
if (jsonschema.properties[prop].type === 'object') {
|
243
|
+
if (jsonschema.properties[prop].title) {
|
244
|
+
return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(jsonschema.properties[prop].title))));
|
245
|
+
}
|
246
|
+
else {
|
247
|
+
throw new Error('getPropertySignatureFromProp() contact maintainer');
|
248
|
+
}
|
249
|
+
}
|
250
|
+
if (Array.isArray(jsonschema.properties[prop].allOf)) {
|
251
|
+
const isOptional = !jsonschema.required?.includes(prop);
|
252
|
+
const unionTypes = jsonschema.properties[prop].allOf.map(el => {
|
253
|
+
if (el.title)
|
254
|
+
return el.title;
|
255
|
+
if (el.$ref)
|
256
|
+
return getTypeStrFromRef(el.$ref);
|
257
|
+
return el.type;
|
258
|
+
}).filter(a => typeof a === 'string');
|
259
|
+
// ONLY SUPPORT string types for now!
|
260
|
+
// e.g. NOT supporting nullable types or type: string[] yet
|
261
|
+
// @ts-ignore:next-line
|
262
|
+
const uniqUnionTypes = [...new Set(unionTypes)];
|
263
|
+
if (uniqUnionTypes.length === 1) {
|
264
|
+
return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(uniqUnionTypes[0]))), isOptional);
|
265
|
+
}
|
266
|
+
else {
|
267
|
+
return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(t.tsUnionType(uniqUnionTypes.map(typ => t.tsTypeReference(t.identifier(typ))))), isOptional);
|
268
|
+
}
|
269
|
+
}
|
270
|
+
else if (Array.isArray(jsonschema.properties[prop].oneOf)) {
|
271
|
+
const isOptional = !jsonschema.required?.includes(prop);
|
272
|
+
const unionTypes = jsonschema.properties[prop].oneOf.map(el => {
|
273
|
+
if (el.title)
|
274
|
+
return el.title;
|
275
|
+
if (el.$ref)
|
276
|
+
return getTypeStrFromRef(el.$ref);
|
277
|
+
return el.type;
|
278
|
+
}).filter(a => typeof a === 'string');
|
279
|
+
// ONLY SUPPORT string types for now!
|
280
|
+
// e.g. NOT supporting nullable types or type: string[] yet
|
281
|
+
const uniqUnionTypes = [...new Set(unionTypes)];
|
282
|
+
if (uniqUnionTypes.length === 1) {
|
283
|
+
return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(t.tsTypeReference(t.identifier(uniqUnionTypes[0]))), isOptional);
|
284
|
+
}
|
285
|
+
else {
|
286
|
+
return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(t.tsUnionType(uniqUnionTypes.map(typ => t.tsTypeReference(t.identifier(typ))))), isOptional);
|
287
|
+
}
|
288
|
+
}
|
289
|
+
try {
|
290
|
+
getPropertyType(context, jsonschema, prop);
|
291
|
+
}
|
292
|
+
catch (e) {
|
293
|
+
console.log(e);
|
294
|
+
console.log(JSON.stringify(jsonschema, null, 2), prop);
|
295
|
+
}
|
296
|
+
const { type, optional } = getPropertyType(context, jsonschema, prop);
|
297
|
+
return propertySignature(camelize ? camel(prop) : prop, t.tsTypeAnnotation(type), optional);
|
298
|
+
}
|
299
|
+
export const getParamsTypeAnnotation = (context, jsonschema, camelize = true) => {
|
300
|
+
const keys = Object.keys(jsonschema.properties ?? {});
|
301
|
+
if (!keys.length && jsonschema.$ref) {
|
302
|
+
return t.tsTypeAnnotation(getTypeFromRef(jsonschema.$ref));
|
303
|
+
}
|
304
|
+
if (!keys.length)
|
305
|
+
return undefined;
|
306
|
+
const typedParams = keys.map(prop => getPropertySignatureFromProp(context, jsonschema, prop, camelize));
|
307
|
+
return t.tsTypeAnnotation(t.tsTypeLiteral(
|
308
|
+
// @ts-ignore:next-line
|
309
|
+
[
|
310
|
+
...typedParams
|
311
|
+
]));
|
312
|
+
};
|
313
|
+
export const createTypedObjectParams = (context, jsonschema, camelize = true) => {
|
314
|
+
const keys = Object.keys(jsonschema.properties ?? {});
|
315
|
+
if (!keys.length) {
|
316
|
+
// is there a ref?
|
317
|
+
if (jsonschema.$ref) {
|
318
|
+
const obj = context.refLookup(jsonschema.$ref);
|
319
|
+
// If there is a oneOf, then we need to create a type for it
|
320
|
+
if (obj?.oneOf) {
|
321
|
+
// the actual type of the ref
|
322
|
+
const refType = jsonschema.$ref.split('/').pop();
|
323
|
+
const refName = camel(refType);
|
324
|
+
const id = t.identifier(refName);
|
325
|
+
id.typeAnnotation = t.tsTypeAnnotation(t.tsTypeReference(t.identifier(refType)));
|
326
|
+
return id;
|
327
|
+
}
|
328
|
+
else if (obj) {
|
329
|
+
return createTypedObjectParams(context, obj, camelize);
|
330
|
+
}
|
331
|
+
}
|
332
|
+
// no results...
|
333
|
+
return;
|
334
|
+
}
|
335
|
+
const params = keys.map(prop => {
|
336
|
+
return t.objectProperty(camelize ? t.identifier(camel(prop)) : t.identifier(prop), camelize ? t.identifier(camel(prop)) : t.identifier(prop), false, true);
|
337
|
+
});
|
338
|
+
const obj = t.objectPattern([
|
339
|
+
...params
|
340
|
+
]);
|
341
|
+
obj.typeAnnotation = getParamsTypeAnnotation(context, jsonschema, camelize);
|
342
|
+
return obj;
|
343
|
+
};
|
package/index.js
ADDED
@@ -0,0 +1,24 @@
|
|
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("./utils"), exports);
|
18
|
+
__exportStar(require("./client"), exports);
|
19
|
+
__exportStar(require("./context"), exports);
|
20
|
+
__exportStar(require("./recoil"), exports);
|
21
|
+
__exportStar(require("./message-composer"), exports);
|
22
|
+
__exportStar(require("./react-query"), exports);
|
23
|
+
__exportStar(require("./message-builder"), exports);
|
24
|
+
__exportStar(require("./provider"), exports);
|
@@ -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-builder"), exports);
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import * as t from '@babel/types';
|
2
|
-
import { ExecuteMsg, QueryMsg } from '
|
2
|
+
import { ExecuteMsg, QueryMsg } from '@cosmology/ts-codegen-types';
|
3
3
|
import { RenderContext } from '../context';
|
4
4
|
export declare const createMessageBuilderClass: (context: RenderContext, className: string, msg: ExecuteMsg | QueryMsg) => t.ExportNamedDeclaration;
|