//! A package's mine graph: closed and at most one profile hop deep. The word //! itself is read by cotton-rules (`cotton_rules::visibility`), the Worker's //! reading too. use super::{refusal_words, ColumnType, TableDefinition}; pub use cotton_rules::visibility::Visibility; /// A visibility word read, its refusal said in the kit's words. pub fn parse(value: Option<&str>) -> Result { Visibility::parse(value).map_err(refusal_words) } pub fn validate_tables(tables: &[TableDefinition]) -> Result<(), String> { for table in tables { let Visibility::Mine(column) = parse(table.visibility.as_deref())? else { continue; }; if table.id == "person" && column == "id" { continue; } let link = table .column(&column) .filter(|c| c.column_type == ColumnType::Link) .and_then(|c| c.link_to.as_deref()) .ok_or_else(|| refusal_words("mine_must_name_a_link_column"))?; if link == "person" { continue; } let target = tables .iter() .find(|t| t.id == link) .ok_or_else(|| refusal_words("mine_profile_must_belong_to_the_package"))?; let Visibility::Mine(person) = parse(target.visibility.as_deref())? else { return Err(refusal_words("mine_profile_must_itself_be_mine")); }; if !target.column(&person).is_some_and(|c| { c.column_type == ColumnType::Link && c.link_to.as_deref() == Some("person") }) { return Err(refusal_words("mine_follows_at_most_one_profile_link")); } } Ok(()) }