remove $consider, replace with $not

This commit is contained in:
2026-04-09 23:43:10 +04:00
parent 9b2f1de4e7
commit ed59e9c8dc
3 changed files with 26 additions and 55 deletions
+3 -10
View File
@@ -14,17 +14,10 @@ pub struct Response {
pub fn evaluate(query: &Value, response: &Response) -> Result<bool> {
match query {
Value::Array(clauses) => {
return Ok(clauses.iter().all(|c| evaluate(c, response).unwrap_or(false)));
}
Value::Object(map) => {
if let Some(consider) = map.get("$consider") {
let is_down = consider.as_str() == Some("down");
let rest: serde_json::Map<String, Value> = map.iter()
.filter(|(k, _)| k.as_str() != "$consider")
.map(|(k, v)| (k.clone(), v.clone()))
.collect();
let matches = evaluate(&Value::Object(rest), response).unwrap_or(false);
return Ok(if is_down { !matches } else { matches });
}
if let Some(and) = map.get("$and") {
let Value::Array(clauses) = and else { bail!("$and expects array") };
return Ok(clauses.iter().all(|c| evaluate(c, response).unwrap_or(false)));