@sap/cds-compiler 2.13.8 → 2.15.2

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 +109 -4
  2. package/bin/cdsc.js +112 -37
  3. package/lib/api/main.js +20 -22
  4. package/lib/api/options.js +2 -3
  5. package/lib/api/validate.js +6 -6
  6. package/lib/base/message-registry.js +89 -14
  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 +6 -5
  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 +33 -15
  26. package/lib/edm/csn2edm.js +216 -98
  27. package/lib/edm/edm.js +298 -225
  28. package/lib/edm/edmPreprocessor.js +486 -415
  29. package/lib/edm/edmUtils.js +22 -22
  30. package/lib/gen/Dictionary.json +90 -16
  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 +5 -5
  63. package/lib/transform/odata/typesExposure.js +145 -197
  64. package/lib/transform/transformUtilsNew.js +9 -12
  65. package/lib/transform/translateAssocsToJoins.js +1 -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
 
@@ -1026,7 +1026,9 @@
1026
1026
  ]
1027
1027
  },
1028
1028
  "Common.RecursiveHierarchy": {
1029
- "Type": "Common.RecursiveHierarchyType"
1029
+ "Type": "Common.RecursiveHierarchyType",
1030
+ "$deprecated": true,
1031
+ "$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
1032
  },
1031
1033
  "Common.CreatedAt": {
1032
1034
  "Type": "Edm.DateTimeOffset",
@@ -1380,8 +1382,49 @@
1380
1382
  "Core.GeometryFeature": {
1381
1383
  "Type": "Core.GeometryFeatureType"
1382
1384
  },
1383
- "Graph.links": {
1384
- "Type": "Collection(Graph.link)",
1385
+ "DataIntegration.Extractable": {
1386
+ "Type": "Edm.Boolean",
1387
+ "AppliesTo": [
1388
+ "EntitySet"
1389
+ ]
1390
+ },
1391
+ "DataIntegration.OriginalDataType": {
1392
+ "Type": "Edm.String",
1393
+ "AppliesTo": [
1394
+ "Property"
1395
+ ]
1396
+ },
1397
+ "DataIntegration.OriginalName": {
1398
+ "Type": "Edm.String"
1399
+ },
1400
+ "DataIntegration.ConversionExit": {
1401
+ "Type": "Edm.String",
1402
+ "AppliesTo": [
1403
+ "Property"
1404
+ ]
1405
+ },
1406
+ "DataIntegration.SourceSystem": {
1407
+ "Type": "Edm.String",
1408
+ "AppliesTo": [
1409
+ "Container"
1410
+ ]
1411
+ },
1412
+ "DataIntegration.DeltaMethod": {
1413
+ "Type": "DataIntegration.DeltaMethodType",
1414
+ "AppliesTo": [
1415
+ "EntitySet"
1416
+ ]
1417
+ },
1418
+ "Graph.traceId": {
1419
+ "Type": "Edm.String",
1420
+ "$experimental": true
1421
+ },
1422
+ "Graph.Details": {
1423
+ "Type": "Graph.DetailsType",
1424
+ "$experimental": true
1425
+ },
1426
+ "Hierarchy.RecursiveHierarchy": {
1427
+ "Type": "Hierarchy.RecursiveHierarchyType",
1385
1428
  "AppliesTo": [
1386
1429
  "EntityType"
1387
1430
  ],
@@ -1393,6 +1436,17 @@
1393
1436
  "Record"
1394
1437
  ]
1395
1438
  },
1439
+ "JSON.Schema": {
1440
+ "Type": "JSON.JSON",
1441
+ "AppliesTo": [
1442
+ "EntityType",
1443
+ "Parameter",
1444
+ "Property",
1445
+ "ReturnType",
1446
+ "Term",
1447
+ "TypeDefinition"
1448
+ ]
1449
+ },
1396
1450
  "Measures.ISOCurrency": {
1397
1451
  "Type": "Edm.String",
1398
1452
  "AppliesTo": [
@@ -1713,7 +1767,8 @@
1713
1767
  "Type": "Core.Tag",
1714
1768
  "AppliesTo": [
1715
1769
  "Property",
1716
- "PropertyValue"
1770
+ "PropertyValue",
1771
+ "Parameter"
1717
1772
  ]
1718
1773
  },
1719
1774
  "UI.Placeholder": {
@@ -1898,14 +1953,14 @@
1898
1953
  ]
1899
1954
  },
1900
1955
  "Validation.OpenPropertyTypeConstraint": {
1901
- "Type": "Collection(Core.QualifiedTypeName)",
1956
+ "Type": "Collection(Validation.SingleOrCollectionType)",
1902
1957
  "AppliesTo": [
1903
1958
  "ComplexType",
1904
1959
  "EntityType"
1905
1960
  ]
1906
1961
  },
1907
1962
  "Validation.DerivedTypeConstraint": {
1908
- "Type": "Collection(Core.QualifiedTypeName)",
1963
+ "Type": "Collection(Validation.SingleOrCollectionType)",
1909
1964
  "AppliesTo": [
1910
1965
  "EntitySet",
1911
1966
  "Singleton",
@@ -2740,7 +2795,9 @@
2740
2795
  "ExternalNodeKeyProperty": "Edm.PropertyPath",
2741
2796
  "NodeDescendantCountProperty": "Edm.PropertyPath",
2742
2797
  "NodeDrillStateProperty": "Edm.PropertyPath"
2743
- }
2798
+ },
2799
+ "$deprecated": true,
2800
+ "$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
2801
  },
2745
2802
  "Common.NumericMessageSeverityType": {
2746
2803
  "$kind": "TypeDefinition",
@@ -3122,22 +3179,31 @@
3122
3179
  "UnderlyingType": "Edm.String",
3123
3180
  "MaxLength": "128"
3124
3181
  },
3125
- "Graph.link": {
3182
+ "DataIntegration.DeltaMethodType": {
3183
+ "$kind": "EnumType",
3184
+ "IsFlags": "true",
3185
+ "Members": [
3186
+ "INSERT",
3187
+ "UPDATE",
3188
+ "DELETE"
3189
+ ]
3190
+ },
3191
+ "Graph.DetailsType": {
3126
3192
  "$kind": "ComplexType",
3127
3193
  "Properties": {
3128
- "title": "Edm.String",
3129
- "alias": "Edm.String",
3130
- "target": "Edm.String",
3131
- "parameters": "Collection(Graph.binding)",
3132
- "filter": "Collection(Graph.binding)"
3194
+ "url": "Edm.String",
3195
+ "body": "JSON.JSON"
3133
3196
  },
3134
3197
  "$experimental": true
3135
3198
  },
3136
- "Graph.binding": {
3199
+ "Hierarchy.RecursiveHierarchyType": {
3137
3200
  "$kind": "ComplexType",
3138
3201
  "Properties": {
3139
- "source": "Edm.PropertyPath",
3140
- "target": "Edm.PropertyPath"
3202
+ "ExternalKeyProperty": "Edm.PropertyPath",
3203
+ "DescendantCountProperty": "Edm.PropertyPath",
3204
+ "DrillStateProperty": "Edm.PropertyPath",
3205
+ "SiblingRankProperty": "Edm.PropertyPath",
3206
+ "PreorderRankProperty": "Edm.PropertyPath"
3141
3207
  },
3142
3208
  "$experimental": true
3143
3209
  },
@@ -3147,6 +3213,10 @@
3147
3213
  "width": "Edm.String"
3148
3214
  }
3149
3215
  },
3216
+ "JSON.JSON": {
3217
+ "$kind": "TypeDefinition",
3218
+ "UnderlyingType": "Edm.Stream"
3219
+ },
3150
3220
  "Measures.DurationGranularityType": {
3151
3221
  "$kind": "TypeDefinition",
3152
3222
  "UnderlyingType": "Edm.String"
@@ -3901,6 +3971,10 @@
3901
3971
  "path": "Edm.NavigationPropertyPath",
3902
3972
  "target": "Edm.NavigationPropertyPath"
3903
3973
  }
3974
+ },
3975
+ "Validation.SingleOrCollectionType": {
3976
+ "$kind": "TypeDefinition",
3977
+ "UnderlyingType": "Edm.String"
3904
3978
  }
3905
3979
  }
3906
3980
  }
@@ -1 +1 @@
1
- 78ff41e0af1a8064856dea9850968eb6
1
+ 351a6ed427f91f2eef4d8e9a2e11dd17