@ankhorage/dependency-graph 0.7.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +12 -3
- package/dist/dependencyGraph.d.ts +14 -9
- package/dist/dependencyGraph.d.ts.map +1 -1
- package/dist/dependencyGraph.js +12 -8
- package/dist/dependencyGraph.js.map +1 -1
- package/dist/features/dependency-analysis/adapters/outbound/cpp/extractCppDependencies.d.ts +2 -1
- package/dist/features/dependency-analysis/adapters/outbound/cpp/extractCppDependencies.d.ts.map +1 -1
- package/dist/features/dependency-analysis/adapters/outbound/cpp/extractCppDependencies.js.map +1 -1
- package/dist/features/dependency-analysis/adapters/outbound/java/extractJavaSourceFacts.d.ts +4 -0
- package/dist/features/dependency-analysis/adapters/outbound/java/extractJavaSourceFacts.d.ts.map +1 -0
- package/dist/features/dependency-analysis/adapters/outbound/java/extractJavaSourceFacts.js +201 -0
- package/dist/features/dependency-analysis/adapters/outbound/java/extractJavaSourceFacts.js.map +1 -0
- package/dist/features/dependency-analysis/adapters/outbound/typescript/extractTypeScriptSourceFacts.d.ts +4 -0
- package/dist/features/dependency-analysis/adapters/outbound/typescript/extractTypeScriptSourceFacts.d.ts.map +1 -0
- package/dist/features/dependency-analysis/adapters/outbound/typescript/extractTypeScriptSourceFacts.js +159 -0
- package/dist/features/dependency-analysis/adapters/outbound/typescript/extractTypeScriptSourceFacts.js.map +1 -0
- package/dist/features/dependency-analysis/application/assertDependencyGraphInspections.d.ts +4 -0
- package/dist/features/dependency-analysis/application/assertDependencyGraphInspections.d.ts.map +1 -0
- package/dist/features/dependency-analysis/application/assertDependencyGraphInspections.js +13 -0
- package/dist/features/dependency-analysis/application/assertDependencyGraphInspections.js.map +1 -0
- package/dist/features/dependency-analysis/application/projectDependencyGraphFromInspections.d.ts +5 -0
- package/dist/features/dependency-analysis/application/projectDependencyGraphFromInspections.d.ts.map +1 -0
- package/dist/features/dependency-analysis/application/projectDependencyGraphFromInspections.js +43 -0
- package/dist/features/dependency-analysis/application/projectDependencyGraphFromInspections.js.map +1 -0
- package/dist/features/dependency-analysis/{application → composition}/createDependencyGraphAsync.d.ts.map +1 -1
- package/dist/features/dependency-analysis/{application → composition}/createDependencyGraphAsync.js +1 -2
- package/dist/features/dependency-analysis/composition/createDependencyGraphAsync.js.map +1 -0
- package/dist/features/dependency-analysis/{application → composition}/createDependencyGraphFromInspectionsAsync.d.ts +1 -3
- package/dist/features/dependency-analysis/composition/createDependencyGraphFromInspectionsAsync.d.ts.map +1 -0
- package/dist/features/dependency-analysis/composition/createDependencyGraphFromInspectionsAsync.js +13 -0
- package/dist/features/dependency-analysis/composition/createDependencyGraphFromInspectionsAsync.js.map +1 -0
- package/dist/features/dependency-analysis/domain/extractCppPackageFromInclude.d.ts.map +1 -0
- package/dist/features/dependency-analysis/domain/extractCppPackageFromInclude.js.map +1 -0
- package/dist/features/dependency-analysis/domain/extractDelphiPackageFromImport.d.ts.map +1 -0
- package/dist/features/dependency-analysis/domain/extractDelphiPackageFromImport.js.map +1 -0
- package/dist/features/dependency-analysis/domain/extractJavaPackageFromImport.d.ts +3 -0
- package/dist/features/dependency-analysis/domain/extractJavaPackageFromImport.d.ts.map +1 -0
- package/dist/features/dependency-analysis/{adapters/outbound/java → domain}/extractJavaPackageFromImport.js +1 -1
- package/dist/features/dependency-analysis/domain/extractJavaPackageFromImport.js.map +1 -0
- package/dist/features/dependency-analysis/domain/extractKotlinPackageFromImport.d.ts.map +1 -0
- package/dist/features/dependency-analysis/domain/extractKotlinPackageFromImport.js.map +1 -0
- package/dist/features/dependency-analysis/domain/extractPythonPackageFromImport.d.ts.map +1 -0
- package/dist/features/dependency-analysis/domain/extractPythonPackageFromImport.js.map +1 -0
- package/dist/features/dependency-analysis/domain/projectDependencyGraphFromSourceGraph.d.ts +5 -0
- package/dist/features/dependency-analysis/domain/projectDependencyGraphFromSourceGraph.d.ts.map +1 -0
- package/dist/features/dependency-analysis/domain/projectDependencyGraphFromSourceGraph.js +144 -0
- package/dist/features/dependency-analysis/domain/projectDependencyGraphFromSourceGraph.js.map +1 -0
- package/dist/features/source-graph/adapters/outbound/extractOtherLanguageFacts.d.ts +4 -0
- package/dist/features/source-graph/adapters/outbound/extractOtherLanguageFacts.d.ts.map +1 -0
- package/dist/features/source-graph/adapters/outbound/extractOtherLanguageFacts.js +36 -0
- package/dist/features/source-graph/adapters/outbound/extractOtherLanguageFacts.js.map +1 -0
- package/dist/features/source-graph/composition/createSourceGraphAsync.d.ts +4 -0
- package/dist/features/source-graph/composition/createSourceGraphAsync.d.ts.map +1 -0
- package/dist/features/source-graph/composition/createSourceGraphAsync.js +16 -0
- package/dist/features/source-graph/composition/createSourceGraphAsync.js.map +1 -0
- package/dist/features/source-graph/composition/createSourceGraphFromInspectionsAsync.d.ts +4 -0
- package/dist/features/source-graph/composition/createSourceGraphFromInspectionsAsync.d.ts.map +1 -0
- package/dist/features/source-graph/composition/createSourceGraphFromInspectionsAsync.js +118 -0
- package/dist/features/source-graph/composition/createSourceGraphFromInspectionsAsync.js.map +1 -0
- package/dist/features/source-graph/domain/createSourceGraph.d.ts +4 -0
- package/dist/features/source-graph/domain/createSourceGraph.d.ts.map +1 -0
- package/dist/features/source-graph/domain/createSourceGraph.js +73 -0
- package/dist/features/source-graph/domain/createSourceGraph.js.map +1 -0
- package/dist/features/source-graph/domain/createSourceGraphIndex.d.ts +4 -0
- package/dist/features/source-graph/domain/createSourceGraphIndex.d.ts.map +1 -0
- package/dist/features/source-graph/domain/createSourceGraphIndex.js +57 -0
- package/dist/features/source-graph/domain/createSourceGraphIndex.js.map +1 -0
- package/dist/features/source-graph/domain/createSourceRelationDraft.d.ts +4 -0
- package/dist/features/source-graph/domain/createSourceRelationDraft.d.ts.map +1 -0
- package/dist/features/source-graph/domain/createSourceRelationDraft.js +119 -0
- package/dist/features/source-graph/domain/createSourceRelationDraft.js.map +1 -0
- package/dist/features/source-graph/domain/createSourceRollupIndex.d.ts +8 -0
- package/dist/features/source-graph/domain/createSourceRollupIndex.d.ts.map +1 -0
- package/dist/features/source-graph/domain/createSourceRollupIndex.js +27 -0
- package/dist/features/source-graph/domain/createSourceRollupIndex.js.map +1 -0
- package/dist/features/source-graph/domain/createSourceStructureDraft.d.ts +11 -0
- package/dist/features/source-graph/domain/createSourceStructureDraft.d.ts.map +1 -0
- package/dist/features/source-graph/domain/createSourceStructureDraft.js +238 -0
- package/dist/features/source-graph/domain/createSourceStructureDraft.js.map +1 -0
- package/dist/features/source-graph/domain/querySourceGraph.d.ts +15 -0
- package/dist/features/source-graph/domain/querySourceGraph.d.ts.map +1 -0
- package/dist/features/source-graph/domain/querySourceGraph.js +40 -0
- package/dist/features/source-graph/domain/querySourceGraph.js.map +1 -0
- package/dist/features/source-graph/domain/resolveSourceImport.d.ts +9 -0
- package/dist/features/source-graph/domain/resolveSourceImport.d.ts.map +1 -0
- package/dist/features/source-graph/domain/resolveSourceImport.js +146 -0
- package/dist/features/source-graph/domain/resolveSourceImport.js.map +1 -0
- package/dist/features/source-graph/domain/rollupSourceRelations.d.ts +4 -0
- package/dist/features/source-graph/domain/rollupSourceRelations.d.ts.map +1 -0
- package/dist/features/source-graph/domain/rollupSourceRelations.js +46 -0
- package/dist/features/source-graph/domain/rollupSourceRelations.js.map +1 -0
- package/dist/features/source-graph/domain/serializeSourceGraph.d.ts +6 -0
- package/dist/features/source-graph/domain/serializeSourceGraph.d.ts.map +1 -0
- package/dist/features/source-graph/domain/serializeSourceGraph.js +64 -0
- package/dist/features/source-graph/domain/serializeSourceGraph.js.map +1 -0
- package/dist/features/source-graph/domain/sourceSemanticPath.d.ts +3 -0
- package/dist/features/source-graph/domain/sourceSemanticPath.d.ts.map +1 -0
- package/dist/features/source-graph/domain/sourceSemanticPath.js +5 -0
- package/dist/features/source-graph/domain/sourceSemanticPath.js.map +1 -0
- package/dist/features/source-graph/domain/summarizeSourceNode.d.ts +4 -0
- package/dist/features/source-graph/domain/summarizeSourceNode.d.ts.map +1 -0
- package/dist/features/source-graph/domain/summarizeSourceNode.js +66 -0
- package/dist/features/source-graph/domain/summarizeSourceNode.js.map +1 -0
- package/dist/types/dependencyGraph.d.ts +2 -23
- package/dist/types/dependencyGraph.d.ts.map +1 -1
- package/dist/types/dependencyGraph.js.map +1 -1
- package/dist/types/sourceGraph.d.ts +173 -0
- package/dist/types/sourceGraph.d.ts.map +1 -0
- package/dist/types/sourceGraph.js +2 -0
- package/dist/types/sourceGraph.js.map +1 -0
- package/package.json +6 -4
- package/dist/features/dependency-analysis/adapters/outbound/cpp/analyzeCppProjectAsync.d.ts +0 -4
- package/dist/features/dependency-analysis/adapters/outbound/cpp/analyzeCppProjectAsync.d.ts.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/cpp/analyzeCppProjectAsync.js +0 -103
- package/dist/features/dependency-analysis/adapters/outbound/cpp/analyzeCppProjectAsync.js.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/cpp/cppDependencyGraphAnalyzer.d.ts +0 -4
- package/dist/features/dependency-analysis/adapters/outbound/cpp/cppDependencyGraphAnalyzer.d.ts.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/cpp/cppDependencyGraphAnalyzer.js +0 -8
- package/dist/features/dependency-analysis/adapters/outbound/cpp/cppDependencyGraphAnalyzer.js.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/cpp/extractCppPackageFromInclude.d.ts.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/cpp/extractCppPackageFromInclude.js.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/delphi/analyzeDelphiProjectAsync.d.ts +0 -4
- package/dist/features/dependency-analysis/adapters/outbound/delphi/analyzeDelphiProjectAsync.d.ts.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/delphi/analyzeDelphiProjectAsync.js +0 -105
- package/dist/features/dependency-analysis/adapters/outbound/delphi/analyzeDelphiProjectAsync.js.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/delphi/delphiDependencyGraphAnalyzer.d.ts +0 -4
- package/dist/features/dependency-analysis/adapters/outbound/delphi/delphiDependencyGraphAnalyzer.d.ts.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/delphi/delphiDependencyGraphAnalyzer.js +0 -8
- package/dist/features/dependency-analysis/adapters/outbound/delphi/delphiDependencyGraphAnalyzer.js.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/delphi/extractDelphiPackageFromImport.d.ts.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/delphi/extractDelphiPackageFromImport.js.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/java/analyzeJavaProjectAsync.d.ts +0 -4
- package/dist/features/dependency-analysis/adapters/outbound/java/analyzeJavaProjectAsync.d.ts.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/java/analyzeJavaProjectAsync.js +0 -103
- package/dist/features/dependency-analysis/adapters/outbound/java/analyzeJavaProjectAsync.js.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/java/extractJavaDependencies.d.ts +0 -7
- package/dist/features/dependency-analysis/adapters/outbound/java/extractJavaDependencies.d.ts.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/java/extractJavaDependencies.js +0 -7
- package/dist/features/dependency-analysis/adapters/outbound/java/extractJavaDependencies.js.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/java/extractJavaPackageFromImport.d.ts +0 -3
- package/dist/features/dependency-analysis/adapters/outbound/java/extractJavaPackageFromImport.d.ts.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/java/extractJavaPackageFromImport.js.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/java/javaDependencyGraphAnalyzer.d.ts +0 -4
- package/dist/features/dependency-analysis/adapters/outbound/java/javaDependencyGraphAnalyzer.d.ts.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/java/javaDependencyGraphAnalyzer.js +0 -8
- package/dist/features/dependency-analysis/adapters/outbound/java/javaDependencyGraphAnalyzer.js.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/kotlin/analyzeKotlinProjectAsync.d.ts +0 -4
- package/dist/features/dependency-analysis/adapters/outbound/kotlin/analyzeKotlinProjectAsync.d.ts.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/kotlin/analyzeKotlinProjectAsync.js +0 -103
- package/dist/features/dependency-analysis/adapters/outbound/kotlin/analyzeKotlinProjectAsync.js.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/kotlin/extractKotlinPackageFromImport.d.ts.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/kotlin/extractKotlinPackageFromImport.js.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/kotlin/kotlinDependencyGraphAnalyzer.d.ts +0 -4
- package/dist/features/dependency-analysis/adapters/outbound/kotlin/kotlinDependencyGraphAnalyzer.d.ts.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/kotlin/kotlinDependencyGraphAnalyzer.js +0 -8
- package/dist/features/dependency-analysis/adapters/outbound/kotlin/kotlinDependencyGraphAnalyzer.js.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/python/analyzePythonProjectAsync.d.ts +0 -4
- package/dist/features/dependency-analysis/adapters/outbound/python/analyzePythonProjectAsync.d.ts.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/python/analyzePythonProjectAsync.js +0 -103
- package/dist/features/dependency-analysis/adapters/outbound/python/analyzePythonProjectAsync.js.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/python/extractPythonPackageFromImport.d.ts.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/python/extractPythonPackageFromImport.js.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/python/pythonDependencyGraphAnalyzer.d.ts +0 -4
- package/dist/features/dependency-analysis/adapters/outbound/python/pythonDependencyGraphAnalyzer.d.ts.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/python/pythonDependencyGraphAnalyzer.js +0 -8
- package/dist/features/dependency-analysis/adapters/outbound/python/pythonDependencyGraphAnalyzer.js.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/typescript/analyzeTypeScriptProjectAsync.d.ts +0 -4
- package/dist/features/dependency-analysis/adapters/outbound/typescript/analyzeTypeScriptProjectAsync.d.ts.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/typescript/analyzeTypeScriptProjectAsync.js +0 -92
- package/dist/features/dependency-analysis/adapters/outbound/typescript/analyzeTypeScriptProjectAsync.js.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/typescript/createTypeScriptModuleNodes.d.ts +0 -5
- package/dist/features/dependency-analysis/adapters/outbound/typescript/createTypeScriptModuleNodes.d.ts.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/typescript/createTypeScriptModuleNodes.js +0 -29
- package/dist/features/dependency-analysis/adapters/outbound/typescript/createTypeScriptModuleNodes.js.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/typescript/extractTypeScriptImports.d.ts +0 -3
- package/dist/features/dependency-analysis/adapters/outbound/typescript/extractTypeScriptImports.d.ts.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/typescript/extractTypeScriptImports.js +0 -9
- package/dist/features/dependency-analysis/adapters/outbound/typescript/extractTypeScriptImports.js.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/typescript/modulePathForFile.d.ts +0 -3
- package/dist/features/dependency-analysis/adapters/outbound/typescript/modulePathForFile.d.ts.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/typescript/modulePathForFile.js +0 -8
- package/dist/features/dependency-analysis/adapters/outbound/typescript/modulePathForFile.js.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/typescript/resolveTypeScriptImport.d.ts +0 -11
- package/dist/features/dependency-analysis/adapters/outbound/typescript/resolveTypeScriptImport.d.ts.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/typescript/resolveTypeScriptImport.js +0 -85
- package/dist/features/dependency-analysis/adapters/outbound/typescript/resolveTypeScriptImport.js.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/typescript/typescriptDependencyGraphAnalyzer.d.ts +0 -4
- package/dist/features/dependency-analysis/adapters/outbound/typescript/typescriptDependencyGraphAnalyzer.d.ts.map +0 -1
- package/dist/features/dependency-analysis/adapters/outbound/typescript/typescriptDependencyGraphAnalyzer.js +0 -8
- package/dist/features/dependency-analysis/adapters/outbound/typescript/typescriptDependencyGraphAnalyzer.js.map +0 -1
- package/dist/features/dependency-analysis/application/createDependencyGraphAsync.js.map +0 -1
- package/dist/features/dependency-analysis/application/createDependencyGraphFromInspectionsAsync.d.ts.map +0 -1
- package/dist/features/dependency-analysis/application/createDependencyGraphFromInspectionsAsync.js +0 -111
- package/dist/features/dependency-analysis/application/createDependencyGraphFromInspectionsAsync.js.map +0 -1
- package/dist/features/dependency-analysis/utils/collectInspectedSourceFiles.d.ts +0 -4
- package/dist/features/dependency-analysis/utils/collectInspectedSourceFiles.d.ts.map +0 -1
- package/dist/features/dependency-analysis/utils/collectInspectedSourceFiles.js +0 -36
- package/dist/features/dependency-analysis/utils/collectInspectedSourceFiles.js.map +0 -1
- package/dist/features/dependency-analysis/utils/findIntrinsicPackageForReference.d.ts +0 -3
- package/dist/features/dependency-analysis/utils/findIntrinsicPackageForReference.d.ts.map +0 -1
- package/dist/features/dependency-analysis/utils/findIntrinsicPackageForReference.js +0 -8
- package/dist/features/dependency-analysis/utils/findIntrinsicPackageForReference.js.map +0 -1
- /package/dist/features/dependency-analysis/{application → composition}/createDependencyGraphAsync.d.ts +0 -0
- /package/dist/features/dependency-analysis/{adapters/outbound/cpp → domain}/extractCppPackageFromInclude.d.ts +0 -0
- /package/dist/features/dependency-analysis/{adapters/outbound/cpp → domain}/extractCppPackageFromInclude.js +0 -0
- /package/dist/features/dependency-analysis/{adapters/outbound/delphi → domain}/extractDelphiPackageFromImport.d.ts +0 -0
- /package/dist/features/dependency-analysis/{adapters/outbound/delphi → domain}/extractDelphiPackageFromImport.js +0 -0
- /package/dist/features/dependency-analysis/{adapters/outbound/kotlin → domain}/extractKotlinPackageFromImport.d.ts +0 -0
- /package/dist/features/dependency-analysis/{adapters/outbound/kotlin → domain}/extractKotlinPackageFromImport.js +0 -0
- /package/dist/features/dependency-analysis/{adapters/outbound/python → domain}/extractPythonPackageFromImport.d.ts +0 -0
- /package/dist/features/dependency-analysis/{adapters/outbound/python → domain}/extractPythonPackageFromImport.js +0 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { sourceSemanticPath } from './sourceSemanticPath.js';
|
|
3
|
+
/*** Preserve scanned projects, packages, empty directories, files, and nested declarations. */
|
|
4
|
+
export function createSourceStructureDraft(projects, files) {
|
|
5
|
+
const nodes = new Map();
|
|
6
|
+
const edges = [];
|
|
7
|
+
for (const project of projects)
|
|
8
|
+
addProject(project, files, nodes, edges);
|
|
9
|
+
return {
|
|
10
|
+
nodes: [...nodes.values()],
|
|
11
|
+
edges,
|
|
12
|
+
capabilities: projects.flatMap(({ id, inspection }) => {
|
|
13
|
+
const analyzers = new Set([
|
|
14
|
+
'project-detector',
|
|
15
|
+
...inspection.detection.languages.map(({ id: languageId }) => languageId),
|
|
16
|
+
...files.filter((file) => file.projectId === id).map((file) => file.analyzerId),
|
|
17
|
+
]);
|
|
18
|
+
return [...analyzers].map((analyzerId) => ({
|
|
19
|
+
projectId: id,
|
|
20
|
+
analyzerId,
|
|
21
|
+
available: analyzerCapabilities(analyzerId),
|
|
22
|
+
}));
|
|
23
|
+
}),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/*** Add the physical containment tree for one inspected project. */
|
|
27
|
+
function addProject(project, analyzedFiles, nodes, edges) {
|
|
28
|
+
const { id, inspection } = project;
|
|
29
|
+
if (!inspection.complete)
|
|
30
|
+
throw new Error(`Source graph inspection is incomplete for ${id}.`);
|
|
31
|
+
const projectKey = sourceSemanticPath('project', id);
|
|
32
|
+
addNode(nodes, { semanticPath: projectKey, kind: 'project', name: id, projectId: id });
|
|
33
|
+
const packageRoots = new Set(['.', ...inspection.packages.map(({ rootPath }) => rootPath)]);
|
|
34
|
+
addPackages(project, packageRoots, projectKey, nodes, edges);
|
|
35
|
+
addDirectories(project, packageRoots, nodes, edges);
|
|
36
|
+
addFiles(project, packageRoots, nodes, edges);
|
|
37
|
+
for (const file of analyzedFiles.filter((item) => item.projectId === id)) {
|
|
38
|
+
addFileFacts(file, nodes, edges);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/*** Preserve package and workspace roots as explicit containment boundaries. */
|
|
42
|
+
function addPackages(project, packageRoots, projectKey, nodes, edges) {
|
|
43
|
+
const { id, inspection } = project;
|
|
44
|
+
for (const root of packageRoots) {
|
|
45
|
+
const key = packageKey(id, root);
|
|
46
|
+
const name = inspection.packages.find(({ rootPath }) => rootPath === root)?.name ?? root;
|
|
47
|
+
addNode(nodes, {
|
|
48
|
+
semanticPath: key,
|
|
49
|
+
kind: 'package',
|
|
50
|
+
name,
|
|
51
|
+
projectId: id,
|
|
52
|
+
path: root,
|
|
53
|
+
classification: 'intrinsic',
|
|
54
|
+
});
|
|
55
|
+
addContains(edges, projectKey, key, 'project-detector', root);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/*** Preserve empty directories and their exact scanned hierarchy. */
|
|
59
|
+
function addDirectories(project, packageRoots, nodes, edges) {
|
|
60
|
+
const { id, inspection } = project;
|
|
61
|
+
for (const directory of inspection.directories.filter((item) => item !== '.')) {
|
|
62
|
+
const root = owningPackageRoot(directory, packageRoots);
|
|
63
|
+
if (directory === root)
|
|
64
|
+
continue;
|
|
65
|
+
const key = directoryKey(id, directory);
|
|
66
|
+
addNode(nodes, {
|
|
67
|
+
semanticPath: key,
|
|
68
|
+
kind: 'directory',
|
|
69
|
+
name: path.posix.basename(directory),
|
|
70
|
+
projectId: id,
|
|
71
|
+
path: directory,
|
|
72
|
+
classification: 'intrinsic',
|
|
73
|
+
});
|
|
74
|
+
const parent = path.posix.dirname(directory);
|
|
75
|
+
addContains(edges, parent === root ? packageKey(id, root) : directoryKey(id, parent), key, 'project-detector', directory);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/*** Preserve all inspected files, including files without an implemented language parser. */
|
|
79
|
+
function addFiles(project, packageRoots, nodes, edges) {
|
|
80
|
+
const { id, inspection } = project;
|
|
81
|
+
for (const file of inspection.files) {
|
|
82
|
+
const root = owningPackageRoot(file, packageRoots);
|
|
83
|
+
const parent = path.posix.dirname(file);
|
|
84
|
+
const key = fileKey(id, file);
|
|
85
|
+
addNode(nodes, {
|
|
86
|
+
semanticPath: key,
|
|
87
|
+
kind: 'file',
|
|
88
|
+
name: path.posix.basename(file),
|
|
89
|
+
projectId: id,
|
|
90
|
+
path: file,
|
|
91
|
+
filePath: file,
|
|
92
|
+
classification: 'intrinsic',
|
|
93
|
+
});
|
|
94
|
+
addContains(edges, parent === root || parent === '.' ? packageKey(id, root) : directoryKey(id, parent), key, 'project-detector', file);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/*** Attach portable declarations and their observed documentation to a source file. */
|
|
98
|
+
function addFileFacts(file, nodes, edges) {
|
|
99
|
+
const parent = fileKey(file.projectId, file.path);
|
|
100
|
+
const fileNode = nodes.get(parent);
|
|
101
|
+
if (fileNode === undefined)
|
|
102
|
+
throw new Error(`Analyzed source file was not inspected: ${file.path}.`);
|
|
103
|
+
if (file.facts.packageName !== undefined && file.facts.packageName !== '') {
|
|
104
|
+
nodes.set(parent, {
|
|
105
|
+
data: { ...fileNode.data, analyzerId: file.analyzerId, packageName: file.facts.packageName },
|
|
106
|
+
});
|
|
107
|
+
const packagePath = addNamespaceHierarchy(file, nodes, edges);
|
|
108
|
+
addRelation(edges, parent, packagePath, 'declares-in', {
|
|
109
|
+
analyzerId: file.analyzerId,
|
|
110
|
+
sourcePath: file.path,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
else
|
|
114
|
+
nodes.set(parent, { data: { ...fileNode.data, analyzerId: file.analyzerId } });
|
|
115
|
+
for (const declaration of file.facts.declarations) {
|
|
116
|
+
addDeclaration(file, declaration, parent, nodes, edges);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/*** Materialize each observed namespace ancestor once for package-level queries. */
|
|
120
|
+
function addNamespaceHierarchy(file, nodes, edges) {
|
|
121
|
+
const segments = file.facts.packageName?.split('.') ?? [];
|
|
122
|
+
let parent = sourceSemanticPath('project', file.projectId);
|
|
123
|
+
let current = '';
|
|
124
|
+
for (const segment of segments) {
|
|
125
|
+
current = current === '' ? segment : `${current}.${segment}`;
|
|
126
|
+
const key = sourceSemanticPath('namespace', file.projectId, current);
|
|
127
|
+
if (!nodes.has(key)) {
|
|
128
|
+
addNode(nodes, {
|
|
129
|
+
semanticPath: key,
|
|
130
|
+
kind: 'package',
|
|
131
|
+
name: current,
|
|
132
|
+
projectId: file.projectId,
|
|
133
|
+
packageName: current,
|
|
134
|
+
classification: 'intrinsic',
|
|
135
|
+
});
|
|
136
|
+
addContains(edges, parent, key, file.analyzerId, file.path);
|
|
137
|
+
}
|
|
138
|
+
parent = key;
|
|
139
|
+
}
|
|
140
|
+
return parent;
|
|
141
|
+
}
|
|
142
|
+
/*** Materialize one nested declaration with a location-qualified stable identity. */
|
|
143
|
+
function addDeclaration(file, declaration, parent, nodes, edges) {
|
|
144
|
+
const key = sourceSemanticPath(parent, declaration.kind, declaration.name, `${declaration.location.line}:${declaration.location.column}`);
|
|
145
|
+
addNode(nodes, {
|
|
146
|
+
semanticPath: key,
|
|
147
|
+
kind: declaration.kind,
|
|
148
|
+
name: declaration.name,
|
|
149
|
+
projectId: file.projectId,
|
|
150
|
+
filePath: file.path,
|
|
151
|
+
...(file.facts.packageName === undefined ? {} : { packageName: file.facts.packageName }),
|
|
152
|
+
classification: 'intrinsic',
|
|
153
|
+
location: declaration.location,
|
|
154
|
+
visibility: declaration.visibility,
|
|
155
|
+
modifiers: declaration.modifiers,
|
|
156
|
+
...(declaration.signature === undefined ? {} : { signature: declaration.signature }),
|
|
157
|
+
...(declaration.documentation === undefined
|
|
158
|
+
? {}
|
|
159
|
+
: { documentation: declaration.documentation }),
|
|
160
|
+
...(declaration.typeOnly === undefined ? {} : { typeOnly: declaration.typeOnly }),
|
|
161
|
+
});
|
|
162
|
+
addContains(edges, parent, key, file.analyzerId, file.path, declaration.location);
|
|
163
|
+
if (declaration.exported === true) {
|
|
164
|
+
addRelation(edges, parent, key, 'exports', {
|
|
165
|
+
analyzerId: file.analyzerId,
|
|
166
|
+
sourcePath: file.path,
|
|
167
|
+
location: declaration.location,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
for (const child of declaration.children)
|
|
171
|
+
addDeclaration(file, child, key, nodes, edges);
|
|
172
|
+
}
|
|
173
|
+
/*** Define source facts that each parser actually emits. */
|
|
174
|
+
function analyzerCapabilities(analyzerId) {
|
|
175
|
+
if (analyzerId === 'project-detector')
|
|
176
|
+
return ['containment'];
|
|
177
|
+
if (analyzerId === 'java')
|
|
178
|
+
return [
|
|
179
|
+
'containment',
|
|
180
|
+
'declarations',
|
|
181
|
+
'documentation',
|
|
182
|
+
'extends',
|
|
183
|
+
'implements',
|
|
184
|
+
'imports',
|
|
185
|
+
'signatures',
|
|
186
|
+
'source-locations',
|
|
187
|
+
'visibility',
|
|
188
|
+
];
|
|
189
|
+
if (analyzerId === 'typescript')
|
|
190
|
+
return [
|
|
191
|
+
'containment',
|
|
192
|
+
'declarations',
|
|
193
|
+
'documentation',
|
|
194
|
+
'exports',
|
|
195
|
+
'extends',
|
|
196
|
+
'implements',
|
|
197
|
+
'imports',
|
|
198
|
+
'signatures',
|
|
199
|
+
'source-locations',
|
|
200
|
+
'visibility',
|
|
201
|
+
];
|
|
202
|
+
if (['cpp', 'delphi', 'kotlin', 'python'].includes(analyzerId))
|
|
203
|
+
return ['imports'];
|
|
204
|
+
return [];
|
|
205
|
+
}
|
|
206
|
+
/*** Select the deepest workspace/package root that owns a portable source path. */
|
|
207
|
+
function owningPackageRoot(file, roots) {
|
|
208
|
+
return ([...roots]
|
|
209
|
+
.filter((root) => root === '.' || file === root || file.startsWith(`${root}/`))
|
|
210
|
+
.sort((left, right) => right.length - left.length)[0] ?? '.');
|
|
211
|
+
}
|
|
212
|
+
/*** Keep node insertion idempotent when multiple files share one namespace. */
|
|
213
|
+
function addNode(nodes, data) {
|
|
214
|
+
if (!nodes.has(data.semanticPath))
|
|
215
|
+
nodes.set(data.semanticPath, { data });
|
|
216
|
+
}
|
|
217
|
+
/*** Record physical or syntactic containment with provenance. */
|
|
218
|
+
function addContains(edges, source, target, analyzerId, sourcePath, location) {
|
|
219
|
+
addRelation(edges, source, target, 'contains', {
|
|
220
|
+
analyzerId,
|
|
221
|
+
sourcePath,
|
|
222
|
+
...(location === undefined ? {} : { location }),
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
/*** Append one observed relation without pre-aggregating its evidence. */
|
|
226
|
+
function addRelation(edges, source, target, kind, evidence) {
|
|
227
|
+
edges.push({ source, target, data: { kind, evidence: [evidence] } });
|
|
228
|
+
}
|
|
229
|
+
function packageKey(projectId, root) {
|
|
230
|
+
return sourceSemanticPath('package', projectId, root);
|
|
231
|
+
}
|
|
232
|
+
function directoryKey(projectId, directory) {
|
|
233
|
+
return sourceSemanticPath('directory', projectId, directory);
|
|
234
|
+
}
|
|
235
|
+
export function fileKey(projectId, file) {
|
|
236
|
+
return sourceSemanticPath('file', projectId, file);
|
|
237
|
+
}
|
|
238
|
+
//# sourceMappingURL=createSourceStructureDraft.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSourceStructureDraft.js","sourceRoot":"","sources":["../../../../src/features/source-graph/domain/createSourceStructureDraft.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAY7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAO7D,+FAA+F;AAC/F,MAAM,UAAU,0BAA0B,CACxC,QAAkC,EAClC,K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,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC;QAAE,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;AAC5E,CAAC;AAED,iEAAiE;AACjE,SAAS,WAAW,CAClB,KAAwB,EACxB,MAAc,EACd,MAAc,EACd,UAAkB,EAClB,UAAkB,EAClB,QAA6C;IAE7C,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE;QAC7C,UAAU;QACV,UAAU;QACV,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC;KAChD,CAAC,CAAC;AACL,CAAC;AAED,0EAA0E;AAC1E,SAAS,WAAW,CAClB,KAAwB,EACxB,MAAc,EACd,MAAc,EACd,IAAqC,EACrC,QAAgC;IAEhC,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC;AACvE,CAAC;AAED,SAAS,UAAU,CAAC,SAAiB,EAAE,IAAY;IACjD,OAAO,kBAAkB,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;AACxD,CAAC;AAED,SAAS,YAAY,CAAC,SAAiB,EAAE,SAAiB;IACxD,OAAO,kBAAkB,CAAC,WAAW,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AAC/D,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,SAAiB,EAAE,IAAY;IACrD,OAAO,kBAAkB,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;AACrD,CAAC","sourcesContent":["import path from 'node:path';\n\nimport type { ProjectInspection } from '@ankhorage/project-detector/types';\n\nimport type {\n SourceAnalyzedFile,\n SourceEdgeDraft,\n SourceGraphDraft,\n SourceNodeData,\n SourceNodeDraft,\n SourceRelationEvidence,\n} from '../../../types/sourceGraph.js';\nimport { sourceSemanticPath } from './sourceSemanticPath.js';\n\ninterface SourceProject {\n readonly id: string;\n readonly inspection: ProjectInspection;\n}\n\n/*** Preserve scanned projects, packages, empty directories, files, and nested declarations. */\nexport function createSourceStructureDraft(\n projects: readonly SourceProject[],\n files: readonly SourceAnalyzedFile[],\n): SourceGraphDraft {\n const nodes = new Map<string, SourceNodeDraft>();\n const edges: SourceEdgeDraft[] = [];\n for (const project of projects) addProject(project, files, nodes, edges);\n return {\n nodes: [...nodes.values()],\n edges,\n capabilities: projects.flatMap(({ id, inspection }) => {\n const analyzers = new Set([\n 'project-detector',\n ...inspection.detection.languages.map(({ id: languageId }) => languageId),\n ...files.filter((file) => file.projectId === id).map((file) => file.analyzerId),\n ]);\n return [...analyzers].map((analyzerId) => ({\n projectId: id,\n analyzerId,\n available: analyzerCapabilities(analyzerId),\n }));\n }),\n };\n}\n\n/*** Add the physical containment tree for one inspected project. */\nfunction addProject(\n project: SourceProject,\n analyzedFiles: readonly SourceAnalyzedFile[],\n nodes: Map<string, SourceNodeDraft>,\n edges: SourceEdgeDraft[],\n): void {\n const { id, inspection } = project;\n if (!inspection.complete) throw new Error(`Source graph inspection is incomplete for ${id}.`);\n const projectKey = sourceSemanticPath('project', id);\n addNode(nodes, { semanticPath: projectKey, kind: 'project', name: id, projectId: id });\n const packageRoots = new Set(['.', ...inspection.packages.map(({ rootPath }) => rootPath)]);\n addPackages(project, packageRoots, projectKey, nodes, edges);\n addDirectories(project, packageRoots, nodes, edges);\n addFiles(project, packageRoots, nodes, edges);\n for (const file of analyzedFiles.filter((item) => item.projectId === id)) {\n addFileFacts(file, nodes, edges);\n }\n}\n\n/*** Preserve package and workspace roots as explicit containment boundaries. */\nfunction addPackages(\n project: SourceProject,\n packageRoots: ReadonlySet<string>,\n projectKey: string,\n nodes: Map<string, SourceNodeDraft>,\n edges: SourceEdgeDraft[],\n): void {\n const { id, inspection } = project;\n for (const root of packageRoots) {\n const key = packageKey(id, root);\n const name = inspection.packages.find(({ rootPath }) => rootPath === root)?.name ?? root;\n addNode(nodes, {\n semanticPath: key,\n kind: 'package',\n name,\n projectId: id,\n path: root,\n classification: 'intrinsic',\n });\n addContains(edges, projectKey, key, 'project-detector', root);\n }\n}\n\n/*** Preserve empty directories and their exact scanned hierarchy. */\nfunction addDirectories(\n project: SourceProject,\n packageRoots: ReadonlySet<string>,\n nodes: Map<string, SourceNodeDraft>,\n edges: SourceEdgeDraft[],\n): void {\n const { id, inspection } = project;\n for (const directory of inspection.directories.filter((item) => item !== '.')) {\n const root = owningPackageRoot(directory, packageRoots);\n if (directory === root) continue;\n const key = directoryKey(id, directory);\n addNode(nodes, {\n semanticPath: key,\n kind: 'directory',\n name: path.posix.basename(directory),\n projectId: id,\n path: directory,\n classification: 'intrinsic',\n });\n const parent = path.posix.dirname(directory);\n addContains(\n edges,\n parent === root ? packageKey(id, root) : directoryKey(id, parent),\n key,\n 'project-detector',\n directory,\n );\n }\n}\n\n/*** Preserve all inspected files, including files without an implemented language parser. */\nfunction addFiles(\n project: SourceProject,\n packageRoots: ReadonlySet<string>,\n nodes: Map<string, SourceNodeDraft>,\n edges: SourceEdgeDraft[],\n): void {\n const { id, inspection } = project;\n for (const file of inspection.files) {\n const root = owningPackageRoot(file, packageRoots);\n const parent = path.posix.dirname(file);\n const key = fileKey(id, file);\n addNode(nodes, {\n semanticPath: key,\n kind: 'file',\n name: path.posix.basename(file),\n projectId: id,\n path: file,\n filePath: file,\n classification: 'intrinsic',\n });\n addContains(\n edges,\n parent === root || parent === '.' ? packageKey(id, root) : directoryKey(id, parent),\n key,\n 'project-detector',\n file,\n );\n }\n}\n\n/*** Attach portable declarations and their observed documentation to a source file. */\nfunction addFileFacts(\n file: SourceAnalyzedFile,\n nodes: Map<string, SourceNodeDraft>,\n edges: SourceEdgeDraft[],\n): void {\n const parent = fileKey(file.projectId, file.path);\n const fileNode = nodes.get(parent);\n if (fileNode === undefined)\n throw new Error(`Analyzed source file was not inspected: ${file.path}.`);\n if (file.facts.packageName !== undefined && file.facts.packageName !== '') {\n nodes.set(parent, {\n data: { ...fileNode.data, analyzerId: file.analyzerId, packageName: file.facts.packageName },\n });\n const packagePath = addNamespaceHierarchy(file, nodes, edges);\n addRelation(edges, parent, packagePath, 'declares-in', {\n analyzerId: file.analyzerId,\n sourcePath: file.path,\n });\n } else nodes.set(parent, { data: { ...fileNode.data, analyzerId: file.analyzerId } });\n for (const declaration of file.facts.declarations) {\n addDeclaration(file, declaration, parent, nodes, edges);\n }\n}\n\n/*** Materialize each observed namespace ancestor once for package-level queries. */\nfunction addNamespaceHierarchy(\n file: SourceAnalyzedFile,\n nodes: Map<string, SourceNodeDraft>,\n edges: SourceEdgeDraft[],\n): string {\n const segments = file.facts.packageName?.split('.') ?? [];\n let parent = sourceSemanticPath('project', file.projectId);\n let current = '';\n for (const segment of segments) {\n current = current === '' ? segment : `${current}.${segment}`;\n const key = sourceSemanticPath('namespace', file.projectId, current);\n if (!nodes.has(key)) {\n addNode(nodes, {\n semanticPath: key,\n kind: 'package',\n name: current,\n projectId: file.projectId,\n packageName: current,\n classification: 'intrinsic',\n });\n addContains(edges, parent, key, file.analyzerId, file.path);\n }\n parent = key;\n }\n return parent;\n}\n\n/*** Materialize one nested declaration with a location-qualified stable identity. */\nfunction addDeclaration(\n file: SourceAnalyzedFile,\n declaration: SourceAnalyzedFile['facts']['declarations'][number],\n parent: string,\n nodes: Map<string, SourceNodeDraft>,\n edges: SourceEdgeDraft[],\n): void {\n const key = sourceSemanticPath(\n parent,\n declaration.kind,\n declaration.name,\n `${declaration.location.line}:${declaration.location.column}`,\n );\n addNode(nodes, {\n semanticPath: key,\n kind: declaration.kind,\n name: declaration.name,\n projectId: file.projectId,\n filePath: file.path,\n ...(file.facts.packageName === undefined ? {} : { packageName: file.facts.packageName }),\n classification: 'intrinsic',\n location: declaration.location,\n visibility: declaration.visibility,\n modifiers: declaration.modifiers,\n ...(declaration.signature === undefined ? {} : { signature: declaration.signature }),\n ...(declaration.documentation === undefined\n ? {}\n : { documentation: declaration.documentation }),\n ...(declaration.typeOnly === undefined ? {} : { typeOnly: declaration.typeOnly }),\n });\n addContains(edges, parent, key, file.analyzerId, file.path, declaration.location);\n if (declaration.exported === true) {\n addRelation(edges, parent, key, 'exports', {\n analyzerId: file.analyzerId,\n sourcePath: file.path,\n location: declaration.location,\n });\n }\n for (const child of declaration.children) addDeclaration(file, child, key, nodes, edges);\n}\n\n/*** Define source facts that each parser actually emits. */\nfunction analyzerCapabilities(\n analyzerId: string,\n): SourceGraphDraft['capabilities'][number]['available'] {\n if (analyzerId === 'project-detector') return ['containment'];\n if (analyzerId === 'java')\n return [\n 'containment',\n 'declarations',\n 'documentation',\n 'extends',\n 'implements',\n 'imports',\n 'signatures',\n 'source-locations',\n 'visibility',\n ];\n if (analyzerId === 'typescript')\n return [\n 'containment',\n 'declarations',\n 'documentation',\n 'exports',\n 'extends',\n 'implements',\n 'imports',\n 'signatures',\n 'source-locations',\n 'visibility',\n ];\n if (['cpp', 'delphi', 'kotlin', 'python'].includes(analyzerId)) return ['imports'];\n return [];\n}\n\n/*** Select the deepest workspace/package root that owns a portable source path. */\nfunction owningPackageRoot(file: string, roots: ReadonlySet<string>): string {\n return (\n [...roots]\n .filter((root) => root === '.' || file === root || file.startsWith(`${root}/`))\n .sort((left, right) => right.length - left.length)[0] ?? '.'\n );\n}\n\n/*** Keep node insertion idempotent when multiple files share one namespace. */\nfunction addNode(nodes: Map<string, SourceNodeDraft>, data: SourceNodeData): void {\n if (!nodes.has(data.semanticPath)) nodes.set(data.semanticPath, { data });\n}\n\n/*** Record physical or syntactic containment with provenance. */\nfunction addContains(\n edges: SourceEdgeDraft[],\n source: string,\n target: string,\n analyzerId: string,\n sourcePath: string,\n location?: SourceRelationEvidence['location'],\n): void {\n addRelation(edges, source, target, 'contains', {\n analyzerId,\n sourcePath,\n ...(location === undefined ? {} : { location }),\n });\n}\n\n/*** Append one observed relation without pre-aggregating its evidence. */\nfunction addRelation(\n edges: SourceEdgeDraft[],\n source: string,\n target: string,\n kind: SourceEdgeDraft['data']['kind'],\n evidence: SourceRelationEvidence,\n): void {\n edges.push({ source, target, data: { kind, evidence: [evidence] } });\n}\n\nfunction packageKey(projectId: string, root: string): string {\n return sourceSemanticPath('package', projectId, root);\n}\n\nfunction directoryKey(projectId: string, directory: string): string {\n return sourceSemanticPath('directory', projectId, directory);\n}\n\nexport function fileKey(projectId: string, file: string): string {\n return sourceSemanticPath('file', projectId, file);\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { GraphNode } from '@ankhorage/graph';
|
|
2
|
+
import type { SourceGraphIndex, SourceNodeData, SourceRelationView } from '../../../types/sourceGraph.js';
|
|
3
|
+
/*** Resolve a stable semantic identity without exposing its local numeric ID. */
|
|
4
|
+
export declare function findSourceNode(index: SourceGraphIndex, semanticPath: string): GraphNode<SourceNodeData, number> | undefined;
|
|
5
|
+
/*** Resolve a file in one project by its project-relative portable path. */
|
|
6
|
+
export declare function findSourceFile(index: SourceGraphIndex, projectId: string, path: string): GraphNode<SourceNodeData, number> | undefined;
|
|
7
|
+
/*** Resolve declarations by project, file, and source-level name. */
|
|
8
|
+
export declare function findSourceSymbols(index: SourceGraphIndex, projectId: string, path: string, name: string): readonly GraphNode<SourceNodeData, number>[];
|
|
9
|
+
/*** Read relationships emitted from a semantic node in index time. */
|
|
10
|
+
export declare function outgoingSourceRelations(index: SourceGraphIndex, semanticPath: string): readonly SourceRelationView[];
|
|
11
|
+
/*** Read relationships targeting a semantic node in index time. */
|
|
12
|
+
export declare function incomingSourceRelations(index: SourceGraphIndex, semanticPath: string): readonly SourceRelationView[];
|
|
13
|
+
/*** Resolve direct observed relationships between two stable semantic identities. */
|
|
14
|
+
export declare function findSourceRelationsBetween(index: SourceGraphIndex, sourceSemanticPath: string, targetSemanticPath: string): readonly SourceRelationView[];
|
|
15
|
+
//# sourceMappingURL=querySourceGraph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"querySourceGraph.d.ts","sourceRoot":"","sources":["../../../../src/features/source-graph/domain/querySourceGraph.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7D,OAAO,KAAK,EAEV,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EACnB,MAAM,+BAA+B,CAAC;AAEvC,iFAAiF;AACjF,wBAAgB,cAAc,CAC5B,KAAK,EAAE,gBAAgB,EACvB,YAAY,EAAE,MAAM,GACnB,SAAS,CAAC,cAAc,EAAE,MAAM,CAAC,GAAG,SAAS,CAE/C;AAED,4EAA4E;AAC5E,wBAAgB,cAAc,CAC5B,KAAK,EAAE,gBAAgB,EACvB,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,GACX,SAAS,CAAC,cAAc,EAAE,MAAM,CAAC,GAAG,SAAS,CAE/C;AAED,qEAAqE;AACrE,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,gBAAgB,EACvB,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACX,SAAS,SAAS,CAAC,cAAc,EAAE,MAAM,CAAC,EAAE,CAE9C;AAED,sEAAsE;AACtE,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,gBAAgB,EACvB,YAAY,EAAE,MAAM,GACnB,SAAS,kBAAkB,EAAE,CAK/B;AAED,mEAAmE;AACnE,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,gBAAgB,EACvB,YAAY,EAAE,MAAM,GACnB,SAAS,kBAAkB,EAAE,CAK/B;AAED,qFAAqF;AACrF,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,gBAAgB,EACvB,kBAAkB,EAAE,MAAM,EAC1B,kBAAkB,EAAE,MAAM,GACzB,SAAS,kBAAkB,EAAE,CAI/B"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*** Resolve a stable semantic identity without exposing its local numeric ID. */
|
|
2
|
+
export function findSourceNode(index, semanticPath) {
|
|
3
|
+
return index.nodeBySemanticPath.get(semanticPath);
|
|
4
|
+
}
|
|
5
|
+
/*** Resolve a file in one project by its project-relative portable path. */
|
|
6
|
+
export function findSourceFile(index, projectId, path) {
|
|
7
|
+
return index.fileByPath.get(`${projectId}\u0000${path}`);
|
|
8
|
+
}
|
|
9
|
+
/*** Resolve declarations by project, file, and source-level name. */
|
|
10
|
+
export function findSourceSymbols(index, projectId, path, name) {
|
|
11
|
+
return index.symbolsByFileAndName.get(`${projectId}\u0000${path}\u0000${name}`) ?? [];
|
|
12
|
+
}
|
|
13
|
+
/*** Read relationships emitted from a semantic node in index time. */
|
|
14
|
+
export function outgoingSourceRelations(index, semanticPath) {
|
|
15
|
+
const node = findSourceNode(index, semanticPath);
|
|
16
|
+
return node === undefined
|
|
17
|
+
? []
|
|
18
|
+
: (index.outgoingByNodeId.get(node.id) ?? []).map((edge) => relationView(index, edge));
|
|
19
|
+
}
|
|
20
|
+
/*** Read relationships targeting a semantic node in index time. */
|
|
21
|
+
export function incomingSourceRelations(index, semanticPath) {
|
|
22
|
+
const node = findSourceNode(index, semanticPath);
|
|
23
|
+
return node === undefined
|
|
24
|
+
? []
|
|
25
|
+
: (index.incomingByNodeId.get(node.id) ?? []).map((edge) => relationView(index, edge));
|
|
26
|
+
}
|
|
27
|
+
/*** Resolve direct observed relationships between two stable semantic identities. */
|
|
28
|
+
export function findSourceRelationsBetween(index, sourceSemanticPath, targetSemanticPath) {
|
|
29
|
+
return outgoingSourceRelations(index, sourceSemanticPath).filter(({ target }) => target.semanticPath === targetSemanticPath);
|
|
30
|
+
}
|
|
31
|
+
/*** Join an indexed edge to semantic endpoint data in constant time. */
|
|
32
|
+
function relationView(index, edge) {
|
|
33
|
+
const source = index.nodeById.get(edge.source)?.data;
|
|
34
|
+
const target = index.nodeById.get(edge.target)?.data;
|
|
35
|
+
if (source === undefined || target === undefined) {
|
|
36
|
+
throw new Error(`Source relation ${edge.id} has an unknown endpoint.`);
|
|
37
|
+
}
|
|
38
|
+
return { edgeId: edge.id, kind: edge.data.kind, source, target, evidence: edge.data.evidence };
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=querySourceGraph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"querySourceGraph.js","sourceRoot":"","sources":["../../../../src/features/source-graph/domain/querySourceGraph.ts"],"names":[],"mappings":"AASA,iFAAiF;AACjF,MAAM,UAAU,cAAc,CAC5B,KAAuB,EACvB,YAAoB;IAEpB,OAAO,KAAK,CAAC,kBAAkB,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;AACpD,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,cAAc,CAC5B,KAAuB,EACvB,SAAiB,EACjB,IAAY;IAEZ,OAAO,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,SAAS,SAAS,IAAI,EAAE,CAAC,CAAC;AAC3D,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,iBAAiB,CAC/B,KAAuB,EACvB,SAAiB,EACjB,IAAY,EACZ,IAAY;IAEZ,OAAO,KAAK,CAAC,oBAAoB,CAAC,GAAG,CAAC,GAAG,SAAS,SAAS,IAAI,SAAS,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;AACxF,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,uBAAuB,CACrC,KAAuB,EACvB,YAAoB;IAEpB,MAAM,IAAI,GAAG,cAAc,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;IACjD,OAAO,IAAI,KAAK,SAAS;QACvB,CAAC,CAAC,EAAE;QACJ,CAAC,CAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;AAC3F,C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C,IAAI,CAAC,QAAQ,EAAE,CAAC;AACjG,CAAC","sourcesContent":["import type { GraphEdge, GraphNode } from '@ankhorage/graph';\n\nimport type {\n SourceEdgeData,\n SourceGraphIndex,\n SourceNodeData,\n SourceRelationView,\n} from '../../../types/sourceGraph.js';\n\n/*** Resolve a stable semantic identity without exposing its local numeric ID. */\nexport function findSourceNode(\n index: SourceGraphIndex,\n semanticPath: string,\n): GraphNode<SourceNodeData, number> | undefined {\n return index.nodeBySemanticPath.get(semanticPath);\n}\n\n/*** Resolve a file in one project by its project-relative portable path. */\nexport function findSourceFile(\n index: SourceGraphIndex,\n projectId: string,\n path: string,\n): GraphNode<SourceNodeData, number> | undefined {\n return index.fileByPath.get(`${projectId}\\u0000${path}`);\n}\n\n/*** Resolve declarations by project, file, and source-level name. */\nexport function findSourceSymbols(\n index: SourceGraphIndex,\n projectId: string,\n path: string,\n name: string,\n): readonly GraphNode<SourceNodeData, number>[] {\n return index.symbolsByFileAndName.get(`${projectId}\\u0000${path}\\u0000${name}`) ?? [];\n}\n\n/*** Read relationships emitted from a semantic node in index time. */\nexport function outgoingSourceRelations(\n index: SourceGraphIndex,\n semanticPath: string,\n): readonly SourceRelationView[] {\n const node = findSourceNode(index, semanticPath);\n return node === undefined\n ? []\n : (index.outgoingByNodeId.get(node.id) ?? []).map((edge) => relationView(index, edge));\n}\n\n/*** Read relationships targeting a semantic node in index time. */\nexport function incomingSourceRelations(\n index: SourceGraphIndex,\n semanticPath: string,\n): readonly SourceRelationView[] {\n const node = findSourceNode(index, semanticPath);\n return node === undefined\n ? []\n : (index.incomingByNodeId.get(node.id) ?? []).map((edge) => relationView(index, edge));\n}\n\n/*** Resolve direct observed relationships between two stable semantic identities. */\nexport function findSourceRelationsBetween(\n index: SourceGraphIndex,\n sourceSemanticPath: string,\n targetSemanticPath: string,\n): readonly SourceRelationView[] {\n return outgoingSourceRelations(index, sourceSemanticPath).filter(\n ({ target }) => target.semanticPath === targetSemanticPath,\n );\n}\n\n/*** Join an indexed edge to semantic endpoint data in constant time. */\nfunction relationView(\n index: SourceGraphIndex,\n edge: GraphEdge<SourceEdgeData, number, number>,\n): SourceRelationView {\n const source = index.nodeById.get(edge.source)?.data;\n const target = index.nodeById.get(edge.target)?.data;\n if (source === undefined || target === undefined) {\n throw new Error(`Source relation ${edge.id} has an unknown endpoint.`);\n }\n return { edgeId: edge.id, kind: edge.data.kind, source, target, evidence: edge.data.evidence };\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DependencyDeclaration } from '../../../types/dependencyGraph.js';
|
|
2
|
+
import type { SourceAnalyzedFile, SourceNodeDraft } from '../../../types/sourceGraph.js';
|
|
3
|
+
export interface ResolvedImport {
|
|
4
|
+
readonly target: string;
|
|
5
|
+
readonly declarations: readonly DependencyDeclaration[];
|
|
6
|
+
}
|
|
7
|
+
/*** Resolve a source import to an observed file/type or explicit unresolved target. */
|
|
8
|
+
export declare function resolveImport(file: SourceAnalyzedFile, specifier: string, local: boolean | undefined, nodes: Map<string, SourceNodeDraft>, symbols: ReadonlyMap<string, string>, namespaces: ReadonlyMap<string, readonly string[]>, focusPackages: ReadonlyMap<string, string>): ResolvedImport;
|
|
9
|
+
//# sourceMappingURL=resolveSourceImport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveSourceImport.d.ts","sourceRoot":"","sources":["../../../../src/features/source-graph/domain/resolveSourceImport.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AASzF,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,YAAY,EAAE,SAAS,qBAAqB,EAAE,CAAC;CACzD;AAED,uFAAuF;AACvF,wBAAgB,aAAa,CAC3B,IAAI,EAAE,kBAAkB,EACxB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,OAAO,GAAG,SAAS,EAC1B,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,EACnC,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,EACpC,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,EAClD,aAAa,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GACzC,cAAc,CAIhB"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { extractCppPackageFromInclude } from '../../dependency-analysis/domain/extractCppPackageFromInclude.js';
|
|
3
|
+
import { extractDelphiPackageFromImport } from '../../dependency-analysis/domain/extractDelphiPackageFromImport.js';
|
|
4
|
+
import { extractJavaPackageFromImport } from '../../dependency-analysis/domain/extractJavaPackageFromImport.js';
|
|
5
|
+
import { extractKotlinPackageFromImport } from '../../dependency-analysis/domain/extractKotlinPackageFromImport.js';
|
|
6
|
+
import { extractPythonPackageFromImport } from '../../dependency-analysis/domain/extractPythonPackageFromImport.js';
|
|
7
|
+
import { fileKey } from './createSourceStructureDraft.js';
|
|
8
|
+
import { sourceSemanticPath } from './sourceSemanticPath.js';
|
|
9
|
+
/*** Resolve a source import to an observed file/type or explicit unresolved target. */
|
|
10
|
+
export function resolveImport(file, specifier, local, nodes, symbols, namespaces, focusPackages) {
|
|
11
|
+
const intrinsic = resolveIntrinsicImport(file, specifier, local, nodes, symbols, namespaces);
|
|
12
|
+
if (intrinsic !== undefined)
|
|
13
|
+
return { target: intrinsic, declarations: [] };
|
|
14
|
+
return resolveExternalImport(file, specifier, nodes, focusPackages);
|
|
15
|
+
}
|
|
16
|
+
/*** Route language-specific reference syntax into one observed intrinsic target. */
|
|
17
|
+
function resolveIntrinsicImport(file, specifier, local, nodes, symbols, namespaces) {
|
|
18
|
+
if (file.analyzerId === 'java')
|
|
19
|
+
return resolveJavaImport(file, specifier, nodes, symbols, namespaces);
|
|
20
|
+
if (file.analyzerId === 'typescript')
|
|
21
|
+
return resolveTypeScriptFileImport(file, specifier, nodes);
|
|
22
|
+
if (file.analyzerId === 'cpp')
|
|
23
|
+
return local ? resolveLocalCppInclude(file, specifier, nodes) : undefined;
|
|
24
|
+
return resolveNamespaceImport(file, specifier, namespaces);
|
|
25
|
+
}
|
|
26
|
+
/*** Resolve a local C++ include to its existing or newly observed namespace. */
|
|
27
|
+
function resolveLocalCppInclude(file, specifier, nodes) {
|
|
28
|
+
const packageName = extractCppPackageFromInclude(specifier);
|
|
29
|
+
if (packageName === '')
|
|
30
|
+
return undefined;
|
|
31
|
+
const key = sourceSemanticPath('namespace', file.projectId, packageName);
|
|
32
|
+
if (!nodes.has(key)) {
|
|
33
|
+
nodes.set(key, {
|
|
34
|
+
data: {
|
|
35
|
+
semanticPath: key,
|
|
36
|
+
kind: 'package',
|
|
37
|
+
name: packageName,
|
|
38
|
+
projectId: file.projectId,
|
|
39
|
+
packageName,
|
|
40
|
+
classification: 'intrinsic',
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return key;
|
|
45
|
+
}
|
|
46
|
+
/*** Resolve imports against namespaces declared by Kotlin, Python, and Delphi source files. */
|
|
47
|
+
function resolveNamespaceImport(file, specifier, namespaces) {
|
|
48
|
+
const candidates = namespaces.get(file.projectId) ?? [];
|
|
49
|
+
const matching = file.analyzerId === 'python'
|
|
50
|
+
? candidates.find((name) => name === extractPythonPackageFromImport(specifier))
|
|
51
|
+
: file.analyzerId === 'delphi'
|
|
52
|
+
? candidates.find((name) => name === extractDelphiPackageFromImport(specifier))
|
|
53
|
+
: candidates.find((name) => specifier === name || specifier.startsWith(`${name}.`));
|
|
54
|
+
return matching === undefined
|
|
55
|
+
? undefined
|
|
56
|
+
: sourceSemanticPath('namespace', file.projectId, matching);
|
|
57
|
+
}
|
|
58
|
+
/*** Resolve an imported Java type or package from observed declarations. */
|
|
59
|
+
function resolveJavaImport(file, specifier, nodes, symbols, namespaces) {
|
|
60
|
+
const name = specifier.replace(/\.\*$/u, '');
|
|
61
|
+
const separator = name.lastIndexOf('.');
|
|
62
|
+
const packageName = separator < 0 ? '' : name.slice(0, separator);
|
|
63
|
+
const simpleName = name.slice(separator + 1);
|
|
64
|
+
const symbol = symbols.get(symbolKey(file.projectId, packageName, simpleName));
|
|
65
|
+
if (symbol !== undefined)
|
|
66
|
+
return symbol;
|
|
67
|
+
const namespace = sourceSemanticPath('namespace', file.projectId, name);
|
|
68
|
+
if (nodes.has(namespace))
|
|
69
|
+
return namespace;
|
|
70
|
+
return resolveNamespaceImport(file, specifier, namespaces);
|
|
71
|
+
}
|
|
72
|
+
/*** Resolve a relative TypeScript import to a scanned source file. */
|
|
73
|
+
function resolveTypeScriptFileImport(file, specifier, nodes) {
|
|
74
|
+
if (!specifier.startsWith('.'))
|
|
75
|
+
return undefined;
|
|
76
|
+
const base = path.posix.normalize(path.posix.join(path.posix.dirname(file.path), specifier));
|
|
77
|
+
const candidates = [
|
|
78
|
+
base,
|
|
79
|
+
`${base}.ts`,
|
|
80
|
+
`${base}.tsx`,
|
|
81
|
+
`${base}.mts`,
|
|
82
|
+
`${base}.cts`,
|
|
83
|
+
`${base}/index.ts`,
|
|
84
|
+
`${base}/index.tsx`,
|
|
85
|
+
];
|
|
86
|
+
return candidates
|
|
87
|
+
.map((candidate) => fileKey(file.projectId, candidate))
|
|
88
|
+
.find((key) => nodes.has(key));
|
|
89
|
+
}
|
|
90
|
+
/*** Distinguish declared vendor imports, focus packages, and unresolved imports. */
|
|
91
|
+
function resolveExternalImport(file, specifier, nodes, focusPackages) {
|
|
92
|
+
const packageName = packageFromSpecifier(file.analyzerId, specifier);
|
|
93
|
+
const declarations = packageName === undefined
|
|
94
|
+
? []
|
|
95
|
+
: (Object.entries(file.declaredDependencies ?? {}).find(([name]) => name === packageName)?.[1] ?? []);
|
|
96
|
+
const focus = packageName === undefined ? undefined : focusPackages.get(packageName);
|
|
97
|
+
if (focus !== undefined)
|
|
98
|
+
return { target: focus, declarations };
|
|
99
|
+
const external = sourceSemanticPath('external', file.projectId, packageName ?? specifier);
|
|
100
|
+
if (!nodes.has(external)) {
|
|
101
|
+
nodes.set(external, {
|
|
102
|
+
data: {
|
|
103
|
+
semanticPath: external,
|
|
104
|
+
kind: 'package',
|
|
105
|
+
name: packageName ?? specifier,
|
|
106
|
+
projectId: file.projectId,
|
|
107
|
+
packageName: packageName ?? specifier,
|
|
108
|
+
classification: file.analyzerId === 'typescript' && declarations.length > 0 ? 'vendor' : 'unknown',
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
return { target: external, declarations };
|
|
113
|
+
}
|
|
114
|
+
/*** Project an unresolved reference onto the established package naming semantics. */
|
|
115
|
+
function packageFromSpecifier(analyzerId, specifier) {
|
|
116
|
+
if (analyzerId === 'java')
|
|
117
|
+
return extractJavaPackageFromImport(specifier);
|
|
118
|
+
if (analyzerId === 'kotlin')
|
|
119
|
+
return extractKotlinPackageFromImport(specifier);
|
|
120
|
+
if (analyzerId === 'python')
|
|
121
|
+
return extractPythonPackageFromImport(specifier);
|
|
122
|
+
if (analyzerId === 'delphi')
|
|
123
|
+
return extractDelphiPackageFromImport(specifier);
|
|
124
|
+
if (analyzerId === 'cpp')
|
|
125
|
+
return extractCppPackageFromInclude(specifier);
|
|
126
|
+
return barePackageName(specifier);
|
|
127
|
+
}
|
|
128
|
+
/*** Extract the declared npm package identity from a bare module specifier. */
|
|
129
|
+
function barePackageName(specifier) {
|
|
130
|
+
if (specifier === '' ||
|
|
131
|
+
specifier.startsWith('.') ||
|
|
132
|
+
specifier.startsWith('#') ||
|
|
133
|
+
specifier.startsWith('/'))
|
|
134
|
+
return undefined;
|
|
135
|
+
const segments = specifier.split('/');
|
|
136
|
+
return specifier.startsWith('@')
|
|
137
|
+
? segments.length >= 2
|
|
138
|
+
? `${segments[0]}/${segments[1]}`
|
|
139
|
+
: undefined
|
|
140
|
+
: segments[0];
|
|
141
|
+
}
|
|
142
|
+
/*** Scope type names without confusing same names in separate Java packages. */
|
|
143
|
+
function symbolKey(projectId, packageName, name) {
|
|
144
|
+
return sourceSemanticPath(projectId, packageName, name);
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=resolveSourceImport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveSourceImport.js","sourceRoot":"","sources":["../../../../src/features/source-graph/domain/resolveSourceImport.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAI7B,OAAO,EAAE,4BAA4B,EAAE,MAAM,kEAAkE,CAAC;AAChH,OAAO,EAAE,8BAA8B,EAAE,MAAM,oEAAoE,CAAC;AACpH,OAAO,EAAE,4BAA4B,EAAE,MAAM,kEAAkE,CAAC;AAChH,OAAO,EAAE,8BAA8B,EAAE,MAAM,oEAAoE,CAAC;AACpH,OAAO,EAAE,8BAA8B,EAAE,MAAM,oEAAoE,CAAC;AACpH,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAO7D,uFAAuF;AACvF,MAAM,UAAU,aAAa,CAC3B,IAAwB,EACxB,SAAiB,EACjB,KAA0B,EAC1B,KAAmC,EACnC,OAAoC,EACpC,UAAkD,EAClD,aAA0C;IAE1C,MAAM,SAAS,GAAG,sBAAsB,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;IAC7F,IAAI,SAAS,KAAK,SAAS;QAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC;IAC5E,OAAO,qBAAqB,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC;AACtE,CAAC;AAED,oFAAoF;AACpF,SAAS,sBAAsB,CAC7B,IAAwB,EACxB,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CAAC","sourcesContent":["import path from 'node:path';\n\nimport type { DependencyDeclaration } from '../../../types/dependencyGraph.js';\nimport type { SourceAnalyzedFile, SourceNodeDraft } from '../../../types/sourceGraph.js';\nimport { extractCppPackageFromInclude } from '../../dependency-analysis/domain/extractCppPackageFromInclude.js';\nimport { extractDelphiPackageFromImport } from '../../dependency-analysis/domain/extractDelphiPackageFromImport.js';\nimport { extractJavaPackageFromImport } from '../../dependency-analysis/domain/extractJavaPackageFromImport.js';\nimport { extractKotlinPackageFromImport } from '../../dependency-analysis/domain/extractKotlinPackageFromImport.js';\nimport { extractPythonPackageFromImport } from '../../dependency-analysis/domain/extractPythonPackageFromImport.js';\nimport { fileKey } from './createSourceStructureDraft.js';\nimport { sourceSemanticPath } from './sourceSemanticPath.js';\n\nexport interface ResolvedImport {\n readonly target: string;\n readonly declarations: readonly DependencyDeclaration[];\n}\n\n/*** Resolve a source import to an observed file/type or explicit unresolved target. */\nexport function resolveImport(\n file: SourceAnalyzedFile,\n specifier: string,\n local: boolean | undefined,\n nodes: Map<string, SourceNodeDraft>,\n symbols: ReadonlyMap<string, string>,\n namespaces: ReadonlyMap<string, readonly string[]>,\n focusPackages: ReadonlyMap<string, string>,\n): ResolvedImport {\n const intrinsic = resolveIntrinsicImport(file, specifier, local, nodes, symbols, namespaces);\n if (intrinsic !== undefined) return { target: intrinsic, declarations: [] };\n return resolveExternalImport(file, specifier, nodes, focusPackages);\n}\n\n/*** Route language-specific reference syntax into one observed intrinsic target. */\nfunction resolveIntrinsicImport(\n file: SourceAnalyzedFile,\n specifier: string,\n local: boolean | undefined,\n nodes: Map<string, SourceNodeDraft>,\n symbols: ReadonlyMap<string, string>,\n namespaces: ReadonlyMap<string, readonly string[]>,\n): string | undefined {\n if (file.analyzerId === 'java')\n return resolveJavaImport(file, specifier, nodes, symbols, namespaces);\n if (file.analyzerId === 'typescript') return resolveTypeScriptFileImport(file, specifier, nodes);\n if (file.analyzerId === 'cpp')\n return local ? resolveLocalCppInclude(file, specifier, nodes) : undefined;\n return resolveNamespaceImport(file, specifier, namespaces);\n}\n\n/*** Resolve a local C++ include to its existing or newly observed namespace. */\nfunction resolveLocalCppInclude(\n file: SourceAnalyzedFile,\n specifier: string,\n nodes: Map<string, SourceNodeDraft>,\n): string | undefined {\n const packageName = extractCppPackageFromInclude(specifier);\n if (packageName === '') return undefined;\n const key = sourceSemanticPath('namespace', file.projectId, packageName);\n if (!nodes.has(key)) {\n nodes.set(key, {\n data: {\n semanticPath: key,\n kind: 'package',\n name: packageName,\n projectId: file.projectId,\n packageName,\n classification: 'intrinsic',\n },\n });\n }\n return key;\n}\n\n/*** Resolve imports against namespaces declared by Kotlin, Python, and Delphi source files. */\nfunction resolveNamespaceImport(\n file: SourceAnalyzedFile,\n specifier: string,\n namespaces: ReadonlyMap<string, readonly string[]>,\n): string | undefined {\n const candidates = namespaces.get(file.projectId) ?? [];\n const matching =\n file.analyzerId === 'python'\n ? candidates.find((name) => name === extractPythonPackageFromImport(specifier))\n : file.analyzerId === 'delphi'\n ? candidates.find((name) => name === extractDelphiPackageFromImport(specifier))\n : candidates.find((name) => specifier === name || specifier.startsWith(`${name}.`));\n return matching === undefined\n ? undefined\n : sourceSemanticPath('namespace', file.projectId, matching);\n}\n\n/*** Resolve an imported Java type or package from observed declarations. */\nfunction resolveJavaImport(\n file: SourceAnalyzedFile,\n specifier: string,\n nodes: ReadonlyMap<string, SourceNodeDraft>,\n symbols: ReadonlyMap<string, string>,\n namespaces: ReadonlyMap<string, readonly string[]>,\n): string | undefined {\n const name = specifier.replace(/\\.\\*$/u, '');\n const separator = name.lastIndexOf('.');\n const packageName = separator < 0 ? '' : name.slice(0, separator);\n const simpleName = name.slice(separator + 1);\n const symbol = symbols.get(symbolKey(file.projectId, packageName, simpleName));\n if (symbol !== undefined) return symbol;\n const namespace = sourceSemanticPath('namespace', file.projectId, name);\n if (nodes.has(namespace)) return namespace;\n return resolveNamespaceImport(file, specifier, namespaces);\n}\n\n/*** Resolve a relative TypeScript import to a scanned source file. */\nfunction resolveTypeScriptFileImport(\n file: SourceAnalyzedFile,\n specifier: string,\n nodes: ReadonlyMap<string, SourceNodeDraft>,\n): string | undefined {\n if (!specifier.startsWith('.')) return undefined;\n const base = path.posix.normalize(path.posix.join(path.posix.dirname(file.path), specifier));\n const candidates = [\n base,\n `${base}.ts`,\n `${base}.tsx`,\n `${base}.mts`,\n `${base}.cts`,\n `${base}/index.ts`,\n `${base}/index.tsx`,\n ];\n return candidates\n .map((candidate) => fileKey(file.projectId, candidate))\n .find((key) => nodes.has(key));\n}\n\n/*** Distinguish declared vendor imports, focus packages, and unresolved imports. */\nfunction resolveExternalImport(\n file: SourceAnalyzedFile,\n specifier: string,\n nodes: Map<string, SourceNodeDraft>,\n focusPackages: ReadonlyMap<string, string>,\n): ResolvedImport {\n const packageName = packageFromSpecifier(file.analyzerId, specifier);\n const declarations =\n packageName === undefined\n ? []\n : (Object.entries(file.declaredDependencies ?? {}).find(\n ([name]) => name === packageName,\n )?.[1] ?? []);\n const focus = packageName === undefined ? undefined : focusPackages.get(packageName);\n if (focus !== undefined) return { target: focus, declarations };\n const external = sourceSemanticPath('external', file.projectId, packageName ?? specifier);\n if (!nodes.has(external)) {\n nodes.set(external, {\n data: {\n semanticPath: external,\n kind: 'package',\n name: packageName ?? specifier,\n projectId: file.projectId,\n packageName: packageName ?? specifier,\n classification:\n file.analyzerId === 'typescript' && declarations.length > 0 ? 'vendor' : 'unknown',\n },\n });\n }\n return { target: external, declarations };\n}\n\n/*** Project an unresolved reference onto the established package naming semantics. */\nfunction packageFromSpecifier(analyzerId: string, specifier: string): string | undefined {\n if (analyzerId === 'java') return extractJavaPackageFromImport(specifier);\n if (analyzerId === 'kotlin') return extractKotlinPackageFromImport(specifier);\n if (analyzerId === 'python') return extractPythonPackageFromImport(specifier);\n if (analyzerId === 'delphi') return extractDelphiPackageFromImport(specifier);\n if (analyzerId === 'cpp') return extractCppPackageFromInclude(specifier);\n return barePackageName(specifier);\n}\n\n/*** Extract the declared npm package identity from a bare module specifier. */\nfunction barePackageName(specifier: string): string | undefined {\n if (\n specifier === '' ||\n specifier.startsWith('.') ||\n specifier.startsWith('#') ||\n specifier.startsWith('/')\n )\n return undefined;\n const segments = specifier.split('/');\n return specifier.startsWith('@')\n ? segments.length >= 2\n ? `${segments[0]}/${segments[1]}`\n : undefined\n : segments[0];\n}\n\n/*** Scope type names without confusing same names in separate Java packages. */\nfunction symbolKey(projectId: string, packageName: string, name: string): string {\n return sourceSemanticPath(projectId, packageName, name);\n}\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SourceGraph, SourceGraphIndex, SourceRollupEdge } from '../../../types/sourceGraph.js';
|
|
2
|
+
/*** Aggregate observed relationships at the requested containment level, preserving edge IDs. */
|
|
3
|
+
export declare function rollupSourceRelations(sourceGraph: SourceGraph, index: SourceGraphIndex, aggregateKind: 'project' | 'package' | 'directory' | 'file', relationKind?: 'imports' | 'exports' | 'extends' | 'implements'): readonly SourceRollupEdge[];
|
|
4
|
+
//# sourceMappingURL=rollupSourceRelations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rollupSourceRelations.d.ts","sourceRoot":"","sources":["../../../../src/features/source-graph/domain/rollupSourceRelations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,+BAA+B,CAAC;AAEvC,iGAAiG;AACjG,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE,gBAAgB,EACvB,aAAa,EAAE,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,MAAM,EAC3D,YAAY,GAAE,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,YAAwB,GACzE,SAAS,gBAAgB,EAAE,CA8B7B"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/*** Aggregate observed relationships at the requested containment level, preserving edge IDs. */
|
|
2
|
+
export function rollupSourceRelations(sourceGraph, index, aggregateKind, relationKind = 'imports') {
|
|
3
|
+
const nodesById = new Map(sourceGraph.graph.nodes.map((node) => [node.id, node.data]));
|
|
4
|
+
const namespaceByFileId = new Map(sourceGraph.graph.edges.flatMap((edge) => edge.data.kind === 'declares-in' ? [[edge.source, edge.target]] : []));
|
|
5
|
+
const pairs = new Map();
|
|
6
|
+
for (const edge of sourceGraph.graph.edges) {
|
|
7
|
+
if (edge.data.kind !== relationKind)
|
|
8
|
+
continue;
|
|
9
|
+
const source = ancestorOfKind(edge.source, aggregateKind, nodesById, namespaceByFileId, index);
|
|
10
|
+
const target = ancestorOfKind(edge.target, aggregateKind, nodesById, namespaceByFileId, index);
|
|
11
|
+
if (source === undefined || target === undefined || source === target)
|
|
12
|
+
continue;
|
|
13
|
+
const sourceSemanticPath = nodesById.get(source)?.semanticPath;
|
|
14
|
+
const targetSemanticPath = nodesById.get(target)?.semanticPath;
|
|
15
|
+
if (sourceSemanticPath === undefined || targetSemanticPath === undefined)
|
|
16
|
+
continue;
|
|
17
|
+
const key = `${source}\u0000${target}`;
|
|
18
|
+
const previous = pairs.get(key);
|
|
19
|
+
pairs.set(key, {
|
|
20
|
+
source,
|
|
21
|
+
target,
|
|
22
|
+
sourceSemanticPath,
|
|
23
|
+
targetSemanticPath,
|
|
24
|
+
weight: (previous?.weight ?? 0) + 1,
|
|
25
|
+
evidenceEdgeIds: [...(previous?.evidenceEdgeIds ?? []), edge.id],
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return [...pairs.values()].sort((left, right) => left.source - right.source || left.target - right.target);
|
|
29
|
+
}
|
|
30
|
+
/*** Ascend factual containment to one requested projection level. */
|
|
31
|
+
function ancestorOfKind(nodeId, kind, nodes, namespaces, index) {
|
|
32
|
+
let current = nodeId;
|
|
33
|
+
while (current !== undefined) {
|
|
34
|
+
if (kind === 'package' && nodes.get(current)?.kind === 'file') {
|
|
35
|
+
const namespace = namespaces.get(current);
|
|
36
|
+
if (namespace !== undefined)
|
|
37
|
+
return namespace;
|
|
38
|
+
}
|
|
39
|
+
if (nodes.get(current)?.kind === kind)
|
|
40
|
+
return current;
|
|
41
|
+
current = index.parentByNodeId.get(current);
|
|
42
|
+
}
|
|
43
|
+
const classification = nodes.get(nodeId)?.classification;
|
|
44
|
+
return classification === 'vendor' || classification === 'unknown' ? nodeId : undefined;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=rollupSourceRelations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rollupSourceRelations.js","sourceRoot":"","sources":["../../../../src/features/source-graph/domain/rollupSourceRelations.ts"],"names":[],"mappings":"AAMA,iGAAiG;AACjG,MAAM,UAAU,qBAAqB,CACnC,WAAwB,EACxB,KAAuB,EACvB,aAA2D,EAC3D,eAAiE,SAAS;IAE1E,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACvF,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAC/B,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CACvC,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAC9E,CACF,CAAC;IACF,MAAM,KAAK,GAAG,IAAI,GAAG,EAA4B,CAAC;IAClD,KAAK,MAAM,IAAI,IAAI,WAAW,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QAC3C,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,YAAY;YAAE,SAAS;QAC9C,MAAM,MAAM,GAAG,cAAc,CAAC,IAAI,CAAC,MA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,EACzE,UAAuC,EACvC,KAAuB;IAEvB,IAAI,OAAO,GAAuB,MAAM,CAAC;IACzC,OAAO,OAAO,KAAK,SAAS,EAAE,CAAC;QAC7B,IAAI,IAAI,KAAK,SAAS,IAAI,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,IAAI,KAAK,MAAM,EAAE,CAAC;YAC9D,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAC1C,IAAI,SAAS,KAAK,SAAS;gBAAE,OAAO,SAAS,CAAC;QAChD,CAAC;QACD,IAAI,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,IAAI,KAAK,IAAI;YAAE,OAAO,OAAO,CAAC;QACtD,OAAO,GAAG,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;IACD,MAAM,cAAc,GAAG,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,cAAc,CAAC;IACzD,OAAO,cAAc,KAAK,QAAQ,IAAI,cAAc,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AAC1F,CAAC","sourcesContent":["import type {\n SourceGraph,\n SourceGraphIndex,\n SourceRollupEdge,\n} from '../../../types/sourceGraph.js';\n\n/*** Aggregate observed relationships at the requested containment level, preserving edge IDs. */\nexport function rollupSourceRelations(\n sourceGraph: SourceGraph,\n index: SourceGraphIndex,\n aggregateKind: 'project' | 'package' | 'directory' | 'file',\n relationKind: 'imports' | 'exports' | 'extends' | 'implements' = 'imports',\n): readonly SourceRollupEdge[] {\n const nodesById = new Map(sourceGraph.graph.nodes.map((node) => [node.id, node.data]));\n const namespaceByFileId = new Map(\n sourceGraph.graph.edges.flatMap((edge) =>\n edge.data.kind === 'declares-in' ? [[edge.source, edge.target] as const] : [],\n ),\n );\n const pairs = new Map<string, SourceRollupEdge>();\n for (const edge of sourceGraph.graph.edges) {\n if (edge.data.kind !== relationKind) continue;\n const source = ancestorOfKind(edge.source, aggregateKind, nodesById, namespaceByFileId, index);\n const target = ancestorOfKind(edge.target, aggregateKind, nodesById, namespaceByFileId, index);\n if (source === undefined || target === undefined || source === target) continue;\n const sourceSemanticPath = nodesById.get(source)?.semanticPath;\n const targetSemanticPath = nodesById.get(target)?.semanticPath;\n if (sourceSemanticPath === undefined || targetSemanticPath === undefined) continue;\n const key = `${source}\\u0000${target}`;\n const previous = pairs.get(key);\n pairs.set(key, {\n source,\n target,\n sourceSemanticPath,\n targetSemanticPath,\n weight: (previous?.weight ?? 0) + 1,\n evidenceEdgeIds: [...(previous?.evidenceEdgeIds ?? []), edge.id],\n });\n }\n return [...pairs.values()].sort(\n (left, right) => left.source - right.source || left.target - right.target,\n );\n}\n\n/*** Ascend factual containment to one requested projection level. */\nfunction ancestorOfKind(\n nodeId: number,\n kind: 'project' | 'package' | 'directory' | 'file',\n nodes: ReadonlyMap<number, SourceGraph['graph']['nodes'][number]['data']>,\n namespaces: ReadonlyMap<number, number>,\n index: SourceGraphIndex,\n): number | undefined {\n let current: number | undefined = nodeId;\n while (current !== undefined) {\n if (kind === 'package' && nodes.get(current)?.kind === 'file') {\n const namespace = namespaces.get(current);\n if (namespace !== undefined) return namespace;\n }\n if (nodes.get(current)?.kind === kind) return current;\n current = index.parentByNodeId.get(current);\n }\n const classification = nodes.get(nodeId)?.classification;\n return classification === 'vendor' || classification === 'unknown' ? nodeId : undefined;\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { SourceGraph } from '../../../types/sourceGraph.js';
|
|
2
|
+
/*** Intern repeated source strings while retaining a lossless JSON interchange format. */
|
|
3
|
+
export declare function serializeSourceGraph(sourceGraph: SourceGraph): string;
|
|
4
|
+
/*** Restore the complete factual graph before constructing any derived index. */
|
|
5
|
+
export declare function deserializeSourceGraph(serialized: string): SourceGraph;
|
|
6
|
+
//# sourceMappingURL=serializeSourceGraph.d.ts.map
|