@polkadot/types-codec 9.5.2 → 9.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/abstract/Array.js +15 -44
  2. package/abstract/Base.js +12 -28
  3. package/abstract/BigInt.js +3 -2
  4. package/abstract/Int.js +25 -52
  5. package/abstract/index.js +1 -0
  6. package/base/Compact.js +21 -45
  7. package/base/DoNotConstruct.js +3 -19
  8. package/base/Enum.js +37 -88
  9. package/base/Int.js +2 -5
  10. package/base/Null.js +12 -23
  11. package/base/Option.js +23 -59
  12. package/base/Result.js +8 -19
  13. package/base/Tuple.js +12 -29
  14. package/base/UInt.js +2 -4
  15. package/base/Vec.js +7 -25
  16. package/base/VecAny.js +2 -2
  17. package/base/VecFixed.js +8 -20
  18. package/base/index.js +1 -0
  19. package/bundle.js +1 -0
  20. package/cjs/abstract/Array.js +13 -47
  21. package/cjs/abstract/Base.js +12 -30
  22. package/cjs/abstract/BigInt.js +1 -4
  23. package/cjs/abstract/Int.js +25 -55
  24. package/cjs/abstract/index.js +0 -3
  25. package/cjs/base/Compact.js +21 -48
  26. package/cjs/base/DoNotConstruct.js +3 -21
  27. package/cjs/base/Enum.js +34 -92
  28. package/cjs/base/Int.js +0 -7
  29. package/cjs/base/Null.js +10 -25
  30. package/cjs/base/Option.js +23 -63
  31. package/cjs/base/Result.js +6 -21
  32. package/cjs/base/Tuple.js +12 -33
  33. package/cjs/base/UInt.js +0 -6
  34. package/cjs/base/Vec.js +7 -31
  35. package/cjs/base/VecAny.js +0 -4
  36. package/cjs/base/VecFixed.js +8 -25
  37. package/cjs/base/index.js +0 -12
  38. package/cjs/bundle.js +0 -13
  39. package/cjs/detectPackage.js +2 -4
  40. package/cjs/extended/BTreeMap.js +1 -5
  41. package/cjs/extended/BTreeSet.js +17 -57
  42. package/cjs/extended/BitVec.js +11 -25
  43. package/cjs/extended/Bytes.js +9 -20
  44. package/cjs/extended/HashMap.js +1 -5
  45. package/cjs/extended/Linkage.js +5 -20
  46. package/cjs/extended/Map.js +16 -62
  47. package/cjs/extended/OptionBool.js +8 -21
  48. package/cjs/extended/Range.js +3 -13
  49. package/cjs/extended/RangeInclusive.js +1 -6
  50. package/cjs/extended/Type.js +1 -7
  51. package/cjs/extended/U8aFixed.js +2 -15
  52. package/cjs/extended/WrapperKeepOpaque.js +8 -28
  53. package/cjs/extended/WrapperOpaque.js +2 -8
  54. package/cjs/extended/index.js +0 -14
  55. package/cjs/index.js +0 -3
  56. package/cjs/native/Bool.js +14 -32
  57. package/cjs/native/Date.js +18 -40
  58. package/cjs/native/Float.js +11 -29
  59. package/cjs/native/Json.js +14 -33
  60. package/cjs/native/Raw.js +18 -41
  61. package/cjs/native/Set.js +21 -67
  62. package/cjs/native/Struct.data.js +1 -0
  63. package/cjs/native/Struct.js +33 -83
  64. package/cjs/native/Text.js +20 -44
  65. package/cjs/native/index.js +0 -8
  66. package/cjs/packageInfo.js +3 -1
  67. package/cjs/primitive/F32.js +0 -3
  68. package/cjs/primitive/F64.js +0 -3
  69. package/cjs/primitive/I128.js +0 -3
  70. package/cjs/primitive/I16.js +0 -3
  71. package/cjs/primitive/I256.js +0 -3
  72. package/cjs/primitive/I32.js +0 -3
  73. package/cjs/primitive/I64.js +0 -3
  74. package/cjs/primitive/I8.js +0 -3
  75. package/cjs/primitive/U128.js +0 -3
  76. package/cjs/primitive/U16.js +0 -3
  77. package/cjs/primitive/U256.js +0 -3
  78. package/cjs/primitive/U32.js +0 -3
  79. package/cjs/primitive/U64.js +0 -3
  80. package/cjs/primitive/U8.js +0 -3
  81. package/cjs/primitive/USize.js +0 -4
  82. package/cjs/primitive/index.js +0 -15
  83. package/cjs/types/index.js +0 -8
  84. package/cjs/utils/compareArray.js +1 -4
  85. package/cjs/utils/compareMap.js +4 -9
  86. package/cjs/utils/compareSet.js +4 -6
  87. package/cjs/utils/decodeU8a.js +7 -17
  88. package/cjs/utils/index.js +0 -9
  89. package/cjs/utils/mapToTypeMap.js +0 -4
  90. package/cjs/utils/sanitize.js +66 -71
  91. package/cjs/utils/sortValues.js +5 -18
  92. package/cjs/utils/typeToConstructor.js +1 -2
  93. package/cjs/utils/typesToMap.js +1 -3
  94. package/cjs/utils/util.js +1 -2
  95. package/detectOther.js +2 -0
  96. package/detectPackage.js +2 -0
  97. package/extended/BTreeMap.js +1 -2
  98. package/extended/BTreeSet.js +17 -53
  99. package/extended/BitVec.js +13 -22
  100. package/extended/Bytes.js +11 -17
  101. package/extended/HashMap.js +1 -2
  102. package/extended/Linkage.js +5 -12
  103. package/extended/Map.js +16 -54
  104. package/extended/OptionBool.js +8 -17
  105. package/extended/Range.js +4 -11
  106. package/extended/RangeInclusive.js +1 -3
  107. package/extended/Type.js +3 -4
  108. package/extended/U8aFixed.js +4 -12
  109. package/extended/WrapperKeepOpaque.js +8 -23
  110. package/extended/WrapperOpaque.js +2 -5
  111. package/extended/index.js +1 -0
  112. package/index.js +1 -0
  113. package/native/Bool.js +16 -30
  114. package/native/Date.js +18 -37
  115. package/native/Float.js +12 -27
  116. package/native/Json.js +16 -30
  117. package/native/Raw.js +20 -39
  118. package/native/Set.js +21 -63
  119. package/native/Struct.data.js +1 -0
  120. package/native/Struct.js +33 -80
  121. package/native/Text.js +20 -40
  122. package/native/index.js +1 -0
  123. package/package.json +1 -1
  124. package/packageInfo.js +3 -1
  125. package/primitive/F32.js +2 -1
  126. package/primitive/F64.js +2 -1
  127. package/primitive/I128.js +2 -1
  128. package/primitive/I16.js +2 -1
  129. package/primitive/I256.js +2 -1
  130. package/primitive/I32.js +2 -1
  131. package/primitive/I64.js +2 -1
  132. package/primitive/I8.js +2 -1
  133. package/primitive/U128.js +2 -1
  134. package/primitive/U16.js +2 -1
  135. package/primitive/U256.js +2 -1
  136. package/primitive/U32.js +2 -1
  137. package/primitive/U64.js +2 -1
  138. package/primitive/U8.js +2 -1
  139. package/primitive/USize.js +2 -2
  140. package/primitive/index.js +1 -0
  141. package/types/index.js +1 -0
  142. package/utils/compareArray.js +4 -3
  143. package/utils/compareMap.js +4 -7
  144. package/utils/compareSet.js +4 -5
  145. package/utils/decodeU8a.js +9 -14
  146. package/utils/index.js +1 -0
  147. package/utils/mapToTypeMap.js +2 -3
  148. package/utils/sanitize.js +66 -60
  149. package/utils/sortValues.js +6 -15
  150. package/utils/typeToConstructor.js +1 -0
  151. package/utils/typesToMap.js +1 -2
  152. package/utils/util.js +1 -0
@@ -6,9 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.decodeU8a = decodeU8a;
7
7
  exports.decodeU8aStruct = decodeU8aStruct;
8
8
  exports.decodeU8aVec = decodeU8aVec;
9
-
10
9
  var _util = require("@polkadot/util");
11
-
12
10
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
13
11
  // SPDX-License-Identifier: Apache-2.0
14
12
 
@@ -18,15 +16,17 @@ function formatFailure(registry, result, _ref, u8a, i, count, Type, key) {
18
16
  message
19
17
  } = _ref;
20
18
  let type = '';
21
-
22
19
  try {
23
20
  type = `: ${new Type(registry).toRawType()}`;
24
- } catch {// ignore
25
- } // console.error(JSON.stringify(result, null, 2));
21
+ } catch {
22
+ // ignore
23
+ }
26
24
 
25
+ // console.error(JSON.stringify(result, null, 2));
27
26
 
28
27
  return `decodeU8a: failed at ${(0, _util.u8aToHex)(u8a.subarray(0, 16))}…${key ? ` on ${key}` : ''} (index ${i}/${count})${type}:: ${message}`;
29
28
  }
29
+
30
30
  /**
31
31
  * @internal
32
32
  *
@@ -37,14 +37,11 @@ function formatFailure(registry, result, _ref, u8a, i, count, Type, key) {
37
37
  * @param result - The result array (will be returned with values pushed)
38
38
  * @param types - The array of CodecClass to decode the U8a against.
39
39
  */
40
-
41
-
42
40
  function decodeU8a(registry, result, u8a, _ref2) {
43
41
  let [Types, keys] = _ref2;
44
42
  const count = result.length;
45
43
  let offset = 0;
46
44
  let i = 0;
47
-
48
45
  try {
49
46
  while (i < count) {
50
47
  const value = new Types[i](registry, u8a.subarray(offset));
@@ -55,23 +52,20 @@ function decodeU8a(registry, result, u8a, _ref2) {
55
52
  } catch (error) {
56
53
  throw new Error(formatFailure(registry, result, error, u8a.subarray(offset), i, count, Types[i], keys[i]));
57
54
  }
58
-
59
55
  return [result, offset];
60
56
  }
57
+
61
58
  /**
62
59
  * @internal
63
60
  *
64
61
  * Split from decodeU8a since this is specialized to zip returns ... while we duplicate, this
65
62
  * is all on the hot-path, so it is not great, however there is (some) method behind the madness
66
63
  */
67
-
68
-
69
64
  function decodeU8aStruct(registry, result, u8a, _ref3) {
70
65
  let [Types, keys] = _ref3;
71
66
  const count = result.length;
72
67
  let offset = 0;
73
68
  let i = 0;
74
-
75
69
  try {
76
70
  while (i < count) {
77
71
  const value = new Types[i](registry, u8a.subarray(offset));
@@ -82,22 +76,19 @@ function decodeU8aStruct(registry, result, u8a, _ref3) {
82
76
  } catch (error) {
83
77
  throw new Error(formatFailure(registry, result, error, u8a.subarray(offset), i, count, Types[i], keys[i]));
84
78
  }
85
-
86
79
  return [result, offset];
87
80
  }
81
+
88
82
  /**
89
83
  * @internal
90
84
  *
91
85
  * Split from decodeU8a since this is specialized to 1 instance ... while we duplicate, this
92
86
  * is all on the hot-path, so it is not great, however there is (some) method behind the madness
93
87
  */
94
-
95
-
96
88
  function decodeU8aVec(registry, result, u8a, startAt, Type) {
97
89
  const count = result.length;
98
90
  let offset = startAt;
99
91
  let i = 0;
100
-
101
92
  try {
102
93
  while (i < count) {
103
94
  const value = new Type(registry, u8a.subarray(offset));
@@ -108,6 +99,5 @@ function decodeU8aVec(registry, result, u8a, startAt, Type) {
108
99
  } catch (error) {
109
100
  throw new Error(formatFailure(registry, result, error, u8a.subarray(offset), i, count, Type));
110
101
  }
111
-
112
102
  return [offset, offset - startAt];
113
103
  }
@@ -81,21 +81,12 @@ Object.defineProperty(exports, "typesToMap", {
81
81
  return _typesToMap.typesToMap;
82
82
  }
83
83
  });
84
-
85
84
  var _compareArray = require("./compareArray");
86
-
87
85
  var _compareMap = require("./compareMap");
88
-
89
86
  var _compareSet = require("./compareSet");
90
-
91
87
  var _decodeU8a = require("./decodeU8a");
92
-
93
88
  var _mapToTypeMap = require("./mapToTypeMap");
94
-
95
89
  var _typeToConstructor = require("./typeToConstructor");
96
-
97
90
  var _sanitize = require("./sanitize");
98
-
99
91
  var _sortValues = require("./sortValues");
100
-
101
92
  var _typesToMap = require("./typesToMap");
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.mapToTypeMap = mapToTypeMap;
7
-
8
7
  var _typeToConstructor = require("./typeToConstructor");
9
-
10
8
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
11
9
  // SPDX-License-Identifier: Apache-2.0
12
10
 
@@ -17,11 +15,9 @@ function mapToTypeMap(registry, input) {
17
15
  const entries = Object.entries(input);
18
16
  const count = entries.length;
19
17
  const output = [new Array(count), new Array(count)];
20
-
21
18
  for (let i = 0; i < count; i++) {
22
19
  output[1][i] = entries[i][0];
23
20
  output[0][i] = (0, _typeToConstructor.typeToConstructor)(registry, entries[i][1]);
24
21
  }
25
-
26
22
  return output;
27
23
  }
@@ -17,152 +17,148 @@ exports.sanitize = sanitize;
17
17
  exports.trim = trim;
18
18
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
19
19
  // SPDX-License-Identifier: Apache-2.0
20
+
20
21
  const BOUNDED = ['BTreeMap', 'BTreeSet', 'HashMap', 'Vec'];
21
22
  const ALLOWED_BOXES = BOUNDED.concat(['Compact', 'DoNotConstruct', 'Int', 'Linkage', 'Range', 'RangeInclusive', 'Result', 'Opaque', 'Option', 'UInt', 'WrapperKeepOpaque', 'WrapperOpaque']);
22
23
  const BOX_PRECEDING = ['<', '(', '[', '"', ',', ' ']; // start of vec, tuple, fixed array, part of struct def or in tuple
23
24
 
24
- const mappings = [// alias <T::InherentOfflineReport as InherentOfflineReport>::Inherent -> InherentOfflineReport
25
- alias('<T::InherentOfflineReport as InherentOfflineReport>::Inherent', 'InherentOfflineReport', false), alias('VecDeque<', 'Vec<', false), // <T::Balance as HasCompact>
26
- cleanupCompact(), // Change BoundedVec<Type, Size> to Vec<Type>
27
- removeExtensions('Bounded', true), // Change WeakVec<Type> to Vec<Type>
28
- removeExtensions('Weak', false), // Remove all the trait prefixes
29
- removeTraits(), // remove PairOf<T> -> (T, T)
30
- removePairOf(), // remove boxing, `Box<Proposal>` -> `Proposal`
31
- removeWrap('Box<'), // remove generics, `MisbehaviorReport<Hash, BlockNumber>` -> `MisbehaviorReport`
32
- removeGenerics(), // alias String -> Text (compat with jsonrpc methods)
33
- alias('String', 'Text'), // alias Vec<u8> -> Bytes
34
- alias('Vec<u8>', 'Bytes'), alias('&\\[u8\\]', 'Bytes'), alias("&'static\\[u8\\]", 'Bytes'), // alias RawAddress -> Address
35
- alias('RawAddress', 'Address'), // lookups, mapped to Address/AccountId as appropriate in runtime
36
- alias('Lookup::Source', 'LookupSource'), alias('Lookup::Target', 'LookupTarget'), // HACK duplication between contracts & primitives, however contracts prefixed with exec
37
- alias('exec::StorageKey', 'ContractStorageKey'), // flattens tuples with one value, `(AccountId)` -> `AccountId`
38
- flattenSingleTuple(), // converts ::Type to Type, <T as Trait<I>>::Proposal -> Proposal
39
- removeColons(), // remove all trailing spaces - this should always be the last
40
- trim()]; // given a string, trim it
41
-
25
+ const mappings = [
26
+ // alias <T::InherentOfflineReport as InherentOfflineReport>::Inherent -> InherentOfflineReport
27
+ alias('<T::InherentOfflineReport as InherentOfflineReport>::Inherent', 'InherentOfflineReport', false), alias('VecDeque<', 'Vec<', false),
28
+ // <T::Balance as HasCompact>
29
+ cleanupCompact(),
30
+ // Change BoundedVec<Type, Size> to Vec<Type>
31
+ removeExtensions('Bounded', true),
32
+ // Change WeakVec<Type> to Vec<Type>
33
+ removeExtensions('Weak', false),
34
+ // Remove all the trait prefixes
35
+ removeTraits(),
36
+ // remove PairOf<T> -> (T, T)
37
+ removePairOf(),
38
+ // remove boxing, `Box<Proposal>` -> `Proposal`
39
+ removeWrap('Box<'),
40
+ // remove generics, `MisbehaviorReport<Hash, BlockNumber>` -> `MisbehaviorReport`
41
+ removeGenerics(),
42
+ // alias String -> Text (compat with jsonrpc methods)
43
+ alias('String', 'Text'),
44
+ // alias Vec<u8> -> Bytes
45
+ alias('Vec<u8>', 'Bytes'), alias('&\\[u8\\]', 'Bytes'), alias("&'static\\[u8\\]", 'Bytes'),
46
+ // alias RawAddress -> Address
47
+ alias('RawAddress', 'Address'),
48
+ // lookups, mapped to Address/AccountId as appropriate in runtime
49
+ alias('Lookup::Source', 'LookupSource'), alias('Lookup::Target', 'LookupTarget'),
50
+ // HACK duplication between contracts & primitives, however contracts prefixed with exec
51
+ alias('exec::StorageKey', 'ContractStorageKey'),
52
+ // flattens tuples with one value, `(AccountId)` -> `AccountId`
53
+ flattenSingleTuple(),
54
+ // converts ::Type to Type, <T as Trait<I>>::Proposal -> Proposal
55
+ removeColons(),
56
+ // remove all trailing spaces - this should always be the last
57
+ trim()];
58
+
59
+ // given a string, trim it
42
60
  function trim() {
43
61
  return value => value.trim();
44
- } // given a starting index, find the closing >
45
-
62
+ }
46
63
 
64
+ // given a starting index, find the closing >
47
65
  function findClosing(value, start) {
48
66
  let depth = 0;
49
-
50
67
  for (let index = start; index < value.length; index++) {
51
68
  if (value[index] === '>') {
52
69
  if (!depth) {
53
70
  return index;
54
71
  }
55
-
56
72
  depth--;
57
73
  } else if (value[index] === '<') {
58
74
  depth++;
59
75
  }
60
76
  }
61
-
62
77
  throw new Error(`Unable to find closing matching <> on '${value}' (start ${start})`);
63
78
  }
64
-
65
79
  function alias(src, dest) {
66
80
  let withChecks = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
67
81
  const from = new RegExp(`(^${src}|${BOX_PRECEDING.map(box => `\\${box}${src}`).join('|')})`, 'g');
68
-
69
82
  const to = src => {
70
83
  from.lastIndex = 0;
71
84
  return withChecks && BOX_PRECEDING.includes(src[0]) ? `${src[0]}${dest}` : dest;
72
85
  };
73
-
74
86
  return value => value.replace(from, to);
75
87
  }
76
-
77
88
  function cleanupCompact() {
78
89
  return value => {
79
90
  if (value.includes(' as HasCompact')) {
80
91
  for (let index = 0; index < value.length; index++) {
81
92
  if (value[index] === '<') {
82
93
  const end = findClosing(value, index + 1) - 14;
83
-
84
94
  if (value.substring(end, end + 14) === ' as HasCompact') {
85
95
  value = `Compact<${value.substring(index + 1, end)}>`;
86
96
  }
87
97
  }
88
98
  }
89
99
  }
90
-
91
100
  return value;
92
101
  };
93
102
  }
94
-
95
103
  function flattenSingleTuple() {
96
104
  const from1 = /,\)/g;
97
105
  const from2 = /\(([^,]+)\)/;
98
106
  return value => {
99
107
  from1.lastIndex = 0;
100
- return value // tuples may have trailing commas, e.g. (u32, BlockNumber, )
101
- .replace(from1, ')') // change (u32) -> u32
108
+ return value
109
+ // tuples may have trailing commas, e.g. (u32, BlockNumber, )
110
+ .replace(from1, ')')
111
+ // change (u32) -> u32
102
112
  .replace(from2, '$1');
103
113
  };
104
114
  }
105
-
106
115
  function replaceTagWith(value, matcher, replacer) {
107
116
  let index = -1;
108
-
109
117
  while (true) {
110
118
  index = value.indexOf(matcher, index + 1);
111
-
112
119
  if (index === -1) {
113
120
  return value;
114
121
  }
115
-
116
122
  const start = index + matcher.length;
117
123
  const end = findClosing(value, start);
118
124
  value = `${value.substring(0, index)}${replacer(value.substring(start, end))}${value.substring(end + 1)}`;
119
125
  }
120
- } // remove the Bounded* or Weak* wrappers
121
-
126
+ }
122
127
 
128
+ // remove the Bounded* or Weak* wrappers
123
129
  function removeExtensions(type, isSized) {
124
130
  return value => {
125
131
  for (let i = 0; i < BOUNDED.length; i++) {
126
132
  const tag = BOUNDED[i];
127
133
  value = replaceTagWith(value, `${type}${tag}<`, v => {
128
134
  const parts = v.split(',').map(s => s.trim()).filter(s => s);
129
-
130
135
  if (isSized) {
131
136
  parts.pop();
132
137
  }
133
-
134
138
  return `${tag}<${parts.join(',')}>`;
135
139
  });
136
140
  }
137
-
138
141
  return value;
139
142
  };
140
143
  }
141
-
142
144
  function removeColons() {
143
145
  return value => {
144
146
  let index = 0;
145
-
146
147
  while (index !== -1) {
147
148
  index = value.indexOf('::');
148
-
149
149
  if (index === 0) {
150
150
  value = value.substring(2);
151
151
  } else if (index !== -1) {
152
152
  let start = index;
153
-
154
153
  while (start !== -1 && !BOX_PRECEDING.includes(value[start])) {
155
154
  start--;
156
155
  }
157
-
158
156
  value = `${value.substring(0, start + 1)}${value.substring(index + 2)}`;
159
157
  }
160
158
  }
161
-
162
159
  return value;
163
160
  };
164
161
  }
165
-
166
162
  function removeGenerics() {
167
163
  return value => {
168
164
  for (let index = 0; index < value.length; index++) {
@@ -170,29 +166,29 @@ function removeGenerics() {
170
166
  // check against the allowed wrappers, be it Vec<..>, Option<...> ...
171
167
  const box = ALLOWED_BOXES.find(box => {
172
168
  const start = index - box.length;
173
- return start >= 0 && value.substring(start, index) === box && ( // make sure it is stand-alone, i.e. don't catch ElectionResult<...> as Result<...>
169
+ return start >= 0 && value.substring(start, index) === box && (
170
+ // make sure it is stand-alone, i.e. don't catch ElectionResult<...> as Result<...>
174
171
  start === 0 || BOX_PRECEDING.includes(value[start - 1]));
175
- }); // we have not found anything, unwrap generic innards
172
+ });
176
173
 
174
+ // we have not found anything, unwrap generic innards
177
175
  if (!box) {
178
176
  const end = findClosing(value, index + 1);
179
177
  value = `${value.substring(0, index)}${value.substring(end + 1)}`;
180
178
  }
181
179
  }
182
180
  }
183
-
184
181
  return value;
185
182
  };
186
- } // remove the PairOf wrappers
187
-
183
+ }
188
184
 
185
+ // remove the PairOf wrappers
189
186
  function removePairOf() {
190
187
  const replacer = v => `(${v},${v})`;
191
-
192
188
  return value => replaceTagWith(value, 'PairOf<', replacer);
193
- } // remove the type traits
194
-
189
+ }
195
190
 
191
+ // remove the type traits
196
192
  function removeTraits() {
197
193
  const from1 = /\s/g;
198
194
  const from2 = /(T|Self)::/g;
@@ -207,39 +203,38 @@ function removeTraits() {
207
203
  from4.lastIndex = 0;
208
204
  from5.lastIndex = 0;
209
205
  from6.lastIndex = 0;
210
- return value // remove all whitespaces
211
- .replace(from1, '') // anything `T::<type>` to end up as `<type>`
212
- .replace(from2, '') // replace `<T as Trait>::` (whitespaces were removed above)
213
- .replace(from3, '') // replace `<T as something::Trait>::` (whitespaces were removed above)
214
- .replace(from4, '') // replace <Lookup as StaticLookup>
215
- .replace(from5, 'Lookup') // replace `<...>::Type`
206
+ return value
207
+ // remove all whitespaces
208
+ .replace(from1, '')
209
+ // anything `T::<type>` to end up as `<type>`
210
+ .replace(from2, '')
211
+ // replace `<T as Trait>::` (whitespaces were removed above)
212
+ .replace(from3, '')
213
+ // replace `<T as something::Trait>::` (whitespaces were removed above)
214
+ .replace(from4, '')
215
+ // replace <Lookup as StaticLookup>
216
+ .replace(from5, 'Lookup')
217
+ // replace `<...>::Type`
216
218
  .replace(from6, '');
217
219
  };
218
- } // remove wrapping values, i.e. Box<Proposal> -> Proposal
219
-
220
+ }
220
221
 
222
+ // remove wrapping values, i.e. Box<Proposal> -> Proposal
221
223
  function removeWrap(check) {
222
224
  const replacer = v => v;
223
-
224
225
  return value => replaceTagWith(value, check, replacer);
225
226
  }
226
-
227
227
  const sanitizeMap = new Map();
228
-
229
228
  function sanitize(value) {
230
229
  const startValue = value.toString();
231
230
  const memoized = sanitizeMap.get(startValue);
232
-
233
231
  if (memoized) {
234
232
  return memoized;
235
233
  }
236
-
237
234
  let result = startValue;
238
-
239
235
  for (let i = 0; i < mappings.length; i++) {
240
236
  result = mappings[i](result);
241
237
  }
242
-
243
238
  sanitizeMap.set(startValue, result);
244
239
  return result;
245
240
  }
@@ -6,9 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.sortAsc = sortAsc;
7
7
  exports.sortMap = sortMap;
8
8
  exports.sortSet = sortSet;
9
-
10
9
  var _util = require("@polkadot/util");
11
-
12
10
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
13
11
  // SPDX-License-Identifier: Apache-2.0
14
12
 
@@ -16,49 +14,41 @@ var _util = require("@polkadot/util");
16
14
  function isArrayLike(arg) {
17
15
  return arg instanceof Uint8Array || Array.isArray(arg);
18
16
  }
19
- /** @internal **/
20
-
21
17
 
18
+ /** @internal **/
22
19
  function isCodec(arg) {
23
20
  return (0, _util.isFunction)(arg && arg.toU8a);
24
21
  }
25
- /** @internal **/
26
-
27
22
 
23
+ /** @internal **/
28
24
  function isEnum(arg) {
29
25
  return isCodec(arg) && (0, _util.isNumber)(arg.index) && isCodec(arg.value);
30
26
  }
31
- /** @internal */
32
-
33
27
 
28
+ /** @internal */
34
29
  function isNumberLike(arg) {
35
30
  return (0, _util.isNumber)(arg) || (0, _util.isBn)(arg) || (0, _util.isBigInt)(arg);
36
31
  }
37
- /** @internal */
38
-
39
32
 
33
+ /** @internal */
40
34
  function sortArray(a, b) {
41
35
  // Vec, Tuple, Bytes etc.
42
36
  let sortRes = 0;
43
37
  const minLen = Math.min(a.length, b.length);
44
-
45
38
  for (let i = 0; i < minLen; ++i) {
46
39
  sortRes = sortAsc(a[i], b[i]);
47
-
48
40
  if (sortRes !== 0) {
49
41
  return sortRes;
50
42
  }
51
43
  }
52
-
53
44
  return a.length - b.length;
54
45
  }
46
+
55
47
  /**
56
48
  * Sort keys/values of BTreeSet/BTreeMap in ascending order for encoding compatibility with Rust's BTreeSet/BTreeMap
57
49
  * (https://doc.rust-lang.org/stable/std/collections/struct.BTreeSet.html)
58
50
  * (https://doc.rust-lang.org/stable/std/collections/struct.BTreeMap.html)
59
51
  */
60
-
61
-
62
52
  function sortAsc(a, b) {
63
53
  if (isNumberLike(a) && isNumberLike(b)) {
64
54
  return (0, _util.bnToBn)(a).cmp((0, _util.bnToBn)(b));
@@ -72,14 +62,11 @@ function sortAsc(a, b) {
72
62
  // Text, Bool etc.
73
63
  return sortAsc(a.toU8a(true), b.toU8a(true));
74
64
  }
75
-
76
65
  throw new Error(`Attempting to sort unrecognized values: ${(0, _util.stringify)(a)} (typeof ${typeof a}) <-> ${(0, _util.stringify)(b)} (typeof ${typeof b})`);
77
66
  }
78
-
79
67
  function sortSet(set) {
80
68
  return new Set(Array.from(set).sort(sortAsc));
81
69
  }
82
-
83
70
  function sortMap(map) {
84
71
  return new Map(Array.from(map.entries()).sort((_ref, _ref2) => {
85
72
  let [keyA] = _ref;
@@ -4,11 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.typeToConstructor = typeToConstructor;
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
10
+
12
11
  function typeToConstructor(registry, type) {
13
12
  return (0, _util.isString)(type) ? registry.createClassUnsafe(type) : type;
14
13
  }
@@ -4,16 +4,14 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.typesToMap = typesToMap;
7
-
8
7
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
9
8
  // SPDX-License-Identifier: Apache-2.0
9
+
10
10
  function typesToMap(registry, _ref) {
11
11
  let [Types, keys] = _ref;
12
12
  const result = {};
13
-
14
13
  for (let i = 0; i < keys.length; i++) {
15
14
  result[keys[i]] = registry.getClassName(Types[i]) || new Types[i](registry).toRawType();
16
15
  }
17
-
18
16
  return result;
19
17
  }
package/cjs/utils/util.js CHANGED
@@ -4,11 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.hasEq = hasEq;
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
10
+
12
11
  function hasEq(o) {
13
12
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
14
13
  return (0, _util.isFunction)(o.eq);
package/detectOther.js CHANGED
@@ -1,4 +1,6 @@
1
1
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+
3
4
  // Empty template, auto-generated by @polkadot/dev
5
+
4
6
  export default [];
package/detectPackage.js CHANGED
@@ -1,6 +1,8 @@
1
1
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+
3
4
  // Do not edit, auto-generated by @polkadot/dev
5
+
4
6
  import { detectPackage } from '@polkadot/util';
5
7
  import others from "./detectOther.js";
6
8
  import { packageInfo } from "./packageInfo.js";
@@ -1,5 +1,6 @@
1
1
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+
3
4
  import { CodecMap } from "./Map.js";
4
5
  export class BTreeMap extends CodecMap {
5
6
  static with(keyType, valType) {
@@ -7,8 +8,6 @@ export class BTreeMap extends CodecMap {
7
8
  constructor(registry, value) {
8
9
  super(registry, keyType, valType, value, 'BTreeMap');
9
10
  }
10
-
11
11
  };
12
12
  }
13
-
14
13
  }