* Combine multiple conditions into a single predicate using AND logic. * Flattens nested AND operations to avoid unnecessary nesting.
( conditions: Array<BasicExpression<boolean>>, )
| 997 | * Flattens nested AND operations to avoid unnecessary nesting. |
| 998 | */ |
| 999 | function combineConditions( |
| 1000 | conditions: Array<BasicExpression<boolean>>, |
| 1001 | ): BasicExpression<boolean> { |
| 1002 | if (conditions.length === 0) { |
| 1003 | return { type: `val`, value: true } as BasicExpression<boolean> |
| 1004 | } else if (conditions.length === 1) { |
| 1005 | return conditions[0]! |
| 1006 | } else { |
| 1007 | // Flatten all conditions, including those that are already AND operations |
| 1008 | const flattenedConditions: Array<BasicExpression<boolean>> = [] |
| 1009 | |
| 1010 | for (const condition of conditions) { |
| 1011 | if (condition.type === `func` && condition.name === `and`) { |
| 1012 | // Flatten nested AND operations |
| 1013 | flattenedConditions.push(...condition.args) |
| 1014 | } else { |
| 1015 | flattenedConditions.push(condition) |
| 1016 | } |
| 1017 | } |
| 1018 | |
| 1019 | if (flattenedConditions.length === 1) { |
| 1020 | return flattenedConditions[0]! |
| 1021 | } else { |
| 1022 | return { |
| 1023 | type: `func`, |
| 1024 | name: `and`, |
| 1025 | args: flattenedConditions, |
| 1026 | } as BasicExpression<boolean> |
| 1027 | } |
| 1028 | } |
| 1029 | } |
| 1030 | |
| 1031 | /** |
| 1032 | * Find a predicate with a specific operator and value |
no outgoing calls
no test coverage detected