Classify a graph node for Mermaid styling and table tags.
(node: dict)
| 500 | |
| 501 | |
| 502 | def node_kind(node: dict) -> str: |
| 503 | """Classify a graph node for Mermaid styling and table tags.""" |
| 504 | label = str(node.get("label") or node.get("id") or "").lower() |
| 505 | source_file = str(node.get("source_file") or "").lower() |
| 506 | file_type = str(node.get("file_type") or "").lower() |
| 507 | node_type = str(node.get("node_type") or "").lower() |
| 508 | if node_type in {"class", "klass", "struct", "interface", "enum", "trait", "model"}: |
| 509 | return "klass" |
| 510 | if node_type in {"module", "file", "package", "namespace"}: |
| 511 | return "module" |
| 512 | if node_type in {"endpoint", "route", "api", "handler", "controller"}: |
| 513 | return "api" |
| 514 | if node_type in {"test", "spec"}: |
| 515 | return "test" |
| 516 | if node_type in {"component", "hook", "view", "page"}: |
| 517 | return "ui" |
| 518 | if file_type in {"rationale", "document"}: |
| 519 | return "concept" |
| 520 | if "test" in source_file or label.startswith("test_") or "spec" in source_file: |
| 521 | return "test" |
| 522 | if any(word in label for word in ("endpoint", "router", "api", "route")): |
| 523 | return "api" |
| 524 | if any(word in label for word in ("cli", "command", "click", "typer")): |
| 525 | return "entry" |
| 526 | if any(word in label for word in ("async", "await", "stream", "sse")): |
| 527 | return "async" |
| 528 | raw_label = str(node.get("label") or "") |
| 529 | hook_like = raw_label.startswith("use") and len(raw_label) > 3 and (raw_label[3].isupper() or raw_label[3] in "_-") |
| 530 | if any(word in label for word in ("component", "props", "hook", "store")) or hook_like or source_file.endswith((".tsx", ".jsx", ".vue", ".svelte")): |
| 531 | return "ui" |
| 532 | raw = raw_label |
| 533 | if raw[:1].isupper() and not raw.endswith("()"): |
| 534 | return "klass" |
| 535 | if raw.endswith((".py", ".ts", ".tsx", ".js", ".jsx", ".go", ".rs", ".java", ".kt", ".rb", ".php", ".cs", ".swift", ".vue", ".svelte")): |
| 536 | return "module" |
| 537 | return "function" |
| 538 | |
| 539 | |
| 540 | def relation_label(relation: str, lang: str) -> str: |
no test coverage detected