@sap/cds-compiler 5.1.0 → 5.2.0

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 (51) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/bin/cdsc.js +2 -2
  3. package/bin/cdshi.js +24 -17
  4. package/bin/cdsse.js +17 -18
  5. package/lib/api/main.js +19 -2
  6. package/lib/api/options.js +4 -1
  7. package/lib/base/builtins.js +1 -0
  8. package/lib/base/message-registry.js +16 -3
  9. package/lib/base/model.js +0 -10
  10. package/lib/checks/actionsFunctions.js +0 -12
  11. package/lib/checks/structuredAnnoExpressions.js +10 -14
  12. package/lib/compiler/assert-consistency.js +19 -11
  13. package/lib/compiler/builtins.js +1 -1
  14. package/lib/compiler/define.js +6 -4
  15. package/lib/compiler/extend.js +5 -5
  16. package/lib/compiler/populate.js +9 -9
  17. package/lib/compiler/propagator.js +1 -0
  18. package/lib/compiler/resolve.js +29 -34
  19. package/lib/compiler/shared.js +7 -8
  20. package/lib/compiler/tweak-assocs.js +155 -64
  21. package/lib/compiler/utils.js +1 -1
  22. package/lib/compiler/xpr-rewrite.js +4 -3
  23. package/lib/edm/annotations/genericTranslation.js +13 -9
  24. package/lib/edm/csn2edm.js +26 -2
  25. package/lib/edm/edm.js +23 -8
  26. package/lib/edm/edmInboundChecks.js +5 -7
  27. package/lib/edm/edmPreprocessor.js +43 -30
  28. package/lib/gen/BaseParser.js +720 -0
  29. package/lib/gen/CdlParser.js +4421 -0
  30. package/lib/gen/language.checksum +1 -1
  31. package/lib/gen/language.interp +1 -1
  32. package/lib/gen/languageParser.js +4006 -4001
  33. package/lib/language/antlrParser.js +62 -0
  34. package/lib/language/genericAntlrParser.js +28 -0
  35. package/lib/model/csnUtils.js +2 -0
  36. package/lib/model/revealInternalProperties.js +2 -0
  37. package/lib/modelCompare/utils/filter.js +70 -42
  38. package/lib/optionProcessor.js +9 -3
  39. package/lib/parsers/AstBuildingParser.js +1172 -0
  40. package/lib/parsers/CdlGrammar.g4 +1940 -0
  41. package/lib/parsers/Lexer.js +239 -0
  42. package/lib/render/toCdl.js +23 -27
  43. package/lib/render/toSql.js +5 -5
  44. package/lib/transform/db/applyTransformations.js +54 -16
  45. package/lib/transform/draft/odata.js +10 -11
  46. package/lib/transform/effective/flattening.js +10 -14
  47. package/lib/transform/odata/flattening.js +42 -31
  48. package/lib/transform/odata/toFinalBaseType.js +7 -6
  49. package/lib/transform/universalCsn/universalCsnEnricher.js +1 -0
  50. package/package.json +2 -2
  51. package/share/messages/redirected-to-ambiguous.md +5 -4
@@ -5,7 +5,7 @@ const { setProp, isDeprecatedEnabled, isBetaEnabled } = require('../base/model')
5
5
  const {
6
6
  forEachDefinition, forEachGeneric, forEachMemberRecursively,
7
7
  isEdmPropertyRendered, getUtils,
8
- applyTransformations, transformExpression, findAnnotationExpression,
8
+ applyTransformations, transformAnnotationExpression, findAnnotationExpression,
9
9
  cardinality2str,
10
10
  } = require('../model/csnUtils');
11
11
  const { isBuiltinType, isMagicVariable } = require('../base/builtins');
@@ -1890,12 +1890,12 @@ function initializeModel( csn, _options, messageFunctions, requestedServiceNames
1890
1890
  mapCdsToEdmProp(def.returns);
1891
1891
  annotateAllowedValues(def.returns, [ ...defLocation, 'returns' ]);
1892
1892
  }
1893
- forEachMemberRecursively(def, (member, _memberName, _prop, location) => {
1893
+ forEachMemberRecursively(def, (member, _memberName, prop, location) => {
1894
1894
  edmUtils.assignAnnotation(member, '@Core.Description', member.doc);
1895
1895
  markCollection(member);
1896
1896
  mapCdsToEdmProp(member);
1897
1897
  annotateAllowedValues(member, location);
1898
- ComputedDefaultValue(member);
1898
+ ComputedDefaultValue(member, prop, location);
1899
1899
  rewriteAnnotationExpressions(member);
1900
1900
  if (member.returns) {
1901
1901
  edmUtils.assignAnnotation(member.returns, '@Core.Description', member.returns.doc);
@@ -2082,8 +2082,6 @@ function initializeModel( csn, _options, messageFunctions, requestedServiceNames
2082
2082
  parameters appear rightmost.
2083
2083
  */
2084
2084
  function annotateOptionalActFuncParams( def, defName ) {
2085
- if (!isBetaEnabled(options, 'optionalActionFunctionParameters'))
2086
- return;
2087
2085
  // return if there is nothing to do
2088
2086
  const loc = [ 'definitions', defName ];
2089
2087
  if (def.kind === 'function' || def.kind === 'action')
@@ -2098,32 +2096,43 @@ function initializeModel( csn, _options, messageFunctions, requestedServiceNames
2098
2096
  function iterateParams( action, location ) {
2099
2097
  let optPns = [];
2100
2098
  if (action.params) {
2101
- Object.values(action.params).forEach((p) => {
2099
+ Object.entries(action.params).forEach(([ pn, p ]) => {
2102
2100
  // user assigned annotation, don't touch it
2101
+ const defT = reqDefs.definitions[p.items?.type || p.type];
2102
+ const isStructType = !!(defT?.items?.elements || defT?.elements);
2103
+ const isItems = !!(p.items || defT?.items);
2104
+
2103
2105
  if (Object.keys(p).some(a => a.startsWith('@Core.OptionalParameter') && p[a] !== null)) {
2104
2106
  optPns.push(p);
2105
2107
  }
2106
2108
  // default value automatically makes param optional
2107
- else if (p.default) {
2108
- if (p.default.val)
2109
- edmUtils.assignAnnotation(p, '@Core.OptionalParameter.DefaultValue', p.default.val);
2110
- else
2109
+ else if (isBetaEnabled(options, 'optionalActionFunctionParameters')) {
2110
+ if (p.default?.val !== undefined) {
2111
+ if (p.default.val !== null && (isStructType || isItems)) {
2112
+ warning('odata-ignoring-param-default', location.concat(pn), { '#': 'colitem' });
2113
+ }
2114
+ else {
2115
+ edmUtils.assignAnnotation(p, '@Core.OptionalParameter.DefaultValue', p.default.val);
2116
+ optPns.push(p);
2117
+ }
2118
+ }
2119
+ // if no default is available, nullable makes param optional
2120
+ else if (!p.notNull) {
2111
2121
  edmUtils.assignAnnotation(p, '@Core.OptionalParameter.$Type', '');
2112
- optPns.push(p);
2113
- }
2114
- // if no default is available, nullable makes param optional
2115
- else if (!p.notNull) {
2116
- edmUtils.assignAnnotation(p, '@Core.OptionalParameter.$Type', '');
2117
- optPns.push(p);
2122
+ optPns.push(p);
2123
+ }
2124
+ else {
2125
+ // this is a mandatory parameter, warn about all previously collected optional parameters
2126
+ optPns.forEach((op) => {
2127
+ const type = op.items?.type || op.type;
2128
+ if (type !== special$self)
2129
+ error('odata-parameter-order', location.concat(op.name));
2130
+ });
2131
+ optPns = [];
2132
+ }
2118
2133
  }
2119
- else {
2120
- // this is a mandatory parameter, warn about all previously collected optional parameters
2121
- optPns.forEach((op) => {
2122
- const type = op.items?.type || op.type;
2123
- if (type !== special$self)
2124
- error('odata-parameter-order', location.concat(op.name));
2125
- });
2126
- optPns = [];
2134
+ else if (p.default) {
2135
+ warning('odata-ignoring-param-default', location.concat(pn));
2127
2136
  }
2128
2137
  });
2129
2138
  }
@@ -2152,7 +2161,7 @@ function initializeModel( csn, _options, messageFunctions, requestedServiceNames
2152
2161
  }
2153
2162
  }
2154
2163
 
2155
- function ComputedDefaultValue( member ) {
2164
+ function ComputedDefaultValue( member, prop, location ) {
2156
2165
  if (member.default && !csn['@Core.ComputedDefaultValue']) {
2157
2166
  let def = member.default;
2158
2167
  let noTailExpr = false;
@@ -2166,8 +2175,12 @@ function initializeModel( csn, _options, messageFunctions, requestedServiceNames
2166
2175
  def = def.xpr[i];
2167
2176
  }
2168
2177
  // it is a computed value if it is not a simple value or an annotation
2169
- if (!((def.val !== undefined && !noTailExpr) || def['#']))
2170
- edmUtils.assignAnnotation(member, '@Core.ComputedDefaultValue', true);
2178
+ if (!((def.val !== undefined && !noTailExpr) || def['#'])) {
2179
+ if (prop === 'params')
2180
+ warning('odata-ignoring-param-default', location, { '#': 'xpr' });
2181
+ else
2182
+ edmUtils.assignAnnotation(member, '@Core.ComputedDefaultValue', true);
2183
+ }
2171
2184
  }
2172
2185
  }
2173
2186
 
@@ -2258,13 +2271,13 @@ function initializeModel( csn, _options, messageFunctions, requestedServiceNames
2258
2271
 
2259
2272
  xprANames.forEach((xprAName) => {
2260
2273
  isSubTreeSpan = true;
2261
- transformExpression(carrier, xprAName, subTreeSpan);
2274
+ transformAnnotationExpression(carrier, xprAName, subTreeSpan);
2262
2275
  if (isSubTreeSpan) {
2263
- transformExpression(carrier, xprAName, relativize);
2276
+ transformAnnotationExpression(carrier, xprAName, relativize);
2264
2277
  }
2265
2278
  else {
2266
2279
  absolutize.scope = scope;
2267
- transformExpression(carrier, xprAName, absolutize);
2280
+ transformAnnotationExpression(carrier, xprAName, absolutize);
2268
2281
  if (!def[proxyDict])
2269
2282
  setProp(def, proxyDict, Object.create(null));
2270
2283
  let proxyCarrier = def[proxyDict][eltPath];