@polkadot/types-codec 9.5.2 → 9.6.2
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/abstract/Array.js +15 -44
- package/abstract/Base.js +12 -28
- package/abstract/BigInt.js +3 -2
- package/abstract/Int.js +25 -52
- package/abstract/index.js +1 -0
- package/base/Compact.js +21 -45
- package/base/DoNotConstruct.js +3 -19
- package/base/Enum.js +37 -88
- package/base/Int.js +2 -5
- package/base/Null.js +12 -23
- package/base/Option.js +23 -59
- package/base/Result.js +8 -19
- package/base/Tuple.js +12 -29
- package/base/UInt.js +2 -4
- package/base/Vec.js +7 -25
- package/base/VecAny.js +2 -2
- package/base/VecFixed.js +8 -20
- package/base/index.js +1 -0
- package/bundle.js +1 -0
- package/cjs/abstract/Array.js +13 -47
- package/cjs/abstract/Base.js +12 -30
- package/cjs/abstract/BigInt.js +1 -4
- package/cjs/abstract/Int.js +25 -55
- package/cjs/abstract/index.js +0 -3
- package/cjs/base/Compact.js +21 -48
- package/cjs/base/DoNotConstruct.js +3 -21
- package/cjs/base/Enum.js +34 -92
- package/cjs/base/Int.js +0 -7
- package/cjs/base/Null.js +10 -25
- package/cjs/base/Option.js +23 -63
- package/cjs/base/Result.js +6 -21
- package/cjs/base/Tuple.js +12 -33
- package/cjs/base/UInt.js +0 -6
- package/cjs/base/Vec.js +7 -31
- package/cjs/base/VecAny.js +0 -4
- package/cjs/base/VecFixed.js +8 -25
- package/cjs/base/index.js +0 -12
- package/cjs/bundle.js +0 -13
- package/cjs/detectPackage.js +2 -4
- package/cjs/extended/BTreeMap.js +1 -5
- package/cjs/extended/BTreeSet.js +17 -57
- package/cjs/extended/BitVec.js +11 -25
- package/cjs/extended/Bytes.js +9 -20
- package/cjs/extended/HashMap.js +1 -5
- package/cjs/extended/Linkage.js +5 -20
- package/cjs/extended/Map.js +16 -62
- package/cjs/extended/OptionBool.js +8 -21
- package/cjs/extended/Range.js +3 -13
- package/cjs/extended/RangeInclusive.js +1 -6
- package/cjs/extended/Type.js +1 -7
- package/cjs/extended/U8aFixed.js +2 -15
- package/cjs/extended/WrapperKeepOpaque.js +8 -28
- package/cjs/extended/WrapperOpaque.js +2 -8
- package/cjs/extended/index.js +0 -14
- package/cjs/index.js +0 -3
- package/cjs/native/Bool.js +14 -32
- package/cjs/native/Date.js +18 -40
- package/cjs/native/Float.js +11 -29
- package/cjs/native/Json.js +14 -33
- package/cjs/native/Raw.js +18 -41
- package/cjs/native/Set.js +21 -67
- package/cjs/native/Struct.data.js +1 -0
- package/cjs/native/Struct.js +33 -83
- package/cjs/native/Text.js +20 -44
- package/cjs/native/index.js +0 -8
- package/cjs/packageInfo.js +3 -1
- package/cjs/primitive/F32.js +0 -3
- package/cjs/primitive/F64.js +0 -3
- package/cjs/primitive/I128.js +0 -3
- package/cjs/primitive/I16.js +0 -3
- package/cjs/primitive/I256.js +0 -3
- package/cjs/primitive/I32.js +0 -3
- package/cjs/primitive/I64.js +0 -3
- package/cjs/primitive/I8.js +0 -3
- package/cjs/primitive/U128.js +0 -3
- package/cjs/primitive/U16.js +0 -3
- package/cjs/primitive/U256.js +0 -3
- package/cjs/primitive/U32.js +0 -3
- package/cjs/primitive/U64.js +0 -3
- package/cjs/primitive/U8.js +0 -3
- package/cjs/primitive/USize.js +0 -4
- package/cjs/primitive/index.js +0 -15
- package/cjs/types/index.js +0 -8
- package/cjs/utils/compareArray.js +1 -4
- package/cjs/utils/compareMap.js +4 -9
- package/cjs/utils/compareSet.js +4 -6
- package/cjs/utils/decodeU8a.js +10 -18
- package/cjs/utils/index.js +0 -9
- package/cjs/utils/mapToTypeMap.js +0 -4
- package/cjs/utils/sanitize.js +66 -71
- package/cjs/utils/sortValues.js +5 -18
- package/cjs/utils/typeToConstructor.js +1 -2
- package/cjs/utils/typesToMap.js +1 -3
- package/cjs/utils/util.js +1 -2
- package/detectOther.js +2 -0
- package/detectPackage.js +2 -0
- package/extended/BTreeMap.js +1 -2
- package/extended/BTreeSet.js +17 -53
- package/extended/BitVec.js +13 -22
- package/extended/Bytes.js +11 -17
- package/extended/HashMap.js +1 -2
- package/extended/Linkage.js +5 -12
- package/extended/Map.js +16 -54
- package/extended/OptionBool.js +8 -17
- package/extended/Range.js +4 -11
- package/extended/RangeInclusive.js +1 -3
- package/extended/Type.js +3 -4
- package/extended/U8aFixed.js +4 -12
- package/extended/WrapperKeepOpaque.js +8 -23
- package/extended/WrapperOpaque.js +2 -5
- package/extended/index.js +1 -0
- package/index.js +1 -0
- package/native/Bool.js +16 -30
- package/native/Date.js +18 -37
- package/native/Float.js +12 -27
- package/native/Json.js +16 -30
- package/native/Raw.js +20 -39
- package/native/Set.js +21 -63
- package/native/Struct.data.js +1 -0
- package/native/Struct.js +33 -80
- package/native/Text.js +20 -40
- package/native/index.js +1 -0
- package/package.json +2 -2
- package/packageInfo.js +3 -1
- package/primitive/F32.js +2 -1
- package/primitive/F64.js +2 -1
- package/primitive/I128.js +2 -1
- package/primitive/I16.js +2 -1
- package/primitive/I256.js +2 -1
- package/primitive/I32.js +2 -1
- package/primitive/I64.js +2 -1
- package/primitive/I8.js +2 -1
- package/primitive/U128.js +2 -1
- package/primitive/U16.js +2 -1
- package/primitive/U256.js +2 -1
- package/primitive/U32.js +2 -1
- package/primitive/U64.js +2 -1
- package/primitive/U8.js +2 -1
- package/primitive/USize.js +2 -2
- package/primitive/index.js +1 -0
- package/types/index.js +1 -0
- package/utils/compareArray.js +4 -3
- package/utils/compareMap.js +4 -7
- package/utils/compareSet.js +4 -5
- package/utils/decodeU8a.js +12 -15
- package/utils/index.js +1 -0
- package/utils/mapToTypeMap.js +2 -3
- package/utils/sanitize.js +66 -60
- package/utils/sortValues.js +6 -15
- package/utils/typeToConstructor.js +1 -0
- package/utils/typesToMap.js +1 -2
- package/utils/util.js +1 -0
package/base/Compact.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { compactFromU8a, compactFromU8aLim, compactToU8a, isU8a } from '@polkadot/util';
|
|
4
5
|
import { typeToConstructor } from "../utils/index.js";
|
|
5
|
-
|
|
6
6
|
function noopSetDefinition(d) {
|
|
7
7
|
return d;
|
|
8
8
|
}
|
|
9
|
-
|
|
10
9
|
function decodeCompact(registry, Type, value) {
|
|
11
10
|
if (isU8a(value)) {
|
|
12
11
|
const [decodedLength, bn] = (value[0] & 0b11) < 0b11 ? compactFromU8aLim(value) : compactFromU8a(value);
|
|
@@ -17,9 +16,9 @@ function decodeCompact(registry, Type, value) {
|
|
|
17
16
|
} else if (value instanceof Type) {
|
|
18
17
|
return [value, 0];
|
|
19
18
|
}
|
|
20
|
-
|
|
21
19
|
return [new Type(registry, value), 0];
|
|
22
20
|
}
|
|
21
|
+
|
|
23
22
|
/**
|
|
24
23
|
* @name Compact
|
|
25
24
|
* @description
|
|
@@ -28,12 +27,9 @@ function decodeCompact(registry, Type, value) {
|
|
|
28
27
|
* used by other types to add length-prefixed encoding, or in the case of wrapped types, taking
|
|
29
28
|
* a number and making the compact representation thereof
|
|
30
29
|
*/
|
|
31
|
-
|
|
32
|
-
|
|
33
30
|
export class Compact {
|
|
34
31
|
#Type;
|
|
35
32
|
#raw;
|
|
36
|
-
|
|
37
33
|
constructor(registry, Type, value = 0, {
|
|
38
34
|
definition,
|
|
39
35
|
setDefinition = noopSetDefinition
|
|
@@ -44,12 +40,11 @@ export class Compact {
|
|
|
44
40
|
this.initialU8aLength = decodedLength;
|
|
45
41
|
this.#raw = raw;
|
|
46
42
|
}
|
|
47
|
-
|
|
48
43
|
static with(Type) {
|
|
49
|
-
let definition;
|
|
44
|
+
let definition;
|
|
50
45
|
|
|
46
|
+
// eslint-disable-next-line no-return-assign
|
|
51
47
|
const setDefinition = d => definition = d;
|
|
52
|
-
|
|
53
48
|
return class extends Compact {
|
|
54
49
|
constructor(registry, value) {
|
|
55
50
|
super(registry, Type, value, {
|
|
@@ -57,148 +52,129 @@ export class Compact {
|
|
|
57
52
|
setDefinition
|
|
58
53
|
});
|
|
59
54
|
}
|
|
60
|
-
|
|
61
55
|
};
|
|
62
56
|
}
|
|
57
|
+
|
|
63
58
|
/**
|
|
64
59
|
* @description The length of the value when encoded as a Uint8Array
|
|
65
60
|
*/
|
|
66
|
-
|
|
67
|
-
|
|
68
61
|
get encodedLength() {
|
|
69
62
|
return this.toU8a().length;
|
|
70
63
|
}
|
|
64
|
+
|
|
71
65
|
/**
|
|
72
66
|
* @description returns a hash of the contents
|
|
73
67
|
*/
|
|
74
|
-
|
|
75
|
-
|
|
76
68
|
get hash() {
|
|
77
69
|
return this.registry.hash(this.toU8a());
|
|
78
70
|
}
|
|
71
|
+
|
|
79
72
|
/**
|
|
80
73
|
* @description Checks if the value is an empty value
|
|
81
74
|
*/
|
|
82
|
-
|
|
83
|
-
|
|
84
75
|
get isEmpty() {
|
|
85
76
|
return this.#raw.isEmpty;
|
|
86
77
|
}
|
|
78
|
+
|
|
87
79
|
/**
|
|
88
80
|
* @description Returns the number of bits in the value
|
|
89
81
|
*/
|
|
90
|
-
|
|
91
|
-
|
|
92
82
|
bitLength() {
|
|
93
83
|
return this.#raw.bitLength();
|
|
94
84
|
}
|
|
85
|
+
|
|
95
86
|
/**
|
|
96
87
|
* @description Compares the value of the input to see if there is a match
|
|
97
88
|
*/
|
|
98
|
-
|
|
99
|
-
|
|
100
89
|
eq(other) {
|
|
101
90
|
return this.#raw.eq(other instanceof Compact ? other.#raw : other);
|
|
102
91
|
}
|
|
92
|
+
|
|
103
93
|
/**
|
|
104
94
|
* @description Returns a breakdown of the hex encoding for this Codec
|
|
105
95
|
*/
|
|
106
|
-
|
|
107
|
-
|
|
108
96
|
inspect() {
|
|
109
97
|
return {
|
|
110
98
|
outer: [this.toU8a()]
|
|
111
99
|
};
|
|
112
100
|
}
|
|
101
|
+
|
|
113
102
|
/**
|
|
114
103
|
* @description Returns a BigInt representation of the number
|
|
115
104
|
*/
|
|
116
|
-
|
|
117
|
-
|
|
118
105
|
toBigInt() {
|
|
119
106
|
return this.#raw.toBigInt();
|
|
120
107
|
}
|
|
108
|
+
|
|
121
109
|
/**
|
|
122
110
|
* @description Returns the BN representation of the number
|
|
123
111
|
*/
|
|
124
|
-
|
|
125
|
-
|
|
126
112
|
toBn() {
|
|
127
113
|
return this.#raw.toBn();
|
|
128
114
|
}
|
|
115
|
+
|
|
129
116
|
/**
|
|
130
117
|
* @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
|
|
131
118
|
*/
|
|
132
|
-
|
|
133
|
-
|
|
134
119
|
toHex(isLe) {
|
|
135
120
|
return this.#raw.toHex(isLe);
|
|
136
121
|
}
|
|
122
|
+
|
|
137
123
|
/**
|
|
138
124
|
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
139
125
|
*/
|
|
140
|
-
|
|
141
|
-
|
|
142
126
|
toHuman(isExtended) {
|
|
143
127
|
return this.#raw.toHuman(isExtended);
|
|
144
128
|
}
|
|
129
|
+
|
|
145
130
|
/**
|
|
146
131
|
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
147
132
|
*/
|
|
148
|
-
|
|
149
|
-
|
|
150
133
|
toJSON() {
|
|
151
134
|
return this.#raw.toJSON();
|
|
152
135
|
}
|
|
136
|
+
|
|
153
137
|
/**
|
|
154
138
|
* @description Returns the number representation for the value
|
|
155
139
|
*/
|
|
156
|
-
|
|
157
|
-
|
|
158
140
|
toNumber() {
|
|
159
141
|
return this.#raw.toNumber();
|
|
160
142
|
}
|
|
143
|
+
|
|
161
144
|
/**
|
|
162
145
|
* @description Converts the value in a best-fit primitive form
|
|
163
146
|
*/
|
|
164
|
-
|
|
165
|
-
|
|
166
147
|
toPrimitive() {
|
|
167
148
|
return this.#raw.toPrimitive();
|
|
168
149
|
}
|
|
150
|
+
|
|
169
151
|
/**
|
|
170
152
|
* @description Returns the base runtime type name for this instance
|
|
171
153
|
*/
|
|
172
|
-
|
|
173
|
-
|
|
174
154
|
toRawType() {
|
|
175
155
|
return `Compact<${this.registry.getClassName(this.#Type) || this.#raw.toRawType()}>`;
|
|
176
156
|
}
|
|
157
|
+
|
|
177
158
|
/**
|
|
178
159
|
* @description Returns the string representation of the value
|
|
179
160
|
*/
|
|
180
|
-
|
|
181
|
-
|
|
182
161
|
toString() {
|
|
183
162
|
return this.#raw.toString();
|
|
184
163
|
}
|
|
164
|
+
|
|
185
165
|
/**
|
|
186
166
|
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
187
167
|
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
188
168
|
*/
|
|
189
169
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
190
|
-
|
|
191
|
-
|
|
192
170
|
toU8a(isBare) {
|
|
193
171
|
return compactToU8a(this.#raw.toBn());
|
|
194
172
|
}
|
|
173
|
+
|
|
195
174
|
/**
|
|
196
175
|
* @description Returns the embedded [[UInt]] or [[Moment]] value
|
|
197
176
|
*/
|
|
198
|
-
|
|
199
|
-
|
|
200
177
|
unwrap() {
|
|
201
178
|
return this.#raw;
|
|
202
179
|
}
|
|
203
|
-
|
|
204
180
|
}
|
package/base/DoNotConstruct.js
CHANGED
|
@@ -8,80 +8,64 @@
|
|
|
8
8
|
*/
|
|
9
9
|
export class DoNotConstruct {
|
|
10
10
|
#neverError;
|
|
11
|
-
|
|
12
11
|
constructor(registry, typeName = 'DoNotConstruct') {
|
|
13
12
|
this.registry = registry;
|
|
14
13
|
this.#neverError = new Error(`DoNotConstruct: Cannot construct unknown type ${typeName}`);
|
|
15
14
|
throw this.#neverError;
|
|
16
15
|
}
|
|
17
|
-
|
|
18
16
|
static with(typeName) {
|
|
19
17
|
return class extends DoNotConstruct {
|
|
20
18
|
constructor(registry) {
|
|
21
19
|
super(registry, typeName);
|
|
22
20
|
}
|
|
23
|
-
|
|
24
21
|
};
|
|
25
22
|
}
|
|
23
|
+
|
|
26
24
|
/**
|
|
27
25
|
* @description The length of the value when encoded as a Uint8Array
|
|
28
26
|
*/
|
|
29
|
-
|
|
30
|
-
|
|
31
27
|
get encodedLength() {
|
|
32
28
|
throw this.#neverError;
|
|
33
29
|
}
|
|
30
|
+
|
|
34
31
|
/**
|
|
35
32
|
* @description returns a hash of the contents
|
|
36
33
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
39
34
|
get hash() {
|
|
40
35
|
throw this.#neverError;
|
|
41
36
|
}
|
|
37
|
+
|
|
42
38
|
/**
|
|
43
39
|
* @description Checks if the value is an empty value (always true)
|
|
44
40
|
*/
|
|
45
|
-
|
|
46
|
-
|
|
47
41
|
get isEmpty() {
|
|
48
42
|
throw this.#neverError;
|
|
49
43
|
}
|
|
50
|
-
|
|
51
44
|
eq() {
|
|
52
45
|
throw this.#neverError;
|
|
53
46
|
}
|
|
54
|
-
|
|
55
47
|
inspect() {
|
|
56
48
|
throw this.#neverError;
|
|
57
49
|
}
|
|
58
|
-
|
|
59
50
|
toHex() {
|
|
60
51
|
throw this.#neverError;
|
|
61
52
|
}
|
|
62
|
-
|
|
63
53
|
toHuman() {
|
|
64
54
|
throw this.#neverError;
|
|
65
55
|
}
|
|
66
|
-
|
|
67
56
|
toJSON() {
|
|
68
57
|
throw this.#neverError;
|
|
69
58
|
}
|
|
70
|
-
|
|
71
59
|
toPrimitive() {
|
|
72
60
|
throw this.#neverError;
|
|
73
61
|
}
|
|
74
|
-
|
|
75
62
|
toRawType() {
|
|
76
63
|
throw this.#neverError;
|
|
77
64
|
}
|
|
78
|
-
|
|
79
65
|
toString() {
|
|
80
66
|
throw this.#neverError;
|
|
81
67
|
}
|
|
82
|
-
|
|
83
68
|
toU8a() {
|
|
84
69
|
throw this.#neverError;
|
|
85
70
|
}
|
|
86
|
-
|
|
87
71
|
}
|