@sap/cds-compiler 2.13.8 → 3.0.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 +155 -1594
  2. package/bin/cdsc.js +144 -66
  3. package/doc/CHANGELOG_ARCHIVE.md +1592 -0
  4. package/doc/CHANGELOG_BETA.md +3 -4
  5. package/doc/CHANGELOG_DEPRECATED.md +35 -1
  6. package/doc/{DeprecatedOptions.md → DeprecatedOptions_v2.md} +3 -1
  7. package/doc/Versioning.md +20 -1
  8. package/lib/api/.eslintrc.json +2 -2
  9. package/lib/api/main.js +237 -122
  10. package/lib/api/options.js +17 -88
  11. package/lib/api/validate.js +12 -16
  12. package/lib/base/keywords.js +216 -109
  13. package/lib/base/message-registry.js +152 -37
  14. package/lib/base/messages.js +145 -83
  15. package/lib/base/model.js +44 -2
  16. package/lib/base/optionProcessorHelper.js +19 -0
  17. package/lib/checks/actionsFunctions.js +7 -5
  18. package/lib/checks/annotationsOData.js +11 -32
  19. package/lib/checks/arrayOfs.js +1 -34
  20. package/lib/checks/cdsPersistence.js +1 -0
  21. package/lib/checks/elements.js +6 -6
  22. package/lib/checks/invalidTarget.js +1 -1
  23. package/lib/checks/nonexpandableStructured.js +1 -1
  24. package/lib/checks/queryNoDbArtifacts.js +2 -1
  25. package/lib/checks/selectItems.js +5 -1
  26. package/lib/checks/types.js +4 -2
  27. package/lib/checks/utils.js +2 -2
  28. package/lib/checks/validator.js +4 -5
  29. package/lib/compiler/assert-consistency.js +16 -10
  30. package/lib/compiler/base.js +1 -0
  31. package/lib/compiler/builtins.js +98 -9
  32. package/lib/compiler/checks.js +22 -70
  33. package/lib/compiler/define.js +61 -13
  34. package/lib/compiler/extend.js +79 -14
  35. package/lib/compiler/finalize-parse-cdl.js +46 -29
  36. package/lib/compiler/index.js +100 -37
  37. package/lib/compiler/moduleLayers.js +7 -0
  38. package/lib/compiler/populate.js +19 -18
  39. package/lib/compiler/propagator.js +7 -4
  40. package/lib/compiler/resolve.js +297 -234
  41. package/lib/compiler/shared.js +107 -102
  42. package/lib/compiler/tweak-assocs.js +16 -11
  43. package/lib/compiler/utils.js +5 -0
  44. package/lib/edm/annotations/genericTranslation.js +93 -21
  45. package/lib/edm/csn2edm.js +230 -115
  46. package/lib/edm/edm.js +305 -226
  47. package/lib/edm/edmPreprocessor.js +509 -438
  48. package/lib/edm/edmUtils.js +31 -45
  49. package/lib/gen/Dictionary.json +98 -22
  50. package/lib/gen/language.checksum +1 -1
  51. package/lib/gen/language.interp +10 -30
  52. package/lib/gen/language.tokens +105 -114
  53. package/lib/gen/languageLexer.interp +1 -34
  54. package/lib/gen/languageLexer.js +889 -1007
  55. package/lib/gen/languageLexer.tokens +95 -106
  56. package/lib/gen/languageParser.js +20786 -22199
  57. package/lib/json/csnVersion.js +10 -11
  58. package/lib/json/from-csn.js +59 -51
  59. package/lib/json/to-csn.js +10 -10
  60. package/lib/language/antlrParser.js +2 -2
  61. package/lib/language/docCommentParser.js +62 -39
  62. package/lib/language/errorStrategy.js +52 -40
  63. package/lib/language/genericAntlrParser.js +348 -229
  64. package/lib/language/language.g4 +629 -653
  65. package/lib/language/multiLineStringParser.js +14 -42
  66. package/lib/language/textUtils.js +44 -0
  67. package/lib/main.d.ts +46 -43
  68. package/lib/main.js +108 -79
  69. package/lib/model/csnRefs.js +34 -7
  70. package/lib/model/csnUtils.js +337 -332
  71. package/lib/model/enrichCsn.js +1 -0
  72. package/lib/model/revealInternalProperties.js +30 -10
  73. package/lib/model/sortViews.js +32 -31
  74. package/lib/modelCompare/compare.js +6 -6
  75. package/lib/optionProcessor.js +73 -46
  76. package/lib/render/.eslintrc.json +1 -1
  77. package/lib/render/DuplicateChecker.js +4 -7
  78. package/lib/render/manageConstraints.js +70 -2
  79. package/lib/render/toCdl.js +1042 -882
  80. package/lib/render/toHdbcds.js +195 -245
  81. package/lib/render/toRename.js +44 -22
  82. package/lib/render/toSql.js +225 -241
  83. package/lib/render/utils/common.js +145 -15
  84. package/lib/render/utils/sql.js +20 -19
  85. package/lib/sql-identifier.js +6 -0
  86. package/lib/transform/db/.eslintrc.json +4 -3
  87. package/lib/transform/db/associations.js +2 -2
  88. package/lib/transform/db/cdsPersistence.js +5 -15
  89. package/lib/transform/db/constraints.js +4 -2
  90. package/lib/transform/db/expansion.js +22 -16
  91. package/lib/transform/db/flattening.js +109 -80
  92. package/lib/transform/db/transformExists.js +7 -7
  93. package/lib/transform/db/views.js +9 -6
  94. package/lib/transform/draft/.eslintrc.json +2 -2
  95. package/lib/transform/draft/db.js +6 -6
  96. package/lib/transform/draft/odata.js +6 -7
  97. package/lib/transform/forHanaNew.js +62 -48
  98. package/lib/transform/forOdataNew.js +49 -50
  99. package/lib/transform/localized.js +31 -20
  100. package/lib/transform/odata/toFinalBaseType.js +16 -14
  101. package/lib/transform/odata/typesExposure.js +146 -198
  102. package/lib/transform/odata/utils.js +1 -38
  103. package/lib/transform/transformUtilsNew.js +67 -84
  104. package/lib/transform/translateAssocsToJoins.js +7 -3
  105. package/lib/transform/universalCsn/.eslintrc.json +2 -2
  106. package/lib/transform/universalCsn/coreComputed.js +16 -9
  107. package/lib/transform/universalCsn/universalCsnEnricher.js +60 -10
  108. package/lib/utils/file.js +3 -3
  109. package/lib/utils/moduleResolve.js +13 -6
  110. package/lib/utils/timetrace.js +20 -21
  111. package/package.json +35 -4
  112. package/share/messages/message-explanations.json +2 -1
  113. package/share/messages/syntax-expected-integer.md +37 -0
  114. package/doc/ApiMigration.md +0 -237
  115. package/doc/CommandLineMigration.md +0 -58
  116. package/doc/ErrorMessages.md +0 -175
  117. package/doc/FioriAnnotations.md +0 -94
  118. package/doc/ODataTransformation.md +0 -273
  119. package/lib/backends.js +0 -529
  120. package/lib/fix_antlr4-8_warning.js +0 -56
  121. package/lib/transform/odata/attachPath.js +0 -96
  122. package/lib/transform/odata/expandStructKeysInAssociations.js +0 -59
  123. package/lib/transform/odata/generateForeignKeyElements.js +0 -261
  124. package/lib/transform/odata/referenceFlattener.js +0 -296
  125. package/lib/transform/odata/sortByAssociationDependency.js +0 -105
  126. package/lib/transform/odata/structuralPath.js +0 -72
  127. package/lib/transform/odata/structureFlattener.js +0 -171
@@ -1,20 +1,24 @@
1
1
 
2
2
  'use strict';
3
3
 
4
- const { CompilationError, hasErrors } = require('../base/messages');
4
+ const { makeMessageFunction } = require('../base/messages');
5
5
  const { checkCSNVersion } = require('../json/csnVersion');
6
- const { getUtils } = require('../model/csnUtils');
6
+ const { getUtils, forEachDefinition } = require('../model/csnUtils');
7
+ const { optionProcessor } = require('../optionProcessor');
8
+ const { isBetaEnabled } = require('../base/model');
9
+ const { transformForHanaWithCsn } = require('../transform/forHanaNew');
7
10
 
8
- // FIXME: This is not up-to-date in regards to the changes to hdbcds/sql quoting etc.
9
11
 
10
12
  /**
13
+ * FIXME: Not yet supported, only in beta mode
14
+ * FIXME: This is not up-to-date in regards to the changes to hdbcds/sql quoting etc.
11
15
  *
12
- * Render the augmented CSN 'model' to SQL DDL statements renaming existing tables and their
16
+ * Generate SQL DDL rename statements for a migration, renaming existing tables and their
13
17
  * columns so that they match the result of "toHana" or "toSql" with the 'plain' option for names.
14
18
  * Expects the naming convention of the existing tables to be either 'quoted' or 'hdbcds' (default).
15
- * The following options control what is actually generated:
19
+ * The following options control what is actually generated (see help above):
16
20
  * options : {
17
- * toRename.names : existing names, either 'quoted' or 'hdbcds' (default)
21
+ * sqlMapping : existing names, either 'quoted' or 'hdbcds' (default)
18
22
  * }
19
23
  * Return a dictionary of top-level artifacts by their names, like this:
20
24
  * { "foo" : "RENAME TABLE \"foo\" ...",
@@ -22,34 +26,52 @@ const { getUtils } = require('../model/csnUtils');
22
26
  * }
23
27
  *
24
28
  * @todo clarify input parameters
25
- * @param {CSN.Model} csn Augmented csn?
29
+ * @param {CSN.Model} inputCsn CSN?
26
30
  * @param {CSN.Options} options Transformation options
27
31
  * @returns {object} A dictionary of name: rename statement
28
32
  */
29
- function toRenameDdl(csn, options) {
30
- // Merge options (arguments first, then model options and default)
31
- const result = Object.create(null);
33
+ function toRename(inputCsn, options) {
34
+ const { error, warning, throwWithError } = makeMessageFunction(inputCsn, options, 'to.rename');
35
+
36
+ // Merge options with defaults.
37
+ options = Object.assign({ sqlMapping: 'hdbcds' }, options);
38
+
39
+ // Verify options
40
+ optionProcessor.verifyOptions(options, 'toRename').forEach(complaint => warning(null, null, `${complaint}`));
41
+ checkCSNVersion(inputCsn, options);
42
+
43
+ // Requires beta mode
44
+ if (!isBetaEnabled(options, 'toRename'))
45
+ error(null, null, 'Generation of SQL rename statements is not supported yet (only in beta mode)');
32
46
 
33
- checkCSNVersion(csn, options);
47
+ // FIXME: Currently, 'toRename' implies transformation for HANA (transferring the options to forHana)
48
+ const csn = transformForHanaWithCsn(inputCsn, options, 'to.rename');
49
+ // forHanaCsn looses empty contexts and services, add them again so that toRename can calculate the namespaces
50
+ forEachDefinition(csn, (artifact, artifactName) => {
51
+ if ((artifact.kind === 'context' || artifact.kind === 'service') && csn.definitions[artifactName] === undefined)
52
+ csn.definitions[artifactName] = artifact;
53
+ });
54
+
55
+ const result = Object.create(null);
56
+ const { getNamespaceOfArtifact } = getUtils(csn, false);
34
57
 
35
- const { getNamespaceOfArtifact } = getUtils(csn);
36
58
  // Render each artifact on its own
37
59
  for (const artifactName in csn.definitions) {
38
60
  const sourceStr = renameTableAndColumns(artifactName, csn.definitions[artifactName]);
39
-
40
61
  if (sourceStr !== '')
41
62
  result[artifactName] = sourceStr;
42
63
  }
43
- // Throw exception in case of errors
44
- if (hasErrors(options.messages))
45
- throw new CompilationError(options.messages);
46
64
 
47
- return result;
65
+ throwWithError();
48
66
 
67
+ return {
68
+ rename: result,
69
+ options,
70
+ };
49
71
 
50
72
  /**
51
73
  * If 'art' is a non-view entity, generate SQL statements to rename the corresponding
52
- * table and its columns from the naming conventions given in 'options.toRename.name'
74
+ * table and its columns from the naming conventions given in 'options.sqlMapping'
53
75
  * (either 'quoted' or 'hdbcds') to 'plain'. In addition, drop any existing associations
54
76
  * from the columns (they would likely become invalid anyway).
55
77
  * Do not rename anything if the names are identical.
@@ -97,7 +119,7 @@ function toRenameDdl(csn, options) {
97
119
  * @returns {string} Absolute name
98
120
  */
99
121
  function absoluteCdsName(name) {
100
- if (options.toRename.names !== 'hdbcds')
122
+ if (options.sqlMapping !== 'hdbcds')
101
123
  return name;
102
124
 
103
125
  const namespaceName = getNamespaceOfArtifact(name);
@@ -108,14 +130,14 @@ function toRenameDdl(csn, options) {
108
130
  }
109
131
 
110
132
  /**
111
- * Return 'name' with appropriate "-quotes, also replacing '::' by '.' if 'options.toRename.names'
133
+ * Return 'name' with appropriate "-quotes, also replacing '::' by '.' if 'options.sqlMapping'
112
134
  * is 'quoted'
113
135
  *
114
136
  * @param {string} name Name to quote
115
137
  * @returns {string} Quoted string
116
138
  */
117
139
  function quoteSqlId(name) {
118
- if (options.toRename.names === 'quoted')
140
+ if (options.sqlMapping === 'quoted')
119
141
  name = name.replace(/::/g, '.');
120
142
 
121
143
  return `"${name.replace(/"/g, '""')}"`;
@@ -134,5 +156,5 @@ function toRenameDdl(csn, options) {
134
156
  }
135
157
 
136
158
  module.exports = {
137
- toRenameDdl,
159
+ toRename,
138
160
  };