panproto-vcs 0.39.0

Schematic version control for panproto — git-like VCS for schema evolution
Documentation
//! Staging area (index) for the next commit.
//!
//! The index tracks a proposed schema change before it is committed.
//! The staging pipeline validates the migration and produces a
//! compatibility report.

use std::path::PathBuf;

use serde::{Deserialize, Serialize};

use crate::gat_validate::GatDiagnostics;
use crate::hash::ObjectId;

/// The staging area for the next commit.
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct Index {
    /// The schema staged for the next commit, if any.
    pub staged: Option<StagedSchema>,
    /// Data files staged for the next commit.
    #[serde(default)]
    pub staged_data: Vec<StagedData>,
    /// Protocol definition staged for the next commit.
    #[serde(default)]
    pub staged_protocol: Option<ObjectId>,
}

/// A data file that has been staged for commit.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct StagedData {
    /// Path to the source data file.
    pub source_path: PathBuf,
    /// Object ID of the stored data set.
    pub data_id: ObjectId,
    /// Object ID of the schema this data conforms to.
    pub schema_id: ObjectId,
}

/// A schema that has been staged for commit.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct StagedSchema {
    /// Object ID of the staged schema.
    pub schema_id: ObjectId,
    /// Object ID of the migration from HEAD's schema (if HEAD exists).
    pub migration_id: Option<ObjectId>,
    /// Whether the migration was automatically derived.
    pub auto_derived: bool,
    /// Validation status from the staging pipeline.
    pub validation: ValidationStatus,
    /// GAT-level diagnostics from type-checking and equation verification.
    #[serde(default)]
    pub gat_diagnostics: Option<GatDiagnostics>,
}

/// Result of the staging validation pipeline.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum ValidationStatus {
    /// Validation has not been run.
    Pending,
    /// The staged schema and migration are valid.
    Valid,
    /// Validation found errors.
    Invalid(Vec<String>),
}

impl Index {
    /// Returns `true` if something is staged.
    #[must_use]
    pub fn has_staged(&self) -> bool {
        self.staged.is_some() || !self.staged_data.is_empty() || self.staged_protocol.is_some()
    }

    /// Clear the staging area.
    pub fn clear(&mut self) {
        self.staged = None;
        self.staged_data.clear();
        self.staged_protocol = None;
    }
}