Skip to content

Commit

Permalink
H-2961: Introduce a ClosedDataType schema type and store it in the …
Browse files Browse the repository at this point in the history
…database (#4692)
  • Loading branch information
TimDiekmann authored Jul 12, 2024
1 parent d9d48d1 commit e3c05fe
Show file tree
Hide file tree
Showing 73 changed files with 575 additions and 314 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
ValueOrArray,
VersionedUrl,
} from "@blockprotocol/type-system";
import { extractVersion } from "@blockprotocol/type-system";
import { atLeastOne, extractVersion } from "@blockprotocol/type-system";
import { typedEntries } from "@local/advanced-types/typed-entries";
import type {
BaseUrl,
Expand Down Expand Up @@ -163,16 +163,20 @@ const dereferencePropertyTypeValue = (params: {
return accumulator;
}, {}),
required: simplifyPropertyKeys
? valueReference.required?.map((requiredPropertyBaseUrl) => {
const simplifiedPropertyId = Object.entries(
simplifiedPropertyTypeMappings,
).find(
([_, propertyBaseUrl]) =>
propertyBaseUrl === requiredPropertyBaseUrl,
)?.[0];

return simplifiedPropertyId ?? requiredPropertyBaseUrl;
})
? valueReference.required
? atLeastOne(
valueReference.required.map((requiredPropertyBaseUrl) => {
const simplifiedPropertyId = Object.entries(
simplifiedPropertyTypeMappings,
).find(
([_, propertyBaseUrl]) =>
propertyBaseUrl === requiredPropertyBaseUrl,
)?.[0];

return simplifiedPropertyId ?? requiredPropertyBaseUrl;
}),
)
: undefined
: valueReference.required,
type: "object",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,9 @@ export const generateSystemPropertyTypeSchema = (
> = {
type: "object" as const,
properties: propertyTypeObjectProperties,
required: propertyTypeObjectRequiredProperties ?? [],
required: propertyTypeObjectRequiredProperties
? atLeastOne(propertyTypeObjectRequiredProperties)
: undefined,
};
inner = propertyTypeObject;
} else {
Expand Down Expand Up @@ -715,7 +717,7 @@ export const generateSystemEntityTypeSchema = (
description: params.description,
type: "object",
properties,
required: requiredProperties,
required: requiredProperties ? atLeastOne(requiredProperties) : undefined,
links,
};
};
Expand Down
2 changes: 1 addition & 1 deletion apps/hash-graph/libs/api/src/rest/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ use serde::{Deserialize, Serialize};
use temporal_client::TemporalClient;
use time::OffsetDateTime;
use type_system::{
schema::DataType,
url::{OntologyTypeVersion, VersionedUrl},
DataType,
};
use utoipa::{OpenApi, ToSchema};

Expand Down
2 changes: 1 addition & 1 deletion apps/hash-graph/libs/api/src/rest/entity_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ use serde::{Deserialize, Serialize};
use temporal_client::TemporalClient;
use time::OffsetDateTime;
use type_system::{
schema::EntityType,
url::{BaseUrl, OntologyTypeVersion, VersionedUrl},
EntityType,
};
use utoipa::{OpenApi, ToSchema};

Expand Down
2 changes: 1 addition & 1 deletion apps/hash-graph/libs/api/src/rest/property_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ use serde::{Deserialize, Serialize};
use temporal_client::TemporalClient;
use time::OffsetDateTime;
use type_system::{
schema::PropertyType,
url::{OntologyTypeVersion, VersionedUrl},
PropertyType,
};
use utoipa::{OpenApi, ToSchema};

Expand Down
2 changes: 1 addition & 1 deletion apps/hash-graph/libs/api/src/rest/utoipa_typedef/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub(crate) mod subgraph;

use graph_types::ontology::{DataTypeMetadata, EntityTypeMetadata, PropertyTypeMetadata};
use serde::{Deserialize, Serialize};
use type_system::{DataType, EntityType, PropertyType};
use type_system::schema::{DataType, EntityType, PropertyType};
use utoipa::{
openapi::{OneOfBuilder, Ref, RefOr, Schema},
ToSchema,
Expand Down
6 changes: 3 additions & 3 deletions apps/hash-graph/libs/graph/src/knowledge/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ pub enum EntityQueryPath<'p> {
/// instead.
///
/// [`BaseUrl`]: type_system::url::BaseUrl
/// [`EntityType`]: type_system::EntityType
/// [`EntityType`]: type_system::schema::EntityType
/// [`EntityTypeEdge`]: Self::EntityTypeEdge
TypeBaseUrls,
/// The list of [`EntityType`]s' versions belonging to the [`Entity`].
///
/// It's currently not possible to query for the list of types directly. Use [`EntityTypeEdge`]
/// instead.
///
/// [`EntityType`]: type_system::EntityType
/// [`EntityType`]: type_system::schema::EntityType
/// [`EntityTypeEdge`]: Self::EntityTypeEdge
TypeVersions,
/// The confidence value for the [`Entity`].
Expand Down Expand Up @@ -188,7 +188,7 @@ pub enum EntityQueryPath<'p> {
/// # Ok::<(), serde_json::Error>(())
/// ```
///
/// [`EntityType`]: type_system::PropertyType
/// [`EntityType`]: type_system::schema::PropertyType
EntityTypeEdge {
edge_kind: SharedEdgeKind,
path: EntityTypeQueryPath<'p>,
Expand Down
24 changes: 12 additions & 12 deletions apps/hash-graph/libs/graph/src/ontology/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
/// single field. This means, that the path currently will always be a sequence with only one
/// element.
///
/// [`DataType`]: type_system::DataType
/// [`DataType`]: type_system::schema::DataType
// TODO: Adjust enum and docs when adding non-primitive data types
// see https://linear.app/hash/issue/BP-104
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
Expand All @@ -35,7 +35,7 @@ pub enum DataTypeQueryPath<'p> {
/// # Ok::<(), serde_json::Error>(())
/// ```
///
/// [`DataType`]: type_system::DataType
/// [`DataType`]: type_system::schema::DataType
/// [`BaseUrl`]: type_system::url::BaseUrl
BaseUrl,
/// The version of the [`DataType`].
Expand Down Expand Up @@ -69,7 +69,7 @@ pub enum DataTypeQueryPath<'p> {
/// # Ok::<(), serde_json::Error>(())
/// ```
///
/// [`DataType`]: type_system::DataType
/// [`DataType`]: type_system::schema::DataType
Version,
/// The [`VersionedUrl`] of the [`DataType`].
///
Expand All @@ -83,14 +83,14 @@ pub enum DataTypeQueryPath<'p> {
/// ```
///
/// [`VersionedUrl`]: type_system::url::VersionedUrl
/// [`DataType`]: type_system::DataType
/// [`DataType`]: type_system::schema::DataType
VersionedUrl,
/// The transaction time of the [`DataType`].
///
/// It's not possible to query for the temporal axis directly, this has to be done via the
/// `temporalAxes` parameter on the request.
///
/// [`DataType`]: type_system::DataType
/// [`DataType`]: type_system::schema::DataType
TransactionTime,
/// The [`OwnedById`] of the [`DataTypeMetadata`] belonging to the [`DataType`].
///
Expand All @@ -103,7 +103,7 @@ pub enum DataTypeQueryPath<'p> {
/// # Ok::<(), serde_json::Error>(())
/// ```
///
/// [`DataType`]: type_system::DataType
/// [`DataType`]: type_system::schema::DataType
/// [`OwnedById`]: graph_types::owned_by_id::OwnedById
/// [`DataTypeMetadata`]: graph_types::ontology::DataTypeMetadata
OwnedById,
Expand All @@ -118,7 +118,7 @@ pub enum DataTypeQueryPath<'p> {
/// # Ok::<(), serde_json::Error>(())
/// ```
///
/// [`DataType::title()`]: type_system::DataType::title
/// [`DataType::title()`]: type_system::schema::DataType::title
Title,
/// Corresponds to [`DataType::description()`]
///
Expand All @@ -131,7 +131,7 @@ pub enum DataTypeQueryPath<'p> {
/// # Ok::<(), serde_json::Error>(())
/// ```
///
/// [`DataType::description()`]: type_system::DataType::description
/// [`DataType::description()`]: type_system::schema::DataType::description
Description,
/// Corresponds to [`DataType::json_type()`].
///
Expand All @@ -144,7 +144,7 @@ pub enum DataTypeQueryPath<'p> {
/// # Ok::<(), serde_json::Error>(())
/// ```
///
/// [`DataType::json_type()`]: type_system::DataType::json_type
/// [`DataType::json_type()`]: type_system::schema::DataType::json_type
Type,
/// Only used internally and not available for deserialization.
OntologyId,
Expand All @@ -160,8 +160,8 @@ pub enum DataTypeQueryPath<'p> {
/// Only used internally and not available for deserialization.
///
/// [`ConstrainsValuesOn`]: OntologyEdgeKind::ConstrainsValuesOn
/// [`DataType`]: type_system::DataType
/// [`PropertyType`]: type_system::PropertyType
/// [`DataType`]: type_system::schema::DataType
/// [`PropertyType`]: type_system::schema::PropertyType
PropertyTypeEdge {
edge_kind: OntologyEdgeKind,
path: Box<PropertyTypeQueryPath<'p>>,
Expand All @@ -186,7 +186,7 @@ pub enum DataTypeQueryPath<'p> {
/// Deserializes from `["editionProvenance", ...]` where `...` is a path to a provenance entry
/// of an [`DataType`].
///
/// [`DataType`]: type_system::DataType
/// [`DataType`]: type_system::schema::DataType
///
/// ```rust
/// # use serde::Deserialize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::fmt;

use error_stack::{Context, ResultExt};
use regex::{Captures, Regex};
use type_system::{DataType, EntityType, PropertyType};
use type_system::schema::{DataType, EntityType, PropertyType};

#[derive(Debug)]
pub struct DomainValidationError;
Expand Down
32 changes: 16 additions & 16 deletions apps/hash-graph/libs/graph/src/ontology/entity_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{

/// A path to a [`EntityType`] field.
///
/// [`EntityType`]: type_system::EntityType
/// [`EntityType`]: type_system::schema::EntityType
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum EntityTypeQueryPath<'p> {
/// The [`BaseUrl`] of the [`EntityType`].
Expand All @@ -35,7 +35,7 @@ pub enum EntityTypeQueryPath<'p> {
/// # Ok::<(), serde_json::Error>(())
/// ```
///
/// [`EntityType`]: type_system::EntityType
/// [`EntityType`]: type_system::schema::EntityType
/// [`BaseUrl`]: type_system::url::BaseUrl
BaseUrl,
/// The version of the [`EntityType`].
Expand Down Expand Up @@ -69,7 +69,7 @@ pub enum EntityTypeQueryPath<'p> {
/// # Ok::<(), serde_json::Error>(())
/// ```
///
/// [`EntityType`]: type_system::EntityType
/// [`EntityType`]: type_system::schema::EntityType
Version,
/// The [`VersionedUrl`] of the [`EntityType`].
///
Expand All @@ -82,15 +82,15 @@ pub enum EntityTypeQueryPath<'p> {
/// # Ok::<(), serde_json::Error>(())
/// ```
///
/// [`EntityType`]: type_system::EntityType
/// [`EntityType`]: type_system::schema::EntityType
/// [`VersionedUrl`]: type_system::url::VersionedUrl
VersionedUrl,
/// The transaction time of the [`EntityType`].
///
/// It's not possible to query for the temporal axis directly, this has to be done via the
/// `temporalAxes` parameter on the request.
///
/// [`EntityType`]: type_system::EntityType
/// [`EntityType`]: type_system::schema::EntityType
TransactionTime,
/// The [`OwnedById`] of the [`EntityTypeMetadata`] belonging to the [`EntityType`].
///
Expand All @@ -103,7 +103,7 @@ pub enum EntityTypeQueryPath<'p> {
/// # Ok::<(), serde_json::Error>(())
/// ```
///
/// [`EntityType`]: type_system::EntityType
/// [`EntityType`]: type_system::schema::EntityType
/// [`OwnedById`]: graph_types::owned_by_id::OwnedById
/// [`EntityTypeMetadata`]: graph_types::ontology::EntityTypeMetadata
OwnedById,
Expand All @@ -118,7 +118,7 @@ pub enum EntityTypeQueryPath<'p> {
/// # Ok::<(), serde_json::Error>(())
/// ```
///
/// [`EntityType::title()`]: type_system::EntityType::title
/// [`EntityType::title()`]: type_system::schema::EntityType::title
Title,
/// Corresponds to [`EntityType::description()`]
///
Expand All @@ -131,7 +131,7 @@ pub enum EntityTypeQueryPath<'p> {
/// # Ok::<(), serde_json::Error>(())
/// ```
///
/// [`EntityType::description()`]: type_system::EntityType::description
/// [`EntityType::description()`]: type_system::schema::EntityType::description
Description,
/// Corresponds to [`EntityType::examples()`].
///
Expand All @@ -144,7 +144,7 @@ pub enum EntityTypeQueryPath<'p> {
/// # Ok::<(), serde_json::Error>(())
/// ```
///
/// [`EntityType::examples()`]: type_system::EntityType::examples
/// [`EntityType::examples()`]: type_system::schema::EntityType::examples
Examples,
/// Corresponds to [`EntityType::required()`].
///
Expand All @@ -157,7 +157,7 @@ pub enum EntityTypeQueryPath<'p> {
/// # Ok::<(), serde_json::Error>(())
/// ```
///
/// [`EntityType::required()`]: type_system::EntityType::required
/// [`EntityType::required()`]: type_system::schema::EntityType::required
Required,
/// The label property metadata of the entity type.
///
Expand Down Expand Up @@ -188,8 +188,8 @@ pub enum EntityTypeQueryPath<'p> {
/// Allowed edge kinds are:
/// - [`ConstrainsPropertiesOn`]
///
/// [`PropertyType`]: type_system::PropertyType
/// [`EntityType`]: type_system::EntityType
/// [`PropertyType`]: type_system::schema::PropertyType
/// [`EntityType`]: type_system::schema::EntityType
/// [`ConstrainsPropertiesOn`]: OntologyEdgeKind::ConstrainsPropertiesOn
///
///
Expand Down Expand Up @@ -253,7 +253,7 @@ pub enum EntityTypeQueryPath<'p> {
/// - [`ConstrainsLinksOn`]
/// - [`ConstrainsLinkDestinationsOn`]
///
/// [`EntityType`]: type_system::EntityType
/// [`EntityType`]: type_system::schema::EntityType
/// [`InheritsFrom`]: OntologyEdgeKind::InheritsFrom
/// [`ConstrainsLinksOn`]: OntologyEdgeKind::ConstrainsLinksOn
/// [`ConstrainsLinkDestinationsOn`]: OntologyEdgeKind::ConstrainsLinkDestinationsOn
Expand Down Expand Up @@ -410,7 +410,7 @@ pub enum EntityTypeQueryPath<'p> {
/// # Ok::<(), serde_json::Error>(())
/// ```
///
/// [`EntityType::link_mappings()`]: type_system::EntityType::link_mappings
/// [`EntityType::link_mappings()`]: type_system::schema::EntityType::link_mappings
///
///
/// ## Constraining link destinations
Expand All @@ -430,7 +430,7 @@ pub enum EntityTypeQueryPath<'p> {
///
/// Only used internally and not available for deserialization.
///
/// [`EntityType`]: type_system::PropertyType
/// [`EntityType`]: type_system::schema::PropertyType
/// [`Entity`]: graph_types::knowledge::entity::Entity
EntityEdge {
edge_kind: SharedEdgeKind,
Expand All @@ -450,7 +450,7 @@ pub enum EntityTypeQueryPath<'p> {
/// Deserializes from `["editionProvenance", ...]` where `...` is a path to a provenance entry
/// of an [`EntityType`].
///
/// [`EntityType`]: type_system::EntityType
/// [`EntityType`]: type_system::schema::EntityType
///
/// ```rust
/// # use serde::Deserialize;
Expand Down
Loading

0 comments on commit e3c05fe

Please sign in to comment.