From ce3add463dd137bb7fe1675b0cb4583f5abc6617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20S=C3=A1nchez?= Date: Mon, 17 Nov 2025 16:17:58 +0000 Subject: [PATCH] Print record id values for easier inspection --- packages/sdk/src/index.ts | 4 ++++ packages/sdk/src/inspect.ts | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 packages/sdk/src/inspect.ts diff --git a/packages/sdk/src/index.ts b/packages/sdk/src/index.ts index d082a1f3..6d05bbaa 100644 --- a/packages/sdk/src/index.ts +++ b/packages/sdk/src/index.ts @@ -5,3 +5,7 @@ export * from "./errors"; export * from "./types"; export * from "./utils"; export * from "./value"; + +import { setUpCustomInspectors } from "./inspect"; + +setUpCustomInspectors(); diff --git a/packages/sdk/src/inspect.ts b/packages/sdk/src/inspect.ts new file mode 100644 index 00000000..cad88321 --- /dev/null +++ b/packages/sdk/src/inspect.ts @@ -0,0 +1,25 @@ +import type { InspectOptions } from "node:util"; +import { RecordId, RecordIdRange, StringRecordId } from "./value"; + +export function setUpCustomInspectors() { + if (typeof process === "undefined") return; + + import("node:util").then((util) => { + function customRecordIdInspect( + this: RecordId | RecordIdRange | StringRecordId, + _: unknown, + options: InspectOptions, + ) { + if (options.colors) { + // raw coloring, bright blue text + return `\x1b[94m${this.toString()}\x1b[0m`; + } + + return this.toString(); + } + + (RecordId.prototype as any)[util.inspect.custom] = customRecordIdInspect; + (RecordIdRange.prototype as any)[util.inspect.custom] = customRecordIdInspect; + (StringRecordId.prototype as any)[util.inspect.custom] = customRecordIdInspect; + }); +}