@sap/cds-compiler 2.11.4 → 2.13.8
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 +159 -1
- package/bin/cds_update_identifiers.js +7 -7
- package/bin/cdsc.js +22 -23
- package/bin/cdsse.js +2 -2
- package/doc/CHANGELOG_ARCHIVE.md +1 -1
- package/doc/CHANGELOG_BETA.md +25 -6
- package/doc/CHANGELOG_DEPRECATED.md +22 -6
- package/doc/NameResolution.md +21 -16
- package/lib/api/main.js +30 -63
- package/lib/api/options.js +5 -5
- 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 +52 -2
- package/lib/base/messages.js +16 -26
- package/lib/base/model.js +2 -62
- package/lib/base/optionProcessorHelper.js +246 -183
- package/lib/checks/.eslintrc.json +2 -0
- package/lib/checks/actionsFunctions.js +2 -1
- package/lib/checks/annotationsOData.js +1 -1
- package/lib/checks/cdsPersistence.js +2 -1
- package/lib/checks/enricher.js +17 -1
- package/lib/checks/foreignKeys.js +4 -4
- package/lib/checks/invalidTarget.js +3 -1
- package/lib/checks/managedInType.js +4 -4
- package/lib/checks/managedWithoutKeys.js +3 -1
- package/lib/checks/queryNoDbArtifacts.js +1 -3
- package/lib/checks/selectItems.js +4 -4
- package/lib/checks/sql-snippets.js +94 -0
- package/lib/checks/types.js +1 -1
- package/lib/checks/validator.js +12 -7
- package/lib/compiler/assert-consistency.js +10 -6
- package/lib/compiler/base.js +0 -1
- package/lib/compiler/builtins.js +8 -6
- package/lib/compiler/checks.js +46 -12
- 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 +33 -14
- 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 +113 -47
- package/lib/compiler/resolve.js +1433 -0
- package/lib/compiler/shared.js +76 -38
- package/lib/compiler/tweak-assocs.js +529 -0
- package/lib/compiler/utils.js +204 -33
- package/lib/edm/.eslintrc.json +5 -0
- package/lib/edm/annotations/genericTranslation.js +38 -25
- package/lib/edm/annotations/preprocessAnnotations.js +3 -3
- package/lib/edm/csn2edm.js +10 -9
- package/lib/edm/edm.js +19 -20
- package/lib/edm/edmPreprocessor.js +166 -95
- package/lib/edm/edmUtils.js +127 -34
- package/lib/gen/Dictionary.json +92 -43
- package/lib/gen/language.checksum +1 -1
- package/lib/gen/language.interp +11 -1
- package/lib/gen/language.tokens +86 -82
- package/lib/gen/languageLexer.interp +18 -1
- package/lib/gen/languageLexer.js +925 -847
- package/lib/gen/languageLexer.tokens +78 -74
- package/lib/gen/languageParser.js +5434 -4298
- package/lib/json/from-csn.js +59 -17
- package/lib/json/to-csn.js +143 -71
- package/lib/language/antlrParser.js +3 -3
- package/lib/language/docCommentParser.js +3 -3
- package/lib/language/genericAntlrParser.js +144 -54
- package/lib/language/language.g4 +424 -203
- package/lib/language/multiLineStringParser.js +536 -0
- package/lib/main.d.ts +472 -61
- package/lib/main.js +38 -11
- package/lib/model/api.js +3 -1
- package/lib/model/csnRefs.js +321 -204
- package/lib/model/csnUtils.js +224 -263
- package/lib/model/enrichCsn.js +97 -40
- 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 +7 -6
- package/lib/render/DuplicateChecker.js +1 -1
- package/lib/render/manageConstraints.js +36 -33
- package/lib/render/toCdl.js +174 -275
- package/lib/render/toHdbcds.js +201 -115
- package/lib/render/toRename.js +7 -10
- package/lib/render/toSql.js +149 -75
- package/lib/render/utils/common.js +22 -8
- package/lib/render/utils/sql.js +10 -7
- 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/braceExpression.js +4 -2
- 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 +187 -0
- package/lib/transform/db/cdsPersistence.js +150 -0
- package/lib/transform/db/constraints.js +61 -56
- package/lib/transform/db/expansion.js +50 -29
- package/lib/transform/db/flattening.js +552 -105
- package/lib/transform/db/groupByOrderBy.js +3 -1
- package/lib/transform/db/temporal.js +236 -0
- package/lib/transform/db/transformExists.js +94 -28
- 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} +9 -7
- package/lib/transform/draft/odata.js +227 -0
- package/lib/transform/forHanaNew.js +94 -801
- package/lib/transform/forOdataNew.js +22 -175
- package/lib/transform/localized.js +36 -32
- package/lib/transform/odata/generateForeignKeyElements.js +3 -3
- 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 +47 -33
- package/lib/transform/translateAssocsToJoins.js +10 -27
- 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/file.js +2 -1
- package/lib/utils/objectUtils.js +30 -0
- package/lib/utils/timetrace.js +8 -2
- package/package.json +1 -1
- package/share/messages/README.md +26 -0
- package/lib/compiler/definer.js +0 -2340
- package/lib/compiler/resolver.js +0 -2988
- package/lib/transform/universalCsnEnricher.js +0 -67
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const { applyTransformations } = require('../../model/csnUtils');
|
|
2
2
|
const { setProp } = require('../../base/model');
|
|
3
3
|
const { implicitAs } = require('../../model/csnRefs');
|
|
4
4
|
const { structuralPath } = require('./structuralPath');
|
|
@@ -52,32 +52,34 @@ class ReferenceFlattener {
|
|
|
52
52
|
* @param {*} isStructured Callback function checking of an artifact is a structured element.
|
|
53
53
|
*/
|
|
54
54
|
resolveAllReferences(csn, inspectRef, isStructured) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (!resolved)
|
|
64
|
-
return; // TODO: fix tests: throw Error("Could not resolve: " + path.join("/"));
|
|
65
|
-
if (!resolved.links)
|
|
66
|
-
return; // TODO: fix tests: throw Error("Could not resolve links: " + path.join("/"));
|
|
67
|
-
let paths = [];
|
|
68
|
-
resolved.links.forEach((element) => {
|
|
69
|
-
if (!element.art)
|
|
70
|
-
paths = undefined; // not resolved -> no paths
|
|
71
|
-
if (paths) {
|
|
72
|
-
paths.push(element.art.$path);
|
|
55
|
+
applyTransformations(csn, {
|
|
56
|
+
ref: (node, prop, _ref, path) => {
|
|
57
|
+
if (!path) return;
|
|
58
|
+
let resolved;
|
|
59
|
+
try {
|
|
60
|
+
resolved = inspectRef(path);
|
|
61
|
+
} catch (ex) {
|
|
62
|
+
return; // TODO: fix tests: throw Error("Could not inspectRef: " + path.join("/"));
|
|
73
63
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
64
|
+
if (!resolved)
|
|
65
|
+
return; // TODO: fix tests: throw Error("Could not resolve: " + path.join("/"));
|
|
66
|
+
if (!resolved.links)
|
|
67
|
+
return; // TODO: fix tests: throw Error("Could not resolve links: " + path.join("/"));
|
|
68
|
+
let paths = [];
|
|
69
|
+
resolved.links.forEach((element) => {
|
|
70
|
+
if (!element.art)
|
|
71
|
+
paths = undefined; // not resolved -> no paths
|
|
72
|
+
if (paths) {
|
|
73
|
+
paths.push(element.art.$path);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
if (paths)
|
|
77
|
+
setProp(node, '$paths', paths);
|
|
78
|
+
// cache if structured or not
|
|
79
|
+
let structured = resolved.links.map(link => link.art ? (isStructured(link.art)) : undefined);
|
|
80
|
+
this.structuredReference[path.join('/')] = structured;
|
|
81
|
+
}
|
|
82
|
+
})
|
|
81
83
|
}
|
|
82
84
|
|
|
83
85
|
/**
|
|
@@ -172,80 +174,84 @@ class ReferenceFlattener {
|
|
|
172
174
|
* @param {*} csn
|
|
173
175
|
*/
|
|
174
176
|
flattenAllReferences(csn) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
ref[i].id
|
|
191
|
-
|
|
177
|
+
applyTransformations(csn, {
|
|
178
|
+
ref: (node, prop, ref, path) => {
|
|
179
|
+
if (node.$paths) {
|
|
180
|
+
let newRef = []; // flattened reference
|
|
181
|
+
let flattenWithPrevious = false;
|
|
182
|
+
let lastFlattenedID = null; // The variable will be set to the index of the last flattened path
|
|
183
|
+
node.$paths.forEach((path, i) => {
|
|
184
|
+
if (path === undefined || !ref[i]) return;
|
|
185
|
+
let spath = path.join('/');
|
|
186
|
+
let movedTo = this.elementTransitions[spath]; // detect element transition
|
|
187
|
+
let flattened = this.flattenedElementPaths[spath];
|
|
188
|
+
if (flattenWithPrevious) {
|
|
189
|
+
newRef[newRef.length - 1] = newRef[newRef.length - 1] + '_' + (ref[i].id || ref[i]);
|
|
190
|
+
// if we have a filter or args in an assoc, it needs to be kept, therefore
|
|
191
|
+
// the id of the ref is updated with the flattened version
|
|
192
|
+
if (ref[i].id) {
|
|
193
|
+
ref[i].id = newRef[newRef.length - 1];
|
|
194
|
+
newRef[newRef.length - 1] = ref[i];
|
|
195
|
+
}
|
|
196
|
+
lastFlattenedID = i;
|
|
197
|
+
} else if(movedTo && i===0) { // handle local scope reference which is transitioned - replace first item in reference
|
|
198
|
+
let movedToElementName = movedTo[movedTo.length-1];
|
|
199
|
+
newRef.push(movedToElementName);
|
|
200
|
+
lastFlattenedID = i;
|
|
201
|
+
} else {
|
|
202
|
+
newRef.push(ref[i]);
|
|
192
203
|
}
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
setProp(newRef, '$path', path.concat('ref'));
|
|
211
|
-
if (!node.as) {
|
|
212
|
-
if (isPartOfKeysStructure(structural))
|
|
213
|
-
node.as = implicitAs(node.ref);
|
|
214
|
-
else
|
|
215
|
-
setProp(node, 'as', implicitAs(node.ref))
|
|
204
|
+
flattenWithPrevious = flattened;
|
|
205
|
+
});
|
|
206
|
+
if (newRef !== undefined && lastFlattenedID !== null) { // make sure the reference changed and only then replace it with the new one
|
|
207
|
+
// check if this is a column and add alias if missing
|
|
208
|
+
let structural = structuralPath(csn, path);
|
|
209
|
+
if (isColumnInSelectOrProjection(structural)) {
|
|
210
|
+
if (!node.as && lastFlattenedID === ref.length-1) // attach alias only if there is none and it is the last item in the reference that was flattened
|
|
211
|
+
node.as = node.ref[node.ref.length - 1];
|
|
212
|
+
}
|
|
213
|
+
setProp(newRef, '$path', path.concat('ref'));
|
|
214
|
+
if (!node.as) {
|
|
215
|
+
if (isPartOfKeysStructure(structural))
|
|
216
|
+
node.as = implicitAs(node.ref);
|
|
217
|
+
else
|
|
218
|
+
setProp(node, 'as', implicitAs(node.ref))
|
|
219
|
+
}
|
|
220
|
+
node.ref = newRef;
|
|
216
221
|
}
|
|
217
|
-
node.ref = newRef;
|
|
218
222
|
}
|
|
219
223
|
}
|
|
220
224
|
})
|
|
221
225
|
}
|
|
222
226
|
|
|
223
227
|
applyAliasesInOnCond(csn, inspectRef) {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
228
|
+
applyTransformations(csn, {
|
|
229
|
+
ref: (node, prop, ref, path) => {
|
|
230
|
+
// Process only on-conditions of associations
|
|
231
|
+
let structural = structuralPath(csn, path);
|
|
232
|
+
if(!isOnCondition(structural)) return;
|
|
233
|
+
let { links } = inspectRef(path);
|
|
234
|
+
if(!links) return; // $user not resolvable
|
|
235
|
+
let keysOfPreviousStepWhenManagedAssoc = undefined;
|
|
236
|
+
|
|
237
|
+
let aliasedRef = [...ref];
|
|
238
|
+
|
|
239
|
+
for (let idx = 0; idx < ref.length; idx++) {
|
|
240
|
+
const currArt = links[idx].art;
|
|
241
|
+
if (keysOfPreviousStepWhenManagedAssoc) {
|
|
242
|
+
const usedKey = keysOfPreviousStepWhenManagedAssoc.find(key => key.ref[0] === ref[idx]);
|
|
243
|
+
if (usedKey && usedKey.as) {
|
|
244
|
+
aliasedRef.splice(idx, usedKey.ref.length, usedKey.as);
|
|
245
|
+
idx += usedKey.ref.length - 1;
|
|
246
|
+
keysOfPreviousStepWhenManagedAssoc = undefined;
|
|
247
|
+
}
|
|
248
|
+
} else {
|
|
249
|
+
keysOfPreviousStepWhenManagedAssoc =
|
|
250
|
+
(currArt.type === 'cds.Association' || currArt.type === 'cds.Composition') && currArt.keys;
|
|
242
251
|
}
|
|
243
|
-
} else {
|
|
244
|
-
keysOfPreviousStepWhenManagedAssoc =
|
|
245
|
-
(currArt.type === 'cds.Association' || currArt.type === 'cds.Composition') && currArt.keys;
|
|
246
252
|
}
|
|
253
|
+
node.ref = aliasedRef;
|
|
247
254
|
}
|
|
248
|
-
node.ref = aliasedRef;
|
|
249
255
|
})
|
|
250
256
|
}
|
|
251
257
|
}
|
|
@@ -71,7 +71,7 @@ function flattenCSN(csn, csnUtils, options, referenceFlattener, error, isExterna
|
|
|
71
71
|
* @param {Function} error
|
|
72
72
|
*/
|
|
73
73
|
function flattenDefinition(definition, definitionPath, csnUtils, options, referenceFlattener, error) {
|
|
74
|
-
if (definition.kind !== 'entity'
|
|
74
|
+
if (definition.kind !== 'entity')
|
|
75
75
|
return;
|
|
76
76
|
|
|
77
77
|
let { newFlatElements } = flattenStructure(definition.elements, definitionPath, csnUtils, options, error, referenceFlattener);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const {
|
|
4
4
|
forEachDefinition, forEachMemberRecursively,
|
|
5
|
-
isBuiltinType, cloneCsnDictionary,
|
|
5
|
+
isBuiltinType, cloneCsnDictionary, cloneCsn,
|
|
6
6
|
} = require('../../model/csnUtils');
|
|
7
7
|
const { isArtifactInSomeService, isArtifactInService } = require('./utils');
|
|
8
8
|
|
|
@@ -86,21 +86,95 @@ function expandToFinalBaseType(csn, transformers, csnUtils, services, options, i
|
|
|
86
86
|
// EDMX at the moment and the reference in the OData CSN is fulfilled.
|
|
87
87
|
if (node.kind === 'event') return;
|
|
88
88
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
89
|
+
// elements have precedence over type
|
|
90
|
+
if (node.type && (!isBuiltinType(node.type) &&isExpandable(node, defName) || node.kind === 'type')) {
|
|
91
|
+
// 1. Get the final type of the node (resolve derived type chain)
|
|
92
|
+
const finalType = csnUtils.getFinalBaseType(node.type);
|
|
93
|
+
if (finalType) {
|
|
94
|
+
// The type replacement depends on whether 'node' is a definition or a member[element].
|
|
95
|
+
if (node.kind) {
|
|
96
|
+
// It is a definition and we expand to builtin type and to elements
|
|
97
|
+
// type T: S; --> Integer;
|
|
98
|
+
// type S: X; --> Integer;
|
|
99
|
+
// type X: Integer;
|
|
100
|
+
//
|
|
101
|
+
// type A: B; -> {...}
|
|
102
|
+
// type B: C; -> { ... }
|
|
103
|
+
// type C { .... };
|
|
104
|
+
if (isBuiltinType(finalType)) {
|
|
105
|
+
// use transformUrilsNew::toFinalBaseType for the moment,
|
|
106
|
+
// as it is collects along the chain of types
|
|
107
|
+
// attributes that need to be propagated
|
|
108
|
+
// enum, length, scale, etc.
|
|
109
|
+
transformers.toFinalBaseType(node);
|
|
110
|
+
// node.type = finalType;
|
|
111
|
+
}
|
|
112
|
+
else if (csnUtils.isStructured(finalType)) {
|
|
113
|
+
cloneElements(finalType);
|
|
114
|
+
}
|
|
115
|
+
else if (node.type && node.items)
|
|
99
116
|
delete node.type;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
// this is a member and we expand to final base only if builtin
|
|
120
|
+
// type T: S; --> Integer;
|
|
121
|
+
// type S: X; --> Integer;
|
|
122
|
+
// type X: Integer;
|
|
123
|
+
//
|
|
124
|
+
// type {
|
|
125
|
+
// struct_elt: many A; ---> stays the same
|
|
126
|
+
// scalar_elt: T; ---> Integer;
|
|
127
|
+
// type_ref_elt: type of struct_elt;
|
|
128
|
+
// };
|
|
129
|
+
// type A: B; -> {...}
|
|
130
|
+
// type B: C; -> { ... }
|
|
131
|
+
// type C { .... };
|
|
132
|
+
if (isBuiltinType(finalType)) {
|
|
133
|
+
// use transformUrilsNew::toFinalBaseType for the moment,
|
|
134
|
+
// as it is collects along the chain of types
|
|
135
|
+
// attributes that need to be propagated
|
|
136
|
+
// enum, length, scale, etc.
|
|
137
|
+
transformers.toFinalBaseType(node);
|
|
138
|
+
// node.type = finalType;
|
|
139
|
+
}
|
|
140
|
+
else if (node.type && node.type.ref) {
|
|
141
|
+
cloneElements(finalType);
|
|
100
142
|
}
|
|
101
143
|
}
|
|
102
144
|
}
|
|
103
145
|
}
|
|
146
|
+
if (node.type && !isBuiltinType(node.type)) {
|
|
147
|
+
// handle array of defined via a named type
|
|
148
|
+
// example in actions: 'action act() return Primitive; type Primitive: array of String;'
|
|
149
|
+
const currService = csnUtils.getServiceName(defName);
|
|
150
|
+
const finalType = csnUtils.getFinalTypeDef(node.type);
|
|
151
|
+
if (finalType.items && isBuiltinType(finalType.items.type)) {
|
|
152
|
+
if (!isArtifactInService(node.type, currService) || !isV4) {
|
|
153
|
+
node.items = finalType.items;
|
|
154
|
+
delete node.type;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function cloneElements(finalType) {
|
|
160
|
+
// cloneCsn only works correctly if we start "from the top"
|
|
161
|
+
let clone;
|
|
162
|
+
// do the clone only if really needed
|
|
163
|
+
if((finalType.items && !node.items) ||
|
|
164
|
+
(finalType.elements && !node.elements))
|
|
165
|
+
clone = cloneCsn({ definitions: { 'TypeDef': finalType } }, options);
|
|
166
|
+
if (finalType.items) {
|
|
167
|
+
delete node.type;
|
|
168
|
+
if(!node.items)
|
|
169
|
+
Object.assign(node, { items: clone.definitions.TypeDef.items });
|
|
170
|
+
}
|
|
171
|
+
if (finalType.elements) {
|
|
172
|
+
if(!finalType.items)
|
|
173
|
+
delete node.type;
|
|
174
|
+
if(!node.elements)
|
|
175
|
+
Object.assign(node, { elements: clone.definitions.TypeDef.elements });
|
|
176
|
+
}
|
|
177
|
+
}
|
|
104
178
|
}
|
|
105
179
|
|
|
106
180
|
function isExpandable(node, defName) {
|
|
@@ -119,4 +193,4 @@ function expandToFinalBaseType(csn, transformers, csnUtils, services, options, i
|
|
|
119
193
|
}
|
|
120
194
|
}
|
|
121
195
|
|
|
122
|
-
module.exports = expandToFinalBaseType;
|
|
196
|
+
module.exports = expandToFinalBaseType;
|
|
@@ -18,7 +18,7 @@ const { copyAnnotations } = require('../../model/csnUtils');
|
|
|
18
18
|
* @param {*} csnUtils
|
|
19
19
|
* @param {object} message message object with { error } function
|
|
20
20
|
*/
|
|
21
|
-
function typesExposure(csn, whatsMyServiceName, options, csnUtils, message) {
|
|
21
|
+
function typesExposure(csn, whatsMyServiceName, autoexposeSchemaName, options, csnUtils, message) {
|
|
22
22
|
const { error } = message;
|
|
23
23
|
// are we working with OData proxies or cross-service refs
|
|
24
24
|
const isMultiSchema = options.toOdata.version === 'v4' && (options.toOdata.odataProxies || options.toOdata.odataXServiceRefs);
|
|
@@ -30,9 +30,9 @@ function typesExposure(csn, whatsMyServiceName, options, csnUtils, message) {
|
|
|
30
30
|
// we do expose types only for definition from inside services
|
|
31
31
|
const serviceName = whatsMyServiceName(defName, false);
|
|
32
32
|
if (serviceName) {
|
|
33
|
-
if (
|
|
33
|
+
if (def.kind === 'type' || def.kind === 'entity') {
|
|
34
34
|
forEachMember(def, (element, elementName, propertyName, path) => {
|
|
35
|
-
if (
|
|
35
|
+
if (propertyName === 'elements' || propertyName === 'params') {
|
|
36
36
|
const artificialtName = `${isMultiSchema ?
|
|
37
37
|
defNameWithoutServiceOrContextName(defName, serviceName)
|
|
38
38
|
: defNameWithoutServiceOrContextName(defName, serviceName).replace(/\./g, '_')}_${elementName}`;
|
|
@@ -190,7 +190,7 @@ function typesExposure(csn, whatsMyServiceName, options, csnUtils, message) {
|
|
|
190
190
|
} else {
|
|
191
191
|
const typeContext = csnUtils.getContextOfArtifact(typeName);
|
|
192
192
|
const typeNamespace = csnUtils.getNamespaceOfArtifact(typeName);
|
|
193
|
-
const newSchemaName = `${service}.${typeContext || typeNamespace ||
|
|
193
|
+
const newSchemaName = `${service}.${typeContext || typeNamespace || autoexposeSchemaName}`;
|
|
194
194
|
// new type name without any prefixes
|
|
195
195
|
const typePlainName = typeContext ? defNameWithoutServiceOrContextName(typeName, typeContext)
|
|
196
196
|
: typeName.replace(`${typeNamespace}.`, '');
|
|
@@ -209,7 +209,7 @@ function typesExposure(csn, whatsMyServiceName, options, csnUtils, message) {
|
|
|
209
209
|
*/
|
|
210
210
|
function getAnonymousTypeNameInMultiSchema(typeName, parentName) {
|
|
211
211
|
let currPrefix = parentName.substring(0, parentName.lastIndexOf('.'));
|
|
212
|
-
const newSchemaName = currPrefix ||
|
|
212
|
+
const newSchemaName = currPrefix || autoexposeSchemaName;
|
|
213
213
|
// new type name without any prefixes
|
|
214
214
|
const typePlainName = defNameWithoutServiceOrContextName(typeName, newSchemaName);
|
|
215
215
|
|
|
@@ -18,7 +18,7 @@ function isAssociationOrComposition(artifact) {
|
|
|
18
18
|
return isAssociation(artifact) || isComposition(artifact);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
function
|
|
21
|
+
function isManagedAssociation(artifact) {
|
|
22
22
|
return artifact.target !== undefined && artifact.on === undefined;
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -94,5 +94,5 @@ module.exports = {
|
|
|
94
94
|
isArtifactInSomeService,
|
|
95
95
|
isAssociationOrComposition,
|
|
96
96
|
isLocalizedArtifactInService,
|
|
97
|
-
|
|
97
|
+
isManagedAssociation,
|
|
98
98
|
}
|