@sap/cds-dk 4.5.4 → 4.6.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 +20 -0
- package/bin/bind.js +124 -8
- package/bin/cds-ts.js +1 -1
- package/bin/cds.js +1 -0
- package/bin/env.js +50 -9
- package/bin/help.js +1 -0
- package/bin/import.js +34 -14
- package/bin/watch.js +25 -4
- package/lib/bind/bindingResolver.js +138 -0
- package/lib/bind/cfKeyProvider.js +353 -0
- package/lib/bind/userCdsrcJsonStorageProvider.js +144 -0
- package/lib/client/auth_manager.js +4 -4
- package/lib/client/settings_manager.js +1 -1
- package/lib/import/common.js +10 -1
- package/lib/import/importapi.js +4 -3
- package/lib/import/index.js +34 -5
- package/lib/import/message.js +1 -0
- package/lib/import/utils/MetadataConverter.js +25 -4
- package/lib/import/utils/MetadataConverterFactory.js +1 -2
- package/lib/import/utils/MultiMap.js +26 -0
- package/lib/import/v2parser.js +131 -12
- package/lib/import/v4parser.js +212 -172
- package/lib/init/template/lint/files/.eslint/rules/no-entity-moo.js +36 -52
- package/lib/init/template/lint/files/.eslint/tests/no-entity-moo/rule.test.js +15 -0
- package/lib/init/template/lint/index.js +14 -6
- package/lib/init/template/mta/files/mta.yaml.hbs +0 -7
- package/lib/init/template/mtx/files/xs-security.json.hbs +3 -1
- package/lib/init/template/mtx/package/dependencies.package.json +1 -1
- package/lib/init/template/nodejs/files/.gitignore.hbs +3 -0
- package/lib/init/util/commandUtil.js +5 -0
- package/lib/lint/Linter.js +31 -20
- package/lib/lint/checks.js +5 -1
- package/lib/lint/io.js +59 -35
- package/lib/util/term.js +2 -0
- package/lib/watch/node-watch.js +38 -19
- package/npm-shrinkwrap.json +1782 -1138
- package/package.json +3 -3
- package/lib/init/template/lint/files/.eslint/tests/no-entity-moo/test.js +0 -10
package/lib/import/v4parser.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* OData V4 to CSN parser
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
'use strict';
|
|
7
6
|
|
|
7
|
+
'use strict';
|
|
8
8
|
let messages = require("./message").getMessages();
|
|
9
9
|
let common = require("./common");
|
|
10
10
|
let versionInfo = require('../../package.json').version;
|
|
@@ -24,7 +24,6 @@ let functionImportToFunctionMap = new Multimap();
|
|
|
24
24
|
let validEdmDatatypes = ['Edm.DateTimeOffset'];
|
|
25
25
|
let jsonEntityContainerName;
|
|
26
26
|
const ignoreObjects = ['$Reference']; // add all the objects that needs to be ignored for parsing.
|
|
27
|
-
|
|
28
27
|
const MetadataConverterFactory = require('../import/utils/MetadataConverterFactory');
|
|
29
28
|
const edmxncdsdatatype = {
|
|
30
29
|
'Edm.String': 'cds.LargeString',
|
|
@@ -117,11 +116,19 @@ function _validateJSON(jsonObj) {
|
|
|
117
116
|
);
|
|
118
117
|
}
|
|
119
118
|
|
|
119
|
+
function _includeExternalNamespaceAnnotation(source,target){
|
|
120
|
+
Object.entries(source).forEach(element =>{
|
|
121
|
+
if(element[0].startsWith('@')){
|
|
122
|
+
target[element[0]] = element[1];
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
120
126
|
function generatePropertyCsn(propertyType, isPrimaryKey) {
|
|
121
127
|
let property = {};
|
|
122
128
|
if (isPrimaryKey) {
|
|
123
129
|
property.key = true;
|
|
124
130
|
}
|
|
131
|
+
_includeExternalNamespaceAnnotation(propertyType,property);
|
|
125
132
|
// conditions have to be made
|
|
126
133
|
if (propertyType.$MaxLength) {
|
|
127
134
|
if (propertyType.$Type) {
|
|
@@ -141,7 +148,7 @@ function generatePropertyCsn(propertyType, isPrimaryKey) {
|
|
|
141
148
|
}
|
|
142
149
|
} else if (propertyType.$Type) {
|
|
143
150
|
property.type = edmxncdsdatatype[propertyType.$Type];
|
|
144
|
-
} else
|
|
151
|
+
} else{
|
|
145
152
|
property.type = 'cds.LargeString'; // if type is missing, then it is String type
|
|
146
153
|
}
|
|
147
154
|
return property;
|
|
@@ -218,10 +225,11 @@ function _parseAssociationProperty(foreignReference, associationNode, mockServer
|
|
|
218
225
|
if (common.checkForEmptyKeys(associationProperty, "V4")) {
|
|
219
226
|
associationProperty.keys = [];
|
|
220
227
|
}
|
|
228
|
+
_includeExternalNamespaceAnnotation(associationNode,associationProperty);
|
|
221
229
|
return associationProperty;
|
|
222
230
|
}
|
|
223
231
|
|
|
224
|
-
function _generateCSNForEntityType(entityTypes, mockServerUc) {
|
|
232
|
+
function _generateCSNForEntityType(entityTypes, ignorePersistenceSkip, mockServerUc) {
|
|
225
233
|
let entityCsn = {};
|
|
226
234
|
let keySet;
|
|
227
235
|
let curKey;
|
|
@@ -235,6 +243,10 @@ function _generateCSNForEntityType(entityTypes, mockServerUc) {
|
|
|
235
243
|
if (key) {
|
|
236
244
|
entityCsn[key] = {};
|
|
237
245
|
entityCsn[key].kind = 'entity';
|
|
246
|
+
if (!ignorePersistenceSkip) {
|
|
247
|
+
entityCsn[key]['@cds.persistence.skip'] = true;
|
|
248
|
+
}
|
|
249
|
+
_includeExternalNamespaceAnnotation(element[key],entityCsn[key]);
|
|
238
250
|
// inheritance
|
|
239
251
|
if (baseType) {
|
|
240
252
|
entityCsn[key].includes = [];
|
|
@@ -326,7 +338,7 @@ function _generateEntityType(entityTypes, schemaData, mockServerUc) {
|
|
|
326
338
|
});
|
|
327
339
|
}
|
|
328
340
|
|
|
329
|
-
function _parseEntityType(schemaDataList, mockServerUc) {
|
|
341
|
+
function _parseEntityType(schemaDataList, ignorePersistenceSkip, mockServerUc) {
|
|
330
342
|
// collect entity types
|
|
331
343
|
let entityTypes = [];
|
|
332
344
|
let schemaData;
|
|
@@ -335,7 +347,7 @@ function _parseEntityType(schemaDataList, mockServerUc) {
|
|
|
335
347
|
_generateEntityType(entityTypes, schemaData, mockServerUc);
|
|
336
348
|
}
|
|
337
349
|
// parse it
|
|
338
|
-
return _generateCSNForEntityType(entityTypes, mockServerUc);
|
|
350
|
+
return _generateCSNForEntityType(entityTypes, ignorePersistenceSkip, mockServerUc);
|
|
339
351
|
}
|
|
340
352
|
|
|
341
353
|
function _generateEnumType(schemaData) {
|
|
@@ -420,8 +432,30 @@ function _collectBounded(schemaDataList, flag) {
|
|
|
420
432
|
}
|
|
421
433
|
}
|
|
422
434
|
|
|
435
|
+
function _getDatatype(datatype) {
|
|
436
|
+
let type = undefined;
|
|
437
|
+
if (datatype === undefined) {
|
|
438
|
+
type = "cds.LargeString"; //intentionally used LargeString
|
|
439
|
+
} else if (entitySetToEntityTypeMap.get(datatype) && entitySetToEntityTypeMap.get(datatype)[0]) {
|
|
440
|
+
//mapping to entity set if type is entity type
|
|
441
|
+
type = namespace + "." + entitySetToEntityTypeMap.get(datatype)[0];
|
|
442
|
+
} else if (complexTypes[datatype] || typeDefinitions[datatype] || enumTypes[datatype]) {
|
|
443
|
+
//if type is complex type, type definition or an enum type
|
|
444
|
+
type = datatype;
|
|
445
|
+
} else {
|
|
446
|
+
//checking if type is an entity set
|
|
447
|
+
for (const element of entitySetToEntityTypeMap.keys()) {
|
|
448
|
+
if (namespace + "." + entitySetToEntityTypeMap.get(element) === datatype)
|
|
449
|
+
type = datatype;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
//will return undefined if type is not supported
|
|
454
|
+
return type;
|
|
455
|
+
}
|
|
456
|
+
|
|
423
457
|
function _parseBounded(csnDefs, flag) {
|
|
424
|
-
let boundedEdmxKind, boundedObj, boundedCsnKind, boundedEntityName, obj,
|
|
458
|
+
let boundedEdmxKind, boundedObj, boundedCsnKind, boundedEntityName, obj, paramName, paramObj, name;
|
|
425
459
|
if (flag == 0) {
|
|
426
460
|
boundedEdmxKind = "Action";
|
|
427
461
|
boundedCsnKind = "action";
|
|
@@ -446,6 +480,7 @@ function _parseBounded(csnDefs, flag) {
|
|
|
446
480
|
if (csnDefs[boundedEntityName].actions === undefined)
|
|
447
481
|
csnDefs[boundedEntityName].actions = {};
|
|
448
482
|
csnDefs[boundedEntityName].actions[name] = {};
|
|
483
|
+
_includeExternalNamespaceAnnotation(obj[0],csnDefs[boundedEntityName].actions[name]);
|
|
449
484
|
csnDefs[boundedEntityName].actions[name].kind = boundedCsnKind;
|
|
450
485
|
// add params
|
|
451
486
|
if (obj[j].$Parameter && obj[j].$Parameter.length >= 2) {
|
|
@@ -462,55 +497,56 @@ function _parseBounded(csnDefs, flag) {
|
|
|
462
497
|
for (let i = 1; i < obj[j].$Parameter.length; i++) {
|
|
463
498
|
paramObj = obj[j].$Parameter[i];
|
|
464
499
|
paramName = obj[j].$Parameter[i].$Name;
|
|
465
|
-
|
|
500
|
+
let paramType ={};
|
|
501
|
+
_includeExternalNamespaceAnnotation(paramObj,paramType);
|
|
502
|
+
//check if the parameter type is pre-defined, undefined or custom defined
|
|
466
503
|
if (edmxncdsdatatype[paramObj.$Type])
|
|
467
504
|
paramType = generatePropertyCsn(paramObj, false);
|
|
468
|
-
else if (paramObj.$Type === undefined)
|
|
469
|
-
paramType = { "type": "cds.LargeString" }; // intentionally used LargeString
|
|
470
505
|
else {
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
paramType = { "type": type };
|
|
474
|
-
}
|
|
475
|
-
else {
|
|
476
|
-
paramType = { "type": obj[j].$Parameter[i].$Type };
|
|
477
|
-
}
|
|
506
|
+
let type = _getDatatype(paramObj.$Type);
|
|
507
|
+
if(type) paramType["type"] = type;
|
|
478
508
|
}
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
509
|
+
if (paramType) {
|
|
510
|
+
// check if parameter type is a collection
|
|
511
|
+
if (paramObj.$Collection) {
|
|
512
|
+
csnDefs[boundedEntityName].actions[name].params[paramName] = {};
|
|
513
|
+
csnDefs[boundedEntityName].actions[name].params[paramName].items = paramType;
|
|
514
|
+
} else
|
|
515
|
+
csnDefs[boundedEntityName].actions[name].params[paramName] = paramType;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
485
519
|
}
|
|
486
520
|
}
|
|
521
|
+
//if parameters has no entries
|
|
522
|
+
if(csnDefs[boundedEntityName].actions[name].params && Object.keys(csnDefs[boundedEntityName].actions[name].params).length === 0)
|
|
523
|
+
{
|
|
524
|
+
delete csnDefs[boundedEntityName].actions[name].params;
|
|
525
|
+
}
|
|
487
526
|
// add returns
|
|
488
527
|
if (obj[j].$ReturnType) {
|
|
489
|
-
|
|
528
|
+
let returnType={};
|
|
490
529
|
// check if the return type is pre-defined, undefined or custom defined
|
|
491
530
|
if (edmxncdsdatatype[obj[j].$ReturnType.$Type])
|
|
492
531
|
returnType = generatePropertyCsn(obj[j].$ReturnType, false);
|
|
493
|
-
else if (obj[j].$ReturnType.$Type === undefined)
|
|
494
|
-
returnType = { "type": "cds.LargeString" }; // intentionally used LargeString
|
|
495
532
|
else {
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
533
|
+
let type = _getDatatype(obj[j].$ReturnType.$Type);
|
|
534
|
+
_includeExternalNamespaceAnnotation(obj[j].$ReturnType,returnType);
|
|
535
|
+
if(type) returnType["type"] = type ;
|
|
536
|
+
}
|
|
537
|
+
if (returnType) {
|
|
538
|
+
csnDefs[boundedEntityName].actions[name].returns = {};
|
|
539
|
+
// check if return type is a collection
|
|
540
|
+
if (obj[j].$ReturnType.$Collection)
|
|
541
|
+
csnDefs[boundedEntityName].actions[name].returns.items = returnType;
|
|
542
|
+
else
|
|
543
|
+
csnDefs[boundedEntityName].actions[name].returns = returnType;
|
|
503
544
|
}
|
|
504
|
-
// check if return type is a collection
|
|
505
|
-
if (obj[j].$ReturnType.$Collection)
|
|
506
|
-
csnDefs[boundedEntityName].actions[name].returns.items = returnType;
|
|
507
|
-
else
|
|
508
|
-
csnDefs[boundedEntityName].actions[name].returns = returnType;
|
|
509
545
|
}
|
|
510
546
|
}
|
|
511
547
|
}
|
|
512
548
|
}
|
|
513
|
-
|
|
549
|
+
);
|
|
514
550
|
}
|
|
515
551
|
}
|
|
516
552
|
|
|
@@ -556,13 +592,15 @@ function _generateCSNForComplexType(schemaData) {
|
|
|
556
592
|
}
|
|
557
593
|
Object.keys(cTypes[element]).forEach(property => { // cTypes[element][property].$Type.startsWith('Edm.')
|
|
558
594
|
if (cTypes[element][property] instanceof Object) {
|
|
559
|
-
if (!cTypes[element][property].$Type || edmxncdsdatatype[cTypes[element][property].$Type]) {
|
|
595
|
+
if (!cTypes[element][property].$Type || edmxncdsdatatype[cTypes[element][property].$Type] ) {
|
|
560
596
|
propertyType = cTypes[element][property];
|
|
561
597
|
complexCsn[element].elements[property] = generatePropertyCsn(propertyType, false);
|
|
562
598
|
}
|
|
563
599
|
} else if (complexTypes[cTypes[element][property].$Type]) {
|
|
564
600
|
propertyType = cTypes[element][property];
|
|
565
601
|
complexCsn[element].elements[property] = _generateComplexTypePropertyCsn(propertyType);
|
|
602
|
+
} else if(property.startsWith("@")){
|
|
603
|
+
complexCsn[element][property] = cTypes[element][property];
|
|
566
604
|
}
|
|
567
605
|
});
|
|
568
606
|
});
|
|
@@ -599,70 +637,67 @@ function _parseUnbounded(schemaData, flag) {
|
|
|
599
637
|
if (Object.keys(unbounded).length > 0) {
|
|
600
638
|
Object.keys(unbounded).forEach(ub => {
|
|
601
639
|
let obj = {};
|
|
602
|
-
let objType = {}, objData = {}, temp;
|
|
603
|
-
if (importToMap && importToMap.get(ub)) {
|
|
604
|
-
temp =
|
|
640
|
+
let objType = {}, objData = {}, temp = {};
|
|
641
|
+
if (importToMap && importToMap.get(ub)) {
|
|
642
|
+
temp = ub.split(".").pop();
|
|
605
643
|
objType = namespace + "." + temp;
|
|
606
644
|
objData = schemaData[0][temp][0];
|
|
607
645
|
obj[objType] = {};
|
|
608
646
|
obj[objType].kind = unboundedCsnKind;
|
|
647
|
+
_includeExternalNamespaceAnnotation(objData,obj[objType]);
|
|
609
648
|
// add params
|
|
610
649
|
if (objData.$Parameter && objData.$Parameter.length > 0) {
|
|
611
650
|
obj[objType].params = {};
|
|
612
|
-
let type;
|
|
613
|
-
let typeProperties = {};
|
|
651
|
+
let type = {};
|
|
614
652
|
for (let i = 0; i < objData.$Parameter.length; i++) {
|
|
615
|
-
|
|
653
|
+
let typeProperties = {};
|
|
654
|
+
_includeExternalNamespaceAnnotation(objData.$Parameter[i],typeProperties);
|
|
616
655
|
// check if the parameter type is pre-defined, undefined or custom defined
|
|
617
656
|
if (edmxncdsdatatype[objData.$Parameter[i].$Type]) {
|
|
618
657
|
const parameterProperties = generatePropertyCsn(objData.$Parameter[i], false);
|
|
619
658
|
({type, ...typeProperties} = parameterProperties);
|
|
659
|
+
} else {
|
|
660
|
+
type = _getDatatype(objData.$Parameter[i].$Type);
|
|
620
661
|
}
|
|
621
|
-
|
|
622
|
-
type = "cds.LargeString"; // intentionally used LargeString
|
|
623
|
-
}
|
|
624
|
-
else {
|
|
625
|
-
if (entitySetToEntityTypeMap.get(objData.$Parameter[i].$Type))
|
|
626
|
-
type = namespace + "." + entitySetToEntityTypeMap.get(objData.$Parameter[i].$Type)[0];
|
|
627
|
-
else
|
|
628
|
-
type = objData.$Parameter[i].$Type;
|
|
629
|
-
}
|
|
662
|
+
if (type) {
|
|
630
663
|
|
|
631
|
-
|
|
632
|
-
|
|
664
|
+
// Adds type properties like scale, precision, etc if any
|
|
665
|
+
const parameterObj = Object.keys(typeProperties).length > 0 ? { type, ...typeProperties } : { type };
|
|
633
666
|
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
667
|
+
// check if parameter type is a collection
|
|
668
|
+
if (objData.$Parameter[i].$Collection)
|
|
669
|
+
obj[objType].params[objData.$Parameter[i].$Name].items = parameterObj;
|
|
670
|
+
else
|
|
671
|
+
obj[objType].params[objData.$Parameter[i].$Name] = parameterObj;
|
|
672
|
+
|
|
673
|
+
}
|
|
639
674
|
}
|
|
640
675
|
}
|
|
676
|
+
//if parameters has no entries
|
|
677
|
+
if(obj[objType].params && Object.keys(obj[objType].params).length === 0)
|
|
678
|
+
{
|
|
679
|
+
delete obj[objType].params;
|
|
680
|
+
}
|
|
641
681
|
// add returns
|
|
642
682
|
if (objData.$ReturnType && Object.keys(objData.$ReturnType).length > 0 && obj) {
|
|
643
|
-
|
|
644
|
-
let returnValue;
|
|
683
|
+
let returnValue = {};
|
|
645
684
|
// check if the return type is pre-defined, undefined or custom defined
|
|
646
685
|
if (edmxncdsdatatype[objData.$ReturnType.$Type]) {
|
|
647
686
|
returnValue = generatePropertyCsn(objData.$ReturnType, false);
|
|
687
|
+
} else {
|
|
688
|
+
let type = _getDatatype(objData.$ReturnType.$Type);
|
|
689
|
+
_includeExternalNamespaceAnnotation(objData.$ReturnType,returnValue);
|
|
690
|
+
if(type) returnValue["type"] = type;
|
|
648
691
|
}
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
else
|
|
658
|
-
returnValue = { "type": objData.$ReturnType.$Type };
|
|
692
|
+
if (returnValue) {
|
|
693
|
+
obj[objType].returns = {};
|
|
694
|
+
// check if return type is a collection
|
|
695
|
+
if (objData.$ReturnType.$Collection) {
|
|
696
|
+
obj[objType].returns.items = {};
|
|
697
|
+
obj[objType].returns.items = returnValue;
|
|
698
|
+
} else
|
|
699
|
+
obj[objType].returns = returnValue;
|
|
659
700
|
}
|
|
660
|
-
// check if return type is a collection
|
|
661
|
-
if (objData.$ReturnType.$Collection) {
|
|
662
|
-
obj[objType].returns.items = {};
|
|
663
|
-
obj[objType].returns.items = returnValue;
|
|
664
|
-
} else
|
|
665
|
-
obj[objType].returns = returnValue;
|
|
666
701
|
}
|
|
667
702
|
}
|
|
668
703
|
unboundedObj = Object.assign(unboundedObj, obj);
|
|
@@ -671,8 +706,7 @@ function _parseUnbounded(schemaData, flag) {
|
|
|
671
706
|
return unboundedObj;
|
|
672
707
|
}
|
|
673
708
|
|
|
674
|
-
function _generateCSN(edmxAsJson, mockServerUc) {
|
|
675
|
-
let schemaCounter = 0;
|
|
709
|
+
function _generateCSN(edmxAsJson, ignorePersistenceSkip, mockServerUc) {
|
|
676
710
|
let csn = {};
|
|
677
711
|
let schemaData = [];
|
|
678
712
|
unboundedActions = {};
|
|
@@ -683,6 +717,16 @@ function _generateCSN(edmxAsJson, mockServerUc) {
|
|
|
683
717
|
csn.meta.creator = 'cds-dk ' + versionInfo;
|
|
684
718
|
csn.$version = '2.0';
|
|
685
719
|
csn.definitions = {};
|
|
720
|
+
|
|
721
|
+
Object.keys(edmxAsJson).forEach(data => {
|
|
722
|
+
if (ignoreObjects.indexOf(data) === -1 && edmxAsJson[data] instanceof Object) {
|
|
723
|
+
// replace the namespace alias value with original namespace value
|
|
724
|
+
if (edmxAsJson[data].$Alias)
|
|
725
|
+
edmxAsJson[data] = common.replaceAliasValue(JSON.stringify(edmxAsJson[data]), data, edmxAsJson[data].$Alias);
|
|
726
|
+
schemaData.push(edmxAsJson[data]);
|
|
727
|
+
}
|
|
728
|
+
});
|
|
729
|
+
|
|
686
730
|
if (mockServerUc) {
|
|
687
731
|
let entitySetData = edmxAsJson[namespace];
|
|
688
732
|
let entityContainer;
|
|
@@ -708,19 +752,6 @@ function _generateCSN(edmxAsJson, mockServerUc) {
|
|
|
708
752
|
}
|
|
709
753
|
});
|
|
710
754
|
}
|
|
711
|
-
Object.keys(edmxAsJson).forEach(data => {
|
|
712
|
-
if (ignoreObjects.indexOf(data) === -1 && edmxAsJson[data] instanceof Object) {
|
|
713
|
-
schemaData.push(edmxAsJson[data]);
|
|
714
|
-
schemaCounter += 1;
|
|
715
|
-
}
|
|
716
|
-
});
|
|
717
|
-
|
|
718
|
-
// Multiple schema found and currently we don't support
|
|
719
|
-
if (schemaCounter > 1) {
|
|
720
|
-
let errorMsg = messages().MULTIPLE_SCHEMA_FOUND;
|
|
721
|
-
errors.push(errorMsg);
|
|
722
|
-
// throw errorMsg;
|
|
723
|
-
}
|
|
724
755
|
|
|
725
756
|
csn.definitions[namespace] = {};
|
|
726
757
|
csn.definitions[namespace].kind = 'service';
|
|
@@ -739,7 +770,7 @@ function _generateCSN(edmxAsJson, mockServerUc) {
|
|
|
739
770
|
csn.definitions = Object.assign(_parseUnbounded(schemaData, 0), csn.definitions);
|
|
740
771
|
csn.definitions = Object.assign(_parseUnbounded(schemaData , 1), csn.definitions);
|
|
741
772
|
// Step 4: get all entity type
|
|
742
|
-
csn.definitions = Object.assign(_parseEntityType(schemaData, mockServerUc), csn.definitions);
|
|
773
|
+
csn.definitions = Object.assign(_parseEntityType(schemaData, ignorePersistenceSkip, mockServerUc), csn.definitions);
|
|
743
774
|
// Step 5: get all bounded action & function
|
|
744
775
|
_parseBounded(csn.definitions, 0);
|
|
745
776
|
_parseBounded(csn.definitions, 1);
|
|
@@ -749,116 +780,125 @@ function _generateCSN(edmxAsJson, mockServerUc) {
|
|
|
749
780
|
return JSON.stringify(csn, null, 4);
|
|
750
781
|
}
|
|
751
782
|
|
|
752
|
-
function
|
|
753
|
-
return text.replace(/(?:\\[rn]|[\r\n]+)+/gm, "\n").replace(/\s+/g, ' ').trim();
|
|
783
|
+
function _replaceSpecialCharacters(text) {
|
|
784
|
+
return text.replace(/(?:\\[rn]|[\r\n]+)+/gm, "\n").replace(/\s+/g, ' ').replace(/"/g, """).trim();
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
function _checkAnnotatationTerm(annotation, path, no_of_terms, targetString){
|
|
788
|
+
if(path){
|
|
789
|
+
if(targetString === "@Core.Description"){
|
|
790
|
+
if(path.doc === undefined)
|
|
791
|
+
path.doc = _replaceSpecialCharacters(annotation[1]["@Core.Description"]);
|
|
792
|
+
else
|
|
793
|
+
path.doc += _replaceSpecialCharacters(annotation[1]["@Core.Description"]);
|
|
794
|
+
}
|
|
795
|
+
else if(targetString === "@Core.LongDescription"){
|
|
796
|
+
_generateLongDescription(annotation,path,no_of_terms);
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
function _checkAnnotationTarget(annotation, cdsDefs , str, no_of_terms){
|
|
801
|
+
if (annotation[0].indexOf('/') === -1 && annotation[0].indexOf('(') === -1) {
|
|
802
|
+
if (annotation[0].endsWith(".EntityContainer")) {
|
|
803
|
+
let path = annotation[0].split(".")[0];
|
|
804
|
+
|
|
805
|
+
_checkAnnotatationTerm(annotation,cdsDefs[path],no_of_terms,str);
|
|
806
|
+
}
|
|
807
|
+
if (cdsDefs[annotation[0]]) {
|
|
808
|
+
_checkAnnotatationTerm(annotation, cdsDefs[annotation[0]], no_of_terms , str);
|
|
809
|
+
}
|
|
810
|
+
} else if(annotation[0].indexOf('(') === -1 && !(annotation[0].indexOf('/') === -1)){
|
|
811
|
+
let path = annotation[0].split('/');
|
|
812
|
+
if(cdsDefs[path[0]]){
|
|
813
|
+
_checkAnnotatationTerm(annotation, cdsDefs[path[0]]["elements"][path[1]], no_of_terms, str);
|
|
814
|
+
}
|
|
815
|
+
} else{
|
|
816
|
+
let path = annotation[0].split('(');
|
|
817
|
+
if(cdsDefs[path[0]]== undefined){
|
|
818
|
+
let temp = path[1].split(')');
|
|
819
|
+
let path1 = temp[0].split(',');
|
|
820
|
+
let path2 = path[0].split('.');
|
|
821
|
+
if(cdsDefs[path1[0]]){
|
|
822
|
+
_checkAnnotatationTerm(annotation,cdsDefs[path1[0]]["actions"][path2[1]],no_of_terms,str);
|
|
823
|
+
}
|
|
824
|
+
} else{
|
|
825
|
+
if(path[1].indexOf('/') === -1){
|
|
826
|
+
_checkAnnotatationTerm(annotation,cdsDefs[path[0]],no_of_terms,str);
|
|
827
|
+
} else{
|
|
828
|
+
let path1 = path[1].split('/');
|
|
829
|
+
if(cdsDefs[path[0]]){
|
|
830
|
+
_checkAnnotatationTerm(annotation,cdsDefs[path[0]]["params"][path1[1]],no_of_terms,str);
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
}
|
|
754
835
|
}
|
|
755
836
|
|
|
756
837
|
function _generateDocumentation(schemaData, cdsDefs) {
|
|
757
838
|
if (schemaData[0].$Annotations) {
|
|
758
839
|
Object.entries(schemaData[0].$Annotations).map(annotation => {
|
|
759
|
-
let
|
|
840
|
+
let no_of_terms;
|
|
760
841
|
// eslint-disable-next-line no-prototype-builtins
|
|
761
842
|
if (annotation[1].hasOwnProperty('@Core.Description')) {
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
let path = annotation[0].split(".")[0];
|
|
766
|
-
cdsDefs[path].doc = _removeCarriageReturn(annotation[1]["@Core.Description"]);
|
|
767
|
-
}
|
|
768
|
-
if (cdsDefs[annotation[0]]) {
|
|
769
|
-
cdsDefs[annotation[0]].doc = _removeCarriageReturn(annotation[1]["@Core.Description"]);
|
|
770
|
-
}
|
|
771
|
-
} else {
|
|
772
|
-
let path = annotation[0].split('/');
|
|
773
|
-
if (cdsDefs[path[0]]["elements"][path[1]]) {
|
|
774
|
-
if (!cdsDefs[path[0]]["elements"][path[1]].doc) {
|
|
775
|
-
cdsDefs[path[0]]["elements"][path[1]].doc = "";
|
|
776
|
-
}
|
|
777
|
-
cdsDefs[path[0]]["elements"][path[1]].doc += _removeCarriageReturn(annotation[1]["@Core.Description"]);
|
|
778
|
-
}
|
|
779
|
-
}
|
|
843
|
+
|
|
844
|
+
no_of_terms = true;
|
|
845
|
+
_checkAnnotationTarget(annotation,cdsDefs,"@Core.Description",no_of_terms);
|
|
780
846
|
}
|
|
781
847
|
// eslint-disable-next-line no-prototype-builtins
|
|
782
848
|
if (annotation[1].hasOwnProperty('@Core.LongDescription')) {
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
let path = annotation[0].split(".")[0];
|
|
786
|
-
if (flag === true) {
|
|
787
|
-
cdsDefs[path].doc += "\n\n";
|
|
788
|
-
} else {
|
|
789
|
-
if (cdsDefs[path].doc){
|
|
790
|
-
cdsDefs[path].doc += "";
|
|
791
|
-
}
|
|
792
|
-
else{
|
|
793
|
-
cdsDefs[path].doc = "";
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
cdsDefs[path].doc += _removeCarriageReturn(annotation[1]["@Core.LongDescription"]);
|
|
797
|
-
}
|
|
798
|
-
if (cdsDefs[annotation[0]]) {
|
|
799
|
-
if (flag === true) {
|
|
800
|
-
cdsDefs[annotation[0]].doc += "\n\n";
|
|
801
|
-
} else {
|
|
802
|
-
if (cdsDefs[annotation[0]].doc){
|
|
803
|
-
cdsDefs[annotation[0]].doc += "";
|
|
804
|
-
}
|
|
805
|
-
else{
|
|
806
|
-
cdsDefs[annotation[0]].doc = "";
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
cdsDefs[annotation[0]].doc += _removeCarriageReturn(annotation[1]["@Core.LongDescription"]);
|
|
810
|
-
}
|
|
811
|
-
} else {
|
|
812
|
-
let path = annotation[0].split('/');
|
|
813
|
-
if (cdsDefs[path[0]]["elements"][path[1]]) {
|
|
814
|
-
if (flag === true) {
|
|
815
|
-
cdsDefs[path[0]]["elements"][path[1]].doc += "\n\n";
|
|
816
|
-
} else {
|
|
817
|
-
if (cdsDefs[path[0]]["elements"][path[1]].doc){
|
|
818
|
-
cdsDefs[path[0]]["elements"][path[1]].doc += "";
|
|
819
|
-
}
|
|
820
|
-
else{
|
|
821
|
-
cdsDefs[path[0]]["elements"][path[1]].doc = "";
|
|
849
|
+
_checkAnnotationTarget(annotation,cdsDefs,"@Core.LongDescription",no_of_terms);
|
|
850
|
+
|
|
822
851
|
}
|
|
823
|
-
}
|
|
824
|
-
cdsDefs[path[0]]["elements"][path[1]].doc += _removeCarriageReturn(annotation[1]["@Core.LongDescription"]);
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
852
|
});
|
|
829
853
|
}
|
|
830
854
|
}
|
|
831
855
|
|
|
832
|
-
function
|
|
833
|
-
|
|
834
|
-
|
|
856
|
+
function _generateLongDescription(annotation,path,no_of_terms){
|
|
857
|
+
if(path){
|
|
858
|
+
path.doc = no_of_terms ? (path.doc += "\n\n") : (path.doc ? (path.doc+="") : (path.doc=""));
|
|
859
|
+
path.doc += _replaceSpecialCharacters(annotation[1]["@Core.LongDescription"]);
|
|
860
|
+
return(path.doc);
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
|
|
865
|
+
function _generateEDMX2JSON(edmx, name_space) {
|
|
866
|
+
return new Promise(function getJson(resolve, reject) {
|
|
867
|
+
try {
|
|
835
868
|
const inputBuffer = edmx;
|
|
836
869
|
// create converter
|
|
837
|
-
const v4Conv = MetadataConverterFactory.createEdmxV40XmlToV40Json();
|
|
838
|
-
v4Conv.execute(inputBuffer, (error, json, missingReferencedDocuments) => {
|
|
870
|
+
const v4Conv = MetadataConverterFactory.createEdmxV40XmlToV40Json(name_space);
|
|
871
|
+
v4Conv.execute(inputBuffer, (error, json, missingReferencedDocuments) => {
|
|
839
872
|
if (missingReferencedDocuments.length > 0) {
|
|
840
873
|
console.log(missingReferencedDocuments); // eslint-disable-line no-console
|
|
841
874
|
}
|
|
842
|
-
|
|
843
875
|
if (_validateJSON(json)) {
|
|
844
876
|
resolve(json);
|
|
845
877
|
}
|
|
846
878
|
});
|
|
847
|
-
} catch (err) {
|
|
879
|
+
} catch (err) {
|
|
848
880
|
reject(err);
|
|
849
881
|
}
|
|
850
882
|
});
|
|
851
883
|
}
|
|
852
884
|
|
|
853
|
-
function getEdmxv4CSN(edmx, mockServerUc) {
|
|
885
|
+
function getEdmxv4CSN(edmx, ignorePersistenceSkip, mockServerUc, context) {
|
|
854
886
|
let csn;
|
|
855
887
|
let edmjConverted;
|
|
888
|
+
let name_space = []
|
|
889
|
+
if(context.include_all_namespaces === true)
|
|
890
|
+
{
|
|
891
|
+
name_space.push(true);
|
|
892
|
+
}
|
|
893
|
+
else{
|
|
894
|
+
name_space = context.namespaces;
|
|
895
|
+
}
|
|
856
896
|
if (_isJson(edmx)) {
|
|
857
897
|
return new Promise(function getCsn(resolve, reject) {
|
|
858
898
|
try {
|
|
859
899
|
edmjConverted = JSON.parse(edmx);
|
|
860
900
|
if (_validateJSON(edmjConverted)) {
|
|
861
|
-
csn = _generateCSN(edmjConverted, mockServerUc);
|
|
901
|
+
csn = _generateCSN(edmjConverted, ignorePersistenceSkip, mockServerUc);
|
|
862
902
|
if (csn) {
|
|
863
903
|
resolve(csn);
|
|
864
904
|
} else {
|
|
@@ -870,9 +910,9 @@ function getEdmxv4CSN(edmx, mockServerUc) {
|
|
|
870
910
|
}
|
|
871
911
|
});
|
|
872
912
|
}
|
|
873
|
-
return _generateEDMX2JSON(edmx).then(function getCsn(edmj) {
|
|
913
|
+
return _generateEDMX2JSON(edmx,name_space).then(function getCsn(edmj) {
|
|
874
914
|
// now parsing logic
|
|
875
|
-
return _generateCSN(edmj, mockServerUc);
|
|
915
|
+
return _generateCSN(edmj, ignorePersistenceSkip, mockServerUc);
|
|
876
916
|
});
|
|
877
917
|
}
|
|
878
918
|
|