@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,152 @@
1
+ // Copyright 2017-2025 @polkadot/typegen authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { VariantDeprecationInfoV16 } from '@pezkuwi/types/interfaces';
5
+ import type { Metadata } from '@pezkuwi/types/metadata/Metadata';
6
+ import type { Text } from '@pezkuwi/types/primitive';
7
+ import type { Definitions, Registry } from '@pezkuwi/types/types';
8
+ import type { HexString } from '@pezkuwi/util/types';
9
+
10
+ import Handlebars from 'handlebars';
11
+
12
+ import * as defaultDefs from '@pezkuwi/types/interfaces/definitions';
13
+ import lookupDefinitions from '@pezkuwi/types-augment/lookup/definitions';
14
+ import { stringCamelCase } from '@pezkuwi/util';
15
+
16
+ import { compareName, createImports, formatType, getSimilarTypes, initMeta, readTemplate, setImports, writeFile } from '../util/index.js';
17
+ import { ignoreUnusedLookups } from './lookup.js';
18
+ import { type ExtraTypes, getDeprecationNotice } from './types.js';
19
+
20
+ const MAPPED_NAMES: Record<string, string> = {
21
+ class: 'clazz',
22
+ new: 'updated'
23
+ };
24
+
25
+ const generateForMetaTemplate = Handlebars.compile(readTemplate('tx'));
26
+
27
+ function mapName (_name: Text): string {
28
+ const name = stringCamelCase(_name);
29
+
30
+ return MAPPED_NAMES[name] || name;
31
+ }
32
+
33
+ /** @internal */
34
+ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extraTypes: ExtraTypes, isStrict: boolean, customLookupDefinitions?: Definitions): void {
35
+ writeFile(dest, (): string => {
36
+ const allTypes: ExtraTypes = {
37
+ '@pezkuwi/types-augment': {
38
+ lookup: {
39
+ ...lookupDefinitions,
40
+ ...customLookupDefinitions
41
+ }
42
+ },
43
+ '@pezkuwi/types/interfaces': defaultDefs,
44
+ ...extraTypes
45
+ };
46
+ const imports = createImports(allTypes);
47
+ const allDefs = Object.entries(allTypes).reduce((defs, [path, obj]) => {
48
+ return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [`${path}/${key}`]: value }), defs);
49
+ }, {});
50
+ const { lookup, pallets } = meta.asLatest;
51
+ const usedTypes = new Set<string>([]);
52
+ const modules = pallets
53
+ .sort(compareName)
54
+ .filter(({ calls }) => calls.isSome)
55
+ .map((data) => {
56
+ const name = data.name;
57
+ const calls = data.calls.unwrap();
58
+ const deprecationInfo = calls.deprecationInfo.toJSON();
59
+
60
+ setImports(allDefs, imports, ['SubmittableExtrinsic']);
61
+
62
+ const sectionName = stringCamelCase(name);
63
+ const items = lookup.getSiType(calls.type).def.asVariant.variants
64
+ .map(({ docs, fields, index, name }) => {
65
+ const rawStatus = deprecationInfo?.[index.toNumber()];
66
+
67
+ if (rawStatus) {
68
+ const deprecationVariantInfo: VariantDeprecationInfoV16 = meta.registry.createTypeUnsafe('VariantDeprecationInfoV16', [rawStatus]);
69
+ const deprecationNotice = getDeprecationNotice(deprecationVariantInfo, name.toString(), 'Call');
70
+ const notice = docs.length ? ['', deprecationNotice] : [deprecationNotice];
71
+
72
+ docs.push(...notice.map((text) => meta.registry.createType('Text', text)));
73
+ }
74
+
75
+ const typesInfo = fields.map(({ name, type, typeName }, index): [string, string, string] => {
76
+ const typeDef = registry.lookup.getTypeDef(type);
77
+
78
+ return [
79
+ name.isSome
80
+ ? mapName(name.unwrap())
81
+ : `param${index}`,
82
+ typeName.isSome
83
+ ? typeName.toString()
84
+ : typeDef.type,
85
+ typeDef.isFromSi
86
+ ? typeDef.type
87
+ : typeDef.lookupName || typeDef.type
88
+ ];
89
+ });
90
+
91
+ const params = typesInfo
92
+ .map(([name,, typeStr]) => {
93
+ const similarTypes = getSimilarTypes(registry, allDefs, typeStr, imports);
94
+
95
+ setImports(allDefs, imports, [typeStr, ...similarTypes]);
96
+
97
+ // Add the type to the list of used types
98
+ if (!(imports.primitiveTypes[typeStr])) {
99
+ usedTypes.add(typeStr);
100
+ }
101
+
102
+ return `${name}: ${similarTypes.join(' | ')}`;
103
+ })
104
+ .join(', ');
105
+
106
+ return {
107
+ args: typesInfo.map(([,, typeStr]) =>
108
+ formatType(registry, allDefs, typeStr, imports)
109
+ ).join(', '),
110
+ docs,
111
+ name: stringCamelCase(name),
112
+ params
113
+ };
114
+ })
115
+ .sort(compareName);
116
+
117
+ return {
118
+ items,
119
+ name: sectionName
120
+ };
121
+ })
122
+ .sort(compareName);
123
+
124
+ // filter out the unused lookup types from imports
125
+ ignoreUnusedLookups([...usedTypes], imports);
126
+
127
+ return generateForMetaTemplate({
128
+ headerType: 'chain',
129
+ imports,
130
+ isStrict,
131
+ modules,
132
+ types: [
133
+ ...Object.keys(imports.localTypes).sort().map((packagePath): { file: string; types: string[] } => ({
134
+ file: packagePath.replace('@pezkuwi/types-augment', '@pezkuwi/types'),
135
+ types: Object.keys(imports.localTypes[packagePath])
136
+ })),
137
+ {
138
+ file: '@pezkuwi/api-base/types',
139
+ types: ['ApiTypes', 'AugmentedSubmittable', 'SubmittableExtrinsic', 'SubmittableExtrinsicFunction']
140
+ }
141
+ ]
142
+ });
143
+ });
144
+ }
145
+
146
+ // Call `generateForMeta()` with current static metadata
147
+ /** @internal */
148
+ export function generateDefaultTx (dest: string, data: HexString, extraTypes: ExtraTypes = {}, isStrict = false, customLookupDefinitions?: Definitions): void {
149
+ const { metadata, registry } = initMeta(data, extraTypes);
150
+
151
+ return generateForMeta(registry, metadata, dest, extraTypes, isStrict, customLookupDefinitions);
152
+ }
@@ -0,0 +1,26 @@
1
+ // Copyright 2017-2025 @polkadot/typegen authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Option, Text } from '@pezkuwi/types-codec';
5
+
6
+ export type ExtraTypes = Record<string, Record<string, {
7
+ runtime?: Record<string, any>;
8
+ types: Record<string, any>;
9
+ }>>;
10
+
11
+ export function getDeprecationNotice<T extends { isDeprecated: boolean; asDeprecated: { note: Text; since: Option<Text> }}> (deprecationInfo: T, name: string, label?: string): string {
12
+ let deprecationNotice = '@deprecated';
13
+
14
+ if (deprecationInfo.isDeprecated) {
15
+ const { note, since } = deprecationInfo.asDeprecated;
16
+ const sinceText = since.isSome ? ` Since ${since.unwrap().toString()}.` : '';
17
+
18
+ deprecationNotice += ` ${note.toString()}${sinceText}`;
19
+ } else {
20
+ const labelText = label ? `${label} ` : '';
21
+
22
+ deprecationNotice += ` ${labelText}${name} has been deprecated`;
23
+ }
24
+
25
+ return deprecationNotice;
26
+ }
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ // Copyright 2017-2025 @polkadot/typegen authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import './packageDetect.js';
5
+
6
+ export * from './bundle.js';
@@ -0,0 +1,35 @@
1
+ // Copyright 2017-2025 @polkadot/typegen authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { HexString } from '@pezkuwi/util/types';
5
+
6
+ // TODO: replace v15 to v16 once metadata is updated
7
+ import assetHubKusama from '@pezkuwi/types-support/metadata/v15/asset-hub-kusama-hex';
8
+ import assetHubPolkadot from '@pezkuwi/types-support/metadata/v15/asset-hub-polkadot-hex';
9
+ import kusama from '@pezkuwi/types-support/metadata/v15/kusama-hex';
10
+ import polkadot from '@pezkuwi/types-support/metadata/v15/polkadot-hex';
11
+ import substrate from '@pezkuwi/types-support/metadata/v15/substrate-hex';
12
+
13
+ import { generateDefaultConsts, generateDefaultErrors, generateDefaultEvents, generateDefaultInterface, generateDefaultLookup, generateDefaultQuery, generateDefaultRpc, generateDefaultRuntime, generateDefaultTsDef, generateDefaultTx } from './generate/index.js';
14
+
15
+ const BASE = 'packages/api-augment/src';
16
+ const METAS = Object.entries<HexString>({ assetHubKusama, assetHubPolkadot, kusama, polkadot, substrate });
17
+
18
+ export function main (): void {
19
+ generateDefaultInterface();
20
+ generateDefaultLookup();
21
+ generateDefaultRpc();
22
+ generateDefaultTsDef();
23
+
24
+ for (const [name, staticMeta] of METAS) {
25
+ console.log();
26
+ console.log(`*** Generating for ${name}`);
27
+
28
+ generateDefaultConsts(`${BASE}/${name}/consts.ts`, staticMeta);
29
+ generateDefaultErrors(`${BASE}/${name}/errors.ts`, staticMeta);
30
+ generateDefaultEvents(`${BASE}/${name}/events.ts`, staticMeta);
31
+ generateDefaultQuery(`${BASE}/${name}/query.ts`, staticMeta);
32
+ generateDefaultRuntime(`${BASE}/${name}/runtime.ts`, staticMeta);
33
+ generateDefaultTx(`${BASE}/${name}/tx.ts`, staticMeta);
34
+ }
35
+ }