@polkadot/types-codec 6.12.2-4 → 6.12.2-8
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/base/Base.cjs +11 -2
- package/base/Base.d.ts +1 -1
- package/base/Base.js +11 -2
- package/native/Json.cjs +4 -0
- package/native/Json.d.ts +1 -0
- package/native/Json.js +4 -0
- package/native/Struct.cjs +15 -2
- package/native/Struct.d.ts +2 -1
- package/native/Struct.js +15 -2
- package/package.json +1 -1
- package/packageInfo.cjs +1 -1
- package/packageInfo.js +1 -1
- package/types/interfaces.d.ts +2 -1
- package/types/registry.d.ts +19 -2
package/base/Base.cjs
CHANGED
|
@@ -11,6 +11,8 @@ var _classPrivateFieldLooseBase2 = _interopRequireDefault(require("@babel/runtim
|
|
|
11
11
|
|
|
12
12
|
var _classPrivateFieldLooseKey2 = _interopRequireDefault(require("@babel/runtime/helpers/classPrivateFieldLooseKey"));
|
|
13
13
|
|
|
14
|
+
var _registry = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("registry");
|
|
15
|
+
|
|
14
16
|
var _raw = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("raw");
|
|
15
17
|
|
|
16
18
|
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
@@ -22,14 +24,17 @@ var _raw = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("raw");
|
|
|
22
24
|
*/
|
|
23
25
|
class Base {
|
|
24
26
|
constructor(registry, value, initialU8aLength) {
|
|
25
|
-
this
|
|
27
|
+
Object.defineProperty(this, _registry, {
|
|
28
|
+
writable: true,
|
|
29
|
+
value: void 0
|
|
30
|
+
});
|
|
26
31
|
this.createdAtHash = void 0;
|
|
27
32
|
this.initialU8aLength = void 0;
|
|
28
33
|
Object.defineProperty(this, _raw, {
|
|
29
34
|
writable: true,
|
|
30
35
|
value: void 0
|
|
31
36
|
});
|
|
32
|
-
this
|
|
37
|
+
(0, _classPrivateFieldLooseBase2.default)(this, _registry)[_registry] = registry;
|
|
33
38
|
(0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw] = value;
|
|
34
39
|
this.initialU8aLength = initialU8aLength;
|
|
35
40
|
}
|
|
@@ -61,6 +66,10 @@ class Base {
|
|
|
61
66
|
get isEmpty() {
|
|
62
67
|
return (0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw].isEmpty;
|
|
63
68
|
}
|
|
69
|
+
|
|
70
|
+
get registry() {
|
|
71
|
+
return (0, _classPrivateFieldLooseBase2.default)(this, _registry)[_registry];
|
|
72
|
+
}
|
|
64
73
|
/**
|
|
65
74
|
* @description Compares the value of the input to see if there is a match
|
|
66
75
|
*/
|
package/base/Base.d.ts
CHANGED
|
@@ -6,7 +6,6 @@ import type { AnyJson, BareOpts, Codec, CodecRegistry, IU8a } from '../types';
|
|
|
6
6
|
*/
|
|
7
7
|
export declare abstract class Base<T extends Codec> implements Codec {
|
|
8
8
|
#private;
|
|
9
|
-
readonly registry: CodecRegistry;
|
|
10
9
|
createdAtHash?: IU8a;
|
|
11
10
|
readonly initialU8aLength?: number;
|
|
12
11
|
protected constructor(registry: CodecRegistry, value: T, initialU8aLength?: number);
|
|
@@ -23,6 +22,7 @@ export declare abstract class Base<T extends Codec> implements Codec {
|
|
|
23
22
|
* @description Checks if the value is an empty value
|
|
24
23
|
*/
|
|
25
24
|
get isEmpty(): boolean;
|
|
25
|
+
get registry(): CodecRegistry;
|
|
26
26
|
/**
|
|
27
27
|
* @description Compares the value of the input to see if there is a match
|
|
28
28
|
*/
|
package/base/Base.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import _classPrivateFieldLooseBase from "@babel/runtime/helpers/esm/classPrivateFieldLooseBase";
|
|
2
2
|
import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateFieldLooseKey";
|
|
3
3
|
|
|
4
|
+
var _registry = /*#__PURE__*/_classPrivateFieldLooseKey("registry");
|
|
5
|
+
|
|
4
6
|
var _raw = /*#__PURE__*/_classPrivateFieldLooseKey("raw");
|
|
5
7
|
|
|
6
8
|
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
@@ -12,14 +14,17 @@ var _raw = /*#__PURE__*/_classPrivateFieldLooseKey("raw");
|
|
|
12
14
|
*/
|
|
13
15
|
export class Base {
|
|
14
16
|
constructor(registry, value, initialU8aLength) {
|
|
15
|
-
this
|
|
17
|
+
Object.defineProperty(this, _registry, {
|
|
18
|
+
writable: true,
|
|
19
|
+
value: void 0
|
|
20
|
+
});
|
|
16
21
|
this.createdAtHash = void 0;
|
|
17
22
|
this.initialU8aLength = void 0;
|
|
18
23
|
Object.defineProperty(this, _raw, {
|
|
19
24
|
writable: true,
|
|
20
25
|
value: void 0
|
|
21
26
|
});
|
|
22
|
-
this
|
|
27
|
+
_classPrivateFieldLooseBase(this, _registry)[_registry] = registry;
|
|
23
28
|
_classPrivateFieldLooseBase(this, _raw)[_raw] = value;
|
|
24
29
|
this.initialU8aLength = initialU8aLength;
|
|
25
30
|
}
|
|
@@ -51,6 +56,10 @@ export class Base {
|
|
|
51
56
|
get isEmpty() {
|
|
52
57
|
return _classPrivateFieldLooseBase(this, _raw)[_raw].isEmpty;
|
|
53
58
|
}
|
|
59
|
+
|
|
60
|
+
get registry() {
|
|
61
|
+
return _classPrivateFieldLooseBase(this, _registry)[_registry];
|
|
62
|
+
}
|
|
54
63
|
/**
|
|
55
64
|
* @description Compares the value of the input to see if there is a match
|
|
56
65
|
*/
|
package/native/Json.cjs
CHANGED
package/native/Json.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export declare class Json extends Map<string, any> implements Codec {
|
|
|
28
28
|
* @description Compares the value of the input to see if there is a match
|
|
29
29
|
*/
|
|
30
30
|
eq(other?: unknown): boolean;
|
|
31
|
+
getT<T>(key: string): T;
|
|
31
32
|
/**
|
|
32
33
|
* @description Unimplemented, will throw
|
|
33
34
|
*/
|
package/native/Json.js
CHANGED
package/native/Struct.cjs
CHANGED
|
@@ -83,6 +83,8 @@ function decodeStructFromObject(registry, Types, value, jsonMap) {
|
|
|
83
83
|
*/
|
|
84
84
|
|
|
85
85
|
|
|
86
|
+
var _registry = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("registry");
|
|
87
|
+
|
|
86
88
|
var _jsonMap = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("jsonMap");
|
|
87
89
|
|
|
88
90
|
var _Types = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("Types");
|
|
@@ -93,7 +95,10 @@ class Struct extends Map {
|
|
|
93
95
|
const typeMap = (0, _index.mapToTypeMap)(registry, Types);
|
|
94
96
|
const [decoded, decodedLength] = (0, _util.isU8a)(value) ? (0, _index.decodeU8a)(registry, value, typeMap, true) : (0, _util.isHex)(value) ? (0, _index.decodeU8a)(registry, (0, _util.u8aToU8a)(value), typeMap, true) : value instanceof Struct ? [value, 0] : decodeStructFromObject(registry, typeMap, value || {}, jsonMap);
|
|
95
97
|
super(decoded);
|
|
96
|
-
this
|
|
98
|
+
Object.defineProperty(this, _registry, {
|
|
99
|
+
writable: true,
|
|
100
|
+
value: void 0
|
|
101
|
+
});
|
|
97
102
|
this.createdAtHash = void 0;
|
|
98
103
|
this.initialU8aLength = void 0;
|
|
99
104
|
Object.defineProperty(this, _jsonMap, {
|
|
@@ -104,7 +109,7 @@ class Struct extends Map {
|
|
|
104
109
|
writable: true,
|
|
105
110
|
value: void 0
|
|
106
111
|
});
|
|
107
|
-
this
|
|
112
|
+
(0, _classPrivateFieldLooseBase2.default)(this, _registry)[_registry] = registry;
|
|
108
113
|
this.initialU8aLength = decodedLength;
|
|
109
114
|
(0, _classPrivateFieldLooseBase2.default)(this, _jsonMap)[_jsonMap] = jsonMap;
|
|
110
115
|
(0, _classPrivateFieldLooseBase2.default)(this, _Types)[_Types] = typeMap;
|
|
@@ -128,6 +133,10 @@ class Struct extends Map {
|
|
|
128
133
|
get defKeys() {
|
|
129
134
|
return Object.keys((0, _classPrivateFieldLooseBase2.default)(this, _Types)[_Types]);
|
|
130
135
|
}
|
|
136
|
+
|
|
137
|
+
getT(key) {
|
|
138
|
+
return this.get(key);
|
|
139
|
+
}
|
|
131
140
|
/**
|
|
132
141
|
* @description Checks if the value is an empty value
|
|
133
142
|
*/
|
|
@@ -180,6 +189,10 @@ class Struct extends Map {
|
|
|
180
189
|
get hash() {
|
|
181
190
|
return this.registry.hash(this.toU8a());
|
|
182
191
|
}
|
|
192
|
+
|
|
193
|
+
get registry() {
|
|
194
|
+
return (0, _classPrivateFieldLooseBase2.default)(this, _registry)[_registry];
|
|
195
|
+
}
|
|
183
196
|
/**
|
|
184
197
|
* @description Compares the value of the input to see if there is a match
|
|
185
198
|
*/
|
package/native/Struct.d.ts
CHANGED
|
@@ -21,7 +21,6 @@ export declare class Struct<S extends TypesDef = TypesDef, V extends {
|
|
|
21
21
|
[K in keyof S]: string;
|
|
22
22
|
}> extends Map<keyof S, Codec> implements IStruct<keyof S> {
|
|
23
23
|
#private;
|
|
24
|
-
readonly registry: CodecRegistry;
|
|
25
24
|
createdAtHash?: IU8a;
|
|
26
25
|
readonly initialU8aLength?: number;
|
|
27
26
|
constructor(registry: CodecRegistry, Types: S, value?: V | Map<unknown, unknown> | unknown[] | HexString | null, jsonMap?: Map<string, string>);
|
|
@@ -30,6 +29,7 @@ export declare class Struct<S extends TypesDef = TypesDef, V extends {
|
|
|
30
29
|
* @description The available keys for this struct
|
|
31
30
|
*/
|
|
32
31
|
get defKeys(): string[];
|
|
32
|
+
getT<T>(key: string): T;
|
|
33
33
|
/**
|
|
34
34
|
* @description Checks if the value is an empty value
|
|
35
35
|
*/
|
|
@@ -46,6 +46,7 @@ export declare class Struct<S extends TypesDef = TypesDef, V extends {
|
|
|
46
46
|
* @description returns a hash of the contents
|
|
47
47
|
*/
|
|
48
48
|
get hash(): IU8a;
|
|
49
|
+
get registry(): CodecRegistry;
|
|
49
50
|
/**
|
|
50
51
|
* @description Compares the value of the input to see if there is a match
|
|
51
52
|
*/
|
package/native/Struct.js
CHANGED
|
@@ -70,6 +70,8 @@ function decodeStructFromObject(registry, Types, value, jsonMap) {
|
|
|
70
70
|
*/
|
|
71
71
|
|
|
72
72
|
|
|
73
|
+
var _registry = /*#__PURE__*/_classPrivateFieldLooseKey("registry");
|
|
74
|
+
|
|
73
75
|
var _jsonMap = /*#__PURE__*/_classPrivateFieldLooseKey("jsonMap");
|
|
74
76
|
|
|
75
77
|
var _Types = /*#__PURE__*/_classPrivateFieldLooseKey("Types");
|
|
@@ -79,7 +81,10 @@ export class Struct extends Map {
|
|
|
79
81
|
const typeMap = mapToTypeMap(registry, Types);
|
|
80
82
|
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);
|
|
81
83
|
super(decoded);
|
|
82
|
-
this
|
|
84
|
+
Object.defineProperty(this, _registry, {
|
|
85
|
+
writable: true,
|
|
86
|
+
value: void 0
|
|
87
|
+
});
|
|
83
88
|
this.createdAtHash = void 0;
|
|
84
89
|
this.initialU8aLength = void 0;
|
|
85
90
|
Object.defineProperty(this, _jsonMap, {
|
|
@@ -90,7 +95,7 @@ export class Struct extends Map {
|
|
|
90
95
|
writable: true,
|
|
91
96
|
value: void 0
|
|
92
97
|
});
|
|
93
|
-
this
|
|
98
|
+
_classPrivateFieldLooseBase(this, _registry)[_registry] = registry;
|
|
94
99
|
this.initialU8aLength = decodedLength;
|
|
95
100
|
_classPrivateFieldLooseBase(this, _jsonMap)[_jsonMap] = jsonMap;
|
|
96
101
|
_classPrivateFieldLooseBase(this, _Types)[_Types] = typeMap;
|
|
@@ -114,6 +119,10 @@ export class Struct extends Map {
|
|
|
114
119
|
get defKeys() {
|
|
115
120
|
return Object.keys(_classPrivateFieldLooseBase(this, _Types)[_Types]);
|
|
116
121
|
}
|
|
122
|
+
|
|
123
|
+
getT(key) {
|
|
124
|
+
return this.get(key);
|
|
125
|
+
}
|
|
117
126
|
/**
|
|
118
127
|
* @description Checks if the value is an empty value
|
|
119
128
|
*/
|
|
@@ -166,6 +175,10 @@ export class Struct extends Map {
|
|
|
166
175
|
get hash() {
|
|
167
176
|
return this.registry.hash(this.toU8a());
|
|
168
177
|
}
|
|
178
|
+
|
|
179
|
+
get registry() {
|
|
180
|
+
return _classPrivateFieldLooseBase(this, _registry)[_registry];
|
|
181
|
+
}
|
|
169
182
|
/**
|
|
170
183
|
* @description Compares the value of the input to see if there is a match
|
|
171
184
|
*/
|
package/package.json
CHANGED
package/packageInfo.cjs
CHANGED
package/packageInfo.js
CHANGED
package/types/interfaces.d.ts
CHANGED
|
@@ -59,10 +59,11 @@ export interface IU8a extends Uint8Array, Codec {
|
|
|
59
59
|
export interface IVec<T extends Codec = Codec> extends Array<T>, Codec {
|
|
60
60
|
toArray(): T[];
|
|
61
61
|
}
|
|
62
|
-
export interface IMethod<A extends AnyTuple = AnyTuple> extends Codec {
|
|
62
|
+
export interface IMethod<A extends AnyTuple = AnyTuple, M = any> extends Codec {
|
|
63
63
|
readonly args: A;
|
|
64
64
|
readonly argsDef: ArgsDef;
|
|
65
65
|
readonly callIndex: Uint8Array;
|
|
66
66
|
readonly data: Uint8Array;
|
|
67
|
+
readonly meta: M;
|
|
67
68
|
is: (tx: IMethod<AnyTuple>) => tx is IMethod<A>;
|
|
68
69
|
}
|
package/types/registry.d.ts
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
2
|
import type { BN } from '@polkadot/util';
|
|
3
3
|
import type { Codec, CodecClass } from './codec';
|
|
4
|
+
import type { AnyTuple } from './helpers';
|
|
4
5
|
import type { ICompact, IEnum, IMap, IMethod, INumber, IOption, IResult, ISet, IStruct, ITuple, IU8a, IVec } from './interfaces';
|
|
5
6
|
export declare type OnlyCodec<K, T, Types> = K extends keyof Types ? Types[K] : T extends ICompact | IEnum | IMap | IMethod | INumber | IOption | IResult | ISet | IStruct | ITuple | IU8a | IVec ? T : T extends Codec ? T : never;
|
|
7
|
+
export interface RegistryError {
|
|
8
|
+
args: string[];
|
|
9
|
+
docs: string[];
|
|
10
|
+
index: number;
|
|
11
|
+
method: string;
|
|
12
|
+
name: string;
|
|
13
|
+
section: string;
|
|
14
|
+
}
|
|
6
15
|
export declare type RegistryTypes = Record<string, CodecClass | string | Record<string, string> | {
|
|
7
16
|
_enum: string[] | Record<string, number> | Record<string, string | null>;
|
|
8
17
|
} | {
|
|
@@ -13,16 +22,24 @@ export interface CodecCreateOptions {
|
|
|
13
22
|
isOptional?: boolean;
|
|
14
23
|
isPedantic?: boolean;
|
|
15
24
|
}
|
|
25
|
+
export interface CallBase<A extends AnyTuple, M = any> extends IMethod<A, M> {
|
|
26
|
+
readonly method: string;
|
|
27
|
+
readonly section: string;
|
|
28
|
+
toJSON: () => any;
|
|
29
|
+
}
|
|
30
|
+
export interface CallFunction<A extends AnyTuple = AnyTuple, M = any> extends CallBase<A, M> {
|
|
31
|
+
(...args: any[]): IMethod<A, M>;
|
|
32
|
+
}
|
|
16
33
|
export interface CodecRegistry {
|
|
17
34
|
readonly chainDecimals: number[];
|
|
18
35
|
readonly chainSS58: number | undefined;
|
|
19
36
|
readonly chainTokens: string[];
|
|
20
37
|
createdAtHash?: IU8a;
|
|
21
|
-
findMetaCall(callIndex: Uint8Array):
|
|
38
|
+
findMetaCall(callIndex: Uint8Array): CallFunction;
|
|
22
39
|
findMetaError(errorIndex: Uint8Array | {
|
|
23
40
|
error: BN;
|
|
24
41
|
index: BN;
|
|
25
|
-
}):
|
|
42
|
+
}): RegistryError;
|
|
26
43
|
findMetaEvent(eventIndex: Uint8Array): CodecClass<any>;
|
|
27
44
|
isLookupType(value: string): boolean;
|
|
28
45
|
createLookupType(lookupId: ICompact<INumber> | number): string;
|