@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
package/lib/model/api.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Miscellaneous CSN functions we put into our compiler API
|
|
2
|
+
|
|
3
|
+
// Do not change at will - they are in the compiler API!
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Dictionary of default traversal functions for function `traverseCsn`.
|
|
7
|
+
* It maps CSN property names to functions which are used by default
|
|
8
|
+
* to traverse the CSN node which is the value of the corresponding property.
|
|
9
|
+
* Users specify their own traversal function via argument `userFunctions`.
|
|
10
|
+
*
|
|
11
|
+
* Each function in `userFunctions` and `defaultFunctions` is called with:
|
|
12
|
+
* - `userFunctions`
|
|
13
|
+
* - the current CSN node, i.e. ‹parent node›.‹property name›
|
|
14
|
+
* - the the ‹parent node›
|
|
15
|
+
* - the ‹property name› (might be useful if the same function is used for several props)
|
|
16
|
+
*/
|
|
17
|
+
const defaultFunctions = {
|
|
18
|
+
'@': () => {}, // do not traverse annotation assignments
|
|
19
|
+
args: dictionary,
|
|
20
|
+
elements: dictionary,
|
|
21
|
+
enum: dictionary,
|
|
22
|
+
params: dictionary,
|
|
23
|
+
actions: dictionary,
|
|
24
|
+
mixin: dictionary,
|
|
25
|
+
definitions: dictionary,
|
|
26
|
+
'$': () => {}, // do not traverse properties starting with '$'
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Traverse the CSN node `csn`.
|
|
31
|
+
* If `csn` is an array, call it recursively on each array item.
|
|
32
|
+
* If `csn` is an(other) object, call a function on each property:
|
|
33
|
+
* - The property name is a used as key in argument `userFunctions` and the
|
|
34
|
+
* constant `defaultFunctions` above to get the function which is called on
|
|
35
|
+
* the property value, see `defaultFunctions` for details.
|
|
36
|
+
* - If no function is found with the property name, try to find one with the first char.
|
|
37
|
+
* - If still not found, call `traverseCsn` recursively.
|
|
38
|
+
*
|
|
39
|
+
* The functions in `userFunctions` are usually transformer functions, which
|
|
40
|
+
* change the input CSN destructively.
|
|
41
|
+
*/
|
|
42
|
+
function traverseCsn( userFunctions, csn ) {
|
|
43
|
+
if (!csn || typeof csn !== 'object')
|
|
44
|
+
return;
|
|
45
|
+
if (Array.isArray( csn )) {
|
|
46
|
+
csn.forEach( node => traverseCsn( userFunctions, node ) );
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
for (const prop of Object.keys( csn )) {
|
|
50
|
+
const func = userFunctions[prop] || defaultFunctions[prop] ||
|
|
51
|
+
userFunctions[prop.charAt(0)] || defaultFunctions[prop.charAt(0)] ||
|
|
52
|
+
traverseCsn;
|
|
53
|
+
func( userFunctions, csn[prop], csn, prop );
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// people might want to have their own traversal function for `elements`, etc:
|
|
58
|
+
traverseCsn.dictionary = dictionary;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Traverse the CSN dictionary node `csn`.
|
|
62
|
+
* Call `traverseCsn` on each property value in `csn`, passing down `userFunctions`.
|
|
63
|
+
*/
|
|
64
|
+
function dictionary( userFunctions, csn ) {
|
|
65
|
+
if (!csn || typeof csn !== 'object')
|
|
66
|
+
return;
|
|
67
|
+
if (Array.isArray( csn )) { // args can be both array and dictionary
|
|
68
|
+
csn.forEach( node => traverseCsn( userFunctions, node ) );
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
for (const name of Object.keys( csn ))
|
|
72
|
+
traverseCsn( userFunctions, csn[name] );
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
module.exports = {
|
|
77
|
+
traverseCsn,
|
|
78
|
+
};
|