@sap/cds-compiler 4.5.0 → 4.6.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 (65) hide show
  1. package/CHANGELOG.md +50 -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/populate.js +5 -1
  18. package/lib/compiler/resolve.js +26 -21
  19. package/lib/compiler/shared.js +19 -9
  20. package/lib/compiler/tweak-assocs.js +82 -107
  21. package/lib/compiler/utils.js +2 -1
  22. package/lib/edm/annotations/edmJson.js +23 -22
  23. package/lib/edm/annotations/genericTranslation.js +14 -4
  24. package/lib/edm/csn2edm.js +24 -10
  25. package/lib/edm/edmInboundChecks.js +1 -2
  26. package/lib/edm/edmPreprocessor.js +11 -9
  27. package/lib/edm/edmUtils.js +5 -2
  28. package/lib/gen/Dictionary.json +3 -1
  29. package/lib/gen/language.checksum +1 -1
  30. package/lib/gen/language.interp +4 -1
  31. package/lib/gen/language.tokens +1 -0
  32. package/lib/gen/languageParser.js +5253 -5214
  33. package/lib/json/to-csn.js +7 -1
  34. package/lib/language/antlrParser.js +19 -1
  35. package/lib/language/errorStrategy.js +21 -4
  36. package/lib/language/genericAntlrParser.js +9 -11
  37. package/lib/main.d.ts +28 -3
  38. package/lib/main.js +3 -0
  39. package/lib/model/csnRefs.js +4 -1
  40. package/lib/model/csnUtils.js +12 -7
  41. package/lib/optionProcessor.js +21 -19
  42. package/lib/render/manageConstraints.js +13 -29
  43. package/lib/render/toCdl.js +18 -15
  44. package/lib/render/toHdbcds.js +59 -28
  45. package/lib/render/toRename.js +6 -10
  46. package/lib/render/toSql.js +57 -82
  47. package/lib/render/utils/common.js +17 -0
  48. package/lib/transform/.eslintrc.json +9 -1
  49. package/lib/transform/addTenantFields.js +228 -0
  50. package/lib/transform/db/applyTransformations.js +27 -31
  51. package/lib/transform/db/assertUnique.js +4 -4
  52. package/lib/transform/db/cdsPersistence.js +1 -1
  53. package/lib/transform/db/flattening.js +68 -69
  54. package/lib/transform/db/temporal.js +1 -1
  55. package/lib/transform/draft/db.js +2 -16
  56. package/lib/transform/draft/odata.js +3 -3
  57. package/lib/transform/effective/associations.js +3 -5
  58. package/lib/transform/effective/main.js +6 -9
  59. package/lib/transform/forOdata.js +13 -9
  60. package/lib/transform/forRelationalDB.js +36 -17
  61. package/lib/transform/odata/toFinalBaseType.js +3 -3
  62. package/lib/transform/odata/typesExposure.js +14 -5
  63. package/lib/transform/transformUtils.js +47 -34
  64. package/lib/transform/translateAssocsToJoins.js +33 -8
  65. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -7,13 +7,55 @@
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.2 - 2024-02-02
12
+
13
+ ### Fixed
14
+
15
+ - compiler: Fix incorrect error about type properties if deprecated flag `ignoreSpecifiedQueryElements` is set.
16
+ - Update OData vocabularies: 'Authorization', 'Common'.
17
+
18
+ ## Version 4.6.0 - 2024-01-26
19
+
20
+ ### Added
21
+
22
+ - compiler: Events can now be projections on other structured events and types.
23
+ - to.cdl: `parseCdl` and `gensrc` style CSN (a.k.a. `inferred` and `xtended`) is now supported as input.
24
+
25
+ ### Changed
26
+
27
+ - Update OData vocabularies: 'Aggregation', 'Validation'
28
+ - to.sql/hdi/hdbcds: Removed warnings for number and type of keys in draft-enabled entities.
29
+
30
+ ### Fixed
31
+
32
+ - compiler:
33
+ + ON-conditions of associations with filters in calculated elements were incorrectly rewritten when included
34
+ in other entities, and the filter was applied twice in some scenarios.
35
+ + redirecting an association with filter did not rewrite paths relative to the redirection target.
36
+ + Unknown type references with an explicit named type argument such as `Unknown(length: 10)` crashed.
37
+ - to.edm(x):
38
+ + `@Core.IsURL` is not rendered in combination with `@Core.MediaType` (V4 only).
39
+ + No 'odata-navigation' warning for association targets annotated with `@cds.autoexpose: false`.
40
+ + No empty annotation in API, when a non-existent base annotation is annotated
41
+ (eg. `@Common.Label.@Core.Description` without `@Common.Label`).
42
+ + Don't crash if value for `$Type` is not a string.
43
+ + Generated foreign keys of type `cds.UUID` that are also primary key are not annotated with
44
+ `@Core.ComputedDefaultValue`. This is a follow up correction to [4.5.0](#version-450---2023-12-08)
45
+
46
+
10
47
  ## Version 4.5.0 - 2023-12-08
11
48
 
12
49
  ### Added
13
50
 
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.
51
+ - compiler/parser
52
+ + Annotations can have any expressions as value, like `@Anno: ( ref + 1 )`.
53
+ References are checked to be valid element references,
54
+ inherited values might become invalid due to element renaming.
55
+ This feature is still experimental, and
56
+ might not be supported by all backends or runtimes at the moment.
57
+ + A single `annotate` statement can now be used to annotate parameters, elements and
58
+ bound actions in one statement.
17
59
  - to.edm(x): Key elements of type `cds.UUID` are annotated with `@Core.ComputedDefaultValue` if they are
18
60
  defined directly in the entity. Elements of type `cds.UUID` that are defined in a named structured type
19
61
  and used to define a key element are not annotated, instead a warning is raised if such elements are
@@ -30,13 +72,13 @@ The compiler behavior concerning `beta` features can change at any time without
30
72
  ### Fixed
31
73
 
32
74
  - 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)
75
+ + Fix false positives of cyclic dependencies for calculated elements.
76
+ + Fix cardinality on source associations when publishing them with a filter (+ different cardinality)
35
77
  in a projection. The cardinality was incorrectly changed on the source as well.
36
78
  - CDL parser:
37
- - More numbers that would lose relevant digits due to precision loss are
79
+ + More numbers that would lose relevant digits due to precision loss are
38
80
  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)
81
+ + Nested table expressions and queries in the FROM clause (with surrounding parentheses)
40
82
  could cause some constructs such as `virtual` to be not properly parsed.
41
83
  - to.hdi.migration: Don't drop-create the primary key when only a doc-comment has changed.
42
84
  - to.cdl: Fix edge case where `@A.![B#]` was not rendered correctly.
@@ -349,6 +391,7 @@ The compiler behavior concerning `beta` features can change at any time without
349
391
  we avoid unexpected name resolution effects in combination with built-in `$`-variables.
350
392
  + A semicolon is now required after a type definition like `type T : many {} null`.
351
393
  + Message ID `duplicate-autoexposed` was changed to `def-duplicate-autoexposed`.
394
+ + Bare `$projection` are rejected. Use `$self` instead.
352
395
  - Update OData vocabularies 'Common', 'UI'.
353
396
  - to.sql:
354
397
  + 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`