@sap/cds-dk 4.5.0 → 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 +65 -9
- package/bin/bind.js +124 -8
- package/bin/cds-ts.js +1 -1
- package/bin/cds.js +1 -0
- package/bin/deploy/index.js +2 -1
- package/bin/env.js +50 -9
- package/bin/help.js +2 -1
- package/bin/import.js +126 -24
- package/bin/watch.js +45 -9
- 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 +33 -1
- package/lib/import/importapi.js +4 -3
- package/lib/import/index.js +49 -23
- package/lib/import/message.js +11 -6
- 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 +142 -24
- package/lib/import/v4parser.js +222 -149
- package/lib/init/constants.js +1 -1
- package/lib/init/index.js +2 -0
- 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/generators.js +1 -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 +1276 -1102
- package/package.json +4 -3
- package/lib/init/template/lint/files/.eslint/tests/no-entity-moo/test.js +0 -10
package/lib/import/v4parser.js
CHANGED
|
@@ -3,9 +3,10 @@
|
|
|
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
|
+
let common = require("./common");
|
|
9
10
|
let versionInfo = require('../../package.json').version;
|
|
10
11
|
let namespace;
|
|
11
12
|
let complexTypes = {};
|
|
@@ -23,7 +24,6 @@ let functionImportToFunctionMap = new Multimap();
|
|
|
23
24
|
let validEdmDatatypes = ['Edm.DateTimeOffset'];
|
|
24
25
|
let jsonEntityContainerName;
|
|
25
26
|
const ignoreObjects = ['$Reference']; // add all the objects that needs to be ignored for parsing.
|
|
26
|
-
|
|
27
27
|
const MetadataConverterFactory = require('../import/utils/MetadataConverterFactory');
|
|
28
28
|
const edmxncdsdatatype = {
|
|
29
29
|
'Edm.String': 'cds.LargeString',
|
|
@@ -116,11 +116,19 @@ function _validateJSON(jsonObj) {
|
|
|
116
116
|
);
|
|
117
117
|
}
|
|
118
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
|
+
}
|
|
119
126
|
function generatePropertyCsn(propertyType, isPrimaryKey) {
|
|
120
127
|
let property = {};
|
|
121
128
|
if (isPrimaryKey) {
|
|
122
129
|
property.key = true;
|
|
123
130
|
}
|
|
131
|
+
_includeExternalNamespaceAnnotation(propertyType,property);
|
|
124
132
|
// conditions have to be made
|
|
125
133
|
if (propertyType.$MaxLength) {
|
|
126
134
|
if (propertyType.$Type) {
|
|
@@ -140,7 +148,7 @@ function generatePropertyCsn(propertyType, isPrimaryKey) {
|
|
|
140
148
|
}
|
|
141
149
|
} else if (propertyType.$Type) {
|
|
142
150
|
property.type = edmxncdsdatatype[propertyType.$Type];
|
|
143
|
-
} else
|
|
151
|
+
} else{
|
|
144
152
|
property.type = 'cds.LargeString'; // if type is missing, then it is String type
|
|
145
153
|
}
|
|
146
154
|
return property;
|
|
@@ -167,6 +175,7 @@ function _parseAssociationProperty(foreignReference, associationNode, mockServer
|
|
|
167
175
|
let data;
|
|
168
176
|
let ref;
|
|
169
177
|
associationProperty.type = 'cds.Association';
|
|
178
|
+
associationProperty.doc = 'Please add an ON condition\n';
|
|
170
179
|
// associationProperty.target = associationNode.$Type;
|
|
171
180
|
if (mockServerUc && entitySetToEntityTypeMap && entitySetToEntityTypeMap.get(associationNode.$Type)) {
|
|
172
181
|
if (entitySetToEntityTypeMap.get(associationNode.$Type).length > 1) {
|
|
@@ -211,6 +220,12 @@ function _parseAssociationProperty(foreignReference, associationNode, mockServer
|
|
|
211
220
|
}
|
|
212
221
|
}
|
|
213
222
|
}
|
|
223
|
+
// Convert managed associations and compositions in unmanaged with empty key to avoid
|
|
224
|
+
// "generation" of keys, that do not exist in the external service.
|
|
225
|
+
if (common.checkForEmptyKeys(associationProperty, "V4")) {
|
|
226
|
+
associationProperty.keys = [];
|
|
227
|
+
}
|
|
228
|
+
_includeExternalNamespaceAnnotation(associationNode,associationProperty);
|
|
214
229
|
return associationProperty;
|
|
215
230
|
}
|
|
216
231
|
|
|
@@ -228,9 +243,10 @@ function _generateCSNForEntityType(entityTypes, ignorePersistenceSkip, mockServe
|
|
|
228
243
|
if (key) {
|
|
229
244
|
entityCsn[key] = {};
|
|
230
245
|
entityCsn[key].kind = 'entity';
|
|
231
|
-
if (!ignorePersistenceSkip) {
|
|
232
|
-
entityCsn[key]['@cds.persistence.skip'] = true;
|
|
246
|
+
if (!ignorePersistenceSkip) {
|
|
247
|
+
entityCsn[key]['@cds.persistence.skip'] = true;
|
|
233
248
|
}
|
|
249
|
+
_includeExternalNamespaceAnnotation(element[key],entityCsn[key]);
|
|
234
250
|
// inheritance
|
|
235
251
|
if (baseType) {
|
|
236
252
|
entityCsn[key].includes = [];
|
|
@@ -403,7 +419,7 @@ function _generateBounded(schemaData, flag) {
|
|
|
403
419
|
return bFunction;
|
|
404
420
|
}
|
|
405
421
|
|
|
406
|
-
function _collectBounded(schemaDataList
|
|
422
|
+
function _collectBounded(schemaDataList, flag) {
|
|
407
423
|
let schemaData;
|
|
408
424
|
for (let i = 0; i < schemaDataList.length; i++) {
|
|
409
425
|
schemaData = schemaDataList[i];
|
|
@@ -416,8 +432,30 @@ function _collectBounded(schemaDataList , flag) {
|
|
|
416
432
|
}
|
|
417
433
|
}
|
|
418
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
|
+
|
|
419
457
|
function _parseBounded(csnDefs, flag) {
|
|
420
|
-
let boundedEdmxKind, boundedObj, boundedCsnKind, boundedEntityName, obj,
|
|
458
|
+
let boundedEdmxKind, boundedObj, boundedCsnKind, boundedEntityName, obj, paramName, paramObj, name;
|
|
421
459
|
if (flag == 0) {
|
|
422
460
|
boundedEdmxKind = "Action";
|
|
423
461
|
boundedCsnKind = "action";
|
|
@@ -442,6 +480,7 @@ function _parseBounded(csnDefs, flag) {
|
|
|
442
480
|
if (csnDefs[boundedEntityName].actions === undefined)
|
|
443
481
|
csnDefs[boundedEntityName].actions = {};
|
|
444
482
|
csnDefs[boundedEntityName].actions[name] = {};
|
|
483
|
+
_includeExternalNamespaceAnnotation(obj[0],csnDefs[boundedEntityName].actions[name]);
|
|
445
484
|
csnDefs[boundedEntityName].actions[name].kind = boundedCsnKind;
|
|
446
485
|
// add params
|
|
447
486
|
if (obj[j].$Parameter && obj[j].$Parameter.length >= 2) {
|
|
@@ -458,55 +497,56 @@ function _parseBounded(csnDefs, flag) {
|
|
|
458
497
|
for (let i = 1; i < obj[j].$Parameter.length; i++) {
|
|
459
498
|
paramObj = obj[j].$Parameter[i];
|
|
460
499
|
paramName = obj[j].$Parameter[i].$Name;
|
|
461
|
-
|
|
500
|
+
let paramType ={};
|
|
501
|
+
_includeExternalNamespaceAnnotation(paramObj,paramType);
|
|
502
|
+
//check if the parameter type is pre-defined, undefined or custom defined
|
|
462
503
|
if (edmxncdsdatatype[paramObj.$Type])
|
|
463
504
|
paramType = generatePropertyCsn(paramObj, false);
|
|
464
|
-
else if (paramObj.$Type === undefined)
|
|
465
|
-
paramType = { "type": "cds.LargeString" }; // intentionally used LargeString
|
|
466
505
|
else {
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
paramType = { "type": type };
|
|
470
|
-
}
|
|
471
|
-
else {
|
|
472
|
-
paramType = { "type": obj[j].$Parameter[i].$Type };
|
|
473
|
-
}
|
|
506
|
+
let type = _getDatatype(paramObj.$Type);
|
|
507
|
+
if(type) paramType["type"] = type;
|
|
474
508
|
}
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
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
|
+
|
|
481
519
|
}
|
|
482
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
|
+
}
|
|
483
526
|
// add returns
|
|
484
527
|
if (obj[j].$ReturnType) {
|
|
485
|
-
|
|
528
|
+
let returnType={};
|
|
486
529
|
// check if the return type is pre-defined, undefined or custom defined
|
|
487
530
|
if (edmxncdsdatatype[obj[j].$ReturnType.$Type])
|
|
488
531
|
returnType = generatePropertyCsn(obj[j].$ReturnType, false);
|
|
489
|
-
else if (obj[j].$ReturnType.$Type === undefined)
|
|
490
|
-
returnType = { "type": "cds.LargeString" }; // intentionally used LargeString
|
|
491
532
|
else {
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
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;
|
|
499
544
|
}
|
|
500
|
-
// check if return type is a collection
|
|
501
|
-
if (obj[j].$ReturnType.$Collection)
|
|
502
|
-
csnDefs[boundedEntityName].actions[name].returns.items = returnType;
|
|
503
|
-
else
|
|
504
|
-
csnDefs[boundedEntityName].actions[name].returns = returnType;
|
|
505
545
|
}
|
|
506
546
|
}
|
|
507
547
|
}
|
|
508
548
|
}
|
|
509
|
-
|
|
549
|
+
);
|
|
510
550
|
}
|
|
511
551
|
}
|
|
512
552
|
|
|
@@ -552,13 +592,15 @@ function _generateCSNForComplexType(schemaData) {
|
|
|
552
592
|
}
|
|
553
593
|
Object.keys(cTypes[element]).forEach(property => { // cTypes[element][property].$Type.startsWith('Edm.')
|
|
554
594
|
if (cTypes[element][property] instanceof Object) {
|
|
555
|
-
if (!cTypes[element][property].$Type || edmxncdsdatatype[cTypes[element][property].$Type]) {
|
|
595
|
+
if (!cTypes[element][property].$Type || edmxncdsdatatype[cTypes[element][property].$Type] ) {
|
|
556
596
|
propertyType = cTypes[element][property];
|
|
557
597
|
complexCsn[element].elements[property] = generatePropertyCsn(propertyType, false);
|
|
558
598
|
}
|
|
559
599
|
} else if (complexTypes[cTypes[element][property].$Type]) {
|
|
560
600
|
propertyType = cTypes[element][property];
|
|
561
601
|
complexCsn[element].elements[property] = _generateComplexTypePropertyCsn(propertyType);
|
|
602
|
+
} else if(property.startsWith("@")){
|
|
603
|
+
complexCsn[element][property] = cTypes[element][property];
|
|
562
604
|
}
|
|
563
605
|
});
|
|
564
606
|
});
|
|
@@ -595,64 +637,67 @@ function _parseUnbounded(schemaData, flag) {
|
|
|
595
637
|
if (Object.keys(unbounded).length > 0) {
|
|
596
638
|
Object.keys(unbounded).forEach(ub => {
|
|
597
639
|
let obj = {};
|
|
598
|
-
let objType = {}, objData = {}, temp;
|
|
599
|
-
if (importToMap && importToMap.get(ub)) {
|
|
600
|
-
temp =
|
|
640
|
+
let objType = {}, objData = {}, temp = {};
|
|
641
|
+
if (importToMap && importToMap.get(ub)) {
|
|
642
|
+
temp = ub.split(".").pop();
|
|
601
643
|
objType = namespace + "." + temp;
|
|
602
644
|
objData = schemaData[0][temp][0];
|
|
603
645
|
obj[objType] = {};
|
|
604
646
|
obj[objType].kind = unboundedCsnKind;
|
|
647
|
+
_includeExternalNamespaceAnnotation(objData,obj[objType]);
|
|
605
648
|
// add params
|
|
606
649
|
if (objData.$Parameter && objData.$Parameter.length > 0) {
|
|
607
650
|
obj[objType].params = {};
|
|
608
|
-
let type;
|
|
651
|
+
let type = {};
|
|
609
652
|
for (let i = 0; i < objData.$Parameter.length; i++) {
|
|
610
|
-
|
|
653
|
+
let typeProperties = {};
|
|
654
|
+
_includeExternalNamespaceAnnotation(objData.$Parameter[i],typeProperties);
|
|
611
655
|
// check if the parameter type is pre-defined, undefined or custom defined
|
|
612
656
|
if (edmxncdsdatatype[objData.$Parameter[i].$Type]) {
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
else
|
|
616
|
-
type =
|
|
657
|
+
const parameterProperties = generatePropertyCsn(objData.$Parameter[i], false);
|
|
658
|
+
({type, ...typeProperties} = parameterProperties);
|
|
659
|
+
} else {
|
|
660
|
+
type = _getDatatype(objData.$Parameter[i].$Type);
|
|
617
661
|
}
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
662
|
+
if (type) {
|
|
663
|
+
|
|
664
|
+
// Adds type properties like scale, precision, etc if any
|
|
665
|
+
const parameterObj = Object.keys(typeProperties).length > 0 ? { type, ...typeProperties } : { type };
|
|
666
|
+
|
|
667
|
+
// check if parameter type is a collection
|
|
668
|
+
if (objData.$Parameter[i].$Collection)
|
|
669
|
+
obj[objType].params[objData.$Parameter[i].$Name].items = parameterObj;
|
|
621
670
|
else
|
|
622
|
-
|
|
671
|
+
obj[objType].params[objData.$Parameter[i].$Name] = parameterObj;
|
|
672
|
+
|
|
623
673
|
}
|
|
624
|
-
// check if parameter type is a collection
|
|
625
|
-
if (objData.$Parameter[i].$Collection)
|
|
626
|
-
obj[objType].params[objData.$Parameter[i].$Name].items = { "type": type };
|
|
627
|
-
else
|
|
628
|
-
obj[objType].params[objData.$Parameter[i].$Name] = { "type": type };
|
|
629
674
|
}
|
|
630
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
|
+
}
|
|
631
681
|
// add returns
|
|
632
682
|
if (objData.$ReturnType && Object.keys(objData.$ReturnType).length > 0 && obj) {
|
|
633
|
-
|
|
634
|
-
let returnValue;
|
|
683
|
+
let returnValue = {};
|
|
635
684
|
// check if the return type is pre-defined, undefined or custom defined
|
|
636
685
|
if (edmxncdsdatatype[objData.$ReturnType.$Type]) {
|
|
637
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;
|
|
638
691
|
}
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
else
|
|
648
|
-
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;
|
|
649
700
|
}
|
|
650
|
-
// check if return type is a collection
|
|
651
|
-
if (objData.$ReturnType.$Collection) {
|
|
652
|
-
obj[objType].returns.items = {};
|
|
653
|
-
obj[objType].returns.items = returnValue;
|
|
654
|
-
} else
|
|
655
|
-
obj[objType].returns = returnValue;
|
|
656
701
|
}
|
|
657
702
|
}
|
|
658
703
|
unboundedObj = Object.assign(unboundedObj, obj);
|
|
@@ -662,7 +707,6 @@ function _parseUnbounded(schemaData, flag) {
|
|
|
662
707
|
}
|
|
663
708
|
|
|
664
709
|
function _generateCSN(edmxAsJson, ignorePersistenceSkip, mockServerUc) {
|
|
665
|
-
let schemaCounter = 0;
|
|
666
710
|
let csn = {};
|
|
667
711
|
let schemaData = [];
|
|
668
712
|
unboundedActions = {};
|
|
@@ -673,6 +717,16 @@ function _generateCSN(edmxAsJson, ignorePersistenceSkip, mockServerUc) {
|
|
|
673
717
|
csn.meta.creator = 'cds-dk ' + versionInfo;
|
|
674
718
|
csn.$version = '2.0';
|
|
675
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
|
+
|
|
676
730
|
if (mockServerUc) {
|
|
677
731
|
let entitySetData = edmxAsJson[namespace];
|
|
678
732
|
let entityContainer;
|
|
@@ -698,27 +752,15 @@ function _generateCSN(edmxAsJson, ignorePersistenceSkip, mockServerUc) {
|
|
|
698
752
|
}
|
|
699
753
|
});
|
|
700
754
|
}
|
|
701
|
-
Object.keys(edmxAsJson).forEach(data => {
|
|
702
|
-
if (ignoreObjects.indexOf(data) === -1 && edmxAsJson[data] instanceof Object) {
|
|
703
|
-
schemaData.push(edmxAsJson[data]);
|
|
704
|
-
schemaCounter += 1;
|
|
705
|
-
}
|
|
706
|
-
});
|
|
707
|
-
|
|
708
|
-
// Multiple schema found and currently we don't support
|
|
709
|
-
if (schemaCounter > 1) {
|
|
710
|
-
let errorMsg = messages().MULTIPLE_SCHEMA_FOUND;
|
|
711
|
-
errors.push(errorMsg);
|
|
712
|
-
// throw errorMsg;
|
|
713
|
-
}
|
|
714
755
|
|
|
715
756
|
csn.definitions[namespace] = {};
|
|
716
757
|
csn.definitions[namespace].kind = 'service';
|
|
758
|
+
csn.definitions[namespace]['@cds.external'] = true;
|
|
717
759
|
|
|
718
760
|
_collectEnumType(schemaData);
|
|
719
761
|
_collectTypeDefinition(schemaData);
|
|
720
|
-
_collectBounded(schemaData,0);
|
|
721
|
-
_collectBounded(schemaData,1);
|
|
762
|
+
_collectBounded(schemaData, 0);
|
|
763
|
+
_collectBounded(schemaData, 1);
|
|
722
764
|
|
|
723
765
|
// Step 1: get all complex types.
|
|
724
766
|
csn.definitions = Object.assign(_generateCSNForComplexType(schemaData), csn.definitions);
|
|
@@ -730,96 +772,127 @@ function _generateCSN(edmxAsJson, ignorePersistenceSkip, mockServerUc) {
|
|
|
730
772
|
// Step 4: get all entity type
|
|
731
773
|
csn.definitions = Object.assign(_parseEntityType(schemaData, ignorePersistenceSkip, mockServerUc), csn.definitions);
|
|
732
774
|
// Step 5: get all bounded action & function
|
|
733
|
-
_parseBounded(csn.definitions, 0
|
|
734
|
-
_parseBounded(csn.definitions, 1
|
|
775
|
+
_parseBounded(csn.definitions, 0);
|
|
776
|
+
_parseBounded(csn.definitions, 1);
|
|
735
777
|
// Step 6: get all annotations
|
|
736
778
|
_generateDocumentation(schemaData, csn.definitions);
|
|
737
779
|
|
|
738
780
|
return JSON.stringify(csn, null, 4);
|
|
739
781
|
}
|
|
740
782
|
|
|
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
|
+
}
|
|
835
|
+
}
|
|
836
|
+
|
|
741
837
|
function _generateDocumentation(schemaData, cdsDefs) {
|
|
742
838
|
if (schemaData[0].$Annotations) {
|
|
743
839
|
Object.entries(schemaData[0].$Annotations).map(annotation => {
|
|
744
|
-
let
|
|
840
|
+
let no_of_terms;
|
|
745
841
|
// eslint-disable-next-line no-prototype-builtins
|
|
746
842
|
if (annotation[1].hasOwnProperty('@Core.Description')) {
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
let path = annotation[0].split(".")[0];
|
|
751
|
-
cdsDefs[path].doc = annotation[1]["@Core.Description"];
|
|
752
|
-
}
|
|
753
|
-
if (cdsDefs[annotation[0]]) {
|
|
754
|
-
cdsDefs[annotation[0]].doc = annotation[1]["@Core.Description"];
|
|
755
|
-
}
|
|
756
|
-
} else {
|
|
757
|
-
let path = annotation[0].split('/');
|
|
758
|
-
if (cdsDefs[path[0]]["elements"][path[1]]) {
|
|
759
|
-
cdsDefs[path[0]]["elements"][path[1]].doc = annotation[1]["@Core.Description"];
|
|
760
|
-
}
|
|
761
|
-
}
|
|
843
|
+
|
|
844
|
+
no_of_terms = true;
|
|
845
|
+
_checkAnnotationTarget(annotation,cdsDefs,"@Core.Description",no_of_terms);
|
|
762
846
|
}
|
|
763
847
|
// eslint-disable-next-line no-prototype-builtins
|
|
764
848
|
if (annotation[1].hasOwnProperty('@Core.LongDescription')) {
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
if (flag === true) {
|
|
769
|
-
cdsDefs[path].doc += "\n\n";
|
|
770
|
-
} else {
|
|
771
|
-
cdsDefs[path].doc = "";
|
|
772
|
-
}
|
|
773
|
-
cdsDefs[path].doc += annotation[1]["@Core.LongDescription"];
|
|
774
|
-
}
|
|
775
|
-
if (cdsDefs[annotation[0]]) {
|
|
776
|
-
if (flag === true) {
|
|
777
|
-
cdsDefs[annotation[0]].doc += "\n\n";
|
|
778
|
-
} else {
|
|
779
|
-
cdsDefs[annotation[0]].doc = "";
|
|
780
|
-
}
|
|
781
|
-
cdsDefs[annotation[0]].doc += annotation[1]["Core.LongDescription"];
|
|
782
|
-
}
|
|
783
|
-
} else {
|
|
784
|
-
let path = annotation[0].split('/');
|
|
785
|
-
if (cdsDefs[path[0]]["elements"][path[1]]) {
|
|
786
|
-
if (flag === true) {
|
|
787
|
-
cdsDefs[path[0]]["elements"][path[1]].doc += "\n\n";
|
|
788
|
-
} else {
|
|
789
|
-
cdsDefs[path[0]]["elements"][path[1]].doc = "";
|
|
790
|
-
}
|
|
791
|
-
cdsDefs[path[0]]["elements"][path[1]].doc += annotation[1]["Core.LongDescription"];
|
|
792
|
-
}
|
|
793
|
-
}
|
|
794
|
-
}
|
|
849
|
+
_checkAnnotationTarget(annotation,cdsDefs,"@Core.LongDescription",no_of_terms);
|
|
850
|
+
|
|
851
|
+
}
|
|
795
852
|
});
|
|
796
853
|
}
|
|
797
854
|
}
|
|
798
855
|
|
|
799
|
-
function
|
|
800
|
-
|
|
801
|
-
|
|
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 {
|
|
802
868
|
const inputBuffer = edmx;
|
|
803
869
|
// create converter
|
|
804
|
-
const v4Conv = MetadataConverterFactory.createEdmxV40XmlToV40Json();
|
|
805
|
-
v4Conv.execute(inputBuffer, (error, json, missingReferencedDocuments) => {
|
|
870
|
+
const v4Conv = MetadataConverterFactory.createEdmxV40XmlToV40Json(name_space);
|
|
871
|
+
v4Conv.execute(inputBuffer, (error, json, missingReferencedDocuments) => {
|
|
806
872
|
if (missingReferencedDocuments.length > 0) {
|
|
807
873
|
console.log(missingReferencedDocuments); // eslint-disable-line no-console
|
|
808
874
|
}
|
|
809
|
-
|
|
810
875
|
if (_validateJSON(json)) {
|
|
811
876
|
resolve(json);
|
|
812
877
|
}
|
|
813
878
|
});
|
|
814
|
-
} catch (err) {
|
|
879
|
+
} catch (err) {
|
|
815
880
|
reject(err);
|
|
816
881
|
}
|
|
817
882
|
});
|
|
818
883
|
}
|
|
819
884
|
|
|
820
|
-
function getEdmxv4CSN(edmx, ignorePersistenceSkip, mockServerUc) {
|
|
885
|
+
function getEdmxv4CSN(edmx, ignorePersistenceSkip, mockServerUc, context) {
|
|
821
886
|
let csn;
|
|
822
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
|
+
}
|
|
823
896
|
if (_isJson(edmx)) {
|
|
824
897
|
return new Promise(function getCsn(resolve, reject) {
|
|
825
898
|
try {
|
|
@@ -837,7 +910,7 @@ function getEdmxv4CSN(edmx, ignorePersistenceSkip, mockServerUc) {
|
|
|
837
910
|
}
|
|
838
911
|
});
|
|
839
912
|
}
|
|
840
|
-
return _generateEDMX2JSON(edmx).then(function getCsn(edmj) {
|
|
913
|
+
return _generateEDMX2JSON(edmx,name_space).then(function getCsn(edmj) {
|
|
841
914
|
// now parsing logic
|
|
842
915
|
return _generateCSN(edmj, ignorePersistenceSkip, mockServerUc);
|
|
843
916
|
});
|
package/lib/init/constants.js
CHANGED