@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,169 @@
|
|
|
1
|
+
// Copyright 2017-2025 @pezkuwi/typegen authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { StorageEntryMetadataLatest } from '@pezkuwi/types/interfaces';
|
|
5
|
+
import type { Metadata, PortableRegistry } from '@pezkuwi/types/metadata';
|
|
6
|
+
import type { Definitions, Registry } from '@pezkuwi/types/types';
|
|
7
|
+
import type { HexString } from '@pezkuwi/util/types';
|
|
8
|
+
import type { ModuleTypes, TypeImports } from '../util/imports.js';
|
|
9
|
+
|
|
10
|
+
import Handlebars from 'handlebars';
|
|
11
|
+
|
|
12
|
+
import * as defaultDefs from '@pezkuwi/types/interfaces/definitions';
|
|
13
|
+
import { unwrapStorageSi } from '@pezkuwi/types/util';
|
|
14
|
+
import lookupDefinitions from '@pezkuwi/types-augment/lookup/definitions';
|
|
15
|
+
import { stringCamelCase } from '@pezkuwi/util';
|
|
16
|
+
|
|
17
|
+
import { compareName, createImports, formatType, getSimilarTypes, initMeta, readTemplate, rebrandTypeName, setImports, writeFile } from '../util/index.js';
|
|
18
|
+
import { ignoreUnusedLookups } from './lookup.js';
|
|
19
|
+
import { type ExtraTypes, getDeprecationNotice } from './types.js';
|
|
20
|
+
|
|
21
|
+
const generateForMetaTemplate = Handlebars.compile(readTemplate('query'));
|
|
22
|
+
|
|
23
|
+
// From a storage entry metadata, we return [args, returnType]
|
|
24
|
+
/** @internal */
|
|
25
|
+
function entrySignature (lookup: PortableRegistry, allDefs: Record<string, ModuleTypes>, registry: Registry, section: string, storageEntry: StorageEntryMetadataLatest, imports: TypeImports): [boolean, string, string, string] {
|
|
26
|
+
try {
|
|
27
|
+
const outputType = lookup.getTypeDef(unwrapStorageSi(storageEntry.type));
|
|
28
|
+
|
|
29
|
+
if (storageEntry.type.isPlain) {
|
|
30
|
+
const typeDef = lookup.getTypeDef(storageEntry.type.asPlain);
|
|
31
|
+
|
|
32
|
+
setImports(allDefs, imports, [
|
|
33
|
+
rebrandTypeName(typeDef.lookupName || typeDef.type),
|
|
34
|
+
storageEntry.modifier.isOptional
|
|
35
|
+
? 'Option'
|
|
36
|
+
: null
|
|
37
|
+
]);
|
|
38
|
+
|
|
39
|
+
return [storageEntry.modifier.isOptional, '', '', formatType(registry, allDefs, outputType, imports)];
|
|
40
|
+
} else if (storageEntry.type.isMap) {
|
|
41
|
+
const { hashers, key, value } = storageEntry.type.asMap;
|
|
42
|
+
const keyDefs = hashers.length === 1
|
|
43
|
+
? [lookup.getTypeDef(key)]
|
|
44
|
+
: lookup.getSiType(key).def.asTuple.map((k) => lookup.getTypeDef(k));
|
|
45
|
+
const similarTypes = keyDefs.map((k) => getSimilarTypes(registry, allDefs, k.lookupName || k.type, imports));
|
|
46
|
+
const keyTypes = similarTypes.map((t) => t.join(' | '));
|
|
47
|
+
const defValue = lookup.getTypeDef(value);
|
|
48
|
+
|
|
49
|
+
setImports(allDefs, imports, [
|
|
50
|
+
...similarTypes.reduce<string[]>((all, t) => all.concat(t), []),
|
|
51
|
+
storageEntry.modifier.isOptional
|
|
52
|
+
? 'Option'
|
|
53
|
+
: null,
|
|
54
|
+
rebrandTypeName(defValue.lookupName || defValue.type)
|
|
55
|
+
]);
|
|
56
|
+
|
|
57
|
+
return [
|
|
58
|
+
storageEntry.modifier.isOptional,
|
|
59
|
+
keyDefs.map((k) => formatType(registry, allDefs, k.lookupName || k.type, imports)).join(', '),
|
|
60
|
+
keyTypes.map((t, i) => `arg${keyTypes.length === 1 ? '' : (i + 1)}: ${t}`).join(', '),
|
|
61
|
+
rebrandTypeName(outputType.lookupName || '') || formatType(registry, allDefs, outputType, imports)
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
throw new Error(`Expected Plain or Map type, found ${storageEntry.type.type}`);
|
|
66
|
+
} catch (error) {
|
|
67
|
+
throw new Error(`entrySignature: Cannot create signature for query ${section}.${storageEntry.name.toString()}:: ${(error as Error).message}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** @internal */
|
|
72
|
+
function generateForMeta (registry: Registry, meta: Metadata, dest: string, extraTypes: ExtraTypes, isStrict: boolean, customLookupDefinitions?: Definitions): void {
|
|
73
|
+
writeFile(dest, (): string => {
|
|
74
|
+
const allTypes: ExtraTypes = {
|
|
75
|
+
'@pezkuwi/types-augment': {
|
|
76
|
+
lookup: {
|
|
77
|
+
...lookupDefinitions,
|
|
78
|
+
...customLookupDefinitions
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
'@pezkuwi/types/interfaces': defaultDefs,
|
|
82
|
+
...extraTypes
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const imports = createImports(allTypes);
|
|
86
|
+
const allDefs = Object.entries(allTypes).reduce((defs, [path, obj]) => {
|
|
87
|
+
return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [`${path}/${key}`]: value }), defs);
|
|
88
|
+
}, {});
|
|
89
|
+
const { lookup, pallets } = meta.asLatest;
|
|
90
|
+
const usedTypes = new Set<string>([]);
|
|
91
|
+
const modules = pallets
|
|
92
|
+
.filter(({ storage }) => storage.isSome)
|
|
93
|
+
.map(({ name, storage }) => {
|
|
94
|
+
const items = storage.unwrap().items
|
|
95
|
+
.map((storageEntry) => {
|
|
96
|
+
const { deprecationInfo, docs, name } = storageEntry;
|
|
97
|
+
const [isOptional, args, params, _returnType] = entrySignature(lookup, allDefs, registry, name.toString(), storageEntry, imports);
|
|
98
|
+
|
|
99
|
+
if (!deprecationInfo.isNotDeprecated) {
|
|
100
|
+
const deprecationNotice = getDeprecationNotice(deprecationInfo, stringCamelCase(name));
|
|
101
|
+
const items = docs.length
|
|
102
|
+
? ['', deprecationNotice]
|
|
103
|
+
: [deprecationNotice];
|
|
104
|
+
|
|
105
|
+
docs.push(...items.map((text) => registry.createType('Text', text)));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Add the type and args to the list of used types
|
|
109
|
+
if (!(imports.primitiveTypes[_returnType])) {
|
|
110
|
+
usedTypes.add(_returnType);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (!(imports.primitiveTypes[args])) {
|
|
114
|
+
usedTypes.add(args);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const returnType = isOptional
|
|
118
|
+
? `Option<${_returnType}>`
|
|
119
|
+
: _returnType;
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
args,
|
|
123
|
+
docs,
|
|
124
|
+
entryType: 'AugmentedQuery',
|
|
125
|
+
name: stringCamelCase(storageEntry.name),
|
|
126
|
+
params,
|
|
127
|
+
returnType
|
|
128
|
+
};
|
|
129
|
+
})
|
|
130
|
+
.sort(compareName);
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
items,
|
|
134
|
+
name: stringCamelCase(name)
|
|
135
|
+
};
|
|
136
|
+
})
|
|
137
|
+
.sort(compareName);
|
|
138
|
+
|
|
139
|
+
imports.typesTypes['Observable'] = true;
|
|
140
|
+
|
|
141
|
+
// filter out the unused lookup types from imports
|
|
142
|
+
ignoreUnusedLookups([...usedTypes], imports);
|
|
143
|
+
|
|
144
|
+
return generateForMetaTemplate({
|
|
145
|
+
headerType: 'chain',
|
|
146
|
+
imports,
|
|
147
|
+
isStrict,
|
|
148
|
+
modules,
|
|
149
|
+
types: [
|
|
150
|
+
...Object.keys(imports.localTypes).sort().map((packagePath): { file: string; types: string[] } => ({
|
|
151
|
+
file: packagePath.replace('@pezkuwi/types-augment', '@pezkuwi/types'),
|
|
152
|
+
types: Object.keys(imports.localTypes[packagePath])
|
|
153
|
+
})),
|
|
154
|
+
{
|
|
155
|
+
file: '@pezkuwi/api-base/types',
|
|
156
|
+
types: ['ApiTypes', 'AugmentedQuery', 'QueryableStorageEntry']
|
|
157
|
+
}
|
|
158
|
+
]
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Call `generateForMeta()` with current static metadata
|
|
164
|
+
/** @internal */
|
|
165
|
+
export function generateDefaultQuery (dest: string, data: HexString, extraTypes: ExtraTypes = {}, isStrict = false, customLookupDefinitions?: Definitions): void {
|
|
166
|
+
const { metadata, registry } = initMeta(data, extraTypes);
|
|
167
|
+
|
|
168
|
+
return generateForMeta(registry, metadata, dest, extraTypes, isStrict, customLookupDefinitions);
|
|
169
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// Copyright 2017-2025 @pezkuwi/typegen authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { TypeRegistry } from '@pezkuwi/types/create';
|
|
5
|
+
import type { Definitions } from '@pezkuwi/types/types';
|
|
6
|
+
import type { ExtraTypes } from './types.js';
|
|
7
|
+
|
|
8
|
+
import Handlebars from 'handlebars';
|
|
9
|
+
|
|
10
|
+
import * as defaultDefinitions from '@pezkuwi/types/interfaces/definitions';
|
|
11
|
+
import staticBizinikiwi from '@pezkuwi/types-support/metadata/static-bizinikiwi';
|
|
12
|
+
|
|
13
|
+
import { createImports, formatType, getSimilarTypes, initMeta, readTemplate, setImports, writeFile } from '../util/index.js';
|
|
14
|
+
|
|
15
|
+
interface ItemDef {
|
|
16
|
+
args: string;
|
|
17
|
+
docs: string[];
|
|
18
|
+
generic: string | undefined;
|
|
19
|
+
name: string;
|
|
20
|
+
type: string | undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface ModuleDef {
|
|
24
|
+
items: ItemDef[];
|
|
25
|
+
name: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const StorageKeyType = 'StorageKey | string | Uint8Array | any';
|
|
29
|
+
|
|
30
|
+
const generateRpcTypesTemplate = Handlebars.compile(readTemplate('rpc'));
|
|
31
|
+
|
|
32
|
+
/** @internal */
|
|
33
|
+
export function generateRpcTypes (registry: TypeRegistry, importDefinitions: Record<string, Definitions>, dest: string, extraTypes: ExtraTypes): void {
|
|
34
|
+
writeFile(dest, (): string => {
|
|
35
|
+
const allTypes: ExtraTypes = { '@pezkuwi/types/interfaces': importDefinitions, ...extraTypes };
|
|
36
|
+
const imports = createImports(allTypes);
|
|
37
|
+
const definitions = imports.definitions as Record<string, Definitions>;
|
|
38
|
+
const allDefs = Object.entries(allTypes).reduce((defs, [path, obj]) => {
|
|
39
|
+
return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [`${path}/${key}`]: value }), defs);
|
|
40
|
+
}, {});
|
|
41
|
+
|
|
42
|
+
const rpcKeys = Object
|
|
43
|
+
.keys(definitions)
|
|
44
|
+
.filter((key) => Object.keys(definitions[key].rpc || {}).length !== 0)
|
|
45
|
+
.sort();
|
|
46
|
+
|
|
47
|
+
const additional: Record<string, ModuleDef> = {};
|
|
48
|
+
const modules = rpcKeys.map((sectionFullName) => {
|
|
49
|
+
const rpc = definitions[sectionFullName].rpc || {};
|
|
50
|
+
const section = sectionFullName.split('/').pop();
|
|
51
|
+
|
|
52
|
+
const allMethods = Object.keys(rpc).sort().map((methodName) => {
|
|
53
|
+
const def = rpc[methodName];
|
|
54
|
+
|
|
55
|
+
let args;
|
|
56
|
+
let type;
|
|
57
|
+
let generic;
|
|
58
|
+
|
|
59
|
+
// These are too hard to type with generics, do manual overrides
|
|
60
|
+
if (section === 'state') {
|
|
61
|
+
setImports(allDefs, imports, ['Codec', 'Hash', 'StorageKey', 'Vec']);
|
|
62
|
+
|
|
63
|
+
if (methodName === 'getStorage') {
|
|
64
|
+
generic = 'T = Codec';
|
|
65
|
+
args = [`key: ${StorageKeyType}, block?: Hash | Uint8Array | string`];
|
|
66
|
+
type = 'T';
|
|
67
|
+
} else if (methodName === 'queryStorage') {
|
|
68
|
+
generic = 'T = Codec[]';
|
|
69
|
+
args = [`keys: Vec<StorageKey> | (${StorageKeyType})[], fromBlock?: Hash | Uint8Array | string, toBlock?: Hash | Uint8Array | string`];
|
|
70
|
+
type = '[Hash, T][]';
|
|
71
|
+
} else if (methodName === 'queryStorageAt') {
|
|
72
|
+
generic = 'T = Codec[]';
|
|
73
|
+
args = [`keys: Vec<StorageKey> | (${StorageKeyType})[], at?: Hash | Uint8Array | string`];
|
|
74
|
+
type = 'T';
|
|
75
|
+
} else if (methodName === 'subscribeStorage') {
|
|
76
|
+
generic = 'T = Codec[]';
|
|
77
|
+
args = [`keys?: Vec<StorageKey> | (${StorageKeyType})[]`];
|
|
78
|
+
type = 'T';
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (args === undefined) {
|
|
83
|
+
setImports(allDefs, imports, [def.type]);
|
|
84
|
+
|
|
85
|
+
args = def.params.map((param) => {
|
|
86
|
+
const similarTypes = getSimilarTypes(registry, definitions, param.type, imports);
|
|
87
|
+
|
|
88
|
+
setImports(allDefs, imports, [param.type, ...similarTypes]);
|
|
89
|
+
|
|
90
|
+
return `${param.name}${param.isOptional ? '?' : ''}: ${similarTypes.join(' | ')}`;
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
type = formatType(registry, allDefs, def.type, imports);
|
|
94
|
+
generic = '';
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const item = {
|
|
98
|
+
args: args.join(', '),
|
|
99
|
+
docs: def.deprecated
|
|
100
|
+
? [`@deprecated ${def.deprecated}`, def.description]
|
|
101
|
+
: [def.description],
|
|
102
|
+
generic,
|
|
103
|
+
name: methodName,
|
|
104
|
+
type
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
if (def.aliasSection) {
|
|
108
|
+
if (!additional[def.aliasSection]) {
|
|
109
|
+
additional[def.aliasSection] = {
|
|
110
|
+
items: [],
|
|
111
|
+
name: def.aliasSection
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
additional[def.aliasSection].items.push(item);
|
|
116
|
+
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return item;
|
|
121
|
+
}).filter((item): item is ItemDef => !!item);
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
items: allMethods,
|
|
125
|
+
name: section || 'unknown'
|
|
126
|
+
};
|
|
127
|
+
}).concat(...Object.values(additional)).sort((a, b) => a.name.localeCompare(b.name));
|
|
128
|
+
|
|
129
|
+
imports.typesTypes['Observable'] = true;
|
|
130
|
+
|
|
131
|
+
return generateRpcTypesTemplate({
|
|
132
|
+
headerType: 'chain',
|
|
133
|
+
imports,
|
|
134
|
+
modules,
|
|
135
|
+
types: [
|
|
136
|
+
...Object.keys(imports.localTypes).sort().map((packagePath): { file: string; types: string[] } => ({
|
|
137
|
+
file: packagePath.replace('@pezkuwi/types-augment', '@pezkuwi/types'),
|
|
138
|
+
types: Object.keys(imports.localTypes[packagePath])
|
|
139
|
+
})),
|
|
140
|
+
{
|
|
141
|
+
file: '@pezkuwi/rpc-core/types',
|
|
142
|
+
types: ['AugmentedRpc']
|
|
143
|
+
}
|
|
144
|
+
]
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function generateDefaultRpc (dest = 'packages/rpc-augment/src/augment/jsonrpc.ts', extraTypes: ExtraTypes = {}): void {
|
|
150
|
+
const { registry } = initMeta(staticBizinikiwi, extraTypes);
|
|
151
|
+
|
|
152
|
+
generateRpcTypes(
|
|
153
|
+
registry,
|
|
154
|
+
defaultDefinitions,
|
|
155
|
+
dest,
|
|
156
|
+
extraTypes
|
|
157
|
+
);
|
|
158
|
+
}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
// Copyright 2017-2025 @pezkuwi/typegen authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { RuntimeApiMethodMetadataV16, SiLookupTypeId } from '@pezkuwi/types/interfaces';
|
|
5
|
+
import type { Metadata } from '@pezkuwi/types/metadata/Metadata';
|
|
6
|
+
import type { DefinitionCall, DefinitionCallNamed, Definitions, DefinitionsCall, Registry } from '@pezkuwi/types/types';
|
|
7
|
+
import type { Vec } from '@pezkuwi/types-codec';
|
|
8
|
+
import type { HexString } from '@pezkuwi/util/types';
|
|
9
|
+
|
|
10
|
+
import Handlebars from 'handlebars';
|
|
11
|
+
|
|
12
|
+
import * as defaultDefs from '@pezkuwi/types/interfaces/definitions';
|
|
13
|
+
import lookupDefinitions from '@pezkuwi/types-augment/lookup/definitions';
|
|
14
|
+
import { objectSpread, stringCamelCase } from '@pezkuwi/util';
|
|
15
|
+
import { blake2AsHex } from '@pezkuwi/util-crypto';
|
|
16
|
+
|
|
17
|
+
import { createImports, formatType, getSimilarTypes, initMeta, readTemplate, rebrandTypeName, setImports, writeFile } from '../util/index.js';
|
|
18
|
+
import { type ExtraTypes, getDeprecationNotice } from './types.js';
|
|
19
|
+
|
|
20
|
+
type Apis = [HexString, number][];
|
|
21
|
+
|
|
22
|
+
const generateCallsTypesTemplate = Handlebars.compile(readTemplate('calls'));
|
|
23
|
+
|
|
24
|
+
// This works similar to the PATHS_ALIAS set from the PortableRegistry
|
|
25
|
+
const aliases: Record<string, string> = {
|
|
26
|
+
AssetHubZagrosRuntimeRuntimeCall: 'RuntimeCall',
|
|
27
|
+
AssetHubPezkuwiRuntimeRuntimeCall: 'RuntimeCall',
|
|
28
|
+
AssetHubDicleRuntimeOriginCaller: 'OriginCaller',
|
|
29
|
+
AssetHubDicleRuntimeRuntimeCall: 'RuntimeCall',
|
|
30
|
+
DicleRuntimeConstantsProxyProxyType: 'ProxyType',
|
|
31
|
+
KitchensinkRuntimeRuntimeCall: 'RuntimeCall',
|
|
32
|
+
KitchensinkRuntimeRuntimeParametersKey: 'RuntimeParametersKey',
|
|
33
|
+
OpaqueValue: 'Bytes',
|
|
34
|
+
PezkuwiTeyrchainPrimitivesPrimitivesId: 'ParaId',
|
|
35
|
+
PezkuwiTeyrchainPrimitivesPrimitivesValidationCodeHash: 'ValidationCodeHash',
|
|
36
|
+
PezkuwiPrimitivesV7SlashingOpaqueKeyOwnershipProof: 'OpaqueKeyOwnershipProof',
|
|
37
|
+
PezkuwiPrimitivesV8SlashingOpaqueKeyOwnershipProof: 'OpaqueKeyOwnershipProof',
|
|
38
|
+
PezkuwiRuntimeRuntimeCall: 'RuntimeCall',
|
|
39
|
+
PrimitiveTypesH160: 'H160',
|
|
40
|
+
PrimitiveTypesH256: 'H256',
|
|
41
|
+
PrimitiveTypesU256: 'U256',
|
|
42
|
+
PezspConsensusBabeOpaqueKeyOwnershipProof: 'OpaqueKeyOwnershipProof',
|
|
43
|
+
PezspConsensusSlotsSlot: 'Slot',
|
|
44
|
+
PezspConsensusSlotsSlotDuration: 'SlotDuration',
|
|
45
|
+
PezspCoreCryptoAccountId32: 'AccountId32',
|
|
46
|
+
PezspCoreOpaqueMetadata: 'OpaqueMetadata',
|
|
47
|
+
PezspRuntimeOpaqueValue: 'Bytes',
|
|
48
|
+
PezspRuntimeUncheckedExtrinsic: 'Extrinsic',
|
|
49
|
+
StagingDicleRuntimeOriginCaller: 'OriginCaller',
|
|
50
|
+
StagingDicleRuntimeRuntimeCall: 'RuntimeCall',
|
|
51
|
+
StagingDicleRuntimeRuntimeParameters: 'RuntimeParameters',
|
|
52
|
+
StagingDicleRuntimeRuntimeParametersKey: 'RuntimeParametersKey',
|
|
53
|
+
StagingZagrosRuntimeRuntimeCall: 'RuntimeCall'
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const getTypesViaAlias = (registry: Registry, id: SiLookupTypeId) => {
|
|
57
|
+
const rawTypeName = registry.lookup.getName(id) || registry.lookup.getTypeDef(id).type;
|
|
58
|
+
const typeName = rebrandTypeName(rawTypeName);
|
|
59
|
+
|
|
60
|
+
if (aliases[typeName]) {
|
|
61
|
+
return aliases[typeName];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return typeName;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/** @internal */
|
|
68
|
+
function getMethods (registry: Registry, methods: Vec<RuntimeApiMethodMetadataV16>) {
|
|
69
|
+
const result: Record<string, DefinitionCall> = {};
|
|
70
|
+
|
|
71
|
+
methods.forEach((m) => {
|
|
72
|
+
const { deprecationInfo, docs, inputs, name, output } = m;
|
|
73
|
+
let description = docs.map((d) => d.toString()).join();
|
|
74
|
+
|
|
75
|
+
if (!deprecationInfo.isNotDeprecated) {
|
|
76
|
+
const deprecationNotice = getDeprecationNotice(deprecationInfo, stringCamelCase(name));
|
|
77
|
+
const notice = description.length ? `\n * ${deprecationNotice}` : ` * ${deprecationNotice}`;
|
|
78
|
+
|
|
79
|
+
description += notice;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
result[name.toString()] = {
|
|
83
|
+
description,
|
|
84
|
+
params: inputs.map(({ name, type }) => {
|
|
85
|
+
return { name: name.toString(), type: getTypesViaAlias(registry, type) };
|
|
86
|
+
}),
|
|
87
|
+
type: getTypesViaAlias(registry, output)
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** @internal */
|
|
95
|
+
function getRuntimeDefViaMetadata (registry: Registry) {
|
|
96
|
+
const result: DefinitionsCall = {};
|
|
97
|
+
const { apis } = registry.metadata;
|
|
98
|
+
|
|
99
|
+
for (let i = 0, count = apis.length; i < count; i++) {
|
|
100
|
+
const { methods, name } = apis[i];
|
|
101
|
+
|
|
102
|
+
result[name.toString()] = [{
|
|
103
|
+
methods: getMethods(registry, methods),
|
|
104
|
+
// We set the version to 0 here since it will not be relevant when we are grabbing the runtime apis
|
|
105
|
+
// from the Metadata.
|
|
106
|
+
version: 0
|
|
107
|
+
}];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return Object.entries(result);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** @internal */
|
|
114
|
+
function getDefs (apis: Apis | null, defs: Record<string, Definitions>, registry: Registry): Record<string, Record<string, DefinitionCallNamed>> {
|
|
115
|
+
const named: Record<string, Record<string, DefinitionCallNamed>> = {};
|
|
116
|
+
const all = Object.values(defs);
|
|
117
|
+
const isApiInMetadata = registry.metadata.apis.length > 0;
|
|
118
|
+
|
|
119
|
+
if (isApiInMetadata) {
|
|
120
|
+
const sections = getRuntimeDefViaMetadata(registry);
|
|
121
|
+
|
|
122
|
+
for (let j = 0, jcount = sections.length; j < jcount; j++) {
|
|
123
|
+
const [_section, secs] = sections[j];
|
|
124
|
+
const sec = secs[0];
|
|
125
|
+
const sectionHash = blake2AsHex(_section, 64);
|
|
126
|
+
|
|
127
|
+
const section = stringCamelCase(_section);
|
|
128
|
+
const methods = Object.entries(sec.methods);
|
|
129
|
+
|
|
130
|
+
if (!named[section]) {
|
|
131
|
+
named[section] = {};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
for (let m = 0, mcount = methods.length; m < mcount; m++) {
|
|
135
|
+
const [_method, def] = methods[m];
|
|
136
|
+
const method = stringCamelCase(_method);
|
|
137
|
+
|
|
138
|
+
named[section][method] = objectSpread({ method, name: `${_section}_${_method}`, section, sectionHash }, def);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
} else {
|
|
142
|
+
for (let j = 0, jcount = all.length; j < jcount; j++) {
|
|
143
|
+
const set = all[j].runtime;
|
|
144
|
+
|
|
145
|
+
if (set) {
|
|
146
|
+
const sections = Object.entries(set);
|
|
147
|
+
|
|
148
|
+
for (let i = 0, scount = sections.length; i < scount; i++) {
|
|
149
|
+
const [_section, sec] = sections[i];
|
|
150
|
+
const sectionHash = blake2AsHex(_section, 64);
|
|
151
|
+
const api = apis?.find(([h]) => h === sectionHash);
|
|
152
|
+
|
|
153
|
+
if (api) {
|
|
154
|
+
const ver = sec.find(({ version }) => version === api[1]);
|
|
155
|
+
|
|
156
|
+
if (ver) {
|
|
157
|
+
const methods = Object.entries(ver.methods);
|
|
158
|
+
const mcount = methods.length;
|
|
159
|
+
|
|
160
|
+
if (mcount) {
|
|
161
|
+
const section = stringCamelCase(_section);
|
|
162
|
+
|
|
163
|
+
if (!named[section]) {
|
|
164
|
+
named[section] = {};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
for (let m = 0; m < mcount; m++) {
|
|
168
|
+
const [_method, def] = methods[m];
|
|
169
|
+
const method = stringCamelCase(_method);
|
|
170
|
+
|
|
171
|
+
named[section][method] = objectSpread({ method, name: `${_section}_${method}`, section, sectionHash, version: ver.version }, def);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
} else {
|
|
175
|
+
console.warn(`Unable to find matching version for runtime ${_section}, expected ${api[1]}`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return named;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** @internal */
|
|
187
|
+
export function generateCallTypes (registry: Registry, meta: Metadata, dest: string, extraTypes: ExtraTypes, isStrict: boolean, customLookupDefinitions?: Definitions): void {
|
|
188
|
+
writeFile(dest, (): string => {
|
|
189
|
+
const allTypes: ExtraTypes = {
|
|
190
|
+
'@pezkuwi/types-augment': {
|
|
191
|
+
lookup: {
|
|
192
|
+
...lookupDefinitions,
|
|
193
|
+
...customLookupDefinitions
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
'@pezkuwi/types/interfaces': defaultDefs,
|
|
197
|
+
...extraTypes
|
|
198
|
+
};
|
|
199
|
+
const imports = createImports(allTypes);
|
|
200
|
+
|
|
201
|
+
// find the system.Version in metadata
|
|
202
|
+
let apis: Apis | null = null;
|
|
203
|
+
const sysp = meta.asLatest.pallets.find(({ name }) => name.eq('System'));
|
|
204
|
+
|
|
205
|
+
if (sysp) {
|
|
206
|
+
const verc = sysp.constants.find(({ name }) => name.eq('Version'));
|
|
207
|
+
|
|
208
|
+
if (verc) {
|
|
209
|
+
apis = registry.createType('RuntimeVersion', verc.value).apis.map(([k, v]): [HexString, number] => [k.toHex(), v.toNumber()]);
|
|
210
|
+
} else {
|
|
211
|
+
console.error('Unable to find System.Version pallet, skipping API extraction');
|
|
212
|
+
}
|
|
213
|
+
} else {
|
|
214
|
+
console.error('Unable to find System pallet, skipping API extraction');
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const allDefs = Object.entries(allTypes).reduce((defs, [path, obj]) => {
|
|
218
|
+
return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [`${path}/${key}`]: value }), defs);
|
|
219
|
+
}, {});
|
|
220
|
+
const definitions = getDefs(apis, imports.definitions as Record<string, Definitions>, registry);
|
|
221
|
+
const callKeys = Object.keys(definitions);
|
|
222
|
+
|
|
223
|
+
const modules = callKeys.map((section) => {
|
|
224
|
+
const calls = definitions[section];
|
|
225
|
+
|
|
226
|
+
const allMethods = Object.keys(calls).sort().map((methodName) => {
|
|
227
|
+
const def = calls[methodName];
|
|
228
|
+
|
|
229
|
+
setImports(allDefs, imports, [def.type]);
|
|
230
|
+
|
|
231
|
+
const args = def.params.map((param) => {
|
|
232
|
+
const similarTypes = getSimilarTypes(registry, imports.definitions, param.type, imports);
|
|
233
|
+
|
|
234
|
+
setImports(allDefs, imports, [param.type, ...similarTypes]);
|
|
235
|
+
|
|
236
|
+
return `${param.name}: ${similarTypes.join(' | ')}`;
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
return {
|
|
240
|
+
args: args.join(', '),
|
|
241
|
+
docs: [def.description],
|
|
242
|
+
name: methodName,
|
|
243
|
+
sectionHash: def.sectionHash,
|
|
244
|
+
sectionName: def.section,
|
|
245
|
+
sectionVersion: def.version,
|
|
246
|
+
type: formatType(registry, allDefs, def.type, imports)
|
|
247
|
+
};
|
|
248
|
+
}).sort((a, b) => a.name.localeCompare(b.name));
|
|
249
|
+
|
|
250
|
+
return {
|
|
251
|
+
items: allMethods,
|
|
252
|
+
name: section || 'unknown',
|
|
253
|
+
sectionHash: allMethods.length && allMethods[0].sectionHash,
|
|
254
|
+
sectionName: allMethods.length && allMethods[0].sectionName,
|
|
255
|
+
sectionVersion: allMethods.length && allMethods[0].sectionVersion
|
|
256
|
+
};
|
|
257
|
+
}).filter(({ items }) => items.length).sort((a, b) => a.name.localeCompare(b.name));
|
|
258
|
+
|
|
259
|
+
if (modules.length) {
|
|
260
|
+
imports.typesTypes['Observable'] = true;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
return generateCallsTypesTemplate({
|
|
264
|
+
headerType: 'chain',
|
|
265
|
+
imports,
|
|
266
|
+
isStrict,
|
|
267
|
+
modules,
|
|
268
|
+
types: [
|
|
269
|
+
...Object.keys(imports.localTypes).sort().map((packagePath): { file: string; types: string[] } => ({
|
|
270
|
+
file: packagePath.replace('@pezkuwi/types-augment', '@pezkuwi/types'),
|
|
271
|
+
types: Object.keys(imports.localTypes[packagePath])
|
|
272
|
+
})),
|
|
273
|
+
{
|
|
274
|
+
file: '@pezkuwi/api-base/types',
|
|
275
|
+
types: ['ApiTypes', 'AugmentedCall', 'DecoratedCallBase']
|
|
276
|
+
}
|
|
277
|
+
]
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export function generateDefaultRuntime (dest: string, data: HexString, extraTypes: ExtraTypes = {}, isStrict = false, customLookupDefinitions?: Definitions): void {
|
|
283
|
+
const { metadata, registry } = initMeta(data, extraTypes);
|
|
284
|
+
|
|
285
|
+
generateCallTypes(
|
|
286
|
+
registry,
|
|
287
|
+
metadata,
|
|
288
|
+
dest,
|
|
289
|
+
extraTypes,
|
|
290
|
+
isStrict,
|
|
291
|
+
customLookupDefinitions
|
|
292
|
+
);
|
|
293
|
+
}
|