UNPKG

@tanstack/db

Version:

A reactive client store for building super fast apps on sync

51 lines (50 loc) • 2.03 kB
const require_ir = require("../ir.cjs"); function getSourceAliasesFromExpression(expr) { switch (expr.type) { case `ref`: { const sourceAlias = require_ir.getPropRefSourceAlias(expr) ?? expr.path[0]; return new Set(sourceAlias ? [sourceAlias] : []); } case `func`: { const sourceAliases = /* @__PURE__ */ new Set(); for (const arg of expr.args) for (const alias of getSourceAliasesFromExpression(arg)) sourceAliases.add(alias); return sourceAliases; } default: return /* @__PURE__ */ new Set(); } } function normalizeExpressionPaths(whereClause, collectionAlias) { const tpe = whereClause.type; if (tpe === `val`) return new require_ir.Value(whereClause.value); else if (tpe === `ref`) { const path = whereClause.path; const sourceAlias = require_ir.getPropRefSourceAlias(whereClause); if (Array.isArray(path)) { if (sourceAlias === collectionAlias) return new require_ir.PropRef(require_ir.getPropRefPropertyPath(whereClause)); else if (sourceAlias !== void 0) return new require_ir.PropRef(path, sourceAlias); else if (path[0] === collectionAlias && path.length > 1) return new require_ir.PropRef(path.slice(1)); else if (path.length === 1 && path[0] !== void 0) return new require_ir.PropRef([path[0]]); } return new require_ir.PropRef(Array.isArray(path) ? path : [String(path)]); } else { const args = []; for (const arg of whereClause.args) { const convertedArg = normalizeExpressionPaths(arg, collectionAlias); args.push(convertedArg); } return new require_ir.Func(whereClause.name, args); } } function normalizeOrderByPaths(orderBy, collectionAlias) { return orderBy.map((clause) => { const basicExp = normalizeExpressionPaths(clause.expression, collectionAlias); return { ...clause, expression: basicExp }; }); } exports.getSourceAliasesFromExpression = getSourceAliasesFromExpression; exports.normalizeExpressionPaths = normalizeExpressionPaths; exports.normalizeOrderByPaths = normalizeOrderByPaths; //# sourceMappingURL=expressions.cjs.map