Skip to main content

helm_schema_ir/contract/
finalized.rs

1use std::collections::BTreeSet;
2
3use super::{ContractDocument, ContractUse};
4use crate::contract_signal_builder::derive_schema_signals_from_contract_parts;
5use crate::observed_facts::ObservedFacts;
6use helm_schema_core::ContractSchemaSignals;
7
8/// Finalized contract artifact derived from one canonical normalized contract.
9///
10/// Stable inspection rows and schema-lowering signals come from the same
11/// normalized contract uses, so downstream callers do not need to re-finalize
12/// a [`super::ContractIr`] separately or hop through another wrapper type.
13#[derive(Debug, Clone, PartialEq, Eq)]
14pub struct FinalizedContract {
15    uses: Vec<ContractUse>,
16    schema_signals: ContractSchemaSignals,
17}
18
19impl FinalizedContract {
20    pub(in crate::contract) fn new(
21        normalized_uses: Vec<ContractUse>,
22        observed_facts: &ObservedFacts,
23        values_program_wrappers: BTreeSet<helm_schema_core::ValuesProgramWrapper>,
24        values_program_wrapper_exclusions: BTreeSet<String>,
25        dependency_values_root_fragments: &BTreeSet<String>,
26    ) -> Self {
27        let schema_signals = derive_schema_signals_from_contract_parts(
28            &normalized_uses,
29            observed_facts,
30            dependency_values_root_fragments,
31        )
32        .with_values_default_sources(observed_facts.values_default_sources.clone())
33        .with_root_overlay_requirement_implications(
34            observed_facts.values_root_overlay_prefixes.clone(),
35        )
36        .with_values_program_wrappers(values_program_wrappers)
37        .with_values_program_wrapper_exclusions(values_program_wrapper_exclusions);
38
39        Self {
40            uses: normalized_uses,
41            schema_signals,
42        }
43    }
44
45    /// Returns normalized contract uses in stable inspection order.
46    #[must_use]
47    pub fn uses(&self) -> &[ContractUse] {
48        &self.uses
49    }
50
51    /// Returns path-local facts prepared for schema lowering.
52    #[must_use]
53    pub fn schema_signals(&self) -> &ContractSchemaSignals {
54        &self.schema_signals
55    }
56
57    /// Builds the versioned inspection document for this contract.
58    #[must_use]
59    pub fn document(&self) -> ContractDocument {
60        ContractDocument::from_contract_uses(self.uses.clone())
61    }
62
63    /// Consumes the contract and returns its schema-lowering signals.
64    #[must_use]
65    pub fn into_schema_signals(self) -> ContractSchemaSignals {
66        self.schema_signals
67    }
68}