@sap/cds-compiler 2.12.0 → 2.13.6

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 (118) hide show
  1. package/CHANGELOG.md +110 -15
  2. package/bin/cdsc.js +13 -13
  3. package/bin/cdsse.js +2 -2
  4. package/doc/CHANGELOG_BETA.md +13 -6
  5. package/doc/CHANGELOG_DEPRECATED.md +22 -6
  6. package/doc/NameResolution.md +21 -16
  7. package/lib/api/main.js +28 -63
  8. package/lib/api/options.js +3 -3
  9. package/lib/api/validate.js +0 -5
  10. package/lib/backends.js +15 -23
  11. package/lib/base/dictionaries.js +0 -8
  12. package/lib/base/error.js +26 -0
  13. package/lib/base/keywords.js +7 -17
  14. package/lib/base/location.js +9 -4
  15. package/lib/base/message-registry.js +25 -4
  16. package/lib/base/messages.js +16 -26
  17. package/lib/base/model.js +2 -63
  18. package/lib/base/optionProcessorHelper.js +158 -123
  19. package/lib/checks/annotationsOData.js +1 -1
  20. package/lib/checks/cdsPersistence.js +2 -1
  21. package/lib/checks/enricher.js +17 -1
  22. package/lib/checks/invalidTarget.js +3 -1
  23. package/lib/checks/managedWithoutKeys.js +3 -1
  24. package/lib/checks/selectItems.js +4 -4
  25. package/lib/checks/sql-snippets.js +27 -26
  26. package/lib/checks/types.js +1 -1
  27. package/lib/checks/validator.js +4 -7
  28. package/lib/compiler/assert-consistency.js +5 -3
  29. package/lib/compiler/builtins.js +8 -6
  30. package/lib/compiler/checks.js +14 -3
  31. package/lib/compiler/cycle-detector.js +1 -1
  32. package/lib/compiler/define.js +1103 -0
  33. package/lib/compiler/extend.js +983 -0
  34. package/lib/compiler/finalize-parse-cdl.js +231 -0
  35. package/lib/compiler/index.js +32 -13
  36. package/lib/compiler/kick-start.js +190 -0
  37. package/lib/compiler/moduleLayers.js +4 -4
  38. package/lib/compiler/populate.js +1226 -0
  39. package/lib/compiler/propagator.js +111 -46
  40. package/lib/compiler/resolve.js +1433 -0
  41. package/lib/compiler/shared.js +64 -37
  42. package/lib/compiler/tweak-assocs.js +529 -0
  43. package/lib/compiler/utils.js +197 -33
  44. package/lib/edm/.eslintrc.json +5 -0
  45. package/lib/edm/annotations/genericTranslation.js +5 -9
  46. package/lib/edm/annotations/preprocessAnnotations.js +2 -2
  47. package/lib/edm/csn2edm.js +9 -8
  48. package/lib/edm/edm.js +11 -12
  49. package/lib/edm/edmPreprocessor.js +137 -73
  50. package/lib/edm/edmUtils.js +116 -22
  51. package/lib/gen/Dictionary.json +10 -3
  52. package/lib/gen/language.checksum +1 -1
  53. package/lib/gen/language.interp +9 -1
  54. package/lib/gen/language.tokens +86 -83
  55. package/lib/gen/languageLexer.interp +10 -1
  56. package/lib/gen/languageLexer.js +860 -833
  57. package/lib/gen/languageLexer.tokens +78 -75
  58. package/lib/gen/languageParser.js +5282 -4265
  59. package/lib/json/from-csn.js +12 -1
  60. package/lib/json/to-csn.js +126 -66
  61. package/lib/language/docCommentParser.js +2 -2
  62. package/lib/language/genericAntlrParser.js +76 -3
  63. package/lib/language/language.g4 +297 -130
  64. package/lib/language/multiLineStringParser.js +5 -5
  65. package/lib/main.d.ts +468 -59
  66. package/lib/main.js +35 -9
  67. package/lib/model/api.js +3 -1
  68. package/lib/model/csnRefs.js +225 -156
  69. package/lib/model/csnUtils.js +192 -223
  70. package/lib/model/enrichCsn.js +70 -29
  71. package/lib/model/revealInternalProperties.js +27 -6
  72. package/lib/model/sortViews.js +2 -1
  73. package/lib/modelCompare/compare.js +17 -12
  74. package/lib/optionProcessor.js +5 -4
  75. package/lib/render/manageConstraints.js +35 -32
  76. package/lib/render/toCdl.js +73 -288
  77. package/lib/render/toHdbcds.js +25 -23
  78. package/lib/render/toSql.js +98 -41
  79. package/lib/render/utils/common.js +5 -10
  80. package/lib/render/utils/sql.js +4 -3
  81. package/lib/render/utils/stringEscapes.js +111 -0
  82. package/lib/sql-identifier.js +1 -1
  83. package/lib/transform/.eslintrc.json +5 -0
  84. package/lib/transform/db/.eslintrc.json +2 -0
  85. package/lib/transform/db/applyTransformations.js +35 -12
  86. package/lib/transform/db/assertUnique.js +1 -1
  87. package/lib/transform/db/associations.js +103 -305
  88. package/lib/transform/db/cdsPersistence.js +2 -2
  89. package/lib/transform/db/constraints.js +55 -52
  90. package/lib/transform/db/expansion.js +46 -24
  91. package/lib/transform/db/flattening.js +553 -102
  92. package/lib/transform/db/groupByOrderBy.js +3 -1
  93. package/lib/transform/db/transformExists.js +59 -6
  94. package/lib/transform/db/views.js +5 -4
  95. package/lib/transform/draft/.eslintrc.json +38 -0
  96. package/lib/transform/{db/draft.js → draft/db.js} +6 -5
  97. package/lib/transform/draft/odata.js +227 -0
  98. package/lib/transform/forHanaNew.js +67 -183
  99. package/lib/transform/forOdataNew.js +17 -171
  100. package/lib/transform/localized.js +34 -19
  101. package/lib/transform/odata/generateForeignKeyElements.js +1 -1
  102. package/lib/transform/odata/referenceFlattener.js +95 -89
  103. package/lib/transform/odata/structureFlattener.js +1 -1
  104. package/lib/transform/odata/toFinalBaseType.js +86 -12
  105. package/lib/transform/odata/typesExposure.js +5 -5
  106. package/lib/transform/odata/utils.js +2 -2
  107. package/lib/transform/transformUtilsNew.js +36 -22
  108. package/lib/transform/translateAssocsToJoins.js +2 -19
  109. package/lib/transform/universalCsn/.eslintrc.json +36 -0
  110. package/lib/transform/universalCsn/coreComputed.js +170 -0
  111. package/lib/transform/universalCsn/universalCsnEnricher.js +715 -0
  112. package/lib/transform/universalCsn/utils.js +63 -0
  113. package/lib/utils/objectUtils.js +30 -0
  114. package/package.json +1 -1
  115. package/share/messages/README.md +26 -0
  116. package/lib/compiler/definer.js +0 -2361
  117. package/lib/compiler/resolver.js +0 -3079
  118. package/lib/transform/universalCsnEnricher.js +0 -237
@@ -20,8 +20,9 @@ const { setProp, isBetaEnabled } = require('../../base/model');
20
20
  * @param {Function} messageFunctions.error
21
21
  * @param {Function} messageFunctions.info
22
22
  * @param {Function} messageFunctions.throwWithError
23
+ * @param {object} iterateOptions
23
24
  */
24
- function expandStructureReferences(csn, options, pathDelimiter, { error, info, throwWithError }) {
25
+ function expandStructureReferences(csn, options, pathDelimiter, { error, info, throwWithError }, iterateOptions = {}) {
25
26
  const {
26
27
  isStructured, get$combined, getFinalBaseType, getServiceName,
27
28
  } = getUtils(csn);
@@ -39,7 +40,11 @@ function expandStructureReferences(csn, options, pathDelimiter, { error, info, t
39
40
  const artifact = csn.definitions[path[1]];
40
41
  if (!hasAnnotationValue(artifact, '@cds.persistence.table')) {
41
42
  const root = get$combined({ SELECT: parent });
42
- parent.columns = replaceStar(root, columns, parent.excluding);
43
+ // TODO: replace with the correct options.transformation?
44
+ // Do not expand the * in OData for a moment, not to introduce changes
45
+ // while the OData CSN is still official
46
+ if (!options.toOdata)
47
+ parent.columns = replaceStar(root, columns, parent.excluding);
43
48
  parent.columns = expand(parent.columns, path.concat('columns'), true);
44
49
  }
45
50
  },
@@ -49,7 +54,7 @@ function expandStructureReferences(csn, options, pathDelimiter, { error, info, t
49
54
  orderBy: (parent, name, orderBy, path) => {
50
55
  parent.orderBy = expand(orderBy, path.concat('orderBy'));
51
56
  },
52
- });
57
+ }, [], iterateOptions);
53
58
 
54
59
  /**
55
60
  * Turn .expand/.inline into normal refs. @cds.persistence.skip .expand with to-many (and all transitive views).
@@ -71,16 +76,25 @@ function expandStructureReferences(csn, options, pathDelimiter, { error, info, t
71
76
  if (!hasAnnotationValue(artifact, '@cds.persistence.table')) {
72
77
  const rewritten = rewrite(root, parent.columns, parent.excluding);
73
78
  parent.columns = rewritten.columns;
74
- if (rewritten.toMany.length > 0) {
79
+ /*
80
+ * Do not remove unexpandable many columns in OData
81
+ */
82
+ if (rewritten.toMany.length > 0 && !options.toOdata) {
75
83
  markAsToDummyfy(artifact, path[1]);
76
84
  if (getServiceName(path[1]) === null)
77
85
  error( null, [ 'definitions', path[1] ], { name: path[1] }, 'Unexpected .expand with to-many association in entity $(NAME), which is outside any service');
78
86
  }
87
+ else {
88
+ parent.columns = rewritten.columns;
89
+ }
79
90
  }
80
91
  },
81
92
  });
82
93
 
83
- dummyfy();
94
+ // OData must keep @cds.persistence.skip definitions
95
+ // to present them in the API (and CSN)
96
+ if (!options.toOdata)
97
+ dummyfy();
84
98
 
85
99
  cleanup.forEach(fn => fn());
86
100
 
@@ -88,23 +102,26 @@ function expandStructureReferences(csn, options, pathDelimiter, { error, info, t
88
102
 
89
103
 
90
104
  const publishing = [];
91
-
92
- applyTransformations(csn, {
93
- target: (parent, name, target, path) => {
94
- if (toDummyfy.indexOf(target) !== -1) {
95
- publishing.push({
96
- parent, name, target, path: [ ...path ],
97
- });
98
- }
99
- },
100
- from: check,
101
- columns: check,
102
- where: check,
103
- groupBy: check,
104
- orderBy: check,
105
- having: check,
106
- limit: check,
107
- });
105
+ // OData must allow navigations to @cds.persistence.skip targets
106
+ // as valid navigations in the API
107
+ if (!options.toOdata) {
108
+ applyTransformations(csn, {
109
+ target: (parent, name, target, path) => {
110
+ if (toDummyfy.indexOf(target) !== -1) {
111
+ publishing.push({
112
+ parent, name, target, path: [ ...path ],
113
+ });
114
+ }
115
+ },
116
+ from: check,
117
+ columns: check,
118
+ where: check,
119
+ groupBy: check,
120
+ orderBy: check,
121
+ having: check,
122
+ limit: check,
123
+ });
124
+ }
108
125
 
109
126
 
110
127
  /**
@@ -269,7 +286,7 @@ function expandStructureReferences(csn, options, pathDelimiter, { error, info, t
269
286
  }
270
287
 
271
288
  /**
272
- * Check wether the given object is a to-many association
289
+ * Check whether the given object is a to-many association
273
290
  *
274
291
  * @param {CSN.Element} obj
275
292
  * @returns {boolean}
@@ -301,6 +318,11 @@ function expandStructureReferences(csn, options, pathDelimiter, { error, info, t
301
318
  while (stack.length > 0) {
302
319
  const [ base, current, currentRef, currentAlias ] = stack.pop();
303
320
  if (isToMany(current) && current.expand) {
321
+ expanded.push({
322
+ expand: current.expand,
323
+ ref: currentRef,
324
+ as: currentAlias.join(pathDelimiter),
325
+ });
304
326
  toManys.push({ art: current, ref: currentRef, as: currentAlias.join(pathDelimiter) });
305
327
  }
306
328
  else if (current.expand) {
@@ -435,7 +457,7 @@ function expandStructureReferences(csn, options, pathDelimiter, { error, info, t
435
457
  *
436
458
  * @param {Array} thing
437
459
  * @param {CSN.Path} path
438
- * @param {boolean} [withAlias=false] Wether to "expand" the (implicit) alias aswell.
460
+ * @param {boolean} [withAlias=false] Whether to "expand" the (implicit) alias aswell.
439
461
  * @returns {Array} New array - with all structured things expanded
440
462
  */
441
463
  function expand(thing, path, withAlias = false) {