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