in packages/sqrl/src/compile/SqrlTruthTable.ts [29:65]
function ensureValidAst(ast: Ast): ast is ValidAst {
if (ast.type === "binary_expr") {
sqrlInvariant(
ast,
["=", "!="].includes(ast.operator),
"Binary operator %s not valid in counter where clause",
ast.operator
);
sqrlInvariant(
ast,
ast.left.type === "feature",
"Counter where clause equality left-hand side must be a feature"
);
sqrlInvariant(
ast,
ast.right.type === "constant" && typeof ast.right.value === "string",
"Counter where clause equality right-hand side must be a constant string"
);
return true;
} else if (ast.type === "boolean_expr") {
sqrlInvariant(
ast,
["and", "or"].includes(ast.operator),
"Only and/or/not operators are valid in a where clause"
);
return ensureValidAst(ast.left) && ensureValidAst(ast.right);
} else if (ast.type === "not") {
return ensureValidAst(ast.expr);
} else if (ast.type === "feature") {
return true;
} else {
throw buildSqrlError(
ast,
"Only and/or/not and constant equality allowed in where clause"
);
}
}