@sap/cds-compiler 2.12.0 → 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.
- package/CHANGELOG.md +221 -15
- package/bin/cdsc.js +125 -50
- package/bin/cdsse.js +2 -2
- package/doc/CHANGELOG_BETA.md +13 -6
- package/doc/CHANGELOG_DEPRECATED.md +22 -6
- package/doc/NameResolution.md +21 -16
- package/lib/api/main.js +47 -84
- package/lib/api/options.js +5 -6
- package/lib/api/validate.js +6 -11
- package/lib/backends.js +15 -23
- package/lib/base/dictionaries.js +0 -8
- package/lib/base/error.js +26 -0
- package/lib/base/keywords.js +7 -17
- package/lib/base/location.js +9 -4
- package/lib/base/message-registry.js +114 -18
- package/lib/base/messages.js +101 -90
- package/lib/base/model.js +2 -63
- package/lib/base/optionProcessorHelper.js +177 -123
- package/lib/checks/annotationsOData.js +12 -33
- package/lib/checks/arrayOfs.js +1 -34
- package/lib/checks/cdsPersistence.js +2 -1
- package/lib/checks/enricher.js +17 -1
- package/lib/checks/invalidTarget.js +3 -1
- package/lib/checks/managedWithoutKeys.js +3 -1
- package/lib/checks/selectItems.js +4 -4
- package/lib/checks/sql-snippets.js +27 -26
- package/lib/checks/types.js +1 -1
- package/lib/checks/validator.js +6 -11
- package/lib/compiler/assert-consistency.js +6 -3
- package/lib/compiler/base.js +1 -0
- package/lib/compiler/builtins.js +19 -6
- package/lib/compiler/checks.js +23 -60
- package/lib/compiler/cycle-detector.js +1 -1
- package/lib/compiler/define.js +1151 -0
- package/lib/compiler/extend.js +1000 -0
- package/lib/compiler/finalize-parse-cdl.js +237 -0
- package/lib/compiler/index.js +107 -39
- package/lib/compiler/kick-start.js +190 -0
- package/lib/compiler/moduleLayers.js +4 -4
- package/lib/compiler/populate.js +1227 -0
- package/lib/compiler/propagator.js +114 -46
- package/lib/compiler/resolve.js +1521 -0
- package/lib/compiler/shared.js +126 -65
- package/lib/compiler/tweak-assocs.js +535 -0
- package/lib/compiler/utils.js +197 -33
- package/lib/edm/.eslintrc.json +5 -0
- package/lib/edm/annotations/genericTranslation.js +38 -24
- package/lib/edm/annotations/preprocessAnnotations.js +2 -2
- package/lib/edm/csn2edm.js +219 -100
- package/lib/edm/edm.js +302 -230
- package/lib/edm/edmPreprocessor.js +554 -419
- package/lib/edm/edmUtils.js +138 -44
- package/lib/gen/Dictionary.json +100 -19
- package/lib/gen/language.checksum +1 -1
- package/lib/gen/language.interp +11 -1
- package/lib/gen/language.tokens +86 -83
- package/lib/gen/languageLexer.interp +10 -1
- package/lib/gen/languageLexer.js +860 -833
- package/lib/gen/languageLexer.tokens +78 -75
- package/lib/gen/languageParser.js +5765 -4480
- package/lib/json/csnVersion.js +10 -11
- package/lib/json/from-csn.js +15 -3
- package/lib/json/to-csn.js +126 -68
- package/lib/language/docCommentParser.js +4 -4
- package/lib/language/genericAntlrParser.js +123 -5
- package/lib/language/language.g4 +355 -156
- package/lib/language/multiLineStringParser.js +5 -5
- package/lib/main.d.ts +486 -59
- package/lib/main.js +41 -9
- package/lib/model/api.js +3 -1
- package/lib/model/csnRefs.js +252 -156
- package/lib/model/csnUtils.js +384 -297
- package/lib/model/enrichCsn.js +71 -29
- package/lib/model/revealInternalProperties.js +29 -8
- package/lib/model/sortViews.js +2 -1
- package/lib/modelCompare/compare.js +23 -18
- package/lib/optionProcessor.js +63 -26
- package/lib/render/manageConstraints.js +35 -32
- package/lib/render/toCdl.js +897 -947
- package/lib/render/toHdbcds.js +205 -257
- package/lib/render/toSql.js +264 -225
- package/lib/render/utils/common.js +136 -25
- package/lib/render/utils/sql.js +4 -3
- package/lib/render/utils/stringEscapes.js +111 -0
- package/lib/sql-identifier.js +1 -1
- package/lib/transform/.eslintrc.json +5 -0
- package/lib/transform/db/.eslintrc.json +3 -1
- package/lib/transform/db/applyTransformations.js +35 -12
- package/lib/transform/db/assertUnique.js +1 -1
- package/lib/transform/db/associations.js +104 -306
- package/lib/transform/db/cdsPersistence.js +2 -2
- package/lib/transform/db/constraints.js +58 -53
- package/lib/transform/db/expansion.js +60 -33
- package/lib/transform/db/flattening.js +582 -104
- package/lib/transform/db/groupByOrderBy.js +3 -1
- package/lib/transform/db/transformExists.js +66 -13
- package/lib/transform/db/views.js +11 -7
- package/lib/transform/draft/.eslintrc.json +38 -0
- package/lib/transform/{db/draft.js → draft/db.js} +6 -5
- package/lib/transform/draft/odata.js +227 -0
- package/lib/transform/forHanaNew.js +109 -208
- package/lib/transform/forOdataNew.js +59 -212
- package/lib/transform/localized.js +46 -26
- package/lib/transform/odata/toFinalBaseType.js +85 -11
- package/lib/transform/odata/typesExposure.js +147 -199
- package/lib/transform/odata/utils.js +2 -2
- package/lib/transform/transformUtilsNew.js +44 -33
- package/lib/transform/translateAssocsToJoins.js +3 -20
- package/lib/transform/universalCsn/.eslintrc.json +36 -0
- package/lib/transform/universalCsn/coreComputed.js +172 -0
- package/lib/transform/universalCsn/universalCsnEnricher.js +737 -0
- package/lib/transform/universalCsn/utils.js +63 -0
- package/lib/utils/moduleResolve.js +13 -6
- package/lib/utils/objectUtils.js +30 -0
- package/package.json +1 -1
- package/share/messages/README.md +26 -0
- package/share/messages/message-explanations.json +2 -1
- package/share/messages/syntax-expected-integer.md +37 -0
- package/lib/compiler/definer.js +0 -2361
- package/lib/compiler/resolver.js +0 -3079
- 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 -290
- 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/transform/universalCsnEnricher.js +0 -237
|
@@ -5,6 +5,7 @@ const {
|
|
|
5
5
|
forEachDefinition,
|
|
6
6
|
getResultingName,
|
|
7
7
|
} = require('../model/csnUtils');
|
|
8
|
+
const { forEach } = require('../utils/objectUtils');
|
|
8
9
|
|
|
9
10
|
const {
|
|
10
11
|
renderReferentialConstraint, getIdentifierUtils,
|
|
@@ -13,7 +14,7 @@ const {
|
|
|
13
14
|
/**
|
|
14
15
|
* This render middleware can be used to generate SQL DDL ALTER TABLE <table> ALTER / ADD / DROP CONSTRAINT <constraint> statements for a given CDL model.
|
|
15
16
|
* Moreover, it can be used to generate .hdbconstraint artifacts.
|
|
16
|
-
* Depending on the options.manageConstraints provided,the VALIDATED / ENFORCED flag of the constraints can be adjusted.
|
|
17
|
+
* Depending on the options.manageConstraints provided, the VALIDATED / ENFORCED flag of the constraints can be adjusted.
|
|
17
18
|
*
|
|
18
19
|
* @param {CSN.Model} csn
|
|
19
20
|
* @param {CSN.Options} options
|
|
@@ -29,25 +30,24 @@ function manageConstraints(csn, options) {
|
|
|
29
30
|
const { quoteSqlId } = getIdentifierUtils(options);
|
|
30
31
|
forEachDefinition(csn, (artifact) => {
|
|
31
32
|
if (artifact.$tableConstraints && artifact.$tableConstraints.referential) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
});
|
|
33
|
+
forEach(artifact.$tableConstraints.referential, (fileName, constraint) => {
|
|
34
|
+
const renderAlterConstraintStatement = alter && src !== 'hdi';
|
|
35
|
+
const renderedConstraint = renderReferentialConstraint(constraint, indent, false, csn, options, renderAlterConstraintStatement);
|
|
36
|
+
if (src === 'hdi') {
|
|
37
|
+
resultArtifacts[fileName] = renderedConstraint;
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
let alterTableStatement = '';
|
|
41
|
+
alterTableStatement += `${indent}ALTER TABLE ${quoteSqlId(getResultingName(csn, options.toSql.names, constraint.dependentTable))}`;
|
|
42
|
+
if (renderAlterConstraintStatement)
|
|
43
|
+
alterTableStatement += `\n${indent}ALTER ${renderedConstraint};`;
|
|
44
|
+
else if (drop)
|
|
45
|
+
alterTableStatement += `${indent} DROP CONSTRAINT ${quoteSqlId(constraint.identifier)};`;
|
|
46
|
+
else
|
|
47
|
+
alterTableStatement += `\n${indent}ADD ${renderedConstraint};`;
|
|
48
|
+
|
|
49
|
+
resultArtifacts[fileName] = alterTableStatement;
|
|
50
|
+
});
|
|
51
51
|
}
|
|
52
52
|
});
|
|
53
53
|
return resultArtifacts;
|
|
@@ -71,19 +71,23 @@ function listReferentialIntegrityViolations(csn, options) {
|
|
|
71
71
|
// helper function to reduce the parent key / foreign key arrays of a referential constraint to a join list which can be used in a where clause
|
|
72
72
|
const joinPkWithFkReducer = (constraint, subQueryAlias, mainQueryAlias) => (prev, curr, index) => (index > 0
|
|
73
73
|
? `${prev} AND
|
|
74
|
-
${increaseIndent(indent)}${mainQueryAlias}.${quoteSqlId(constraint.foreignKey[index])} = ${subQueryAlias}.${quoteSqlId(constraint.parentKey[index])}`
|
|
74
|
+
${increaseIndent(indent)}"${mainQueryAlias}".${quoteSqlId(constraint.foreignKey[index])} = ${subQueryAlias}.${quoteSqlId(constraint.parentKey[index])}`
|
|
75
75
|
: increaseIndent(increaseIndent(indent)) + prev);
|
|
76
76
|
|
|
77
|
-
Object.entries(referentialConstraints).forEach(([ identifier, constraint ]) => {
|
|
77
|
+
Object.entries(referentialConstraints).forEach(([ identifier, constraint ], index) => {
|
|
78
78
|
let selectViolations = 'SELECT\n';
|
|
79
|
+
// this column indicates which SELECT revealed the integrity violation
|
|
80
|
+
// and helps to identify the corrupted table
|
|
81
|
+
selectViolations += `${index} as "SELECT-ID",\n`;
|
|
79
82
|
// SELECT <primary_key>,
|
|
80
83
|
const primaryKeyList = selectPrimaryKeyColumns(constraint);
|
|
81
84
|
if (primaryKeyList)
|
|
82
85
|
selectViolations += `${primaryKeyList},\n`;
|
|
83
86
|
// ... <foreign_key>
|
|
84
87
|
selectViolations += selectForeignKeyColumns(constraint);
|
|
85
|
-
|
|
86
|
-
|
|
88
|
+
const mainQueryAlias = `MAIN_${index}`;
|
|
89
|
+
// ... FROM <dependent table> AS "${index}"
|
|
90
|
+
selectViolations += `\nFROM ${quoteAndGetResultingName(constraint.dependentTable)} AS "${mainQueryAlias}"\n`;
|
|
87
91
|
// ... WHERE NOT (<(part of) foreign key is null>)
|
|
88
92
|
selectViolations += whereNotForeignKeyIsNull(constraint);
|
|
89
93
|
/*
|
|
@@ -91,7 +95,7 @@ function listReferentialIntegrityViolations(csn, options) {
|
|
|
91
95
|
SELECT * FROM <parent_table> WHERE <dependent_table>.<foreign_key> = <parent_table>.<parent_key>
|
|
92
96
|
)
|
|
93
97
|
*/
|
|
94
|
-
selectViolations += andNoMatchingPrimaryKeyExists(constraint);
|
|
98
|
+
selectViolations += andNoMatchingPrimaryKeyExists(constraint, mainQueryAlias);
|
|
95
99
|
resultArtifacts[identifier] = selectViolations;
|
|
96
100
|
});
|
|
97
101
|
|
|
@@ -147,21 +151,21 @@ function listReferentialIntegrityViolations(csn, options) {
|
|
|
147
151
|
* Generate SQL sub-SELECT, listing all rows of the parent table where no matching primary key column for the respective foreign key is found.
|
|
148
152
|
*
|
|
149
153
|
* @param {CSN.ReferentialConstraint} constraint
|
|
154
|
+
* @param {string} mainQueryAlias
|
|
150
155
|
* @returns AND NOT EXISTS ( SELECT * FROM <parent_table> WHERE <dependent_table>.<foreign_key> = <parent_table>.<parent_key> ) statement
|
|
151
156
|
*/
|
|
152
|
-
function andNoMatchingPrimaryKeyExists(constraint) {
|
|
157
|
+
function andNoMatchingPrimaryKeyExists(constraint, mainQueryAlias) {
|
|
153
158
|
let andNotExists = `\n${indent}AND NOT EXISTS (\n`;
|
|
154
159
|
andNotExists += `${increaseIndent(indent)}SELECT * FROM ${quoteAndGetResultingName(constraint.parentTable)}`;
|
|
155
160
|
// add an alias to both queries so that they can be distinguished at all times
|
|
156
161
|
const subQueryAlias = '"SUB"';
|
|
157
|
-
const mainQueryAlias = '"MAIN"';
|
|
158
162
|
andNotExists += ` AS ${subQueryAlias}`;
|
|
159
163
|
andNotExists += '\n';
|
|
160
164
|
const joinListReducer = joinPkWithFkReducer(constraint, subQueryAlias, mainQueryAlias);
|
|
161
165
|
andNotExists += `${increaseIndent(indent)}WHERE (\n`;
|
|
162
166
|
andNotExists += constraint.foreignKey
|
|
163
167
|
.reduce(joinListReducer,
|
|
164
|
-
|
|
168
|
+
`"${mainQueryAlias}".${quoteSqlId(constraint.foreignKey[0])} = ${subQueryAlias}.${quoteSqlId(constraint.parentKey[0])}`);
|
|
165
169
|
andNotExists += `\n${increaseIndent(indent)})`;
|
|
166
170
|
andNotExists += `\n${indent});`;
|
|
167
171
|
return andNotExists;
|
|
@@ -179,10 +183,9 @@ function getListOfAllConstraints(csn) {
|
|
|
179
183
|
const referentialConstraints = {};
|
|
180
184
|
forEachDefinition(csn, (artifact) => {
|
|
181
185
|
if (artifact.$tableConstraints && artifact.$tableConstraints.referential) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
});
|
|
186
|
+
forEach(artifact.$tableConstraints.referential, (identifier, referentialConstraint) => {
|
|
187
|
+
referentialConstraints[identifier] = referentialConstraint;
|
|
188
|
+
});
|
|
186
189
|
}
|
|
187
190
|
});
|
|
188
191
|
return referentialConstraints;
|