@dedot/codegen 0.0.1-next.0a597de3.0 → 0.0.1-next.16e37feb.8

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.
@@ -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");
@@ -61,13 +61,13 @@ async function run() {
61
61
  const { chain, endpoint, metadataHex, rpcMethods } = network;
62
62
  if (endpoint) {
63
63
  console.log(`Generate types for ${chain} via endpoint ${endpoint}`);
64
- await (0, index_1.generateTypesFromChain)(network, endpoint, OUT_DIR);
64
+ await (0, index_js_1.generateTypesFromChain)(network, endpoint, OUT_DIR);
65
65
  }
66
66
  else if (metadataHex && rpcMethods) {
67
67
  console.log(`Generate types for ${chain} via raw data`);
68
68
  const metadata = codecs_1.$Metadata.tryDecode(metadataHex);
69
69
  const runtimeVersion = getRuntimeVersion(metadata);
70
- await (0, 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);
71
71
  }
72
72
  }
73
73
  console.log('DONE!');
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConstsGen = void 0;
4
4
  const util_1 = require("@polkadot/util");
5
5
  const utils_1 = require("@dedot/utils");
6
- const 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,14 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RpcGen = void 0;
4
4
  const specs_1 = require("@dedot/specs");
5
5
  const utils_1 = require("@dedot/utils");
6
- const generator_1 = require("../generator");
7
- const utils_2 = require("./utils");
8
- const known_codecs_1 = require("./known-codecs");
6
+ const index_js_1 = require("../generator/index.js");
7
+ const utils_js_1 = require("./utils.js");
8
+ const known_codecs_js_1 = require("./known-codecs.js");
9
9
  const HIDDEN_RPCS = [
10
10
  // Ref: https://github.com/paritytech/polkadot-sdk/blob/43415ef58c143b985e09015cd000dbd65f6d3997/substrate/client/rpc-servers/src/lib.rs#L152C9-L158
11
11
  'rpc_methods',
12
12
  ];
13
- class RpcGen extends generator_1.ApiGen {
13
+ class RpcGen extends index_js_1.ApiGen {
14
14
  typesGen;
15
15
  rpcMethods;
16
16
  constructor(typesGen, rpcMethods) {
@@ -63,8 +63,8 @@ class RpcGen extends generator_1.ApiGen {
63
63
  });
64
64
  // TODO include & define external types
65
65
  const importTypes = this.typesGen.typeImports.toImports();
66
- const template = (0, utils_2.compileTemplate)('rpc.hbs');
67
- 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 }));
68
68
  }
69
69
  #generateMethodDef(spec) {
70
70
  const { name, type, module, method, docs = [], params, pubsub, deprecated } = spec;
@@ -74,7 +74,7 @@ class RpcGen extends generator_1.ApiGen {
74
74
  defaultDocs.push(`@deprecated: ${deprecated}`);
75
75
  }
76
76
  if (type === 'GenericRpcCall' && params.length === 0) {
77
- return `${(0, utils_2.commentBlock)(defaultDocs)}${method}: GenericRpcCall`;
77
+ return `${(0, utils_js_1.commentBlock)(defaultDocs)}${method}: GenericRpcCall`;
78
78
  }
79
79
  this.addTypeImport(type, false);
80
80
  params.forEach(({ type, isScale }) => {
@@ -92,10 +92,10 @@ class RpcGen extends generator_1.ApiGen {
92
92
  defaultDocs.shift();
93
93
  defaultDocs.unshift(`@pubsub: ${pubsub?.join(', ')}`);
94
94
  paramsOut.push(`callback: Callback<${typeOut}>`);
95
- return `${(0, 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>>`;
96
96
  }
97
97
  else {
98
- 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}>>`;
99
99
  }
100
100
  }
101
101
  // TODO check typeIn, typeOut if param type, or rpc type isScale
@@ -109,11 +109,11 @@ class RpcGen extends generator_1.ApiGen {
109
109
  return;
110
110
  }
111
111
  // Handle generic wrapper types
112
- const matchArray = type.match(utils_2.WRAPPER_TYPE_REGEX);
112
+ const matchArray = type.match(utils_js_1.WRAPPER_TYPE_REGEX);
113
113
  if (matchArray) {
114
114
  const [_, $1, $2] = matchArray;
115
115
  this.addTypeImport($1, toTypeIn);
116
- if ($2.match(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)) {
117
117
  this.addTypeImport($2, toTypeIn);
118
118
  }
119
119
  else {
@@ -122,7 +122,7 @@ class RpcGen extends generator_1.ApiGen {
122
122
  return;
123
123
  }
124
124
  // Check tuple type
125
- if (type.match(utils_2.TUPLE_TYPE_REGEX)) {
125
+ if (type.match(utils_js_1.TUPLE_TYPE_REGEX)) {
126
126
  this.addTypeImport(type.slice(1, -1).split(','), toTypeIn);
127
127
  return;
128
128
  }
@@ -142,11 +142,11 @@ class RpcGen extends generator_1.ApiGen {
142
142
  }
143
143
  getGeneratedTypeName(type, toTypeIn = true) {
144
144
  try {
145
- const matchArray = type.match(utils_2.WRAPPER_TYPE_REGEX);
145
+ const matchArray = type.match(utils_js_1.WRAPPER_TYPE_REGEX);
146
146
  if (matchArray) {
147
147
  const [_, $1, $2] = matchArray;
148
148
  const wrapperTypeName = this.#getCodecType($1, toTypeIn);
149
- if ($2.match(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)) {
150
150
  return `${wrapperTypeName}<${this.getGeneratedTypeName($2, toTypeIn)}>`;
151
151
  }
152
152
  const innerTypeNames = $2
@@ -155,7 +155,7 @@ class RpcGen extends generator_1.ApiGen {
155
155
  .join(', ');
156
156
  return `${wrapperTypeName}<${innerTypeNames}>`;
157
157
  }
158
- else if (type.match(utils_2.TUPLE_TYPE_REGEX)) {
158
+ else if (type.match(utils_js_1.TUPLE_TYPE_REGEX)) {
159
159
  const innerTypeNames = type
160
160
  .slice(1, -1)
161
161
  .split(',')
@@ -169,7 +169,7 @@ class RpcGen extends generator_1.ApiGen {
169
169
  return type;
170
170
  }
171
171
  #getCodecType(type, toTypeIn = true) {
172
- const { typeIn, typeOut } = (0, known_codecs_1.findKnownCodecType)(type);
172
+ const { typeIn, typeOut } = (0, known_codecs_js_1.findKnownCodecType)(type);
173
173
  return toTypeIn ? typeIn : typeOut;
174
174
  }
175
175
  }
@@ -2,11 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RuntimeApisGen = void 0;
4
4
  const specs_1 = require("@dedot/specs");
5
- const 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,7 +92,7 @@ class RuntimeApisGen extends RpcGen_1.RpcGen {
92
92
  const paramsOut = typedInputs
93
93
  .map(({ name, type, isOptional }) => `${(0, util_1.stringCamelCase)(name)}${isOptional ? '?' : ''}: ${type}`)
94
94
  .join(', ');
95
- return `${(0, 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]) => {
@@ -112,7 +112,7 @@ class RuntimeApisGen extends RpcGen_1.RpcGen {
112
112
  }, []);
113
113
  }
114
114
  #findRuntimeApiSpec = (runtimeApiHash, version) => {
115
- const runtimeApiName = (0, specs_1.getRuntimeApiNames)().find((one) => (0, utils_2.calculateRuntimeApiHash)(one) === runtimeApiHash);
115
+ const runtimeApiName = (0, specs_1.getRuntimeApiNames)().find((one) => (0, utils_1.calculateRuntimeApiHash)(one) === runtimeApiHash);
116
116
  return (0, specs_1.getRuntimeApiSpecs)().find((one) => one.runtimeApiName === runtimeApiName && one.version === version);
117
117
  };
118
118
  }
@@ -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,10 +4,10 @@ exports.TypesGen = exports.BASIC_KNOWN_TYPES = void 0;
4
4
  const util_1 = require("@polkadot/util");
5
5
  const codecs_1 = require("@dedot/codecs");
6
6
  const utils_1 = require("@dedot/utils");
7
- const utils_2 = require("./utils");
8
- const known_types_1 = require("./known-types");
9
- const TypeImports_1 = require("./TypeImports");
10
- const known_codecs_1 = require("./known-codecs");
7
+ const utils_js_1 = require("./utils.js");
8
+ const known_types_js_1 = require("./known-types.js");
9
+ const TypeImports_js_1 = require("./TypeImports.js");
10
+ const known_codecs_js_1 = require("./known-codecs.js");
11
11
  // Skip generate types for these
12
12
  // as we do have native types for them
13
13
  const SKIP_TYPES = [
@@ -43,7 +43,7 @@ class TypesGen {
43
43
  this.metadata = metadata;
44
44
  this.registry = new codecs_1.PortableRegistry(this.metadata);
45
45
  this.includedTypes = this.#includedTypes();
46
- this.typeImports = new TypeImports_1.TypeImports();
46
+ this.typeImports = new TypeImports_js_1.TypeImports();
47
47
  }
48
48
  generate() {
49
49
  this.clearCache();
@@ -51,14 +51,14 @@ class TypesGen {
51
51
  Object.values(this.includedTypes)
52
52
  .filter(({ skip, knownType }) => !(skip || knownType))
53
53
  .forEach(({ name, nameOut, id, docs }) => {
54
- defTypeOut += `${(0, 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`;
55
55
  if (this.#shouldGenerateTypeIn(id)) {
56
56
  defTypeOut += `export type ${name} = ${this.generateType(id)};\n\n`;
57
57
  }
58
58
  });
59
59
  const importTypes = this.typeImports.toImports('./types');
60
- const template = (0, utils_2.compileTemplate)('types.hbs');
61
- 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 }));
62
62
  }
63
63
  typeCache = {};
64
64
  clearCache() {
@@ -103,7 +103,7 @@ class TypesGen {
103
103
  const { tag, value } = type;
104
104
  switch (tag) {
105
105
  case 'Primitive':
106
- const $codec = (0, known_codecs_1.findKnownCodec)(value.kind);
106
+ const $codec = (0, known_codecs_js_1.findKnownCodec)(value.kind);
107
107
  if ($codec.nativeType) {
108
108
  return $codec.nativeType;
109
109
  }
@@ -151,7 +151,7 @@ class TypesGen {
151
151
  return 'null';
152
152
  }
153
153
  else if (members.every((x) => x.fields.length === 0)) {
154
- return members.map(({ name, docs }) => `${(0, 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(' | ');
155
155
  }
156
156
  else {
157
157
  const membersType = [];
@@ -164,7 +164,7 @@ class TypesGen {
164
164
  const valueType = fields.length === 1
165
165
  ? this.generateType(fields[0].typeId, nestedLevel + 1, typeOut)
166
166
  : `[${fields
167
- .map(({ typeId, docs }) => `${(0, 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)}`)
168
168
  .join(', ')}]`;
169
169
  membersType.push([keyName, valueType, docs]);
170
170
  }
@@ -179,7 +179,7 @@ class TypesGen {
179
179
  value: valueType ? `, ${valueKey}${this.#isOptionalType(valueType) ? '?' : ''}: ${valueType} ` : '',
180
180
  docs,
181
181
  }))
182
- .map(({ tag, value, docs }) => `${(0, utils_2.commentBlock)(docs)}{ ${tag}${value} }`)
182
+ .map(({ tag, value, docs }) => `${(0, utils_js_1.commentBlock)(docs)}{ ${tag}${value} }`)
183
183
  .join(' | ');
184
184
  }
185
185
  }
@@ -226,7 +226,7 @@ class TypesGen {
226
226
  };
227
227
  });
228
228
  return `{${props
229
- .map(({ name, type, optional, docs }) => `${(0, utils_2.commentBlock)(docs)}${name}${optional ? '?' : ''}: ${type}`)
229
+ .map(({ name, type, optional, docs }) => `${(0, utils_js_1.commentBlock)(docs)}${name}${optional ? '?' : ''}: ${type}`)
230
230
  .join(',\n')}}`;
231
231
  }
232
232
  #isOptionalType(type) {
@@ -267,8 +267,8 @@ class TypesGen {
267
267
  const suffix = typeSuffixes.get(id) || '';
268
268
  let knownType = false;
269
269
  let name, nameOut;
270
- if ((0, known_codecs_1.isKnownCodecType)(joinedPath)) {
271
- const codecType = (0, known_codecs_1.findKnownCodecType)(path.at(-1));
270
+ if ((0, known_codecs_js_1.isKnownCodecType)(joinedPath)) {
271
+ const codecType = (0, known_codecs_js_1.findKnownCodecType)(path.at(-1));
272
272
  name = codecType.typeIn;
273
273
  nameOut = codecType.typeOut;
274
274
  knownType = true;
@@ -426,7 +426,7 @@ class TypesGen {
426
426
  this.typeImports.addCodecType(typeName);
427
427
  return;
428
428
  }
429
- if (known_types_1.knownTypes.includes(typeName)) {
429
+ if (known_types_js_1.knownTypes.includes(typeName)) {
430
430
  this.typeImports.addKnownType(typeName);
431
431
  }
432
432
  else {
@@ -14,13 +14,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./TypesGen"), exports);
18
- __exportStar(require("./ApiGen"), exports);
19
- __exportStar(require("./ConstsGen"), exports);
20
- __exportStar(require("./QueryGen"), exports);
21
- __exportStar(require("./RpcGen"), exports);
22
- __exportStar(require("./IndexGen"), exports);
23
- __exportStar(require("./ErrorsGen"), exports);
24
- __exportStar(require("./EventsGen"), exports);
25
- __exportStar(require("./TxGen"), exports);
26
- __exportStar(require("./RuntimeApisGen"), exports);
17
+ __exportStar(require("./TypesGen.js"), exports);
18
+ __exportStar(require("./ApiGen.js"), exports);
19
+ __exportStar(require("./ConstsGen.js"), exports);
20
+ __exportStar(require("./QueryGen.js"), exports);
21
+ __exportStar(require("./RpcGen.js"), exports);
22
+ __exportStar(require("./IndexGen.js"), exports);
23
+ __exportStar(require("./ErrorsGen.js"), exports);
24
+ __exportStar(require("./EventsGen.js"), exports);
25
+ __exportStar(require("./TxGen.js"), exports);
26
+ __exportStar(require("./RuntimeApisGen.js"), exports);
package/cjs/index.js CHANGED
@@ -27,7 +27,7 @@ exports.generateTypes = exports.generateTypesFromChain = void 0;
27
27
  const dedot_1 = require("dedot");
28
28
  const fs = __importStar(require("fs"));
29
29
  const path = __importStar(require("path"));
30
- const generator_1 = require("./generator");
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 generator_1.TypesGen(metadata);
58
- const constsGen = new generator_1.ConstsGen(typesGen);
59
- const queryGen = new generator_1.QueryGen(typesGen);
60
- const rpcGen = new generator_1.RpcGen(typesGen, rpcMethods);
61
- const indexGen = new generator_1.IndexGen(network);
62
- const errorsGen = new generator_1.ErrorsGen(typesGen);
63
- const eventsGen = new generator_1.EventsGen(typesGen);
64
- const runtimeApisGen = new generator_1.RuntimeApisGen(typesGen, runtimeApis);
65
- const txGen = new generator_1.TxGen(typesGen);
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());
@@ -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.27' };
5
+ exports.packageInfo = { name: '@dedot/codegen', version: '0.0.1-alpha.28' };
@@ -1,4 +1,4 @@
1
- import { generateTypes, generateTypesFromChain } from './index';
1
+ import { generateTypes, generateTypesFromChain } from './index.js';
2
2
  import { rpc } from '@polkadot/types-support/metadata/static-substrate';
3
3
  import staticSubstrate from '@polkadot/types-support/metadata/v15/substrate-hex';
4
4
  import { $Metadata, PortableRegistry } from '@dedot/codecs';
@@ -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);
@@ -1,4 +1,4 @@
1
- import { ApiGen } from '../generator';
1
+ import { ApiGen } from '../generator/index.js';
2
2
  export declare class ConstsGen extends ApiGen {
3
3
  generate(): Promise<string>;
4
4
  }
@@ -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;
@@ -1,4 +1,4 @@
1
- import { ApiGen } from './ApiGen';
1
+ import { ApiGen } from './ApiGen.js';
2
2
  export declare class ErrorsGen extends ApiGen {
3
3
  #private;
4
4
  generate(): Promise<string>;
@@ -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 {
@@ -1,4 +1,4 @@
1
- import { ApiGen } from './ApiGen';
1
+ import { ApiGen } from './ApiGen.js';
2
2
  export declare class EventsGen extends ApiGen {
3
3
  #private;
4
4
  generate(): Promise<string>;
@@ -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 {
@@ -1,4 +1,4 @@
1
- import { NetworkInfo } from '../types';
1
+ import { NetworkInfo } from '../types.js';
2
2
  export declare class IndexGen {
3
3
  readonly networkInfo: NetworkInfo;
4
4
  constructor(networkInfo: NetworkInfo);
@@ -1,4 +1,4 @@
1
- import { beautifySourceCode, compileTemplate } from './utils';
1
+ import { beautifySourceCode, compileTemplate } from './utils.js';
2
2
  import { stringPascalCase } from '@polkadot/util';
3
3
  export class IndexGen {
4
4
  networkInfo;
@@ -1,4 +1,4 @@
1
- import { ApiGen } from '../generator';
1
+ import { ApiGen } from '../generator/index.js';
2
2
  export declare class QueryGen extends ApiGen {
3
3
  #private;
4
4
  generate(): Promise<string>;
@@ -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;
@@ -1,4 +1,4 @@
1
- import { ApiGen, TypesGen } from '../generator';
1
+ import { ApiGen, TypesGen } from '../generator/index.js';
2
2
  export declare class RpcGen extends ApiGen {
3
3
  #private;
4
4
  readonly typesGen: TypesGen;
@@ -1,8 +1,8 @@
1
1
  import { findAliasRpcSpec, findRpcSpec, isUnsubscribeMethod } from '@dedot/specs';
2
2
  import { isNativeType } from '@dedot/utils';
3
- import { ApiGen } from '../generator';
4
- import { beautifySourceCode, commentBlock, compileTemplate, TUPLE_TYPE_REGEX, WRAPPER_TYPE_REGEX } from './utils';
5
- import { findKnownCodecType } from './known-codecs';
3
+ import { ApiGen } from '../generator/index.js';
4
+ import { beautifySourceCode, commentBlock, compileTemplate, TUPLE_TYPE_REGEX, WRAPPER_TYPE_REGEX } from './utils.js';
5
+ import { findKnownCodecType } from './known-codecs.js';
6
6
  const HIDDEN_RPCS = [
7
7
  // Ref: https://github.com/paritytech/polkadot-sdk/blob/43415ef58c143b985e09015cd000dbd65f6d3997/substrate/client/rpc-servers/src/lib.rs#L152C9-L158
8
8
  'rpc_methods',
@@ -1,5 +1,5 @@
1
- import { TypesGen } from './TypesGen';
2
- import { RpcGen } from './RpcGen';
1
+ import { TypesGen } from './TypesGen.js';
2
+ import { RpcGen } from './RpcGen.js';
3
3
  export declare class RuntimeApisGen extends RpcGen {
4
4
  #private;
5
5
  readonly typesGen: TypesGen;
@@ -1,7 +1,7 @@
1
1
  import { getRuntimeApiNames, getRuntimeApiSpecs } from '@dedot/specs';
2
- import { beautifySourceCode, commentBlock, compileTemplate } from './utils';
2
+ import { beautifySourceCode, commentBlock, compileTemplate } from './utils.js';
3
3
  import { calculateRuntimeApiHash, stringSnakeCase } from '@dedot/utils';
4
- import { RpcGen } from './RpcGen';
4
+ import { RpcGen } from './RpcGen.js';
5
5
  import { stringCamelCase } from '@polkadot/util';
6
6
  export class RuntimeApisGen extends RpcGen {
7
7
  typesGen;
@@ -1,4 +1,4 @@
1
- import { ApiGen } from '../generator';
1
+ import { ApiGen } from '../generator/index.js';
2
2
  export declare class TxGen extends ApiGen {
3
3
  #private;
4
4
  generate(): Promise<string>;
@@ -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;
@@ -1,5 +1,5 @@
1
1
  import { PortableRegistry, Field, MetadataLatest, PortableType, TypeId } from '@dedot/codecs';
2
- import { TypeImports } from './TypeImports';
2
+ import { TypeImports } from './TypeImports.js';
3
3
  interface NamedType extends PortableType {
4
4
  name: string;
5
5
  nameOut: string;
@@ -1,10 +1,10 @@
1
1
  import { stringPascalCase } from '@polkadot/util';
2
2
  import { PortableRegistry } from '@dedot/codecs';
3
3
  import { isNativeType, normalizeName } from '@dedot/utils';
4
- import { beautifySourceCode, commentBlock, compileTemplate } from './utils';
5
- import { knownTypes } from './known-types';
6
- import { TypeImports } from './TypeImports';
7
- import { findKnownCodec, findKnownCodecType, isKnownCodecType } from './known-codecs';
4
+ import { beautifySourceCode, commentBlock, compileTemplate } from './utils.js';
5
+ import { knownTypes } from './known-types.js';
6
+ import { TypeImports } from './TypeImports.js';
7
+ import { findKnownCodec, findKnownCodecType, isKnownCodecType } from './known-codecs.js';
8
8
  // Skip generate types for these
9
9
  // as we do have native types for them
10
10
  const SKIP_TYPES = [
@@ -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';
@@ -1,10 +1,10 @@
1
- export * from './TypesGen';
2
- export * from './ApiGen';
3
- export * from './ConstsGen';
4
- export * from './QueryGen';
5
- export * from './RpcGen';
6
- export * from './IndexGen';
7
- export * from './ErrorsGen';
8
- export * from './EventsGen';
9
- export * from './TxGen';
10
- export * from './RuntimeApisGen';
1
+ export * from './TypesGen.js';
2
+ export * from './ApiGen.js';
3
+ export * from './ConstsGen.js';
4
+ export * from './QueryGen.js';
5
+ export * from './RpcGen.js';
6
+ export * from './IndexGen.js';
7
+ export * from './ErrorsGen.js';
8
+ export * from './EventsGen.js';
9
+ export * from './TxGen.js';
10
+ export * from './RuntimeApisGen.js';
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { MetadataLatest } from '@dedot/codecs';
2
- import { NetworkInfo } from './types';
2
+ import { NetworkInfo } from './types.js';
3
3
  export declare function generateTypesFromChain(network: NetworkInfo, endpoint: string, outDir: string): Promise<void>;
4
4
  export declare function generateTypes(network: NetworkInfo, metadata: MetadataLatest, rpcMethods: string[], runtimeApis: any[], outDir?: string): Promise<void>;
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Dedot } from 'dedot';
2
2
  import * as fs from 'fs';
3
3
  import * as path from 'path';
4
- import { ConstsGen, ErrorsGen, EventsGen, IndexGen, QueryGen, RpcGen, RuntimeApisGen, TxGen, TypesGen, } from './generator';
4
+ import { ConstsGen, ErrorsGen, EventsGen, IndexGen, QueryGen, RpcGen, RuntimeApisGen, TxGen, TypesGen, } from './generator/index.js';
5
5
  import { stringCamelCase } from '@polkadot/util';
6
6
  export async function generateTypesFromChain(network, endpoint, outDir) {
7
7
  const api = await Dedot.create(endpoint);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dedot/codegen",
3
- "version": "0.0.1-next.0a597de3.0+0a597de",
3
+ "version": "0.0.1-next.16e37feb.8+16e37fe",
4
4
  "description": "Generate types",
5
5
  "author": "Thang X. Vu <thang@coongcrafts.io>",
6
6
  "homepage": "https://github.com/dedotdev/dedot/tree/main/packages/codegen",
@@ -18,12 +18,12 @@
18
18
  "copy": "cp -R ./src/templates ./dist && cp -R ./src/templates ./dist/cjs"
19
19
  },
20
20
  "dependencies": {
21
- "@dedot/codecs": "0.0.1-next.0a597de3.0+0a597de",
22
- "@dedot/shape": "0.0.1-next.0a597de3.0+0a597de",
23
- "@dedot/specs": "0.0.1-next.0a597de3.0+0a597de",
24
- "@dedot/utils": "0.0.1-next.0a597de3.0+0a597de",
21
+ "@dedot/codecs": "0.0.1-next.16e37feb.8+16e37fe",
22
+ "@dedot/shape": "0.0.1-next.16e37feb.8+16e37fe",
23
+ "@dedot/specs": "0.0.1-next.16e37feb.8+16e37fe",
24
+ "@dedot/utils": "0.0.1-next.16e37feb.8+16e37fe",
25
25
  "@polkadot/util": "^12.6.2",
26
- "dedot": "0.0.1-next.0a597de3.0+0a597de",
26
+ "dedot": "0.0.1-next.16e37feb.8+16e37fe",
27
27
  "handlebars": "^4.7.8",
28
28
  "prettier": "^3.0.3"
29
29
  },
@@ -32,7 +32,7 @@
32
32
  "directory": "dist"
33
33
  },
34
34
  "license": "Apache-2.0",
35
- "gitHead": "0a597de3c59c70bf39a56e1569e76b61dce9af8f",
35
+ "gitHead": "16e37feb35200c80b3ffcba5791154050da36443",
36
36
  "module": "./index.js",
37
37
  "types": "./index.d.ts",
38
38
  "exports": {
package/packageInfo.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // THIS FILE IS AUTO-GENERATED, DO NOT EDIT!
2
- export const packageInfo = { name: '@dedot/codegen', version: '0.0.1-alpha.27' };
2
+ export const packageInfo = { name: '@dedot/codegen', version: '0.0.1-alpha.28' };