@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.
- package/LICENSE +201 -0
- package/augment.js +2 -0
- package/bundle.js +2 -0
- package/cjs/augment.d.ts +2 -0
- package/cjs/augment.js +4 -0
- package/cjs/bundle.d.ts +2 -0
- package/cjs/bundle.js +7 -0
- package/cjs/extractChain.js +44 -0
- package/cjs/fromChain.js +95 -0
- package/cjs/fromDefs.js +82 -0
- package/cjs/generate/consts.js +91 -0
- package/cjs/generate/errors.js +59 -0
- package/cjs/generate/events.js +139 -0
- package/cjs/generate/index.js +23 -0
- package/cjs/generate/interfaceRegistry.js +64 -0
- package/cjs/generate/lookup.js +240 -0
- package/cjs/generate/query.js +140 -0
- package/cjs/generate/rpc.js +115 -0
- package/cjs/generate/runtime.js +233 -0
- package/{build → cjs}/generate/tsDef.d.ts +1 -1
- package/cjs/generate/tsDef.js +254 -0
- package/cjs/generate/tx.js +121 -0
- package/cjs/generate/types.js +16 -0
- package/cjs/index.js +5 -0
- package/cjs/interfacesTs.js +28 -0
- package/cjs/metadataMd.js +652 -0
- package/cjs/package.json +3 -0
- package/cjs/packageDetect.js +8 -0
- package/cjs/packageInfo.js +4 -0
- package/cjs/util/assert.js +15 -0
- package/cjs/util/derived.js +128 -0
- package/cjs/util/docs.js +10 -0
- package/cjs/util/file.js +33 -0
- package/{build → cjs}/util/formatting.d.ts +1 -1
- package/cjs/util/formatting.js +237 -0
- package/cjs/util/imports.js +126 -0
- package/{build → cjs}/util/index.d.ts +1 -0
- package/cjs/util/index.js +39 -0
- package/cjs/util/initMeta.js +22 -0
- package/cjs/util/register.js +10 -0
- package/cjs/util/wsMeta.js +60 -0
- package/extractChain.d.ts +1 -0
- package/extractChain.js +40 -0
- package/fromChain.d.ts +1 -0
- package/fromChain.js +91 -0
- package/fromDefs.d.ts +1 -0
- package/fromDefs.js +78 -0
- package/generate/consts.d.ts +5 -0
- package/generate/consts.js +87 -0
- package/generate/errors.d.ts +4 -0
- package/generate/errors.js +55 -0
- package/generate/events.d.ts +5 -0
- package/generate/events.js +135 -0
- package/{src/generate/index.ts → generate/index.d.ts} +0 -3
- package/generate/index.js +10 -0
- package/generate/interfaceRegistry.d.ts +4 -0
- package/generate/interfaceRegistry.js +59 -0
- package/generate/lookup.d.ts +4 -0
- package/generate/lookup.js +235 -0
- package/generate/query.d.ts +5 -0
- package/generate/query.js +136 -0
- package/generate/rpc.d.ts +6 -0
- package/generate/rpc.js +110 -0
- package/generate/runtime.d.ts +7 -0
- package/generate/runtime.js +228 -0
- package/generate/tsDef.d.ts +16 -0
- package/generate/tsDef.js +246 -0
- package/generate/tx.d.ts +5 -0
- package/generate/tx.js +117 -0
- package/generate/types.d.ts +12 -0
- package/generate/types.js +13 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/interfacesTs.d.ts +1 -0
- package/interfacesTs.js +24 -0
- package/metadataMd.d.ts +1 -0
- package/metadataMd.js +648 -0
- package/package.json +520 -24
- package/packageDetect.d.ts +1 -0
- package/{src/packageDetect.ts → packageDetect.js} +0 -8
- package/packageInfo.d.ts +6 -0
- package/packageInfo.js +1 -0
- package/scripts/{polkadot-types-chain-info.mjs → pezkuwi-types-chain-info.mjs} +1 -1
- package/scripts/{polkadot-types-from-chain.mjs → pezkuwi-types-from-chain.mjs} +1 -1
- package/scripts/{polkadot-types-from-defs.mjs → pezkuwi-types-from-defs.mjs} +1 -1
- package/{build/scripts/polkadot-types-internal-interfaces.mjs → scripts/pezkuwi-types-internal-interfaces.mjs} +1 -1
- package/{build/scripts/polkadot-types-internal-metadata.mjs → scripts/pezkuwi-types-internal-metadata.mjs} +1 -1
- package/{src/templates → templates}/calls.hbs +2 -2
- package/{src/templates → templates}/consts.hbs +2 -2
- package/{src/templates → templates}/errors.hbs +2 -2
- package/{src/templates → templates}/events.hbs +2 -2
- package/{src/templates → templates}/interfaceRegistry.hbs +2 -2
- package/{src/templates → templates}/lookup/types.hbs +2 -2
- package/{src/templates → templates}/query.hbs +2 -2
- package/{src/templates → templates}/rpc.hbs +2 -2
- package/{src/templates → templates}/tx.hbs +2 -2
- package/util/assert.d.ts +2 -0
- package/util/assert.js +10 -0
- package/util/derived.d.ts +4 -0
- package/util/derived.js +125 -0
- package/util/docs.d.ts +1 -0
- package/util/docs.js +6 -0
- package/util/file.d.ts +2 -0
- package/util/file.js +28 -0
- package/util/formatting.d.ts +11 -0
- package/util/formatting.js +230 -0
- package/util/imports.d.ts +23 -0
- package/util/imports.js +121 -0
- package/{src/util/index.ts → util/index.d.ts} +6 -8
- package/util/index.js +34 -0
- package/util/initMeta.d.ts +12 -0
- package/util/initMeta.js +19 -0
- package/util/register.d.ts +4 -0
- package/util/register.js +7 -0
- package/util/wsMeta.d.ts +4 -0
- package/util/wsMeta.js +55 -0
- package/build/scripts/polkadot-types-chain-info.mjs +0 -7
- package/build/scripts/polkadot-types-from-chain.mjs +0 -7
- package/build/scripts/polkadot-types-from-defs.mjs +0 -7
- package/scripts/polkadot-types-internal-interfaces.mjs +0 -7
- package/scripts/polkadot-types-internal-metadata.mjs +0 -7
- package/src/augment.ts +0 -5
- package/src/bundle.ts +0 -5
- package/src/extractChain.ts +0 -54
- package/src/fromChain.ts +0 -123
- package/src/fromDefs.ts +0 -106
- package/src/generate/consts.ts +0 -112
- package/src/generate/errors.ts +0 -75
- package/src/generate/events.ts +0 -165
- package/src/generate/interfaceRegistry.ts +0 -85
- package/src/generate/lookup.ts +0 -294
- package/src/generate/query.ts +0 -169
- package/src/generate/rpc.ts +0 -158
- package/src/generate/runtime.ts +0 -284
- package/src/generate/tsDef.ts +0 -321
- package/src/generate/tx.ts +0 -152
- package/src/generate/types.ts +0 -26
- package/src/index.ts +0 -6
- package/src/interfacesTs.ts +0 -35
- package/src/metadataMd.ts +0 -844
- package/src/packageInfo.ts +0 -6
- package/src/util/assert.ts +0 -18
- package/src/util/derived.spec.ts +0 -58
- package/src/util/derived.ts +0 -133
- package/src/util/docs.ts +0 -13
- package/src/util/file.ts +0 -42
- package/src/util/formatting.spec.ts +0 -30
- package/src/util/formatting.ts +0 -295
- package/src/util/imports.ts +0 -164
- package/src/util/initMeta.ts +0 -37
- package/src/util/register.ts +0 -12
- package/src/util/wsMeta.ts +0 -70
- package/tsconfig.build.json +0 -28
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.scripts.json +0 -19
- package/tsconfig.spec.json +0 -17
- /package/{build/augment.d.ts → augment.d.ts} +0 -0
- /package/{build/bundle.d.ts → bundle.d.ts} +0 -0
- /package/{build → cjs}/extractChain.d.ts +0 -0
- /package/{build → cjs}/fromChain.d.ts +0 -0
- /package/{build → cjs}/fromDefs.d.ts +0 -0
- /package/{build → cjs}/generate/consts.d.ts +0 -0
- /package/{build → cjs}/generate/errors.d.ts +0 -0
- /package/{build → cjs}/generate/events.d.ts +0 -0
- /package/{build → cjs}/generate/index.d.ts +0 -0
- /package/{build → cjs}/generate/interfaceRegistry.d.ts +0 -0
- /package/{build → cjs}/generate/lookup.d.ts +0 -0
- /package/{build → cjs}/generate/query.d.ts +0 -0
- /package/{build → cjs}/generate/rpc.d.ts +0 -0
- /package/{build → cjs}/generate/runtime.d.ts +0 -0
- /package/{build → cjs}/generate/tx.d.ts +0 -0
- /package/{build → cjs}/generate/types.d.ts +0 -0
- /package/{build → cjs}/index.d.ts +0 -0
- /package/{build → cjs}/interfacesTs.d.ts +0 -0
- /package/{build → cjs}/metadataMd.d.ts +0 -0
- /package/{build → cjs}/packageDetect.d.ts +0 -0
- /package/{build → cjs}/packageInfo.d.ts +0 -0
- /package/{build → cjs}/util/assert.d.ts +0 -0
- /package/{build → cjs}/util/derived.d.ts +0 -0
- /package/{build → cjs}/util/docs.d.ts +0 -0
- /package/{build → cjs}/util/file.d.ts +0 -0
- /package/{build → cjs}/util/imports.d.ts +0 -0
- /package/{build → cjs}/util/initMeta.d.ts +0 -0
- /package/{build → cjs}/util/register.d.ts +0 -0
- /package/{build → cjs}/util/wsMeta.d.ts +0 -0
- /package/{src/templates → templates}/docs.hbs +0 -0
- /package/{src/templates → templates}/header.hbs +0 -0
- /package/{src/templates → templates}/lookup/defs-named.hbs +0 -0
- /package/{src/templates → templates}/lookup/defs.hbs +0 -0
- /package/{src/templates → templates}/lookup/index.hbs +0 -0
- /package/{src/templates → templates}/tsDef/index.hbs +0 -0
- /package/{src/templates → templates}/tsDef/moduleTypes.hbs +0 -0
- /package/{src/templates → templates}/tsDef/types.hbs +0 -0
package/src/generate/consts.ts
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @polkadot/typegen authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import type { Metadata } from '@pezkuwi/types/metadata/Metadata';
|
|
5
|
-
import type { Definitions } from '@pezkuwi/types/types';
|
|
6
|
-
import type { HexString } from '@pezkuwi/util/types';
|
|
7
|
-
|
|
8
|
-
import Handlebars from 'handlebars';
|
|
9
|
-
|
|
10
|
-
import * as defaultDefs from '@pezkuwi/types/interfaces/definitions';
|
|
11
|
-
import lookupDefinitions from '@pezkuwi/types-augment/lookup/definitions';
|
|
12
|
-
import { stringCamelCase } from '@pezkuwi/util';
|
|
13
|
-
|
|
14
|
-
import { compareName, createImports, formatType, initMeta, readTemplate, setImports, writeFile } from '../util/index.js';
|
|
15
|
-
import { ignoreUnusedLookups } from './lookup.js';
|
|
16
|
-
import { type ExtraTypes, getDeprecationNotice } from './types.js';
|
|
17
|
-
|
|
18
|
-
const generateForMetaTemplate = Handlebars.compile(readTemplate('consts'));
|
|
19
|
-
|
|
20
|
-
/** @internal */
|
|
21
|
-
function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes, isStrict: boolean, customLookupDefinitions?: Definitions): void {
|
|
22
|
-
writeFile(dest, (): string => {
|
|
23
|
-
const allTypes = {
|
|
24
|
-
'@pezkuwi/types-augment': {
|
|
25
|
-
lookup: {
|
|
26
|
-
...lookupDefinitions,
|
|
27
|
-
...customLookupDefinitions
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
'@pezkuwi/types/interfaces': defaultDefs,
|
|
31
|
-
...extraTypes
|
|
32
|
-
};
|
|
33
|
-
const imports = createImports(allTypes);
|
|
34
|
-
const allDefs = Object.entries(allTypes).reduce((defs, [path, obj]) => {
|
|
35
|
-
return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [`${path}/${key}`]: value }), defs);
|
|
36
|
-
}, {});
|
|
37
|
-
const { lookup, pallets, registry } = meta.asLatest;
|
|
38
|
-
const usedTypes = new Set<string>([]);
|
|
39
|
-
|
|
40
|
-
const modules = pallets
|
|
41
|
-
.filter(({ constants }) => constants.length > 0)
|
|
42
|
-
.map(({ constants, name }) => {
|
|
43
|
-
if (!isStrict) {
|
|
44
|
-
setImports(allDefs, imports, ['Codec']);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const items = constants
|
|
48
|
-
.map(({ deprecationInfo, docs, name, type }) => {
|
|
49
|
-
const typeDef = lookup.getTypeDef(type);
|
|
50
|
-
const returnType = typeDef.lookupName || formatType(registry, allDefs, typeDef, imports);
|
|
51
|
-
|
|
52
|
-
if (!deprecationInfo.isNotDeprecated) {
|
|
53
|
-
const deprecationNotice = getDeprecationNotice(deprecationInfo, stringCamelCase(name), 'Constant');
|
|
54
|
-
|
|
55
|
-
const items = docs.length
|
|
56
|
-
? ['', deprecationNotice]
|
|
57
|
-
: [deprecationNotice];
|
|
58
|
-
|
|
59
|
-
docs.push(...items.map((text) => registry.createType('Text', text)));
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Add the type to the list of used types
|
|
63
|
-
if (!(imports.primitiveTypes[returnType])) {
|
|
64
|
-
usedTypes.add(returnType);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
setImports(allDefs, imports, [returnType]);
|
|
68
|
-
|
|
69
|
-
return {
|
|
70
|
-
docs,
|
|
71
|
-
name: stringCamelCase(name),
|
|
72
|
-
type: returnType
|
|
73
|
-
};
|
|
74
|
-
})
|
|
75
|
-
.sort(compareName);
|
|
76
|
-
|
|
77
|
-
return {
|
|
78
|
-
items,
|
|
79
|
-
name: stringCamelCase(name)
|
|
80
|
-
};
|
|
81
|
-
})
|
|
82
|
-
.sort(compareName);
|
|
83
|
-
|
|
84
|
-
// filter out the unused lookup types from imports
|
|
85
|
-
ignoreUnusedLookups([...usedTypes], imports);
|
|
86
|
-
|
|
87
|
-
return generateForMetaTemplate({
|
|
88
|
-
headerType: 'chain',
|
|
89
|
-
imports,
|
|
90
|
-
isStrict,
|
|
91
|
-
modules,
|
|
92
|
-
types: [
|
|
93
|
-
...Object.keys(imports.localTypes).sort().map<{ file: string; types: string[] }>((packagePath) => ({
|
|
94
|
-
file: packagePath.replace('@pezkuwi/types-augment', '@pezkuwi/types'),
|
|
95
|
-
types: Object.keys(imports.localTypes[packagePath])
|
|
96
|
-
})),
|
|
97
|
-
{
|
|
98
|
-
file: '@pezkuwi/api-base/types',
|
|
99
|
-
types: ['ApiTypes', 'AugmentedConst']
|
|
100
|
-
}
|
|
101
|
-
]
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Call `generateForMeta()` with current static metadata
|
|
107
|
-
/** @internal */
|
|
108
|
-
export function generateDefaultConsts (dest: string, data: HexString, extraTypes: ExtraTypes = {}, isStrict = false, customLookupDefinitions?: Definitions): void {
|
|
109
|
-
const { metadata } = initMeta(data, extraTypes);
|
|
110
|
-
|
|
111
|
-
return generateForMeta(metadata, dest, extraTypes, isStrict, customLookupDefinitions);
|
|
112
|
-
}
|
package/src/generate/errors.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
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 { HexString } from '@pezkuwi/util/types';
|
|
7
|
-
|
|
8
|
-
import Handlebars from 'handlebars';
|
|
9
|
-
|
|
10
|
-
import { stringCamelCase } from '@pezkuwi/util';
|
|
11
|
-
|
|
12
|
-
import { compareName, createImports, initMeta, readTemplate, writeFile } from '../util/index.js';
|
|
13
|
-
import { type ExtraTypes, getDeprecationNotice } from './types.js';
|
|
14
|
-
|
|
15
|
-
const generateForMetaTemplate = Handlebars.compile(readTemplate('errors'));
|
|
16
|
-
|
|
17
|
-
/** @internal */
|
|
18
|
-
function generateForMeta (meta: Metadata, dest: string, isStrict: boolean): void {
|
|
19
|
-
writeFile(dest, (): string => {
|
|
20
|
-
const imports = createImports({});
|
|
21
|
-
const { lookup, pallets } = meta.asLatest;
|
|
22
|
-
const modules = pallets
|
|
23
|
-
.filter(({ errors }) => errors.isSome)
|
|
24
|
-
.map((data) => {
|
|
25
|
-
const name = data.name;
|
|
26
|
-
const errors = data.errors.unwrap();
|
|
27
|
-
const deprecationInfo = errors.deprecationInfo.toJSON();
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
items: lookup.getSiType(errors.type).def.asVariant.variants
|
|
31
|
-
.map(({ docs, index, name }) => {
|
|
32
|
-
const rawStatus = deprecationInfo?.[index.toNumber()];
|
|
33
|
-
|
|
34
|
-
if (rawStatus) {
|
|
35
|
-
const deprecationVariantInfo: VariantDeprecationInfoV16 = meta.registry.createTypeUnsafe('VariantDeprecationInfoV16', [rawStatus]);
|
|
36
|
-
|
|
37
|
-
const deprecationNotice = getDeprecationNotice(deprecationVariantInfo, name.toString());
|
|
38
|
-
const notice = docs.length ? ['', deprecationNotice] : [deprecationNotice];
|
|
39
|
-
|
|
40
|
-
docs.push(...notice.map((text) => meta.registry.createType('Text', text)));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return {
|
|
44
|
-
docs,
|
|
45
|
-
name: name.toString()
|
|
46
|
-
};
|
|
47
|
-
})
|
|
48
|
-
.sort(compareName),
|
|
49
|
-
name: stringCamelCase(name)
|
|
50
|
-
};
|
|
51
|
-
})
|
|
52
|
-
.sort(compareName);
|
|
53
|
-
|
|
54
|
-
return generateForMetaTemplate({
|
|
55
|
-
headerType: 'chain',
|
|
56
|
-
imports,
|
|
57
|
-
isStrict,
|
|
58
|
-
modules,
|
|
59
|
-
types: [
|
|
60
|
-
{
|
|
61
|
-
file: '@pezkuwi/api-base/types',
|
|
62
|
-
types: ['ApiTypes', 'AugmentedError']
|
|
63
|
-
}
|
|
64
|
-
]
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Call `generateForMeta()` with current static metadata
|
|
70
|
-
/** @internal */
|
|
71
|
-
export function generateDefaultErrors (dest: string, data: HexString, extraTypes: ExtraTypes = {}, isStrict = false): void {
|
|
72
|
-
const { metadata } = initMeta(data, extraTypes);
|
|
73
|
-
|
|
74
|
-
return generateForMeta(metadata, dest, isStrict);
|
|
75
|
-
}
|
package/src/generate/events.ts
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
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 { Definitions } from '@pezkuwi/types/types';
|
|
7
|
-
import type { HexString } from '@pezkuwi/util/types';
|
|
8
|
-
|
|
9
|
-
import Handlebars from 'handlebars';
|
|
10
|
-
|
|
11
|
-
import * as defaultDefs from '@pezkuwi/types/interfaces/definitions';
|
|
12
|
-
import lookupDefinitions from '@pezkuwi/types-augment/lookup/definitions';
|
|
13
|
-
import { stringCamelCase } from '@pezkuwi/util';
|
|
14
|
-
|
|
15
|
-
import { compareName, createImports, formatType, initMeta, readTemplate, setImports, writeFile } from '../util/index.js';
|
|
16
|
-
import { ignoreUnusedLookups } from './lookup.js';
|
|
17
|
-
import { type ExtraTypes, getDeprecationNotice } from './types.js';
|
|
18
|
-
|
|
19
|
-
const generateForMetaTemplate = Handlebars.compile(readTemplate('events'));
|
|
20
|
-
|
|
21
|
-
// For babel itself we need some extra aliasing
|
|
22
|
-
// Also avoid reserved words to prevent generating invalid TS
|
|
23
|
-
// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#reserved_words
|
|
24
|
-
const ALIAS = [
|
|
25
|
-
'symbol',
|
|
26
|
-
'break',
|
|
27
|
-
'case',
|
|
28
|
-
'catch',
|
|
29
|
-
'class',
|
|
30
|
-
'const',
|
|
31
|
-
'continue',
|
|
32
|
-
'debugger',
|
|
33
|
-
'default',
|
|
34
|
-
'delete',
|
|
35
|
-
'do',
|
|
36
|
-
'else',
|
|
37
|
-
'export',
|
|
38
|
-
'extends',
|
|
39
|
-
'false',
|
|
40
|
-
'finally',
|
|
41
|
-
'for',
|
|
42
|
-
'function',
|
|
43
|
-
'if',
|
|
44
|
-
'import',
|
|
45
|
-
'in',
|
|
46
|
-
'instanceof',
|
|
47
|
-
'new',
|
|
48
|
-
'null',
|
|
49
|
-
'return',
|
|
50
|
-
'static',
|
|
51
|
-
'super',
|
|
52
|
-
'switch',
|
|
53
|
-
'this',
|
|
54
|
-
'throw',
|
|
55
|
-
'true',
|
|
56
|
-
'try',
|
|
57
|
-
'typeof',
|
|
58
|
-
'var',
|
|
59
|
-
'void',
|
|
60
|
-
'while',
|
|
61
|
-
'with',
|
|
62
|
-
'yield'
|
|
63
|
-
];
|
|
64
|
-
|
|
65
|
-
/** @internal */
|
|
66
|
-
function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes, isStrict: boolean, customLookupDefinitions?: Definitions): void {
|
|
67
|
-
writeFile(dest, (): string => {
|
|
68
|
-
const allTypes = {
|
|
69
|
-
'@pezkuwi/types-augment': {
|
|
70
|
-
lookup: {
|
|
71
|
-
...lookupDefinitions,
|
|
72
|
-
...customLookupDefinitions
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
'@pezkuwi/types/interfaces': defaultDefs,
|
|
76
|
-
...extraTypes
|
|
77
|
-
};
|
|
78
|
-
const imports = createImports(allTypes);
|
|
79
|
-
const allDefs = Object.entries(allTypes).reduce((defs, [path, obj]) => {
|
|
80
|
-
return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [`${path}/${key}`]: value }), defs);
|
|
81
|
-
}, {});
|
|
82
|
-
const { lookup, pallets, registry } = meta.asLatest;
|
|
83
|
-
const usedTypes = new Set<string>([]);
|
|
84
|
-
const modules = pallets
|
|
85
|
-
.filter(({ events }) => events.isSome)
|
|
86
|
-
.map((data) => {
|
|
87
|
-
const name = data.name;
|
|
88
|
-
const events = data.events.unwrap();
|
|
89
|
-
const deprecationInfo = events.deprecationInfo.toJSON();
|
|
90
|
-
|
|
91
|
-
return {
|
|
92
|
-
items: lookup.getSiType(events.type).def.asVariant.variants
|
|
93
|
-
.map(({ docs, fields, index, name }) => {
|
|
94
|
-
const rawStatus = deprecationInfo?.[index.toNumber()];
|
|
95
|
-
|
|
96
|
-
if (rawStatus) {
|
|
97
|
-
const deprecationVariantInfo: VariantDeprecationInfoV16 = meta.registry.createTypeUnsafe('VariantDeprecationInfoV16', [rawStatus]);
|
|
98
|
-
const deprecationNotice = getDeprecationNotice(deprecationVariantInfo, name.toString());
|
|
99
|
-
const notice = docs.length ? ['', deprecationNotice] : [deprecationNotice];
|
|
100
|
-
|
|
101
|
-
docs.push(...notice.map((text) => meta.registry.createType('Text', text)));
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const args = fields
|
|
105
|
-
.map(({ type }) => lookup.getTypeDef(type))
|
|
106
|
-
.map((typeDef) => {
|
|
107
|
-
const arg = typeDef.lookupName || formatType(registry, allDefs, typeDef, imports);
|
|
108
|
-
|
|
109
|
-
// Add the type to the list of used types
|
|
110
|
-
if (!(imports.primitiveTypes[arg])) {
|
|
111
|
-
usedTypes.add(arg);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return arg;
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
const names = fields
|
|
118
|
-
.map(({ name }) => registry.lookup.sanitizeField(name)[0])
|
|
119
|
-
.filter((n): n is string => !!n);
|
|
120
|
-
|
|
121
|
-
setImports(allDefs, imports, args);
|
|
122
|
-
|
|
123
|
-
return {
|
|
124
|
-
docs,
|
|
125
|
-
name: name.toString(),
|
|
126
|
-
type: names.length !== 0 && names.length === args.length
|
|
127
|
-
? `[${names.map((n, i) => `${ALIAS.includes(n) ? `${n}_` : n}: ${args[i]}`).join(', ')}], { ${names.map((n, i) => `${n}: ${args[i]}`).join(', ')} }`
|
|
128
|
-
: `[${args.join(', ')}]`
|
|
129
|
-
};
|
|
130
|
-
})
|
|
131
|
-
.sort(compareName),
|
|
132
|
-
name: stringCamelCase(name)
|
|
133
|
-
};
|
|
134
|
-
})
|
|
135
|
-
.sort(compareName);
|
|
136
|
-
|
|
137
|
-
// filter out the unused lookup types from imports
|
|
138
|
-
ignoreUnusedLookups([...usedTypes], imports);
|
|
139
|
-
|
|
140
|
-
return generateForMetaTemplate({
|
|
141
|
-
headerType: 'chain',
|
|
142
|
-
imports,
|
|
143
|
-
isStrict,
|
|
144
|
-
modules,
|
|
145
|
-
types: [
|
|
146
|
-
...Object.keys(imports.localTypes).sort().map((packagePath): { file: string; types: string[] } => ({
|
|
147
|
-
file: packagePath.replace('@pezkuwi/types-augment', '@pezkuwi/types'),
|
|
148
|
-
types: Object.keys(imports.localTypes[packagePath])
|
|
149
|
-
})),
|
|
150
|
-
{
|
|
151
|
-
file: '@pezkuwi/api-base/types',
|
|
152
|
-
types: ['ApiTypes', 'AugmentedEvent']
|
|
153
|
-
}
|
|
154
|
-
]
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// Call `generateForMeta()` with current static metadata
|
|
160
|
-
/** @internal */
|
|
161
|
-
export function generateDefaultEvents (dest: string, data: HexString, extraTypes: ExtraTypes = {}, isStrict = false, customLookupDefinitions?: Definitions): void {
|
|
162
|
-
const { metadata } = initMeta(data, extraTypes);
|
|
163
|
-
|
|
164
|
-
return generateForMeta(metadata, dest, extraTypes, isStrict, customLookupDefinitions);
|
|
165
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @polkadot/typegen authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import type { ModuleTypes } from '../util/imports.js';
|
|
5
|
-
|
|
6
|
-
import Handlebars from 'handlebars';
|
|
7
|
-
|
|
8
|
-
import { Json, Raw } from '@pezkuwi/types/codec';
|
|
9
|
-
import { TypeRegistry } from '@pezkuwi/types/create';
|
|
10
|
-
import * as defaultDefinitions from '@pezkuwi/types/interfaces/definitions';
|
|
11
|
-
import * as defaultPrimitives from '@pezkuwi/types/primitive';
|
|
12
|
-
|
|
13
|
-
import { createImports, readTemplate, setImports, writeFile } from '../util/index.js';
|
|
14
|
-
|
|
15
|
-
const primitiveClasses = {
|
|
16
|
-
...defaultPrimitives,
|
|
17
|
-
Json,
|
|
18
|
-
Raw
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const generateInterfaceTypesTemplate = Handlebars.compile(readTemplate('interfaceRegistry'));
|
|
22
|
-
|
|
23
|
-
/** @internal */
|
|
24
|
-
export function generateInterfaceTypes (importDefinitions: Record<string, Record<string, ModuleTypes>>, dest: string): void {
|
|
25
|
-
const registry = new TypeRegistry();
|
|
26
|
-
|
|
27
|
-
writeFile(dest, (): string => {
|
|
28
|
-
Object.entries(importDefinitions).reduce((acc, def) => Object.assign(acc, def), {});
|
|
29
|
-
|
|
30
|
-
const imports = createImports(importDefinitions);
|
|
31
|
-
const definitions = imports.definitions;
|
|
32
|
-
const items: string[] = [];
|
|
33
|
-
|
|
34
|
-
// first we create imports for our known classes from the API
|
|
35
|
-
Object
|
|
36
|
-
.keys(primitiveClasses)
|
|
37
|
-
.filter((name) => !name.includes('Generic'))
|
|
38
|
-
.forEach((primitiveName): void => {
|
|
39
|
-
setImports(definitions, imports, [primitiveName]);
|
|
40
|
-
|
|
41
|
-
items.push(primitiveName);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
const existingTypes: Record<string, boolean> = {};
|
|
45
|
-
|
|
46
|
-
// ensure we have everything registered since we will get the definition
|
|
47
|
-
// form the available types (so any unknown should show after this)
|
|
48
|
-
Object.values(definitions).forEach(({ types }) => {
|
|
49
|
-
registry.register(types as Record<string, string>);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
// create imports for everything that we have available
|
|
53
|
-
Object.values(definitions).forEach(({ types }) => {
|
|
54
|
-
setImports(definitions, imports, Object.keys(types));
|
|
55
|
-
|
|
56
|
-
const uniqueTypes = Object.keys(types).filter((type) => !existingTypes[type]);
|
|
57
|
-
|
|
58
|
-
uniqueTypes.forEach((type): void => {
|
|
59
|
-
existingTypes[type] = true;
|
|
60
|
-
|
|
61
|
-
items.push(type);
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
return generateInterfaceTypesTemplate({
|
|
66
|
-
headerType: 'defs',
|
|
67
|
-
imports,
|
|
68
|
-
items: items.sort((a, b) => a.localeCompare(b)),
|
|
69
|
-
types: [
|
|
70
|
-
...Object.keys(imports.localTypes).sort().map((packagePath): { file: string; types: string[] } => ({
|
|
71
|
-
file: packagePath,
|
|
72
|
-
types: Object.keys(imports.localTypes[packagePath])
|
|
73
|
-
}))
|
|
74
|
-
]
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Generate `packages/types/src/interfaceRegistry.ts`, the registry of all interfaces
|
|
80
|
-
export function generateDefaultInterface (): void {
|
|
81
|
-
generateInterfaceTypes(
|
|
82
|
-
{ '@pezkuwi/types/interfaces': defaultDefinitions },
|
|
83
|
-
'packages/types-augment/src/registry/interfaces.ts'
|
|
84
|
-
);
|
|
85
|
-
}
|