From 27523268cb4b1d2949ca1e6b82e500ffa0505c0b Mon Sep 17 00:00:00 2001 From: tarikgul Date: Wed, 20 Mar 2024 15:12:08 -0400 Subject: [PATCH 1/7] Add `allowAscii` option for toHuman, and toPrimitive --- packages/types-codec/src/native/Raw.ts | 8 ++++---- packages/types-codec/src/types/codec.ts | 4 ++-- packages/types/src/primitive/StorageKey.ts | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/types-codec/src/native/Raw.ts b/packages/types-codec/src/native/Raw.ts index 677102afd0d5..de3ebbd191cf 100644 --- a/packages/types-codec/src/native/Raw.ts +++ b/packages/types-codec/src/native/Raw.ts @@ -110,8 +110,8 @@ export class Raw extends Uint8Array implements IU8a { /** * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information */ - public toHuman (): AnyJson { - return this.toPrimitive(); + public toHuman (_isExtended?: boolean, allowAscii?: boolean): AnyJson { + return this.toPrimitive(allowAscii); } /** @@ -124,8 +124,8 @@ export class Raw extends Uint8Array implements IU8a { /** * @description Converts the value in a best-fit primitive form */ - public toPrimitive (): AnyJson { - if (this.isAscii) { + public toPrimitive (allowAscii?: boolean): AnyJson { + if (this.isAscii && !!allowAscii) { const text = this.toUtf8(); // ensure we didn't end up with multibyte codepoints diff --git a/packages/types-codec/src/types/codec.ts b/packages/types-codec/src/types/codec.ts index dfd96f81bc51..8c8b273eb719 100644 --- a/packages/types-codec/src/types/codec.ts +++ b/packages/types-codec/src/types/codec.ts @@ -87,7 +87,7 @@ export interface Codec { /** * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information */ - toHuman (isExtended?: boolean): AnyJson; + toHuman (isExtended?: boolean, allowAscii?: boolean): AnyJson; /** * @description Converts the Object to JSON, typically used for RPC transfers @@ -97,7 +97,7 @@ export interface Codec { /** * @description Converts the value in a best-fit primitive form */ - toPrimitive (): AnyJson; + toPrimitive (allowAscii?: boolean): AnyJson; /** * @description Returns the base runtime type name for this instance diff --git a/packages/types/src/primitive/StorageKey.ts b/packages/types/src/primitive/StorageKey.ts index ee7562985d75..685ed52ef772 100644 --- a/packages/types/src/primitive/StorageKey.ts +++ b/packages/types/src/primitive/StorageKey.ts @@ -236,10 +236,10 @@ export class StorageKey extends Bytes implements /** * @description Returns the Human representation for this type */ - public override toHuman (): AnyJson { + public override toHuman (_isExtended?: boolean, allowAscii?: boolean): AnyJson { return this.#args.length - ? this.#args.map((a) => a.toHuman()) - : super.toHuman(); + ? this.#args.map((a) => a.toHuman(_isExtended, allowAscii)) + : super.toHuman(allowAscii); } /** From 93487b5dd034cd3111c7d2177e0b4f4fddf0a6c4 Mon Sep 17 00:00:00 2001 From: tarikgul Date: Wed, 20 Mar 2024 17:30:21 -0400 Subject: [PATCH 2/7] change allowAscii to disableAscii --- packages/types-codec/src/native/Raw.ts | 8 ++++---- packages/types-codec/src/types/codec.ts | 7 +++++-- packages/types/src/primitive/StorageKey.ts | 6 +++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/types-codec/src/native/Raw.ts b/packages/types-codec/src/native/Raw.ts index de3ebbd191cf..431ba44d82a4 100644 --- a/packages/types-codec/src/native/Raw.ts +++ b/packages/types-codec/src/native/Raw.ts @@ -110,8 +110,8 @@ export class Raw extends Uint8Array implements IU8a { /** * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information */ - public toHuman (_isExtended?: boolean, allowAscii?: boolean): AnyJson { - return this.toPrimitive(allowAscii); + public toHuman (_isExtended?: boolean, disableAscii?: boolean): AnyJson { + return this.toPrimitive(disableAscii); } /** @@ -124,8 +124,8 @@ export class Raw extends Uint8Array implements IU8a { /** * @description Converts the value in a best-fit primitive form */ - public toPrimitive (allowAscii?: boolean): AnyJson { - if (this.isAscii && !!allowAscii) { + public toPrimitive (disableAscii?: boolean): AnyJson { + if (!disableAscii && this.isAscii) { const text = this.toUtf8(); // ensure we didn't end up with multibyte codepoints diff --git a/packages/types-codec/src/types/codec.ts b/packages/types-codec/src/types/codec.ts index 8c8b273eb719..52bcb030032f 100644 --- a/packages/types-codec/src/types/codec.ts +++ b/packages/types-codec/src/types/codec.ts @@ -86,8 +86,10 @@ export interface Codec { /** * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information + * @param isExtended When set, for some (e.g. call) it can add more info, e.g. metadata documentation. (Generally not needed in all cases, but can be useful in Events, Calls, ...) + * @param disableAscii When set, for some (e.g. `Raw` types) it will disable converting the value to ascii. */ - toHuman (isExtended?: boolean, allowAscii?: boolean): AnyJson; + toHuman (isExtended?: boolean, disableAscii?: boolean): AnyJson; /** * @description Converts the Object to JSON, typically used for RPC transfers @@ -96,8 +98,9 @@ export interface Codec { /** * @description Converts the value in a best-fit primitive form + * @param disableAscii */ - toPrimitive (allowAscii?: boolean): AnyJson; + toPrimitive (disableAscii?: boolean): AnyJson; /** * @description Returns the base runtime type name for this instance diff --git a/packages/types/src/primitive/StorageKey.ts b/packages/types/src/primitive/StorageKey.ts index 685ed52ef772..5faeec90802e 100644 --- a/packages/types/src/primitive/StorageKey.ts +++ b/packages/types/src/primitive/StorageKey.ts @@ -236,10 +236,10 @@ export class StorageKey extends Bytes implements /** * @description Returns the Human representation for this type */ - public override toHuman (_isExtended?: boolean, allowAscii?: boolean): AnyJson { + public override toHuman (_isExtended?: boolean, disableAscii?: boolean): AnyJson { return this.#args.length - ? this.#args.map((a) => a.toHuman(_isExtended, allowAscii)) - : super.toHuman(allowAscii); + ? this.#args.map((a) => a.toHuman()) + : super.toHuman(disableAscii); } /** From fce53512232b2edd3b639dc5df9b7e17b5e9d142 Mon Sep 17 00:00:00 2001 From: tarikgul Date: Wed, 20 Mar 2024 22:27:38 -0400 Subject: [PATCH 3/7] add test --- packages/types-codec/src/native/Raw.spec.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/types-codec/src/native/Raw.spec.ts b/packages/types-codec/src/native/Raw.spec.ts index de57c2f9b737..fb601211167d 100644 --- a/packages/types-codec/src/native/Raw.spec.ts +++ b/packages/types-codec/src/native/Raw.spec.ts @@ -82,6 +82,10 @@ describe('Raw', (): void => { expect(new Raw(registry, '0x2021222324').isAscii).toBe(true); }); + it('has valid toHuman with disableAscii option set as true', (): void => { + expect(new Raw(registry, new Uint8Array([85, 85, 85, 85, 85, 85, 85, 85])).toHuman(undefined, true)).toEqual('0x5555555555555555'); + }); + it('has valid toPrimitive', (): void => { expect(new Raw(registry, 'testing').toPrimitive()).toEqual('testing'); expect(new Raw(registry, '0xe4bda0e5a5bd').toPrimitive()).toEqual('0xe4bda0e5a5bd'); From f9660cb76a8aa89bbc04afa56dab93e41cf52ccd Mon Sep 17 00:00:00 2001 From: tarikgul Date: Wed, 20 Mar 2024 23:40:57 -0400 Subject: [PATCH 4/7] Ensure Struct passes down the value to Raw, and add disableAscii to other types --- packages/types-codec/src/abstract/Array.ts | 4 ++-- packages/types-codec/src/abstract/Base.ts | 4 ++-- packages/types-codec/src/abstract/Object.ts | 2 +- packages/types-codec/src/base/Compact.ts | 4 ++-- packages/types-codec/src/base/Enum.ts | 4 ++-- packages/types-codec/src/base/Option.ts | 4 ++-- packages/types-codec/src/extended/BTreeSet.ts | 4 ++-- packages/types-codec/src/extended/Map.ts | 4 ++-- .../types-codec/src/extended/WrapperKeepOpaque.ts | 4 ++-- packages/types-codec/src/native/Struct.ts | 4 ++-- packages/types/src/extrinsic/Extrinsic.ts | 12 ++++++------ packages/types/src/extrinsic/ExtrinsicPayload.ts | 4 ++-- packages/types/src/generic/Call.ts | 4 ++-- packages/types/src/generic/Event.ts | 8 ++++---- packages/types/src/primitive/StorageKey.ts | 4 ++-- 15 files changed, 35 insertions(+), 35 deletions(-) diff --git a/packages/types-codec/src/abstract/Array.ts b/packages/types-codec/src/abstract/Array.ts index 05445c7ea2c6..551117168c41 100644 --- a/packages/types-codec/src/abstract/Array.ts +++ b/packages/types-codec/src/abstract/Array.ts @@ -123,12 +123,12 @@ export abstract class AbstractArray extends Array implements /** * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information */ - public toHuman (isExtended?: boolean): AnyJson { + public toHuman (isExtended?: boolean, disableAscii?: boolean): AnyJson { const count = this.length; const result = new Array(count); for (let i = 0; i < count; i++) { - result[i] = this[i] && this[i].toHuman(isExtended); + result[i] = this[i] && this[i].toHuman(isExtended, disableAscii); } return result; diff --git a/packages/types-codec/src/abstract/Base.ts b/packages/types-codec/src/abstract/Base.ts index fca5ec09a3d3..c92c6b1ecc96 100644 --- a/packages/types-codec/src/abstract/Base.ts +++ b/packages/types-codec/src/abstract/Base.ts @@ -75,8 +75,8 @@ export abstract class AbstractBase implements Codec { /** * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information */ - public toHuman (isExtended?: boolean): AnyJson { - return this.#raw.toHuman(isExtended); + public toHuman (isExtended?: boolean, disableAscii?: boolean): AnyJson { + return this.#raw.toHuman(isExtended, disableAscii); } /** diff --git a/packages/types-codec/src/abstract/Object.ts b/packages/types-codec/src/abstract/Object.ts index 48bb82db4a97..74a3b66f3763 100644 --- a/packages/types-codec/src/abstract/Object.ts +++ b/packages/types-codec/src/abstract/Object.ts @@ -60,7 +60,7 @@ export abstract class AbstractObject implements CodecObject< /** * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information */ - public abstract toHuman (isExtended?: boolean): AnyJson; + public abstract toHuman (isExtended?: boolean, disableAscii?: boolean): AnyJson; /** * @description Converts the Object to JSON, typically used for RPC transfers diff --git a/packages/types-codec/src/base/Compact.ts b/packages/types-codec/src/base/Compact.ts index 5b73d69b11a8..065a82f57bfd 100644 --- a/packages/types-codec/src/base/Compact.ts +++ b/packages/types-codec/src/base/Compact.ts @@ -143,8 +143,8 @@ export class Compact implements ICompact { /** * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information */ - public toHuman (isExtended?: boolean): AnyJson { - return this.#raw.toHuman(isExtended); + public toHuman (isExtended?: boolean, disableAscii?: boolean): AnyJson { + return this.#raw.toHuman(isExtended, disableAscii); } /** diff --git a/packages/types-codec/src/base/Enum.ts b/packages/types-codec/src/base/Enum.ts index 931fcf034e57..8f8ef87ff349 100644 --- a/packages/types-codec/src/base/Enum.ts +++ b/packages/types-codec/src/base/Enum.ts @@ -374,10 +374,10 @@ export class Enum implements IEnum { /** * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information */ - public toHuman (isExtended?: boolean): AnyJson { + public toHuman (isExtended?: boolean, disableAscii?: boolean): AnyJson { return this.#isBasic || this.isNone ? this.type - : { [this.type]: this.#raw.toHuman(isExtended) }; + : { [this.type]: this.#raw.toHuman(isExtended, disableAscii) }; } /** diff --git a/packages/types-codec/src/base/Option.ts b/packages/types-codec/src/base/Option.ts index 3967a6271b5a..5482fe502b56 100644 --- a/packages/types-codec/src/base/Option.ts +++ b/packages/types-codec/src/base/Option.ts @@ -183,8 +183,8 @@ export class Option implements IOption { /** * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information */ - public toHuman (isExtended?: boolean): AnyJson { - return this.#raw.toHuman(isExtended); + public toHuman (isExtended?: boolean, disableAscii?: boolean): AnyJson { + return this.#raw.toHuman(isExtended, disableAscii); } /** diff --git a/packages/types-codec/src/extended/BTreeSet.ts b/packages/types-codec/src/extended/BTreeSet.ts index cc5533d31d0d..a2e0fec77f31 100644 --- a/packages/types-codec/src/extended/BTreeSet.ts +++ b/packages/types-codec/src/extended/BTreeSet.ts @@ -163,11 +163,11 @@ export class BTreeSet extends Set implements ISet /** * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information */ - public toHuman (isExtended?: boolean): AnyJson { + public toHuman (isExtended?: boolean, disableAscii?: boolean): AnyJson { const json: AnyJson = []; for (const v of this.values()) { - json.push(v.toHuman(isExtended)); + json.push(v.toHuman(isExtended, disableAscii)); } return json; diff --git a/packages/types-codec/src/extended/Map.ts b/packages/types-codec/src/extended/Map.ts index 32ae225d31cb..ab745f367344 100644 --- a/packages/types-codec/src/extended/Map.ts +++ b/packages/types-codec/src/extended/Map.ts @@ -177,7 +177,7 @@ export class CodecMap extends /** * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information */ - public toHuman (isExtended?: boolean): Record { + public toHuman (isExtended?: boolean, disableAscii?: boolean): Record { const json: Record = {}; for (const [k, v] of this.entries()) { @@ -185,7 +185,7 @@ export class CodecMap extends k instanceof Raw && k.isAscii ? k.toUtf8() : k.toString() - ] = v.toHuman(isExtended); + ] = v.toHuman(isExtended, disableAscii); } return json; diff --git a/packages/types-codec/src/extended/WrapperKeepOpaque.ts b/packages/types-codec/src/extended/WrapperKeepOpaque.ts index e304b7f954de..e15073df07c9 100644 --- a/packages/types-codec/src/extended/WrapperKeepOpaque.ts +++ b/packages/types-codec/src/extended/WrapperKeepOpaque.ts @@ -84,9 +84,9 @@ export class WrapperKeepOpaque extends Bytes { /** * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information */ - public override toHuman (isExtended?: boolean): AnyJson { + public override toHuman (isExtended?: boolean, disableAscii?: boolean): AnyJson { return this.#decoded - ? this.#decoded.toHuman(isExtended) + ? this.#decoded.toHuman(isExtended, disableAscii) : super.toHuman(); } diff --git a/packages/types-codec/src/native/Struct.ts b/packages/types-codec/src/native/Struct.ts index e37ffaf1b776..82e472d165ae 100644 --- a/packages/types-codec/src/native/Struct.ts +++ b/packages/types-codec/src/native/Struct.ts @@ -268,11 +268,11 @@ export class Struct< /** * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information */ - public toHuman (isExtended?: boolean): Record { + public toHuman (isExtended?: boolean, disableAscii?: boolean): Record { const json: Record = {}; for (const [k, v] of this.entries()) { - json[k as string] = v.toHuman(isExtended); + json[k as string] = v.toHuman(isExtended, disableAscii); } return json; diff --git a/packages/types/src/extrinsic/Extrinsic.ts b/packages/types/src/extrinsic/Extrinsic.ts index f7a5fe71c90f..c2fcdb62e9f7 100644 --- a/packages/types/src/extrinsic/Extrinsic.ts +++ b/packages/types/src/extrinsic/Extrinsic.ts @@ -307,20 +307,20 @@ export class GenericExtrinsic extends ExtrinsicBa /** * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information */ - public override toHuman (isExpanded?: boolean): AnyJson { + public override toHuman (isExpanded?: boolean, disableAscii?: boolean): AnyJson { return objectSpread>( {}, { isSigned: this.isSigned, - method: this.method.toHuman(isExpanded) + method: this.method.toHuman(isExpanded, disableAscii) }, this.isSigned ? { - era: this.era.toHuman(isExpanded), - nonce: this.nonce.toHuman(isExpanded), + era: this.era.toHuman(isExpanded, disableAscii), + nonce: this.nonce.toHuman(isExpanded, disableAscii), signature: this.signature.toHex(), - signer: this.signer.toHuman(isExpanded), - tip: this.tip.toHuman(isExpanded) + signer: this.signer.toHuman(isExpanded, disableAscii), + tip: this.tip.toHuman(isExpanded, disableAscii) } : null ); diff --git a/packages/types/src/extrinsic/ExtrinsicPayload.ts b/packages/types/src/extrinsic/ExtrinsicPayload.ts index 9221d8c61676..bbd98f0eee44 100644 --- a/packages/types/src/extrinsic/ExtrinsicPayload.ts +++ b/packages/types/src/extrinsic/ExtrinsicPayload.ts @@ -134,8 +134,8 @@ export class GenericExtrinsicPayload extends AbstractBase { /** * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information */ - public override toHuman (isExtended?: boolean): AnyJson { - return this.inner.toHuman(isExtended); + public override toHuman (isExtended?: boolean, disableAscii?: boolean): AnyJson { + return this.inner.toHuman(isExtended, disableAscii); } /** diff --git a/packages/types/src/generic/Call.ts b/packages/types/src/generic/Call.ts index 5cc1853f796b..172b2527694b 100644 --- a/packages/types/src/generic/Call.ts +++ b/packages/types/src/generic/Call.ts @@ -213,7 +213,7 @@ export class GenericCall extends Struct implement /** * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information */ - public override toHuman (isExpanded?: boolean): Record { + public override toHuman (isExpanded?: boolean, disableAscii?: boolean): Record { let call: CallFunction | undefined; try { @@ -225,7 +225,7 @@ export class GenericCall extends Struct implement return objectSpread( { args: this.argsEntries.reduce>((args, [n, a]) => - objectSpread(args, { [n]: a.toHuman(isExpanded) }), {}), + objectSpread(args, { [n]: a.toHuman(isExpanded, disableAscii) }), {}), method: call?.method, section: call?.section }, diff --git a/packages/types/src/generic/Event.ts b/packages/types/src/generic/Event.ts index e4a01acb9da2..31f3c88a3b51 100644 --- a/packages/types/src/generic/Event.ts +++ b/packages/types/src/generic/Event.ts @@ -106,12 +106,12 @@ export class GenericEventData extends Tuple implements IEventData { /** * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information */ - public override toHuman (isExtended?: boolean): AnyJson { + public override toHuman (isExtended?: boolean, disableAscii?: boolean): AnyJson { if (this.#names !== null) { const json: Record = {}; for (let i = 0, count = this.#names.length; i < count; i++) { - json[this.#names[i]] = this[i].toHuman(isExtended); + json[this.#names[i]] = this[i].toHuman(isExtended, disableAscii); } return json; @@ -185,7 +185,7 @@ export class GenericEvent extends Struct implements IEvent { /** * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information */ - public override toHuman (isExpanded?: boolean): Record { + public override toHuman (isExpanded?: boolean, disableAscii?: boolean): Record { return objectSpread( { method: this.method, @@ -194,7 +194,7 @@ export class GenericEvent extends Struct implements IEvent { isExpanded ? { docs: this.meta.docs.map((d) => d.toString()) } : null, - super.toHuman(isExpanded) + super.toHuman(isExpanded, disableAscii) ); } } diff --git a/packages/types/src/primitive/StorageKey.ts b/packages/types/src/primitive/StorageKey.ts index 5faeec90802e..f4e8ebafc3aa 100644 --- a/packages/types/src/primitive/StorageKey.ts +++ b/packages/types/src/primitive/StorageKey.ts @@ -238,8 +238,8 @@ export class StorageKey extends Bytes implements */ public override toHuman (_isExtended?: boolean, disableAscii?: boolean): AnyJson { return this.#args.length - ? this.#args.map((a) => a.toHuman()) - : super.toHuman(disableAscii); + ? this.#args.map((a) => a.toHuman(undefined, disableAscii)) + : super.toHuman(undefined, disableAscii); } /** From ddedcb2afe9b288db5d6797cb2b1030f2538f236 Mon Sep 17 00:00:00 2001 From: tarikgul Date: Thu, 21 Mar 2024 11:30:06 -0400 Subject: [PATCH 5/7] ensure CodecMap also has disableAscii --- packages/types-codec/src/extended/Map.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/types-codec/src/extended/Map.ts b/packages/types-codec/src/extended/Map.ts index ab745f367344..8d9ebb80337b 100644 --- a/packages/types-codec/src/extended/Map.ts +++ b/packages/types-codec/src/extended/Map.ts @@ -182,7 +182,7 @@ export class CodecMap extends for (const [k, v] of this.entries()) { json[ - k instanceof Raw && k.isAscii + k instanceof Raw && !disableAscii && k.isAscii ? k.toUtf8() : k.toString() ] = v.toHuman(isExtended, disableAscii); From 123737afebfa5a933aa884c429f226f18cb38b2e Mon Sep 17 00:00:00 2001 From: tarikgul Date: Thu, 21 Mar 2024 11:42:35 -0400 Subject: [PATCH 6/7] toPrimitive CodecMap disableAscii --- packages/types-codec/src/extended/Map.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/types-codec/src/extended/Map.ts b/packages/types-codec/src/extended/Map.ts index 8d9ebb80337b..dcb68ef418bb 100644 --- a/packages/types-codec/src/extended/Map.ts +++ b/packages/types-codec/src/extended/Map.ts @@ -207,15 +207,15 @@ export class CodecMap extends /** * @description Converts the value in a best-fit primitive form */ - public toPrimitive (): AnyJson { + public toPrimitive (disableAscii?: boolean): AnyJson { const json: Record = {}; for (const [k, v] of this.entries()) { json[ - k instanceof Raw && k.isAscii + k instanceof Raw && !disableAscii && k.isAscii ? k.toUtf8() : k.toString() - ] = v.toPrimitive(); + ] = v.toPrimitive(disableAscii); } return json; From fbb769156b4c74e6b2590ad3c0cb848b9c1c8866 Mon Sep 17 00:00:00 2001 From: tarikgul Date: Thu, 21 Mar 2024 12:29:30 -0400 Subject: [PATCH 7/7] add toPrimitive options --- packages/types-codec/src/abstract/Array.ts | 4 ++-- packages/types-codec/src/abstract/Base.ts | 4 ++-- packages/types-codec/src/abstract/Object.ts | 2 +- packages/types-codec/src/base/Compact.ts | 4 ++-- packages/types-codec/src/base/Enum.ts | 4 ++-- packages/types-codec/src/base/Option.ts | 4 ++-- packages/types-codec/src/extended/BTreeSet.ts | 4 ++-- packages/types-codec/src/extended/WrapperKeepOpaque.ts | 8 ++++---- packages/types-codec/src/native/Json.ts | 4 ++-- packages/types-codec/src/native/Struct.ts | 4 ++-- packages/types-codec/src/types/interfaces.ts | 4 ++-- 11 files changed, 23 insertions(+), 23 deletions(-) diff --git a/packages/types-codec/src/abstract/Array.ts b/packages/types-codec/src/abstract/Array.ts index 551117168c41..ebeeba9afaee 100644 --- a/packages/types-codec/src/abstract/Array.ts +++ b/packages/types-codec/src/abstract/Array.ts @@ -153,12 +153,12 @@ export abstract class AbstractArray extends Array implements /** * @description Converts the value in a best-fit primitive form */ - public toPrimitive (): AnyJson { + public toPrimitive (disableAscii?: boolean): AnyJson { const count = this.length; const result = new Array(count); for (let i = 0; i < count; i++) { - result[i] = this[i] && this[i].toPrimitive(); + result[i] = this[i] && this[i].toPrimitive(disableAscii); } return result; diff --git a/packages/types-codec/src/abstract/Base.ts b/packages/types-codec/src/abstract/Base.ts index c92c6b1ecc96..1a54b5809c5c 100644 --- a/packages/types-codec/src/abstract/Base.ts +++ b/packages/types-codec/src/abstract/Base.ts @@ -89,8 +89,8 @@ export abstract class AbstractBase implements Codec { /** * @description Converts the value in a best-fit primitive form */ - public toPrimitive (): AnyJson { - return this.#raw.toPrimitive(); + public toPrimitive (disableAscii?: boolean): AnyJson { + return this.#raw.toPrimitive(disableAscii); } /** diff --git a/packages/types-codec/src/abstract/Object.ts b/packages/types-codec/src/abstract/Object.ts index 74a3b66f3763..7ab48145e6dc 100644 --- a/packages/types-codec/src/abstract/Object.ts +++ b/packages/types-codec/src/abstract/Object.ts @@ -70,7 +70,7 @@ export abstract class AbstractObject implements CodecObject< /** * @description Converts the value in a best-fit primitive form */ - public abstract toPrimitive (): AnyJson; + public abstract toPrimitive (disableAscii?: boolean): AnyJson; /** * @description Returns the string representation of the value diff --git a/packages/types-codec/src/base/Compact.ts b/packages/types-codec/src/base/Compact.ts index 065a82f57bfd..e8ae40b5525c 100644 --- a/packages/types-codec/src/base/Compact.ts +++ b/packages/types-codec/src/base/Compact.ts @@ -164,8 +164,8 @@ export class Compact implements ICompact { /** * @description Converts the value in a best-fit primitive form */ - public toPrimitive (): string | number { - return this.#raw.toPrimitive(); + public toPrimitive (disableAscii?: boolean): string | number { + return this.#raw.toPrimitive(disableAscii); } /** diff --git a/packages/types-codec/src/base/Enum.ts b/packages/types-codec/src/base/Enum.ts index 8f8ef87ff349..53c112444445 100644 --- a/packages/types-codec/src/base/Enum.ts +++ b/packages/types-codec/src/base/Enum.ts @@ -399,10 +399,10 @@ export class Enum implements IEnum { /** * @description Converts the value in a best-fit primitive form */ - public toPrimitive (): AnyJson { + public toPrimitive (disableAscii?: boolean): AnyJson { return this.#isBasic ? this.type - : { [stringCamelCase(this.type)]: this.#raw.toPrimitive() }; + : { [stringCamelCase(this.type)]: this.#raw.toPrimitive(disableAscii) }; } /** diff --git a/packages/types-codec/src/base/Option.ts b/packages/types-codec/src/base/Option.ts index 5482fe502b56..fc270d578374 100644 --- a/packages/types-codec/src/base/Option.ts +++ b/packages/types-codec/src/base/Option.ts @@ -199,10 +199,10 @@ export class Option implements IOption { /** * @description Converts the value in a best-fit primitive form */ - public toPrimitive (): AnyJson { + public toPrimitive (disableAscii?: boolean): AnyJson { return this.isNone ? null - : this.#raw.toPrimitive(); + : this.#raw.toPrimitive(disableAscii); } /** diff --git a/packages/types-codec/src/extended/BTreeSet.ts b/packages/types-codec/src/extended/BTreeSet.ts index a2e0fec77f31..41bc60b2e5c6 100644 --- a/packages/types-codec/src/extended/BTreeSet.ts +++ b/packages/types-codec/src/extended/BTreeSet.ts @@ -196,11 +196,11 @@ export class BTreeSet extends Set implements ISet /** * @description Converts the value in a best-fit primitive form */ - public toPrimitive (): AnyJson { + public toPrimitive (disableAscii?: boolean): AnyJson { const json: AnyJson = []; for (const v of this.values()) { - json.push(v.toPrimitive()); + json.push(v.toPrimitive(disableAscii)); } return json; diff --git a/packages/types-codec/src/extended/WrapperKeepOpaque.ts b/packages/types-codec/src/extended/WrapperKeepOpaque.ts index e15073df07c9..24c7991963b0 100644 --- a/packages/types-codec/src/extended/WrapperKeepOpaque.ts +++ b/packages/types-codec/src/extended/WrapperKeepOpaque.ts @@ -87,16 +87,16 @@ export class WrapperKeepOpaque extends Bytes { public override toHuman (isExtended?: boolean, disableAscii?: boolean): AnyJson { return this.#decoded ? this.#decoded.toHuman(isExtended, disableAscii) - : super.toHuman(); + : super.toHuman(isExtended, disableAscii); } /** * @description Converts the value in a best-fit primitive form */ - public override toPrimitive (): any { + public override toPrimitive (disableAscii?: boolean): any { return this.#decoded - ? this.#decoded.toPrimitive() - : super.toPrimitive(); + ? this.#decoded.toPrimitive(disableAscii) + : super.toPrimitive(disableAscii); } /** diff --git a/packages/types-codec/src/native/Json.ts b/packages/types-codec/src/native/Json.ts index 93a72b7fbb3b..362d81d7c162 100644 --- a/packages/types-codec/src/native/Json.ts +++ b/packages/types-codec/src/native/Json.ts @@ -114,10 +114,10 @@ export class Json extends Map implements Codec { /** * @description Converts the value in a best-fit primitive form */ - public toPrimitive (): Record { + public toPrimitive (disableAscii?: boolean): Record { return [...this.entries()].reduce>((json, [key, value]): Record => { json[key] = isFunction((value as Codec).toPrimitive) - ? (value as Codec).toPrimitive() + ? (value as Codec).toPrimitive(disableAscii) : value as AnyJson; return json; diff --git a/packages/types-codec/src/native/Struct.ts b/packages/types-codec/src/native/Struct.ts index 82e472d165ae..1089c21e4685 100644 --- a/packages/types-codec/src/native/Struct.ts +++ b/packages/types-codec/src/native/Struct.ts @@ -296,11 +296,11 @@ export class Struct< /** * @description Converts the value in a best-fit primitive form */ - public toPrimitive (): Record { + public toPrimitive (disableAscii?: boolean): Record { const json: Record = {}; for (const [k, v] of this.entries()) { - json[k as string] = v.toPrimitive(); + json[k as string] = v.toPrimitive(disableAscii); } return json; diff --git a/packages/types-codec/src/types/interfaces.ts b/packages/types-codec/src/types/interfaces.ts index 9f0760778241..2a11bf53d7a2 100644 --- a/packages/types-codec/src/types/interfaces.ts +++ b/packages/types-codec/src/types/interfaces.ts @@ -31,7 +31,7 @@ export interface INumber extends Codec { toBigInt (): bigint; toBn (): BN; toNumber (): number; - toPrimitive (): string | number; + toPrimitive (disableAscii?: boolean): string | number; } export interface IFloat extends Codec { @@ -78,7 +78,7 @@ export interface IU8a extends Uint8Array, Codec { readonly isUtf8: boolean bitLength (): number; - toHuman (isExtended?: boolean): any; + toHuman (isExtended?: boolean, disableAscii?: boolean): any; toJSON (): any; toUtf8 (): string; }