@pezkuwi/types-codec 16.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/build/abstract/Array.d.ts +89 -0
- package/build/abstract/Base.d.ts +75 -0
- package/build/abstract/Int.d.ts +80 -0
- package/build/abstract/Object.d.ts +67 -0
- package/build/abstract/index.d.ts +3 -0
- package/build/base/Compact.d.ts +88 -0
- package/build/base/DoNotConstruct.d.ts +63 -0
- package/build/base/Enum.d.ts +118 -0
- package/build/base/Int.d.ts +16 -0
- package/build/base/Null.d.ts +56 -0
- package/build/base/Option.d.ts +94 -0
- package/build/base/Result.d.ts +38 -0
- package/build/base/Tuple.d.ts +42 -0
- package/build/base/UInt.d.ts +15 -0
- package/build/base/Vec.d.ts +28 -0
- package/build/base/VecAny.d.ts +15 -0
- package/build/base/VecFixed.d.ts +30 -0
- package/build/base/index.d.ts +12 -0
- package/build/bundle.d.ts +7 -0
- package/build/extended/BTreeMap.d.ts +5 -0
- package/build/extended/BTreeSet.d.ts +64 -0
- package/build/extended/BitVec.d.ts +37 -0
- package/build/extended/Bytes.d.ts +29 -0
- package/build/extended/HashMap.d.ts +5 -0
- package/build/extended/Linkage.d.ts +37 -0
- package/build/extended/Map.d.ts +59 -0
- package/build/extended/OptionBool.d.ts +36 -0
- package/build/extended/Range.d.ts +29 -0
- package/build/extended/RangeInclusive.d.ts +6 -0
- package/build/extended/Type.d.ts +16 -0
- package/build/extended/U8aFixed.d.ts +16 -0
- package/build/extended/WrapperKeepOpaque.d.ts +40 -0
- package/build/extended/WrapperOpaque.d.ts +10 -0
- package/build/extended/index.d.ts +14 -0
- package/build/index.d.ts +2 -0
- package/build/native/Bool.d.ts +71 -0
- package/build/native/Date.d.ts +84 -0
- package/build/native/Float.d.ts +68 -0
- package/build/native/Json.d.ts +69 -0
- package/build/native/Raw.d.ts +87 -0
- package/build/native/Set.d.ts +84 -0
- package/build/native/Struct.d.ts +106 -0
- package/build/native/Text.d.ts +77 -0
- package/build/native/index.d.ts +8 -0
- package/build/packageDetect.d.ts +1 -0
- package/build/packageInfo.d.ts +6 -0
- package/build/primitive/F32.d.ts +11 -0
- package/build/primitive/F64.d.ts +11 -0
- package/build/primitive/I128.d.ts +11 -0
- package/build/primitive/I16.d.ts +11 -0
- package/build/primitive/I256.d.ts +11 -0
- package/build/primitive/I32.d.ts +11 -0
- package/build/primitive/I64.d.ts +11 -0
- package/build/primitive/I8.d.ts +11 -0
- package/build/primitive/ISize.d.ts +12 -0
- package/build/primitive/U128.d.ts +11 -0
- package/build/primitive/U16.d.ts +11 -0
- package/build/primitive/U256.d.ts +11 -0
- package/build/primitive/U32.d.ts +11 -0
- package/build/primitive/U64.d.ts +11 -0
- package/build/primitive/U8.d.ts +11 -0
- package/build/primitive/USize.d.ts +12 -0
- package/build/primitive/index.d.ts +16 -0
- package/build/types/codec.d.ts +113 -0
- package/build/types/helpers.d.ts +27 -0
- package/build/types/index.d.ts +4 -0
- package/build/types/interfaces.d.ts +74 -0
- package/build/types/registry.d.ts +67 -0
- package/build/utils/compareArray.d.ts +1 -0
- package/build/utils/compareMap.d.ts +1 -0
- package/build/utils/compareSet.d.ts +1 -0
- package/build/utils/decodeU8a.d.ts +26 -0
- package/build/utils/index.d.ts +8 -0
- package/build/utils/sanitize.d.ts +15 -0
- package/build/utils/sortValues.d.ts +12 -0
- package/build/utils/toConstructors.d.ts +16 -0
- package/build/utils/typesToMap.d.ts +2 -0
- package/build/utils/util.d.ts +3 -0
- package/package.json +34 -0
- package/src/abstract/Array.ts +213 -0
- package/src/abstract/Base.ts +129 -0
- package/src/abstract/Int.ts +271 -0
- package/src/abstract/Object.ts +99 -0
- package/src/abstract/index.ts +6 -0
- package/src/base/Compact.spec.ts +99 -0
- package/src/base/Compact.ts +198 -0
- package/src/base/DoNotConstruct.spec.ts +23 -0
- package/src/base/DoNotConstruct.ts +118 -0
- package/src/base/Enum.spec.ts +487 -0
- package/src/base/Enum.ts +460 -0
- package/src/base/Int.spec.ts +225 -0
- package/src/base/Int.ts +34 -0
- package/src/base/Null.spec.ts +41 -0
- package/src/base/Null.ts +96 -0
- package/src/base/Option.spec.ts +216 -0
- package/src/base/Option.ts +275 -0
- package/src/base/Result.spec.ts +64 -0
- package/src/base/Result.ts +79 -0
- package/src/base/Tuple.spec.ts +161 -0
- package/src/base/Tuple.ts +149 -0
- package/src/base/UInt.spec.ts +192 -0
- package/src/base/UInt.ts +30 -0
- package/src/base/Vec.spec.ts +224 -0
- package/src/base/Vec.ts +133 -0
- package/src/base/VecAny.ts +23 -0
- package/src/base/VecFixed.spec.ts +78 -0
- package/src/base/VecFixed.ts +92 -0
- package/src/base/index.ts +15 -0
- package/src/bundle.ts +13 -0
- package/src/checkTypes.manual.ts +12 -0
- package/src/extended/BTreeMap.spec.ts +245 -0
- package/src/extended/BTreeMap.ts +16 -0
- package/src/extended/BTreeSet.spec.ts +260 -0
- package/src/extended/BTreeSet.ts +233 -0
- package/src/extended/BitVec.spec.ts +97 -0
- package/src/extended/BitVec.ts +137 -0
- package/src/extended/Bytes.spec.ts +75 -0
- package/src/extended/Bytes.ts +88 -0
- package/src/extended/HashMap.spec.ts +36 -0
- package/src/extended/HashMap.ts +16 -0
- package/src/extended/Linkage.spec.ts +43 -0
- package/src/extended/Linkage.ts +81 -0
- package/src/extended/Map.spec.ts +123 -0
- package/src/extended/Map.ts +255 -0
- package/src/extended/OptionBool.spec.ts +49 -0
- package/src/extended/OptionBool.ts +93 -0
- package/src/extended/Range.spec.ts +37 -0
- package/src/extended/Range.ts +56 -0
- package/src/extended/RangeInclusive.ts +20 -0
- package/src/extended/Type.spec.ts +118 -0
- package/src/extended/Type.ts +29 -0
- package/src/extended/U8aFixed.spec.ts +117 -0
- package/src/extended/U8aFixed.ts +57 -0
- package/src/extended/WrapperKeepOpaque.spec.ts +101 -0
- package/src/extended/WrapperKeepOpaque.ts +128 -0
- package/src/extended/WrapperOpaque.spec.ts +58 -0
- package/src/extended/WrapperOpaque.ts +27 -0
- package/src/extended/index.ts +17 -0
- package/src/index.ts +6 -0
- package/src/mod.ts +4 -0
- package/src/native/Bool.spec.ts +74 -0
- package/src/native/Bool.ts +137 -0
- package/src/native/Date.spec.ts +85 -0
- package/src/native/Date.ts +169 -0
- package/src/native/Float.spec.ts +51 -0
- package/src/native/Float.ts +136 -0
- package/src/native/Json.ts +147 -0
- package/src/native/Raw.spec.ts +113 -0
- package/src/native/Raw.ts +171 -0
- package/src/native/Set.spec.ts +116 -0
- package/src/native/Set.ts +269 -0
- package/src/native/Struct.data.ts +4 -0
- package/src/native/Struct.spec.ts +411 -0
- package/src/native/Struct.ts +338 -0
- package/src/native/Text.spec.ts +85 -0
- package/src/native/Text.ts +184 -0
- package/src/native/index.ts +11 -0
- package/src/packageDetect.ts +11 -0
- package/src/packageInfo.ts +6 -0
- package/src/primitive/F32.ts +14 -0
- package/src/primitive/F64.ts +14 -0
- package/src/primitive/I128.ts +14 -0
- package/src/primitive/I16.ts +14 -0
- package/src/primitive/I256.ts +14 -0
- package/src/primitive/I32.ts +14 -0
- package/src/primitive/I64.ts +14 -0
- package/src/primitive/I8.ts +14 -0
- package/src/primitive/ISize.ts +21 -0
- package/src/primitive/U128.ts +14 -0
- package/src/primitive/U16.ts +14 -0
- package/src/primitive/U256.ts +14 -0
- package/src/primitive/U32.ts +14 -0
- package/src/primitive/U64.ts +14 -0
- package/src/primitive/U8.ts +14 -0
- package/src/primitive/USize.ts +21 -0
- package/src/primitive/index.ts +19 -0
- package/src/test/performance.ts +61 -0
- package/src/types/codec.ts +140 -0
- package/src/types/helpers.ts +50 -0
- package/src/types/index.ts +7 -0
- package/src/types/interfaces.ts +98 -0
- package/src/types/registry.ts +86 -0
- package/src/utils/compareArray.ts +22 -0
- package/src/utils/compareMap.ts +40 -0
- package/src/utils/compareSet.ts +23 -0
- package/src/utils/decodeU8a.ts +123 -0
- package/src/utils/index.ts +11 -0
- package/src/utils/sanitize.spec.ts +89 -0
- package/src/utils/sanitize.ts +290 -0
- package/src/utils/sortValues.ts +103 -0
- package/src/utils/toConstructors.ts +46 -0
- package/src/utils/typesToMap.ts +14 -0
- package/src/utils/util.ts +8 -0
- package/tsconfig.build.json +16 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.spec.json +21 -0
package/README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { HexString } from '@pezkuwi/util/types';
|
|
2
|
+
import type { AnyJson, Codec, Inspect, IU8a, IVec, Registry } from '../types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* @name AbstractArray
|
|
5
|
+
* @description
|
|
6
|
+
* This manages codec arrays. It is an extension to Array, providing
|
|
7
|
+
* specific encoding/decoding on top of the base type.
|
|
8
|
+
* @noInheritDoc
|
|
9
|
+
*/
|
|
10
|
+
export declare abstract class AbstractArray<T extends Codec> extends Array<T> implements IVec<T> {
|
|
11
|
+
readonly registry: Registry;
|
|
12
|
+
createdAtHash?: IU8a;
|
|
13
|
+
initialU8aLength?: number;
|
|
14
|
+
isStorageFallback?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* @description This ensures that operators such as clice, filter, map, etc. return
|
|
17
|
+
* new Array instances (without this we need to apply overrides)
|
|
18
|
+
*/
|
|
19
|
+
static get [Symbol.species](): typeof Array;
|
|
20
|
+
protected constructor(registry: Registry, length: number);
|
|
21
|
+
/**
|
|
22
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
23
|
+
*/
|
|
24
|
+
get encodedLength(): number;
|
|
25
|
+
/**
|
|
26
|
+
* @description returns a hash of the contents
|
|
27
|
+
*/
|
|
28
|
+
get hash(): IU8a;
|
|
29
|
+
/**
|
|
30
|
+
* @description Checks if the value is an empty value
|
|
31
|
+
*/
|
|
32
|
+
get isEmpty(): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* @description The length of the value
|
|
35
|
+
*/
|
|
36
|
+
get length(): number;
|
|
37
|
+
/**
|
|
38
|
+
* @description Compares the value of the input to see if there is a match
|
|
39
|
+
*/
|
|
40
|
+
eq(other?: unknown): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* @description Returns a breakdown of the hex encoding for this Codec
|
|
43
|
+
*/
|
|
44
|
+
inspect(): Inspect;
|
|
45
|
+
/**
|
|
46
|
+
* @internal
|
|
47
|
+
* @description Internal per-item inspection of internal values
|
|
48
|
+
*/
|
|
49
|
+
inspectInner(): Inspect[];
|
|
50
|
+
/**
|
|
51
|
+
* @description Converts the Object to an standard JavaScript Array
|
|
52
|
+
*/
|
|
53
|
+
toArray(): T[];
|
|
54
|
+
/**
|
|
55
|
+
* @description Returns a hex string representation of the value
|
|
56
|
+
*/
|
|
57
|
+
toHex(): HexString;
|
|
58
|
+
/**
|
|
59
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
60
|
+
*/
|
|
61
|
+
toHuman(isExtended?: boolean, disableAscii?: boolean): AnyJson;
|
|
62
|
+
/**
|
|
63
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
64
|
+
*/
|
|
65
|
+
toJSON(): AnyJson;
|
|
66
|
+
/**
|
|
67
|
+
* @description Converts the value in a best-fit primitive form
|
|
68
|
+
*/
|
|
69
|
+
toPrimitive(disableAscii?: boolean): AnyJson;
|
|
70
|
+
/**
|
|
71
|
+
* @description Returns the base runtime type name for this instance
|
|
72
|
+
*/
|
|
73
|
+
abstract toRawType(): string;
|
|
74
|
+
/**
|
|
75
|
+
* @description Returns the string representation of the value
|
|
76
|
+
*/
|
|
77
|
+
toString(): string;
|
|
78
|
+
/**
|
|
79
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
80
|
+
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
81
|
+
*/
|
|
82
|
+
toU8a(isBare?: boolean): Uint8Array;
|
|
83
|
+
/**
|
|
84
|
+
* @internal
|
|
85
|
+
* @description Internal per-item SCALE encoding of contained values
|
|
86
|
+
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
87
|
+
*/
|
|
88
|
+
toU8aInner(isBare?: boolean): Uint8Array[];
|
|
89
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { HexString } from '@pezkuwi/util/types';
|
|
2
|
+
import type { AnyJson, BareOpts, Codec, Inspect, IU8a, Registry } from '../types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* @name Base
|
|
5
|
+
* @description A type extends the Base class, when it holds a value
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class AbstractBase<T extends Codec> implements Codec {
|
|
8
|
+
#private;
|
|
9
|
+
readonly registry: Registry;
|
|
10
|
+
createdAtHash?: IU8a | undefined;
|
|
11
|
+
initialU8aLength?: number | undefined;
|
|
12
|
+
isStorageFallback?: boolean;
|
|
13
|
+
protected constructor(registry: Registry, value: T, initialU8aLength?: number);
|
|
14
|
+
/**
|
|
15
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
16
|
+
*/
|
|
17
|
+
get encodedLength(): number;
|
|
18
|
+
/**
|
|
19
|
+
* @description returns a hash of the contents
|
|
20
|
+
*/
|
|
21
|
+
get hash(): IU8a;
|
|
22
|
+
/**
|
|
23
|
+
* @description returns the inner (wrapped value)
|
|
24
|
+
*/
|
|
25
|
+
get inner(): T;
|
|
26
|
+
/**
|
|
27
|
+
* @description Checks if the value is an empty value
|
|
28
|
+
*/
|
|
29
|
+
get isEmpty(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* @description Compares the value of the input to see if there is a match
|
|
32
|
+
*/
|
|
33
|
+
eq(other?: unknown): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* @description Returns a breakdown of the hex encoding for this Codec
|
|
36
|
+
*/
|
|
37
|
+
inspect(): Inspect;
|
|
38
|
+
/**
|
|
39
|
+
* @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
|
|
40
|
+
*/
|
|
41
|
+
toHex(isLe?: boolean): HexString;
|
|
42
|
+
/**
|
|
43
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
44
|
+
*/
|
|
45
|
+
toHuman(isExtended?: boolean, disableAscii?: boolean): AnyJson;
|
|
46
|
+
/**
|
|
47
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
48
|
+
*/
|
|
49
|
+
toJSON(): AnyJson;
|
|
50
|
+
/**
|
|
51
|
+
* @description Converts the value in a best-fit primitive form
|
|
52
|
+
*/
|
|
53
|
+
toPrimitive(disableAscii?: boolean): AnyJson;
|
|
54
|
+
/**
|
|
55
|
+
* @description Returns the string representation of the value
|
|
56
|
+
*/
|
|
57
|
+
toString(): string;
|
|
58
|
+
/**
|
|
59
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
60
|
+
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
61
|
+
*/
|
|
62
|
+
toU8a(isBare?: BareOpts): Uint8Array;
|
|
63
|
+
/**
|
|
64
|
+
* @description Returns the base runtime type name for this instance
|
|
65
|
+
*/
|
|
66
|
+
abstract toRawType(): string;
|
|
67
|
+
/**
|
|
68
|
+
* @description Returns the inner wrapped value (equivalent to valueOf)
|
|
69
|
+
*/
|
|
70
|
+
unwrap(): T;
|
|
71
|
+
/**
|
|
72
|
+
* @description Returns the inner wrapped value
|
|
73
|
+
*/
|
|
74
|
+
valueOf(): T;
|
|
75
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { HexString } from '@pezkuwi/util/types';
|
|
2
|
+
import type { AnyNumber, Inspect, INumber, IU8a, Registry, UIntBitLength } from '../types/index.js';
|
|
3
|
+
import { BN } from '@pezkuwi/util';
|
|
4
|
+
export declare const DEFAULT_UINT_BITS = 64;
|
|
5
|
+
/**
|
|
6
|
+
* @name AbstractInt
|
|
7
|
+
* @ignore
|
|
8
|
+
* @noInheritDoc
|
|
9
|
+
*/
|
|
10
|
+
export declare abstract class AbstractInt extends BN implements INumber {
|
|
11
|
+
#private;
|
|
12
|
+
readonly registry: Registry;
|
|
13
|
+
readonly encodedLength: number;
|
|
14
|
+
readonly isUnsigned: boolean;
|
|
15
|
+
createdAtHash?: IU8a;
|
|
16
|
+
initialU8aLength?: number;
|
|
17
|
+
isStorageFallback?: boolean;
|
|
18
|
+
constructor(registry: Registry, value?: AnyNumber | null, bitLength?: UIntBitLength, isSigned?: boolean);
|
|
19
|
+
/**
|
|
20
|
+
* @description returns a hash of the contents
|
|
21
|
+
*/
|
|
22
|
+
get hash(): IU8a;
|
|
23
|
+
/**
|
|
24
|
+
* @description Checks if the value is a zero value (align elsewhere)
|
|
25
|
+
*/
|
|
26
|
+
get isEmpty(): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* @description Returns the number of bits in the value
|
|
29
|
+
*/
|
|
30
|
+
bitLength(): number;
|
|
31
|
+
/**
|
|
32
|
+
* @description Compares the value of the input to see if there is a match
|
|
33
|
+
*/
|
|
34
|
+
eq(other?: unknown): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* @description Returns a breakdown of the hex encoding for this Codec
|
|
37
|
+
*/
|
|
38
|
+
inspect(): Inspect;
|
|
39
|
+
/**
|
|
40
|
+
* @description True if this value is the max of the type
|
|
41
|
+
*/
|
|
42
|
+
isMax(): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* @description Returns a BigInt representation of the number
|
|
45
|
+
*/
|
|
46
|
+
toBigInt(): bigint;
|
|
47
|
+
/**
|
|
48
|
+
* @description Returns the BN representation of the number. (Compatibility)
|
|
49
|
+
*/
|
|
50
|
+
toBn(): BN;
|
|
51
|
+
/**
|
|
52
|
+
* @description Returns a hex string representation of the value
|
|
53
|
+
*/
|
|
54
|
+
toHex(isLe?: boolean): HexString;
|
|
55
|
+
/**
|
|
56
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
57
|
+
*/
|
|
58
|
+
toHuman(_isExpanded?: boolean): string;
|
|
59
|
+
/**
|
|
60
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
61
|
+
*/
|
|
62
|
+
toJSON(onlyHex?: boolean): any;
|
|
63
|
+
/**
|
|
64
|
+
* @description Returns the value in a primitive form, either number when <= 52 bits, or string otherwise
|
|
65
|
+
*/
|
|
66
|
+
toPrimitive(): number | string;
|
|
67
|
+
/**
|
|
68
|
+
* @description Returns the base runtime type name for this instance
|
|
69
|
+
*/
|
|
70
|
+
toRawType(): string;
|
|
71
|
+
/**
|
|
72
|
+
* @description Returns the string representation of the value
|
|
73
|
+
* @param base The base to use for the conversion
|
|
74
|
+
*/
|
|
75
|
+
toString(base?: number): string;
|
|
76
|
+
/**
|
|
77
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
78
|
+
*/
|
|
79
|
+
toU8a(_isBare?: boolean): Uint8Array;
|
|
80
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { HexString } from '@pezkuwi/util/types';
|
|
2
|
+
import type { AnyJson, BareOpts, CodecObject, Inspect, IU8a, Registry, ToString } from '../types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* @name Object
|
|
5
|
+
* @description A type extends the Base class, when it holds a value
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class AbstractObject<T extends ToString> implements CodecObject<T> {
|
|
8
|
+
readonly registry: Registry;
|
|
9
|
+
createdAtHash?: IU8a;
|
|
10
|
+
initialU8aLength?: number | undefined;
|
|
11
|
+
isStorageFallback?: boolean;
|
|
12
|
+
readonly $: T;
|
|
13
|
+
protected constructor(registry: Registry, value: T, initialU8aLength?: number);
|
|
14
|
+
/**
|
|
15
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
16
|
+
*/
|
|
17
|
+
get encodedLength(): number;
|
|
18
|
+
/**
|
|
19
|
+
* @description returns a hash of the contents
|
|
20
|
+
*/
|
|
21
|
+
get hash(): IU8a;
|
|
22
|
+
/**
|
|
23
|
+
* @description Checks if the value is an empty value
|
|
24
|
+
*/
|
|
25
|
+
abstract get isEmpty(): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* @description Compares the value of the input to see if there is a match
|
|
28
|
+
*/
|
|
29
|
+
abstract eq(other?: unknown): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* @description Returns a breakdown of the hex encoding for this Codec
|
|
32
|
+
*/
|
|
33
|
+
abstract inspect(): Inspect;
|
|
34
|
+
/**
|
|
35
|
+
* @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
|
|
36
|
+
*/
|
|
37
|
+
abstract toHex(isLe?: boolean): HexString;
|
|
38
|
+
/**
|
|
39
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
40
|
+
*/
|
|
41
|
+
abstract toHuman(isExtended?: boolean, disableAscii?: boolean): AnyJson;
|
|
42
|
+
/**
|
|
43
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
44
|
+
*/
|
|
45
|
+
abstract toJSON(): AnyJson;
|
|
46
|
+
/**
|
|
47
|
+
* @description Converts the value in a best-fit primitive form
|
|
48
|
+
*/
|
|
49
|
+
abstract toPrimitive(disableAscii?: boolean): AnyJson;
|
|
50
|
+
/**
|
|
51
|
+
* @description Returns the string representation of the value
|
|
52
|
+
*/
|
|
53
|
+
toString(): string;
|
|
54
|
+
/**
|
|
55
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
56
|
+
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
57
|
+
*/
|
|
58
|
+
abstract toU8a(isBare?: BareOpts): Uint8Array;
|
|
59
|
+
/**
|
|
60
|
+
* @description Returns the base runtime type name for this instance
|
|
61
|
+
*/
|
|
62
|
+
abstract toRawType(): string;
|
|
63
|
+
/**
|
|
64
|
+
* @description Return the internal value (JS-aligned, same result as $)
|
|
65
|
+
*/
|
|
66
|
+
valueOf(): T;
|
|
67
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { BN } from '@pezkuwi/util';
|
|
2
|
+
import type { HexString } from '@pezkuwi/util/types';
|
|
3
|
+
import type { AnyJson, AnyNumber, CodecClass, DefinitionSetter, ICompact, Inspect, INumber, IU8a, Registry } from '../types/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* @name Compact
|
|
6
|
+
* @description
|
|
7
|
+
* A compact length-encoding codec wrapper. It performs the same function as Length, however
|
|
8
|
+
* differs in that it uses a variable number of bytes to do the actual encoding. This is mostly
|
|
9
|
+
* used by other types to add length-prefixed encoding, or in the case of wrapped types, taking
|
|
10
|
+
* a number and making the compact representation thereof
|
|
11
|
+
*/
|
|
12
|
+
export declare class Compact<T extends INumber> implements ICompact<T> {
|
|
13
|
+
#private;
|
|
14
|
+
readonly registry: Registry;
|
|
15
|
+
createdAtHash?: IU8a;
|
|
16
|
+
initialU8aLength?: number;
|
|
17
|
+
isStorageFallback?: boolean;
|
|
18
|
+
constructor(registry: Registry, Type: CodecClass<T> | string, value?: Compact<T> | AnyNumber, { definition, setDefinition }?: DefinitionSetter<CodecClass<T>>);
|
|
19
|
+
static with<O extends INumber>(Type: CodecClass<O> | string): CodecClass<Compact<O>>;
|
|
20
|
+
/**
|
|
21
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
22
|
+
*/
|
|
23
|
+
get encodedLength(): number;
|
|
24
|
+
/**
|
|
25
|
+
* @description returns a hash of the contents
|
|
26
|
+
*/
|
|
27
|
+
get hash(): IU8a;
|
|
28
|
+
/**
|
|
29
|
+
* @description Checks if the value is an empty value
|
|
30
|
+
*/
|
|
31
|
+
get isEmpty(): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* @description Returns the number of bits in the value
|
|
34
|
+
*/
|
|
35
|
+
bitLength(): number;
|
|
36
|
+
/**
|
|
37
|
+
* @description Compares the value of the input to see if there is a match
|
|
38
|
+
*/
|
|
39
|
+
eq(other?: unknown): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* @description Returns a breakdown of the hex encoding for this Codec
|
|
42
|
+
*/
|
|
43
|
+
inspect(): Inspect;
|
|
44
|
+
/**
|
|
45
|
+
* @description Returns a BigInt representation of the number
|
|
46
|
+
*/
|
|
47
|
+
toBigInt(): bigint;
|
|
48
|
+
/**
|
|
49
|
+
* @description Returns the BN representation of the number
|
|
50
|
+
*/
|
|
51
|
+
toBn(): BN;
|
|
52
|
+
/**
|
|
53
|
+
* @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
|
|
54
|
+
*/
|
|
55
|
+
toHex(isLe?: boolean): HexString;
|
|
56
|
+
/**
|
|
57
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
58
|
+
*/
|
|
59
|
+
toHuman(isExtended?: boolean, disableAscii?: boolean): AnyJson;
|
|
60
|
+
/**
|
|
61
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
62
|
+
*/
|
|
63
|
+
toJSON(): AnyJson;
|
|
64
|
+
/**
|
|
65
|
+
* @description Returns the number representation for the value
|
|
66
|
+
*/
|
|
67
|
+
toNumber(): number;
|
|
68
|
+
/**
|
|
69
|
+
* @description Converts the value in a best-fit primitive form
|
|
70
|
+
*/
|
|
71
|
+
toPrimitive(disableAscii?: boolean): string | number;
|
|
72
|
+
/**
|
|
73
|
+
* @description Returns the base runtime type name for this instance
|
|
74
|
+
*/
|
|
75
|
+
toRawType(): string;
|
|
76
|
+
/**
|
|
77
|
+
* @description Returns the string representation of the value
|
|
78
|
+
*/
|
|
79
|
+
toString(): string;
|
|
80
|
+
/**
|
|
81
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
82
|
+
*/
|
|
83
|
+
toU8a(_isBare?: boolean): Uint8Array;
|
|
84
|
+
/**
|
|
85
|
+
* @description Returns the embedded [[UInt]] or [[Moment]] value
|
|
86
|
+
*/
|
|
87
|
+
unwrap(): T;
|
|
88
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { HexString } from '@pezkuwi/util/types';
|
|
2
|
+
import type { AnyJson, Codec, CodecClass, Inspect, IU8a, Registry } from '../types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* @name DoNotConstruct
|
|
5
|
+
* @description
|
|
6
|
+
* An unknown type that fails on construction with the type info
|
|
7
|
+
*/
|
|
8
|
+
export declare class DoNotConstruct implements Codec {
|
|
9
|
+
#private;
|
|
10
|
+
readonly registry: Registry;
|
|
11
|
+
createdAtHash?: IU8a;
|
|
12
|
+
isStorageFallback?: boolean;
|
|
13
|
+
constructor(registry: Registry, typeName?: string);
|
|
14
|
+
static with(typeName?: string): CodecClass;
|
|
15
|
+
/**
|
|
16
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
17
|
+
*/
|
|
18
|
+
get encodedLength(): number;
|
|
19
|
+
/**
|
|
20
|
+
* @description returns a hash of the contents
|
|
21
|
+
*/
|
|
22
|
+
get hash(): IU8a;
|
|
23
|
+
/**
|
|
24
|
+
* @description Checks if the value is an empty value (always true)
|
|
25
|
+
*/
|
|
26
|
+
get isEmpty(): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* @description Unimplemented
|
|
29
|
+
*/
|
|
30
|
+
eq(): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* @description Unimplemented
|
|
33
|
+
*/
|
|
34
|
+
inspect(): Inspect;
|
|
35
|
+
/**
|
|
36
|
+
* @description Unimplemented
|
|
37
|
+
*/
|
|
38
|
+
toHex(): HexString;
|
|
39
|
+
/**
|
|
40
|
+
* @description Unimplemented
|
|
41
|
+
*/
|
|
42
|
+
toHuman(): AnyJson;
|
|
43
|
+
/**
|
|
44
|
+
* @description Unimplemented
|
|
45
|
+
*/
|
|
46
|
+
toJSON(): AnyJson;
|
|
47
|
+
/**
|
|
48
|
+
* @description Unimplemented
|
|
49
|
+
*/
|
|
50
|
+
toPrimitive(): AnyJson;
|
|
51
|
+
/**
|
|
52
|
+
* @description Unimplemented
|
|
53
|
+
*/
|
|
54
|
+
toRawType(): string;
|
|
55
|
+
/**
|
|
56
|
+
* @description Unimplemented
|
|
57
|
+
*/
|
|
58
|
+
toString(): string;
|
|
59
|
+
/**
|
|
60
|
+
* @description Unimplemented
|
|
61
|
+
*/
|
|
62
|
+
toU8a(): Uint8Array;
|
|
63
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type { HexString } from '@pezkuwi/util/types';
|
|
2
|
+
import type { AnyJson, Codec, CodecClass, DefinitionSetter, IEnum, Inspect, IU8a, Registry } from '../types/index.js';
|
|
3
|
+
export type EnumCodecClass<T = Codec> = new (registry: Registry, value?: any, index?: number) => T;
|
|
4
|
+
interface Definition {
|
|
5
|
+
def: TypesDef;
|
|
6
|
+
isBasic: boolean;
|
|
7
|
+
isIndexed: boolean;
|
|
8
|
+
}
|
|
9
|
+
interface EntryDef {
|
|
10
|
+
Type: CodecClass;
|
|
11
|
+
index: number;
|
|
12
|
+
}
|
|
13
|
+
type TypesDef = Record<string, EntryDef>;
|
|
14
|
+
/**
|
|
15
|
+
* @name Enum
|
|
16
|
+
* @description
|
|
17
|
+
* This implements an enum, that based on the value wraps a different type. It is effectively
|
|
18
|
+
* an extension to enum where the value type is determined by the actual index.
|
|
19
|
+
*/
|
|
20
|
+
export declare class Enum implements IEnum {
|
|
21
|
+
#private;
|
|
22
|
+
readonly registry: Registry;
|
|
23
|
+
createdAtHash?: IU8a;
|
|
24
|
+
initialU8aLength?: number;
|
|
25
|
+
isStorageFallback?: boolean;
|
|
26
|
+
constructor(registry: Registry, Types: Record<string, string | CodecClass> | Record<string, number> | string[], value?: unknown, index?: number, { definition, setDefinition }?: DefinitionSetter<Definition>);
|
|
27
|
+
static with(Types: Record<string, string | CodecClass> | Record<string, number> | string[]): EnumCodecClass<Enum>;
|
|
28
|
+
/**
|
|
29
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
30
|
+
*/
|
|
31
|
+
get encodedLength(): number;
|
|
32
|
+
/**
|
|
33
|
+
* @description returns a hash of the contents
|
|
34
|
+
*/
|
|
35
|
+
get hash(): IU8a;
|
|
36
|
+
/**
|
|
37
|
+
* @description The index of the enum value
|
|
38
|
+
*/
|
|
39
|
+
get index(): number;
|
|
40
|
+
/**
|
|
41
|
+
* @description The value of the enum
|
|
42
|
+
*/
|
|
43
|
+
get inner(): Codec;
|
|
44
|
+
/**
|
|
45
|
+
* @description true if this is a basic enum (no values)
|
|
46
|
+
*/
|
|
47
|
+
get isBasic(): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* @description Checks if the value is an empty value
|
|
50
|
+
*/
|
|
51
|
+
get isEmpty(): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* @description Checks if the Enum points to a [[Null]] type
|
|
54
|
+
*/
|
|
55
|
+
get isNone(): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* @description The available keys for this enum
|
|
58
|
+
*/
|
|
59
|
+
get defIndexes(): number[];
|
|
60
|
+
/**
|
|
61
|
+
* @description The available keys for this enum
|
|
62
|
+
*/
|
|
63
|
+
get defKeys(): string[];
|
|
64
|
+
/**
|
|
65
|
+
* @description The name of the type this enum value represents
|
|
66
|
+
*/
|
|
67
|
+
get type(): string;
|
|
68
|
+
/**
|
|
69
|
+
* @description The value of the enum
|
|
70
|
+
*/
|
|
71
|
+
get value(): Codec;
|
|
72
|
+
/**
|
|
73
|
+
* @description Compares the value of the input to see if there is a match
|
|
74
|
+
*/
|
|
75
|
+
eq(other?: unknown): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* @description Returns a breakdown of the hex encoding for this Codec
|
|
78
|
+
*/
|
|
79
|
+
inspect(): Inspect;
|
|
80
|
+
/**
|
|
81
|
+
* @description Returns a hex string representation of the value
|
|
82
|
+
*/
|
|
83
|
+
toHex(): HexString;
|
|
84
|
+
/**
|
|
85
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
86
|
+
*/
|
|
87
|
+
toHuman(isExtended?: boolean, disableAscii?: boolean): AnyJson;
|
|
88
|
+
/**
|
|
89
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
90
|
+
*/
|
|
91
|
+
toJSON(): AnyJson;
|
|
92
|
+
/**
|
|
93
|
+
* @description Returns the number representation for the value
|
|
94
|
+
*/
|
|
95
|
+
toNumber(): number;
|
|
96
|
+
/**
|
|
97
|
+
* @description Converts the value in a best-fit primitive form
|
|
98
|
+
*/
|
|
99
|
+
toPrimitive(disableAscii?: boolean): AnyJson;
|
|
100
|
+
/**
|
|
101
|
+
* @description Returns a raw struct representation of the enum types
|
|
102
|
+
*/
|
|
103
|
+
protected _toRawStruct(): string[] | Record<string, string | number>;
|
|
104
|
+
/**
|
|
105
|
+
* @description Returns the base runtime type name for this instance
|
|
106
|
+
*/
|
|
107
|
+
toRawType(): string;
|
|
108
|
+
/**
|
|
109
|
+
* @description Returns the string representation of the value
|
|
110
|
+
*/
|
|
111
|
+
toString(): string;
|
|
112
|
+
/**
|
|
113
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
114
|
+
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
115
|
+
*/
|
|
116
|
+
toU8a(isBare?: boolean): Uint8Array;
|
|
117
|
+
}
|
|
118
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AnyNumber, CodecClass, Registry, UIntBitLength } from '../types/index.js';
|
|
2
|
+
import { AbstractInt } from '../abstract/Int.js';
|
|
3
|
+
/**
|
|
4
|
+
* @name Int
|
|
5
|
+
* @description
|
|
6
|
+
* A generic signed integer codec. For Substrate all numbers are Little Endian encoded,
|
|
7
|
+
* this handles the encoding and decoding of those numbers. Upon construction
|
|
8
|
+
* the bitLength is provided and any additional use keeps the number to this
|
|
9
|
+
* length. This extends `BN`, so all methods available on a normal `BN` object
|
|
10
|
+
* is available here.
|
|
11
|
+
* @noInheritDoc
|
|
12
|
+
*/
|
|
13
|
+
export declare class Int extends AbstractInt {
|
|
14
|
+
constructor(registry: Registry, value?: AnyNumber | null, bitLength?: UIntBitLength);
|
|
15
|
+
static with(bitLength: UIntBitLength, typeName?: string): CodecClass<Int>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { HexString } from '@pezkuwi/util/types';
|
|
2
|
+
import type { Codec, Inspect, IU8a, Registry } from '../types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* @name Null
|
|
5
|
+
* @description
|
|
6
|
+
* Implements a type that does not contain anything (apart from `null`)
|
|
7
|
+
*/
|
|
8
|
+
export declare class Null implements Codec {
|
|
9
|
+
readonly encodedLength = 0;
|
|
10
|
+
readonly isEmpty = true;
|
|
11
|
+
readonly registry: Registry;
|
|
12
|
+
createdAtHash?: IU8a;
|
|
13
|
+
initialU8aLength: number;
|
|
14
|
+
isStorageFallback?: boolean;
|
|
15
|
+
constructor(registry: Registry);
|
|
16
|
+
/**
|
|
17
|
+
* @description returns a hash of the contents
|
|
18
|
+
*/
|
|
19
|
+
get hash(): IU8a;
|
|
20
|
+
/**
|
|
21
|
+
* @description Compares the value of the input to see if there is a match
|
|
22
|
+
*/
|
|
23
|
+
eq(other?: unknown): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* @description Returns a breakdown of the hex encoding for this Codec
|
|
26
|
+
*/
|
|
27
|
+
inspect(): Inspect;
|
|
28
|
+
/**
|
|
29
|
+
* @description Returns a hex string representation of the value
|
|
30
|
+
*/
|
|
31
|
+
toHex(): HexString;
|
|
32
|
+
/**
|
|
33
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
34
|
+
*/
|
|
35
|
+
toHuman(): null;
|
|
36
|
+
/**
|
|
37
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
38
|
+
*/
|
|
39
|
+
toJSON(): null;
|
|
40
|
+
/**
|
|
41
|
+
* @description Converts the value in a best-fit primitive form
|
|
42
|
+
*/
|
|
43
|
+
toPrimitive(): null;
|
|
44
|
+
/**
|
|
45
|
+
* @description Returns the base runtime type name for this instance
|
|
46
|
+
*/
|
|
47
|
+
toRawType(): string;
|
|
48
|
+
/**
|
|
49
|
+
* @description Returns the string representation of the value
|
|
50
|
+
*/
|
|
51
|
+
toString(): string;
|
|
52
|
+
/**
|
|
53
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
54
|
+
*/
|
|
55
|
+
toU8a(_isBare?: boolean): Uint8Array;
|
|
56
|
+
}
|