@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.
- package/abstract/{AbstractArray.d.ts → Array.d.ts} +0 -0
- package/abstract/{AbstractArray.js → Array.js} +0 -0
- package/{base → abstract}/Base.d.ts +2 -2
- package/{base → abstract}/Base.js +2 -7
- package/abstract/{AbstractInt.d.ts → Int.d.ts} +1 -4
- package/abstract/{AbstractInt.js → Int.js} +19 -22
- package/abstract/index.d.ts +3 -2
- package/abstract/index.js +3 -2
- package/base/Compact.d.ts +0 -2
- package/base/Compact.js +16 -17
- package/base/Enum.js +6 -6
- package/base/Int.d.ts +1 -1
- package/base/Int.js +1 -1
- package/base/Null.d.ts +2 -8
- package/base/Null.js +2 -16
- package/base/Option.d.ts +1 -4
- package/base/Option.js +1 -10
- package/base/Tuple.d.ts +1 -1
- package/base/Tuple.js +3 -4
- package/base/UInt.d.ts +1 -1
- package/base/UInt.js +1 -1
- package/base/Vec.d.ts +1 -1
- package/base/Vec.js +2 -3
- package/base/VecAny.d.ts +1 -1
- package/base/VecAny.js +1 -1
- package/base/VecFixed.d.ts +1 -1
- package/base/VecFixed.js +2 -3
- package/base/index.d.ts +0 -1
- package/base/index.js +0 -1
- package/cjs/abstract/{AbstractArray.js → Array.js} +0 -0
- package/cjs/{base → abstract}/Base.js +4 -9
- package/cjs/abstract/{AbstractInt.js → Int.js} +18 -21
- package/cjs/abstract/index.js +12 -4
- package/cjs/base/Compact.js +15 -16
- package/cjs/base/Enum.js +5 -5
- package/cjs/base/Int.js +2 -2
- package/cjs/base/Null.js +2 -16
- package/cjs/base/Option.js +1 -10
- package/cjs/base/Tuple.js +4 -5
- package/cjs/base/UInt.js +2 -2
- package/cjs/base/Vec.js +3 -4
- package/cjs/base/VecAny.js +2 -2
- package/cjs/base/VecFixed.js +3 -4
- package/cjs/base/index.js +0 -8
- package/cjs/extended/Bytes.js +1 -1
- package/cjs/extended/Map.js +2 -2
- package/cjs/extended/OptionBool.js +1 -8
- package/cjs/native/Struct.js +2 -7
- package/cjs/native/Text.js +1 -10
- package/cjs/packageInfo.js +1 -1
- package/cjs/utils/decodeU8a.js +63 -20
- package/cjs/utils/index.js +6 -0
- package/cjs/utils/mapToTypeMap.js +1 -1
- package/cjs/utils/sanitize.js +17 -37
- package/extended/Bytes.js +2 -2
- package/extended/Map.js +1 -1
- package/extended/OptionBool.d.ts +0 -4
- package/extended/OptionBool.js +1 -8
- package/native/Raw.d.ts +1 -1
- package/native/Struct.d.ts +1 -1
- package/native/Struct.js +3 -8
- package/native/Text.d.ts +2 -5
- package/native/Text.js +1 -10
- package/package.json +15 -15
- package/packageInfo.js +1 -1
- package/utils/decodeU8a.d.ts +16 -1
- package/utils/decodeU8a.js +57 -19
- package/utils/index.d.ts +1 -1
- package/utils/index.js +1 -1
- package/utils/mapToTypeMap.js +1 -1
- package/utils/sanitize.d.ts +3 -5
- package/utils/sanitize.js +17 -37
package/utils/mapToTypeMap.js
CHANGED
|
@@ -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 <
|
|
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
|
}
|
package/utils/sanitize.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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:
|
|
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
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
212
|
-
}
|
|
213
|
-
const sanitizeMap = new Map(); // eslint-disable-next-line @typescript-eslint/ban-types
|
|
195
|
+
const replacer = v => v;
|
|
214
196
|
|
|
215
|
-
|
|
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
|
-
|
|
202
|
+
const memoized = sanitizeMap.get(startValue);
|
|
218
203
|
|
|
219
|
-
if (
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
if (memoized) {
|
|
223
|
-
return memoized;
|
|
224
|
-
}
|
|
204
|
+
if (memoized) {
|
|
205
|
+
return memoized;
|
|
225
206
|
}
|
|
226
207
|
|
|
227
|
-
|
|
228
|
-
result = mappings[i](result, options);
|
|
229
|
-
}
|
|
208
|
+
let result = startValue;
|
|
230
209
|
|
|
231
|
-
|
|
232
|
-
|
|
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
|
}
|