(hops: readonly WireTrailHop[])
| 222 | * nothing the viewer can draw. |
| 223 | */ |
| 224 | export function encodeResolvedRun(hops: readonly WireTrailHop[]): { |
| 225 | encoded: string | null; |
| 226 | openFrom: number; |
| 227 | openCount: number; |
| 228 | openId: string | null; |
| 229 | } { |
| 230 | let bestStart = -1; |
| 231 | let bestLength = 0; |
| 232 | let start = -1; |
| 233 | for (let i = 0; i <= hops.length; i += 1) { |
| 234 | const resolved = i < hops.length && (hops[i] as WireTrailHop).id !== null; |
| 235 | if (resolved) { |
| 236 | if (start < 0) start = i; |
| 237 | continue; |
| 238 | } |
| 239 | if (start >= 0 && i - start > bestLength) { |
| 240 | bestStart = start; |
| 241 | bestLength = i - start; |
| 242 | } |
| 243 | start = -1; |
| 244 | } |
| 245 | if (bestLength === 0) return { encoded: null, openFrom: 0, openCount: 0, openId: null }; |
| 246 | |
| 247 | const run = hops.slice(bestStart, bestStart + bestLength); |
| 248 | const encoded = run |
| 249 | .map((hop, index) => `${index === 0 ? 's' : DIR_CHAR[hop.dir]}${encodeURIComponent(hop.id as string)}`) |
| 250 | .join(','); |
| 251 | return { |
| 252 | encoded, |
| 253 | openFrom: bestStart + 1, |
| 254 | openCount: bestLength, |
| 255 | openId: (run[run.length - 1] as WireTrailHop).id, |
| 256 | }; |
| 257 | } |
| 258 | |
| 259 | export function resolveTrail(cg: CodeGraph, stored: StoredTrail): WireTrail { |
| 260 | const hops = stored.hops.map((hop) => resolveHop(cg, hop)); |
no test coverage detected