@polkadot/types-codec 10.0.1 → 10.1.2

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 (171) hide show
  1. package/abstract/Array.d.ts +1 -1
  2. package/abstract/Array.js +0 -4
  3. package/abstract/Base.d.ts +1 -1
  4. package/abstract/Base.js +18 -19
  5. package/abstract/Int.d.ts +1 -1
  6. package/abstract/Int.js +11 -14
  7. package/abstract/Object.d.ts +1 -1
  8. package/abstract/Object.js +0 -5
  9. package/abstract/index.d.ts +3 -3
  10. package/base/Compact.d.ts +1 -1
  11. package/base/Compact.js +24 -25
  12. package/base/DoNotConstruct.d.ts +1 -1
  13. package/base/DoNotConstruct.js +19 -19
  14. package/base/Enum.d.ts +1 -1
  15. package/base/Enum.js +54 -53
  16. package/base/Int.d.ts +2 -2
  17. package/base/Null.d.ts +1 -1
  18. package/base/Null.js +3 -6
  19. package/base/Option.d.ts +1 -1
  20. package/base/Option.js +21 -22
  21. package/base/Result.d.ts +2 -2
  22. package/base/Tuple.d.ts +2 -2
  23. package/base/Tuple.js +10 -7
  24. package/base/UInt.d.ts +2 -2
  25. package/base/Vec.d.ts +2 -2
  26. package/base/Vec.js +12 -9
  27. package/base/VecAny.d.ts +2 -2
  28. package/base/VecFixed.d.ts +2 -2
  29. package/base/VecFixed.js +9 -6
  30. package/base/index.d.ts +12 -12
  31. package/bundle.d.ts +7 -7
  32. package/cjs/abstract/Array.js +2 -2
  33. package/cjs/abstract/index.js +6 -6
  34. package/cjs/base/Compact.js +2 -2
  35. package/cjs/base/Enum.js +8 -8
  36. package/cjs/base/Int.js +2 -2
  37. package/cjs/base/Option.js +4 -4
  38. package/cjs/base/Result.js +2 -2
  39. package/cjs/base/Tuple.js +8 -8
  40. package/cjs/base/UInt.js +2 -2
  41. package/cjs/base/Vec.js +6 -6
  42. package/cjs/base/VecAny.js +2 -2
  43. package/cjs/base/VecFixed.js +7 -7
  44. package/cjs/base/index.js +24 -24
  45. package/cjs/bundle.js +8 -8
  46. package/cjs/detectPackage.js +3 -3
  47. package/cjs/extended/BTreeMap.js +2 -2
  48. package/cjs/extended/BTreeSet.js +5 -5
  49. package/cjs/extended/BitVec.js +2 -2
  50. package/cjs/extended/Bytes.js +3 -3
  51. package/cjs/extended/HashMap.js +2 -2
  52. package/cjs/extended/Linkage.js +10 -10
  53. package/cjs/extended/Map.js +15 -15
  54. package/cjs/extended/OptionBool.js +5 -5
  55. package/cjs/extended/Range.js +2 -2
  56. package/cjs/extended/RangeInclusive.js +2 -2
  57. package/cjs/extended/Type.js +4 -4
  58. package/cjs/extended/U8aFixed.js +2 -2
  59. package/cjs/extended/WrapperKeepOpaque.js +6 -6
  60. package/cjs/extended/WrapperOpaque.js +2 -2
  61. package/cjs/extended/index.js +29 -29
  62. package/cjs/index.js +2 -2
  63. package/cjs/native/Json.js +2 -2
  64. package/cjs/native/Set.js +2 -2
  65. package/cjs/native/Struct.js +5 -5
  66. package/cjs/native/Text.js +2 -2
  67. package/cjs/native/index.js +19 -19
  68. package/cjs/packageInfo.js +1 -1
  69. package/cjs/primitive/F32.js +2 -2
  70. package/cjs/primitive/F64.js +2 -2
  71. package/cjs/primitive/I128.js +2 -2
  72. package/cjs/primitive/I16.js +2 -2
  73. package/cjs/primitive/I256.js +2 -2
  74. package/cjs/primitive/I32.js +2 -2
  75. package/cjs/primitive/I64.js +2 -2
  76. package/cjs/primitive/I8.js +2 -2
  77. package/cjs/primitive/U128.js +2 -2
  78. package/cjs/primitive/U16.js +2 -2
  79. package/cjs/primitive/U256.js +2 -2
  80. package/cjs/primitive/U32.js +2 -2
  81. package/cjs/primitive/U64.js +2 -2
  82. package/cjs/primitive/U8.js +2 -2
  83. package/cjs/primitive/USize.js +2 -2
  84. package/cjs/primitive/index.js +45 -45
  85. package/cjs/types/index.js +4 -4
  86. package/cjs/utils/compareArray.js +2 -2
  87. package/cjs/utils/compareMap.js +2 -2
  88. package/cjs/utils/index.js +22 -22
  89. package/cjs/utils/mapToTypeMap.js +2 -2
  90. package/extended/BTreeMap.d.ts +2 -2
  91. package/extended/BTreeSet.d.ts +1 -1
  92. package/extended/BTreeSet.js +7 -8
  93. package/extended/BitVec.d.ts +2 -2
  94. package/extended/BitVec.js +12 -9
  95. package/extended/Bytes.d.ts +2 -2
  96. package/extended/HashMap.d.ts +2 -2
  97. package/extended/Linkage.d.ts +4 -4
  98. package/extended/Map.d.ts +1 -1
  99. package/extended/Map.js +11 -12
  100. package/extended/OptionBool.d.ts +3 -3
  101. package/extended/Range.d.ts +2 -2
  102. package/extended/Range.js +7 -4
  103. package/extended/RangeInclusive.d.ts +2 -2
  104. package/extended/Type.d.ts +2 -2
  105. package/extended/U8aFixed.d.ts +2 -2
  106. package/extended/WrapperKeepOpaque.d.ts +2 -2
  107. package/extended/WrapperKeepOpaque.js +23 -20
  108. package/extended/WrapperOpaque.d.ts +2 -2
  109. package/extended/index.d.ts +14 -14
  110. package/index.d.ts +2 -2
  111. package/native/Bool.d.ts +1 -1
  112. package/native/Bool.js +1 -4
  113. package/native/Date.d.ts +1 -1
  114. package/native/Date.js +1 -4
  115. package/native/Float.d.ts +1 -1
  116. package/native/Float.js +8 -10
  117. package/native/Json.d.ts +1 -1
  118. package/native/Json.js +0 -4
  119. package/native/Raw.d.ts +1 -1
  120. package/native/Raw.js +0 -4
  121. package/native/Set.d.ts +1 -1
  122. package/native/Set.js +35 -34
  123. package/native/Struct.d.ts +1 -1
  124. package/native/Struct.js +22 -21
  125. package/native/Text.d.ts +1 -1
  126. package/native/Text.js +7 -8
  127. package/native/index.d.ts +8 -8
  128. package/package.json +3 -3
  129. package/packageInfo.js +1 -1
  130. package/primitive/F32.d.ts +2 -2
  131. package/primitive/F32.js +5 -2
  132. package/primitive/F64.d.ts +2 -2
  133. package/primitive/F64.js +5 -2
  134. package/primitive/I128.d.ts +2 -2
  135. package/primitive/I128.js +5 -2
  136. package/primitive/I16.d.ts +2 -2
  137. package/primitive/I16.js +5 -2
  138. package/primitive/I256.d.ts +2 -2
  139. package/primitive/I256.js +5 -2
  140. package/primitive/I32.d.ts +2 -2
  141. package/primitive/I32.js +5 -2
  142. package/primitive/I64.d.ts +2 -2
  143. package/primitive/I64.js +5 -2
  144. package/primitive/I8.d.ts +2 -2
  145. package/primitive/I8.js +5 -2
  146. package/primitive/U128.d.ts +2 -2
  147. package/primitive/U128.js +5 -2
  148. package/primitive/U16.d.ts +2 -2
  149. package/primitive/U16.js +5 -2
  150. package/primitive/U256.d.ts +2 -2
  151. package/primitive/U256.js +5 -2
  152. package/primitive/U32.d.ts +2 -2
  153. package/primitive/U32.js +5 -2
  154. package/primitive/U64.d.ts +2 -2
  155. package/primitive/U64.js +5 -2
  156. package/primitive/U8.d.ts +2 -2
  157. package/primitive/U8.js +5 -2
  158. package/primitive/USize.d.ts +2 -2
  159. package/primitive/index.d.ts +15 -15
  160. package/types/codec.d.ts +3 -3
  161. package/types/helpers.d.ts +1 -1
  162. package/types/index.d.ts +4 -4
  163. package/types/interfaces.d.ts +2 -2
  164. package/types/registry.d.ts +3 -3
  165. package/utils/decodeU8a.d.ts +1 -1
  166. package/utils/index.d.ts +9 -9
  167. package/utils/mapToTypeMap.d.ts +1 -1
  168. package/utils/sanitize.d.ts +1 -1
  169. package/utils/sortValues.d.ts +1 -1
  170. package/utils/typeToConstructor.d.ts +1 -1
  171. package/utils/typesToMap.d.ts +1 -1
@@ -1,3 +1,5 @@
1
+ var _WrapperKeepOpaque_Type, _WrapperKeepOpaque_decoded, _WrapperKeepOpaque_opaqueName;
2
+ import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
1
3
  import { compactAddLength, compactStripLength, compactToU8a, isHex, isU8a, u8aToU8a } from '@polkadot/util';
2
4
  import { Raw } from '../native/Raw.js';
3
5
  import { typeToConstructor } from '../utils/index.js';
@@ -21,15 +23,15 @@ function decodeRaw(registry, typeName, value) {
21
23
  return [Type, instance, compactAddLength(instance.toU8a())];
22
24
  }
23
25
  export class WrapperKeepOpaque extends Bytes {
24
- #Type;
25
- #decoded;
26
- #opaqueName;
27
26
  constructor(registry, typeName, value, { opaqueName = 'WrapperKeepOpaque' } = {}) {
28
27
  const [Type, decoded, u8a] = decodeRaw(registry, typeName, value);
29
28
  super(registry, u8a);
30
- this.#Type = Type;
31
- this.#decoded = decoded;
32
- this.#opaqueName = opaqueName;
29
+ _WrapperKeepOpaque_Type.set(this, void 0);
30
+ _WrapperKeepOpaque_decoded.set(this, void 0);
31
+ _WrapperKeepOpaque_opaqueName.set(this, void 0);
32
+ __classPrivateFieldSet(this, _WrapperKeepOpaque_Type, Type, "f");
33
+ __classPrivateFieldSet(this, _WrapperKeepOpaque_decoded, decoded, "f");
34
+ __classPrivateFieldSet(this, _WrapperKeepOpaque_opaqueName, opaqueName, "f");
33
35
  }
34
36
  static with(Type) {
35
37
  return class extends WrapperKeepOpaque {
@@ -42,15 +44,15 @@ export class WrapperKeepOpaque extends Bytes {
42
44
  * @description Checks if the wrapper is decodable
43
45
  */
44
46
  get isDecoded() {
45
- return !!this.#decoded;
47
+ return !!__classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f");
46
48
  }
47
49
  /**
48
50
  * @description Returns a breakdown of the hex encoding for this Codec
49
51
  */
50
52
  inspect() {
51
- return this.#decoded
53
+ return __classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f")
52
54
  ? {
53
- inner: [this.#decoded.inspect()],
55
+ inner: [__classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f").inspect()],
54
56
  outer: [compactToU8a(this.length)]
55
57
  }
56
58
  : {
@@ -61,39 +63,40 @@ export class WrapperKeepOpaque extends Bytes {
61
63
  * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
62
64
  */
63
65
  toHuman(isExtended) {
64
- return this.#decoded
65
- ? this.#decoded.toHuman(isExtended)
66
+ return __classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f")
67
+ ? __classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f").toHuman(isExtended)
66
68
  : super.toHuman();
67
69
  }
68
70
  /**
69
71
  * @description Converts the value in a best-fit primitive form
70
72
  */
71
73
  toPrimitive() {
72
- return this.#decoded
73
- ? this.#decoded.toPrimitive()
74
+ return __classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f")
75
+ ? __classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f").toPrimitive()
74
76
  : super.toPrimitive();
75
77
  }
76
78
  /**
77
79
  * @description Returns the base runtime type name for this instance
78
80
  */
79
81
  toRawType() {
80
- return `${this.#opaqueName}<${this.registry.getClassName(this.#Type) || (this.#decoded ? this.#decoded.toRawType() : new this.#Type(this.registry).toRawType())}>`;
82
+ return `${__classPrivateFieldGet(this, _WrapperKeepOpaque_opaqueName, "f")}<${this.registry.getClassName(__classPrivateFieldGet(this, _WrapperKeepOpaque_Type, "f")) || (__classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f") ? __classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f").toRawType() : new (__classPrivateFieldGet(this, _WrapperKeepOpaque_Type, "f"))(this.registry).toRawType())}>`;
81
83
  }
82
84
  /**
83
85
  * @description Converts the Object to to a string (either decoded or bytes)
84
86
  */
85
87
  toString() {
86
- return this.#decoded
87
- ? this.#decoded.toString()
88
+ return __classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f")
89
+ ? __classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f").toString()
88
90
  : super.toString();
89
91
  }
90
92
  /**
91
93
  * @description Returns the decoded that the WrapperKeepOpaque represents (if available), throws if non-decodable
92
94
  */
93
95
  unwrap() {
94
- if (!this.#decoded) {
95
- throw new Error(`${this.#opaqueName}: unwrapping an undecodable value`);
96
+ if (!__classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f")) {
97
+ throw new Error(`${__classPrivateFieldGet(this, _WrapperKeepOpaque_opaqueName, "f")}: unwrapping an undecodable value`);
96
98
  }
97
- return this.#decoded;
99
+ return __classPrivateFieldGet(this, _WrapperKeepOpaque_decoded, "f");
98
100
  }
99
- }
101
+ }
102
+ _WrapperKeepOpaque_Type = new WeakMap(), _WrapperKeepOpaque_decoded = new WeakMap(), _WrapperKeepOpaque_opaqueName = new WeakMap();
@@ -1,5 +1,5 @@
1
- import type { Codec, CodecClass, Registry } from '../types';
2
- import { WrapperKeepOpaque } from './WrapperKeepOpaque';
1
+ import type { Codec, CodecClass, Registry } from '../types/index.js';
2
+ import { WrapperKeepOpaque } from './WrapperKeepOpaque.js';
3
3
  export declare class WrapperOpaque<T extends Codec> extends WrapperKeepOpaque<T> {
4
4
  constructor(registry: Registry, typeName: CodecClass<T> | string, value?: unknown);
5
5
  static with<T extends Codec>(Type: CodecClass<T> | string): CodecClass<WrapperKeepOpaque<T>>;
@@ -1,14 +1,14 @@
1
- export { BitVec } from './BitVec';
2
- export { BTreeMap } from './BTreeMap';
3
- export { BTreeSet } from './BTreeSet';
4
- export { Bytes } from './Bytes';
5
- export { HashMap } from './HashMap';
6
- export { Linkage } from './Linkage';
7
- export { CodecMap, CodecMap as Map } from './Map';
8
- export { OptionBool } from './OptionBool';
9
- export { Range } from './Range';
10
- export { RangeInclusive } from './RangeInclusive';
11
- export { Type } from './Type';
12
- export { U8aFixed } from './U8aFixed';
13
- export { WrapperKeepOpaque } from './WrapperKeepOpaque';
14
- export { WrapperOpaque } from './WrapperOpaque';
1
+ export { BitVec } from './BitVec.js';
2
+ export { BTreeMap } from './BTreeMap.js';
3
+ export { BTreeSet } from './BTreeSet.js';
4
+ export { Bytes } from './Bytes.js';
5
+ export { HashMap } from './HashMap.js';
6
+ export { Linkage } from './Linkage.js';
7
+ export { CodecMap, CodecMap as Map } from './Map.js';
8
+ export { OptionBool } from './OptionBool.js';
9
+ export { Range } from './Range.js';
10
+ export { RangeInclusive } from './RangeInclusive.js';
11
+ export { Type } from './Type.js';
12
+ export { U8aFixed } from './U8aFixed.js';
13
+ export { WrapperKeepOpaque } from './WrapperKeepOpaque.js';
14
+ export { WrapperOpaque } from './WrapperOpaque.js';
package/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import './detectPackage';
2
- export * from './bundle';
1
+ import './detectPackage.js';
2
+ export * from './bundle.js';
package/native/Bool.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { HexString } from '@polkadot/util/types';
2
- import type { AnyBool, Codec, Inspect, IU8a, Registry } from '../types';
2
+ import type { AnyBool, Codec, Inspect, IU8a, Registry } from '../types/index.js';
3
3
  /**
4
4
  * @name bool
5
5
  * @description
package/native/Bool.js CHANGED
@@ -6,16 +6,13 @@ import { isU8a, u8aToHex } from '@polkadot/util';
6
6
  * @noInheritDoc
7
7
  */
8
8
  export class bool extends Boolean {
9
- registry;
10
- createdAtHash;
11
- initialU8aLength = 1;
12
- isStorageFallback;
13
9
  constructor(registry, value = false) {
14
10
  super(isU8a(value)
15
11
  ? value[0] === 1
16
12
  : value instanceof Boolean
17
13
  ? value.valueOf()
18
14
  : !!value);
15
+ this.initialU8aLength = 1;
19
16
  this.registry = registry;
20
17
  }
21
18
  /**
package/native/Date.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /// <reference types="bn.js" />
2
2
  import type { HexString } from '@polkadot/util/types';
3
- import type { AnyNumber, Inspect, INumber, IU8a, Registry, UIntBitLength } from '../types';
3
+ import type { AnyNumber, Inspect, INumber, IU8a, Registry, UIntBitLength } from '../types/index.js';
4
4
  import { BN } from '@polkadot/util';
5
5
  /**
6
6
  * @name Date
package/native/Date.js CHANGED
@@ -24,12 +24,9 @@ function decodeDate(value) {
24
24
  * @noInheritDoc
25
25
  */
26
26
  export class CodecDate extends Date {
27
- registry;
28
- createdAtHash;
29
- initialU8aLength = BITLENGTH / 8;
30
- isStorageFallback;
31
27
  constructor(registry, value = 0) {
32
28
  super(decodeDate(value));
29
+ this.initialU8aLength = BITLENGTH / 8;
33
30
  this.registry = registry;
34
31
  }
35
32
  /**
package/native/Float.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { HexString } from '@polkadot/util/types';
2
- import type { AnyFloat, CodecClass, IFloat, Inspect, IU8a, Registry } from '../types';
2
+ import type { AnyFloat, CodecClass, IFloat, Inspect, IU8a, Registry } from '../types/index.js';
3
3
  interface Options {
4
4
  bitLength?: 32 | 64;
5
5
  }
package/native/Float.js CHANGED
@@ -1,3 +1,5 @@
1
+ var _Float_bitLength;
2
+ import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
1
3
  import { floatToU8a, isHex, isU8a, u8aToFloat, u8aToHex, u8aToU8a } from '@polkadot/util';
2
4
  /**
3
5
  * @name Float
@@ -8,19 +10,14 @@ import { floatToU8a, isHex, isU8a, u8aToFloat, u8aToHex, u8aToU8a } from '@polka
8
10
  * in some eth_* RPCs
9
11
  */
10
12
  export class Float extends Number {
11
- encodedLength;
12
- registry;
13
- createdAtHash;
14
- initialU8aLength;
15
- isStorageFallback;
16
- #bitLength;
17
13
  constructor(registry, value, { bitLength = 32 } = {}) {
18
14
  super(isU8a(value) || isHex(value)
19
15
  ? value.length === 0
20
16
  ? 0
21
17
  : u8aToFloat(u8aToU8a(value), { bitLength })
22
18
  : (value || 0));
23
- this.#bitLength = bitLength;
19
+ _Float_bitLength.set(this, void 0);
20
+ __classPrivateFieldSet(this, _Float_bitLength, bitLength, "f");
24
21
  this.encodedLength = bitLength / 8;
25
22
  this.initialU8aLength = this.encodedLength;
26
23
  this.registry = registry;
@@ -94,12 +91,13 @@ export class Float extends Number {
94
91
  * @description Returns the base runtime type name for this instance
95
92
  */
96
93
  toRawType() {
97
- return `f${this.#bitLength}`;
94
+ return `f${__classPrivateFieldGet(this, _Float_bitLength, "f")}`;
98
95
  }
99
96
  /**
100
97
  * @description Encodes the value as a Uint8Array as per the SCALE specifications
101
98
  */
102
99
  toU8a() {
103
- return floatToU8a(this, { bitLength: this.#bitLength });
100
+ return floatToU8a(this, { bitLength: __classPrivateFieldGet(this, _Float_bitLength, "f") });
104
101
  }
105
- }
102
+ }
103
+ _Float_bitLength = new WeakMap();
package/native/Json.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { HexString } from '@polkadot/util/types';
2
- import type { AnyJson, Codec, Inspect, IU8a, Registry } from '../types';
2
+ import type { AnyJson, Codec, Inspect, IU8a, Registry } from '../types/index.js';
3
3
  /**
4
4
  * @name Json
5
5
  * @description
package/native/Json.js CHANGED
@@ -13,10 +13,6 @@ function decodeJson(value) {
13
13
  * @noInheritDoc
14
14
  */
15
15
  export class Json extends Map {
16
- registry;
17
- createdAtHash;
18
- initialU8aLength;
19
- isStorageFallback;
20
16
  constructor(registry, value) {
21
17
  const decoded = decodeJson(value);
22
18
  super(decoded);
package/native/Raw.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { HexString } from '@polkadot/util/types';
2
- import type { AnyJson, AnyU8a, Inspect, IU8a, Registry } from '../types';
2
+ import type { AnyJson, AnyU8a, Inspect, IU8a, Registry } from '../types/index.js';
3
3
  /**
4
4
  * @name Raw
5
5
  * @description
package/native/Raw.js CHANGED
@@ -9,10 +9,6 @@ import { isAscii, isUndefined, isUtf8, u8aToHex, u8aToString, u8aToU8a } from '@
9
9
  * @noInheritDoc
10
10
  */
11
11
  export class Raw extends Uint8Array {
12
- registry;
13
- createdAtHash;
14
- initialU8aLength;
15
- isStorageFallback;
16
12
  /**
17
13
  * @description This ensures that operators such as clice, filter, map, etc. return
18
14
  * new Array instances (without this we need to apply overrides)
package/native/Set.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /// <reference types="bn.js" />
2
2
  import type { HexString } from '@polkadot/util/types';
3
- import type { CodecClass, Inspect, ISet, IU8a, Registry } from '../types';
3
+ import type { CodecClass, Inspect, ISet, IU8a, Registry } from '../types/index.js';
4
4
  import { BN } from '@polkadot/util';
5
5
  type SetValues = Record<string, number | BN>;
6
6
  /**
package/native/Set.js CHANGED
@@ -1,3 +1,5 @@
1
+ var _CodecSet_allowed, _CodecSet_byteLength;
2
+ import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
1
3
  import { BN, bnToBn, bnToU8a, isBn, isNumber, isString, isU8a, isUndefined, objectProperties, stringify, stringPascalCase, u8aToBn, u8aToHex, u8aToU8a } from '@polkadot/util';
2
4
  import { compareArray } from '../utils/index.js';
3
5
  function encodeSet(setValues, values) {
@@ -65,38 +67,49 @@ function decodeSet(setValues, value = 0, bitLength) {
65
67
  * a bitwise representation of the values.
66
68
  */
67
69
  export class CodecSet extends Set {
68
- registry;
69
- createdAtHash;
70
- initialU8aLength;
71
- isStorageFallback;
72
- #allowed;
73
- #byteLength;
74
70
  constructor(registry, setValues, value, bitLength = 8) {
75
71
  super(decodeSet(setValues, value, bitLength));
72
+ _CodecSet_allowed.set(this, void 0);
73
+ _CodecSet_byteLength.set(this, void 0);
74
+ /**
75
+ * @description adds a value to the Set (extended to allow for validity checking)
76
+ */
77
+ this.add = (key) => {
78
+ // ^^^ add = () property done to assign this instance's this, otherwise Set.add creates "some" chaos
79
+ // we have the isUndefined(this._setValues) in here as well, add is used internally
80
+ // in the Set constructor (so it is undefined at this point, and should allow)
81
+ if (__classPrivateFieldGet(this, _CodecSet_allowed, "f") && isUndefined(__classPrivateFieldGet(this, _CodecSet_allowed, "f")[key])) {
82
+ throw new Error(`Set: Invalid key '${key}' on add`);
83
+ }
84
+ super.add(key);
85
+ return this;
86
+ };
76
87
  this.registry = registry;
77
- this.#allowed = setValues;
78
- this.#byteLength = bitLength / 8;
88
+ __classPrivateFieldSet(this, _CodecSet_allowed, setValues, "f");
89
+ __classPrivateFieldSet(this, _CodecSet_byteLength, bitLength / 8, "f");
79
90
  }
80
91
  static with(values, bitLength) {
81
- return class extends CodecSet {
82
- static {
92
+ var _a;
93
+ return _a = class extends CodecSet {
94
+ constructor(registry, value) {
95
+ super(registry, values, value, bitLength);
96
+ }
97
+ },
98
+ (() => {
83
99
  const keys = Object.keys(values);
84
100
  const isKeys = new Array(keys.length);
85
101
  for (let i = 0; i < keys.length; i++) {
86
102
  isKeys[i] = `is${stringPascalCase(keys[i])}`;
87
103
  }
88
- objectProperties(this.prototype, isKeys, (_, i, self) => self.strings.includes(keys[i]));
89
- }
90
- constructor(registry, value) {
91
- super(registry, values, value, bitLength);
92
- }
93
- };
104
+ objectProperties(_a.prototype, isKeys, (_, i, self) => self.strings.includes(keys[i]));
105
+ })(),
106
+ _a;
94
107
  }
95
108
  /**
96
109
  * @description The length of the value when encoded as a Uint8Array
97
110
  */
98
111
  get encodedLength() {
99
- return this.#byteLength;
112
+ return __classPrivateFieldGet(this, _CodecSet_byteLength, "f");
100
113
  }
101
114
  /**
102
115
  * @description returns a hash of the contents
@@ -120,21 +133,8 @@ export class CodecSet extends Set {
120
133
  * @description The encoded value for the set members
121
134
  */
122
135
  get valueEncoded() {
123
- return encodeSet(this.#allowed, this.strings);
136
+ return encodeSet(__classPrivateFieldGet(this, _CodecSet_allowed, "f"), this.strings);
124
137
  }
125
- /**
126
- * @description adds a value to the Set (extended to allow for validity checking)
127
- */
128
- add = (key) => {
129
- // ^^^ add = () property done to assign this instance's this, otherwise Set.add creates "some" chaos
130
- // we have the isUndefined(this._setValues) in here as well, add is used internally
131
- // in the Set constructor (so it is undefined at this point, and should allow)
132
- if (this.#allowed && isUndefined(this.#allowed[key])) {
133
- throw new Error(`Set: Invalid key '${key}' on add`);
134
- }
135
- super.add(key);
136
- return this;
137
- };
138
138
  /**
139
139
  * @description Compares the value of the input to see if there is a match
140
140
  */
@@ -193,7 +193,7 @@ export class CodecSet extends Set {
193
193
  * @description Returns the base runtime type name for this instance
194
194
  */
195
195
  toRawType() {
196
- return stringify({ _set: this.#allowed });
196
+ return stringify({ _set: __classPrivateFieldGet(this, _CodecSet_allowed, "f") });
197
197
  }
198
198
  /**
199
199
  * @description Returns the string representation of the value
@@ -208,8 +208,9 @@ export class CodecSet extends Set {
208
208
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
209
209
  toU8a(isBare) {
210
210
  return bnToU8a(this.valueEncoded, {
211
- bitLength: this.#byteLength * 8,
211
+ bitLength: __classPrivateFieldGet(this, _CodecSet_byteLength, "f") * 8,
212
212
  isLe: true
213
213
  });
214
214
  }
215
- }
215
+ }
216
+ _CodecSet_allowed = new WeakMap(), _CodecSet_byteLength = new WeakMap();
@@ -1,5 +1,5 @@
1
1
  import type { HexString } from '@polkadot/util/types';
2
- import type { AnyJson, BareOpts, Codec, CodecClass, Inspect, IStruct, IU8a, Registry } from '../types';
2
+ import type { AnyJson, BareOpts, Codec, CodecClass, Inspect, IStruct, IU8a, Registry } from '../types/index.js';
3
3
  type TypesDef<T = Codec> = Record<string, string | CodecClass<T>>;
4
4
  type Definition = [CodecClass[], string[]];
5
5
  interface Options {
package/native/Struct.js CHANGED
@@ -1,3 +1,5 @@
1
+ var _Struct_jsonMap, _Struct_Types;
2
+ import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
1
3
  import { isBoolean, isHex, isObject, isU8a, isUndefined, objectProperties, stringCamelCase, stringify, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util';
2
4
  import { compareMap, decodeU8aStruct, mapToTypeMap, typesToMap } from '../utils/index.js';
3
5
  function noopSetDefinition(d) {
@@ -71,12 +73,6 @@ function decodeStructFromObject(registry, [Types, keys], value, jsonMap) {
71
73
  * @noInheritDoc
72
74
  */
73
75
  export class Struct extends Map {
74
- registry;
75
- createdAtHash;
76
- initialU8aLength;
77
- isStorageFallback;
78
- #jsonMap;
79
- #Types;
80
76
  constructor(registry, Types, value, jsonMap = new Map(), { definition, setDefinition = noopSetDefinition } = {}) {
81
77
  const typeMap = definition || setDefinition(mapToTypeMap(registry, Types));
82
78
  const [decoded, decodedLength] = isU8a(value) || isHex(value)
@@ -85,30 +81,34 @@ export class Struct extends Map {
85
81
  ? [value, 0]
86
82
  : decodeStructFromObject(registry, typeMap, value || {}, jsonMap);
87
83
  super(decoded);
84
+ _Struct_jsonMap.set(this, void 0);
85
+ _Struct_Types.set(this, void 0);
88
86
  this.initialU8aLength = decodedLength;
89
87
  this.registry = registry;
90
- this.#jsonMap = jsonMap;
91
- this.#Types = typeMap;
88
+ __classPrivateFieldSet(this, _Struct_jsonMap, jsonMap, "f");
89
+ __classPrivateFieldSet(this, _Struct_Types, typeMap, "f");
92
90
  }
93
91
  static with(Types, jsonMap) {
92
+ var _a;
94
93
  let definition;
95
94
  // eslint-disable-next-line no-return-assign
96
95
  const setDefinition = (d) => definition = d;
97
- return class extends Struct {
98
- static {
96
+ return _a = class extends Struct {
97
+ constructor(registry, value) {
98
+ super(registry, Types, value, jsonMap, { definition, setDefinition });
99
+ }
100
+ },
101
+ (() => {
99
102
  const keys = Object.keys(Types);
100
- objectProperties(this.prototype, keys, (k, _, self) => self.get(k));
101
- }
102
- constructor(registry, value) {
103
- super(registry, Types, value, jsonMap, { definition, setDefinition });
104
- }
105
- };
103
+ objectProperties(_a.prototype, keys, (k, _, self) => self.get(k));
104
+ })(),
105
+ _a;
106
106
  }
107
107
  /**
108
108
  * @description The available keys for this struct
109
109
  */
110
110
  get defKeys() {
111
- return this.#Types[1];
111
+ return __classPrivateFieldGet(this, _Struct_Types, "f")[1];
112
112
  }
113
113
  /**
114
114
  * @description Checks if the value is an empty value
@@ -142,7 +142,7 @@ export class Struct extends Map {
142
142
  */
143
143
  get Type() {
144
144
  const result = {};
145
- const [Types, keys] = this.#Types;
145
+ const [Types, keys] = __classPrivateFieldGet(this, _Struct_Types, "f");
146
146
  for (let i = 0; i < keys.length; i++) {
147
147
  result[keys[i]] = new Types[i](this.registry).toRawType();
148
148
  }
@@ -220,7 +220,7 @@ export class Struct extends Map {
220
220
  for (const [k, v] of this.entries()) {
221
221
  // Here we pull out the entry against the JSON mapping (if supplied)
222
222
  // since this representation goes over RPC and needs to be correct
223
- json[(this.#jsonMap.get(k) || k)] = v.toJSON();
223
+ json[(__classPrivateFieldGet(this, _Struct_jsonMap, "f").get(k) || k)] = v.toJSON();
224
224
  }
225
225
  return json;
226
226
  }
@@ -238,7 +238,7 @@ export class Struct extends Map {
238
238
  * @description Returns the base runtime type name for this instance
239
239
  */
240
240
  toRawType() {
241
- return stringify(typesToMap(this.registry, this.#Types));
241
+ return stringify(typesToMap(this.registry, __classPrivateFieldGet(this, _Struct_Types, "f")));
242
242
  }
243
243
  /**
244
244
  * @description Returns the string representation of the value
@@ -259,4 +259,5 @@ export class Struct extends Map {
259
259
  }
260
260
  return u8aConcatStrict(encoded);
261
261
  }
262
- }
262
+ }
263
+ _Struct_jsonMap = new WeakMap(), _Struct_Types = new WeakMap();
package/native/Text.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { HexString } from '@polkadot/util/types';
2
- import type { AnyString, AnyU8a, Inspect, IText, IU8a, Registry } from '../types';
2
+ import type { AnyString, AnyU8a, Inspect, IText, IU8a, Registry } from '../types/index.js';
3
3
  /**
4
4
  * @name Text
5
5
  * @description
package/native/Text.js CHANGED
@@ -1,3 +1,5 @@
1
+ var _Text_override;
2
+ import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
1
3
  import { compactAddLength, compactFromU8aLim, compactToU8a, hexToU8a, isHex, isString, isU8a, stringToU8a, u8aToHex, u8aToString } from '@polkadot/util';
2
4
  import { Raw } from './Raw.js';
3
5
  const MAX_LENGTH = 128 * 1024;
@@ -36,14 +38,10 @@ function decodeText(value) {
36
38
  * @noInheritDoc
37
39
  */
38
40
  export class Text extends String {
39
- registry;
40
- createdAtHash;
41
- initialU8aLength;
42
- isStorageFallback;
43
- #override = null;
44
41
  constructor(registry, value) {
45
42
  const [str, decodedLength] = decodeText(value);
46
43
  super(str);
44
+ _Text_override.set(this, null);
47
45
  this.registry = registry;
48
46
  this.initialU8aLength = decodedLength;
49
47
  }
@@ -95,7 +93,7 @@ export class Text extends String {
95
93
  * @description Set an override value for this
96
94
  */
97
95
  setOverride(override) {
98
- this.#override = override;
96
+ __classPrivateFieldSet(this, _Text_override, override, "f");
99
97
  }
100
98
  /**
101
99
  * @description Returns a hex string representation of the value
@@ -133,7 +131,7 @@ export class Text extends String {
133
131
  * @description Returns the string representation of the value
134
132
  */
135
133
  toString() {
136
- return this.#override || super.toString();
134
+ return __classPrivateFieldGet(this, _Text_override, "f") || super.toString();
137
135
  }
138
136
  /**
139
137
  * @description Encodes the value as a Uint8Array as per the SCALE specifications
@@ -147,4 +145,5 @@ export class Text extends String {
147
145
  ? encoded
148
146
  : compactAddLength(encoded);
149
147
  }
150
- }
148
+ }
149
+ _Text_override = new WeakMap();
package/native/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- export { bool, bool as Bool } from './Bool';
2
- export { CodecDate, CodecDate as Date } from './Date';
3
- export { Float } from './Float';
4
- export { Json } from './Json';
5
- export { Raw } from './Raw';
6
- export { CodecSet, CodecSet as Set } from './Set';
7
- export { Struct } from './Struct';
8
- export { Text } from './Text';
1
+ export { bool, bool as Bool } from './Bool.js';
2
+ export { CodecDate, CodecDate as Date } from './Date.js';
3
+ export { Float } from './Float.js';
4
+ export { Json } from './Json.js';
5
+ export { Raw } from './Raw.js';
6
+ export { CodecSet, CodecSet as Set } from './Set.js';
7
+ export { Struct } from './Struct.js';
8
+ export { Text } from './Text.js';
package/package.json CHANGED
@@ -20,7 +20,7 @@
20
20
  "./cjs/detectPackage.js"
21
21
  ],
22
22
  "type": "module",
23
- "version": "10.0.1",
23
+ "version": "10.1.2",
24
24
  "main": "./cjs/index.js",
25
25
  "module": "./index.js",
26
26
  "types": "./index.d.ts",
@@ -437,8 +437,8 @@
437
437
  }
438
438
  },
439
439
  "dependencies": {
440
- "@polkadot/util": "^11.0.1",
441
- "@polkadot/x-bigint": "^11.0.1",
440
+ "@polkadot/util": "^11.0.2",
441
+ "@polkadot/x-bigint": "^11.0.2",
442
442
  "tslib": "^2.5.0"
443
443
  }
444
444
  }
package/packageInfo.js CHANGED
@@ -1 +1 @@
1
- export const packageInfo = { name: '@polkadot/types-codec', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '10.0.1' };
1
+ export const packageInfo = { name: '@polkadot/types-codec', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '10.1.2' };
@@ -1,5 +1,5 @@
1
- import { Float } from '../native/Float';
2
- declare const f32_base: import("../types").CodecClass<Float>;
1
+ import { Float } from '../native/Float.js';
2
+ declare const f32_base: import("../types/codec.js").CodecClass<Float>;
3
3
  /**
4
4
  * @name f32
5
5
  * @description
package/primitive/F32.js CHANGED
@@ -5,6 +5,9 @@ import { Float } from '../native/Float.js';
5
5
  * A 32-bit float
6
6
  */
7
7
  export class f32 extends Float.with(32) {
8
- // NOTE without this, we cannot properly determine extensions
9
- __FloatType = 'f32';
8
+ constructor() {
9
+ super(...arguments);
10
+ // NOTE without this, we cannot properly determine extensions
11
+ this.__FloatType = 'f32';
12
+ }
10
13
  }
@@ -1,5 +1,5 @@
1
- import { Float } from '../native/Float';
2
- declare const f64_base: import("../types").CodecClass<Float>;
1
+ import { Float } from '../native/Float.js';
2
+ declare const f64_base: import("../types/codec.js").CodecClass<Float>;
3
3
  /**
4
4
  * @name f64
5
5
  * @description