import { inspect } from "node:util"; /** Persisted JSON and event payloads enter background lifecycle code here. */ export function isRecord(value: unknown): value is Readonly> { return typeof value === "object" && value !== null && !Array.isArray(value); } export function errorCode(error: unknown): string | undefined { return isRecord(error) && typeof error.code === "string" ? error.code : undefined; } export function errorMessage(error: unknown): string { if (error instanceof Error) { return error.message; } return typeof error === "string" ? error : inspect(error); } export function hasText(value: string | null | undefined): value is string { return value !== undefined && value !== null && value.length > 0; } export function stringField( record: Readonly>, key: string, ): string | undefined { const value = record[key]; return typeof value === "string" ? value : undefined; }