refactor: dedupe tlon monitor string helper

This commit is contained in:
Peter Steinberger
2026-04-06 22:36:44 +01:00
parent e88c39b0a1
commit 0cc4f50576
2 changed files with 6 additions and 8 deletions

View File

@@ -28,7 +28,7 @@ import {
mergeUniqueStrings,
shouldMigrateTlonSetting,
} from "./settings-helpers.js";
import { asRecord, formatErrorMessage } from "./utils.js";
import { asRecord, formatErrorMessage, readString } from "./utils.js";
import {
extractMessageText,
formatModelName,
@@ -46,11 +46,6 @@ export type MonitorTlonOpts = {
accountId?: string | null;
};
function readString(record: Record<string, unknown> | null, key: string): string | undefined {
const value = record?.[key];
return typeof value === "string" ? value : undefined;
}
function readNumber(record: Record<string, unknown> | null, key: string): number | undefined {
const value = record?.[key];
return typeof value === "number" && Number.isFinite(value) ? value : undefined;

View File

@@ -189,8 +189,11 @@ export function formatErrorMessage(error: unknown): string {
return error instanceof Error ? error.message : String(error);
}
function readString(record: Record<string, unknown>, key: string): string | undefined {
const value = record[key];
export function readString(
record: Record<string, unknown> | null,
key: string,
): string | undefined {
const value = record?.[key];
return typeof value === "string" ? value : undefined;
}