* Remove specified conditions from a predicate. * Returns the predicate with the specified conditions removed, or undefined if all conditions are removed.
( predicate: BasicExpression<boolean>, conditionsToRemove: Array<BasicExpression<boolean>>, )
| 964 | * Returns the predicate with the specified conditions removed, or undefined if all conditions are removed. |
| 965 | */ |
| 966 | function removeConditions( |
| 967 | predicate: BasicExpression<boolean>, |
| 968 | conditionsToRemove: Array<BasicExpression<boolean>>, |
| 969 | ): BasicExpression<boolean> | undefined { |
| 970 | if (predicate.type === `func` && predicate.name === `and`) { |
| 971 | const remainingArgs = predicate.args.filter( |
| 972 | (arg) => |
| 973 | !conditionsToRemove.some((cond) => |
| 974 | areExpressionsEqual(arg as BasicExpression<boolean>, cond), |
| 975 | ), |
| 976 | ) |
| 977 | |
| 978 | if (remainingArgs.length === 0) { |
| 979 | return undefined |
| 980 | } else if (remainingArgs.length === 1) { |
| 981 | return remainingArgs[0]! |
| 982 | } else { |
| 983 | return { |
| 984 | type: `func`, |
| 985 | name: `and`, |
| 986 | args: remainingArgs, |
| 987 | } as BasicExpression<boolean> |
| 988 | } |
| 989 | } |
| 990 | |
| 991 | // For non-AND predicates, don't remove anything |
| 992 | return predicate |
| 993 | } |
| 994 | |
| 995 | /** |
| 996 | * Combine multiple conditions into a single predicate using AND logic. |
no test coverage detected