@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.
- package/CHANGELOG.md +155 -1594
- package/bin/cdsc.js +144 -66
- package/doc/CHANGELOG_ARCHIVE.md +1592 -0
- package/doc/CHANGELOG_BETA.md +3 -4
- package/doc/CHANGELOG_DEPRECATED.md +35 -1
- package/doc/{DeprecatedOptions.md → DeprecatedOptions_v2.md} +3 -1
- package/doc/Versioning.md +20 -1
- package/lib/api/.eslintrc.json +2 -2
- package/lib/api/main.js +237 -122
- package/lib/api/options.js +17 -88
- package/lib/api/validate.js +12 -16
- package/lib/base/keywords.js +216 -109
- package/lib/base/message-registry.js +152 -37
- package/lib/base/messages.js +145 -83
- package/lib/base/model.js +44 -2
- package/lib/base/optionProcessorHelper.js +19 -0
- package/lib/checks/actionsFunctions.js +7 -5
- package/lib/checks/annotationsOData.js +11 -32
- package/lib/checks/arrayOfs.js +1 -34
- package/lib/checks/cdsPersistence.js +1 -0
- package/lib/checks/elements.js +6 -6
- package/lib/checks/invalidTarget.js +1 -1
- package/lib/checks/nonexpandableStructured.js +1 -1
- package/lib/checks/queryNoDbArtifacts.js +2 -1
- package/lib/checks/selectItems.js +5 -1
- package/lib/checks/types.js +4 -2
- package/lib/checks/utils.js +2 -2
- package/lib/checks/validator.js +4 -5
- package/lib/compiler/assert-consistency.js +16 -10
- package/lib/compiler/base.js +1 -0
- package/lib/compiler/builtins.js +98 -9
- package/lib/compiler/checks.js +22 -70
- package/lib/compiler/define.js +61 -13
- package/lib/compiler/extend.js +79 -14
- package/lib/compiler/finalize-parse-cdl.js +46 -29
- package/lib/compiler/index.js +100 -37
- package/lib/compiler/moduleLayers.js +7 -0
- package/lib/compiler/populate.js +19 -18
- package/lib/compiler/propagator.js +7 -4
- package/lib/compiler/resolve.js +297 -234
- package/lib/compiler/shared.js +107 -102
- package/lib/compiler/tweak-assocs.js +16 -11
- package/lib/compiler/utils.js +5 -0
- package/lib/edm/annotations/genericTranslation.js +93 -21
- package/lib/edm/csn2edm.js +230 -115
- package/lib/edm/edm.js +305 -226
- package/lib/edm/edmPreprocessor.js +509 -438
- package/lib/edm/edmUtils.js +31 -45
- package/lib/gen/Dictionary.json +98 -22
- package/lib/gen/language.checksum +1 -1
- package/lib/gen/language.interp +10 -30
- package/lib/gen/language.tokens +105 -114
- package/lib/gen/languageLexer.interp +1 -34
- package/lib/gen/languageLexer.js +889 -1007
- package/lib/gen/languageLexer.tokens +95 -106
- package/lib/gen/languageParser.js +20786 -22199
- package/lib/json/csnVersion.js +10 -11
- package/lib/json/from-csn.js +59 -51
- package/lib/json/to-csn.js +10 -10
- package/lib/language/antlrParser.js +2 -2
- package/lib/language/docCommentParser.js +62 -39
- package/lib/language/errorStrategy.js +52 -40
- package/lib/language/genericAntlrParser.js +348 -229
- package/lib/language/language.g4 +629 -653
- package/lib/language/multiLineStringParser.js +14 -42
- package/lib/language/textUtils.js +44 -0
- package/lib/main.d.ts +46 -43
- package/lib/main.js +108 -79
- package/lib/model/csnRefs.js +34 -7
- package/lib/model/csnUtils.js +337 -332
- package/lib/model/enrichCsn.js +1 -0
- package/lib/model/revealInternalProperties.js +30 -10
- package/lib/model/sortViews.js +32 -31
- package/lib/modelCompare/compare.js +6 -6
- package/lib/optionProcessor.js +73 -46
- package/lib/render/.eslintrc.json +1 -1
- package/lib/render/DuplicateChecker.js +4 -7
- package/lib/render/manageConstraints.js +70 -2
- package/lib/render/toCdl.js +1042 -882
- package/lib/render/toHdbcds.js +195 -245
- package/lib/render/toRename.js +44 -22
- package/lib/render/toSql.js +225 -241
- package/lib/render/utils/common.js +145 -15
- package/lib/render/utils/sql.js +20 -19
- package/lib/sql-identifier.js +6 -0
- package/lib/transform/db/.eslintrc.json +4 -3
- package/lib/transform/db/associations.js +2 -2
- package/lib/transform/db/cdsPersistence.js +5 -15
- package/lib/transform/db/constraints.js +4 -2
- package/lib/transform/db/expansion.js +22 -16
- package/lib/transform/db/flattening.js +109 -80
- package/lib/transform/db/transformExists.js +7 -7
- package/lib/transform/db/views.js +9 -6
- package/lib/transform/draft/.eslintrc.json +2 -2
- package/lib/transform/draft/db.js +6 -6
- package/lib/transform/draft/odata.js +6 -7
- package/lib/transform/forHanaNew.js +62 -48
- package/lib/transform/forOdataNew.js +49 -50
- package/lib/transform/localized.js +31 -20
- package/lib/transform/odata/toFinalBaseType.js +16 -14
- package/lib/transform/odata/typesExposure.js +146 -198
- package/lib/transform/odata/utils.js +1 -38
- package/lib/transform/transformUtilsNew.js +67 -84
- package/lib/transform/translateAssocsToJoins.js +7 -3
- package/lib/transform/universalCsn/.eslintrc.json +2 -2
- package/lib/transform/universalCsn/coreComputed.js +16 -9
- package/lib/transform/universalCsn/universalCsnEnricher.js +60 -10
- package/lib/utils/file.js +3 -3
- package/lib/utils/moduleResolve.js +13 -6
- package/lib/utils/timetrace.js +20 -21
- package/package.json +35 -4
- package/share/messages/message-explanations.json +2 -1
- package/share/messages/syntax-expected-integer.md +37 -0
- package/doc/ApiMigration.md +0 -237
- package/doc/CommandLineMigration.md +0 -58
- package/doc/ErrorMessages.md +0 -175
- package/doc/FioriAnnotations.md +0 -94
- package/doc/ODataTransformation.md +0 -273
- package/lib/backends.js +0 -529
- package/lib/fix_antlr4-8_warning.js +0 -56
- package/lib/transform/odata/attachPath.js +0 -96
- package/lib/transform/odata/expandStructKeysInAssociations.js +0 -59
- package/lib/transform/odata/generateForeignKeyElements.js +0 -261
- package/lib/transform/odata/referenceFlattener.js +0 -296
- package/lib/transform/odata/sortByAssociationDependency.js +0 -105
- package/lib/transform/odata/structuralPath.js +0 -72
- package/lib/transform/odata/structureFlattener.js +0 -171
package/lib/render/toRename.js
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
const {
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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}
|
|
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
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
-
|
|
159
|
+
toRename,
|
|
138
160
|
};
|