@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
package/base/Enum.js ADDED
@@ -0,0 +1,421 @@
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, isHex, isNumber, isObject, isString, isU8a, isUndefined, objectProperties, stringCamelCase, stringify, stringPascalCase, u8aConcat, u8aToHex, u8aToU8a } from '@polkadot/util';
6
+ import { mapToTypeMap, typesToMap } from "../utils/index.js";
7
+ import { Null } from "./Null.js"; // export interface, this is used in Enum.with, so required as public by TS
8
+
9
+ function isRustEnum(def) {
10
+ const defValues = Object.values(def);
11
+
12
+ if (defValues.some(v => isNumber(v))) {
13
+ assert(defValues.every(v => isNumber(v) && v >= 0 && v <= 255), 'Invalid number-indexed enum definition');
14
+ return false;
15
+ }
16
+
17
+ return true;
18
+ }
19
+
20
+ function extractDef(registry, _def) {
21
+ const def = {};
22
+ let isBasic;
23
+ let isIndexed;
24
+
25
+ if (Array.isArray(_def)) {
26
+ for (let i = 0; i < _def.length; i++) {
27
+ def[_def[i]] = {
28
+ Type: Null,
29
+ index: i
30
+ };
31
+ }
32
+
33
+ isBasic = true;
34
+ isIndexed = false;
35
+ } else if (isRustEnum(_def)) {
36
+ const entries = Object.entries(mapToTypeMap(registry, _def));
37
+
38
+ for (let i = 0; i < entries.length; i++) {
39
+ const [key, Type] = entries[i];
40
+ def[key] = {
41
+ Type,
42
+ index: i
43
+ };
44
+ }
45
+
46
+ isBasic = !Object.values(def).some(({
47
+ Type
48
+ }) => Type !== Null);
49
+ isIndexed = false;
50
+ } else {
51
+ const entries = Object.entries(_def);
52
+
53
+ for (let i = 0; i < entries.length; i++) {
54
+ const [key, index] = entries[i];
55
+ def[key] = {
56
+ Type: Null,
57
+ index
58
+ };
59
+ }
60
+
61
+ isBasic = true;
62
+ isIndexed = true;
63
+ }
64
+
65
+ return {
66
+ def,
67
+ isBasic,
68
+ isIndexed
69
+ };
70
+ }
71
+
72
+ function createFromValue(registry, def, index = 0, value) {
73
+ const entry = Object.values(def).find(e => e.index === index);
74
+ assert(!isUndefined(entry), () => `Unable to create Enum via index ${index}, in ${Object.keys(def).join(', ')}`);
75
+ return {
76
+ index,
77
+ value: value instanceof entry.Type ? value : new entry.Type(registry, value)
78
+ };
79
+ }
80
+
81
+ function decodeFromJSON(registry, def, key, value) {
82
+ // JSON comes in the form of { "<type (camelCase)>": "<value for type>" }, here we
83
+ // additionally force to lower to ensure forward compat
84
+ const keys = Object.keys(def).map(k => k.toLowerCase());
85
+ const keyLower = key.toLowerCase();
86
+ const index = keys.indexOf(keyLower);
87
+ assert(index !== -1, () => `Cannot map Enum JSON, unable to find '${key}' in ${keys.join(', ')}`);
88
+
89
+ try {
90
+ return createFromValue(registry, def, Object.values(def)[index].index, value);
91
+ } catch (error) {
92
+ throw new Error(`Enum(${key}):: ${error.message}`);
93
+ }
94
+ }
95
+
96
+ function decodeEnum(registry, def, value, index) {
97
+ // NOTE We check the index path first, before looking at values - this allows treating
98
+ // the optional indexes before anything else, more-specific > less-specific
99
+ if (isNumber(index)) {
100
+ return createFromValue(registry, def, index, value);
101
+ } else if (isU8a(value) || isHex(value)) {
102
+ const u8a = u8aToU8a(value); // nested, we don't want to match isObject below
103
+
104
+ if (u8a.length) {
105
+ return createFromValue(registry, def, u8a[0], u8a.subarray(1));
106
+ }
107
+ } else if (value instanceof Enum) {
108
+ return createFromValue(registry, def, value.index, value.value);
109
+ } else if (isNumber(value)) {
110
+ return createFromValue(registry, def, value);
111
+ } else if (isString(value)) {
112
+ return decodeFromJSON(registry, def, value.toString());
113
+ } else if (isObject(value)) {
114
+ const key = Object.keys(value)[0];
115
+ return decodeFromJSON(registry, def, key, value[key]);
116
+ } // Worst-case scenario, return the first with default
117
+
118
+
119
+ return createFromValue(registry, def, Object.values(def)[0].index);
120
+ }
121
+ /**
122
+ * @name Enum
123
+ * @description
124
+ * This implements an enum, that based on the value wraps a different type. It is effectively
125
+ * an extension to enum where the value type is determined by the actual index.
126
+ */
127
+
128
+
129
+ var _def2 = /*#__PURE__*/_classPrivateFieldLooseKey("def");
130
+
131
+ var _entryIndex = /*#__PURE__*/_classPrivateFieldLooseKey("entryIndex");
132
+
133
+ var _indexes = /*#__PURE__*/_classPrivateFieldLooseKey("indexes");
134
+
135
+ var _isBasic = /*#__PURE__*/_classPrivateFieldLooseKey("isBasic");
136
+
137
+ var _isIndexed = /*#__PURE__*/_classPrivateFieldLooseKey("isIndexed");
138
+
139
+ var _raw = /*#__PURE__*/_classPrivateFieldLooseKey("raw");
140
+
141
+ export class Enum {
142
+ constructor(registry, Types, value, index) {
143
+ this.registry = void 0;
144
+ this.createdAtHash = void 0;
145
+ Object.defineProperty(this, _def2, {
146
+ writable: true,
147
+ value: void 0
148
+ });
149
+ Object.defineProperty(this, _entryIndex, {
150
+ writable: true,
151
+ value: void 0
152
+ });
153
+ this.initialU8aLength = void 0;
154
+ Object.defineProperty(this, _indexes, {
155
+ writable: true,
156
+ value: void 0
157
+ });
158
+ Object.defineProperty(this, _isBasic, {
159
+ writable: true,
160
+ value: void 0
161
+ });
162
+ Object.defineProperty(this, _isIndexed, {
163
+ writable: true,
164
+ value: void 0
165
+ });
166
+ Object.defineProperty(this, _raw, {
167
+ writable: true,
168
+ value: void 0
169
+ });
170
+ const {
171
+ def,
172
+ isBasic,
173
+ isIndexed
174
+ } = extractDef(registry, Types); // shortcut isU8a as used in SCALE decoding
175
+
176
+ const decoded = isU8a(value) && value.length && !isNumber(index) ? createFromValue(registry, def, value[0], value.subarray(1)) : decodeEnum(registry, def, value, index);
177
+ this.registry = registry;
178
+ _classPrivateFieldLooseBase(this, _def2)[_def2] = def;
179
+ _classPrivateFieldLooseBase(this, _isBasic)[_isBasic] = isBasic;
180
+ _classPrivateFieldLooseBase(this, _isIndexed)[_isIndexed] = isIndexed;
181
+ _classPrivateFieldLooseBase(this, _indexes)[_indexes] = Object.values(def).map(({
182
+ index
183
+ }) => index);
184
+ _classPrivateFieldLooseBase(this, _entryIndex)[_entryIndex] = _classPrivateFieldLooseBase(this, _indexes)[_indexes].indexOf(decoded.index) || 0;
185
+ _classPrivateFieldLooseBase(this, _raw)[_raw] = decoded.value;
186
+
187
+ if (_classPrivateFieldLooseBase(this, _raw)[_raw].initialU8aLength) {
188
+ this.initialU8aLength = 1 + _classPrivateFieldLooseBase(this, _raw)[_raw].initialU8aLength;
189
+ }
190
+ }
191
+
192
+ static with(Types) {
193
+ const keys = Array.isArray(Types) ? Types : Object.keys(Types);
194
+ const asKeys = new Array(keys.length);
195
+ const isKeys = new Array(keys.length);
196
+
197
+ for (let i = 0; i < keys.length; i++) {
198
+ const name = stringPascalCase(keys[i].replace(' ', '_'));
199
+ asKeys[i] = `as${name}`;
200
+ isKeys[i] = `is${name}`;
201
+ }
202
+
203
+ return class extends Enum {
204
+ constructor(registry, value, index) {
205
+ super(registry, Types, value, index);
206
+ objectProperties(this, isKeys, (_, i) => this.type === keys[i]);
207
+ objectProperties(this, asKeys, (k, i) => {
208
+ assert(this[isKeys[i]], () => `Cannot convert '${this.type}' via ${k}`);
209
+ return this.value;
210
+ });
211
+ }
212
+
213
+ };
214
+ }
215
+ /**
216
+ * @description The length of the value when encoded as a Uint8Array
217
+ */
218
+
219
+
220
+ get encodedLength() {
221
+ return 1 + _classPrivateFieldLooseBase(this, _raw)[_raw].encodedLength;
222
+ }
223
+ /**
224
+ * @description returns a hash of the contents
225
+ */
226
+
227
+
228
+ get hash() {
229
+ return this.registry.hash(this.toU8a());
230
+ }
231
+ /**
232
+ * @description The index of the enum value
233
+ */
234
+
235
+
236
+ get index() {
237
+ return _classPrivateFieldLooseBase(this, _indexes)[_indexes][_classPrivateFieldLooseBase(this, _entryIndex)[_entryIndex]];
238
+ }
239
+ /**
240
+ * @description The value of the enum
241
+ */
242
+
243
+
244
+ get inner() {
245
+ return _classPrivateFieldLooseBase(this, _raw)[_raw];
246
+ }
247
+ /**
248
+ * @description true if this is a basic enum (no values)
249
+ */
250
+
251
+
252
+ get isBasic() {
253
+ return _classPrivateFieldLooseBase(this, _isBasic)[_isBasic];
254
+ }
255
+ /**
256
+ * @description Checks if the value is an empty value
257
+ */
258
+
259
+
260
+ get isEmpty() {
261
+ return _classPrivateFieldLooseBase(this, _raw)[_raw].isEmpty;
262
+ }
263
+ /**
264
+ * @description Checks if the Enum points to a [[Null]] type
265
+ */
266
+
267
+
268
+ get isNone() {
269
+ return _classPrivateFieldLooseBase(this, _raw)[_raw] instanceof Null;
270
+ }
271
+ /**
272
+ * @description Checks if the Enum points to a [[Null]] type
273
+ * @deprecated use isNone
274
+ */
275
+
276
+
277
+ get isNull() {
278
+ return _classPrivateFieldLooseBase(this, _raw)[_raw] instanceof Null;
279
+ }
280
+ /**
281
+ * @description The available keys for this enum
282
+ */
283
+
284
+
285
+ get defIndexes() {
286
+ return _classPrivateFieldLooseBase(this, _indexes)[_indexes];
287
+ }
288
+ /**
289
+ * @description The available keys for this enum
290
+ */
291
+
292
+
293
+ get defKeys() {
294
+ return Object.keys(_classPrivateFieldLooseBase(this, _def2)[_def2]);
295
+ }
296
+ /**
297
+ * @description The name of the type this enum value represents
298
+ */
299
+
300
+
301
+ get type() {
302
+ return this.defKeys[_classPrivateFieldLooseBase(this, _entryIndex)[_entryIndex]];
303
+ }
304
+ /**
305
+ * @description The value of the enum
306
+ */
307
+
308
+
309
+ get value() {
310
+ return _classPrivateFieldLooseBase(this, _raw)[_raw];
311
+ }
312
+ /**
313
+ * @description Compares the value of the input to see if there is a match
314
+ */
315
+
316
+
317
+ eq(other) {
318
+ // cater for the case where we only pass the enum index
319
+ if (isU8a(other)) {
320
+ return !this.toU8a().some((entry, index) => entry !== other[index]);
321
+ } else if (isNumber(other)) {
322
+ return this.toNumber() === other;
323
+ } else if (_classPrivateFieldLooseBase(this, _isBasic)[_isBasic] && isString(other)) {
324
+ return this.type === other;
325
+ } else if (isHex(other)) {
326
+ return this.toHex() === other;
327
+ } else if (other instanceof Enum) {
328
+ return this.index === other.index && this.value.eq(other.value);
329
+ } else if (isObject(other)) {
330
+ return this.value.eq(other[this.type]);
331
+ } // compare the actual wrapper value
332
+
333
+
334
+ return this.value.eq(other);
335
+ }
336
+ /**
337
+ * @description Returns a hex string representation of the value
338
+ */
339
+
340
+
341
+ toHex() {
342
+ return u8aToHex(this.toU8a());
343
+ }
344
+ /**
345
+ * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
346
+ */
347
+
348
+
349
+ toHuman(isExtended) {
350
+ return _classPrivateFieldLooseBase(this, _isBasic)[_isBasic] || this.isNone ? this.type : {
351
+ [this.type]: _classPrivateFieldLooseBase(this, _raw)[_raw].toHuman(isExtended)
352
+ };
353
+ }
354
+ /**
355
+ * @description Converts the Object to JSON, typically used for RPC transfers
356
+ */
357
+
358
+
359
+ toJSON() {
360
+ return _classPrivateFieldLooseBase(this, _isBasic)[_isBasic] ? this.type : {
361
+ [stringCamelCase(this.type)]: _classPrivateFieldLooseBase(this, _raw)[_raw].toJSON()
362
+ };
363
+ }
364
+ /**
365
+ * @description Returns the number representation for the value
366
+ */
367
+
368
+
369
+ toNumber() {
370
+ return this.index;
371
+ }
372
+ /**
373
+ * @description Returns a raw struct representation of the enum types
374
+ */
375
+
376
+
377
+ _toRawStruct() {
378
+ if (_classPrivateFieldLooseBase(this, _isBasic)[_isBasic]) {
379
+ return _classPrivateFieldLooseBase(this, _isIndexed)[_isIndexed] ? this.defKeys.reduce((out, key, index) => {
380
+ out[key] = _classPrivateFieldLooseBase(this, _indexes)[_indexes][index];
381
+ return out;
382
+ }, {}) : this.defKeys;
383
+ }
384
+
385
+ const typeMap = Object.entries(_classPrivateFieldLooseBase(this, _def2)[_def2]).reduce((out, [key, {
386
+ Type
387
+ }]) => {
388
+ out[key] = Type;
389
+ return out;
390
+ }, {});
391
+ return typesToMap(this.registry, typeMap);
392
+ }
393
+ /**
394
+ * @description Returns the base runtime type name for this instance
395
+ */
396
+
397
+
398
+ toRawType() {
399
+ return stringify({
400
+ _enum: this._toRawStruct()
401
+ });
402
+ }
403
+ /**
404
+ * @description Returns the string representation of the value
405
+ */
406
+
407
+
408
+ toString() {
409
+ return this.isNull ? this.type : stringify(this.toJSON());
410
+ }
411
+ /**
412
+ * @description Encodes the value as a Uint8Array as per the SCALE specifications
413
+ * @param isBare true when the value has none of the type-specific prefixes (internal)
414
+ */
415
+
416
+
417
+ toU8a(isBare) {
418
+ return u8aConcat(new Uint8Array(isBare ? [] : [this.index]), _classPrivateFieldLooseBase(this, _raw)[_raw].toU8a(isBare));
419
+ }
420
+
421
+ }
package/base/Int.cjs ADDED
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Int = void 0;
7
+
8
+ var _AbstractInt = require("../abstract/AbstractInt.cjs");
9
+
10
+ // Copyright 2017-2021 @polkadot/types-codec authors & contributors
11
+ // SPDX-License-Identifier: Apache-2.0
12
+
13
+ /**
14
+ * @name Int
15
+ * @description
16
+ * A generic signed integer codec. For Substrate all numbers are Little Endian encoded,
17
+ * this handles the encoding and decoding of those numbers. Upon construction
18
+ * the bitLength is provided and any additional use keeps the number to this
19
+ * length. This extends `BN`, so all methods available on a normal `BN` object
20
+ * is available here.
21
+ * @noInheritDoc
22
+ */
23
+ class Int extends _AbstractInt.AbstractInt {
24
+ constructor(registry) {
25
+ let value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
26
+ let bitLength = arguments.length > 2 ? arguments[2] : undefined;
27
+ super(registry, value, bitLength, true);
28
+ }
29
+
30
+ static with(bitLength, typeName) {
31
+ return class extends Int {
32
+ constructor(registry, value) {
33
+ super(registry, value, bitLength);
34
+ }
35
+
36
+ toRawType() {
37
+ return typeName || super.toRawType();
38
+ }
39
+
40
+ };
41
+ }
42
+
43
+ }
44
+
45
+ exports.Int = Int;
package/base/Int.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ import type { AnyNumber, CodecClass, CodecRegistry, UIntBitLength } from '../types';
2
+ import { AbstractInt } from '../abstract/AbstractInt';
3
+ /**
4
+ * @name Int
5
+ * @description
6
+ * A generic signed integer codec. For Substrate all numbers are Little Endian encoded,
7
+ * this handles the encoding and decoding of those numbers. Upon construction
8
+ * the bitLength is provided and any additional use keeps the number to this
9
+ * length. This extends `BN`, so all methods available on a normal `BN` object
10
+ * is available here.
11
+ * @noInheritDoc
12
+ */
13
+ export declare class Int extends AbstractInt {
14
+ constructor(registry: CodecRegistry, value?: AnyNumber, bitLength?: UIntBitLength);
15
+ static with(bitLength: UIntBitLength, typeName?: string): CodecClass<Int>;
16
+ }
package/base/Int.js ADDED
@@ -0,0 +1,33 @@
1
+ // Copyright 2017-2021 @polkadot/types-codec authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { AbstractInt } from "../abstract/AbstractInt.js";
4
+ /**
5
+ * @name Int
6
+ * @description
7
+ * A generic signed integer codec. For Substrate all numbers are Little Endian encoded,
8
+ * this handles the encoding and decoding of those numbers. Upon construction
9
+ * the bitLength is provided and any additional use keeps the number to this
10
+ * length. This extends `BN`, so all methods available on a normal `BN` object
11
+ * is available here.
12
+ * @noInheritDoc
13
+ */
14
+
15
+ export class Int extends AbstractInt {
16
+ constructor(registry, value = 0, bitLength) {
17
+ super(registry, value, bitLength, true);
18
+ }
19
+
20
+ static with(bitLength, typeName) {
21
+ return class extends Int {
22
+ constructor(registry, value) {
23
+ super(registry, value, bitLength);
24
+ }
25
+
26
+ toRawType() {
27
+ return typeName || super.toRawType();
28
+ }
29
+
30
+ };
31
+ }
32
+
33
+ }
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
+ }