@sap/cds-compiler 2.7.0 → 2.11.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 +167 -0
- package/bin/cdsc.js +42 -25
- package/bin/cdsse.js +1 -0
- package/doc/CHANGELOG_BETA.md +10 -0
- package/lib/api/.eslintrc.json +2 -0
- package/lib/api/main.js +17 -33
- package/lib/api/options.js +25 -13
- package/lib/api/validate.js +33 -9
- package/lib/backends.js +9 -8
- package/lib/base/dictionaries.js +2 -1
- package/lib/base/keywords.js +32 -2
- package/lib/base/message-registry.js +26 -2
- package/lib/base/messages.js +25 -9
- package/lib/base/model.js +5 -3
- package/lib/base/optionProcessorHelper.js +56 -22
- package/lib/checks/onConditions.js +5 -0
- package/lib/checks/selectItems.js +4 -0
- package/lib/checks/types.js +26 -2
- package/lib/checks/unknownMagic.js +41 -0
- package/lib/checks/validator.js +7 -2
- package/lib/compiler/assert-consistency.js +18 -5
- package/lib/compiler/base.js +65 -0
- package/lib/compiler/builtins.js +30 -1
- package/lib/compiler/checks.js +5 -2
- package/lib/compiler/definer.js +145 -120
- package/lib/compiler/index.js +16 -4
- package/lib/compiler/propagator.js +5 -2
- package/lib/compiler/resolver.js +207 -47
- package/lib/compiler/shared.js +47 -200
- package/lib/compiler/utils.js +173 -0
- package/lib/edm/annotations/genericTranslation.js +183 -187
- package/lib/edm/csn2edm.js +94 -98
- package/lib/edm/edm.js +16 -20
- package/lib/edm/edmPreprocessor.js +302 -115
- package/lib/edm/edmUtils.js +31 -12
- package/lib/gen/language.checksum +1 -1
- package/lib/gen/language.interp +28 -1
- package/lib/gen/language.tokens +79 -69
- package/lib/gen/languageLexer.interp +28 -1
- package/lib/gen/languageLexer.js +879 -805
- package/lib/gen/languageLexer.tokens +71 -62
- package/lib/gen/languageParser.js +5308 -4308
- package/lib/json/from-csn.js +59 -30
- package/lib/json/to-csn.js +354 -105
- package/lib/language/antlrParser.js +11 -0
- package/lib/language/errorStrategy.js +1 -0
- package/lib/language/genericAntlrParser.js +81 -14
- package/lib/language/language.g4 +163 -31
- package/lib/main.d.ts +136 -17
- package/lib/main.js +7 -1
- package/lib/model/api.js +78 -0
- package/lib/model/csnRefs.js +115 -32
- package/lib/model/csnUtils.js +71 -33
- package/lib/model/enrichCsn.js +36 -9
- package/lib/model/revealInternalProperties.js +20 -4
- package/lib/modelCompare/compare.js +2 -1
- package/lib/optionProcessor.js +33 -16
- package/lib/render/.eslintrc.json +3 -1
- package/lib/render/DuplicateChecker.js +1 -1
- package/lib/render/toCdl.js +60 -17
- package/lib/render/toHdbcds.js +122 -74
- package/lib/render/toSql.js +57 -32
- package/lib/render/utils/common.js +6 -10
- package/lib/sql-identifier.js +6 -1
- package/lib/transform/db/constraints.js +273 -119
- package/lib/transform/db/draft.js +9 -6
- package/lib/transform/db/expansion.js +19 -7
- package/lib/transform/db/flattening.js +31 -7
- package/lib/transform/db/transformExists.js +344 -66
- package/lib/transform/db/views.js +438 -0
- package/lib/transform/forHanaNew.js +65 -436
- package/lib/transform/forOdataNew.js +21 -10
- package/lib/transform/localized.js +2 -0
- package/lib/transform/odata/attachPath.js +19 -4
- package/lib/transform/odata/generateForeignKeyElements.js +11 -10
- package/lib/transform/odata/referenceFlattener.js +44 -38
- package/lib/transform/odata/sortByAssociationDependency.js +2 -2
- package/lib/transform/odata/structuralPath.js +72 -0
- package/lib/transform/odata/structureFlattener.js +13 -10
- package/lib/transform/odata/typesExposure.js +22 -12
- package/lib/transform/transformUtilsNew.js +55 -9
- package/lib/transform/translateAssocsToJoins.js +11 -17
- package/lib/transform/universalCsnEnricher.js +67 -0
- package/lib/utils/file.js +5 -3
- package/lib/utils/term.js +65 -42
- package/lib/utils/timetrace.js +48 -26
- package/package.json +1 -1
package/lib/edm/edmUtils.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
const { setProp } = require('../base/model');
|
|
2
3
|
const { isBuiltinType, isEdmPropertyRendered } = require('../model/csnUtils');
|
|
3
4
|
|
|
4
5
|
/* eslint max-statements-per-line:off */
|
|
@@ -114,6 +115,12 @@ function isToMany(assoc) {
|
|
|
114
115
|
return targetMax === '*' || Number(targetMax) > 1;
|
|
115
116
|
}
|
|
116
117
|
|
|
118
|
+
function isSingleton(entityCsn, v) {
|
|
119
|
+
const singleton = entityCsn['@odata.singleton'];
|
|
120
|
+
const hasNullable = entityCsn['@odata.singleton.nullable'] !== undefined && entityCsn['@odata.singleton.nullable'] !== null;
|
|
121
|
+
return v && singleton || ((singleton === undefined || singleton === null) && hasNullable);
|
|
122
|
+
}
|
|
123
|
+
|
|
117
124
|
function isEntity(artifact)
|
|
118
125
|
{
|
|
119
126
|
return ['entity'].includes(artifact.kind);
|
|
@@ -154,7 +161,7 @@ function resolveOnConditionAndPrepareConstraints(csn, assocCsn, messageFunctions
|
|
|
154
161
|
getExpressionArguments(assocCsn.on);
|
|
155
162
|
|
|
156
163
|
// for all $self conditions, fill constraints of partner (if any)
|
|
157
|
-
let isBacklink = assocCsn._constraints.selfs.length
|
|
164
|
+
let isBacklink = assocCsn._constraints.selfs.length === 1 && assocCsn._constraints.termCount === 1;
|
|
158
165
|
|
|
159
166
|
/* example for _originalTarget:
|
|
160
167
|
entity E (with parameters) {
|
|
@@ -172,10 +179,12 @@ function resolveOnConditionAndPrepareConstraints(csn, assocCsn, messageFunctions
|
|
|
172
179
|
const originAssocCsn = resolveOriginAssoc(csn, (assocCsn._originalTarget || assocCsn._target), partnerPath);
|
|
173
180
|
const parentName = assocCsn.$abspath[0];
|
|
174
181
|
const parent = csn.definitions[parentName];
|
|
175
|
-
const originParentName = originAssocCsn.$abspath[0];
|
|
176
182
|
if(originAssocCsn) {
|
|
177
|
-
|
|
183
|
+
const originParentName = originAssocCsn.$abspath[0];
|
|
184
|
+
if(parent.$mySchemaName && originAssocCsn._originalTarget !== parent && originAssocCsn._target !== parent) {
|
|
178
185
|
isBacklink = false;
|
|
186
|
+
// Partnership is ambiguous
|
|
187
|
+
setProp(originAssocCsn, '$noPartner', true);
|
|
179
188
|
info(null, ['definitions', parentName, 'elements', assocCsn.name],
|
|
180
189
|
`"${originParentName}:${partnerPath.join('.')}" with target "${originAssocCsn._target.name}" is compared with $self which represents "${parentName}"`);
|
|
181
190
|
}
|
|
@@ -183,14 +192,17 @@ function resolveOnConditionAndPrepareConstraints(csn, assocCsn, messageFunctions
|
|
|
183
192
|
// Mark this association as backlink if $self appears exactly once
|
|
184
193
|
// to surpress edm:Association generation in V2 mode
|
|
185
194
|
if(isBacklink) {
|
|
186
|
-
//
|
|
195
|
+
// establish partnership with origin assoc but only if this association is the first one
|
|
187
196
|
if(originAssocCsn._selfReferences.length === 0) {
|
|
188
197
|
assocCsn._constraints._partnerCsn = originAssocCsn;
|
|
189
198
|
}
|
|
190
199
|
else {
|
|
191
200
|
isBacklink = false;
|
|
192
201
|
}
|
|
193
|
-
|
|
202
|
+
}
|
|
203
|
+
// store all backlinks at forward, required to calculate rendering of foreign keys
|
|
204
|
+
// if the termCount != 1 or more than one $self compare this is not a backlink
|
|
205
|
+
if(parent.$mySchemaName && assocCsn._constraints.selfs.length === 1 && assocCsn._constraints.termCount === 1) {
|
|
194
206
|
originAssocCsn._selfReferences.push(assocCsn);
|
|
195
207
|
}
|
|
196
208
|
assocCsn._constraints._origins.push(originAssocCsn);
|
|
@@ -512,7 +524,7 @@ function determineMultiplicity(csn)
|
|
|
512
524
|
|
|
513
525
|
function mapCdsToEdmType(csn, messageFunctions, isV2=false, isMediaType=false)
|
|
514
526
|
{
|
|
515
|
-
const {
|
|
527
|
+
const { error } = messageFunctions || { error: ()=>true };
|
|
516
528
|
let cdsType = csn.type;
|
|
517
529
|
if(cdsType === undefined) {
|
|
518
530
|
error(null, csn.$location, `no type found`);
|
|
@@ -581,8 +593,6 @@ function mapCdsToEdmType(csn, messageFunctions, isV2=false, isMediaType=false)
|
|
|
581
593
|
if(['cds.hana.ST_POINT', 'cds.hana.ST_GEOMETRY'].includes(cdsType)) {
|
|
582
594
|
error(null, csn.$path, { type: cdsType }, `OData V2 does not support Geometry data types, $(TYPE) can't be mapped`);
|
|
583
595
|
}
|
|
584
|
-
if(cdsType === 'cds.DecimalFloat' || cdsType === 'cds.hana.SMALLDECIMAL')
|
|
585
|
-
warning(null, csn.$path, { type: cdsType }, `OData V2 does not support $(TYPE)`);
|
|
586
596
|
}
|
|
587
597
|
else // isV4
|
|
588
598
|
{
|
|
@@ -609,13 +619,21 @@ function addTypeFacets(node, csn)
|
|
|
609
619
|
// node.Precision = 16;
|
|
610
620
|
else if (csn.type === 'cds.Timestamp' && node.Type === 'Edm.DateTimeOffset')
|
|
611
621
|
node.Precision = 7;
|
|
612
|
-
|
|
622
|
+
if([ 'cds.Decimal', 'cds.DecimalFloat', 'cds.hana.SMALLDECIMAL' ].includes(csn.type)) {
|
|
613
623
|
if(isV2) {
|
|
614
|
-
|
|
624
|
+
// no prec/scale or scale is 'floating'/'variable'
|
|
625
|
+
if(!(csn.precision || csn.scale) || ['floating', 'variable'].includes(csn.scale)) {
|
|
626
|
+
node.setXml( { 'sap:variable-scale': true } );
|
|
627
|
+
delete node.Scale;
|
|
628
|
+
}
|
|
615
629
|
}
|
|
616
630
|
else {
|
|
617
|
-
//
|
|
618
|
-
node.
|
|
631
|
+
// map both floating and variable to => variable
|
|
632
|
+
if(node.Scale === 'floating')
|
|
633
|
+
node.Scale = 'variable';
|
|
634
|
+
if(!csn.precision && !csn.scale)
|
|
635
|
+
// if Decimal has no p, s set scale 'variable'
|
|
636
|
+
node.setXml( { Scale: 'variable' } ); // floating is V4.01
|
|
619
637
|
}
|
|
620
638
|
}
|
|
621
639
|
// Unicode unused today
|
|
@@ -698,6 +716,7 @@ module.exports = {
|
|
|
698
716
|
isComposition,
|
|
699
717
|
isAssociationOrComposition,
|
|
700
718
|
isToMany,
|
|
719
|
+
isSingleton,
|
|
701
720
|
isEntity,
|
|
702
721
|
isStructuredType,
|
|
703
722
|
isStructuredArtifact,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
e80280336eed20b6633835d33df8ec76
|