diff --git a/src/application/javascript/JavaScriptArtifactGraphFindings.ts b/src/application/javascript/JavaScriptArtifactGraphFindings.ts index 1ee1e0f86f7..a17d821dc64 100644 --- a/src/application/javascript/JavaScriptArtifactGraphFindings.ts +++ b/src/application/javascript/JavaScriptArtifactGraphFindings.ts @@ -4,6 +4,7 @@ import { compactStringIdentityKey } from "../../domain/compactStringIdentity.js" import type { ApplicationNode } from "../../domain/javascript/javascriptApplicationGraphSchemas.js"; import { VITE_OUTPUT_DEPENDENCY_PREFIX, + type JavaScriptSourceRange, type JavaScriptStaticAnalysis, } from "../../domain/javascript/javascriptStaticAnalysisTypes.js"; import type { JavaScriptArtifactFile } from "../../domain/javascript/javascriptArtifactFiles.js"; @@ -51,6 +52,27 @@ interface FindingInput { readonly coverage: JavaScriptArtifactGraphCoverage; } +const findingEdgeSource = ({ + file, + value, + coverage, +}: FindingInput<{ readonly location: JavaScriptSourceRange }>) => ({ + file, + range: value.location, + coverage, +}); + +const findingEvidenceSource = ({ + file, + value, + coverage, +}: FindingInput<{ readonly location: JavaScriptSourceRange }>) => ({ + sha256: file.sha256, + path: file.path, + range: value.location, + coverage, +}); + interface ResolvedReference { readonly targetImportsUnexamined?: true; readonly path: string | null; @@ -272,11 +294,8 @@ const addReference = ( ...artifactPathResolutionProperties(resolved?.resolution), }, evidence: staticInferenceEvidence({ - sha256: input.file.sha256, - path: input.file.path, - range: input.value.location, + ...findingEvidenceSource(input), operation: "discover-worker", - coverage: input.coverage, ...loaderEvidence, }), }, @@ -285,9 +304,7 @@ const addReference = ( addStaticInferenceEdge(context, { source, target: worker, - file: input.file, - range: input.value.location, - coverage: input.coverage, + ...findingEdgeSource(input), relation: "loads", properties: { kind: input.value.kind, @@ -300,9 +317,7 @@ const addReference = ( addStaticInferenceEdge(context, { source: worker, target: resolved.node, - file: input.file, - range: input.value.location, - coverage: input.coverage, + ...findingEdgeSource(input), relation: "maps_to", properties: { resolved_path: resolved.path }, ...loaderEvidence, @@ -322,9 +337,7 @@ const addReference = ( addStaticInferenceEdge(context, { source, target, - file: input.file, - range: input.value.location, - coverage: input.coverage, + ...findingEdgeSource(input), relation: input.value.operation === "load" && resolved?.path != null && @@ -397,11 +410,8 @@ const addEndpoint = ( }, evidence: candidate ? staticInferenceEvidence({ - sha256: input.file.sha256, - path: input.file.path, - range: input.value.location, + ...findingEvidenceSource(input), operation: "classify-static-endpoint-candidate", - coverage: input.coverage, confidence: "low", limitations: [ candidateLimitation, @@ -409,11 +419,8 @@ const addEndpoint = ( ], }) : astObservationEvidence({ - sha256: input.file.sha256, - path: input.file.path, - range: input.value.location, + ...findingEvidenceSource(input), operation: "discover-static-endpoint", - coverage: input.coverage, ...(partial ? { limitations: [partialLimitation] } : {}), }), }, @@ -422,9 +429,7 @@ const addEndpoint = ( addStaticInferenceEdge(context, { source, target: node, - file: input.file, - range: input.value.location, - coverage: input.coverage, + ...findingEdgeSource(input), relation: input.value.kind === "route" ? "exposes" : "calls", properties: { mechanism: input.value.mechanism, @@ -471,20 +476,14 @@ const addStorage = ( }, evidence: candidate ? staticInferenceEvidence({ - sha256: input.file.sha256, - path: input.file.path, - range: input.value.location, + ...findingEvidenceSource(input), operation: "classify-static-storage-candidate", - coverage: input.coverage, confidence: "low", limitations: [limitation], }) : astObservationEvidence({ - sha256: input.file.sha256, - path: input.file.path, - range: input.value.location, + ...findingEvidenceSource(input), operation: "discover-static-storage", - coverage: input.coverage, }), }, ], @@ -492,9 +491,7 @@ const addStorage = ( addStaticInferenceEdge(context, { source, target: node, - file: input.file, - range: input.value.location, - coverage: input.coverage, + ...findingEdgeSource(input), relation: "persists_to", properties: { mechanism: input.value.mechanism, @@ -568,9 +565,7 @@ const addDiscoveredRole = ( addStaticInferenceEdge(context, { source, target: role, - file: input.file, - range: input.value.location, - coverage: input.coverage, + ...findingEdgeSource(input), relation: "loads", properties: { mechanism: input.value.mechanism, @@ -619,11 +614,8 @@ const addCandidateRole = ( label: input.value.path, properties, evidence: staticInferenceEvidence({ - sha256: input.file.sha256, - path: input.file.path, - range: input.value.location, + ...findingEvidenceSource(input), operation: "retain-candidate-electron-role", - coverage: input.coverage, confidence: "low", limitations: [limitation], }), @@ -633,9 +625,7 @@ const addCandidateRole = ( addStaticInferenceEdge(context, { source, target: role, - file: input.file, - range: input.value.location, - coverage: input.coverage, + ...findingEdgeSource(input), relation: "loads", properties, confidence: "low", @@ -692,11 +682,8 @@ const addSourceMapEdge = ( available: isAvailable, }, evidence: staticInferenceEvidence({ - sha256: input.file.sha256, - path: input.file.path, - range: input.value.location, + ...findingEvidenceSource(input), operation: "discover-source-map", - coverage: input.coverage, confidence: "medium", limitations, }), @@ -706,9 +693,7 @@ const addSourceMapEdge = ( addStaticInferenceEdge(context, { source: input.asset, target, - file: input.file, - range: input.value.location, - coverage: input.coverage, + ...findingEdgeSource(input), relation: "maps_to", limitations, properties: {