* Serialize for persistence to .codebase-context/intelligence.json
()
| 862 | * Serialize for persistence to .codebase-context/intelligence.json |
| 863 | */ |
| 864 | toJSON(): { |
| 865 | imports: Record<string, string[]>; |
| 866 | exports: Record<string, FileExport[]>; |
| 867 | importDetails?: Record<string, Record<string, ImportEdgeDetail>>; |
| 868 | stats: { files: number; edges: number; avgDependencies: number }; |
| 869 | } { |
| 870 | const imports: Record<string, string[]> = {}; |
| 871 | for (const [file, deps] of this.imports.entries()) { |
| 872 | imports[file] = Array.from(deps); |
| 873 | } |
| 874 | |
| 875 | const exports: Record<string, FileExport[]> = {}; |
| 876 | for (const [file, exps] of this.exports.entries()) { |
| 877 | exports[file] = exps; |
| 878 | } |
| 879 | |
| 880 | const importDetails: Record<string, Record<string, ImportEdgeDetail>> = {}; |
| 881 | for (const [fromFile, edges] of this.importDetails.entries()) { |
| 882 | const nested: Record<string, ImportEdgeDetail> = {}; |
| 883 | for (const [toFile, detail] of edges.entries()) { |
| 884 | if (!detail.line && (!detail.importedSymbols || detail.importedSymbols.length === 0)) |
| 885 | continue; |
| 886 | nested[toFile] = detail; |
| 887 | } |
| 888 | if (Object.keys(nested).length > 0) { |
| 889 | importDetails[fromFile] = nested; |
| 890 | } |
| 891 | } |
| 892 | |
| 893 | return { |
| 894 | imports, |
| 895 | exports, |
| 896 | ...(Object.keys(importDetails).length > 0 ? { importDetails } : {}), |
| 897 | stats: this.getStats() |
| 898 | }; |
| 899 | } |
| 900 | |
| 901 | /** |
| 902 | * Restore from JSON (for loading from .codebase-context/intelligence.json) |
no test coverage detected