@pezkuwi/typegen 16.5.5 → 16.5.6

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 (193) hide show
  1. package/LICENSE +201 -0
  2. package/augment.js +2 -0
  3. package/bundle.js +2 -0
  4. package/cjs/augment.d.ts +2 -0
  5. package/cjs/augment.js +4 -0
  6. package/cjs/bundle.d.ts +2 -0
  7. package/cjs/bundle.js +7 -0
  8. package/cjs/extractChain.js +44 -0
  9. package/cjs/fromChain.js +95 -0
  10. package/cjs/fromDefs.js +82 -0
  11. package/cjs/generate/consts.js +91 -0
  12. package/cjs/generate/errors.js +59 -0
  13. package/cjs/generate/events.js +139 -0
  14. package/cjs/generate/index.js +23 -0
  15. package/cjs/generate/interfaceRegistry.js +64 -0
  16. package/cjs/generate/lookup.js +240 -0
  17. package/cjs/generate/query.js +140 -0
  18. package/cjs/generate/rpc.js +115 -0
  19. package/cjs/generate/runtime.js +233 -0
  20. package/{build → cjs}/generate/tsDef.d.ts +1 -1
  21. package/cjs/generate/tsDef.js +254 -0
  22. package/cjs/generate/tx.js +121 -0
  23. package/cjs/generate/types.js +16 -0
  24. package/cjs/index.js +5 -0
  25. package/cjs/interfacesTs.js +28 -0
  26. package/cjs/metadataMd.js +652 -0
  27. package/cjs/package.json +3 -0
  28. package/cjs/packageDetect.js +8 -0
  29. package/cjs/packageInfo.js +4 -0
  30. package/cjs/util/assert.js +15 -0
  31. package/cjs/util/derived.js +128 -0
  32. package/cjs/util/docs.js +10 -0
  33. package/cjs/util/file.js +33 -0
  34. package/{build → cjs}/util/formatting.d.ts +1 -1
  35. package/cjs/util/formatting.js +237 -0
  36. package/cjs/util/imports.js +126 -0
  37. package/{build → cjs}/util/index.d.ts +1 -0
  38. package/cjs/util/index.js +39 -0
  39. package/cjs/util/initMeta.js +22 -0
  40. package/cjs/util/register.js +10 -0
  41. package/cjs/util/wsMeta.js +60 -0
  42. package/extractChain.d.ts +1 -0
  43. package/extractChain.js +40 -0
  44. package/fromChain.d.ts +1 -0
  45. package/fromChain.js +91 -0
  46. package/fromDefs.d.ts +1 -0
  47. package/fromDefs.js +78 -0
  48. package/generate/consts.d.ts +5 -0
  49. package/generate/consts.js +87 -0
  50. package/generate/errors.d.ts +4 -0
  51. package/generate/errors.js +55 -0
  52. package/generate/events.d.ts +5 -0
  53. package/generate/events.js +135 -0
  54. package/{src/generate/index.ts → generate/index.d.ts} +0 -3
  55. package/generate/index.js +10 -0
  56. package/generate/interfaceRegistry.d.ts +4 -0
  57. package/generate/interfaceRegistry.js +59 -0
  58. package/generate/lookup.d.ts +4 -0
  59. package/generate/lookup.js +235 -0
  60. package/generate/query.d.ts +5 -0
  61. package/generate/query.js +136 -0
  62. package/generate/rpc.d.ts +6 -0
  63. package/generate/rpc.js +110 -0
  64. package/generate/runtime.d.ts +7 -0
  65. package/generate/runtime.js +228 -0
  66. package/generate/tsDef.d.ts +16 -0
  67. package/generate/tsDef.js +246 -0
  68. package/generate/tx.d.ts +5 -0
  69. package/generate/tx.js +117 -0
  70. package/generate/types.d.ts +12 -0
  71. package/generate/types.js +13 -0
  72. package/index.d.ts +2 -0
  73. package/index.js +2 -0
  74. package/interfacesTs.d.ts +1 -0
  75. package/interfacesTs.js +24 -0
  76. package/metadataMd.d.ts +1 -0
  77. package/metadataMd.js +648 -0
  78. package/package.json +520 -24
  79. package/packageDetect.d.ts +1 -0
  80. package/{src/packageDetect.ts → packageDetect.js} +0 -8
  81. package/packageInfo.d.ts +6 -0
  82. package/packageInfo.js +1 -0
  83. package/scripts/{polkadot-types-chain-info.mjs → pezkuwi-types-chain-info.mjs} +1 -1
  84. package/scripts/{polkadot-types-from-chain.mjs → pezkuwi-types-from-chain.mjs} +1 -1
  85. package/scripts/{polkadot-types-from-defs.mjs → pezkuwi-types-from-defs.mjs} +1 -1
  86. package/{build/scripts/polkadot-types-internal-interfaces.mjs → scripts/pezkuwi-types-internal-interfaces.mjs} +1 -1
  87. package/{build/scripts/polkadot-types-internal-metadata.mjs → scripts/pezkuwi-types-internal-metadata.mjs} +1 -1
  88. package/{src/templates → templates}/calls.hbs +2 -2
  89. package/{src/templates → templates}/consts.hbs +2 -2
  90. package/{src/templates → templates}/errors.hbs +2 -2
  91. package/{src/templates → templates}/events.hbs +2 -2
  92. package/{src/templates → templates}/interfaceRegistry.hbs +2 -2
  93. package/{src/templates → templates}/lookup/types.hbs +2 -2
  94. package/{src/templates → templates}/query.hbs +2 -2
  95. package/{src/templates → templates}/rpc.hbs +2 -2
  96. package/{src/templates → templates}/tx.hbs +2 -2
  97. package/util/assert.d.ts +2 -0
  98. package/util/assert.js +10 -0
  99. package/util/derived.d.ts +4 -0
  100. package/util/derived.js +125 -0
  101. package/util/docs.d.ts +1 -0
  102. package/util/docs.js +6 -0
  103. package/util/file.d.ts +2 -0
  104. package/util/file.js +28 -0
  105. package/util/formatting.d.ts +11 -0
  106. package/util/formatting.js +230 -0
  107. package/util/imports.d.ts +23 -0
  108. package/util/imports.js +121 -0
  109. package/{src/util/index.ts → util/index.d.ts} +6 -8
  110. package/util/index.js +34 -0
  111. package/util/initMeta.d.ts +12 -0
  112. package/util/initMeta.js +19 -0
  113. package/util/register.d.ts +4 -0
  114. package/util/register.js +7 -0
  115. package/util/wsMeta.d.ts +4 -0
  116. package/util/wsMeta.js +55 -0
  117. package/build/scripts/polkadot-types-chain-info.mjs +0 -7
  118. package/build/scripts/polkadot-types-from-chain.mjs +0 -7
  119. package/build/scripts/polkadot-types-from-defs.mjs +0 -7
  120. package/scripts/polkadot-types-internal-interfaces.mjs +0 -7
  121. package/scripts/polkadot-types-internal-metadata.mjs +0 -7
  122. package/src/augment.ts +0 -5
  123. package/src/bundle.ts +0 -5
  124. package/src/extractChain.ts +0 -54
  125. package/src/fromChain.ts +0 -123
  126. package/src/fromDefs.ts +0 -106
  127. package/src/generate/consts.ts +0 -112
  128. package/src/generate/errors.ts +0 -75
  129. package/src/generate/events.ts +0 -165
  130. package/src/generate/interfaceRegistry.ts +0 -85
  131. package/src/generate/lookup.ts +0 -294
  132. package/src/generate/query.ts +0 -169
  133. package/src/generate/rpc.ts +0 -158
  134. package/src/generate/runtime.ts +0 -284
  135. package/src/generate/tsDef.ts +0 -321
  136. package/src/generate/tx.ts +0 -152
  137. package/src/generate/types.ts +0 -26
  138. package/src/index.ts +0 -6
  139. package/src/interfacesTs.ts +0 -35
  140. package/src/metadataMd.ts +0 -844
  141. package/src/packageInfo.ts +0 -6
  142. package/src/util/assert.ts +0 -18
  143. package/src/util/derived.spec.ts +0 -58
  144. package/src/util/derived.ts +0 -133
  145. package/src/util/docs.ts +0 -13
  146. package/src/util/file.ts +0 -42
  147. package/src/util/formatting.spec.ts +0 -30
  148. package/src/util/formatting.ts +0 -295
  149. package/src/util/imports.ts +0 -164
  150. package/src/util/initMeta.ts +0 -37
  151. package/src/util/register.ts +0 -12
  152. package/src/util/wsMeta.ts +0 -70
  153. package/tsconfig.build.json +0 -28
  154. package/tsconfig.build.tsbuildinfo +0 -1
  155. package/tsconfig.scripts.json +0 -19
  156. package/tsconfig.spec.json +0 -17
  157. /package/{build/augment.d.ts → augment.d.ts} +0 -0
  158. /package/{build/bundle.d.ts → bundle.d.ts} +0 -0
  159. /package/{build → cjs}/extractChain.d.ts +0 -0
  160. /package/{build → cjs}/fromChain.d.ts +0 -0
  161. /package/{build → cjs}/fromDefs.d.ts +0 -0
  162. /package/{build → cjs}/generate/consts.d.ts +0 -0
  163. /package/{build → cjs}/generate/errors.d.ts +0 -0
  164. /package/{build → cjs}/generate/events.d.ts +0 -0
  165. /package/{build → cjs}/generate/index.d.ts +0 -0
  166. /package/{build → cjs}/generate/interfaceRegistry.d.ts +0 -0
  167. /package/{build → cjs}/generate/lookup.d.ts +0 -0
  168. /package/{build → cjs}/generate/query.d.ts +0 -0
  169. /package/{build → cjs}/generate/rpc.d.ts +0 -0
  170. /package/{build → cjs}/generate/runtime.d.ts +0 -0
  171. /package/{build → cjs}/generate/tx.d.ts +0 -0
  172. /package/{build → cjs}/generate/types.d.ts +0 -0
  173. /package/{build → cjs}/index.d.ts +0 -0
  174. /package/{build → cjs}/interfacesTs.d.ts +0 -0
  175. /package/{build → cjs}/metadataMd.d.ts +0 -0
  176. /package/{build → cjs}/packageDetect.d.ts +0 -0
  177. /package/{build → cjs}/packageInfo.d.ts +0 -0
  178. /package/{build → cjs}/util/assert.d.ts +0 -0
  179. /package/{build → cjs}/util/derived.d.ts +0 -0
  180. /package/{build → cjs}/util/docs.d.ts +0 -0
  181. /package/{build → cjs}/util/file.d.ts +0 -0
  182. /package/{build → cjs}/util/imports.d.ts +0 -0
  183. /package/{build → cjs}/util/initMeta.d.ts +0 -0
  184. /package/{build → cjs}/util/register.d.ts +0 -0
  185. /package/{build → cjs}/util/wsMeta.d.ts +0 -0
  186. /package/{src/templates → templates}/docs.hbs +0 -0
  187. /package/{src/templates → templates}/header.hbs +0 -0
  188. /package/{src/templates → templates}/lookup/defs-named.hbs +0 -0
  189. /package/{src/templates → templates}/lookup/defs.hbs +0 -0
  190. /package/{src/templates → templates}/lookup/index.hbs +0 -0
  191. /package/{src/templates → templates}/tsDef/index.hbs +0 -0
  192. /package/{src/templates → templates}/tsDef/moduleTypes.hbs +0 -0
  193. /package/{src/templates → templates}/tsDef/types.hbs +0 -0
@@ -0,0 +1,121 @@
1
+ import * as codecClasses from '@pezkuwi/types/codec';
2
+ import * as extrinsicClasses from '@pezkuwi/types/extrinsic';
3
+ import * as genericClasses from '@pezkuwi/types/generic';
4
+ import * as primitiveClasses from '@pezkuwi/types/primitive';
5
+ import { getTypeDef, TypeDefInfo } from '@pezkuwi/types-create';
6
+ function splitAlternatives(type) {
7
+ const alternatives = [];
8
+ let beginOfAlternative = 1;
9
+ let level = 0;
10
+ // we assume that the string starts with '['
11
+ for (let i = 1, count = type.length; i < count; i++) {
12
+ if (level === 0) {
13
+ switch (type[i]) {
14
+ case ']':
15
+ case ',':
16
+ case '|':
17
+ alternatives.push(type.substring(beginOfAlternative, i).trim());
18
+ beginOfAlternative = i + 1;
19
+ break;
20
+ }
21
+ }
22
+ switch (type[i]) {
23
+ case '[':
24
+ case '(':
25
+ case '<':
26
+ level++;
27
+ break;
28
+ case ']':
29
+ case ')':
30
+ case '>':
31
+ level--;
32
+ break;
33
+ }
34
+ }
35
+ return alternatives;
36
+ }
37
+ /** @internal */
38
+ export function setImports(allDefs, imports, types) {
39
+ const { codecTypes, extrinsicTypes, genericTypes, ignoredTypes, localTypes, metadataTypes, primitiveTypes, typesTypes } = imports;
40
+ types.filter((t) => !!t).forEach((type) => {
41
+ if (ignoredTypes.includes(type)) {
42
+ // do nothing
43
+ }
44
+ else if (['AnyNumber', 'CallFunction', 'Codec', 'IExtrinsic', 'IMethod', 'ITuple'].includes(type)) {
45
+ typesTypes[type] = true;
46
+ }
47
+ else if (['Metadata', 'PortableRegistry'].includes(type)) {
48
+ metadataTypes[type] = true;
49
+ }
50
+ else if (codecClasses[type]) {
51
+ codecTypes[type] = true;
52
+ }
53
+ else if (extrinsicClasses[type]) {
54
+ extrinsicTypes[type] = true;
55
+ }
56
+ else if (genericClasses[type]) {
57
+ genericTypes[type] = true;
58
+ }
59
+ else if (primitiveClasses[type]) {
60
+ primitiveTypes[type] = true;
61
+ }
62
+ else if (type.startsWith('[') && type.includes('|')) {
63
+ const splitTypes = splitAlternatives(type);
64
+ setImports(allDefs, imports, splitTypes);
65
+ }
66
+ else if (type.includes('<') || type.includes('(') || type.includes('[')) {
67
+ // If the type is a bit special (tuple, fixed u8, nested type...), then we
68
+ // need to parse it with `getTypeDef`.
69
+ const typeDef = getTypeDef(type);
70
+ setImports(allDefs, imports, [TypeDefInfo[typeDef.info]]);
71
+ // TypeDef.sub is a `TypeDef | TypeDef[]`
72
+ if (Array.isArray(typeDef.sub)) {
73
+ typeDef.sub.forEach((subType) => setImports(allDefs, imports, [subType.lookupName || subType.type]));
74
+ }
75
+ else if (typeDef.sub && (typeDef.info !== TypeDefInfo.VecFixed || typeDef.sub.type !== 'u8')) {
76
+ // typeDef.sub is a TypeDef in this case
77
+ setImports(allDefs, imports, [typeDef.sub.lookupName || typeDef.sub.type]);
78
+ }
79
+ }
80
+ else {
81
+ // find this module inside the exports from the rest
82
+ const [moduleName] = Object.entries(allDefs).find(([, { types }]) => Object.keys(types).includes(type)) || [null];
83
+ if (moduleName) {
84
+ localTypes[moduleName][type] = true;
85
+ }
86
+ }
87
+ });
88
+ }
89
+ /** @internal */
90
+ export function createImports(importDefinitions, { types } = { types: {} }) {
91
+ const definitions = {};
92
+ const typeToModule = {};
93
+ Object.entries(importDefinitions).forEach(([packagePath, packageDef]) => {
94
+ Object.entries(packageDef).forEach(([name, moduleDef]) => {
95
+ const fullName = `${packagePath}/${name}`;
96
+ definitions[fullName] = moduleDef;
97
+ Object.keys(moduleDef.types).forEach((type) => {
98
+ if (typeToModule[type]) {
99
+ console.warn(`\t\tWARN: Overwriting duplicated type '${type}' ${typeToModule[type]} -> ${fullName}`);
100
+ }
101
+ typeToModule[type] = fullName;
102
+ });
103
+ });
104
+ });
105
+ return {
106
+ codecTypes: {},
107
+ definitions,
108
+ extrinsicTypes: {},
109
+ genericTypes: {},
110
+ ignoredTypes: Object.keys(types),
111
+ localTypes: Object.keys(definitions).reduce((local, mod) => {
112
+ local[mod] = {};
113
+ return local;
114
+ }, {}),
115
+ lookupTypes: {},
116
+ metadataTypes: {},
117
+ primitiveTypes: {},
118
+ typeToModule,
119
+ typesTypes: {}
120
+ };
121
+ }
@@ -1,6 +1,3 @@
1
- // Copyright 2017-2025 @polkadot/typegen authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
1
  export * from './assert.js';
5
2
  export * from './derived.js';
6
3
  export * from './docs.js';
@@ -10,9 +7,10 @@ export * from './imports.js';
10
7
  export * from './initMeta.js';
11
8
  export * from './register.js';
12
9
  export * from './wsMeta.js';
13
-
14
- interface Cmp { name: { toString(): string } }
15
-
16
- export function compareName (a: Cmp, b: Cmp): number {
17
- return a.name.toString().localeCompare(b.name.toString());
10
+ interface Cmp {
11
+ name: {
12
+ toString(): string;
13
+ };
18
14
  }
15
+ export declare function compareName(a: Cmp, b: Cmp): number;
16
+ export declare function rebrandTypeName(typeName: string): string;
package/util/index.js ADDED
@@ -0,0 +1,34 @@
1
+ export * from './assert.js';
2
+ export * from './derived.js';
3
+ export * from './docs.js';
4
+ export * from './file.js';
5
+ export * from './formatting.js';
6
+ export * from './imports.js';
7
+ export * from './initMeta.js';
8
+ export * from './register.js';
9
+ export * from './wsMeta.js';
10
+ export function compareName(a, b) {
11
+ return a.name.toString().localeCompare(b.name.toString());
12
+ }
13
+ export function rebrandTypeName(typeName) {
14
+ return typeName
15
+ // Main projects
16
+ .replace(/Polkadot/g, 'Pezkuwi')
17
+ .replace(/Substrate/g, 'Bizinikiwi')
18
+ .replace(/Cumulus/g, 'Pezcumulus')
19
+ // Networks
20
+ .replace(/Kusama/g, 'Dicle')
21
+ .replace(/Westend/g, 'Zagros')
22
+ .replace(/Rococo/g, 'Pezkuwichain')
23
+ // Chain types
24
+ .replace(/Parachain/g, 'Teyrchain')
25
+ // Module prefixes (in PascalCase type names)
26
+ .replace(/Frame(?=[A-Z])/g, 'Pezframe')
27
+ .replace(/Pallet(?=[A-Z])/g, 'Pezpallet')
28
+ // Primitives prefixes (sp_ becomes Sp in type names)
29
+ .replace(/^Sp(?=[A-Z])/g, 'Pezsp')
30
+ .replace(/([^a-zA-Z])Sp(?=[A-Z])/g, '$1Pezsp')
31
+ // Client prefixes (sc_ becomes Sc in type names)
32
+ .replace(/^Sc(?=[A-Z])/g, 'Pezsc')
33
+ .replace(/([^a-zA-Z])Sc(?=[A-Z])/g, '$1Pezsc');
34
+ }
@@ -0,0 +1,12 @@
1
+ import type { HexString } from '@pezkuwi/util/types';
2
+ import type { ExtraTypes } from '../generate/types.js';
3
+ import { Metadata, TypeRegistry } from '@pezkuwi/types';
4
+ interface Result {
5
+ metadata: Metadata;
6
+ registry: TypeRegistry;
7
+ }
8
+ /**
9
+ * This helper method has been transitioned to work with V14, V15 and up.
10
+ */
11
+ export declare function initMeta(staticMeta: HexString, extraTypes?: ExtraTypes): Result;
12
+ export {};
@@ -0,0 +1,19 @@
1
+ import { Metadata, TypeRegistry } from '@pezkuwi/types';
2
+ import { registerDefinitions } from './register.js';
3
+ /**
4
+ * This helper method has been transitioned to work with V14, V15 and up.
5
+ */
6
+ export function initMeta(staticMeta, extraTypes = {}) {
7
+ const registry = new TypeRegistry();
8
+ registerDefinitions(registry, extraTypes);
9
+ let metadata;
10
+ try {
11
+ const opaqueMetadata = registry.createType('Option<OpaqueMetadata>', registry.createType('Raw', staticMeta).toU8a()).unwrap();
12
+ metadata = new Metadata(registry, opaqueMetadata.toHex());
13
+ }
14
+ catch {
15
+ metadata = new Metadata(registry, staticMeta);
16
+ }
17
+ registry.setMetadata(metadata);
18
+ return { metadata, registry };
19
+ }
@@ -0,0 +1,4 @@
1
+ import type { TypeRegistry } from '@pezkuwi/types/create';
2
+ export declare function registerDefinitions(registry: TypeRegistry, extras: Record<string, Record<string, {
3
+ types: Record<string, any>;
4
+ }>>): void;
@@ -0,0 +1,7 @@
1
+ export function registerDefinitions(registry, extras) {
2
+ Object.values(extras).forEach((def) => {
3
+ Object.values(def).forEach(({ types }) => {
4
+ registry.register(types);
5
+ });
6
+ });
7
+ }
@@ -0,0 +1,4 @@
1
+ import type { HexString } from '@pezkuwi/util/types';
2
+ export declare function getMetadataViaWs(endpoint: string, metadataVer?: number): Promise<HexString>;
3
+ export declare function getRpcMethodsViaWs(endpoint: string): Promise<string[]>;
4
+ export declare function getRuntimeVersionViaWs(endpoint: string): Promise<[apiHash: string, apiVersion: number][]>;
package/util/wsMeta.js ADDED
@@ -0,0 +1,55 @@
1
+ import { promiseTracker } from '@pezkuwi/api/promise/decorateMethod';
2
+ import { TypeRegistry } from '@pezkuwi/types';
3
+ import { stringify, u8aToHex } from '@pezkuwi/util';
4
+ import { WebSocket } from '@pezkuwi/x-ws';
5
+ async function getWsData(endpoint, method, params) {
6
+ return new Promise((resolve, reject) => {
7
+ const tracker = promiseTracker(resolve, reject);
8
+ try {
9
+ const websocket = new WebSocket(endpoint);
10
+ websocket.onclose = (event) => {
11
+ if (event.code !== 1000) {
12
+ tracker.reject(new Error(`disconnected, code: '${event.code}' reason: '${event.reason}'`));
13
+ }
14
+ };
15
+ websocket.onerror = (event) => {
16
+ tracker.reject(new Error(`WebSocket error:: ${stringify(event)}`));
17
+ };
18
+ websocket.onopen = () => {
19
+ console.log('connected');
20
+ params
21
+ ? websocket.send(`{"id":"1","jsonrpc":"2.0","method":"${method}","params":[${params.map((param) => `"${param}"`).join(',')}]}`)
22
+ : websocket.send(`{"id":"1","jsonrpc":"2.0","method":"${method}","params":[]}`);
23
+ };
24
+ websocket.onmessage = (message) => {
25
+ try {
26
+ tracker.resolve(JSON.parse(message.data).result);
27
+ }
28
+ catch (error) {
29
+ tracker.reject(error);
30
+ }
31
+ websocket.close();
32
+ };
33
+ }
34
+ catch (error) {
35
+ tracker.reject(error);
36
+ }
37
+ });
38
+ }
39
+ export async function getMetadataViaWs(endpoint, metadataVer) {
40
+ const registry = new TypeRegistry();
41
+ if (metadataVer) {
42
+ return await getWsData(endpoint, 'state_call', ['Metadata_metadata_at_version', u8aToHex(registry.createType('u32', metadataVer).toU8a())]);
43
+ }
44
+ else {
45
+ return await getWsData(endpoint, 'state_getMetadata');
46
+ }
47
+ }
48
+ export async function getRpcMethodsViaWs(endpoint) {
49
+ const result = await getWsData(endpoint, 'rpc_methods');
50
+ return result.methods;
51
+ }
52
+ export async function getRuntimeVersionViaWs(endpoint) {
53
+ const result = await getWsData(endpoint, 'state_getRuntimeVersion');
54
+ return result.apis;
55
+ }
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env node
2
- // Copyright 2017-2025 @polkadot/typegen authors & contributors
3
- // SPDX-License-Identifier: Apache-2.0
4
-
5
- import { main } from '@pezkuwi/typegen/extractChain';
6
-
7
- main();
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env node
2
- // Copyright 2017-2025 @polkadot/typegen authors & contributors
3
- // SPDX-License-Identifier: Apache-2.0
4
-
5
- import { main } from '@pezkuwi/typegen/fromChain';
6
-
7
- main();
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env node
2
- // Copyright 2017-2025 @polkadot/typegen authors & contributors
3
- // SPDX-License-Identifier: Apache-2.0
4
-
5
- import { main } from '@pezkuwi/typegen/fromDefs';
6
-
7
- main();
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env node
2
- // Copyright 2017-2025 @polkadot/typegen authors & contributors
3
- // SPDX-License-Identifier: Apache-2.0
4
-
5
- import { main } from '@pezkuwi/typegen/interfacesTs';
6
-
7
- main();
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env node
2
- // Copyright 2017-2025 @polkadot/typegen authors & contributors
3
- // SPDX-License-Identifier: Apache-2.0
4
-
5
- import { main } from '@pezkuwi/typegen/metadataMd';
6
-
7
- main();
package/src/augment.ts DELETED
@@ -1,5 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/typegen authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import '@pezkuwi/api-augment';
5
- import '@pezkuwi/rpc-augment';
package/src/bundle.ts DELETED
@@ -1,5 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/typegen authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- export { packageInfo } from './packageInfo.js';
5
- export { formatType } from './util/formatting.js';
@@ -1,54 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/typegen authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- // Connects to the local chain and outputs a re-usable calls-only chain definition in the form
5
- // export default { chain: 'Development', genesisHash: '0x27b6d5e0f4fdce1c4d20b82406f193acacce0c19e0d2c0e7ca47725c2572a06a', ss58Format: 42, tokenDecimals: 0, tokenSymbol: 'UNIT'; metaCalls: 'bWV0...4AAA==' };
6
-
7
- import process from 'node:process';
8
- import yargs from 'yargs';
9
- import { hideBin } from 'yargs/helpers';
10
-
11
- import { ApiPromise, WsProvider } from '@pezkuwi/api';
12
-
13
- /** @internal */
14
- async function run (ws: string): Promise<void> {
15
- const provider = new WsProvider(ws);
16
- const api = await ApiPromise.create({ provider, throwOnConnect: true });
17
- const [chain, props] = await Promise.all([
18
- api.rpc.system.chain(),
19
- api.rpc.system.properties()
20
- ]);
21
-
22
- // output the chain info, for easy re-use
23
- console.error(`// Generated via 'yarn run chain:info ${ws}'\n\nexport default {\n chain: '${chain.toString()}',\n genesisHash: '${api.genesisHash.toHex()}',\n specVersion: ${api.runtimeVersion.specVersion.toNumber()},\n ss58Format: ${props.ss58Format.unwrapOr(42).toString()},\n tokenDecimals: ${props.tokenDecimals.unwrapOr(0).toString()},\n tokenSymbol: '${props.tokenSymbol.unwrapOr('UNIT').toString()}',\n metaCalls: '${Buffer.from(api.runtimeMetadata.asCallsOnly.toU8a()).toString('base64')}'\n};`);
24
-
25
- // show any missing types
26
- api.runtimeMetadata.getUniqTypes(false);
27
- }
28
-
29
- interface ArgV { ws: string }
30
-
31
- export function main (): void {
32
- // retrieve and parse arguments - we do this globally, since this is a single command
33
- const { ws } = yargs(hideBin(process.argv))
34
- .usage('Usage: [options]')
35
- .wrap(120)
36
- .strict()
37
- .options({
38
- ws: {
39
- default: 'ws://127.0.0.1:9944',
40
- description: 'The API endpoint to connect to, e.g. wss://kusama-rpc.polkadot.io',
41
- required: true,
42
- type: 'string'
43
- }
44
- }).argv as ArgV;
45
-
46
- run(ws)
47
- .then((): void => {
48
- process.exit(0);
49
- })
50
- .catch((error: Error) => {
51
- console.error('FATAL:', error.message);
52
- process.exit(-1);
53
- });
54
- }
package/src/fromChain.ts DELETED
@@ -1,123 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/typegen authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { Definitions, DefinitionsTypes } from '@pezkuwi/types/types';
5
- import type { HexString } from '@pezkuwi/util/types';
6
-
7
- import fs from 'node:fs';
8
- import path from 'node:path';
9
- import yargs from 'yargs';
10
- import { hideBin } from 'yargs/helpers';
11
-
12
- import { formatNumber, isHex } from '@pezkuwi/util';
13
-
14
- import { generateDefaultConsts, generateDefaultErrors, generateDefaultEvents, generateDefaultQuery, generateDefaultRpc, generateDefaultRuntime, generateDefaultTx } from './generate/index.js';
15
- import { assertDir, assertFile, getMetadataViaWs, HEADER, writeFile } from './util/index.js';
16
-
17
- async function generate (metaHex: HexString, pkg: string | undefined, output: string, isStrict?: boolean): Promise<void> {
18
- console.log(`Generating from metadata, ${formatNumber((metaHex.length - 2) / 2)} bytes`);
19
-
20
- const outputPath = assertDir(path.join(process.cwd(), output));
21
- let extraTypes: Record<string, any> = {};
22
- let customLookupDefinitions: Definitions = { rpc: {}, types: {} };
23
-
24
- if (pkg) {
25
- try {
26
- const defCont = await import(
27
- assertFile(path.join(outputPath, 'definitions.ts'))
28
- ) as Record<string, any>;
29
-
30
- extraTypes = {
31
- [pkg]: defCont
32
- };
33
- } catch (error) {
34
- console.error('ERROR: No custom definitions found:', (error as Error).message);
35
- }
36
- }
37
-
38
- try {
39
- const lookCont = await import(
40
- assertFile(path.join(outputPath, 'lookup.ts'))
41
- ) as { default: DefinitionsTypes };
42
-
43
- customLookupDefinitions = {
44
- rpc: {},
45
- types: lookCont.default
46
- };
47
- } catch (error) {
48
- console.error('ERROR: No lookup definitions found:', (error as Error).message);
49
- }
50
-
51
- generateDefaultConsts(path.join(outputPath, 'augment-api-consts.ts'), metaHex, extraTypes, isStrict, customLookupDefinitions);
52
- generateDefaultErrors(path.join(outputPath, 'augment-api-errors.ts'), metaHex, extraTypes, isStrict);
53
- generateDefaultEvents(path.join(outputPath, 'augment-api-events.ts'), metaHex, extraTypes, isStrict, customLookupDefinitions);
54
- generateDefaultQuery(path.join(outputPath, 'augment-api-query.ts'), metaHex, extraTypes, isStrict, customLookupDefinitions);
55
- generateDefaultRpc(path.join(outputPath, 'augment-api-rpc.ts'), extraTypes);
56
- generateDefaultRuntime(path.join(outputPath, 'augment-api-runtime.ts'), metaHex, extraTypes, isStrict, customLookupDefinitions);
57
- generateDefaultTx(path.join(outputPath, 'augment-api-tx.ts'), metaHex, extraTypes, isStrict, customLookupDefinitions);
58
-
59
- writeFile(path.join(outputPath, 'augment-api.ts'), (): string =>
60
- [
61
- HEADER('chain'),
62
- ...[
63
- ...['consts', 'errors', 'events', 'query', 'tx', 'rpc', 'runtime']
64
- .filter((key) => !!key)
65
- .map((key) => `./augment-api-${key}.js`)
66
- ].map((path) => `import '${path}';\n`)
67
- ].join('')
68
- );
69
-
70
- process.exit(0);
71
- }
72
-
73
- interface ArgV { endpoint: string; output: string; package?: string; strict?: boolean }
74
-
75
- async function mainPromise (): Promise<void> {
76
- const { endpoint, output, package: pkg, strict: isStrict } = yargs(hideBin(process.argv)).strict().options({
77
- endpoint: {
78
- description: 'The endpoint to connect to (e.g. wss://kusama-rpc.polkadot.io) or relative path to a file containing the JSON output of an RPC state_getMetadata call',
79
- required: true,
80
- type: 'string'
81
- },
82
- output: {
83
- description: 'The target directory to write the data to',
84
- required: true,
85
- type: 'string'
86
- },
87
- package: {
88
- description: 'Optional package in output location (for extra definitions)',
89
- type: 'string'
90
- },
91
- strict: {
92
- description: 'Turns on strict mode, no output of catch-all generic versions',
93
- type: 'boolean'
94
- }
95
- }).argv as ArgV;
96
-
97
- let metaHex: HexString;
98
-
99
- if (endpoint.startsWith('wss://') || endpoint.startsWith('ws://')) {
100
- metaHex = await getMetadataViaWs(endpoint);
101
- } else {
102
- metaHex = (
103
- JSON.parse(
104
- fs.readFileSync(assertFile(path.join(process.cwd(), endpoint)), 'utf-8')
105
- ) as { result: HexString }
106
- ).result;
107
-
108
- if (!isHex(metaHex)) {
109
- throw new Error('Invalid metadata file');
110
- }
111
- }
112
-
113
- await generate(metaHex, pkg, output, isStrict);
114
- }
115
-
116
- export function main (): void {
117
- mainPromise().catch((error) => {
118
- console.error();
119
- console.error(error);
120
- console.error();
121
- process.exit(1);
122
- });
123
- }
package/src/fromDefs.ts DELETED
@@ -1,106 +0,0 @@
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
- import fs from 'node:fs';
7
- import path from 'node:path';
8
- import yargs from 'yargs';
9
- import { hideBin } from 'yargs/helpers';
10
-
11
- import * as substrateDefs from '@pezkuwi/types/interfaces/definitions';
12
- import { isHex } from '@pezkuwi/util';
13
-
14
- import { generateDefaultLookup } from './generate/index.js';
15
- import { generateInterfaceTypes } from './generate/interfaceRegistry.js';
16
- import { generateTsDef } from './generate/tsDef.js';
17
- import { assertDir, assertFile, getMetadataViaWs } from './util/index.js';
18
-
19
- interface ArgV { input: string; package: string; endpoint?: string; }
20
-
21
- async function mainPromise (): Promise<void> {
22
- const { endpoint, input, package: pkg } = yargs(hideBin(process.argv)).strict().options({
23
- endpoint: {
24
- description: 'The endpoint to connect to (e.g. wss://kusama-rpc.polkadot.io) or relative path to a file containing the JSON output of an RPC state_getMetadata call',
25
- type: 'string'
26
- },
27
- input: {
28
- description: 'The directory to use for the user definitions',
29
- required: true,
30
- type: 'string'
31
- },
32
- package: {
33
- description: 'The package name & path to use for the user types',
34
- required: true,
35
- type: 'string'
36
- }
37
- }).argv as ArgV;
38
-
39
- const inputPath = assertDir(path.join(process.cwd(), input));
40
- let userDefs: Record<string, any> = {};
41
-
42
- try {
43
- const defCont = await import(
44
- assertFile(path.join(inputPath, 'definitions.ts'))
45
- ) as Record<string, any>;
46
-
47
- userDefs = defCont;
48
- } catch (error) {
49
- console.error('ERROR: Unable to load user definitions:', (error as Error).message);
50
- }
51
-
52
- const userKeys = Object.keys(userDefs);
53
- const filteredBase = Object
54
- .entries(substrateDefs as Record<string, unknown>)
55
- .filter(([key]) => {
56
- if (userKeys.includes(key)) {
57
- console.warn(`Override found for ${key} in user types, ignoring in @polkadot/types`);
58
-
59
- return false;
60
- }
61
-
62
- return true;
63
- })
64
- .reduce((defs: Record<string, any>, [key, value]) => {
65
- defs[key] = value;
66
-
67
- return defs;
68
- }, {});
69
-
70
- const allDefs = {
71
- '@pezkuwi/types/interfaces': filteredBase,
72
- [pkg]: userDefs
73
- };
74
-
75
- generateTsDef(allDefs, inputPath, pkg);
76
- generateInterfaceTypes(allDefs, path.join(inputPath, 'augment-types.ts'));
77
-
78
- if (endpoint) {
79
- let metaHex: HexString;
80
-
81
- if (endpoint.startsWith('wss://') || endpoint.startsWith('ws://')) {
82
- metaHex = await getMetadataViaWs(endpoint);
83
- } else {
84
- metaHex = (
85
- JSON.parse(
86
- fs.readFileSync(assertFile(path.join(process.cwd(), endpoint)), 'utf-8')
87
- ) as { result: HexString }
88
- ).result;
89
-
90
- if (!isHex(metaHex)) {
91
- throw new Error('Invalid metadata file');
92
- }
93
- }
94
-
95
- generateDefaultLookup(inputPath, metaHex);
96
- }
97
- }
98
-
99
- export function main (): void {
100
- mainPromise().catch((error) => {
101
- console.error();
102
- console.error(error);
103
- console.error();
104
- process.exit(1);
105
- });
106
- }