@sap/cds-compiler 2.7.0 → 2.11.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 (87) hide show
  1. package/CHANGELOG.md +167 -0
  2. package/bin/cdsc.js +42 -25
  3. package/bin/cdsse.js +1 -0
  4. package/doc/CHANGELOG_BETA.md +10 -0
  5. package/lib/api/.eslintrc.json +2 -0
  6. package/lib/api/main.js +17 -33
  7. package/lib/api/options.js +25 -13
  8. package/lib/api/validate.js +33 -9
  9. package/lib/backends.js +9 -8
  10. package/lib/base/dictionaries.js +2 -1
  11. package/lib/base/keywords.js +32 -2
  12. package/lib/base/message-registry.js +26 -2
  13. package/lib/base/messages.js +25 -9
  14. package/lib/base/model.js +5 -3
  15. package/lib/base/optionProcessorHelper.js +56 -22
  16. package/lib/checks/onConditions.js +5 -0
  17. package/lib/checks/selectItems.js +4 -0
  18. package/lib/checks/types.js +26 -2
  19. package/lib/checks/unknownMagic.js +41 -0
  20. package/lib/checks/validator.js +7 -2
  21. package/lib/compiler/assert-consistency.js +18 -5
  22. package/lib/compiler/base.js +65 -0
  23. package/lib/compiler/builtins.js +30 -1
  24. package/lib/compiler/checks.js +5 -2
  25. package/lib/compiler/definer.js +145 -120
  26. package/lib/compiler/index.js +16 -4
  27. package/lib/compiler/propagator.js +5 -2
  28. package/lib/compiler/resolver.js +207 -47
  29. package/lib/compiler/shared.js +47 -200
  30. package/lib/compiler/utils.js +173 -0
  31. package/lib/edm/annotations/genericTranslation.js +183 -187
  32. package/lib/edm/csn2edm.js +94 -98
  33. package/lib/edm/edm.js +16 -20
  34. package/lib/edm/edmPreprocessor.js +302 -115
  35. package/lib/edm/edmUtils.js +31 -12
  36. package/lib/gen/language.checksum +1 -1
  37. package/lib/gen/language.interp +28 -1
  38. package/lib/gen/language.tokens +79 -69
  39. package/lib/gen/languageLexer.interp +28 -1
  40. package/lib/gen/languageLexer.js +879 -805
  41. package/lib/gen/languageLexer.tokens +71 -62
  42. package/lib/gen/languageParser.js +5308 -4308
  43. package/lib/json/from-csn.js +59 -30
  44. package/lib/json/to-csn.js +354 -105
  45. package/lib/language/antlrParser.js +11 -0
  46. package/lib/language/errorStrategy.js +1 -0
  47. package/lib/language/genericAntlrParser.js +81 -14
  48. package/lib/language/language.g4 +163 -31
  49. package/lib/main.d.ts +136 -17
  50. package/lib/main.js +7 -1
  51. package/lib/model/api.js +78 -0
  52. package/lib/model/csnRefs.js +115 -32
  53. package/lib/model/csnUtils.js +71 -33
  54. package/lib/model/enrichCsn.js +36 -9
  55. package/lib/model/revealInternalProperties.js +20 -4
  56. package/lib/modelCompare/compare.js +2 -1
  57. package/lib/optionProcessor.js +33 -16
  58. package/lib/render/.eslintrc.json +3 -1
  59. package/lib/render/DuplicateChecker.js +1 -1
  60. package/lib/render/toCdl.js +60 -17
  61. package/lib/render/toHdbcds.js +122 -74
  62. package/lib/render/toSql.js +57 -32
  63. package/lib/render/utils/common.js +6 -10
  64. package/lib/sql-identifier.js +6 -1
  65. package/lib/transform/db/constraints.js +273 -119
  66. package/lib/transform/db/draft.js +9 -6
  67. package/lib/transform/db/expansion.js +19 -7
  68. package/lib/transform/db/flattening.js +31 -7
  69. package/lib/transform/db/transformExists.js +344 -66
  70. package/lib/transform/db/views.js +438 -0
  71. package/lib/transform/forHanaNew.js +65 -436
  72. package/lib/transform/forOdataNew.js +21 -10
  73. package/lib/transform/localized.js +2 -0
  74. package/lib/transform/odata/attachPath.js +19 -4
  75. package/lib/transform/odata/generateForeignKeyElements.js +11 -10
  76. package/lib/transform/odata/referenceFlattener.js +44 -38
  77. package/lib/transform/odata/sortByAssociationDependency.js +2 -2
  78. package/lib/transform/odata/structuralPath.js +72 -0
  79. package/lib/transform/odata/structureFlattener.js +13 -10
  80. package/lib/transform/odata/typesExposure.js +22 -12
  81. package/lib/transform/transformUtilsNew.js +55 -9
  82. package/lib/transform/translateAssocsToJoins.js +11 -17
  83. package/lib/transform/universalCsnEnricher.js +67 -0
  84. package/lib/utils/file.js +5 -3
  85. package/lib/utils/term.js +65 -42
  86. package/lib/utils/timetrace.js +48 -26
  87. package/package.json +1 -1
@@ -446,11 +446,15 @@ function expandStructureReferences(csn, options, pathDelimiter, { error, info, t
446
446
  if (col.ref && col.$scope !== '$magic') {
447
447
  const _art = col._art || inspectRef(path.concat(i)).art;
448
448
  if (_art && isStructured(_art))
449
- newThing.push(...expandRef(_art, col.ref, [ col.as || col.ref[col.ref.length - 1] ], col.key || false, withAlias));
449
+ newThing.push(...expandRef(_art, col.ref, col.as, col.key || false, withAlias));
450
450
 
451
451
  else
452
452
  newThing.push(col);
453
453
  }
454
+ else if (col.ref && col.$scope === '$magic' && ( col.ref[0] === '$user' || col.ref[0] === '$session' ) && !col.as) {
455
+ col.as = implicitAs(col.ref);
456
+ newThing.push(col);
457
+ }
454
458
  else {
455
459
  newThing.push(col);
456
460
  }
@@ -473,7 +477,7 @@ function expandStructureReferences(csn, options, pathDelimiter, { error, info, t
473
477
  */
474
478
  function expandRef(art, ref, alias, isKey, withAlias) {
475
479
  const expanded = [];
476
- const stack = [ [ art, ref, alias ] ];
480
+ const stack = [ [ art, ref, [ alias || ref[ref.length - 1] ] ] ];
477
481
  while (stack.length > 0) {
478
482
  const [ current, currentRef, currentAlias ] = stack.pop();
479
483
  if (isStructured(current)) {
@@ -482,8 +486,14 @@ function expandStructureReferences(csn, options, pathDelimiter, { error, info, t
482
486
  }
483
487
  else {
484
488
  const obj = { ref: currentRef };
485
- if (withAlias)
486
- obj.as = currentAlias.join(pathDelimiter);
489
+ if (withAlias) {
490
+ const newAlias = currentAlias.join(pathDelimiter);
491
+ // if (alias !== undefined) // explicit alias
492
+ obj.as = newAlias;
493
+ // alias was implicit - to later distinguish expanded s -> s.a from explicitly written s.a
494
+ if (alias === undefined)
495
+ setProp(obj, '$implicitAlias', true);
496
+ }
487
497
  if (isKey)
488
498
  obj.key = true;
489
499
  expanded.push(obj);
@@ -542,9 +552,11 @@ function expandStructureReferences(csn, options, pathDelimiter, { error, info, t
542
552
  for (const part of Object.keys(base)) {
543
553
  if (excluding.indexOf(part) === -1) {
544
554
  // The thing is shadowed - ignore names present because of .inline, as those "disappear"
545
- if (names[part] && !subs[names[part]].inline) {
546
- replaced[part] = true;
547
- star.push(subs[names[part]]);
555
+ if (names[part] !== undefined && !subs[names[part]].inline) { // Only works for a single * - but a second is forbidden anyway
556
+ if (names[part] > stars[0]) { // explicit definitions BEFORE the star should stay "infront" of the star
557
+ replaced[part] = true;
558
+ star.push(subs[names[part]]);
559
+ }
548
560
  }
549
561
  else { // the thing is not shadowed - use the name from the base
550
562
  star.push({ ref: [ part ] });
@@ -69,12 +69,32 @@ function resolveTypeReferences(csn, options, resolved, pathDelimiter) {
69
69
  }
70
70
  }
71
71
  const { toFinalBaseType } = transformUtils.getTransformers(csn, options, pathDelimiter);
72
- // (030) - For all elements, replace derived types by final base type
73
72
  applyTransformations(csn, {
73
+ cast: (parent) => {
74
+ // Resolve cast already - we otherwise lose .localized
75
+ if (parent.cast.type && !isBuiltinType(parent.cast.type))
76
+ toFinalBaseType(parent.cast, resolved, true);
77
+ },
74
78
  type: (parent, prop, type) => {
75
79
  if (!isBuiltinType(type)) {
76
80
  const directLocalized = parent.localized || false;
77
81
  toFinalBaseType(parent, resolved);
82
+ // structured types might not have the child-types replaced.
83
+ // Drill down to ensure this.
84
+ if (parent.elements) {
85
+ const stack = [ parent.elements ];
86
+ while (stack.length > 0) {
87
+ const elements = stack.pop();
88
+ for (const e of Object.values(elements)) {
89
+ if (e.type && !isBuiltinType(e.type))
90
+ toFinalBaseType(e, resolved);
91
+
92
+ if (e.elements)
93
+ stack.push(e.elements);
94
+ }
95
+ }
96
+ }
97
+
78
98
  if (!directLocalized)
79
99
  removeLocalized(parent);
80
100
  }
@@ -99,7 +119,7 @@ function resolveTypeReferences(csn, options, resolved, pathDelimiter) {
99
119
 
100
120
  definitions[artifactName] = dummy;
101
121
  }
102
- } ]);
122
+ } ], true, { skipDict: { actions: true } });
103
123
  }
104
124
 
105
125
  /**
@@ -143,13 +163,17 @@ function flattenAllStructStepsInRefs(csn, options, resolved, pathDelimiter) {
143
163
 
144
164
  parent.ref = flattenStructStepsInRef(ref, scopedPath, links, scope, resolvedLinkTypes );
145
165
  resolved.set(parent, { links, art, scope });
146
- // Because of expansion we added alias to everything - strip off superflous alias
147
- if (parent.as && parent.as === parent.ref[parent.ref.length - 1] && scope !== '$magic')
148
- delete parent.as;
149
166
  // Explicitly set implicit alias for things that are now flattened - but only in columns
150
167
  // TODO: Can this be done elegantly during expand phase already?
151
- else if (parent.ref[ref.length - 1] !== lastRef && (insideColumns(scopedPath) || insideKeys(scopedPath)) && !parent.as)
168
+ if (parent.$implicitAlias) { // an expanded s -> s.a is marked with this - do not add implicit alias "a" there, we want s_a
169
+ if (parent.ref[parent.ref.length - 1] === parent.as) // for a simple s that was expanded - for s.substructure this would not apply
170
+ delete parent.as;
171
+ delete parent.$implicitAlias;
172
+ }
173
+ // To handle explicitly written s.a - add implicit alias a, since after flattening it would otherwise be s_a
174
+ else if (parent.ref[parent.ref.length - 1] !== lastRef && (insideColumns(scopedPath) || insideKeys(scopedPath)) && !parent.as) {
152
175
  parent.as = lastRef;
176
+ }
153
177
  };
154
178
  // adapt queries later
155
179
  adaptRefs.push(fn);
@@ -263,7 +287,7 @@ function flattenElements(csn, options, pathDelimiter, error) {
263
287
  previous[name] = element;
264
288
  return previous;
265
289
  }, Object.create(null));
266
- });
290
+ }, true);
267
291
  }
268
292
 
269
293
  /**