(expr: BasicExpression)
| 113 | const results: Array<{ fieldName: string; fieldPath: Array<string> }> = [] |
| 114 | |
| 115 | function extractFromExpression(expr: BasicExpression): void { |
| 116 | if (expr.type !== `func`) { |
| 117 | return |
| 118 | } |
| 119 | |
| 120 | const func = expr as any |
| 121 | |
| 122 | // Handle 'and' expressions by recursively processing all arguments |
| 123 | if (func.name === `and`) { |
| 124 | for (const arg of func.args) { |
| 125 | extractFromExpression(arg) |
| 126 | } |
| 127 | return |
| 128 | } |
| 129 | |
| 130 | // Check if this is a supported operation |
| 131 | const supportedOperations = [`eq`, `gt`, `gte`, `lt`, `lte`, `in`] |
| 132 | if (!supportedOperations.includes(func.name)) { |
| 133 | return |
| 134 | } |
| 135 | |
| 136 | // Check if the first argument is a property reference |
| 137 | if (func.args.length < 1 || func.args[0].type !== `ref`) { |
| 138 | return |
| 139 | } |
| 140 | |
| 141 | const fieldRef = func.args[0] |
| 142 | const fieldPath = fieldRef.path |
| 143 | |
| 144 | // Skip if the path is empty |
| 145 | if (fieldPath.length === 0) { |
| 146 | return |
| 147 | } |
| 148 | |
| 149 | // For nested paths, use the full path joined with underscores as the field name |
| 150 | // For simple paths, use the first (and only) element |
| 151 | const fieldName = fieldPath.join(`_`) |
| 152 | results.push({ fieldName, fieldPath }) |
| 153 | } |
| 154 | |
| 155 | extractFromExpression(expression) |
| 156 | return results |
no test coverage detected