@polkadot/types-codec 6.12.2-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.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 +137 -0
- package/base/Base.d.ts +56 -0
- package/base/Base.js +125 -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 +445 -0
- package/base/Enum.d.ts +105 -0
- package/base/Enum.js +421 -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 +60 -0
- package/extended/WrapperOpaque.d.ts +14 -0
- package/extended/WrapperOpaque.js +49 -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 +137 -0
- package/native/Json.d.ts +56 -0
- package/native/Json.js +121 -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 +302 -0
- package/native/Struct.d.ts +93 -0
- package/native/Struct.js +286 -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 +69 -0
- package/types/interfaces.js +1 -0
- package/types/registry.cjs +1 -0
- package/types/registry.d.ts +61 -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
package/base/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
export { Base } from "./Base.js";
|
|
4
|
+
export { Compact } from "./Compact.js";
|
|
5
|
+
export { DoNotConstruct } from "./DoNotConstruct.js";
|
|
6
|
+
export { Enum } from "./Enum.js";
|
|
7
|
+
export { Int } from "./Int.js";
|
|
8
|
+
export { Null } from "./Null.js";
|
|
9
|
+
export { Option } from "./Option.js";
|
|
10
|
+
export { Result } from "./Result.js";
|
|
11
|
+
export { Tuple } from "./Tuple.js";
|
|
12
|
+
export { UInt } from "./UInt.js";
|
|
13
|
+
export { Vec } from "./Vec.js";
|
|
14
|
+
export { VecAny } from "./VecAny.js";
|
|
15
|
+
export { VecFixed } from "./VecFixed.js";
|
package/bundle.cjs
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
packageInfo: true
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "packageInfo", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return _packageInfo.packageInfo;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
var _packageInfo = require("./packageInfo.cjs");
|
|
17
|
+
|
|
18
|
+
var _index = require("./abstract/index.cjs");
|
|
19
|
+
|
|
20
|
+
Object.keys(_index).forEach(function (key) {
|
|
21
|
+
if (key === "default" || key === "__esModule") return;
|
|
22
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
23
|
+
if (key in exports && exports[key] === _index[key]) return;
|
|
24
|
+
Object.defineProperty(exports, key, {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _index[key];
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
var _index2 = require("./base/index.cjs");
|
|
33
|
+
|
|
34
|
+
Object.keys(_index2).forEach(function (key) {
|
|
35
|
+
if (key === "default" || key === "__esModule") return;
|
|
36
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
37
|
+
if (key in exports && exports[key] === _index2[key]) return;
|
|
38
|
+
Object.defineProperty(exports, key, {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
get: function () {
|
|
41
|
+
return _index2[key];
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
var _index3 = require("./extended/index.cjs");
|
|
47
|
+
|
|
48
|
+
Object.keys(_index3).forEach(function (key) {
|
|
49
|
+
if (key === "default" || key === "__esModule") return;
|
|
50
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
51
|
+
if (key in exports && exports[key] === _index3[key]) return;
|
|
52
|
+
Object.defineProperty(exports, key, {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
get: function () {
|
|
55
|
+
return _index3[key];
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
var _index4 = require("./native/index.cjs");
|
|
61
|
+
|
|
62
|
+
Object.keys(_index4).forEach(function (key) {
|
|
63
|
+
if (key === "default" || key === "__esModule") return;
|
|
64
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
65
|
+
if (key in exports && exports[key] === _index4[key]) return;
|
|
66
|
+
Object.defineProperty(exports, key, {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function () {
|
|
69
|
+
return _index4[key];
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
var _index5 = require("./primitive/index.cjs");
|
|
75
|
+
|
|
76
|
+
Object.keys(_index5).forEach(function (key) {
|
|
77
|
+
if (key === "default" || key === "__esModule") return;
|
|
78
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
79
|
+
if (key in exports && exports[key] === _index5[key]) return;
|
|
80
|
+
Object.defineProperty(exports, key, {
|
|
81
|
+
enumerable: true,
|
|
82
|
+
get: function () {
|
|
83
|
+
return _index5[key];
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
var _index6 = require("./utils/index.cjs");
|
|
89
|
+
|
|
90
|
+
Object.keys(_index6).forEach(function (key) {
|
|
91
|
+
if (key === "default" || key === "__esModule") return;
|
|
92
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
93
|
+
if (key in exports && exports[key] === _index6[key]) return;
|
|
94
|
+
Object.defineProperty(exports, key, {
|
|
95
|
+
enumerable: true,
|
|
96
|
+
get: function () {
|
|
97
|
+
return _index6[key];
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
});
|
package/bundle.d.ts
ADDED
package/bundle.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
export { packageInfo } from "./packageInfo.js";
|
|
4
|
+
export * from "./abstract/index.js";
|
|
5
|
+
export * from "./base/index.js";
|
|
6
|
+
export * from "./extended/index.js";
|
|
7
|
+
export * from "./native/index.js";
|
|
8
|
+
export * from "./primitive/index.js";
|
|
9
|
+
export * from "./utils/index.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _util = require("@polkadot/util");
|
|
4
|
+
|
|
5
|
+
var _packageInfo = require("./packageInfo.cjs");
|
|
6
|
+
|
|
7
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
8
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
(0, _util.detectPackage)(_packageInfo.packageInfo, typeof __dirname !== 'undefined' && __dirname, []);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/detectPackage.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { detectPackage } from '@polkadot/util';
|
|
4
|
+
import { packageInfo } from "./packageInfo.js";
|
|
5
|
+
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname, []);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.BTreeMap = void 0;
|
|
7
|
+
|
|
8
|
+
var _Map = require("./Map.cjs");
|
|
9
|
+
|
|
10
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
11
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
12
|
+
class BTreeMap extends _Map.CodecMap {
|
|
13
|
+
static with(keyType, valType) {
|
|
14
|
+
return class extends BTreeMap {
|
|
15
|
+
constructor(registry, value) {
|
|
16
|
+
super(registry, keyType, valType, value, 'BTreeMap');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
exports.BTreeMap = BTreeMap;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Codec, CodecClass } from '../types';
|
|
2
|
+
import { CodecMap } from './Map';
|
|
3
|
+
export declare class BTreeMap<K extends Codec = Codec, V extends Codec = Codec> extends CodecMap<K, V> {
|
|
4
|
+
static with<K extends Codec, V extends Codec>(keyType: CodecClass<K> | string, valType: CodecClass<V> | string): CodecClass<CodecMap<K, V>>;
|
|
5
|
+
}
|
|
@@ -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 BTreeMap extends CodecMap {
|
|
5
|
+
static with(keyType, valType) {
|
|
6
|
+
return class extends BTreeMap {
|
|
7
|
+
constructor(registry, value) {
|
|
8
|
+
super(registry, keyType, valType, value, 'BTreeMap');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.BTreeSet = 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 _index = require("../utils/index.cjs");
|
|
17
|
+
|
|
18
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
19
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
20
|
+
const l = (0, _util.logger)('BTreeSet');
|
|
21
|
+
/** @internal */
|
|
22
|
+
|
|
23
|
+
function decodeSetFromU8a(registry, ValClass, u8a) {
|
|
24
|
+
const output = new Set();
|
|
25
|
+
const [offset, length] = (0, _util.compactFromU8a)(u8a);
|
|
26
|
+
const [values, decodedLength] = (0, _index.decodeU8aVec)(registry, u8a, offset, ValClass, length.toNumber());
|
|
27
|
+
|
|
28
|
+
for (let i = 0; i < values.length; i++) {
|
|
29
|
+
output.add(values[i]);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return [output, decodedLength + offset];
|
|
33
|
+
}
|
|
34
|
+
/** @internal */
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
function decodeSetFromSet(registry, ValClass, value) {
|
|
38
|
+
const output = new Set();
|
|
39
|
+
value.forEach(val => {
|
|
40
|
+
try {
|
|
41
|
+
output.add(val instanceof ValClass ? val : new ValClass(registry, val));
|
|
42
|
+
} catch (error) {
|
|
43
|
+
l.error('Failed to decode key or value:', error.message);
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return [output, 0];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Decode input to pass into constructor.
|
|
51
|
+
*
|
|
52
|
+
* @param ValClass - Type of the map value
|
|
53
|
+
* @param value - Value to decode, one of:
|
|
54
|
+
* - null
|
|
55
|
+
* - undefined
|
|
56
|
+
* - hex
|
|
57
|
+
* - Uint8Array
|
|
58
|
+
* - Set<any>, where both key and value types are either
|
|
59
|
+
* constructors or decodeable values for their types.
|
|
60
|
+
* @param jsonSet
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
function decodeSet(registry, valType, value) {
|
|
66
|
+
if (!value) {
|
|
67
|
+
return [new Set(), 0];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const ValClass = (0, _index.typeToConstructor)(registry, valType);
|
|
71
|
+
|
|
72
|
+
if ((0, _util.isU8a)(value) || (0, _util.isHex)(value)) {
|
|
73
|
+
return decodeSetFromU8a(registry, ValClass, (0, _util.u8aToU8a)(value));
|
|
74
|
+
} else if (Array.isArray(value) || value instanceof Set) {
|
|
75
|
+
return decodeSetFromSet(registry, ValClass, value);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
throw new Error('BTreeSet: cannot decode type');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
var _ValClass = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("ValClass");
|
|
82
|
+
|
|
83
|
+
class BTreeSet extends Set {
|
|
84
|
+
constructor(registry, valType, rawValue) {
|
|
85
|
+
const [values, decodedLength] = decodeSet(registry, valType, rawValue);
|
|
86
|
+
super((0, _index.sortSet)(values));
|
|
87
|
+
this.registry = void 0;
|
|
88
|
+
this.createdAtHash = void 0;
|
|
89
|
+
this.initialU8aLength = void 0;
|
|
90
|
+
Object.defineProperty(this, _ValClass, {
|
|
91
|
+
writable: true,
|
|
92
|
+
value: void 0
|
|
93
|
+
});
|
|
94
|
+
this.registry = registry;
|
|
95
|
+
this.initialU8aLength = decodedLength;
|
|
96
|
+
(0, _classPrivateFieldLooseBase2.default)(this, _ValClass)[_ValClass] = (0, _index.typeToConstructor)(registry, valType);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
static with(valType) {
|
|
100
|
+
return class extends BTreeSet {
|
|
101
|
+
constructor(registry, value) {
|
|
102
|
+
super(registry, valType, value);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
109
|
+
*/
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
get encodedLength() {
|
|
113
|
+
let len = (0, _util.compactToU8a)(this.size).length;
|
|
114
|
+
|
|
115
|
+
for (const v of this.values()) {
|
|
116
|
+
len += v.encodedLength;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return len;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* @description Returns a hash of the value
|
|
123
|
+
*/
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
get hash() {
|
|
127
|
+
return this.registry.hash(this.toU8a());
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* @description Checks if the value is an empty value
|
|
131
|
+
*/
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
get isEmpty() {
|
|
135
|
+
return this.size === 0;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* @description The actual set values as a string[]
|
|
139
|
+
*/
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
get strings() {
|
|
143
|
+
return [...super.values()].map(v => v.toString());
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* @description Compares the value of the input to see if there is a match
|
|
147
|
+
*/
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
eq(other) {
|
|
151
|
+
return (0, _index.compareSet)(this, other);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
|
|
155
|
+
*/
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
toHex() {
|
|
159
|
+
return (0, _util.u8aToHex)(this.toU8a());
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
163
|
+
*/
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
toHuman(isExtended) {
|
|
167
|
+
const json = [];
|
|
168
|
+
|
|
169
|
+
for (const v of this.values()) {
|
|
170
|
+
json.push(v.toHuman(isExtended));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return json;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
177
|
+
*/
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
toJSON() {
|
|
181
|
+
const json = [];
|
|
182
|
+
|
|
183
|
+
for (const v of this.values()) {
|
|
184
|
+
json.push(v.toJSON());
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return json;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* @description Returns the base runtime type name for this instance
|
|
191
|
+
*/
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
toRawType() {
|
|
195
|
+
return `BTreeSet<${this.registry.getClassName((0, _classPrivateFieldLooseBase2.default)(this, _ValClass)[_ValClass]) || new ((0, _classPrivateFieldLooseBase2.default)(this, _ValClass)[_ValClass])(this.registry).toRawType()}>`;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* @description Returns the string representation of the value
|
|
199
|
+
*/
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
toString() {
|
|
203
|
+
return (0, _util.stringify)(this.toJSON());
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
207
|
+
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
208
|
+
*/
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
toU8a(isBare) {
|
|
212
|
+
const encoded = new Array();
|
|
213
|
+
|
|
214
|
+
if (!isBare) {
|
|
215
|
+
encoded.push((0, _util.compactToU8a)(this.size));
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
for (const v of this.values()) {
|
|
219
|
+
encoded.push(v.toU8a(isBare));
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return (0, _util.u8aConcat)(...encoded);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
exports.BTreeSet = BTreeSet;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { HexString } from '@polkadot/util/types';
|
|
2
|
+
import type { AnyJson, Codec, CodecClass, CodecRegistry, ISet, IU8a } from '../types';
|
|
3
|
+
export declare class BTreeSet<V extends Codec = Codec> extends Set<V> implements ISet<V> {
|
|
4
|
+
#private;
|
|
5
|
+
readonly registry: CodecRegistry;
|
|
6
|
+
createdAtHash?: IU8a;
|
|
7
|
+
readonly initialU8aLength?: number;
|
|
8
|
+
constructor(registry: CodecRegistry, valType: CodecClass<V> | string, rawValue?: Uint8Array | string | string[] | Set<any>);
|
|
9
|
+
static with<V extends Codec>(valType: CodecClass<V> | string): CodecClass<BTreeSet<V>>;
|
|
10
|
+
/**
|
|
11
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
12
|
+
*/
|
|
13
|
+
get encodedLength(): number;
|
|
14
|
+
/**
|
|
15
|
+
* @description Returns a hash of the value
|
|
16
|
+
*/
|
|
17
|
+
get hash(): IU8a;
|
|
18
|
+
/**
|
|
19
|
+
* @description Checks if the value is an empty value
|
|
20
|
+
*/
|
|
21
|
+
get isEmpty(): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* @description The actual set values as a string[]
|
|
24
|
+
*/
|
|
25
|
+
get strings(): string[];
|
|
26
|
+
/**
|
|
27
|
+
* @description Compares the value of the input to see if there is a match
|
|
28
|
+
*/
|
|
29
|
+
eq(other?: unknown): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
|
|
32
|
+
*/
|
|
33
|
+
toHex(): HexString;
|
|
34
|
+
/**
|
|
35
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
36
|
+
*/
|
|
37
|
+
toHuman(isExtended?: boolean): AnyJson;
|
|
38
|
+
/**
|
|
39
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
40
|
+
*/
|
|
41
|
+
toJSON(): AnyJson;
|
|
42
|
+
/**
|
|
43
|
+
* @description Returns the base runtime type name for this instance
|
|
44
|
+
*/
|
|
45
|
+
toRawType(): string;
|
|
46
|
+
/**
|
|
47
|
+
* @description Returns the string representation of the value
|
|
48
|
+
*/
|
|
49
|
+
toString(): string;
|
|
50
|
+
/**
|
|
51
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
52
|
+
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
53
|
+
*/
|
|
54
|
+
toU8a(isBare?: boolean): Uint8Array;
|
|
55
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import _classPrivateFieldLooseBase from "@babel/runtime/helpers/esm/classPrivateFieldLooseBase";
|
|
2
|
+
import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateFieldLooseKey";
|
|
3
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
import { compactFromU8a, compactToU8a, isHex, isU8a, logger, stringify, u8aConcat, u8aToHex, u8aToU8a } from '@polkadot/util';
|
|
6
|
+
import { compareSet, decodeU8aVec, sortSet, typeToConstructor } from "../utils/index.js";
|
|
7
|
+
const l = logger('BTreeSet');
|
|
8
|
+
/** @internal */
|
|
9
|
+
|
|
10
|
+
function decodeSetFromU8a(registry, ValClass, u8a) {
|
|
11
|
+
const output = new Set();
|
|
12
|
+
const [offset, length] = compactFromU8a(u8a);
|
|
13
|
+
const [values, decodedLength] = decodeU8aVec(registry, u8a, offset, ValClass, length.toNumber());
|
|
14
|
+
|
|
15
|
+
for (let i = 0; i < values.length; i++) {
|
|
16
|
+
output.add(values[i]);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return [output, decodedLength + offset];
|
|
20
|
+
}
|
|
21
|
+
/** @internal */
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
function decodeSetFromSet(registry, ValClass, value) {
|
|
25
|
+
const output = new Set();
|
|
26
|
+
value.forEach(val => {
|
|
27
|
+
try {
|
|
28
|
+
output.add(val instanceof ValClass ? val : new ValClass(registry, val));
|
|
29
|
+
} catch (error) {
|
|
30
|
+
l.error('Failed to decode key or value:', error.message);
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return [output, 0];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Decode input to pass into constructor.
|
|
38
|
+
*
|
|
39
|
+
* @param ValClass - Type of the map value
|
|
40
|
+
* @param value - Value to decode, one of:
|
|
41
|
+
* - null
|
|
42
|
+
* - undefined
|
|
43
|
+
* - hex
|
|
44
|
+
* - Uint8Array
|
|
45
|
+
* - Set<any>, where both key and value types are either
|
|
46
|
+
* constructors or decodeable values for their types.
|
|
47
|
+
* @param jsonSet
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
function decodeSet(registry, valType, value) {
|
|
53
|
+
if (!value) {
|
|
54
|
+
return [new Set(), 0];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const ValClass = typeToConstructor(registry, valType);
|
|
58
|
+
|
|
59
|
+
if (isU8a(value) || isHex(value)) {
|
|
60
|
+
return decodeSetFromU8a(registry, ValClass, u8aToU8a(value));
|
|
61
|
+
} else if (Array.isArray(value) || value instanceof Set) {
|
|
62
|
+
return decodeSetFromSet(registry, ValClass, value);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
throw new Error('BTreeSet: cannot decode type');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
var _ValClass = /*#__PURE__*/_classPrivateFieldLooseKey("ValClass");
|
|
69
|
+
|
|
70
|
+
export class BTreeSet extends Set {
|
|
71
|
+
constructor(registry, valType, rawValue) {
|
|
72
|
+
const [values, decodedLength] = decodeSet(registry, valType, rawValue);
|
|
73
|
+
super(sortSet(values));
|
|
74
|
+
this.registry = void 0;
|
|
75
|
+
this.createdAtHash = void 0;
|
|
76
|
+
this.initialU8aLength = void 0;
|
|
77
|
+
Object.defineProperty(this, _ValClass, {
|
|
78
|
+
writable: true,
|
|
79
|
+
value: void 0
|
|
80
|
+
});
|
|
81
|
+
this.registry = registry;
|
|
82
|
+
this.initialU8aLength = decodedLength;
|
|
83
|
+
_classPrivateFieldLooseBase(this, _ValClass)[_ValClass] = typeToConstructor(registry, valType);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
static with(valType) {
|
|
87
|
+
return class extends BTreeSet {
|
|
88
|
+
constructor(registry, value) {
|
|
89
|
+
super(registry, valType, value);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
get encodedLength() {
|
|
100
|
+
let len = compactToU8a(this.size).length;
|
|
101
|
+
|
|
102
|
+
for (const v of this.values()) {
|
|
103
|
+
len += v.encodedLength;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return len;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* @description Returns a hash of the value
|
|
110
|
+
*/
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
get hash() {
|
|
114
|
+
return this.registry.hash(this.toU8a());
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* @description Checks if the value is an empty value
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
get isEmpty() {
|
|
122
|
+
return this.size === 0;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* @description The actual set values as a string[]
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
get strings() {
|
|
130
|
+
return [...super.values()].map(v => v.toString());
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* @description Compares the value of the input to see if there is a match
|
|
134
|
+
*/
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
eq(other) {
|
|
138
|
+
return compareSet(this, other);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
|
|
142
|
+
*/
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
toHex() {
|
|
146
|
+
return u8aToHex(this.toU8a());
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
toHuman(isExtended) {
|
|
154
|
+
const json = [];
|
|
155
|
+
|
|
156
|
+
for (const v of this.values()) {
|
|
157
|
+
json.push(v.toHuman(isExtended));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return json;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
164
|
+
*/
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
toJSON() {
|
|
168
|
+
const json = [];
|
|
169
|
+
|
|
170
|
+
for (const v of this.values()) {
|
|
171
|
+
json.push(v.toJSON());
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return json;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* @description Returns the base runtime type name for this instance
|
|
178
|
+
*/
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
toRawType() {
|
|
182
|
+
return `BTreeSet<${this.registry.getClassName(_classPrivateFieldLooseBase(this, _ValClass)[_ValClass]) || new (_classPrivateFieldLooseBase(this, _ValClass)[_ValClass])(this.registry).toRawType()}>`;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* @description Returns the string representation of the value
|
|
186
|
+
*/
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
toString() {
|
|
190
|
+
return stringify(this.toJSON());
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
194
|
+
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
195
|
+
*/
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
toU8a(isBare) {
|
|
199
|
+
const encoded = new Array();
|
|
200
|
+
|
|
201
|
+
if (!isBare) {
|
|
202
|
+
encoded.push(compactToU8a(this.size));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
for (const v of this.values()) {
|
|
206
|
+
encoded.push(v.toU8a(isBare));
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return u8aConcat(...encoded);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
}
|