@polkadot/types-codec 8.7.2-7 → 8.8.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.js CHANGED
@@ -21,16 +21,23 @@ class None extends Null {
21
21
 
22
22
 
23
23
  function decodeOption(registry, Type, value) {
24
- // In the case of an option, unwrap the inner
25
- if (value instanceof Option) {
26
- value = value.value;
27
- }
28
-
29
- if (isNull(value) || isUndefined(value) || value === '0x' || value instanceof None) {
30
- return new None(registry);
31
- } else if (value instanceof Type) {
24
+ if (value instanceof Type) {
32
25
  // don't re-create, use as it (which also caters for derived types)
33
26
  return value;
27
+ } else if (value instanceof Option) {
28
+ if (value.value instanceof Type) {
29
+ // same instance, return it
30
+ return value.value;
31
+ } else if (value.isNone) {
32
+ // internal is None, we are also none
33
+ return new None(registry);
34
+ } // convert the actual value into known
35
+
36
+
37
+ return new Type(registry, value.value);
38
+ } else if (isNull(value) || isUndefined(value) || value === '0x' || value instanceof None) {
39
+ // anyhting empty we pass as-is
40
+ return new None(registry);
34
41
  } else if (isU8a(value)) {
35
42
  // the isU8a check happens last in the if-tree - since the wrapped value
36
43
  // may be an instance of it, so Type and Option checks go in first
@@ -30,16 +30,23 @@ class None extends _Null.Null {
30
30
 
31
31
 
32
32
  function decodeOption(registry, Type, value) {
33
- // In the case of an option, unwrap the inner
34
- if (value instanceof Option) {
35
- value = value.value;
36
- }
37
-
38
- if ((0, _util.isNull)(value) || (0, _util.isUndefined)(value) || value === '0x' || value instanceof None) {
39
- return new None(registry);
40
- } else if (value instanceof Type) {
33
+ if (value instanceof Type) {
41
34
  // don't re-create, use as it (which also caters for derived types)
42
35
  return value;
36
+ } else if (value instanceof Option) {
37
+ if (value.value instanceof Type) {
38
+ // same instance, return it
39
+ return value.value;
40
+ } else if (value.isNone) {
41
+ // internal is None, we are also none
42
+ return new None(registry);
43
+ } // convert the actual value into known
44
+
45
+
46
+ return new Type(registry, value.value);
47
+ } else if ((0, _util.isNull)(value) || (0, _util.isUndefined)(value) || value === '0x' || value instanceof None) {
48
+ // anyhting empty we pass as-is
49
+ return new None(registry);
43
50
  } else if ((0, _util.isU8a)(value)) {
44
51
  // the isU8a check happens last in the if-tree - since the wrapped value
45
52
  // may be an instance of it, so Type and Option checks go in first
@@ -19,18 +19,17 @@ class Range extends _Tuple.Tuple {
19
19
  #rangeName;
20
20
 
21
21
  constructor(registry, Type, value) {
22
- let rangeName = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'Range';
23
- super(registry, {
24
- end: Type,
25
- start: Type
26
- }, value);
22
+ let {
23
+ rangeName = 'Range'
24
+ } = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
25
+ super(registry, [Type, Type], value);
27
26
  this.#rangeName = rangeName;
28
27
  }
29
28
 
30
- static with(Types) {
29
+ static with(Type) {
31
30
  return class extends Range {
32
31
  constructor(registry, value) {
33
- super(registry, Types, value);
32
+ super(registry, Type, value);
34
33
  }
35
34
 
36
35
  };
@@ -11,7 +11,9 @@ var _Range = require("./Range");
11
11
  // SPDX-License-Identifier: Apache-2.0
12
12
  class RangeInclusive extends _Range.Range {
13
13
  constructor(registry, Type, value) {
14
- super(registry, Type, value, 'RangeInclusive');
14
+ super(registry, Type, value, {
15
+ rangeName: 'RangeInclusive'
16
+ });
15
17
  }
16
18
 
17
19
  static with(Type) {
@@ -37,7 +37,9 @@ class WrapperKeepOpaque extends _Bytes.Bytes {
37
37
  #opaqueName;
38
38
 
39
39
  constructor(registry, typeName, value) {
40
- let opaqueName = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'WrapperKeepOpaque';
40
+ let {
41
+ opaqueName = 'WrapperKeepOpaque'
42
+ } = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
41
43
  const [Type, decoded, u8a] = decodeRaw(registry, typeName, value);
42
44
  super(registry, u8a);
43
45
  this.#Type = Type;
@@ -11,7 +11,9 @@ var _WrapperKeepOpaque = require("./WrapperKeepOpaque");
11
11
  // SPDX-License-Identifier: Apache-2.0
12
12
  class WrapperOpaque extends _WrapperKeepOpaque.WrapperKeepOpaque {
13
13
  constructor(registry, typeName, value) {
14
- super(registry, typeName, value, 'WrapperOpaque');
14
+ super(registry, typeName, value, {
15
+ opaqueName: 'WrapperOpaque'
16
+ });
15
17
  }
16
18
 
17
19
  static with(Type) {
@@ -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.7.2-7'
14
+ version: '8.8.1'
15
15
  };
16
16
  exports.packageInfo = packageInfo;
@@ -1,6 +1,9 @@
1
1
  import type { AnyTuple, CodecClass, INumber, Registry } from '../types';
2
2
  import { Tuple } from '../base/Tuple';
3
3
  declare type RangeType = 'Range' | 'RangeInclusive';
4
+ interface Options {
5
+ rangeName?: RangeType;
6
+ }
4
7
  /**
5
8
  * @name Range
6
9
  * @description
@@ -8,8 +11,8 @@ declare type RangeType = 'Range' | 'RangeInclusive';
8
11
  */
9
12
  export declare class Range<T extends INumber> extends Tuple {
10
13
  #private;
11
- constructor(registry: Registry, Type: CodecClass<T> | string, value?: AnyTuple, rangeName?: RangeType);
12
- static with<T extends INumber>(Types: CodecClass<T> | string): CodecClass<Range<T>>;
14
+ constructor(registry: Registry, Type: CodecClass<T> | string, value?: AnyTuple, { rangeName }?: Options);
15
+ static with<T extends INumber>(Type: CodecClass<T> | string): CodecClass<Range<T>>;
13
16
  /**
14
17
  * @description Returns the starting range value
15
18
  */
package/extended/Range.js CHANGED
@@ -10,18 +10,17 @@ import { Tuple } from "../base/Tuple.js";
10
10
  export class Range extends Tuple {
11
11
  #rangeName;
12
12
 
13
- constructor(registry, Type, value, rangeName = 'Range') {
14
- super(registry, {
15
- end: Type,
16
- start: Type
17
- }, value);
13
+ constructor(registry, Type, value, {
14
+ rangeName = 'Range'
15
+ } = {}) {
16
+ super(registry, [Type, Type], value);
18
17
  this.#rangeName = rangeName;
19
18
  }
20
19
 
21
- static with(Types) {
20
+ static with(Type) {
22
21
  return class extends Range {
23
22
  constructor(registry, value) {
24
- super(registry, Types, value);
23
+ super(registry, Type, value);
25
24
  }
26
25
 
27
26
  };
@@ -3,7 +3,9 @@
3
3
  import { Range } from "./Range.js";
4
4
  export class RangeInclusive extends Range {
5
5
  constructor(registry, Type, value) {
6
- super(registry, Type, value, 'RangeInclusive');
6
+ super(registry, Type, value, {
7
+ rangeName: 'RangeInclusive'
8
+ });
7
9
  }
8
10
 
9
11
  static with(Type) {
@@ -1,9 +1,12 @@
1
1
  import type { AnyJson, Codec, CodecClass, Inspect, Registry } from '../types';
2
2
  import { Bytes } from './Bytes';
3
3
  declare type OpaqueName = 'WrapperKeepOpaque' | 'WrapperOpaque';
4
+ interface Options {
5
+ opaqueName?: OpaqueName;
6
+ }
4
7
  export declare class WrapperKeepOpaque<T extends Codec> extends Bytes {
5
8
  #private;
6
- constructor(registry: Registry, typeName: CodecClass<T> | string, value?: unknown, opaqueName?: OpaqueName);
9
+ constructor(registry: Registry, typeName: CodecClass<T> | string, value?: unknown, { opaqueName }?: Options);
7
10
  static with<T extends Codec>(Type: CodecClass<T> | string): CodecClass<WrapperKeepOpaque<T>>;
8
11
  /**
9
12
  * @description Checks if the wrapper is decodable
@@ -26,7 +26,9 @@ export class WrapperKeepOpaque extends Bytes {
26
26
  #decoded;
27
27
  #opaqueName;
28
28
 
29
- constructor(registry, typeName, value, opaqueName = 'WrapperKeepOpaque') {
29
+ constructor(registry, typeName, value, {
30
+ opaqueName = 'WrapperKeepOpaque'
31
+ } = {}) {
30
32
  const [Type, decoded, u8a] = decodeRaw(registry, typeName, value);
31
33
  super(registry, u8a);
32
34
  this.#Type = Type;
@@ -3,7 +3,9 @@
3
3
  import { WrapperKeepOpaque } from "./WrapperKeepOpaque.js";
4
4
  export class WrapperOpaque extends WrapperKeepOpaque {
5
5
  constructor(registry, typeName, value) {
6
- super(registry, typeName, value, 'WrapperOpaque');
6
+ super(registry, typeName, value, {
7
+ opaqueName: 'WrapperOpaque'
8
+ });
7
9
  }
8
10
 
9
11
  static with(Type) {
package/package.json CHANGED
@@ -20,7 +20,7 @@
20
20
  "./cjs/detectPackage.js"
21
21
  ],
22
22
  "type": "module",
23
- "version": "8.7.2-7",
23
+ "version": "8.8.1",
24
24
  "main": "./cjs/index.js",
25
25
  "module": "./index.js",
26
26
  "types": "./index.d.ts",
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.7.2-7'
8
+ version: '8.8.1'
9
9
  };