#![allow(
missing_docs,
clippy::doc_markdown,
clippy::struct_excessive_bools,
clippy::derive_partial_eq_without_eq,
clippy::large_enum_variant
)]
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PanprotoRefUpdate {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub breaking_changes: Option<Vec<BreakingChange>>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub commit_count: Option<i64>,
pub committer_did: idiolect_records::Did,
pub created_at: idiolect_records::Datetime,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub lens_hash: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub lens_quality: Option<f64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub migration_hash: Option<String>,
pub new_target: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub old_target: Option<String>,
pub protocol: String,
pub r#ref: String,
pub repo: idiolect_records::AtUri,
}
impl crate::Record for PanprotoRefUpdate {
const NSID: &'static str = "dev.panproto.vcs.refUpdate";
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BreakingChange {
pub description: String,
pub element: String,
pub kind: BreakingChangeKind,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum BreakingChangeKind {
VertexRemoved,
EdgeRemoved,
ConstraintTightened,
RequiredFieldAdded,
TypeChanged,
ArityChanged,
VariantRemoved,
SemanticChange,
Other(String),
}
impl BreakingChangeKind {
#[must_use]
pub fn as_str(&self) -> &str {
match self {
Self::VertexRemoved => "vertexRemoved",
Self::EdgeRemoved => "edgeRemoved",
Self::ConstraintTightened => "constraintTightened",
Self::RequiredFieldAdded => "requiredFieldAdded",
Self::TypeChanged => "typeChanged",
Self::ArityChanged => "arityChanged",
Self::VariantRemoved => "variantRemoved",
Self::SemanticChange => "semanticChange",
Self::Other(s) => s.as_str(),
}
}
#[must_use]
pub fn is_subsumed_by(
&self,
vocab: &idiolect_records::vocab::VocabGraph,
ancestor: &str,
) -> bool {
vocab.is_subsumed_by(self.as_str(), ancestor)
}
#[must_use]
pub fn satisfies(
&self,
vocab: &idiolect_records::vocab::VocabGraph,
relation: &str,
target: &str,
) -> bool {
if self.as_str() == target {
return true;
}
vocab
.walk_relation(self.as_str(), relation, false)
.iter()
.any(|n| n == target)
}
#[must_use]
pub fn translate_to<T: From<String>>(
&self,
src_vocab_uri: &str,
tgt_vocab_uri: &str,
registry: &idiolect_records::vocab::VocabRegistry,
) -> Option<T> {
registry
.translate(src_vocab_uri, tgt_vocab_uri, self.as_str())
.map(T::from)
}
}
impl From<String> for BreakingChangeKind {
fn from(s: String) -> Self {
match s.as_str() {
"vertexRemoved" => Self::VertexRemoved,
"edgeRemoved" => Self::EdgeRemoved,
"constraintTightened" => Self::ConstraintTightened,
"requiredFieldAdded" => Self::RequiredFieldAdded,
"typeChanged" => Self::TypeChanged,
"arityChanged" => Self::ArityChanged,
"variantRemoved" => Self::VariantRemoved,
"semanticChange" => Self::SemanticChange,
_ => Self::Other(s),
}
}
}
impl From<&str> for BreakingChangeKind {
fn from(s: &str) -> Self {
match s {
"vertexRemoved" => Self::VertexRemoved,
"edgeRemoved" => Self::EdgeRemoved,
"constraintTightened" => Self::ConstraintTightened,
"requiredFieldAdded" => Self::RequiredFieldAdded,
"typeChanged" => Self::TypeChanged,
"arityChanged" => Self::ArityChanged,
"variantRemoved" => Self::VariantRemoved,
"semanticChange" => Self::SemanticChange,
_ => Self::Other(s.to_owned()),
}
}
}
impl serde::Serialize for BreakingChangeKind {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de> serde::Deserialize<'de> for BreakingChangeKind {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
Ok(Self::from(s))
}
}