@sap/cds-compiler 4.5.0 → 4.6.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 (64) hide show
  1. package/CHANGELOG.md +43 -7
  2. package/bin/cdsc.js +13 -11
  3. package/doc/CHANGELOG_BETA.md +6 -0
  4. package/lib/api/main.js +256 -115
  5. package/lib/api/options.js +8 -0
  6. package/lib/base/message-registry.js +17 -4
  7. package/lib/base/messages.js +15 -3
  8. package/lib/base/model.js +1 -0
  9. package/lib/base/optionProcessorHelper.js +45 -176
  10. package/lib/checks/elements.js +32 -34
  11. package/lib/checks/enricher.js +39 -3
  12. package/lib/checks/validator.js +2 -3
  13. package/lib/compiler/assert-consistency.js +2 -1
  14. package/lib/compiler/builtins.js +20 -4
  15. package/lib/compiler/checks.js +30 -6
  16. package/lib/compiler/define.js +31 -9
  17. package/lib/compiler/resolve.js +26 -21
  18. package/lib/compiler/shared.js +19 -9
  19. package/lib/compiler/tweak-assocs.js +82 -107
  20. package/lib/compiler/utils.js +2 -1
  21. package/lib/edm/annotations/edmJson.js +23 -22
  22. package/lib/edm/annotations/genericTranslation.js +14 -4
  23. package/lib/edm/csn2edm.js +24 -10
  24. package/lib/edm/edmInboundChecks.js +1 -2
  25. package/lib/edm/edmPreprocessor.js +11 -9
  26. package/lib/edm/edmUtils.js +5 -2
  27. package/lib/gen/Dictionary.json +2 -0
  28. package/lib/gen/language.checksum +1 -1
  29. package/lib/gen/language.interp +4 -1
  30. package/lib/gen/language.tokens +1 -0
  31. package/lib/gen/languageParser.js +5253 -5214
  32. package/lib/json/to-csn.js +7 -1
  33. package/lib/language/antlrParser.js +19 -1
  34. package/lib/language/errorStrategy.js +21 -4
  35. package/lib/language/genericAntlrParser.js +9 -11
  36. package/lib/main.d.ts +28 -3
  37. package/lib/main.js +3 -0
  38. package/lib/model/csnRefs.js +4 -1
  39. package/lib/model/csnUtils.js +12 -7
  40. package/lib/optionProcessor.js +21 -19
  41. package/lib/render/manageConstraints.js +13 -29
  42. package/lib/render/toCdl.js +18 -15
  43. package/lib/render/toHdbcds.js +59 -28
  44. package/lib/render/toRename.js +6 -10
  45. package/lib/render/toSql.js +57 -82
  46. package/lib/render/utils/common.js +17 -0
  47. package/lib/transform/.eslintrc.json +9 -1
  48. package/lib/transform/addTenantFields.js +228 -0
  49. package/lib/transform/db/applyTransformations.js +27 -31
  50. package/lib/transform/db/assertUnique.js +4 -4
  51. package/lib/transform/db/cdsPersistence.js +1 -1
  52. package/lib/transform/db/flattening.js +68 -69
  53. package/lib/transform/db/temporal.js +1 -1
  54. package/lib/transform/draft/db.js +2 -16
  55. package/lib/transform/draft/odata.js +3 -3
  56. package/lib/transform/effective/associations.js +3 -5
  57. package/lib/transform/effective/main.js +6 -9
  58. package/lib/transform/forOdata.js +13 -9
  59. package/lib/transform/forRelationalDB.js +36 -17
  60. package/lib/transform/odata/toFinalBaseType.js +3 -3
  61. package/lib/transform/odata/typesExposure.js +14 -5
  62. package/lib/transform/transformUtils.js +47 -34
  63. package/lib/transform/translateAssocsToJoins.js +33 -8
  64. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -7,13 +7,48 @@
7
7
  Note: `beta` fixes, changes and features are usually not listed in this ChangeLog but [here](doc/CHANGELOG_BETA.md).
8
8
  The compiler behavior concerning `beta` features can change at any time without notice.
9
9
 
10
+
11
+ ## Version 4.6.0 - 2024-01-26
12
+
13
+ ### Added
14
+
15
+ - compiler: Events can now be projections on other structured events and types.
16
+ - to.cdl: `parseCdl` and `gensrc` style CSN (a.k.a. `inferred` and `xtended`) is now supported as input.
17
+
18
+ ### Changed
19
+
20
+ - Update OData vocabularies: 'Aggregation', 'Validation'
21
+ - to.sql/hdi/hdbcds: Removed warnings for number and type of keys in draft-enabled entities.
22
+
23
+ ### Fixed
24
+
25
+ - compiler:
26
+ + ON-conditions of associations with filters in calculated elements were incorrectly rewritten when included
27
+ in other entities, and the filter was applied twice in some scenarios.
28
+ + redirecting an association with filter did not rewrite paths relative to the redirection target.
29
+ + Unknown type references with an explicit named type argument such as `Unknown(length: 10)` crashed.
30
+ - to.edm(x):
31
+ + `@Core.IsURL` is not rendered in combination with `@Core.MediaType` (V4 only).
32
+ + No 'odata-navigation' warning for association targets annotated with `@cds.autoexpose: false`.
33
+ + No empty annotation in API, when a non-existent base annotation is annotated
34
+ (eg. `@Common.Label.@Core.Description` without `@Common.Label`).
35
+ + Don't crash if value for `$Type` is not a string.
36
+ + Generated foreign keys of type `cds.UUID` that are also primary key are not annotated with
37
+ `@Core.ComputedDefaultValue`. This is a follow up correction to [4.5.0](#version-450---2023-12-08)
38
+
39
+
10
40
  ## Version 4.5.0 - 2023-12-08
11
41
 
12
42
  ### Added
13
43
 
14
- - parser: `annotate` can now annotate entity parameters, elements and bound actions in one statement.
15
- - compiler: A single `annotate` statement can now be used to annotate parameters, elements and
16
- bound actions in one statement.
44
+ - compiler/parser
45
+ + Annotations can have any expressions as value, like `@Anno: ( ref + 1 )`.
46
+ References are checked to be valid element references,
47
+ inherited values might become invalid due to element renaming.
48
+ This feature is still experimental, and
49
+ might not be supported by all backends or runtimes at the moment.
50
+ + A single `annotate` statement can now be used to annotate parameters, elements and
51
+ bound actions in one statement.
17
52
  - to.edm(x): Key elements of type `cds.UUID` are annotated with `@Core.ComputedDefaultValue` if they are
18
53
  defined directly in the entity. Elements of type `cds.UUID` that are defined in a named structured type
19
54
  and used to define a key element are not annotated, instead a warning is raised if such elements are
@@ -30,13 +65,13 @@ The compiler behavior concerning `beta` features can change at any time without
30
65
  ### Fixed
31
66
 
32
67
  - compiler:
33
- - Fix false positives of cyclic dependencies for calculated elements.
34
- - Fix cardinality on source associations when publishing them with a filter (+ different cardinality)
68
+ + Fix false positives of cyclic dependencies for calculated elements.
69
+ + Fix cardinality on source associations when publishing them with a filter (+ different cardinality)
35
70
  in a projection. The cardinality was incorrectly changed on the source as well.
36
71
  - CDL parser:
37
- - More numbers that would lose relevant digits due to precision loss are
72
+ + More numbers that would lose relevant digits due to precision loss are
38
73
  stored as strings in CSN (i.e. `{ "literal":"number", "val": "1.0000000000000001" }`).
39
- - Nested table expressions and queries in the FROM clause (with surrounding parentheses)
74
+ + Nested table expressions and queries in the FROM clause (with surrounding parentheses)
40
75
  could cause some constructs such as `virtual` to be not properly parsed.
41
76
  - to.hdi.migration: Don't drop-create the primary key when only a doc-comment has changed.
42
77
  - to.cdl: Fix edge case where `@A.![B#]` was not rendered correctly.
@@ -349,6 +384,7 @@ The compiler behavior concerning `beta` features can change at any time without
349
384
  we avoid unexpected name resolution effects in combination with built-in `$`-variables.
350
385
  + A semicolon is now required after a type definition like `type T : many {} null`.
351
386
  + Message ID `duplicate-autoexposed` was changed to `def-duplicate-autoexposed`.
387
+ + Bare `$projection` are rejected. Use `$self` instead.
352
388
  - Update OData vocabularies 'Common', 'UI'.
353
389
  - to.sql:
354
390
  + Change default `length` for `cds.String` for all SQL dialects except `hana` to 255.
package/bin/cdsc.js CHANGED
@@ -27,10 +27,12 @@ const { reveal } = require('../lib/model/revealInternalProperties');
27
27
  const enrichCsn = require('../lib/model/enrichCsn');
28
28
  const { optionProcessor } = require('../lib/optionProcessor');
29
29
  const {
30
- explainMessage, hasMessageExplanation, sortMessages, messageIdsWithExplanation,
30
+ explainMessage, hasMessageExplanation, sortMessages,
31
+ messageIdsWithExplanation, makeMessageFunction,
31
32
  } = require('../lib/base/messages');
32
33
  const { term } = require('../lib/utils/term');
33
34
  const { addLocalizationViews } = require('../lib/transform/localized');
35
+ const { addTenantFields } = require('../lib/transform/addTenantFields');
34
36
  const { availableBetaFlags } = require('../lib/base/model');
35
37
  const { alterConstraintsWithCsn } = require('../lib/render/manageConstraints');
36
38
 
@@ -63,17 +65,13 @@ function remapCmdOptions( options, command ) {
63
65
  for (const [ key, value ] of Object.entries(options[command])) {
64
66
  switch (key) {
65
67
  case 'user':
66
- if (!options.variableReplacements)
67
- options.variableReplacements = {};
68
- if (!options.variableReplacements.$user)
69
- options.variableReplacements.$user = {};
68
+ options.variableReplacements ??= {};
69
+ options.variableReplacements.$user ??= {};
70
70
  options.variableReplacements.$user.id = value;
71
71
  break;
72
72
  case 'locale':
73
- if (!options.variableReplacements)
74
- options.variableReplacements = {};
75
- if (!options.variableReplacements.$user)
76
- options.variableReplacements.$user = {};
73
+ options.variableReplacements ??= {};
74
+ options.variableReplacements.$user ??= {};
77
75
  options.variableReplacements.$user.locale = value;
78
76
  break;
79
77
  case 'serviceNames':
@@ -391,7 +389,8 @@ function executeCommandLine( command, options, args ) {
391
389
  // / DO NOT DELETE THIS TORENAME FUNCTIONALITY!!
392
390
  function toRename( model ) {
393
391
  const csn = options.directBackend ? model : compactModel(model, options);
394
- const renameResult = _toRename(csn, options);
392
+ const messageFunctions = makeMessageFunction(csn, options, 'to.rename');
393
+ const renameResult = _toRename(csn, options, messageFunctions);
395
394
  let storedProcedure = `PROCEDURE RENAME_${renameResult.options.sqlMapping.toUpperCase()}_TO_PLAIN LANGUAGE SQLSCRIPT AS BEGIN\n`;
396
395
  for (const name in renameResult.rename) {
397
396
  storedProcedure += ` --\n -- ${name}\n --\n`;
@@ -406,7 +405,8 @@ function executeCommandLine( command, options, args ) {
406
405
  function manageConstraints( model ) {
407
406
  const csn = options.directBackend ? model : compactModel(model, options);
408
407
  const { src } = options || {};
409
- const alterConstraintsResult = alterConstraintsWithCsn(csn, options);
408
+ const messageFunctions = makeMessageFunction(csn, options, 'alterConstraints');
409
+ const alterConstraintsResult = alterConstraintsWithCsn(csn, options, messageFunctions);
410
410
  Object.keys(alterConstraintsResult).forEach((id) => {
411
411
  const renderedConstraintStatement = alterConstraintsResult[id];
412
412
  if (src === 'hdi')
@@ -559,6 +559,8 @@ function executeCommandLine( command, options, args ) {
559
559
  }
560
560
  else if (!options.parseOnly) { // no output if parseOnly but not rawOutput
561
561
  const csn = compactModel(xsn, options);
562
+ if (command === 'toCsn' && options.tenantAsColumn)
563
+ addTenantFields(csn, options);
562
564
  if (command === 'toCsn' && options.withLocalized)
563
565
  addLocalizationViews(csn, options);
564
566
  if (options.enrichCsn)
@@ -8,6 +8,12 @@ Note: `beta` fixes, changes and features are listed in this ChangeLog just for i
8
8
  The compiler behavior concerning `beta` features can change at any time without notice.
9
9
  **Don't use `beta` fixes, changes and features in productive mode.**
10
10
 
11
+ ## Version 4.6.0 - 2024-01-26
12
+
13
+ ### Added `vectorType`
14
+
15
+ Using this beta flag, the new type `cds.Vector` is available for modeling.
16
+
11
17
  ## Version 4.5.0 - 2023-12-08
12
18
 
13
19
  ### Added `odataAnnotationExpressions`