@dedot/codegen 0.0.1-alpha.3 → 0.0.1-alpha.30

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 (73) hide show
  1. package/cjs/generator/ConstsGen.js +9 -10
  2. package/cjs/generator/ErrorsGen.js +12 -13
  3. package/cjs/generator/EventsGen.js +13 -14
  4. package/cjs/generator/IndexGen.js +8 -9
  5. package/cjs/generator/QueryGen.js +9 -10
  6. package/cjs/generator/RpcGen.js +18 -18
  7. package/cjs/generator/RuntimeApisGen.js +34 -36
  8. package/cjs/generator/TxGen.js +15 -15
  9. package/cjs/generator/TypesGen.js +24 -24
  10. package/cjs/{types.js → generator/dirname.js} +3 -0
  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/generator/utils.js +33 -9
  15. package/cjs/index.js +29 -29
  16. package/cjs/templates/consts.hbs +7 -0
  17. package/cjs/templates/errors.hbs +7 -0
  18. package/cjs/templates/events.hbs +7 -0
  19. package/cjs/templates/index.hbs +22 -0
  20. package/cjs/templates/query.hbs +7 -0
  21. package/cjs/templates/rpc.hbs +7 -0
  22. package/cjs/templates/runtime.hbs +8 -0
  23. package/cjs/templates/tx.hbs +9 -0
  24. package/cjs/templates/types.hbs +5 -0
  25. package/generator/ApiGen.d.ts +3 -3
  26. package/generator/ConstsGen.d.ts +1 -1
  27. package/generator/ConstsGen.js +4 -5
  28. package/generator/ErrorsGen.d.ts +1 -1
  29. package/generator/ErrorsGen.js +3 -4
  30. package/generator/EventsGen.d.ts +1 -1
  31. package/generator/EventsGen.js +3 -4
  32. package/generator/IndexGen.d.ts +2 -3
  33. package/generator/IndexGen.js +6 -7
  34. package/generator/QueryGen.d.ts +1 -1
  35. package/generator/QueryGen.js +4 -5
  36. package/generator/RpcGen.d.ts +1 -1
  37. package/generator/RpcGen.js +4 -4
  38. package/generator/RuntimeApisGen.d.ts +2 -2
  39. package/generator/RuntimeApisGen.js +23 -25
  40. package/generator/TxGen.d.ts +1 -1
  41. package/generator/TxGen.js +3 -3
  42. package/generator/TypesGen.d.ts +3 -3
  43. package/generator/TypesGen.js +13 -13
  44. package/generator/dirname.d.ts +1 -0
  45. package/generator/dirname.js +6 -0
  46. package/generator/index.d.ts +10 -10
  47. package/generator/index.js +10 -10
  48. package/generator/known-codecs.d.ts +23 -0
  49. package/generator/known-codecs.js +120 -0
  50. package/generator/known-types.d.ts +6 -0
  51. package/generator/known-types.js +30 -0
  52. package/generator/utils.d.ts +5 -1
  53. package/generator/utils.js +31 -7
  54. package/index.d.ts +2 -3
  55. package/index.js +19 -19
  56. package/package.json +11 -10
  57. package/templates/consts.hbs +7 -0
  58. package/templates/errors.hbs +7 -0
  59. package/templates/events.hbs +7 -0
  60. package/templates/index.hbs +22 -0
  61. package/templates/query.hbs +7 -0
  62. package/templates/rpc.hbs +7 -0
  63. package/templates/runtime.hbs +8 -0
  64. package/templates/tx.hbs +9 -0
  65. package/templates/types.hbs +5 -0
  66. package/cjs/genSupportedChainTypes.js +0 -79
  67. package/cjs/packageInfo.js +0 -5
  68. package/genSupportedChainTypes.d.ts +0 -1
  69. package/genSupportedChainTypes.js +0 -74
  70. package/packageInfo.d.ts +0 -4
  71. package/packageInfo.js +0 -2
  72. package/types.d.ts +0 -6
  73. package/types.js +0 -1
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConstsGen = void 0;
4
- const util_1 = require("@polkadot/util");
5
4
  const utils_1 = require("@dedot/utils");
6
- const generator_1 = require("../generator");
7
- const utils_2 = require("./utils");
8
- class ConstsGen extends generator_1.ApiGen {
5
+ const index_js_1 = require("../generator/index.js");
6
+ const utils_js_1 = require("./utils.js");
7
+ class ConstsGen extends index_js_1.ApiGen {
9
8
  generate() {
10
9
  const { pallets } = this.metadata;
11
10
  this.typesGen.clearCache();
@@ -17,16 +16,16 @@ class ConstsGen extends generator_1.ApiGen {
17
16
  type: this.typesGen.generateType(one.typeId, 1, true),
18
17
  docs: one.docs,
19
18
  }));
20
- defTypeOut += (0, utils_2.commentBlock)(`Pallet \`${pallet.name}\`'s constants`);
21
- defTypeOut += `${(0, util_1.stringLowerFirst)(pallet.name)}: {
22
- ${typedConstants.map(({ name, type, docs }) => `${(0, utils_2.commentBlock)(docs)}${name}: ${type}`).join(',\n')}
19
+ defTypeOut += (0, utils_js_1.commentBlock)(`Pallet \`${pallet.name}\`'s constants`);
20
+ defTypeOut += `${(0, utils_1.stringCamelCase)(pallet.name)}: {
21
+ ${typedConstants.map(({ name, type, docs }) => `${(0, utils_js_1.commentBlock)(docs)}${name}: ${type}`).join(',\n')}
23
22
 
24
- ${(0, utils_2.commentBlock)('Generic pallet constant')}[name: string]: any,
23
+ ${(0, utils_js_1.commentBlock)('Generic pallet constant')}[name: string]: any,
25
24
  },`;
26
25
  }
27
26
  const importTypes = this.typesGen.typeImports.toImports();
28
- const template = (0, utils_2.compileTemplate)('consts.hbs');
29
- return (0, utils_2.beautifySourceCode)(template({ importTypes, defTypeOut }));
27
+ const template = (0, utils_js_1.compileTemplate)('consts.hbs');
28
+ return (0, utils_js_1.beautifySourceCode)(template({ importTypes, defTypeOut }));
30
29
  }
31
30
  }
32
31
  exports.ConstsGen = ConstsGen;
@@ -1,11 +1,10 @@
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");
6
- const util_1 = require("@polkadot/util");
7
- const utils_2 = require("@dedot/utils");
8
- class ErrorsGen extends ApiGen_1.ApiGen {
4
+ const ApiGen_js_1 = require("./ApiGen.js");
5
+ const utils_js_1 = require("./utils.js");
6
+ const utils_1 = require("@dedot/utils");
7
+ class ErrorsGen extends ApiGen_js_1.ApiGen {
9
8
  generate() {
10
9
  const { pallets } = this.metadata;
11
10
  this.typesGen.clearCache();
@@ -17,24 +16,24 @@ class ErrorsGen extends ApiGen_1.ApiGen {
17
16
  continue;
18
17
  }
19
18
  const errorDefs = this.#getErrorDefs(errorTypeId);
20
- defTypeOut += (0, utils_1.commentBlock)(`Pallet \`${pallet.name}\`'s errors`);
21
- defTypeOut += `${(0, util_1.stringCamelCase)(pallet.name)}: {
19
+ defTypeOut += (0, utils_js_1.commentBlock)(`Pallet \`${pallet.name}\`'s errors`);
20
+ defTypeOut += `${(0, utils_1.stringCamelCase)(pallet.name)}: {
22
21
  ${errorDefs
23
- .map(({ name, docs }) => `${(0, utils_1.commentBlock)(docs)}${(0, util_1.stringPascalCase)(name)}: GenericPalletError`)
22
+ .map(({ name, docs }) => `${(0, utils_js_1.commentBlock)(docs)}${(0, utils_1.stringPascalCase)(name)}: GenericPalletError`)
24
23
  .join(',\n')}
25
24
 
26
- ${(0, utils_1.commentBlock)('Generic pallet error')}[error: string]: GenericPalletError,
25
+ ${(0, utils_js_1.commentBlock)('Generic pallet error')}[error: string]: GenericPalletError,
27
26
  },`;
28
27
  }
29
28
  const importTypes = this.typesGen.typeImports.toImports();
30
- const template = (0, utils_1.compileTemplate)('errors.hbs');
31
- return (0, utils_1.beautifySourceCode)(template({ importTypes, defTypeOut }));
29
+ const template = (0, utils_js_1.compileTemplate)('errors.hbs');
30
+ return (0, utils_js_1.beautifySourceCode)(template({ importTypes, defTypeOut }));
32
31
  }
33
32
  #getErrorDefs(errorTypeId) {
34
33
  const def = this.metadata.types[errorTypeId];
35
- (0, utils_2.assert)(def, `Error def not found for id ${errorTypeId}`);
34
+ (0, utils_1.assert)(def, `Error def not found for id ${errorTypeId}`);
36
35
  const { tag, value } = def.type;
37
- (0, utils_2.assert)(tag === 'Enum', `Invalid pallet error type!`);
36
+ (0, utils_1.assert)(tag === 'Enum', `Invalid pallet error type!`);
38
37
  return value.members;
39
38
  }
40
39
  }
@@ -1,11 +1,10 @@
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");
6
- const util_1 = require("@polkadot/util");
7
- const utils_2 = require("@dedot/utils");
8
- class EventsGen extends ApiGen_1.ApiGen {
4
+ const ApiGen_js_1 = require("./ApiGen.js");
5
+ const utils_js_1 = require("./utils.js");
6
+ const utils_1 = require("@dedot/utils");
7
+ class EventsGen extends ApiGen_js_1.ApiGen {
9
8
  generate() {
10
9
  const { pallets } = this.metadata;
11
10
  this.typesGen.clearCache();
@@ -18,8 +17,8 @@ class EventsGen extends ApiGen_1.ApiGen {
18
17
  }
19
18
  const eventDefs = this.#getEventDefs(eventTypeId);
20
19
  const flatMembers = eventDefs.every((d) => d.fields.length === 0);
21
- defTypeOut += (0, utils_1.commentBlock)(`Pallet \`${pallet.name}\`'s events`);
22
- defTypeOut += `${(0, util_1.stringCamelCase)(pallet.name)}: {
20
+ defTypeOut += (0, utils_js_1.commentBlock)(`Pallet \`${pallet.name}\`'s events`);
21
+ defTypeOut += `${(0, utils_1.stringCamelCase)(pallet.name)}: {
23
22
  ${eventDefs
24
23
  .map((def) => {
25
24
  const genericParts = [`'${pallet.name}'`, `'${def.name}'`];
@@ -32,21 +31,21 @@ class EventsGen extends ApiGen_1.ApiGen {
32
31
  }
33
32
  return { ...def, genericParts };
34
33
  })
35
- .map(({ name, docs, fields, genericParts }) => `${(0, utils_1.commentBlock)(docs)}${(0, util_1.stringPascalCase)(name)}: GenericPalletEvent<${genericParts.join(', ')}>`)
34
+ .map(({ name, docs, fields, genericParts }) => `${(0, utils_js_1.commentBlock)(docs)}${(0, utils_1.stringPascalCase)(name)}: GenericPalletEvent<${genericParts.join(', ')}>`)
36
35
  .join(',\n')}
37
36
 
38
- ${(0, utils_1.commentBlock)('Generic pallet event')}[prop: string]: GenericPalletEvent,
37
+ ${(0, utils_js_1.commentBlock)('Generic pallet event')}[prop: string]: GenericPalletEvent,
39
38
  },`;
40
39
  }
41
40
  const importTypes = this.typesGen.typeImports.toImports();
42
- const template = (0, utils_1.compileTemplate)('events.hbs');
43
- return (0, utils_1.beautifySourceCode)(template({ importTypes, defTypeOut }));
41
+ const template = (0, utils_js_1.compileTemplate)('events.hbs');
42
+ return (0, utils_js_1.beautifySourceCode)(template({ importTypes, defTypeOut }));
44
43
  }
45
44
  #getEventDefs(typeId) {
46
45
  const def = this.metadata.types[typeId];
47
- (0, utils_2.assert)(def, `Event def not found for id ${typeId}`);
46
+ (0, utils_1.assert)(def, `Event def not found for id ${typeId}`);
48
47
  const { tag, value } = def.type;
49
- (0, utils_2.assert)(tag === 'Enum', 'Invalid pallet event type!');
48
+ (0, utils_1.assert)(tag === 'Enum', 'Invalid pallet event type!');
50
49
  return value.members;
51
50
  }
52
51
  #generateMemberDefType(fields) {
@@ -57,7 +56,7 @@ class EventsGen extends ApiGen_1.ApiGen {
57
56
  return fields.length === 1
58
57
  ? this.typesGen.generateType(fields[0].typeId, 1, true)
59
58
  : `[${fields
60
- .map(({ typeId, docs }) => `${(0, utils_1.commentBlock)(docs)}${this.typesGen.generateType(typeId, 1, true)}`)
59
+ .map(({ typeId, docs }) => `${(0, utils_js_1.commentBlock)(docs)}${this.typesGen.generateType(typeId, 1, true)}`)
61
60
  .join(', ')}]`;
62
61
  }
63
62
  else {
@@ -1,18 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.IndexGen = void 0;
4
- const utils_1 = require("./utils");
5
- const util_1 = require("@polkadot/util");
4
+ const utils_js_1 = require("./utils.js");
5
+ const utils_1 = require("@dedot/utils");
6
6
  class IndexGen {
7
- networkInfo;
8
- constructor(networkInfo) {
9
- this.networkInfo = networkInfo;
7
+ chain;
8
+ constructor(chain) {
9
+ this.chain = chain;
10
10
  }
11
11
  async generate() {
12
- const { chain } = this.networkInfo;
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 }));
12
+ const interfaceName = (0, utils_1.stringPascalCase)(this.chain);
13
+ const template = (0, utils_js_1.compileTemplate)('index.hbs');
14
+ return (0, utils_js_1.beautifySourceCode)(template({ interfaceName }));
16
15
  }
17
16
  }
18
17
  exports.IndexGen = IndexGen;
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.QueryGen = void 0;
4
- const util_1 = require("@polkadot/util");
5
4
  const utils_1 = require("@dedot/utils");
6
- const generator_1 = require("../generator");
7
- const utils_2 = require("./utils");
8
- class QueryGen extends generator_1.ApiGen {
5
+ const index_js_1 = require("../generator/index.js");
6
+ const utils_js_1 = require("./utils.js");
7
+ class QueryGen extends index_js_1.ApiGen {
9
8
  generate() {
10
9
  const { pallets } = this.metadata;
11
10
  this.typesGen.clearCache();
@@ -16,17 +15,17 @@ class QueryGen extends generator_1.ApiGen {
16
15
  if (!storage)
17
16
  continue;
18
17
  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`);
21
- defTypeOut += `${(0, util_1.stringLowerFirst)(pallet.name)}: {
18
+ const queryDefs = queries.map(({ name, valueType, keyType, docs }) => `${(0, utils_js_1.commentBlock)(docs)}${name}: GenericStorageQuery<(${keyType}) => ${valueType}>`);
19
+ defTypeOut += (0, utils_js_1.commentBlock)(`Pallet \`${pallet.name}\`'s storage queries`);
20
+ defTypeOut += `${(0, utils_1.stringCamelCase)(pallet.name)}: {
22
21
  ${queryDefs.join(',\n')}
23
22
 
24
- ${(0, utils_2.commentBlock)('Generic pallet storage query')}[storage: string]: GenericStorageQuery;
23
+ ${(0, utils_js_1.commentBlock)('Generic pallet storage query')}[storage: string]: GenericStorageQuery;
25
24
  },`;
26
25
  }
27
26
  const importTypes = this.typesGen.typeImports.toImports();
28
- const template = (0, utils_2.compileTemplate)('query.hbs');
29
- return (0, utils_2.beautifySourceCode)(template({ importTypes, defTypeOut }));
27
+ const template = (0, utils_js_1.compileTemplate)('query.hbs');
28
+ return (0, utils_js_1.beautifySourceCode)(template({ importTypes, defTypeOut }));
30
29
  }
31
30
  #generateEntry(entry) {
32
31
  const { name, type, docs, modifier } = entry;
@@ -2,14 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RpcGen = void 0;
4
4
  const specs_1 = require("@dedot/specs");
5
- const utils_1 = require("@dedot/utils");
6
- const generator_1 = require("../generator");
7
- const utils_2 = require("./utils");
5
+ const index_js_1 = require("../generator/index.js");
6
+ const utils_js_1 = require("./utils.js");
7
+ const known_codecs_js_1 = require("./known-codecs.js");
8
8
  const HIDDEN_RPCS = [
9
9
  // Ref: https://github.com/paritytech/polkadot-sdk/blob/43415ef58c143b985e09015cd000dbd65f6d3997/substrate/client/rpc-servers/src/lib.rs#L152C9-L158
10
10
  'rpc_methods',
11
11
  ];
12
- class RpcGen extends generator_1.ApiGen {
12
+ class RpcGen extends index_js_1.ApiGen {
13
13
  typesGen;
14
14
  rpcMethods;
15
15
  constructor(typesGen, rpcMethods) {
@@ -62,8 +62,8 @@ class RpcGen extends generator_1.ApiGen {
62
62
  });
63
63
  // TODO include & define external types
64
64
  const importTypes = this.typesGen.typeImports.toImports();
65
- const template = (0, utils_2.compileTemplate)('rpc.hbs');
66
- return (0, utils_2.beautifySourceCode)(template({ importTypes, rpcCallsOut }));
65
+ const template = (0, utils_js_1.compileTemplate)('rpc.hbs');
66
+ return (0, utils_js_1.beautifySourceCode)(template({ importTypes, rpcCallsOut }));
67
67
  }
68
68
  #generateMethodDef(spec) {
69
69
  const { name, type, module, method, docs = [], params, pubsub, deprecated } = spec;
@@ -73,7 +73,7 @@ class RpcGen extends generator_1.ApiGen {
73
73
  defaultDocs.push(`@deprecated: ${deprecated}`);
74
74
  }
75
75
  if (type === 'GenericRpcCall' && params.length === 0) {
76
- return `${(0, utils_2.commentBlock)(defaultDocs)}${method}: GenericRpcCall`;
76
+ return `${(0, utils_js_1.commentBlock)(defaultDocs)}${method}: GenericRpcCall`;
77
77
  }
78
78
  this.addTypeImport(type, false);
79
79
  params.forEach(({ type, isScale }) => {
@@ -91,10 +91,10 @@ class RpcGen extends generator_1.ApiGen {
91
91
  defaultDocs.shift();
92
92
  defaultDocs.unshift(`@pubsub: ${pubsub?.join(', ')}`);
93
93
  paramsOut.push(`callback: Callback<${typeOut}>`);
94
- return `${(0, utils_2.commentBlock)(docs, '\n', defaultDocs, paramsDoc)}${method}: GenericRpcCall<(${paramsOut.join(', ')}) => Promise<Unsub>>`;
94
+ return `${(0, utils_js_1.commentBlock)(docs, '\n', defaultDocs, paramsDoc)}${method}: GenericRpcCall<(${paramsOut.join(', ')}) => Promise<Unsub>>`;
95
95
  }
96
96
  else {
97
- return `${(0, utils_2.commentBlock)(docs, '\n', defaultDocs, paramsDoc)}${method}: GenericRpcCall<(${paramsOut.join(', ')}) => Promise<${typeOut}>>`;
97
+ return `${(0, utils_js_1.commentBlock)(docs, '\n', defaultDocs, paramsDoc)}${method}: GenericRpcCall<(${paramsOut.join(', ')}) => Promise<${typeOut}>>`;
98
98
  }
99
99
  }
100
100
  // TODO check typeIn, typeOut if param type, or rpc type isScale
@@ -104,15 +104,15 @@ class RpcGen extends generator_1.ApiGen {
104
104
  return;
105
105
  }
106
106
  type = type.trim();
107
- if ((0, utils_1.isNativeType)(type)) {
107
+ if ((0, utils_js_1.isNativeType)(type)) {
108
108
  return;
109
109
  }
110
110
  // Handle generic wrapper types
111
- const matchArray = type.match(utils_2.WRAPPER_TYPE_REGEX);
111
+ const matchArray = type.match(utils_js_1.WRAPPER_TYPE_REGEX);
112
112
  if (matchArray) {
113
113
  const [_, $1, $2] = matchArray;
114
114
  this.addTypeImport($1, toTypeIn);
115
- if ($2.match(utils_2.WRAPPER_TYPE_REGEX) || $2.match(utils_2.TUPLE_TYPE_REGEX)) {
115
+ if ($2.match(utils_js_1.WRAPPER_TYPE_REGEX) || $2.match(utils_js_1.TUPLE_TYPE_REGEX)) {
116
116
  this.addTypeImport($2, toTypeIn);
117
117
  }
118
118
  else {
@@ -121,7 +121,7 @@ class RpcGen extends generator_1.ApiGen {
121
121
  return;
122
122
  }
123
123
  // Check tuple type
124
- if (type.match(utils_2.TUPLE_TYPE_REGEX)) {
124
+ if (type.match(utils_js_1.TUPLE_TYPE_REGEX)) {
125
125
  this.addTypeImport(type.slice(1, -1).split(','), toTypeIn);
126
126
  return;
127
127
  }
@@ -131,7 +131,7 @@ class RpcGen extends generator_1.ApiGen {
131
131
  }
132
132
  try {
133
133
  const codecType = this.#getCodecType(type, toTypeIn);
134
- if ((0, utils_1.isNativeType)(codecType))
134
+ if ((0, utils_js_1.isNativeType)(codecType))
135
135
  return;
136
136
  this.typesGen.typeImports.addCodecType(codecType);
137
137
  return;
@@ -141,11 +141,11 @@ class RpcGen extends generator_1.ApiGen {
141
141
  }
142
142
  getGeneratedTypeName(type, toTypeIn = true) {
143
143
  try {
144
- const matchArray = type.match(utils_2.WRAPPER_TYPE_REGEX);
144
+ const matchArray = type.match(utils_js_1.WRAPPER_TYPE_REGEX);
145
145
  if (matchArray) {
146
146
  const [_, $1, $2] = matchArray;
147
147
  const wrapperTypeName = this.#getCodecType($1, toTypeIn);
148
- if ($2.match(utils_2.WRAPPER_TYPE_REGEX) || $2.match(utils_2.TUPLE_TYPE_REGEX)) {
148
+ if ($2.match(utils_js_1.WRAPPER_TYPE_REGEX) || $2.match(utils_js_1.TUPLE_TYPE_REGEX)) {
149
149
  return `${wrapperTypeName}<${this.getGeneratedTypeName($2, toTypeIn)}>`;
150
150
  }
151
151
  const innerTypeNames = $2
@@ -154,7 +154,7 @@ class RpcGen extends generator_1.ApiGen {
154
154
  .join(', ');
155
155
  return `${wrapperTypeName}<${innerTypeNames}>`;
156
156
  }
157
- else if (type.match(utils_2.TUPLE_TYPE_REGEX)) {
157
+ else if (type.match(utils_js_1.TUPLE_TYPE_REGEX)) {
158
158
  const innerTypeNames = type
159
159
  .slice(1, -1)
160
160
  .split(',')
@@ -168,7 +168,7 @@ class RpcGen extends generator_1.ApiGen {
168
168
  return type;
169
169
  }
170
170
  #getCodecType(type, toTypeIn = true) {
171
- const { typeIn, typeOut } = this.registry.findCodecType(type);
171
+ const { typeIn, typeOut } = (0, known_codecs_js_1.findKnownCodecType)(type);
172
172
  return toTypeIn ? typeIn : typeOut;
173
173
  }
174
174
  }
@@ -2,11 +2,10 @@
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");
8
- const util_1 = require("@polkadot/util");
9
- class RuntimeApisGen extends RpcGen_1.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
+ class RuntimeApisGen extends RpcGen_js_1.RpcGen {
10
9
  typesGen;
11
10
  runtimeApis;
12
11
  constructor(typesGen, runtimeApis) {
@@ -21,32 +20,34 @@ class RuntimeApisGen extends RpcGen_1.RpcGen {
21
20
  if (this.metadata.apis.length > 0) {
22
21
  this.metadata.apis.forEach((runtimeApi) => {
23
22
  const { name: runtimeApiName, methods } = runtimeApi;
24
- runtimeCallsOut += (0, utils_1.commentBlock)(`@runtimeapi: ${runtimeApiName} - ${(0, utils_2.calculateRuntimeApiHash)(runtimeApiName)}`);
25
- runtimeCallsOut += `${(0, util_1.stringCamelCase)(runtimeApiName)}: {
23
+ runtimeCallsOut += (0, utils_js_1.commentBlock)(`@runtimeapi: ${runtimeApiName} - ${(0, utils_1.calcRuntimeApiHash)(runtimeApiName)}`);
24
+ runtimeCallsOut += `${(0, utils_1.stringCamelCase)(runtimeApiName)}: {
26
25
  ${methods.map((method) => this.#generateMethodDef(runtimeApiName, method)).join('\n')}
27
26
 
28
- ${(0, utils_1.commentBlock)('Generic runtime api call')}[method: string]: GenericRuntimeApiMethod
27
+ ${(0, utils_js_1.commentBlock)('Generic runtime api call')}[method: string]: GenericRuntimeApiMethod
29
28
  }`;
30
29
  });
31
30
  }
32
31
  else {
33
- const specsByModule = this.#runtimeApisSpecsByModule();
34
- Object.values(specsByModule).forEach((specs) => {
35
- specs.forEach(({ methods, runtimeApiName, runtimeApiHash, version }) => {
36
- runtimeCallsOut += (0, utils_1.commentBlock)(`@runtimeapi: ${runtimeApiName} - ${runtimeApiHash}`, `@version: ${version}`);
37
- runtimeCallsOut += `${(0, util_1.stringCamelCase)(runtimeApiName)}: {
32
+ const specs = this.#targetRuntimeApiSpecs();
33
+ specs.forEach(({ methods, runtimeApiName, runtimeApiHash, version }) => {
34
+ runtimeCallsOut += (0, utils_js_1.commentBlock)(`@runtimeapi: ${runtimeApiName} - ${runtimeApiHash}`, `@version: ${version}`);
35
+ runtimeCallsOut += `${(0, utils_1.stringCamelCase)(runtimeApiName)}: {
38
36
  ${Object.keys(methods)
39
- .map((methodName) => this.#generateMethodDefFromSpec({ ...methods[methodName], runtimeApiName, methodName }))
40
- .join('\n')}
37
+ .map((methodName) => this.#generateMethodDefFromSpec({
38
+ ...methods[methodName],
39
+ runtimeApiName,
40
+ methodName,
41
+ }))
42
+ .join('\n')}
41
43
 
42
- ${(0, utils_1.commentBlock)('Generic runtime api call')}[method: string]: GenericRuntimeApiMethod
44
+ ${(0, utils_js_1.commentBlock)('Generic runtime api call')}[method: string]: GenericRuntimeApiMethod
43
45
  }`;
44
- });
45
46
  });
46
47
  }
47
48
  const importTypes = this.typesGen.typeImports.toImports();
48
- const template = (0, utils_1.compileTemplate)('runtime.hbs');
49
- return (0, utils_1.beautifySourceCode)(template({ importTypes, runtimeCallsOut }));
49
+ const template = (0, utils_js_1.compileTemplate)('runtime.hbs');
50
+ return (0, utils_js_1.beautifySourceCode)(template({ importTypes, runtimeCallsOut }));
50
51
  }
51
52
  #isOptionalType(type) {
52
53
  return type.startsWith('Option<') || type.endsWith('| undefined');
@@ -56,7 +57,7 @@ class RuntimeApisGen extends RpcGen_1.RpcGen {
56
57
  }
57
58
  #generateMethodDefFromSpec(spec) {
58
59
  const { docs = [], params, type, runtimeApiName, methodName } = spec;
59
- const callName = `${runtimeApiName}_${(0, utils_2.stringSnakeCase)(methodName)}`;
60
+ const callName = `${runtimeApiName}_${(0, utils_1.stringSnakeCase)(methodName)}`;
60
61
  const defaultDocs = [`@callname: ${callName}`];
61
62
  this.addTypeImport(type, false);
62
63
  params.forEach(({ type }) => this.addTypeImport(type));
@@ -66,14 +67,14 @@ class RuntimeApisGen extends RpcGen_1.RpcGen {
66
67
  plainType: this.getGeneratedTypeName(param.type),
67
68
  }));
68
69
  const paramsOut = typedParams
69
- .map(({ name, isOptional, plainType }) => `${(0, util_1.stringCamelCase)(name)}${isOptional ? '?' : ''}: ${plainType}`)
70
+ .map(({ name, isOptional, plainType }) => `${(0, utils_1.stringCamelCase)(name)}${isOptional ? '?' : ''}: ${plainType}`)
70
71
  .join(', ');
71
72
  const typeOut = this.getGeneratedTypeName(type, false);
72
- return `${(0, utils_1.commentBlock)(docs, '\n', defaultDocs, typedParams.map(({ plainType, name }) => `@param {${plainType}} ${name}`))}${methodName}: GenericRuntimeApiMethod<(${paramsOut}) => Promise<${typeOut}>>`;
73
+ return `${(0, utils_js_1.commentBlock)(docs, '\n', defaultDocs, typedParams.map(({ plainType, name }) => `@param {${plainType}} ${name}`))}${methodName}: GenericRuntimeApiMethod<(${paramsOut}) => Promise<${typeOut}>>`;
73
74
  }
74
75
  #generateMethodDef(runtimeApiName, methodDef) {
75
76
  const { name: methodName, inputs, output, docs } = methodDef;
76
- const callName = `${runtimeApiName}_${(0, utils_2.stringSnakeCase)(methodName)}`;
77
+ const callName = `${runtimeApiName}_${(0, utils_1.stringSnakeCase)(methodName)}`;
77
78
  const defaultDocs = [`@callname: ${callName}`];
78
79
  const typeOut = this.typesGen.generateType(output, 1, true);
79
80
  this.addTypeImport(typeOut, false);
@@ -88,13 +89,13 @@ class RuntimeApisGen extends RpcGen_1.RpcGen {
88
89
  }));
89
90
  this.addTypeImport(typedInputs.map((t) => t.type));
90
91
  const paramsOut = typedInputs
91
- .map(({ name, type, isOptional }) => `${(0, util_1.stringCamelCase)(name)}${isOptional ? '?' : ''}: ${type}`)
92
+ .map(({ name, type, isOptional }) => `${(0, utils_1.stringCamelCase)(name)}${isOptional ? '?' : ''}: ${type}`)
92
93
  .join(', ');
93
- return `${(0, utils_1.commentBlock)(docs, '\n', defaultDocs, typedInputs.map(({ type, name }) => `@param {${type}} ${name}`))}${(0, util_1.stringCamelCase)(methodName)}: GenericRuntimeApiMethod<(${paramsOut}) => Promise<${typeOut}>>`;
94
+ return `${(0, utils_js_1.commentBlock)(docs, '\n', defaultDocs, typedInputs.map(({ type, name }) => `@param {${type}} ${name}`))}${(0, utils_1.stringCamelCase)(methodName)}: GenericRuntimeApiMethod<(${paramsOut}) => Promise<${typeOut}>>`;
94
95
  }
95
- #runtimeApisSpecsByModule() {
96
+ #targetRuntimeApiSpecs() {
96
97
  const specs = this.runtimeApis.map(([runtimeApiHash, version]) => {
97
- const runtimeApiSpec = (0, specs_1.findRuntimeApiSpec)(runtimeApiHash, version);
98
+ const runtimeApiSpec = this.#findRuntimeApiSpec(runtimeApiHash, version);
98
99
  if (!runtimeApiSpec)
99
100
  return;
100
101
  return {
@@ -106,15 +107,12 @@ class RuntimeApisGen extends RpcGen_1.RpcGen {
106
107
  if (!spec) {
107
108
  return o;
108
109
  }
109
- const { moduleName } = spec;
110
- if (!moduleName) {
111
- return o;
112
- }
113
- return {
114
- ...o,
115
- [moduleName]: o[moduleName] ? [...o[moduleName], spec] : [spec],
116
- };
117
- }, {});
110
+ return [...o, spec];
111
+ }, []);
118
112
  }
113
+ #findRuntimeApiSpec = (runtimeApiHash, version) => {
114
+ const runtimeApiName = (0, specs_1.getRuntimeApiNames)().find((one) => (0, utils_1.calcRuntimeApiHash)(one) === runtimeApiHash);
115
+ return (0, specs_1.getRuntimeApiSpecs)().find((one) => one.runtimeApiName === runtimeApiName && one.version === version);
116
+ };
119
117
  }
120
118
  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");
5
- const util_1 = require("@polkadot/util");
6
- const utils_1 = require("./utils");
7
- class TxGen extends generator_1.ApiGen {
4
+ const index_js_1 = require("../generator/index.js");
5
+ const utils_1 = require("@dedot/utils");
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();
@@ -26,9 +26,9 @@ class TxGen extends generator_1.ApiGen {
26
26
  const isFlatEnum = type.value.members.every((m) => m.fields.length === 0);
27
27
  const typedTxs = type.value.members
28
28
  .map((one) => ({
29
- functionName: (0, util_1.stringCamelCase)(one.name),
29
+ functionName: (0, utils_1.stringCamelCase)(one.name),
30
30
  params: one.fields.map((f) => ({
31
- name: (0, util_1.stringCamelCase)(f.name),
31
+ name: (0, utils_1.stringCamelCase)(f.name),
32
32
  normalizedName: this.#normalizeParamName(f.name),
33
33
  type: this.typesGen.generateType(f.typeId, 1),
34
34
  docs: f.docs,
@@ -38,16 +38,16 @@ class TxGen extends generator_1.ApiGen {
38
38
  .map((f) => {
39
39
  return {
40
40
  ...f,
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),
41
+ callInput: this.#generateCallInput((0, utils_1.stringPascalCase)(pallet.name), (0, utils_1.stringPascalCase)(f.functionName), !isFlatEnum ? f.params.map((p) => `${p.name}: ${p.type}`) : undefined),
42
42
  };
43
43
  });
44
- txDefsOut += (0, utils_1.commentBlock)(`Pallet \`${pallet.name}\`'s transaction calls`);
45
- txDefsOut += `${(0, util_1.stringCamelCase)(pallet.name)}: {
44
+ txDefsOut += (0, utils_js_1.commentBlock)(`Pallet \`${pallet.name}\`'s transaction calls`);
45
+ txDefsOut += `${(0, utils_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
- name = (0, util_1.stringCamelCase)(name);
67
- return (0, utils_1.isReservedWord)(name) ? `${name}_` : name;
66
+ name = (0, utils_1.stringCamelCase)(name);
67
+ return (0, utils_js_1.isReservedWord)(name) ? `${name}_` : name;
68
68
  }
69
69
  #generateCallInput(palletName, callName, params) {
70
70
  if (!params) {