@sap/cds-compiler 6.4.2 → 6.5.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 (71) hide show
  1. package/CHANGELOG.md +87 -1159
  2. package/README.md +1 -10
  3. package/doc/IncompatibleChanges_v5.md +436 -0
  4. package/doc/IncompatibleChanges_v6.md +659 -0
  5. package/doc/Versioning.md +3 -7
  6. package/lib/api/main.js +1 -0
  7. package/lib/api/options.js +5 -0
  8. package/lib/api/validate.js +3 -0
  9. package/lib/base/message-registry.js +25 -2
  10. package/lib/base/messages.js +1 -1
  11. package/lib/base/model.js +3 -2
  12. package/lib/checks/actionsFunctions.js +6 -3
  13. package/lib/checks/existsExpressionsOnlyForeignKeys.js +16 -10
  14. package/lib/checks/existsInForbiddenPlaces.js +32 -0
  15. package/lib/checks/existsMustEndInAssoc.js +1 -1
  16. package/lib/checks/existsMustNotStartWithDollarSelf.js +31 -0
  17. package/lib/checks/validator.js +6 -2
  18. package/lib/compiler/assert-consistency.js +5 -7
  19. package/lib/compiler/builtins.js +5 -6
  20. package/lib/compiler/checks.js +4 -8
  21. package/lib/compiler/define.js +244 -459
  22. package/lib/compiler/extend.js +297 -11
  23. package/lib/compiler/finalize-parse-cdl.js +2 -10
  24. package/lib/compiler/generate.js +29 -1
  25. package/lib/compiler/populate.js +21 -63
  26. package/lib/compiler/propagator.js +1 -2
  27. package/lib/compiler/resolve.js +2 -12
  28. package/lib/compiler/shared.js +145 -114
  29. package/lib/compiler/tweak-assocs.js +14 -10
  30. package/lib/compiler/utils.js +97 -0
  31. package/lib/compiler/xpr-rewrite.js +113 -140
  32. package/lib/edm/annotations/edmJson.js +9 -6
  33. package/lib/edm/annotations/genericTranslation.js +8 -4
  34. package/lib/edm/csn2edm.js +3 -4
  35. package/lib/edm/edmInboundChecks.js +1 -2
  36. package/lib/edm/edmPreprocessor.js +3 -3
  37. package/lib/gen/CdlGrammar.checksum +1 -1
  38. package/lib/gen/CdlParser.js +4 -3
  39. package/lib/gen/Dictionary.json +16 -1
  40. package/lib/json/from-csn.js +4 -6
  41. package/lib/json/to-csn.js +3 -3
  42. package/lib/model/csnRefs.js +13 -4
  43. package/lib/model/enrichCsn.js +4 -2
  44. package/lib/optionProcessor.js +8 -4
  45. package/lib/parsers/AstBuildingParser.js +1 -1
  46. package/lib/render/utils/sql.js +3 -2
  47. package/lib/transform/db/applyTransformations.js +1 -1
  48. package/lib/transform/db/assertUnique.js +3 -3
  49. package/lib/transform/db/assocsToQueries/normalizeFrom.js +33 -0
  50. package/lib/transform/db/assocsToQueries/transformExists.js +17 -13
  51. package/lib/transform/db/assocsToQueries/utils.js +1 -6
  52. package/lib/transform/db/backlinks.js +4 -4
  53. package/lib/transform/db/cdsPersistence.js +4 -4
  54. package/lib/transform/db/constraints.js +4 -4
  55. package/lib/transform/db/expansion.js +5 -5
  56. package/lib/transform/db/flattening.js +4 -5
  57. package/lib/transform/db/rewriteCalculatedElements.js +3 -3
  58. package/lib/transform/db/temporal.js +11 -11
  59. package/lib/transform/draft/db.js +2 -0
  60. package/lib/transform/draft/odata.js +5 -7
  61. package/lib/transform/effective/flattening.js +1 -2
  62. package/lib/transform/forOdata.js +3 -3
  63. package/lib/transform/forRelationalDB.js +1 -1
  64. package/lib/transform/localized.js +13 -20
  65. package/lib/transform/odata/createForeignKeys.js +1 -2
  66. package/lib/transform/odata/flattening.js +1 -2
  67. package/lib/transform/odata/toFinalBaseType.js +52 -55
  68. package/lib/transform/transformUtils.js +3 -4
  69. package/package.json +3 -3
  70. package/doc/CHANGELOG_BETA.md +0 -464
  71. package/doc/CHANGELOG_DEPRECATED.md +0 -235
@@ -0,0 +1,659 @@
1
+ # Incompatible Changes in CDS Compiler Version 6
2
+
3
+ This document lists (potentially) incompatible changes
4
+ which came with Compiler Version 6.
5
+
6
+ <!-- toc: start -->
7
+
8
+ 1. [Preamble](#preamble)
9
+ 2. [General](#general)
10
+ 1. [Increase Required Node.js Version to 20](#increase-required-nodejs-version-to-20)
11
+ 2. [Deprecate HDBCDS backend](#deprecate-hdbcds-backend)
12
+ 3. [Remove old deprecated flags](#remove-old-deprecated-flags)
13
+ 3. [Changes in CDL and CSN parser](#changes-in-cdl-and-csn-parser)
14
+ 1. [Virtual elements in views](#virtual-elements-in-views)
15
+ 2. [`syntax-deprecated-ref-virtual` (warning in v5)](#syntax-deprecated-ref-virtual-warning-in-v5)
16
+ 3. [`syntax-unexpected-filter` (warning in v5)](#syntax-unexpected-filter-warning-in-v5)
17
+ 4. [`syntax-unexpected-after` (warning in v5)](#syntax-unexpected-after-warning-in-v5)
18
+ 5. [`syntax-duplicate-clause` (error in v5, downgradable)](#syntax-duplicate-clause-error-in-v5-downgradable)
19
+ 6. [`syntax-unexpected-many-one` (error in v5, downgradable)](#syntax-unexpected-many-one-error-in-v5-downgradable)
20
+ 7. [`syntax-invalid-name` (error in v5, downgradable with deprecated flag)](#syntax-invalid-name-error-in-v5-downgradable-with-deprecated-flag)
21
+ 8. [CSN parser: reject elements, enum and items inside cast function](#csn-parser-reject-elements-enum-and-items-inside-cast-function)
22
+ 4. [Changes in Core Compiler](#changes-in-core-compiler)
23
+ 1. [Require columns to be virtual if they select non-virtual element of virtual structure](#require-columns-to-be-virtual-if-they-select-non-virtual-element-of-virtual-structure)
24
+ 2. [No SET for simple query inside parentheses](#no-set-for-simple-query-inside-parentheses)
25
+ 3. [Inconsistent handling of `@cds.persistence.skip: 'if-unused'`](#inconsistent-handling-of-cdspersistenceskip-if-unused)
26
+ 4. [Propagate actions from aspect to managed composition](#propagate-actions-from-aspect-to-managed-composition)
27
+ 5. [Disallow "not null default null"](#disallow-not-null-default-null)
28
+ 6. [Don't propagate doc comments](#dont-propagate-doc-comments)
29
+ 7. [No FK generation for "Association to Many Foo"](#no-fk-generation-for-association-to-many-foo)
30
+ 8. [Propagate journal annotation to generated entities](#propagate-journal-annotation-to-generated-entities)
31
+ 5. [Changes in OData/EDM](#changes-in-odataedm)
32
+ 1. [Shorten message id prefix](#shorten-message-id-prefix)
33
+ 6. [Changes in to.cdl()](#changes-in-tocdl)
34
+ 1. [Nesting Definitions in Services and Contexts](#nesting-definitions-in-services-and-contexts)
35
+ 2. [No namespace file](#no-namespace-file)
36
+ 7. [Changes in to.sql()](#changes-in-tosql)
37
+ 1. [DB standard functions](#db-standard-functions)
38
+ 2. [Change semantics of `!=`](#change-semantics-of-!=)
39
+ 3. [Change translation of `$now`](#change-translation-of-now)
40
+ 4. [Switch off native HANA associations](#switch-off-native-hana-associations)
41
+
42
+ <!-- toc: end -->
43
+
44
+ ## Preamble
45
+
46
+ Major versions are used to clean up things that could potentially break existing user code.
47
+ Such changes always have a reason, and we don't introduce them "just for the sake of it".
48
+
49
+
50
+ ## General
51
+
52
+ ### Increase Required Node.js Version to 20
53
+
54
+ Node.js 18 reaches EOL on April 30th 2025. Accordingly, we require Node.js 20 starting with cds-compiler v6.
55
+
56
+
57
+ ### Deprecate HDBCDS backend
58
+
59
+ Only relevant for HANA on-prem (or "old" HaaS), as HANA CDS is not available on HANA Cloud.
60
+
61
+ In the early days of CAP, the only possibility to generate the DB schema was via
62
+ the hdbcds backend (i.e. generating HANA CDS files).
63
+
64
+ Since cds-compiler 1.5 the DB backend could alternatively be generated via hdbtable/hdbview,
65
+ while for new projects the default still was hdbcds.
66
+ With CDS 7 (corresponds to cds-compiler 4), the default was switched to hdbtable.
67
+
68
+ For regular CAP projects on HANA, there now is no need to use the hdbcds backend any longer.
69
+ They should migrate to hdbtable, see [hdbcds-to-hdbtable migration guide](https://cap.cloud.sap/docs/cds/compiler/hdbcds-to-hdbtable).
70
+
71
+ We started deprecating the hdbcds backend in compiler V5.
72
+ Now in V6:
73
+ - Document as deprecated
74
+ - No new features in hdbcds backend
75
+ - No bugfixes
76
+ - Using the hdbcds backend leads to an error message (can be downgraded to warning or info)
77
+ - Make sure that hdbcds is removed from all documentation ...
78
+ - ... and is not mentioned in any command line tool (e.g. `cds`)
79
+
80
+ The hdbcds backend can still be used by downgrading the error, e.g. in _package.json_:
81
+ ```json
82
+ {
83
+ "cds": {
84
+ "cdsc": {
85
+ "severities": {
86
+ "api-deprecated-hdbcds": "Warning"
87
+ }
88
+ }
89
+ }
90
+ }
91
+ ```
92
+
93
+ With the next major version V7, we plan to remove the code.
94
+
95
+ When is hdbcds still needed?
96
+
97
+ - If custom code makes use of the HANA CDS metadata in the HANA catalog
98
+ - XSA to CAP migration currently requires deployment via hdbcds as an intermediate step.
99
+ Should no longer be necessary with HANA 2 SPS08 (RTC 20.11.2024)
100
+
101
+
102
+ ### Remove old deprecated flags
103
+
104
+ As mentioned in the ChangeLog, we removed deprecated flags `includesNonShadowedFirst`,
105
+ `eagerPersistenceForGeneratedEntities` and `noKeyPropagationWithExpansions`.
106
+ If you really still need them, please let us know (and give some reasons for your wish).
107
+
108
+ All hidden deprecated flags (i.e. those listed as removed before,
109
+ but actually having been just renamed) are now really removed.
110
+
111
+
112
+ ## Changes in CDL and CSN parser
113
+
114
+ The first of the following sub sections covers an potential incompatible change
115
+ with `virtual` columns in a `select`.
116
+
117
+ The remaining sections cover warnings and configurable errors in v5 that
118
+ become errors in v6 (some are downgradable, some are not).
119
+ Some message id and text might be different.
120
+ If possible, the message text now includes expected tokens which are valid
121
+ instead of the erroneous one.
122
+
123
+
124
+ ### Virtual elements in views
125
+
126
+ Up to V5, a virtual element in a view can only be declared when also
127
+ a value (literal, reference, even expression is possible) is specified.
128
+
129
+ ```cds
130
+ entity E {
131
+ a : String;
132
+ b : String;
133
+ c : Integer;
134
+ foo: { bar : Integer; }
135
+ };
136
+ view V as select from E {
137
+ virtual null as myV0 : String,
138
+ virtual 17 as myV1 : Integer,
139
+ virtual 3*c as myV2 : Integer,
140
+
141
+ virtual a as myV3 : String, // pre v6: refers to E:a
142
+ virtual a : String, // pre v6: refers to E:a
143
+ virtual a as myV4, // pre v6: refers to E:a
144
+ virtual b, // pre v6: refers to E:b
145
+ virtual E.c,
146
+ virtual foo.bar
147
+ }
148
+ ```
149
+
150
+ Important: When the "value" is a reference without an explicit type (CDL style cast),
151
+ all properties (incl. annotations) of the base element are propagated to the virtual view element,
152
+ and the view element can be traced back to the respective element of the base entity.
153
+
154
+ In V6, it is possible to define "new" virtual elements in a view without a value,
155
+ with and without providing a type:
156
+ ```cds
157
+ view V as select from E {
158
+ virtual newV0 : String, // v6: just new name, no reference to `newV0`
159
+ virtual newV1, // v6: just new name, no reference to `newV1`
160
+ }
161
+ ```
162
+
163
+ In v6, we __change the semantics__ of such virtual select list entries:
164
+ the compiler doesn't try to resolve names `newV0/1` as elements of `E`,
165
+ but these are new elements that are not linked to an element of `E` in any way.
166
+
167
+ Consequence: if the name of the virtual element is present as element in `E`
168
+ and there is no explicit type specification (as this would break the chain anyway),
169
+ the semantics of such a select item changes.
170
+ ```cds
171
+ view V as select from E {
172
+ virtual a : String, // v5: like `virtual a as a : String`
173
+ virtual b, // v5: like `virtual b as b`
174
+ }
175
+ ```
176
+ Incompatibilities in the example:
177
+ - none for `a`, as the CDL style cast cuts off property propagation anyway
178
+ - some for `b`: no properties are propagated anymore;
179
+ use `virtual b as b` to get the v5 behavior also in v6.
180
+
181
+ There is no change in semantics if the syntax clearly indicates that the select item is
182
+ a reference, e.g. if an alias is present, if a table alias is used, or if the reference is a path:
183
+ ```cds
184
+ view V as select from E {
185
+ virtual a as myV3, // alias -> `a` is a reference (no change)
186
+ virtual E.c, // table alias -> this is a reference (no change)
187
+ virtual foo.bar // path -> this is a reference (no change)
188
+ }
189
+ ```
190
+
191
+ With v5.9, we have introduced a warning for those select items whose semantics changes with in v6.
192
+
193
+
194
+ ### `syntax-deprecated-ref-virtual` (warning in v5)
195
+
196
+ In v6, an initial `virtual` at the beginning of an `expand` or `inline` column is
197
+ parsed in the same way as an initial `virtual` at the beginning of a `select` column.
198
+
199
+ Up to v5, the nested `virtual` was always considered a reference or function name,
200
+ which could lead to a constructed incompatibility:
201
+
202
+ ```cds
203
+ entity Base {
204
+ key virtual: Integer; // element named 'virtual' - great choice
205
+ name: Integer;
206
+ me: Association to Base;
207
+ }
208
+ entity Proj as select from Base {
209
+ virtual -42 as minusFourtyTwo, // v5=v6: 'virtual' is keyword
210
+ me {
211
+ virtual -42 as subtraction, // v5: 'virtual' is ref, v6: keyword → Error
212
+ virtual name, // v5: 'virtual' is ref, v6: keyword → Error
213
+ virtual (42) as funcCall, // v5: 'virtual' is function, v6: keyword → Error
214
+ },
215
+ virtual (42) as fourtyTwo, // v5=v6: 'virtual' is keyword
216
+ }
217
+ ```
218
+
219
+ As `virtual` is not allowed inside `expand` and `inline`, the above model
220
+ leads to a syntax error in v6.
221
+
222
+ Situation v5: warning (`syntax-deprecated-ref-virtual`, introduced in v5.9);
223
+ v6: (non-downgradable) error `syntax-unexpected-modifier` (new parser) or
224
+ `syntax-deprecated-ref-virtual` (old parser)
225
+
226
+ _Fix_: if you really want to name an element `virtual`
227
+ (in any lower-/upper-case variation), use a delimited id (`![virtual]`)
228
+ when referring to it at the beginning of an `expand`/`inline` column expression
229
+ (as you already have to do so at the beginning of a `select` column expressions).
230
+
231
+
232
+ ### `syntax-unexpected-filter` (warning in v5)
233
+
234
+ You can't provide a filter to the result of a function call.
235
+ In v5, it is simply ignored, with a warning since v5.8.
236
+
237
+ ```cds
238
+ entity Proj as select from Base {
239
+ count(*)[ uncheckedFilterRef > 0 ] as count,
240
+ assoc()[ id > 0 ] as target
241
+ };
242
+ entity Base { id: Integer; assoc: Association to Target; }
243
+ entity Target() { key id: Integer; } // in definitions unnecessary () are still allowed
244
+ ```
245
+
246
+ Situation v5: warning (introduced in v5.8);
247
+ v6: downgradable error.
248
+
249
+ _Fix:_ Delete the ignored filter.
250
+ In the second column, you probably meant to follow the association `assoc`,
251
+ not calling a function named `assoc` → remove the `()`.
252
+
253
+
254
+ ### `syntax-unexpected-after` (warning in v5)
255
+
256
+ #### Default
257
+
258
+ Because CDL has no array literals, providing a `default` value
259
+ for an element or parameter using `many` or `array of` as type is erroneous.
260
+
261
+ ```cds
262
+ entity E { elem: many String default 42; } // error in v5: syntax-unexpected-token
263
+ action Act( PAR: many String default 42 ); // warning in v5: syntax-unexpected-after
264
+ ```
265
+
266
+ Situation v5: error `syntax-unexpected-token` for element; warning `syntax-unexpected-after` for parameter
267
+ (introduced in v5.3), OData backend ignores the default value;
268
+ v6: (non-downgradable) error `syntax-unexpected-token` for element and parameter.
269
+
270
+ #### Annotation
271
+
272
+ The effect of the following type expression is probably very surprising:
273
+ `String`, `null` and `enum` determine the _line_ type,
274
+ but `@anno` _in between_ `null` and `enum` clauses is assigned to the _complete element_.
275
+
276
+ ```cds
277
+ entity E {
278
+ bar: many String null @anno enum { symbol }; // @anno annotates to element(!), not the line type
279
+ }
280
+ ```
281
+
282
+ Situation v5: warning `syntax-unexpected-after` (introduced in v5.3);
283
+ v6: (non-downgradable) error `syntax-unexpected-token`.
284
+
285
+ _Fix:_ move the annotation assignment out of the type expression, e.g. before the element name `bar`.
286
+
287
+
288
+ ### `syntax-duplicate-clause` (error in v5, downgradable)
289
+
290
+ In some places it is possible to provide contradicting clauses.
291
+
292
+ Has the following element a `not null` constraint or not?
293
+ ```cds
294
+ entity E {
295
+ elem: Integer null default 42 not null;
296
+ }
297
+ ```
298
+
299
+ Is the following association “to many” (via `*` inside `[…]`) or “to one”?
300
+ ```cds
301
+ entity E {
302
+ key ID: UUID;
303
+ assoc: Association[*] to one E;
304
+ }
305
+ ```
306
+
307
+ Situation v5: downgradable error (`syntax-duplicate-clause`);
308
+ v6: (non-downgradable) error `syntax-unexpected-token`.
309
+
310
+ Remark: if the clause is repeated without conflicting semantics,
311
+ the corresponding message is still just a warning `syntax-duplicate-equal-clause`.
312
+
313
+ ### `syntax-unexpected-many-one` (error in v5, downgradable)
314
+
315
+ A composition type definition with a user-provided foreign key (not a commonly used feature)
316
+ to an entity named `many` or `one` (in all lower-/upper-case variations)
317
+ looks syntactically like a managed composition of an anonymous aspect.
318
+ Because the latter is not allowed as type (only as element), the following model leads to a syntax error:
319
+
320
+ ```cds
321
+ entity Many { key id };
322
+ type MyType: Composition of Many { id };
323
+ ```
324
+
325
+ Situation v5: downgradable error `syntax-unexpected-many-one`;
326
+ v6: (non-downgradable) error `type-unexpected-target-aspect`.
327
+
328
+ ### `syntax-invalid-name` (error in v5, downgradable with deprecated flag)
329
+
330
+ An empty string as name for an element (or any other definition) is not the best idea:
331
+
332
+ ```cds
333
+ entity E {
334
+ ![]: Integer;
335
+ }
336
+ ```
337
+ > Remark: Empty names are neither allowed on HANA, nor in OData. Probably none uses this.
338
+
339
+ Situation v5: error, downgradable with deprecated flag (`--deprecated downgradableErrors --warn syntax-invalid-name`);
340
+ v6: non-downgradable error.
341
+
342
+
343
+ ### CSN parser: reject elements, enum and items inside cast function
344
+
345
+ The following properties are no longer allowed to occur in the SQL cast function:
346
+ - `enum`
347
+ - `elements`
348
+ - `items`
349
+
350
+
351
+ ## Changes in Core Compiler
352
+
353
+ ### Require columns to be virtual if they select non-virtual element of virtual structure
354
+
355
+ If a user selects an element of a virtual structure that itself is not explicitly marked as virtual,
356
+ then the select item must be explicitly marked as virtual, too.
357
+ The compiler does not propagate `virtual` to the column, as the selected element isn't `virtual`, either.
358
+
359
+ ```cds
360
+ entity E {
361
+ virtual struct : { // < virtual struct
362
+ a : String; // < elem is not marked as virtual
363
+ b : String; // < elem is not marked as virtual
364
+ virtual c : String // < elem is marked as virtual
365
+ };
366
+ };
367
+ entity P as projection on E {
368
+ struct.a, // < ERR (since v6, warning before)
369
+ virtual struct.b, // < ok
370
+ struct.c // < ok
371
+ };
372
+ ```
373
+
374
+ Situation v5: warning; v6: configurable error.
375
+
376
+ ```
377
+ Warning[def-missing-virtual]: Prepend ‘virtual’ to current select item - referred element “E:struct” is virtual which is not inherited
378
+ |
379
+ ../e.cds:N:3-9, at entity:“P”/column:“str”
380
+ |
381
+ 9 | struct.str
382
+ | ^^^^^^
383
+ ```
384
+
385
+ Note: Upon flattening, the flat elements resulting from `struct` are all virtual.
386
+
387
+ Remark: it would be nice and users probably would expect that `virtual` is
388
+ propagated to the elements.
389
+
390
+
391
+ ### No SET for simple query inside parentheses
392
+
393
+ Before V6, (unnecessary) parentheses around a simple query, like in
394
+ ```cds
395
+ entity E { id };
396
+ entity V as (select from E) order by id;
397
+ ```
398
+ were represented in CSN by a `SET`:
399
+ ```json
400
+ query: { SET: { args: [ { SELECT: { from: … } } ], orderBy: … } }
401
+ ```
402
+
403
+ This is now simplified to
404
+ ```json
405
+ query: { SELECT: { from: …, orderBy: … } }
406
+ ```
407
+
408
+ If the compiler receives as input a CSN in the "old" format, it is rewritten.
409
+
410
+ Additionally, we do not allow repeated `order by` or `limit`, e.g.
411
+ ```cds
412
+ entity V as ( select from E order by id ) order by id;
413
+ ```
414
+ This change should be uncritical, as the generated SQL was invalid (at least for HANA and SQLite):
415
+ ```sql
416
+ CREATE VIEW V AS ((SELECT E_0.id FROM E AS E_0 ORDER BY id)) ORDER BY id;
417
+ ```
418
+
419
+ Remark: such `SET` queries as generated by v5 were not supported by runtimes in some situations,
420
+ i.e. this change potentially fixes the runtime behavior.
421
+
422
+
423
+ ### Inconsistent handling of `@cds.persistence.skip: 'if-unused'`
424
+
425
+ In our backends we have
426
+ - checks that test for `=== true`
427
+ - checks that test for truthy
428
+
429
+ In v6, consistently check for truthiness, but have a special handling for `if-unused` and handle it as false.
430
+
431
+ This change is not expected to have any observable changes.
432
+
433
+
434
+ ### Propagate actions from aspect to managed composition
435
+
436
+ The generated child entity for a managed composition of named aspect should
437
+ inherit the actions (and functions) from the aspect.
438
+
439
+ ```cds
440
+ aspect A {
441
+ key id : String;
442
+ } actions {
443
+ action a();
444
+ };
445
+
446
+ entity E {
447
+ key id : String;
448
+ comp: Composition of A; // -> generated E.comp should have the action
449
+ };
450
+ ```
451
+
452
+ `E.comp` "includes" `A`, so that _all_ properties of `A` (also actions/functions) become properties of `E.comp`.
453
+ Ensure that order of key elements does not change.
454
+
455
+ It is possible switch back to old behavior via deprecated switch `noCompositionIncludes`.
456
+
457
+
458
+ ### Disallow "not null default null"
459
+
460
+ There is no known use case where an element definition with both `not null` and `default null` is reasonable.
461
+ ```cds
462
+ elem : <type> not null default null;
463
+ ```
464
+
465
+ Such a definition is rejected by the compiler
466
+ - in element definitions
467
+ - in entity parameter definitions
468
+ - in action/function parameter definitions
469
+
470
+ The first two should be uncritical, as the combination of `not null` and `default null` should lead to an error
471
+ upon deployment. The third may be an incompatible change.
472
+
473
+ The error (`type-unexpected-null`) is configurable.
474
+
475
+
476
+ ### Don't propagate doc comments
477
+
478
+ Currently, doc comments are controlled via switch `docComment` with three-valued logic:
479
+
480
+ - truthy : keep doc comments in CSN, translate CDL doc comments to `doc` property in CSN
481
+ - falsy excl. `false` : keep doc property in CSN, don't translate CDL doc comments to `doc` property in CSN
482
+ - `false` : remove doc comments (also if they come in via CSN)
483
+
484
+ If doc comments are present in CSN,
485
+
486
+ In v5, doc comments are propagated according to usual propagation rules.
487
+ In v6, doc comments are by default not propagated, only if the option `propagateDocComments` is set.
488
+
489
+
490
+ ### No FK generation for "Association to Many Foo"
491
+
492
+ An association "to many" w/o explicit FKs and w/o ON-condition
493
+ ```cds
494
+ entity E {
495
+ key id : Integer;
496
+ assoc: Association to many F;
497
+ }
498
+ entity F { key id : Integer; }
499
+ ```
500
+ has up to and including v5 been treated as managed association with implicit FK, i.e. FKs are generated that reflect the key of the target.
501
+
502
+ Client CSN:
503
+ ```json
504
+ "f": {
505
+ "type": "cds.Association",
506
+ "cardinality": {"max": "*"},
507
+ "target": "F",
508
+ "keys": [{"ref": ["id"]}]
509
+ }
510
+ ```
511
+ OData CSN:
512
+ ```json
513
+ "f": {
514
+ "type": "cds.Association",
515
+ "cardinality": {"max": "*"},
516
+ "target": "S.F",
517
+ "keys": [{
518
+ "ref": ["id"],
519
+ "$generatedFieldName": "f_id"
520
+ }]
521
+ },
522
+ "f_id": {
523
+ "type": "cds.Integer",
524
+ "@odata.foreignKey4": "f"
525
+ }
526
+ ```
527
+ This is in most cases not what a user has intended, thus there was a warning `assoc-incomplete-to-many`.
528
+
529
+ In v6, the situation is as follows:
530
+
531
+ - such a definition is to be regarded as an "unspecified" association/composition, similar to
532
+ `Association to many F {}`
533
+ - core compiler: no compiler message, do not generate a `keys` array (not even an empty one)
534
+ - for.odata/to.edmx: do not generate foreign key elements, just render NavigationProperty
535
+ - toSql: raise error for such association (i.e. for association with cardinality to-many w/o ON condition and
536
+ w/o keys array)
537
+
538
+ The error in the SQL backend is to prevent data loss in existing projects that by mistake
539
+ have such associations. Otherwise we would just drop FK columns on the database and loose
540
+ the content. In a future major release (ideally not already v7 but better v8) we can
541
+ assume that all projects have been fixed and remove the error.
542
+
543
+ User action:
544
+ - if a real managed association is needed, fix by changing cardinality to "to one"
545
+ - if an unspecified association is needed, add explicit empty keys array `{}`
546
+ - or model a correct to-many association, if that is what is needed
547
+
548
+ There is a deprecated flag `noQuasiVirtualAssocs` to get back the old behavior.
549
+
550
+
551
+ ### Propagate journal annotation to generated entities
552
+
553
+ Build/tools team has decided to change semantics of `@cds.persistence.journal` (hdbmigrationtable),
554
+ so that now switching on journal for an entity automatically also switches it on for the related texts entity.
555
+ User can opt out by explicitly annotating texts entity with `@cds.persistence.journal: false`.
556
+
557
+ When using "composition of aspect", this annotation is now also copied from an entity to its generated composition children.
558
+
559
+ The compiler doesn't copy the annotation to generated drafts entity.
560
+ Reasoning: hdbtablemigration mainly used for controlling
561
+ migration of large tables, but the drafts table usually has only few entries.
562
+ Don't copy it to localized convenience views, too.
563
+
564
+ As always, we don't overwrite user-provided annotation `@cds.persistence.journal`
565
+ on a generated entity.
566
+
567
+
568
+ ## Changes in OData/EDM
569
+
570
+ ### Shorten message id prefix
571
+
572
+ Shorten message id prefix `odata-spec-violation-` to `odata-`.
573
+
574
+ Benefit?
575
+ - shorten the IDs
576
+ - also: define more specific msg IDs (currently there are rather coarse grained)
577
+
578
+ Only "incompatible" effect: people would see different msg id
579
+ (the old msg ids still can be used to downgrade messages, the new should be preferred, though).
580
+
581
+
582
+ ## Changes in to.cdl()
583
+
584
+ ### Nesting Definitions in Services and Contexts
585
+
586
+ With compiler v5.9., it became possible to nest definitions into services/contexts
587
+ and extract a common namespace via setting options. In v6, nesting is made the default.
588
+ It is possible to switch back to the old behavior by setting these options to `false`:
589
+ - `renderCdlDefinitionNesting`
590
+ - `renderCdlCommonNamespace`
591
+
592
+
593
+ ### No namespace file
594
+
595
+ Behavior up to v6: If input CSN for `toCdl` contains property `namespace`,
596
+ `toCdl` produces two files. One contains the model, the other one only contains a `namespace`
597
+ and a `using` directive. This second file is only needed to ensure that when fed into the compiler,
598
+ the result is again a CSN with a `namespace`.
599
+
600
+ The `namespace` is not an official CSN property, but is only needed in the Node runtime for
601
+ a shortcut to address some entities in custom code without having to write their full name.
602
+ When transferring CSN, it is not intended to also transfer the `namespace`, as this shortcut
603
+ mechanism should be set up by the consumer of the CSN in his app, e.g. by adding an `index.cds`
604
+ which adds the respective namespace.
605
+
606
+ In v6, `toCdl` does not render this additional file anymore.
607
+
608
+ ## Changes in to.sql()
609
+
610
+ ### DB standard functions
611
+
612
+ The new standard functions are currently available via switch `standardDatabaseFunctions`.
613
+ In v6, make them default, but keep switch to allow users to get back old behavior.
614
+ The function names are case sensitive, thus the native DB function is available by
615
+ writing the function name not in lower case.
616
+
617
+ Hint for users: use sql preview in VS Code to check what is actually used/rendered.
618
+
619
+
620
+ ### Change semantics of `!=`
621
+
622
+ Change behavior of operator `!=` in SQL backend:
623
+ - situation v5: SQL semantics, behaves like `<>`
624
+ - planned for v6: switch to 2-valued Boolean semantics, for precise translation see BLI
625
+
626
+ Note: option `booleanEquality` only affects `!=`.
627
+
628
+
629
+ ### Change translation of `$now`
630
+
631
+ Before V6, we translate `$now` in CDS models to `CURRENT_TIMESTAMP` when generating SQL.
632
+ This is not consistent with the behavior of the CAP runtimes, which translate `$now`
633
+ to `session_context('$now')` on HANA and corresponding constructs for other databses.
634
+
635
+ In V6, we change the mapping to do the same as the runtimes, with one exception:
636
+ as the `default` clause in HANA (other databases, too?) doesn't allow `session_context('$now')`,
637
+ we don't change the mapping of `$now` in the `default` clause and still render `CURRENT_TIMESTAMP`.
638
+
639
+ It is possible to switch back to the old behavior with option `dollarNowAsTimestamp`.
640
+
641
+
642
+ ### Switch off native HANA associations
643
+
644
+ With v5 we introduced the possibility to switch off generation of native HANA associations.
645
+ In v6, generation of native HANA associations is switched off by default.
646
+
647
+ Generation of native HANA associations can be switched on via
648
+ ```json
649
+ {
650
+ "cds": {
651
+ "sql": {
652
+ "native_hana_associations": true
653
+ }
654
+ }
655
+ }
656
+ ```
657
+
658
+ To avoid long migrations when upgrading to v6, we recommend to set HDI deploy parameter
659
+ `try_fast_table_migration`.
package/doc/Versioning.md CHANGED
@@ -54,19 +54,15 @@ we detect invalid CDS code. OData vocabularies may be updated.
54
54
 
55
55
  The compiler provides so-called “beta flags” that enable or disable certain
56
56
  features. We do not guarantee that any such flags stay consistent between
57
- patch versions! Beta flags may change any time.
58
-
59
- Refer to [CHANGELOG_BETA.md](./CHANGELOG_BETA.md) for changes to beta flags.
57
+ patch versions! Beta flags may change any time,
58
+ with or without being listed in the [CHANGELOG.md](../CHANGELOG.md).
60
59
 
61
60
  ## Deprecated Flags
62
61
 
63
62
  “Deprecated flags” allow developers to switch to old behavior and make it
64
63
  easier to upgrade to a later major version. These flags may be changed or
65
64
  removed anytime as they only serve to make upgrades easier during a grace
66
- period.
67
-
68
- Refer to [CHANGELOG_DEPRECATED.md](./CHANGELOG_DEPRECATED.md) for changes
69
- to deprecated flags.
65
+ period. For change of deprecated flags, see the [CHANGELOG.md](../CHANGELOG.md).
70
66
 
71
67
  ## Command Line Tool `cdsc`
72
68
 
package/lib/api/main.js CHANGED
@@ -173,6 +173,7 @@ function odata( csn, options, messageFunctions ) {
173
173
  function java( csn, options, messageFunctions ) {
174
174
  const internalOptions = prepareOptions.for.java(options);
175
175
  internalOptions.transformation = 'odata'; // otherwise generateDrafts adds tenant
176
+ internalOptions.odataVersion ??= 'v4';
176
177
  messageFunctions.setOptions( internalOptions );
177
178
  handleTenantDiscriminator(options, internalOptions, messageFunctions);
178
179