@sap/cds-compiler 2.15.8 → 3.1.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 (127) hide show
  1. package/CHANGELOG.md +102 -1590
  2. package/bin/.eslintrc.json +2 -1
  3. package/bin/cdsc.js +61 -46
  4. package/doc/API.md +11 -0
  5. package/doc/CHANGELOG_ARCHIVE.md +1592 -0
  6. package/doc/CHANGELOG_BETA.md +26 -5
  7. package/doc/CHANGELOG_DEPRECATED.md +55 -1
  8. package/doc/{DeprecatedOptions.md → DeprecatedOptions_v2.md} +3 -1
  9. package/doc/Versioning.md +20 -1
  10. package/lib/api/.eslintrc.json +2 -2
  11. package/lib/api/main.js +282 -156
  12. package/lib/api/options.js +17 -88
  13. package/lib/api/validate.js +6 -10
  14. package/lib/base/keywords.js +280 -110
  15. package/lib/base/message-registry.js +85 -25
  16. package/lib/base/messages.js +119 -89
  17. package/lib/base/model.js +46 -2
  18. package/lib/base/optionProcessorHelper.js +53 -21
  19. package/lib/checks/actionsFunctions.js +15 -12
  20. package/lib/checks/annotationsOData.js +1 -1
  21. package/lib/checks/cdsPersistence.js +1 -0
  22. package/lib/checks/elements.js +6 -6
  23. package/lib/checks/invalidTarget.js +1 -1
  24. package/lib/checks/nonexpandableStructured.js +1 -1
  25. package/lib/checks/queryNoDbArtifacts.js +2 -1
  26. package/lib/checks/selectItems.js +101 -15
  27. package/lib/checks/types.js +7 -8
  28. package/lib/checks/utils.js +2 -2
  29. package/lib/checks/validator.js +3 -3
  30. package/lib/compiler/assert-consistency.js +78 -21
  31. package/lib/compiler/base.js +6 -4
  32. package/lib/compiler/builtins.js +177 -10
  33. package/lib/compiler/checks.js +1 -1
  34. package/lib/compiler/define.js +28 -23
  35. package/lib/compiler/extend.js +75 -18
  36. package/lib/compiler/finalize-parse-cdl.js +25 -18
  37. package/lib/compiler/index.js +27 -11
  38. package/lib/compiler/moduleLayers.js +7 -0
  39. package/lib/compiler/populate.js +26 -39
  40. package/lib/compiler/propagator.js +12 -7
  41. package/lib/compiler/resolve.js +207 -236
  42. package/lib/compiler/shared.js +100 -93
  43. package/lib/compiler/tweak-assocs.js +13 -20
  44. package/lib/compiler/utils.js +20 -6
  45. package/lib/edm/annotations/preprocessAnnotations.js +12 -13
  46. package/lib/edm/csn2edm.js +35 -37
  47. package/lib/edm/edm.js +22 -13
  48. package/lib/edm/edmAnnoPreprocessor.js +349 -0
  49. package/lib/edm/edmInboundChecks.js +85 -0
  50. package/lib/edm/edmPreprocessor.js +338 -689
  51. package/lib/edm/edmUtils.js +97 -67
  52. package/lib/gen/Dictionary.json +29 -9
  53. package/lib/gen/language.checksum +1 -1
  54. package/lib/gen/language.interp +8 -31
  55. package/lib/gen/language.tokens +105 -114
  56. package/lib/gen/languageLexer.interp +1 -34
  57. package/lib/gen/languageLexer.js +892 -1007
  58. package/lib/gen/languageLexer.tokens +95 -106
  59. package/lib/gen/languageParser.js +20629 -22474
  60. package/lib/inspect/.eslintrc.json +4 -0
  61. package/lib/inspect/index.js +14 -0
  62. package/lib/inspect/inspectModelStatistics.js +81 -0
  63. package/lib/inspect/inspectPropagation.js +189 -0
  64. package/lib/inspect/inspectUtils.js +44 -0
  65. package/lib/json/from-csn.js +74 -69
  66. package/lib/json/to-csn.js +17 -14
  67. package/lib/language/antlrParser.js +2 -2
  68. package/lib/language/docCommentParser.js +61 -38
  69. package/lib/language/errorStrategy.js +52 -40
  70. package/lib/language/genericAntlrParser.js +424 -292
  71. package/lib/language/language.g4 +604 -687
  72. package/lib/language/multiLineStringParser.js +14 -42
  73. package/lib/language/textUtils.js +44 -0
  74. package/lib/main.d.ts +28 -42
  75. package/lib/main.js +104 -81
  76. package/lib/model/api.js +1 -1
  77. package/lib/model/csnRefs.js +57 -30
  78. package/lib/model/csnUtils.js +189 -287
  79. package/lib/model/revealInternalProperties.js +32 -10
  80. package/lib/model/sortViews.js +32 -31
  81. package/lib/modelCompare/compare.js +3 -0
  82. package/lib/optionProcessor.js +91 -57
  83. package/lib/render/.eslintrc.json +1 -1
  84. package/lib/render/DuplicateChecker.js +4 -7
  85. package/lib/render/manageConstraints.js +70 -2
  86. package/lib/render/toCdl.js +387 -367
  87. package/lib/render/toHdbcds.js +20 -16
  88. package/lib/render/toRename.js +44 -22
  89. package/lib/render/toSql.js +81 -59
  90. package/lib/render/utils/common.js +16 -3
  91. package/lib/render/utils/sql.js +20 -19
  92. package/lib/sql-identifier.js +6 -0
  93. package/lib/transform/db/.eslintrc.json +3 -2
  94. package/lib/transform/db/associations.js +43 -35
  95. package/lib/transform/db/cdsPersistence.js +5 -16
  96. package/lib/transform/db/constraints.js +1 -1
  97. package/lib/transform/db/expansion.js +7 -6
  98. package/lib/transform/db/flattening.js +16 -18
  99. package/lib/transform/db/transformExists.js +7 -5
  100. package/lib/transform/db/views.js +3 -3
  101. package/lib/transform/draft/.eslintrc.json +2 -2
  102. package/lib/transform/draft/db.js +6 -6
  103. package/lib/transform/draft/odata.js +6 -7
  104. package/lib/transform/forHanaNew.js +30 -24
  105. package/lib/transform/forOdataNew.js +14 -16
  106. package/lib/transform/localized.js +35 -25
  107. package/lib/transform/odata/toFinalBaseType.js +10 -10
  108. package/lib/transform/odata/typesExposure.js +17 -8
  109. package/lib/transform/odata/utils.js +1 -38
  110. package/lib/transform/transformUtilsNew.js +63 -77
  111. package/lib/transform/translateAssocsToJoins.js +2 -2
  112. package/lib/transform/universalCsn/.eslintrc.json +2 -2
  113. package/lib/transform/universalCsn/coreComputed.js +11 -6
  114. package/lib/transform/universalCsn/universalCsnEnricher.js +33 -5
  115. package/lib/utils/file.js +31 -21
  116. package/lib/utils/moduleResolve.js +0 -1
  117. package/lib/utils/timetrace.js +20 -21
  118. package/package.json +34 -4
  119. package/share/messages/syntax-expected-integer.md +9 -8
  120. package/doc/ApiMigration.md +0 -237
  121. package/doc/CommandLineMigration.md +0 -58
  122. package/doc/ErrorMessages.md +0 -175
  123. package/doc/FioriAnnotations.md +0 -94
  124. package/doc/ODataTransformation.md +0 -273
  125. package/lib/backends.js +0 -529
  126. package/lib/checks/unknownMagic.js +0 -41
  127. package/lib/fix_antlr4-8_warning.js +0 -56
@@ -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?