@polkadot/types-codec 7.4.2-9 → 7.5.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.
@@ -14,10 +14,6 @@ export class AbstractArray extends Array {
14
14
  constructor(registry, values, initialU8aLength) {
15
15
  super(values.length); // explicitly set the values here - this removes the need for any extra allocations
16
16
 
17
- this.registry = void 0;
18
- this.createdAtHash = void 0;
19
- this.initialU8aLength = void 0;
20
-
21
17
  for (let i = 0; i < values.length; i++) {
22
18
  this[i] = values[i];
23
19
  }
@@ -1,5 +1,3 @@
1
- import _classPrivateFieldLooseBase from "@babel/runtime/helpers/esm/classPrivateFieldLooseBase";
2
- import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateFieldLooseKey";
3
1
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
4
2
  // SPDX-License-Identifier: Apache-2.0
5
3
  import { assert, BN, BN_BILLION, BN_HUNDRED, BN_MILLION, BN_QUINTILL, BN_ZERO, bnToBn, bnToHex, bnToU8a, formatBalance, formatNumber, hexToBn, isBn, isHex, isNumber, isString, isU8a, u8aToBn } from '@polkadot/util';
@@ -44,11 +42,10 @@ function decodeAbstractInt(value, bitLength, isNegative) {
44
42
  */
45
43
 
46
44
 
47
- var _bitLength = /*#__PURE__*/_classPrivateFieldLooseKey("bitLength");
48
-
49
- var _isSigned = /*#__PURE__*/_classPrivateFieldLooseKey("isSigned");
50
-
51
45
  export class AbstractInt extends BN {
46
+ #bitLength;
47
+ #isSigned;
48
+
52
49
  constructor(registry, value = 0, bitLength = DEFAULT_UINT_BITS, isSigned = false) {
53
50
  // Construct via a string, which will be passed in the BN constructor.
54
51
  // It would be ideal to actually return a BN, but there is an issue:
@@ -58,21 +55,10 @@ export class AbstractInt extends BN {
58
55
  isLe: true,
59
56
  isNegative: isSigned
60
57
  }).toString() : decodeAbstractInt(value, bitLength, isSigned));
61
- this.registry = void 0;
62
- this.createdAtHash = void 0;
63
- this.encodedLength = void 0;
64
- Object.defineProperty(this, _bitLength, {
65
- writable: true,
66
- value: void 0
67
- });
68
- Object.defineProperty(this, _isSigned, {
69
- writable: true,
70
- value: void 0
71
- });
72
58
  this.registry = registry;
73
- _classPrivateFieldLooseBase(this, _bitLength)[_bitLength] = bitLength;
74
- this.encodedLength = _classPrivateFieldLooseBase(this, _bitLength)[_bitLength] / 8;
75
- _classPrivateFieldLooseBase(this, _isSigned)[_isSigned] = isSigned;
59
+ this.#bitLength = bitLength;
60
+ this.encodedLength = this.#bitLength / 8;
61
+ this.#isSigned = isSigned;
76
62
  const isPositive = this.gte(BN_ZERO);
77
63
  const maxBits = bitLength - (isSigned && isPositive ? 1 : 0);
78
64
  assert(isSigned || isPositive, () => `${this.toRawType()}: Negative number passed to unsigned type`);
@@ -100,7 +86,7 @@ export class AbstractInt extends BN {
100
86
 
101
87
 
102
88
  get isUnsigned() {
103
- return !_classPrivateFieldLooseBase(this, _isSigned)[_isSigned];
89
+ return !this.#isSigned;
104
90
  }
105
91
  /**
106
92
  * @description Returns the number of bits in the value
@@ -108,7 +94,7 @@ export class AbstractInt extends BN {
108
94
 
109
95
 
110
96
  bitLength() {
111
- return _classPrivateFieldLooseBase(this, _bitLength)[_bitLength];
97
+ return this.#bitLength;
112
98
  }
113
99
  /**
114
100
  * @description Compares the value of the input to see if there is a match
@@ -121,7 +107,7 @@ export class AbstractInt extends BN {
121
107
  // number and BN inputs (no `.eqn` needed) - numbers will be converted
122
108
  return super.eq(isHex(other) ? hexToBn(other.toString(), {
123
109
  isLe: false,
124
- isNegative: _classPrivateFieldLooseBase(this, _isSigned)[_isSigned]
110
+ isNegative: this.#isSigned
125
111
  }) : bnToBn(other));
126
112
  }
127
113
  /**
@@ -131,7 +117,7 @@ export class AbstractInt extends BN {
131
117
 
132
118
  isMax() {
133
119
  const u8a = this.toU8a().filter(b => b === 0xff);
134
- return u8a.length === _classPrivateFieldLooseBase(this, _bitLength)[_bitLength] / 8;
120
+ return u8a.length === this.#bitLength / 8;
135
121
  }
136
122
  /**
137
123
  * @description Returns a BigInt representation of the number
package/base/Base.js CHANGED
@@ -1,10 +1,3 @@
1
- import _classPrivateFieldLooseBase from "@babel/runtime/helpers/esm/classPrivateFieldLooseBase";
2
- import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateFieldLooseKey";
3
-
4
- var _registry = /*#__PURE__*/_classPrivateFieldLooseKey("registry");
5
-
6
- var _raw = /*#__PURE__*/_classPrivateFieldLooseKey("raw");
7
-
8
1
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
9
2
  // SPDX-License-Identifier: Apache-2.0
10
3
 
@@ -13,19 +6,12 @@ var _raw = /*#__PURE__*/_classPrivateFieldLooseKey("raw");
13
6
  * @description A type extends the Base class, when it holds a value
14
7
  */
15
8
  export class Base {
9
+ #registry;
10
+ #raw;
11
+
16
12
  constructor(registry, value, initialU8aLength) {
17
- Object.defineProperty(this, _registry, {
18
- writable: true,
19
- value: void 0
20
- });
21
- this.createdAtHash = void 0;
22
- this.initialU8aLength = void 0;
23
- Object.defineProperty(this, _raw, {
24
- writable: true,
25
- value: void 0
26
- });
27
- _classPrivateFieldLooseBase(this, _registry)[_registry] = registry;
28
- _classPrivateFieldLooseBase(this, _raw)[_raw] = value;
13
+ this.#registry = registry;
14
+ this.#raw = value;
29
15
  this.initialU8aLength = initialU8aLength;
30
16
  }
31
17
  /**
@@ -46,7 +32,7 @@ export class Base {
46
32
  }
47
33
 
48
34
  get inner() {
49
- return _classPrivateFieldLooseBase(this, _raw)[_raw];
35
+ return this.#raw;
50
36
  }
51
37
  /**
52
38
  * @description Checks if the value is an empty value
@@ -54,11 +40,11 @@ export class Base {
54
40
 
55
41
 
56
42
  get isEmpty() {
57
- return _classPrivateFieldLooseBase(this, _raw)[_raw].isEmpty;
43
+ return this.#raw.isEmpty;
58
44
  }
59
45
 
60
46
  get registry() {
61
- return _classPrivateFieldLooseBase(this, _registry)[_registry];
47
+ return this.#registry;
62
48
  }
63
49
  /**
64
50
  * @description Compares the value of the input to see if there is a match
@@ -66,7 +52,7 @@ export class Base {
66
52
 
67
53
 
68
54
  eq(other) {
69
- return _classPrivateFieldLooseBase(this, _raw)[_raw].eq(other);
55
+ return this.#raw.eq(other);
70
56
  }
71
57
  /**
72
58
  * @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
@@ -74,7 +60,7 @@ export class Base {
74
60
 
75
61
 
76
62
  toHex(isLe) {
77
- return _classPrivateFieldLooseBase(this, _raw)[_raw].toHex(isLe);
63
+ return this.#raw.toHex(isLe);
78
64
  }
79
65
  /**
80
66
  * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
@@ -82,7 +68,7 @@ export class Base {
82
68
 
83
69
 
84
70
  toHuman(isExtended) {
85
- return _classPrivateFieldLooseBase(this, _raw)[_raw].toHuman(isExtended);
71
+ return this.#raw.toHuman(isExtended);
86
72
  }
87
73
  /**
88
74
  * @description Converts the Object to JSON, typically used for RPC transfers
@@ -90,7 +76,7 @@ export class Base {
90
76
 
91
77
 
92
78
  toJSON() {
93
- return _classPrivateFieldLooseBase(this, _raw)[_raw].toJSON();
79
+ return this.#raw.toJSON();
94
80
  }
95
81
  /**
96
82
  * @description Returns the string representation of the value
@@ -98,7 +84,7 @@ export class Base {
98
84
 
99
85
 
100
86
  toString() {
101
- return _classPrivateFieldLooseBase(this, _raw)[_raw].toString();
87
+ return this.#raw.toString();
102
88
  }
103
89
  /**
104
90
  * @description Encodes the value as a Uint8Array as per the SCALE specifications
@@ -107,7 +93,7 @@ export class Base {
107
93
 
108
94
 
109
95
  toU8a(isBare) {
110
- return _classPrivateFieldLooseBase(this, _raw)[_raw].toU8a(isBare);
96
+ return this.#raw.toU8a(isBare);
111
97
  }
112
98
  /**
113
99
  * @description Returns the base runtime type name for this instance
@@ -119,7 +105,7 @@ export class Base {
119
105
  }
120
106
 
121
107
  unwrap() {
122
- return _classPrivateFieldLooseBase(this, _raw)[_raw];
108
+ return this.#raw;
123
109
  }
124
110
 
125
111
  }
package/base/Compact.js CHANGED
@@ -1,5 +1,3 @@
1
- import _classPrivateFieldLooseBase from "@babel/runtime/helpers/esm/classPrivateFieldLooseBase";
2
- import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateFieldLooseKey";
3
1
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
4
2
  // SPDX-License-Identifier: Apache-2.0
5
3
  import { compactFromU8a, compactToU8a, isBigInt, isBn, isNumber, isString } from '@polkadot/util';
@@ -13,28 +11,16 @@ import { typeToConstructor } from "../utils/index.js";
13
11
  * a number and making the compact representation thereof
14
12
  */
15
13
 
16
- var _Type = /*#__PURE__*/_classPrivateFieldLooseKey("Type");
17
-
18
- var _raw = /*#__PURE__*/_classPrivateFieldLooseKey("raw");
19
-
20
14
  export class Compact {
15
+ #Type;
16
+ #raw;
17
+
21
18
  constructor(registry, Type, value = 0) {
22
- this.registry = void 0;
23
- this.createdAtHash = void 0;
24
- this.initialU8aLength = void 0;
25
- Object.defineProperty(this, _Type, {
26
- writable: true,
27
- value: void 0
28
- });
29
- Object.defineProperty(this, _raw, {
30
- writable: true,
31
- value: void 0
32
- });
33
19
  this.registry = registry;
34
- _classPrivateFieldLooseBase(this, _Type)[_Type] = typeToConstructor(registry, Type);
35
- const [raw, decodedLength] = Compact.decodeCompact(registry, _classPrivateFieldLooseBase(this, _Type)[_Type], value);
20
+ this.#Type = typeToConstructor(registry, Type);
21
+ const [raw, decodedLength] = Compact.decodeCompact(registry, this.#Type, value);
36
22
  this.initialU8aLength = decodedLength;
37
- _classPrivateFieldLooseBase(this, _raw)[_raw] = raw;
23
+ this.#raw = raw;
38
24
  }
39
25
 
40
26
  static with(Type) {
@@ -50,7 +36,7 @@ export class Compact {
50
36
 
51
37
  static decodeCompact(registry, Type, value) {
52
38
  if (value instanceof Compact) {
53
- return [new Type(registry, _classPrivateFieldLooseBase(value, _raw)[_raw]), 0];
39
+ return [new Type(registry, value.#raw), 0];
54
40
  } else if (value instanceof Type) {
55
41
  return [value, 0];
56
42
  } else if (isString(value) || isNumber(value) || isBn(value) || isBigInt(value)) {
@@ -82,7 +68,7 @@ export class Compact {
82
68
 
83
69
 
84
70
  get isEmpty() {
85
- return _classPrivateFieldLooseBase(this, _raw)[_raw].isEmpty;
71
+ return this.#raw.isEmpty;
86
72
  }
87
73
  /**
88
74
  * @description Returns the number of bits in the value
@@ -90,7 +76,7 @@ export class Compact {
90
76
 
91
77
 
92
78
  bitLength() {
93
- return _classPrivateFieldLooseBase(this, _raw)[_raw].bitLength();
79
+ return this.#raw.bitLength();
94
80
  }
95
81
  /**
96
82
  * @description Compares the value of the input to see if there is a match
@@ -98,7 +84,7 @@ export class Compact {
98
84
 
99
85
 
100
86
  eq(other) {
101
- return _classPrivateFieldLooseBase(this, _raw)[_raw].eq(other instanceof Compact ? _classPrivateFieldLooseBase(other, _raw)[_raw] : other);
87
+ return this.#raw.eq(other instanceof Compact ? other.#raw : other);
102
88
  }
103
89
  /**
104
90
  * @description Returns a BigInt representation of the number
@@ -106,7 +92,7 @@ export class Compact {
106
92
 
107
93
 
108
94
  toBigInt() {
109
- return _classPrivateFieldLooseBase(this, _raw)[_raw].toBigInt();
95
+ return this.#raw.toBigInt();
110
96
  }
111
97
  /**
112
98
  * @description Returns the BN representation of the number
@@ -114,7 +100,7 @@ export class Compact {
114
100
 
115
101
 
116
102
  toBn() {
117
- return _classPrivateFieldLooseBase(this, _raw)[_raw].toBn();
103
+ return this.#raw.toBn();
118
104
  }
119
105
  /**
120
106
  * @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
@@ -122,7 +108,7 @@ export class Compact {
122
108
 
123
109
 
124
110
  toHex(isLe) {
125
- return _classPrivateFieldLooseBase(this, _raw)[_raw].toHex(isLe);
111
+ return this.#raw.toHex(isLe);
126
112
  }
127
113
  /**
128
114
  * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
@@ -130,7 +116,7 @@ export class Compact {
130
116
 
131
117
 
132
118
  toHuman(isExtended) {
133
- return _classPrivateFieldLooseBase(this, _raw)[_raw].toHuman(isExtended);
119
+ return this.#raw.toHuman(isExtended);
134
120
  }
135
121
  /**
136
122
  * @description Converts the Object to JSON, typically used for RPC transfers
@@ -138,7 +124,7 @@ export class Compact {
138
124
 
139
125
 
140
126
  toJSON() {
141
- return _classPrivateFieldLooseBase(this, _raw)[_raw].toJSON();
127
+ return this.#raw.toJSON();
142
128
  }
143
129
  /**
144
130
  * @description Returns the number representation for the value
@@ -146,7 +132,7 @@ export class Compact {
146
132
 
147
133
 
148
134
  toNumber() {
149
- return _classPrivateFieldLooseBase(this, _raw)[_raw].toNumber();
135
+ return this.#raw.toNumber();
150
136
  }
151
137
  /**
152
138
  * @description Returns the base runtime type name for this instance
@@ -154,7 +140,7 @@ export class Compact {
154
140
 
155
141
 
156
142
  toRawType() {
157
- return `Compact<${this.registry.getClassName(_classPrivateFieldLooseBase(this, _Type)[_Type]) || _classPrivateFieldLooseBase(this, _raw)[_raw].toRawType()}>`;
143
+ return `Compact<${this.registry.getClassName(this.#Type) || this.#raw.toRawType()}>`;
158
144
  }
159
145
  /**
160
146
  * @description Returns the string representation of the value
@@ -162,7 +148,7 @@ export class Compact {
162
148
 
163
149
 
164
150
  toString() {
165
- return _classPrivateFieldLooseBase(this, _raw)[_raw].toString();
151
+ return this.#raw.toString();
166
152
  }
167
153
  /**
168
154
  * @description Encodes the value as a Uint8Array as per the SCALE specifications
@@ -172,7 +158,7 @@ export class Compact {
172
158
 
173
159
 
174
160
  toU8a(isBare) {
175
- return compactToU8a(_classPrivateFieldLooseBase(this, _raw)[_raw].toBn());
161
+ return compactToU8a(this.#raw.toBn());
176
162
  }
177
163
  /**
178
164
  * @description Returns the embedded [[UInt]] or [[Moment]] value
@@ -180,7 +166,7 @@ export class Compact {
180
166
 
181
167
 
182
168
  unwrap() {
183
- return _classPrivateFieldLooseBase(this, _raw)[_raw];
169
+ return this.#raw;
184
170
  }
185
171
 
186
172
  }
@@ -1,8 +1,3 @@
1
- import _classPrivateFieldLooseBase from "@babel/runtime/helpers/esm/classPrivateFieldLooseBase";
2
- import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateFieldLooseKey";
3
-
4
- var _neverError = /*#__PURE__*/_classPrivateFieldLooseKey("neverError");
5
-
6
1
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
7
2
  // SPDX-License-Identifier: Apache-2.0
8
3
 
@@ -12,16 +7,12 @@ var _neverError = /*#__PURE__*/_classPrivateFieldLooseKey("neverError");
12
7
  * An unknown type that fails on construction with the type info
13
8
  */
14
9
  export class DoNotConstruct {
10
+ #neverError;
11
+
15
12
  constructor(registry, typeName = 'DoNotConstruct') {
16
- this.registry = void 0;
17
- this.createdAtHash = void 0;
18
- Object.defineProperty(this, _neverError, {
19
- writable: true,
20
- value: void 0
21
- });
22
13
  this.registry = registry;
23
- _classPrivateFieldLooseBase(this, _neverError)[_neverError] = new Error(`DoNotConstruct: Cannot construct unknown type ${typeName}`);
24
- throw _classPrivateFieldLooseBase(this, _neverError)[_neverError];
14
+ this.#neverError = new Error(`DoNotConstruct: Cannot construct unknown type ${typeName}`);
15
+ throw this.#neverError;
25
16
  }
26
17
 
27
18
  static with(typeName) {
@@ -38,7 +29,7 @@ export class DoNotConstruct {
38
29
 
39
30
 
40
31
  get encodedLength() {
41
- throw _classPrivateFieldLooseBase(this, _neverError)[_neverError];
32
+ throw this.#neverError;
42
33
  }
43
34
  /**
44
35
  * @description returns a hash of the contents
@@ -46,7 +37,7 @@ export class DoNotConstruct {
46
37
 
47
38
 
48
39
  get hash() {
49
- throw _classPrivateFieldLooseBase(this, _neverError)[_neverError];
40
+ throw this.#neverError;
50
41
  }
51
42
  /**
52
43
  * @description Checks if the value is an empty value (always true)
@@ -54,35 +45,35 @@ export class DoNotConstruct {
54
45
 
55
46
 
56
47
  get isEmpty() {
57
- throw _classPrivateFieldLooseBase(this, _neverError)[_neverError];
48
+ throw this.#neverError;
58
49
  }
59
50
 
60
51
  eq() {
61
- throw _classPrivateFieldLooseBase(this, _neverError)[_neverError];
52
+ throw this.#neverError;
62
53
  }
63
54
 
64
55
  toHex() {
65
- throw _classPrivateFieldLooseBase(this, _neverError)[_neverError];
56
+ throw this.#neverError;
66
57
  }
67
58
 
68
59
  toHuman() {
69
- throw _classPrivateFieldLooseBase(this, _neverError)[_neverError];
60
+ throw this.#neverError;
70
61
  }
71
62
 
72
63
  toJSON() {
73
- throw _classPrivateFieldLooseBase(this, _neverError)[_neverError];
64
+ throw this.#neverError;
74
65
  }
75
66
 
76
67
  toRawType() {
77
- throw _classPrivateFieldLooseBase(this, _neverError)[_neverError];
68
+ throw this.#neverError;
78
69
  }
79
70
 
80
71
  toString() {
81
- throw _classPrivateFieldLooseBase(this, _neverError)[_neverError];
72
+ throw this.#neverError;
82
73
  }
83
74
 
84
75
  toU8a() {
85
- throw _classPrivateFieldLooseBase(this, _neverError)[_neverError];
76
+ throw this.#neverError;
86
77
  }
87
78
 
88
79
  }