@dedot/codegen 0.15.3-next.65898ecf.10 → 0.16.0

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.
@@ -12,7 +12,7 @@ export class IndexGen {
12
12
  const interfaceName = this.interfaceName;
13
13
  // Clear cache and setup type imports
14
14
  this.typesGen.clearCache();
15
- this.typesGen.typeImports.addKnownType('GenericSubstrateApi', 'GenericChainTypes', 'RpcLegacy', 'RpcV2', 'RpcVersion');
15
+ this.typesGen.typeImports.addKnownType('GenericSubstrateApi', 'GenericChainKnownTypes', 'RpcLegacy', 'RpcV2', 'RpcVersion');
16
16
  // Extract type IDs from metadata.extrinsic
17
17
  const { callTypeId, addressTypeId, signatureTypeId, signedExtensions } = this.typesGen.metadata.extrinsic;
18
18
  // Generate proper TypeScript types using typeOut format (0, true)
@@ -12,7 +12,7 @@ import { ChainTx } from './tx.js';
12
12
 
13
13
  export * from './types.js';
14
14
 
15
- interface ChainTypes extends GenericChainTypes {
15
+ interface ChainKnownTypes extends GenericChainKnownTypes {
16
16
  Address: {{{addressType}}};
17
17
  Signature: {{{signatureType}}};
18
18
  RuntimeCall: {{{runtimeCallType}}};
@@ -29,7 +29,7 @@ export interface Versioned{{{interfaceName}}}<Rv extends RpcVersion> extends Gen
29
29
  view: ChainViewFunctions<Rv>;
30
30
  tx: ChainTx<Rv>;
31
31
 
32
- types: ChainTypes;
32
+ types: ChainKnownTypes;
33
33
  }
34
34
 
35
35
  {{interfaceDocs}}export interface {{{interfaceName}}} {
@@ -15,7 +15,7 @@ class IndexGen {
15
15
  const interfaceName = this.interfaceName;
16
16
  // Clear cache and setup type imports
17
17
  this.typesGen.clearCache();
18
- this.typesGen.typeImports.addKnownType('GenericSubstrateApi', 'GenericChainTypes', 'RpcLegacy', 'RpcV2', 'RpcVersion');
18
+ this.typesGen.typeImports.addKnownType('GenericSubstrateApi', 'GenericChainKnownTypes', 'RpcLegacy', 'RpcV2', 'RpcVersion');
19
19
  // Extract type IDs from metadata.extrinsic
20
20
  const { callTypeId, addressTypeId, signatureTypeId, signedExtensions } = this.typesGen.metadata.extrinsic;
21
21
  // Generate proper TypeScript types using typeOut format (0, true)
@@ -12,7 +12,7 @@ import { ChainTx } from './tx.js';
12
12
 
13
13
  export * from './types.js';
14
14
 
15
- interface ChainTypes extends GenericChainTypes {
15
+ interface ChainKnownTypes extends GenericChainKnownTypes {
16
16
  Address: {{{addressType}}};
17
17
  Signature: {{{signatureType}}};
18
18
  RuntimeCall: {{{runtimeCallType}}};
@@ -29,7 +29,7 @@ export interface Versioned{{{interfaceName}}}<Rv extends RpcVersion> extends Gen
29
29
  view: ChainViewFunctions<Rv>;
30
30
  tx: ChainTx<Rv>;
31
31
 
32
- types: ChainTypes;
32
+ types: ChainKnownTypes;
33
33
  }
34
34
 
35
35
  {{interfaceDocs}}export interface {{{interfaceName}}} {
@@ -58,7 +58,12 @@ class BaseTypesGen {
58
58
  }
59
59
  else {
60
60
  pathsCount.get(joinedPath).push(id);
61
- typeSuffixes.set(id, this.extractDupTypeSuffix(id, firstOccurrenceTypeId, pathsCount.get(joinedPath).length));
61
+ const existingSuffixes = pathsCount
62
+ .get(joinedPath)
63
+ .map((id) => typeSuffixes.get(id))
64
+ .filter((x) => x);
65
+ typeSuffixes.set(id, this.extractDupTypeSuffix(id, // --
66
+ firstOccurrenceTypeId, pathsCount.get(joinedPath).length, existingSuffixes));
62
67
  }
63
68
  }
64
69
  else {
@@ -340,13 +345,9 @@ class BaseTypesGen {
340
345
  (param1.typeId === undefined) === (param2.typeId === undefined) &&
341
346
  (param1.typeId === undefined || this.#typeEql(param1.typeId, param2.typeId)));
342
347
  }
343
- extractDupTypeSuffix(dupTypeId, originalTypeId, dupCount) {
344
- const originalTypeParams = this.types[originalTypeId].params;
345
- const dupTypeParams = this.types[dupTypeId].params;
346
- const diffParam = dupTypeParams.find((one, idx) => !this.#eqlTypeParam(one, originalTypeParams[idx]));
347
- // TODO make sure these suffix is unique if a type is duplicated more than 2 times
348
- if (diffParam?.typeId) {
349
- const diffType = this.types[diffParam.typeId];
348
+ #getTypeSuffix(typeId) {
349
+ if (typeId) {
350
+ const diffType = this.types[typeId];
350
351
  if (diffType.path.length > 0) {
351
352
  return (0, utils_1.stringPascalCase)(diffType.path.at(-1));
352
353
  }
@@ -354,6 +355,17 @@ class BaseTypesGen {
354
355
  return (0, utils_1.stringPascalCase)(diffType.typeDef.value.kind);
355
356
  }
356
357
  }
358
+ }
359
+ extractDupTypeSuffix(dupTypeId, originalTypeId, dupCount, existingSuffixes = []) {
360
+ const originalTypeParams = this.types[originalTypeId].params;
361
+ const dupTypeParams = this.types[dupTypeId].params;
362
+ const diffParam = dupTypeParams.find((one, idx) => !this.#eqlTypeParam(one, originalTypeParams[idx]));
363
+ if (diffParam?.typeId) {
364
+ const suffix = this.#getTypeSuffix(diffParam.typeId);
365
+ if (suffix && !existingSuffixes.includes(suffix)) {
366
+ return suffix;
367
+ }
368
+ }
357
369
  // Last resort!
358
370
  return dupCount.toString().padStart(3, '0');
359
371
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dedot/codegen",
3
- "version": "0.15.3-next.65898ecf.10+65898ecf",
3
+ "version": "0.16.0",
4
4
  "description": "Generate types",
5
5
  "author": "Thang X. Vu <thang@dedot.dev>",
6
6
  "homepage": "https://dedot.dev",
@@ -18,16 +18,16 @@
18
18
  "copy": "cp -R ./src/chaintypes/templates ./dist/chaintypes && cp -R ./src/chaintypes/templates ./dist/cjs/chaintypes && cp -R ./src/typink/templates ./dist/typink && cp -R ./src/typink/templates ./dist/cjs/typink"
19
19
  },
20
20
  "dependencies": {
21
- "@dedot/api": "0.15.3-next.65898ecf.10+65898ecf",
22
- "@dedot/codecs": "0.15.3-next.65898ecf.10+65898ecf",
23
- "@dedot/contracts": "0.15.3-next.65898ecf.10+65898ecf",
24
- "@dedot/providers": "0.15.3-next.65898ecf.10+65898ecf",
25
- "@dedot/runtime-specs": "0.15.3-next.65898ecf.10+65898ecf",
26
- "@dedot/shape": "0.15.3-next.65898ecf.10+65898ecf",
27
- "@dedot/types": "0.15.3-next.65898ecf.10+65898ecf",
28
- "@dedot/utils": "0.15.3-next.65898ecf.10+65898ecf",
21
+ "@dedot/api": "0.16.0",
22
+ "@dedot/codecs": "0.16.0",
23
+ "@dedot/contracts": "0.16.0",
24
+ "@dedot/providers": "0.16.0",
25
+ "@dedot/runtime-specs": "0.16.0",
26
+ "@dedot/shape": "0.16.0",
27
+ "@dedot/types": "0.16.0",
28
+ "@dedot/utils": "0.16.0",
29
29
  "handlebars": "^4.7.8",
30
- "prettier": "^3.5.3"
30
+ "prettier": "^3.6.2"
31
31
  },
32
32
  "publishConfig": {
33
33
  "access": "public",
@@ -37,7 +37,7 @@
37
37
  "node": ">=18"
38
38
  },
39
39
  "license": "Apache-2.0",
40
- "gitHead": "65898ecf2226162fc6632d3f4f64ad5fe1179643",
40
+ "gitHead": "3e78a8eebb8977de0c5fb956154e5b09c4448f31",
41
41
  "module": "./index.js",
42
42
  "types": "./index.d.ts",
43
43
  "exports": {
@@ -27,7 +27,7 @@ export declare abstract class BaseTypesGen {
27
27
  cleanPath(path: string[]): string;
28
28
  eqlCache: Map<string, boolean>;
29
29
  typeEql(idA: number, idB: number, level?: number): boolean;
30
- extractDupTypeSuffix(dupTypeId: TypeId, originalTypeId: TypeId, dupCount: number): string;
30
+ extractDupTypeSuffix(dupTypeId: TypeId, originalTypeId: TypeId, dupCount: number, existingSuffixes?: string[]): string;
31
31
  addTypeImport(typeName: string | string[]): void;
32
32
  getEnumOptions(_typeId: TypeId): EnumOptions;
33
33
  }
@@ -55,7 +55,12 @@ export class BaseTypesGen {
55
55
  }
56
56
  else {
57
57
  pathsCount.get(joinedPath).push(id);
58
- typeSuffixes.set(id, this.extractDupTypeSuffix(id, firstOccurrenceTypeId, pathsCount.get(joinedPath).length));
58
+ const existingSuffixes = pathsCount
59
+ .get(joinedPath)
60
+ .map((id) => typeSuffixes.get(id))
61
+ .filter((x) => x);
62
+ typeSuffixes.set(id, this.extractDupTypeSuffix(id, // --
63
+ firstOccurrenceTypeId, pathsCount.get(joinedPath).length, existingSuffixes));
59
64
  }
60
65
  }
61
66
  else {
@@ -337,13 +342,9 @@ export class BaseTypesGen {
337
342
  (param1.typeId === undefined) === (param2.typeId === undefined) &&
338
343
  (param1.typeId === undefined || this.#typeEql(param1.typeId, param2.typeId)));
339
344
  }
340
- extractDupTypeSuffix(dupTypeId, originalTypeId, dupCount) {
341
- const originalTypeParams = this.types[originalTypeId].params;
342
- const dupTypeParams = this.types[dupTypeId].params;
343
- const diffParam = dupTypeParams.find((one, idx) => !this.#eqlTypeParam(one, originalTypeParams[idx]));
344
- // TODO make sure these suffix is unique if a type is duplicated more than 2 times
345
- if (diffParam?.typeId) {
346
- const diffType = this.types[diffParam.typeId];
345
+ #getTypeSuffix(typeId) {
346
+ if (typeId) {
347
+ const diffType = this.types[typeId];
347
348
  if (diffType.path.length > 0) {
348
349
  return stringPascalCase(diffType.path.at(-1));
349
350
  }
@@ -351,6 +352,17 @@ export class BaseTypesGen {
351
352
  return stringPascalCase(diffType.typeDef.value.kind);
352
353
  }
353
354
  }
355
+ }
356
+ extractDupTypeSuffix(dupTypeId, originalTypeId, dupCount, existingSuffixes = []) {
357
+ const originalTypeParams = this.types[originalTypeId].params;
358
+ const dupTypeParams = this.types[dupTypeId].params;
359
+ const diffParam = dupTypeParams.find((one, idx) => !this.#eqlTypeParam(one, originalTypeParams[idx]));
360
+ if (diffParam?.typeId) {
361
+ const suffix = this.#getTypeSuffix(diffParam.typeId);
362
+ if (suffix && !existingSuffixes.includes(suffix)) {
363
+ return suffix;
364
+ }
365
+ }
354
366
  // Last resort!
355
367
  return dupCount.toString().padStart(3, '0');
356
368
  }