@polkadot/types-codec 9.5.1 → 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 +4 -4
  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
@@ -1,19 +1,18 @@
1
1
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+
3
4
  import { typeToConstructor } from "./typeToConstructor.js";
5
+
4
6
  /**
5
7
  * @description takes an input map of the form `{ [string]: string | CodecClass }` and returns a map of `{ [string]: CodecClass }`
6
8
  */
7
-
8
9
  export function mapToTypeMap(registry, input) {
9
10
  const entries = Object.entries(input);
10
11
  const count = entries.length;
11
12
  const output = [new Array(count), new Array(count)];
12
-
13
13
  for (let i = 0; i < count; i++) {
14
14
  output[1][i] = entries[i][0];
15
15
  output[0][i] = typeToConstructor(registry, entries[i][1]);
16
16
  }
17
-
18
17
  return output;
19
18
  }
package/utils/sanitize.js CHANGED
@@ -1,56 +1,70 @@
1
1
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+
3
4
  const BOUNDED = ['BTreeMap', 'BTreeSet', 'HashMap', 'Vec'];
4
5
  const ALLOWED_BOXES = BOUNDED.concat(['Compact', 'DoNotConstruct', 'Int', 'Linkage', 'Range', 'RangeInclusive', 'Result', 'Opaque', 'Option', 'UInt', 'WrapperKeepOpaque', 'WrapperOpaque']);
5
6
  const BOX_PRECEDING = ['<', '(', '[', '"', ',', ' ']; // start of vec, tuple, fixed array, part of struct def or in tuple
6
7
 
7
- const mappings = [// alias <T::InherentOfflineReport as InherentOfflineReport>::Inherent -> InherentOfflineReport
8
- alias('<T::InherentOfflineReport as InherentOfflineReport>::Inherent', 'InherentOfflineReport', false), alias('VecDeque<', 'Vec<', false), // <T::Balance as HasCompact>
9
- cleanupCompact(), // Change BoundedVec<Type, Size> to Vec<Type>
10
- removeExtensions('Bounded', true), // Change WeakVec<Type> to Vec<Type>
11
- removeExtensions('Weak', false), // Remove all the trait prefixes
12
- removeTraits(), // remove PairOf<T> -> (T, T)
13
- removePairOf(), // remove boxing, `Box<Proposal>` -> `Proposal`
14
- removeWrap('Box<'), // remove generics, `MisbehaviorReport<Hash, BlockNumber>` -> `MisbehaviorReport`
15
- removeGenerics(), // alias String -> Text (compat with jsonrpc methods)
16
- alias('String', 'Text'), // alias Vec<u8> -> Bytes
17
- alias('Vec<u8>', 'Bytes'), alias('&\\[u8\\]', 'Bytes'), alias("&'static\\[u8\\]", 'Bytes'), // alias RawAddress -> Address
18
- alias('RawAddress', 'Address'), // lookups, mapped to Address/AccountId as appropriate in runtime
19
- alias('Lookup::Source', 'LookupSource'), alias('Lookup::Target', 'LookupTarget'), // HACK duplication between contracts & primitives, however contracts prefixed with exec
20
- alias('exec::StorageKey', 'ContractStorageKey'), // flattens tuples with one value, `(AccountId)` -> `AccountId`
21
- flattenSingleTuple(), // converts ::Type to Type, <T as Trait<I>>::Proposal -> Proposal
22
- removeColons(), // remove all trailing spaces - this should always be the last
23
- trim()]; // given a string, trim it
24
-
8
+ const mappings = [
9
+ // alias <T::InherentOfflineReport as InherentOfflineReport>::Inherent -> InherentOfflineReport
10
+ alias('<T::InherentOfflineReport as InherentOfflineReport>::Inherent', 'InherentOfflineReport', false), alias('VecDeque<', 'Vec<', false),
11
+ // <T::Balance as HasCompact>
12
+ cleanupCompact(),
13
+ // Change BoundedVec<Type, Size> to Vec<Type>
14
+ removeExtensions('Bounded', true),
15
+ // Change WeakVec<Type> to Vec<Type>
16
+ removeExtensions('Weak', false),
17
+ // Remove all the trait prefixes
18
+ removeTraits(),
19
+ // remove PairOf<T> -> (T, T)
20
+ removePairOf(),
21
+ // remove boxing, `Box<Proposal>` -> `Proposal`
22
+ removeWrap('Box<'),
23
+ // remove generics, `MisbehaviorReport<Hash, BlockNumber>` -> `MisbehaviorReport`
24
+ removeGenerics(),
25
+ // alias String -> Text (compat with jsonrpc methods)
26
+ alias('String', 'Text'),
27
+ // alias Vec<u8> -> Bytes
28
+ alias('Vec<u8>', 'Bytes'), alias('&\\[u8\\]', 'Bytes'), alias("&'static\\[u8\\]", 'Bytes'),
29
+ // alias RawAddress -> Address
30
+ alias('RawAddress', 'Address'),
31
+ // lookups, mapped to Address/AccountId as appropriate in runtime
32
+ alias('Lookup::Source', 'LookupSource'), alias('Lookup::Target', 'LookupTarget'),
33
+ // HACK duplication between contracts & primitives, however contracts prefixed with exec
34
+ alias('exec::StorageKey', 'ContractStorageKey'),
35
+ // flattens tuples with one value, `(AccountId)` -> `AccountId`
36
+ flattenSingleTuple(),
37
+ // converts ::Type to Type, <T as Trait<I>>::Proposal -> Proposal
38
+ removeColons(),
39
+ // remove all trailing spaces - this should always be the last
40
+ trim()];
41
+
42
+ // given a string, trim it
25
43
  export function trim() {
26
44
  return value => value.trim();
27
- } // given a starting index, find the closing >
45
+ }
28
46
 
47
+ // given a starting index, find the closing >
29
48
  export function findClosing(value, start) {
30
49
  let depth = 0;
31
-
32
50
  for (let index = start; index < value.length; index++) {
33
51
  if (value[index] === '>') {
34
52
  if (!depth) {
35
53
  return index;
36
54
  }
37
-
38
55
  depth--;
39
56
  } else if (value[index] === '<') {
40
57
  depth++;
41
58
  }
42
59
  }
43
-
44
60
  throw new Error(`Unable to find closing matching <> on '${value}' (start ${start})`);
45
61
  }
46
62
  export function alias(src, dest, withChecks = true) {
47
63
  const from = new RegExp(`(^${src}|${BOX_PRECEDING.map(box => `\\${box}${src}`).join('|')})`, 'g');
48
-
49
64
  const to = src => {
50
65
  from.lastIndex = 0;
51
66
  return withChecks && BOX_PRECEDING.includes(src[0]) ? `${src[0]}${dest}` : dest;
52
67
  };
53
-
54
68
  return value => value.replace(from, to);
55
69
  }
56
70
  export function cleanupCompact() {
@@ -59,14 +73,12 @@ export function cleanupCompact() {
59
73
  for (let index = 0; index < value.length; index++) {
60
74
  if (value[index] === '<') {
61
75
  const end = findClosing(value, index + 1) - 14;
62
-
63
76
  if (value.substring(end, end + 14) === ' as HasCompact') {
64
77
  value = `Compact<${value.substring(index + 1, end)}>`;
65
78
  }
66
79
  }
67
80
  }
68
81
  }
69
-
70
82
  return value;
71
83
  };
72
84
  }
@@ -75,67 +87,57 @@ export function flattenSingleTuple() {
75
87
  const from2 = /\(([^,]+)\)/;
76
88
  return value => {
77
89
  from1.lastIndex = 0;
78
- return value // tuples may have trailing commas, e.g. (u32, BlockNumber, )
79
- .replace(from1, ')') // change (u32) -> u32
90
+ return value
91
+ // tuples may have trailing commas, e.g. (u32, BlockNumber, )
92
+ .replace(from1, ')')
93
+ // change (u32) -> u32
80
94
  .replace(from2, '$1');
81
95
  };
82
96
  }
83
-
84
97
  function replaceTagWith(value, matcher, replacer) {
85
98
  let index = -1;
86
-
87
99
  while (true) {
88
100
  index = value.indexOf(matcher, index + 1);
89
-
90
101
  if (index === -1) {
91
102
  return value;
92
103
  }
93
-
94
104
  const start = index + matcher.length;
95
105
  const end = findClosing(value, start);
96
106
  value = `${value.substring(0, index)}${replacer(value.substring(start, end))}${value.substring(end + 1)}`;
97
107
  }
98
- } // remove the Bounded* or Weak* wrappers
99
-
108
+ }
100
109
 
110
+ // remove the Bounded* or Weak* wrappers
101
111
  export function removeExtensions(type, isSized) {
102
112
  return value => {
103
113
  for (let i = 0; i < BOUNDED.length; i++) {
104
114
  const tag = BOUNDED[i];
105
115
  value = replaceTagWith(value, `${type}${tag}<`, v => {
106
116
  const parts = v.split(',').map(s => s.trim()).filter(s => s);
107
-
108
117
  if (isSized) {
109
118
  parts.pop();
110
119
  }
111
-
112
120
  return `${tag}<${parts.join(',')}>`;
113
121
  });
114
122
  }
115
-
116
123
  return value;
117
124
  };
118
125
  }
119
126
  export function removeColons() {
120
127
  return value => {
121
128
  let index = 0;
122
-
123
129
  while (index !== -1) {
124
130
  index = value.indexOf('::');
125
-
126
131
  if (index === 0) {
127
132
  value = value.substring(2);
128
133
  } else if (index !== -1) {
129
134
  let start = index;
130
-
131
135
  while (start !== -1 && !BOX_PRECEDING.includes(value[start])) {
132
136
  start--;
133
137
  }
134
-
135
138
  value = `${value.substring(0, start + 1)}${value.substring(index + 2)}`;
136
139
  }
137
140
  }
138
-
139
141
  return value;
140
142
  };
141
143
  }
@@ -146,27 +148,29 @@ export function removeGenerics() {
146
148
  // check against the allowed wrappers, be it Vec<..>, Option<...> ...
147
149
  const box = ALLOWED_BOXES.find(box => {
148
150
  const start = index - box.length;
149
- return start >= 0 && value.substring(start, index) === box && ( // make sure it is stand-alone, i.e. don't catch ElectionResult<...> as Result<...>
151
+ return start >= 0 && value.substring(start, index) === box && (
152
+ // make sure it is stand-alone, i.e. don't catch ElectionResult<...> as Result<...>
150
153
  start === 0 || BOX_PRECEDING.includes(value[start - 1]));
151
- }); // we have not found anything, unwrap generic innards
154
+ });
152
155
 
156
+ // we have not found anything, unwrap generic innards
153
157
  if (!box) {
154
158
  const end = findClosing(value, index + 1);
155
159
  value = `${value.substring(0, index)}${value.substring(end + 1)}`;
156
160
  }
157
161
  }
158
162
  }
159
-
160
163
  return value;
161
164
  };
162
- } // remove the PairOf wrappers
165
+ }
163
166
 
167
+ // remove the PairOf wrappers
164
168
  export function removePairOf() {
165
169
  const replacer = v => `(${v},${v})`;
166
-
167
170
  return value => replaceTagWith(value, 'PairOf<', replacer);
168
- } // remove the type traits
171
+ }
169
172
 
173
+ // remove the type traits
170
174
  export function removeTraits() {
171
175
  const from1 = /\s/g;
172
176
  const from2 = /(T|Self)::/g;
@@ -181,36 +185,38 @@ export function removeTraits() {
181
185
  from4.lastIndex = 0;
182
186
  from5.lastIndex = 0;
183
187
  from6.lastIndex = 0;
184
- return value // remove all whitespaces
185
- .replace(from1, '') // anything `T::<type>` to end up as `<type>`
186
- .replace(from2, '') // replace `<T as Trait>::` (whitespaces were removed above)
187
- .replace(from3, '') // replace `<T as something::Trait>::` (whitespaces were removed above)
188
- .replace(from4, '') // replace <Lookup as StaticLookup>
189
- .replace(from5, 'Lookup') // replace `<...>::Type`
188
+ return value
189
+ // remove all whitespaces
190
+ .replace(from1, '')
191
+ // anything `T::<type>` to end up as `<type>`
192
+ .replace(from2, '')
193
+ // replace `<T as Trait>::` (whitespaces were removed above)
194
+ .replace(from3, '')
195
+ // replace `<T as something::Trait>::` (whitespaces were removed above)
196
+ .replace(from4, '')
197
+ // replace <Lookup as StaticLookup>
198
+ .replace(from5, 'Lookup')
199
+ // replace `<...>::Type`
190
200
  .replace(from6, '');
191
201
  };
192
- } // remove wrapping values, i.e. Box<Proposal> -> Proposal
202
+ }
193
203
 
204
+ // remove wrapping values, i.e. Box<Proposal> -> Proposal
194
205
  export function removeWrap(check) {
195
206
  const replacer = v => v;
196
-
197
207
  return value => replaceTagWith(value, check, replacer);
198
208
  }
199
209
  const sanitizeMap = new Map();
200
210
  export function sanitize(value) {
201
211
  const startValue = value.toString();
202
212
  const memoized = sanitizeMap.get(startValue);
203
-
204
213
  if (memoized) {
205
214
  return memoized;
206
215
  }
207
-
208
216
  let result = startValue;
209
-
210
217
  for (let i = 0; i < mappings.length; i++) {
211
218
  result = mappings[i](result);
212
219
  }
213
-
214
220
  sanitizeMap.set(startValue, result);
215
221
  return result;
216
222
  }
@@ -1,54 +1,46 @@
1
1
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import { bnToBn, isBigInt, isBn, isFunction, isNumber, stringify } from '@polkadot/util';
4
3
 
4
+ import { bnToBn, isBigInt, isBn, isFunction, isNumber, stringify } from '@polkadot/util';
5
5
  /** @internal **/
6
6
  function isArrayLike(arg) {
7
7
  return arg instanceof Uint8Array || Array.isArray(arg);
8
8
  }
9
- /** @internal **/
10
-
11
9
 
10
+ /** @internal **/
12
11
  function isCodec(arg) {
13
12
  return isFunction(arg && arg.toU8a);
14
13
  }
15
- /** @internal **/
16
-
17
14
 
15
+ /** @internal **/
18
16
  function isEnum(arg) {
19
17
  return isCodec(arg) && isNumber(arg.index) && isCodec(arg.value);
20
18
  }
21
- /** @internal */
22
-
23
19
 
20
+ /** @internal */
24
21
  function isNumberLike(arg) {
25
22
  return isNumber(arg) || isBn(arg) || isBigInt(arg);
26
23
  }
27
- /** @internal */
28
-
29
24
 
25
+ /** @internal */
30
26
  function sortArray(a, b) {
31
27
  // Vec, Tuple, Bytes etc.
32
28
  let sortRes = 0;
33
29
  const minLen = Math.min(a.length, b.length);
34
-
35
30
  for (let i = 0; i < minLen; ++i) {
36
31
  sortRes = sortAsc(a[i], b[i]);
37
-
38
32
  if (sortRes !== 0) {
39
33
  return sortRes;
40
34
  }
41
35
  }
42
-
43
36
  return a.length - b.length;
44
37
  }
38
+
45
39
  /**
46
40
  * Sort keys/values of BTreeSet/BTreeMap in ascending order for encoding compatibility with Rust's BTreeSet/BTreeMap
47
41
  * (https://doc.rust-lang.org/stable/std/collections/struct.BTreeSet.html)
48
42
  * (https://doc.rust-lang.org/stable/std/collections/struct.BTreeMap.html)
49
43
  */
50
-
51
-
52
44
  export function sortAsc(a, b) {
53
45
  if (isNumberLike(a) && isNumberLike(b)) {
54
46
  return bnToBn(a).cmp(bnToBn(b));
@@ -62,7 +54,6 @@ export function sortAsc(a, b) {
62
54
  // Text, Bool etc.
63
55
  return sortAsc(a.toU8a(true), b.toU8a(true));
64
56
  }
65
-
66
57
  throw new Error(`Attempting to sort unrecognized values: ${stringify(a)} (typeof ${typeof a}) <-> ${stringify(b)} (typeof ${typeof b})`);
67
58
  }
68
59
  export function sortSet(set) {
@@ -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 { isString } from '@polkadot/util';
4
5
  export function typeToConstructor(registry, type) {
5
6
  return isString(type) ? registry.createClassUnsafe(type) : type;
@@ -1,11 +1,10 @@
1
1
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+
3
4
  export function typesToMap(registry, [Types, keys]) {
4
5
  const result = {};
5
-
6
6
  for (let i = 0; i < keys.length; i++) {
7
7
  result[keys[i]] = registry.getClassName(Types[i]) || new Types[i](registry).toRawType();
8
8
  }
9
-
10
9
  return result;
11
10
  }
package/utils/util.js CHANGED
@@ -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 { isFunction } from '@polkadot/util';
4
5
  export function hasEq(o) {
5
6
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access