@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,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.WrapperOpaque = void 0;
|
|
7
|
+
|
|
8
|
+
var _util = require("@polkadot/util");
|
|
9
|
+
|
|
10
|
+
var _Base = require("../base/Base.cjs");
|
|
11
|
+
|
|
12
|
+
var _index = require("../utils/index.cjs");
|
|
13
|
+
|
|
14
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
15
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
16
|
+
function decodeRaw(registry, Type, value) {
|
|
17
|
+
const Clazz = (0, _index.typeToConstructor)(registry, Type);
|
|
18
|
+
|
|
19
|
+
if ((0, _util.isU8a)(value)) {
|
|
20
|
+
const [, u8a] = (0, _util.compactStripLength)(value);
|
|
21
|
+
return new Clazz(registry, u8a);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return new Clazz(registry, value);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
class WrapperOpaque extends _Base.Base {
|
|
28
|
+
constructor(registry, Type, value) {
|
|
29
|
+
super(registry, decodeRaw(registry, Type, value));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static with(Type) {
|
|
33
|
+
return class extends WrapperOpaque {
|
|
34
|
+
constructor(registry, value) {
|
|
35
|
+
super(registry, Type, value);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @description Returns the base runtime type name for this instance
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
toRawType() {
|
|
46
|
+
return `WrapperOpaque<${this._raw.toRawType()}>`;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
toU8a(isBare) {
|
|
54
|
+
const u8a = super.toU8a(isBare);
|
|
55
|
+
return isBare ? u8a : (0, _util.compactAddLength)(u8a);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* @description Return the inner value for the wrapped type
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
unwrap() {
|
|
63
|
+
return this._raw;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
exports.WrapperOpaque = WrapperOpaque;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Codec, CodecClass, CodecRegistry } from '../types';
|
|
2
|
+
import { Base } from '../base/Base';
|
|
3
|
+
export declare class WrapperOpaque<T extends Codec> extends Base<T> {
|
|
4
|
+
constructor(registry: CodecRegistry, Type: CodecClass<T> | string, value?: unknown);
|
|
5
|
+
static with<T extends Codec>(Type: CodecClass<T> | string): CodecClass<WrapperOpaque<T>>;
|
|
6
|
+
/**
|
|
7
|
+
* @description Returns the base runtime type name for this instance
|
|
8
|
+
*/
|
|
9
|
+
toRawType(): string;
|
|
10
|
+
/**
|
|
11
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
12
|
+
*/
|
|
13
|
+
toU8a(isBare?: boolean): Uint8Array;
|
|
14
|
+
/**
|
|
15
|
+
* @description Return the inner value for the wrapped type
|
|
16
|
+
*/
|
|
17
|
+
unwrap(): T;
|
|
18
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { compactAddLength, compactStripLength, isU8a } from '@polkadot/util';
|
|
4
|
+
import { Base } from "../base/Base.js";
|
|
5
|
+
import { typeToConstructor } from "../utils/index.js";
|
|
6
|
+
|
|
7
|
+
function decodeRaw(registry, Type, value) {
|
|
8
|
+
const Clazz = typeToConstructor(registry, Type);
|
|
9
|
+
|
|
10
|
+
if (isU8a(value)) {
|
|
11
|
+
const [, u8a] = compactStripLength(value);
|
|
12
|
+
return new Clazz(registry, u8a);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return new Clazz(registry, value);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class WrapperOpaque extends Base {
|
|
19
|
+
constructor(registry, Type, value) {
|
|
20
|
+
super(registry, decodeRaw(registry, Type, value));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static with(Type) {
|
|
24
|
+
return class extends WrapperOpaque {
|
|
25
|
+
constructor(registry, value) {
|
|
26
|
+
super(registry, Type, value);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @description Returns the base runtime type name for this instance
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
toRawType() {
|
|
37
|
+
return `WrapperOpaque<${this._raw.toRawType()}>`;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
toU8a(isBare) {
|
|
45
|
+
const u8a = super.toU8a(isBare);
|
|
46
|
+
return isBare ? u8a : compactAddLength(u8a);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* @description Return the inner value for the wrapped type
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
unwrap() {
|
|
54
|
+
return this._raw;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "BTreeMap", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _BTreeMap.BTreeMap;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "BTreeSet", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _BTreeSet.BTreeSet;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "BitVec", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _BitVec.BitVec;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "Bytes", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _Bytes.Bytes;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "CodecMap", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _Map.CodecMap;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "HashMap", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _HashMap.HashMap;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "Linkage", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _Linkage.Linkage;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "Map", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _Map.CodecMap;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(exports, "Range", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _Range.Range;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(exports, "RangeInclusive", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () {
|
|
63
|
+
return _Range.RangeInclusive;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
Object.defineProperty(exports, "Type", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function () {
|
|
69
|
+
return _Type.Type;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(exports, "U8aFixed", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function () {
|
|
75
|
+
return _U8aFixed.U8aFixed;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(exports, "WrapperOpaque", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function () {
|
|
81
|
+
return _WrapperOpaque.WrapperOpaque;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
var _BitVec = require("./BitVec.cjs");
|
|
86
|
+
|
|
87
|
+
var _BTreeMap = require("./BTreeMap.cjs");
|
|
88
|
+
|
|
89
|
+
var _BTreeSet = require("./BTreeSet.cjs");
|
|
90
|
+
|
|
91
|
+
var _Bytes = require("./Bytes.cjs");
|
|
92
|
+
|
|
93
|
+
var _HashMap = require("./HashMap.cjs");
|
|
94
|
+
|
|
95
|
+
var _Linkage = require("./Linkage.cjs");
|
|
96
|
+
|
|
97
|
+
var _Map = require("./Map.cjs");
|
|
98
|
+
|
|
99
|
+
var _Range = require("./Range.cjs");
|
|
100
|
+
|
|
101
|
+
var _Type = require("./Type.cjs");
|
|
102
|
+
|
|
103
|
+
var _U8aFixed = require("./U8aFixed.cjs");
|
|
104
|
+
|
|
105
|
+
var _WrapperOpaque = require("./WrapperOpaque.cjs");
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { BitVec } from './BitVec';
|
|
2
|
+
export { BTreeMap } from './BTreeMap';
|
|
3
|
+
export { BTreeSet } from './BTreeSet';
|
|
4
|
+
export { Bytes } from './Bytes';
|
|
5
|
+
export { HashMap } from './HashMap';
|
|
6
|
+
export { Linkage } from './Linkage';
|
|
7
|
+
export { CodecMap, CodecMap as Map } from './Map';
|
|
8
|
+
export { Range, RangeInclusive } from './Range';
|
|
9
|
+
export { Type } from './Type';
|
|
10
|
+
export { U8aFixed } from './U8aFixed';
|
|
11
|
+
export { WrapperOpaque } from './WrapperOpaque';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
export { BitVec } from "./BitVec.js";
|
|
4
|
+
export { BTreeMap } from "./BTreeMap.js";
|
|
5
|
+
export { BTreeSet } from "./BTreeSet.js";
|
|
6
|
+
export { Bytes } from "./Bytes.js";
|
|
7
|
+
export { HashMap } from "./HashMap.js";
|
|
8
|
+
export { Linkage } from "./Linkage.js";
|
|
9
|
+
export { CodecMap, CodecMap as Map } from "./Map.js";
|
|
10
|
+
export { Range, RangeInclusive } from "./Range.js";
|
|
11
|
+
export { Type } from "./Type.js";
|
|
12
|
+
export { U8aFixed } from "./U8aFixed.js";
|
|
13
|
+
export { WrapperOpaque } from "./WrapperOpaque.js";
|
package/index.cjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
require("./detectPackage.cjs");
|
|
8
|
+
|
|
9
|
+
var _bundle = require("./bundle.cjs");
|
|
10
|
+
|
|
11
|
+
Object.keys(_bundle).forEach(function (key) {
|
|
12
|
+
if (key === "default" || key === "__esModule") return;
|
|
13
|
+
if (key in exports && exports[key] === _bundle[key]) return;
|
|
14
|
+
Object.defineProperty(exports, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () {
|
|
17
|
+
return _bundle[key];
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
});
|
package/index.d.ts
ADDED
package/index.js
ADDED
package/native/Bool.cjs
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.bool = void 0;
|
|
7
|
+
|
|
8
|
+
var _util = require("@polkadot/util");
|
|
9
|
+
|
|
10
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
11
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
12
|
+
|
|
13
|
+
/** @internal */
|
|
14
|
+
function decodeBool(value) {
|
|
15
|
+
if ((0, _util.isU8a)(value)) {
|
|
16
|
+
return value[0] === 1;
|
|
17
|
+
} else if (value instanceof Boolean) {
|
|
18
|
+
return value.valueOf();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return !!value;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* @name bool
|
|
25
|
+
* @description
|
|
26
|
+
* Representation for a boolean value in the system. It extends the base JS `Boolean` class
|
|
27
|
+
* @noInheritDoc
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class bool extends Boolean {
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
33
|
+
constructor(registry) {
|
|
34
|
+
let value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
35
|
+
super(decodeBool(value));
|
|
36
|
+
this.registry = void 0;
|
|
37
|
+
this.createdAtHash = void 0;
|
|
38
|
+
this.registry = registry;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
get encodedLength() {
|
|
46
|
+
return 1;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* @description returns a hash of the contents
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
get hash() {
|
|
54
|
+
return this.registry.hash(this.toU8a());
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* @description Checks if the value is an empty value (true when it wraps false/default)
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
get isEmpty() {
|
|
62
|
+
return this.isFalse;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* @description Checks if the value is an empty value (always false)
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
get isFalse() {
|
|
70
|
+
return !this.isTrue;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* @description Checks if the value is an empty value (always false)
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
get isTrue() {
|
|
78
|
+
return this.valueOf();
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* @description Compares the value of the input to see if there is a match
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
eq(other) {
|
|
86
|
+
return this.valueOf() === (other instanceof Boolean ? other.valueOf() : other);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* @description Returns a hex string representation of the value
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
toHex() {
|
|
94
|
+
return (0, _util.u8aToHex)(this.toU8a());
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
toHuman() {
|
|
102
|
+
return this.toJSON();
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
toJSON() {
|
|
110
|
+
return this.valueOf();
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* @description Returns the base runtime type name for this instance
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
toRawType() {
|
|
118
|
+
return 'bool';
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* @description Returns the string representation of the value
|
|
122
|
+
*/
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
toString() {
|
|
126
|
+
return this.toJSON().toString();
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
130
|
+
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
131
|
+
*/
|
|
132
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
toU8a(isBare) {
|
|
136
|
+
return new Uint8Array([this.valueOf() ? 1 : 0]);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
exports.bool = bool;
|
package/native/Bool.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { HexString } from '@polkadot/util/types';
|
|
2
|
+
import type { Codec, CodecRegistry, IU8a } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* @name bool
|
|
5
|
+
* @description
|
|
6
|
+
* Representation for a boolean value in the system. It extends the base JS `Boolean` class
|
|
7
|
+
* @noInheritDoc
|
|
8
|
+
*/
|
|
9
|
+
export declare class bool extends Boolean implements Codec {
|
|
10
|
+
readonly registry: CodecRegistry;
|
|
11
|
+
createdAtHash?: IU8a;
|
|
12
|
+
constructor(registry: CodecRegistry, value?: bool | Boolean | Uint8Array | boolean | number);
|
|
13
|
+
/**
|
|
14
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
15
|
+
*/
|
|
16
|
+
get encodedLength(): number;
|
|
17
|
+
/**
|
|
18
|
+
* @description returns a hash of the contents
|
|
19
|
+
*/
|
|
20
|
+
get hash(): IU8a;
|
|
21
|
+
/**
|
|
22
|
+
* @description Checks if the value is an empty value (true when it wraps false/default)
|
|
23
|
+
*/
|
|
24
|
+
get isEmpty(): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* @description Checks if the value is an empty value (always false)
|
|
27
|
+
*/
|
|
28
|
+
get isFalse(): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* @description Checks if the value is an empty value (always false)
|
|
31
|
+
*/
|
|
32
|
+
get isTrue(): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* @description Compares the value of the input to see if there is a match
|
|
35
|
+
*/
|
|
36
|
+
eq(other?: unknown): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* @description Returns a hex string representation of the value
|
|
39
|
+
*/
|
|
40
|
+
toHex(): HexString;
|
|
41
|
+
/**
|
|
42
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
43
|
+
*/
|
|
44
|
+
toHuman(): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
47
|
+
*/
|
|
48
|
+
toJSON(): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* @description Returns the base runtime type name for this instance
|
|
51
|
+
*/
|
|
52
|
+
toRawType(): string;
|
|
53
|
+
/**
|
|
54
|
+
* @description Returns the string representation of the value
|
|
55
|
+
*/
|
|
56
|
+
toString(): string;
|
|
57
|
+
/**
|
|
58
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
59
|
+
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
60
|
+
*/
|
|
61
|
+
toU8a(isBare?: boolean): Uint8Array;
|
|
62
|
+
}
|
package/native/Bool.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { isU8a, u8aToHex } from '@polkadot/util';
|
|
4
|
+
/** @internal */
|
|
5
|
+
|
|
6
|
+
function decodeBool(value) {
|
|
7
|
+
if (isU8a(value)) {
|
|
8
|
+
return value[0] === 1;
|
|
9
|
+
} else if (value instanceof Boolean) {
|
|
10
|
+
return value.valueOf();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return !!value;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* @name bool
|
|
17
|
+
* @description
|
|
18
|
+
* Representation for a boolean value in the system. It extends the base JS `Boolean` class
|
|
19
|
+
* @noInheritDoc
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
export class bool extends Boolean {
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
25
|
+
constructor(registry, value = false) {
|
|
26
|
+
super(decodeBool(value));
|
|
27
|
+
this.registry = void 0;
|
|
28
|
+
this.createdAtHash = void 0;
|
|
29
|
+
this.registry = registry;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
get encodedLength() {
|
|
37
|
+
return 1;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @description returns a hash of the contents
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
get hash() {
|
|
45
|
+
return this.registry.hash(this.toU8a());
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* @description Checks if the value is an empty value (true when it wraps false/default)
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
get isEmpty() {
|
|
53
|
+
return this.isFalse;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* @description Checks if the value is an empty value (always false)
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
get isFalse() {
|
|
61
|
+
return !this.isTrue;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* @description Checks if the value is an empty value (always false)
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
get isTrue() {
|
|
69
|
+
return this.valueOf();
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* @description Compares the value of the input to see if there is a match
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
eq(other) {
|
|
77
|
+
return this.valueOf() === (other instanceof Boolean ? other.valueOf() : other);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* @description Returns a hex string representation of the value
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
toHex() {
|
|
85
|
+
return u8aToHex(this.toU8a());
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
toHuman() {
|
|
93
|
+
return this.toJSON();
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
toJSON() {
|
|
101
|
+
return this.valueOf();
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* @description Returns the base runtime type name for this instance
|
|
105
|
+
*/
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
toRawType() {
|
|
109
|
+
return 'bool';
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* @description Returns the string representation of the value
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
toString() {
|
|
117
|
+
return this.toJSON().toString();
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
121
|
+
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
122
|
+
*/
|
|
123
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
toU8a(isBare) {
|
|
127
|
+
return new Uint8Array([this.valueOf() ? 1 : 0]);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
}
|