@sap/cds-dk 4.4.2 → 4.5.4
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 +60 -0
- package/bin/activate.js +1 -2
- package/bin/deploy/index.js +3 -2
- package/bin/deploy/to-sqlite.js +2 -2
- package/bin/extend.js +2 -4
- package/bin/help.js +1 -1
- package/bin/import.js +105 -23
- package/bin/login.js +7 -8
- package/bin/logout.js +1 -2
- package/bin/repl.js +1 -1
- package/bin/watch.js +30 -11
- package/lib/client/activate.js +243 -0
- package/lib/client/auth_manager.js +115 -0
- package/lib/client/base_command.js +55 -0
- package/lib/client/extend.js +179 -0
- package/lib/client/helper/cf_helper.js +186 -0
- package/lib/client/helper/dependency_helper.js +26 -0
- package/lib/client/helper/env_helper.js +4 -0
- package/lib/client/helper/fs_helper.js +83 -0
- package/lib/client/helper/logging.js +37 -0
- package/lib/client/helper/question.js +50 -0
- package/lib/client/helper/string_helper.js +53 -0
- package/lib/client/helper/url_helper.js +17 -0
- package/lib/client/index.js +14 -0
- package/lib/client/params.js +435 -0
- package/lib/client/settings_manager.js +526 -0
- package/lib/import/common.js +24 -1
- package/lib/import/importapi.js +1 -1
- package/lib/import/index.js +25 -41
- package/lib/import/message.js +10 -6
- package/lib/import/v2parser.js +301 -47
- package/lib/import/v4parser.js +391 -71
- package/lib/init/constants.js +1 -1
- package/lib/init/index.js +15 -10
- package/lib/init/template/data/index.js +38 -46
- package/lib/init/template/hana/index.js +2 -2
- package/lib/init/template/lint/index.js +8 -6
- package/lib/init/template/mta/projectReader.js +8 -5
- package/lib/init/template/nodejs/files/.vscode/extensions.json +1 -1
- package/lib/init/template/nodejs/index.js +1 -8
- package/lib/lint/Linter.js +62 -60
- package/lib/lint/generators.js +1 -1
- package/lib/lint/io.js +9 -33
- package/npm-shrinkwrap.json +5179 -10848
- package/package.json +5 -5
package/lib/import/v2parser.js
CHANGED
|
@@ -9,12 +9,15 @@ let allEntities = [];
|
|
|
9
9
|
let allEntitiesMC = [];
|
|
10
10
|
let allEntitySetMap = {};
|
|
11
11
|
let allEntitySetMapMC = {};
|
|
12
|
+
let allFunctionImports = [];
|
|
13
|
+
let allFunctionImportsMap = {};
|
|
12
14
|
let allAssociations = {};
|
|
13
15
|
let allAssociationSets = {};
|
|
14
16
|
let allComplexTypes = {};
|
|
15
17
|
let allComplexTypeDocs = {};
|
|
16
18
|
let allInheritedComplexTypes = {};
|
|
17
19
|
let messages = require("./message").getMessages();
|
|
20
|
+
let common = require("./common");
|
|
18
21
|
let versionInfo = require('../../package.json').version;
|
|
19
22
|
|
|
20
23
|
let edmxncdsdatatype = {
|
|
@@ -48,6 +51,8 @@ function _initialize() {
|
|
|
48
51
|
allEntitiesMC.length = 0;
|
|
49
52
|
allEntitySetMap = {};
|
|
50
53
|
allEntitySetMapMC = {};
|
|
54
|
+
allFunctionImports.length = 0;
|
|
55
|
+
allFunctionImportsMap = {};
|
|
51
56
|
allAssociations = {};
|
|
52
57
|
allAssociationSets = {};
|
|
53
58
|
allComplexTypes = {};
|
|
@@ -55,10 +60,6 @@ function _initialize() {
|
|
|
55
60
|
allInheritedComplexTypes = {};
|
|
56
61
|
}
|
|
57
62
|
|
|
58
|
-
function getNamespace() {
|
|
59
|
-
return serviceNamespace;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
63
|
function _isValidEDMX(jsonObj) {
|
|
63
64
|
let isValid = false;
|
|
64
65
|
let edmx;
|
|
@@ -195,7 +196,9 @@ function _extractEntityFromEntitySet(entitySet) {
|
|
|
195
196
|
Object.keys(entitySet).forEach((key) => {
|
|
196
197
|
if (key === "_attributes") {
|
|
197
198
|
allEntitySetMap[entitySet[key].Name] = entitySet[key].EntityType;
|
|
198
|
-
allEntitySetMapMC[entitySet[key].EntityType]
|
|
199
|
+
if (allEntitySetMapMC[entitySet[key].EntityType] === undefined)
|
|
200
|
+
allEntitySetMapMC[entitySet[key].EntityType] = [];
|
|
201
|
+
allEntitySetMapMC[entitySet[key].EntityType].push(entitySet[key].Name);
|
|
199
202
|
entityName = _extractEntityFromNamespace(entitySet[key].EntityType);
|
|
200
203
|
allEntities.push(entityName);
|
|
201
204
|
allEntitiesMC.push(entitySet[key].Name);
|
|
@@ -216,15 +219,101 @@ function _extractAllEntityFromEntitySets(entitySets) {
|
|
|
216
219
|
}
|
|
217
220
|
}
|
|
218
221
|
|
|
222
|
+
function _extractNameFromFunctionImport(entityName) {
|
|
223
|
+
let entityId = "";
|
|
224
|
+
let pos = entityName.lastIndexOf("_");
|
|
225
|
+
if (pos < 0) {
|
|
226
|
+
return entityName;
|
|
227
|
+
}
|
|
228
|
+
entityId = entityName.substring(pos + 1);
|
|
229
|
+
return entityId;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function _getFunctionAttributes(functionImport, serviceNamespaceParam)
|
|
233
|
+
{
|
|
234
|
+
let funcAttributes = [];
|
|
235
|
+
if(functionImport["_attributes"])
|
|
236
|
+
{
|
|
237
|
+
funcAttributes.push(serviceNamespaceParam + _extractNameFromFunctionImport(functionImport["_attributes"].Name));
|
|
238
|
+
funcAttributes.push(functionImport["_attributes"]["m:HttpMethod"]);
|
|
239
|
+
if(functionImport["_attributes"].ReturnType)
|
|
240
|
+
{
|
|
241
|
+
funcAttributes.push(functionImport["_attributes"].ReturnType);
|
|
242
|
+
} else {
|
|
243
|
+
funcAttributes.push(-1);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if(functionImport["Parameter"])
|
|
248
|
+
{
|
|
249
|
+
funcAttributes.push(functionImport["Parameter"]);
|
|
250
|
+
} else {
|
|
251
|
+
funcAttributes.push(-1);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if(functionImport["Documentation"])
|
|
255
|
+
{
|
|
256
|
+
funcAttributes.push(_parseDocumentationTag(functionImport["Documentation"]));
|
|
257
|
+
} else {
|
|
258
|
+
funcAttributes.push(-1);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return funcAttributes;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function _extractFunctionImport(functionImport, serviceNamespaceParam)
|
|
265
|
+
{
|
|
266
|
+
//extracting the bounded and unbounded function import
|
|
267
|
+
let boundedFunctionImports = [];
|
|
268
|
+
let entityName;
|
|
269
|
+
Object.keys(functionImport).forEach((key) => {
|
|
270
|
+
if(key === "_attributes") {
|
|
271
|
+
if(functionImport[key]["sap:action-for"])
|
|
272
|
+
{
|
|
273
|
+
//storing bounded function imports
|
|
274
|
+
entityName = _extractEntityFromNamespace(functionImport[key]["sap:action-for"]);
|
|
275
|
+
boundedFunctionImports = (allFunctionImportsMap[entityName]) ? allFunctionImportsMap[entityName] : [];
|
|
276
|
+
boundedFunctionImports.push(_getFunctionAttributes(functionImport,""));
|
|
277
|
+
allFunctionImportsMap[entityName] = boundedFunctionImports;
|
|
278
|
+
}
|
|
279
|
+
else
|
|
280
|
+
{
|
|
281
|
+
//storing unbounded function imports
|
|
282
|
+
allFunctionImports.push(_getFunctionAttributes(functionImport,serviceNamespaceParam + "."));
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
//extracting the function imports from the metadata
|
|
289
|
+
function _extractAllFunctionImports(functionImports, serviceNamespaceParam)
|
|
290
|
+
{
|
|
291
|
+
let i;
|
|
292
|
+
if (functionImports.length) {
|
|
293
|
+
//Has many function imports in metadata
|
|
294
|
+
for (i = 0; i < functionImports.length; i++) {
|
|
295
|
+
_extractFunctionImport(functionImports[i], serviceNamespaceParam);
|
|
296
|
+
}
|
|
297
|
+
} else {
|
|
298
|
+
//Has only one function import in metadata
|
|
299
|
+
_extractFunctionImport(functionImports, serviceNamespaceParam);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function _removeCarriageReturn(text) {
|
|
304
|
+
return text.replace(/(?:\\[rn]|[\r\n]+)+/gm, "\\n").replace(/\s+/g, ' ').trim();
|
|
305
|
+
}
|
|
306
|
+
|
|
219
307
|
// to parse the documentation tag
|
|
220
|
-
function _parseDocumentationTag(documentedContent){
|
|
308
|
+
function _parseDocumentationTag(documentedContent) {
|
|
221
309
|
let documentation = "";
|
|
222
|
-
if(documentedContent.Summary && documentedContent.Summary._text)
|
|
223
|
-
documentation = documentedContent.Summary._text;
|
|
224
|
-
|
|
225
|
-
|
|
310
|
+
if (documentedContent.Summary && documentedContent.Summary._text) {
|
|
311
|
+
documentation = _removeCarriageReturn(documentedContent.Summary._text);
|
|
312
|
+
}
|
|
313
|
+
if (documentedContent.LongDescription && documentedContent.LongDescription._text) {
|
|
314
|
+
if (documentedContent.Summary)
|
|
226
315
|
documentation += "\\n\\n";
|
|
227
|
-
documentation += documentedContent.LongDescription._text;
|
|
316
|
+
documentation += _removeCarriageReturn(documentedContent.LongDescription._text);
|
|
228
317
|
}
|
|
229
318
|
return documentation;
|
|
230
319
|
}
|
|
@@ -271,11 +360,12 @@ function _getServiceEntityProperty(
|
|
|
271
360
|
scale,
|
|
272
361
|
displayFormat,
|
|
273
362
|
isKey,
|
|
274
|
-
documentation
|
|
363
|
+
documentation,
|
|
364
|
+
isCollection
|
|
275
365
|
) {
|
|
276
366
|
let cdsDataType = null;
|
|
277
367
|
let hasInvalidPrecision = false;
|
|
278
|
-
let propertyJson;
|
|
368
|
+
let propertyJson='';
|
|
279
369
|
if (length && length > 0) {
|
|
280
370
|
cdsDataType = edmxncdsdatatype[dataType + "_m"];
|
|
281
371
|
} else if (precision && precision > 0) {
|
|
@@ -301,11 +391,23 @@ function _getServiceEntityProperty(
|
|
|
301
391
|
cdsDataType = dataType;
|
|
302
392
|
}
|
|
303
393
|
|
|
304
|
-
|
|
394
|
+
//Possibility of entity type or entity set as the data type
|
|
395
|
+
if (!cdsDataType && allEntitySetMapMC[dataType]) {
|
|
396
|
+
cdsDataType = serviceNamespace + "." + allEntitySetMapMC[dataType];
|
|
397
|
+
} else if(!cdsDataType && allEntitySetMap[_extractEntityFromNamespace(dataType)]) {
|
|
398
|
+
cdsDataType = dataType;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
if(propertyName)
|
|
402
|
+
propertyJson = '"' + propertyName + '": {\n';
|
|
305
403
|
|
|
306
404
|
if (isKey) {
|
|
307
405
|
propertyJson = propertyJson + '"key": true,\n';
|
|
308
406
|
}
|
|
407
|
+
if(isCollection === 1)
|
|
408
|
+
{
|
|
409
|
+
propertyJson = propertyJson + '"items": { \n'
|
|
410
|
+
}
|
|
309
411
|
propertyJson = propertyJson + '"type":"' + cdsDataType + '"';
|
|
310
412
|
if (length && length > 0) {
|
|
311
413
|
propertyJson = propertyJson + ',\n"length":' + length;
|
|
@@ -317,10 +419,16 @@ function _getServiceEntityProperty(
|
|
|
317
419
|
propertyJson = propertyJson + ',\n"scale":' + 0;
|
|
318
420
|
}
|
|
319
421
|
}
|
|
422
|
+
if(isCollection === 1)
|
|
423
|
+
{
|
|
424
|
+
propertyJson = propertyJson + '\n}'
|
|
425
|
+
}
|
|
320
426
|
if(documentation != -1 && documentation != undefined){
|
|
321
427
|
propertyJson = propertyJson + ',\n"doc":"' + documentation + '"';
|
|
322
428
|
}
|
|
323
|
-
|
|
429
|
+
|
|
430
|
+
if(propertyName)
|
|
431
|
+
propertyJson = propertyJson + "\n}";
|
|
324
432
|
return propertyJson;
|
|
325
433
|
}
|
|
326
434
|
|
|
@@ -349,7 +457,8 @@ function _getServiceComplexType(complexTypeKey, complexType) {
|
|
|
349
457
|
complexTypeProperty.Scale,
|
|
350
458
|
complexTypeProperty["sap:display-format"],
|
|
351
459
|
false,
|
|
352
|
-
complexTypeProperty.doc
|
|
460
|
+
complexTypeProperty.doc,
|
|
461
|
+
-1
|
|
353
462
|
);
|
|
354
463
|
if (i !== complexType.length - 1) {
|
|
355
464
|
complexTypeCSN = complexTypeCSN + ",\n";
|
|
@@ -372,7 +481,8 @@ function _getServiceComplexType(complexTypeKey, complexType) {
|
|
|
372
481
|
complexTypeProperty.Scale,
|
|
373
482
|
complexTypeProperty["sap:display-format"],
|
|
374
483
|
false,
|
|
375
|
-
complexTypeProperty.doc
|
|
484
|
+
complexTypeProperty.doc,
|
|
485
|
+
-1
|
|
376
486
|
);
|
|
377
487
|
}
|
|
378
488
|
}
|
|
@@ -410,6 +520,116 @@ function _getServiceComplexTypes() {
|
|
|
410
520
|
return complexTypeCSN;
|
|
411
521
|
}
|
|
412
522
|
|
|
523
|
+
function _parseParameter(parameter)
|
|
524
|
+
{
|
|
525
|
+
let csn = "";
|
|
526
|
+
let doc;
|
|
527
|
+
let isCollection = -1;
|
|
528
|
+
if(parameter.Documentation)
|
|
529
|
+
doc = _parseDocumentationTag(parameter.Documentation);
|
|
530
|
+
let type = parameter["_attributes"].Type;
|
|
531
|
+
if(type.substring(0,10) === 'Collection')
|
|
532
|
+
{
|
|
533
|
+
type = type.substring(11,type.length-1);
|
|
534
|
+
isCollection = 1;
|
|
535
|
+
}
|
|
536
|
+
csn = csn + _getServiceEntityProperty(parameter["_attributes"].Name,
|
|
537
|
+
type,
|
|
538
|
+
parameter["_attributes"].MaxLength,
|
|
539
|
+
parameter["_attributes"].Precision,
|
|
540
|
+
parameter["_attributes"].Scale,
|
|
541
|
+
parameter["_attributes"]["sap:display-format"],
|
|
542
|
+
false,
|
|
543
|
+
doc,
|
|
544
|
+
isCollection);
|
|
545
|
+
return csn;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
function _parseParametersFunctionImport(parameters, isBounded) {
|
|
549
|
+
let csn = "";
|
|
550
|
+
let i = isBounded===1 ? 1 : 0;
|
|
551
|
+
if(parameters.length)
|
|
552
|
+
{
|
|
553
|
+
for(i;i<parameters.length;i++)
|
|
554
|
+
{
|
|
555
|
+
csn = csn + _parseParameter(parameters[i]);
|
|
556
|
+
if(i!== parameters.length - 1) {
|
|
557
|
+
csn = csn + ",\n";
|
|
558
|
+
} else {
|
|
559
|
+
csn = csn + "\n";
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
} else {
|
|
563
|
+
csn = csn + _parseParameter(parameters);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
return csn;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
function _getFunctionImport(functionImport,isBounded) {
|
|
570
|
+
let noValue;
|
|
571
|
+
let csn = "";
|
|
572
|
+
csn = csn + '"' + functionImport[0] + '": { \n';
|
|
573
|
+
csn = csn + '"kind": "';
|
|
574
|
+
if(functionImport[1] === "GET")
|
|
575
|
+
{
|
|
576
|
+
csn = csn + "function";
|
|
577
|
+
} else if(functionImport[1] === "POST")
|
|
578
|
+
{
|
|
579
|
+
csn = csn + "action";
|
|
580
|
+
}
|
|
581
|
+
csn = csn + '"';
|
|
582
|
+
if(functionImport[3] !== -1)
|
|
583
|
+
{
|
|
584
|
+
if(isBounded === 0 || (isBounded === 1 && functionImport[3] instanceof Array ))
|
|
585
|
+
{
|
|
586
|
+
csn = csn + ", \n";
|
|
587
|
+
csn = csn + '"params": { \n';
|
|
588
|
+
csn = csn + _parseParametersFunctionImport(functionImport[3],isBounded);
|
|
589
|
+
csn = csn + '\n }';
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
if(functionImport[2] !== -1)
|
|
593
|
+
{
|
|
594
|
+
csn = csn + ", \n";
|
|
595
|
+
csn = csn + '"returns": { \n';
|
|
596
|
+
let isCollection = -1;
|
|
597
|
+
if(functionImport[2].substring(0,10) === 'Collection')
|
|
598
|
+
{
|
|
599
|
+
functionImport[2] = functionImport[2].substring(11,functionImport[2].length-1);
|
|
600
|
+
isCollection = 1;
|
|
601
|
+
}
|
|
602
|
+
//return type
|
|
603
|
+
csn = csn + _getServiceEntityProperty(noValue,functionImport[2],noValue,noValue,noValue,noValue,noValue,noValue,isCollection);
|
|
604
|
+
csn = csn + '\n }';
|
|
605
|
+
}
|
|
606
|
+
if(functionImport[4] !== -1)
|
|
607
|
+
{
|
|
608
|
+
csn = csn + ',\n "doc": "' + functionImport[4] + '"';
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
csn = csn + "\n }";
|
|
612
|
+
return csn;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
function _getAllFunctionImports(functionImports,isBounded) {
|
|
616
|
+
let functionImportCSN = "";
|
|
617
|
+
let i;
|
|
618
|
+
for(i=0; i<functionImports.length;i++)
|
|
619
|
+
{
|
|
620
|
+
functionImportCSN =
|
|
621
|
+
functionImportCSN +
|
|
622
|
+
_getFunctionImport(functionImports[i],isBounded);
|
|
623
|
+
if(i!== functionImports.length - 1) {
|
|
624
|
+
functionImportCSN = functionImportCSN + ",\n";
|
|
625
|
+
} else {
|
|
626
|
+
functionImportCSN = functionImportCSN + "\n";
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
return functionImportCSN;
|
|
631
|
+
}
|
|
632
|
+
|
|
413
633
|
function _getEntityName(entity) {
|
|
414
634
|
return entity._attributes.Name;
|
|
415
635
|
}
|
|
@@ -537,7 +757,8 @@ function _generateCSNEntityKeys(entityKeysList, entityPropertiesMap) {
|
|
|
537
757
|
propAttributes[3],
|
|
538
758
|
propAttributes[4],
|
|
539
759
|
true,
|
|
540
|
-
propAttributes[5]
|
|
760
|
+
propAttributes[5],
|
|
761
|
+
-1
|
|
541
762
|
);
|
|
542
763
|
if (i !== entityKeysList.length - 1) {
|
|
543
764
|
csnEntity = csnEntity + ",\n";
|
|
@@ -574,7 +795,8 @@ function _generateCSNEntityProperties(entityKeysList, entityPropertiesMap) {
|
|
|
574
795
|
propAttributes[3],
|
|
575
796
|
propAttributes[4],
|
|
576
797
|
false,
|
|
577
|
-
propAttributes[5]
|
|
798
|
+
propAttributes[5],
|
|
799
|
+
-1
|
|
578
800
|
);
|
|
579
801
|
if (i !== entityProperties.length - 1) {
|
|
580
802
|
csnEntity = csnEntity + ",\n";
|
|
@@ -869,17 +1091,24 @@ function _getServiceEntityNavigationProperty(navPropAttributes, mockServerUc) {
|
|
|
869
1091
|
|
|
870
1092
|
csn = csn + '"' + navPropName + '": {\n';
|
|
871
1093
|
// if documentatin exists for navigation property
|
|
872
|
-
if(navPropDoc)
|
|
873
|
-
csn = csn +
|
|
1094
|
+
if (navPropDoc) {
|
|
1095
|
+
csn = csn + '"doc":' + `"Please add an ON condition\\n${navPropDoc}",\n`;
|
|
1096
|
+
} else {
|
|
1097
|
+
csn = csn + '"doc": "Please add an ON condition", \n';
|
|
1098
|
+
}
|
|
874
1099
|
csn = csn + '"type": "cds.Association",\n';
|
|
875
|
-
csn =
|
|
876
|
-
csn +
|
|
1100
|
+
csn = csn +
|
|
877
1101
|
_getCSNAssociatedEntitySet(
|
|
878
1102
|
relationshipName,
|
|
879
1103
|
toRole,
|
|
880
1104
|
navPropName,
|
|
881
1105
|
mockServerUc
|
|
882
1106
|
);
|
|
1107
|
+
// Convert managed associations and compositions in unmanaged with empty key to avoid
|
|
1108
|
+
// "generation" of keys, that do not exist in the external service.
|
|
1109
|
+
if (common.checkForEmptyKeys(csn, "V2")) {
|
|
1110
|
+
csn = csn + ',\n"keys": []\n';
|
|
1111
|
+
}
|
|
883
1112
|
csn = csn + "}";
|
|
884
1113
|
|
|
885
1114
|
return csn;
|
|
@@ -927,7 +1156,6 @@ function _constructServiceEntity(
|
|
|
927
1156
|
entityPropertiesMap,
|
|
928
1157
|
entityNavigationPropertiesMap,
|
|
929
1158
|
entityAttributes,
|
|
930
|
-
ignorePersistenceSkip,
|
|
931
1159
|
mockServerUc,
|
|
932
1160
|
documentation
|
|
933
1161
|
) {
|
|
@@ -937,9 +1165,6 @@ function _constructServiceEntity(
|
|
|
937
1165
|
let csnProperties;
|
|
938
1166
|
let hasProperties;
|
|
939
1167
|
csnEntity = csnEntity + '"kind": "entity",\n';
|
|
940
|
-
if (ignorePersistenceSkip === false) {
|
|
941
|
-
csnEntity = csnEntity + '"@cds.persistence.skip": true,\n';
|
|
942
|
-
}
|
|
943
1168
|
if (
|
|
944
1169
|
entityAttributes.Abstract &&
|
|
945
1170
|
entityAttributes.Abstract.toUpperCase() === "TRUE"
|
|
@@ -983,6 +1208,21 @@ function _constructServiceEntity(
|
|
|
983
1208
|
csnEntity =
|
|
984
1209
|
csnEntity + '"includes": ["' + entityAttributes.BaseType + '"]\n';
|
|
985
1210
|
}
|
|
1211
|
+
|
|
1212
|
+
//if the function import is bounded to entitySet
|
|
1213
|
+
if (allFunctionImportsMap[entityName])
|
|
1214
|
+
{
|
|
1215
|
+
csnEntity = csnEntity + ', \n "actions": {\n';
|
|
1216
|
+
csnEntity = csnEntity + _getAllFunctionImports(allFunctionImportsMap[entityName],1);
|
|
1217
|
+
csnEntity = csnEntity + "}";
|
|
1218
|
+
}
|
|
1219
|
+
else if (allFunctionImportsMap[_extractEntityFromNamespace(allEntitySetMap[entityName])]) //if the function import is bounded to entityType
|
|
1220
|
+
{
|
|
1221
|
+
csnEntity = csnEntity + ', \n "actions": {\n';
|
|
1222
|
+
csnEntity = csnEntity + _getAllFunctionImports(allFunctionImportsMap[_extractEntityFromNamespace(allEntitySetMap[entityName])],1);
|
|
1223
|
+
csnEntity = csnEntity + "}";
|
|
1224
|
+
}
|
|
1225
|
+
|
|
986
1226
|
return csnEntity;
|
|
987
1227
|
}
|
|
988
1228
|
|
|
@@ -990,7 +1230,6 @@ function _parseServiceEntity(
|
|
|
990
1230
|
serviceNamespaceParam,
|
|
991
1231
|
entityName,
|
|
992
1232
|
entity,
|
|
993
|
-
ignorePersistenceSkip,
|
|
994
1233
|
mockServerUc
|
|
995
1234
|
) {
|
|
996
1235
|
let entityAttributes;
|
|
@@ -1039,7 +1278,6 @@ function _parseServiceEntity(
|
|
|
1039
1278
|
entityPropertiesMap,
|
|
1040
1279
|
entityNavigationPropertiesMap,
|
|
1041
1280
|
entityAttributes,
|
|
1042
|
-
ignorePersistenceSkip,
|
|
1043
1281
|
mockServerUc,
|
|
1044
1282
|
documentation
|
|
1045
1283
|
);
|
|
@@ -1055,24 +1293,31 @@ function _getEntitesWithNamesFromEntitySets(
|
|
|
1055
1293
|
allEntitySetMapMC[
|
|
1056
1294
|
serviceNamespaceParam + "." + _getEntityName(entity)
|
|
1057
1295
|
]
|
|
1058
|
-
: (entity) => _getEntityName(entity);
|
|
1296
|
+
: (entity) => [_getEntityName(entity)];
|
|
1059
1297
|
|
|
1060
1298
|
const isNameInEntitySet = mockServerUc
|
|
1061
1299
|
? (name) => allEntitiesMC.indexOf(name) >= 0
|
|
1062
1300
|
: (name) => allEntities.indexOf(name) >= 0;
|
|
1063
1301
|
|
|
1302
|
+
const getEntitySetNames = entityWithName => {
|
|
1303
|
+
for (let i = 0; i < entityWithName.name.length; i++) {
|
|
1304
|
+
if (!isNameInEntitySet(entityWithName.name[i]))
|
|
1305
|
+
return false;
|
|
1306
|
+
}
|
|
1307
|
+
return true;
|
|
1308
|
+
};
|
|
1309
|
+
|
|
1064
1310
|
return entityJson
|
|
1065
1311
|
.map((entity) => ({
|
|
1066
1312
|
entity,
|
|
1067
1313
|
name: getEntityName(entity),
|
|
1068
1314
|
}))
|
|
1069
|
-
.filter((entityWithName) =>
|
|
1315
|
+
.filter((entityWithName) => getEntitySetNames(entityWithName));
|
|
1070
1316
|
}
|
|
1071
1317
|
|
|
1072
1318
|
function _getServiceEntitites(
|
|
1073
1319
|
serviceNamespaceParam,
|
|
1074
1320
|
entityJson = [],
|
|
1075
|
-
ignorePersistenceSkip,
|
|
1076
1321
|
mockServerUc
|
|
1077
1322
|
) {
|
|
1078
1323
|
const entities = Array.isArray(entityJson) ? entityJson : [entityJson];
|
|
@@ -1084,17 +1329,17 @@ function _getServiceEntitites(
|
|
|
1084
1329
|
|
|
1085
1330
|
if (entitiesWithNames.length) {
|
|
1086
1331
|
return (
|
|
1087
|
-
entitiesWithNames
|
|
1088
|
-
.map((
|
|
1332
|
+
entitiesWithNames.map((entityWithName) =>
|
|
1333
|
+
entityWithName.name.map((entityName) =>
|
|
1089
1334
|
_parseServiceEntity(
|
|
1090
1335
|
serviceNamespaceParam,
|
|
1091
|
-
|
|
1336
|
+
entityName,
|
|
1092
1337
|
entityWithName.entity,
|
|
1093
|
-
ignorePersistenceSkip,
|
|
1094
1338
|
mockServerUc
|
|
1095
1339
|
)
|
|
1096
1340
|
)
|
|
1097
1341
|
.join("},") + "}"
|
|
1342
|
+
)
|
|
1098
1343
|
);
|
|
1099
1344
|
}
|
|
1100
1345
|
return "";
|
|
@@ -1103,7 +1348,6 @@ function _getServiceEntitites(
|
|
|
1103
1348
|
function _generateEDMXJSON2CSN(
|
|
1104
1349
|
jsonObj,
|
|
1105
1350
|
serviceNamespaceParam,
|
|
1106
|
-
ignorePersistenceSkip,
|
|
1107
1351
|
mockServerUc
|
|
1108
1352
|
) {
|
|
1109
1353
|
const csn = {};
|
|
@@ -1132,6 +1376,13 @@ function _generateEDMXJSON2CSN(
|
|
|
1132
1376
|
if (entitySets) {
|
|
1133
1377
|
_extractAllEntityFromEntitySets(entitySets);
|
|
1134
1378
|
}
|
|
1379
|
+
// Extract function imports
|
|
1380
|
+
const functionImports =
|
|
1381
|
+
jsonObj["edmx:Edmx"]["edmx:DataServices"].Schema.EntityContainer
|
|
1382
|
+
.FunctionImport;
|
|
1383
|
+
if(functionImports) {
|
|
1384
|
+
_extractAllFunctionImports(functionImports, serviceNamespaceParam);
|
|
1385
|
+
}
|
|
1135
1386
|
// Extract complex types
|
|
1136
1387
|
const complexTypes =
|
|
1137
1388
|
jsonObj["edmx:Edmx"]["edmx:DataServices"].Schema.ComplexType;
|
|
@@ -1145,11 +1396,12 @@ function _generateEDMXJSON2CSN(
|
|
|
1145
1396
|
const definitions = [];
|
|
1146
1397
|
|
|
1147
1398
|
if (mockServerUc) {
|
|
1148
|
-
let def
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
if
|
|
1152
|
-
|
|
1399
|
+
let def = '"' + serviceNamespaceParam + '": {"kind": "service"' + ',\n' + '"@cds.external": true';
|
|
1400
|
+
|
|
1401
|
+
let serviceDoc = jsonObj["edmx:Edmx"]["edmx:DataServices"]["Schema"].EntityContainer.Documentation;
|
|
1402
|
+
// if documentation exists for service
|
|
1403
|
+
if(serviceDoc)
|
|
1404
|
+
def += ',\n' + `"doc": "${_parseDocumentationTag(serviceDoc)}"`;
|
|
1153
1405
|
def += "}";
|
|
1154
1406
|
definitions.push(def);
|
|
1155
1407
|
}
|
|
@@ -1159,12 +1411,17 @@ function _generateEDMXJSON2CSN(
|
|
|
1159
1411
|
definitions.push(_getServiceComplexTypes());
|
|
1160
1412
|
}
|
|
1161
1413
|
|
|
1414
|
+
//if there are unbounded function imports
|
|
1415
|
+
if(Object.keys(allFunctionImports).length > 0)
|
|
1416
|
+
{
|
|
1417
|
+
definitions.push(_getAllFunctionImports(allFunctionImports,0)); //passing 0 for unbounded actions/functions
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1162
1420
|
if (entityJson) {
|
|
1163
1421
|
definitions.push(
|
|
1164
1422
|
_getServiceEntitites(
|
|
1165
1423
|
serviceNamespaceParam,
|
|
1166
1424
|
entityJson,
|
|
1167
|
-
ignorePersistenceSkip,
|
|
1168
1425
|
mockServerUc
|
|
1169
1426
|
)
|
|
1170
1427
|
);
|
|
@@ -1180,7 +1437,6 @@ function _generateEDMXJSON2CSN(
|
|
|
1180
1437
|
|
|
1181
1438
|
function getEdmxv2CSN(
|
|
1182
1439
|
edmx2jsonModel,
|
|
1183
|
-
ignorePersistenceSkip,
|
|
1184
1440
|
mockServerUc
|
|
1185
1441
|
) {
|
|
1186
1442
|
let csnDataModel;
|
|
@@ -1192,7 +1448,6 @@ function getEdmxv2CSN(
|
|
|
1192
1448
|
csnDataModel = _generateEDMXJSON2CSN(
|
|
1193
1449
|
edmx2jsonModel,
|
|
1194
1450
|
serviceNamespace,
|
|
1195
|
-
ignorePersistenceSkip,
|
|
1196
1451
|
mockServerUc
|
|
1197
1452
|
);
|
|
1198
1453
|
}
|
|
@@ -1200,6 +1455,5 @@ function getEdmxv2CSN(
|
|
|
1200
1455
|
}
|
|
1201
1456
|
|
|
1202
1457
|
module.exports = {
|
|
1203
|
-
getEdmxv2CSN
|
|
1204
|
-
getNamespace,
|
|
1458
|
+
getEdmxv2CSN
|
|
1205
1459
|
};
|