@polkadot/types-codec 8.13.1 → 8.14.2-12
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/Array.d.ts +4 -0
- package/abstract/Array.js +14 -0
- package/abstract/Base.d.ts +4 -0
- package/abstract/Base.js +8 -0
- package/abstract/Int.d.ts +4 -0
- package/abstract/Int.js +8 -0
- package/base/Compact.d.ts +4 -0
- package/base/Compact.js +8 -0
- package/base/DoNotConstruct.d.ts +1 -0
- package/base/DoNotConstruct.js +4 -0
- package/base/Enum.d.ts +4 -5
- package/base/Enum.js +31 -27
- package/base/Null.d.ts +4 -0
- package/base/Null.js +8 -0
- package/base/Option.d.ts +4 -0
- package/base/Option.js +8 -0
- package/base/Result.d.ts +0 -8
- package/base/Result.js +0 -16
- package/cjs/abstract/Array.js +14 -0
- package/cjs/abstract/Base.js +8 -0
- package/cjs/abstract/Int.js +8 -0
- package/cjs/base/Compact.js +8 -0
- package/cjs/base/DoNotConstruct.js +4 -0
- package/cjs/base/Enum.js +31 -27
- package/cjs/base/Null.js +8 -0
- package/cjs/base/Option.js +8 -0
- package/cjs/base/Result.js +0 -16
- package/cjs/extended/BTreeSet.js +14 -0
- package/cjs/extended/Map.js +17 -1
- package/cjs/extended/WrapperKeepOpaque.js +8 -0
- package/cjs/native/Bool.js +8 -0
- package/cjs/native/Date.js +8 -0
- package/cjs/native/Float.js +8 -0
- package/cjs/native/Json.js +12 -0
- package/cjs/native/Raw.js +16 -8
- package/cjs/native/Set.js +20 -9
- package/cjs/native/Struct.js +50 -26
- package/cjs/native/Text.js +8 -0
- package/cjs/packageInfo.js +1 -1
- package/extended/BTreeSet.d.ts +4 -0
- package/extended/BTreeSet.js +14 -0
- package/extended/Map.d.ts +4 -0
- package/extended/Map.js +16 -1
- package/extended/WrapperKeepOpaque.d.ts +4 -0
- package/extended/WrapperKeepOpaque.js +8 -0
- package/native/Bool.d.ts +4 -0
- package/native/Bool.js +8 -0
- package/native/Date.d.ts +4 -0
- package/native/Date.js +8 -0
- package/native/Float.d.ts +4 -0
- package/native/Float.js +8 -0
- package/native/Json.d.ts +4 -0
- package/native/Json.js +11 -0
- package/native/Raw.d.ts +4 -0
- package/native/Raw.js +16 -8
- package/native/Set.d.ts +4 -0
- package/native/Set.js +20 -9
- package/native/Struct.d.ts +14 -7
- package/native/Struct.js +50 -26
- package/native/Text.d.ts +4 -0
- package/native/Text.js +8 -0
- package/package.json +4 -4
- package/packageInfo.js +1 -1
- package/types/codec.d.ts +5 -1
- package/types/interfaces.d.ts +1 -0
package/native/Struct.d.ts
CHANGED
|
@@ -35,15 +35,10 @@ export declare class Struct<S extends TypesDef = TypesDef, V extends {
|
|
|
35
35
|
* @description The available keys for this struct
|
|
36
36
|
*/
|
|
37
37
|
get defKeys(): string[];
|
|
38
|
-
getT<T>(key: string): T;
|
|
39
38
|
/**
|
|
40
39
|
* @description Checks if the value is an empty value
|
|
41
40
|
*/
|
|
42
41
|
get isEmpty(): boolean;
|
|
43
|
-
/**
|
|
44
|
-
* @description Returns the Type description of the structure
|
|
45
|
-
*/
|
|
46
|
-
get Type(): E;
|
|
47
42
|
/**
|
|
48
43
|
* @description The length of the value when encoded as a Uint8Array
|
|
49
44
|
*/
|
|
@@ -52,19 +47,27 @@ export declare class Struct<S extends TypesDef = TypesDef, V extends {
|
|
|
52
47
|
* @description returns a hash of the contents
|
|
53
48
|
*/
|
|
54
49
|
get hash(): IU8a;
|
|
50
|
+
/**
|
|
51
|
+
* @description Returns the Type description of the structure
|
|
52
|
+
*/
|
|
53
|
+
get Type(): E;
|
|
55
54
|
/**
|
|
56
55
|
* @description Compares the value of the input to see if there is a match
|
|
57
56
|
*/
|
|
58
57
|
eq(other?: unknown): boolean;
|
|
59
58
|
/**
|
|
60
59
|
* @description Returns a specific names entry in the structure
|
|
61
|
-
* @param
|
|
60
|
+
* @param key The name of the entry to retrieve
|
|
62
61
|
*/
|
|
63
|
-
get(
|
|
62
|
+
get(key: keyof S): Codec | undefined;
|
|
64
63
|
/**
|
|
65
64
|
* @description Returns the values of a member at a specific index (Rather use get(name) for performance)
|
|
66
65
|
*/
|
|
67
66
|
getAtIndex(index: number): Codec;
|
|
67
|
+
/**
|
|
68
|
+
* @description Returns the a types value by name
|
|
69
|
+
*/
|
|
70
|
+
getT<T>(key: string): T;
|
|
68
71
|
/**
|
|
69
72
|
* @description Returns a breakdown of the hex encoding for this Codec
|
|
70
73
|
*/
|
|
@@ -85,6 +88,10 @@ export declare class Struct<S extends TypesDef = TypesDef, V extends {
|
|
|
85
88
|
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
86
89
|
*/
|
|
87
90
|
toJSON(): Record<string, AnyJson>;
|
|
91
|
+
/**
|
|
92
|
+
* @description Converts the value in a best-fit primitive form
|
|
93
|
+
*/
|
|
94
|
+
toPrimitive(): Record<string, AnyJson>;
|
|
88
95
|
/**
|
|
89
96
|
* @description Returns the base runtime type name for this instance
|
|
90
97
|
*/
|
package/native/Struct.js
CHANGED
|
@@ -95,21 +95,24 @@ export class Struct extends Map {
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
static with(Types, jsonMap) {
|
|
98
|
-
|
|
98
|
+
var _class;
|
|
99
|
+
|
|
99
100
|
let definition; // eslint-disable-next-line no-return-assign
|
|
100
101
|
|
|
101
102
|
const setDefinition = d => definition = d;
|
|
102
103
|
|
|
103
|
-
return class extends Struct {
|
|
104
|
+
return _class = class extends Struct {
|
|
104
105
|
constructor(registry, value) {
|
|
105
106
|
super(registry, Types, value, jsonMap, {
|
|
106
107
|
definition,
|
|
107
108
|
setDefinition
|
|
108
109
|
});
|
|
109
|
-
objectProperties(this, keys, k => this.get(k));
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
}
|
|
112
|
+
}, (() => {
|
|
113
|
+
const keys = Object.keys(Types);
|
|
114
|
+
objectProperties(_class.prototype, keys, (k, _, self) => self.get(k));
|
|
115
|
+
})(), _class;
|
|
113
116
|
}
|
|
114
117
|
/**
|
|
115
118
|
* @description The available keys for this struct
|
|
@@ -119,10 +122,6 @@ export class Struct extends Map {
|
|
|
119
122
|
get defKeys() {
|
|
120
123
|
return this.#Types[1];
|
|
121
124
|
}
|
|
122
|
-
|
|
123
|
-
getT(key) {
|
|
124
|
-
return this.get(key);
|
|
125
|
-
}
|
|
126
125
|
/**
|
|
127
126
|
* @description Checks if the value is an empty value
|
|
128
127
|
*/
|
|
@@ -137,21 +136,6 @@ export class Struct extends Map {
|
|
|
137
136
|
|
|
138
137
|
return true;
|
|
139
138
|
}
|
|
140
|
-
/**
|
|
141
|
-
* @description Returns the Type description of the structure
|
|
142
|
-
*/
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
get Type() {
|
|
146
|
-
const result = {};
|
|
147
|
-
const [Types, keys] = this.#Types;
|
|
148
|
-
|
|
149
|
-
for (let i = 0; i < keys.length; i++) {
|
|
150
|
-
result[keys[i]] = new Types[i](this.registry).toRawType();
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return result;
|
|
154
|
-
}
|
|
155
139
|
/**
|
|
156
140
|
* @description The length of the value when encoded as a Uint8Array
|
|
157
141
|
*/
|
|
@@ -174,6 +158,21 @@ export class Struct extends Map {
|
|
|
174
158
|
get hash() {
|
|
175
159
|
return this.registry.hash(this.toU8a());
|
|
176
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* @description Returns the Type description of the structure
|
|
163
|
+
*/
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
get Type() {
|
|
167
|
+
const result = {};
|
|
168
|
+
const [Types, keys] = this.#Types;
|
|
169
|
+
|
|
170
|
+
for (let i = 0; i < keys.length; i++) {
|
|
171
|
+
result[keys[i]] = new Types[i](this.registry).toRawType();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return result;
|
|
175
|
+
}
|
|
177
176
|
/**
|
|
178
177
|
* @description Compares the value of the input to see if there is a match
|
|
179
178
|
*/
|
|
@@ -184,12 +183,12 @@ export class Struct extends Map {
|
|
|
184
183
|
}
|
|
185
184
|
/**
|
|
186
185
|
* @description Returns a specific names entry in the structure
|
|
187
|
-
* @param
|
|
186
|
+
* @param key The name of the entry to retrieve
|
|
188
187
|
*/
|
|
189
188
|
|
|
190
189
|
|
|
191
|
-
get(
|
|
192
|
-
return super.get(
|
|
190
|
+
get(key) {
|
|
191
|
+
return super.get(key);
|
|
193
192
|
}
|
|
194
193
|
/**
|
|
195
194
|
* @description Returns the values of a member at a specific index (Rather use get(name) for performance)
|
|
@@ -199,6 +198,14 @@ export class Struct extends Map {
|
|
|
199
198
|
getAtIndex(index) {
|
|
200
199
|
return this.toArray()[index];
|
|
201
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* @description Returns the a types value by name
|
|
203
|
+
*/
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
getT(key) {
|
|
207
|
+
return super.get(key);
|
|
208
|
+
}
|
|
202
209
|
/**
|
|
203
210
|
* @description Returns a breakdown of the hex encoding for this Codec
|
|
204
211
|
*/
|
|
@@ -264,6 +271,23 @@ export class Struct extends Map {
|
|
|
264
271
|
|
|
265
272
|
return json;
|
|
266
273
|
}
|
|
274
|
+
/**
|
|
275
|
+
* @description Converts the value in a best-fit primitive form
|
|
276
|
+
*/
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
toPrimitive() {
|
|
280
|
+
const json = {};
|
|
281
|
+
|
|
282
|
+
for (const [k, v] of this.entries()) {
|
|
283
|
+
const jsonKey = this.#jsonMap.get(k) || k; // We actually log inside the U8a decoding and use JSON.stringify(...), which
|
|
284
|
+
// means that the Vec may be partially populated (same applies to toHuman, same check)
|
|
285
|
+
|
|
286
|
+
json[jsonKey] = v && v.toPrimitive();
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return json;
|
|
290
|
+
}
|
|
267
291
|
/**
|
|
268
292
|
* @description Returns the base runtime type name for this instance
|
|
269
293
|
*/
|
package/native/Text.d.ts
CHANGED
|
@@ -56,6 +56,10 @@ export declare class Text extends String implements IText {
|
|
|
56
56
|
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
57
57
|
*/
|
|
58
58
|
toJSON(): string;
|
|
59
|
+
/**
|
|
60
|
+
* @description Converts the value in a best-fit primitive form
|
|
61
|
+
*/
|
|
62
|
+
toPrimitive(): string;
|
|
59
63
|
/**
|
|
60
64
|
* @description Returns the base runtime type name for this instance
|
|
61
65
|
*/
|
package/native/Text.js
CHANGED
|
@@ -138,6 +138,14 @@ export class Text extends String {
|
|
|
138
138
|
toJSON() {
|
|
139
139
|
return this.toString();
|
|
140
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* @description Converts the value in a best-fit primitive form
|
|
143
|
+
*/
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
toPrimitive() {
|
|
147
|
+
return this.toJSON();
|
|
148
|
+
}
|
|
141
149
|
/**
|
|
142
150
|
* @description Returns the base runtime type name for this instance
|
|
143
151
|
*/
|
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"./cjs/detectPackage.js"
|
|
21
21
|
],
|
|
22
22
|
"type": "module",
|
|
23
|
-
"version": "8.
|
|
23
|
+
"version": "8.14.2-12",
|
|
24
24
|
"main": "./cjs/index.js",
|
|
25
25
|
"module": "./index.js",
|
|
26
26
|
"types": "./index.d.ts",
|
|
@@ -434,8 +434,8 @@
|
|
|
434
434
|
}
|
|
435
435
|
},
|
|
436
436
|
"dependencies": {
|
|
437
|
-
"@babel/runtime": "^7.18.
|
|
438
|
-
"@polkadot/util": "^10.
|
|
439
|
-
"@polkadot/x-bigint": "^10.
|
|
437
|
+
"@babel/runtime": "^7.18.9",
|
|
438
|
+
"@polkadot/util": "^10.1.1",
|
|
439
|
+
"@polkadot/x-bigint": "^10.1.1"
|
|
440
440
|
}
|
|
441
441
|
}
|
package/packageInfo.js
CHANGED
|
@@ -5,5 +5,5 @@ export const packageInfo = {
|
|
|
5
5
|
name: '@polkadot/types-codec',
|
|
6
6
|
path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
|
|
7
7
|
type: 'esm',
|
|
8
|
-
version: '8.
|
|
8
|
+
version: '8.14.2-12'
|
|
9
9
|
};
|
package/types/codec.d.ts
CHANGED
|
@@ -60,6 +60,10 @@ export interface Codec {
|
|
|
60
60
|
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
61
61
|
*/
|
|
62
62
|
toJSON(): AnyJson;
|
|
63
|
+
/**
|
|
64
|
+
* @description Converts the value in a best-fit primitive form
|
|
65
|
+
*/
|
|
66
|
+
toPrimitive(): AnyJson;
|
|
63
67
|
/**
|
|
64
68
|
* @description Returns the base runtime type name for this instance
|
|
65
69
|
*/
|
|
@@ -81,5 +85,5 @@ export interface CodecClass<T = Codec> {
|
|
|
81
85
|
readonly __fallbackType?: string;
|
|
82
86
|
new (registry: Registry, ...args: any[]): T;
|
|
83
87
|
}
|
|
84
|
-
export declare type CodecTo = 'toHex' | 'toJSON' | 'toString' | 'toU8a';
|
|
88
|
+
export declare type CodecTo = 'toHex' | 'toJSON' | 'toPrimitive' | 'toString' | 'toU8a';
|
|
85
89
|
export declare type ArgsDef = Record<string, CodecClass | string>;
|