@sap/cds-compiler 5.1.0 → 5.2.0
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 +32 -0
- package/bin/cdsc.js +2 -2
- package/bin/cdshi.js +24 -17
- package/bin/cdsse.js +17 -18
- package/lib/api/main.js +19 -2
- package/lib/api/options.js +4 -1
- package/lib/base/builtins.js +1 -0
- package/lib/base/message-registry.js +16 -3
- package/lib/base/model.js +0 -10
- package/lib/checks/actionsFunctions.js +0 -12
- package/lib/checks/structuredAnnoExpressions.js +10 -14
- package/lib/compiler/assert-consistency.js +19 -11
- package/lib/compiler/builtins.js +1 -1
- package/lib/compiler/define.js +6 -4
- package/lib/compiler/extend.js +5 -5
- package/lib/compiler/populate.js +9 -9
- package/lib/compiler/propagator.js +1 -0
- package/lib/compiler/resolve.js +29 -34
- package/lib/compiler/shared.js +7 -8
- package/lib/compiler/tweak-assocs.js +155 -64
- package/lib/compiler/utils.js +1 -1
- package/lib/compiler/xpr-rewrite.js +4 -3
- package/lib/edm/annotations/genericTranslation.js +13 -9
- package/lib/edm/csn2edm.js +26 -2
- package/lib/edm/edm.js +23 -8
- package/lib/edm/edmInboundChecks.js +5 -7
- package/lib/edm/edmPreprocessor.js +43 -30
- package/lib/gen/BaseParser.js +720 -0
- package/lib/gen/CdlParser.js +4421 -0
- package/lib/gen/language.checksum +1 -1
- package/lib/gen/language.interp +1 -1
- package/lib/gen/languageParser.js +4006 -4001
- package/lib/language/antlrParser.js +62 -0
- package/lib/language/genericAntlrParser.js +28 -0
- package/lib/model/csnUtils.js +2 -0
- package/lib/model/revealInternalProperties.js +2 -0
- package/lib/modelCompare/utils/filter.js +70 -42
- package/lib/optionProcessor.js +9 -3
- package/lib/parsers/AstBuildingParser.js +1172 -0
- package/lib/parsers/CdlGrammar.g4 +1940 -0
- package/lib/parsers/Lexer.js +239 -0
- package/lib/render/toCdl.js +23 -27
- package/lib/render/toSql.js +5 -5
- package/lib/transform/db/applyTransformations.js +54 -16
- package/lib/transform/draft/odata.js +10 -11
- package/lib/transform/effective/flattening.js +10 -14
- package/lib/transform/odata/flattening.js +42 -31
- package/lib/transform/odata/toFinalBaseType.js +7 -6
- package/lib/transform/universalCsn/universalCsnEnricher.js +1 -0
- package/package.json +2 -2
- package/share/messages/redirected-to-ambiguous.md +5 -4
|
@@ -5,7 +5,7 @@ const { setProp, isDeprecatedEnabled, isBetaEnabled } = require('../base/model')
|
|
|
5
5
|
const {
|
|
6
6
|
forEachDefinition, forEachGeneric, forEachMemberRecursively,
|
|
7
7
|
isEdmPropertyRendered, getUtils,
|
|
8
|
-
applyTransformations,
|
|
8
|
+
applyTransformations, transformAnnotationExpression, findAnnotationExpression,
|
|
9
9
|
cardinality2str,
|
|
10
10
|
} = require('../model/csnUtils');
|
|
11
11
|
const { isBuiltinType, isMagicVariable } = require('../base/builtins');
|
|
@@ -1890,12 +1890,12 @@ function initializeModel( csn, _options, messageFunctions, requestedServiceNames
|
|
|
1890
1890
|
mapCdsToEdmProp(def.returns);
|
|
1891
1891
|
annotateAllowedValues(def.returns, [ ...defLocation, 'returns' ]);
|
|
1892
1892
|
}
|
|
1893
|
-
forEachMemberRecursively(def, (member, _memberName,
|
|
1893
|
+
forEachMemberRecursively(def, (member, _memberName, prop, location) => {
|
|
1894
1894
|
edmUtils.assignAnnotation(member, '@Core.Description', member.doc);
|
|
1895
1895
|
markCollection(member);
|
|
1896
1896
|
mapCdsToEdmProp(member);
|
|
1897
1897
|
annotateAllowedValues(member, location);
|
|
1898
|
-
ComputedDefaultValue(member);
|
|
1898
|
+
ComputedDefaultValue(member, prop, location);
|
|
1899
1899
|
rewriteAnnotationExpressions(member);
|
|
1900
1900
|
if (member.returns) {
|
|
1901
1901
|
edmUtils.assignAnnotation(member.returns, '@Core.Description', member.returns.doc);
|
|
@@ -2082,8 +2082,6 @@ function initializeModel( csn, _options, messageFunctions, requestedServiceNames
|
|
|
2082
2082
|
parameters appear rightmost.
|
|
2083
2083
|
*/
|
|
2084
2084
|
function annotateOptionalActFuncParams( def, defName ) {
|
|
2085
|
-
if (!isBetaEnabled(options, 'optionalActionFunctionParameters'))
|
|
2086
|
-
return;
|
|
2087
2085
|
// return if there is nothing to do
|
|
2088
2086
|
const loc = [ 'definitions', defName ];
|
|
2089
2087
|
if (def.kind === 'function' || def.kind === 'action')
|
|
@@ -2098,32 +2096,43 @@ function initializeModel( csn, _options, messageFunctions, requestedServiceNames
|
|
|
2098
2096
|
function iterateParams( action, location ) {
|
|
2099
2097
|
let optPns = [];
|
|
2100
2098
|
if (action.params) {
|
|
2101
|
-
Object.
|
|
2099
|
+
Object.entries(action.params).forEach(([ pn, p ]) => {
|
|
2102
2100
|
// user assigned annotation, don't touch it
|
|
2101
|
+
const defT = reqDefs.definitions[p.items?.type || p.type];
|
|
2102
|
+
const isStructType = !!(defT?.items?.elements || defT?.elements);
|
|
2103
|
+
const isItems = !!(p.items || defT?.items);
|
|
2104
|
+
|
|
2103
2105
|
if (Object.keys(p).some(a => a.startsWith('@Core.OptionalParameter') && p[a] !== null)) {
|
|
2104
2106
|
optPns.push(p);
|
|
2105
2107
|
}
|
|
2106
2108
|
// default value automatically makes param optional
|
|
2107
|
-
else if (
|
|
2108
|
-
if (p.default
|
|
2109
|
-
|
|
2110
|
-
|
|
2109
|
+
else if (isBetaEnabled(options, 'optionalActionFunctionParameters')) {
|
|
2110
|
+
if (p.default?.val !== undefined) {
|
|
2111
|
+
if (p.default.val !== null && (isStructType || isItems)) {
|
|
2112
|
+
warning('odata-ignoring-param-default', location.concat(pn), { '#': 'colitem' });
|
|
2113
|
+
}
|
|
2114
|
+
else {
|
|
2115
|
+
edmUtils.assignAnnotation(p, '@Core.OptionalParameter.DefaultValue', p.default.val);
|
|
2116
|
+
optPns.push(p);
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
// if no default is available, nullable makes param optional
|
|
2120
|
+
else if (!p.notNull) {
|
|
2111
2121
|
edmUtils.assignAnnotation(p, '@Core.OptionalParameter.$Type', '');
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2122
|
+
optPns.push(p);
|
|
2123
|
+
}
|
|
2124
|
+
else {
|
|
2125
|
+
// this is a mandatory parameter, warn about all previously collected optional parameters
|
|
2126
|
+
optPns.forEach((op) => {
|
|
2127
|
+
const type = op.items?.type || op.type;
|
|
2128
|
+
if (type !== special$self)
|
|
2129
|
+
error('odata-parameter-order', location.concat(op.name));
|
|
2130
|
+
});
|
|
2131
|
+
optPns = [];
|
|
2132
|
+
}
|
|
2118
2133
|
}
|
|
2119
|
-
else {
|
|
2120
|
-
|
|
2121
|
-
optPns.forEach((op) => {
|
|
2122
|
-
const type = op.items?.type || op.type;
|
|
2123
|
-
if (type !== special$self)
|
|
2124
|
-
error('odata-parameter-order', location.concat(op.name));
|
|
2125
|
-
});
|
|
2126
|
-
optPns = [];
|
|
2134
|
+
else if (p.default) {
|
|
2135
|
+
warning('odata-ignoring-param-default', location.concat(pn));
|
|
2127
2136
|
}
|
|
2128
2137
|
});
|
|
2129
2138
|
}
|
|
@@ -2152,7 +2161,7 @@ function initializeModel( csn, _options, messageFunctions, requestedServiceNames
|
|
|
2152
2161
|
}
|
|
2153
2162
|
}
|
|
2154
2163
|
|
|
2155
|
-
function ComputedDefaultValue( member ) {
|
|
2164
|
+
function ComputedDefaultValue( member, prop, location ) {
|
|
2156
2165
|
if (member.default && !csn['@Core.ComputedDefaultValue']) {
|
|
2157
2166
|
let def = member.default;
|
|
2158
2167
|
let noTailExpr = false;
|
|
@@ -2166,8 +2175,12 @@ function initializeModel( csn, _options, messageFunctions, requestedServiceNames
|
|
|
2166
2175
|
def = def.xpr[i];
|
|
2167
2176
|
}
|
|
2168
2177
|
// it is a computed value if it is not a simple value or an annotation
|
|
2169
|
-
if (!((def.val !== undefined && !noTailExpr) || def['#']))
|
|
2170
|
-
|
|
2178
|
+
if (!((def.val !== undefined && !noTailExpr) || def['#'])) {
|
|
2179
|
+
if (prop === 'params')
|
|
2180
|
+
warning('odata-ignoring-param-default', location, { '#': 'xpr' });
|
|
2181
|
+
else
|
|
2182
|
+
edmUtils.assignAnnotation(member, '@Core.ComputedDefaultValue', true);
|
|
2183
|
+
}
|
|
2171
2184
|
}
|
|
2172
2185
|
}
|
|
2173
2186
|
|
|
@@ -2258,13 +2271,13 @@ function initializeModel( csn, _options, messageFunctions, requestedServiceNames
|
|
|
2258
2271
|
|
|
2259
2272
|
xprANames.forEach((xprAName) => {
|
|
2260
2273
|
isSubTreeSpan = true;
|
|
2261
|
-
|
|
2274
|
+
transformAnnotationExpression(carrier, xprAName, subTreeSpan);
|
|
2262
2275
|
if (isSubTreeSpan) {
|
|
2263
|
-
|
|
2276
|
+
transformAnnotationExpression(carrier, xprAName, relativize);
|
|
2264
2277
|
}
|
|
2265
2278
|
else {
|
|
2266
2279
|
absolutize.scope = scope;
|
|
2267
|
-
|
|
2280
|
+
transformAnnotationExpression(carrier, xprAName, absolutize);
|
|
2268
2281
|
if (!def[proxyDict])
|
|
2269
2282
|
setProp(def, proxyDict, Object.create(null));
|
|
2270
2283
|
let proxyCarrier = def[proxyDict][eltPath];
|