@sap/cds-compiler 2.15.4 → 3.0.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 (105) hide show
  1. package/CHANGELOG.md +33 -1590
  2. package/bin/cdsc.js +36 -33
  3. package/doc/CHANGELOG_ARCHIVE.md +1592 -0
  4. package/doc/CHANGELOG_BETA.md +3 -4
  5. package/doc/CHANGELOG_DEPRECATED.md +35 -1
  6. package/doc/{DeprecatedOptions.md → DeprecatedOptions_v2.md} +3 -1
  7. package/doc/Versioning.md +20 -1
  8. package/lib/api/.eslintrc.json +2 -2
  9. package/lib/api/main.js +220 -103
  10. package/lib/api/options.js +15 -85
  11. package/lib/api/validate.js +6 -10
  12. package/lib/base/keywords.js +216 -109
  13. package/lib/base/message-registry.js +60 -20
  14. package/lib/base/messages.js +65 -24
  15. package/lib/base/model.js +44 -2
  16. package/lib/checks/actionsFunctions.js +7 -5
  17. package/lib/checks/annotationsOData.js +1 -1
  18. package/lib/checks/cdsPersistence.js +1 -0
  19. package/lib/checks/elements.js +6 -6
  20. package/lib/checks/invalidTarget.js +1 -1
  21. package/lib/checks/nonexpandableStructured.js +1 -1
  22. package/lib/checks/queryNoDbArtifacts.js +2 -1
  23. package/lib/checks/selectItems.js +5 -1
  24. package/lib/checks/types.js +4 -2
  25. package/lib/checks/utils.js +2 -2
  26. package/lib/checks/validator.js +2 -1
  27. package/lib/compiler/assert-consistency.js +15 -10
  28. package/lib/compiler/builtins.js +87 -9
  29. package/lib/compiler/define.js +2 -2
  30. package/lib/compiler/extend.js +59 -11
  31. package/lib/compiler/finalize-parse-cdl.js +20 -9
  32. package/lib/compiler/index.js +25 -11
  33. package/lib/compiler/moduleLayers.js +7 -0
  34. package/lib/compiler/populate.js +13 -13
  35. package/lib/compiler/propagator.js +3 -3
  36. package/lib/compiler/resolve.js +193 -218
  37. package/lib/compiler/shared.js +47 -76
  38. package/lib/compiler/tweak-assocs.js +9 -10
  39. package/lib/compiler/utils.js +5 -0
  40. package/lib/edm/csn2edm.js +18 -21
  41. package/lib/edm/edmPreprocessor.js +25 -30
  42. package/lib/edm/edmUtils.js +10 -24
  43. package/lib/gen/language.checksum +1 -1
  44. package/lib/gen/language.interp +8 -30
  45. package/lib/gen/language.tokens +105 -114
  46. package/lib/gen/languageLexer.interp +1 -34
  47. package/lib/gen/languageLexer.js +889 -1007
  48. package/lib/gen/languageLexer.tokens +95 -106
  49. package/lib/gen/languageParser.js +20632 -22313
  50. package/lib/json/from-csn.js +56 -49
  51. package/lib/json/to-csn.js +10 -8
  52. package/lib/language/antlrParser.js +2 -2
  53. package/lib/language/docCommentParser.js +61 -38
  54. package/lib/language/errorStrategy.js +52 -40
  55. package/lib/language/genericAntlrParser.js +303 -229
  56. package/lib/language/language.g4 +573 -629
  57. package/lib/language/multiLineStringParser.js +14 -42
  58. package/lib/language/textUtils.js +44 -0
  59. package/lib/main.d.ts +27 -42
  60. package/lib/main.js +104 -81
  61. package/lib/model/csnRefs.js +1 -1
  62. package/lib/model/csnUtils.js +170 -283
  63. package/lib/model/revealInternalProperties.js +28 -8
  64. package/lib/model/sortViews.js +32 -31
  65. package/lib/optionProcessor.js +12 -21
  66. package/lib/render/.eslintrc.json +1 -1
  67. package/lib/render/DuplicateChecker.js +4 -7
  68. package/lib/render/manageConstraints.js +70 -2
  69. package/lib/render/toCdl.js +334 -339
  70. package/lib/render/toHdbcds.js +19 -15
  71. package/lib/render/toRename.js +44 -22
  72. package/lib/render/toSql.js +53 -51
  73. package/lib/render/utils/common.js +15 -1
  74. package/lib/render/utils/sql.js +20 -19
  75. package/lib/sql-identifier.js +6 -0
  76. package/lib/transform/db/.eslintrc.json +3 -2
  77. package/lib/transform/db/cdsPersistence.js +5 -15
  78. package/lib/transform/db/constraints.js +1 -1
  79. package/lib/transform/db/expansion.js +7 -6
  80. package/lib/transform/db/flattening.js +18 -19
  81. package/lib/transform/db/views.js +3 -3
  82. package/lib/transform/draft/.eslintrc.json +2 -2
  83. package/lib/transform/draft/db.js +6 -6
  84. package/lib/transform/draft/odata.js +6 -7
  85. package/lib/transform/forHanaNew.js +19 -22
  86. package/lib/transform/forOdataNew.js +10 -12
  87. package/lib/transform/localized.js +22 -16
  88. package/lib/transform/odata/toFinalBaseType.js +10 -10
  89. package/lib/transform/odata/typesExposure.js +3 -3
  90. package/lib/transform/odata/utils.js +1 -38
  91. package/lib/transform/transformUtilsNew.js +63 -77
  92. package/lib/transform/translateAssocsToJoins.js +2 -2
  93. package/lib/transform/universalCsn/.eslintrc.json +2 -2
  94. package/lib/transform/universalCsn/coreComputed.js +11 -6
  95. package/lib/transform/universalCsn/universalCsnEnricher.js +33 -5
  96. package/lib/utils/file.js +3 -3
  97. package/lib/utils/timetrace.js +20 -21
  98. package/package.json +35 -4
  99. package/doc/ApiMigration.md +0 -237
  100. package/doc/CommandLineMigration.md +0 -58
  101. package/doc/ErrorMessages.md +0 -175
  102. package/doc/FioriAnnotations.md +0 -94
  103. package/doc/ODataTransformation.md +0 -273
  104. package/lib/backends.js +0 -529
  105. package/lib/fix_antlr4-8_warning.js +0 -56
@@ -1,94 +0,0 @@
1
- # Translation of Fiori annotations
2
-
3
- > Status Oct 2019: too vague, old links, to be moved to internalDoc if we want to keep it.
4
-
5
- Fiori annotations are translated in a generic way. Essentially, write down in CDS precisely what you want to get in edmx.
6
-
7
- A more detailed description will follow soon, for the time being we hope the following example will give the idea:
8
-
9
- These CDS annotations
10
- ```
11
- @(
12
- UI.Chart : {
13
- ChartType: #Bullet,
14
- Measures: [ Revenue ],
15
- MeasureAttributes: [
16
- {
17
- Measure: Revenue,
18
- Role: #Axis1,
19
- DataPoint: '@UI.DataPoint#BulletChartDataPoint'
20
- }
21
- ]
22
- },
23
- UI.DataPoint#BulletChartDataPoint: {
24
- Title: 'Product',
25
- Value: Revenue,
26
- TargetValue: TargetRevenue,
27
- ForecastValue: ForecastRevenue,
28
- MinimumValue: MinValue,
29
- MaximumValue: MaxValue,
30
- CriticalityCalculation: {
31
- ImprovementDirection: #Target,
32
- ToleranceRangeLowValue: ToleranceRangeLow,
33
- ToleranceRangeHighValue: ToleranceRangeHigh,
34
- DeviationRangeLowValue: DeviationRangeLow,
35
- DeviationRangeHighValue: DeviationRangeHigh
36
- }
37
- }
38
- )
39
- Something ...;
40
- ```
41
- are translated into the following edmx:
42
- ```xml
43
- <Annotations Target="Something">
44
- <Annotation Term="UI.Chart">
45
- <Record>
46
- <PropertyValue EnumMember="UI.ChartType/Bullet"
47
- Property="ChartType" />
48
- <PropertyValue Property="Measures">
49
- <Collection>
50
- <PropertyPath>Revenue</PropertyPath>
51
- </Collection>
52
- </PropertyValue>
53
- <PropertyValue Property="MeasureAttributes">
54
- <Collection>
55
- <Record Type="UI.ChartMeasureAttributeType">
56
- <PropertyValue Property="Measure" PropertyPath="Revenue" />
57
- <PropertyValue Property="Role" EnumMember="UI.ChartMeasureRoleType/Axis1" />
58
- <PropertyValue Property="DataPoint" AnnotationPath="@UI.DataPoint#BulletChartDataPoint" />
59
- </Record>
60
- </Collection>
61
- </PropertyValue>
62
- </Record>
63
- </Annotation>
64
- <Annotation Term="UI.DataPoint" Qualifier="BulletChartDataPoint">
65
- <Record>
66
- <PropertyValue String="Product" Property="Title" />
67
- <PropertyValue Path="Revenue" Property="Value" />
68
- <PropertyValue Path="TargetRevenue" Property="TargetValue" />
69
- <PropertyValue Path="ForecastRevenue" Property="ForecastValue" />
70
- <PropertyValue Path="MinValue" Property="MinimumValue" />
71
- <PropertyValue Path="MaxValue" Property="MaximumValue" />
72
- <PropertyValue Property="CriticalityCalculation">
73
- <Record>
74
- <PropertyValue Property="ImprovementDirection" EnumMember="UI.ImprovementDirectionType/Target" />
75
- <PropertyValue Path="ToleranceRangeLow" Property="ToleranceRangeLowValue" />
76
- <PropertyValue Path="ToleranceRangeHigh" Property="ToleranceRangeHighValue" />
77
- <PropertyValue Path="DeviationRangeLow" Property="DeviationRangeLowValue" />
78
- <PropertyValue Path="DeviationRangeHigh" Property="DeviationRangeHighValue" />
79
- </Record>
80
- </PropertyValue>
81
- </Record>
82
- </Annotation>
83
- </Annotations>
84
- ```
85
-
86
-
87
- All suppoted Fiori annotations are defined in the following vocabularies:
88
- * [Core](http://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/vocabularies/Org.OData.Core.V1.xml)
89
- * [Measures](http://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/vocabularies/Org.OData.Measures.V1.xml)
90
- * [Capabilities](http://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/vocabularies/Org.OData.Capabilities.V1.xml)
91
- * [Aggregation](http://docs.oasis-open.org/odata/odata-data-aggregation-ext/v4.0/cs02/vocabularies/Org.OData.Aggregation.V1.xml)
92
- * [Common](https://wiki.scn.sap.com/wiki/download/attachments/448470974/Common.xml?api=v2)
93
- * [Communication](https://wiki.scn.sap.com/wiki/download/attachments/448470971/Communication.xml?api=v2)
94
- * [UI](https://wiki.scn.sap.com/wiki/download/attachments/448470968/UI.xml?api=v2)
@@ -1,273 +0,0 @@
1
- # ODATA Transformation
2
-
3
- > Status Oct 2019: outdated, uses old-style CSN, to be reworked completely -> move to internalDoc/.
4
- > For users, OData is a backend, they do not care too much that it works via a CSN transformation.
5
-
6
- Prior to the generation of EDMX (Entity Data Model XML) files from a CDS model,
7
- the following transformations are applied to the model. Most (but not all) of
8
- them become visible both in Augmented CSN and in Plain CSN:
9
-
10
- ## Generated foreign key fields for managed associations
11
-
12
- Managed associations do not have ON-conditions. Instead, they implicitly
13
- compare fields (usually the key fields) of the association's target entity with
14
- foreign key fields automatically generated into the entity containing the
15
- association.
16
-
17
- ### Creating the generated fields
18
-
19
- The ODATA transformation adds the generated foreign key fields to the model.
20
- The names of the generated foreign key fields are a concatenation of the
21
- association element name, an underscore, and the key name or its alias.
22
-
23
- Each generated foreign key field gets the name of the corresponding association
24
- as an annotation `@odata.foreignKey4`.
25
-
26
- _FIXME_: Do we want to keep that?
27
-
28
- For example, for the three association elements `a1`, `a2` and `a3` in the
29
- following snippet:
30
-
31
- ```
32
- service S {
33
- entity FromEntity {
34
- a1 : association to ToEntity; // Use target's keys
35
- a2 : association to ToEntity {x}; // Explicitly specified key
36
- a3 : association to ToEntity {x as z}; // Key with alias
37
- }
38
-
39
- entity ToEntity {
40
- key x : Integer;
41
- key y : Integer;
42
- }
43
- }
44
- ```
45
-
46
- the ODATA transformation would generate foreign key fields in the resulting CSN
47
- as follows (shown here in CDS source form):
48
-
49
- ```
50
- entity FromEntity {
51
- a1 : association to ToEntity;
52
- a2 : association to ToEntity {x};
53
- @odata.foreignKey4: 'a1'
54
- a1_x : Integer; // Generated foreign key
55
- @odata.foreignKey4: 'a1'
56
- a1_y : Integer; // Generated foreign key
57
- @odata.foreignKey4: 'a2'
58
- a2_x : Integer; // Generated foreign key
59
- @odata.foreignKey4: 'a3'
60
- a3_z : Integer; // Generated foreign key
61
- }
62
- ```
63
-
64
- It is an error if the generated fields conflict with existing fields.
65
-
66
- ### Annotation propagation
67
-
68
- The ODATA transformation propagates all annotations from the association to all
69
- its generated foreign key fields.
70
-
71
- _FIXME_: Do we want to keep that?
72
-
73
- ### Connecting the associations with the generated fields
74
-
75
- The CSN for the managed association elements contains a `foreignKeys` property,
76
- which is a dictionary of foreign key names (taken from the target key names, or
77
- from explicitly specified keys resp. their aliases) to the foreign key
78
- properties.
79
-
80
- The ODATA transformation adds a `generatedFieldName` property to each foreign
81
- key, containing the name of the generated foreign key field. Together with the
82
- `@odata.foreignKey4` annotation described above, this provides a bi-directional
83
- link between the association and its generated field.
84
-
85
- For the example shown above, the CSN for the three association elements `a1`,
86
- `a2` and `a3` would look as follows:
87
-
88
- ```
89
- "a1": {
90
- "indexNo": 1,
91
- "target": "S.ToEntity",
92
- "type": "cds.Association",
93
- "foreignKeys": {
94
- "x": {
95
- "indexNo": 1,
96
- "path": "x",
97
- "generatedFieldName": "a1_x"
98
- },
99
- "y": {
100
- "indexNo": 2,
101
- "path": "y",
102
- "generatedFieldName": "a1_y"
103
- }
104
- }
105
- },
106
- "a2": {
107
- "indexNo": 2,
108
- "target": "S.ToEntity",
109
- "type": "cds.Association",
110
- "foreignKeys": {
111
- "x": {
112
- "path": "x",
113
- "indexNo": 1,
114
- "generatedFieldName": "a2_x"
115
- }
116
- }
117
- },
118
- "a3": {
119
- "indexNo": 3,
120
- "target": "S.ToEntity",
121
- "type": "cds.Association",
122
- "foreignKeys": {
123
- "z": {
124
- "path": "x",
125
- "indexNo": 1,
126
- "generatedFieldName": "a3_z"
127
- }
128
- }
129
- },
130
- ```
131
-
132
- ## (Augmented CSN only): Adding `_service` to exposed artifacts
133
-
134
- For each artifact that is exposed by a service (including the service itself),
135
- the ODATA transformation adds a non-enumerable property `_service` to the
136
- artifact in the Augmented CSN model, containing a link to the corresponding
137
- service artifact.
138
-
139
- This is convenient for EDMX processors that want to process only exposed
140
- artifacts or only artifacts belonging to a specific service.
141
-
142
- ## Implicit redirection for non-exposed association targets
143
-
144
- For each exposed artifact that contains associations, it is checked that the
145
- association target is also exposed by the same service. If this is not the
146
- case, the ODATA transformation tries to find an "exposed representative" of
147
- the target, i.e. an exposed projection or view on the target, or an exposed entity
148
- that includes the target. If such a representative is found and unique, the
149
- association is implicitly redirected to the exposed representative.
150
-
151
- Note that only projections and projection-like views (i.e. those that have a
152
- single `from` source without `union`, `join` or nested queries) are considered
153
- as implicit redirection targets.
154
-
155
- Example:
156
-
157
- ```
158
- // All these entities are used as association targets below
159
- // Simple target
160
- entity E1 {
161
- key id : Integer;
162
- }
163
- // Base target included by E2a
164
- entity E2 {
165
- key id : Integer;
166
- }
167
- entity E2a : E2 {
168
- s : String(10);
169
- }
170
- // Base target included by S.E3a
171
- entity E3 {
172
- key id : Integer;
173
- }
174
-
175
- // Exposure in service
176
- service S {
177
- entity P1 as projection on E1; // Exposes simple target E1
178
- entity P2a as projection on E2a; // Exposes E2a but also its included E2
179
- entity E3a : E3 { }; // Exposes included E3
180
-
181
- entity Redirected {
182
- toE1 : association to E1; // Implicitly redirected to P1 (projection exposes E1)
183
- toE2 : association to E2; // Implicitly redirected to P2a (projection exposes something that includes E2)
184
- toE3 : association to E3; // Implicitly redirected to E3a (entity includes E3)
185
- }
186
- }
187
- ```
188
-
189
- ## Exposure checking
190
-
191
- Currently, it is assumed that services must be self-contained, i.e. that all
192
- associations within a service must point to targets also exposed by this
193
- service. This is checked by the ODATA transformation.
194
-
195
- _FIXME: The same restriction will probably apply when structured types are
196
- allowed as element types within exposed entities._
197
-
198
- ## Unraveling derived scalar types
199
-
200
- The ODATA transformation unravels derived scalar types, i.e. primitive types
201
- for which the user has provided a custom name (possibly multiple times in a
202
- chain) are replaced by the original primitive type. Annotations are propagated
203
- upwards in the chain from the primitive type to the most derived type.
204
-
205
- For example, the following CDS source
206
-
207
- ```
208
- @IsName: true
209
- type Name : String(20);
210
-
211
- @IsCustomer: true
212
- type CustomerName : Name;
213
-
214
- service S {
215
- entity E {
216
- name : CustomerName;
217
- }
218
- }
219
- ```
220
-
221
- essentially behaves as if the user had written
222
-
223
- ```
224
- service S {
225
- entity E {
226
- @IsCustomer: true
227
- @IsName: true
228
- name : String(20);
229
- }
230
- }
231
- ```
232
-
233
- ## (Tentative): Checking ON-conditions
234
-
235
- Currently, the ODATA transformation checks for various restrictions regarding
236
- ON-conditions of unmanaged associations:
237
-
238
- - only `=` and `AND` operators may be used
239
- - operands may only be paths or values (not expressions)
240
- - exactly one of the operands must traverse the association
241
-
242
- The intention behind this restriction is to produce a meaningful value for the
243
- `ReferentialConstraint` of the resulting `NavigationProperty`.
244
-
245
- _FIXME_: Do we want to keep that?
246
-
247
- ## (Tentative): Renaming annotations
248
-
249
- Currently, the ODATA transformation renames various "shorthand" annotations to
250
- their more elaborate "long form".
251
-
252
- | Original name | New name |
253
- | -------------------------- | --------------------------------------------- |
254
- | `@label` | `@Common.Label` |
255
- | `@label` | `@Common.Label` |
256
- | `@title` | `@Common.Label` |
257
- | `@ValueList.entity` | `@Common.ValueList.entity` |
258
- | `@ValueList.type` | `@Common.ValueList.type` |
259
- | `@Capabilities.Deletable` | `@Capabilities.DeleteRestrictions.Deletable` |
260
- | `@Capabilities.Insertable` | `@Capabilities.InsertRestrictions.Insertable` |
261
- | `@Capabilities.Updatable` | `@Capabilities.UpdateRestrictions.Updatable` |
262
- | `@readonly` | `@Core.Immutable` |
263
- | `@important` | `@UI.Importance` |
264
- | `@assert.format` | `@Validation.pattern: value` |
265
- | `@assert.range` | `@Validation.Minimum/Maximum: value` |
266
- | | or `@Validation.AllowedValues: {` |
267
- | | `@Core.SymbolicName: enum-name }` |
268
-
269
-
270
- For the annotation `@important` (which is renamed to `@UI.Importance`), the
271
- values `true`/`false` are also replaced by the enum constants `#High`/`#Low`.
272
-
273
- _FIXME_: Do we want to keep that?