@sap/cds-compiler 5.9.4 → 6.0.12

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 (114) hide show
  1. package/CHANGELOG.md +117 -319
  2. package/README.md +1 -1
  3. package/bin/cds_update_identifiers.js +3 -5
  4. package/bin/cdsc.js +24 -9
  5. package/bin/cdshi.js +1 -1
  6. package/bin/cdsse.js +4 -4
  7. package/doc/CHANGELOG_BETA.md +11 -0
  8. package/doc/CHANGELOG_DEPRECATED.md +29 -0
  9. package/lib/api/main.js +8 -5
  10. package/lib/api/options.js +12 -10
  11. package/lib/base/builtins.js +1 -0
  12. package/lib/base/message-registry.js +191 -99
  13. package/lib/base/messages.js +35 -21
  14. package/lib/base/model.js +14 -24
  15. package/lib/checks/actionsFunctions.js +10 -20
  16. package/lib/checks/annotationsOData.js +1 -1
  17. package/lib/checks/elements.js +35 -10
  18. package/lib/checks/enums.js +31 -0
  19. package/lib/checks/foreignKeys.js +2 -2
  20. package/lib/checks/hasPersistedElements.js +5 -0
  21. package/lib/checks/invalidTarget.js +1 -1
  22. package/lib/checks/managedWithoutKeys.js +5 -4
  23. package/lib/checks/queryNoDbArtifacts.js +10 -8
  24. package/lib/checks/types.js +5 -5
  25. package/lib/checks/validator.js +6 -4
  26. package/lib/compiler/assert-consistency.js +13 -9
  27. package/lib/compiler/checks.js +20 -52
  28. package/lib/compiler/define.js +31 -6
  29. package/lib/compiler/extend.js +5 -1
  30. package/lib/compiler/generate.js +14 -17
  31. package/lib/compiler/populate.js +8 -31
  32. package/lib/compiler/propagator.js +21 -35
  33. package/lib/compiler/resolve.js +64 -29
  34. package/lib/compiler/shared.js +16 -4
  35. package/lib/compiler/tweak-assocs.js +1 -1
  36. package/lib/compiler/utils.js +1 -1
  37. package/lib/edm/annotations/edmJson.js +23 -20
  38. package/lib/edm/annotations/genericTranslation.js +12 -10
  39. package/lib/edm/csn2edm.js +50 -56
  40. package/lib/edm/edm.js +33 -28
  41. package/lib/edm/edmInboundChecks.js +2 -2
  42. package/lib/edm/edmPreprocessor.js +54 -88
  43. package/lib/edm/edmUtils.js +9 -12
  44. package/lib/gen/BaseParser.js +63 -52
  45. package/lib/gen/CdlGrammar.checksum +1 -1
  46. package/lib/gen/CdlParser.js +1153 -1165
  47. package/lib/gen/Dictionary.json +21 -1
  48. package/lib/json/from-csn.js +70 -43
  49. package/lib/json/to-csn.js +6 -8
  50. package/lib/language/multiLineStringParser.js +3 -2
  51. package/lib/main.d.ts +58 -24
  52. package/lib/model/cloneCsn.js +3 -0
  53. package/lib/model/csnUtils.js +28 -39
  54. package/lib/model/xprAsTree.js +23 -9
  55. package/lib/modelCompare/compare.js +5 -4
  56. package/lib/optionProcessor.js +24 -17
  57. package/lib/parsers/AstBuildingParser.js +81 -25
  58. package/lib/parsers/XprTree.js +57 -3
  59. package/lib/parsers/identifiers.js +1 -1
  60. package/lib/parsers/index.js +0 -3
  61. package/lib/render/manageConstraints.js +25 -25
  62. package/lib/render/toCdl.js +173 -170
  63. package/lib/render/toHdbcds.js +126 -128
  64. package/lib/render/toRename.js +7 -7
  65. package/lib/render/toSql.js +128 -125
  66. package/lib/render/utils/common.js +47 -22
  67. package/lib/render/utils/delta.js +25 -25
  68. package/lib/render/utils/operators.js +2 -2
  69. package/lib/render/utils/pretty.js +5 -5
  70. package/lib/render/utils/sql.js +13 -13
  71. package/lib/render/utils/standardDatabaseFunctions.js +115 -103
  72. package/lib/render/utils/unique.js +4 -4
  73. package/lib/transform/db/applyTransformations.js +1 -1
  74. package/lib/transform/db/assertUnique.js +2 -2
  75. package/lib/transform/db/associations.js +6 -7
  76. package/lib/transform/db/assocsToQueries/utils.js +4 -5
  77. package/lib/transform/db/backlinks.js +12 -9
  78. package/lib/transform/db/cdsPersistence.js +8 -7
  79. package/lib/transform/db/constraints.js +13 -10
  80. package/lib/transform/db/expansion.js +7 -3
  81. package/lib/transform/db/flattening.js +4 -14
  82. package/lib/transform/db/processSqlServices.js +2 -1
  83. package/lib/transform/db/temporal.js +5 -7
  84. package/lib/transform/db/views.js +2 -4
  85. package/lib/transform/draft/db.js +8 -8
  86. package/lib/transform/draft/odata.js +10 -7
  87. package/lib/transform/forOdata.js +10 -5
  88. package/lib/transform/forRelationalDB.js +5 -75
  89. package/lib/transform/localized.js +1 -1
  90. package/lib/transform/odata/createForeignKeys.js +11 -10
  91. package/lib/transform/odata/flattening.js +8 -4
  92. package/lib/transform/odata/foreignKeyRefsInXprAnnos.js +96 -0
  93. package/lib/transform/odata/typesExposure.js +3 -3
  94. package/lib/transform/transformUtils.js +4 -8
  95. package/lib/transform/translateAssocsToJoins.js +14 -7
  96. package/lib/transform/universalCsn/universalCsnEnricher.js +10 -4
  97. package/lib/utils/objectUtils.js +0 -17
  98. package/package.json +10 -13
  99. package/share/messages/def-upcoming-virtual-change.md +1 -1
  100. package/LICENSE +0 -37
  101. package/bin/cds_remove_invalid_whitespace.js +0 -138
  102. package/doc/CHANGELOG_ARCHIVE.md +0 -3604
  103. package/lib/gen/genericAntlrParser.js +0 -3
  104. package/lib/gen/language.checksum +0 -1
  105. package/lib/gen/language.interp +0 -456
  106. package/lib/gen/language.tokens +0 -180
  107. package/lib/gen/languageLexer.interp +0 -439
  108. package/lib/gen/languageLexer.js +0 -1483
  109. package/lib/gen/languageLexer.tokens +0 -167
  110. package/lib/gen/languageParser.js +0 -24941
  111. package/lib/language/antlrParser.js +0 -205
  112. package/lib/language/errorStrategy.js +0 -646
  113. package/lib/language/genericAntlrParser.js +0 -1572
  114. package/lib/parsers/CdlGrammar.g4 +0 -2070
@@ -35,22 +35,49 @@
35
35
 
36
36
  'use strict';
37
37
 
38
- const { CompilerAssertion } = require('./error');
39
- const { createDict } = require('../utils/objectUtils');
38
+ const { CompilerAssertion } = require( './error' );
39
+ const { isDeprecatedEnabled } = require( './model' );
40
+
41
+ const configurableForValidValues = {
42
+ __proto__: null,
43
+ // can always be downgraded, we do not really care:
44
+ true: () => true,
45
+ // like `true`, but is intended to be removed or made 'deprecated' with v7:
46
+ v7: () => true,
47
+ // only configurable if option deprecated.downgradableErrors is set:
48
+ deprecated: options => isDeprecatedEnabled( options, 'downgradableErrors' ),
49
+ // still allow to produce output in tests:
50
+ test: options => options.testMode != null,
51
+ };
40
52
 
53
+ const validModules = [ // for configurableFor and errorFor
54
+ 'v7', // pseudo module in errorFor: planned as error
55
+ 'compile',
56
+ 'for.odata',
57
+ 'to.edmx',
58
+ 'to.hdbcds',
59
+ 'to.hdi',
60
+ 'to.sql',
61
+ 'to.sql.migration',
62
+ 'to.sql.migration-script',
63
+ 'to.rename',
64
+ 'for.effective',
65
+ ];
41
66
  /**
42
67
  * Central register of messages and their configuration.
43
68
  * Group by id-category.
44
69
  *
45
- * configurableFor: truthy = error can be downgraded in certain situations
46
- * - true = can always be downgraded, we do not really care
47
- * - 'v4', 'v6' etc: like `true`, but is intended to be removed with next major
48
- * - [‹module›, …] = can be downgraded in compiler function ‹module›
49
- * - 'deprecated' = severity can only be changed with deprecated.downgradableErrors
70
+ * Message with severity 'Error' can have a configurableFor property. Its value
71
+ * is either array of modules (see validModules) where the error can be
72
+ * downgraded, or a value in configurableForValidValues.
73
+ *
74
+ * Messages with another severity can have an errorFor property. Its value is an
75
+ * array of modules (see validModules) where the message is turned into an error.
50
76
  *
51
77
  * @type {Object<string, MessageConfig>}
52
78
  */
53
79
  const centralMessages = {
80
+ 'api-deprecated-hdbcds': { severity: 'Error', configurableFor: true },
54
81
  'anno-definition': { severity: 'Warning' },
55
82
  'anno-duplicate': { severity: 'Error', configurableFor: true }, // does not hurt us
56
83
  'anno-duplicate-unrelated-layer': { severity: 'Error', configurableFor: true }, // does not hurt us
@@ -76,12 +103,9 @@ const centralMessages = {
76
103
 
77
104
  'type-invalid-items': { severity: 'Error' }, // not supported yet
78
105
  'assoc-as-type': { severity: 'Error' }, // TODO: allow more, but not all
79
- // the following is not really an error in v6, but gets a different semantics:
80
- 'assoc-incomplete-to-many': { severity: 'Warning', errorFor: [ 'v6' ] },
81
- 'def-unexpected-nested-proj': { severity: 'Error', configurableFor: 'v4' },
106
+ 'def-unexpected-nested-proj': { severity: 'Error' },
82
107
  'def-unexpected-paramview-assoc': { severity: 'Error' },
83
108
  'def-unexpected-calcview-assoc': { severity: 'Error' },
84
- 'chained-array-of': { severity: 'Error' },
85
109
  'def-missing-type': { severity: 'Error', configurableFor: [ 'compile' ] },
86
110
  'def-missing-argument': { severity: 'Error' },
87
111
  'check-proper-type-of': { severity: 'Info', errorFor: [ 'for.odata', 'to.edmx', 'to.hdbcds', 'to.sql', 'to.hdi', 'to.rename', 'for.effective' ] },
@@ -100,7 +124,7 @@ const centralMessages = {
100
124
  'ref-unexpected-self': { severity: 'Error' },
101
125
  'ref-invalid-include': { severity: 'Error' },
102
126
  'type-unexpected-typeof': { severity: 'Error' },
103
- 'type-unexpected-null': { severity: 'Warning', errorFor: [ 'v6' ] },
127
+ 'type-unexpected-null': { severity: 'Error', configurableFor: true },
104
128
  'type-ignoring-argument': { severity: 'Error', configurableFor: true },
105
129
  'type-expected-builtin': { severity: 'Error', configurableFor: true },
106
130
  'type-expecting-service-target': { severity: 'Error', configurableFor: true },
@@ -109,7 +133,7 @@ const centralMessages = {
109
133
  'ref-invalid-source': { severity: 'Error' },
110
134
  'ref-invalid-target': { severity: 'Error' },
111
135
  'ref-missing-self-counterpart': { severity: 'Error', configurableFor: true },
112
- 'ref-sloppy-target': { severity: 'Error', configurableFor: 'v4' },
136
+ 'ref-sloppy-target': { severity: 'Error', configurableFor: 'deprecated' },
113
137
 
114
138
  'extend-repeated-intralayer': { severity: 'Warning' },
115
139
  'extend-unrelated-layer': { severity: 'Info' },
@@ -137,10 +161,11 @@ const centralMessages = {
137
161
  'ref-undefined-element': { severity: 'Error' },
138
162
  'anno-undefined-element': { severity: 'Error' },
139
163
  'ref-unknown-var': { severity: 'Info' },
140
- 'ref-obsolete-parameters': { severity: 'Error', configurableFor: 'v4' },
164
+ 'ref-obsolete-parameters': { severity: 'Error', configurableFor: 'deprecated' },
141
165
  // does not hurt us, but makes it tedious to detect parameter refs
142
166
  'ref-undefined-param': { severity: 'Error' },
143
167
  'ref-undefined-enum': { severity: 'Warning', errorFor: [ 'to.sql', 'to.hdbcds', 'to.hdi' ] },
168
+ 'ref-unexpected-enum': { severity: 'Warning', errorFor: [ 'to.sql', 'to.hdbcds', 'to.hdi' ] },
144
169
  'anno-undefined-param': { severity: 'Error' },
145
170
  'ref-rejected-on': { severity: 'Error' },
146
171
  'ref-expected-element': { severity: 'Error' },
@@ -155,60 +180,62 @@ const centralMessages = {
155
180
 
156
181
  'expr-unexpected-operator': { severity: 'Error', configurableFor: true },
157
182
 
158
- 'syntax-deprecated-auto-union': { severity: 'Error', configurableFor: 'v4' },
159
183
  // Published! Used in @sap/cds-lsp; if renamed, add to oldMessageIds and contact colleagues
160
184
  // Also used by other projects that rely on double-quotes for delimited identifiers.
161
185
  'syntax-deprecated-ident': { severity: 'Error', configurableFor: true },
162
- 'syntax-deprecated-property': { severity: 'Error', configurableFor: 'v4' }, // v0 prop
163
- 'syntax-deprecated-value': { severity: 'Error', configurableFor: 'v4' }, // v0 prop
186
+ 'syntax-deprecated-property': { severity: 'Error', configurableFor: 'test' }, // v0 prop
187
+ 'syntax-deprecated-value': { severity: 'Error', configurableFor: 'test' }, // v0 prop
164
188
  // 'syntax-duplicate-annotate' came late with v3 - make it configurable as
165
189
  // fallback, but then parse.cdl is not supposed to work correctly (it can
166
190
  // then either issue an error or produce a CSN missing some annotations):
167
191
  'syntax-duplicate-annotate': { severity: 'Error' },
168
- 'syntax-duplicate-clause': { severity: 'Error', configurableFor: [ 'v6' ] },
192
+ 'syntax-duplicate-clause': { severity: 'Error' },
169
193
  // remark: a hard syntax error in new parser for `null` together with `not null`
170
- 'syntax-duplicate-equal-clause': { severity: 'Warning', errorFor: [ 'v6' ] },
171
- 'syntax-invalid-name': { severity: 'Error', configurableFor: 'deprecated' },
194
+ 'syntax-duplicate-equal-clause': { severity: 'Warning' },
195
+ 'syntax-invalid-name': { severity: 'Error' },
172
196
  'syntax-missing-as': { severity: 'Error', configurableFor: true },
173
197
  'syntax-missing-proj-semicolon': { severity: 'Warning' },
174
- 'syntax-unexpected-after': { severity: 'Warning', errorFor: [ 'v6' ] },
175
- 'syntax-unexpected-filter': { severity: 'Warning', errorFor: [ 'v6' ] },
176
- 'syntax-unexpected-many-one': { severity: 'Error', configurableFor: true }, // TODO: remove `configurableFor` soon, latest v6
177
- 'syntax-deprecated-ref-virtual': { severity: 'Warning', errorFor: [ 'v6' ] },
198
+ 'syntax-unexpected-after': { severity: 'Error' },
199
+ 'syntax-unexpected-filter': { severity: 'Error', configurableFor: true },
200
+ 'syntax-unexpected-many-one': { severity: 'Error' },
201
+ 'syntax-deprecated-ref-virtual': { severity: 'Error' },
178
202
  'syntax-unexpected-reserved-word': { severity: 'Error', configurableFor: true },
179
203
  'syntax-unknown-escape': { severity: 'Error', configurableFor: true },
180
204
  'syntax-unsupported-masked': { severity: 'Error', configurableFor: 'deprecated' },
181
205
  'syntax-unexpected-sql-clause': { severity: 'Error' }, // TODO: configurableFor:'tests'?
182
- 'syntax-invalid-space': { severity: 'Error', configurableFor: 'test' },
206
+ 'syntax-invalid-space': { severity: 'Error', configurableFor: true },
183
207
  'syntax-expecting-space': { severity: 'Error' },
184
208
  'syntax-unexpected-anno': { severity: 'Error' },
185
209
  'migration-unsupported-key-change': { severity: 'Error', configurableFor: [ 'to.sql.migration', 'to.sql.migration-script' ] },
186
- 'type-missing-enum-value': { severity: 'Error', configurableFor: 'test' },
210
+ 'type-missing-enum-value': { severity: 'Error', configurableFor: 'deprecated' },
187
211
 
188
212
  'def-missing-element': { severity: 'Error' },
213
+ 'def-missing-virtual': { severity: 'Error', configurableFor: true },
189
214
  'def-expected-structured': { severity: 'Error', configurableFor: true },
190
215
  'def-unsupported-calc-elem': { severity: 'Error', configurableFor: true },
191
216
 
192
217
  'def-invalid-key-cardinality': { severity: 'Error' },
193
- // Published! Used in @cap-js-community/odata-v2-adapter; if renamed, add to oldMessageIds
194
- 'odata-spec-violation-array': { severity: 'Warning' }, // more than 30 chars
195
- // Published! Used in @cap-js-community/odata-v2-adapter; if renamed, add to oldMessageIds
196
- 'odata-spec-violation-assoc': { severity: 'Warning' }, // more than 30 chars
197
- // Published! Used in @cap-js-community/odata-v2-adapter; if renamed, add to oldMessageIds
198
- 'odata-spec-violation-constraints': { severity: 'Info' }, // more than 30 chars
199
- 'odata-spec-violation-id': { severity: 'Error', configurableFor: true },
200
- 'odata-spec-violation-namespace': { severity: 'Warning' }, // more than 30 chars
201
- // Published! Used in @cap-js-community/odata-v2-adapter; if renamed, add to oldMessageIds
202
- 'odata-spec-violation-param': { severity: 'Warning' }, // more than 30 chars
203
- // Published! Used in @cap-js-community/odata-v2-adapter; if renamed, add to oldMessageIds
204
- 'odata-spec-violation-returns': { severity: 'Warning' }, // more than 30 chars
205
- 'odata-spec-violation-type': { severity: 'Error', configurableFor: true },
206
- 'odata-spec-violation-type-unknown': { severity: 'Error', configurableFor: true },
207
- 'odata-spec-violation-no-key': { severity: 'Error', configurableFor: true },
208
- 'odata-spec-violation-key-array': { severity: 'Error', configurableFor: true }, // more than 30 chars
209
- 'odata-spec-violation-key-null': { severity: 'Error', configurableFor: true }, // more than 30 chars
210
- 'odata-spec-violation-key-type': { severity: 'Warning' }, // more than 30 chars
211
- 'odata-spec-violation-property-name': { severity: 'Warning' }, // more than 30 chars
218
+
219
+ 'odata-unexpected-array': { severity: 'Warning' },
220
+ 'odata-unexpected-assoc': { severity: 'Warning' },
221
+ 'odata-incomplete-constraints': { severity: 'Info' },
222
+ 'odata-invalid-name': { severity: 'Error', configurableFor: true },
223
+ 'odata-invalid-vocabulary-alias': { severity: 'Error', configurableFor: true },
224
+ 'odata-invalid-qualifier': { severity: 'Error', configurableFor: true },
225
+ 'odata-invalid-service-name': { severity: 'Warning' },
226
+ 'odata-invalid-param-type': { severity: 'Warning' },
227
+ 'odata-invalid-return-type': { severity: 'Warning' },
228
+ 'odata-missing-type': { severity: 'Error', configurableFor: true },
229
+ 'odata-invalid-scale': { severity: 'Error', configurableFor: true },
230
+ 'odata-unexpected-edm-facet': { severity: 'Error', configurableFor: true },
231
+ 'odata-invalid-external-type': { severity: 'Error', configurableFor: true },
232
+ 'odata-unexpected-edm-type': { severity: 'Error', configurableFor: true },
233
+ 'odata-unknown-edm-type': { severity: 'Error', configurableFor: true },
234
+ 'odata-missing-key': { severity: 'Error', configurableFor: true },
235
+ 'odata-unexpected-arrayed-key': { severity: 'Error', configurableFor: true },
236
+ 'odata-unexpected-nullable-key': { severity: 'Error', configurableFor: true },
237
+ 'odata-invalid-key-type': { severity: 'Warning' },
238
+ 'odata-invalid-property-name': { severity: 'Warning' },
212
239
  'odata-anno-preproc': { severity: 'Warning' },
213
240
  'odata-anno-dict': { severity: 'Warning' },
214
241
  'odata-anno-vocref': { severity: 'Warning' },
@@ -216,7 +243,11 @@ const centralMessages = {
216
243
  'odata-anno-value': { severity: 'Warning' },
217
244
  'odata-anno-type': { severity: 'Warning' },
218
245
  'odata-anno-def': { severity: 'Info' },
246
+ 'odata-duplicate-definition': { severity: 'Error' },
247
+ 'odata-duplicate-proxy': { severity: 'Warning' },
248
+
219
249
  'query-ignoring-assoc-in-union': { severity: 'Info' },
250
+
220
251
  // for to.sql.migration - cannot be supplied by the user!
221
252
  'migration-unsupported-precision-change': { severity: 'Error', configurableFor: [ 'to.sql.migration-script' ] },
222
253
  'migration-unsupported-element-drop': { severity: 'Error', configurableFor: [ 'to.sql.migration-script' ] },
@@ -231,26 +262,46 @@ const centralMessages = {
231
262
  // We keep them in a separate array for easier access. No need to go through all
232
263
  // existing messages and search for the old one in `oldNames` property.
233
264
  // The keys will be added to `oldNames` of the new message, which is used for reclassification.
234
- const oldMessageIds = createDict({
265
+ const oldMessageIds = {
266
+ __proto__: null,
267
+
235
268
  'old-anno-duplicate': 'anno-duplicate', // Example
269
+
236
270
  'assoc-in-array': 'type-invalid-items',
237
271
  'duplicate-autoexposed': 'def-duplicate-autoexposed',
238
272
  'expr-no-filter': 'expr-unexpected-filter',
239
273
  'check-proper-type': 'def-missing-type',
240
- });
274
+
275
+ // All odata messages were renamed in v6. Some were split up into separate ones.
276
+ 'odata-spec-violation-array': 'odata-unexpected-array',
277
+ 'odata-spec-violation-assoc': 'odata-unexpected-assoc',
278
+ 'odata-spec-violation-constraints': 'odata-incomplete-constraints',
279
+ 'odata-spec-violation-id': [ 'odata-invalid-name', 'odata-invalid-vocabulary-alias', 'odata-invalid-qualifier' ],
280
+ 'odata-spec-violation-namespace': 'odata-invalid-service-name',
281
+ 'odata-spec-violation-param': 'odata-invalid-param-type',
282
+ 'odata-spec-violation-returns': 'odata-invalid-return-type',
283
+ 'odata-spec-violation-type': [ 'odata-unexpected-edm-facet', 'odata-missing-type', 'odata-invalid-scale', 'odata-unexpected-edm-type', 'odata-invalid-external-type' ],
284
+ 'odata-spec-violation-type-unknown': 'odata-unknown-edm-type',
285
+ 'odata-spec-violation-no-key': 'odata-missing-key',
286
+ 'odata-spec-violation-key-array': 'odata-unexpected-arrayed-key',
287
+ 'odata-spec-violation-key-type': 'odata-invalid-key-type',
288
+ 'odata-spec-violation-key-null': 'odata-unexpected-nullable-key',
289
+ 'odata-spec-violation-property-name': 'odata-invalid-property-name',
290
+ 'odata-definition-exists': [ 'odata-duplicate-definition', 'odata-duplicate-proxy' ],
291
+ };
241
292
 
242
293
  // Set up the old-to-new message ID mapping in the message registry.
243
294
  for (const oldName in oldMessageIds) {
244
- const newName = oldMessageIds[oldName];
245
295
  if (centralMessages[oldName])
246
296
  throw new CompilerAssertion(`Mapping from ${ oldName } not possible: ID is still used in message registry.`);
247
- if (!centralMessages[newName])
248
- throw new CompilerAssertion(`Mapping from ${ oldName } to new message ID ${ newName } does not exist!`);
249
297
 
250
- if (!centralMessages[newName].oldNames)
251
- centralMessages[newName].oldNames = [ oldName ];
252
- else
298
+ const newNames = Array.isArray(oldMessageIds[oldName]) ? oldMessageIds[oldName] : [ oldMessageIds[oldName] ];
299
+ for (const newName of newNames) {
300
+ if (!centralMessages[newName])
301
+ throw new CompilerAssertion(`Mapping from ${ oldName } to new message ID ${ newName } does not exist!`);
302
+ centralMessages[newName].oldNames ??= [ ];
253
303
  centralMessages[newName].oldNames.push(oldName);
304
+ }
254
305
  }
255
306
 
256
307
 
@@ -259,9 +310,7 @@ for (const oldName in oldMessageIds) {
259
310
  // If you change it, keep in sync with scripts/eslint/rules/message-text.js
260
311
 
261
312
  const centralMessageTexts = {
262
- 'api-deprecated-v5': {
263
- std: 'Support for generating hdbcds output is deprecated with @sap/cds-compiler v5 and later',
264
- },
313
+ 'api-deprecated-hdbcds': 'Support for generating hdbcds output is deprecated with @sap/cds-compiler v5 and later',
265
314
  'api-invalid-option': {
266
315
  std: 'Invalid option $(NAME)!',
267
316
  deprecated: 'Option $(NAME) is no longer supported! Use latest API options instead',
@@ -270,10 +319,12 @@ const centralMessageTexts = {
270
319
  value2: 'Expected option $(OPTION) to have value $(VALUE) or $(RAWVALUE); found: $(OTHERVALUE)',
271
320
  type: 'Expected option $(OPTION) to be of type $(VALUE). Found: $(OTHERVALUE)',
272
321
  forbidden: 'Option $(OPTION) can\'t be used with API function $(MODULE)',
322
+ odataV2json: 'OData JSON output is not available for OData V2',
273
323
  },
274
324
  'def-upcoming-virtual-change': {
275
- std: 'This select item will be a new element in cds-compiler v6, without referencing $(NAME); prepend a table alias if you want to keep the virtual element as a reference; see https://cap.cloud.sap/docs/cds/compiler/messages#def-upcoming-virtual-change for details',
325
+ std: 'This select item is a new element in cds-compiler v6, but only supported with the new parser',
276
326
  },
327
+ 'query-invalid-virtual-struct': 'For a virtual structure in a query, use a defined structure type, or add $(CODE) when you meant to specify references',
277
328
 
278
329
  'api-invalid-variable-replacement': {
279
330
  std: 'Option $(OPTION) does not support $(NAME)',
@@ -282,12 +333,18 @@ const centralMessageTexts = {
282
333
  noDollar: 'Option $(OPTION) does not know $(NAME). Did you forget a leading $(CODE)?',
283
334
  },
284
335
 
336
+ 'api-invalid-version': {
337
+ std: 'Invalid CSN version: $(VERSION)',
338
+ migrationComparison: 'Incompatible CSN versions: $(VALUE) is a major downgrade from $(OTHERVALUE). Is @sap/cds-compiler version $(VERSION) outdated?',
339
+ },
340
+
285
341
  'api-invalid-combination': {
286
342
  std: 'Invalid option combination found: $(OPTION) and $(PROP)', // unused
287
343
  'valid-structured': 'Structured OData is only supported with OData version v4',
288
344
  'sql-dialect-and-naming': 'sqlDialect $(NAME) can\'t be combined with sqlMapping $(PROP)',
289
345
  'tenant-and-naming': 'Option $(OPTION) can\'t be combined with sqlMapping $(PROP) - expected sqlMapping $(VALUE)',
290
346
  'dry-and-script': 'script:true must be combined with dry:true, found $(VALUE)',
347
+ 'hana-migration': 'SQL dialect $(VALUE) is not supported with API function "to.sql.migration" - use HDI via "to.hdi" and "to.hdi.migration"',
291
348
  'effectiveServiceName-and-type-resolution': 'Option $(NAME) can\'t be used without $(PROP)',
292
349
  },
293
350
  'api-unexpected-combination': {
@@ -332,8 +389,6 @@ const centralMessageTexts = {
332
389
  param: 'Assign a value for $(ANNO); the value inherited from $(ART) can\'t be rewritten due to parameter reference $(ELEMREF)',
333
390
  },
334
391
 
335
- 'chained-array-of': '"Array of"/"many" must not be chained with another "array of"/"many" inside a service',
336
-
337
392
  'check-proper-type-of': {
338
393
  std: 'Referred element $(NAME) of $(ART) does not contain proper type information',
339
394
  derived: 'Referred type of $(ART) does not contain proper type information',
@@ -448,6 +503,8 @@ const centralMessageTexts = {
448
503
  std: 'You have already provided this clause',
449
504
  cardinality: 'You have already provided a target cardinality $(CODE) instead, at line $(LINE), column $(COL)',
450
505
  notNull: 'You have already provided $(CODE) instead, at line $(LINE), column $(COL) below',
506
+ orderByLimit: 'You have already provided $(CODE) before',
507
+ setForCsn: 'You have provided property $(PROP)/$(SIBLINGPROP) inside and outside $(PARENTPROP)',
451
508
  },
452
509
  'syntax-duplicate-equal-clause': {
453
510
  std: 'You have already provided the same clause',
@@ -611,6 +668,7 @@ const centralMessageTexts = {
611
668
  // to help users for `… from E:toF { toF[…].x }`
612
669
  tableAlias: 'A filter can only be provided when navigating along associations, but found table alias',
613
670
  from: 'A filter can only be provided for the source entity or associations',
671
+ 'model-only': 'A filter can\'t be provided for a to-many association without ON-condition',
614
672
  },
615
673
 
616
674
  // multi-line strings: --------------------------------------------------------
@@ -632,6 +690,12 @@ const centralMessageTexts = {
632
690
 
633
691
  // Messages for erroneous references -----------------------------------------
634
692
  // location at erroneous reference (if possible)
693
+ 'ref-cyclic': {
694
+ std: 'Illegal circular reference to $(ART)',
695
+ element: 'Illegal circular reference to element $(MEMBER) of $(ART)',
696
+ target: 'Illegal circular reference to target $(ART)',
697
+ type: 'Illegal recursive type definition to $(TYPE)',
698
+ },
635
699
  'ref-deprecated-orderby': 'Replace source element reference $(ID) by $(NEWCODE); auto-corrected',
636
700
  'ref-missing-self-counterpart' : {
637
701
  std: 'Expected to find a matching element in $self-comparison for foreign key $(PROP) of association $(NAME)',
@@ -690,7 +754,13 @@ const centralMessageTexts = {
690
754
  self: 'Variable $(ID) has not been found. Use $(ALIAS) to refer an element with the same name',
691
755
  value: 'No value found for variable $(ID). Use option $(OPTION) to specify a value for $(ID)',
692
756
  },
693
- 'ref-undefined-enum' : 'Enum symbol $(ID) is not defined in $(TYPE)',
757
+ 'ref-undefined-enum': 'Enum symbol $(ID) is not defined in $(TYPE)',
758
+ 'ref-unexpected-enum': {
759
+ std: 'Unexpected enum reference $(ENUM)',
760
+ symbolDef: 'References to other values are not allowed as enum values',
761
+ untyped: 'Unexpected enum reference $(ENUM); no type can be inferred for it',
762
+ invalidType: 'Unexpected enum reference $(ENUM) as value for a non-enum type $(TYPE)',
763
+ },
694
764
  'ref-unknown-var': {
695
765
  std: 'No replacement found for special variable $(ID)',
696
766
  },
@@ -738,6 +808,13 @@ const centralMessageTexts = {
738
808
  'managed-filter': 'Unexpected managed association $(NAME) in filter expression of $(ID)',
739
809
  'unmanaged-filter': 'Unexpected unmanaged association $(NAME) in filter expression of $(ID)',
740
810
  },
811
+ 'ref-unexpected-assoc-type': {
812
+ std: 'An association is not allowed as this artifact\'s type', // Not used
813
+ 'action-param': 'An association is not allowed as action\'s parameter type',
814
+ 'function-param': 'An association is not allowed as function\'s parameter type',
815
+ 'action-returns': 'An association is not allowed as action\'s return type',
816
+ 'function-returns': 'An association is not allowed as function\'s return type',
817
+ },
741
818
  'ref-unexpected-calculated': {
742
819
  std: 'Unexpected reference to calculated element',
743
820
  on: 'Calculated elements (on-read) can\'t be used in ON-conditions of unmanaged associations',
@@ -771,6 +848,7 @@ const centralMessageTexts = {
771
848
  hana: 'Type $(TYPE) is only supported for SQL dialect $(VALUE), not $(OTHERVALUE)',
772
849
  hdbcds:'Type $(TYPE) is not supported in HDBCDS',
773
850
  odata: 'Type $(TYPE) is not supported for OData $(VERSION)',
851
+ key: 'Type $(TYPE) can\'t be used as primary key in element $(NAME)',
774
852
  },
775
853
  'ref-unexpected-var': {
776
854
  std: 'Variable $(NAME) can\'t be used here',
@@ -827,6 +905,7 @@ const centralMessageTexts = {
827
905
  nested: 'Unexpected $(PROP) inside $(PROP)',
828
906
  assoc: 'Unexpected association inside $(PROP)',
829
907
  comp: 'Unexpected composition inside $(PROP)',
908
+ 'chained-service': '"Array of"/"many" must not be chained with another "array of"/"many" inside a service',
830
909
  },
831
910
 
832
911
  'type-unexpected-default': {
@@ -918,6 +997,7 @@ const centralMessageTexts = {
918
997
  },
919
998
  'def-unexpected-localized-struct': '$(KEYWORD) is not fully supported for structures',
920
999
  'def-unexpected-localized-anno': 'Annotations can\'t have localized elements',
1000
+ 'def-unexpected-virtual': 'Unexpected $(KEYWORD): an element can\'t be virtual and an association/composition',
921
1001
  'type-unexpected-structure': {
922
1002
  std: 'Unexpected structured type', // unused variant
923
1003
  calc: 'A structured type can\'t be used for calculated elements',
@@ -1070,6 +1150,7 @@ const centralMessageTexts = {
1070
1150
  std: 'Using nested projections next to calculated elements is not supported, yet',
1071
1151
  inside: 'Using calculated elements in nested projections is not supported, yet',
1072
1152
  },
1153
+ 'query-unsupported-asterisk': 'Unsupported asterisk in $(CODE) inside a nested projection',
1073
1154
  'query-mismatched-element': {
1074
1155
  std: 'Specified element $(NAME) differs from inferred element in property $(PROP)',
1075
1156
  type: 'Expected type of specified element $(NAME) to be the same as the inferred element\'s type',
@@ -1158,6 +1239,12 @@ const centralMessageTexts = {
1158
1239
  targetVal: 'Target minimum cardinality must not be greater than target maximum cardinality',
1159
1240
  },
1160
1241
 
1242
+ 'type-invalid-self': 'An association that uses $(NAME) in its ON-condition can\'t be compared to $(NAME)',
1243
+ 'type-invalid-foreign-key': {
1244
+ std: 'Unexpected type $(TYPE) in foreign key',
1245
+ items: 'Unexpected arrayed element as foreign keys',
1246
+ },
1247
+
1161
1248
  'i18n-different-value': 'Different translation for key $(PROP) of language $(OTHERPROP) in unrelated layers',
1162
1249
 
1163
1250
  'expr-missing-foreign-key': {
@@ -1184,58 +1271,58 @@ const centralMessageTexts = {
1184
1271
  // OData Message section starts here
1185
1272
  // -----------------------------------------------------------------------------------
1186
1273
  // OData version dependent messages
1187
- 'odata-spec-violation-array': 'Unexpected array type for OData $(VERSION)',
1188
- 'odata-spec-violation-param' : 'Expected parameter to be typed with either scalar or structured type for OData $(VERSION)',
1189
- 'odata-spec-violation-returns': 'Expected $(KIND) to return one or many values of scalar, complex, entity or view type for OData $(VERSION)',
1190
- 'odata-spec-violation-assoc': 'Unexpected association in structured type for OData $(VERSION)',
1191
- 'odata-spec-violation-constraints': 'Partial referential constraints produced for OData $(VERSION)',
1192
- 'odata-spec-violation-id': {
1274
+ 'odata-unexpected-array': 'Unexpected array type for OData $(VERSION)',
1275
+ 'odata-invalid-param-type' : 'Expected parameter to be typed with either scalar or structured type for OData $(VERSION)',
1276
+ 'odata-invalid-return-type': 'Expected $(KIND) to return one or many values of scalar, complex, entity or view type for OData $(VERSION)',
1277
+ 'odata-unexpected-assoc': 'Unexpected association in structured type for OData $(VERSION)',
1278
+ 'odata-incomplete-constraints': 'Partial referential constraints produced for OData $(VERSION)',
1279
+ 'odata-invalid-name': {
1193
1280
  std: 'Expected OData name $(ID) to start with an alphabetic character or underscore, followed by a maximum of 127 alphabetic characters, digits, or underscores',
1194
1281
  v2firstChar: 'Unexpected first character $(PROP) of OData name $(ID) for OData $(VERSION)',
1195
- qualifier: 'Expected OData annotation qualifier $(ID) to start with an alphabetic character or underscore, followed by a maximum of 127 alphabetic characters, digits, or underscores',
1196
- vocRefAlias: 'Expected value $(VALUE) of OData vocabulary reference attribute $(ID) to start with an alphabetic character or underscore, followed by a maximum of 127 alphabetic characters, digits, or underscores',
1197
1282
  },
1283
+ 'odata-invalid-vocabulary-alias': 'Expected value $(VALUE) of OData vocabulary reference attribute $(ID) to start with an alphabetic character or underscore, followed by a maximum of 127 alphabetic characters, digits, or underscores',
1284
+ 'odata-invalid-qualifier': 'Expected OData annotation qualifier $(ID) to start with an alphabetic character or underscore, followed by a maximum of 127 alphabetic characters, digits, or underscores',
1198
1285
  // version independent messages
1199
- 'odata-spec-violation-key-array': {
1200
- std: 'Unexpected array type for primary key $(NAME)',
1201
- assoc: 'Unexpected target cardinality $(VALUE) for primary key $(NAME)',
1202
- },
1203
- 'odata-spec-violation-key-null': {
1286
+ 'odata-unexpected-nullable-key': {
1204
1287
  std: 'Expected key element $(NAME) to be not nullable', // flat
1205
1288
  scalar: 'Expected key element $(NAME) to be not nullable', // structured
1206
1289
  },
1207
- 'odata-spec-violation-key-type': {
1290
+ 'odata-unexpected-arrayed-key': {
1291
+ std: 'Unexpected array type for primary key $(NAME)',
1292
+ assoc: 'Unexpected target cardinality $(VALUE) for primary key $(NAME)',
1293
+ },
1294
+ 'odata-invalid-key-type': {
1208
1295
  std: 'Unexpected $(TYPE) mapped to $(ID) as type for key element $(NAME)', // structured
1209
1296
  scalar: 'Unexpected $(TYPE) mapped to $(ID) as type for key element', // flat
1210
1297
  },
1211
- 'odata-spec-violation-no-key': 'Expected entity to have a primary key',
1212
- 'odata-spec-violation-type-unknown': 'Unknown EDM Type $(TYPE)',
1213
- 'odata-spec-violation-type': {
1214
- std: 'Expected element to have a type',
1215
- incompatible: 'Unexpected EDM Type $(TYPE) for OData $(VERSION)',
1216
- incompatible_anno: 'Unexpected EDM Type $(TYPE) for OData $(VERSION) in $(ANNO)',
1217
- facet: 'Unexpected EDM Type facet $(NAME) of type $(TYPE) for OData $(VERSION)',
1218
- facet_anno: 'Unexpected EDM Type facet $(NAME) of type $(TYPE) for OData $(VERSION) in $(ANNO)',
1219
- external: 'Referenced type $(TYPE) marked as $(ANNO) can\'t be rendered as $(CODE) in service $(NAME) for OData $(VERSION)',
1220
- scale: 'Expected scale $(NUMBER) to be less than or equal to precision $(RAWVALUE)',
1221
- scale_anno: 'Expected scale $(NUMBER) to be less than or equal to precision $(RAWVALUE) in $(ANNO)',
1222
- },
1223
- 'odata-spec-violation-property-name': 'Expected element name to be different from declaring $(META)',
1224
- 'odata-spec-violation-namespace': {
1298
+ 'odata-missing-key': 'Expected entity to have a primary key',
1299
+ 'odata-unknown-edm-type': 'Unknown EDM Type $(TYPE)',
1300
+ 'odata-unexpected-edm-type': {
1301
+ std: 'Unexpected EDM Type $(TYPE) for OData $(VERSION)',
1302
+ anno: 'Unexpected EDM Type $(TYPE) for OData $(VERSION) in $(ANNO)',
1303
+ },
1304
+ 'odata-missing-type': 'Expected element to have a type',
1305
+ 'odata-unexpected-edm-facet': {
1306
+ std: 'Unexpected EDM Type facet $(NAME) of type $(TYPE) for OData $(VERSION)',
1307
+ anno: 'Unexpected EDM Type facet $(NAME) of type $(TYPE) for OData $(VERSION) in $(ANNO)',
1308
+ },
1309
+ 'odata-invalid-external-type': 'Referenced type $(TYPE) marked as $(ANNO) can\'t be rendered as $(CODE) in service $(NAME) for OData $(VERSION)',
1310
+ 'odata-invalid-scale': {
1311
+ std: 'Expected scale $(NUMBER) to be less than or equal to precision $(RAWVALUE)',
1312
+ anno: 'Expected scale $(NUMBER) to be less than or equal to precision $(RAWVALUE) in $(ANNO)',
1313
+ },
1314
+ 'odata-invalid-property-name': 'Expected element name to be different from declaring $(META)',
1315
+ 'odata-invalid-service-name': {
1225
1316
  std: 'Expected service name not to be one of the reserved names $(NAMES)',
1226
1317
  length: 'Expected service name not to exceed 511 characters',
1227
1318
  },
1228
1319
  // Other odata/edm errors
1229
- 'odata-definition-exists': {
1320
+ 'odata-duplicate-proxy': 'No proxy entity created due to name collision with existing definition $(NAME) of kind $(KIND)',
1321
+ 'odata-duplicate-definition': {
1230
1322
  std: 'Entity can\'t be created due to name collision with existing definition $(NAME)',
1231
- proxy: 'No proxy entity created due to name collision with existing definition $(NAME) of kind $(KIND)',
1232
1323
  anno: 'Name of annotation definition $(ANNO) conflicts with existing service definition',
1233
- termredef: 'Unexpected redefinition of annotation $(ANNO)',
1234
- },
1235
- 'odata-navigation': {
1236
- std: 'No OData navigation property generated, target $(TARGET) is outside of service $(SERVICE)',
1237
- oncond: 'No OData navigation property generated for association with arbitrary ON-condition and target $(TARGET) outside of service $(SERVICE)',
1238
1324
  },
1325
+ 'odata-navigation': 'No OData navigation property generated, target $(TARGET) is outside of service $(SERVICE)',
1239
1326
  'odata-parameter-order': 'Unexpected mandatory after optional parameter',
1240
1327
  'odata-key-recursive': 'Unexpected recursive key $(NAME)',
1241
1328
  'odata-key-uuid-default-anno': 'Expected element of type $(TYPE) to be annotated with $(ANNO) when used as primary key in $(ID)',
@@ -1291,8 +1378,8 @@ const centralMessageTexts = {
1291
1378
  enum: 'Value $(VALUE) is not one out of $(RAWVALUES) for $(ANNO) of type $(TYPE)',
1292
1379
  std: 'Unexpected value $(VALUE) for $(ANNO) of type $(TYPE)',
1293
1380
  incompval: 'Unexpected $(STR) value for $(ANNO) of type $(TYPE)',
1294
- nestedcollection: 'Nested collections are not supported for $(ANNO)',
1295
- enumincollection: 'Enum inside collection is not supported for $(ANNO)',
1381
+ nestedCollection: 'Nested collections are not supported for $(ANNO)',
1382
+ enuminCollection: 'Enum inside collection is not supported for $(ANNO)',
1296
1383
  multexpr: 'EDM JSON code contains more than one dynamic expression: $(RAWVALUES) for $(ANNO)',
1297
1384
  },
1298
1385
  'odata-anno-type': {
@@ -1394,7 +1481,6 @@ const centralMessageTexts = {
1394
1481
  * If not `true` then an array is expected with specified modules in which the error is downgradable.
1395
1482
  * Only has an effect if default severity is 'Error'.
1396
1483
  * 'deprecated': severity can only be changed with deprecated.downgradableErrors.
1397
- * TODO: Value `true` is temporary. Use an array instead.
1398
1484
  * @property {string[]} [errorFor] Array of module names where the message shall be reclassified to an error.
1399
1485
  * @property {boolean} [throughMessageCall]
1400
1486
  * If set, it means that a message-id was added to the registry in test-mode through a `message.<severity>()`
@@ -1405,4 +1491,10 @@ const centralMessageTexts = {
1405
1491
 
1406
1492
  // console.log('FOO')
1407
1493
 
1408
- module.exports = { centralMessages, centralMessageTexts, oldMessageIds };
1494
+ module.exports = {
1495
+ centralMessages,
1496
+ configurableForValidValues,
1497
+ validModules,
1498
+ centralMessageTexts,
1499
+ oldMessageIds,
1500
+ };