From 6dc62f8d1455b1ffc6c3f138e062e30efbd85299 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Wed, 4 Oct 2023 09:29:46 +0200 Subject: [PATCH] Implement != operator for arrays --- plug-api/lib/query.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/plug-api/lib/query.ts b/plug-api/lib/query.ts index 340ca771..81d68ade 100644 --- a/plug-api/lib/query.ts +++ b/plug-api/lib/query.ts @@ -80,19 +80,23 @@ export function evalQueryExpression( case "=": { if (Array.isArray(val1) && !Array.isArray(val2)) { // Record property is an array, and value is a scalar: find the value in the array - if (val1.includes(val2)) { - return true; - } + return val1.includes(val2); } else if (Array.isArray(val1) && Array.isArray(val2)) { // Record property is an array, and value is an array: find the value in the array - if (val1.some((v) => val2.includes(v))) { - return true; - } + return val1.some((v) => val2.includes(v)); } return val1 == val2; } - case "!=": - return val1 != val2; + case "!=": { + if (Array.isArray(val1) && !Array.isArray(val2)) { + // Record property is an array, and value is a scalar: find the value in the array + return !val1.includes(val2); + } else if (Array.isArray(val1) && Array.isArray(val2)) { + // Record property is an array, and value is an array: find the value in the array + return !val1.some((v) => val2.includes(v)); + } + return val1 !== val2; + } case "=~": { if (!Array.isArray(val2)) { throw new Error(`Invalid regexp: ${val2}`);