diff --git a/apps/hash-graph/Cargo.lock b/apps/hash-graph/Cargo.lock index 17d186a2af8..b0acfde56af 100644 --- a/apps/hash-graph/Cargo.lock +++ b/apps/hash-graph/Cargo.lock @@ -2701,7 +2701,7 @@ dependencies = [ [[package]] name = "type-system" version = "0.0.0" -source = "git+https://github.com/blockprotocol/blockprotocol?rev=646b7d1#646b7d1c6cc35197ac76872d6c34e8e4185f2f0c" +source = "git+https://github.com/blockprotocol/blockprotocol?rev=adab205#adab205d4724c992b0f4b8efbf21f8942050479b" dependencies = [ "console_error_panic_hook", "regex", diff --git a/apps/hash-graph/bench/Cargo.toml b/apps/hash-graph/bench/Cargo.toml index 6bba0605326..efdcc490033 100644 --- a/apps/hash-graph/bench/Cargo.toml +++ b/apps/hash-graph/bench/Cargo.toml @@ -21,7 +21,7 @@ serde = { version = "1.0.152", features = ["derive"] } serde_json = "1.0.91" tokio = { version = "1.25.0", features = ["rt-multi-thread", "macros"] } tokio-postgres = { version = "0.7.7", default-features = false } -type-system = { git = "https://github.com/blockprotocol/blockprotocol", rev = "646b7d1" } +type-system = { git = "https://github.com/blockprotocol/blockprotocol", rev = "adab205" } uuid = { version = "1.3.0", features = ["v4", "serde"] } [[bench]] diff --git a/apps/hash-graph/bench/read_scaling/knowledge/complete/entity.rs b/apps/hash-graph/bench/read_scaling/knowledge/complete/entity.rs index 251a9f63484..bd56c59fd4b 100644 --- a/apps/hash-graph/bench/read_scaling/knowledge/complete/entity.rs +++ b/apps/hash-graph/bench/read_scaling/knowledge/complete/entity.rs @@ -10,7 +10,7 @@ use graph::{ UnresolvedTimeProjection, }, }, - knowledge::{EntityMetadata, EntityProperties, LinkData}, + knowledge::{EntityLinkOrder, EntityMetadata, EntityProperties, LinkData}, provenance::{OwnedById, UpdatedById}, store::{query::Filter, AccountStore, EntityStore}, subgraph::{ @@ -105,12 +105,14 @@ async fn seed_db( owned_by_id, None, properties.clone(), - Some(LinkData::new( - entity_a_metadata.record_id().entity_id(), - entity_b_metadata.record_id().entity_id(), - None, - None, - )), + Some(LinkData { + left_entity_id: entity_a_metadata.record_id().entity_id, + right_entity_id: entity_b_metadata.record_id().entity_id, + order: EntityLinkOrder { + left_to_right: None, + right_to_left: None, + }, + }), None, ) }) @@ -161,7 +163,7 @@ pub fn bench_get_entity_by_id( |entity_record_id| async move { store .get_entity(&StructuralQuery { - filter: Filter::for_entity_by_entity_id(entity_record_id.entity_id()), + filter: Filter::for_entity_by_entity_id(entity_record_id.entity_id), graph_resolve_depths, time_projection: UnresolvedTimeProjection::DecisionTime(UnresolvedProjection { pinned: UnresolvedKernel::new(None), diff --git a/apps/hash-graph/bench/read_scaling/knowledge/linkless/entity.rs b/apps/hash-graph/bench/read_scaling/knowledge/linkless/entity.rs index 0346822c825..86ad860e99a 100644 --- a/apps/hash-graph/bench/read_scaling/knowledge/linkless/entity.rs +++ b/apps/hash-graph/bench/read_scaling/knowledge/linkless/entity.rs @@ -115,7 +115,7 @@ pub fn bench_get_entity_by_id( |entity_record_id| async move { store .get_entity(&StructuralQuery { - filter: Filter::for_entity_by_entity_id(entity_record_id.entity_id()), + filter: Filter::for_entity_by_entity_id(entity_record_id.entity_id), graph_resolve_depths: GraphResolveDepths::default(), time_projection: UnresolvedTimeProjection::DecisionTime(UnresolvedProjection { pinned: UnresolvedKernel::new(None), diff --git a/apps/hash-graph/bench/representative_read/seed.rs b/apps/hash-graph/bench/representative_read/seed.rs index 0bdf5308e5c..d8bc4060de4 100644 --- a/apps/hash-graph/bench/representative_read/seed.rs +++ b/apps/hash-graph/bench/representative_read/seed.rs @@ -6,7 +6,7 @@ use std::{ use graph::{ identifier::account::AccountId, - knowledge::{EntityProperties, EntityUuid, LinkData}, + knowledge::{EntityLinkOrder, EntityProperties, EntityUuid, LinkData}, provenance::{OwnedById, UpdatedById}, store::{AccountStore, AsClient, EntityStore}, }; @@ -180,12 +180,14 @@ async fn seed_db(account_id: AccountId, store_wrapper: &mut StoreWrapper) { OwnedById::new(account_id), None, EntityProperties::empty(), - Some(LinkData::new( - left_entity_metadata.record_id().entity_id(), - right_entity_metadata.record_id().entity_id(), - None, - None, - )), + Some(LinkData { + left_entity_id: left_entity_metadata.record_id().entity_id, + right_entity_id: right_entity_metadata.record_id().entity_id, + order: EntityLinkOrder { + left_to_right: None, + right_to_left: None, + }, + }), None, ) }), @@ -267,8 +269,8 @@ async fn get_samples(account_id: AccountId, store_wrapper: &mut StoreWrapper) -> LIMIT 50 "#, &[ - &entity_type_id.base_uri().as_str(), - &i64::from(entity_type_id.version()), + &entity_type_id.base_uri.as_str(), + &i64::from(entity_type_id.version), ], ) .await diff --git a/apps/hash-graph/bench/util.rs b/apps/hash-graph/bench/util.rs index 9f9a283783a..e0b9aa8c2e7 100644 --- a/apps/hash-graph/bench/util.rs +++ b/apps/hash-graph/bench/util.rs @@ -201,7 +201,7 @@ pub async fn seed( .create_data_type( data_type.clone(), &OntologyElementMetadata::Owned(OwnedOntologyElementMetadata::new( - data_type.id().into(), + data_type.id().clone().into(), ProvenanceMetadata::new(UpdatedById::new(account_id)), OwnedById::new(account_id), )), @@ -232,7 +232,7 @@ pub async fn seed( .create_property_type( property_type.clone(), &OntologyElementMetadata::Owned(OwnedOntologyElementMetadata::new( - property_type.id().into(), + property_type.id().clone().into(), ProvenanceMetadata::new(UpdatedById::new(account_id)), OwnedById::new(account_id), )), @@ -263,7 +263,7 @@ pub async fn seed( .create_entity_type( entity_type.clone(), &OntologyElementMetadata::Owned(OwnedOntologyElementMetadata::new( - entity_type.id().into(), + entity_type.id().clone().into(), ProvenanceMetadata::new(UpdatedById::new(account_id)), OwnedById::new(account_id), )), diff --git a/apps/hash-graph/bin/cli/Cargo.toml b/apps/hash-graph/bin/cli/Cargo.toml index 29942a31bc3..85d4b5b2d40 100644 --- a/apps/hash-graph/bin/cli/Cargo.toml +++ b/apps/hash-graph/bin/cli/Cargo.toml @@ -24,7 +24,7 @@ tokio = { version = "1.25.0", features = ["rt-multi-thread", "macros"] } tokio-postgres = { version = "0.7.7", default-features = false } tokio-serde = { version = "0.8", features = ["messagepack"], optional = true } tracing = "0.1.37" -type-system = { git = "https://github.com/blockprotocol/blockprotocol", rev = "646b7d1" } +type-system = { git = "https://github.com/blockprotocol/blockprotocol", rev = "adab205" } uuid = "1.3.0" # Remove again when the type fetcher is used in the graph diff --git a/apps/hash-graph/bin/cli/src/subcommand/server.rs b/apps/hash-graph/bin/cli/src/subcommand/server.rs index ff24a1df95e..6f6d009f7bd 100644 --- a/apps/hash-graph/bin/cli/src/subcommand/server.rs +++ b/apps/hash-graph/bin/cli/src/subcommand/server.rs @@ -98,13 +98,13 @@ async fn stop_gap_setup(pool: &PostgresStorePool) -> Result<(), GraphErro // TODO: how do we make these URIs compliant let text = DataType::new( - VersionedUri::new( - BaseUri::new( + VersionedUri { + base_uri: BaseUri::new( "https://blockprotocol.org/@blockprotocol/types/data-type/text/".to_owned(), ) .expect("failed to construct base URI"), - 1, - ), + version: 1, + }, "Text".to_owned(), Some("An ordered sequence of characters".to_owned()), "string".to_owned(), @@ -112,13 +112,13 @@ async fn stop_gap_setup(pool: &PostgresStorePool) -> Result<(), GraphErro ); let number = DataType::new( - VersionedUri::new( - BaseUri::new( + VersionedUri { + base_uri: BaseUri::new( "https://blockprotocol.org/@blockprotocol/types/data-type/number/".to_owned(), ) .expect("failed to construct base URI"), - 1, - ), + version: 1, + }, "Number".to_owned(), Some("An arithmetical value (in the Real number system)".to_owned()), "number".to_owned(), @@ -126,13 +126,13 @@ async fn stop_gap_setup(pool: &PostgresStorePool) -> Result<(), GraphErro ); let boolean = DataType::new( - VersionedUri::new( - BaseUri::new( + VersionedUri { + base_uri: BaseUri::new( "https://blockprotocol.org/@blockprotocol/types/data-type/boolean/".to_owned(), ) .expect("failed to construct base URI"), - 1, - ), + version: 1, + }, "Boolean".to_owned(), Some("A True or False value".to_owned()), "boolean".to_owned(), @@ -140,13 +140,13 @@ async fn stop_gap_setup(pool: &PostgresStorePool) -> Result<(), GraphErro ); let null = DataType::new( - VersionedUri::new( - BaseUri::new( + VersionedUri { + base_uri: BaseUri::new( "https://blockprotocol.org/@blockprotocol/types/data-type/null/".to_owned(), ) .expect("failed to construct base URI"), - 1, - ), + version: 1, + }, "Null".to_owned(), Some("A placeholder value representing 'nothing'".to_owned()), "null".to_owned(), @@ -154,13 +154,13 @@ async fn stop_gap_setup(pool: &PostgresStorePool) -> Result<(), GraphErro ); let object = DataType::new( - VersionedUri::new( - BaseUri::new( + VersionedUri { + base_uri: BaseUri::new( "https://blockprotocol.org/@blockprotocol/types/data-type/object/".to_owned(), ) .expect("failed to construct base URI"), - 1, - ), + version: 1, + }, "Object".to_owned(), Some("A plain JSON object with no pre-defined structure".to_owned()), "object".to_owned(), @@ -168,13 +168,13 @@ async fn stop_gap_setup(pool: &PostgresStorePool) -> Result<(), GraphErro ); let empty_list = DataType::new( - VersionedUri::new( - BaseUri::new( + VersionedUri { + base_uri: BaseUri::new( "https://blockprotocol.org/@blockprotocol/types/data-type/empty-list/".to_owned(), ) .expect("failed to construct base URI"), - 1, - ), + version: 1, + }, "Empty List".to_owned(), Some("An Empty List".to_owned()), "array".to_owned(), @@ -212,7 +212,7 @@ async fn stop_gap_setup(pool: &PostgresStorePool) -> Result<(), GraphErro let data_type_metadata = OntologyElementMetadata::External(ExternalOntologyElementMetadata::new( - data_type.id().into(), + data_type.id().clone().into(), ProvenanceMetadata::new(UpdatedById::new(root_account_id)), OffsetDateTime::now_utc(), )); @@ -232,13 +232,13 @@ async fn stop_gap_setup(pool: &PostgresStorePool) -> Result<(), GraphErro } } let link_entity_type = EntityType::new( - VersionedUri::new( - BaseUri::new( + VersionedUri { + base_uri: BaseUri::new( "https://blockprotocol.org/@blockprotocol/types/entity-type/link/".to_owned(), ) .expect("failed to construct base URI"), - 1, - ), + version: 1, + }, "Link".to_owned(), Some("A link".to_owned()), Object::new(HashMap::default(), Vec::default()).expect("invalid property object"), @@ -250,7 +250,7 @@ async fn stop_gap_setup(pool: &PostgresStorePool) -> Result<(), GraphErro let link_entity_type_metadata = OntologyElementMetadata::External(ExternalOntologyElementMetadata::new( - link_entity_type.id().into(), + link_entity_type.id().clone().into(), ProvenanceMetadata::new(UpdatedById::new(root_account_id)), OffsetDateTime::now_utc(), )); diff --git a/apps/hash-graph/lib/graph/Cargo.toml b/apps/hash-graph/lib/graph/Cargo.toml index 5fdc04c379d..d30ce42a9f6 100644 --- a/apps/hash-graph/lib/graph/Cargo.toml +++ b/apps/hash-graph/lib/graph/Cargo.toml @@ -34,7 +34,7 @@ tonic = "0.8.3" opentelemetry = { version = "0.18.0", features = ["rt-tokio"] } opentelemetry-otlp = "0.11.0" tracing-subscriber = { version = "0.3.16", features = ["env-filter", "json"] } -type-system = { git = "https://github.com/blockprotocol/blockprotocol", rev = "646b7d1" } +type-system = { git = "https://github.com/blockprotocol/blockprotocol", rev = "adab205" } uuid = { version = "1.3.0", features = ["v4", "serde"] } utoipa = { version = "3.0.1", features = ["uuid"] } include_dir = "0.7.3" diff --git a/apps/hash-graph/lib/graph/src/api/rest.rs b/apps/hash-graph/lib/graph/src/api/rest.rs index 3be49c9b03a..06456a5e0e6 100644 --- a/apps/hash-graph/lib/graph/src/api/rest.rs +++ b/apps/hash-graph/lib/graph/src/api/rest.rs @@ -54,7 +54,7 @@ use crate::{ UnresolvedTransactionTimeImage, UnresolvedTransactionTimeKernel, UnresolvedTransactionTimeProjection, }, - EntityVertexId, GraphElementId, GraphElementVertexId, OntologyTypeVertexId, + EntityVertexId, GraphElementVertexId, OntologyTypeVertexId, }, ontology::{ domain_validator::DomainValidator, ExternalOntologyElementMetadata, @@ -186,7 +186,6 @@ async fn serve_static_schema(Path(path): Path) -> Result( })?; let metadata = OntologyElementMetadata::Owned(OwnedOntologyElementMetadata::new( - data_type.id().into(), + data_type.id().clone().into(), ProvenanceMetadata::new(actor_id), owned_by_id, )); @@ -204,16 +204,13 @@ async fn update_data_type( ) -> Result, StatusCode> { let Json(UpdateDataTypeRequest { schema, - type_to_update, + mut type_to_update, actor_id, }) = body; - let new_type_id = VersionedUri::new( - type_to_update.base_uri().clone(), - type_to_update.version() + 1, - ); + type_to_update.version += 1; - let data_type = patch_id_and_parse(&new_type_id, schema).map_err(|report| { + let data_type = patch_id_and_parse(&type_to_update, schema).map_err(|report| { tracing::error!(error=?report, "Couldn't patch schema and convert to Data Type"); StatusCode::UNPROCESSABLE_ENTITY // TODO - We should probably return more information to the client diff --git a/apps/hash-graph/lib/graph/src/api/rest/entity_type.rs b/apps/hash-graph/lib/graph/src/api/rest/entity_type.rs index f34d1b18f0a..e5c80ce522b 100644 --- a/apps/hash-graph/lib/graph/src/api/rest/entity_type.rs +++ b/apps/hash-graph/lib/graph/src/api/rest/entity_type.rs @@ -119,7 +119,7 @@ async fn create_entity_type( })?; let metadata = OntologyElementMetadata::Owned(OwnedOntologyElementMetadata::new( - entity_type.id().into(), + entity_type.id().clone().into(), ProvenanceMetadata::new(actor_id), owned_by_id, )); @@ -213,16 +213,13 @@ async fn update_entity_type( ) -> Result, StatusCode> { let Json(UpdateEntityTypeRequest { schema, - type_to_update, + mut type_to_update, actor_id, }) = body; - let new_type_id = VersionedUri::new( - type_to_update.base_uri().clone(), - type_to_update.version() + 1, - ); + type_to_update.version += 1; - let entity_type = patch_id_and_parse(&new_type_id, schema).map_err(|report| { + let entity_type = patch_id_and_parse(&type_to_update, schema).map_err(|report| { tracing::error!(error=?report, "Couldn't convert schema to Entity Type"); // Shame there isn't an UNPROCESSABLE_ENTITY_TYPE code :D StatusCode::UNPROCESSABLE_ENTITY diff --git a/apps/hash-graph/lib/graph/src/api/rest/property_type.rs b/apps/hash-graph/lib/graph/src/api/rest/property_type.rs index c4d2f706c34..1507bffb8e7 100644 --- a/apps/hash-graph/lib/graph/src/api/rest/property_type.rs +++ b/apps/hash-graph/lib/graph/src/api/rest/property_type.rs @@ -116,7 +116,7 @@ async fn create_property_type( })?; let metadata = OntologyElementMetadata::Owned(OwnedOntologyElementMetadata::new( - property_type.id().into(), + property_type.id().clone().into(), ProvenanceMetadata::new(actor_id), owned_by_id, )); @@ -211,16 +211,13 @@ async fn update_property_type( ) -> Result, StatusCode> { let Json(UpdatePropertyTypeRequest { schema, - type_to_update, + mut type_to_update, actor_id, }) = body; - let new_type_id = VersionedUri::new( - type_to_update.base_uri().clone(), - type_to_update.version() + 1, - ); + type_to_update.version += 1; - let property_type = patch_id_and_parse(&new_type_id, schema).map_err(|report| { + let property_type = patch_id_and_parse(&type_to_update, schema).map_err(|report| { tracing::error!(error=?report, "Couldn't patch schema and convert to Property Type"); StatusCode::UNPROCESSABLE_ENTITY // TODO - We should probably return more information to the client diff --git a/apps/hash-graph/lib/graph/src/api/rest/utoipa_typedef/subgraph/edges.rs b/apps/hash-graph/lib/graph/src/api/rest/utoipa_typedef/subgraph/edges.rs index ca8e11dc946..046333f7e69 100644 --- a/apps/hash-graph/lib/graph/src/api/rest/utoipa_typedef/subgraph/edges.rs +++ b/apps/hash-graph/lib/graph/src/api/rest/utoipa_typedef/subgraph/edges.rs @@ -72,12 +72,12 @@ impl Edges { HashMap::new(), |mut map, (id, edges)| { let edges = edges.into_iter().collect(); - match map.entry(id.base_id().clone()) { + match map.entry(id.base_id.clone()) { Entry::Occupied(entry) => { - entry.into_mut().insert(id.version(), edges); + entry.into_mut().insert(id.version, edges); } Entry::Vacant(entry) => { - entry.insert(BTreeMap::from([(id.version(), edges)])); + entry.insert(BTreeMap::from([(id.version, edges)])); } } map @@ -117,11 +117,11 @@ impl Edges { let earliest_timestamp = if edge.reversed { vertices.earliest_entity_by_id(&edge.right_endpoint) } else { - vertices.earliest_entity_by_id(&id.base_id()) + vertices.earliest_entity_by_id(&id.base_id) } .expect("entity must exist in subgraph") .vertex_id(time_axis) - .version(); + .version; KnowledgeGraphOutwardEdges::ToKnowledgeGraph(OutwardEdge { kind: edge.kind, @@ -134,16 +134,16 @@ impl Edges { } } }).collect(); - match map.entry(id.base_id()) { + match map.entry(id.base_id) { Entry::Occupied(entry) => { entry.into_mut().insert( - id.version(), + id.version, edges, ); } Entry::Vacant(entry) => { entry.insert(BTreeMap::from([( - id.version(), + id.version, edges, )])); } diff --git a/apps/hash-graph/lib/graph/src/api/rest/utoipa_typedef/subgraph/vertices.rs b/apps/hash-graph/lib/graph/src/api/rest/utoipa_typedef/subgraph/vertices.rs index 36ea83bb9bb..64c36f69736 100644 --- a/apps/hash-graph/lib/graph/src/api/rest/utoipa_typedef/subgraph/vertices.rs +++ b/apps/hash-graph/lib/graph/src/api/rest/utoipa_typedef/subgraph/vertices.rs @@ -66,12 +66,12 @@ impl From for Vertices { ontology: OntologyVertices(data_types.chain(property_types).chain(entity_types).fold( HashMap::new(), |mut map, (id, vertex)| { - match map.entry(id.base_id().clone()) { + match map.entry(id.base_id.clone()) { Entry::Occupied(entry) => { - entry.into_mut().insert(id.version(), vertex); + entry.into_mut().insert(id.version, vertex); } Entry::Vacant(entry) => { - entry.insert(BTreeMap::from([(id.version(), vertex)])); + entry.insert(BTreeMap::from([(id.version, vertex)])); } } map @@ -80,15 +80,15 @@ impl From for Vertices { knowledge_graph: KnowledgeGraphVertices(vertices.entities.into_iter().fold( HashMap::new(), |mut map, (id, vertex)| { - match map.entry(id.base_id()) { + match map.entry(id.base_id) { Entry::Occupied(entry) => { entry .into_mut() - .insert(id.version(), KnowledgeGraphVertex::Entity(vertex)); + .insert(id.version, KnowledgeGraphVertex::Entity(vertex)); } Entry::Vacant(entry) => { entry.insert(BTreeMap::from([( - id.version(), + id.version, KnowledgeGraphVertex::Entity(vertex), )])); } diff --git a/apps/hash-graph/lib/graph/src/knowledge/entity.rs b/apps/hash-graph/lib/graph/src/knowledge/entity.rs index 3805f242041..ef1e5ce0a68 100644 --- a/apps/hash-graph/lib/graph/src/knowledge/entity.rs +++ b/apps/hash-graph/lib/graph/src/knowledge/entity.rs @@ -31,6 +31,7 @@ use crate::{ Serialize, Deserialize, ToSchema, + FromSql, ToSql, )] #[postgres(transparent)] @@ -91,86 +92,38 @@ impl EntityProperties { } #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, ToSchema)] -#[serde(deny_unknown_fields, rename_all = "camelCase")] +#[serde(deny_unknown_fields)] pub struct EntityLinkOrder { - #[serde(default, skip_serializing_if = "Option::is_none")] - left_to_right_order: Option, - #[serde(default, skip_serializing_if = "Option::is_none")] - right_to_left_order: Option, -} - -impl EntityLinkOrder { - #[must_use] - pub const fn new( - left_to_right_order: Option, - right_to_left_order: Option, - ) -> Self { - Self { - left_to_right_order, - right_to_left_order, - } - } - - #[must_use] - pub const fn left_to_right(&self) -> Option { - self.left_to_right_order - } - - #[must_use] - pub const fn right_to_left(&self) -> Option { - self.right_to_left_order - } + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "leftToRightOrder" + )] + pub left_to_right: Option, + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "rightToLeftOrder" + )] + pub right_to_left: Option, } /// The associated information for 'Link' entities #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, ToSchema)] #[serde(deny_unknown_fields, rename_all = "camelCase")] pub struct LinkData { - left_entity_id: EntityId, - right_entity_id: EntityId, + pub left_entity_id: EntityId, + pub right_entity_id: EntityId, #[serde(flatten)] - order: EntityLinkOrder, -} - -impl LinkData { - #[must_use] - pub const fn new( - left_entity_id: EntityId, - right_entity_id: EntityId, - left_to_right_order: Option, - right_to_left_order: Option, - ) -> Self { - Self { - left_entity_id, - right_entity_id, - order: EntityLinkOrder::new(left_to_right_order, right_to_left_order), - } - } - - #[must_use] - pub const fn left_entity_id(&self) -> EntityId { - self.left_entity_id - } - - #[must_use] - pub const fn right_entity_id(&self) -> EntityId { - self.right_entity_id - } - - #[must_use] - pub const fn left_to_right_order(&self) -> Option { - self.order.left_to_right_order - } - - #[must_use] - pub const fn right_to_left_order(&self) -> Option { - self.order.right_to_left_order - } + pub order: EntityLinkOrder, } /// The metadata of an [`Entity`] record. #[derive(Debug, Clone, PartialEq, Eq, Serialize, ToSchema)] // TODO: deny_unknown_fields on other structs +// TODO: Make fields `pub` when `#[feature(mut_restriction)]` is available. +// see https://github.com/rust-lang/rust/issues/105077 +// see https://app.asana.com/0/0/1203977361907407/f #[serde(deny_unknown_fields, rename_all = "camelCase")] pub struct EntityMetadata { record_id: EntityRecordId, @@ -231,50 +184,10 @@ impl EntityMetadata { #[derive(Debug, PartialEq, Eq, Serialize, ToSchema)] #[serde(rename_all = "camelCase")] pub struct Entity { - properties: EntityProperties, + pub properties: EntityProperties, #[serde(default, skip_serializing_if = "Option::is_none")] - link_data: Option, - metadata: EntityMetadata, -} - -impl Entity { - #[must_use] - pub const fn new( - properties: EntityProperties, - link_data: Option, - identifier: EntityRecordId, - version: EntityVersion, - entity_type_id: VersionedUri, - provenance_metadata: ProvenanceMetadata, - archived: bool, - ) -> Self { - Self { - properties, - link_data, - metadata: EntityMetadata::new( - identifier, - version, - entity_type_id, - provenance_metadata, - archived, - ), - } - } - - #[must_use] - pub const fn properties(&self) -> &EntityProperties { - &self.properties - } - - #[must_use] - pub const fn link_data(&self) -> Option { - self.link_data - } - - #[must_use] - pub const fn metadata(&self) -> &EntityMetadata { - &self.metadata - } + pub link_data: Option, + pub metadata: EntityMetadata, } impl Record for Entity { @@ -283,14 +196,17 @@ impl Record for Entity { fn vertex_id(&self, time_axis: TimeAxis) -> Self::VertexId { let timestamp = match time_axis { - TimeAxis::DecisionTime => self.metadata().version().decision_time.start().cast(), - TimeAxis::TransactionTime => self.metadata().version().transaction_time.start().cast(), + TimeAxis::DecisionTime => self.metadata.version().decision_time.start().cast(), + TimeAxis::TransactionTime => self.metadata.version().transaction_time.start().cast(), }; - EntityVertexId::new(self.metadata().record_id().entity_id(), timestamp.into()) + EntityVertexId { + base_id: self.metadata.record_id().entity_id, + version: timestamp.into(), + } } fn create_filter_for_vertex_id(vertex_id: &Self::VertexId) -> Filter { - Filter::for_entity_by_entity_id(vertex_id.base_id()) + Filter::for_entity_by_entity_id(vertex_id.base_id) } } diff --git a/apps/hash-graph/lib/graph/src/knowledge/entity/query.rs b/apps/hash-graph/lib/graph/src/knowledge/entity/query.rs index cbe0928bf3f..abad29454ed 100644 --- a/apps/hash-graph/lib/graph/src/knowledge/entity/query.rs +++ b/apps/hash-graph/lib/graph/src/knowledge/entity/query.rs @@ -197,7 +197,7 @@ pub enum EntityQueryPath<'p> { /// [`Entity`]: crate::knowledge::Entity /// [`LinkData::right_entity_id()`]: crate::knowledge::LinkData::right_entity_id RightEntity(Box), - /// Corresponds to [`LinkData::left_to_right_order()`]. + /// Corresponds to [`EntityLinkOrder::left_to_right`]. /// /// ```rust /// # use serde::Deserialize; @@ -208,9 +208,9 @@ pub enum EntityQueryPath<'p> { /// # Ok::<(), serde_json::Error>(()) /// ``` /// - /// [`LinkData::left_to_right_order()`]: crate::knowledge::LinkData::left_to_right_order + /// [`EntityLinkOrder::left_to_right`]: crate::knowledge::EntityLinkOrder::left_to_right LeftToRightOrder, - /// Corresponds to [`LinkData::right_to_left_order()`]. + /// Corresponds to [`EntityLinkOrder::right_to_left`]. /// /// ```rust /// # use serde::Deserialize; @@ -221,9 +221,9 @@ pub enum EntityQueryPath<'p> { /// # Ok::<(), serde_json::Error>(()) /// ``` /// - /// [`LinkData::right_to_left_order()`]: crate::knowledge::LinkData::right_to_left_order + /// [`EntityLinkOrder::right_to_left`]: crate::knowledge::EntityLinkOrder::right_to_left RightToLeftOrder, - /// Corresponds to [`Entity::properties()`]. + /// Corresponds to [`Entity::properties`]. /// /// Deserializes from `["properties", ...]` where `...` is a path to a property URI of an /// [`Entity`]. @@ -246,7 +246,7 @@ pub enum EntityQueryPath<'p> { /// ``` /// /// [`Entity`]: crate::knowledge::Entity - /// [`Entity::properties()`]: crate::knowledge::Entity::properties + /// [`Entity::properties`]: crate::knowledge::Entity::properties Properties(Option>), } diff --git a/apps/hash-graph/lib/graph/src/ontology.rs b/apps/hash-graph/lib/graph/src/ontology.rs index ccd1f986638..402ee8af628 100644 --- a/apps/hash-graph/lib/graph/src/ontology.rs +++ b/apps/hash-graph/lib/graph/src/ontology.rs @@ -173,6 +173,9 @@ pub trait OntologyTypeWithMetadata: Record { fn metadata(&self) -> &OntologyElementMetadata; } +// TODO: Flatten when `#[feature(mut_restriction)]` is available. +// see https://github.com/rust-lang/rust/issues/105077 +// see https://app.asana.com/0/0/1203977361907407/f #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ToSchema)] #[serde(untagged)] pub enum OntologyElementMetadata { @@ -292,7 +295,10 @@ impl Record for DataTypeWithMetadata { fn vertex_id(&self, _time_axis: TimeAxis) -> Self::VertexId { let record_id = self.metadata().record_id(); - OntologyTypeVertexId::new(record_id.base_uri().clone(), record_id.version()) + OntologyTypeVertexId { + base_id: record_id.base_uri.clone(), + version: record_id.version, + } } fn create_filter_for_vertex_id(vertex_id: &Self::VertexId) -> Filter { @@ -333,7 +339,10 @@ impl Record for PropertyTypeWithMetadata { fn vertex_id(&self, _time_axis: TimeAxis) -> Self::VertexId { let record_id = self.metadata().record_id(); - OntologyTypeVertexId::new(record_id.base_uri().clone(), record_id.version()) + OntologyTypeVertexId { + base_id: record_id.base_uri.clone(), + version: record_id.version, + } } fn create_filter_for_vertex_id(vertex_id: &Self::VertexId) -> Filter { @@ -374,7 +383,10 @@ impl Record for EntityTypeWithMetadata { fn vertex_id(&self, _time_axis: TimeAxis) -> Self::VertexId { let record_id = self.metadata().record_id(); - OntologyTypeVertexId::new(record_id.base_uri().clone(), record_id.version()) + OntologyTypeVertexId { + base_id: record_id.base_uri.clone(), + version: record_id.version, + } } fn create_filter_for_vertex_id(vertex_id: &Self::VertexId) -> Filter { diff --git a/apps/hash-graph/lib/graph/src/ontology/domain_validator.rs b/apps/hash-graph/lib/graph/src/ontology/domain_validator.rs index 8e93c8910b9..19ef10ada0d 100644 --- a/apps/hash-graph/lib/graph/src/ontology/domain_validator.rs +++ b/apps/hash-graph/lib/graph/src/ontology/domain_validator.rs @@ -101,7 +101,7 @@ impl DomainValidator { impl ValidateOntologyType for DomainValidator { fn validate(&self, ontology_type: &DataType) -> error_stack::Result<(), DomainValidationError> { - let base_uri = ontology_type.id().base_uri(); + let base_uri = &ontology_type.id().base_uri; if !self.validate_url(base_uri.as_str()) { return Err(DomainValidationError) @@ -134,7 +134,7 @@ impl ValidateOntologyType for DomainValidator { &self, ontology_type: &PropertyType, ) -> error_stack::Result<(), DomainValidationError> { - let base_uri = ontology_type.id().base_uri(); + let base_uri = &ontology_type.id().base_uri; if !self.validate_url(base_uri.as_str()) { return Err(DomainValidationError).into_report().attach_printable( @@ -167,7 +167,7 @@ impl ValidateOntologyType for DomainValidator { &self, ontology_type: &EntityType, ) -> error_stack::Result<(), DomainValidationError> { - let base_uri = ontology_type.id().base_uri(); + let base_uri = &ontology_type.id().base_uri; if !self.validate_url(base_uri.as_str()) { return Err(DomainValidationError) diff --git a/apps/hash-graph/lib/graph/src/shared/identifier.rs b/apps/hash-graph/lib/graph/src/shared/identifier.rs index bfba94759c7..057007fe56e 100644 --- a/apps/hash-graph/lib/graph/src/shared/identifier.rs +++ b/apps/hash-graph/lib/graph/src/shared/identifier.rs @@ -3,7 +3,7 @@ pub mod knowledge; pub mod ontology; pub mod time; -use serde::{Deserialize, Serialize}; +use serde::Serialize; use type_system::uri::{BaseUri, VersionedUri}; use utoipa::ToSchema; @@ -13,66 +13,25 @@ use crate::identifier::{ time::{ProjectedTime, Timestamp}, }; -#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, ToSchema)] -#[serde(untagged)] -pub enum GraphElementId { - Ontology(BaseUri), - KnowledgeGraph(EntityId), -} - #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, Serialize, ToSchema)] #[serde(rename_all = "camelCase")] pub struct EntityVertexId { - base_id: EntityId, - version: Timestamp, -} - -impl EntityVertexId { - #[must_use] - pub const fn new(base_id: EntityId, version: Timestamp) -> Self { - Self { base_id, version } - } - - #[must_use] - pub const fn base_id(&self) -> EntityId { - self.base_id - } - - #[must_use] - pub const fn version(&self) -> Timestamp { - self.version - } + pub base_id: EntityId, + pub version: Timestamp, } #[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize, ToSchema)] #[serde(rename_all = "camelCase")] pub struct OntologyTypeVertexId { - base_id: BaseUri, - version: OntologyTypeVersion, -} - -impl OntologyTypeVertexId { - #[must_use] - pub const fn new(base_id: BaseUri, version: OntologyTypeVersion) -> Self { - Self { base_id, version } - } - - #[must_use] - pub const fn base_id(&self) -> &BaseUri { - &self.base_id - } - - #[must_use] - pub const fn version(&self) -> OntologyTypeVersion { - self.version - } + pub base_id: BaseUri, + pub version: OntologyTypeVersion, } -impl From<&VersionedUri> for OntologyTypeVertexId { - fn from(uri: &VersionedUri) -> Self { +impl From for OntologyTypeVertexId { + fn from(uri: VersionedUri) -> Self { Self { - base_id: uri.base_uri().clone(), - version: OntologyTypeVersion::new(uri.version()), + base_id: uri.base_uri, + version: OntologyTypeVersion::new(uri.version), } } } diff --git a/apps/hash-graph/lib/graph/src/shared/identifier/knowledge.rs b/apps/hash-graph/lib/graph/src/shared/identifier/knowledge.rs index 2925ea7a0e1..4a35b83cf96 100644 --- a/apps/hash-graph/lib/graph/src/shared/identifier/knowledge.rs +++ b/apps/hash-graph/lib/graph/src/shared/identifier/knowledge.rs @@ -4,7 +4,7 @@ use std::{ }; use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer}; -use tokio_postgres::types::ToSql; +use tokio_postgres::types::{FromSql, ToSql}; use utoipa::{openapi, ToSchema}; use uuid::Uuid; @@ -25,28 +25,8 @@ use crate::{ #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] pub struct EntityId { - owned_by_id: OwnedById, - entity_uuid: EntityUuid, -} - -impl EntityId { - #[must_use] - pub const fn new(owned_by_id: OwnedById, entity_uuid: EntityUuid) -> Self { - Self { - owned_by_id, - entity_uuid, - } - } - - #[must_use] - pub const fn owned_by_id(&self) -> OwnedById { - self.owned_by_id - } - - #[must_use] - pub const fn entity_uuid(&self) -> EntityUuid { - self.entity_uuid - } + pub owned_by_id: OwnedById, + pub entity_uuid: EntityUuid, } impl Serialize for EntityId { @@ -130,7 +110,9 @@ impl EntityVersion { } } -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, ToSql, ToSchema)] +#[derive( + Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, FromSql, ToSql, ToSchema, +)] #[postgres(transparent)] #[repr(transparent)] pub struct EntityEditionId(Uuid); @@ -150,8 +132,8 @@ impl EntityEditionId { #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, Serialize, ToSchema)] #[serde(rename_all = "camelCase")] pub struct EntityRecordId { - entity_id: EntityId, - edition_id: EntityEditionId, + pub entity_id: EntityId, + pub edition_id: EntityEditionId, } impl SubgraphIndex for EntityVertexId { @@ -162,23 +144,3 @@ impl SubgraphIndex for EntityVertexId { subgraph.vertices.entities.raw_entry_mut().from_key(self) } } - -impl EntityRecordId { - #[must_use] - pub const fn new(entity_id: EntityId, edition_id: EntityEditionId) -> Self { - Self { - entity_id, - edition_id, - } - } - - #[must_use] - pub const fn entity_id(&self) -> EntityId { - self.entity_id - } - - #[must_use] - pub const fn edition_id(&self) -> EntityEditionId { - self.edition_id - } -} diff --git a/apps/hash-graph/lib/graph/src/shared/identifier/ontology.rs b/apps/hash-graph/lib/graph/src/shared/identifier/ontology.rs index 13c5c64fb44..0c48a6e1aff 100644 --- a/apps/hash-graph/lib/graph/src/shared/identifier/ontology.rs +++ b/apps/hash-graph/lib/graph/src/shared/identifier/ontology.rs @@ -59,29 +59,9 @@ impl<'a> FromSql<'a> for OntologyTypeVersion { #[serde(rename_all = "camelCase")] pub struct OntologyTypeRecordId { #[schema(value_type = String)] - base_uri: BaseUri, + pub base_uri: BaseUri, #[schema(value_type = u32)] - version: OntologyTypeVersion, -} - -impl OntologyTypeRecordId { - #[must_use] - pub const fn new(base_id: BaseUri, version: OntologyTypeVersion) -> Self { - Self { - base_uri: base_id, - version, - } - } - - #[must_use] - pub const fn base_uri(&self) -> &BaseUri { - &self.base_uri - } - - #[must_use] - pub const fn version(&self) -> OntologyTypeVersion { - self.version - } + pub version: OntologyTypeVersion, } impl Display for OntologyTypeRecordId { @@ -90,20 +70,21 @@ impl Display for OntologyTypeRecordId { } } -// The Type System crate doesn't let us destructure so we need to clone base_uri -impl From<&VersionedUri> for OntologyTypeRecordId { - fn from(versioned_uri: &VersionedUri) -> Self { +impl From for OntologyTypeRecordId { + fn from(versioned_uri: VersionedUri) -> Self { Self { - base_uri: versioned_uri.base_uri().clone(), - version: OntologyTypeVersion::new(versioned_uri.version()), + base_uri: versioned_uri.base_uri, + version: OntologyTypeVersion::new(versioned_uri.version), } } } -impl From<&OntologyTypeRecordId> for VersionedUri { - fn from(record_id: &OntologyTypeRecordId) -> Self { - // We should make it possible to destructure to avoid the clone - Self::new(record_id.base_uri().clone(), record_id.version.inner()) +impl From for VersionedUri { + fn from(record_id: OntologyTypeRecordId) -> Self { + Self { + base_uri: record_id.base_uri, + version: record_id.version.inner(), + } } } diff --git a/apps/hash-graph/lib/graph/src/shared/provenance.rs b/apps/hash-graph/lib/graph/src/shared/provenance.rs index 6985bc46e32..570232c738a 100644 --- a/apps/hash-graph/lib/graph/src/shared/provenance.rs +++ b/apps/hash-graph/lib/graph/src/shared/provenance.rs @@ -1,7 +1,7 @@ use core::fmt; use serde::{Deserialize, Serialize}; -use tokio_postgres::types::ToSql; +use tokio_postgres::types::{FromSql, ToSql}; use utoipa::{openapi, ToSchema}; use uuid::Uuid; @@ -10,7 +10,18 @@ use crate::identifier::account::AccountId; macro_rules! define_provenance_id { ($name:tt) => { #[derive( - Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize, ToSql, + Debug, + Copy, + Clone, + PartialEq, + Eq, + Hash, + PartialOrd, + Ord, + Serialize, + Deserialize, + FromSql, + ToSql, )] #[postgres(transparent)] #[repr(transparent)] @@ -50,6 +61,9 @@ macro_rules! define_provenance_id { define_provenance_id!(OwnedById); define_provenance_id!(UpdatedById); +// TODO: Make fields `pub` when `#[feature(mut_restriction)]` is available. +// see https://github.com/rust-lang/rust/issues/105077 +// see https://app.asana.com/0/0/1203977361907407/f #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, ToSchema)] #[serde(deny_unknown_fields, rename_all = "camelCase")] pub struct ProvenanceMetadata { diff --git a/apps/hash-graph/lib/graph/src/store/fetcher.rs b/apps/hash-graph/lib/graph/src/store/fetcher.rs index 3159d9b70a5..76114963fc6 100644 --- a/apps/hash-graph/lib/graph/src/store/fetcher.rs +++ b/apps/hash-graph/lib/graph/src/store/fetcher.rs @@ -149,7 +149,7 @@ where OntologyTypeReference::EntityTypeReference(reference) => reference.uri(), }; - if self.domain_validator.validate_url(uri.base_uri().as_str()) { + if self.domain_validator.validate_url(uri.base_uri.as_str()) { // If the domain is valid, we own the data type and it either exists or we cannot // reference it. return Ok(true); @@ -233,7 +233,7 @@ where .await? { let metadata = ExternalOntologyElementMetadata::new( - data_type.id().into(), + data_type.id().clone().into(), provenance_metadata, fetched_ontology_type.fetched_at, ); @@ -255,7 +255,7 @@ where .await? { let metadata = ExternalOntologyElementMetadata::new( - property_type.id().into(), + property_type.id().clone().into(), provenance_metadata, fetched_ontology_type.fetched_at, ); @@ -277,7 +277,7 @@ where .await? { let metadata = ExternalOntologyElementMetadata::new( - entity_type.id().into(), + entity_type.id().clone().into(), provenance_metadata, fetched_ontology_type.fetched_at, ); diff --git a/apps/hash-graph/lib/graph/src/store/postgres.rs b/apps/hash-graph/lib/graph/src/store/postgres.rs index 77a671a9f76..e2632090f78 100644 --- a/apps/hash-graph/lib/graph/src/store/postgres.rs +++ b/apps/hash-graph/lib/graph/src/store/postgres.rs @@ -267,8 +267,8 @@ where record_created_by_id := $4 );"#, &[ - &metadata.record_id().base_uri().as_str(), - &metadata.record_id().version(), + &metadata.record_id().base_uri.as_str(), + &metadata.record_id().version, &metadata.owned_by_id(), &metadata.provenance_metadata().updated_by_id(), ], @@ -279,11 +279,11 @@ where .map_err(|report| match report.current_context().code() { Some(&SqlState::EXCLUSION_VIOLATION | &SqlState::UNIQUE_VIOLATION) => report .change_context(BaseUriAlreadyExists) - .attach_printable(metadata.record_id().base_uri().clone()) + .attach_printable(metadata.record_id().base_uri.clone()) .change_context(InsertionError), _ => report .change_context(InsertionError) - .attach_printable(VersionedUri::from(metadata.record_id())), + .attach_printable(VersionedUri::from(metadata.record_id().clone())), }) } @@ -309,8 +309,8 @@ where record_created_by_id := $4 );"#, &[ - &metadata.record_id().base_uri().as_str(), - &metadata.record_id().version(), + &metadata.record_id().base_uri.as_str(), + &metadata.record_id().version, &metadata.fetched_at(), &metadata.provenance_metadata().updated_by_id(), ], @@ -321,11 +321,11 @@ where .map_err(|report| match report.current_context().code() { Some(&SqlState::EXCLUSION_VIOLATION | &SqlState::UNIQUE_VIOLATION) => report .change_context(BaseUriAlreadyExists) - .attach_printable(metadata.record_id().base_uri().clone()) + .attach_printable(metadata.record_id().base_uri.clone()) .change_context(InsertionError), _ => report .change_context(InsertionError) - .attach_printable(VersionedUri::from(metadata.record_id())), + .attach_printable(VersionedUri::from(metadata.record_id().clone())), }) } @@ -355,8 +355,8 @@ where record_created_by_id := $3 );"#, &[ - &uri.base_uri().as_str(), - &i64::from(uri.version()), + &uri.base_uri.as_str(), + &i64::from(uri.version), &updated_by_id, ], ) @@ -373,7 +373,7 @@ where .change_context(UpdateError), Some(&SqlState::RESTRICT_VIOLATION) => report .change_context(BaseUriDoesNotExist) - .attach_printable(uri.base_uri().clone()) + .attach_printable(uri.base_uri.clone()) .change_context(UpdateError), _ => report .change_context(UpdateError) @@ -439,7 +439,7 @@ where T::Representation: Send, { let uri = database_type.id(); - let record_id = OntologyTypeRecordId::from(uri); + let record_id = OntologyTypeRecordId::from(uri.clone()); let (ontology_id, owned_by_id) = self .update_owned_ontology_id(uri, updated_by_id) @@ -679,7 +679,7 @@ where /// - if the entry referred to by `uri` does not exist. #[tracing::instrument(level = "debug", skip(self))] async fn ontology_id_by_uri(&self, uri: &VersionedUri) -> Result { - let version = i64::from(uri.version()); + let version = i64::from(uri.version); Ok(self .client .as_client() @@ -689,7 +689,7 @@ where FROM ontology_ids WHERE base_uri = $1 AND version = $2; "#, - &[&uri.base_uri().as_str(), &version], + &[&uri.base_uri.as_str(), &version], ) .await .into_report() @@ -775,17 +775,25 @@ impl PostgresStore> { writer .as_mut() .write(&[ - &entity_id.owned_by_id(), - &entity_id.entity_uuid(), - &left_entity_id.as_ref().map(EntityId::owned_by_id), - &left_entity_id.as_ref().map(EntityId::entity_uuid), - &right_entity_id.as_ref().map(EntityId::owned_by_id), - &right_entity_id.as_ref().map(EntityId::entity_uuid), + &entity_id.owned_by_id, + &entity_id.entity_uuid, + &left_entity_id + .as_ref() + .map(|entity_id| entity_id.owned_by_id), + &left_entity_id + .as_ref() + .map(|entity_id| entity_id.entity_uuid), + &right_entity_id + .as_ref() + .map(|entity_id| entity_id.owned_by_id), + &right_entity_id + .as_ref() + .map(|entity_id| entity_id.entity_uuid), ]) .await .into_report() .change_context(InsertionError) - .attach_printable(entity_id.entity_uuid())?; + .attach_printable(entity_id.entity_uuid)?; } writer @@ -957,8 +965,8 @@ impl PostgresStore> { writer .as_mut() .write(&[ - &entity_id.owned_by_id(), - &entity_id.entity_uuid(), + &entity_id.owned_by_id, + &entity_id.entity_uuid, &entity_edition_id, &decision_time, ]) diff --git a/apps/hash-graph/lib/graph/src/store/postgres/knowledge/entity.rs b/apps/hash-graph/lib/graph/src/store/postgres/knowledge/entity.rs index a93ee86102c..1f6ae5108ce 100644 --- a/apps/hash-graph/lib/graph/src/store/postgres/knowledge/entity.rs +++ b/apps/hash-graph/lib/graph/src/store/postgres/knowledge/entity.rs @@ -60,7 +60,7 @@ impl PostgresStore { }; let version_interval = entity - .metadata() + .metadata .version() .projected_time(time_axis); @@ -100,7 +100,7 @@ impl PostgresStore { if current_resolve_depths.is_of_type.outgoing > 0 { let entity_type_id = - OntologyTypeVertexId::from(entity.metadata().entity_type_id()); + OntologyTypeVertexId::from(entity.metadata.entity_type_id().clone()); subgraph.edges.insert(Edge::KnowledgeGraph { vertex_id: entity_vertex_id, outward_edge: KnowledgeGraphOutwardEdges::ToOntology(OutwardEdge { @@ -129,7 +129,7 @@ impl PostgresStore { if current_resolve_depths.has_left_entity.incoming > 0 { for outgoing_link_entity in >::read( self, - &Filter::for_outgoing_link_by_source_entity_id(entity_vertex_id.base_id()), + &Filter::for_outgoing_link_by_source_entity_id(entity_vertex_id.base_id), &intersected_time_projection, ) .await? @@ -141,7 +141,7 @@ impl PostgresStore { // outgoing link `Entity` kind: KnowledgeGraphEdgeKind::HasLeftEntity, reversed: true, - right_endpoint: outgoing_link_entity.metadata().record_id().entity_id(), + right_endpoint: outgoing_link_entity.metadata.record_id().entity_id, }), }); @@ -168,7 +168,7 @@ impl PostgresStore { if current_resolve_depths.has_right_entity.incoming > 0 { for incoming_link_entity in >::read( self, - &Filter::for_incoming_link_by_source_entity_id(entity_vertex_id.base_id()), + &Filter::for_incoming_link_by_source_entity_id(entity_vertex_id.base_id), &intersected_time_projection, ) .await? @@ -180,7 +180,7 @@ impl PostgresStore { // incoming link `Entity` kind: KnowledgeGraphEdgeKind::HasRightEntity, reversed: true, - right_endpoint: incoming_link_entity.metadata().record_id().entity_id(), + right_endpoint: incoming_link_entity.metadata.record_id().entity_id, }), }); @@ -207,7 +207,7 @@ impl PostgresStore { if current_resolve_depths.has_left_entity.outgoing > 0 { for left_entity in >::read( self, - &Filter::for_left_entity_by_entity_id(entity_vertex_id.base_id()), + &Filter::for_left_entity_by_entity_id(entity_vertex_id.base_id), &intersected_time_projection, ) .await? @@ -219,7 +219,7 @@ impl PostgresStore { // outgoing `Link` `Entity` kind: KnowledgeGraphEdgeKind::HasLeftEntity, reversed: false, - right_endpoint: left_entity.metadata().record_id().entity_id(), + right_endpoint: left_entity.metadata.record_id().entity_id, }), }); @@ -246,7 +246,7 @@ impl PostgresStore { if current_resolve_depths.has_right_entity.outgoing > 0 { for right_entity in >::read( self, - &Filter::for_right_entity_by_entity_id(entity_vertex_id.base_id()), + &Filter::for_right_entity_by_entity_id(entity_vertex_id.base_id), &intersected_time_projection, ) .await? @@ -258,7 +258,7 @@ impl PostgresStore { // outgoing `Link` `Entity` kind: KnowledgeGraphEdgeKind::HasRightEntity, reversed: false, - right_endpoint: right_entity.metadata().record_id().entity_id(), + right_endpoint: right_entity.metadata.record_id().entity_id, }), }); @@ -302,10 +302,10 @@ impl EntityStore for PostgresStore { properties: EntityProperties, link_data: Option, ) -> Result { - let entity_id = EntityId::new( + let entity_id = EntityId { owned_by_id, - entity_uuid.unwrap_or_else(|| EntityUuid::new(Uuid::new_v4())), - ); + entity_uuid: entity_uuid.unwrap_or_else(|| EntityUuid::new(Uuid::new_v4())), + }; let entity_type_ontology_id = self .ontology_id_by_uri(&entity_type_id) @@ -342,8 +342,8 @@ impl EntityStore for PostgresStore { ); "#, &[ - &entity_id.owned_by_id(), - &entity_id.entity_uuid(), + &entity_id.owned_by_id, + &entity_id.entity_uuid, &decision_time, &updated_by_id, &archived, @@ -351,18 +351,22 @@ impl EntityStore for PostgresStore { &properties, &link_data .as_ref() - .map(|metadata| metadata.left_entity_id().owned_by_id()), + .map(|metadata| metadata.left_entity_id.owned_by_id), + &link_data + .as_ref() + .map(|metadata| metadata.left_entity_id.entity_uuid), + &link_data + .as_ref() + .map(|metadata| metadata.right_entity_id.owned_by_id), &link_data .as_ref() - .map(|metadata| metadata.left_entity_id().entity_uuid()), + .map(|metadata| metadata.right_entity_id.entity_uuid), &link_data .as_ref() - .map(|metadata| metadata.right_entity_id().owned_by_id()), + .map(|link_data| link_data.order.left_to_right), &link_data .as_ref() - .map(|metadata| metadata.right_entity_id().entity_uuid()), - &link_data.as_ref().map(LinkData::left_to_right_order), - &link_data.as_ref().map(LinkData::right_to_left_order), + .map(|link_data| link_data.order.right_to_left), ], ) .await @@ -370,7 +374,10 @@ impl EntityStore for PostgresStore { .change_context(InsertionError)?; Ok(EntityMetadata::new( - EntityRecordId::new(entity_id, EntityEditionId::new(row.get(0))), + EntityRecordId { + entity_id, + edition_id: EntityEditionId::new(row.get(0)), + }, EntityVersion { decision_time: row.get(1), transaction_time: row.get(2), @@ -406,17 +413,23 @@ impl EntityStore for PostgresStore { let mut entity_versions = Vec::with_capacity(entities.size_hint().0); for (owned_by_id, entity_uuid, properties, link_data, decision_time) in entities { entity_ids.push(( - EntityId::new( + EntityId { owned_by_id, - entity_uuid.unwrap_or_else(|| EntityUuid::new(Uuid::new_v4())), - ), - link_data.as_ref().map(LinkData::left_entity_id), - link_data.as_ref().map(LinkData::right_entity_id), + entity_uuid: entity_uuid.unwrap_or_else(|| EntityUuid::new(Uuid::new_v4())), + }, + link_data.as_ref().map(|link_data| link_data.left_entity_id), + link_data + .as_ref() + .map(|link_data| link_data.right_entity_id), )); entity_editions.push(( properties, - link_data.as_ref().and_then(LinkData::left_to_right_order), - link_data.as_ref().and_then(LinkData::right_to_left_order), + link_data + .as_ref() + .and_then(|link_data| link_data.order.left_to_right), + link_data + .as_ref() + .and_then(|link_data| link_data.order.right_to_left), )); entity_versions.push(decision_time); } @@ -458,9 +471,12 @@ impl EntityStore for PostgresStore { .into_iter() .zip(entity_versions) .zip(entity_edition_ids) - .map(|(((entity_id, ..), entity_version), entity_edition_id)| { + .map(|(((entity_id, ..), entity_version), edition_id)| { EntityMetadata::new( - EntityRecordId::new(entity_id, entity_edition_id), + EntityRecordId { + entity_id, + edition_id, + }, entity_version, entity_type_id.clone(), ProvenanceMetadata::new(actor_id), @@ -540,7 +556,7 @@ impl EntityStore for PostgresStore { SELECT EXISTS ( SELECT 1 FROM entity_ids WHERE owned_by_id = $1 AND entity_uuid = $2 );"#, - &[&entity_id.owned_by_id(), &entity_id.entity_uuid()], + &[&entity_id.owned_by_id, &entity_id.entity_uuid], ) .await .into_report() @@ -574,15 +590,15 @@ impl EntityStore for PostgresStore { ); "#, &[ - &entity_id.owned_by_id(), - &entity_id.entity_uuid(), + &entity_id.owned_by_id, + &entity_id.entity_uuid, &decision_time, &updated_by_id, &archived, &entity_type_ontology_id, &properties, - &link_order.left_to_right(), - &link_order.right_to_left(), + &link_order.left_to_right, + &link_order.right_to_left, ], ) .await @@ -598,7 +614,10 @@ impl EntityStore for PostgresStore { transaction.commit().await.change_context(UpdateError)?; Ok(EntityMetadata::new( - EntityRecordId::new(entity_id, EntityEditionId::new(row.get(0))), + EntityRecordId { + entity_id, + edition_id: EntityEditionId::new(row.get(0)), + }, EntityVersion { decision_time: row.get(1), transaction_time: row.get(2), diff --git a/apps/hash-graph/lib/graph/src/store/postgres/knowledge/entity/read.rs b/apps/hash-graph/lib/graph/src/store/postgres/knowledge/entity/read.rs index 56b10cf7b35..a7f4b0eda49 100644 --- a/apps/hash-graph/lib/graph/src/store/postgres/knowledge/entity/read.rs +++ b/apps/hash-graph/lib/graph/src/store/postgres/knowledge/entity/read.rs @@ -10,10 +10,13 @@ use uuid::Uuid; use crate::{ identifier::{ account::AccountId, - knowledge::{EntityEditionId, EntityId, EntityRecordId, EntityVersion}, + knowledge::{EntityId, EntityRecordId, EntityVersion}, time::TimeProjection, }, - knowledge::{Entity, EntityProperties, EntityQueryPath, EntityUuid, LinkData}, + knowledge::{ + Entity, EntityLinkOrder, EntityMetadata, EntityProperties, EntityQueryPath, EntityUuid, + LinkData, + }, ontology::EntityTypeQueryPath, provenance::{OwnedById, ProvenanceMetadata, UpdatedById}, store::{ @@ -86,7 +89,7 @@ impl crud::Read for PostgresStore { serde_json::from_value(row.get(properties_index)) .into_report() .change_context(QueryError)?; - let entity_type_uri = VersionedUri::from_str(row.get(type_id_index)) + let entity_type_id = VersionedUri::from_str(row.get(type_id_index)) .into_report() .change_context(QueryError)?; @@ -108,18 +111,20 @@ impl crud::Read for PostgresStore { Some(left_entity_uuid), Some(right_owned_by_id), Some(right_entity_uuid), - ) => Some(LinkData::new( - EntityId::new( - OwnedById::new(left_owned_by_id), - EntityUuid::new(left_entity_uuid), - ), - EntityId::new( - OwnedById::new(right_owned_by_id), - EntityUuid::new(right_entity_uuid), - ), - row.get(left_to_right_order_index), - row.get(right_to_left_order_index), - )), + ) => Some(LinkData { + left_entity_id: EntityId { + owned_by_id: OwnedById::new(left_owned_by_id), + entity_uuid: EntityUuid::new(left_entity_uuid), + }, + right_entity_id: EntityId { + owned_by_id: OwnedById::new(right_owned_by_id), + entity_uuid: EntityUuid::new(right_entity_uuid), + }, + order: EntityLinkOrder { + left_to_right: row.get(left_to_right_order_index), + right_to_left: row.get(right_to_left_order_index), + }, + }), (None, None, None, None) => None, _ => unreachable!( "It's not possible to have a link entity with the left entityId or \ @@ -128,27 +133,28 @@ impl crud::Read for PostgresStore { } }; - let owned_by_id = OwnedById::new(row.get(owned_by_id_index)); - let entity_uuid = EntityUuid::new(row.get(entity_uuid_index)); let updated_by_id = UpdatedById::new(row.get(updated_by_id_index)); - Ok(Entity::new( + Ok(Entity { properties, link_data, - EntityRecordId::new( - EntityId::new(owned_by_id, entity_uuid), - EntityEditionId::new(row.get(edition_id_index)), + metadata: EntityMetadata::new( + EntityRecordId { + entity_id: EntityId { + owned_by_id: row.get(owned_by_id_index), + entity_uuid: row.get(entity_uuid_index), + }, + edition_id: row.get(edition_id_index), + }, + EntityVersion { + decision_time: row.get(decision_time_index), + transaction_time: row.get(transaction_time_index), + }, + entity_type_id, + ProvenanceMetadata::new(updated_by_id), + row.get(archived_index), ), - EntityVersion { - decision_time: row.get(decision_time_index), - transaction_time: row.get(transaction_time_index), - }, - entity_type_uri, - ProvenanceMetadata::new(updated_by_id), - // TODO: only the historic table would have an `archived` field. - // Consider what we should do about that. - row.get(archived_index), - )) + }) }) .try_collect() .await diff --git a/apps/hash-graph/lib/graph/src/store/postgres/ontology/entity_type.rs b/apps/hash-graph/lib/graph/src/store/postgres/ontology/entity_type.rs index 57e2dcfe8ae..3b43b2a5ae7 100644 --- a/apps/hash-graph/lib/graph/src/store/postgres/ontology/entity_type.rs +++ b/apps/hash-graph/lib/graph/src/store/postgres/ontology/entity_type.rs @@ -112,17 +112,19 @@ impl PostgresStore { if let Some(property_type_ref_uris) = property_type_ref_uris { for property_type_ref_uri in property_type_ref_uris { + let property_type_vertex_id = OntologyTypeVertexId::from(property_type_ref_uri); + subgraph.edges.insert(Edge::Ontology { vertex_id: entity_type_id.clone(), outward_edge: OntologyOutwardEdges::ToOntology(OutwardEdge { kind: OntologyEdgeKind::ConstrainsPropertiesOn, reversed: false, - right_endpoint: OntologyTypeVertexId::from(&property_type_ref_uri), + right_endpoint: property_type_vertex_id.clone(), }), }); self.traverse_property_type( - &OntologyTypeVertexId::from(&property_type_ref_uri), + &property_type_vertex_id, dependency_context, subgraph, GraphResolveDepths { @@ -141,17 +143,20 @@ impl PostgresStore { if let Some(inherits_from_type_ref_uris) = inherits_from_type_ref_uris { for inherits_from_type_ref_uri in inherits_from_type_ref_uris { + let inherits_from_type_vertex_id = + OntologyTypeVertexId::from(inherits_from_type_ref_uri); + subgraph.edges.insert(Edge::Ontology { vertex_id: entity_type_id.clone(), outward_edge: OntologyOutwardEdges::ToOntology(OutwardEdge { kind: OntologyEdgeKind::InheritsFrom, reversed: false, - right_endpoint: OntologyTypeVertexId::from(&inherits_from_type_ref_uri), + right_endpoint: inherits_from_type_vertex_id.clone(), }), }); self.traverse_entity_type( - &OntologyTypeVertexId::from(&inherits_from_type_ref_uri), + &inherits_from_type_vertex_id, dependency_context, subgraph, GraphResolveDepths { @@ -170,17 +175,19 @@ impl PostgresStore { if let Some(link_mappings) = link_mappings { for (link_type_uri, destination_type_uris) in link_mappings { if current_resolve_depths.constrains_links_on.outgoing > 0 { + let link_type_vertex_id = OntologyTypeVertexId::from(link_type_uri); + subgraph.edges.insert(Edge::Ontology { vertex_id: entity_type_id.clone(), outward_edge: OntologyOutwardEdges::ToOntology(OutwardEdge { kind: OntologyEdgeKind::ConstrainsLinksOn, reversed: false, - right_endpoint: OntologyTypeVertexId::from(&link_type_uri), + right_endpoint: link_type_vertex_id.clone(), }), }); self.traverse_entity_type( - &OntologyTypeVertexId::from(&link_type_uri), + &link_type_vertex_id, dependency_context, subgraph, GraphResolveDepths { @@ -201,19 +208,20 @@ impl PostgresStore { > 0 { for destination_type_uri in destination_type_uris { + let destination_type_vertex_id = + OntologyTypeVertexId::from(destination_type_uri); + subgraph.edges.insert(Edge::Ontology { vertex_id: entity_type_id.clone(), outward_edge: OntologyOutwardEdges::ToOntology(OutwardEdge { kind: OntologyEdgeKind::ConstrainsLinkDestinationsOn, reversed: false, - right_endpoint: OntologyTypeVertexId::from( - &destination_type_uri, - ), + right_endpoint: destination_type_vertex_id.clone(), }), }); self.traverse_entity_type( - &OntologyTypeVertexId::from(&destination_type_uri), + &destination_type_vertex_id, dependency_context, subgraph, GraphResolveDepths { diff --git a/apps/hash-graph/lib/graph/src/store/postgres/ontology/property_type.rs b/apps/hash-graph/lib/graph/src/store/postgres/ontology/property_type.rs index 67535989411..c77cbef56af 100644 --- a/apps/hash-graph/lib/graph/src/store/postgres/ontology/property_type.rs +++ b/apps/hash-graph/lib/graph/src/store/postgres/ontology/property_type.rs @@ -88,17 +88,19 @@ impl PostgresStore { if let Some(data_type_ref_uris) = data_type_ref_uris { for data_type_ref in data_type_ref_uris { + let data_type_vertex_id = OntologyTypeVertexId::from(data_type_ref); + subgraph.edges.insert(Edge::Ontology { vertex_id: property_type_id.clone(), outward_edge: OntologyOutwardEdges::ToOntology(OutwardEdge { kind: OntologyEdgeKind::ConstrainsValuesOn, reversed: false, - right_endpoint: OntologyTypeVertexId::from(&data_type_ref), + right_endpoint: data_type_vertex_id.clone(), }), }); self.traverse_data_type( - &OntologyTypeVertexId::from(&data_type_ref), + &data_type_vertex_id, dependency_context, subgraph, GraphResolveDepths { @@ -116,17 +118,19 @@ impl PostgresStore { if let Some(property_type_ref_uris) = property_type_ref_uris { for property_type_ref_uri in property_type_ref_uris { + let property_type_vertex_id = OntologyTypeVertexId::from(property_type_ref_uri); + subgraph.edges.insert(Edge::Ontology { vertex_id: property_type_id.clone(), outward_edge: OntologyOutwardEdges::ToOntology(OutwardEdge { kind: OntologyEdgeKind::ConstrainsPropertiesOn, reversed: false, - right_endpoint: OntologyTypeVertexId::from(&property_type_ref_uri), + right_endpoint: property_type_vertex_id.clone(), }), }); self.traverse_property_type( - &OntologyTypeVertexId::from(&property_type_ref_uri), + &property_type_vertex_id, dependency_context, subgraph, GraphResolveDepths { diff --git a/apps/hash-graph/lib/graph/src/store/postgres/ontology/read.rs b/apps/hash-graph/lib/graph/src/store/postgres/ontology/read.rs index 14ae864791f..0ca51c83c36 100644 --- a/apps/hash-graph/lib/graph/src/store/postgres/ontology/read.rs +++ b/apps/hash-graph/lib/graph/src/store/postgres/ontology/read.rs @@ -113,7 +113,7 @@ where .into_report() .change_context(QueryError)?; - let record_id = OntologyTypeRecordId::new(base_uri, version); + let record_id = OntologyTypeRecordId { base_uri, version }; let provenance = ProvenanceMetadata::new(updated_by_id); Ok(T::new(record, match metadata { diff --git a/apps/hash-graph/lib/graph/src/store/postgres/query/statement/select.rs b/apps/hash-graph/lib/graph/src/store/postgres/query/statement/select.rs index dbc026feddf..8a0a60667fb 100644 --- a/apps/hash-graph/lib/graph/src/store/postgres/query/statement/select.rs +++ b/apps/hash-graph/lib/graph/src/store/postgres/query/statement/select.rs @@ -775,13 +775,13 @@ mod tests { #[test] fn for_versioned_uri() { - let uri = VersionedUri::new( - BaseUri::new( + let uri = VersionedUri { + base_uri: BaseUri::new( "https://blockprotocol.org/@blockprotocol/types/data-type/text/".to_owned(), ) .expect("invalid base uri"), - 1, - ); + version: 1, + }; let time_projection = UnresolvedTimeProjection::default().resolve(); let mut compiler = @@ -800,21 +800,21 @@ mod tests { WHERE ("ontology_id_with_metadata_0_1_0"."base_uri" = $1) AND ("ontology_id_with_metadata_0_1_0"."version" = $2) "#, &[ - &uri.base_uri().as_str(), - &OntologyTypeVersion::new(uri.version()), + &uri.base_uri.as_str(), + &OntologyTypeVersion::new(uri.version), ], ); } #[test] fn for_ontology_type_record_id() { - let uri = OntologyTypeVertexId::new( - BaseUri::new( + let uri = OntologyTypeVertexId { + base_id: BaseUri::new( "https://blockprotocol.org/@blockprotocol/types/data-type/text/".to_owned(), ) .expect("invalid base uri"), - OntologyTypeVersion::new(1), - ); + version: OntologyTypeVersion::new(1), + }; let time_projection = UnresolvedTimeProjection::default().resolve(); let mut compiler = @@ -832,16 +832,16 @@ mod tests { ON "ontology_id_with_metadata_0_1_0"."ontology_id" = "data_types_0_0_0"."ontology_id" WHERE ("ontology_id_with_metadata_0_1_0"."base_uri" = $1) AND ("ontology_id_with_metadata_0_1_0"."version" = $2) "#, - &[&uri.base_id().as_str(), &uri.version()], + &[&uri.base_id.as_str(), &uri.version], ); } #[test] fn for_entity_by_entity_id() { - let entity_id = EntityId::new( - OwnedById::new(AccountId::new(Uuid::new_v4())), - EntityUuid::new(Uuid::new_v4()), - ); + let entity_id = EntityId { + owned_by_id: OwnedById::new(AccountId::new(Uuid::new_v4())), + entity_uuid: EntityUuid::new(Uuid::new_v4()), + }; let time_projection = UnresolvedTimeProjection::default().resolve(); let kernel = time_projection.kernel().cast::(); @@ -863,18 +863,18 @@ mod tests { &[ &kernel, &time_projection.image(), - &entity_id.owned_by_id().as_uuid(), - &entity_id.entity_uuid().as_uuid(), + &entity_id.owned_by_id.as_uuid(), + &entity_id.entity_uuid.as_uuid(), ], ); } #[test] fn for_incoming_link_by_source_entity_id() { - let entity_id = EntityId::new( - OwnedById::new(AccountId::new(Uuid::new_v4())), - EntityUuid::new(Uuid::new_v4()), - ); + let entity_id = EntityId { + owned_by_id: OwnedById::new(AccountId::new(Uuid::new_v4())), + entity_uuid: EntityUuid::new(Uuid::new_v4()), + }; let time_projection = UnresolvedTimeProjection::default().resolve(); let kernel = time_projection.kernel().cast::(); @@ -896,18 +896,18 @@ mod tests { &[ &kernel, &time_projection.image(), - &entity_id.owned_by_id().as_uuid(), - &entity_id.entity_uuid().as_uuid(), + &entity_id.owned_by_id.as_uuid(), + &entity_id.entity_uuid.as_uuid(), ], ); } #[test] fn for_outgoing_link_by_source_entity_id() { - let entity_id = EntityId::new( - OwnedById::new(AccountId::new(Uuid::new_v4())), - EntityUuid::new(Uuid::new_v4()), - ); + let entity_id = EntityId { + owned_by_id: OwnedById::new(AccountId::new(Uuid::new_v4())), + entity_uuid: EntityUuid::new(Uuid::new_v4()), + }; let time_projection = UnresolvedTimeProjection::default().resolve(); let kernel = time_projection.kernel().cast::(); @@ -929,18 +929,18 @@ mod tests { &[ &kernel, &time_projection.image(), - &entity_id.owned_by_id().as_uuid(), - &entity_id.entity_uuid().as_uuid(), + &entity_id.owned_by_id.as_uuid(), + &entity_id.entity_uuid.as_uuid(), ], ); } #[test] fn for_left_entity_by_entity_id() { - let entity_id = EntityId::new( - OwnedById::new(AccountId::new(Uuid::new_v4())), - EntityUuid::new(Uuid::new_v4()), - ); + let entity_id = EntityId { + owned_by_id: OwnedById::new(AccountId::new(Uuid::new_v4())), + entity_uuid: EntityUuid::new(Uuid::new_v4()), + }; let time_projection = UnresolvedTimeProjection::default().resolve(); let kernel = time_projection.kernel().cast::(); @@ -966,18 +966,18 @@ mod tests { &[ &kernel, &time_projection.image(), - &entity_id.owned_by_id().as_uuid(), - &entity_id.entity_uuid().as_uuid(), + &entity_id.owned_by_id.as_uuid(), + &entity_id.entity_uuid.as_uuid(), ], ); } #[test] fn for_right_entity_by_entity_id() { - let entity_id = EntityId::new( - OwnedById::new(AccountId::new(Uuid::new_v4())), - EntityUuid::new(Uuid::new_v4()), - ); + let entity_id = EntityId { + owned_by_id: OwnedById::new(AccountId::new(Uuid::new_v4())), + entity_uuid: EntityUuid::new(Uuid::new_v4()), + }; let time_projection = UnresolvedTimeProjection::default().resolve(); let kernel = time_projection.kernel().cast::(); @@ -1003,8 +1003,8 @@ mod tests { &[ &kernel, &time_projection.image(), - &entity_id.owned_by_id().as_uuid(), - &entity_id.entity_uuid().as_uuid(), + &entity_id.owned_by_id.as_uuid(), + &entity_id.entity_uuid.as_uuid(), ], ); } diff --git a/apps/hash-graph/lib/graph/src/store/query/filter.rs b/apps/hash-graph/lib/graph/src/store/query/filter.rs index c6cc33c35ce..51ff762b177 100644 --- a/apps/hash-graph/lib/graph/src/store/query/filter.rs +++ b/apps/hash-graph/lib/graph/src/store/query/filter.rs @@ -87,8 +87,8 @@ where #[must_use] pub fn for_versioned_uri(versioned_uri: &'p VersionedUri) -> Self { Self::All(vec![ - Self::for_base_uri(versioned_uri.base_uri()), - Self::for_version(OntologyTypeVersion::new(versioned_uri.version())), + Self::for_base_uri(&versioned_uri.base_uri), + Self::for_version(OntologyTypeVersion::new(versioned_uri.version)), ]) } @@ -97,8 +97,8 @@ where #[must_use] pub fn for_ontology_type_vertex_id(ontology_type_vertex_id: &'p OntologyTypeVertexId) -> Self { Self::All(vec![ - Self::for_base_uri(ontology_type_vertex_id.base_id()), - Self::for_version(ontology_type_vertex_id.version()), + Self::for_base_uri(&ontology_type_vertex_id.base_id), + Self::for_version(ontology_type_vertex_id.version), ]) } } @@ -111,13 +111,13 @@ impl<'p> Filter<'p, Entity> { Self::Equal( Some(FilterExpression::Path(EntityQueryPath::OwnedById)), Some(FilterExpression::Parameter(Parameter::Uuid( - entity_id.owned_by_id().as_uuid(), + entity_id.owned_by_id.as_uuid(), ))), ), Self::Equal( Some(FilterExpression::Path(EntityQueryPath::Uuid)), Some(FilterExpression::Parameter(Parameter::Uuid( - entity_id.entity_uuid().as_uuid(), + entity_id.entity_uuid.as_uuid(), ))), ), ]) @@ -133,7 +133,7 @@ impl<'p> Filter<'p, Entity> { Box::new(EntityQueryPath::OwnedById), ))), Some(FilterExpression::Parameter(Parameter::Uuid( - entity_id.owned_by_id().as_uuid(), + entity_id.owned_by_id.as_uuid(), ))), ), Self::Equal( @@ -141,7 +141,7 @@ impl<'p> Filter<'p, Entity> { Box::new(EntityQueryPath::Uuid), ))), Some(FilterExpression::Parameter(Parameter::Uuid( - entity_id.entity_uuid().as_uuid(), + entity_id.entity_uuid.as_uuid(), ))), ), ]) @@ -157,7 +157,7 @@ impl<'p> Filter<'p, Entity> { Box::new(EntityQueryPath::OwnedById), ))), Some(FilterExpression::Parameter(Parameter::Uuid( - entity_id.owned_by_id().as_uuid(), + entity_id.owned_by_id.as_uuid(), ))), ), Self::Equal( @@ -165,7 +165,7 @@ impl<'p> Filter<'p, Entity> { Box::new(EntityQueryPath::Uuid), ))), Some(FilterExpression::Parameter(Parameter::Uuid( - entity_id.entity_uuid().as_uuid(), + entity_id.entity_uuid.as_uuid(), ))), ), ]) @@ -181,7 +181,7 @@ impl<'p> Filter<'p, Entity> { Box::new(EntityQueryPath::OwnedById), ))), Some(FilterExpression::Parameter(Parameter::Uuid( - entity_id.owned_by_id().as_uuid(), + entity_id.owned_by_id.as_uuid(), ))), ), Self::Equal( @@ -189,7 +189,7 @@ impl<'p> Filter<'p, Entity> { Box::new(EntityQueryPath::Uuid), ))), Some(FilterExpression::Parameter(Parameter::Uuid( - entity_id.entity_uuid().as_uuid(), + entity_id.entity_uuid.as_uuid(), ))), ), ]) @@ -205,7 +205,7 @@ impl<'p> Filter<'p, Entity> { Box::new(EntityQueryPath::OwnedById), ))), Some(FilterExpression::Parameter(Parameter::Uuid( - entity_id.owned_by_id().as_uuid(), + entity_id.owned_by_id.as_uuid(), ))), ), Self::Equal( @@ -213,7 +213,7 @@ impl<'p> Filter<'p, Entity> { Box::new(EntityQueryPath::Uuid), ))), Some(FilterExpression::Parameter(Parameter::Uuid( - entity_id.entity_uuid().as_uuid(), + entity_id.entity_uuid.as_uuid(), ))), ), ]) @@ -440,23 +440,23 @@ mod tests { #[test] fn for_versioned_uri() { - let uri = VersionedUri::new( - BaseUri::new( + let uri = VersionedUri { + base_uri: BaseUri::new( "https://blockprotocol.org/@blockprotocol/types/data-type/text/".to_owned(), ) .expect("invalid base uri"), - 1, - ); + version: 1, + }; let expected = json! {{ "all": [ { "equal": [ { "path": ["baseUri"] }, - { "parameter": uri.base_uri() } + { "parameter": uri.base_uri } ]}, { "equal": [ { "path": ["version"] }, - { "parameter": uri.version() } + { "parameter": uri.version } ]} ] }}; @@ -469,23 +469,23 @@ mod tests { #[test] fn for_ontology_type_version_id() { - let uri = OntologyTypeVertexId::new( - BaseUri::new( + let uri = OntologyTypeVertexId { + base_id: BaseUri::new( "https://blockprotocol.org/@blockprotocol/types/data-type/text/".to_owned(), ) .expect("invalid base uri"), - OntologyTypeVersion::new(1), - ); + version: OntologyTypeVersion::new(1), + }; let expected = json! {{ "all": [ { "equal": [ { "path": ["baseUri"] }, - { "parameter": uri.base_id() } + { "parameter": uri.base_id } ]}, { "equal": [ { "path": ["version"] }, - { "parameter": uri.version() } + { "parameter": uri.version } ]} ] }}; @@ -498,20 +498,20 @@ mod tests { #[test] fn for_entity_by_entity_id() { - let entity_id = EntityId::new( - OwnedById::new(AccountId::new(Uuid::new_v4())), - EntityUuid::new(Uuid::new_v4()), - ); + let entity_id = EntityId { + owned_by_id: OwnedById::new(AccountId::new(Uuid::new_v4())), + entity_uuid: EntityUuid::new(Uuid::new_v4()), + }; let expected = json! {{ "all": [ { "equal": [ { "path": ["ownedById"] }, - { "parameter": entity_id.owned_by_id() } + { "parameter": entity_id.owned_by_id } ]}, { "equal": [ { "path": ["uuid"] }, - { "parameter": entity_id.entity_uuid() } + { "parameter": entity_id.entity_uuid } ]} ] }}; @@ -521,20 +521,20 @@ mod tests { #[test] fn for_entity_by_id() { - let entity_id = EntityId::new( - OwnedById::new(AccountId::new(Uuid::new_v4())), - EntityUuid::new(Uuid::new_v4()), - ); + let entity_id = EntityId { + owned_by_id: OwnedById::new(AccountId::new(Uuid::new_v4())), + entity_uuid: EntityUuid::new(Uuid::new_v4()), + }; let expected = json! {{ "all": [ { "equal": [ { "path": ["ownedById"] }, - { "parameter": entity_id.owned_by_id() } + { "parameter": entity_id.owned_by_id } ]}, { "equal": [ { "path": ["uuid"] }, - { "parameter": entity_id.entity_uuid() } + { "parameter": entity_id.entity_uuid } ]} ] }}; @@ -544,20 +544,20 @@ mod tests { #[test] fn for_outgoing_link_by_source_entity_id() { - let entity_id = EntityId::new( - OwnedById::new(AccountId::new(Uuid::new_v4())), - EntityUuid::new(Uuid::new_v4()), - ); + let entity_id = EntityId { + owned_by_id: OwnedById::new(AccountId::new(Uuid::new_v4())), + entity_uuid: EntityUuid::new(Uuid::new_v4()), + }; let expected = json! {{ "all": [ { "equal": [ { "path": ["leftEntity", "ownedById"] }, - { "parameter": entity_id.owned_by_id() } + { "parameter": entity_id.owned_by_id } ]}, { "equal": [ { "path": ["leftEntity", "uuid"] }, - { "parameter": entity_id.entity_uuid() } + { "parameter": entity_id.entity_uuid } ]} ] }}; @@ -570,20 +570,20 @@ mod tests { #[test] fn for_left_entity_by_entity_id() { - let entity_id = EntityId::new( - OwnedById::new(AccountId::new(Uuid::new_v4())), - EntityUuid::new(Uuid::new_v4()), - ); + let entity_id = EntityId { + owned_by_id: OwnedById::new(AccountId::new(Uuid::new_v4())), + entity_uuid: EntityUuid::new(Uuid::new_v4()), + }; let expected = json! {{ "all": [ { "equal": [ { "path": ["outgoingLinks", "ownedById"] }, - { "parameter": entity_id.owned_by_id() } + { "parameter": entity_id.owned_by_id } ]}, { "equal": [ { "path": ["outgoingLinks", "uuid"] }, - { "parameter": entity_id.entity_uuid() } + { "parameter": entity_id.entity_uuid } ]} ] }}; @@ -593,20 +593,20 @@ mod tests { #[test] fn for_right_entity_by_entity_id() { - let entity_id = EntityId::new( - OwnedById::new(AccountId::new(Uuid::new_v4())), - EntityUuid::new(Uuid::new_v4()), - ); + let entity_id = EntityId { + owned_by_id: OwnedById::new(AccountId::new(Uuid::new_v4())), + entity_uuid: EntityUuid::new(Uuid::new_v4()), + }; let expected = json! {{ "all": [ { "equal": [ { "path": ["incomingLinks", "ownedById"] }, - { "parameter": entity_id.owned_by_id() } + { "parameter": entity_id.owned_by_id } ]}, { "equal": [ { "path": ["incomingLinks", "uuid"] }, - { "parameter": entity_id.entity_uuid() } + { "parameter": entity_id.entity_uuid } ]} ] }}; diff --git a/apps/hash-graph/lib/type-fetcher/Cargo.toml b/apps/hash-graph/lib/type-fetcher/Cargo.toml index d571a915528..680608e131b 100644 --- a/apps/hash-graph/lib/type-fetcher/Cargo.toml +++ b/apps/hash-graph/lib/type-fetcher/Cargo.toml @@ -7,7 +7,7 @@ description = "RPC service definition to fetch external BP types" [dependencies] error-stack = { version = "0.3.1", features = ["spantrace"] } -type-system = { git = "https://github.com/blockprotocol/blockprotocol", rev = "646b7d1" } +type-system = { git = "https://github.com/blockprotocol/blockprotocol", rev = "adab205" } serde = { version = "1.0.152", features = ["derive"] } serde_json = "1.0.91" diff --git a/apps/hash-graph/tests/integration/Cargo.toml b/apps/hash-graph/tests/integration/Cargo.toml index 1fae402d341..2564d49a742 100644 --- a/apps/hash-graph/tests/integration/Cargo.toml +++ b/apps/hash-graph/tests/integration/Cargo.toml @@ -16,7 +16,7 @@ serde_json = "1.0.91" time = "0.3.17" tokio = { version = "1.25.0", features = ["rt-multi-thread", "macros"] } tokio-postgres = { version = "0.7.7", default-features = false } -type-system = { git = "https://github.com/blockprotocol/blockprotocol", rev = "646b7d1" } +type-system = { git = "https://github.com/blockprotocol/blockprotocol", rev = "adab205" } uuid = { version = "1.3.0", features = ["v4", "serde"] } [[test]] diff --git a/apps/hash-graph/tests/integration/postgres/entity.rs b/apps/hash-graph/tests/integration/postgres/entity.rs index b983a77f3dc..5195974a686 100644 --- a/apps/hash-graph/tests/integration/postgres/entity.rs +++ b/apps/hash-graph/tests/integration/postgres/entity.rs @@ -22,25 +22,25 @@ async fn insert() { let metadata = api .create_entity( person.clone(), - VersionedUri::new( - BaseUri::new( + VersionedUri { + base_uri: BaseUri::new( "https://blockprotocol.org/@alice/types/entity-type/person/".to_owned(), ) .expect("couldn't construct Base URI"), - 1, - ), + version: 1, + }, None, ) .await .expect("could not create entity"); let entities = api - .get_entities(metadata.record_id().entity_id()) + .get_entities(metadata.record_id().entity_id) .await .expect("could not get entity"); assert_eq!(entities.len(), 1); - assert_eq!(entities[0].properties(), &person); + assert_eq!(entities[0].properties, person); } #[tokio::test] @@ -59,25 +59,25 @@ async fn query() { let metadata = api .create_entity( organization.clone(), - VersionedUri::new( - BaseUri::new( + VersionedUri { + base_uri: BaseUri::new( "https://blockprotocol.org/@alice/types/entity-type/organization/".to_owned(), ) .expect("couldn't construct Base URI"), - 1, - ), + version: 1, + }, None, ) .await .expect("could not create entity"); let queried_organizations = api - .get_entities(metadata.record_id().entity_id()) + .get_entities(metadata.record_id().entity_id) .await .expect("could not get entity"); assert_eq!(queried_organizations.len(), 1); - assert_eq!(queried_organizations[0].properties(), &organization); + assert_eq!(queried_organizations[0].properties, organization); } #[tokio::test] @@ -98,11 +98,13 @@ async fn update() { let v1_metadata = api .create_entity( page_v1.clone(), - VersionedUri::new( - BaseUri::new("https://blockprotocol.org/@alice/types/entity-type/page/".to_owned()) - .expect("couldn't construct Base URI"), - 1, - ), + VersionedUri { + base_uri: BaseUri::new( + "https://blockprotocol.org/@alice/types/entity-type/page/".to_owned(), + ) + .expect("couldn't construct Base URI"), + version: 1, + }, None, ) .await @@ -110,48 +112,53 @@ async fn update() { let v2_metadata = api .update_entity( - v1_metadata.record_id().entity_id(), + v1_metadata.record_id().entity_id, page_v2.clone(), - VersionedUri::new( - BaseUri::new("https://blockprotocol.org/@alice/types/entity-type/page/".to_owned()) - .expect("couldn't construct Base URI"), - 1, - ), - EntityLinkOrder::new(None, None), + VersionedUri { + base_uri: BaseUri::new( + "https://blockprotocol.org/@alice/types/entity-type/page/".to_owned(), + ) + .expect("couldn't construct Base URI"), + version: 1, + }, + EntityLinkOrder { + left_to_right: None, + right_to_left: None, + }, ) .await .expect("could not update entity"); let entities = api - .get_entities(v2_metadata.record_id().entity_id()) + .get_entities(v2_metadata.record_id().entity_id) .await .expect("could not get entity"); assert_eq!(entities.len(), 2); let entity_v2 = api - .get_latest_entity(v2_metadata.record_id().entity_id()) + .get_latest_entity(v2_metadata.record_id().entity_id) .await .expect("could not get entity"); - assert_eq!(entity_v2.properties(), &page_v2); + assert_eq!(entity_v2.properties, page_v2); let entity_v1 = api .get_entity_by_timestamp( - v1_metadata.record_id().entity_id(), + v1_metadata.record_id().entity_id, (*v1_metadata.version().decision_time.start()).into(), ) .await .expect("could not get entity"); - assert_eq!(entity_v1.properties(), &page_v1); + assert_eq!(entity_v1.properties, page_v1); let entity_v2 = api .get_entity_by_timestamp( - v2_metadata.record_id().entity_id(), + v2_metadata.record_id().entity_id, (*v2_metadata.version().decision_time.start()).into(), ) .await .expect("could not get entity"); - assert_eq!(entity_v2.properties(), &page_v2); + assert_eq!(entity_v2.properties, page_v2); } diff --git a/apps/hash-graph/tests/integration/postgres/lib.rs b/apps/hash-graph/tests/integration/postgres/lib.rs index a04817b9cb7..506e0766751 100644 --- a/apps/hash-graph/tests/integration/postgres/lib.rs +++ b/apps/hash-graph/tests/integration/postgres/lib.rs @@ -123,7 +123,7 @@ impl DatabaseTestWrapper { let data_type = DataType::try_from(data_type_repr).expect("could not parse data type"); let metadata = OntologyElementMetadata::Owned(OwnedOntologyElementMetadata::new( - data_type.id().into(), + data_type.id().clone().into(), ProvenanceMetadata::new(UpdatedById::new(account_id)), OwnedById::new(account_id), )); @@ -139,7 +139,7 @@ impl DatabaseTestWrapper { PropertyType::try_from(property_type_repr).expect("could not parse property type"); let metadata = OntologyElementMetadata::Owned(OwnedOntologyElementMetadata::new( - property_type.id().into(), + property_type.id().clone().into(), ProvenanceMetadata::new(UpdatedById::new(account_id)), OwnedById::new(account_id), )); @@ -155,7 +155,7 @@ impl DatabaseTestWrapper { EntityType::try_from(entity_type_repr).expect("could not parse entity type"); let metadata = OntologyElementMetadata::Owned(OwnedOntologyElementMetadata::new( - entity_type.id().into(), + entity_type.id().clone().into(), ProvenanceMetadata::new(UpdatedById::new(account_id)), OwnedById::new(account_id), )); @@ -188,7 +188,7 @@ impl DatabaseApi<'_> { data_type: DataType, ) -> Result { let metadata = OntologyElementMetadata::Owned(OwnedOntologyElementMetadata::new( - data_type.id().into(), + data_type.id().clone().into(), ProvenanceMetadata::new(UpdatedById::new(self.account_id)), OwnedById::new(self.account_id), )); @@ -215,7 +215,7 @@ impl DatabaseApi<'_> { .await? .vertices .data_types - .remove(&OntologyTypeVertexId::from(uri)) + .remove(&OntologyTypeVertexId::from(uri.clone())) .expect("no data type found")) } @@ -233,7 +233,7 @@ impl DatabaseApi<'_> { property_type: PropertyType, ) -> Result { let metadata = OntologyElementMetadata::Owned(OwnedOntologyElementMetadata::new( - property_type.id().into(), + property_type.id().clone().into(), ProvenanceMetadata::new(UpdatedById::new(self.account_id)), OwnedById::new(self.account_id), )); @@ -262,7 +262,7 @@ impl DatabaseApi<'_> { .await? .vertices .property_types - .remove(&OntologyTypeVertexId::from(uri)) + .remove(&OntologyTypeVertexId::from(uri.clone())) .expect("no property type found")) } @@ -280,7 +280,7 @@ impl DatabaseApi<'_> { entity_type: EntityType, ) -> Result { let metadata = OntologyElementMetadata::Owned(OwnedOntologyElementMetadata::new( - entity_type.id().into(), + entity_type.id().clone().into(), ProvenanceMetadata::new(UpdatedById::new(self.account_id)), OwnedById::new(self.account_id), )); @@ -309,7 +309,7 @@ impl DatabaseApi<'_> { .await? .vertices .entity_types - .remove(&OntologyTypeVertexId::from(uri)) + .remove(&OntologyTypeVertexId::from(uri.clone())) .expect("no entity type found")) } @@ -444,7 +444,14 @@ impl DatabaseApi<'_> { false, entity_type_id, properties, - Some(LinkData::new(left_entity_id, right_entity_id, None, None)), + Some(LinkData { + left_entity_id, + right_entity_id, + order: EntityLinkOrder { + left_to_right: None, + right_to_left: None, + }, + }), ) .await } @@ -460,7 +467,7 @@ impl DatabaseApi<'_> { Box::new(EntityQueryPath::Uuid), ))), Some(FilterExpression::Parameter(Parameter::Uuid( - source_entity_id.entity_uuid().as_uuid(), + source_entity_id.entity_uuid.as_uuid(), ))), ), Filter::Equal( @@ -468,7 +475,7 @@ impl DatabaseApi<'_> { Box::new(EntityQueryPath::OwnedById), ))), Some(FilterExpression::Parameter(Parameter::Uuid( - source_entity_id.owned_by_id().as_uuid(), + source_entity_id.owned_by_id.as_uuid(), ))), ), Filter::Equal( @@ -476,7 +483,7 @@ impl DatabaseApi<'_> { EntityTypeQueryPath::BaseUri, ))), Some(FilterExpression::Parameter(Parameter::Text(Cow::Borrowed( - link_type_id.base_uri().as_str(), + link_type_id.base_uri.as_str(), )))), ), Filter::Equal( @@ -484,7 +491,7 @@ impl DatabaseApi<'_> { EntityTypeQueryPath::Version, ))), Some(FilterExpression::Parameter(Parameter::OntologyTypeVersion( - OntologyTypeVersion::new(link_type_id.version()), + OntologyTypeVersion::new(link_type_id.version), ))), ), ]); @@ -528,7 +535,7 @@ impl DatabaseApi<'_> { Box::new(EntityQueryPath::Uuid), ))), Some(FilterExpression::Parameter(Parameter::Uuid( - source_entity_id.entity_uuid().as_uuid(), + source_entity_id.entity_uuid.as_uuid(), ))), ), Filter::Equal( @@ -536,7 +543,7 @@ impl DatabaseApi<'_> { Box::new(EntityQueryPath::OwnedById), ))), Some(FilterExpression::Parameter(Parameter::Uuid( - source_entity_id.owned_by_id().as_uuid(), + source_entity_id.owned_by_id.as_uuid(), ))), ), Filter::Equal( diff --git a/apps/hash-graph/tests/integration/postgres/links.rs b/apps/hash-graph/tests/integration/postgres/links.rs index 60ab90b08c9..b6b4a47294b 100644 --- a/apps/hash-graph/tests/integration/postgres/links.rs +++ b/apps/hash-graph/tests/integration/postgres/links.rs @@ -20,11 +20,13 @@ async fn insert() { .await .expect("could not seed database"); - let person_type_id = VersionedUri::new( - BaseUri::new("https://blockprotocol.org/@alice/types/entity-type/person/".to_owned()) - .expect("couldn't construct Base URI"), - 1, - ); + let person_type_id = VersionedUri { + base_uri: BaseUri::new( + "https://blockprotocol.org/@alice/types/entity-type/person/".to_owned(), + ) + .expect("couldn't construct Base URI"), + version: 1, + }; let alice_metadata = api .create_entity(alice, person_type_id.clone(), None) @@ -36,35 +38,37 @@ async fn insert() { .await .expect("could not create entity"); - let friend_of_type_id = VersionedUri::new( - BaseUri::new("https://blockprotocol.org/@alice/types/entity-type/friend-of/".to_owned()) - .expect("couldn't construct Base URI"), - 1, - ); + let friend_of_type_id = VersionedUri { + base_uri: BaseUri::new( + "https://blockprotocol.org/@alice/types/entity-type/friend-of/".to_owned(), + ) + .expect("couldn't construct Base URI"), + version: 1, + }; api.create_link_entity( friend_of, friend_of_type_id.clone(), None, - alice_metadata.record_id().entity_id(), - bob_metadata.record_id().entity_id(), + alice_metadata.record_id().entity_id, + bob_metadata.record_id().entity_id, ) .await .expect("could not create link"); let link_entity = api - .get_link_entity_target(alice_metadata.record_id().entity_id(), friend_of_type_id) + .get_link_entity_target(alice_metadata.record_id().entity_id, friend_of_type_id) .await .expect("could not fetch entity"); - let link_data = link_entity.link_data().expect("entity is not a link"); + let link_data = link_entity.link_data.expect("entity is not a link"); assert_eq!( - link_data.left_entity_id(), - alice_metadata.record_id().entity_id() + link_data.left_entity_id, + alice_metadata.record_id().entity_id ); assert_eq!( - link_data.right_entity_id(), - bob_metadata.record_id().entity_id() + link_data.right_entity_id, + bob_metadata.record_id().entity_id ); } @@ -85,25 +89,29 @@ async fn get_entity_links() { .await .expect("could not seed database"); - let person_type_id = VersionedUri::new( - BaseUri::new("https://blockprotocol.org/@alice/types/entity-type/person/".to_owned()) - .expect("couldn't construct Base URI"), - 1, - ); + let person_type_id = VersionedUri { + base_uri: BaseUri::new( + "https://blockprotocol.org/@alice/types/entity-type/person/".to_owned(), + ) + .expect("couldn't construct Base URI"), + version: 1, + }; - let friend_link_type_id = VersionedUri::new( - BaseUri::new("https://blockprotocol.org/@alice/types/entity-type/friend-of/".to_owned()) - .expect("couldn't construct Base URI"), - 1, - ); + let friend_link_type_id = VersionedUri { + base_uri: BaseUri::new( + "https://blockprotocol.org/@alice/types/entity-type/friend-of/".to_owned(), + ) + .expect("couldn't construct Base URI"), + version: 1, + }; - let acquaintance_entity_link_type_id = VersionedUri::new( - BaseUri::new( + let acquaintance_entity_link_type_id = VersionedUri { + base_uri: BaseUri::new( "https://blockprotocol.org/@alice/types/entity-type/acquaintance-of/".to_owned(), ) .expect("couldn't construct Base URI"), - 1, - ); + version: 1, + }; let alice_metadata = api .create_entity(alice, person_type_id.clone(), None) @@ -124,8 +132,8 @@ async fn get_entity_links() { EntityProperties::empty(), friend_link_type_id.clone(), None, - alice_metadata.record_id().entity_id(), - bob_metadata.record_id().entity_id(), + alice_metadata.record_id().entity_id, + bob_metadata.record_id().entity_id, ) .await .expect("could not create link"); @@ -134,47 +142,47 @@ async fn get_entity_links() { EntityProperties::empty(), acquaintance_entity_link_type_id.clone(), None, - alice_metadata.record_id().entity_id(), - charles_metadata.record_id().entity_id(), + alice_metadata.record_id().entity_id, + charles_metadata.record_id().entity_id, ) .await .expect("could not create link"); let links_from_source = api - .get_latest_entity_links(alice_metadata.record_id().entity_id()) + .get_latest_entity_links(alice_metadata.record_id().entity_id) .await .expect("could not fetch link"); assert!( links_from_source .iter() - .any(|link_entity| link_entity.metadata().entity_type_id() == &friend_link_type_id) + .any(|link_entity| link_entity.metadata.entity_type_id() == &friend_link_type_id) ); assert!( links_from_source .iter() - .any(|link_entity| link_entity.metadata().entity_type_id() + .any(|link_entity| link_entity.metadata.entity_type_id() == &acquaintance_entity_link_type_id) ); let link_datas = links_from_source .iter() - .map(|entity| entity.link_data().expect("entity is not a link")) + .map(|entity| entity.link_data.expect("entity is not a link")) .collect::>(); assert!( link_datas .iter() - .any(|link_data| link_data.left_entity_id() == alice_metadata.record_id().entity_id()) + .any(|link_data| link_data.left_entity_id == alice_metadata.record_id().entity_id) ); assert!( link_datas .iter() - .any(|link_data| link_data.right_entity_id() == bob_metadata.record_id().entity_id()) + .any(|link_data| link_data.right_entity_id == bob_metadata.record_id().entity_id) ); assert!( - link_datas.iter().any( - |link_data| link_data.right_entity_id() == charles_metadata.record_id().entity_id() - ) + link_datas + .iter() + .any(|link_data| link_data.right_entity_id == charles_metadata.record_id().entity_id) ); } @@ -193,17 +201,21 @@ async fn remove_link() { .await .expect("could not seed database"); - let person_type_id = VersionedUri::new( - BaseUri::new("https://blockprotocol.org/@alice/types/entity-type/person/".to_owned()) - .expect("couldn't construct Base URI"), - 1, - ); + let person_type_id = VersionedUri { + base_uri: BaseUri::new( + "https://blockprotocol.org/@alice/types/entity-type/person/".to_owned(), + ) + .expect("couldn't construct Base URI"), + version: 1, + }; - let friend_link_type_id = VersionedUri::new( - BaseUri::new("https://blockprotocol.org/@alice/types/entity-type/friend-of/".to_owned()) - .expect("couldn't construct Base URI"), - 1, - ); + let friend_link_type_id = VersionedUri { + base_uri: BaseUri::new( + "https://blockprotocol.org/@alice/types/entity-type/friend-of/".to_owned(), + ) + .expect("couldn't construct Base URI"), + version: 1, + }; let alice_metadata = api .create_entity(alice, person_type_id.clone(), None) @@ -220,30 +232,33 @@ async fn remove_link() { EntityProperties::empty(), friend_link_type_id.clone(), None, - alice_metadata.record_id().entity_id(), - bob_metadata.record_id().entity_id(), + alice_metadata.record_id().entity_id, + bob_metadata.record_id().entity_id, ) .await .expect("could not create link"); assert!( - !api.get_latest_entity_links(alice_metadata.record_id().entity_id()) + !api.get_latest_entity_links(alice_metadata.record_id().entity_id) .await .expect("could not fetch links") .is_empty() ); api.archive_entity( - link_entity_metadata.record_id().entity_id(), + link_entity_metadata.record_id().entity_id, EntityProperties::empty(), friend_link_type_id, - EntityLinkOrder::new(None, None), + EntityLinkOrder { + left_to_right: None, + right_to_left: None, + }, ) .await .expect("could not remove link"); assert!( - api.get_latest_entity_links(alice_metadata.record_id().entity_id()) + api.get_latest_entity_links(alice_metadata.record_id().entity_id) .await .expect("could not fetch links") .is_empty() diff --git a/libs/@local/hash-graph-client/api.ts b/libs/@local/hash-graph-client/api.ts index d6956376125..e0411fe6a9b 100644 --- a/libs/@local/hash-graph-client/api.ts +++ b/libs/@local/hash-graph-client/api.ts @@ -905,12 +905,6 @@ export type Filter = */ export type FilterExpression = ParameterExpression | PathExpression; -/** - * @type GraphElementId - * @export - */ -export type GraphElementId = string; - /** * @type GraphElementVertexId * @export