@sap/cds-compiler 3.1.2 → 3.4.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 (117) hide show
  1. package/CHANGELOG.md +101 -3
  2. package/bin/cdsc.js +4 -2
  3. package/doc/CHANGELOG_BETA.md +35 -0
  4. package/lib/api/main.js +153 -29
  5. package/lib/api/validate.js +8 -3
  6. package/lib/base/dictionaries.js +6 -6
  7. package/lib/base/error.js +2 -2
  8. package/lib/base/keywords.js +106 -24
  9. package/lib/base/message-registry.js +177 -79
  10. package/lib/base/messages.js +78 -57
  11. package/lib/base/model.js +2 -1
  12. package/lib/checks/actionsFunctions.js +1 -1
  13. package/lib/checks/annotationsOData.js +2 -2
  14. package/lib/checks/arrayOfs.js +15 -7
  15. package/lib/checks/cdsPersistence.js +1 -1
  16. package/lib/checks/checkForTypes.js +53 -0
  17. package/lib/checks/defaultValues.js +4 -2
  18. package/lib/checks/elements.js +81 -6
  19. package/lib/checks/foreignKeys.js +12 -13
  20. package/lib/checks/invalidTarget.js +10 -11
  21. package/lib/checks/managedInType.js +21 -15
  22. package/lib/checks/nullableKeys.js +1 -1
  23. package/lib/checks/onConditions.js +9 -9
  24. package/lib/checks/parameters.js +23 -0
  25. package/lib/checks/queryNoDbArtifacts.js +1 -1
  26. package/lib/checks/selectItems.js +1 -1
  27. package/lib/checks/sql-snippets.js +12 -10
  28. package/lib/checks/types.js +2 -2
  29. package/lib/checks/utils.js +17 -7
  30. package/lib/checks/validator.js +36 -14
  31. package/lib/compiler/assert-consistency.js +21 -13
  32. package/lib/compiler/builtins.js +8 -0
  33. package/lib/compiler/checks.js +57 -40
  34. package/lib/compiler/define.js +139 -69
  35. package/lib/compiler/extend.js +319 -50
  36. package/lib/compiler/finalize-parse-cdl.js +14 -9
  37. package/lib/compiler/kick-start.js +2 -35
  38. package/lib/compiler/populate.js +111 -68
  39. package/lib/compiler/propagator.js +5 -3
  40. package/lib/compiler/resolve.js +71 -108
  41. package/lib/compiler/shared.js +82 -54
  42. package/lib/compiler/tweak-assocs.js +26 -14
  43. package/lib/compiler/utils.js +13 -2
  44. package/lib/edm/annotations/genericTranslation.js +10 -7
  45. package/lib/edm/csn2edm.js +11 -11
  46. package/lib/edm/edm.js +17 -9
  47. package/lib/edm/edmPreprocessor.js +53 -30
  48. package/lib/edm/edmUtils.js +7 -2
  49. package/lib/gen/Dictionary.json +14 -0
  50. package/lib/gen/language.checksum +1 -1
  51. package/lib/gen/language.interp +3 -2
  52. package/lib/gen/languageParser.js +4312 -4186
  53. package/lib/inspect/inspectModelStatistics.js +1 -1
  54. package/lib/inspect/inspectPropagation.js +23 -9
  55. package/lib/json/csnVersion.js +13 -13
  56. package/lib/json/from-csn.js +161 -172
  57. package/lib/json/to-csn.js +70 -10
  58. package/lib/language/.eslintrc.json +4 -0
  59. package/lib/language/antlrParser.js +8 -11
  60. package/lib/language/docCommentParser.js +1 -2
  61. package/lib/language/errorStrategy.js +54 -27
  62. package/lib/language/genericAntlrParser.js +140 -93
  63. package/lib/language/language.g4 +57 -33
  64. package/lib/language/multiLineStringParser.js +75 -63
  65. package/lib/main.d.ts +3 -6
  66. package/lib/main.js +1 -0
  67. package/lib/model/.eslintrc.json +13 -0
  68. package/lib/model/api.js +4 -2
  69. package/lib/model/csnRefs.js +78 -50
  70. package/lib/model/csnUtils.js +272 -222
  71. package/lib/model/enrichCsn.js +41 -31
  72. package/lib/model/revealInternalProperties.js +61 -57
  73. package/lib/model/sortViews.js +35 -31
  74. package/lib/modelCompare/compare.js +52 -18
  75. package/lib/modelCompare/filter.js +83 -0
  76. package/lib/optionProcessor.js +10 -1
  77. package/lib/render/manageConstraints.js +11 -7
  78. package/lib/render/toCdl.js +151 -106
  79. package/lib/render/toHdbcds.js +8 -6
  80. package/lib/render/toRename.js +4 -4
  81. package/lib/render/toSql.js +17 -7
  82. package/lib/render/utils/common.js +27 -9
  83. package/lib/render/utils/sql.js +5 -5
  84. package/lib/sql-identifier.js +7 -0
  85. package/lib/transform/db/applyTransformations.js +32 -3
  86. package/lib/transform/db/assertUnique.js +27 -38
  87. package/lib/transform/db/expansion.js +92 -41
  88. package/lib/transform/db/flattening.js +1 -1
  89. package/lib/transform/db/temporal.js +3 -1
  90. package/lib/transform/db/transformExists.js +8 -2
  91. package/lib/transform/db/views.js +42 -13
  92. package/lib/transform/draft/db.js +2 -2
  93. package/lib/transform/forOdataNew.js +10 -7
  94. package/lib/transform/{forHanaNew.js → forRelationalDB.js} +18 -12
  95. package/lib/transform/localized.js +29 -20
  96. package/lib/transform/odata/toFinalBaseType.js +8 -11
  97. package/lib/transform/odata/typesExposure.js +2 -1
  98. package/lib/transform/parseExpr.js +245 -0
  99. package/lib/transform/transformUtilsNew.js +122 -51
  100. package/lib/transform/translateAssocsToJoins.js +17 -16
  101. package/lib/utils/moduleResolve.js +5 -5
  102. package/lib/utils/objectUtils.js +3 -3
  103. package/lib/utils/term.js +5 -5
  104. package/package.json +2 -2
  105. package/share/messages/anno-duplicate-unrelated-layer.md +6 -6
  106. package/share/messages/check-proper-type-of.md +4 -4
  107. package/share/messages/check-proper-type.md +2 -2
  108. package/share/messages/duplicate-autoexposed.md +4 -4
  109. package/share/messages/extend-repeated-intralayer.md +4 -5
  110. package/share/messages/extend-unrelated-layer.md +4 -4
  111. package/share/messages/message-explanations.json +3 -1
  112. package/share/messages/redirected-to-ambiguous.md +7 -6
  113. package/share/messages/redirected-to-complex.md +63 -0
  114. package/share/messages/redirected-to-unrelated.md +6 -5
  115. package/share/messages/rewrite-not-supported.md +4 -4
  116. package/share/messages/{syntax-expected-integer.md → syntax-expecting-integer.md} +4 -4
  117. package/share/messages/wildcard-excluding-one.md +37 -0
@@ -11,7 +11,7 @@ your model.
11
11
 
12
12
  Erroneous code example:
13
13
 
14
- ```cdl
14
+ ```cds
15
15
  entity Main {
16
16
  key id : Integer;
17
17
  toTarget : Association to Target;
@@ -42,11 +42,11 @@ to trigger this error.
42
42
 
43
43
  ## How to Fix
44
44
 
45
- To fix the issue, you must have the original target only once in your direct
46
- and indirect sources. The previous example can be fixed by removing
47
- `Duplicate` from the select clause.
45
+ You must have the original target only once in your direct and indirect
46
+ sources. The previous example can be fixed by removing `Duplicate` from
47
+ the select clause.
48
48
 
49
- ```cdl
49
+ ```cds
50
50
  view View as select from Main, Target {
51
51
  Main.toTarget : redirected to View
52
52
  };
@@ -55,7 +55,7 @@ view View as select from Main, Target {
55
55
  If this isn’t feasible then you have to redefine the association using a mixin
56
56
  clause.
57
57
 
58
- ```cdl
58
+ ```cds
59
59
  view View as select from Main, Target mixin {
60
60
  toMain : Association to View on Main.id = Target.id;
61
61
  } into {
@@ -68,3 +68,4 @@ view View as select from Main, Target mixin {
68
68
  ## Related Messages
69
69
 
70
70
  - `redirected-to-unrelated`
71
+ - `redirected-to-complex`
@@ -0,0 +1,63 @@
1
+ # redirected-to-complex
2
+
3
+ The redirected target is a complex view, for example, contains a JOIN or UNION.
4
+
5
+ The message's severity is `Info` and is raised by the compiler.
6
+ It is emitted to help developers identify possible modelling issues.
7
+
8
+ ## Example
9
+
10
+ Erroneous code example:
11
+
12
+ ```cds
13
+ entity Main {
14
+ key id : Integer;
15
+ // self association for example purpose only
16
+ toMain : Association to one Main;
17
+ }
18
+ entity Secondary {
19
+ content: String;
20
+ };
21
+ entity CrossJoin as SELECT from Main, Secondary;
22
+ entity RedirectToComplex as projection on Main {
23
+ id,
24
+ toMain: redirected to CrossJoin,
25
+ };
26
+ ```
27
+
28
+ `Main:toMain` is a to-one association. Since `Main` contains a single key,
29
+ which is used in the managed association, we know that following the
30
+ association returns a single result.
31
+
32
+ The cross join in the view `CrossJoin` results in multiple rows with the same
33
+ `id`. Following the redirected view now returns multiple results, effectively
34
+ making the to-one association a to-many association.
35
+
36
+ Visualizing the tables with a bit of data, this issues becomes obvious:
37
+
38
+ ```markdown
39
+ Main Secondary
40
+ | id | toMain_id | | content |
41
+ |-----|-----------| |---------|
42
+ | 1 | 2 | | 'Hello' |
43
+ | 2 | 1 | | 'World' |
44
+
45
+ CrossJoin
46
+ | id | toMain_id | content |
47
+ |-----|-----------|---------|
48
+ | 1 | 2 | 'Hello' |
49
+ | 1 | 2 | 'World' |
50
+ | 2 | 1 | 'Hello' |
51
+ | 2 | 1 | 'World' |
52
+ ```
53
+
54
+ ## How to Fix
55
+
56
+ Ensure that the redirected association points to an entity that is a reasonable
57
+ redirection target. You must ensure that the redirection does not accidentally
58
+ result in a to-one association becoming a to-many association.
59
+
60
+ ## Related Messages
61
+
62
+ - `redirected-to-ambiguous`
63
+ - `redirected-to-unrelated`
@@ -10,7 +10,7 @@ your model.
10
10
 
11
11
  Erroneous code example:
12
12
 
13
- ```cdl
13
+ ```cds
14
14
  entity Main {
15
15
  key id : Integer;
16
16
  // self association for example purpose only
@@ -35,7 +35,7 @@ that make the error not as obvious.
35
35
 
36
36
  Erroneous code example with multiple redirections:
37
37
 
38
- ```cdl
38
+ ```cds
39
39
  entity Main {
40
40
  key id : Integer;
41
41
  toMain : Association to Main;
@@ -58,12 +58,12 @@ originate from `FirstRedirect` but only vice versa.
58
58
 
59
59
  ## How to Fix
60
60
 
61
- To fix the issue, you must redirect the association to an entity that originates
62
- from the original target. In the first example above you could redirect
61
+ You must redirect the association to an entity that originates from the
62
+ original target. In the first example above you could redirect
63
63
  `SecondRedirect:toMain` to `SecondRedirect`. However, if that isn’t feasible
64
64
  then you have to redefine the association using a mixin clause.
65
65
 
66
- ```cdl
66
+ ```cds
67
67
  view SecondRedirect as select from FirstRedirect mixin {
68
68
  toMain : Association to Main on id = $self.id;
69
69
  } into {
@@ -75,3 +75,4 @@ view SecondRedirect as select from FirstRedirect mixin {
75
75
  ## Related Messages
76
76
 
77
77
  - `redirected-to-ambiguous`
78
+ - `redirected-to-complex`
@@ -9,7 +9,7 @@ The message's severity is `Error`.
9
9
 
10
10
  Erroneous code example:
11
11
 
12
- ```cdl
12
+ ```cds
13
13
  entity Base {
14
14
  key id : Integer;
15
15
  primary : Association to Primary on primary.id = primary_id;
@@ -39,10 +39,10 @@ compiler can’t determine how to properly rewrite them for `View`.
39
39
 
40
40
  ## How to Fix
41
41
 
42
- To fix the issue, you have to provide an explicit ON condition. This can be
43
- achieved by using the `redirected to` statement:
42
+ You have to provide an explicit ON condition. This can be achieved by using
43
+ the `redirected to` statement:
44
44
 
45
- ```cdl
45
+ ```cds
46
46
  entity View as select from Base {
47
47
  id,
48
48
  primary.secondary_id,
@@ -1,4 +1,4 @@
1
- # syntax-expected-integer
1
+ # syntax-expecting-integer
2
2
 
3
3
  The compiler expects a safe integer here.
4
4
  The last safe integer is `2^53 - 1` or `9007199254740991`.
@@ -16,7 +16,7 @@ The message's severity is `Error`.
16
16
  Erroneous code example:
17
17
 
18
18
  <!-- cds-mode: ignore -->
19
- ```cdl
19
+ ```cds
20
20
  type LengthIsUnsafe : String(9007199254740992);
21
21
  type NotAnInteger : String(42.1);
22
22
  ```
@@ -27,9 +27,9 @@ Likewise, the string length for the type `NotAnInteger` is a decimal.
27
27
 
28
28
  ## How to Fix
29
29
 
30
- To fix the issue, you have to provide a safe integer:
30
+ You have to provide a safe integer:
31
31
 
32
- ```cdl
32
+ ```cds
33
33
  type LengthIsSafe : String(9007199254740991);
34
34
  type AnInteger : String(42);
35
35
  ```
@@ -0,0 +1,37 @@
1
+ # wildcard-excluding-one
2
+
3
+ You're replacing an element in your projection, that is already included by
4
+ using the wildcard `*`.
5
+
6
+ The message's severity is `Info`.
7
+
8
+ ## Example
9
+
10
+ Erroneous code example:
11
+
12
+ ```cds
13
+ entity Book {
14
+ key id : String;
15
+ isbn : String;
16
+ content : String;
17
+ };
18
+ entity IsbnBook as projection on Book {
19
+ *,
20
+ isbn as id,
21
+ };
22
+ ```
23
+
24
+ `IsbnBook:id` replaces `Book:id`, which was included in `IsbnBook` through
25
+ the wildcard `*`.
26
+
27
+ ## How to Fix
28
+
29
+ Add the replaced element to the list of wildcard excludes:
30
+
31
+ ```cds
32
+ entity IsbnBook as projection on Book {
33
+ *,
34
+ isbn as id
35
+ } excluding { id };
36
+ ```
37
+