@sap/cds-compiler 5.4.0 → 5.4.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,19 @@
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 5.4.4 - 2024-11-14
11
+
12
+ ### Fixed
13
+
14
+ - Re-allow referring to mixins (and table aliases) in added columns
15
+ - Re-add foreign keys of named aspects to the OData CSN.
16
+
17
+ ## Version 5.4.2 - 2024-11-06
18
+
19
+ ### Fixed
20
+
21
+ - to.sql: For SQLite, map `cds.Map` to `JSON_TEXT` to ensure text affinity.
22
+
10
23
  ## Version 5.4.0 - 2024-10-24
11
24
 
12
25
  ### Added
@@ -1038,6 +1038,12 @@ const centralMessageTexts = {
1038
1038
  none: 'Ambiguous $(ID) requires an explicit table alias, but there are none: add table aliases to all sub-queries to disambiguate $(ID)',
1039
1039
  },
1040
1040
 
1041
+ 'ref-special-in-extend': {
1042
+ std: 'In an added column, $(ID) refers to the element of the projection source $(ART), not the table alias or mixin',
1043
+ alias: 'In an added column, $(ID) refers to the element of the projection source $(ART), not the table alias',
1044
+ mixin: 'In an added column, $(ID) refers to the element of the projection source $(ART), not the mixin',
1045
+ },
1046
+
1041
1047
  'type-managed-composition': {
1042
1048
  std: 'Managed compositions can\'t be used in types', // yet
1043
1049
  sub: 'Managed compositions can\'t be used in sub elements',
@@ -174,7 +174,7 @@ function fns( model ) {
174
174
  having: 'where',
175
175
  groupBy: 'where',
176
176
  column: {
177
- lexical: tableAliasesIfNotExtendAndSelf,
177
+ lexical: tableAliasesAndSelf,
178
178
  dollar: true,
179
179
  dynamic: combinedSourcesOrParentElements,
180
180
  notFound: undefinedSourceElement,
@@ -721,16 +721,41 @@ function fns( model ) {
721
721
  return setArtifactLink( head, def ); // we do not want to see the using
722
722
  }
723
723
  case 'mixin': {
724
+ // use a source element having that name if in `extend … with columns`:
725
+ const elem = (user._user || user).$extended &&
726
+ art._parent._combined[head.id];
727
+ if (elem) {
728
+ path.$prefix = elem._parent.name.id; // prepend alias name
729
+ info( 'ref-special-in-extend', [ head.location, user ],
730
+ { '#': 'mixin', id: head.id, art: elem._origin._main } );
731
+ setLink( head, '_navigation', elem );
732
+ return setArtifactLink( head, elem._origin );
733
+ }
724
734
  return setLink( head, '_navigation', art );
725
735
  }
726
736
  case '$navElement': {
727
- if (head.id === (user._user || user).$extended)
728
- path.$prefix = head.id;
729
737
  setLink( head, '_navigation', art );
730
738
  return setArtifactLink( head, art._origin );
731
739
  }
732
- case '$self': // TODO: remove $projection from CC
733
740
  case '$tableAlias': {
741
+ // use a source element having that name if in `extend … with columns`:
742
+ const { $extended } = user._user || user;
743
+ const elem = $extended && art.elements[head.id];
744
+ if (elem) {
745
+ path.$prefix = art.name.id; // prepend alias name
746
+ info( 'ref-special-in-extend', [ head.location, user ],
747
+ { '#': 'alias', id: head.id, art: elem._origin._main } );
748
+ setLink( head, '_navigation', elem );
749
+ return setArtifactLink( head, elem._origin );
750
+ }
751
+ else if ($extended) {
752
+ warning( 'ref-deprecated-in-extend', [ head.location, user ], { id: head.id },
753
+ // eslint-disable-next-line @stylistic/js/max-len
754
+ 'In an added column, do not use the table alias $(ID) to refer to source elements' );
755
+ }
756
+ }
757
+ /* FALLTHROUGH */
758
+ case '$self': { // TODO: remove $projection from CC
734
759
  setLink( head, '_navigation', art );
735
760
  setArtifactLink( head, art._origin ); // query source or leading query in FROM
736
761
  if (!art._origin)
@@ -842,15 +867,6 @@ function fns( model ) {
842
867
  function tableAliasesAndSelf( user ) {
843
868
  return userQuery( user ) || user._main || user;
844
869
  }
845
- function tableAliasesIfNotExtendAndSelf( user ) {
846
- if (!user.$extended)
847
- return tableAliasesAndSelf( user );
848
- if (typeof user.$extended !== 'string') {
849
- const aliases = userQuery( user ).$tableAliases;
850
- user.$extended = Object.keys( aliases )[0];
851
- }
852
- return justDollarAliases( user );
853
- }
854
870
 
855
871
  // Functions called via semantics.dynamic: ------------------------------------
856
872
 
@@ -1202,7 +1202,9 @@ function exprInternal( node, xprParens ) {
1202
1202
  }
1203
1203
  if (node.path) {
1204
1204
  const ref = node.path.map( pathItem );
1205
- if (node.path.$prefix) // auto-corrected ORDER BY refs without table alias
1205
+ // auto-corrected ORDER BY refs without table alias, or EXTEND … WITH COLUMN
1206
+ // refs to source element shadowed by alias name:
1207
+ if (node.path.$prefix)
1206
1208
  ref.unshift( node.path.$prefix );
1207
1209
  // we would need to consider node.global here if we introduce that
1208
1210
  return extra( { ref }, node );
@@ -282,7 +282,7 @@ const cdsToSqlTypes = {
282
282
  'cds.hana.BINARY': 'BINARY_BLOB',
283
283
  'cds.hana.SMALLDECIMAL': 'SMALLDECIMAL',
284
284
  'cds.Vector': 'BINARY_BLOB', // Not supported; see #11725
285
- 'cds.Map': 'JSON',
285
+ 'cds.Map': 'JSON_TEXT', // '_TEXT' suffix required for text affinity
286
286
  },
287
287
  plain: {
288
288
  'cds.Binary': 'VARBINARY',
@@ -10,7 +10,7 @@ function createForeignKeyElements(csn, options, messageFunctions, csnUtils, iter
10
10
  const { error } = messageFunctions;
11
11
 
12
12
  applyTransformations(csn, { elements: createForeignKeysInCsn, params: createForeignKeysInCsn},
13
- [], Object.assign(iterateOptions, { skip: ['aspect', 'event'], skipStandard: { targetAspect: true } }));
13
+ [], Object.assign(iterateOptions, { skip: ['event'], skipStandard: { targetAspect: true } }));
14
14
 
15
15
  /**
16
16
  * Process a given elements or params dictionary and create foreign key elements.
@@ -142,7 +142,7 @@ function allInOneFlattening(csn, refFlattener, adaptRefs, inspectRef, getFinalTy
142
142
  }
143
143
  // loop through types as well in order to collect the managaed associations
144
144
  // that reside in types definitions
145
- if ((def.kind === 'action' || def.kind === 'function' || def.kind === 'type') && !isExternalServiceMember(def, defName)) {
145
+ if ((def.kind === 'action' || def.kind === 'function' || def.kind === 'type' || def.kind === 'aspect') && !isExternalServiceMember(def, defName)) {
146
146
  if (def.kind === 'type' && csnUtils.isManagedAssociation(def))
147
147
  allMgdAssocDefs.push(def);
148
148
  else
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap/cds-compiler",
3
- "version": "5.4.0",
3
+ "version": "5.4.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)",