Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jhelwig committed Aug 20, 2024
1 parent 2567075 commit 680635b
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 11 deletions.
16 changes: 16 additions & 0 deletions lib/dal/src/layer_db_types/content_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ pub struct FuncArgumentContentV1 {
#[derive(Debug, Clone, EnumDiscriminants, Serialize, Deserialize, PartialEq)]
pub enum InputSocketContent {
V1(InputSocketContentV1),
V2(InputSocketContentV2),
}

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
Expand All @@ -315,6 +316,21 @@ pub struct InputSocketContentV1 {
pub connection_annotations: Vec<ConnectionAnnotation>,
}

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub struct InputSocketContentV2 {
pub timestamp: Timestamp,
/// Name for [`Self`] that can be used for identification.
pub name: String,
/// Definition of the inbound type (e.g. "JSONSchema" or "Number").
pub inbound_type_definition: Option<String>,
/// Definition of the outbound type (e.g. "JSONSchema" or "Number").
pub outbound_type_definition: Option<String>,
pub kind: SocketKind,
pub required: bool,
pub ui_hidden: bool,
pub connection_annotations: Vec<ConnectionAnnotation>,
}

#[derive(Debug, Clone, EnumDiscriminants, Serialize, Deserialize, PartialEq)]
pub enum ModuleContent {
V1(ModuleContentV1),
Expand Down
39 changes: 32 additions & 7 deletions lib/dal/src/socket/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::attribute::prototype::AttributePrototypeError;
use crate::attribute::value::AttributeValueError;
use crate::change_set::ChangeSetError;
use crate::func::FuncError;
use crate::layer_db_types::{InputSocketContent, InputSocketContentV1};
use crate::layer_db_types::{InputSocketContent, InputSocketContentV1, InputSocketContentV2};

use crate::socket::{SocketArity, SocketKind};
use crate::workspace_snapshot::content_address::{ContentAddress, ContentAddressDiscriminants};
Expand Down Expand Up @@ -117,14 +117,14 @@ impl InputSocket {
Self::get_from_node_weight(ctx, &node_weight).await
}

pub fn assemble(id: InputSocketId, inner: InputSocketContentV1) -> Self {
pub fn assemble(id: InputSocketId, arity: SocketArity, inner: InputSocketContentV2) -> Self {
Self {
id,
timestamp: inner.timestamp,
name: inner.name,
inbound_type_definition: inner.inbound_type_definition,
outbound_type_definition: inner.outbound_type_definition,
arity: inner.arity,
arity,
kind: inner.kind,
required: inner.required,
ui_hidden: inner.ui_hidden,
Expand Down Expand Up @@ -159,18 +159,43 @@ impl InputSocket {
ctx: &DalContext,
node_weight: &NodeWeight,
) -> InputSocketResult<Self> {
let input_socket_node_weight = node_weight.get_input_socket_node_weight()?;
let content: InputSocketContent = ctx
.layer_db()
.cas()
.try_read_as(&node_weight.content_hash())
.try_read_as(&input_socket_node_weight.content_hash())
.await?
.ok_or(WorkspaceSnapshotError::MissingContentFromStore(
node_weight.id(),
input_socket_node_weight.id(),
))?;

let InputSocketContent::V1(inner) = content;
let input_socket = match content {
InputSocketContent::V1(v1_inner) => {
let v2_inner = InputSocketContentV2 {
timestamp: v1_inner.timestamp,
name: v1_inner.name,
inbound_type_definition: v1_inner.inbound_type_definition,
outbound_type_definition: v1_inner.outbound_type_definition,
kind: v1_inner.kind,
required: v1_inner.required,
ui_hidden: v1_inner.ui_hidden,
connection_annotations: v1_inner.connection_annotations,
};

Self::assemble(
input_socket_node_weight.id().into(),
v1_inner.arity,
v2_inner,
)
}
InputSocketContent::V2(inner) => Self::assemble(
input_socket_node_weight.id().into(),
input_socket_node_weight.inner().arity(),
inner,
),
};

Ok(Self::assemble(node_weight.id().into(), inner))
Ok(input_socket)
}

implement_add_edge_to!(
Expand Down
30 changes: 29 additions & 1 deletion lib/dal/src/workspace_snapshot/node_weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
content_address::{ContentAddress, ContentAddressDiscriminants},
vector_clock::VectorClockError,
},
ChangeSetId, PropKind,
ChangeSetId, PropKind, SocketArity,
};
use crate::{EdgeWeightKindDiscriminants, WorkspaceSnapshotGraphV2};

Expand Down Expand Up @@ -718,6 +718,34 @@ impl NodeWeight {
encrypted_secret_key,
))
}

pub fn new_input_socket(
input_socket_id: Ulid,
lineage_id: Ulid,
arity: SocketArity,
content_hash: ContentHash,
) -> Self {
NodeWeight::InputSocket(InputSocketNodeWeight::new(
input_socket_id,
lineage_id,
arity,
content_hash,
))
}

pub fn new_schema_variant(
schema_variant_id: Ulid,
lineage_id: Ulid,
is_locked: bool,
content_hash: ContentHash,
) -> Self {
NodeWeight::SchemaVariant(SchemaVariantNodeWeight::new(
schema_variant_id,
lineage_id,
is_locked,
content_hash,
))
}
}

impl From<DeprecatedNodeWeightV1> for NodeWeight {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use serde::{Deserialize, Serialize};
use si_events::{merkle_tree_hash::MerkleTreeHash, ulid::Ulid, ContentHash};

use crate::EdgeWeightKindDiscriminants;
use crate::{ContentAddressDiscriminants, DalContext, EdgeWeightKindDiscriminants, SocketArity};

pub mod v1;

pub use v1::InputSocketNodeWeightV1;

use super::{traits::CorrectTransforms, ContentNodeWeight, NodeWeightError, NodeWeightResult};

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum InputSocketNodeWeight {
V1(InputSocketNodeWeightV1),
Expand Down Expand Up @@ -68,4 +70,46 @@ impl InputSocketNodeWeight {
InputSocketNodeWeight::V1(inner) => inner.exclusive_outgoing_edges(),
}
}

pub fn new(id: Ulid, lineage_id: Ulid, arity: SocketArity, content_hash: ContentHash) -> Self {
Self::V1(InputSocketNodeWeightV1::new(
id,
lineage_id,
arity,
content_hash,
))
}
}

impl CorrectTransforms for InputSocketNodeWeight {
fn correct_transforms(
&self,
workspace_snapshot_graph: &crate::WorkspaceSnapshotGraphV2,
updates: Vec<crate::workspace_snapshot::graph::detect_updates::Update>,
from_different_change_set: bool,
) -> super::traits::CorrectTransformsResult<
Vec<crate::workspace_snapshot::graph::detect_updates::Update>,
> {
self.inner().correct_transforms(
workspace_snapshot_graph,
updates,
from_different_change_set,
)
}
}

impl InputSocketNodeWeight {
fn try_from_content_node_weight(
ctx: &DalContext,
value: ContentNodeWeight,
) -> NodeWeightResult<Self> {
if value.content_address_discriminants() != ContentAddressDiscriminants::InputSocket {
return Err(NodeWeightError::UnexpectedContentAddressVariant(
ContentAddressDiscriminants::InputSocket,
value.content_address_discriminants(),
));
}

todo!()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use serde::{Deserialize, Serialize};
use si_events::{merkle_tree_hash::MerkleTreeHash, ulid::Ulid, ContentHash};

use crate::{
workspace_snapshot::{content_address::ContentAddress, graph::LineageId},
workspace_snapshot::{
content_address::ContentAddress, graph::LineageId, node_weight::traits::CorrectTransforms,
},
EdgeWeightKindDiscriminants, SocketArity, Timestamp,
};

Expand Down Expand Up @@ -60,4 +62,21 @@ impl InputSocketNodeWeightV1 {
pub const fn exclusive_outgoing_edges(&self) -> &[EdgeWeightKindDiscriminants] {
&[]
}

pub fn arity(&self) -> SocketArity {
self.arity
}

pub fn new(id: Ulid, lineage_id: Ulid, arity: SocketArity, content_hash: ContentHash) -> Self {
Self {
id,
lineage_id,
arity,
content_address: ContentAddress::InputSocket(content_hash),
merkle_tree_hash: MerkleTreeHash::default(),
timestamp: Timestamp::now(),
}
}
}

impl CorrectTransforms for InputSocketNodeWeightV1 {}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use si_events::{merkle_tree_hash::MerkleTreeHash, ulid::Ulid, ContentHash};

pub use v1::SchemaVariantNodeWeightV1;

use super::traits::CorrectTransforms;

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum SchemaVariantNodeWeight {
V1(SchemaVariantNodeWeightV1),
Expand Down Expand Up @@ -68,4 +70,30 @@ impl SchemaVariantNodeWeight {
SchemaVariantNodeWeight::V1(inner) => inner.exclusive_outgoing_edges(),
}
}

pub fn new(id: Ulid, lineage_id: Ulid, is_locked: bool, content_hash: ContentHash) -> Self {
Self::V1(SchemaVariantNodeWeightV1::new(
id,
lineage_id,
is_locked,
content_hash,
))
}
}

impl CorrectTransforms for SchemaVariantNodeWeight {
fn correct_transforms(
&self,
workspace_snapshot_graph: &crate::WorkspaceSnapshotGraphV2,
updates: Vec<crate::workspace_snapshot::graph::detect_updates::Update>,
from_different_change_set: bool,
) -> super::traits::CorrectTransformsResult<
Vec<crate::workspace_snapshot::graph::detect_updates::Update>,
> {
self.inner().correct_transforms(
workspace_snapshot_graph,
updates,
from_different_change_set,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use serde::{Deserialize, Serialize};
use si_events::{merkle_tree_hash::MerkleTreeHash, ulid::Ulid, ContentHash};

use crate::{
workspace_snapshot::{content_address::ContentAddress, graph::LineageId},
workspace_snapshot::{
content_address::ContentAddress, graph::LineageId, node_weight::traits::CorrectTransforms,
},
EdgeWeightKindDiscriminants, Timestamp,
};

Expand Down Expand Up @@ -60,4 +62,17 @@ impl SchemaVariantNodeWeightV1 {
pub const fn exclusive_outgoing_edges(&self) -> &[EdgeWeightKindDiscriminants] {
&[]
}

pub fn new(id: Ulid, lineage_id: Ulid, is_locked: bool, content_hash: ContentHash) -> Self {
Self {
id,
lineage_id,
is_locked,
content_address: ContentAddress::SchemaVariant(content_hash),
merkle_tree_hash: MerkleTreeHash::default(),
timestamp: Timestamp::now(),
}
}
}

impl CorrectTransforms for SchemaVariantNodeWeightV1 {}

0 comments on commit 680635b

Please sign in to comment.