UNPKG

azurite

Version:

An open source Azure Storage API compatible server

36 lines 1.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateQueryTree = void 0; const tslib_1 = require("tslib"); const BinaryOperatorNode_1 = tslib_1.__importDefault(require("./QueryNodes/BinaryOperatorNode")); const IdentifierNode_1 = tslib_1.__importDefault(require("./QueryNodes/IdentifierNode")); const NotNode_1 = tslib_1.__importDefault(require("./QueryNodes/NotNode")); /** * Validates that the provided query tree represents a valid query. * * That is, a query containing at least one conditional expression, * where every conditional expression operates on at least * one column or built-in identifier (i.e. comparison between two constants is not allowed). * * @param {IQueryNode} queryTree */ function validateQueryTree(queryTree) { const identifierReferences = countIdentifierReferences(queryTree); if (identifierReferences === 0) { throw new Error("Invalid Query, no identifier references found."); } } exports.validateQueryTree = validateQueryTree; function countIdentifierReferences(queryTree) { if (queryTree instanceof IdentifierNode_1.default) { return 1; } if (queryTree instanceof BinaryOperatorNode_1.default) { return countIdentifierReferences(queryTree.left) + countIdentifierReferences(queryTree.right); } if (queryTree instanceof NotNode_1.default) { return countIdentifierReferences(queryTree.right); } return 0; } //# sourceMappingURL=QueryValidator.js.map