@sap/cds-compiler 4.0.2 → 4.2.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 (101) hide show
  1. package/CHANGELOG.md +200 -5
  2. package/bin/cdsc.js +18 -15
  3. package/doc/CHANGELOG_BETA.md +16 -0
  4. package/doc/CHANGELOG_DEPRECATED.md +15 -0
  5. package/lib/api/main.js +33 -13
  6. package/lib/api/options.js +2 -2
  7. package/lib/api/validate.js +25 -25
  8. package/lib/base/location.js +6 -7
  9. package/lib/base/message-registry.js +123 -42
  10. package/lib/base/messages.js +18 -10
  11. package/lib/base/model.js +43 -10
  12. package/lib/checks/defaultValues.js +6 -6
  13. package/lib/checks/elements.js +11 -10
  14. package/lib/checks/foreignKeys.js +0 -5
  15. package/lib/checks/manyNavigations.js +33 -0
  16. package/lib/checks/onConditions.js +22 -14
  17. package/lib/checks/queryNoDbArtifacts.js +132 -73
  18. package/lib/checks/selectItems.js +4 -55
  19. package/lib/checks/sql-snippets.js +15 -4
  20. package/lib/checks/types.js +3 -3
  21. package/lib/checks/utils.js +4 -3
  22. package/lib/checks/validator.js +3 -1
  23. package/lib/compiler/.eslintrc.json +2 -1
  24. package/lib/compiler/assert-consistency.js +71 -40
  25. package/lib/compiler/base.js +7 -2
  26. package/lib/compiler/builtins.js +40 -41
  27. package/lib/compiler/checks.js +415 -367
  28. package/lib/compiler/classes.js +62 -0
  29. package/lib/compiler/cycle-detector.js +9 -9
  30. package/lib/compiler/define.js +124 -90
  31. package/lib/compiler/extend.js +115 -88
  32. package/lib/compiler/finalize-parse-cdl.js +26 -25
  33. package/lib/compiler/generate.js +57 -49
  34. package/lib/compiler/index.js +56 -56
  35. package/lib/compiler/kick-start.js +10 -7
  36. package/lib/compiler/moduleLayers.js +1 -1
  37. package/lib/compiler/populate.js +180 -144
  38. package/lib/compiler/propagator.js +10 -9
  39. package/lib/compiler/resolve.js +321 -246
  40. package/lib/compiler/shared.js +812 -433
  41. package/lib/compiler/tweak-assocs.js +114 -50
  42. package/lib/compiler/utils.js +241 -46
  43. package/lib/edm/.eslintrc.json +40 -1
  44. package/lib/edm/annotations/genericTranslation.js +721 -707
  45. package/lib/edm/annotations/preprocessAnnotations.js +88 -77
  46. package/lib/edm/csn2edm.js +389 -378
  47. package/lib/edm/edm.js +679 -770
  48. package/lib/edm/edmAnnoPreprocessor.js +132 -146
  49. package/lib/edm/edmInboundChecks.js +29 -27
  50. package/lib/edm/edmPreprocessor.js +689 -648
  51. package/lib/edm/edmUtils.js +279 -300
  52. package/lib/gen/Dictionary.json +34 -10
  53. package/lib/gen/language.checksum +1 -1
  54. package/lib/gen/language.interp +1 -1
  55. package/lib/gen/languageParser.js +2857 -2856
  56. package/lib/json/from-csn.js +77 -51
  57. package/lib/json/to-csn.js +15 -15
  58. package/lib/language/antlrParser.js +2 -1
  59. package/lib/language/genericAntlrParser.js +52 -43
  60. package/lib/language/language.g4 +61 -64
  61. package/lib/language/multiLineStringParser.js +2 -0
  62. package/lib/main.d.ts +65 -0
  63. package/lib/model/csnRefs.js +37 -19
  64. package/lib/model/csnUtils.js +51 -18
  65. package/lib/model/revealInternalProperties.js +30 -22
  66. package/lib/modelCompare/compare.js +149 -41
  67. package/lib/modelCompare/utils/filter.js +55 -25
  68. package/lib/optionProcessor.js +21 -9
  69. package/lib/render/manageConstraints.js +20 -17
  70. package/lib/render/toCdl.js +63 -23
  71. package/lib/render/toHdbcds.js +2 -2
  72. package/lib/render/toRename.js +4 -9
  73. package/lib/render/toSql.js +82 -35
  74. package/lib/render/utils/common.js +11 -9
  75. package/lib/render/utils/unique.js +52 -0
  76. package/lib/transform/db/applyTransformations.js +62 -21
  77. package/lib/transform/db/assertUnique.js +7 -8
  78. package/lib/transform/db/associations.js +2 -2
  79. package/lib/transform/db/cdsPersistence.js +9 -9
  80. package/lib/transform/db/constraints.js +47 -17
  81. package/lib/transform/db/expansion.js +138 -68
  82. package/lib/transform/db/flattening.js +98 -30
  83. package/lib/transform/db/rewriteCalculatedElements.js +20 -14
  84. package/lib/transform/db/temporal.js +1 -1
  85. package/lib/transform/db/transformExists.js +8 -7
  86. package/lib/transform/db/views.js +73 -33
  87. package/lib/transform/draft/db.js +11 -9
  88. package/lib/transform/draft/odata.js +1 -1
  89. package/lib/transform/{forOdataNew.js → forOdata.js} +10 -7
  90. package/lib/transform/forRelationalDB.js +148 -136
  91. package/lib/transform/localized.js +92 -54
  92. package/lib/transform/odata/toFinalBaseType.js +3 -3
  93. package/lib/transform/{transformUtilsNew.js → transformUtils.js} +13 -111
  94. package/lib/transform/translateAssocsToJoins.js +14 -28
  95. package/lib/utils/file.js +7 -7
  96. package/lib/utils/moduleResolve.js +210 -121
  97. package/lib/utils/objectUtils.js +1 -1
  98. package/package.json +5 -5
  99. package/share/messages/check-proper-type-of.md +1 -1
  100. package/share/messages/{check-proper-type.md → def-missing-type.md} +3 -5
  101. package/share/messages/message-explanations.json +1 -1
@@ -33,7 +33,7 @@ function kickStart( model ) {
33
33
  const art = model.definitions[name];
34
34
  if (art._parent === undefined)
35
35
  return; // nothing to do for builtins and redefinitions
36
- if (art.query && art._ancestors === undefined)
36
+ if (art.query && art._ancestors === undefined && art.kind === 'entity')
37
37
  setProjectionAncestors( art );
38
38
 
39
39
  let parent = art._parent;
@@ -44,7 +44,7 @@ function kickStart( model ) {
44
44
  if (!parent || !service)
45
45
  return;
46
46
  // To be removed when nested services are allowed
47
- if (!isBetaEnabled(options, 'nestedServices') && art.kind === 'service') {
47
+ if (!isBetaEnabled( options, 'nestedServices' ) && art.kind === 'service') {
48
48
  while (parent.kind !== 'service')
49
49
  parent = parent._parent;
50
50
  message( 'service-nested-service', [ art.name.location, art ], { art: parent },
@@ -66,15 +66,16 @@ function kickStart( model ) {
66
66
  // TODO: do not do implicit redirection across services, i.e. Service2.E is
67
67
  // no redirection target for E if Service2.E = projection on Service1.E and
68
68
  // Service1.E = projection on E
69
+
70
+ // Remark: _ancestors are also set with includes, and there also for aspects,
71
+ // types and events.
69
72
  const chain = [];
70
73
  const autoexposed = annotationVal( art['@cds.autoexposed'] );
71
- const preferredRedirectionTarget = annotationVal( art['@cds.redirection.target'] );
72
74
  // no need to set preferredRedirectionTarget in the while loop as we would
73
75
  // use the projection having @cds.redirection.target anyhow instead of
74
76
  // `art` anyway (if we do the no-x-service-implicit-redirection TODO above)
75
77
  while (art?.query?.from?.path && // direct select with one source
76
- art._ancestors !== 0 && // prevent inf-loop
77
- (preferredRedirectionTarget || !annotationIsFalse( art['@cds.redirection.target'] ) )) {
78
+ art._ancestors !== 0) { // prevent inf-loop
78
79
  chain.push( art );
79
80
  setLink( art, '_ancestors', 0 ); // avoid infloop with cyclic from
80
81
  const name = resolveUncheckedPath( art.query.from, 'from', art );
@@ -109,10 +110,10 @@ function kickStart( model ) {
109
110
  return;
110
111
 
111
112
  function expose( ancestor ) {
112
- if (ancestor._service === service)
113
+ if (ancestor._service === service || annotationIsFalse( art['@cds.redirection.target'] ))
113
114
  return;
114
115
  const desc = ancestor._descendants ||
115
- setLink( ancestor, '_descendants', Object.create(null) );
116
+ setLink( ancestor, '_descendants', Object.create( null ) );
116
117
  if (!desc[sname])
117
118
  desc[sname] = [ art ];
118
119
  else
@@ -125,6 +126,7 @@ function kickStart( model ) {
125
126
  if (elem.target && type && type[0] && type[0].id === 'cds.Composition') {
126
127
  // A target aspect would have already moved to property `targetAspect` in
127
128
  // define.js (hm... more something for kick-start.js...)
129
+ // TODO: for safety, just use resolveUncheckedPath()
128
130
  const target = resolvePath( elem.target, 'target', elem );
129
131
  if (target)
130
132
  model.$compositionTargets[target.name.absolute] = true;
@@ -134,6 +136,7 @@ function kickStart( model ) {
134
136
 
135
137
  // Resolve the using declarations in `using`. Issue
136
138
  // error message if the referenced artifact does not exist.
139
+ // TODO: think of moving this to resolve.js
137
140
  function resolveUsings( src, topLevel ) {
138
141
  if (!src.usings)
139
142
  return;
@@ -23,7 +23,7 @@ function setLayers( sources ) {
23
23
 
24
24
  // It is ensured that the representative is called last in SCC and that
25
25
  // dependent SCCs are called first
26
- function setExtends( node, representative, sccDeps = Object.create(null) ) {
26
+ function setExtends( node, representative, sccDeps = Object.create( null ) ) {
27
27
  setLink( node, '_layerRepresentative', representative );
28
28
  if (layerRepresentative !== representative) {
29
29
  layerRepresentative = representative;