Skip to main content

relay_knowledge/domain/operations/software/
projection.rs

1use serde::{Deserialize, Serialize};
2
3use super::super::GraphVersion;
4use super::{
5    SoftwareBuildTarget, SoftwareComponent, SoftwareDependencyUsage, SoftwareDesignElement,
6    SoftwareEntity, SoftwareFile, SoftwareIacResource, SoftwareRelationship, SoftwareSdkUsage,
7    SoftwareShapeDiagnostic, SoftwareSourceKind, SoftwareStatement, SoftwareTopic,
8};
9
10/// Current SQLite read-model contract. Older scopes are rebuilt through the durable projection task.
11pub const SOFTWARE_PROJECTION_SCHEMA_VERSION: u32 = 7;
12
13/// Read-model freshness kept explicit even when repository scope metadata is unavailable.
14#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
15#[serde(rename_all = "snake_case")]
16pub enum SoftwareProjectionFreshness {
17    Fresh,
18    #[default]
19    Stale,
20    Degraded,
21}
22
23impl SoftwareProjectionFreshness {
24    pub const fn as_str(self) -> &'static str {
25        match self {
26            Self::Fresh => "fresh",
27            Self::Stale => "stale",
28            Self::Degraded => "degraded",
29        }
30    }
31
32    pub fn parse(value: &str) -> Option<Self> {
33        match value {
34            "fresh" => Some(Self::Fresh),
35            "stale" => Some(Self::Stale),
36            "degraded" => Some(Self::Degraded),
37            _ => None,
38        }
39    }
40}
41
42/// Bounded provenance coverage summary for the current source scope.
43#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
44pub struct SoftwareSourceCoverage {
45    pub source_kinds: Vec<SoftwareSourceKind>,
46    pub source_path_count: usize,
47    pub evidence_ref_count: usize,
48}
49
50/// Freshness and count summary for the software global projection.
51#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
52pub struct SoftwareGlobalStatus {
53    pub repository_id: String,
54    pub source_scope: String,
55    pub projected_graph_version: GraphVersion,
56    pub stale: bool,
57    #[serde(default = "legacy_ontology_version")]
58    pub ontology_version: String,
59    #[serde(default)]
60    pub projection_schema_version: u32,
61    #[serde(default)]
62    pub source_coverage: SoftwareSourceCoverage,
63    #[serde(default)]
64    pub completeness_basis_points: u16,
65    #[serde(default)]
66    pub freshness: SoftwareProjectionFreshness,
67    #[serde(default)]
68    pub conflict_count: usize,
69    #[serde(default)]
70    pub entity_count: usize,
71    #[serde(default)]
72    pub statement_count: usize,
73    #[serde(default)]
74    pub diagnostic_count: usize,
75    pub component_count: usize,
76    pub sdk_usage_count: usize,
77    pub file_count: usize,
78    pub topic_count: usize,
79    pub relationship_count: usize,
80    pub build_target_count: usize,
81    pub iac_resource_count: usize,
82    pub design_element_count: usize,
83    #[serde(skip_serializing_if = "Option::is_none")]
84    pub last_error: Option<String>,
85}
86
87fn legacy_ontology_version() -> String {
88    "legacy-unknown".to_owned()
89}
90
91/// Projected software global facts for one repository scope.
92#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
93pub struct SoftwareGlobalProjection {
94    pub status: SoftwareGlobalStatus,
95    pub components: Vec<SoftwareComponent>,
96    pub dependency_usages: Vec<SoftwareDependencyUsage>,
97    pub sdk_usages: Vec<SoftwareSdkUsage>,
98    pub files: Vec<SoftwareFile>,
99    pub topics: Vec<SoftwareTopic>,
100    pub relationships: Vec<SoftwareRelationship>,
101    pub build_targets: Vec<SoftwareBuildTarget>,
102    pub iac_resources: Vec<SoftwareIacResource>,
103    pub design_elements: Vec<SoftwareDesignElement>,
104    pub entities: Vec<SoftwareEntity>,
105    pub statements: Vec<SoftwareStatement>,
106    pub diagnostics: Vec<SoftwareShapeDiagnostic>,
107}
108
109#[cfg(test)]
110#[path = "projection_tests.rs"]
111mod tests;