@polkadot/types-codec 8.8.3-2 → 8.8.3-5

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 (69) hide show
  1. package/abstract/{AbstractArray.d.ts → Array.d.ts} +0 -0
  2. package/abstract/{AbstractArray.js → Array.js} +0 -0
  3. package/{base → abstract}/Base.d.ts +2 -2
  4. package/{base → abstract}/Base.js +2 -7
  5. package/abstract/{AbstractInt.d.ts → Int.d.ts} +1 -4
  6. package/abstract/{AbstractInt.js → Int.js} +7 -14
  7. package/abstract/index.d.ts +3 -2
  8. package/abstract/index.js +3 -2
  9. package/base/Compact.d.ts +0 -2
  10. package/base/Compact.js +15 -16
  11. package/base/Enum.js +6 -6
  12. package/base/Int.d.ts +1 -1
  13. package/base/Int.js +1 -1
  14. package/base/Null.d.ts +2 -8
  15. package/base/Null.js +2 -16
  16. package/base/Option.d.ts +1 -4
  17. package/base/Option.js +1 -10
  18. package/base/Tuple.d.ts +1 -1
  19. package/base/Tuple.js +3 -4
  20. package/base/UInt.d.ts +1 -1
  21. package/base/UInt.js +1 -1
  22. package/base/Vec.d.ts +1 -1
  23. package/base/Vec.js +2 -3
  24. package/base/VecAny.d.ts +1 -1
  25. package/base/VecAny.js +1 -1
  26. package/base/VecFixed.d.ts +1 -1
  27. package/base/VecFixed.js +2 -3
  28. package/base/index.d.ts +0 -1
  29. package/base/index.js +0 -1
  30. package/cjs/abstract/{AbstractArray.js → Array.js} +0 -0
  31. package/cjs/{base → abstract}/Base.js +4 -9
  32. package/cjs/abstract/{AbstractInt.js → Int.js} +6 -13
  33. package/cjs/abstract/index.js +12 -4
  34. package/cjs/base/Compact.js +15 -16
  35. package/cjs/base/Enum.js +5 -5
  36. package/cjs/base/Int.js +2 -2
  37. package/cjs/base/Null.js +2 -16
  38. package/cjs/base/Option.js +1 -10
  39. package/cjs/base/Tuple.js +4 -5
  40. package/cjs/base/UInt.js +2 -2
  41. package/cjs/base/Vec.js +3 -4
  42. package/cjs/base/VecAny.js +2 -2
  43. package/cjs/base/VecFixed.js +3 -4
  44. package/cjs/base/index.js +0 -8
  45. package/cjs/extended/Bytes.js +1 -1
  46. package/cjs/extended/Map.js +2 -2
  47. package/cjs/extended/OptionBool.js +1 -8
  48. package/cjs/native/Struct.js +2 -7
  49. package/cjs/native/Text.js +1 -10
  50. package/cjs/packageInfo.js +1 -1
  51. package/cjs/utils/decodeU8a.js +63 -20
  52. package/cjs/utils/index.js +6 -0
  53. package/cjs/utils/mapToTypeMap.js +1 -1
  54. package/extended/Bytes.js +2 -2
  55. package/extended/Map.js +1 -1
  56. package/extended/OptionBool.d.ts +0 -4
  57. package/extended/OptionBool.js +1 -8
  58. package/native/Raw.d.ts +1 -1
  59. package/native/Struct.d.ts +1 -1
  60. package/native/Struct.js +3 -8
  61. package/native/Text.d.ts +2 -5
  62. package/native/Text.js +1 -10
  63. package/package.json +15 -15
  64. package/packageInfo.js +1 -1
  65. package/utils/decodeU8a.d.ts +16 -1
  66. package/utils/decodeU8a.js +57 -19
  67. package/utils/index.d.ts +1 -1
  68. package/utils/index.js +1 -1
  69. package/utils/mapToTypeMap.js +1 -1
@@ -6,16 +6,24 @@ Object.defineProperty(exports, "__esModule", {
6
6
  Object.defineProperty(exports, "AbstractArray", {
7
7
  enumerable: true,
8
8
  get: function () {
9
- return _AbstractArray.AbstractArray;
9
+ return _Array.AbstractArray;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "AbstractBase", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _Base.AbstractBase;
10
16
  }
11
17
  });
12
18
  Object.defineProperty(exports, "AbstractInt", {
13
19
  enumerable: true,
14
20
  get: function () {
15
- return _AbstractInt.AbstractInt;
21
+ return _Int.AbstractInt;
16
22
  }
17
23
  });
18
24
 
19
- var _AbstractArray = require("./AbstractArray");
25
+ var _Array = require("./Array");
26
+
27
+ var _Base = require("./Base");
20
28
 
21
- var _AbstractInt = require("./AbstractInt");
29
+ var _Int = require("./Int");
@@ -14,6 +14,20 @@ var _utils = require("../utils");
14
14
  function noopSetDefinition(d) {
15
15
  return d;
16
16
  }
17
+
18
+ function decodeCompact(registry, Type, value) {
19
+ if ((0, _util.isU8a)(value)) {
20
+ const [decodedLength, bn] = (value[0] & 0b11) < 0b11 ? (0, _util.compactFromU8aLim)(value) : (0, _util.compactFromU8a)(value);
21
+ return [new Type(registry, bn), decodedLength];
22
+ } else if (value instanceof Compact) {
23
+ const raw = value.unwrap();
24
+ return raw instanceof Type ? [raw, 0] : [new Type(registry, raw), 0];
25
+ } else if (value instanceof Type) {
26
+ return [value, 0];
27
+ }
28
+
29
+ return [new Type(registry, value), 0];
30
+ }
17
31
  /**
18
32
  * @name Compact
19
33
  * @description
@@ -36,7 +50,7 @@ class Compact {
36
50
  } = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
37
51
  this.registry = registry;
38
52
  this.#Type = definition || setDefinition((0, _utils.typeToConstructor)(registry, Type));
39
- const [raw, decodedLength] = Compact.decodeCompact(registry, this.#Type, value);
53
+ const [raw, decodedLength] = decodeCompact(registry, this.#Type, value);
40
54
  this.initialU8aLength = decodedLength;
41
55
  this.#raw = raw;
42
56
  }
@@ -56,21 +70,6 @@ class Compact {
56
70
 
57
71
  };
58
72
  }
59
- /** @internal */
60
-
61
-
62
- static decodeCompact(registry, Type, value) {
63
- if ((0, _util.isU8a)(value)) {
64
- const [decodedLength, bn] = (value[0] & 0b11) < 0b11 ? (0, _util.compactFromU8aLim)(value) : (0, _util.compactFromU8a)(value);
65
- return [new Type(registry, bn), decodedLength];
66
- } else if (value instanceof Compact) {
67
- return value.#raw instanceof Type ? [value.#raw, 0] : [new Type(registry, value.#raw), 0];
68
- } else if (value instanceof Type) {
69
- return [value, 0];
70
- }
71
-
72
- return [new Type(registry, value), 0];
73
- }
74
73
  /**
75
74
  * @description The length of the value when encoded as a Uint8Array
76
75
  */
package/cjs/base/Enum.js CHANGED
@@ -89,7 +89,7 @@ function createFromValue(registry, def) {
89
89
  (0, _util.assert)(!(0, _util.isUndefined)(entry), () => `Unable to create Enum via index ${index}, in ${Object.keys(def).join(', ')}`);
90
90
  return {
91
91
  index,
92
- value: (0, _util.isCodec)(value) && value instanceof entry.Type ? value : new entry.Type(registry, value)
92
+ value: value instanceof entry.Type ? value : new entry.Type(registry, value)
93
93
  };
94
94
  }
95
95
 
@@ -171,7 +171,7 @@ class Enum {
171
171
  } = _ref2;
172
172
  return index;
173
173
  });
174
- this.#entryIndex = this.#indexes.indexOf(decoded.index) || 0;
174
+ this.#entryIndex = this.#indexes.indexOf(decoded.index);
175
175
  this.#raw = decoded.value;
176
176
 
177
177
  if (this.#raw.initialU8aLength) {
@@ -185,7 +185,7 @@ class Enum {
185
185
  const isKeys = new Array(keys.length);
186
186
 
187
187
  for (let i = 0; i < keys.length; i++) {
188
- const name = (0, _util.stringPascalCase)(keys[i].replace(' ', '_'));
188
+ const name = (0, _util.stringPascalCase)(keys[i]);
189
189
  asKeys[i] = `as${name}`;
190
190
  isKeys[i] = `is${name}`;
191
191
  }
@@ -321,7 +321,7 @@ class Enum {
321
321
  return this.type === other;
322
322
  } else if ((0, _util.isHex)(other)) {
323
323
  return this.toHex() === other;
324
- } else if ((0, _util.isCodec)(other) && other instanceof Enum) {
324
+ } else if (other instanceof Enum) {
325
325
  return this.index === other.index && this.value.eq(other.value);
326
326
  } else if ((0, _util.isObject)(other)) {
327
327
  return this.value.eq(other[this.type]);
@@ -336,7 +336,7 @@ class Enum {
336
336
 
337
337
 
338
338
  inspect() {
339
- if (this.isBasic) {
339
+ if (this.#isBasic) {
340
340
  return {
341
341
  outer: [new Uint8Array([this.index])]
342
342
  };
package/cjs/base/Int.js CHANGED
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.Int = void 0;
7
7
 
8
- var _AbstractInt = require("../abstract/AbstractInt");
8
+ var _Int = require("../abstract/Int");
9
9
 
10
10
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
11
11
  // SPDX-License-Identifier: Apache-2.0
@@ -20,7 +20,7 @@ var _AbstractInt = require("../abstract/AbstractInt");
20
20
  * is available here.
21
21
  * @noInheritDoc
22
22
  */
23
- class Int extends _AbstractInt.AbstractInt {
23
+ class Int extends _Int.AbstractInt {
24
24
  constructor(registry) {
25
25
  let value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
26
26
  let bitLength = arguments.length > 2 ? arguments[2] : undefined;
package/cjs/base/Null.js CHANGED
@@ -16,20 +16,14 @@ var _util = require("@polkadot/util");
16
16
  * Implements a type that does not contain anything (apart from `null`)
17
17
  */
18
18
  class Null {
19
+ encodedLength = 0;
20
+ isEmpty = true;
19
21
  // Added for compatibility reasons, e.g. see Option
20
22
  initialU8aLength = 0;
21
23
 
22
24
  constructor(registry) {
23
25
  this.registry = registry;
24
26
  }
25
- /**
26
- * @description The length of the value when encoded as a Uint8Array
27
- */
28
-
29
-
30
- get encodedLength() {
31
- return 0;
32
- }
33
27
  /**
34
28
  * @description returns a hash of the contents
35
29
  */
@@ -38,14 +32,6 @@ class Null {
38
32
  get hash() {
39
33
  throw new Error('.hash is not implemented on Null');
40
34
  }
41
- /**
42
- * @description Checks if the value is an empty value (always true)
43
- */
44
-
45
-
46
- get isEmpty() {
47
- return true;
48
- }
49
35
  /**
50
36
  * @description Compares the value of the input to see if there is a match
51
37
  */
@@ -67,7 +67,6 @@ function decodeOption(registry, Type, value) {
67
67
 
68
68
  class Option {
69
69
  #Type;
70
- #initialU8aLength;
71
70
  #raw;
72
71
 
73
72
  constructor(registry, typeName, value) {
@@ -82,7 +81,7 @@ class Option {
82
81
  this.#raw = decoded;
83
82
 
84
83
  if (decoded && decoded.initialU8aLength) {
85
- this.#initialU8aLength = 1 + decoded.initialU8aLength;
84
+ this.initialU8aLength = 1 + decoded.initialU8aLength;
86
85
  }
87
86
  }
88
87
 
@@ -113,14 +112,6 @@ class Option {
113
112
  // boolean byte (has value, doesn't have) along with wrapped length
114
113
  return 1 + this.#raw.encodedLength;
115
114
  }
116
- /**
117
- * @description The length of the initial encoded value (Only available when constructed from a Uint8Array)
118
- */
119
-
120
-
121
- get initialU8aLength() {
122
- return this.#initialU8aLength;
123
- }
124
115
  /**
125
116
  * @description returns a hash of the contents
126
117
  */
package/cjs/base/Tuple.js CHANGED
@@ -7,7 +7,7 @@ exports.Tuple = void 0;
7
7
 
8
8
  var _util = require("@polkadot/util");
9
9
 
10
- var _AbstractArray = require("../abstract/AbstractArray");
10
+ var _Array = require("../abstract/Array");
11
11
 
12
12
  var _utils = require("../utils");
13
13
 
@@ -19,7 +19,7 @@ function noopSetDefinition(d) {
19
19
  /** @internal */
20
20
 
21
21
 
22
- function decodeTuple(registry, result, Classes, value) {
22
+ function decodeTuple(registry, result, value, Classes) {
23
23
  if ((0, _util.isU8a)(value) || (0, _util.isHex)(value)) {
24
24
  return (0, _utils.decodeU8a)(registry, result, (0, _util.u8aToU8a)(value), Classes);
25
25
  }
@@ -45,7 +45,7 @@ function decodeTuple(registry, result, Classes, value) {
45
45
  */
46
46
 
47
47
 
48
- class Tuple extends _AbstractArray.AbstractArray {
48
+ class Tuple extends _Array.AbstractArray {
49
49
  #Types;
50
50
 
51
51
  constructor(registry, Types, value) {
@@ -55,8 +55,7 @@ class Tuple extends _AbstractArray.AbstractArray {
55
55
  } = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
56
56
  const Classes = definition || setDefinition(Array.isArray(Types) ? [Types.map(t => (0, _utils.typeToConstructor)(registry, t)), []] : (0, _util.isFunction)(Types) || (0, _util.isString)(Types) ? [[(0, _utils.typeToConstructor)(registry, Types)], []] : (0, _utils.mapToTypeMap)(registry, Types));
57
57
  super(registry, Classes[0].length);
58
- const [, decodedLength] = (0, _util.isU8a)(value) ? (0, _utils.decodeU8a)(registry, this, value, Classes, false) : decodeTuple(registry, this, Classes, value);
59
- this.initialU8aLength = decodedLength;
58
+ this.initialU8aLength = ((0, _util.isU8a)(value) ? (0, _utils.decodeU8a)(registry, this, value, Classes) : decodeTuple(registry, this, value, Classes))[1];
60
59
  this.#Types = Classes;
61
60
  }
62
61
 
package/cjs/base/UInt.js CHANGED
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.UInt = void 0;
7
7
 
8
- var _AbstractInt = require("../abstract/AbstractInt");
8
+ var _Int = require("../abstract/Int");
9
9
 
10
10
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
11
11
  // SPDX-License-Identifier: Apache-2.0
@@ -20,7 +20,7 @@ var _AbstractInt = require("../abstract/AbstractInt");
20
20
  * is available here.
21
21
  * @noInheritDoc
22
22
  */
23
- class UInt extends _AbstractInt.AbstractInt {
23
+ class UInt extends _Int.AbstractInt {
24
24
  static with(bitLength, typeName) {
25
25
  return class extends UInt {
26
26
  constructor(registry, value) {
package/cjs/base/Vec.js CHANGED
@@ -8,7 +8,7 @@ exports.decodeVec = decodeVec;
8
8
 
9
9
  var _util = require("@polkadot/util");
10
10
 
11
- var _AbstractArray = require("../abstract/AbstractArray");
11
+ var _Array = require("../abstract/Array");
12
12
 
13
13
  var _utils = require("../utils");
14
14
 
@@ -61,7 +61,7 @@ function decodeVec(registry, result, value, startAt, Type) {
61
61
  */
62
62
 
63
63
 
64
- class Vec extends _AbstractArray.AbstractArray {
64
+ class Vec extends _Array.AbstractArray {
65
65
  #Type;
66
66
 
67
67
  constructor(registry, Type) {
@@ -73,8 +73,7 @@ class Vec extends _AbstractArray.AbstractArray {
73
73
  const [decodeFrom, length, startAt] = decodeVecLength(value);
74
74
  super(registry, length);
75
75
  this.#Type = definition || setDefinition((0, _utils.typeToConstructor)(registry, Type));
76
- const [decodedLength] = (0, _util.isU8a)(decodeFrom) ? (0, _utils.decodeU8aVec)(registry, this, decodeFrom, startAt, this.#Type) : decodeVec(registry, this, decodeFrom, startAt, this.#Type);
77
- this.initialU8aLength = decodedLength;
76
+ this.initialU8aLength = ((0, _util.isU8a)(decodeFrom) ? (0, _utils.decodeU8aVec)(registry, this, decodeFrom, startAt, this.#Type) : decodeVec(registry, this, decodeFrom, startAt, this.#Type))[0];
78
77
  }
79
78
 
80
79
  static with(Type) {
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.VecAny = void 0;
7
7
 
8
- var _AbstractArray = require("../abstract/AbstractArray");
8
+ var _Array = require("../abstract/Array");
9
9
 
10
10
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
11
11
  // SPDX-License-Identifier: Apache-2.0
@@ -17,7 +17,7 @@ var _AbstractArray = require("../abstract/AbstractArray");
17
17
  * a vector, this can be used to manage array-like structures with variable arguments of
18
18
  * any types
19
19
  */
20
- class VecAny extends _AbstractArray.AbstractArray {
20
+ class VecAny extends _Array.AbstractArray {
21
21
  /**
22
22
  * @description Returns the base runtime type name for this instance
23
23
  */
@@ -7,7 +7,7 @@ exports.VecFixed = void 0;
7
7
 
8
8
  var _util = require("@polkadot/util");
9
9
 
10
- var _AbstractArray = require("../abstract/AbstractArray");
10
+ var _Array = require("../abstract/Array");
11
11
 
12
12
  var _utils = require("../utils");
13
13
 
@@ -25,7 +25,7 @@ function noopSetDefinition(d) {
25
25
  */
26
26
 
27
27
 
28
- class VecFixed extends _AbstractArray.AbstractArray {
28
+ class VecFixed extends _Array.AbstractArray {
29
29
  #Type;
30
30
 
31
31
  constructor(registry, Type, length) {
@@ -36,8 +36,7 @@ class VecFixed extends _AbstractArray.AbstractArray {
36
36
  } = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
37
37
  super(registry, length);
38
38
  this.#Type = definition || setDefinition((0, _utils.typeToConstructor)(registry, Type));
39
- const [, decodedLengthNoOffset] = (0, _util.isU8a)(value) ? (0, _utils.decodeU8aVec)(registry, this, value, 0, this.#Type) : (0, _Vec.decodeVec)(registry, this, value, 0, this.#Type);
40
- this.initialU8aLength = decodedLengthNoOffset;
39
+ this.initialU8aLength = ((0, _util.isU8a)(value) ? (0, _utils.decodeU8aVec)(registry, this, value, 0, this.#Type) : (0, _Vec.decodeVec)(registry, this, value, 0, this.#Type))[1];
41
40
  }
42
41
 
43
42
  static with(Type, length) {
package/cjs/base/index.js CHANGED
@@ -3,12 +3,6 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "Base", {
7
- enumerable: true,
8
- get: function () {
9
- return _Base.Base;
10
- }
11
- });
12
6
  Object.defineProperty(exports, "Compact", {
13
7
  enumerable: true,
14
8
  get: function () {
@@ -82,8 +76,6 @@ Object.defineProperty(exports, "VecFixed", {
82
76
  }
83
77
  });
84
78
 
85
- var _Base = require("./Base");
86
-
87
79
  var _Compact = require("./Compact");
88
80
 
89
81
  var _DoNotConstruct = require("./DoNotConstruct");
@@ -38,7 +38,7 @@ function decodeBytesU8a(value) {
38
38
 
39
39
  class Bytes extends _Raw.Raw {
40
40
  constructor(registry, value) {
41
- const [u8a, decodedLength] = (0, _util.isU8a)(value) && !((0, _util.isCodec)(value) && value instanceof _Raw.Raw) ? decodeBytesU8a(value) : Array.isArray(value) || (0, _util.isString)(value) ? [(0, _util.u8aToU8a)(value), 0] : [value, 0];
41
+ const [u8a, decodedLength] = (0, _util.isU8a)(value) && !(value instanceof _Raw.Raw) ? decodeBytesU8a(value) : Array.isArray(value) || (0, _util.isString)(value) ? [(0, _util.u8aToU8a)(value), 0] : [value, 0];
42
42
  super(registry, u8a, decodedLength);
43
43
  }
44
44
  /**
@@ -7,7 +7,7 @@ exports.CodecMap = void 0;
7
7
 
8
8
  var _util = require("@polkadot/util");
9
9
 
10
- var _AbstractArray = require("../abstract/AbstractArray");
10
+ var _Array = require("../abstract/Array");
11
11
 
12
12
  var _Enum = require("../base/Enum");
13
13
 
@@ -44,7 +44,7 @@ function decodeMapFromMap(registry, KeyClass, ValClass, value) {
44
44
  const output = new Map();
45
45
 
46
46
  for (const [key, val] of value.entries()) {
47
- const isComplex = KeyClass.prototype instanceof _AbstractArray.AbstractArray || KeyClass.prototype instanceof _Struct.Struct || KeyClass.prototype instanceof _Enum.Enum;
47
+ const isComplex = KeyClass.prototype instanceof _Array.AbstractArray || KeyClass.prototype instanceof _Struct.Struct || KeyClass.prototype instanceof _Enum.Enum;
48
48
 
49
49
  try {
50
50
  output.set(key instanceof KeyClass ? key : new KeyClass(registry, isComplex ? JSON.parse(key) : key), val instanceof ValClass ? val : new ValClass(registry, val));
@@ -29,6 +29,7 @@ function decodeU8a(registry, value) {
29
29
  class OptionBool extends _Option.Option {
30
30
  constructor(registry, value) {
31
31
  super(registry, _Bool.bool, (0, _util.isU8a)(value) || (0, _util.isHex)(value) ? decodeU8a(registry, (0, _util.u8aToU8a)(value)) : value);
32
+ this.initialU8aLength = 1;
32
33
  }
33
34
  /**
34
35
  * @description The length of the value when encoded as a Uint8Array
@@ -38,14 +39,6 @@ class OptionBool extends _Option.Option {
38
39
  get encodedLength() {
39
40
  return 1;
40
41
  }
41
- /**
42
- * @description The length of the initial encoded value (Only available when constructed from a Uint8Array)
43
- */
44
-
45
-
46
- get initialU8aLength() {
47
- return 1;
48
- }
49
42
  /**
50
43
  * @description Checks if the value is an empty value (always false)
51
44
  */
@@ -82,7 +82,6 @@ function decodeStructFromObject(registry, _ref, value, jsonMap) {
82
82
 
83
83
 
84
84
  class Struct extends Map {
85
- #registry;
86
85
  #jsonMap;
87
86
  #Types;
88
87
 
@@ -93,10 +92,10 @@ class Struct extends Map {
93
92
  setDefinition = noopSetDefinition
94
93
  } = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
95
94
  const typeMap = definition || setDefinition((0, _utils.mapToTypeMap)(registry, Types));
96
- const [decoded, decodedLength] = (0, _util.isU8a)(value) || (0, _util.isHex)(value) ? (0, _utils.decodeU8a)(registry, new Array(typeMap[0].length), (0, _util.u8aToU8a)(value), typeMap, true) : value instanceof Struct ? [value, 0] : decodeStructFromObject(registry, typeMap, value || {}, jsonMap);
95
+ const [decoded, decodedLength] = (0, _util.isU8a)(value) || (0, _util.isHex)(value) ? (0, _utils.decodeU8aStruct)(registry, new Array(typeMap[0].length), (0, _util.u8aToU8a)(value), typeMap) : value instanceof Struct ? [value, 0] : decodeStructFromObject(registry, typeMap, value || {}, jsonMap);
97
96
  super(decoded);
98
- this.#registry = registry;
99
97
  this.initialU8aLength = decodedLength;
98
+ this.registry = registry;
100
99
  this.#jsonMap = jsonMap;
101
100
  this.#Types = typeMap;
102
101
  }
@@ -181,10 +180,6 @@ class Struct extends Map {
181
180
  get hash() {
182
181
  return this.registry.hash(this.toU8a());
183
182
  }
184
-
185
- get registry() {
186
- return this.#registry;
187
- }
188
183
  /**
189
184
  * @description Compares the value of the input to see if there is a match
190
185
  */
@@ -48,14 +48,13 @@ function decodeText(value) {
48
48
 
49
49
 
50
50
  class Text extends String {
51
- #initialU8aLength;
52
51
  #override = null;
53
52
 
54
53
  constructor(registry, value) {
55
54
  const [str, decodedLength] = decodeText(value);
56
55
  super(str);
57
56
  this.registry = registry;
58
- this.#initialU8aLength = decodedLength;
57
+ this.initialU8aLength = decodedLength;
59
58
  }
60
59
  /**
61
60
  * @description The length of the value when encoded as a Uint8Array
@@ -65,14 +64,6 @@ class Text extends String {
65
64
  get encodedLength() {
66
65
  return this.toU8a().length;
67
66
  }
68
- /**
69
- * @description The length of the initial encoded value (Only available when constructed from a Uint8Array)
70
- */
71
-
72
-
73
- get initialU8aLength() {
74
- return this.#initialU8aLength;
75
- }
76
67
  /**
77
68
  * @description returns a hash of the contents
78
69
  */
@@ -11,6 +11,6 @@ const packageInfo = {
11
11
  name: '@polkadot/types-codec',
12
12
  path: typeof __dirname === 'string' ? __dirname : 'auto',
13
13
  type: 'cjs',
14
- version: '8.8.3-2'
14
+ version: '8.8.3-5'
15
15
  };
16
16
  exports.packageInfo = packageInfo;
@@ -4,24 +4,31 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.decodeU8a = decodeU8a;
7
+ exports.decodeU8aStruct = decodeU8aStruct;
7
8
  exports.decodeU8aVec = decodeU8aVec;
8
9
 
9
10
  var _util = require("@polkadot/util");
10
11
 
11
12
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
12
13
  // SPDX-License-Identifier: Apache-2.0
13
- function formatFailure(error, type, u8a, key) {
14
- return `decodeU8a: failed at ${(0, _util.u8aToHex)(u8a)}…${key ? ` on ${key}` : ''}${type ? `: ${type}` : ''}:: ${error.message}`;
15
- }
16
14
 
17
- function getRawType(registry, Type) {
15
+ /** @internal */
16
+ function formatFailure(registry, _ref, u8a, i, count, Type, key) {
17
+ let {
18
+ message
19
+ } = _ref;
20
+ let type = '';
21
+
18
22
  try {
19
- return new Type(registry).toRawType();
20
- } catch {
21
- return null;
23
+ type = `: ${new Type(registry).toRawType()}`;
24
+ } catch {// ignore
22
25
  }
26
+
27
+ return `decodeU8a: failed at ${(0, _util.u8aToHex)(u8a.subarray(0, 16))}…${key ? ` on ${key}` : ''} (index ${i}/${count})${type}:: ${message}`;
23
28
  }
24
29
  /**
30
+ * @internal
31
+ *
25
32
  * Given an u8a, and an array of Type constructors, decode the u8a against the
26
33
  * types, and return an array of decoded values.
27
34
  *
@@ -31,38 +38,74 @@ function getRawType(registry, Type) {
31
38
  */
32
39
 
33
40
 
34
- function decodeU8a(registry, result, u8a, _ref, withZip) {
35
- let [Types, keys] = _ref;
41
+ function decodeU8a(registry, result, u8a, _ref2) {
42
+ let [Types, keys] = _ref2;
36
43
  const count = result.length;
37
44
  let offset = 0;
45
+ let i = 0;
38
46
 
39
- for (let i = 0; i < count; i++) {
40
- try {
47
+ try {
48
+ while (i < count) {
41
49
  const value = new Types[i](registry, u8a.subarray(offset));
42
50
  offset += value.initialU8aLength || value.encodedLength;
43
- result[i] = withZip ? [keys[i], value] : value;
44
- } catch (error) {
45
- throw new Error(formatFailure(error, getRawType(registry, Types[i]), u8a.subarray(offset, offset + 16), keys[i]));
51
+ result[i] = value;
52
+ i++;
46
53
  }
54
+ } catch (error) {
55
+ throw new Error(formatFailure(registry, error, u8a.subarray(offset), i, count, Types[i], keys[i]));
47
56
  }
48
57
 
49
58
  return [result, offset];
50
- } // Split from decodeU8a since this is specialized to 1 instance ... yes duplication, but
51
- // since we have to do less checks (and these are intensive anyway), much faster
59
+ }
60
+ /**
61
+ * @internal
62
+ *
63
+ * Split from decodeU8a since this is specialized to zip returns ... while we duplicate, this
64
+ * is all on the hot-path, so it is not great, however there is (some) method behind the madness
65
+ */
66
+
67
+
68
+ function decodeU8aStruct(registry, result, u8a, _ref3) {
69
+ let [Types, keys] = _ref3;
70
+ const count = result.length;
71
+ let offset = 0;
72
+ let i = 0;
73
+
74
+ try {
75
+ while (i < count) {
76
+ const value = new Types[i](registry, u8a.subarray(offset));
77
+ offset += value.initialU8aLength || value.encodedLength;
78
+ result[i] = [keys[i], value];
79
+ i++;
80
+ }
81
+ } catch (error) {
82
+ throw new Error(formatFailure(registry, error, u8a.subarray(offset), i, count, Types[i], keys[i]));
83
+ }
84
+
85
+ return [result, offset];
86
+ }
87
+ /**
88
+ * @internal
89
+ *
90
+ * Split from decodeU8a since this is specialized to 1 instance ... while we duplicate, this
91
+ * is all on the hot-path, so it is not great, however there is (some) method behind the madness
92
+ */
52
93
 
53
94
 
54
95
  function decodeU8aVec(registry, result, u8a, startAt, Type) {
55
96
  const count = result.length;
56
97
  let offset = startAt;
98
+ let i = 0;
57
99
 
58
- for (let i = 0; i < count; i++) {
59
- try {
100
+ try {
101
+ while (i < count) {
60
102
  const value = new Type(registry, u8a.subarray(offset));
61
103
  offset += value.initialU8aLength || value.encodedLength;
62
104
  result[i] = value;
63
- } catch (error) {
64
- throw new Error(formatFailure(error, getRawType(registry, Type), u8a.subarray(offset, offset + 16)));
105
+ i++;
65
106
  }
107
+ } catch (error) {
108
+ throw new Error(formatFailure(registry, error, u8a.subarray(offset), i, count, Type));
66
109
  }
67
110
 
68
111
  return [offset, offset - startAt];
@@ -27,6 +27,12 @@ Object.defineProperty(exports, "decodeU8a", {
27
27
  return _decodeU8a.decodeU8a;
28
28
  }
29
29
  });
30
+ Object.defineProperty(exports, "decodeU8aStruct", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _decodeU8a.decodeU8aStruct;
34
+ }
35
+ });
30
36
  Object.defineProperty(exports, "decodeU8aVec", {
31
37
  enumerable: true,
32
38
  get: function () {
@@ -18,7 +18,7 @@ function mapToTypeMap(registry, input) {
18
18
  const count = entries.length;
19
19
  const output = [new Array(count), new Array(count)];
20
20
 
21
- for (let i = 0; i < entries.length; i++) {
21
+ for (let i = 0; i < count; i++) {
22
22
  output[1][i] = entries[i][0];
23
23
  output[0][i] = (0, _typeToConstructor.typeToConstructor)(registry, entries[i][1]);
24
24
  }
package/extended/Bytes.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import { assert, compactAddLength, compactFromU8aLim, compactToU8a, isCodec, isString, isU8a, u8aToU8a } from '@polkadot/util';
3
+ import { assert, compactAddLength, compactFromU8aLim, compactToU8a, isString, isU8a, u8aToU8a } from '@polkadot/util';
4
4
  import { Raw } from "../native/Raw.js"; // Bytes are used for things like on-chain code, so it has a healthy limit
5
5
 
6
6
  const MAX_LENGTH = 10 * 1024 * 1024;
@@ -29,7 +29,7 @@ function decodeBytesU8a(value) {
29
29
 
30
30
  export class Bytes extends Raw {
31
31
  constructor(registry, value) {
32
- const [u8a, decodedLength] = isU8a(value) && !(isCodec(value) && value instanceof Raw) ? decodeBytesU8a(value) : Array.isArray(value) || isString(value) ? [u8aToU8a(value), 0] : [value, 0];
32
+ const [u8a, decodedLength] = isU8a(value) && !(value instanceof Raw) ? decodeBytesU8a(value) : Array.isArray(value) || isString(value) ? [u8aToU8a(value), 0] : [value, 0];
33
33
  super(registry, u8a, decodedLength);
34
34
  }
35
35
  /**
package/extended/Map.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { compactFromU8aLim, compactToU8a, isHex, isObject, isU8a, logger, stringify, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util';
4
- import { AbstractArray } from "../abstract/AbstractArray.js";
4
+ import { AbstractArray } from "../abstract/Array.js";
5
5
  import { Enum } from "../base/Enum.js";
6
6
  import { Struct } from "../native/Struct.js";
7
7
  import { compareMap, decodeU8a, sortMap, typeToConstructor } from "../utils/index.js";