@sap/cds-compiler 4.1.2 → 4.2.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 (74) hide show
  1. package/CHANGELOG.md +101 -1
  2. package/bin/cdsc.js +6 -3
  3. package/doc/CHANGELOG_BETA.md +5 -0
  4. package/doc/CHANGELOG_DEPRECATED.md +15 -0
  5. package/lib/api/main.js +2 -2
  6. package/lib/api/options.js +2 -2
  7. package/lib/api/validate.js +24 -24
  8. package/lib/base/message-registry.js +41 -6
  9. package/lib/base/messages.js +7 -0
  10. package/lib/base/model.js +37 -8
  11. package/lib/checks/elements.js +11 -10
  12. package/lib/checks/manyNavigations.js +33 -0
  13. package/lib/checks/onConditions.js +5 -2
  14. package/lib/checks/queryNoDbArtifacts.js +2 -3
  15. package/lib/checks/selectItems.js +4 -55
  16. package/lib/checks/utils.js +3 -2
  17. package/lib/checks/validator.js +3 -1
  18. package/lib/compiler/.eslintrc.json +2 -1
  19. package/lib/compiler/assert-consistency.js +27 -24
  20. package/lib/compiler/base.js +6 -2
  21. package/lib/compiler/builtins.js +34 -34
  22. package/lib/compiler/checks.js +179 -208
  23. package/lib/compiler/classes.js +2 -2
  24. package/lib/compiler/cycle-detector.js +6 -6
  25. package/lib/compiler/define.js +66 -45
  26. package/lib/compiler/extend.js +81 -72
  27. package/lib/compiler/finalize-parse-cdl.js +26 -26
  28. package/lib/compiler/generate.js +61 -45
  29. package/lib/compiler/index.js +47 -49
  30. package/lib/compiler/kick-start.js +8 -7
  31. package/lib/compiler/moduleLayers.js +1 -1
  32. package/lib/compiler/populate.js +42 -35
  33. package/lib/compiler/propagator.js +6 -6
  34. package/lib/compiler/resolve.js +170 -126
  35. package/lib/compiler/shared.js +122 -45
  36. package/lib/compiler/tweak-assocs.js +93 -40
  37. package/lib/compiler/utils.js +15 -12
  38. package/lib/edm/.eslintrc.json +40 -1
  39. package/lib/edm/annotations/genericTranslation.js +721 -707
  40. package/lib/edm/annotations/preprocessAnnotations.js +88 -77
  41. package/lib/edm/csn2edm.js +389 -378
  42. package/lib/edm/edm.js +678 -772
  43. package/lib/edm/edmAnnoPreprocessor.js +132 -146
  44. package/lib/edm/edmInboundChecks.js +29 -27
  45. package/lib/edm/edmPreprocessor.js +686 -646
  46. package/lib/edm/edmUtils.js +277 -296
  47. package/lib/gen/language.checksum +1 -1
  48. package/lib/gen/language.interp +1 -1
  49. package/lib/gen/languageParser.js +1253 -1276
  50. package/lib/json/from-csn.js +34 -4
  51. package/lib/json/to-csn.js +4 -4
  52. package/lib/language/language.g4 +2 -5
  53. package/lib/main.d.ts +61 -1
  54. package/lib/model/csnUtils.js +31 -2
  55. package/lib/model/revealInternalProperties.js +1 -1
  56. package/lib/modelCompare/compare.js +37 -2
  57. package/lib/modelCompare/utils/filter.js +1 -1
  58. package/lib/optionProcessor.js +15 -3
  59. package/lib/render/toCdl.js +30 -4
  60. package/lib/render/toSql.js +5 -9
  61. package/lib/render/utils/common.js +8 -6
  62. package/lib/transform/db/applyTransformations.js +1 -1
  63. package/lib/transform/db/cdsPersistence.js +1 -1
  64. package/lib/transform/db/constraints.js +47 -17
  65. package/lib/transform/db/expansion.js +121 -47
  66. package/lib/transform/db/flattening.js +75 -7
  67. package/lib/transform/forOdata.js +4 -1
  68. package/lib/transform/forRelationalDB.js +80 -62
  69. package/lib/transform/localized.js +91 -54
  70. package/lib/transform/transformUtils.js +9 -10
  71. package/lib/utils/file.js +7 -7
  72. package/lib/utils/moduleResolve.js +210 -121
  73. package/lib/utils/objectUtils.js +1 -1
  74. package/package.json +5 -5
@@ -14,7 +14,7 @@ const { dictAdd, pushToDict, dictFirst } = require('../base/dictionaries');
14
14
  const { kindProperties } = require('./base');
15
15
  const { XsnName, XsnArtifact, CsnLocation } = require('./classes');
16
16
 
17
- const $inferred = Symbol.for('cds.$inferred');
17
+ const $inferred = Symbol.for( 'cds.$inferred' );
18
18
 
19
19
  // for links, i.e., properties starting with an underscore '_':
20
20
 
@@ -109,7 +109,7 @@ function linkToOrigin( origin, name, parent, prop, location, silentDep ) {
109
109
  return elem;
110
110
  }
111
111
 
112
- function proxyCopyMembers( art, dictProp, originDict, location, kind ) {
112
+ function proxyCopyMembers( art, dictProp, originDict, location, kind, tmpDeprecated ) {
113
113
  art[dictProp] = Object.create( null );
114
114
  // TODO: set $inferred ? for dict?
115
115
  for (const name in originDict) {
@@ -118,8 +118,11 @@ function proxyCopyMembers( art, dictProp, originDict, location, kind ) {
118
118
  const member = linkToOrigin( origin, name, art, dictProp,
119
119
  location || origin.location, true );
120
120
  member.$inferred = 'expanded';
121
+ // TODO throughout the compiler: do not set art.‹prop›.$inferred if art.$inferred
121
122
  if (kind)
122
123
  member.kind = kind;
124
+ else if (origin.key && !tmpDeprecated) // TODO(v5/v6): remove tmpDeprecated
125
+ member.key = Object.assign( { $inferred: 'expanded' }, origin.key );
123
126
  if (kind && origin.masked) // TODO: remove!
124
127
  member.masked = Object.assign( { $inferred: 'nav' }, origin.masked );
125
128
  }
@@ -139,7 +142,7 @@ function setMemberParent( elem, name, parent, prop ) {
139
142
  // TODO: consider nested ARRAY OF and RETURNS, COMPOSITION OF type
140
143
  const p = parent.items || parent.targetAspect || parent;
141
144
  if (p[prop] === undefined)
142
- p[prop] = Object.create(null);
145
+ p[prop] = Object.create( null );
143
146
  dictAdd( p[prop], name, elem );
144
147
  }
145
148
  if (parent._outer && parent._outer.items) // TODO: remove for items, too
@@ -161,7 +164,7 @@ function setMemberParent( elem, name, parent, prop ) {
161
164
 
162
165
  else
163
166
  delete elem.name[kind];
164
- });
167
+ } );
165
168
  // try { throw new CompilerAssertion('Foo') } catch (e) { elem.name.stack = e; };
166
169
  }
167
170
 
@@ -207,7 +210,7 @@ function storeExtension( elem, name, prop, parent, block ) {
207
210
  // return;
208
211
  // }
209
212
  if (!parent[kind][prop])
210
- parent[kind][prop] = Object.create(null);
213
+ parent[kind][prop] = Object.create( null );
211
214
  pushToDict( parent[kind][prop], name, elem );
212
215
  }
213
216
 
@@ -233,7 +236,7 @@ function withAssociation( ref, test = testFunctionPlaceholder, alsoTestLast = fa
233
236
  * @param {XSN.Path} path
234
237
  */
235
238
  function pathName( path ) {
236
- return (path && !path.broken) ? path.map( id => id.id ).join('.') : '';
239
+ return (path && !path.broken) ? path.map( id => id.id ).join( '.' ) : '';
237
240
  }
238
241
 
239
242
  /**
@@ -245,7 +248,7 @@ function pathName( path ) {
245
248
  * @returns {XSN.Path}
246
249
  */
247
250
  function splitIntoPath( location, name ) {
248
- return name.split('.').map( id => ({ id, location }) );
251
+ return name.split( '.' ).map( id => ({ id, location }) );
249
252
  }
250
253
 
251
254
  /**
@@ -259,7 +262,7 @@ function augmentPath( location, ...args ) {
259
262
  function copyExpr( expr, location, skipUnderscored, rewritePath ) {
260
263
  if (!expr || typeof expr !== 'object')
261
264
  return expr;
262
- else if (Array.isArray(expr))
265
+ else if (Array.isArray( expr ))
263
266
  return expr.map( e => copyExpr( e, location, skipUnderscored, rewritePath ) );
264
267
 
265
268
  const proto = Object.getPrototypeOf( expr );
@@ -296,7 +299,7 @@ function testExpr( expr, pathTest, queryTest, user ) {
296
299
  if (!expr || typeof expr === 'string') { // parse error or keywords in {xpr:...}
297
300
  return false;
298
301
  }
299
- else if (Array.isArray(expr)) {
302
+ else if (Array.isArray( expr )) {
300
303
  return expr.some( e => testExpr( e, pathTest, queryTest, user ) );
301
304
  }
302
305
  else if (expr.path) {
@@ -307,10 +310,10 @@ function testExpr( expr, pathTest, queryTest, user ) {
307
310
  }
308
311
  else if (expr.op && expr.args) {
309
312
  // unnamed args => array
310
- if (Array.isArray(expr.args))
313
+ if (Array.isArray( expr.args ))
311
314
  return expr.args.some( e => testExpr( e, pathTest, queryTest, user ) );
312
315
  // named args => dictionary
313
- for (const namedArg of Object.keys(expr.args)) {
316
+ for (const namedArg of Object.keys( expr.args )) {
314
317
  if (testExpr( expr.args[namedArg], pathTest, queryTest, user ))
315
318
  return true;
316
319
  }
@@ -403,7 +406,7 @@ function forEachUserDict( art, prop, callback ) {
403
406
  if (obj.$inferred)
404
407
  continue;
405
408
  callback( obj, name, prop );
406
- if (Array.isArray(obj.$duplicates)) // redefinitions
409
+ if (Array.isArray( obj.$duplicates )) // redefinitions
407
410
  obj.$duplicates.forEach( o => callback( o, name, prop ) );
408
411
  }
409
412
  }
@@ -1,5 +1,44 @@
1
1
  {
2
+ "root": true,
3
+ //"plugins": ["sonarjs", "jsdoc"],
4
+ //"extends": ["plugin:jsdoc/recommended", "../../../.eslintrc-ydkjsi.json", "plugin:sonarjs/recommended"],
5
+ "plugins": ["sonarjs"],
6
+ "extends": ["../../.eslintrc-ydkjsi.json", "plugin:sonarjs/recommended"],
2
7
  "rules": {
3
- "no-shadow": "off"
8
+ "prefer-const": "error",
9
+ "quotes": ["error", "single", "avoid-escape"],
10
+ "prefer-template": "error",
11
+ "no-trailing-spaces": "error",
12
+ "template-curly-spacing":["error", "never"],
13
+ "complexity": ["warn", 50],
14
+ "max-len": "off",
15
+ // there seem to be false positives
16
+ "jsdoc/require-returns-check": "off",
17
+ // Don't enforce stupid descriptions
18
+ "jsdoc/require-param-description": "off",
19
+ "jsdoc/require-returns-description": "off",
20
+ // Sometimes if-else's are more specific
21
+ "sonarjs/prefer-single-boolean-return": "off",
22
+ // Very whiny and nitpicky
23
+ "sonarjs/cognitive-complexity": "off",
24
+ "sonarjs/no-duplicate-string": "off",
25
+ // Does not recognize TS types
26
+ "jsdoc/no-undefined-types": "off",
27
+ "jsdoc/tag-lines": "off",
28
+ "no-nested-ternary": "off",
29
+ "sonarjs/no-nested-template-literals": "off"
30
+ },
31
+ "parserOptions": {
32
+ "ecmaVersion": 2022,
33
+ "sourceType": "script"
34
+ },
35
+ "env": {
36
+ "es2022": true,
37
+ "node": true
38
+ },
39
+ "settings": {
40
+ "jsdoc": {
41
+ "mode": "typescript"
42
+ }
4
43
  }
5
44
  }