WIP checkpoint schema8 analysis core before user reboot

This commit is contained in:
Codex
2026-09-11 06:46:52 -07:00
parent 7d14bd0dd1
commit b96ff3935a
21 changed files with 3329 additions and 113 deletions
+43 -3
View File
@@ -6,7 +6,7 @@ use std::{
use uuid::Uuid;
pub type Id = Uuid;
pub const SCHEMA_VERSION: u32 = 7;
pub const SCHEMA_VERSION: u32 = 8;
pub const MAX_COORDINATE: f32 = 1_000_000.;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
@@ -64,9 +64,12 @@ pub enum Kind {
Terminate,
Event,
Constraint,
EngineeringProperty,
AnalysisCase,
AnalysisCheck,
}
impl Kind {
pub const ALL: [Self; 39] = [
pub const ALL: [Self; 42] = [
Self::Entity,
Self::Actor,
Self::Role,
@@ -106,6 +109,9 @@ impl Kind {
Self::Terminate,
Self::Event,
Self::Constraint,
Self::EngineeringProperty,
Self::AnalysisCase,
Self::AnalysisCheck,
];
pub fn label(self) -> &'static str {
match self {
@@ -148,6 +154,9 @@ impl Kind {
Self::Terminate => "Terminate",
Self::Event => "Event",
Self::Constraint => "Constraint",
Self::EngineeringProperty => "Engineering property",
Self::AnalysisCase => "Analysis case",
Self::AnalysisCheck => "Analysis check",
}
}
pub fn is_performer(self) -> bool {
@@ -156,6 +165,9 @@ impl Kind {
Self::Entity | Self::Actor | Self::System | Self::SystemActor
)
}
pub fn is_analysis(self) -> bool {
matches!(self, Self::EngineeringProperty | Self::AnalysisCase | Self::AnalysisCheck)
}
pub fn is_work(self) -> bool {
matches!(self, Self::Activity | Self::Function)
}
@@ -652,6 +664,23 @@ pub enum SharedBody {
expression: String,
constrained: Vec<Id>,
},
EngineeringProperty {
subject: crate::analysis::AnalysisSubject,
value_type: crate::analysis::AnalysisType,
display_unit: Option<crate::analysis::DefinitionRef>,
base: crate::analysis::Binding,
},
AnalysisCase {
subject: Option<crate::analysis::AnalysisSubject>,
base: crate::analysis::BaselineBase,
#[serde(deserialize_with = "unique_id_map")]
overrides: BTreeMap<Id, crate::analysis::Binding>,
},
AnalysisCheck {
subject: Option<crate::analysis::AnalysisSubject>,
documented_constraint: Option<Id>,
predicate: crate::analysis::Binding,
},
}
impl Element {
pub fn layer(&self) -> Layer {
@@ -752,7 +781,8 @@ impl ElementBody {
}
}
pub fn new(kind: Kind, layer: Layer) -> Option<Self> {
if !kind.supports(layer) {
// Analysis creation requires explicitly authored types and bindings.
if !kind.supports(layer) || kind.is_analysis() {
return None;
}
Some(match kind {
@@ -864,6 +894,9 @@ impl SharedBody {
Self::Region => Kind::Region,
Self::State { kind, .. } => kind.kind(),
Self::Constraint { .. } => Kind::Constraint,
Self::EngineeringProperty { .. } => Kind::EngineeringProperty,
Self::AnalysisCase { .. } => Kind::AnalysisCase,
Self::AnalysisCheck { .. } => Kind::AnalysisCheck,
}
}
}
@@ -1625,6 +1658,8 @@ pub struct Project {
pub name: String,
pub description: String,
#[serde(deserialize_with = "unique_id_map")]
pub definitions: BTreeMap<Id, crate::analysis::Definition>,
#[serde(deserialize_with = "unique_id_map")]
pub elements: BTreeMap<Id, Element>,
#[serde(deserialize_with = "unique_id_map")]
pub relations: BTreeMap<Id, Relation>,
@@ -1717,6 +1752,7 @@ impl Project {
alias: "mission".into(),
name: "Untitled mission".into(),
description: String::new(),
definitions: BTreeMap::new(),
elements: BTreeMap::new(),
relations: BTreeMap::new(),
diagrams: BTreeMap::new(),
@@ -1726,6 +1762,7 @@ impl Project {
}
pub fn identities(&self) -> Vec<(Id, &str)> {
let mut out = vec![(self.id, self.alias.as_str())];
out.extend(self.definitions.values().map(|v| (v.id, v.alias.as_str())));
out.extend(self.elements.values().map(|v| (v.id, v.alias.as_str())));
out.extend(self.relations.values().map(|v| (v.id, v.alias.as_str())));
out.extend(self.diagrams.values().map(|v| (v.id, v.alias.as_str())));
@@ -1783,6 +1820,9 @@ impl Project {
if id == self.id {
return &self.name;
}
if let Some(v) = self.definitions.get(&id) {
return &v.name;
}
if let Some(v) = self.elements.get(&id) {
return &v.name;
}