@sap/cds-compiler 3.1.2 → 3.4.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 (117) hide show
  1. package/CHANGELOG.md +101 -3
  2. package/bin/cdsc.js +4 -2
  3. package/doc/CHANGELOG_BETA.md +35 -0
  4. package/lib/api/main.js +153 -29
  5. package/lib/api/validate.js +8 -3
  6. package/lib/base/dictionaries.js +6 -6
  7. package/lib/base/error.js +2 -2
  8. package/lib/base/keywords.js +106 -24
  9. package/lib/base/message-registry.js +177 -79
  10. package/lib/base/messages.js +78 -57
  11. package/lib/base/model.js +2 -1
  12. package/lib/checks/actionsFunctions.js +1 -1
  13. package/lib/checks/annotationsOData.js +2 -2
  14. package/lib/checks/arrayOfs.js +15 -7
  15. package/lib/checks/cdsPersistence.js +1 -1
  16. package/lib/checks/checkForTypes.js +53 -0
  17. package/lib/checks/defaultValues.js +4 -2
  18. package/lib/checks/elements.js +81 -6
  19. package/lib/checks/foreignKeys.js +12 -13
  20. package/lib/checks/invalidTarget.js +10 -11
  21. package/lib/checks/managedInType.js +21 -15
  22. package/lib/checks/nullableKeys.js +1 -1
  23. package/lib/checks/onConditions.js +9 -9
  24. package/lib/checks/parameters.js +23 -0
  25. package/lib/checks/queryNoDbArtifacts.js +1 -1
  26. package/lib/checks/selectItems.js +1 -1
  27. package/lib/checks/sql-snippets.js +12 -10
  28. package/lib/checks/types.js +2 -2
  29. package/lib/checks/utils.js +17 -7
  30. package/lib/checks/validator.js +36 -14
  31. package/lib/compiler/assert-consistency.js +21 -13
  32. package/lib/compiler/builtins.js +8 -0
  33. package/lib/compiler/checks.js +57 -40
  34. package/lib/compiler/define.js +139 -69
  35. package/lib/compiler/extend.js +319 -50
  36. package/lib/compiler/finalize-parse-cdl.js +14 -9
  37. package/lib/compiler/kick-start.js +2 -35
  38. package/lib/compiler/populate.js +111 -68
  39. package/lib/compiler/propagator.js +5 -3
  40. package/lib/compiler/resolve.js +71 -108
  41. package/lib/compiler/shared.js +82 -54
  42. package/lib/compiler/tweak-assocs.js +26 -14
  43. package/lib/compiler/utils.js +13 -2
  44. package/lib/edm/annotations/genericTranslation.js +10 -7
  45. package/lib/edm/csn2edm.js +11 -11
  46. package/lib/edm/edm.js +17 -9
  47. package/lib/edm/edmPreprocessor.js +53 -30
  48. package/lib/edm/edmUtils.js +7 -2
  49. package/lib/gen/Dictionary.json +14 -0
  50. package/lib/gen/language.checksum +1 -1
  51. package/lib/gen/language.interp +3 -2
  52. package/lib/gen/languageParser.js +4312 -4186
  53. package/lib/inspect/inspectModelStatistics.js +1 -1
  54. package/lib/inspect/inspectPropagation.js +23 -9
  55. package/lib/json/csnVersion.js +13 -13
  56. package/lib/json/from-csn.js +161 -172
  57. package/lib/json/to-csn.js +70 -10
  58. package/lib/language/.eslintrc.json +4 -0
  59. package/lib/language/antlrParser.js +8 -11
  60. package/lib/language/docCommentParser.js +1 -2
  61. package/lib/language/errorStrategy.js +54 -27
  62. package/lib/language/genericAntlrParser.js +140 -93
  63. package/lib/language/language.g4 +57 -33
  64. package/lib/language/multiLineStringParser.js +75 -63
  65. package/lib/main.d.ts +3 -6
  66. package/lib/main.js +1 -0
  67. package/lib/model/.eslintrc.json +13 -0
  68. package/lib/model/api.js +4 -2
  69. package/lib/model/csnRefs.js +78 -50
  70. package/lib/model/csnUtils.js +272 -222
  71. package/lib/model/enrichCsn.js +41 -31
  72. package/lib/model/revealInternalProperties.js +61 -57
  73. package/lib/model/sortViews.js +35 -31
  74. package/lib/modelCompare/compare.js +52 -18
  75. package/lib/modelCompare/filter.js +83 -0
  76. package/lib/optionProcessor.js +10 -1
  77. package/lib/render/manageConstraints.js +11 -7
  78. package/lib/render/toCdl.js +151 -106
  79. package/lib/render/toHdbcds.js +8 -6
  80. package/lib/render/toRename.js +4 -4
  81. package/lib/render/toSql.js +17 -7
  82. package/lib/render/utils/common.js +27 -9
  83. package/lib/render/utils/sql.js +5 -5
  84. package/lib/sql-identifier.js +7 -0
  85. package/lib/transform/db/applyTransformations.js +32 -3
  86. package/lib/transform/db/assertUnique.js +27 -38
  87. package/lib/transform/db/expansion.js +92 -41
  88. package/lib/transform/db/flattening.js +1 -1
  89. package/lib/transform/db/temporal.js +3 -1
  90. package/lib/transform/db/transformExists.js +8 -2
  91. package/lib/transform/db/views.js +42 -13
  92. package/lib/transform/draft/db.js +2 -2
  93. package/lib/transform/forOdataNew.js +10 -7
  94. package/lib/transform/{forHanaNew.js → forRelationalDB.js} +18 -12
  95. package/lib/transform/localized.js +29 -20
  96. package/lib/transform/odata/toFinalBaseType.js +8 -11
  97. package/lib/transform/odata/typesExposure.js +2 -1
  98. package/lib/transform/parseExpr.js +245 -0
  99. package/lib/transform/transformUtilsNew.js +122 -51
  100. package/lib/transform/translateAssocsToJoins.js +17 -16
  101. package/lib/utils/moduleResolve.js +5 -5
  102. package/lib/utils/objectUtils.js +3 -3
  103. package/lib/utils/term.js +5 -5
  104. package/package.json +2 -2
  105. package/share/messages/anno-duplicate-unrelated-layer.md +6 -6
  106. package/share/messages/check-proper-type-of.md +4 -4
  107. package/share/messages/check-proper-type.md +2 -2
  108. package/share/messages/duplicate-autoexposed.md +4 -4
  109. package/share/messages/extend-repeated-intralayer.md +4 -5
  110. package/share/messages/extend-unrelated-layer.md +4 -4
  111. package/share/messages/message-explanations.json +3 -1
  112. package/share/messages/redirected-to-ambiguous.md +7 -6
  113. package/share/messages/redirected-to-complex.md +63 -0
  114. package/share/messages/redirected-to-unrelated.md +6 -5
  115. package/share/messages/rewrite-not-supported.md +4 -4
  116. package/share/messages/{syntax-expected-integer.md → syntax-expecting-integer.md} +4 -4
  117. package/share/messages/wildcard-excluding-one.md +37 -0
@@ -14,7 +14,7 @@ function inspectModelStatistics(xsn, options) {
14
14
  let result = '';
15
15
 
16
16
  // Default color mode is 'auto'
17
- const color = term(options.color || 'auto');
17
+ const color = term(options.color !== undefined ? options.color : 'auto');
18
18
 
19
19
  const defCount = countDefinitionKinds(xsn);
20
20
  const sources = {
@@ -16,7 +16,7 @@ function inspectPropagation(xsn, options, artifactName) {
16
16
  const result = [];
17
17
 
18
18
  // Default color mode is 'auto'
19
- const color = term(options.color || 'auto');
19
+ const color = term(options.color !== undefined ? options.color : 'auto');
20
20
 
21
21
  const path = stringRefToPath(artifactName);
22
22
  if (!path) {
@@ -121,19 +121,28 @@ function _inspectElements(artifactXsn) {
121
121
  const result = [];
122
122
  const elements = Object.keys(artifactXsn.elements);
123
123
 
124
- let maxElemLength = 12;
125
-
126
124
  const inferredNiceOutput = {
127
125
  '*': 'wildcard',
128
- 'expand-element': 'expanded',
129
- 'expand-param': 'expanded',
130
126
  'aspect-composition': 'composition',
131
127
  };
132
128
 
129
+ let maxElemLength = 12;
130
+ let maxOriginLength = 6;
131
+
132
+ // type: assume max length 11 of 'composition'
133
+ // element: assume average length of 30, chosen randomly
134
+ result.push([
135
+ 'type'.padStart(11),
136
+ 'element'.padEnd(maxElemLength),
137
+ 'origin'.padEnd(maxOriginLength),
138
+ 'location (definition)',
139
+ ].join(' | '));
140
+
133
141
  for (const element of elements) {
134
142
  const elementXsn = artifactXsn.elements[element];
135
143
  const loc = locationString(_origin(elementXsn).name.location);
136
144
  let origin;
145
+ const originName = elementXsn._origin?.name?.absolute || '';
137
146
 
138
147
  if (elementXsn.$inferred) {
139
148
  // Use nice(r) output for known $inferred
@@ -151,11 +160,16 @@ function _inspectElements(artifactXsn) {
151
160
  }
152
161
 
153
162
  maxElemLength = Math.max(maxElemLength, element.length);
154
-
155
- // origin: assume max length 11 of 'composition'
156
- // element: assume average length of 30, chosen randomly
157
- result.push([ origin.padStart(11), element.padEnd(maxElemLength), loc ].join(' | '));
163
+ maxOriginLength = Math.max(maxOriginLength, originName.length);
164
+
165
+ result.push([
166
+ origin.padStart(11),
167
+ element.padEnd(maxElemLength),
168
+ originName.padEnd(maxOriginLength),
169
+ loc,
170
+ ].join(' | '));
158
171
  }
172
+
159
173
  return result;
160
174
  }
161
175
 
@@ -1,5 +1,6 @@
1
- // csn version functions
1
+ 'use strict';
2
2
 
3
+ // csn version functions
3
4
 
4
5
  // The CSN file format version produced by this compiler
5
6
  // (Note that all 0.x.x versions are floating targets, i.e. the format is frequently
@@ -18,15 +19,12 @@
18
19
  // Use literal version constants intentionally and not number intervals to
19
20
  // record all published version strings of the core compiler.
20
21
  const newCSNVersions = [ '0.1.99', '0.2', '0.2.0', '1.0', '2.0' ];
21
- // checks if new-csn is requested via the options of already specified in the CSN
22
- // default: old-style
22
+
23
+ // Check if new-style CSN is requested, i.e. versions >= 0.1.99
23
24
  function isNewCSN(csn, options) {
24
- if ( (options && options.newCsn === false) ||
25
+ return !( options?.newCsn === false ||
25
26
  (csn.version && !newCSNVersions.includes(csn.version.csn)) ||
26
- (csn.$version && !newCSNVersions.includes(csn.$version)))
27
- return false;
28
-
29
- return true;
27
+ (csn.$version && !newCSNVersions.includes(csn.$version)));
30
28
  }
31
29
 
32
30
  function checkCSNVersion(csn, options) {
@@ -35,11 +33,13 @@ function checkCSNVersion(csn, options) {
35
33
  const { makeMessageFunction } = require('../base/messages');
36
34
  const { error, throwWithAnyError } = makeMessageFunction(csn, options);
37
35
 
38
- let errStr = 'CSN Version not supported, version tag: "';
39
- errStr += `${ csn.version && csn.version.csn ? csn.version.csn : (csn.$version ? csn.$version : 'not available') }"`;
40
- errStr += (options.newCsn !== undefined) ? `, options.newCsn: ${ options.newCsn }` : '';
41
-
42
- error(null, null, errStr);
36
+ const version = csn.version?.csn ? csn.version.csn : (csn.$version || 'unknown');
37
+ const variant = options.newCsn !== undefined ? 'newCsn' : 'std';
38
+ error('api-unsupported-csn-version', null,
39
+ { '#': variant, version, code: options.newCsn }, {
40
+ std: 'CSN version $(VERSION) not supported',
41
+ newCsn: 'CSN version $(VERSION) not supported; options.newCsn: $(CODE)',
42
+ });
43
43
  throwWithAnyError();
44
44
  }
45
45
  }