@dedot/codegen 0.0.1-next.020a0293.9 → 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 +8 -4
- 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 -15
- package/cjs/generator/RuntimeApisGen.js +19 -15
- package/cjs/generator/TxGen.js +9 -9
- package/cjs/generator/TypesGen.js +19 -18
- package/cjs/generator/index.js +10 -10
- package/cjs/generator/known-codecs.js +151 -0
- package/cjs/generator/known-types.js +33 -0
- package/cjs/index.js +10 -10
- package/cjs/packageInfo.js +1 -1
- package/genSupportedChainTypes.js +7 -3
- package/generator/ApiGen.d.ts +3 -3
- 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 +4 -3
- package/generator/RuntimeApisGen.d.ts +2 -2
- package/generator/RuntimeApisGen.js +8 -4
- package/generator/TxGen.d.ts +1 -1
- package/generator/TxGen.js +2 -2
- package/generator/TypesGen.d.ts +3 -3
- package/generator/TypesGen.js +12 -11
- package/generator/index.d.ts +10 -10
- package/generator/index.js +10 -10
- package/generator/known-codecs.d.ts +23 -0
- package/generator/known-codecs.js +120 -0
- package/generator/known-types.d.ts +6 -0
- package/generator/known-types.js +30 -0
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +7 -7
- package/packageInfo.js +1 -1
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);
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.isKnownCodecType = exports.findKnownWrapperCodec = exports.findKnownCodec = exports.findKnownCodecType = exports.looseTypeCodecs = exports.normalizeCodecName = void 0;
|
|
27
|
+
const $ = __importStar(require("@dedot/shape"));
|
|
28
|
+
const Codecs = __importStar(require("@dedot/codecs"));
|
|
29
|
+
const codecs_1 = require("@dedot/codecs");
|
|
30
|
+
const utils_1 = require("@dedot/utils");
|
|
31
|
+
const normalizeCodecName = (name) => {
|
|
32
|
+
return name.startsWith('$') ? name : `$${name}`;
|
|
33
|
+
};
|
|
34
|
+
exports.normalizeCodecName = normalizeCodecName;
|
|
35
|
+
// Known paths for codecs (primitives) that are shared between
|
|
36
|
+
// different substrate-based blockchains
|
|
37
|
+
const KNOWN_PATHS = [
|
|
38
|
+
'sp_core::crypto::AccountId32',
|
|
39
|
+
'sp_runtime::generic::era::Era',
|
|
40
|
+
'sp_runtime::multiaddress::MultiAddress',
|
|
41
|
+
/^sp_runtime::DispatchError$/,
|
|
42
|
+
'sp_runtime::ModuleError',
|
|
43
|
+
'sp_runtime::TokenError',
|
|
44
|
+
'sp_arithmetic::ArithmeticError',
|
|
45
|
+
'sp_runtime::TransactionalError',
|
|
46
|
+
'frame_support::dispatch::DispatchInfo',
|
|
47
|
+
'frame_system::Phase',
|
|
48
|
+
'sp_version::RuntimeVersion',
|
|
49
|
+
'fp_account::AccountId20',
|
|
50
|
+
'account::AccountId20',
|
|
51
|
+
'polkadot_runtime_common::claims::EthereumAddress',
|
|
52
|
+
'pallet_identity::types::Data',
|
|
53
|
+
'sp_runtime::generic::digest::Digest',
|
|
54
|
+
'sp_runtime::generic::digest::DigestItem',
|
|
55
|
+
'sp_runtime::generic::header::Header',
|
|
56
|
+
'sp_runtime::generic::unchecked_extrinsic::UncheckedExtrinsic',
|
|
57
|
+
/^primitive_types::\w+$/,
|
|
58
|
+
/^sp_arithmetic::per_things::\w+$/,
|
|
59
|
+
/^sp_arithmetic::fixed_point::\w+$/,
|
|
60
|
+
];
|
|
61
|
+
const WRAPPER_TYPE_REGEX = /^(\w+)<(.*)>$/;
|
|
62
|
+
const TUPLE_TYPE_REGEX = /^\[(.*)]$/;
|
|
63
|
+
const KNOWN_WRAPPER_TYPES = ['Option', 'Vec', 'Result', 'Array'];
|
|
64
|
+
/**
|
|
65
|
+
* Collection of codec types with loose input types
|
|
66
|
+
*
|
|
67
|
+
* Loose codecs are codecs with different typeIn & typeOut,
|
|
68
|
+
* E.g: Codec `$AccountId32`, we have its typeIn is `AccountId32Like` & typeOut is `AccountId32`
|
|
69
|
+
*
|
|
70
|
+
* This registry keep track the list of codecs which follow this convention
|
|
71
|
+
*/
|
|
72
|
+
exports.looseTypeCodecs = {
|
|
73
|
+
$AccountId20: codecs_1.$AccountId20,
|
|
74
|
+
$EthereumAddress: codecs_1.$EthereumAddress,
|
|
75
|
+
$AccountId32: codecs_1.$AccountId32,
|
|
76
|
+
$ConsensusEngineId: codecs_1.$ConsensusEngineId,
|
|
77
|
+
$StorageKey: codecs_1.$StorageKey,
|
|
78
|
+
$StorageData: codecs_1.$StorageData,
|
|
79
|
+
$PrefixedStorageKey: codecs_1.$PrefixedStorageKey,
|
|
80
|
+
$Bytes: codecs_1.$Bytes,
|
|
81
|
+
$RawBytes: codecs_1.$RawBytes,
|
|
82
|
+
$MultiAddress: codecs_1.$MultiAddress,
|
|
83
|
+
$OpaqueExtrinsic: codecs_1.$OpaqueExtrinsic,
|
|
84
|
+
$UncheckedExtrinsic: codecs_1.$UncheckedExtrinsic,
|
|
85
|
+
$Era: codecs_1.$Era,
|
|
86
|
+
};
|
|
87
|
+
function findKnownCodecType(name) {
|
|
88
|
+
const normalizedName = (0, exports.normalizeCodecName)(name);
|
|
89
|
+
const $knownCodec = exports.looseTypeCodecs[normalizedName];
|
|
90
|
+
if ($knownCodec) {
|
|
91
|
+
return {
|
|
92
|
+
name: normalizedName,
|
|
93
|
+
$codec: $knownCodec,
|
|
94
|
+
typeIn: `${name}Like`,
|
|
95
|
+
typeOut: name,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
const $codec = findKnownCodec(name);
|
|
99
|
+
if ($codec.nativeType && $[name]) {
|
|
100
|
+
return {
|
|
101
|
+
name: normalizedName,
|
|
102
|
+
$codec,
|
|
103
|
+
typeIn: $codec.nativeType,
|
|
104
|
+
typeOut: $codec.nativeType,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
name: normalizedName,
|
|
109
|
+
$codec,
|
|
110
|
+
typeIn: name,
|
|
111
|
+
typeOut: name,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
exports.findKnownCodecType = findKnownCodecType;
|
|
115
|
+
function findKnownCodec(typeName) {
|
|
116
|
+
// @ts-ignore
|
|
117
|
+
const $codec = findKnownWrapperCodec(typeName) || Codecs[(0, exports.normalizeCodecName)(typeName)] || $[typeName];
|
|
118
|
+
(0, utils_1.assert)($codec, `Known codec not found - ${typeName}`);
|
|
119
|
+
return $codec;
|
|
120
|
+
}
|
|
121
|
+
exports.findKnownCodec = findKnownCodec;
|
|
122
|
+
function findKnownWrapperCodec(typeName) {
|
|
123
|
+
const matchNames = typeName.match(WRAPPER_TYPE_REGEX);
|
|
124
|
+
if (matchNames) {
|
|
125
|
+
const [_, wrapper, inner] = matchNames;
|
|
126
|
+
if (KNOWN_WRAPPER_TYPES.includes(wrapper)) {
|
|
127
|
+
// @ts-ignore
|
|
128
|
+
const $Wrapper = $[wrapper];
|
|
129
|
+
if (inner.match(TUPLE_TYPE_REGEX) || inner.match(WRAPPER_TYPE_REGEX)) {
|
|
130
|
+
return $Wrapper(findKnownWrapperCodec(inner));
|
|
131
|
+
}
|
|
132
|
+
const $inners = inner.split(',').map((one) => findKnownCodec(one.trim()));
|
|
133
|
+
return $Wrapper(...$inners);
|
|
134
|
+
}
|
|
135
|
+
throw new Error(`Unknown wrapper type ${wrapper} from ${typeName}`);
|
|
136
|
+
}
|
|
137
|
+
else if (typeName.match(TUPLE_TYPE_REGEX)) {
|
|
138
|
+
const $inner = typeName
|
|
139
|
+
.slice(1, -1)
|
|
140
|
+
.split(',')
|
|
141
|
+
.filter((x) => x)
|
|
142
|
+
.map((one) => findKnownCodec(one.trim()));
|
|
143
|
+
return $.Tuple(...$inner);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
exports.findKnownWrapperCodec = findKnownWrapperCodec;
|
|
147
|
+
function isKnownCodecType(path) {
|
|
148
|
+
const joinedPath = Array.isArray(path) ? path.join('::') : path;
|
|
149
|
+
return KNOWN_PATHS.some((one) => joinedPath.match(one));
|
|
150
|
+
}
|
|
151
|
+
exports.isKnownCodecType = isKnownCodecType;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.knownTypes = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Known type names registered in @dedot/types
|
|
6
|
+
* Since TS interfaces are trim-off when compiling,
|
|
7
|
+
* So we need to register them explicitly here for RPC codegen process
|
|
8
|
+
*/
|
|
9
|
+
exports.knownTypes = [
|
|
10
|
+
'ExtrinsicOrHash',
|
|
11
|
+
'EpochAuthorship',
|
|
12
|
+
'BlockStats',
|
|
13
|
+
'Prevotes',
|
|
14
|
+
'Precommits',
|
|
15
|
+
'RoundState',
|
|
16
|
+
'ReportedRoundStates',
|
|
17
|
+
'JustificationNotification',
|
|
18
|
+
'EncodedFinalityProofs',
|
|
19
|
+
'LeavesProof',
|
|
20
|
+
'StorageKind',
|
|
21
|
+
'RpcMethods',
|
|
22
|
+
'ReadProof',
|
|
23
|
+
'StorageChangeSet',
|
|
24
|
+
'TraceBlockResponse',
|
|
25
|
+
'MigrationStatusResult',
|
|
26
|
+
'ChainType',
|
|
27
|
+
'ChainProperties',
|
|
28
|
+
'Health',
|
|
29
|
+
'SyncState',
|
|
30
|
+
'PeerInfo',
|
|
31
|
+
'NodeRole',
|
|
32
|
+
'NetworkState',
|
|
33
|
+
];
|
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,7 +1,7 @@
|
|
|
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
|
-
import { $Metadata,
|
|
4
|
+
import { $Metadata, PortableRegistry } from '@dedot/codecs';
|
|
5
5
|
import { ConstantExecutor } from 'dedot';
|
|
6
6
|
const NETWORKS = [
|
|
7
7
|
{
|
|
@@ -33,6 +33,10 @@ const NETWORKS = [
|
|
|
33
33
|
chain: 'kusamaAssetHub',
|
|
34
34
|
endpoint: 'wss://kusama-asset-hub-rpc.polkadot.io/',
|
|
35
35
|
},
|
|
36
|
+
{
|
|
37
|
+
chain: 'rococo',
|
|
38
|
+
endpoint: 'wss://rococo-rpc.polkadot.io/',
|
|
39
|
+
},
|
|
36
40
|
{
|
|
37
41
|
chain: 'rococoAssetHub',
|
|
38
42
|
endpoint: 'wss://rococo-asset-hub-rpc.polkadot.io/',
|
|
@@ -64,7 +68,7 @@ async function run() {
|
|
|
64
68
|
console.log('DONE!');
|
|
65
69
|
}
|
|
66
70
|
const getRuntimeVersion = (metadata) => {
|
|
67
|
-
const registry = new
|
|
71
|
+
const registry = new PortableRegistry(metadata.latest);
|
|
68
72
|
const executor = new ConstantExecutor({
|
|
69
73
|
registry,
|
|
70
74
|
metadataLatest: metadata.latest,
|
package/generator/ApiGen.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TypesGen } from '../generator';
|
|
1
|
+
import { TypesGen } from '../generator/index.js';
|
|
2
2
|
export declare abstract class ApiGen {
|
|
3
3
|
readonly typesGen: TypesGen;
|
|
4
4
|
constructor(typesGen: TypesGen);
|
|
@@ -44,7 +44,7 @@ export declare abstract class ApiGen {
|
|
|
44
44
|
} | {
|
|
45
45
|
tag: "Primitive";
|
|
46
46
|
value: {
|
|
47
|
-
kind: "bool" | "
|
|
47
|
+
kind: "bool" | "u8" | "i8" | "u16" | "i16" | "u32" | "i32" | "u64" | "i64" | "u128" | "i128" | "u256" | "i256" | "str" | "char";
|
|
48
48
|
};
|
|
49
49
|
} | {
|
|
50
50
|
tag: "Compact";
|
|
@@ -134,5 +134,5 @@ export declare abstract class ApiGen {
|
|
|
134
134
|
}>;
|
|
135
135
|
};
|
|
136
136
|
};
|
|
137
|
-
get registry(): import("@dedot/codecs").
|
|
137
|
+
get registry(): import("@dedot/codecs").PortableRegistry;
|
|
138
138
|
}
|
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,7 +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';
|
|
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';
|
|
5
6
|
const HIDDEN_RPCS = [
|
|
6
7
|
// Ref: https://github.com/paritytech/polkadot-sdk/blob/43415ef58c143b985e09015cd000dbd65f6d3997/substrate/client/rpc-servers/src/lib.rs#L152C9-L158
|
|
7
8
|
'rpc_methods',
|
|
@@ -165,7 +166,7 @@ export class RpcGen extends ApiGen {
|
|
|
165
166
|
return type;
|
|
166
167
|
}
|
|
167
168
|
#getCodecType(type, toTypeIn = true) {
|
|
168
|
-
const { typeIn, typeOut } =
|
|
169
|
+
const { typeIn, typeOut } = findKnownCodecType(type);
|
|
169
170
|
return toTypeIn ? typeIn : typeOut;
|
|
170
171
|
}
|
|
171
172
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { beautifySourceCode, commentBlock, compileTemplate } from './utils';
|
|
1
|
+
import { getRuntimeApiNames, getRuntimeApiSpecs } from '@dedot/specs';
|
|
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;
|
|
@@ -93,7 +93,7 @@ export class RuntimeApisGen extends RpcGen {
|
|
|
93
93
|
}
|
|
94
94
|
#targetRuntimeApiSpecs() {
|
|
95
95
|
const specs = this.runtimeApis.map(([runtimeApiHash, version]) => {
|
|
96
|
-
const runtimeApiSpec = findRuntimeApiSpec(runtimeApiHash, version);
|
|
96
|
+
const runtimeApiSpec = this.#findRuntimeApiSpec(runtimeApiHash, version);
|
|
97
97
|
if (!runtimeApiSpec)
|
|
98
98
|
return;
|
|
99
99
|
return {
|
|
@@ -108,4 +108,8 @@ export class RuntimeApisGen extends RpcGen {
|
|
|
108
108
|
return [...o, spec];
|
|
109
109
|
}, []);
|
|
110
110
|
}
|
|
111
|
+
#findRuntimeApiSpec = (runtimeApiHash, version) => {
|
|
112
|
+
const runtimeApiName = getRuntimeApiNames().find((one) => calculateRuntimeApiHash(one) === runtimeApiHash);
|
|
113
|
+
return getRuntimeApiSpecs().find((one) => one.runtimeApiName === runtimeApiName && one.version === version);
|
|
114
|
+
};
|
|
111
115
|
}
|
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
|
-
import {
|
|
2
|
-
import { TypeImports } from './TypeImports';
|
|
1
|
+
import { PortableRegistry, Field, MetadataLatest, PortableType, TypeId } from '@dedot/codecs';
|
|
2
|
+
import { TypeImports } from './TypeImports.js';
|
|
3
3
|
interface NamedType extends PortableType {
|
|
4
4
|
name: string;
|
|
5
5
|
nameOut: string;
|
|
@@ -15,7 +15,7 @@ export declare class TypesGen {
|
|
|
15
15
|
* Types will be generated its definition out.
|
|
16
16
|
*/
|
|
17
17
|
includedTypes: Record<TypeId, NamedType>;
|
|
18
|
-
registry:
|
|
18
|
+
registry: PortableRegistry;
|
|
19
19
|
typeImports: TypeImports;
|
|
20
20
|
constructor(metadata: MetadataLatest);
|
|
21
21
|
generate(): Promise<string>;
|
package/generator/TypesGen.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { stringPascalCase } from '@polkadot/util';
|
|
2
|
-
import {
|
|
2
|
+
import { PortableRegistry } from '@dedot/codecs';
|
|
3
3
|
import { isNativeType, normalizeName } from '@dedot/utils';
|
|
4
|
-
import { beautifySourceCode, commentBlock, compileTemplate } from './utils';
|
|
5
|
-
import {
|
|
6
|
-
import { TypeImports } from './TypeImports';
|
|
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';
|
|
7
8
|
// Skip generate types for these
|
|
8
9
|
// as we do have native types for them
|
|
9
10
|
const SKIP_TYPES = [
|
|
@@ -37,7 +38,7 @@ export class TypesGen {
|
|
|
37
38
|
typeImports;
|
|
38
39
|
constructor(metadata) {
|
|
39
40
|
this.metadata = metadata;
|
|
40
|
-
this.registry = new
|
|
41
|
+
this.registry = new PortableRegistry(this.metadata);
|
|
41
42
|
this.includedTypes = this.#includedTypes();
|
|
42
43
|
this.typeImports = new TypeImports();
|
|
43
44
|
}
|
|
@@ -99,7 +100,7 @@ export class TypesGen {
|
|
|
99
100
|
const { tag, value } = type;
|
|
100
101
|
switch (tag) {
|
|
101
102
|
case 'Primitive':
|
|
102
|
-
const $codec =
|
|
103
|
+
const $codec = findKnownCodec(value.kind);
|
|
103
104
|
if ($codec.nativeType) {
|
|
104
105
|
return $codec.nativeType;
|
|
105
106
|
}
|
|
@@ -168,7 +169,7 @@ export class TypesGen {
|
|
|
168
169
|
membersType.push([keyName, this.generateObjectType(fields, nestedLevel + 1, typeOut), docs]);
|
|
169
170
|
}
|
|
170
171
|
}
|
|
171
|
-
const { tagKey, valueKey } = this.registry.
|
|
172
|
+
const { tagKey, valueKey } = this.registry.getEnumOptions(typeId);
|
|
172
173
|
return membersType
|
|
173
174
|
.map(([keyName, valueType, docs]) => ({
|
|
174
175
|
tag: `${tagKey}: '${keyName}'`,
|
|
@@ -263,8 +264,8 @@ export class TypesGen {
|
|
|
263
264
|
const suffix = typeSuffixes.get(id) || '';
|
|
264
265
|
let knownType = false;
|
|
265
266
|
let name, nameOut;
|
|
266
|
-
if (
|
|
267
|
-
const codecType =
|
|
267
|
+
if (isKnownCodecType(joinedPath)) {
|
|
268
|
+
const codecType = findKnownCodecType(path.at(-1));
|
|
268
269
|
name = codecType.typeIn;
|
|
269
270
|
nameOut = codecType.typeOut;
|
|
270
271
|
knownType = true;
|
|
@@ -317,7 +318,7 @@ export class TypesGen {
|
|
|
317
318
|
}
|
|
318
319
|
#shouldGenerateTypeIn(id) {
|
|
319
320
|
const { callTypeId } = this.metadata.extrinsic;
|
|
320
|
-
const palletCallTypeIds = this.registry.
|
|
321
|
+
const palletCallTypeIds = this.registry.getPalletCallTypeIds();
|
|
321
322
|
return callTypeId === id || palletCallTypeIds.includes(id);
|
|
322
323
|
}
|
|
323
324
|
eqlCache = new Map();
|
|
@@ -422,7 +423,7 @@ export class TypesGen {
|
|
|
422
423
|
this.typeImports.addCodecType(typeName);
|
|
423
424
|
return;
|
|
424
425
|
}
|
|
425
|
-
if (
|
|
426
|
+
if (knownTypes.includes(typeName)) {
|
|
426
427
|
this.typeImports.addKnownType(typeName);
|
|
427
428
|
}
|
|
428
429
|
else {
|
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';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as $ from '@dedot/shape';
|
|
2
|
+
import { AnyShape } from '@dedot/shape';
|
|
3
|
+
export type CodecName = `$${string}`;
|
|
4
|
+
export interface CodecType {
|
|
5
|
+
name: CodecName;
|
|
6
|
+
$codec: AnyShape;
|
|
7
|
+
typeIn: string;
|
|
8
|
+
typeOut: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const normalizeCodecName: (name: string | CodecName) => CodecName;
|
|
11
|
+
/**
|
|
12
|
+
* Collection of codec types with loose input types
|
|
13
|
+
*
|
|
14
|
+
* Loose codecs are codecs with different typeIn & typeOut,
|
|
15
|
+
* E.g: Codec `$AccountId32`, we have its typeIn is `AccountId32Like` & typeOut is `AccountId32`
|
|
16
|
+
*
|
|
17
|
+
* This registry keep track the list of codecs which follow this convention
|
|
18
|
+
*/
|
|
19
|
+
export declare const looseTypeCodecs: Record<string, AnyShape>;
|
|
20
|
+
export declare function findKnownCodecType(name: string): CodecType;
|
|
21
|
+
export declare function findKnownCodec<I = unknown, O = I>(typeName: string): $.Shape<I, O>;
|
|
22
|
+
export declare function findKnownWrapperCodec(typeName: string): $.AnyShape | undefined;
|
|
23
|
+
export declare function isKnownCodecType(path: string | string[]): boolean;
|