* Helper function to create a deep copy of a QueryIR object for immutability. * * This ensures that all optimizations create new objects rather than modifying * existing ones, preventing infinite recursion and shared reference issues. * * @param query - QueryIR to deep copy * @returns New Quer
(query: QueryIR)
| 825 | * @returns New QueryIR object with all nested objects copied |
| 826 | */ |
| 827 | function deepCopyQuery(query: QueryIR): QueryIR { |
| 828 | return { |
| 829 | // Recursively copy the FROM clause |
| 830 | from: deepCopyFrom(query.from), |
| 831 | |
| 832 | // Copy all other fields, creating new arrays where necessary |
| 833 | select: query.select, |
| 834 | join: query.join |
| 835 | ? query.join.map((joinClause) => ({ |
| 836 | type: joinClause.type, |
| 837 | left: joinClause.left, |
| 838 | right: joinClause.right, |
| 839 | from: deepCopyJoinFrom(joinClause.from), |
| 840 | })) |
| 841 | : undefined, |
| 842 | where: query.where ? [...query.where] : undefined, |
| 843 | groupBy: query.groupBy ? [...query.groupBy] : undefined, |
| 844 | having: query.having ? [...query.having] : undefined, |
| 845 | orderBy: query.orderBy ? [...query.orderBy] : undefined, |
| 846 | limit: query.limit, |
| 847 | offset: query.offset, |
| 848 | fnSelect: query.fnSelect, |
| 849 | fnWhere: query.fnWhere ? [...query.fnWhere] : undefined, |
| 850 | fnHaving: query.fnHaving ? [...query.fnHaving] : undefined, |
| 851 | } |
| 852 | } |
| 853 | |
| 854 | function deepCopyFrom(from: From): From { |
| 855 | if (from.type === `collectionRef`) { |
no test coverage detected