@dedot/codegen 0.0.1-next.6cd3bbb0.6 → 0.0.1-next.70fc26c6.11
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/cjs/generator/ConstsGen.js +1 -2
- package/cjs/generator/ErrorsGen.js +2 -3
- package/cjs/generator/EventsGen.js +2 -3
- package/cjs/generator/IndexGen.js +5 -6
- package/cjs/generator/QueryGen.js +1 -2
- package/cjs/generator/RpcGen.js +2 -3
- package/cjs/generator/RuntimeApisGen.js +7 -8
- package/cjs/generator/TxGen.js +6 -6
- package/cjs/generator/TypesGen.js +6 -7
- package/cjs/generator/utils.js +30 -1
- package/cjs/index.js +11 -11
- package/generator/ConstsGen.js +2 -3
- package/generator/ErrorsGen.js +1 -2
- package/generator/EventsGen.js +1 -2
- package/generator/IndexGen.d.ts +2 -3
- package/generator/IndexGen.js +5 -6
- package/generator/QueryGen.js +2 -3
- package/generator/RpcGen.js +1 -2
- package/generator/RuntimeApisGen.js +3 -4
- package/generator/TxGen.js +1 -1
- package/generator/TypesGen.js +2 -3
- package/generator/utils.d.ts +5 -0
- package/generator/utils.js +28 -0
- package/index.d.ts +2 -3
- package/index.js +9 -9
- package/package.json +7 -8
- package/cjs/genSupportedChainTypes.js +0 -83
- package/cjs/types.js +0 -2
- package/genSupportedChainTypes.d.ts +0 -1
- package/genSupportedChainTypes.js +0 -78
- package/types.d.ts +0 -6
- package/types.js +0 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ConstsGen = void 0;
|
|
4
|
-
const util_1 = require("@polkadot/util");
|
|
5
4
|
const utils_1 = require("@dedot/utils");
|
|
6
5
|
const index_js_1 = require("../generator/index.js");
|
|
7
6
|
const utils_js_1 = require("./utils.js");
|
|
@@ -18,7 +17,7 @@ class ConstsGen extends index_js_1.ApiGen {
|
|
|
18
17
|
docs: one.docs,
|
|
19
18
|
}));
|
|
20
19
|
defTypeOut += (0, utils_js_1.commentBlock)(`Pallet \`${pallet.name}\`'s constants`);
|
|
21
|
-
defTypeOut += `${(0,
|
|
20
|
+
defTypeOut += `${(0, utils_1.stringCamelCase)(pallet.name)}: {
|
|
22
21
|
${typedConstants.map(({ name, type, docs }) => `${(0, utils_js_1.commentBlock)(docs)}${name}: ${type}`).join(',\n')}
|
|
23
22
|
|
|
24
23
|
${(0, utils_js_1.commentBlock)('Generic pallet constant')}[name: string]: any,
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ErrorsGen = void 0;
|
|
4
4
|
const ApiGen_js_1 = require("./ApiGen.js");
|
|
5
5
|
const utils_js_1 = require("./utils.js");
|
|
6
|
-
const util_1 = require("@polkadot/util");
|
|
7
6
|
const utils_1 = require("@dedot/utils");
|
|
8
7
|
class ErrorsGen extends ApiGen_js_1.ApiGen {
|
|
9
8
|
generate() {
|
|
@@ -18,9 +17,9 @@ class ErrorsGen extends ApiGen_js_1.ApiGen {
|
|
|
18
17
|
}
|
|
19
18
|
const errorDefs = this.#getErrorDefs(errorTypeId);
|
|
20
19
|
defTypeOut += (0, utils_js_1.commentBlock)(`Pallet \`${pallet.name}\`'s errors`);
|
|
21
|
-
defTypeOut += `${(0,
|
|
20
|
+
defTypeOut += `${(0, utils_1.stringCamelCase)(pallet.name)}: {
|
|
22
21
|
${errorDefs
|
|
23
|
-
.map(({ name, docs }) => `${(0, utils_js_1.commentBlock)(docs)}${(0,
|
|
22
|
+
.map(({ name, docs }) => `${(0, utils_js_1.commentBlock)(docs)}${(0, utils_1.stringPascalCase)(name)}: GenericPalletError`)
|
|
24
23
|
.join(',\n')}
|
|
25
24
|
|
|
26
25
|
${(0, utils_js_1.commentBlock)('Generic pallet error')}[error: string]: GenericPalletError,
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.EventsGen = void 0;
|
|
4
4
|
const ApiGen_js_1 = require("./ApiGen.js");
|
|
5
5
|
const utils_js_1 = require("./utils.js");
|
|
6
|
-
const util_1 = require("@polkadot/util");
|
|
7
6
|
const utils_1 = require("@dedot/utils");
|
|
8
7
|
class EventsGen extends ApiGen_js_1.ApiGen {
|
|
9
8
|
generate() {
|
|
@@ -19,7 +18,7 @@ class EventsGen extends ApiGen_js_1.ApiGen {
|
|
|
19
18
|
const eventDefs = this.#getEventDefs(eventTypeId);
|
|
20
19
|
const flatMembers = eventDefs.every((d) => d.fields.length === 0);
|
|
21
20
|
defTypeOut += (0, utils_js_1.commentBlock)(`Pallet \`${pallet.name}\`'s events`);
|
|
22
|
-
defTypeOut += `${(0,
|
|
21
|
+
defTypeOut += `${(0, utils_1.stringCamelCase)(pallet.name)}: {
|
|
23
22
|
${eventDefs
|
|
24
23
|
.map((def) => {
|
|
25
24
|
const genericParts = [`'${pallet.name}'`, `'${def.name}'`];
|
|
@@ -32,7 +31,7 @@ class EventsGen extends ApiGen_js_1.ApiGen {
|
|
|
32
31
|
}
|
|
33
32
|
return { ...def, genericParts };
|
|
34
33
|
})
|
|
35
|
-
.map(({ name, docs, fields, genericParts }) => `${(0, utils_js_1.commentBlock)(docs)}${(0,
|
|
34
|
+
.map(({ name, docs, fields, genericParts }) => `${(0, utils_js_1.commentBlock)(docs)}${(0, utils_1.stringPascalCase)(name)}: GenericPalletEvent<${genericParts.join(', ')}>`)
|
|
36
35
|
.join(',\n')}
|
|
37
36
|
|
|
38
37
|
${(0, utils_js_1.commentBlock)('Generic pallet event')}[prop: string]: GenericPalletEvent,
|
|
@@ -2,15 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.IndexGen = void 0;
|
|
4
4
|
const utils_js_1 = require("./utils.js");
|
|
5
|
-
const
|
|
5
|
+
const utils_1 = require("@dedot/utils");
|
|
6
6
|
class IndexGen {
|
|
7
|
-
|
|
8
|
-
constructor(
|
|
9
|
-
this.
|
|
7
|
+
chain;
|
|
8
|
+
constructor(chain) {
|
|
9
|
+
this.chain = chain;
|
|
10
10
|
}
|
|
11
11
|
async generate() {
|
|
12
|
-
const
|
|
13
|
-
const interfaceName = (0, util_1.stringPascalCase)(chain);
|
|
12
|
+
const interfaceName = (0, utils_1.stringPascalCase)(this.chain);
|
|
14
13
|
const template = (0, utils_js_1.compileTemplate)('index.hbs');
|
|
15
14
|
return (0, utils_js_1.beautifySourceCode)(template({ interfaceName }));
|
|
16
15
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.QueryGen = void 0;
|
|
4
|
-
const util_1 = require("@polkadot/util");
|
|
5
4
|
const utils_1 = require("@dedot/utils");
|
|
6
5
|
const index_js_1 = require("../generator/index.js");
|
|
7
6
|
const utils_js_1 = require("./utils.js");
|
|
@@ -18,7 +17,7 @@ class QueryGen extends index_js_1.ApiGen {
|
|
|
18
17
|
const queries = storage.entries.map((one) => this.#generateEntry(one));
|
|
19
18
|
const queryDefs = queries.map(({ name, valueType, keyType, docs }) => `${(0, utils_js_1.commentBlock)(docs)}${name}: GenericStorageQuery<(${keyType}) => ${valueType}>`);
|
|
20
19
|
defTypeOut += (0, utils_js_1.commentBlock)(`Pallet \`${pallet.name}\`'s storage queries`);
|
|
21
|
-
defTypeOut += `${(0,
|
|
20
|
+
defTypeOut += `${(0, utils_1.stringCamelCase)(pallet.name)}: {
|
|
22
21
|
${queryDefs.join(',\n')}
|
|
23
22
|
|
|
24
23
|
${(0, utils_js_1.commentBlock)('Generic pallet storage query')}[storage: string]: GenericStorageQuery;
|
package/cjs/generator/RpcGen.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RpcGen = void 0;
|
|
4
4
|
const specs_1 = require("@dedot/specs");
|
|
5
|
-
const utils_1 = require("@dedot/utils");
|
|
6
5
|
const index_js_1 = require("../generator/index.js");
|
|
7
6
|
const utils_js_1 = require("./utils.js");
|
|
8
7
|
const known_codecs_js_1 = require("./known-codecs.js");
|
|
@@ -105,7 +104,7 @@ class RpcGen extends index_js_1.ApiGen {
|
|
|
105
104
|
return;
|
|
106
105
|
}
|
|
107
106
|
type = type.trim();
|
|
108
|
-
if ((0,
|
|
107
|
+
if ((0, utils_js_1.isNativeType)(type)) {
|
|
109
108
|
return;
|
|
110
109
|
}
|
|
111
110
|
// Handle generic wrapper types
|
|
@@ -132,7 +131,7 @@ class RpcGen extends index_js_1.ApiGen {
|
|
|
132
131
|
}
|
|
133
132
|
try {
|
|
134
133
|
const codecType = this.#getCodecType(type, toTypeIn);
|
|
135
|
-
if ((0,
|
|
134
|
+
if ((0, utils_js_1.isNativeType)(codecType))
|
|
136
135
|
return;
|
|
137
136
|
this.typesGen.typeImports.addCodecType(codecType);
|
|
138
137
|
return;
|
|
@@ -5,7 +5,6 @@ const specs_1 = require("@dedot/specs");
|
|
|
5
5
|
const utils_js_1 = require("./utils.js");
|
|
6
6
|
const utils_1 = require("@dedot/utils");
|
|
7
7
|
const RpcGen_js_1 = require("./RpcGen.js");
|
|
8
|
-
const util_1 = require("@polkadot/util");
|
|
9
8
|
class RuntimeApisGen extends RpcGen_js_1.RpcGen {
|
|
10
9
|
typesGen;
|
|
11
10
|
runtimeApis;
|
|
@@ -21,8 +20,8 @@ class RuntimeApisGen extends RpcGen_js_1.RpcGen {
|
|
|
21
20
|
if (this.metadata.apis.length > 0) {
|
|
22
21
|
this.metadata.apis.forEach((runtimeApi) => {
|
|
23
22
|
const { name: runtimeApiName, methods } = runtimeApi;
|
|
24
|
-
runtimeCallsOut += (0, utils_js_1.commentBlock)(`@runtimeapi: ${runtimeApiName} - ${(0, utils_1.
|
|
25
|
-
runtimeCallsOut += `${(0,
|
|
23
|
+
runtimeCallsOut += (0, utils_js_1.commentBlock)(`@runtimeapi: ${runtimeApiName} - ${(0, utils_1.calcRuntimeApiHash)(runtimeApiName)}`);
|
|
24
|
+
runtimeCallsOut += `${(0, utils_1.stringCamelCase)(runtimeApiName)}: {
|
|
26
25
|
${methods.map((method) => this.#generateMethodDef(runtimeApiName, method)).join('\n')}
|
|
27
26
|
|
|
28
27
|
${(0, utils_js_1.commentBlock)('Generic runtime api call')}[method: string]: GenericRuntimeApiMethod
|
|
@@ -33,7 +32,7 @@ class RuntimeApisGen extends RpcGen_js_1.RpcGen {
|
|
|
33
32
|
const specs = this.#targetRuntimeApiSpecs();
|
|
34
33
|
specs.forEach(({ methods, runtimeApiName, runtimeApiHash, version }) => {
|
|
35
34
|
runtimeCallsOut += (0, utils_js_1.commentBlock)(`@runtimeapi: ${runtimeApiName} - ${runtimeApiHash}`, `@version: ${version}`);
|
|
36
|
-
runtimeCallsOut += `${(0,
|
|
35
|
+
runtimeCallsOut += `${(0, utils_1.stringCamelCase)(runtimeApiName)}: {
|
|
37
36
|
${Object.keys(methods)
|
|
38
37
|
.map((methodName) => this.#generateMethodDefFromSpec({
|
|
39
38
|
...methods[methodName],
|
|
@@ -68,7 +67,7 @@ class RuntimeApisGen extends RpcGen_js_1.RpcGen {
|
|
|
68
67
|
plainType: this.getGeneratedTypeName(param.type),
|
|
69
68
|
}));
|
|
70
69
|
const paramsOut = typedParams
|
|
71
|
-
.map(({ name, isOptional, plainType }) => `${(0,
|
|
70
|
+
.map(({ name, isOptional, plainType }) => `${(0, utils_1.stringCamelCase)(name)}${isOptional ? '?' : ''}: ${plainType}`)
|
|
72
71
|
.join(', ');
|
|
73
72
|
const typeOut = this.getGeneratedTypeName(type, false);
|
|
74
73
|
return `${(0, utils_js_1.commentBlock)(docs, '\n', defaultDocs, typedParams.map(({ plainType, name }) => `@param {${plainType}} ${name}`))}${methodName}: GenericRuntimeApiMethod<(${paramsOut}) => Promise<${typeOut}>>`;
|
|
@@ -90,9 +89,9 @@ class RuntimeApisGen extends RpcGen_js_1.RpcGen {
|
|
|
90
89
|
}));
|
|
91
90
|
this.addTypeImport(typedInputs.map((t) => t.type));
|
|
92
91
|
const paramsOut = typedInputs
|
|
93
|
-
.map(({ name, type, isOptional }) => `${(0,
|
|
92
|
+
.map(({ name, type, isOptional }) => `${(0, utils_1.stringCamelCase)(name)}${isOptional ? '?' : ''}: ${type}`)
|
|
94
93
|
.join(', ');
|
|
95
|
-
return `${(0, utils_js_1.commentBlock)(docs, '\n', defaultDocs, typedInputs.map(({ type, name }) => `@param {${type}} ${name}`))}${(0,
|
|
94
|
+
return `${(0, utils_js_1.commentBlock)(docs, '\n', defaultDocs, typedInputs.map(({ type, name }) => `@param {${type}} ${name}`))}${(0, utils_1.stringCamelCase)(methodName)}: GenericRuntimeApiMethod<(${paramsOut}) => Promise<${typeOut}>>`;
|
|
96
95
|
}
|
|
97
96
|
#targetRuntimeApiSpecs() {
|
|
98
97
|
const specs = this.runtimeApis.map(([runtimeApiHash, version]) => {
|
|
@@ -112,7 +111,7 @@ class RuntimeApisGen extends RpcGen_js_1.RpcGen {
|
|
|
112
111
|
}, []);
|
|
113
112
|
}
|
|
114
113
|
#findRuntimeApiSpec = (runtimeApiHash, version) => {
|
|
115
|
-
const runtimeApiName = (0, specs_1.getRuntimeApiNames)().find((one) => (0, utils_1.
|
|
114
|
+
const runtimeApiName = (0, specs_1.getRuntimeApiNames)().find((one) => (0, utils_1.calcRuntimeApiHash)(one) === runtimeApiHash);
|
|
116
115
|
return (0, specs_1.getRuntimeApiSpecs)().find((one) => one.runtimeApiName === runtimeApiName && one.version === version);
|
|
117
116
|
};
|
|
118
117
|
}
|
package/cjs/generator/TxGen.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TxGen = void 0;
|
|
4
4
|
const index_js_1 = require("../generator/index.js");
|
|
5
|
-
const
|
|
5
|
+
const utils_1 = require("@dedot/utils");
|
|
6
6
|
const utils_js_1 = require("./utils.js");
|
|
7
7
|
class TxGen extends index_js_1.ApiGen {
|
|
8
8
|
generate() {
|
|
@@ -26,9 +26,9 @@ class TxGen extends index_js_1.ApiGen {
|
|
|
26
26
|
const isFlatEnum = type.value.members.every((m) => m.fields.length === 0);
|
|
27
27
|
const typedTxs = type.value.members
|
|
28
28
|
.map((one) => ({
|
|
29
|
-
functionName: (0,
|
|
29
|
+
functionName: (0, utils_1.stringCamelCase)(one.name),
|
|
30
30
|
params: one.fields.map((f) => ({
|
|
31
|
-
name: (0,
|
|
31
|
+
name: (0, utils_1.stringCamelCase)(f.name),
|
|
32
32
|
normalizedName: this.#normalizeParamName(f.name),
|
|
33
33
|
type: this.typesGen.generateType(f.typeId, 1),
|
|
34
34
|
docs: f.docs,
|
|
@@ -38,11 +38,11 @@ class TxGen extends index_js_1.ApiGen {
|
|
|
38
38
|
.map((f) => {
|
|
39
39
|
return {
|
|
40
40
|
...f,
|
|
41
|
-
callInput: this.#generateCallInput((0,
|
|
41
|
+
callInput: this.#generateCallInput((0, utils_1.stringPascalCase)(pallet.name), (0, utils_1.stringPascalCase)(f.functionName), !isFlatEnum ? f.params.map((p) => `${p.name}: ${p.type}`) : undefined),
|
|
42
42
|
};
|
|
43
43
|
});
|
|
44
44
|
txDefsOut += (0, utils_js_1.commentBlock)(`Pallet \`${pallet.name}\`'s transaction calls`);
|
|
45
|
-
txDefsOut += `${(0,
|
|
45
|
+
txDefsOut += `${(0, utils_1.stringCamelCase)(pallet.name)}: {
|
|
46
46
|
${typedTxs
|
|
47
47
|
.map(({ functionName, params, docs, callInput }) => `${(0, utils_js_1.commentBlock)(docs, '\n', params.map((p) => `@param {${p.type}} ${p.normalizedName} ${p.docs}`))}${functionName}: GenericTxCall<(${params.map((p) => `${p.normalizedName}: ${p.type}`).join(', ')}) => ChainSubmittableExtrinsic<${callInput}>>`)
|
|
48
48
|
.join(',\n')}
|
|
@@ -63,7 +63,7 @@ class TxGen extends index_js_1.ApiGen {
|
|
|
63
63
|
return (0, utils_js_1.beautifySourceCode)(template({ importTypes, defTypes, txDefsOut }));
|
|
64
64
|
}
|
|
65
65
|
#normalizeParamName(name) {
|
|
66
|
-
name = (0,
|
|
66
|
+
name = (0, utils_1.stringCamelCase)(name);
|
|
67
67
|
return (0, utils_js_1.isReservedWord)(name) ? `${name}_` : name;
|
|
68
68
|
}
|
|
69
69
|
#generateCallInput(palletName, callName, params) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TypesGen = exports.BASIC_KNOWN_TYPES = void 0;
|
|
4
|
-
const util_1 = require("@polkadot/util");
|
|
5
4
|
const codecs_1 = require("@dedot/codecs");
|
|
6
5
|
const utils_1 = require("@dedot/utils");
|
|
7
6
|
const utils_js_1 = require("./utils.js");
|
|
@@ -151,12 +150,12 @@ class TypesGen {
|
|
|
151
150
|
return 'null';
|
|
152
151
|
}
|
|
153
152
|
else if (members.every((x) => x.fields.length === 0)) {
|
|
154
|
-
return members.map(({ name, docs }) => `${(0, utils_js_1.commentBlock)(docs)}'${(0,
|
|
153
|
+
return members.map(({ name, docs }) => `${(0, utils_js_1.commentBlock)(docs)}'${(0, utils_1.stringPascalCase)(name)}'`).join(' | ');
|
|
155
154
|
}
|
|
156
155
|
else {
|
|
157
156
|
const membersType = [];
|
|
158
157
|
for (const { fields, name, docs } of members) {
|
|
159
|
-
const keyName = (0,
|
|
158
|
+
const keyName = (0, utils_1.stringPascalCase)(name);
|
|
160
159
|
if (fields.length === 0) {
|
|
161
160
|
membersType.push([keyName, null, docs]);
|
|
162
161
|
}
|
|
@@ -315,7 +314,7 @@ class TypesGen {
|
|
|
315
314
|
*/
|
|
316
315
|
#cleanPath(path) {
|
|
317
316
|
return path
|
|
318
|
-
.map((one) => (0,
|
|
317
|
+
.map((one) => (0, utils_1.stringPascalCase)(one))
|
|
319
318
|
.filter((one, idx, currentPath) => idx === 0 || one !== currentPath[idx - 1])
|
|
320
319
|
.join('');
|
|
321
320
|
}
|
|
@@ -390,10 +389,10 @@ class TypesGen {
|
|
|
390
389
|
if (diffParam?.typeId) {
|
|
391
390
|
const diffType = types[diffParam.typeId];
|
|
392
391
|
if (diffType.path.length > 0) {
|
|
393
|
-
return (0,
|
|
392
|
+
return (0, utils_1.stringPascalCase)(diffType.path.at(-1));
|
|
394
393
|
}
|
|
395
394
|
else if (diffType.type.tag === 'Primitive') {
|
|
396
|
-
return (0,
|
|
395
|
+
return (0, utils_1.stringPascalCase)(diffType.type.value.kind);
|
|
397
396
|
}
|
|
398
397
|
}
|
|
399
398
|
// Last resort!
|
|
@@ -404,7 +403,7 @@ class TypesGen {
|
|
|
404
403
|
typeName.forEach((one) => this.addTypeImport(one));
|
|
405
404
|
return;
|
|
406
405
|
}
|
|
407
|
-
if ((0,
|
|
406
|
+
if ((0, utils_js_1.isNativeType)(typeName)) {
|
|
408
407
|
return;
|
|
409
408
|
}
|
|
410
409
|
for (let type of Object.values(this.includedTypes)) {
|
package/cjs/generator/utils.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.isReservedWord = exports.compileTemplate = exports.beautifySourceCode = exports.commentBlock = exports.TUPLE_TYPE_REGEX = exports.WRAPPER_TYPE_REGEX = void 0;
|
|
29
|
+
exports.isNativeType = exports.isReservedWord = exports.compileTemplate = exports.beautifySourceCode = exports.commentBlock = exports.TUPLE_TYPE_REGEX = exports.WRAPPER_TYPE_REGEX = void 0;
|
|
30
30
|
const fs = __importStar(require("fs"));
|
|
31
31
|
const handlebars_1 = __importDefault(require("handlebars"));
|
|
32
32
|
const path = __importStar(require("path"));
|
|
@@ -66,3 +66,32 @@ const TS_RESERVED_WORDS = ['new', 'class'];
|
|
|
66
66
|
*/
|
|
67
67
|
const isReservedWord = (word) => TS_RESERVED_WORDS.includes(word);
|
|
68
68
|
exports.isReservedWord = isReservedWord;
|
|
69
|
+
const TS_PRIMITIVE_TYPES = [
|
|
70
|
+
'void',
|
|
71
|
+
'undefined',
|
|
72
|
+
'null',
|
|
73
|
+
'number',
|
|
74
|
+
'boolean',
|
|
75
|
+
'bigint',
|
|
76
|
+
'Map',
|
|
77
|
+
'Set',
|
|
78
|
+
'string',
|
|
79
|
+
'any',
|
|
80
|
+
'Array',
|
|
81
|
+
'Record',
|
|
82
|
+
];
|
|
83
|
+
/**
|
|
84
|
+
* Check if a type is native JS/TS type
|
|
85
|
+
* @param type
|
|
86
|
+
*/
|
|
87
|
+
const isNativeType = (type) => {
|
|
88
|
+
return TS_PRIMITIVE_TYPES.some((one) => {
|
|
89
|
+
if (typeof one === 'string') {
|
|
90
|
+
return one === type;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
return type.match(one);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
exports.isNativeType = isNativeType;
|
package/cjs/index.js
CHANGED
|
@@ -23,25 +23,25 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.generateTypes = exports.
|
|
26
|
+
exports.generateTypes = exports.generateTypesFromEndpoint = void 0;
|
|
27
27
|
const dedot_1 = require("dedot");
|
|
28
28
|
const fs = __importStar(require("fs"));
|
|
29
29
|
const path = __importStar(require("path"));
|
|
30
30
|
const index_js_1 = require("./generator/index.js");
|
|
31
|
-
const
|
|
32
|
-
async function
|
|
33
|
-
const api = await dedot_1.Dedot.
|
|
31
|
+
const utils_1 = require("@dedot/utils");
|
|
32
|
+
async function generateTypesFromEndpoint(chain, endpoint, outDir) {
|
|
33
|
+
const api = await dedot_1.Dedot.new(endpoint);
|
|
34
34
|
const { methods } = await api.rpc.rpc.methods();
|
|
35
35
|
const apis = api.runtimeVersion?.apis || [];
|
|
36
|
-
if (!
|
|
37
|
-
|
|
36
|
+
if (!chain) {
|
|
37
|
+
chain = (0, utils_1.stringCamelCase)(api.runtimeVersion?.specName || api.runtimeChain || 'local');
|
|
38
38
|
}
|
|
39
|
-
await generateTypes(
|
|
39
|
+
await generateTypes(chain, api.metadataLatest, methods, apis, outDir);
|
|
40
40
|
await api.disconnect();
|
|
41
41
|
}
|
|
42
|
-
exports.
|
|
43
|
-
async function generateTypes(
|
|
44
|
-
const dirPath = path.resolve(outDir,
|
|
42
|
+
exports.generateTypesFromEndpoint = generateTypesFromEndpoint;
|
|
43
|
+
async function generateTypes(chain, metadata, rpcMethods, runtimeApis, outDir = '.') {
|
|
44
|
+
const dirPath = path.resolve(outDir, chain);
|
|
45
45
|
const defTypesFileName = path.join(dirPath, `types.d.ts`);
|
|
46
46
|
const constsTypesFileName = path.join(dirPath, `consts.d.ts`);
|
|
47
47
|
const queryTypesFileName = path.join(dirPath, `query.d.ts`);
|
|
@@ -58,7 +58,7 @@ async function generateTypes(network, metadata, rpcMethods, runtimeApis, outDir
|
|
|
58
58
|
const constsGen = new index_js_1.ConstsGen(typesGen);
|
|
59
59
|
const queryGen = new index_js_1.QueryGen(typesGen);
|
|
60
60
|
const rpcGen = new index_js_1.RpcGen(typesGen, rpcMethods);
|
|
61
|
-
const indexGen = new index_js_1.IndexGen(
|
|
61
|
+
const indexGen = new index_js_1.IndexGen(chain);
|
|
62
62
|
const errorsGen = new index_js_1.ErrorsGen(typesGen);
|
|
63
63
|
const eventsGen = new index_js_1.EventsGen(typesGen);
|
|
64
64
|
const runtimeApisGen = new index_js_1.RuntimeApisGen(typesGen, runtimeApis);
|
package/generator/ConstsGen.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { normalizeName } from '@dedot/utils';
|
|
1
|
+
import { normalizeName, stringCamelCase } from '@dedot/utils';
|
|
3
2
|
import { ApiGen } from '../generator/index.js';
|
|
4
3
|
import { beautifySourceCode, commentBlock, compileTemplate } from './utils.js';
|
|
5
4
|
export class ConstsGen extends ApiGen {
|
|
@@ -15,7 +14,7 @@ export class ConstsGen extends ApiGen {
|
|
|
15
14
|
docs: one.docs,
|
|
16
15
|
}));
|
|
17
16
|
defTypeOut += commentBlock(`Pallet \`${pallet.name}\`'s constants`);
|
|
18
|
-
defTypeOut += `${
|
|
17
|
+
defTypeOut += `${stringCamelCase(pallet.name)}: {
|
|
19
18
|
${typedConstants.map(({ name, type, docs }) => `${commentBlock(docs)}${name}: ${type}`).join(',\n')}
|
|
20
19
|
|
|
21
20
|
${commentBlock('Generic pallet constant')}[name: string]: any,
|
package/generator/ErrorsGen.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ApiGen } from './ApiGen.js';
|
|
2
2
|
import { beautifySourceCode, commentBlock, compileTemplate } from './utils.js';
|
|
3
|
-
import { stringCamelCase, stringPascalCase } from '@
|
|
4
|
-
import { assert } from '@dedot/utils';
|
|
3
|
+
import { assert, stringCamelCase, stringPascalCase } from '@dedot/utils';
|
|
5
4
|
export class ErrorsGen extends ApiGen {
|
|
6
5
|
generate() {
|
|
7
6
|
const { pallets } = this.metadata;
|
package/generator/EventsGen.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ApiGen } from './ApiGen.js';
|
|
2
2
|
import { beautifySourceCode, commentBlock, compileTemplate } from './utils.js';
|
|
3
|
-
import { stringCamelCase, stringPascalCase } from '@
|
|
4
|
-
import { assert } from '@dedot/utils';
|
|
3
|
+
import { assert, stringCamelCase, stringPascalCase } from '@dedot/utils';
|
|
5
4
|
export class EventsGen extends ApiGen {
|
|
6
5
|
generate() {
|
|
7
6
|
const { pallets } = this.metadata;
|
package/generator/IndexGen.d.ts
CHANGED
package/generator/IndexGen.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { beautifySourceCode, compileTemplate } from './utils.js';
|
|
2
|
-
import { stringPascalCase } from '@
|
|
2
|
+
import { stringPascalCase } from '@dedot/utils';
|
|
3
3
|
export class IndexGen {
|
|
4
|
-
|
|
5
|
-
constructor(
|
|
6
|
-
this.
|
|
4
|
+
chain;
|
|
5
|
+
constructor(chain) {
|
|
6
|
+
this.chain = chain;
|
|
7
7
|
}
|
|
8
8
|
async generate() {
|
|
9
|
-
const
|
|
10
|
-
const interfaceName = stringPascalCase(chain);
|
|
9
|
+
const interfaceName = stringPascalCase(this.chain);
|
|
11
10
|
const template = compileTemplate('index.hbs');
|
|
12
11
|
return beautifySourceCode(template({ interfaceName }));
|
|
13
12
|
}
|
package/generator/QueryGen.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { normalizeName } from '@dedot/utils';
|
|
1
|
+
import { normalizeName, stringCamelCase } from '@dedot/utils';
|
|
3
2
|
import { ApiGen } from '../generator/index.js';
|
|
4
3
|
import { beautifySourceCode, commentBlock, compileTemplate } from './utils.js';
|
|
5
4
|
export class QueryGen extends ApiGen {
|
|
@@ -15,7 +14,7 @@ export class QueryGen extends ApiGen {
|
|
|
15
14
|
const queries = storage.entries.map((one) => this.#generateEntry(one));
|
|
16
15
|
const queryDefs = queries.map(({ name, valueType, keyType, docs }) => `${commentBlock(docs)}${name}: GenericStorageQuery<(${keyType}) => ${valueType}>`);
|
|
17
16
|
defTypeOut += commentBlock(`Pallet \`${pallet.name}\`'s storage queries`);
|
|
18
|
-
defTypeOut += `${
|
|
17
|
+
defTypeOut += `${stringCamelCase(pallet.name)}: {
|
|
19
18
|
${queryDefs.join(',\n')}
|
|
20
19
|
|
|
21
20
|
${commentBlock('Generic pallet storage query')}[storage: string]: GenericStorageQuery;
|
package/generator/RpcGen.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { findAliasRpcSpec, findRpcSpec, isUnsubscribeMethod } from '@dedot/specs';
|
|
2
|
-
import { isNativeType } from '@dedot/utils';
|
|
3
2
|
import { ApiGen } from '../generator/index.js';
|
|
4
|
-
import { beautifySourceCode, commentBlock, compileTemplate, TUPLE_TYPE_REGEX, WRAPPER_TYPE_REGEX } from './utils.js';
|
|
3
|
+
import { isNativeType, beautifySourceCode, commentBlock, compileTemplate, TUPLE_TYPE_REGEX, WRAPPER_TYPE_REGEX, } from './utils.js';
|
|
5
4
|
import { findKnownCodecType } from './known-codecs.js';
|
|
6
5
|
const HIDDEN_RPCS = [
|
|
7
6
|
// Ref: https://github.com/paritytech/polkadot-sdk/blob/43415ef58c143b985e09015cd000dbd65f6d3997/substrate/client/rpc-servers/src/lib.rs#L152C9-L158
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { getRuntimeApiNames, getRuntimeApiSpecs } from '@dedot/specs';
|
|
2
2
|
import { beautifySourceCode, commentBlock, compileTemplate } from './utils.js';
|
|
3
|
-
import {
|
|
3
|
+
import { calcRuntimeApiHash, stringSnakeCase, stringCamelCase } from '@dedot/utils';
|
|
4
4
|
import { RpcGen } from './RpcGen.js';
|
|
5
|
-
import { stringCamelCase } from '@polkadot/util';
|
|
6
5
|
export class RuntimeApisGen extends RpcGen {
|
|
7
6
|
typesGen;
|
|
8
7
|
runtimeApis;
|
|
@@ -18,7 +17,7 @@ export class RuntimeApisGen extends RpcGen {
|
|
|
18
17
|
if (this.metadata.apis.length > 0) {
|
|
19
18
|
this.metadata.apis.forEach((runtimeApi) => {
|
|
20
19
|
const { name: runtimeApiName, methods } = runtimeApi;
|
|
21
|
-
runtimeCallsOut += commentBlock(`@runtimeapi: ${runtimeApiName} - ${
|
|
20
|
+
runtimeCallsOut += commentBlock(`@runtimeapi: ${runtimeApiName} - ${calcRuntimeApiHash(runtimeApiName)}`);
|
|
22
21
|
runtimeCallsOut += `${stringCamelCase(runtimeApiName)}: {
|
|
23
22
|
${methods.map((method) => this.#generateMethodDef(runtimeApiName, method)).join('\n')}
|
|
24
23
|
|
|
@@ -109,7 +108,7 @@ export class RuntimeApisGen extends RpcGen {
|
|
|
109
108
|
}, []);
|
|
110
109
|
}
|
|
111
110
|
#findRuntimeApiSpec = (runtimeApiHash, version) => {
|
|
112
|
-
const runtimeApiName = getRuntimeApiNames().find((one) =>
|
|
111
|
+
const runtimeApiName = getRuntimeApiNames().find((one) => calcRuntimeApiHash(one) === runtimeApiHash);
|
|
113
112
|
return getRuntimeApiSpecs().find((one) => one.runtimeApiName === runtimeApiName && one.version === version);
|
|
114
113
|
};
|
|
115
114
|
}
|
package/generator/TxGen.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ApiGen } from '../generator/index.js';
|
|
2
|
-
import { stringCamelCase, stringPascalCase } from '@
|
|
2
|
+
import { stringCamelCase, stringPascalCase } from '@dedot/utils';
|
|
3
3
|
import { beautifySourceCode, commentBlock, compileTemplate, isReservedWord } from './utils.js';
|
|
4
4
|
export class TxGen extends ApiGen {
|
|
5
5
|
generate() {
|
package/generator/TypesGen.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { stringPascalCase } from '@polkadot/util';
|
|
2
1
|
import { PortableRegistry } from '@dedot/codecs';
|
|
3
|
-
import {
|
|
4
|
-
import { beautifySourceCode, commentBlock, compileTemplate } from './utils.js';
|
|
2
|
+
import { normalizeName, stringPascalCase } from '@dedot/utils';
|
|
3
|
+
import { isNativeType, beautifySourceCode, commentBlock, compileTemplate } from './utils.js';
|
|
5
4
|
import { knownTypes } from './known-types.js';
|
|
6
5
|
import { TypeImports } from './TypeImports.js';
|
|
7
6
|
import { findKnownCodec, findKnownCodecType, isKnownCodecType } from './known-codecs.js';
|
package/generator/utils.d.ts
CHANGED
|
@@ -8,3 +8,8 @@ export declare const compileTemplate: (templateFileName: string) => HandlebarsTe
|
|
|
8
8
|
* @param word
|
|
9
9
|
*/
|
|
10
10
|
export declare const isReservedWord: (word: string) => boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Check if a type is native JS/TS type
|
|
13
|
+
* @param type
|
|
14
|
+
*/
|
|
15
|
+
export declare const isNativeType: (type: string) => boolean;
|
package/generator/utils.js
CHANGED
|
@@ -33,3 +33,31 @@ const TS_RESERVED_WORDS = ['new', 'class'];
|
|
|
33
33
|
* @param word
|
|
34
34
|
*/
|
|
35
35
|
export const isReservedWord = (word) => TS_RESERVED_WORDS.includes(word);
|
|
36
|
+
const TS_PRIMITIVE_TYPES = [
|
|
37
|
+
'void',
|
|
38
|
+
'undefined',
|
|
39
|
+
'null',
|
|
40
|
+
'number',
|
|
41
|
+
'boolean',
|
|
42
|
+
'bigint',
|
|
43
|
+
'Map',
|
|
44
|
+
'Set',
|
|
45
|
+
'string',
|
|
46
|
+
'any',
|
|
47
|
+
'Array',
|
|
48
|
+
'Record',
|
|
49
|
+
];
|
|
50
|
+
/**
|
|
51
|
+
* Check if a type is native JS/TS type
|
|
52
|
+
* @param type
|
|
53
|
+
*/
|
|
54
|
+
export const isNativeType = (type) => {
|
|
55
|
+
return TS_PRIMITIVE_TYPES.some((one) => {
|
|
56
|
+
if (typeof one === 'string') {
|
|
57
|
+
return one === type;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
return type.match(one);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
};
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { MetadataLatest } from '@dedot/codecs';
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function generateTypes(network: NetworkInfo, metadata: MetadataLatest, rpcMethods: string[], runtimeApis: any[], outDir?: string): Promise<void>;
|
|
2
|
+
export declare function generateTypesFromEndpoint(chain: string, endpoint: string, outDir?: string): Promise<void>;
|
|
3
|
+
export declare function generateTypes(chain: string, metadata: MetadataLatest, rpcMethods: string[], runtimeApis: any[], outDir?: string): Promise<void>;
|
package/index.js
CHANGED
|
@@ -2,19 +2,19 @@ import { Dedot } from 'dedot';
|
|
|
2
2
|
import * as fs from 'fs';
|
|
3
3
|
import * as path from 'path';
|
|
4
4
|
import { ConstsGen, ErrorsGen, EventsGen, IndexGen, QueryGen, RpcGen, RuntimeApisGen, TxGen, TypesGen, } from './generator/index.js';
|
|
5
|
-
import { stringCamelCase } from '@
|
|
6
|
-
export async function
|
|
7
|
-
const api = await Dedot.
|
|
5
|
+
import { stringCamelCase } from '@dedot/utils';
|
|
6
|
+
export async function generateTypesFromEndpoint(chain, endpoint, outDir) {
|
|
7
|
+
const api = await Dedot.new(endpoint);
|
|
8
8
|
const { methods } = await api.rpc.rpc.methods();
|
|
9
9
|
const apis = api.runtimeVersion?.apis || [];
|
|
10
|
-
if (!
|
|
11
|
-
|
|
10
|
+
if (!chain) {
|
|
11
|
+
chain = stringCamelCase(api.runtimeVersion?.specName || api.runtimeChain || 'local');
|
|
12
12
|
}
|
|
13
|
-
await generateTypes(
|
|
13
|
+
await generateTypes(chain, api.metadataLatest, methods, apis, outDir);
|
|
14
14
|
await api.disconnect();
|
|
15
15
|
}
|
|
16
|
-
export async function generateTypes(
|
|
17
|
-
const dirPath = path.resolve(outDir,
|
|
16
|
+
export async function generateTypes(chain, metadata, rpcMethods, runtimeApis, outDir = '.') {
|
|
17
|
+
const dirPath = path.resolve(outDir, chain);
|
|
18
18
|
const defTypesFileName = path.join(dirPath, `types.d.ts`);
|
|
19
19
|
const constsTypesFileName = path.join(dirPath, `consts.d.ts`);
|
|
20
20
|
const queryTypesFileName = path.join(dirPath, `query.d.ts`);
|
|
@@ -31,7 +31,7 @@ export async function generateTypes(network, metadata, rpcMethods, runtimeApis,
|
|
|
31
31
|
const constsGen = new ConstsGen(typesGen);
|
|
32
32
|
const queryGen = new QueryGen(typesGen);
|
|
33
33
|
const rpcGen = new RpcGen(typesGen, rpcMethods);
|
|
34
|
-
const indexGen = new IndexGen(
|
|
34
|
+
const indexGen = new IndexGen(chain);
|
|
35
35
|
const errorsGen = new ErrorsGen(typesGen);
|
|
36
36
|
const eventsGen = new EventsGen(typesGen);
|
|
37
37
|
const runtimeApisGen = new RuntimeApisGen(typesGen, runtimeApis);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dedot/codegen",
|
|
3
|
-
"version": "0.0.1-next.
|
|
3
|
+
"version": "0.0.1-next.70fc26c6.11+70fc26c",
|
|
4
4
|
"description": "Generate types",
|
|
5
5
|
"author": "Thang X. Vu <thang@coongcrafts.io>",
|
|
6
6
|
"homepage": "https://github.com/dedotdev/dedot/tree/main/packages/codegen",
|
|
@@ -18,12 +18,11 @@
|
|
|
18
18
|
"copy": "cp -R ./src/templates ./dist && cp -R ./src/templates ./dist/cjs"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@dedot/codecs": "0.0.1-next.
|
|
22
|
-
"@dedot/shape": "0.0.1-next.
|
|
23
|
-
"@dedot/specs": "0.0.1-next.
|
|
24
|
-
"@dedot/utils": "0.0.1-next.
|
|
25
|
-
"
|
|
26
|
-
"dedot": "0.0.1-next.6cd3bbb0.6+6cd3bbb",
|
|
21
|
+
"@dedot/codecs": "0.0.1-next.70fc26c6.11+70fc26c",
|
|
22
|
+
"@dedot/shape": "0.0.1-next.70fc26c6.11+70fc26c",
|
|
23
|
+
"@dedot/specs": "0.0.1-next.70fc26c6.11+70fc26c",
|
|
24
|
+
"@dedot/utils": "0.0.1-next.70fc26c6.11+70fc26c",
|
|
25
|
+
"dedot": "0.0.1-next.70fc26c6.11+70fc26c",
|
|
27
26
|
"handlebars": "^4.7.8",
|
|
28
27
|
"prettier": "^3.0.3"
|
|
29
28
|
},
|
|
@@ -32,7 +31,7 @@
|
|
|
32
31
|
"directory": "dist"
|
|
33
32
|
},
|
|
34
33
|
"license": "Apache-2.0",
|
|
35
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "70fc26c6203468dad24de97361eae314cab3b32b",
|
|
36
35
|
"module": "./index.js",
|
|
37
36
|
"types": "./index.d.ts",
|
|
38
37
|
"exports": {
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const index_js_1 = require("./index.js");
|
|
7
|
-
const static_substrate_1 = require("@polkadot/types-support/metadata/static-substrate");
|
|
8
|
-
const substrate_hex_1 = __importDefault(require("@polkadot/types-support/metadata/v15/substrate-hex"));
|
|
9
|
-
const codecs_1 = require("@dedot/codecs");
|
|
10
|
-
const dedot_1 = require("dedot");
|
|
11
|
-
const NETWORKS = [
|
|
12
|
-
{
|
|
13
|
-
chain: 'substrate',
|
|
14
|
-
metadataHex: substrate_hex_1.default,
|
|
15
|
-
rpcMethods: static_substrate_1.rpc.methods,
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
chain: 'polkadot',
|
|
19
|
-
endpoint: 'wss://rpc.polkadot.io',
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
chain: 'kusama',
|
|
23
|
-
endpoint: 'wss://kusama-rpc.polkadot.io',
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
chain: 'astar',
|
|
27
|
-
endpoint: 'wss://rpc.astar.network',
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
chain: 'moonbeam',
|
|
31
|
-
endpoint: 'wss://moonbeam.api.onfinality.io/public-ws',
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
chain: 'polkadotAssetHub',
|
|
35
|
-
endpoint: 'wss://polkadot-asset-hub-rpc.polkadot.io/',
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
chain: 'kusamaAssetHub',
|
|
39
|
-
endpoint: 'wss://kusama-asset-hub-rpc.polkadot.io/',
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
chain: 'rococo',
|
|
43
|
-
endpoint: 'wss://rococo-rpc.polkadot.io/',
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
chain: 'rococoAssetHub',
|
|
47
|
-
endpoint: 'wss://rococo-asset-hub-rpc.polkadot.io/',
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
chain: 'aleph',
|
|
51
|
-
endpoint: 'wss://aleph-zero.api.onfinality.io/public-ws',
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
chain: 'westendAssetHub',
|
|
55
|
-
endpoint: 'wss://westend-asset-hub-rpc.polkadot.io',
|
|
56
|
-
},
|
|
57
|
-
];
|
|
58
|
-
const OUT_DIR = 'packages/chaintypes/src';
|
|
59
|
-
async function run() {
|
|
60
|
-
for (const network of NETWORKS) {
|
|
61
|
-
const { chain, endpoint, metadataHex, rpcMethods } = network;
|
|
62
|
-
if (endpoint) {
|
|
63
|
-
console.log(`Generate types for ${chain} via endpoint ${endpoint}`);
|
|
64
|
-
await (0, index_js_1.generateTypesFromChain)(network, endpoint, OUT_DIR);
|
|
65
|
-
}
|
|
66
|
-
else if (metadataHex && rpcMethods) {
|
|
67
|
-
console.log(`Generate types for ${chain} via raw data`);
|
|
68
|
-
const metadata = codecs_1.$Metadata.tryDecode(metadataHex);
|
|
69
|
-
const runtimeVersion = getRuntimeVersion(metadata);
|
|
70
|
-
await (0, index_js_1.generateTypes)(network, metadata.latest, rpcMethods, runtimeVersion.apis, OUT_DIR);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
console.log('DONE!');
|
|
74
|
-
}
|
|
75
|
-
const getRuntimeVersion = (metadata) => {
|
|
76
|
-
const registry = new codecs_1.PortableRegistry(metadata.latest);
|
|
77
|
-
const executor = new dedot_1.ConstantExecutor({
|
|
78
|
-
registry,
|
|
79
|
-
metadataLatest: metadata.latest,
|
|
80
|
-
});
|
|
81
|
-
return executor.execute('system', 'version');
|
|
82
|
-
};
|
|
83
|
-
run().catch(console.log);
|
package/cjs/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { generateTypes, generateTypesFromChain } from './index.js';
|
|
2
|
-
import { rpc } from '@polkadot/types-support/metadata/static-substrate';
|
|
3
|
-
import staticSubstrate from '@polkadot/types-support/metadata/v15/substrate-hex';
|
|
4
|
-
import { $Metadata, PortableRegistry } from '@dedot/codecs';
|
|
5
|
-
import { ConstantExecutor } from 'dedot';
|
|
6
|
-
const NETWORKS = [
|
|
7
|
-
{
|
|
8
|
-
chain: 'substrate',
|
|
9
|
-
metadataHex: staticSubstrate,
|
|
10
|
-
rpcMethods: rpc.methods,
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
chain: 'polkadot',
|
|
14
|
-
endpoint: 'wss://rpc.polkadot.io',
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
chain: 'kusama',
|
|
18
|
-
endpoint: 'wss://kusama-rpc.polkadot.io',
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
chain: 'astar',
|
|
22
|
-
endpoint: 'wss://rpc.astar.network',
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
chain: 'moonbeam',
|
|
26
|
-
endpoint: 'wss://moonbeam.api.onfinality.io/public-ws',
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
chain: 'polkadotAssetHub',
|
|
30
|
-
endpoint: 'wss://polkadot-asset-hub-rpc.polkadot.io/',
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
chain: 'kusamaAssetHub',
|
|
34
|
-
endpoint: 'wss://kusama-asset-hub-rpc.polkadot.io/',
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
chain: 'rococo',
|
|
38
|
-
endpoint: 'wss://rococo-rpc.polkadot.io/',
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
chain: 'rococoAssetHub',
|
|
42
|
-
endpoint: 'wss://rococo-asset-hub-rpc.polkadot.io/',
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
chain: 'aleph',
|
|
46
|
-
endpoint: 'wss://aleph-zero.api.onfinality.io/public-ws',
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
chain: 'westendAssetHub',
|
|
50
|
-
endpoint: 'wss://westend-asset-hub-rpc.polkadot.io',
|
|
51
|
-
},
|
|
52
|
-
];
|
|
53
|
-
const OUT_DIR = 'packages/chaintypes/src';
|
|
54
|
-
async function run() {
|
|
55
|
-
for (const network of NETWORKS) {
|
|
56
|
-
const { chain, endpoint, metadataHex, rpcMethods } = network;
|
|
57
|
-
if (endpoint) {
|
|
58
|
-
console.log(`Generate types for ${chain} via endpoint ${endpoint}`);
|
|
59
|
-
await generateTypesFromChain(network, endpoint, OUT_DIR);
|
|
60
|
-
}
|
|
61
|
-
else if (metadataHex && rpcMethods) {
|
|
62
|
-
console.log(`Generate types for ${chain} via raw data`);
|
|
63
|
-
const metadata = $Metadata.tryDecode(metadataHex);
|
|
64
|
-
const runtimeVersion = getRuntimeVersion(metadata);
|
|
65
|
-
await generateTypes(network, metadata.latest, rpcMethods, runtimeVersion.apis, OUT_DIR);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
console.log('DONE!');
|
|
69
|
-
}
|
|
70
|
-
const getRuntimeVersion = (metadata) => {
|
|
71
|
-
const registry = new PortableRegistry(metadata.latest);
|
|
72
|
-
const executor = new ConstantExecutor({
|
|
73
|
-
registry,
|
|
74
|
-
metadataLatest: metadata.latest,
|
|
75
|
-
});
|
|
76
|
-
return executor.execute('system', 'version');
|
|
77
|
-
};
|
|
78
|
-
run().catch(console.log);
|
package/types.d.ts
DELETED
package/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|