import type { BackendMetricsRow } from "./backend-metrics-client"; export type BackendMetricsSearchRequestMessage = { type: "backend-metrics:search"; value: { starIds: string[]; }; }; export type BackendMetricsResponseMessage = | { ok: true; type: "backend-metrics:result"; value: { rows: BackendMetricsRow[]; }; } | { error: string; ok: false; type: "backend-metrics:error"; }; export function isBackendMetricsSearchRequestMessage( value: unknown ): value is BackendMetricsSearchRequestMessage { if (!value || typeof value !== "object") { return false; } const candidate = value as Partial; return ( candidate.type === "backend-metrics:search" && Boolean( candidate.value && typeof candidate.value === "object" && Array.isArray((candidate.value as { starIds?: unknown }).starIds) && (candidate.value as { starIds: unknown[] }).starIds.every( (starId) => typeof starId === "string" ) ) ); } export function isBackendMetricsResponseMessage( value: unknown ): value is BackendMetricsResponseMessage { if (!value || typeof value !== "object") { return false; } const candidate = value as Partial; if (candidate.ok === false) { return ( candidate.type === "backend-metrics:error" && typeof candidate.error === "string" ); } return Boolean( candidate.ok === true && candidate.type === "backend-metrics:result" && candidate.value && typeof candidate.value === "object" && Array.isArray((candidate.value as { rows?: unknown }).rows) ); }