@sap/cds-compiler 2.5.0 → 2.10.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.
- package/CHANGELOG.md +191 -9
- package/bin/cdsc.js +2 -2
- package/doc/CHANGELOG_BETA.md +33 -3
- package/lib/api/main.js +29 -101
- package/lib/api/options.js +15 -11
- package/lib/api/validate.js +12 -8
- package/lib/backends.js +0 -81
- package/lib/base/keywords.js +32 -2
- package/lib/base/message-registry.js +63 -9
- package/lib/base/messages.js +63 -21
- package/lib/base/model.js +2 -3
- package/lib/checks/defaultValues.js +27 -2
- package/lib/checks/elements.js +1 -6
- package/lib/checks/foreignKeys.js +0 -6
- package/lib/checks/managedWithoutKeys.js +17 -0
- package/lib/checks/nonexpandableStructured.js +38 -0
- package/lib/checks/onConditions.js +9 -45
- package/lib/checks/queryNoDbArtifacts.js +25 -7
- package/lib/checks/selectItems.js +25 -2
- package/lib/checks/types.js +26 -2
- package/lib/checks/unknownMagic.js +38 -0
- package/lib/checks/utils.js +61 -0
- package/lib/checks/validator.js +60 -7
- package/lib/compiler/assert-consistency.js +16 -7
- package/lib/compiler/builtins.js +2 -0
- package/lib/compiler/checks.js +6 -4
- package/lib/compiler/definer.js +99 -42
- package/lib/compiler/index.js +73 -27
- package/lib/compiler/resolver.js +288 -157
- package/lib/compiler/shared.js +31 -11
- package/lib/edm/annotations/genericTranslation.js +182 -186
- package/lib/edm/csn2edm.js +103 -108
- package/lib/edm/edm.js +18 -21
- package/lib/edm/edmPreprocessor.js +361 -114
- package/lib/edm/edmUtils.js +103 -33
- package/lib/gen/Dictionary.json +22 -0
- package/lib/gen/language.checksum +1 -1
- package/lib/gen/language.interp +12 -1
- package/lib/gen/language.tokens +57 -53
- package/lib/gen/languageLexer.interp +10 -1
- package/lib/gen/languageLexer.js +770 -744
- package/lib/gen/languageLexer.tokens +49 -46
- package/lib/gen/languageParser.js +4713 -4279
- package/lib/json/from-csn.js +103 -45
- package/lib/json/to-csn.js +296 -117
- package/lib/language/antlrParser.js +4 -3
- package/lib/language/errorStrategy.js +1 -0
- package/lib/language/genericAntlrParser.js +21 -12
- package/lib/language/language.g4 +99 -31
- package/lib/main.d.ts +81 -3
- package/lib/main.js +30 -7
- package/lib/model/api.js +78 -0
- package/lib/model/csnRefs.js +329 -142
- package/lib/model/csnUtils.js +235 -58
- package/lib/model/enrichCsn.js +18 -1
- package/lib/model/revealInternalProperties.js +2 -1
- package/lib/modelCompare/compare.js +37 -20
- package/lib/optionProcessor.js +9 -3
- package/lib/render/.eslintrc.json +4 -1
- package/lib/render/DuplicateChecker.js +8 -5
- package/lib/render/toCdl.js +112 -33
- package/lib/render/toHdbcds.js +134 -64
- package/lib/render/toSql.js +91 -38
- package/lib/render/utils/common.js +8 -13
- package/lib/render/utils/sql.js +3 -3
- package/lib/sql-identifier.js +6 -1
- package/lib/transform/db/assertUnique.js +5 -6
- package/lib/transform/db/constraints.js +29 -13
- package/lib/transform/db/draft.js +8 -6
- package/lib/transform/db/expansion.js +582 -0
- package/lib/transform/db/flattening.js +325 -0
- package/lib/transform/db/groupByOrderBy.js +2 -2
- package/lib/transform/db/transformExists.js +284 -63
- package/lib/transform/forHanaNew.js +98 -381
- package/lib/transform/forOdataNew.js +21 -22
- package/lib/transform/localized.js +37 -10
- package/lib/transform/odata/attachPath.js +19 -4
- package/lib/transform/odata/generateForeignKeyElements.js +11 -10
- package/lib/transform/odata/referenceFlattener.js +60 -39
- package/lib/transform/odata/sortByAssociationDependency.js +2 -2
- package/lib/transform/odata/structuralPath.js +72 -0
- package/lib/transform/odata/structureFlattener.js +19 -18
- package/lib/transform/odata/typesExposure.js +22 -12
- package/lib/transform/transformUtilsNew.js +134 -78
- package/lib/transform/translateAssocsToJoins.js +17 -14
- package/lib/transform/universalCsnEnricher.js +67 -0
- package/lib/utils/file.js +0 -11
- package/lib/utils/moduleResolve.js +6 -8
- package/package.json +1 -1
- package/lib/json/walker.js +0 -26
- package/lib/transform/sqlite +0 -0
- package/lib/utils/string.js +0 -17
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { forEachDefinition } = require('../base/model');
|
|
4
|
+
const {
|
|
5
|
+
applyTransformations,
|
|
6
|
+
cloneCsn,
|
|
7
|
+
getUtils,
|
|
8
|
+
isBuiltinType,
|
|
9
|
+
} = require('../model/csnUtils');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Loop through a universal CSN and enrich it with the properties
|
|
13
|
+
* from the source definition - modifies the input model in-place
|
|
14
|
+
*
|
|
15
|
+
* @param {CSN.Model} csn
|
|
16
|
+
* @param {CSN.Options} options
|
|
17
|
+
*/
|
|
18
|
+
module.exports = function(csn, options) {
|
|
19
|
+
let { getOrigin, getFinalType, getFinalTypeDef } = getUtils(csn);
|
|
20
|
+
// User-defined structured types do not have the elements propagated any longer
|
|
21
|
+
// if there is no association among the elements. For that reason,
|
|
22
|
+
// as a first step propagate the elements of these
|
|
23
|
+
forEachDefinition(csn, (def) => {
|
|
24
|
+
if (def.kind === 'type' && def.type && !def.elements) {
|
|
25
|
+
const finalType = getFinalType(def.type);
|
|
26
|
+
if (isBuiltinType(finalType)) return;
|
|
27
|
+
const finalTypeDef = getFinalTypeDef(def.type);
|
|
28
|
+
if (finalTypeDef.elements)
|
|
29
|
+
def.elements = cloneCsn(finalTypeDef.elements, options);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// as a second step, loop through all the $origin properties in the model
|
|
34
|
+
// and propagate the properties from the origin definition
|
|
35
|
+
applyTransformations(csn, {
|
|
36
|
+
'$origin': (node, _$orign, $originValue, _path, parent, propName) => {
|
|
37
|
+
if (!node.kind) { // we do not want to replace whole definitions
|
|
38
|
+
if (Array.isArray($originValue))
|
|
39
|
+
propagatePropsFromOrigin(node, propName, parent);
|
|
40
|
+
else if ($originValue.$origin && Array.isArray($originValue.$origin)) {
|
|
41
|
+
// cover the case of query entity elements where we have own and ihnerited attributes/annotations
|
|
42
|
+
propagatePropsFromOrigin($originValue, propName, parent);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}, undefined, undefined, options);
|
|
48
|
+
|
|
49
|
+
function propagatePropsFromOrigin(member, memberName, construct) {
|
|
50
|
+
// TODO: shall the $origin be kept as part of the element?
|
|
51
|
+
const origin = getOrigin(member);
|
|
52
|
+
if (origin.kind) return;
|
|
53
|
+
if (member.elements && origin.type) {
|
|
54
|
+
delete member.$origin;
|
|
55
|
+
member.type = origin.type;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
let newMember = cloneCsn(origin, options);
|
|
59
|
+
// keep targets and keys of assoc, if it was redirected
|
|
60
|
+
if (origin.type === 'cds.Association') {
|
|
61
|
+
newMember.target = member.target || newMember.target;
|
|
62
|
+
newMember.keys = member.keys || newMember.keys;
|
|
63
|
+
}
|
|
64
|
+
// TODO: check if this works fine for items/returns/actions
|
|
65
|
+
construct[memberName] = newMember;
|
|
66
|
+
}
|
|
67
|
+
}
|
package/lib/utils/file.js
CHANGED
|
@@ -15,16 +15,6 @@ function splitLines(src) {
|
|
|
15
15
|
return src.split(/\r\n?|\n/);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
/**
|
|
19
|
-
* Change Windows style line endings to Unix style
|
|
20
|
-
*
|
|
21
|
-
* @param {string} src
|
|
22
|
-
* @returns {string}
|
|
23
|
-
*/
|
|
24
|
-
function normalizeLineEndings(src) {
|
|
25
|
-
return (src && process.platform === 'win32') ? src.replace(/\r\n/g, '\n') : src;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
18
|
/**
|
|
29
19
|
* Returns filesystem utils readFile(), isFile(), realpath() for _CDS_ usage.
|
|
30
20
|
* This includes a trace as well as usage of a file cache.
|
|
@@ -181,6 +171,5 @@ function cdsFs(fileCache, enableTrace) {
|
|
|
181
171
|
|
|
182
172
|
module.exports = {
|
|
183
173
|
splitLines,
|
|
184
|
-
normalizeLineEndings,
|
|
185
174
|
cdsFs,
|
|
186
175
|
};
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
|
|
8
8
|
const path = require('path');
|
|
9
9
|
|
|
10
|
-
const { makeMessageFunction } = require('../base/messages');
|
|
11
10
|
const { cdsFs } = require('./file');
|
|
12
11
|
|
|
13
12
|
const DEFAULT_ENCODING = 'utf-8';
|
|
@@ -44,7 +43,7 @@ function adaptCdsModule(modulePath) {
|
|
|
44
43
|
* @param {object} fileCache
|
|
45
44
|
* @param {CSN.Options} options
|
|
46
45
|
*/
|
|
47
|
-
function resolveModule( dep, fileCache, options ) {
|
|
46
|
+
function resolveModule( dep, fileCache, options, messageFunctions ) {
|
|
48
47
|
const _fs = cdsFs(fileCache, options.traceFs);
|
|
49
48
|
// let opts = { extensions, basedir: dep.basedir, preserveSymlinks: false };
|
|
50
49
|
// `preserveSymlinks` option does not really work -> provide workaround anyway...
|
|
@@ -96,7 +95,7 @@ function resolveModule( dep, fileCache, options ) {
|
|
|
96
95
|
}
|
|
97
96
|
}
|
|
98
97
|
}).catch( () => {
|
|
99
|
-
_errorFileNotFound(dep, options);
|
|
98
|
+
_errorFileNotFound(dep, options, messageFunctions);
|
|
100
99
|
return false;
|
|
101
100
|
});
|
|
102
101
|
}
|
|
@@ -107,7 +106,7 @@ function resolveModule( dep, fileCache, options ) {
|
|
|
107
106
|
* @param {object} fileCache
|
|
108
107
|
* @param {CSN.Options} options
|
|
109
108
|
*/
|
|
110
|
-
function resolveModuleSync( dep, fileCache, options ) {
|
|
109
|
+
function resolveModuleSync( dep, fileCache, options, messageFunctions ) {
|
|
111
110
|
const _fs = cdsFs(fileCache, options.traceFs);
|
|
112
111
|
const opts = {
|
|
113
112
|
extensions,
|
|
@@ -129,7 +128,7 @@ function resolveModuleSync( dep, fileCache, options ) {
|
|
|
129
128
|
});
|
|
130
129
|
|
|
131
130
|
if (error) {
|
|
132
|
-
_errorFileNotFound(dep, options);
|
|
131
|
+
_errorFileNotFound(dep, options, messageFunctions);
|
|
133
132
|
return false;
|
|
134
133
|
}
|
|
135
134
|
|
|
@@ -148,7 +147,7 @@ function resolveModuleSync( dep, fileCache, options ) {
|
|
|
148
147
|
}
|
|
149
148
|
|
|
150
149
|
if (error) {
|
|
151
|
-
_errorFileNotFound(dep, options);
|
|
150
|
+
_errorFileNotFound(dep, options, messageFunctions);
|
|
152
151
|
return false;
|
|
153
152
|
}
|
|
154
153
|
|
|
@@ -161,8 +160,7 @@ function resolveModuleSync( dep, fileCache, options ) {
|
|
|
161
160
|
return result;
|
|
162
161
|
}
|
|
163
162
|
|
|
164
|
-
function _errorFileNotFound(dep, options) {
|
|
165
|
-
const { error } = makeMessageFunction( null, options, 'compile' );
|
|
163
|
+
function _errorFileNotFound(dep, options, { error }) {
|
|
166
164
|
if (dep.resolved) {
|
|
167
165
|
let resolved = path.relative( dep.basedir, dep.resolved );
|
|
168
166
|
if (options.testMode)
|
package/package.json
CHANGED
package/lib/json/walker.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Walker module provides non-recursive tree walkers with different flavours
|
|
3
|
-
* @module json/walker
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Callback of the forEach function called for each node it walks
|
|
8
|
-
* @callback forEachCallback
|
|
9
|
-
* @param {string} name of the node
|
|
10
|
-
* @param {object} node
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Loops over all elements in an object and calls the specified callback(key,obj)
|
|
15
|
-
* @param {object} obj
|
|
16
|
-
* @param {forEachCallback} callback
|
|
17
|
-
*/
|
|
18
|
-
function forEach(obj, callback) {
|
|
19
|
-
for(var key in obj) {
|
|
20
|
-
callback(key, obj[key]);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
module.exports = {
|
|
25
|
-
forEach,
|
|
26
|
-
}
|
package/lib/transform/sqlite
DELETED
|
File without changes
|
package/lib/utils/string.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// String utils
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Removes duplicate entries from the given string array.
|
|
7
|
-
*
|
|
8
|
-
* @param {string[]} strings Array of strings with duplicates
|
|
9
|
-
* @returns {string[]} strings New array with unique strings
|
|
10
|
-
*/
|
|
11
|
-
function uniqueStrings(strings) {
|
|
12
|
-
return [ ...new Set(strings) ];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
module.exports = {
|
|
16
|
-
uniqueStrings,
|
|
17
|
-
};
|