@polkadot/types-codec 6.12.2-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 (214) hide show
  1. package/abstract/AbstractArray.cjs +208 -0
  2. package/abstract/AbstractArray.d.ts +84 -0
  3. package/abstract/AbstractArray.js +197 -0
  4. package/abstract/AbstractInt.cjs +254 -0
  5. package/abstract/AbstractInt.d.ts +75 -0
  6. package/abstract/AbstractInt.js +231 -0
  7. package/abstract/index.cjs +21 -0
  8. package/abstract/index.d.ts +2 -0
  9. package/abstract/index.js +4 -0
  10. package/base/Base.cjs +109 -0
  11. package/base/Base.d.ts +54 -0
  12. package/base/Base.js +100 -0
  13. package/base/Compact.cjs +201 -0
  14. package/base/Compact.d.ts +83 -0
  15. package/base/Compact.js +186 -0
  16. package/base/DoNotConstruct.cjs +101 -0
  17. package/base/DoNotConstruct.d.ts +33 -0
  18. package/base/DoNotConstruct.js +88 -0
  19. package/base/Enum.cjs +437 -0
  20. package/base/Enum.d.ts +101 -0
  21. package/base/Enum.js +413 -0
  22. package/base/Int.cjs +45 -0
  23. package/base/Int.d.ts +16 -0
  24. package/base/Int.js +33 -0
  25. package/base/Null.cjs +111 -0
  26. package/base/Null.d.ts +54 -0
  27. package/base/Null.js +101 -0
  28. package/base/Option.cjs +256 -0
  29. package/base/Option.d.ts +88 -0
  30. package/base/Option.js +240 -0
  31. package/base/Result.cjs +109 -0
  32. package/base/Result.d.ts +46 -0
  33. package/base/Result.js +98 -0
  34. package/base/Tuple.cjs +132 -0
  35. package/base/Tuple.d.ts +39 -0
  36. package/base/Tuple.js +116 -0
  37. package/base/UInt.cjs +39 -0
  38. package/base/UInt.d.ts +15 -0
  39. package/base/UInt.js +29 -0
  40. package/base/Vec.cjs +126 -0
  41. package/base/Vec.d.ts +28 -0
  42. package/base/Vec.js +104 -0
  43. package/base/VecAny.cjs +31 -0
  44. package/base/VecAny.d.ts +15 -0
  45. package/base/VecAny.js +21 -0
  46. package/base/VecFixed.cjs +111 -0
  47. package/base/VecFixed.d.ts +26 -0
  48. package/base/VecFixed.js +93 -0
  49. package/base/index.cjs +109 -0
  50. package/base/index.d.ts +13 -0
  51. package/base/index.js +15 -0
  52. package/bundle.cjs +100 -0
  53. package/bundle.d.ts +7 -0
  54. package/bundle.js +9 -0
  55. package/detectPackage.cjs +9 -0
  56. package/detectPackage.d.ts +1 -0
  57. package/detectPackage.js +5 -0
  58. package/extended/BTreeMap.cjs +24 -0
  59. package/extended/BTreeMap.d.ts +5 -0
  60. package/extended/BTreeMap.js +14 -0
  61. package/extended/BTreeSet.cjs +227 -0
  62. package/extended/BTreeSet.d.ts +55 -0
  63. package/extended/BTreeSet.js +212 -0
  64. package/extended/BitVec.cjs +97 -0
  65. package/extended/BitVec.d.ts +26 -0
  66. package/extended/BitVec.js +82 -0
  67. package/extended/Bytes.cjs +86 -0
  68. package/extended/Bytes.d.ts +25 -0
  69. package/extended/Bytes.js +75 -0
  70. package/extended/HashMap.cjs +24 -0
  71. package/extended/HashMap.d.ts +5 -0
  72. package/extended/HashMap.js +14 -0
  73. package/extended/Linkage.cjs +89 -0
  74. package/extended/Linkage.d.ts +31 -0
  75. package/extended/Linkage.js +71 -0
  76. package/extended/Map.cjs +244 -0
  77. package/extended/Map.d.ts +50 -0
  78. package/extended/Map.js +225 -0
  79. package/extended/Range.cjs +92 -0
  80. package/extended/Range.d.ts +30 -0
  81. package/extended/Range.js +75 -0
  82. package/extended/Type.cjs +39 -0
  83. package/extended/Type.d.ts +16 -0
  84. package/extended/Type.js +27 -0
  85. package/extended/U8aFixed.cjs +66 -0
  86. package/extended/U8aFixed.d.ts +16 -0
  87. package/extended/U8aFixed.js +53 -0
  88. package/extended/WrapperOpaque.cjs +68 -0
  89. package/extended/WrapperOpaque.d.ts +18 -0
  90. package/extended/WrapperOpaque.js +57 -0
  91. package/extended/index.cjs +105 -0
  92. package/extended/index.d.ts +11 -0
  93. package/extended/index.js +13 -0
  94. package/index.cjs +20 -0
  95. package/index.d.ts +2 -0
  96. package/index.js +4 -0
  97. package/native/Bool.cjs +141 -0
  98. package/native/Bool.d.ts +62 -0
  99. package/native/Bool.js +130 -0
  100. package/native/Date.cjs +170 -0
  101. package/native/Date.d.ts +76 -0
  102. package/native/Date.js +158 -0
  103. package/native/Json.cjs +133 -0
  104. package/native/Json.d.ts +55 -0
  105. package/native/Json.js +117 -0
  106. package/native/Raw.cjs +192 -0
  107. package/native/Raw.d.ts +90 -0
  108. package/native/Raw.js +182 -0
  109. package/native/Set.cjs +268 -0
  110. package/native/Set.d.ts +76 -0
  111. package/native/Set.js +251 -0
  112. package/native/Struct.cjs +289 -0
  113. package/native/Struct.d.ts +92 -0
  114. package/native/Struct.js +273 -0
  115. package/native/Text.cjs +193 -0
  116. package/native/Text.d.ts +71 -0
  117. package/native/Text.js +178 -0
  118. package/native/index.cjs +79 -0
  119. package/native/index.d.ts +7 -0
  120. package/native/index.js +9 -0
  121. package/package.json +387 -0
  122. package/packageInfo.cjs +14 -0
  123. package/packageInfo.d.ts +4 -0
  124. package/packageInfo.js +7 -0
  125. package/primitive/I128.cjs +26 -0
  126. package/primitive/I128.d.ts +11 -0
  127. package/primitive/I128.js +16 -0
  128. package/primitive/I16.cjs +26 -0
  129. package/primitive/I16.d.ts +11 -0
  130. package/primitive/I16.js +16 -0
  131. package/primitive/I256.cjs +26 -0
  132. package/primitive/I256.d.ts +11 -0
  133. package/primitive/I256.js +16 -0
  134. package/primitive/I32.cjs +26 -0
  135. package/primitive/I32.d.ts +11 -0
  136. package/primitive/I32.js +16 -0
  137. package/primitive/I64.cjs +26 -0
  138. package/primitive/I64.d.ts +11 -0
  139. package/primitive/I64.js +16 -0
  140. package/primitive/I8.cjs +26 -0
  141. package/primitive/I8.d.ts +11 -0
  142. package/primitive/I8.js +16 -0
  143. package/primitive/U128.cjs +26 -0
  144. package/primitive/U128.d.ts +11 -0
  145. package/primitive/U128.js +16 -0
  146. package/primitive/U16.cjs +26 -0
  147. package/primitive/U16.d.ts +11 -0
  148. package/primitive/U16.js +16 -0
  149. package/primitive/U256.cjs +26 -0
  150. package/primitive/U256.d.ts +11 -0
  151. package/primitive/U256.js +16 -0
  152. package/primitive/U32.cjs +26 -0
  153. package/primitive/U32.d.ts +11 -0
  154. package/primitive/U32.js +16 -0
  155. package/primitive/U64.cjs +26 -0
  156. package/primitive/U64.d.ts +11 -0
  157. package/primitive/U64.js +16 -0
  158. package/primitive/U8.cjs +26 -0
  159. package/primitive/U8.d.ts +11 -0
  160. package/primitive/U8.js +16 -0
  161. package/primitive/USize.cjs +28 -0
  162. package/primitive/USize.d.ts +12 -0
  163. package/primitive/USize.js +18 -0
  164. package/primitive/index.cjs +187 -0
  165. package/primitive/index.d.ts +13 -0
  166. package/primitive/index.js +15 -0
  167. package/types/codec.cjs +1 -0
  168. package/types/codec.d.ts +77 -0
  169. package/types/codec.js +1 -0
  170. package/types/helpers.cjs +1 -0
  171. package/types/helpers.d.ts +14 -0
  172. package/types/helpers.js +1 -0
  173. package/types/index.cjs +57 -0
  174. package/types/index.d.ts +4 -0
  175. package/types/index.js +6 -0
  176. package/types/interfaces.cjs +1 -0
  177. package/types/interfaces.d.ts +68 -0
  178. package/types/interfaces.js +1 -0
  179. package/types/registry.cjs +1 -0
  180. package/types/registry.d.ts +44 -0
  181. package/types/registry.js +1 -0
  182. package/utils/compareArray.cjs +22 -0
  183. package/utils/compareArray.d.ts +1 -0
  184. package/utils/compareArray.js +13 -0
  185. package/utils/compareMap.cjs +39 -0
  186. package/utils/compareMap.d.ts +1 -0
  187. package/utils/compareMap.js +31 -0
  188. package/utils/compareSet.cjs +29 -0
  189. package/utils/compareSet.d.ts +1 -0
  190. package/utils/compareSet.js +22 -0
  191. package/utils/decodeU8a.cjs +69 -0
  192. package/utils/decodeU8a.d.ts +13 -0
  193. package/utils/decodeU8a.js +60 -0
  194. package/utils/index.cjs +95 -0
  195. package/utils/index.d.ts +9 -0
  196. package/utils/index.js +11 -0
  197. package/utils/mapToTypeMap.cjs +25 -0
  198. package/utils/mapToTypeMap.d.ts +5 -0
  199. package/utils/mapToTypeMap.js +17 -0
  200. package/utils/sanitize.cjs +242 -0
  201. package/utils/sanitize.d.ts +16 -0
  202. package/utils/sanitize.js +215 -0
  203. package/utils/sortValues.cjs +89 -0
  204. package/utils/sortValues.d.ts +13 -0
  205. package/utils/sortValues.js +73 -0
  206. package/utils/typeToConstructor.cjs +14 -0
  207. package/utils/typeToConstructor.d.ts +2 -0
  208. package/utils/typeToConstructor.js +6 -0
  209. package/utils/typesToMap.cjs +20 -0
  210. package/utils/typesToMap.d.ts +2 -0
  211. package/utils/typesToMap.js +13 -0
  212. package/utils/util.cjs +15 -0
  213. package/utils/util.d.ts +3 -0
  214. package/utils/util.js +7 -0
package/base/Null.cjs ADDED
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Null = void 0;
7
+
8
+ var _util = require("@polkadot/util");
9
+
10
+ // Copyright 2017-2021 @polkadot/types-codec authors & contributors
11
+ // SPDX-License-Identifier: Apache-2.0
12
+
13
+ /**
14
+ * @name Null
15
+ * @description
16
+ * Implements a type that does not contain anything (apart from `null`)
17
+ */
18
+ class Null {
19
+ // Added for compatibility reasons, e.g. see Option
20
+ constructor(registry) {
21
+ this.registry = void 0;
22
+ this.createdAtHash = void 0;
23
+ this.initialU8aLength = 0;
24
+ this.registry = registry;
25
+ }
26
+ /**
27
+ * @description The length of the value when encoded as a Uint8Array
28
+ */
29
+
30
+
31
+ get encodedLength() {
32
+ return 0;
33
+ }
34
+ /**
35
+ * @description returns a hash of the contents
36
+ */
37
+
38
+
39
+ get hash() {
40
+ throw new Error('.hash is not implemented on Null');
41
+ }
42
+ /**
43
+ * @description Checks if the value is an empty value (always true)
44
+ */
45
+
46
+
47
+ get isEmpty() {
48
+ return true;
49
+ }
50
+ /**
51
+ * @description Compares the value of the input to see if there is a match
52
+ */
53
+
54
+
55
+ eq(other) {
56
+ return other instanceof Null || (0, _util.isNull)(other);
57
+ }
58
+ /**
59
+ * @description Returns a hex string representation of the value
60
+ */
61
+
62
+
63
+ toHex() {
64
+ return '0x';
65
+ }
66
+ /**
67
+ * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
68
+ */
69
+
70
+
71
+ toHuman() {
72
+ return this.toJSON();
73
+ }
74
+ /**
75
+ * @description Converts the Object to JSON, typically used for RPC transfers
76
+ */
77
+
78
+
79
+ toJSON() {
80
+ return null;
81
+ }
82
+ /**
83
+ * @description Returns the base runtime type name for this instance
84
+ */
85
+
86
+
87
+ toRawType() {
88
+ return 'Null';
89
+ }
90
+ /**
91
+ * @description Returns the string representation of the value
92
+ */
93
+
94
+
95
+ toString() {
96
+ return '';
97
+ }
98
+ /**
99
+ * @description Encodes the value as a Uint8Array as per the SCALE specifications
100
+ * @param isBare true when the value has none of the type-specific prefixes (internal)
101
+ */
102
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
103
+
104
+
105
+ toU8a(isBare) {
106
+ return new Uint8Array();
107
+ }
108
+
109
+ }
110
+
111
+ exports.Null = Null;
package/base/Null.d.ts ADDED
@@ -0,0 +1,54 @@
1
+ import type { HexString } from '@polkadot/util/types';
2
+ import type { Codec, CodecRegistry, IU8a } from '../types';
3
+ /**
4
+ * @name Null
5
+ * @description
6
+ * Implements a type that does not contain anything (apart from `null`)
7
+ */
8
+ export declare class Null implements Codec {
9
+ readonly registry: CodecRegistry;
10
+ createdAtHash?: IU8a;
11
+ readonly initialU8aLength = 0;
12
+ constructor(registry: CodecRegistry);
13
+ /**
14
+ * @description The length of the value when encoded as a Uint8Array
15
+ */
16
+ get encodedLength(): number;
17
+ /**
18
+ * @description returns a hash of the contents
19
+ */
20
+ get hash(): IU8a;
21
+ /**
22
+ * @description Checks if the value is an empty value (always true)
23
+ */
24
+ get isEmpty(): boolean;
25
+ /**
26
+ * @description Compares the value of the input to see if there is a match
27
+ */
28
+ eq(other?: unknown): boolean;
29
+ /**
30
+ * @description Returns a hex string representation of the value
31
+ */
32
+ toHex(): HexString;
33
+ /**
34
+ * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
35
+ */
36
+ toHuman(): null;
37
+ /**
38
+ * @description Converts the Object to JSON, typically used for RPC transfers
39
+ */
40
+ toJSON(): null;
41
+ /**
42
+ * @description Returns the base runtime type name for this instance
43
+ */
44
+ toRawType(): string;
45
+ /**
46
+ * @description Returns the string representation of the value
47
+ */
48
+ toString(): string;
49
+ /**
50
+ * @description Encodes the value as a Uint8Array as per the SCALE specifications
51
+ * @param isBare true when the value has none of the type-specific prefixes (internal)
52
+ */
53
+ toU8a(isBare?: boolean): Uint8Array;
54
+ }
package/base/Null.js ADDED
@@ -0,0 +1,101 @@
1
+ // Copyright 2017-2021 @polkadot/types-codec authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { isNull } from '@polkadot/util';
4
+ /**
5
+ * @name Null
6
+ * @description
7
+ * Implements a type that does not contain anything (apart from `null`)
8
+ */
9
+
10
+ export class Null {
11
+ // Added for compatibility reasons, e.g. see Option
12
+ constructor(registry) {
13
+ this.registry = void 0;
14
+ this.createdAtHash = void 0;
15
+ this.initialU8aLength = 0;
16
+ this.registry = registry;
17
+ }
18
+ /**
19
+ * @description The length of the value when encoded as a Uint8Array
20
+ */
21
+
22
+
23
+ get encodedLength() {
24
+ return 0;
25
+ }
26
+ /**
27
+ * @description returns a hash of the contents
28
+ */
29
+
30
+
31
+ get hash() {
32
+ throw new Error('.hash is not implemented on Null');
33
+ }
34
+ /**
35
+ * @description Checks if the value is an empty value (always true)
36
+ */
37
+
38
+
39
+ get isEmpty() {
40
+ return true;
41
+ }
42
+ /**
43
+ * @description Compares the value of the input to see if there is a match
44
+ */
45
+
46
+
47
+ eq(other) {
48
+ return other instanceof Null || isNull(other);
49
+ }
50
+ /**
51
+ * @description Returns a hex string representation of the value
52
+ */
53
+
54
+
55
+ toHex() {
56
+ return '0x';
57
+ }
58
+ /**
59
+ * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
60
+ */
61
+
62
+
63
+ toHuman() {
64
+ return this.toJSON();
65
+ }
66
+ /**
67
+ * @description Converts the Object to JSON, typically used for RPC transfers
68
+ */
69
+
70
+
71
+ toJSON() {
72
+ return null;
73
+ }
74
+ /**
75
+ * @description Returns the base runtime type name for this instance
76
+ */
77
+
78
+
79
+ toRawType() {
80
+ return 'Null';
81
+ }
82
+ /**
83
+ * @description Returns the string representation of the value
84
+ */
85
+
86
+
87
+ toString() {
88
+ return '';
89
+ }
90
+ /**
91
+ * @description Encodes the value as a Uint8Array as per the SCALE specifications
92
+ * @param isBare true when the value has none of the type-specific prefixes (internal)
93
+ */
94
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
95
+
96
+
97
+ toU8a(isBare) {
98
+ return new Uint8Array();
99
+ }
100
+
101
+ }
@@ -0,0 +1,256 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.Option = void 0;
9
+
10
+ var _classPrivateFieldLooseBase2 = _interopRequireDefault(require("@babel/runtime/helpers/classPrivateFieldLooseBase"));
11
+
12
+ var _classPrivateFieldLooseKey2 = _interopRequireDefault(require("@babel/runtime/helpers/classPrivateFieldLooseKey"));
13
+
14
+ var _util = require("@polkadot/util");
15
+
16
+ var _index = require("../utils/index.cjs");
17
+
18
+ var _Null = require("./Null.cjs");
19
+
20
+ // Copyright 2017-2021 @polkadot/types-codec authors & contributors
21
+ // SPDX-License-Identifier: Apache-2.0
22
+
23
+ /** @internal */
24
+ function decodeOption(registry, Type, value) {
25
+ // In the case of an option, unwrap the inner
26
+ if (value instanceof Option) {
27
+ value = value.value;
28
+ }
29
+
30
+ if ((0, _util.isNull)(value) || (0, _util.isUndefined)(value) || value instanceof _Null.Null || value === '0x') {
31
+ return new _Null.Null(registry);
32
+ } else if (value instanceof Type) {
33
+ // don't re-create, use as it (which also caters for derived types)
34
+ return value;
35
+ } else if ((0, _util.isU8a)(value)) {
36
+ // the isU8a check happens last in the if-tree - since the wrapped value
37
+ // may be an instance of it, so Type and Option checks go in first
38
+ return !value.length || value[0] === 0 ? new _Null.Null(registry) : new Type(registry, value.subarray(1));
39
+ }
40
+
41
+ return new Type(registry, value);
42
+ }
43
+ /**
44
+ * @name Option
45
+ * @description
46
+ * An Option is an optional field. Basically the first byte indicates that there is
47
+ * is value to follow. If the byte is `1` there is an actual value. So the Option
48
+ * implements that - decodes, checks for optionality and wraps the required structure
49
+ * with a value if/as required/found.
50
+ */
51
+
52
+
53
+ var _Type = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("Type");
54
+
55
+ var _initialU8aLength = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("initialU8aLength");
56
+
57
+ var _raw = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("raw");
58
+
59
+ class Option {
60
+ constructor(registry, typeName, value) {
61
+ this.registry = void 0;
62
+ this.createdAtHash = void 0;
63
+ Object.defineProperty(this, _Type, {
64
+ writable: true,
65
+ value: void 0
66
+ });
67
+ Object.defineProperty(this, _initialU8aLength, {
68
+ writable: true,
69
+ value: void 0
70
+ });
71
+ Object.defineProperty(this, _raw, {
72
+ writable: true,
73
+ value: void 0
74
+ });
75
+ const Type = (0, _index.typeToConstructor)(registry, typeName);
76
+ 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);
77
+ this.registry = registry;
78
+ (0, _classPrivateFieldLooseBase2.default)(this, _Type)[_Type] = Type;
79
+ (0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw] = decoded;
80
+
81
+ if (decoded.initialU8aLength) {
82
+ (0, _classPrivateFieldLooseBase2.default)(this, _initialU8aLength)[_initialU8aLength] = 1 + decoded.initialU8aLength;
83
+ }
84
+ }
85
+
86
+ static with(Type) {
87
+ return class extends Option {
88
+ constructor(registry, value) {
89
+ super(registry, Type, value);
90
+ }
91
+
92
+ };
93
+ }
94
+ /**
95
+ * @description The length of the value when encoded as a Uint8Array
96
+ */
97
+
98
+
99
+ get encodedLength() {
100
+ // boolean byte (has value, doesn't have) along with wrapped length
101
+ return 1 + (0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw].encodedLength;
102
+ }
103
+ /**
104
+ * @description The length of the initial encoded value (Only available when constructed from a Uint8Array)
105
+ */
106
+
107
+
108
+ get initialU8aLength() {
109
+ return (0, _classPrivateFieldLooseBase2.default)(this, _initialU8aLength)[_initialU8aLength];
110
+ }
111
+ /**
112
+ * @description returns a hash of the contents
113
+ */
114
+
115
+
116
+ get hash() {
117
+ return this.registry.hash(this.toU8a());
118
+ }
119
+ /**
120
+ * @description Checks if the Option has no value
121
+ */
122
+
123
+
124
+ get isEmpty() {
125
+ return this.isNone;
126
+ }
127
+ /**
128
+ * @description Checks if the Option has no value
129
+ */
130
+
131
+
132
+ get isNone() {
133
+ return (0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw] instanceof _Null.Null;
134
+ }
135
+ /**
136
+ * @description Checks if the Option has a value
137
+ */
138
+
139
+
140
+ get isSome() {
141
+ return !this.isNone;
142
+ }
143
+ /**
144
+ * @description The actual value for the Option
145
+ */
146
+
147
+
148
+ get value() {
149
+ return (0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw];
150
+ }
151
+ /**
152
+ * @description Compares the value of the input to see if there is a match
153
+ */
154
+
155
+
156
+ eq(other) {
157
+ if (other instanceof Option) {
158
+ return this.isSome === other.isSome && this.value.eq(other.value);
159
+ }
160
+
161
+ return this.value.eq(other);
162
+ }
163
+ /**
164
+ * @description Returns a hex string representation of the value
165
+ */
166
+
167
+
168
+ toHex() {
169
+ // This attempts to align with the JSON encoding - actually in this case
170
+ // the isSome value is correct, however the `isNone` may be problematic
171
+ return this.isNone ? '0x' : (0, _util.u8aToHex)(this.toU8a().subarray(1));
172
+ }
173
+ /**
174
+ * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
175
+ */
176
+
177
+
178
+ toHuman(isExtended) {
179
+ return (0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw].toHuman(isExtended);
180
+ }
181
+ /**
182
+ * @description Converts the Object to JSON, typically used for RPC transfers
183
+ */
184
+
185
+
186
+ toJSON() {
187
+ return this.isNone ? null : (0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw].toJSON();
188
+ }
189
+ /**
190
+ * @description Returns the base runtime type name for this instance
191
+ */
192
+
193
+
194
+ toRawType(isBare) {
195
+ const wrapped = this.registry.getClassName((0, _classPrivateFieldLooseBase2.default)(this, _Type)[_Type]) || new ((0, _classPrivateFieldLooseBase2.default)(this, _Type)[_Type])(this.registry).toRawType();
196
+ return isBare ? wrapped : `Option<${wrapped}>`;
197
+ }
198
+ /**
199
+ * @description Returns the string representation of the value
200
+ */
201
+
202
+
203
+ toString() {
204
+ return (0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw].toString();
205
+ }
206
+ /**
207
+ * @description Encodes the value as a Uint8Array as per the SCALE specifications
208
+ * @param isBare true when the value has none of the type-specific prefixes (internal)
209
+ */
210
+
211
+
212
+ toU8a(isBare) {
213
+ if (isBare) {
214
+ return (0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw].toU8a(true);
215
+ }
216
+
217
+ const u8a = new Uint8Array(this.encodedLength);
218
+
219
+ if (this.isSome) {
220
+ u8a.set([1]);
221
+ u8a.set((0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw].toU8a(), 1);
222
+ }
223
+
224
+ return u8a;
225
+ }
226
+ /**
227
+ * @description Returns the value that the Option represents (if available), throws if null
228
+ */
229
+
230
+
231
+ unwrap() {
232
+ (0, _util.assert)(this.isSome, 'Option: unwrapping a None value');
233
+ return (0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw];
234
+ }
235
+ /**
236
+ * @description Returns the value that the Option represents (if available) or defaultValue if none
237
+ * @param defaultValue The value to return if the option isNone
238
+ */
239
+
240
+
241
+ unwrapOr(defaultValue) {
242
+ return this.isSome ? this.unwrap() : defaultValue;
243
+ }
244
+ /**
245
+ * @description Returns the value that the Option represents (if available) or defaultValue if none
246
+ * @param defaultValue The value to return if the option isNone
247
+ */
248
+
249
+
250
+ unwrapOrDefault() {
251
+ return this.isSome ? this.unwrap() : new ((0, _classPrivateFieldLooseBase2.default)(this, _Type)[_Type])(this.registry);
252
+ }
253
+
254
+ }
255
+
256
+ exports.Option = Option;
@@ -0,0 +1,88 @@
1
+ import type { HexString } from '@polkadot/util/types';
2
+ import type { AnyJson, Codec, CodecClass, CodecRegistry, IOption, IU8a } from '../types';
3
+ /**
4
+ * @name Option
5
+ * @description
6
+ * An Option is an optional field. Basically the first byte indicates that there is
7
+ * is value to follow. If the byte is `1` there is an actual value. So the Option
8
+ * implements that - decodes, checks for optionality and wraps the required structure
9
+ * with a value if/as required/found.
10
+ */
11
+ export declare class Option<T extends Codec> implements IOption<T> {
12
+ #private;
13
+ readonly registry: CodecRegistry;
14
+ createdAtHash?: IU8a;
15
+ constructor(registry: CodecRegistry, typeName: CodecClass<T> | string, value?: unknown);
16
+ static with<O extends Codec>(Type: CodecClass<O> | string): CodecClass<Option<O>>;
17
+ /**
18
+ * @description The length of the value when encoded as a Uint8Array
19
+ */
20
+ get encodedLength(): number;
21
+ /**
22
+ * @description The length of the initial encoded value (Only available when constructed from a Uint8Array)
23
+ */
24
+ get initialU8aLength(): number | undefined;
25
+ /**
26
+ * @description returns a hash of the contents
27
+ */
28
+ get hash(): IU8a;
29
+ /**
30
+ * @description Checks if the Option has no value
31
+ */
32
+ get isEmpty(): boolean;
33
+ /**
34
+ * @description Checks if the Option has no value
35
+ */
36
+ get isNone(): boolean;
37
+ /**
38
+ * @description Checks if the Option has a value
39
+ */
40
+ get isSome(): boolean;
41
+ /**
42
+ * @description The actual value for the Option
43
+ */
44
+ get value(): Codec;
45
+ /**
46
+ * @description Compares the value of the input to see if there is a match
47
+ */
48
+ eq(other?: unknown): boolean;
49
+ /**
50
+ * @description Returns a hex string representation of the value
51
+ */
52
+ toHex(): HexString;
53
+ /**
54
+ * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
55
+ */
56
+ toHuman(isExtended?: boolean): AnyJson;
57
+ /**
58
+ * @description Converts the Object to JSON, typically used for RPC transfers
59
+ */
60
+ toJSON(): AnyJson;
61
+ /**
62
+ * @description Returns the base runtime type name for this instance
63
+ */
64
+ toRawType(isBare?: boolean): string;
65
+ /**
66
+ * @description Returns the string representation of the value
67
+ */
68
+ toString(): string;
69
+ /**
70
+ * @description Encodes the value as a Uint8Array as per the SCALE specifications
71
+ * @param isBare true when the value has none of the type-specific prefixes (internal)
72
+ */
73
+ toU8a(isBare?: boolean): Uint8Array;
74
+ /**
75
+ * @description Returns the value that the Option represents (if available), throws if null
76
+ */
77
+ unwrap(): T;
78
+ /**
79
+ * @description Returns the value that the Option represents (if available) or defaultValue if none
80
+ * @param defaultValue The value to return if the option isNone
81
+ */
82
+ unwrapOr<O>(defaultValue: O): T | O;
83
+ /**
84
+ * @description Returns the value that the Option represents (if available) or defaultValue if none
85
+ * @param defaultValue The value to return if the option isNone
86
+ */
87
+ unwrapOrDefault(): T;
88
+ }