* Helper to compute difference between range predicates
( fromFunc: Func, fromValue: any, subtractFunc: Func, subtractValue: any, )
| 532 | * Helper to compute difference between range predicates |
| 533 | */ |
| 534 | function minusRangePredicates( |
| 535 | fromFunc: Func, |
| 536 | fromValue: any, |
| 537 | subtractFunc: Func, |
| 538 | subtractValue: any, |
| 539 | ): BasicExpression<boolean> | null { |
| 540 | const fromOp = fromFunc.name as `gt` | `gte` | `lt` | `lte` | `eq` |
| 541 | const subtractOp = subtractFunc.name as `gt` | `gte` | `lt` | `lte` | `eq` |
| 542 | const ref = (extractComparisonField(fromFunc) || |
| 543 | extractEqualityField(fromFunc))!.ref |
| 544 | |
| 545 | // age > 10 - age > 20 = (age > 10 AND age <= 20) |
| 546 | if (fromOp === `gt` && subtractOp === `gt`) { |
| 547 | if (fromValue < subtractValue) { |
| 548 | // Result is: fromValue < field <= subtractValue |
| 549 | return { |
| 550 | type: `func`, |
| 551 | name: `and`, |
| 552 | args: [ |
| 553 | fromFunc as BasicExpression<boolean>, |
| 554 | { |
| 555 | type: `func`, |
| 556 | name: `lte`, |
| 557 | args: [ref, { type: `val`, value: subtractValue }], |
| 558 | } as BasicExpression<boolean>, |
| 559 | ], |
| 560 | } as BasicExpression<boolean> |
| 561 | } |
| 562 | // fromValue >= subtractValue means no overlap |
| 563 | return fromFunc as BasicExpression<boolean> |
| 564 | } |
| 565 | |
| 566 | // age >= 10 - age >= 20 = (age >= 10 AND age < 20) |
| 567 | if (fromOp === `gte` && subtractOp === `gte`) { |
| 568 | if (fromValue < subtractValue) { |
| 569 | return { |
| 570 | type: `func`, |
| 571 | name: `and`, |
| 572 | args: [ |
| 573 | fromFunc as BasicExpression<boolean>, |
| 574 | { |
| 575 | type: `func`, |
| 576 | name: `lt`, |
| 577 | args: [ref, { type: `val`, value: subtractValue }], |
| 578 | } as BasicExpression<boolean>, |
| 579 | ], |
| 580 | } as BasicExpression<boolean> |
| 581 | } |
| 582 | return fromFunc as BasicExpression<boolean> |
| 583 | } |
| 584 | |
| 585 | // age > 10 - age >= 20 = (age > 10 AND age < 20) |
| 586 | if (fromOp === `gt` && subtractOp === `gte`) { |
| 587 | if (fromValue < subtractValue) { |
| 588 | return { |
| 589 | type: `func`, |
| 590 | name: `and`, |
| 591 | args: [ |
no test coverage detected