@polkadot/types-codec 7.11.2-0 → 7.11.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.
package/base/Option.cjs CHANGED
@@ -13,23 +13,33 @@ var _Null = require("./Null.cjs");
13
13
 
14
14
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
15
15
  // SPDX-License-Identifier: Apache-2.0
16
+ class None extends _Null.Null {
17
+ /**
18
+ * @description Returns the base runtime type name for this instance
19
+ */
20
+ toRawType() {
21
+ return 'None';
22
+ }
16
23
 
24
+ }
17
25
  /** @internal */
26
+
27
+
18
28
  function decodeOption(registry, Type, value) {
19
29
  // In the case of an option, unwrap the inner
20
30
  if (value instanceof Option) {
21
31
  value = value.value;
22
32
  }
23
33
 
24
- if ((0, _util.isNull)(value) || (0, _util.isUndefined)(value) || value instanceof _Null.Null || value === '0x') {
25
- return new _Null.Null(registry);
34
+ if ((0, _util.isNull)(value) || (0, _util.isUndefined)(value) || value === '0x') {
35
+ return new None(registry);
26
36
  } else if (value instanceof Type) {
27
37
  // don't re-create, use as it (which also caters for derived types)
28
38
  return value;
29
39
  } else if ((0, _util.isU8a)(value)) {
30
40
  // the isU8a check happens last in the if-tree - since the wrapped value
31
41
  // may be an instance of it, so Type and Option checks go in first
32
- return !value.length || value[0] === 0 ? new _Null.Null(registry) : new Type(registry, value.subarray(1));
42
+ return !value.length || value[0] === 0 ? new None(registry) : new Type(registry, value.subarray(1));
33
43
  }
34
44
 
35
45
  return new Type(registry, value);
@@ -51,12 +61,12 @@ class Option {
51
61
 
52
62
  constructor(registry, typeName, value) {
53
63
  const Type = (0, _index.typeToConstructor)(registry, typeName);
54
- const decoded = (0, _util.isU8a)(value) && value.length && !(0, _util.isCodec)(value) ? value[0] === 0 ? new _Null.Null(registry) : new Type(registry, value.subarray(1)) : decodeOption(registry, Type, value);
64
+ const decoded = (0, _util.isU8a)(value) && value.length && !(0, _util.isCodec)(value) ? value[0] === 0 ? new None(registry) : new Type(registry, value.subarray(1)) : decodeOption(registry, Type, value);
55
65
  this.registry = registry;
56
66
  this.#Type = Type;
57
67
  this.#raw = decoded;
58
68
 
59
- if (decoded.initialU8aLength) {
69
+ if (decoded && decoded.initialU8aLength) {
60
70
  this.#initialU8aLength = 1 + decoded.initialU8aLength;
61
71
  }
62
72
  }
@@ -108,7 +118,7 @@ class Option {
108
118
 
109
119
 
110
120
  get isNone() {
111
- return this.#raw instanceof _Null.Null;
121
+ return this.#raw instanceof None;
112
122
  }
113
123
  /**
114
124
  * @description Checks if the Option has a value
package/base/Option.js CHANGED
@@ -3,23 +3,34 @@
3
3
  import { assert, isCodec, isNull, isU8a, isUndefined, u8aToHex } from '@polkadot/util';
4
4
  import { typeToConstructor } from "../utils/index.js";
5
5
  import { Null } from "./Null.js";
6
+
7
+ class None extends Null {
8
+ /**
9
+ * @description Returns the base runtime type name for this instance
10
+ */
11
+ toRawType() {
12
+ return 'None';
13
+ }
14
+
15
+ }
6
16
  /** @internal */
7
17
 
18
+
8
19
  function decodeOption(registry, Type, value) {
9
20
  // In the case of an option, unwrap the inner
10
21
  if (value instanceof Option) {
11
22
  value = value.value;
12
23
  }
13
24
 
14
- if (isNull(value) || isUndefined(value) || value instanceof Null || value === '0x') {
15
- return new Null(registry);
25
+ if (isNull(value) || isUndefined(value) || value === '0x') {
26
+ return new None(registry);
16
27
  } else if (value instanceof Type) {
17
28
  // don't re-create, use as it (which also caters for derived types)
18
29
  return value;
19
30
  } else if (isU8a(value)) {
20
31
  // the isU8a check happens last in the if-tree - since the wrapped value
21
32
  // may be an instance of it, so Type and Option checks go in first
22
- return !value.length || value[0] === 0 ? new Null(registry) : new Type(registry, value.subarray(1));
33
+ return !value.length || value[0] === 0 ? new None(registry) : new Type(registry, value.subarray(1));
23
34
  }
24
35
 
25
36
  return new Type(registry, value);
@@ -41,12 +52,12 @@ export class Option {
41
52
 
42
53
  constructor(registry, typeName, value) {
43
54
  const Type = typeToConstructor(registry, typeName);
44
- const decoded = isU8a(value) && value.length && !isCodec(value) ? value[0] === 0 ? new Null(registry) : new Type(registry, value.subarray(1)) : decodeOption(registry, Type, value);
55
+ const decoded = isU8a(value) && value.length && !isCodec(value) ? value[0] === 0 ? new None(registry) : new Type(registry, value.subarray(1)) : decodeOption(registry, Type, value);
45
56
  this.registry = registry;
46
57
  this.#Type = Type;
47
58
  this.#raw = decoded;
48
59
 
49
- if (decoded.initialU8aLength) {
60
+ if (decoded && decoded.initialU8aLength) {
50
61
  this.#initialU8aLength = 1 + decoded.initialU8aLength;
51
62
  }
52
63
  }
@@ -98,7 +109,7 @@ export class Option {
98
109
 
99
110
 
100
111
  get isNone() {
101
- return this.#raw instanceof Null;
112
+ return this.#raw instanceof None;
102
113
  }
103
114
  /**
104
115
  * @description Checks if the Option has a value
package/package.json CHANGED
@@ -20,7 +20,7 @@
20
20
  "./detectPackage.cjs"
21
21
  ],
22
22
  "type": "module",
23
- "version": "7.11.2-0",
23
+ "version": "7.11.2-1",
24
24
  "main": "index.cjs",
25
25
  "module": "index.js",
26
26
  "types": "index.d.ts",
package/packageInfo.cjs CHANGED
@@ -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: '7.11.2-0'
14
+ version: '7.11.2-1'
15
15
  };
16
16
  exports.packageInfo = packageInfo;
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 : 'auto',
7
7
  type: 'esm',
8
- version: '7.11.2-0'
8
+ version: '7.11.2-1'
9
9
  };