export type TopologyNodeOperationalState = | "healthy" | "degraded" | "disabled" | "draining" | "maintenance" | "failed" | "unknown"; export interface TopologyNodeOperationalStateLike { disabled?: boolean; status?: string | null; } const operationalStateAlias: Record = { healthy: "healthy", watch: "degraded", degraded: "degraded", disabled: "disabled", draining: "draining", maintenance: "maintenance", failed: "failed", unknown: "unknown", }; const traversableStates = new Set([ "healthy", "degraded", "unknown", "draining", ]); const routingCostByState: Record = { healthy: 1, degraded: 5, unknown: 10, draining: 20, disabled: Number.POSITIVE_INFINITY, maintenance: Number.POSITIVE_INFINITY, failed: Number.POSITIVE_INFINITY, }; export function resolveTopologyNodeOperationalState( node: TopologyNodeOperationalStateLike, ): TopologyNodeOperationalState { if (node.disabled) { return "disabled"; } const normalized = node.status?.trim().toLowerCase(); if (!normalized) { return "healthy"; } return operationalStateAlias[normalized] ?? "unknown"; } export function isTopologyNodeTraversable( node: TopologyNodeOperationalStateLike, ) { return traversableStates.has(resolveTopologyNodeOperationalState(node)); } export function getTopologyNodeRoutingCost( node: TopologyNodeOperationalStateLike, ) { return routingCostByState[resolveTopologyNodeOperationalState(node)]; }