Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ export * from "./errors";
export * from "./types";
export * from "./utils";
export * from "./value";

import { setUpCustomInspectors } from "./inspect";

setUpCustomInspectors();
25 changes: 25 additions & 0 deletions packages/sdk/src/inspect.ts
Original file line number Diff line number Diff line change
@@ -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;
});
}