@polkadot/types-codec 7.5.1 → 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/extended/WrapperKeepOpaque.cjs +11 -3
- package/extended/WrapperKeepOpaque.d.ts +4 -2
- package/extended/WrapperKeepOpaque.js +7 -5
- package/extended/WrapperOpaque.cjs +7 -31
- package/extended/WrapperOpaque.d.ts +6 -10
- package/extended/WrapperOpaque.js +7 -30
- package/package.json +1 -1
- package/packageInfo.cjs +1 -1
- package/packageInfo.js +1 -1
|
@@ -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,6 +1,6 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { assertReturn, compactStripLength, isHex, isU8a } from '@polkadot/util';
|
|
3
|
+
import { assertReturn, compactAddLength, compactStripLength, isHex, isU8a } from '@polkadot/util';
|
|
4
4
|
import { Raw } from "../native/Raw.js";
|
|
5
5
|
import { typeToConstructor } from "../utils/index.js";
|
|
6
6
|
import { Bytes } from "./Bytes.js";
|
|
@@ -18,18 +18,20 @@ function decodeRaw(registry, typeName, value) {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
const instance = new Type(registry, value);
|
|
21
|
-
return [Type, instance, instance.
|
|
21
|
+
return [Type, instance, compactAddLength(instance.toU8a())];
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
export class WrapperKeepOpaque extends Bytes {
|
|
25
25
|
#Type;
|
|
26
26
|
#decoded;
|
|
27
|
+
#opaqueName;
|
|
27
28
|
|
|
28
|
-
constructor(registry, typeName, value) {
|
|
29
|
+
constructor(registry, typeName, value, opaqueName = 'WrapperKeepOpaque') {
|
|
29
30
|
const [Type, decoded, u8a] = decodeRaw(registry, typeName, value);
|
|
30
31
|
super(registry, u8a);
|
|
31
32
|
this.#Type = Type;
|
|
32
33
|
this.#decoded = decoded;
|
|
34
|
+
this.#opaqueName = opaqueName;
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
static with(Type) {
|
|
@@ -62,7 +64,7 @@ export class WrapperKeepOpaque extends Bytes {
|
|
|
62
64
|
|
|
63
65
|
|
|
64
66
|
toRawType() {
|
|
65
|
-
return
|
|
67
|
+
return `${this.#opaqueName}<${this.registry.getClassName(this.#Type) || (this.#decoded ? this.#decoded.toRawType() : new this.#Type(this.registry).toRawType())}>`;
|
|
66
68
|
}
|
|
67
69
|
/**
|
|
68
70
|
* @description Converts the Object to to a string (either decoded or bytes)
|
|
@@ -78,7 +80,7 @@ export class WrapperKeepOpaque extends Bytes {
|
|
|
78
80
|
|
|
79
81
|
|
|
80
82
|
unwrap() {
|
|
81
|
-
return assertReturn(this.#decoded,
|
|
83
|
+
return assertReturn(this.#decoded, () => `${this.#opaqueName}: unwrapping an undecodable value`);
|
|
82
84
|
}
|
|
83
85
|
|
|
84
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/package.json
CHANGED
package/packageInfo.cjs
CHANGED
package/packageInfo.js
CHANGED