diff --git a/lib/dal/src/layer_db_types/content_types.rs b/lib/dal/src/layer_db_types/content_types.rs index 83bc087bb5..92cce39d54 100644 --- a/lib/dal/src/layer_db_types/content_types.rs +++ b/lib/dal/src/layer_db_types/content_types.rs @@ -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)] @@ -315,6 +316,21 @@ pub struct InputSocketContentV1 { pub connection_annotations: Vec, } +#[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, + /// Definition of the outbound type (e.g. "JSONSchema" or "Number"). + pub outbound_type_definition: Option, + pub kind: SocketKind, + pub required: bool, + pub ui_hidden: bool, + pub connection_annotations: Vec, +} + #[derive(Debug, Clone, EnumDiscriminants, Serialize, Deserialize, PartialEq)] pub enum ModuleContent { V1(ModuleContentV1), diff --git a/lib/dal/src/socket/input.rs b/lib/dal/src/socket/input.rs index 53dc342b04..afdb63a631 100644 --- a/lib/dal/src/socket/input.rs +++ b/lib/dal/src/socket/input.rs @@ -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}; @@ -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, @@ -159,18 +159,43 @@ impl InputSocket { ctx: &DalContext, node_weight: &NodeWeight, ) -> InputSocketResult { + 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!( diff --git a/lib/dal/src/workspace_snapshot/node_weight.rs b/lib/dal/src/workspace_snapshot/node_weight.rs index c71b99555d..83e5bf208e 100644 --- a/lib/dal/src/workspace_snapshot/node_weight.rs +++ b/lib/dal/src/workspace_snapshot/node_weight.rs @@ -12,7 +12,7 @@ use crate::{ content_address::{ContentAddress, ContentAddressDiscriminants}, vector_clock::VectorClockError, }, - ChangeSetId, PropKind, + ChangeSetId, PropKind, SocketArity, }; use crate::{EdgeWeightKindDiscriminants, WorkspaceSnapshotGraphV2}; @@ -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 for NodeWeight { diff --git a/lib/dal/src/workspace_snapshot/node_weight/input_socket_node_weight.rs b/lib/dal/src/workspace_snapshot/node_weight/input_socket_node_weight.rs index f1d617e303..53ec579a26 100644 --- a/lib/dal/src/workspace_snapshot/node_weight/input_socket_node_weight.rs +++ b/lib/dal/src/workspace_snapshot/node_weight/input_socket_node_weight.rs @@ -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), @@ -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, + from_different_change_set: bool, + ) -> super::traits::CorrectTransformsResult< + Vec, + > { + 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 { + if value.content_address_discriminants() != ContentAddressDiscriminants::InputSocket { + return Err(NodeWeightError::UnexpectedContentAddressVariant( + ContentAddressDiscriminants::InputSocket, + value.content_address_discriminants(), + )); + } + + todo!() + } } diff --git a/lib/dal/src/workspace_snapshot/node_weight/input_socket_node_weight/v1.rs b/lib/dal/src/workspace_snapshot/node_weight/input_socket_node_weight/v1.rs index ed2886a2e0..0af347190e 100644 --- a/lib/dal/src/workspace_snapshot/node_weight/input_socket_node_weight/v1.rs +++ b/lib/dal/src/workspace_snapshot/node_weight/input_socket_node_weight/v1.rs @@ -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, }; @@ -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 {} diff --git a/lib/dal/src/workspace_snapshot/node_weight/schema_variant_node_weight.rs b/lib/dal/src/workspace_snapshot/node_weight/schema_variant_node_weight.rs index cfa5ed2856..beea80127f 100644 --- a/lib/dal/src/workspace_snapshot/node_weight/schema_variant_node_weight.rs +++ b/lib/dal/src/workspace_snapshot/node_weight/schema_variant_node_weight.rs @@ -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), @@ -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, + from_different_change_set: bool, + ) -> super::traits::CorrectTransformsResult< + Vec, + > { + self.inner().correct_transforms( + workspace_snapshot_graph, + updates, + from_different_change_set, + ) + } } diff --git a/lib/dal/src/workspace_snapshot/node_weight/schema_variant_node_weight/v1.rs b/lib/dal/src/workspace_snapshot/node_weight/schema_variant_node_weight/v1.rs index 20b6cf65e3..86dafedcb8 100644 --- a/lib/dal/src/workspace_snapshot/node_weight/schema_variant_node_weight/v1.rs +++ b/lib/dal/src/workspace_snapshot/node_weight/schema_variant_node_weight/v1.rs @@ -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, }; @@ -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 {}