All files / server/services registry-logic.ts

100% Statements 16/16
85.71% Branches 12/14
100% Functions 3/3
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20      4x 4x 2x 4x 2x       344x 344x 344x 342x 342x   344x    
import type { IOPinRecord } from "@shared/schema";
 
export function mergeRegistryUsage(existing: IOPinRecord["usedAt"], incoming: IOPinRecord["usedAt"]): IOPinRecord["usedAt"] {
  const merged = [...(existing ?? []), ...(incoming ?? [])];
  if (merged.length === 0) return undefined;
  const unique = new Map<string, (typeof merged)[number]>();
  for (const entry of merged) unique.set(`${entry.operation}@${entry.line}`, entry);
  return [...unique.values()];
}
 
export function cleanRegistryRecord(pin: IOPinRecord): IOPinRecord {
  const cleaned = { ...pin };
  if (cleaned.definedAt?.line === 0) delete cleaned.definedAt;
  if (cleaned.usedAt) {
    cleaned.usedAt = cleaned.usedAt.filter((entry) => entry.line !== 0 || !!entry.operation);
    if (cleaned.usedAt.length === 0) delete cleaned.usedAt;
  }
  return cleaned;
}