@sap/cds-compiler 6.3.6 → 6.4.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 +101 -3
- package/LICENSE +32 -0
- package/README.md +14 -2
- package/bin/cdsse.js +0 -3
- package/doc/CHANGELOG_BETA.md +1 -1
- package/doc/CHANGELOG_DEPRECATED.md +1 -1
- package/lib/base/message-registry.js +9 -2
- package/lib/base/messages.js +1 -1
- package/lib/base/model.js +2 -0
- package/lib/checks/existsExpressionsOnlyForeignKeys.js +16 -10
- package/lib/checks/existsMustEndInAssoc.js +1 -1
- package/lib/checks/existsMustNotStartWithDollarSelf.js +31 -0
- package/lib/checks/validator.js +4 -2
- package/lib/compiler/assert-consistency.js +3 -2
- package/lib/compiler/builtins.js +5 -6
- package/lib/compiler/checks.js +37 -26
- package/lib/compiler/define.js +1 -1
- package/lib/compiler/extend.js +39 -50
- package/lib/compiler/finalize-parse-cdl.js +1 -1
- package/lib/compiler/lsp-api.js +1 -1
- package/lib/compiler/populate.js +2 -2
- package/lib/compiler/propagator.js +29 -6
- package/lib/compiler/resolve.js +13 -3
- package/lib/compiler/shared.js +157 -133
- package/lib/compiler/tweak-assocs.js +87 -29
- package/lib/compiler/xpr-rewrite.js +164 -160
- package/lib/edm/annotations/edmJson.js +206 -37
- package/lib/edm/csn2edm.js +13 -0
- package/lib/edm/edmUtils.js +2 -2
- package/lib/gen/BaseParser.js +106 -72
- package/lib/gen/CdlGrammar.checksum +1 -1
- package/lib/gen/CdlParser.js +1501 -1509
- package/lib/json/to-csn.js +8 -5
- package/lib/language/genericAntlrParser.js +0 -0
- package/lib/main.js +19 -16
- package/lib/model/csnRefs.js +589 -521
- package/lib/model/csnUtils.js +8 -5
- package/lib/model/enrichCsn.js +1 -0
- package/lib/parsers/AstBuildingParser.js +73 -28
- package/lib/render/toCdl.js +2 -1
- package/lib/render/toHdbcds.js +6 -3
- package/lib/render/toSql.js +5 -0
- package/lib/transform/db/applyTransformations.js +1 -1
- package/lib/transform/db/assertUnique.js +4 -1
- package/lib/transform/db/assocsToQueries/transformExists.js +3 -10
- package/lib/transform/db/assocsToQueries/utils.js +0 -5
- package/lib/transform/db/cdsPersistence.js +17 -18
- package/lib/transform/db/expansion.js +179 -3
- package/lib/transform/db/flattening.js +16 -5
- package/lib/transform/db/rewriteCalculatedElements.js +79 -283
- package/lib/transform/effective/main.js +8 -1
- package/lib/transform/forOdata.js +1 -1
- package/lib/transform/forRelationalDB.js +21 -80
- package/lib/transform/localized.js +75 -127
- package/lib/transform/odata/foreignKeyRefsInXprAnnos.js +89 -63
- package/lib/transform/transformUtils.js +23 -21
- package/lib/transform/translateAssocsToJoins.js +7 -5
- package/lib/transform/tupleExpansion.js +16 -3
- package/package.json +3 -3
- package/doc/DeprecatedOptions_v2.md +0 -150
- package/doc/NameResolution.md +0 -837
- package/lib/transform/parseExpr.js +0 -415
package/lib/json/to-csn.js
CHANGED
|
@@ -31,7 +31,6 @@ const normalizedKind = {
|
|
|
31
31
|
let gensrcFlavor = true; // good enough here...
|
|
32
32
|
let universalCsn = false;
|
|
33
33
|
let strictMode = false; // whether to dump with unknown properties (in standard)
|
|
34
|
-
/** @type {boolean|string} */
|
|
35
34
|
let withLocations = false;
|
|
36
35
|
let withDocComments = false;
|
|
37
36
|
let structXpr = false;
|
|
@@ -121,6 +120,7 @@ const transformers = {
|
|
|
121
120
|
default: expression,
|
|
122
121
|
targetElement, // special display of foreign key
|
|
123
122
|
value: enumValueOrCalc, // do not list for select items as elements
|
|
123
|
+
$calc: enumValueOrCalc,
|
|
124
124
|
query,
|
|
125
125
|
elements,
|
|
126
126
|
actions: sortedDict, // TODO: just normal dictionary
|
|
@@ -253,7 +253,7 @@ function compactModel( model, options = model.options || {} ) {
|
|
|
253
253
|
const loc = srcDict[first].location;
|
|
254
254
|
if (loc && loc.file) {
|
|
255
255
|
Object.defineProperty( csn, '$location', {
|
|
256
|
-
value: { file: loc.file }, configurable: true, writable: true, enumerable:
|
|
256
|
+
value: { file: loc.file }, configurable: true, writable: true, enumerable: withLocations,
|
|
257
257
|
} );
|
|
258
258
|
}
|
|
259
259
|
set( '$extra', csn, srcDict[first] );
|
|
@@ -612,7 +612,7 @@ function addLocation( loc, csn ) {
|
|
|
612
612
|
val.endCol = loc.endCol;
|
|
613
613
|
}
|
|
614
614
|
Object.defineProperty( csn, '$location', {
|
|
615
|
-
value: val, configurable: true, writable: true, enumerable:
|
|
615
|
+
value: val, configurable: true, writable: true, enumerable: withLocations,
|
|
616
616
|
} );
|
|
617
617
|
}
|
|
618
618
|
return csn;
|
|
@@ -1165,19 +1165,22 @@ function targetElement( val, csn, node ) {
|
|
|
1165
1165
|
Object.assign(csn, key);
|
|
1166
1166
|
}
|
|
1167
1167
|
|
|
1168
|
-
function enumValueOrCalc( v, csn, node ) {
|
|
1168
|
+
function enumValueOrCalc( v, csn, node, prop ) {
|
|
1169
1169
|
if (v.$inferred && (universalCsn || gensrcFlavor))
|
|
1170
1170
|
return undefined;
|
|
1171
1171
|
// Enum values in CSN are without outer `value: { … }`:
|
|
1172
1172
|
if (node.kind === 'enum') {
|
|
1173
1173
|
Object.assign( csn, expression( v ) );
|
|
1174
1174
|
}
|
|
1175
|
+
else if (v === true && prop === '$calc') {
|
|
1176
|
+
return true; // calculation has used non-projected elements
|
|
1177
|
+
}
|
|
1175
1178
|
// In XSN, there are combined elem/column objects: do not represent column
|
|
1176
1179
|
// expression when presented as element in CSN
|
|
1177
1180
|
|
|
1178
1181
|
// node.$syntax set in define.el(!), but not inside an `extend`, a _parent might
|
|
1179
1182
|
// not be set always for parse-only, especially with CSN input
|
|
1180
|
-
else if (node.$syntax === 'calc' ||
|
|
1183
|
+
else if (node.$syntax === 'calc' || prop === '$calc' ||
|
|
1181
1184
|
!node._parent || node._parent.kind === 'extend') {
|
|
1182
1185
|
const stored = v.stored ? { stored: value(v.stored) } : {};
|
|
1183
1186
|
return Object.assign( stored, expression( v ) );
|
|
File without changes
|
package/lib/main.js
CHANGED
|
@@ -20,7 +20,7 @@ const { traceApi } = require('./api/trace');
|
|
|
20
20
|
|
|
21
21
|
const snapi = lazyload('./api/main');
|
|
22
22
|
const csnUtils = lazyload('./model/csnUtils');
|
|
23
|
-
const
|
|
23
|
+
const modelApi = lazyload('./model/api');
|
|
24
24
|
const messages = lazyload('./base/messages');
|
|
25
25
|
const sqlIdentifier = lazyload('./sql-identifier');
|
|
26
26
|
const keywords = lazyload( './base/keywords' );
|
|
@@ -37,13 +37,15 @@ const lsp = lazyload('./compiler/lsp-api');
|
|
|
37
37
|
const meta = lazyload('./base/meta');
|
|
38
38
|
|
|
39
39
|
|
|
40
|
-
const toCsn = lazyload('./json/to-csn')
|
|
40
|
+
const toCsn = lazyload('./json/to-csn');
|
|
41
41
|
|
|
42
42
|
function parseCdl( cdlSource, filename, options = {} ) {
|
|
43
43
|
options = Object.assign( {}, options, { parseCdl: true } );
|
|
44
44
|
const sources = Object.create(null);
|
|
45
45
|
/** @type {XSN.Model} */
|
|
46
|
-
const model = {
|
|
46
|
+
const model = {
|
|
47
|
+
sources, options, $functions: {}, $volatileFunctions: {},
|
|
48
|
+
};
|
|
47
49
|
const messageFunctions = messages.createMessageFunctions( options, 'parse', model );
|
|
48
50
|
model.$messageFunctions = messageFunctions;
|
|
49
51
|
|
|
@@ -73,7 +75,8 @@ function parseExpr( cdlSource, filename = '<expr>.cds', options = {} ) {
|
|
|
73
75
|
return toCsn.compactExpr( xsn );
|
|
74
76
|
}
|
|
75
77
|
|
|
76
|
-
// FIXME: The implementation of those functions that delegate to 'backends'
|
|
78
|
+
// FIXME: The implementation of those functions that delegate to 'backends'
|
|
79
|
+
// should probably move here
|
|
77
80
|
// ATTENTION: Keep in sync with main.d.ts!
|
|
78
81
|
module.exports = {
|
|
79
82
|
// Compiler
|
|
@@ -96,7 +99,7 @@ module.exports = {
|
|
|
96
99
|
value: messages.CompilationError,
|
|
97
100
|
writable: false,
|
|
98
101
|
configurable: false,
|
|
99
|
-
enumerable: true
|
|
102
|
+
enumerable: true,
|
|
100
103
|
});
|
|
101
104
|
return messages.CompilationError;
|
|
102
105
|
},
|
|
@@ -113,7 +116,7 @@ module.exports = {
|
|
|
113
116
|
value: compiler.InvocationError,
|
|
114
117
|
writable: false,
|
|
115
118
|
configurable: false,
|
|
116
|
-
enumerable: false
|
|
119
|
+
enumerable: false,
|
|
117
120
|
});
|
|
118
121
|
return compiler.InvocationError;
|
|
119
122
|
},
|
|
@@ -123,7 +126,7 @@ module.exports = {
|
|
|
123
126
|
parse: {
|
|
124
127
|
cdl: (...args) => parseCdl(...args),
|
|
125
128
|
cql: (...args) => parseCql(...args),
|
|
126
|
-
expr: (...args) => parseExpr(...args)
|
|
129
|
+
expr: (...args) => parseExpr(...args),
|
|
127
130
|
},
|
|
128
131
|
// SNAPI
|
|
129
132
|
for: {
|
|
@@ -143,13 +146,13 @@ module.exports = {
|
|
|
143
146
|
sql: Object.assign((...args) => snapi.sql(...args), {
|
|
144
147
|
migration: (...args) => snapi.sql.migration(...args),
|
|
145
148
|
sqlite: {
|
|
146
|
-
keywords: Object.freeze([ ...keywords.sqlite ] )
|
|
149
|
+
keywords: Object.freeze([ ...keywords.sqlite ] ),
|
|
147
150
|
},
|
|
148
151
|
postgres: {
|
|
149
|
-
keywords: Object.freeze([ ...keywords.postgres ] )
|
|
152
|
+
keywords: Object.freeze([ ...keywords.postgres ] ),
|
|
150
153
|
},
|
|
151
154
|
h2: {
|
|
152
|
-
keywords: Object.freeze([ ...keywords.h2 ] )
|
|
155
|
+
keywords: Object.freeze([ ...keywords.h2 ] ),
|
|
153
156
|
},
|
|
154
157
|
smartId: (...args) => sqlIdentifier.smartId(...args),
|
|
155
158
|
smartFunctionId: (...args) => sqlIdentifier.smartFuncId(...args),
|
|
@@ -163,13 +166,13 @@ module.exports = {
|
|
|
163
166
|
keywords: Object.freeze([ ...keywords.hdbcds ] ),
|
|
164
167
|
}),
|
|
165
168
|
edm: Object.assign((...args) => snapi.edm(...args), {
|
|
166
|
-
all: (...args) => snapi.edm.all(...args)
|
|
169
|
+
all: (...args) => snapi.edm.all(...args),
|
|
167
170
|
}),
|
|
168
171
|
edmx: Object.assign((...args) => snapi.edmx(...args), {
|
|
169
|
-
all: (...args) => snapi.edmx.all(...args)
|
|
172
|
+
all: (...args) => snapi.edmx.all(...args),
|
|
170
173
|
}),
|
|
171
174
|
odata: Object.assign((...args) => snapi.odata2(...args), {
|
|
172
|
-
all: (...args) => snapi.odata2.all(...args)
|
|
175
|
+
all: (...args) => snapi.odata2.all(...args),
|
|
173
176
|
}),
|
|
174
177
|
},
|
|
175
178
|
// Convenience for hdbtabledata calculation in @sap/cds
|
|
@@ -177,7 +180,7 @@ module.exports = {
|
|
|
177
180
|
getElementCdsPersistenceName: (...args) => csnUtils.getElementDatabaseNameOf(...args),
|
|
178
181
|
|
|
179
182
|
// Other API functions:
|
|
180
|
-
traverseCsn: (...args) =>
|
|
183
|
+
traverseCsn: (...args) => modelApi.traverseCsn(...args),
|
|
181
184
|
|
|
182
185
|
// INTERNAL functions for the cds-lsp package and friends - before you use
|
|
183
186
|
// it, you MUST talk with us - there can be potential incompatibilities with
|
|
@@ -185,9 +188,9 @@ module.exports = {
|
|
|
185
188
|
$lsp: {
|
|
186
189
|
parse: (...args) => compiler.parseX(...args),
|
|
187
190
|
compile: (...args) => compiler.compileX(...args),
|
|
188
|
-
getArtifactName:
|
|
191
|
+
getArtifactName: art => base.getArtifactName(art),
|
|
189
192
|
traverseSemanticTokens: (xsn, options) => lsp.traverseSemanticTokens(xsn, options),
|
|
190
|
-
getSemanticTokenOrigin:
|
|
193
|
+
getSemanticTokenOrigin: obj => lsp.getSemanticTokenOrigin(obj),
|
|
191
194
|
},
|
|
192
195
|
|
|
193
196
|
// CSN Model related functionality
|