Skip to content

Commit

Permalink
Remove const in arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
TimDiekmann committed Sep 27, 2024
1 parent 775284c commit c5bfb3b
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ mod wasm {
pub enum ArraySchema {
Constrained(ArrayConstraints),
Tuple(TupleConstraints),
// TODO: Remove
// see https://linear.app/hash/issue/H-3368/remove-const-from-array-constraints
Const { r#const: [JsonValue; 0] },
}

impl ArraySchema {
Expand All @@ -116,14 +113,6 @@ impl ArraySchema {
Self::Tuple(constraints) => constraints
.validate_value(array)
.change_context(ConstraintError::ValueConstraint)?,
Self::Const { r#const } => {
if array != *r#const {
bail!(ConstraintError::InvalidConstValue {
actual: JsonValue::Array(array.to_vec()),
expected: JsonValue::Array(r#const.to_vec()),
});
}
}
}
Ok(())
}
Expand Down
17 changes: 0 additions & 17 deletions libs/@blockprotocol/type-system/rust/src/schema/data_type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ mod raw {
use std::collections::HashSet;

use serde::{Deserialize, Serialize};
use serde_json::Value as JsonValue;

use super::{DataTypeSchemaTag, DataTypeTag};
use crate::{
Expand Down Expand Up @@ -216,12 +215,6 @@ mod raw {
#[serde(flatten)]
constraints: TupleConstraints,
},
ArrayConst {
r#type: ArrayTypeTag,
#[serde(flatten)]
common: ValueSchemaMetadata,
r#const: [JsonValue; 0],
},
AnyOf {
#[serde(flatten)]
common: ValueSchemaMetadata,
Expand Down Expand Up @@ -352,16 +345,6 @@ mod raw {
constraints,
))),
),
DataType::ArrayConst {
r#type: _,
common,
r#const,
} => (
common,
ValueConstraints::Typed(SingleValueConstraints::Array(ArraySchema::Const {
r#const,
})),
),
DataType::AnyOf {
common,
constraints: any_of,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,13 @@ export const DataTypesOptionsContext =
const isArrayConstraints = (

Check failure on line 180 in libs/@hashintel/type-editor/src/shared/data-types-options-context.tsx

View workflow job for this annotation

GitHub Actions / Package (@hashintel/type-editor)

'isArrayConstraints' is assigned a value but never used. Allowed unused vars must match /^_+/u
schema: ArraySchema,
): schema is ArrayConstraints => {
// TODO: Remove `"items" in schema` check when `const` is not allowed on arrays
// see https://linear.app/hash/issue/H-3368/remove-const-from-array-constraints
return (
"items" in schema && schema.items !== undefined && schema.items !== false
);
return schema.items !== undefined && schema.items !== false;
};

const isTupleConstraints = (
schema: ArraySchema,
): schema is TupleConstraints => {
// TODO: Remove `"items" in schema` check when `const` is not allowed on arrays
// see https://linear.app/hash/issue/H-3368/remove-const-from-array-constraints
return "items" in schema && schema.items === false;
schema.items === false;

Check failure on line 189 in libs/@hashintel/type-editor/src/shared/data-types-options-context.tsx

View workflow job for this annotation

GitHub Actions / Package (@hashintel/type-editor)

Expected an assignment or function call and instead saw an expression
};

const isArrayItemsSchema = (
Expand All @@ -213,11 +207,6 @@ const getArrayDataTypeDisplay = (
}

items = dataType.prefixItems;

// TODO: Remove when `const` is not allowed on arrays
// see https://linear.app/hash/issue/H-3368/remove-const-from-array-constraints
} else if (!isArrayConstraints(dataType)) {
return expectedValuesDisplayMap.emptyList;
} else if (!dataType.items) {
return expectedValuesDisplayMap.mixedArray;
} else {
Expand Down

0 comments on commit c5bfb3b

Please sign in to comment.