Skip to content

Commit

Permalink
Merge pull request #204 from samply/chore/restore-old-empty-query
Browse files Browse the repository at this point in the history
chore: restore old structure of the empty query
  • Loading branch information
torbrenner authored Feb 10, 2025
2 parents d6410a3 + 1a1df89 commit d175d45
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion packages/lib/src/helpers/ast-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,28 @@ import { get } from "svelte/store";
* @returns Ast: the AST will later be converted to a query language of choice
*/
export const buildAstFromQuery = (queryStore: QueryItem[][]): AstTopLayer => {
return returnNestedValues(queryStore) as AstTopLayer;
const ast = returnNestedValues(queryStore) as AstTopLayer;

// The empty query is currently a special case because focus and potentially other consumers want it like this
// Instead of:
// {"nodeType":"branch","operand":"OR","children":[{"nodeType":"branch","operand":"AND","children":[]}]}
// We return:
// {"nodeType":"branch","operand":"OR","children":[]}
if (ast.children.length === 1) {
const onlyChild = ast.children[0];
if (
onlyChild.nodeType === "branch" &&
onlyChild.children.length === 0
) {
return {
nodeType: "branch",
operand: "OR",
children: [],
};
}
}

return ast;
};

/**
Expand Down

0 comments on commit d175d45

Please sign in to comment.