( condition: Condition, usedHint: IndexHint, )
| 257 | * @returns Remaining condition to filter, or undefined if fully covered. |
| 258 | */ |
| 259 | export function extractRemainingCondition( |
| 260 | condition: Condition, |
| 261 | usedHint: IndexHint, |
| 262 | ): Condition | undefined { |
| 263 | const [operator] = condition; |
| 264 | |
| 265 | // If this is the exact condition being handled by index |
| 266 | if (isConditionFullyCovered(condition, usedHint)) { |
| 267 | return undefined; |
| 268 | } |
| 269 | |
| 270 | // For AND conditions, remove the covered sub-condition |
| 271 | if (operator === "and") { |
| 272 | const remaining: Condition[] = []; |
| 273 | |
| 274 | for (let i = 1; i < condition.length; i++) { |
| 275 | const subCondition = condition[i] as Condition; |
| 276 | if (subCondition !== usedHint.condition) { |
| 277 | remaining.push(subCondition); |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | if (remaining.length === 0) { |
| 282 | return undefined; |
| 283 | } |
| 284 | |
| 285 | if (remaining.length === 1) { |
| 286 | return remaining[0]; |
| 287 | } |
| 288 | |
| 289 | return ["and", ...remaining] as Condition; |
| 290 | } |
| 291 | |
| 292 | // For other conditions, we need to keep the whole thing |
| 293 | return condition; |
| 294 | } |
no test coverage detected