Adjust object index typings (#5671)
* Adjust object index typings * CHANGELOG * Remove dot-notation overrides * Align overrides * Ordering * Revert lint formatting changes * Bump common
This commit is contained in:
@@ -19,6 +19,13 @@ import { isString, stringify } from '@polkadot/util';
|
||||
import { createImports, exportInterface, initMeta, readTemplate, writeFile } from '../util/index.js';
|
||||
import { typeEncoders } from './tsDef.js';
|
||||
|
||||
// Record<string, >
|
||||
interface ParsedDef {
|
||||
_set: Record<string, number>;
|
||||
|
||||
[key: string]: string | Record<string, string> | Record<string, number>;
|
||||
}
|
||||
|
||||
const WITH_TYPEDEF = false;
|
||||
|
||||
const generateLookupDefsTmpl = Handlebars.compile(readTemplate('lookup/defs'));
|
||||
@@ -67,9 +74,9 @@ function expandSet (parsed: Record<string, number>): string[] {
|
||||
);
|
||||
}
|
||||
|
||||
function expandObject (parsed: Record<string, string | Record<string, string>>): string[] {
|
||||
function expandObject (parsed: ParsedDef): string[] {
|
||||
if (parsed._set) {
|
||||
return expandSet(parsed._set as unknown as Record<string, number>);
|
||||
return expandSet(parsed._set);
|
||||
}
|
||||
|
||||
return formatObject(
|
||||
@@ -78,7 +85,7 @@ function expandObject (parsed: Record<string, string | Record<string, string>>):
|
||||
? expandType(v)
|
||||
: Array.isArray(v)
|
||||
? [`[${(v as string[]).map((e) => `'${e}'`).join(', ')}]`]
|
||||
: expandObject(v);
|
||||
: expandObject(v as ParsedDef);
|
||||
|
||||
inner.forEach((l, index): void => {
|
||||
all.push(`${
|
||||
@@ -98,7 +105,7 @@ function expandType (encoded: string): string[] {
|
||||
return [`'${encoded}'`];
|
||||
}
|
||||
|
||||
return expandObject(JSON.parse(encoded) as Record<string, string | Record<string, string>>);
|
||||
return expandObject(JSON.parse(encoded) as ParsedDef);
|
||||
}
|
||||
|
||||
function expandDefToString ({ lookupNameRoot, type }: TypeDef, indent: number): string {
|
||||
|
||||
@@ -114,7 +114,7 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr
|
||||
})
|
||||
.sort(compareName);
|
||||
|
||||
imports.typesTypes.Observable = true;
|
||||
imports.typesTypes['Observable'] = true;
|
||||
|
||||
return generateForMetaTemplate({
|
||||
headerType: 'chain',
|
||||
|
||||
@@ -126,7 +126,7 @@ export function generateRpcTypes (registry: TypeRegistry, importDefinitions: Rec
|
||||
};
|
||||
}).concat(...Object.values(additional)).sort((a, b) => a.name.localeCompare(b.name));
|
||||
|
||||
imports.typesTypes.Observable = true;
|
||||
imports.typesTypes['Observable'] = true;
|
||||
|
||||
return generateRpcTypesTemplate({
|
||||
headerType: 'chain',
|
||||
|
||||
@@ -141,7 +141,7 @@ export function generateCallTypes (registry: Registry, meta: Metadata, dest: str
|
||||
}).filter(({ items }) => items.length).sort((a, b) => a.name.localeCompare(b.name));
|
||||
|
||||
if (modules.length) {
|
||||
imports.typesTypes.Observable = true;
|
||||
imports.typesTypes['Observable'] = true;
|
||||
}
|
||||
|
||||
return generateCallsTypesTemplate({
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
// Copyright 2017-2023 @polkadot/typegen authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export type ExtraTypes = Record<string, Record<string, { runtime?: Record<string, any>, types: Record<string, any> }>>;
|
||||
export type ExtraTypes = Record<string, Record<string, {
|
||||
runtime?: Record<string, any>;
|
||||
types: Record<string, any>;
|
||||
}>>;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2023 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Constructor, Registry } from '@polkadot/types/types';
|
||||
import type { CodecClass, Registry } from '@polkadot/types/types';
|
||||
import type { UInt } from '@polkadot/types-codec';
|
||||
import type { TypeDef } from '@polkadot/types-create/types';
|
||||
import type { ModuleTypes, TypeImports } from './imports.js';
|
||||
@@ -69,7 +69,7 @@ export function getSimilarTypes (registry: Registry, definitions: Record<string,
|
||||
}
|
||||
}
|
||||
} else if (isChildClass(Enum, Clazz)) {
|
||||
const { defKeys, isBasic } = new (Clazz as Constructor)(registry) as Enum;
|
||||
const { defKeys, isBasic } = new (Clazz as CodecClass)(registry) as Enum;
|
||||
const keys = defKeys.filter((v) => !v.startsWith('__Unused'));
|
||||
|
||||
if (isBasic) {
|
||||
@@ -80,7 +80,7 @@ export function getSimilarTypes (registry: Registry, definitions: Record<string,
|
||||
}
|
||||
|
||||
possibleTypes.push('Uint8Array');
|
||||
} else if (isChildClass(AbstractInt as unknown as Constructor<UInt>, Clazz) || isChildClass(Compact, Clazz)) {
|
||||
} else if (isChildClass(AbstractInt as unknown as CodecClass<UInt>, Clazz) || isChildClass(Compact, Clazz)) {
|
||||
possibleTypes.push('AnyNumber', 'Uint8Array');
|
||||
} else if (isChildClass(GenericLookupSource, Clazz)) {
|
||||
possibleTypes.push('Address', 'AccountId', 'AccountIndex', 'LookupSource', 'string', 'Uint8Array');
|
||||
@@ -93,7 +93,7 @@ export function getSimilarTypes (registry: Registry, definitions: Record<string,
|
||||
} else if (isChildClass(Null, Clazz)) {
|
||||
possibleTypes.push('null');
|
||||
} else if (isChildClass(Struct, Clazz)) {
|
||||
const s = new (Clazz as Constructor)(registry) as Struct;
|
||||
const s = new (Clazz as CodecClass)(registry) as Struct;
|
||||
const obj = s.defKeys.map((key): string => `${key}?: any`).join('; ');
|
||||
|
||||
possibleTypes.push(`{ ${obj} }`, 'string', 'Uint8Array');
|
||||
|
||||
Reference in New Issue
Block a user