Warn on deprecated getter usage (#5423)

* Warn on deprecated getter usage

* Adjust warning message

* Make read-only interafces for deprecations

* Re-word Codec deprecation messages

* Re-adjust warning messages

* Fix getter return

* Explicit deprecation holder
This commit is contained in:
Jaco
2023-01-19 09:56:34 +02:00
committed by GitHub
parent 96a3ef51f0
commit da1cf9d64e
23 changed files with 253 additions and 110 deletions
+11 -6
View File
@@ -6,7 +6,7 @@ import type { AnyJson, Codec, Inspect, IU8a, IVec, Registry } from '../types';
import { compactToU8a, u8aConcatStrict, u8aToHex } from '@polkadot/util';
import { compareArray } from '../utils/compareArray';
import { compareArray, warnGet } from '../utils';
/**
* @name AbstractArray
@@ -16,11 +16,6 @@ import { compareArray } from '../utils/compareArray';
* @noInheritDoc
*/
export abstract class AbstractArray<T extends Codec> extends Array<T> implements IVec<T> {
/** @deprecated This is not populated anymore. Use $createdAtHash instead. */
public createdAtHash?: never;
/** @deprecated This is not populated anymore. Use $initialU8aLength instead. */
public initialU8aLength?: never;
public readonly registry: Registry;
public $createdAtHash?: IU8a;
@@ -41,6 +36,16 @@ export abstract class AbstractArray<T extends Codec> extends Array<T> implements
this.registry = registry;
}
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
public get createdAtHash (): IU8a | undefined {
return warnGet(this, 'createdAtHash');
}
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
public get initialU8aLength (): number | undefined {
return warnGet(this, 'initialU8aLength');
}
/**
* @description The length of the value when encoded as a Uint8Array
*/
+12 -5
View File
@@ -4,16 +4,13 @@
import type { HexString } from '@polkadot/util/types';
import type { AnyJson, BareOpts, Codec, Inspect, IU8a, Registry } from '../types';
import { warnGet } from '../utils';
/**
* @name Base
* @description A type extends the Base class, when it holds a value
*/
export abstract class AbstractBase<T extends Codec> implements Codec {
/** @deprecated This is not populated anymore. Use $createdAtHash instead. */
public createdAtHash?: never;
/** @deprecated This is not populated anymore. Use $initialU8aLength instead. */
public initialU8aLength?: never;
public readonly registry: Registry;
public $createdAtHash?: IU8a;
@@ -28,6 +25,16 @@ export abstract class AbstractBase<T extends Codec> implements Codec {
this.registry = registry;
}
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
public get createdAtHash (): IU8a | undefined {
return warnGet(this, 'createdAtHash');
}
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
public get initialU8aLength (): number | undefined {
return warnGet(this, 'initialU8aLength');
}
/**
* @description The length of the value when encoded as a Uint8Array
*/
+12 -5
View File
@@ -6,6 +6,8 @@ import type { AnyNumber, Inspect, INumber, IU8a, Registry, UIntBitLength } from
import { BN, BN_BILLION, BN_HUNDRED, BN_MILLION, BN_QUINTILL, bnToBn, bnToHex, bnToU8a, formatBalance, formatNumber, hexToBn, isBn, isFunction, isHex, isNumber, isObject, isString, isU8a, u8aToBn, u8aToNumber } from '@polkadot/util';
import { warnGet } from '../utils';
export const DEFAULT_UINT_BITS = 64;
// Maximum allowed integer for JS is 2^53 - 1, set limit at 52
@@ -72,11 +74,6 @@ function decodeAbstractInt (value: Exclude<AnyNumber, Uint8Array> | Record<strin
* @noInheritDoc
*/
export abstract class AbstractInt extends BN implements INumber {
/** @deprecated This is not populated anymore. Use $createdAtHash instead. */
public createdAtHash?: never;
/** @deprecated This is not populated anymore. Use $initialU8aLength instead. */
public initialU8aLength?: never;
public readonly registry: Registry;
public readonly encodedLength: number;
public readonly isUnsigned: boolean;
@@ -116,6 +113,16 @@ export abstract class AbstractInt extends BN implements INumber {
}
}
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
public get createdAtHash (): IU8a | undefined {
return warnGet(this, 'createdAtHash');
}
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
public get initialU8aLength (): number | undefined {
return warnGet(this, 'initialU8aLength');
}
/**
* @description returns a hash of the contents
*/
@@ -12,6 +12,18 @@ const CompactU32 = Compact.with(U32);
describe('Compact', (): void => {
const registry = new TypeRegistry();
describe('@deprecated', (): void => {
it('warns on createdAtHash usage', () => {
// eslint-disable-next-line deprecation/deprecation
expect(new Compact(registry, 'u128').createdAtHash).not.toBeDefined();
});
it('warns on initialU8aLength usage', () => {
// eslint-disable-next-line deprecation/deprecation
expect(new Compact(registry, 'u128').initialU8aLength).toEqual(0);
});
});
describe('constructor', (): void => {
it('fails on > MAX_SAFE_INTEGER', (): void => {
// eslint-disable-next-line @typescript-eslint/no-loss-of-precision
+11 -6
View File
@@ -7,7 +7,7 @@ import type { AnyJson, AnyNumber, CodecClass, ICompact, Inspect, INumber, IU8a,
import { compactFromU8a, compactFromU8aLim, compactToU8a, isU8a } from '@polkadot/util';
import { typeToConstructor } from '../utils';
import { typeToConstructor, warnGet } from '../utils';
interface Options<T> {
definition?: CodecClass<T>;
@@ -47,11 +47,6 @@ 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> {
/** @deprecated This is not populated anymore. Use $createdAtHash instead. */
public createdAtHash?: never;
/** @deprecated This is not populated anymore. Use $initialU8aLength instead. */
public initialU8aLength?: never;
public readonly registry: Registry;
public $createdAtHash?: IU8a;
@@ -71,6 +66,16 @@ export class Compact<T extends INumber> implements ICompact<T> {
this.#raw = raw;
}
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
public get createdAtHash (): IU8a | undefined {
return warnGet(this, 'createdAtHash');
}
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
public get initialU8aLength (): number | undefined {
return warnGet(this, 'initialU8aLength');
}
public static with<O extends INumber> (Type: CodecClass<O> | string): CodecClass<Compact<O>> {
let definition: CodecClass<O> | undefined;
@@ -4,17 +4,14 @@
import type { HexString } from '@polkadot/util/types';
import type { AnyJson, Codec, CodecClass, Inspect, IU8a, Registry } from '../types';
import { warnGet } from '../utils';
/**
* @name DoNotConstruct
* @description
* An unknown type that fails on construction with the type info
*/
export class DoNotConstruct implements Codec {
/** @deprecated This is not populated anymore. Use $createdAtHash instead. */
public createdAtHash?: never;
/** @deprecated This is not populated anymore. Use $initialU8aLength instead. */
public initialU8aLength?: never;
public readonly registry: Registry;
public $createdAtHash?: IU8a;
@@ -29,6 +26,16 @@ export class DoNotConstruct implements Codec {
throw this.#neverError;
}
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
public get createdAtHash (): IU8a | undefined {
return warnGet(this, 'createdAtHash');
}
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
public get initialU8aLength (): number | undefined {
return warnGet(this, 'initialU8aLength');
}
public static with (typeName?: string): CodecClass {
return class extends DoNotConstruct {
constructor (registry: Registry) {
+11 -6
View File
@@ -6,7 +6,7 @@ import type { AnyJson, Codec, CodecClass, IEnum, Inspect, IU8a, Registry } from
import { isHex, isNumber, isObject, isString, isU8a, objectProperties, stringCamelCase, stringify, stringPascalCase, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util';
import { mapToTypeMap, typesToMap } from '../utils';
import { mapToTypeMap, typesToMap, warnGet } from '../utils';
import { Null } from './Null';
// export interface, this is used in Enum.with, so required as public by TS
@@ -183,11 +183,6 @@ 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 {
/** @deprecated This is not populated anymore. Use $createdAtHash instead. */
public createdAtHash?: never;
/** @deprecated This is not populated anymore. Use $initialU8aLength instead. */
public initialU8aLength?: never;
public readonly registry: Registry;
public $createdAtHash?: IU8a;
@@ -222,6 +217,16 @@ export class Enum implements IEnum {
}
}
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
public get createdAtHash (): IU8a | undefined {
return warnGet(this, 'createdAtHash');
}
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
public get initialU8aLength (): number | undefined {
return warnGet(this, 'initialU8aLength');
}
public static with (Types: Record<string, string | CodecClass> | Record<string, number> | string[]): EnumCodecClass<Enum> {
let definition: Definition | undefined;
+12 -5
View File
@@ -6,17 +6,14 @@ import type { Codec, Inspect, IU8a, Registry } from '../types';
import { isNull } from '@polkadot/util';
import { warnGet } from '../utils';
/**
* @name Null
* @description
* Implements a type that does not contain anything (apart from `null`)
*/
export class Null implements Codec {
/** @deprecated This is not populated anymore. Use $createdAtHash instead. */
public createdAtHash?: never;
/** @deprecated This is not populated anymore. Use $initialU8aLength instead. */
public initialU8aLength?: never;
public readonly encodedLength = 0;
public readonly isEmpty = true;
public readonly registry: Registry;
@@ -29,6 +26,16 @@ export class Null implements Codec {
this.registry = registry;
}
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
public get createdAtHash (): IU8a | undefined {
return warnGet(this, 'createdAtHash');
}
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
public get initialU8aLength (): number | undefined {
return warnGet(this, 'initialU8aLength');
}
/**
* @description returns a hash of the contents
*/
+11 -6
View File
@@ -6,7 +6,7 @@ import type { AnyJson, Codec, CodecClass, Inspect, IOption, IU8a, Registry } fro
import { isCodec, isNull, isU8a, isUndefined, u8aToHex } from '@polkadot/util';
import { typeToConstructor } from '../utils';
import { typeToConstructor, warnGet } from '../utils';
import { Null } from './Null';
interface Options<T> {
@@ -66,11 +66,6 @@ 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> {
/** @deprecated This is not populated anymore. Use $createdAtHash instead. */
public createdAtHash?: never;
/** @deprecated This is not populated anymore. Use $initialU8aLength instead. */
public initialU8aLength?: never;
public readonly registry: Registry;
public $createdAtHash?: IU8a;
@@ -97,6 +92,16 @@ export class Option<T extends Codec> implements IOption<T> {
}
}
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
public get createdAtHash (): IU8a | undefined {
return warnGet(this, 'createdAtHash');
}
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
public get initialU8aLength (): number | undefined {
return warnGet(this, 'initialU8aLength');
}
public static with<O extends Codec> (Type: CodecClass<O> | string): CodecClass<Option<O>> {
let definition: CodecClass<O> | undefined;
+11 -6
View File
@@ -6,7 +6,7 @@ import type { AnyJson, Codec, CodecClass, Inspect, ISet, IU8a, Registry } from '
import { compactFromU8aLim, compactToU8a, isHex, isU8a, logger, stringify, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util';
import { compareSet, decodeU8aVec, sortSet, typeToConstructor } from '../utils';
import { compareSet, decodeU8aVec, sortSet, typeToConstructor, warnGet } from '../utils';
const l = logger('BTreeSet');
@@ -70,11 +70,6 @@ function decodeSet<V extends Codec> (registry: Registry, valType: CodecClass<V>
}
export class BTreeSet<V extends Codec = Codec> extends Set<V> implements ISet<V> {
/** @deprecated This is not populated anymore. Use $createdAtHash instead. */
public createdAtHash?: never;
/** @deprecated This is not populated anymore. Use $initialU8aLength instead. */
public initialU8aLength?: never;
public readonly registry: Registry;
public $createdAtHash?: IU8a;
@@ -93,6 +88,16 @@ export class BTreeSet<V extends Codec = Codec> extends Set<V> implements ISet<V>
this.#ValClass = ValClass;
}
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
public get createdAtHash (): IU8a | undefined {
return warnGet(this, 'createdAtHash');
}
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
public get initialU8aLength (): number | undefined {
return warnGet(this, 'initialU8aLength');
}
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>) {
+11 -6
View File
@@ -10,7 +10,7 @@ import { AbstractArray } from '../abstract/Array';
import { Enum } from '../base/Enum';
import { Raw } from '../native/Raw';
import { Struct } from '../native/Struct';
import { compareMap, decodeU8a, sortMap, typeToConstructor } from '../utils';
import { compareMap, decodeU8a, sortMap, typeToConstructor, warnGet } from '../utils';
const l = logger('Map');
@@ -94,11 +94,6 @@ 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> {
/** @deprecated This is not populated anymore. Use $createdAtHash instead. */
public createdAtHash?: never;
/** @deprecated This is not populated anymore. Use $initialU8aLength instead. */
public initialU8aLength?: never;
public readonly registry: Registry;
public $createdAtHash?: IU8a;
@@ -121,6 +116,16 @@ export class CodecMap<K extends Codec = Codec, V extends Codec = Codec> extends
this.#type = type;
}
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
public get createdAtHash (): IU8a | undefined {
return warnGet(this, 'createdAtHash');
}
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
public get initialU8aLength (): number | undefined {
return warnGet(this, 'initialU8aLength');
}
/**
* @description The length of the value when encoded as a Uint8Array
*/
+12 -5
View File
@@ -6,6 +6,8 @@ import type { AnyBool, Codec, Inspect, IU8a, Registry } from '../types';
import { isU8a, u8aToHex } from '@polkadot/util';
import { warnGet } from '../utils';
/**
* @name bool
* @description
@@ -13,11 +15,6 @@ import { isU8a, u8aToHex } from '@polkadot/util';
* @noInheritDoc
*/
export class bool extends Boolean implements Codec {
/** @deprecated This is not populated anymore. Use $createdAtHash instead. */
public createdAtHash?: never;
/** @deprecated This is not populated anymore. Use $initialU8aLength instead. */
public initialU8aLength?: never;
public readonly registry: Registry;
public $createdAtHash?: IU8a;
@@ -36,6 +33,16 @@ export class bool extends Boolean implements Codec {
this.registry = registry;
}
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
public get createdAtHash (): IU8a | undefined {
return warnGet(this, 'createdAtHash');
}
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
public get initialU8aLength (): number | undefined {
return warnGet(this, 'initialU8aLength');
}
/**
* @description The length of the value when encoded as a Uint8Array
*/
+12 -5
View File
@@ -6,6 +6,8 @@ import type { AnyNumber, Inspect, INumber, IU8a, Registry, UIntBitLength } from
import { BN, bnToBn, bnToHex, bnToU8a, isString, isU8a, u8aToBn } from '@polkadot/util';
import { warnGet } from '../utils';
const BITLENGTH: UIntBitLength = 64;
const U8A_OPTS = { bitLength: BITLENGTH, isLe: true };
@@ -34,11 +36,6 @@ function decodeDate (value: CodecDate | Date | AnyNumber): Date {
* @noInheritDoc
*/
export class CodecDate extends Date implements INumber {
/** @deprecated This is not populated anymore. Use $createdAtHash instead. */
public createdAtHash?: never;
/** @deprecated This is not populated anymore. Use $initialU8aLength instead. */
public initialU8aLength?: never;
public readonly registry: Registry;
public $createdAtHash?: IU8a;
@@ -51,6 +48,16 @@ export class CodecDate extends Date implements INumber {
this.registry = registry;
}
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
public get createdAtHash (): IU8a | undefined {
return warnGet(this, 'createdAtHash');
}
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
public get initialU8aLength (): number | undefined {
return warnGet(this, 'initialU8aLength');
}
/**
* @description The length of the value when encoded as a Uint8Array
*/
+12 -5
View File
@@ -6,6 +6,8 @@ import type { AnyFloat, CodecClass, IFloat, Inspect, IU8a, Registry } from '../t
import { floatToU8a, isHex, isU8a, u8aToFloat, u8aToHex, u8aToU8a } from '@polkadot/util';
import { warnGet } from '../utils';
interface Options {
bitLength?: 32 | 64;
}
@@ -19,11 +21,6 @@ interface Options {
* in some eth_* RPCs
*/
export class Float extends Number implements IFloat {
/** @deprecated This is not populated anymore. Use $createdAtHash instead. */
public createdAtHash?: never;
/** @deprecated This is not populated anymore. Use $initialU8aLength instead. */
public initialU8aLength?: never;
public readonly encodedLength: number;
public readonly registry: Registry;
@@ -48,6 +45,16 @@ export class Float extends Number implements IFloat {
this.registry = registry;
}
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
public get createdAtHash (): IU8a | undefined {
return warnGet(this, 'createdAtHash');
}
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
public get initialU8aLength (): number | undefined {
return warnGet(this, 'initialU8aLength');
}
public static with (bitLength: 32 | 64): CodecClass<Float> {
return class extends Float {
constructor (registry: Registry, value?: AnyFloat) {
+11 -6
View File
@@ -6,7 +6,7 @@ import type { AnyJson, Codec, Inspect, IU8a, Registry } from '../types';
import { isFunction, objectProperties, stringify } from '@polkadot/util';
import { compareMap } from '../utils';
import { compareMap, warnGet } from '../utils';
/** @internal */
function decodeJson (value?: Record<string, unknown> | null): [string, any][] {
@@ -22,11 +22,6 @@ function decodeJson (value?: Record<string, unknown> | null): [string, any][] {
* @noInheritDoc
*/
export class Json extends Map<string, any> implements Codec {
/** @deprecated This is not populated anymore. Use $createdAtHash instead. */
public createdAtHash?: never;
/** @deprecated This is not populated anymore. Use $initialU8aLength instead. */
public initialU8aLength?: never;
public readonly registry: Registry;
public $createdAtHash?: IU8a;
@@ -43,6 +38,16 @@ export class Json extends Map<string, any> implements Codec {
objectProperties(this, decoded.map(([k]) => k), (k) => this.get(k));
}
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
public get createdAtHash (): IU8a | undefined {
return warnGet(this, 'createdAtHash');
}
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
public get initialU8aLength (): number | undefined {
return warnGet(this, 'initialU8aLength');
}
/**
* @description Always 0, never encodes as a Uint8Array
*/
+12 -5
View File
@@ -6,6 +6,8 @@ import type { AnyJson, AnyU8a, Inspect, IU8a, Registry } from '../types';
import { isAscii, isUndefined, isUtf8, u8aToHex, u8aToString, u8aToU8a } from '@polkadot/util';
import { warnGet } from '../utils';
/**
* @name Raw
* @description
@@ -16,11 +18,6 @@ import { isAscii, isUndefined, isUtf8, u8aToHex, u8aToString, u8aToU8a } from '@
* @noInheritDoc
*/
export class Raw extends Uint8Array implements IU8a {
/** @deprecated This is not populated anymore. Use $createdAtHash instead. */
public createdAtHash?: never;
/** @deprecated This is not populated anymore. Use $initialU8aLength instead. */
public initialU8aLength?: never;
public readonly registry: Registry;
public $createdAtHash?: IU8a;
@@ -42,6 +39,16 @@ export class Raw extends Uint8Array implements IU8a {
this.$initialU8aLength = initialU8aLength;
}
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
public get createdAtHash (): IU8a | undefined {
return warnGet(this, 'createdAtHash');
}
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
public get initialU8aLength (): number | undefined {
return warnGet(this, 'initialU8aLength');
}
/**
* @description The length of the value when encoded as a Uint8Array
*/
+11 -6
View File
@@ -6,7 +6,7 @@ import type { CodecClass, Inspect, ISet, IU8a, Registry } from '../types';
import { BN, bnToBn, bnToU8a, isBn, isNumber, isString, isU8a, isUndefined, objectProperties, stringify, stringPascalCase, u8aToBn, u8aToHex, u8aToU8a } from '@polkadot/util';
import { compareArray } from '../utils';
import { compareArray, warnGet } from '../utils';
type SetValues = Record<string, number | BN>;
@@ -92,11 +92,6 @@ function decodeSet (setValues: SetValues, value: string[] | Set<string> | Uint8A
* a bitwise representation of the values.
*/
export class CodecSet extends Set<string> implements ISet<string> {
/** @deprecated This is not populated anymore. Use $createdAtHash instead. */
public createdAtHash?: never;
/** @deprecated This is not populated anymore. Use $initialU8aLength instead. */
public initialU8aLength?: never;
public readonly registry: Registry;
public $createdAtHash?: IU8a;
@@ -114,6 +109,16 @@ export class CodecSet extends Set<string> implements ISet<string> {
this.#byteLength = bitLength / 8;
}
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
public get createdAtHash (): IU8a | undefined {
return warnGet(this, 'createdAtHash');
}
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
public get initialU8aLength (): number | undefined {
return warnGet(this, 'initialU8aLength');
}
public static with (values: SetValues, bitLength?: number): CodecClass<CodecSet> {
return class extends CodecSet {
static {
+11 -6
View File
@@ -6,7 +6,7 @@ import type { AnyJson, BareOpts, Codec, CodecClass, Inspect, IStruct, IU8a, Regi
import { isBoolean, isFunction, isHex, isObject, isU8a, isUndefined, objectProperties, stringCamelCase, stringify, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util';
import { compareMap, decodeU8aStruct, mapToTypeMap, typesToMap } from '../utils';
import { compareMap, decodeU8aStruct, mapToTypeMap, typesToMap, warnGet } from '../utils';
type TypesDef<T = Codec> = Record<string, string | CodecClass<T>>;
@@ -103,11 +103,6 @@ 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> {
/** @deprecated This is not populated anymore. Use $createdAtHash instead. */
public createdAtHash?: never;
/** @deprecated This is not populated anymore. Use $initialU8aLength instead. */
public initialU8aLength?: never;
public readonly registry: Registry;
public $createdAtHash?: IU8a;
@@ -133,6 +128,16 @@ export class Struct<
this.#Types = typeMap;
}
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
public get createdAtHash (): IU8a | undefined {
return warnGet(this, 'createdAtHash');
}
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
public get initialU8aLength (): number | undefined {
return warnGet(this, 'initialU8aLength');
}
public static with<S extends TypesDef> (Types: S, jsonMap?: Map<string, string>): CodecClass<Struct<S>> {
let definition: Definition | undefined;
+11 -5
View File
@@ -6,6 +6,7 @@ import type { AnyString, AnyU8a, Inspect, IText, IU8a, Registry } from '../types
import { compactAddLength, compactFromU8aLim, compactToU8a, hexToU8a, isHex, isString, isU8a, stringToU8a, u8aToHex, u8aToString } from '@polkadot/util';
import { warnGet } from '../utils';
import { Raw } from './Raw';
const MAX_LENGTH = 128 * 1024;
@@ -49,11 +50,6 @@ function decodeText (value?: null | AnyString | AnyU8a | { toString: () => strin
* @noInheritDoc
*/
export class Text extends String implements IText {
/** @deprecated This is not populated anymore. Use $createdAtHash instead. */
public createdAtHash?: never;
/** @deprecated This is not populated anymore. Use $initialU8aLength instead. */
public initialU8aLength?: never;
public readonly registry: Registry;
public $createdAtHash?: IU8a;
@@ -71,6 +67,16 @@ export class Text extends String implements IText {
this.$initialU8aLength = decodedLength;
}
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
public get createdAtHash (): IU8a | undefined {
return warnGet(this, 'createdAtHash');
}
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
public get initialU8aLength (): number | undefined {
return warnGet(this, 'initialU8aLength');
}
/**
* @description The length of the value when encoded as a Uint8Array
*/
+9 -7
View File
@@ -14,6 +14,14 @@ export interface Inspect {
outer?: Uint8Array[];
}
interface CodecDeprecated {
/** @deprecated Use $createdAtHash instead. This getter will be removed in a future version. */
readonly createdAtHash: IU8a | undefined;
/** @deprecated Use $initialU8aLength instead. This getter will be removed in a future version. */
readonly initialU8aLength: number | undefined;
}
/**
* @name Codec
* @description
@@ -22,13 +30,7 @@ export interface Inspect {
* with getters and functions. The Codec Base is however required for operating
* as an encoding/decoding layer
*/
export interface Codec {
/** @deprecated This is not populated anymore. Use $createdAtHash instead. */
createdAtHash?: never;
/** @deprecated This is not populated anymore. Use $initialU8aLength instead. */
initialU8aLength?: never;
export interface Codec extends CodecDeprecated {
/**
* @description
* The block at which this value was retrieved/created (set to non-empty when
+1
View File
@@ -10,3 +10,4 @@ export { typeToConstructor } from './typeToConstructor';
export { sanitize } from './sanitize';
export { sortAsc, sortSet, sortMap } from './sortValues';
export { typesToMap } from './typesToMap';
export { warnGet } from './warnGet';
+19
View File
@@ -0,0 +1,19 @@
// Copyright 2017-2023 @polkadot/types-codec authors & contributors
// SPDX-License-Identifier: Apache-2.0
const hasWarned: Record<string, boolean> = {};
/** @description Warns (once, per class) on the use of a deprecated interface */
export function warnGet <T> (obj: Record<string, any>, name: 'createdAtHash' | 'initialU8aLength'): T {
const clazz = `${obj.constructor?.name || 'Codec'}`;
const check = `${clazz}.${name}`;
const pass = `$${name}`;
if (!hasWarned[check]) {
hasWarned[check] = true;
console.warn(`Use ${clazz}.${pass} instead. The use of ${check} is deprecated and will be removed in a future version.`);
}
return obj[pass] as T;
}