@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
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @pezkuwi/typegen
2
+
3
+ A collection of type generation scripts, allowing the input of metadata and definitions for the creation of TS outputs.
@@ -0,0 +1,2 @@
1
+ import '@pezkuwi/api-augment';
2
+ import '@pezkuwi/rpc-augment';
@@ -0,0 +1,2 @@
1
+ export { packageInfo } from './packageInfo.js';
2
+ export { formatType } from './util/formatting.js';
@@ -0,0 +1 @@
1
+ export declare function main(): void;
@@ -0,0 +1 @@
1
+ export declare function main(): void;
@@ -0,0 +1 @@
1
+ export declare function main(): void;
@@ -0,0 +1,5 @@
1
+ import type { Definitions } from '@pezkuwi/types/types';
2
+ import type { HexString } from '@pezkuwi/util/types';
3
+ import { type ExtraTypes } from './types.js';
4
+ /** @internal */
5
+ export declare function generateDefaultConsts(dest: string, data: HexString, extraTypes?: ExtraTypes, isStrict?: boolean, customLookupDefinitions?: Definitions): void;
@@ -0,0 +1,4 @@
1
+ import type { HexString } from '@pezkuwi/util/types';
2
+ import { type ExtraTypes } from './types.js';
3
+ /** @internal */
4
+ export declare function generateDefaultErrors(dest: string, data: HexString, extraTypes?: ExtraTypes, isStrict?: boolean): void;
@@ -0,0 +1,5 @@
1
+ import type { Definitions } from '@pezkuwi/types/types';
2
+ import type { HexString } from '@pezkuwi/util/types';
3
+ import { type ExtraTypes } from './types.js';
4
+ /** @internal */
5
+ export declare function generateDefaultEvents(dest: string, data: HexString, extraTypes?: ExtraTypes, isStrict?: boolean, customLookupDefinitions?: Definitions): void;
@@ -0,0 +1,10 @@
1
+ export { generateDefaultConsts } from './consts.js';
2
+ export { generateDefaultErrors } from './errors.js';
3
+ export { generateDefaultEvents } from './events.js';
4
+ export { generateDefaultInterface } from './interfaceRegistry.js';
5
+ export { generateDefaultLookup } from './lookup.js';
6
+ export { generateDefaultQuery } from './query.js';
7
+ export { generateDefaultRpc } from './rpc.js';
8
+ export { generateDefaultRuntime } from './runtime.js';
9
+ export { generateDefaultTsDef } from './tsDef.js';
10
+ export { generateDefaultTx } from './tx.js';
@@ -0,0 +1,4 @@
1
+ import type { ModuleTypes } from '../util/imports.js';
2
+ /** @internal */
3
+ export declare function generateInterfaceTypes(importDefinitions: Record<string, Record<string, ModuleTypes>>, dest: string): void;
4
+ export declare function generateDefaultInterface(): void;
@@ -0,0 +1,4 @@
1
+ import type { HexString } from '@pezkuwi/util/types';
2
+ import { type TypeImports } from '../util/index.js';
3
+ export declare function generateDefaultLookup(destDir?: string, staticData?: HexString): void;
4
+ export declare function ignoreUnusedLookups(usedTypes: string[], imports: TypeImports): void;
@@ -0,0 +1,5 @@
1
+ import type { Definitions } from '@pezkuwi/types/types';
2
+ import type { HexString } from '@pezkuwi/util/types';
3
+ import { type ExtraTypes } from './types.js';
4
+ /** @internal */
5
+ export declare function generateDefaultQuery(dest: string, data: HexString, extraTypes?: ExtraTypes, isStrict?: boolean, customLookupDefinitions?: Definitions): void;
@@ -0,0 +1,6 @@
1
+ import type { TypeRegistry } from '@pezkuwi/types/create';
2
+ import type { Definitions } from '@pezkuwi/types/types';
3
+ import type { ExtraTypes } from './types.js';
4
+ /** @internal */
5
+ export declare function generateRpcTypes(registry: TypeRegistry, importDefinitions: Record<string, Definitions>, dest: string, extraTypes: ExtraTypes): void;
6
+ export declare function generateDefaultRpc(dest?: string, extraTypes?: ExtraTypes): void;
@@ -0,0 +1,7 @@
1
+ import type { Metadata } from '@pezkuwi/types/metadata/Metadata';
2
+ import type { Definitions, Registry } from '@pezkuwi/types/types';
3
+ import type { HexString } from '@pezkuwi/util/types';
4
+ import { type ExtraTypes } from './types.js';
5
+ /** @internal */
6
+ export declare function generateCallTypes(registry: Registry, meta: Metadata, dest: string, extraTypes: ExtraTypes, isStrict: boolean, customLookupDefinitions?: Definitions): void;
7
+ export declare function generateDefaultRuntime(dest: string, data: HexString, extraTypes?: ExtraTypes, isStrict?: boolean, customLookupDefinitions?: Definitions): void;
@@ -0,0 +1,16 @@
1
+ import type { Registry } from '@pezkuwi/types/types';
2
+ import type { TypeDef } from '@pezkuwi/types-create/types';
3
+ import type { ModuleTypes } from '../util/imports.js';
4
+ import type { TypeImports } from '../util/index.js';
5
+ import { TypeDefInfo } from '@pezkuwi/types-create';
6
+ /** @internal */
7
+ export declare function createGetter(definitions: Record<string, ModuleTypes>, name: string, type: string, imports: TypeImports): string;
8
+ export declare const typeEncoders: Record<TypeDefInfo, (registry: Registry, definitions: Record<string, ModuleTypes>, def: TypeDef, imports: TypeImports) => string>;
9
+ /** @internal */
10
+ export declare function generateTsDefFor(registry: Registry, importDefinitions: Record<string, Record<string, ModuleTypes>>, defName: string, { types }: {
11
+ types: Record<string, any>;
12
+ }, outputDir: string): void;
13
+ /** @internal */
14
+ export declare function generateTsDef(importDefinitions: Record<string, Record<string, ModuleTypes>>, outputDir: string, generatingPackage: string): void;
15
+ /** @internal */
16
+ export declare function generateDefaultTsDef(): void;
@@ -0,0 +1,5 @@
1
+ import type { Definitions } from '@pezkuwi/types/types';
2
+ import type { HexString } from '@pezkuwi/util/types';
3
+ import { type ExtraTypes } from './types.js';
4
+ /** @internal */
5
+ export declare function generateDefaultTx(dest: string, data: HexString, extraTypes?: ExtraTypes, isStrict?: boolean, customLookupDefinitions?: Definitions): void;
@@ -0,0 +1,12 @@
1
+ import type { Option, Text } from '@pezkuwi/types-codec';
2
+ export type ExtraTypes = Record<string, Record<string, {
3
+ runtime?: Record<string, any>;
4
+ types: Record<string, any>;
5
+ }>>;
6
+ export declare function getDeprecationNotice<T extends {
7
+ isDeprecated: boolean;
8
+ asDeprecated: {
9
+ note: Text;
10
+ since: Option<Text>;
11
+ };
12
+ }>(deprecationInfo: T, name: string, label?: string): string;
@@ -0,0 +1,2 @@
1
+ import './packageDetect.js';
2
+ export * from './bundle.js';
@@ -0,0 +1 @@
1
+ export declare function main(): void;
@@ -0,0 +1 @@
1
+ export declare function main(): void;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ export declare const packageInfo: {
2
+ name: string;
3
+ path: string;
4
+ type: string;
5
+ version: string;
6
+ };
@@ -0,0 +1,7 @@
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();
@@ -0,0 +1,7 @@
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();
@@ -0,0 +1,7 @@
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();
@@ -0,0 +1,7 @@
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();
@@ -0,0 +1,7 @@
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();
@@ -0,0 +1,2 @@
1
+ export declare function assertDir(path: string): string;
2
+ export declare function assertFile(path: string): string;
@@ -0,0 +1,4 @@
1
+ import type { Registry } from '@pezkuwi/types/types';
2
+ import type { ModuleTypes, TypeImports } from './imports.js';
3
+ /** @internal */
4
+ export declare function getSimilarTypes(registry: Registry, definitions: Record<string, ModuleTypes>, _type: string, imports: TypeImports): string[];
@@ -0,0 +1 @@
1
+ export declare const __TYPEGEN_DUMMY_DOCS = "DUMMY_DOCS";
@@ -0,0 +1,2 @@
1
+ export declare function writeFile(dest: string, generator: () => string, noLog?: boolean): void;
2
+ export declare function readTemplate(template: string): string;
@@ -0,0 +1,11 @@
1
+ import type { AnyString, Registry } from '@pezkuwi/types/types';
2
+ import type { TypeDef } from '@pezkuwi/types-create/types';
3
+ import type { ModuleTypes, TypeImports } from './imports.js';
4
+ export declare const HEADER: (type: "chain" | "defs") => string;
5
+ /** @internal */
6
+ export declare function exportInterface(lookupIndex: number, name: string, base: string, body?: string, withShortcut?: boolean): string;
7
+ /**
8
+ * Correctly format a given type
9
+ */
10
+ /** @internal */
11
+ export declare function formatType(registry: Registry, definitions: Record<string, ModuleTypes>, type: AnyString | TypeDef, imports: TypeImports, withShortcut?: boolean): string;
@@ -0,0 +1,23 @@
1
+ export interface ModuleTypes {
2
+ types: Record<string, unknown>;
3
+ }
4
+ type TypeExist = Record<string, boolean>;
5
+ type TypeExistMap = Record<string, TypeExist>;
6
+ export interface TypeImports {
7
+ codecTypes: TypeExist;
8
+ extrinsicTypes: TypeExist;
9
+ genericTypes: TypeExist;
10
+ ignoredTypes: string[];
11
+ localTypes: TypeExistMap;
12
+ lookupTypes: TypeExistMap;
13
+ primitiveTypes: TypeExist;
14
+ metadataTypes: TypeExist;
15
+ typesTypes: TypeExist;
16
+ definitions: Record<string, ModuleTypes>;
17
+ typeToModule: Record<string, string>;
18
+ }
19
+ /** @internal */
20
+ export declare function setImports(allDefs: Record<string, ModuleTypes>, imports: TypeImports, types: (string | null | undefined)[]): void;
21
+ /** @internal */
22
+ export declare function createImports(importDefinitions: Record<string, Record<string, ModuleTypes>>, { types }?: ModuleTypes): TypeImports;
23
+ export {};
@@ -0,0 +1,15 @@
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
+ interface Cmp {
11
+ name: {
12
+ toString(): string;
13
+ };
14
+ }
15
+ export declare function compareName(a: Cmp, b: Cmp): number;
@@ -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,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,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/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "author": "Jaco Greeff <jacogr@gmail.com>",
3
+ "bugs": "https://github.com/pezkuwichain/pezkuwi-api/issues",
4
+ "description": "Type generation scripts",
5
+ "engines": {
6
+ "node": ">=18"
7
+ },
8
+ "homepage": "https://github.com/pezkuwichain/pezkuwi-api/tree/master/packages/typegen#readme",
9
+ "license": "Apache-2.0",
10
+ "name": "@pezkuwi/typegen",
11
+ "repository": {
12
+ "directory": "packages/typegen",
13
+ "type": "git",
14
+ "url": "https://github.com/pezkuwichain/pezkuwi-api.git"
15
+ },
16
+ "sideEffects": [
17
+ "./packageDetect.js",
18
+ "./packageDetect.cjs"
19
+ ],
20
+ "type": "module",
21
+ "version": "16.5.5",
22
+ "main": "index.js",
23
+ "bin": {
24
+ "polkadot-types-chain-info": "./scripts/polkadot-types-chain-info.mjs",
25
+ "polkadot-types-from-chain": "./scripts/polkadot-types-from-chain.mjs",
26
+ "polkadot-types-from-defs": "./scripts/polkadot-types-from-defs.mjs",
27
+ "polkadot-types-internal-interfaces": "./scripts/polkadot-types-internal-interfaces.mjs",
28
+ "polkadot-types-internal-metadata": "./scripts/polkadot-types-internal-metadata.mjs"
29
+ },
30
+ "dependencies": {
31
+ "@pezkuwi/api": "16.5.5",
32
+ "@pezkuwi/api-augment": "16.5.5",
33
+ "@pezkuwi/api-derive": "16.5.5",
34
+ "@pezkuwi/rpc-augment": "16.5.5",
35
+ "@pezkuwi/rpc-provider": "16.5.5",
36
+ "@pezkuwi/types": "16.5.5",
37
+ "@pezkuwi/types-augment": "16.5.5",
38
+ "@pezkuwi/types-codec": "16.5.5",
39
+ "@pezkuwi/types-create": "16.5.5",
40
+ "@pezkuwi/types-support": "16.5.5",
41
+ "@pezkuwi/util": "14.0.5",
42
+ "@pezkuwi/util-crypto": "14.0.5",
43
+ "@pezkuwi/x-ws": "14.0.5",
44
+ "comment-parser": "^1.4.1",
45
+ "handlebars": "^4.7.8",
46
+ "tslib": "^2.8.1",
47
+ "yargs": "^17.7.2"
48
+ },
49
+ "devDependencies": {
50
+ "@types/yargs": "^17.0.33"
51
+ }
52
+ }
@@ -0,0 +1,7 @@
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();
@@ -0,0 +1,7 @@
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();
@@ -0,0 +1,7 @@
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();
@@ -0,0 +1,7 @@
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();
@@ -0,0 +1,7 @@
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 ADDED
@@ -0,0 +1,5 @@
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 ADDED
@@ -0,0 +1,5 @@
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';
@@ -0,0 +1,54 @@
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
+ }
@@ -0,0 +1,123 @@
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
+ }