@sap/cds-compiler 3.5.4 → 3.6.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 (83) hide show
  1. package/CHANGELOG.md +56 -2
  2. package/bin/cdsc.js +14 -6
  3. package/doc/CHANGELOG_ARCHIVE.md +10 -10
  4. package/doc/CHANGELOG_DEPRECATED.md +2 -2
  5. package/lib/api/main.js +32 -55
  6. package/lib/api/validate.js +5 -0
  7. package/lib/base/message-registry.js +104 -32
  8. package/lib/base/messages.js +277 -212
  9. package/lib/base/optionProcessorHelper.js +9 -2
  10. package/lib/base/shuffle.js +50 -0
  11. package/lib/checks/actionsFunctions.js +37 -20
  12. package/lib/checks/foreignKeys.js +13 -6
  13. package/lib/checks/nonexpandableStructured.js +1 -2
  14. package/lib/checks/onConditions.js +21 -19
  15. package/lib/checks/parameters.js +1 -1
  16. package/lib/checks/queryNoDbArtifacts.js +2 -0
  17. package/lib/checks/types.js +16 -22
  18. package/lib/compiler/assert-consistency.js +31 -28
  19. package/lib/compiler/builtins.js +20 -4
  20. package/lib/compiler/checks.js +72 -63
  21. package/lib/compiler/define.js +396 -314
  22. package/lib/compiler/extend.js +55 -49
  23. package/lib/compiler/index.js +5 -0
  24. package/lib/compiler/populate.js +28 -11
  25. package/lib/compiler/propagator.js +2 -1
  26. package/lib/compiler/resolve.js +28 -13
  27. package/lib/compiler/shared.js +15 -10
  28. package/lib/compiler/utils.js +7 -7
  29. package/lib/edm/annotations/genericTranslation.js +51 -46
  30. package/lib/edm/annotations/preprocessAnnotations.js +37 -40
  31. package/lib/edm/csn2edm.js +69 -21
  32. package/lib/edm/edm.js +2 -2
  33. package/lib/edm/edmInboundChecks.js +6 -8
  34. package/lib/edm/edmPreprocessor.js +88 -80
  35. package/lib/edm/edmUtils.js +6 -15
  36. package/lib/gen/Dictionary.json +81 -13
  37. package/lib/gen/language.checksum +1 -1
  38. package/lib/gen/language.interp +2 -1
  39. package/lib/gen/languageParser.js +4680 -4484
  40. package/lib/inspect/inspectModelStatistics.js +2 -1
  41. package/lib/inspect/inspectPropagation.js +2 -1
  42. package/lib/json/from-csn.js +131 -78
  43. package/lib/json/to-csn.js +39 -23
  44. package/lib/language/antlrParser.js +0 -3
  45. package/lib/language/docCommentParser.js +7 -3
  46. package/lib/language/errorStrategy.js +3 -2
  47. package/lib/language/genericAntlrParser.js +96 -41
  48. package/lib/language/language.g4 +112 -128
  49. package/lib/language/multiLineStringParser.js +2 -1
  50. package/lib/main.d.ts +115 -2
  51. package/lib/main.js +16 -3
  52. package/lib/model/csnRefs.js +3 -3
  53. package/lib/model/csnUtils.js +109 -179
  54. package/lib/model/enrichCsn.js +13 -8
  55. package/lib/model/revealInternalProperties.js +4 -3
  56. package/lib/optionProcessor.js +19 -3
  57. package/lib/render/manageConstraints.js +11 -15
  58. package/lib/render/toCdl.js +144 -47
  59. package/lib/render/toHdbcds.js +22 -22
  60. package/lib/render/toRename.js +3 -4
  61. package/lib/render/toSql.js +29 -20
  62. package/lib/render/utils/delta.js +3 -1
  63. package/lib/render/utils/sql.js +2 -14
  64. package/lib/transform/db/associations.js +6 -6
  65. package/lib/transform/db/cdsPersistence.js +3 -3
  66. package/lib/transform/db/constraints.js +4 -6
  67. package/lib/transform/db/expansion.js +4 -4
  68. package/lib/transform/db/flattening.js +12 -15
  69. package/lib/transform/db/temporal.js +4 -3
  70. package/lib/transform/db/transformExists.js +2 -1
  71. package/lib/transform/draft/db.js +7 -7
  72. package/lib/transform/forOdataNew.js +15 -4
  73. package/lib/transform/forRelationalDB.js +53 -39
  74. package/lib/transform/odata/toFinalBaseType.js +106 -82
  75. package/lib/transform/odata/typesExposure.js +26 -17
  76. package/lib/transform/odata/utils.js +1 -1
  77. package/lib/transform/parseExpr.js +1 -1
  78. package/lib/transform/transformUtilsNew.js +33 -10
  79. package/lib/transform/translateAssocsToJoins.js +8 -7
  80. package/lib/transform/universalCsn/coreComputed.js +7 -5
  81. package/lib/transform/universalCsn/universalCsnEnricher.js +12 -4
  82. package/lib/utils/timetrace.js +2 -2
  83. package/package.json +1 -2
@@ -55,11 +55,11 @@ const centralMessages = {
55
55
  'anno-invalid-sql-kind': { severity: 'Error', configurableFor: true }, // @sql.prepend/append - configurable for "I know what I'm doing"
56
56
  'anno-invalid-sql-view': { severity: 'Error', configurableFor: true }, // @sql.prepend/append - configurable for "I know what I'm doing"
57
57
  'anno-invalid-sql-view-element': { severity: 'Error', configurableFor: true }, // @sql.prepend/append - configurable for "I know what I'm doing"
58
- 'anno-undefined-action': { severity: 'Info' },
59
- 'anno-undefined-art': { severity: 'Info' }, // for annotate statement (for CDL path root)
60
- 'anno-undefined-def': { severity: 'Info' }, // for annotate statement (for CSN or CDL path cont)
61
- 'anno-undefined-element': { severity: 'Info' },
62
- 'anno-undefined-param': { severity: 'Info' },
58
+ 'anno-undefined-action': { severity: 'Warning' },
59
+ 'anno-undefined-art': { severity: 'Warning' }, // for annotate statement (for CDL path root)
60
+ 'anno-undefined-def': { severity: 'Warning' }, // for annotate statement (for CSN or CDL path cont)
61
+ 'anno-undefined-element': { severity: 'Warning' },
62
+ 'anno-undefined-param': { severity: 'Warning' },
63
63
  'anno-unexpected-ellipsis-layers': { severity: 'Error', configurableFor: true }, // TODO(v3): Merge with anno-unexpected-ellipsis and make non-configurable
64
64
 
65
65
  'args-expected-named': { severity: 'Error', configurableFor: 'deprecated' }, // future --sloppy
@@ -145,6 +145,8 @@ const centralMessages = {
145
145
  // fallback, but then parse.cdl is not supposed to work correctly (it can
146
146
  // then either issue an error or produce a CSN missing some annotations):
147
147
  'syntax-duplicate-annotate': { severity: 'Error', configurableFor: 'v3' },
148
+ 'syntax-duplicate-clause': { severity: 'Error', configurableFor: true },
149
+ 'syntax-duplicate-equal-clause': { severity: 'Warning' },
148
150
  'syntax-invalid-name': { severity: 'Error', configurableFor: 'v3' },
149
151
  'syntax-missing-as': { severity: 'Error', configurableFor: true },
150
152
  'syntax-unexpected-null': { severity: 'Error', configurableFor: true },
@@ -225,14 +227,27 @@ const centralMessageTexts = {
225
227
  'noDollar': 'Option “variableReplacements” does not know $(NAME). Did you forget a leading “$”?'
226
228
  },
227
229
 
228
- 'anno-duplicate': 'Duplicate assignment with $(ANNO)',
229
- 'anno-duplicate-unrelated-layer': 'Duplicate assignment with $(ANNO)',
230
+ 'anno-duplicate': {
231
+ std: 'Duplicate assignment with $(ANNO)',
232
+ doc: 'Duplicate assignment with a doc comment',
233
+ },
234
+ 'anno-duplicate-unrelated-layer': {
235
+ std: 'Duplicate assignment with $(ANNO)',
236
+ doc: 'Duplicate assignment with a doc comment',
237
+ },
230
238
  'anno-unstable-array': 'Unstable order of array items due to repeated assignments for $(ANNO) in unrelated layers',
231
239
  'anno-mismatched-ellipsis': 'An array with $(CODE) can only be used if there is an assignment below with an array value',
232
240
  'anno-unexpected-ellipsis': 'No base annotation available to apply $(CODE)',
233
241
  'anno-unexpected-ellipsis-layers': 'No base annotation available to apply $(CODE)',
234
242
  'chained-array-of': '"Array of"/"many" must not be chained with another "array of"/"many" inside a service',
235
243
 
244
+ 'check-proper-type-of': {
245
+ std: 'Referred element $(NAME) of $(ART) does not contain proper type information',
246
+ derived: 'Referred type of $(ART) does not contain proper type information',
247
+ managedAssocForeignKey: 'Foreign key $(NAME) of managed association $(ART) must have a type',
248
+ managedCompForeignKey: 'Foreign key $(NAME) of managed composition $(ART) must have a type',
249
+ },
250
+
236
251
  'name-duplicate-element': {
237
252
  'std': 'Generated element $(NAME) conflicts with another element',
238
253
  'flatten-element-gen': 'Generated element $(NAME) conflicts with other generated element',
@@ -260,16 +275,20 @@ const centralMessageTexts = {
260
275
  std: 'A safe non-negative integer is expected here',
261
276
  normal: 'A non-negative integer number is expected here',
262
277
  unsafe: 'The provided integer is too large',
263
- csn: 'Expecting a non-negative integer for property $(PROP)'
278
+ csn: 'Expecting a non-negative integer for property $(PROP)',
279
+ 'or-asterisk': 'Expecting a non-negative integer or string $(OP) for property $(PROP)',
264
280
  },
265
281
  'syntax-ignoring-anno': {
266
282
  std: 'Annotations can\'t be used in a column with $(CODE)',
267
283
  doc: 'Doc comments can\'t be used in a column with $(CODE)',
268
284
  },
269
285
  'syntax-invalid-name': {
270
- std: 'Identifier must consist of at least one character',
271
- csn: 'Property name in dictionary $(PARENTPROP) must not be empty',
272
- as: 'String in property $(PROP) must not be empty', // TODO: use
286
+ std: 'Identifier must consist of at least one character', // only via delimited id
287
+ // as: 'String in property $(PROP) must not be empty', // expecting non-empty string is ok
288
+ '{}': 'Property name in structured value must not be empty', // CSN anno val
289
+ dict: 'Property name in dictionary $(PARENTPROP) must not be empty',
290
+ '=': 'The dot-separated name parts in property $(PROP) must not be empty',
291
+ type: 'The dot-separated element name parts in property $(PROP) must not be empty', // CSN v0
273
292
  },
274
293
  'syntax-invalid-literal': {
275
294
  'std': 'Invalid literal value',
@@ -278,6 +297,9 @@ const centralMessageTexts = {
278
297
  'time': 'A time literal must look like ‹hh:mm:ss› or ‹hh:mm› where each letter represents a digit',
279
298
  'date': 'A date literal must look like ‹YYYY-MM-DD› where each letter represents a digit',
280
299
  'timestamp': 'A timestamp literal must look like ‹YYYY-MM-DD hh:mm:ss.u…u› or ‹YYYY-MM-DD hh:mm› where each letter represents a digit, ‹u…u› represents 1 to 7 digits',
300
+ 'number': 'The string value in property $(PROP) does not represent a number',
301
+ 'expecting': 'Expecting literal type $(OP) for the value in property $(OTHERPROP)',
302
+ 'typeof': 'String $(RAWVALUE) is no valid literal type for the string value in property $(OTHERPROP)',
281
303
  },
282
304
  'syntax-missing-ellipsis': 'Expecting an array item $(NEWCODE) after an item with $(CODE)',
283
305
  'syntax-unexpected-ellipsis': {
@@ -298,17 +320,29 @@ const centralMessageTexts = {
298
320
  std: 'Duplicate value for parameter $(NAME)',
299
321
  type: 'Duplicate value for type parameter $(NAME)',
300
322
  },
323
+ 'syntax-duplicate-clause': {
324
+ std: 'You have already provided this clause',
325
+ cardinality: 'You have already provided a target cardinality $(CODE) instead, at line $(LINE), column $(COL)',
326
+ notNull: 'You have already provided $(CODE) instead, at line $(LINE), column $(COL) below',
327
+ },
328
+ 'syntax-duplicate-equal-clause': {
329
+ std: 'You have already provided the same clause',
330
+ cardinality: 'You have already provided the target cardinality $(CODE) at line $(LINE), column $(COL)',
331
+ notNull: 'You have already provided $(CODE) at line $(LINE), column $(COL) below',
332
+ },
301
333
  'syntax-duplicate-extend': {
302
334
  std: 'You can\'t define and refer to $(NAME) repeatedly in the same extend statement',
303
335
  define: 'You can\'t refer to $(NAME) in the same extend statement where it was defined',
304
336
  extend: 'You can\'t refer to $(NAME) repeatedly in the same extend statement',
305
337
  },
306
- // 'syntax-duplicate-anno', 'syntax-duplicate-doc-comment', 'syntax-duplicate-cardinality',
307
- // 'syntax-duplicate-property'
338
+ // 'syntax-duplicate-anno', 'syntax-duplicate-doc-comment', 'syntax-duplicate-property',
339
+ // 'syntax-duplicate-wildcard'
340
+ // 'syntax-ignoring-doc-comment' (Info)
308
341
  'syntax-unexpected-reserved-word': '$(CODE) is a reserved word - write $(DELIMITED) instead if you want to use it as name',
309
342
  'syntax-invalid-text-block': 'Missing newline in text block',
310
343
  // 'syntax-missing-newline' (Warning), 'syntax-missing-as',
311
344
  // 'syntax-missing-token'
345
+ 'syntax-unexpected-extension': 'Unexpected $(KEYWORD) inside $(CODE) block',
312
346
  'syntax-unexpected-null': 'Keyword $(KEYWORD) must appear after the enum definition and not before',
313
347
  'syntax-unexpected-token': {
314
348
  std: 'Mismatched $(OFFENDING), expecting $(EXPECTING)',
@@ -319,10 +353,8 @@ const centralMessageTexts = {
319
353
  service: 'Annotations can\'t be defined inside services',
320
354
  context: 'Annotations can\'t be defined inside contexts',
321
355
  },
322
- // 'syntax-unexpected-space', 'syntax-unexpected-doc-comment' (TODO is: -ignoring-, Info)
323
- // 'syntax-unexpected-alias' (is 'syntax-unexpected-property' in CSN),
324
- // 'syntax-unexpected-right-paren'
325
- 'syntax-unsupported-calc-elem': 'Calculated elements are not supported',
356
+ // 'syntax-unexpected-space' (TODO: also use for :param, #variant, @(…) and @Begin),
357
+ // 'syntax-unexpected-alias' (is 'syntax-unexpected-property' in CSN)
326
358
  'syntax-unsupported-param': {
327
359
  std: 'Parameter not supported', // unused
328
360
  dynamic: 'Dynamic parameter $(CODE) is not supported',
@@ -331,7 +363,6 @@ const centralMessageTexts = {
331
363
  // 'syntax-unsupported-method', 'syntax-unsupported-new'
332
364
 
333
365
  // Syntax messages, CSN parser - default: Error ------------------------------
334
- // TODO: use one id with text variants instead of several message ids
335
366
  'syntax-deprecated-dollar-syntax': {
336
367
  std: 'The property $(PROP) is deprecated; its value is ignored',
337
368
  projection: 'The property $(PROP) is deprecated; use property $(SIBLINGPROP) instead of $(OTHERPROP) for the query',
@@ -349,12 +380,17 @@ const centralMessageTexts = {
349
380
  'zero-replace': 'Replace CSN v0.1.0 value in $(PROP) by $(VALUE)',
350
381
  },
351
382
 
352
- 'syntax-expecting-object': 'Expecting object for property $(PROP)',
353
- 'syntax-expecting-column': 'Expecting object or string \'*\' for property $(PROP)',
354
- 'syntax-expecting-cardinality': 'Expecting non-negative number or string \'*\' for property $(PROP)',
355
- 'syntax-expecting-reference': 'Expecting non-empty string or object for property $(PROP)',
356
- 'syntax-expecting-term': 'Expecting non-empty string or object for property $(PROP)',
357
- // 'syntax-expecting-string', 'syntax-expecting-boolean' (Warning), 'syntax-expecting-scalar',
383
+ 'syntax-expecting-object': {
384
+ std: 'Expecting object for property $(PROP)',
385
+ 'or-asterisk': 'Expecting object or string $(OP) for property $(PROP)',
386
+ 'or-string': 'Expecting object or non-empty string for property $(PROP)',
387
+ },
388
+ 'syntax-expecting-string': {
389
+ std: 'Expecting non-empty string for property $(PROP)',
390
+ 'or-object': 'Expecting non-empty string or object for property $(PROP)',
391
+ 'or-null': 'Expecting non-empty string or null for property $(PROP)',
392
+ },
393
+ // 'syntax-expecting-boolean' (Warning), 'syntax-expecting-scalar',
358
394
  // 'syntax-expecting-args', 'syntax-expecting-translation', 'syntax-expecting-array'
359
395
  'syntax-incomplete-array': { // location at ']'
360
396
  std: 'Expecting array in $(PROP) to have at least $(N) items',
@@ -384,6 +420,18 @@ const centralMessageTexts = {
384
420
  extend: 'CSN property $(PROP) is not expected by an extend in $(PARENTPROP)',
385
421
  annotate: 'CSN property $(PROP) is not expected by an annotate in $(PARENTPROP)',
386
422
  },
423
+ 'syntax-invalid-calc-elem': {
424
+ std: 'Invalid calculated element',
425
+ key: 'A primary key element can\'t be calculated',
426
+ virtual: 'A virtual element can\'t be calculated',
427
+ localized: 'A localized element can\'t be calculated',
428
+ default: 'An element with a default value can\'t be calculated',
429
+ event: 'An event can\'t have calculated elements',
430
+ type: 'A type can\'t have calculated elements',
431
+ action: 'An action can\'t have calculated elements',
432
+ function: 'A function can\'t have calculated elements',
433
+ annotation: 'Annotation definitions can\'t have calculated elements'
434
+ },
387
435
  // 'syntax-unknown-property' (Warning? Better configurable Error)
388
436
 
389
437
  // multi-line strings: --------------------------------------------------------
@@ -403,8 +451,8 @@ const centralMessageTexts = {
403
451
  placeholder: 'Placeholders are not supported. Replace $(CODE) with $(NEWCODE)',
404
452
  },
405
453
 
406
- // Messages for errorneous references -----------------------------------------
407
- // location at errorneous reference (if possible)
454
+ // Messages for erroneous references -----------------------------------------
455
+ // location at erroneous reference (if possible)
408
456
  'ref-unexpected-self': 'Unexpected $(ID) reference; is valid only in ON-conditions',
409
457
  'ref-undefined-def': {
410
458
  std: 'Artifact $(ART) has not been found',
@@ -417,7 +465,8 @@ const centralMessageTexts = {
417
465
  'ref-undefined-element': {
418
466
  std: 'Element $(ART) has not been found',
419
467
  element: 'Artifact $(ART) has no element $(MEMBER)',
420
- aspect: 'Element $(ID) has not been found in the anonymous target aspect'
468
+ aspect: 'Element $(ID) has not been found in the anonymous target aspect',
469
+ virtual: 'Element $(ART) has not been found. Use $(CODE) to add virtual elements in queries'
421
470
  },
422
471
  'ref-undefined-var': {
423
472
  std: 'Variable $(ID) has not been found',
@@ -436,6 +485,25 @@ const centralMessageTexts = {
436
485
  std: 'Expected element reference',
437
486
  magicVar: 'Only elements of magic variable $(ID) can be selected',
438
487
  },
488
+ 'ref-expected-direct-structure': {
489
+ std: '$(ART) can\'t be extended because it originates from an include',
490
+ elements: '$(ART) can\'t be extended by elements/enums because it originates from an include',
491
+ },
492
+ 'ref-unexpected-structured': {
493
+ std: 'Unexpected usage of structured type $(ELEMREF)',
494
+ expr: 'Structured elements can\'t be used in expressions',
495
+ },
496
+ 'ref-unexpected-virtual': {
497
+ std: 'Unexpected reference to virtual element $(NAME)', // "std" currently unused
498
+ expr: 'Virtual elements can\'t be used in expressions',
499
+ fkey: 'Virtual elements can\'t be used as foreign keys for managed associations',
500
+ },
501
+ 'ref-unexpected-assoc': {
502
+ std: 'Unexpected reference to association $(NAME)', // "std" currently unused
503
+ expr: 'Associations can\'t be used as values in expressions',
504
+ cast: 'Casting to an association is not supported',
505
+ },
506
+
439
507
  'type-unexpected-typeof': {
440
508
  std: 'Unexpected $(KEYWORD) for the type reference here',
441
509
  type: 'Unexpected $(KEYWORD) in type of a type definition',
@@ -461,9 +529,11 @@ const centralMessageTexts = {
461
529
  'anno-undefined-def': 'Artifact $(ART) has not been found',
462
530
  'anno-undefined-art': 'No artifact has been found with name $(NAME)',
463
531
  'anno-undefined-element': {
464
- std: 'Element $(ART) has not been found',
465
- element: 'Artifact $(ART) has no element $(MEMBER)',
466
- enum: 'Artifact $(ART) has no enum $(MEMBER)'
532
+ std: 'Element $(NAME) has not been found',
533
+ element: 'Artifact $(ART) has no element $(NAME)',
534
+ enum: 'Artifact $(ART) has no enum $(NAME)',
535
+ returns: 'Return value of $(ART) has no element $(NAME)',
536
+ 'entity-element': 'Elements of entity types can\'t be annotated',
467
537
  },
468
538
  'anno-undefined-action': {
469
539
  std: 'Action $(ART) has not been found',
@@ -486,14 +556,16 @@ const centralMessageTexts = {
486
556
  },
487
557
  'def-unexpected-key': {
488
558
  std: '$(ART) can\'t have additional keys',
559
+ virtual: 'Unexpected $(PROP) for virtual element $(NAME)',
489
560
  // TODO: Better message?
490
- include: '$(ART) can\'t have additional keys (through include)'
561
+ include: '$(ART) can\'t have additional keys (through include)',
491
562
  },
492
563
  'def-unexpected-localized': {
493
564
  std: '$(ART) can\'t have localized elements',
494
565
  // TODO: Better message?
495
566
  include: '$(ART) can\'t have localized elements (through include)',
496
567
  },
568
+ 'def-unexpected-localized-anno': 'Annotations can\'t have localized elements',
497
569
 
498
570
  'def-missing-element': {
499
571
  std: 'Expecting entity to have at least one non-virtual element',
@@ -686,7 +758,7 @@ const centralMessageTexts = {
686
758
  'odata-anno-type': {
687
759
  'std': '$(NAME) is not a known property for $(ANNO) of type $(TYPE)',
688
760
  'unknown': '$(TYPE) is not a known vocabulary type for $(ANNO)',
689
- 'abstract': 'Unexpected abstract type $(TYPE) for $(ANNO)',
761
+ 'abstract': 'Unexpected abstract type $(TYPE) for $(ANNO), use $(CODE) to specify a concrete type',
690
762
  'derived': 'Expected specified $(TYPE) to be derived from $(NAME) for $(ANNO)',
691
763
  },
692
764
  'odata-anno-def': {