@sap/cds-compiler 2.13.8 → 2.15.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 (78) hide show
  1. package/CHANGELOG.md +128 -4
  2. package/bin/cdsc.js +112 -37
  3. package/lib/api/main.js +63 -22
  4. package/lib/api/options.js +2 -3
  5. package/lib/api/validate.js +6 -6
  6. package/lib/base/message-registry.js +100 -17
  7. package/lib/base/messages.js +85 -64
  8. package/lib/base/optionProcessorHelper.js +19 -0
  9. package/lib/checks/annotationsOData.js +11 -32
  10. package/lib/checks/arrayOfs.js +1 -34
  11. package/lib/checks/validator.js +2 -4
  12. package/lib/compiler/assert-consistency.js +1 -0
  13. package/lib/compiler/base.js +1 -0
  14. package/lib/compiler/builtins.js +11 -0
  15. package/lib/compiler/checks.js +22 -70
  16. package/lib/compiler/define.js +59 -11
  17. package/lib/compiler/extend.js +20 -3
  18. package/lib/compiler/finalize-parse-cdl.js +26 -20
  19. package/lib/compiler/index.js +75 -26
  20. package/lib/compiler/populate.js +36 -17
  21. package/lib/compiler/propagator.js +4 -1
  22. package/lib/compiler/resolve.js +104 -16
  23. package/lib/compiler/shared.js +61 -27
  24. package/lib/compiler/tweak-assocs.js +7 -1
  25. package/lib/edm/annotations/genericTranslation.js +93 -21
  26. package/lib/edm/csn2edm.js +216 -98
  27. package/lib/edm/edm.js +305 -226
  28. package/lib/edm/edmPreprocessor.js +499 -423
  29. package/lib/edm/edmUtils.js +22 -22
  30. package/lib/gen/Dictionary.json +98 -22
  31. package/lib/gen/language.checksum +1 -1
  32. package/lib/gen/language.interp +3 -1
  33. package/lib/gen/languageParser.js +4636 -4368
  34. package/lib/json/csnVersion.js +10 -11
  35. package/lib/json/from-csn.js +3 -2
  36. package/lib/json/to-csn.js +0 -2
  37. package/lib/language/docCommentParser.js +2 -2
  38. package/lib/language/genericAntlrParser.js +47 -2
  39. package/lib/language/language.g4 +59 -27
  40. package/lib/main.d.ts +19 -1
  41. package/lib/main.js +6 -0
  42. package/lib/model/csnRefs.js +33 -6
  43. package/lib/model/csnUtils.js +193 -75
  44. package/lib/model/enrichCsn.js +1 -0
  45. package/lib/model/revealInternalProperties.js +2 -2
  46. package/lib/modelCompare/compare.js +6 -6
  47. package/lib/optionProcessor.js +62 -26
  48. package/lib/render/toCdl.js +844 -679
  49. package/lib/render/toHdbcds.js +189 -243
  50. package/lib/render/toSql.js +180 -198
  51. package/lib/render/utils/common.js +131 -15
  52. package/lib/transform/db/.eslintrc.json +1 -1
  53. package/lib/transform/db/associations.js +2 -2
  54. package/lib/transform/db/constraints.js +3 -1
  55. package/lib/transform/db/expansion.js +15 -10
  56. package/lib/transform/db/flattening.js +94 -64
  57. package/lib/transform/db/transformExists.js +7 -7
  58. package/lib/transform/db/views.js +6 -3
  59. package/lib/transform/forHanaNew.js +43 -26
  60. package/lib/transform/forOdataNew.js +43 -42
  61. package/lib/transform/localized.js +12 -7
  62. package/lib/transform/odata/toFinalBaseType.js +8 -6
  63. package/lib/transform/odata/typesExposure.js +145 -197
  64. package/lib/transform/transformUtilsNew.js +9 -12
  65. package/lib/transform/translateAssocsToJoins.js +5 -1
  66. package/lib/transform/universalCsn/coreComputed.js +5 -3
  67. package/lib/transform/universalCsn/universalCsnEnricher.js +27 -5
  68. package/lib/utils/moduleResolve.js +13 -6
  69. package/package.json +1 -1
  70. package/share/messages/message-explanations.json +2 -1
  71. package/share/messages/syntax-expected-integer.md +37 -0
  72. package/lib/transform/odata/attachPath.js +0 -96
  73. package/lib/transform/odata/expandStructKeysInAssociations.js +0 -59
  74. package/lib/transform/odata/generateForeignKeyElements.js +0 -261
  75. package/lib/transform/odata/referenceFlattener.js +0 -296
  76. package/lib/transform/odata/sortByAssociationDependency.js +0 -105
  77. package/lib/transform/odata/structuralPath.js +0 -72
  78. package/lib/transform/odata/structureFlattener.js +0 -171
@@ -401,7 +401,7 @@ function finalizeReferentialConstraints(csn, assocCsn, options, info)
401
401
  if(options.isV2() && intersect(renderedKeys, remainingPrincipalRefs).length !== renderedKeys.length)
402
402
  if(options.odataV2PartialConstr) {
403
403
  info('odata-spec-violation-constraints',
404
- ['definitions', assocCsn._parent.name, 'elements', assocCsn.name], { api: 'OData V2' });
404
+ ['definitions', assocCsn._parent.name, 'elements', assocCsn.name], { version: '2.0' });
405
405
  }
406
406
  else {
407
407
  assocCsn._constraints.constraints = {};
@@ -439,7 +439,7 @@ function finalizeReferentialConstraints(csn, assocCsn, options, info)
439
439
  if(options.isV2() && intersect(renderedKeys, remainingPrincipalRefs).length !== renderedKeys.length) {
440
440
  if(options.odataV2PartialConstr) {
441
441
  info('odata-spec-violation-constraints',
442
- ['definitions', assocCsn._parent.name, 'elements', assocCsn.name], { api: 'OData V2' } );
442
+ ['definitions', assocCsn._parent.name, 'elements', assocCsn.name], { version: '2.0' } );
443
443
  }
444
444
  else {
445
445
  assocCsn._constraints.constraints = {};
@@ -467,7 +467,7 @@ function finalizeReferentialConstraints(csn, assocCsn, options, info)
467
467
  return (elt &&
468
468
  elt.type &&
469
469
  (!options.isFlatFormat || options.isFlatFormat && isBuiltinType(elt.type)) &&
470
- !['cds.Association', 'cds.Composition'].includes(elt.type) &&
470
+ !(elt.type === 'cds.Association' || elt.type === 'cds.Composition') &&
471
471
  isEdmPropertyRendered(elt, options));
472
472
  }
473
473
  }
@@ -522,12 +522,14 @@ function determineMultiplicity(csn)
522
522
  return [srcCardinality, tgtCardinality];
523
523
  }
524
524
 
525
- function mapCdsToEdmType(csn, messageFunctions, isV2=false, isMediaType=false)
525
+ function mapCdsToEdmType(csn, messageFunctions, isV2=false, isMediaType=false, location=undefined)
526
526
  {
527
+ if(location === undefined)
528
+ location = csn.$path;
527
529
  const { error } = messageFunctions || { error: ()=>true };
528
530
  let cdsType = csn.type;
529
531
  if(cdsType === undefined) {
530
- error(null, csn.$location, `no type found`);
532
+ error(null, location, `no type found`);
531
533
  return '<NOTYPE>';
532
534
  }
533
535
  if(!isBuiltinType(cdsType))
@@ -582,7 +584,7 @@ function mapCdsToEdmType(csn, messageFunctions, isV2=false, isMediaType=false)
582
584
  */
583
585
  }[cdsType];
584
586
  if (edmType == undefined) {
585
- error(null, csn.$path, { type: cdsType }, `No EDM type available for $(TYPE)`);
587
+ error(null, location, { type: cdsType }, `No EDM type available for $(TYPE)`);
586
588
  }
587
589
  if(isV2)
588
590
  {
@@ -590,9 +592,6 @@ function mapCdsToEdmType(csn, messageFunctions, isV2=false, isMediaType=false)
590
592
  edmType = 'Edm.DateTime';
591
593
  if (edmType === 'Edm.TimeOfDay')
592
594
  edmType = 'Edm.Time';
593
- if(['cds.hana.ST_POINT', 'cds.hana.ST_GEOMETRY'].includes(cdsType)) {
594
- error(null, csn.$path, { type: cdsType }, `OData V2 does not support Geometry data types, $(TYPE) can't be mapped`);
595
- }
596
595
  }
597
596
  else // isV4
598
597
  {
@@ -606,31 +605,32 @@ function mapCdsToEdmType(csn, messageFunctions, isV2=false, isMediaType=false)
606
605
  function addTypeFacets(node, csn)
607
606
  {
608
607
  const isV2 = node.v2;
608
+ const decimalTypes = {'cds.Decimal':1, 'cds.DecimalFloat':1, 'cds.hana.SMALLDECIMAL':1};
609
609
  if (csn.length != null)
610
- node.MaxLength = csn.length;
610
+ node.setEdmAttribute('MaxLength', csn.length);
611
611
  if (csn.scale !== undefined)
612
- node.Scale = csn.scale;
612
+ node.setEdmAttribute('Scale', csn.scale);
613
613
  // else if (csn.type === 'cds.hana.SMALLDECIMAL' && !isV2)
614
- // node.Scale = 'floating';
614
+ // node._edmAttributes.Scale = 'floating';
615
615
 
616
616
  if (csn.precision != null)
617
- node.Precision = csn.precision;
617
+ node.setEdmAttribute('Precision', csn.precision);
618
618
  // else if (csn.type === 'cds.hana.SMALLDECIMAL' && !isV2)
619
619
  // node.Precision = 16;
620
- else if (csn.type === 'cds.Timestamp' && node.Type === 'Edm.DateTimeOffset')
621
- node.Precision = 7;
622
- if([ 'cds.Decimal', 'cds.DecimalFloat', 'cds.hana.SMALLDECIMAL' ].includes(csn.type)) {
620
+ else if (csn.type === 'cds.Timestamp' && node._edmAttributes.Type === 'Edm.DateTimeOffset')
621
+ node.setEdmAttribute('Precision', 7);
622
+ if(csn.type in decimalTypes) {
623
623
  if(isV2) {
624
624
  // no prec/scale or scale is 'floating'/'variable'
625
- if(!(csn.precision || csn.scale) || ['floating', 'variable'].includes(csn.scale)) {
625
+ if(!(csn.precision || csn.scale) || (csn.scale === 'floating' || csn.scale === 'variable')) {
626
626
  node.setXml( { 'sap:variable-scale': true } );
627
- delete node.Scale;
627
+ node.removeEdmAttribute('Scale');
628
628
  }
629
629
  }
630
630
  else {
631
631
  // map both floating and variable to => variable
632
- if(node.Scale === 'floating')
633
- node.Scale = 'variable';
632
+ if(node._edmAttributes.Scale === 'floating')
633
+ node.setEdmAttribute('Scale', 'variable');
634
634
  if(!csn.precision && !csn.scale)
635
635
  // if Decimal has no p, s set scale 'variable'
636
636
  node.setXml( { Scale: 'variable' } ); // floating is V4.01
@@ -638,9 +638,9 @@ function addTypeFacets(node, csn)
638
638
  }
639
639
  // Unicode unused today
640
640
  if(csn.unicode)
641
- node.Unicode = csn.unicode;
641
+ node.setEdmAttribute('Unicode', csn.unicode);
642
642
  if(csn.srid)
643
- node.SRID = csn.srid;
643
+ node.setEdmAttribute('SRID', csn.srid);
644
644
  }
645
645
 
646
646
 
@@ -658,6 +658,7 @@
658
658
  "Type": "Common.FieldControlType",
659
659
  "AppliesTo": [
660
660
  "Property",
661
+ "Parameter",
661
662
  "Record",
662
663
  "EntityType"
663
664
  ]
@@ -1026,7 +1027,9 @@
1026
1027
  ]
1027
1028
  },
1028
1029
  "Common.RecursiveHierarchy": {
1029
- "Type": "Common.RecursiveHierarchyType"
1030
+ "Type": "Common.RecursiveHierarchyType",
1031
+ "$deprecated": true,
1032
+ "$deprecationText": "Use terms [Aggregation.RecursiveHierarchy](https://github.com/oasis-tcs/odata-vocabularies/blob/main/vocabularies/Org.OData.Aggregation.V1.md#RecursiveHierarchy) and [Hierarchy.RecursiveHierarchy](https://github.com/SAP/odata-vocabularies/blob/main/vocabularies/Hierarchy.md#RecursiveHierarchy) instead"
1030
1033
  },
1031
1034
  "Common.CreatedAt": {
1032
1035
  "Type": "Edm.DateTimeOffset",
@@ -1380,8 +1383,49 @@
1380
1383
  "Core.GeometryFeature": {
1381
1384
  "Type": "Core.GeometryFeatureType"
1382
1385
  },
1383
- "Graph.links": {
1384
- "Type": "Collection(Graph.link)",
1386
+ "DataIntegration.Extractable": {
1387
+ "Type": "Edm.Boolean",
1388
+ "AppliesTo": [
1389
+ "EntitySet"
1390
+ ]
1391
+ },
1392
+ "DataIntegration.OriginalDataType": {
1393
+ "Type": "Edm.String",
1394
+ "AppliesTo": [
1395
+ "Property"
1396
+ ]
1397
+ },
1398
+ "DataIntegration.OriginalName": {
1399
+ "Type": "Edm.String"
1400
+ },
1401
+ "DataIntegration.ConversionExit": {
1402
+ "Type": "Edm.String",
1403
+ "AppliesTo": [
1404
+ "Property"
1405
+ ]
1406
+ },
1407
+ "DataIntegration.SourceSystem": {
1408
+ "Type": "Edm.String",
1409
+ "AppliesTo": [
1410
+ "Container"
1411
+ ]
1412
+ },
1413
+ "DataIntegration.DeltaMethod": {
1414
+ "Type": "DataIntegration.DeltaMethodType",
1415
+ "AppliesTo": [
1416
+ "EntitySet"
1417
+ ]
1418
+ },
1419
+ "Graph.traceId": {
1420
+ "Type": "Edm.String",
1421
+ "$experimental": true
1422
+ },
1423
+ "Graph.Details": {
1424
+ "Type": "Graph.DetailsType",
1425
+ "$experimental": true
1426
+ },
1427
+ "Hierarchy.RecursiveHierarchy": {
1428
+ "Type": "Hierarchy.RecursiveHierarchyType",
1385
1429
  "AppliesTo": [
1386
1430
  "EntityType"
1387
1431
  ],
@@ -1393,6 +1437,17 @@
1393
1437
  "Record"
1394
1438
  ]
1395
1439
  },
1440
+ "JSON.Schema": {
1441
+ "Type": "JSON.JSON",
1442
+ "AppliesTo": [
1443
+ "EntityType",
1444
+ "Parameter",
1445
+ "Property",
1446
+ "ReturnType",
1447
+ "Term",
1448
+ "TypeDefinition"
1449
+ ]
1450
+ },
1396
1451
  "Measures.ISOCurrency": {
1397
1452
  "Type": "Edm.String",
1398
1453
  "AppliesTo": [
@@ -1713,7 +1768,8 @@
1713
1768
  "Type": "Core.Tag",
1714
1769
  "AppliesTo": [
1715
1770
  "Property",
1716
- "PropertyValue"
1771
+ "PropertyValue",
1772
+ "Parameter"
1717
1773
  ]
1718
1774
  },
1719
1775
  "UI.Placeholder": {
@@ -1898,14 +1954,14 @@
1898
1954
  ]
1899
1955
  },
1900
1956
  "Validation.OpenPropertyTypeConstraint": {
1901
- "Type": "Collection(Core.QualifiedTypeName)",
1957
+ "Type": "Collection(Validation.SingleOrCollectionType)",
1902
1958
  "AppliesTo": [
1903
1959
  "ComplexType",
1904
1960
  "EntityType"
1905
1961
  ]
1906
1962
  },
1907
1963
  "Validation.DerivedTypeConstraint": {
1908
- "Type": "Collection(Core.QualifiedTypeName)",
1964
+ "Type": "Collection(Validation.SingleOrCollectionType)",
1909
1965
  "AppliesTo": [
1910
1966
  "EntitySet",
1911
1967
  "Singleton",
@@ -2740,7 +2796,9 @@
2740
2796
  "ExternalNodeKeyProperty": "Edm.PropertyPath",
2741
2797
  "NodeDescendantCountProperty": "Edm.PropertyPath",
2742
2798
  "NodeDrillStateProperty": "Edm.PropertyPath"
2743
- }
2799
+ },
2800
+ "$deprecated": true,
2801
+ "$deprecationText": "Use terms [Aggregation.RecursiveHierarchy](https://github.com/oasis-tcs/odata-vocabularies/blob/main/vocabularies/Org.OData.Aggregation.V1.md#RecursiveHierarchy) and [Hierarchy.RecursiveHierarchy](https://github.com/SAP/odata-vocabularies/blob/main/vocabularies/Hierarchy.md#RecursiveHierarchy) instead"
2744
2802
  },
2745
2803
  "Common.NumericMessageSeverityType": {
2746
2804
  "$kind": "TypeDefinition",
@@ -3122,22 +3180,31 @@
3122
3180
  "UnderlyingType": "Edm.String",
3123
3181
  "MaxLength": "128"
3124
3182
  },
3125
- "Graph.link": {
3183
+ "DataIntegration.DeltaMethodType": {
3184
+ "$kind": "EnumType",
3185
+ "IsFlags": "true",
3186
+ "Members": [
3187
+ "INSERT",
3188
+ "UPDATE",
3189
+ "DELETE"
3190
+ ]
3191
+ },
3192
+ "Graph.DetailsType": {
3126
3193
  "$kind": "ComplexType",
3127
3194
  "Properties": {
3128
- "title": "Edm.String",
3129
- "alias": "Edm.String",
3130
- "target": "Edm.String",
3131
- "parameters": "Collection(Graph.binding)",
3132
- "filter": "Collection(Graph.binding)"
3195
+ "url": "Edm.String",
3196
+ "body": "JSON.JSON"
3133
3197
  },
3134
3198
  "$experimental": true
3135
3199
  },
3136
- "Graph.binding": {
3200
+ "Hierarchy.RecursiveHierarchyType": {
3137
3201
  "$kind": "ComplexType",
3138
3202
  "Properties": {
3139
- "source": "Edm.PropertyPath",
3140
- "target": "Edm.PropertyPath"
3203
+ "ExternalKeyProperty": "Edm.PropertyPath",
3204
+ "DescendantCountProperty": "Edm.PropertyPath",
3205
+ "DrillStateProperty": "Edm.PropertyPath",
3206
+ "SiblingRankProperty": "Edm.PropertyPath",
3207
+ "PreorderRankProperty": "Edm.PropertyPath"
3141
3208
  },
3142
3209
  "$experimental": true
3143
3210
  },
@@ -3147,6 +3214,10 @@
3147
3214
  "width": "Edm.String"
3148
3215
  }
3149
3216
  },
3217
+ "JSON.JSON": {
3218
+ "$kind": "TypeDefinition",
3219
+ "UnderlyingType": "Edm.Stream"
3220
+ },
3150
3221
  "Measures.DurationGranularityType": {
3151
3222
  "$kind": "TypeDefinition",
3152
3223
  "UnderlyingType": "Edm.String"
@@ -3176,6 +3247,7 @@
3176
3247
  "TypeNamePlural": "Edm.String",
3177
3248
  "Title": "UI.DataFieldAbstract",
3178
3249
  "Description": "UI.DataFieldAbstract",
3250
+ "Image": "Edm.Stream",
3179
3251
  "ImageUrl": "Edm.String",
3180
3252
  "TypeImageUrl": "Edm.String",
3181
3253
  "Initials": "Edm.String"
@@ -3623,7 +3695,7 @@
3623
3695
  "$kind": "ComplexType",
3624
3696
  "BaseType": "UI.DataFieldAbstract",
3625
3697
  "Properties": {
3626
- "Value": "Edm.PrimitiveType",
3698
+ "Value": "Edm.Untyped",
3627
3699
  "Label": "Edm.String",
3628
3700
  "Criticality": "UI.CriticalityType",
3629
3701
  "CriticalityRepresentation": "UI.CriticalityRepresentationType",
@@ -3634,8 +3706,8 @@
3634
3706
  "$kind": "ComplexType",
3635
3707
  "BaseType": "UI.DataField",
3636
3708
  "Properties": {
3637
- "Action": "Common.QualifiedName",
3638
3709
  "Value": "Edm.PrimitiveType",
3710
+ "Action": "Common.QualifiedName",
3639
3711
  "Label": "Edm.String",
3640
3712
  "Criticality": "UI.CriticalityType",
3641
3713
  "CriticalityRepresentation": "UI.CriticalityRepresentationType",
@@ -3646,10 +3718,10 @@
3646
3718
  "$kind": "ComplexType",
3647
3719
  "BaseType": "UI.DataField",
3648
3720
  "Properties": {
3721
+ "Value": "Edm.PrimitiveType",
3649
3722
  "SemanticObject": "Edm.String",
3650
3723
  "Action": "Edm.String",
3651
3724
  "Mapping": "Collection(Common.SemanticObjectMappingType)",
3652
- "Value": "Edm.PrimitiveType",
3653
3725
  "Label": "Edm.String",
3654
3726
  "Criticality": "UI.CriticalityType",
3655
3727
  "CriticalityRepresentation": "UI.CriticalityRepresentationType",
@@ -3660,8 +3732,8 @@
3660
3732
  "$kind": "ComplexType",
3661
3733
  "BaseType": "UI.DataField",
3662
3734
  "Properties": {
3663
- "Target": "Edm.NavigationPropertyPath",
3664
3735
  "Value": "Edm.PrimitiveType",
3736
+ "Target": "Edm.NavigationPropertyPath",
3665
3737
  "Label": "Edm.String",
3666
3738
  "Criticality": "UI.CriticalityType",
3667
3739
  "CriticalityRepresentation": "UI.CriticalityRepresentationType",
@@ -3672,9 +3744,9 @@
3672
3744
  "$kind": "ComplexType",
3673
3745
  "BaseType": "UI.DataField",
3674
3746
  "Properties": {
3747
+ "Value": "Edm.PrimitiveType",
3675
3748
  "Url": "Edm.String",
3676
3749
  "UrlContentType": "Edm.String",
3677
- "Value": "Edm.PrimitiveType",
3678
3750
  "Label": "Edm.String",
3679
3751
  "Criticality": "UI.CriticalityType",
3680
3752
  "CriticalityRepresentation": "UI.CriticalityRepresentationType",
@@ -3685,8 +3757,8 @@
3685
3757
  "$kind": "ComplexType",
3686
3758
  "BaseType": "UI.DataField",
3687
3759
  "Properties": {
3688
- "Actions": "Collection(UI.DataField)",
3689
3760
  "Value": "Edm.PrimitiveType",
3761
+ "Actions": "Collection(UI.DataField)",
3690
3762
  "Label": "Edm.String",
3691
3763
  "Criticality": "UI.CriticalityType",
3692
3764
  "CriticalityRepresentation": "UI.CriticalityRepresentationType",
@@ -3901,6 +3973,10 @@
3901
3973
  "path": "Edm.NavigationPropertyPath",
3902
3974
  "target": "Edm.NavigationPropertyPath"
3903
3975
  }
3976
+ },
3977
+ "Validation.SingleOrCollectionType": {
3978
+ "$kind": "TypeDefinition",
3979
+ "UnderlyingType": "Edm.String"
3904
3980
  }
3905
3981
  }
3906
3982
  }
@@ -1 +1 @@
1
- 78ff41e0af1a8064856dea9850968eb6
1
+ 351a6ed427f91f2eef4d8e9a2e11dd17