Add lookup types to the registry (#4642)
* Add lookup types to the registry * Adjust
This commit is contained in:
@@ -6,4 +6,5 @@ import './consts';
|
|||||||
import './errors';
|
import './errors';
|
||||||
import './events';
|
import './events';
|
||||||
import './query';
|
import './query';
|
||||||
|
import './registry';
|
||||||
import './tx';
|
import './tx';
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// Copyright 2017-2022 @polkadot/api-augment authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import '@polkadot/types-augment/registry/substrate';
|
||||||
|
import '@polkadot/types-augment/registry/polkadot';
|
||||||
|
import '@polkadot/types-augment/registry/kusama';
|
||||||
@@ -6,4 +6,5 @@ import './consts';
|
|||||||
import './errors';
|
import './errors';
|
||||||
import './events';
|
import './events';
|
||||||
import './query';
|
import './query';
|
||||||
|
import './registry';
|
||||||
import './tx';
|
import './tx';
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
// Copyright 2017-2022 @polkadot/api-augment authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import '@polkadot/types-augment/registry/substrate';
|
||||||
|
import '@polkadot/types-augment/registry/polkadot';
|
||||||
@@ -6,4 +6,5 @@ import './consts';
|
|||||||
import './errors';
|
import './errors';
|
||||||
import './events';
|
import './events';
|
||||||
import './query';
|
import './query';
|
||||||
|
import './registry';
|
||||||
import './tx';
|
import './tx';
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// Copyright 2017-2022 @polkadot/api-augment authors & contributors
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
import '@polkadot/types-augment/registry/substrate';
|
||||||
@@ -25,6 +25,7 @@ const generateLookupDefsTmpl = Handlebars.compile(readTemplate('lookup/defs'));
|
|||||||
const generateLookupDefsNamedTmpl = Handlebars.compile(readTemplate('lookup/defs-named'));
|
const generateLookupDefsNamedTmpl = Handlebars.compile(readTemplate('lookup/defs-named'));
|
||||||
const generateLookupIndexTmpl = Handlebars.compile(readTemplate('lookup/index'));
|
const generateLookupIndexTmpl = Handlebars.compile(readTemplate('lookup/index'));
|
||||||
const generateLookupTypesTmpl = Handlebars.compile(readTemplate('lookup/types'));
|
const generateLookupTypesTmpl = Handlebars.compile(readTemplate('lookup/types'));
|
||||||
|
const generateRegistryTmpl = Handlebars.compile(readTemplate('interfaceRegistry'));
|
||||||
|
|
||||||
function generateParamType (registry: Registry, { name, type }: SiTypeParameter): string {
|
function generateParamType (registry: Registry, { name, type }: SiTypeParameter): string {
|
||||||
if (type.isSome) {
|
if (type.isSome) {
|
||||||
@@ -214,13 +215,34 @@ function generateLookupTypes (registry: Registry, filtered: [PortableType, TypeD
|
|||||||
writeFile(path.join(destDir, 'index.ts'), () => generateLookupIndexTmpl({ headerType: 'defs' }), true);
|
writeFile(path.join(destDir, 'index.ts'), () => generateLookupIndexTmpl({ headerType: 'defs' }), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateLookup (destDir: string, entries: [string | undefined, HexString][]): void {
|
function generateRegistry (registry: Registry, filtered: [PortableType, TypeDef][], destDir: string, subPath: string): void {
|
||||||
|
writeFile(path.join(destDir, `${subPath}.ts`), (): string => {
|
||||||
|
const items = filtered
|
||||||
|
.map(([, { lookupName }]) => lookupName)
|
||||||
|
.filter((n): n is string => !!n)
|
||||||
|
.sort()
|
||||||
|
.reduce((all: string[], n) => all.includes(n) ? all : all.concat(n), []);
|
||||||
|
const imports = createImports({}, { types: {} });
|
||||||
|
|
||||||
|
imports.lookupTypes = items.reduce((all, n) => ({ ...all, [n]: true }), {});
|
||||||
|
|
||||||
|
return generateRegistryTmpl({
|
||||||
|
headerType: 'defs',
|
||||||
|
imports,
|
||||||
|
items,
|
||||||
|
types: []
|
||||||
|
});
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateLookup (destDir: string, entries: [string, HexString][]): void {
|
||||||
entries.reduce<string[]>((exclude, [subPath, staticMeta]): string[] => {
|
entries.reduce<string[]>((exclude, [subPath, staticMeta]): string[] => {
|
||||||
const { lookup, registry } = initMeta(staticMeta).metadata.asLatest;
|
const { lookup, registry } = initMeta(staticMeta).metadata.asLatest;
|
||||||
const filtered = getFilteredTypes(lookup, exclude);
|
const filtered = getFilteredTypes(lookup, exclude);
|
||||||
|
|
||||||
generateLookupDefs(registry, filtered, destDir, subPath);
|
generateLookupDefs(registry, filtered, destDir, subPath);
|
||||||
generateLookupTypes(registry, filtered, destDir, subPath);
|
generateLookupTypes(registry, filtered, destDir, subPath);
|
||||||
|
generateRegistry(registry, filtered, destDir, subPath === 'lookup' ? 'registry' : `../registry/${subPath}`);
|
||||||
|
|
||||||
return exclude.concat(
|
return exclude.concat(
|
||||||
...filtered
|
...filtered
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ describe('getSimilarTypes', (): void => {
|
|||||||
genericTypes: {},
|
genericTypes: {},
|
||||||
ignoredTypes: [],
|
ignoredTypes: [],
|
||||||
localTypes: {},
|
localTypes: {},
|
||||||
|
lookupTypes: {},
|
||||||
metadataTypes: {},
|
metadataTypes: {},
|
||||||
primitiveTypes: {},
|
primitiveTypes: {},
|
||||||
typeToModule: {},
|
typeToModule: {},
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ describe('formatType', (): void => {
|
|||||||
genericTypes: {},
|
genericTypes: {},
|
||||||
ignoredTypes: [],
|
ignoredTypes: [],
|
||||||
localTypes: {},
|
localTypes: {},
|
||||||
|
lookupTypes: {},
|
||||||
metadataTypes: {},
|
metadataTypes: {},
|
||||||
primitiveTypes: {},
|
primitiveTypes: {},
|
||||||
typeToModule: {},
|
typeToModule: {},
|
||||||
|
|||||||
@@ -47,6 +47,10 @@ function extractImports ({ imports, types }: This): string[] {
|
|||||||
!NO_CODEC.includes(n) && !ON_CODEC.includes(n)
|
!NO_CODEC.includes(n) && !ON_CODEC.includes(n)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
file: '@polkadot/types/lookup',
|
||||||
|
types: Object.keys(imports.lookupTypes)
|
||||||
|
},
|
||||||
{
|
{
|
||||||
file: '@polkadot/types/types',
|
file: '@polkadot/types/types',
|
||||||
types: Object.keys(imports.typesTypes).filter((n) =>
|
types: Object.keys(imports.typesTypes).filter((n) =>
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ export interface TypeImports {
|
|||||||
genericTypes: TypeExist; // `import {} from '@polkadot/types/generic`
|
genericTypes: TypeExist; // `import {} from '@polkadot/types/generic`
|
||||||
ignoredTypes: string[]; // No need to import these types
|
ignoredTypes: string[]; // No need to import these types
|
||||||
localTypes: TypeExistMap; // `import {} from '../something'`
|
localTypes: TypeExistMap; // `import {} from '../something'`
|
||||||
|
lookupTypes: TypeExistMap; // `import {} from '@polkadot/types/lookup`
|
||||||
primitiveTypes: TypeExist; // `import {} from '@polkadot/types/primitive`
|
primitiveTypes: TypeExist; // `import {} from '@polkadot/types/primitive`
|
||||||
metadataTypes: TypeExist; // `import {} from '@polkadot/types/metadata`
|
metadataTypes: TypeExist; // `import {} from '@polkadot/types/metadata`
|
||||||
typesTypes: TypeExist; // `import {} from '@polkadot/types/types`
|
typesTypes: TypeExist; // `import {} from '@polkadot/types/types`
|
||||||
@@ -119,6 +120,7 @@ export function createImports (importDefinitions: Record<string, Record<string,
|
|||||||
|
|
||||||
return local;
|
return local;
|
||||||
}, {}),
|
}, {}),
|
||||||
|
lookupTypes: {},
|
||||||
metadataTypes: {},
|
metadataTypes: {},
|
||||||
primitiveTypes: {},
|
primitiveTypes: {},
|
||||||
typeToModule,
|
typeToModule,
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
|
||||||
|
/* eslint-disable */
|
||||||
|
|
||||||
|
import type { KusamaRuntimeNposCompactSolution24, KusamaRuntimeOriginCaller, KusamaRuntimeProxyType, KusamaRuntimeRuntime, KusamaRuntimeSessionKeys } from '@polkadot/types/lookup';
|
||||||
|
|
||||||
|
declare module '@polkadot/types/types/registry' {
|
||||||
|
export interface InterfaceTypes {
|
||||||
|
KusamaRuntimeNposCompactSolution24: KusamaRuntimeNposCompactSolution24;
|
||||||
|
KusamaRuntimeOriginCaller: KusamaRuntimeOriginCaller;
|
||||||
|
KusamaRuntimeProxyType: KusamaRuntimeProxyType;
|
||||||
|
KusamaRuntimeRuntime: KusamaRuntimeRuntime;
|
||||||
|
KusamaRuntimeSessionKeys: KusamaRuntimeSessionKeys;
|
||||||
|
} // InterfaceTypes
|
||||||
|
} // declare module
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user