@sap/cds-compiler 4.6.2 → 4.7.4

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 (69) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/bin/cds_update_identifiers.js +6 -2
  3. package/bin/cdsc.js +1 -1
  4. package/doc/CHANGELOG_ARCHIVE.md +9 -9
  5. package/doc/CHANGELOG_BETA.md +6 -0
  6. package/lib/api/main.js +56 -9
  7. package/lib/api/options.js +6 -3
  8. package/lib/api/validate.js +20 -29
  9. package/lib/base/message-registry.js +27 -3
  10. package/lib/base/messages.js +8 -3
  11. package/lib/base/model.js +2 -0
  12. package/lib/checks/dbFeatureFlags.js +28 -0
  13. package/lib/checks/elements.js +81 -13
  14. package/lib/checks/enricher.js +3 -2
  15. package/lib/checks/validator.js +38 -4
  16. package/lib/compiler/assert-consistency.js +4 -4
  17. package/lib/compiler/checks.js +5 -4
  18. package/lib/compiler/define.js +2 -2
  19. package/lib/compiler/generate.js +2 -1
  20. package/lib/compiler/propagator.js +3 -11
  21. package/lib/compiler/shared.js +2 -1
  22. package/lib/compiler/tweak-assocs.js +43 -24
  23. package/lib/edm/annotations/edmJson.js +3 -0
  24. package/lib/edm/annotations/genericTranslation.js +156 -106
  25. package/lib/edm/annotations/preprocessAnnotations.js +11 -14
  26. package/lib/edm/csn2edm.js +27 -24
  27. package/lib/edm/edm.js +8 -8
  28. package/lib/edm/edmPreprocessor.js +135 -37
  29. package/lib/edm/edmUtils.js +20 -7
  30. package/lib/gen/Dictionary.json +1 -0
  31. package/lib/gen/language.checksum +1 -1
  32. package/lib/gen/language.interp +9 -11
  33. package/lib/gen/languageParser.js +5942 -5446
  34. package/lib/json/to-csn.js +7 -114
  35. package/lib/language/genericAntlrParser.js +106 -48
  36. package/lib/model/cloneCsn.js +203 -0
  37. package/lib/model/csnRefs.js +11 -3
  38. package/lib/model/csnUtils.js +42 -85
  39. package/lib/optionProcessor.js +2 -2
  40. package/lib/render/manageConstraints.js +1 -1
  41. package/lib/render/toCdl.js +133 -88
  42. package/lib/render/toHdbcds.js +1 -5
  43. package/lib/render/toSql.js +7 -9
  44. package/lib/render/utils/common.js +9 -16
  45. package/lib/transform/addTenantFields.js +277 -102
  46. package/lib/transform/db/applyTransformations.js +14 -9
  47. package/lib/transform/db/backlinks.js +2 -1
  48. package/lib/transform/db/constraints.js +60 -82
  49. package/lib/transform/db/expansion.js +6 -6
  50. package/lib/transform/db/featureFlags.js +5 -0
  51. package/lib/transform/db/flattening.js +4 -4
  52. package/lib/transform/db/killAnnotations.js +1 -0
  53. package/lib/transform/db/rewriteCalculatedElements.js +2 -2
  54. package/lib/transform/db/transformExists.js +12 -0
  55. package/lib/transform/db/views.js +5 -2
  56. package/lib/transform/draft/odata.js +7 -6
  57. package/lib/transform/effective/associations.js +2 -1
  58. package/lib/transform/effective/main.js +3 -2
  59. package/lib/transform/effective/types.js +6 -3
  60. package/lib/transform/forOdata.js +39 -24
  61. package/lib/transform/forRelationalDB.js +34 -27
  62. package/lib/transform/localized.js +29 -9
  63. package/lib/transform/odata/flattening.js +419 -0
  64. package/lib/transform/odata/toFinalBaseType.js +95 -15
  65. package/lib/transform/odata/typesExposure.js +9 -7
  66. package/lib/transform/transformUtils.js +7 -6
  67. package/lib/transform/translateAssocsToJoins.js +3 -3
  68. package/lib/utils/objectUtils.js +14 -0
  69. package/package.json +1 -1
@@ -7,10 +7,11 @@
7
7
  const { setProp } = require('../base/model');
8
8
 
9
9
  const { copyAnnotations, applyTransformations, isDollarSelfOrProjectionOperand } = require('../model/csnUtils');
10
- const { cloneCsnNonDict, cloneCsnDictionary, getUtils } = require('../model/csnUtils');
10
+ const { getUtils } = require('../model/csnUtils');
11
11
  const { typeParameters, isBuiltinType } = require('../compiler/builtins');
12
12
  const { ModelError, CompilerAssertion} = require('../base/error');
13
13
  const { forEach } = require('../utils/objectUtils');
14
+ const { cloneCsnNonDict, cloneCsnDict } = require('../model/cloneCsn');
14
15
 
15
16
  const RestrictedOperators = ['<', '>', '>=', '<='];
16
17
  const RelationalOperators = ['=', '!=', '<>', 'is' /*, 'like'*/,...RestrictedOperators];
@@ -341,13 +342,13 @@ function getTransformers(model, options, msgFunctions, pathDelimiter = '_') {
341
342
 
342
343
  // Don't process a leading $self - it will a .art with .elements!
343
344
  let i = scope === '$self' ? 1 : 0;
344
-
345
+
345
346
  // read property from resolved path link
346
347
  const art = (propName) =>
347
348
  (links[i].art?.[propName] ||
348
349
  effectiveType(links[i].art)[propName] ||
349
350
  (resolvedLinkTypes.get(links[i])||{})[propName]);
350
-
351
+
351
352
  let flattenStep = false;
352
353
  let nextIsItems = !!art('items') || (refParentIsItems && i === 0);
353
354
  for(; i < links.length; i++) {
@@ -370,7 +371,7 @@ function getTransformers(model, options, msgFunctions, pathDelimiter = '_') {
370
371
  if(nextIsItems && art('target'))
371
372
  nextIsItems = false;
372
373
 
373
- flattenStep = !links[i].art?.kind &&
374
+ flattenStep = !links[i].art?.kind &&
374
375
  !links[i].art?.SELECT &&
375
376
  !links[i].art?.from &&
376
377
  art('elements');
@@ -441,7 +442,7 @@ function getTransformers(model, options, msgFunctions, pathDelimiter = '_') {
441
442
  // since it must also be structured and must contain at least as many elements,
442
443
  // if not more (in client style CSN).
443
444
  if (typeRef.elements && !(options.transformation === 'hdbcds' && options.sqlMapping === 'hdbcds'))
444
- nodeWithType.elements = cloneCsnDictionary(typeRef.elements, options);
445
+ nodeWithType.elements = cloneCsnDict(typeRef.elements, options);
445
446
  else if (typeRef.items)
446
447
  nodeWithType.items = cloneCsnNonDict(typeRef.items, options);
447
448
 
@@ -449,7 +450,7 @@ function getTransformers(model, options, msgFunctions, pathDelimiter = '_') {
449
450
  }
450
451
 
451
452
  if (typeRef.enum && nodeWithType.enum === undefined)
452
- nodeWithType.enum = cloneCsnDictionary(typeRef.enum, options);
453
+ nodeWithType.enum = cloneCsnDict(typeRef.enum, options);
453
454
 
454
455
  // Copy type and type arguments (+ localized)
455
456
 
@@ -55,7 +55,7 @@ function translateAssocsToJoinsCSN(csn, options){
55
55
 
56
56
  function translateAssocsToJoins(model, inputOptions = {})
57
57
  {
58
- const { error, warning, throwWithError } = makeMessageFunction(model, inputOptions);
58
+ const { error, warning, throwWithError } = makeMessageFunction(model, inputOptions, 'a2j');
59
59
 
60
60
  const options = model.options || inputOptions;
61
61
 
@@ -495,7 +495,7 @@ function translateAssocsToJoins(model, inputOptions = {})
495
495
  let srcTableAlias = constructTableAliasPathStep(assocSourceQA);
496
496
  let tgtTableAlias = constructTableAliasPathStep(assocQAT.$QA);
497
497
 
498
- node.on = createOnCondition(assoc, srcTableAlias, tgtTableAlias, options.tenantAsColumn);
498
+ node.on = createOnCondition(assoc, srcTableAlias, tgtTableAlias, options.tenantDiscriminator);
499
499
 
500
500
  if(assocQAT._filter)
501
501
  {
@@ -600,7 +600,7 @@ function translateAssocsToJoins(model, inputOptions = {})
600
600
  Put all src/tgt path siblings into the EQ term and create the proper path objects
601
601
  with the src/tgt table alias path steps in front.
602
602
  */
603
- let args = []; // TODO: tenant comparison?
603
+ let args = compareTenants ? [ addTenantComparison(assoc) ] : [];
604
604
  for(let i = 0; i < assoc.$flatSrcFKs.length; i++)
605
605
  {
606
606
  args.push({op: {val: '=' },
@@ -70,10 +70,24 @@ function forEachKey( o, callback ) {
70
70
  }
71
71
  }
72
72
 
73
+ /**
74
+ * Sets a property as "hidden" (a.k.a. non-enumerable).
75
+ *
76
+ * @param {object} obj
77
+ * @param {string} prop
78
+ * @param {any} val
79
+ */
80
+ function setHidden( obj, prop, val ) {
81
+ Object.defineProperty( obj, prop, {
82
+ value: val, configurable: true, writable: true, enumerable: false,
83
+ } );
84
+ }
85
+
73
86
  module.exports = {
74
87
  copyPropIfExist,
75
88
  createDict,
76
89
  forEach,
77
90
  forEachValue,
78
91
  forEachKey,
92
+ setHidden,
79
93
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap/cds-compiler",
3
- "version": "4.6.2",
3
+ "version": "4.7.4",
4
4
  "description": "CDS (Core Data Services) compiler and backends",
5
5
  "homepage": "https://cap.cloud.sap/",
6
6
  "author": "SAP SE (https://www.sap.com)",