( path: TraversalPath<any, any, any>, condition: Condition, context?: QueryContext, )
| 1017 | | IsLabeledCondition; |
| 1018 | |
| 1019 | function evaluateCondition( |
| 1020 | path: TraversalPath<any, any, any>, |
| 1021 | condition: Condition, |
| 1022 | context?: QueryContext, |
| 1023 | ): boolean { |
| 1024 | switch (condition[0]) { |
| 1025 | case "and": { |
| 1026 | for (let i = 1; i < condition.length; i++) { |
| 1027 | if (!evaluateCondition(path, condition[i] as Condition, context)) { |
| 1028 | return false; |
| 1029 | } |
| 1030 | } |
| 1031 | return true; |
| 1032 | } |
| 1033 | case "or": { |
| 1034 | for (let i = 1; i < condition.length; i++) { |
| 1035 | if (evaluateCondition(path, condition[i] as Condition, context)) { |
| 1036 | return true; |
| 1037 | } |
| 1038 | } |
| 1039 | return false; |
| 1040 | } |
| 1041 | case "xor": { |
| 1042 | // XOR: exactly one of the conditions must be true |
| 1043 | let trueCount = 0; |
| 1044 | for (let i = 1; i < condition.length; i++) { |
| 1045 | if (evaluateCondition(path, condition[i] as Condition, context)) { |
| 1046 | trueCount++; |
| 1047 | } |
| 1048 | } |
| 1049 | return trueCount === 1; |
| 1050 | } |
| 1051 | case "not": { |
| 1052 | return !evaluateCondition(path, condition[1] as Condition, context); |
| 1053 | } |
| 1054 | case "exists": { |
| 1055 | const key = condition[1]!; |
| 1056 | const element = path.value; |
| 1057 | if (!(element instanceof Vertex || element instanceof Edge)) { |
| 1058 | return false; |
| 1059 | } |
| 1060 | return key === "@id" |
| 1061 | ? element.id !== undefined |
| 1062 | : key === "@label" |
| 1063 | ? element.label !== undefined |
| 1064 | : element.get(key) !== undefined; |
| 1065 | } |
| 1066 | case "isNull": { |
| 1067 | const key = condition[1]!; |
| 1068 | const element = path.value; |
| 1069 | if (!(element instanceof Vertex || element instanceof Edge)) { |
| 1070 | return true; |
| 1071 | } |
| 1072 | const value = |
| 1073 | key === "@id" ? element.id : key === "@label" ? element.label : element.get(key); |
| 1074 | return value === undefined || value === null; |
| 1075 | } |
| 1076 | case "isNotNull": { |
no test coverage detected