@tanstack/db
Version:
A reactive client store for building super fast apps on sync
65 lines (64 loc) • 1.8 kB
JavaScript
;
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const utils = require("../../utils.cjs");
const irStableIdentity = require("../ir-stable-identity.cjs");
const errors = require("../../errors.cjs");
function queriesMatchForCaching(a, b) {
if (!utils.deepEquals(normalizeQuery(a), normalizeQuery(b))) return false;
try {
return irStableIdentity.getQueryIdentity(a) === irStableIdentity.getQueryIdentity(b);
} catch (error) {
if (error instanceof errors.UnhashableQueryIRError) return false;
throw error;
}
}
function normalizeQuery(query) {
return {
from: normalizeFrom(query.from),
select: query.select,
join: query.join?.map((join) => ({
from: normalizeFrom(join.from),
type: join.type,
on: join.on
})),
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)
};
}
}
exports.queriesMatchForCaching = queriesMatchForCaching;
//# sourceMappingURL=query-equivalence.cjs.map