@sap/cds-compiler 3.9.4 → 4.0.2

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.
Files changed (95) hide show
  1. package/CHANGELOG.md +107 -4
  2. package/README.md +0 -1
  3. package/bin/cdsc.js +11 -23
  4. package/bin/cdsse.js +3 -3
  5. package/doc/API.md +5 -0
  6. package/doc/CHANGELOG_ARCHIVE.md +1 -1
  7. package/doc/CHANGELOG_BETA.md +17 -1
  8. package/doc/CHANGELOG_DEPRECATED.md +28 -0
  9. package/lib/api/.eslintrc.json +1 -1
  10. package/lib/api/main.js +55 -9
  11. package/lib/api/options.js +2 -0
  12. package/lib/base/error.js +2 -0
  13. package/lib/base/message-registry.js +143 -64
  14. package/lib/base/messages.js +213 -107
  15. package/lib/base/model.js +11 -11
  16. package/lib/checks/.eslintrc.json +1 -1
  17. package/lib/checks/annotationsOData.js +2 -2
  18. package/lib/checks/elements.js +1 -1
  19. package/lib/checks/enricher.js +26 -3
  20. package/lib/checks/onConditions.js +67 -12
  21. package/lib/checks/queryNoDbArtifacts.js +106 -105
  22. package/lib/checks/sql-snippets.js +2 -0
  23. package/lib/checks/types.js +12 -6
  24. package/lib/checks/validator.js +2 -2
  25. package/lib/compiler/assert-consistency.js +10 -8
  26. package/lib/compiler/builtins.js +8 -2
  27. package/lib/compiler/checks.js +52 -35
  28. package/lib/compiler/define.js +31 -26
  29. package/lib/compiler/extend.js +120 -65
  30. package/lib/compiler/finalize-parse-cdl.js +12 -43
  31. package/lib/compiler/generate.js +16 -5
  32. package/lib/compiler/index.js +8 -5
  33. package/lib/compiler/kick-start.js +4 -3
  34. package/lib/compiler/populate.js +96 -95
  35. package/lib/compiler/propagator.js +7 -8
  36. package/lib/compiler/resolve.js +377 -103
  37. package/lib/compiler/shared.js +794 -517
  38. package/lib/compiler/tweak-assocs.js +8 -6
  39. package/lib/compiler/utils.js +44 -0
  40. package/lib/edm/annotations/genericTranslation.js +41 -5
  41. package/lib/edm/csn2edm.js +34 -32
  42. package/lib/edm/edm.js +34 -31
  43. package/lib/edm/edmAnnoPreprocessor.js +0 -23
  44. package/lib/edm/edmInboundChecks.js +7 -2
  45. package/lib/edm/edmPreprocessor.js +25 -18
  46. package/lib/edm/edmUtils.js +8 -4
  47. package/lib/gen/Dictionary.json +18 -0
  48. package/lib/gen/language.checksum +1 -1
  49. package/lib/gen/language.interp +4 -2
  50. package/lib/gen/languageParser.js +5006 -4582
  51. package/lib/json/from-csn.js +157 -112
  52. package/lib/json/to-csn.js +60 -89
  53. package/lib/language/antlrParser.js +17 -13
  54. package/lib/language/docCommentParser.js +11 -1
  55. package/lib/language/genericAntlrParser.js +13 -10
  56. package/lib/language/language.g4 +168 -97
  57. package/lib/main.d.ts +128 -36
  58. package/lib/main.js +1 -1
  59. package/lib/model/csnRefs.js +24 -5
  60. package/lib/model/csnUtils.js +9 -8
  61. package/lib/model/revealInternalProperties.js +7 -12
  62. package/lib/model/sortViews.js +4 -2
  63. package/lib/modelCompare/compare.js +1 -1
  64. package/lib/modelCompare/utils/filter.js +40 -2
  65. package/lib/optionProcessor.js +0 -3
  66. package/lib/render/toCdl.js +247 -214
  67. package/lib/render/toHdbcds.js +197 -181
  68. package/lib/render/toSql.js +325 -289
  69. package/lib/render/utils/common.js +42 -4
  70. package/lib/render/utils/delta.js +1 -1
  71. package/lib/render/utils/sql.js +3 -3
  72. package/lib/transform/braceExpression.js +2 -2
  73. package/lib/transform/db/.eslintrc.json +1 -1
  74. package/lib/transform/db/applyTransformations.js +3 -3
  75. package/lib/transform/db/associations.js +24 -12
  76. package/lib/transform/db/expansion.js +17 -18
  77. package/lib/transform/db/flattening.js +17 -21
  78. package/lib/transform/db/rewriteCalculatedElements.js +171 -64
  79. package/lib/transform/db/views.js +3 -4
  80. package/lib/transform/draft/db.js +21 -12
  81. package/lib/transform/draft/odata.js +4 -0
  82. package/lib/transform/forOdataNew.js +62 -47
  83. package/lib/transform/forRelationalDB.js +12 -7
  84. package/lib/transform/localized.js +4 -2
  85. package/lib/transform/odata/toFinalBaseType.js +5 -5
  86. package/lib/transform/odata/typesExposure.js +3 -3
  87. package/lib/transform/parseExpr.js +3 -0
  88. package/lib/transform/transformUtilsNew.js +43 -23
  89. package/lib/transform/translateAssocsToJoins.js +7 -6
  90. package/lib/transform/universalCsn/.eslintrc.json +1 -1
  91. package/lib/transform/universalCsn/coreComputed.js +7 -5
  92. package/lib/transform/universalCsn/universalCsnEnricher.js +12 -12
  93. package/package.json +2 -2
  94. package/share/messages/{duplicate-autoexposed.md → def-duplicate-autoexposed.md} +5 -1
  95. package/share/messages/message-explanations.json +1 -1
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const { setProp, isBetaEnabled } = require('../../base/model');
3
+ const { setProp } = require('../../base/model');
4
4
  const shuffleGen = require('../../base/shuffle');
5
5
  const { setAnnotationIfNotDefined, makeClientCompatible } = require('./utils');
6
6
  const {
@@ -23,7 +23,6 @@ const { setCoreComputedOnViewsAndCalculatedElements } = require('./coreComputed'
23
23
  * @param {CSN.Options} options
24
24
  */
25
25
  module.exports = (csn, options) => {
26
- const propagateToReturns = isBetaEnabled( options, 'v4preview' );
27
26
  const csnUtils = getUtils(csn, 'init-all');
28
27
  const {
29
28
  initDefinition, getOrigin, getQueryPrimarySource, artifactRef, getColumn,
@@ -116,7 +115,7 @@ module.exports = (csn, options) => {
116
115
  // The $origin properties need to be removed separately
117
116
  // as the values are used in csnRef::getOrigin that is used during
118
117
  // the propagation above.
119
- // Currently testMode-only for comparison against client CSN.
118
+ // Currently, testMode-only for comparison against client CSN.
120
119
  if (options.testMode)
121
120
  makeClientCompatible(csn);
122
121
 
@@ -174,10 +173,7 @@ module.exports = (csn, options) => {
174
173
 
175
174
  setTargetAspectIfRequired(parent);
176
175
  },
177
- type: ( parent, prop, type, path, grandParent, parentProp ) => {
178
- // annos are not propagated to `returns` (<=v3) and `items`
179
- if (parentProp === 'returns' && !propagateToReturns)
180
- return;
176
+ type: ( parent, prop, type ) => {
181
177
  const annotationsForBuiltinType = extensions[type];
182
178
  Object.assign( parent, annotationsForBuiltinType );
183
179
  },
@@ -288,13 +284,17 @@ module.exports = (csn, options) => {
288
284
  },
289
285
  params: (parent, prop, params) => {
290
286
  forEachValue(params, (param) => {
287
+ const propagateToParams = typeof param.type === 'string' ? csn.definitions[param.type]?.kind !== 'entity' : true;
291
288
  propagateMemberPropsFromOrigin(param, {
292
- items: true, elements: true, enum: true, virtual: true,
289
+ '@': !propagateToParams, items: true, elements: true, enum: true, virtual: true,
293
290
  });
294
291
  });
295
292
  },
296
293
  returns: (parent, prop, returns) => {
297
- propagateMemberPropsFromOrigin(returns, { items: true, '@': !propagateToReturns, elements: true });
294
+ // Only propagate to `returns` (return parameter) if return type is not an entity.
295
+ // If returns.type is an array, it is an element ref. If it's not found, it's likely builtin.
296
+ const propagateToParams = typeof returns.type === 'string' ? csn.definitions[returns.type]?.kind !== 'entity' : true;
297
+ propagateMemberPropsFromOrigin(returns, { '@': !propagateToParams, items: true, elements: true });
298
298
  if (returns.target)
299
299
  calculateForeignKeys(returns);
300
300
  },
@@ -368,7 +368,7 @@ module.exports = (csn, options) => {
368
368
  * @todo check if still necessary
369
369
  */
370
370
  function skipMemberPropagation( origin ) {
371
- // For empty members (`{}`), the origin was set in a previous call to `getOrigin(definition)`.
371
+ // For empty members (`{}`), the origin was set in a previous call to `getOrigin(definition)`.
372
372
  return !origin;
373
373
  }
374
374
  }
@@ -519,7 +519,7 @@ module.exports = (csn, options) => {
519
519
  forEachValue(elements, (element) => {
520
520
  if (element.target) {
521
521
  const column = getColumn(element);
522
- if (column) {
522
+ if (column?.ref) {
523
523
  const mixin = query.SELECT.mixin[implicitAs(column.ref)] || {};
524
524
  copyProperties(mixin, element, getMemberPropagationRuleFor);
525
525
  }
@@ -552,7 +552,7 @@ module.exports = (csn, options) => {
552
552
  if (!target.kind)
553
553
  return;
554
554
  const primarySourceRef = getQueryPrimarySource(target.query || target.projection);
555
- const artRef = primarySourceRef ? artifactRef(primarySourceRef) : source;
555
+ const artRef = primarySourceRef ? artifactRef.from(primarySourceRef) : source;
556
556
  if (!artRef.target)
557
557
  target[prop] = source[prop];
558
558
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap/cds-compiler",
3
- "version": "3.9.4",
3
+ "version": "4.0.2",
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)",
@@ -59,6 +59,6 @@
59
59
  "LICENSE"
60
60
  ],
61
61
  "engines": {
62
- "node": ">=14"
62
+ "node": ">=16"
63
63
  }
64
64
  }
@@ -1,4 +1,4 @@
1
- # duplicate-autoexposed
1
+ # def-duplicate-autoexposed
2
2
 
3
3
  Two or more entities with the same name can’t be auto-exposed in the same
4
4
  service.
@@ -76,3 +76,7 @@ auto-exposing entities. The reason is that the resulting auto-exposed names
76
76
  could become _long_ names that don’t seem natural nor intuitive. We chose to
77
77
  expose the entity name because that’s what most developers want to do when
78
78
  they manually expose entities.
79
+
80
+ ## Other Notes
81
+
82
+ This message was called `duplicate-autoexposed` in cds-compiler v3 and earlier.
@@ -4,7 +4,7 @@
4
4
  "anno-duplicate-unrelated-layer",
5
5
  "check-proper-type",
6
6
  "check-proper-type-of",
7
- "duplicate-autoexposed",
7
+ "def-duplicate-autoexposed",
8
8
  "extend-repeated-intralayer",
9
9
  "extend-unrelated-layer",
10
10
  "redirected-to-ambiguous",