* Bump dev

* Adjust

* Adjust
This commit is contained in:
Jaco
2023-04-13 13:10:36 +03:00
committed by GitHub
parent 8fe02a1434
commit a7526ba5f3
46 changed files with 218 additions and 225 deletions
+2 -2
View File
@@ -11,8 +11,8 @@ import type { AnyJson, BareOpts, Codec, Inspect, IU8a, Registry } from '../types
export abstract class AbstractBase<T extends Codec> implements Codec {
readonly registry: Registry;
public createdAtHash?: IU8a;
public initialU8aLength?: number;
public createdAtHash?: IU8a | undefined;
public initialU8aLength?: number | undefined;
public isStorageFallback?: boolean;
readonly #raw: T;
+1 -1
View File
@@ -12,7 +12,7 @@ export abstract class AbstractObject<T extends ToString> implements CodecObject<
readonly registry: Registry;
public createdAtHash?: IU8a;
public initialU8aLength?: number;
public initialU8aLength?: number | undefined;
public isStorageFallback?: boolean;
readonly $: T;
+2 -7
View File
@@ -3,17 +3,12 @@
import type { BN } from '@polkadot/util';
import type { HexString } from '@polkadot/util/types';
import type { AnyJson, AnyNumber, CodecClass, ICompact, Inspect, INumber, IU8a, Registry } from '../types/index.js';
import type { AnyJson, AnyNumber, CodecClass, DefinitionSetter, ICompact, Inspect, INumber, IU8a, Registry } from '../types/index.js';
import { compactFromU8a, compactFromU8aLim, compactToU8a, isU8a } from '@polkadot/util';
import { typeToConstructor } from '../utils/index.js';
interface Options<T> {
definition?: CodecClass<T>;
setDefinition?: (d: CodecClass<T>) => CodecClass<T>;
}
function noopSetDefinition <T> (d: CodecClass<T>): CodecClass<T> {
return d;
}
@@ -56,7 +51,7 @@ export class Compact<T extends INumber> implements ICompact<T> {
readonly #Type: CodecClass<T>;
readonly #raw: T;
constructor (registry: Registry, Type: CodecClass<T> | string, value: Compact<T> | AnyNumber = 0, { definition, setDefinition = noopSetDefinition }: Options<T> = {}) {
constructor (registry: Registry, Type: CodecClass<T> | string, value: Compact<T> | AnyNumber = 0, { definition, setDefinition = noopSetDefinition }: DefinitionSetter<CodecClass<T>> = {}) {
this.registry = registry;
this.#Type = definition || setDefinition(typeToConstructor(registry, Type));
+2 -7
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { HexString } from '@polkadot/util/types';
import type { AnyJson, Codec, CodecClass, IEnum, Inspect, IU8a, Registry } from '../types/index.js';
import type { AnyJson, Codec, CodecClass, DefinitionSetter, IEnum, Inspect, IU8a, Registry } from '../types/index.js';
import { isHex, isNumber, isObject, isString, isU8a, objectProperties, stringCamelCase, stringify, stringPascalCase, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util';
@@ -32,11 +32,6 @@ interface Decoded {
value: Codec;
}
interface Options {
definition?: Definition;
setDefinition?: (d: Definition) => Definition;
}
function noopSetDefinition (d: Definition): Definition {
return d;
}
@@ -196,7 +191,7 @@ export class Enum implements IEnum {
readonly #isIndexed: boolean;
readonly #raw: Codec;
constructor (registry: Registry, Types: Record<string, string | CodecClass> | Record<string, number> | string[], value?: unknown, index?: number, { definition, setDefinition = noopSetDefinition }: Options = {}) {
constructor (registry: Registry, Types: Record<string, string | CodecClass> | Record<string, number> | string[], value?: unknown, index?: number, { definition, setDefinition = noopSetDefinition }: DefinitionSetter<Definition> = {}) {
const { def, isBasic, isIndexed } = definition || setDefinition(extractDef(registry, Types));
// shortcut isU8a as used in SCALE decoding
+2 -7
View File
@@ -2,18 +2,13 @@
// SPDX-License-Identifier: Apache-2.0
import type { HexString } from '@polkadot/util/types';
import type { AnyJson, Codec, CodecClass, Inspect, IOption, IU8a, Registry } from '../types/index.js';
import type { AnyJson, Codec, CodecClass, DefinitionSetter, Inspect, IOption, IU8a, Registry } from '../types/index.js';
import { isCodec, isNull, isU8a, isUndefined, u8aToHex } from '@polkadot/util';
import { typeToConstructor } from '../utils/index.js';
import { Null } from './Null.js';
interface Options<T> {
definition?: CodecClass<T>;
setDefinition?: (d: CodecClass<T>) => CodecClass<T>;
}
function noopSetDefinition <T extends Codec> (d: CodecClass<T>): CodecClass<T> {
return d;
}
@@ -75,7 +70,7 @@ export class Option<T extends Codec> implements IOption<T> {
readonly #Type: CodecClass<T>;
readonly #raw: T;
constructor (registry: Registry, typeName: CodecClass<T> | string, value?: unknown, { definition, setDefinition = noopSetDefinition }: Options<T> = {}) {
constructor (registry: Registry, typeName: CodecClass<T> | string, value?: unknown, { definition, setDefinition = noopSetDefinition }: DefinitionSetter<CodecClass<T>> = {}) {
const Type = definition || setDefinition(typeToConstructor(registry, typeName));
const decoded = isU8a(value) && value.length && !isCodec(value)
? value[0] === 0
+2 -7
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2023 @polkadot/types-codec authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AnyTupleValue, Codec, CodecClass, Inspect, ITuple, Registry } from '../types/index.js';
import type { AnyTupleValue, Codec, CodecClass, DefinitionSetter, Inspect, ITuple, Registry } from '../types/index.js';
import { isFunction, isHex, isString, isU8a, stringify, u8aConcatStrict, u8aToU8a } from '@polkadot/util';
@@ -16,11 +16,6 @@ type TupleTypes = TupleType[] | {
type Definition = [CodecClass[], string[]];
interface Options {
definition?: Definition;
setDefinition?: (d: Definition) => Definition;
}
function noopSetDefinition (d: Definition): Definition {
return d;
}
@@ -67,7 +62,7 @@ function decodeTuple (registry: Registry, result: Codec[], value: Exclude<AnyTup
export class Tuple extends AbstractArray<Codec> implements ITuple<Codec[]> {
#Types: Definition;
constructor (registry: Registry, Types: TupleTypes | TupleType, value?: AnyTupleValue, { definition, setDefinition = noopSetDefinition }: Options = {}) {
constructor (registry: Registry, Types: TupleTypes | TupleType, value?: AnyTupleValue, { definition, setDefinition = noopSetDefinition }: DefinitionSetter<Definition> = {}) {
const Classes = definition || setDefinition(
Array.isArray(Types)
? [Types.map((t) => typeToConstructor(registry, t)), []]
+2 -7
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { HexString } from '@polkadot/util/types';
import type { Codec, CodecClass, Registry } from '../types/index.js';
import type { Codec, CodecClass, DefinitionSetter, Registry } from '../types/index.js';
import { compactFromU8aLim, isHex, isU8a, logger, stringify, u8aToU8a } from '@polkadot/util';
@@ -13,11 +13,6 @@ const MAX_LENGTH = 64 * 1024;
const l = logger('Vec');
interface Options<T> {
definition?: CodecClass<T>;
setDefinition?: (d: CodecClass<T>) => CodecClass<T>;
}
function noopSetDefinition <T extends Codec> (d: CodecClass<T>): CodecClass<T> {
return d;
}
@@ -80,7 +75,7 @@ export function decodeVec<T extends Codec> (registry: Registry, result: T[], val
export class Vec<T extends Codec> extends AbstractArray<T> {
#Type: CodecClass<T>;
constructor (registry: Registry, Type: CodecClass<T> | string, value: Uint8Array | HexString | unknown[] = [], { definition, setDefinition = noopSetDefinition }: Options<T> = {}) {
constructor (registry: Registry, Type: CodecClass<T> | string, value: Uint8Array | HexString | unknown[] = [], { definition, setDefinition = noopSetDefinition }: DefinitionSetter<CodecClass<T>> = {}) {
const [decodeFrom, length, startAt] = decodeVecLength(value);
super(registry, length);
+2 -7
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { HexString } from '@polkadot/util/types';
import type { Codec, CodecClass, Inspect, Registry } from '../types/index.js';
import type { Codec, CodecClass, DefinitionSetter, Inspect, Registry } from '../types/index.js';
import { isU8a, u8aConcatStrict } from '@polkadot/util';
@@ -10,11 +10,6 @@ import { AbstractArray } from '../abstract/Array.js';
import { decodeU8aVec, typeToConstructor } from '../utils/index.js';
import { decodeVec } from './Vec.js';
interface Options<T> {
definition?: CodecClass<T>;
setDefinition?: (d: CodecClass<T>) => CodecClass<T>;
}
function noopSetDefinition <T extends Codec> (d: CodecClass<T>): CodecClass<T> {
return d;
}
@@ -27,7 +22,7 @@ function noopSetDefinition <T extends Codec> (d: CodecClass<T>): CodecClass<T> {
export class VecFixed<T extends Codec> extends AbstractArray<T> {
#Type: CodecClass<T>;
constructor (registry: Registry, Type: CodecClass<T> | string, length: number, value: Uint8Array | HexString | unknown[] = [] as unknown[], { definition, setDefinition = noopSetDefinition }: Options<T> = {}) {
constructor (registry: Registry, Type: CodecClass<T> | string, length: number, value: Uint8Array | HexString | unknown[] = [] as unknown[], { definition, setDefinition = noopSetDefinition }: DefinitionSetter<CodecClass<T>> = {}) {
super(registry, length);
this.#Type = definition || setDefinition(typeToConstructor<T>(registry, Type));
+2 -2
View File
@@ -18,8 +18,8 @@ import { isAscii, isUndefined, isUtf8, u8aToHex, u8aToString, u8aToU8a } from '@
export class Raw extends Uint8Array implements IU8a {
readonly registry: Registry;
public createdAtHash?: IU8a;
public initialU8aLength?: number;
public createdAtHash?: IU8a | undefined;
public initialU8aLength?: number | undefined;
public isStorageFallback?: boolean;
/**
+3 -8
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { HexString } from '@polkadot/util/types';
import type { AnyJson, BareOpts, Codec, CodecClass, Inspect, IStruct, IU8a, Registry } from '../types/index.js';
import type { AnyJson, BareOpts, Codec, CodecClass, DefinitionSetter, Inspect, IStruct, IU8a, Registry } from '../types/index.js';
import { isBoolean, isHex, isObject, isU8a, isUndefined, objectProperties, stringCamelCase, stringify, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util';
@@ -12,11 +12,6 @@ type TypesDef<T = Codec> = Record<string, string | CodecClass<T>>;
type Definition = [CodecClass[], string[]];
interface Options {
definition?: Definition;
setDefinition?: (d: Definition) => Definition;
}
function noopSetDefinition (d: Definition): Definition {
return d;
}
@@ -105,14 +100,14 @@ export class Struct<
E extends { [K in keyof S]: string } = { [K in keyof S]: string }> extends Map<keyof S, Codec> implements IStruct<keyof S> {
readonly registry: Registry;
public createdAtHash?: IU8a;
public createdAtHash?: IU8a | undefined;
public initialU8aLength?: number;
public isStorageFallback?: boolean;
readonly #jsonMap: Map<keyof S, string>;
readonly #Types: Definition;
constructor (registry: Registry, Types: S, value?: V | Map<unknown, unknown> | unknown[] | HexString | null, jsonMap = new Map<string, string>(), { definition, setDefinition = noopSetDefinition }: Options = {}) {
constructor (registry: Registry, Types: S, value?: V | Map<unknown, unknown> | unknown[] | HexString | null, jsonMap = new Map<string, string>(), { definition, setDefinition = noopSetDefinition }: DefinitionSetter<Definition> = {}) {
const typeMap = definition || setDefinition(mapToTypeMap(registry, Types));
const [decoded, decodedLength] = isU8a(value) || isHex(value)
? decodeU8aStruct(registry, new Array<[string, Codec]>(typeMap[0].length), u8aToU8a(value), typeMap)
+3 -3
View File
@@ -9,7 +9,7 @@ import type { Registry } from './registry.js';
export type BareOpts = boolean | Record<string, boolean>;
export interface Inspect {
inner?: Inspect[];
inner?: Inspect[] | undefined;
name?: string;
outer?: Uint8Array[];
}
@@ -28,14 +28,14 @@ export interface Codec {
* The block at which this value was retrieved/created (set to non-empty when
* retrieved from storage)
*/
createdAtHash?: IU8a;
createdAtHash?: IU8a | undefined;
/**
* @description
* The length of the initial encoded value (Only available when the value was
* constructed from a Uint8Array input)
*/
initialU8aLength?: number;
initialU8aLength?: number | undefined;
/**
* @description
@@ -42,4 +42,9 @@ export interface ToBn {
toBn: () => BN;
}
export interface DefinitionSetter <T> {
definition?: T | undefined;
setDefinition?: (d: T) => T;
}
export type LookupString = `Lookup${number}`;
+1 -1
View File
@@ -31,7 +31,7 @@ export type RegistryTypes =
{ _set: Record<string, number> }>;
export interface CodecCreateOptions {
blockHash?: Uint8Array | string | null;
blockHash?: Uint8Array | string | null | undefined;
isFallback?: boolean;
isOptional?: boolean;
isPedantic?: boolean;