@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.
Files changed (45) hide show
  1. package/cjs/genSupportedChainTypes.js +8 -4
  2. package/cjs/generator/ConstsGen.js +8 -8
  3. package/cjs/generator/ErrorsGen.js +11 -11
  4. package/cjs/generator/EventsGen.js +12 -12
  5. package/cjs/generator/IndexGen.js +3 -3
  6. package/cjs/generator/QueryGen.js +8 -8
  7. package/cjs/generator/RpcGen.js +16 -15
  8. package/cjs/generator/RuntimeApisGen.js +19 -15
  9. package/cjs/generator/TxGen.js +9 -9
  10. package/cjs/generator/TypesGen.js +19 -18
  11. package/cjs/generator/index.js +10 -10
  12. package/cjs/generator/known-codecs.js +151 -0
  13. package/cjs/generator/known-types.js +33 -0
  14. package/cjs/index.js +10 -10
  15. package/cjs/packageInfo.js +1 -1
  16. package/genSupportedChainTypes.js +7 -3
  17. package/generator/ApiGen.d.ts +3 -3
  18. package/generator/ConstsGen.d.ts +1 -1
  19. package/generator/ConstsGen.js +2 -2
  20. package/generator/ErrorsGen.d.ts +1 -1
  21. package/generator/ErrorsGen.js +2 -2
  22. package/generator/EventsGen.d.ts +1 -1
  23. package/generator/EventsGen.js +2 -2
  24. package/generator/IndexGen.d.ts +1 -1
  25. package/generator/IndexGen.js +1 -1
  26. package/generator/QueryGen.d.ts +1 -1
  27. package/generator/QueryGen.js +2 -2
  28. package/generator/RpcGen.d.ts +1 -1
  29. package/generator/RpcGen.js +4 -3
  30. package/generator/RuntimeApisGen.d.ts +2 -2
  31. package/generator/RuntimeApisGen.js +8 -4
  32. package/generator/TxGen.d.ts +1 -1
  33. package/generator/TxGen.js +2 -2
  34. package/generator/TypesGen.d.ts +3 -3
  35. package/generator/TypesGen.js +12 -11
  36. package/generator/index.d.ts +10 -10
  37. package/generator/index.js +10 -10
  38. package/generator/known-codecs.d.ts +23 -0
  39. package/generator/known-codecs.js +120 -0
  40. package/generator/known-types.d.ts +6 -0
  41. package/generator/known-types.js +30 -0
  42. package/index.d.ts +1 -1
  43. package/index.js +1 -1
  44. package/package.json +7 -7
  45. 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 index_1 = require("./index");
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");
@@ -38,6 +38,10 @@ const NETWORKS = [
38
38
  chain: 'kusamaAssetHub',
39
39
  endpoint: 'wss://kusama-asset-hub-rpc.polkadot.io/',
40
40
  },
41
+ {
42
+ chain: 'rococo',
43
+ endpoint: 'wss://rococo-rpc.polkadot.io/',
44
+ },
41
45
  {
42
46
  chain: 'rococoAssetHub',
43
47
  endpoint: 'wss://rococo-asset-hub-rpc.polkadot.io/',
@@ -57,19 +61,19 @@ async function run() {
57
61
  const { chain, endpoint, metadataHex, rpcMethods } = network;
58
62
  if (endpoint) {
59
63
  console.log(`Generate types for ${chain} via endpoint ${endpoint}`);
60
- await (0, index_1.generateTypesFromChain)(network, endpoint, OUT_DIR);
64
+ await (0, index_js_1.generateTypesFromChain)(network, endpoint, OUT_DIR);
61
65
  }
62
66
  else if (metadataHex && rpcMethods) {
63
67
  console.log(`Generate types for ${chain} via raw data`);
64
68
  const metadata = codecs_1.$Metadata.tryDecode(metadataHex);
65
69
  const runtimeVersion = getRuntimeVersion(metadata);
66
- await (0, index_1.generateTypes)(network, metadata.latest, rpcMethods, runtimeVersion.apis, OUT_DIR);
70
+ await (0, index_js_1.generateTypes)(network, metadata.latest, rpcMethods, runtimeVersion.apis, OUT_DIR);
67
71
  }
68
72
  }
69
73
  console.log('DONE!');
70
74
  }
71
75
  const getRuntimeVersion = (metadata) => {
72
- const registry = new codecs_1.CodecRegistry(metadata.latest);
76
+ const registry = new codecs_1.PortableRegistry(metadata.latest);
73
77
  const executor = new dedot_1.ConstantExecutor({
74
78
  registry,
75
79
  metadataLatest: metadata.latest,
@@ -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 generator_1 = require("../generator");
7
- const utils_2 = require("./utils");
8
- class ConstsGen extends generator_1.ApiGen {
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, utils_2.commentBlock)(`Pallet \`${pallet.name}\`'s constants`);
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, utils_2.commentBlock)(docs)}${name}: ${type}`).join(',\n')}
22
+ ${typedConstants.map(({ name, type, docs }) => `${(0, utils_js_1.commentBlock)(docs)}${name}: ${type}`).join(',\n')}
23
23
 
24
- ${(0, utils_2.commentBlock)('Generic pallet constant')}[name: string]: any,
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, utils_2.compileTemplate)('consts.hbs');
29
- return (0, utils_2.beautifySourceCode)(template({ importTypes, defTypeOut }));
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 ApiGen_1 = require("./ApiGen");
5
- const utils_1 = require("./utils");
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 utils_2 = require("@dedot/utils");
8
- class ErrorsGen extends ApiGen_1.ApiGen {
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, utils_1.commentBlock)(`Pallet \`${pallet.name}\`'s errors`);
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, utils_1.commentBlock)(docs)}${(0, util_1.stringPascalCase)(name)}: GenericPalletError`)
23
+ .map(({ name, docs }) => `${(0, utils_js_1.commentBlock)(docs)}${(0, util_1.stringPascalCase)(name)}: GenericPalletError`)
24
24
  .join(',\n')}
25
25
 
26
- ${(0, utils_1.commentBlock)('Generic pallet error')}[error: string]: GenericPalletError,
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, utils_1.compileTemplate)('errors.hbs');
31
- return (0, utils_1.beautifySourceCode)(template({ importTypes, defTypeOut }));
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, utils_2.assert)(def, `Error def not found for id ${errorTypeId}`);
35
+ (0, utils_1.assert)(def, `Error def not found for id ${errorTypeId}`);
36
36
  const { tag, value } = def.type;
37
- (0, utils_2.assert)(tag === 'Enum', `Invalid pallet error type!`);
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 ApiGen_1 = require("./ApiGen");
5
- const utils_1 = require("./utils");
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 utils_2 = require("@dedot/utils");
8
- class EventsGen extends ApiGen_1.ApiGen {
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, utils_1.commentBlock)(`Pallet \`${pallet.name}\`'s events`);
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, utils_1.commentBlock)(docs)}${(0, util_1.stringPascalCase)(name)}: GenericPalletEvent<${genericParts.join(', ')}>`)
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, utils_1.commentBlock)('Generic pallet event')}[prop: string]: GenericPalletEvent,
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, utils_1.compileTemplate)('events.hbs');
43
- return (0, utils_1.beautifySourceCode)(template({ importTypes, defTypeOut }));
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, utils_2.assert)(def, `Event def not found for id ${typeId}`);
47
+ (0, utils_1.assert)(def, `Event def not found for id ${typeId}`);
48
48
  const { tag, value } = def.type;
49
- (0, utils_2.assert)(tag === 'Enum', 'Invalid pallet event type!');
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, utils_1.commentBlock)(docs)}${this.typesGen.generateType(typeId, 1, true)}`)
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 utils_1 = require("./utils");
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, utils_1.compileTemplate)('index.hbs');
15
- return (0, utils_1.beautifySourceCode)(template({ interfaceName }));
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 generator_1 = require("../generator");
7
- const utils_2 = require("./utils");
8
- class QueryGen extends generator_1.ApiGen {
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, utils_2.commentBlock)(docs)}${name}: GenericStorageQuery<(${keyType}) => ${valueType}>`);
20
- defTypeOut += (0, utils_2.commentBlock)(`Pallet \`${pallet.name}\`'s storage queries`);
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, utils_2.commentBlock)('Generic pallet storage query')}[storage: string]: GenericStorageQuery;
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, utils_2.compileTemplate)('query.hbs');
29
- return (0, utils_2.beautifySourceCode)(template({ importTypes, defTypeOut }));
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;
@@ -3,13 +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 generator_1 = require("../generator");
7
- const utils_2 = require("./utils");
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");
8
9
  const HIDDEN_RPCS = [
9
10
  // Ref: https://github.com/paritytech/polkadot-sdk/blob/43415ef58c143b985e09015cd000dbd65f6d3997/substrate/client/rpc-servers/src/lib.rs#L152C9-L158
10
11
  'rpc_methods',
11
12
  ];
12
- class RpcGen extends generator_1.ApiGen {
13
+ class RpcGen extends index_js_1.ApiGen {
13
14
  typesGen;
14
15
  rpcMethods;
15
16
  constructor(typesGen, rpcMethods) {
@@ -62,8 +63,8 @@ class RpcGen extends generator_1.ApiGen {
62
63
  });
63
64
  // TODO include & define external types
64
65
  const importTypes = this.typesGen.typeImports.toImports();
65
- const template = (0, utils_2.compileTemplate)('rpc.hbs');
66
- return (0, utils_2.beautifySourceCode)(template({ importTypes, rpcCallsOut }));
66
+ const template = (0, utils_js_1.compileTemplate)('rpc.hbs');
67
+ return (0, utils_js_1.beautifySourceCode)(template({ importTypes, rpcCallsOut }));
67
68
  }
68
69
  #generateMethodDef(spec) {
69
70
  const { name, type, module, method, docs = [], params, pubsub, deprecated } = spec;
@@ -73,7 +74,7 @@ class RpcGen extends generator_1.ApiGen {
73
74
  defaultDocs.push(`@deprecated: ${deprecated}`);
74
75
  }
75
76
  if (type === 'GenericRpcCall' && params.length === 0) {
76
- return `${(0, utils_2.commentBlock)(defaultDocs)}${method}: GenericRpcCall`;
77
+ return `${(0, utils_js_1.commentBlock)(defaultDocs)}${method}: GenericRpcCall`;
77
78
  }
78
79
  this.addTypeImport(type, false);
79
80
  params.forEach(({ type, isScale }) => {
@@ -91,10 +92,10 @@ class RpcGen extends generator_1.ApiGen {
91
92
  defaultDocs.shift();
92
93
  defaultDocs.unshift(`@pubsub: ${pubsub?.join(', ')}`);
93
94
  paramsOut.push(`callback: Callback<${typeOut}>`);
94
- return `${(0, utils_2.commentBlock)(docs, '\n', defaultDocs, paramsDoc)}${method}: GenericRpcCall<(${paramsOut.join(', ')}) => Promise<Unsub>>`;
95
+ return `${(0, utils_js_1.commentBlock)(docs, '\n', defaultDocs, paramsDoc)}${method}: GenericRpcCall<(${paramsOut.join(', ')}) => Promise<Unsub>>`;
95
96
  }
96
97
  else {
97
- return `${(0, utils_2.commentBlock)(docs, '\n', defaultDocs, paramsDoc)}${method}: GenericRpcCall<(${paramsOut.join(', ')}) => Promise<${typeOut}>>`;
98
+ return `${(0, utils_js_1.commentBlock)(docs, '\n', defaultDocs, paramsDoc)}${method}: GenericRpcCall<(${paramsOut.join(', ')}) => Promise<${typeOut}>>`;
98
99
  }
99
100
  }
100
101
  // TODO check typeIn, typeOut if param type, or rpc type isScale
@@ -108,11 +109,11 @@ class RpcGen extends generator_1.ApiGen {
108
109
  return;
109
110
  }
110
111
  // Handle generic wrapper types
111
- const matchArray = type.match(utils_2.WRAPPER_TYPE_REGEX);
112
+ const matchArray = type.match(utils_js_1.WRAPPER_TYPE_REGEX);
112
113
  if (matchArray) {
113
114
  const [_, $1, $2] = matchArray;
114
115
  this.addTypeImport($1, toTypeIn);
115
- if ($2.match(utils_2.WRAPPER_TYPE_REGEX) || $2.match(utils_2.TUPLE_TYPE_REGEX)) {
116
+ if ($2.match(utils_js_1.WRAPPER_TYPE_REGEX) || $2.match(utils_js_1.TUPLE_TYPE_REGEX)) {
116
117
  this.addTypeImport($2, toTypeIn);
117
118
  }
118
119
  else {
@@ -121,7 +122,7 @@ class RpcGen extends generator_1.ApiGen {
121
122
  return;
122
123
  }
123
124
  // Check tuple type
124
- if (type.match(utils_2.TUPLE_TYPE_REGEX)) {
125
+ if (type.match(utils_js_1.TUPLE_TYPE_REGEX)) {
125
126
  this.addTypeImport(type.slice(1, -1).split(','), toTypeIn);
126
127
  return;
127
128
  }
@@ -141,11 +142,11 @@ class RpcGen extends generator_1.ApiGen {
141
142
  }
142
143
  getGeneratedTypeName(type, toTypeIn = true) {
143
144
  try {
144
- const matchArray = type.match(utils_2.WRAPPER_TYPE_REGEX);
145
+ const matchArray = type.match(utils_js_1.WRAPPER_TYPE_REGEX);
145
146
  if (matchArray) {
146
147
  const [_, $1, $2] = matchArray;
147
148
  const wrapperTypeName = this.#getCodecType($1, toTypeIn);
148
- if ($2.match(utils_2.WRAPPER_TYPE_REGEX) || $2.match(utils_2.TUPLE_TYPE_REGEX)) {
149
+ if ($2.match(utils_js_1.WRAPPER_TYPE_REGEX) || $2.match(utils_js_1.TUPLE_TYPE_REGEX)) {
149
150
  return `${wrapperTypeName}<${this.getGeneratedTypeName($2, toTypeIn)}>`;
150
151
  }
151
152
  const innerTypeNames = $2
@@ -154,7 +155,7 @@ class RpcGen extends generator_1.ApiGen {
154
155
  .join(', ');
155
156
  return `${wrapperTypeName}<${innerTypeNames}>`;
156
157
  }
157
- else if (type.match(utils_2.TUPLE_TYPE_REGEX)) {
158
+ else if (type.match(utils_js_1.TUPLE_TYPE_REGEX)) {
158
159
  const innerTypeNames = type
159
160
  .slice(1, -1)
160
161
  .split(',')
@@ -168,7 +169,7 @@ class RpcGen extends generator_1.ApiGen {
168
169
  return type;
169
170
  }
170
171
  #getCodecType(type, toTypeIn = true) {
171
- const { typeIn, typeOut } = this.registry.findCodecType(type);
172
+ const { typeIn, typeOut } = (0, known_codecs_js_1.findKnownCodecType)(type);
172
173
  return toTypeIn ? typeIn : typeOut;
173
174
  }
174
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 utils_1 = require("./utils");
6
- const utils_2 = require("@dedot/utils");
7
- const RpcGen_1 = require("./RpcGen");
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 RpcGen_1.RpcGen {
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, utils_1.commentBlock)(`@runtimeapi: ${runtimeApiName} - ${(0, utils_2.calculateRuntimeApiHash)(runtimeApiName)}`);
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, utils_1.commentBlock)('Generic runtime api call')}[method: string]: GenericRuntimeApiMethod
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, utils_1.commentBlock)(`@runtimeapi: ${runtimeApiName} - ${runtimeApiHash}`, `@version: ${version}`);
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, utils_1.commentBlock)('Generic runtime api call')}[method: string]: GenericRuntimeApiMethod
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, utils_1.compileTemplate)('runtime.hbs');
51
- return (0, utils_1.beautifySourceCode)(template({ importTypes, runtimeCallsOut }));
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, utils_2.stringSnakeCase)(methodName)}`;
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, utils_1.commentBlock)(docs, '\n', defaultDocs, typedParams.map(({ plainType, name }) => `@param {${plainType}} ${name}`))}${methodName}: GenericRuntimeApiMethod<(${paramsOut}) => Promise<${typeOut}>>`;
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, utils_2.stringSnakeCase)(methodName)}`;
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,11 +92,11 @@ 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, utils_1.commentBlock)(docs, '\n', defaultDocs, typedInputs.map(({ type, name }) => `@param {${type}} ${name}`))}${(0, util_1.stringCamelCase)(methodName)}: GenericRuntimeApiMethod<(${paramsOut}) => Promise<${typeOut}>>`;
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]) => {
99
- const runtimeApiSpec = (0, specs_1.findRuntimeApiSpec)(runtimeApiHash, version);
99
+ const runtimeApiSpec = this.#findRuntimeApiSpec(runtimeApiHash, version);
100
100
  if (!runtimeApiSpec)
101
101
  return;
102
102
  return {
@@ -111,5 +111,9 @@ class RuntimeApisGen extends RpcGen_1.RpcGen {
111
111
  return [...o, spec];
112
112
  }, []);
113
113
  }
114
+ #findRuntimeApiSpec = (runtimeApiHash, version) => {
115
+ const runtimeApiName = (0, specs_1.getRuntimeApiNames)().find((one) => (0, utils_1.calculateRuntimeApiHash)(one) === runtimeApiHash);
116
+ return (0, specs_1.getRuntimeApiSpecs)().find((one) => one.runtimeApiName === runtimeApiName && one.version === version);
117
+ };
114
118
  }
115
119
  exports.RuntimeApisGen = RuntimeApisGen;
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TxGen = void 0;
4
- const generator_1 = require("../generator");
4
+ const index_js_1 = require("../generator/index.js");
5
5
  const util_1 = require("@polkadot/util");
6
- const utils_1 = require("./utils");
7
- class TxGen extends generator_1.ApiGen {
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, utils_1.commentBlock)(`Pallet \`${pallet.name}\`'s transaction calls`);
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, utils_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}>>`)
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, utils_1.commentBlock)('Generic pallet tx call')}[callName: string]: GenericTxCall<TxCall>,
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, utils_1.compileTemplate)('tx.hbs');
63
- return (0, utils_1.beautifySourceCode)(template({ importTypes, defTypes, txDefsOut }));
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, utils_1.isReservedWord)(name) ? `${name}_` : name;
67
+ return (0, utils_js_1.isReservedWord)(name) ? `${name}_` : name;
68
68
  }
69
69
  #generateCallInput(palletName, callName, params) {
70
70
  if (!params) {
@@ -4,9 +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 utils_2 = require("./utils");
8
- const types_1 = require("@dedot/types");
9
- const TypeImports_1 = require("./TypeImports");
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");
10
11
  // Skip generate types for these
11
12
  // as we do have native types for them
12
13
  const SKIP_TYPES = [
@@ -40,9 +41,9 @@ class TypesGen {
40
41
  typeImports;
41
42
  constructor(metadata) {
42
43
  this.metadata = metadata;
43
- this.registry = new codecs_1.CodecRegistry(this.metadata);
44
+ this.registry = new codecs_1.PortableRegistry(this.metadata);
44
45
  this.includedTypes = this.#includedTypes();
45
- this.typeImports = new TypeImports_1.TypeImports();
46
+ this.typeImports = new TypeImports_js_1.TypeImports();
46
47
  }
47
48
  generate() {
48
49
  this.clearCache();
@@ -50,14 +51,14 @@ class TypesGen {
50
51
  Object.values(this.includedTypes)
51
52
  .filter(({ skip, knownType }) => !(skip || knownType))
52
53
  .forEach(({ name, nameOut, id, docs }) => {
53
- defTypeOut += `${(0, utils_2.commentBlock)(docs)}export type ${nameOut} = ${this.generateType(id, 0, true)};\n\n`;
54
+ defTypeOut += `${(0, utils_js_1.commentBlock)(docs)}export type ${nameOut} = ${this.generateType(id, 0, true)};\n\n`;
54
55
  if (this.#shouldGenerateTypeIn(id)) {
55
56
  defTypeOut += `export type ${name} = ${this.generateType(id)};\n\n`;
56
57
  }
57
58
  });
58
59
  const importTypes = this.typeImports.toImports('./types');
59
- const template = (0, utils_2.compileTemplate)('types.hbs');
60
- return (0, utils_2.beautifySourceCode)(template({ importTypes, defTypeOut }));
60
+ const template = (0, utils_js_1.compileTemplate)('types.hbs');
61
+ return (0, utils_js_1.beautifySourceCode)(template({ importTypes, defTypeOut }));
61
62
  }
62
63
  typeCache = {};
63
64
  clearCache() {
@@ -102,7 +103,7 @@ class TypesGen {
102
103
  const { tag, value } = type;
103
104
  switch (tag) {
104
105
  case 'Primitive':
105
- const $codec = this.registry.findCodec(value.kind);
106
+ const $codec = (0, known_codecs_js_1.findKnownCodec)(value.kind);
106
107
  if ($codec.nativeType) {
107
108
  return $codec.nativeType;
108
109
  }
@@ -150,7 +151,7 @@ class TypesGen {
150
151
  return 'null';
151
152
  }
152
153
  else if (members.every((x) => x.fields.length === 0)) {
153
- return members.map(({ name, docs }) => `${(0, utils_2.commentBlock)(docs)}'${(0, util_1.stringPascalCase)(name)}'`).join(' | ');
154
+ return members.map(({ name, docs }) => `${(0, utils_js_1.commentBlock)(docs)}'${(0, util_1.stringPascalCase)(name)}'`).join(' | ');
154
155
  }
155
156
  else {
156
157
  const membersType = [];
@@ -163,7 +164,7 @@ class TypesGen {
163
164
  const valueType = fields.length === 1
164
165
  ? this.generateType(fields[0].typeId, nestedLevel + 1, typeOut)
165
166
  : `[${fields
166
- .map(({ typeId, docs }) => `${(0, utils_2.commentBlock)(docs)}${this.generateType(typeId, nestedLevel + 1, typeOut)}`)
167
+ .map(({ typeId, docs }) => `${(0, utils_js_1.commentBlock)(docs)}${this.generateType(typeId, nestedLevel + 1, typeOut)}`)
167
168
  .join(', ')}]`;
168
169
  membersType.push([keyName, valueType, docs]);
169
170
  }
@@ -171,14 +172,14 @@ class TypesGen {
171
172
  membersType.push([keyName, this.generateObjectType(fields, nestedLevel + 1, typeOut), docs]);
172
173
  }
173
174
  }
174
- const { tagKey, valueKey } = this.registry.portableRegistry.getEnumOptions(typeId);
175
+ const { tagKey, valueKey } = this.registry.getEnumOptions(typeId);
175
176
  return membersType
176
177
  .map(([keyName, valueType, docs]) => ({
177
178
  tag: `${tagKey}: '${keyName}'`,
178
179
  value: valueType ? `, ${valueKey}${this.#isOptionalType(valueType) ? '?' : ''}: ${valueType} ` : '',
179
180
  docs,
180
181
  }))
181
- .map(({ tag, value, docs }) => `${(0, utils_2.commentBlock)(docs)}{ ${tag}${value} }`)
182
+ .map(({ tag, value, docs }) => `${(0, utils_js_1.commentBlock)(docs)}{ ${tag}${value} }`)
182
183
  .join(' | ');
183
184
  }
184
185
  }
@@ -225,7 +226,7 @@ class TypesGen {
225
226
  };
226
227
  });
227
228
  return `{${props
228
- .map(({ name, type, optional, docs }) => `${(0, utils_2.commentBlock)(docs)}${name}${optional ? '?' : ''}: ${type}`)
229
+ .map(({ name, type, optional, docs }) => `${(0, utils_js_1.commentBlock)(docs)}${name}${optional ? '?' : ''}: ${type}`)
229
230
  .join(',\n')}}`;
230
231
  }
231
232
  #isOptionalType(type) {
@@ -266,8 +267,8 @@ class TypesGen {
266
267
  const suffix = typeSuffixes.get(id) || '';
267
268
  let knownType = false;
268
269
  let name, nameOut;
269
- if (this.registry.isKnownType(joinedPath)) {
270
- const codecType = this.registry.findCodecType(path.at(-1));
270
+ if ((0, known_codecs_js_1.isKnownCodecType)(joinedPath)) {
271
+ const codecType = (0, known_codecs_js_1.findKnownCodecType)(path.at(-1));
271
272
  name = codecType.typeIn;
272
273
  nameOut = codecType.typeOut;
273
274
  knownType = true;
@@ -320,7 +321,7 @@ class TypesGen {
320
321
  }
321
322
  #shouldGenerateTypeIn(id) {
322
323
  const { callTypeId } = this.metadata.extrinsic;
323
- const palletCallTypeIds = this.registry.portableRegistry.getPalletCallTypeIds();
324
+ const palletCallTypeIds = this.registry.getPalletCallTypeIds();
324
325
  return callTypeId === id || palletCallTypeIds.includes(id);
325
326
  }
326
327
  eqlCache = new Map();
@@ -425,7 +426,7 @@ class TypesGen {
425
426
  this.typeImports.addCodecType(typeName);
426
427
  return;
427
428
  }
428
- if (types_1.registry.has(typeName)) {
429
+ if (known_types_js_1.knownTypes.includes(typeName)) {
429
430
  this.typeImports.addKnownType(typeName);
430
431
  }
431
432
  else {