@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.
Files changed (68) hide show
  1. package/abstract/Array.d.ts +4 -0
  2. package/abstract/Array.js +18 -2
  3. package/abstract/Base.d.ts +4 -0
  4. package/abstract/Base.js +8 -0
  5. package/abstract/Int.d.ts +4 -0
  6. package/abstract/Int.js +8 -0
  7. package/base/Compact.d.ts +4 -0
  8. package/base/Compact.js +8 -0
  9. package/base/DoNotConstruct.d.ts +1 -0
  10. package/base/DoNotConstruct.js +4 -0
  11. package/base/Enum.d.ts +4 -5
  12. package/base/Enum.js +31 -27
  13. package/base/Null.d.ts +4 -0
  14. package/base/Null.js +8 -0
  15. package/base/Option.d.ts +4 -0
  16. package/base/Option.js +8 -0
  17. package/base/Result.d.ts +0 -8
  18. package/base/Result.js +0 -16
  19. package/cjs/abstract/Array.js +18 -2
  20. package/cjs/abstract/Base.js +8 -0
  21. package/cjs/abstract/Int.js +8 -0
  22. package/cjs/base/Compact.js +8 -0
  23. package/cjs/base/DoNotConstruct.js +4 -0
  24. package/cjs/base/Enum.js +31 -27
  25. package/cjs/base/Null.js +8 -0
  26. package/cjs/base/Option.js +8 -0
  27. package/cjs/base/Result.js +0 -16
  28. package/cjs/extended/BTreeSet.js +14 -0
  29. package/cjs/extended/Map.js +17 -1
  30. package/cjs/extended/WrapperKeepOpaque.js +8 -0
  31. package/cjs/native/Bool.js +8 -0
  32. package/cjs/native/Date.js +8 -0
  33. package/cjs/native/Float.js +8 -0
  34. package/cjs/native/Json.js +12 -0
  35. package/cjs/native/Raw.js +16 -8
  36. package/cjs/native/Set.js +20 -9
  37. package/cjs/native/Struct.js +53 -27
  38. package/cjs/native/Text.js +8 -0
  39. package/cjs/package.json +1 -1
  40. package/cjs/packageInfo.js +1 -1
  41. package/cjs/utils/decodeU8a.js +6 -5
  42. package/extended/BTreeSet.d.ts +4 -0
  43. package/extended/BTreeSet.js +14 -0
  44. package/extended/Map.d.ts +4 -0
  45. package/extended/Map.js +16 -1
  46. package/extended/WrapperKeepOpaque.d.ts +4 -0
  47. package/extended/WrapperKeepOpaque.js +8 -0
  48. package/native/Bool.d.ts +4 -0
  49. package/native/Bool.js +8 -0
  50. package/native/Date.d.ts +4 -0
  51. package/native/Date.js +8 -0
  52. package/native/Float.d.ts +4 -0
  53. package/native/Float.js +8 -0
  54. package/native/Json.d.ts +4 -0
  55. package/native/Json.js +11 -0
  56. package/native/Raw.d.ts +4 -0
  57. package/native/Raw.js +16 -8
  58. package/native/Set.d.ts +4 -0
  59. package/native/Set.js +20 -9
  60. package/native/Struct.d.ts +14 -7
  61. package/native/Struct.js +53 -27
  62. package/native/Text.d.ts +4 -0
  63. package/native/Text.js +8 -0
  64. package/package.json +5 -5
  65. package/packageInfo.js +1 -1
  66. package/types/codec.d.ts +5 -1
  67. package/types/interfaces.d.ts +1 -0
  68. package/utils/decodeU8a.js +6 -5
@@ -57,6 +57,10 @@ export declare abstract class AbstractArray<T extends Codec> extends Array<T> im
57
57
  * @description Converts the Object to JSON, typically used for RPC transfers
58
58
  */
59
59
  toJSON(): AnyJson;
60
+ /**
61
+ * @description Converts the value in a best-fit primitive form
62
+ */
63
+ toPrimitive(): AnyJson;
60
64
  /**
61
65
  * @description Returns the base runtime type name for this instance
62
66
  */
package/abstract/Array.js CHANGED
@@ -118,7 +118,7 @@ export class AbstractArray extends Array {
118
118
  const result = new Array(this.length);
119
119
 
120
120
  for (let i = 0; i < this.length; i++) {
121
- result[i] = this[i].toHuman(isExtended);
121
+ result[i] = this[i] && this[i].toHuman(isExtended);
122
122
  }
123
123
 
124
124
  return result;
@@ -132,7 +132,23 @@ export class AbstractArray extends Array {
132
132
  const result = new Array(this.length);
133
133
 
134
134
  for (let i = 0; i < this.length; i++) {
135
- result[i] = this[i].toJSON();
135
+ // We actually log inside the U8a decoding and use JSON.stringify(...), which
136
+ // means that the Vec may be partially populated (same applies to toHuman, same check)
137
+ result[i] = this[i] && this[i].toJSON();
138
+ }
139
+
140
+ return result;
141
+ }
142
+ /**
143
+ * @description Converts the value in a best-fit primitive form
144
+ */
145
+
146
+
147
+ toPrimitive() {
148
+ const result = new Array(this.length);
149
+
150
+ for (let i = 0; i < this.length; i++) {
151
+ result[i] = this[i] && this[i].toPrimitive();
136
152
  }
137
153
 
138
154
  return result;
@@ -43,6 +43,10 @@ export declare abstract class AbstractBase<T extends Codec> implements Codec {
43
43
  * @description Converts the Object to JSON, typically used for RPC transfers
44
44
  */
45
45
  toJSON(): AnyJson;
46
+ /**
47
+ * @description Converts the value in a best-fit primitive form
48
+ */
49
+ toPrimitive(): AnyJson;
46
50
  /**
47
51
  * @description Returns the string representation of the value
48
52
  */
package/abstract/Base.js CHANGED
@@ -81,6 +81,14 @@ export class AbstractBase {
81
81
  toJSON() {
82
82
  return this.#raw.toJSON();
83
83
  }
84
+ /**
85
+ * @description Converts the value in a best-fit primitive form
86
+ */
87
+
88
+
89
+ toPrimitive() {
90
+ return this.#raw.toPrimitive();
91
+ }
84
92
  /**
85
93
  * @description Returns the string representation of the value
86
94
  */
package/abstract/Int.d.ts CHANGED
@@ -59,6 +59,10 @@ export declare abstract class AbstractInt extends BN implements INumber {
59
59
  * @description Converts the Object to JSON, typically used for RPC transfers
60
60
  */
61
61
  toJSON(onlyHex?: boolean): any;
62
+ /**
63
+ * @description Returns the value in a primitive form, either number when <= 52 bits, or string otherwise
64
+ */
65
+ toPrimitive(): number | string;
62
66
  /**
63
67
  * @description Returns the base runtime type name for this instance
64
68
  */
package/abstract/Int.js CHANGED
@@ -194,6 +194,14 @@ export class AbstractInt extends BN {
194
194
  // - this.#bitLength - the type bits (this should be used, however contracts RPC is problematic)
195
195
  return onlyHex || super.bitLength() > MAX_NUMBER_BITS ? this.toHex() : this.toNumber();
196
196
  }
197
+ /**
198
+ * @description Returns the value in a primitive form, either number when <= 52 bits, or string otherwise
199
+ */
200
+
201
+
202
+ toPrimitive() {
203
+ return super.bitLength() > MAX_NUMBER_BITS ? this.toString() : this.toNumber();
204
+ }
197
205
  /**
198
206
  * @description Returns the base runtime type name for this instance
199
207
  */
package/base/Compact.d.ts CHANGED
@@ -69,6 +69,10 @@ export declare class Compact<T extends INumber> implements ICompact<T> {
69
69
  * @description Returns the number representation for the value
70
70
  */
71
71
  toNumber(): number;
72
+ /**
73
+ * @description Converts the value in a best-fit primitive form
74
+ */
75
+ toPrimitive(): string | number;
72
76
  /**
73
77
  * @description Returns the base runtime type name for this instance
74
78
  */
package/base/Compact.js CHANGED
@@ -158,6 +158,14 @@ export class Compact {
158
158
  toNumber() {
159
159
  return this.#raw.toNumber();
160
160
  }
161
+ /**
162
+ * @description Converts the value in a best-fit primitive form
163
+ */
164
+
165
+
166
+ toPrimitive() {
167
+ return this.#raw.toPrimitive();
168
+ }
161
169
  /**
162
170
  * @description Returns the base runtime type name for this instance
163
171
  */
@@ -28,6 +28,7 @@ export declare class DoNotConstruct implements Codec {
28
28
  toHex(): HexString;
29
29
  toHuman(): AnyJson;
30
30
  toJSON(): AnyJson;
31
+ toPrimitive(): AnyJson;
31
32
  toRawType(): string;
32
33
  toString(): string;
33
34
  toU8a(): Uint8Array;
@@ -68,6 +68,10 @@ export class DoNotConstruct {
68
68
  throw this.#neverError;
69
69
  }
70
70
 
71
+ toPrimitive() {
72
+ throw this.#neverError;
73
+ }
74
+
71
75
  toRawType() {
72
76
  throw this.#neverError;
73
77
  }
package/base/Enum.d.ts CHANGED
@@ -58,11 +58,6 @@ export declare class Enum implements IEnum {
58
58
  * @description Checks if the Enum points to a [[Null]] type
59
59
  */
60
60
  get isNone(): boolean;
61
- /**
62
- * @description Checks if the Enum points to a [[Null]] type
63
- * @deprecated use isNone
64
- */
65
- get isNull(): boolean;
66
61
  /**
67
62
  * @description The available keys for this enum
68
63
  */
@@ -103,6 +98,10 @@ export declare class Enum implements IEnum {
103
98
  * @description Returns the number representation for the value
104
99
  */
105
100
  toNumber(): number;
101
+ /**
102
+ * @description Converts the value in a best-fit primitive form
103
+ */
104
+ toPrimitive(): AnyJson;
106
105
  /**
107
106
  * @description Returns a raw struct representation of the enum types
108
107
  */
package/base/Enum.js CHANGED
@@ -192,37 +192,40 @@ export class Enum {
192
192
  }
193
193
 
194
194
  static with(Types) {
195
- const keys = Array.isArray(Types) ? Types : Object.keys(Types);
196
- const asKeys = new Array(keys.length);
197
- const isKeys = new Array(keys.length);
198
-
199
- for (let i = 0; i < keys.length; i++) {
200
- const name = stringPascalCase(keys[i]);
201
- asKeys[i] = `as${name}`;
202
- isKeys[i] = `is${name}`;
203
- }
195
+ var _class;
204
196
 
205
197
  let definition; // eslint-disable-next-line no-return-assign
206
198
 
207
199
  const setDefinition = d => definition = d;
208
200
 
209
- return class extends Enum {
201
+ return _class = class extends Enum {
210
202
  constructor(registry, value, index) {
211
203
  super(registry, Types, value, index, {
212
204
  definition,
213
205
  setDefinition
214
206
  });
215
- objectProperties(this, isKeys, (_, i) => this.type === keys[i]);
216
- objectProperties(this, asKeys, (k, i) => {
217
- if (!this[isKeys[i]]) {
218
- throw new Error(`Cannot convert '${this.type}' via ${k}`);
219
- }
207
+ }
220
208
 
221
- return this.value;
222
- });
209
+ }, (() => {
210
+ const keys = Array.isArray(Types) ? Types : Object.keys(Types);
211
+ const asKeys = new Array(keys.length);
212
+ const isKeys = new Array(keys.length);
213
+
214
+ for (let i = 0; i < keys.length; i++) {
215
+ const name = stringPascalCase(keys[i]);
216
+ asKeys[i] = `as${name}`;
217
+ isKeys[i] = `is${name}`;
223
218
  }
224
219
 
225
- };
220
+ objectProperties(_class.prototype, isKeys, (_, i, self) => self.type === keys[i]);
221
+ objectProperties(_class.prototype, asKeys, (k, i, self) => {
222
+ if (self.type !== keys[i]) {
223
+ throw new Error(`Cannot convert '${self.type}' via ${k}`);
224
+ }
225
+
226
+ return self.value;
227
+ });
228
+ })(), _class;
226
229
  }
227
230
  /**
228
231
  * @description The length of the value when encoded as a Uint8Array
@@ -280,15 +283,6 @@ export class Enum {
280
283
  get isNone() {
281
284
  return this.#raw instanceof Null;
282
285
  }
283
- /**
284
- * @description Checks if the Enum points to a [[Null]] type
285
- * @deprecated use isNone
286
- */
287
-
288
-
289
- get isNull() {
290
- return this.isNone;
291
- }
292
286
  /**
293
287
  * @description The available keys for this enum
294
288
  */
@@ -402,6 +396,16 @@ export class Enum {
402
396
  toNumber() {
403
397
  return this.index;
404
398
  }
399
+ /**
400
+ * @description Converts the value in a best-fit primitive form
401
+ */
402
+
403
+
404
+ toPrimitive() {
405
+ return this.#isBasic ? this.type : {
406
+ [stringCamelCase(this.type)]: this.#raw.toPrimitive()
407
+ };
408
+ }
405
409
  /**
406
410
  * @description Returns a raw struct representation of the enum types
407
411
  */
package/base/Null.d.ts CHANGED
@@ -36,6 +36,10 @@ export declare class Null implements Codec {
36
36
  * @description Converts the Object to JSON, typically used for RPC transfers
37
37
  */
38
38
  toJSON(): null;
39
+ /**
40
+ * @description Converts the value in a best-fit primitive form
41
+ */
42
+ toPrimitive(): null;
39
43
  /**
40
44
  * @description Returns the base runtime type name for this instance
41
45
  */
package/base/Null.js CHANGED
@@ -64,6 +64,14 @@ export class Null {
64
64
  toJSON() {
65
65
  return null;
66
66
  }
67
+ /**
68
+ * @description Converts the value in a best-fit primitive form
69
+ */
70
+
71
+
72
+ toPrimitive() {
73
+ return null;
74
+ }
67
75
  /**
68
76
  * @description Returns the base runtime type name for this instance
69
77
  */
package/base/Option.d.ts CHANGED
@@ -63,6 +63,10 @@ export declare class Option<T extends Codec> implements IOption<T> {
63
63
  * @description Converts the Object to JSON, typically used for RPC transfers
64
64
  */
65
65
  toJSON(): AnyJson;
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/base/Option.js CHANGED
@@ -201,6 +201,14 @@ export class Option {
201
201
  toJSON() {
202
202
  return this.isNone ? null : this.#raw.toJSON();
203
203
  }
204
+ /**
205
+ * @description Converts the value in a best-fit primitive form
206
+ */
207
+
208
+
209
+ toPrimitive() {
210
+ return this.isNone ? null : this.#raw.toPrimitive();
211
+ }
204
212
  /**
205
213
  * @description Returns the base runtime type name for this instance
206
214
  */
package/base/Result.d.ts CHANGED
@@ -15,10 +15,6 @@ export declare class Result<O extends Codec, E extends Codec> extends Enum imple
15
15
  * @description Returns the wrapper Err value (if isErr)
16
16
  */
17
17
  get asErr(): E;
18
- /**
19
- * @deprecated Use asErr
20
- */
21
- get asError(): E;
22
18
  /**
23
19
  * @description Returns the wrapper Ok value (if isOk)
24
20
  */
@@ -31,10 +27,6 @@ export declare class Result<O extends Codec, E extends Codec> extends Enum imple
31
27
  * @description Checks if the Result wraps an Err value
32
28
  */
33
29
  get isErr(): boolean;
34
- /**
35
- * @deprecated Use isErr
36
- */
37
- get isError(): boolean;
38
30
  /**
39
31
  * @description Checks if the Result wraps an Ok value
40
32
  */
package/base/Result.js CHANGED
@@ -37,14 +37,6 @@ export class Result extends Enum {
37
37
 
38
38
  return this.value;
39
39
  }
40
- /**
41
- * @deprecated Use asErr
42
- */
43
-
44
-
45
- get asError() {
46
- return this.asErr;
47
- }
48
40
  /**
49
41
  * @description Returns the wrapper Ok value (if isOk)
50
42
  */
@@ -73,14 +65,6 @@ export class Result extends Enum {
73
65
  get isErr() {
74
66
  return !this.isOk;
75
67
  }
76
- /**
77
- * @deprecated Use isErr
78
- */
79
-
80
-
81
- get isError() {
82
- return this.isErr;
83
- }
84
68
  /**
85
69
  * @description Checks if the Result wraps an Ok value
86
70
  */
@@ -127,7 +127,7 @@ class AbstractArray extends Array {
127
127
  const result = new Array(this.length);
128
128
 
129
129
  for (let i = 0; i < this.length; i++) {
130
- result[i] = this[i].toHuman(isExtended);
130
+ result[i] = this[i] && this[i].toHuman(isExtended);
131
131
  }
132
132
 
133
133
  return result;
@@ -141,7 +141,23 @@ class AbstractArray extends Array {
141
141
  const result = new Array(this.length);
142
142
 
143
143
  for (let i = 0; i < this.length; i++) {
144
- result[i] = this[i].toJSON();
144
+ // We actually log inside the U8a decoding and use JSON.stringify(...), which
145
+ // means that the Vec may be partially populated (same applies to toHuman, same check)
146
+ result[i] = this[i] && this[i].toJSON();
147
+ }
148
+
149
+ return result;
150
+ }
151
+ /**
152
+ * @description Converts the value in a best-fit primitive form
153
+ */
154
+
155
+
156
+ toPrimitive() {
157
+ const result = new Array(this.length);
158
+
159
+ for (let i = 0; i < this.length; i++) {
160
+ result[i] = this[i] && this[i].toPrimitive();
145
161
  }
146
162
 
147
163
  return result;
@@ -88,6 +88,14 @@ class AbstractBase {
88
88
  toJSON() {
89
89
  return this.#raw.toJSON();
90
90
  }
91
+ /**
92
+ * @description Converts the value in a best-fit primitive form
93
+ */
94
+
95
+
96
+ toPrimitive() {
97
+ return this.#raw.toPrimitive();
98
+ }
91
99
  /**
92
100
  * @description Returns the string representation of the value
93
101
  */
@@ -211,6 +211,14 @@ class AbstractInt extends _util.BN {
211
211
  // - this.#bitLength - the type bits (this should be used, however contracts RPC is problematic)
212
212
  return onlyHex || super.bitLength() > MAX_NUMBER_BITS ? this.toHex() : this.toNumber();
213
213
  }
214
+ /**
215
+ * @description Returns the value in a primitive form, either number when <= 52 bits, or string otherwise
216
+ */
217
+
218
+
219
+ toPrimitive() {
220
+ return super.bitLength() > MAX_NUMBER_BITS ? this.toString() : this.toNumber();
221
+ }
214
222
  /**
215
223
  * @description Returns the base runtime type name for this instance
216
224
  */
@@ -168,6 +168,14 @@ class Compact {
168
168
  toNumber() {
169
169
  return this.#raw.toNumber();
170
170
  }
171
+ /**
172
+ * @description Converts the value in a best-fit primitive form
173
+ */
174
+
175
+
176
+ toPrimitive() {
177
+ return this.#raw.toPrimitive();
178
+ }
171
179
  /**
172
180
  * @description Returns the base runtime type name for this instance
173
181
  */
@@ -76,6 +76,10 @@ class DoNotConstruct {
76
76
  throw this.#neverError;
77
77
  }
78
78
 
79
+ toPrimitive() {
80
+ throw this.#neverError;
81
+ }
82
+
79
83
  toRawType() {
80
84
  throw this.#neverError;
81
85
  }
package/cjs/base/Enum.js CHANGED
@@ -210,37 +210,40 @@ class Enum {
210
210
  }
211
211
 
212
212
  static with(Types) {
213
- const keys = Array.isArray(Types) ? Types : Object.keys(Types);
214
- const asKeys = new Array(keys.length);
215
- const isKeys = new Array(keys.length);
216
-
217
- for (let i = 0; i < keys.length; i++) {
218
- const name = (0, _util.stringPascalCase)(keys[i]);
219
- asKeys[i] = `as${name}`;
220
- isKeys[i] = `is${name}`;
221
- }
213
+ var _class;
222
214
 
223
215
  let definition; // eslint-disable-next-line no-return-assign
224
216
 
225
217
  const setDefinition = d => definition = d;
226
218
 
227
- return class extends Enum {
219
+ return _class = class extends Enum {
228
220
  constructor(registry, value, index) {
229
221
  super(registry, Types, value, index, {
230
222
  definition,
231
223
  setDefinition
232
224
  });
233
- (0, _util.objectProperties)(this, isKeys, (_, i) => this.type === keys[i]);
234
- (0, _util.objectProperties)(this, asKeys, (k, i) => {
235
- if (!this[isKeys[i]]) {
236
- throw new Error(`Cannot convert '${this.type}' via ${k}`);
237
- }
225
+ }
238
226
 
239
- return this.value;
240
- });
227
+ }, (() => {
228
+ const keys = Array.isArray(Types) ? Types : Object.keys(Types);
229
+ const asKeys = new Array(keys.length);
230
+ const isKeys = new Array(keys.length);
231
+
232
+ for (let i = 0; i < keys.length; i++) {
233
+ const name = (0, _util.stringPascalCase)(keys[i]);
234
+ asKeys[i] = `as${name}`;
235
+ isKeys[i] = `is${name}`;
241
236
  }
242
237
 
243
- };
238
+ (0, _util.objectProperties)(_class.prototype, isKeys, (_, i, self) => self.type === keys[i]);
239
+ (0, _util.objectProperties)(_class.prototype, asKeys, (k, i, self) => {
240
+ if (self.type !== keys[i]) {
241
+ throw new Error(`Cannot convert '${self.type}' via ${k}`);
242
+ }
243
+
244
+ return self.value;
245
+ });
246
+ })(), _class;
244
247
  }
245
248
  /**
246
249
  * @description The length of the value when encoded as a Uint8Array
@@ -298,15 +301,6 @@ class Enum {
298
301
  get isNone() {
299
302
  return this.#raw instanceof _Null.Null;
300
303
  }
301
- /**
302
- * @description Checks if the Enum points to a [[Null]] type
303
- * @deprecated use isNone
304
- */
305
-
306
-
307
- get isNull() {
308
- return this.isNone;
309
- }
310
304
  /**
311
305
  * @description The available keys for this enum
312
306
  */
@@ -420,6 +414,16 @@ class Enum {
420
414
  toNumber() {
421
415
  return this.index;
422
416
  }
417
+ /**
418
+ * @description Converts the value in a best-fit primitive form
419
+ */
420
+
421
+
422
+ toPrimitive() {
423
+ return this.#isBasic ? this.type : {
424
+ [(0, _util.stringCamelCase)(this.type)]: this.#raw.toPrimitive()
425
+ };
426
+ }
423
427
  /**
424
428
  * @description Returns a raw struct representation of the enum types
425
429
  */
package/cjs/base/Null.js CHANGED
@@ -72,6 +72,14 @@ class Null {
72
72
  toJSON() {
73
73
  return null;
74
74
  }
75
+ /**
76
+ * @description Converts the value in a best-fit primitive form
77
+ */
78
+
79
+
80
+ toPrimitive() {
81
+ return null;
82
+ }
75
83
  /**
76
84
  * @description Returns the base runtime type name for this instance
77
85
  */
@@ -211,6 +211,14 @@ class Option {
211
211
  toJSON() {
212
212
  return this.isNone ? null : this.#raw.toJSON();
213
213
  }
214
+ /**
215
+ * @description Converts the value in a best-fit primitive form
216
+ */
217
+
218
+
219
+ toPrimitive() {
220
+ return this.isNone ? null : this.#raw.toPrimitive();
221
+ }
214
222
  /**
215
223
  * @description Returns the base runtime type name for this instance
216
224
  */
@@ -45,14 +45,6 @@ class Result extends _Enum.Enum {
45
45
 
46
46
  return this.value;
47
47
  }
48
- /**
49
- * @deprecated Use asErr
50
- */
51
-
52
-
53
- get asError() {
54
- return this.asErr;
55
- }
56
48
  /**
57
49
  * @description Returns the wrapper Ok value (if isOk)
58
50
  */
@@ -81,14 +73,6 @@ class Result extends _Enum.Enum {
81
73
  get isErr() {
82
74
  return !this.isOk;
83
75
  }
84
- /**
85
- * @deprecated Use isErr
86
- */
87
-
88
-
89
- get isError() {
90
- return this.isErr;
91
- }
92
76
  /**
93
77
  * @description Checks if the Result wraps an Ok value
94
78
  */
@@ -197,6 +197,20 @@ class BTreeSet extends Set {
197
197
  toRawType() {
198
198
  return `BTreeSet<${this.registry.getClassName(this.#ValClass) || new this.#ValClass(this.registry).toRawType()}>`;
199
199
  }
200
+ /**
201
+ * @description Converts the value in a best-fit primitive form
202
+ */
203
+
204
+
205
+ toPrimitive() {
206
+ const json = [];
207
+
208
+ for (const v of this.values()) {
209
+ json.push(v.toPrimitive());
210
+ }
211
+
212
+ return json;
213
+ }
200
214
  /**
201
215
  * @description Returns the string representation of the value
202
216
  */
@@ -11,6 +11,8 @@ var _Array = require("../abstract/Array");
11
11
 
12
12
  var _Enum = require("../base/Enum");
13
13
 
14
+ var _Raw = require("../native/Raw");
15
+
14
16
  var _Struct = require("../native/Struct");
15
17
 
16
18
  var _utils = require("../utils");
@@ -178,7 +180,7 @@ class CodecMap extends Map {
178
180
  const json = {};
179
181
 
180
182
  for (const [k, v] of this.entries()) {
181
- json[k.toString()] = v.toHuman(isExtended);
183
+ json[k instanceof _Raw.Raw && k.isAscii ? k.toUtf8() : k.toString()] = v.toHuman(isExtended);
182
184
  }
183
185
 
184
186
  return json;
@@ -197,6 +199,20 @@ class CodecMap extends Map {
197
199
 
198
200
  return json;
199
201
  }
202
+ /**
203
+ * @description Converts the value in a best-fit primitive form
204
+ */
205
+
206
+
207
+ toPrimitive() {
208
+ const json = {};
209
+
210
+ for (const [k, v] of this.entries()) {
211
+ json[k instanceof _Raw.Raw && k.isAscii ? k.toUtf8() : k.toString()] = v.toPrimitive();
212
+ }
213
+
214
+ return json;
215
+ }
200
216
  /**
201
217
  * @description Returns the base runtime type name for this instance
202
218
  */