@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
package/lib/main.js
CHANGED
|
@@ -18,11 +18,15 @@ const { odata, cdl, sql, hdi, hdbcds, edm, edmx } = require('./api/main');
|
|
|
18
18
|
const { getArtifactDatabaseNameOf, getElementDatabaseNameOf } = require('./model/csnUtils');
|
|
19
19
|
const { traverseCsn } = require('./model/api');
|
|
20
20
|
const { createMessageFunctions, sortMessages, sortMessagesSeverityAware, deduplicateMessages } = require('./base/messages');
|
|
21
|
+
const { smartId, smartFuncId, delimitedId } = require('./sql-identifier');
|
|
22
|
+
const keywords = require( './base/keywords' );
|
|
21
23
|
|
|
22
24
|
const parseLanguage = require('./language/antlrParser');
|
|
23
25
|
const { parseX, compileX, compileSyncX, compileSourcesX, InvocationError } = require('./compiler');
|
|
24
26
|
const { fns } = require('./compiler/shared');
|
|
25
|
-
const
|
|
27
|
+
const define = require('./compiler/define');
|
|
28
|
+
const { isInReservedNamespace } = require("./compiler/builtins");
|
|
29
|
+
const finalizeParseCdl = require('./compiler/finalize-parse-cdl');
|
|
26
30
|
|
|
27
31
|
// The compiler version (taken from package.json)
|
|
28
32
|
function version() {
|
|
@@ -41,7 +45,7 @@ const {
|
|
|
41
45
|
|
|
42
46
|
const { compactModel, compactQuery, compactExpr } = require('./json/to-csn')
|
|
43
47
|
|
|
44
|
-
function parseCdl(
|
|
48
|
+
function parseCdl( cdlSource, filename, options = {} ) {
|
|
45
49
|
options = Object.assign( {}, options, { parseCdl: true } );
|
|
46
50
|
const sources = Object.create(null);
|
|
47
51
|
/** @type {XSN.Model} */
|
|
@@ -49,26 +53,27 @@ function parseCdl( cdl, filename, options = {} ) {
|
|
|
49
53
|
const messageFunctions = createMessageFunctions( options, 'parse', model );
|
|
50
54
|
model.$messageFunctions = messageFunctions;
|
|
51
55
|
|
|
52
|
-
const xsn = parseLanguage(
|
|
56
|
+
const xsn = parseLanguage( cdlSource, filename, Object.assign( { parseOnly: true }, options ),
|
|
53
57
|
messageFunctions );
|
|
54
58
|
sources[filename] = xsn;
|
|
55
59
|
fns( model );
|
|
56
60
|
define( model );
|
|
61
|
+
finalizeParseCdl( model );
|
|
57
62
|
messageFunctions.throwWithError();
|
|
58
63
|
return compactModel( model );
|
|
59
64
|
}
|
|
60
65
|
|
|
61
|
-
function parseCql(
|
|
66
|
+
function parseCql( cdlSource, filename = '<query>.cds', options = {} ) {
|
|
62
67
|
const messageFunctions = createMessageFunctions( options, 'parse' );
|
|
63
|
-
const xsn = parseLanguage(
|
|
68
|
+
const xsn = parseLanguage( cdlSource, filename, Object.assign( { parseOnly: true }, options ),
|
|
64
69
|
messageFunctions, 'query' );
|
|
65
70
|
messageFunctions.throwWithError();
|
|
66
71
|
return compactQuery( xsn );
|
|
67
72
|
}
|
|
68
73
|
|
|
69
|
-
function parseExpr(
|
|
74
|
+
function parseExpr( cdlSource, filename = '<expr>.cds', options = {} ) {
|
|
70
75
|
const messageFunctions = createMessageFunctions( options, 'parse' );
|
|
71
|
-
const xsn = parseLanguage(
|
|
76
|
+
const xsn = parseLanguage( cdlSource, filename, Object.assign( { parseOnly: true }, options ),
|
|
72
77
|
messageFunctions, 'expr' );
|
|
73
78
|
messageFunctions.throwWithError();
|
|
74
79
|
return compactExpr( xsn );
|
|
@@ -107,10 +112,32 @@ module.exports = {
|
|
|
107
112
|
* @deprecated Use parse.cql instead
|
|
108
113
|
*/
|
|
109
114
|
parseToCqn: parseCql,
|
|
115
|
+
/**
|
|
116
|
+
* @deprecated Use parse.expr instead
|
|
117
|
+
*/
|
|
110
118
|
parseToExpr: parseExpr, // deprecated name
|
|
111
119
|
// SNAPI
|
|
112
120
|
for: { odata },
|
|
113
|
-
to: {
|
|
121
|
+
to: {
|
|
122
|
+
cdl: Object.assign(cdl, {
|
|
123
|
+
keywords: Object.freeze([ ...keywords.cdl ]),
|
|
124
|
+
functions: Object.freeze([ ...keywords.cdl_functions ]),
|
|
125
|
+
}),
|
|
126
|
+
sql: Object.assign(sql, {
|
|
127
|
+
sqlite: { keywords: Object.freeze([ ...keywords.sqlite ] )},
|
|
128
|
+
smartId,
|
|
129
|
+
smartFunctionId: smartFuncId,
|
|
130
|
+
delimitedId,
|
|
131
|
+
}),
|
|
132
|
+
hdi: Object.assign(hdi, {
|
|
133
|
+
keywords: Object.freeze([ ...keywords.hana ]),
|
|
134
|
+
}),
|
|
135
|
+
hdbcds: Object.assign(hdbcds, {
|
|
136
|
+
keywords: Object.freeze([ ...keywords.hdbcds ]),
|
|
137
|
+
}),
|
|
138
|
+
edm,
|
|
139
|
+
edmx
|
|
140
|
+
},
|
|
114
141
|
// Convenience for hdbtabledata calculation in @sap/cds
|
|
115
142
|
getArtifactCdsPersistenceName: getArtifactDatabaseNameOf,
|
|
116
143
|
getElementCdsPersistenceName: getElementDatabaseNameOf,
|
|
@@ -121,5 +148,10 @@ module.exports = {
|
|
|
121
148
|
// INTERNAL functions for the cds-lsp package and friends - before you use
|
|
122
149
|
// it, you MUST talk with us - there can be potential incompatibilities with
|
|
123
150
|
// new releases (even having the same major version):
|
|
124
|
-
$lsp: { parse: parseX, compile: compileX },
|
|
151
|
+
$lsp: { parse: parseX, compile: compileX, getArtifactName: a => a.name },
|
|
152
|
+
|
|
153
|
+
// CSN Model related functionality
|
|
154
|
+
model: {
|
|
155
|
+
isInReservedNamespace,
|
|
156
|
+
},
|
|
125
157
|
};
|
package/lib/model/api.js
CHANGED
|
@@ -28,12 +28,14 @@ const defaultFunctions = {
|
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* Traverse the CSN node `csn`.
|
|
31
|
+
*
|
|
31
32
|
* If `csn` is an array, call it recursively on each array item.
|
|
32
33
|
* If `csn` is an(other) object, call a function on each property:
|
|
33
34
|
* - The property name is a used as key in argument `userFunctions` and the
|
|
34
35
|
* constant `defaultFunctions` above to get the function which is called on
|
|
35
36
|
* the property value, see `defaultFunctions` for details.
|
|
36
|
-
* - If no function is found with the property name, try to find one with the
|
|
37
|
+
* - If no function is found with the property name, try to find one with the
|
|
38
|
+
* first char, which is useful for annotations.
|
|
37
39
|
* - If still not found, call `traverseCsn` recursively.
|
|
38
40
|
*
|
|
39
41
|
* The functions in `userFunctions` are usually transformer functions, which
|