@polkadot/types-codec 7.4.2-7 → 7.5.2-0
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.js +0 -4
- package/abstract/AbstractInt.js +10 -24
- package/base/Base.js +15 -29
- package/base/Compact.js +20 -34
- package/base/DoNotConstruct.js +14 -23
- package/base/Enum.js +36 -70
- package/base/Null.js +2 -3
- package/base/Option.js +19 -37
- package/base/Tuple.js +5 -11
- package/base/Vec.js +6 -12
- package/base/VecFixed.js +4 -10
- package/extended/BTreeSet.js +4 -13
- package/extended/BitVec.js +5 -11
- package/extended/Map.js +8 -27
- package/extended/Range.js +4 -10
- package/extended/WrapperKeepOpaque.cjs +11 -3
- package/extended/WrapperKeepOpaque.d.ts +4 -2
- package/extended/WrapperKeepOpaque.js +15 -24
- package/extended/WrapperOpaque.cjs +7 -31
- package/extended/WrapperOpaque.d.ts +6 -10
- package/extended/WrapperOpaque.js +7 -30
- package/native/Bool.js +0 -2
- package/native/Date.js +0 -2
- package/native/Json.js +0 -2
- package/native/Raw.js +0 -3
- package/native/Set.js +18 -32
- package/native/Struct.js +12 -30
- package/native/Text.js +7 -20
- package/package.json +2 -2
- package/packageInfo.cjs +1 -1
- package/packageInfo.js +1 -1
- package/primitive/I128.js +2 -5
- package/primitive/I16.js +2 -5
- package/primitive/I256.js +2 -5
- package/primitive/I32.js +2 -5
- package/primitive/I64.js +2 -5
- package/primitive/I8.js +2 -5
- package/primitive/U128.js +2 -5
- package/primitive/U16.js +2 -5
- package/primitive/U256.js +2 -5
- package/primitive/U32.js +2 -5
- package/primitive/U64.js +2 -5
- package/primitive/U8.js +2 -5
package/extended/Map.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import _classPrivateFieldLooseBase from "@babel/runtime/helpers/esm/classPrivateFieldLooseBase";
|
|
2
|
-
import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateFieldLooseKey";
|
|
3
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
4
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
3
|
import { compactFromU8a, compactToU8a, isHex, isObject, isU8a, logger, stringify, u8aConcat, u8aToHex, u8aToU8a } from '@polkadot/util';
|
|
@@ -81,36 +79,19 @@ function decodeMap(registry, keyType, valType, value) {
|
|
|
81
79
|
throw new Error('Map: cannot decode type');
|
|
82
80
|
}
|
|
83
81
|
|
|
84
|
-
var _KeyClass = /*#__PURE__*/_classPrivateFieldLooseKey("KeyClass");
|
|
85
|
-
|
|
86
|
-
var _ValClass = /*#__PURE__*/_classPrivateFieldLooseKey("ValClass");
|
|
87
|
-
|
|
88
|
-
var _type = /*#__PURE__*/_classPrivateFieldLooseKey("type");
|
|
89
|
-
|
|
90
82
|
export class CodecMap extends Map {
|
|
83
|
+
#KeyClass;
|
|
84
|
+
#ValClass;
|
|
85
|
+
#type;
|
|
86
|
+
|
|
91
87
|
constructor(registry, keyType, valType, rawValue, type = 'HashMap') {
|
|
92
88
|
const [decoded, decodedLength] = decodeMap(registry, keyType, valType, rawValue);
|
|
93
89
|
super(type === 'BTreeMap' ? sortMap(decoded) : decoded);
|
|
94
|
-
this.registry = void 0;
|
|
95
|
-
this.createdAtHash = void 0;
|
|
96
|
-
Object.defineProperty(this, _KeyClass, {
|
|
97
|
-
writable: true,
|
|
98
|
-
value: void 0
|
|
99
|
-
});
|
|
100
|
-
Object.defineProperty(this, _ValClass, {
|
|
101
|
-
writable: true,
|
|
102
|
-
value: void 0
|
|
103
|
-
});
|
|
104
|
-
this.initialU8aLength = void 0;
|
|
105
|
-
Object.defineProperty(this, _type, {
|
|
106
|
-
writable: true,
|
|
107
|
-
value: void 0
|
|
108
|
-
});
|
|
109
90
|
this.registry = registry;
|
|
110
91
|
this.initialU8aLength = decodedLength;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
92
|
+
this.#KeyClass = typeToConstructor(registry, keyType);
|
|
93
|
+
this.#ValClass = typeToConstructor(registry, valType);
|
|
94
|
+
this.#type = type;
|
|
114
95
|
}
|
|
115
96
|
/**
|
|
116
97
|
* @description The length of the value when encoded as a Uint8Array
|
|
@@ -192,7 +173,7 @@ export class CodecMap extends Map {
|
|
|
192
173
|
|
|
193
174
|
|
|
194
175
|
toRawType() {
|
|
195
|
-
return `${
|
|
176
|
+
return `${this.#type}<${this.registry.getClassName(this.#KeyClass) || new this.#KeyClass(this.registry).toRawType()},${this.registry.getClassName(this.#ValClass) || new this.#ValClass(this.registry).toRawType()}>`;
|
|
196
177
|
}
|
|
197
178
|
/**
|
|
198
179
|
* @description Returns the string representation of the value
|
package/extended/Range.js
CHANGED
|
@@ -1,27 +1,21 @@
|
|
|
1
|
-
import _classPrivateFieldLooseBase from "@babel/runtime/helpers/esm/classPrivateFieldLooseBase";
|
|
2
|
-
import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateFieldLooseKey";
|
|
3
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
4
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
3
|
import { Tuple } from "../base/Tuple.js";
|
|
6
4
|
|
|
7
|
-
var _rangeName = /*#__PURE__*/_classPrivateFieldLooseKey("rangeName");
|
|
8
|
-
|
|
9
5
|
/**
|
|
10
6
|
* @name Range
|
|
11
7
|
* @description
|
|
12
8
|
* Rust `Range<T>` representation
|
|
13
9
|
*/
|
|
14
10
|
export class Range extends Tuple {
|
|
11
|
+
#rangeName;
|
|
12
|
+
|
|
15
13
|
constructor(registry, Type, value, rangeName = 'Range') {
|
|
16
14
|
super(registry, {
|
|
17
15
|
end: Type,
|
|
18
16
|
start: Type
|
|
19
17
|
}, value);
|
|
20
|
-
|
|
21
|
-
writable: true,
|
|
22
|
-
value: void 0
|
|
23
|
-
});
|
|
24
|
-
_classPrivateFieldLooseBase(this, _rangeName)[_rangeName] = rangeName;
|
|
18
|
+
this.#rangeName = rangeName;
|
|
25
19
|
}
|
|
26
20
|
|
|
27
21
|
static with(Types) {
|
|
@@ -54,7 +48,7 @@ export class Range extends Tuple {
|
|
|
54
48
|
|
|
55
49
|
|
|
56
50
|
toRawType() {
|
|
57
|
-
return `${
|
|
51
|
+
return `${this.#rangeName}<${this.start.toRawType()}>`;
|
|
58
52
|
}
|
|
59
53
|
|
|
60
54
|
}
|
|
@@ -34,15 +34,18 @@ function decodeRaw(registry, typeName, value) {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
const instance = new Type(registry, value);
|
|
37
|
-
return [Type, instance, instance.
|
|
37
|
+
return [Type, instance, (0, _util.compactAddLength)(instance.toU8a())];
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
var _Type = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("Type");
|
|
41
41
|
|
|
42
42
|
var _decoded = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("decoded");
|
|
43
43
|
|
|
44
|
+
var _opaqueName = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("opaqueName");
|
|
45
|
+
|
|
44
46
|
class WrapperKeepOpaque extends _Bytes.Bytes {
|
|
45
47
|
constructor(registry, typeName, value) {
|
|
48
|
+
let opaqueName = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'WrapperKeepOpaque';
|
|
46
49
|
const [Type, decoded, u8a] = decodeRaw(registry, typeName, value);
|
|
47
50
|
super(registry, u8a);
|
|
48
51
|
Object.defineProperty(this, _Type, {
|
|
@@ -53,8 +56,13 @@ class WrapperKeepOpaque extends _Bytes.Bytes {
|
|
|
53
56
|
writable: true,
|
|
54
57
|
value: void 0
|
|
55
58
|
});
|
|
59
|
+
Object.defineProperty(this, _opaqueName, {
|
|
60
|
+
writable: true,
|
|
61
|
+
value: void 0
|
|
62
|
+
});
|
|
56
63
|
(0, _classPrivateFieldLooseBase2.default)(this, _Type)[_Type] = Type;
|
|
57
64
|
(0, _classPrivateFieldLooseBase2.default)(this, _decoded)[_decoded] = decoded;
|
|
65
|
+
(0, _classPrivateFieldLooseBase2.default)(this, _opaqueName)[_opaqueName] = opaqueName;
|
|
58
66
|
}
|
|
59
67
|
|
|
60
68
|
static with(Type) {
|
|
@@ -87,7 +95,7 @@ class WrapperKeepOpaque extends _Bytes.Bytes {
|
|
|
87
95
|
|
|
88
96
|
|
|
89
97
|
toRawType() {
|
|
90
|
-
return
|
|
98
|
+
return `${(0, _classPrivateFieldLooseBase2.default)(this, _opaqueName)[_opaqueName]}<${this.registry.getClassName((0, _classPrivateFieldLooseBase2.default)(this, _Type)[_Type]) || ((0, _classPrivateFieldLooseBase2.default)(this, _decoded)[_decoded] ? (0, _classPrivateFieldLooseBase2.default)(this, _decoded)[_decoded].toRawType() : new ((0, _classPrivateFieldLooseBase2.default)(this, _Type)[_Type])(this.registry).toRawType())}>`;
|
|
91
99
|
}
|
|
92
100
|
/**
|
|
93
101
|
* @description Converts the Object to to a string (either decoded or bytes)
|
|
@@ -103,7 +111,7 @@ class WrapperKeepOpaque extends _Bytes.Bytes {
|
|
|
103
111
|
|
|
104
112
|
|
|
105
113
|
unwrap() {
|
|
106
|
-
return (0, _util.assertReturn)((0, _classPrivateFieldLooseBase2.default)(this, _decoded)[_decoded],
|
|
114
|
+
return (0, _util.assertReturn)((0, _classPrivateFieldLooseBase2.default)(this, _decoded)[_decoded], () => `${(0, _classPrivateFieldLooseBase2.default)(this, _opaqueName)[_opaqueName]}: unwrapping an undecodable value`);
|
|
107
115
|
}
|
|
108
116
|
|
|
109
117
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { AnyJson,
|
|
1
|
+
import type { AnyJson, Codec, CodecClass, Registry } from '../types';
|
|
2
2
|
import { Bytes } from './Bytes';
|
|
3
|
+
declare type OpaqueName = 'WrapperKeepOpaque' | 'WrapperOpaque';
|
|
3
4
|
export declare class WrapperKeepOpaque<T extends Codec> extends Bytes {
|
|
4
5
|
#private;
|
|
5
|
-
constructor(registry: Registry, typeName: CodecClass<T> | string, value?:
|
|
6
|
+
constructor(registry: Registry, typeName: CodecClass<T> | string, value?: unknown, opaqueName?: OpaqueName);
|
|
6
7
|
static with<T extends Codec>(Type: CodecClass<T> | string): CodecClass<WrapperKeepOpaque<T>>;
|
|
7
8
|
/**
|
|
8
9
|
* @description Checks if the wrapper is decodable
|
|
@@ -25,3 +26,4 @@ export declare class WrapperKeepOpaque<T extends Codec> extends Bytes {
|
|
|
25
26
|
*/
|
|
26
27
|
unwrap(): T;
|
|
27
28
|
}
|
|
29
|
+
export {};
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import _classPrivateFieldLooseBase from "@babel/runtime/helpers/esm/classPrivateFieldLooseBase";
|
|
2
|
-
import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateFieldLooseKey";
|
|
3
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
4
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
import { assertReturn, compactStripLength, isHex, isU8a } from '@polkadot/util';
|
|
3
|
+
import { assertReturn, compactAddLength, compactStripLength, isHex, isU8a } from '@polkadot/util';
|
|
6
4
|
import { Raw } from "../native/Raw.js";
|
|
7
5
|
import { typeToConstructor } from "../utils/index.js";
|
|
8
6
|
import { Bytes } from "./Bytes.js";
|
|
@@ -20,27 +18,20 @@ function decodeRaw(registry, typeName, value) {
|
|
|
20
18
|
}
|
|
21
19
|
|
|
22
20
|
const instance = new Type(registry, value);
|
|
23
|
-
return [Type, instance, instance.
|
|
21
|
+
return [Type, instance, compactAddLength(instance.toU8a())];
|
|
24
22
|
}
|
|
25
23
|
|
|
26
|
-
var _Type = /*#__PURE__*/_classPrivateFieldLooseKey("Type");
|
|
27
|
-
|
|
28
|
-
var _decoded = /*#__PURE__*/_classPrivateFieldLooseKey("decoded");
|
|
29
|
-
|
|
30
24
|
export class WrapperKeepOpaque extends Bytes {
|
|
31
|
-
|
|
25
|
+
#Type;
|
|
26
|
+
#decoded;
|
|
27
|
+
#opaqueName;
|
|
28
|
+
|
|
29
|
+
constructor(registry, typeName, value, opaqueName = 'WrapperKeepOpaque') {
|
|
32
30
|
const [Type, decoded, u8a] = decodeRaw(registry, typeName, value);
|
|
33
31
|
super(registry, u8a);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
});
|
|
38
|
-
Object.defineProperty(this, _decoded, {
|
|
39
|
-
writable: true,
|
|
40
|
-
value: void 0
|
|
41
|
-
});
|
|
42
|
-
_classPrivateFieldLooseBase(this, _Type)[_Type] = Type;
|
|
43
|
-
_classPrivateFieldLooseBase(this, _decoded)[_decoded] = decoded;
|
|
32
|
+
this.#Type = Type;
|
|
33
|
+
this.#decoded = decoded;
|
|
34
|
+
this.#opaqueName = opaqueName;
|
|
44
35
|
}
|
|
45
36
|
|
|
46
37
|
static with(Type) {
|
|
@@ -57,7 +48,7 @@ export class WrapperKeepOpaque extends Bytes {
|
|
|
57
48
|
|
|
58
49
|
|
|
59
50
|
get isDecoded() {
|
|
60
|
-
return !!
|
|
51
|
+
return !!this.#decoded;
|
|
61
52
|
}
|
|
62
53
|
/**
|
|
63
54
|
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
@@ -65,7 +56,7 @@ export class WrapperKeepOpaque extends Bytes {
|
|
|
65
56
|
|
|
66
57
|
|
|
67
58
|
toHuman(isExtended) {
|
|
68
|
-
return
|
|
59
|
+
return this.#decoded ? this.#decoded.toHuman(isExtended) : super.toHuman();
|
|
69
60
|
}
|
|
70
61
|
/**
|
|
71
62
|
* @description Returns the base runtime type name for this instance
|
|
@@ -73,7 +64,7 @@ export class WrapperKeepOpaque extends Bytes {
|
|
|
73
64
|
|
|
74
65
|
|
|
75
66
|
toRawType() {
|
|
76
|
-
return
|
|
67
|
+
return `${this.#opaqueName}<${this.registry.getClassName(this.#Type) || (this.#decoded ? this.#decoded.toRawType() : new this.#Type(this.registry).toRawType())}>`;
|
|
77
68
|
}
|
|
78
69
|
/**
|
|
79
70
|
* @description Converts the Object to to a string (either decoded or bytes)
|
|
@@ -81,7 +72,7 @@ export class WrapperKeepOpaque extends Bytes {
|
|
|
81
72
|
|
|
82
73
|
|
|
83
74
|
toString() {
|
|
84
|
-
return
|
|
75
|
+
return this.#decoded ? this.#decoded.toString() : super.toString();
|
|
85
76
|
}
|
|
86
77
|
/**
|
|
87
78
|
* @description Returns the decoded that the WrapperKeepOpaque represents (if available), throws if non-decodable
|
|
@@ -89,7 +80,7 @@ export class WrapperKeepOpaque extends Bytes {
|
|
|
89
80
|
|
|
90
81
|
|
|
91
82
|
unwrap() {
|
|
92
|
-
return assertReturn(
|
|
83
|
+
return assertReturn(this.#decoded, () => `${this.#opaqueName}: unwrapping an undecodable value`);
|
|
93
84
|
}
|
|
94
85
|
|
|
95
86
|
}
|
|
@@ -5,28 +5,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.WrapperOpaque = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
var _Base = require("../base/Base.cjs");
|
|
11
|
-
|
|
12
|
-
var _index = require("../utils/index.cjs");
|
|
8
|
+
var _WrapperKeepOpaque = require("./WrapperKeepOpaque.cjs");
|
|
13
9
|
|
|
14
10
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
15
11
|
// SPDX-License-Identifier: Apache-2.0
|
|
16
|
-
|
|
17
|
-
|
|
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));
|
|
12
|
+
class WrapperOpaque extends _WrapperKeepOpaque.WrapperKeepOpaque {
|
|
13
|
+
constructor(registry, typeName, value) {
|
|
14
|
+
super(registry, typeName, value, 'WrapperOpaque');
|
|
30
15
|
}
|
|
31
16
|
|
|
32
17
|
static with(Type) {
|
|
@@ -38,21 +23,12 @@ class WrapperOpaque extends _Base.Base {
|
|
|
38
23
|
};
|
|
39
24
|
}
|
|
40
25
|
/**
|
|
41
|
-
* @description
|
|
42
|
-
*/
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
toRawType() {
|
|
46
|
-
return `WrapperOpaque<${this.inner.toRawType()}>`;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* @description The length of the value when encoded as a Uint8Array
|
|
26
|
+
* @description The inner value for this wrapper, in all cases it _should_ be decodable (unlike KeepOpaque)
|
|
50
27
|
*/
|
|
51
28
|
|
|
52
29
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return isBare ? u8a : (0, _util.compactAddLength)(u8a);
|
|
30
|
+
get inner() {
|
|
31
|
+
return this.unwrap();
|
|
56
32
|
}
|
|
57
33
|
|
|
58
34
|
}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import type { Codec, CodecClass, Registry } from '../types';
|
|
2
|
-
import {
|
|
3
|
-
export declare class WrapperOpaque<T extends Codec> extends
|
|
4
|
-
constructor(registry: Registry,
|
|
5
|
-
static with<T extends Codec>(Type: CodecClass<T> | string): CodecClass<
|
|
2
|
+
import { WrapperKeepOpaque } from './WrapperKeepOpaque';
|
|
3
|
+
export declare class WrapperOpaque<T extends Codec> extends WrapperKeepOpaque<T> {
|
|
4
|
+
constructor(registry: Registry, typeName: CodecClass<T> | string, value?: unknown);
|
|
5
|
+
static with<T extends Codec>(Type: CodecClass<T> | string): CodecClass<WrapperKeepOpaque<T>>;
|
|
6
6
|
/**
|
|
7
|
-
* @description
|
|
7
|
+
* @description The inner value for this wrapper, in all cases it _should_ be decodable (unlike KeepOpaque)
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @description The length of the value when encoded as a Uint8Array
|
|
12
|
-
*/
|
|
13
|
-
toU8a(isBare?: boolean): Uint8Array;
|
|
9
|
+
get inner(): T;
|
|
14
10
|
}
|
|
@@ -1,23 +1,9 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
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));
|
|
3
|
+
import { WrapperKeepOpaque } from "./WrapperKeepOpaque.js";
|
|
4
|
+
export class WrapperOpaque extends WrapperKeepOpaque {
|
|
5
|
+
constructor(registry, typeName, value) {
|
|
6
|
+
super(registry, typeName, value, 'WrapperOpaque');
|
|
21
7
|
}
|
|
22
8
|
|
|
23
9
|
static with(Type) {
|
|
@@ -29,21 +15,12 @@ export class WrapperOpaque extends Base {
|
|
|
29
15
|
};
|
|
30
16
|
}
|
|
31
17
|
/**
|
|
32
|
-
* @description
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
toRawType() {
|
|
37
|
-
return `WrapperOpaque<${this.inner.toRawType()}>`;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* @description The length of the value when encoded as a Uint8Array
|
|
18
|
+
* @description The inner value for this wrapper, in all cases it _should_ be decodable (unlike KeepOpaque)
|
|
41
19
|
*/
|
|
42
20
|
|
|
43
21
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return isBare ? u8a : compactAddLength(u8a);
|
|
22
|
+
get inner() {
|
|
23
|
+
return this.unwrap();
|
|
47
24
|
}
|
|
48
25
|
|
|
49
26
|
}
|
package/native/Bool.js
CHANGED
|
@@ -24,8 +24,6 @@ export class bool extends Boolean {
|
|
|
24
24
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
25
25
|
constructor(registry, value = false) {
|
|
26
26
|
super(decodeBool(value));
|
|
27
|
-
this.registry = void 0;
|
|
28
|
-
this.createdAtHash = void 0;
|
|
29
27
|
this.registry = registry;
|
|
30
28
|
}
|
|
31
29
|
/**
|
package/native/Date.js
CHANGED
package/native/Json.js
CHANGED
|
@@ -21,8 +21,6 @@ export class Json extends Map {
|
|
|
21
21
|
constructor(registry, value) {
|
|
22
22
|
const decoded = decodeJson(value);
|
|
23
23
|
super(decoded);
|
|
24
|
-
this.registry = void 0;
|
|
25
|
-
this.createdAtHash = void 0;
|
|
26
24
|
this.registry = registry;
|
|
27
25
|
objectProperties(this, decoded.map(([k]) => k), k => this.get(k));
|
|
28
26
|
}
|
package/native/Raw.js
CHANGED
|
@@ -14,9 +14,6 @@ import { assert, isAscii, isUndefined, isUtf8, u8aToHex, u8aToString, u8aToU8a }
|
|
|
14
14
|
export class Raw extends Uint8Array {
|
|
15
15
|
constructor(registry, value, initialU8aLength) {
|
|
16
16
|
super(u8aToU8a(value));
|
|
17
|
-
this.registry = void 0;
|
|
18
|
-
this.createdAtHash = void 0;
|
|
19
|
-
this.initialU8aLength = void 0;
|
|
20
17
|
this.registry = registry;
|
|
21
18
|
this.initialU8aLength = initialU8aLength;
|
|
22
19
|
}
|
package/native/Set.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import _classPrivateFieldLooseBase from "@babel/runtime/helpers/esm/classPrivateFieldLooseBase";
|
|
2
|
-
import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateFieldLooseKey";
|
|
3
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
4
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
3
|
import { assert, BN, bnToBn, bnToU8a, isBn, isNumber, isString, isU8a, isUndefined, objectProperties, stringify, stringPascalCase, u8aToBn, u8aToHex, u8aToU8a } from '@polkadot/util';
|
|
@@ -76,36 +74,15 @@ function decodeSet(setValues, value = 0, bitLength) {
|
|
|
76
74
|
*/
|
|
77
75
|
|
|
78
76
|
|
|
79
|
-
var _allowed = /*#__PURE__*/_classPrivateFieldLooseKey("allowed");
|
|
80
|
-
|
|
81
|
-
var _byteLength = /*#__PURE__*/_classPrivateFieldLooseKey("byteLength");
|
|
82
|
-
|
|
83
77
|
export class CodecSet extends Set {
|
|
78
|
+
#allowed;
|
|
79
|
+
#byteLength;
|
|
80
|
+
|
|
84
81
|
constructor(registry, setValues, value, bitLength = 8) {
|
|
85
82
|
super(decodeSet(setValues, value, bitLength));
|
|
86
|
-
this.registry = void 0;
|
|
87
|
-
this.createdAtHash = void 0;
|
|
88
|
-
Object.defineProperty(this, _allowed, {
|
|
89
|
-
writable: true,
|
|
90
|
-
value: void 0
|
|
91
|
-
});
|
|
92
|
-
Object.defineProperty(this, _byteLength, {
|
|
93
|
-
writable: true,
|
|
94
|
-
value: void 0
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
this.add = key => {
|
|
98
|
-
// ^^^ add = () property done to assign this instance's this, otherwise Set.add creates "some" chaos
|
|
99
|
-
// we have the isUndefined(this._setValues) in here as well, add is used internally
|
|
100
|
-
// in the Set constructor (so it is undefined at this point, and should allow)
|
|
101
|
-
assert(isUndefined(_classPrivateFieldLooseBase(this, _allowed)[_allowed]) || !isUndefined(_classPrivateFieldLooseBase(this, _allowed)[_allowed][key]), () => `Set: Invalid key '${key}' on add`);
|
|
102
|
-
super.add(key);
|
|
103
|
-
return this;
|
|
104
|
-
};
|
|
105
|
-
|
|
106
83
|
this.registry = registry;
|
|
107
|
-
|
|
108
|
-
|
|
84
|
+
this.#allowed = setValues;
|
|
85
|
+
this.#byteLength = bitLength / 8;
|
|
109
86
|
}
|
|
110
87
|
|
|
111
88
|
static with(values, bitLength) {
|
|
@@ -130,7 +107,7 @@ export class CodecSet extends Set {
|
|
|
130
107
|
|
|
131
108
|
|
|
132
109
|
get encodedLength() {
|
|
133
|
-
return
|
|
110
|
+
return this.#byteLength;
|
|
134
111
|
}
|
|
135
112
|
/**
|
|
136
113
|
* @description returns a hash of the contents
|
|
@@ -162,16 +139,25 @@ export class CodecSet extends Set {
|
|
|
162
139
|
|
|
163
140
|
|
|
164
141
|
get valueEncoded() {
|
|
165
|
-
return encodeSet(
|
|
142
|
+
return encodeSet(this.#allowed, this.strings);
|
|
166
143
|
}
|
|
167
144
|
/**
|
|
168
145
|
* @description adds a value to the Set (extended to allow for validity checking)
|
|
169
146
|
*/
|
|
170
147
|
|
|
171
148
|
|
|
149
|
+
add = key => {
|
|
150
|
+
// ^^^ add = () property done to assign this instance's this, otherwise Set.add creates "some" chaos
|
|
151
|
+
// we have the isUndefined(this._setValues) in here as well, add is used internally
|
|
152
|
+
// in the Set constructor (so it is undefined at this point, and should allow)
|
|
153
|
+
assert(isUndefined(this.#allowed) || !isUndefined(this.#allowed[key]), () => `Set: Invalid key '${key}' on add`);
|
|
154
|
+
super.add(key);
|
|
155
|
+
return this;
|
|
156
|
+
};
|
|
172
157
|
/**
|
|
173
158
|
* @description Compares the value of the input to see if there is a match
|
|
174
159
|
*/
|
|
160
|
+
|
|
175
161
|
eq(other) {
|
|
176
162
|
if (Array.isArray(other)) {
|
|
177
163
|
// we don't actually care about the order, sort the values
|
|
@@ -223,7 +209,7 @@ export class CodecSet extends Set {
|
|
|
223
209
|
|
|
224
210
|
toRawType() {
|
|
225
211
|
return stringify({
|
|
226
|
-
_set:
|
|
212
|
+
_set: this.#allowed
|
|
227
213
|
});
|
|
228
214
|
}
|
|
229
215
|
/**
|
|
@@ -243,7 +229,7 @@ export class CodecSet extends Set {
|
|
|
243
229
|
|
|
244
230
|
toU8a(isBare) {
|
|
245
231
|
return bnToU8a(this.valueEncoded, {
|
|
246
|
-
bitLength:
|
|
232
|
+
bitLength: this.#byteLength * 8,
|
|
247
233
|
isLe: true
|
|
248
234
|
});
|
|
249
235
|
}
|
package/native/Struct.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import _classPrivateFieldLooseBase from "@babel/runtime/helpers/esm/classPrivateFieldLooseBase";
|
|
2
|
-
import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateFieldLooseKey";
|
|
3
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
4
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
3
|
import { assert, isBoolean, isFunction, isHex, isObject, isU8a, isUndefined, objectProperties, stringCamelCase, stringify, u8aConcat, u8aToHex, u8aToU8a } from '@polkadot/util';
|
|
@@ -70,35 +68,19 @@ function decodeStructFromObject(registry, Types, value, jsonMap) {
|
|
|
70
68
|
*/
|
|
71
69
|
|
|
72
70
|
|
|
73
|
-
var _registry = /*#__PURE__*/_classPrivateFieldLooseKey("registry");
|
|
74
|
-
|
|
75
|
-
var _jsonMap = /*#__PURE__*/_classPrivateFieldLooseKey("jsonMap");
|
|
76
|
-
|
|
77
|
-
var _Types = /*#__PURE__*/_classPrivateFieldLooseKey("Types");
|
|
78
|
-
|
|
79
71
|
export class Struct extends Map {
|
|
72
|
+
#registry;
|
|
73
|
+
#jsonMap;
|
|
74
|
+
#Types;
|
|
75
|
+
|
|
80
76
|
constructor(registry, Types, value, jsonMap = new Map()) {
|
|
81
77
|
const typeMap = mapToTypeMap(registry, Types);
|
|
82
78
|
const [decoded, decodedLength] = isU8a(value) ? decodeU8a(registry, value, typeMap, true) : isHex(value) ? decodeU8a(registry, u8aToU8a(value), typeMap, true) : value instanceof Struct ? [value, 0] : decodeStructFromObject(registry, typeMap, value || {}, jsonMap);
|
|
83
79
|
super(decoded);
|
|
84
|
-
|
|
85
|
-
writable: true,
|
|
86
|
-
value: void 0
|
|
87
|
-
});
|
|
88
|
-
this.createdAtHash = void 0;
|
|
89
|
-
this.initialU8aLength = void 0;
|
|
90
|
-
Object.defineProperty(this, _jsonMap, {
|
|
91
|
-
writable: true,
|
|
92
|
-
value: void 0
|
|
93
|
-
});
|
|
94
|
-
Object.defineProperty(this, _Types, {
|
|
95
|
-
writable: true,
|
|
96
|
-
value: void 0
|
|
97
|
-
});
|
|
98
|
-
_classPrivateFieldLooseBase(this, _registry)[_registry] = registry;
|
|
80
|
+
this.#registry = registry;
|
|
99
81
|
this.initialU8aLength = decodedLength;
|
|
100
|
-
|
|
101
|
-
|
|
82
|
+
this.#jsonMap = jsonMap;
|
|
83
|
+
this.#Types = typeMap;
|
|
102
84
|
}
|
|
103
85
|
|
|
104
86
|
static with(Types, jsonMap) {
|
|
@@ -117,7 +99,7 @@ export class Struct extends Map {
|
|
|
117
99
|
|
|
118
100
|
|
|
119
101
|
get defKeys() {
|
|
120
|
-
return Object.keys(
|
|
102
|
+
return Object.keys(this.#Types);
|
|
121
103
|
}
|
|
122
104
|
|
|
123
105
|
getT(key) {
|
|
@@ -144,7 +126,7 @@ export class Struct extends Map {
|
|
|
144
126
|
|
|
145
127
|
get Type() {
|
|
146
128
|
const result = {};
|
|
147
|
-
const defs = Object.entries(
|
|
129
|
+
const defs = Object.entries(this.#Types);
|
|
148
130
|
|
|
149
131
|
for (let i = 0; i < defs.length; i++) {
|
|
150
132
|
const [key, Type] = defs[i];
|
|
@@ -177,7 +159,7 @@ export class Struct extends Map {
|
|
|
177
159
|
}
|
|
178
160
|
|
|
179
161
|
get registry() {
|
|
180
|
-
return
|
|
162
|
+
return this.#registry;
|
|
181
163
|
}
|
|
182
164
|
/**
|
|
183
165
|
* @description Compares the value of the input to see if there is a match
|
|
@@ -243,7 +225,7 @@ export class Struct extends Map {
|
|
|
243
225
|
const json = {};
|
|
244
226
|
|
|
245
227
|
for (const [k, v] of this.entries()) {
|
|
246
|
-
const jsonKey =
|
|
228
|
+
const jsonKey = this.#jsonMap.get(k) || k;
|
|
247
229
|
json[jsonKey] = v && v.toJSON();
|
|
248
230
|
}
|
|
249
231
|
|
|
@@ -255,7 +237,7 @@ export class Struct extends Map {
|
|
|
255
237
|
|
|
256
238
|
|
|
257
239
|
toRawType() {
|
|
258
|
-
return stringify(typesToMap(this.registry,
|
|
240
|
+
return stringify(typesToMap(this.registry, this.#Types));
|
|
259
241
|
}
|
|
260
242
|
/**
|
|
261
243
|
* @description Returns the string representation of the value
|