UNPKG

@tanstack/db

Version:

A reactive client store for building super fast apps on sync

58 lines (57 loc) • 1.39 kB
import { deepEquals } from "../../utils.js"; function queriesMatchForCaching(a, b) { return deepEquals(normalizeQuery(a), normalizeQuery(b)); } function normalizeQuery(query) { return { from: normalizeFrom(query.from), select: query.select, join: query.join?.map((join) => ({ from: normalizeFrom(join.from), type: join.type, left: join.left, right: join.right })), where: query.where, groupBy: query.groupBy, having: query.having, orderBy: query.orderBy, limit: query.limit, offset: query.offset, distinct: query.distinct, singleResult: query.singleResult, fnSelect: query.fnSelect, fnWhere: query.fnWhere, fnHaving: query.fnHaving }; } function normalizeFrom(from) { switch (from.type) { case `collectionRef`: return { type: from.type, collection: from.collection, alias: from.alias }; case `queryRef`: return { type: from.type, query: normalizeQuery(from.query), alias: from.alias }; case `unionFrom`: return { type: from.type, sources: from.sources.map(normalizeFrom) }; case `unionAll`: return { type: from.type, queries: from.queries.map(normalizeQuery) }; } } export { queriesMatchForCaching }; //# sourceMappingURL=query-equivalence.js.map