@sap/cds-compiler
Advanced tools
Comparing version 2.15.4 to 2.15.6
@@ -39,3 +39,3 @@ /** @module API */ | ||
const { ModelError } = require('../base/error'); | ||
const { forEach } = require('../utils/objectUtils'); | ||
const { forEach, forEachKey } = require('../utils/objectUtils'); | ||
@@ -643,2 +643,3 @@ const relevantGeneralOptions = [ /* for future generic options */ ]; | ||
try { | ||
checkOutdatedOptions( options ); | ||
return processor( csn, options, ...args ); | ||
@@ -667,3 +668,45 @@ } | ||
// Note: No toCsn, because @sap/cds may still use it (2022-06-15) | ||
const oldBackendOptionNames = [ 'toSql', 'toOdata', 'toHana', 'forHana' ]; | ||
/** | ||
* Checks if outdated options are used and if so, throw a compiler error. | ||
* These include: | ||
* - magicVars (now variableReplacements) | ||
* - toOdata/toSql/toHana/forHana -> now flat options | ||
* | ||
* @param {CSN.Options} options Backend options | ||
*/ | ||
function checkOutdatedOptions(options) { | ||
if (!options) | ||
return; | ||
const { warning } = makeMessageFunction(null, options, 'api'); | ||
// This warning has been emitted once, we don't need to emit it again. | ||
if (options.messages && options.messages.some(m => m.messageId === 'api-invalid-option')) | ||
return; | ||
for (const name of oldBackendOptionNames) { | ||
if (typeof options[name] === 'object') // may be a boolean due to internal options | ||
warning('api-invalid-option', null, { '#': 'std', name }); | ||
} | ||
if (options.magicVars) | ||
warning('api-invalid-option', null, { '#': 'magicVars' }); | ||
// Don't check `options.magicVars`. It's likely that the user renamed `magicVars` but | ||
// forgot about user -> $user and locale -> $user.locale | ||
if (options.variableReplacements) { | ||
if (options.variableReplacements.user) | ||
warning('api-invalid-option', null, { '#': 'user' }); | ||
if (options.variableReplacements.locale) | ||
warning('api-invalid-option', null, { '#': 'locale' }); | ||
} | ||
forEachKey(options.variableReplacements || {}, (name) => { | ||
if (!name.startsWith('$') && name !== 'user' && name !== 'locale') | ||
warning('api-invalid-option', null, { '#': 'noDollar', name }); | ||
}); | ||
} | ||
/** | ||
@@ -670,0 +713,0 @@ * Option format used by the old API, where they are grouped thematically. |
@@ -196,2 +196,10 @@ // Central registry for messages. | ||
const centralMessageTexts = { | ||
'api-invalid-option': { | ||
std: 'Option $(NAME) is deprecated! Use SNAPI options instead', | ||
magicVars: 'Option “magicVars” is deprecated! Use “variableReplacements” instead. See <https://cap.cloud.sap/docs/guides/databases#configuring-variables> for details', | ||
user: 'Option “variableReplacements” expects “$user” instead of “user”. See <https://cap.cloud.sap/docs/guides/databases#configuring-variables> for details', | ||
locale: 'Option “variableReplacements” expects “$user.locale” instead of “locale”. See <https://cap.cloud.sap/docs/guides/databases#configuring-variables> for details', | ||
'noDollar': 'Option “variableReplacements” does not know $(NAME). Did you forget a leading “$”?' | ||
}, | ||
'anno-duplicate': 'Duplicate assignment with $(ANNO)', | ||
@@ -198,0 +206,0 @@ 'anno-mismatched-ellipsis': 'An array with $(CODE) can only be used if there is an assignment below with an array value', |
@@ -112,2 +112,4 @@ // Populate views with elements, elements with association targets, ... | ||
environment( art ); | ||
if (art.elements$) | ||
mergeSpecifiedElements(art); | ||
forEachMember( art, traverseElementEnvironments ); | ||
@@ -429,4 +431,2 @@ } | ||
traverseQueryPost( view.query, null, populateQuery ); | ||
if (view.elements$) // specified elements | ||
mergeSpecifiedElements( view ); | ||
if (!view.$entity) { | ||
@@ -440,10 +440,21 @@ model._entities.push( view ); | ||
function mergeSpecifiedElements( view ) { | ||
/** | ||
* Merge _specified_ elements with _inferred_ elements in the given view/element, | ||
* where specified elements can appear through CSN. | ||
* | ||
* We only copy annotations, since they are not part of `columns`, | ||
* but only appear in `elements` in CSN. | ||
* | ||
* This is important to ensure re-compilability. | ||
* | ||
* @param art | ||
*/ | ||
function mergeSpecifiedElements( art ) { | ||
// Later we use specified elements as proxies to inferred of leading query | ||
// (No, we probably do not.) | ||
for (const id in view.elements) { | ||
const ielem = view.elements[id]; // inferred element | ||
const selem = view.elements$[id]; // specified element | ||
for (const id in art.elements) { | ||
const ielem = art.elements[id]; // inferred element | ||
const selem = art.elements$[id]; // specified element | ||
if (!selem) { | ||
info( 'query-missing-element', [ ielem.name.location, view ], { id }, | ||
info( 'query-missing-element', [ ielem.name.location, art ], { id }, | ||
'Element $(ID) is missing in specified elements' ); | ||
@@ -458,9 +469,16 @@ } | ||
selem.$replacement = true; | ||
if (selem.elements) { | ||
setLink(ielem, 'elements$', selem.elements); | ||
delete selem.elements; | ||
} | ||
} | ||
} | ||
for (const id in view.elements$) { | ||
const selem = view.elements$[id]; // specified element | ||
if (!selem.$replacement) { | ||
error( 'query-unspecified-element', [ selem.name.location, selem ], { id }, | ||
'Element $(ID) does not result from the query' ); | ||
// Without element expansion, we can't merge nested elements. | ||
if (art.kind === 'entity' || enableExpandElements) { | ||
for (const id in art.elements$) { | ||
const selem = art.elements$[id]; // specified element | ||
if (!selem.$replacement) { | ||
error( 'query-unspecified-element', [ selem.name.location, selem ], { id }, | ||
'Element $(ID) does not result from the query' ); | ||
} | ||
} | ||
@@ -467,0 +485,0 @@ } |
{ | ||
"name": "@sap/cds-compiler", | ||
"version": "2.15.4", | ||
"version": "2.15.6", | ||
"description": "CDS (Core Data Services) compiler and backends", | ||
@@ -5,0 +5,0 @@ "homepage": "https://cap.cloud.sap/", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4051040
80082