@sap/cds-compiler 3.5.0 → 3.5.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,20 @@
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 3.5.4 - 2023-01-10
11
+
12
+ ### Fixed
13
+
14
+ - Allow window functions also with a deprecated flag being set.
15
+ - to.edm(x): Fix program abort due to malformed error location in EDM annotation preprocessing.
16
+ - to.sql/hdi/hdbcds: The option `pre2134ReferentialConstraintNames` can be used to omit the referential constraint identifier prefix "c__".
17
+
18
+ ## Version 3.5.2 - 2022-12-20
19
+
20
+ ### Fixed
21
+
22
+ - to.sql/hdi/hdbcds: Don't process references in actions, as they have no impact on the database - avoids internal errors
23
+
10
24
  ## Version 3.5.0 - 2022-12-07
11
25
 
12
26
  ### Added
@@ -20,26 +34,6 @@ The compiler behavior concerning `beta` features can change at any time without
20
34
  - If option `addTextsLanguageAssoc` is set but ignored by the compiler, an info message is emitted.
21
35
  This can happen if, e.g., the `sap.common.Languages` entity is missing.
22
36
  - Add OData vocabularies 'Offline' and 'PDF'.
23
- - Two new aspects in the `sap.common` context get special meaning:
24
- `sap.common.TextsAspect` and `sap.common.FioriTextsAspect`.
25
- If these aspects exist, the former will be included in all `.texts`
26
- entities without `@fiori.draft.enabled` annotation. The latter will be
27
- included in all `.texts` aspects that are `@fiori.draft.enabled`.
28
- They allow to extend `.texts` entities by simply extending these aspects.
29
- Example:
30
- ```
31
- entity E {
32
- key id : Integer;
33
- content: localized String;
34
- }
35
- extend sap.common.TextsAspect with {
36
- elem: String;
37
- };
38
- // from @sap/cds common.cds
39
- aspect sap.common.TextsAspect {
40
- key locale: String;
41
- }
42
- ```
43
37
 
44
38
  ### Changed
45
39
 
@@ -27,6 +27,7 @@ const publicOptionsNewAPI = [
27
27
  'joinfk',
28
28
  'magicVars', // deprecated, not removed in v3 as we have specific error messages for it
29
29
  'variableReplacements',
30
+ 'pre2134ReferentialConstraintNames',
30
31
  // ODATA
31
32
  'odataVersion',
32
33
  'odataFormat',
package/lib/base/model.js CHANGED
@@ -37,6 +37,30 @@ const availableBetaFlags = {
37
37
  nestedServices: false,
38
38
  };
39
39
 
40
+ const availableDeprecatedFlags = {
41
+ // the old ones starting with _, : false
42
+ autoCorrectOrderBySourceRefs: true,
43
+ eagerPersistenceForGeneratedEntities: true,
44
+ }
45
+
46
+ const oldDeprecatedFlags_v2 = [
47
+ 'createLocalizedViews',
48
+ 'downgradableErrors',
49
+ 'generatedEntityNameWithUnderscore',
50
+ 'longAutoexposed',
51
+ 'noElementsExpansion',
52
+ 'noInheritedAutoexposeViaComposition',
53
+ 'noScopedRedirections',
54
+ 'oldVirtualNotNullPropagation',
55
+ 'parensAsStrings',
56
+ 'projectionAsQuery',
57
+ 'redirectInSubQueries',
58
+ 'renderVirtualElements',
59
+ 'shortAutoexposed',
60
+ 'unmanagedUpInComponent',
61
+ 'v1KeysForTemporal',
62
+ ];
63
+
40
64
  /**
41
65
  * Test for early-adaptor feature, stored in option `beta`(new-style) / `betaMode`(old-style)
42
66
  * With that, the value of `beta` is a dictionary of feature=>Boolean.
@@ -59,7 +83,11 @@ function isBetaEnabled( options, feature ) {
59
83
  /**
60
84
  * Test for deprecated feature, stored in option `deprecated`.
61
85
  * With that, the value of `deprecated` is a dictionary of feature=>Boolean.
62
- * If no `feature` is provided, checks if any deprecated option is set.
86
+ *
87
+ * If no `feature` is provided, checks if any deprecated option is set
88
+ * which is not mentioned in availableDeprecatedFlags with value true.
89
+ * Useful for newer functionality which might not work with some
90
+ * deprecated feature turned on.
63
91
  *
64
92
  * Please do not move this function to the "option processor" code.
65
93
  *
@@ -69,30 +97,13 @@ function isBetaEnabled( options, feature ) {
69
97
  */
70
98
  function isDeprecatedEnabled( options, feature = null ) {
71
99
  const { deprecated } = options;
72
- if (!feature)
73
- return !!deprecated;
74
-
100
+ if (!feature) {
101
+ return !!deprecated && Object.keys( deprecated )
102
+ .some( d => !availableDeprecatedFlags[d] );
103
+ }
75
104
  return deprecated && typeof deprecated === 'object' && deprecated[feature];
76
105
  }
77
106
 
78
- const oldDeprecatedFlags_v2 = [
79
- 'createLocalizedViews',
80
- 'downgradableErrors',
81
- 'generatedEntityNameWithUnderscore',
82
- 'longAutoexposed',
83
- 'noElementsExpansion',
84
- 'noInheritedAutoexposeViaComposition',
85
- 'noScopedRedirections',
86
- 'oldVirtualNotNullPropagation',
87
- 'parensAsStrings',
88
- 'projectionAsQuery',
89
- 'redirectInSubQueries',
90
- 'renderVirtualElements',
91
- 'shortAutoexposed',
92
- 'unmanagedUpInComponent',
93
- 'v1KeysForTemporal',
94
- ];
95
-
96
107
  /**
97
108
  * In cds-compiler v3, we removed old v2 deprecated flags. That can lead to silent
98
109
  * errors such as entity/view names changing. To ensure that the user is forced
@@ -39,7 +39,6 @@
39
39
  'use strict';
40
40
 
41
41
  const {
42
- isDeprecatedEnabled,
43
42
  forEachDefinition,
44
43
  forEachMember,
45
44
  forEachGeneric,
@@ -80,7 +79,7 @@ const $inferred = Symbol.for('cds.$inferred');
80
79
  // exception in case of an error, but push the corresponding error object to
81
80
  // that property (should be a vector).
82
81
  function resolve( model ) {
83
- const { options } = model;
82
+ // const { options } = model;
84
83
  // Get shared functionality and the message function:
85
84
  const {
86
85
  info, warning, error, message,
@@ -1328,11 +1327,6 @@ function resolve( model ) {
1328
1327
  const args = Array.isArray(expr.args) ? expr.args : Object.values( expr.args );
1329
1328
  args.forEach( e => e && resolveExpr( e, e.$expected || expected, user, extDict ) );
1330
1329
  }
1331
- if (expr.suffix && isDeprecatedEnabled( options )) {
1332
- const { location } = expr.suffix[0] || expr;
1333
- error( null, [ location, user ], { prop: 'deprecated' },
1334
- 'Window functions are not supported if $(PROP) options are set' );
1335
- }
1336
1330
  if (expr.suffix)
1337
1331
  expr.suffix.forEach( s => s && resolveExpr( s, expected, user, extDict ) );
1338
1332
  }
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const { makeMessageFunction } = require('../../base/messages.js');
4
- const { forEachDefinition } = require('../../model/csnUtils.js');
4
+ const { forEachDefinition, forEachGeneric } = require('../../model/csnUtils.js');
5
5
 
6
6
 
7
7
  /**************************************************************************************************
@@ -66,9 +66,9 @@ function preprocessAnnotations(csn, serviceName, options) {
66
66
  artifact.elements && Object.entries(artifact.elements).forEach(([elementName, element]) => {
67
67
  handleAnnotations(elementName, element, [ ...location, 'elements', elementName ]);
68
68
  });
69
- artifact.actions && Object.values(artifact.actions).forEach(action => {
69
+ forEachGeneric(artifact, 'actions', (action, actionName) => {
70
70
  action.params && Object.entries(action.params).forEach(([paramName, param]) => {
71
- handleAnnotations(paramName, param, [ ...location, 'actions', action, 'params', paramName ]);
71
+ handleAnnotations(paramName, param, [ ...location, 'actions', actionName, 'params', paramName ]);
72
72
  });
73
73
  });
74
74
  }
@@ -166,6 +166,7 @@ optionProcessor.command('H, toHana')
166
166
  .option(' --integrity-not-enforced')
167
167
  .option(' --assert-integrity <mode>', ['true', 'false', 'individual'])
168
168
  .option(' --assert-integrity-type <type>', ['RT', 'DB'], { ignoreCase: true })
169
+ .option(' --pre2134ReferentialConstraintNames')
169
170
  .option(' --disable-hana-comments')
170
171
  .help(`
171
172
  Usage: cdsc toHana [options] <files...>
@@ -201,6 +202,7 @@ optionProcessor.command('H, toHana')
201
202
  RT : (default) No database constraint for an association
202
203
  if not explicitly demanded via annotation
203
204
  DB : Create database constraints for associations
205
+ --pre2134ReferentialConstraintNames Do not prefix the constraint identifier with "c__"
204
206
  --disable-hana-comments Disable rendering of doc comments as SAP HANA comments.
205
207
  `);
206
208
 
@@ -280,6 +282,7 @@ optionProcessor.command('Q, toSql')
280
282
  .option(' --assert-integrity <mode>', ['true', 'false', 'individual'])
281
283
  .option(' --assert-integrity-type <type>', ['RT', 'DB'], { ignoreCase: true })
282
284
  .option(' --constraints-in-create-table')
285
+ .option(' --pre2134ReferentialConstraintNames')
283
286
  .option(' --disable-hana-comments')
284
287
  .help(`
285
288
  Usage: cdsc toSql [options] <files...>
@@ -329,6 +332,7 @@ optionProcessor.command('Q, toSql')
329
332
  --constraints-in-create-table If set, the foreign key constraints will be rendered as
330
333
  part of the "CREATE TABLE" statements rather than as separate
331
334
  "ALTER TABLE ADD CONSTRAINT" statements
335
+ --pre2134ReferentialConstraintNames Do not prefix the constraint identifier with "c__"
332
336
  --disable-hana-comments Disable rendering of doc comments as SAP HANA comments.
333
337
  `);
334
338
 
@@ -146,7 +146,7 @@ function toHdbcdsSource( csn, options ) {
146
146
  Object.entries(art.$tableConstraints.referential)
147
147
  .forEach(([ fileName, referentialConstraint ]) => {
148
148
  referentialConstraints[fileName] = renderReferentialConstraint(
149
- referentialConstraint, '', renderToUppercase, csn, options
149
+ referentialConstraint, increaseIndent(createEnv()).indent, renderToUppercase, csn, options
150
150
  );
151
151
  });
152
152
  Object.entries(referentialConstraints)
@@ -65,8 +65,7 @@ function renderReferentialConstraint( constraint, indent, toUpperCase, csn, opti
65
65
  }
66
66
  // constraint enforcement / validation must be switched off using sqlite pragma statement
67
67
  // constraint enforcement / validation not supported by postgres
68
- // Does not include HDBCDS.
69
- if (options.toSql && sqlDialect !== 'sqlite' && sqlDialect !== 'postgres') {
68
+ if (options.transformation === 'hdbcds' || (options.toSql && sqlDialect !== 'sqlite' && sqlDialect !== 'postgres')) {
70
69
  result += `${indent}${!constraint.validated ? 'NOT ' : ''}VALIDATED\n`;
71
70
  result += `${indent}${!constraint.enforced ? 'NOT ' : ''}ENFORCED\n`;
72
71
  }
@@ -515,9 +515,11 @@ function createReferentialConstraints( csn, options ) {
515
515
  // comments in sqlite files are causing the JDBC driver to throw an error on deployment
516
516
  if (options.testMode && onDelete === 'CASCADE')
517
517
  onDeleteRemark = `Up_ link for Composition "${$foreignKeyConstraint.upLinkFor}" implies existential dependency`;
518
+ // constraint identifier usually start with `c__` to avoid name clashes
519
+ let identifier = options.pre2134ReferentialConstraintNames ? '' : 'c__';
520
+ identifier += `${getResultingName(csn, options.sqlMapping, artifactName)}_${$foreignKeyConstraint.sourceAssociation}`;
518
521
  referentialConstraints[`${getResultingName(csn, 'quoted', artifactName)}_${$foreignKeyConstraint.sourceAssociation}`] = {
519
- // constraint identifier start with `c__` to avoid name clashes
520
- identifier: `c__${getResultingName(csn, options.sqlMapping, artifactName)}_${$foreignKeyConstraint.sourceAssociation}`,
522
+ identifier,
521
523
  foreignKey: dependentKey,
522
524
  parentKey,
523
525
  dependentTable: artifactName,
@@ -260,7 +260,7 @@ function transformForRelationalDBWithCsn(inputModel, options, moduleName) {
260
260
  forEachDefinition(csn, temporal.getAnnotationHandler(csn, options, pathDelimiter, {error}));
261
261
 
262
262
  // eliminate the doA2J in the functions 'handleManagedAssociationFKs' and 'createForeignKeyElements'
263
- doA2J && flattening.handleManagedAssociationsAndCreateForeignKeys(csn, options, error, pathDelimiter, true, { allowArtifact: artifact => (artifact.kind === 'entity') });
263
+ doA2J && flattening.handleManagedAssociationsAndCreateForeignKeys(csn, options, error, pathDelimiter, true, { skipDict: { actions: true }, allowArtifact: artifact => (artifact.kind === 'entity') });
264
264
 
265
265
  doA2J && forEachDefinition(csn, flattenIndexes);
266
266
  // Managed associations get an on-condition - in views and entities
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap/cds-compiler",
3
- "version": "3.5.0",
3
+ "version": "3.5.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)",