( subset: LoadSubsetOptions, superset: LoadSubsetOptions, )
| 854 | * @returns true if subset is satisfied by superset |
| 855 | */ |
| 856 | export function isPredicateSubset( |
| 857 | subset: LoadSubsetOptions, |
| 858 | superset: LoadSubsetOptions, |
| 859 | ): boolean { |
| 860 | // When the superset has a limit, we can only determine subset relationship |
| 861 | // if the where clauses are equal (not just subset relationship). |
| 862 | // |
| 863 | // This is because a limited query only loads a portion of the matching rows. |
| 864 | // A more restrictive where clause might require rows outside that portion. |
| 865 | // |
| 866 | // Example: superset = {where: undefined, limit: 10, orderBy: desc} |
| 867 | // subset = {where: LIKE 'search%', limit: 10, orderBy: desc} |
| 868 | // The top 10 items matching 'search%' might include items outside the overall top 10. |
| 869 | // |
| 870 | // However, if the where clauses are equal, then the subset relationship can |
| 871 | // be determined by orderBy, limit, and offset: |
| 872 | // Example: superset = {where: status='active', limit: 10, offset: 0, orderBy: desc} |
| 873 | // subset = {where: status='active', limit: 5, offset: 0, orderBy: desc} |
| 874 | // The top 5 active items ARE contained in the top 10 active items. |
| 875 | if (superset.limit !== undefined) { |
| 876 | // For limited supersets, where clauses must be equal |
| 877 | if (!areWhereClausesEqual(subset.where, superset.where)) { |
| 878 | return false |
| 879 | } |
| 880 | return ( |
| 881 | isOrderBySubset(subset.orderBy, superset.orderBy) && |
| 882 | isOffsetLimitSubset(subset, superset) |
| 883 | ) |
| 884 | } |
| 885 | |
| 886 | // For unlimited supersets, use the normal subset logic |
| 887 | // Still need to consider offset - an unlimited query with offset only covers |
| 888 | // rows from that offset onwards |
| 889 | return ( |
| 890 | isWhereSubset(subset.where, superset.where) && |
| 891 | isOrderBySubset(subset.orderBy, superset.orderBy) && |
| 892 | isOffsetLimitSubset(subset, superset) |
| 893 | ) |
| 894 | } |
| 895 | |
| 896 | /** |
| 897 | * Check if two where clauses are structurally equal. |
no test coverage detected