@polkadot/types-codec 6.12.2-10

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 +137 -0
  11. package/base/Base.d.ts +56 -0
  12. package/base/Base.js +125 -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 +445 -0
  20. package/base/Enum.d.ts +105 -0
  21. package/base/Enum.js +421 -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 +60 -0
  89. package/extended/WrapperOpaque.d.ts +14 -0
  90. package/extended/WrapperOpaque.js +49 -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 +137 -0
  104. package/native/Json.d.ts +56 -0
  105. package/native/Json.js +121 -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 +302 -0
  113. package/native/Struct.d.ts +93 -0
  114. package/native/Struct.js +286 -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 +69 -0
  178. package/types/interfaces.js +1 -0
  179. package/types/registry.cjs +1 -0
  180. package/types/registry.d.ts +61 -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
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.BitVec = 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 _Raw = require("../native/Raw.cjs");
17
+
18
+ // Copyright 2017-2021 @polkadot/types-codec authors & contributors
19
+ // SPDX-License-Identifier: Apache-2.0
20
+
21
+ /** @internal */
22
+ function decodeBitVecU8a(value) {
23
+ if (!value || !value.length) {
24
+ return [0, new Uint8Array()];
25
+ } // handle all other Uint8Array inputs, these do have a length prefix which is the number of bits encoded
26
+
27
+
28
+ const [offset, length] = (0, _util.compactFromU8a)(value);
29
+ const total = offset + Math.ceil(length.toNumber() / 8);
30
+ (0, _util.assert)(total <= value.length, () => `BitVec: required length less than remainder, expected at least ${total}, found ${value.length}`);
31
+ return [length.toNumber(), value.subarray(offset, total)];
32
+ }
33
+ /** @internal */
34
+
35
+
36
+ function decodeBitVec(value) {
37
+ if (Array.isArray(value) || (0, _util.isString)(value)) {
38
+ const u8a = (0, _util.u8aToU8a)(value);
39
+ return [u8a.length / 8, u8a];
40
+ }
41
+
42
+ return decodeBitVecU8a(value);
43
+ }
44
+ /**
45
+ * @name BitVec
46
+ * @description
47
+ * A BitVec that represents an array of bits. The bits are however stored encoded. The difference between this
48
+ * and a normal Bytes would be that the length prefix indicates the number of bits encoded, not the bytes
49
+ */
50
+
51
+
52
+ var _decodedLength = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("decodedLength");
53
+
54
+ class BitVec extends _Raw.Raw {
55
+ constructor(registry, value) {
56
+ const [decodedLength, u8a] = decodeBitVec(value);
57
+ super(registry, u8a);
58
+ Object.defineProperty(this, _decodedLength, {
59
+ writable: true,
60
+ value: void 0
61
+ });
62
+ (0, _classPrivateFieldLooseBase2.default)(this, _decodedLength)[_decodedLength] = decodedLength;
63
+ }
64
+ /**
65
+ * @description The length of the value when encoded as a Uint8Array
66
+ */
67
+
68
+
69
+ get encodedLength() {
70
+ return this.length + (0, _util.compactToU8a)((0, _classPrivateFieldLooseBase2.default)(this, _decodedLength)[_decodedLength]).length;
71
+ }
72
+
73
+ toHuman() {
74
+ return `0b${[...this.toU8a(true)].map(d => `00000000${d.toString(2)}`.slice(-8)).join('_')}`;
75
+ }
76
+ /**
77
+ * @description Returns the base runtime type name for this instance
78
+ */
79
+
80
+
81
+ toRawType() {
82
+ return 'BitVec';
83
+ }
84
+ /**
85
+ * @description Encodes the value as a Uint8Array as per the SCALE specifications
86
+ * @param isBare true when the value has none of the type-specific prefixes (internal)
87
+ */
88
+
89
+
90
+ toU8a(isBare) {
91
+ const bitVec = super.toU8a();
92
+ return isBare ? bitVec : (0, _util.u8aConcat)((0, _util.compactToU8a)((0, _classPrivateFieldLooseBase2.default)(this, _decodedLength)[_decodedLength]), bitVec);
93
+ }
94
+
95
+ }
96
+
97
+ exports.BitVec = BitVec;
@@ -0,0 +1,26 @@
1
+ import type { AnyU8a, CodecRegistry } from '../types';
2
+ import { Raw } from '../native/Raw';
3
+ /**
4
+ * @name BitVec
5
+ * @description
6
+ * A BitVec that represents an array of bits. The bits are however stored encoded. The difference between this
7
+ * and a normal Bytes would be that the length prefix indicates the number of bits encoded, not the bytes
8
+ */
9
+ export declare class BitVec extends Raw {
10
+ #private;
11
+ constructor(registry: CodecRegistry, value?: AnyU8a);
12
+ /**
13
+ * @description The length of the value when encoded as a Uint8Array
14
+ */
15
+ get encodedLength(): number;
16
+ toHuman(): string;
17
+ /**
18
+ * @description Returns the base runtime type name for this instance
19
+ */
20
+ toRawType(): string;
21
+ /**
22
+ * @description Encodes the value as a Uint8Array as per the SCALE specifications
23
+ * @param isBare true when the value has none of the type-specific prefixes (internal)
24
+ */
25
+ toU8a(isBare?: boolean): Uint8Array;
26
+ }
@@ -0,0 +1,82 @@
1
+ import _classPrivateFieldLooseBase from "@babel/runtime/helpers/esm/classPrivateFieldLooseBase";
2
+ import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateFieldLooseKey";
3
+ // Copyright 2017-2021 @polkadot/types-codec authors & contributors
4
+ // SPDX-License-Identifier: Apache-2.0
5
+ import { assert, compactFromU8a, compactToU8a, isString, u8aConcat, u8aToU8a } from '@polkadot/util';
6
+ import { Raw } from "../native/Raw.js";
7
+ /** @internal */
8
+
9
+ function decodeBitVecU8a(value) {
10
+ if (!value || !value.length) {
11
+ return [0, new Uint8Array()];
12
+ } // handle all other Uint8Array inputs, these do have a length prefix which is the number of bits encoded
13
+
14
+
15
+ const [offset, length] = compactFromU8a(value);
16
+ const total = offset + Math.ceil(length.toNumber() / 8);
17
+ assert(total <= value.length, () => `BitVec: required length less than remainder, expected at least ${total}, found ${value.length}`);
18
+ return [length.toNumber(), value.subarray(offset, total)];
19
+ }
20
+ /** @internal */
21
+
22
+
23
+ function decodeBitVec(value) {
24
+ if (Array.isArray(value) || isString(value)) {
25
+ const u8a = u8aToU8a(value);
26
+ return [u8a.length / 8, u8a];
27
+ }
28
+
29
+ return decodeBitVecU8a(value);
30
+ }
31
+ /**
32
+ * @name BitVec
33
+ * @description
34
+ * A BitVec that represents an array of bits. The bits are however stored encoded. The difference between this
35
+ * and a normal Bytes would be that the length prefix indicates the number of bits encoded, not the bytes
36
+ */
37
+
38
+
39
+ var _decodedLength = /*#__PURE__*/_classPrivateFieldLooseKey("decodedLength");
40
+
41
+ export class BitVec extends Raw {
42
+ constructor(registry, value) {
43
+ const [decodedLength, u8a] = decodeBitVec(value);
44
+ super(registry, u8a);
45
+ Object.defineProperty(this, _decodedLength, {
46
+ writable: true,
47
+ value: void 0
48
+ });
49
+ _classPrivateFieldLooseBase(this, _decodedLength)[_decodedLength] = decodedLength;
50
+ }
51
+ /**
52
+ * @description The length of the value when encoded as a Uint8Array
53
+ */
54
+
55
+
56
+ get encodedLength() {
57
+ return this.length + compactToU8a(_classPrivateFieldLooseBase(this, _decodedLength)[_decodedLength]).length;
58
+ }
59
+
60
+ toHuman() {
61
+ return `0b${[...this.toU8a(true)].map(d => `00000000${d.toString(2)}`.slice(-8)).join('_')}`;
62
+ }
63
+ /**
64
+ * @description Returns the base runtime type name for this instance
65
+ */
66
+
67
+
68
+ toRawType() {
69
+ return 'BitVec';
70
+ }
71
+ /**
72
+ * @description Encodes the value as a Uint8Array as per the SCALE specifications
73
+ * @param isBare true when the value has none of the type-specific prefixes (internal)
74
+ */
75
+
76
+
77
+ toU8a(isBare) {
78
+ const bitVec = super.toU8a();
79
+ return isBare ? bitVec : u8aConcat(compactToU8a(_classPrivateFieldLooseBase(this, _decodedLength)[_decodedLength]), bitVec);
80
+ }
81
+
82
+ }
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Bytes = void 0;
7
+
8
+ var _util = require("@polkadot/util");
9
+
10
+ var _Raw = require("../native/Raw.cjs");
11
+
12
+ // Copyright 2017-2021 @polkadot/types-codec authors & contributors
13
+ // SPDX-License-Identifier: Apache-2.0
14
+ // Bytes are used for things like on-chain code, so it has a healthy limit
15
+ const MAX_LENGTH = 10 * 1024 * 1024;
16
+ /** @internal */
17
+
18
+ function decodeBytesU8a(value) {
19
+ if (!value.length) {
20
+ return [new Uint8Array(), 0];
21
+ } // handle all other Uint8Array inputs, these do have a length prefix
22
+
23
+
24
+ const [offset, length] = (0, _util.compactFromU8a)(value);
25
+ const total = offset + length.toNumber();
26
+ (0, _util.assert)(length.lten(MAX_LENGTH), () => `Bytes length ${length.toString()} exceeds ${MAX_LENGTH}`);
27
+ (0, _util.assert)(total <= value.length, () => `Bytes: required length less than remainder, expected at least ${total}, found ${value.length}`);
28
+ return [value.subarray(offset, total), total];
29
+ }
30
+ /** @internal */
31
+
32
+
33
+ function decodeBytes(value) {
34
+ if (Array.isArray(value) || (0, _util.isString)(value)) {
35
+ return [(0, _util.u8aToU8a)(value), 0];
36
+ } else if (!(value instanceof _Raw.Raw) && (0, _util.isU8a)(value)) {
37
+ // We are ensuring we are not a Raw instance. In the case of a Raw we already have gotten
38
+ // rid of the length, i.e. new Bytes(new Bytes(...)) will work as expected
39
+ return decodeBytesU8a(value);
40
+ }
41
+
42
+ return [value, 0];
43
+ }
44
+ /**
45
+ * @name Bytes
46
+ * @description
47
+ * A Bytes wrapper for Vec<u8>. The significant difference between this and a normal Uint8Array
48
+ * is that this version allows for length-encoding. (i.e. it is a variable-item codec, the same
49
+ * as what is found in [[Text]] and [[Vec]])
50
+ */
51
+
52
+
53
+ class Bytes extends _Raw.Raw {
54
+ constructor(registry, value) {
55
+ const [u8a, decodedLength] = decodeBytes(value);
56
+ super(registry, u8a, decodedLength);
57
+ }
58
+ /**
59
+ * @description The length of the value when encoded as a Uint8Array
60
+ */
61
+
62
+
63
+ get encodedLength() {
64
+ return this.length + (0, _util.compactToU8a)(this.length).length;
65
+ }
66
+ /**
67
+ * @description Returns the base runtime type name for this instance
68
+ */
69
+
70
+
71
+ toRawType() {
72
+ return 'Bytes';
73
+ }
74
+ /**
75
+ * @description Encodes the value as a Uint8Array as per the SCALE specifications
76
+ * @param isBare true when the value has none of the type-specific prefixes (internal)
77
+ */
78
+
79
+
80
+ toU8a(isBare) {
81
+ return isBare ? super.toU8a(isBare) : (0, _util.compactAddLength)(this);
82
+ }
83
+
84
+ }
85
+
86
+ exports.Bytes = Bytes;
@@ -0,0 +1,25 @@
1
+ import type { AnyU8a, CodecRegistry } from '../types';
2
+ import { Raw } from '../native/Raw';
3
+ /**
4
+ * @name Bytes
5
+ * @description
6
+ * A Bytes wrapper for Vec<u8>. The significant difference between this and a normal Uint8Array
7
+ * is that this version allows for length-encoding. (i.e. it is a variable-item codec, the same
8
+ * as what is found in [[Text]] and [[Vec]])
9
+ */
10
+ export declare class Bytes extends Raw {
11
+ constructor(registry: CodecRegistry, value?: AnyU8a);
12
+ /**
13
+ * @description The length of the value when encoded as a Uint8Array
14
+ */
15
+ get encodedLength(): number;
16
+ /**
17
+ * @description Returns the base runtime type name for this instance
18
+ */
19
+ toRawType(): string;
20
+ /**
21
+ * @description Encodes the value as a Uint8Array as per the SCALE specifications
22
+ * @param isBare true when the value has none of the type-specific prefixes (internal)
23
+ */
24
+ toU8a(isBare?: boolean): Uint8Array;
25
+ }
@@ -0,0 +1,75 @@
1
+ // Copyright 2017-2021 @polkadot/types-codec authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { assert, compactAddLength, compactFromU8a, compactToU8a, isString, isU8a, u8aToU8a } from '@polkadot/util';
4
+ import { Raw } from "../native/Raw.js"; // Bytes are used for things like on-chain code, so it has a healthy limit
5
+
6
+ const MAX_LENGTH = 10 * 1024 * 1024;
7
+ /** @internal */
8
+
9
+ function decodeBytesU8a(value) {
10
+ if (!value.length) {
11
+ return [new Uint8Array(), 0];
12
+ } // handle all other Uint8Array inputs, these do have a length prefix
13
+
14
+
15
+ const [offset, length] = compactFromU8a(value);
16
+ const total = offset + length.toNumber();
17
+ assert(length.lten(MAX_LENGTH), () => `Bytes length ${length.toString()} exceeds ${MAX_LENGTH}`);
18
+ assert(total <= value.length, () => `Bytes: required length less than remainder, expected at least ${total}, found ${value.length}`);
19
+ return [value.subarray(offset, total), total];
20
+ }
21
+ /** @internal */
22
+
23
+
24
+ function decodeBytes(value) {
25
+ if (Array.isArray(value) || isString(value)) {
26
+ return [u8aToU8a(value), 0];
27
+ } else if (!(value instanceof Raw) && isU8a(value)) {
28
+ // We are ensuring we are not a Raw instance. In the case of a Raw we already have gotten
29
+ // rid of the length, i.e. new Bytes(new Bytes(...)) will work as expected
30
+ return decodeBytesU8a(value);
31
+ }
32
+
33
+ return [value, 0];
34
+ }
35
+ /**
36
+ * @name Bytes
37
+ * @description
38
+ * A Bytes wrapper for Vec<u8>. The significant difference between this and a normal Uint8Array
39
+ * is that this version allows for length-encoding. (i.e. it is a variable-item codec, the same
40
+ * as what is found in [[Text]] and [[Vec]])
41
+ */
42
+
43
+
44
+ export class Bytes extends Raw {
45
+ constructor(registry, value) {
46
+ const [u8a, decodedLength] = decodeBytes(value);
47
+ super(registry, u8a, decodedLength);
48
+ }
49
+ /**
50
+ * @description The length of the value when encoded as a Uint8Array
51
+ */
52
+
53
+
54
+ get encodedLength() {
55
+ return this.length + compactToU8a(this.length).length;
56
+ }
57
+ /**
58
+ * @description Returns the base runtime type name for this instance
59
+ */
60
+
61
+
62
+ toRawType() {
63
+ return 'Bytes';
64
+ }
65
+ /**
66
+ * @description Encodes the value as a Uint8Array as per the SCALE specifications
67
+ * @param isBare true when the value has none of the type-specific prefixes (internal)
68
+ */
69
+
70
+
71
+ toU8a(isBare) {
72
+ return isBare ? super.toU8a(isBare) : compactAddLength(this);
73
+ }
74
+
75
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.HashMap = void 0;
7
+
8
+ var _Map = require("./Map.cjs");
9
+
10
+ // Copyright 2017-2021 @polkadot/types-codec authors & contributors
11
+ // SPDX-License-Identifier: Apache-2.0
12
+ class HashMap extends _Map.CodecMap {
13
+ static with(keyType, valType) {
14
+ return class extends HashMap {
15
+ constructor(registry, value) {
16
+ super(registry, keyType, valType, value);
17
+ }
18
+
19
+ };
20
+ }
21
+
22
+ }
23
+
24
+ exports.HashMap = HashMap;
@@ -0,0 +1,5 @@
1
+ import type { Codec, CodecClass } from '../types';
2
+ import { CodecMap } from './Map';
3
+ export declare class HashMap<K extends Codec = Codec, V extends Codec = Codec> extends CodecMap<K, V> {
4
+ static with<K extends Codec, V extends Codec>(keyType: CodecClass<K> | string, valType: CodecClass<V> | string): CodecClass<CodecMap<K, V>>;
5
+ }
@@ -0,0 +1,14 @@
1
+ // Copyright 2017-2021 @polkadot/types-codec authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { CodecMap } from "./Map.js";
4
+ export class HashMap extends CodecMap {
5
+ static with(keyType, valType) {
6
+ return class extends HashMap {
7
+ constructor(registry, value) {
8
+ super(registry, keyType, valType, value);
9
+ }
10
+
11
+ };
12
+ }
13
+
14
+ }
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.LinkageResult = exports.Linkage = void 0;
7
+
8
+ var _Option = require("../base/Option.cjs");
9
+
10
+ var _Tuple = require("../base/Tuple.cjs");
11
+
12
+ var _Vec = require("../base/Vec.cjs");
13
+
14
+ var _Struct = require("../native/Struct.cjs");
15
+
16
+ // Copyright 2017-2021 @polkadot/types-codec authors & contributors
17
+ // SPDX-License-Identifier: Apache-2.0
18
+ const EMPTY = new Uint8Array();
19
+ /**
20
+ * @name Linkage
21
+ * @description The wrapper for the result from a LinkedMap
22
+ */
23
+
24
+ class Linkage extends _Struct.Struct {
25
+ constructor(registry, Type, value) {
26
+ super(registry, {
27
+ previous: _Option.Option.with(Type),
28
+ // eslint-disable-next-line sort-keys
29
+ next: _Option.Option.with(Type)
30
+ }, value);
31
+ }
32
+
33
+ static withKey(Type) {
34
+ return class extends Linkage {
35
+ constructor(registry, value) {
36
+ super(registry, Type, value);
37
+ }
38
+
39
+ };
40
+ }
41
+
42
+ get previous() {
43
+ return this.get('previous');
44
+ }
45
+
46
+ get next() {
47
+ return this.get('next');
48
+ }
49
+ /**
50
+ * @description Returns the base runtime type name for this instance
51
+ */
52
+
53
+
54
+ toRawType() {
55
+ return `Linkage<${this.next.toRawType(true)}>`;
56
+ }
57
+ /**
58
+ * @description Custom toU8a which with bare mode does not return the linkage if empty
59
+ */
60
+
61
+
62
+ toU8a() {
63
+ // As part of a storage query (where these appear), in the case of empty, the values
64
+ // are NOT populated by the node - follow the same logic, leaving it empty
65
+ return this.isEmpty ? EMPTY : super.toU8a();
66
+ }
67
+
68
+ }
69
+ /**
70
+ * @name LinkageResult
71
+ * @description A Linkage keys/Values tuple
72
+ */
73
+
74
+
75
+ exports.Linkage = Linkage;
76
+
77
+ class LinkageResult extends _Tuple.Tuple {
78
+ constructor(registry, _ref, _ref2) {
79
+ let [TypeKey, keys] = _ref;
80
+ let [TypeValue, values] = _ref2;
81
+ super(registry, {
82
+ Keys: _Vec.Vec.with(TypeKey),
83
+ Values: _Vec.Vec.with(TypeValue)
84
+ }, [keys, values]);
85
+ }
86
+
87
+ }
88
+
89
+ exports.LinkageResult = LinkageResult;
@@ -0,0 +1,31 @@
1
+ import type { Codec, CodecClass, CodecRegistry } from '../types';
2
+ import { Option } from '../base/Option';
3
+ import { Tuple } from '../base/Tuple';
4
+ import { Struct } from '../native/Struct';
5
+ declare type TypeWithValues = [CodecClass, any[]];
6
+ /**
7
+ * @name Linkage
8
+ * @description The wrapper for the result from a LinkedMap
9
+ */
10
+ export declare class Linkage<T extends Codec> extends Struct {
11
+ constructor(registry: CodecRegistry, Type: CodecClass | string, value?: unknown);
12
+ static withKey<O extends Codec>(Type: CodecClass | string): CodecClass<Linkage<O>>;
13
+ get previous(): Option<T>;
14
+ get next(): Option<T>;
15
+ /**
16
+ * @description Returns the base runtime type name for this instance
17
+ */
18
+ toRawType(): string;
19
+ /**
20
+ * @description Custom toU8a which with bare mode does not return the linkage if empty
21
+ */
22
+ toU8a(): Uint8Array;
23
+ }
24
+ /**
25
+ * @name LinkageResult
26
+ * @description A Linkage keys/Values tuple
27
+ */
28
+ export declare class LinkageResult extends Tuple {
29
+ constructor(registry: CodecRegistry, [TypeKey, keys]: TypeWithValues, [TypeValue, values]: TypeWithValues);
30
+ }
31
+ export {};
@@ -0,0 +1,71 @@
1
+ // Copyright 2017-2021 @polkadot/types-codec authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { Option } from "../base/Option.js";
4
+ import { Tuple } from "../base/Tuple.js";
5
+ import { Vec } from "../base/Vec.js";
6
+ import { Struct } from "../native/Struct.js";
7
+ const EMPTY = new Uint8Array();
8
+ /**
9
+ * @name Linkage
10
+ * @description The wrapper for the result from a LinkedMap
11
+ */
12
+
13
+ export class Linkage extends Struct {
14
+ constructor(registry, Type, value) {
15
+ super(registry, {
16
+ previous: Option.with(Type),
17
+ // eslint-disable-next-line sort-keys
18
+ next: Option.with(Type)
19
+ }, value);
20
+ }
21
+
22
+ static withKey(Type) {
23
+ return class extends Linkage {
24
+ constructor(registry, value) {
25
+ super(registry, Type, value);
26
+ }
27
+
28
+ };
29
+ }
30
+
31
+ get previous() {
32
+ return this.get('previous');
33
+ }
34
+
35
+ get next() {
36
+ return this.get('next');
37
+ }
38
+ /**
39
+ * @description Returns the base runtime type name for this instance
40
+ */
41
+
42
+
43
+ toRawType() {
44
+ return `Linkage<${this.next.toRawType(true)}>`;
45
+ }
46
+ /**
47
+ * @description Custom toU8a which with bare mode does not return the linkage if empty
48
+ */
49
+
50
+
51
+ toU8a() {
52
+ // As part of a storage query (where these appear), in the case of empty, the values
53
+ // are NOT populated by the node - follow the same logic, leaving it empty
54
+ return this.isEmpty ? EMPTY : super.toU8a();
55
+ }
56
+
57
+ }
58
+ /**
59
+ * @name LinkageResult
60
+ * @description A Linkage keys/Values tuple
61
+ */
62
+
63
+ export class LinkageResult extends Tuple {
64
+ constructor(registry, [TypeKey, keys], [TypeValue, values]) {
65
+ super(registry, {
66
+ Keys: Vec.with(TypeKey),
67
+ Values: Vec.with(TypeValue)
68
+ }, [keys, values]);
69
+ }
70
+
71
+ }