@polkadot/types-codec 6.12.2-2
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.cjs +208 -0
- package/abstract/AbstractArray.d.ts +84 -0
- package/abstract/AbstractArray.js +197 -0
- package/abstract/AbstractInt.cjs +254 -0
- package/abstract/AbstractInt.d.ts +75 -0
- package/abstract/AbstractInt.js +231 -0
- package/abstract/index.cjs +21 -0
- package/abstract/index.d.ts +2 -0
- package/abstract/index.js +4 -0
- package/base/Base.cjs +109 -0
- package/base/Base.d.ts +54 -0
- package/base/Base.js +100 -0
- package/base/Compact.cjs +201 -0
- package/base/Compact.d.ts +83 -0
- package/base/Compact.js +186 -0
- package/base/DoNotConstruct.cjs +101 -0
- package/base/DoNotConstruct.d.ts +33 -0
- package/base/DoNotConstruct.js +88 -0
- package/base/Enum.cjs +437 -0
- package/base/Enum.d.ts +101 -0
- package/base/Enum.js +413 -0
- package/base/Int.cjs +45 -0
- package/base/Int.d.ts +16 -0
- package/base/Int.js +33 -0
- package/base/Null.cjs +111 -0
- package/base/Null.d.ts +54 -0
- package/base/Null.js +101 -0
- package/base/Option.cjs +256 -0
- package/base/Option.d.ts +88 -0
- package/base/Option.js +240 -0
- package/base/Result.cjs +109 -0
- package/base/Result.d.ts +46 -0
- package/base/Result.js +98 -0
- package/base/Tuple.cjs +132 -0
- package/base/Tuple.d.ts +39 -0
- package/base/Tuple.js +116 -0
- package/base/UInt.cjs +39 -0
- package/base/UInt.d.ts +15 -0
- package/base/UInt.js +29 -0
- package/base/Vec.cjs +126 -0
- package/base/Vec.d.ts +28 -0
- package/base/Vec.js +104 -0
- package/base/VecAny.cjs +31 -0
- package/base/VecAny.d.ts +15 -0
- package/base/VecAny.js +21 -0
- package/base/VecFixed.cjs +111 -0
- package/base/VecFixed.d.ts +26 -0
- package/base/VecFixed.js +93 -0
- package/base/index.cjs +109 -0
- package/base/index.d.ts +13 -0
- package/base/index.js +15 -0
- package/bundle.cjs +100 -0
- package/bundle.d.ts +7 -0
- package/bundle.js +9 -0
- package/detectPackage.cjs +9 -0
- package/detectPackage.d.ts +1 -0
- package/detectPackage.js +5 -0
- package/extended/BTreeMap.cjs +24 -0
- package/extended/BTreeMap.d.ts +5 -0
- package/extended/BTreeMap.js +14 -0
- package/extended/BTreeSet.cjs +227 -0
- package/extended/BTreeSet.d.ts +55 -0
- package/extended/BTreeSet.js +212 -0
- package/extended/BitVec.cjs +97 -0
- package/extended/BitVec.d.ts +26 -0
- package/extended/BitVec.js +82 -0
- package/extended/Bytes.cjs +86 -0
- package/extended/Bytes.d.ts +25 -0
- package/extended/Bytes.js +75 -0
- package/extended/HashMap.cjs +24 -0
- package/extended/HashMap.d.ts +5 -0
- package/extended/HashMap.js +14 -0
- package/extended/Linkage.cjs +89 -0
- package/extended/Linkage.d.ts +31 -0
- package/extended/Linkage.js +71 -0
- package/extended/Map.cjs +244 -0
- package/extended/Map.d.ts +50 -0
- package/extended/Map.js +225 -0
- package/extended/Range.cjs +92 -0
- package/extended/Range.d.ts +30 -0
- package/extended/Range.js +75 -0
- package/extended/Type.cjs +39 -0
- package/extended/Type.d.ts +16 -0
- package/extended/Type.js +27 -0
- package/extended/U8aFixed.cjs +66 -0
- package/extended/U8aFixed.d.ts +16 -0
- package/extended/U8aFixed.js +53 -0
- package/extended/WrapperOpaque.cjs +68 -0
- package/extended/WrapperOpaque.d.ts +18 -0
- package/extended/WrapperOpaque.js +57 -0
- package/extended/index.cjs +105 -0
- package/extended/index.d.ts +11 -0
- package/extended/index.js +13 -0
- package/index.cjs +20 -0
- package/index.d.ts +2 -0
- package/index.js +4 -0
- package/native/Bool.cjs +141 -0
- package/native/Bool.d.ts +62 -0
- package/native/Bool.js +130 -0
- package/native/Date.cjs +170 -0
- package/native/Date.d.ts +76 -0
- package/native/Date.js +158 -0
- package/native/Json.cjs +133 -0
- package/native/Json.d.ts +55 -0
- package/native/Json.js +117 -0
- package/native/Raw.cjs +192 -0
- package/native/Raw.d.ts +90 -0
- package/native/Raw.js +182 -0
- package/native/Set.cjs +268 -0
- package/native/Set.d.ts +76 -0
- package/native/Set.js +251 -0
- package/native/Struct.cjs +289 -0
- package/native/Struct.d.ts +92 -0
- package/native/Struct.js +273 -0
- package/native/Text.cjs +193 -0
- package/native/Text.d.ts +71 -0
- package/native/Text.js +178 -0
- package/native/index.cjs +79 -0
- package/native/index.d.ts +7 -0
- package/native/index.js +9 -0
- package/package.json +387 -0
- package/packageInfo.cjs +14 -0
- package/packageInfo.d.ts +4 -0
- package/packageInfo.js +7 -0
- package/primitive/I128.cjs +26 -0
- package/primitive/I128.d.ts +11 -0
- package/primitive/I128.js +16 -0
- package/primitive/I16.cjs +26 -0
- package/primitive/I16.d.ts +11 -0
- package/primitive/I16.js +16 -0
- package/primitive/I256.cjs +26 -0
- package/primitive/I256.d.ts +11 -0
- package/primitive/I256.js +16 -0
- package/primitive/I32.cjs +26 -0
- package/primitive/I32.d.ts +11 -0
- package/primitive/I32.js +16 -0
- package/primitive/I64.cjs +26 -0
- package/primitive/I64.d.ts +11 -0
- package/primitive/I64.js +16 -0
- package/primitive/I8.cjs +26 -0
- package/primitive/I8.d.ts +11 -0
- package/primitive/I8.js +16 -0
- package/primitive/U128.cjs +26 -0
- package/primitive/U128.d.ts +11 -0
- package/primitive/U128.js +16 -0
- package/primitive/U16.cjs +26 -0
- package/primitive/U16.d.ts +11 -0
- package/primitive/U16.js +16 -0
- package/primitive/U256.cjs +26 -0
- package/primitive/U256.d.ts +11 -0
- package/primitive/U256.js +16 -0
- package/primitive/U32.cjs +26 -0
- package/primitive/U32.d.ts +11 -0
- package/primitive/U32.js +16 -0
- package/primitive/U64.cjs +26 -0
- package/primitive/U64.d.ts +11 -0
- package/primitive/U64.js +16 -0
- package/primitive/U8.cjs +26 -0
- package/primitive/U8.d.ts +11 -0
- package/primitive/U8.js +16 -0
- package/primitive/USize.cjs +28 -0
- package/primitive/USize.d.ts +12 -0
- package/primitive/USize.js +18 -0
- package/primitive/index.cjs +187 -0
- package/primitive/index.d.ts +13 -0
- package/primitive/index.js +15 -0
- package/types/codec.cjs +1 -0
- package/types/codec.d.ts +77 -0
- package/types/codec.js +1 -0
- package/types/helpers.cjs +1 -0
- package/types/helpers.d.ts +14 -0
- package/types/helpers.js +1 -0
- package/types/index.cjs +57 -0
- package/types/index.d.ts +4 -0
- package/types/index.js +6 -0
- package/types/interfaces.cjs +1 -0
- package/types/interfaces.d.ts +68 -0
- package/types/interfaces.js +1 -0
- package/types/registry.cjs +1 -0
- package/types/registry.d.ts +44 -0
- package/types/registry.js +1 -0
- package/utils/compareArray.cjs +22 -0
- package/utils/compareArray.d.ts +1 -0
- package/utils/compareArray.js +13 -0
- package/utils/compareMap.cjs +39 -0
- package/utils/compareMap.d.ts +1 -0
- package/utils/compareMap.js +31 -0
- package/utils/compareSet.cjs +29 -0
- package/utils/compareSet.d.ts +1 -0
- package/utils/compareSet.js +22 -0
- package/utils/decodeU8a.cjs +69 -0
- package/utils/decodeU8a.d.ts +13 -0
- package/utils/decodeU8a.js +60 -0
- package/utils/index.cjs +95 -0
- package/utils/index.d.ts +9 -0
- package/utils/index.js +11 -0
- package/utils/mapToTypeMap.cjs +25 -0
- package/utils/mapToTypeMap.d.ts +5 -0
- package/utils/mapToTypeMap.js +17 -0
- package/utils/sanitize.cjs +242 -0
- package/utils/sanitize.d.ts +16 -0
- package/utils/sanitize.js +215 -0
- package/utils/sortValues.cjs +89 -0
- package/utils/sortValues.d.ts +13 -0
- package/utils/sortValues.js +73 -0
- package/utils/typeToConstructor.cjs +14 -0
- package/utils/typeToConstructor.d.ts +2 -0
- package/utils/typeToConstructor.js +6 -0
- package/utils/typesToMap.cjs +20 -0
- package/utils/typesToMap.d.ts +2 -0
- package/utils/typesToMap.js +13 -0
- package/utils/util.cjs +15 -0
- package/utils/util.d.ts +3 -0
- package/utils/util.js +7 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { CodecMap } from "./Map.js";
|
|
4
|
+
export class HashMap extends CodecMap {
|
|
5
|
+
static with(keyType, valType) {
|
|
6
|
+
return class extends HashMap {
|
|
7
|
+
constructor(registry, value) {
|
|
8
|
+
super(registry, keyType, valType, value);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.LinkageResult = exports.Linkage = void 0;
|
|
7
|
+
|
|
8
|
+
var _Option = require("../base/Option.cjs");
|
|
9
|
+
|
|
10
|
+
var _Tuple = require("../base/Tuple.cjs");
|
|
11
|
+
|
|
12
|
+
var _Vec = require("../base/Vec.cjs");
|
|
13
|
+
|
|
14
|
+
var _Struct = require("../native/Struct.cjs");
|
|
15
|
+
|
|
16
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
17
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
18
|
+
const EMPTY = new Uint8Array();
|
|
19
|
+
/**
|
|
20
|
+
* @name Linkage
|
|
21
|
+
* @description The wrapper for the result from a LinkedMap
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
class Linkage extends _Struct.Struct {
|
|
25
|
+
constructor(registry, Type, value) {
|
|
26
|
+
super(registry, {
|
|
27
|
+
previous: _Option.Option.with(Type),
|
|
28
|
+
// eslint-disable-next-line sort-keys
|
|
29
|
+
next: _Option.Option.with(Type)
|
|
30
|
+
}, value);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static withKey(Type) {
|
|
34
|
+
return class extends Linkage {
|
|
35
|
+
constructor(registry, value) {
|
|
36
|
+
super(registry, Type, value);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get previous() {
|
|
43
|
+
return this.get('previous');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
get next() {
|
|
47
|
+
return this.get('next');
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* @description Returns the base runtime type name for this instance
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
toRawType() {
|
|
55
|
+
return `Linkage<${this.next.toRawType(true)}>`;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* @description Custom toU8a which with bare mode does not return the linkage if empty
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
toU8a() {
|
|
63
|
+
// As part of a storage query (where these appear), in the case of empty, the values
|
|
64
|
+
// are NOT populated by the node - follow the same logic, leaving it empty
|
|
65
|
+
return this.isEmpty ? EMPTY : super.toU8a();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* @name LinkageResult
|
|
71
|
+
* @description A Linkage keys/Values tuple
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
exports.Linkage = Linkage;
|
|
76
|
+
|
|
77
|
+
class LinkageResult extends _Tuple.Tuple {
|
|
78
|
+
constructor(registry, _ref, _ref2) {
|
|
79
|
+
let [TypeKey, keys] = _ref;
|
|
80
|
+
let [TypeValue, values] = _ref2;
|
|
81
|
+
super(registry, {
|
|
82
|
+
Keys: _Vec.Vec.with(TypeKey),
|
|
83
|
+
Values: _Vec.Vec.with(TypeValue)
|
|
84
|
+
}, [keys, values]);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
exports.LinkageResult = LinkageResult;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Codec, CodecClass, CodecRegistry } from '../types';
|
|
2
|
+
import { Option } from '../base/Option';
|
|
3
|
+
import { Tuple } from '../base/Tuple';
|
|
4
|
+
import { Struct } from '../native/Struct';
|
|
5
|
+
declare type TypeWithValues = [CodecClass, any[]];
|
|
6
|
+
/**
|
|
7
|
+
* @name Linkage
|
|
8
|
+
* @description The wrapper for the result from a LinkedMap
|
|
9
|
+
*/
|
|
10
|
+
export declare class Linkage<T extends Codec> extends Struct {
|
|
11
|
+
constructor(registry: CodecRegistry, Type: CodecClass | string, value?: unknown);
|
|
12
|
+
static withKey<O extends Codec>(Type: CodecClass | string): CodecClass<Linkage<O>>;
|
|
13
|
+
get previous(): Option<T>;
|
|
14
|
+
get next(): Option<T>;
|
|
15
|
+
/**
|
|
16
|
+
* @description Returns the base runtime type name for this instance
|
|
17
|
+
*/
|
|
18
|
+
toRawType(): string;
|
|
19
|
+
/**
|
|
20
|
+
* @description Custom toU8a which with bare mode does not return the linkage if empty
|
|
21
|
+
*/
|
|
22
|
+
toU8a(): Uint8Array;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @name LinkageResult
|
|
26
|
+
* @description A Linkage keys/Values tuple
|
|
27
|
+
*/
|
|
28
|
+
export declare class LinkageResult extends Tuple {
|
|
29
|
+
constructor(registry: CodecRegistry, [TypeKey, keys]: TypeWithValues, [TypeValue, values]: TypeWithValues);
|
|
30
|
+
}
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { Option } from "../base/Option.js";
|
|
4
|
+
import { Tuple } from "../base/Tuple.js";
|
|
5
|
+
import { Vec } from "../base/Vec.js";
|
|
6
|
+
import { Struct } from "../native/Struct.js";
|
|
7
|
+
const EMPTY = new Uint8Array();
|
|
8
|
+
/**
|
|
9
|
+
* @name Linkage
|
|
10
|
+
* @description The wrapper for the result from a LinkedMap
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export class Linkage extends Struct {
|
|
14
|
+
constructor(registry, Type, value) {
|
|
15
|
+
super(registry, {
|
|
16
|
+
previous: Option.with(Type),
|
|
17
|
+
// eslint-disable-next-line sort-keys
|
|
18
|
+
next: Option.with(Type)
|
|
19
|
+
}, value);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static withKey(Type) {
|
|
23
|
+
return class extends Linkage {
|
|
24
|
+
constructor(registry, value) {
|
|
25
|
+
super(registry, Type, value);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
get previous() {
|
|
32
|
+
return this.get('previous');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
get next() {
|
|
36
|
+
return this.get('next');
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @description Returns the base runtime type name for this instance
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
toRawType() {
|
|
44
|
+
return `Linkage<${this.next.toRawType(true)}>`;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* @description Custom toU8a which with bare mode does not return the linkage if empty
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
toU8a() {
|
|
52
|
+
// As part of a storage query (where these appear), in the case of empty, the values
|
|
53
|
+
// are NOT populated by the node - follow the same logic, leaving it empty
|
|
54
|
+
return this.isEmpty ? EMPTY : super.toU8a();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* @name LinkageResult
|
|
60
|
+
* @description A Linkage keys/Values tuple
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
export class LinkageResult extends Tuple {
|
|
64
|
+
constructor(registry, [TypeKey, keys], [TypeValue, values]) {
|
|
65
|
+
super(registry, {
|
|
66
|
+
Keys: Vec.with(TypeKey),
|
|
67
|
+
Values: Vec.with(TypeValue)
|
|
68
|
+
}, [keys, values]);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
}
|
package/extended/Map.cjs
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.CodecMap = void 0;
|
|
9
|
+
|
|
10
|
+
var _classPrivateFieldLooseBase2 = _interopRequireDefault(require("@babel/runtime/helpers/classPrivateFieldLooseBase"));
|
|
11
|
+
|
|
12
|
+
var _classPrivateFieldLooseKey2 = _interopRequireDefault(require("@babel/runtime/helpers/classPrivateFieldLooseKey"));
|
|
13
|
+
|
|
14
|
+
var _util = require("@polkadot/util");
|
|
15
|
+
|
|
16
|
+
var _AbstractArray = require("../abstract/AbstractArray.cjs");
|
|
17
|
+
|
|
18
|
+
var _Enum = require("../base/Enum.cjs");
|
|
19
|
+
|
|
20
|
+
var _Struct = require("../native/Struct.cjs");
|
|
21
|
+
|
|
22
|
+
var _index = require("../utils/index.cjs");
|
|
23
|
+
|
|
24
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
25
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
26
|
+
const l = (0, _util.logger)('Map');
|
|
27
|
+
/** @internal */
|
|
28
|
+
|
|
29
|
+
function decodeMapFromU8a(registry, KeyClass, ValClass, u8a) {
|
|
30
|
+
const output = new Map();
|
|
31
|
+
const [offset, length] = (0, _util.compactFromU8a)(u8a);
|
|
32
|
+
const count = length.toNumber();
|
|
33
|
+
const types = [];
|
|
34
|
+
|
|
35
|
+
for (let i = 0; i < count; i++) {
|
|
36
|
+
types.push(KeyClass, ValClass);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const [values, decodedLength] = (0, _index.decodeU8a)(registry, u8a.subarray(offset), types);
|
|
40
|
+
|
|
41
|
+
for (let i = 0; i < values.length; i += 2) {
|
|
42
|
+
output.set(values[i], values[i + 1]);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return [output, offset + decodedLength];
|
|
46
|
+
}
|
|
47
|
+
/** @internal */
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
function decodeMapFromMap(registry, KeyClass, ValClass, value) {
|
|
51
|
+
const output = new Map();
|
|
52
|
+
|
|
53
|
+
for (const [key, val] of value.entries()) {
|
|
54
|
+
const isComplex = KeyClass.prototype instanceof _AbstractArray.AbstractArray || KeyClass.prototype instanceof _Struct.Struct || KeyClass.prototype instanceof _Enum.Enum;
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
output.set(key instanceof KeyClass ? key : new KeyClass(registry, isComplex ? JSON.parse(key) : key), val instanceof ValClass ? val : new ValClass(registry, val));
|
|
58
|
+
} catch (error) {
|
|
59
|
+
l.error('Failed to decode key or value:', error.message);
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return [output, 0];
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Decode input to pass into constructor.
|
|
68
|
+
*
|
|
69
|
+
* @param KeyClass - Type of the map key
|
|
70
|
+
* @param ValClass - Type of the map value
|
|
71
|
+
* @param value - Value to decode, one of:
|
|
72
|
+
* - null
|
|
73
|
+
* - undefined
|
|
74
|
+
* - hex
|
|
75
|
+
* - Uint8Array
|
|
76
|
+
* - Map<any, any>, where both key and value types are either
|
|
77
|
+
* constructors or decodeable values for their types.
|
|
78
|
+
* @param jsonMap
|
|
79
|
+
* @internal
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
function decodeMap(registry, keyType, valType, value) {
|
|
84
|
+
const KeyClass = (0, _index.typeToConstructor)(registry, keyType);
|
|
85
|
+
const ValClass = (0, _index.typeToConstructor)(registry, valType);
|
|
86
|
+
|
|
87
|
+
if (!value) {
|
|
88
|
+
return [new Map(), 0];
|
|
89
|
+
} else if ((0, _util.isU8a)(value) || (0, _util.isHex)(value)) {
|
|
90
|
+
return decodeMapFromU8a(registry, KeyClass, ValClass, (0, _util.u8aToU8a)(value));
|
|
91
|
+
} else if (value instanceof Map) {
|
|
92
|
+
return decodeMapFromMap(registry, KeyClass, ValClass, value);
|
|
93
|
+
} else if ((0, _util.isObject)(value)) {
|
|
94
|
+
return decodeMapFromMap(registry, KeyClass, ValClass, new Map(Object.entries(value)));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
throw new Error('Map: cannot decode type');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
var _KeyClass = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("KeyClass");
|
|
101
|
+
|
|
102
|
+
var _ValClass = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("ValClass");
|
|
103
|
+
|
|
104
|
+
var _type = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("type");
|
|
105
|
+
|
|
106
|
+
class CodecMap extends Map {
|
|
107
|
+
constructor(registry, keyType, valType, rawValue) {
|
|
108
|
+
let type = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 'HashMap';
|
|
109
|
+
const [decoded, decodedLength] = decodeMap(registry, keyType, valType, rawValue);
|
|
110
|
+
super(type === 'BTreeMap' ? (0, _index.sortMap)(decoded) : decoded);
|
|
111
|
+
this.registry = void 0;
|
|
112
|
+
this.createdAtHash = void 0;
|
|
113
|
+
Object.defineProperty(this, _KeyClass, {
|
|
114
|
+
writable: true,
|
|
115
|
+
value: void 0
|
|
116
|
+
});
|
|
117
|
+
Object.defineProperty(this, _ValClass, {
|
|
118
|
+
writable: true,
|
|
119
|
+
value: void 0
|
|
120
|
+
});
|
|
121
|
+
this.initialU8aLength = void 0;
|
|
122
|
+
Object.defineProperty(this, _type, {
|
|
123
|
+
writable: true,
|
|
124
|
+
value: void 0
|
|
125
|
+
});
|
|
126
|
+
this.registry = registry;
|
|
127
|
+
this.initialU8aLength = decodedLength;
|
|
128
|
+
(0, _classPrivateFieldLooseBase2.default)(this, _KeyClass)[_KeyClass] = (0, _index.typeToConstructor)(registry, keyType);
|
|
129
|
+
(0, _classPrivateFieldLooseBase2.default)(this, _ValClass)[_ValClass] = (0, _index.typeToConstructor)(registry, valType);
|
|
130
|
+
(0, _classPrivateFieldLooseBase2.default)(this, _type)[_type] = type;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
134
|
+
*/
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
get encodedLength() {
|
|
138
|
+
let len = (0, _util.compactToU8a)(this.size).length;
|
|
139
|
+
|
|
140
|
+
for (const [k, v] of this.entries()) {
|
|
141
|
+
len += v.encodedLength + k.encodedLength;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return len;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* @description Returns a hash of the value
|
|
148
|
+
*/
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
get hash() {
|
|
152
|
+
return this.registry.hash(this.toU8a());
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* @description Checks if the value is an empty value
|
|
156
|
+
*/
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
get isEmpty() {
|
|
160
|
+
return this.size === 0;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* @description Compares the value of the input to see if there is a match
|
|
164
|
+
*/
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
eq(other) {
|
|
168
|
+
return (0, _index.compareMap)(this, other);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
|
|
172
|
+
*/
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
toHex() {
|
|
176
|
+
return (0, _util.u8aToHex)(this.toU8a());
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
180
|
+
*/
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
toHuman(isExtended) {
|
|
184
|
+
const json = {};
|
|
185
|
+
|
|
186
|
+
for (const [k, v] of this.entries()) {
|
|
187
|
+
json[k.toString()] = v.toHuman(isExtended);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return json;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
194
|
+
*/
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
toJSON() {
|
|
198
|
+
const json = {};
|
|
199
|
+
|
|
200
|
+
for (const [k, v] of this.entries()) {
|
|
201
|
+
json[k.toString()] = v.toJSON();
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return json;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* @description Returns the base runtime type name for this instance
|
|
208
|
+
*/
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
toRawType() {
|
|
212
|
+
return `${(0, _classPrivateFieldLooseBase2.default)(this, _type)[_type]}<${this.registry.getClassName((0, _classPrivateFieldLooseBase2.default)(this, _KeyClass)[_KeyClass]) || new ((0, _classPrivateFieldLooseBase2.default)(this, _KeyClass)[_KeyClass])(this.registry).toRawType()},${this.registry.getClassName((0, _classPrivateFieldLooseBase2.default)(this, _ValClass)[_ValClass]) || new ((0, _classPrivateFieldLooseBase2.default)(this, _ValClass)[_ValClass])(this.registry).toRawType()}>`;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* @description Returns the string representation of the value
|
|
216
|
+
*/
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
toString() {
|
|
220
|
+
return (0, _util.stringify)(this.toJSON());
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
224
|
+
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
225
|
+
*/
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
toU8a(isBare) {
|
|
229
|
+
const encoded = new Array();
|
|
230
|
+
|
|
231
|
+
if (!isBare) {
|
|
232
|
+
encoded.push((0, _util.compactToU8a)(this.size));
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
for (const [k, v] of this.entries()) {
|
|
236
|
+
encoded.push(k.toU8a(isBare), v.toU8a(isBare));
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return (0, _util.u8aConcat)(...encoded);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
exports.CodecMap = CodecMap;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { HexString } from '@polkadot/util/types';
|
|
2
|
+
import type { AnyJson, Codec, CodecClass, CodecRegistry, IMap, IU8a } from '../types';
|
|
3
|
+
export declare class CodecMap<K extends Codec = Codec, V extends Codec = Codec> extends Map<K, V> implements IMap<K, V> {
|
|
4
|
+
#private;
|
|
5
|
+
readonly registry: CodecRegistry;
|
|
6
|
+
createdAtHash?: IU8a;
|
|
7
|
+
readonly initialU8aLength?: number;
|
|
8
|
+
constructor(registry: CodecRegistry, keyType: CodecClass<K> | string, valType: CodecClass<V> | string, rawValue: Uint8Array | string | Map<any, any> | undefined, type?: 'BTreeMap' | 'HashMap');
|
|
9
|
+
/**
|
|
10
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
11
|
+
*/
|
|
12
|
+
get encodedLength(): number;
|
|
13
|
+
/**
|
|
14
|
+
* @description Returns a hash of the value
|
|
15
|
+
*/
|
|
16
|
+
get hash(): IU8a;
|
|
17
|
+
/**
|
|
18
|
+
* @description Checks if the value is an empty value
|
|
19
|
+
*/
|
|
20
|
+
get isEmpty(): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* @description Compares the value of the input to see if there is a match
|
|
23
|
+
*/
|
|
24
|
+
eq(other?: unknown): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
|
|
27
|
+
*/
|
|
28
|
+
toHex(): HexString;
|
|
29
|
+
/**
|
|
30
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
31
|
+
*/
|
|
32
|
+
toHuman(isExtended?: boolean): Record<string, AnyJson>;
|
|
33
|
+
/**
|
|
34
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
35
|
+
*/
|
|
36
|
+
toJSON(): Record<string, AnyJson>;
|
|
37
|
+
/**
|
|
38
|
+
* @description Returns the base runtime type name for this instance
|
|
39
|
+
*/
|
|
40
|
+
toRawType(): string;
|
|
41
|
+
/**
|
|
42
|
+
* @description Returns the string representation of the value
|
|
43
|
+
*/
|
|
44
|
+
toString(): string;
|
|
45
|
+
/**
|
|
46
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
47
|
+
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
48
|
+
*/
|
|
49
|
+
toU8a(isBare?: boolean): Uint8Array;
|
|
50
|
+
}
|