@ankhorage/dependency-graph 0.7.2 → 1.0.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 +6 -0
- package/README.md +12 -3
- package/dist/dependencyGraph.d.ts +13 -9
- package/dist/dependencyGraph.d.ts.map +1 -1
- package/dist/dependencyGraph.js +11 -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 → 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/composition/createDependencyGraphFromInspectionsAsync.d.ts.map +1 -0
- package/dist/features/dependency-analysis/composition/createDependencyGraphFromInspectionsAsync.js +58 -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/{application → composition}/createDependencyGraphFromInspectionsAsync.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,4 @@
|
|
|
1
|
+
import type { SourceGraph, SourceGraphDraft } from '../../../types/sourceGraph.js';
|
|
2
|
+
/*** Assign dense numeric IDs to deterministic factual source nodes and edges. */
|
|
3
|
+
export declare function createSourceGraph(draft: SourceGraphDraft): SourceGraph;
|
|
4
|
+
//# sourceMappingURL=createSourceGraph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSourceGraph.d.ts","sourceRoot":"","sources":["../../../../src/features/source-graph/domain/createSourceGraph.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,WAAW,EACX,gBAAgB,EAEjB,MAAM,+BAA+B,CAAC;AAEvC,iFAAiF;AACjF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,gBAAgB,GAAG,WAAW,CAmBtE"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { createGraph } from '@ankhorage/graph';
|
|
2
|
+
/*** Assign dense numeric IDs to deterministic factual source nodes and edges. */
|
|
3
|
+
export function createSourceGraph(draft) {
|
|
4
|
+
const nodes = [...draft.nodes].sort(compareNodeDrafts);
|
|
5
|
+
assertUniqueSemanticPaths(nodes);
|
|
6
|
+
const idBySemanticPath = new Map(nodes.map((node, id) => [node.data.semanticPath, id]));
|
|
7
|
+
const edges = [...draft.edges].sort(compareEdgeDrafts).map((edge, id) => ({
|
|
8
|
+
id,
|
|
9
|
+
source: requiredNodeId(idBySemanticPath, edge.source),
|
|
10
|
+
target: requiredNodeId(idBySemanticPath, edge.target),
|
|
11
|
+
data: edge.data,
|
|
12
|
+
}));
|
|
13
|
+
return {
|
|
14
|
+
version: 1,
|
|
15
|
+
graph: createGraph({
|
|
16
|
+
nodes: nodes.map((node, id) => ({ id, data: node.data })),
|
|
17
|
+
edges,
|
|
18
|
+
}),
|
|
19
|
+
capabilities: [...draft.capabilities].map(sortCapabilities).sort(compareCapabilityReports),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/*** Reject ambiguous stable identities before assigning compact IDs. */
|
|
23
|
+
function assertUniqueSemanticPaths(nodes) {
|
|
24
|
+
const seen = new Set();
|
|
25
|
+
for (const node of nodes) {
|
|
26
|
+
const key = node.data.semanticPath;
|
|
27
|
+
if (key.trim() === '')
|
|
28
|
+
throw new Error('Source nodes require a semantic path.');
|
|
29
|
+
if (seen.has(key))
|
|
30
|
+
throw new Error(`Duplicate source semantic path: ${key}.`);
|
|
31
|
+
seen.add(key);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/*** Resolve one edge endpoint from the semantic identity index. */
|
|
35
|
+
function requiredNodeId(ids, semanticPath) {
|
|
36
|
+
const id = ids.get(semanticPath);
|
|
37
|
+
if (id === undefined)
|
|
38
|
+
throw new Error(`Unknown source semantic path: ${semanticPath}.`);
|
|
39
|
+
return id;
|
|
40
|
+
}
|
|
41
|
+
/*** Order semantic nodes without host-locale behavior. */
|
|
42
|
+
function compareNodeDrafts(left, right) {
|
|
43
|
+
return compareText(left.data.semanticPath, right.data.semanticPath);
|
|
44
|
+
}
|
|
45
|
+
/*** Order observed relations by semantic endpoints, kind, and evidence. */
|
|
46
|
+
function compareEdgeDrafts(left, right) {
|
|
47
|
+
return (compareText(left.source, right.source) ||
|
|
48
|
+
compareText(left.target, right.target) ||
|
|
49
|
+
compareText(left.data.kind, right.data.kind) ||
|
|
50
|
+
compareText(evidenceKey(left), evidenceKey(right)));
|
|
51
|
+
}
|
|
52
|
+
/*** Build a stable ordering key from exact analyzer evidence. */
|
|
53
|
+
function evidenceKey(edge) {
|
|
54
|
+
return edge.data.evidence
|
|
55
|
+
.map(({ analyzerId, sourcePath, location, specifier }) => `${analyzerId}\u0000${sourcePath}\u0000${location?.line ?? ''}\u0000${location?.column ?? ''}\u0000${specifier ?? ''}`)
|
|
56
|
+
.sort(compareText)
|
|
57
|
+
.join('\u0001');
|
|
58
|
+
}
|
|
59
|
+
/*** Canonicalize each analyzer's explicit available-capability list. */
|
|
60
|
+
function sortCapabilities(report) {
|
|
61
|
+
return { ...report, available: [...report.available].sort(compareText) };
|
|
62
|
+
}
|
|
63
|
+
/*** Keep analyzer provenance order stable in serialized snapshots. */
|
|
64
|
+
function compareCapabilityReports(left, right) {
|
|
65
|
+
return (compareText(left.projectId, right.projectId) || compareText(left.analyzerId, right.analyzerId));
|
|
66
|
+
}
|
|
67
|
+
/*** Compare portable identities by code unit rather than process locale. */
|
|
68
|
+
function compareText(left, right) {
|
|
69
|
+
if (left < right)
|
|
70
|
+
return -1;
|
|
71
|
+
return left > right ? 1 : 0;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=createSourceGraph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSourceGraph.js","sourceRoot":"","sources":["../../../../src/features/source-graph/domain/createSourceGraph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAU/C,iFAAiF;AACjF,MAAM,UAAU,iBAAiB,CAAC,KAAuB;IACvD,MAAM,KAAK,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IACvD,yBAAyB,CAAC,KAAK,CAAC,CAAC;IACjC,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,CAAU,CAAC,CAAC,CAAC;IACjG,MAAM,KAAK,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;QACxE,EAAE;QACF,MAAM,EAAE,cAAc,CAAC,gBAAgB,EAAE,IAAI,CAAC,MAAM,CAAC;QACrD,MAAM,EAAE,cAAc,CAAC,gBAAgB,EAAE,IAAI,CAAC,MAAM,CAAC;QACrD,IAAI,EAAE,IAAI,CAAC,IAAI;KAChB,CAAC,CAAC,CAAC;IAEJ,OAAO;QACL,OAAO,EAAE,CAAC;QACV,KAAK,EAAE,WAAW,CAA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4E;AAC5E,SAAS,WAAW,CAAC,IAAY,EAAE,KAAa;IAC9C,IAAI,IAAI,GAAG,KAAK;QAAE,OAAO,CAAC,CAAC,CAAC;IAC5B,OAAO,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["import { createGraph } from '@ankhorage/graph';\n\nimport type {\n SourceCapabilityReport,\n SourceEdgeDraft,\n SourceGraph,\n SourceGraphDraft,\n SourceNodeDraft,\n} from '../../../types/sourceGraph.js';\n\n/*** Assign dense numeric IDs to deterministic factual source nodes and edges. */\nexport function createSourceGraph(draft: SourceGraphDraft): SourceGraph {\n const nodes = [...draft.nodes].sort(compareNodeDrafts);\n assertUniqueSemanticPaths(nodes);\n const idBySemanticPath = new Map(nodes.map((node, id) => [node.data.semanticPath, id] as const));\n const edges = [...draft.edges].sort(compareEdgeDrafts).map((edge, id) => ({\n id,\n source: requiredNodeId(idBySemanticPath, edge.source),\n target: requiredNodeId(idBySemanticPath, edge.target),\n data: edge.data,\n }));\n\n return {\n version: 1,\n graph: createGraph({\n nodes: nodes.map((node, id) => ({ id, data: node.data })),\n edges,\n }),\n capabilities: [...draft.capabilities].map(sortCapabilities).sort(compareCapabilityReports),\n };\n}\n\n/*** Reject ambiguous stable identities before assigning compact IDs. */\nfunction assertUniqueSemanticPaths(nodes: readonly SourceNodeDraft[]): void {\n const seen = new Set<string>();\n for (const node of nodes) {\n const key = node.data.semanticPath;\n if (key.trim() === '') throw new Error('Source nodes require a semantic path.');\n if (seen.has(key)) throw new Error(`Duplicate source semantic path: ${key}.`);\n seen.add(key);\n }\n}\n\n/*** Resolve one edge endpoint from the semantic identity index. */\nfunction requiredNodeId(ids: ReadonlyMap<string, number>, semanticPath: string): number {\n const id = ids.get(semanticPath);\n if (id === undefined) throw new Error(`Unknown source semantic path: ${semanticPath}.`);\n return id;\n}\n\n/*** Order semantic nodes without host-locale behavior. */\nfunction compareNodeDrafts(left: SourceNodeDraft, right: SourceNodeDraft): number {\n return compareText(left.data.semanticPath, right.data.semanticPath);\n}\n\n/*** Order observed relations by semantic endpoints, kind, and evidence. */\nfunction compareEdgeDrafts(left: SourceEdgeDraft, right: SourceEdgeDraft): number {\n return (\n compareText(left.source, right.source) ||\n compareText(left.target, right.target) ||\n compareText(left.data.kind, right.data.kind) ||\n compareText(evidenceKey(left), evidenceKey(right))\n );\n}\n\n/*** Build a stable ordering key from exact analyzer evidence. */\nfunction evidenceKey(edge: SourceEdgeDraft): string {\n return edge.data.evidence\n .map(\n ({ analyzerId, sourcePath, location, specifier }) =>\n `${analyzerId}\\u0000${sourcePath}\\u0000${location?.line ?? ''}\\u0000${location?.column ?? ''}\\u0000${specifier ?? ''}`,\n )\n .sort(compareText)\n .join('\\u0001');\n}\n\n/*** Canonicalize each analyzer's explicit available-capability list. */\nfunction sortCapabilities(report: SourceCapabilityReport): SourceCapabilityReport {\n return { ...report, available: [...report.available].sort(compareText) };\n}\n\n/*** Keep analyzer provenance order stable in serialized snapshots. */\nfunction compareCapabilityReports(\n left: SourceCapabilityReport,\n right: SourceCapabilityReport,\n): number {\n return (\n compareText(left.projectId, right.projectId) || compareText(left.analyzerId, right.analyzerId)\n );\n}\n\n/*** Compare portable identities by code unit rather than process locale. */\nfunction compareText(left: string, right: string): number {\n if (left < right) return -1;\n return left > right ? 1 : 0;\n}\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SourceGraph, SourceGraphIndex } from '../../../types/sourceGraph.js';
|
|
2
|
+
/*** Build reusable semantic and adjacency indexes once from observed source facts. */
|
|
3
|
+
export declare function createSourceGraphIndex(sourceGraph: SourceGraph): SourceGraphIndex;
|
|
4
|
+
//# sourceMappingURL=createSourceGraphIndex.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSourceGraphIndex.d.ts","sourceRoot":"","sources":["../../../../src/features/source-graph/domain/createSourceGraphIndex.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,WAAW,EACX,gBAAgB,EAEjB,MAAM,+BAA+B,CAAC;AAEvC,sFAAsF;AACtF,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,WAAW,GAAG,gBAAgB,CA6CjF"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/*** Build reusable semantic and adjacency indexes once from observed source facts. */
|
|
2
|
+
export function createSourceGraphIndex(sourceGraph) {
|
|
3
|
+
const nodeById = new Map();
|
|
4
|
+
const nodeBySemanticPath = new Map();
|
|
5
|
+
const fileByPath = new Map();
|
|
6
|
+
const symbolsByFileAndName = new Map();
|
|
7
|
+
const incomingByNodeId = new Map();
|
|
8
|
+
const outgoingByNodeId = new Map();
|
|
9
|
+
const parentByNodeId = new Map();
|
|
10
|
+
// Local map mutation constructs lookup tables without rescanning on consumer queries.
|
|
11
|
+
for (const node of sourceGraph.graph.nodes) {
|
|
12
|
+
nodeById.set(node.id, node);
|
|
13
|
+
nodeBySemanticPath.set(node.data.semanticPath, node);
|
|
14
|
+
incomingByNodeId.set(node.id, []);
|
|
15
|
+
outgoingByNodeId.set(node.id, []);
|
|
16
|
+
if (node.data.kind === 'file' && node.data.path !== undefined) {
|
|
17
|
+
fileByPath.set(fileKey(node.data.projectId, node.data.path), node);
|
|
18
|
+
}
|
|
19
|
+
if (node.data.filePath !== undefined && isDeclaration(node.data.kind)) {
|
|
20
|
+
const key = symbolKey(node.data.projectId, node.data.filePath, node.data.name);
|
|
21
|
+
symbolsByFileAndName.set(key, [...(symbolsByFileAndName.get(key) ?? []), node]);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
for (const edge of sourceGraph.graph.edges) {
|
|
25
|
+
outgoingByNodeId.get(edge.source)?.push(edge);
|
|
26
|
+
incomingByNodeId.get(edge.target)?.push(edge);
|
|
27
|
+
if (edge.data.kind === 'contains') {
|
|
28
|
+
const existing = parentByNodeId.get(edge.target);
|
|
29
|
+
if (existing !== undefined && existing !== edge.source) {
|
|
30
|
+
throw new Error(`Source node ${edge.target} has multiple containment parents.`);
|
|
31
|
+
}
|
|
32
|
+
parentByNodeId.set(edge.target, edge.source);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
nodeById,
|
|
37
|
+
nodeBySemanticPath,
|
|
38
|
+
fileByPath,
|
|
39
|
+
symbolsByFileAndName,
|
|
40
|
+
incomingByNodeId,
|
|
41
|
+
outgoingByNodeId,
|
|
42
|
+
parentByNodeId,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/*** Distinguish declarations from container and external-package nodes. */
|
|
46
|
+
function isDeclaration(kind) {
|
|
47
|
+
return kind !== 'project' && kind !== 'package' && kind !== 'directory' && kind !== 'file';
|
|
48
|
+
}
|
|
49
|
+
/*** Scope a path lookup to one observed project. */
|
|
50
|
+
function fileKey(projectId, path) {
|
|
51
|
+
return `${projectId}\u0000${path}`;
|
|
52
|
+
}
|
|
53
|
+
/*** Scope a symbol lookup to its project, file, and human-readable name. */
|
|
54
|
+
function symbolKey(projectId, path, name) {
|
|
55
|
+
return `${fileKey(projectId, path)}\u0000${name}`;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=createSourceGraphIndex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSourceGraphIndex.js","sourceRoot":"","sources":["../../../../src/features/source-graph/domain/createSourceGraphIndex.ts"],"names":[],"mappings":"AASA,sFAAsF;AACtF,MAAM,UAAU,sBAAsB,CAAC,WAAwB;IAC7D,MAAM,QAAQ,GAAG,IAAI,GAAG,EAA6C,CAAC;IACtE,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAA6C,CAAC;IAChF,MAAM,UAAU,GAAG,IAAI,GAAG,EAA6C,CAAC;IACxE,MAAM,oBAAoB,GAAG,IAAI,GAAG,EAA+C,CAAC;IACpF,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAuD,CAAC;IACxF,MAAM,gBAAgB,GAAG,IAAI,G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ankhorage/graph';\n\nimport type {\n SourceEdgeData,\n SourceGraph,\n SourceGraphIndex,\n SourceNodeData,\n} from '../../../types/sourceGraph.js';\n\n/*** Build reusable semantic and adjacency indexes once from observed source facts. */\nexport function createSourceGraphIndex(sourceGraph: SourceGraph): SourceGraphIndex {\n const nodeById = new Map<number, GraphNode<SourceNodeData, number>>();\n const nodeBySemanticPath = new Map<string, GraphNode<SourceNodeData, number>>();\n const fileByPath = new Map<string, GraphNode<SourceNodeData, number>>();\n const symbolsByFileAndName = new Map<string, GraphNode<SourceNodeData, number>[]>();\n const incomingByNodeId = new Map<number, GraphEdge<SourceEdgeData, number, number>[]>();\n const outgoingByNodeId = new Map<number, GraphEdge<SourceEdgeData, number, number>[]>();\n const parentByNodeId = new Map<number, number>();\n\n // Local map mutation constructs lookup tables without rescanning on consumer queries.\n for (const node of sourceGraph.graph.nodes) {\n nodeById.set(node.id, node);\n nodeBySemanticPath.set(node.data.semanticPath, node);\n incomingByNodeId.set(node.id, []);\n outgoingByNodeId.set(node.id, []);\n if (node.data.kind === 'file' && node.data.path !== undefined) {\n fileByPath.set(fileKey(node.data.projectId, node.data.path), node);\n }\n if (node.data.filePath !== undefined && isDeclaration(node.data.kind)) {\n const key = symbolKey(node.data.projectId, node.data.filePath, node.data.name);\n symbolsByFileAndName.set(key, [...(symbolsByFileAndName.get(key) ?? []), node]);\n }\n }\n\n for (const edge of sourceGraph.graph.edges) {\n outgoingByNodeId.get(edge.source)?.push(edge);\n incomingByNodeId.get(edge.target)?.push(edge);\n if (edge.data.kind === 'contains') {\n const existing = parentByNodeId.get(edge.target);\n if (existing !== undefined && existing !== edge.source) {\n throw new Error(`Source node ${edge.target} has multiple containment parents.`);\n }\n parentByNodeId.set(edge.target, edge.source);\n }\n }\n\n return {\n nodeById,\n nodeBySemanticPath,\n fileByPath,\n symbolsByFileAndName,\n incomingByNodeId,\n outgoingByNodeId,\n parentByNodeId,\n };\n}\n\n/*** Distinguish declarations from container and external-package nodes. */\nfunction isDeclaration(kind: SourceNodeData['kind']): boolean {\n return kind !== 'project' && kind !== 'package' && kind !== 'directory' && kind !== 'file';\n}\n\n/*** Scope a path lookup to one observed project. */\nfunction fileKey(projectId: string, path: string): string {\n return `${projectId}\\u0000${path}`;\n}\n\n/*** Scope a symbol lookup to its project, file, and human-readable name. */\nfunction symbolKey(projectId: string, path: string, name: string): string {\n return `${fileKey(projectId, path)}\\u0000${name}`;\n}\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SourceAnalyzedFile, SourceGraphDraft } from '../../../types/sourceGraph.js';
|
|
2
|
+
/*** Resolve source imports and inheritance after all declarations have been indexed. */
|
|
3
|
+
export declare function createSourceRelationDraft(structure: SourceGraphDraft, files: readonly SourceAnalyzedFile[]): SourceGraphDraft;
|
|
4
|
+
//# sourceMappingURL=createSourceRelationDraft.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSourceRelationDraft.d.ts","sourceRoot":"","sources":["../../../../src/features/source-graph/domain/createSourceRelationDraft.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAGlB,gBAAgB,EAGjB,MAAM,+BAA+B,CAAC;AAKvC,wFAAwF;AACxF,wBAAgB,yBAAyB,CACvC,SAAS,EAAE,gBAAgB,EAC3B,KAAK,EAAE,SAAS,kBAAkB,EAAE,GACnC,gBAAgB,CA4ClB"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { fileKey } from './createSourceStructureDraft.js';
|
|
2
|
+
import { resolveImport } from './resolveSourceImport.js';
|
|
3
|
+
import { sourceSemanticPath } from './sourceSemanticPath.js';
|
|
4
|
+
/*** Resolve source imports and inheritance after all declarations have been indexed. */
|
|
5
|
+
export function createSourceRelationDraft(structure, files) {
|
|
6
|
+
const nodes = new Map(structure.nodes.map((node) => [node.data.semanticPath, node]));
|
|
7
|
+
const edges = [...structure.edges];
|
|
8
|
+
const symbolIndex = buildSymbolIndex(structure.nodes);
|
|
9
|
+
const declarationIndex = buildDeclarationIndex(structure.nodes);
|
|
10
|
+
const namespaceIndex = buildNamespaceIndex(structure.nodes);
|
|
11
|
+
const focusPackages = new Map(structure.nodes.flatMap(({ data }) => data.kind === 'package' && data.path !== undefined && data.classification === 'intrinsic'
|
|
12
|
+
? [[data.name, data.semanticPath]]
|
|
13
|
+
: []));
|
|
14
|
+
for (const file of files) {
|
|
15
|
+
for (const imported of file.facts.imports) {
|
|
16
|
+
const resolved = resolveImport(file, imported.specifier, imported.local, nodes, symbolIndex, namespaceIndex, focusPackages);
|
|
17
|
+
addRelation(edges, fileKey(file.projectId, file.path), resolved.target, imported.kind === 'reexport' ? 'exports' : 'imports', {
|
|
18
|
+
analyzerId: file.analyzerId,
|
|
19
|
+
sourcePath: file.path,
|
|
20
|
+
...(imported.location === undefined ? {} : { location: imported.location }),
|
|
21
|
+
specifier: imported.specifier,
|
|
22
|
+
...(imported.typeOnly === undefined ? {} : { typeOnly: imported.typeOnly }),
|
|
23
|
+
...(resolved.declarations.length === 0 ? {} : { declarations: resolved.declarations }),
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
for (const declaration of file.facts.declarations) {
|
|
27
|
+
addInheritance(file, declaration, nodes, edges, symbolIndex, declarationIndex);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return { nodes: [...nodes.values()], edges, capabilities: structure.capabilities };
|
|
31
|
+
}
|
|
32
|
+
/*** Index intrinsic namespaces once for import resolution. */
|
|
33
|
+
function buildNamespaceIndex(nodes) {
|
|
34
|
+
const names = new Map();
|
|
35
|
+
for (const { data } of nodes) {
|
|
36
|
+
if (data.kind !== 'package' ||
|
|
37
|
+
data.packageName === undefined ||
|
|
38
|
+
data.classification !== 'intrinsic')
|
|
39
|
+
continue;
|
|
40
|
+
names.set(data.projectId, [...(names.get(data.projectId) ?? []), data.packageName]);
|
|
41
|
+
}
|
|
42
|
+
return new Map([...names].map(([projectId, values]) => [
|
|
43
|
+
projectId,
|
|
44
|
+
values.sort((left, right) => right.length - left.length),
|
|
45
|
+
]));
|
|
46
|
+
}
|
|
47
|
+
/*** Index declaration locations once for evidence relationship resolution. */
|
|
48
|
+
function buildDeclarationIndex(nodes) {
|
|
49
|
+
const index = new Map();
|
|
50
|
+
for (const { data } of nodes) {
|
|
51
|
+
if (data.filePath === undefined || data.location === undefined)
|
|
52
|
+
continue;
|
|
53
|
+
const key = sourceSemanticPath(data.projectId, data.filePath, data.kind, data.name, `${data.location.line}:${data.location.column}`);
|
|
54
|
+
index.set(key, data.semanticPath);
|
|
55
|
+
}
|
|
56
|
+
return index;
|
|
57
|
+
}
|
|
58
|
+
/*** Index source types by project, namespace, and simple name for language-neutral resolution. */
|
|
59
|
+
function buildSymbolIndex(nodes) {
|
|
60
|
+
const index = new Map();
|
|
61
|
+
for (const { data } of nodes) {
|
|
62
|
+
if (data.kind !== 'class' && data.kind !== 'interface' && data.kind !== 'type')
|
|
63
|
+
continue;
|
|
64
|
+
index.set(symbolKey(data.projectId, data.packageName ?? '', data.name), data.semanticPath);
|
|
65
|
+
index.set(symbolKey(data.projectId, '', data.name), data.semanticPath);
|
|
66
|
+
}
|
|
67
|
+
return index;
|
|
68
|
+
}
|
|
69
|
+
/*** Resolve observed extends/implements references with exact source evidence. */
|
|
70
|
+
function addInheritance(file, declaration, nodes, edges, symbols, declarations) {
|
|
71
|
+
const source = declarations.get(sourceSemanticPath(file.projectId, file.path, declaration.kind, declaration.name, `${declaration.location.line}:${declaration.location.column}`));
|
|
72
|
+
if (source !== undefined) {
|
|
73
|
+
for (const [kind, names] of [
|
|
74
|
+
['extends', declaration.extends],
|
|
75
|
+
['implements', declaration.implements],
|
|
76
|
+
]) {
|
|
77
|
+
for (const name of names) {
|
|
78
|
+
const simpleName = name.replace(/<.*$/u, '').split('.').at(-1) ?? name;
|
|
79
|
+
const resolved = symbols.get(symbolKey(file.projectId, file.facts.packageName ?? '', simpleName)) ??
|
|
80
|
+
symbols.get(symbolKey(file.projectId, '', simpleName));
|
|
81
|
+
const target = resolved ?? unresolvedType(file, name, nodes);
|
|
82
|
+
addRelation(edges, source, target, kind, {
|
|
83
|
+
analyzerId: file.analyzerId,
|
|
84
|
+
sourcePath: file.path,
|
|
85
|
+
location: declaration.location,
|
|
86
|
+
specifier: name,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
for (const child of declaration.children) {
|
|
92
|
+
addInheritance(file, child, nodes, edges, symbols, declarations);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/*** Preserve a base-type reference even when its declaration is outside the scan. */
|
|
96
|
+
function unresolvedType(file, name, nodes) {
|
|
97
|
+
const key = sourceSemanticPath('external-type', file.projectId, name);
|
|
98
|
+
if (!nodes.has(key)) {
|
|
99
|
+
nodes.set(key, {
|
|
100
|
+
data: {
|
|
101
|
+
semanticPath: key,
|
|
102
|
+
kind: 'type',
|
|
103
|
+
name,
|
|
104
|
+
projectId: file.projectId,
|
|
105
|
+
classification: 'unknown',
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return key;
|
|
110
|
+
}
|
|
111
|
+
/*** Scope type names without confusing same names in separate Java packages. */
|
|
112
|
+
function symbolKey(projectId, packageName, name) {
|
|
113
|
+
return sourceSemanticPath(projectId, packageName, name);
|
|
114
|
+
}
|
|
115
|
+
/*** Preserve each observed relation as one traceable canonical edge. */
|
|
116
|
+
function addRelation(edges, source, target, kind, evidence) {
|
|
117
|
+
edges.push({ source, target, data: { kind, evidence: [evidence] } });
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=createSourceRelationDraft.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSourceRelationDraft.js","sourceRoot":"","sources":["../../../../src/features/source-graph/domain/createSourceRelationDraft.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC1D,OAAO,EAAE,aAAa,EA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,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE;YACb,IAAI,EAAE;gBACJ,YAAY,EAAE,GAAG;gBACjB,IAAI,EAAE,MAAM;gBACZ,IAAI;gBACJ,SAAS,EAAE,IAAI,CAAC,SAAS;gBACzB,cAAc,EAAE,SAAS;aAC1B;SACF,CAAC,CAAC;IACL,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,gFAAgF;AAChF,SAAS,SAAS,CAAC,SAAiB,EAAE,WAAmB,EAAE,IAAY;IACrE,OAAO,kBAAkB,CAAC,SAAS,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;AAC1D,CAAC;AAED,wEAAwE;AACxE,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","sourcesContent":["import type {\n SourceAnalyzedFile,\n SourceDeclarationFact,\n SourceEdgeDraft,\n SourceGraphDraft,\n SourceNodeDraft,\n SourceRelationEvidence,\n} from '../../../types/sourceGraph.js';\nimport { fileKey } from './createSourceStructureDraft.js';\nimport { resolveImport } from './resolveSourceImport.js';\nimport { sourceSemanticPath } from './sourceSemanticPath.js';\n\n/*** Resolve source imports and inheritance after all declarations have been indexed. */\nexport function createSourceRelationDraft(\n structure: SourceGraphDraft,\n files: readonly SourceAnalyzedFile[],\n): SourceGraphDraft {\n const nodes = new Map(structure.nodes.map((node) => [node.data.semanticPath, node]));\n const edges = [...structure.edges];\n const symbolIndex = buildSymbolIndex(structure.nodes);\n const declarationIndex = buildDeclarationIndex(structure.nodes);\n const namespaceIndex = buildNamespaceIndex(structure.nodes);\n const focusPackages = new Map(\n structure.nodes.flatMap(({ data }) =>\n data.kind === 'package' && data.path !== undefined && data.classification === 'intrinsic'\n ? [[data.name, data.semanticPath] as const]\n : [],\n ),\n );\n for (const file of files) {\n for (const imported of file.facts.imports) {\n const resolved = resolveImport(\n file,\n imported.specifier,\n imported.local,\n nodes,\n symbolIndex,\n namespaceIndex,\n focusPackages,\n );\n addRelation(\n edges,\n fileKey(file.projectId, file.path),\n resolved.target,\n imported.kind === 'reexport' ? 'exports' : 'imports',\n {\n analyzerId: file.analyzerId,\n sourcePath: file.path,\n ...(imported.location === undefined ? {} : { location: imported.location }),\n specifier: imported.specifier,\n ...(imported.typeOnly === undefined ? {} : { typeOnly: imported.typeOnly }),\n ...(resolved.declarations.length === 0 ? {} : { declarations: resolved.declarations }),\n },\n );\n }\n for (const declaration of file.facts.declarations) {\n addInheritance(file, declaration, nodes, edges, symbolIndex, declarationIndex);\n }\n }\n return { nodes: [...nodes.values()], edges, capabilities: structure.capabilities };\n}\n\n/*** Index intrinsic namespaces once for import resolution. */\nfunction buildNamespaceIndex(\n nodes: readonly SourceNodeDraft[],\n): ReadonlyMap<string, readonly string[]> {\n const names = new Map<string, string[]>();\n for (const { data } of nodes) {\n if (\n data.kind !== 'package' ||\n data.packageName === undefined ||\n data.classification !== 'intrinsic'\n )\n continue;\n names.set(data.projectId, [...(names.get(data.projectId) ?? []), data.packageName]);\n }\n return new Map(\n [...names].map(([projectId, values]) => [\n projectId,\n values.sort((left, right) => right.length - left.length),\n ]),\n );\n}\n\n/*** Index declaration locations once for evidence relationship resolution. */\nfunction buildDeclarationIndex(nodes: readonly SourceNodeDraft[]): ReadonlyMap<string, string> {\n const index = new Map<string, string>();\n for (const { data } of nodes) {\n if (data.filePath === undefined || data.location === undefined) continue;\n const key = sourceSemanticPath(\n data.projectId,\n data.filePath,\n data.kind,\n data.name,\n `${data.location.line}:${data.location.column}`,\n );\n index.set(key, data.semanticPath);\n }\n return index;\n}\n\n/*** Index source types by project, namespace, and simple name for language-neutral resolution. */\nfunction buildSymbolIndex(nodes: readonly SourceNodeDraft[]): ReadonlyMap<string, string> {\n const index = new Map<string, string>();\n for (const { data } of nodes) {\n if (data.kind !== 'class' && data.kind !== 'interface' && data.kind !== 'type') continue;\n index.set(symbolKey(data.projectId, data.packageName ?? '', data.name), data.semanticPath);\n index.set(symbolKey(data.projectId, '', data.name), data.semanticPath);\n }\n return index;\n}\n\n/*** Resolve observed extends/implements references with exact source evidence. */\nfunction addInheritance(\n file: SourceAnalyzedFile,\n declaration: SourceDeclarationFact,\n nodes: Map<string, SourceNodeDraft>,\n edges: SourceEdgeDraft[],\n symbols: ReadonlyMap<string, string>,\n declarations: ReadonlyMap<string, string>,\n): void {\n const source = declarations.get(\n sourceSemanticPath(\n file.projectId,\n file.path,\n declaration.kind,\n declaration.name,\n `${declaration.location.line}:${declaration.location.column}`,\n ),\n );\n if (source !== undefined) {\n for (const [kind, names] of [\n ['extends', declaration.extends],\n ['implements', declaration.implements],\n ] as const) {\n for (const name of names) {\n const simpleName = name.replace(/<.*$/u, '').split('.').at(-1) ?? name;\n const resolved =\n symbols.get(symbolKey(file.projectId, file.facts.packageName ?? '', simpleName)) ??\n symbols.get(symbolKey(file.projectId, '', simpleName));\n const target = resolved ?? unresolvedType(file, name, nodes);\n addRelation(edges, source, target, kind, {\n analyzerId: file.analyzerId,\n sourcePath: file.path,\n location: declaration.location,\n specifier: name,\n });\n }\n }\n }\n for (const child of declaration.children) {\n addInheritance(file, child, nodes, edges, symbols, declarations);\n }\n}\n\n/*** Preserve a base-type reference even when its declaration is outside the scan. */\nfunction unresolvedType(\n file: SourceAnalyzedFile,\n name: string,\n nodes: Map<string, SourceNodeDraft>,\n): string {\n const key = sourceSemanticPath('external-type', file.projectId, name);\n if (!nodes.has(key)) {\n nodes.set(key, {\n data: {\n semanticPath: key,\n kind: 'type',\n name,\n projectId: file.projectId,\n classification: 'unknown',\n },\n });\n }\n return key;\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\n/*** Preserve each observed relation as one traceable canonical edge. */\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"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { SourceRollupEdge, SourceRollupIndex } from '../../../types/sourceGraph.js';
|
|
2
|
+
/*** Index one computed rollup so repeated semantic dependency queries avoid graph scans. */
|
|
3
|
+
export declare function createSourceRollupIndex(rollups: readonly SourceRollupEdge[]): SourceRollupIndex;
|
|
4
|
+
/*** Look up an aggregate dependency using stable semantic identities. */
|
|
5
|
+
export declare function findRolledUpDependency(index: SourceRollupIndex, sourceSemanticPath: string, targetSemanticPath: string): SourceRollupEdge | undefined;
|
|
6
|
+
/*** List aggregate dependencies leaving one semantic container. */
|
|
7
|
+
export declare function outgoingRolledUpDependencies(index: SourceRollupIndex, sourceSemanticPath: string): readonly SourceRollupEdge[];
|
|
8
|
+
//# sourceMappingURL=createSourceRollupIndex.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSourceRollupIndex.d.ts","sourceRoot":"","sources":["../../../../src/features/source-graph/domain/createSourceRollupIndex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAEzF,4FAA4F;AAC5F,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,SAAS,gBAAgB,EAAE,GAAG,iBAAiB,CAU/F;AAED,yEAAyE;AACzE,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,iBAAiB,EACxB,kBAAkB,EAAE,MAAM,EAC1B,kBAAkB,EAAE,MAAM,GACzB,gBAAgB,GAAG,SAAS,CAE9B;AAED,mEAAmE;AACnE,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,iBAAiB,EACxB,kBAAkB,EAAE,MAAM,GACzB,SAAS,gBAAgB,EAAE,CAE7B"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*** Index one computed rollup so repeated semantic dependency queries avoid graph scans. */
|
|
2
|
+
export function createSourceRollupIndex(rollups) {
|
|
3
|
+
const byPair = new Map();
|
|
4
|
+
const outgoingBySource = new Map();
|
|
5
|
+
for (const edge of rollups) {
|
|
6
|
+
byPair.set(pairKey(edge.sourceSemanticPath, edge.targetSemanticPath), edge);
|
|
7
|
+
const outgoing = outgoingBySource.get(edge.sourceSemanticPath);
|
|
8
|
+
if (outgoing === undefined)
|
|
9
|
+
outgoingBySource.set(edge.sourceSemanticPath, [edge]);
|
|
10
|
+
else
|
|
11
|
+
outgoing.push(edge);
|
|
12
|
+
}
|
|
13
|
+
return { byPair, outgoingBySource };
|
|
14
|
+
}
|
|
15
|
+
/*** Look up an aggregate dependency using stable semantic identities. */
|
|
16
|
+
export function findRolledUpDependency(index, sourceSemanticPath, targetSemanticPath) {
|
|
17
|
+
return index.byPair.get(pairKey(sourceSemanticPath, targetSemanticPath));
|
|
18
|
+
}
|
|
19
|
+
/*** List aggregate dependencies leaving one semantic container. */
|
|
20
|
+
export function outgoingRolledUpDependencies(index, sourceSemanticPath) {
|
|
21
|
+
return index.outgoingBySource.get(sourceSemanticPath) ?? [];
|
|
22
|
+
}
|
|
23
|
+
/*** Preserve pair identity even when paths contain punctuation. */
|
|
24
|
+
function pairKey(source, target) {
|
|
25
|
+
return `${source}\u0000${target}`;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=createSourceRollupIndex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSourceRollupIndex.js","sourceRoot":"","sources":["../../../../src/features/source-graph/domain/createSourceRollupIndex.ts"],"names":[],"mappings":"AAEA,4FAA4F;AAC5F,MAAM,UAAU,uBAAuB,CAAC,OAAoC;IAC1E,MAAM,MAAM,GAAG,IAAI,GAAG,EAA4B,CAAC;IACnD,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAA8B,CAAC;IAC/D,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;QAC3B,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,kBAAkB,EAAE,IAAI,CAAC,kBAAkB,CAAC,EAAE,IAAI,CAAC,CAAC;QAC5E,MAAM,QAAQ,GAAG,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;QAC/D,IAAI,QAAQ,KAAK,SAAS;YAAE,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,kBAAkB,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;;YAC7E,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC;AACtC,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,sBAAsB,CACpC,KAAwB,EACxB,kBAA0B,EAC1B,kBAA0B;IAE1B,OAAO,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CAAC;AAC3E,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,4BAA4B,CAC1C,KAAwB,EACxB,kBAA0B;IAE1B,OAAO,KAAK,CAAC,gBAAgB,CAAC,GAAG,CAAC,kBAAkB,CAAC,IAAI,EAAE,CAAC;AAC9D,CAAC;AAED,mEAAmE;AACnE,SAAS,OAAO,CAAC,MAAc,EAAE,MAAc;IAC7C,OAAO,GAAG,MAAM,SAAS,MAAM,EAAE,CAAC;AACpC,CAAC","sourcesContent":["import type { SourceRollupEdge, SourceRollupIndex } from '../../../types/sourceGraph.js';\n\n/*** Index one computed rollup so repeated semantic dependency queries avoid graph scans. */\nexport function createSourceRollupIndex(rollups: readonly SourceRollupEdge[]): SourceRollupIndex {\n const byPair = new Map<string, SourceRollupEdge>();\n const outgoingBySource = new Map<string, SourceRollupEdge[]>();\n for (const edge of rollups) {\n byPair.set(pairKey(edge.sourceSemanticPath, edge.targetSemanticPath), edge);\n const outgoing = outgoingBySource.get(edge.sourceSemanticPath);\n if (outgoing === undefined) outgoingBySource.set(edge.sourceSemanticPath, [edge]);\n else outgoing.push(edge);\n }\n return { byPair, outgoingBySource };\n}\n\n/*** Look up an aggregate dependency using stable semantic identities. */\nexport function findRolledUpDependency(\n index: SourceRollupIndex,\n sourceSemanticPath: string,\n targetSemanticPath: string,\n): SourceRollupEdge | undefined {\n return index.byPair.get(pairKey(sourceSemanticPath, targetSemanticPath));\n}\n\n/*** List aggregate dependencies leaving one semantic container. */\nexport function outgoingRolledUpDependencies(\n index: SourceRollupIndex,\n sourceSemanticPath: string,\n): readonly SourceRollupEdge[] {\n return index.outgoingBySource.get(sourceSemanticPath) ?? [];\n}\n\n/*** Preserve pair identity even when paths contain punctuation. */\nfunction pairKey(source: string, target: string): string {\n return `${source}\\u0000${target}`;\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ProjectInspection } from '@ankhorage/project-detector/types';
|
|
2
|
+
import type { SourceAnalyzedFile, SourceGraphDraft } from '../../../types/sourceGraph.js';
|
|
3
|
+
interface SourceProject {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly inspection: ProjectInspection;
|
|
6
|
+
}
|
|
7
|
+
/*** Preserve scanned projects, packages, empty directories, files, and nested declarations. */
|
|
8
|
+
export declare function createSourceStructureDraft(projects: readonly SourceProject[], files: readonly SourceAnalyzedFile[]): SourceGraphDraft;
|
|
9
|
+
export declare function fileKey(projectId: string, file: string): string;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=createSourceStructureDraft.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSourceStructureDraft.d.ts","sourceRoot":"","sources":["../../../../src/features/source-graph/domain/createSourceStructureDraft.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAE3E,OAAO,KAAK,EACV,kBAAkB,EAElB,gBAAgB,EAIjB,MAAM,+BAA+B,CAAC;AAGvC,UAAU,aAAa;IACrB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,UAAU,EAAE,iBAAiB,CAAC;CACxC;AAED,+FAA+F;AAC/F,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,SAAS,aAAa,EAAE,EAClC,KAAK,EAAE,SAAS,kBAAkB,EAAE,GACnC,gBAAgB,CAoBlB;AA8RD,wBAAgB,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE/D"}
|