@polkadot/types-codec 8.12.2 → 8.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/abstract/Array.js CHANGED
@@ -118,7 +118,7 @@ export class AbstractArray extends Array {
118
118
  const result = new Array(this.length);
119
119
 
120
120
  for (let i = 0; i < this.length; i++) {
121
- result[i] = this[i].toHuman(isExtended);
121
+ result[i] = this[i] && this[i].toHuman(isExtended);
122
122
  }
123
123
 
124
124
  return result;
@@ -132,7 +132,9 @@ export class AbstractArray extends Array {
132
132
  const result = new Array(this.length);
133
133
 
134
134
  for (let i = 0; i < this.length; i++) {
135
- result[i] = this[i].toJSON();
135
+ // We actually log inside the U8a decoding and use JSON.stringify(...), which
136
+ // means that the Vec may be partially populated (same applies to toHuman, same check)
137
+ result[i] = this[i] && this[i].toJSON();
136
138
  }
137
139
 
138
140
  return result;
@@ -127,7 +127,7 @@ class AbstractArray extends Array {
127
127
  const result = new Array(this.length);
128
128
 
129
129
  for (let i = 0; i < this.length; i++) {
130
- result[i] = this[i].toHuman(isExtended);
130
+ result[i] = this[i] && this[i].toHuman(isExtended);
131
131
  }
132
132
 
133
133
  return result;
@@ -141,7 +141,9 @@ class AbstractArray extends Array {
141
141
  const result = new Array(this.length);
142
142
 
143
143
  for (let i = 0; i < this.length; i++) {
144
- result[i] = this[i].toJSON();
144
+ // We actually log inside the U8a decoding and use JSON.stringify(...), which
145
+ // means that the Vec may be partially populated (same applies to toHuman, same check)
146
+ result[i] = this[i] && this[i].toJSON();
145
147
  }
146
148
 
147
149
  return result;
@@ -267,7 +267,9 @@ class Struct extends Map {
267
267
  const json = {};
268
268
 
269
269
  for (const [k, v] of this.entries()) {
270
- const jsonKey = this.#jsonMap.get(k) || k;
270
+ const jsonKey = this.#jsonMap.get(k) || k; // We actually log inside the U8a decoding and use JSON.stringify(...), which
271
+ // means that the Vec may be partially populated (same applies to toHuman, same check)
272
+
271
273
  json[jsonKey] = v && v.toJSON();
272
274
  }
273
275
 
package/cjs/package.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
2
  "type": "commonjs"
3
- }
3
+ }
@@ -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.12.2'
14
+ version: '8.13.1'
15
15
  };
16
16
  exports.packageInfo = packageInfo;
@@ -13,7 +13,7 @@ var _util = require("@polkadot/util");
13
13
  // SPDX-License-Identifier: Apache-2.0
14
14
 
15
15
  /** @internal */
16
- function formatFailure(registry, _ref, u8a, i, count, Type, key) {
16
+ function formatFailure(registry, result, _ref, u8a, i, count, Type, key) {
17
17
  let {
18
18
  message
19
19
  } = _ref;
@@ -22,7 +22,8 @@ function formatFailure(registry, _ref, u8a, i, count, Type, key) {
22
22
  try {
23
23
  type = `: ${new Type(registry).toRawType()}`;
24
24
  } catch {// ignore
25
- }
25
+ } // console.error(JSON.stringify(result, null, 2));
26
+
26
27
 
27
28
  return `decodeU8a: failed at ${(0, _util.u8aToHex)(u8a.subarray(0, 16))}…${key ? ` on ${key}` : ''} (index ${i}/${count})${type}:: ${message}`;
28
29
  }
@@ -52,7 +53,7 @@ function decodeU8a(registry, result, u8a, _ref2) {
52
53
  i++;
53
54
  }
54
55
  } catch (error) {
55
- throw new Error(formatFailure(registry, error, u8a.subarray(offset), i, count, Types[i], keys[i]));
56
+ throw new Error(formatFailure(registry, result, error, u8a.subarray(offset), i, count, Types[i], keys[i]));
56
57
  }
57
58
 
58
59
  return [result, offset];
@@ -79,7 +80,7 @@ function decodeU8aStruct(registry, result, u8a, _ref3) {
79
80
  i++;
80
81
  }
81
82
  } catch (error) {
82
- throw new Error(formatFailure(registry, error, u8a.subarray(offset), i, count, Types[i], keys[i]));
83
+ throw new Error(formatFailure(registry, result, error, u8a.subarray(offset), i, count, Types[i], keys[i]));
83
84
  }
84
85
 
85
86
  return [result, offset];
@@ -105,7 +106,7 @@ function decodeU8aVec(registry, result, u8a, startAt, Type) {
105
106
  i++;
106
107
  }
107
108
  } catch (error) {
108
- throw new Error(formatFailure(registry, error, u8a.subarray(offset), i, count, Type));
109
+ throw new Error(formatFailure(registry, result, error, u8a.subarray(offset), i, count, Type));
109
110
  }
110
111
 
111
112
  return [offset, offset - startAt];
package/native/Struct.js CHANGED
@@ -256,7 +256,9 @@ export class Struct extends Map {
256
256
  const json = {};
257
257
 
258
258
  for (const [k, v] of this.entries()) {
259
- const jsonKey = this.#jsonMap.get(k) || k;
259
+ const jsonKey = this.#jsonMap.get(k) || k; // We actually log inside the U8a decoding and use JSON.stringify(...), which
260
+ // means that the Vec may be partially populated (same applies to toHuman, same check)
261
+
260
262
  json[jsonKey] = v && v.toJSON();
261
263
  }
262
264
 
package/package.json CHANGED
@@ -20,7 +20,7 @@
20
20
  "./cjs/detectPackage.js"
21
21
  ],
22
22
  "type": "module",
23
- "version": "8.12.2",
23
+ "version": "8.13.1",
24
24
  "main": "./cjs/index.js",
25
25
  "module": "./index.js",
26
26
  "types": "./index.d.ts",
@@ -438,4 +438,4 @@
438
438
  "@polkadot/util": "^10.0.2",
439
439
  "@polkadot/x-bigint": "^10.0.2"
440
440
  }
441
- }
441
+ }
package/packageInfo.js CHANGED
@@ -5,5 +5,5 @@ export const packageInfo = {
5
5
  name: '@polkadot/types-codec',
6
6
  path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
7
7
  type: 'esm',
8
- version: '8.12.2'
8
+ version: '8.13.1'
9
9
  };
@@ -3,7 +3,7 @@
3
3
  import { u8aToHex } from '@polkadot/util';
4
4
  /** @internal */
5
5
 
6
- function formatFailure(registry, {
6
+ function formatFailure(registry, result, {
7
7
  message
8
8
  }, u8a, i, count, Type, key) {
9
9
  let type = '';
@@ -11,7 +11,8 @@ function formatFailure(registry, {
11
11
  try {
12
12
  type = `: ${new Type(registry).toRawType()}`;
13
13
  } catch {// ignore
14
- }
14
+ } // console.error(JSON.stringify(result, null, 2));
15
+
15
16
 
16
17
  return `decodeU8a: failed at ${u8aToHex(u8a.subarray(0, 16))}…${key ? ` on ${key}` : ''} (index ${i}/${count})${type}:: ${message}`;
17
18
  }
@@ -40,7 +41,7 @@ export function decodeU8a(registry, result, u8a, [Types, keys]) {
40
41
  i++;
41
42
  }
42
43
  } catch (error) {
43
- throw new Error(formatFailure(registry, error, u8a.subarray(offset), i, count, Types[i], keys[i]));
44
+ throw new Error(formatFailure(registry, result, error, u8a.subarray(offset), i, count, Types[i], keys[i]));
44
45
  }
45
46
 
46
47
  return [result, offset];
@@ -65,7 +66,7 @@ export function decodeU8aStruct(registry, result, u8a, [Types, keys]) {
65
66
  i++;
66
67
  }
67
68
  } catch (error) {
68
- throw new Error(formatFailure(registry, error, u8a.subarray(offset), i, count, Types[i], keys[i]));
69
+ throw new Error(formatFailure(registry, result, error, u8a.subarray(offset), i, count, Types[i], keys[i]));
69
70
  }
70
71
 
71
72
  return [result, offset];
@@ -90,7 +91,7 @@ export function decodeU8aVec(registry, result, u8a, startAt, Type) {
90
91
  i++;
91
92
  }
92
93
  } catch (error) {
93
- throw new Error(formatFailure(registry, error, u8a.subarray(offset), i, count, Type));
94
+ throw new Error(formatFailure(registry, result, error, u8a.subarray(offset), i, count, Type));
94
95
  }
95
96
 
96
97
  return [offset, offset - startAt];