@polkadot/types-codec 9.11.3 → 9.13.1
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/LICENSE +201 -0
- package/abstract/Array.d.ts +2 -0
- package/abstract/Base.d.ts +14 -3
- package/abstract/Base.js +16 -4
- package/abstract/Int.d.ts +3 -1
- package/abstract/Int.js +13 -9
- package/abstract/Object.d.ts +67 -0
- package/abstract/Object.js +51 -0
- package/base/Compact.d.ts +2 -1
- package/base/DoNotConstruct.d.ts +1 -0
- package/base/Enum.d.ts +2 -1
- package/base/Null.d.ts +2 -1
- package/base/Null.js +0 -1
- package/base/Option.d.ts +1 -0
- package/base/Option.js +1 -1
- package/base/Tuple.d.ts +0 -1
- package/base/Tuple.js +18 -10
- package/base/Vec.d.ts +1 -2
- package/base/Vec.js +21 -8
- package/base/VecFixed.d.ts +0 -1
- package/cjs/abstract/Base.js +16 -4
- package/cjs/abstract/Int.js +12 -8
- package/cjs/abstract/Object.js +58 -0
- package/cjs/base/Null.js +0 -1
- package/cjs/base/Option.js +1 -1
- package/cjs/base/Tuple.js +18 -10
- package/cjs/base/Vec.js +20 -7
- package/cjs/native/Bool.js +1 -0
- package/cjs/native/Date.js +1 -0
- package/cjs/native/Struct.js +6 -14
- package/cjs/packageInfo.js +1 -1
- package/extended/BTreeSet.d.ts +2 -1
- package/extended/Map.d.ts +2 -1
- package/native/Bool.d.ts +2 -0
- package/native/Bool.js +1 -0
- package/native/Date.d.ts +2 -0
- package/native/Date.js +1 -0
- package/native/Float.d.ts +3 -2
- package/native/Json.d.ts +2 -0
- package/native/Raw.d.ts +3 -2
- package/native/Set.d.ts +2 -0
- package/native/Struct.d.ts +3 -2
- package/native/Struct.js +7 -15
- package/native/Text.d.ts +3 -2
- package/package.json +9 -9
- package/packageInfo.js +1 -1
- package/types/codec.d.ts +32 -12
- package/types/helpers.d.ts +9 -1
- package/types/registry.d.ts +4 -3
- package/abstract/BigInt.d.ts +0 -4
- package/abstract/BigInt.js +0 -14
- package/cjs/abstract/BigInt.js +0 -20
package/base/Vec.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright 2017-2023 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { compactFromU8aLim, isU8a, logger, u8aToU8a } from '@polkadot/util';
|
|
4
|
+
import { compactFromU8aLim, isHex, isU8a, logger, stringify, u8aToU8a } from '@polkadot/util';
|
|
5
5
|
import { AbstractArray } from "../abstract/Array.js";
|
|
6
6
|
import { decodeU8aVec, typeToConstructor } from "../utils/index.js";
|
|
7
7
|
const MAX_LENGTH = 64 * 1024;
|
|
@@ -12,13 +12,17 @@ function noopSetDefinition(d) {
|
|
|
12
12
|
function decodeVecLength(value) {
|
|
13
13
|
if (Array.isArray(value)) {
|
|
14
14
|
return [value, value.length, 0];
|
|
15
|
+
} else if (isU8a(value) || isHex(value)) {
|
|
16
|
+
const u8a = u8aToU8a(value);
|
|
17
|
+
const [startAt, length] = compactFromU8aLim(u8a);
|
|
18
|
+
if (length > MAX_LENGTH) {
|
|
19
|
+
throw new Error(`Vec length ${length.toString()} exceeds ${MAX_LENGTH}`);
|
|
20
|
+
}
|
|
21
|
+
return [u8a, length, startAt];
|
|
22
|
+
} else if (!value) {
|
|
23
|
+
return [null, 0, 0];
|
|
15
24
|
}
|
|
16
|
-
|
|
17
|
-
const [startAt, length] = compactFromU8aLim(u8a);
|
|
18
|
-
if (length > MAX_LENGTH) {
|
|
19
|
-
throw new Error(`Vec length ${length.toString()} exceeds ${MAX_LENGTH}`);
|
|
20
|
-
}
|
|
21
|
-
return [u8a, length, startAt];
|
|
25
|
+
throw new Error(`Expected array/hex input to Vec<*> decoding, found ${typeof value}: ${stringify(value)}`);
|
|
22
26
|
}
|
|
23
27
|
export function decodeVec(registry, result, value, startAt, Type) {
|
|
24
28
|
if (Array.isArray(value)) {
|
|
@@ -35,7 +39,11 @@ export function decodeVec(registry, result, value, startAt, Type) {
|
|
|
35
39
|
}
|
|
36
40
|
}
|
|
37
41
|
return [0, 0];
|
|
42
|
+
} else if (!value) {
|
|
43
|
+
return [0, 0];
|
|
38
44
|
}
|
|
45
|
+
|
|
46
|
+
// we don't need more checks, we already limited it via the length decoding
|
|
39
47
|
return decodeU8aVec(registry, result, u8aToU8a(value), startAt, Type);
|
|
40
48
|
}
|
|
41
49
|
|
|
@@ -55,7 +63,12 @@ export class Vec extends AbstractArray {
|
|
|
55
63
|
const [decodeFrom, length, startAt] = decodeVecLength(value);
|
|
56
64
|
super(registry, length);
|
|
57
65
|
this.#Type = definition || setDefinition(typeToConstructor(registry, Type));
|
|
58
|
-
|
|
66
|
+
try {
|
|
67
|
+
this.initialU8aLength = (isU8a(decodeFrom) ? decodeU8aVec(registry, this, decodeFrom, startAt, this.#Type) : decodeVec(registry, this, decodeFrom, startAt, this.#Type))[0];
|
|
68
|
+
} catch (e) {
|
|
69
|
+
console.error(decodeFrom, length, startAt);
|
|
70
|
+
throw e;
|
|
71
|
+
}
|
|
59
72
|
}
|
|
60
73
|
static with(Type) {
|
|
61
74
|
let definition;
|
package/base/VecFixed.d.ts
CHANGED
|
@@ -12,7 +12,6 @@ interface Options<T> {
|
|
|
12
12
|
*/
|
|
13
13
|
export declare class VecFixed<T extends Codec> extends AbstractArray<T> {
|
|
14
14
|
#private;
|
|
15
|
-
readonly initialU8aLength?: number;
|
|
16
15
|
constructor(registry: Registry, Type: CodecClass<T> | string, length: number, value?: Uint8Array | HexString | unknown[], { definition, setDefinition }?: Options<T>);
|
|
17
16
|
static with<O extends Codec>(Type: CodecClass<O> | string, length: number): CodecClass<VecFixed<O>>;
|
|
18
17
|
/**
|
package/cjs/abstract/Base.js
CHANGED
|
@@ -14,8 +14,8 @@ exports.AbstractBase = void 0;
|
|
|
14
14
|
class AbstractBase {
|
|
15
15
|
#raw;
|
|
16
16
|
constructor(registry, value, initialU8aLength) {
|
|
17
|
-
this.#raw = value;
|
|
18
17
|
this.initialU8aLength = initialU8aLength;
|
|
18
|
+
this.#raw = value;
|
|
19
19
|
this.registry = registry;
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -32,6 +32,10 @@ class AbstractBase {
|
|
|
32
32
|
get hash() {
|
|
33
33
|
return this.registry.hash(this.toU8a());
|
|
34
34
|
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @description returns the inner (wrapped value)
|
|
38
|
+
*/
|
|
35
39
|
get inner() {
|
|
36
40
|
return this.#raw;
|
|
37
41
|
}
|
|
@@ -103,11 +107,19 @@ class AbstractBase {
|
|
|
103
107
|
/**
|
|
104
108
|
* @description Returns the base runtime type name for this instance
|
|
105
109
|
*/
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @description Returns the inner wrapped value (equivalent to valueOf)
|
|
113
|
+
*/
|
|
109
114
|
unwrap() {
|
|
110
115
|
return this.#raw;
|
|
111
116
|
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* @description Returns the inner wrapped value
|
|
120
|
+
*/
|
|
121
|
+
valueOf() {
|
|
122
|
+
return this.#raw;
|
|
123
|
+
}
|
|
112
124
|
}
|
|
113
125
|
exports.AbstractBase = AbstractBase;
|
package/cjs/abstract/Int.js
CHANGED
|
@@ -16,6 +16,9 @@ exports.DEFAULT_UINT_BITS = DEFAULT_UINT_BITS;
|
|
|
16
16
|
const MAX_NUMBER_BITS = 52;
|
|
17
17
|
const MUL_P = new _util.BN(10000);
|
|
18
18
|
const FORMATTERS = [['Perquintill', _util.BN_QUINTILL], ['Perbill', _util.BN_BILLION], ['Permill', _util.BN_MILLION], ['Percent', _util.BN_HUNDRED]];
|
|
19
|
+
function isToBn(value) {
|
|
20
|
+
return (0, _util.isFunction)(value.toBn);
|
|
21
|
+
}
|
|
19
22
|
function toPercentage(value, divisor) {
|
|
20
23
|
return `${(value.mul(MUL_P).div(divisor).toNumber() / 100).toFixed(2)}%`;
|
|
21
24
|
}
|
|
@@ -38,9 +41,13 @@ function decodeAbstractInt(value, isNegative) {
|
|
|
38
41
|
throw new Error('String should not contain decimal points or scientific notation');
|
|
39
42
|
}
|
|
40
43
|
return value;
|
|
41
|
-
} else if ((0, _util.isBn)(value)) {
|
|
44
|
+
} else if ((0, _util.isBn)(value) || (0, _util.isBigInt)(value)) {
|
|
42
45
|
return value.toString();
|
|
43
|
-
} else if ((0, _util.isObject)(value)
|
|
46
|
+
} else if ((0, _util.isObject)(value)) {
|
|
47
|
+
if (isToBn(value)) {
|
|
48
|
+
return value.toBn().toString();
|
|
49
|
+
}
|
|
50
|
+
|
|
44
51
|
// Allow the construction from an object with a single top-level key. This means that
|
|
45
52
|
// single key objects can be treated equivalently to numbers, assuming they meet the
|
|
46
53
|
// specific requirements. (This is useful in Weights 1.5 where Objects are compact)
|
|
@@ -48,13 +55,9 @@ function decodeAbstractInt(value, isNegative) {
|
|
|
48
55
|
if (keys.length !== 1) {
|
|
49
56
|
throw new Error('Unable to construct number from multi-key object');
|
|
50
57
|
}
|
|
51
|
-
|
|
52
|
-
if (!(0, _util.isString)(inner) && !(0, _util.isNumber)(inner)) {
|
|
53
|
-
throw new Error('Unable to construct from object with non-string/non-number value');
|
|
54
|
-
}
|
|
55
|
-
return decodeAbstractInt(inner, isNegative);
|
|
58
|
+
return decodeAbstractInt(value[keys[0]], isNegative);
|
|
56
59
|
}
|
|
57
|
-
|
|
60
|
+
throw new Error(`Unable to create BN from unknown type ${typeof value}`);
|
|
58
61
|
}
|
|
59
62
|
|
|
60
63
|
/**
|
|
@@ -82,6 +85,7 @@ class AbstractInt extends _util.BN {
|
|
|
82
85
|
this.registry = registry;
|
|
83
86
|
this.#bitLength = bitLength;
|
|
84
87
|
this.encodedLength = this.#bitLength / 8;
|
|
88
|
+
this.initialU8aLength = this.#bitLength / 8;
|
|
85
89
|
this.isUnsigned = !isSigned;
|
|
86
90
|
const isNegative = this.isNeg();
|
|
87
91
|
const maxBits = bitLength - (isSigned && !isNegative ? 1 : 0);
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.AbstractObject = void 0;
|
|
7
|
+
// Copyright 2017-2023 @polkadot/types-codec authors & contributors
|
|
8
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @name Object
|
|
12
|
+
* @description A type extends the Base class, when it holds a value
|
|
13
|
+
*/
|
|
14
|
+
class AbstractObject {
|
|
15
|
+
constructor(registry, value, initialU8aLength) {
|
|
16
|
+
this.$ = value;
|
|
17
|
+
this.initialU8aLength = initialU8aLength;
|
|
18
|
+
this.registry = registry;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
23
|
+
*/
|
|
24
|
+
get encodedLength() {
|
|
25
|
+
return this.toU8a().length;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @description returns a hash of the contents
|
|
30
|
+
*/
|
|
31
|
+
get hash() {
|
|
32
|
+
return this.registry.hash(this.toU8a());
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @description Checks if the value is an empty value
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @description Returns the string representation of the value
|
|
41
|
+
*/
|
|
42
|
+
toString() {
|
|
43
|
+
return this.$.toString();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
48
|
+
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @description Return the internal value (JS-aligned, same result as $)
|
|
53
|
+
*/
|
|
54
|
+
valueOf() {
|
|
55
|
+
return this.$;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.AbstractObject = AbstractObject;
|
package/cjs/base/Null.js
CHANGED
package/cjs/base/Option.js
CHANGED
package/cjs/base/Tuple.js
CHANGED
|
@@ -16,19 +16,27 @@ function noopSetDefinition(d) {
|
|
|
16
16
|
|
|
17
17
|
/** @internal */
|
|
18
18
|
function decodeTuple(registry, result, value, Classes) {
|
|
19
|
-
if (
|
|
19
|
+
if (Array.isArray(value)) {
|
|
20
|
+
const Types = Classes[0];
|
|
21
|
+
for (let i = 0; i < Types.length; i++) {
|
|
22
|
+
try {
|
|
23
|
+
const entry = value == null ? void 0 : value[i];
|
|
24
|
+
result[i] = entry instanceof Types[i] ? entry : new Types[i](registry, entry);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
throw new Error(`Tuple: failed on ${i}:: ${error.message}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return [result, 0];
|
|
30
|
+
} else if ((0, _util.isHex)(value)) {
|
|
20
31
|
return (0, _utils.decodeU8a)(registry, result, (0, _util.u8aToU8a)(value), Classes);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const entry = value == null ? void 0 : value[i];
|
|
26
|
-
result[i] = entry instanceof Types[i] ? entry : new Types[i](registry, entry);
|
|
27
|
-
} catch (error) {
|
|
28
|
-
throw new Error(`Tuple: failed on ${i}:: ${error.message}`);
|
|
32
|
+
} else if (!value || !result.length) {
|
|
33
|
+
const Types = Classes[0];
|
|
34
|
+
for (let i = 0; i < Types.length; i++) {
|
|
35
|
+
result[i] = new Types[i](registry);
|
|
29
36
|
}
|
|
37
|
+
return [result, 0];
|
|
30
38
|
}
|
|
31
|
-
|
|
39
|
+
throw new Error(`Expected array input to Tuple decoding, found ${typeof value}: ${(0, _util.stringify)(value)}`);
|
|
32
40
|
}
|
|
33
41
|
|
|
34
42
|
/**
|
package/cjs/base/Vec.js
CHANGED
|
@@ -19,13 +19,17 @@ function noopSetDefinition(d) {
|
|
|
19
19
|
function decodeVecLength(value) {
|
|
20
20
|
if (Array.isArray(value)) {
|
|
21
21
|
return [value, value.length, 0];
|
|
22
|
+
} else if ((0, _util.isU8a)(value) || (0, _util.isHex)(value)) {
|
|
23
|
+
const u8a = (0, _util.u8aToU8a)(value);
|
|
24
|
+
const [startAt, length] = (0, _util.compactFromU8aLim)(u8a);
|
|
25
|
+
if (length > MAX_LENGTH) {
|
|
26
|
+
throw new Error(`Vec length ${length.toString()} exceeds ${MAX_LENGTH}`);
|
|
27
|
+
}
|
|
28
|
+
return [u8a, length, startAt];
|
|
29
|
+
} else if (!value) {
|
|
30
|
+
return [null, 0, 0];
|
|
22
31
|
}
|
|
23
|
-
|
|
24
|
-
const [startAt, length] = (0, _util.compactFromU8aLim)(u8a);
|
|
25
|
-
if (length > MAX_LENGTH) {
|
|
26
|
-
throw new Error(`Vec length ${length.toString()} exceeds ${MAX_LENGTH}`);
|
|
27
|
-
}
|
|
28
|
-
return [u8a, length, startAt];
|
|
32
|
+
throw new Error(`Expected array/hex input to Vec<*> decoding, found ${typeof value}: ${(0, _util.stringify)(value)}`);
|
|
29
33
|
}
|
|
30
34
|
function decodeVec(registry, result, value, startAt, Type) {
|
|
31
35
|
if (Array.isArray(value)) {
|
|
@@ -42,7 +46,11 @@ function decodeVec(registry, result, value, startAt, Type) {
|
|
|
42
46
|
}
|
|
43
47
|
}
|
|
44
48
|
return [0, 0];
|
|
49
|
+
} else if (!value) {
|
|
50
|
+
return [0, 0];
|
|
45
51
|
}
|
|
52
|
+
|
|
53
|
+
// we don't need more checks, we already limited it via the length decoding
|
|
46
54
|
return (0, _utils.decodeU8aVec)(registry, result, (0, _util.u8aToU8a)(value), startAt, Type);
|
|
47
55
|
}
|
|
48
56
|
|
|
@@ -64,7 +72,12 @@ class Vec extends _Array.AbstractArray {
|
|
|
64
72
|
const [decodeFrom, length, startAt] = decodeVecLength(value);
|
|
65
73
|
super(registry, length);
|
|
66
74
|
this.#Type = definition || setDefinition((0, _utils.typeToConstructor)(registry, Type));
|
|
67
|
-
|
|
75
|
+
try {
|
|
76
|
+
this.initialU8aLength = ((0, _util.isU8a)(decodeFrom) ? (0, _utils.decodeU8aVec)(registry, this, decodeFrom, startAt, this.#Type) : decodeVec(registry, this, decodeFrom, startAt, this.#Type))[0];
|
|
77
|
+
} catch (e) {
|
|
78
|
+
console.error(decodeFrom, length, startAt);
|
|
79
|
+
throw e;
|
|
80
|
+
}
|
|
68
81
|
}
|
|
69
82
|
static with(Type) {
|
|
70
83
|
let definition;
|
package/cjs/native/Bool.js
CHANGED
|
@@ -15,6 +15,7 @@ var _util = require("@polkadot/util");
|
|
|
15
15
|
* @noInheritDoc
|
|
16
16
|
*/
|
|
17
17
|
class bool extends Boolean {
|
|
18
|
+
initialU8aLength = 1;
|
|
18
19
|
constructor(registry) {
|
|
19
20
|
let value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
20
21
|
super((0, _util.isU8a)(value) ? value[0] === 1 : value instanceof Boolean ? value.valueOf() : !!value);
|
package/cjs/native/Date.js
CHANGED
|
@@ -35,6 +35,7 @@ function decodeDate(value) {
|
|
|
35
35
|
* @noInheritDoc
|
|
36
36
|
*/
|
|
37
37
|
class CodecDate extends Date {
|
|
38
|
+
initialU8aLength = BITLENGTH / 8;
|
|
38
39
|
constructor(registry) {
|
|
39
40
|
let value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
40
41
|
super(decodeDate(value));
|
package/cjs/native/Struct.js
CHANGED
|
@@ -222,7 +222,7 @@ class Struct extends Map {
|
|
|
222
222
|
toHuman(isExtended) {
|
|
223
223
|
const json = {};
|
|
224
224
|
for (const [k, v] of this.entries()) {
|
|
225
|
-
json[k] = v
|
|
225
|
+
json[k] = v.toHuman(isExtended);
|
|
226
226
|
}
|
|
227
227
|
return json;
|
|
228
228
|
}
|
|
@@ -233,11 +233,9 @@ class Struct extends Map {
|
|
|
233
233
|
toJSON() {
|
|
234
234
|
const json = {};
|
|
235
235
|
for (const [k, v] of this.entries()) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
// means that the Vec may be partially populated (same applies to toHuman, same check)
|
|
240
|
-
json[jsonKey] = v && v.toJSON();
|
|
236
|
+
// Here we pull out the entry against the JSON mapping (if supplied)
|
|
237
|
+
// since this representation goes over RPC and needs to be correct
|
|
238
|
+
json[this.#jsonMap.get(k) || k] = v.toJSON();
|
|
241
239
|
}
|
|
242
240
|
return json;
|
|
243
241
|
}
|
|
@@ -248,11 +246,7 @@ class Struct extends Map {
|
|
|
248
246
|
toPrimitive() {
|
|
249
247
|
const json = {};
|
|
250
248
|
for (const [k, v] of this.entries()) {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
// We actually log inside the U8a decoding and use JSON.stringify(...), which
|
|
254
|
-
// means that the Vec may be partially populated (same applies to toHuman, same check)
|
|
255
|
-
json[jsonKey] = v && v.toPrimitive();
|
|
249
|
+
json[k] = v.toPrimitive();
|
|
256
250
|
}
|
|
257
251
|
return json;
|
|
258
252
|
}
|
|
@@ -278,9 +272,7 @@ class Struct extends Map {
|
|
|
278
272
|
toU8a(isBare) {
|
|
279
273
|
const encoded = [];
|
|
280
274
|
for (const [k, v] of this.entries()) {
|
|
281
|
-
|
|
282
|
-
encoded.push(v.toU8a(!isBare || (0, _util.isBoolean)(isBare) ? isBare : isBare[k]));
|
|
283
|
-
}
|
|
275
|
+
encoded.push(v.toU8a(!isBare || (0, _util.isBoolean)(isBare) ? isBare : isBare[k]));
|
|
284
276
|
}
|
|
285
277
|
return (0, _util.u8aConcatStrict)(encoded);
|
|
286
278
|
}
|
package/cjs/packageInfo.js
CHANGED
package/extended/BTreeSet.d.ts
CHANGED
|
@@ -4,7 +4,8 @@ export declare class BTreeSet<V extends Codec = Codec> extends Set<V> implements
|
|
|
4
4
|
#private;
|
|
5
5
|
readonly registry: Registry;
|
|
6
6
|
createdAtHash?: IU8a;
|
|
7
|
-
|
|
7
|
+
initialU8aLength?: number;
|
|
8
|
+
isStorageFallback?: boolean;
|
|
8
9
|
constructor(registry: Registry, valType: CodecClass<V> | string, rawValue?: Uint8Array | string | string[] | Set<any>);
|
|
9
10
|
static with<V extends Codec>(valType: CodecClass<V> | string): CodecClass<BTreeSet<V>>;
|
|
10
11
|
/**
|
package/extended/Map.d.ts
CHANGED
|
@@ -4,7 +4,8 @@ export declare class CodecMap<K extends Codec = Codec, V extends Codec = Codec>
|
|
|
4
4
|
#private;
|
|
5
5
|
readonly registry: Registry;
|
|
6
6
|
createdAtHash?: IU8a;
|
|
7
|
-
|
|
7
|
+
initialU8aLength?: number;
|
|
8
|
+
isStorageFallback?: boolean;
|
|
8
9
|
constructor(registry: Registry, keyType: CodecClass<K> | string, valType: CodecClass<V> | string, rawValue: Uint8Array | string | Map<any, any> | undefined, type?: 'BTreeMap' | 'HashMap');
|
|
9
10
|
/**
|
|
10
11
|
* @description The length of the value when encoded as a Uint8Array
|
package/native/Bool.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ import type { AnyBool, Codec, Inspect, IU8a, Registry } from '../types';
|
|
|
9
9
|
export declare class bool extends Boolean implements Codec {
|
|
10
10
|
readonly registry: Registry;
|
|
11
11
|
createdAtHash?: IU8a;
|
|
12
|
+
initialU8aLength: number;
|
|
13
|
+
isStorageFallback?: boolean;
|
|
12
14
|
constructor(registry: Registry, value?: bool | AnyBool | Uint8Array | number);
|
|
13
15
|
/**
|
|
14
16
|
* @description The length of the value when encoded as a Uint8Array
|
package/native/Bool.js
CHANGED
|
@@ -10,6 +10,7 @@ import { isU8a, u8aToHex } from '@polkadot/util';
|
|
|
10
10
|
* @noInheritDoc
|
|
11
11
|
*/
|
|
12
12
|
export class bool extends Boolean {
|
|
13
|
+
initialU8aLength = 1;
|
|
13
14
|
constructor(registry, value = false) {
|
|
14
15
|
super(isU8a(value) ? value[0] === 1 : value instanceof Boolean ? value.valueOf() : !!value);
|
|
15
16
|
this.registry = registry;
|
package/native/Date.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ import { BN } from '@polkadot/util';
|
|
|
15
15
|
export declare class CodecDate extends Date implements INumber {
|
|
16
16
|
readonly registry: Registry;
|
|
17
17
|
createdAtHash?: IU8a;
|
|
18
|
+
initialU8aLength: number;
|
|
19
|
+
isStorageFallback?: boolean;
|
|
18
20
|
constructor(registry: Registry, value?: CodecDate | Date | AnyNumber);
|
|
19
21
|
/**
|
|
20
22
|
* @description The length of the value when encoded as a Uint8Array
|
package/native/Date.js
CHANGED
package/native/Float.d.ts
CHANGED
|
@@ -13,10 +13,11 @@ interface Options {
|
|
|
13
13
|
*/
|
|
14
14
|
export declare class Float extends Number implements IFloat {
|
|
15
15
|
#private;
|
|
16
|
-
createdAtHash?: IU8a;
|
|
17
16
|
readonly encodedLength: number;
|
|
18
|
-
readonly initialU8aLength?: number;
|
|
19
17
|
readonly registry: Registry;
|
|
18
|
+
createdAtHash?: IU8a;
|
|
19
|
+
initialU8aLength?: number;
|
|
20
|
+
isStorageFallback?: boolean;
|
|
20
21
|
constructor(registry: Registry, value?: AnyFloat, { bitLength }?: Options);
|
|
21
22
|
static with(bitLength: 32 | 64): CodecClass<Float>;
|
|
22
23
|
/**
|
package/native/Json.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ import type { AnyJson, Codec, Inspect, IU8a, Registry } from '../types';
|
|
|
11
11
|
export declare class Json extends Map<string, any> implements Codec {
|
|
12
12
|
readonly registry: Registry;
|
|
13
13
|
createdAtHash?: IU8a;
|
|
14
|
+
initialU8aLength?: number;
|
|
15
|
+
isStorageFallback?: boolean;
|
|
14
16
|
constructor(registry: Registry, value?: Record<string, unknown> | null);
|
|
15
17
|
/**
|
|
16
18
|
* @description Always 0, never encodes as a Uint8Array
|
package/native/Raw.d.ts
CHANGED
|
@@ -10,9 +10,10 @@ import type { AnyJson, AnyU8a, Inspect, IU8a, Registry } from '../types';
|
|
|
10
10
|
* @noInheritDoc
|
|
11
11
|
*/
|
|
12
12
|
export declare class Raw extends Uint8Array implements IU8a {
|
|
13
|
-
createdAtHash?: IU8a;
|
|
14
|
-
readonly initialU8aLength?: number;
|
|
15
13
|
readonly registry: Registry;
|
|
14
|
+
createdAtHash?: IU8a;
|
|
15
|
+
initialU8aLength?: number;
|
|
16
|
+
isStorageFallback?: boolean;
|
|
16
17
|
/**
|
|
17
18
|
* @description This ensures that operators such as clice, filter, map, etc. return
|
|
18
19
|
* new Array instances (without this we need to apply overrides)
|
package/native/Set.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ export declare class CodecSet extends Set<string> implements ISet<string> {
|
|
|
13
13
|
#private;
|
|
14
14
|
readonly registry: Registry;
|
|
15
15
|
createdAtHash?: IU8a;
|
|
16
|
+
initialU8aLength?: number;
|
|
17
|
+
isStorageFallback?: boolean;
|
|
16
18
|
constructor(registry: Registry, setValues: SetValues, value?: string[] | Set<string> | Uint8Array | BN | number | string, bitLength?: number);
|
|
17
19
|
static with(values: SetValues, bitLength?: number): CodecClass<CodecSet>;
|
|
18
20
|
/**
|
package/native/Struct.d.ts
CHANGED
|
@@ -26,9 +26,10 @@ export declare class Struct<S extends TypesDef = TypesDef, V extends {
|
|
|
26
26
|
[K in keyof S]: string;
|
|
27
27
|
}> extends Map<keyof S, Codec> implements IStruct<keyof S> {
|
|
28
28
|
#private;
|
|
29
|
-
createdAtHash?: IU8a;
|
|
30
|
-
readonly initialU8aLength?: number;
|
|
31
29
|
readonly registry: Registry;
|
|
30
|
+
createdAtHash?: IU8a;
|
|
31
|
+
initialU8aLength?: number;
|
|
32
|
+
isStorageFallback?: boolean;
|
|
32
33
|
constructor(registry: Registry, Types: S, value?: V | Map<unknown, unknown> | unknown[] | HexString | null, jsonMap?: Map<string, string>, { definition, setDefinition }?: Options);
|
|
33
34
|
static with<S extends TypesDef>(Types: S, jsonMap?: Map<string, string>): CodecClass<Struct<S>>;
|
|
34
35
|
/**
|
package/native/Struct.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright 2017-2023 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { isBoolean,
|
|
4
|
+
import { isBoolean, isHex, isObject, isU8a, isUndefined, objectProperties, stringCamelCase, stringify, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util';
|
|
5
5
|
import { compareMap, decodeU8aStruct, mapToTypeMap, typesToMap } from "../utils/index.js";
|
|
6
6
|
function noopSetDefinition(d) {
|
|
7
7
|
return d;
|
|
@@ -213,7 +213,7 @@ export class Struct extends Map {
|
|
|
213
213
|
toHuman(isExtended) {
|
|
214
214
|
const json = {};
|
|
215
215
|
for (const [k, v] of this.entries()) {
|
|
216
|
-
json[k] = v
|
|
216
|
+
json[k] = v.toHuman(isExtended);
|
|
217
217
|
}
|
|
218
218
|
return json;
|
|
219
219
|
}
|
|
@@ -224,11 +224,9 @@ export class Struct extends Map {
|
|
|
224
224
|
toJSON() {
|
|
225
225
|
const json = {};
|
|
226
226
|
for (const [k, v] of this.entries()) {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
// means that the Vec may be partially populated (same applies to toHuman, same check)
|
|
231
|
-
json[jsonKey] = v && v.toJSON();
|
|
227
|
+
// Here we pull out the entry against the JSON mapping (if supplied)
|
|
228
|
+
// since this representation goes over RPC and needs to be correct
|
|
229
|
+
json[this.#jsonMap.get(k) || k] = v.toJSON();
|
|
232
230
|
}
|
|
233
231
|
return json;
|
|
234
232
|
}
|
|
@@ -239,11 +237,7 @@ export class Struct extends Map {
|
|
|
239
237
|
toPrimitive() {
|
|
240
238
|
const json = {};
|
|
241
239
|
for (const [k, v] of this.entries()) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
// We actually log inside the U8a decoding and use JSON.stringify(...), which
|
|
245
|
-
// means that the Vec may be partially populated (same applies to toHuman, same check)
|
|
246
|
-
json[jsonKey] = v && v.toPrimitive();
|
|
240
|
+
json[k] = v.toPrimitive();
|
|
247
241
|
}
|
|
248
242
|
return json;
|
|
249
243
|
}
|
|
@@ -269,9 +263,7 @@ export class Struct extends Map {
|
|
|
269
263
|
toU8a(isBare) {
|
|
270
264
|
const encoded = [];
|
|
271
265
|
for (const [k, v] of this.entries()) {
|
|
272
|
-
|
|
273
|
-
encoded.push(v.toU8a(!isBare || isBoolean(isBare) ? isBare : isBare[k]));
|
|
274
|
-
}
|
|
266
|
+
encoded.push(v.toU8a(!isBare || isBoolean(isBare) ? isBare : isBare[k]));
|
|
275
267
|
}
|
|
276
268
|
return u8aConcatStrict(encoded);
|
|
277
269
|
}
|
package/native/Text.d.ts
CHANGED
|
@@ -10,9 +10,10 @@ import type { AnyString, AnyU8a, Inspect, IText, IU8a, Registry } from '../types
|
|
|
10
10
|
*/
|
|
11
11
|
export declare class Text extends String implements IText {
|
|
12
12
|
#private;
|
|
13
|
-
createdAtHash?: IU8a;
|
|
14
|
-
readonly initialU8aLength?: number;
|
|
15
13
|
readonly registry: Registry;
|
|
14
|
+
createdAtHash?: IU8a;
|
|
15
|
+
initialU8aLength?: number;
|
|
16
|
+
isStorageFallback?: boolean;
|
|
16
17
|
constructor(registry: Registry, value?: null | AnyString | AnyU8a | {
|
|
17
18
|
toString: () => string;
|
|
18
19
|
});
|
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"./cjs/detectPackage.js"
|
|
21
21
|
],
|
|
22
22
|
"type": "module",
|
|
23
|
-
"version": "9.
|
|
23
|
+
"version": "9.13.1",
|
|
24
24
|
"main": "./cjs/index.js",
|
|
25
25
|
"module": "./index.js",
|
|
26
26
|
"types": "./index.d.ts",
|
|
@@ -47,16 +47,16 @@
|
|
|
47
47
|
"require": "./cjs/abstract/Base.js",
|
|
48
48
|
"default": "./abstract/Base.js"
|
|
49
49
|
},
|
|
50
|
-
"./abstract/BigInt": {
|
|
51
|
-
"types": "./abstract/BigInt.d.ts",
|
|
52
|
-
"require": "./cjs/abstract/BigInt.js",
|
|
53
|
-
"default": "./abstract/BigInt.js"
|
|
54
|
-
},
|
|
55
50
|
"./abstract/Int": {
|
|
56
51
|
"types": "./abstract/Int.d.ts",
|
|
57
52
|
"require": "./cjs/abstract/Int.js",
|
|
58
53
|
"default": "./abstract/Int.js"
|
|
59
54
|
},
|
|
55
|
+
"./abstract/Object": {
|
|
56
|
+
"types": "./abstract/Object.d.ts",
|
|
57
|
+
"require": "./cjs/abstract/Object.js",
|
|
58
|
+
"default": "./abstract/Object.js"
|
|
59
|
+
},
|
|
60
60
|
"./base": {
|
|
61
61
|
"types": "./base/index.d.ts",
|
|
62
62
|
"require": "./cjs/base/index.js",
|
|
@@ -434,8 +434,8 @@
|
|
|
434
434
|
}
|
|
435
435
|
},
|
|
436
436
|
"dependencies": {
|
|
437
|
-
"@babel/runtime": "^7.20.
|
|
438
|
-
"@polkadot/util": "^10.
|
|
439
|
-
"@polkadot/x-bigint": "^10.
|
|
437
|
+
"@babel/runtime": "^7.20.13",
|
|
438
|
+
"@polkadot/util": "^10.3.1",
|
|
439
|
+
"@polkadot/x-bigint": "^10.3.1"
|
|
440
440
|
}
|
|
441
441
|
}
|
package/packageInfo.js
CHANGED
|
@@ -7,5 +7,5 @@ export const packageInfo = {
|
|
|
7
7
|
name: '@polkadot/types-codec',
|
|
8
8
|
path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
|
|
9
9
|
type: 'esm',
|
|
10
|
-
version: '9.
|
|
10
|
+
version: '9.13.1'
|
|
11
11
|
};
|