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

H-3995: Make value required for properties with metadata #6309

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion libs/@local/codec/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"license": "AGPL-3",
"scripts": {
"fix:clippy": "just clippy --fix",
"lint:clippy": "just clippy"
"lint:clippy": "just clippy",
"test:unit": "cargo hack nextest run --feature-powerset --all-targets && cargo test --all-features --doc"
},
"dependencies": {
"@rust/error-stack": "0.5.0",
Expand Down
2 changes: 1 addition & 1 deletion libs/@local/codec/src/serde/string_hash_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//!
//! #[derive(Debug, PartialEq, Serialize, Deserialize)]
//! struct MyStruct {
//! #[serde(with = "codec::serde::string_hash_map")]
//! #[serde(with = "hash_codec::serde::string_hash_map")]
//! map: HashMap<u32, String>,
//! }
//!
Expand Down
12 changes: 12 additions & 0 deletions libs/@local/graph/api/openapi/openapi.json

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

3 changes: 2 additions & 1 deletion libs/@local/graph/types/rust/src/knowledge/property/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use crate::knowledge::property::{ArrayMetadata, PropertyWithMetadata};
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct PropertyWithMetadataArray {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
#[cfg_attr(feature = "utoipa", schema(required))]
pub value: Vec<PropertyWithMetadata>,
#[serde(default, skip_serializing_if = "ArrayMetadata::is_empty")]
pub metadata: ArrayMetadata,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ use type_system::url::BaseUrl;
pub enum PropertyMetadata {
#[cfg_attr(feature = "utoipa", schema(title = "PropertyMetadataArray"))]
Array {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
#[cfg_attr(feature = "utoipa", schema(required))]
value: Vec<Self>,
#[serde(default, skip_serializing_if = "ArrayMetadata::is_empty")]
metadata: ArrayMetadata,
},
#[cfg_attr(feature = "utoipa", schema(title = "PropertyMetadataObject"))]
Object {
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
#[serde(default)]
#[cfg_attr(feature = "utoipa", schema(required))]
value: HashMap<BaseUrl, Self>,
#[serde(default, skip_serializing_if = "ObjectMetadata::is_empty")]
metadata: ObjectMetadata,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ impl<'a> FromSql<'a> for PropertyObject {
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct PropertyWithMetadataObject {
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
#[serde(default)]
#[cfg_attr(feature = "utoipa", schema(required))]
pub value: HashMap<BaseUrl, PropertyWithMetadata>,
#[serde(default, skip_serializing_if = "ObjectMetadata::is_empty")]
pub metadata: ObjectMetadata,
Expand Down
15 changes: 15 additions & 0 deletions libs/@local/graph/types/typescript/src/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,21 @@ export type PropertyWithMetadata =
| PropertyObjectWithMetadata
| PropertyValueWithMetadata;

export const isValueWithMetadata = (
metadata: PropertyWithMetadata,
): metadata is PropertyValueWithMetadata =>
metadata.metadata !== undefined && "dataTypeId" in metadata.metadata;

export const isArrayWithMetadata = (
metadata: PropertyWithMetadata,
): metadata is PropertyArrayWithMetadata =>
!isValueMetadata(metadata) && Array.isArray(metadata.value);

export const isObjectWithMetadata = (
metadata: PropertyWithMetadata,
): metadata is PropertyObjectWithMetadata =>
!isValueMetadata(metadata) && !Array.isArray(metadata.value);

/**
* A path to a property in a properties object
*
Expand Down
Loading