UNPKG

@sap/cds-compiler

Version:

CDS (Core Data Services) compiler and backends

33 lines (29 loc) 1.12 kB
'use strict'; const { applyTransformationsOnNonDictionary } = require('../model/csnUtils'); /** * Checks a query for forbidden usage of the `exists` predicate within `groupBy` and `orderBy`. * * @param {object} query * @param {string} prop - either groupBy or orderBy. * @param {object[]} _tokenStream the value of query[prop] * @param {object|Array} pathToClause - Path to respective groupBy/orderBy clause in the CSN. * @this {object} The calling context must provide an `error` function. */ function existsInForbiddenPlaces( query, prop, _tokenStream, pathToClause ) { applyTransformationsOnNonDictionary(query, prop, { ref: (_parent, _prop, _ref, pathToError, tokenStream, index) => { if (tokenStream[index - 1] === 'exists') { // the path should point to the exists const pathToExists = pathToError.with(-1, index - 1); this.error('query-unexpected-exists', pathToExists, { '#': prop, prop: 'exists', }); } }, }, null, pathToClause); } module.exports = { groupBy: existsInForbiddenPlaces, orderBy: existsInForbiddenPlaces, };