@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
|
@@ -446,11 +446,15 @@ function expandStructureReferences(csn, options, pathDelimiter, { error, info, t
|
|
|
446
446
|
if (col.ref && col.$scope !== '$magic') {
|
|
447
447
|
const _art = col._art || inspectRef(path.concat(i)).art;
|
|
448
448
|
if (_art && isStructured(_art))
|
|
449
|
-
newThing.push(...expandRef(_art, col.ref,
|
|
449
|
+
newThing.push(...expandRef(_art, col.ref, col.as, col.key || false, withAlias));
|
|
450
450
|
|
|
451
451
|
else
|
|
452
452
|
newThing.push(col);
|
|
453
453
|
}
|
|
454
|
+
else if (col.ref && col.$scope === '$magic' && ( col.ref[0] === '$user' || col.ref[0] === '$session' ) && !col.as) {
|
|
455
|
+
col.as = implicitAs(col.ref);
|
|
456
|
+
newThing.push(col);
|
|
457
|
+
}
|
|
454
458
|
else {
|
|
455
459
|
newThing.push(col);
|
|
456
460
|
}
|
|
@@ -473,7 +477,7 @@ function expandStructureReferences(csn, options, pathDelimiter, { error, info, t
|
|
|
473
477
|
*/
|
|
474
478
|
function expandRef(art, ref, alias, isKey, withAlias) {
|
|
475
479
|
const expanded = [];
|
|
476
|
-
const stack = [ [ art, ref, alias ] ];
|
|
480
|
+
const stack = [ [ art, ref, [ alias || ref[ref.length - 1] ] ] ];
|
|
477
481
|
while (stack.length > 0) {
|
|
478
482
|
const [ current, currentRef, currentAlias ] = stack.pop();
|
|
479
483
|
if (isStructured(current)) {
|
|
@@ -482,8 +486,14 @@ function expandStructureReferences(csn, options, pathDelimiter, { error, info, t
|
|
|
482
486
|
}
|
|
483
487
|
else {
|
|
484
488
|
const obj = { ref: currentRef };
|
|
485
|
-
if (withAlias)
|
|
486
|
-
|
|
489
|
+
if (withAlias) {
|
|
490
|
+
const newAlias = currentAlias.join(pathDelimiter);
|
|
491
|
+
// if (alias !== undefined) // explicit alias
|
|
492
|
+
obj.as = newAlias;
|
|
493
|
+
// alias was implicit - to later distinguish expanded s -> s.a from explicitly written s.a
|
|
494
|
+
if (alias === undefined)
|
|
495
|
+
setProp(obj, '$implicitAlias', true);
|
|
496
|
+
}
|
|
487
497
|
if (isKey)
|
|
488
498
|
obj.key = true;
|
|
489
499
|
expanded.push(obj);
|
|
@@ -542,9 +552,11 @@ function expandStructureReferences(csn, options, pathDelimiter, { error, info, t
|
|
|
542
552
|
for (const part of Object.keys(base)) {
|
|
543
553
|
if (excluding.indexOf(part) === -1) {
|
|
544
554
|
// The thing is shadowed - ignore names present because of .inline, as those "disappear"
|
|
545
|
-
if (names[part] && !subs[names[part]].inline) {
|
|
546
|
-
|
|
547
|
-
|
|
555
|
+
if (names[part] !== undefined && !subs[names[part]].inline) { // Only works for a single * - but a second is forbidden anyway
|
|
556
|
+
if (names[part] > stars[0]) { // explicit definitions BEFORE the star should stay "infront" of the star
|
|
557
|
+
replaced[part] = true;
|
|
558
|
+
star.push(subs[names[part]]);
|
|
559
|
+
}
|
|
548
560
|
}
|
|
549
561
|
else { // the thing is not shadowed - use the name from the base
|
|
550
562
|
star.push({ ref: [ part ] });
|
|
@@ -69,12 +69,32 @@ function resolveTypeReferences(csn, options, resolved, pathDelimiter) {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
const { toFinalBaseType } = transformUtils.getTransformers(csn, options, pathDelimiter);
|
|
72
|
-
// (030) - For all elements, replace derived types by final base type
|
|
73
72
|
applyTransformations(csn, {
|
|
73
|
+
cast: (parent) => {
|
|
74
|
+
// Resolve cast already - we otherwise lose .localized
|
|
75
|
+
if (parent.cast.type && !isBuiltinType(parent.cast.type))
|
|
76
|
+
toFinalBaseType(parent.cast, resolved, true);
|
|
77
|
+
},
|
|
74
78
|
type: (parent, prop, type) => {
|
|
75
79
|
if (!isBuiltinType(type)) {
|
|
76
80
|
const directLocalized = parent.localized || false;
|
|
77
81
|
toFinalBaseType(parent, resolved);
|
|
82
|
+
// structured types might not have the child-types replaced.
|
|
83
|
+
// Drill down to ensure this.
|
|
84
|
+
if (parent.elements) {
|
|
85
|
+
const stack = [ parent.elements ];
|
|
86
|
+
while (stack.length > 0) {
|
|
87
|
+
const elements = stack.pop();
|
|
88
|
+
for (const e of Object.values(elements)) {
|
|
89
|
+
if (e.type && !isBuiltinType(e.type))
|
|
90
|
+
toFinalBaseType(e, resolved);
|
|
91
|
+
|
|
92
|
+
if (e.elements)
|
|
93
|
+
stack.push(e.elements);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
78
98
|
if (!directLocalized)
|
|
79
99
|
removeLocalized(parent);
|
|
80
100
|
}
|
|
@@ -99,7 +119,7 @@ function resolveTypeReferences(csn, options, resolved, pathDelimiter) {
|
|
|
99
119
|
|
|
100
120
|
definitions[artifactName] = dummy;
|
|
101
121
|
}
|
|
102
|
-
} ]);
|
|
122
|
+
} ], true, { skipDict: { actions: true } });
|
|
103
123
|
}
|
|
104
124
|
|
|
105
125
|
/**
|
|
@@ -143,13 +163,17 @@ function flattenAllStructStepsInRefs(csn, options, resolved, pathDelimiter) {
|
|
|
143
163
|
|
|
144
164
|
parent.ref = flattenStructStepsInRef(ref, scopedPath, links, scope, resolvedLinkTypes );
|
|
145
165
|
resolved.set(parent, { links, art, scope });
|
|
146
|
-
// Because of expansion we added alias to everything - strip off superflous alias
|
|
147
|
-
if (parent.as && parent.as === parent.ref[parent.ref.length - 1] && scope !== '$magic')
|
|
148
|
-
delete parent.as;
|
|
149
166
|
// Explicitly set implicit alias for things that are now flattened - but only in columns
|
|
150
167
|
// TODO: Can this be done elegantly during expand phase already?
|
|
151
|
-
|
|
168
|
+
if (parent.$implicitAlias) { // an expanded s -> s.a is marked with this - do not add implicit alias "a" there, we want s_a
|
|
169
|
+
if (parent.ref[parent.ref.length - 1] === parent.as) // for a simple s that was expanded - for s.substructure this would not apply
|
|
170
|
+
delete parent.as;
|
|
171
|
+
delete parent.$implicitAlias;
|
|
172
|
+
}
|
|
173
|
+
// To handle explicitly written s.a - add implicit alias a, since after flattening it would otherwise be s_a
|
|
174
|
+
else if (parent.ref[parent.ref.length - 1] !== lastRef && (insideColumns(scopedPath) || insideKeys(scopedPath)) && !parent.as) {
|
|
152
175
|
parent.as = lastRef;
|
|
176
|
+
}
|
|
153
177
|
};
|
|
154
178
|
// adapt queries later
|
|
155
179
|
adaptRefs.push(fn);
|
|
@@ -263,7 +287,7 @@ function flattenElements(csn, options, pathDelimiter, error) {
|
|
|
263
287
|
previous[name] = element;
|
|
264
288
|
return previous;
|
|
265
289
|
}, Object.create(null));
|
|
266
|
-
});
|
|
290
|
+
}, true);
|
|
267
291
|
}
|
|
268
292
|
|
|
269
293
|
/**
|