feat: add $consider (UP/DOWN) toggle to query builder and evaluators

This commit is contained in:
M1
2026-03-16 13:56:36 +04:00
parent 5328471229
commit 27c9044a8b
3 changed files with 46 additions and 9 deletions
+11
View File
@@ -50,6 +50,17 @@ pub struct Response {
pub fn evaluate(query: &Value, response: &Response) -> Result<bool> {
match query {
Value::Object(map) => {
// $consider — "up" (default) or "down": flips result if conditions match
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 });
}
// $and / $or / $not
if let Some(and) = map.get("$and") {
let Value::Array(clauses) = and else { bail!("$and expects array") };