@pezkuwi/typegen 16.5.16 → 16.5.18
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/build/LICENSE +201 -0
- package/build/README.md +3 -0
- package/build/augment.js +2 -0
- package/build/bundle.js +2 -0
- package/build/cjs/augment.d.ts +2 -0
- package/build/cjs/augment.js +4 -0
- package/build/cjs/bundle.d.ts +2 -0
- package/build/cjs/bundle.js +7 -0
- package/build/cjs/extractChain.js +44 -0
- package/build/cjs/fromChain.js +95 -0
- package/build/cjs/fromDefs.js +82 -0
- package/build/cjs/generate/consts.d.ts +5 -0
- package/build/cjs/generate/consts.js +91 -0
- package/build/cjs/generate/errors.d.ts +4 -0
- package/build/cjs/generate/errors.js +59 -0
- package/build/cjs/generate/events.d.ts +5 -0
- package/build/cjs/generate/events.js +139 -0
- package/build/cjs/generate/index.js +23 -0
- package/build/cjs/generate/interfaceRegistry.d.ts +4 -0
- package/build/cjs/generate/interfaceRegistry.js +64 -0
- package/build/cjs/generate/lookup.d.ts +4 -0
- package/build/cjs/generate/lookup.js +240 -0
- package/build/cjs/generate/query.d.ts +5 -0
- package/build/cjs/generate/query.js +140 -0
- package/build/cjs/generate/rpc.d.ts +6 -0
- package/build/cjs/generate/rpc.js +115 -0
- package/build/cjs/generate/runtime.d.ts +7 -0
- package/build/cjs/generate/runtime.js +233 -0
- package/build/cjs/generate/tsDef.d.ts +16 -0
- package/build/cjs/generate/tsDef.js +254 -0
- package/build/cjs/generate/tx.d.ts +5 -0
- package/build/cjs/generate/tx.js +121 -0
- package/build/cjs/generate/types.d.ts +12 -0
- package/build/cjs/generate/types.js +16 -0
- package/build/cjs/index.js +5 -0
- package/build/cjs/interfacesTs.js +28 -0
- package/build/cjs/metadataMd.js +652 -0
- package/build/cjs/packageInfo.js +4 -0
- package/build/cjs/util/assert.js +15 -0
- package/build/cjs/util/derived.js +128 -0
- package/build/cjs/util/docs.js +10 -0
- package/build/cjs/util/file.js +33 -0
- package/build/cjs/util/formatting.js +237 -0
- package/build/cjs/util/imports.js +126 -0
- package/build/cjs/util/index.js +39 -0
- package/build/cjs/util/initMeta.js +22 -0
- package/build/cjs/util/register.js +10 -0
- package/build/cjs/util/wsMeta.js +60 -0
- package/build/extractChain.d.ts +1 -0
- package/build/extractChain.js +40 -0
- package/build/fromChain.d.ts +1 -0
- package/build/fromChain.js +91 -0
- package/build/fromDefs.d.ts +1 -0
- package/build/fromDefs.js +78 -0
- package/build/generate/consts.d.ts +5 -0
- package/build/generate/consts.js +87 -0
- package/build/generate/errors.d.ts +4 -0
- package/build/generate/errors.js +55 -0
- package/build/generate/events.d.ts +5 -0
- package/build/generate/events.js +135 -0
- package/build/generate/index.d.ts +10 -0
- package/build/generate/index.js +10 -0
- package/build/generate/interfaceRegistry.d.ts +4 -0
- package/build/generate/interfaceRegistry.js +59 -0
- package/build/generate/lookup.d.ts +4 -0
- package/build/generate/lookup.js +235 -0
- package/build/generate/query.d.ts +5 -0
- package/build/generate/query.js +136 -0
- package/build/generate/rpc.d.ts +6 -0
- package/build/generate/rpc.js +110 -0
- package/build/generate/runtime.d.ts +7 -0
- package/build/generate/runtime.js +228 -0
- package/build/generate/tsDef.d.ts +16 -0
- package/build/generate/tsDef.js +246 -0
- package/build/generate/tx.d.ts +5 -0
- package/build/generate/tx.js +117 -0
- package/build/generate/types.d.ts +12 -0
- package/build/generate/types.js +13 -0
- package/build/index.d.ts +2 -0
- package/build/index.js +2 -0
- package/build/interfacesTs.d.ts +1 -0
- package/build/interfacesTs.js +24 -0
- package/build/metadataMd.d.ts +1 -0
- package/build/metadataMd.js +648 -0
- package/build/package.json +548 -0
- package/build/packageDetect.d.ts +1 -0
- package/build/packageDetect.js +6 -0
- package/build/packageInfo.d.ts +6 -0
- package/build/packageInfo.js +1 -0
- package/build/scripts/pezkuwi-types-chain-info.mjs +7 -0
- package/build/scripts/pezkuwi-types-from-chain.mjs +7 -0
- package/build/scripts/pezkuwi-types-from-defs.mjs +7 -0
- package/build/scripts/pezkuwi-types-internal-interfaces.mjs +7 -0
- package/build/scripts/pezkuwi-types-internal-metadata.mjs +7 -0
- package/build/templates/calls.hbs +30 -0
- package/build/templates/consts.hbs +28 -0
- package/build/templates/docs.hbs +7 -0
- package/build/templates/errors.hbs +28 -0
- package/build/templates/events.hbs +28 -0
- package/build/templates/header.hbs +2 -0
- package/build/templates/interfaceRegistry.hbs +15 -0
- package/build/templates/lookup/defs-named.hbs +12 -0
- package/build/templates/lookup/defs.hbs +15 -0
- package/build/templates/lookup/index.hbs +3 -0
- package/build/templates/lookup/types.hbs +14 -0
- package/build/templates/query.hbs +29 -0
- package/build/templates/rpc.hbs +22 -0
- package/build/templates/tsDef/index.hbs +3 -0
- package/build/templates/tsDef/moduleTypes.hbs +10 -0
- package/build/templates/tsDef/types.hbs +7 -0
- package/build/templates/tx.hbs +30 -0
- package/build/util/assert.d.ts +2 -0
- package/build/util/assert.js +10 -0
- package/build/util/derived.d.ts +4 -0
- package/build/util/derived.js +125 -0
- package/build/util/docs.d.ts +1 -0
- package/build/util/docs.js +6 -0
- package/build/util/file.d.ts +2 -0
- package/build/util/file.js +28 -0
- package/build/util/formatting.d.ts +11 -0
- package/build/util/formatting.js +230 -0
- package/build/util/imports.d.ts +23 -0
- package/build/util/imports.js +121 -0
- package/build/util/index.d.ts +16 -0
- package/build/util/index.js +34 -0
- package/build/util/initMeta.d.ts +12 -0
- package/build/util/initMeta.js +19 -0
- package/build/util/register.d.ts +4 -0
- package/build/util/register.js +7 -0
- package/build/util/wsMeta.d.ts +4 -0
- package/build/util/wsMeta.js +55 -0
- package/build-tsc-cjs/packageDetect.js +8 -0
- package/{cjs → build-tsc-cjs}/packageInfo.js +1 -1
- package/build-tsc-esm/generate/consts.js +87 -0
- package/build-tsc-esm/generate/errors.js +55 -0
- package/build-tsc-esm/generate/events.js +135 -0
- package/build-tsc-esm/generate/interfaceRegistry.js +59 -0
- package/build-tsc-esm/generate/lookup.js +235 -0
- package/build-tsc-esm/generate/query.js +136 -0
- package/build-tsc-esm/generate/rpc.js +110 -0
- package/build-tsc-esm/generate/runtime.js +228 -0
- package/build-tsc-esm/generate/tsDef.js +246 -0
- package/build-tsc-esm/generate/tx.js +117 -0
- package/build-tsc-esm/generate/types.js +13 -0
- package/{packageInfo.js → build-tsc-esm/packageInfo.js} +1 -1
- package/package.json +27 -27
- package/src/augment.ts +5 -0
- package/src/bundle.ts +5 -0
- package/src/extractChain.ts +54 -0
- package/src/fromChain.ts +123 -0
- package/src/fromDefs.ts +106 -0
- package/src/generate/consts.ts +112 -0
- package/src/generate/errors.ts +75 -0
- package/src/generate/events.ts +165 -0
- package/src/generate/index.ts +13 -0
- package/src/generate/interfaceRegistry.ts +85 -0
- package/src/generate/lookup.ts +322 -0
- package/src/generate/query.ts +169 -0
- package/src/generate/rpc.ts +158 -0
- package/src/generate/runtime.ts +293 -0
- package/src/generate/tsDef.ts +321 -0
- package/src/generate/tx.ts +152 -0
- package/src/generate/types.ts +26 -0
- package/src/index.ts +6 -0
- package/src/interfacesTs.ts +35 -0
- package/src/metadataMd.ts +844 -0
- package/src/packageDetect.ts +14 -0
- package/src/packageInfo.ts +6 -0
- package/src/templates/calls.hbs +30 -0
- package/src/templates/consts.hbs +28 -0
- package/src/templates/docs.hbs +7 -0
- package/src/templates/errors.hbs +28 -0
- package/src/templates/events.hbs +28 -0
- package/src/templates/header.hbs +2 -0
- package/src/templates/interfaceRegistry.hbs +15 -0
- package/src/templates/lookup/defs-named.hbs +12 -0
- package/src/templates/lookup/defs.hbs +15 -0
- package/src/templates/lookup/index.hbs +3 -0
- package/src/templates/lookup/types.hbs +14 -0
- package/src/templates/query.hbs +29 -0
- package/src/templates/rpc.hbs +22 -0
- package/src/templates/tsDef/index.hbs +3 -0
- package/src/templates/tsDef/moduleTypes.hbs +10 -0
- package/src/templates/tsDef/types.hbs +7 -0
- package/src/templates/tx.hbs +30 -0
- package/src/util/assert.ts +18 -0
- package/src/util/derived.spec.ts +58 -0
- package/src/util/derived.ts +133 -0
- package/src/util/docs.ts +13 -0
- package/src/util/file.ts +42 -0
- package/src/util/formatting.spec.ts +30 -0
- package/src/util/formatting.ts +322 -0
- package/src/util/imports.ts +164 -0
- package/src/util/index.ts +42 -0
- package/src/util/initMeta.ts +37 -0
- package/src/util/register.ts +12 -0
- package/src/util/wsMeta.ts +70 -0
- package/tsconfig.build.json +28 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.scripts.json +19 -0
- package/tsconfig.spec.json +17 -0
- package/tsconfig.spec.tsbuildinfo +1 -0
- /package/{cjs → build}/augment.d.ts +0 -0
- /package/{cjs → build}/bundle.d.ts +0 -0
- /package/{extractChain.d.ts → build/cjs/extractChain.d.ts} +0 -0
- /package/{fromChain.d.ts → build/cjs/fromChain.d.ts} +0 -0
- /package/{fromDefs.d.ts → build/cjs/fromDefs.d.ts} +0 -0
- /package/{generate → build/cjs/generate}/index.d.ts +0 -0
- /package/{index.d.ts → build/cjs/index.d.ts} +0 -0
- /package/{interfacesTs.d.ts → build/cjs/interfacesTs.d.ts} +0 -0
- /package/{metadataMd.d.ts → build/cjs/metadataMd.d.ts} +0 -0
- /package/{cjs → build/cjs}/package.json +0 -0
- /package/{packageDetect.d.ts → build/cjs/packageDetect.d.ts} +0 -0
- /package/{cjs → build/cjs}/packageDetect.js +0 -0
- /package/{packageInfo.d.ts → build/cjs/packageInfo.d.ts} +0 -0
- /package/{util → build/cjs/util}/assert.d.ts +0 -0
- /package/{util → build/cjs/util}/derived.d.ts +0 -0
- /package/{util → build/cjs/util}/docs.d.ts +0 -0
- /package/{util → build/cjs/util}/file.d.ts +0 -0
- /package/{util → build/cjs/util}/formatting.d.ts +0 -0
- /package/{util → build/cjs/util}/imports.d.ts +0 -0
- /package/{util → build/cjs/util}/index.d.ts +0 -0
- /package/{util → build/cjs/util}/initMeta.d.ts +0 -0
- /package/{util → build/cjs/util}/register.d.ts +0 -0
- /package/{util → build/cjs/util}/wsMeta.d.ts +0 -0
- /package/{augment.d.ts → build-tsc/augment.d.ts} +0 -0
- /package/{bundle.d.ts → build-tsc/bundle.d.ts} +0 -0
- /package/{cjs → build-tsc}/extractChain.d.ts +0 -0
- /package/{cjs → build-tsc}/fromChain.d.ts +0 -0
- /package/{cjs → build-tsc}/fromDefs.d.ts +0 -0
- /package/{cjs → build-tsc}/generate/consts.d.ts +0 -0
- /package/{cjs → build-tsc}/generate/errors.d.ts +0 -0
- /package/{cjs → build-tsc}/generate/events.d.ts +0 -0
- /package/{cjs → build-tsc}/generate/index.d.ts +0 -0
- /package/{cjs → build-tsc}/generate/interfaceRegistry.d.ts +0 -0
- /package/{cjs → build-tsc}/generate/lookup.d.ts +0 -0
- /package/{cjs → build-tsc}/generate/query.d.ts +0 -0
- /package/{cjs → build-tsc}/generate/rpc.d.ts +0 -0
- /package/{cjs → build-tsc}/generate/runtime.d.ts +0 -0
- /package/{cjs → build-tsc}/generate/tsDef.d.ts +0 -0
- /package/{cjs → build-tsc}/generate/tx.d.ts +0 -0
- /package/{cjs → build-tsc}/generate/types.d.ts +0 -0
- /package/{cjs → build-tsc}/index.d.ts +0 -0
- /package/{cjs → build-tsc}/interfacesTs.d.ts +0 -0
- /package/{cjs → build-tsc}/metadataMd.d.ts +0 -0
- /package/{cjs → build-tsc}/packageDetect.d.ts +0 -0
- /package/{cjs → build-tsc}/packageInfo.d.ts +0 -0
- /package/{cjs → build-tsc}/util/assert.d.ts +0 -0
- /package/{cjs → build-tsc}/util/derived.d.ts +0 -0
- /package/{cjs → build-tsc}/util/docs.d.ts +0 -0
- /package/{cjs → build-tsc}/util/file.d.ts +0 -0
- /package/{cjs → build-tsc}/util/formatting.d.ts +0 -0
- /package/{cjs → build-tsc}/util/imports.d.ts +0 -0
- /package/{cjs → build-tsc}/util/index.d.ts +0 -0
- /package/{cjs → build-tsc}/util/initMeta.d.ts +0 -0
- /package/{cjs → build-tsc}/util/register.d.ts +0 -0
- /package/{cjs → build-tsc}/util/wsMeta.d.ts +0 -0
- /package/{cjs → build-tsc-cjs}/augment.js +0 -0
- /package/{cjs → build-tsc-cjs}/bundle.js +0 -0
- /package/{cjs → build-tsc-cjs}/extractChain.js +0 -0
- /package/{cjs → build-tsc-cjs}/fromChain.js +0 -0
- /package/{cjs → build-tsc-cjs}/fromDefs.js +0 -0
- /package/{cjs → build-tsc-cjs}/generate/consts.js +0 -0
- /package/{cjs → build-tsc-cjs}/generate/errors.js +0 -0
- /package/{cjs → build-tsc-cjs}/generate/events.js +0 -0
- /package/{cjs → build-tsc-cjs}/generate/index.js +0 -0
- /package/{cjs → build-tsc-cjs}/generate/interfaceRegistry.js +0 -0
- /package/{cjs → build-tsc-cjs}/generate/lookup.js +0 -0
- /package/{cjs → build-tsc-cjs}/generate/query.js +0 -0
- /package/{cjs → build-tsc-cjs}/generate/rpc.js +0 -0
- /package/{cjs → build-tsc-cjs}/generate/runtime.js +0 -0
- /package/{cjs → build-tsc-cjs}/generate/tsDef.js +0 -0
- /package/{cjs → build-tsc-cjs}/generate/tx.js +0 -0
- /package/{cjs → build-tsc-cjs}/generate/types.js +0 -0
- /package/{cjs → build-tsc-cjs}/index.js +0 -0
- /package/{cjs → build-tsc-cjs}/interfacesTs.js +0 -0
- /package/{cjs → build-tsc-cjs}/metadataMd.js +0 -0
- /package/{cjs → build-tsc-cjs}/util/assert.js +0 -0
- /package/{cjs → build-tsc-cjs}/util/derived.js +0 -0
- /package/{cjs → build-tsc-cjs}/util/docs.js +0 -0
- /package/{cjs → build-tsc-cjs}/util/file.js +0 -0
- /package/{cjs → build-tsc-cjs}/util/formatting.js +0 -0
- /package/{cjs → build-tsc-cjs}/util/imports.js +0 -0
- /package/{cjs → build-tsc-cjs}/util/index.js +0 -0
- /package/{cjs → build-tsc-cjs}/util/initMeta.js +0 -0
- /package/{cjs → build-tsc-cjs}/util/register.js +0 -0
- /package/{cjs → build-tsc-cjs}/util/wsMeta.js +0 -0
- /package/{augment.js → build-tsc-esm/augment.js} +0 -0
- /package/{bundle.js → build-tsc-esm/bundle.js} +0 -0
- /package/{extractChain.js → build-tsc-esm/extractChain.js} +0 -0
- /package/{fromChain.js → build-tsc-esm/fromChain.js} +0 -0
- /package/{fromDefs.js → build-tsc-esm/fromDefs.js} +0 -0
- /package/{generate → build-tsc-esm/generate}/index.js +0 -0
- /package/{index.js → build-tsc-esm/index.js} +0 -0
- /package/{interfacesTs.js → build-tsc-esm/interfacesTs.js} +0 -0
- /package/{metadataMd.js → build-tsc-esm/metadataMd.js} +0 -0
- /package/{packageDetect.js → build-tsc-esm/packageDetect.js} +0 -0
- /package/{util → build-tsc-esm/util}/assert.js +0 -0
- /package/{util → build-tsc-esm/util}/derived.js +0 -0
- /package/{util → build-tsc-esm/util}/docs.js +0 -0
- /package/{util → build-tsc-esm/util}/file.js +0 -0
- /package/{util → build-tsc-esm/util}/formatting.js +0 -0
- /package/{util → build-tsc-esm/util}/imports.js +0 -0
- /package/{util → build-tsc-esm/util}/index.js +0 -0
- /package/{util → build-tsc-esm/util}/initMeta.js +0 -0
- /package/{util → build-tsc-esm/util}/register.js +0 -0
- /package/{util → build-tsc-esm/util}/wsMeta.js +0 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import Handlebars from 'handlebars';
|
|
2
|
+
import * as defaultDefs from '@pezkuwi/types/interfaces/definitions';
|
|
3
|
+
import lookupDefinitions from '@pezkuwi/types-augment/lookup/definitions';
|
|
4
|
+
import { stringCamelCase } from '@pezkuwi/util';
|
|
5
|
+
import { compareName, createImports, formatType, getSimilarTypes, initMeta, readTemplate, rebrandTypeName, setImports, writeFile } from '../util/index.js';
|
|
6
|
+
import { ignoreUnusedLookups } from './lookup.js';
|
|
7
|
+
import { getDeprecationNotice } from './types.js';
|
|
8
|
+
const MAPPED_NAMES = {
|
|
9
|
+
class: 'clazz',
|
|
10
|
+
new: 'updated'
|
|
11
|
+
};
|
|
12
|
+
const generateForMetaTemplate = Handlebars.compile(readTemplate('tx'));
|
|
13
|
+
function mapName(_name) {
|
|
14
|
+
const name = stringCamelCase(_name);
|
|
15
|
+
return MAPPED_NAMES[name] || name;
|
|
16
|
+
}
|
|
17
|
+
/** @internal */
|
|
18
|
+
function generateForMeta(registry, meta, dest, extraTypes, isStrict, customLookupDefinitions) {
|
|
19
|
+
writeFile(dest, () => {
|
|
20
|
+
const allTypes = {
|
|
21
|
+
'@pezkuwi/types-augment': {
|
|
22
|
+
lookup: {
|
|
23
|
+
...lookupDefinitions,
|
|
24
|
+
...customLookupDefinitions
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
'@pezkuwi/types/interfaces': defaultDefs,
|
|
28
|
+
...extraTypes
|
|
29
|
+
};
|
|
30
|
+
const imports = createImports(allTypes);
|
|
31
|
+
const allDefs = Object.entries(allTypes).reduce((defs, [path, obj]) => {
|
|
32
|
+
return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [`${path}/${key}`]: value }), defs);
|
|
33
|
+
}, {});
|
|
34
|
+
const { lookup, pallets } = meta.asLatest;
|
|
35
|
+
const usedTypes = new Set([]);
|
|
36
|
+
const modules = pallets
|
|
37
|
+
.sort(compareName)
|
|
38
|
+
.filter(({ calls }) => calls.isSome)
|
|
39
|
+
.map((data) => {
|
|
40
|
+
const name = data.name;
|
|
41
|
+
const calls = data.calls.unwrap();
|
|
42
|
+
const deprecationInfo = calls.deprecationInfo.toJSON();
|
|
43
|
+
setImports(allDefs, imports, ['SubmittableExtrinsic']);
|
|
44
|
+
const sectionName = stringCamelCase(name);
|
|
45
|
+
const items = lookup.getSiType(calls.type).def.asVariant.variants
|
|
46
|
+
.map(({ docs, fields, index, name }) => {
|
|
47
|
+
const rawStatus = deprecationInfo?.[index.toNumber()];
|
|
48
|
+
if (rawStatus) {
|
|
49
|
+
const deprecationVariantInfo = meta.registry.createTypeUnsafe('VariantDeprecationInfoV16', [rawStatus]);
|
|
50
|
+
const deprecationNotice = getDeprecationNotice(deprecationVariantInfo, name.toString(), 'Call');
|
|
51
|
+
const notice = docs.length ? ['', deprecationNotice] : [deprecationNotice];
|
|
52
|
+
docs.push(...notice.map((text) => meta.registry.createType('Text', text)));
|
|
53
|
+
}
|
|
54
|
+
const typesInfo = fields.map(({ name, type, typeName }, index) => {
|
|
55
|
+
const typeDef = registry.lookup.getTypeDef(type);
|
|
56
|
+
return [
|
|
57
|
+
name.isSome
|
|
58
|
+
? mapName(name.unwrap())
|
|
59
|
+
: `param${index}`,
|
|
60
|
+
rebrandTypeName(typeName.isSome
|
|
61
|
+
? typeName.toString()
|
|
62
|
+
: typeDef.type),
|
|
63
|
+
rebrandTypeName(typeDef.isFromSi
|
|
64
|
+
? typeDef.type
|
|
65
|
+
: typeDef.lookupName || typeDef.type)
|
|
66
|
+
];
|
|
67
|
+
});
|
|
68
|
+
const params = typesInfo
|
|
69
|
+
.map(([name, , typeStr]) => {
|
|
70
|
+
const similarTypes = getSimilarTypes(registry, allDefs, typeStr, imports);
|
|
71
|
+
setImports(allDefs, imports, [typeStr, ...similarTypes]);
|
|
72
|
+
// Add the type to the list of used types
|
|
73
|
+
if (!(imports.primitiveTypes[typeStr])) {
|
|
74
|
+
usedTypes.add(typeStr);
|
|
75
|
+
}
|
|
76
|
+
return `${name}: ${similarTypes.join(' | ')}`;
|
|
77
|
+
})
|
|
78
|
+
.join(', ');
|
|
79
|
+
return {
|
|
80
|
+
args: typesInfo.map(([, , typeStr]) => formatType(registry, allDefs, typeStr, imports)).join(', '),
|
|
81
|
+
docs,
|
|
82
|
+
name: stringCamelCase(name),
|
|
83
|
+
params
|
|
84
|
+
};
|
|
85
|
+
})
|
|
86
|
+
.sort(compareName);
|
|
87
|
+
return {
|
|
88
|
+
items,
|
|
89
|
+
name: sectionName
|
|
90
|
+
};
|
|
91
|
+
})
|
|
92
|
+
.sort(compareName);
|
|
93
|
+
// filter out the unused lookup types from imports
|
|
94
|
+
ignoreUnusedLookups([...usedTypes], imports);
|
|
95
|
+
return generateForMetaTemplate({
|
|
96
|
+
headerType: 'chain',
|
|
97
|
+
imports,
|
|
98
|
+
isStrict,
|
|
99
|
+
modules,
|
|
100
|
+
types: [
|
|
101
|
+
...Object.keys(imports.localTypes).sort().map((packagePath) => ({
|
|
102
|
+
file: packagePath.replace('@pezkuwi/types-augment', '@pezkuwi/types'),
|
|
103
|
+
types: Object.keys(imports.localTypes[packagePath])
|
|
104
|
+
})),
|
|
105
|
+
{
|
|
106
|
+
file: '@pezkuwi/api-base/types',
|
|
107
|
+
types: ['ApiTypes', 'AugmentedSubmittable', 'SubmittableExtrinsic', 'SubmittableExtrinsicFunction']
|
|
108
|
+
}
|
|
109
|
+
]
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/** @internal */
|
|
114
|
+
export function generateDefaultTx(dest, data, extraTypes = {}, isStrict = false, customLookupDefinitions) {
|
|
115
|
+
const { metadata, registry } = initMeta(data, extraTypes);
|
|
116
|
+
return generateForMeta(registry, metadata, dest, extraTypes, isStrict, customLookupDefinitions);
|
|
117
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function getDeprecationNotice(deprecationInfo, name, label) {
|
|
2
|
+
let deprecationNotice = '@deprecated';
|
|
3
|
+
if (deprecationInfo.isDeprecated) {
|
|
4
|
+
const { note, since } = deprecationInfo.asDeprecated;
|
|
5
|
+
const sinceText = since.isSome ? ` Since ${since.unwrap().toString()}.` : '';
|
|
6
|
+
deprecationNotice += ` ${note.toString()}${sinceText}`;
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
const labelText = label ? `${label} ` : '';
|
|
10
|
+
deprecationNotice += ` ${labelText}${name} has been deprecated`;
|
|
11
|
+
}
|
|
12
|
+
return deprecationNotice;
|
|
13
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const packageInfo = { name: '@pezkuwi/typegen', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '16.5.
|
|
1
|
+
export const packageInfo = { name: '@pezkuwi/typegen', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '16.5.18' };
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"author": "
|
|
2
|
+
"author": "Jaco Greeff <jacogr@gmail.com>",
|
|
3
3
|
"bugs": "https://github.com/pezkuwichain/pezkuwi-api/issues",
|
|
4
4
|
"description": "Type generation scripts",
|
|
5
5
|
"engines": {
|
|
@@ -18,7 +18,10 @@
|
|
|
18
18
|
"./cjs/packageDetect.js"
|
|
19
19
|
],
|
|
20
20
|
"type": "module",
|
|
21
|
-
"
|
|
21
|
+
"types": "./index.d.ts",
|
|
22
|
+
"version": "16.5.18",
|
|
23
|
+
"main": "./cjs/index.js",
|
|
24
|
+
"module": "./index.js",
|
|
22
25
|
"bin": {
|
|
23
26
|
"pezkuwi-types-chain-info": "./scripts/pezkuwi-types-chain-info.mjs",
|
|
24
27
|
"pezkuwi-types-from-chain": "./scripts/pezkuwi-types-from-chain.mjs",
|
|
@@ -26,12 +29,7 @@
|
|
|
26
29
|
"pezkuwi-types-internal-interfaces": "./scripts/pezkuwi-types-internal-interfaces.mjs",
|
|
27
30
|
"pezkuwi-types-internal-metadata": "./scripts/pezkuwi-types-internal-metadata.mjs"
|
|
28
31
|
},
|
|
29
|
-
"main": "./cjs/index.js",
|
|
30
|
-
"module": "./cjs/index.js",
|
|
31
|
-
"types": "./cjs/index.d.ts",
|
|
32
32
|
"exports": {
|
|
33
|
-
"./cjs/package.json": "./cjs/package.json",
|
|
34
|
-
"./cjs/*": "./cjs/*.js",
|
|
35
33
|
".": {
|
|
36
34
|
"module": {
|
|
37
35
|
"types": "./index.d.ts",
|
|
@@ -74,6 +72,8 @@
|
|
|
74
72
|
"default": "./bundle.js"
|
|
75
73
|
}
|
|
76
74
|
},
|
|
75
|
+
"./cjs/*": "./cjs/*.js",
|
|
76
|
+
"./cjs/package.json": "./cjs/package.json",
|
|
77
77
|
"./extractChain": {
|
|
78
78
|
"module": {
|
|
79
79
|
"types": "./extractChain.d.ts",
|
|
@@ -330,7 +330,7 @@
|
|
|
330
330
|
"default": "./packageDetect.js"
|
|
331
331
|
}
|
|
332
332
|
},
|
|
333
|
-
"./packageInfo
|
|
333
|
+
"./packageInfo": {
|
|
334
334
|
"module": {
|
|
335
335
|
"types": "./packageInfo.d.ts",
|
|
336
336
|
"default": "./packageInfo.js"
|
|
@@ -344,7 +344,7 @@
|
|
|
344
344
|
"default": "./packageInfo.js"
|
|
345
345
|
}
|
|
346
346
|
},
|
|
347
|
-
"./packageInfo": {
|
|
347
|
+
"./packageInfo.js": {
|
|
348
348
|
"module": {
|
|
349
349
|
"types": "./packageInfo.d.ts",
|
|
350
350
|
"default": "./packageInfo.js"
|
|
@@ -358,16 +358,16 @@
|
|
|
358
358
|
"default": "./packageInfo.js"
|
|
359
359
|
}
|
|
360
360
|
},
|
|
361
|
-
"./scripts/pezkuwi-types-chain-info.mjs": "./scripts/pezkuwi-types-chain-info.mjs",
|
|
362
361
|
"./scripts/pezkuwi-types-chain-info": "./scripts/pezkuwi-types-chain-info.mjs",
|
|
363
|
-
"./scripts/pezkuwi-types-
|
|
362
|
+
"./scripts/pezkuwi-types-chain-info.mjs": "./scripts/pezkuwi-types-chain-info.mjs",
|
|
364
363
|
"./scripts/pezkuwi-types-from-chain": "./scripts/pezkuwi-types-from-chain.mjs",
|
|
365
|
-
"./scripts/pezkuwi-types-from-
|
|
364
|
+
"./scripts/pezkuwi-types-from-chain.mjs": "./scripts/pezkuwi-types-from-chain.mjs",
|
|
366
365
|
"./scripts/pezkuwi-types-from-defs": "./scripts/pezkuwi-types-from-defs.mjs",
|
|
367
|
-
"./scripts/pezkuwi-types-
|
|
366
|
+
"./scripts/pezkuwi-types-from-defs.mjs": "./scripts/pezkuwi-types-from-defs.mjs",
|
|
368
367
|
"./scripts/pezkuwi-types-internal-interfaces": "./scripts/pezkuwi-types-internal-interfaces.mjs",
|
|
369
|
-
"./scripts/pezkuwi-types-internal-
|
|
368
|
+
"./scripts/pezkuwi-types-internal-interfaces.mjs": "./scripts/pezkuwi-types-internal-interfaces.mjs",
|
|
370
369
|
"./scripts/pezkuwi-types-internal-metadata": "./scripts/pezkuwi-types-internal-metadata.mjs",
|
|
370
|
+
"./scripts/pezkuwi-types-internal-metadata.mjs": "./scripts/pezkuwi-types-internal-metadata.mjs",
|
|
371
371
|
"./templates/calls.hbs": "./templates/calls.hbs",
|
|
372
372
|
"./templates/consts.hbs": "./templates/consts.hbs",
|
|
373
373
|
"./templates/docs.hbs": "./templates/docs.hbs",
|
|
@@ -527,19 +527,19 @@
|
|
|
527
527
|
}
|
|
528
528
|
},
|
|
529
529
|
"dependencies": {
|
|
530
|
-
"@pezkuwi/api": "16.5.
|
|
531
|
-
"@pezkuwi/api-augment": "16.5.
|
|
532
|
-
"@pezkuwi/api-derive": "16.5.
|
|
533
|
-
"@pezkuwi/rpc-augment": "16.5.
|
|
534
|
-
"@pezkuwi/rpc-provider": "16.5.
|
|
535
|
-
"@pezkuwi/types": "16.5.
|
|
536
|
-
"@pezkuwi/types-augment": "16.5.
|
|
537
|
-
"@pezkuwi/types-codec": "16.5.
|
|
538
|
-
"@pezkuwi/types-create": "16.5.
|
|
539
|
-
"@pezkuwi/types-support": "16.5.
|
|
540
|
-
"@pezkuwi/util": "14.0.
|
|
541
|
-
"@pezkuwi/util-crypto": "14.0.
|
|
542
|
-
"@pezkuwi/x-ws": "14.0.
|
|
530
|
+
"@pezkuwi/api": "16.5.9",
|
|
531
|
+
"@pezkuwi/api-augment": "16.5.9",
|
|
532
|
+
"@pezkuwi/api-derive": "16.5.9",
|
|
533
|
+
"@pezkuwi/rpc-augment": "16.5.9",
|
|
534
|
+
"@pezkuwi/rpc-provider": "16.5.9",
|
|
535
|
+
"@pezkuwi/types": "16.5.9",
|
|
536
|
+
"@pezkuwi/types-augment": "16.5.9",
|
|
537
|
+
"@pezkuwi/types-codec": "16.5.9",
|
|
538
|
+
"@pezkuwi/types-create": "16.5.9",
|
|
539
|
+
"@pezkuwi/types-support": "16.5.9",
|
|
540
|
+
"@pezkuwi/util": "14.0.11",
|
|
541
|
+
"@pezkuwi/util-crypto": "14.0.11",
|
|
542
|
+
"@pezkuwi/x-ws": "14.0.11",
|
|
543
543
|
"comment-parser": "^1.4.1",
|
|
544
544
|
"handlebars": "^4.7.8",
|
|
545
545
|
"tslib": "^2.8.1",
|
package/src/augment.ts
ADDED
package/src/bundle.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Copyright 2017-2025 @pezkuwi/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://dicle-rpc.pezkuwi.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
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// Copyright 2017-2025 @pezkuwi/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://dicle-rpc.pezkuwi.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
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// Copyright 2017-2025 @pezkuwi/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 bizinikiwiDefs 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://dicle-rpc.pezkuwi.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(bizinikiwiDefs as Record<string, unknown>)
|
|
55
|
+
.filter(([key]) => {
|
|
56
|
+
if (userKeys.includes(key)) {
|
|
57
|
+
console.warn(`Override found for ${key} in user types, ignoring in @pezkuwi/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
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// Copyright 2017-2025 @pezkuwi/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, rebrandTypeName, 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 = rebrandTypeName(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
|
+
}
|