Bump deps w/ eslint (#2302)
* Bump deps w/ eslint * Additional cleanups * Additional * @polkadot/types done * Additional * @polkadot/typegen done * Additional * @polkadot/rpc-core done * Additional * Additional * Additional * docs * @polkadot/api-derive done * @polkadot/api done * @polkadot/api-contracts done * Update tests
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Registry } from '@polkadot/types/types';
|
||||
import { AnyNumber, Registry } from '@polkadot/types/types';
|
||||
|
||||
import { assert } from '@polkadot/util';
|
||||
|
||||
@@ -11,7 +11,7 @@ import U32 from '@polkadot/types/primitive/U32';
|
||||
export const MAGIC_NUMBER = 0x6174656d; // `meta`, reversed for Little Endian encoding
|
||||
|
||||
export default class MagicNumber extends U32 {
|
||||
constructor (registry: Registry, value?: any) {
|
||||
constructor (registry: Registry, value?: AnyNumber) {
|
||||
super(registry, value);
|
||||
|
||||
if (!this.isEmpty) {
|
||||
|
||||
@@ -33,13 +33,13 @@ type MetaAsX = 'asV0' | 'asV1' | 'asV2' | 'asV3' | 'asV4' | 'asV5' | 'asV6' | 'a
|
||||
* The versioned runtime metadata as a decoded structure
|
||||
*/
|
||||
export default class MetadataVersioned extends Struct {
|
||||
readonly #converted: Map<number, MetaMapped> = new Map();
|
||||
readonly #converted = new Map<number, MetaMapped>();
|
||||
|
||||
constructor (registry: Registry, value?: any) {
|
||||
constructor (registry: Registry, value?: unknown) {
|
||||
super(registry, {
|
||||
magicNumber: MagicNumber,
|
||||
metadata: 'MetadataAll'
|
||||
}, value);
|
||||
}, value as Map<unknown, unknown>);
|
||||
|
||||
registry.setMetadata(this);
|
||||
}
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
type Types = string | Types[];
|
||||
|
||||
/** @internal */
|
||||
export default function flattenUniq (list: any[]): any[] {
|
||||
const flat = list.reduce((result, entry): any[] => {
|
||||
export default function flattenUniq (list: Types[]): string[] {
|
||||
const flat = list.reduce((result: string[], entry): string[] => {
|
||||
return result.concat(
|
||||
Array.isArray(entry)
|
||||
? flattenUniq(entry)
|
||||
@@ -13,6 +15,6 @@ export default function flattenUniq (list: any[]): any[] {
|
||||
}, []);
|
||||
|
||||
return [...new Set(flat)]
|
||||
.filter((value: any): any => value)
|
||||
.filter((value: string) => value)
|
||||
.sort();
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import getUniqTypes from './getUniqTypes';
|
||||
import Metadata from '../Metadata';
|
||||
|
||||
/** @internal */
|
||||
export function decodeLatestSubstrate<Modules extends Codec> (registry: Registry, version: number, rpcData: string, staticSubstrate: object): void {
|
||||
export function decodeLatestSubstrate<Modules extends Codec> (registry: Registry, version: number, rpcData: string, staticSubstrate: Record<string, unknown>): void {
|
||||
it('decodes latest substrate properly', (): void => {
|
||||
const metadata = new Metadata(registry, rpcData);
|
||||
|
||||
@@ -49,14 +49,14 @@ export function defaultValues (registry: Registry, rpcData: string, withThrow =
|
||||
metadata.asLatest.modules.filter(({ storage }): boolean => storage.isSome).forEach((mod): void => {
|
||||
mod.storage.unwrap().items.forEach(({ fallback, name, type }): void => {
|
||||
const inner = unwrapStorageType(type);
|
||||
const location = `${mod.name}.${name}: ${inner}`;
|
||||
const location = `${mod.name.toString()}.${name.toString()}: ${inner}`;
|
||||
|
||||
it(`creates default types for ${location}`, (): void => {
|
||||
expect((): void => {
|
||||
try {
|
||||
registry.createType(inner, fallback);
|
||||
} catch (error) {
|
||||
const message = `${location}:: ${error.message}`;
|
||||
const message = `${location}:: ${(error as Error).message}`;
|
||||
|
||||
if (withThrow) {
|
||||
throw new Error(message);
|
||||
|
||||
@@ -26,7 +26,7 @@ function mapCalls (registry: Registry, _calls: Option<Vec<FunctionMetadataLatest
|
||||
})
|
||||
)
|
||||
: null
|
||||
);
|
||||
) as Option<Vec<FunctionMetadataLatest>>;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
|
||||
@@ -8,9 +8,11 @@ import { getTypeDef } from '@polkadot/types/create';
|
||||
|
||||
import flattenUniq from './flattenUniq';
|
||||
|
||||
type Extracted = string | Extracted[];
|
||||
|
||||
/** @internal */
|
||||
function extractTypes (types: string[]): any[] {
|
||||
return types.map((type): any => {
|
||||
function extractTypes (types: string[]): Extracted[] {
|
||||
return types.map((type): Extracted => {
|
||||
const decoded = getTypeDef(type);
|
||||
|
||||
switch (decoded.info) {
|
||||
@@ -38,12 +40,10 @@ function extractTypes (types: string[]): any[] {
|
||||
|
||||
/** @internal */
|
||||
export default function validateTypes (registry: Registry, types: string[], throwError: boolean): void {
|
||||
const missing = flattenUniq(extractTypes(types)).filter((type): boolean =>
|
||||
!registry.hasType(type)
|
||||
);
|
||||
const missing = flattenUniq(extractTypes(types)).filter((type) => !registry.hasType(type));
|
||||
|
||||
if (missing.length !== 0) {
|
||||
const message = `Unknown types found, no types for ${missing}`;
|
||||
const message = `Unknown types found, no types for ${missing.join(', ')}`;
|
||||
|
||||
if (throwError) {
|
||||
throw new Error(message);
|
||||
|
||||
Reference in New Issue
Block a user