@sap/cds-compiler 2.11.2 → 2.13.6
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 +175 -2
- package/bin/.eslintrc.json +1 -2
- package/bin/cds_update_identifiers.js +10 -8
- package/bin/cdsc.js +23 -17
- package/bin/cdsse.js +2 -2
- package/bin/cdsv2m.js +3 -2
- package/doc/CHANGELOG_ARCHIVE.md +1 -1
- package/doc/CHANGELOG_BETA.md +25 -6
- package/doc/CHANGELOG_DEPRECATED.md +22 -6
- package/doc/NameResolution.md +21 -16
- package/lib/api/main.js +32 -79
- package/lib/api/options.js +3 -2
- package/lib/api/validate.js +2 -1
- package/lib/backends.js +16 -26
- package/lib/base/dictionaries.js +0 -8
- package/lib/base/error.js +26 -0
- package/lib/base/keywords.js +10 -19
- package/lib/base/location.js +9 -4
- package/lib/base/message-registry.js +75 -9
- package/lib/base/messages.js +31 -35
- package/lib/base/model.js +2 -62
- package/lib/base/optionProcessorHelper.js +246 -183
- package/lib/checks/.eslintrc.json +2 -0
- package/lib/checks/actionsFunctions.js +2 -1
- package/lib/checks/annotationsOData.js +1 -1
- package/lib/checks/cdsPersistence.js +2 -1
- package/lib/checks/emptyOrOnlyVirtual.js +2 -2
- package/lib/checks/enricher.js +17 -1
- package/lib/checks/foreignKeys.js +4 -4
- package/lib/checks/invalidTarget.js +3 -1
- package/lib/checks/managedInType.js +4 -4
- package/lib/checks/managedWithoutKeys.js +3 -1
- package/lib/checks/queryNoDbArtifacts.js +1 -3
- package/lib/checks/selectItems.js +4 -4
- package/lib/checks/sql-snippets.js +94 -0
- package/lib/checks/types.js +1 -1
- package/lib/checks/unknownMagic.js +1 -1
- package/lib/checks/validator.js +12 -7
- package/lib/compiler/assert-consistency.js +12 -8
- package/lib/compiler/base.js +0 -1
- package/lib/compiler/builtins.js +42 -21
- package/lib/compiler/checks.js +46 -12
- package/lib/compiler/cycle-detector.js +1 -1
- package/lib/compiler/define.js +1103 -0
- package/lib/compiler/extend.js +983 -0
- package/lib/compiler/finalize-parse-cdl.js +231 -0
- package/lib/compiler/index.js +46 -39
- package/lib/compiler/kick-start.js +190 -0
- package/lib/compiler/moduleLayers.js +4 -4
- package/lib/compiler/populate.js +1226 -0
- package/lib/compiler/propagator.js +113 -47
- package/lib/compiler/resolve.js +1433 -0
- package/lib/compiler/shared.js +100 -65
- package/lib/compiler/tweak-assocs.js +529 -0
- package/lib/compiler/utils.js +215 -33
- package/lib/edm/.eslintrc.json +5 -0
- package/lib/edm/annotations/genericTranslation.js +38 -25
- package/lib/edm/annotations/preprocessAnnotations.js +3 -3
- package/lib/edm/csn2edm.js +10 -9
- package/lib/edm/edm.js +19 -20
- package/lib/edm/edmPreprocessor.js +166 -95
- package/lib/edm/edmUtils.js +127 -34
- package/lib/gen/Dictionary.json +92 -43
- package/lib/gen/language.checksum +1 -1
- package/lib/gen/language.interp +11 -1
- package/lib/gen/language.tokens +86 -82
- package/lib/gen/languageLexer.interp +18 -1
- package/lib/gen/languageLexer.js +925 -847
- package/lib/gen/languageLexer.tokens +78 -74
- package/lib/gen/languageParser.js +5434 -4298
- package/lib/json/from-csn.js +59 -17
- package/lib/json/to-csn.js +189 -71
- package/lib/language/antlrParser.js +3 -3
- package/lib/language/docCommentParser.js +3 -3
- package/lib/language/errorStrategy.js +26 -8
- package/lib/language/genericAntlrParser.js +144 -53
- package/lib/language/language.g4 +424 -200
- package/lib/language/multiLineStringParser.js +536 -0
- package/lib/main.d.ts +550 -61
- package/lib/main.js +38 -11
- package/lib/model/api.js +3 -1
- package/lib/model/csnRefs.js +322 -198
- package/lib/model/csnUtils.js +226 -370
- package/lib/model/enrichCsn.js +124 -69
- package/lib/model/revealInternalProperties.js +29 -7
- package/lib/model/sortViews.js +10 -2
- package/lib/modelCompare/compare.js +17 -12
- package/lib/optionProcessor.js +8 -3
- package/lib/render/.eslintrc.json +1 -2
- package/lib/render/DuplicateChecker.js +1 -1
- package/lib/render/manageConstraints.js +36 -33
- package/lib/render/toCdl.js +174 -275
- package/lib/render/toHdbcds.js +203 -122
- package/lib/render/toRename.js +7 -10
- package/lib/render/toSql.js +161 -82
- package/lib/render/utils/common.js +22 -8
- package/lib/render/utils/sql.js +10 -7
- 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/braceExpression.js +4 -2
- package/lib/transform/db/.eslintrc.json +2 -0
- package/lib/transform/db/applyTransformations.js +212 -0
- package/lib/transform/db/assertUnique.js +1 -1
- package/lib/transform/db/associations.js +187 -0
- package/lib/transform/db/cdsPersistence.js +150 -0
- package/lib/transform/db/constraints.js +61 -56
- package/lib/transform/db/expansion.js +50 -29
- package/lib/transform/db/flattening.js +556 -106
- package/lib/transform/db/groupByOrderBy.js +3 -1
- package/lib/transform/db/temporal.js +236 -0
- package/lib/transform/db/transformExists.js +103 -28
- package/lib/transform/db/views.js +92 -44
- package/lib/transform/draft/.eslintrc.json +38 -0
- package/lib/transform/{db/draft.js → draft/db.js} +9 -7
- package/lib/transform/draft/odata.js +227 -0
- package/lib/transform/forHanaNew.js +98 -783
- package/lib/transform/forOdataNew.js +22 -175
- package/lib/transform/localized.js +36 -32
- package/lib/transform/odata/generateForeignKeyElements.js +3 -3
- package/lib/transform/odata/referenceFlattener.js +95 -89
- package/lib/transform/odata/structureFlattener.js +1 -1
- package/lib/transform/odata/toFinalBaseType.js +86 -12
- package/lib/transform/odata/typesExposure.js +5 -5
- package/lib/transform/odata/utils.js +2 -2
- package/lib/transform/transformUtilsNew.js +47 -33
- package/lib/transform/translateAssocsToJoins.js +13 -30
- package/lib/transform/universalCsn/.eslintrc.json +36 -0
- package/lib/transform/universalCsn/coreComputed.js +170 -0
- package/lib/transform/universalCsn/universalCsnEnricher.js +715 -0
- package/lib/transform/universalCsn/utils.js +63 -0
- package/lib/utils/file.js +8 -3
- package/lib/utils/objectUtils.js +30 -0
- package/lib/utils/timetrace.js +8 -2
- package/package.json +1 -1
- package/share/messages/README.md +26 -0
- package/lib/compiler/definer.js +0 -2349
- package/lib/compiler/resolver.js +0 -2922
- package/lib/transform/db/helpers.js +0 -58
- package/lib/transform/universalCsnEnricher.js +0 -67
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
applyTransformations,
|
|
5
|
+
} = require('../../model/csnUtils');
|
|
6
|
+
const { setProp } = require('../../base/model');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Set the annotation on the carrier if it is not already present.
|
|
10
|
+
*
|
|
11
|
+
* @param {object} carrier Object having/getting the annotation
|
|
12
|
+
* @param {string} name Name of the annotations
|
|
13
|
+
* @param {any} value Value of the annotation
|
|
14
|
+
*/
|
|
15
|
+
function setAnnotationIfNotDefined(carrier, name, value) {
|
|
16
|
+
if (carrier[name] === undefined)
|
|
17
|
+
carrier[name] = value;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Strip/change the CSN to ensure compatibility with what we have in the client CSN
|
|
22
|
+
* - Removes every occurrence of '$origin', '$generated' and '$source'
|
|
23
|
+
* - elements of subqueries become non-enumerable
|
|
24
|
+
* - remove `actions|params|virtual|notNull: null`, this stops the inheritance of the actions/params/virtual
|
|
25
|
+
* along the $origin chain, this can be ignored for the comparison in our tests.
|
|
26
|
+
*
|
|
27
|
+
* @param {CSN.Model} csn
|
|
28
|
+
*/
|
|
29
|
+
function makeClientCompatible(csn) {
|
|
30
|
+
applyTransformations(csn, {
|
|
31
|
+
actions: removeNullProperty,
|
|
32
|
+
notNull: removeNullProperty,
|
|
33
|
+
params: removeNullProperty,
|
|
34
|
+
virtual: removeNullProperty,
|
|
35
|
+
$origin: (parent, prop) => delete parent[prop],
|
|
36
|
+
$generated: (parent, prop) => delete parent[prop],
|
|
37
|
+
$source: (parent, prop) => delete parent[prop],
|
|
38
|
+
SELECT: (parent, prop, query) => {
|
|
39
|
+
if (query.elements)
|
|
40
|
+
setProp(query, 'elements', query.elements);
|
|
41
|
+
},
|
|
42
|
+
SET: (parent, prop, query) => {
|
|
43
|
+
if (query.elements)
|
|
44
|
+
setProp(query, 'elements', query.elements);
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Removes the `prop` from the `node` if `prop === null`
|
|
51
|
+
*
|
|
52
|
+
* @param {object} node
|
|
53
|
+
* @param {string} prop
|
|
54
|
+
*/
|
|
55
|
+
function removeNullProperty(node, prop) {
|
|
56
|
+
if (node[prop] === null)
|
|
57
|
+
delete node[prop];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
module.exports = {
|
|
61
|
+
setAnnotationIfNotDefined,
|
|
62
|
+
makeClientCompatible,
|
|
63
|
+
};
|
package/lib/utils/file.js
CHANGED
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
5
|
const fs = require('fs');
|
|
6
|
+
const util = require('util');
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Split the given source string into its lines. Respects Unix,
|
|
9
|
-
* Windows
|
|
10
|
+
* Windows and Macintosh line breaks.
|
|
10
11
|
*
|
|
11
12
|
* @param {string} src
|
|
12
13
|
* @returns {string[]}
|
|
@@ -19,8 +20,8 @@ function splitLines(src) {
|
|
|
19
20
|
* Returns filesystem utils readFile(), isFile(), realpath() for _CDS_ usage.
|
|
20
21
|
* This includes a trace as well as usage of a file cache.
|
|
21
22
|
*
|
|
22
|
-
* Note: The synchronous versions accept a callback
|
|
23
|
-
* immediately! This is different from NodeJS's readFileSync()!
|
|
23
|
+
* Note: The synchronous versions accept a callback instead of being async (duh!), which
|
|
24
|
+
* is executed immediately! This is different from NodeJS's readFileSync()!
|
|
24
25
|
* This is done to allow using it in places where fs.readFile (async) is used.
|
|
25
26
|
*
|
|
26
27
|
* @param {object} fileCache
|
|
@@ -47,10 +48,14 @@ function cdsFs(fileCache, enableTrace) {
|
|
|
47
48
|
});
|
|
48
49
|
|
|
49
50
|
return {
|
|
51
|
+
/** @type {function(string, string)} */
|
|
52
|
+
readFileAsync: util.promisify(readFile),
|
|
50
53
|
readFile,
|
|
51
54
|
readFileSync,
|
|
55
|
+
isFileAsync: util.promisify(isFile),
|
|
52
56
|
isFile,
|
|
53
57
|
isFileSync,
|
|
58
|
+
realpathAsync: util.promisify(realpath),
|
|
54
59
|
realpath,
|
|
55
60
|
realpathSync,
|
|
56
61
|
};
|
package/lib/utils/objectUtils.js
CHANGED
|
@@ -42,8 +42,38 @@ function forEach(obj, callback) {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Loops over all elements in an object and calls the specified callback(o[key]) for each key
|
|
47
|
+
* --> can be used as substitute for `Object.values(…).forEach(…)`
|
|
48
|
+
*
|
|
49
|
+
* @param {object} o the object which values should be iterated
|
|
50
|
+
* @param {Function} callback
|
|
51
|
+
*/
|
|
52
|
+
function forEachValue(o, callback) {
|
|
53
|
+
for (const key in o) {
|
|
54
|
+
if (Object.hasOwnProperty.call(o, key))
|
|
55
|
+
callback(o[key]);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Loops over all elements in an object and calls the specified callback(key) for each key
|
|
61
|
+
* --> can be used as substitute for `Object.keys(…).forEach(…)`
|
|
62
|
+
*
|
|
63
|
+
* @param {object} o the object which keys should be iterated
|
|
64
|
+
* @param {Function} callback
|
|
65
|
+
*/
|
|
66
|
+
function forEachKey(o, callback) {
|
|
67
|
+
for (const key in o) {
|
|
68
|
+
if (Object.hasOwnProperty.call(o, key))
|
|
69
|
+
callback(key);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
45
73
|
module.exports = {
|
|
46
74
|
copyPropIfExist,
|
|
47
75
|
createDict,
|
|
48
76
|
forEach,
|
|
77
|
+
forEachValue,
|
|
78
|
+
forEachKey,
|
|
49
79
|
};
|
package/lib/utils/timetrace.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* A single
|
|
4
|
+
* A single StopWatch encapsulates the runtime of a selected code frame.
|
|
5
5
|
*
|
|
6
6
|
* @class TimeTrace
|
|
7
7
|
*/
|
|
@@ -14,6 +14,8 @@ class StopWatch {
|
|
|
14
14
|
*/
|
|
15
15
|
constructor(id) {
|
|
16
16
|
this.id = id;
|
|
17
|
+
// TODO: If we require Node 12, use process.hrtime.bigint()
|
|
18
|
+
// as process.hrtime() is deprecated.
|
|
17
19
|
// eslint-disable-next-line no-multi-assign
|
|
18
20
|
this.startTime = this.lapTime = process.hrtime();
|
|
19
21
|
}
|
|
@@ -123,4 +125,8 @@ const ignoreTimeTrace = {
|
|
|
123
125
|
};
|
|
124
126
|
|
|
125
127
|
const doTimeTrace = process && process.env && process.env.CDSC_TIMETRACING !== undefined;
|
|
126
|
-
module.exports = {
|
|
128
|
+
module.exports = {
|
|
129
|
+
timetrace: (doTimeTrace ? new TimeTracer() : ignoreTimeTrace),
|
|
130
|
+
TimeTracer,
|
|
131
|
+
StopWatch,
|
|
132
|
+
};
|
package/package.json
CHANGED
package/share/messages/README.md
CHANGED
|
@@ -30,3 +30,29 @@ Furthermore:
|
|
|
30
30
|
If users open the message in a terminal, it is often 80 characters wide.
|
|
31
31
|
Even if that was not the case, longer lines are harder to read, so keep them
|
|
32
32
|
short.
|
|
33
|
+
|
|
34
|
+
## Example Structure
|
|
35
|
+
|
|
36
|
+
```markdown
|
|
37
|
+
# ‹message-id›
|
|
38
|
+
|
|
39
|
+
Longer message text. Some background info.
|
|
40
|
+
Usually mentions the severity.
|
|
41
|
+
|
|
42
|
+
## Example
|
|
43
|
+
|
|
44
|
+
Code which also lead to the current message,
|
|
45
|
+
with an explanation why it is problematic.
|
|
46
|
+
|
|
47
|
+
## How to Fix
|
|
48
|
+
|
|
49
|
+
Description of options how the issue can be fixed, using the example.
|
|
50
|
+
|
|
51
|
+
## Notes on …
|
|
52
|
+
|
|
53
|
+
Optional: more background info.
|
|
54
|
+
|
|
55
|
+
## Related messages
|
|
56
|
+
|
|
57
|
+
- Optional: message ids for similar issues.
|
|
58
|
+
```
|