@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 CHANGED
@@ -7,10 +7,10 @@ export class AbstractBase {
7
7
  createdAtHash;
8
8
  initialU8aLength;
9
9
  isStorageFallback;
10
- __internal__raw;
10
+ #raw;
11
11
  constructor(registry, value, initialU8aLength) {
12
12
  this.initialU8aLength = initialU8aLength;
13
- this.__internal__raw = value;
13
+ this.#raw = value;
14
14
  this.registry = registry;
15
15
  }
16
16
  /**
@@ -29,73 +29,73 @@ export class AbstractBase {
29
29
  * @description returns the inner (wrapped value)
30
30
  */
31
31
  get inner() {
32
- return this.__internal__raw;
32
+ return this.#raw;
33
33
  }
34
34
  /**
35
35
  * @description Checks if the value is an empty value
36
36
  */
37
37
  get isEmpty() {
38
- return this.__internal__raw.isEmpty;
38
+ return this.#raw.isEmpty;
39
39
  }
40
40
  /**
41
41
  * @description Compares the value of the input to see if there is a match
42
42
  */
43
43
  eq(other) {
44
- return this.__internal__raw.eq(other);
44
+ return this.#raw.eq(other);
45
45
  }
46
46
  /**
47
47
  * @description Returns a breakdown of the hex encoding for this Codec
48
48
  */
49
49
  inspect() {
50
- return this.__internal__raw.inspect();
50
+ return this.#raw.inspect();
51
51
  }
52
52
  /**
53
53
  * @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
54
54
  */
55
55
  toHex(isLe) {
56
- return this.__internal__raw.toHex(isLe);
56
+ return this.#raw.toHex(isLe);
57
57
  }
58
58
  /**
59
59
  * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
60
60
  */
61
61
  toHuman(isExtended, disableAscii) {
62
- return this.__internal__raw.toHuman(isExtended, disableAscii);
62
+ return this.#raw.toHuman(isExtended, disableAscii);
63
63
  }
64
64
  /**
65
65
  * @description Converts the Object to JSON, typically used for RPC transfers
66
66
  */
67
67
  toJSON() {
68
- return this.__internal__raw.toJSON();
68
+ return this.#raw.toJSON();
69
69
  }
70
70
  /**
71
71
  * @description Converts the value in a best-fit primitive form
72
72
  */
73
73
  toPrimitive(disableAscii) {
74
- return this.__internal__raw.toPrimitive(disableAscii);
74
+ return this.#raw.toPrimitive(disableAscii);
75
75
  }
76
76
  /**
77
77
  * @description Returns the string representation of the value
78
78
  */
79
79
  toString() {
80
- return this.__internal__raw.toString();
80
+ return this.#raw.toString();
81
81
  }
82
82
  /**
83
83
  * @description Encodes the value as a Uint8Array as per the SCALE specifications
84
84
  * @param isBare true when the value has none of the type-specific prefixes (internal)
85
85
  */
86
86
  toU8a(isBare) {
87
- return this.__internal__raw.toU8a(isBare);
87
+ return this.#raw.toU8a(isBare);
88
88
  }
89
89
  /**
90
90
  * @description Returns the inner wrapped value (equivalent to valueOf)
91
91
  */
92
92
  unwrap() {
93
- return this.__internal__raw;
93
+ return this.#raw;
94
94
  }
95
95
  /**
96
96
  * @description Returns the inner wrapped value
97
97
  */
98
98
  valueOf() {
99
- return this.__internal__raw;
99
+ return this.#raw;
100
100
  }
101
101
  }
package/abstract/Int.js CHANGED
@@ -64,7 +64,7 @@ export class AbstractInt extends BN {
64
64
  createdAtHash;
65
65
  initialU8aLength;
66
66
  isStorageFallback;
67
- __internal__bitLength;
67
+ #bitLength;
68
68
  constructor(registry, value = 0, bitLength = DEFAULT_UINT_BITS, isSigned = false) {
69
69
  // Construct via a string/number, which will be passed in the BN constructor.
70
70
  // It would be ideal to actually return a BN, but there is an issue:
@@ -77,9 +77,9 @@ export class AbstractInt extends BN {
77
77
  : u8aToBn(value.subarray(0, bitLength / 8), { isLe: true, isNegative: isSigned }).toString()
78
78
  : decodeAbstractInt(value, isSigned));
79
79
  this.registry = registry;
80
- this.__internal__bitLength = bitLength;
81
- this.encodedLength = this.__internal__bitLength / 8;
82
- this.initialU8aLength = this.__internal__bitLength / 8;
80
+ this.#bitLength = bitLength;
81
+ this.encodedLength = this.#bitLength / 8;
82
+ this.initialU8aLength = this.#bitLength / 8;
83
83
  this.isUnsigned = !isSigned;
84
84
  const isNegative = this.isNeg();
85
85
  const maxBits = bitLength - (isSigned && !isNegative ? 1 : 0);
@@ -106,7 +106,7 @@ export class AbstractInt extends BN {
106
106
  * @description Returns the number of bits in the value
107
107
  */
108
108
  bitLength() {
109
- return this.__internal__bitLength;
109
+ return this.#bitLength;
110
110
  }
111
111
  /**
112
112
  * @description Compares the value of the input to see if there is a match
@@ -132,7 +132,7 @@ export class AbstractInt extends BN {
132
132
  */
133
133
  isMax() {
134
134
  const u8a = this.toU8a().filter((b) => b === 0xff);
135
- return u8a.length === (this.__internal__bitLength / 8);
135
+ return u8a.length === (this.#bitLength / 8);
136
136
  }
137
137
  /**
138
138
  * @description Returns a BigInt representation of the number
@@ -181,8 +181,8 @@ export class AbstractInt extends BN {
181
181
  // FIXME this return type should by string | number, however BN returns string
182
182
  // Options here are
183
183
  // - super.bitLength() - the actual used bits, use hex when close to MAX_SAFE_INTEGER
184
- // - this.__internal__bitLength - the max used bits, use hex when larger than native Rust type
185
- return onlyHex || (this.__internal__bitLength > 128) || (super.bitLength() > MAX_NUMBER_BITS)
184
+ // - this.#bitLength - the max used bits, use hex when larger than native Rust type
185
+ return onlyHex || (this.#bitLength > 128) || (super.bitLength() > MAX_NUMBER_BITS)
186
186
  ? this.toHex()
187
187
  : this.toNumber();
188
188
  }
package/base/Compact.js CHANGED
@@ -31,14 +31,14 @@ export class Compact {
31
31
  createdAtHash;
32
32
  initialU8aLength;
33
33
  isStorageFallback;
34
- __internal__Type;
35
- __internal__raw;
34
+ #Type;
35
+ #raw;
36
36
  constructor(registry, Type, value = 0, { definition, setDefinition = identity } = {}) {
37
37
  this.registry = registry;
38
- this.__internal__Type = definition || setDefinition(typeToConstructor(registry, Type));
39
- const [raw, decodedLength] = decodeCompact(registry, this.__internal__Type, value);
38
+ this.#Type = definition || setDefinition(typeToConstructor(registry, Type));
39
+ const [raw, decodedLength] = decodeCompact(registry, this.#Type, value);
40
40
  this.initialU8aLength = decodedLength;
41
- this.__internal__raw = raw;
41
+ this.#raw = raw;
42
42
  }
43
43
  static with(Type) {
44
44
  let definition;
@@ -66,20 +66,20 @@ export class Compact {
66
66
  * @description Checks if the value is an empty value
67
67
  */
68
68
  get isEmpty() {
69
- return this.__internal__raw.isEmpty;
69
+ return this.#raw.isEmpty;
70
70
  }
71
71
  /**
72
72
  * @description Returns the number of bits in the value
73
73
  */
74
74
  bitLength() {
75
- return this.__internal__raw.bitLength();
75
+ return this.#raw.bitLength();
76
76
  }
77
77
  /**
78
78
  * @description Compares the value of the input to see if there is a match
79
79
  */
80
80
  eq(other) {
81
- return this.__internal__raw.eq(other instanceof Compact
82
- ? other.__internal__raw
81
+ return this.#raw.eq(other instanceof Compact
82
+ ? other.#raw
83
83
  : other);
84
84
  }
85
85
  /**
@@ -94,66 +94,66 @@ export class Compact {
94
94
  * @description Returns a BigInt representation of the number
95
95
  */
96
96
  toBigInt() {
97
- return this.__internal__raw.toBigInt();
97
+ return this.#raw.toBigInt();
98
98
  }
99
99
  /**
100
100
  * @description Returns the BN representation of the number
101
101
  */
102
102
  toBn() {
103
- return this.__internal__raw.toBn();
103
+ return this.#raw.toBn();
104
104
  }
105
105
  /**
106
106
  * @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
107
107
  */
108
108
  toHex(isLe) {
109
- return this.__internal__raw.toHex(isLe);
109
+ return this.#raw.toHex(isLe);
110
110
  }
111
111
  /**
112
112
  * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
113
113
  */
114
114
  toHuman(isExtended, disableAscii) {
115
- return this.__internal__raw.toHuman(isExtended, disableAscii);
115
+ return this.#raw.toHuman(isExtended, disableAscii);
116
116
  }
117
117
  /**
118
118
  * @description Converts the Object to JSON, typically used for RPC transfers
119
119
  */
120
120
  toJSON() {
121
- return this.__internal__raw.toJSON();
121
+ return this.#raw.toJSON();
122
122
  }
123
123
  /**
124
124
  * @description Returns the number representation for the value
125
125
  */
126
126
  toNumber() {
127
- return this.__internal__raw.toNumber();
127
+ return this.#raw.toNumber();
128
128
  }
129
129
  /**
130
130
  * @description Converts the value in a best-fit primitive form
131
131
  */
132
132
  toPrimitive(disableAscii) {
133
- return this.__internal__raw.toPrimitive(disableAscii);
133
+ return this.#raw.toPrimitive(disableAscii);
134
134
  }
135
135
  /**
136
136
  * @description Returns the base runtime type name for this instance
137
137
  */
138
138
  toRawType() {
139
- return `Compact<${this.registry.getClassName(this.__internal__Type) || this.__internal__raw.toRawType()}>`;
139
+ return `Compact<${this.registry.getClassName(this.#Type) || this.#raw.toRawType()}>`;
140
140
  }
141
141
  /**
142
142
  * @description Returns the string representation of the value
143
143
  */
144
144
  toString() {
145
- return this.__internal__raw.toString();
145
+ return this.#raw.toString();
146
146
  }
147
147
  /**
148
148
  * @description Encodes the value as a Uint8Array as per the SCALE specifications
149
149
  */
150
150
  toU8a(_isBare) {
151
- return compactToU8a(this.__internal__raw.toBn());
151
+ return compactToU8a(this.#raw.toBn());
152
152
  }
153
153
  /**
154
154
  * @description Returns the embedded [[UInt]] or [[Moment]] value
155
155
  */
156
156
  unwrap() {
157
- return this.__internal__raw;
157
+ return this.#raw;
158
158
  }
159
159
  }
@@ -7,11 +7,11 @@ export class DoNotConstruct {
7
7
  registry;
8
8
  createdAtHash;
9
9
  isStorageFallback;
10
- __internal__neverError;
10
+ #neverError;
11
11
  constructor(registry, typeName = 'DoNotConstruct') {
12
12
  this.registry = registry;
13
- this.__internal__neverError = new Error(`DoNotConstruct: Cannot construct unknown type ${typeName}`);
14
- throw this.__internal__neverError;
13
+ this.#neverError = new Error(`DoNotConstruct: Cannot construct unknown type ${typeName}`);
14
+ throw this.#neverError;
15
15
  }
16
16
  static with(typeName) {
17
17
  return class extends DoNotConstruct {
@@ -24,72 +24,72 @@ export class DoNotConstruct {
24
24
  * @description The length of the value when encoded as a Uint8Array
25
25
  */
26
26
  get encodedLength() {
27
- throw this.__internal__neverError;
27
+ throw this.#neverError;
28
28
  }
29
29
  /**
30
30
  * @description returns a hash of the contents
31
31
  */
32
32
  get hash() {
33
- throw this.__internal__neverError;
33
+ throw this.#neverError;
34
34
  }
35
35
  /**
36
36
  * @description Checks if the value is an empty value (always true)
37
37
  */
38
38
  get isEmpty() {
39
- throw this.__internal__neverError;
39
+ throw this.#neverError;
40
40
  }
41
41
  /**
42
42
  * @description Unimplemented
43
43
  */
44
44
  eq() {
45
- throw this.__internal__neverError;
45
+ throw this.#neverError;
46
46
  }
47
47
  /**
48
48
  * @description Unimplemented
49
49
  */
50
50
  inspect() {
51
- throw this.__internal__neverError;
51
+ throw this.#neverError;
52
52
  }
53
53
  /**
54
54
  * @description Unimplemented
55
55
  */
56
56
  toHex() {
57
- throw this.__internal__neverError;
57
+ throw this.#neverError;
58
58
  }
59
59
  /**
60
60
  * @description Unimplemented
61
61
  */
62
62
  toHuman() {
63
- throw this.__internal__neverError;
63
+ throw this.#neverError;
64
64
  }
65
65
  /**
66
66
  * @description Unimplemented
67
67
  */
68
68
  toJSON() {
69
- throw this.__internal__neverError;
69
+ throw this.#neverError;
70
70
  }
71
71
  /**
72
72
  * @description Unimplemented
73
73
  */
74
74
  toPrimitive() {
75
- throw this.__internal__neverError;
75
+ throw this.#neverError;
76
76
  }
77
77
  /**
78
78
  * @description Unimplemented
79
79
  */
80
80
  toRawType() {
81
- throw this.__internal__neverError;
81
+ throw this.#neverError;
82
82
  }
83
83
  /**
84
84
  * @description Unimplemented
85
85
  */
86
86
  toString() {
87
- throw this.__internal__neverError;
87
+ throw this.#neverError;
88
88
  }
89
89
  /**
90
90
  * @description Unimplemented
91
91
  */
92
92
  toU8a() {
93
- throw this.__internal__neverError;
93
+ throw this.#neverError;
94
94
  }
95
95
  }
package/base/Enum.js CHANGED
@@ -127,12 +127,12 @@ export class Enum {
127
127
  createdAtHash;
128
128
  initialU8aLength;
129
129
  isStorageFallback;
130
- __internal__def;
131
- __internal__entryIndex;
132
- __internal__indexes;
133
- __internal__isBasic;
134
- __internal__isIndexed;
135
- __internal__raw;
130
+ #def;
131
+ #entryIndex;
132
+ #indexes;
133
+ #isBasic;
134
+ #isIndexed;
135
+ #raw;
136
136
  constructor(registry, Types, value, index, { definition, setDefinition = identity } = {}) {
137
137
  const { def, isBasic, isIndexed } = definition || setDefinition(extractDef(registry, Types));
138
138
  // shortcut isU8a as used in SCALE decoding
@@ -140,14 +140,14 @@ export class Enum {
140
140
  ? createFromU8a(registry, def, value[0], value.subarray(1))
141
141
  : decodeEnum(registry, def, value, index);
142
142
  this.registry = registry;
143
- this.__internal__def = def;
144
- this.__internal__isBasic = isBasic;
145
- this.__internal__isIndexed = isIndexed;
146
- this.__internal__indexes = Object.values(def).map(({ index }) => index);
147
- this.__internal__entryIndex = this.__internal__indexes.indexOf(decoded.index);
148
- this.__internal__raw = decoded.value;
149
- if (this.__internal__raw.initialU8aLength) {
150
- this.initialU8aLength = 1 + this.__internal__raw.initialU8aLength;
143
+ this.#def = def;
144
+ this.#isBasic = isBasic;
145
+ this.#isIndexed = isIndexed;
146
+ this.#indexes = Object.values(def).map(({ index }) => index);
147
+ this.#entryIndex = this.#indexes.indexOf(decoded.index);
148
+ this.#raw = decoded.value;
149
+ if (this.#raw.initialU8aLength) {
150
+ this.initialU8aLength = 1 + this.#raw.initialU8aLength;
151
151
  }
152
152
  }
153
153
  static with(Types) {
@@ -184,7 +184,7 @@ export class Enum {
184
184
  * @description The length of the value when encoded as a Uint8Array
185
185
  */
186
186
  get encodedLength() {
187
- return 1 + this.__internal__raw.encodedLength;
187
+ return 1 + this.#raw.encodedLength;
188
188
  }
189
189
  /**
190
190
  * @description returns a hash of the contents
@@ -196,55 +196,55 @@ export class Enum {
196
196
  * @description The index of the enum value
197
197
  */
198
198
  get index() {
199
- return this.__internal__indexes[this.__internal__entryIndex];
199
+ return this.#indexes[this.#entryIndex];
200
200
  }
201
201
  /**
202
202
  * @description The value of the enum
203
203
  */
204
204
  get inner() {
205
- return this.__internal__raw;
205
+ return this.#raw;
206
206
  }
207
207
  /**
208
208
  * @description true if this is a basic enum (no values)
209
209
  */
210
210
  get isBasic() {
211
- return this.__internal__isBasic;
211
+ return this.#isBasic;
212
212
  }
213
213
  /**
214
214
  * @description Checks if the value is an empty value
215
215
  */
216
216
  get isEmpty() {
217
- return this.__internal__raw.isEmpty;
217
+ return this.#raw.isEmpty;
218
218
  }
219
219
  /**
220
220
  * @description Checks if the Enum points to a [[Null]] type
221
221
  */
222
222
  get isNone() {
223
- return this.__internal__raw instanceof Null;
223
+ return this.#raw instanceof Null;
224
224
  }
225
225
  /**
226
226
  * @description The available keys for this enum
227
227
  */
228
228
  get defIndexes() {
229
- return this.__internal__indexes;
229
+ return this.#indexes;
230
230
  }
231
231
  /**
232
232
  * @description The available keys for this enum
233
233
  */
234
234
  get defKeys() {
235
- return Object.keys(this.__internal__def);
235
+ return Object.keys(this.#def);
236
236
  }
237
237
  /**
238
238
  * @description The name of the type this enum value represents
239
239
  */
240
240
  get type() {
241
- return this.defKeys[this.__internal__entryIndex];
241
+ return this.defKeys[this.#entryIndex];
242
242
  }
243
243
  /**
244
244
  * @description The value of the enum
245
245
  */
246
246
  get value() {
247
- return this.__internal__raw;
247
+ return this.#raw;
248
248
  }
249
249
  /**
250
250
  * @description Compares the value of the input to see if there is a match
@@ -257,7 +257,7 @@ export class Enum {
257
257
  else if (isNumber(other)) {
258
258
  return this.toNumber() === other;
259
259
  }
260
- else if (this.__internal__isBasic && isString(other)) {
260
+ else if (this.#isBasic && isString(other)) {
261
261
  return this.type === other;
262
262
  }
263
263
  else if (isHex(other)) {
@@ -276,10 +276,10 @@ export class Enum {
276
276
  * @description Returns a breakdown of the hex encoding for this Codec
277
277
  */
278
278
  inspect() {
279
- if (this.__internal__isBasic) {
279
+ if (this.#isBasic) {
280
280
  return { outer: [new Uint8Array([this.index])] };
281
281
  }
282
- const { inner, outer = [] } = this.__internal__raw.inspect();
282
+ const { inner, outer = [] } = this.#raw.inspect();
283
283
  return {
284
284
  inner,
285
285
  outer: [new Uint8Array([this.index]), ...outer]
@@ -295,17 +295,17 @@ export class Enum {
295
295
  * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
296
296
  */
297
297
  toHuman(isExtended, disableAscii) {
298
- return this.__internal__isBasic || this.isNone
298
+ return this.#isBasic || this.isNone
299
299
  ? this.type
300
- : { [this.type]: this.__internal__raw.toHuman(isExtended, disableAscii) };
300
+ : { [this.type]: this.#raw.toHuman(isExtended, disableAscii) };
301
301
  }
302
302
  /**
303
303
  * @description Converts the Object to JSON, typically used for RPC transfers
304
304
  */
305
305
  toJSON() {
306
- return this.__internal__isBasic
306
+ return this.#isBasic
307
307
  ? this.type
308
- : { [stringCamelCase(this.type)]: this.__internal__raw.toJSON() };
308
+ : { [stringCamelCase(this.type)]: this.#raw.toJSON() };
309
309
  }
310
310
  /**
311
311
  * @description Returns the number representation for the value
@@ -317,23 +317,23 @@ export class Enum {
317
317
  * @description Converts the value in a best-fit primitive form
318
318
  */
319
319
  toPrimitive(disableAscii) {
320
- return this.__internal__isBasic
320
+ return this.#isBasic
321
321
  ? this.type
322
- : { [stringCamelCase(this.type)]: this.__internal__raw.toPrimitive(disableAscii) };
322
+ : { [stringCamelCase(this.type)]: this.#raw.toPrimitive(disableAscii) };
323
323
  }
324
324
  /**
325
325
  * @description Returns a raw struct representation of the enum types
326
326
  */
327
327
  _toRawStruct() {
328
- if (this.__internal__isBasic) {
329
- return this.__internal__isIndexed
328
+ if (this.#isBasic) {
329
+ return this.#isIndexed
330
330
  ? this.defKeys.reduce((out, key, index) => {
331
- out[key] = this.__internal__indexes[index];
331
+ out[key] = this.#indexes[index];
332
332
  return out;
333
333
  }, {})
334
334
  : this.defKeys;
335
335
  }
336
- const entries = Object.entries(this.__internal__def);
336
+ const entries = Object.entries(this.#def);
337
337
  return typesToMap(this.registry, entries.reduce((out, [key, { Type }], i) => {
338
338
  out[0][i] = Type;
339
339
  out[1][i] = key;
@@ -360,10 +360,10 @@ export class Enum {
360
360
  */
361
361
  toU8a(isBare) {
362
362
  return isBare
363
- ? this.__internal__raw.toU8a(isBare)
363
+ ? this.#raw.toU8a(isBare)
364
364
  : u8aConcatStrict([
365
365
  new Uint8Array([this.index]),
366
- this.__internal__raw.toU8a(isBare)
366
+ this.#raw.toU8a(isBare)
367
367
  ]);
368
368
  }
369
369
  }