@sap/cds-compiler 4.2.2 → 4.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,12 @@
7
7
  Note: `beta` fixes, changes and features are usually not listed in this ChangeLog but [here](doc/CHANGELOG_BETA.md).
8
8
  The compiler behavior concerning `beta` features can change at any time without notice.
9
9
 
10
+ ## Version 4.2.4 - 2023-09-14
11
+
12
+ ### Fixed
13
+
14
+ - OData: For compatibility with the Java runtime, don't prepend table aliases to column aliases unless necessary.
15
+
10
16
  ## Version 4.2.2 - 2023-08-31
11
17
 
12
18
  ### Fixed
package/lib/base/model.js CHANGED
@@ -46,6 +46,7 @@ const availableDeprecatedFlags = {
46
46
  includesNonShadowedFirst: true,
47
47
  eagerPersistenceForGeneratedEntities: true,
48
48
  noKeyPropagationWithExpansions: true,
49
+ ignoreSpecifiedQueryElements: true,
49
50
  }
50
51
 
51
52
  const oldDeprecatedFlags_v2 = [
@@ -7,7 +7,7 @@ const {
7
7
  walkCsnPath,
8
8
  getUtils,
9
9
  } = require('../../model/csnUtils');
10
- const { implicitAs, columnAlias } = require('../../model/csnRefs');
10
+ const { implicitAs, columnAlias, pathId } = require('../../model/csnRefs');
11
11
  const { setProp } = require('../../base/model');
12
12
  const { forEach } = require('../../utils/objectUtils');
13
13
 
@@ -39,9 +39,10 @@ function expandStructureReferences( csn, options, pathDelimiter, messageFunction
39
39
  // TODO: replace with the correct options.transformation?
40
40
  // Do not expand the * in OData for a moment, not to introduce changes
41
41
  // while the OData CSN is still official
42
+ const isComplexQuery = parent.from.join !== undefined;
42
43
  if (!options.toOdata)
43
- parent.columns = replaceStar(root, columns, parent.excluding, parent.from.join !== undefined);
44
- parent.columns = expand(parent.columns, path.concat('columns'), true);
44
+ parent.columns = replaceStar(root, columns, parent.excluding, isComplexQuery);
45
+ parent.columns = expand(parent.columns, path.concat('columns'), true, isComplexQuery);
45
46
  }
46
47
  },
47
48
  groupBy: (parent, name, groupBy, path) => {
@@ -512,16 +513,17 @@ function expandStructureReferences( csn, options, pathDelimiter, messageFunction
512
513
  * @param {Array} thing
513
514
  * @param {CSN.Path} path
514
515
  * @param {boolean} [withAlias=false] Whether to "expand" the (implicit) alias as well.
516
+ * @param {boolean} [isComplexQuery]
515
517
  * @returns {Array} New array - with all structured things expanded
516
518
  */
517
- function expand( thing, path, withAlias = false ) {
519
+ function expand( thing, path, withAlias = false, isComplexQuery = false ) {
518
520
  const newThing = [];
519
521
  for (let i = 0; i < thing.length; i++) {
520
522
  const col = thing[i];
521
523
  if (col.ref && col.$scope !== '$magic') {
522
524
  const _art = col._art || csnUtils.inspectRef(path.concat(i)).art;
523
525
  if (_art && csnUtils.isStructured(_art))
524
- newThing.push(...expandRef(_art, col, withAlias));
526
+ newThing.push(...expandRef(_art, col, withAlias, isComplexQuery));
525
527
  else
526
528
  newThing.push(col);
527
529
  }
@@ -596,9 +598,10 @@ function expandStructureReferences( csn, options, pathDelimiter, messageFunction
596
598
  * @param {CSN.Element} art
597
599
  * @param {object} root Column, ref in order by, etc.
598
600
  * @param {boolean} withAlias Whether to add an explicit flattened alias to the expanded columns/references.
601
+ * @param {boolean} [isComplexQuery]
599
602
  * @returns {Array}
600
603
  */
601
- function expandRef( art, root, withAlias ) {
604
+ function expandRef( art, root, withAlias, isComplexQuery ) {
602
605
  return _expandStructCol(art, columnAlias(root), root.ref, ( currentRef, currentAlias) => {
603
606
  const obj = { ...root, ref: currentRef };
604
607
  if (withAlias) {
@@ -613,7 +616,13 @@ function expandStructureReferences( csn, options, pathDelimiter, messageFunction
613
616
  setProp(obj, '$implicitAlias', true);
614
617
  }
615
618
 
616
- if (typeof root.$env === 'string')
619
+ // The Java runtime, as of 2023-09-13, assumes that for _simple projections_, all references
620
+ // are relative to the query source. To avoid breaking that assumption unless necessary,
621
+ // we only add the table alias if:
622
+ // - it is a complex query with possibly multiple available table aliases, or
623
+ // - the transformation is not for OData (which is used by Java), or
624
+ // - the first path step has the same name as the table alias (only one, as otherwise the query would be complex)
625
+ if (typeof root.$env === 'string' && (isComplexQuery || options.transformation !== 'odata' || root.$env === pathId(obj.ref[0])))
617
626
  obj.ref = [ root.$env, ...obj.ref ];
618
627
 
619
628
  return obj;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap/cds-compiler",
3
- "version": "4.2.2",
3
+ "version": "4.2.4",
4
4
  "description": "CDS (Core Data Services) compiler and backends",
5
5
  "homepage": "https://cap.cloud.sap/",
6
6
  "author": "SAP SE (https://www.sap.com)",