@polkadot/types-codec 10.4.1 → 10.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.
- package/abstract/Array.js +21 -14
- package/abstract/Base.js +13 -17
- package/abstract/Int.js +8 -12
- package/base/Compact.js +20 -28
- package/base/DoNotConstruct.js +14 -18
- package/base/Enum.js +42 -53
- package/base/Option.js +17 -25
- package/base/Tuple.js +12 -19
- package/base/Vec.js +10 -17
- package/base/VecFixed.js +7 -14
- package/cjs/abstract/Array.js +21 -14
- package/cjs/abstract/Base.js +13 -17
- package/cjs/abstract/Int.js +8 -12
- package/cjs/base/Compact.js +19 -27
- package/cjs/base/DoNotConstruct.js +14 -18
- package/cjs/base/Enum.js +41 -52
- package/cjs/base/Option.js +16 -24
- package/cjs/base/Tuple.js +10 -17
- package/cjs/base/Vec.js +9 -16
- package/cjs/base/VecFixed.js +6 -13
- package/cjs/extended/BTreeSet.js +2 -6
- package/cjs/extended/BitVec.js +10 -14
- package/cjs/extended/Map.js +5 -11
- package/cjs/extended/Range.js +2 -6
- package/cjs/extended/WrapperKeepOpaque.js +16 -22
- package/cjs/native/Float.js +3 -7
- package/cjs/native/Set.js +15 -18
- package/cjs/native/Struct.js +12 -16
- package/cjs/native/Text.js +3 -6
- package/cjs/native/index.js +2 -2
- package/cjs/packageInfo.js +1 -1
- package/cjs/primitive/index.js +17 -17
- package/cjs/utils/index.js +6 -6
- package/cjs/utils/sanitize.js +16 -16
- package/cjs/utils/sortValues.js +2 -6
- package/cjs/utils/toConstructors.js +41 -0
- package/cjs/utils/typesToMap.js +1 -1
- package/extended/BTreeSet.js +2 -6
- package/extended/BitVec.js +10 -14
- package/extended/Map.js +5 -11
- package/extended/Range.js +2 -6
- package/extended/WrapperKeepOpaque.js +16 -22
- package/native/Float.js +3 -7
- package/native/Set.js +15 -18
- package/native/Struct.js +12 -16
- package/native/Text.js +3 -6
- package/native/index.d.ts +1 -1
- package/native/index.js +1 -1
- package/package.json +8 -13
- package/packageInfo.js +1 -1
- package/primitive/index.d.ts +16 -16
- package/primitive/index.js +16 -16
- package/types/registry.d.ts +1 -0
- package/utils/index.d.ts +2 -3
- package/utils/index.js +2 -3
- package/utils/sanitize.js +16 -16
- package/utils/sortValues.js +1 -5
- package/utils/toConstructors.d.ts +16 -0
- package/utils/toConstructors.js +35 -0
- package/utils/typesToMap.js +1 -1
- package/cjs/utils/mapToTypeMap.js +0 -18
- package/cjs/utils/typeToConstructor.js +0 -10
- package/utils/mapToTypeMap.d.ts +0 -5
- package/utils/mapToTypeMap.js +0 -14
- package/utils/typeToConstructor.d.ts +0 -2
- package/utils/typeToConstructor.js +0 -6
package/native/Struct.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
var _Struct_jsonMap, _Struct_Types;
|
|
2
|
-
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
1
|
import { isBoolean, isHex, isObject, isU8a, isUndefined, objectProperties, stringCamelCase, stringify, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util';
|
|
4
2
|
import { compareMap, decodeU8aStruct, mapToTypeMap, typesToMap } from '../utils/index.js';
|
|
5
3
|
function noopSetDefinition(d) {
|
|
@@ -10,14 +8,15 @@ function decodeStructFromObject(registry, [Types, keys], value, jsonMap) {
|
|
|
10
8
|
let jsonObj;
|
|
11
9
|
const typeofArray = Array.isArray(value);
|
|
12
10
|
const typeofMap = value instanceof Map;
|
|
11
|
+
const count = keys.length;
|
|
13
12
|
if (!typeofArray && !typeofMap && !isObject(value)) {
|
|
14
13
|
throw new Error(`Struct: Cannot decode value ${stringify(value)} (typeof ${typeof value}), expected an input object, map or array`);
|
|
15
14
|
}
|
|
16
|
-
else if (typeofArray && value.length !==
|
|
15
|
+
else if (typeofArray && value.length !== count) {
|
|
17
16
|
throw new Error(`Struct: Unable to map ${stringify(value)} array to object with known keys ${keys.join(', ')}`);
|
|
18
17
|
}
|
|
19
|
-
const raw = new Array(
|
|
20
|
-
for (let i = 0; i <
|
|
18
|
+
const raw = new Array(count);
|
|
19
|
+
for (let i = 0; i < count; i++) {
|
|
21
20
|
const key = keys[i];
|
|
22
21
|
const jsonKey = jsonMap.get(key) || key;
|
|
23
22
|
const Type = Types[i];
|
|
@@ -35,7 +34,7 @@ function decodeStructFromObject(registry, [Types, keys], value, jsonMap) {
|
|
|
35
34
|
if (isUndefined(jsonObj)) {
|
|
36
35
|
const entries = Object.entries(value);
|
|
37
36
|
jsonObj = {};
|
|
38
|
-
for (let e = 0
|
|
37
|
+
for (let e = 0, ecount = entries.length; e < ecount; e++) {
|
|
39
38
|
jsonObj[stringCamelCase(entries[e][0])] = entries[e][1];
|
|
40
39
|
}
|
|
41
40
|
}
|
|
@@ -81,12 +80,10 @@ export class Struct extends Map {
|
|
|
81
80
|
? [value, 0]
|
|
82
81
|
: decodeStructFromObject(registry, typeMap, value || {}, jsonMap);
|
|
83
82
|
super(decoded);
|
|
84
|
-
_Struct_jsonMap.set(this, void 0);
|
|
85
|
-
_Struct_Types.set(this, void 0);
|
|
86
83
|
this.initialU8aLength = decodedLength;
|
|
87
84
|
this.registry = registry;
|
|
88
|
-
|
|
89
|
-
|
|
85
|
+
this.__internal__jsonMap = jsonMap;
|
|
86
|
+
this.__internal__Types = typeMap;
|
|
90
87
|
}
|
|
91
88
|
static with(Types, jsonMap) {
|
|
92
89
|
var _a;
|
|
@@ -108,7 +105,7 @@ export class Struct extends Map {
|
|
|
108
105
|
* @description The available keys for this struct
|
|
109
106
|
*/
|
|
110
107
|
get defKeys() {
|
|
111
|
-
return
|
|
108
|
+
return this.__internal__Types[1];
|
|
112
109
|
}
|
|
113
110
|
/**
|
|
114
111
|
* @description Checks if the value is an empty value
|
|
@@ -142,8 +139,8 @@ export class Struct extends Map {
|
|
|
142
139
|
*/
|
|
143
140
|
get Type() {
|
|
144
141
|
const result = {};
|
|
145
|
-
const [Types, keys] =
|
|
146
|
-
for (let i = 0
|
|
142
|
+
const [Types, keys] = this.__internal__Types;
|
|
143
|
+
for (let i = 0, count = keys.length; i < count; i++) {
|
|
147
144
|
result[keys[i]] = new Types[i](this.registry).toRawType();
|
|
148
145
|
}
|
|
149
146
|
return result;
|
|
@@ -220,7 +217,7 @@ export class Struct extends Map {
|
|
|
220
217
|
for (const [k, v] of this.entries()) {
|
|
221
218
|
// Here we pull out the entry against the JSON mapping (if supplied)
|
|
222
219
|
// since this representation goes over RPC and needs to be correct
|
|
223
|
-
json[(
|
|
220
|
+
json[(this.__internal__jsonMap.get(k) || k)] = v.toJSON();
|
|
224
221
|
}
|
|
225
222
|
return json;
|
|
226
223
|
}
|
|
@@ -238,7 +235,7 @@ export class Struct extends Map {
|
|
|
238
235
|
* @description Returns the base runtime type name for this instance
|
|
239
236
|
*/
|
|
240
237
|
toRawType() {
|
|
241
|
-
return stringify(typesToMap(this.registry,
|
|
238
|
+
return stringify(typesToMap(this.registry, this.__internal__Types));
|
|
242
239
|
}
|
|
243
240
|
/**
|
|
244
241
|
* @description Returns the string representation of the value
|
|
@@ -260,4 +257,3 @@ export class Struct extends Map {
|
|
|
260
257
|
return u8aConcatStrict(encoded);
|
|
261
258
|
}
|
|
262
259
|
}
|
|
263
|
-
_Struct_jsonMap = new WeakMap(), _Struct_Types = new WeakMap();
|
package/native/Text.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
var _Text_override;
|
|
2
|
-
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
1
|
import { compactAddLength, compactFromU8aLim, compactToU8a, hexToU8a, isHex, isString, isU8a, stringToU8a, u8aToHex, u8aToString } from '@polkadot/util';
|
|
4
2
|
import { Raw } from './Raw.js';
|
|
5
3
|
const MAX_LENGTH = 128 * 1024;
|
|
@@ -41,7 +39,7 @@ export class Text extends String {
|
|
|
41
39
|
constructor(registry, value) {
|
|
42
40
|
const [str, decodedLength] = decodeText(value);
|
|
43
41
|
super(str);
|
|
44
|
-
|
|
42
|
+
this.__internal__override = null;
|
|
45
43
|
this.registry = registry;
|
|
46
44
|
this.initialU8aLength = decodedLength;
|
|
47
45
|
}
|
|
@@ -93,7 +91,7 @@ export class Text extends String {
|
|
|
93
91
|
* @description Set an override value for this
|
|
94
92
|
*/
|
|
95
93
|
setOverride(override) {
|
|
96
|
-
|
|
94
|
+
this.__internal__override = override;
|
|
97
95
|
}
|
|
98
96
|
/**
|
|
99
97
|
* @description Returns a hex string representation of the value
|
|
@@ -131,7 +129,7 @@ export class Text extends String {
|
|
|
131
129
|
* @description Returns the string representation of the value
|
|
132
130
|
*/
|
|
133
131
|
toString() {
|
|
134
|
-
return
|
|
132
|
+
return this.__internal__override || super.toString();
|
|
135
133
|
}
|
|
136
134
|
/**
|
|
137
135
|
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
@@ -146,4 +144,3 @@ export class Text extends String {
|
|
|
146
144
|
: compactAddLength(encoded);
|
|
147
145
|
}
|
|
148
146
|
}
|
|
149
|
-
_Text_override = new WeakMap();
|
package/native/index.d.ts
CHANGED
package/native/index.js
CHANGED
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"./cjs/detectPackage.js"
|
|
19
19
|
],
|
|
20
20
|
"type": "module",
|
|
21
|
-
"version": "10.
|
|
21
|
+
"version": "10.6.1",
|
|
22
22
|
"main": "./cjs/index.js",
|
|
23
23
|
"module": "./index.js",
|
|
24
24
|
"types": "./index.d.ts",
|
|
@@ -408,11 +408,6 @@
|
|
|
408
408
|
"require": "./cjs/utils/decodeU8a.js",
|
|
409
409
|
"default": "./utils/decodeU8a.js"
|
|
410
410
|
},
|
|
411
|
-
"./utils/mapToTypeMap": {
|
|
412
|
-
"types": "./utils/mapToTypeMap.d.ts",
|
|
413
|
-
"require": "./cjs/utils/mapToTypeMap.js",
|
|
414
|
-
"default": "./utils/mapToTypeMap.js"
|
|
415
|
-
},
|
|
416
411
|
"./utils/sanitize": {
|
|
417
412
|
"types": "./utils/sanitize.d.ts",
|
|
418
413
|
"require": "./cjs/utils/sanitize.js",
|
|
@@ -423,16 +418,16 @@
|
|
|
423
418
|
"require": "./cjs/utils/sortValues.js",
|
|
424
419
|
"default": "./utils/sortValues.js"
|
|
425
420
|
},
|
|
421
|
+
"./utils/toConstructors": {
|
|
422
|
+
"types": "./utils/toConstructors.d.ts",
|
|
423
|
+
"require": "./cjs/utils/toConstructors.js",
|
|
424
|
+
"default": "./utils/toConstructors.js"
|
|
425
|
+
},
|
|
426
426
|
"./utils/typesToMap": {
|
|
427
427
|
"types": "./utils/typesToMap.d.ts",
|
|
428
428
|
"require": "./cjs/utils/typesToMap.js",
|
|
429
429
|
"default": "./utils/typesToMap.js"
|
|
430
430
|
},
|
|
431
|
-
"./utils/typeToConstructor": {
|
|
432
|
-
"types": "./utils/typeToConstructor.d.ts",
|
|
433
|
-
"require": "./cjs/utils/typeToConstructor.js",
|
|
434
|
-
"default": "./utils/typeToConstructor.js"
|
|
435
|
-
},
|
|
436
431
|
"./utils/util": {
|
|
437
432
|
"types": "./utils/util.d.ts",
|
|
438
433
|
"require": "./cjs/utils/util.js",
|
|
@@ -440,8 +435,8 @@
|
|
|
440
435
|
}
|
|
441
436
|
},
|
|
442
437
|
"dependencies": {
|
|
443
|
-
"@polkadot/util": "^12.
|
|
444
|
-
"@polkadot/x-bigint": "^12.
|
|
438
|
+
"@polkadot/util": "^12.1.2",
|
|
439
|
+
"@polkadot/x-bigint": "^12.1.2",
|
|
445
440
|
"tslib": "^2.5.0"
|
|
446
441
|
}
|
|
447
442
|
}
|
package/packageInfo.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const packageInfo = { name: '@polkadot/types-codec', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '10.
|
|
1
|
+
export const packageInfo = { name: '@polkadot/types-codec', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '10.6.1' };
|
package/primitive/index.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export { f32
|
|
2
|
-
export { f64
|
|
3
|
-
export { i8
|
|
4
|
-
export { i16
|
|
5
|
-
export { i32
|
|
6
|
-
export { i64
|
|
7
|
-
export { i128
|
|
8
|
-
export { i256
|
|
9
|
-
export { isize
|
|
10
|
-
export { u8
|
|
11
|
-
export { u16
|
|
12
|
-
export { u32
|
|
13
|
-
export { u64
|
|
14
|
-
export { u128
|
|
15
|
-
export { u256
|
|
16
|
-
export { usize
|
|
1
|
+
export { f32 as F32, f32 } from './F32.js';
|
|
2
|
+
export { f64 as F64, f64 } from './F64.js';
|
|
3
|
+
export { i8 as I8, i8 } from './I8.js';
|
|
4
|
+
export { i16 as I16, i16 } from './I16.js';
|
|
5
|
+
export { i32 as I32, i32 } from './I32.js';
|
|
6
|
+
export { i64 as I64, i64 } from './I64.js';
|
|
7
|
+
export { i128 as I128, i128 } from './I128.js';
|
|
8
|
+
export { i256 as I256, i256 } from './I256.js';
|
|
9
|
+
export { isize as ISize, isize } from './ISize.js';
|
|
10
|
+
export { u8 as U8, u8 } from './U8.js';
|
|
11
|
+
export { u16 as U16, u16 } from './U16.js';
|
|
12
|
+
export { u32 as U32, u32 } from './U32.js';
|
|
13
|
+
export { u64 as U64, u64 } from './U64.js';
|
|
14
|
+
export { u128 as U128, u128 } from './U128.js';
|
|
15
|
+
export { u256 as U256, u256 } from './U256.js';
|
|
16
|
+
export { usize as USize, usize } from './USize.js';
|
package/primitive/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export { f32
|
|
2
|
-
export { f64
|
|
3
|
-
export { i8
|
|
4
|
-
export { i16
|
|
5
|
-
export { i32
|
|
6
|
-
export { i64
|
|
7
|
-
export { i128
|
|
8
|
-
export { i256
|
|
9
|
-
export { isize
|
|
10
|
-
export { u8
|
|
11
|
-
export { u16
|
|
12
|
-
export { u32
|
|
13
|
-
export { u64
|
|
14
|
-
export { u128
|
|
15
|
-
export { u256
|
|
16
|
-
export { usize
|
|
1
|
+
export { f32 as F32, f32 } from './F32.js';
|
|
2
|
+
export { f64 as F64, f64 } from './F64.js';
|
|
3
|
+
export { i8 as I8, i8 } from './I8.js';
|
|
4
|
+
export { i16 as I16, i16 } from './I16.js';
|
|
5
|
+
export { i32 as I32, i32 } from './I32.js';
|
|
6
|
+
export { i64 as I64, i64 } from './I64.js';
|
|
7
|
+
export { i128 as I128, i128 } from './I128.js';
|
|
8
|
+
export { i256 as I256, i256 } from './I256.js';
|
|
9
|
+
export { isize as ISize, isize } from './ISize.js';
|
|
10
|
+
export { u8 as U8, u8 } from './U8.js';
|
|
11
|
+
export { u16 as U16, u16 } from './U16.js';
|
|
12
|
+
export { u32 as U32, u32 } from './U32.js';
|
|
13
|
+
export { u64 as U64, u64 } from './U64.js';
|
|
14
|
+
export { u128 as U128, u128 } from './U128.js';
|
|
15
|
+
export { u256 as U256, u256 } from './U256.js';
|
|
16
|
+
export { usize as USize, usize } from './USize.js';
|
package/types/registry.d.ts
CHANGED
|
@@ -49,6 +49,7 @@ export interface Registry {
|
|
|
49
49
|
createLookupType(lookupId: ICompact<INumber> | number): LookupString;
|
|
50
50
|
createClassUnsafe<T extends Codec = Codec, K extends string = string>(type: K): CodecClass<T>;
|
|
51
51
|
createTypeUnsafe<T extends Codec = Codec, K extends string = string>(type: K, params: unknown[], options?: CodecCreateOptions): T;
|
|
52
|
+
get(...params: never[]): any;
|
|
52
53
|
getClassName(clazz: CodecClass): string | undefined;
|
|
53
54
|
getOrThrow<T extends Codec = Codec, K extends string = string>(name: K, msg?: string): CodecClass<T>;
|
|
54
55
|
getOrUnknown<T extends Codec = Codec, K extends string = string>(name: K): CodecClass<T>;
|
package/utils/index.d.ts
CHANGED
|
@@ -2,8 +2,7 @@ export { compareArray } from './compareArray.js';
|
|
|
2
2
|
export { compareMap } from './compareMap.js';
|
|
3
3
|
export { compareSet } from './compareSet.js';
|
|
4
4
|
export { decodeU8a, decodeU8aStruct, decodeU8aVec } from './decodeU8a.js';
|
|
5
|
-
export { mapToTypeMap } from './mapToTypeMap.js';
|
|
6
|
-
export { typeToConstructor } from './typeToConstructor.js';
|
|
7
5
|
export { sanitize } from './sanitize.js';
|
|
8
|
-
export { sortAsc,
|
|
6
|
+
export { sortAsc, sortMap, sortSet } from './sortValues.js';
|
|
7
|
+
export { mapToTypeMap, typesToConstructors, typeToConstructor } from './toConstructors.js';
|
|
9
8
|
export { typesToMap } from './typesToMap.js';
|
package/utils/index.js
CHANGED
|
@@ -2,8 +2,7 @@ export { compareArray } from './compareArray.js';
|
|
|
2
2
|
export { compareMap } from './compareMap.js';
|
|
3
3
|
export { compareSet } from './compareSet.js';
|
|
4
4
|
export { decodeU8a, decodeU8aStruct, decodeU8aVec } from './decodeU8a.js';
|
|
5
|
-
export { mapToTypeMap } from './mapToTypeMap.js';
|
|
6
|
-
export { typeToConstructor } from './typeToConstructor.js';
|
|
7
5
|
export { sanitize } from './sanitize.js';
|
|
8
|
-
export { sortAsc,
|
|
6
|
+
export { sortAsc, sortMap, sortSet } from './sortValues.js';
|
|
7
|
+
export { mapToTypeMap, typesToConstructors, typeToConstructor } from './toConstructors.js';
|
|
9
8
|
export { typesToMap } from './typesToMap.js';
|
package/utils/sanitize.js
CHANGED
|
@@ -44,14 +44,14 @@ export function trim() {
|
|
|
44
44
|
}
|
|
45
45
|
export function findClosing(value, start) {
|
|
46
46
|
let depth = 0;
|
|
47
|
-
for (let
|
|
48
|
-
if (value[
|
|
47
|
+
for (let i = start, count = value.length; i < count; i++) {
|
|
48
|
+
if (value[i] === '>') {
|
|
49
49
|
if (!depth) {
|
|
50
|
-
return
|
|
50
|
+
return i;
|
|
51
51
|
}
|
|
52
52
|
depth--;
|
|
53
53
|
}
|
|
54
|
-
else if (value[
|
|
54
|
+
else if (value[i] === '<') {
|
|
55
55
|
depth++;
|
|
56
56
|
}
|
|
57
57
|
}
|
|
@@ -70,11 +70,11 @@ export function alias(src, dest, withChecks = true) {
|
|
|
70
70
|
export function cleanupCompact() {
|
|
71
71
|
return (value) => {
|
|
72
72
|
if (value.includes(' as HasCompact')) {
|
|
73
|
-
for (let
|
|
74
|
-
if (value[
|
|
75
|
-
const end = findClosing(value,
|
|
73
|
+
for (let i = 0, count = value.length; i < count; i++) {
|
|
74
|
+
if (value[i] === '<') {
|
|
75
|
+
const end = findClosing(value, i + 1) - 14;
|
|
76
76
|
if (value.substring(end, end + 14) === ' as HasCompact') {
|
|
77
|
-
value = `Compact<${value.substring(
|
|
77
|
+
value = `Compact<${value.substring(i + 1, end)}>`;
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
}
|
|
@@ -108,7 +108,7 @@ function replaceTagWith(value, matcher, replacer) {
|
|
|
108
108
|
}
|
|
109
109
|
export function removeExtensions(type, isSized) {
|
|
110
110
|
return (value) => {
|
|
111
|
-
for (let i = 0
|
|
111
|
+
for (let i = 0, count = BOUNDED.length; i < count; i++) {
|
|
112
112
|
const tag = BOUNDED[i];
|
|
113
113
|
value = replaceTagWith(value, `${type}${tag}<`, (v) => {
|
|
114
114
|
const parts = v
|
|
@@ -145,21 +145,21 @@ export function removeColons() {
|
|
|
145
145
|
}
|
|
146
146
|
export function removeGenerics() {
|
|
147
147
|
return (value) => {
|
|
148
|
-
for (let
|
|
149
|
-
if (value[
|
|
148
|
+
for (let i = 0, count = value.length; i < count; i++) {
|
|
149
|
+
if (value[i] === '<') {
|
|
150
150
|
// check against the allowed wrappers, be it Vec<..>, Option<...> ...
|
|
151
151
|
const box = ALLOWED_BOXES.find((box) => {
|
|
152
|
-
const start =
|
|
152
|
+
const start = i - box.length;
|
|
153
153
|
return ((start >= 0 &&
|
|
154
|
-
value.substring(start,
|
|
154
|
+
value.substring(start, i) === box) && (
|
|
155
155
|
// make sure it is stand-alone, i.e. don't catch ElectionResult<...> as Result<...>
|
|
156
156
|
start === 0 ||
|
|
157
157
|
BOX_PRECEDING.includes(value[start - 1])));
|
|
158
158
|
});
|
|
159
159
|
// we have not found anything, unwrap generic innards
|
|
160
160
|
if (!box) {
|
|
161
|
-
const end = findClosing(value,
|
|
162
|
-
value = `${value.substring(0,
|
|
161
|
+
const end = findClosing(value, i + 1);
|
|
162
|
+
value = `${value.substring(0, i)}${value.substring(end + 1)}`;
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
165
|
}
|
|
@@ -211,7 +211,7 @@ export function sanitize(value) {
|
|
|
211
211
|
return memoized;
|
|
212
212
|
}
|
|
213
213
|
let result = startValue;
|
|
214
|
-
for (let i = 0
|
|
214
|
+
for (let i = 0, count = mappings.length; i < count; i++) {
|
|
215
215
|
result = mappings[i](result);
|
|
216
216
|
}
|
|
217
217
|
sanitizeMap.set(startValue, result);
|
package/utils/sortValues.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import { bnToBn, isBigInt, isBn,
|
|
1
|
+
import { bnToBn, isBigInt, isBn, isCodec, isNumber, stringify } from '@polkadot/util';
|
|
2
2
|
/** @internal **/
|
|
3
3
|
function isArrayLike(arg) {
|
|
4
4
|
return arg instanceof Uint8Array || Array.isArray(arg);
|
|
5
5
|
}
|
|
6
6
|
/** @internal **/
|
|
7
|
-
function isCodec(arg) {
|
|
8
|
-
return isFunction(arg && arg.toU8a);
|
|
9
|
-
}
|
|
10
|
-
/** @internal **/
|
|
11
7
|
function isEnum(arg) {
|
|
12
8
|
return isCodec(arg) && isNumber(arg.index) && isCodec(arg.value);
|
|
13
9
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Codec, CodecClass, Registry } from '../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
* From a type string or class, return the associated type class
|
|
5
|
+
*/
|
|
6
|
+
export declare function typeToConstructor<T extends Codec = Codec>(registry: Registry, type: string | CodecClass<T>): CodecClass<T>;
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
* Takes an input array of types and returns the associated classes for it
|
|
10
|
+
*/
|
|
11
|
+
export declare function typesToConstructors<T extends Codec = Codec>(registry: Registry, types: (string | CodecClass<T>)[]): CodecClass<T>[];
|
|
12
|
+
/**
|
|
13
|
+
* @internal
|
|
14
|
+
* Takes an input map of the form `{ [string]: string | CodecClass }` and returns a map of `{ [string]: CodecClass }`
|
|
15
|
+
*/
|
|
16
|
+
export declare function mapToTypeMap(registry: Registry, input: Record<string, string | CodecClass>): [CodecClass[], string[]];
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal
|
|
3
|
+
* From a type string or class, return the associated type class
|
|
4
|
+
*/
|
|
5
|
+
export function typeToConstructor(registry, type) {
|
|
6
|
+
return typeof type === 'function'
|
|
7
|
+
? type
|
|
8
|
+
: registry.createClassUnsafe(type);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* @internal
|
|
12
|
+
* Takes an input array of types and returns the associated classes for it
|
|
13
|
+
*/
|
|
14
|
+
export function typesToConstructors(registry, types) {
|
|
15
|
+
const count = types.length;
|
|
16
|
+
const result = new Array(count);
|
|
17
|
+
for (let i = 0; i < count; i++) {
|
|
18
|
+
result[i] = typeToConstructor(registry, types[i]);
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @internal
|
|
24
|
+
* Takes an input map of the form `{ [string]: string | CodecClass }` and returns a map of `{ [string]: CodecClass }`
|
|
25
|
+
*/
|
|
26
|
+
export function mapToTypeMap(registry, input) {
|
|
27
|
+
const entries = Object.entries(input);
|
|
28
|
+
const count = entries.length;
|
|
29
|
+
const output = [new Array(count), new Array(count)];
|
|
30
|
+
for (let i = 0; i < count; i++) {
|
|
31
|
+
output[1][i] = entries[i][0];
|
|
32
|
+
output[0][i] = typeToConstructor(registry, entries[i][1]);
|
|
33
|
+
}
|
|
34
|
+
return output;
|
|
35
|
+
}
|
package/utils/typesToMap.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export function typesToMap(registry, [Types, keys]) {
|
|
2
2
|
const result = {};
|
|
3
|
-
for (let i = 0
|
|
3
|
+
for (let i = 0, count = keys.length; i < count; i++) {
|
|
4
4
|
result[keys[i]] = registry.getClassName(Types[i]) || new Types[i](registry).toRawType();
|
|
5
5
|
}
|
|
6
6
|
return result;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mapToTypeMap = void 0;
|
|
4
|
-
const typeToConstructor_js_1 = require("./typeToConstructor.js");
|
|
5
|
-
/**
|
|
6
|
-
* @description takes an input map of the form `{ [string]: string | CodecClass }` and returns a map of `{ [string]: CodecClass }`
|
|
7
|
-
*/
|
|
8
|
-
function mapToTypeMap(registry, input) {
|
|
9
|
-
const entries = Object.entries(input);
|
|
10
|
-
const count = entries.length;
|
|
11
|
-
const output = [new Array(count), new Array(count)];
|
|
12
|
-
for (let i = 0; i < count; i++) {
|
|
13
|
-
output[1][i] = entries[i][0];
|
|
14
|
-
output[0][i] = (0, typeToConstructor_js_1.typeToConstructor)(registry, entries[i][1]);
|
|
15
|
-
}
|
|
16
|
-
return output;
|
|
17
|
-
}
|
|
18
|
-
exports.mapToTypeMap = mapToTypeMap;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.typeToConstructor = void 0;
|
|
4
|
-
const util_1 = require("@polkadot/util");
|
|
5
|
-
function typeToConstructor(registry, type) {
|
|
6
|
-
return ((0, util_1.isString)(type)
|
|
7
|
-
? registry.createClassUnsafe(type)
|
|
8
|
-
: type);
|
|
9
|
-
}
|
|
10
|
-
exports.typeToConstructor = typeToConstructor;
|
package/utils/mapToTypeMap.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { CodecClass, Registry } from '../types/index.js';
|
|
2
|
-
/**
|
|
3
|
-
* @description takes an input map of the form `{ [string]: string | CodecClass }` and returns a map of `{ [string]: CodecClass }`
|
|
4
|
-
*/
|
|
5
|
-
export declare function mapToTypeMap(registry: Registry, input: Record<string, string | CodecClass>): [CodecClass[], string[]];
|
package/utils/mapToTypeMap.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { typeToConstructor } from './typeToConstructor.js';
|
|
2
|
-
/**
|
|
3
|
-
* @description takes an input map of the form `{ [string]: string | CodecClass }` and returns a map of `{ [string]: CodecClass }`
|
|
4
|
-
*/
|
|
5
|
-
export function mapToTypeMap(registry, input) {
|
|
6
|
-
const entries = Object.entries(input);
|
|
7
|
-
const count = entries.length;
|
|
8
|
-
const output = [new Array(count), new Array(count)];
|
|
9
|
-
for (let i = 0; i < count; i++) {
|
|
10
|
-
output[1][i] = entries[i][0];
|
|
11
|
-
output[0][i] = typeToConstructor(registry, entries[i][1]);
|
|
12
|
-
}
|
|
13
|
-
return output;
|
|
14
|
-
}
|