@sap/cds-compiler 2.15.8 → 3.1.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 (127) hide show
  1. package/CHANGELOG.md +102 -1590
  2. package/bin/.eslintrc.json +2 -1
  3. package/bin/cdsc.js +61 -46
  4. package/doc/API.md +11 -0
  5. package/doc/CHANGELOG_ARCHIVE.md +1592 -0
  6. package/doc/CHANGELOG_BETA.md +26 -5
  7. package/doc/CHANGELOG_DEPRECATED.md +55 -1
  8. package/doc/{DeprecatedOptions.md → DeprecatedOptions_v2.md} +3 -1
  9. package/doc/Versioning.md +20 -1
  10. package/lib/api/.eslintrc.json +2 -2
  11. package/lib/api/main.js +282 -156
  12. package/lib/api/options.js +17 -88
  13. package/lib/api/validate.js +6 -10
  14. package/lib/base/keywords.js +280 -110
  15. package/lib/base/message-registry.js +85 -25
  16. package/lib/base/messages.js +119 -89
  17. package/lib/base/model.js +46 -2
  18. package/lib/base/optionProcessorHelper.js +53 -21
  19. package/lib/checks/actionsFunctions.js +15 -12
  20. package/lib/checks/annotationsOData.js +1 -1
  21. package/lib/checks/cdsPersistence.js +1 -0
  22. package/lib/checks/elements.js +6 -6
  23. package/lib/checks/invalidTarget.js +1 -1
  24. package/lib/checks/nonexpandableStructured.js +1 -1
  25. package/lib/checks/queryNoDbArtifacts.js +2 -1
  26. package/lib/checks/selectItems.js +101 -15
  27. package/lib/checks/types.js +7 -8
  28. package/lib/checks/utils.js +2 -2
  29. package/lib/checks/validator.js +3 -3
  30. package/lib/compiler/assert-consistency.js +78 -21
  31. package/lib/compiler/base.js +6 -4
  32. package/lib/compiler/builtins.js +177 -10
  33. package/lib/compiler/checks.js +1 -1
  34. package/lib/compiler/define.js +28 -23
  35. package/lib/compiler/extend.js +75 -18
  36. package/lib/compiler/finalize-parse-cdl.js +25 -18
  37. package/lib/compiler/index.js +27 -11
  38. package/lib/compiler/moduleLayers.js +7 -0
  39. package/lib/compiler/populate.js +26 -39
  40. package/lib/compiler/propagator.js +12 -7
  41. package/lib/compiler/resolve.js +207 -236
  42. package/lib/compiler/shared.js +100 -93
  43. package/lib/compiler/tweak-assocs.js +13 -20
  44. package/lib/compiler/utils.js +20 -6
  45. package/lib/edm/annotations/preprocessAnnotations.js +12 -13
  46. package/lib/edm/csn2edm.js +35 -37
  47. package/lib/edm/edm.js +22 -13
  48. package/lib/edm/edmAnnoPreprocessor.js +349 -0
  49. package/lib/edm/edmInboundChecks.js +85 -0
  50. package/lib/edm/edmPreprocessor.js +338 -689
  51. package/lib/edm/edmUtils.js +97 -67
  52. package/lib/gen/Dictionary.json +29 -9
  53. package/lib/gen/language.checksum +1 -1
  54. package/lib/gen/language.interp +8 -31
  55. package/lib/gen/language.tokens +105 -114
  56. package/lib/gen/languageLexer.interp +1 -34
  57. package/lib/gen/languageLexer.js +892 -1007
  58. package/lib/gen/languageLexer.tokens +95 -106
  59. package/lib/gen/languageParser.js +20629 -22474
  60. package/lib/inspect/.eslintrc.json +4 -0
  61. package/lib/inspect/index.js +14 -0
  62. package/lib/inspect/inspectModelStatistics.js +81 -0
  63. package/lib/inspect/inspectPropagation.js +189 -0
  64. package/lib/inspect/inspectUtils.js +44 -0
  65. package/lib/json/from-csn.js +74 -69
  66. package/lib/json/to-csn.js +17 -14
  67. package/lib/language/antlrParser.js +2 -2
  68. package/lib/language/docCommentParser.js +61 -38
  69. package/lib/language/errorStrategy.js +52 -40
  70. package/lib/language/genericAntlrParser.js +424 -292
  71. package/lib/language/language.g4 +604 -687
  72. package/lib/language/multiLineStringParser.js +14 -42
  73. package/lib/language/textUtils.js +44 -0
  74. package/lib/main.d.ts +28 -42
  75. package/lib/main.js +104 -81
  76. package/lib/model/api.js +1 -1
  77. package/lib/model/csnRefs.js +57 -30
  78. package/lib/model/csnUtils.js +189 -287
  79. package/lib/model/revealInternalProperties.js +32 -10
  80. package/lib/model/sortViews.js +32 -31
  81. package/lib/modelCompare/compare.js +3 -0
  82. package/lib/optionProcessor.js +91 -57
  83. package/lib/render/.eslintrc.json +1 -1
  84. package/lib/render/DuplicateChecker.js +4 -7
  85. package/lib/render/manageConstraints.js +70 -2
  86. package/lib/render/toCdl.js +387 -367
  87. package/lib/render/toHdbcds.js +20 -16
  88. package/lib/render/toRename.js +44 -22
  89. package/lib/render/toSql.js +81 -59
  90. package/lib/render/utils/common.js +16 -3
  91. package/lib/render/utils/sql.js +20 -19
  92. package/lib/sql-identifier.js +6 -0
  93. package/lib/transform/db/.eslintrc.json +3 -2
  94. package/lib/transform/db/associations.js +43 -35
  95. package/lib/transform/db/cdsPersistence.js +5 -16
  96. package/lib/transform/db/constraints.js +1 -1
  97. package/lib/transform/db/expansion.js +7 -6
  98. package/lib/transform/db/flattening.js +16 -18
  99. package/lib/transform/db/transformExists.js +7 -5
  100. package/lib/transform/db/views.js +3 -3
  101. package/lib/transform/draft/.eslintrc.json +2 -2
  102. package/lib/transform/draft/db.js +6 -6
  103. package/lib/transform/draft/odata.js +6 -7
  104. package/lib/transform/forHanaNew.js +30 -24
  105. package/lib/transform/forOdataNew.js +14 -16
  106. package/lib/transform/localized.js +35 -25
  107. package/lib/transform/odata/toFinalBaseType.js +10 -10
  108. package/lib/transform/odata/typesExposure.js +17 -8
  109. package/lib/transform/odata/utils.js +1 -38
  110. package/lib/transform/transformUtilsNew.js +63 -77
  111. package/lib/transform/translateAssocsToJoins.js +2 -2
  112. package/lib/transform/universalCsn/.eslintrc.json +2 -2
  113. package/lib/transform/universalCsn/coreComputed.js +11 -6
  114. package/lib/transform/universalCsn/universalCsnEnricher.js +33 -5
  115. package/lib/utils/file.js +31 -21
  116. package/lib/utils/moduleResolve.js +0 -1
  117. package/lib/utils/timetrace.js +20 -21
  118. package/package.json +34 -4
  119. package/share/messages/syntax-expected-integer.md +9 -8
  120. package/doc/ApiMigration.md +0 -237
  121. package/doc/CommandLineMigration.md +0 -58
  122. package/doc/ErrorMessages.md +0 -175
  123. package/doc/FioriAnnotations.md +0 -94
  124. package/doc/ODataTransformation.md +0 -273
  125. package/lib/backends.js +0 -529
  126. package/lib/checks/unknownMagic.js +0 -41
  127. package/lib/fix_antlr4-8_warning.js +0 -56
@@ -6,11 +6,78 @@ const {
6
6
  getResultingName,
7
7
  } = require('../model/csnUtils');
8
8
  const { forEach } = require('../utils/objectUtils');
9
+ const { makeMessageFunction } = require('../base/messages');
10
+ const { optionProcessor } = require('../optionProcessor');
11
+ const { transformForHanaWithCsn } = require('../transform/forHanaNew');
9
12
 
10
13
  const {
11
14
  renderReferentialConstraint, getIdentifierUtils,
12
15
  } = require('./utils/sql');
13
16
 
17
+ /**
18
+ * Used only by `cdsc manageConstraints`.
19
+ * Not part of our API, yet.
20
+ *
21
+ * @param {CSN.Model} csn
22
+ * @param {CSN.Options} options
23
+ */
24
+ function alterConstraintsWithCsn(csn, options) {
25
+ const { error } = makeMessageFunction(csn, options, 'manageConstraints');
26
+
27
+ const {
28
+ drop, alter, names, src, violations,
29
+ } = options.manageConstraints || {};
30
+
31
+ if (drop && alter)
32
+ error(null, null, 'Option “--drop” can\'t be combined with “--alter”');
33
+
34
+ options.sqlDialect = 'hana';
35
+ options.sqlMapping = names || 'plain';
36
+
37
+ // Of course we want the database constraints
38
+ options.assertIntegrityType = 'DB';
39
+
40
+ const transformedOptions = _transformSqlOptions(csn, options);
41
+ const forSqlCsn = transformForHanaWithCsn(csn, transformedOptions, 'to.sql');
42
+
43
+ if (violations && src && src !== 'sql')
44
+ error(null, null, `Option “--violations“ can't be combined with source style “${src}“`);
45
+
46
+ let intermediateResult;
47
+ if (violations)
48
+ intermediateResult = listReferentialIntegrityViolations(forSqlCsn, transformedOptions);
49
+ else
50
+ intermediateResult = manageConstraints(forSqlCsn, transformedOptions);
51
+
52
+ return intermediateResult;
53
+ }
54
+
55
+ function _transformSqlOptions(model, options) {
56
+ // Merge options with defaults.
57
+ options = Object.assign({ sqlMapping: 'plain', sqlDialect: 'plain' }, options);
58
+ options.toSql = true;
59
+
60
+ if (!options.src && !options.csn)
61
+ options.src = 'sql';
62
+
63
+ const { warning, error } = makeMessageFunction(model, options, 'to.sql');
64
+
65
+ optionProcessor.verifyOptions(options, 'toSql', true)
66
+ .forEach(complaint => warning(null, null, `${complaint}`));
67
+
68
+ if (options.sqlDialect !== 'hana') {
69
+ // CDXCORE-465, 'quoted' and 'hdbcds' are to be used in combination with dialect 'hana' only
70
+ if (options.sqlMapping === 'quoted' || options.sqlMapping === 'hdbcds')
71
+ error(null, null, `Option "{ sqlDialect: '${options.sqlDialect}' }" can't be combined with "{ sqlMapping: '${options.sqlMapping}' }"`);
72
+
73
+ // No non-HANA SQL for HDI
74
+ if (options.src === 'hdi')
75
+ error(null, null, `Option "{ sqlDialect: '${options.sqlDialect}' }" can't be used for HDI"`);
76
+ }
77
+
78
+ return options;
79
+ }
80
+
14
81
  /**
15
82
  * This render middleware can be used to generate SQL DDL ALTER TABLE <table> ALTER / ADD / DROP CONSTRAINT <constraint> statements for a given CDL model.
16
83
  * Moreover, it can be used to generate .hdbconstraint artifacts.
@@ -38,7 +105,7 @@ function manageConstraints(csn, options) {
38
105
  return;
39
106
  }
40
107
  let alterTableStatement = '';
41
- alterTableStatement += `${indent}ALTER TABLE ${quoteSqlId(getResultingName(csn, options.toSql.names, constraint.dependentTable))}`;
108
+ alterTableStatement += `${indent}ALTER TABLE ${quoteSqlId(getResultingName(csn, options.sqlMapping, constraint.dependentTable))}`;
42
109
  if (renderAlterConstraintStatement)
43
110
  alterTableStatement += `\n${indent}ALTER ${renderedConstraint};`;
44
111
  else if (drop)
@@ -172,7 +239,7 @@ function listReferentialIntegrityViolations(csn, options) {
172
239
  }
173
240
 
174
241
  function quoteAndGetResultingName(id) {
175
- return quoteSqlId(getResultingName(csn, options.toSql.names, id));
242
+ return quoteSqlId(getResultingName(csn, options.sqlMapping, id));
176
243
  }
177
244
 
178
245
  return resultArtifacts;
@@ -192,6 +259,7 @@ function getListOfAllConstraints(csn) {
192
259
  }
193
260
 
194
261
  module.exports = {
262
+ alterConstraintsWithCsn,
195
263
  manageConstraints,
196
264
  listReferentialIntegrityViolations,
197
265
  };