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