@polkadot/types-codec 8.12.2 → 8.14.2-11
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 +18 -2
- 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 +18 -2
- 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 +53 -27
- package/cjs/native/Text.js +8 -0
- package/cjs/package.json +1 -1
- package/cjs/packageInfo.js +1 -1
- package/cjs/utils/decodeU8a.js +6 -5
- 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 +53 -27
- package/native/Text.d.ts +4 -0
- package/native/Text.js +8 -0
- package/package.json +5 -5
- package/packageInfo.js +1 -1
- package/types/codec.d.ts +5 -1
- package/types/interfaces.d.ts +1 -0
- package/utils/decodeU8a.js +6 -5
|
@@ -84,6 +84,14 @@ class WrapperKeepOpaque extends _Bytes.Bytes {
|
|
|
84
84
|
toHuman(isExtended) {
|
|
85
85
|
return this.#decoded ? this.#decoded.toHuman(isExtended) : super.toHuman();
|
|
86
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* @description Converts the value in a best-fit primitive form
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
toPrimitive() {
|
|
93
|
+
return this.#decoded ? this.#decoded.toPrimitive() : super.toPrimitive();
|
|
94
|
+
}
|
|
87
95
|
/**
|
|
88
96
|
* @description Returns the base runtime type name for this instance
|
|
89
97
|
*/
|
package/cjs/native/Bool.js
CHANGED
|
@@ -104,6 +104,14 @@ class bool extends Boolean {
|
|
|
104
104
|
toJSON() {
|
|
105
105
|
return this.valueOf();
|
|
106
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* @description Converts the value in a best-fit primitive form
|
|
109
|
+
*/
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
toPrimitive() {
|
|
113
|
+
return this.toJSON();
|
|
114
|
+
}
|
|
107
115
|
/**
|
|
108
116
|
* @description Returns the base runtime type name for this instance
|
|
109
117
|
*/
|
package/cjs/native/Date.js
CHANGED
|
@@ -149,6 +149,14 @@ class CodecDate extends Date {
|
|
|
149
149
|
toNumber() {
|
|
150
150
|
return Math.ceil(this.getTime() / 1000);
|
|
151
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* @description Converts the value in a best-fit primitive form
|
|
154
|
+
*/
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
toPrimitive() {
|
|
158
|
+
return this.toNumber();
|
|
159
|
+
}
|
|
152
160
|
/**
|
|
153
161
|
* @description Returns the base runtime type name for this instance
|
|
154
162
|
*/
|
package/cjs/native/Float.js
CHANGED
|
@@ -112,6 +112,14 @@ class Float extends Number {
|
|
|
112
112
|
toNumber() {
|
|
113
113
|
return this.valueOf();
|
|
114
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* @description Converts the value in a best-fit primitive form
|
|
117
|
+
*/
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
toPrimitive() {
|
|
121
|
+
return this.toNumber();
|
|
122
|
+
}
|
|
115
123
|
/**
|
|
116
124
|
* @description Returns the base runtime type name for this instance
|
|
117
125
|
*/
|
package/cjs/native/Json.js
CHANGED
|
@@ -116,6 +116,18 @@ class Json extends Map {
|
|
|
116
116
|
return json;
|
|
117
117
|
}, {});
|
|
118
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* @description Converts the value in a best-fit primitive form
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
toPrimitive() {
|
|
125
|
+
return [...this.entries()].reduce((json, _ref4) => {
|
|
126
|
+
let [key, value] = _ref4;
|
|
127
|
+
json[key] = (0, _util.isFunction)(value.toHuman) ? value.toPrimitive() : value;
|
|
128
|
+
return json;
|
|
129
|
+
}, {});
|
|
130
|
+
}
|
|
119
131
|
/**
|
|
120
132
|
* @description Returns the base runtime type name for this instance
|
|
121
133
|
*/
|
package/cjs/native/Raw.js
CHANGED
|
@@ -117,6 +117,22 @@ class Raw extends Uint8Array {
|
|
|
117
117
|
|
|
118
118
|
|
|
119
119
|
toHuman() {
|
|
120
|
+
return this.toPrimitive();
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
toJSON() {
|
|
128
|
+
return this.toHex();
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* @description Converts the value in a best-fit primitive form
|
|
132
|
+
*/
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
toPrimitive() {
|
|
120
136
|
if (this.isAscii) {
|
|
121
137
|
const text = this.toUtf8(); // ensure we didn't end up with multibyte codepoints
|
|
122
138
|
|
|
@@ -127,14 +143,6 @@ class Raw extends Uint8Array {
|
|
|
127
143
|
|
|
128
144
|
return this.toJSON();
|
|
129
145
|
}
|
|
130
|
-
/**
|
|
131
|
-
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
132
|
-
*/
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
toJSON() {
|
|
136
|
-
return this.toHex();
|
|
137
|
-
}
|
|
138
146
|
/**
|
|
139
147
|
* @description Returns the base runtime type name for this instance
|
|
140
148
|
*/
|
package/cjs/native/Set.js
CHANGED
|
@@ -109,20 +109,23 @@ class CodecSet extends Set {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
static with(values, bitLength) {
|
|
112
|
-
|
|
113
|
-
const isKeys = new Array(keys.length);
|
|
112
|
+
var _class;
|
|
114
113
|
|
|
115
|
-
|
|
116
|
-
isKeys[i] = `is${(0, _util.stringPascalCase)(keys[i])}`;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return class extends CodecSet {
|
|
114
|
+
return _class = class extends CodecSet {
|
|
120
115
|
constructor(registry, value) {
|
|
121
116
|
super(registry, values, value, bitLength);
|
|
122
|
-
(0, _util.objectProperties)(this, isKeys, (_, i) => this.strings.includes(keys[i]));
|
|
123
117
|
}
|
|
124
118
|
|
|
125
|
-
}
|
|
119
|
+
}, (() => {
|
|
120
|
+
const keys = Object.keys(values);
|
|
121
|
+
const isKeys = new Array(keys.length);
|
|
122
|
+
|
|
123
|
+
for (let i = 0; i < keys.length; i++) {
|
|
124
|
+
isKeys[i] = `is${(0, _util.stringPascalCase)(keys[i])}`;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
(0, _util.objectProperties)(_class.prototype, isKeys, (_, i, self) => self.strings.includes(keys[i]));
|
|
128
|
+
})(), _class;
|
|
126
129
|
}
|
|
127
130
|
/**
|
|
128
131
|
* @description The length of the value when encoded as a Uint8Array
|
|
@@ -238,6 +241,14 @@ class CodecSet extends Set {
|
|
|
238
241
|
toNumber() {
|
|
239
242
|
return this.valueEncoded.toNumber();
|
|
240
243
|
}
|
|
244
|
+
/**
|
|
245
|
+
* @description Converts the value in a best-fit primitive form
|
|
246
|
+
*/
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
toPrimitive() {
|
|
250
|
+
return this.toJSON();
|
|
251
|
+
}
|
|
241
252
|
/**
|
|
242
253
|
* @description Returns the base runtime type name for this instance
|
|
243
254
|
*/
|
package/cjs/native/Struct.js
CHANGED
|
@@ -106,21 +106,24 @@ class Struct extends Map {
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
static with(Types, jsonMap) {
|
|
109
|
-
|
|
109
|
+
var _class;
|
|
110
|
+
|
|
110
111
|
let definition; // eslint-disable-next-line no-return-assign
|
|
111
112
|
|
|
112
113
|
const setDefinition = d => definition = d;
|
|
113
114
|
|
|
114
|
-
return class extends Struct {
|
|
115
|
+
return _class = class extends Struct {
|
|
115
116
|
constructor(registry, value) {
|
|
116
117
|
super(registry, Types, value, jsonMap, {
|
|
117
118
|
definition,
|
|
118
119
|
setDefinition
|
|
119
120
|
});
|
|
120
|
-
(0, _util.objectProperties)(this, keys, k => this.get(k));
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
}
|
|
123
|
+
}, (() => {
|
|
124
|
+
const keys = Object.keys(Types);
|
|
125
|
+
(0, _util.objectProperties)(_class.prototype, keys, (k, _, self) => self.get(k));
|
|
126
|
+
})(), _class;
|
|
124
127
|
}
|
|
125
128
|
/**
|
|
126
129
|
* @description The available keys for this struct
|
|
@@ -130,10 +133,6 @@ class Struct extends Map {
|
|
|
130
133
|
get defKeys() {
|
|
131
134
|
return this.#Types[1];
|
|
132
135
|
}
|
|
133
|
-
|
|
134
|
-
getT(key) {
|
|
135
|
-
return this.get(key);
|
|
136
|
-
}
|
|
137
136
|
/**
|
|
138
137
|
* @description Checks if the value is an empty value
|
|
139
138
|
*/
|
|
@@ -148,21 +147,6 @@ class Struct extends Map {
|
|
|
148
147
|
|
|
149
148
|
return true;
|
|
150
149
|
}
|
|
151
|
-
/**
|
|
152
|
-
* @description Returns the Type description of the structure
|
|
153
|
-
*/
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
get Type() {
|
|
157
|
-
const result = {};
|
|
158
|
-
const [Types, keys] = this.#Types;
|
|
159
|
-
|
|
160
|
-
for (let i = 0; i < keys.length; i++) {
|
|
161
|
-
result[keys[i]] = new Types[i](this.registry).toRawType();
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return result;
|
|
165
|
-
}
|
|
166
150
|
/**
|
|
167
151
|
* @description The length of the value when encoded as a Uint8Array
|
|
168
152
|
*/
|
|
@@ -185,6 +169,21 @@ class Struct extends Map {
|
|
|
185
169
|
get hash() {
|
|
186
170
|
return this.registry.hash(this.toU8a());
|
|
187
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* @description Returns the Type description of the structure
|
|
174
|
+
*/
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
get Type() {
|
|
178
|
+
const result = {};
|
|
179
|
+
const [Types, keys] = this.#Types;
|
|
180
|
+
|
|
181
|
+
for (let i = 0; i < keys.length; i++) {
|
|
182
|
+
result[keys[i]] = new Types[i](this.registry).toRawType();
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return result;
|
|
186
|
+
}
|
|
188
187
|
/**
|
|
189
188
|
* @description Compares the value of the input to see if there is a match
|
|
190
189
|
*/
|
|
@@ -195,12 +194,12 @@ class Struct extends Map {
|
|
|
195
194
|
}
|
|
196
195
|
/**
|
|
197
196
|
* @description Returns a specific names entry in the structure
|
|
198
|
-
* @param
|
|
197
|
+
* @param key The name of the entry to retrieve
|
|
199
198
|
*/
|
|
200
199
|
|
|
201
200
|
|
|
202
|
-
get(
|
|
203
|
-
return super.get(
|
|
201
|
+
get(key) {
|
|
202
|
+
return super.get(key);
|
|
204
203
|
}
|
|
205
204
|
/**
|
|
206
205
|
* @description Returns the values of a member at a specific index (Rather use get(name) for performance)
|
|
@@ -210,6 +209,14 @@ class Struct extends Map {
|
|
|
210
209
|
getAtIndex(index) {
|
|
211
210
|
return this.toArray()[index];
|
|
212
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* @description Returns the a types value by name
|
|
214
|
+
*/
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
getT(key) {
|
|
218
|
+
return super.get(key);
|
|
219
|
+
}
|
|
213
220
|
/**
|
|
214
221
|
* @description Returns a breakdown of the hex encoding for this Codec
|
|
215
222
|
*/
|
|
@@ -267,12 +274,31 @@ class Struct extends Map {
|
|
|
267
274
|
const json = {};
|
|
268
275
|
|
|
269
276
|
for (const [k, v] of this.entries()) {
|
|
270
|
-
const jsonKey = this.#jsonMap.get(k) || k;
|
|
277
|
+
const jsonKey = this.#jsonMap.get(k) || k; // We actually log inside the U8a decoding and use JSON.stringify(...), which
|
|
278
|
+
// means that the Vec may be partially populated (same applies to toHuman, same check)
|
|
279
|
+
|
|
271
280
|
json[jsonKey] = v && v.toJSON();
|
|
272
281
|
}
|
|
273
282
|
|
|
274
283
|
return json;
|
|
275
284
|
}
|
|
285
|
+
/**
|
|
286
|
+
* @description Converts the value in a best-fit primitive form
|
|
287
|
+
*/
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
toPrimitive() {
|
|
291
|
+
const json = {};
|
|
292
|
+
|
|
293
|
+
for (const [k, v] of this.entries()) {
|
|
294
|
+
const jsonKey = this.#jsonMap.get(k) || k; // We actually log inside the U8a decoding and use JSON.stringify(...), which
|
|
295
|
+
// means that the Vec may be partially populated (same applies to toHuman, same check)
|
|
296
|
+
|
|
297
|
+
json[jsonKey] = v && v.toPrimitive();
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return json;
|
|
301
|
+
}
|
|
276
302
|
/**
|
|
277
303
|
* @description Returns the base runtime type name for this instance
|
|
278
304
|
*/
|
package/cjs/native/Text.js
CHANGED
|
@@ -147,6 +147,14 @@ class Text extends String {
|
|
|
147
147
|
toJSON() {
|
|
148
148
|
return this.toString();
|
|
149
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* @description Converts the value in a best-fit primitive form
|
|
152
|
+
*/
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
toPrimitive() {
|
|
156
|
+
return this.toJSON();
|
|
157
|
+
}
|
|
150
158
|
/**
|
|
151
159
|
* @description Returns the base runtime type name for this instance
|
|
152
160
|
*/
|
package/cjs/package.json
CHANGED
package/cjs/packageInfo.js
CHANGED
package/cjs/utils/decodeU8a.js
CHANGED
|
@@ -13,7 +13,7 @@ var _util = require("@polkadot/util");
|
|
|
13
13
|
// SPDX-License-Identifier: Apache-2.0
|
|
14
14
|
|
|
15
15
|
/** @internal */
|
|
16
|
-
function formatFailure(registry, _ref, u8a, i, count, Type, key) {
|
|
16
|
+
function formatFailure(registry, result, _ref, u8a, i, count, Type, key) {
|
|
17
17
|
let {
|
|
18
18
|
message
|
|
19
19
|
} = _ref;
|
|
@@ -22,7 +22,8 @@ function formatFailure(registry, _ref, u8a, i, count, Type, key) {
|
|
|
22
22
|
try {
|
|
23
23
|
type = `: ${new Type(registry).toRawType()}`;
|
|
24
24
|
} catch {// ignore
|
|
25
|
-
}
|
|
25
|
+
} // console.error(JSON.stringify(result, null, 2));
|
|
26
|
+
|
|
26
27
|
|
|
27
28
|
return `decodeU8a: failed at ${(0, _util.u8aToHex)(u8a.subarray(0, 16))}…${key ? ` on ${key}` : ''} (index ${i}/${count})${type}:: ${message}`;
|
|
28
29
|
}
|
|
@@ -52,7 +53,7 @@ function decodeU8a(registry, result, u8a, _ref2) {
|
|
|
52
53
|
i++;
|
|
53
54
|
}
|
|
54
55
|
} catch (error) {
|
|
55
|
-
throw new Error(formatFailure(registry, error, u8a.subarray(offset), i, count, Types[i], keys[i]));
|
|
56
|
+
throw new Error(formatFailure(registry, result, error, u8a.subarray(offset), i, count, Types[i], keys[i]));
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
return [result, offset];
|
|
@@ -79,7 +80,7 @@ function decodeU8aStruct(registry, result, u8a, _ref3) {
|
|
|
79
80
|
i++;
|
|
80
81
|
}
|
|
81
82
|
} catch (error) {
|
|
82
|
-
throw new Error(formatFailure(registry, error, u8a.subarray(offset), i, count, Types[i], keys[i]));
|
|
83
|
+
throw new Error(formatFailure(registry, result, error, u8a.subarray(offset), i, count, Types[i], keys[i]));
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
return [result, offset];
|
|
@@ -105,7 +106,7 @@ function decodeU8aVec(registry, result, u8a, startAt, Type) {
|
|
|
105
106
|
i++;
|
|
106
107
|
}
|
|
107
108
|
} catch (error) {
|
|
108
|
-
throw new Error(formatFailure(registry, error, u8a.subarray(offset), i, count, Type));
|
|
109
|
+
throw new Error(formatFailure(registry, result, error, u8a.subarray(offset), i, count, Type));
|
|
109
110
|
}
|
|
110
111
|
|
|
111
112
|
return [offset, offset - startAt];
|
package/extended/BTreeSet.d.ts
CHANGED
|
@@ -47,6 +47,10 @@ export declare class BTreeSet<V extends Codec = Codec> extends Set<V> implements
|
|
|
47
47
|
* @description Returns the base runtime type name for this instance
|
|
48
48
|
*/
|
|
49
49
|
toRawType(): string;
|
|
50
|
+
/**
|
|
51
|
+
* @description Converts the value in a best-fit primitive form
|
|
52
|
+
*/
|
|
53
|
+
toPrimitive(): AnyJson;
|
|
50
54
|
/**
|
|
51
55
|
* @description Returns the string representation of the value
|
|
52
56
|
*/
|
package/extended/BTreeSet.js
CHANGED
|
@@ -188,6 +188,20 @@ export class BTreeSet extends Set {
|
|
|
188
188
|
toRawType() {
|
|
189
189
|
return `BTreeSet<${this.registry.getClassName(this.#ValClass) || new this.#ValClass(this.registry).toRawType()}>`;
|
|
190
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* @description Converts the value in a best-fit primitive form
|
|
193
|
+
*/
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
toPrimitive() {
|
|
197
|
+
const json = [];
|
|
198
|
+
|
|
199
|
+
for (const v of this.values()) {
|
|
200
|
+
json.push(v.toPrimitive());
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return json;
|
|
204
|
+
}
|
|
191
205
|
/**
|
|
192
206
|
* @description Returns the string representation of the value
|
|
193
207
|
*/
|
package/extended/Map.d.ts
CHANGED
|
@@ -38,6 +38,10 @@ export declare class CodecMap<K extends Codec = Codec, V extends Codec = Codec>
|
|
|
38
38
|
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
39
39
|
*/
|
|
40
40
|
toJSON(): Record<string, AnyJson>;
|
|
41
|
+
/**
|
|
42
|
+
* @description Converts the value in a best-fit primitive form
|
|
43
|
+
*/
|
|
44
|
+
toPrimitive(): AnyJson;
|
|
41
45
|
/**
|
|
42
46
|
* @description Returns the base runtime type name for this instance
|
|
43
47
|
*/
|
package/extended/Map.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { compactFromU8aLim, compactToU8a, isHex, isObject, isU8a, logger, stringify, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util';
|
|
4
4
|
import { AbstractArray } from "../abstract/Array.js";
|
|
5
5
|
import { Enum } from "../base/Enum.js";
|
|
6
|
+
import { Raw } from "../native/Raw.js";
|
|
6
7
|
import { Struct } from "../native/Struct.js";
|
|
7
8
|
import { compareMap, decodeU8a, sortMap, typeToConstructor } from "../utils/index.js";
|
|
8
9
|
const l = logger('Map');
|
|
@@ -165,7 +166,7 @@ export class CodecMap extends Map {
|
|
|
165
166
|
const json = {};
|
|
166
167
|
|
|
167
168
|
for (const [k, v] of this.entries()) {
|
|
168
|
-
json[k.toString()] = v.toHuman(isExtended);
|
|
169
|
+
json[k instanceof Raw && k.isAscii ? k.toUtf8() : k.toString()] = v.toHuman(isExtended);
|
|
169
170
|
}
|
|
170
171
|
|
|
171
172
|
return json;
|
|
@@ -184,6 +185,20 @@ export class CodecMap extends Map {
|
|
|
184
185
|
|
|
185
186
|
return json;
|
|
186
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* @description Converts the value in a best-fit primitive form
|
|
190
|
+
*/
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
toPrimitive() {
|
|
194
|
+
const json = {};
|
|
195
|
+
|
|
196
|
+
for (const [k, v] of this.entries()) {
|
|
197
|
+
json[k instanceof Raw && k.isAscii ? k.toUtf8() : k.toString()] = v.toPrimitive();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return json;
|
|
201
|
+
}
|
|
187
202
|
/**
|
|
188
203
|
* @description Returns the base runtime type name for this instance
|
|
189
204
|
*/
|
|
@@ -20,6 +20,10 @@ export declare class WrapperKeepOpaque<T extends Codec> extends Bytes {
|
|
|
20
20
|
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
21
21
|
*/
|
|
22
22
|
toHuman(isExtended?: boolean): AnyJson;
|
|
23
|
+
/**
|
|
24
|
+
* @description Converts the value in a best-fit primitive form
|
|
25
|
+
*/
|
|
26
|
+
toPrimitive(): any;
|
|
23
27
|
/**
|
|
24
28
|
* @description Returns the base runtime type name for this instance
|
|
25
29
|
*/
|
|
@@ -73,6 +73,14 @@ export class WrapperKeepOpaque extends Bytes {
|
|
|
73
73
|
toHuman(isExtended) {
|
|
74
74
|
return this.#decoded ? this.#decoded.toHuman(isExtended) : super.toHuman();
|
|
75
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* @description Converts the value in a best-fit primitive form
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
toPrimitive() {
|
|
82
|
+
return this.#decoded ? this.#decoded.toPrimitive() : super.toPrimitive();
|
|
83
|
+
}
|
|
76
84
|
/**
|
|
77
85
|
* @description Returns the base runtime type name for this instance
|
|
78
86
|
*/
|
package/native/Bool.d.ts
CHANGED
|
@@ -50,6 +50,10 @@ export declare class bool extends Boolean implements Codec {
|
|
|
50
50
|
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
51
51
|
*/
|
|
52
52
|
toJSON(): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* @description Converts the value in a best-fit primitive form
|
|
55
|
+
*/
|
|
56
|
+
toPrimitive(): boolean;
|
|
53
57
|
/**
|
|
54
58
|
* @description Returns the base runtime type name for this instance
|
|
55
59
|
*/
|
package/native/Bool.js
CHANGED
|
@@ -95,6 +95,14 @@ export class bool extends Boolean {
|
|
|
95
95
|
toJSON() {
|
|
96
96
|
return this.valueOf();
|
|
97
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* @description Converts the value in a best-fit primitive form
|
|
100
|
+
*/
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
toPrimitive() {
|
|
104
|
+
return this.toJSON();
|
|
105
|
+
}
|
|
98
106
|
/**
|
|
99
107
|
* @description Returns the base runtime type name for this instance
|
|
100
108
|
*/
|
package/native/Date.d.ts
CHANGED
|
@@ -64,6 +64,10 @@ export declare class CodecDate extends Date implements INumber {
|
|
|
64
64
|
* @description Returns the number representation for the timestamp
|
|
65
65
|
*/
|
|
66
66
|
toNumber(): number;
|
|
67
|
+
/**
|
|
68
|
+
* @description Converts the value in a best-fit primitive form
|
|
69
|
+
*/
|
|
70
|
+
toPrimitive(): number;
|
|
67
71
|
/**
|
|
68
72
|
* @description Returns the base runtime type name for this instance
|
|
69
73
|
*/
|
package/native/Date.js
CHANGED
|
@@ -139,6 +139,14 @@ export class CodecDate extends Date {
|
|
|
139
139
|
toNumber() {
|
|
140
140
|
return Math.ceil(this.getTime() / 1000);
|
|
141
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* @description Converts the value in a best-fit primitive form
|
|
144
|
+
*/
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
toPrimitive() {
|
|
148
|
+
return this.toNumber();
|
|
149
|
+
}
|
|
142
150
|
/**
|
|
143
151
|
* @description Returns the base runtime type name for this instance
|
|
144
152
|
*/
|
package/native/Float.d.ts
CHANGED
|
@@ -51,6 +51,10 @@ export declare class Float extends Number implements IFloat {
|
|
|
51
51
|
* @description Returns the number representation (Same as valueOf)
|
|
52
52
|
*/
|
|
53
53
|
toNumber(): number;
|
|
54
|
+
/**
|
|
55
|
+
* @description Converts the value in a best-fit primitive form
|
|
56
|
+
*/
|
|
57
|
+
toPrimitive(): number;
|
|
54
58
|
/**
|
|
55
59
|
* @description Returns the base runtime type name for this instance
|
|
56
60
|
*/
|
package/native/Float.js
CHANGED
|
@@ -103,6 +103,14 @@ export class Float extends Number {
|
|
|
103
103
|
toNumber() {
|
|
104
104
|
return this.valueOf();
|
|
105
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* @description Converts the value in a best-fit primitive form
|
|
108
|
+
*/
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
toPrimitive() {
|
|
112
|
+
return this.toNumber();
|
|
113
|
+
}
|
|
106
114
|
/**
|
|
107
115
|
* @description Returns the base runtime type name for this instance
|
|
108
116
|
*/
|
package/native/Json.d.ts
CHANGED
|
@@ -48,6 +48,10 @@ export declare class Json extends Map<string, any> implements Codec {
|
|
|
48
48
|
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
49
49
|
*/
|
|
50
50
|
toJSON(): Record<string, AnyJson>;
|
|
51
|
+
/**
|
|
52
|
+
* @description Converts the value in a best-fit primitive form
|
|
53
|
+
*/
|
|
54
|
+
toPrimitive(): Record<string, AnyJson>;
|
|
51
55
|
/**
|
|
52
56
|
* @description Returns the base runtime type name for this instance
|
|
53
57
|
*/
|
package/native/Json.js
CHANGED
|
@@ -102,6 +102,17 @@ export class Json extends Map {
|
|
|
102
102
|
return json;
|
|
103
103
|
}, {});
|
|
104
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* @description Converts the value in a best-fit primitive form
|
|
107
|
+
*/
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
toPrimitive() {
|
|
111
|
+
return [...this.entries()].reduce((json, [key, value]) => {
|
|
112
|
+
json[key] = isFunction(value.toHuman) ? value.toPrimitive() : value;
|
|
113
|
+
return json;
|
|
114
|
+
}, {});
|
|
115
|
+
}
|
|
105
116
|
/**
|
|
106
117
|
* @description Returns the base runtime type name for this instance
|
|
107
118
|
*/
|
package/native/Raw.d.ts
CHANGED
|
@@ -63,6 +63,10 @@ export declare class Raw extends Uint8Array implements IU8a {
|
|
|
63
63
|
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
64
64
|
*/
|
|
65
65
|
toJSON(): string;
|
|
66
|
+
/**
|
|
67
|
+
* @description Converts the value in a best-fit primitive form
|
|
68
|
+
*/
|
|
69
|
+
toPrimitive(): AnyJson;
|
|
66
70
|
/**
|
|
67
71
|
* @description Returns the base runtime type name for this instance
|
|
68
72
|
*/
|
package/native/Raw.js
CHANGED
|
@@ -109,6 +109,22 @@ export class Raw extends Uint8Array {
|
|
|
109
109
|
|
|
110
110
|
|
|
111
111
|
toHuman() {
|
|
112
|
+
return this.toPrimitive();
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
116
|
+
*/
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
toJSON() {
|
|
120
|
+
return this.toHex();
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* @description Converts the value in a best-fit primitive form
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
toPrimitive() {
|
|
112
128
|
if (this.isAscii) {
|
|
113
129
|
const text = this.toUtf8(); // ensure we didn't end up with multibyte codepoints
|
|
114
130
|
|
|
@@ -119,14 +135,6 @@ export class Raw extends Uint8Array {
|
|
|
119
135
|
|
|
120
136
|
return this.toJSON();
|
|
121
137
|
}
|
|
122
|
-
/**
|
|
123
|
-
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
124
|
-
*/
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
toJSON() {
|
|
128
|
-
return this.toHex();
|
|
129
|
-
}
|
|
130
138
|
/**
|
|
131
139
|
* @description Returns the base runtime type name for this instance
|
|
132
140
|
*/
|
package/native/Set.d.ts
CHANGED
|
@@ -63,6 +63,10 @@ export declare class CodecSet extends Set<string> implements ISet<string> {
|
|
|
63
63
|
* @description The encoded value for the set members
|
|
64
64
|
*/
|
|
65
65
|
toNumber(): number;
|
|
66
|
+
/**
|
|
67
|
+
* @description Converts the value in a best-fit primitive form
|
|
68
|
+
*/
|
|
69
|
+
toPrimitive(): string[];
|
|
66
70
|
/**
|
|
67
71
|
* @description Returns the base runtime type name for this instance
|
|
68
72
|
*/
|