@dedot/codegen 0.0.1-next.ce93b605.2 → 0.0.1-next.cfee875e.21
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/{generator → chaintypes/generator}/ApiGen.d.ts +1 -1
- package/chaintypes/generator/ConstsGen.d.ts +4 -0
- package/{generator → chaintypes/generator}/ConstsGen.js +8 -9
- package/chaintypes/generator/ErrorsGen.d.ts +5 -0
- package/{generator → chaintypes/generator}/ErrorsGen.js +9 -10
- package/chaintypes/generator/EventsGen.d.ts +5 -0
- package/{generator → chaintypes/generator}/EventsGen.js +9 -10
- package/chaintypes/generator/IndexGen.d.ts +5 -0
- package/chaintypes/generator/IndexGen.js +17 -0
- package/chaintypes/generator/JsonRpcGen.d.ts +8 -0
- package/chaintypes/generator/JsonRpcGen.js +55 -0
- package/chaintypes/generator/QueryGen.d.ts +5 -0
- package/{generator → chaintypes/generator}/QueryGen.js +24 -16
- package/chaintypes/generator/RuntimeApisGen.d.ts +9 -0
- package/{generator → chaintypes/generator}/RuntimeApisGen.js +98 -24
- package/chaintypes/generator/TxGen.d.ts +5 -0
- package/{generator → chaintypes/generator}/TxGen.js +14 -12
- package/chaintypes/generator/TypesGen.d.ts +11 -0
- package/chaintypes/generator/TypesGen.js +55 -0
- package/chaintypes/generator/index.d.ts +10 -0
- package/chaintypes/generator/index.js +10 -0
- package/chaintypes/index.d.ts +3 -0
- package/chaintypes/index.js +49 -0
- package/chaintypes/templates/consts.hbs +7 -0
- package/chaintypes/templates/errors.hbs +7 -0
- package/chaintypes/templates/events.hbs +7 -0
- package/chaintypes/templates/index.hbs +27 -0
- package/chaintypes/templates/json-rpc.hbs +5 -0
- package/chaintypes/templates/query.hbs +7 -0
- package/chaintypes/templates/runtime.hbs +8 -0
- package/chaintypes/templates/tx.hbs +9 -0
- package/{cjs → chaintypes}/templates/types.hbs +1 -1
- package/cjs/{generator → chaintypes/generator}/ConstsGen.js +12 -13
- package/cjs/chaintypes/generator/ErrorsGen.js +40 -0
- package/cjs/{generator → chaintypes/generator}/EventsGen.js +16 -17
- package/cjs/chaintypes/generator/IndexGen.js +21 -0
- package/cjs/chaintypes/generator/JsonRpcGen.js +59 -0
- package/cjs/{generator → chaintypes/generator}/QueryGen.js +26 -18
- package/cjs/chaintypes/generator/RuntimeApisGen.js +193 -0
- package/cjs/{generator → chaintypes/generator}/TxGen.js +23 -21
- package/cjs/chaintypes/generator/TypesGen.js +59 -0
- package/cjs/chaintypes/generator/index.js +26 -0
- package/cjs/chaintypes/index.js +77 -0
- package/cjs/chaintypes/templates/consts.hbs +7 -0
- package/cjs/chaintypes/templates/errors.hbs +7 -0
- package/cjs/chaintypes/templates/events.hbs +7 -0
- package/cjs/chaintypes/templates/index.hbs +27 -0
- package/cjs/chaintypes/templates/json-rpc.hbs +5 -0
- package/cjs/chaintypes/templates/query.hbs +7 -0
- package/cjs/chaintypes/templates/runtime.hbs +8 -0
- package/cjs/chaintypes/templates/tx.hbs +9 -0
- package/{templates → cjs/chaintypes/templates}/types.hbs +1 -1
- package/cjs/index.js +4 -62
- package/cjs/{generator/TypesGen.js → shared/BaseTypesGen.js} +102 -161
- package/cjs/{generator → shared}/TypeImports.js +29 -3
- package/cjs/{generator → shared}/index.js +3 -10
- package/cjs/{generator → shared}/known-codecs.js +24 -5
- package/cjs/typink/generator/ConstructorQueryGen.js +24 -0
- package/cjs/typink/generator/ConstructorTxGen.js +24 -0
- package/cjs/typink/generator/IndexGen.js +24 -0
- package/cjs/typink/generator/QueryGen.js +72 -0
- package/cjs/typink/generator/TxGen.js +25 -0
- package/cjs/typink/generator/TypesGen.js +35 -0
- package/cjs/typink/generator/index.js +22 -0
- package/cjs/typink/index.js +37 -0
- package/cjs/typink/templates/constructor-query.hbs +7 -0
- package/cjs/typink/templates/constructor-tx.hbs +7 -0
- package/cjs/typink/templates/index.hbs +14 -0
- package/cjs/typink/templates/query.hbs +7 -0
- package/cjs/typink/templates/tx.hbs +7 -0
- package/cjs/typink/templates/types.hbs +5 -0
- package/cjs/{generator/utils.js → utils.js} +34 -5
- package/index.d.ts +2 -4
- package/index.js +2 -48
- package/package.json +16 -19
- package/{generator/TypesGen.d.ts → shared/BaseTypesGen.d.ts} +13 -12
- package/{generator/TypesGen.js → shared/BaseTypesGen.js} +88 -147
- package/{generator → shared}/TypeImports.d.ts +12 -1
- package/{generator → shared}/TypeImports.js +29 -3
- package/shared/index.d.ts +3 -0
- package/shared/index.js +3 -0
- package/{generator → shared}/known-codecs.d.ts +1 -1
- package/{generator → shared}/known-codecs.js +22 -3
- package/typink/generator/ConstructorQueryGen.d.ts +6 -0
- package/typink/generator/ConstructorQueryGen.js +20 -0
- package/typink/generator/ConstructorTxGen.d.ts +6 -0
- package/typink/generator/ConstructorTxGen.js +20 -0
- package/typink/generator/IndexGen.d.ts +6 -0
- package/typink/generator/IndexGen.js +20 -0
- package/typink/generator/QueryGen.d.ts +12 -0
- package/typink/generator/QueryGen.js +68 -0
- package/typink/generator/TxGen.d.ts +6 -0
- package/typink/generator/TxGen.js +21 -0
- package/typink/generator/TypesGen.d.ts +8 -0
- package/typink/generator/TypesGen.js +31 -0
- package/typink/generator/index.d.ts +6 -0
- package/typink/generator/index.js +6 -0
- package/typink/index.d.ts +2 -0
- package/typink/index.js +30 -0
- package/typink/templates/constructor-query.hbs +7 -0
- package/typink/templates/constructor-tx.hbs +7 -0
- package/typink/templates/index.hbs +14 -0
- package/typink/templates/query.hbs +7 -0
- package/typink/templates/tx.hbs +7 -0
- package/typink/templates/types.hbs +5 -0
- package/{generator/utils.d.ts → utils.d.ts} +6 -1
- package/{generator/utils.js → utils.js} +32 -4
- package/cjs/genSupportedChainTypes.js +0 -83
- package/cjs/generator/ErrorsGen.js +0 -41
- package/cjs/generator/IndexGen.js +0 -18
- package/cjs/generator/RpcGen.js +0 -176
- package/cjs/generator/RuntimeApisGen.js +0 -119
- package/cjs/generator/known-types.js +0 -33
- package/cjs/packageInfo.js +0 -5
- package/cjs/templates/consts.hbs +0 -7
- package/cjs/templates/errors.hbs +0 -7
- package/cjs/templates/events.hbs +0 -7
- package/cjs/templates/index.hbs +0 -22
- package/cjs/templates/query.hbs +0 -7
- package/cjs/templates/rpc.hbs +0 -7
- package/cjs/templates/runtime.hbs +0 -8
- package/cjs/templates/tx.hbs +0 -9
- package/cjs/types.js +0 -2
- package/genSupportedChainTypes.d.ts +0 -1
- package/genSupportedChainTypes.js +0 -78
- package/generator/ConstsGen.d.ts +0 -4
- package/generator/ErrorsGen.d.ts +0 -5
- package/generator/EventsGen.d.ts +0 -5
- package/generator/IndexGen.d.ts +0 -6
- package/generator/IndexGen.js +0 -14
- package/generator/QueryGen.d.ts +0 -5
- package/generator/RpcGen.d.ts +0 -10
- package/generator/RpcGen.js +0 -172
- package/generator/RuntimeApisGen.d.ts +0 -9
- package/generator/TxGen.d.ts +0 -5
- package/generator/index.d.ts +0 -10
- package/generator/index.js +0 -10
- package/generator/known-types.d.ts +0 -6
- package/generator/known-types.js +0 -30
- package/packageInfo.d.ts +0 -4
- package/packageInfo.js +0 -2
- package/templates/consts.hbs +0 -7
- package/templates/errors.hbs +0 -7
- package/templates/events.hbs +0 -7
- package/templates/index.hbs +0 -22
- package/templates/query.hbs +0 -7
- package/templates/rpc.hbs +0 -7
- package/templates/runtime.hbs +0 -8
- package/templates/tx.hbs +0 -9
- package/types.d.ts +0 -6
- package/types.js +0 -1
- /package/{generator → chaintypes/generator}/ApiGen.js +0 -0
- /package/cjs/{generator → chaintypes/generator}/ApiGen.js +0 -0
- /package/cjs/{generator/dirname.js → dirname.js} +0 -0
- /package/{generator/dirname.d.ts → dirname.d.ts} +0 -0
- /package/{generator/dirname.js → dirname.js} +0 -0
|
@@ -1,70 +1,93 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const util_1 = require("@polkadot/util");
|
|
5
|
-
const codecs_1 = require("@dedot/codecs");
|
|
3
|
+
exports.BaseTypesGen = exports.BASIC_KNOWN_TYPES = void 0;
|
|
6
4
|
const utils_1 = require("@dedot/utils");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const known_codecs_1 = require("./known-codecs");
|
|
11
|
-
// Skip generate types for these
|
|
12
|
-
// as we do have native types for them
|
|
13
|
-
const SKIP_TYPES = [
|
|
14
|
-
'BoundedBTreeMap',
|
|
15
|
-
'BoundedBTreeSet',
|
|
16
|
-
'BoundedVec',
|
|
17
|
-
'Box',
|
|
18
|
-
'BTreeMap',
|
|
19
|
-
'BTreeSet',
|
|
20
|
-
'Cow',
|
|
21
|
-
'Option',
|
|
22
|
-
'Range',
|
|
23
|
-
'RangeInclusive',
|
|
24
|
-
'Result',
|
|
25
|
-
'WeakBoundedVec',
|
|
26
|
-
'WrapperKeepOpaque',
|
|
27
|
-
'WrapperOpaque',
|
|
28
|
-
];
|
|
5
|
+
const utils_js_1 = require("../utils.js");
|
|
6
|
+
const TypeImports_js_1 = require("./TypeImports.js");
|
|
7
|
+
const known_codecs_js_1 = require("./known-codecs.js");
|
|
29
8
|
// These are common & generic types, so we'll remove these from all paths at index 1
|
|
30
9
|
// This helps make the type name shorter
|
|
31
10
|
const PATH_RM_INDEX_1 = ['generic', 'misc', 'pallet', 'traits', 'types'];
|
|
32
11
|
exports.BASIC_KNOWN_TYPES = ['BitSequence', 'Bytes', 'BytesLike', 'FixedBytes', 'FixedArray', 'Result'];
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
metadata;
|
|
36
|
-
/**
|
|
37
|
-
* Types will be generated its definition out.
|
|
38
|
-
*/
|
|
12
|
+
class BaseTypesGen {
|
|
13
|
+
types;
|
|
39
14
|
includedTypes;
|
|
40
|
-
registry;
|
|
41
15
|
typeImports;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
this.
|
|
45
|
-
this.includedTypes =
|
|
46
|
-
this.typeImports = new
|
|
47
|
-
|
|
48
|
-
generate() {
|
|
49
|
-
this.clearCache();
|
|
50
|
-
let defTypeOut = '';
|
|
51
|
-
Object.values(this.includedTypes)
|
|
52
|
-
.filter(({ skip, knownType }) => !(skip || knownType))
|
|
53
|
-
.forEach(({ name, nameOut, id, docs }) => {
|
|
54
|
-
defTypeOut += `${(0, utils_2.commentBlock)(docs)}export type ${nameOut} = ${this.generateType(id, 0, true)};\n\n`;
|
|
55
|
-
if (this.#shouldGenerateTypeIn(id)) {
|
|
56
|
-
defTypeOut += `export type ${name} = ${this.generateType(id)};\n\n`;
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
const importTypes = this.typeImports.toImports('./types');
|
|
60
|
-
const template = (0, utils_2.compileTemplate)('types.hbs');
|
|
61
|
-
return (0, utils_2.beautifySourceCode)(template({ importTypes, defTypeOut }));
|
|
16
|
+
skipTypes;
|
|
17
|
+
constructor(types) {
|
|
18
|
+
this.types = types;
|
|
19
|
+
this.includedTypes = {};
|
|
20
|
+
this.typeImports = new TypeImports_js_1.TypeImports();
|
|
21
|
+
this.skipTypes = [];
|
|
62
22
|
}
|
|
63
23
|
typeCache = {};
|
|
64
24
|
clearCache() {
|
|
65
25
|
this.typeCache = {};
|
|
66
26
|
this.typeImports.clear();
|
|
67
27
|
}
|
|
28
|
+
includeTypes() {
|
|
29
|
+
const pathsCount = new Map();
|
|
30
|
+
const typesWithPath = this.types.filter((one) => one.path.length > 0);
|
|
31
|
+
const skipIds = [];
|
|
32
|
+
const typeSuffixes = new Map();
|
|
33
|
+
typesWithPath.forEach(({ path, id }) => {
|
|
34
|
+
const joinedPath = path.join('::');
|
|
35
|
+
if (pathsCount.has(joinedPath)) {
|
|
36
|
+
// We compare 2 types with the same path here,
|
|
37
|
+
// if they are the same type -> skip the current one, keep the first occurrence
|
|
38
|
+
// if they are not the same type but has the same path -> we'll try to calculate & add a suffix for the current type name
|
|
39
|
+
const firstOccurrenceTypeId = pathsCount.get(joinedPath)[0];
|
|
40
|
+
const sameType = this.typeEql(firstOccurrenceTypeId, id);
|
|
41
|
+
if (sameType) {
|
|
42
|
+
skipIds.push(id);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
pathsCount.get(joinedPath).push(id);
|
|
46
|
+
typeSuffixes.set(id, this.extractDupTypeSuffix(id, firstOccurrenceTypeId, pathsCount.get(joinedPath).length));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
pathsCount.set(joinedPath, [id]);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
return typesWithPath.reduce((o, type) => {
|
|
54
|
+
const { path, id } = type;
|
|
55
|
+
const joinedPath = path.join('::');
|
|
56
|
+
if (this.skipTypes.includes(joinedPath) || this.skipTypes.includes(path.at(-1))) {
|
|
57
|
+
return o;
|
|
58
|
+
}
|
|
59
|
+
const suffix = typeSuffixes.get(id) || '';
|
|
60
|
+
let knownType = false;
|
|
61
|
+
let name, nameOut;
|
|
62
|
+
const [isKnownCodecType, codecName] = (0, known_codecs_js_1.checkKnownCodecType)(joinedPath);
|
|
63
|
+
if (isKnownCodecType) {
|
|
64
|
+
const codecType = (0, known_codecs_js_1.findKnownCodecType)(codecName);
|
|
65
|
+
name = codecType.typeIn;
|
|
66
|
+
nameOut = codecType.typeOut;
|
|
67
|
+
knownType = true;
|
|
68
|
+
}
|
|
69
|
+
else if (PATH_RM_INDEX_1.includes(path[1])) {
|
|
70
|
+
const newPath = path.slice();
|
|
71
|
+
newPath.splice(1, 1);
|
|
72
|
+
name = this.cleanPath(newPath);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
name = this.cleanPath(path);
|
|
76
|
+
}
|
|
77
|
+
if (this.shouldGenerateTypeIn(id)) {
|
|
78
|
+
nameOut = name;
|
|
79
|
+
name = name.endsWith('Like') ? name : `${name}Like`;
|
|
80
|
+
}
|
|
81
|
+
o[id] = {
|
|
82
|
+
name: `${name}${suffix}`,
|
|
83
|
+
nameOut: nameOut ? `${nameOut}${suffix}` : `${name}${suffix}`,
|
|
84
|
+
knownType,
|
|
85
|
+
skip: skipIds.includes(id),
|
|
86
|
+
...type,
|
|
87
|
+
};
|
|
88
|
+
return o;
|
|
89
|
+
}, {});
|
|
90
|
+
}
|
|
68
91
|
generateType(typeId, nestedLevel = 0, typeOut = false) {
|
|
69
92
|
if (nestedLevel > 0) {
|
|
70
93
|
const includedDef = this.includedTypes[typeId];
|
|
@@ -95,7 +118,7 @@ class TypesGen {
|
|
|
95
118
|
return type;
|
|
96
119
|
}
|
|
97
120
|
#generateType(typeId, nestedLevel = 0, typeOut = false) {
|
|
98
|
-
const def = this.
|
|
121
|
+
const def = this.types[typeId];
|
|
99
122
|
if (!def) {
|
|
100
123
|
throw new Error(`Type def not found ${JSON.stringify(def)}`);
|
|
101
124
|
}
|
|
@@ -103,7 +126,7 @@ class TypesGen {
|
|
|
103
126
|
const { tag, value } = type;
|
|
104
127
|
switch (tag) {
|
|
105
128
|
case 'Primitive':
|
|
106
|
-
const $codec = (0,
|
|
129
|
+
const $codec = (0, known_codecs_js_1.findKnownCodec)(value.kind);
|
|
107
130
|
if ($codec.nativeType) {
|
|
108
131
|
return $codec.nativeType;
|
|
109
132
|
}
|
|
@@ -151,12 +174,12 @@ class TypesGen {
|
|
|
151
174
|
return 'null';
|
|
152
175
|
}
|
|
153
176
|
else if (members.every((x) => x.fields.length === 0)) {
|
|
154
|
-
return members.map(({ name, docs }) => `${(0,
|
|
177
|
+
return members.map(({ name, docs }) => `${(0, utils_js_1.commentBlock)(docs)}'${(0, utils_1.stringPascalCase)(name)}'`).join(' | ');
|
|
155
178
|
}
|
|
156
179
|
else {
|
|
157
180
|
const membersType = [];
|
|
158
181
|
for (const { fields, name, docs } of members) {
|
|
159
|
-
const keyName = (0,
|
|
182
|
+
const keyName = (0, utils_1.stringPascalCase)(name);
|
|
160
183
|
if (fields.length === 0) {
|
|
161
184
|
membersType.push([keyName, null, docs]);
|
|
162
185
|
}
|
|
@@ -164,7 +187,7 @@ class TypesGen {
|
|
|
164
187
|
const valueType = fields.length === 1
|
|
165
188
|
? this.generateType(fields[0].typeId, nestedLevel + 1, typeOut)
|
|
166
189
|
: `[${fields
|
|
167
|
-
.map(({ typeId, docs }) => `${(0,
|
|
190
|
+
.map(({ typeId, docs }) => `${(0, utils_js_1.commentBlock)(docs)}${this.generateType(typeId, nestedLevel + 1, typeOut)}`)
|
|
168
191
|
.join(', ')}]`;
|
|
169
192
|
membersType.push([keyName, valueType, docs]);
|
|
170
193
|
}
|
|
@@ -172,14 +195,14 @@ class TypesGen {
|
|
|
172
195
|
membersType.push([keyName, this.generateObjectType(fields, nestedLevel + 1, typeOut), docs]);
|
|
173
196
|
}
|
|
174
197
|
}
|
|
175
|
-
const { tagKey, valueKey } = this.
|
|
198
|
+
const { tagKey, valueKey } = this.getEnumOptions(typeId);
|
|
176
199
|
return membersType
|
|
177
200
|
.map(([keyName, valueType, docs]) => ({
|
|
178
201
|
tag: `${tagKey}: '${keyName}'`,
|
|
179
202
|
value: valueType ? `, ${valueKey}${this.#isOptionalType(valueType) ? '?' : ''}: ${valueType} ` : '',
|
|
180
203
|
docs,
|
|
181
204
|
}))
|
|
182
|
-
.map(({ tag, value, docs }) => `${(0,
|
|
205
|
+
.map(({ tag, value, docs }) => `${(0, utils_js_1.commentBlock)(docs)}{ ${tag}${value} }`)
|
|
183
206
|
.join(' | ');
|
|
184
207
|
}
|
|
185
208
|
}
|
|
@@ -202,7 +225,7 @@ class TypesGen {
|
|
|
202
225
|
case 'Sequence':
|
|
203
226
|
case 'SizedVec': {
|
|
204
227
|
const fixedSize = tag === 'SizedVec' ? `${value.len}` : null;
|
|
205
|
-
const $innerType = this.
|
|
228
|
+
const $innerType = this.types[value.typeParam].type;
|
|
206
229
|
if ($innerType.tag === 'Primitive' && $innerType.value.kind === 'u8') {
|
|
207
230
|
return fixedSize ? `FixedBytes<${fixedSize}>` : typeOut ? 'Bytes' : 'BytesLike';
|
|
208
231
|
}
|
|
@@ -226,104 +249,26 @@ class TypesGen {
|
|
|
226
249
|
};
|
|
227
250
|
});
|
|
228
251
|
return `{${props
|
|
229
|
-
.map(({ name, type, optional, docs }) => `${(0,
|
|
252
|
+
.map(({ name, type, optional, docs }) => `${(0, utils_js_1.commentBlock)(docs)}${name}${optional ? '?' : ''}: ${type}`)
|
|
230
253
|
.join(',\n')}}`;
|
|
231
254
|
}
|
|
232
255
|
#isOptionalType(type) {
|
|
233
256
|
return type.endsWith('| undefined');
|
|
234
257
|
}
|
|
235
|
-
#includedTypes() {
|
|
236
|
-
const { types } = this.metadata;
|
|
237
|
-
const pathsCount = new Map();
|
|
238
|
-
const typesWithPath = types.filter((one) => one.path.length > 0);
|
|
239
|
-
const skipIds = [];
|
|
240
|
-
const typeSuffixes = new Map();
|
|
241
|
-
typesWithPath.forEach(({ path, id }) => {
|
|
242
|
-
const joinedPath = path.join('::');
|
|
243
|
-
if (pathsCount.has(joinedPath)) {
|
|
244
|
-
// We compare 2 types with the same path here,
|
|
245
|
-
// if they are the same type -> skip the current one, keep the first occurrence
|
|
246
|
-
// if they are not the same type but has the same path -> we'll try to calculate & add a suffix for the current type name
|
|
247
|
-
const firstOccurrenceTypeId = pathsCount.get(joinedPath)[0];
|
|
248
|
-
const sameType = this.typeEql(firstOccurrenceTypeId, id);
|
|
249
|
-
if (sameType) {
|
|
250
|
-
skipIds.push(id);
|
|
251
|
-
}
|
|
252
|
-
else {
|
|
253
|
-
pathsCount.get(joinedPath).push(id);
|
|
254
|
-
typeSuffixes.set(id, this.#extractDupTypeSuffix(id, firstOccurrenceTypeId, pathsCount.get(joinedPath).length));
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
else {
|
|
258
|
-
pathsCount.set(joinedPath, [id]);
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
return typesWithPath.reduce((o, type) => {
|
|
262
|
-
const { path, id } = type;
|
|
263
|
-
const joinedPath = path.join('::');
|
|
264
|
-
if (SKIP_TYPES.includes(joinedPath) || SKIP_TYPES.includes(path.at(-1))) {
|
|
265
|
-
return o;
|
|
266
|
-
}
|
|
267
|
-
const suffix = typeSuffixes.get(id) || '';
|
|
268
|
-
let knownType = false;
|
|
269
|
-
let name, nameOut;
|
|
270
|
-
if ((0, known_codecs_1.isKnownCodecType)(joinedPath)) {
|
|
271
|
-
const codecType = (0, known_codecs_1.findKnownCodecType)(path.at(-1));
|
|
272
|
-
name = codecType.typeIn;
|
|
273
|
-
nameOut = codecType.typeOut;
|
|
274
|
-
knownType = true;
|
|
275
|
-
}
|
|
276
|
-
else if (PATH_RM_INDEX_1.includes(path[1])) {
|
|
277
|
-
const newPath = path.slice();
|
|
278
|
-
newPath.splice(1, 1);
|
|
279
|
-
name = this.#cleanPath(newPath);
|
|
280
|
-
}
|
|
281
|
-
else {
|
|
282
|
-
name = this.#cleanPath(path);
|
|
283
|
-
}
|
|
284
|
-
if (this.#shouldGenerateTypeIn(id)) {
|
|
285
|
-
nameOut = name;
|
|
286
|
-
name = name.endsWith('Like') ? name : `${name}Like`;
|
|
287
|
-
}
|
|
288
|
-
o[id] = {
|
|
289
|
-
name: `${name}${suffix}`,
|
|
290
|
-
nameOut: nameOut ? `${nameOut}${suffix}` : `${name}${suffix}`,
|
|
291
|
-
knownType,
|
|
292
|
-
skip: skipIds.includes(id),
|
|
293
|
-
...type,
|
|
294
|
-
};
|
|
295
|
-
return o;
|
|
296
|
-
}, {});
|
|
297
|
-
}
|
|
298
258
|
#removeGenericPart(typeName) {
|
|
299
|
-
if (typeName.match(WRAPPER_TYPE_REGEX)) {
|
|
300
|
-
return typeName.replace(WRAPPER_TYPE_REGEX, (_, $1) => $1);
|
|
259
|
+
if (typeName.match(utils_js_1.WRAPPER_TYPE_REGEX)) {
|
|
260
|
+
return typeName.replace(utils_js_1.WRAPPER_TYPE_REGEX, (_, $1) => $1);
|
|
301
261
|
}
|
|
302
262
|
else {
|
|
303
263
|
return typeName;
|
|
304
264
|
}
|
|
305
265
|
}
|
|
306
|
-
|
|
307
|
-
* @description Remove duplicated part of the path
|
|
308
|
-
*
|
|
309
|
-
* Example:
|
|
310
|
-
* ["pallet_staking", "pallet", "pallet", "Event"]
|
|
311
|
-
* => ["pallet_staking", "pallet", "Event"]
|
|
312
|
-
*
|
|
313
|
-
* @param path
|
|
314
|
-
* @private
|
|
315
|
-
*/
|
|
316
|
-
#cleanPath(path) {
|
|
266
|
+
cleanPath(path) {
|
|
317
267
|
return path
|
|
318
|
-
.map((one) => (0,
|
|
268
|
+
.map((one) => (0, utils_1.stringPascalCase)(one))
|
|
319
269
|
.filter((one, idx, currentPath) => idx === 0 || one !== currentPath[idx - 1])
|
|
320
270
|
.join('');
|
|
321
271
|
}
|
|
322
|
-
#shouldGenerateTypeIn(id) {
|
|
323
|
-
const { callTypeId } = this.metadata.extrinsic;
|
|
324
|
-
const palletCallTypeIds = this.registry.getPalletCallTypeIds();
|
|
325
|
-
return callTypeId === id || palletCallTypeIds.includes(id);
|
|
326
|
-
}
|
|
327
272
|
eqlCache = new Map();
|
|
328
273
|
typeEql(idA, idB, level = 0) {
|
|
329
274
|
const cacheKey = `${idA}==${idB}`;
|
|
@@ -336,9 +281,8 @@ class TypesGen {
|
|
|
336
281
|
#typeEql(idA, idB, lvl = 0) {
|
|
337
282
|
if (idA === idB)
|
|
338
283
|
return true;
|
|
339
|
-
const
|
|
340
|
-
const
|
|
341
|
-
const typeB = types[idB];
|
|
284
|
+
const typeA = this.types[idA];
|
|
285
|
+
const typeB = this.types[idB];
|
|
342
286
|
if (typeA.path.join('::') !== typeB.path.join('::'))
|
|
343
287
|
return false;
|
|
344
288
|
const { type: defA, params: paramsA } = typeA;
|
|
@@ -381,19 +325,18 @@ class TypesGen {
|
|
|
381
325
|
(param1.typeId === undefined) === (param2.typeId === undefined) &&
|
|
382
326
|
(param1.typeId === undefined || this.#typeEql(param1.typeId, param2.typeId)));
|
|
383
327
|
}
|
|
384
|
-
|
|
385
|
-
const
|
|
386
|
-
const
|
|
387
|
-
const dupTypeParams = types[dupTypeId].params;
|
|
328
|
+
extractDupTypeSuffix(dupTypeId, originalTypeId, dupCount) {
|
|
329
|
+
const originalTypeParams = this.types[originalTypeId].params;
|
|
330
|
+
const dupTypeParams = this.types[dupTypeId].params;
|
|
388
331
|
const diffParam = dupTypeParams.find((one, idx) => !this.#eqlTypeParam(one, originalTypeParams[idx]));
|
|
389
332
|
// TODO make sure these suffix is unique if a type is duplicated more than 2 times
|
|
390
333
|
if (diffParam?.typeId) {
|
|
391
|
-
const diffType = types[diffParam.typeId];
|
|
334
|
+
const diffType = this.types[diffParam.typeId];
|
|
392
335
|
if (diffType.path.length > 0) {
|
|
393
|
-
return (0,
|
|
336
|
+
return (0, utils_1.stringPascalCase)(diffType.path.at(-1));
|
|
394
337
|
}
|
|
395
338
|
else if (diffType.type.tag === 'Primitive') {
|
|
396
|
-
return (0,
|
|
339
|
+
return (0, utils_1.stringPascalCase)(diffType.type.value.kind);
|
|
397
340
|
}
|
|
398
341
|
}
|
|
399
342
|
// Last resort!
|
|
@@ -404,7 +347,7 @@ class TypesGen {
|
|
|
404
347
|
typeName.forEach((one) => this.addTypeImport(one));
|
|
405
348
|
return;
|
|
406
349
|
}
|
|
407
|
-
if ((0,
|
|
350
|
+
if ((0, utils_js_1.isNativeType)(typeName)) {
|
|
408
351
|
return;
|
|
409
352
|
}
|
|
410
353
|
for (let type of Object.values(this.includedTypes)) {
|
|
@@ -426,12 +369,10 @@ class TypesGen {
|
|
|
426
369
|
this.typeImports.addCodecType(typeName);
|
|
427
370
|
return;
|
|
428
371
|
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
this.typeImports.addOutType(typeName);
|
|
434
|
-
}
|
|
372
|
+
this.typeImports.addOutType(typeName);
|
|
373
|
+
}
|
|
374
|
+
getEnumOptions(_typeId) {
|
|
375
|
+
return { tagKey: 'tag', valueKey: 'value' };
|
|
435
376
|
}
|
|
436
377
|
}
|
|
437
|
-
exports.
|
|
378
|
+
exports.BaseTypesGen = BaseTypesGen;
|
|
@@ -8,30 +8,47 @@ class TypeImports {
|
|
|
8
8
|
codecTypes;
|
|
9
9
|
// Known types that're not codecs or chain/portable types defined in @dedot/types
|
|
10
10
|
knownTypes;
|
|
11
|
+
knownJsonRpcTypes;
|
|
11
12
|
// External types to define explicitly
|
|
12
13
|
outTypes;
|
|
14
|
+
// Know types defined in @dedot/contracts
|
|
15
|
+
contractTypes;
|
|
16
|
+
// Know types defined in @dedot/api/chaintypes or dedot/chaintypes
|
|
17
|
+
chainTypes;
|
|
13
18
|
constructor() {
|
|
14
19
|
this.portableTypes = new Set();
|
|
15
20
|
this.codecTypes = new Set();
|
|
16
21
|
this.knownTypes = new Set();
|
|
22
|
+
this.knownJsonRpcTypes = new Set();
|
|
17
23
|
this.outTypes = new Set();
|
|
24
|
+
this.contractTypes = new Set();
|
|
25
|
+
this.chainTypes = new Set();
|
|
18
26
|
}
|
|
19
27
|
clear() {
|
|
20
28
|
this.portableTypes.clear();
|
|
21
29
|
this.codecTypes.clear();
|
|
22
30
|
this.knownTypes.clear();
|
|
31
|
+
this.knownJsonRpcTypes.clear();
|
|
23
32
|
this.outTypes.clear();
|
|
33
|
+
this.contractTypes.clear();
|
|
34
|
+
this.chainTypes.clear();
|
|
24
35
|
}
|
|
25
|
-
toImports(
|
|
36
|
+
toImports(config) {
|
|
37
|
+
const { excludeModules = [], useSubPaths = false } = config || {};
|
|
26
38
|
// TODO generate outTypes!
|
|
39
|
+
const prefix = useSubPaths ? '' : '@';
|
|
27
40
|
const toImports = [
|
|
28
|
-
[this.knownTypes,
|
|
29
|
-
[this.
|
|
41
|
+
[this.knownTypes, `${prefix}dedot/types`],
|
|
42
|
+
[this.knownJsonRpcTypes, `${prefix}dedot/types/json-rpc`],
|
|
43
|
+
[this.codecTypes, `${prefix}dedot/codecs`],
|
|
44
|
+
[this.contractTypes, `${prefix}dedot/contracts`],
|
|
45
|
+
[this.chainTypes, prefix ? '@dedot/api/chaintypes' : 'dedot/chaintypes'],
|
|
30
46
|
[this.portableTypes, './types'],
|
|
31
47
|
];
|
|
32
48
|
return toImports
|
|
33
49
|
.filter(([_, module]) => !excludeModules.includes(module))
|
|
34
50
|
.map(([types, module]) => this.#toImportLine(types, module))
|
|
51
|
+
.filter((line) => line.length > 0)
|
|
35
52
|
.join('\n');
|
|
36
53
|
}
|
|
37
54
|
#toImportLine(types, module) {
|
|
@@ -49,8 +66,17 @@ class TypeImports {
|
|
|
49
66
|
addKnownType(...types) {
|
|
50
67
|
types.forEach((one) => this.knownTypes.add(one));
|
|
51
68
|
}
|
|
69
|
+
addKnownJsonRpcType(...types) {
|
|
70
|
+
types.forEach((one) => this.knownJsonRpcTypes.add(one));
|
|
71
|
+
}
|
|
52
72
|
addOutType(...types) {
|
|
53
73
|
types.forEach((one) => this.outTypes.add(one));
|
|
54
74
|
}
|
|
75
|
+
addContractType(...types) {
|
|
76
|
+
types.forEach((one) => this.contractTypes.add(one));
|
|
77
|
+
}
|
|
78
|
+
addChainType(...types) {
|
|
79
|
+
types.forEach((one) => this.chainTypes.add(one));
|
|
80
|
+
}
|
|
55
81
|
}
|
|
56
82
|
exports.TypeImports = TypeImports;
|
|
@@ -14,13 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
18
|
-
__exportStar(require("./
|
|
19
|
-
__exportStar(require("./
|
|
20
|
-
__exportStar(require("./QueryGen"), exports);
|
|
21
|
-
__exportStar(require("./RpcGen"), exports);
|
|
22
|
-
__exportStar(require("./IndexGen"), exports);
|
|
23
|
-
__exportStar(require("./ErrorsGen"), exports);
|
|
24
|
-
__exportStar(require("./EventsGen"), exports);
|
|
25
|
-
__exportStar(require("./TxGen"), exports);
|
|
26
|
-
__exportStar(require("./RuntimeApisGen"), exports);
|
|
17
|
+
__exportStar(require("./BaseTypesGen.js"), exports);
|
|
18
|
+
__exportStar(require("./known-codecs.js"), exports);
|
|
19
|
+
__exportStar(require("./TypeImports.js"), exports);
|
|
@@ -23,10 +23,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
27
|
-
const $ = __importStar(require("@dedot/shape"));
|
|
26
|
+
exports.checkKnownCodecType = exports.findKnownWrapperCodec = exports.findKnownCodec = exports.findKnownCodecType = exports.looseTypeCodecs = exports.normalizeCodecName = void 0;
|
|
28
27
|
const Codecs = __importStar(require("@dedot/codecs"));
|
|
29
28
|
const codecs_1 = require("@dedot/codecs");
|
|
29
|
+
const $ = __importStar(require("@dedot/shape"));
|
|
30
30
|
const utils_1 = require("@dedot/utils");
|
|
31
31
|
const normalizeCodecName = (name) => {
|
|
32
32
|
return name.startsWith('$') ? name : `$${name}`;
|
|
@@ -57,6 +57,8 @@ const KNOWN_PATHS = [
|
|
|
57
57
|
/^primitive_types::\w+$/,
|
|
58
58
|
/^sp_arithmetic::per_things::\w+$/,
|
|
59
59
|
/^sp_arithmetic::fixed_point::\w+$/,
|
|
60
|
+
'ink_primitives::types::Hash',
|
|
61
|
+
{ path: 'ink_primitives::types::AccountId', codec: 'AccountId32' },
|
|
60
62
|
];
|
|
61
63
|
const WRAPPER_TYPE_REGEX = /^(\w+)<(.*)>$/;
|
|
62
64
|
const TUPLE_TYPE_REGEX = /^\[(.*)]$/;
|
|
@@ -144,8 +146,25 @@ function findKnownWrapperCodec(typeName) {
|
|
|
144
146
|
}
|
|
145
147
|
}
|
|
146
148
|
exports.findKnownWrapperCodec = findKnownWrapperCodec;
|
|
147
|
-
function
|
|
149
|
+
function checkKnownCodecType(path) {
|
|
148
150
|
const joinedPath = Array.isArray(path) ? path.join('::') : path;
|
|
149
|
-
|
|
151
|
+
const knownPath = KNOWN_PATHS.find((one) => {
|
|
152
|
+
if (typeof one === 'string') {
|
|
153
|
+
return one === joinedPath;
|
|
154
|
+
}
|
|
155
|
+
else if (one instanceof RegExp) {
|
|
156
|
+
return one.test(joinedPath);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
return one.path === joinedPath;
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
if (!knownPath) {
|
|
163
|
+
return [false, ''];
|
|
164
|
+
}
|
|
165
|
+
if (typeof knownPath === 'string' || knownPath instanceof RegExp) {
|
|
166
|
+
return [true, joinedPath.split('::').at(-1)];
|
|
167
|
+
}
|
|
168
|
+
return [true, knownPath.codec];
|
|
150
169
|
}
|
|
151
|
-
exports.
|
|
170
|
+
exports.checkKnownCodecType = checkKnownCodecType;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConstructorQueryGen = void 0;
|
|
4
|
+
const utils_js_1 = require("../../utils.js");
|
|
5
|
+
const QueryGen_js_1 = require("./QueryGen.js");
|
|
6
|
+
class ConstructorQueryGen extends QueryGen_js_1.QueryGen {
|
|
7
|
+
generate(useSubPaths = false) {
|
|
8
|
+
this.typesGen.clearCache();
|
|
9
|
+
this.typesGen.typeImports.addKnownType('GenericSubstrateApi');
|
|
10
|
+
this.typesGen.typeImports.addContractType('GenericConstructorQuery', 'GenericConstructorQueryCall', 'ConstructorCallOptions', 'ContractInstantiateResult');
|
|
11
|
+
const { constructors } = this.contractMetadata.spec;
|
|
12
|
+
const constructorsOut = this.doGenerate(constructors, 'ConstructorCallOptions');
|
|
13
|
+
const importTypes = this.typesGen.typeImports.toImports({ useSubPaths });
|
|
14
|
+
const template = (0, utils_js_1.compileTemplate)('typink/templates/constructor-query.hbs');
|
|
15
|
+
return (0, utils_js_1.beautifySourceCode)(template({ importTypes, constructorsOut }));
|
|
16
|
+
}
|
|
17
|
+
generateMethodDef(def) {
|
|
18
|
+
const { args } = def;
|
|
19
|
+
args.forEach(({ type: { type } }) => this.importType(type));
|
|
20
|
+
const paramsOut = this.generateParamsOut(args);
|
|
21
|
+
return `GenericConstructorQueryCall<ChainApi, (${paramsOut && `${paramsOut},`} options: ConstructorCallOptions) => Promise<ContractInstantiateResult<ChainApi>>>`;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.ConstructorQueryGen = ConstructorQueryGen;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConstructorTxGen = void 0;
|
|
4
|
+
const utils_js_1 = require("../../utils.js");
|
|
5
|
+
const QueryGen_js_1 = require("./QueryGen.js");
|
|
6
|
+
class ConstructorTxGen extends QueryGen_js_1.QueryGen {
|
|
7
|
+
generate(useSubPaths = false) {
|
|
8
|
+
this.typesGen.clearCache();
|
|
9
|
+
this.typesGen.typeImports.addKnownType('GenericSubstrateApi');
|
|
10
|
+
this.typesGen.typeImports.addContractType('GenericConstructorTx', 'GenericConstructorTxCall', 'ConstructorTxOptions', 'GenericInstantiateSubmittableExtrinsic');
|
|
11
|
+
const { constructors } = this.contractMetadata.spec;
|
|
12
|
+
const constructorsOut = this.doGenerate(constructors, 'ConstructorTxOptions');
|
|
13
|
+
const importTypes = this.typesGen.typeImports.toImports({ useSubPaths });
|
|
14
|
+
const template = (0, utils_js_1.compileTemplate)('typink/templates/constructor-tx.hbs');
|
|
15
|
+
return (0, utils_js_1.beautifySourceCode)(template({ importTypes, constructorsOut }));
|
|
16
|
+
}
|
|
17
|
+
generateMethodDef(def) {
|
|
18
|
+
const { args } = def;
|
|
19
|
+
args.forEach(({ type: { type } }) => this.importType(type));
|
|
20
|
+
const paramsOut = this.generateParamsOut(args);
|
|
21
|
+
return `GenericConstructorTxCall<ChainApi, (${paramsOut && `${paramsOut},`} options: ConstructorTxOptions) => GenericInstantiateSubmittableExtrinsic<ChainApi>>`;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.ConstructorTxGen = ConstructorTxGen;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IndexGen = void 0;
|
|
4
|
+
const utils_1 = require("@dedot/utils");
|
|
5
|
+
const index_js_1 = require("../../shared/index.js");
|
|
6
|
+
const utils_js_1 = require("../../utils.js");
|
|
7
|
+
const SUFFIX = 'contract_api';
|
|
8
|
+
class IndexGen {
|
|
9
|
+
contractMetadata;
|
|
10
|
+
constructor(contractMetadata) {
|
|
11
|
+
this.contractMetadata = contractMetadata;
|
|
12
|
+
}
|
|
13
|
+
generate(useSubPaths = false) {
|
|
14
|
+
const contractName = (0, utils_1.stringPascalCase)(`${this.contractMetadata.contract.name}_${SUFFIX}`);
|
|
15
|
+
const typeImports = new index_js_1.TypeImports();
|
|
16
|
+
typeImports.addKnownType('VersionedGenericSubstrateApi', 'RpcVersion');
|
|
17
|
+
typeImports.addContractType('GenericContractApi');
|
|
18
|
+
typeImports.addChainType('SubstrateApi');
|
|
19
|
+
const importTypes = typeImports.toImports({ useSubPaths });
|
|
20
|
+
const template = (0, utils_js_1.compileTemplate)('typink/templates/index.hbs');
|
|
21
|
+
return (0, utils_js_1.beautifySourceCode)(template({ contractName, importTypes }));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.IndexGen = IndexGen;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QueryGen = void 0;
|
|
4
|
+
const contracts_1 = require("@dedot/contracts");
|
|
5
|
+
const utils_1 = require("@dedot/utils");
|
|
6
|
+
const utils_js_1 = require("../../utils.js");
|
|
7
|
+
class QueryGen {
|
|
8
|
+
contractMetadata;
|
|
9
|
+
typesGen;
|
|
10
|
+
constructor(contractMetadata, typeGen) {
|
|
11
|
+
this.contractMetadata = contractMetadata;
|
|
12
|
+
this.typesGen = typeGen;
|
|
13
|
+
}
|
|
14
|
+
generate(useSubPaths = false) {
|
|
15
|
+
this.typesGen.clearCache();
|
|
16
|
+
this.typesGen.typeImports.addKnownType('GenericSubstrateApi');
|
|
17
|
+
this.typesGen.typeImports.addContractType('GenericContractQuery', 'GenericContractQueryCall', 'ContractCallOptions', 'GenericContractCallResult', 'ContractCallResult');
|
|
18
|
+
const { messages } = this.contractMetadata.spec;
|
|
19
|
+
const queryCallsOut = this.doGenerate(messages, 'ContractCallOptions');
|
|
20
|
+
const importTypes = this.typesGen.typeImports.toImports({ useSubPaths });
|
|
21
|
+
const template = (0, utils_js_1.compileTemplate)('typink/templates/query.hbs');
|
|
22
|
+
return (0, utils_js_1.beautifySourceCode)(template({ importTypes, queryCallsOut }));
|
|
23
|
+
}
|
|
24
|
+
doGenerate(messages, optionsTypeName) {
|
|
25
|
+
let callsOut = '';
|
|
26
|
+
messages.forEach((messageDef) => {
|
|
27
|
+
const { label, docs, selector, args } = messageDef;
|
|
28
|
+
callsOut += `${(0, utils_js_1.commentBlock)(docs, '\n', args.map((arg) => `@param {${this.typesGen.generateType(arg.type.type, 1)}} ${(0, utils_1.stringCamelCase)(arg.label)}`), optionsTypeName ? `@param {${optionsTypeName}} options` : '', '\n', `@selector ${selector}`)}`;
|
|
29
|
+
callsOut += `${(0, contracts_1.normalizeLabel)(label)}: ${this.generateMethodDef(messageDef)};\n\n`;
|
|
30
|
+
});
|
|
31
|
+
return callsOut;
|
|
32
|
+
}
|
|
33
|
+
generateMethodDef(def) {
|
|
34
|
+
const { args, returnType } = def;
|
|
35
|
+
this.importType(returnType.type);
|
|
36
|
+
args.forEach(({ type: { type } }) => this.importType(type));
|
|
37
|
+
const paramsOut = this.generateParamsOut(args);
|
|
38
|
+
const typeOut = this.typesGen.generateType(returnType.type, 0, true);
|
|
39
|
+
return `GenericContractQueryCall<ChainApi, (${paramsOut && `${paramsOut},`} options: ContractCallOptions) => Promise<GenericContractCallResult<${typeOut}, ContractCallResult<ChainApi>>>>`;
|
|
40
|
+
}
|
|
41
|
+
generateParamsOut(args) {
|
|
42
|
+
return args
|
|
43
|
+
.map(({ type: { type }, label }) => `${(0, utils_1.stringCamelCase)(label)}: ${this.typesGen.generateType(type, 1)}`)
|
|
44
|
+
.join(', ');
|
|
45
|
+
}
|
|
46
|
+
importType(typeId) {
|
|
47
|
+
const type = this.contractMetadata.types[typeId];
|
|
48
|
+
const def = (0, contracts_1.normalizeContractTypeDef)(this.contractMetadata.types[typeId].type.def);
|
|
49
|
+
if (this.typesGen.includedTypes[type.id]) {
|
|
50
|
+
this.typesGen.addTypeImport(this.typesGen.includedTypes[type.id].name);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const { tag, value } = def;
|
|
54
|
+
switch (tag) {
|
|
55
|
+
case 'Compact':
|
|
56
|
+
case 'Primitive':
|
|
57
|
+
case 'BitSequence':
|
|
58
|
+
return;
|
|
59
|
+
case 'Struct':
|
|
60
|
+
return value.fields.forEach(({ typeId }) => this.importType(typeId));
|
|
61
|
+
case 'Enum':
|
|
62
|
+
return value.members.forEach(({ fields }) => fields.map(({ typeId }) => this.importType(typeId)).flat());
|
|
63
|
+
case 'Tuple':
|
|
64
|
+
return value.fields.forEach((typeId) => this.importType(typeId));
|
|
65
|
+
case 'SizedVec':
|
|
66
|
+
return this.importType(value.typeParam);
|
|
67
|
+
case 'Sequence':
|
|
68
|
+
return this.importType(value.typeParam);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.QueryGen = QueryGen;
|