Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/backend/src/user_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,8 @@ pub mod arbitrary {
DocumentType::Model,
DocumentType::Diagram,
DocumentType::Analysis,
// TODO: Re-enable once DocumentType::PetriNet is restored in document-types.
// DocumentType::PetriNet,
])
.boxed()
}
Expand Down
4 changes: 2 additions & 2 deletions packages/document-types/src/v0/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use tsify::Tsify;
/// `id`, to avoid conflicts with other keys and unambiguously signal that the
/// data occur at the *database* level, rather than merely the *document* level.
/// The same convention is used in document databases like CouchDB and MongoDB.
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Tsify)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Tsify)]
#[tsify(into_wasm_abi, from_wasm_abi)]
#[tsify(missing_as_null)]
pub struct StableRef {
Expand Down Expand Up @@ -38,7 +38,7 @@ pub struct StableRef {
///
/// The source of the link is the document containing this data and the target
/// of link is given by the data itself.
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Tsify)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Tsify)]
#[tsify(into_wasm_abi, from_wasm_abi)]
pub struct Link {
#[serde(flatten)]
Expand Down
8 changes: 8 additions & 0 deletions packages/document-types/src/v0/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ pub enum DocumentType {
Diagram,
#[cfg_attr(feature = "backend", autosurgeon(rename = "analysis"))]
Analysis,
// TODO: Re-enable this only after the frontend supports Petri net documents
// throughout its document routing, menus ... other exhaustive checks over
// document types.

// #[cfg_attr(feature = "backend", autosurgeon(rename = "petrinet"))]
// PetriNet,
}

impl FromStr for DocumentType {
Expand All @@ -74,6 +80,8 @@ impl FromStr for DocumentType {
"model" => Ok(DocumentType::Model),
"diagram" => Ok(DocumentType::Diagram),
"analysis" => Ok(DocumentType::Analysis),
// TODO: Re-enable with the PetriNet DocumentType variant above.
// "petrinet" => Ok(DocumentType::PetriNet),
other => Err(format!("unknown document type: {other}")),
}
}
Expand Down
24 changes: 18 additions & 6 deletions packages/document-types/src/v0/model_judgment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::model::{Mor, Ob};
use super::theory::{MorType, ObType};

/// Declares an object in a model of a double theory.
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Tsify)]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Tsify)]
#[tsify(into_wasm_abi, from_wasm_abi, missing_as_null)]
pub struct ObDecl {
/// Human-readable label for object.
Expand All @@ -22,7 +22,7 @@ pub struct ObDecl {
}

/// Declares a morphism in a model of a double theory.
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Tsify)]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Tsify)]
#[tsify(into_wasm_abi, from_wasm_abi, missing_as_null)]
pub struct MorDecl {
/// Human-readable label for morphism.
Expand All @@ -43,7 +43,7 @@ pub struct MorDecl {
}

/// Instantiates an existing model into the current model.
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Tsify)]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Tsify)]
#[tsify(into_wasm_abi, from_wasm_abi, missing_as_null)]
pub struct InstantiatedModel {
/// Human-readable label for the instantiation.
Expand All @@ -60,7 +60,7 @@ pub struct InstantiatedModel {
}

/// A specialization of a generating object in an instantiated model.
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Tsify)]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Tsify)]
#[tsify(into_wasm_abi, from_wasm_abi, missing_as_null)]
pub struct SpecializeModel {
/// ID (qualified name) of generating object to specialize.
Expand All @@ -71,7 +71,7 @@ pub struct SpecializeModel {
}

/// Declares an equation in a model of a double theory.
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Tsify)]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Tsify)]
#[tsify(into_wasm_abi, from_wasm_abi, missing_as_null)]
pub struct EqnDecl {
/// Human-readable label for equation.
Expand All @@ -88,7 +88,7 @@ pub struct EqnDecl {
}

/// A judgment defining part of a model of a double theory.
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Tsify)]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Tsify)]
#[serde(tag = "tag")]
#[tsify(into_wasm_abi, from_wasm_abi)]
pub enum ModelJudgment {
Expand All @@ -109,6 +109,18 @@ pub enum ModelJudgment {
Instantiation(InstantiatedModel),
}

impl ModelJudgment {
/// UUIDs are unique among all components, so we may extract them uniformly.
pub fn id(&self) -> Uuid {
match self {
ModelJudgment::Object(d) => d.id,
ModelJudgment::Morphism(d) => d.id,
ModelJudgment::Equation(d) => d.id,
ModelJudgment::Instantiation(d) => d.id,
}
}
}

/// Arbitrary instances for property-based testing.
#[cfg(feature = "property-tests")]
pub(crate) mod arbitrary {
Expand Down
8 changes: 7 additions & 1 deletion packages/document-types/src/v2/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub struct AnalysisDocumentContent {
pub version: String,
}

#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Tsify)]
#[derive(PartialEq, Debug, Serialize, Deserialize, Tsify)]
#[serde(tag = "type")]
#[tsify(into_wasm_abi, from_wasm_abi)]
pub enum Document {
Expand All @@ -58,6 +58,12 @@ pub enum Document {
Diagram(DiagramDocumentContent),
#[serde(rename = "analysis")]
Analysis(AnalysisDocumentContent),
// TODO: Re-enable this only after the frontend supports Petri net documents
// throughout its document routing, menus ... other exhaustive checks over
// document types.

// #[serde(rename = "petrinet")]
// PetriNet(PetriNetDocumentContent),
}

impl Document {
Expand Down
8 changes: 8 additions & 0 deletions packages/document-types/src/v2/lens/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pub mod notebook;
pub mod petrinet;
pub mod types;

#[cfg(test)]
mod petri_test;

pub use types::*;
35 changes: 35 additions & 0 deletions packages/document-types/src/v2/lens/notebook.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use crate::v0::model_judgment::ModelJudgment;
use crate::v2::cell::NotebookCell;
use crate::v2::lens::{
FormalContent, FormalContentChange, FormalContentDelta, FormalContentDeltaLens,
};
use crate::v2::notebook::Notebook;

impl FormalContentDeltaLens for Notebook<ModelJudgment> {
fn to_formal_content(&self) -> FormalContent {
// We perform no filtering here, as this is intended to be a generic
// delta lens implementation.
self.formal_content().cloned().collect()
}

fn apply_delta(&mut self, delta: &FormalContentDelta) {
// Notebook<ModelJudgement> is very close to FormalContent already,
// there's little to do.
for change in delta {
match change {
FormalContentChange::Upsert(jgmt) => {
let id = jgmt.id();
let cell = NotebookCell::Formal { id, content: jgmt.clone() };
if !self.cell_contents.contains_key(&id) {
self.cell_order.push(id);
}
self.cell_contents.insert(id, cell);
}
FormalContentChange::Remove(id) => {
self.cell_contents.remove(id);
self.cell_order.retain(|i| i != id);
}
}
}
}
}
Loading
Loading