Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
68 changes: 68 additions & 0 deletions packages/catlog-wasm/src/diagram.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//! Wasm bindings for diagrams in models of a double theory.

use uuid::Uuid;

use serde::{Deserialize, Serialize};
use tsify_next::Tsify;
use wasm_bindgen::prelude::*;

use super::model::{Mor, Ob};
use super::theory::{MorType, ObType};

/// An object of a diagram in a model of a double theory.
#[derive(Debug, Serialize, Deserialize, Tsify)]
#[tsify(into_wasm_abi, from_wasm_abi)]
pub struct DiagramOb {
/// Indexing object.
pub ob: Ob,

/// Object in the model that the indexing object is over.
pub over: Ob,
}

/// A morphism of a diagram in a model of a double theory.
#[derive(Debug, Serialize, Deserialize, Tsify)]
#[tsify(into_wasm_abi, from_wasm_abi)]
pub struct DiagramMor {
/// Indexing morphism.
pub mor: Mor,

/// Morphism that the indexing morphism is over (mapped to).
pub over: Mor,
}

/// Declares an object of a diagram in a model.
#[derive(Serialize, Deserialize, Tsify)]
#[tsify(into_wasm_abi, from_wasm_abi, missing_as_null)]
pub struct DiagramObDecl {
/// Globally unique identifier of object.
pub id: Uuid,

/// The object's type in the double theory.
#[serde(rename = "obType")]
pub ob_type: ObType,

/// Object in the model that this object is over, if defined.
pub over: Option<Ob>,
}

/// Declares a morphism of a diagram in a model.
#[derive(Serialize, Deserialize, Tsify)]
#[tsify(into_wasm_abi, from_wasm_abi, missing_as_null)]
pub struct DiagramMorDecl {
/// Globally unique identifier of morphism.
pub id: Uuid,

/// The morphism's type in the double theory.
#[serde(rename = "morType")]
pub mor_type: MorType,

/// Morphism in the model that this morphism is over, if defined.
pub over: Option<Mor>,

/// Domain of this morphism, if defined.
pub dom: Option<Ob>,

/// Codomain of this morphism, if defined.
pub cod: Option<Ob>,
}
3 changes: 2 additions & 1 deletion packages/catlog-wasm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
pub mod result;

pub mod analyses;
pub mod diagram;
pub mod model;
pub mod model_morphism;
pub mod theory;

pub mod analyses;
#[allow(clippy::new_without_default)]
pub mod theories;

Expand Down
32 changes: 27 additions & 5 deletions packages/catlog-wasm/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use tsify_next::Tsify;
use wasm_bindgen::prelude::*;

use super::theory::*;
use catlog::dbl::model::{self as dbl_model, InvalidDiscreteDblModel};
use catlog::dbl::model::{self as dbl_model, FgDblModel, InvalidDiscreteDblModel};
use catlog::one::fin_category::UstrFinCategory;
use catlog::one::Path;
use catlog::one::{Category as _, FgCategory};
Expand Down Expand Up @@ -83,26 +83,26 @@ impl TryFrom<Mor> for Path<Uuid, Uuid> {
}
}

/// Declaration of an object in a model of a double theory.
/// Declares an object in a model of a double theory.
#[derive(Serialize, Deserialize, Tsify)]
#[tsify(into_wasm_abi, from_wasm_abi, missing_as_null)]
pub struct ObDecl {
/// Globally unique identifier of object.
pub id: Uuid,

/// Object type in double theory.
/// The object's type in the double theory.
#[serde(rename = "obType")]
pub ob_type: ObType,
}

/// Declaration of a morphism in a model of a double theory.
/// Declares a morphism in a model of a double theory.
#[derive(Serialize, Deserialize, Tsify)]
#[tsify(into_wasm_abi, from_wasm_abi, missing_as_null)]
pub struct MorDecl {
/// Globally unique identifier of morphism.
pub id: Uuid,

/// Morphism type in double theory.
/// The morphism's type in the double theory.
#[serde(rename = "morType")]
pub mor_type: MorType,

Expand Down Expand Up @@ -225,6 +225,28 @@ impl DblModel {
})
}

/// Returns array of basic objects with the given type.
#[wasm_bindgen(js_name = "objectsWithType")]
pub fn objects_with_type(&self, ob_type: ObType) -> Result<Vec<Ob>, String> {
all_the_same!(match &self.0 {
DblModelBox::[Discrete](model) => {
let ob_type = ob_type.try_into()?;
Ok(model.object_generators_with_type(&ob_type).map(Ob::Basic).collect())
}
})
}

/// Returns array of basic morphisms with the given type.
#[wasm_bindgen(js_name = "morphismsWithType")]
pub fn morphisms_with_type(&self, mor_type: MorType) -> Result<Vec<Mor>, String> {
all_the_same!(match &self.0 {
DblModelBox::[Discrete](model) => {
let mor_type = mor_type.try_into()?;
Ok(model.morphism_generators_with_type(&mor_type).map(Mor::Basic).collect())
}
})
}

/// Validates that the model is well defined.
#[wasm_bindgen]
pub fn validate(&self) -> Vec<InvalidDiscreteDblModel<Uuid>> {
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@
"vite-plugin-top-level-await": "^1.4.1",
"vite-plugin-wasm": "^3.3.0",
"vitest": "^2.1.2",
"wasm-pack": "^0.13.0"
"wasm-pack": "^0.13.1"
}
}
10 changes: 5 additions & 5 deletions packages/frontend/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 12 additions & 14 deletions packages/frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import * as uuid from "uuid";
import { MultiProvider } from "@solid-primitives/context";
import { Navigate, type RouteDefinition, type RouteSectionProps, Router } from "@solidjs/router";
import { FirebaseProvider } from "solid-firebase";
import { Match, Switch, createResource, lazy, useContext } from "solid-js";
import { Show, createResource, lazy, useContext } from "solid-js";

import type { JsonValue } from "catcolab-api";
import { RepoContext, RpcContext, createRpcClient } from "./api";
import { newModelDocument } from "./document/types";
import { HelperContainer, lazyMdx } from "./page/help_page";
import { newModelDocument } from "./model/document";
import { HelpContainer, lazyMdx } from "./page/help_page";
import { TheoryLibraryContext, stdTheories } from "./stdlib";

const serverUrl = import.meta.env.VITE_SERVER_URL;
Expand Down Expand Up @@ -62,14 +62,7 @@ function CreateModel() {
return result.content;
});

return (
<Switch>
<Match when={ref.error}>
<span>Error: {ref.error}</span>
</Match>
<Match when={ref()}>{(ref) => <Navigate href={`/model/${ref()}`} />}</Match>
</Switch>
);
return <Show when={ref()}>{(ref) => <Navigate href={`/model/${ref()}`} />}</Show>;
}

const refIsUUIDFilter = {
Expand All @@ -84,16 +77,21 @@ const routes: RouteDefinition[] = [
{
path: "/model/:ref",
matchFilters: refIsUUIDFilter,
component: lazy(() => import("./document/model_document_editor")),
component: lazy(() => import("./model/model_editor")),
},
{
path: "/diagram/:ref",
matchFilters: refIsUUIDFilter,
component: lazy(() => import("./diagram/diagram_editor")),
},
{
path: "/analysis/:ref",
matchFilters: refIsUUIDFilter,
component: lazy(() => import("./document/analysis_document_editor")),
component: lazy(() => import("./analysis/analysis_editor")),
},
{
path: "/help",
component: HelperContainer,
component: HelpContainer,
children: [
{
path: "/",
Expand Down
Loading