@polkadot/types-codec 16.2.1 → 16.3.1
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/Base.js +14 -14
- package/abstract/Int.js +8 -8
- package/base/Compact.js +20 -20
- package/base/DoNotConstruct.js +15 -15
- package/base/Enum.js +39 -39
- package/base/Option.js +17 -17
- package/base/Tuple.js +6 -6
- package/base/Vec.js +8 -8
- package/base/VecFixed.js +5 -5
- package/cjs/abstract/Base.js +14 -14
- package/cjs/abstract/Int.js +8 -8
- package/cjs/base/Compact.js +20 -20
- package/cjs/base/DoNotConstruct.js +15 -15
- package/cjs/base/Enum.js +39 -39
- package/cjs/base/Option.js +17 -17
- package/cjs/base/Tuple.js +6 -6
- package/cjs/base/Vec.js +8 -8
- package/cjs/base/VecFixed.js +5 -5
- package/cjs/extended/BTreeSet.js +3 -3
- package/cjs/extended/BitVec.js +9 -9
- package/cjs/extended/Map.js +7 -7
- package/cjs/extended/Range.js +3 -3
- package/cjs/extended/WrapperKeepOpaque.js +19 -19
- package/cjs/native/Float.js +4 -4
- package/cjs/native/Set.js +9 -9
- package/cjs/native/Struct.js +8 -8
- package/cjs/native/Text.js +3 -3
- package/cjs/packageInfo.js +1 -1
- package/cjs/utils/decodeU8a.js +12 -0
- package/extended/BTreeSet.js +3 -3
- package/extended/BitVec.js +9 -9
- package/extended/Map.js +7 -7
- package/extended/Range.js +3 -3
- package/extended/WrapperKeepOpaque.js +19 -19
- package/native/Float.js +4 -4
- package/native/Set.js +9 -9
- package/native/Struct.js +8 -8
- package/native/Text.js +3 -3
- package/package.json +3 -3
- package/packageInfo.js +1 -1
- package/utils/decodeU8a.js +12 -0
package/cjs/base/Enum.js
CHANGED
|
@@ -130,12 +130,12 @@ class Enum {
|
|
|
130
130
|
createdAtHash;
|
|
131
131
|
initialU8aLength;
|
|
132
132
|
isStorageFallback;
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
133
|
+
#def;
|
|
134
|
+
#entryIndex;
|
|
135
|
+
#indexes;
|
|
136
|
+
#isBasic;
|
|
137
|
+
#isIndexed;
|
|
138
|
+
#raw;
|
|
139
139
|
constructor(registry, Types, value, index, { definition, setDefinition = util_1.identity } = {}) {
|
|
140
140
|
const { def, isBasic, isIndexed } = definition || setDefinition(extractDef(registry, Types));
|
|
141
141
|
// shortcut isU8a as used in SCALE decoding
|
|
@@ -143,14 +143,14 @@ class Enum {
|
|
|
143
143
|
? createFromU8a(registry, def, value[0], value.subarray(1))
|
|
144
144
|
: decodeEnum(registry, def, value, index);
|
|
145
145
|
this.registry = registry;
|
|
146
|
-
this
|
|
147
|
-
this
|
|
148
|
-
this
|
|
149
|
-
this
|
|
150
|
-
this
|
|
151
|
-
this
|
|
152
|
-
if (this.
|
|
153
|
-
this.initialU8aLength = 1 + this.
|
|
146
|
+
this.#def = def;
|
|
147
|
+
this.#isBasic = isBasic;
|
|
148
|
+
this.#isIndexed = isIndexed;
|
|
149
|
+
this.#indexes = Object.values(def).map(({ index }) => index);
|
|
150
|
+
this.#entryIndex = this.#indexes.indexOf(decoded.index);
|
|
151
|
+
this.#raw = decoded.value;
|
|
152
|
+
if (this.#raw.initialU8aLength) {
|
|
153
|
+
this.initialU8aLength = 1 + this.#raw.initialU8aLength;
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
static with(Types) {
|
|
@@ -187,7 +187,7 @@ class Enum {
|
|
|
187
187
|
* @description The length of the value when encoded as a Uint8Array
|
|
188
188
|
*/
|
|
189
189
|
get encodedLength() {
|
|
190
|
-
return 1 + this.
|
|
190
|
+
return 1 + this.#raw.encodedLength;
|
|
191
191
|
}
|
|
192
192
|
/**
|
|
193
193
|
* @description returns a hash of the contents
|
|
@@ -199,55 +199,55 @@ class Enum {
|
|
|
199
199
|
* @description The index of the enum value
|
|
200
200
|
*/
|
|
201
201
|
get index() {
|
|
202
|
-
return this
|
|
202
|
+
return this.#indexes[this.#entryIndex];
|
|
203
203
|
}
|
|
204
204
|
/**
|
|
205
205
|
* @description The value of the enum
|
|
206
206
|
*/
|
|
207
207
|
get inner() {
|
|
208
|
-
return this
|
|
208
|
+
return this.#raw;
|
|
209
209
|
}
|
|
210
210
|
/**
|
|
211
211
|
* @description true if this is a basic enum (no values)
|
|
212
212
|
*/
|
|
213
213
|
get isBasic() {
|
|
214
|
-
return this
|
|
214
|
+
return this.#isBasic;
|
|
215
215
|
}
|
|
216
216
|
/**
|
|
217
217
|
* @description Checks if the value is an empty value
|
|
218
218
|
*/
|
|
219
219
|
get isEmpty() {
|
|
220
|
-
return this.
|
|
220
|
+
return this.#raw.isEmpty;
|
|
221
221
|
}
|
|
222
222
|
/**
|
|
223
223
|
* @description Checks if the Enum points to a [[Null]] type
|
|
224
224
|
*/
|
|
225
225
|
get isNone() {
|
|
226
|
-
return this
|
|
226
|
+
return this.#raw instanceof Null_js_1.Null;
|
|
227
227
|
}
|
|
228
228
|
/**
|
|
229
229
|
* @description The available keys for this enum
|
|
230
230
|
*/
|
|
231
231
|
get defIndexes() {
|
|
232
|
-
return this
|
|
232
|
+
return this.#indexes;
|
|
233
233
|
}
|
|
234
234
|
/**
|
|
235
235
|
* @description The available keys for this enum
|
|
236
236
|
*/
|
|
237
237
|
get defKeys() {
|
|
238
|
-
return Object.keys(this
|
|
238
|
+
return Object.keys(this.#def);
|
|
239
239
|
}
|
|
240
240
|
/**
|
|
241
241
|
* @description The name of the type this enum value represents
|
|
242
242
|
*/
|
|
243
243
|
get type() {
|
|
244
|
-
return this.defKeys[this
|
|
244
|
+
return this.defKeys[this.#entryIndex];
|
|
245
245
|
}
|
|
246
246
|
/**
|
|
247
247
|
* @description The value of the enum
|
|
248
248
|
*/
|
|
249
249
|
get value() {
|
|
250
|
-
return this
|
|
250
|
+
return this.#raw;
|
|
251
251
|
}
|
|
252
252
|
/**
|
|
253
253
|
* @description Compares the value of the input to see if there is a match
|
|
@@ -260,7 +260,7 @@ class Enum {
|
|
|
260
260
|
else if ((0, util_1.isNumber)(other)) {
|
|
261
261
|
return this.toNumber() === other;
|
|
262
262
|
}
|
|
263
|
-
else if (this
|
|
263
|
+
else if (this.#isBasic && (0, util_1.isString)(other)) {
|
|
264
264
|
return this.type === other;
|
|
265
265
|
}
|
|
266
266
|
else if ((0, util_1.isHex)(other)) {
|
|
@@ -279,10 +279,10 @@ class Enum {
|
|
|
279
279
|
* @description Returns a breakdown of the hex encoding for this Codec
|
|
280
280
|
*/
|
|
281
281
|
inspect() {
|
|
282
|
-
if (this
|
|
282
|
+
if (this.#isBasic) {
|
|
283
283
|
return { outer: [new Uint8Array([this.index])] };
|
|
284
284
|
}
|
|
285
|
-
const { inner, outer = [] } = this.
|
|
285
|
+
const { inner, outer = [] } = this.#raw.inspect();
|
|
286
286
|
return {
|
|
287
287
|
inner,
|
|
288
288
|
outer: [new Uint8Array([this.index]), ...outer]
|
|
@@ -298,17 +298,17 @@ class Enum {
|
|
|
298
298
|
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
299
299
|
*/
|
|
300
300
|
toHuman(isExtended, disableAscii) {
|
|
301
|
-
return this
|
|
301
|
+
return this.#isBasic || this.isNone
|
|
302
302
|
? this.type
|
|
303
|
-
: { [this.type]: this.
|
|
303
|
+
: { [this.type]: this.#raw.toHuman(isExtended, disableAscii) };
|
|
304
304
|
}
|
|
305
305
|
/**
|
|
306
306
|
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
307
307
|
*/
|
|
308
308
|
toJSON() {
|
|
309
|
-
return this
|
|
309
|
+
return this.#isBasic
|
|
310
310
|
? this.type
|
|
311
|
-
: { [(0, util_1.stringCamelCase)(this.type)]: this.
|
|
311
|
+
: { [(0, util_1.stringCamelCase)(this.type)]: this.#raw.toJSON() };
|
|
312
312
|
}
|
|
313
313
|
/**
|
|
314
314
|
* @description Returns the number representation for the value
|
|
@@ -320,23 +320,23 @@ class Enum {
|
|
|
320
320
|
* @description Converts the value in a best-fit primitive form
|
|
321
321
|
*/
|
|
322
322
|
toPrimitive(disableAscii) {
|
|
323
|
-
return this
|
|
323
|
+
return this.#isBasic
|
|
324
324
|
? this.type
|
|
325
|
-
: { [(0, util_1.stringCamelCase)(this.type)]: this.
|
|
325
|
+
: { [(0, util_1.stringCamelCase)(this.type)]: this.#raw.toPrimitive(disableAscii) };
|
|
326
326
|
}
|
|
327
327
|
/**
|
|
328
328
|
* @description Returns a raw struct representation of the enum types
|
|
329
329
|
*/
|
|
330
330
|
_toRawStruct() {
|
|
331
|
-
if (this
|
|
332
|
-
return this
|
|
331
|
+
if (this.#isBasic) {
|
|
332
|
+
return this.#isIndexed
|
|
333
333
|
? this.defKeys.reduce((out, key, index) => {
|
|
334
|
-
out[key] = this
|
|
334
|
+
out[key] = this.#indexes[index];
|
|
335
335
|
return out;
|
|
336
336
|
}, {})
|
|
337
337
|
: this.defKeys;
|
|
338
338
|
}
|
|
339
|
-
const entries = Object.entries(this
|
|
339
|
+
const entries = Object.entries(this.#def);
|
|
340
340
|
return (0, index_js_1.typesToMap)(this.registry, entries.reduce((out, [key, { Type }], i) => {
|
|
341
341
|
out[0][i] = Type;
|
|
342
342
|
out[1][i] = key;
|
|
@@ -363,10 +363,10 @@ class Enum {
|
|
|
363
363
|
*/
|
|
364
364
|
toU8a(isBare) {
|
|
365
365
|
return isBare
|
|
366
|
-
? this.
|
|
366
|
+
? this.#raw.toU8a(isBare)
|
|
367
367
|
: (0, util_1.u8aConcatStrict)([
|
|
368
368
|
new Uint8Array([this.index]),
|
|
369
|
-
this.
|
|
369
|
+
this.#raw.toU8a(isBare)
|
|
370
370
|
]);
|
|
371
371
|
}
|
|
372
372
|
}
|
package/cjs/base/Option.js
CHANGED
|
@@ -56,8 +56,8 @@ class Option {
|
|
|
56
56
|
createdAtHash;
|
|
57
57
|
initialU8aLength;
|
|
58
58
|
isStorageFallback;
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
#Type;
|
|
60
|
+
#raw;
|
|
61
61
|
constructor(registry, typeName, value, { definition, setDefinition = util_1.identity } = {}) {
|
|
62
62
|
const Type = definition || setDefinition((0, index_js_1.typeToConstructor)(registry, typeName));
|
|
63
63
|
const decoded = (0, util_1.isU8a)(value) && value.length && !(0, util_1.isCodec)(value)
|
|
@@ -66,8 +66,8 @@ class Option {
|
|
|
66
66
|
: new Type(registry, value.subarray(1))
|
|
67
67
|
: decodeOption(registry, Type, value);
|
|
68
68
|
this.registry = registry;
|
|
69
|
-
this
|
|
70
|
-
this
|
|
69
|
+
this.#Type = Type;
|
|
70
|
+
this.#raw = decoded;
|
|
71
71
|
if (decoded?.initialU8aLength) {
|
|
72
72
|
this.initialU8aLength = 1 + decoded.initialU8aLength;
|
|
73
73
|
}
|
|
@@ -89,7 +89,7 @@ class Option {
|
|
|
89
89
|
*/
|
|
90
90
|
get encodedLength() {
|
|
91
91
|
// boolean byte (has value, doesn't have) along with wrapped length
|
|
92
|
-
return 1 + this.
|
|
92
|
+
return 1 + this.#raw.encodedLength;
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
95
95
|
* @description returns a hash of the contents
|
|
@@ -107,7 +107,7 @@ class Option {
|
|
|
107
107
|
* @description Checks if the Option has no value
|
|
108
108
|
*/
|
|
109
109
|
get isNone() {
|
|
110
|
-
return this
|
|
110
|
+
return this.#raw instanceof None;
|
|
111
111
|
}
|
|
112
112
|
/**
|
|
113
113
|
* @description Checks if the Option has a value
|
|
@@ -119,7 +119,7 @@ class Option {
|
|
|
119
119
|
* @description The actual value for the Option
|
|
120
120
|
*/
|
|
121
121
|
get value() {
|
|
122
|
-
return this
|
|
122
|
+
return this.#raw;
|
|
123
123
|
}
|
|
124
124
|
/**
|
|
125
125
|
* @description Compares the value of the input to see if there is a match
|
|
@@ -137,7 +137,7 @@ class Option {
|
|
|
137
137
|
if (this.isNone) {
|
|
138
138
|
return { outer: [new Uint8Array([0])] };
|
|
139
139
|
}
|
|
140
|
-
const { inner, outer = [] } = this.
|
|
140
|
+
const { inner, outer = [] } = this.#raw.inspect();
|
|
141
141
|
return {
|
|
142
142
|
inner,
|
|
143
143
|
outer: [new Uint8Array([1]), ...outer]
|
|
@@ -157,7 +157,7 @@ class Option {
|
|
|
157
157
|
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
158
158
|
*/
|
|
159
159
|
toHuman(isExtended, disableAscii) {
|
|
160
|
-
return this.
|
|
160
|
+
return this.#raw.toHuman(isExtended, disableAscii);
|
|
161
161
|
}
|
|
162
162
|
/**
|
|
163
163
|
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
@@ -165,7 +165,7 @@ class Option {
|
|
|
165
165
|
toJSON() {
|
|
166
166
|
return this.isNone
|
|
167
167
|
? null
|
|
168
|
-
: this.
|
|
168
|
+
: this.#raw.toJSON();
|
|
169
169
|
}
|
|
170
170
|
/**
|
|
171
171
|
* @description Converts the value in a best-fit primitive form
|
|
@@ -173,13 +173,13 @@ class Option {
|
|
|
173
173
|
toPrimitive(disableAscii) {
|
|
174
174
|
return this.isNone
|
|
175
175
|
? null
|
|
176
|
-
: this.
|
|
176
|
+
: this.#raw.toPrimitive(disableAscii);
|
|
177
177
|
}
|
|
178
178
|
/**
|
|
179
179
|
* @description Returns the base runtime type name for this instance
|
|
180
180
|
*/
|
|
181
181
|
toRawType(isBare) {
|
|
182
|
-
const wrapped = this.registry.getClassName(this
|
|
182
|
+
const wrapped = this.registry.getClassName(this.#Type) || new this.#Type(this.registry).toRawType();
|
|
183
183
|
return isBare
|
|
184
184
|
? wrapped
|
|
185
185
|
: `Option<${wrapped}>`;
|
|
@@ -188,7 +188,7 @@ class Option {
|
|
|
188
188
|
* @description Returns the string representation of the value
|
|
189
189
|
*/
|
|
190
190
|
toString() {
|
|
191
|
-
return this.
|
|
191
|
+
return this.#raw.toString();
|
|
192
192
|
}
|
|
193
193
|
/**
|
|
194
194
|
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
@@ -196,12 +196,12 @@ class Option {
|
|
|
196
196
|
*/
|
|
197
197
|
toU8a(isBare) {
|
|
198
198
|
if (isBare) {
|
|
199
|
-
return this.
|
|
199
|
+
return this.#raw.toU8a(true);
|
|
200
200
|
}
|
|
201
201
|
const u8a = new Uint8Array(this.encodedLength);
|
|
202
202
|
if (this.isSome) {
|
|
203
203
|
u8a.set([1]);
|
|
204
|
-
u8a.set(this.
|
|
204
|
+
u8a.set(this.#raw.toU8a(), 1);
|
|
205
205
|
}
|
|
206
206
|
return u8a;
|
|
207
207
|
}
|
|
@@ -212,7 +212,7 @@ class Option {
|
|
|
212
212
|
if (this.isNone) {
|
|
213
213
|
throw new Error('Option: unwrapping a None value');
|
|
214
214
|
}
|
|
215
|
-
return this
|
|
215
|
+
return this.#raw;
|
|
216
216
|
}
|
|
217
217
|
/**
|
|
218
218
|
* @description Returns the value that the Option represents (if available) or defaultValue if none
|
|
@@ -230,7 +230,7 @@ class Option {
|
|
|
230
230
|
unwrapOrDefault() {
|
|
231
231
|
return this.isSome
|
|
232
232
|
? this.unwrap()
|
|
233
|
-
: new this
|
|
233
|
+
: new this.#Type(this.registry);
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
236
|
exports.Option = Option;
|
package/cjs/base/Tuple.js
CHANGED
|
@@ -40,7 +40,7 @@ function decodeTuple(registry, result, value, Classes) {
|
|
|
40
40
|
* own type. It extends the base JS `Array` object.
|
|
41
41
|
*/
|
|
42
42
|
class Tuple extends Array_js_1.AbstractArray {
|
|
43
|
-
|
|
43
|
+
#Types;
|
|
44
44
|
constructor(registry, Types, value, { definition, setDefinition = util_1.identity } = {}) {
|
|
45
45
|
const Classes = definition || setDefinition(Array.isArray(Types)
|
|
46
46
|
? [(0, index_js_1.typesToConstructors)(registry, Types), []]
|
|
@@ -51,7 +51,7 @@ class Tuple extends Array_js_1.AbstractArray {
|
|
|
51
51
|
this.initialU8aLength = ((0, util_1.isU8a)(value)
|
|
52
52
|
? (0, index_js_1.decodeU8a)(registry, this, value, Classes)
|
|
53
53
|
: decodeTuple(registry, this, value, Classes))[1];
|
|
54
|
-
this
|
|
54
|
+
this.#Types = Classes;
|
|
55
55
|
}
|
|
56
56
|
static with(Types) {
|
|
57
57
|
let definition;
|
|
@@ -77,9 +77,9 @@ class Tuple extends Array_js_1.AbstractArray {
|
|
|
77
77
|
* @description The types definition of the tuple
|
|
78
78
|
*/
|
|
79
79
|
get Types() {
|
|
80
|
-
return this
|
|
81
|
-
? this
|
|
82
|
-
: this
|
|
80
|
+
return this.#Types[1].length
|
|
81
|
+
? this.#Types[1]
|
|
82
|
+
: this.#Types[0].map((T) => new T(this.registry).toRawType());
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
85
85
|
* @description Returns a breakdown of the hex encoding for this Codec
|
|
@@ -93,7 +93,7 @@ class Tuple extends Array_js_1.AbstractArray {
|
|
|
93
93
|
* @description Returns the base runtime type name for this instance
|
|
94
94
|
*/
|
|
95
95
|
toRawType() {
|
|
96
|
-
const types = this
|
|
96
|
+
const types = this.#Types[0].map((T) => this.registry.getClassName(T) || new T(this.registry).toRawType());
|
|
97
97
|
return `(${types.join(',')})`;
|
|
98
98
|
}
|
|
99
99
|
/**
|
package/cjs/base/Vec.js
CHANGED
|
@@ -57,14 +57,14 @@ function decodeVec(registry, result, value, startAt, Type) {
|
|
|
57
57
|
* specific encoding/decoding on top of the base type.
|
|
58
58
|
*/
|
|
59
59
|
class Vec extends Array_js_1.AbstractArray {
|
|
60
|
-
|
|
60
|
+
#Type;
|
|
61
61
|
constructor(registry, Type, value = [], { definition, setDefinition = util_1.identity } = {}) {
|
|
62
62
|
const [decodeFrom, length, startAt] = decodeVecLength(value);
|
|
63
63
|
super(registry, length);
|
|
64
|
-
this
|
|
64
|
+
this.#Type = definition || setDefinition((0, index_js_1.typeToConstructor)(registry, Type));
|
|
65
65
|
this.initialU8aLength = ((0, util_1.isU8a)(decodeFrom)
|
|
66
|
-
? (0, index_js_1.decodeU8aVec)(registry, this, decodeFrom, startAt, this
|
|
67
|
-
: decodeVec(registry, this, decodeFrom, startAt, this
|
|
66
|
+
? (0, index_js_1.decodeU8aVec)(registry, this, decodeFrom, startAt, this.#Type)
|
|
67
|
+
: decodeVec(registry, this, decodeFrom, startAt, this.#Type))[0];
|
|
68
68
|
}
|
|
69
69
|
static with(Type) {
|
|
70
70
|
let definition;
|
|
@@ -80,16 +80,16 @@ class Vec extends Array_js_1.AbstractArray {
|
|
|
80
80
|
* @description The type for the items
|
|
81
81
|
*/
|
|
82
82
|
get Type() {
|
|
83
|
-
return this.
|
|
83
|
+
return this.#Type.name;
|
|
84
84
|
}
|
|
85
85
|
/**
|
|
86
86
|
* @description Finds the index of the value in the array
|
|
87
87
|
*/
|
|
88
88
|
indexOf(other) {
|
|
89
89
|
// convert type first, this removes overhead from the eq
|
|
90
|
-
const check = other instanceof this
|
|
90
|
+
const check = other instanceof this.#Type
|
|
91
91
|
? other
|
|
92
|
-
: new this
|
|
92
|
+
: new this.#Type(this.registry, other);
|
|
93
93
|
for (let i = 0, count = this.length; i < count; i++) {
|
|
94
94
|
if (check.eq(this[i])) {
|
|
95
95
|
return i;
|
|
@@ -101,7 +101,7 @@ class Vec extends Array_js_1.AbstractArray {
|
|
|
101
101
|
* @description Returns the base runtime type name for this instance
|
|
102
102
|
*/
|
|
103
103
|
toRawType() {
|
|
104
|
-
return `Vec<${this.registry.getClassName(this
|
|
104
|
+
return `Vec<${this.registry.getClassName(this.#Type) || new this.#Type(this.registry).toRawType()}>`;
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
exports.Vec = Vec;
|
package/cjs/base/VecFixed.js
CHANGED
|
@@ -11,13 +11,13 @@ const Vec_js_1 = require("./Vec.js");
|
|
|
11
11
|
* This manages codec arrays of a fixed length
|
|
12
12
|
*/
|
|
13
13
|
class VecFixed extends Array_js_1.AbstractArray {
|
|
14
|
-
|
|
14
|
+
#Type;
|
|
15
15
|
constructor(registry, Type, length, value = [], { definition, setDefinition = util_1.identity } = {}) {
|
|
16
16
|
super(registry, length);
|
|
17
|
-
this
|
|
17
|
+
this.#Type = definition || setDefinition((0, index_js_1.typeToConstructor)(registry, Type));
|
|
18
18
|
this.initialU8aLength = ((0, util_1.isU8a)(value)
|
|
19
|
-
? (0, index_js_1.decodeU8aVec)(registry, this, value, 0, this
|
|
20
|
-
: (0, Vec_js_1.decodeVec)(registry, this, value, 0, this
|
|
19
|
+
? (0, index_js_1.decodeU8aVec)(registry, this, value, 0, this.#Type)
|
|
20
|
+
: (0, Vec_js_1.decodeVec)(registry, this, value, 0, this.#Type))[1];
|
|
21
21
|
}
|
|
22
22
|
static with(Type, length) {
|
|
23
23
|
let definition;
|
|
@@ -33,7 +33,7 @@ class VecFixed extends Array_js_1.AbstractArray {
|
|
|
33
33
|
* @description The type for the items
|
|
34
34
|
*/
|
|
35
35
|
get Type() {
|
|
36
|
-
return new this
|
|
36
|
+
return new this.#Type(this.registry).toRawType();
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
39
|
* @description The length of the value when encoded as a Uint8Array
|
package/cjs/extended/BTreeSet.js
CHANGED
|
@@ -61,13 +61,13 @@ class BTreeSet extends Set {
|
|
|
61
61
|
createdAtHash;
|
|
62
62
|
initialU8aLength;
|
|
63
63
|
isStorageFallback;
|
|
64
|
-
|
|
64
|
+
#ValClass;
|
|
65
65
|
constructor(registry, valType, rawValue) {
|
|
66
66
|
const [ValClass, values, decodedLength] = decodeSet(registry, valType, rawValue);
|
|
67
67
|
super((0, index_js_1.sortSet)(values));
|
|
68
68
|
this.registry = registry;
|
|
69
69
|
this.initialU8aLength = decodedLength;
|
|
70
|
-
this
|
|
70
|
+
this.#ValClass = ValClass;
|
|
71
71
|
}
|
|
72
72
|
static with(valType) {
|
|
73
73
|
return class extends BTreeSet {
|
|
@@ -153,7 +153,7 @@ class BTreeSet extends Set {
|
|
|
153
153
|
* @description Returns the base runtime type name for this instance
|
|
154
154
|
*/
|
|
155
155
|
toRawType() {
|
|
156
|
-
return `BTreeSet<${this.registry.getClassName(this
|
|
156
|
+
return `BTreeSet<${this.registry.getClassName(this.#ValClass) || new this.#ValClass(this.registry).toRawType()}>`;
|
|
157
157
|
}
|
|
158
158
|
/**
|
|
159
159
|
* @description Converts the value in a best-fit primitive form
|
package/cjs/extended/BitVec.js
CHANGED
|
@@ -31,29 +31,29 @@ function decodeBitVec(value) {
|
|
|
31
31
|
* and a normal Bytes would be that the length prefix indicates the number of bits encoded, not the bytes
|
|
32
32
|
*/
|
|
33
33
|
class BitVec extends Raw_js_1.Raw {
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
#decodedLength;
|
|
35
|
+
#isMsb;
|
|
36
36
|
// In lieu of having the Msb/Lsb identifiers passed through, we default to assuming
|
|
37
37
|
// we are dealing with Lsb, which is the default (as of writing) BitVec format used
|
|
38
38
|
// in the Polkadot code (this only affects the toHuman displays)
|
|
39
39
|
constructor(registry, value, isMsb = false) {
|
|
40
40
|
const [decodedLength, u8a] = decodeBitVec(value);
|
|
41
41
|
super(registry, u8a);
|
|
42
|
-
this
|
|
43
|
-
this
|
|
42
|
+
this.#decodedLength = decodedLength;
|
|
43
|
+
this.#isMsb = isMsb;
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
46
46
|
* @description The length of the value when encoded as a Uint8Array
|
|
47
47
|
*/
|
|
48
48
|
get encodedLength() {
|
|
49
|
-
return this.length + (0, util_1.compactToU8a)(this
|
|
49
|
+
return this.length + (0, util_1.compactToU8a)(this.#decodedLength).length;
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* @description Returns a breakdown of the hex encoding for this Codec
|
|
53
53
|
*/
|
|
54
54
|
inspect() {
|
|
55
55
|
return {
|
|
56
|
-
outer: [(0, util_1.compactToU8a)(this
|
|
56
|
+
outer: [(0, util_1.compactToU8a)(this.#decodedLength), super.toU8a()]
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
@@ -76,7 +76,7 @@ class BitVec extends Raw_js_1.Raw {
|
|
|
76
76
|
const off = i * 8;
|
|
77
77
|
const v = map[i];
|
|
78
78
|
for (let j = 0; j < 8; j++) {
|
|
79
|
-
result[off + j] = this
|
|
79
|
+
result[off + j] = this.#isMsb
|
|
80
80
|
? v[j]
|
|
81
81
|
: v[7 - j];
|
|
82
82
|
}
|
|
@@ -89,7 +89,7 @@ class BitVec extends Raw_js_1.Raw {
|
|
|
89
89
|
toHuman() {
|
|
90
90
|
return `0b${[...this.toU8a(true)]
|
|
91
91
|
.map((d) => `00000000${d.toString(2)}`.slice(-8))
|
|
92
|
-
.map((s) => this
|
|
92
|
+
.map((s) => this.#isMsb ? s : s.split('').reverse().join(''))
|
|
93
93
|
.join('_')}`;
|
|
94
94
|
}
|
|
95
95
|
/**
|
|
@@ -106,7 +106,7 @@ class BitVec extends Raw_js_1.Raw {
|
|
|
106
106
|
const bitVec = super.toU8a(isBare);
|
|
107
107
|
return isBare
|
|
108
108
|
? bitVec
|
|
109
|
-
: (0, util_1.u8aConcatStrict)([(0, util_1.compactToU8a)(this
|
|
109
|
+
: (0, util_1.u8aConcatStrict)([(0, util_1.compactToU8a)(this.#decodedLength), bitVec]);
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
exports.BitVec = BitVec;
|
package/cjs/extended/Map.js
CHANGED
|
@@ -80,17 +80,17 @@ class CodecMap extends Map {
|
|
|
80
80
|
createdAtHash;
|
|
81
81
|
initialU8aLength;
|
|
82
82
|
isStorageFallback;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
#KeyClass;
|
|
84
|
+
#ValClass;
|
|
85
|
+
#type;
|
|
86
86
|
constructor(registry, keyType, valType, rawValue, type = 'HashMap') {
|
|
87
87
|
const [KeyClass, ValClass, decoded, decodedLength] = decodeMap(registry, keyType, valType, rawValue);
|
|
88
88
|
super(type === 'BTreeMap' ? (0, index_js_1.sortMap)(decoded) : decoded);
|
|
89
89
|
this.registry = registry;
|
|
90
90
|
this.initialU8aLength = decodedLength;
|
|
91
|
-
this
|
|
92
|
-
this
|
|
93
|
-
this
|
|
91
|
+
this.#KeyClass = KeyClass;
|
|
92
|
+
this.#ValClass = ValClass;
|
|
93
|
+
this.#type = type;
|
|
94
94
|
}
|
|
95
95
|
/**
|
|
96
96
|
* @description The length of the value when encoded as a Uint8Array
|
|
@@ -178,7 +178,7 @@ class CodecMap extends Map {
|
|
|
178
178
|
* @description Returns the base runtime type name for this instance
|
|
179
179
|
*/
|
|
180
180
|
toRawType() {
|
|
181
|
-
return `${this
|
|
181
|
+
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()}>`;
|
|
182
182
|
}
|
|
183
183
|
/**
|
|
184
184
|
* @description Returns the string representation of the value
|
package/cjs/extended/Range.js
CHANGED
|
@@ -8,10 +8,10 @@ const Tuple_js_1 = require("../base/Tuple.js");
|
|
|
8
8
|
* Rust `Range<T>` representation
|
|
9
9
|
*/
|
|
10
10
|
class Range extends Tuple_js_1.Tuple {
|
|
11
|
-
|
|
11
|
+
#rangeName;
|
|
12
12
|
constructor(registry, Type, value, { rangeName = 'Range' } = {}) {
|
|
13
13
|
super(registry, [Type, Type], value);
|
|
14
|
-
this
|
|
14
|
+
this.#rangeName = rangeName;
|
|
15
15
|
}
|
|
16
16
|
static with(Type) {
|
|
17
17
|
return class extends Range {
|
|
@@ -36,7 +36,7 @@ class Range extends Tuple_js_1.Tuple {
|
|
|
36
36
|
* @description Returns the base runtime type name for this instance
|
|
37
37
|
*/
|
|
38
38
|
toRawType() {
|
|
39
|
-
return `${this
|
|
39
|
+
return `${this.#rangeName}<${this.start.toRawType()}>`;
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
exports.Range = Range;
|