@sap/cds-compiler 5.6.0 → 5.7.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 (54) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/bin/cdsse.js +1 -0
  3. package/bin/cdsv2m.js +2 -1
  4. package/doc/Versioning.md +4 -4
  5. package/lib/api/options.js +1 -0
  6. package/lib/base/builtins.js +2 -2
  7. package/lib/base/dictionaries.js +1 -2
  8. package/lib/base/keywords.js +3 -1
  9. package/lib/base/lazyload.js +1 -1
  10. package/lib/base/message-registry.js +169 -144
  11. package/lib/base/messages.js +69 -59
  12. package/lib/base/model.js +3 -3
  13. package/lib/base/node-helpers.js +17 -16
  14. package/lib/base/optionProcessorHelper.js +13 -14
  15. package/lib/base/shuffle.js +4 -1
  16. package/lib/checks/structuredAnnoExpressions.js +1 -1
  17. package/lib/compiler/assert-consistency.js +1 -1
  18. package/lib/compiler/builtins.js +2 -1
  19. package/lib/compiler/extend.js +20 -5
  20. package/lib/compiler/resolve.js +45 -9
  21. package/lib/compiler/shared.js +1 -0
  22. package/lib/edm/annotations/edmJson.js +3 -3
  23. package/lib/edm/annotations/genericTranslation.js +5 -1
  24. package/lib/edm/annotations/vocabularyDefinitions.js +2 -2
  25. package/lib/edm/edmUtils.js +2 -1
  26. package/lib/gen/BaseParser.js +32 -32
  27. package/lib/gen/CdlParser.js +2237 -2196
  28. package/lib/json/from-csn.js +2 -0
  29. package/lib/json/to-csn.js +13 -4
  30. package/lib/language/docCommentParser.js +11 -5
  31. package/lib/language/errorStrategy.js +3 -3
  32. package/lib/language/genericAntlrParser.js +2 -0
  33. package/lib/model/csnUtils.js +6 -1
  34. package/lib/optionProcessor.js +5 -1
  35. package/lib/parsers/AstBuildingParser.js +151 -72
  36. package/lib/parsers/CdlGrammar.g4 +125 -83
  37. package/lib/parsers/Lexer.js +5 -3
  38. package/lib/parsers/index.js +1 -1
  39. package/lib/render/toCdl.js +6 -5
  40. package/lib/render/toHdbcds.js +1 -1
  41. package/lib/render/toSql.js +5 -3
  42. package/lib/render/utils/common.js +19 -6
  43. package/lib/render/utils/standardDatabaseFunctions.js +576 -0
  44. package/lib/transform/addTenantFields.js +2 -1
  45. package/lib/transform/db/flattening.js +18 -77
  46. package/lib/transform/db/groupByOrderBy.js +2 -2
  47. package/lib/transform/db/rewriteCalculatedElements.js +14 -19
  48. package/lib/transform/db/temporal.js +2 -1
  49. package/lib/transform/odata/adaptAnnotationRefs.js +79 -0
  50. package/lib/transform/odata/createForeignKeys.js +4 -71
  51. package/lib/transform/odata/flattening.js +11 -1
  52. package/lib/transform/transformUtils.js +20 -85
  53. package/package.json +2 -1
  54. package/bin/cds_update_annotations.js +0 -180
package/CHANGELOG.md CHANGED
@@ -7,6 +7,37 @@
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
+ ## Version 5.7.0 - 2025-01-24
11
+
12
+ ### Added
13
+
14
+ - Analyze enum symbols like `#ENUM_SYMB`; support starts at the following places:
15
+ + used as sole `default` value or `select` column expression
16
+ if the element/column has a specified enum type, or
17
+ + used as sole value (in parentheses) of an annotation assignment
18
+ if there is a definition for that annotation having an enum type;
19
+ + effects in compiler: complain if enum symbol is undefined
20
+ + effects in the IDE with an upcoming version of cds-lsp when compiler option `newParser` is set:
21
+ offer code completion and hover information,
22
+ + effects in backends like `to.sql` (and potentially runtimes): enum symbol
23
+ is replaced by corresponding string/integer value when appropriate.
24
+ - for.seal: Process foreign key annotations similar to to.edm(x)
25
+
26
+ ### Changed
27
+
28
+ - CDL parser: it is now recommended to set the option `newParser` to make the compiler
29
+ use a CDL parser with a significantly smaller footprint (among other things).
30
+ New features might only work if this option is set, see above.
31
+
32
+ ### Fixed
33
+
34
+ - CDL parser: doc comment parser was susceptible to ReDos
35
+ - to.sql/hdi: Paths inside calculated elements that are simple functions were not properly rewritten.
36
+ - for.odata: Re-add foreign keys in property `targetAspect` in the OData CSN.
37
+ - to.edm(x): In annotation translation, by default map `SemanticObjectMappingAbstract` to `SemanticObjectMappingType` to avoid regreessions.
38
+ - to.cdl: Fix quoting of identifier `many` in `Composition of`/`Association to`
39
+ - for.seal: Allow annotation paths to end in `many`-elements, not just scalar, liek we allow in for.odata
40
+
10
41
  ## Version 5.6.0 - 2024-12-12
11
42
 
12
43
  ### Added
package/bin/cdsse.js CHANGED
@@ -188,6 +188,7 @@ function offset( buf, alsoSuffix ) { // for line and column
188
188
  return false;
189
189
  }
190
190
  let cursor = pos + column - 1;
191
+ // eslint-disable-next-line sonarjs/slow-regex
191
192
  const prefix = /[a-z_0-9$]*$/i.exec( buf.substring( pos, cursor ) ).index + pos;
192
193
  const col = column + prefix - cursor;
193
194
  if (alsoSuffix)
package/bin/cdsv2m.js CHANGED
@@ -37,7 +37,8 @@ function ria() {
37
37
  // 'Choose via $(ANNO) one of $(SORTED_ARTS) as redirection target for $(TARGET) in … $(ART) otherwise'
38
38
  // NOTE: regex match on message text not for productive code!
39
39
  for (const msgObj of msgs) {
40
- const matches = msgObj.message.match( /["“][^"”]+["”]/g );
40
+ // eslint-disable-next-line sonarjs/slow-regex
41
+ const matches = msgObj.message.match( /["“][^"”]+["”]/ug );
41
42
  matches.slice( 1, -2 ).forEach( (name) => {
42
43
  annotates[name.slice( 1, -1 )] = true;
43
44
  } );
package/doc/Versioning.md CHANGED
@@ -19,9 +19,9 @@ expect from version updates.
19
19
  ## Public API
20
20
 
21
21
  According to [§1] of SemVer, a public API must be made available. Our public
22
- API is available through `lib/main.js` which can be used by
23
- `const compiler = require('@sap/cds-compiler');` in NodeJS or, if you use
24
- ES modules, with `import compiler from "@sap/cds-compiler";`
22
+ API is available through `lib/main.js` which can be used via
23
+ `const compiler = require('@sap/cds-compiler');` in Node.js or, if you use
24
+ ES modules, via `import compiler from "@sap/cds-compiler";`
25
25
 
26
26
  Furthermore, any exported property in `lib/main.js` whose name starts with `$`
27
27
  is _not_ part of the public API.
@@ -48,7 +48,7 @@ only later upgraded to errors.
48
48
  “patch versions” can be applied.
49
49
 
50
50
  We may introduce new compiler-checks that might make your compilation fail if
51
- we detect invalid CDS code.
51
+ we detect invalid CDS code. OData vocabularies may be updated.
52
52
 
53
53
  ## Beta Flags
54
54
 
@@ -32,6 +32,7 @@ const publicOptionsNewAPI = [
32
32
  'betterSqliteSessionVariables',
33
33
  'fewerLocalizedViews',
34
34
  'withHanaAssociations',
35
+ 'standardDatabaseFunctions',
35
36
  // ODATA
36
37
  'odataOpenapiHints',
37
38
  'edm4OpenAPI',
@@ -29,7 +29,7 @@ const propagationRules = {
29
29
  '@sql.append': 'never',
30
30
  '@sql.prepend': 'never',
31
31
  '@sql.replace': 'never',
32
- }
32
+ };
33
33
 
34
34
  /**
35
35
  * Checks whether the given absolute path is inside a reserved namespace.
@@ -105,4 +105,4 @@ module.exports = {
105
105
  isBuiltinType,
106
106
  isMagicVariable,
107
107
  isAnnotationExpression,
108
- }
108
+ };
@@ -84,9 +84,8 @@ function dictAddArray( dict, name, entry, messageCallback ) {
84
84
  function dictFirst( dict ) {
85
85
  if (!dict)
86
86
  return dict;
87
- for (const name in dict) {
87
+ for (const name in dict)
88
88
  return dict[name];
89
- }
90
89
  return undefined;
91
90
  }
92
91
 
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ /* eslint @stylistic/js/no-multi-spaces: 0 */
4
+
3
5
  const { functionsWithoutParentheses, cdlKeywords } = require('../parsers/identifiers');
4
6
 
5
7
  module.exports = {
@@ -713,7 +715,7 @@ module.exports = {
713
715
  'SYSTIME', 'SYSTIMESTAMP', 'SYSUUID',
714
716
  'TOP', 'TRAILING', 'UNION',
715
717
  'USING', 'VALUES', 'WHEN',
716
- 'WHERE', 'WHILE', 'WITH'
718
+ 'WHERE', 'WHILE', 'WITH',
717
719
  ],
718
720
  // Postgres keywords, used for smart quoting in to-sql.plain.postgres
719
721
  // Taken from https://www.postgresql.org/docs/current/sql-keywords-appendix.html
@@ -22,7 +22,7 @@ function createLazyload( callingModule ) {
22
22
  return module[name];
23
23
  },
24
24
  });
25
- }
25
+ };
26
26
  }
27
27
 
28
28
  module.exports = createLazyload;