Rename Code .registry to .$registry (#5428)
* Adapt $registry getter, deprecate registry * warnGet adjustments * Additional adjustments
This commit is contained in:
@@ -16,11 +16,10 @@ import { compareArray, warnGet } from '../utils';
|
||||
* @noInheritDoc
|
||||
*/
|
||||
export abstract class AbstractArray<T extends Codec> extends Array<T> implements IVec<T> {
|
||||
readonly registry: Registry;
|
||||
|
||||
public $createdAtHash?: IU8a;
|
||||
public $initialU8aLength?: number;
|
||||
public $isStorageFallback?: boolean;
|
||||
readonly $registry: Registry;
|
||||
|
||||
/**
|
||||
* @description This ensures that operators such as clice, filter, map, etc. return
|
||||
@@ -33,7 +32,7 @@ export abstract class AbstractArray<T extends Codec> extends Array<T> implements
|
||||
protected constructor (registry: Registry, length: number) {
|
||||
super(length);
|
||||
|
||||
this.registry = registry;
|
||||
this.$registry = registry;
|
||||
}
|
||||
|
||||
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
|
||||
@@ -56,6 +55,11 @@ export abstract class AbstractArray<T extends Codec> extends Array<T> implements
|
||||
return warnGet(this, 'isEmpty');
|
||||
}
|
||||
|
||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
||||
public get registry (): Registry {
|
||||
return warnGet(this, 'registry');
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The length of the value when encoded as a Uint8Array
|
||||
*/
|
||||
@@ -75,7 +79,7 @@ export abstract class AbstractArray<T extends Codec> extends Array<T> implements
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
public get hash (): IU8a {
|
||||
return this.registry.hash(this.toU8a());
|
||||
return this.$registry.hash(this.toU8a());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,18 +11,17 @@ import { warnGet } from '../utils';
|
||||
* @description A type extends the Base class, when it holds a value
|
||||
*/
|
||||
export abstract class AbstractBase<T extends Codec> implements Codec {
|
||||
readonly registry: Registry;
|
||||
|
||||
public $createdAtHash?: IU8a;
|
||||
public $initialU8aLength?: number;
|
||||
public $isStorageFallback?: boolean;
|
||||
readonly $registry: Registry;
|
||||
|
||||
readonly #raw: T;
|
||||
|
||||
protected constructor (registry: Registry, value: T, initialU8aLength?: number) {
|
||||
this.$initialU8aLength = initialU8aLength;
|
||||
this.#raw = value;
|
||||
this.registry = registry;
|
||||
this.$registry = registry;
|
||||
}
|
||||
|
||||
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
|
||||
@@ -45,6 +44,11 @@ export abstract class AbstractBase<T extends Codec> implements Codec {
|
||||
return warnGet(this, 'isEmpty');
|
||||
}
|
||||
|
||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
||||
public get registry (): Registry {
|
||||
return warnGet(this, 'registry');
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The length of the value when encoded as a Uint8Array
|
||||
*/
|
||||
@@ -56,7 +60,7 @@ export abstract class AbstractBase<T extends Codec> implements Codec {
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
public get hash (): IU8a {
|
||||
return this.registry.hash(this.toU8a());
|
||||
return this.$registry.hash(this.toU8a());
|
||||
}
|
||||
|
||||
public get inner (): T {
|
||||
|
||||
@@ -74,13 +74,12 @@ function decodeAbstractInt (value: Exclude<AnyNumber, Uint8Array> | Record<strin
|
||||
* @noInheritDoc
|
||||
*/
|
||||
export abstract class AbstractInt extends BN implements INumber {
|
||||
readonly registry: Registry;
|
||||
|
||||
public $createdAtHash?: IU8a;
|
||||
readonly $encodedLength: number;
|
||||
public $initialU8aLength?: number;
|
||||
public $isStorageFallback?: boolean;
|
||||
readonly $isUnsigned: boolean;
|
||||
readonly $registry: Registry;
|
||||
|
||||
readonly #bitLength: UIntBitLength;
|
||||
|
||||
@@ -97,7 +96,7 @@ export abstract class AbstractInt extends BN implements INumber {
|
||||
: decodeAbstractInt(value, isSigned)
|
||||
);
|
||||
|
||||
this.registry = registry;
|
||||
this.$registry = registry;
|
||||
this.#bitLength = bitLength;
|
||||
this.$encodedLength = this.$initialU8aLength = this.#bitLength / 8;
|
||||
this.$isUnsigned = !isSigned;
|
||||
@@ -137,11 +136,16 @@ export abstract class AbstractInt extends BN implements INumber {
|
||||
return warnGet(this, 'isUnsigned');
|
||||
}
|
||||
|
||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
||||
public get registry (): Registry {
|
||||
return warnGet(this, 'registry');
|
||||
}
|
||||
|
||||
/**
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
public get hash (): IU8a {
|
||||
return this.registry.hash(this.toU8a());
|
||||
return this.$registry.hash(this.toU8a());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -228,7 +232,7 @@ export abstract class AbstractInt extends BN implements INumber {
|
||||
? 'everything'
|
||||
// FIXME In the case of multiples we need some way of detecting which instance this belongs
|
||||
// to. as it stands we will always format (incorrectly) against the first token defined
|
||||
: formatBalance(this, { decimals: this.registry.chainDecimals[0], withSi: true, withUnit: this.registry.chainTokens[0] });
|
||||
: formatBalance(this, { decimals: this.$registry.chainDecimals[0], withSi: true, withUnit: this.$registry.chainTokens[0] });
|
||||
}
|
||||
|
||||
const [, divisor] = FORMATTERS.find(([type]) => type === rawType) || [];
|
||||
@@ -267,7 +271,7 @@ export abstract class AbstractInt extends BN implements INumber {
|
||||
// NOTE In the case of balances, which have a special meaning on the UI
|
||||
// and can be interpreted differently, return a specific value for it so
|
||||
// underlying it always matches (no matter which length it actually is)
|
||||
return this instanceof this.registry.createClassUnsafe('Balance')
|
||||
return this instanceof this.$registry.createClassUnsafe('Balance')
|
||||
? 'Balance'
|
||||
: `${this.$isUnsigned ? 'u' : 'i'}${this.bitLength()}`;
|
||||
}
|
||||
|
||||
@@ -47,17 +47,16 @@ function decodeCompact<T extends INumber> (registry: Registry, Type: CodecClass<
|
||||
* a number and making the compact representation thereof
|
||||
*/
|
||||
export class Compact<T extends INumber> implements ICompact<T> {
|
||||
readonly registry: Registry;
|
||||
|
||||
public $createdAtHash?: IU8a;
|
||||
public $initialU8aLength?: number;
|
||||
public $isStorageFallback?: boolean;
|
||||
readonly $registry: Registry;
|
||||
|
||||
readonly #Type: CodecClass<T>;
|
||||
readonly #raw: T;
|
||||
|
||||
constructor (registry: Registry, Type: CodecClass<T> | string, value: Compact<T> | AnyNumber = 0, { definition, setDefinition = noopSetDefinition }: Options<T> = {}) {
|
||||
this.registry = registry;
|
||||
this.$registry = registry;
|
||||
this.#Type = definition || setDefinition(typeToConstructor(registry, Type));
|
||||
|
||||
const [raw, decodedLength] = decodeCompact<T>(registry, this.#Type, value);
|
||||
@@ -86,6 +85,11 @@ export class Compact<T extends INumber> implements ICompact<T> {
|
||||
return warnGet(this, 'isEmpty');
|
||||
}
|
||||
|
||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
||||
public get registry (): Registry {
|
||||
return warnGet(this, 'registry');
|
||||
}
|
||||
|
||||
public static with<O extends INumber> (Type: CodecClass<O> | string): CodecClass<Compact<O>> {
|
||||
let definition: CodecClass<O> | undefined;
|
||||
|
||||
@@ -111,7 +115,7 @@ export class Compact<T extends INumber> implements ICompact<T> {
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
public get hash (): IU8a {
|
||||
return this.registry.hash(this.toU8a());
|
||||
return this.$registry.hash(this.toU8a());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -201,7 +205,7 @@ export class Compact<T extends INumber> implements ICompact<T> {
|
||||
* @description Returns the base runtime type name for this instance
|
||||
*/
|
||||
public toRawType (): string {
|
||||
return `Compact<${this.registry.getClassName(this.#Type) || this.#raw.toRawType()}>`;
|
||||
return `Compact<${this.$registry.getClassName(this.#Type) || this.#raw.toRawType()}>`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,7 +12,7 @@ import { warnGet } from '../utils';
|
||||
* An unknown type that fails on construction with the type info
|
||||
*/
|
||||
export class DoNotConstruct implements Codec {
|
||||
readonly registry: Registry;
|
||||
readonly $registry: Registry;
|
||||
|
||||
public $createdAtHash?: IU8a;
|
||||
public $isStorageFallback?: boolean;
|
||||
@@ -20,7 +20,7 @@ export class DoNotConstruct implements Codec {
|
||||
#neverError: Error;
|
||||
|
||||
constructor (registry: Registry, typeName = 'DoNotConstruct') {
|
||||
this.registry = registry;
|
||||
this.$registry = registry;
|
||||
this.#neverError = new Error(`DoNotConstruct: Cannot construct unknown type ${typeName}`);
|
||||
|
||||
throw this.#neverError;
|
||||
@@ -46,6 +46,11 @@ export class DoNotConstruct implements Codec {
|
||||
return warnGet(this, 'isEmpty');
|
||||
}
|
||||
|
||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
||||
public get registry (): Registry {
|
||||
return warnGet(this, 'registry');
|
||||
}
|
||||
|
||||
public static with (typeName?: string): CodecClass {
|
||||
return class extends DoNotConstruct {
|
||||
constructor (registry: Registry) {
|
||||
|
||||
@@ -183,7 +183,7 @@ function decodeEnum (registry: Registry, def: TypesDef, value?: unknown, index?:
|
||||
* an extension to enum where the value type is determined by the actual index.
|
||||
*/
|
||||
export class Enum implements IEnum {
|
||||
readonly registry: Registry;
|
||||
readonly $registry: Registry;
|
||||
|
||||
public $createdAtHash?: IU8a;
|
||||
public $initialU8aLength?: number;
|
||||
@@ -206,7 +206,7 @@ export class Enum implements IEnum {
|
||||
|
||||
this.$isBasic = isBasic;
|
||||
|
||||
this.registry = registry;
|
||||
this.$registry = registry;
|
||||
this.#def = def;
|
||||
this.#isIndexed = isIndexed;
|
||||
this.#indexes = Object.values(def).map(({ index }) => index);
|
||||
@@ -233,6 +233,11 @@ export class Enum implements IEnum {
|
||||
return warnGet(this, 'initialU8aLength');
|
||||
}
|
||||
|
||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
||||
public get registry (): Registry {
|
||||
return warnGet(this, 'registry');
|
||||
}
|
||||
|
||||
/** @deprecated Use $isBasic instead. This getter will be removed in a future version */
|
||||
public get isBasic (): boolean {
|
||||
return warnGet(this, 'isBasic');
|
||||
@@ -300,7 +305,7 @@ export class Enum implements IEnum {
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
public get hash (): IU8a {
|
||||
return this.registry.hash(this.toU8a());
|
||||
return this.$registry.hash(this.toU8a());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -455,7 +460,7 @@ export class Enum implements IEnum {
|
||||
|
||||
const entries = Object.entries(this.#def);
|
||||
|
||||
return typesToMap(this.registry, entries.reduce<[CodecClass[], string[]]>((out, [key, { Type }], i) => {
|
||||
return typesToMap(this.$registry, entries.reduce<[CodecClass[], string[]]>((out, [key, { Type }], i) => {
|
||||
out[0][i] = Type;
|
||||
out[1][i] = key;
|
||||
|
||||
|
||||
@@ -14,16 +14,15 @@ import { warnGet } from '../utils';
|
||||
* Implements a type that does not contain anything (apart from `null`)
|
||||
*/
|
||||
export class Null implements Codec {
|
||||
readonly registry: Registry;
|
||||
|
||||
public $createdAtHash?: IU8a;
|
||||
readonly $encodedLength = 0;
|
||||
public $initialU8aLength = 0;
|
||||
public $isStorageFallback?: boolean;
|
||||
readonly $isEmpty = true;
|
||||
readonly $registry: Registry;
|
||||
|
||||
constructor (registry: Registry) {
|
||||
this.registry = registry;
|
||||
this.$registry = registry;
|
||||
}
|
||||
|
||||
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
|
||||
@@ -46,6 +45,11 @@ export class Null implements Codec {
|
||||
return warnGet(this, 'isEmpty');
|
||||
}
|
||||
|
||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
||||
public get registry (): Registry {
|
||||
return warnGet(this, 'registry');
|
||||
}
|
||||
|
||||
/**
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
|
||||
@@ -66,7 +66,7 @@ function decodeOption (registry: Registry, Type: CodecClass, value?: unknown): C
|
||||
* with a value if/as required/found.
|
||||
*/
|
||||
export class Option<T extends Codec> implements IOption<T> {
|
||||
readonly registry: Registry;
|
||||
readonly $registry: Registry;
|
||||
|
||||
public $createdAtHash?: IU8a;
|
||||
public $initialU8aLength?: number;
|
||||
@@ -83,7 +83,7 @@ export class Option<T extends Codec> implements IOption<T> {
|
||||
: new Type(registry, value.subarray(1))
|
||||
: decodeOption(registry, Type, value);
|
||||
|
||||
this.registry = registry;
|
||||
this.$registry = registry;
|
||||
this.#Type = Type;
|
||||
this.#raw = decoded as T;
|
||||
|
||||
@@ -112,6 +112,11 @@ export class Option<T extends Codec> implements IOption<T> {
|
||||
return warnGet(this, 'isEmpty');
|
||||
}
|
||||
|
||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
||||
public get registry (): Registry {
|
||||
return warnGet(this, 'registry');
|
||||
}
|
||||
|
||||
public static with<O extends Codec> (Type: CodecClass<O> | string): CodecClass<Option<O>> {
|
||||
let definition: CodecClass<O> | undefined;
|
||||
|
||||
@@ -140,7 +145,7 @@ export class Option<T extends Codec> implements IOption<T> {
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
public get hash (): IU8a {
|
||||
return this.registry.hash(this.toU8a());
|
||||
return this.$registry.hash(this.toU8a());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -238,7 +243,7 @@ export class Option<T extends Codec> implements IOption<T> {
|
||||
* @description Returns the base runtime type name for this instance
|
||||
*/
|
||||
public toRawType (isBare?: boolean): string {
|
||||
const wrapped = this.registry.getClassName(this.#Type) || new this.#Type(this.registry).toRawType();
|
||||
const wrapped = this.$registry.getClassName(this.#Type) || new this.#Type(this.$registry).toRawType();
|
||||
|
||||
return isBare
|
||||
? wrapped
|
||||
@@ -299,6 +304,6 @@ export class Option<T extends Codec> implements IOption<T> {
|
||||
public unwrapOrDefault (): T {
|
||||
return this.isSome
|
||||
? this.unwrap()
|
||||
: new this.#Type(this.registry);
|
||||
: new this.#Type(this.$registry);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ export class Tuple extends AbstractArray<Codec> implements ITuple<Codec[]> {
|
||||
public get Types (): string[] {
|
||||
return this.#Types[1].length
|
||||
? this.#Types[1]
|
||||
: this.#Types[0].map((T) => new T(this.registry).toRawType());
|
||||
: this.#Types[0].map((T) => new T(this.$registry).toRawType());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,7 +126,7 @@ export class Tuple extends AbstractArray<Codec> implements ITuple<Codec[]> {
|
||||
*/
|
||||
public toRawType (): string {
|
||||
const types = this.#Types[0].map((T) =>
|
||||
this.registry.getClassName(T) || new T(this.registry).toRawType()
|
||||
this.$registry.getClassName(T) || new T(this.$registry).toRawType()
|
||||
);
|
||||
|
||||
return `(${types.join(',')})`;
|
||||
|
||||
@@ -115,7 +115,7 @@ export class Vec<T extends Codec> extends AbstractArray<T> {
|
||||
// convert type first, this removes overhead from the eq
|
||||
const other = _other instanceof this.#Type
|
||||
? _other
|
||||
: new this.#Type(this.registry, _other);
|
||||
: new this.#Type(this.$registry, _other);
|
||||
|
||||
for (let i = 0; i < this.length; i++) {
|
||||
if (other.eq(this[i])) {
|
||||
@@ -130,6 +130,6 @@ export class Vec<T extends Codec> extends AbstractArray<T> {
|
||||
* @description Returns the base runtime type name for this instance
|
||||
*/
|
||||
public toRawType (): string {
|
||||
return `Vec<${this.registry.getClassName(this.#Type) || new this.#Type(this.registry).toRawType()}>`;
|
||||
return `Vec<${this.$registry.getClassName(this.#Type) || new this.#Type(this.$registry).toRawType()}>`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ export class VecFixed<T extends Codec> extends AbstractArray<T> {
|
||||
* @description The type for the items
|
||||
*/
|
||||
public get Type (): string {
|
||||
return new this.#Type(this.registry).toRawType();
|
||||
return new this.#Type(this.$registry).toRawType();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -70,7 +70,7 @@ function decodeSet<V extends Codec> (registry: Registry, valType: CodecClass<V>
|
||||
}
|
||||
|
||||
export class BTreeSet<V extends Codec = Codec> extends Set<V> implements ISet<V> {
|
||||
readonly registry: Registry;
|
||||
readonly $registry: Registry;
|
||||
|
||||
public $createdAtHash?: IU8a;
|
||||
public $initialU8aLength?: number;
|
||||
@@ -83,7 +83,7 @@ export class BTreeSet<V extends Codec = Codec> extends Set<V> implements ISet<V>
|
||||
|
||||
super(sortSet(values));
|
||||
|
||||
this.registry = registry;
|
||||
this.$registry = registry;
|
||||
this.$initialU8aLength = decodedLength;
|
||||
this.#ValClass = ValClass;
|
||||
}
|
||||
@@ -108,6 +108,11 @@ export class BTreeSet<V extends Codec = Codec> extends Set<V> implements ISet<V>
|
||||
return warnGet(this, 'isEmpty');
|
||||
}
|
||||
|
||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
||||
public get registry (): Registry {
|
||||
return warnGet(this, 'registry');
|
||||
}
|
||||
|
||||
public static with<V extends Codec> (valType: CodecClass<V> | string): CodecClass<BTreeSet<V>> {
|
||||
return class extends BTreeSet<V> {
|
||||
constructor (registry: Registry, value?: Uint8Array | string | Set<any>) {
|
||||
@@ -133,7 +138,7 @@ export class BTreeSet<V extends Codec = Codec> extends Set<V> implements ISet<V>
|
||||
* @description Returns a hash of the value
|
||||
*/
|
||||
public get hash (): IU8a {
|
||||
return this.registry.hash(this.toU8a());
|
||||
return this.$registry.hash(this.toU8a());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -210,7 +215,7 @@ export class BTreeSet<V extends Codec = Codec> extends Set<V> implements ISet<V>
|
||||
* @description Returns the base runtime type name for this instance
|
||||
*/
|
||||
public toRawType (): string {
|
||||
return `BTreeSet<${this.registry.getClassName(this.#ValClass) || new this.#ValClass(this.registry).toRawType()}>`;
|
||||
return `BTreeSet<${this.$registry.getClassName(this.#ValClass) || new this.#ValClass(this.$registry).toRawType()}>`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -94,7 +94,7 @@ function decodeMap<K extends Codec, V extends Codec> (registry: Registry, keyTyp
|
||||
}
|
||||
|
||||
export class CodecMap<K extends Codec = Codec, V extends Codec = Codec> extends Map<K, V> implements IMap<K, V> {
|
||||
readonly registry: Registry;
|
||||
readonly $registry: Registry;
|
||||
|
||||
public $createdAtHash?: IU8a;
|
||||
public $initialU8aLength?: number;
|
||||
@@ -109,7 +109,7 @@ export class CodecMap<K extends Codec = Codec, V extends Codec = Codec> extends
|
||||
|
||||
super(type === 'BTreeMap' ? sortMap(decoded) : decoded);
|
||||
|
||||
this.registry = registry;
|
||||
this.$registry = registry;
|
||||
this.$initialU8aLength = decodedLength;
|
||||
this.#KeyClass = KeyClass;
|
||||
this.#ValClass = ValClass;
|
||||
@@ -136,6 +136,11 @@ export class CodecMap<K extends Codec = Codec, V extends Codec = Codec> extends
|
||||
return warnGet(this, 'isEmpty');
|
||||
}
|
||||
|
||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
||||
public get registry (): Registry {
|
||||
return warnGet(this, 'registry');
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The length of the value when encoded as a Uint8Array
|
||||
*/
|
||||
@@ -153,7 +158,7 @@ export class CodecMap<K extends Codec = Codec, V extends Codec = Codec> extends
|
||||
* @description Returns a hash of the value
|
||||
*/
|
||||
public get hash (): IU8a {
|
||||
return this.registry.hash(this.toU8a());
|
||||
return this.$registry.hash(this.toU8a());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -245,7 +250,7 @@ export class CodecMap<K extends Codec = Codec, V extends Codec = Codec> extends
|
||||
* @description Returns the base runtime type name for this instance
|
||||
*/
|
||||
public toRawType (): string {
|
||||
return `${this.#type}<${this.registry.getClassName(this.#KeyClass) || new this.#KeyClass(this.registry).toRawType()},${this.registry.getClassName(this.#ValClass) || new this.#ValClass(this.registry).toRawType()}>`;
|
||||
return `${this.#type}<${this.$registry.getClassName(this.#KeyClass) || new this.#KeyClass(this.$registry).toRawType()},${this.$registry.getClassName(this.#ValClass) || new this.#ValClass(this.$registry).toRawType()}>`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -103,7 +103,7 @@ export class WrapperKeepOpaque<T extends Codec> extends Bytes {
|
||||
* @description Returns the base runtime type name for this instance
|
||||
*/
|
||||
public override toRawType (): string {
|
||||
return `${this.#opaqueName}<${this.registry.getClassName(this.#Type) || (this.#decoded ? this.#decoded.toRawType() : new this.#Type(this.registry).toRawType())}>`;
|
||||
return `${this.#opaqueName}<${this.$registry.getClassName(this.#Type) || (this.#decoded ? this.#decoded.toRawType() : new this.#Type(this.$registry).toRawType())}>`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,7 +15,7 @@ import { warnGet } from '../utils';
|
||||
* @noInheritDoc
|
||||
*/
|
||||
export class bool extends Boolean implements Codec {
|
||||
readonly registry: Registry;
|
||||
readonly $registry: Registry;
|
||||
|
||||
public $createdAtHash?: IU8a;
|
||||
readonly $encodedLength = 1;
|
||||
@@ -31,7 +31,7 @@ export class bool extends Boolean implements Codec {
|
||||
: !!value
|
||||
);
|
||||
|
||||
this.registry = registry;
|
||||
this.$registry = registry;
|
||||
}
|
||||
|
||||
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
|
||||
@@ -54,11 +54,16 @@ export class bool extends Boolean implements Codec {
|
||||
return warnGet(this, 'isEmpty');
|
||||
}
|
||||
|
||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
||||
public get registry (): Registry {
|
||||
return warnGet(this, 'registry');
|
||||
}
|
||||
|
||||
/**
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
public get hash (): IU8a {
|
||||
return this.registry.hash(this.toU8a());
|
||||
return this.$registry.hash(this.toU8a());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,7 +36,7 @@ function decodeDate (value: CodecDate | Date | AnyNumber): Date {
|
||||
* @noInheritDoc
|
||||
*/
|
||||
export class CodecDate extends Date implements INumber {
|
||||
readonly registry: Registry;
|
||||
readonly $registry: Registry;
|
||||
|
||||
public $createdAtHash?: IU8a;
|
||||
readonly $encodedLength = BITLENGTH / 8;
|
||||
@@ -46,7 +46,7 @@ export class CodecDate extends Date implements INumber {
|
||||
constructor (registry: Registry, value: CodecDate | Date | AnyNumber = 0) {
|
||||
super(decodeDate(value));
|
||||
|
||||
this.registry = registry;
|
||||
this.$registry = registry;
|
||||
}
|
||||
|
||||
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
|
||||
@@ -69,11 +69,16 @@ export class CodecDate extends Date implements INumber {
|
||||
return warnGet(this, 'isEmpty');
|
||||
}
|
||||
|
||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
||||
public get registry (): Registry {
|
||||
return warnGet(this, 'registry');
|
||||
}
|
||||
|
||||
/**
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
public get hash (): IU8a {
|
||||
return this.registry.hash(this.toU8a());
|
||||
return this.$registry.hash(this.toU8a());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,12 +21,11 @@ interface Options {
|
||||
* in some eth_* RPCs
|
||||
*/
|
||||
export class Float extends Number implements IFloat {
|
||||
readonly registry: Registry;
|
||||
|
||||
public $createdAtHash?: IU8a;
|
||||
readonly $encodedLength: number;
|
||||
public $initialU8aLength?: number;
|
||||
public $isStorageFallback?: boolean;
|
||||
readonly $registry: Registry;
|
||||
|
||||
readonly #bitLength: 32 | 64;
|
||||
|
||||
@@ -42,7 +41,7 @@ export class Float extends Number implements IFloat {
|
||||
this.#bitLength = bitLength;
|
||||
this.$encodedLength = bitLength / 8;
|
||||
this.$initialU8aLength = this.$encodedLength;
|
||||
this.registry = registry;
|
||||
this.$registry = registry;
|
||||
}
|
||||
|
||||
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
|
||||
@@ -65,6 +64,11 @@ export class Float extends Number implements IFloat {
|
||||
return warnGet(this, 'isEmpty');
|
||||
}
|
||||
|
||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
||||
public get registry (): Registry {
|
||||
return warnGet(this, 'registry');
|
||||
}
|
||||
|
||||
public static with (bitLength: 32 | 64): CodecClass<Float> {
|
||||
return class extends Float {
|
||||
constructor (registry: Registry, value?: AnyFloat) {
|
||||
@@ -77,7 +81,7 @@ export class Float extends Number implements IFloat {
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
public get hash (): IU8a {
|
||||
return this.registry.hash(this.toU8a());
|
||||
return this.$registry.hash(this.toU8a());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,7 +22,7 @@ function decodeJson (value?: Record<string, unknown> | null): [string, any][] {
|
||||
* @noInheritDoc
|
||||
*/
|
||||
export class Json extends Map<string, any> implements Codec {
|
||||
readonly registry: Registry;
|
||||
readonly $registry: Registry;
|
||||
|
||||
public $createdAtHash?: IU8a;
|
||||
readonly $encodedLength = 0;
|
||||
@@ -34,7 +34,7 @@ export class Json extends Map<string, any> implements Codec {
|
||||
|
||||
super(decoded);
|
||||
|
||||
this.registry = registry;
|
||||
this.$registry = registry;
|
||||
|
||||
objectProperties(this, decoded.map(([k]) => k), (k) => this.get(k));
|
||||
}
|
||||
@@ -59,11 +59,16 @@ export class Json extends Map<string, any> implements Codec {
|
||||
return warnGet(this, 'isEmpty');
|
||||
}
|
||||
|
||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
||||
public get registry (): Registry {
|
||||
return warnGet(this, 'registry');
|
||||
}
|
||||
|
||||
/**
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
public get hash (): IU8a {
|
||||
return this.registry.hash(this.toU8a());
|
||||
return this.$registry.hash(this.toU8a());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,7 +18,7 @@ import { warnGet } from '../utils';
|
||||
* @noInheritDoc
|
||||
*/
|
||||
export class Raw extends Uint8Array implements IU8a {
|
||||
readonly registry: Registry;
|
||||
readonly $registry: Registry;
|
||||
|
||||
public $createdAtHash?: IU8a;
|
||||
public $initialU8aLength?: number;
|
||||
@@ -35,7 +35,7 @@ export class Raw extends Uint8Array implements IU8a {
|
||||
constructor (registry: Registry, value?: AnyU8a, initialU8aLength?: number) {
|
||||
super(u8aToU8a(value));
|
||||
|
||||
this.registry = registry;
|
||||
this.$registry = registry;
|
||||
this.$initialU8aLength = initialU8aLength;
|
||||
}
|
||||
|
||||
@@ -59,6 +59,11 @@ export class Raw extends Uint8Array implements IU8a {
|
||||
return warnGet(this, 'isEmpty');
|
||||
}
|
||||
|
||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
||||
public get registry (): Registry {
|
||||
return warnGet(this, 'registry');
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The length of the value when encoded as a Uint8Array
|
||||
*/
|
||||
@@ -70,7 +75,7 @@ export class Raw extends Uint8Array implements IU8a {
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
public get hash (): IU8a {
|
||||
return this.registry.hash(this.toU8a());
|
||||
return this.$registry.hash(this.toU8a());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -92,7 +92,7 @@ function decodeSet (setValues: SetValues, value: string[] | Set<string> | Uint8A
|
||||
* a bitwise representation of the values.
|
||||
*/
|
||||
export class CodecSet extends Set<string> implements ISet<string> {
|
||||
readonly registry: Registry;
|
||||
readonly $registry: Registry;
|
||||
|
||||
public $createdAtHash?: IU8a;
|
||||
public $initialU8aLength?: number;
|
||||
@@ -104,7 +104,7 @@ export class CodecSet extends Set<string> implements ISet<string> {
|
||||
constructor (registry: Registry, setValues: SetValues, value?: string[] | Set<string> | Uint8Array | BN | number | string, bitLength = 8) {
|
||||
super(decodeSet(setValues, value, bitLength));
|
||||
|
||||
this.registry = registry;
|
||||
this.$registry = registry;
|
||||
this.#allowed = setValues;
|
||||
this.#byteLength = bitLength / 8;
|
||||
}
|
||||
@@ -129,6 +129,11 @@ export class CodecSet extends Set<string> implements ISet<string> {
|
||||
return warnGet(this, 'isEmpty');
|
||||
}
|
||||
|
||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
||||
public get registry (): Registry {
|
||||
return warnGet(this, 'registry');
|
||||
}
|
||||
|
||||
public static with (values: SetValues, bitLength?: number): CodecClass<CodecSet> {
|
||||
return class extends CodecSet {
|
||||
static {
|
||||
@@ -161,7 +166,7 @@ export class CodecSet extends Set<string> implements ISet<string> {
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
public get hash (): IU8a {
|
||||
return this.registry.hash(this.toU8a());
|
||||
return this.$registry.hash(this.toU8a());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -103,7 +103,7 @@ export class Struct<
|
||||
V extends { [K in keyof S]: any } = { [K in keyof S]: any },
|
||||
// type names, mapped by key, name of Class in S
|
||||
E extends { [K in keyof S]: string } = { [K in keyof S]: string }> extends Map<keyof S, Codec> implements IStruct<keyof S> {
|
||||
readonly registry: Registry;
|
||||
readonly $registry: Registry;
|
||||
|
||||
public $createdAtHash?: IU8a;
|
||||
public $initialU8aLength?: number;
|
||||
@@ -123,7 +123,7 @@ export class Struct<
|
||||
super(decoded);
|
||||
|
||||
this.$initialU8aLength = decodedLength;
|
||||
this.registry = registry;
|
||||
this.$registry = registry;
|
||||
this.#jsonMap = jsonMap;
|
||||
this.#Types = typeMap;
|
||||
}
|
||||
@@ -148,6 +148,11 @@ export class Struct<
|
||||
return warnGet(this, 'isEmpty');
|
||||
}
|
||||
|
||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
||||
public get registry (): Registry {
|
||||
return warnGet(this, 'registry');
|
||||
}
|
||||
|
||||
public static with<S extends TypesDef> (Types: S, jsonMap?: Map<string, string>): CodecClass<Struct<S>> {
|
||||
let definition: Definition | undefined;
|
||||
|
||||
@@ -207,7 +212,7 @@ export class Struct<
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
public get hash (): IU8a {
|
||||
return this.registry.hash(this.toU8a());
|
||||
return this.$registry.hash(this.toU8a());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -218,7 +223,7 @@ export class Struct<
|
||||
const [Types, keys] = this.#Types;
|
||||
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
result[keys[i]] = new Types[i](this.registry).toRawType();
|
||||
result[keys[i]] = new Types[i](this.$registry).toRawType();
|
||||
}
|
||||
|
||||
return result as E;
|
||||
@@ -340,7 +345,7 @@ export class Struct<
|
||||
* @description Returns the base runtime type name for this instance
|
||||
*/
|
||||
public toRawType (): string {
|
||||
return stringify(typesToMap(this.registry, this.#Types));
|
||||
return stringify(typesToMap(this.$registry, this.#Types));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -50,7 +50,7 @@ function decodeText (value?: null | AnyString | AnyU8a | { toString: () => strin
|
||||
* @noInheritDoc
|
||||
*/
|
||||
export class Text extends String implements IText {
|
||||
readonly registry: Registry;
|
||||
readonly $registry: Registry;
|
||||
|
||||
public $createdAtHash?: IU8a;
|
||||
public $initialU8aLength?: number;
|
||||
@@ -63,7 +63,7 @@ export class Text extends String implements IText {
|
||||
|
||||
super(str);
|
||||
|
||||
this.registry = registry;
|
||||
this.$registry = registry;
|
||||
this.$initialU8aLength = decodedLength;
|
||||
}
|
||||
|
||||
@@ -87,6 +87,11 @@ export class Text extends String implements IText {
|
||||
return warnGet(this, 'isEmpty');
|
||||
}
|
||||
|
||||
/** @deprecated Use $registry instead. This getter will be removed in a future version */
|
||||
public get registry (): Registry {
|
||||
return warnGet(this, 'registry');
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The length of the value when encoded as a Uint8Array
|
||||
*/
|
||||
@@ -98,7 +103,7 @@ export class Text extends String implements IText {
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
public get hash (): IU8a {
|
||||
return this.registry.hash(this.toU8a());
|
||||
return this.$registry.hash(this.toU8a());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,6 +26,9 @@ interface CodecDeprecated {
|
||||
|
||||
/** @deprecated Use $isEmpty instead. This getter will be removed in a future version. */
|
||||
readonly isEmpty: boolean;
|
||||
|
||||
/** @deprecated Use $registry instead. This getter will be removed in a future version. */
|
||||
readonly registry: Registry;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,16 +78,18 @@ export interface Codec extends CodecDeprecated {
|
||||
*/
|
||||
$isStorageFallback?: boolean;
|
||||
|
||||
/**
|
||||
* @description
|
||||
* The type registry associated with this object, as available when this type
|
||||
* was initially created.
|
||||
*/
|
||||
readonly $registry: Registry;
|
||||
|
||||
/**
|
||||
* @description Returns a hash of the value
|
||||
*/
|
||||
readonly hash: IU8a;
|
||||
|
||||
/**
|
||||
* @description The registry associated with this object
|
||||
*/
|
||||
readonly registry: Registry;
|
||||
|
||||
/**
|
||||
* @description Compares the value of the input to see if there is a match
|
||||
*/
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2023 @polkadot/types-codec authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
type Getters = 'createdAtHash' | 'encodedLength' | 'initialU8aLength' | 'isBasic' | 'isEmpty' | 'isNone' | 'isUnsigned';
|
||||
type Getters = 'createdAtHash' | 'encodedLength' | 'hash' | 'initialU8aLength' | 'isBasic' | 'isEmpty' | 'isNone' | 'isUnsigned' | 'registry';
|
||||
|
||||
const hasWarned: Record<string, boolean> = {};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user