Adjust interfaces for cleaner esnext usage (#2833)
* Adjust interfaces for cleaner esnext usage * Swap out esnext
This commit is contained in:
@@ -20,6 +20,7 @@ describe('getSimilarTypes', (): void => {
|
||||
genericTypes: {},
|
||||
ignoredTypes: [],
|
||||
localTypes: {},
|
||||
metadataTypes: {},
|
||||
primitiveTypes: {},
|
||||
typeToModule: {},
|
||||
typesTypes: {}
|
||||
|
||||
@@ -13,6 +13,7 @@ describe('formatType', (): void => {
|
||||
genericTypes: {},
|
||||
ignoredTypes: [],
|
||||
localTypes: {},
|
||||
metadataTypes: {},
|
||||
primitiveTypes: {},
|
||||
typeToModule: {},
|
||||
typesTypes: {}
|
||||
|
||||
@@ -20,8 +20,6 @@ interface This {
|
||||
}[]
|
||||
}
|
||||
|
||||
const TYPES_NON_PRIMITIVE = ['Metadata'];
|
||||
|
||||
export const HEADER = (type: 'chain' | 'defs'): string => `// Auto-generated via \`yarn polkadot-types-from-${type}\`, do not edit\n/* eslint-disable */\n\n`;
|
||||
|
||||
Handlebars.registerPartial({
|
||||
@@ -34,8 +32,8 @@ Handlebars.registerHelper({
|
||||
const { imports, types } = this as unknown as This;
|
||||
const defs = [
|
||||
{
|
||||
file: '@polkadot/types/types',
|
||||
types: Object.keys(imports.typesTypes)
|
||||
file: '@polkadot/metadata',
|
||||
types: Object.keys(imports.metadataTypes)
|
||||
},
|
||||
{
|
||||
file: '@polkadot/types/codec',
|
||||
@@ -53,15 +51,11 @@ Handlebars.registerHelper({
|
||||
},
|
||||
{
|
||||
file: '@polkadot/types/primitive',
|
||||
types: Object
|
||||
.keys(imports.primitiveTypes)
|
||||
.filter((name) => !TYPES_NON_PRIMITIVE.includes(name))
|
||||
types: Object.keys(imports.primitiveTypes)
|
||||
},
|
||||
{
|
||||
file: '@polkadot/types',
|
||||
types: Object
|
||||
.keys(imports.primitiveTypes)
|
||||
.filter((name) => TYPES_NON_PRIMITIVE.includes(name))
|
||||
file: '@polkadot/types/types',
|
||||
types: Object.keys(imports.typesTypes)
|
||||
},
|
||||
...types
|
||||
];
|
||||
|
||||
@@ -28,6 +28,7 @@ export interface TypeImports {
|
||||
ignoredTypes: string[]; // No need to import these types
|
||||
localTypes: TypeExistMap; // `import {} from '../something'`
|
||||
primitiveTypes: TypeExist; // `import {} from '@polkadot/types/primitive`
|
||||
metadataTypes: TypeExist; // `import {} from '@polkadot/metadata`
|
||||
typesTypes: TypeExist; // `import {} from '@polkadot/types/types`
|
||||
definitions: Record<string, ModuleTypes>; // all definitions
|
||||
typeToModule: Record<string, string>;
|
||||
@@ -37,20 +38,22 @@ export interface TypeImports {
|
||||
// imports in the output file, dep-duped and sorted
|
||||
/** @internal */
|
||||
export function setImports (allDefs: Record<string, ModuleTypes>, imports: TypeImports, types: string[]): void {
|
||||
const { codecTypes, extrinsicTypes, genericTypes, ignoredTypes, localTypes, primitiveTypes, typesTypes } = imports;
|
||||
const { codecTypes, extrinsicTypes, genericTypes, ignoredTypes, localTypes, metadataTypes, primitiveTypes, typesTypes } = imports;
|
||||
|
||||
types.forEach((type): void => {
|
||||
if (ignoredTypes.includes(type)) {
|
||||
// do nothing
|
||||
} else if (['AnyNumber', 'CallFunction', 'Codec', 'IExtrinsic', 'ITuple'].includes(type)) {
|
||||
typesTypes[type] = true;
|
||||
} else if (type === 'Metadata') {
|
||||
metadataTypes[type] = true;
|
||||
} else if ((codecClasses as Record<string, unknown>)[type]) {
|
||||
codecTypes[type] = true;
|
||||
} else if ((extrinsicClasses as Record<string, unknown>)[type]) {
|
||||
extrinsicTypes[type] = true;
|
||||
} else if ((genericClasses as Record<string, unknown>)[type]) {
|
||||
genericTypes[type] = true;
|
||||
} else if ((primitiveClasses as Record<string, unknown>)[type] || type === 'Metadata') {
|
||||
} else if ((primitiveClasses as Record<string, unknown>)[type]) {
|
||||
primitiveTypes[type] = true;
|
||||
} else if (type.includes('<') || type.includes('(') || (type.includes('[') && !type.includes('|'))) {
|
||||
// If the type is a bit special (tuple, fixed u8, nested type...), then we
|
||||
@@ -118,6 +121,7 @@ export function createImports (importDefinitions: Record<string, Record<string,
|
||||
|
||||
return local;
|
||||
}, {}),
|
||||
metadataTypes: {},
|
||||
primitiveTypes: {},
|
||||
typeToModule,
|
||||
typesTypes: {}
|
||||
|
||||
Reference in New Issue
Block a user