MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / buildOrderModel

Function buildOrderModel

ui/src/lib/program-model.ts:328–465  ·  view source on GitHub ↗
(payload: WireStepsPayload)

Source from the content-addressed store, hash-verified

326 * when the anchor has no body to read — the view then offers the tree.
327 */
328export function buildOrderModel(payload: WireStepsPayload): StepsModel | null {
329 if (!payload.program) return null;
330 const anchorStep = payload.steps.find((s) => s.anchor);
331 if (!anchorStep) return null;
332 const graph = orderGraph(payload.program, anchorStep.id);
333
334 const nodes = new Map<string, StepNodeInfo>();
335 const forks = new Map<string, StepForkInfo>();
336 const modules: WireMapModule[] = [];
337 const counts: StepsModel['counts'] = { anchor: 0, screen: 0, trigger: 0, bridge: 0, event: 0, store: 0, effect: 0 };
338 const degree = new Map<string, number>();
339 for (const e of graph.edges) {
340 degree.set(e.from, (degree.get(e.from) ?? 0) + 1);
341 degree.set(e.to, (degree.get(e.to) ?? 0) + 1);
342 }
343 const byId = new Map(payload.steps.map((s) => [s.id, s]));
344 for (const id of [anchorStep.id, ...graph.depth.keys()]) {
345 if (nodes.has(id)) continue;
346 const step: WireStep | undefined = byId.get(id);
347 if (!step) continue;
348 counts[step.kind]++;
349 const info: StepNodeInfo = { id, step, label: stepLabel(step), sub: stepSub(step, payload.project) };
350 nodes.set(id, info);
351 modules.push({
352 id,
353 label: info.label,
354 files: 1,
355 symbols: degree.get(id) ?? 0,
356 languages: [],
357 test: false,
358 generated: 0,
359 generatedFiles: [],
360 facade: false,
361 fileList: { total: 1, shown: 1, truncated: false, items: [step.node?.file ?? step.sub] },
362 dependents: { files: 0, modules: 0 },
363 });
364 }
365 // Each decision is a point of its own on the canvas: a small box asking the
366 // condition once, where the arms diverge.
367 for (const f of graph.forks) {
368 const label = forkLabel(f.on);
369 forks.set(f.id, { id: f.id, on: f.on, form: f.form, label });
370 modules.push({
371 id: f.id,
372 label,
373 files: 0,
374 symbols: degree.get(f.id) ?? 0,
375 languages: [],
376 test: false,
377 generated: 0,
378 generatedFiles: [],
379 facade: false,
380 fileList: { total: 0, shown: 0, truncated: false, items: [] },
381 dependents: { files: 0, modules: 0 },
382 });
383 }
384 const drawn = (id: string): boolean => nodes.has(id) || forks.has(id);
385

Callers 1

Calls 15

stepLabelFunction · 0.90
stepSubFunction · 0.90
linkIdFunction · 0.90
buildMapLayoutFunction · 0.90
trackedCurvesFunction · 0.90
samplePolylineFunction · 0.90
orderGraphFunction · 0.85
forkLabelFunction · 0.85
drawnFunction · 0.85
lineWordsFunction · 0.85
mapMethod · 0.80
hasMethod · 0.80

Tested by

no test coverage detected