@sap/cds-compiler 3.1.0 → 3.3.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 (100) hide show
  1. package/CHANGELOG.md +90 -3
  2. package/bin/cdsc.js +1 -1
  3. package/doc/CHANGELOG_BETA.md +18 -0
  4. package/lib/api/main.js +8 -13
  5. package/lib/base/error.js +2 -2
  6. package/lib/base/keywords.js +2 -24
  7. package/lib/base/message-registry.js +43 -14
  8. package/lib/base/messages.js +20 -10
  9. package/lib/base/model.js +1 -1
  10. package/lib/checks/actionsFunctions.js +1 -1
  11. package/lib/checks/annotationsOData.js +2 -2
  12. package/lib/checks/arrayOfs.js +15 -7
  13. package/lib/checks/cdsPersistence.js +1 -1
  14. package/lib/checks/checkForTypes.js +48 -0
  15. package/lib/checks/defaultValues.js +2 -2
  16. package/lib/checks/elements.js +81 -6
  17. package/lib/checks/foreignKeys.js +12 -13
  18. package/lib/checks/invalidTarget.js +10 -11
  19. package/lib/checks/managedInType.js +21 -15
  20. package/lib/checks/nullableKeys.js +1 -1
  21. package/lib/checks/onConditions.js +9 -9
  22. package/lib/checks/parameters.js +21 -0
  23. package/lib/checks/selectItems.js +1 -1
  24. package/lib/checks/types.js +2 -2
  25. package/lib/checks/utils.js +17 -7
  26. package/lib/checks/validator.js +26 -14
  27. package/lib/compiler/assert-consistency.js +13 -6
  28. package/lib/compiler/builtins.js +8 -0
  29. package/lib/compiler/checks.js +40 -33
  30. package/lib/compiler/define.js +50 -44
  31. package/lib/compiler/extend.js +303 -37
  32. package/lib/compiler/kick-start.js +2 -35
  33. package/lib/compiler/populate.js +83 -62
  34. package/lib/compiler/propagator.js +1 -1
  35. package/lib/compiler/resolve.js +61 -104
  36. package/lib/compiler/shared.js +16 -6
  37. package/lib/compiler/tweak-assocs.js +25 -12
  38. package/lib/compiler/utils.js +2 -2
  39. package/lib/edm/annotations/genericTranslation.js +15 -5
  40. package/lib/edm/csn2edm.js +10 -10
  41. package/lib/edm/edm.js +17 -9
  42. package/lib/edm/edmPreprocessor.js +82 -42
  43. package/lib/edm/edmUtils.js +18 -16
  44. package/lib/gen/Dictionary.json +14 -0
  45. package/lib/gen/language.checksum +1 -1
  46. package/lib/gen/language.interp +3 -2
  47. package/lib/gen/languageParser.js +4205 -4100
  48. package/lib/inspect/inspectModelStatistics.js +1 -1
  49. package/lib/inspect/inspectPropagation.js +23 -9
  50. package/lib/json/csnVersion.js +1 -1
  51. package/lib/json/from-csn.js +26 -19
  52. package/lib/json/to-csn.js +47 -5
  53. package/lib/language/antlrParser.js +1 -1
  54. package/lib/language/genericAntlrParser.js +29 -13
  55. package/lib/language/language.g4 +28 -8
  56. package/lib/main.d.ts +3 -6
  57. package/lib/model/.eslintrc.json +13 -0
  58. package/lib/model/api.js +4 -2
  59. package/lib/model/csnRefs.js +74 -47
  60. package/lib/model/csnUtils.js +236 -218
  61. package/lib/model/enrichCsn.js +41 -31
  62. package/lib/model/revealInternalProperties.js +61 -57
  63. package/lib/model/sortViews.js +31 -31
  64. package/lib/modelCompare/compare.js +6 -6
  65. package/lib/optionProcessor.js +5 -0
  66. package/lib/render/manageConstraints.js +2 -2
  67. package/lib/render/toCdl.js +31 -44
  68. package/lib/render/toHdbcds.js +7 -5
  69. package/lib/render/toRename.js +4 -4
  70. package/lib/render/toSql.js +11 -5
  71. package/lib/render/utils/common.js +20 -9
  72. package/lib/render/utils/sql.js +5 -5
  73. package/lib/transform/db/applyTransformations.js +32 -3
  74. package/lib/transform/db/expansion.js +81 -37
  75. package/lib/transform/db/flattening.js +1 -1
  76. package/lib/transform/db/temporal.js +1 -1
  77. package/lib/transform/db/transformExists.js +1 -1
  78. package/lib/transform/forOdataNew.js +10 -7
  79. package/lib/transform/{forHanaNew.js → forRelationalDB.js} +7 -7
  80. package/lib/transform/localized.js +28 -19
  81. package/lib/transform/odata/toFinalBaseType.js +8 -11
  82. package/lib/transform/odata/typesExposure.js +1 -1
  83. package/lib/transform/transformUtilsNew.js +101 -39
  84. package/lib/transform/translateAssocsToJoins.js +5 -4
  85. package/lib/utils/moduleResolve.js +5 -5
  86. package/lib/utils/objectUtils.js +3 -3
  87. package/package.json +2 -2
  88. package/share/messages/anno-duplicate-unrelated-layer.md +6 -6
  89. package/share/messages/check-proper-type-of.md +4 -4
  90. package/share/messages/check-proper-type.md +2 -2
  91. package/share/messages/duplicate-autoexposed.md +4 -4
  92. package/share/messages/extend-repeated-intralayer.md +4 -5
  93. package/share/messages/extend-unrelated-layer.md +4 -4
  94. package/share/messages/message-explanations.json +3 -1
  95. package/share/messages/redirected-to-ambiguous.md +7 -6
  96. package/share/messages/redirected-to-complex.md +63 -0
  97. package/share/messages/redirected-to-unrelated.md +6 -5
  98. package/share/messages/rewrite-not-supported.md +4 -4
  99. package/share/messages/syntax-expected-integer.md +3 -3
  100. package/share/messages/wildcard-excluding-one.md +37 -0
@@ -11,7 +11,7 @@ CDL file is equivalent to a layer.
11
11
 
12
12
  Erroneous code example using four CDS files:
13
13
 
14
- ```cdl
14
+ ```cds
15
15
  // (1) Base.cds: Contains the artifact that should be annotated
16
16
  entity FooBar { }
17
17
 
@@ -41,15 +41,15 @@ represents one layer.
41
41
 
42
42
  ## How to Fix
43
43
 
44
- To fix the issue, remove one of the duplicate annotations. Chances are, that
45
- only one was intended to begin with. For the erroneous example above, remove
46
- the annotation from (3).
44
+ Remove one of the duplicate annotations. Chances are, that only one was
45
+ intended to begin with. For the erroneous example above, remove the annotation
46
+ from (3).
47
47
 
48
48
  Alternatively, add an annotation assignment to (4). This annotation has
49
49
  precedence and the error will vanish. For the example above, (4) will look
50
50
  like this:
51
51
 
52
- ```cdl
52
+ ```cds
53
53
  // (4) All.cds: Combine all files
54
54
  using from './FooAnnotate';
55
55
  using from './BarAnnotate';
@@ -60,7 +60,7 @@ annotate FooBar with @Anno: 'Bar';
60
60
  You can also make (3) depend on (2) so that they are no longer in unrelated
61
61
  layers and the compiler can determine which annotation to apply.
62
62
 
63
- ```cdl
63
+ ```cds
64
64
  // (3) BarAnnotate.cds: Now depends on (2)
65
65
  using from './FooAnnotate';
66
66
  annotate FooBar with @Anno: 'Bar';
@@ -4,13 +4,13 @@ An element in a `type of` expression doesn’t have proper type information.
4
4
 
5
5
  The message's severity is `Info` but may be raised to `Error` in the SQL,
6
6
  SAP HANA, and OData backends. These backends require elements to have a type.
7
- Otherwise they aren’t able to render elements (for example, to SQL columns).
7
+ Otherwise, they aren’t able to render elements (for example, to SQL columns).
8
8
 
9
9
  ## Example
10
10
 
11
11
  Erroneous code example:
12
12
 
13
- ```cdl
13
+ ```cds
14
14
  entity Foo {
15
15
  key id : Integer;
16
16
  };
@@ -33,9 +33,9 @@ properties but won’t have a proper type, which is required by some backends.
33
33
 
34
34
  ## How to Fix
35
35
 
36
- To fix the issue, assign an explicit type to `ViewFoo:calculatedField`.
36
+ Assign an explicit type to `ViewFoo:calculatedField`.
37
37
 
38
- ```cdl
38
+ ```cds
39
39
  view ViewFoo as select from Foo {
40
40
  1+1 as calculatedField @(anno) : Integer
41
41
  };
@@ -27,8 +27,8 @@ Erroneous code example:
27
27
 
28
28
  ## How to Fix
29
29
 
30
- To fix the issue, add explicit type information to `MainType`, for example, add
31
- an `elements` property to make a structured type.
30
+ Add explicit type information to `MainType`, for example, add an `elements`
31
+ property to make a structured type.
32
32
 
33
33
  ```json
34
34
  {
@@ -15,7 +15,7 @@ adapt your model to fix the error.
15
15
 
16
16
  Erroneous code example:
17
17
 
18
- ```cdl
18
+ ```cds
19
19
  // (1)
20
20
  entity ns.first.Foo {
21
21
  key parent : Association to one ns.Base;
@@ -46,13 +46,13 @@ of (2) and (3) are ignored, a name collision happens.
46
46
 
47
47
  ## How to Fix
48
48
 
49
- To fix the issue, you need to explicitly expose one or more entities under
50
- a name that does not exist in the service, yet.
49
+ You need to explicitly expose one or more entities under a name that does not
50
+ exist in the service, yet.
51
51
 
52
52
  For the erroneous example above, you could add these two lines to the service
53
53
  `ns.MyService`:
54
54
 
55
- ```cdl
55
+ ```cds
56
56
  entity first.Foo as projection on ns.first.Foo; // (5)
57
57
  entity second.Foo as projection on ns.second.Foo; // (6)
58
58
  ```
@@ -11,7 +11,7 @@ They form a cyclic connection through their dependencies
11
11
 
12
12
  Erroneous code example with a single CDL file:
13
13
 
14
- ```cdl
14
+ ```cds
15
15
  entity FooBar { }
16
16
 
17
17
  extend FooBar { foo : Integer; }
@@ -24,7 +24,7 @@ inside `FooBar` may not be stable. You therefore can’t depend on it.
24
24
  It's also possible to trigger this warning with multiple files.
25
25
  Look at the following example:
26
26
 
27
- ```cdl
27
+ ```cds
28
28
  // (1) Definition.cds
29
29
  using from './Extension.cds';
30
30
  entity FooBar { };
@@ -40,10 +40,9 @@ layer with multiple extensions. Again, the element order isn’t stable.
40
40
 
41
41
  ## How to Fix
42
42
 
43
- To fix the issue, move extensions for the same artifact into the same extension
44
- block:
43
+ Move extensions for the same artifact into the same extension block:
45
44
 
46
- ```cdl
45
+ ```cds
47
46
  // (1) Definition.cds : No extension block
48
47
  using from './Extension.cds';
49
48
  entity FooBar { }
@@ -11,7 +11,7 @@ They form a cyclic connection through their dependencies
11
11
 
12
12
  Erroneous code example using four CDS files:
13
13
 
14
- ```cdl
14
+ ```cds
15
15
  // (1) Base.cds: Contains the artifact that should be extended
16
16
  entity FooBar { }
17
17
 
@@ -38,13 +38,13 @@ represents one layer.
38
38
 
39
39
  ## How to Fix
40
40
 
41
- To fix the issue, move extensions for the same artifact into the same layer,
42
- that is, the same file.
41
+ Move extensions for the same artifact into the same layer, that is, the same
42
+ file.
43
43
 
44
44
  For the erroneous example above, remove the extension from (3) and move
45
45
  it to (2):
46
46
 
47
- ```cdl
47
+ ```cds
48
48
  // (2) FooExtend.cds
49
49
  using from './Base';
50
50
  extend FooBar {
@@ -8,8 +8,10 @@
8
8
  "extend-repeated-intralayer",
9
9
  "extend-unrelated-layer",
10
10
  "redirected-to-ambiguous",
11
+ "redirected-to-complex",
11
12
  "redirected-to-unrelated",
12
13
  "rewrite-not-supported",
13
- "syntax-expected-integer"
14
+ "syntax-expected-integer",
15
+ "wildcard-excluding-one"
14
16
  ]
15
17
  }
@@ -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,
@@ -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
+