@sap/cds-compiler 3.6.2 → 3.8.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 (89) hide show
  1. package/CHANGELOG.md +109 -1
  2. package/README.md +3 -0
  3. package/bin/cdsc.js +12 -5
  4. package/doc/CHANGELOG_ARCHIVE.md +6 -6
  5. package/doc/CHANGELOG_BETA.md +35 -2
  6. package/doc/CHANGELOG_DEPRECATED.md +2 -2
  7. package/doc/DeprecatedOptions_v2.md +1 -1
  8. package/doc/NameResolution.md +1 -1
  9. package/lib/api/main.js +63 -23
  10. package/lib/api/options.js +1 -0
  11. package/lib/api/validate.js +5 -0
  12. package/lib/base/dictionaries.js +15 -3
  13. package/lib/base/keywords.js +2 -0
  14. package/lib/base/message-registry.js +120 -34
  15. package/lib/base/messages.js +51 -27
  16. package/lib/base/model.js +4 -2
  17. package/lib/base/shuffle.js +2 -1
  18. package/lib/checks/arrayOfs.js +1 -1
  19. package/lib/checks/defaultValues.js +1 -1
  20. package/lib/checks/elements.js +29 -1
  21. package/lib/checks/{emptyOrOnlyVirtual.js → hasPersistedElements.js} +10 -6
  22. package/lib/checks/invalidTarget.js +1 -1
  23. package/lib/checks/nonexpandableStructured.js +1 -1
  24. package/lib/checks/onConditions.js +15 -9
  25. package/lib/checks/sql-snippets.js +2 -2
  26. package/lib/checks/types.js +5 -1
  27. package/lib/checks/validator.js +7 -3
  28. package/lib/compiler/assert-consistency.js +42 -26
  29. package/lib/compiler/base.js +50 -4
  30. package/lib/compiler/builtins.js +17 -8
  31. package/lib/compiler/checks.js +241 -246
  32. package/lib/compiler/define.js +113 -146
  33. package/lib/compiler/extend.js +889 -383
  34. package/lib/compiler/finalize-parse-cdl.js +5 -58
  35. package/lib/compiler/index.js +1 -1
  36. package/lib/compiler/kick-start.js +7 -8
  37. package/lib/compiler/populate.js +297 -293
  38. package/lib/compiler/propagator.js +27 -18
  39. package/lib/compiler/resolve.js +146 -463
  40. package/lib/compiler/shared.js +36 -79
  41. package/lib/compiler/tweak-assocs.js +30 -28
  42. package/lib/compiler/utils.js +31 -5
  43. package/lib/edm/annotations/genericTranslation.js +131 -59
  44. package/lib/edm/annotations/preprocessAnnotations.js +3 -0
  45. package/lib/edm/csn2edm.js +22 -5
  46. package/lib/edm/edm.js +6 -4
  47. package/lib/edm/edmAnnoPreprocessor.js +1 -0
  48. package/lib/edm/edmPreprocessor.js +42 -26
  49. package/lib/gen/Dictionary.json +38 -2
  50. package/lib/gen/language.checksum +1 -1
  51. package/lib/gen/language.interp +3 -1
  52. package/lib/gen/languageLexer.js +1 -1
  53. package/lib/gen/languageParser.js +4828 -4472
  54. package/lib/inspect/inspectPropagation.js +20 -34
  55. package/lib/json/from-csn.js +140 -44
  56. package/lib/json/to-csn.js +114 -122
  57. package/lib/language/errorStrategy.js +2 -0
  58. package/lib/language/genericAntlrParser.js +156 -36
  59. package/lib/language/language.g4 +100 -58
  60. package/lib/language/textUtils.js +13 -0
  61. package/lib/main.d.ts +43 -3
  62. package/lib/main.js +4 -2
  63. package/lib/model/csnRefs.js +15 -3
  64. package/lib/model/csnUtils.js +12 -74
  65. package/lib/model/revealInternalProperties.js +4 -2
  66. package/lib/modelCompare/compare.js +2 -1
  67. package/lib/optionProcessor.js +3 -0
  68. package/lib/render/manageConstraints.js +5 -2
  69. package/lib/render/toCdl.js +216 -104
  70. package/lib/render/toHdbcds.js +2 -9
  71. package/lib/render/toRename.js +14 -51
  72. package/lib/render/toSql.js +4 -3
  73. package/lib/render/utils/common.js +9 -5
  74. package/lib/transform/braceExpression.js +6 -0
  75. package/lib/transform/db/assertUnique.js +2 -1
  76. package/lib/transform/db/expansion.js +2 -0
  77. package/lib/transform/db/flattening.js +37 -36
  78. package/lib/transform/db/rewriteCalculatedElements.js +600 -0
  79. package/lib/transform/db/transformExists.js +4 -0
  80. package/lib/transform/db/views.js +40 -37
  81. package/lib/transform/forOdataNew.js +20 -15
  82. package/lib/transform/forRelationalDB.js +58 -41
  83. package/lib/transform/odata/typesExposure.js +50 -15
  84. package/lib/transform/parseExpr.js +16 -8
  85. package/lib/transform/transformUtilsNew.js +42 -14
  86. package/lib/transform/translateAssocsToJoins.js +60 -37
  87. package/lib/transform/universalCsn/coreComputed.js +15 -7
  88. package/lib/transform/universalCsn/universalCsnEnricher.js +4 -4
  89. package/package.json +2 -1
@@ -14,7 +14,12 @@ const {
14
14
  forEachGeneric,
15
15
  isDeprecatedEnabled,
16
16
  } = require( '../base/model');
17
- const { setLink, linkToOrigin, withAssociation } = require('./utils');
17
+ const {
18
+ setLink,
19
+ linkToOrigin,
20
+ withAssociation,
21
+ viewFromPrimary,
22
+ } = require('./utils');
18
23
  const $inferred = Symbol.for('cds.$inferred');
19
24
  // const { refString } = require( '../base/messages')
20
25
 
@@ -81,7 +86,7 @@ function propagate( model ) {
81
86
  function run( art ) {
82
87
  if (!art)
83
88
  return;
84
- if (!checkAndSetStatus( art )) {
89
+ if (!checkAndSetStatus( art ) || art.kind === 'select') {
85
90
  runMembers( art );
86
91
  return;
87
92
  }
@@ -94,6 +99,13 @@ function propagate( model ) {
94
99
  for (const target of targets) {
95
100
  const origin = getOrigin( target );
96
101
  if (origin) {
102
+ // Calculated elements that are simple references: `calc = field;`.
103
+ // Respect sibling properties in inheritance.
104
+ if (target._calcOrigin?._origin && target.value?._artifact) {
105
+ chain.push({ target, source: target.value._artifact });
106
+ if (checkAndSetStatus( target.value._artifact ))
107
+ news.push(target.value._artifact);
108
+ }
97
109
  chain.push( { target, source: origin } );
98
110
  if (checkAndSetStatus( origin ))
99
111
  news.push( origin );
@@ -173,13 +185,13 @@ function propagate( model ) {
173
185
  }
174
186
  else {
175
187
  target[prop] = Object.assign( {}, val, { $inferred: 'prop' } );
176
- if ('_artifact' in val)
188
+ if (val._artifact !== undefined)
177
189
  setLink( target[prop], '_artifact', val._artifact );
178
- if ('_outer' in val)
190
+ if (val._outer !== undefined)
179
191
  setLink( target[prop], '_outer', val._outer );
180
- if ('_parent' in val)
192
+ if (val._parent !== undefined)
181
193
  setLink( target[prop], '_parent', val._parent );
182
- if ('_main' in val)
194
+ if (val._main !== undefined)
183
195
  setLink( target[prop], '_main', val._main );
184
196
  }
185
197
  }
@@ -254,7 +266,8 @@ function propagate( model ) {
254
266
  }
255
267
 
256
268
  function onlyViaArtifact( prop, target, source ) {
257
- const from = target._from && target._from[0].path;
269
+ const from = viewFromPrimary( target )?.path;
270
+ // do not propagate from member / if follow assoc in from:
258
271
  if (!(from ? from[from.length - 1]._artifact : source)._main)
259
272
  annotation( prop, target, source );
260
273
  }
@@ -280,7 +293,7 @@ function propagate( model ) {
280
293
  if (!viaType)
281
294
  always( prop, target, source );
282
295
  else if (!oldVirtualNotNullPropagation) // NULL would block strange propagation to sub element
283
- target[prop] = { $inferred: 'NULL', val: undefined }; // set null value in Univeral CSN
296
+ target[prop] = { $inferred: 'NULL', val: undefined }; // set null value in Universal CSN
284
297
  }
285
298
 
286
299
  function checkVirtual( view ) {
@@ -331,18 +344,14 @@ function targetMinZero( art ) {
331
344
  }
332
345
 
333
346
  function getOrigin( art ) {
334
- if (art._origin)
347
+ let origin = art._origin;
348
+ while (origin?.kind === 'select')
349
+ origin = origin._origin;
350
+ if (origin)
335
351
  // Do not consider _origin if due to expand of table alias ref
336
- return (!art.expand || art._origin.kind === 'element') && art._origin;
352
+ return (!art.expand || origin.kind === 'element') && origin;
337
353
  // Remark: a column with an 'inline' is never an element -> no need to check
338
354
  // art.inline
339
- if (art._from && art._from.length) { // query
340
- const tabref = art._from[0]._artifact;
341
- return (tabref && tabref.kind === 'element')
342
- ? tabref._effectiveType && tabref._effectiveType.target &&
343
- tabref._effectiveType.target._artifact
344
- : tabref;
345
- }
346
355
 
347
356
  return (art.type && (!art.type.$inferred || art.type.$inferred === 'cast'))
348
357
  ? art.type._artifact
@@ -357,7 +366,7 @@ function checkAndSetStatus( art ) {
357
366
  }
358
367
 
359
368
  function setEffectiveType( target, source ) {
360
- if ('_effectiveType' in source)
369
+ if (source._effectiveType !== undefined)
361
370
  setLink( target, '_effectiveType', source._effectiveType);
362
371
  }
363
372