@polkadot/types-codec 8.8.2 → 8.8.3-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 (72) hide show
  1. package/abstract/{AbstractArray.d.ts → Array.d.ts} +0 -0
  2. package/abstract/{AbstractArray.js → Array.js} +0 -0
  3. package/{base → abstract}/Base.d.ts +2 -2
  4. package/{base → abstract}/Base.js +2 -7
  5. package/abstract/{AbstractInt.d.ts → Int.d.ts} +1 -4
  6. package/abstract/{AbstractInt.js → Int.js} +19 -22
  7. package/abstract/index.d.ts +3 -2
  8. package/abstract/index.js +3 -2
  9. package/base/Compact.d.ts +0 -2
  10. package/base/Compact.js +16 -17
  11. package/base/Enum.js +6 -6
  12. package/base/Int.d.ts +1 -1
  13. package/base/Int.js +1 -1
  14. package/base/Null.d.ts +2 -8
  15. package/base/Null.js +2 -16
  16. package/base/Option.d.ts +1 -4
  17. package/base/Option.js +1 -10
  18. package/base/Tuple.d.ts +1 -1
  19. package/base/Tuple.js +3 -4
  20. package/base/UInt.d.ts +1 -1
  21. package/base/UInt.js +1 -1
  22. package/base/Vec.d.ts +1 -1
  23. package/base/Vec.js +2 -3
  24. package/base/VecAny.d.ts +1 -1
  25. package/base/VecAny.js +1 -1
  26. package/base/VecFixed.d.ts +1 -1
  27. package/base/VecFixed.js +2 -3
  28. package/base/index.d.ts +0 -1
  29. package/base/index.js +0 -1
  30. package/cjs/abstract/{AbstractArray.js → Array.js} +0 -0
  31. package/cjs/{base → abstract}/Base.js +4 -9
  32. package/cjs/abstract/{AbstractInt.js → Int.js} +18 -21
  33. package/cjs/abstract/index.js +12 -4
  34. package/cjs/base/Compact.js +15 -16
  35. package/cjs/base/Enum.js +5 -5
  36. package/cjs/base/Int.js +2 -2
  37. package/cjs/base/Null.js +2 -16
  38. package/cjs/base/Option.js +1 -10
  39. package/cjs/base/Tuple.js +4 -5
  40. package/cjs/base/UInt.js +2 -2
  41. package/cjs/base/Vec.js +3 -4
  42. package/cjs/base/VecAny.js +2 -2
  43. package/cjs/base/VecFixed.js +3 -4
  44. package/cjs/base/index.js +0 -8
  45. package/cjs/extended/Bytes.js +1 -1
  46. package/cjs/extended/Map.js +2 -2
  47. package/cjs/extended/OptionBool.js +1 -8
  48. package/cjs/native/Struct.js +2 -7
  49. package/cjs/native/Text.js +1 -10
  50. package/cjs/packageInfo.js +1 -1
  51. package/cjs/utils/decodeU8a.js +63 -20
  52. package/cjs/utils/index.js +6 -0
  53. package/cjs/utils/mapToTypeMap.js +1 -1
  54. package/cjs/utils/sanitize.js +17 -37
  55. package/extended/Bytes.js +2 -2
  56. package/extended/Map.js +1 -1
  57. package/extended/OptionBool.d.ts +0 -4
  58. package/extended/OptionBool.js +1 -8
  59. package/native/Raw.d.ts +1 -1
  60. package/native/Struct.d.ts +1 -1
  61. package/native/Struct.js +3 -8
  62. package/native/Text.d.ts +2 -5
  63. package/native/Text.js +1 -10
  64. package/package.json +15 -15
  65. package/packageInfo.js +1 -1
  66. package/utils/decodeU8a.d.ts +16 -1
  67. package/utils/decodeU8a.js +57 -19
  68. package/utils/index.d.ts +1 -1
  69. package/utils/index.js +1 -1
  70. package/utils/mapToTypeMap.js +1 -1
  71. package/utils/sanitize.d.ts +3 -5
  72. package/utils/sanitize.js +17 -37
@@ -10,7 +10,7 @@ export function mapToTypeMap(registry, input) {
10
10
  const count = entries.length;
11
11
  const output = [new Array(count), new Array(count)];
12
12
 
13
- for (let i = 0; i < entries.length; i++) {
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
  }
@@ -1,7 +1,5 @@
1
- interface SanitizeOptions {
2
- allowNamespaces?: boolean;
3
- }
4
- declare type Mapper = (value: string, options?: SanitizeOptions) => string;
1
+ import { AnyString } from '../types';
2
+ declare type Mapper = (value: string) => string;
5
3
  export declare function trim(): Mapper;
6
4
  export declare function findClosing(value: string, start: number): number;
7
5
  export declare function alias(src: string, dest: string, withChecks?: boolean): Mapper;
@@ -13,5 +11,5 @@ export declare function removeGenerics(): Mapper;
13
11
  export declare function removePairOf(): Mapper;
14
12
  export declare function removeTraits(): Mapper;
15
13
  export declare function removeWrap(check: string): Mapper;
16
- export declare function sanitize(value: String | string, options?: SanitizeOptions): string;
14
+ export declare function sanitize(value: AnyString): string;
17
15
  export {};
package/utils/sanitize.js CHANGED
@@ -117,9 +117,7 @@ export function removeExtensions(type, isSized) {
117
117
  };
118
118
  }
119
119
  export function removeColons() {
120
- return (value, {
121
- allowNamespaces
122
- } = {}) => {
120
+ return value => {
123
121
  let index = 0;
124
122
 
125
123
  while (index !== -1) {
@@ -128,10 +126,6 @@ export function removeColons() {
128
126
  if (index === 0) {
129
127
  value = value.substring(2);
130
128
  } else if (index !== -1) {
131
- if (allowNamespaces) {
132
- return value;
133
- }
134
-
135
129
  let start = index;
136
130
 
137
131
  while (start !== -1 && !BOX_PRECEDING.includes(value[start])) {
@@ -152,7 +146,7 @@ export function removeGenerics() {
152
146
  // check against the allowed wrappers, be it Vec<..>, Option<...> ...
153
147
  const box = ALLOWED_BOXES.find(box => {
154
148
  const start = index - box.length;
155
- return start >= 0 && value.substring(start, start + box.length) === box && ( // make sure it is stand-alone, i.e. don't catch ElectionResult<...> as Result<...>
149
+ return start >= 0 && value.substring(start, index) === box && ( // make sure it is stand-alone, i.e. don't catch ElectionResult<...> as Result<...>
156
150
  start === 0 || BOX_PRECEDING.includes(value[start - 1]));
157
151
  }); // we have not found anything, unwrap generic innards
158
152
 
@@ -165,16 +159,12 @@ export function removeGenerics() {
165
159
 
166
160
  return value;
167
161
  };
168
- }
169
- /** @internal */
170
-
171
- function pairOfReplacer(v) {
172
- return `(${v},${v})`;
173
162
  } // remove the PairOf wrappers
174
163
 
175
-
176
164
  export function removePairOf() {
177
- return value => replaceTagWith(value, 'PairOf<', pairOfReplacer);
165
+ const replacer = v => `(${v},${v})`;
166
+
167
+ return value => replaceTagWith(value, 'PairOf<', replacer);
178
168
  } // remove the type traits
179
169
 
180
170
  export function removeTraits() {
@@ -199,38 +189,28 @@ export function removeTraits() {
199
189
  .replace(from5, 'Lookup') // replace `<...>::Type`
200
190
  .replace(from6, '');
201
191
  };
202
- }
203
- /** @internal */
204
-
205
- function wrapReplacer(v) {
206
- return v;
207
192
  } // remove wrapping values, i.e. Box<Proposal> -> Proposal
208
193
 
209
-
210
194
  export function removeWrap(check) {
211
- return value => replaceTagWith(value, check, wrapReplacer);
212
- }
213
- const sanitizeMap = new Map(); // eslint-disable-next-line @typescript-eslint/ban-types
195
+ const replacer = v => v;
214
196
 
215
- export function sanitize(value, options) {
197
+ return value => replaceTagWith(value, check, replacer);
198
+ }
199
+ const sanitizeMap = new Map();
200
+ export function sanitize(value) {
216
201
  const startValue = value.toString();
217
- let result = startValue;
202
+ const memoized = sanitizeMap.get(startValue);
218
203
 
219
- if (!options) {
220
- const memoized = sanitizeMap.get(startValue);
221
-
222
- if (memoized) {
223
- return memoized;
224
- }
204
+ if (memoized) {
205
+ return memoized;
225
206
  }
226
207
 
227
- for (let i = 0; i < mappings.length; i++) {
228
- result = mappings[i](result, options);
229
- }
208
+ let result = startValue;
230
209
 
231
- if (!options) {
232
- sanitizeMap.set(startValue, result);
210
+ for (let i = 0; i < mappings.length; i++) {
211
+ result = mappings[i](result);
233
212
  }
234
213
 
214
+ sanitizeMap.set(startValue, result);
235
215
  return result;
236
216
  }