@polkadot/types-codec 9.5.1 → 9.6.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.
Files changed (152) hide show
  1. package/abstract/Array.js +15 -44
  2. package/abstract/Base.js +12 -28
  3. package/abstract/BigInt.js +3 -2
  4. package/abstract/Int.js +25 -52
  5. package/abstract/index.js +1 -0
  6. package/base/Compact.js +21 -45
  7. package/base/DoNotConstruct.js +3 -19
  8. package/base/Enum.js +37 -88
  9. package/base/Int.js +2 -5
  10. package/base/Null.js +12 -23
  11. package/base/Option.js +23 -59
  12. package/base/Result.js +8 -19
  13. package/base/Tuple.js +12 -29
  14. package/base/UInt.js +2 -4
  15. package/base/Vec.js +7 -25
  16. package/base/VecAny.js +2 -2
  17. package/base/VecFixed.js +8 -20
  18. package/base/index.js +1 -0
  19. package/bundle.js +1 -0
  20. package/cjs/abstract/Array.js +13 -47
  21. package/cjs/abstract/Base.js +12 -30
  22. package/cjs/abstract/BigInt.js +1 -4
  23. package/cjs/abstract/Int.js +25 -55
  24. package/cjs/abstract/index.js +0 -3
  25. package/cjs/base/Compact.js +21 -48
  26. package/cjs/base/DoNotConstruct.js +3 -21
  27. package/cjs/base/Enum.js +34 -92
  28. package/cjs/base/Int.js +0 -7
  29. package/cjs/base/Null.js +10 -25
  30. package/cjs/base/Option.js +23 -63
  31. package/cjs/base/Result.js +6 -21
  32. package/cjs/base/Tuple.js +12 -33
  33. package/cjs/base/UInt.js +0 -6
  34. package/cjs/base/Vec.js +7 -31
  35. package/cjs/base/VecAny.js +0 -4
  36. package/cjs/base/VecFixed.js +8 -25
  37. package/cjs/base/index.js +0 -12
  38. package/cjs/bundle.js +0 -13
  39. package/cjs/detectPackage.js +2 -4
  40. package/cjs/extended/BTreeMap.js +1 -5
  41. package/cjs/extended/BTreeSet.js +17 -57
  42. package/cjs/extended/BitVec.js +11 -25
  43. package/cjs/extended/Bytes.js +9 -20
  44. package/cjs/extended/HashMap.js +1 -5
  45. package/cjs/extended/Linkage.js +5 -20
  46. package/cjs/extended/Map.js +16 -62
  47. package/cjs/extended/OptionBool.js +8 -21
  48. package/cjs/extended/Range.js +3 -13
  49. package/cjs/extended/RangeInclusive.js +1 -6
  50. package/cjs/extended/Type.js +1 -7
  51. package/cjs/extended/U8aFixed.js +2 -15
  52. package/cjs/extended/WrapperKeepOpaque.js +8 -28
  53. package/cjs/extended/WrapperOpaque.js +2 -8
  54. package/cjs/extended/index.js +0 -14
  55. package/cjs/index.js +0 -3
  56. package/cjs/native/Bool.js +14 -32
  57. package/cjs/native/Date.js +18 -40
  58. package/cjs/native/Float.js +11 -29
  59. package/cjs/native/Json.js +14 -33
  60. package/cjs/native/Raw.js +18 -41
  61. package/cjs/native/Set.js +21 -67
  62. package/cjs/native/Struct.data.js +1 -0
  63. package/cjs/native/Struct.js +33 -83
  64. package/cjs/native/Text.js +20 -44
  65. package/cjs/native/index.js +0 -8
  66. package/cjs/packageInfo.js +3 -1
  67. package/cjs/primitive/F32.js +0 -3
  68. package/cjs/primitive/F64.js +0 -3
  69. package/cjs/primitive/I128.js +0 -3
  70. package/cjs/primitive/I16.js +0 -3
  71. package/cjs/primitive/I256.js +0 -3
  72. package/cjs/primitive/I32.js +0 -3
  73. package/cjs/primitive/I64.js +0 -3
  74. package/cjs/primitive/I8.js +0 -3
  75. package/cjs/primitive/U128.js +0 -3
  76. package/cjs/primitive/U16.js +0 -3
  77. package/cjs/primitive/U256.js +0 -3
  78. package/cjs/primitive/U32.js +0 -3
  79. package/cjs/primitive/U64.js +0 -3
  80. package/cjs/primitive/U8.js +0 -3
  81. package/cjs/primitive/USize.js +0 -4
  82. package/cjs/primitive/index.js +0 -15
  83. package/cjs/types/index.js +0 -8
  84. package/cjs/utils/compareArray.js +1 -4
  85. package/cjs/utils/compareMap.js +4 -9
  86. package/cjs/utils/compareSet.js +4 -6
  87. package/cjs/utils/decodeU8a.js +7 -17
  88. package/cjs/utils/index.js +0 -9
  89. package/cjs/utils/mapToTypeMap.js +0 -4
  90. package/cjs/utils/sanitize.js +66 -71
  91. package/cjs/utils/sortValues.js +5 -18
  92. package/cjs/utils/typeToConstructor.js +1 -2
  93. package/cjs/utils/typesToMap.js +1 -3
  94. package/cjs/utils/util.js +1 -2
  95. package/detectOther.js +2 -0
  96. package/detectPackage.js +2 -0
  97. package/extended/BTreeMap.js +1 -2
  98. package/extended/BTreeSet.js +17 -53
  99. package/extended/BitVec.js +13 -22
  100. package/extended/Bytes.js +11 -17
  101. package/extended/HashMap.js +1 -2
  102. package/extended/Linkage.js +5 -12
  103. package/extended/Map.js +16 -54
  104. package/extended/OptionBool.js +8 -17
  105. package/extended/Range.js +4 -11
  106. package/extended/RangeInclusive.js +1 -3
  107. package/extended/Type.js +3 -4
  108. package/extended/U8aFixed.js +4 -12
  109. package/extended/WrapperKeepOpaque.js +8 -23
  110. package/extended/WrapperOpaque.js +2 -5
  111. package/extended/index.js +1 -0
  112. package/index.js +1 -0
  113. package/native/Bool.js +16 -30
  114. package/native/Date.js +18 -37
  115. package/native/Float.js +12 -27
  116. package/native/Json.js +16 -30
  117. package/native/Raw.js +20 -39
  118. package/native/Set.js +21 -63
  119. package/native/Struct.data.js +1 -0
  120. package/native/Struct.js +33 -80
  121. package/native/Text.js +20 -40
  122. package/native/index.js +1 -0
  123. package/package.json +4 -4
  124. package/packageInfo.js +3 -1
  125. package/primitive/F32.js +2 -1
  126. package/primitive/F64.js +2 -1
  127. package/primitive/I128.js +2 -1
  128. package/primitive/I16.js +2 -1
  129. package/primitive/I256.js +2 -1
  130. package/primitive/I32.js +2 -1
  131. package/primitive/I64.js +2 -1
  132. package/primitive/I8.js +2 -1
  133. package/primitive/U128.js +2 -1
  134. package/primitive/U16.js +2 -1
  135. package/primitive/U256.js +2 -1
  136. package/primitive/U32.js +2 -1
  137. package/primitive/U64.js +2 -1
  138. package/primitive/U8.js +2 -1
  139. package/primitive/USize.js +2 -2
  140. package/primitive/index.js +1 -0
  141. package/types/index.js +1 -0
  142. package/utils/compareArray.js +4 -3
  143. package/utils/compareMap.js +4 -7
  144. package/utils/compareSet.js +4 -5
  145. package/utils/decodeU8a.js +9 -14
  146. package/utils/index.js +1 -0
  147. package/utils/mapToTypeMap.js +2 -3
  148. package/utils/sanitize.js +66 -60
  149. package/utils/sortValues.js +6 -15
  150. package/utils/typeToConstructor.js +1 -0
  151. package/utils/typesToMap.js +1 -2
  152. package/utils/util.js +1 -0
package/native/Bool.js CHANGED
@@ -1,133 +1,119 @@
1
1
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+
3
4
  import { isU8a, u8aToHex } from '@polkadot/util';
5
+
4
6
  /**
5
7
  * @name bool
6
8
  * @description
7
9
  * Representation for a boolean value in the system. It extends the base JS `Boolean` class
8
10
  * @noInheritDoc
9
11
  */
10
-
11
12
  export class bool extends Boolean {
12
13
  constructor(registry, value = false) {
13
14
  super(isU8a(value) ? value[0] === 1 : value instanceof Boolean ? value.valueOf() : !!value);
14
15
  this.registry = registry;
15
16
  }
17
+
16
18
  /**
17
19
  * @description The length of the value when encoded as a Uint8Array
18
20
  */
19
-
20
-
21
21
  get encodedLength() {
22
22
  return 1;
23
23
  }
24
+
24
25
  /**
25
26
  * @description returns a hash of the contents
26
27
  */
27
-
28
-
29
28
  get hash() {
30
29
  return this.registry.hash(this.toU8a());
31
30
  }
31
+
32
32
  /**
33
33
  * @description Checks if the value is an empty value (true when it wraps false/default)
34
34
  */
35
-
36
-
37
35
  get isEmpty() {
38
36
  return this.isFalse;
39
37
  }
38
+
40
39
  /**
41
40
  * @description Checks if the value is an empty value (always false)
42
41
  */
43
-
44
-
45
42
  get isFalse() {
46
43
  return !this.isTrue;
47
44
  }
45
+
48
46
  /**
49
47
  * @description Checks if the value is an empty value (always false)
50
48
  */
51
-
52
-
53
49
  get isTrue() {
54
50
  return this.valueOf();
55
51
  }
52
+
56
53
  /**
57
54
  * @description Compares the value of the input to see if there is a match
58
55
  */
59
-
60
-
61
56
  eq(other) {
62
57
  return this.valueOf() === (other instanceof Boolean ? other.valueOf() : other);
63
58
  }
59
+
64
60
  /**
65
61
  * @description Returns a breakdown of the hex encoding for this Codec
66
62
  */
67
-
68
-
69
63
  inspect() {
70
64
  return {
71
65
  outer: [this.toU8a()]
72
66
  };
73
67
  }
68
+
74
69
  /**
75
70
  * @description Returns a hex string representation of the value
76
71
  */
77
-
78
-
79
72
  toHex() {
80
73
  return u8aToHex(this.toU8a());
81
74
  }
75
+
82
76
  /**
83
77
  * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
84
78
  */
85
-
86
-
87
79
  toHuman() {
88
80
  return this.toJSON();
89
81
  }
82
+
90
83
  /**
91
84
  * @description Converts the Object to JSON, typically used for RPC transfers
92
85
  */
93
-
94
-
95
86
  toJSON() {
96
87
  return this.valueOf();
97
88
  }
89
+
98
90
  /**
99
91
  * @description Converts the value in a best-fit primitive form
100
92
  */
101
-
102
-
103
93
  toPrimitive() {
104
94
  return this.toJSON();
105
95
  }
96
+
106
97
  /**
107
98
  * @description Returns the base runtime type name for this instance
108
99
  */
109
-
110
-
111
100
  toRawType() {
112
101
  return 'bool';
113
102
  }
103
+
114
104
  /**
115
105
  * @description Returns the string representation of the value
116
106
  */
117
-
118
-
119
107
  toString() {
120
108
  return this.toJSON().toString();
121
109
  }
110
+
122
111
  /**
123
112
  * @description Encodes the value as a Uint8Array as per the SCALE specifications
124
113
  * @param isBare true when the value has none of the type-specific prefixes (internal)
125
114
  */
126
115
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
127
-
128
-
129
116
  toU8a(isBare) {
130
117
  return new Uint8Array([this.valueOf() ? 1 : 0]);
131
118
  }
132
-
133
119
  }
package/native/Date.js CHANGED
@@ -1,12 +1,12 @@
1
1
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+
3
4
  import { BN, bnToBn, bnToHex, bnToU8a, isString, isU8a, u8aToBn } from '@polkadot/util';
4
5
  const BITLENGTH = 64;
5
6
  const U8A_OPTS = {
6
7
  bitLength: BITLENGTH,
7
8
  isLe: true
8
9
  };
9
-
10
10
  function decodeDate(value) {
11
11
  if (isU8a(value)) {
12
12
  value = u8aToBn(value.subarray(0, BITLENGTH / 8));
@@ -15,9 +15,9 @@ function decodeDate(value) {
15
15
  } else if (isString(value)) {
16
16
  value = new BN(value.toString(), 10, 'le');
17
17
  }
18
-
19
18
  return new Date(bnToBn(value).toNumber() * 1000);
20
19
  }
20
+
21
21
  /**
22
22
  * @name Date
23
23
  * @description
@@ -28,84 +28,73 @@ function decodeDate(value) {
28
28
  * and has all the methods available that are applicable to any `Date`
29
29
  * @noInheritDoc
30
30
  */
31
-
32
-
33
31
  export class CodecDate extends Date {
34
32
  constructor(registry, value = 0) {
35
33
  super(decodeDate(value));
36
34
  this.registry = registry;
37
35
  }
36
+
38
37
  /**
39
38
  * @description The length of the value when encoded as a Uint8Array
40
39
  */
41
-
42
-
43
40
  get encodedLength() {
44
41
  return BITLENGTH / 8;
45
42
  }
43
+
46
44
  /**
47
45
  * @description returns a hash of the contents
48
46
  */
49
-
50
-
51
47
  get hash() {
52
48
  return this.registry.hash(this.toU8a());
53
49
  }
50
+
54
51
  /**
55
52
  * @description Checks if the value is an empty value
56
53
  */
57
-
58
-
59
54
  get isEmpty() {
60
55
  return this.getTime() === 0;
61
56
  }
57
+
62
58
  /**
63
59
  * @description Returns the number of bits in the value
64
60
  */
65
-
66
-
67
61
  bitLength() {
68
62
  return BITLENGTH;
69
63
  }
64
+
70
65
  /**
71
66
  * @description Compares the value of the input to see if there is a match
72
67
  */
73
-
74
-
75
68
  eq(other) {
76
69
  return decodeDate(other).getTime() === this.getTime();
77
70
  }
71
+
78
72
  /**
79
73
  * @description Returns a breakdown of the hex encoding for this Codec
80
74
  */
81
-
82
-
83
75
  inspect() {
84
76
  return {
85
77
  outer: [this.toU8a()]
86
78
  };
87
79
  }
80
+
88
81
  /**
89
82
  * @description Returns a BigInt representation of the number
90
83
  */
91
-
92
-
93
84
  toBigInt() {
94
85
  return BigInt(this.toNumber());
95
86
  }
87
+
96
88
  /**
97
89
  * @description Returns the BN representation of the timestamp
98
90
  */
99
-
100
-
101
91
  toBn() {
102
92
  return new BN(this.toNumber());
103
93
  }
94
+
104
95
  /**
105
96
  * @description Returns a hex string representation of the value
106
97
  */
107
-
108
-
109
98
  toHex(isLe = false) {
110
99
  return bnToHex(this.toBn(), {
111
100
  bitLength: BITLENGTH,
@@ -113,66 +102,58 @@ export class CodecDate extends Date {
113
102
  isNegative: false
114
103
  });
115
104
  }
105
+
116
106
  /**
117
107
  * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
118
108
  */
119
-
120
-
121
109
  toHuman() {
122
110
  return this.toISOString();
123
111
  }
112
+
124
113
  /**
125
114
  * @description Converts the Object to JSON, typically used for RPC transfers
126
115
  */
127
-
128
-
129
116
  toJSON() {
130
117
  // FIXME Return type should be number, but conflicts with Date.toJSON()
131
118
  // which returns string
132
119
  return this.toNumber();
133
120
  }
121
+
134
122
  /**
135
123
  * @description Returns the number representation for the timestamp
136
124
  */
137
-
138
-
139
125
  toNumber() {
140
126
  return Math.ceil(this.getTime() / 1000);
141
127
  }
128
+
142
129
  /**
143
130
  * @description Converts the value in a best-fit primitive form
144
131
  */
145
-
146
-
147
132
  toPrimitive() {
148
133
  return this.toNumber();
149
134
  }
135
+
150
136
  /**
151
137
  * @description Returns the base runtime type name for this instance
152
138
  */
153
-
154
-
155
139
  toRawType() {
156
140
  return 'Moment';
157
141
  }
142
+
158
143
  /**
159
144
  * @description Returns the string representation of the value
160
145
  */
161
-
162
-
163
146
  toString() {
164
147
  // only included here since we do not inherit docs
165
148
  return super.toString();
166
149
  }
150
+
167
151
  /**
168
152
  * @description Encodes the value as a Uint8Array as per the SCALE specifications
169
153
  * @param isBare true when the value has none of the type-specific prefixes (internal)
170
154
  */
171
155
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
172
-
173
-
174
156
  toU8a(isBare) {
175
157
  return bnToU8a(this.toNumber(), U8A_OPTS);
176
158
  }
177
-
178
159
  }
package/native/Float.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
- import { floatToU8a, isHex, isU8a, u8aToFloat, u8aToHex, u8aToU8a } from '@polkadot/util';
4
3
 
4
+ import { floatToU8a, isHex, isU8a, u8aToFloat, u8aToHex, u8aToU8a } from '@polkadot/util';
5
5
  /**
6
6
  * @name Float
7
7
  * @description
@@ -12,7 +12,6 @@ import { floatToU8a, isHex, isU8a, u8aToFloat, u8aToHex, u8aToU8a } from '@polka
12
12
  */
13
13
  export class Float extends Number {
14
14
  #bitLength;
15
-
16
15
  constructor(registry, value, {
17
16
  bitLength = 32
18
17
  } = {}) {
@@ -24,7 +23,6 @@ export class Float extends Number {
24
23
  this.initialU8aLength = this.encodedLength;
25
24
  this.registry = registry;
26
25
  }
27
-
28
26
  static with(bitLength) {
29
27
  return class extends Float {
30
28
  constructor(registry, value) {
@@ -32,102 +30,89 @@ export class Float extends Number {
32
30
  bitLength
33
31
  });
34
32
  }
35
-
36
33
  };
37
34
  }
35
+
38
36
  /**
39
37
  * @description returns a hash of the contents
40
38
  */
41
-
42
-
43
39
  get hash() {
44
40
  return this.registry.hash(this.toU8a());
45
41
  }
42
+
46
43
  /**
47
44
  * @description Returns true if the type wraps an empty/default all-0 value
48
45
  */
49
-
50
-
51
46
  get isEmpty() {
52
47
  return this.valueOf() === 0;
53
48
  }
49
+
54
50
  /**
55
51
  * @description Compares the value of the input to see if there is a match
56
52
  */
57
-
58
-
59
53
  eq(other) {
60
54
  return this.valueOf() === Number(other);
61
55
  }
56
+
62
57
  /**
63
58
  * @description Returns a breakdown of the hex encoding for this Codec
64
59
  */
65
-
66
-
67
60
  inspect() {
68
61
  return {
69
62
  outer: [this.toU8a()]
70
63
  };
71
64
  }
65
+
72
66
  /**
73
67
  * @description Returns a hex string representation of the value
74
68
  */
75
-
76
-
77
69
  toHex() {
78
70
  return u8aToHex(this.toU8a());
79
71
  }
72
+
80
73
  /**
81
74
  * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
82
75
  */
83
-
84
-
85
76
  toHuman() {
86
77
  return this.toString();
87
78
  }
79
+
88
80
  /**
89
81
  * @description Converts the Object to JSON, typically used for RPC transfers
90
82
  */
91
-
92
-
93
83
  toJSON() {
94
84
  // Not sure if this is actually a hex or a string value
95
85
  // (would need to check against RPCs to see the result here)
96
86
  return this.toHex();
97
87
  }
88
+
98
89
  /**
99
90
  * @description Returns the number representation (Same as valueOf)
100
91
  */
101
-
102
-
103
92
  toNumber() {
104
93
  return this.valueOf();
105
94
  }
95
+
106
96
  /**
107
97
  * @description Converts the value in a best-fit primitive form
108
98
  */
109
-
110
-
111
99
  toPrimitive() {
112
100
  return this.toNumber();
113
101
  }
102
+
114
103
  /**
115
104
  * @description Returns the base runtime type name for this instance
116
105
  */
117
-
118
-
119
106
  toRawType() {
120
107
  return `f${this.#bitLength}`;
121
108
  }
109
+
122
110
  /**
123
111
  * @description Encodes the value as a Uint8Array as per the SCALE specifications
124
112
  */
125
-
126
-
127
113
  toU8a() {
128
114
  return floatToU8a(this, {
129
115
  bitLength: this.#bitLength
130
116
  });
131
117
  }
132
-
133
118
  }
package/native/Json.js CHANGED
@@ -1,12 +1,14 @@
1
1
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+
3
4
  import { isFunction, objectProperties, stringify } from '@polkadot/util';
4
5
  import { compareMap } from "../utils/index.js";
5
- /** @internal */
6
6
 
7
+ /** @internal */
7
8
  function decodeJson(value) {
8
9
  return Object.entries(value || {});
9
10
  }
11
+
10
12
  /**
11
13
  * @name Json
12
14
  * @description
@@ -15,8 +17,6 @@ function decodeJson(value) {
15
17
  * i.e. no hex decoding. Unlike a struct, this waps a JSON object with unknown keys
16
18
  * @noInheritDoc
17
19
  */
18
-
19
-
20
20
  export class Json extends Map {
21
21
  constructor(registry, value) {
22
22
  const decoded = decodeJson(value);
@@ -24,119 +24,105 @@ export class Json extends Map {
24
24
  this.registry = registry;
25
25
  objectProperties(this, decoded.map(([k]) => k), k => this.get(k));
26
26
  }
27
+
27
28
  /**
28
29
  * @description Always 0, never encodes as a Uint8Array
29
30
  */
30
-
31
-
32
31
  get encodedLength() {
33
32
  return 0;
34
33
  }
34
+
35
35
  /**
36
36
  * @description returns a hash of the contents
37
37
  */
38
-
39
-
40
38
  get hash() {
41
39
  return this.registry.hash(this.toU8a());
42
40
  }
41
+
43
42
  /**
44
43
  * @description Checks if the value is an empty value
45
44
  */
46
-
47
-
48
45
  get isEmpty() {
49
46
  return [...this.keys()].length === 0;
50
47
  }
48
+
51
49
  /**
52
50
  * @description Compares the value of the input to see if there is a match
53
51
  */
54
-
55
-
56
52
  eq(other) {
57
53
  return compareMap(this, other);
58
54
  }
55
+
59
56
  /**
60
57
  * @description Returns a typed value from the internal map
61
58
  */
62
-
63
-
64
59
  getT(key) {
65
60
  return this.get(key);
66
61
  }
62
+
67
63
  /**
68
64
  * @description Unimplemented, will throw
69
65
  */
70
-
71
-
72
66
  inspect() {
73
67
  throw new Error('Unimplemented');
74
68
  }
69
+
75
70
  /**
76
71
  * @description Unimplemented, will throw
77
72
  */
78
-
79
-
80
73
  toHex() {
81
74
  throw new Error('Unimplemented');
82
75
  }
76
+
83
77
  /**
84
78
  * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
85
79
  */
86
-
87
-
88
80
  toHuman() {
89
81
  return [...this.entries()].reduce((json, [key, value]) => {
90
82
  json[key] = isFunction(value.toHuman) ? value.toHuman() : value;
91
83
  return json;
92
84
  }, {});
93
85
  }
86
+
94
87
  /**
95
88
  * @description Converts the Object to JSON, typically used for RPC transfers
96
89
  */
97
-
98
-
99
90
  toJSON() {
100
91
  return [...this.entries()].reduce((json, [key, value]) => {
101
92
  json[key] = value;
102
93
  return json;
103
94
  }, {});
104
95
  }
96
+
105
97
  /**
106
98
  * @description Converts the value in a best-fit primitive form
107
99
  */
108
-
109
-
110
100
  toPrimitive() {
111
101
  return [...this.entries()].reduce((json, [key, value]) => {
112
102
  json[key] = isFunction(value.toHuman) ? value.toPrimitive() : value;
113
103
  return json;
114
104
  }, {});
115
105
  }
106
+
116
107
  /**
117
108
  * @description Returns the base runtime type name for this instance
118
109
  */
119
-
120
-
121
110
  toRawType() {
122
111
  return 'Json';
123
112
  }
113
+
124
114
  /**
125
115
  * @description Returns the string representation of the value
126
116
  */
127
-
128
-
129
117
  toString() {
130
118
  return stringify(this.toJSON());
131
119
  }
120
+
132
121
  /**
133
122
  * @description Unimplemented, will throw
134
123
  */
135
124
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
136
-
137
-
138
125
  toU8a(isBare) {
139
126
  throw new Error('Unimplemented');
140
127
  }
141
-
142
128
  }