Bump dev (w/ eslint 8) (#4070)
* Bump dev (w/ eslint 8) * Additional linting * Additional * More lint fixes * Last batch * Additional * Cleanups
This commit is contained in:
@@ -64,9 +64,9 @@ const mockEnumSetObj = [
|
||||
|
||||
describe('BTreeSet', (): void => {
|
||||
describe('decoding', (): void => {
|
||||
const testDecode = (type: string, input: any, output: string): void =>
|
||||
const testDecode = (type: string, input: unknown, output: string): void =>
|
||||
it(`can decode from ${type}`, (): void => {
|
||||
const s = new BTreeSet(registry, U32, input);
|
||||
const s = new BTreeSet(registry, U32, input as string);
|
||||
|
||||
expect(s.toString()).toBe(output);
|
||||
});
|
||||
|
||||
@@ -31,9 +31,9 @@ const mockU32U32MapUint8Array = Uint8Array.from([16, 4, 49, 2, 0, 0, 0, 8, 50, 5
|
||||
|
||||
describe('CodecMap', (): void => {
|
||||
describe('decoding', (): void => {
|
||||
const testDecode = (type: string, input: any, output: string): void =>
|
||||
const testDecode = (type: string, input: unknown, output: string): void =>
|
||||
it(`can decode from ${type}`, (): void => {
|
||||
const s = new CodecMap(registry, Text, U32, input);
|
||||
const s = new CodecMap(registry, Text, U32, input as string);
|
||||
|
||||
expect(s.toString()).toBe(output);
|
||||
});
|
||||
|
||||
@@ -36,7 +36,7 @@ function decodeMapFromU8a<K extends Codec, V extends Codec> (registry: Registry,
|
||||
function decodeMapFromMap<K extends Codec, V extends Codec> (registry: Registry, KeyClass: Constructor<K>, ValClass: Constructor<V>, value: Map<any, any>): Map<K, V> {
|
||||
const output = new Map<K, V>();
|
||||
|
||||
value.forEach((val: any, key: any) => {
|
||||
value.forEach((val: unknown, key: unknown) => {
|
||||
const isComplex = KeyClass.prototype instanceof AbstractArray ||
|
||||
KeyClass.prototype instanceof Struct ||
|
||||
KeyClass.prototype instanceof Enum;
|
||||
@@ -45,7 +45,7 @@ function decodeMapFromMap<K extends Codec, V extends Codec> (registry: Registry,
|
||||
output.set(
|
||||
key instanceof KeyClass
|
||||
? key
|
||||
: new KeyClass(registry, isComplex ? JSON.parse(key) : key),
|
||||
: new KeyClass(registry, isComplex ? JSON.parse(key as string) : key),
|
||||
val instanceof ValClass
|
||||
? val
|
||||
: new ValClass(registry, val)
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
// Copyright 2017-2021 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { CodecTo } from '../types';
|
||||
import type { AnyU8a, CodecTo } from '../types';
|
||||
|
||||
import { TypeRegistry } from '../create';
|
||||
import { Raw } from '.';
|
||||
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
const testDecode = (type: string, input: any, expected: string): void =>
|
||||
const testDecode = (type: string, input: AnyU8a, expected: string): void =>
|
||||
it(`can decode from ${type}`, (): void => {
|
||||
const e = new Raw(registry, input);
|
||||
|
||||
expect(e.toString()).toBe(expected);
|
||||
});
|
||||
|
||||
const testEncode = (to: CodecTo, expected: any): void =>
|
||||
const testEncode = (to: CodecTo, expected: AnyU8a): void =>
|
||||
it(`can encode ${to}`, (): void => {
|
||||
const e = new Raw(registry, [1, 2, 3, 4, 5]);
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ export class Raw extends Uint8Array implements IU8a {
|
||||
!this.some((value, index) => value !== other[index]);
|
||||
}
|
||||
|
||||
return this.eq(u8aToU8a(other as any));
|
||||
return this.eq(u8aToU8a(other as string));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -156,7 +156,7 @@ export class CodecSet extends Set<string> implements ISet<string> {
|
||||
super.add(key);
|
||||
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Compares the value of the input to see if there is a match
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
import type { VoteThreshold } from '../interfaces/elections';
|
||||
import type { BlockNumber } from '../interfaces/runtime';
|
||||
import type { CodecTo } from '../types';
|
||||
import type { AnyTupleValue } from './Tuple';
|
||||
|
||||
import rpcMetadata from '@polkadot/types-support/metadata/static-substrate';
|
||||
|
||||
@@ -25,7 +26,7 @@ describe('Tuple', (): void => {
|
||||
});
|
||||
|
||||
describe('decoding', (): void => {
|
||||
const testDecode = (type: string, input: any): void =>
|
||||
const testDecode = (type: string, input: AnyTupleValue): void =>
|
||||
it(`can decode from ${type}`, (): void => {
|
||||
const t = new Tuple(registry, [
|
||||
Text,
|
||||
|
||||
@@ -8,7 +8,7 @@ import { isFunction, isHex, isString, isU8a, stringify, u8aConcat, u8aToU8a } fr
|
||||
import { AbstractArray } from './AbstractArray';
|
||||
import { decodeU8a, mapToTypeMap, typeToConstructor } from './utils';
|
||||
|
||||
type AnyTuple = AnyU8a | string | (Codec | AnyU8a | AnyNumber | AnyString | undefined | null)[];
|
||||
export type AnyTupleValue = AnyU8a | (Codec | AnyU8a | AnyNumber | AnyString | undefined | null)[];
|
||||
|
||||
type TupleConstructors = Constructor[] | {
|
||||
[index: string]: Constructor;
|
||||
@@ -21,7 +21,7 @@ type TupleTypes = TupleType[] | {
|
||||
};
|
||||
|
||||
/** @internal */
|
||||
function decodeTuple (registry: Registry, _Types: TupleConstructors, value?: AnyTuple): Codec[] {
|
||||
function decodeTuple (registry: Registry, _Types: TupleConstructors, value?: AnyTupleValue): Codec[] {
|
||||
if (isU8a(value) || isHex(value)) {
|
||||
return decodeU8a(registry, u8aToU8a(value), _Types);
|
||||
}
|
||||
@@ -54,7 +54,7 @@ function decodeTuple (registry: Registry, _Types: TupleConstructors, value?: Any
|
||||
export class Tuple extends AbstractArray<Codec> implements ITuple<Codec[]> {
|
||||
private _Types: TupleConstructors;
|
||||
|
||||
constructor (registry: Registry, Types: TupleTypes | TupleType, value?: AnyTuple) {
|
||||
constructor (registry: Registry, Types: TupleTypes | TupleType, value?: AnyTupleValue) {
|
||||
const Clazzes = Array.isArray(Types)
|
||||
? Types.map((t) => typeToConstructor(registry, t))
|
||||
: isFunction(Types) || isString(Types)
|
||||
@@ -68,7 +68,7 @@ export class Tuple extends AbstractArray<Codec> implements ITuple<Codec[]> {
|
||||
|
||||
public static with (Types: TupleTypes | TupleType): Constructor<Tuple> {
|
||||
return class extends Tuple {
|
||||
constructor (registry: Registry, value?: AnyTuple) {
|
||||
constructor (registry: Registry, value?: AnyTupleValue) {
|
||||
super(registry, Types, value);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -13,22 +13,23 @@ function hasMismatch (a?: unknown, b?: unknown): boolean {
|
||||
);
|
||||
}
|
||||
|
||||
function notEntry (value: any): boolean {
|
||||
function notEntry (value: unknown): boolean {
|
||||
return !Array.isArray(value) || value.length !== 2;
|
||||
}
|
||||
|
||||
function compareMapArray (a: Map<any, any>, b: [any, any][]): boolean {
|
||||
function compareMapArray (a: Map<unknown, unknown>, b: [unknown, unknown][]): boolean {
|
||||
// equal number of entries and each entry in the array should match
|
||||
return (a.size === b.length) && !b.some((entry): boolean =>
|
||||
notEntry(entry) || hasMismatch(a.get(entry[0]), entry[1])
|
||||
return (a.size === b.length) && !b.some((entry) =>
|
||||
notEntry(entry) ||
|
||||
hasMismatch(a.get(entry[0]), entry[1])
|
||||
);
|
||||
}
|
||||
|
||||
// NOTE These are used internally and when comparing objects, expects that
|
||||
// when the second is an Map<string, Codec> that the first has to be as well
|
||||
export function compareMap (a: Map<any, any>, b?: unknown): boolean {
|
||||
export function compareMap (a: Map<unknown, unknown>, b?: unknown): boolean {
|
||||
if (Array.isArray(b)) {
|
||||
return compareMapArray(a, b);
|
||||
return compareMapArray(a, b as [unknown, unknown][]);
|
||||
} else if (b instanceof Map) {
|
||||
return compareMapArray(a, [...b.entries()]);
|
||||
} else if (isObject(b)) {
|
||||
|
||||
@@ -88,14 +88,13 @@ function _decodeSet (value: TypeDef, details: Record<string, number>): TypeDef {
|
||||
// decode a struct, set or enum
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
function _decodeStruct (value: TypeDef, type: string, _: string, count: number): TypeDef {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const parsed: Record<string, any> = JSON.parse(type);
|
||||
const parsed = JSON.parse(type) as Record<string, unknown> & { _alias: string };
|
||||
const keys = Object.keys(parsed);
|
||||
|
||||
if (keys.length === 1 && keys[0] === '_enum') {
|
||||
return _decodeEnum(value, parsed[keys[0]], count);
|
||||
return _decodeEnum(value, parsed[keys[0]] as string[], count);
|
||||
} else if (keys.length === 1 && keys[0] === '_set') {
|
||||
return _decodeSet(value, parsed[keys[0]]);
|
||||
return _decodeSet(value, parsed[keys[0]] as Record<string, number>);
|
||||
}
|
||||
|
||||
value.alias = parsed._alias
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
/* eslint-disable sort-keys */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
|
||||
import type { BlockValue } from './Block';
|
||||
|
||||
import block00300 from '@polkadot/types-support/json/SignedBlock.003.00.json';
|
||||
import metadataStatic from '@polkadot/types-support/metadata/static-substrate';
|
||||
|
||||
@@ -11,6 +13,12 @@ import { TypeRegistry } from '../create';
|
||||
import { Metadata } from '../metadata';
|
||||
import { GenericBlock as Block } from './Block';
|
||||
|
||||
interface BlockJson {
|
||||
result: {
|
||||
block: BlockValue;
|
||||
};
|
||||
}
|
||||
|
||||
const registry = new TypeRegistry();
|
||||
const metadata = new Metadata(registry, metadataStatic);
|
||||
|
||||
@@ -30,9 +38,9 @@ describe('Block', (): void => {
|
||||
});
|
||||
|
||||
it('re-encodes digest items correctly', (): void => {
|
||||
const digest = new Block(registry, block00300.result.block).header.digest;
|
||||
const digest = new Block(registry, (block00300 as BlockJson).result.block).header.digest;
|
||||
|
||||
expect(digest.logs[0].toHex()).toEqual(block00300.result.block.header.digest.logs[0]);
|
||||
expect(digest.logs[1].toHex()).toEqual(block00300.result.block.header.digest.logs[1]);
|
||||
expect(digest.logs[0].toHex()).toEqual((block00300 as BlockJson).result.block.header?.digest?.logs[0]);
|
||||
expect(digest.logs[1].toHex()).toEqual((block00300 as BlockJson).result.block.header?.digest?.logs[1]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -65,7 +65,7 @@ export class MetadataVersioned extends Struct {
|
||||
*/
|
||||
#metadata = (): MetadataAll => {
|
||||
return this.get('metadata') as MetadataAll;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Returns the wrapped metadata as a limited calls-only (latest) version
|
||||
|
||||
@@ -76,7 +76,7 @@ export type __ToTuple<O extends Codec[]> =
|
||||
: O[0]
|
||||
: Null;
|
||||
|
||||
export type __CodecFirst<K extends unknown> =
|
||||
export type __CodecFirst<K> =
|
||||
K extends keyof InterfaceTypes
|
||||
? InterfaceTypes[K]
|
||||
: K extends unknown[]
|
||||
@@ -85,7 +85,7 @@ export type __CodecFirst<K extends unknown> =
|
||||
? __ToStruct<K>
|
||||
: Codec;
|
||||
|
||||
export type __CodecsNext<K extends unknown, C extends Codec[]> =
|
||||
export type __CodecsNext<K, C extends Codec[]> =
|
||||
K extends __WrapOne
|
||||
? C extends [Codec, ...infer X]
|
||||
? [__MapWrapOne<C[0]>[K], ...X]
|
||||
|
||||
Reference in New Issue
Block a user