@dedot/codegen 0.0.1-next.0a597de3.0 → 0.0.1-next.2d39ff2d.5
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/genSupportedChainTypes.js +3 -3
- package/cjs/generator/ConstsGen.js +8 -8
- package/cjs/generator/ErrorsGen.js +11 -11
- package/cjs/generator/EventsGen.js +12 -12
- package/cjs/generator/IndexGen.js +3 -3
- package/cjs/generator/QueryGen.js +8 -8
- package/cjs/generator/RpcGen.js +16 -16
- package/cjs/generator/RuntimeApisGen.js +15 -15
- package/cjs/generator/TxGen.js +9 -9
- package/cjs/generator/TypesGen.js +16 -16
- package/cjs/generator/index.js +10 -10
- package/cjs/index.js +10 -10
- package/cjs/packageInfo.js +1 -1
- package/genSupportedChainTypes.js +1 -1
- package/generator/ApiGen.d.ts +1 -1
- package/generator/ConstsGen.d.ts +1 -1
- package/generator/ConstsGen.js +2 -2
- package/generator/ErrorsGen.d.ts +1 -1
- package/generator/ErrorsGen.js +2 -2
- package/generator/EventsGen.d.ts +1 -1
- package/generator/EventsGen.js +2 -2
- package/generator/IndexGen.d.ts +1 -1
- package/generator/IndexGen.js +1 -1
- package/generator/QueryGen.d.ts +1 -1
- package/generator/QueryGen.js +2 -2
- package/generator/RpcGen.d.ts +1 -1
- package/generator/RpcGen.js +3 -3
- package/generator/RuntimeApisGen.d.ts +2 -2
- package/generator/RuntimeApisGen.js +2 -2
- package/generator/TxGen.d.ts +1 -1
- package/generator/TxGen.js +2 -2
- package/generator/TypesGen.d.ts +1 -1
- package/generator/TypesGen.js +4 -4
- package/generator/index.d.ts +10 -10
- package/generator/index.js +10 -10
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +7 -7
- package/packageInfo.js +1 -1
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
6
|
+
const index_js_1 = require("./index.js");
|
|
7
7
|
const static_substrate_1 = require("@polkadot/types-support/metadata/static-substrate");
|
|
8
8
|
const substrate_hex_1 = __importDefault(require("@polkadot/types-support/metadata/v15/substrate-hex"));
|
|
9
9
|
const codecs_1 = require("@dedot/codecs");
|
|
@@ -61,13 +61,13 @@ async function run() {
|
|
|
61
61
|
const { chain, endpoint, metadataHex, rpcMethods } = network;
|
|
62
62
|
if (endpoint) {
|
|
63
63
|
console.log(`Generate types for ${chain} via endpoint ${endpoint}`);
|
|
64
|
-
await (0,
|
|
64
|
+
await (0, index_js_1.generateTypesFromChain)(network, endpoint, OUT_DIR);
|
|
65
65
|
}
|
|
66
66
|
else if (metadataHex && rpcMethods) {
|
|
67
67
|
console.log(`Generate types for ${chain} via raw data`);
|
|
68
68
|
const metadata = codecs_1.$Metadata.tryDecode(metadataHex);
|
|
69
69
|
const runtimeVersion = getRuntimeVersion(metadata);
|
|
70
|
-
await (0,
|
|
70
|
+
await (0, index_js_1.generateTypes)(network, metadata.latest, rpcMethods, runtimeVersion.apis, OUT_DIR);
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
console.log('DONE!');
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ConstsGen = void 0;
|
|
4
4
|
const util_1 = require("@polkadot/util");
|
|
5
5
|
const utils_1 = require("@dedot/utils");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
class ConstsGen extends
|
|
6
|
+
const index_js_1 = require("../generator/index.js");
|
|
7
|
+
const utils_js_1 = require("./utils.js");
|
|
8
|
+
class ConstsGen extends index_js_1.ApiGen {
|
|
9
9
|
generate() {
|
|
10
10
|
const { pallets } = this.metadata;
|
|
11
11
|
this.typesGen.clearCache();
|
|
@@ -17,16 +17,16 @@ class ConstsGen extends generator_1.ApiGen {
|
|
|
17
17
|
type: this.typesGen.generateType(one.typeId, 1, true),
|
|
18
18
|
docs: one.docs,
|
|
19
19
|
}));
|
|
20
|
-
defTypeOut += (0,
|
|
20
|
+
defTypeOut += (0, utils_js_1.commentBlock)(`Pallet \`${pallet.name}\`'s constants`);
|
|
21
21
|
defTypeOut += `${(0, util_1.stringLowerFirst)(pallet.name)}: {
|
|
22
|
-
${typedConstants.map(({ name, type, docs }) => `${(0,
|
|
22
|
+
${typedConstants.map(({ name, type, docs }) => `${(0, utils_js_1.commentBlock)(docs)}${name}: ${type}`).join(',\n')}
|
|
23
23
|
|
|
24
|
-
${(0,
|
|
24
|
+
${(0, utils_js_1.commentBlock)('Generic pallet constant')}[name: string]: any,
|
|
25
25
|
},`;
|
|
26
26
|
}
|
|
27
27
|
const importTypes = this.typesGen.typeImports.toImports();
|
|
28
|
-
const template = (0,
|
|
29
|
-
return (0,
|
|
28
|
+
const template = (0, utils_js_1.compileTemplate)('consts.hbs');
|
|
29
|
+
return (0, utils_js_1.beautifySourceCode)(template({ importTypes, defTypeOut }));
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
exports.ConstsGen = ConstsGen;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ErrorsGen = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const ApiGen_js_1 = require("./ApiGen.js");
|
|
5
|
+
const utils_js_1 = require("./utils.js");
|
|
6
6
|
const util_1 = require("@polkadot/util");
|
|
7
|
-
const
|
|
8
|
-
class ErrorsGen extends
|
|
7
|
+
const utils_1 = require("@dedot/utils");
|
|
8
|
+
class ErrorsGen extends ApiGen_js_1.ApiGen {
|
|
9
9
|
generate() {
|
|
10
10
|
const { pallets } = this.metadata;
|
|
11
11
|
this.typesGen.clearCache();
|
|
@@ -17,24 +17,24 @@ class ErrorsGen extends ApiGen_1.ApiGen {
|
|
|
17
17
|
continue;
|
|
18
18
|
}
|
|
19
19
|
const errorDefs = this.#getErrorDefs(errorTypeId);
|
|
20
|
-
defTypeOut += (0,
|
|
20
|
+
defTypeOut += (0, utils_js_1.commentBlock)(`Pallet \`${pallet.name}\`'s errors`);
|
|
21
21
|
defTypeOut += `${(0, util_1.stringCamelCase)(pallet.name)}: {
|
|
22
22
|
${errorDefs
|
|
23
|
-
.map(({ name, docs }) => `${(0,
|
|
23
|
+
.map(({ name, docs }) => `${(0, utils_js_1.commentBlock)(docs)}${(0, util_1.stringPascalCase)(name)}: GenericPalletError`)
|
|
24
24
|
.join(',\n')}
|
|
25
25
|
|
|
26
|
-
${(0,
|
|
26
|
+
${(0, utils_js_1.commentBlock)('Generic pallet error')}[error: string]: GenericPalletError,
|
|
27
27
|
},`;
|
|
28
28
|
}
|
|
29
29
|
const importTypes = this.typesGen.typeImports.toImports();
|
|
30
|
-
const template = (0,
|
|
31
|
-
return (0,
|
|
30
|
+
const template = (0, utils_js_1.compileTemplate)('errors.hbs');
|
|
31
|
+
return (0, utils_js_1.beautifySourceCode)(template({ importTypes, defTypeOut }));
|
|
32
32
|
}
|
|
33
33
|
#getErrorDefs(errorTypeId) {
|
|
34
34
|
const def = this.metadata.types[errorTypeId];
|
|
35
|
-
(0,
|
|
35
|
+
(0, utils_1.assert)(def, `Error def not found for id ${errorTypeId}`);
|
|
36
36
|
const { tag, value } = def.type;
|
|
37
|
-
(0,
|
|
37
|
+
(0, utils_1.assert)(tag === 'Enum', `Invalid pallet error type!`);
|
|
38
38
|
return value.members;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EventsGen = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const ApiGen_js_1 = require("./ApiGen.js");
|
|
5
|
+
const utils_js_1 = require("./utils.js");
|
|
6
6
|
const util_1 = require("@polkadot/util");
|
|
7
|
-
const
|
|
8
|
-
class EventsGen extends
|
|
7
|
+
const utils_1 = require("@dedot/utils");
|
|
8
|
+
class EventsGen extends ApiGen_js_1.ApiGen {
|
|
9
9
|
generate() {
|
|
10
10
|
const { pallets } = this.metadata;
|
|
11
11
|
this.typesGen.clearCache();
|
|
@@ -18,7 +18,7 @@ class EventsGen extends ApiGen_1.ApiGen {
|
|
|
18
18
|
}
|
|
19
19
|
const eventDefs = this.#getEventDefs(eventTypeId);
|
|
20
20
|
const flatMembers = eventDefs.every((d) => d.fields.length === 0);
|
|
21
|
-
defTypeOut += (0,
|
|
21
|
+
defTypeOut += (0, utils_js_1.commentBlock)(`Pallet \`${pallet.name}\`'s events`);
|
|
22
22
|
defTypeOut += `${(0, util_1.stringCamelCase)(pallet.name)}: {
|
|
23
23
|
${eventDefs
|
|
24
24
|
.map((def) => {
|
|
@@ -32,21 +32,21 @@ class EventsGen extends ApiGen_1.ApiGen {
|
|
|
32
32
|
}
|
|
33
33
|
return { ...def, genericParts };
|
|
34
34
|
})
|
|
35
|
-
.map(({ name, docs, fields, genericParts }) => `${(0,
|
|
35
|
+
.map(({ name, docs, fields, genericParts }) => `${(0, utils_js_1.commentBlock)(docs)}${(0, util_1.stringPascalCase)(name)}: GenericPalletEvent<${genericParts.join(', ')}>`)
|
|
36
36
|
.join(',\n')}
|
|
37
37
|
|
|
38
|
-
${(0,
|
|
38
|
+
${(0, utils_js_1.commentBlock)('Generic pallet event')}[prop: string]: GenericPalletEvent,
|
|
39
39
|
},`;
|
|
40
40
|
}
|
|
41
41
|
const importTypes = this.typesGen.typeImports.toImports();
|
|
42
|
-
const template = (0,
|
|
43
|
-
return (0,
|
|
42
|
+
const template = (0, utils_js_1.compileTemplate)('events.hbs');
|
|
43
|
+
return (0, utils_js_1.beautifySourceCode)(template({ importTypes, defTypeOut }));
|
|
44
44
|
}
|
|
45
45
|
#getEventDefs(typeId) {
|
|
46
46
|
const def = this.metadata.types[typeId];
|
|
47
|
-
(0,
|
|
47
|
+
(0, utils_1.assert)(def, `Event def not found for id ${typeId}`);
|
|
48
48
|
const { tag, value } = def.type;
|
|
49
|
-
(0,
|
|
49
|
+
(0, utils_1.assert)(tag === 'Enum', 'Invalid pallet event type!');
|
|
50
50
|
return value.members;
|
|
51
51
|
}
|
|
52
52
|
#generateMemberDefType(fields) {
|
|
@@ -57,7 +57,7 @@ class EventsGen extends ApiGen_1.ApiGen {
|
|
|
57
57
|
return fields.length === 1
|
|
58
58
|
? this.typesGen.generateType(fields[0].typeId, 1, true)
|
|
59
59
|
: `[${fields
|
|
60
|
-
.map(({ typeId, docs }) => `${(0,
|
|
60
|
+
.map(({ typeId, docs }) => `${(0, utils_js_1.commentBlock)(docs)}${this.typesGen.generateType(typeId, 1, true)}`)
|
|
61
61
|
.join(', ')}]`;
|
|
62
62
|
}
|
|
63
63
|
else {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.IndexGen = void 0;
|
|
4
|
-
const
|
|
4
|
+
const utils_js_1 = require("./utils.js");
|
|
5
5
|
const util_1 = require("@polkadot/util");
|
|
6
6
|
class IndexGen {
|
|
7
7
|
networkInfo;
|
|
@@ -11,8 +11,8 @@ class IndexGen {
|
|
|
11
11
|
async generate() {
|
|
12
12
|
const { chain } = this.networkInfo;
|
|
13
13
|
const interfaceName = (0, util_1.stringPascalCase)(chain);
|
|
14
|
-
const template = (0,
|
|
15
|
-
return (0,
|
|
14
|
+
const template = (0, utils_js_1.compileTemplate)('index.hbs');
|
|
15
|
+
return (0, utils_js_1.beautifySourceCode)(template({ interfaceName }));
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
exports.IndexGen = IndexGen;
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.QueryGen = void 0;
|
|
4
4
|
const util_1 = require("@polkadot/util");
|
|
5
5
|
const utils_1 = require("@dedot/utils");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
class QueryGen extends
|
|
6
|
+
const index_js_1 = require("../generator/index.js");
|
|
7
|
+
const utils_js_1 = require("./utils.js");
|
|
8
|
+
class QueryGen extends index_js_1.ApiGen {
|
|
9
9
|
generate() {
|
|
10
10
|
const { pallets } = this.metadata;
|
|
11
11
|
this.typesGen.clearCache();
|
|
@@ -16,17 +16,17 @@ class QueryGen extends generator_1.ApiGen {
|
|
|
16
16
|
if (!storage)
|
|
17
17
|
continue;
|
|
18
18
|
const queries = storage.entries.map((one) => this.#generateEntry(one));
|
|
19
|
-
const queryDefs = queries.map(({ name, valueType, keyType, docs }) => `${(0,
|
|
20
|
-
defTypeOut += (0,
|
|
19
|
+
const queryDefs = queries.map(({ name, valueType, keyType, docs }) => `${(0, utils_js_1.commentBlock)(docs)}${name}: GenericStorageQuery<(${keyType}) => ${valueType}>`);
|
|
20
|
+
defTypeOut += (0, utils_js_1.commentBlock)(`Pallet \`${pallet.name}\`'s storage queries`);
|
|
21
21
|
defTypeOut += `${(0, util_1.stringLowerFirst)(pallet.name)}: {
|
|
22
22
|
${queryDefs.join(',\n')}
|
|
23
23
|
|
|
24
|
-
${(0,
|
|
24
|
+
${(0, utils_js_1.commentBlock)('Generic pallet storage query')}[storage: string]: GenericStorageQuery;
|
|
25
25
|
},`;
|
|
26
26
|
}
|
|
27
27
|
const importTypes = this.typesGen.typeImports.toImports();
|
|
28
|
-
const template = (0,
|
|
29
|
-
return (0,
|
|
28
|
+
const template = (0, utils_js_1.compileTemplate)('query.hbs');
|
|
29
|
+
return (0, utils_js_1.beautifySourceCode)(template({ importTypes, defTypeOut }));
|
|
30
30
|
}
|
|
31
31
|
#generateEntry(entry) {
|
|
32
32
|
const { name, type, docs, modifier } = entry;
|
package/cjs/generator/RpcGen.js
CHANGED
|
@@ -3,14 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RpcGen = void 0;
|
|
4
4
|
const specs_1 = require("@dedot/specs");
|
|
5
5
|
const utils_1 = require("@dedot/utils");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
6
|
+
const index_js_1 = require("../generator/index.js");
|
|
7
|
+
const utils_js_1 = require("./utils.js");
|
|
8
|
+
const known_codecs_js_1 = require("./known-codecs.js");
|
|
9
9
|
const HIDDEN_RPCS = [
|
|
10
10
|
// Ref: https://github.com/paritytech/polkadot-sdk/blob/43415ef58c143b985e09015cd000dbd65f6d3997/substrate/client/rpc-servers/src/lib.rs#L152C9-L158
|
|
11
11
|
'rpc_methods',
|
|
12
12
|
];
|
|
13
|
-
class RpcGen extends
|
|
13
|
+
class RpcGen extends index_js_1.ApiGen {
|
|
14
14
|
typesGen;
|
|
15
15
|
rpcMethods;
|
|
16
16
|
constructor(typesGen, rpcMethods) {
|
|
@@ -63,8 +63,8 @@ class RpcGen extends generator_1.ApiGen {
|
|
|
63
63
|
});
|
|
64
64
|
// TODO include & define external types
|
|
65
65
|
const importTypes = this.typesGen.typeImports.toImports();
|
|
66
|
-
const template = (0,
|
|
67
|
-
return (0,
|
|
66
|
+
const template = (0, utils_js_1.compileTemplate)('rpc.hbs');
|
|
67
|
+
return (0, utils_js_1.beautifySourceCode)(template({ importTypes, rpcCallsOut }));
|
|
68
68
|
}
|
|
69
69
|
#generateMethodDef(spec) {
|
|
70
70
|
const { name, type, module, method, docs = [], params, pubsub, deprecated } = spec;
|
|
@@ -74,7 +74,7 @@ class RpcGen extends generator_1.ApiGen {
|
|
|
74
74
|
defaultDocs.push(`@deprecated: ${deprecated}`);
|
|
75
75
|
}
|
|
76
76
|
if (type === 'GenericRpcCall' && params.length === 0) {
|
|
77
|
-
return `${(0,
|
|
77
|
+
return `${(0, utils_js_1.commentBlock)(defaultDocs)}${method}: GenericRpcCall`;
|
|
78
78
|
}
|
|
79
79
|
this.addTypeImport(type, false);
|
|
80
80
|
params.forEach(({ type, isScale }) => {
|
|
@@ -92,10 +92,10 @@ class RpcGen extends generator_1.ApiGen {
|
|
|
92
92
|
defaultDocs.shift();
|
|
93
93
|
defaultDocs.unshift(`@pubsub: ${pubsub?.join(', ')}`);
|
|
94
94
|
paramsOut.push(`callback: Callback<${typeOut}>`);
|
|
95
|
-
return `${(0,
|
|
95
|
+
return `${(0, utils_js_1.commentBlock)(docs, '\n', defaultDocs, paramsDoc)}${method}: GenericRpcCall<(${paramsOut.join(', ')}) => Promise<Unsub>>`;
|
|
96
96
|
}
|
|
97
97
|
else {
|
|
98
|
-
return `${(0,
|
|
98
|
+
return `${(0, utils_js_1.commentBlock)(docs, '\n', defaultDocs, paramsDoc)}${method}: GenericRpcCall<(${paramsOut.join(', ')}) => Promise<${typeOut}>>`;
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
// TODO check typeIn, typeOut if param type, or rpc type isScale
|
|
@@ -109,11 +109,11 @@ class RpcGen extends generator_1.ApiGen {
|
|
|
109
109
|
return;
|
|
110
110
|
}
|
|
111
111
|
// Handle generic wrapper types
|
|
112
|
-
const matchArray = type.match(
|
|
112
|
+
const matchArray = type.match(utils_js_1.WRAPPER_TYPE_REGEX);
|
|
113
113
|
if (matchArray) {
|
|
114
114
|
const [_, $1, $2] = matchArray;
|
|
115
115
|
this.addTypeImport($1, toTypeIn);
|
|
116
|
-
if ($2.match(
|
|
116
|
+
if ($2.match(utils_js_1.WRAPPER_TYPE_REGEX) || $2.match(utils_js_1.TUPLE_TYPE_REGEX)) {
|
|
117
117
|
this.addTypeImport($2, toTypeIn);
|
|
118
118
|
}
|
|
119
119
|
else {
|
|
@@ -122,7 +122,7 @@ class RpcGen extends generator_1.ApiGen {
|
|
|
122
122
|
return;
|
|
123
123
|
}
|
|
124
124
|
// Check tuple type
|
|
125
|
-
if (type.match(
|
|
125
|
+
if (type.match(utils_js_1.TUPLE_TYPE_REGEX)) {
|
|
126
126
|
this.addTypeImport(type.slice(1, -1).split(','), toTypeIn);
|
|
127
127
|
return;
|
|
128
128
|
}
|
|
@@ -142,11 +142,11 @@ class RpcGen extends generator_1.ApiGen {
|
|
|
142
142
|
}
|
|
143
143
|
getGeneratedTypeName(type, toTypeIn = true) {
|
|
144
144
|
try {
|
|
145
|
-
const matchArray = type.match(
|
|
145
|
+
const matchArray = type.match(utils_js_1.WRAPPER_TYPE_REGEX);
|
|
146
146
|
if (matchArray) {
|
|
147
147
|
const [_, $1, $2] = matchArray;
|
|
148
148
|
const wrapperTypeName = this.#getCodecType($1, toTypeIn);
|
|
149
|
-
if ($2.match(
|
|
149
|
+
if ($2.match(utils_js_1.WRAPPER_TYPE_REGEX) || $2.match(utils_js_1.TUPLE_TYPE_REGEX)) {
|
|
150
150
|
return `${wrapperTypeName}<${this.getGeneratedTypeName($2, toTypeIn)}>`;
|
|
151
151
|
}
|
|
152
152
|
const innerTypeNames = $2
|
|
@@ -155,7 +155,7 @@ class RpcGen extends generator_1.ApiGen {
|
|
|
155
155
|
.join(', ');
|
|
156
156
|
return `${wrapperTypeName}<${innerTypeNames}>`;
|
|
157
157
|
}
|
|
158
|
-
else if (type.match(
|
|
158
|
+
else if (type.match(utils_js_1.TUPLE_TYPE_REGEX)) {
|
|
159
159
|
const innerTypeNames = type
|
|
160
160
|
.slice(1, -1)
|
|
161
161
|
.split(',')
|
|
@@ -169,7 +169,7 @@ class RpcGen extends generator_1.ApiGen {
|
|
|
169
169
|
return type;
|
|
170
170
|
}
|
|
171
171
|
#getCodecType(type, toTypeIn = true) {
|
|
172
|
-
const { typeIn, typeOut } = (0,
|
|
172
|
+
const { typeIn, typeOut } = (0, known_codecs_js_1.findKnownCodecType)(type);
|
|
173
173
|
return toTypeIn ? typeIn : typeOut;
|
|
174
174
|
}
|
|
175
175
|
}
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RuntimeApisGen = void 0;
|
|
4
4
|
const specs_1 = require("@dedot/specs");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
5
|
+
const utils_js_1 = require("./utils.js");
|
|
6
|
+
const utils_1 = require("@dedot/utils");
|
|
7
|
+
const RpcGen_js_1 = require("./RpcGen.js");
|
|
8
8
|
const util_1 = require("@polkadot/util");
|
|
9
|
-
class RuntimeApisGen extends
|
|
9
|
+
class RuntimeApisGen extends RpcGen_js_1.RpcGen {
|
|
10
10
|
typesGen;
|
|
11
11
|
runtimeApis;
|
|
12
12
|
constructor(typesGen, runtimeApis) {
|
|
@@ -21,18 +21,18 @@ class RuntimeApisGen extends RpcGen_1.RpcGen {
|
|
|
21
21
|
if (this.metadata.apis.length > 0) {
|
|
22
22
|
this.metadata.apis.forEach((runtimeApi) => {
|
|
23
23
|
const { name: runtimeApiName, methods } = runtimeApi;
|
|
24
|
-
runtimeCallsOut += (0,
|
|
24
|
+
runtimeCallsOut += (0, utils_js_1.commentBlock)(`@runtimeapi: ${runtimeApiName} - ${(0, utils_1.calculateRuntimeApiHash)(runtimeApiName)}`);
|
|
25
25
|
runtimeCallsOut += `${(0, util_1.stringCamelCase)(runtimeApiName)}: {
|
|
26
26
|
${methods.map((method) => this.#generateMethodDef(runtimeApiName, method)).join('\n')}
|
|
27
27
|
|
|
28
|
-
${(0,
|
|
28
|
+
${(0, utils_js_1.commentBlock)('Generic runtime api call')}[method: string]: GenericRuntimeApiMethod
|
|
29
29
|
}`;
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
else {
|
|
33
33
|
const specs = this.#targetRuntimeApiSpecs();
|
|
34
34
|
specs.forEach(({ methods, runtimeApiName, runtimeApiHash, version }) => {
|
|
35
|
-
runtimeCallsOut += (0,
|
|
35
|
+
runtimeCallsOut += (0, utils_js_1.commentBlock)(`@runtimeapi: ${runtimeApiName} - ${runtimeApiHash}`, `@version: ${version}`);
|
|
36
36
|
runtimeCallsOut += `${(0, util_1.stringCamelCase)(runtimeApiName)}: {
|
|
37
37
|
${Object.keys(methods)
|
|
38
38
|
.map((methodName) => this.#generateMethodDefFromSpec({
|
|
@@ -42,13 +42,13 @@ class RuntimeApisGen extends RpcGen_1.RpcGen {
|
|
|
42
42
|
}))
|
|
43
43
|
.join('\n')}
|
|
44
44
|
|
|
45
|
-
${(0,
|
|
45
|
+
${(0, utils_js_1.commentBlock)('Generic runtime api call')}[method: string]: GenericRuntimeApiMethod
|
|
46
46
|
}`;
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
const importTypes = this.typesGen.typeImports.toImports();
|
|
50
|
-
const template = (0,
|
|
51
|
-
return (0,
|
|
50
|
+
const template = (0, utils_js_1.compileTemplate)('runtime.hbs');
|
|
51
|
+
return (0, utils_js_1.beautifySourceCode)(template({ importTypes, runtimeCallsOut }));
|
|
52
52
|
}
|
|
53
53
|
#isOptionalType(type) {
|
|
54
54
|
return type.startsWith('Option<') || type.endsWith('| undefined');
|
|
@@ -58,7 +58,7 @@ class RuntimeApisGen extends RpcGen_1.RpcGen {
|
|
|
58
58
|
}
|
|
59
59
|
#generateMethodDefFromSpec(spec) {
|
|
60
60
|
const { docs = [], params, type, runtimeApiName, methodName } = spec;
|
|
61
|
-
const callName = `${runtimeApiName}_${(0,
|
|
61
|
+
const callName = `${runtimeApiName}_${(0, utils_1.stringSnakeCase)(methodName)}`;
|
|
62
62
|
const defaultDocs = [`@callname: ${callName}`];
|
|
63
63
|
this.addTypeImport(type, false);
|
|
64
64
|
params.forEach(({ type }) => this.addTypeImport(type));
|
|
@@ -71,11 +71,11 @@ class RuntimeApisGen extends RpcGen_1.RpcGen {
|
|
|
71
71
|
.map(({ name, isOptional, plainType }) => `${(0, util_1.stringCamelCase)(name)}${isOptional ? '?' : ''}: ${plainType}`)
|
|
72
72
|
.join(', ');
|
|
73
73
|
const typeOut = this.getGeneratedTypeName(type, false);
|
|
74
|
-
return `${(0,
|
|
74
|
+
return `${(0, utils_js_1.commentBlock)(docs, '\n', defaultDocs, typedParams.map(({ plainType, name }) => `@param {${plainType}} ${name}`))}${methodName}: GenericRuntimeApiMethod<(${paramsOut}) => Promise<${typeOut}>>`;
|
|
75
75
|
}
|
|
76
76
|
#generateMethodDef(runtimeApiName, methodDef) {
|
|
77
77
|
const { name: methodName, inputs, output, docs } = methodDef;
|
|
78
|
-
const callName = `${runtimeApiName}_${(0,
|
|
78
|
+
const callName = `${runtimeApiName}_${(0, utils_1.stringSnakeCase)(methodName)}`;
|
|
79
79
|
const defaultDocs = [`@callname: ${callName}`];
|
|
80
80
|
const typeOut = this.typesGen.generateType(output, 1, true);
|
|
81
81
|
this.addTypeImport(typeOut, false);
|
|
@@ -92,7 +92,7 @@ class RuntimeApisGen extends RpcGen_1.RpcGen {
|
|
|
92
92
|
const paramsOut = typedInputs
|
|
93
93
|
.map(({ name, type, isOptional }) => `${(0, util_1.stringCamelCase)(name)}${isOptional ? '?' : ''}: ${type}`)
|
|
94
94
|
.join(', ');
|
|
95
|
-
return `${(0,
|
|
95
|
+
return `${(0, utils_js_1.commentBlock)(docs, '\n', defaultDocs, typedInputs.map(({ type, name }) => `@param {${type}} ${name}`))}${(0, util_1.stringCamelCase)(methodName)}: GenericRuntimeApiMethod<(${paramsOut}) => Promise<${typeOut}>>`;
|
|
96
96
|
}
|
|
97
97
|
#targetRuntimeApiSpecs() {
|
|
98
98
|
const specs = this.runtimeApis.map(([runtimeApiHash, version]) => {
|
|
@@ -112,7 +112,7 @@ class RuntimeApisGen extends RpcGen_1.RpcGen {
|
|
|
112
112
|
}, []);
|
|
113
113
|
}
|
|
114
114
|
#findRuntimeApiSpec = (runtimeApiHash, version) => {
|
|
115
|
-
const runtimeApiName = (0, specs_1.getRuntimeApiNames)().find((one) => (0,
|
|
115
|
+
const runtimeApiName = (0, specs_1.getRuntimeApiNames)().find((one) => (0, utils_1.calculateRuntimeApiHash)(one) === runtimeApiHash);
|
|
116
116
|
return (0, specs_1.getRuntimeApiSpecs)().find((one) => one.runtimeApiName === runtimeApiName && one.version === version);
|
|
117
117
|
};
|
|
118
118
|
}
|
package/cjs/generator/TxGen.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TxGen = void 0;
|
|
4
|
-
const
|
|
4
|
+
const index_js_1 = require("../generator/index.js");
|
|
5
5
|
const util_1 = require("@polkadot/util");
|
|
6
|
-
const
|
|
7
|
-
class TxGen extends
|
|
6
|
+
const utils_js_1 = require("./utils.js");
|
|
7
|
+
class TxGen extends index_js_1.ApiGen {
|
|
8
8
|
generate() {
|
|
9
9
|
const { pallets, types } = this.metadata;
|
|
10
10
|
this.typesGen.clearCache();
|
|
@@ -41,13 +41,13 @@ class TxGen extends generator_1.ApiGen {
|
|
|
41
41
|
callInput: this.#generateCallInput((0, util_1.stringPascalCase)(pallet.name), (0, util_1.stringPascalCase)(f.functionName), !isFlatEnum ? f.params.map((p) => `${p.name}: ${p.type}`) : undefined),
|
|
42
42
|
};
|
|
43
43
|
});
|
|
44
|
-
txDefsOut += (0,
|
|
44
|
+
txDefsOut += (0, utils_js_1.commentBlock)(`Pallet \`${pallet.name}\`'s transaction calls`);
|
|
45
45
|
txDefsOut += `${(0, util_1.stringCamelCase)(pallet.name)}: {
|
|
46
46
|
${typedTxs
|
|
47
|
-
.map(({ functionName, params, docs, callInput }) => `${(0,
|
|
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')}
|
|
49
49
|
|
|
50
|
-
${(0,
|
|
50
|
+
${(0, utils_js_1.commentBlock)('Generic pallet tx call')}[callName: string]: GenericTxCall<TxCall>,
|
|
51
51
|
},`;
|
|
52
52
|
}
|
|
53
53
|
const importTypes = this.typesGen.typeImports.toImports();
|
|
@@ -59,12 +59,12 @@ class TxGen extends generator_1.ApiGen {
|
|
|
59
59
|
|
|
60
60
|
export type TxCall = (...args: any[]) => ChainSubmittableExtrinsic;
|
|
61
61
|
`;
|
|
62
|
-
const template = (0,
|
|
63
|
-
return (0,
|
|
62
|
+
const template = (0, utils_js_1.compileTemplate)('tx.hbs');
|
|
63
|
+
return (0, utils_js_1.beautifySourceCode)(template({ importTypes, defTypes, txDefsOut }));
|
|
64
64
|
}
|
|
65
65
|
#normalizeParamName(name) {
|
|
66
66
|
name = (0, util_1.stringCamelCase)(name);
|
|
67
|
-
return (0,
|
|
67
|
+
return (0, utils_js_1.isReservedWord)(name) ? `${name}_` : name;
|
|
68
68
|
}
|
|
69
69
|
#generateCallInput(palletName, callName, params) {
|
|
70
70
|
if (!params) {
|
|
@@ -4,10 +4,10 @@ exports.TypesGen = exports.BASIC_KNOWN_TYPES = void 0;
|
|
|
4
4
|
const util_1 = require("@polkadot/util");
|
|
5
5
|
const codecs_1 = require("@dedot/codecs");
|
|
6
6
|
const utils_1 = require("@dedot/utils");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
7
|
+
const utils_js_1 = require("./utils.js");
|
|
8
|
+
const known_types_js_1 = require("./known-types.js");
|
|
9
|
+
const TypeImports_js_1 = require("./TypeImports.js");
|
|
10
|
+
const known_codecs_js_1 = require("./known-codecs.js");
|
|
11
11
|
// Skip generate types for these
|
|
12
12
|
// as we do have native types for them
|
|
13
13
|
const SKIP_TYPES = [
|
|
@@ -43,7 +43,7 @@ class TypesGen {
|
|
|
43
43
|
this.metadata = metadata;
|
|
44
44
|
this.registry = new codecs_1.PortableRegistry(this.metadata);
|
|
45
45
|
this.includedTypes = this.#includedTypes();
|
|
46
|
-
this.typeImports = new
|
|
46
|
+
this.typeImports = new TypeImports_js_1.TypeImports();
|
|
47
47
|
}
|
|
48
48
|
generate() {
|
|
49
49
|
this.clearCache();
|
|
@@ -51,14 +51,14 @@ class TypesGen {
|
|
|
51
51
|
Object.values(this.includedTypes)
|
|
52
52
|
.filter(({ skip, knownType }) => !(skip || knownType))
|
|
53
53
|
.forEach(({ name, nameOut, id, docs }) => {
|
|
54
|
-
defTypeOut += `${(0,
|
|
54
|
+
defTypeOut += `${(0, utils_js_1.commentBlock)(docs)}export type ${nameOut} = ${this.generateType(id, 0, true)};\n\n`;
|
|
55
55
|
if (this.#shouldGenerateTypeIn(id)) {
|
|
56
56
|
defTypeOut += `export type ${name} = ${this.generateType(id)};\n\n`;
|
|
57
57
|
}
|
|
58
58
|
});
|
|
59
59
|
const importTypes = this.typeImports.toImports('./types');
|
|
60
|
-
const template = (0,
|
|
61
|
-
return (0,
|
|
60
|
+
const template = (0, utils_js_1.compileTemplate)('types.hbs');
|
|
61
|
+
return (0, utils_js_1.beautifySourceCode)(template({ importTypes, defTypeOut }));
|
|
62
62
|
}
|
|
63
63
|
typeCache = {};
|
|
64
64
|
clearCache() {
|
|
@@ -103,7 +103,7 @@ class TypesGen {
|
|
|
103
103
|
const { tag, value } = type;
|
|
104
104
|
switch (tag) {
|
|
105
105
|
case 'Primitive':
|
|
106
|
-
const $codec = (0,
|
|
106
|
+
const $codec = (0, known_codecs_js_1.findKnownCodec)(value.kind);
|
|
107
107
|
if ($codec.nativeType) {
|
|
108
108
|
return $codec.nativeType;
|
|
109
109
|
}
|
|
@@ -151,7 +151,7 @@ class TypesGen {
|
|
|
151
151
|
return 'null';
|
|
152
152
|
}
|
|
153
153
|
else if (members.every((x) => x.fields.length === 0)) {
|
|
154
|
-
return members.map(({ name, docs }) => `${(0,
|
|
154
|
+
return members.map(({ name, docs }) => `${(0, utils_js_1.commentBlock)(docs)}'${(0, util_1.stringPascalCase)(name)}'`).join(' | ');
|
|
155
155
|
}
|
|
156
156
|
else {
|
|
157
157
|
const membersType = [];
|
|
@@ -164,7 +164,7 @@ class TypesGen {
|
|
|
164
164
|
const valueType = fields.length === 1
|
|
165
165
|
? this.generateType(fields[0].typeId, nestedLevel + 1, typeOut)
|
|
166
166
|
: `[${fields
|
|
167
|
-
.map(({ typeId, docs }) => `${(0,
|
|
167
|
+
.map(({ typeId, docs }) => `${(0, utils_js_1.commentBlock)(docs)}${this.generateType(typeId, nestedLevel + 1, typeOut)}`)
|
|
168
168
|
.join(', ')}]`;
|
|
169
169
|
membersType.push([keyName, valueType, docs]);
|
|
170
170
|
}
|
|
@@ -179,7 +179,7 @@ class TypesGen {
|
|
|
179
179
|
value: valueType ? `, ${valueKey}${this.#isOptionalType(valueType) ? '?' : ''}: ${valueType} ` : '',
|
|
180
180
|
docs,
|
|
181
181
|
}))
|
|
182
|
-
.map(({ tag, value, docs }) => `${(0,
|
|
182
|
+
.map(({ tag, value, docs }) => `${(0, utils_js_1.commentBlock)(docs)}{ ${tag}${value} }`)
|
|
183
183
|
.join(' | ');
|
|
184
184
|
}
|
|
185
185
|
}
|
|
@@ -226,7 +226,7 @@ class TypesGen {
|
|
|
226
226
|
};
|
|
227
227
|
});
|
|
228
228
|
return `{${props
|
|
229
|
-
.map(({ name, type, optional, docs }) => `${(0,
|
|
229
|
+
.map(({ name, type, optional, docs }) => `${(0, utils_js_1.commentBlock)(docs)}${name}${optional ? '?' : ''}: ${type}`)
|
|
230
230
|
.join(',\n')}}`;
|
|
231
231
|
}
|
|
232
232
|
#isOptionalType(type) {
|
|
@@ -267,8 +267,8 @@ class TypesGen {
|
|
|
267
267
|
const suffix = typeSuffixes.get(id) || '';
|
|
268
268
|
let knownType = false;
|
|
269
269
|
let name, nameOut;
|
|
270
|
-
if ((0,
|
|
271
|
-
const codecType = (0,
|
|
270
|
+
if ((0, known_codecs_js_1.isKnownCodecType)(joinedPath)) {
|
|
271
|
+
const codecType = (0, known_codecs_js_1.findKnownCodecType)(path.at(-1));
|
|
272
272
|
name = codecType.typeIn;
|
|
273
273
|
nameOut = codecType.typeOut;
|
|
274
274
|
knownType = true;
|
|
@@ -426,7 +426,7 @@ class TypesGen {
|
|
|
426
426
|
this.typeImports.addCodecType(typeName);
|
|
427
427
|
return;
|
|
428
428
|
}
|
|
429
|
-
if (
|
|
429
|
+
if (known_types_js_1.knownTypes.includes(typeName)) {
|
|
430
430
|
this.typeImports.addKnownType(typeName);
|
|
431
431
|
}
|
|
432
432
|
else {
|
package/cjs/generator/index.js
CHANGED
|
@@ -14,13 +14,13 @@ 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("./TypesGen"), exports);
|
|
18
|
-
__exportStar(require("./ApiGen"), exports);
|
|
19
|
-
__exportStar(require("./ConstsGen"), exports);
|
|
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("./TypesGen.js"), exports);
|
|
18
|
+
__exportStar(require("./ApiGen.js"), exports);
|
|
19
|
+
__exportStar(require("./ConstsGen.js"), exports);
|
|
20
|
+
__exportStar(require("./QueryGen.js"), exports);
|
|
21
|
+
__exportStar(require("./RpcGen.js"), exports);
|
|
22
|
+
__exportStar(require("./IndexGen.js"), exports);
|
|
23
|
+
__exportStar(require("./ErrorsGen.js"), exports);
|
|
24
|
+
__exportStar(require("./EventsGen.js"), exports);
|
|
25
|
+
__exportStar(require("./TxGen.js"), exports);
|
|
26
|
+
__exportStar(require("./RuntimeApisGen.js"), exports);
|
package/cjs/index.js
CHANGED
|
@@ -27,7 +27,7 @@ exports.generateTypes = exports.generateTypesFromChain = void 0;
|
|
|
27
27
|
const dedot_1 = require("dedot");
|
|
28
28
|
const fs = __importStar(require("fs"));
|
|
29
29
|
const path = __importStar(require("path"));
|
|
30
|
-
const
|
|
30
|
+
const index_js_1 = require("./generator/index.js");
|
|
31
31
|
const util_1 = require("@polkadot/util");
|
|
32
32
|
async function generateTypesFromChain(network, endpoint, outDir) {
|
|
33
33
|
const api = await dedot_1.Dedot.create(endpoint);
|
|
@@ -54,15 +54,15 @@ async function generateTypes(network, metadata, rpcMethods, runtimeApis, outDir
|
|
|
54
54
|
if (!fs.existsSync(dirPath)) {
|
|
55
55
|
fs.mkdirSync(dirPath, { recursive: true });
|
|
56
56
|
}
|
|
57
|
-
const typesGen = new
|
|
58
|
-
const constsGen = new
|
|
59
|
-
const queryGen = new
|
|
60
|
-
const rpcGen = new
|
|
61
|
-
const indexGen = new
|
|
62
|
-
const errorsGen = new
|
|
63
|
-
const eventsGen = new
|
|
64
|
-
const runtimeApisGen = new
|
|
65
|
-
const txGen = new
|
|
57
|
+
const typesGen = new index_js_1.TypesGen(metadata);
|
|
58
|
+
const constsGen = new index_js_1.ConstsGen(typesGen);
|
|
59
|
+
const queryGen = new index_js_1.QueryGen(typesGen);
|
|
60
|
+
const rpcGen = new index_js_1.RpcGen(typesGen, rpcMethods);
|
|
61
|
+
const indexGen = new index_js_1.IndexGen(network);
|
|
62
|
+
const errorsGen = new index_js_1.ErrorsGen(typesGen);
|
|
63
|
+
const eventsGen = new index_js_1.EventsGen(typesGen);
|
|
64
|
+
const runtimeApisGen = new index_js_1.RuntimeApisGen(typesGen, runtimeApis);
|
|
65
|
+
const txGen = new index_js_1.TxGen(typesGen);
|
|
66
66
|
fs.writeFileSync(defTypesFileName, await typesGen.generate());
|
|
67
67
|
fs.writeFileSync(errorsFileName, await errorsGen.generate());
|
|
68
68
|
fs.writeFileSync(eventsFileName, await eventsGen.generate());
|
package/cjs/packageInfo.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
// THIS FILE IS AUTO-GENERATED, DO NOT EDIT!
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.packageInfo = void 0;
|
|
5
|
-
exports.packageInfo = { name: '@dedot/codegen', version: '0.0.1-alpha.
|
|
5
|
+
exports.packageInfo = { name: '@dedot/codegen', version: '0.0.1-alpha.28' };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { generateTypes, generateTypesFromChain } from './index';
|
|
1
|
+
import { generateTypes, generateTypesFromChain } from './index.js';
|
|
2
2
|
import { rpc } from '@polkadot/types-support/metadata/static-substrate';
|
|
3
3
|
import staticSubstrate from '@polkadot/types-support/metadata/v15/substrate-hex';
|
|
4
4
|
import { $Metadata, PortableRegistry } from '@dedot/codecs';
|
package/generator/ApiGen.d.ts
CHANGED
package/generator/ConstsGen.d.ts
CHANGED
package/generator/ConstsGen.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { stringLowerFirst } from '@polkadot/util';
|
|
2
2
|
import { normalizeName } from '@dedot/utils';
|
|
3
|
-
import { ApiGen } from '../generator';
|
|
4
|
-
import { beautifySourceCode, commentBlock, compileTemplate } from './utils';
|
|
3
|
+
import { ApiGen } from '../generator/index.js';
|
|
4
|
+
import { beautifySourceCode, commentBlock, compileTemplate } from './utils.js';
|
|
5
5
|
export class ConstsGen extends ApiGen {
|
|
6
6
|
generate() {
|
|
7
7
|
const { pallets } = this.metadata;
|
package/generator/ErrorsGen.d.ts
CHANGED
package/generator/ErrorsGen.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ApiGen } from './ApiGen';
|
|
2
|
-
import { beautifySourceCode, commentBlock, compileTemplate } from './utils';
|
|
1
|
+
import { ApiGen } from './ApiGen.js';
|
|
2
|
+
import { beautifySourceCode, commentBlock, compileTemplate } from './utils.js';
|
|
3
3
|
import { stringCamelCase, stringPascalCase } from '@polkadot/util';
|
|
4
4
|
import { assert } from '@dedot/utils';
|
|
5
5
|
export class ErrorsGen extends ApiGen {
|
package/generator/EventsGen.d.ts
CHANGED
package/generator/EventsGen.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ApiGen } from './ApiGen';
|
|
2
|
-
import { beautifySourceCode, commentBlock, compileTemplate } from './utils';
|
|
1
|
+
import { ApiGen } from './ApiGen.js';
|
|
2
|
+
import { beautifySourceCode, commentBlock, compileTemplate } from './utils.js';
|
|
3
3
|
import { stringCamelCase, stringPascalCase } from '@polkadot/util';
|
|
4
4
|
import { assert } from '@dedot/utils';
|
|
5
5
|
export class EventsGen extends ApiGen {
|
package/generator/IndexGen.d.ts
CHANGED
package/generator/IndexGen.js
CHANGED
package/generator/QueryGen.d.ts
CHANGED
package/generator/QueryGen.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { stringLowerFirst } from '@polkadot/util';
|
|
2
2
|
import { normalizeName } from '@dedot/utils';
|
|
3
|
-
import { ApiGen } from '../generator';
|
|
4
|
-
import { beautifySourceCode, commentBlock, compileTemplate } from './utils';
|
|
3
|
+
import { ApiGen } from '../generator/index.js';
|
|
4
|
+
import { beautifySourceCode, commentBlock, compileTemplate } from './utils.js';
|
|
5
5
|
export class QueryGen extends ApiGen {
|
|
6
6
|
generate() {
|
|
7
7
|
const { pallets } = this.metadata;
|
package/generator/RpcGen.d.ts
CHANGED
package/generator/RpcGen.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { findAliasRpcSpec, findRpcSpec, isUnsubscribeMethod } from '@dedot/specs';
|
|
2
2
|
import { isNativeType } from '@dedot/utils';
|
|
3
|
-
import { ApiGen } from '../generator';
|
|
4
|
-
import { beautifySourceCode, commentBlock, compileTemplate, TUPLE_TYPE_REGEX, WRAPPER_TYPE_REGEX } from './utils';
|
|
5
|
-
import { findKnownCodecType } from './known-codecs';
|
|
3
|
+
import { ApiGen } from '../generator/index.js';
|
|
4
|
+
import { beautifySourceCode, commentBlock, compileTemplate, TUPLE_TYPE_REGEX, WRAPPER_TYPE_REGEX } from './utils.js';
|
|
5
|
+
import { findKnownCodecType } from './known-codecs.js';
|
|
6
6
|
const HIDDEN_RPCS = [
|
|
7
7
|
// Ref: https://github.com/paritytech/polkadot-sdk/blob/43415ef58c143b985e09015cd000dbd65f6d3997/substrate/client/rpc-servers/src/lib.rs#L152C9-L158
|
|
8
8
|
'rpc_methods',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getRuntimeApiNames, getRuntimeApiSpecs } from '@dedot/specs';
|
|
2
|
-
import { beautifySourceCode, commentBlock, compileTemplate } from './utils';
|
|
2
|
+
import { beautifySourceCode, commentBlock, compileTemplate } from './utils.js';
|
|
3
3
|
import { calculateRuntimeApiHash, stringSnakeCase } from '@dedot/utils';
|
|
4
|
-
import { RpcGen } from './RpcGen';
|
|
4
|
+
import { RpcGen } from './RpcGen.js';
|
|
5
5
|
import { stringCamelCase } from '@polkadot/util';
|
|
6
6
|
export class RuntimeApisGen extends RpcGen {
|
|
7
7
|
typesGen;
|
package/generator/TxGen.d.ts
CHANGED
package/generator/TxGen.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ApiGen } from '../generator';
|
|
1
|
+
import { ApiGen } from '../generator/index.js';
|
|
2
2
|
import { stringCamelCase, stringPascalCase } from '@polkadot/util';
|
|
3
|
-
import { beautifySourceCode, commentBlock, compileTemplate, isReservedWord } from './utils';
|
|
3
|
+
import { beautifySourceCode, commentBlock, compileTemplate, isReservedWord } from './utils.js';
|
|
4
4
|
export class TxGen extends ApiGen {
|
|
5
5
|
generate() {
|
|
6
6
|
const { pallets, types } = this.metadata;
|
package/generator/TypesGen.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PortableRegistry, Field, MetadataLatest, PortableType, TypeId } from '@dedot/codecs';
|
|
2
|
-
import { TypeImports } from './TypeImports';
|
|
2
|
+
import { TypeImports } from './TypeImports.js';
|
|
3
3
|
interface NamedType extends PortableType {
|
|
4
4
|
name: string;
|
|
5
5
|
nameOut: string;
|
package/generator/TypesGen.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { stringPascalCase } from '@polkadot/util';
|
|
2
2
|
import { PortableRegistry } from '@dedot/codecs';
|
|
3
3
|
import { isNativeType, normalizeName } from '@dedot/utils';
|
|
4
|
-
import { beautifySourceCode, commentBlock, compileTemplate } from './utils';
|
|
5
|
-
import { knownTypes } from './known-types';
|
|
6
|
-
import { TypeImports } from './TypeImports';
|
|
7
|
-
import { findKnownCodec, findKnownCodecType, isKnownCodecType } from './known-codecs';
|
|
4
|
+
import { beautifySourceCode, commentBlock, compileTemplate } from './utils.js';
|
|
5
|
+
import { knownTypes } from './known-types.js';
|
|
6
|
+
import { TypeImports } from './TypeImports.js';
|
|
7
|
+
import { findKnownCodec, findKnownCodecType, isKnownCodecType } from './known-codecs.js';
|
|
8
8
|
// Skip generate types for these
|
|
9
9
|
// as we do have native types for them
|
|
10
10
|
const SKIP_TYPES = [
|
package/generator/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export * from './TypesGen';
|
|
2
|
-
export * from './ApiGen';
|
|
3
|
-
export * from './ConstsGen';
|
|
4
|
-
export * from './QueryGen';
|
|
5
|
-
export * from './RpcGen';
|
|
6
|
-
export * from './IndexGen';
|
|
7
|
-
export * from './ErrorsGen';
|
|
8
|
-
export * from './EventsGen';
|
|
9
|
-
export * from './TxGen';
|
|
10
|
-
export * from './RuntimeApisGen';
|
|
1
|
+
export * from './TypesGen.js';
|
|
2
|
+
export * from './ApiGen.js';
|
|
3
|
+
export * from './ConstsGen.js';
|
|
4
|
+
export * from './QueryGen.js';
|
|
5
|
+
export * from './RpcGen.js';
|
|
6
|
+
export * from './IndexGen.js';
|
|
7
|
+
export * from './ErrorsGen.js';
|
|
8
|
+
export * from './EventsGen.js';
|
|
9
|
+
export * from './TxGen.js';
|
|
10
|
+
export * from './RuntimeApisGen.js';
|
package/generator/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export * from './TypesGen';
|
|
2
|
-
export * from './ApiGen';
|
|
3
|
-
export * from './ConstsGen';
|
|
4
|
-
export * from './QueryGen';
|
|
5
|
-
export * from './RpcGen';
|
|
6
|
-
export * from './IndexGen';
|
|
7
|
-
export * from './ErrorsGen';
|
|
8
|
-
export * from './EventsGen';
|
|
9
|
-
export * from './TxGen';
|
|
10
|
-
export * from './RuntimeApisGen';
|
|
1
|
+
export * from './TypesGen.js';
|
|
2
|
+
export * from './ApiGen.js';
|
|
3
|
+
export * from './ConstsGen.js';
|
|
4
|
+
export * from './QueryGen.js';
|
|
5
|
+
export * from './RpcGen.js';
|
|
6
|
+
export * from './IndexGen.js';
|
|
7
|
+
export * from './ErrorsGen.js';
|
|
8
|
+
export * from './EventsGen.js';
|
|
9
|
+
export * from './TxGen.js';
|
|
10
|
+
export * from './RuntimeApisGen.js';
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { MetadataLatest } from '@dedot/codecs';
|
|
2
|
-
import { NetworkInfo } from './types';
|
|
2
|
+
import { NetworkInfo } from './types.js';
|
|
3
3
|
export declare function generateTypesFromChain(network: NetworkInfo, endpoint: string, outDir: string): Promise<void>;
|
|
4
4
|
export declare function generateTypes(network: NetworkInfo, metadata: MetadataLatest, rpcMethods: string[], runtimeApis: any[], outDir?: string): Promise<void>;
|
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Dedot } from 'dedot';
|
|
2
2
|
import * as fs from 'fs';
|
|
3
3
|
import * as path from 'path';
|
|
4
|
-
import { ConstsGen, ErrorsGen, EventsGen, IndexGen, QueryGen, RpcGen, RuntimeApisGen, TxGen, TypesGen, } from './generator';
|
|
4
|
+
import { ConstsGen, ErrorsGen, EventsGen, IndexGen, QueryGen, RpcGen, RuntimeApisGen, TxGen, TypesGen, } from './generator/index.js';
|
|
5
5
|
import { stringCamelCase } from '@polkadot/util';
|
|
6
6
|
export async function generateTypesFromChain(network, endpoint, outDir) {
|
|
7
7
|
const api = await Dedot.create(endpoint);
|
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.2d39ff2d.5+2d39ff2",
|
|
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,12 @@
|
|
|
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.
|
|
21
|
+
"@dedot/codecs": "0.0.1-next.2d39ff2d.5+2d39ff2",
|
|
22
|
+
"@dedot/shape": "0.0.1-next.2d39ff2d.5+2d39ff2",
|
|
23
|
+
"@dedot/specs": "0.0.1-next.2d39ff2d.5+2d39ff2",
|
|
24
|
+
"@dedot/utils": "0.0.1-next.2d39ff2d.5+2d39ff2",
|
|
25
25
|
"@polkadot/util": "^12.6.2",
|
|
26
|
-
"dedot": "0.0.1-next.
|
|
26
|
+
"dedot": "0.0.1-next.2d39ff2d.5+2d39ff2",
|
|
27
27
|
"handlebars": "^4.7.8",
|
|
28
28
|
"prettier": "^3.0.3"
|
|
29
29
|
},
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"directory": "dist"
|
|
33
33
|
},
|
|
34
34
|
"license": "Apache-2.0",
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "2d39ff2dc624f3b10eb7a913fe177112046bfbd9",
|
|
36
36
|
"module": "./index.js",
|
|
37
37
|
"types": "./index.d.ts",
|
|
38
38
|
"exports": {
|
package/packageInfo.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// THIS FILE IS AUTO-GENERATED, DO NOT EDIT!
|
|
2
|
-
export const packageInfo = { name: '@dedot/codegen', version: '0.0.1-alpha.
|
|
2
|
+
export const packageInfo = { name: '@dedot/codegen', version: '0.0.1-alpha.28' };
|