Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make fields on common structs pub #2081

Merged
merged 19 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/hash-graph/Cargo.lock

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

2 changes: 1 addition & 1 deletion apps/hash-graph/bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
18 changes: 10 additions & 8 deletions apps/hash-graph/bench/read_scaling/knowledge/complete/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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,
)
})
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
20 changes: 11 additions & 9 deletions apps/hash-graph/bench/representative_read/seed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down Expand Up @@ -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,
)
}),
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions apps/hash-graph/bench/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ pub async fn seed<D, P, E, C>(
.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),
)),
Expand Down Expand Up @@ -232,7 +232,7 @@ pub async fn seed<D, P, E, C>(
.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),
)),
Expand Down Expand Up @@ -263,7 +263,7 @@ pub async fn seed<D, P, E, C>(
.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),
)),
Expand Down
2 changes: 1 addition & 1 deletion apps/hash-graph/bin/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
60 changes: 30 additions & 30 deletions apps/hash-graph/bin/cli/src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,83 +98,83 @@ async fn stop_gap_setup(pool: &PostgresStorePool<NoTls>) -> 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(),
HashMap::default(),
);

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(),
HashMap::default(),
);

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(),
HashMap::default(),
);

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(),
HashMap::default(),
);

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(),
HashMap::default(),
);

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(),
Expand Down Expand Up @@ -212,7 +212,7 @@ async fn stop_gap_setup(pool: &PostgresStorePool<NoTls>) -> 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(),
));
Expand All @@ -232,13 +232,13 @@ async fn stop_gap_setup(pool: &PostgresStorePool<NoTls>) -> 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"),
Expand All @@ -250,7 +250,7 @@ async fn stop_gap_setup(pool: &PostgresStorePool<NoTls>) -> 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(),
));
Expand Down
2 changes: 1 addition & 1 deletion apps/hash-graph/lib/graph/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions apps/hash-graph/lib/graph/src/api/rest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use crate::{
UnresolvedTransactionTimeImage, UnresolvedTransactionTimeKernel,
UnresolvedTransactionTimeProjection,
},
EntityVertexId, GraphElementId, GraphElementVertexId, OntologyTypeVertexId,
EntityVertexId, GraphElementVertexId, OntologyTypeVertexId,
},
ontology::{
domain_validator::DomainValidator, ExternalOntologyElementMetadata,
Expand Down Expand Up @@ -186,7 +186,6 @@ async fn serve_static_schema(Path(path): Path<String>) -> Result<Response, Statu
OntologyTypeVersion,
Selector,

GraphElementId,
GraphElementVertexId,
OntologyVertex,
KnowledgeGraphVertex,
Expand Down
11 changes: 4 additions & 7 deletions apps/hash-graph/lib/graph/src/api/rest/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async fn create_data_type<P: StorePool + Send>(
})?;

let metadata = OntologyElementMetadata::Owned(OwnedOntologyElementMetadata::new(
data_type.id().into(),
data_type.id().clone().into(),
ProvenanceMetadata::new(actor_id),
owned_by_id,
));
Expand Down Expand Up @@ -204,16 +204,13 @@ async fn update_data_type<P: StorePool + Send>(
) -> Result<Json<OntologyElementMetadata>, 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
Expand Down
11 changes: 4 additions & 7 deletions apps/hash-graph/lib/graph/src/api/rest/entity_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ async fn create_entity_type<P: StorePool + Send>(
})?;

let metadata = OntologyElementMetadata::Owned(OwnedOntologyElementMetadata::new(
entity_type.id().into(),
entity_type.id().clone().into(),
ProvenanceMetadata::new(actor_id),
owned_by_id,
));
Expand Down Expand Up @@ -213,16 +213,13 @@ async fn update_entity_type<P: StorePool + Send>(
) -> Result<Json<OntologyElementMetadata>, 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
Expand Down
11 changes: 4 additions & 7 deletions apps/hash-graph/lib/graph/src/api/rest/property_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ async fn create_property_type<P: StorePool + Send>(
})?;

let metadata = OntologyElementMetadata::Owned(OwnedOntologyElementMetadata::new(
property_type.id().into(),
property_type.id().clone().into(),
ProvenanceMetadata::new(actor_id),
owned_by_id,
));
Expand Down Expand Up @@ -211,16 +211,13 @@ async fn update_property_type<P: StorePool + Send>(
) -> Result<Json<OntologyElementMetadata>, 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
Expand Down
Loading