Re-enable esnext (with mjs) (#2836)

* Re-enable esnext (with mjs)

* Updates

* Adjust
This commit is contained in:
Jaco Greeff
2020-11-10 13:58:11 +01:00
committed by GitHub
parent 143febf807
commit a8a956c85d
102 changed files with 301 additions and 317 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ import { compareArray } from './utils';
* specific encoding/decoding on top of the base type.
* @noInheritDoc
*/
export default abstract class AbstractArray<T extends Codec> extends Array<T> implements Codec {
export abstract class AbstractArray<T extends Codec> extends Array<T> implements Codec {
public readonly registry: Registry;
protected constructor (registry: Registry, ...values: T[]) {
+1 -1
View File
@@ -61,7 +61,7 @@ function decodeAbstractInt (value: AnyNumber, bitLength: UIntBitLength, isNegati
*/
// TODO:
// - Apart from encoding/decoding we don't actually keep check on the sizes, is this good enough?
export default abstract class AbstractInt extends BN implements Codec {
export abstract class AbstractInt extends BN implements Codec {
public readonly registry: Registry;
readonly #bitLength: UIntBitLength;
+1 -3
View File
@@ -4,9 +4,7 @@
import { TypeRegistry } from '../create';
import Text from '../primitive/Text';
import U32 from '../primitive/U32';
import Struct from './Struct';
import BTreeMap from './BTreeMap';
import { BTreeMap, Struct } from '.';
const registry = new TypeRegistry();
+2 -2
View File
@@ -3,9 +3,9 @@
import { Constructor, Codec, InterfaceTypes, Registry } from '../types';
import CodecMap from './Map';
import { CodecMap } from './Map';
export default class BTreeMap<K extends Codec = Codec, V extends Codec = Codec> extends CodecMap<K, V> {
export class BTreeMap<K extends Codec = Codec, V extends Codec = Codec> extends CodecMap<K, V> {
public static with<K extends Codec, V extends Codec> (keyType: Constructor<K> | keyof InterfaceTypes, valType: Constructor<V> | keyof InterfaceTypes): Constructor<CodecMap<K, V>> {
return class extends BTreeMap<K, V> {
constructor (registry: Registry, value?: Uint8Array | string | Map<any, any>) {
+3 -3
View File
@@ -1,13 +1,13 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { CodecTo } from '../types';
import { TypeRegistry } from '../create';
import Text from '../primitive/Text';
import U32 from '../primitive/U32';
import Struct from './Struct';
import { CodecTo } from '../types';
import BTreeSet from './BTreeSet';
import { BTreeSet, Struct } from '.';
const registry = new TypeRegistry();
+1 -1
View File
@@ -78,7 +78,7 @@ function decodeSet<V extends Codec = Codec> (registry: Registry, valType: Constr
throw new Error('BTreeSet: cannot decode type');
}
export default class BTreeSet<V extends Codec = Codec> extends Set<V> implements Codec {
export class BTreeSet<V extends Codec = Codec> extends Set<V> implements Codec {
public readonly registry: Registry;
readonly #ValClass: Constructor<V>;
+1 -1
View File
@@ -8,7 +8,7 @@ import { AnyJson, BareOpts, Codec, Registry } from '../types';
* @name Base
* @description A type extends the Base class, when it holds a value
*/
export default abstract class Base<T extends Codec> implements Codec {
export abstract class Base<T extends Codec> implements Codec {
public readonly registry: Registry;
protected readonly _raw: T;
+3 -3
View File
@@ -4,9 +4,9 @@
import BN from 'bn.js';
import { TypeRegistry } from '../create';
import Moment from './Date';
import U32 from '../primitive/U32';
import Compact from './Compact';
import { CodecDate } from './Date';
import { Compact } from '.';
describe('Compact', (): void => {
const registry = new TypeRegistry();
@@ -50,7 +50,7 @@ describe('Compact', (): void => {
it('constructs properly via number as Moment', (): void => {
expect(
new (Compact.with(Moment))(registry, 1537968546).toString().startsWith('Wed Sep 26 2018') // The time depends on the timezone this test is run in
new (Compact.with(CodecDate))(registry, 1537968546).toString().startsWith('Wed Sep 26 2018') // The time depends on the timezone this test is run in
).toBe(true);
});
});
+1 -1
View File
@@ -24,7 +24,7 @@ export interface CompactEncodable extends Codec {
* used by other types to add length-prefixed encoding, or in the case of wrapped types, taking
* a number and making the compact representation thereof
*/
export default class Compact<T extends CompactEncodable> implements ICompact<T> {
export class Compact<T extends CompactEncodable> implements ICompact<T> {
public readonly registry: Registry;
readonly #Type: Constructor<T>;
+1 -1
View File
@@ -7,7 +7,7 @@ import BN from 'bn.js';
import { TypeRegistry } from '../create';
import U64 from '../primitive/U64';
import CodecDate from './Date';
import { CodecDate } from './Date';
describe('Date', (): void => {
const registry = new TypeRegistry();
+1 -1
View File
@@ -21,7 +21,7 @@ const BITLENGTH: UIntBitLength = 64;
* and has all the methods available that are applicable to any `Date`
* @noInheritDoc
*/
export default class CodecDate extends Date implements Codec {
export class CodecDate extends Date implements Codec {
public readonly registry: Registry;
constructor (registry: Registry, value: CodecDate | Date | AnyNumber = 0) {
+1 -1
View File
@@ -9,7 +9,7 @@ import { TypeRegistry } from '../create';
import Null from '../primitive/Null';
import Text from '../primitive/Text';
import U32 from '../primitive/U32';
import Enum from './Enum';
import { Enum } from '.';
describe('Enum', (): void => {
const registry = new TypeRegistry();
+2 -2
View File
@@ -8,7 +8,7 @@ import { assert, hexToU8a, isHex, isNumber, isObject, isString, isU8a, isUndefin
import Null from '../primitive/Null';
import { mapToTypeMap } from './utils';
import Struct from './Struct';
import { Struct } from './Struct';
// export interface, this is used in Enum.with, so required as public by TS
export interface EnumConstructor<T = Codec> {
@@ -117,7 +117,7 @@ function decodeEnum (registry: Registry, def: TypesDef, value?: any, index?: num
// TODO:
// - As per Enum, actually use TS enum
// - It should rather probably extend Enum instead of copying code
export default class Enum implements Codec {
export class Enum implements Codec {
public readonly registry: Registry;
readonly #def: TypesDef;
+1 -3
View File
@@ -4,9 +4,7 @@
import { TypeRegistry } from '../create';
import Text from '../primitive/Text';
import U32 from '../primitive/U32';
import Struct from './Struct';
import HashMap from './HashMap';
import { HashMap, Struct } from '.';
const registry = new TypeRegistry();
+2 -2
View File
@@ -3,9 +3,9 @@
import { Constructor, Codec, InterfaceTypes, Registry } from '../types';
import CodecMap from './Map';
import { CodecMap } from './Map';
export default class HashMap<K extends Codec = Codec, V extends Codec = Codec> extends CodecMap<K, V> {
export class HashMap<K extends Codec = Codec, V extends Codec = Codec> extends CodecMap<K, V> {
public static with<K extends Codec, V extends Codec> (keyType: Constructor<K> | keyof InterfaceTypes, valType: Constructor<V> | keyof InterfaceTypes): Constructor<CodecMap<K, V>> {
return class extends HashMap<K, V> {
constructor (registry: Registry, value?: Uint8Array | string | Map<any, any>) {
+1 -1
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import { TypeRegistry } from '../create';
import Int from './Int';
import { Int } from '.';
describe('Int', (): void => {
const registry = new TypeRegistry();
+2 -2
View File
@@ -3,7 +3,7 @@
import { AnyNumber, Constructor, Registry } from '../types';
import AbstractInt, { UIntBitLength } from './AbstractInt';
import { AbstractInt, UIntBitLength } from './AbstractInt';
/**
* @name Int
@@ -15,7 +15,7 @@ import AbstractInt, { UIntBitLength } from './AbstractInt';
* is available here.
* @noInheritDoc
*/
export default class Int extends AbstractInt {
export class Int extends AbstractInt {
constructor (registry: Registry, value: AnyNumber = 0, bitLength?: UIntBitLength) {
super(registry, value, bitLength, true);
}
+1 -1
View File
@@ -21,7 +21,7 @@ function decodeJson (value?: Record<string, unknown> | null): [string, any][] {
* i.e. no hex decoding. Unlike a struct, this waps a JSON object with unknown keys
* @noInheritDoc
*/
export default class StructAny extends Map<string, any> implements Codec {
export class Json extends Map<string, any> implements Codec {
public readonly registry: Registry;
constructor (registry: Registry, value?: Record<string, unknown> | null) {
+1 -1
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import { TypeRegistry } from '../create/registry';
import Linkage from './Linkage';
import { Linkage } from '.';
const registry = new TypeRegistry();
+5 -5
View File
@@ -3,10 +3,10 @@
import { Constructor, Codec, InterfaceTypes, Registry } from '../types';
import Option from './Option';
import Struct from './Struct';
import Tuple from './Tuple';
import Vec from './Vec';
import { Option } from './Option';
import { Struct } from './Struct';
import { Tuple } from './Tuple';
import { Vec } from './Vec';
type TypeWithValues = [Constructor, any[]];
@@ -16,7 +16,7 @@ const EMPTY = new Uint8Array();
* @name Linkage
* @description The wrapper for the result from a LinkedMap
*/
export default class Linkage<T extends Codec> extends Struct {
export class Linkage<T extends Codec> extends Struct {
constructor (registry: Registry, Type: Constructor | keyof InterfaceTypes, value?: unknown) {
super(registry, {
previous: Option.with(Type),
+3 -2
View File
@@ -1,12 +1,13 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { CodecTo } from '../types';
import { TypeRegistry } from '../create';
import Text from '../primitive/Text';
import U32 from '../primitive/U32';
import { CodecTo } from '../types';
import CodecMap from './Map';
import { CodecMap } from '.';
const registry = new TypeRegistry();
const mockU32TextMap = new Map<Text, U32>();
+1 -1
View File
@@ -87,7 +87,7 @@ function decodeMap<K extends Codec = Codec, V extends Codec = Codec> (registry:
throw new Error('Map: cannot decode type');
}
export default class CodecMap<K extends Codec = Codec, V extends Codec = Codec> extends Map<K, V> implements Codec {
export class CodecMap<K extends Codec = Codec, V extends Codec = Codec> extends Map<K, V> implements Codec {
public readonly registry: Registry;
readonly #KeyClass: Constructor<K>;
+1 -1
View File
@@ -5,7 +5,7 @@ import { TypeRegistry } from '../create';
import Bytes from '../primitive/Bytes';
import U32 from '../primitive/U32';
import Text from '../primitive/Text';
import Option from './Option';
import { Option } from '.';
const registry = new TypeRegistry();
+1 -1
View File
@@ -47,7 +47,7 @@ function decodeOption (registry: Registry, typeName: Constructor | keyof Interfa
* implements that - decodes, checks for optionality and wraps the required structure
* with a value if/as required/found.
*/
export default class Option<T extends Codec> implements Codec {
export class Option<T extends Codec> implements Codec {
public readonly registry: Registry;
readonly #Type: Constructor<T>;
+1 -1
View File
@@ -4,7 +4,7 @@
import { CodecTo } from '../types';
import { TypeRegistry } from '../create';
import Raw from './Raw';
import { Raw } from '.';
const registry = new TypeRegistry();
+1 -1
View File
@@ -24,7 +24,7 @@ function decodeU8a (value?: any): Uint8Array {
* actual lengths instead of used directly.
* @noInheritDoc
*/
export default class Raw extends Uint8Array implements IU8a {
export class Raw extends Uint8Array implements IU8a {
public readonly registry: Registry;
constructor (registry: Registry, value?: AnyU8a) {
+1 -1
View File
@@ -5,7 +5,7 @@ import { hexToString } from '@polkadot/util';
import { u32, Text } from '../primitive';
import { TypeRegistry } from '../create';
import Result from './Result';
import { Result } from '.';
describe('Result', (): void => {
const registry = new TypeRegistry();
+2 -2
View File
@@ -5,14 +5,14 @@ import { Codec, Constructor, InterfaceTypes, Registry } from '../types';
import { assert } from '@polkadot/util';
import Enum from './Enum';
import { Enum } from './Enum';
/**
* @name Result
* @description
* A Result maps to the Rust Result type, that can either wrap a success or error value
*/
export default class Result<O extends Codec, E extends Codec> extends Enum {
export class Result<O extends Codec, E extends Codec> extends Enum {
constructor (registry: Registry, Ok: Constructor<O> | keyof InterfaceTypes, Error: Constructor<E> | keyof InterfaceTypes, value?: unknown) {
// NOTE This is order-dependent, Ok (with index 0) needs to be first
// eslint-disable-next-line sort-keys
+10 -10
View File
@@ -4,7 +4,7 @@
/* eslint-disable sort-keys */
import { TypeRegistry } from '../create';
import Set from './Set';
import { CodecSet } from '.';
// TODO actually import these from definitions, don't re-define here
const SET_FIELDS = {
@@ -31,7 +31,7 @@ describe('Set', (): void => {
const registry = new TypeRegistry();
it('constructs via an string[]', (): void => {
const set = new Set(registry, SET_ROLES, ['full', 'authority']);
const set = new CodecSet(registry, SET_ROLES, ['full', 'authority']);
expect(set.isEmpty).toEqual(false);
expect(set.toString()).toEqual(
@@ -41,36 +41,36 @@ describe('Set', (): void => {
it('throws with invalid values', (): void => {
expect(
(): Set => new Set(registry, SET_ROLES, ['full', 'authority', 'invalid'])
() => new CodecSet(registry, SET_ROLES, ['full', 'authority', 'invalid'])
).toThrow(/Invalid key 'invalid'/);
});
it('throws with add on invalid', (): void => {
expect(
(): Set => (new Set(registry, SET_ROLES, [])).add('invalid')
() => (new CodecSet(registry, SET_ROLES, [])).add('invalid')
).toThrow(/Invalid key 'invalid'/);
});
it('allows construction via number', (): void => {
expect(
(new Set(registry, SET_WITHDRAW, 15)).eq(['TransactionPayment', 'Transfer', 'Reserve', 'Fee'])
(new CodecSet(registry, SET_WITHDRAW, 15)).eq(['TransactionPayment', 'Transfer', 'Reserve', 'Fee'])
).toBe(true);
});
it('does not allow invalid number', (): void => {
expect(
(): Set => new Set(registry, SET_WITHDRAW, 31)
() => new CodecSet(registry, SET_WITHDRAW, 31)
).toThrow(/Mismatch decoding '31', computed as '15'/);
});
it('hash a valid encoding', (): void => {
const set = new Set(registry, SET_FIELDS, ['header', 'body', 'justification']);
const set = new CodecSet(registry, SET_FIELDS, ['header', 'body', 'justification']);
expect(set.toU8a()).toEqual(new Uint8Array([19]));
});
describe('utils', (): void => {
const set = new Set(registry, SET_ROLES, ['full', 'authority']);
const set = new CodecSet(registry, SET_ROLES, ['full', 'authority']);
it('compares against string array', (): void => {
expect(
@@ -86,7 +86,7 @@ describe('Set', (): void => {
it('compares against other sets', (): void => {
expect(
set.eq(new Set(registry, SET_ROLES, ['authority', 'full']))
set.eq(new CodecSet(registry, SET_ROLES, ['authority', 'full']))
).toBe(true);
});
@@ -99,7 +99,7 @@ describe('Set', (): void => {
it('has a sane toRawType representation', (): void => {
expect(
new Set(registry, { a: 1, b: 2, c: 345 }).toRawType()
new CodecSet(registry, { a: 1, b: 2, c: 345 }).toRawType()
).toEqual(JSON.stringify({
_set: { a: 1, b: 2, c: 345 }
}));
+1 -1
View File
@@ -76,7 +76,7 @@ function decodeSet (setValues: SetValues, value: string[] | Set<string> | Uint8A
* a bitwise representation of the values.
*/
// FIXME This is a prime candidate to extend the JavaScript built-in Set
export default class CodecSet extends Set<string> implements Codec {
export class CodecSet extends Set<string> implements Codec {
public readonly registry: Registry;
readonly #allowed: SetValues;
+3 -3
View File
@@ -3,12 +3,12 @@
/* eslint-disable sort-keys */
import { CodecTo } from '../types';
import { TypeRegistry } from '../create';
import Text from '../primitive/Text';
import U32 from '../primitive/U32';
import { CodecTo } from '../types';
import Struct from './Struct';
import Vec from './Vec';
import { Struct, Vec } from '.';
describe('Struct', (): void => {
const registry = new TypeRegistry();
+1 -1
View File
@@ -126,7 +126,7 @@ function decodeStruct <T> (registry: Registry, Types: ConstructorDef, value: unk
* it needs to decoded in the specific defined order.
* @noInheritDoc
*/
export default class Struct<
export class Struct<
// The actual Class structure, i.e. key -> Class
S extends TypesDef = TypesDef,
// input values, mapped by key can be anything (construction)
+1 -1
View File
@@ -12,7 +12,7 @@ import { TypeRegistry } from '../create';
import Text from '../primitive/Text';
import U32 from '../primitive/U32';
import U128 from '../primitive/U128';
import Tuple from './Tuple';
import { Tuple } from '.';
describe('Tuple', (): void => {
const registry = new TypeRegistry();
+2 -2
View File
@@ -6,7 +6,7 @@ import { AnyNumber, AnyU8a, AnyString, Codec, Constructor, InterfaceTypes, Regis
import { isU8a, isHex, hexToU8a, u8aConcat } from '@polkadot/util';
import { decodeU8a, mapToTypeMap, typeToConstructor } from './utils';
import AbstractArray from './AbstractArray';
import { AbstractArray } from './AbstractArray';
type AnyTuple = AnyU8a | string | (Codec | AnyU8a | AnyNumber | AnyString | undefined | null)[];
@@ -51,7 +51,7 @@ function decodeTuple (registry: Registry, _Types: TupleConstructors, value?: Any
* A Tuple defines an anonymous fixed-length array, where each element has its
* own type. It extends the base JS `Array` object.
*/
export default class Tuple extends AbstractArray<Codec> {
export class Tuple extends AbstractArray<Codec> {
private _Types: TupleConstructors;
constructor (registry: Registry, Types: TupleTypes, value?: AnyTuple) {
+1 -1
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import { TypeRegistry } from '../create';
import U8aFixed from './U8aFixed';
import { U8aFixed } from '.';
describe('U8aFixed', (): void => {
const registry = new TypeRegistry();
+2 -2
View File
@@ -5,7 +5,7 @@ import { AnyU8a, Constructor, Registry } from '../types';
import { isString, u8aToU8a } from '@polkadot/util';
import Raw from './Raw';
import { Raw } from './Raw';
// The 520 here is a weird one - it is explicitly for a [u8; 65] as found as a EcdsaSignature,
// and 264 here is explicity for a [u8; 33] as found as EcdsaPublic key.
@@ -41,7 +41,7 @@ function decodeU8aFixed (value: AnyU8a, bitLength: BitLength): AnyU8a {
* A U8a that manages a a sequence of bytes up to the specified bitLength. Not meant
* to be used directly, rather is should be subclassed with the specific lengths.
*/
export default class U8aFixed extends Raw {
export class U8aFixed extends Raw {
constructor (registry: Registry, value: AnyU8a = new Uint8Array(), bitLength: BitLength = 256) {
super(registry, decodeU8aFixed(value, bitLength));
}
+1 -1
View File
@@ -4,7 +4,7 @@
import BN from 'bn.js';
import { TypeRegistry } from '../create';
import UInt from './UInt';
import { UInt } from '.';
describe('UInt', (): void => {
const registry = new TypeRegistry();
+2 -2
View File
@@ -3,7 +3,7 @@
import { AnyNumber, Constructor, Registry } from '../types';
import AbstractInt, { UIntBitLength } from './AbstractInt';
import { AbstractInt, UIntBitLength } from './AbstractInt';
/**
* @name UInt
@@ -15,7 +15,7 @@ import AbstractInt, { UIntBitLength } from './AbstractInt';
* is available here.
* @noInheritDoc
*/
export default class UInt extends AbstractInt {
export class UInt extends AbstractInt {
public static with (bitLength: UIntBitLength, typeName?: string): Constructor<UInt> {
return class extends UInt {
constructor (registry: Registry, value?: AnyNumber) {
+1 -2
View File
@@ -10,8 +10,7 @@ import rpcMetadata from '@polkadot/metadata/static';
import { createTypeUnsafe, TypeRegistry } from '../create';
import AccountId from '../generic/AccountId';
import Text from '../primitive/Text';
import Vec from './Vec';
import Tuple from './Tuple';
import { Tuple, Vec } from '.';
const registry = new TypeRegistry();
const metadata = new Metadata(registry, rpcMetadata);
+2 -2
View File
@@ -6,7 +6,7 @@ import { Codec, Constructor, InterfaceTypes, Registry } from '../types';
import { assert, compactFromU8a, logger, u8aToU8a } from '@polkadot/util';
import { decodeU8a, typeToConstructor } from './utils';
import AbstractArray from './AbstractArray';
import { AbstractArray } from './AbstractArray';
const MAX_LENGTH = 64 * 1024;
@@ -19,7 +19,7 @@ const l = logger('Vec');
* construction with the passed `Type` in the constructor. It is an extension to Array, providing
* specific encoding/decoding on top of the base type.
*/
export default class Vec<T extends Codec> extends AbstractArray<T> {
export class Vec<T extends Codec> extends AbstractArray<T> {
private _Type: Constructor<T>;
constructor (registry: Registry, Type: Constructor<T> | keyof InterfaceTypes, value: Vec<Codec> | Uint8Array | string | unknown[] = []) {
+2 -2
View File
@@ -3,7 +3,7 @@
import { Codec } from '../types';
import AbstractArray from './AbstractArray';
import { AbstractArray } from './AbstractArray';
/**
* @name VecAny
@@ -12,7 +12,7 @@ import AbstractArray from './AbstractArray';
* a vector, this can be used to manage array-like structures with variable arguments of
* any types
*/
export default class VecAny<T extends Codec> extends AbstractArray<T> {
export class VecAny<T extends Codec> extends AbstractArray<T> {
/**
* @description Returns the base runtime type name for this instance
*/
+1 -1
View File
@@ -3,7 +3,7 @@
import { TypeRegistry } from '../create';
import Text from '../primitive/Text';
import VecFixed from './VecFixed';
import { VecFixed } from './VecFixed';
describe('VecFixed', (): void => {
const registry = new TypeRegistry();
+3 -3
View File
@@ -4,16 +4,16 @@
import { Codec, Constructor, InterfaceTypes, Registry } from '../types';
import { assert, isU8a, u8aConcat, compactToU8a } from '@polkadot/util';
import AbstractArray from './AbstractArray';
import { AbstractArray } from './AbstractArray';
import { Vec } from './Vec';
import { typeToConstructor } from './utils';
import Vec from './Vec';
/**
* @name VecFixed
* @description
* This manages codec arrays of a fixed length
*/
export default class VecFixed<T extends Codec> extends AbstractArray<T> {
export class VecFixed<T extends Codec> extends AbstractArray<T> {
private _Type: Constructor<T>;
constructor (registry: Registry, Type: Constructor<T> | keyof InterfaceTypes, length: number, value: VecFixed<any> | Uint8Array | string | any[] = [] as any[]) {
+21 -20
View File
@@ -7,23 +7,24 @@
// others, so there _should_ not be need for direct use)
// These are the base codec types, generally used for construction
export { default as BTreeMap } from './BTreeMap';
export { default as BTreeSet } from './BTreeSet';
export { default as Compact } from './Compact';
// export { default as Date } from './Date';
export { default as Enum } from './Enum';
export { default as HashMap } from './HashMap';
export { default as Json } from './Json';
export { default as Linkage } from './Linkage';
export { default as Option } from './Option';
export { default as Result } from './Result';
export { default as Set } from './Set';
export { default as Struct } from './Struct';
export { default as Tuple } from './Tuple';
export { default as Vec } from './Vec';
// Convenience base classes, used as "anything of this type" bases
export { default as Int } from './Int';
export { default as Raw } from './Raw';
export { default as UInt } from './UInt';
export { default as U8aFixed } from './U8aFixed';
export { BTreeMap } from './BTreeMap';
export { BTreeSet } from './BTreeSet';
export { Compact } from './Compact';
// export { CodecDate, CodecDate as Date } from './Date';
export { Enum } from './Enum';
export { HashMap } from './HashMap';
export { Int } from './Int';
export { Json } from './Json';
export { Linkage } from './Linkage';
export { CodecMap, CodecMap as Map } from './Map';
export { Option } from './Option';
export { Raw } from './Raw';
export { Result } from './Result';
export { CodecSet, CodecSet as Set } from './Set';
export { Struct } from './Struct';
export { Tuple } from './Tuple';
export { UInt } from './UInt';
export { U8aFixed } from './U8aFixed';
export { Vec } from './Vec';
// export { VecAny } from './VecAny';
// export { VecFixed } from './VecFixed';
+3 -15
View File
@@ -7,21 +7,9 @@ import { FromReg, TypeDef, TypeDefInfo } from './types';
import { assert, isNumber, isUndefined } from '@polkadot/util';
import { UIntBitLength } from '../codec/AbstractInt';
import BTreeMap from '../codec/BTreeMap';
import BTreeSet from '../codec/BTreeSet';
import Compact from '../codec/Compact';
import Enum from '../codec/Enum';
import HashMap from '../codec/HashMap';
import Int from '../codec/Int';
import Option from '../codec/Option';
import Result from '../codec/Result';
import CodecSet from '../codec/Set';
import Struct from '../codec/Struct';
import Tuple from '../codec/Tuple';
import U8aFixed, { BitLength as U8aFixedBitLength } from '../codec/U8aFixed';
import UInt from '../codec/UInt';
import Vec from '../codec/Vec';
import VecFixed from '../codec/VecFixed';
import { BitLength as U8aFixedBitLength } from '../codec/U8aFixed';
import { BTreeMap, BTreeSet, CodecSet, Compact, Enum, HashMap, Int, Option, Result, Struct, Tuple, U8aFixed, UInt, Vec } from '../codec';
import { VecFixed } from '../codec/VecFixed';
import DoNotConstruct from '../primitive/DoNotConstruct';
import { getTypeDef } from './getTypeDef';
+1 -2
View File
@@ -1,8 +1,7 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import Int from '../codec/Int';
import CodecSet from '../codec/Set';
import { CodecSet, Int } from '../codec';
import { createClass, createTypeUnsafe, TypeRegistry } from '.';
describe('createType', (): void => {
+2 -2
View File
@@ -8,11 +8,11 @@ import { Codec, Constructor } from '../types';
import { isChildClass, u8aToU8a } from '@polkadot/util';
import { keccakAsU8a } from '@polkadot/util-crypto';
import Struct from '../codec/Struct';
import { Struct } from '../codec/Struct';
import DoNotConstruct from '../primitive/DoNotConstruct';
import Text from '../primitive/Text';
import U32 from '../primitive/U32';
import { TypeRegistry } from './registry';
import { TypeRegistry } from '.';
describe('TypeRegistry', (): void => {
const registry = new TypeRegistry();
+2 -2
View File
@@ -10,8 +10,8 @@ import { Metadata, extrinsicsFromMeta } from '@polkadot/metadata';
import { BN_ZERO, assert, assertReturn, formatBalance, isFunction, isString, isU8a, logger, stringCamelCase, u8aToHex } from '@polkadot/util';
import { blake2AsU8a } from '@polkadot/util-crypto';
import Json from '../codec/Json';
import Raw from '../codec/Raw';
import { Json } from '../codec/Json';
import { Raw } from '../codec/Raw';
import { defaultExtensions, expandExtensionTypes, findUnknownExtensions } from '../extrinsic/signedExtensions';
import { EventData } from '../generic/Event';
import DoNotConstruct from '../primitive/DoNotConstruct';
@@ -4,7 +4,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import { TypeRegistry } from '../create';
import Raw from '../codec/Raw';
import { Raw } from '../codec/Raw';
import { GenericEthereumAccountId as AccountId } from './AccountId';
describe('EthereumAccountId', (): void => {
+1 -1
View File
@@ -6,7 +6,7 @@ import { AnyString, AnyU8a, Registry } from '../types';
import { hexToU8a, isHex, isString, isU8a, u8aToU8a } from '@polkadot/util';
import { ethereumEncode, isEthereumAddress } from '@polkadot/util-crypto';
import U8aFixed from '../codec/U8aFixed';
import { U8aFixed } from '../codec/U8aFixed';
/** @internal */
function decodeAccountId (value: AnyU8a | AnyString): AnyU8a {
+1 -1
View File
@@ -7,7 +7,7 @@ import BN from 'bn.js';
import { isBigInt, isBn, isHex, isNumber, isU8a, u8aConcat, u8aToHex, u8aToU8a, u8aToBn } from '@polkadot/util';
import { decodeAddress } from '@polkadot/util-crypto';
import Base from '../codec/Base';
import { Base } from '../codec/Base';
import AccountIndex from '../generic/AccountIndex';
import { GenericEthereumAccountId } from './AccountId';
+2 -2
View File
@@ -8,8 +8,8 @@ import { AnyJson, AnyU8a, ArgsDef, Codec, ExtrinsicPayloadValue, IExtrinsic, IKe
import { assert, compactAddLength, compactFromU8a, isHex, isU8a, u8aConcat, u8aToHex, u8aToU8a } from '@polkadot/util';
import Base from '../codec/Base';
import Compact from '../codec/Compact';
import { Base } from '../codec/Base';
import { Compact } from '../codec/Compact';
import { ExtrinsicValueV4 } from './v4/Extrinsic';
import ExtrinsicEra from './ExtrinsicEra';
import { BIT_SIGNED, BIT_UNSIGNED, DEFAULT_VERSION, UNMASK_VERSION } from './constants';
+3 -3
View File
@@ -6,9 +6,9 @@ import { AnyU8a, IExtrinsicEra, Registry } from '../types';
import BN from 'bn.js';
import { assert, bnToBn, formatNumber, hexToU8a, isHex, isU8a, isObject, u8aToBn, u8aToU8a } from '@polkadot/util';
import Enum from '../codec/Enum';
import Tuple from '../codec/Tuple';
import Raw from '../codec/Raw';
import { Enum } from '../codec/Enum';
import { Tuple } from '../codec/Tuple';
import { Raw } from '../codec/Raw';
import U64 from '../primitive/U64';
import { IMMORTAL_ERA } from './constants';
@@ -7,9 +7,9 @@ import { AnyJson, BareOpts, ExtrinsicPayloadValue, IKeyringPair, InterfaceTypes,
import { u8aToHex } from '@polkadot/util';
import Base from '../codec/Base';
import Compact from '../codec/Compact';
import Raw from '../codec/Raw';
import { Base } from '../codec/Base';
import { Compact } from '../codec/Compact';
import { Raw } from '../codec/Raw';
import u32 from '../primitive/U32';
import ExtrinsicEra from './ExtrinsicEra';
import { DEFAULT_VERSION } from './constants';
@@ -4,7 +4,7 @@
import { Registry } from '../types';
import { ExtrinsicPayloadOptions } from './types';
import Struct from '../codec/Struct';
import { Struct } from '../codec/Struct';
/**
* @name GenericExtrinsicPayloadUnknown
@@ -4,7 +4,7 @@
import { Registry } from '../types';
import { ExtrinsicOptions } from './types';
import Struct from '../codec/Struct';
import { Struct } from '../codec/Struct';
import { UNMASK_VERSION } from './constants';
/**
@@ -6,9 +6,9 @@ import { Codec, Constructor, ISignerPayload, SignerPayloadJSON, SignerPayloadRaw
import { u8aToHex } from '@polkadot/util';
import Compact from '../codec/Compact';
import Struct from '../codec/Struct';
import Vec from '../codec/Vec';
import { Compact } from '../codec/Compact';
import { Struct } from '../codec/Struct';
import { Vec } from '../codec/Vec';
import Text from '../primitive/Text';
import u8 from '../primitive/U8';
+1 -1
View File
@@ -8,7 +8,7 @@ import { ExtrinsicOptions } from '../types';
import { isU8a } from '@polkadot/util';
import Struct from '../../codec/Struct';
import { Struct } from '../../codec/Struct';
export const EXTRINSIC_VERSION = 4;
@@ -5,8 +5,8 @@ import { ExtrinsicEra } from '../../interfaces/extrinsics';
import { Balance, Hash, Index } from '../../interfaces/runtime';
import { ExtrinsicPayloadValue, IKeyringPair, Registry } from '../../types';
import Compact from '../../codec/Compact';
import Struct from '../../codec/Struct';
import { Compact } from '../../codec/Compact';
import { Struct } from '../../codec/Struct';
import Bytes from '../../primitive/Bytes';
import u32 from '../../primitive/U32';
import { sign } from '../util';
@@ -8,8 +8,8 @@ import { ExtrinsicSignatureOptions } from '../types';
import { u8aConcat } from '@polkadot/util';
import Compact from '../../codec/Compact';
import Struct from '../../codec/Struct';
import { Compact } from '../../codec/Compact';
import { Struct } from '../../codec/Struct';
import { EMPTY_U8A, IMMORTAL_ERA } from '../constants';
import ExtrinsicPayloadV4 from './ExtrinsicPayload';
+1 -1
View File
@@ -4,7 +4,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import { TypeRegistry } from '../create';
import Raw from '../codec/Raw';
import { Raw } from '../codec/Raw';
import jsonVec from '../json/AccountIdVec.001.json';
import AccountId from './AccountId';
+1 -1
View File
@@ -6,7 +6,7 @@ import { AnyString, AnyU8a, Registry } from '../types';
import { hexToU8a, isHex, isString, isU8a, u8aToU8a, assert } from '@polkadot/util';
import { decodeAddress, encodeAddress } from '@polkadot/util-crypto';
import U8aFixed from '../codec/U8aFixed';
import { U8aFixed } from '../codec/U8aFixed';
/** @internal */
function decodeAccountId (value?: AnyU8a | AnyString): Uint8Array {
+2 -2
View File
@@ -5,8 +5,8 @@ import { Digest, DigestItem, H256, Header } from '../interfaces/runtime';
import { AnyNumber, AnyU8a, Registry } from '../types';
import Extrinsic from '../extrinsic/Extrinsic';
import Struct from '../codec/Struct';
import Vec from '../codec/Vec';
import { Struct } from '../codec/Struct';
import { Vec } from '../codec/Vec';
export interface HeaderValue {
digest?: Digest | { logs: DigestItem[] };
+2 -2
View File
@@ -7,8 +7,8 @@ import { AnyJson, AnyU8a, ArgsDef, CallFunction, Codec, IMethod, Registry } from
import { isHex, isObject, isU8a, u8aToU8a } from '@polkadot/util';
import { getTypeDef, getTypeClass } from '../create';
import Struct from '../codec/Struct';
import U8aFixed from '../codec/U8aFixed';
import { Struct } from '../codec/Struct';
import { U8aFixed } from '../codec/U8aFixed';
interface DecodeMethodInput {
args: unknown;
+2 -2
View File
@@ -6,8 +6,8 @@ import { EventMetadataLatest } from '../interfaces/metadata';
import { EventId } from '../interfaces/system';
import { AnyJson, Constructor, Registry, RegistryMetadataEvent } from '../types';
import Struct from '../codec/Struct';
import Tuple from '../codec/Tuple';
import { Struct } from '../codec/Struct';
import { Tuple } from '../codec/Tuple';
import Null from '../primitive/Null';
/**
+1 -1
View File
@@ -7,7 +7,7 @@ import BN from 'bn.js';
import { isBigInt, isBn, isHex, isNumber, isU8a, u8aConcat, u8aToHex, u8aToU8a, u8aToBn } from '@polkadot/util';
import { decodeAddress } from '@polkadot/util-crypto';
import Base from '../codec/Base';
import { Base } from '../codec/Base';
import AccountId from './AccountId';
import AccountIndex from './AccountIndex';
+1 -1
View File
@@ -6,7 +6,7 @@ import { Registry } from '../types';
import { isString, u8aConcat } from '@polkadot/util';
import { decodeAddress } from '@polkadot/util-crypto';
import Enum from '../codec/Enum';
import { Enum } from '../codec/Enum';
export default class MultiAddress extends Enum {
constructor (registry: Registry, value?: unknown) {
+28 -28
View File
@@ -2,64 +2,64 @@
// SPDX-License-Identifier: Apache-2.0
import { TypeRegistry } from '../create';
import Vote from './Vote';
import { GenericVote } from '.';
describe('Vote', (): void => {
describe('GenericVote', (): void => {
const registry = new TypeRegistry();
describe('construction', (): void => {
it('constructs via boolean true', (): void => {
expect(new Vote(registry, true).toU8a()).toEqual(new Uint8Array([128]));
expect(new Vote(registry, true).isAye).toBe(true);
expect(new Vote(registry, true).isNay).toBe(false);
expect(new GenericVote(registry, true).toU8a()).toEqual(new Uint8Array([128]));
expect(new GenericVote(registry, true).isAye).toBe(true);
expect(new GenericVote(registry, true).isNay).toBe(false);
});
it('constructs via boolean false', (): void => {
expect(new Vote(registry, false).toU8a()).toEqual(new Uint8Array([0]));
expect(new Vote(registry, false).isNay).toBe(true);
expect(new Vote(registry, false).isAye).toBe(false);
expect(new GenericVote(registry, false).toU8a()).toEqual(new Uint8Array([0]));
expect(new GenericVote(registry, false).isNay).toBe(true);
expect(new GenericVote(registry, false).isAye).toBe(false);
});
it('constructs via undefined', (): void => {
expect(new Vote(registry).isNay).toBe(true);
expect(new GenericVote(registry).isNay).toBe(true);
});
it('has isYay for positive', (): void => {
// eslint-disable-next-line no-new-wrappers
expect(new Vote(registry, true).isAye).toBe(true);
expect(new GenericVote(registry, true).isAye).toBe(true);
});
it('has isNay for negative', (): void => {
// eslint-disable-next-line no-new-wrappers
expect(new Vote(registry, false).isNay).toBe(true);
expect(new GenericVote(registry, false).isNay).toBe(true);
});
it('is Aye for negative numbers', (): void => {
expect(new Vote(registry, -128).isAye).toBe(true);
expect(new GenericVote(registry, -128).isAye).toBe(true);
});
it('is Nay for positive numbers', (): void => {
expect(new Vote(registry, 127).isNay).toBe(true);
expect(new GenericVote(registry, 127).isNay).toBe(true);
});
it('is Nay for 0', (): void => {
expect(new Vote(registry, 0).isNay).toBe(true);
expect(new GenericVote(registry, 0).isNay).toBe(true);
});
it('constructs via empty', (): void => {
expect(new Vote(registry).isNay).toBe(true);
expect(new GenericVote(registry).isNay).toBe(true);
});
it('constructs via Uint8Array (empty)', (): void => {
expect(new Vote(registry, new Uint8Array()).isNay).toBe(true);
expect(new GenericVote(registry, new Uint8Array()).isNay).toBe(true);
});
it('constructs via Uint8Array (nay)', (): void => {
expect(new Vote(registry, new Uint8Array([1])).isNay).toBe(true);
expect(new GenericVote(registry, new Uint8Array([1])).isNay).toBe(true);
});
it('constructs via Uint8Array (aye)', (): void => {
const test = new Vote(registry, new Uint8Array([0b10000010]));
const test = new GenericVote(registry, new Uint8Array([0b10000010]));
expect(test.isNay).toBe(false);
expect(test.conviction.toString()).toEqual('Locked2x');
@@ -69,7 +69,7 @@ describe('Vote', (): void => {
describe('Vote with conviction', (): void => {
it('constructs Vote with raw boolean', (): void => {
expect(
new Vote(registry, {
new GenericVote(registry, {
aye: true,
conviction: 'Locked1x'
}).toU8a()
@@ -78,7 +78,7 @@ describe('Vote', (): void => {
it('constructs with Vote aye is false, conviction is None', (): void => {
expect(
new Vote(registry, {
new GenericVote(registry, {
aye: false,
conviction: 'None'
}).toU8a()
@@ -87,7 +87,7 @@ describe('Vote', (): void => {
it('constructs with Vote aye is true, conviction is Locked4x', (): void => {
expect(
new Vote(registry, {
new GenericVote(registry, {
aye: true,
conviction: 'Locked4x'
}).toU8a()
@@ -98,7 +98,7 @@ describe('Vote', (): void => {
describe('getters', (): void => {
it('Conviction getter works', (): void => {
expect(
new Vote(registry, {
new GenericVote(registry, {
aye: true,
conviction: 'Locked2x'
}).conviction.toString()
@@ -107,7 +107,7 @@ describe('Vote', (): void => {
it('Conviction getter works with raw boolean and string conviction', (): void => {
expect(
new Vote(registry, {
new GenericVote(registry, {
aye: true,
conviction: 'Locked2x'
}).conviction.toString()
@@ -116,7 +116,7 @@ describe('Vote', (): void => {
it('Conviction getter works with raw boolean and conviction index', (): void => {
expect(
new Vote(registry, {
new GenericVote(registry, {
aye: true,
conviction: 2
}).conviction.toString()
@@ -124,7 +124,7 @@ describe('Vote', (): void => {
});
it('Conviction getter works with raw boolean and no conviction', (): void => {
const test = new Vote(registry, { aye: true });
const test = new GenericVote(registry, { aye: true });
expect(test.isAye).toEqual(true);
expect(test.conviction.toString()).toEqual('None');
@@ -132,7 +132,7 @@ describe('Vote', (): void => {
it('isAye getter works', (): void => {
expect(
new Vote(registry, {
new GenericVote(registry, {
aye: true,
conviction: 'None'
}).isAye)
@@ -141,7 +141,7 @@ describe('Vote', (): void => {
it('isNay getter works', (): void => {
expect(
new Vote(registry, {
new GenericVote(registry, {
aye: true,
conviction: 'None'
}).isNay)
@@ -151,7 +151,7 @@ describe('Vote', (): void => {
describe('utils', (): void => {
it('has a sane toRawType', (): void => {
expect(new Vote(registry).toRawType()).toEqual('Vote');
expect(new GenericVote(registry).toRawType()).toEqual('Vote');
});
});
});
+1 -1
View File
@@ -7,7 +7,7 @@ import { Conviction } from '../interfaces/democracy';
import { isBoolean, isNumber, isU8a, isUndefined } from '@polkadot/util';
import U8aFixed from '../codec/U8aFixed';
import { U8aFixed } from '../codec/U8aFixed';
import Bool from '../primitive/Bool';
interface VoteType {
+1 -1
View File
@@ -5,7 +5,7 @@ import { AnyU8a, Registry } from '../types';
import { assert, compactFromU8a, compactToU8a, isString, u8aConcat, u8aToU8a } from '@polkadot/util';
import Raw from '../codec/Raw';
import { Raw } from '../codec/Raw';
/** @internal */
function decodeBitVecU8a (value?: Uint8Array): Uint8Array {
+1 -1
View File
@@ -5,7 +5,7 @@ import { AnyU8a, Registry } from '../types';
import { assert, compactAddLength, compactFromU8a, compactToU8a, isString, isU8a, u8aToU8a } from '@polkadot/util';
import Raw from '../codec/Raw';
import { Raw } from '../codec/Raw';
// Bytes are used for things like on-chain code, so it has a healthy limit
const MAX_LENGTH = 10 * 1024 * 1024;
+1 -1
View File
@@ -6,7 +6,7 @@ import { Registry } from '../types';
import { isString, isU8a, u8aToU8a } from '@polkadot/util';
import Enum from '../codec/Enum';
import { Enum } from '../codec/Enum';
import Bytes from './Bytes';
/** @internal */
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import Int from '../codec/Int';
import { Int } from '../codec/Int';
/**
* @name I128
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import Int from '../codec/Int';
import { Int } from '../codec/Int';
/**
* @name I16
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import Int from '../codec/Int';
import { Int } from '../codec/Int';
/**
* @name I256
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import Int from '../codec/Int';
import { Int } from '../codec/Int';
/**
* @name I32
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import Int from '../codec/Int';
import { Int } from '../codec/Int';
/**
* @name I64
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import Int from '../codec/Int';
import { Int } from '../codec/Int';
/**
* @name I8
+1 -1
View File
@@ -3,7 +3,7 @@
import { CodecTo } from '../types';
import { TypeRegistry } from '../create';
import Raw from '../codec/Raw';
import { Raw } from '../codec/Raw';
import Text from './Text';
describe('Text', (): void => {
+1 -1
View File
@@ -6,7 +6,7 @@ import { AnyU8a, Codec, Registry } from '../types';
import { assert, hexToU8a, isHex, isString, stringToU8a, u8aToString, u8aToHex, compactFromU8a, compactAddLength } from '@polkadot/util';
import Raw from '../codec/Raw';
import { Raw } from '../codec/Raw';
const MAX_LENGTH = 128 * 1024;
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import UInt from '../codec/UInt';
import { UInt } from '../codec/UInt';
/**
* @name U128
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import UInt from '../codec/UInt';
import { UInt } from '../codec/UInt';
/**
* @name U16
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import UInt from '../codec/UInt';
import { UInt } from '../codec/UInt';
/**
* @name U256
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import UInt from '../codec/UInt';
import { UInt } from '../codec/UInt';
/**
* @name U32
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import UInt from '../codec/UInt';
import { UInt } from '../codec/UInt';
/**
* @name U64
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import UInt from '../codec/UInt';
import { UInt } from '../codec/UInt';
/**
* @name U8