UNPKG

@sap/cds-compiler

Version:

CDS (Core Data Services) compiler and backends

58 lines (49 loc) 1.76 kB
'use strict'; const { applyTransformationsOnNonDictionary } = require('../model/csnUtils'); // Only to be used with validator.js - a correct this value needs to be provided! /** * Validate select items of a query. If a column reference starts with $self or * $projection, it must not contain association steps. * * @param {CSN.Query} query query object * @todo Why do we care about this with $self? */ function validateSelectItems( query ) { const { SELECT } = query; if (!SELECT) return; /** * Check the given assoc filter for usage of $self - in an assoc-filter, you must only * address things on the target side of the association, not from global scope. * * @param {object} parent * @param {string} prop * @param {Array} where */ function checkFilterForInvalid$Self( parent, prop, where ) { where.forEach((whereStep) => { if (whereStep.ref && ( whereStep.ref[0] === '$projection' || whereStep.ref[0] === '$self')) { this.error('expr-where-unexpected-self', whereStep.$path, { name: whereStep.ref[0] }, 'Path steps inside of filters must not start with $(NAME)'); } }); } const aTCB = (parent, prop) => { applyTransformationsOnNonDictionary(parent, prop, { where: checkFilterForInvalid$Self.bind(this), }, { skipStandard: { on: true }, drillRef: true }); }; const transformers = { /* columns: aTCB, groupBy: aTCB, having: aTCB, where: aTCB, */ orderBy: aTCB, // filters in order by imply a join, not allowed from: aTCB, // $self refs in from clause filters are not allowed }; applyTransformationsOnNonDictionary(query, 'SELECT', transformers ); } module.exports = { validateSelectItems };