@sap/cds-compiler 2.12.0 → 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 +110 -15
- package/bin/cdsc.js +13 -13
- 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 +28 -63
- package/lib/api/options.js +3 -3
- package/lib/api/validate.js +0 -5
- 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 +25 -4
- package/lib/base/messages.js +16 -26
- package/lib/base/model.js +2 -63
- package/lib/base/optionProcessorHelper.js +158 -123
- package/lib/checks/annotationsOData.js +1 -1
- 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 +4 -7
- package/lib/compiler/assert-consistency.js +5 -3
- package/lib/compiler/builtins.js +8 -6
- package/lib/compiler/checks.js +14 -3
- 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 +32 -13
- 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 +111 -46
- package/lib/compiler/resolve.js +1433 -0
- package/lib/compiler/shared.js +64 -37
- package/lib/compiler/tweak-assocs.js +529 -0
- package/lib/compiler/utils.js +197 -33
- package/lib/edm/.eslintrc.json +5 -0
- package/lib/edm/annotations/genericTranslation.js +5 -9
- package/lib/edm/annotations/preprocessAnnotations.js +2 -2
- package/lib/edm/csn2edm.js +9 -8
- package/lib/edm/edm.js +11 -12
- package/lib/edm/edmPreprocessor.js +137 -73
- package/lib/edm/edmUtils.js +116 -22
- package/lib/gen/Dictionary.json +10 -3
- package/lib/gen/language.checksum +1 -1
- package/lib/gen/language.interp +9 -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 +5282 -4265
- package/lib/json/from-csn.js +12 -1
- package/lib/json/to-csn.js +126 -66
- package/lib/language/docCommentParser.js +2 -2
- package/lib/language/genericAntlrParser.js +76 -3
- package/lib/language/language.g4 +297 -130
- package/lib/language/multiLineStringParser.js +5 -5
- package/lib/main.d.ts +468 -59
- package/lib/main.js +35 -9
- package/lib/model/api.js +3 -1
- package/lib/model/csnRefs.js +225 -156
- package/lib/model/csnUtils.js +192 -223
- package/lib/model/enrichCsn.js +70 -29
- package/lib/model/revealInternalProperties.js +27 -6
- package/lib/model/sortViews.js +2 -1
- package/lib/modelCompare/compare.js +17 -12
- package/lib/optionProcessor.js +5 -4
- package/lib/render/manageConstraints.js +35 -32
- package/lib/render/toCdl.js +73 -288
- package/lib/render/toHdbcds.js +25 -23
- package/lib/render/toSql.js +98 -41
- package/lib/render/utils/common.js +5 -10
- 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 +2 -0
- package/lib/transform/db/applyTransformations.js +35 -12
- package/lib/transform/db/assertUnique.js +1 -1
- package/lib/transform/db/associations.js +103 -305
- package/lib/transform/db/cdsPersistence.js +2 -2
- package/lib/transform/db/constraints.js +55 -52
- package/lib/transform/db/expansion.js +46 -24
- package/lib/transform/db/flattening.js +553 -102
- package/lib/transform/db/groupByOrderBy.js +3 -1
- package/lib/transform/db/transformExists.js +59 -6
- package/lib/transform/db/views.js +5 -4
- 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 +67 -183
- package/lib/transform/forOdataNew.js +17 -171
- package/lib/transform/localized.js +34 -19
- package/lib/transform/odata/generateForeignKeyElements.js +1 -1
- 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 +36 -22
- package/lib/transform/translateAssocsToJoins.js +2 -19
- 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/objectUtils.js +30 -0
- package/package.json +1 -1
- package/share/messages/README.md +26 -0
- package/lib/compiler/definer.js +0 -2361
- package/lib/compiler/resolver.js +0 -3079
- package/lib/transform/universalCsnEnricher.js +0 -237
package/lib/main.js
CHANGED
|
@@ -18,11 +18,14 @@ 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 finalizeParseCdl = require('./compiler/finalize-parse-cdl');
|
|
26
29
|
|
|
27
30
|
// The compiler version (taken from package.json)
|
|
28
31
|
function version() {
|
|
@@ -41,7 +44,7 @@ const {
|
|
|
41
44
|
|
|
42
45
|
const { compactModel, compactQuery, compactExpr } = require('./json/to-csn')
|
|
43
46
|
|
|
44
|
-
function parseCdl(
|
|
47
|
+
function parseCdl( cdlSource, filename, options = {} ) {
|
|
45
48
|
options = Object.assign( {}, options, { parseCdl: true } );
|
|
46
49
|
const sources = Object.create(null);
|
|
47
50
|
/** @type {XSN.Model} */
|
|
@@ -49,26 +52,27 @@ function parseCdl( cdl, filename, options = {} ) {
|
|
|
49
52
|
const messageFunctions = createMessageFunctions( options, 'parse', model );
|
|
50
53
|
model.$messageFunctions = messageFunctions;
|
|
51
54
|
|
|
52
|
-
const xsn = parseLanguage(
|
|
55
|
+
const xsn = parseLanguage( cdlSource, filename, Object.assign( { parseOnly: true }, options ),
|
|
53
56
|
messageFunctions );
|
|
54
57
|
sources[filename] = xsn;
|
|
55
58
|
fns( model );
|
|
56
59
|
define( model );
|
|
60
|
+
finalizeParseCdl( model );
|
|
57
61
|
messageFunctions.throwWithError();
|
|
58
62
|
return compactModel( model );
|
|
59
63
|
}
|
|
60
64
|
|
|
61
|
-
function parseCql(
|
|
65
|
+
function parseCql( cdlSource, filename = '<query>.cds', options = {} ) {
|
|
62
66
|
const messageFunctions = createMessageFunctions( options, 'parse' );
|
|
63
|
-
const xsn = parseLanguage(
|
|
67
|
+
const xsn = parseLanguage( cdlSource, filename, Object.assign( { parseOnly: true }, options ),
|
|
64
68
|
messageFunctions, 'query' );
|
|
65
69
|
messageFunctions.throwWithError();
|
|
66
70
|
return compactQuery( xsn );
|
|
67
71
|
}
|
|
68
72
|
|
|
69
|
-
function parseExpr(
|
|
73
|
+
function parseExpr( cdlSource, filename = '<expr>.cds', options = {} ) {
|
|
70
74
|
const messageFunctions = createMessageFunctions( options, 'parse' );
|
|
71
|
-
const xsn = parseLanguage(
|
|
75
|
+
const xsn = parseLanguage( cdlSource, filename, Object.assign( { parseOnly: true }, options ),
|
|
72
76
|
messageFunctions, 'expr' );
|
|
73
77
|
messageFunctions.throwWithError();
|
|
74
78
|
return compactExpr( xsn );
|
|
@@ -107,10 +111,32 @@ module.exports = {
|
|
|
107
111
|
* @deprecated Use parse.cql instead
|
|
108
112
|
*/
|
|
109
113
|
parseToCqn: parseCql,
|
|
114
|
+
/**
|
|
115
|
+
* @deprecated Use parse.expr instead
|
|
116
|
+
*/
|
|
110
117
|
parseToExpr: parseExpr, // deprecated name
|
|
111
118
|
// SNAPI
|
|
112
119
|
for: { odata },
|
|
113
|
-
to: {
|
|
120
|
+
to: {
|
|
121
|
+
cdl: Object.assign(cdl, {
|
|
122
|
+
keywords: Object.freeze([ ...keywords.cdl ]),
|
|
123
|
+
functions: Object.freeze([ ...keywords.cdl_functions ]),
|
|
124
|
+
}),
|
|
125
|
+
sql: Object.assign(sql, {
|
|
126
|
+
sqlite: { keywords: Object.freeze([ ...keywords.sqlite ] )},
|
|
127
|
+
smartId,
|
|
128
|
+
smartFunctionId: smartFuncId,
|
|
129
|
+
delimitedId,
|
|
130
|
+
}),
|
|
131
|
+
hdi: Object.assign(hdi, {
|
|
132
|
+
keywords: Object.freeze([ ...keywords.hana ]),
|
|
133
|
+
}),
|
|
134
|
+
hdbcds: Object.assign(hdbcds, {
|
|
135
|
+
keywords: Object.freeze([ ...keywords.hdbcds ]),
|
|
136
|
+
}),
|
|
137
|
+
edm,
|
|
138
|
+
edmx
|
|
139
|
+
},
|
|
114
140
|
// Convenience for hdbtabledata calculation in @sap/cds
|
|
115
141
|
getArtifactCdsPersistenceName: getArtifactDatabaseNameOf,
|
|
116
142
|
getElementCdsPersistenceName: getElementDatabaseNameOf,
|
|
@@ -121,5 +147,5 @@ module.exports = {
|
|
|
121
147
|
// INTERNAL functions for the cds-lsp package and friends - before you use
|
|
122
148
|
// it, you MUST talk with us - there can be potential incompatibilities with
|
|
123
149
|
// new releases (even having the same major version):
|
|
124
|
-
$lsp: { parse: parseX, compile: compileX },
|
|
150
|
+
$lsp: { parse: parseX, compile: compileX, getArtifactName: a => a.name },
|
|
125
151
|
};
|
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
|