MCPcopy Index your code
hub / github.com/TanStack/db / deepCopyQuery

Function deepCopyQuery

packages/db/src/query/optimizer.ts:827–852  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

825 * @returns New QueryIR object with all nested objects copied
826 */
827function 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
854function deepCopyFrom(from: From): From {
855 if (from.type === `collectionRef`) {

Callers 2

deepCopyFromFunction · 0.85
optimizeFromWithTrackingFunction · 0.85

Calls 3

deepCopyFromFunction · 0.85
deepCopyJoinFromFunction · 0.85
mapMethod · 0.45

Tested by

no test coverage detected