@pezkuwi/typegen 16.5.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 (99) hide show
  1. package/README.md +3 -0
  2. package/build/augment.d.ts +2 -0
  3. package/build/bundle.d.ts +2 -0
  4. package/build/extractChain.d.ts +1 -0
  5. package/build/fromChain.d.ts +1 -0
  6. package/build/fromDefs.d.ts +1 -0
  7. package/build/generate/consts.d.ts +5 -0
  8. package/build/generate/errors.d.ts +4 -0
  9. package/build/generate/events.d.ts +5 -0
  10. package/build/generate/index.d.ts +10 -0
  11. package/build/generate/interfaceRegistry.d.ts +4 -0
  12. package/build/generate/lookup.d.ts +4 -0
  13. package/build/generate/query.d.ts +5 -0
  14. package/build/generate/rpc.d.ts +6 -0
  15. package/build/generate/runtime.d.ts +7 -0
  16. package/build/generate/tsDef.d.ts +16 -0
  17. package/build/generate/tx.d.ts +5 -0
  18. package/build/generate/types.d.ts +12 -0
  19. package/build/index.d.ts +2 -0
  20. package/build/interfacesTs.d.ts +1 -0
  21. package/build/metadataMd.d.ts +1 -0
  22. package/build/packageDetect.d.ts +1 -0
  23. package/build/packageInfo.d.ts +6 -0
  24. package/build/scripts/polkadot-types-chain-info.mjs +7 -0
  25. package/build/scripts/polkadot-types-from-chain.mjs +7 -0
  26. package/build/scripts/polkadot-types-from-defs.mjs +7 -0
  27. package/build/scripts/polkadot-types-internal-interfaces.mjs +7 -0
  28. package/build/scripts/polkadot-types-internal-metadata.mjs +7 -0
  29. package/build/util/assert.d.ts +2 -0
  30. package/build/util/derived.d.ts +4 -0
  31. package/build/util/docs.d.ts +1 -0
  32. package/build/util/file.d.ts +2 -0
  33. package/build/util/formatting.d.ts +11 -0
  34. package/build/util/imports.d.ts +23 -0
  35. package/build/util/index.d.ts +15 -0
  36. package/build/util/initMeta.d.ts +12 -0
  37. package/build/util/register.d.ts +4 -0
  38. package/build/util/wsMeta.d.ts +4 -0
  39. package/package.json +52 -0
  40. package/scripts/polkadot-types-chain-info.mjs +7 -0
  41. package/scripts/polkadot-types-from-chain.mjs +7 -0
  42. package/scripts/polkadot-types-from-defs.mjs +7 -0
  43. package/scripts/polkadot-types-internal-interfaces.mjs +7 -0
  44. package/scripts/polkadot-types-internal-metadata.mjs +7 -0
  45. package/src/augment.ts +5 -0
  46. package/src/bundle.ts +5 -0
  47. package/src/extractChain.ts +54 -0
  48. package/src/fromChain.ts +123 -0
  49. package/src/fromDefs.ts +106 -0
  50. package/src/generate/consts.ts +112 -0
  51. package/src/generate/errors.ts +75 -0
  52. package/src/generate/events.ts +165 -0
  53. package/src/generate/index.ts +13 -0
  54. package/src/generate/interfaceRegistry.ts +85 -0
  55. package/src/generate/lookup.ts +294 -0
  56. package/src/generate/query.ts +169 -0
  57. package/src/generate/rpc.ts +158 -0
  58. package/src/generate/runtime.ts +284 -0
  59. package/src/generate/tsDef.ts +321 -0
  60. package/src/generate/tx.ts +152 -0
  61. package/src/generate/types.ts +26 -0
  62. package/src/index.ts +6 -0
  63. package/src/interfacesTs.ts +35 -0
  64. package/src/metadataMd.ts +844 -0
  65. package/src/packageDetect.ts +14 -0
  66. package/src/packageInfo.ts +6 -0
  67. package/src/templates/calls.hbs +30 -0
  68. package/src/templates/consts.hbs +28 -0
  69. package/src/templates/docs.hbs +7 -0
  70. package/src/templates/errors.hbs +28 -0
  71. package/src/templates/events.hbs +28 -0
  72. package/src/templates/header.hbs +2 -0
  73. package/src/templates/interfaceRegistry.hbs +15 -0
  74. package/src/templates/lookup/defs-named.hbs +12 -0
  75. package/src/templates/lookup/defs.hbs +15 -0
  76. package/src/templates/lookup/index.hbs +3 -0
  77. package/src/templates/lookup/types.hbs +14 -0
  78. package/src/templates/query.hbs +29 -0
  79. package/src/templates/rpc.hbs +22 -0
  80. package/src/templates/tsDef/index.hbs +3 -0
  81. package/src/templates/tsDef/moduleTypes.hbs +10 -0
  82. package/src/templates/tsDef/types.hbs +7 -0
  83. package/src/templates/tx.hbs +30 -0
  84. package/src/util/assert.ts +18 -0
  85. package/src/util/derived.spec.ts +58 -0
  86. package/src/util/derived.ts +133 -0
  87. package/src/util/docs.ts +13 -0
  88. package/src/util/file.ts +42 -0
  89. package/src/util/formatting.spec.ts +30 -0
  90. package/src/util/formatting.ts +295 -0
  91. package/src/util/imports.ts +164 -0
  92. package/src/util/index.ts +18 -0
  93. package/src/util/initMeta.ts +37 -0
  94. package/src/util/register.ts +12 -0
  95. package/src/util/wsMeta.ts +70 -0
  96. package/tsconfig.build.json +28 -0
  97. package/tsconfig.build.tsbuildinfo +1 -0
  98. package/tsconfig.scripts.json +19 -0
  99. package/tsconfig.spec.json +17 -0
@@ -0,0 +1,14 @@
1
+ // Copyright 2017-2025 @polkadot/typegen authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // Do not edit, auto-generated by @polkadot/dev
5
+ // (packageInfo imports will be kept as-is, user-editable)
6
+
7
+ import { packageInfo as apiInfo } from '@pezkuwi/api/packageInfo';
8
+ import { packageInfo as providerInfo } from '@pezkuwi/rpc-provider/packageInfo';
9
+ import { packageInfo as typesInfo } from '@pezkuwi/types/packageInfo';
10
+ import { detectPackage } from '@pezkuwi/util';
11
+
12
+ import { packageInfo } from './packageInfo.js';
13
+
14
+ detectPackage(packageInfo, null, [apiInfo, providerInfo, typesInfo]);
@@ -0,0 +1,6 @@
1
+ // Copyright 2017-2025 @polkadot/typegen authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // Do not edit, auto-generated by @polkadot/dev
5
+
6
+ export const packageInfo = { name: '@pezkuwi/typegen', path: 'auto', type: 'auto', version: '16.5.5' };
@@ -0,0 +1,30 @@
1
+ {{> header }}
2
+
3
+ // import type lookup before we augment - in some environments
4
+ // this is required to allow for ambient/previous definitions
5
+ import '@polkadot/api-base/types/calls';
6
+
7
+ {{{ importsAll }}}
8
+
9
+ export type __AugmentedCall<ApiType extends ApiTypes> = AugmentedCall<ApiType>;
10
+ export type __DecoratedCallBase<ApiType extends ApiTypes> = DecoratedCallBase<ApiType>;
11
+
12
+ declare module '@polkadot/api-base/types/calls' {
13
+ interface AugmentedCalls<ApiType extends ApiTypes> {
14
+ {{#each modules}}
15
+ /** {{{sectionHash}}}/{{{sectionVersion}}} */
16
+ {{{name}}}: {
17
+ {{#each items}}
18
+ {{> docs}}
19
+ {{{name}}}: AugmentedCall<ApiType, ({{{args}}}) => Observable<{{{type}}}>>;
20
+ {{/each}}
21
+ {{#unless @root.isStrict}}
22
+ /**
23
+ * Generic call
24
+ **/
25
+ [key: string]: DecoratedCallBase<ApiType>;
26
+ {{/unless}}
27
+ };
28
+ {{/each}}
29
+ } // AugmentedCalls
30
+ } // declare module
@@ -0,0 +1,28 @@
1
+ {{> header }}
2
+
3
+ // import type lookup before we augment - in some environments
4
+ // this is required to allow for ambient/previous definitions
5
+ import '@polkadot/api-base/types/consts';
6
+
7
+ {{{ importsAll }}}
8
+
9
+ export type __AugmentedConst<ApiType extends ApiTypes> = AugmentedConst<ApiType>;
10
+
11
+ declare module '@polkadot/api-base/types/consts' {
12
+ interface AugmentedConsts<ApiType extends ApiTypes> {
13
+ {{#each modules}}
14
+ {{{name}}}: {
15
+ {{#each items}}
16
+ {{> docs}}
17
+ {{{name}}}: {{{type}}} & AugmentedConst<ApiType>;
18
+ {{/each}}
19
+ {{#unless @root.isStrict}}
20
+ /**
21
+ * Generic const
22
+ **/
23
+ [key: string]: Codec;
24
+ {{/unless}}
25
+ };
26
+ {{/each}}
27
+ } // AugmentedConsts
28
+ } // declare module
@@ -0,0 +1,7 @@
1
+ {{#if docs.length}}
2
+ /**
3
+ {{#each docs}}
4
+ * {{#trim}}{{{this}}}{{/trim}}
5
+ {{/each}}
6
+ **/
7
+ {{/if}}
@@ -0,0 +1,28 @@
1
+ {{> header }}
2
+
3
+ // import type lookup before we augment - in some environments
4
+ // this is required to allow for ambient/previous definitions
5
+ import '@polkadot/api-base/types/errors';
6
+
7
+ {{{ importsAll }}}
8
+
9
+ export type __AugmentedError<ApiType extends ApiTypes> = AugmentedError<ApiType>;
10
+
11
+ declare module '@polkadot/api-base/types/errors' {
12
+ interface AugmentedErrors<ApiType extends ApiTypes> {
13
+ {{#each modules}}
14
+ {{{name}}}: {
15
+ {{#each items}}
16
+ {{> docs}}
17
+ {{{name}}}: AugmentedError<ApiType>;
18
+ {{/each}}
19
+ {{#unless @root.isStrict}}
20
+ /**
21
+ * Generic error
22
+ **/
23
+ [key: string]: AugmentedError<ApiType>;
24
+ {{/unless}}
25
+ };
26
+ {{/each}}
27
+ } // AugmentedErrors
28
+ } // declare module
@@ -0,0 +1,28 @@
1
+ {{> header }}
2
+
3
+ // import type lookup before we augment - in some environments
4
+ // this is required to allow for ambient/previous definitions
5
+ import '@polkadot/api-base/types/events';
6
+
7
+ {{{ importsAll }}}
8
+
9
+ export type __AugmentedEvent<ApiType extends ApiTypes> = AugmentedEvent<ApiType>;
10
+
11
+ declare module '@polkadot/api-base/types/events' {
12
+ interface AugmentedEvents<ApiType extends ApiTypes> {
13
+ {{#each modules}}
14
+ {{{name}}}: {
15
+ {{#each items}}
16
+ {{> docs}}
17
+ {{{name}}}: AugmentedEvent<ApiType, {{{type}}}>;
18
+ {{/each}}
19
+ {{#unless @root.isStrict}}
20
+ /**
21
+ * Generic event
22
+ **/
23
+ [key: string]: AugmentedEvent<ApiType>;
24
+ {{/unless}}
25
+ };
26
+ {{/each}}
27
+ } // AugmentedEvents
28
+ } // declare module
@@ -0,0 +1,2 @@
1
+ // Auto-generated via `yarn polkadot-types-from-{{headerType}}`, do not edit
2
+ /* eslint-disable */
@@ -0,0 +1,15 @@
1
+ {{> header }}
2
+
3
+ // import type lookup before we augment - in some environments
4
+ // this is required to allow for ambient/previous definitions
5
+ import '@polkadot/types/types/registry';
6
+
7
+ {{{ importsAll }}}
8
+
9
+ declare module '@polkadot/types/types/registry' {
10
+ interface InterfaceTypes {
11
+ {{#each items}}
12
+ {{{this}}}: {{{this}}};
13
+ {{/each}}
14
+ } // InterfaceTypes
15
+ } // declare module
@@ -0,0 +1,12 @@
1
+ {{> header }}
2
+
3
+ /* eslint-disable sort-keys */
4
+
5
+ export default {
6
+ {{#each defs}}
7
+ {{> docs}}
8
+ {{#each defs}}
9
+ {{{this}}}
10
+ {{/each}}
11
+ {{/each}}
12
+ };
@@ -0,0 +1,15 @@
1
+ {{> header }}
2
+
3
+ /* eslint-disable sort-keys */
4
+
5
+ export default {
6
+ rpc: {},
7
+ types: {
8
+ {{#each defs}}
9
+ {{> docs}}
10
+ {{#each defs}}
11
+ {{{this}}}
12
+ {{/each}}
13
+ {{/each}}
14
+ }
15
+ };
@@ -0,0 +1,3 @@
1
+ {{> header }}
2
+
3
+ export * from './types.js';
@@ -0,0 +1,14 @@
1
+ {{> header }}
2
+
3
+ // import type lookup before we augment - in some environments
4
+ // this is required to allow for ambient/previous definitions
5
+ import '@polkadot/types/lookup';
6
+
7
+ {{{ importsAll }}}
8
+
9
+ declare module '@polkadot/types/lookup' {
10
+ {{#each items}}
11
+ {{{this}}}
12
+
13
+ {{/each}}
14
+ } // declare module
@@ -0,0 +1,29 @@
1
+ {{> header }}
2
+
3
+ // import type lookup before we augment - in some environments
4
+ // this is required to allow for ambient/previous definitions
5
+ import '@polkadot/api-base/types/storage';
6
+
7
+ {{{ importsAll }}}
8
+
9
+ export type __AugmentedQuery<ApiType extends ApiTypes> = AugmentedQuery<ApiType, () => unknown>;
10
+ export type __QueryableStorageEntry<ApiType extends ApiTypes> = QueryableStorageEntry<ApiType>;
11
+
12
+ declare module '@polkadot/api-base/types/storage' {
13
+ interface AugmentedQueries<ApiType extends ApiTypes> {
14
+ {{#each modules}}
15
+ {{{name}}}: {
16
+ {{#each items}}
17
+ {{> docs}}
18
+ {{{name}}}: {{{entryType}}}<ApiType, ({{{params}}}) => Observable<{{{returnType}}}>, [{{{args}}}]>{{#unless @root.isStrict}} & QueryableStorageEntry<ApiType, [{{{args}}}]>{{/unless}};
19
+ {{/each}}
20
+ {{#unless @root.isStrict}}
21
+ /**
22
+ * Generic query
23
+ **/
24
+ [key: string]: QueryableStorageEntry<ApiType>;
25
+ {{/unless}}
26
+ };
27
+ {{/each}}
28
+ } // AugmentedQueries
29
+ } // declare module
@@ -0,0 +1,22 @@
1
+ {{> header }}
2
+
3
+ // import type lookup before we augment - in some environments
4
+ // this is required to allow for ambient/previous definitions
5
+ import '@polkadot/rpc-core/types/jsonrpc';
6
+
7
+ {{{ importsAll }}}
8
+
9
+ export type __AugmentedRpc = AugmentedRpc<() => unknown>;
10
+
11
+ declare module '@polkadot/rpc-core/types/jsonrpc' {
12
+ interface RpcInterface {
13
+ {{#each modules}}
14
+ {{{name}}}: {
15
+ {{#each items}}
16
+ {{> docs}}
17
+ {{{name}}}: AugmentedRpc<{{#if generic}}<{{{generic}}}>{{/if}}({{{args}}}) => Observable<{{{type}}}>>;
18
+ {{/each}}
19
+ };
20
+ {{/each}}
21
+ } // RpcInterface
22
+ } // declare module
@@ -0,0 +1,3 @@
1
+ {{> header }}
2
+
3
+ export * from './types.js';
@@ -0,0 +1,10 @@
1
+ {{> header }}
2
+
3
+ {{{ importsAll }}}
4
+
5
+ {{#each items}}
6
+ {{{this}}}
7
+
8
+ {{/each}}
9
+
10
+ export type PHANTOM_{{#upper}}{{{name}}}{{/upper}} = '{{{name}}}';
@@ -0,0 +1,7 @@
1
+ {{> header }}
2
+
3
+ {{#each items}}
4
+ export * from './{{{this}}}/types.js';
5
+ {{/each}}
6
+
7
+ export type PHANTOM_GENERATED = 'generated';
@@ -0,0 +1,30 @@
1
+ {{> header }}
2
+
3
+ // import type lookup before we augment - in some environments
4
+ // this is required to allow for ambient/previous definitions
5
+ import '@polkadot/api-base/types/submittable';
6
+
7
+ {{{ importsAll }}}
8
+
9
+ export type __AugmentedSubmittable = AugmentedSubmittable<() => unknown>;
10
+ export type __SubmittableExtrinsic<ApiType extends ApiTypes> = SubmittableExtrinsic<ApiType>;
11
+ export type __SubmittableExtrinsicFunction<ApiType extends ApiTypes> = SubmittableExtrinsicFunction<ApiType>;
12
+
13
+ declare module '@polkadot/api-base/types/submittable' {
14
+ interface AugmentedSubmittables<ApiType extends ApiTypes> {
15
+ {{#each modules}}
16
+ {{{name}}}: {
17
+ {{#each items}}
18
+ {{> docs}}
19
+ {{{name}}}: AugmentedSubmittable<({{{params}}}) => SubmittableExtrinsic<ApiType>, [{{{args}}}]>;
20
+ {{/each}}
21
+ {{#unless @root.isStrict}}
22
+ /**
23
+ * Generic tx
24
+ **/
25
+ [key: string]: SubmittableExtrinsicFunction<ApiType>;
26
+ {{/unless}}
27
+ };
28
+ {{/each}}
29
+ } // AugmentedSubmittables
30
+ } // declare module
@@ -0,0 +1,18 @@
1
+ // Copyright 2017-2025 @polkadot/typegen authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import fs from 'node:fs';
5
+
6
+ import { assert } from '@pezkuwi/util';
7
+
8
+ export function assertDir (path: string): string {
9
+ assert(fs.existsSync(path) && fs.lstatSync(path).isDirectory(), `${path} is not a directory`);
10
+
11
+ return path;
12
+ }
13
+
14
+ export function assertFile (path: string): string {
15
+ assert(fs.existsSync(path) && fs.lstatSync(path).isFile(), `${path} is not a file`);
16
+
17
+ return path;
18
+ }
@@ -0,0 +1,58 @@
1
+ // Copyright 2017-2025 @polkadot/typegen authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /// <reference types="@pezkuwi/dev-test/globals.d.ts" />
5
+
6
+ import { TypeRegistry } from '@pezkuwi/types/create';
7
+
8
+ import { getSimilarTypes } from './derived.js';
9
+
10
+ describe('getSimilarTypes', (): void => {
11
+ const registry = new TypeRegistry();
12
+ const mockImports = {
13
+ codecTypes: {},
14
+ definitions: {},
15
+ extrinsicTypes: {},
16
+ genericTypes: {},
17
+ ignoredTypes: [],
18
+ localTypes: {},
19
+ lookupTypes: {},
20
+ metadataTypes: {},
21
+ primitiveTypes: {},
22
+ typeToModule: {},
23
+ typesTypes: {}
24
+ };
25
+
26
+ it('handles nested Tuples', (): void => {
27
+ expect(getSimilarTypes(registry, {}, '(AccountId, (Balance, u32), u64)', mockImports)).toEqual([
28
+ 'ITuple<[AccountId, ITuple<[Balance, u32]>, u64]>',
29
+ '[AccountId | string | Uint8Array, ITuple<[Balance, u32]> | [Balance | AnyNumber | Uint8Array, u32 | AnyNumber | Uint8Array], u64 | AnyNumber | Uint8Array]'
30
+ ]);
31
+ });
32
+
33
+ it('handles vectors of slices', (): void => {
34
+ expect(getSimilarTypes(registry, {}, 'Vec<[u8;4]>', mockImports)).toEqual([
35
+ 'Vec<U8aFixed>'
36
+ ]);
37
+ expect(getSimilarTypes(registry, {}, 'Vec<[Balance;8]>', mockImports)).toEqual([
38
+ 'Vec<Vec<Balance>>'
39
+ ]);
40
+ });
41
+
42
+ it('handles structs', (): void => {
43
+ expect(getSimilarTypes(registry, {}, '{ "a": "u8", "b": "Vec<u8>" }', mockImports)).toEqual([
44
+ `{
45
+ readonly a: u8;
46
+ readonly b: Bytes;
47
+ } & Struct`, '{ a?: any; b?: any }', 'string', 'Uint8Array'
48
+ ]);
49
+ });
50
+ it('handles vectors of structs', (): void => {
51
+ expect(getSimilarTypes(registry, {}, 'Vec<{ "a": "H256", "b": "Vec<H256>" }>', mockImports)).toEqual([
52
+ `Vec<{
53
+ readonly a: H256;
54
+ readonly b: Vec<H256>;
55
+ } & Struct>`
56
+ ]);
57
+ });
58
+ });
@@ -0,0 +1,133 @@
1
+ // Copyright 2017-2025 @polkadot/types authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { CodecClass, Registry } from '@pezkuwi/types/types';
5
+ import type { UInt } from '@pezkuwi/types-codec';
6
+ import type { TypeDef } from '@pezkuwi/types-create/types';
7
+ import type { ModuleTypes, TypeImports } from './imports.js';
8
+
9
+ import { GenericAccountId, GenericCall, GenericLookupSource, GenericVote } from '@pezkuwi/types/generic';
10
+ import { AllConvictions } from '@pezkuwi/types/interfaces/democracy/definitions';
11
+ import { AbstractInt, bool, Compact, Enum, Null, Option, Struct, Tuple, Vec, WrapperKeepOpaque, WrapperOpaque } from '@pezkuwi/types-codec';
12
+ import { getTypeDef, TypeDefInfo } from '@pezkuwi/types-create';
13
+ import { isChildClass, stringify } from '@pezkuwi/util';
14
+
15
+ import { formatType } from './formatting.js';
16
+ import { setImports } from './imports.js';
17
+
18
+ function arrayToStrType (arr: string[]): string {
19
+ return `${arr.map((c) => `'${c}'`).join(' | ')}`;
20
+ }
21
+
22
+ const voteConvictions = arrayToStrType(AllConvictions);
23
+
24
+ // Make types a little bit more flexible
25
+ // - if param instanceof AbstractInt, then param: u64 | Uint8array | AnyNumber
26
+ // etc
27
+ /** @internal */
28
+ export function getSimilarTypes (registry: Registry, definitions: Record<string, ModuleTypes>, _type: string, imports: TypeImports): string[] {
29
+ const typeParts = _type.split('::');
30
+ const type = typeParts[typeParts.length - 1];
31
+ const possibleTypes = [formatType(registry, definitions, type, imports)];
32
+
33
+ if (type === 'Extrinsic') {
34
+ setImports(definitions, imports, ['IExtrinsic']);
35
+
36
+ return ['Extrinsic', 'IExtrinsic', 'string', 'Uint8Array'];
37
+ } else if (type === 'Keys') {
38
+ // This one is weird... surely it should popup as a Tuple? (but either way better as defined hex)
39
+ return ['Keys', 'string', 'Uint8Array'];
40
+ } else if (type === 'StorageKey') {
41
+ // TODO We can do better
42
+ return ['StorageKey', 'string', 'Uint8Array', 'any'];
43
+ } else if (type === '()') {
44
+ return ['null'];
45
+ }
46
+
47
+ const Clazz = registry.createClass(type);
48
+
49
+ if (isChildClass(Vec, Clazz)) {
50
+ const vecDef = getTypeDef(type);
51
+ const subDef = (vecDef.sub) as TypeDef;
52
+
53
+ // this could be that we define a Vec type and refer to it by name
54
+ if (subDef) {
55
+ if (subDef.info === TypeDefInfo.Plain) {
56
+ possibleTypes.push(`(${getSimilarTypes(registry, definitions, subDef.type, imports).join(' | ')})[]`);
57
+ } else if (subDef.info === TypeDefInfo.Tuple) {
58
+ const subs = (subDef.sub as TypeDef[]).map(({ type }): string =>
59
+ getSimilarTypes(registry, definitions, type, imports).join(' | ')
60
+ );
61
+
62
+ possibleTypes.push(`([${subs.join(', ')}])[]`);
63
+ } else if (subDef.info === TypeDefInfo.Option || subDef.info === TypeDefInfo.Vec || subDef.info === TypeDefInfo.VecFixed) {
64
+ // TODO: Add possibleTypes so imports work
65
+ } else if (subDef.info === TypeDefInfo.Struct) {
66
+ // TODO: Add possibleTypes so imports work
67
+ } else {
68
+ throw new Error(`Unhandled subtype in Vec, ${stringify(subDef)}`);
69
+ }
70
+ }
71
+ } else if (isChildClass(Enum, Clazz)) {
72
+ const { defKeys, isBasic } = new (Clazz as CodecClass)(registry) as Enum;
73
+ const keys = defKeys.filter((v) => !v.startsWith('__Unused'));
74
+
75
+ if (isBasic) {
76
+ possibleTypes.push(arrayToStrType(keys), 'number');
77
+ } else {
78
+ // TODO We don't really want any here, these should be expanded
79
+ possibleTypes.push(...keys.map((k) => `{ ${k}: any }`), 'string');
80
+ }
81
+
82
+ possibleTypes.push('Uint8Array');
83
+ } else if (isChildClass(AbstractInt as unknown as CodecClass<UInt>, Clazz) || isChildClass(Compact, Clazz)) {
84
+ possibleTypes.push('AnyNumber', 'Uint8Array');
85
+ } else if (isChildClass(GenericLookupSource, Clazz)) {
86
+ possibleTypes.push('Address', 'AccountId', 'AccountIndex', 'LookupSource', 'string', 'Uint8Array');
87
+ } else if (isChildClass(GenericAccountId, Clazz)) {
88
+ possibleTypes.push('string', 'Uint8Array');
89
+ } else if (isChildClass(GenericCall, Clazz)) {
90
+ possibleTypes.push('IMethod', 'string', 'Uint8Array');
91
+ } else if (isChildClass(bool, Clazz)) {
92
+ possibleTypes.push('boolean', 'Uint8Array');
93
+ } else if (isChildClass(Null, Clazz)) {
94
+ possibleTypes.push('null');
95
+ } else if (isChildClass(Struct, Clazz)) {
96
+ const s = new (Clazz as CodecClass)(registry) as Struct;
97
+ const obj = s.defKeys.map((key): string => `${key}?: any`).join('; ');
98
+
99
+ possibleTypes.push(`{ ${obj} }`, 'string', 'Uint8Array');
100
+ } else if (isChildClass(Option, Clazz)) {
101
+ possibleTypes.push('null', 'Uint8Array');
102
+
103
+ const optDef = getTypeDef(type);
104
+ const subDef = (optDef.sub) as TypeDef;
105
+
106
+ if (subDef) {
107
+ possibleTypes.push(...getSimilarTypes(registry, definitions, subDef.type, imports));
108
+ } else {
109
+ possibleTypes.push('object', 'string');
110
+ }
111
+ } else if (isChildClass(GenericVote, Clazz)) {
112
+ possibleTypes.push(`{ aye: boolean; conviction?: ${voteConvictions} | number }`, 'boolean', 'string', 'Uint8Array');
113
+ } else if (isChildClass(WrapperKeepOpaque, Clazz) || isChildClass(WrapperOpaque, Clazz)) {
114
+ // TODO inspect container
115
+ possibleTypes.push('object', 'string', 'Uint8Array');
116
+ } else if (isChildClass(Uint8Array, Clazz)) {
117
+ possibleTypes.push('string', 'Uint8Array');
118
+ } else if (isChildClass(String, Clazz)) {
119
+ possibleTypes.push('string');
120
+ } else if (isChildClass(Tuple, Clazz)) {
121
+ const tupDef = getTypeDef(type);
122
+ const subDef = tupDef.sub;
123
+
124
+ // this could be that we define a Tuple type and refer to it by name
125
+ if (Array.isArray(subDef)) {
126
+ const subs = subDef.map(({ type }) => getSimilarTypes(registry, definitions, type, imports).join(' | '));
127
+
128
+ possibleTypes.push(`[${subs.join(', ')}]`);
129
+ }
130
+ }
131
+
132
+ return [...new Set(possibleTypes)];
133
+ }
@@ -0,0 +1,13 @@
1
+ // Copyright 2017-2025 @polkadot/typegen authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import Handlebars from 'handlebars';
5
+
6
+ import { readTemplate } from './file.js';
7
+
8
+ Handlebars.registerPartial({
9
+ docs: Handlebars.compile(readTemplate('docs'))
10
+ });
11
+
12
+ // empty export
13
+ export const __TYPEGEN_DUMMY_DOCS = 'DUMMY_DOCS';
@@ -0,0 +1,42 @@
1
+ // Copyright 2017-2025 @polkadot/typegen authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import fs from 'node:fs';
5
+ import path from 'node:path';
6
+ import process from 'node:process';
7
+
8
+ import { packageInfo } from '../packageInfo.js';
9
+
10
+ export function writeFile (dest: string, generator: () => string, noLog?: boolean): void {
11
+ !noLog && console.log(`${dest}\n\tGenerating`);
12
+
13
+ let generated = generator();
14
+
15
+ while (generated.includes('\n\n\n')) {
16
+ generated = generated.replace(/\n\n\n/g, '\n\n');
17
+ }
18
+
19
+ !noLog && console.log('\tWriting');
20
+
21
+ fs.writeFileSync(dest, generated, { flag: 'w' });
22
+
23
+ !noLog && console.log('');
24
+ }
25
+
26
+ export function readTemplate (template: string): string {
27
+ // Inside the api repo itself, it will be 'auto'
28
+ const rootDir = packageInfo.path === 'auto'
29
+ ? path.join(process.cwd(), 'packages/typegen/src')
30
+ : packageInfo.path;
31
+
32
+ // NOTE With cjs in a subdir, search one lower as well
33
+ const file = ['./templates', '../templates']
34
+ .map((p) => path.join(rootDir, p, `${template}.hbs`))
35
+ .find((p) => fs.existsSync(p));
36
+
37
+ if (!file) {
38
+ throw new Error(`Unable to locate ${template}.hbs from ${rootDir}`);
39
+ }
40
+
41
+ return fs.readFileSync(file).toString();
42
+ }
@@ -0,0 +1,30 @@
1
+ // Copyright 2017-2025 @polkadot/typegen authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /// <reference types="@pezkuwi/dev-test/globals.d.ts" />
5
+
6
+ import { TypeRegistry } from '@pezkuwi/types';
7
+
8
+ import { formatType } from './formatting.js';
9
+
10
+ describe('formatType', (): void => {
11
+ const registry = new TypeRegistry();
12
+
13
+ it('handles nested Tuples', (): void => {
14
+ expect(
15
+ formatType(registry, {}, '(AccountId, (Balance, u32), u64)', {
16
+ codecTypes: {},
17
+ definitions: {},
18
+ extrinsicTypes: {},
19
+ genericTypes: {},
20
+ ignoredTypes: [],
21
+ localTypes: {},
22
+ lookupTypes: {},
23
+ metadataTypes: {},
24
+ primitiveTypes: {},
25
+ typeToModule: {},
26
+ typesTypes: {}
27
+ })
28
+ ).toEqual('ITuple<[AccountId, ITuple<[Balance, u32]>, u64]>');
29
+ });
30
+ });