This commit is contained in:
2026-04-17 17:20:07 -04:00
parent 3a4c53dc7d
commit 8ebf6a69bf
3 changed files with 171 additions and 3 deletions

View File

@ -174,12 +174,48 @@
"person.filter": { "person.filter": {
"type": "filter", "type": "filter",
"compiledPropertyNames": [ "compiledPropertyNames": [
"$and",
"$or",
"age", "age",
"billing_address", "billing_address",
"birth_date", "birth_date",
"first_name" "first_name"
], ],
"properties": { "properties": {
"$and": {
"type": [
"array",
"null"
],
"items": {
"compiledPropertyNames": [
"$and",
"$or",
"age",
"billing_address",
"birth_date",
"first_name"
],
"type": "person.filter"
}
},
"$or": {
"type": [
"array",
"null"
],
"items": {
"compiledPropertyNames": [
"$and",
"$or",
"age",
"billing_address",
"birth_date",
"first_name"
],
"type": "person.filter"
}
},
"first_name": { "first_name": {
"type": [ "type": [
"string.condition", "string.condition",
@ -210,9 +246,39 @@
"address.filter": { "address.filter": {
"type": "filter", "type": "filter",
"compiledPropertyNames": [ "compiledPropertyNames": [
"$and",
"$or",
"city" "city"
], ],
"properties": { "properties": {
"$and": {
"type": [
"array",
"null"
],
"items": {
"compiledPropertyNames": [
"$and",
"$or",
"city"
],
"type": "address.filter"
}
},
"$or": {
"type": [
"array",
"null"
],
"items": {
"compiledPropertyNames": [
"$and",
"$or",
"city"
],
"type": "address.filter"
}
},
"city": { "city": {
"type": [ "type": [
"string.condition", "string.condition",
@ -230,10 +296,42 @@
"search.filter": { "search.filter": {
"type": "filter", "type": "filter",
"compiledPropertyNames": [ "compiledPropertyNames": [
"$and",
"$or",
"filter", "filter",
"name" "name"
], ],
"properties": { "properties": {
"$and": {
"type": [
"array",
"null"
],
"items": {
"compiledPropertyNames": [
"$and",
"$or",
"filter",
"name"
],
"type": "search.filter"
}
},
"$or": {
"type": [
"array",
"null"
],
"items": {
"compiledPropertyNames": [
"$and",
"$or",
"filter",
"name"
],
"type": "search.filter"
}
},
"filter": { "filter": {
"type": [ "type": [
"filter.filter", "filter.filter",

View File

@ -8,7 +8,7 @@ impl Schema {
pub fn compile_filter( pub fn compile_filter(
&self, &self,
_db: &Database, _db: &Database,
_root_id: &str, root_id: &str,
_errors: &mut Vec<crate::drop::Error>, _errors: &mut Vec<crate::drop::Error>,
) -> Option<Schema> { ) -> Option<Schema> {
if let Some(props) = self.obj.compiled_properties.get() { if let Some(props) = self.obj.compiled_properties.get() {
@ -31,6 +31,48 @@ impl Schema {
} }
if !filter_props.is_empty() { if !filter_props.is_empty() {
let root_filter_type = format!("{}.filter", root_id);
let mut and_obj = SchemaObject::default();
and_obj.type_ = Some(SchemaTypeOrArray::Multiple(vec![
"array".to_string(),
"null".to_string(),
]));
and_obj.items = Some(Arc::new(Schema {
obj: SchemaObject {
type_: Some(SchemaTypeOrArray::Single(root_filter_type.clone())),
..Default::default()
},
always_fail: false,
}));
filter_props.insert(
"$and".to_string(),
Arc::new(Schema {
obj: and_obj,
always_fail: false,
}),
);
let mut or_obj = SchemaObject::default();
or_obj.type_ = Some(SchemaTypeOrArray::Multiple(vec![
"array".to_string(),
"null".to_string(),
]));
or_obj.items = Some(Arc::new(Schema {
obj: SchemaObject {
type_: Some(SchemaTypeOrArray::Single(root_filter_type.clone())),
..Default::default()
},
always_fail: false,
}));
filter_props.insert(
"$or".to_string(),
Arc::new(Schema {
obj: or_obj,
always_fail: false,
}),
);
let mut wrapper_obj = SchemaObject::default(); let mut wrapper_obj = SchemaObject::default();
// Conceptually link this directly into the STI lineage of the base `filter` object // Conceptually link this directly into the STI lineage of the base `filter` object
wrapper_obj.type_ = Some(SchemaTypeOrArray::Single("filter".to_string())); wrapper_obj.type_ = Some(SchemaTypeOrArray::Single("filter".to_string()));

View File

@ -140,8 +140,22 @@ fn test_library_api() {
"type": "object" "type": "object"
}, },
"source_schema.filter": { "source_schema.filter": {
"compiledPropertyNames": ["name", "target", "type"], "compiledPropertyNames": ["$and", "$or", "name", "target", "type"],
"properties": { "properties": {
"$and": {
"type": ["array", "null"],
"items": {
"compiledPropertyNames": ["$and", "$or", "name", "target", "type"],
"type": "source_schema.filter"
}
},
"$or": {
"type": ["array", "null"],
"items": {
"compiledPropertyNames": ["$and", "$or", "name", "target", "type"],
"type": "source_schema.filter"
}
},
"name": { "type": ["string.condition", "null"] }, "name": { "type": ["string.condition", "null"] },
"target": { "type": ["target_schema.filter", "null"] }, "target": { "type": ["target_schema.filter", "null"] },
"type": { "type": ["string.condition", "null"] } "type": { "type": ["string.condition", "null"] }
@ -179,8 +193,22 @@ fn test_library_api() {
"type": "object" "type": "object"
}, },
"target_schema.filter": { "target_schema.filter": {
"compiledPropertyNames": ["value"], "compiledPropertyNames": ["$and", "$or", "value"],
"properties": { "properties": {
"$and": {
"type": ["array", "null"],
"items": {
"compiledPropertyNames": ["$and", "$or", "value"],
"type": "target_schema.filter"
}
},
"$or": {
"type": ["array", "null"],
"items": {
"compiledPropertyNames": ["$and", "$or", "value"],
"type": "target_schema.filter"
}
},
"value": { "type": ["number.condition", "null"] } "value": { "type": ["number.condition", "null"] }
}, },
"type": "filter" "type": "filter"