@polkadot/types-codec 10.3.4 → 10.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.
Files changed (66) hide show
  1. package/abstract/Array.js +21 -14
  2. package/abstract/Base.js +13 -17
  3. package/abstract/Int.js +8 -12
  4. package/base/Compact.js +20 -28
  5. package/base/DoNotConstruct.js +14 -18
  6. package/base/Enum.js +42 -53
  7. package/base/Option.js +17 -25
  8. package/base/Tuple.js +12 -19
  9. package/base/Vec.js +10 -17
  10. package/base/VecFixed.js +7 -14
  11. package/cjs/abstract/Array.js +21 -14
  12. package/cjs/abstract/Base.js +13 -17
  13. package/cjs/abstract/Int.js +8 -12
  14. package/cjs/base/Compact.js +19 -27
  15. package/cjs/base/DoNotConstruct.js +14 -18
  16. package/cjs/base/Enum.js +41 -52
  17. package/cjs/base/Option.js +16 -24
  18. package/cjs/base/Tuple.js +10 -17
  19. package/cjs/base/Vec.js +9 -16
  20. package/cjs/base/VecFixed.js +6 -13
  21. package/cjs/extended/BTreeSet.js +2 -6
  22. package/cjs/extended/BitVec.js +10 -14
  23. package/cjs/extended/Map.js +5 -11
  24. package/cjs/extended/Range.js +2 -6
  25. package/cjs/extended/WrapperKeepOpaque.js +16 -22
  26. package/cjs/native/Float.js +3 -7
  27. package/cjs/native/Set.js +15 -18
  28. package/cjs/native/Struct.js +12 -16
  29. package/cjs/native/Text.js +3 -6
  30. package/cjs/native/index.js +2 -2
  31. package/cjs/packageInfo.js +1 -1
  32. package/cjs/primitive/index.js +17 -17
  33. package/cjs/utils/index.js +6 -6
  34. package/cjs/utils/sanitize.js +16 -16
  35. package/cjs/utils/sortValues.js +2 -6
  36. package/cjs/utils/toConstructors.js +41 -0
  37. package/cjs/utils/typesToMap.js +1 -1
  38. package/extended/BTreeSet.js +2 -6
  39. package/extended/BitVec.js +10 -14
  40. package/extended/Map.js +5 -11
  41. package/extended/Range.js +2 -6
  42. package/extended/WrapperKeepOpaque.js +16 -22
  43. package/native/Float.js +3 -7
  44. package/native/Set.js +15 -18
  45. package/native/Struct.js +12 -16
  46. package/native/Text.js +3 -6
  47. package/native/index.d.ts +1 -1
  48. package/native/index.js +1 -1
  49. package/package.json +9 -14
  50. package/packageInfo.js +1 -1
  51. package/primitive/index.d.ts +16 -16
  52. package/primitive/index.js +16 -16
  53. package/types/registry.d.ts +2 -1
  54. package/utils/index.d.ts +2 -3
  55. package/utils/index.js +2 -3
  56. package/utils/sanitize.js +16 -16
  57. package/utils/sortValues.js +1 -5
  58. package/utils/toConstructors.d.ts +16 -0
  59. package/utils/toConstructors.js +35 -0
  60. package/utils/typesToMap.js +1 -1
  61. package/cjs/utils/mapToTypeMap.js +0 -18
  62. package/cjs/utils/typeToConstructor.js +0 -10
  63. package/utils/mapToTypeMap.d.ts +0 -5
  64. package/utils/mapToTypeMap.js +0 -14
  65. package/utils/typeToConstructor.d.ts +0 -2
  66. package/utils/typeToConstructor.js +0 -6
package/cjs/base/Enum.js CHANGED
@@ -1,14 +1,9 @@
1
1
  "use strict";
2
- var _Enum_def, _Enum_entryIndex, _Enum_indexes, _Enum_isBasic, _Enum_isIndexed, _Enum_raw;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.Enum = void 0;
5
- const tslib_1 = require("tslib");
6
4
  const util_1 = require("@polkadot/util");
7
5
  const index_js_1 = require("../utils/index.js");
8
6
  const Null_js_1 = require("./Null.js");
9
- function noopSetDefinition(d) {
10
- return d;
11
- }
12
7
  function isRustEnum(def) {
13
8
  const defValues = Object.values(def);
14
9
  if (defValues.some((v) => (0, util_1.isNumber)(v))) {
@@ -24,7 +19,7 @@ function extractDef(registry, _def) {
24
19
  let isBasic;
25
20
  let isIndexed;
26
21
  if (Array.isArray(_def)) {
27
- for (let i = 0; i < _def.length; i++) {
22
+ for (let i = 0, count = _def.length; i < count; i++) {
28
23
  def[_def[i]] = { Type: Null_js_1.Null, index: i };
29
24
  }
30
25
  isBasic = true;
@@ -32,7 +27,7 @@ function extractDef(registry, _def) {
32
27
  }
33
28
  else if (isRustEnum(_def)) {
34
29
  const [Types, keys] = (0, index_js_1.mapToTypeMap)(registry, _def);
35
- for (let i = 0; i < keys.length; i++) {
30
+ for (let i = 0, count = keys.length; i < count; i++) {
36
31
  def[keys[i]] = { Type: Types[i], index: i };
37
32
  }
38
33
  isBasic = !Object.values(def).some(({ Type }) => Type !== Null_js_1.Null);
@@ -40,7 +35,7 @@ function extractDef(registry, _def) {
40
35
  }
41
36
  else {
42
37
  const entries = Object.entries(_def);
43
- for (let i = 0; i < entries.length; i++) {
38
+ for (let i = 0, count = entries.length; i < count; i++) {
44
39
  const [key, index] = entries[i];
45
40
  def[key] = { Type: Null_js_1.Null, index };
46
41
  }
@@ -131,27 +126,21 @@ function decodeEnum(registry, def, value, index) {
131
126
  * an extension to enum where the value type is determined by the actual index.
132
127
  */
133
128
  class Enum {
134
- constructor(registry, Types, value, index, { definition, setDefinition = noopSetDefinition } = {}) {
135
- _Enum_def.set(this, void 0);
136
- _Enum_entryIndex.set(this, void 0);
137
- _Enum_indexes.set(this, void 0);
138
- _Enum_isBasic.set(this, void 0);
139
- _Enum_isIndexed.set(this, void 0);
140
- _Enum_raw.set(this, void 0);
129
+ constructor(registry, Types, value, index, { definition, setDefinition = util_1.identity } = {}) {
141
130
  const { def, isBasic, isIndexed } = definition || setDefinition(extractDef(registry, Types));
142
131
  // shortcut isU8a as used in SCALE decoding
143
132
  const decoded = (0, util_1.isU8a)(value) && value.length && !(0, util_1.isNumber)(index)
144
133
  ? createFromU8a(registry, def, value[0], value.subarray(1))
145
134
  : decodeEnum(registry, def, value, index);
146
135
  this.registry = registry;
147
- tslib_1.__classPrivateFieldSet(this, _Enum_def, def, "f");
148
- tslib_1.__classPrivateFieldSet(this, _Enum_isBasic, isBasic, "f");
149
- tslib_1.__classPrivateFieldSet(this, _Enum_isIndexed, isIndexed, "f");
150
- tslib_1.__classPrivateFieldSet(this, _Enum_indexes, Object.values(def).map(({ index }) => index), "f");
151
- tslib_1.__classPrivateFieldSet(this, _Enum_entryIndex, tslib_1.__classPrivateFieldGet(this, _Enum_indexes, "f").indexOf(decoded.index), "f");
152
- tslib_1.__classPrivateFieldSet(this, _Enum_raw, decoded.value, "f");
153
- if (tslib_1.__classPrivateFieldGet(this, _Enum_raw, "f").initialU8aLength) {
154
- this.initialU8aLength = 1 + tslib_1.__classPrivateFieldGet(this, _Enum_raw, "f").initialU8aLength;
136
+ this.__internal__def = def;
137
+ this.__internal__isBasic = isBasic;
138
+ this.__internal__isIndexed = isIndexed;
139
+ this.__internal__indexes = Object.values(def).map(({ index }) => index);
140
+ this.__internal__entryIndex = this.__internal__indexes.indexOf(decoded.index);
141
+ this.__internal__raw = decoded.value;
142
+ if (this.__internal__raw.initialU8aLength) {
143
+ this.initialU8aLength = 1 + this.__internal__raw.initialU8aLength;
155
144
  }
156
145
  }
157
146
  static with(Types) {
@@ -168,9 +157,10 @@ class Enum {
168
157
  const keys = Array.isArray(Types)
169
158
  ? Types
170
159
  : Object.keys(Types);
171
- const asKeys = new Array(keys.length);
172
- const isKeys = new Array(keys.length);
173
- for (let i = 0; i < keys.length; i++) {
160
+ const count = keys.length;
161
+ const asKeys = new Array(count);
162
+ const isKeys = new Array(count);
163
+ for (let i = 0; i < count; i++) {
174
164
  const name = (0, util_1.stringPascalCase)(keys[i]);
175
165
  asKeys[i] = `as${name}`;
176
166
  isKeys[i] = `is${name}`;
@@ -189,7 +179,7 @@ class Enum {
189
179
  * @description The length of the value when encoded as a Uint8Array
190
180
  */
191
181
  get encodedLength() {
192
- return 1 + tslib_1.__classPrivateFieldGet(this, _Enum_raw, "f").encodedLength;
182
+ return 1 + this.__internal__raw.encodedLength;
193
183
  }
194
184
  /**
195
185
  * @description returns a hash of the contents
@@ -201,55 +191,55 @@ class Enum {
201
191
  * @description The index of the enum value
202
192
  */
203
193
  get index() {
204
- return tslib_1.__classPrivateFieldGet(this, _Enum_indexes, "f")[tslib_1.__classPrivateFieldGet(this, _Enum_entryIndex, "f")];
194
+ return this.__internal__indexes[this.__internal__entryIndex];
205
195
  }
206
196
  /**
207
197
  * @description The value of the enum
208
198
  */
209
199
  get inner() {
210
- return tslib_1.__classPrivateFieldGet(this, _Enum_raw, "f");
200
+ return this.__internal__raw;
211
201
  }
212
202
  /**
213
203
  * @description true if this is a basic enum (no values)
214
204
  */
215
205
  get isBasic() {
216
- return tslib_1.__classPrivateFieldGet(this, _Enum_isBasic, "f");
206
+ return this.__internal__isBasic;
217
207
  }
218
208
  /**
219
209
  * @description Checks if the value is an empty value
220
210
  */
221
211
  get isEmpty() {
222
- return tslib_1.__classPrivateFieldGet(this, _Enum_raw, "f").isEmpty;
212
+ return this.__internal__raw.isEmpty;
223
213
  }
224
214
  /**
225
215
  * @description Checks if the Enum points to a [[Null]] type
226
216
  */
227
217
  get isNone() {
228
- return tslib_1.__classPrivateFieldGet(this, _Enum_raw, "f") instanceof Null_js_1.Null;
218
+ return this.__internal__raw instanceof Null_js_1.Null;
229
219
  }
230
220
  /**
231
221
  * @description The available keys for this enum
232
222
  */
233
223
  get defIndexes() {
234
- return tslib_1.__classPrivateFieldGet(this, _Enum_indexes, "f");
224
+ return this.__internal__indexes;
235
225
  }
236
226
  /**
237
227
  * @description The available keys for this enum
238
228
  */
239
229
  get defKeys() {
240
- return Object.keys(tslib_1.__classPrivateFieldGet(this, _Enum_def, "f"));
230
+ return Object.keys(this.__internal__def);
241
231
  }
242
232
  /**
243
233
  * @description The name of the type this enum value represents
244
234
  */
245
235
  get type() {
246
- return this.defKeys[tslib_1.__classPrivateFieldGet(this, _Enum_entryIndex, "f")];
236
+ return this.defKeys[this.__internal__entryIndex];
247
237
  }
248
238
  /**
249
239
  * @description The value of the enum
250
240
  */
251
241
  get value() {
252
- return tslib_1.__classPrivateFieldGet(this, _Enum_raw, "f");
242
+ return this.__internal__raw;
253
243
  }
254
244
  /**
255
245
  * @description Compares the value of the input to see if there is a match
@@ -262,7 +252,7 @@ class Enum {
262
252
  else if ((0, util_1.isNumber)(other)) {
263
253
  return this.toNumber() === other;
264
254
  }
265
- else if (tslib_1.__classPrivateFieldGet(this, _Enum_isBasic, "f") && (0, util_1.isString)(other)) {
255
+ else if (this.__internal__isBasic && (0, util_1.isString)(other)) {
266
256
  return this.type === other;
267
257
  }
268
258
  else if ((0, util_1.isHex)(other)) {
@@ -281,10 +271,10 @@ class Enum {
281
271
  * @description Returns a breakdown of the hex encoding for this Codec
282
272
  */
283
273
  inspect() {
284
- if (tslib_1.__classPrivateFieldGet(this, _Enum_isBasic, "f")) {
274
+ if (this.__internal__isBasic) {
285
275
  return { outer: [new Uint8Array([this.index])] };
286
276
  }
287
- const { inner, outer = [] } = tslib_1.__classPrivateFieldGet(this, _Enum_raw, "f").inspect();
277
+ const { inner, outer = [] } = this.__internal__raw.inspect();
288
278
  return {
289
279
  inner,
290
280
  outer: [new Uint8Array([this.index]), ...outer]
@@ -300,17 +290,17 @@ class Enum {
300
290
  * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
301
291
  */
302
292
  toHuman(isExtended) {
303
- return tslib_1.__classPrivateFieldGet(this, _Enum_isBasic, "f") || this.isNone
293
+ return this.__internal__isBasic || this.isNone
304
294
  ? this.type
305
- : { [this.type]: tslib_1.__classPrivateFieldGet(this, _Enum_raw, "f").toHuman(isExtended) };
295
+ : { [this.type]: this.__internal__raw.toHuman(isExtended) };
306
296
  }
307
297
  /**
308
298
  * @description Converts the Object to JSON, typically used for RPC transfers
309
299
  */
310
300
  toJSON() {
311
- return tslib_1.__classPrivateFieldGet(this, _Enum_isBasic, "f")
301
+ return this.__internal__isBasic
312
302
  ? this.type
313
- : { [(0, util_1.stringCamelCase)(this.type)]: tslib_1.__classPrivateFieldGet(this, _Enum_raw, "f").toJSON() };
303
+ : { [(0, util_1.stringCamelCase)(this.type)]: this.__internal__raw.toJSON() };
314
304
  }
315
305
  /**
316
306
  * @description Returns the number representation for the value
@@ -322,23 +312,23 @@ class Enum {
322
312
  * @description Converts the value in a best-fit primitive form
323
313
  */
324
314
  toPrimitive() {
325
- return tslib_1.__classPrivateFieldGet(this, _Enum_isBasic, "f")
315
+ return this.__internal__isBasic
326
316
  ? this.type
327
- : { [(0, util_1.stringCamelCase)(this.type)]: tslib_1.__classPrivateFieldGet(this, _Enum_raw, "f").toPrimitive() };
317
+ : { [(0, util_1.stringCamelCase)(this.type)]: this.__internal__raw.toPrimitive() };
328
318
  }
329
319
  /**
330
320
  * @description Returns a raw struct representation of the enum types
331
321
  */
332
322
  _toRawStruct() {
333
- if (tslib_1.__classPrivateFieldGet(this, _Enum_isBasic, "f")) {
334
- return tslib_1.__classPrivateFieldGet(this, _Enum_isIndexed, "f")
323
+ if (this.__internal__isBasic) {
324
+ return this.__internal__isIndexed
335
325
  ? this.defKeys.reduce((out, key, index) => {
336
- out[key] = tslib_1.__classPrivateFieldGet(this, _Enum_indexes, "f")[index];
326
+ out[key] = this.__internal__indexes[index];
337
327
  return out;
338
328
  }, {})
339
329
  : this.defKeys;
340
330
  }
341
- const entries = Object.entries(tslib_1.__classPrivateFieldGet(this, _Enum_def, "f"));
331
+ const entries = Object.entries(this.__internal__def);
342
332
  return (0, index_js_1.typesToMap)(this.registry, entries.reduce((out, [key, { Type }], i) => {
343
333
  out[0][i] = Type;
344
334
  out[1][i] = key;
@@ -365,12 +355,11 @@ class Enum {
365
355
  */
366
356
  toU8a(isBare) {
367
357
  return isBare
368
- ? tslib_1.__classPrivateFieldGet(this, _Enum_raw, "f").toU8a(isBare)
358
+ ? this.__internal__raw.toU8a(isBare)
369
359
  : (0, util_1.u8aConcatStrict)([
370
360
  new Uint8Array([this.index]),
371
- tslib_1.__classPrivateFieldGet(this, _Enum_raw, "f").toU8a(isBare)
361
+ this.__internal__raw.toU8a(isBare)
372
362
  ]);
373
363
  }
374
364
  }
375
365
  exports.Enum = Enum;
376
- _Enum_def = new WeakMap(), _Enum_entryIndex = new WeakMap(), _Enum_indexes = new WeakMap(), _Enum_isBasic = new WeakMap(), _Enum_isIndexed = new WeakMap(), _Enum_raw = new WeakMap();
@@ -1,14 +1,9 @@
1
1
  "use strict";
2
- var _Option_Type, _Option_raw;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.Option = void 0;
5
- const tslib_1 = require("tslib");
6
4
  const util_1 = require("@polkadot/util");
7
5
  const index_js_1 = require("../utils/index.js");
8
6
  const Null_js_1 = require("./Null.js");
9
- function noopSetDefinition(d) {
10
- return d;
11
- }
12
7
  class None extends Null_js_1.Null {
13
8
  /**
14
9
  * @description Returns the base runtime type name for this instance
@@ -57,9 +52,7 @@ function decodeOption(registry, Type, value) {
57
52
  * with a value if/as required/found.
58
53
  */
59
54
  class Option {
60
- constructor(registry, typeName, value, { definition, setDefinition = noopSetDefinition } = {}) {
61
- _Option_Type.set(this, void 0);
62
- _Option_raw.set(this, void 0);
55
+ constructor(registry, typeName, value, { definition, setDefinition = util_1.identity } = {}) {
63
56
  const Type = definition || setDefinition((0, index_js_1.typeToConstructor)(registry, typeName));
64
57
  const decoded = (0, util_1.isU8a)(value) && value.length && !(0, util_1.isCodec)(value)
65
58
  ? value[0] === 0
@@ -67,8 +60,8 @@ class Option {
67
60
  : new Type(registry, value.subarray(1))
68
61
  : decodeOption(registry, Type, value);
69
62
  this.registry = registry;
70
- tslib_1.__classPrivateFieldSet(this, _Option_Type, Type, "f");
71
- tslib_1.__classPrivateFieldSet(this, _Option_raw, decoded, "f");
63
+ this.__internal__Type = Type;
64
+ this.__internal__raw = decoded;
72
65
  if (decoded?.initialU8aLength) {
73
66
  this.initialU8aLength = 1 + decoded.initialU8aLength;
74
67
  }
@@ -90,7 +83,7 @@ class Option {
90
83
  */
91
84
  get encodedLength() {
92
85
  // boolean byte (has value, doesn't have) along with wrapped length
93
- return 1 + tslib_1.__classPrivateFieldGet(this, _Option_raw, "f").encodedLength;
86
+ return 1 + this.__internal__raw.encodedLength;
94
87
  }
95
88
  /**
96
89
  * @description returns a hash of the contents
@@ -108,7 +101,7 @@ class Option {
108
101
  * @description Checks if the Option has no value
109
102
  */
110
103
  get isNone() {
111
- return tslib_1.__classPrivateFieldGet(this, _Option_raw, "f") instanceof None;
104
+ return this.__internal__raw instanceof None;
112
105
  }
113
106
  /**
114
107
  * @description Checks if the Option has a value
@@ -120,7 +113,7 @@ class Option {
120
113
  * @description The actual value for the Option
121
114
  */
122
115
  get value() {
123
- return tslib_1.__classPrivateFieldGet(this, _Option_raw, "f");
116
+ return this.__internal__raw;
124
117
  }
125
118
  /**
126
119
  * @description Compares the value of the input to see if there is a match
@@ -138,7 +131,7 @@ class Option {
138
131
  if (this.isNone) {
139
132
  return { outer: [new Uint8Array([0])] };
140
133
  }
141
- const { inner, outer = [] } = tslib_1.__classPrivateFieldGet(this, _Option_raw, "f").inspect();
134
+ const { inner, outer = [] } = this.__internal__raw.inspect();
142
135
  return {
143
136
  inner,
144
137
  outer: [new Uint8Array([1]), ...outer]
@@ -158,7 +151,7 @@ class Option {
158
151
  * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
159
152
  */
160
153
  toHuman(isExtended) {
161
- return tslib_1.__classPrivateFieldGet(this, _Option_raw, "f").toHuman(isExtended);
154
+ return this.__internal__raw.toHuman(isExtended);
162
155
  }
163
156
  /**
164
157
  * @description Converts the Object to JSON, typically used for RPC transfers
@@ -166,7 +159,7 @@ class Option {
166
159
  toJSON() {
167
160
  return this.isNone
168
161
  ? null
169
- : tslib_1.__classPrivateFieldGet(this, _Option_raw, "f").toJSON();
162
+ : this.__internal__raw.toJSON();
170
163
  }
171
164
  /**
172
165
  * @description Converts the value in a best-fit primitive form
@@ -174,13 +167,13 @@ class Option {
174
167
  toPrimitive() {
175
168
  return this.isNone
176
169
  ? null
177
- : tslib_1.__classPrivateFieldGet(this, _Option_raw, "f").toPrimitive();
170
+ : this.__internal__raw.toPrimitive();
178
171
  }
179
172
  /**
180
173
  * @description Returns the base runtime type name for this instance
181
174
  */
182
175
  toRawType(isBare) {
183
- const wrapped = this.registry.getClassName(tslib_1.__classPrivateFieldGet(this, _Option_Type, "f")) || new (tslib_1.__classPrivateFieldGet(this, _Option_Type, "f"))(this.registry).toRawType();
176
+ const wrapped = this.registry.getClassName(this.__internal__Type) || new this.__internal__Type(this.registry).toRawType();
184
177
  return isBare
185
178
  ? wrapped
186
179
  : `Option<${wrapped}>`;
@@ -189,7 +182,7 @@ class Option {
189
182
  * @description Returns the string representation of the value
190
183
  */
191
184
  toString() {
192
- return tslib_1.__classPrivateFieldGet(this, _Option_raw, "f").toString();
185
+ return this.__internal__raw.toString();
193
186
  }
194
187
  /**
195
188
  * @description Encodes the value as a Uint8Array as per the SCALE specifications
@@ -197,12 +190,12 @@ class Option {
197
190
  */
198
191
  toU8a(isBare) {
199
192
  if (isBare) {
200
- return tslib_1.__classPrivateFieldGet(this, _Option_raw, "f").toU8a(true);
193
+ return this.__internal__raw.toU8a(true);
201
194
  }
202
195
  const u8a = new Uint8Array(this.encodedLength);
203
196
  if (this.isSome) {
204
197
  u8a.set([1]);
205
- u8a.set(tslib_1.__classPrivateFieldGet(this, _Option_raw, "f").toU8a(), 1);
198
+ u8a.set(this.__internal__raw.toU8a(), 1);
206
199
  }
207
200
  return u8a;
208
201
  }
@@ -213,7 +206,7 @@ class Option {
213
206
  if (this.isNone) {
214
207
  throw new Error('Option: unwrapping a None value');
215
208
  }
216
- return tslib_1.__classPrivateFieldGet(this, _Option_raw, "f");
209
+ return this.__internal__raw;
217
210
  }
218
211
  /**
219
212
  * @description Returns the value that the Option represents (if available) or defaultValue if none
@@ -231,8 +224,7 @@ class Option {
231
224
  unwrapOrDefault() {
232
225
  return this.isSome
233
226
  ? this.unwrap()
234
- : new (tslib_1.__classPrivateFieldGet(this, _Option_Type, "f"))(this.registry);
227
+ : new this.__internal__Type(this.registry);
235
228
  }
236
229
  }
237
230
  exports.Option = Option;
238
- _Option_Type = new WeakMap(), _Option_raw = new WeakMap();
package/cjs/base/Tuple.js CHANGED
@@ -1,19 +1,14 @@
1
1
  "use strict";
2
- var _Tuple_Types;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.Tuple = void 0;
5
- const tslib_1 = require("tslib");
6
4
  const util_1 = require("@polkadot/util");
7
5
  const Array_js_1 = require("../abstract/Array.js");
8
6
  const index_js_1 = require("../utils/index.js");
9
- function noopSetDefinition(d) {
10
- return d;
11
- }
12
7
  /** @internal */
13
8
  function decodeTuple(registry, result, value, Classes) {
14
9
  if (Array.isArray(value)) {
15
10
  const Types = Classes[0];
16
- for (let i = 0; i < Types.length; i++) {
11
+ for (let i = 0, count = Types.length; i < count; i++) {
17
12
  try {
18
13
  const entry = value?.[i];
19
14
  result[i] = entry instanceof Types[i]
@@ -31,7 +26,7 @@ function decodeTuple(registry, result, value, Classes) {
31
26
  }
32
27
  else if (!value || !result.length) {
33
28
  const Types = Classes[0];
34
- for (let i = 0; i < Types.length; i++) {
29
+ for (let i = 0, count = Types.length; i < count; i++) {
35
30
  result[i] = new Types[i](registry);
36
31
  }
37
32
  return [result, 0];
@@ -45,18 +40,17 @@ function decodeTuple(registry, result, value, Classes) {
45
40
  * own type. It extends the base JS `Array` object.
46
41
  */
47
42
  class Tuple extends Array_js_1.AbstractArray {
48
- constructor(registry, Types, value, { definition, setDefinition = noopSetDefinition } = {}) {
43
+ constructor(registry, Types, value, { definition, setDefinition = util_1.identity } = {}) {
49
44
  const Classes = definition || setDefinition(Array.isArray(Types)
50
- ? [Types.map((t) => (0, index_js_1.typeToConstructor)(registry, t)), []]
45
+ ? [(0, index_js_1.typesToConstructors)(registry, Types), []]
51
46
  : (0, util_1.isFunction)(Types) || (0, util_1.isString)(Types)
52
47
  ? [[(0, index_js_1.typeToConstructor)(registry, Types)], []]
53
48
  : (0, index_js_1.mapToTypeMap)(registry, Types));
54
49
  super(registry, Classes[0].length);
55
- _Tuple_Types.set(this, void 0);
56
50
  this.initialU8aLength = ((0, util_1.isU8a)(value)
57
51
  ? (0, index_js_1.decodeU8a)(registry, this, value, Classes)
58
52
  : decodeTuple(registry, this, value, Classes))[1];
59
- tslib_1.__classPrivateFieldSet(this, _Tuple_Types, Classes, "f");
53
+ this.__internal__Types = Classes;
60
54
  }
61
55
  static with(Types) {
62
56
  let definition;
@@ -73,7 +67,7 @@ class Tuple extends Array_js_1.AbstractArray {
73
67
  */
74
68
  get encodedLength() {
75
69
  let total = 0;
76
- for (let i = 0; i < this.length; i++) {
70
+ for (let i = 0, count = this.length; i < count; i++) {
77
71
  total += this[i].encodedLength;
78
72
  }
79
73
  return total;
@@ -82,9 +76,9 @@ class Tuple extends Array_js_1.AbstractArray {
82
76
  * @description The types definition of the tuple
83
77
  */
84
78
  get Types() {
85
- return tslib_1.__classPrivateFieldGet(this, _Tuple_Types, "f")[1].length
86
- ? tslib_1.__classPrivateFieldGet(this, _Tuple_Types, "f")[1]
87
- : tslib_1.__classPrivateFieldGet(this, _Tuple_Types, "f")[0].map((T) => new T(this.registry).toRawType());
79
+ return this.__internal__Types[1].length
80
+ ? this.__internal__Types[1]
81
+ : this.__internal__Types[0].map((T) => new T(this.registry).toRawType());
88
82
  }
89
83
  /**
90
84
  * @description Returns a breakdown of the hex encoding for this Codec
@@ -98,7 +92,7 @@ class Tuple extends Array_js_1.AbstractArray {
98
92
  * @description Returns the base runtime type name for this instance
99
93
  */
100
94
  toRawType() {
101
- const types = tslib_1.__classPrivateFieldGet(this, _Tuple_Types, "f")[0].map((T) => this.registry.getClassName(T) || new T(this.registry).toRawType());
95
+ const types = this.__internal__Types[0].map((T) => this.registry.getClassName(T) || new T(this.registry).toRawType());
102
96
  return `(${types.join(',')})`;
103
97
  }
104
98
  /**
@@ -117,4 +111,3 @@ class Tuple extends Array_js_1.AbstractArray {
117
111
  }
118
112
  }
119
113
  exports.Tuple = Tuple;
120
- _Tuple_Types = new WeakMap();
package/cjs/base/Vec.js CHANGED
@@ -1,16 +1,11 @@
1
1
  "use strict";
2
- var _Vec_Type;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.Vec = exports.decodeVec = void 0;
5
- const tslib_1 = require("tslib");
6
4
  const util_1 = require("@polkadot/util");
7
5
  const Array_js_1 = require("../abstract/Array.js");
8
6
  const index_js_1 = require("../utils/index.js");
9
7
  const MAX_LENGTH = 64 * 1024;
10
8
  const l = (0, util_1.logger)('Vec');
11
- function noopSetDefinition(d) {
12
- return d;
13
- }
14
9
  function decodeVecLength(value) {
15
10
  if (Array.isArray(value)) {
16
11
  return [value, value.length, 0];
@@ -62,14 +57,13 @@ exports.decodeVec = decodeVec;
62
57
  * specific encoding/decoding on top of the base type.
63
58
  */
64
59
  class Vec extends Array_js_1.AbstractArray {
65
- constructor(registry, Type, value = [], { definition, setDefinition = noopSetDefinition } = {}) {
60
+ constructor(registry, Type, value = [], { definition, setDefinition = util_1.identity } = {}) {
66
61
  const [decodeFrom, length, startAt] = decodeVecLength(value);
67
62
  super(registry, length);
68
- _Vec_Type.set(this, void 0);
69
- tslib_1.__classPrivateFieldSet(this, _Vec_Type, definition || setDefinition((0, index_js_1.typeToConstructor)(registry, Type)), "f");
63
+ this.__internal__Type = definition || setDefinition((0, index_js_1.typeToConstructor)(registry, Type));
70
64
  this.initialU8aLength = ((0, util_1.isU8a)(decodeFrom)
71
- ? (0, index_js_1.decodeU8aVec)(registry, this, decodeFrom, startAt, tslib_1.__classPrivateFieldGet(this, _Vec_Type, "f"))
72
- : decodeVec(registry, this, decodeFrom, startAt, tslib_1.__classPrivateFieldGet(this, _Vec_Type, "f")))[0];
65
+ ? (0, index_js_1.decodeU8aVec)(registry, this, decodeFrom, startAt, this.__internal__Type)
66
+ : decodeVec(registry, this, decodeFrom, startAt, this.__internal__Type))[0];
73
67
  }
74
68
  static with(Type) {
75
69
  let definition;
@@ -85,17 +79,17 @@ class Vec extends Array_js_1.AbstractArray {
85
79
  * @description The type for the items
86
80
  */
87
81
  get Type() {
88
- return tslib_1.__classPrivateFieldGet(this, _Vec_Type, "f").name;
82
+ return this.__internal__Type.name;
89
83
  }
90
84
  /**
91
85
  * @description Finds the index of the value in the array
92
86
  */
93
87
  indexOf(other) {
94
88
  // convert type first, this removes overhead from the eq
95
- const check = other instanceof tslib_1.__classPrivateFieldGet(this, _Vec_Type, "f")
89
+ const check = other instanceof this.__internal__Type
96
90
  ? other
97
- : new (tslib_1.__classPrivateFieldGet(this, _Vec_Type, "f"))(this.registry, other);
98
- for (let i = 0; i < this.length; i++) {
91
+ : new this.__internal__Type(this.registry, other);
92
+ for (let i = 0, count = this.length; i < count; i++) {
99
93
  if (check.eq(this[i])) {
100
94
  return i;
101
95
  }
@@ -106,8 +100,7 @@ class Vec extends Array_js_1.AbstractArray {
106
100
  * @description Returns the base runtime type name for this instance
107
101
  */
108
102
  toRawType() {
109
- return `Vec<${this.registry.getClassName(tslib_1.__classPrivateFieldGet(this, _Vec_Type, "f")) || new (tslib_1.__classPrivateFieldGet(this, _Vec_Type, "f"))(this.registry).toRawType()}>`;
103
+ return `Vec<${this.registry.getClassName(this.__internal__Type) || new this.__internal__Type(this.registry).toRawType()}>`;
110
104
  }
111
105
  }
112
106
  exports.Vec = Vec;
113
- _Vec_Type = new WeakMap();
@@ -1,28 +1,22 @@
1
1
  "use strict";
2
- var _VecFixed_Type;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.VecFixed = void 0;
5
- const tslib_1 = require("tslib");
6
4
  const util_1 = require("@polkadot/util");
7
5
  const Array_js_1 = require("../abstract/Array.js");
8
6
  const index_js_1 = require("../utils/index.js");
9
7
  const Vec_js_1 = require("./Vec.js");
10
- function noopSetDefinition(d) {
11
- return d;
12
- }
13
8
  /**
14
9
  * @name VecFixed
15
10
  * @description
16
11
  * This manages codec arrays of a fixed length
17
12
  */
18
13
  class VecFixed extends Array_js_1.AbstractArray {
19
- constructor(registry, Type, length, value = [], { definition, setDefinition = noopSetDefinition } = {}) {
14
+ constructor(registry, Type, length, value = [], { definition, setDefinition = util_1.identity } = {}) {
20
15
  super(registry, length);
21
- _VecFixed_Type.set(this, void 0);
22
- tslib_1.__classPrivateFieldSet(this, _VecFixed_Type, definition || setDefinition((0, index_js_1.typeToConstructor)(registry, Type)), "f");
16
+ this.__internal__Type = definition || setDefinition((0, index_js_1.typeToConstructor)(registry, Type));
23
17
  this.initialU8aLength = ((0, util_1.isU8a)(value)
24
- ? (0, index_js_1.decodeU8aVec)(registry, this, value, 0, tslib_1.__classPrivateFieldGet(this, _VecFixed_Type, "f"))
25
- : (0, Vec_js_1.decodeVec)(registry, this, value, 0, tslib_1.__classPrivateFieldGet(this, _VecFixed_Type, "f")))[1];
18
+ ? (0, index_js_1.decodeU8aVec)(registry, this, value, 0, this.__internal__Type)
19
+ : (0, Vec_js_1.decodeVec)(registry, this, value, 0, this.__internal__Type))[1];
26
20
  }
27
21
  static with(Type, length) {
28
22
  let definition;
@@ -38,14 +32,14 @@ class VecFixed extends Array_js_1.AbstractArray {
38
32
  * @description The type for the items
39
33
  */
40
34
  get Type() {
41
- return new (tslib_1.__classPrivateFieldGet(this, _VecFixed_Type, "f"))(this.registry).toRawType();
35
+ return new this.__internal__Type(this.registry).toRawType();
42
36
  }
43
37
  /**
44
38
  * @description The length of the value when encoded as a Uint8Array
45
39
  */
46
40
  get encodedLength() {
47
41
  let total = 0;
48
- for (let i = 0; i < this.length; i++) {
42
+ for (let i = 0, count = this.length; i < count; i++) {
49
43
  total += this[i].encodedLength;
50
44
  }
51
45
  return total;
@@ -74,4 +68,3 @@ class VecFixed extends Array_js_1.AbstractArray {
74
68
  }
75
69
  }
76
70
  exports.VecFixed = VecFixed;
77
- _VecFixed_Type = new WeakMap();
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
- var _BTreeSet_ValClass;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.BTreeSet = void 0;
5
- const tslib_1 = require("tslib");
6
4
  const util_1 = require("@polkadot/util");
7
5
  const index_js_1 = require("../utils/index.js");
8
6
  const l = (0, util_1.logger)('BTreeSet');
@@ -62,10 +60,9 @@ class BTreeSet extends Set {
62
60
  constructor(registry, valType, rawValue) {
63
61
  const [ValClass, values, decodedLength] = decodeSet(registry, valType, rawValue);
64
62
  super((0, index_js_1.sortSet)(values));
65
- _BTreeSet_ValClass.set(this, void 0);
66
63
  this.registry = registry;
67
64
  this.initialU8aLength = decodedLength;
68
- tslib_1.__classPrivateFieldSet(this, _BTreeSet_ValClass, ValClass, "f");
65
+ this.__internal__ValClass = ValClass;
69
66
  }
70
67
  static with(valType) {
71
68
  return class extends BTreeSet {
@@ -151,7 +148,7 @@ class BTreeSet extends Set {
151
148
  * @description Returns the base runtime type name for this instance
152
149
  */
153
150
  toRawType() {
154
- return `BTreeSet<${this.registry.getClassName(tslib_1.__classPrivateFieldGet(this, _BTreeSet_ValClass, "f")) || new (tslib_1.__classPrivateFieldGet(this, _BTreeSet_ValClass, "f"))(this.registry).toRawType()}>`;
151
+ return `BTreeSet<${this.registry.getClassName(this.__internal__ValClass) || new this.__internal__ValClass(this.registry).toRawType()}>`;
155
152
  }
156
153
  /**
157
154
  * @description Converts the value in a best-fit primitive form
@@ -185,4 +182,3 @@ class BTreeSet extends Set {
185
182
  }
186
183
  }
187
184
  exports.BTreeSet = BTreeSet;
188
- _BTreeSet_ValClass = new WeakMap();